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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
d595d1d1ed6b35e4b2387160ddb72842f200a43b | 94637389e03c919023691dcd05bd4411b1034aa5 | /src/inClassNotes/langs/imp.lean | 5a034aefae8e554e837bb6925018882e65a78a81 | [] | 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 | 5,285 | lean | import .arith_expr
import .bool_expr
/-
A little PL in which we have mutable
state and an update (assignment) operation.
-/
/-
We don't have mutable state in a pure functional language
-/
def x := 1
-- def x := 2
-- structure avar : Type := (idx : nat)
def X := avar.mk 0
def Y := avar.mk 1
def Z := avar.mk 2
def init : a_state := λ (v : avar), 0
/-
{ (X,0), (Y,0), (Z,0), ... } st
X = 7;
{ (X,7), (Y,0), (Z,0), ... } st'
Y = 8
{ (X,7), (Y,8), (Z,0), ... } st''
Z = 9
{ (X,7), (Y,8), (Z,9), ... } st'''
X = 10
{ (X,10), (Y,8), (Z,9), ... } st'''
Π (v : avar), if v = X then st' v = 7 else st' v = st v
-/
def var_eq : avar → avar → bool
| (avar.mk n1) (avar.mk n2) := n1 = n2
def override : a_state → avar → aexp → a_state
| st v exp :=
λ (v' : avar),
if (var_eq v v')
then (aeval exp st)
else (st v')
def st' := override init X [7]
#eval st' X
#eval st' Y
#eval st' Z
def st'' := override st' Y [8]
#eval st'' X
#eval st'' Y
#eval st'' Z
def st''' := override st'' Z [9]
#eval st''' X
#eval st''' Y
#eval st''' Z
def st'''' := override st''' X [10]
#eval st'''' X
#eval st'''' Y
#eval st'''' Z
inductive cmd : Type
| skip
| assn (v : avar) (e : aexp)
| seq (c1 c2 : cmd) : cmd
-- | cond (b : bool_expr) (c1 c2 : cmd) : cmd
-- | while (b : bool_expr) (c : cmd) : cmd
open cmd
notation v = a := assn v a
notation c1 ; c2 := seq c1 c2
def a1 : cmd := X = [7]
def a2 := Y = [8]
def a3 := Z = [9]
def a4 := X = [10]
def program : cmd := -- a1; a2; a3; a4
X = [7];
Y = [8];
Z = [9];
X = [10]
def c_eval : cmd → a_state → a_state
| skip st := st
| (v = e) st := override st v e
| (c1 ; c2) st := c_eval c2 (c_eval c1 st)
/-
We implement assignment using function override,
converting a given (initial) state into a new state
by binding a given variable to the value of a given
arithmetic expression.
We implement sequential composition of c1 and c2 by
evaluating c2 in the state obtained by evaluating
c1 in the given (initial) state. Note that c1 and
c2 can each themselves be complex programs (in our
little language).
-/
def res := c_eval program init
#reduce res X
#reduce res Y
#reduce res Z
-- Yay!
inductive c_sem : cmd → a_state → a_state → Prop
| c_sem_skip : ∀ (st : a_state),
c_sem skip st st
| c_sem_assm :
∀ (pre post : a_state) (v : avar) (e : aexp),
(override pre v e = post) →
c_sem (v = e) pre post
| c_sem_seq :
∀ (pre is post : a_state) (c1 c2 : cmd),
c_sem c1 pre is →
c_sem c2 is post →
c_sem (c1 ; c2) pre post
/-
{pre}
(c1
{is}
c2)
{post}
-/
-- proof broken because we added skip at end of "program"
theorem t1 :
∀ (post : a_state), c_sem program init post → post X = 10 :=
begin
assume post,
assume h,
unfold program at h,
cases h,
cases h_ᾰ_1,
rw <- h_ᾰ_1_ᾰ,
apply rfl,
end
/-
-- here we fix it
theorem t2 :
∀ (post : a_state), c_sem program init post → post X = 10 :=
begin
assume post,
assume h,
unfold program at h,
cases h,
cases h_ᾰ_1,
cases h_ᾰ,
cases h_ᾰ_ᾰ_1,86/
rw <- h_ᾰ_ᾰ_1_ᾰ,
apply rfl,
end
-/
-- program broken because we added skip at end of "program"
-- homework: you fix it
example :
∀ (post : a_state), c_sem program init post → post Z = 9 :=
begin
assume post,
assume h,
unfold program at h,
cases h,
cases h_ᾰ,
cases h_ᾰ_ᾰ_1,
cases h_ᾰ_1,
rw <- h_ᾰ_1_ᾰ,
rw <- h_ᾰ_ᾰ_1_ᾰ,
apply rfl,
end
/-
SPECIFICATION AND VERIFICATION
-/
def Assertion := a_state → Prop
/-
Write an assertion that specifies the set of states in which X = 10
-/
def pre1 : Assertion := λ (st : a_state), st X = 10
/-
An assertion that's satisfied by any state
-/
def any : Assertion := λ (st : a_state), true
/-
Pre: X = 10 or Y = 8
-/
def pre2 : Assertion := λ (st : a_state), st X = 10 ∨ st Y = 8
def plus4 := λ (n : nat), 4 + n
#eval plus4 7
-- 4 + 7
-- 11
/-
{X = 10, Y =2, Z = 9}
{X = 3, Y = 8, Z = 0}
-/
/-
res : state -- {X = 10, Y = 8, Z = 9}
-/
/-
pre2 res
res X = 10 ∨ res Y = 8
-/
example : pre2 res :=
begin
unfold pre2,
apply or.inr,
apply rfl,
end
/-
What does it mean for a program, C,
to satisfy a pre/post specification?
-/
-- remember: Assertion
def satisfies (c : cmd) (pre post : Assertion) :=
∀ (st st' : a_state),
pre st →
c_sem c st st' →
post st'
notation pre {c} post := satisfies c pre post -- Hoare triple
def prog2 := X = [10]
lemma foo : satisfies prog2 any (λ st : a_state, st X = 10) :=
begin
unfold satisfies,
assume st st',
assume trivial h,
unfold prog2 at h,
cases h,
rw <- h_ᾰ,
exact rfl,
end
example : ∀ (n m k : nat), m = n → k = m → n = k :=
begin
intros n m k,
assume h1 h2,
rw <- h1,
rw h2,
end
example : any { prog2 } (λ st' : a_state, st' X = 10 ∨ st' Y = 9) :=
begin
unfold satisfies,
-- COMPLETE THIS PROOF
end
example : any { prog2 } (λ st' : a_state, st' X = 10 ∨ st' Y = 9) :=
begin
unfold satisfies, -- remembering the definition of pre{c}post notation, ...
assume pre post h_any h_sem,
apply or.inr,
cases h_sem,
rw <- h_sem_ᾰ,
end |
d761434aa409976463a5a9a5c82e57551ffac699 | 958488bc7f3c2044206e0358e56d7690b6ae696c | /lean/tutorials/tutorial0.lean | b80f40653a8acc1a1bafcd7ff69a7ae84767a9ba | [] | no_license | possientis/Prog | a08eec1c1b121c2fd6c70a8ae89e2fbef952adb4 | d4b3debc37610a88e0dac3ac5914903604fd1d1f | refs/heads/master | 1,692,263,717,723 | 1,691,757,179,000 | 1,691,757,179,000 | 40,361,602 | 3 | 0 | null | 1,679,896,438,000 | 1,438,953,859,000 | Coq | UTF-8 | Lean | false | false | 4,772 | lean | import data.real.basic
import tactic.suggest
noncomputable theory
open_locale classical
--#check upper_bounds
def up_bounds (A : set ℝ) := { a : ℝ | ∀ x ∈ A, x ≤ a }
def is_max (a : ℝ) (A : set ℝ) := a ∈ A ∧ a ∈ up_bounds A
infix ` is_a_max_of `:55 := is_max
lemma unique_max : ∀ (A : set ℝ) (x y : ℝ),
x is_a_max_of A →
y is_a_max_of A →
x = y
:= begin
intros A x y H₁ H₂,
cases H₁ with H₁ H₃, unfold up_bounds at H₃, simp at H₃,
cases H₂ with H₂ H₄, unfold up_bounds at H₄, simp at H₄,
specialize H₃ y H₂,
specialize H₄ x H₁,
linarith
end
example : ∀ (A : set ℝ) (x y : ℝ),
x is_a_max_of A →
y is_a_max_of A →
x = y
:= begin
intros A x y Hx Hy,
have : x ≤ y, from Hy.2 _ Hx.1,
have : y ≤ x, from Hx.2 _ Hy.1,
linarith
end
def low_bounds (A : set ℝ) := { a : ℝ | ∀ x ∈ A, a ≤ x }
def is_inf (a : ℝ) (A : set ℝ) := a is_a_max_of (low_bounds A)
infix ` is_an_inf_of `:55 := is_inf
lemma inf_lt {A : set ℝ} {a : ℝ} : a is_an_inf_of A →
∀ x, a < x → ∃ y ∈ A, y < x
:= begin
intros H₁ x,
contrapose,
push_neg,
intros H₂,
unfold is_inf at H₁, unfold is_max at H₁, cases H₁ with H₁ H₃,
unfold up_bounds at H₃,
apply H₃, assumption,
end
lemma le_of_le_add_eps : ∀ (x y : ℝ),
(∀ ε > 0, y ≤ x + ε) → y ≤ x
:= begin
intros x y, contrapose!, intros H₁, use ((y-x)/2), split; linarith
end
example : ∀ (x y : ℝ), (∀ ε > 0, y ≤ x + ε) → y ≤ x
:= begin
intros x y, contrapose!, intros H₁,
exact ⟨(y-x)/2, by linarith, by linarith⟩,
end
example : ∀ (x y : ℝ), (∀ ε > 0, y ≤ x + ε) → y ≤ x
:= by { intros x y, contrapose!, intros H₁, exact ⟨(y-x)/2, by linarith, by linarith⟩}
example : ∀ (x y : ℝ), (∀ ε > 0, y ≤ x + ε) → y ≤ x
:= begin
intros x y H₁,
by_contradiction H₂,
push_neg at H₂,
have H₃ := calc
y ≤ x + (y-x)/2 : by { apply H₁, linarith }
... = x/2 + y/2 : by ring
... < y : by linarith,
linarith
end
local notation `|`x`|` := abs x
def limit (u : ℕ → ℝ) (l : ℝ) := ∀ ε > 0, ∃ N, ∀ n ≥ N, |u n - l| ≤ ε
lemma le_lim : forall (x y : ℝ) (u : ℕ → ℝ),
limit u x → (∀ n, y ≤ u n) → y ≤ x
:= begin
intros x y u H₁ H₂,
apply le_of_le_add_eps,
intros ε H₃,
cases H₁ ε H₃ with N H₄,
calc
y ≤ u N : H₂ N
... = x + (u N - x) : by linarith
... ≤ x + |u N - x| : add_le_add (by apply le_refl) (by apply le_abs_self)
... ≤ x + ε : add_le_add (by apply le_refl) (H₄ N (by apply le_refl))
end
lemma inv_succ_pos : ∀ (n : ℕ), 1/(n+1 : ℝ) > 0
:=begin
intros n,
suffices : (n + 1 : ℝ) > 0 ,
{exact one_div_pos.mpr this},
{norm_cast, linarith}
end
lemma limit_inv_succ : ∀ (ε > 0), ∃ (N : ℕ), ∀ (n ≥ N), 1/(n + 1 : ℝ) ≤ ε
:=
begin
intros ε H₁,
suffices : ∃ N : ℕ, 1/ε ≤ N,
{ cases this with N H₂, use N, intros n H₃, rw div_le_iff,
{ rw ← div_le_iff',
{replace H₃ : (N : ℝ) ≤ n,
{exact_mod_cast H₃},
{linarith}},
{assumption}},
{exact_mod_cast _, apply nat.succ_pos}},
{ apply archimedean_iff_nat_le.1, apply_instance }
end
--#check archimedean_iff_nat_le.1
lemma inf_seq : ∀ (A : set ℝ) (a : ℝ),
(a is_an_inf_of A) ↔ (a ∈ low_bounds A ∧ ∃ u : ℕ → ℝ, limit u a ∧ ∀ n, u n ∈ A)
:=begin
intros A a, split,
{ intros H₁, unfold is_inf at H₁, unfold is_max at H₁, cases H₁ with H₁ H₂, split,
{ assumption },
{ have H₃ : ∀ (n:ℕ), ∃ (x ∈ A), x < a + 1/(n+1),
{ intros n, apply inf_lt,
{ exact ⟨H₁,H₂⟩},
{ have : 0 < 1/(n + 1 : ℝ),
{apply inv_succ_pos},
linarith}},
choose u H₄ using H₃,
use u,
split,
{ intros ε H₅, cases limit_inv_succ ε H₅ with N H₆,
use N, intros n H₇,
have : a ≤ u n,
{ unfold low_bounds at H₁,
apply H₁, cases (H₄ n) with H₈ H₉, assumption },
have := calc
u n < a + 1/(n + 1) : (H₄ n).2
... <= a + ε : add_le_add (le_refl _) (H₆ n H₇),
rw abs_of_nonneg; linarith},
{ intros n, exact (H₄ n).1}}},
{ intros H₁, rcases H₁ with ⟨H₁, u, H₂, H₃⟩,
unfold is_inf, unfold is_max, split,
{ assumption },
{ unfold up_bounds, intros x H₄, unfold low_bounds at H₄,
apply le_lim,
{ assumption },
{ intros n, apply H₄, apply H₃}}}
end
|
7493af5189eaec1d9c7ea39d07785b3a8c71cd39 | 624f6f2ae8b3b1adc5f8f67a365c51d5126be45a | /tests/lean/run/natlit.lean | 8c0f61426ec7673aca9ac48c025fc230566e3b78 | [
"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 | 188 | lean | new_frontend
def tst1 : 0 + 1 = 1 := rfl
def tst2 : 2 + 3 = 5 := rfl
def tst3 : 4 + 3 = 7 := rfl
def tst4 : 0 + 3 = 3 := rfl
def tst5 : 1 + 3 = 4 := rfl
def tst6 : 100 + 100 = 200 := rfl
|
dac32eaddc7ed2fe157ac5385f12ebe7c059a62b | 302c785c90d40ad3d6be43d33bc6a558354cc2cf | /src/group_theory/quaternion_group.lean | 824735264d8ed4d1e37ed7a8a50664fbdccb1082 | [
"Apache-2.0"
] | permissive | ilitzroth/mathlib | ea647e67f1fdfd19a0f7bdc5504e8acec6180011 | 5254ef14e3465f6504306132fe3ba9cec9ffff16 | refs/heads/master | 1,680,086,661,182 | 1,617,715,647,000 | 1,617,715,647,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 8,079 | lean | /-
Copyright (c) 2021 Julian Kuelshammer. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Julian Kuelshammer
-/
import data.zmod.basic
import group_theory.order_of_element
import data.nat.basic
import tactic.interval_cases
import group_theory.dihedral_group
/-!
# Quaternion Groups
We define the (generalised) quaternion groups `quaternion_group n` of order `4n`, also known as
dicyclic groups, with elements `a i` and `xa i` for `i : zmod n`. The (generalised) quaternion
groups can be defined by the presentation
$\langle a, x | a^{2n} = 1, x^2 = a^n, x^{-1}ax=a^{-1}\rangle$. We write `a i` for
$a^i$ and `xa i` for $x * a^i$. For `n=2` the quaternion group `quaternion_group 2` is isomorphic to
the unit integral quaternions `units (quaternion ℤ)`.
## Main definition
`quaternion_group n`: The (generalised) quaternion group of order `4n`.
## Implementation notes
This file is heavily based on `dihedral_group` by Shing Tak Lam.
In mathematics, the name "quaternion group" is reserved for the cases `n ≥ 2`. Since it would be
inconvenient to carry around this condition we define `quaternion_group` also for `n = 0` and
`n = 1`. `quaternion_group 0` is isomorphic to the infinite dihedral group, while
`quaternion_group 1` is isomorphic to a cyclic group of order `4`.
## References
* https://en.wikipedia.org/wiki/Dicyclic_group
* https://en.wikipedia.org/wiki/Quaternion_group
## TODO
Show that `quaternion_group 2 ≃* units (quaternion ℤ)`.
-/
/--
The (generalised) quaternion group `quaternion_group n` of order `4n`. It can be defined by the
presentation $\langle a, x | a^{2n} = 1, x^2 = a^n, x^{-1}ax=a^{-1}\rangle$. We write `a i` for
$a^i$ and `xa i` for $x * a^i$.
-/
@[derive decidable_eq]
inductive quaternion_group (n : ℕ) : Type
| a : zmod (2 * n) → quaternion_group
| xa : zmod (2 * n) → quaternion_group
namespace quaternion_group
variables {n : ℕ}
/--
Multiplication of the dihedral group.
-/
private def mul : quaternion_group n → quaternion_group n → quaternion_group n
| (a i) (a j) := a (i + j)
| (a i) (xa j) := xa (j - i)
| (xa i) (a j) := xa (i + j)
| (xa i) (xa j) := a (n + j - i)
/--
The identity `1` is given by `aⁱ`.
-/
private def one : quaternion_group n := a 0
instance : inhabited (quaternion_group n) := ⟨one⟩
/--
The inverse of an element of the quaternion group.
-/
private def inv : quaternion_group n → quaternion_group n
| (a i) := a (-i)
| (xa i) := xa (n + i)
/--
The group structure on `quaternion_group n`.
-/
instance : group (quaternion_group n) :=
{ mul := mul,
mul_assoc :=
begin
rintros (i | i) (j | j) (k | k);
simp only [mul];
abel,
simp only [neg_mul_eq_neg_mul_symm, one_mul, int.cast_one, gsmul_eq_mul, int.cast_neg,
add_right_inj],
calc -(n : zmod (2 * n)) = 0 - n : by rw zero_sub
... = 2 * n - n : by { norm_cast, simp, }
... = n : by ring
end,
one := one,
one_mul :=
begin
rintros (i | i),
{ exact congr_arg a (zero_add i) },
{ exact congr_arg xa (sub_zero i) },
end,
mul_one := begin
rintros (i | i),
{ exact congr_arg a (add_zero i) },
{ exact congr_arg xa (add_zero i) },
end,
inv := inv,
mul_left_inv := begin
rintros (i | i),
{ exact congr_arg a (neg_add_self i) },
{ exact congr_arg a (sub_self (n + i)) },
end }
variable {n}
@[simp] lemma a_mul_a (i j : zmod (2 * n)) : a i * a j = a (i + j) := rfl
@[simp] lemma a_mul_xa (i j : zmod (2 * n)) : a i * xa j = xa (j - i) := rfl
@[simp] lemma xa_mul_a (i j : zmod (2 * n)) : xa i * a j = xa (i + j) := rfl
@[simp] lemma xa_mul_xa (i j : zmod (2 * n)) : xa i * xa j = a (n + j - i) := rfl
lemma one_def : (1 : quaternion_group n) = a 0 := rfl
private def fintype_helper : (zmod (2 * n) ⊕ zmod (2 * n)) ≃ quaternion_group n :=
{ inv_fun := λ i, match i with
| (a j) := sum.inl j
| (xa j) := sum.inr j
end,
to_fun := λ i, match i with
| (sum.inl j) := a j
| (sum.inr j) := xa j
end,
left_inv := by rintro (x | x); refl,
right_inv := by rintro (x | x); refl }
/-- The special case that more or less by definition `quaternion_group 0` is isomorphic to the
infinite dihedral group. -/
def quaternion_group_zero_equiv_dihedral_group_zero : quaternion_group 0 ≃* dihedral_group 0 :=
{ to_fun := λ i, quaternion_group.rec_on i dihedral_group.r dihedral_group.sr,
inv_fun := λ i, match i with
| (dihedral_group.r j) := a j
| (dihedral_group.sr j) := xa j
end,
left_inv := by rintro (k | k); refl,
right_inv := by rintro (k | k); refl,
map_mul' := by { rintros (k | k) (l | l); { dsimp, simp, }, } }
/-- Some of the lemmas on `zmod m` require that `m` is positive, as `m = 2 * n` is the case relevant
in this file but we don't want to write `[fact (0 < 2 * n)]` we make this lemma a local instance. -/
private lemma succ_mul_pos_fact {m : ℕ} [hn : fact (0 < n)] : fact (0 < (nat.succ m) * n) :=
⟨nat.succ_mul_pos m hn.1⟩
local attribute [instance] succ_mul_pos_fact
/--
If `0 < n`, then `quaternion_group n` is a finite group.
-/
instance [fact (0 < n)] : fintype (quaternion_group n) := fintype.of_equiv _ fintype_helper
instance : nontrivial (quaternion_group n) := ⟨⟨a 0, xa 0, dec_trivial⟩⟩
/--
If `0 < n`, then `quaternion_group n` has `4n` elements.
-/
lemma card [fact (0 < n)] : fintype.card (quaternion_group n) = 4 * n :=
begin
rw [← fintype.card_eq.mpr ⟨fintype_helper⟩, fintype.card_sum, zmod.card, two_mul],
ring
end
@[simp] lemma a_one_pow (k : ℕ) : (a 1 : quaternion_group n) ^ k = a k :=
begin
induction k with k IH,
{ refl },
{ rw [pow_succ, IH, a_mul_a],
congr' 1,
norm_cast,
rw nat.one_add }
end
@[simp] lemma a_one_pow_n : (a 1 : quaternion_group n)^(2 * n) = 1 :=
begin
cases n,
{ simp_rw [mul_zero, pow_zero] },
{ rw [a_one_pow, one_def],
congr' 1,
exact zmod.nat_cast_self _ }
end
@[simp] lemma xa_pow_two (i : zmod (2 * n)) : xa i ^ 2 = a n :=
begin
simp [pow_two]
end
@[simp] lemma xa_pow_four (i : zmod (2 * n)) : xa i ^ 4 = 1 :=
begin
simp only [pow_succ, pow_two, xa_mul_xa, xa_mul_a, add_sub_cancel, add_sub_assoc, add_sub_cancel',
sub_self, add_zero],
norm_cast,
rw ← two_mul,
simp [one_def],
end
/--
If `0 < n`, then `xa i` has order 4.
-/
@[simp] lemma order_of_xa [hpos : fact (0 < n)] (i : zmod (2 * n)) : order_of (xa i) = 4 :=
begin
change _ = 2^2,
apply order_of_eq_prime_pow nat.prime_two,
{ intro h,
simp only [pow_one, xa_pow_two] at h,
injection h with h',
apply_fun zmod.val at h',
apply_fun ( / n) at h',
simp only [zmod.val_nat_cast, zmod.val_zero, nat.zero_div, nat.mod_mul_left_div_self,
nat.div_self hpos.1] at h',
norm_num at h' },
{ norm_num }
end
/-- In the special case `n = 1`, `quaternion 1` is a cyclic group (of order `4`). -/
lemma quaternion_group_one_is_cyclic : is_cyclic (quaternion_group 1) :=
begin
apply is_cyclic_of_order_of_eq_card,
rw [card, mul_one],
exact order_of_xa 0
end
/--
If `0 < n`, then `a 1` has order `2 * n`.
-/
@[simp] lemma order_of_a_one [hn : fact (0 < n)] : order_of (a 1 : quaternion_group n) = 2 * n :=
begin
cases (nat.le_of_dvd (nat.succ_mul_pos _ hn.1)
(order_of_dvd_of_pow_eq_one (@a_one_pow_n n))).lt_or_eq with h h,
{ have h1 : (a 1 : quaternion_group n)^(order_of (a 1)) = 1 := pow_order_of_eq_one _,
rw a_one_pow at h1,
injection h1 with h2,
rw [← zmod.val_eq_zero, zmod.val_nat_cast, nat.mod_eq_of_lt h] at h2,
exact absurd h2.symm (order_of_pos _).ne },
{ exact h }
end
/--
If `0 < n`, then `a i` has order `(2 * n) / gcd (2 * n) i`.
-/
lemma order_of_a [fact (0 < n)] (i : zmod (2 * n)) :
order_of (a i) = (2 * n) / nat.gcd (2 * n) i.val :=
begin
conv_lhs { rw ← zmod.nat_cast_zmod_val i },
rw [← a_one_pow, order_of_pow, order_of_a_one]
end
end quaternion_group
|
e83dce8f20692b3dadfd0e9742e5e0ab9448b557 | 74addaa0e41490cbaf2abd313a764c96df57b05d | /Mathlib/algebra/divisibility_auto.lean | 1c43dd2981db5dd10863525c10bae7f7e9d3b955 | [] | 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 | 9,132 | lean | /-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura, Floris van Doorn, Amelia Livingston, Yury Kudryashov,
Neil Strickland, Aaron Anderson
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.algebra.group_with_zero.default
import Mathlib.PostPort
universes u_1
namespace Mathlib
/-!
# Divisibility
This file defines the basics of the divisibility relation in the context of `(comm_)` `monoid`s
`(_with_zero)`.
## Main definitions
* `monoid.has_dvd`
## Implementation notes
The divisibility relation is defined for all monoids, and as such, depends on the order of
multiplication if the monoid is not commutative. There are two possible conventions for
divisibility in the noncommutative context, and this relation follows the convention for ordinals,
so `a | b` is defined as `∃ c, b = a * c`.
## Tags
divisibility, divides
-/
/-- There are two possible conventions for divisibility, which coincide in a `comm_monoid`.
This matches the convention for ordinals. -/
protected instance monoid_has_dvd {α : Type u_1} [monoid α] : has_dvd α :=
has_dvd.mk fun (a b : α) => ∃ (c : α), b = a * c
-- TODO: this used to not have c explicit, but that seems to be important
-- for use with tactics, similar to exist.intro
theorem dvd.intro {α : Type u_1} [monoid α] {a : α} {b : α} (c : α) (h : a * c = b) : a ∣ b :=
exists.intro c (Eq.symm h)
theorem dvd_of_mul_right_eq {α : Type u_1} [monoid α] {a : α} {b : α} (c : α) (h : a * c = b) :
a ∣ b :=
dvd.intro
theorem exists_eq_mul_right_of_dvd {α : Type u_1} [monoid α] {a : α} {b : α} (h : a ∣ b) :
∃ (c : α), b = a * c :=
h
theorem dvd.elim {α : Type u_1} [monoid α] {P : Prop} {a : α} {b : α} (H₁ : a ∣ b)
(H₂ : ∀ (c : α), b = a * c → P) : P :=
exists.elim H₁ H₂
@[simp] theorem dvd_refl {α : Type u_1} [monoid α] (a : α) : a ∣ a := sorry
theorem dvd_trans {α : Type u_1} [monoid α] {a : α} {b : α} {c : α} (h₁ : a ∣ b) (h₂ : b ∣ c) :
a ∣ c :=
sorry
theorem dvd.trans {α : Type u_1} [monoid α] {a : α} {b : α} {c : α} (h₁ : a ∣ b) (h₂ : b ∣ c) :
a ∣ c :=
dvd_trans
theorem one_dvd {α : Type u_1} [monoid α] (a : α) : 1 ∣ a := sorry
@[simp] theorem dvd_mul_right {α : Type u_1} [monoid α] (a : α) (b : α) : a ∣ a * b :=
dvd.intro b rfl
theorem dvd_mul_of_dvd_left {α : Type u_1} [monoid α] {a : α} {b : α} (h : a ∣ b) (c : α) :
a ∣ b * c :=
sorry
theorem dvd_of_mul_right_dvd {α : Type u_1} [monoid α] {a : α} {b : α} {c : α} (h : a * b ∣ c) :
a ∣ c :=
sorry
theorem dvd.intro_left {α : Type u_1} [comm_monoid α] {a : α} {b : α} (c : α) (h : c * a = b) :
a ∣ b :=
dvd.intro c (eq.mp (Eq._oldrec (Eq.refl (c * a = b)) (mul_comm c a)) h)
theorem dvd_of_mul_left_eq {α : Type u_1} [comm_monoid α] {a : α} {b : α} (c : α) (h : c * a = b) :
a ∣ b :=
dvd.intro_left
theorem exists_eq_mul_left_of_dvd {α : Type u_1} [comm_monoid α] {a : α} {b : α} (h : a ∣ b) :
∃ (c : α), b = c * a :=
dvd.elim h fun (c : α) (H1 : b = a * c) => exists.intro c (Eq.trans H1 (mul_comm a c))
theorem dvd.elim_left {α : Type u_1} [comm_monoid α] {a : α} {b : α} {P : Prop} (h₁ : a ∣ b)
(h₂ : ∀ (c : α), b = c * a → P) : P :=
exists.elim (exists_eq_mul_left_of_dvd h₁) fun (c : α) (h₃ : b = c * a) => h₂ c h₃
@[simp] theorem dvd_mul_left {α : Type u_1} [comm_monoid α] (a : α) (b : α) : a ∣ b * a :=
dvd.intro b (mul_comm a b)
theorem dvd_mul_of_dvd_right {α : Type u_1} [comm_monoid α] {a : α} {b : α} (h : a ∣ b) (c : α) :
a ∣ c * b :=
eq.mpr (id (Eq._oldrec (Eq.refl (a ∣ c * b)) (mul_comm c b))) (dvd_mul_of_dvd_left h c)
theorem mul_dvd_mul {α : Type u_1} [comm_monoid α] {a : α} {b : α} {c : α} {d : α} :
a ∣ b → c ∣ d → a * c ∣ b * d :=
sorry
theorem mul_dvd_mul_left {α : Type u_1} [comm_monoid α] (a : α) {b : α} {c : α} (h : b ∣ c) :
a * b ∣ a * c :=
mul_dvd_mul (dvd_refl a) h
theorem mul_dvd_mul_right {α : Type u_1} [comm_monoid α] {a : α} {b : α} (h : a ∣ b) (c : α) :
a * c ∣ b * c :=
mul_dvd_mul h (dvd_refl c)
theorem dvd_of_mul_left_dvd {α : Type u_1} [comm_monoid α] {a : α} {b : α} {c : α} (h : a * b ∣ c) :
b ∣ c :=
sorry
theorem eq_zero_of_zero_dvd {α : Type u_1} [monoid_with_zero α] {a : α} (h : 0 ∣ a) : a = 0 :=
dvd.elim h fun (c : α) (H' : a = 0 * c) => Eq.trans H' (zero_mul c)
/-- Given an element `a` of a commutative monoid with zero, there exists another element whose
product with zero equals `a` iff `a` equals zero. -/
@[simp] theorem zero_dvd_iff {α : Type u_1} [monoid_with_zero α] {a : α} : 0 ∣ a ↔ a = 0 :=
{ mp := eq_zero_of_zero_dvd,
mpr := fun (h : a = 0) => eq.mpr (id (Eq._oldrec (Eq.refl (0 ∣ a)) h)) (dvd_refl 0) }
@[simp] theorem dvd_zero {α : Type u_1} [monoid_with_zero α] (a : α) : a ∣ 0 := sorry
/-- Given two elements `b`, `c` of a `cancel_monoid_with_zero` and a nonzero element `a`,
`a*b` divides `a*c` iff `b` divides `c`. -/
theorem mul_dvd_mul_iff_left {α : Type u_1} [cancel_monoid_with_zero α] {a : α} {b : α} {c : α}
(ha : a ≠ 0) : a * b ∣ a * c ↔ b ∣ c :=
sorry
/-- Given two elements `a`, `b` of a commutative `cancel_monoid_with_zero` and a nonzero
element `c`, `a*c` divides `b*c` iff `a` divides `b`. -/
theorem mul_dvd_mul_iff_right {α : Type u_1} [comm_cancel_monoid_with_zero α] {a : α} {b : α}
{c : α} (hc : c ≠ 0) : a * c ∣ b * c ↔ a ∣ b :=
sorry
/-!
### Units in various monoids
-/
namespace units
/-- Elements of the unit group of a monoid represented as elements of the monoid
divide any element of the monoid. -/
theorem coe_dvd {α : Type u_1} [monoid α] {a : α} {u : units α} : ↑u ∣ a := sorry
/-- In a monoid, an element `a` divides an element `b` iff `a` divides all
associates of `b`. -/
theorem dvd_mul_right {α : Type u_1} [monoid α] {a : α} {b : α} {u : units α} :
a ∣ b * ↑u ↔ a ∣ b :=
sorry
/-- In a monoid, an element a divides an element b iff all associates of `a` divide `b`.-/
theorem mul_right_dvd {α : Type u_1} [monoid α] {a : α} {b : α} {u : units α} :
a * ↑u ∣ b ↔ a ∣ b :=
sorry
/-- In a commutative monoid, an element `a` divides an element `b` iff `a` divides all left
associates of `b`. -/
theorem dvd_mul_left {α : Type u_1} [comm_monoid α] {a : α} {b : α} {u : units α} :
a ∣ ↑u * b ↔ a ∣ b :=
eq.mpr (id (Eq._oldrec (Eq.refl (a ∣ ↑u * b ↔ a ∣ b)) (mul_comm (↑u) b))) dvd_mul_right
/-- In a commutative monoid, an element `a` divides an element `b` iff all
left associates of `a` divide `b`.-/
theorem mul_left_dvd {α : Type u_1} [comm_monoid α] {a : α} {b : α} {u : units α} :
↑u * a ∣ b ↔ a ∣ b :=
eq.mpr (id (Eq._oldrec (Eq.refl (↑u * a ∣ b ↔ a ∣ b)) (mul_comm (↑u) a))) mul_right_dvd
end units
namespace is_unit
/-- Units of a monoid divide any element of the monoid. -/
@[simp] theorem dvd {α : Type u_1} [monoid α] {a : α} {u : α} (hu : is_unit u) : u ∣ a :=
Exists.dcases_on hu fun (u_1 : units α) (hu_h : ↑u_1 = u) => Eq._oldrec units.coe_dvd hu_h
@[simp] theorem dvd_mul_right {α : Type u_1} [monoid α] {a : α} {b : α} {u : α} (hu : is_unit u) :
a ∣ b * u ↔ a ∣ b :=
Exists.dcases_on hu fun (u_1 : units α) (hu_h : ↑u_1 = u) => Eq._oldrec units.dvd_mul_right hu_h
/-- In a monoid, an element a divides an element b iff all associates of `a` divide `b`.-/
@[simp] theorem mul_right_dvd {α : Type u_1} [monoid α] {a : α} {b : α} {u : α} (hu : is_unit u) :
a * u ∣ b ↔ a ∣ b :=
Exists.dcases_on hu fun (u_1 : units α) (hu_h : ↑u_1 = u) => Eq._oldrec units.mul_right_dvd hu_h
/-- In a commutative monoid, an element `a` divides an element `b` iff `a` divides all left
associates of `b`. -/
@[simp] theorem dvd_mul_left {α : Type u_1} [comm_monoid α] (a : α) (b : α) (u : α)
(hu : is_unit u) : a ∣ u * b ↔ a ∣ b :=
Exists.dcases_on hu fun (u_1 : units α) (hu_h : ↑u_1 = u) => Eq._oldrec units.dvd_mul_left hu_h
/-- In a commutative monoid, an element `a` divides an element `b` iff all
left associates of `a` divide `b`.-/
@[simp] theorem mul_left_dvd {α : Type u_1} [comm_monoid α] (a : α) (b : α) (u : α)
(hu : is_unit u) : u * a ∣ b ↔ a ∣ b :=
Exists.dcases_on hu fun (u_1 : units α) (hu_h : ↑u_1 = u) => Eq._oldrec units.mul_left_dvd hu_h
end is_unit
/-- `dvd_not_unit a b` expresses that `a` divides `b` "strictly", i.e. that `b` divided by `a` is not a unit. -/
def dvd_not_unit {α : Type u_1} [comm_monoid_with_zero α] (a : α) (b : α) :=
a ≠ 0 ∧ ∃ (x : α), ¬is_unit x ∧ b = a * x
theorem dvd_not_unit_of_dvd_of_not_dvd {α : Type u_1} [comm_monoid_with_zero α] {a : α} {b : α}
(hd : a ∣ b) (hnd : ¬b ∣ a) : dvd_not_unit a b :=
sorry
end Mathlib |
3fa846994dee2b0f45b6d17567d8289b4f228293 | abd85493667895c57a7507870867b28124b3998f | /src/analysis/normed_space/enorm.lean | 725e401a2ad03990d9ef738fe0db1fa8718b025d | [
"Apache-2.0"
] | permissive | pechersky/mathlib | d56eef16bddb0bfc8bc552b05b7270aff5944393 | f1df14c2214ee114c9738e733efd5de174deb95d | refs/heads/master | 1,666,714,392,571 | 1,591,747,567,000 | 1,591,747,567,000 | 270,557,274 | 0 | 0 | Apache-2.0 | 1,591,597,975,000 | 1,591,597,974,000 | null | UTF-8 | Lean | false | false | 7,504 | lean | /-
Copyright (c) 2020 Yury G. Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Yury G. Kudryashov
-/
import analysis.normed_space.basic
/-!
# Extended norm
In this file we define a structure `enorm 𝕜 V` representing an extended norm (i.e., a norm that can
take the value `∞`) on a vector space `V` over a normed field `𝕜`. We do not use `class` for
an `enorm` because the same space can have more than one extended norm. For example, the space of
measurable functions `f : α → ℝ` has a family of `L_p` extended norms.
We prove some basic inequalities, then define
* `emetric_space` structure on `V` corresponding to `e : enorm 𝕜 V`;
* the subspace of vectors with finite norm, called `e.finite_subspace`;
* a `normed_space` structure on this space.
The last definition is an instance because the type involves `e`.
## Implementation notes
We do not define extended normed groups. They can be added to the chain once someone will need them.
## Tags
normed space, extended norm
-/
local attribute [instance, priority 1001] classical.prop_decidable
/-- Extended norm on a vector space. As in the case of normed spaces, we require only
`∥c • x∥ ≤ ∥c∥ * ∥x∥` in the definition, then prove an equality in `map_smul`. -/
structure enorm (𝕜 : Type*) (V : Type*) [normed_field 𝕜] [add_comm_group V] [vector_space 𝕜 V] :=
(to_fun : V → ennreal)
(eq_zero' : ∀ x, to_fun x = 0 → x = 0)
(map_add_le' : ∀ x y : V, to_fun (x + y) ≤ to_fun x + to_fun y)
(map_smul_le' : ∀ (c : 𝕜) (x : V), to_fun (c • x) ≤ nnnorm c * to_fun x)
namespace enorm
variables {𝕜 : Type*} {V : Type*} [normed_field 𝕜] [add_comm_group V] [vector_space 𝕜 V]
(e : enorm 𝕜 V)
instance : has_coe_to_fun (enorm 𝕜 V) := ⟨_, enorm.to_fun⟩
lemma coe_fn_injective ⦃e₁ e₂ : enorm 𝕜 V⦄ (h : ⇑e₁ = e₂) : e₁ = e₂ :=
by cases e₁; cases e₂; congr; exact h
@[ext] lemma ext {e₁ e₂ : enorm 𝕜 V} (h : ∀ x, e₁ x = e₂ x) : e₁ = e₂ :=
coe_fn_injective $ funext h
lemma ext_iff {e₁ e₂ : enorm 𝕜 V} : e₁ = e₂ ↔ ∀ x, e₁ x = e₂ x :=
⟨λ h x, h ▸ rfl, ext⟩
@[simp] lemma map_smul (c : 𝕜) (x : V) : e (c • x) = nnnorm c * e x :=
le_antisymm (e.map_smul_le' c x) $
begin
by_cases hc : c = 0, { simp [hc] },
calc (nnnorm c : ennreal) * e x = nnnorm c * e (c⁻¹ • c • x) : by rw [inv_smul_smul' hc]
... ≤ nnnorm c * (nnnorm (c⁻¹) * e (c • x)) : _
... = e (c • x) : _,
{ exact ennreal.mul_le_mul (le_refl _) (e.map_smul_le' _ _) },
{ rw [← mul_assoc, normed_field.nnnorm_inv, ennreal.coe_inv,
ennreal.mul_inv_cancel _ ennreal.coe_ne_top, one_mul]; simp [hc] }
end
@[simp] lemma map_zero : e 0 = 0 :=
by { rw [← zero_smul 𝕜 (0:V), e.map_smul], norm_num }
@[simp] lemma eq_zero_iff {x : V} : e x = 0 ↔ x = 0 :=
⟨e.eq_zero' x, λ h, h.symm ▸ e.map_zero⟩
@[simp] lemma map_neg (x : V) : e (-x) = e x :=
calc e (-x) = nnnorm (-1:𝕜) * e x : by rw [← map_smul, neg_one_smul]
... = e x : by simp
lemma map_sub_rev (x y : V) : e (x - y) = e (y - x) :=
by rw [← neg_sub, e.map_neg]
lemma map_add_le (x y : V) : e (x + y) ≤ e x + e y := e.map_add_le' x y
lemma map_sub_le (x y : V) : e (x - y) ≤ e x + e y :=
calc e (x - y) ≤ e x + e (-y) : e.map_add_le x (-y)
... = e x + e y : by rw [e.map_neg]
instance : partial_order (enorm 𝕜 V) :=
{ le := λ e₁ e₂, ∀ x, e₁ x ≤ e₂ x,
le_refl := λ e x, le_refl _,
le_trans := λ e₁ e₂ e₃ h₁₂ h₂₃ x, le_trans (h₁₂ x) (h₂₃ x),
le_antisymm := λ e₁ e₂ h₁₂ h₂₁, ext $ λ x, le_antisymm (h₁₂ x) (h₂₁ x) }
/-- The `enorm` sending each non-zero vector to infinity. -/
noncomputable instance : has_top (enorm 𝕜 V) :=
⟨{ to_fun := λ x, if x = 0 then 0 else ⊤,
eq_zero' := λ x, by { split_ifs; simp [*] },
map_add_le' := λ x y,
begin
split_ifs with hxy hx hy hy hx hy hy; try { simp [*] },
simpa [hx, hy] using hxy
end,
map_smul_le' := λ c x,
begin
split_ifs with hcx hx hx; simp only [smul_eq_zero, not_or_distrib] at hcx,
{ simp only [mul_zero, le_refl] },
{ have : c = 0, by tauto,
simp [this] },
{ tauto },
{ simp [hcx.1] }
end }⟩
noncomputable instance : inhabited (enorm 𝕜 V) := ⟨⊤⟩
lemma top_map {x : V} (hx : x ≠ 0) : (⊤ : enorm 𝕜 V) x = ⊤ := if_neg hx
noncomputable instance : semilattice_sup_top (enorm 𝕜 V) :=
{ le := (≤),
lt := (<),
top := ⊤,
le_top := λ e x, if h : x = 0 then by simp [h] else by simp [top_map h],
sup := λ e₁ e₂,
{ to_fun := λ x, max (e₁ x) (e₂ x),
eq_zero' := λ x h, e₁.eq_zero_iff.1 (ennreal.max_eq_zero_iff.1 h).1,
map_add_le' := λ x y, max_le
(le_trans (e₁.map_add_le _ _) $ add_le_add' (le_max_left _ _) (le_max_left _ _))
(le_trans (e₂.map_add_le _ _) $ add_le_add' (le_max_right _ _) (le_max_right _ _)),
map_smul_le' := λ c x, le_of_eq $ by simp only [map_smul, ennreal.mul_max] },
le_sup_left := λ e₁ e₂ x, le_max_left _ _,
le_sup_right := λ e₁ e₂ x, le_max_right _ _,
sup_le := λ e₁ e₂ e₃ h₁ h₂ x, max_le (h₁ x) (h₂ x),
.. enorm.partial_order }
@[simp, norm_cast] lemma coe_max (e₁ e₂ : enorm 𝕜 V) : ⇑(e₁ ⊔ e₂) = λ x, max (e₁ x) (e₂ x) := rfl
@[norm_cast]
lemma max_map (e₁ e₂ : enorm 𝕜 V) (x : V) : (e₁ ⊔ e₂) x = max (e₁ x) (e₂ x) := rfl
/-- Structure of an `emetric_space` defined by an extended norm. -/
def emetric_space : emetric_space V :=
{ edist := λ x y, e (x - y),
edist_self := λ x, by simp,
eq_of_edist_eq_zero := λ x y, by simp [sub_eq_zero],
edist_comm := e.map_sub_rev,
edist_triangle := λ x y z,
calc e (x - z) = e ((x - y) + (y - z)) : by rw [sub_add_sub_cancel]
... ≤ e (x - y) + e (y - z) : e.map_add_le (x - y) (y - z) }
/-- The subspace of vectors with finite enorm. -/
def finite_subspace : subspace 𝕜 V :=
{ carrier := {x | e x < ⊤},
zero := by simp,
add := λ x y hx hy, lt_of_le_of_lt (e.map_add_le x y) (ennreal.add_lt_top.2 ⟨hx, hy⟩),
smul := λ c x hx,
calc e (c • x) = nnnorm c * e x : e.map_smul c x
... < ⊤ : ennreal.mul_lt_top ennreal.coe_lt_top hx }
/-- Metric space structure on `e.finite_subspace`. We use `emetric_space.to_metric_space_of_dist`
to ensure that this definition agrees with `e.emetric_space`. -/
instance : metric_space e.finite_subspace :=
begin
letI := e.emetric_space,
refine emetric_space.to_metric_space_of_dist _ (λ x y, _) (λ x y, rfl),
change e (x - y) ≠ ⊤,
rw [← ennreal.lt_top_iff_ne_top],
exact lt_of_le_of_lt (e.map_sub_le x y) (ennreal.add_lt_top.2 ⟨x.2, y.2⟩)
end
lemma finite_dist_eq (x y : e.finite_subspace) : dist x y = (e (x - y)).to_real := rfl
lemma finite_edist_eq (x y : e.finite_subspace) : edist x y = e (x - y) := rfl
/-- Normed group instance on `e.finite_subspace`. -/
instance : normed_group e.finite_subspace :=
{ norm := λ x, (e x).to_real,
dist_eq := λ x y, rfl }
lemma finite_norm_eq (x : e.finite_subspace) : ∥x∥ = (e x).to_real := rfl
/-- Normed space instance on `e.finite_subspace`. -/
instance : normed_space 𝕜 e.finite_subspace :=
{ norm_smul_le := λ c x, le_of_eq $ by simp [finite_norm_eq, ← ennreal.to_real_mul_to_real] }
end enorm
|
1a774fa536cf5a8b7d6dced6c263de6a9ed45914 | b29f946a2f0afd23ef86b9219116968babbb9f4f | /src/Bolzano_Weierstrass.lean | f98bf1687d0a5b5bcee91bd1445aa0b850940f60 | [
"Apache-2.0"
] | permissive | ImperialCollegeLondon/M1P1-lean | 58be7394fded719d95e45e6b10e1ecf2ed3c7c4c | 3723468cc50f8bebd00a9811caf25224a578de17 | refs/heads/master | 1,587,063,867,779 | 1,572,727,164,000 | 1,572,727,164,000 | 165,845,802 | 14 | 4 | Apache-2.0 | 1,549,730,698,000 | 1,547,554,675,000 | Lean | UTF-8 | Lean | false | false | 2,192 | lean | import monotone limits
theorem bdd_above_of_is_bounded (f : ℕ → ℝ) (hfb : M1P1.is_bounded f) : bdd_above (set.range f) :=
let ⟨M, hm⟩ := hfb in ⟨M, λ y ⟨n, hn⟩, hn ▸ (abs_le.1 (hm n)).2⟩
theorem bdd_below_of_is_bounded (f : ℕ → ℝ) (hfb : M1P1.is_bounded f) : bdd_below (set.range f) :=
let ⟨M, hm⟩ := hfb in ⟨-M, λ y ⟨n, hn⟩, hn ▸ (abs_le.1 (hm n)).1⟩
theorem M1P1.is_bounded.comp {f : ℕ → ℝ} (hf : M1P1.is_bounded f) (s : ℕ → ℕ) : M1P1.is_bounded (f ∘ s) :=
let ⟨M, hm⟩ := hf in ⟨M, λ y, hm (s y)⟩
theorem increasing_bounded (f : ℕ → ℝ) (hfb : M1P1.is_bounded f) (hfi : increasing f) :
M1P1.is_limit f (real.Sup $ set.range f) :=
begin
intros ε Hε,
have := mt (real.Sup_le_ub (set.range f) ⟨f 0, 0, rfl⟩) (not_le_of_lt $ sub_lt_self _ Hε),
classical, simp only [not_forall] at this, rcases this with ⟨_, ⟨n, rfl⟩, hn⟩, use n, intros m hnm,
rw abs_sub_lt_iff, split,
{ rw sub_lt_iff_lt_add', refine lt_of_le_of_lt _ (lt_add_of_pos_right _ Hε),
exact real.le_Sup _ (bdd_above_of_is_bounded _ hfb) ⟨m, rfl⟩ },
{ rw sub_lt, exact lt_of_lt_of_le (not_le.1 hn) (hfi _ _ hnm) }
end
theorem decreasing_bounded (f : ℕ → ℝ) (hfb : M1P1.is_bounded f) (hfd : decreasing f) :
M1P1.is_limit f (real.Inf $ set.range f) :=
begin
intros ε Hε,
have := mt (real.lb_le_Inf (set.range f) ⟨f 0, 0, rfl⟩) (not_le_of_lt $ lt_add_of_pos_right _ Hε),
classical, simp only [not_forall] at this, rcases this with ⟨_, ⟨n, rfl⟩, hn⟩, use n, intros m hnm,
rw abs_sub_lt_iff, split,
{ rw sub_lt_iff_lt_add', exact lt_of_le_of_lt (hfd _ _ hnm) (not_le.1 hn) },
{ rw sub_lt, refine lt_of_lt_of_le (sub_lt_self _ Hε) _,
exact real.Inf_le _ (bdd_below_of_is_bounded _ hfb) ⟨m, rfl⟩ }
end
theorem bolzano_weierstrass (f : ℕ → ℝ) (hf : M1P1.is_bounded f) : ∃ s : ℕ → ℕ, strictly_increasing s ∧ M1P1.has_limit (f ∘ s) :=
let ⟨s, hs1, hs2⟩ := exists_monotone f in or.cases_on hs2
(λ hsi, ⟨s, hs1, _, increasing_bounded _ (hf.comp s) (increasing_of_strictly_increasing _ hsi)⟩)
(λ hsd, ⟨s, hs1, _, decreasing_bounded _ (hf.comp s) hsd⟩)
|
c442c9a49e48935b9c5e498fcfea476a7167393f | 3f7026ea8bef0825ca0339a275c03b911baef64d | /src/group_theory/quotient_group.lean | 2e44d8241c74f0c0607d6e3803d78d6c29c20b76 | [
"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 | 7,183 | lean | /-
Copyright (c) 2018 Kevin Buzzard and Patrick Massot. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kevin Buzzard, Patrick Massot.
This file is to a certain extent based on `quotient_module.lean` by Johannes Hölzl.
-/
import group_theory.coset
universes u v
namespace quotient_group
variables {G : Type u} [group G] (N : set G) [normal_subgroup N] {H : Type v} [group H]
@[to_additive quotient_add_group.add_group]
instance : group (quotient N) :=
{ one := (1 : G),
mul := λ a b, quotient.lift_on₂' a b
(λ a b, ((a * b : G) : quotient N))
(λ a₁ a₂ b₁ b₂ hab₁ hab₂,
quot.sound
((is_subgroup.mul_mem_cancel_left N (is_subgroup.inv_mem hab₂)).1
(by rw [mul_inv_rev, mul_inv_rev, ← mul_assoc (a₂⁻¹ * a₁⁻¹),
mul_assoc _ b₂, ← mul_assoc b₂, mul_inv_self, one_mul, mul_assoc (a₂⁻¹)];
exact normal_subgroup.normal _ hab₁ _))),
mul_assoc := λ a b c, quotient.induction_on₃' a b c
(λ a b c, congr_arg mk (mul_assoc a b c)),
one_mul := λ a, quotient.induction_on' a
(λ a, congr_arg mk (one_mul a)),
mul_one := λ a, quotient.induction_on' a
(λ a, congr_arg mk (mul_one a)),
inv := λ a, quotient.lift_on' a (λ a, ((a⁻¹ : G) : quotient N))
(λ a b hab, quotient.sound' begin
show a⁻¹⁻¹ * b⁻¹ ∈ N,
rw ← mul_inv_rev,
exact is_subgroup.inv_mem (is_subgroup.mem_norm_comm hab)
end),
mul_left_inv := λ a, quotient.induction_on' a
(λ a, congr_arg mk (mul_left_inv a)) }
@[to_additive quotient_add_group.is_add_group_hom]
instance : is_group_hom (mk : G → quotient N) := { map_mul := λ _ _, rfl }
@[simp, to_additive quotient_add_group.ker_mk]
lemma ker_mk :
is_group_hom.ker (quotient_group.mk : G → quotient_group.quotient N) = N :=
begin
ext g,
rw [is_group_hom.mem_ker, eq_comm],
show (((1 : G) : quotient_group.quotient N)) = g ↔ _,
rw [quotient_group.eq, one_inv, one_mul],
end
@[to_additive quotient_add_group.add_comm_group]
instance {G : Type*} [comm_group G] (s : set G) [is_subgroup s] : comm_group (quotient s) :=
{ mul_comm := λ a b, quotient.induction_on₂' a b
(λ a b, congr_arg mk (mul_comm a b)),
..@quotient_group.group _ _ s (normal_subgroup_of_comm_group s) }
@[simp, to_additive quotient_add_group.coe_zero]
lemma coe_one : ((1 : G) : quotient N) = 1 := rfl
@[simp, to_additive quotient_add_group.coe_add]
lemma coe_mul (a b : G) : ((a * b : G) : quotient N) = a * b := rfl
@[simp, to_additive quotient_add_group.coe_neg]
lemma coe_inv (a : G) : ((a⁻¹ : G) : quotient N) = a⁻¹ := rfl
@[simp] lemma coe_pow (a : G) (n : ℕ) : ((a ^ n : G) : quotient N) = a ^ n :=
@is_group_hom.map_pow _ _ _ _ mk _ a n
@[simp] lemma coe_gpow (a : G) (n : ℤ) : ((a ^ n : G) : quotient N) = a ^ n :=
@is_group_hom.map_gpow _ _ _ _ mk _ a n
local notation ` Q ` := quotient N
@[to_additive quotient_add_group.lift]
def lift (φ : G → H) [is_group_hom φ] (HN : ∀x∈N, φ x = 1) (q : Q) : H :=
q.lift_on' φ $ assume a b (hab : a⁻¹ * b ∈ N),
(calc φ a = φ a * 1 : (mul_one _).symm
... = φ a * φ (a⁻¹ * b) : HN (a⁻¹ * b) hab ▸ rfl
... = φ (a * (a⁻¹ * b)) : (is_mul_hom.map_mul φ a (a⁻¹ * b)).symm
... = φ b : by rw mul_inv_cancel_left)
@[simp, to_additive quotient_add_group.lift_mk]
lemma lift_mk {φ : G → H} [is_group_hom φ] (HN : ∀x∈N, φ x = 1) (g : G) :
lift N φ HN (g : Q) = φ g := rfl
@[simp, to_additive quotient_add_group.lift_mk']
lemma lift_mk' {φ : G → H} [is_group_hom φ] (HN : ∀x∈N, φ x = 1) (g : G) :
lift N φ HN (mk g : Q) = φ g := rfl
@[to_additive quotient_add_group.map]
def map (M : set H) [normal_subgroup M] (f : G → H) [is_group_hom f] (h : N ⊆ f ⁻¹' M) :
quotient N → quotient M :=
begin
haveI : is_group_hom ((mk : H → quotient M) ∘ f) := is_group_hom.comp _ _,
refine quotient_group.lift N (mk ∘ f) _,
assume x hx,
refine quotient_group.eq.2 _,
rw [mul_one, is_subgroup.inv_mem_iff],
exact h hx,
end
variables (φ : G → H) [is_group_hom φ] (HN : ∀x∈N, φ x = 1)
@[to_additive quotient_add_group.is_add_group_hom_quotient_lift]
instance is_group_hom_quotient_lift :
is_group_hom (lift N φ HN) :=
{ map_mul := λ q r, quotient.induction_on₂' q r $ is_mul_hom.map_mul φ }
@[to_additive quotient_add_group.map_is_add_group_hom]
instance map_is_group_hom (M : set H) [normal_subgroup M]
(f : G → H) [is_group_hom f] (h : N ⊆ f ⁻¹' M) : is_group_hom (map N M f h) :=
quotient_group.is_group_hom_quotient_lift _ _ _
open function is_group_hom
/-- The induced map from the quotient by the kernel to the codomain. -/
@[to_additive quotient_add_group.ker_lift]
def ker_lift : quotient (ker φ) → H :=
lift _ φ $ λ g, (mem_ker φ).mp
@[simp, to_additive quotient_add_group.ker_lift_mk]
lemma ker_lift_mk (g : G) : (ker_lift φ) g = φ g :=
lift_mk _ _ _
@[simp, to_additive quotient_add_group.ker_lift_mk']
lemma ker_lift_mk' (g : G) : (ker_lift φ) (mk g) = φ g :=
lift_mk' _ _ _
@[to_additive quotient_add_group.ker_lift_is_add_group_hom]
instance ker_lift_is_group_hom : is_group_hom (ker_lift φ) :=
quotient_group.is_group_hom_quotient_lift _ _ _
@[to_additive quotient_add_group.injective_ker_lift]
lemma injective_ker_lift : injective (ker_lift φ) :=
assume a b, quotient.induction_on₂' a b $ assume a b (h : φ a = φ b), quotient.sound' $
show a⁻¹ * b ∈ ker φ, by rw [mem_ker φ,
is_mul_hom.map_mul φ, ← h, is_group_hom.map_inv φ, inv_mul_self]
--@[to_additive quotient_add_group.quotient_ker_equiv_range]
noncomputable def quotient_ker_equiv_range : (quotient (ker φ)) ≃ set.range φ :=
@equiv.of_bijective _ (set.range φ) (λ x, ⟨lift (ker φ) φ
(by simp [mem_ker]) x, by exact quotient.induction_on' x (λ x, ⟨x, rfl⟩)⟩)
⟨λ a b h, injective_ker_lift _ (subtype.mk.inj h),
λ ⟨x, y, hy⟩, ⟨mk y, subtype.eq hy⟩⟩
noncomputable def quotient_ker_equiv_of_surjective (hφ : function.surjective φ) :
(quotient (ker φ)) ≃ H :=
calc (quotient_group.quotient (is_group_hom.ker φ)) ≃ set.range φ : quotient_ker_equiv_range _
... ≃ H : ⟨λ a, a.1, λ b, ⟨b, hφ b⟩, λ ⟨_, _⟩, rfl, λ _, rfl⟩
end quotient_group
namespace quotient_add_group
open is_add_group_hom
variables {G : Type u} [_root_.add_group G] (N : set G) [normal_add_subgroup N] {H : Type v} [_root_.add_group H]
variables (φ : G → H) [_root_.is_add_group_hom φ]
noncomputable def quotient_ker_equiv_range : (quotient (ker φ)) ≃ set.range φ :=
@quotient_group.quotient_ker_equiv_range (multiplicative G) _ (multiplicative H) _ φ _
noncomputable def quotient_ker_equiv_of_surjective (hφ : function.surjective φ) : (quotient (ker φ)) ≃ H :=
@quotient_group.quotient_ker_equiv_of_surjective (multiplicative G) _ (multiplicative H) _ φ _ hφ
attribute [to_additive quotient_add_group.quotient_ker_equiv_range] quotient_group.quotient_ker_equiv_range
attribute [to_additive quotient_add_group.quotient_ker_equiv_of_surjective] quotient_group.quotient_ker_equiv_of_surjective
end quotient_add_group
|
32fb14d3a1555efa122c89bcf6296845e286abef | 592ee40978ac7604005a4e0d35bbc4b467389241 | /Library/generated/mathscheme-lean/LeftCancellative.lean | ac7c4889047a61a3caaa9834a919207debf6b92c | [] | 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 | 8,836 | 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 LeftCancellative
structure LeftCancellative (A : Type) : Type :=
(op : (A → (A → A)))
(linv : (A → (A → A)))
(leftCancel : (∀ {x y : A} , (op x (linv x y)) = y))
open LeftCancellative
structure Sig (AS : Type) : Type :=
(opS : (AS → (AS → AS)))
(linvS : (AS → (AS → AS)))
structure Product (A : Type) : Type :=
(opP : ((Prod A A) → ((Prod A A) → (Prod A A))))
(linvP : ((Prod A A) → ((Prod A A) → (Prod A A))))
(leftCancelP : (∀ {xP yP : (Prod A A)} , (opP xP (linvP xP yP)) = yP))
structure Hom {A1 : Type} {A2 : Type} (Le1 : (LeftCancellative A1)) (Le2 : (LeftCancellative A2)) : Type :=
(hom : (A1 → A2))
(pres_op : (∀ {x1 x2 : A1} , (hom ((op Le1) x1 x2)) = ((op Le2) (hom x1) (hom x2))))
(pres_linv : (∀ {x1 x2 : A1} , (hom ((linv Le1) x1 x2)) = ((linv Le2) (hom x1) (hom x2))))
structure RelInterp {A1 : Type} {A2 : Type} (Le1 : (LeftCancellative A1)) (Le2 : (LeftCancellative A2)) : Type 1 :=
(interp : (A1 → (A2 → Type)))
(interp_op : (∀ {x1 x2 : A1} {y1 y2 : A2} , ((interp x1 y1) → ((interp x2 y2) → (interp ((op Le1) x1 x2) ((op Le2) y1 y2))))))
(interp_linv : (∀ {x1 x2 : A1} {y1 y2 : A2} , ((interp x1 y1) → ((interp x2 y2) → (interp ((linv Le1) x1 x2) ((linv Le2) y1 y2))))))
inductive LeftCancellativeTerm : Type
| opL : (LeftCancellativeTerm → (LeftCancellativeTerm → LeftCancellativeTerm))
| linvL : (LeftCancellativeTerm → (LeftCancellativeTerm → LeftCancellativeTerm))
open LeftCancellativeTerm
inductive ClLeftCancellativeTerm (A : Type) : Type
| sing : (A → ClLeftCancellativeTerm)
| opCl : (ClLeftCancellativeTerm → (ClLeftCancellativeTerm → ClLeftCancellativeTerm))
| linvCl : (ClLeftCancellativeTerm → (ClLeftCancellativeTerm → ClLeftCancellativeTerm))
open ClLeftCancellativeTerm
inductive OpLeftCancellativeTerm (n : ℕ) : Type
| v : ((fin n) → OpLeftCancellativeTerm)
| opOL : (OpLeftCancellativeTerm → (OpLeftCancellativeTerm → OpLeftCancellativeTerm))
| linvOL : (OpLeftCancellativeTerm → (OpLeftCancellativeTerm → OpLeftCancellativeTerm))
open OpLeftCancellativeTerm
inductive OpLeftCancellativeTerm2 (n : ℕ) (A : Type) : Type
| v2 : ((fin n) → OpLeftCancellativeTerm2)
| sing2 : (A → OpLeftCancellativeTerm2)
| opOL2 : (OpLeftCancellativeTerm2 → (OpLeftCancellativeTerm2 → OpLeftCancellativeTerm2))
| linvOL2 : (OpLeftCancellativeTerm2 → (OpLeftCancellativeTerm2 → OpLeftCancellativeTerm2))
open OpLeftCancellativeTerm2
def simplifyCl {A : Type} : ((ClLeftCancellativeTerm A) → (ClLeftCancellativeTerm A))
| (opCl x1 x2) := (opCl (simplifyCl x1) (simplifyCl x2))
| (linvCl x1 x2) := (linvCl (simplifyCl x1) (simplifyCl x2))
| (sing x1) := (sing x1)
def simplifyOpB {n : ℕ} : ((OpLeftCancellativeTerm n) → (OpLeftCancellativeTerm n))
| (opOL x1 x2) := (opOL (simplifyOpB x1) (simplifyOpB x2))
| (linvOL x1 x2) := (linvOL (simplifyOpB x1) (simplifyOpB x2))
| (v x1) := (v x1)
def simplifyOp {n : ℕ} {A : Type} : ((OpLeftCancellativeTerm2 n A) → (OpLeftCancellativeTerm2 n A))
| (opOL2 x1 x2) := (opOL2 (simplifyOp x1) (simplifyOp x2))
| (linvOL2 x1 x2) := (linvOL2 (simplifyOp x1) (simplifyOp x2))
| (v2 x1) := (v2 x1)
| (sing2 x1) := (sing2 x1)
def evalB {A : Type} : ((LeftCancellative A) → (LeftCancellativeTerm → A))
| Le (opL x1 x2) := ((op Le) (evalB Le x1) (evalB Le x2))
| Le (linvL x1 x2) := ((linv Le) (evalB Le x1) (evalB Le x2))
def evalCl {A : Type} : ((LeftCancellative A) → ((ClLeftCancellativeTerm A) → A))
| Le (sing x1) := x1
| Le (opCl x1 x2) := ((op Le) (evalCl Le x1) (evalCl Le x2))
| Le (linvCl x1 x2) := ((linv Le) (evalCl Le x1) (evalCl Le x2))
def evalOpB {A : Type} {n : ℕ} : ((LeftCancellative A) → ((vector A n) → ((OpLeftCancellativeTerm n) → A)))
| Le vars (v x1) := (nth vars x1)
| Le vars (opOL x1 x2) := ((op Le) (evalOpB Le vars x1) (evalOpB Le vars x2))
| Le vars (linvOL x1 x2) := ((linv Le) (evalOpB Le vars x1) (evalOpB Le vars x2))
def evalOp {A : Type} {n : ℕ} : ((LeftCancellative A) → ((vector A n) → ((OpLeftCancellativeTerm2 n A) → A)))
| Le vars (v2 x1) := (nth vars x1)
| Le vars (sing2 x1) := x1
| Le vars (opOL2 x1 x2) := ((op Le) (evalOp Le vars x1) (evalOp Le vars x2))
| Le vars (linvOL2 x1 x2) := ((linv Le) (evalOp Le vars x1) (evalOp Le vars x2))
def inductionB {P : (LeftCancellativeTerm → Type)} : ((∀ (x1 x2 : LeftCancellativeTerm) , ((P x1) → ((P x2) → (P (opL x1 x2))))) → ((∀ (x1 x2 : LeftCancellativeTerm) , ((P x1) → ((P x2) → (P (linvL x1 x2))))) → (∀ (x : LeftCancellativeTerm) , (P x))))
| popl plinvl (opL x1 x2) := (popl _ _ (inductionB popl plinvl x1) (inductionB popl plinvl x2))
| popl plinvl (linvL x1 x2) := (plinvl _ _ (inductionB popl plinvl x1) (inductionB popl plinvl x2))
def inductionCl {A : Type} {P : ((ClLeftCancellativeTerm A) → Type)} : ((∀ (x1 : A) , (P (sing x1))) → ((∀ (x1 x2 : (ClLeftCancellativeTerm A)) , ((P x1) → ((P x2) → (P (opCl x1 x2))))) → ((∀ (x1 x2 : (ClLeftCancellativeTerm A)) , ((P x1) → ((P x2) → (P (linvCl x1 x2))))) → (∀ (x : (ClLeftCancellativeTerm A)) , (P x)))))
| psing popcl plinvcl (sing x1) := (psing x1)
| psing popcl plinvcl (opCl x1 x2) := (popcl _ _ (inductionCl psing popcl plinvcl x1) (inductionCl psing popcl plinvcl x2))
| psing popcl plinvcl (linvCl x1 x2) := (plinvcl _ _ (inductionCl psing popcl plinvcl x1) (inductionCl psing popcl plinvcl x2))
def inductionOpB {n : ℕ} {P : ((OpLeftCancellativeTerm n) → Type)} : ((∀ (fin : (fin n)) , (P (v fin))) → ((∀ (x1 x2 : (OpLeftCancellativeTerm n)) , ((P x1) → ((P x2) → (P (opOL x1 x2))))) → ((∀ (x1 x2 : (OpLeftCancellativeTerm n)) , ((P x1) → ((P x2) → (P (linvOL x1 x2))))) → (∀ (x : (OpLeftCancellativeTerm n)) , (P x)))))
| pv popol plinvol (v x1) := (pv x1)
| pv popol plinvol (opOL x1 x2) := (popol _ _ (inductionOpB pv popol plinvol x1) (inductionOpB pv popol plinvol x2))
| pv popol plinvol (linvOL x1 x2) := (plinvol _ _ (inductionOpB pv popol plinvol x1) (inductionOpB pv popol plinvol x2))
def inductionOp {n : ℕ} {A : Type} {P : ((OpLeftCancellativeTerm2 n A) → Type)} : ((∀ (fin : (fin n)) , (P (v2 fin))) → ((∀ (x1 : A) , (P (sing2 x1))) → ((∀ (x1 x2 : (OpLeftCancellativeTerm2 n A)) , ((P x1) → ((P x2) → (P (opOL2 x1 x2))))) → ((∀ (x1 x2 : (OpLeftCancellativeTerm2 n A)) , ((P x1) → ((P x2) → (P (linvOL2 x1 x2))))) → (∀ (x : (OpLeftCancellativeTerm2 n A)) , (P x))))))
| pv2 psing2 popol2 plinvol2 (v2 x1) := (pv2 x1)
| pv2 psing2 popol2 plinvol2 (sing2 x1) := (psing2 x1)
| pv2 psing2 popol2 plinvol2 (opOL2 x1 x2) := (popol2 _ _ (inductionOp pv2 psing2 popol2 plinvol2 x1) (inductionOp pv2 psing2 popol2 plinvol2 x2))
| pv2 psing2 popol2 plinvol2 (linvOL2 x1 x2) := (plinvol2 _ _ (inductionOp pv2 psing2 popol2 plinvol2 x1) (inductionOp pv2 psing2 popol2 plinvol2 x2))
def stageB : (LeftCancellativeTerm → (Staged LeftCancellativeTerm))
| (opL x1 x2) := (stage2 opL (codeLift2 opL) (stageB x1) (stageB x2))
| (linvL x1 x2) := (stage2 linvL (codeLift2 linvL) (stageB x1) (stageB x2))
def stageCl {A : Type} : ((ClLeftCancellativeTerm A) → (Staged (ClLeftCancellativeTerm A)))
| (sing x1) := (Now (sing x1))
| (opCl x1 x2) := (stage2 opCl (codeLift2 opCl) (stageCl x1) (stageCl x2))
| (linvCl x1 x2) := (stage2 linvCl (codeLift2 linvCl) (stageCl x1) (stageCl x2))
def stageOpB {n : ℕ} : ((OpLeftCancellativeTerm n) → (Staged (OpLeftCancellativeTerm n)))
| (v x1) := (const (code (v x1)))
| (opOL x1 x2) := (stage2 opOL (codeLift2 opOL) (stageOpB x1) (stageOpB x2))
| (linvOL x1 x2) := (stage2 linvOL (codeLift2 linvOL) (stageOpB x1) (stageOpB x2))
def stageOp {n : ℕ} {A : Type} : ((OpLeftCancellativeTerm2 n A) → (Staged (OpLeftCancellativeTerm2 n A)))
| (sing2 x1) := (Now (sing2 x1))
| (v2 x1) := (const (code (v2 x1)))
| (opOL2 x1 x2) := (stage2 opOL2 (codeLift2 opOL2) (stageOp x1) (stageOp x2))
| (linvOL2 x1 x2) := (stage2 linvOL2 (codeLift2 linvOL2) (stageOp x1) (stageOp x2))
structure StagedRepr (A : Type) (Repr : (Type → Type)) : Type :=
(opT : ((Repr A) → ((Repr A) → (Repr A))))
(linvT : ((Repr A) → ((Repr A) → (Repr A))))
end LeftCancellative |
aa3921fc9918c4391b99f95a07d0747138b98d94 | d436468d80b739ba7e06843c4d0d2070e43448e5 | /src/category_theory/limits/shapes/terminal.lean | 6bd48914267f4e57be58f4af8983d3be4757bc43 | [
"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 | 1,940 | lean | /-
Copyright (c) 2019 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import category_theory.limits.shapes.finite_products
import category_theory.pempty
universes v u
open category_theory
namespace category_theory.limits
variables (C : Type u) [𝒞 : category.{v} C]
include 𝒞
class has_terminal :=
(has_limits_of_shape : has_limits_of_shape.{v} pempty C)
class has_initial :=
(has_colimits_of_shape : has_colimits_of_shape.{v} pempty C)
attribute [instance] has_terminal.has_limits_of_shape has_initial.has_colimits_of_shape
instance [has_finite_products.{v} C] : has_terminal.{v} C :=
{ has_limits_of_shape :=
{ has_limit := λ F,
has_limit_of_equivalence_comp ((functor.empty.{v} (discrete pempty.{v+1})).as_equivalence.symm) } }
instance [has_finite_coproducts.{v} C] : has_initial.{v} C :=
{ has_colimits_of_shape :=
{ has_colimit := λ F,
has_colimit_of_equivalence_comp ((functor.empty.{v} (discrete pempty.{v+1})).as_equivalence.symm) } }
abbreviation terminal [has_terminal.{v} C] : C := limit (functor.empty C)
abbreviation initial [has_initial.{v} C] : C := colimit (functor.empty C)
notation `⊤_` C:20 := terminal C
notation `⊥_` C:20 := initial C
section
variables {C}
abbreviation terminal.from [has_terminal.{v} C] (P : C) : P ⟶ ⊤_ C :=
limit.lift (functor.empty C) { X := P, π := by tidy }.
abbreviation initial.to [has_initial.{v} C] (P : C) : ⊥_ C ⟶ P :=
colimit.desc (functor.empty C) { X := P, ι := by tidy }.
instance unique_to_terminal [has_terminal.{v} C] (P : C) : unique (P ⟶ ⊤_ C) :=
{ default := terminal.from P,
uniq := λ m, by { apply limit.hom_ext, rintro ⟨⟩ } }
instance unique_from_initial [has_initial.{v} C] (P : C) : unique (⊥_ C ⟶ P) :=
{ default := initial.to P,
uniq := λ m, by { apply colimit.hom_ext, rintro ⟨⟩ } }
end
end category_theory.limits
|
bbf8c8e0a47720460f53f92d6bb0ae9bd1b66db4 | a11f4536efad51bc2b648123619720f3b9318c0f | /src/symm_trans_refl.lean | 813becf816a0c89e80fbd69f550a2f95e5331ccc | [] | no_license | ezrasitorus/codewars_lean | 909471d43f5130669a90b8e11afc37aec2f21d8f | 6d1abcc1253403511f4cfd767c645596175e4fd3 | refs/heads/master | 1,672,659,589,352 | 1,603,281,507,000 | 1,603,281,507,000 | 288,579,451 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 428 | lean | def bad_theorem : Prop :=
∀ (α : Type) (r : α → α → Prop), symmetric r → transitive r → reflexive r
def fail (a b : unit): Prop := false
theorem fail_symm : symmetric fail := λ x y h, h
theorem fail_trans : transitive fail := λ x y z h1 _, false.rec (fail x z) h1
-- theorem not_refl_fail : ¬ reflexive fail := λ a, a ()
theorem correct_version : ¬ bad_theorem := λ a, a unit fail fail_symm fail_trans () |
ddfca1ffe50bb52c76ebec19cd30a287f4e5dbea | bbecf0f1968d1fba4124103e4f6b55251d08e9c4 | /src/order/preorder_hom.lean | eb33a3ee73cba59e2d51f78f59946284bc83a1db | [
"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 | 18,394 | 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 logic.function.iterate
import order.bounded_lattice
import order.complete_lattice
import tactic.monotonicity
/-!
# Preorder homomorphisms
This file defines preorder homomorphisms, which are bundled monotone functions. A preorder
homomorphism `f : α →ₘ β` is a function `α → β` along with a proof that `∀ x y, x ≤ y → f x ≤ f y`.
## Main definitions
In this file we define `preorder_hom α β` a.k.a. `α →ₘ β` to be a bundled monotone map.
We also define many `preorder_hom`s. In some cases we define two versions, one with `ₘ` suffix and
one without it (e.g., `preorder_hom.compₘ` and `preorder_hom.comp`). This means that the former
function is a "more bundled" version of the latter. We can't just drop the "less bundled" version
because the more bundled version usually does not work with dot notation.
* `preorder_hom.id`: identity map as `α →ₘ α`;
* `preorder_hom.curry`: an order isomorphism between `α × β →ₘ γ` and `α →ₘ β →ₘ γ`;
* `preorder_hom.comp`: composition of two bundled monotone maps;
* `preorder_hom.compₘ`: composition of bundled monotone maps as a bundled monotone map;
* `preorder_hom.const`: constant function as a bundled monotone map;
* `preorder_hom.prod`: combine `α →ₘ β` and `α →ₘ γ` into `α →ₘ β × γ`;
* `preorder_hom.prodₘ`: a more bundled version of `preorder_hom.prod`;
* `preorder_hom.prod_iso`: order isomorphism between `α →ₘ β × γ` and `(α →ₘ β) × (α →ₘ γ)`;
* `preorder_hom.diag`: diagonal embedding of `α` into `α × α` as a bundled monotone map;
* `preorder_hom.on_diag`: restrict a monotone map `α →ₘ α →ₘ β` to the diagonal;
* `preorder_hom.fst`: projection `prod.fst : α × β → α` as a bundled monotone map;
* `preorder_hom.snd`: projection `prod.snd : α × β → β` as a bundled monotone map;
* `preorder_hom.prod_map`: `prod.map f g` as a bundled monotone map;
* `pi.eval_preorder_hom`: evaluation of a function at a point `function.eval i` as a bundled
monotone map;
* `preorder_hom.coe_fn_hom`: coercion to function as a bundled monotone map;
* `preorder_hom.apply`: application of a `preorder_hom` at a point as a bundled monotone map;
* `preorder_hom.pi`: combine a family of monotone maps `f i : α →ₘ π i` into a monotone map
`α →ₘ Π i, π i`;
* `preorder_hom.pi_iso`: order isomorphism between `α →ₘ Π i, π i` and `Π i, α →ₘ π i`;
* `preorder_hom.subtyle.val`: embedding `subtype.val : subtype p → α` as a bundled monotone map;
* `preorder_hom.dual`: reinterpret a monotone map `α →ₘ β` as a monotone map
`order_dual α →ₘ order_dual β`;
* `preorder_hom.dual_iso`: order isomorphism between `α →ₘ β` and
`order_dual (order_dual α →ₘ order_dual β)`;
We also define two functions to convert other bundled maps to `α →ₘ β`:
* `order_embedding.to_preorder_hom`: convert `α ↪o β` to `α →ₘ β`;
* `rel_hom.to_preorder_hom`: conver a `rel_hom` between strict orders to a `preorder_hom`.
## Tags
monotone map, bundled morphism
-/
/-- Bundled monotone (aka, increasing) function -/
structure preorder_hom (α β : Type*) [preorder α] [preorder β] :=
(to_fun : α → β)
(monotone' : monotone to_fun)
infixr ` →ₘ `:25 := preorder_hom
namespace preorder_hom
variables {α β γ δ : Type*} [preorder α] [preorder β] [preorder γ] [preorder δ]
instance : has_coe_to_fun (α →ₘ β) :=
{ F := λ f, α → β,
coe := preorder_hom.to_fun }
initialize_simps_projections preorder_hom (to_fun → coe)
protected lemma monotone (f : α →ₘ β) : monotone f := f.monotone'
protected lemma mono (f : α →ₘ β) : monotone f := f.monotone
@[simp] lemma to_fun_eq_coe {f : α →ₘ β} : f.to_fun = f := rfl
@[simp] lemma coe_fun_mk {f : α → β} (hf : _root_.monotone f) : (mk f hf : α → β) = f := rfl
@[ext] -- See library note [partially-applied ext lemmas]
lemma ext (f g : α →ₘ β) (h : (f : α → β) = g) : f = g :=
by { cases f, cases g, congr, exact h }
/-- One can lift an unbundled monotone function to a bundled one. -/
instance : can_lift (α → β) (α →ₘ β) :=
{ coe := coe_fn,
cond := monotone,
prf := λ f h, ⟨⟨f, h⟩, rfl⟩ }
/-- The identity function as bundled monotone function. -/
@[simps {fully_applied := ff}]
def id : α →ₘ α := ⟨id, monotone_id⟩
instance : inhabited (α →ₘ α) := ⟨id⟩
/-- The preorder structure of `α →ₘ β` is pointwise inequality: `f ≤ g ↔ ∀ a, f a ≤ g a`. -/
instance : preorder (α →ₘ β) :=
@preorder.lift (α →ₘ β) (α → β) _ coe_fn
instance {β : Type*} [partial_order β] : partial_order (α →ₘ β) :=
@partial_order.lift (α →ₘ β) (α → β) _ coe_fn ext
lemma le_def {f g : α →ₘ β} : f ≤ g ↔ ∀ x, f x ≤ g x := iff.rfl
@[simp, norm_cast] lemma coe_le_coe {f g : α →ₘ β} : (f : α → β) ≤ g ↔ f ≤ g := iff.rfl
@[simp] lemma mk_le_mk {f g : α → β} {hf hg} : mk f hf ≤ mk g hg ↔ f ≤ g := iff.rfl
@[mono] lemma apply_mono {f g : α →ₘ β} {x y : α} (h₁ : f ≤ g) (h₂ : x ≤ y) :
f x ≤ g y :=
(h₁ x).trans $ g.mono h₂
/-- Curry/uncurry as an order isomorphism between `α × β →ₘ γ` and `α →ₘ β →ₘ γ`. -/
def curry : (α × β →ₘ γ) ≃o (α →ₘ β →ₘ γ) :=
{ to_fun := λ f, ⟨λ x, ⟨function.curry f x, λ y₁ y₂ h, f.mono ⟨le_rfl, h⟩⟩,
λ x₁ x₂ h y, f.mono ⟨h, le_rfl⟩⟩,
inv_fun := λ f, ⟨function.uncurry (λ x, f x), λ x y h, (f.mono h.1 x.2).trans $ (f y.1).mono h.2⟩,
left_inv := λ f, by { ext ⟨x, y⟩, refl },
right_inv := λ f, by { ext x y, refl },
map_rel_iff' := λ f g, by simp [le_def] }
@[simp] lemma curry_apply (f : α × β →ₘ γ) (x : α) (y : β) : curry f x y = f (x, y) := rfl
@[simp] lemma curry_symm_apply (f : α →ₘ β →ₘ γ) (x : α × β) : curry.symm f x = f x.1 x.2 := rfl
/-- The composition of two bundled monotone functions. -/
@[simps {fully_applied := ff}]
def comp (g : β →ₘ γ) (f : α →ₘ β) : α →ₘ γ := ⟨g ∘ f, g.mono.comp f.mono⟩
@[mono] lemma comp_mono ⦃g₁ g₂ : β →ₘ γ⦄ (hg : g₁ ≤ g₂) ⦃f₁ f₂ : α →ₘ β⦄ (hf : f₁ ≤ f₂) :
g₁.comp f₁ ≤ g₂.comp f₂ :=
λ x, (hg _).trans (g₂.mono $ hf _)
/-- The composition of two bundled monotone functions, a fully bundled version. -/
@[simps {fully_applied := ff}]
def compₘ : (β →ₘ γ) →ₘ (α →ₘ β) →ₘ α →ₘ γ :=
curry ⟨λ f : (β →ₘ γ) × (α →ₘ β), f.1.comp f.2, λ f₁ f₂ h, comp_mono h.1 h.2⟩
@[simp] lemma comp_id (f : α →ₘ β) : comp f id = f :=
by { ext, refl }
@[simp] lemma id_comp (f : α →ₘ β) : comp id f = f :=
by { ext, refl }
/-- Constant function bundled as a `preorder_hom`. -/
@[simps {fully_applied := ff}]
def const (α : Type*) [preorder α] {β : Type*} [preorder β] : β →ₘ α →ₘ β :=
{ to_fun := λ b, ⟨function.const α b, λ _ _ _, le_rfl⟩,
monotone' := λ b₁ b₂ h x, h }
@[simp] lemma const_comp (f : α →ₘ β) (c : γ) : (const β c).comp f = const α c := rfl
@[simp] lemma comp_const (γ : Type*) [preorder γ] (f : α →ₘ β) (c : α) :
f.comp (const γ c) = const γ (f c) := rfl
/-- Given two bundled monotone maps `f`, `g`, `f.prod g` is the map `x ↦ (f x, g x)` bundled as a
`preorder_hom`. -/
@[simps] protected def prod (f : α →ₘ β) (g : α →ₘ γ) : α →ₘ (β × γ) :=
⟨λ x, (f x, g x), λ x y h, ⟨f.mono h, g.mono h⟩⟩
@[mono] lemma prod_mono {f₁ f₂ : α →ₘ β} (hf : f₁ ≤ f₂) {g₁ g₂ : α →ₘ γ} (hg : g₁ ≤ g₂) :
f₁.prod g₁ ≤ f₂.prod g₂ :=
λ x, prod.le_def.2 ⟨hf _, hg _⟩
lemma comp_prod_comp_same (f₁ f₂ : β →ₘ γ) (g : α →ₘ β) :
(f₁.comp g).prod (f₂.comp g) = (f₁.prod f₂).comp g :=
rfl
/-- Given two bundled monotone maps `f`, `g`, `f.prod g` is the map `x ↦ (f x, g x)` bundled as a
`preorder_hom`. This is a fully bundled version. -/
@[simps] def prodₘ : (α →ₘ β) →ₘ (α →ₘ γ) →ₘ α →ₘ β × γ :=
curry ⟨λ f : (α →ₘ β) × (α →ₘ γ), f.1.prod f.2, λ f₁ f₂ h, prod_mono h.1 h.2⟩
/-- Diagonal embedding of `α` into `α × α` as a `preorder_hom`. -/
@[simps] def diag : α →ₘ α × α := id.prod id
/-- Restriction of `f : α →ₘ α →ₘ β` to the diagonal. -/
@[simps {simp_rhs := tt}] def on_diag (f : α →ₘ α →ₘ β) : α →ₘ β := (curry.symm f).comp diag
/-- `prod.fst` as a `preorder_hom`. -/
@[simps] def fst : α × β →ₘ α := ⟨prod.fst, λ x y h, h.1⟩
/-- `prod.snd` as a `preorder_hom`. -/
@[simps] def snd : α × β →ₘ β := ⟨prod.snd, λ x y h, h.2⟩
@[simp] lemma fst_prod_snd : (fst : α × β →ₘ α).prod snd = id :=
by { ext ⟨x, y⟩ : 2, refl }
@[simp] lemma fst_comp_prod (f : α →ₘ β) (g : α →ₘ γ) : fst.comp (f.prod g) = f := ext _ _ rfl
@[simp] lemma snd_comp_prod (f : α →ₘ β) (g : α →ₘ γ) : snd.comp (f.prod g) = g := ext _ _ rfl
/-- Order isomorphism between the space of monotone maps to `β × γ` and the product of the spaces
of monotone maps to `β` and `γ`. -/
@[simps] def prod_iso : (α →ₘ β × γ) ≃o (α →ₘ β) × (α →ₘ γ) :=
{ to_fun := λ f, (fst.comp f, snd.comp f),
inv_fun := λ f, f.1.prod f.2,
left_inv := λ f, by ext; refl,
right_inv := λ f, by ext; refl,
map_rel_iff' := λ f g, forall_and_distrib.symm }
/-- `prod.map` of two `preorder_hom`s as a `preorder_hom`. -/
@[simps] def prod_map (f : α →ₘ β) (g : γ →ₘ δ) : α × γ →ₘ β × δ :=
⟨prod.map f g, λ x y h, ⟨f.mono h.1, g.mono h.2⟩⟩
variables {ι : Type*} {π : ι → Type*} [Π i, preorder (π i)]
/-- Evaluation of an unbundled function at a point (`function.eval`) as a `preorder_hom`. -/
@[simps {fully_applied := ff}]
def _root_.pi.eval_preorder_hom (i : ι) : (Π j, π j) →ₘ π i :=
⟨function.eval i, function.monotone_eval i⟩
/-- The "forgetful functor" from `α →ₘ β` to `α → β` that takes the underlying function,
is monotone. -/
@[simps {fully_applied := ff}] def coe_fn_hom : (α →ₘ β) →ₘ (α → β) :=
{ to_fun := λ f, f,
monotone' := λ x y h, h }
/-- Function application `λ f, f a` (for fixed `a`) is a monotone function from the
monotone function space `α →ₘ β` to `β`. See also `pi.eval_preorder_hom`. -/
@[simps {fully_applied := ff}] def apply (x : α) : (α →ₘ β) →ₘ β :=
(pi.eval_preorder_hom x).comp coe_fn_hom
/-- Construct a bundled monotone map `α →ₘ Π i, π i` from a family of monotone maps
`f i : α →ₘ π i`. -/
@[simps] def pi (f : Π i, α →ₘ π i) : α →ₘ (Π i, π i) :=
⟨λ x i, f i x, λ x y h i, (f i).mono h⟩
/-- Order isomorphism between bundled monotone maps `α →ₘ Π i, π i` and families of bundled monotone
maps `Π i, α →ₘ π i`. -/
@[simps] def pi_iso : (α →ₘ Π i, π i) ≃o Π i, α →ₘ π i :=
{ to_fun := λ f i, (pi.eval_preorder_hom i).comp f,
inv_fun := pi,
left_inv := λ f, by { ext x i, refl },
right_inv := λ f, by { ext x i, refl },
map_rel_iff' := λ f g, forall_swap }
/-- `subtype.val` as a bundled monotone function. -/
@[simps {fully_applied := ff}]
def subtype.val (p : α → Prop) : subtype p →ₘ α :=
⟨subtype.val, λ x y h, h⟩
-- TODO[gh-6025]: make this a global instance once safe to do so
/-- There is a unique monotone map from a subsingleton to itself. -/
local attribute [instance]
def unique [subsingleton α] : unique (α →ₘ α) :=
{ default := preorder_hom.id, uniq := λ a, ext _ _ (subsingleton.elim _ _) }
lemma preorder_hom_eq_id [subsingleton α] (g : α →ₘ α) : g = preorder_hom.id :=
subsingleton.elim _ _
/-- Reinterpret a bundled monotone function as a monotone function between dual orders. -/
@[simps] protected def dual : (α →ₘ β) ≃ (order_dual α →ₘ order_dual β) :=
{ to_fun := λ f, ⟨order_dual.to_dual ∘ f ∘ order_dual.of_dual, f.mono.dual⟩,
inv_fun := λ f, ⟨order_dual.of_dual ∘ f ∘ order_dual.to_dual, f.mono.dual⟩,
left_inv := λ f, ext _ _ rfl,
right_inv := λ f, ext _ _ rfl }
/-- `preorder_hom.dual` as an order isomorphism. -/
def dual_iso (α β : Type*) [preorder α] [preorder β] :
(α →ₘ β) ≃o order_dual (order_dual α →ₘ order_dual β) :=
{ to_equiv := preorder_hom.dual.trans order_dual.to_dual,
map_rel_iff' := λ f g, iff.rfl }
@[simps]
instance {β : Type*} [semilattice_sup β] : has_sup (α →ₘ β) :=
{ sup := λ f g, ⟨λ a, f a ⊔ g a, f.mono.sup g.mono⟩ }
instance {β : Type*} [semilattice_sup β] : semilattice_sup (α →ₘ β) :=
{ sup := has_sup.sup,
le_sup_left := λ a b x, le_sup_left,
le_sup_right := λ a b x, le_sup_right,
sup_le := λ a b c h₀ h₁ x, sup_le (h₀ x) (h₁ x),
.. (_ : partial_order (α →ₘ β)) }
@[simps]
instance {β : Type*} [semilattice_inf β] : has_inf (α →ₘ β) :=
{ inf := λ f g, ⟨λ a, f a ⊓ g a, f.mono.inf g.mono⟩ }
instance {β : Type*} [semilattice_inf β] : semilattice_inf (α →ₘ β) :=
{ inf := (⊓),
.. (_ : partial_order (α →ₘ β)),
.. (dual_iso α β).symm.to_galois_insertion.lift_semilattice_inf }
instance {β : Type*} [lattice β] : lattice (α →ₘ β) :=
{ .. (_ : semilattice_sup (α →ₘ β)),
.. (_ : semilattice_inf (α →ₘ β)) }
@[simps]
instance {β : Type*} [order_bot β] : has_bot (α →ₘ β) :=
{ bot := const α ⊥ }
instance {β : Type*} [order_bot β] : order_bot (α →ₘ β) :=
{ bot := ⊥,
bot_le := λ a x, bot_le,
.. (_ : partial_order (α →ₘ β)) }
@[simps]
instance {β : Type*} [order_top β] : has_top (α →ₘ β) :=
{ top := const α ⊤ }
instance {β : Type*} [order_top β] : order_top (α →ₘ β) :=
{ top := ⊤,
le_top := λ a x, le_top,
.. (_ : partial_order (α →ₘ β)) }
instance {β : Type*} [complete_lattice β] : has_Inf (α →ₘ β) :=
{ Inf := λ s, ⟨λ x, ⨅ f ∈ s, (f : _) x, λ x y h, binfi_le_binfi (λ f _, f.mono h)⟩ }
@[simp] lemma Inf_apply {β : Type*} [complete_lattice β] (s : set (α →ₘ β)) (x : α) :
Inf s x = ⨅ f ∈ s, (f : _) x := rfl
lemma infi_apply {ι : Sort*} {β : Type*} [complete_lattice β] (f : ι → α →ₘ β) (x : α) :
(⨅ i, f i) x = ⨅ i, f i x :=
(Inf_apply _ _).trans infi_range
@[simp, norm_cast] lemma coe_infi {ι : Sort*} {β : Type*} [complete_lattice β] (f : ι → α →ₘ β) :
((⨅ i, f i : α →ₘ β) : α → β) = ⨅ i, f i :=
funext $ λ x, (infi_apply f x).trans (@_root_.infi_apply _ _ _ _ (λ i, f i) _).symm
instance {β : Type*} [complete_lattice β] : has_Sup (α →ₘ β) :=
{ Sup := λ s, ⟨λ x, ⨆ f ∈ s, (f : _) x, λ x y h, bsupr_le_bsupr (λ f _, f.mono h)⟩ }
@[simp] lemma Sup_apply {β : Type*} [complete_lattice β] (s : set (α →ₘ β)) (x : α) :
Sup s x = ⨆ f ∈ s, (f : _) x := rfl
lemma supr_apply {ι : Sort*} {β : Type*} [complete_lattice β] (f : ι → α →ₘ β) (x : α) :
(⨆ i, f i) x = ⨆ i, f i x :=
(Sup_apply _ _).trans supr_range
@[simp, norm_cast] lemma coe_supr {ι : Sort*} {β : Type*} [complete_lattice β] (f : ι → α →ₘ β) :
((⨆ i, f i : α →ₘ β) : α → β) = ⨆ i, f i :=
funext $ λ x, (supr_apply f x).trans (@_root_.supr_apply _ _ _ _ (λ i, f i) _).symm
instance {β : Type*} [complete_lattice β] : complete_lattice (α →ₘ β) :=
{ Sup := Sup,
le_Sup := λ s f hf x, le_supr_of_le f (le_supr _ hf),
Sup_le := λ s f hf x, bsupr_le (λ g hg, hf g hg x),
Inf := Inf,
le_Inf := λ s f hf x, le_binfi (λ g hg, hf g hg x),
Inf_le := λ s f hf x, infi_le_of_le f (infi_le _ hf),
.. (_ : lattice (α →ₘ β)),
.. (_ : order_top (α →ₘ β)),
.. (_ : order_bot (α →ₘ β)) }
lemma iterate_sup_le_sup_iff {α : Type*} [semilattice_sup α] (f : α →ₘ α) :
(∀ n₁ n₂ a₁ a₂, f^[n₁ + n₂] (a₁ ⊔ a₂) ≤ (f^[n₁] a₁) ⊔ (f^[n₂] a₂)) ↔
(∀ a₁ a₂, f (a₁ ⊔ a₂) ≤ (f a₁) ⊔ a₂) :=
begin
split; intros h,
{ exact h 1 0, },
{ intros n₁ n₂ a₁ a₂, have h' : ∀ n a₁ a₂, f^[n] (a₁ ⊔ a₂) ≤ (f^[n] a₁) ⊔ a₂,
{ intros n, induction n with n ih; intros a₁ a₂,
{ refl, },
{ calc f^[n + 1] (a₁ ⊔ a₂) = (f^[n] (f (a₁ ⊔ a₂))) : function.iterate_succ_apply f n _
... ≤ (f^[n] ((f a₁) ⊔ a₂)) : f.mono.iterate n (h a₁ a₂)
... ≤ (f^[n] (f a₁)) ⊔ a₂ : ih _ _
... = (f^[n + 1] a₁) ⊔ a₂ : by rw ← function.iterate_succ_apply, }, },
calc f^[n₁ + n₂] (a₁ ⊔ a₂) = (f^[n₁] (f^[n₂] (a₁ ⊔ a₂))) : function.iterate_add_apply f n₁ n₂ _
... = (f^[n₁] (f^[n₂] (a₂ ⊔ a₁))) : by rw sup_comm
... ≤ (f^[n₁] ((f^[n₂] a₂) ⊔ a₁)) : f.mono.iterate n₁ (h' n₂ _ _)
... = (f^[n₁] (a₁ ⊔ (f^[n₂] a₂))) : by rw sup_comm
... ≤ (f^[n₁] a₁) ⊔ (f^[n₂] a₂) : h' n₁ a₁ _, },
end
end preorder_hom
namespace order_embedding
/-- Convert an `order_embedding` to a `preorder_hom`. -/
@[simps {fully_applied := ff}]
def to_preorder_hom {X Y : Type*} [preorder X] [preorder Y] (f : X ↪o Y) : X →ₘ Y :=
{ to_fun := f,
monotone' := f.monotone }
end order_embedding
section rel_hom
variables {α β : Type*} [partial_order α] [preorder β]
namespace rel_hom
variables (f : ((<) : α → α → Prop) →r ((<) : β → β → Prop))
/-- A bundled expression of the fact that a map between partial orders that is strictly monotone
is weakly monotone. -/
@[simps {fully_applied := ff}]
def to_preorder_hom : α →ₘ β :=
{ to_fun := f,
monotone' := strict_mono.monotone (λ x y, f.map_rel), }
end rel_hom
lemma rel_embedding.to_preorder_hom_injective (f : ((<) : α → α → Prop) ↪r ((<) : β → β → Prop)) :
function.injective (f : ((<) : α → α → Prop) →r ((<) : β → β → Prop)).to_preorder_hom :=
λ _ _ h, f.injective h
end rel_hom
|
a46011c6b1e1e80198974e7aefa27e9eb54fff52 | 8e6cad62ec62c6c348e5faaa3c3f2079012bdd69 | /src/topology/uniform_space/cauchy.lean | e2906cf63b63c48fb4bc55e57faab0315a6a53d1 | [
"Apache-2.0"
] | permissive | benjamindavidson/mathlib | 8cc81c865aa8e7cf4462245f58d35ae9a56b150d | fad44b9f670670d87c8e25ff9cdf63af87ad731e | refs/heads/master | 1,679,545,578,362 | 1,615,343,014,000 | 1,615,343,014,000 | 312,926,983 | 0 | 0 | Apache-2.0 | 1,615,360,301,000 | 1,605,399,418,000 | Lean | UTF-8 | Lean | false | false | 27,036 | lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro
-/
import topology.uniform_space.basic
import topology.bases
import data.set.intervals
/-!
# Theory of Cauchy filters in uniform spaces. Complete uniform spaces. Totally bounded subsets.
-/
universes u v
open filter topological_space set classical uniform_space
open_locale classical uniformity topological_space filter
variables {α : Type u} {β : Type v} [uniform_space α]
/-- A filter `f` is Cauchy if for every entourage `r`, there exists an
`s ∈ f` such that `s × s ⊆ r`. This is a generalization of Cauchy
sequences, because if `a : ℕ → α` then the filter of sets containing
cofinitely many of the `a n` is Cauchy iff `a` is a Cauchy sequence. -/
def cauchy (f : filter α) := ne_bot f ∧ f ×ᶠ f ≤ (𝓤 α)
/-- A set `s` is called *complete*, if any Cauchy filter `f` such that `s ∈ f`
has a limit in `s` (formally, it satisfies `f ≤ 𝓝 x` for some `x ∈ s`). -/
def is_complete (s : set α) := ∀f, cauchy f → f ≤ 𝓟 s → ∃x∈s, f ≤ 𝓝 x
lemma filter.has_basis.cauchy_iff {p : β → Prop} {s : β → set (α × α)} (h : (𝓤 α).has_basis p s)
{f : filter α} :
cauchy f ↔ (ne_bot f ∧ (∀ i, p i → ∃ t ∈ f, ∀ x y ∈ t, (x, y) ∈ s i)) :=
and_congr iff.rfl $ (f.basis_sets.prod_self.le_basis_iff h).trans $
by simp only [subset_def, prod.forall, mem_prod_eq, and_imp, id]
lemma cauchy_iff' {f : filter α} :
cauchy f ↔ (ne_bot f ∧ (∀ s ∈ 𝓤 α, ∃t∈f, ∀ x y ∈ t, (x, y) ∈ s)) :=
(𝓤 α).basis_sets.cauchy_iff
lemma cauchy_iff {f : filter α} :
cauchy f ↔ (ne_bot f ∧ (∀ s ∈ 𝓤 α, ∃t∈f, (set.prod t t) ⊆ s)) :=
(𝓤 α).basis_sets.cauchy_iff.trans $
by simp only [subset_def, prod.forall, mem_prod_eq, and_imp, id]
lemma cauchy_map_iff {l : filter β} {f : β → α} :
cauchy (l.map f) ↔ (ne_bot l ∧ tendsto (λp:β×β, (f p.1, f p.2)) (l ×ᶠ l) (𝓤 α)) :=
by rw [cauchy, map_ne_bot_iff, prod_map_map_eq, tendsto]
lemma cauchy_map_iff' {l : filter β} [hl : ne_bot l] {f : β → α} :
cauchy (l.map f) ↔ tendsto (λp:β×β, (f p.1, f p.2)) (l ×ᶠ l) (𝓤 α) :=
cauchy_map_iff.trans $ and_iff_right hl
lemma cauchy.mono {f g : filter α} [hg : ne_bot g] (h_c : cauchy f) (h_le : g ≤ f) : cauchy g :=
⟨hg, le_trans (filter.prod_mono h_le h_le) h_c.right⟩
lemma cauchy.mono' {f g : filter α} (h_c : cauchy f) (hg : ne_bot g) (h_le : g ≤ f) : cauchy g :=
h_c.mono h_le
lemma cauchy_nhds {a : α} : cauchy (𝓝 a) :=
⟨nhds_ne_bot,
calc 𝓝 a ×ᶠ 𝓝 a =
(𝓤 α).lift (λs:set (α×α), (𝓤 α).lift' (λt:set(α×α),
set.prod {y : α | (y, a) ∈ s} {y : α | (a, y) ∈ t})) : nhds_nhds_eq_uniformity_uniformity_prod
... ≤ (𝓤 α).lift' (λs:set (α×α), comp_rel s s) :
le_infi $ assume s, le_infi $ assume hs,
infi_le_of_le s $ infi_le_of_le hs $ infi_le_of_le s $ infi_le_of_le hs $
principal_mono.mpr $
assume ⟨x, y⟩ ⟨(hx : (x, a) ∈ s), (hy : (a, y) ∈ s)⟩, ⟨a, hx, hy⟩
... ≤ 𝓤 α : comp_le_uniformity⟩
lemma cauchy_pure {a : α} : cauchy (pure a) :=
cauchy_nhds.mono (pure_le_nhds a)
lemma filter.tendsto.cauchy_map {l : filter β} [ne_bot l] {f : β → α} {a : α}
(h : tendsto f l (𝓝 a)) :
cauchy (map f l) :=
cauchy_nhds.mono h
/-- The common part of the proofs of `le_nhds_of_cauchy_adhp` and
`sequentially_complete.le_nhds_of_seq_tendsto_nhds`: if for any entourage `s`
one can choose a set `t ∈ f` of diameter `s` such that it contains a point `y`
with `(x, y) ∈ s`, then `f` converges to `x`. -/
lemma le_nhds_of_cauchy_adhp_aux {f : filter α} {x : α}
(adhs : ∀ s ∈ 𝓤 α, ∃ t ∈ f, (set.prod t t ⊆ s) ∧ ∃ y, (x, y) ∈ s ∧ y ∈ t) :
f ≤ 𝓝 x :=
begin
-- Consider a neighborhood `s` of `x`
assume s hs,
-- Take an entourage twice smaller than `s`
rcases comp_mem_uniformity_sets (mem_nhds_uniformity_iff_right.1 hs) with ⟨U, U_mem, hU⟩,
-- Take a set `t ∈ f`, `t × t ⊆ U`, and a point `y ∈ t` such that `(x, y) ∈ U`
rcases adhs U U_mem with ⟨t, t_mem, ht, y, hxy, hy⟩,
apply mem_sets_of_superset t_mem,
-- Given a point `z ∈ t`, we have `(x, y) ∈ U` and `(y, z) ∈ t × t ⊆ U`, hence `z ∈ s`
exact (λ z hz, hU (prod_mk_mem_comp_rel hxy (ht $ mk_mem_prod hy hz)) rfl)
end
/-- If `x` is an adherent (cluster) point for a Cauchy filter `f`, then it is a limit point
for `f`. -/
lemma le_nhds_of_cauchy_adhp {f : filter α} {x : α} (hf : cauchy f)
(adhs : cluster_pt x f) : f ≤ 𝓝 x :=
le_nhds_of_cauchy_adhp_aux
begin
assume s hs,
obtain ⟨t, t_mem, ht⟩ : ∃ t ∈ f, set.prod t t ⊆ s,
from (cauchy_iff.1 hf).2 s hs,
use [t, t_mem, ht],
exact (forall_sets_nonempty_iff_ne_bot.2 adhs _
(inter_mem_inf_sets (mem_nhds_left x hs) t_mem ))
end
lemma le_nhds_iff_adhp_of_cauchy {f : filter α} {x : α} (hf : cauchy f) :
f ≤ 𝓝 x ↔ cluster_pt x f :=
⟨assume h, cluster_pt.of_le_nhds' h hf.1, le_nhds_of_cauchy_adhp hf⟩
lemma cauchy.map [uniform_space β] {f : filter α} {m : α → β}
(hf : cauchy f) (hm : uniform_continuous m) : cauchy (map m f) :=
⟨hf.1.map _,
calc map m f ×ᶠ map m f = map (λp:α×α, (m p.1, m p.2)) (f ×ᶠ f) : filter.prod_map_map_eq
... ≤ map (λp:α×α, (m p.1, m p.2)) (𝓤 α) : map_mono hf.right
... ≤ 𝓤 β : hm⟩
lemma cauchy.comap [uniform_space β] {f : filter β} {m : α → β}
(hf : cauchy f) (hm : comap (λp:α×α, (m p.1, m p.2)) (𝓤 β) ≤ 𝓤 α)
[ne_bot (comap m f)] : cauchy (comap m f) :=
⟨‹_›,
calc comap m f ×ᶠ comap m f = comap (λp:α×α, (m p.1, m p.2)) (f ×ᶠ f) : filter.prod_comap_comap_eq
... ≤ comap (λp:α×α, (m p.1, m p.2)) (𝓤 β) : comap_mono hf.right
... ≤ 𝓤 α : hm⟩
lemma cauchy.comap' [uniform_space β] {f : filter β} {m : α → β}
(hf : cauchy f) (hm : comap (λp:α×α, (m p.1, m p.2)) (𝓤 β) ≤ 𝓤 α)
(hb : ne_bot (comap m f)) : cauchy (comap m f) :=
hf.comap hm
/-- Cauchy sequences. Usually defined on ℕ, but often it is also useful to say that a function
defined on ℝ is Cauchy at +∞ to deduce convergence. Therefore, we define it in a type class that
is general enough to cover both ℕ and ℝ, which are the main motivating examples. -/
def cauchy_seq [semilattice_sup β] (u : β → α) := cauchy (at_top.map u)
lemma cauchy_seq.mem_entourage {ι : Type*} [nonempty ι] [linear_order ι] {u : ι → α}
(h : cauchy_seq u) {V : set (α × α)} (hV : V ∈ 𝓤 α) :
∃ k₀, ∀ i j, k₀ ≤ i → k₀ ≤ j → (u i, u j) ∈ V :=
begin
have := h.right hV,
obtain ⟨⟨i₀, j₀⟩, H⟩ : ∃ a, ∀ b : ι × ι, b ≥ a → prod.map u u b ∈ V,
by rwa [prod_map_at_top_eq, mem_map, mem_at_top_sets] at this,
refine ⟨max i₀ j₀, _⟩,
intros i j hi hj,
exact H (i, j) ⟨le_of_max_le_left hi, le_of_max_le_right hj⟩,
end
lemma filter.tendsto.cauchy_seq [semilattice_sup β] [nonempty β] {f : β → α} {x}
(hx : tendsto f at_top (𝓝 x)) :
cauchy_seq f :=
hx.cauchy_map
lemma cauchy_seq_iff_tendsto [nonempty β] [semilattice_sup β] {u : β → α} :
cauchy_seq u ↔ tendsto (prod.map u u) at_top (𝓤 α) :=
cauchy_map_iff'.trans $ by simp only [prod_at_top_at_top_eq, prod.map_def]
/-- If a Cauchy sequence has a convergent subsequence, then it converges. -/
lemma tendsto_nhds_of_cauchy_seq_of_subseq
[semilattice_sup β] {u : β → α} (hu : cauchy_seq u)
{ι : Type*} {f : ι → β} {p : filter ι} [ne_bot p]
(hf : tendsto f p at_top) {a : α} (ha : tendsto (u ∘ f) p (𝓝 a)) :
tendsto u at_top (𝓝 a) :=
le_nhds_of_cauchy_adhp hu (map_cluster_pt_of_comp hf ha)
@[nolint ge_or_gt] -- see Note [nolint_ge]
lemma filter.has_basis.cauchy_seq_iff {γ} [nonempty β] [semilattice_sup β] {u : β → α}
{p : γ → Prop} {s : γ → set (α × α)} (h : (𝓤 α).has_basis p s) :
cauchy_seq u ↔ ∀ i, p i → ∃N, ∀m n≥N, (u m, u n) ∈ s i :=
begin
rw [cauchy_seq_iff_tendsto, ← prod_at_top_at_top_eq],
refine (at_top_basis.prod_self.tendsto_iff h).trans _,
simp only [exists_prop, true_and, maps_to, preimage, subset_def, prod.forall,
mem_prod_eq, mem_set_of_eq, mem_Ici, and_imp, prod.map]
end
lemma filter.has_basis.cauchy_seq_iff' {γ} [nonempty β] [semilattice_sup β] {u : β → α}
{p : γ → Prop} {s : γ → set (α × α)} (H : (𝓤 α).has_basis p s) :
cauchy_seq u ↔ ∀ i, p i → ∃N, ∀n≥N, (u n, u N) ∈ s i :=
begin
refine H.cauchy_seq_iff.trans ⟨λ h i hi, _, λ h i hi, _⟩,
{ exact (h i hi).imp (λ N hN n hn, hN n N hn (le_refl N)) },
{ rcases comp_symm_of_uniformity (H.mem_of_mem hi) with ⟨t, ht, ht', hts⟩,
rcases H.mem_iff.1 ht with ⟨j, hj, hjt⟩,
refine (h j hj).imp (λ N hN m n hm hn, hts ⟨u N, hjt _, ht' $ hjt _⟩),
{ exact hN m hm },
{ exact hN n hn } }
end
lemma cauchy_seq_of_controlled [semilattice_sup β] [nonempty β]
(U : β → set (α × α)) (hU : ∀ s ∈ 𝓤 α, ∃ n, U n ⊆ s)
{f : β → α} (hf : ∀ {N m n : β}, N ≤ m → N ≤ n → (f m, f n) ∈ U N) :
cauchy_seq f :=
cauchy_seq_iff_tendsto.2
begin
assume s hs,
rw [mem_map, mem_at_top_sets],
cases hU s hs with N hN,
refine ⟨(N, N), λ mn hmn, _⟩,
cases mn with m n,
exact hN (hf hmn.1 hmn.2)
end
/-- A complete space is defined here using uniformities. A uniform space
is complete if every Cauchy filter converges. -/
class complete_space (α : Type u) [uniform_space α] : Prop :=
(complete : ∀{f:filter α}, cauchy f → ∃x, f ≤ 𝓝 x)
lemma complete_univ {α : Type u} [uniform_space α] [complete_space α] :
is_complete (univ : set α) :=
begin
assume f hf _,
rcases complete_space.complete hf with ⟨x, hx⟩,
exact ⟨x, mem_univ x, hx⟩
end
lemma cauchy_prod [uniform_space β] {f : filter α} {g : filter β} :
cauchy f → cauchy g → cauchy (f ×ᶠ g)
| ⟨f_proper, hf⟩ ⟨g_proper, hg⟩ := ⟨filter.prod_ne_bot.2 ⟨f_proper, g_proper⟩,
let p_α := λp:(α×β)×(α×β), (p.1.1, p.2.1), p_β := λp:(α×β)×(α×β), (p.1.2, p.2.2) in
suffices (f.prod f).comap p_α ⊓ (g.prod g).comap p_β ≤ (𝓤 α).comap p_α ⊓ (𝓤 β).comap p_β,
by simpa [uniformity_prod, filter.prod, filter.comap_inf, filter.comap_comap, (∘),
inf_assoc, inf_comm, inf_left_comm],
inf_le_inf (filter.comap_mono hf) (filter.comap_mono hg)⟩
instance complete_space.prod [uniform_space β] [complete_space α] [complete_space β] :
complete_space (α × β) :=
{ complete := λ f hf,
let ⟨x1, hx1⟩ := complete_space.complete $ hf.map uniform_continuous_fst in
let ⟨x2, hx2⟩ := complete_space.complete $ hf.map uniform_continuous_snd in
⟨(x1, x2), by rw [nhds_prod_eq, filter.prod_def];
from filter.le_lift (λ s hs, filter.le_lift' $ λ t ht,
have H1 : prod.fst ⁻¹' s ∈ f.sets := hx1 hs,
have H2 : prod.snd ⁻¹' t ∈ f.sets := hx2 ht,
filter.inter_mem_sets H1 H2)⟩ }
/--If `univ` is complete, the space is a complete space -/
lemma complete_space_of_is_complete_univ (h : is_complete (univ : set α)) : complete_space α :=
⟨λ f hf, let ⟨x, _, hx⟩ := h f hf ((@principal_univ α).symm ▸ le_top) in ⟨x, hx⟩⟩
lemma complete_space_iff_is_complete_univ :
complete_space α ↔ is_complete (univ : set α) :=
⟨@complete_univ α _, complete_space_of_is_complete_univ⟩
lemma cauchy_iff_exists_le_nhds [complete_space α] {l : filter α} [ne_bot l] :
cauchy l ↔ (∃x, l ≤ 𝓝 x) :=
⟨complete_space.complete, assume ⟨x, hx⟩, cauchy_nhds.mono hx⟩
lemma cauchy_map_iff_exists_tendsto [complete_space α] {l : filter β} {f : β → α} [ne_bot l] :
cauchy (l.map f) ↔ (∃x, tendsto f l (𝓝 x)) :=
cauchy_iff_exists_le_nhds
/-- A Cauchy sequence in a complete space converges -/
theorem cauchy_seq_tendsto_of_complete [semilattice_sup β] [complete_space α]
{u : β → α} (H : cauchy_seq u) : ∃x, tendsto u at_top (𝓝 x) :=
complete_space.complete H
/-- If `K` is a complete subset, then any cauchy sequence in `K` converges to a point in `K` -/
lemma cauchy_seq_tendsto_of_is_complete [semilattice_sup β] {K : set α} (h₁ : is_complete K)
{u : β → α} (h₂ : ∀ n, u n ∈ K) (h₃ : cauchy_seq u) : ∃ v ∈ K, tendsto u at_top (𝓝 v) :=
h₁ _ h₃ $ le_principal_iff.2 $ mem_map_sets_iff.2 ⟨univ, univ_mem_sets,
by { simp only [image_univ], rintros _ ⟨n, rfl⟩, exact h₂ n }⟩
theorem cauchy.le_nhds_Lim [complete_space α] [nonempty α] {f : filter α} (hf : cauchy f) :
f ≤ 𝓝 (Lim f) :=
le_nhds_Lim (complete_space.complete hf)
theorem cauchy_seq.tendsto_lim [semilattice_sup β] [complete_space α] [nonempty α] {u : β → α}
(h : cauchy_seq u) :
tendsto u at_top (𝓝 $ lim at_top u) :=
h.le_nhds_Lim
lemma is_closed.is_complete [complete_space α] {s : set α}
(h : is_closed s) : is_complete s :=
λ f cf fs, let ⟨x, hx⟩ := complete_space.complete cf in
⟨x, is_closed_iff_cluster_pt.mp h x (cf.left.mono (le_inf hx fs)), hx⟩
/-- A set `s` is totally bounded if for every entourage `d` there is a finite
set of points `t` such that every element of `s` is `d`-near to some element of `t`. -/
def totally_bounded (s : set α) : Prop :=
∀d ∈ 𝓤 α, ∃t : set α, finite t ∧ s ⊆ (⋃y∈t, {x | (x,y) ∈ d})
theorem totally_bounded_iff_subset {s : set α} : totally_bounded s ↔
∀d ∈ 𝓤 α, ∃t ⊆ s, finite t ∧ s ⊆ (⋃y∈t, {x | (x,y) ∈ d}) :=
⟨λ H d hd, begin
rcases comp_symm_of_uniformity hd with ⟨r, hr, rs, rd⟩,
rcases H r hr with ⟨k, fk, ks⟩,
let u := {y ∈ k | ∃ x, x ∈ s ∧ (x, y) ∈ r},
let f : u → α := λ x, classical.some x.2.2,
have : ∀ x : u, f x ∈ s ∧ (f x, x.1) ∈ r := λ x, classical.some_spec x.2.2,
refine ⟨range f, _, _, _⟩,
{ exact range_subset_iff.2 (λ x, (this x).1) },
{ have : finite u := fk.subset (λ x h, h.1),
exact ⟨@set.fintype_range _ _ _ _ this.fintype⟩ },
{ intros x xs,
have := ks xs, simp at this,
rcases this with ⟨y, hy, xy⟩,
let z : coe_sort u := ⟨y, hy, x, xs, xy⟩,
exact mem_bUnion_iff.2 ⟨_, ⟨z, rfl⟩, rd $ mem_comp_rel.2 ⟨_, xy, rs (this z).2⟩⟩ }
end,
λ H d hd, let ⟨t, _, ht⟩ := H d hd in ⟨t, ht⟩⟩
lemma totally_bounded_of_forall_symm {s : set α}
(h : ∀ V ∈ 𝓤 α, symmetric_rel V → ∃ t : set α, finite t ∧ s ⊆ ⋃ y ∈ t, ball y V) :
totally_bounded s :=
begin
intros V V_in,
rcases h _ (symmetrize_mem_uniformity V_in) (symmetric_symmetrize_rel V) with ⟨t, tfin, h⟩,
refine ⟨t, tfin, subset.trans h _⟩,
mono,
intros x x_in z z_in,
exact z_in.right
end
lemma totally_bounded_subset {s₁ s₂ : set α} (hs : s₁ ⊆ s₂)
(h : totally_bounded s₂) : totally_bounded s₁ :=
assume d hd, let ⟨t, ht₁, ht₂⟩ := h d hd in ⟨t, ht₁, subset.trans hs ht₂⟩
lemma totally_bounded_empty : totally_bounded (∅ : set α) :=
λ d hd, ⟨∅, finite_empty, empty_subset _⟩
/-- The closure of a totally bounded set is totally bounded. -/
lemma totally_bounded.closure {s : set α} (h : totally_bounded s) :
totally_bounded (closure s) :=
assume t ht,
let ⟨t', ht', hct', htt'⟩ := mem_uniformity_is_closed ht, ⟨c, hcf, hc⟩ := h t' ht' in
⟨c, hcf,
calc closure s ⊆ closure (⋃ (y : α) (H : y ∈ c), {x : α | (x, y) ∈ t'}) : closure_mono hc
... = _ : is_closed.closure_eq $ is_closed_bUnion hcf $ assume i hi,
continuous_iff_is_closed.mp (continuous_id.prod_mk continuous_const) _ hct'
... ⊆ _ : bUnion_subset $ assume i hi, subset.trans (assume x, @htt' (x, i))
(subset_bUnion_of_mem hi)⟩
/-- The image of a totally bounded set under a unifromly continuous map is totally bounded. -/
lemma totally_bounded.image [uniform_space β] {f : α → β} {s : set α}
(hs : totally_bounded s) (hf : uniform_continuous f) : totally_bounded (f '' s) :=
assume t ht,
have {p:α×α | (f p.1, f p.2) ∈ t} ∈ 𝓤 α,
from hf ht,
let ⟨c, hfc, hct⟩ := hs _ this in
⟨f '' c, hfc.image f,
begin
simp [image_subset_iff],
simp [subset_def] at hct,
intros x hx, simp,
exact hct x hx
end⟩
lemma ultrafilter.cauchy_of_totally_bounded {s : set α} (f : ultrafilter α)
(hs : totally_bounded s) (h : ↑f ≤ 𝓟 s) : cauchy (f : filter α) :=
⟨f.ne_bot', assume t ht,
let ⟨t', ht'₁, ht'_symm, ht'_t⟩ := comp_symm_of_uniformity ht in
let ⟨i, hi, hs_union⟩ := hs t' ht'₁ in
have (⋃y∈i, {x | (x,y) ∈ t'}) ∈ f,
from mem_sets_of_superset (le_principal_iff.mp h) hs_union,
have ∃y∈i, {x | (x,y) ∈ t'} ∈ f,
from (ultrafilter.finite_bUnion_mem_iff hi).1 this,
let ⟨y, hy, hif⟩ := this in
have set.prod {x | (x,y) ∈ t'} {x | (x,y) ∈ t'} ⊆ comp_rel t' t',
from assume ⟨x₁, x₂⟩ ⟨(h₁ : (x₁, y) ∈ t'), (h₂ : (x₂, y) ∈ t')⟩,
⟨y, h₁, ht'_symm h₂⟩,
mem_sets_of_superset (prod_mem_prod hif hif) (subset.trans this ht'_t)⟩
lemma totally_bounded_iff_filter {s : set α} :
totally_bounded s ↔ (∀f, ne_bot f → f ≤ 𝓟 s → ∃c ≤ f, cauchy c) :=
begin
split,
{ introsI H f hf hfs,
exact ⟨ultrafilter.of f, ultrafilter.of_le f,
(ultrafilter.of f).cauchy_of_totally_bounded H ((ultrafilter.of_le f).trans hfs)⟩ },
{ intros H d hd,
contrapose! H with hd_cover,
set f := ⨅ t : finset α, 𝓟 (s \ ⋃ y ∈ t, {x | (x, y) ∈ d}),
have : ne_bot f,
{ refine infi_ne_bot_of_directed' (directed_of_sup _) _,
{ intros t₁ t₂ h,
exact principal_mono.2 (diff_subset_diff_right $ bUnion_subset_bUnion_left h) },
{ intro t,
simpa [nonempty_diff] using hd_cover t t.finite_to_set } },
have : f ≤ 𝓟 s, from infi_le_of_le ∅ (by simp),
refine ⟨f, ‹_›, ‹_›, λ c hcf hc, _⟩,
rcases mem_prod_same_iff.1 (hc.2 hd) with ⟨m, hm, hmd⟩,
have : m ∩ s ∈ c, from inter_mem_sets hm (le_principal_iff.mp (hcf.trans ‹_›)),
rcases hc.1.nonempty_of_mem this with ⟨y, hym, hys⟩,
set ys := ⋃ y' ∈ ({y} : finset α), {x | (x, y') ∈ d},
have : m ⊆ ys, by simpa [ys] using λ x hx, hmd (mk_mem_prod hx hym),
have : c ≤ 𝓟 (s \ ys) := hcf.trans (infi_le_of_le {y} le_rfl),
refine hc.1.ne (empty_in_sets_eq_bot.mp _),
filter_upwards [le_principal_iff.1 this, hm],
refine λ x hx hxm, hx.2 _,
simpa [ys] using hmd (mk_mem_prod hxm hym) }
end
lemma totally_bounded_iff_ultrafilter {s : set α} :
totally_bounded s ↔ (∀f : ultrafilter α, ↑f ≤ 𝓟 s → cauchy (f : filter α)) :=
begin
refine ⟨λ hs f, f.cauchy_of_totally_bounded hs, λ H, totally_bounded_iff_filter.2 _⟩,
introsI f hf hfs,
exact ⟨ultrafilter.of f, ultrafilter.of_le f, H _ ((ultrafilter.of_le f).trans hfs)⟩
end
lemma compact_iff_totally_bounded_complete {s : set α} :
is_compact s ↔ totally_bounded s ∧ is_complete s :=
⟨λ hs, ⟨totally_bounded_iff_ultrafilter.2 (λ f hf,
let ⟨x, xs, fx⟩ := compact_iff_ultrafilter_le_nhds.1 hs f hf in cauchy_nhds.mono fx),
λ f fc fs,
let ⟨a, as, fa⟩ := @hs f fc.1 fs in
⟨a, as, le_nhds_of_cauchy_adhp fc fa⟩⟩,
λ ⟨ht, hc⟩, compact_iff_ultrafilter_le_nhds.2
(λf hf, hc _ (totally_bounded_iff_ultrafilter.1 ht f hf) hf)⟩
@[priority 100] -- see Note [lower instance priority]
instance complete_of_compact {α : Type u} [uniform_space α] [compact_space α] : complete_space α :=
⟨λf hf, by simpa using (compact_iff_totally_bounded_complete.1 compact_univ).2 f hf⟩
lemma compact_of_totally_bounded_is_closed [complete_space α] {s : set α}
(ht : totally_bounded s) (hc : is_closed s) : is_compact s :=
(@compact_iff_totally_bounded_complete α _ s).2 ⟨ht, hc.is_complete⟩
/-!
### Sequentially complete space
In this section we prove that a uniform space is complete provided that it is sequentially complete
(i.e., any Cauchy sequence converges) and its uniformity filter admits a countable generating set.
In particular, this applies to (e)metric spaces, see the files `topology/metric_space/emetric_space`
and `topology/metric_space/basic`.
More precisely, we assume that there is a sequence of entourages `U_n` such that any other
entourage includes one of `U_n`. Then any Cauchy filter `f` generates a decreasing sequence of
sets `s_n ∈ f` such that `s_n × s_n ⊆ U_n`. Choose a sequence `x_n∈s_n`. It is easy to show
that this is a Cauchy sequence. If this sequence converges to some `a`, then `f ≤ 𝓝 a`. -/
namespace sequentially_complete
variables {f : filter α} (hf : cauchy f) {U : ℕ → set (α × α)}
(U_mem : ∀ n, U n ∈ 𝓤 α) (U_le : ∀ s ∈ 𝓤 α, ∃ n, U n ⊆ s)
open set finset
noncomputable theory
/-- An auxiliary sequence of sets approximating a Cauchy filter. -/
def set_seq_aux (n : ℕ) : {s : set α // ∃ (_ : s ∈ f), s.prod s ⊆ U n } :=
indefinite_description _ $ (cauchy_iff.1 hf).2 (U n) (U_mem n)
/-- Given a Cauchy filter `f` and a sequence `U` of entourages, `set_seq` provides
a sequence of monotonically decreasing sets `s n ∈ f` such that `(s n).prod (s n) ⊆ U`. -/
def set_seq (n : ℕ) : set α := ⋂ m ∈ Iic n, (set_seq_aux hf U_mem m).val
lemma set_seq_mem (n : ℕ) : set_seq hf U_mem n ∈ f :=
(bInter_mem_sets (finite_le_nat n)).2 (λ m _, (set_seq_aux hf U_mem m).2.fst)
lemma set_seq_mono ⦃m n : ℕ⦄ (h : m ≤ n) : set_seq hf U_mem n ⊆ set_seq hf U_mem m :=
bInter_subset_bInter_left (λ k hk, le_trans hk h)
lemma set_seq_sub_aux (n : ℕ) : set_seq hf U_mem n ⊆ set_seq_aux hf U_mem n :=
bInter_subset_of_mem right_mem_Iic
lemma set_seq_prod_subset {N m n} (hm : N ≤ m) (hn : N ≤ n) :
(set_seq hf U_mem m).prod (set_seq hf U_mem n) ⊆ U N :=
begin
assume p hp,
refine (set_seq_aux hf U_mem N).2.snd ⟨_, _⟩;
apply set_seq_sub_aux,
exact set_seq_mono hf U_mem hm hp.1,
exact set_seq_mono hf U_mem hn hp.2
end
/-- A sequence of points such that `seq n ∈ set_seq n`. Here `set_seq` is a monotonically
decreasing sequence of sets `set_seq n ∈ f` with diameters controlled by a given sequence
of entourages. -/
def seq (n : ℕ) : α := some $ hf.1.nonempty_of_mem (set_seq_mem hf U_mem n)
lemma seq_mem (n : ℕ) : seq hf U_mem n ∈ set_seq hf U_mem n :=
some_spec $ hf.1.nonempty_of_mem (set_seq_mem hf U_mem n)
lemma seq_pair_mem ⦃N m n : ℕ⦄ (hm : N ≤ m) (hn : N ≤ n) :
(seq hf U_mem m, seq hf U_mem n) ∈ U N :=
set_seq_prod_subset hf U_mem hm hn ⟨seq_mem hf U_mem m, seq_mem hf U_mem n⟩
include U_le
theorem seq_is_cauchy_seq : cauchy_seq $ seq hf U_mem :=
cauchy_seq_of_controlled U U_le $ seq_pair_mem hf U_mem
/-- If the sequence `sequentially_complete.seq` converges to `a`, then `f ≤ 𝓝 a`. -/
theorem le_nhds_of_seq_tendsto_nhds ⦃a : α⦄ (ha : tendsto (seq hf U_mem) at_top (𝓝 a)) :
f ≤ 𝓝 a :=
le_nhds_of_cauchy_adhp_aux
begin
assume s hs,
rcases U_le s hs with ⟨m, hm⟩,
rcases tendsto_at_top'.1 ha _ (mem_nhds_left a (U_mem m)) with ⟨n, hn⟩,
refine ⟨set_seq hf U_mem (max m n), set_seq_mem hf U_mem _, _,
seq hf U_mem (max m n), _, seq_mem hf U_mem _⟩,
{ have := le_max_left m n,
exact set.subset.trans (set_seq_prod_subset hf U_mem this this) hm },
{ exact hm (hn _ $ le_max_right m n) }
end
end sequentially_complete
namespace uniform_space
open sequentially_complete
variables (H : is_countably_generated (𝓤 α))
include H
/-- A uniform space is complete provided that (a) its uniformity filter has a countable basis;
(b) any sequence satisfying a "controlled" version of the Cauchy condition converges. -/
theorem complete_of_convergent_controlled_sequences (U : ℕ → set (α × α)) (U_mem : ∀ n, U n ∈ 𝓤 α)
(HU : ∀ u : ℕ → α, (∀ N m n, N ≤ m → N ≤ n → (u m, u n) ∈ U N) → ∃ a, tendsto u at_top (𝓝 a)) :
complete_space α :=
begin
rcases H.exists_antimono_seq' with ⟨U', U'_mono, hU'⟩,
have Hmem : ∀ n, U n ∩ U' n ∈ 𝓤 α,
from λ n, inter_mem_sets (U_mem n) (hU'.2 ⟨n, subset.refl _⟩),
refine ⟨λ f hf, (HU (seq hf Hmem) (λ N m n hm hn, _)).imp $
le_nhds_of_seq_tendsto_nhds _ _ (λ s hs, _)⟩,
{ rcases (hU'.1 hs) with ⟨N, hN⟩,
exact ⟨N, subset.trans (inter_subset_right _ _) hN⟩ },
{ exact inter_subset_left _ _ (seq_pair_mem hf Hmem hm hn) }
end
/-- A sequentially complete uniform space with a countable basis of the uniformity filter is
complete. -/
theorem complete_of_cauchy_seq_tendsto
(H' : ∀ u : ℕ → α, cauchy_seq u → ∃a, tendsto u at_top (𝓝 a)) :
complete_space α :=
let ⟨U', U'_mono, hU'⟩ := H.exists_antimono_seq' in
complete_of_convergent_controlled_sequences H U' (λ n, hU'.2 ⟨n, subset.refl _⟩)
(λ u hu, H' u $ cauchy_seq_of_controlled U' (λ s hs, hU'.1 hs) hu)
protected lemma first_countable_topology : first_countable_topology α :=
⟨λ a, by { rw nhds_eq_comap_uniformity, exact H.comap (prod.mk a) }⟩
/-- A separable uniform space with countably generated uniformity filter is second countable:
one obtains a countable basis by taking the balls centered at points in a dense subset,
and with rational "radii" from a countable open symmetric antimono basis of `𝓤 α`. We do not
register this as an instance, as there is already an instance going in the other direction
from second countable spaces to separable spaces, and we want to avoid loops. -/
lemma second_countable_of_separable [separable_space α] : second_countable_topology α :=
begin
rcases exists_countable_dense α with ⟨s, hsc, hsd⟩,
obtain ⟨t : ℕ → set (α × α),
hto : ∀ (i : ℕ), t i ∈ (𝓤 α).sets ∧ is_open (t i) ∧ symmetric_rel (t i),
h_basis : (𝓤 α).has_antimono_basis (λ _, true) t⟩ :=
H.exists_antimono_subbasis uniformity_has_basis_open_symmetric,
refine ⟨⟨⋃ (x ∈ s), range (λ k, ball x (t k)), hsc.bUnion (λ x hx, countable_range _), _⟩⟩,
refine (is_topological_basis_of_open_of_nhds _ _).2.2,
{ simp only [mem_bUnion_iff, mem_range],
rintros _ ⟨x, hxs, k, rfl⟩,
exact is_open_ball x (hto k).2.1 },
{ intros x V hxV hVo,
simp only [mem_bUnion_iff, mem_range, exists_prop],
rcases uniform_space.mem_nhds_iff.1 (mem_nhds_sets hVo hxV) with ⟨U, hU, hUV⟩,
rcases comp_symm_of_uniformity hU with ⟨U', hU', hsymm, hUU'⟩,
rcases h_basis.to_has_basis.mem_iff.1 hU' with ⟨k, -, hk⟩,
rcases hsd.inter_open_nonempty (ball x $ t k) (uniform_space.is_open_ball x (hto k).2.1)
⟨x, uniform_space.mem_ball_self _ (hto k).1⟩ with ⟨y, hxy, hys⟩,
refine ⟨_, ⟨y, hys, k, rfl⟩, (hto k).2.2.subset hxy, λ z hz, _⟩,
exact hUV (ball_subset_of_comp_subset (hk hxy) hUU' (hk hz)) }
end
end uniform_space
|
37374369dda60f955c91361e1ca89b3ff5bcce6b | 74addaa0e41490cbaf2abd313a764c96df57b05d | /Mathlib/algebra/ring/basic_auto.lean | e1222e4e317481db8df65315c507a564196b8d61 | [] | 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 | 47,329 | lean | /-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura, Floris van Doorn, Amelia Livingston, Yury Kudryashov,
Neil Strickland
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.algebra.divisibility
import Mathlib.data.set.basic
import Mathlib.PostPort
universes u_1 l x u v u_2 w
namespace Mathlib
/-!
# Properties and homomorphisms of semirings and rings
This file proves simple properties of semirings, rings and domains and their unit groups. It also
defines bundled homomorphisms of semirings and rings. As with monoid and groups, we use the same
structure `ring_hom a β`, a.k.a. `α →+* β`, for both homomorphism types.
The unbundled homomorphisms are defined in `deprecated/ring`. They are deprecated and the plan is to
slowly remove them from mathlib.
## Main definitions
ring_hom, nonzero, domain, integral_domain
## Notations
→+* for bundled ring homs (also use for semiring homs)
## Implementation notes
There's a coercion from bundled homs to fun, and the canonical
notation is to use the bundled hom as a function via this coercion.
There is no `semiring_hom` -- the idea is that `ring_hom` is used.
The constructor for a `ring_hom` between semirings needs a proof of `map_zero`, `map_one` and
`map_add` as well as `map_mul`; a separate constructor `ring_hom.mk'` will construct ring homs
between rings from monoid homs given only a proof that addition is preserved.
## Tags
`ring_hom`, `semiring_hom`, `semiring`, `comm_semiring`, `ring`, `comm_ring`, `domain`,
`integral_domain`, `nonzero`, `units`
-/
/-!
### `distrib` class
-/
/-- A typeclass stating that multiplication is left and right distributive
over addition. -/
class distrib (R : Type u_1) extends Mul R, Add R where
left_distrib : ∀ (a b c : R), a * (b + c) = a * b + a * c
right_distrib : ∀ (a b c : R), (a + b) * c = a * c + b * c
theorem left_distrib {R : Type x} [distrib R] (a : R) (b : R) (c : R) :
a * (b + c) = a * b + a * c :=
distrib.left_distrib a b c
theorem mul_add {R : Type x} [distrib R] (a : R) (b : R) (c : R) : a * (b + c) = a * b + a * c :=
left_distrib
theorem right_distrib {R : Type x} [distrib R] (a : R) (b : R) (c : R) :
(a + b) * c = a * c + b * c :=
distrib.right_distrib a b c
theorem add_mul {R : Type x} [distrib R] (a : R) (b : R) (c : R) : (a + b) * c = a * c + b * c :=
right_distrib
/-- Pullback a `distrib` instance along an injective function. -/
protected def function.injective.distrib {R : Type x} {S : Type u_1} [Mul R] [Add R] [distrib S]
(f : R → S) (hf : function.injective f) (add : ∀ (x y : R), f (x + y) = f x + f y)
(mul : ∀ (x y : R), f (x * y) = f x * f y) : distrib R :=
distrib.mk Mul.mul Add.add sorry sorry
/-- Pushforward a `distrib` instance along a surjective function. -/
protected def function.surjective.distrib {R : Type x} {S : Type u_1} [distrib R] [Add S] [Mul S]
(f : R → S) (hf : function.surjective f) (add : ∀ (x y : R), f (x + y) = f x + f y)
(mul : ∀ (x y : R), f (x * y) = f x * f y) : distrib S :=
distrib.mk Mul.mul Add.add sorry sorry
/-!
### Semirings
-/
/-- A semiring is a type with the following structures: additive commutative monoid
(`add_comm_monoid`), multiplicative monoid (`monoid`), distributive laws (`distrib`), and
multiplication by zero law (`mul_zero_class`). The actual definition extends `monoid_with_zero`
instead of `monoid` and `mul_zero_class`. -/
class semiring (α : Type u) extends monoid_with_zero α, distrib α, add_comm_monoid α where
/-- Pullback a `semiring` instance along an injective function. -/
protected def function.injective.semiring {α : Type u} {β : Type v} [semiring α] [HasZero β]
[HasOne β] [Add β] [Mul β] (f : β → α) (hf : function.injective f) (zero : f 0 = 0)
(one : f 1 = 1) (add : ∀ (x y : β), f (x + y) = f x + f y)
(mul : ∀ (x y : β), f (x * y) = f x * f y) : semiring β :=
semiring.mk add_comm_monoid.add sorry monoid_with_zero.zero sorry sorry sorry monoid_with_zero.mul
sorry monoid_with_zero.one sorry sorry sorry sorry sorry sorry
/-- Pullback a `semiring` instance along an injective function. -/
protected def function.surjective.semiring {α : Type u} {β : Type v} [semiring α] [HasZero β]
[HasOne β] [Add β] [Mul β] (f : α → β) (hf : function.surjective f) (zero : f 0 = 0)
(one : f 1 = 1) (add : ∀ (x y : α), f (x + y) = f x + f y)
(mul : ∀ (x y : α), f (x * y) = f x * f y) : semiring β :=
semiring.mk add_comm_monoid.add sorry monoid_with_zero.zero sorry sorry sorry monoid_with_zero.mul
sorry monoid_with_zero.one sorry sorry sorry sorry sorry sorry
theorem one_add_one_eq_two {α : Type u} [semiring α] : 1 + 1 = bit0 1 := sorry
theorem two_mul {α : Type u} [semiring α] (n : α) : bit0 1 * n = n + n := sorry
theorem distrib_three_right {α : Type u} [semiring α] (a : α) (b : α) (c : α) (d : α) :
(a + b + c) * d = a * d + b * d + c * d :=
sorry
theorem mul_two {α : Type u} [semiring α] (n : α) : n * bit0 1 = n + n := sorry
theorem bit0_eq_two_mul {α : Type u} [semiring α] (n : α) : bit0 n = bit0 1 * n :=
Eq.symm (two_mul n)
theorem add_ite {α : Type u_1} [Add α] (P : Prop) [Decidable P] (a : α) (b : α) (c : α) :
a + ite P b c = ite P (a + b) (a + c) :=
sorry
@[simp] theorem ite_mul {α : Type u_1} [Mul α] (P : Prop) [Decidable P] (a : α) (b : α) (c : α) :
ite P a b * c = ite P (a * c) (b * c) :=
sorry
-- We make `mul_ite` and `ite_mul` simp lemmas,
-- but not `add_ite` or `ite_add`.
-- The problem we're trying to avoid is dealing with
-- summations of the form `∑ x in s, (f x + ite P 1 0)`,
-- in which `add_ite` followed by `sum_ite` would needlessly slice up
-- the `f x` terms according to whether `P` holds at `x`.
-- There doesn't appear to be a corresponding difficulty so far with
-- `mul_ite` and `ite_mul`.
@[simp] theorem mul_boole {α : Type u_1} [semiring α] (P : Prop) [Decidable P] (a : α) :
a * ite P 1 0 = ite P a 0 :=
sorry
@[simp] theorem boole_mul {α : Type u_1} [semiring α] (P : Prop) [Decidable P] (a : α) :
ite P 1 0 * a = ite P a 0 :=
sorry
theorem ite_mul_zero_left {α : Type u_1} [mul_zero_class α] (P : Prop) [Decidable P] (a : α)
(b : α) : ite P (a * b) 0 = ite P a 0 * b :=
sorry
theorem ite_mul_zero_right {α : Type u_1} [mul_zero_class α] (P : Prop) [Decidable P] (a : α)
(b : α) : ite P (a * b) 0 = a * ite P b 0 :=
sorry
/-- An element `a` of a semiring is even if there exists `k` such `a = 2*k`. -/
def even {α : Type u} [semiring α] (a : α) := ∃ (k : α), a = bit0 1 * k
theorem even_iff_two_dvd {α : Type u} [semiring α] {a : α} : even a ↔ bit0 1 ∣ a := iff.rfl
/-- An element `a` of a semiring is odd if there exists `k` such `a = 2*k + 1`. -/
def odd {α : Type u} [semiring α] (a : α) := ∃ (k : α), a = bit0 1 * k + 1
theorem dvd_add {α : Type u} [semiring α] {a : α} {b : α} {c : α} (h₁ : a ∣ b) (h₂ : a ∣ c) :
a ∣ b + c :=
sorry
namespace add_monoid_hom
/-- Left multiplication by an element of a (semi)ring is an `add_monoid_hom` -/
def mul_left {R : Type u_1} [semiring R] (r : R) : R →+ R := mk (Mul.mul r) sorry sorry
@[simp] theorem coe_mul_left {R : Type u_1} [semiring R] (r : R) : ⇑(mul_left r) = Mul.mul r := rfl
/-- Right multiplication by an element of a (semi)ring is an `add_monoid_hom` -/
def mul_right {R : Type u_1} [semiring R] (r : R) : R →+ R := mk (fun (a : R) => a * r) sorry sorry
@[simp] theorem coe_mul_right {R : Type u_1} [semiring R] (r : R) :
⇑(mul_right r) = fun (_x : R) => _x * r :=
rfl
theorem mul_right_apply {R : Type u_1} [semiring R] (a : R) (r : R) :
coe_fn (mul_right r) a = a * r :=
rfl
end add_monoid_hom
/-- Bundled semiring homomorphisms; use this for bundled ring homomorphisms too.
This extends from both `monoid_hom` and `monoid_with_zero_hom` in order to put the fields in a
sensible order, even though `monoid_with_zero_hom` already extends `monoid_hom`. -/
structure ring_hom (α : Type u_1) (β : Type u_2) [semiring α] [semiring β]
extends monoid_with_zero_hom α β, α →* β, α →+ β where
infixr:25 " →+* " => Mathlib.ring_hom
/-- Reinterpret a ring homomorphism `f : R →+* S` as a `monoid_with_zero_hom R S`.
The `simp`-normal form is `(f : monoid_with_zero_hom R S)`. -/
/-- Reinterpret a ring homomorphism `f : R →+* S` as a monoid homomorphism `R →* S`.
The `simp`-normal form is `(f : R →* S)`. -/
/-- Reinterpret a ring homomorphism `f : R →+* S` as an additive monoid homomorphism `R →+ S`.
The `simp`-normal form is `(f : R →+ S)`. -/
namespace ring_hom
/-!
Throughout this section, some `semiring` arguments are specified with `{}` instead of `[]`.
See note [implicit instance arguments].
-/
protected instance has_coe_to_fun {α : Type u} {β : Type v} {rα : semiring α} {rβ : semiring β} :
has_coe_to_fun (α →+* β) :=
has_coe_to_fun.mk (fun (x : α →+* β) => α → β) to_fun
@[simp] theorem to_fun_eq_coe {α : Type u} {β : Type v} {rα : semiring α} {rβ : semiring β}
(f : α →+* β) : to_fun f = ⇑f :=
rfl
@[simp] theorem coe_mk {α : Type u} {β : Type v} {rα : semiring α} {rβ : semiring β} (f : α → β)
(h₁ : f 1 = 1) (h₂ : ∀ (x y : α), f (x * y) = f x * f y) (h₃ : f 0 = 0)
(h₄ : ∀ (x y : α), f (x + y) = f x + f y) : ⇑(mk f h₁ h₂ h₃ h₄) = f :=
rfl
protected instance has_coe_monoid_hom {α : Type u} {β : Type v} {rα : semiring α}
{rβ : semiring β} : has_coe (α →+* β) (α →* β) :=
has_coe.mk to_monoid_hom
@[simp] theorem coe_monoid_hom {α : Type u} {β : Type v} {rα : semiring α} {rβ : semiring β}
(f : α →+* β) : ⇑↑f = ⇑f :=
rfl
@[simp] theorem to_monoid_hom_eq_coe {α : Type u} {β : Type v} {rα : semiring α} {rβ : semiring β}
(f : α →+* β) : to_monoid_hom f = ↑f :=
rfl
@[simp] theorem coe_monoid_hom_mk {α : Type u} {β : Type v} {rα : semiring α} {rβ : semiring β}
(f : α → β) (h₁ : f 1 = 1) (h₂ : ∀ (x y : α), f (x * y) = f x * f y) (h₃ : f 0 = 0)
(h₄ : ∀ (x y : α), f (x + y) = f x + f y) : ↑(mk f h₁ h₂ h₃ h₄) = monoid_hom.mk f h₁ h₂ :=
rfl
protected instance has_coe_add_monoid_hom {α : Type u} {β : Type v} {rα : semiring α}
{rβ : semiring β} : has_coe (α →+* β) (α →+ β) :=
has_coe.mk to_add_monoid_hom
@[simp] theorem coe_add_monoid_hom {α : Type u} {β : Type v} {rα : semiring α} {rβ : semiring β}
(f : α →+* β) : ⇑↑f = ⇑f :=
rfl
@[simp] theorem to_add_monoid_hom_eq_coe {α : Type u} {β : Type v} {rα : semiring α}
{rβ : semiring β} (f : α →+* β) : to_add_monoid_hom f = ↑f :=
rfl
@[simp] theorem coe_add_monoid_hom_mk {α : Type u} {β : Type v} {rα : semiring α} {rβ : semiring β}
(f : α → β) (h₁ : f 1 = 1) (h₂ : ∀ (x y : α), f (x * y) = f x * f y) (h₃ : f 0 = 0)
(h₄ : ∀ (x y : α), f (x + y) = f x + f y) : ↑(mk f h₁ h₂ h₃ h₄) = add_monoid_hom.mk f h₃ h₄ :=
rfl
theorem congr_fun {α : Type u} {β : Type v} {rα : semiring α} {rβ : semiring β} {f : α →+* β}
{g : α →+* β} (h : f = g) (x : α) : coe_fn f x = coe_fn g x :=
congr_arg (fun (h : α →+* β) => coe_fn h x) h
theorem congr_arg {α : Type u} {β : Type v} {rα : semiring α} {rβ : semiring β} (f : α →+* β)
{x : α} {y : α} (h : x = y) : coe_fn f x = coe_fn f y :=
congr_arg (fun (x : α) => coe_fn f x) h
theorem coe_inj {α : Type u} {β : Type v} {rα : semiring α} {rβ : semiring β} {f : α →+* β}
{g : α →+* β} (h : ⇑f = ⇑g) : f = g :=
sorry
theorem ext {α : Type u} {β : Type v} {rα : semiring α} {rβ : semiring β} {f : α →+* β}
{g : α →+* β} (h : ∀ (x : α), coe_fn f x = coe_fn g x) : f = g :=
coe_inj (funext h)
theorem ext_iff {α : Type u} {β : Type v} {rα : semiring α} {rβ : semiring β} {f : α →+* β}
{g : α →+* β} : f = g ↔ ∀ (x : α), coe_fn f x = coe_fn g x :=
{ mp := fun (h : f = g) (x : α) => h ▸ rfl,
mpr := fun (h : ∀ (x : α), coe_fn f x = coe_fn g x) => ext h }
@[simp] theorem mk_coe {α : Type u} {β : Type v} {rα : semiring α} {rβ : semiring β} (f : α →+* β)
(h₁ : coe_fn f 1 = 1) (h₂ : ∀ (x y : α), coe_fn f (x * y) = coe_fn f x * coe_fn f y)
(h₃ : coe_fn f 0 = 0) (h₄ : ∀ (x y : α), coe_fn f (x + y) = coe_fn f x + coe_fn f y) :
mk (⇑f) h₁ h₂ h₃ h₄ = f :=
ext fun (_x : α) => rfl
theorem coe_add_monoid_hom_injective {α : Type u} {β : Type v} {rα : semiring α} {rβ : semiring β} :
function.injective coe :=
fun (f g : α →+* β) (h : ↑f = ↑g) => ext fun (x : α) => add_monoid_hom.congr_fun h x
theorem coe_monoid_hom_injective {α : Type u} {β : Type v} {rα : semiring α} {rβ : semiring β} :
function.injective coe :=
fun (f g : α →+* β) (h : ↑f = ↑g) => ext fun (x : α) => monoid_hom.congr_fun h x
/-- Ring homomorphisms map zero to zero. -/
@[simp] theorem map_zero {α : Type u} {β : Type v} {rα : semiring α} {rβ : semiring β}
(f : α →+* β) : coe_fn f 0 = 0 :=
map_zero' f
/-- Ring homomorphisms map one to one. -/
@[simp] theorem map_one {α : Type u} {β : Type v} {rα : semiring α} {rβ : semiring β}
(f : α →+* β) : coe_fn f 1 = 1 :=
map_one' f
/-- Ring homomorphisms preserve addition. -/
@[simp] theorem map_add {α : Type u} {β : Type v} {rα : semiring α} {rβ : semiring β} (f : α →+* β)
(a : α) (b : α) : coe_fn f (a + b) = coe_fn f a + coe_fn f b :=
map_add' f a b
/-- Ring homomorphisms preserve multiplication. -/
@[simp] theorem map_mul {α : Type u} {β : Type v} {rα : semiring α} {rβ : semiring β} (f : α →+* β)
(a : α) (b : α) : coe_fn f (a * b) = coe_fn f a * coe_fn f b :=
map_mul' f a b
/-- Ring homomorphisms preserve `bit0`. -/
@[simp] theorem map_bit0 {α : Type u} {β : Type v} {rα : semiring α} {rβ : semiring β} (f : α →+* β)
(a : α) : coe_fn f (bit0 a) = bit0 (coe_fn f a) :=
map_add f a a
/-- Ring homomorphisms preserve `bit1`. -/
@[simp] theorem map_bit1 {α : Type u} {β : Type v} {rα : semiring α} {rβ : semiring β} (f : α →+* β)
(a : α) : coe_fn f (bit1 a) = bit1 (coe_fn f a) :=
sorry
/-- `f : R →+* S` has a trivial codomain iff `f 1 = 0`. -/
theorem codomain_trivial_iff_map_one_eq_zero {α : Type u} {β : Type v} {rα : semiring α}
{rβ : semiring β} (f : α →+* β) : 0 = 1 ↔ coe_fn f 1 = 0 :=
eq.mpr (id (Eq._oldrec (Eq.refl (0 = 1 ↔ coe_fn f 1 = 0)) (map_one f)))
(eq.mpr (id (Eq._oldrec (Eq.refl (0 = 1 ↔ 1 = 0)) (propext eq_comm))) (iff.refl (1 = 0)))
/-- `f : R →+* S` has a trivial codomain iff it has a trivial range. -/
theorem codomain_trivial_iff_range_trivial {α : Type u} {β : Type v} {rα : semiring α}
{rβ : semiring β} (f : α →+* β) : 0 = 1 ↔ ∀ (x : α), coe_fn f x = 0 :=
sorry
/-- `f : R →+* S` has a trivial codomain iff its range is `{0}`. -/
theorem codomain_trivial_iff_range_eq_singleton_zero {α : Type u} {β : Type v} {rα : semiring α}
{rβ : semiring β} (f : α →+* β) : 0 = 1 ↔ set.range ⇑f = singleton 0 :=
sorry
/-- `f : R →+* S` doesn't map `1` to `0` if `S` is nontrivial -/
theorem map_one_ne_zero {α : Type u} {β : Type v} {rα : semiring α} {rβ : semiring β} (f : α →+* β)
[nontrivial β] : coe_fn f 1 ≠ 0 :=
mt (iff.mpr (codomain_trivial_iff_map_one_eq_zero f)) zero_ne_one
/-- If there is a homomorphism `f : R →+* S` and `S` is nontrivial, then `R` is nontrivial. -/
theorem domain_nontrivial {α : Type u} {β : Type v} {rα : semiring α} {rβ : semiring β}
(f : α →+* β) [nontrivial β] : nontrivial α :=
sorry
theorem is_unit_map {α : Type u} {β : Type v} {rα : semiring α} {rβ : semiring β} (f : α →+* β)
{a : α} (h : is_unit a) : is_unit (coe_fn f a) :=
is_unit.map (to_monoid_hom f) h
/-- The identity ring homomorphism from a semiring to itself. -/
def id (α : Type u_1) [semiring α] : α →+* α := mk id sorry sorry sorry sorry
protected instance inhabited {α : Type u} [rα : semiring α] : Inhabited (α →+* α) :=
{ default := id α }
@[simp] theorem id_apply {α : Type u} [rα : semiring α] (x : α) : coe_fn (id α) x = x := rfl
/-- Composition of ring homomorphisms is a ring homomorphism. -/
def comp {α : Type u} {β : Type v} {γ : Type w} [rα : semiring α] [rβ : semiring β]
{rγ : semiring γ} (hnp : β →+* γ) (hmn : α →+* β) : α →+* γ :=
mk (⇑hnp ∘ ⇑hmn) sorry sorry sorry sorry
/-- Composition of semiring homomorphisms is associative. -/
theorem comp_assoc {α : Type u} {β : Type v} {γ : Type w} [rα : semiring α] [rβ : semiring β]
{rγ : semiring γ} {δ : Type u_1} {rδ : semiring δ} (f : α →+* β) (g : β →+* γ) (h : γ →+* δ) :
comp (comp h g) f = comp h (comp g f) :=
rfl
@[simp] theorem coe_comp {α : Type u} {β : Type v} {γ : Type w} [rα : semiring α] [rβ : semiring β]
{rγ : semiring γ} (hnp : β →+* γ) (hmn : α →+* β) : ⇑(comp hnp hmn) = ⇑hnp ∘ ⇑hmn :=
rfl
theorem comp_apply {α : Type u} {β : Type v} {γ : Type w} [rα : semiring α] [rβ : semiring β]
{rγ : semiring γ} (hnp : β →+* γ) (hmn : α →+* β) (x : α) :
coe_fn (comp hnp hmn) x = coe_fn hnp (coe_fn hmn x) :=
rfl
@[simp] theorem comp_id {α : Type u} {β : Type v} [rα : semiring α] [rβ : semiring β]
(f : α →+* β) : comp f (id α) = f :=
ext fun (x : α) => rfl
@[simp] theorem id_comp {α : Type u} {β : Type v} [rα : semiring α] [rβ : semiring β]
(f : α →+* β) : comp (id β) f = f :=
ext fun (x : α) => rfl
protected instance monoid {α : Type u} [rα : semiring α] : monoid (α →+* α) :=
monoid.mk comp sorry (id α) id_comp comp_id
theorem one_def {α : Type u} [rα : semiring α] : 1 = id α := rfl
@[simp] theorem coe_one {α : Type u} [rα : semiring α] : ⇑1 = id := rfl
theorem mul_def {α : Type u} [rα : semiring α] (f : α →+* α) (g : α →+* α) : f * g = comp f g := rfl
@[simp] theorem coe_mul {α : Type u} [rα : semiring α] (f : α →+* α) (g : α →+* α) :
⇑(f * g) = ⇑f ∘ ⇑g :=
rfl
theorem cancel_right {α : Type u} {β : Type v} {γ : Type w} [rα : semiring α] [rβ : semiring β]
{rγ : semiring γ} {g₁ : β →+* γ} {g₂ : β →+* γ} {f : α →+* β} (hf : function.surjective ⇑f) :
comp g₁ f = comp g₂ f ↔ g₁ = g₂ :=
{ mp :=
fun (h : comp g₁ f = comp g₂ f) =>
ext (iff.mp (forall_iff_forall_surj hf) (iff.mp ext_iff h)),
mpr := fun (h : g₁ = g₂) => h ▸ rfl }
theorem cancel_left {α : Type u} {β : Type v} {γ : Type w} [rα : semiring α] [rβ : semiring β]
{rγ : semiring γ} {g : β →+* γ} {f₁ : α →+* β} {f₂ : α →+* β} (hg : function.injective ⇑g) :
comp g f₁ = comp g f₂ ↔ f₁ = f₂ :=
sorry
end ring_hom
/-- A commutative semiring is a `semiring` with commutative multiplication. In other words, it is a
type with the following structures: additive commutative monoid (`add_comm_monoid`), multiplicative
commutative monoid (`comm_monoid`), distributive laws (`distrib`), and multiplication by zero law
(`mul_zero_class`). -/
class comm_semiring (α : Type u) extends semiring α, comm_monoid α where
protected instance comm_semiring.to_comm_monoid_with_zero {α : Type u} [comm_semiring α] :
comm_monoid_with_zero α :=
comm_monoid_with_zero.mk comm_monoid.mul sorry comm_monoid.one sorry sorry sorry semiring.zero
sorry sorry
/-- Pullback a `semiring` instance along an injective function. -/
protected def function.injective.comm_semiring {α : Type u} {γ : Type w} [comm_semiring α]
[HasZero γ] [HasOne γ] [Add γ] [Mul γ] (f : γ → α) (hf : function.injective f) (zero : f 0 = 0)
(one : f 1 = 1) (add : ∀ (x y : γ), f (x + y) = f x + f y)
(mul : ∀ (x y : γ), f (x * y) = f x * f y) : comm_semiring γ :=
comm_semiring.mk semiring.add sorry semiring.zero sorry sorry sorry semiring.mul sorry
semiring.one sorry sorry sorry sorry sorry sorry sorry
/-- Pullback a `semiring` instance along an injective function. -/
protected def function.surjective.comm_semiring {α : Type u} {γ : Type w} [comm_semiring α]
[HasZero γ] [HasOne γ] [Add γ] [Mul γ] (f : α → γ) (hf : function.surjective f) (zero : f 0 = 0)
(one : f 1 = 1) (add : ∀ (x y : α), f (x + y) = f x + f y)
(mul : ∀ (x y : α), f (x * y) = f x * f y) : comm_semiring γ :=
comm_semiring.mk semiring.add sorry semiring.zero sorry sorry sorry semiring.mul sorry
semiring.one sorry sorry sorry sorry sorry sorry sorry
theorem add_mul_self_eq {α : Type u} [comm_semiring α] (a : α) (b : α) :
(a + b) * (a + b) = a * a + bit0 1 * a * b + b * b :=
sorry
@[simp] theorem two_dvd_bit0 {α : Type u} [comm_semiring α] {a : α} : bit0 1 ∣ bit0 a :=
Exists.intro a (bit0_eq_two_mul a)
theorem ring_hom.map_dvd {α : Type u} {β : Type v} [comm_semiring α] [comm_semiring β] (f : α →+* β)
{a : α} {b : α} : a ∣ b → coe_fn f a ∣ coe_fn f b :=
sorry
/-!
### Rings
-/
/-- A ring is a type with the following structures: additive commutative group (`add_comm_group`),
multiplicative monoid (`monoid`), and distributive laws (`distrib`). Equivalently, a ring is a
`semiring` with a negation operation making it an additive group. -/
class ring (α : Type u) extends monoid α, distrib α, add_comm_group α where
/- The instance from `ring` to `semiring` happens often in linear algebra, for which all the basic
definitions are given in terms of semirings, but many applications use rings or fields. We increase
a little bit its priority above 100 to try it quickly, but remaining below the default 1000 so that
more specific instances are tried first. -/
protected instance ring.to_semiring {α : Type u} [ring α] : semiring α :=
semiring.mk ring.add ring.add_assoc ring.zero ring.zero_add ring.add_zero ring.add_comm ring.mul
ring.mul_assoc ring.one ring.one_mul ring.mul_one sorry sorry ring.left_distrib
ring.right_distrib
/-- Pullback a `ring` instance along an injective function. -/
protected def function.injective.ring {α : Type u} {β : Type v} [ring α] [HasZero β] [HasOne β]
[Add β] [Mul β] [Neg β] (f : β → α) (hf : function.injective f) (zero : f 0 = 0) (one : f 1 = 1)
(add : ∀ (x y : β), f (x + y) = f x + f y) (mul : ∀ (x y : β), f (x * y) = f x * f y)
(neg : ∀ (x : β), f (-x) = -f x) : ring β :=
ring.mk add_comm_group.add sorry add_comm_group.zero sorry sorry add_comm_group.neg
add_comm_group.sub sorry sorry monoid.mul sorry monoid.one sorry sorry sorry sorry
/-- Pullback a `ring` instance along an injective function,
with a subtraction (`-`) that is not necessarily defeq to `a + -b`. -/
protected def function.injective.ring_sub {α : Type u} {β : Type v} [ring α] [HasZero β] [HasOne β]
[Add β] [Mul β] [Neg β] [Sub β] (f : β → α) (hf : function.injective f) (zero : f 0 = 0)
(one : f 1 = 1) (add : ∀ (x y : β), f (x + y) = f x + f y)
(mul : ∀ (x y : β), f (x * y) = f x * f y) (neg : ∀ (x : β), f (-x) = -f x)
(sub : ∀ (x y : β), f (x - y) = f x - f y) : ring β :=
ring.mk add_comm_group.add sorry add_comm_group.zero sorry sorry add_comm_group.neg
add_comm_group.sub sorry sorry monoid.mul sorry monoid.one sorry sorry sorry sorry
/-- Pullback a `ring` instance along an injective function. -/
protected def function.surjective.ring {α : Type u} {β : Type v} [ring α] [HasZero β] [HasOne β]
[Add β] [Mul β] [Neg β] (f : α → β) (hf : function.surjective f) (zero : f 0 = 0)
(one : f 1 = 1) (add : ∀ (x y : α), f (x + y) = f x + f y)
(mul : ∀ (x y : α), f (x * y) = f x * f y) (neg : ∀ (x : α), f (-x) = -f x) : ring β :=
ring.mk add_comm_group.add sorry add_comm_group.zero sorry sorry add_comm_group.neg
add_comm_group.sub sorry sorry monoid.mul sorry monoid.one sorry sorry sorry sorry
/-- Pullback a `ring` instance along an injective function,
with a subtraction (`-`) that is not necessarily defeq to `a + -b`. -/
protected def function.surjective.ring_sub {α : Type u} {β : Type v} [ring α] [HasZero β] [HasOne β]
[Add β] [Mul β] [Neg β] [Sub β] (f : α → β) (hf : function.surjective f) (zero : f 0 = 0)
(one : f 1 = 1) (add : ∀ (x y : α), f (x + y) = f x + f y)
(mul : ∀ (x y : α), f (x * y) = f x * f y) (neg : ∀ (x : α), f (-x) = -f x)
(sub : ∀ (x y : α), f (x - y) = f x - f y) : ring β :=
ring.mk add_comm_group.add sorry add_comm_group.zero sorry sorry add_comm_group.neg
add_comm_group.sub sorry sorry monoid.mul sorry monoid.one sorry sorry sorry sorry
theorem neg_mul_eq_neg_mul {α : Type u} [ring α] (a : α) (b : α) : -(a * b) = -a * b := sorry
theorem neg_mul_eq_mul_neg {α : Type u} [ring α] (a : α) (b : α) : -(a * b) = a * -b := sorry
@[simp] theorem neg_mul_eq_neg_mul_symm {α : Type u} [ring α] (a : α) (b : α) : -a * b = -(a * b) :=
Eq.symm (neg_mul_eq_neg_mul a b)
@[simp] theorem mul_neg_eq_neg_mul_symm {α : Type u} [ring α] (a : α) (b : α) : a * -b = -(a * b) :=
Eq.symm (neg_mul_eq_mul_neg a b)
theorem neg_mul_neg {α : Type u} [ring α] (a : α) (b : α) : -a * -b = a * b := sorry
theorem neg_mul_comm {α : Type u} [ring α] (a : α) (b : α) : -a * b = a * -b := sorry
theorem neg_eq_neg_one_mul {α : Type u} [ring α] (a : α) : -a = -1 * a := sorry
theorem mul_sub_left_distrib {α : Type u} [ring α] (a : α) (b : α) (c : α) :
a * (b - c) = a * b - a * c :=
sorry
theorem mul_sub {α : Type u} [ring α] (a : α) (b : α) (c : α) : a * (b - c) = a * b - a * c :=
mul_sub_left_distrib
theorem mul_sub_right_distrib {α : Type u} [ring α] (a : α) (b : α) (c : α) :
(a - b) * c = a * c - b * c :=
sorry
theorem sub_mul {α : Type u} [ring α] (a : α) (b : α) (c : α) : (a - b) * c = a * c - b * c :=
mul_sub_right_distrib
/-- An element of a ring multiplied by the additive inverse of one is the element's additive
inverse. -/
theorem mul_neg_one {α : Type u} [ring α] (a : α) : a * -1 = -a := sorry
/-- The additive inverse of one multiplied by an element of a ring is the element's additive
inverse. -/
theorem neg_one_mul {α : Type u} [ring α] (a : α) : -1 * a = -a := sorry
/-- An iff statement following from right distributivity in rings and the definition
of subtraction. -/
theorem mul_add_eq_mul_add_iff_sub_mul_add_eq {α : Type u} [ring α] {a : α} {b : α} {c : α} {d : α}
{e : α} : a * e + c = b * e + d ↔ (a - b) * e + c = d :=
sorry
/-- A simplification of one side of an equation exploiting right distributivity in rings
and the definition of subtraction. -/
theorem sub_mul_add_eq_of_mul_add_eq_mul_add {α : Type u} [ring α] {a : α} {b : α} {c : α} {d : α}
{e : α} : a * e + c = b * e + d → (a - b) * e + c = d :=
sorry
namespace units
/-- Each element of the group of units of a ring has an additive inverse. -/
protected instance has_neg {α : Type u} [ring α] : Neg (units α) :=
{ neg := fun (u : units α) => mk (-↑u) (-↑(u⁻¹)) sorry sorry }
/-- Representing an element of a ring's unit group as an element of the ring commutes with
mapping this element to its additive inverse. -/
@[simp] protected theorem coe_neg {α : Type u} [ring α] (u : units α) : ↑(-u) = -↑u := rfl
@[simp] protected theorem coe_neg_one {α : Type u} [ring α] : ↑(-1) = -1 := rfl
/-- Mapping an element of a ring's unit group to its inverse commutes with mapping this element
to its additive inverse. -/
@[simp] protected theorem neg_inv {α : Type u} [ring α] (u : units α) : -u⁻¹ = -(u⁻¹) := rfl
/-- An element of a ring's unit group equals the additive inverse of its additive inverse. -/
@[simp] protected theorem neg_neg {α : Type u} [ring α] (u : units α) : --u = u := ext (neg_neg ↑u)
/-- Multiplication of elements of a ring's unit group commutes with mapping the first
argument to its additive inverse. -/
@[simp] protected theorem neg_mul {α : Type u} [ring α] (u₁ : units α) (u₂ : units α) :
-u₁ * u₂ = -(u₁ * u₂) :=
ext (neg_mul_eq_neg_mul_symm (↑u₁) (val u₂))
/-- Multiplication of elements of a ring's unit group commutes with mapping the second argument
to its additive inverse. -/
@[simp] protected theorem mul_neg {α : Type u} [ring α] (u₁ : units α) (u₂ : units α) :
u₁ * -u₂ = -(u₁ * u₂) :=
ext (Eq.symm (neg_mul_eq_mul_neg (val u₁) ↑u₂))
/-- Multiplication of the additive inverses of two elements of a ring's unit group equals
multiplication of the two original elements. -/
@[simp] protected theorem neg_mul_neg {α : Type u} [ring α] (u₁ : units α) (u₂ : units α) :
-u₁ * -u₂ = u₁ * u₂ :=
sorry
/-- The additive inverse of an element of a ring's unit group equals the additive inverse of
one times the original element. -/
protected theorem neg_eq_neg_one_mul {α : Type u} [ring α] (u : units α) : -u = -1 * u := sorry
end units
namespace ring_hom
/-- Ring homomorphisms preserve additive inverse. -/
@[simp] theorem map_neg {α : Type u_1} {β : Type u_2} [ring α] [ring β] (f : α →+* β) (x : α) :
coe_fn f (-x) = -coe_fn f x :=
add_monoid_hom.map_neg (↑f) x
/-- Ring homomorphisms preserve subtraction. -/
@[simp] theorem map_sub {α : Type u_1} {β : Type u_2} [ring α] [ring β] (f : α →+* β) (x : α)
(y : α) : coe_fn f (x - y) = coe_fn f x - coe_fn f y :=
add_monoid_hom.map_sub (↑f) x y
/-- A ring homomorphism is injective iff its kernel is trivial. -/
theorem injective_iff {α : Type u_1} {β : Type u_2} [ring α] [semiring β] (f : α →+* β) :
function.injective ⇑f ↔ ∀ (a : α), coe_fn f a = 0 → a = 0 :=
add_monoid_hom.injective_iff ↑f
/-- Makes a ring homomorphism from a monoid homomorphism of rings which preserves addition. -/
def mk' {α : Type u} {γ : Type u_1} [semiring α] [ring γ] (f : α →* γ)
(map_add : ∀ (a b : α), coe_fn f (a + b) = coe_fn f a + coe_fn f b) : α →+* γ :=
mk ⇑f sorry sorry sorry sorry
end ring_hom
/-- A commutative ring is a `ring` with commutative multiplication. -/
class comm_ring (α : Type u) extends ring α, comm_semigroup α where
protected instance comm_ring.to_comm_semiring {α : Type u} [s : comm_ring α] : comm_semiring α :=
comm_semiring.mk comm_ring.add comm_ring.add_assoc comm_ring.zero comm_ring.zero_add
comm_ring.add_zero comm_ring.add_comm comm_ring.mul comm_ring.mul_assoc comm_ring.one
comm_ring.one_mul comm_ring.mul_one sorry sorry comm_ring.left_distrib comm_ring.right_distrib
comm_ring.mul_comm
/-- Pullback a `comm_ring` instance along an injective function. -/
protected def function.injective.comm_ring {α : Type u} {β : Type v} [comm_ring α] [HasZero β]
[HasOne β] [Add β] [Mul β] [Neg β] (f : β → α) (hf : function.injective f) (zero : f 0 = 0)
(one : f 1 = 1) (add : ∀ (x y : β), f (x + y) = f x + f y)
(mul : ∀ (x y : β), f (x * y) = f x * f y) (neg : ∀ (x : β), f (-x) = -f x) : comm_ring β :=
comm_ring.mk ring.add sorry ring.zero sorry sorry ring.neg ring.sub sorry sorry ring.mul sorry
ring.one sorry sorry sorry sorry sorry
/-- Pullback a `comm_ring` instance along an injective function,
with a subtraction (`-`) that is not necessarily defeq to `a + -b`. -/
protected def function.injective.comm_ring_sub {α : Type u} {β : Type v} [comm_ring α] [HasZero β]
[HasOne β] [Add β] [Mul β] [Neg β] [Sub β] (f : β → α) (hf : function.injective f)
(zero : f 0 = 0) (one : f 1 = 1) (add : ∀ (x y : β), f (x + y) = f x + f y)
(mul : ∀ (x y : β), f (x * y) = f x * f y) (neg : ∀ (x : β), f (-x) = -f x)
(sub : ∀ (x y : β), f (x - y) = f x - f y) : comm_ring β :=
comm_ring.mk ring.add sorry ring.zero sorry sorry ring.neg ring.sub sorry sorry ring.mul sorry
ring.one sorry sorry sorry sorry sorry
/-- Pullback a `comm_ring` instance along an injective function. -/
protected def function.surjective.comm_ring {α : Type u} {β : Type v} [comm_ring α] [HasZero β]
[HasOne β] [Add β] [Mul β] [Neg β] (f : α → β) (hf : function.surjective f) (zero : f 0 = 0)
(one : f 1 = 1) (add : ∀ (x y : α), f (x + y) = f x + f y)
(mul : ∀ (x y : α), f (x * y) = f x * f y) (neg : ∀ (x : α), f (-x) = -f x) : comm_ring β :=
comm_ring.mk ring.add sorry ring.zero sorry sorry ring.neg ring.sub sorry sorry ring.mul sorry
ring.one sorry sorry sorry sorry sorry
/-- Pullback a `comm_ring` instance along an injective function,
with a subtraction (`-`) that is not necessarily defeq to `a + -b`. -/
protected def function.surjective.comm_ring_sub {α : Type u} {β : Type v} [comm_ring α] [HasZero β]
[HasOne β] [Add β] [Mul β] [Neg β] [Sub β] (f : α → β) (hf : function.surjective f)
(zero : f 0 = 0) (one : f 1 = 1) (add : ∀ (x y : α), f (x + y) = f x + f y)
(mul : ∀ (x y : α), f (x * y) = f x * f y) (neg : ∀ (x : α), f (-x) = -f x)
(sub : ∀ (x y : α), f (x - y) = f x - f y) : comm_ring β :=
comm_ring.mk ring.add sorry ring.zero sorry sorry ring.neg ring.sub sorry sorry ring.mul sorry
ring.one sorry sorry sorry sorry sorry
theorem dvd_neg_of_dvd {α : Type u} [comm_ring α] {a : α} {b : α} (h : a ∣ b) : a ∣ -b := sorry
theorem dvd_of_dvd_neg {α : Type u} [comm_ring α] {a : α} {b : α} (h : a ∣ -b) : a ∣ b :=
let t : a ∣ --b := dvd_neg_of_dvd h;
eq.mp (Eq._oldrec (Eq.refl (a ∣ --b)) (neg_neg b)) t
theorem dvd_neg_iff_dvd {α : Type u} [comm_ring α] (a : α) (b : α) : a ∣ -b ↔ a ∣ b :=
{ mp := dvd_of_dvd_neg, mpr := dvd_neg_of_dvd }
theorem neg_dvd_of_dvd {α : Type u} [comm_ring α] {a : α} {b : α} (h : a ∣ b) : -a ∣ b := sorry
theorem dvd_of_neg_dvd {α : Type u} [comm_ring α] {a : α} {b : α} (h : -a ∣ b) : a ∣ b :=
let t : --a ∣ b := neg_dvd_of_dvd h;
eq.mp (Eq._oldrec (Eq.refl ( --a ∣ b)) (neg_neg a)) t
theorem neg_dvd_iff_dvd {α : Type u} [comm_ring α] (a : α) (b : α) : -a ∣ b ↔ a ∣ b :=
{ mp := dvd_of_neg_dvd, mpr := neg_dvd_of_dvd }
theorem dvd_sub {α : Type u} [comm_ring α] {a : α} {b : α} {c : α} (h₁ : a ∣ b) (h₂ : a ∣ c) :
a ∣ b - c :=
eq.mpr (id (Eq._oldrec (Eq.refl (a ∣ b - c)) (sub_eq_add_neg b c)))
(dvd_add h₁ (dvd_neg_of_dvd h₂))
theorem dvd_add_iff_left {α : Type u} [comm_ring α] {a : α} {b : α} {c : α} (h : a ∣ c) :
a ∣ b ↔ a ∣ b + c :=
{ mp := fun (h₂ : a ∣ b) => dvd_add h₂ h,
mpr :=
fun (H : a ∣ b + c) =>
eq.mp (Eq._oldrec (Eq.refl (a ∣ b + c - c)) (add_sub_cancel b c)) (dvd_sub H h) }
theorem dvd_add_iff_right {α : Type u} [comm_ring α] {a : α} {b : α} {c : α} (h : a ∣ b) :
a ∣ c ↔ a ∣ b + c :=
eq.mpr (id (Eq._oldrec (Eq.refl (a ∣ c ↔ a ∣ b + c)) (add_comm b c))) (dvd_add_iff_left h)
theorem two_dvd_bit1 {α : Type u} [comm_ring α] {a : α} : bit0 1 ∣ bit1 a ↔ bit0 1 ∣ 1 :=
iff.symm (dvd_add_iff_right two_dvd_bit0)
/-- Representation of a difference of two squares in a commutative ring as a product. -/
theorem mul_self_sub_mul_self {α : Type u} [comm_ring α] (a : α) (b : α) :
a * a - b * b = (a + b) * (a - b) :=
sorry
theorem mul_self_sub_one {α : Type u} [comm_ring α] (a : α) : a * a - 1 = (a + 1) * (a - 1) :=
eq.mpr
(id
(Eq._oldrec (Eq.refl (a * a - 1 = (a + 1) * (a - 1))) (Eq.symm (mul_self_sub_mul_self a 1))))
(eq.mpr (id (Eq._oldrec (Eq.refl (a * a - 1 = a * a - 1 * 1)) (mul_one 1)))
(Eq.refl (a * a - 1)))
/-- An element a of a commutative ring divides the additive inverse of an element b iff a
divides b. -/
@[simp] theorem dvd_neg {α : Type u} [comm_ring α] (a : α) (b : α) : a ∣ -b ↔ a ∣ b :=
{ mp := dvd_of_dvd_neg, mpr := dvd_neg_of_dvd }
/-- The additive inverse of an element a of a commutative ring divides another element b iff a
divides b. -/
@[simp] theorem neg_dvd {α : Type u} [comm_ring α] (a : α) (b : α) : -a ∣ b ↔ a ∣ b :=
{ mp := dvd_of_neg_dvd, mpr := neg_dvd_of_dvd }
/-- If an element a divides another element c in a commutative ring, a divides the sum of another
element b with c iff a divides b. -/
theorem dvd_add_left {α : Type u} [comm_ring α] {a : α} {b : α} {c : α} (h : a ∣ c) :
a ∣ b + c ↔ a ∣ b :=
iff.symm (dvd_add_iff_left h)
/-- If an element a divides another element b in a commutative ring, a divides the sum of b and
another element c iff a divides c. -/
theorem dvd_add_right {α : Type u} [comm_ring α] {a : α} {b : α} {c : α} (h : a ∣ b) :
a ∣ b + c ↔ a ∣ c :=
iff.symm (dvd_add_iff_right h)
/-- An element a divides the sum a + b if and only if a divides b.-/
@[simp] theorem dvd_add_self_left {α : Type u} [comm_ring α] {a : α} {b : α} : a ∣ a + b ↔ a ∣ b :=
dvd_add_right (dvd_refl a)
/-- An element a divides the sum b + a if and only if a divides b.-/
@[simp] theorem dvd_add_self_right {α : Type u} [comm_ring α] {a : α} {b : α} : a ∣ b + a ↔ a ∣ b :=
dvd_add_left (dvd_refl a)
/-- Vieta's formula for a quadratic equation, relating the coefficients of the polynomial with
its roots. This particular version states that if we have a root `x` of a monic quadratic
polynomial, then there is another root `y` such that `x + y` is negative the `a_1` coefficient
and `x * y` is the `a_0` coefficient. -/
theorem Vieta_formula_quadratic {α : Type u} [comm_ring α] {b : α} {c : α} {x : α}
(h : x * x - b * x + c = 0) : ∃ (y : α), y * y - b * y + c = 0 ∧ x + y = b ∧ x * y = c :=
sorry
theorem dvd_mul_sub_mul {α : Type u} [comm_ring α] {k : α} {a : α} {b : α} {x : α} {y : α}
(hab : k ∣ a - b) (hxy : k ∣ x - y) : k ∣ a * x - b * y :=
sorry
theorem dvd_iff_dvd_of_dvd_sub {α : Type u} [comm_ring α] {a : α} {b : α} {c : α} (h : a ∣ b - c) :
a ∣ b ↔ a ∣ c :=
sorry
theorem succ_ne_self {α : Type u} [ring α] [nontrivial α] (a : α) : a + 1 ≠ a := sorry
theorem pred_ne_self {α : Type u} [ring α] [nontrivial α] (a : α) : a - 1 ≠ a := sorry
/-- A domain is a ring with no zero divisors, i.e. satisfying
the condition `a * b = 0 ↔ a = 0 ∨ b = 0`. Alternatively, a domain
is an integral domain without assuming commutativity of multiplication. -/
class domain (α : Type u) extends ring α, nontrivial α where
eq_zero_or_eq_zero_of_mul_eq_zero : ∀ (a b : α), a * b = 0 → a = 0 ∨ b = 0
protected instance domain.to_no_zero_divisors {α : Type u} [domain α] : no_zero_divisors α :=
no_zero_divisors.mk domain.eq_zero_or_eq_zero_of_mul_eq_zero
protected instance domain.to_cancel_monoid_with_zero {α : Type u} [domain α] :
cancel_monoid_with_zero α :=
cancel_monoid_with_zero.mk semiring.mul sorry semiring.one sorry sorry semiring.zero sorry sorry
sorry sorry
/-- Pullback a `domain` instance along an injective function. -/
protected def function.injective.domain {α : Type u} {β : Type v} [domain α] [HasZero β] [HasOne β]
[Add β] [Mul β] [Neg β] (f : β → α) (hf : function.injective f) (zero : f 0 = 0) (one : f 1 = 1)
(add : ∀ (x y : β), f (x + y) = f x + f y) (mul : ∀ (x y : β), f (x * y) = f x * f y)
(neg : ∀ (x : β), f (-x) = -f x) : domain β :=
domain.mk ring.add sorry ring.zero sorry sorry ring.neg ring.sub sorry sorry ring.mul sorry
ring.one sorry sorry sorry sorry sorry sorry
/-!
### Integral domains
-/
/-- An integral domain is a commutative ring with no zero divisors, i.e. satisfying the condition
`a * b = 0 ↔ a = 0 ∨ b = 0`. Alternatively, an integral domain is a domain with commutative
multiplication. -/
class integral_domain (α : Type u) extends comm_ring α, domain α where
protected instance integral_domain.to_comm_cancel_monoid_with_zero {α : Type u}
[integral_domain α] : comm_cancel_monoid_with_zero α :=
comm_cancel_monoid_with_zero.mk comm_monoid_with_zero.mul sorry comm_monoid_with_zero.one sorry
sorry sorry comm_monoid_with_zero.zero sorry sorry sorry sorry
/-- Pullback an `integral_domain` instance along an injective function. -/
protected def function.injective.integral_domain {α : Type u} {β : Type v} [integral_domain α]
[HasZero β] [HasOne β] [Add β] [Mul β] [Neg β] (f : β → α) (hf : function.injective f)
(zero : f 0 = 0) (one : f 1 = 1) (add : ∀ (x y : β), f (x + y) = f x + f y)
(mul : ∀ (x y : β), f (x * y) = f x * f y) (neg : ∀ (x : β), f (-x) = -f x) :
integral_domain β :=
integral_domain.mk comm_ring.add sorry comm_ring.zero sorry sorry comm_ring.neg comm_ring.sub
sorry sorry comm_ring.mul sorry comm_ring.one sorry sorry sorry sorry sorry sorry sorry
theorem mul_self_eq_mul_self_iff {α : Type u} [integral_domain α] {a : α} {b : α} :
a * a = b * b ↔ a = b ∨ a = -b :=
sorry
theorem mul_self_eq_one_iff {α : Type u} [integral_domain α] {a : α} : a * a = 1 ↔ a = 1 ∨ a = -1 :=
eq.mpr
(id
(Eq._oldrec (Eq.refl (a * a = 1 ↔ a = 1 ∨ a = -1))
(Eq.symm (propext mul_self_eq_mul_self_iff))))
(eq.mpr (id (Eq._oldrec (Eq.refl (a * a = 1 ↔ a * a = 1 * 1)) (one_mul 1)))
(iff.refl (a * a = 1)))
/-- In the unit group of an integral domain, a unit is its own inverse iff the unit is one or
one's additive inverse. -/
theorem units.inv_eq_self_iff {α : Type u} [integral_domain α] (u : units α) :
u⁻¹ = u ↔ u = 1 ∨ u = -1 :=
sorry
namespace ring
/-- Introduce a function `inverse` on a ring `R`, which sends `x` to `x⁻¹` if `x` is invertible and
to `0` otherwise. This definition is somewhat ad hoc, but one needs a fully (rather than partially)
defined inverse function for some purposes, including for calculus. -/
def inverse {R : Type x} [ring R] : R → R :=
fun (x : R) =>
dite (is_unit x) (fun (h : is_unit x) => ↑(classical.some h⁻¹)) fun (h : ¬is_unit x) => 0
/-- By definition, if `x` is invertible then `inverse x = x⁻¹`. -/
@[simp] theorem inverse_unit {R : Type x} [ring R] (a : units R) : inverse ↑a = ↑(a⁻¹) := sorry
/-- By definition, if `x` is not invertible then `inverse x = 0`. -/
@[simp] theorem inverse_non_unit {R : Type x} [ring R] (x : R) (h : ¬is_unit x) : inverse x = 0 :=
dif_neg h
end ring
/-- A predicate to express that a ring is an integral domain.
This is mainly useful because such a predicate does not contain data,
and can therefore be easily transported along ring isomorphisms. -/
structure is_integral_domain (R : Type u) [ring R] extends nontrivial R where
mul_comm : ∀ (x y : R), x * y = y * x
eq_zero_or_eq_zero_of_mul_eq_zero : ∀ (x y : R), x * y = 0 → x = 0 ∨ y = 0
-- The linter does not recognize that is_integral_domain.to_nontrivial is a structure
-- projection, disable it
/-- Every integral domain satisfies the predicate for integral domains. -/
theorem integral_domain.to_is_integral_domain (R : Type u) [integral_domain R] :
is_integral_domain R :=
is_integral_domain.mk integral_domain.exists_pair_ne integral_domain.mul_comm
integral_domain.eq_zero_or_eq_zero_of_mul_eq_zero
/-- If a ring satisfies the predicate for integral domains,
then it can be endowed with an `integral_domain` instance
whose data is definitionally equal to the existing data. -/
def is_integral_domain.to_integral_domain (R : Type u) [ring R] (h : is_integral_domain R) :
integral_domain R :=
integral_domain.mk ring.add ring.add_assoc ring.zero ring.zero_add ring.add_zero ring.neg ring.sub
ring.add_left_neg ring.add_comm ring.mul ring.mul_assoc ring.one ring.one_mul ring.mul_one
ring.left_distrib ring.right_distrib (is_integral_domain.mul_comm h)
(is_integral_domain.exists_pair_ne h) (is_integral_domain.eq_zero_or_eq_zero_of_mul_eq_zero h)
namespace semiconj_by
@[simp] theorem add_right {R : Type x} [distrib R] {a : R} {x : R} {y : R} {x' : R} {y' : R}
(h : semiconj_by a x y) (h' : semiconj_by a x' y') : semiconj_by a (x + x') (y + y') :=
sorry
@[simp] theorem add_left {R : Type x} [distrib R] {a : R} {b : R} {x : R} {y : R}
(ha : semiconj_by a x y) (hb : semiconj_by b x y) : semiconj_by (a + b) x y :=
sorry
theorem neg_right {R : Type x} [ring R] {a : R} {x : R} {y : R} (h : semiconj_by a x y) :
semiconj_by a (-x) (-y) :=
sorry
@[simp] theorem neg_right_iff {R : Type x} [ring R] {a : R} {x : R} {y : R} :
semiconj_by a (-x) (-y) ↔ semiconj_by a x y :=
{ mp := fun (h : semiconj_by a (-x) (-y)) => neg_neg x ▸ neg_neg y ▸ neg_right h,
mpr := neg_right }
theorem neg_left {R : Type x} [ring R] {a : R} {x : R} {y : R} (h : semiconj_by a x y) :
semiconj_by (-a) x y :=
sorry
@[simp] theorem neg_left_iff {R : Type x} [ring R] {a : R} {x : R} {y : R} :
semiconj_by (-a) x y ↔ semiconj_by a x y :=
{ mp := fun (h : semiconj_by (-a) x y) => neg_neg a ▸ neg_left h, mpr := neg_left }
@[simp] theorem neg_one_right {R : Type x} [ring R] (a : R) : semiconj_by a (-1) (-1) :=
neg_right (one_right a)
@[simp] theorem neg_one_left {R : Type x} [ring R] (x : R) : semiconj_by (-1) x x :=
neg_left (one_left x)
@[simp] theorem sub_right {R : Type x} [ring R] {a : R} {x : R} {y : R} {x' : R} {y' : R}
(h : semiconj_by a x y) (h' : semiconj_by a x' y') : semiconj_by a (x - x') (y - y') :=
sorry
@[simp] theorem sub_left {R : Type x} [ring R] {a : R} {b : R} {x : R} {y : R}
(ha : semiconj_by a x y) (hb : semiconj_by b x y) : semiconj_by (a - b) x y :=
sorry
end semiconj_by
namespace commute
@[simp] theorem add_right {R : Type x} [distrib R] {a : R} {b : R} {c : R} :
commute a b → commute a c → commute a (b + c) :=
semiconj_by.add_right
@[simp] theorem add_left {R : Type x} [distrib R] {a : R} {b : R} {c : R} :
commute a c → commute b c → commute (a + b) c :=
semiconj_by.add_left
theorem neg_right {R : Type x} [ring R] {a : R} {b : R} : commute a b → commute a (-b) :=
semiconj_by.neg_right
@[simp] theorem neg_right_iff {R : Type x} [ring R] {a : R} {b : R} :
commute a (-b) ↔ commute a b :=
semiconj_by.neg_right_iff
theorem neg_left {R : Type x} [ring R] {a : R} {b : R} : commute a b → commute (-a) b :=
semiconj_by.neg_left
@[simp] theorem neg_left_iff {R : Type x} [ring R] {a : R} {b : R} : commute (-a) b ↔ commute a b :=
semiconj_by.neg_left_iff
@[simp] theorem neg_one_right {R : Type x} [ring R] (a : R) : commute a (-1) :=
semiconj_by.neg_one_right a
@[simp] theorem neg_one_left {R : Type x} [ring R] (a : R) : commute (-1) a :=
semiconj_by.neg_one_left a
@[simp] theorem sub_right {R : Type x} [ring R] {a : R} {b : R} {c : R} :
commute a b → commute a c → commute a (b - c) :=
semiconj_by.sub_right
@[simp] theorem sub_left {R : Type x} [ring R] {a : R} {b : R} {c : R} :
commute a c → commute b c → commute (a - b) c :=
semiconj_by.sub_left
end Mathlib |
64188cbe199338733f79a2f45415ecc9f9d072b7 | 63abd62053d479eae5abf4951554e1064a4c45b4 | /src/algebra/ring_quot.lean | f5ab3683a3fe11cf25c54e12530e4a42d6e42ae4 | [
"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 | 11,343 | 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 algebra.algebra.basic
import ring_theory.ideal.basic
/-!
# Quotients of non-commutative rings
Unfortunately, ideals have only been developed in the commutative case as `ideal`,
and it's not immediately clear how one should formalise ideals in the non-commutative case.
In this file, we directly define the quotient of a semiring by any relation,
by building a bigger relation that represents the ideal generated by that relation.
We prove the universal properties of the quotient,
and recommend avoiding relying on the actual definition!
Since everything runs in parallel for quotients of `R`-algebras, we do that case at the same time.
-/
universes u₁ u₂ u₃ u₄
variables {R : Type u₁} [semiring R]
variables {S : Type u₂} [comm_semiring S]
variables {A : Type u₃} [semiring A] [algebra S A]
namespace ring_quot
/--
Given an arbitrary relation `r` on a ring, we strengthen it to a relation `rel r`,
such that the equivalence relation generated by `rel r` has `x ~ y` if and only if
`x - y` is in the ideal generated by elements `a - b` such that `r a b`.
-/
inductive rel (r : R → R → Prop) : R → R → Prop
| of ⦃x y : R⦄ (h : r x y) : rel x y
| add_left ⦃a b c⦄ : rel a b → rel (a + c) (b + c)
| mul_left ⦃a b c⦄ : rel a b → rel (a * c) (b * c)
| mul_right ⦃a b c⦄ : rel b c → rel (a * b) (a * c)
theorem rel.add_right {r : R → R → Prop} ⦃a b c : R⦄ (h : rel r b c) : rel r (a + b) (a + c) :=
by { rw [add_comm a b, add_comm a c], exact rel.add_left h }
theorem rel.neg {R : Type u₁} [ring R] {r : R → R → Prop} ⦃a b : R⦄ (h : rel r a b) : rel r (-a) (-b) :=
by simp only [neg_eq_neg_one_mul a, neg_eq_neg_one_mul b, rel.mul_right h]
theorem rel.smul {r : A → A → Prop} (k : S) ⦃a b : A⦄ (h : rel r a b) : rel r (k • a) (k • b) :=
by simp only [algebra.smul_def, rel.mul_right h]
end ring_quot
/-- The quotient of a ring by an arbitrary relation. -/
def ring_quot (r : R → R → Prop) := quot (ring_quot.rel r)
namespace ring_quot
instance (r : R → R → Prop) : semiring (ring_quot r) :=
{ add := quot.map₂ (+) rel.add_right rel.add_left,
add_assoc := by { rintros ⟨⟩ ⟨⟩ ⟨⟩, exact congr_arg (quot.mk _) (add_assoc _ _ _), },
zero := quot.mk _ 0,
zero_add := by { rintros ⟨⟩, exact congr_arg (quot.mk _) (zero_add _), },
add_zero := by { rintros ⟨⟩, exact congr_arg (quot.mk _) (add_zero _), },
zero_mul := by { rintros ⟨⟩, exact congr_arg (quot.mk _) (zero_mul _), },
mul_zero := by { rintros ⟨⟩, exact congr_arg (quot.mk _) (mul_zero _), },
add_comm := by { rintros ⟨⟩ ⟨⟩, exact congr_arg (quot.mk _) (add_comm _ _), },
mul := quot.map₂ (*) rel.mul_right rel.mul_left,
mul_assoc := by { rintros ⟨⟩ ⟨⟩ ⟨⟩, exact congr_arg (quot.mk _) (mul_assoc _ _ _), },
one := quot.mk _ 1,
one_mul := by { rintros ⟨⟩, exact congr_arg (quot.mk _) (one_mul _), },
mul_one := by { rintros ⟨⟩, exact congr_arg (quot.mk _) (mul_one _), },
left_distrib := by { rintros ⟨⟩ ⟨⟩ ⟨⟩, exact congr_arg (quot.mk _) (left_distrib _ _ _), },
right_distrib := by { rintros ⟨⟩ ⟨⟩ ⟨⟩, exact congr_arg (quot.mk _) (right_distrib _ _ _), }, }
instance {R : Type u₁} [ring R] (r : R → R → Prop) : ring (ring_quot r) :=
{ neg := quot.map (λ a, -a)
rel.neg,
add_left_neg := by { rintros ⟨⟩, exact congr_arg (quot.mk _) (add_left_neg _), },
.. (ring_quot.semiring r) }
instance {R : Type u₁} [comm_semiring R] (r : R → R → Prop) : comm_semiring (ring_quot r) :=
{ mul_comm := by { rintros ⟨⟩ ⟨⟩, exact congr_arg (quot.mk _) (mul_comm _ _), }
.. (ring_quot.semiring r) }
instance {R : Type u₁} [comm_ring R] (r : R → R → Prop) : comm_ring (ring_quot r) :=
{ .. (ring_quot.comm_semiring r),
.. (ring_quot.ring r) }
instance (s : A → A → Prop) : algebra S (ring_quot s) :=
{ smul := λ r, quot.map ((•) r) (rel.smul r),
to_fun := λ r, quot.mk _ (algebra_map S A r),
map_one' := congr_arg (quot.mk _) (ring_hom.map_one _),
map_mul' := λ r s, congr_arg (quot.mk _) (ring_hom.map_mul _ _ _),
map_zero' := congr_arg (quot.mk _) (ring_hom.map_zero _),
map_add' := λ r s, congr_arg (quot.mk _) (ring_hom.map_add _ _ _),
commutes' := λ r, by { rintro ⟨a⟩, exact congr_arg (quot.mk _) (algebra.commutes _ _) },
smul_def' := λ r, by { rintro ⟨a⟩, exact congr_arg (quot.mk _) (algebra.smul_def _ _) }, }
instance (r : R → R → Prop) : inhabited (ring_quot r) := ⟨0⟩
/--
The quotient map from a ring to its quotient, as a homomorphism of rings.
-/
def mk_ring_hom (r : R → R → Prop) : R →+* ring_quot r :=
{ to_fun := quot.mk _,
map_one' := rfl,
map_mul' := λ a b, rfl,
map_zero' := rfl,
map_add' := λ a b, rfl, }
lemma mk_ring_hom_rel {r : R → R → Prop} {x y : R} (w : r x y) :
mk_ring_hom r x = mk_ring_hom r y :=
quot.sound (rel.of w)
lemma mk_ring_hom_surjective (r : R → R → Prop) : function.surjective (mk_ring_hom r) :=
by { dsimp [mk_ring_hom], rintro ⟨⟩, simp, }
@[ext]
lemma ring_quot_ext {T : Type u₄} [semiring T] {r : R → R → Prop} (f g : ring_quot r →+* T)
(w : f.comp (mk_ring_hom r) = g.comp (mk_ring_hom r)) : f = g :=
begin
ext,
rcases mk_ring_hom_surjective r x with ⟨x, rfl⟩,
exact (congr_arg (λ h : R →+* T, h x) w), -- TODO should we have `ring_hom.congr` for this?
end
variables {T : Type u₄} [semiring T]
/--
Any ring homomorphism `f : R →+* T` which respects a relation `r : R → R → Prop`
factors through a morphism `ring_quot r →+* T`.
-/
def lift (f : R →+* T) {r : R → R → Prop} (w : ∀ ⦃x y⦄, r x y → f x = f y) :
ring_quot r →+* T :=
{ to_fun := quot.lift f
begin
rintros _ _ r,
induction r,
case of : _ _ r { exact w r, },
case add_left : _ _ _ _ r' { simp [r'], },
case mul_left : _ _ _ _ r' { simp [r'], },
case mul_right : _ _ _ _ r' { simp [r'], },
end,
map_zero' := f.map_zero,
map_add' := by { rintros ⟨x⟩ ⟨y⟩, exact f.map_add x y, },
map_one' := f.map_one,
map_mul' := by { rintros ⟨x⟩ ⟨y⟩, exact f.map_mul x y, }, }
@[simp]
lemma lift_mk_ring_hom_apply (f : R →+* T) {r : R → R → Prop} (w : ∀ ⦃x y⦄, r x y → f x = f y) (x) :
(lift f w) (mk_ring_hom r x) = f x :=
rfl
lemma lift_unique (f : R →+* T) {r : R → R → Prop} (w : ∀ ⦃x y⦄, r x y → f x = f y)
(g : ring_quot r →+* T) (h : g.comp (mk_ring_hom r) = f) : g = lift f w :=
by { ext, simp [h], }
lemma eq_lift_comp_mk_ring_hom {r : R → R → Prop} (f : ring_quot r →+* T) :
f = lift (f.comp (mk_ring_hom r)) (λ x y h, by { dsimp, rw mk_ring_hom_rel h, }) :=
by { ext, simp, }
section comm_ring
/-!
We now verify that in the case of a commutative ring, the `ring_quot` construction
agrees with the quotient by the appropriate ideal.
-/
variables {B : Type u₁} [comm_ring B]
/-- The universal ring homomorphism from `ring_quot r` to `(ideal.of_rel r).quotient`. -/
def ring_quot_to_ideal_quotient (r : B → B → Prop) :
ring_quot r →+* (ideal.of_rel r).quotient :=
lift
(ideal.quotient.mk (ideal.of_rel r))
(λ x y h, quot.sound (submodule.mem_Inf.mpr (λ p w, w ⟨x, y, h, rfl⟩)))
@[simp] lemma ring_quot_to_ideal_quotient_apply (r : B → B → Prop) (x : B) :
ring_quot_to_ideal_quotient r (mk_ring_hom r x) = ideal.quotient.mk _ x := rfl
/-- The universal ring homomorphism from `(ideal.of_rel r).quotient` to `ring_quot r`. -/
def ideal_quotient_to_ring_quot (r : B → B → Prop) :
(ideal.of_rel r).quotient →+* ring_quot r :=
ideal.quotient.lift (ideal.of_rel r) (mk_ring_hom r)
begin
intros x h,
apply submodule.span_induction h,
{ rintros - ⟨a,b,h,rfl⟩,
rw [ring_hom.map_sub, mk_ring_hom_rel h, sub_self], },
{ simp, },
{ intros a b ha hb, simp [ha, hb], },
{ intros a x hx, simp [hx], },
end
@[simp] lemma ideal_quotient_to_ring_quot_apply (r : B → B → Prop) (x : B) :
ideal_quotient_to_ring_quot r (ideal.quotient.mk _ x) = mk_ring_hom r x := rfl
/--
The ring equivalence between `ring_quot r` and `(ideal.of_rel r).quotient`
-/
def ring_quot_equiv_ideal_quotient (r : B → B → Prop) :
ring_quot r ≃+* (ideal.of_rel r).quotient :=
ring_equiv.of_hom_inv (ring_quot_to_ideal_quotient r) (ideal_quotient_to_ring_quot r)
(by { ext, simp, }) (by { ext ⟨x⟩, simp, })
end comm_ring
section algebra
variables (S)
/--
The quotient map from an `S`-algebra to its quotient, as a homomorphism of `S`-algebras.
-/
def mk_alg_hom (s : A → A → Prop) : A →ₐ[S] ring_quot s :=
{ commutes' := λ r, rfl,
..mk_ring_hom s }
@[simp]
lemma mk_alg_hom_coe (s : A → A → Prop) : (mk_alg_hom S s : A →+* ring_quot s) = mk_ring_hom s :=
rfl
lemma mk_alg_hom_rel {s : A → A → Prop} {x y : A} (w : s x y) :
mk_alg_hom S s x = mk_alg_hom S s y :=
quot.sound (rel.of w)
lemma mk_alg_hom_surjective (s : A → A → Prop) : function.surjective (mk_alg_hom S s) :=
by { dsimp [mk_alg_hom], rintro ⟨a⟩, use a, refl, }
variables {B : Type u₄} [semiring B] [algebra S B]
@[ext]
lemma ring_quot_ext' {s : A → A → Prop}
(f g : ring_quot s →ₐ[S] B) (w : f.comp (mk_alg_hom S s) = g.comp (mk_alg_hom S s)) : f = g :=
begin
ext,
rcases mk_alg_hom_surjective S s x with ⟨x, rfl⟩,
exact (congr_arg (λ h : A →ₐ[S] B, h x) w), -- TODO should we have `alg_hom.congr` for this?
end
/--
Any `S`-algebra homomorphism `f : A →ₐ[S] B` which respects a relation `s : A → A → Prop`
factors through a morphism `ring_quot s →ₐ[S] B`.
-/
def lift_alg_hom (f : A →ₐ[S] B) {s : A → A → Prop} (w : ∀ ⦃x y⦄, s x y → f x = f y) :
ring_quot s →ₐ[S] B :=
{ to_fun := quot.lift f
begin
rintros _ _ r,
induction r,
case of : _ _ r { exact w r, },
case add_left : _ _ _ _ r' { simp [r'], },
case mul_left : _ _ _ _ r' { simp [r'], },
case mul_right : _ _ _ _ r' { simp [r'], },
end,
map_zero' := f.map_zero,
map_add' := by { rintros ⟨x⟩ ⟨y⟩, exact f.map_add x y, },
map_one' := f.map_one,
map_mul' := by { rintros ⟨x⟩ ⟨y⟩, exact f.map_mul x y, },
commutes' :=
begin
rintros x,
conv_rhs { rw [algebra.algebra_map_eq_smul_one, ←f.map_one, ←f.map_smul], },
rw algebra.algebra_map_eq_smul_one,
exact quot.lift_beta f @w (x • 1),
end, }
@[simp]
lemma lift_alg_hom_mk_alg_hom_apply (f : A →ₐ[S] B) {s : A → A → Prop} (w : ∀ ⦃x y⦄, s x y → f x = f y) (x) :
(lift_alg_hom S f w) ((mk_alg_hom S s) x) = f x :=
rfl
lemma lift_alg_hom_unique (f : A →ₐ[S] B) {s : A → A → Prop} (w : ∀ ⦃x y⦄, s x y → f x = f y)
(g : ring_quot s →ₐ[S] B) (h : g.comp (mk_alg_hom S s) = f) : g = lift_alg_hom S f w :=
by { ext, simp [h], }
lemma eq_lift_alg_hom_comp_mk_alg_hom {s : A → A → Prop} (f : ring_quot s →ₐ[S] B) :
f = lift_alg_hom S (f.comp (mk_alg_hom S s)) (λ x y h, by { dsimp, erw mk_alg_hom_rel S h, }) :=
by { ext, simp, }
end algebra
attribute [irreducible] ring_quot mk_ring_hom mk_alg_hom lift lift_alg_hom
end ring_quot
|
06552e54c622188695d0b6979c7a2b8532e0bcd6 | 74addaa0e41490cbaf2abd313a764c96df57b05d | /Mathlib/set_theory/ordinal_arithmetic_auto.lean | 12a518b758812b5bd0334c2c3d64d0cfbcec0fe7 | [] | 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 | 45,280 | lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Mario Carneiro
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.set_theory.ordinal
import Mathlib.PostPort
universes u_1 u_2 u u_3 v
namespace Mathlib
/-!
# Ordinal arithmetic
Ordinals have an addition (corresponding to disjoint union) that turns them into an additive
monoid, and a multiplication (corresponding to the lexicographic order on the product) that turns
them into a monoid. One can also define correspondingly a subtraction, a division, a successor
function, a power function and a logarithm function.
We also define limit ordinals and prove the basic induction principle on ordinals separating
successor ordinals and limit ordinals, in `limit_rec_on`.
## Main definitions and results
* `o₁ + o₂` is the order on the disjoint union of `o₁` and `o₂` obtained by declaring that
every element of `o₁` is smaller than every element of `o₂`.
* `o₁ - o₂` is the unique ordinal `o` such that `o₂ + o = o₁`, when `o₂ ≤ o₁`.
* `o₁ * o₂` is the lexicographic order on `o₂ × o₁`.
* `o₁ / o₂` is the ordinal `o` such that `o₁ = o₂ * o + o'` with `o' < o₂`. We also define the
divisibility predicate, and a modulo operation.
* `succ o = o + 1` is the successor of `o`.
* `pred o` if the predecessor of `o`. If `o` is not a successor, we set `pred o = o`.
We also define the power function and the logarithm function on ordinals, and discuss the properties
of casts of natural numbers of and of `omega` with respect to these operations.
Some properties of the operations are also used to discuss general tools on ordinals:
* `is_limit o`: an ordinal is a limit ordinal if it is neither `0` nor a successor.
* `limit_rec_on` is the main induction principle of ordinals: if one can prove a property by
induction at successor ordinals and at limit ordinals, then it holds for all ordinals.
* `is_normal`: a function `f : ordinal → ordinal` satisfies `is_normal` if it is strictly increasing
and order-continuous, i.e., the image `f o` of a limit ordinal `o` is the sup of `f a` for
`a < o`.
* `nfp f a`: the next fixed point of a function `f` on ordinals, above `a`. It behaves well
for normal functions.
* `CNF b o` is the Cantor normal form of the ordinal `o` in base `b`.
* `sup`: the supremum of an indexed family of ordinals in `Type u`, as an ordinal in `Type u`.
* `bsup`: the supremum of a set of ordinals indexed by ordinals less than a given ordinal `o`.
-/
namespace ordinal
/-! ### Further properties of addition on ordinals -/
@[simp] theorem lift_add (a : ordinal) (b : ordinal) : lift (a + b) = lift a + lift b := sorry
@[simp] theorem lift_succ (a : ordinal) : lift (succ a) = succ (lift a) := sorry
theorem add_le_add_iff_left (a : ordinal) {b : ordinal} {c : ordinal} : a + b ≤ a + c ↔ b ≤ c :=
sorry
theorem add_succ (o₁ : ordinal) (o₂ : ordinal) : o₁ + succ o₂ = succ (o₁ + o₂) :=
Eq.symm (add_assoc o₁ o₂ 1)
@[simp] theorem succ_zero : succ 0 = 1 := zero_add 1
theorem one_le_iff_pos {o : ordinal} : 1 ≤ o ↔ 0 < o :=
eq.mpr (id (Eq._oldrec (Eq.refl (1 ≤ o ↔ 0 < o)) (Eq.symm succ_zero)))
(eq.mpr (id (Eq._oldrec (Eq.refl (succ 0 ≤ o ↔ 0 < o)) (propext succ_le))) (iff.refl (0 < o)))
theorem one_le_iff_ne_zero {o : ordinal} : 1 ≤ o ↔ o ≠ 0 :=
eq.mpr (id (Eq._oldrec (Eq.refl (1 ≤ o ↔ o ≠ 0)) (propext one_le_iff_pos)))
(eq.mpr (id (Eq._oldrec (Eq.refl (0 < o ↔ o ≠ 0)) (propext ordinal.pos_iff_ne_zero)))
(iff.refl (o ≠ 0)))
theorem succ_pos (o : ordinal) : 0 < succ o := lt_of_le_of_lt (ordinal.zero_le o) (lt_succ_self o)
theorem succ_ne_zero (o : ordinal) : succ o ≠ 0 := ne_of_gt (succ_pos o)
@[simp] theorem card_succ (o : ordinal) : card (succ o) = card o + 1 := sorry
theorem nat_cast_succ (n : ℕ) : succ ↑n = ↑(Nat.succ n) := rfl
theorem add_left_cancel (a : ordinal) {b : ordinal} {c : ordinal} : a + b = a + c ↔ b = c := sorry
theorem lt_succ {a : ordinal} {b : ordinal} : a < succ b ↔ a ≤ b :=
eq.mpr (id (Eq._oldrec (Eq.refl (a < succ b ↔ a ≤ b)) (Eq.symm (propext not_le))))
(eq.mpr (id (Eq._oldrec (Eq.refl (¬succ b ≤ a ↔ a ≤ b)) (propext succ_le)))
(eq.mpr (id (Eq._oldrec (Eq.refl (¬b < a ↔ a ≤ b)) (propext not_lt))) (iff.refl (a ≤ b))))
theorem add_lt_add_iff_left (a : ordinal) {b : ordinal} {c : ordinal} : a + b < a + c ↔ b < c :=
sorry
theorem lt_of_add_lt_add_right {a : ordinal} {b : ordinal} {c : ordinal} : a + b < c + b → a < c :=
lt_imp_lt_of_le_imp_le fun (h : c ≤ a) => add_le_add_right h b
@[simp] theorem succ_lt_succ {a : ordinal} {b : ordinal} : succ a < succ b ↔ a < b :=
eq.mpr (id (Eq._oldrec (Eq.refl (succ a < succ b ↔ a < b)) (propext lt_succ)))
(eq.mpr (id (Eq._oldrec (Eq.refl (succ a ≤ b ↔ a < b)) (propext succ_le))) (iff.refl (a < b)))
@[simp] theorem succ_le_succ {a : ordinal} {b : ordinal} : succ a ≤ succ b ↔ a ≤ b :=
iff.mpr le_iff_le_iff_lt_iff_lt succ_lt_succ
theorem succ_inj {a : ordinal} {b : ordinal} : succ a = succ b ↔ a = b := sorry
theorem add_le_add_iff_right {a : ordinal} {b : ordinal} (n : ℕ) : a + ↑n ≤ b + ↑n ↔ a ≤ b := sorry
theorem add_right_cancel {a : ordinal} {b : ordinal} (n : ℕ) : a + ↑n = b + ↑n ↔ a = b := sorry
/-! ### The zero ordinal -/
@[simp] theorem card_eq_zero {o : ordinal} : card o = 0 ↔ o = 0 := sorry
theorem type_ne_zero_iff_nonempty {α : Type u_1} {r : α → α → Prop} [is_well_order α r] :
type r ≠ 0 ↔ Nonempty α :=
iff.trans (iff.symm (not_congr card_eq_zero)) cardinal.ne_zero_iff_nonempty
@[simp] theorem type_eq_zero_iff_empty {α : Type u_1} {r : α → α → Prop} [is_well_order α r] :
type r = 0 ↔ ¬Nonempty α :=
iff.symm (iff.mp not_iff_comm type_ne_zero_iff_nonempty)
protected theorem one_ne_zero : 1 ≠ 0 :=
iff.mpr type_ne_zero_iff_nonempty (Nonempty.intro PUnit.unit)
protected instance nontrivial : nontrivial ordinal :=
nontrivial.mk (Exists.intro 1 (Exists.intro 0 ordinal.one_ne_zero))
theorem zero_lt_one : 0 < 1 :=
iff.mpr lt_iff_le_and_ne { left := ordinal.zero_le 1, right := ne.symm ordinal.one_ne_zero }
/-! ### The predecessor of an ordinal -/
/-- The ordinal predecessor of `o` is `o'` if `o = succ o'`,
and `o` otherwise. -/
def pred (o : ordinal) : ordinal :=
dite (∃ (a : ordinal), o = succ a) (fun (h : ∃ (a : ordinal), o = succ a) => classical.some h)
fun (h : ¬∃ (a : ordinal), o = succ a) => o
@[simp] theorem pred_succ (o : ordinal) : pred (succ o) = o := sorry
theorem pred_le_self (o : ordinal) : pred o ≤ o := sorry
theorem pred_eq_iff_not_succ {o : ordinal} : pred o = o ↔ ¬∃ (a : ordinal), o = succ a := sorry
theorem pred_lt_iff_is_succ {o : ordinal} : pred o < o ↔ ∃ (a : ordinal), o = succ a := sorry
theorem succ_pred_iff_is_succ {o : ordinal} : succ (pred o) = o ↔ ∃ (a : ordinal), o = succ a :=
sorry
theorem succ_lt_of_not_succ {o : ordinal} (h : ¬∃ (a : ordinal), o = succ a) {b : ordinal} :
succ b < o ↔ b < o :=
{ mp := lt_trans (lt_succ_self b),
mpr :=
fun (l : b < o) =>
lt_of_le_of_ne (iff.mpr succ_le l) fun (e : succ b = o) => h (Exists.intro b (Eq.symm e)) }
theorem lt_pred {a : ordinal} {b : ordinal} : a < pred b ↔ succ a < b := sorry
theorem pred_le {a : ordinal} {b : ordinal} : pred a ≤ b ↔ a ≤ succ b :=
iff.mpr le_iff_le_iff_lt_iff_lt lt_pred
@[simp] theorem lift_is_succ {o : ordinal} :
(∃ (a : ordinal), lift o = succ a) ↔ ∃ (a : ordinal), o = succ a :=
sorry
@[simp] theorem lift_pred (o : ordinal) : lift (pred o) = pred (lift o) := sorry
/-! ### Limit ordinals -/
/-- A limit ordinal is an ordinal which is not zero and not a successor. -/
def is_limit (o : ordinal) := o ≠ 0 ∧ ∀ (a : ordinal), a < o → succ a < o
theorem not_zero_is_limit : ¬is_limit 0 :=
fun (ᾰ : is_limit 0) =>
and.dcases_on ᾰ
fun (ᾰ_left : 0 ≠ 0) (ᾰ_right : ∀ (a : ordinal), a < 0 → succ a < 0) =>
idRhs False (ᾰ_left rfl)
theorem not_succ_is_limit (o : ordinal) : ¬is_limit (succ o) := sorry
theorem not_succ_of_is_limit {o : ordinal} (h : is_limit o) : ¬∃ (a : ordinal), o = succ a :=
fun (ᾰ : ∃ (a : ordinal), o = succ a) =>
Exists.dcases_on ᾰ
fun (ᾰ_w : ordinal) (ᾰ_h : o = succ ᾰ_w) => idRhs False (not_succ_is_limit ᾰ_w (ᾰ_h ▸ h))
theorem succ_lt_of_is_limit {o : ordinal} (h : is_limit o) {a : ordinal} : succ a < o ↔ a < o :=
{ mp := lt_trans (lt_succ_self a), mpr := and.right h a }
theorem le_succ_of_is_limit {o : ordinal} (h : is_limit o) {a : ordinal} : o ≤ succ a ↔ o ≤ a :=
iff.mpr le_iff_le_iff_lt_iff_lt (succ_lt_of_is_limit h)
theorem limit_le {o : ordinal} (h : is_limit o) {a : ordinal} :
o ≤ a ↔ ∀ (x : ordinal), x < o → x ≤ a :=
sorry
theorem lt_limit {o : ordinal} (h : is_limit o) {a : ordinal} :
a < o ↔ ∃ (x : ordinal), ∃ (H : x < o), a < x :=
sorry
@[simp] theorem lift_is_limit (o : ordinal) : is_limit (lift o) ↔ is_limit o := sorry
theorem is_limit.pos {o : ordinal} (h : is_limit o) : 0 < o :=
lt_of_le_of_ne (ordinal.zero_le o) (ne.symm (and.left h))
theorem is_limit.one_lt {o : ordinal} (h : is_limit o) : 1 < o := sorry
theorem is_limit.nat_lt {o : ordinal} (h : is_limit o) (n : ℕ) : ↑n < o := sorry
theorem zero_or_succ_or_limit (o : ordinal) : o = 0 ∨ (∃ (a : ordinal), o = succ a) ∨ is_limit o :=
sorry
/-- Main induction principle of ordinals: if one can prove a property by
induction at successor ordinals and at limit ordinals, then it holds for all ordinals. -/
def limit_rec_on {C : ordinal → Sort u_2} (o : ordinal) (H₁ : C 0)
(H₂ : (o : ordinal) → C o → C (succ o))
(H₃ : (o : ordinal) → is_limit o → ((o' : ordinal) → o' < o → C o') → C o) : C o :=
well_founded.fix wf
(fun (o : ordinal) (IH : (y : ordinal) → y < o → C y) =>
dite (o = 0) (fun (o0 : o = 0) => eq.mpr sorry H₁)
fun (o0 : ¬o = 0) =>
dite (∃ (a : ordinal), o = succ a)
(fun (h : ∃ (a : ordinal), o = succ a) =>
eq.mpr sorry (H₂ (pred o) (IH (pred o) sorry)))
fun (h : ¬∃ (a : ordinal), o = succ a) => H₃ o sorry IH)
o
@[simp] theorem limit_rec_on_zero {C : ordinal → Sort u_2} (H₁ : C 0)
(H₂ : (o : ordinal) → C o → C (succ o))
(H₃ : (o : ordinal) → is_limit o → ((o' : ordinal) → o' < o → C o') → C o) :
limit_rec_on 0 H₁ H₂ H₃ = H₁ :=
sorry
@[simp] theorem limit_rec_on_succ {C : ordinal → Sort u_2} (o : ordinal) (H₁ : C 0)
(H₂ : (o : ordinal) → C o → C (succ o))
(H₃ : (o : ordinal) → is_limit o → ((o' : ordinal) → o' < o → C o') → C o) :
limit_rec_on (succ o) H₁ H₂ H₃ = H₂ o (limit_rec_on o H₁ H₂ H₃) :=
sorry
@[simp] theorem limit_rec_on_limit {C : ordinal → Sort u_2} (o : ordinal) (H₁ : C 0)
(H₂ : (o : ordinal) → C o → C (succ o))
(H₃ : (o : ordinal) → is_limit o → ((o' : ordinal) → o' < o → C o') → C o) (h : is_limit o) :
limit_rec_on o H₁ H₂ H₃ = H₃ o h fun (x : ordinal) (h : x < o) => limit_rec_on x H₁ H₂ H₃ :=
sorry
theorem has_succ_of_is_limit {α : Type u_1} {r : α → α → Prop} [wo : is_well_order α r]
(h : is_limit (type r)) (x : α) : ∃ (y : α), r x y :=
sorry
theorem type_subrel_lt (o : ordinal) :
type (subrel Less (set_of fun (o' : ordinal) => o' < o)) = lift o :=
sorry
theorem mk_initial_seg (o : ordinal) :
cardinal.mk ↥(set_of fun (o' : ordinal) => o' < o) = cardinal.lift (card o) :=
sorry
/-! ### Normal ordinal functions -/
/-- A normal ordinal function is a strictly increasing function which is
order-continuous, i.e., the image `f o` of a limit ordinal `o` is the sup of `f a` for
`a < o`. -/
def is_normal (f : ordinal → ordinal) :=
(∀ (o : ordinal), f o < f (succ o)) ∧
∀ (o : ordinal), is_limit o → ∀ (a : ordinal), f o ≤ a ↔ ∀ (b : ordinal), b < o → f b ≤ a
theorem is_normal.limit_le {f : ordinal → ordinal} (H : is_normal f) {o : ordinal} :
is_limit o → ∀ {a : ordinal}, f o ≤ a ↔ ∀ (b : ordinal), b < o → f b ≤ a :=
and.right H
theorem is_normal.limit_lt {f : ordinal → ordinal} (H : is_normal f) {o : ordinal} (h : is_limit o)
{a : ordinal} : a < f o ↔ ∃ (b : ordinal), ∃ (H : b < o), a < f b :=
sorry
theorem is_normal.lt_iff {f : ordinal → ordinal} (H : is_normal f) {a : ordinal} {b : ordinal} :
f a < f b ↔ a < b :=
sorry
theorem is_normal.le_iff {f : ordinal → ordinal} (H : is_normal f) {a : ordinal} {b : ordinal} :
f a ≤ f b ↔ a ≤ b :=
iff.mpr le_iff_le_iff_lt_iff_lt (is_normal.lt_iff H)
theorem is_normal.inj {f : ordinal → ordinal} (H : is_normal f) {a : ordinal} {b : ordinal} :
f a = f b ↔ a = b :=
sorry
theorem is_normal.le_self {f : ordinal → ordinal} (H : is_normal f) (a : ordinal) : a ≤ f a := sorry
theorem is_normal.le_set {f : ordinal → ordinal} (H : is_normal f) (p : ordinal → Prop)
(p0 : ∃ (x : ordinal), p x) (S : ordinal)
(H₂ : ∀ (o : ordinal), S ≤ o ↔ ∀ (a : ordinal), p a → a ≤ o) {o : ordinal} :
f S ≤ o ↔ ∀ (a : ordinal), p a → f a ≤ o :=
sorry
theorem is_normal.le_set' {α : Type u_1} {f : ordinal → ordinal} (H : is_normal f) (p : α → Prop)
(g : α → ordinal) (p0 : ∃ (x : α), p x) (S : ordinal)
(H₂ : ∀ (o : ordinal), S ≤ o ↔ ∀ (a : α), p a → g a ≤ o) {o : ordinal} :
f S ≤ o ↔ ∀ (a : α), p a → f (g a) ≤ o :=
sorry
theorem is_normal.refl : is_normal id :=
{ left := fun (x : ordinal) => lt_succ_self (id x),
right := fun (o : ordinal) (l : is_limit o) (a : ordinal) => limit_le l }
theorem is_normal.trans {f : ordinal → ordinal} {g : ordinal → ordinal} (H₁ : is_normal f)
(H₂ : is_normal g) : is_normal fun (x : ordinal) => f (g x) :=
sorry
theorem is_normal.is_limit {f : ordinal → ordinal} (H : is_normal f) {o : ordinal}
(l : is_limit o) : is_limit (f o) :=
sorry
theorem add_le_of_limit {a : ordinal} {b : ordinal} {c : ordinal} (h : is_limit b) :
a + b ≤ c ↔ ∀ (b' : ordinal), b' < b → a + b' ≤ c :=
sorry
theorem add_is_normal (a : ordinal) : is_normal (Add.add a) :=
{ left := fun (b : ordinal) => iff.mpr (add_lt_add_iff_left a) (lt_succ_self b),
right := fun (b : ordinal) (l : is_limit b) (c : ordinal) => add_le_of_limit l }
theorem add_is_limit (a : ordinal) {b : ordinal} : is_limit b → is_limit (a + b) :=
is_normal.is_limit (add_is_normal a)
/-! ### Subtraction on ordinals-/
/-- `a - b` is the unique ordinal satisfying
`b + (a - b) = a` when `b ≤ a`. -/
def sub (a : ordinal) (b : ordinal) : ordinal := omin (set_of fun (o : ordinal) => a ≤ b + o) sorry
protected instance has_sub : Sub ordinal := { sub := sub }
theorem le_add_sub (a : ordinal) (b : ordinal) : a ≤ b + (a - b) :=
omin_mem (set_of fun (o : ordinal) => a ≤ b + o) (sub._proof_1 a b)
theorem sub_le {a : ordinal} {b : ordinal} {c : ordinal} : a - b ≤ c ↔ a ≤ b + c :=
{ mp := fun (h : a - b ≤ c) => le_trans (le_add_sub a b) (add_le_add_left h b),
mpr := fun (h : a ≤ b + c) => omin_le h }
theorem lt_sub {a : ordinal} {b : ordinal} {c : ordinal} : a < b - c ↔ c + a < b :=
lt_iff_lt_of_le_iff_le sub_le
theorem add_sub_cancel (a : ordinal) (b : ordinal) : a + b - a = b :=
le_antisymm (iff.mpr sub_le (le_refl (a + b)))
(iff.mp (add_le_add_iff_left a) (le_add_sub (a + b) a))
theorem sub_eq_of_add_eq {a : ordinal} {b : ordinal} {c : ordinal} (h : a + b = c) : c - a = b :=
h ▸ add_sub_cancel a b
theorem sub_le_self (a : ordinal) (b : ordinal) : a - b ≤ a := iff.mpr sub_le (le_add_left a b)
theorem add_sub_cancel_of_le {a : ordinal} {b : ordinal} (h : b ≤ a) : b + (a - b) = a := sorry
@[simp] theorem sub_zero (a : ordinal) : a - 0 = a := sorry
@[simp] theorem zero_sub (a : ordinal) : 0 - a = 0 :=
eq.mpr (id (Eq._oldrec (Eq.refl (0 - a = 0)) (Eq.symm (propext ordinal.le_zero))))
(sub_le_self 0 a)
@[simp] theorem sub_self (a : ordinal) : a - a = 0 := sorry
theorem sub_eq_zero_iff_le {a : ordinal} {b : ordinal} : a - b = 0 ↔ a ≤ b := sorry
theorem sub_sub (a : ordinal) (b : ordinal) (c : ordinal) : a - b - c = a - (b + c) := sorry
theorem add_sub_add_cancel (a : ordinal) (b : ordinal) (c : ordinal) : a + b - (a + c) = b - c :=
eq.mpr (id (Eq._oldrec (Eq.refl (a + b - (a + c) = b - c)) (Eq.symm (sub_sub (a + b) a c))))
(eq.mpr (id (Eq._oldrec (Eq.refl (a + b - a - c = b - c)) (add_sub_cancel a b)))
(Eq.refl (b - c)))
theorem sub_is_limit {a : ordinal} {b : ordinal} (l : is_limit a) (h : b < a) : is_limit (a - b) :=
sorry
@[simp] theorem one_add_omega : 1 + omega = omega := sorry
@[simp] theorem one_add_of_omega_le {o : ordinal} (h : omega ≤ o) : 1 + o = o := sorry
/-! ### Multiplication of ordinals-/
/-- The multiplication of ordinals `o₁` and `o₂` is the (well founded) lexicographic order on
`o₂ × o₁`. -/
protected instance monoid : monoid ordinal :=
monoid.mk (fun (a b : ordinal) => quotient.lift_on₂ a b (fun (_x : Well_order) => sorry) sorry)
sorry 1 sorry sorry
@[simp] theorem type_mul {α : Type u} {β : Type u} (r : α → α → Prop) (s : β → β → Prop)
[is_well_order α r] [is_well_order β s] : type r * type s = type (prod.lex s r) :=
rfl
@[simp] theorem lift_mul (a : ordinal) (b : ordinal) : lift (a * b) = lift a * lift b := sorry
@[simp] theorem card_mul (a : ordinal) (b : ordinal) : card (a * b) = card a * card b := sorry
@[simp] theorem mul_zero (a : ordinal) : a * 0 = 0 := sorry
@[simp] theorem zero_mul (a : ordinal) : 0 * a = 0 := sorry
theorem mul_add (a : ordinal) (b : ordinal) (c : ordinal) : a * (b + c) = a * b + a * c := sorry
@[simp] theorem mul_add_one (a : ordinal) (b : ordinal) : a * (b + 1) = a * b + a := sorry
@[simp] theorem mul_succ (a : ordinal) (b : ordinal) : a * succ b = a * b + a := mul_add_one a b
theorem mul_le_mul_left {a : ordinal} {b : ordinal} (c : ordinal) : a ≤ b → c * a ≤ c * b := sorry
theorem mul_le_mul_right {a : ordinal} {b : ordinal} (c : ordinal) : a ≤ b → a * c ≤ b * c := sorry
theorem mul_le_mul {a : ordinal} {b : ordinal} {c : ordinal} {d : ordinal} (h₁ : a ≤ c)
(h₂ : b ≤ d) : a * b ≤ c * d :=
le_trans (mul_le_mul_left a h₂) (mul_le_mul_right d h₁)
theorem mul_le_of_limit {a : ordinal} {b : ordinal} {c : ordinal} (h : is_limit b) :
a * b ≤ c ↔ ∀ (b' : ordinal), b' < b → a * b' ≤ c :=
sorry
theorem mul_is_normal {a : ordinal} (h : 0 < a) : is_normal (Mul.mul a) := sorry
theorem lt_mul_of_limit {a : ordinal} {b : ordinal} {c : ordinal} (h : is_limit c) :
a < b * c ↔ ∃ (c' : ordinal), ∃ (H : c' < c), a < b * c' :=
sorry
theorem mul_lt_mul_iff_left {a : ordinal} {b : ordinal} {c : ordinal} (a0 : 0 < a) :
a * b < a * c ↔ b < c :=
is_normal.lt_iff (mul_is_normal a0)
theorem mul_le_mul_iff_left {a : ordinal} {b : ordinal} {c : ordinal} (a0 : 0 < a) :
a * b ≤ a * c ↔ b ≤ c :=
is_normal.le_iff (mul_is_normal a0)
theorem mul_lt_mul_of_pos_left {a : ordinal} {b : ordinal} {c : ordinal} (h : a < b) (c0 : 0 < c) :
c * a < c * b :=
iff.mpr (mul_lt_mul_iff_left c0) h
theorem mul_pos {a : ordinal} {b : ordinal} (h₁ : 0 < a) (h₂ : 0 < b) : 0 < a * b := sorry
theorem mul_ne_zero {a : ordinal} {b : ordinal} : a ≠ 0 → b ≠ 0 → a * b ≠ 0 := sorry
theorem le_of_mul_le_mul_left {a : ordinal} {b : ordinal} {c : ordinal} (h : c * a ≤ c * b)
(h0 : 0 < c) : a ≤ b :=
le_imp_le_of_lt_imp_lt (fun (h' : b < a) => mul_lt_mul_of_pos_left h' h0) h
theorem mul_right_inj {a : ordinal} {b : ordinal} {c : ordinal} (a0 : 0 < a) :
a * b = a * c ↔ b = c :=
is_normal.inj (mul_is_normal a0)
theorem mul_is_limit {a : ordinal} {b : ordinal} (a0 : 0 < a) : is_limit b → is_limit (a * b) :=
is_normal.is_limit (mul_is_normal a0)
theorem mul_is_limit_left {a : ordinal} {b : ordinal} (l : is_limit a) (b0 : 0 < b) :
is_limit (a * b) :=
sorry
/-! ### Division on ordinals -/
protected theorem div_aux (a : ordinal) (b : ordinal) (h : b ≠ 0) :
set.nonempty (set_of fun (o : ordinal) => a < b * succ o) :=
sorry
/-- `a / b` is the unique ordinal `o` satisfying
`a = b * o + o'` with `o' < b`. -/
protected def div (a : ordinal) (b : ordinal) : ordinal :=
dite (b = 0) (fun (h : b = 0) => 0)
fun (h : ¬b = 0) => omin (set_of fun (o : ordinal) => a < b * succ o) (ordinal.div_aux a b h)
protected instance has_div : Div ordinal := { div := ordinal.div }
@[simp] theorem div_zero (a : ordinal) : a / 0 = 0 := dif_pos rfl
theorem div_def (a : ordinal) {b : ordinal} (h : b ≠ 0) :
a / b = omin (set_of fun (o : ordinal) => a < b * succ o) (ordinal.div_aux a b h) :=
dif_neg h
theorem lt_mul_succ_div (a : ordinal) {b : ordinal} (h : b ≠ 0) : a < b * succ (a / b) :=
eq.mpr (id (Eq._oldrec (Eq.refl (a < b * succ (a / b))) (div_def a h)))
(omin_mem (set_of fun (o : ordinal) => a < b * succ o) (ordinal.div_aux a b h))
theorem lt_mul_div_add (a : ordinal) {b : ordinal} (h : b ≠ 0) : a < b * (a / b) + b := sorry
theorem div_le {a : ordinal} {b : ordinal} {c : ordinal} (b0 : b ≠ 0) :
a / b ≤ c ↔ a < b * succ c :=
{ mp :=
fun (h : a / b ≤ c) =>
lt_of_lt_of_le (lt_mul_succ_div a b0) (mul_le_mul_left b (iff.mpr succ_le_succ h)),
mpr :=
fun (h : a < b * succ c) =>
eq.mpr (id (Eq._oldrec (Eq.refl (a / b ≤ c)) (div_def a b0))) (omin_le h) }
theorem lt_div {a : ordinal} {b : ordinal} {c : ordinal} (c0 : c ≠ 0) :
a < b / c ↔ c * succ a ≤ b :=
sorry
theorem le_div {a : ordinal} {b : ordinal} {c : ordinal} (c0 : c ≠ 0) : a ≤ b / c ↔ c * a ≤ b :=
sorry
theorem div_lt {a : ordinal} {b : ordinal} {c : ordinal} (b0 : b ≠ 0) : a / b < c ↔ a < b * c :=
lt_iff_lt_of_le_iff_le (le_div b0)
theorem div_le_of_le_mul {a : ordinal} {b : ordinal} {c : ordinal} (h : a ≤ b * c) : a / b ≤ c :=
sorry
theorem mul_lt_of_lt_div {a : ordinal} {b : ordinal} {c : ordinal} : a < b / c → c * a < b :=
lt_imp_lt_of_le_imp_le div_le_of_le_mul
@[simp] theorem zero_div (a : ordinal) : 0 / a = 0 :=
iff.mp ordinal.le_zero (div_le_of_le_mul (ordinal.zero_le (a * 0)))
theorem mul_div_le (a : ordinal) (b : ordinal) : b * (a / b) ≤ a := sorry
theorem mul_add_div (a : ordinal) {b : ordinal} (b0 : b ≠ 0) (c : ordinal) :
(b * a + c) / b = a + c / b :=
sorry
theorem div_eq_zero_of_lt {a : ordinal} {b : ordinal} (h : a < b) : a / b = 0 := sorry
@[simp] theorem mul_div_cancel (a : ordinal) {b : ordinal} (b0 : b ≠ 0) : b * a / b = a := sorry
@[simp] theorem div_one (a : ordinal) : a / 1 = a := sorry
@[simp] theorem div_self {a : ordinal} (h : a ≠ 0) : a / a = 1 := sorry
theorem mul_sub (a : ordinal) (b : ordinal) (c : ordinal) : a * (b - c) = a * b - a * c := sorry
theorem is_limit_add_iff {a : ordinal} {b : ordinal} :
is_limit (a + b) ↔ is_limit b ∨ b = 0 ∧ is_limit a :=
sorry
theorem dvd_add_iff {a : ordinal} {b : ordinal} {c : ordinal} : a ∣ b → (a ∣ b + c ↔ a ∣ c) := sorry
theorem dvd_add {a : ordinal} {b : ordinal} {c : ordinal} (h₁ : a ∣ b) : a ∣ c → a ∣ b + c :=
iff.mpr (dvd_add_iff h₁)
theorem dvd_zero (a : ordinal) : a ∣ 0 := Exists.intro 0 (Eq.symm (mul_zero a))
theorem zero_dvd {a : ordinal} : 0 ∣ a ↔ a = 0 := sorry
theorem one_dvd (a : ordinal) : 1 ∣ a := Exists.intro a (Eq.symm (one_mul a))
theorem div_mul_cancel {a : ordinal} {b : ordinal} : a ≠ 0 → a ∣ b → a * (b / a) = b := sorry
theorem le_of_dvd {a : ordinal} {b : ordinal} : b ≠ 0 → a ∣ b → a ≤ b := sorry
theorem dvd_antisymm {a : ordinal} {b : ordinal} (h₁ : a ∣ b) (h₂ : b ∣ a) : a = b := sorry
/-- `a % b` is the unique ordinal `o'` satisfying
`a = b * o + o'` with `o' < b`. -/
protected instance has_mod : Mod ordinal := { mod := fun (a b : ordinal) => a - b * (a / b) }
theorem mod_def (a : ordinal) (b : ordinal) : a % b = a - b * (a / b) := rfl
@[simp] theorem mod_zero (a : ordinal) : a % 0 = a := sorry
theorem mod_eq_of_lt {a : ordinal} {b : ordinal} (h : a < b) : a % b = a := sorry
@[simp] theorem zero_mod (b : ordinal) : 0 % b = 0 := sorry
theorem div_add_mod (a : ordinal) (b : ordinal) : b * (a / b) + a % b = a :=
add_sub_cancel_of_le (mul_div_le a b)
theorem mod_lt (a : ordinal) {b : ordinal} (h : b ≠ 0) : a % b < b :=
iff.mp (add_lt_add_iff_left (b * (a / b)))
(eq.mpr (id (Eq._oldrec (Eq.refl (b * (a / b) + a % b < b * (a / b) + b)) (div_add_mod a b)))
(lt_mul_div_add a h))
@[simp] theorem mod_self (a : ordinal) : a % a = 0 := sorry
@[simp] theorem mod_one (a : ordinal) : a % 1 = 0 := sorry
/-! ### Supremum of a family of ordinals -/
/-- The supremum of a family of ordinals -/
def sup {ι : Type u_1} (f : ι → ordinal) : ordinal :=
omin (set_of fun (c : ordinal) => ∀ (i : ι), f i ≤ c) sorry
theorem le_sup {ι : Type u_1} (f : ι → ordinal) (i : ι) : f i ≤ sup f :=
omin_mem (set_of fun (c : ordinal) => ∀ (i : ι), f i ≤ c) (sup._proof_1 f)
theorem sup_le {ι : Type u_1} {f : ι → ordinal} {a : ordinal} : sup f ≤ a ↔ ∀ (i : ι), f i ≤ a :=
{ mp := fun (h : sup f ≤ a) (i : ι) => le_trans (le_sup f i) h,
mpr := fun (h : ∀ (i : ι), f i ≤ a) => omin_le h }
theorem lt_sup {ι : Type u_1} {f : ι → ordinal} {a : ordinal} : a < sup f ↔ ∃ (i : ι), a < f i :=
sorry
theorem is_normal.sup {f : ordinal → ordinal} (H : is_normal f) {ι : Type u_1} {g : ι → ordinal}
(h : Nonempty ι) : f (sup g) = sup (f ∘ g) :=
sorry
theorem sup_ord {ι : Type u_1} (f : ι → cardinal) :
(sup fun (i : ι) => cardinal.ord (f i)) = cardinal.ord (cardinal.sup f) :=
sorry
theorem sup_succ {ι : Type u_1} (f : ι → ordinal) :
(sup fun (i : ι) => succ (f i)) ≤ succ (sup f) :=
eq.mpr
(id (Eq._oldrec (Eq.refl ((sup fun (i : ι) => succ (f i)) ≤ succ (sup f))) (propext sup_le)))
fun (i : ι) =>
eq.mpr (id (Eq._oldrec (Eq.refl (succ (f i) ≤ succ (sup f))) (propext succ_le_succ)))
(le_sup f i)
theorem unbounded_range_of_sup_ge {α : Type u} {β : Type u} (r : α → α → Prop) [is_well_order α r]
(f : β → α) (h : type r ≤ sup (typein r ∘ f)) : unbounded r (set.range f) :=
sorry
/-- The supremum of a family of ordinals indexed by the set
of ordinals less than some `o : ordinal.{u}`.
(This is not a special case of `sup` over the subtype,
because `{a // a < o} : Type (u+1)` and `sup` only works over
families in `Type u`.) -/
def bsup (o : ordinal) : ((a : ordinal) → a < o → ordinal) → ordinal := sorry
theorem bsup_le {o : ordinal} {f : (a : ordinal) → a < o → ordinal} {a : ordinal} :
bsup o f ≤ a ↔ ∀ (i : ordinal) (h : i < o), f i h ≤ a :=
sorry
theorem bsup_type {α : Type u_1} (r : α → α → Prop) [is_well_order α r]
(f : (a : ordinal) → a < type r → ordinal) :
bsup (type r) f = sup fun (a : α) => f (typein r a) (typein_lt_type r a) :=
sorry
theorem le_bsup {o : ordinal} (f : (a : ordinal) → a < o → ordinal) (i : ordinal) (h : i < o) :
f i h ≤ bsup o f :=
iff.mp bsup_le (le_refl (bsup o f)) i h
theorem lt_bsup {o : ordinal} {f : (a : ordinal) → a < o → ordinal}
(hf : ∀ {a a' : ordinal} (ha : a < o) (ha' : a' < o), a < a' → f a ha < f a' ha')
(ho : is_limit o) (i : ordinal) (h : i < o) : f i h < bsup o f :=
lt_of_lt_of_le (hf h (and.right ho i h) (lt_succ_self i)) (le_bsup f (succ i) (and.right ho i h))
theorem bsup_id {o : ordinal} (ho : is_limit o) :
(bsup o fun (x : ordinal) (_x : x < o) => x) = o :=
sorry
theorem is_normal.bsup {f : ordinal → ordinal} (H : is_normal f) {o : ordinal}
(g : (a : ordinal) → a < o → ordinal) (h : o ≠ 0) :
f (bsup o g) = bsup o fun (a : ordinal) (h : a < o) => f (g a h) :=
sorry
theorem is_normal.bsup_eq {f : ordinal → ordinal} (H : is_normal f) {o : ordinal} (h : is_limit o) :
(bsup o fun (x : ordinal) (_x : x < o) => f x) = f o :=
sorry
/-! ### Ordinal exponential -/
/-- The ordinal exponential, defined by transfinite recursion. -/
def power (a : ordinal) (b : ordinal) : ordinal :=
ite (a = 0) (1 - b)
(limit_rec_on b 1 (fun (_x IH : ordinal) => IH * a)
fun (b : ordinal) (_x : is_limit b) => bsup b)
protected instance has_pow : has_pow ordinal ordinal := has_pow.mk power
theorem zero_power' (a : ordinal) : 0 ^ a = 1 - a := sorry
@[simp] theorem zero_power {a : ordinal} (a0 : a ≠ 0) : 0 ^ a = 0 :=
eq.mpr (id (Eq._oldrec (Eq.refl (0 ^ a = 0)) (zero_power' a)))
(eq.mpr (id (Eq._oldrec (Eq.refl (1 - a = 0)) (propext sub_eq_zero_iff_le)))
(eq.mpr (id (Eq._oldrec (Eq.refl (1 ≤ a)) (propext one_le_iff_ne_zero))) a0))
@[simp] theorem power_zero (a : ordinal) : a ^ 0 = 1 := sorry
@[simp] theorem power_succ (a : ordinal) (b : ordinal) : a ^ succ b = a ^ b * a := sorry
theorem power_limit {a : ordinal} {b : ordinal} (a0 : a ≠ 0) (h : is_limit b) :
a ^ b = bsup b fun (c : ordinal) (_x : c < b) => a ^ c :=
sorry
theorem power_le_of_limit {a : ordinal} {b : ordinal} {c : ordinal} (a0 : a ≠ 0) (h : is_limit b) :
a ^ b ≤ c ↔ ∀ (b' : ordinal), b' < b → a ^ b' ≤ c :=
sorry
theorem lt_power_of_limit {a : ordinal} {b : ordinal} {c : ordinal} (b0 : b ≠ 0) (h : is_limit c) :
a < b ^ c ↔ ∃ (c' : ordinal), ∃ (H : c' < c), a < b ^ c' :=
sorry
@[simp] theorem power_one (a : ordinal) : a ^ 1 = a := sorry
@[simp] theorem one_power (a : ordinal) : 1 ^ a = 1 := sorry
theorem power_pos {a : ordinal} (b : ordinal) (a0 : 0 < a) : 0 < a ^ b := sorry
theorem power_ne_zero {a : ordinal} (b : ordinal) (a0 : a ≠ 0) : a ^ b ≠ 0 :=
iff.mp ordinal.pos_iff_ne_zero (power_pos b (iff.mpr ordinal.pos_iff_ne_zero a0))
theorem power_is_normal {a : ordinal} (h : 1 < a) : is_normal fun (_y : ordinal) => a ^ _y := sorry
theorem power_lt_power_iff_right {a : ordinal} {b : ordinal} {c : ordinal} (a1 : 1 < a) :
a ^ b < a ^ c ↔ b < c :=
is_normal.lt_iff (power_is_normal a1)
theorem power_le_power_iff_right {a : ordinal} {b : ordinal} {c : ordinal} (a1 : 1 < a) :
a ^ b ≤ a ^ c ↔ b ≤ c :=
is_normal.le_iff (power_is_normal a1)
theorem power_right_inj {a : ordinal} {b : ordinal} {c : ordinal} (a1 : 1 < a) :
a ^ b = a ^ c ↔ b = c :=
is_normal.inj (power_is_normal a1)
theorem power_is_limit {a : ordinal} {b : ordinal} (a1 : 1 < a) : is_limit b → is_limit (a ^ b) :=
is_normal.is_limit (power_is_normal a1)
theorem power_is_limit_left {a : ordinal} {b : ordinal} (l : is_limit a) (hb : b ≠ 0) :
is_limit (a ^ b) :=
sorry
theorem power_le_power_right {a : ordinal} {b : ordinal} {c : ordinal} (h₁ : 0 < a) (h₂ : b ≤ c) :
a ^ b ≤ a ^ c :=
sorry
theorem power_le_power_left {a : ordinal} {b : ordinal} (c : ordinal) (ab : a ≤ b) :
a ^ c ≤ b ^ c :=
sorry
theorem le_power_self {a : ordinal} (b : ordinal) (a1 : 1 < a) : b ≤ a ^ b :=
is_normal.le_self (power_is_normal a1) b
theorem power_lt_power_left_of_succ {a : ordinal} {b : ordinal} {c : ordinal} (ab : a < b) :
a ^ succ c < b ^ succ c :=
sorry
theorem power_add (a : ordinal) (b : ordinal) (c : ordinal) : a ^ (b + c) = a ^ b * a ^ c := sorry
theorem power_dvd_power (a : ordinal) {b : ordinal} {c : ordinal} (h : b ≤ c) : a ^ b ∣ a ^ c :=
eq.mpr (id (Eq._oldrec (Eq.refl (a ^ b ∣ a ^ c)) (Eq.symm (add_sub_cancel_of_le h))))
(eq.mpr (id (Eq._oldrec (Eq.refl (a ^ b ∣ a ^ (b + (c - b)))) (power_add a b (c - b))))
(dvd_mul_right (a ^ b) (a ^ (c - b))))
theorem power_dvd_power_iff {a : ordinal} {b : ordinal} {c : ordinal} (a1 : 1 < a) :
a ^ b ∣ a ^ c ↔ b ≤ c :=
sorry
theorem power_mul (a : ordinal) (b : ordinal) (c : ordinal) : a ^ (b * c) = (a ^ b) ^ c := sorry
/-! ### Ordinal logarithm -/
/-- The ordinal logarithm is the solution `u` to the equation
`x = b ^ u * v + w` where `v < b` and `w < b`. -/
def log (b : ordinal) (x : ordinal) : ordinal :=
dite (1 < b) (fun (h : 1 < b) => pred (omin (set_of fun (o : ordinal) => x < b ^ o) sorry))
fun (h : ¬1 < b) => 0
@[simp] theorem log_not_one_lt {b : ordinal} (b1 : ¬1 < b) (x : ordinal) : log b x = 0 := sorry
theorem log_def {b : ordinal} (b1 : 1 < b) (x : ordinal) :
log b x = pred (omin (set_of fun (o : ordinal) => x < b ^ o) (log._proof_1 b x b1)) :=
sorry
@[simp] theorem log_zero (b : ordinal) : log b 0 = 0 := sorry
theorem succ_log_def {b : ordinal} {x : ordinal} (b1 : 1 < b) (x0 : 0 < x) :
succ (log b x) = omin (set_of fun (o : ordinal) => x < b ^ o) (log._proof_1 b x b1) :=
sorry
theorem lt_power_succ_log {b : ordinal} (b1 : 1 < b) (x : ordinal) : x < b ^ succ (log b x) := sorry
theorem power_log_le (b : ordinal) {x : ordinal} (x0 : 0 < x) : b ^ log b x ≤ x := sorry
theorem le_log {b : ordinal} {x : ordinal} {c : ordinal} (b1 : 1 < b) (x0 : 0 < x) :
c ≤ log b x ↔ b ^ c ≤ x :=
sorry
theorem log_lt {b : ordinal} {x : ordinal} {c : ordinal} (b1 : 1 < b) (x0 : 0 < x) :
log b x < c ↔ x < b ^ c :=
lt_iff_lt_of_le_iff_le (le_log b1 x0)
theorem log_le_log (b : ordinal) {x : ordinal} {y : ordinal} (xy : x ≤ y) : log b x ≤ log b y :=
sorry
theorem log_le_self (b : ordinal) (x : ordinal) : log b x ≤ x := sorry
/-! ### The Cantor normal form -/
theorem CNF_aux {b : ordinal} {o : ordinal} (b0 : b ≠ 0) (o0 : o ≠ 0) : o % b ^ log b o < o :=
lt_of_lt_of_le (mod_lt o (power_ne_zero (log b o) b0))
(power_log_le b (iff.mpr ordinal.pos_iff_ne_zero o0))
/-- Proving properties of ordinals by induction over their Cantor normal form. -/
def CNF_rec {b : ordinal} (b0 : b ≠ 0) {C : ordinal → Sort u_2} (H0 : C 0)
(H : (o : ordinal) → o ≠ 0 → o % b ^ log b o < o → C (o % b ^ log b o) → C o) (o : ordinal) :
C o :=
sorry
@[simp] theorem CNF_rec_zero {b : ordinal} (b0 : b ≠ 0) {C : ordinal → Sort u_2} {H0 : C 0}
{H : (o : ordinal) → o ≠ 0 → o % b ^ log b o < o → C (o % b ^ log b o) → C o} :
CNF_rec b0 H0 H 0 = H0 :=
sorry
@[simp] theorem CNF_rec_ne_zero {b : ordinal} (b0 : b ≠ 0) {C : ordinal → Sort u_2} {H0 : C 0}
{H : (o : ordinal) → o ≠ 0 → o % b ^ log b o < o → C (o % b ^ log b o) → C o} {o : ordinal}
(o0 : o ≠ 0) : CNF_rec b0 H0 H o = H o o0 (CNF_aux b0 o0) (CNF_rec b0 H0 H (o % b ^ log b o)) :=
sorry
/-- The Cantor normal form of an ordinal is the list of coefficients
in the base-`b` expansion of `o`.
CNF b (b ^ u₁ * v₁ + b ^ u₂ * v₂) = [(u₁, v₁), (u₂, v₂)] -/
def CNF (b : optParam ordinal omega) (o : ordinal) : List (ordinal × ordinal) :=
dite (b = 0) (fun (b0 : b = 0) => [])
fun (b0 : ¬b = 0) =>
CNF_rec b0 []
(fun (o : ordinal) (o0 : o ≠ 0) (h : o % b ^ log b o < o) (IH : List (ordinal × ordinal)) =>
(log b o, o / b ^ log b o) :: IH)
o
@[simp] theorem zero_CNF (o : ordinal) : CNF 0 o = [] := dif_pos rfl
@[simp] theorem CNF_zero (b : optParam ordinal omega) : CNF b 0 = [] :=
dite (b = 0) (fun (b0 : b = 0) => dif_pos b0)
fun (b0 : ¬b = 0) => Eq.trans (dif_neg b0) (CNF_rec_zero b0)
theorem CNF_ne_zero {b : ordinal} {o : ordinal} (b0 : b ≠ 0) (o0 : o ≠ 0) :
CNF b o = (log b o, o / b ^ log b o) :: CNF b (o % b ^ log b o) :=
sorry
theorem one_CNF {o : ordinal} (o0 : o ≠ 0) : CNF 1 o = [(0, o)] := sorry
theorem CNF_foldr {b : ordinal} (b0 : b ≠ 0) (o : ordinal) :
list.foldr (fun (p : ordinal × ordinal) (r : ordinal) => b ^ prod.fst p * prod.snd p + r) 0
(CNF b o) =
o :=
sorry
theorem CNF_pairwise_aux (b : optParam ordinal omega) (o : ordinal) :
(∀ (p : ordinal × ordinal), p ∈ CNF b o → prod.fst p ≤ log b o) ∧
list.pairwise (fun (p q : ordinal × ordinal) => prod.fst q < prod.fst p) (CNF b o) :=
sorry
theorem CNF_pairwise (b : optParam ordinal omega) (o : ordinal) :
list.pairwise (fun (p q : ordinal × ordinal) => prod.fst q < prod.fst p) (CNF b o) :=
and.right (CNF_pairwise_aux b o)
theorem CNF_fst_le_log (b : optParam ordinal omega) (o : ordinal) (p : ordinal × ordinal)
(H : p ∈ CNF b o) : prod.fst p ≤ log b o :=
and.left (CNF_pairwise_aux b o)
theorem CNF_fst_le (b : optParam ordinal omega) (o : ordinal) (p : ordinal × ordinal)
(H : p ∈ CNF b o) : prod.fst p ≤ o :=
le_trans (CNF_fst_le_log b o p H) (log_le_self b o)
theorem CNF_snd_lt {b : ordinal} (b1 : 1 < b) (o : ordinal) (p : ordinal × ordinal)
(H : p ∈ CNF b o) : prod.snd p < b :=
sorry
theorem CNF_sorted (b : optParam ordinal omega) (o : ordinal) :
list.sorted gt (list.map prod.fst (CNF b o)) :=
sorry
/-! ### Casting naturals into ordinals, compatibility with operations -/
@[simp] theorem nat_cast_mul {m : ℕ} {n : ℕ} : ↑(m * n) = ↑m * ↑n := sorry
@[simp] theorem nat_cast_power {m : ℕ} {n : ℕ} : ↑(m ^ n) = ↑m ^ ↑n := sorry
@[simp] theorem nat_cast_le {m : ℕ} {n : ℕ} : ↑m ≤ ↑n ↔ m ≤ n := sorry
@[simp] theorem nat_cast_lt {m : ℕ} {n : ℕ} : ↑m < ↑n ↔ m < n := sorry
@[simp] theorem nat_cast_inj {m : ℕ} {n : ℕ} : ↑m = ↑n ↔ m = n := sorry
@[simp] theorem nat_cast_eq_zero {n : ℕ} : ↑n = 0 ↔ n = 0 := nat_cast_inj
theorem nat_cast_ne_zero {n : ℕ} : ↑n ≠ 0 ↔ n ≠ 0 := not_congr nat_cast_eq_zero
@[simp] theorem nat_cast_pos {n : ℕ} : 0 < ↑n ↔ 0 < n := nat_cast_lt
@[simp] theorem nat_cast_sub {m : ℕ} {n : ℕ} : ↑(m - n) = ↑m - ↑n := sorry
@[simp] theorem nat_cast_div {m : ℕ} {n : ℕ} : ↑(m / n) = ↑m / ↑n := sorry
@[simp] theorem nat_cast_mod {m : ℕ} {n : ℕ} : ↑(m % n) = ↑m % ↑n := sorry
@[simp] theorem nat_le_card {o : ordinal} {n : ℕ} : ↑n ≤ card o ↔ ↑n ≤ o := sorry
@[simp] theorem nat_lt_card {o : ordinal} {n : ℕ} : ↑n < card o ↔ ↑n < o := sorry
@[simp] theorem card_lt_nat {o : ordinal} {n : ℕ} : card o < ↑n ↔ o < ↑n :=
lt_iff_lt_of_le_iff_le nat_le_card
@[simp] theorem card_le_nat {o : ordinal} {n : ℕ} : card o ≤ ↑n ↔ o ≤ ↑n :=
iff.mpr le_iff_le_iff_lt_iff_lt nat_lt_card
@[simp] theorem card_eq_nat {o : ordinal} {n : ℕ} : card o = ↑n ↔ o = ↑n := sorry
@[simp] theorem type_fin (n : ℕ) : type Less = ↑n :=
eq.mpr (id (Eq._oldrec (Eq.refl (type Less = ↑n)) (Eq.symm (propext card_eq_nat))))
(eq.mpr (id (Eq._oldrec (Eq.refl (card (type Less) = ↑n)) (card_type Less)))
(eq.mpr (id (Eq._oldrec (Eq.refl (cardinal.mk (fin n) = ↑n)) (cardinal.mk_fin n)))
(Eq.refl ↑n)))
@[simp] theorem lift_nat_cast (n : ℕ) : lift ↑n = ↑n := sorry
theorem lift_type_fin (n : ℕ) : lift (type Less) = ↑n := sorry
theorem fintype_card {α : Type u_1} (r : α → α → Prop) [is_well_order α r] [fintype α] :
type r = ↑(fintype.card α) :=
sorry
end ordinal
/-! ### Properties of `omega` -/
namespace cardinal
@[simp] theorem ord_omega : ord omega = ordinal.omega := sorry
@[simp] theorem add_one_of_omega_le {c : cardinal} (h : omega ≤ c) : c + 1 = c := sorry
end cardinal
namespace ordinal
theorem lt_omega {o : ordinal} : o < omega ↔ ∃ (n : ℕ), o = ↑n := sorry
theorem nat_lt_omega (n : ℕ) : ↑n < omega := iff.mpr lt_omega (Exists.intro n rfl)
theorem omega_pos : 0 < omega := nat_lt_omega 0
theorem omega_ne_zero : omega ≠ 0 := ne_of_gt omega_pos
theorem one_lt_omega : 1 < omega := sorry
theorem omega_is_limit : is_limit omega := sorry
theorem omega_le {o : ordinal} : omega ≤ o ↔ ∀ (n : ℕ), ↑n ≤ o := sorry
theorem nat_lt_limit {o : ordinal} (h : is_limit o) (n : ℕ) : ↑n < o := sorry
theorem omega_le_of_is_limit {o : ordinal} (h : is_limit o) : omega ≤ o :=
iff.mpr omega_le fun (n : ℕ) => le_of_lt (nat_lt_limit h n)
theorem add_omega {a : ordinal} (h : a < omega) : a + omega = omega := sorry
theorem add_lt_omega {a : ordinal} {b : ordinal} (ha : a < omega) (hb : b < omega) :
a + b < omega :=
sorry
theorem mul_lt_omega {a : ordinal} {b : ordinal} (ha : a < omega) (hb : b < omega) :
a * b < omega :=
sorry
theorem is_limit_iff_omega_dvd {a : ordinal} : is_limit a ↔ a ≠ 0 ∧ omega ∣ a := sorry
theorem power_lt_omega {a : ordinal} {b : ordinal} (ha : a < omega) (hb : b < omega) :
a ^ b < omega :=
sorry
theorem add_omega_power {a : ordinal} {b : ordinal} (h : a < omega ^ b) :
a + omega ^ b = omega ^ b :=
sorry
theorem add_lt_omega_power {a : ordinal} {b : ordinal} {c : ordinal} (h₁ : a < omega ^ c)
(h₂ : b < omega ^ c) : a + b < omega ^ c :=
eq.mpr (id (Eq._oldrec (Eq.refl (a + b < omega ^ c)) (Eq.symm (add_omega_power h₁))))
(eq.mpr (id (Eq._oldrec (Eq.refl (a + b < a + omega ^ c)) (propext (add_lt_add_iff_left a))))
h₂)
theorem add_absorp {a : ordinal} {b : ordinal} {c : ordinal} (h₁ : a < omega ^ b)
(h₂ : omega ^ b ≤ c) : a + c = c :=
sorry
theorem add_absorp_iff {o : ordinal} (o0 : 0 < o) :
(∀ (a : ordinal), a < o → a + o = o) ↔ ∃ (a : ordinal), o = omega ^ a :=
sorry
theorem add_mul_limit_aux {a : ordinal} {b : ordinal} {c : ordinal} (ba : b + a = a)
(l : is_limit c) (IH : ∀ (c' : ordinal), c' < c → (a + b) * succ c' = a * succ c' + b) :
(a + b) * c = a * c :=
sorry
theorem add_mul_succ {a : ordinal} {b : ordinal} (c : ordinal) (ba : b + a = a) :
(a + b) * succ c = a * succ c + b :=
sorry
theorem add_mul_limit {a : ordinal} {b : ordinal} {c : ordinal} (ba : b + a = a) (l : is_limit c) :
(a + b) * c = a * c :=
add_mul_limit_aux ba l fun (c' : ordinal) (_x : c' < c) => add_mul_succ c' ba
theorem mul_omega {a : ordinal} (a0 : 0 < a) (ha : a < omega) : a * omega = omega := sorry
theorem mul_lt_omega_power {a : ordinal} {b : ordinal} {c : ordinal} (c0 : 0 < c)
(ha : a < omega ^ c) (hb : b < omega) : a * b < omega ^ c :=
sorry
theorem mul_omega_dvd {a : ordinal} (a0 : 0 < a) (ha : a < omega) {b : ordinal} :
omega ∣ b → a * b = b :=
sorry
theorem mul_omega_power_power {a : ordinal} {b : ordinal} (a0 : 0 < a) (h : a < omega ^ omega ^ b) :
a * omega ^ omega ^ b = omega ^ omega ^ b :=
sorry
theorem power_omega {a : ordinal} (a1 : 1 < a) (h : a < omega) : a ^ omega = omega := sorry
/-! ### Fixed points of normal functions -/
/-- The next fixed point function, the least fixed point of the
normal function `f` above `a`. -/
def nfp (f : ordinal → ordinal) (a : ordinal) : ordinal := sup fun (n : ℕ) => nat.iterate f n a
theorem iterate_le_nfp (f : ordinal → ordinal) (a : ordinal) (n : ℕ) :
nat.iterate f n a ≤ nfp f a :=
le_sup (fun (n : ℕ) => nat.iterate f n a) n
theorem le_nfp_self (f : ordinal → ordinal) (a : ordinal) : a ≤ nfp f a := iterate_le_nfp f a 0
theorem is_normal.lt_nfp {f : ordinal → ordinal} (H : is_normal f) {a : ordinal} {b : ordinal} :
f b < nfp f a ↔ b < nfp f a :=
sorry
theorem is_normal.nfp_le {f : ordinal → ordinal} (H : is_normal f) {a : ordinal} {b : ordinal} :
nfp f a ≤ f b ↔ nfp f a ≤ b :=
iff.mpr le_iff_le_iff_lt_iff_lt (is_normal.lt_nfp H)
theorem is_normal.nfp_le_fp {f : ordinal → ordinal} (H : is_normal f) {a : ordinal} {b : ordinal}
(ab : a ≤ b) (h : f b ≤ b) : nfp f a ≤ b :=
sorry
theorem is_normal.nfp_fp {f : ordinal → ordinal} (H : is_normal f) (a : ordinal) :
f (nfp f a) = nfp f a :=
sorry
theorem is_normal.le_nfp {f : ordinal → ordinal} (H : is_normal f) {a : ordinal} {b : ordinal} :
f b ≤ nfp f a ↔ b ≤ nfp f a :=
sorry
theorem nfp_eq_self {f : ordinal → ordinal} {a : ordinal} (h : f a = a) : nfp f a = a := sorry
/-- The derivative of a normal function `f` is
the sequence of fixed points of `f`. -/
def deriv (f : ordinal → ordinal) (o : ordinal) : ordinal :=
limit_rec_on o (nfp f 0) (fun (a IH : ordinal) => nfp f (succ IH))
fun (a : ordinal) (l : is_limit a) => bsup a
@[simp] theorem deriv_zero (f : ordinal → ordinal) : deriv f 0 = nfp f 0 :=
limit_rec_on_zero (nfp f 0) (fun (a IH : ordinal) => nfp f (succ IH))
fun (a : ordinal) (l : is_limit a) => bsup a
@[simp] theorem deriv_succ (f : ordinal → ordinal) (o : ordinal) :
deriv f (succ o) = nfp f (succ (deriv f o)) :=
limit_rec_on_succ o (nfp f 0) (fun (a IH : ordinal) => nfp f (succ IH))
fun (a : ordinal) (l : is_limit a) => bsup a
theorem deriv_limit (f : ordinal → ordinal) {o : ordinal} :
is_limit o → deriv f o = bsup o fun (a : ordinal) (_x : a < o) => deriv f a :=
limit_rec_on_limit o (nfp f 0) (fun (a IH : ordinal) => nfp f (succ IH))
fun (a : ordinal) (l : is_limit a) => bsup a
theorem deriv_is_normal (f : ordinal → ordinal) : is_normal (deriv f) := sorry
theorem is_normal.deriv_fp {f : ordinal → ordinal} (H : is_normal f) (o : ordinal) :
f (deriv f o) = deriv f o :=
sorry
theorem is_normal.fp_iff_deriv {f : ordinal → ordinal} (H : is_normal f) {a : ordinal} :
f a ≤ a ↔ ∃ (o : ordinal), a = deriv f o :=
sorry
end Mathlib |
cad6d2b6f92d0bed2bb5fd404858ea711624d8c1 | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/algebraic_geometry/Gamma_Spec_adjunction.lean | 566db61904700bbad149cdc8d2f23e689c49db46 | [
"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 | 16,251 | lean | /-
Copyright (c) 2021 Junyan Xu. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Junyan Xu
-/
import algebraic_geometry.Scheme
import category_theory.adjunction.limits
import category_theory.adjunction.reflective
/-!
# Adjunction between `Γ` and `Spec`
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
We define the adjunction `Γ_Spec.adjunction : Γ ⊣ Spec` by defining the unit (`to_Γ_Spec`,
in multiple steps in this file) and counit (done in Spec.lean) and checking that they satisfy
the left and right triangle identities. The constructions and proofs make use of
maps and lemmas defined and proved in structure_sheaf.lean extensively.
Notice that since the adjunction is between contravariant functors, you get to choose
one of the two categories to have arrows reversed, and it is equally valid to present
the adjunction as `Spec ⊣ Γ` (`Spec.to_LocallyRingedSpace.right_op ⊣ Γ`), in which
case the unit and the counit would switch to each other.
## Main definition
* `algebraic_geometry.identity_to_Γ_Spec` : The natural transformation `𝟭 _ ⟶ Γ ⋙ Spec`.
* `algebraic_geometry.Γ_Spec.LocallyRingedSpace_adjunction` : The adjunction `Γ ⊣ Spec` from
`CommRingᵒᵖ` to `LocallyRingedSpace`.
* `algebraic_geometry.Γ_Spec.adjunction` : The adjunction `Γ ⊣ Spec` from
`CommRingᵒᵖ` to `Scheme`.
-/
noncomputable theory
universes u
open prime_spectrum
namespace algebraic_geometry
open opposite
open category_theory
open structure_sheaf Spec (structure_sheaf)
open topological_space
open algebraic_geometry.LocallyRingedSpace
open Top.presheaf
open Top.presheaf.sheaf_condition
namespace LocallyRingedSpace
variable (X : LocallyRingedSpace.{u})
/-- The map from the global sections to a stalk. -/
def Γ_to_stalk (x : X) : Γ.obj (op X) ⟶ X.presheaf.stalk x :=
X.presheaf.germ (⟨x,trivial⟩ : (⊤ : opens X))
/-- The canonical map from the underlying set to the prime spectrum of `Γ(X)`. -/
def to_Γ_Spec_fun : X → prime_spectrum (Γ.obj (op X)) :=
λ x, comap (X.Γ_to_stalk x) (local_ring.closed_point (X.presheaf.stalk x))
lemma not_mem_prime_iff_unit_in_stalk (r : Γ.obj (op X)) (x : X) :
r ∉ (X.to_Γ_Spec_fun x).as_ideal ↔ is_unit (X.Γ_to_stalk x r) :=
by erw [local_ring.mem_maximal_ideal, not_not]
/-- The preimage of a basic open in `Spec Γ(X)` under the unit is the basic
open in `X` defined by the same element (they are equal as sets). -/
lemma to_Γ_Spec_preim_basic_open_eq (r : Γ.obj (op X)) :
X.to_Γ_Spec_fun⁻¹' (basic_open r).1 = (X.to_RingedSpace.basic_open r).1 :=
by { ext, erw X.to_RingedSpace.mem_top_basic_open, apply not_mem_prime_iff_unit_in_stalk }
/-- `to_Γ_Spec_fun` is continuous. -/
lemma to_Γ_Spec_continuous : continuous X.to_Γ_Spec_fun :=
begin
apply is_topological_basis_basic_opens.continuous,
rintro _ ⟨r, rfl⟩,
erw X.to_Γ_Spec_preim_basic_open_eq r,
exact (X.to_RingedSpace.basic_open r).2,
end
/-- The canonical (bundled) continuous map from the underlying topological
space of `X` to the prime spectrum of its global sections. -/
@[simps]
def to_Γ_Spec_base : X.to_Top ⟶ Spec.Top_obj (Γ.obj (op X)) :=
{ to_fun := X.to_Γ_Spec_fun,
continuous_to_fun := X.to_Γ_Spec_continuous }
variable (r : Γ.obj (op X))
/-- The preimage in `X` of a basic open in `Spec Γ(X)` (as an open set). -/
abbreviation to_Γ_Spec_map_basic_open : opens X :=
(opens.map X.to_Γ_Spec_base).obj (basic_open r)
/-- The preimage is the basic open in `X` defined by the same element `r`. -/
lemma to_Γ_Spec_map_basic_open_eq : X.to_Γ_Spec_map_basic_open r = X.to_RingedSpace.basic_open r :=
opens.ext (X.to_Γ_Spec_preim_basic_open_eq r)
/-- The map from the global sections `Γ(X)` to the sections on the (preimage of) a basic open. -/
abbreviation to_to_Γ_Spec_map_basic_open :
X.presheaf.obj (op ⊤) ⟶ X.presheaf.obj (op $ X.to_Γ_Spec_map_basic_open r) :=
X.presheaf.map (X.to_Γ_Spec_map_basic_open r).le_top.op
/-- `r` is a unit as a section on the basic open defined by `r`. -/
lemma is_unit_res_to_Γ_Spec_map_basic_open :
is_unit (X.to_to_Γ_Spec_map_basic_open r r) :=
begin
convert (X.presheaf.map $ (eq_to_hom $ X.to_Γ_Spec_map_basic_open_eq r).op)
.is_unit_map (X.to_RingedSpace.is_unit_res_basic_open r),
rw ← comp_apply,
erw ← functor.map_comp,
congr
end
/-- Define the sheaf hom on individual basic opens for the unit. -/
def to_Γ_Spec_c_app :
(structure_sheaf $ Γ.obj $ op X).val.obj (op $ basic_open r) ⟶
X.presheaf.obj (op $ X.to_Γ_Spec_map_basic_open r) :=
is_localization.away.lift r (is_unit_res_to_Γ_Spec_map_basic_open _ r)
/-- Characterization of the sheaf hom on basic opens,
direction ← (next lemma) is used at various places, but → is not used in this file. -/
lemma to_Γ_Spec_c_app_iff
(f : (structure_sheaf $ Γ.obj $ op X).val.obj (op $ basic_open r) ⟶
X.presheaf.obj (op $ X.to_Γ_Spec_map_basic_open r)) :
to_open _ (basic_open r) ≫ f = X.to_to_Γ_Spec_map_basic_open r ↔ f = X.to_Γ_Spec_c_app r :=
begin
rw ← (is_localization.away.away_map.lift_comp r
(X.is_unit_res_to_Γ_Spec_map_basic_open r)),
swap 5, exact is_localization.to_basic_open _ r,
split,
{ intro h, refine is_localization.ring_hom_ext _ _,
swap 5, exact is_localization.to_basic_open _ r, exact h },
apply congr_arg,
end
lemma to_Γ_Spec_c_app_spec :
to_open _ (basic_open r) ≫ X.to_Γ_Spec_c_app r = X.to_to_Γ_Spec_map_basic_open r :=
(X.to_Γ_Spec_c_app_iff r _).2 rfl
/-- The sheaf hom on all basic opens, commuting with restrictions. -/
def to_Γ_Spec_c_basic_opens :
(induced_functor basic_open).op ⋙ (structure_sheaf (Γ.obj (op X))).1 ⟶
(induced_functor basic_open).op ⋙ ((Top.sheaf.pushforward X.to_Γ_Spec_base).obj X.𝒪).1 :=
{ app := λ r, X.to_Γ_Spec_c_app r.unop,
naturality' := λ r s f, begin
apply (structure_sheaf.to_basic_open_epi (Γ.obj (op X)) r.unop).1,
simp only [← category.assoc],
erw X.to_Γ_Spec_c_app_spec r.unop,
convert X.to_Γ_Spec_c_app_spec s.unop,
symmetry,
apply X.presheaf.map_comp
end }
/-- The canonical morphism of sheafed spaces from `X` to the spectrum of its global sections. -/
@[simps]
def to_Γ_Spec_SheafedSpace : X.to_SheafedSpace ⟶ Spec.to_SheafedSpace.obj (op (Γ.obj (op X))) :=
{ base := X.to_Γ_Spec_base,
c := Top.sheaf.restrict_hom_equiv_hom (structure_sheaf (Γ.obj (op X))).1 _
is_basis_basic_opens X.to_Γ_Spec_c_basic_opens }
lemma to_Γ_Spec_SheafedSpace_app_eq :
X.to_Γ_Spec_SheafedSpace.c.app (op (basic_open r)) = X.to_Γ_Spec_c_app r :=
Top.sheaf.extend_hom_app _ _ _ _ _
lemma to_Γ_Spec_SheafedSpace_app_spec (r : Γ.obj (op X)) :
to_open _ (basic_open r) ≫ X.to_Γ_Spec_SheafedSpace.c.app (op (basic_open r)) =
X.to_to_Γ_Spec_map_basic_open r :=
(X.to_Γ_Spec_SheafedSpace_app_eq r).symm ▸ X.to_Γ_Spec_c_app_spec r
/-- The map on stalks induced by the unit commutes with maps from `Γ(X)` to
stalks (in `Spec Γ(X)` and in `X`). -/
lemma to_stalk_stalk_map_to_Γ_Spec (x : X) : to_stalk _ _ ≫
PresheafedSpace.stalk_map X.to_Γ_Spec_SheafedSpace x = X.Γ_to_stalk x :=
begin
rw PresheafedSpace.stalk_map,
erw ← to_open_germ _ (basic_open (1 : Γ.obj (op X)))
⟨X.to_Γ_Spec_fun x, by rw basic_open_one; trivial⟩,
rw [← category.assoc, category.assoc (to_open _ _)],
erw stalk_functor_map_germ,
rw [← category.assoc (to_open _ _), X.to_Γ_Spec_SheafedSpace_app_spec 1],
unfold Γ_to_stalk,
rw ← stalk_pushforward_germ _ X.to_Γ_Spec_base X.presheaf ⊤,
congr' 1,
change (X.to_Γ_Spec_base _* X.presheaf).map le_top.hom.op ≫ _ = _,
apply germ_res,
end
/-- The canonical morphism from `X` to the spectrum of its global sections. -/
@[simps val_base]
def to_Γ_Spec : X ⟶ Spec.LocallyRingedSpace_obj (Γ.obj (op X)) :=
{ val := X.to_Γ_Spec_SheafedSpace,
prop :=
begin
intro x,
let p : prime_spectrum (Γ.obj (op X)) := X.to_Γ_Spec_fun x,
constructor, /- show stalk map is local hom ↓ -/
let S := (structure_sheaf _).presheaf.stalk p,
rintros (t : S) ht,
obtain ⟨⟨r, s⟩, he⟩ := is_localization.surj p.as_ideal.prime_compl t,
dsimp at he,
apply is_unit_of_mul_is_unit_left,
rw he,
refine is_localization.map_units S (⟨r, _⟩ : p.as_ideal.prime_compl),
apply (not_mem_prime_iff_unit_in_stalk _ _ _).mpr,
rw [← to_stalk_stalk_map_to_Γ_Spec, comp_apply],
erw ← he,
rw ring_hom.map_mul,
exact ht.mul ((is_localization.map_units S s : _).map
(PresheafedSpace.stalk_map X.to_Γ_Spec_SheafedSpace x))
end }
lemma comp_ring_hom_ext {X : LocallyRingedSpace} {R : CommRing}
{f : R ⟶ Γ.obj (op X)} {β : X ⟶ Spec.LocallyRingedSpace_obj R}
(w : X.to_Γ_Spec.1.base ≫ (Spec.LocallyRingedSpace_map f).1.base = β.1.base)
(h : ∀ r : R,
f ≫ X.presheaf.map (hom_of_le le_top : (opens.map β.1.base).obj (basic_open r) ⟶ _).op =
to_open R (basic_open r) ≫ β.1.c.app (op (basic_open r))) :
X.to_Γ_Spec ≫ Spec.LocallyRingedSpace_map f = β :=
begin
ext1,
apply Spec.basic_open_hom_ext,
{ intros r _,
rw LocallyRingedSpace.comp_val_c_app,
erw to_open_comp_comap_assoc,
rw category.assoc,
erw [to_Γ_Spec_SheafedSpace_app_spec, ← X.presheaf.map_comp],
convert h r },
exact w,
end
/-- `to_Spec_Γ _` is an isomorphism so these are mutually two-sided inverses. -/
lemma Γ_Spec_left_triangle : to_Spec_Γ (Γ.obj (op X)) ≫ X.to_Γ_Spec.1.c.app (op ⊤) = 𝟙 _ :=
begin
unfold to_Spec_Γ,
rw ← to_open_res _ (basic_open (1 : Γ.obj (op X))) ⊤ (eq_to_hom basic_open_one.symm),
erw category.assoc,
rw [nat_trans.naturality, ← category.assoc],
erw [X.to_Γ_Spec_SheafedSpace_app_spec 1, ← functor.map_comp],
convert eq_to_hom_map X.presheaf _, refl,
end
end LocallyRingedSpace
/-- The unit as a natural transformation. -/
def identity_to_Γ_Spec : 𝟭 LocallyRingedSpace.{u} ⟶ Γ.right_op ⋙ Spec.to_LocallyRingedSpace :=
{ app := LocallyRingedSpace.to_Γ_Spec,
naturality' := λ X Y f, begin
symmetry,
apply LocallyRingedSpace.comp_ring_hom_ext,
{ ext1 x,
dsimp [Spec.Top_map, LocallyRingedSpace.to_Γ_Spec_fun],
rw [← local_ring.comap_closed_point (PresheafedSpace.stalk_map _ x),
← prime_spectrum.comap_comp_apply, ← prime_spectrum.comap_comp_apply],
congr' 2,
exact (PresheafedSpace.stalk_map_germ f.1 ⊤ ⟨x,trivial⟩).symm,
apply_instance },
{ intro r,
rw [LocallyRingedSpace.comp_val_c_app, ← category.assoc],
erw [Y.to_Γ_Spec_SheafedSpace_app_spec, f.1.c.naturality],
refl },
end }
namespace Γ_Spec
lemma left_triangle (X : LocallyRingedSpace) :
Spec_Γ_identity.inv.app (Γ.obj (op X)) ≫ (identity_to_Γ_Spec.app X).val.c.app (op ⊤) = 𝟙 _ :=
X.Γ_Spec_left_triangle
/-- `Spec_Γ_identity` is iso so these are mutually two-sided inverses. -/
lemma right_triangle (R : CommRing) :
identity_to_Γ_Spec.app (Spec.to_LocallyRingedSpace.obj $ op R) ≫
Spec.to_LocallyRingedSpace.map (Spec_Γ_identity.inv.app R).op = 𝟙 _ :=
begin
apply LocallyRingedSpace.comp_ring_hom_ext,
{ ext (p : prime_spectrum R) x,
erw ← is_localization.at_prime.to_map_mem_maximal_iff
((structure_sheaf R).presheaf.stalk p) p.as_ideal x,
refl },
{ intro r, apply to_open_res },
end
-- Removing this makes the following definition time out.
local attribute [irreducible] Spec_Γ_identity identity_to_Γ_Spec Spec.to_LocallyRingedSpace
/-- The adjunction `Γ ⊣ Spec` from `CommRingᵒᵖ` to `LocallyRingedSpace`. -/
@[simps unit counit] def LocallyRingedSpace_adjunction : Γ.right_op ⊣ Spec.to_LocallyRingedSpace :=
adjunction.mk_of_unit_counit
{ unit := identity_to_Γ_Spec,
counit := (nat_iso.op Spec_Γ_identity).inv,
left_triangle' := by { ext X, erw category.id_comp,
exact congr_arg quiver.hom.op (left_triangle X) },
right_triangle' := by { ext1, ext1 R, erw category.id_comp,
exact right_triangle R.unop } }
local attribute [semireducible] Spec.to_LocallyRingedSpace
/-- The adjunction `Γ ⊣ Spec` from `CommRingᵒᵖ` to `Scheme`. -/
def adjunction : Scheme.Γ.right_op ⊣ Scheme.Spec :=
LocallyRingedSpace_adjunction.restrict_fully_faithful
Scheme.forget_to_LocallyRingedSpace (𝟭 _)
(nat_iso.of_components (λ X, iso.refl _) (λ _ _ f, by simpa))
(nat_iso.of_components (λ X, iso.refl _) (λ _ _ f, by simpa))
lemma adjunction_hom_equiv_apply {X : Scheme} {R : CommRingᵒᵖ}
(f : (op $ Scheme.Γ.obj $ op X) ⟶ R) :
Γ_Spec.adjunction.hom_equiv X R f =
LocallyRingedSpace_adjunction.hom_equiv X.1 R f :=
by { dsimp [adjunction, adjunction.restrict_fully_faithful], simp }
local attribute [irreducible] LocallyRingedSpace_adjunction Γ_Spec.adjunction
lemma adjunction_hom_equiv (X : Scheme) (R : CommRingᵒᵖ) :
Γ_Spec.adjunction.hom_equiv X R = LocallyRingedSpace_adjunction.hom_equiv X.1 R :=
equiv.ext $ λ f, adjunction_hom_equiv_apply f
lemma adjunction_hom_equiv_symm_apply {X : Scheme} {R : CommRingᵒᵖ}
(f : X ⟶ Scheme.Spec.obj R) :
(Γ_Spec.adjunction.hom_equiv X R).symm f =
(LocallyRingedSpace_adjunction.hom_equiv X.1 R).symm f :=
by { congr' 2, exact adjunction_hom_equiv _ _ }
@[simp] lemma adjunction_counit_app {R : CommRingᵒᵖ} :
Γ_Spec.adjunction.counit.app R = LocallyRingedSpace_adjunction.counit.app R :=
by { rw [← adjunction.hom_equiv_symm_id, ← adjunction.hom_equiv_symm_id,
adjunction_hom_equiv_symm_apply], refl }
@[simp] lemma adjunction_unit_app {X : Scheme} :
Γ_Spec.adjunction.unit.app X = LocallyRingedSpace_adjunction.unit.app X.1 :=
by { rw [← adjunction.hom_equiv_id, ← adjunction.hom_equiv_id, adjunction_hom_equiv_apply], refl }
local attribute [semireducible] LocallyRingedSpace_adjunction Γ_Spec.adjunction
instance is_iso_LocallyRingedSpace_adjunction_counit :
is_iso LocallyRingedSpace_adjunction.counit :=
is_iso.of_iso_inv _
instance is_iso_adjunction_counit : is_iso Γ_Spec.adjunction.counit :=
begin
apply_with nat_iso.is_iso_of_is_iso_app { instances := ff },
intro R,
rw adjunction_counit_app,
apply_instance,
end
-- This is just
-- `(Γ_Spec.adjunction.unit.app X).1.c.app (op ⊤) = Spec_Γ_identity.hom.app (X.presheaf.obj (op ⊤))`
-- But lean times out when trying to unify the types of the two sides.
lemma adjunction_unit_app_app_top (X : Scheme) :
@eq ((Scheme.Spec.obj (op $ X.presheaf.obj (op ⊤))).presheaf.obj (op ⊤) ⟶
((Γ_Spec.adjunction.unit.app X).1.base _* X.presheaf).obj (op ⊤))
((Γ_Spec.adjunction.unit.app X).val.c.app (op ⊤))
(Spec_Γ_identity.hom.app (X.presheaf.obj (op ⊤))) :=
begin
have := congr_app Γ_Spec.adjunction.left_triangle X,
dsimp at this,
rw ← is_iso.eq_comp_inv at this,
simp only [Γ_Spec.LocallyRingedSpace_adjunction_counit, nat_trans.op_app, category.id_comp,
Γ_Spec.adjunction_counit_app] at this,
rw [← op_inv, nat_iso.inv_inv_app, quiver.hom.op_inj.eq_iff] at this,
exact this
end
end Γ_Spec
/-! Immediate consequences of the adjunction. -/
/-- Spec preserves limits. -/
instance : limits.preserves_limits Spec.to_LocallyRingedSpace :=
Γ_Spec.LocallyRingedSpace_adjunction.right_adjoint_preserves_limits
instance Spec.preserves_limits : limits.preserves_limits Scheme.Spec :=
Γ_Spec.adjunction.right_adjoint_preserves_limits
/-- Spec is a full functor. -/
instance : full Spec.to_LocallyRingedSpace :=
R_full_of_counit_is_iso Γ_Spec.LocallyRingedSpace_adjunction
instance Spec.full : full Scheme.Spec :=
R_full_of_counit_is_iso Γ_Spec.adjunction
/-- Spec is a faithful functor. -/
instance : faithful Spec.to_LocallyRingedSpace :=
R_faithful_of_counit_is_iso Γ_Spec.LocallyRingedSpace_adjunction
instance Spec.faithful : faithful Scheme.Spec :=
R_faithful_of_counit_is_iso Γ_Spec.adjunction
instance : is_right_adjoint Spec.to_LocallyRingedSpace := ⟨_, Γ_Spec.LocallyRingedSpace_adjunction⟩
instance : is_right_adjoint Scheme.Spec := ⟨_, Γ_Spec.adjunction⟩
instance : reflective Spec.to_LocallyRingedSpace := ⟨⟩
instance Spec.reflective : reflective Scheme.Spec := ⟨⟩
end algebraic_geometry
|
36199a971db559c91856888a8a0b8ed68c777dc5 | b7f22e51856f4989b970961f794f1c435f9b8f78 | /library/algebra/interval.lean | 57dfd054ab5d3dc5c6524b59507ea2ca0d7de355 | [
"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,538 | lean | /-
Copyright (c) 2015 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Jeremy Avigad
Notation for intervals and some properties.
The mnemonic: o = open, c = closed, i = infinity. For example, Ioi a b is '(a, ∞).
-/
import .order data.set
open set
namespace interval
section order_pair
variables {A : Type} [order_pair A]
definition Ioo (a b : A) : set A := {x | a < x ∧ x < b}
definition Ioc (a b : A) : set A := {x | a < x ∧ x ≤ b}
definition Ico (a b : A) : set A := {x | a ≤ x ∧ x < b}
definition Icc (a b : A) : set A := {x | a ≤ x ∧ x ≤ b}
definition Ioi (a : A) : set A := {x | a < x}
definition Ici (a : A) : set A := {x | a ≤ x}
definition Iio (b : A) : set A := {x | x < b}
definition Iic (b : A) : set A := {x | x ≤ b}
notation `'(` a `, ` b `)` := Ioo a b
notation `'(` a `, ` b `]` := Ioc a b
notation `'[` a `, ` b `)` := Ico a b
notation `'[` a `, ` b `]` := Icc a b
notation `'(` a `, ` `∞` `)` := Ioi a
notation `'[` a `, ` `∞` `)` := Ici a
notation `'(` `-∞` `, ` b `)` := Iio b
notation `'(` `-∞` `, ` b `]` := Iic b
variables a b : A
proposition Ioi_inter_Iio : '(a, ∞) ∩ '(-∞, b) = '(a, b) := rfl
proposition Ici_inter_Iio : '[a, ∞) ∩ '(-∞, b) = '[a, b) := rfl
proposition Ioi_inter_Iic : '(a, ∞) ∩ '(-∞, b] = '(a, b] := rfl
proposition Ioc_inter_Iic : '[a, ∞) ∩ '(-∞, b] = '[a, b] := rfl
proposition Icc_self : '[a, a] = '{a} :=
set.ext (take x, iff.intro
(suppose x ∈ '[a, a],
have x = a, from le.antisymm (and.right this) (and.left this),
show x ∈ '{a}, from mem_singleton_of_eq this)
(suppose x ∈ '{a},
have x = a, from eq_of_mem_singleton this,
show a ≤ x ∧ x ≤ a, from and.intro (eq.subst this !le.refl) (eq.subst this !le.refl)))
proposition Icc_eq_empty {a b : A} (H : b < a) : '[a, b] = ∅ :=
eq_empty_of_forall_not_mem
(take x, suppose x ∈ '[a, b],
have a ≤ b, from le.trans (and.left this) (and.right this),
not_le_of_gt H this)
end order_pair
section strong_order_pair
variables {A : Type} [linear_strong_order_pair A]
proposition compl_Ici (a : A) : -'[a, ∞) = '(-∞, a) :=
ext (take x, iff.intro
(assume H, lt_of_not_ge H)
(assume H, not_le_of_gt H))
proposition compl_Iic (a : A) : -'(-∞, a] = '(a, ∞) :=
ext (take x, iff.intro
(assume H, lt_of_not_ge H)
(assume H, not_le_of_gt H))
proposition compl_Ioi (a : A) : -'(a, ∞) = '(-∞, a] :=
ext (take x, iff.intro
(assume H, le_of_not_gt H)
(assume H, not_lt_of_ge H))
proposition compl_Iio (a : A) : -'(-∞, a) = '[a, ∞) :=
ext (take x, iff.intro
(assume H, le_of_not_gt H)
(assume H, not_lt_of_ge H))
proposition Icc_eq_Icc_union_Ioc {a b c : A} (H1 : a ≤ b) (H2 : b ≤ c) :
'[a, c] = '[a, b] ∪ '(b, c] :=
set.ext (take x, iff.intro
(assume H3 : x ∈ '[a, c],
or.elim (le_or_gt x b)
(suppose x ≤ b,
or.inl (and.intro (and.left H3) this))
(suppose x > b,
or.inr (and.intro this (and.right H3))))
(suppose x ∈ '[a, b] ∪ '(b, c],
or.elim this
(suppose x ∈ '[a, b],
and.intro (and.left this) (le.trans (and.right this) H2))
(suppose x ∈ '(b, c],
and.intro (le_of_lt (lt_of_le_of_lt H1 (and.left this))) (and.right this))))
proposition singleton_union_Ioc {a b : A} (H : a ≤ b) : '{a} ∪ '(a, b] = '[a,b] :=
by rewrite [-Icc_self, Icc_eq_Icc_union_Ioc !le.refl H]
end strong_order_pair
/- intervals of natural numbers -/
namespace nat
open nat eq.ops
variables m n : ℕ
proposition Ioc_eq_Icc_succ : '(m, n] = '[succ m, n] := rfl
proposition Ioo_eq_Ico_succ : '(m, n) = '[succ m, n) := rfl
proposition Ico_succ_eq_Icc : '[m, succ n) = '[m, n] :=
set.ext (take x, iff.intro
(assume H, and.intro (and.left H) (le_of_lt_succ (and.right H)))
(assume H, and.intro (and.left H) (lt_succ_of_le (and.right H))))
proposition Ioo_succ_eq_Ioc : '(m, succ n) = '(m, n] :=
set.ext (take x, iff.intro
(assume H, and.intro (and.left H) (le_of_lt_succ (and.right H)))
(assume H, and.intro (and.left H) (lt_succ_of_le (and.right H))))
proposition Ici_zero : '[(0 : nat), ∞) = univ :=
eq_univ_of_forall (take x, zero_le x)
proposition Icc_zero (n : ℕ) : '[0, n] = '(-∞, n] :=
have '[0, n] = '[0, ∞) ∩ '(-∞, n], from rfl,
by rewrite [this, Ici_zero, univ_inter]
proposition bij_on_add_Icc_zero (m n : ℕ) : bij_on (add m) ('[0, n]) ('[m, m+n]) :=
have mapsto : ∀₀ i ∈ '[0, n], m + i ∈ '[m, m+n], from
(take i, assume imem,
have H1 : m ≤ m + i, from !le_add_right,
have H2 : m + i ≤ m + n, from add_le_add_left (and.right imem) m,
show m + i ∈ '[m, m+n], from and.intro H1 H2),
have injon : inj_on (add m) ('[0, n]), from
(take i j, assume Hi Hj H, !eq_of_add_eq_add_left H),
have surjon : surj_on (add m) ('[0, n]) ('[m, m+n]), from
(take j, assume Hj : j ∈ '[m, m+n],
obtain lej jle, from Hj,
let i := j - m in
have ile : i ≤ n, from calc
j - m ≤ m + n - m : nat.sub_le_sub_right jle m
... = n : nat.add_sub_cancel_left,
have iadd : m + i = j, by rewrite add.comm; apply nat.sub_add_cancel lej,
exists.intro i (and.intro (and.intro !zero_le ile) iadd)),
bij_on.mk mapsto injon surjon
end nat
section nat -- put the instances in the intervals namespace
open nat eq.ops
variables m n : ℕ
proposition nat.Iic_finite [instance] (n : ℕ) : finite '(-∞, n] :=
nat.induction_on n
(have '(-∞, 0] ⊆ '{0}, from λ x H, mem_singleton_of_eq (le.antisymm H !zero_le),
finite_subset this)
(take n, assume ih : finite '(-∞, n],
have '(-∞, succ n] ⊆ '(-∞, n] ∪ '{succ n},
by intro x H; rewrite [mem_union_iff, mem_singleton_iff]; apply le_or_eq_succ_of_le_succ H,
finite_subset this)
proposition nat.Iio_finite [instance] (n : ℕ) : finite '(-∞, n) :=
have '(-∞, n) ⊆ '(-∞, n], from λ x, le_of_lt,
finite_subset this
proposition nat.Icc_finite [instance] (m n : ℕ) : finite ('[m, n]) :=
have '[m, n] ⊆ '(-∞, n], from λ x H, and.right H,
finite_subset this
proposition nat.Ico_finite [instance] (m n : ℕ) : finite ('[m, n)) :=
have '[m, n) ⊆ '(-∞, n), from λ x H, and.right H,
finite_subset this
proposition nat.Ioc_finite [instance] (m n : ℕ) : finite '(m, n] :=
have '(m, n] ⊆ '(-∞, n], from λ x H, and.right H,
finite_subset this
end nat
end interval
|
c256cafe2a18090f71a30ffacf379b5ea4c791c2 | 6432ea7a083ff6ba21ea17af9ee47b9c371760f7 | /src/Init/Data/Nat/Div.lean | 31fe788f175d5d4f3d3beb5d8e0d47858460cab9 | [
"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 | 6,235 | 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.WF
import Init.WFTactics
import Init.Data.Nat.Basic
namespace Nat
theorem div_rec_lemma {x y : Nat} : 0 < y ∧ y ≤ x → x - y < x :=
fun ⟨ypos, ylex⟩ => sub_lt (Nat.lt_of_lt_of_le ypos ylex) ypos
@[extern "lean_nat_div"]
protected def div (x y : @& Nat) : Nat :=
if 0 < y ∧ y ≤ x then
Nat.div (x - y) y + 1
else
0
decreasing_by apply div_rec_lemma; assumption
instance : Div Nat := ⟨Nat.div⟩
theorem div_eq (x y : Nat) : x / y = if 0 < y ∧ y ≤ x then (x - y) / y + 1 else 0 := by
show Nat.div x y = _
rw [Nat.div]
rfl
theorem div.inductionOn.{u}
{motive : Nat → Nat → Sort u}
(x y : Nat)
(ind : ∀ x y, 0 < y ∧ y ≤ x → motive (x - y) y → motive x y)
(base : ∀ x y, ¬(0 < y ∧ y ≤ x) → motive x y)
: motive x y :=
if h : 0 < y ∧ y ≤ x then
ind x y h (inductionOn (x - y) y ind base)
else
base x y h
decreasing_by apply div_rec_lemma; assumption
theorem div_le_self (n k : Nat) : n / k ≤ n := by
induction n using Nat.strongInductionOn with
| ind n ih =>
rw [div_eq]
-- Note: manual split to avoid Classical.em which is not yet defined
cases (inferInstance : Decidable (0 < k ∧ k ≤ n)) with
| isFalse h => simp [h]
| isTrue h =>
suffices (n - k) / k + 1 ≤ n by simp [h, this]
have ⟨hK, hKN⟩ := h
have hSub : n - k < n := sub_lt (Nat.lt_of_lt_of_le hK hKN) hK
have : (n - k) / k ≤ n - k := ih (n - k) hSub
exact succ_le_of_lt (Nat.lt_of_le_of_lt this hSub)
theorem div_lt_self {n k : Nat} (hLtN : 0 < n) (hLtK : 1 < k) : n / k < n := by
rw [div_eq]
cases (inferInstance : Decidable (0 < k ∧ k ≤ n)) with
| isFalse h => simp [hLtN, h]
| isTrue h =>
suffices (n - k) / k + 1 < n by simp [h, this]
have ⟨_, hKN⟩ := h
have : (n - k) / k ≤ n - k := div_le_self (n - k) k
have := Nat.add_le_of_le_sub hKN this
exact Nat.lt_of_lt_of_le (Nat.add_lt_add_left hLtK _) this
@[extern "lean_nat_mod"]
protected def modCore (x y : @& Nat) : Nat :=
if 0 < y ∧ y ≤ x then
Nat.modCore (x - y) y
else
x
decreasing_by apply div_rec_lemma; assumption
@[extern "lean_nat_mod"]
protected def mod : @& Nat → @& Nat → Nat
/- This case is not needed mathematically as the case below is equal to it; however, it makes
`0 % n = 0` true definitionally rather than just propositionally.
This property is desirable for `Fin n`, as it means `(ofNat 0 : Fin n).val = 0` by definition.
Primarily, this is valuable because mathlib in Lean3 assumed this was true definitionally, and so
keeping this definitional equality makes mathlib easier to port to mathlib4. -/
| 0, _ => 0
| x@(_ + 1), y => Nat.modCore x y
instance : Mod Nat := ⟨Nat.mod⟩
protected theorem modCore_eq_mod (x y : Nat) : Nat.modCore x y = x % y := by
cases x with
| zero =>
rw [Nat.modCore]
exact if_neg fun ⟨hlt, hle⟩ => Nat.lt_irrefl _ (Nat.lt_of_lt_of_le hlt hle)
| succ x => rfl
theorem mod_eq (x y : Nat) : x % y = if 0 < y ∧ y ≤ x then (x - y) % y else x := by
rw [←Nat.modCore_eq_mod, ←Nat.modCore_eq_mod, Nat.modCore]
theorem mod.inductionOn.{u}
{motive : Nat → Nat → Sort u}
(x y : Nat)
(ind : ∀ x y, 0 < y ∧ y ≤ x → motive (x - y) y → motive x y)
(base : ∀ x y, ¬(0 < y ∧ y ≤ x) → motive x y)
: motive x y :=
div.inductionOn x y ind base
@[simp] theorem mod_zero (a : Nat) : a % 0 = a :=
have : (if 0 < 0 ∧ 0 ≤ a then (a - 0) % 0 else a) = a :=
have h : ¬ (0 < 0 ∧ 0 ≤ a) := fun ⟨h₁, _⟩ => absurd h₁ (Nat.lt_irrefl _)
if_neg h
(mod_eq a 0).symm ▸ this
theorem mod_eq_of_lt {a b : Nat} (h : a < b) : a % b = a :=
have : (if 0 < b ∧ b ≤ a then (a - b) % b else a) = a :=
have h' : ¬(0 < b ∧ b ≤ a) := fun ⟨_, h₁⟩ => absurd h₁ (Nat.not_le_of_gt h)
if_neg h'
(mod_eq a b).symm ▸ this
theorem mod_eq_sub_mod {a b : Nat} (h : a ≥ b) : a % b = (a - b) % b :=
match eq_zero_or_pos b with
| Or.inl h₁ => h₁.symm ▸ (Nat.sub_zero a).symm ▸ rfl
| Or.inr h₁ => (mod_eq a b).symm ▸ if_pos ⟨h₁, h⟩
theorem mod_lt (x : Nat) {y : Nat} : y > 0 → x % y < y := by
induction x, y using mod.inductionOn with
| base x y h₁ =>
intro h₂
have h₁ : ¬ 0 < y ∨ ¬ y ≤ x := Iff.mp (Decidable.not_and_iff_or_not _ _) h₁
match h₁ with
| Or.inl h₁ => exact absurd h₂ h₁
| Or.inr h₁ =>
have hgt : y > x := gt_of_not_le h₁
have heq : x % y = x := mod_eq_of_lt hgt
rw [← heq] at hgt
exact hgt
| ind x y h h₂ =>
intro h₃
have ⟨_, h₁⟩ := h
rw [mod_eq_sub_mod h₁]
exact h₂ h₃
theorem mod_le (x y : Nat) : x % y ≤ x := by
match Nat.lt_or_ge x y with
| Or.inl h₁ => rw [mod_eq_of_lt h₁]; apply Nat.le_refl
| Or.inr h₁ => match eq_zero_or_pos y with
| Or.inl h₂ => rw [h₂, Nat.mod_zero x]; apply Nat.le_refl
| Or.inr h₂ => exact Nat.le_trans (Nat.le_of_lt (mod_lt _ h₂)) h₁
@[simp] theorem zero_mod (b : Nat) : 0 % b = 0 := by
rw [mod_eq]
have : ¬ (0 < b ∧ b = 0) := by
intro ⟨h₁, h₂⟩
simp_all
simp [this]
@[simp] theorem mod_self (n : Nat) : n % n = 0 := by
rw [mod_eq_sub_mod (Nat.le_refl _), Nat.sub_self, zero_mod]
theorem mod_one (x : Nat) : x % 1 = 0 := by
have h : x % 1 < 1 := mod_lt x (by decide)
have : (y : Nat) → y < 1 → y = 0 := by
intro y
cases y with
| zero => intro _; rfl
| succ y => intro h; apply absurd (Nat.lt_of_succ_lt_succ h) (Nat.not_lt_zero y)
exact this _ h
theorem div_add_mod (m n : Nat) : n * (m / n) + m % n = m := by
rw [div_eq, mod_eq]
have h : Decidable (0 < n ∧ n ≤ m) := inferInstance
cases h with
| isFalse h => simp [h]
| isTrue h =>
simp [h]
have ih := div_add_mod (m - n) n
rw [Nat.left_distrib, Nat.mul_one, Nat.add_assoc, Nat.add_left_comm, ih, Nat.add_comm, Nat.sub_add_cancel h.2]
decreasing_by apply div_rec_lemma; assumption
end Nat
|
c31b8efd2bb3397d3cfe815bfe32ec7c27759af7 | 94d8c57c0a90adc01592a2509d65a360540671a9 | /M1F/2017-18/Example_Sheet_02/solutions.lean | 313eafa6d19af46262594c3900439524b3137ac2 | [] | no_license | TudorTitan/xena | ee58125263b84ca8787ea46778e7b4838c7b3057 | 389b9c40c43b26139722c88763f4d04d85467e0f | refs/heads/master | 1,628,408,454,654 | 1,510,265,443,000 | 1,510,265,443,000 | 110,169,835 | 0 | 0 | null | 1,510,264,043,000 | 1,510,264,043,000 | null | UTF-8 | Lean | false | false | 19,135 | lean | import xenalib.M1Fstuff algebra.group_power xenalib.square_root
-- automatic coercions to reals
section M1F_Sheet02
-- #check arbitrary
-- #print arbitrary
-- #check default
-- #print default
-- ask about this
/-
example : arbitrary = default :=
begin
unfold eq,
end
-/
-- set_option pp.all true
def countable_union_from_zero {α : Type} (X : nat → set α ) := { t : α | exists i, t ∈ X i}
def countable_union_from_one {α : Type} (X : nat → set α ) := { t : α | exists i, i > 0 ∧ t ∈ X i}
def Q1a_sets : ℕ → set ℝ := λ n x, ↑n ≤ x ∧ x < (n+1)
-- #check Q1a_sets
/-
def Q1a_sets2 : ℕ → set ℝ := λ n, { x | ↑ n ≤ x ∧ x < (n+1)}
example : Q1a_sets = Q1a_sets2 :=
begin
apply funext,
intro n,
unfold Q1a_sets,
unfold Q1a_sets2,
apply funext,
intro x,unfold set_of,
end
-/
-- set_option pp.all true
theorem Q1a : countable_union_from_zero Q1a_sets = { x | 0 ≤ x} :=
begin
unfold countable_union_from_zero,
unfold Q1a_sets,
apply funext,
intro x,
unfold set_of,
have H : ∃ (n : ℤ), ↑n ≤ x ∧ x < ↑n + 1,
exact M1F.floor_real_exists x,
apply propext,
split,
intro H2,
cases H2 with i H3,
have H4 : ↑i ≤ x,
exact H3.left,
have H5 : (0:ℤ) ≤ ↑i,
exact int.coe_zero_le i,
apply le_trans _ H4,
simp [H5],
intro H2,
cases H with n H3,
have H4 : ((0:ℤ):ℝ) < (n:real) +(1:real),
exact lt_of_le_of_lt H2 H3.right,
have H5 : ((0:ℤ):ℝ) < (n:ℝ) + ((1:ℤ):ℝ),
rw [int.cast_one], exact H4,
clear H4,
-- rw [←int.cast_add] at H4,
-- have H5 : (0:ℤ) < n + of_rat(1),
-- exact H4,
-- rw [of_rat_add,of_rat_lt] at H5,
-- clear H4,
rw [←int.cast_add,int.cast_lt] at H5,
rw [int.lt_iff_add_one_le] at H5,
simp at H5,
have H : ∃ (n_1 : ℕ), n = ↑n_1,
exact int.eq_coe_of_zero_le H5,
cases H with i H4,
clear H5 H2,
existsi i,
split,
exact calc (i:ℝ) = ((i:ℤ):ℝ) : by simp
... = (n:ℝ) : int.cast_inj.mpr (eq.symm H4)
... ≤ x : H3.left,
suffices H : (↑n : ℝ) = (↑i : ℝ),
rw [←H],exact H3.right,
rw [H4],
refl,
end
def Q1b_sets : ℕ → set ℝ := λ n x, 1/(↑n) ≤ x ∧ x ≤ 1
-- set_option pp.notation false
-- set_option class.instance_max_depth
-- set_option pp.all true
theorem Q1b : countable_union_from_one Q1b_sets = { x | 0 < x ∧ x ≤ 1} :=
begin
unfold countable_union_from_one,
unfold Q1b_sets,
apply funext,
intro x,
unfold set_of,
apply propext,
split;intro H,
cases H with i Hi,
split,
tactic.swap,
exact Hi.right.right,
suffices H2 : (0:ℝ) < 1/(↑i),
exact lt_of_lt_of_le H2 Hi.right.left,
-- have H3 : of_rat (((0:nat):int):rat) < of_rat ((i:int):rat),
-- rw [of_rat_lt,rat.coe_int_lt,int.coe_nat_lt_coe_nat_iff],
-- exact Hi.left,
rw [←int.cast_zero],
exact lt_div_of_mul_lt (nat.cast_lt.mpr Hi.left) (by simp [zero_lt_one]),
have H2 : 0 < 1/x,
exact lt_div_of_mul_lt H.left (by simp [zero_lt_one]),
have H3 : ∃ (n : ℤ), ↑n ≤ 1 / x ∧ 1 / x < ↑n + 1,
exact M1F.floor_real_exists (1/x),
cases H3 with n Hn,
have H3 : (0:ℝ) < (n:ℝ) + (1:ℝ),
exact lt_of_lt_of_le H2 (le_of_lt Hn.right),
rw [←int.cast_one,←int.cast_add,←int.cast_zero,int.cast_lt,int.lt_iff_add_one_le] at H3,
have H4 : ↑0 ≤ n,
apply le_of_add_le_add_right H3,
cases n with nnat nfalse,
tactic.swap,
have H5 : (0:ℤ) < (0:ℤ),
exact calc (0:ℤ) ≤ int.neg_succ_of_nat nfalse : H4
... < 0 : int.neg_succ_of_nat_lt_zero nfalse,
exfalso,
apply H5,
clear H3 H4,
existsi (nnat+1),
split,
exact calc 0< nat.succ nnat : nat.zero_lt_succ nnat
... = nnat+1 : rfl,
split,
tactic.swap,
exact H.right,
have H4 : x > 0,
unfold gt,exact H.left,
have H5 : nnat+1>0,
exact (nat.zero_lt_succ nnat),
have H6 : (((nnat+1):ℕ):ℝ) > 0,
exact nat.cast_lt.mpr H5,
have H7 : ((int.of_nat nnat):ℝ) + 1 = (((nnat+1):ℕ):ℝ), simp,
have Hnr : 1 / x < ↑(int.of_nat nnat) + 1,
exact Hn.right,
rw [H7] at Hnr,
clear Hn H5,
suffices H5 : 1 ≤ ↑(nnat+1)*x,
exact div_le_of_le_mul H6 H5,
exact (div_le_iff_le_mul_of_pos H4).mp (le_of_lt Hnr)
end
def Q1c_sets : ℕ → set ℝ := λ n x, -↑n < x ∧ x < n
-- #check max,
theorem Q1c : countable_union_from_one Q1c_sets = { x | true } :=
begin
unfold countable_union_from_one,
unfold Q1c_sets,
apply funext,
intro x,
unfold set_of,
apply propext,
split;intro H,
trivial,
have H2 : ∃ (n : ℤ), ↑n ≤ x ∧ x < ↑n + 1,
exact M1F.floor_real_exists x,
have H3 : ∃ (m : ℤ), ↑m ≤ (-x) ∧ (-x) < ↑m + 1,
exact M1F.floor_real_exists (-x),
cases H2 with n Hn,
cases H3 with m Hm,
let iz:ℤ := max (1:ℤ) (max (n+1) ((m+1))),
have H4 : iz ≥ 1,
exact le_max_left (1:ℤ) _,
have H5 : ∃ (i:ℕ), iz=i,
exact int.eq_coe_of_zero_le (le_trans (le_of_lt (zero_lt_one)) H4),
cases H5 with i Hi,
existsi i,
split,
suffices H1 : 0<i,
exact H1,
rw [←int.coe_nat_lt_coe_nat_iff,←Hi],
exact lt_of_lt_of_le zero_lt_one H4,
split,
suffices H1 : -↑i ≤ -(↑m + (1:ℝ)),
exact lt_of_le_of_lt H1 (neg_lt.mp Hm.right),
suffices H2 : (↑m+1)≤ (↑i:ℝ),
exact neg_le_neg H2,
rw [←int.cast_one,←int.cast_add],
suffices H5 : (((m+1):ℤ):ℝ)≤((i:ℤ):ℝ),
exact H5,
rw [int.cast_le],
rw [←Hi],
exact calc m+1 ≤ max (n+1) (m+1) : le_max_right (n+1) (m+1)
... ≤ iz : le_max_right 1 _,
suffices H1 : (n:ℝ)+1 ≤ i, -- of_rat ((n:ℤ):ℚ) + of_rat ((1:ℤ):ℚ) ≤ of_rat ((i:ℤ):ℚ),
exact lt_of_lt_of_le Hn.right H1,
rw [←int.cast_one,←int.cast_add],
suffices H8 : (((n+1):ℤ):ℝ)≤ ((i:ℤ):ℝ), -- of_rat_add,of_rat_le_of_rat,←rat.coe_int_add,rat.coe_int_le],
exact H8,
rw [int.cast_le,←Hi],
exact calc n+1 ≤ max (n+1) (m+1) : le_max_left (n+1) (m+1)
... ≤ iz : le_max_right 1 _,
end
def countable_intersection_from_one {α : Type} (X : nat → set α ) := { t : α | ∀ i, i>0 → t ∈ X i}
-- part d has same sets as part c
-- set_option pp.notation false
theorem Q1d : countable_intersection_from_one Q1c_sets = {x | -1<x ∧ x<1} :=
begin
unfold countable_intersection_from_one,
unfold Q1c_sets,
apply funext,
intro x,
unfold set_of,
apply propext,
unfold has_mem.mem set.mem,
-- all that unfolding leaves us with
/-
x : ℝ
⊢ (∀ (i : ℕ), i > 0 → -↑i < x ∧ x < ↑i) ↔ -1 < x ∧ x < 1
-/
split;intro H,
simpa using ((H 1) (zero_lt_one)),
intro i,
intro Hi,
have i_le_one, exact nat.succ_le_of_lt Hi,
split,
exact calc -(i:ℝ) ≤ -↑1 : neg_le_neg (nat.cast_le.2 i_le_one)
... = -1 : by simp
... <x : H.left,
exact calc x < 1 : H.right
... = ↑(1:ℕ) : by simp
... ≤ ↑i : nat.cast_le.2 i_le_one
end
-- question 2
def open_zero_one := { x : ℝ | 0<x ∧ x<1}
theorem Q2 : forall x : ℝ, x ∈ open_zero_one → ∃ y : ℝ, y ∈ open_zero_one ∧ x<y :=
begin
intro x,
intro H,
have H1 : (0:ℝ) < (2:ℝ),
exact lt_add_of_le_of_pos zero_le_one zero_lt_one,
existsi (x+1)/2,
split,
split,
have H2 : 0<x,
exact H.left,
have H3 : 0 < (x+1),
exact lt_add_of_lt_of_nonneg' H2 zero_le_one,
exact lt_div_of_mul_lt H1 (by simp [H3]),
suffices H2 : (x+1) < 2,
-- tell nmario that without simp theres a timeout
exact div_lt_of_mul_lt_of_pos H1 (by simp [H2]),
exact add_lt_add_right H.right 1,
have H2 : x*(1+1) < (x+1),
rw [mul_add,mul_one,add_lt_add_iff_left],
exact H.right,
have H3 : x*2<(x+1),
exact H2,
exact lt_div_of_mul_lt H1 H3,
-- simp [div_lt_div_of_lt_of_pos H2 H1],
end
-- set_option pp.notation false
theorem Q3a (n : int) : (3:ℤ) ∣ n^2 → 3 ∣ n :=
begin
intro Hn2,
-- let r := n % 3,
-- let q := int.div n 3,
-- have H : n = 3*q+r,
have H : n % 3 < 3,
exact @int.mod_lt_of_pos n 3 (by exact dec_trivial),
have H2 : n%3 ≥ 0,
exact int.mod_nonneg n (by exact dec_trivial),
have H3 : exists r:ℕ, (n%3) = int.of_nat r,
exact (int.eq_coe_of_zero_le H2),
cases H3 with r Hr,
have H3 : r<3,
rw [←int.coe_nat_lt_coe_nat_iff,←int.of_nat_eq_coe,←Hr],
exact H,
cases r with r0,
exact (int.dvd_iff_mod_eq_zero 3 n).mpr Hr,
cases r0 with r1,
clear H H2 H3,
exfalso,
have H : (n+2)%3=0,
rw [←int.mod_add_mod,Hr],
have H : int.of_nat 1 + 2 = 3,
exact dec_trivial,
rw [H],
exact int.mod_self,
have H2 : 3 ∣ ((n-2)*(n+2)),
-- rw [←int.dvd_iff_mod_eq_zero],
rw [←int.dvd_iff_mod_eq_zero] at H,
exact dvd_trans H (dvd_mul_left _ _),
simp at H2,
rw [mul_add,add_mul,add_mul,add_assoc,←add_assoc (2*n) _ _,mul_comm 2 n,←mul_add,add_neg_self,mul_zero,zero_add] at H2,
unfold pow_nat has_pow_nat.pow_nat pow_nat monoid.pow at Hn2,
have H3 : 3 ∣ n * (n * 1) - (n * n + 2 * -2),
exact dvd_sub Hn2 H2,
simp at H3,
rw [←add_assoc,add_neg_self,zero_add] at H3,
have H4 : ¬ ((3:ℤ) ∣ 2*2),
exact dec_trivial,
exact H4 H3,
cases r1 with r2,
clear H H2 H3,
exfalso,
have H : (n+1)%3=0,
rw [←int.mod_add_mod,Hr],
have H : int.of_nat 2 + 1 = 3,
exact dec_trivial,
rw [H],
exact int.mod_self,
have H2 : 3 ∣ ((n-1)*(n+1)),
-- rw [←int.dvd_iff_mod_eq_zero],
rw [←int.dvd_iff_mod_eq_zero] at H,
exact dvd_trans H (dvd_mul_left _ _),
simp at H2,
rw [mul_add,add_mul,add_mul,add_assoc,←add_assoc (1*n) _ _,mul_comm 1 n,←mul_add,add_neg_self,mul_zero,zero_add] at H2,
unfold pow_nat has_pow_nat.pow_nat pow_nat monoid.pow at Hn2,
have H3 : 3 ∣ n * (n * 1) - (n * n + 1 * -1),
exact dvd_sub Hn2 H2,
simp at H3,
have H4 : ¬ ((3:ℤ) ∣ 1),
exact dec_trivial,
exact H4 H3,
exfalso,
have H4 : r2+4 ≤ 3,
exact nat.succ_le_of_lt H3,
repeat {rw [nat.succ_le_succ_iff] at H4},
have H5 : nat.succ r2 > 0,
exact nat.zero_lt_succ r2,
have H6 : 0 < 0,
exact calc 0 < r2+1 : H5 ... ≤ 0 : H4,
have H7 : 0 ≠ 0, exact ne_of_gt H6,
have H8 : 0 = 0, refl,
exact H7 H8
-- unfold int.nat_mod at r,
-- unfold int.div at q,
end
-- square root of 3
def exists_sqrt_3 := square_root.exists_unique_square_root 3 (by norm_num)
-- #check exists_sqrt_3
-- exists_sqrt_3 : ∃ (q : ℝ), q ≥ 0 ∧ q ^ 2 = 3 ∧ ∀ (s : ℝ), s ≥ 0 ∧ s ^ 2 = 3 → s = q
noncomputable def sqrt3 := classical.some (exists_sqrt_3)
def sqrt3_proof := classical.some_spec (exists_sqrt_3)
-- #check sqrt3_proof
example : sqrt3^2 = 3 := sqrt3_proof.right.left
noncomputable example : monoid ℝ := by apply_instance
set_option pp.all true
theorem no_rational_squared_is_three : ¬ (∃ (q:ℚ),q^2=3) :=
begin
intro H0,cases H0 with q Hq2,
rw [pow_two_eq_mul_self] at Hq2,
let n:=q.num,
let d0:=q.denom,
have Hq_is_n_div_d : q=n/d0,
rw [rat.num_denom q,rat.mk_eq_div],
refl,
have Hd0_not_zero : ¬ (d0=0),
intro Hd0,
have Hq0 : q=0,
rwa [Hd0,nat.cast_zero,div_zero] at Hq_is_n_div_d,
rw [Hq0,mul_zero] at Hq2,
revert Hq2,
norm_num,
let d:ℤ:=↑d0,
rw [rat.num_denom q] at Hq2,
rw [rat.mk_eq_div] at Hq2,
change q.denom with d0 at Hq2,
change (d0:ℤ) with d at Hq2,
have Hd_not_zero : ¬ (d=0),
intro H0, apply Hd0_not_zero,
rw [←nat.cast_zero] at H0,
change d with (d0:ℤ) at H0,
rw [←@nat.cast_inj ℤ],
simp [H0], -- why doesn't exact work?
-- tidy up
change q.num with n at Hq2,
clear Hq_is_n_div_d Hd0_not_zero,
rw [div_mul_div] at Hq2,
have H0 : (d:ℚ) * (d:ℚ) ≠ 0,
intro H1,
apply Hd_not_zero,
rw [←int.cast_zero,←int.cast_mul,int.cast_inj] at H1,
cases eq_zero_or_eq_zero_of_mul_eq_zero H1,
assumption,
assumption,
have H1 : (3:ℚ) * (↑d * ↑d) = ↑n * ↑n,
exact (eq_div_iff_mul_eq _ _ H0).mp (eq.symm Hq2),
have H2 : ((3:ℤ):ℚ) * (↑d * ↑d) = ↑n * ↑n,
exact H1,
rw [←int.cast_mul,←int.cast_mul,←int.cast_mul,int.cast_inj] at H2,
-- tidy up; now in Z.
clear Hq2 H0 H1,
-- coprimality of n and d0 built into rat
have H0 : nat.coprime (int.nat_abs n) d0,
exact q.cop,
have H3 : n*n=n^2,
exact mul_self_eq_pow_two,
rw [H3] at H2,
have H1 : (3:ℤ) ∣ n^2,
exact ⟨d*d,eq.symm H2⟩,
have H4 : (3:ℤ) ∣ n,
exact Q3a n H1,
cases H4 with n1 H5,
rw [←H3,H5] at H2,clear H3,
rw [mul_assoc] at H2,
have H6 : d * d = n1 * (3 * n1),
exact eq_of_mul_eq_mul_left (by norm_num) H2,clear H2,
rw [mul_comm n1,mul_assoc] at H6,
rw [mul_self_eq_pow_two] at H6,
have H2 : (3:ℤ) ∣ d^2,
exact ⟨n1 * n1, H6⟩,
clear H1 H6,
have H1 : (3:ℤ) ∣ d,
exact Q3a d H2,
clear H2,
cases H1 with d1 H2,
-- now know H5 : n=3*something,
-- H2 : d = 3 * something,
-- H0 : n coprime to d (modulo coercions)
-- Seems like I now have to coerce everything down to nat
let n0 := int.nat_abs n,
clear Hd_not_zero,
change int.nat_abs n with n0 at H0,
let n2 := int.nat_abs n1,
have H1 : n0 = 3 * n2,
change (3:ℕ) with int.nat_abs (3:ℤ),
rw [←int.nat_abs_mul,←H5],
clear H5,
let d2 := int.nat_abs d1,
have H3 : d0 = 3 * d2,
rw [←int.nat_abs_of_nat d0],
change 3 with int.nat_abs (3:ℤ),
change d2 with int.nat_abs d1,
rw [←int.nat_abs_mul,←H2],
rw [H1,H3] at H0,
clear H3 H2 d d0 H1 n0 n q,
have H1 : nat.coprime (3 * n2) 3,
exact nat.coprime.coprime_mul_right_right H0,
clear H0,
rw [mul_comm] at H1,
have H2 :nat.coprime 3 3,
exact nat.coprime.coprime_mul_left H1,
clear H1 n2 d2 n1 d1,
have H0 : nat.gcd 3 3 = 1,
exact H2,clear H2,
have H1 : 3 ∣ nat.gcd 3 3,
exact nat.dvd_gcd ⟨1,mul_one 3⟩ ⟨1,mul_one 3⟩,
rw H0 at H1,
clear H0,
have H0 : 3 = 1,
exact nat.eq_one_of_dvd_one H1,
clear H1,
revert H0,
norm_num,
end
theorem Q3b : M1F.is_irrational (sqrt3) :=
begin
unfold M1F.is_irrational,
intro H,
cases H with q Hq,
have Hq2 : q*q = (3:ℚ),
rw [←@rat.cast_inj ℝ,rat.cast_mul,Hq,mul_self_eq_pow_two],
unfold sqrt3,
rw [sqrt3_proof.right.left],
norm_num,
clear Hq,
rw [mul_self_eq_pow_two] at Hq2,
apply no_rational_squared_is_three,
existsi q,
exact Hq2,
end
-- #print no_rational_squared_is_three -- interesting with pp.all true
theorem Q4a : ¬ (∀ (x y : ℝ), M1F.is_irrational x → M1F.is_irrational y → M1F.is_irrational (x+y)) :=
begin
intro H,
let H2 := H sqrt3 (-sqrt3) Q3b,
have H3 : M1F.is_irrational (-sqrt3),
unfold M1F.is_irrational,
intro H4,
cases H4 with q Hq,
apply Q3b,
exact ⟨-q,
begin
rw [rat.cast_neg],
exact eq.symm (eq_neg_iff_eq_neg.mpr (Hq)),
end
⟩,
apply H2 H3,
exact ⟨0,
begin
rw [add_neg_self,rat.cast_zero],
end
⟩,
end
theorem Q4b : ¬ (∀ (a : ℝ), ∀ (b : ℚ), M1F.is_irrational a → M1F.is_irrational (a*b)) :=
begin
intro H,
let H2 := H sqrt3 0 Q3b,
apply H2,
exact ⟨0,by rw [rat.cast_zero,mul_zero]⟩,
end
theorem Q5a : ∀ (x : ℝ), ∃ (y:ℝ), x+y=2 :=
begin
intro x,
exact ⟨-x+2,by rw [←add_assoc,add_neg_self,zero_add]⟩,
end
theorem Q5b : ¬ (∃ (y:ℝ), ∀ (x:ℝ), x+y=2) :=
begin
intro H,
cases H with y Hy,
let H := Hy (-y),
rw [neg_add_self] at H,
revert H,
norm_num,
end
theorem Q6 : square_root.sqrt_abs 2 + square_root.sqrt_abs 6 < square_root.sqrt_abs 15 :=
begin
let s2 := square_root.sqrt_abs 2,
change square_root.sqrt_abs 2 with s2, --
let s6 := square_root.sqrt_abs 6,
change square_root.sqrt_abs 6 with s6, --
let s15 := square_root.sqrt_abs 15,
change square_root.sqrt_abs 15 with s15, -- I just want names for these variables.
have Hs15 : s15^2 = 15,
exact square_root.sqrt_abs_squared 15 (by norm_num),
rw [pow_two_eq_mul_self] at Hs15,
have Hs2 : s2^2 = 2,
exact square_root.sqrt_abs_squared 2 (by norm_num),
rw [pow_two_eq_mul_self] at Hs2,
have Hs6 : s6^2 = 6,
exact square_root.sqrt_abs_squared 6 (by norm_num), -- I know I'll need these things at some point.
rw [pow_two_eq_mul_self] at Hs6,
apply imp_of_not_or (le_or_gt s15 (s2 + s6)),
intro H1,
-- now square both sides of H1
have H2 : s15 ≥ 0,
exact square_root.sqrt_abs_ge_zero 15,
have H3 : s15*s15 ≤ (s2+s6)*(s2+s6) := mul_self_le_mul_self H2 H1,
rw [Hs15,add_mul_self_eq,Hs2,Hs6] at H3,
rw [←sub_le_iff_le_add,add_comm,←sub_le_iff_le_add] at H3,
revert H3,
norm_num,
intro H3,
have H4 : 7*7 ≤ (s2*(s6*2))*(s2*(s6*2)) := mul_self_le_mul_self (by norm_num) H3,
have H5 : (49:ℝ) ≤ 48 := calc
49 = 7 * 7 : by norm_num
... ≤ s2 * (s6 * 2) * (s2 * (s6 * 2)) : H4
... = (s2*s2)*(s6*s6)*(2*2) : by simp
... = (2:ℝ)*6*(2*2) : by rw [Hs2,Hs6]
... = 48 : by norm_num,
revert H5,
norm_num,
end
/- Q7 : are the following numbers rational or irrational
(a) sqrt(2)+sqrt(3/2)
(b) 1+sqrt(2)+sqrt(3/2)
(c) 2sqrt(18)-3sqrt(8)
-/
theorem Q7a : M1F.is_irrational (square_root.sqrt_abs 2 + square_root.sqrt_abs (3/2)) :=
begin
let s2 := square_root.sqrt_abs 2,
change square_root.sqrt_abs 2 with s2,
have Hs2 : s2^2 = 2,
exact square_root.sqrt_abs_squared 2 (by norm_num),
rw [pow_two_eq_mul_self] at Hs2,
let s3o2 := square_root.sqrt_abs (3/2),
change square_root.sqrt_abs (3/2) with s3o2,
have Hs3o2 : s3o2^2 = 3/2,
exact square_root.sqrt_abs_squared (3/2) (by norm_num),
rw [pow_two_eq_mul_self] at Hs3o2,
intro H,cases H with q Hq,
have H1 : (q:ℝ)*q = 2 + 2*s2*s3o2 + (3/2) := calc
(q:ℝ)*q = (s2 + s3o2)*(s2+s3o2) : by rw [Hq]
... = _ : by rw [add_mul_self_eq]
... = 2 + 2*s2*s3o2 + (3/2) : by rw [Hs2,Hs3o2],
rw [←sub_eq_iff_eq_add,add_comm,←sub_eq_iff_eq_add] at H1,
let r:ℚ := q*q-3/2-2,
have H2 : (r:ℝ)=↑q * ↑q - 3 / 2 - 2,
norm_num,
rw [←H2] at H1,
let s:ℚ := r/2,
have H2not0 : (2:ℝ) ≠ 0 := by norm_num,
have Htemp : (2*(s2*s3o2))/2 = s2*s3o2 := mul_div_cancel_left (s2*s3o2) H2not0,
rw ←mul_assoc at Htemp,
have H3 : (s:ℝ)*s=3 := calc
(s:ℝ)*s=(r/2)*(r/2) : by simp
... = ((2*s2*s3o2)/2)*((2*s2*s3o2)/2) : by rw [H1]
... = (s2*s3o2)*(s2*s3o2) : by rw [Htemp] -- simp [H2not0,mul_assoc,mul_div_cancel_left] -- rw [mul_assoc,mul_div_cancel_left,mul_assoc,mul_div_cancel_left];exact H2not0
... = (s2*s2)*(s3o2*s3o2) : by simp
... = 2*(3/2) : by rw [Hs2,Hs3o2]
... = 3 : by norm_num,
let t:ℚ := abs s,
have H4 : (t:ℝ)*t=3,
change t with abs s,
rwa [←rat.cast_mul,abs_mul_abs_self,rat.cast_mul],
have H4 : (t:ℝ) = sqrt3,
apply sqrt3_proof.right.right t,
split,
change t with abs s,
rw [rat.cast_abs],
exact abs_nonneg (s:ℝ),
rwa [pow_two_eq_mul_self],
have Htemp2 :M1F.is_irrational (t:ℝ),
rw [H4],
exact Q3b,
apply Htemp2,
existsi t,
refl,
end
theorem Q7b : M1F.is_irrational (1+square_root.sqrt_abs 2+square_root.sqrt_abs (3/2)) :=
begin
intro H,
apply Q7a,
cases H with q Hq,
existsi (q-1),
rw [rat.cast_sub,Hq],
simp,
end
theorem Q7c : exists q:ℚ, (q:ℝ) = 2*square_root.sqrt_abs 18 - 3 * square_root.sqrt_abs 8 :=
begin
existsi (0:ℚ),
rw [rat.cast_zero],apply eq.symm,
rw [sub_eq_zero_iff_eq,mul_comm],
-- apply eq.symm,
apply mul_eq_of_eq_div,
norm_num,
apply eq.symm,
apply square_root.sqrt_abs_unique,
{ norm_num},
split,
apply div_nonneg_of_nonneg_of_pos _ _,
apply mul_nonneg _ _,
norm_num,
apply square_root.sqrt_abs_ge_zero _,
norm_num,
-- rw [div_eq_mul_inv],
exact calc
3 * square_root.sqrt_abs 8 / 2 * (3 * square_root.sqrt_abs 8 / 2)
= (square_root.sqrt_abs 8) * (square_root.sqrt_abs 8) * 3 * 3 / 2 / 2 : by simp [div_eq_mul_inv]
... = 8*3*3/2/2 : by rw [square_root.sqrt_abs_mul_self 8 (by norm_num)]
... = 18 : by norm_num,
end
#print Q3b
end M1F_Sheet02 |
3aece32162bf881b69f9e3907ae100cf16cf4b56 | 95dcf8dea2baf2b4b0a60d438f27c35ae3dd3990 | /src/tactic/explode.lean | ef4ee54d30b547d6b85d629ba9f662f9d2d69299 | [
"Apache-2.0"
] | permissive | uniformity1/mathlib | 829341bad9dfa6d6be9adaacb8086a8a492e85a4 | dd0e9bd8f2e5ec267f68e72336f6973311909105 | refs/heads/master | 1,588,592,015,670 | 1,554,219,842,000 | 1,554,219,842,000 | 179,110,702 | 0 | 0 | Apache-2.0 | 1,554,220,076,000 | 1,554,220,076,000 | null | UTF-8 | Lean | false | false | 5,271 | lean | /-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Mario Carneiro
Displays a proof term in a line by line format somewhat akin to a Fitch style
proof or the Metamath proof style.
-/
import tactic.basic meta.coinductive_predicates
open expr tactic
namespace tactic
namespace explode
-- TODO(Mario): move back to list.basic
@[simp] def head' {α} : list α → option α
| [] := none
| (a :: l) := some a
inductive status | reg | intro | lam | sintro
meta structure entry :=
(expr : expr)
(line : nat)
(depth : nat)
(status : status)
(thm : string)
(deps : list nat)
meta def pad_right (l : list string) : list string :=
let n := l.foldl (λ r (s:string), max r s.length) 0 in
l.map $ λ s, nat.iterate (λ s, s.push ' ') (n - s.length) s
meta structure entries := mk' ::
(s : expr_map entry)
(l : list entry)
meta def entries.find (es : entries) (e : expr) := es.s.find e
meta def entries.size (es : entries) := es.s.size
meta def entries.add : entries → entry → entries
| es@⟨s, l⟩ e := if s.contains e.expr then es else ⟨s.insert e.expr e, e :: l⟩
meta def entries.head (es : entries) : option entry := head' es.l
meta instance : inhabited entries := ⟨⟨expr_map.mk _, []⟩⟩
meta def format_aux : list string → list string → list string → list entry → tactic format
| (line :: lines) (dep :: deps) (thm :: thms) (en :: es) := do
fmt ← do {
let margin := string.join (list.repeat " │" en.depth),
let margin := match en.status with
| status.sintro := " ├" ++ margin
| status.intro := " │" ++ margin ++ " ┌"
| status.reg := " │" ++ margin ++ ""
| status.lam := " │" ++ margin ++ ""
end,
p ← infer_type en.expr >>= pp,
let lhs := line ++ "│" ++ dep ++ "│ " ++ thm ++ margin ++ " ",
return $ format.of_string lhs ++ to_string p ++ format.line },
(++ fmt) <$> format_aux lines deps thms es
| _ _ _ _ := return format.nil
meta instance : has_to_tactic_format entries :=
⟨λ es : entries,
let lines := pad_right $ es.l.map (λ en, to_string en.line),
deps := pad_right $ es.l.map (λ en, string.intercalate "," (en.deps.map to_string)),
thms := pad_right $ es.l.map entry.thm in
format_aux lines deps thms es.l⟩
meta def append_dep (filter : expr → tactic unit)
(es : entries) (e : expr) (deps : list nat) : tactic (list nat) :=
do { ei ← es.find e,
filter ei.expr,
return (ei.line :: deps) }
<|> return deps
meta def may_be_proof (e : expr) : tactic bool :=
is_proof e >>= λ b, return $
b || is_app e || is_local_constant e || is_pi e || is_lambda e
end explode
open explode
meta mutual def explode.core, explode.args (filter : expr → tactic unit)
with explode.core : expr → bool → nat → entries → tactic entries
| e@(lam n bi d b) si depth es := do
m ← mk_fresh_name,
let l := local_const m n bi d,
let b' := instantiate_var b l,
if si then
let en : entry := ⟨l, es.size, depth, status.sintro, to_string n, []⟩ in do
es' ← explode.core b' si depth (es.add en),
return $ es'.add ⟨e, es'.size, depth, status.lam, "∀I", [es.size, es'.size - 1]⟩
else do
let en : entry := ⟨l, es.size, depth, status.intro, to_string n, []⟩,
es' ← explode.core b' si (depth + 1) (es.add en),
deps' ← explode.append_dep filter es' b' [],
deps' ← explode.append_dep filter es' l deps',
return $ es'.add ⟨e, es'.size, depth, status.lam, "∀I", deps'⟩
| e@(macro _ l) si depth es := explode.core l.head si depth es
| e si depth es := filter e >>
match get_app_fn_args e with
| (const n _, args) :=
explode.args e args depth es (to_string n) []
| (fn, []) := do
p ← pp fn,
let en : entry := ⟨fn, es.size, depth, status.reg, to_string p, []⟩,
return (es.add en)
| (fn, args) := do
es' ← explode.core fn ff depth es,
deps ← explode.append_dep filter es' fn [],
explode.args e args depth es' "∀E" deps
end
with explode.args : expr → list expr → nat → entries → string → list nat → tactic entries
| e (arg :: args) depth es thm deps := do
es' ← explode.core arg ff depth es <|> return es,
deps' ← explode.append_dep filter es' arg deps,
explode.args e args depth es' thm deps'
| e [] depth es thm deps :=
return (es.add ⟨e, es.size, depth, status.reg, thm, deps.reverse⟩)
meta def explode_expr (e : expr) (hide_non_prop := tt) : tactic entries :=
let filter := if hide_non_prop then λ e, may_be_proof e >>= guardb else λ _, skip in
tactic.explode.core filter e tt 0 (default _)
meta def explode (n : name) : tactic unit :=
do const n _ ← resolve_name n | fail "cannot resolve name",
d ← get_decl n,
v ← match d with
| (declaration.defn _ _ _ v _ _) := return v
| (declaration.thm _ _ _ v) := return v.get
| _ := fail "not a definition"
end,
t ← pp d.type,
explode_expr v <* trace (to_fmt n ++ " : " ++ t) >>= trace
open interactive lean lean.parser interaction_monad.result
@[user_command]
meta def explode_cmd (_ : parse $ tk "#explode") : parser unit :=
do n ← ident,
explode n
.
-- #explode iff_true_intro
-- #explode nat.strong_rec_on
end tactic
|
ad8ea0861be85203145001903579aa9a05093435 | 17d632ea5f1f2c2ec209290d6ba2172413c7247d | /.config.lean | 95a10d70f4d554b76ff50250329bf47aff3e3afc | [
"MIT"
] | permissive | zzc1308/MT1300 | 3ae434cbb5a874edd365719d6e8667b88de5a14d | ace57539645f4ac7f8170b95bb20e72849b34f15 | refs/heads/main | 1,677,561,804,582 | 1,612,434,366,000 | 1,612,434,366,000 | 335,842,283 | 0 | 0 | MIT | 1,612,414,537,000 | 1,612,414,537,000 | null | UTF-8 | Lean | false | false | 248,665 | lean | #
# Automatically generated file; DO NOT EDIT.
# OpenWrt Configuration
#
CONFIG_MODULES=y
CONFIG_HAVE_DOT_CONFIG=y
# CONFIG_TARGET_sunxi is not set
# CONFIG_TARGET_apm821xx is not set
# CONFIG_TARGET_ath25 is not set
# CONFIG_TARGET_ar71xx is not set
# CONFIG_TARGET_ath79 is not set
# CONFIG_TARGET_bcm27xx is not set
# CONFIG_TARGET_bcm53xx is not set
# CONFIG_TARGET_bcm47xx is not set
# CONFIG_TARGET_bcm63xx is not set
# CONFIG_TARGET_cns3xxx is not set
# CONFIG_TARGET_octeon is not set
# CONFIG_TARGET_gemini is not set
# CONFIG_TARGET_mpc85xx is not set
# CONFIG_TARGET_imx6 is not set
# CONFIG_TARGET_mxs is not set
# CONFIG_TARGET_lantiq is not set
# CONFIG_TARGET_malta is not set
# CONFIG_TARGET_pistachio is not set
# CONFIG_TARGET_mvebu is not set
# CONFIG_TARGET_kirkwood is not set
# CONFIG_TARGET_mediatek is not set
CONFIG_TARGET_ramips=y
# CONFIG_TARGET_at91 is not set
# CONFIG_TARGET_rb532 is not set
# CONFIG_TARGET_tegra is not set
# CONFIG_TARGET_layerscape is not set
# CONFIG_TARGET_octeontx is not set
# CONFIG_TARGET_oxnas is not set
# CONFIG_TARGET_armvirt is not set
# CONFIG_TARGET_ipq40xx is not set
# CONFIG_TARGET_ipq806x is not set
# CONFIG_TARGET_ipq807x is not set
# CONFIG_TARGET_rockchip is not set
# CONFIG_TARGET_samsung is not set
# CONFIG_TARGET_arc770 is not set
# CONFIG_TARGET_archs38 is not set
# CONFIG_TARGET_omap is not set
# CONFIG_TARGET_uml is not set
# CONFIG_TARGET_zynq is not set
# CONFIG_TARGET_x86 is not set
# CONFIG_TARGET_ramips_mt7620 is not set
CONFIG_TARGET_ramips_mt7621=y
# CONFIG_TARGET_ramips_mt76x8 is not set
# CONFIG_TARGET_ramips_rt288x is not set
# CONFIG_TARGET_ramips_rt305x is not set
# CONFIG_TARGET_ramips_rt3883 is not set
# CONFIG_TARGET_MULTI_PROFILE is not set
# CONFIG_TARGET_ramips_mt7621_Default is not set
# CONFIG_TARGET_ramips_mt7621_DEVICE_adslr_g7 is not set
# CONFIG_TARGET_ramips_mt7621_DEVICE_afoundry_ew1200 is not set
# CONFIG_TARGET_ramips_mt7621_DEVICE_alfa-network_quad-e4g is not set
# CONFIG_TARGET_ramips_mt7621_DEVICE_asus_rt-ac57u is not set
# CONFIG_TARGET_ramips_mt7621_DEVICE_asus_rt-ac65p is not set
# CONFIG_TARGET_ramips_mt7621_DEVICE_asus_rt-ac85p is not set
# CONFIG_TARGET_ramips_mt7621_DEVICE_asiarf_ap7621-001 is not set
# CONFIG_TARGET_ramips_mt7621_DEVICE_asiarf_ap7621-nv1 is not set
# CONFIG_TARGET_ramips_mt7621_DEVICE_buffalo_wsr-1166dhp is not set
# CONFIG_TARGET_ramips_mt7621_DEVICE_buffalo_wsr-2533dhpl is not set
# CONFIG_TARGET_ramips_mt7621_DEVICE_buffalo_wsr-600dhp is not set
# CONFIG_TARGET_ramips_mt7621_DEVICE_xzwifi_creativebox-v1 is not set
# CONFIG_TARGET_ramips_mt7621_DEVICE_dlink_dir-860l-b1 is not set
# CONFIG_TARGET_ramips_mt7621_DEVICE_dlink_dir-867-a1 is not set
# CONFIG_TARGET_ramips_mt7621_DEVICE_dlink_dir-878-a1 is not set
# CONFIG_TARGET_ramips_mt7621_DEVICE_dlink_dir-882-a1 is not set
# CONFIG_TARGET_ramips_mt7621_DEVICE_elecom_wrc-1167ghbk2-s is not set
# CONFIG_TARGET_ramips_mt7621_DEVICE_elecom_wrc-1900gst is not set
# CONFIG_TARGET_ramips_mt7621_DEVICE_elecom_wrc-2533gst is not set
# CONFIG_TARGET_ramips_mt7621_DEVICE_elecom_wrc-2533gst2 is not set
# CONFIG_TARGET_ramips_mt7621_DEVICE_edimax_rg21s is not set
# CONFIG_TARGET_ramips_mt7621_DEVICE_edimax_ra21s is not set
# CONFIG_TARGET_ramips_mt7621_DEVICE_firefly_firewrt is not set
CONFIG_TARGET_ramips_mt7621_DEVICE_glinet_gl-mt1300=y
# CONFIG_TARGET_ramips_mt7621_DEVICE_gehua_ghl-r-001 is not set
# CONFIG_TARGET_ramips_mt7621_DEVICE_gnubee_gb-pc1 is not set
# CONFIG_TARGET_ramips_mt7621_DEVICE_gnubee_gb-pc2 is not set
# CONFIG_TARGET_ramips_mt7621_DEVICE_hiwifi_hc5962 is not set
# CONFIG_TARGET_ramips_mt7621_DEVICE_iodata_wn-ax1167gr is not set
# CONFIG_TARGET_ramips_mt7621_DEVICE_iodata_wn-ax1167gr2 is not set
# CONFIG_TARGET_ramips_mt7621_DEVICE_iodata_wn-ax2033gr is not set
# CONFIG_TARGET_ramips_mt7621_DEVICE_iodata_wn-dx1167r is not set
# CONFIG_TARGET_ramips_mt7621_DEVICE_iodata_wn-gx300gr is not set
# CONFIG_TARGET_ramips_mt7621_DEVICE_iodata_wnpr2600g is not set
# CONFIG_TARGET_ramips_mt7621_DEVICE_jcg_jhr-ac876m is not set
# CONFIG_TARGET_ramips_mt7621_DEVICE_jcg_y2 is not set
# CONFIG_TARGET_ramips_mt7621_DEVICE_jdcloud_re-sp-01b is not set
# CONFIG_TARGET_ramips_mt7621_DEVICE_linksys_ea7500-v2 is not set
# CONFIG_TARGET_ramips_mt7621_DEVICE_linksys_re6500 is not set
# CONFIG_TARGET_ramips_mt7621_DEVICE_mqmaker_witi is not set
# CONFIG_TARGET_ramips_mt7621_DEVICE_mtc_wr1201 is not set
# CONFIG_TARGET_ramips_mt7621_DEVICE_mediatek_mt7621-eval-board is not set
# CONFIG_TARGET_ramips_mt7621_DEVICE_mediatek_ap-mt7621a-v60 is not set
# CONFIG_TARGET_ramips_mt7621_DEVICE_mikrotik_routerboard-750gr3 is not set
# CONFIG_TARGET_ramips_mt7621_DEVICE_mikrotik_routerboard-m11g is not set
# CONFIG_TARGET_ramips_mt7621_DEVICE_mikrotik_routerboard-m33g is not set
# CONFIG_TARGET_ramips_mt7621_DEVICE_motorola_mr2600 is not set
# CONFIG_TARGET_ramips_mt7621_DEVICE_netgear_ex6150 is not set
# CONFIG_TARGET_ramips_mt7621_DEVICE_netgear_r6700-v2 is not set
# CONFIG_TARGET_ramips_mt7621_DEVICE_netgear_r6220 is not set
# CONFIG_TARGET_ramips_mt7621_DEVICE_netgear_r6260 is not set
# CONFIG_TARGET_ramips_mt7621_DEVICE_netgear_r6350 is not set
# CONFIG_TARGET_ramips_mt7621_DEVICE_netgear_r6800 is not set
# CONFIG_TARGET_ramips_mt7621_DEVICE_netgear_r6850 is not set
# CONFIG_TARGET_ramips_mt7621_DEVICE_netgear_wac104 is not set
# CONFIG_TARGET_ramips_mt7621_DEVICE_netgear_wac124 is not set
# CONFIG_TARGET_ramips_mt7621_DEVICE_netgear_wndr3700-v5 is not set
# CONFIG_TARGET_ramips_mt7621_DEVICE_netis_wf2881 is not set
# CONFIG_TARGET_ramips_mt7621_DEVICE_lenovo_newifi-d1 is not set
# CONFIG_TARGET_ramips_mt7621_DEVICE_d-team_newifi-d2 is not set
# CONFIG_TARGET_ramips_mt7621_DEVICE_d-team_pbr-m1 is not set
# CONFIG_TARGET_ramips_mt7621_DEVICE_phicomm_k2p is not set
# CONFIG_TARGET_ramips_mt7621_DEVICE_planex_vr500 is not set
# CONFIG_TARGET_ramips_mt7621_DEVICE_storylink_sap-g3200u3 is not set
# CONFIG_TARGET_ramips_mt7621_DEVICE_samknows_whitebox-v8 is not set
# CONFIG_TARGET_ramips_mt7621_DEVICE_totolink_a7000r is not set
# CONFIG_TARGET_ramips_mt7621_DEVICE_tplink_re350-v1 is not set
# CONFIG_TARGET_ramips_mt7621_DEVICE_tplink_re650-v1 is not set
# CONFIG_TARGET_ramips_mt7621_DEVICE_telco-electronics_x1 is not set
# CONFIG_TARGET_ramips_mt7621_DEVICE_thunder_timecloud is not set
# CONFIG_TARGET_ramips_mt7621_DEVICE_ubnt_edgerouter-x is not set
# CONFIG_TARGET_ramips_mt7621_DEVICE_ubnt_edgerouter-x-sfp is not set
# CONFIG_TARGET_ramips_mt7621_DEVICE_ubnt_unifi-nanohd is not set
# CONFIG_TARGET_ramips_mt7621_DEVICE_unielec_u7621-06-16m is not set
# CONFIG_TARGET_ramips_mt7621_DEVICE_unielec_u7621-06-64m is not set
# CONFIG_TARGET_ramips_mt7621_DEVICE_wevo_11acnas is not set
# CONFIG_TARGET_ramips_mt7621_DEVICE_wevo_w2914ns-v2 is not set
# CONFIG_TARGET_ramips_mt7621_DEVICE_xiaoyu_xy-c5 is not set
# CONFIG_TARGET_ramips_mt7621_DEVICE_xiaomi_mir3p is not set
# CONFIG_TARGET_ramips_mt7621_DEVICE_xiaomi_mir3g is not set
# CONFIG_TARGET_ramips_mt7621_DEVICE_xiaomi_mir3g-v2 is not set
# CONFIG_TARGET_ramips_mt7621_DEVICE_xiaomi_mir4 is not set
# CONFIG_TARGET_ramips_mt7621_DEVICE_xiaomi_mi-router-ac2100 is not set
# CONFIG_TARGET_ramips_mt7621_DEVICE_xiaomi_redmi-router-ac2100 is not set
# CONFIG_TARGET_ramips_mt7621_DEVICE_youhua_wr1200js is not set
# CONFIG_TARGET_ramips_mt7621_DEVICE_youku_yk-l2 is not set
# CONFIG_TARGET_ramips_mt7621_DEVICE_zio_freezio is not set
# CONFIG_TARGET_ramips_mt7621_DEVICE_zbtlink_zbt-we1326 is not set
# CONFIG_TARGET_ramips_mt7621_DEVICE_zbtlink_zbt-we3526 is not set
# CONFIG_TARGET_ramips_mt7621_DEVICE_zbtlink_zbt-wg2626 is not set
# CONFIG_TARGET_ramips_mt7621_DEVICE_zbtlink_zbt-wg3526-16m is not set
# CONFIG_TARGET_ramips_mt7621_DEVICE_zbtlink_zbt-wg3526-32m is not set
# CONFIG_TARGET_ramips_mt7621_DEVICE_iptime_a6ns-m is not set
# CONFIG_TARGET_ramips_mt7621_DEVICE_iptime_a8004t is not set
CONFIG_HAS_SUBTARGETS=y
CONFIG_HAS_DEVICES=y
CONFIG_TARGET_BOARD="ramips"
CONFIG_TARGET_SUBTARGET="mt7621"
CONFIG_TARGET_PROFILE="DEVICE_glinet_gl-mt1300"
CONFIG_TARGET_ARCH_PACKAGES="mipsel_24kc"
CONFIG_DEFAULT_TARGET_OPTIMIZATION="-Os -pipe -mno-branch-likely -mips32r2 -mtune=24kc"
CONFIG_CPU_TYPE="24kc"
CONFIG_LINUX_5_4=y
CONFIG_DEFAULT_base-files=y
CONFIG_DEFAULT_block-mount=y
CONFIG_DEFAULT_busybox=y
CONFIG_DEFAULT_ca-certificates=y
CONFIG_DEFAULT_coremark=y
CONFIG_DEFAULT_ddns-scripts_aliyun=y
CONFIG_DEFAULT_ddns-scripts_dnspod=y
CONFIG_DEFAULT_default-settings=y
CONFIG_DEFAULT_dnsmasq-full=y
CONFIG_DEFAULT_dropbear=y
CONFIG_DEFAULT_firewall=y
CONFIG_DEFAULT_fstools=y
CONFIG_DEFAULT_iptables=y
CONFIG_DEFAULT_kmod-gpio-button-hotplug=y
CONFIG_DEFAULT_kmod-ipt-raw=y
CONFIG_DEFAULT_kmod-leds-gpio=y
CONFIG_DEFAULT_kmod-mt7615-firmware=y
CONFIG_DEFAULT_kmod-mt7615e=y
CONFIG_DEFAULT_kmod-nf-nathelper=y
CONFIG_DEFAULT_kmod-nf-nathelper-extra=y
CONFIG_DEFAULT_kmod-usb3=y
CONFIG_DEFAULT_libc=y
CONFIG_DEFAULT_libgcc=y
CONFIG_DEFAULT_libustream-openssl=y
CONFIG_DEFAULT_logd=y
CONFIG_DEFAULT_luci=y
CONFIG_DEFAULT_luci-app-accesscontrol=y
CONFIG_DEFAULT_luci-app-arpbind=y
CONFIG_DEFAULT_luci-app-autoreboot=y
CONFIG_DEFAULT_luci-app-cpufreq=y
CONFIG_DEFAULT_luci-app-ddns=y
CONFIG_DEFAULT_luci-app-filetransfer=y
CONFIG_DEFAULT_luci-app-flowoffload=y
CONFIG_DEFAULT_luci-app-nlbwmon=y
CONFIG_DEFAULT_luci-app-ramfree=y
CONFIG_DEFAULT_luci-app-ssr-plus=y
CONFIG_DEFAULT_luci-app-unblockmusic=y
CONFIG_DEFAULT_luci-app-upnp=y
CONFIG_DEFAULT_luci-app-vlmcsd=y
CONFIG_DEFAULT_luci-app-vsftpd=y
CONFIG_DEFAULT_luci-app-webadmin=y
CONFIG_DEFAULT_luci-app-wol=y
CONFIG_DEFAULT_mtd=y
CONFIG_DEFAULT_netifd=y
CONFIG_DEFAULT_opkg=y
CONFIG_DEFAULT_ppp=y
CONFIG_DEFAULT_ppp-mod-pppoe=y
CONFIG_DEFAULT_swconfig=y
CONFIG_DEFAULT_uci=y
CONFIG_DEFAULT_uclient-fetch=y
CONFIG_DEFAULT_urandom-seed=y
CONFIG_DEFAULT_urngd=y
CONFIG_DEFAULT_wget=y
CONFIG_AUDIO_SUPPORT=y
CONFIG_GPIO_SUPPORT=y
CONFIG_PCI_SUPPORT=y
CONFIG_USB_SUPPORT=y
CONFIG_RTC_SUPPORT=y
CONFIG_USES_DEVICETREE=y
CONFIG_USES_INITRAMFS=y
CONFIG_USES_SQUASHFS=y
CONFIG_USES_MINOR=y
CONFIG_HAS_MIPS16=y
CONFIG_NAND_SUPPORT=y
CONFIG_mipsel=y
CONFIG_ARCH="mipsel"
#
# Target Images
#
CONFIG_TARGET_ROOTFS_INITRAMFS=y
# CONFIG_TARGET_INITRAMFS_COMPRESSION_NONE is not set
# CONFIG_TARGET_INITRAMFS_COMPRESSION_GZIP is not set
# CONFIG_TARGET_INITRAMFS_COMPRESSION_BZIP2 is not set
CONFIG_TARGET_INITRAMFS_COMPRESSION_LZMA=y
# CONFIG_TARGET_INITRAMFS_COMPRESSION_LZO is not set
# CONFIG_TARGET_INITRAMFS_COMPRESSION_LZ4 is not set
# CONFIG_TARGET_INITRAMFS_COMPRESSION_XZ is not set
CONFIG_EXTERNAL_CPIO=""
# CONFIG_TARGET_INITRAMFS_FORCE is not set
#
# Root filesystem archives
#
# CONFIG_TARGET_ROOTFS_CPIOGZ is not set
# CONFIG_TARGET_ROOTFS_TARGZ is not set
#
# Root filesystem images
#
# CONFIG_TARGET_ROOTFS_EXT4FS is not set
CONFIG_TARGET_ROOTFS_SQUASHFS=y
CONFIG_TARGET_SQUASHFS_BLOCK_SIZE=256
CONFIG_TARGET_UBIFS_FREE_SPACE_FIXUP=y
CONFIG_TARGET_UBIFS_JOURNAL_SIZE=""
#
# Image Options
#
# end of Target Images
#
# Global build settings
#
# CONFIG_JSON_OVERVIEW_IMAGE_INFO is not set
# CONFIG_ALL_NONSHARED is not set
# CONFIG_ALL_KMODS is not set
# CONFIG_ALL is not set
# CONFIG_BUILDBOT is not set
CONFIG_SIGNED_PACKAGES=y
CONFIG_SIGNATURE_CHECK=y
#
# General build options
#
# CONFIG_DISPLAY_SUPPORT is not set
# CONFIG_BUILD_PATENTED is not set
# CONFIG_BUILD_NLS is not set
CONFIG_SHADOW_PASSWORDS=y
# CONFIG_CLEAN_IPKG is not set
# CONFIG_IPK_FILES_CHECKSUMS is not set
# CONFIG_INCLUDE_CONFIG is not set
# CONFIG_COLLECT_KERNEL_DEBUG is not set
#
# Kernel build options
#
CONFIG_KERNEL_BUILD_USER=""
CONFIG_KERNEL_BUILD_DOMAIN=""
CONFIG_KERNEL_PRINTK=y
CONFIG_KERNEL_CRASHLOG=y
CONFIG_KERNEL_SWAP=y
CONFIG_KERNEL_DEBUG_FS=y
CONFIG_KERNEL_MIPS_FPU_EMULATOR=y
CONFIG_KERNEL_MIPS_FP_SUPPORT=y
# CONFIG_KERNEL_PERF_EVENTS is not set
# CONFIG_KERNEL_PROFILING is not set
# CONFIG_KERNEL_UBSAN is not set
# CONFIG_KERNEL_KCOV is not set
# CONFIG_KERNEL_TASKSTATS is not set
CONFIG_KERNEL_KALLSYMS=y
# CONFIG_KERNEL_FTRACE is not set
CONFIG_KERNEL_DEBUG_KERNEL=y
CONFIG_KERNEL_DEBUG_INFO=y
# CONFIG_KERNEL_DYNAMIC_DEBUG is not set
# CONFIG_KERNEL_KPROBES is not set
CONFIG_KERNEL_AIO=y
CONFIG_KERNEL_FHANDLE=y
CONFIG_KERNEL_FANOTIFY=y
# CONFIG_KERNEL_BLK_DEV_BSG is not set
CONFIG_KERNEL_MAGIC_SYSRQ=y
# CONFIG_KERNEL_DEBUG_PINCTRL is not set
# CONFIG_KERNEL_DEBUG_GPIO is not set
CONFIG_KERNEL_COREDUMP=y
CONFIG_KERNEL_ELF_CORE=y
# CONFIG_KERNEL_PROVE_LOCKING is not set
# CONFIG_KERNEL_LOCKUP_DETECTOR is not set
# CONFIG_KERNEL_DETECT_HUNG_TASK is not set
# CONFIG_KERNEL_WQ_WATCHDOG is not set
# CONFIG_KERNEL_DEBUG_ATOMIC_SLEEP is not set
# CONFIG_KERNEL_DEBUG_VM is not set
CONFIG_KERNEL_PRINTK_TIME=y
# CONFIG_KERNEL_SLABINFO is not set
# CONFIG_KERNEL_PROC_PAGE_MONITOR is not set
# CONFIG_KERNEL_KEXEC is not set
# CONFIG_USE_RFKILL is not set
# CONFIG_USE_SPARSE is not set
# CONFIG_KERNEL_DEVTMPFS is not set
# CONFIG_KERNEL_KEYS is not set
CONFIG_KERNEL_CGROUPS=y
# CONFIG_KERNEL_CGROUP_DEBUG is not set
CONFIG_KERNEL_FREEZER=y
CONFIG_KERNEL_CGROUP_FREEZER=y
CONFIG_KERNEL_CGROUP_DEVICE=y
CONFIG_KERNEL_CGROUP_PIDS=y
CONFIG_KERNEL_CPUSETS=y
# CONFIG_KERNEL_PROC_PID_CPUSET is not set
CONFIG_KERNEL_CGROUP_CPUACCT=y
CONFIG_KERNEL_RESOURCE_COUNTERS=y
CONFIG_KERNEL_MM_OWNER=y
CONFIG_KERNEL_MEMCG=y
# CONFIG_KERNEL_MEMCG_SWAP is not set
CONFIG_KERNEL_MEMCG_KMEM=y
# CONFIG_KERNEL_CGROUP_PERF is not set
CONFIG_KERNEL_CGROUP_SCHED=y
CONFIG_KERNEL_FAIR_GROUP_SCHED=y
# CONFIG_KERNEL_CFS_BANDWIDTH is not set
CONFIG_KERNEL_RT_GROUP_SCHED=y
CONFIG_KERNEL_BLK_CGROUP=y
# CONFIG_KERNEL_CFQ_GROUP_IOSCHED is not set
# CONFIG_KERNEL_BLK_DEV_THROTTLING is not set
# CONFIG_KERNEL_DEBUG_BLK_CGROUP is not set
CONFIG_KERNEL_NET_CLS_CGROUP=y
CONFIG_KERNEL_CGROUP_NET_PRIO=y
CONFIG_KERNEL_NAMESPACES=y
CONFIG_KERNEL_UTS_NS=y
CONFIG_KERNEL_IPC_NS=y
CONFIG_KERNEL_USER_NS=y
CONFIG_KERNEL_PID_NS=y
CONFIG_KERNEL_NET_NS=y
CONFIG_KERNEL_DEVPTS_MULTIPLE_INSTANCES=y
CONFIG_KERNEL_POSIX_MQUEUE=y
CONFIG_KERNEL_SECCOMP_FILTER=y
CONFIG_KERNEL_SECCOMP=y
CONFIG_KERNEL_IP_MROUTE=y
CONFIG_KERNEL_IPV6=y
CONFIG_KERNEL_IPV6_MULTIPLE_TABLES=y
CONFIG_KERNEL_IPV6_SUBTREES=y
CONFIG_KERNEL_IPV6_MROUTE=y
# CONFIG_KERNEL_IPV6_PIMSM_V2 is not set
# CONFIG_KERNEL_IP_PNP is not set
#
# Filesystem ACL and attr support options
#
# CONFIG_USE_FS_ACL_ATTR is not set
# CONFIG_KERNEL_FS_POSIX_ACL is not set
# CONFIG_KERNEL_BTRFS_FS_POSIX_ACL is not set
# CONFIG_KERNEL_EXT4_FS_POSIX_ACL is not set
# CONFIG_KERNEL_F2FS_FS_POSIX_ACL is not set
# CONFIG_KERNEL_JFFS2_FS_POSIX_ACL is not set
# CONFIG_KERNEL_TMPFS_POSIX_ACL is not set
# CONFIG_KERNEL_CIFS_ACL is not set
# CONFIG_KERNEL_HFS_FS_POSIX_ACL is not set
# CONFIG_KERNEL_HFSPLUS_FS_POSIX_ACL is not set
# CONFIG_KERNEL_NFS_ACL_SUPPORT is not set
# CONFIG_KERNEL_NFS_V3_ACL_SUPPORT is not set
# CONFIG_KERNEL_NFSD_V2_ACL_SUPPORT is not set
# CONFIG_KERNEL_NFSD_V3_ACL_SUPPORT is not set
# CONFIG_KERNEL_REISER_FS_POSIX_ACL is not set
# CONFIG_KERNEL_XFS_POSIX_ACL is not set
# CONFIG_KERNEL_JFS_POSIX_ACL is not set
# end of Filesystem ACL and attr support options
# CONFIG_KERNEL_DEVMEM is not set
# CONFIG_KERNEL_DEVKMEM is not set
CONFIG_KERNEL_SQUASHFS_FRAGMENT_CACHE_SIZE=3
CONFIG_KERNEL_CC_OPTIMIZE_FOR_PERFORMANCE=y
# CONFIG_KERNEL_CC_OPTIMIZE_FOR_SIZE is not set
# end of Kernel build options
#
# Package build options
#
# CONFIG_DEBUG is not set
CONFIG_IPV6=y
#
# Stripping options
#
# CONFIG_NO_STRIP is not set
# CONFIG_USE_STRIP is not set
CONFIG_USE_SSTRIP=y
# CONFIG_STRIP_KERNEL_EXPORTS is not set
# CONFIG_USE_MKLIBS is not set
CONFIG_USE_UCLIBCXX=y
# CONFIG_USE_LIBCXX is not set
# CONFIG_USE_LIBSTDCXX is not set
#
# Hardening build options
#
CONFIG_PKG_CHECK_FORMAT_SECURITY=y
# CONFIG_PKG_ASLR_PIE_NONE is not set
CONFIG_PKG_ASLR_PIE_REGULAR=y
# CONFIG_PKG_ASLR_PIE_ALL is not set
# CONFIG_PKG_CC_STACKPROTECTOR_NONE is not set
CONFIG_PKG_CC_STACKPROTECTOR_REGULAR=y
# CONFIG_KERNEL_CC_STACKPROTECTOR_NONE is not set
CONFIG_KERNEL_CC_STACKPROTECTOR_REGULAR=y
# CONFIG_KERNEL_CC_STACKPROTECTOR_STRONG is not set
CONFIG_KERNEL_STACKPROTECTOR=y
# CONFIG_KERNEL_STACKPROTECTOR_STRONG is not set
# CONFIG_PKG_FORTIFY_SOURCE_NONE is not set
CONFIG_PKG_FORTIFY_SOURCE_1=y
# CONFIG_PKG_FORTIFY_SOURCE_2 is not set
# CONFIG_PKG_RELRO_NONE is not set
# CONFIG_PKG_RELRO_PARTIAL is not set
CONFIG_PKG_RELRO_FULL=y
# end of Global build settings
# CONFIG_DEVEL is not set
# CONFIG_BROKEN is not set
CONFIG_BINARY_FOLDER=""
CONFIG_DOWNLOAD_FOLDER=""
CONFIG_LOCALMIRROR=""
CONFIG_AUTOREBUILD=y
# CONFIG_AUTOREMOVE is not set
CONFIG_BUILD_SUFFIX=""
CONFIG_TARGET_ROOTFS_DIR=""
# CONFIG_CCACHE is not set
CONFIG_EXTERNAL_KERNEL_TREE=""
CONFIG_KERNEL_GIT_CLONE_URI=""
CONFIG_BUILD_LOG_DIR=""
CONFIG_EXTRA_OPTIMIZATION="-fno-caller-saves -fno-plt"
CONFIG_TARGET_OPTIMIZATION="-Os -pipe -mno-branch-likely -mips32r2 -mtune=24kc"
CONFIG_SOFT_FLOAT=y
CONFIG_USE_MIPS16=y
# CONFIG_EXTRA_TARGET_ARCH is not set
CONFIG_EXTRA_BINUTILS_CONFIG_OPTIONS=""
CONFIG_EXTRA_GCC_CONFIG_OPTIONS=""
# CONFIG_GCC_DEFAULT_PIE is not set
# CONFIG_GCC_DEFAULT_SSP is not set
# CONFIG_SJLJ_EXCEPTIONS is not set
# CONFIG_INSTALL_GFORTRAN is not set
CONFIG_GDB=y
CONFIG_USE_MUSL=y
CONFIG_SSP_SUPPORT=y
CONFIG_BINUTILS_VERSION_2_31_1=y
CONFIG_BINUTILS_VERSION="2.31.1"
CONFIG_GCC_VERSION="8.4.0"
# CONFIG_GCC_USE_IREMAP is not set
CONFIG_LIBC="musl"
CONFIG_TARGET_SUFFIX="musl"
# CONFIG_IB is not set
# CONFIG_SDK is not set
# CONFIG_MAKE_TOOLCHAIN is not set
# CONFIG_IMAGEOPT is not set
# CONFIG_PREINITOPT is not set
CONFIG_TARGET_PREINIT_SUPPRESS_STDERR=y
# CONFIG_TARGET_PREINIT_DISABLE_FAILSAFE is not set
CONFIG_TARGET_PREINIT_TIMEOUT=2
# CONFIG_TARGET_PREINIT_SHOW_NETMSG is not set
# CONFIG_TARGET_PREINIT_SUPPRESS_FAILSAFE_NETMSG is not set
CONFIG_TARGET_PREINIT_IFNAME=""
CONFIG_TARGET_PREINIT_IP="192.168.1.1"
CONFIG_TARGET_PREINIT_NETMASK="255.255.255.0"
CONFIG_TARGET_PREINIT_BROADCAST="192.168.1.255"
# CONFIG_INITOPT is not set
CONFIG_TARGET_INIT_PATH="/usr/sbin:/usr/bin:/sbin:/bin"
CONFIG_TARGET_INIT_ENV=""
CONFIG_TARGET_INIT_CMD="/sbin/init"
CONFIG_TARGET_INIT_SUPPRESS_STDERR=y
# CONFIG_VERSIONOPT is not set
CONFIG_PER_FEED_REPO=y
CONFIG_FEED_packages=y
CONFIG_FEED_luci=y
CONFIG_FEED_routing=y
CONFIG_FEED_telephony=y
CONFIG_FEED_freifunk=y
#
# Base system
#
# CONFIG_PACKAGE_attendedsysupgrade-common is not set
# CONFIG_PACKAGE_auc is not set
CONFIG_PACKAGE_base-files=y
CONFIG_PACKAGE_block-mount=y
# CONFIG_PACKAGE_blockd is not set
# CONFIG_PACKAGE_bridge is not set
CONFIG_PACKAGE_busybox=y
# CONFIG_BUSYBOX_CUSTOM is not set
CONFIG_BUSYBOX_DEFAULT_HAVE_DOT_CONFIG=y
# CONFIG_BUSYBOX_DEFAULT_DESKTOP is not set
# CONFIG_BUSYBOX_DEFAULT_EXTRA_COMPAT is not set
# CONFIG_BUSYBOX_DEFAULT_FEDORA_COMPAT is not set
CONFIG_BUSYBOX_DEFAULT_INCLUDE_SUSv2=y
CONFIG_BUSYBOX_DEFAULT_LONG_OPTS=y
CONFIG_BUSYBOX_DEFAULT_SHOW_USAGE=y
CONFIG_BUSYBOX_DEFAULT_FEATURE_VERBOSE_USAGE=y
# CONFIG_BUSYBOX_DEFAULT_FEATURE_COMPRESS_USAGE is not set
CONFIG_BUSYBOX_DEFAULT_LFS=y
# CONFIG_BUSYBOX_DEFAULT_PAM is not set
CONFIG_BUSYBOX_DEFAULT_FEATURE_DEVPTS=y
# CONFIG_BUSYBOX_DEFAULT_FEATURE_UTMP is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_WTMP is not set
CONFIG_BUSYBOX_DEFAULT_FEATURE_PIDFILE=y
CONFIG_BUSYBOX_DEFAULT_PID_FILE_PATH="/var/run"
# CONFIG_BUSYBOX_DEFAULT_BUSYBOX is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_SHOW_SCRIPT is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_INSTALLER is not set
# CONFIG_BUSYBOX_DEFAULT_INSTALL_NO_USR is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_SUID is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_SUID_CONFIG is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_SUID_CONFIG_QUIET is not set
CONFIG_BUSYBOX_DEFAULT_FEATURE_PREFER_APPLETS=y
CONFIG_BUSYBOX_DEFAULT_BUSYBOX_EXEC_PATH="/proc/self/exe"
# CONFIG_BUSYBOX_DEFAULT_SELINUX is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_CLEAN_UP is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_SYSLOG_INFO is not set
CONFIG_BUSYBOX_DEFAULT_FEATURE_SYSLOG=y
CONFIG_BUSYBOX_DEFAULT_PLATFORM_LINUX=y
# CONFIG_BUSYBOX_DEFAULT_STATIC is not set
# CONFIG_BUSYBOX_DEFAULT_PIE is not set
# CONFIG_BUSYBOX_DEFAULT_NOMMU is not set
# CONFIG_BUSYBOX_DEFAULT_BUILD_LIBBUSYBOX is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_LIBBUSYBOX_STATIC is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_INDIVIDUAL is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_SHARED_BUSYBOX is not set
CONFIG_BUSYBOX_DEFAULT_CROSS_COMPILER_PREFIX=""
CONFIG_BUSYBOX_DEFAULT_SYSROOT=""
CONFIG_BUSYBOX_DEFAULT_EXTRA_CFLAGS=""
CONFIG_BUSYBOX_DEFAULT_EXTRA_LDFLAGS=""
CONFIG_BUSYBOX_DEFAULT_EXTRA_LDLIBS=""
# CONFIG_BUSYBOX_DEFAULT_USE_PORTABLE_CODE is not set
# CONFIG_BUSYBOX_DEFAULT_STACK_OPTIMIZATION_386 is not set
CONFIG_BUSYBOX_DEFAULT_INSTALL_APPLET_SYMLINKS=y
# CONFIG_BUSYBOX_DEFAULT_INSTALL_APPLET_HARDLINKS is not set
# CONFIG_BUSYBOX_DEFAULT_INSTALL_APPLET_SCRIPT_WRAPPERS is not set
# CONFIG_BUSYBOX_DEFAULT_INSTALL_APPLET_DONT is not set
# CONFIG_BUSYBOX_DEFAULT_INSTALL_SH_APPLET_SYMLINK is not set
# CONFIG_BUSYBOX_DEFAULT_INSTALL_SH_APPLET_HARDLINK is not set
# CONFIG_BUSYBOX_DEFAULT_INSTALL_SH_APPLET_SCRIPT_WRAPPER is not set
CONFIG_BUSYBOX_DEFAULT_PREFIX="./_install"
# CONFIG_BUSYBOX_DEFAULT_DEBUG is not set
# CONFIG_BUSYBOX_DEFAULT_DEBUG_PESSIMIZE is not set
# CONFIG_BUSYBOX_DEFAULT_DEBUG_SANITIZE is not set
# CONFIG_BUSYBOX_DEFAULT_UNIT_TEST is not set
# CONFIG_BUSYBOX_DEFAULT_WERROR is not set
CONFIG_BUSYBOX_DEFAULT_NO_DEBUG_LIB=y
# CONFIG_BUSYBOX_DEFAULT_DMALLOC is not set
# CONFIG_BUSYBOX_DEFAULT_EFENCE is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_USE_BSS_TAIL is not set
# CONFIG_BUSYBOX_DEFAULT_FLOAT_DURATION is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_RTMINMAX is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_RTMINMAX_USE_LIBC_DEFINITIONS is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_BUFFERS_USE_MALLOC is not set
CONFIG_BUSYBOX_DEFAULT_FEATURE_BUFFERS_GO_ON_STACK=y
# CONFIG_BUSYBOX_DEFAULT_FEATURE_BUFFERS_GO_IN_BSS is not set
CONFIG_BUSYBOX_DEFAULT_PASSWORD_MINLEN=6
CONFIG_BUSYBOX_DEFAULT_MD5_SMALL=1
CONFIG_BUSYBOX_DEFAULT_SHA3_SMALL=1
CONFIG_BUSYBOX_DEFAULT_FEATURE_FAST_TOP=y
# CONFIG_BUSYBOX_DEFAULT_FEATURE_ETC_NETWORKS is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_ETC_SERVICES is not set
CONFIG_BUSYBOX_DEFAULT_FEATURE_EDITING=y
CONFIG_BUSYBOX_DEFAULT_FEATURE_EDITING_MAX_LEN=512
# CONFIG_BUSYBOX_DEFAULT_FEATURE_EDITING_VI is not set
CONFIG_BUSYBOX_DEFAULT_FEATURE_EDITING_HISTORY=256
# CONFIG_BUSYBOX_DEFAULT_FEATURE_EDITING_SAVEHISTORY is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_EDITING_SAVE_ON_EXIT is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_REVERSE_SEARCH is not set
CONFIG_BUSYBOX_DEFAULT_FEATURE_TAB_COMPLETION=y
# CONFIG_BUSYBOX_DEFAULT_FEATURE_USERNAME_COMPLETION is not set
CONFIG_BUSYBOX_DEFAULT_FEATURE_EDITING_FANCY_PROMPT=y
# CONFIG_BUSYBOX_DEFAULT_FEATURE_EDITING_WINCH is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_EDITING_ASK_TERMINAL is not set
# CONFIG_BUSYBOX_DEFAULT_LOCALE_SUPPORT is not set
# CONFIG_BUSYBOX_DEFAULT_UNICODE_SUPPORT is not set
# CONFIG_BUSYBOX_DEFAULT_UNICODE_USING_LOCALE is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_CHECK_UNICODE_IN_ENV is not set
CONFIG_BUSYBOX_DEFAULT_SUBST_WCHAR=0
CONFIG_BUSYBOX_DEFAULT_LAST_SUPPORTED_WCHAR=0
# CONFIG_BUSYBOX_DEFAULT_UNICODE_COMBINING_WCHARS is not set
# CONFIG_BUSYBOX_DEFAULT_UNICODE_WIDE_WCHARS is not set
# CONFIG_BUSYBOX_DEFAULT_UNICODE_BIDI_SUPPORT is not set
# CONFIG_BUSYBOX_DEFAULT_UNICODE_NEUTRAL_TABLE is not set
# CONFIG_BUSYBOX_DEFAULT_UNICODE_PRESERVE_BROKEN is not set
CONFIG_BUSYBOX_DEFAULT_FEATURE_NON_POSIX_CP=y
# CONFIG_BUSYBOX_DEFAULT_FEATURE_VERBOSE_CP_MESSAGE is not set
CONFIG_BUSYBOX_DEFAULT_FEATURE_USE_SENDFILE=y
CONFIG_BUSYBOX_DEFAULT_FEATURE_COPYBUF_KB=4
# CONFIG_BUSYBOX_DEFAULT_FEATURE_SKIP_ROOTFS is not set
CONFIG_BUSYBOX_DEFAULT_MONOTONIC_SYSCALL=y
CONFIG_BUSYBOX_DEFAULT_IOCTL_HEX2STR_ERROR=y
# CONFIG_BUSYBOX_DEFAULT_FEATURE_HWIB is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_SEAMLESS_XZ is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_SEAMLESS_LZMA is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_SEAMLESS_BZ2 is not set
CONFIG_BUSYBOX_DEFAULT_FEATURE_SEAMLESS_GZ=y
# CONFIG_BUSYBOX_DEFAULT_FEATURE_SEAMLESS_Z is not set
# CONFIG_BUSYBOX_DEFAULT_AR is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_AR_LONG_FILENAMES is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_AR_CREATE is not set
# CONFIG_BUSYBOX_DEFAULT_UNCOMPRESS is not set
CONFIG_BUSYBOX_DEFAULT_GUNZIP=y
CONFIG_BUSYBOX_DEFAULT_ZCAT=y
# CONFIG_BUSYBOX_DEFAULT_FEATURE_GUNZIP_LONG_OPTIONS is not set
CONFIG_BUSYBOX_DEFAULT_BUNZIP2=y
CONFIG_BUSYBOX_DEFAULT_BZCAT=y
# CONFIG_BUSYBOX_DEFAULT_UNLZMA is not set
# CONFIG_BUSYBOX_DEFAULT_LZCAT is not set
# CONFIG_BUSYBOX_DEFAULT_LZMA is not set
# CONFIG_BUSYBOX_DEFAULT_UNXZ is not set
# CONFIG_BUSYBOX_DEFAULT_XZCAT is not set
# CONFIG_BUSYBOX_DEFAULT_XZ is not set
# CONFIG_BUSYBOX_DEFAULT_BZIP2 is not set
CONFIG_BUSYBOX_DEFAULT_BZIP2_SMALL=0
CONFIG_BUSYBOX_DEFAULT_FEATURE_BZIP2_DECOMPRESS=y
# CONFIG_BUSYBOX_DEFAULT_CPIO is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_CPIO_O is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_CPIO_P is not set
# CONFIG_BUSYBOX_DEFAULT_DPKG is not set
# CONFIG_BUSYBOX_DEFAULT_DPKG_DEB is not set
CONFIG_BUSYBOX_DEFAULT_GZIP=y
# CONFIG_BUSYBOX_DEFAULT_FEATURE_GZIP_LONG_OPTIONS is not set
CONFIG_BUSYBOX_DEFAULT_GZIP_FAST=0
# CONFIG_BUSYBOX_DEFAULT_FEATURE_GZIP_LEVELS is not set
CONFIG_BUSYBOX_DEFAULT_FEATURE_GZIP_DECOMPRESS=y
# CONFIG_BUSYBOX_DEFAULT_LZOP is not set
# CONFIG_BUSYBOX_DEFAULT_UNLZOP is not set
# CONFIG_BUSYBOX_DEFAULT_LZOPCAT is not set
# CONFIG_BUSYBOX_DEFAULT_LZOP_COMPR_HIGH is not set
# CONFIG_BUSYBOX_DEFAULT_RPM is not set
# CONFIG_BUSYBOX_DEFAULT_RPM2CPIO is not set
CONFIG_BUSYBOX_DEFAULT_TAR=y
# CONFIG_BUSYBOX_DEFAULT_FEATURE_TAR_LONG_OPTIONS is not set
CONFIG_BUSYBOX_DEFAULT_FEATURE_TAR_CREATE=y
# CONFIG_BUSYBOX_DEFAULT_FEATURE_TAR_AUTODETECT is not set
CONFIG_BUSYBOX_DEFAULT_FEATURE_TAR_FROM=y
# CONFIG_BUSYBOX_DEFAULT_FEATURE_TAR_OLDGNU_COMPATIBILITY is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_TAR_OLDSUN_COMPATIBILITY is not set
CONFIG_BUSYBOX_DEFAULT_FEATURE_TAR_GNU_EXTENSIONS=y
# CONFIG_BUSYBOX_DEFAULT_FEATURE_TAR_TO_COMMAND is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_TAR_UNAME_GNAME is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_TAR_NOPRESERVE_TIME is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_TAR_SELINUX is not set
# CONFIG_BUSYBOX_DEFAULT_UNZIP is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_UNZIP_CDF is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_UNZIP_BZIP2 is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_UNZIP_LZMA is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_UNZIP_XZ is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_LZMA_FAST is not set
CONFIG_BUSYBOX_DEFAULT_BASENAME=y
CONFIG_BUSYBOX_DEFAULT_CAT=y
# CONFIG_BUSYBOX_DEFAULT_FEATURE_CATN is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_CATV is not set
CONFIG_BUSYBOX_DEFAULT_CHGRP=y
CONFIG_BUSYBOX_DEFAULT_CHMOD=y
CONFIG_BUSYBOX_DEFAULT_CHOWN=y
# CONFIG_BUSYBOX_DEFAULT_FEATURE_CHOWN_LONG_OPTIONS is not set
CONFIG_BUSYBOX_DEFAULT_CHROOT=y
# CONFIG_BUSYBOX_DEFAULT_CKSUM is not set
# CONFIG_BUSYBOX_DEFAULT_COMM is not set
CONFIG_BUSYBOX_DEFAULT_CP=y
# CONFIG_BUSYBOX_DEFAULT_FEATURE_CP_LONG_OPTIONS is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_CP_REFLINK is not set
CONFIG_BUSYBOX_DEFAULT_CUT=y
CONFIG_BUSYBOX_DEFAULT_DATE=y
CONFIG_BUSYBOX_DEFAULT_FEATURE_DATE_ISOFMT=y
# CONFIG_BUSYBOX_DEFAULT_FEATURE_DATE_NANO is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_DATE_COMPAT is not set
CONFIG_BUSYBOX_DEFAULT_DD=y
CONFIG_BUSYBOX_DEFAULT_FEATURE_DD_SIGNAL_HANDLING=y
# CONFIG_BUSYBOX_DEFAULT_FEATURE_DD_THIRD_STATUS_LINE is not set
CONFIG_BUSYBOX_DEFAULT_FEATURE_DD_IBS_OBS=y
# CONFIG_BUSYBOX_DEFAULT_FEATURE_DD_STATUS is not set
CONFIG_BUSYBOX_DEFAULT_DF=y
# CONFIG_BUSYBOX_DEFAULT_FEATURE_DF_FANCY is not set
CONFIG_BUSYBOX_DEFAULT_DIRNAME=y
# CONFIG_BUSYBOX_DEFAULT_DOS2UNIX is not set
# CONFIG_BUSYBOX_DEFAULT_UNIX2DOS is not set
CONFIG_BUSYBOX_DEFAULT_DU=y
CONFIG_BUSYBOX_DEFAULT_FEATURE_DU_DEFAULT_BLOCKSIZE_1K=y
CONFIG_BUSYBOX_DEFAULT_ECHO=y
CONFIG_BUSYBOX_DEFAULT_FEATURE_FANCY_ECHO=y
CONFIG_BUSYBOX_DEFAULT_ENV=y
# CONFIG_BUSYBOX_DEFAULT_EXPAND is not set
# CONFIG_BUSYBOX_DEFAULT_UNEXPAND is not set
CONFIG_BUSYBOX_DEFAULT_EXPR=y
CONFIG_BUSYBOX_DEFAULT_EXPR_MATH_SUPPORT_64=y
# CONFIG_BUSYBOX_DEFAULT_FACTOR is not set
CONFIG_BUSYBOX_DEFAULT_FALSE=y
# CONFIG_BUSYBOX_DEFAULT_FOLD is not set
CONFIG_BUSYBOX_DEFAULT_HEAD=y
CONFIG_BUSYBOX_DEFAULT_FEATURE_FANCY_HEAD=y
# CONFIG_BUSYBOX_DEFAULT_HOSTID is not set
CONFIG_BUSYBOX_DEFAULT_ID=y
# CONFIG_BUSYBOX_DEFAULT_GROUPS is not set
# CONFIG_BUSYBOX_DEFAULT_INSTALL is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_INSTALL_LONG_OPTIONS is not set
# CONFIG_BUSYBOX_DEFAULT_LINK is not set
CONFIG_BUSYBOX_DEFAULT_LN=y
# CONFIG_BUSYBOX_DEFAULT_LOGNAME is not set
CONFIG_BUSYBOX_DEFAULT_LS=y
CONFIG_BUSYBOX_DEFAULT_FEATURE_LS_FILETYPES=y
CONFIG_BUSYBOX_DEFAULT_FEATURE_LS_FOLLOWLINKS=y
CONFIG_BUSYBOX_DEFAULT_FEATURE_LS_RECURSIVE=y
CONFIG_BUSYBOX_DEFAULT_FEATURE_LS_WIDTH=y
CONFIG_BUSYBOX_DEFAULT_FEATURE_LS_SORTFILES=y
CONFIG_BUSYBOX_DEFAULT_FEATURE_LS_TIMESTAMPS=y
CONFIG_BUSYBOX_DEFAULT_FEATURE_LS_USERNAME=y
CONFIG_BUSYBOX_DEFAULT_FEATURE_LS_COLOR=y
CONFIG_BUSYBOX_DEFAULT_FEATURE_LS_COLOR_IS_DEFAULT=y
CONFIG_BUSYBOX_DEFAULT_MD5SUM=y
# CONFIG_BUSYBOX_DEFAULT_SHA1SUM is not set
CONFIG_BUSYBOX_DEFAULT_SHA256SUM=y
# CONFIG_BUSYBOX_DEFAULT_SHA512SUM is not set
# CONFIG_BUSYBOX_DEFAULT_SHA3SUM is not set
CONFIG_BUSYBOX_DEFAULT_FEATURE_MD5_SHA1_SUM_CHECK=y
CONFIG_BUSYBOX_DEFAULT_MKDIR=y
CONFIG_BUSYBOX_DEFAULT_MKFIFO=y
CONFIG_BUSYBOX_DEFAULT_MKNOD=y
CONFIG_BUSYBOX_DEFAULT_MKTEMP=y
CONFIG_BUSYBOX_DEFAULT_MV=y
CONFIG_BUSYBOX_DEFAULT_NICE=y
# CONFIG_BUSYBOX_DEFAULT_NL is not set
# CONFIG_BUSYBOX_DEFAULT_NOHUP is not set
# CONFIG_BUSYBOX_DEFAULT_NPROC is not set
# CONFIG_BUSYBOX_DEFAULT_OD is not set
# CONFIG_BUSYBOX_DEFAULT_PASTE is not set
# CONFIG_BUSYBOX_DEFAULT_PRINTENV is not set
CONFIG_BUSYBOX_DEFAULT_PRINTF=y
CONFIG_BUSYBOX_DEFAULT_PWD=y
CONFIG_BUSYBOX_DEFAULT_READLINK=y
CONFIG_BUSYBOX_DEFAULT_FEATURE_READLINK_FOLLOW=y
# CONFIG_BUSYBOX_DEFAULT_REALPATH is not set
CONFIG_BUSYBOX_DEFAULT_RM=y
CONFIG_BUSYBOX_DEFAULT_RMDIR=y
CONFIG_BUSYBOX_DEFAULT_SEQ=y
# CONFIG_BUSYBOX_DEFAULT_SHRED is not set
# CONFIG_BUSYBOX_DEFAULT_SHUF is not set
CONFIG_BUSYBOX_DEFAULT_SLEEP=y
CONFIG_BUSYBOX_DEFAULT_FEATURE_FANCY_SLEEP=y
CONFIG_BUSYBOX_DEFAULT_SORT=y
# CONFIG_BUSYBOX_DEFAULT_FEATURE_SORT_BIG is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_SORT_OPTIMIZE_MEMORY is not set
# CONFIG_BUSYBOX_DEFAULT_SPLIT is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_SPLIT_FANCY is not set
# CONFIG_BUSYBOX_DEFAULT_STAT is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_STAT_FORMAT is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_STAT_FILESYSTEM is not set
# CONFIG_BUSYBOX_DEFAULT_STTY is not set
# CONFIG_BUSYBOX_DEFAULT_SUM is not set
CONFIG_BUSYBOX_DEFAULT_SYNC=y
# CONFIG_BUSYBOX_DEFAULT_FEATURE_SYNC_FANCY is not set
CONFIG_BUSYBOX_DEFAULT_FSYNC=y
# CONFIG_BUSYBOX_DEFAULT_TAC is not set
CONFIG_BUSYBOX_DEFAULT_TAIL=y
CONFIG_BUSYBOX_DEFAULT_FEATURE_FANCY_TAIL=y
CONFIG_BUSYBOX_DEFAULT_TEE=y
CONFIG_BUSYBOX_DEFAULT_FEATURE_TEE_USE_BLOCK_IO=y
CONFIG_BUSYBOX_DEFAULT_TEST=y
CONFIG_BUSYBOX_DEFAULT_TEST1=y
CONFIG_BUSYBOX_DEFAULT_TEST2=y
CONFIG_BUSYBOX_DEFAULT_FEATURE_TEST_64=y
# CONFIG_BUSYBOX_DEFAULT_TIMEOUT is not set
CONFIG_BUSYBOX_DEFAULT_TOUCH=y
# CONFIG_BUSYBOX_DEFAULT_FEATURE_TOUCH_NODEREF is not set
CONFIG_BUSYBOX_DEFAULT_FEATURE_TOUCH_SUSV3=y
CONFIG_BUSYBOX_DEFAULT_TR=y
# CONFIG_BUSYBOX_DEFAULT_FEATURE_TR_CLASSES is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_TR_EQUIV is not set
CONFIG_BUSYBOX_DEFAULT_TRUE=y
# CONFIG_BUSYBOX_DEFAULT_TRUNCATE is not set
# CONFIG_BUSYBOX_DEFAULT_TTY is not set
CONFIG_BUSYBOX_DEFAULT_UNAME=y
CONFIG_BUSYBOX_DEFAULT_UNAME_OSNAME="GNU/Linux"
# CONFIG_BUSYBOX_DEFAULT_BB_ARCH is not set
CONFIG_BUSYBOX_DEFAULT_UNIQ=y
# CONFIG_BUSYBOX_DEFAULT_UNLINK is not set
# CONFIG_BUSYBOX_DEFAULT_USLEEP is not set
# CONFIG_BUSYBOX_DEFAULT_UUDECODE is not set
# CONFIG_BUSYBOX_DEFAULT_BASE64 is not set
# CONFIG_BUSYBOX_DEFAULT_UUENCODE is not set
CONFIG_BUSYBOX_DEFAULT_WC=y
# CONFIG_BUSYBOX_DEFAULT_FEATURE_WC_LARGE is not set
# CONFIG_BUSYBOX_DEFAULT_WHO is not set
# CONFIG_BUSYBOX_DEFAULT_W is not set
# CONFIG_BUSYBOX_DEFAULT_USERS is not set
# CONFIG_BUSYBOX_DEFAULT_WHOAMI is not set
CONFIG_BUSYBOX_DEFAULT_YES=y
# CONFIG_BUSYBOX_DEFAULT_FEATURE_VERBOSE is not set
CONFIG_BUSYBOX_DEFAULT_FEATURE_PRESERVE_HARDLINKS=y
CONFIG_BUSYBOX_DEFAULT_FEATURE_HUMAN_READABLE=y
# CONFIG_BUSYBOX_DEFAULT_CHVT is not set
CONFIG_BUSYBOX_DEFAULT_CLEAR=y
# CONFIG_BUSYBOX_DEFAULT_DEALLOCVT is not set
# CONFIG_BUSYBOX_DEFAULT_DUMPKMAP is not set
# CONFIG_BUSYBOX_DEFAULT_FGCONSOLE is not set
# CONFIG_BUSYBOX_DEFAULT_KBD_MODE is not set
# CONFIG_BUSYBOX_DEFAULT_LOADFONT is not set
# CONFIG_BUSYBOX_DEFAULT_SETFONT is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_SETFONT_TEXTUAL_MAP is not set
CONFIG_BUSYBOX_DEFAULT_DEFAULT_SETFONT_DIR=""
# CONFIG_BUSYBOX_DEFAULT_FEATURE_LOADFONT_PSF2 is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_LOADFONT_RAW is not set
# CONFIG_BUSYBOX_DEFAULT_LOADKMAP is not set
# CONFIG_BUSYBOX_DEFAULT_OPENVT is not set
CONFIG_BUSYBOX_DEFAULT_RESET=y
# CONFIG_BUSYBOX_DEFAULT_RESIZE is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_RESIZE_PRINT is not set
# CONFIG_BUSYBOX_DEFAULT_SETCONSOLE is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_SETCONSOLE_LONG_OPTIONS is not set
# CONFIG_BUSYBOX_DEFAULT_SETKEYCODES is not set
# CONFIG_BUSYBOX_DEFAULT_SETLOGCONS is not set
# CONFIG_BUSYBOX_DEFAULT_SHOWKEY is not set
# CONFIG_BUSYBOX_DEFAULT_PIPE_PROGRESS is not set
# CONFIG_BUSYBOX_DEFAULT_RUN_PARTS is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_RUN_PARTS_LONG_OPTIONS is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_RUN_PARTS_FANCY is not set
CONFIG_BUSYBOX_DEFAULT_START_STOP_DAEMON=y
# CONFIG_BUSYBOX_DEFAULT_FEATURE_START_STOP_DAEMON_LONG_OPTIONS is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_START_STOP_DAEMON_FANCY is not set
CONFIG_BUSYBOX_DEFAULT_WHICH=y
# CONFIG_BUSYBOX_DEFAULT_MINIPS is not set
# CONFIG_BUSYBOX_DEFAULT_NUKE is not set
# CONFIG_BUSYBOX_DEFAULT_RESUME is not set
# CONFIG_BUSYBOX_DEFAULT_RUN_INIT is not set
CONFIG_BUSYBOX_DEFAULT_AWK=y
CONFIG_BUSYBOX_DEFAULT_FEATURE_AWK_LIBM=y
CONFIG_BUSYBOX_DEFAULT_FEATURE_AWK_GNU_EXTENSIONS=y
CONFIG_BUSYBOX_DEFAULT_CMP=y
# CONFIG_BUSYBOX_DEFAULT_DIFF is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_DIFF_LONG_OPTIONS is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_DIFF_DIR is not set
# CONFIG_BUSYBOX_DEFAULT_ED is not set
# CONFIG_BUSYBOX_DEFAULT_PATCH is not set
CONFIG_BUSYBOX_DEFAULT_SED=y
CONFIG_BUSYBOX_DEFAULT_VI=y
CONFIG_BUSYBOX_DEFAULT_FEATURE_VI_MAX_LEN=1024
# CONFIG_BUSYBOX_DEFAULT_FEATURE_VI_8BIT is not set
CONFIG_BUSYBOX_DEFAULT_FEATURE_VI_COLON=y
CONFIG_BUSYBOX_DEFAULT_FEATURE_VI_YANKMARK=y
CONFIG_BUSYBOX_DEFAULT_FEATURE_VI_SEARCH=y
# CONFIG_BUSYBOX_DEFAULT_FEATURE_VI_REGEX_SEARCH is not set
CONFIG_BUSYBOX_DEFAULT_FEATURE_VI_USE_SIGNALS=y
CONFIG_BUSYBOX_DEFAULT_FEATURE_VI_DOT_CMD=y
CONFIG_BUSYBOX_DEFAULT_FEATURE_VI_READONLY=y
CONFIG_BUSYBOX_DEFAULT_FEATURE_VI_SETOPTS=y
CONFIG_BUSYBOX_DEFAULT_FEATURE_VI_SET=y
CONFIG_BUSYBOX_DEFAULT_FEATURE_VI_WIN_RESIZE=y
CONFIG_BUSYBOX_DEFAULT_FEATURE_VI_ASK_TERMINAL=y
# CONFIG_BUSYBOX_DEFAULT_FEATURE_VI_UNDO is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_VI_UNDO_QUEUE is not set
CONFIG_BUSYBOX_DEFAULT_FEATURE_VI_UNDO_QUEUE_MAX=0
CONFIG_BUSYBOX_DEFAULT_FEATURE_ALLOW_EXEC=y
CONFIG_BUSYBOX_DEFAULT_FIND=y
CONFIG_BUSYBOX_DEFAULT_FEATURE_FIND_PRINT0=y
CONFIG_BUSYBOX_DEFAULT_FEATURE_FIND_MTIME=y
# CONFIG_BUSYBOX_DEFAULT_FEATURE_FIND_MMIN is not set
CONFIG_BUSYBOX_DEFAULT_FEATURE_FIND_PERM=y
CONFIG_BUSYBOX_DEFAULT_FEATURE_FIND_TYPE=y
# CONFIG_BUSYBOX_DEFAULT_FEATURE_FIND_EXECUTABLE is not set
CONFIG_BUSYBOX_DEFAULT_FEATURE_FIND_XDEV=y
CONFIG_BUSYBOX_DEFAULT_FEATURE_FIND_MAXDEPTH=y
CONFIG_BUSYBOX_DEFAULT_FEATURE_FIND_NEWER=y
# CONFIG_BUSYBOX_DEFAULT_FEATURE_FIND_INUM is not set
CONFIG_BUSYBOX_DEFAULT_FEATURE_FIND_EXEC=y
# CONFIG_BUSYBOX_DEFAULT_FEATURE_FIND_EXEC_PLUS is not set
CONFIG_BUSYBOX_DEFAULT_FEATURE_FIND_USER=y
CONFIG_BUSYBOX_DEFAULT_FEATURE_FIND_GROUP=y
CONFIG_BUSYBOX_DEFAULT_FEATURE_FIND_NOT=y
CONFIG_BUSYBOX_DEFAULT_FEATURE_FIND_DEPTH=y
CONFIG_BUSYBOX_DEFAULT_FEATURE_FIND_PAREN=y
CONFIG_BUSYBOX_DEFAULT_FEATURE_FIND_SIZE=y
CONFIG_BUSYBOX_DEFAULT_FEATURE_FIND_PRUNE=y
# CONFIG_BUSYBOX_DEFAULT_FEATURE_FIND_QUIT is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_FIND_DELETE is not set
CONFIG_BUSYBOX_DEFAULT_FEATURE_FIND_PATH=y
CONFIG_BUSYBOX_DEFAULT_FEATURE_FIND_REGEX=y
# CONFIG_BUSYBOX_DEFAULT_FEATURE_FIND_CONTEXT is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_FIND_LINKS is not set
CONFIG_BUSYBOX_DEFAULT_GREP=y
CONFIG_BUSYBOX_DEFAULT_EGREP=y
CONFIG_BUSYBOX_DEFAULT_FGREP=y
CONFIG_BUSYBOX_DEFAULT_FEATURE_GREP_CONTEXT=y
CONFIG_BUSYBOX_DEFAULT_XARGS=y
CONFIG_BUSYBOX_DEFAULT_FEATURE_XARGS_SUPPORT_CONFIRMATION=y
CONFIG_BUSYBOX_DEFAULT_FEATURE_XARGS_SUPPORT_QUOTES=y
CONFIG_BUSYBOX_DEFAULT_FEATURE_XARGS_SUPPORT_TERMOPT=y
CONFIG_BUSYBOX_DEFAULT_FEATURE_XARGS_SUPPORT_ZERO_TERM=y
# CONFIG_BUSYBOX_DEFAULT_FEATURE_XARGS_SUPPORT_REPL_STR is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_XARGS_SUPPORT_PARALLEL is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_XARGS_SUPPORT_ARGS_FILE is not set
# CONFIG_BUSYBOX_DEFAULT_BOOTCHARTD is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_BOOTCHARTD_BLOATED_HEADER is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_BOOTCHARTD_CONFIG_FILE is not set
CONFIG_BUSYBOX_DEFAULT_HALT=y
CONFIG_BUSYBOX_DEFAULT_POWEROFF=y
CONFIG_BUSYBOX_DEFAULT_REBOOT=y
# CONFIG_BUSYBOX_DEFAULT_FEATURE_WAIT_FOR_INIT is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_CALL_TELINIT is not set
CONFIG_BUSYBOX_DEFAULT_TELINIT_PATH=""
# CONFIG_BUSYBOX_DEFAULT_INIT is not set
# CONFIG_BUSYBOX_DEFAULT_LINUXRC is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_USE_INITTAB is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_KILL_REMOVED is not set
CONFIG_BUSYBOX_DEFAULT_FEATURE_KILL_DELAY=0
# CONFIG_BUSYBOX_DEFAULT_FEATURE_INIT_SCTTY is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_INIT_SYSLOG is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_INIT_QUIET is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_INIT_COREDUMPS is not set
CONFIG_BUSYBOX_DEFAULT_INIT_TERMINAL_TYPE=""
# CONFIG_BUSYBOX_DEFAULT_FEATURE_INIT_MODIFY_CMDLINE is not set
CONFIG_BUSYBOX_DEFAULT_FEATURE_SHADOWPASSWDS=y
# CONFIG_BUSYBOX_DEFAULT_USE_BB_PWD_GRP is not set
# CONFIG_BUSYBOX_DEFAULT_USE_BB_SHADOW is not set
# CONFIG_BUSYBOX_DEFAULT_USE_BB_CRYPT is not set
# CONFIG_BUSYBOX_DEFAULT_USE_BB_CRYPT_SHA is not set
# CONFIG_BUSYBOX_DEFAULT_ADD_SHELL is not set
# CONFIG_BUSYBOX_DEFAULT_REMOVE_SHELL is not set
# CONFIG_BUSYBOX_DEFAULT_ADDGROUP is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_ADDUSER_TO_GROUP is not set
# CONFIG_BUSYBOX_DEFAULT_ADDUSER is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_CHECK_NAMES is not set
CONFIG_BUSYBOX_DEFAULT_LAST_ID=0
CONFIG_BUSYBOX_DEFAULT_FIRST_SYSTEM_ID=0
CONFIG_BUSYBOX_DEFAULT_LAST_SYSTEM_ID=0
# CONFIG_BUSYBOX_DEFAULT_CHPASSWD is not set
CONFIG_BUSYBOX_DEFAULT_FEATURE_DEFAULT_PASSWD_ALGO="md5"
# CONFIG_BUSYBOX_DEFAULT_CRYPTPW is not set
# CONFIG_BUSYBOX_DEFAULT_MKPASSWD is not set
# CONFIG_BUSYBOX_DEFAULT_DELUSER is not set
# CONFIG_BUSYBOX_DEFAULT_DELGROUP is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_DEL_USER_FROM_GROUP is not set
# CONFIG_BUSYBOX_DEFAULT_GETTY is not set
CONFIG_BUSYBOX_DEFAULT_LOGIN=y
CONFIG_BUSYBOX_DEFAULT_LOGIN_SESSION_AS_CHILD=y
# CONFIG_BUSYBOX_DEFAULT_LOGIN_SCRIPTS is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_NOLOGIN is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_SECURETTY is not set
CONFIG_BUSYBOX_DEFAULT_PASSWD=y
CONFIG_BUSYBOX_DEFAULT_FEATURE_PASSWD_WEAK_CHECK=y
# CONFIG_BUSYBOX_DEFAULT_SU is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_SU_SYSLOG is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_SU_CHECKS_SHELLS is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_SU_BLANK_PW_NEEDS_SECURE_TTY is not set
# CONFIG_BUSYBOX_DEFAULT_SULOGIN is not set
# CONFIG_BUSYBOX_DEFAULT_VLOCK is not set
# CONFIG_BUSYBOX_DEFAULT_CHATTR is not set
# CONFIG_BUSYBOX_DEFAULT_FSCK is not set
# CONFIG_BUSYBOX_DEFAULT_LSATTR is not set
# CONFIG_BUSYBOX_DEFAULT_TUNE2FS is not set
# CONFIG_BUSYBOX_DEFAULT_MODPROBE_SMALL is not set
# CONFIG_BUSYBOX_DEFAULT_DEPMOD is not set
# CONFIG_BUSYBOX_DEFAULT_INSMOD is not set
# CONFIG_BUSYBOX_DEFAULT_LSMOD is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_LSMOD_PRETTY_2_6_OUTPUT is not set
# CONFIG_BUSYBOX_DEFAULT_MODINFO is not set
# CONFIG_BUSYBOX_DEFAULT_MODPROBE is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_MODPROBE_BLACKLIST is not set
# CONFIG_BUSYBOX_DEFAULT_RMMOD is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_CMDLINE_MODULE_OPTIONS is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_MODPROBE_SMALL_CHECK_ALREADY_LOADED is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_2_4_MODULES is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_INSMOD_VERSION_CHECKING is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_INSMOD_KSYMOOPS_SYMBOLS is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_INSMOD_LOADINKMEM is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_INSMOD_LOAD_MAP is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_INSMOD_LOAD_MAP_FULL is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_CHECK_TAINTED_MODULE is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_INSMOD_TRY_MMAP is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_MODUTILS_ALIAS is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_MODUTILS_SYMBOLS is not set
CONFIG_BUSYBOX_DEFAULT_DEFAULT_MODULES_DIR=""
CONFIG_BUSYBOX_DEFAULT_DEFAULT_DEPMOD_FILE=""
# CONFIG_BUSYBOX_DEFAULT_ACPID is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_ACPID_COMPAT is not set
# CONFIG_BUSYBOX_DEFAULT_BLKDISCARD is not set
# CONFIG_BUSYBOX_DEFAULT_BLKID is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_BLKID_TYPE is not set
# CONFIG_BUSYBOX_DEFAULT_BLOCKDEV is not set
# CONFIG_BUSYBOX_DEFAULT_CAL is not set
# CONFIG_BUSYBOX_DEFAULT_CHRT is not set
CONFIG_BUSYBOX_DEFAULT_DMESG=y
CONFIG_BUSYBOX_DEFAULT_FEATURE_DMESG_PRETTY=y
# CONFIG_BUSYBOX_DEFAULT_EJECT is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_EJECT_SCSI is not set
# CONFIG_BUSYBOX_DEFAULT_FALLOCATE is not set
# CONFIG_BUSYBOX_DEFAULT_FATATTR is not set
# CONFIG_BUSYBOX_DEFAULT_FBSET is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_FBSET_FANCY is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_FBSET_READMODE is not set
# CONFIG_BUSYBOX_DEFAULT_FDFORMAT is not set
# CONFIG_BUSYBOX_DEFAULT_FDISK is not set
# CONFIG_BUSYBOX_DEFAULT_FDISK_SUPPORT_LARGE_DISKS is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_FDISK_WRITABLE is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_AIX_LABEL is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_SGI_LABEL is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_SUN_LABEL is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_OSF_LABEL is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_GPT_LABEL is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_FDISK_ADVANCED is not set
# CONFIG_BUSYBOX_DEFAULT_FINDFS is not set
CONFIG_BUSYBOX_DEFAULT_FLOCK=y
# CONFIG_BUSYBOX_DEFAULT_FDFLUSH is not set
# CONFIG_BUSYBOX_DEFAULT_FREERAMDISK is not set
# CONFIG_BUSYBOX_DEFAULT_FSCK_MINIX is not set
# CONFIG_BUSYBOX_DEFAULT_FSFREEZE is not set
# CONFIG_BUSYBOX_DEFAULT_FSTRIM is not set
# CONFIG_BUSYBOX_DEFAULT_GETOPT is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_GETOPT_LONG is not set
CONFIG_BUSYBOX_DEFAULT_HEXDUMP=y
# CONFIG_BUSYBOX_DEFAULT_FEATURE_HEXDUMP_REVERSE is not set
# CONFIG_BUSYBOX_DEFAULT_HD is not set
# CONFIG_BUSYBOX_DEFAULT_XXD is not set
CONFIG_BUSYBOX_DEFAULT_HWCLOCK=y
# CONFIG_BUSYBOX_DEFAULT_FEATURE_HWCLOCK_ADJTIME_FHS is not set
# CONFIG_BUSYBOX_DEFAULT_IONICE is not set
# CONFIG_BUSYBOX_DEFAULT_IPCRM is not set
# CONFIG_BUSYBOX_DEFAULT_IPCS is not set
# CONFIG_BUSYBOX_DEFAULT_LAST is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_LAST_FANCY is not set
# CONFIG_BUSYBOX_DEFAULT_LOSETUP is not set
# CONFIG_BUSYBOX_DEFAULT_LSPCI is not set
# CONFIG_BUSYBOX_DEFAULT_LSUSB is not set
# CONFIG_BUSYBOX_DEFAULT_MDEV is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_MDEV_CONF is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_MDEV_RENAME is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_MDEV_RENAME_REGEXP is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_MDEV_EXEC is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_MDEV_LOAD_FIRMWARE is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_MDEV_DAEMON is not set
# CONFIG_BUSYBOX_DEFAULT_MESG is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_MESG_ENABLE_ONLY_GROUP is not set
# CONFIG_BUSYBOX_DEFAULT_MKE2FS is not set
# CONFIG_BUSYBOX_DEFAULT_MKFS_EXT2 is not set
# CONFIG_BUSYBOX_DEFAULT_MKFS_MINIX is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_MINIX2 is not set
# CONFIG_BUSYBOX_DEFAULT_MKFS_REISER is not set
# CONFIG_BUSYBOX_DEFAULT_MKDOSFS is not set
# CONFIG_BUSYBOX_DEFAULT_MKFS_VFAT is not set
CONFIG_BUSYBOX_DEFAULT_MKSWAP=y
# CONFIG_BUSYBOX_DEFAULT_FEATURE_MKSWAP_UUID is not set
# CONFIG_BUSYBOX_DEFAULT_MORE is not set
CONFIG_BUSYBOX_DEFAULT_MOUNT=y
# CONFIG_BUSYBOX_DEFAULT_FEATURE_MOUNT_FAKE is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_MOUNT_VERBOSE is not set
CONFIG_BUSYBOX_DEFAULT_FEATURE_MOUNT_HELPERS=y
# CONFIG_BUSYBOX_DEFAULT_FEATURE_MOUNT_LABEL is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_MOUNT_NFS is not set
CONFIG_BUSYBOX_DEFAULT_FEATURE_MOUNT_CIFS=y
CONFIG_BUSYBOX_DEFAULT_FEATURE_MOUNT_FLAGS=y
CONFIG_BUSYBOX_DEFAULT_FEATURE_MOUNT_FSTAB=y
# CONFIG_BUSYBOX_DEFAULT_FEATURE_MOUNT_OTHERTAB is not set
# CONFIG_BUSYBOX_DEFAULT_MOUNTPOINT is not set
# CONFIG_BUSYBOX_DEFAULT_NOLOGIN is not set
# CONFIG_BUSYBOX_DEFAULT_NOLOGIN_DEPENDENCIES is not set
# CONFIG_BUSYBOX_DEFAULT_NSENTER is not set
CONFIG_BUSYBOX_DEFAULT_PIVOT_ROOT=y
# CONFIG_BUSYBOX_DEFAULT_RDATE is not set
# CONFIG_BUSYBOX_DEFAULT_RDEV is not set
# CONFIG_BUSYBOX_DEFAULT_READPROFILE is not set
# CONFIG_BUSYBOX_DEFAULT_RENICE is not set
# CONFIG_BUSYBOX_DEFAULT_REV is not set
# CONFIG_BUSYBOX_DEFAULT_RTCWAKE is not set
# CONFIG_BUSYBOX_DEFAULT_SCRIPT is not set
# CONFIG_BUSYBOX_DEFAULT_SCRIPTREPLAY is not set
# CONFIG_BUSYBOX_DEFAULT_SETARCH is not set
# CONFIG_BUSYBOX_DEFAULT_LINUX32 is not set
# CONFIG_BUSYBOX_DEFAULT_LINUX64 is not set
# CONFIG_BUSYBOX_DEFAULT_SETPRIV is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_SETPRIV_DUMP is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_SETPRIV_CAPABILITIES is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_SETPRIV_CAPABILITY_NAMES is not set
# CONFIG_BUSYBOX_DEFAULT_SETSID is not set
CONFIG_BUSYBOX_DEFAULT_SWAPON=y
CONFIG_BUSYBOX_DEFAULT_FEATURE_SWAPON_DISCARD=y
CONFIG_BUSYBOX_DEFAULT_FEATURE_SWAPON_PRI=y
CONFIG_BUSYBOX_DEFAULT_SWAPOFF=y
# CONFIG_BUSYBOX_DEFAULT_FEATURE_SWAPONOFF_LABEL is not set
CONFIG_BUSYBOX_DEFAULT_SWITCH_ROOT=y
# CONFIG_BUSYBOX_DEFAULT_TASKSET is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_TASKSET_FANCY is not set
# CONFIG_BUSYBOX_DEFAULT_UEVENT is not set
CONFIG_BUSYBOX_DEFAULT_UMOUNT=y
CONFIG_BUSYBOX_DEFAULT_FEATURE_UMOUNT_ALL=y
# CONFIG_BUSYBOX_DEFAULT_UNSHARE is not set
# CONFIG_BUSYBOX_DEFAULT_WALL is not set
CONFIG_BUSYBOX_DEFAULT_FEATURE_MOUNT_LOOP=y
# CONFIG_BUSYBOX_DEFAULT_FEATURE_MOUNT_LOOP_CREATE is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_MTAB_SUPPORT is not set
# CONFIG_BUSYBOX_DEFAULT_VOLUMEID is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_VOLUMEID_BCACHE is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_VOLUMEID_BTRFS is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_VOLUMEID_CRAMFS is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_VOLUMEID_EXFAT is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_VOLUMEID_EXT is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_VOLUMEID_F2FS is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_VOLUMEID_FAT is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_VOLUMEID_HFS is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_VOLUMEID_ISO9660 is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_VOLUMEID_JFS is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_VOLUMEID_LFS is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_VOLUMEID_LINUXRAID is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_VOLUMEID_LINUXSWAP is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_VOLUMEID_LUKS is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_VOLUMEID_MINIX is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_VOLUMEID_NILFS is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_VOLUMEID_NTFS is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_VOLUMEID_OCFS2 is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_VOLUMEID_REISERFS is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_VOLUMEID_ROMFS is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_VOLUMEID_SQUASHFS is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_VOLUMEID_SYSV is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_VOLUMEID_UBIFS is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_VOLUMEID_UDF is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_VOLUMEID_XFS is not set
# CONFIG_BUSYBOX_DEFAULT_ADJTIMEX is not set
# CONFIG_BUSYBOX_DEFAULT_BBCONFIG is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_COMPRESS_BBCONFIG is not set
# CONFIG_BUSYBOX_DEFAULT_BC is not set
# CONFIG_BUSYBOX_DEFAULT_DC is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_DC_BIG is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_DC_LIBM is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_BC_INTERACTIVE is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_BC_LONG_OPTIONS is not set
# CONFIG_BUSYBOX_DEFAULT_BEEP is not set
CONFIG_BUSYBOX_DEFAULT_FEATURE_BEEP_FREQ=0
CONFIG_BUSYBOX_DEFAULT_FEATURE_BEEP_LENGTH_MS=0
# CONFIG_BUSYBOX_DEFAULT_CHAT is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_CHAT_NOFAIL is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_CHAT_TTY_HIFI is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_CHAT_IMPLICIT_CR is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_CHAT_SWALLOW_OPTS is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_CHAT_SEND_ESCAPES is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_CHAT_VAR_ABORT_LEN is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_CHAT_CLR_ABORT is not set
# CONFIG_BUSYBOX_DEFAULT_CONSPY is not set
CONFIG_BUSYBOX_DEFAULT_CROND=y
# CONFIG_BUSYBOX_DEFAULT_FEATURE_CROND_D is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_CROND_CALL_SENDMAIL is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_CROND_SPECIAL_TIMES is not set
CONFIG_BUSYBOX_DEFAULT_FEATURE_CROND_DIR="/etc"
CONFIG_BUSYBOX_DEFAULT_CRONTAB=y
# CONFIG_BUSYBOX_DEFAULT_DEVFSD is not set
# CONFIG_BUSYBOX_DEFAULT_DEVFSD_MODLOAD is not set
# CONFIG_BUSYBOX_DEFAULT_DEVFSD_FG_NP is not set
# CONFIG_BUSYBOX_DEFAULT_DEVFSD_VERBOSE is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_DEVFS is not set
# CONFIG_BUSYBOX_DEFAULT_DEVMEM is not set
# CONFIG_BUSYBOX_DEFAULT_FBSPLASH is not set
# CONFIG_BUSYBOX_DEFAULT_FLASH_ERASEALL is not set
# CONFIG_BUSYBOX_DEFAULT_FLASH_LOCK is not set
# CONFIG_BUSYBOX_DEFAULT_FLASH_UNLOCK is not set
# CONFIG_BUSYBOX_DEFAULT_FLASHCP is not set
# CONFIG_BUSYBOX_DEFAULT_HDPARM is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_HDPARM_GET_IDENTITY is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_HDPARM_HDIO_SCAN_HWIF is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_HDPARM_HDIO_UNREGISTER_HWIF is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_HDPARM_HDIO_DRIVE_RESET is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_HDPARM_HDIO_TRISTATE_HWIF is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_HDPARM_HDIO_GETSET_DMA is not set
# CONFIG_BUSYBOX_DEFAULT_HEXEDIT is not set
# CONFIG_BUSYBOX_DEFAULT_I2CGET is not set
# CONFIG_BUSYBOX_DEFAULT_I2CSET is not set
# CONFIG_BUSYBOX_DEFAULT_I2CDUMP is not set
# CONFIG_BUSYBOX_DEFAULT_I2CDETECT is not set
# CONFIG_BUSYBOX_DEFAULT_I2CTRANSFER is not set
# CONFIG_BUSYBOX_DEFAULT_INOTIFYD is not set
CONFIG_BUSYBOX_DEFAULT_LESS=y
CONFIG_BUSYBOX_DEFAULT_FEATURE_LESS_MAXLINES=9999999
# CONFIG_BUSYBOX_DEFAULT_FEATURE_LESS_BRACKETS is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_LESS_FLAGS is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_LESS_TRUNCATE is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_LESS_MARKS is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_LESS_REGEXP is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_LESS_WINCH is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_LESS_ASK_TERMINAL is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_LESS_DASHCMD is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_LESS_LINENUMS is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_LESS_RAW is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_LESS_ENV is not set
CONFIG_BUSYBOX_DEFAULT_LOCK=y
# CONFIG_BUSYBOX_DEFAULT_LSSCSI is not set
# CONFIG_BUSYBOX_DEFAULT_MAKEDEVS is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_MAKEDEVS_LEAF is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_MAKEDEVS_TABLE is not set
# CONFIG_BUSYBOX_DEFAULT_MAN is not set
# CONFIG_BUSYBOX_DEFAULT_MICROCOM is not set
# CONFIG_BUSYBOX_DEFAULT_MT is not set
# CONFIG_BUSYBOX_DEFAULT_NANDWRITE is not set
# CONFIG_BUSYBOX_DEFAULT_NANDDUMP is not set
# CONFIG_BUSYBOX_DEFAULT_PARTPROBE is not set
# CONFIG_BUSYBOX_DEFAULT_RAIDAUTORUN is not set
# CONFIG_BUSYBOX_DEFAULT_READAHEAD is not set
# CONFIG_BUSYBOX_DEFAULT_RFKILL is not set
# CONFIG_BUSYBOX_DEFAULT_RUNLEVEL is not set
# CONFIG_BUSYBOX_DEFAULT_RX is not set
# CONFIG_BUSYBOX_DEFAULT_SETFATTR is not set
# CONFIG_BUSYBOX_DEFAULT_SETSERIAL is not set
CONFIG_BUSYBOX_DEFAULT_STRINGS=y
CONFIG_BUSYBOX_DEFAULT_TIME=y
# CONFIG_BUSYBOX_DEFAULT_TS is not set
# CONFIG_BUSYBOX_DEFAULT_TTYSIZE is not set
# CONFIG_BUSYBOX_DEFAULT_UBIATTACH is not set
# CONFIG_BUSYBOX_DEFAULT_UBIDETACH is not set
# CONFIG_BUSYBOX_DEFAULT_UBIMKVOL is not set
# CONFIG_BUSYBOX_DEFAULT_UBIRMVOL is not set
# CONFIG_BUSYBOX_DEFAULT_UBIRSVOL is not set
# CONFIG_BUSYBOX_DEFAULT_UBIUPDATEVOL is not set
# CONFIG_BUSYBOX_DEFAULT_UBIRENAME is not set
# CONFIG_BUSYBOX_DEFAULT_VOLNAME is not set
# CONFIG_BUSYBOX_DEFAULT_WATCHDOG is not set
CONFIG_BUSYBOX_DEFAULT_FEATURE_IPV6=y
# CONFIG_BUSYBOX_DEFAULT_FEATURE_UNIX_LOCAL is not set
CONFIG_BUSYBOX_DEFAULT_FEATURE_PREFER_IPV4_ADDRESS=y
CONFIG_BUSYBOX_DEFAULT_VERBOSE_RESOLUTION_ERRORS=y
# CONFIG_BUSYBOX_DEFAULT_FEATURE_TLS_SHA1 is not set
# CONFIG_BUSYBOX_DEFAULT_ARP is not set
# CONFIG_BUSYBOX_DEFAULT_ARPING is not set
CONFIG_BUSYBOX_DEFAULT_BRCTL=y
CONFIG_BUSYBOX_DEFAULT_FEATURE_BRCTL_FANCY=y
CONFIG_BUSYBOX_DEFAULT_FEATURE_BRCTL_SHOW=y
# CONFIG_BUSYBOX_DEFAULT_DNSD is not set
# CONFIG_BUSYBOX_DEFAULT_ETHER_WAKE is not set
# CONFIG_BUSYBOX_DEFAULT_FTPD is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_FTPD_WRITE is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_FTPD_ACCEPT_BROKEN_LIST is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_FTPD_AUTHENTICATION is not set
# CONFIG_BUSYBOX_DEFAULT_FTPGET is not set
# CONFIG_BUSYBOX_DEFAULT_FTPPUT is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_FTPGETPUT_LONG_OPTIONS is not set
# CONFIG_BUSYBOX_DEFAULT_HOSTNAME is not set
# CONFIG_BUSYBOX_DEFAULT_DNSDOMAINNAME is not set
# CONFIG_BUSYBOX_DEFAULT_HTTPD is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_HTTPD_RANGES is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_HTTPD_SETUID is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_HTTPD_BASIC_AUTH is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_HTTPD_AUTH_MD5 is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_HTTPD_CGI is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_HTTPD_CONFIG_WITH_SCRIPT_INTERPR is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_HTTPD_SET_REMOTE_PORT_TO_ENV is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_HTTPD_ENCODE_URL_STR is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_HTTPD_ERROR_PAGES is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_HTTPD_PROXY is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_HTTPD_GZIP is not set
CONFIG_BUSYBOX_DEFAULT_IFCONFIG=y
CONFIG_BUSYBOX_DEFAULT_FEATURE_IFCONFIG_STATUS=y
# CONFIG_BUSYBOX_DEFAULT_FEATURE_IFCONFIG_SLIP is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_IFCONFIG_MEMSTART_IOADDR_IRQ is not set
CONFIG_BUSYBOX_DEFAULT_FEATURE_IFCONFIG_HW=y
CONFIG_BUSYBOX_DEFAULT_FEATURE_IFCONFIG_BROADCAST_PLUS=y
# CONFIG_BUSYBOX_DEFAULT_IFENSLAVE is not set
# CONFIG_BUSYBOX_DEFAULT_IFPLUGD is not set
# CONFIG_BUSYBOX_DEFAULT_IFUP is not set
# CONFIG_BUSYBOX_DEFAULT_IFDOWN is not set
CONFIG_BUSYBOX_DEFAULT_IFUPDOWN_IFSTATE_PATH=""
# CONFIG_BUSYBOX_DEFAULT_FEATURE_IFUPDOWN_IP is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_IFUPDOWN_IPV4 is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_IFUPDOWN_IPV6 is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_IFUPDOWN_MAPPING is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_IFUPDOWN_EXTERNAL_DHCP is not set
# CONFIG_BUSYBOX_DEFAULT_INETD is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_INETD_SUPPORT_BUILTIN_ECHO is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_INETD_SUPPORT_BUILTIN_DISCARD is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_INETD_SUPPORT_BUILTIN_TIME is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_INETD_SUPPORT_BUILTIN_DAYTIME is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_INETD_SUPPORT_BUILTIN_CHARGEN is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_INETD_RPC is not set
CONFIG_BUSYBOX_DEFAULT_IP=y
# CONFIG_BUSYBOX_DEFAULT_IPADDR is not set
# CONFIG_BUSYBOX_DEFAULT_IPLINK is not set
# CONFIG_BUSYBOX_DEFAULT_IPROUTE is not set
# CONFIG_BUSYBOX_DEFAULT_IPTUNNEL is not set
# CONFIG_BUSYBOX_DEFAULT_IPRULE is not set
# CONFIG_BUSYBOX_DEFAULT_IPNEIGH is not set
CONFIG_BUSYBOX_DEFAULT_FEATURE_IP_ADDRESS=y
CONFIG_BUSYBOX_DEFAULT_FEATURE_IP_LINK=y
CONFIG_BUSYBOX_DEFAULT_FEATURE_IP_ROUTE=y
CONFIG_BUSYBOX_DEFAULT_FEATURE_IP_ROUTE_DIR="/etc/iproute2"
# CONFIG_BUSYBOX_DEFAULT_FEATURE_IP_TUNNEL is not set
CONFIG_BUSYBOX_DEFAULT_FEATURE_IP_RULE=y
CONFIG_BUSYBOX_DEFAULT_FEATURE_IP_NEIGH=y
# CONFIG_BUSYBOX_DEFAULT_FEATURE_IP_RARE_PROTOCOLS is not set
# CONFIG_BUSYBOX_DEFAULT_IPCALC is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_IPCALC_LONG_OPTIONS is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_IPCALC_FANCY is not set
# CONFIG_BUSYBOX_DEFAULT_FAKEIDENTD is not set
# CONFIG_BUSYBOX_DEFAULT_NAMEIF is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_NAMEIF_EXTENDED is not set
# CONFIG_BUSYBOX_DEFAULT_NBDCLIENT is not set
CONFIG_BUSYBOX_DEFAULT_NC=y
# CONFIG_BUSYBOX_DEFAULT_NETCAT is not set
# CONFIG_BUSYBOX_DEFAULT_NC_SERVER is not set
# CONFIG_BUSYBOX_DEFAULT_NC_EXTRA is not set
# CONFIG_BUSYBOX_DEFAULT_NC_110_COMPAT is not set
CONFIG_BUSYBOX_DEFAULT_NETMSG=y
CONFIG_BUSYBOX_DEFAULT_NETSTAT=y
CONFIG_BUSYBOX_DEFAULT_FEATURE_NETSTAT_WIDE=y
CONFIG_BUSYBOX_DEFAULT_FEATURE_NETSTAT_PRG=y
# CONFIG_BUSYBOX_DEFAULT_NSLOOKUP is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_NSLOOKUP_BIG is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_NSLOOKUP_LONG_OPTIONS is not set
CONFIG_BUSYBOX_DEFAULT_NSLOOKUP_OPENWRT=y
# CONFIG_BUSYBOX_DEFAULT_FEATURE_NSLOOKUP_OPENWRT_LONG_OPTIONS is not set
CONFIG_BUSYBOX_DEFAULT_NTPD=y
CONFIG_BUSYBOX_DEFAULT_FEATURE_NTPD_SERVER=y
# CONFIG_BUSYBOX_DEFAULT_FEATURE_NTPD_CONF is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_NTP_AUTH is not set
CONFIG_BUSYBOX_DEFAULT_PING=y
CONFIG_BUSYBOX_DEFAULT_PING6=y
CONFIG_BUSYBOX_DEFAULT_FEATURE_FANCY_PING=y
# CONFIG_BUSYBOX_DEFAULT_PSCAN is not set
CONFIG_BUSYBOX_DEFAULT_ROUTE=y
# CONFIG_BUSYBOX_DEFAULT_SLATTACH is not set
# CONFIG_BUSYBOX_DEFAULT_SSL_CLIENT is not set
# CONFIG_BUSYBOX_DEFAULT_TC is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_TC_INGRESS is not set
# CONFIG_BUSYBOX_DEFAULT_TCPSVD is not set
# CONFIG_BUSYBOX_DEFAULT_UDPSVD is not set
# CONFIG_BUSYBOX_DEFAULT_TELNET is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_TELNET_TTYPE is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_TELNET_AUTOLOGIN is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_TELNET_WIDTH is not set
# CONFIG_BUSYBOX_DEFAULT_TELNETD is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_TELNETD_STANDALONE is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_TELNETD_INETD_WAIT is not set
# CONFIG_BUSYBOX_DEFAULT_TFTP is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_TFTP_PROGRESS_BAR is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_TFTP_HPA_COMPAT is not set
# CONFIG_BUSYBOX_DEFAULT_TFTPD is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_TFTP_GET is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_TFTP_PUT is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_TFTP_BLOCKSIZE is not set
# CONFIG_BUSYBOX_DEFAULT_TFTP_DEBUG is not set
# CONFIG_BUSYBOX_DEFAULT_TLS is not set
CONFIG_BUSYBOX_DEFAULT_TRACEROUTE=y
CONFIG_BUSYBOX_DEFAULT_TRACEROUTE6=y
CONFIG_BUSYBOX_DEFAULT_FEATURE_TRACEROUTE_VERBOSE=y
# CONFIG_BUSYBOX_DEFAULT_FEATURE_TRACEROUTE_USE_ICMP is not set
# CONFIG_BUSYBOX_DEFAULT_TUNCTL is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_TUNCTL_UG is not set
# CONFIG_BUSYBOX_DEFAULT_VCONFIG is not set
# CONFIG_BUSYBOX_DEFAULT_WGET is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_WGET_LONG_OPTIONS is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_WGET_STATUSBAR is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_WGET_AUTHENTICATION is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_WGET_TIMEOUT is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_WGET_HTTPS is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_WGET_OPENSSL is not set
# CONFIG_BUSYBOX_DEFAULT_WHOIS is not set
# CONFIG_BUSYBOX_DEFAULT_ZCIP is not set
# CONFIG_BUSYBOX_DEFAULT_UDHCPD is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_UDHCPD_BASE_IP_ON_MAC is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_UDHCPD_WRITE_LEASES_EARLY is not set
CONFIG_BUSYBOX_DEFAULT_DHCPD_LEASES_FILE=""
# CONFIG_BUSYBOX_DEFAULT_DUMPLEASES is not set
# CONFIG_BUSYBOX_DEFAULT_DHCPRELAY is not set
CONFIG_BUSYBOX_DEFAULT_UDHCPC=y
# CONFIG_BUSYBOX_DEFAULT_FEATURE_UDHCPC_ARPING is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_UDHCPC_SANITIZEOPT is not set
CONFIG_BUSYBOX_DEFAULT_UDHCPC_DEFAULT_SCRIPT="/usr/share/udhcpc/default.script"
# CONFIG_BUSYBOX_DEFAULT_UDHCPC6 is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_UDHCPC6_RFC3646 is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_UDHCPC6_RFC4704 is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_UDHCPC6_RFC4833 is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_UDHCPC6_RFC5970 is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_UDHCP_PORT is not set
CONFIG_BUSYBOX_DEFAULT_UDHCP_DEBUG=0
CONFIG_BUSYBOX_DEFAULT_UDHCPC_SLACK_FOR_BUGGY_SERVERS=80
CONFIG_BUSYBOX_DEFAULT_FEATURE_UDHCP_RFC3397=y
# CONFIG_BUSYBOX_DEFAULT_FEATURE_UDHCP_8021Q is not set
CONFIG_BUSYBOX_DEFAULT_IFUPDOWN_UDHCPC_CMD_OPTIONS=""
# CONFIG_BUSYBOX_DEFAULT_LPD is not set
# CONFIG_BUSYBOX_DEFAULT_LPR is not set
# CONFIG_BUSYBOX_DEFAULT_LPQ is not set
# CONFIG_BUSYBOX_DEFAULT_MAKEMIME is not set
# CONFIG_BUSYBOX_DEFAULT_POPMAILDIR is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_POPMAILDIR_DELIVERY is not set
# CONFIG_BUSYBOX_DEFAULT_REFORMIME is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_REFORMIME_COMPAT is not set
# CONFIG_BUSYBOX_DEFAULT_SENDMAIL is not set
CONFIG_BUSYBOX_DEFAULT_FEATURE_MIME_CHARSET=""
CONFIG_BUSYBOX_DEFAULT_FREE=y
# CONFIG_BUSYBOX_DEFAULT_FUSER is not set
# CONFIG_BUSYBOX_DEFAULT_IOSTAT is not set
CONFIG_BUSYBOX_DEFAULT_KILL=y
CONFIG_BUSYBOX_DEFAULT_KILLALL=y
# CONFIG_BUSYBOX_DEFAULT_KILLALL5 is not set
# CONFIG_BUSYBOX_DEFAULT_LSOF is not set
# CONFIG_BUSYBOX_DEFAULT_MPSTAT is not set
# CONFIG_BUSYBOX_DEFAULT_NMETER is not set
CONFIG_BUSYBOX_DEFAULT_PGREP=y
# CONFIG_BUSYBOX_DEFAULT_PKILL is not set
CONFIG_BUSYBOX_DEFAULT_PIDOF=y
# CONFIG_BUSYBOX_DEFAULT_FEATURE_PIDOF_SINGLE is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_PIDOF_OMIT is not set
# CONFIG_BUSYBOX_DEFAULT_PMAP is not set
# CONFIG_BUSYBOX_DEFAULT_POWERTOP is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_POWERTOP_INTERACTIVE is not set
CONFIG_BUSYBOX_DEFAULT_PS=y
CONFIG_BUSYBOX_DEFAULT_FEATURE_PS_WIDE=y
# CONFIG_BUSYBOX_DEFAULT_FEATURE_PS_LONG is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_PS_TIME is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_PS_UNUSUAL_SYSTEMS is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_PS_ADDITIONAL_COLUMNS is not set
# CONFIG_BUSYBOX_DEFAULT_PSTREE is not set
# CONFIG_BUSYBOX_DEFAULT_PWDX is not set
# CONFIG_BUSYBOX_DEFAULT_SMEMCAP is not set
CONFIG_BUSYBOX_DEFAULT_BB_SYSCTL=y
CONFIG_BUSYBOX_DEFAULT_TOP=y
# CONFIG_BUSYBOX_DEFAULT_FEATURE_TOP_INTERACTIVE is not set
CONFIG_BUSYBOX_DEFAULT_FEATURE_TOP_CPU_USAGE_PERCENTAGE=y
CONFIG_BUSYBOX_DEFAULT_FEATURE_TOP_CPU_GLOBAL_PERCENTS=y
# CONFIG_BUSYBOX_DEFAULT_FEATURE_TOP_SMP_CPU is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_TOP_DECIMALS is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_TOP_SMP_PROCESS is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_TOPMEM is not set
CONFIG_BUSYBOX_DEFAULT_UPTIME=y
# CONFIG_BUSYBOX_DEFAULT_FEATURE_UPTIME_UTMP_SUPPORT is not set
# CONFIG_BUSYBOX_DEFAULT_WATCH is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_SHOW_THREADS is not set
# CONFIG_BUSYBOX_DEFAULT_CHPST is not set
# CONFIG_BUSYBOX_DEFAULT_SETUIDGID is not set
# CONFIG_BUSYBOX_DEFAULT_ENVUIDGID is not set
# CONFIG_BUSYBOX_DEFAULT_ENVDIR is not set
# CONFIG_BUSYBOX_DEFAULT_SOFTLIMIT is not set
# CONFIG_BUSYBOX_DEFAULT_RUNSV is not set
# CONFIG_BUSYBOX_DEFAULT_RUNSVDIR is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_RUNSVDIR_LOG is not set
# CONFIG_BUSYBOX_DEFAULT_SV is not set
CONFIG_BUSYBOX_DEFAULT_SV_DEFAULT_SERVICE_DIR=""
# CONFIG_BUSYBOX_DEFAULT_SVC is not set
# CONFIG_BUSYBOX_DEFAULT_SVOK is not set
# CONFIG_BUSYBOX_DEFAULT_SVLOGD is not set
# CONFIG_BUSYBOX_DEFAULT_CHCON is not set
# CONFIG_BUSYBOX_DEFAULT_GETENFORCE is not set
# CONFIG_BUSYBOX_DEFAULT_GETSEBOOL is not set
# CONFIG_BUSYBOX_DEFAULT_LOAD_POLICY is not set
# CONFIG_BUSYBOX_DEFAULT_MATCHPATHCON is not set
# CONFIG_BUSYBOX_DEFAULT_RUNCON is not set
# CONFIG_BUSYBOX_DEFAULT_SELINUXENABLED is not set
# CONFIG_BUSYBOX_DEFAULT_SESTATUS is not set
# CONFIG_BUSYBOX_DEFAULT_SETENFORCE is not set
# CONFIG_BUSYBOX_DEFAULT_SETFILES is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_SETFILES_CHECK_OPTION is not set
# CONFIG_BUSYBOX_DEFAULT_RESTORECON is not set
# CONFIG_BUSYBOX_DEFAULT_SETSEBOOL is not set
CONFIG_BUSYBOX_DEFAULT_SH_IS_ASH=y
# CONFIG_BUSYBOX_DEFAULT_SH_IS_HUSH is not set
# CONFIG_BUSYBOX_DEFAULT_SH_IS_NONE is not set
# CONFIG_BUSYBOX_DEFAULT_BASH_IS_ASH is not set
# CONFIG_BUSYBOX_DEFAULT_BASH_IS_HUSH is not set
CONFIG_BUSYBOX_DEFAULT_BASH_IS_NONE=y
CONFIG_BUSYBOX_DEFAULT_ASH=y
# CONFIG_BUSYBOX_DEFAULT_ASH_OPTIMIZE_FOR_SIZE is not set
CONFIG_BUSYBOX_DEFAULT_ASH_INTERNAL_GLOB=y
CONFIG_BUSYBOX_DEFAULT_ASH_BASH_COMPAT=y
# CONFIG_BUSYBOX_DEFAULT_ASH_BASH_SOURCE_CURDIR is not set
# CONFIG_BUSYBOX_DEFAULT_ASH_BASH_NOT_FOUND_HOOK is not set
CONFIG_BUSYBOX_DEFAULT_ASH_JOB_CONTROL=y
CONFIG_BUSYBOX_DEFAULT_ASH_ALIAS=y
# CONFIG_BUSYBOX_DEFAULT_ASH_RANDOM_SUPPORT is not set
CONFIG_BUSYBOX_DEFAULT_ASH_EXPAND_PRMT=y
# CONFIG_BUSYBOX_DEFAULT_ASH_IDLE_TIMEOUT is not set
# CONFIG_BUSYBOX_DEFAULT_ASH_MAIL is not set
CONFIG_BUSYBOX_DEFAULT_ASH_ECHO=y
CONFIG_BUSYBOX_DEFAULT_ASH_PRINTF=y
CONFIG_BUSYBOX_DEFAULT_ASH_TEST=y
# CONFIG_BUSYBOX_DEFAULT_ASH_HELP is not set
CONFIG_BUSYBOX_DEFAULT_ASH_GETOPTS=y
CONFIG_BUSYBOX_DEFAULT_ASH_CMDCMD=y
# CONFIG_BUSYBOX_DEFAULT_CTTYHACK is not set
# CONFIG_BUSYBOX_DEFAULT_HUSH is not set
# CONFIG_BUSYBOX_DEFAULT_HUSH_BASH_COMPAT is not set
# CONFIG_BUSYBOX_DEFAULT_HUSH_BRACE_EXPANSION is not set
# CONFIG_BUSYBOX_DEFAULT_HUSH_LINENO_VAR is not set
# CONFIG_BUSYBOX_DEFAULT_HUSH_BASH_SOURCE_CURDIR is not set
# CONFIG_BUSYBOX_DEFAULT_HUSH_INTERACTIVE is not set
# CONFIG_BUSYBOX_DEFAULT_HUSH_SAVEHISTORY is not set
# CONFIG_BUSYBOX_DEFAULT_HUSH_JOB is not set
# CONFIG_BUSYBOX_DEFAULT_HUSH_TICK is not set
# CONFIG_BUSYBOX_DEFAULT_HUSH_IF is not set
# CONFIG_BUSYBOX_DEFAULT_HUSH_LOOPS is not set
# CONFIG_BUSYBOX_DEFAULT_HUSH_CASE is not set
# CONFIG_BUSYBOX_DEFAULT_HUSH_FUNCTIONS is not set
# CONFIG_BUSYBOX_DEFAULT_HUSH_LOCAL is not set
# CONFIG_BUSYBOX_DEFAULT_HUSH_RANDOM_SUPPORT is not set
# CONFIG_BUSYBOX_DEFAULT_HUSH_MODE_X is not set
# CONFIG_BUSYBOX_DEFAULT_HUSH_ECHO is not set
# CONFIG_BUSYBOX_DEFAULT_HUSH_PRINTF is not set
# CONFIG_BUSYBOX_DEFAULT_HUSH_TEST is not set
# CONFIG_BUSYBOX_DEFAULT_HUSH_HELP is not set
# CONFIG_BUSYBOX_DEFAULT_HUSH_EXPORT is not set
# CONFIG_BUSYBOX_DEFAULT_HUSH_EXPORT_N is not set
# CONFIG_BUSYBOX_DEFAULT_HUSH_READONLY is not set
# CONFIG_BUSYBOX_DEFAULT_HUSH_KILL is not set
# CONFIG_BUSYBOX_DEFAULT_HUSH_WAIT is not set
# CONFIG_BUSYBOX_DEFAULT_HUSH_COMMAND is not set
# CONFIG_BUSYBOX_DEFAULT_HUSH_TRAP is not set
# CONFIG_BUSYBOX_DEFAULT_HUSH_TYPE is not set
# CONFIG_BUSYBOX_DEFAULT_HUSH_TIMES is not set
# CONFIG_BUSYBOX_DEFAULT_HUSH_READ is not set
# CONFIG_BUSYBOX_DEFAULT_HUSH_SET is not set
# CONFIG_BUSYBOX_DEFAULT_HUSH_UNSET is not set
# CONFIG_BUSYBOX_DEFAULT_HUSH_ULIMIT is not set
# CONFIG_BUSYBOX_DEFAULT_HUSH_UMASK is not set
# CONFIG_BUSYBOX_DEFAULT_HUSH_GETOPTS is not set
# CONFIG_BUSYBOX_DEFAULT_HUSH_MEMLEAK is not set
CONFIG_BUSYBOX_DEFAULT_FEATURE_SH_MATH=y
CONFIG_BUSYBOX_DEFAULT_FEATURE_SH_MATH_64=y
# CONFIG_BUSYBOX_DEFAULT_FEATURE_SH_MATH_BASE is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_SH_EXTRA_QUIET is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_SH_STANDALONE is not set
CONFIG_BUSYBOX_DEFAULT_FEATURE_SH_NOFORK=y
# CONFIG_BUSYBOX_DEFAULT_FEATURE_SH_READ_FRAC is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_SH_HISTFILESIZE is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_SH_EMBEDDED_SCRIPTS is not set
# CONFIG_BUSYBOX_DEFAULT_KLOGD is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_KLOGD_KLOGCTL is not set
CONFIG_BUSYBOX_DEFAULT_LOGGER=y
# CONFIG_BUSYBOX_DEFAULT_LOGREAD is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_LOGREAD_REDUCED_LOCKING is not set
# CONFIG_BUSYBOX_DEFAULT_SYSLOGD is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_ROTATE_LOGFILE is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_REMOTE_LOG is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_SYSLOGD_DUP is not set
# CONFIG_BUSYBOX_DEFAULT_FEATURE_SYSLOGD_CFG is not set
CONFIG_BUSYBOX_DEFAULT_FEATURE_SYSLOGD_READ_BUFFER_SIZE=0
# CONFIG_BUSYBOX_DEFAULT_FEATURE_IPC_SYSLOG is not set
CONFIG_BUSYBOX_DEFAULT_FEATURE_IPC_SYSLOG_BUFFER_SIZE=0
# CONFIG_BUSYBOX_DEFAULT_FEATURE_KMSG_SYSLOG is not set
CONFIG_PACKAGE_ca-bundle=y
CONFIG_PACKAGE_ca-certificates=y
# CONFIG_PACKAGE_dnsmasq is not set
# CONFIG_PACKAGE_dnsmasq-dhcpv6 is not set
CONFIG_PACKAGE_dnsmasq-full=y
CONFIG_PACKAGE_dnsmasq_full_dhcp=y
# CONFIG_PACKAGE_dnsmasq_full_dhcpv6 is not set
# CONFIG_PACKAGE_dnsmasq_full_dnssec is not set
# CONFIG_PACKAGE_dnsmasq_full_auth is not set
CONFIG_PACKAGE_dnsmasq_full_ipset=y
# CONFIG_PACKAGE_dnsmasq_full_conntrack is not set
# CONFIG_PACKAGE_dnsmasq_full_noid is not set
# CONFIG_PACKAGE_dnsmasq_full_broken_rtc is not set
CONFIG_PACKAGE_dnsmasq_full_tftp=y
CONFIG_PACKAGE_dropbear=y
#
# Configuration
#
CONFIG_DROPBEAR_CURVE25519=y
# CONFIG_DROPBEAR_ECC is not set
# CONFIG_DROPBEAR_ED25519 is not set
CONFIG_DROPBEAR_CHACHA20POLY1305=y
# CONFIG_DROPBEAR_ZLIB is not set
CONFIG_DROPBEAR_DBCLIENT=y
# end of Configuration
# CONFIG_PACKAGE_ead is not set
CONFIG_PACKAGE_firewall=y
CONFIG_PACKAGE_fstools=y
CONFIG_FSTOOLS_UBIFS_EXTROOT=y
# CONFIG_FSTOOLS_OVL_MOUNT_FULL_ACCESS_TIME is not set
# CONFIG_FSTOOLS_OVL_MOUNT_COMPRESS_ZLIB is not set
CONFIG_PACKAGE_fwtool=y
CONFIG_PACKAGE_getrandom=y
CONFIG_PACKAGE_jsonfilter=y
CONFIG_PACKAGE_libatomic=y
CONFIG_PACKAGE_libc=y
CONFIG_PACKAGE_libgcc=y
# CONFIG_PACKAGE_libgomp is not set
CONFIG_PACKAGE_libpthread=y
CONFIG_PACKAGE_librt=y
CONFIG_PACKAGE_libstdcpp=y
CONFIG_PACKAGE_logd=y
CONFIG_PACKAGE_mtd=y
CONFIG_PACKAGE_netifd=y
# CONFIG_PACKAGE_nft-qos is not set
# CONFIG_PACKAGE_om-watchdog is not set
CONFIG_PACKAGE_openwrt-keyring=y
CONFIG_PACKAGE_opkg=y
CONFIG_PACKAGE_procd=y
#
# Configuration
#
# CONFIG_PROCD_SHOW_BOOT is not set
# CONFIG_PROCD_ZRAM_TMPFS is not set
# end of Configuration
# CONFIG_PACKAGE_procd-seccomp is not set
# CONFIG_PACKAGE_procd-ujail is not set
# CONFIG_PACKAGE_procd-ujail-console is not set
# CONFIG_PACKAGE_qos-scripts is not set
CONFIG_PACKAGE_resolveip=y
CONFIG_PACKAGE_rpcd=y
# CONFIG_PACKAGE_rpcd-mod-file is not set
# CONFIG_PACKAGE_rpcd-mod-iwinfo is not set
# CONFIG_PACKAGE_rpcd-mod-rpcsys is not set
# CONFIG_PACKAGE_snapshot-tool is not set
# CONFIG_PACKAGE_sqm-scripts is not set
# CONFIG_PACKAGE_sqm-scripts-extra is not set
CONFIG_PACKAGE_swconfig=y
CONFIG_PACKAGE_ubox=y
CONFIG_PACKAGE_ubus=y
CONFIG_PACKAGE_ubusd=y
# CONFIG_PACKAGE_ucert is not set
# CONFIG_PACKAGE_ucert-full is not set
CONFIG_PACKAGE_uci=y
CONFIG_PACKAGE_urandom-seed=y
CONFIG_PACKAGE_urngd=y
CONFIG_PACKAGE_usign=y
# CONFIG_PACKAGE_wireless-tools is not set
# CONFIG_PACKAGE_zram-swap is not set
# end of Base system
#
# Administration
#
#
# OpenWISP
#
# CONFIG_PACKAGE_openwisp-config-cyassl is not set
# CONFIG_PACKAGE_openwisp-config-mbedtls is not set
# CONFIG_PACKAGE_openwisp-config-nossl is not set
# CONFIG_PACKAGE_openwisp-config-openssl is not set
# end of OpenWISP
#
# Zabbix
#
# CONFIG_PACKAGE_zabbix-agentd is not set
#
# SSL support
#
# CONFIG_ZABBIX_OPENSSL is not set
# CONFIG_ZABBIX_GNUTLS is not set
CONFIG_ZABBIX_NOSSL=y
# CONFIG_PACKAGE_zabbix-extra-mac80211 is not set
# CONFIG_PACKAGE_zabbix-extra-network is not set
# CONFIG_PACKAGE_zabbix-extra-wifi is not set
# CONFIG_PACKAGE_zabbix-get is not set
# CONFIG_PACKAGE_zabbix-proxy is not set
# CONFIG_PACKAGE_zabbix-sender is not set
# CONFIG_PACKAGE_zabbix-server is not set
#
# Database Software
#
# CONFIG_ZABBIX_MYSQL is not set
CONFIG_ZABBIX_POSTGRESQL=y
# CONFIG_PACKAGE_zabbix-server-frontend is not set
# end of Zabbix
# CONFIG_PACKAGE_atop is not set
# CONFIG_PACKAGE_backuppc is not set
# CONFIG_PACKAGE_debootstrap is not set
# CONFIG_PACKAGE_gkrellmd is not set
#CONFIG_PACKAGE_gotop=y
#CONFIG_PACKAGE_htop=y
# CONFIG_PACKAGE_ipmitool is not set
# CONFIG_PACKAGE_monit is not set
# CONFIG_PACKAGE_monit-nossl is not set
# CONFIG_PACKAGE_muninlite is not set
# CONFIG_PACKAGE_netatop is not set
# CONFIG_PACKAGE_netdata is not set
# CONFIG_PACKAGE_nyx is not set
# CONFIG_PACKAGE_schroot is not set
#
# Configuration
#
# CONFIG_SCHROOT_BTRFS is not set
# CONFIG_SCHROOT_LOOPBACK is not set
# CONFIG_SCHROOT_LVM is not set
# CONFIG_SCHROOT_UUID is not set
# end of Configuration
# CONFIG_PACKAGE_sudo is not set
# CONFIG_PACKAGE_syslog-ng is not set
# end of Administration
#
# Boot Loaders
#
# end of Boot Loaders
#
# Development
#
#
# Libraries
#
# CONFIG_PACKAGE_libncurses-dev is not set
# CONFIG_PACKAGE_libxml2-dev is not set
# CONFIG_PACKAGE_zlib-dev is not set
# end of Libraries
# CONFIG_PACKAGE_ar is not set
# CONFIG_PACKAGE_autoconf is not set
# CONFIG_PACKAGE_automake is not set
# CONFIG_PACKAGE_binutils is not set
# CONFIG_PACKAGE_diffutils is not set
# CONFIG_PACKAGE_gcc is not set
# CONFIG_PACKAGE_gdb is not set
# CONFIG_PACKAGE_gdbserver is not set
# CONFIG_PACKAGE_libtool-bin is not set
# CONFIG_PACKAGE_lpc21isp is not set
# CONFIG_PACKAGE_lttng-tools is not set
# CONFIG_PACKAGE_m4 is not set
# CONFIG_PACKAGE_make is not set
# CONFIG_PACKAGE_meson is not set
# CONFIG_PACKAGE_mt76-test is not set
# CONFIG_PACKAGE_ninja is not set
# CONFIG_PACKAGE_objdump is not set
# CONFIG_PACKAGE_patch is not set
# CONFIG_PACKAGE_pkg-config is not set
# CONFIG_PACKAGE_pkgconf is not set
# CONFIG_PACKAGE_trace-cmd is not set
# CONFIG_PACKAGE_trace-cmd-extra is not set
# CONFIG_PACKAGE_valgrind is not set
# end of Development
#
# Extra packages
#
# CONFIG_PACKAGE_automount is not set
# CONFIG_PACKAGE_autosamba is not set
# CONFIG_PACKAGE_ipv6helper is not set
# CONFIG_PACKAGE_jose is not set
# CONFIG_PACKAGE_k3wifi is not set
# CONFIG_PACKAGE_libjose is not set
# CONFIG_PACKAGE_tang is not set
# CONFIG_PACKAGE_wireguard-tools is not set
# end of Extra packages
#
# Firmware
#
#
# ath10k Board-Specific Overrides
#
# end of ath10k Board-Specific Overrides
# CONFIG_PACKAGE_aircard-pcmcia-firmware is not set
# CONFIG_PACKAGE_amdgpu-firmware is not set
# CONFIG_PACKAGE_ar3k-firmware is not set
# CONFIG_PACKAGE_ath10k-board-qca4019 is not set
# CONFIG_PACKAGE_ath10k-board-qca9887 is not set
# CONFIG_PACKAGE_ath10k-board-qca9888 is not set
# CONFIG_PACKAGE_ath10k-board-qca988x is not set
# CONFIG_PACKAGE_ath10k-board-qca9984 is not set
# CONFIG_PACKAGE_ath10k-board-qca99x0 is not set
# CONFIG_PACKAGE_ath10k-firmware-qca4019 is not set
# CONFIG_PACKAGE_ath10k-firmware-qca4019-ct is not set
# CONFIG_PACKAGE_ath10k-firmware-qca4019-ct-full-htt is not set
# CONFIG_PACKAGE_ath10k-firmware-qca4019-ct-htt is not set
# CONFIG_PACKAGE_ath10k-firmware-qca6174 is not set
# CONFIG_PACKAGE_ath10k-firmware-qca9887 is not set
# CONFIG_PACKAGE_ath10k-firmware-qca9887-ct is not set
# CONFIG_PACKAGE_ath10k-firmware-qca9887-ct-full-htt is not set
# CONFIG_PACKAGE_ath10k-firmware-qca9888 is not set
# CONFIG_PACKAGE_ath10k-firmware-qca9888-ct is not set
# CONFIG_PACKAGE_ath10k-firmware-qca9888-ct-full-htt is not set
# CONFIG_PACKAGE_ath10k-firmware-qca9888-ct-htt is not set
# CONFIG_PACKAGE_ath10k-firmware-qca988x is not set
# CONFIG_PACKAGE_ath10k-firmware-qca988x-ct is not set
# CONFIG_PACKAGE_ath10k-firmware-qca988x-ct-full-htt is not set
# CONFIG_PACKAGE_ath10k-firmware-qca9984 is not set
# CONFIG_PACKAGE_ath10k-firmware-qca9984-ct is not set
# CONFIG_PACKAGE_ath10k-firmware-qca9984-ct-full-htt is not set
# CONFIG_PACKAGE_ath10k-firmware-qca9984-ct-htt is not set
# CONFIG_PACKAGE_ath10k-firmware-qca99x0 is not set
# CONFIG_PACKAGE_ath10k-firmware-qca99x0-ct is not set
# CONFIG_PACKAGE_ath10k-firmware-qca99x0-ct-full-htt is not set
# CONFIG_PACKAGE_ath10k-firmware-qca99x0-ct-htt is not set
# CONFIG_PACKAGE_ath6k-firmware is not set
# CONFIG_PACKAGE_ath9k-htc-firmware is not set
# CONFIG_PACKAGE_b43legacy-firmware is not set
# CONFIG_PACKAGE_bnx2-firmware is not set
# CONFIG_PACKAGE_bnx2x-firmware is not set
# CONFIG_PACKAGE_brcmfmac-firmware-4329-sdio is not set
# CONFIG_PACKAGE_brcmfmac-firmware-43362-sdio is not set
# CONFIG_PACKAGE_brcmfmac-firmware-43430-sdio is not set
# CONFIG_PACKAGE_brcmfmac-firmware-43430-sdio-rpi-3b is not set
# CONFIG_PACKAGE_brcmfmac-firmware-43430-sdio-rpi-zero-w is not set
# CONFIG_PACKAGE_brcmfmac-firmware-43430a0-sdio is not set
# CONFIG_PACKAGE_brcmfmac-firmware-43455-sdio is not set
# CONFIG_PACKAGE_brcmfmac-firmware-43455-sdio-rpi-3b-plus is not set
# CONFIG_PACKAGE_brcmfmac-firmware-43455-sdio-rpi-4b is not set
# CONFIG_PACKAGE_brcmfmac-firmware-43602a1-pcie is not set
# CONFIG_PACKAGE_brcmfmac-firmware-4366b1-pcie is not set
# CONFIG_PACKAGE_brcmfmac-firmware-4366c0-pcie is not set
# CONFIG_PACKAGE_brcmfmac-firmware-usb is not set
# CONFIG_PACKAGE_brcmsmac-firmware is not set
# CONFIG_PACKAGE_carl9170-firmware is not set
# CONFIG_PACKAGE_cypress-firmware-43012-sdio is not set
# CONFIG_PACKAGE_cypress-firmware-43340-sdio is not set
# CONFIG_PACKAGE_cypress-firmware-43362-sdio is not set
# CONFIG_PACKAGE_cypress-firmware-4339-sdio is not set
# CONFIG_PACKAGE_cypress-firmware-43430-sdio is not set
# CONFIG_PACKAGE_cypress-firmware-43455-sdio is not set
# CONFIG_PACKAGE_cypress-firmware-4354-sdio is not set
# CONFIG_PACKAGE_cypress-firmware-4356-pcie is not set
# CONFIG_PACKAGE_cypress-firmware-4356-sdio is not set
# CONFIG_PACKAGE_cypress-firmware-43570-pcie is not set
# CONFIG_PACKAGE_cypress-firmware-4359-pcie is not set
# CONFIG_PACKAGE_cypress-firmware-4359-sdio is not set
# CONFIG_PACKAGE_cypress-firmware-4373-sdio is not set
# CONFIG_PACKAGE_cypress-firmware-4373-usb is not set
# CONFIG_PACKAGE_cypress-firmware-54591-pcie is not set
# CONFIG_PACKAGE_cypress-firmware-89459-pcie is not set
# CONFIG_PACKAGE_e100-firmware is not set
# CONFIG_PACKAGE_edgeport-firmware is not set
# CONFIG_PACKAGE_eip197-mini-firmware is not set
# CONFIG_PACKAGE_ibt-firmware is not set
# CONFIG_PACKAGE_iwl3945-firmware is not set
# CONFIG_PACKAGE_iwl4965-firmware is not set
# CONFIG_PACKAGE_iwlwifi-firmware-iwl100 is not set
# CONFIG_PACKAGE_iwlwifi-firmware-iwl1000 is not set
# CONFIG_PACKAGE_iwlwifi-firmware-iwl105 is not set
# CONFIG_PACKAGE_iwlwifi-firmware-iwl135 is not set
# CONFIG_PACKAGE_iwlwifi-firmware-iwl2000 is not set
# CONFIG_PACKAGE_iwlwifi-firmware-iwl2030 is not set
# CONFIG_PACKAGE_iwlwifi-firmware-iwl3160 is not set
# CONFIG_PACKAGE_iwlwifi-firmware-iwl3168 is not set
# CONFIG_PACKAGE_iwlwifi-firmware-iwl5000 is not set
# CONFIG_PACKAGE_iwlwifi-firmware-iwl5150 is not set
# CONFIG_PACKAGE_iwlwifi-firmware-iwl6000g2 is not set
# CONFIG_PACKAGE_iwlwifi-firmware-iwl6000g2a is not set
# CONFIG_PACKAGE_iwlwifi-firmware-iwl6000g2b is not set
# CONFIG_PACKAGE_iwlwifi-firmware-iwl6050 is not set
# CONFIG_PACKAGE_iwlwifi-firmware-iwl7260 is not set
# CONFIG_PACKAGE_iwlwifi-firmware-iwl7265 is not set
# CONFIG_PACKAGE_iwlwifi-firmware-iwl7265d is not set
# CONFIG_PACKAGE_iwlwifi-firmware-iwl8260c is not set
# CONFIG_PACKAGE_iwlwifi-firmware-iwl8265 is not set
# CONFIG_PACKAGE_iwlwifi-firmware-iwl9000 is not set
# CONFIG_PACKAGE_iwlwifi-firmware-iwl9260 is not set
# CONFIG_PACKAGE_jboot-tools is not set
# CONFIG_PACKAGE_libertas-sdio-firmware is not set
# CONFIG_PACKAGE_libertas-spi-firmware is not set
# CONFIG_PACKAGE_libertas-usb-firmware is not set
# CONFIG_PACKAGE_mt7601u-firmware is not set
# CONFIG_PACKAGE_mt7622bt-firmware is not set
# CONFIG_PACKAGE_mwifiex-pcie-firmware is not set
# CONFIG_PACKAGE_mwifiex-sdio-firmware is not set
# CONFIG_PACKAGE_mwl8k-firmware is not set
# CONFIG_PACKAGE_p54-pci-firmware is not set
# CONFIG_PACKAGE_p54-spi-firmware is not set
# CONFIG_PACKAGE_p54-usb-firmware is not set
# CONFIG_PACKAGE_prism54-firmware is not set
# CONFIG_PACKAGE_r8169-firmware is not set
# CONFIG_PACKAGE_radeon-firmware is not set
# CONFIG_PACKAGE_rs9113-firmware is not set
# CONFIG_PACKAGE_rt2800-pci-firmware is not set
# CONFIG_PACKAGE_rt2800-usb-firmware is not set
# CONFIG_PACKAGE_rt61-pci-firmware is not set
# CONFIG_PACKAGE_rt73-usb-firmware is not set
# CONFIG_PACKAGE_rtl8188eu-firmware is not set
# CONFIG_PACKAGE_rtl8192ce-firmware is not set
# CONFIG_PACKAGE_rtl8192cu-firmware is not set
# CONFIG_PACKAGE_rtl8192de-firmware is not set
# CONFIG_PACKAGE_rtl8192eu-firmware is not set
# CONFIG_PACKAGE_rtl8192se-firmware is not set
# CONFIG_PACKAGE_rtl8192su-firmware is not set
# CONFIG_PACKAGE_rtl8723au-firmware is not set
# CONFIG_PACKAGE_rtl8723bs-firmware is not set
# CONFIG_PACKAGE_rtl8723bu-firmware is not set
# CONFIG_PACKAGE_rtl8821ae-firmware is not set
# CONFIG_PACKAGE_rtl8822be-firmware is not set
# CONFIG_PACKAGE_rtl8822ce-firmware is not set
# CONFIG_PACKAGE_ti-3410-firmware is not set
# CONFIG_PACKAGE_ti-5052-firmware is not set
# CONFIG_PACKAGE_wil6210-firmware is not set
CONFIG_PACKAGE_wireless-regdb=y
# CONFIG_PACKAGE_wl12xx-firmware is not set
# CONFIG_PACKAGE_wl18xx-firmware is not set
# end of Firmware
#
# Fonts
#
#
# DejaVu
#
# CONFIG_PACKAGE_dejavu-fonts-ttf-DejaVuMathTeXGyre is not set
# CONFIG_PACKAGE_dejavu-fonts-ttf-DejaVuSans is not set
# CONFIG_PACKAGE_dejavu-fonts-ttf-DejaVuSans-Bold is not set
# CONFIG_PACKAGE_dejavu-fonts-ttf-DejaVuSans-BoldOblique is not set
# CONFIG_PACKAGE_dejavu-fonts-ttf-DejaVuSans-ExtraLight is not set
# CONFIG_PACKAGE_dejavu-fonts-ttf-DejaVuSans-Oblique is not set
# CONFIG_PACKAGE_dejavu-fonts-ttf-DejaVuSansCondensed is not set
# CONFIG_PACKAGE_dejavu-fonts-ttf-DejaVuSansCondensed-Bold is not set
# CONFIG_PACKAGE_dejavu-fonts-ttf-DejaVuSansCondensed-BoldOblique is not set
# CONFIG_PACKAGE_dejavu-fonts-ttf-DejaVuSansCondensed-Oblique is not set
# CONFIG_PACKAGE_dejavu-fonts-ttf-DejaVuSansMono is not set
# CONFIG_PACKAGE_dejavu-fonts-ttf-DejaVuSansMono-Bold is not set
# CONFIG_PACKAGE_dejavu-fonts-ttf-DejaVuSansMono-BoldOblique is not set
# CONFIG_PACKAGE_dejavu-fonts-ttf-DejaVuSansMono-Oblique is not set
# CONFIG_PACKAGE_dejavu-fonts-ttf-DejaVuSerif is not set
# CONFIG_PACKAGE_dejavu-fonts-ttf-DejaVuSerif-Bold is not set
# CONFIG_PACKAGE_dejavu-fonts-ttf-DejaVuSerif-BoldItalic is not set
# CONFIG_PACKAGE_dejavu-fonts-ttf-DejaVuSerif-Italic is not set
# CONFIG_PACKAGE_dejavu-fonts-ttf-DejaVuSerifCondensed is not set
# CONFIG_PACKAGE_dejavu-fonts-ttf-DejaVuSerifCondensed-Bold is not set
# CONFIG_PACKAGE_dejavu-fonts-ttf-DejaVuSerifCondensed-BoldItalic is not set
# CONFIG_PACKAGE_dejavu-fonts-ttf-DejaVuSerifCondensed-Italic is not set
# end of DejaVu
# end of Fonts
#
# Kernel modules
#
#
# Block Devices
#
# CONFIG_PACKAGE_kmod-aoe is not set
# CONFIG_PACKAGE_kmod-ata-ahci is not set
# CONFIG_PACKAGE_kmod-ata-artop is not set
# CONFIG_PACKAGE_kmod-ata-core is not set
# CONFIG_PACKAGE_kmod-ata-marvell-sata is not set
# CONFIG_PACKAGE_kmod-ata-nvidia-sata is not set
# CONFIG_PACKAGE_kmod-ata-pdc202xx-old is not set
# CONFIG_PACKAGE_kmod-ata-piix is not set
# CONFIG_PACKAGE_kmod-ata-sil is not set
# CONFIG_PACKAGE_kmod-ata-sil24 is not set
# CONFIG_PACKAGE_kmod-ata-via-sata is not set
# CONFIG_PACKAGE_kmod-block2mtd is not set
# CONFIG_PACKAGE_kmod-dax is not set
# CONFIG_PACKAGE_kmod-dm is not set
# CONFIG_PACKAGE_kmod-dm-raid is not set
# CONFIG_PACKAGE_kmod-iosched-bfq is not set
# CONFIG_PACKAGE_kmod-iscsi-initiator is not set
# CONFIG_PACKAGE_kmod-loop is not set
# CONFIG_PACKAGE_kmod-md-mod is not set
# CONFIG_PACKAGE_kmod-nbd is not set
# CONFIG_PACKAGE_kmod-scsi-cdrom is not set
CONFIG_PACKAGE_kmod-scsi-core=y
# CONFIG_PACKAGE_kmod-scsi-generic is not set
# CONFIG_PACKAGE_kmod-scsi-tape is not set
# end of Block Devices
#
# CAN Support
#
# CONFIG_PACKAGE_kmod-can is not set
# end of CAN Support
#
# Cryptographic API modules
#
CONFIG_PACKAGE_kmod-crypto-aead=y
CONFIG_PACKAGE_kmod-crypto-arc4=y
CONFIG_PACKAGE_kmod-crypto-authenc=y
# CONFIG_PACKAGE_kmod-crypto-cbc is not set
# CONFIG_PACKAGE_kmod-crypto-ccm is not set
# CONFIG_PACKAGE_kmod-crypto-cmac is not set
CONFIG_PACKAGE_kmod-crypto-crc32c=y
# CONFIG_PACKAGE_kmod-crypto-ctr is not set
# CONFIG_PACKAGE_kmod-crypto-cts is not set
# CONFIG_PACKAGE_kmod-crypto-deflate is not set
# CONFIG_PACKAGE_kmod-crypto-des is not set
CONFIG_PACKAGE_kmod-crypto-ecb=y
# CONFIG_PACKAGE_kmod-crypto-ecdh is not set
# CONFIG_PACKAGE_kmod-crypto-echainiv is not set
# CONFIG_PACKAGE_kmod-crypto-fcrypt is not set
# CONFIG_PACKAGE_kmod-crypto-gcm is not set
# CONFIG_PACKAGE_kmod-crypto-gf128 is not set
# CONFIG_PACKAGE_kmod-crypto-ghash is not set
CONFIG_PACKAGE_kmod-crypto-hash=y
# CONFIG_PACKAGE_kmod-crypto-hmac is not set
# CONFIG_PACKAGE_kmod-crypto-hw-ccp is not set
# CONFIG_PACKAGE_kmod-crypto-hw-geode is not set
# CONFIG_PACKAGE_kmod-crypto-hw-hifn-795x is not set
# CONFIG_PACKAGE_kmod-crypto-hw-padlock is not set
# CONFIG_PACKAGE_kmod-crypto-hw-talitos is not set
CONFIG_PACKAGE_kmod-crypto-manager=y
# CONFIG_PACKAGE_kmod-crypto-md4 is not set
# CONFIG_PACKAGE_kmod-crypto-md5 is not set
# CONFIG_PACKAGE_kmod-crypto-michael-mic is not set
# CONFIG_PACKAGE_kmod-crypto-misc is not set
CONFIG_PACKAGE_kmod-crypto-null=y
# CONFIG_PACKAGE_kmod-crypto-pcbc is not set
CONFIG_PACKAGE_kmod-crypto-pcompress=y
# CONFIG_PACKAGE_kmod-crypto-rmd160 is not set
# CONFIG_PACKAGE_kmod-crypto-rng is not set
# CONFIG_PACKAGE_kmod-crypto-seqiv is not set
CONFIG_PACKAGE_kmod-crypto-sha1=y
# CONFIG_PACKAGE_kmod-crypto-sha256 is not set
# CONFIG_PACKAGE_kmod-crypto-sha512 is not set
# CONFIG_PACKAGE_kmod-crypto-test is not set
CONFIG_PACKAGE_kmod-crypto-user=y
# CONFIG_PACKAGE_kmod-crypto-wq is not set
# CONFIG_PACKAGE_kmod-crypto-xcbc is not set
# CONFIG_PACKAGE_kmod-crypto-xts is not set
CONFIG_PACKAGE_kmod-cryptodev=y
# end of Cryptographic API modules
#
# Filesystems
#
# CONFIG_PACKAGE_kmod-fs-afs is not set
# CONFIG_PACKAGE_kmod-fs-antfs is not set
# CONFIG_PACKAGE_kmod-fs-autofs4 is not set
# CONFIG_PACKAGE_kmod-fs-btrfs is not set
# CONFIG_PACKAGE_kmod-fs-cifs is not set
# CONFIG_PACKAGE_kmod-fs-configfs is not set
# CONFIG_PACKAGE_kmod-fs-cramfs is not set
CONFIG_PACKAGE_kmod-fs-exfat=y
# CONFIG_PACKAGE_kmod-fs-exportfs is not set
CONFIG_PACKAGE_kmod-fs-ext4=y
# CONFIG_PACKAGE_kmod-fs-f2fs is not set
# CONFIG_PACKAGE_kmod-fs-fscache is not set
# CONFIG_PACKAGE_kmod-fs-hfs is not set
# CONFIG_PACKAGE_kmod-fs-hfsplus is not set
# CONFIG_PACKAGE_kmod-fs-isofs is not set
# CONFIG_PACKAGE_kmod-fs-jfs is not set
# CONFIG_PACKAGE_kmod-fs-ksmbd is not set
# CONFIG_PACKAGE_kmod-fs-minix is not set
# CONFIG_PACKAGE_kmod-fs-msdos is not set
# CONFIG_PACKAGE_kmod-fs-nfs is not set
# CONFIG_PACKAGE_kmod-fs-nfs-common is not set
# CONFIG_PACKAGE_kmod-fs-nfs-common-rpcsec is not set
# CONFIG_PACKAGE_kmod-fs-nfs-v3 is not set
# CONFIG_PACKAGE_kmod-fs-nfs-v4 is not set
# CONFIG_PACKAGE_kmod-fs-nfsd is not set
CONFIG_PACKAGE_kmod-fs-ntfs=y
# CONFIG_PACKAGE_kmod-fs-reiserfs is not set
# CONFIG_PACKAGE_kmod-fs-squashfs is not set
# CONFIG_PACKAGE_kmod-fs-udf is not set
CONFIG_PACKAGE_kmod-fs-vfat=y
# CONFIG_PACKAGE_kmod-fs-xfs is not set
# CONFIG_PACKAGE_kmod-fuse is not set
# end of Filesystems
#
# FireWire support
#
# CONFIG_PACKAGE_kmod-firewire is not set
# end of FireWire support
#
# Hardware Monitoring Support
#
# CONFIG_PACKAGE_kmod-hwmon-ad7418 is not set
# CONFIG_PACKAGE_kmod-hwmon-adcxx is not set
# CONFIG_PACKAGE_kmod-hwmon-ads1015 is not set
# CONFIG_PACKAGE_kmod-hwmon-adt7410 is not set
# CONFIG_PACKAGE_kmod-hwmon-adt7475 is not set
# CONFIG_PACKAGE_kmod-hwmon-core is not set
# CONFIG_PACKAGE_kmod-hwmon-dme1737 is not set
# CONFIG_PACKAGE_kmod-hwmon-drivetemp is not set
# CONFIG_PACKAGE_kmod-hwmon-gpiofan is not set
# CONFIG_PACKAGE_kmod-hwmon-ina209 is not set
# CONFIG_PACKAGE_kmod-hwmon-ina2xx is not set
# CONFIG_PACKAGE_kmod-hwmon-it87 is not set
# CONFIG_PACKAGE_kmod-hwmon-lm63 is not set
# CONFIG_PACKAGE_kmod-hwmon-lm75 is not set
# CONFIG_PACKAGE_kmod-hwmon-lm77 is not set
# CONFIG_PACKAGE_kmod-hwmon-lm85 is not set
# CONFIG_PACKAGE_kmod-hwmon-lm90 is not set
# CONFIG_PACKAGE_kmod-hwmon-lm92 is not set
# CONFIG_PACKAGE_kmod-hwmon-lm95241 is not set
# CONFIG_PACKAGE_kmod-hwmon-ltc4151 is not set
# CONFIG_PACKAGE_kmod-hwmon-mcp3021 is not set
# CONFIG_PACKAGE_kmod-hwmon-pwmfan is not set
# CONFIG_PACKAGE_kmod-hwmon-sch5627 is not set
# CONFIG_PACKAGE_kmod-hwmon-sht21 is not set
# CONFIG_PACKAGE_kmod-hwmon-tmp102 is not set
# CONFIG_PACKAGE_kmod-hwmon-tmp103 is not set
# CONFIG_PACKAGE_kmod-hwmon-tmp421 is not set
# CONFIG_PACKAGE_kmod-hwmon-vid is not set
# CONFIG_PACKAGE_kmod-hwmon-w83793 is not set
# CONFIG_PACKAGE_kmod-pmbus-core is not set
# CONFIG_PACKAGE_kmod-pmbus-zl6100 is not set
# end of Hardware Monitoring Support
#
# I2C support
#
# CONFIG_PACKAGE_kmod-i2c-algo-bit is not set
# CONFIG_PACKAGE_kmod-i2c-algo-pca is not set
# CONFIG_PACKAGE_kmod-i2c-algo-pcf is not set
# CONFIG_PACKAGE_kmod-i2c-core is not set
# CONFIG_PACKAGE_kmod-i2c-gpio is not set
# CONFIG_PACKAGE_kmod-i2c-mux is not set
# CONFIG_PACKAGE_kmod-i2c-mux-gpio is not set
# CONFIG_PACKAGE_kmod-i2c-mux-pca9541 is not set
# CONFIG_PACKAGE_kmod-i2c-mux-pca954x is not set
# CONFIG_PACKAGE_kmod-i2c-pxa is not set
# CONFIG_PACKAGE_kmod-i2c-smbus is not set
# CONFIG_PACKAGE_kmod-i2c-tiny-usb is not set
# end of I2C support
#
# Industrial I/O Modules
#
# CONFIG_PACKAGE_kmod-iio-ad799x is not set
# CONFIG_PACKAGE_kmod-iio-am2315 is not set
# CONFIG_PACKAGE_kmod-iio-bh1750 is not set
# CONFIG_PACKAGE_kmod-iio-bme680 is not set
# CONFIG_PACKAGE_kmod-iio-bme680-i2c is not set
# CONFIG_PACKAGE_kmod-iio-bme680-spi is not set
# CONFIG_PACKAGE_kmod-iio-bmp280 is not set
# CONFIG_PACKAGE_kmod-iio-bmp280-i2c is not set
# CONFIG_PACKAGE_kmod-iio-bmp280-spi is not set
# CONFIG_PACKAGE_kmod-iio-ccs811 is not set
# CONFIG_PACKAGE_kmod-iio-core is not set
# CONFIG_PACKAGE_kmod-iio-dht11 is not set
# CONFIG_PACKAGE_kmod-iio-fxas21002c is not set
# CONFIG_PACKAGE_kmod-iio-fxas21002c-i2c is not set
# CONFIG_PACKAGE_kmod-iio-fxas21002c-spi is not set
# CONFIG_PACKAGE_kmod-iio-fxos8700 is not set
# CONFIG_PACKAGE_kmod-iio-fxos8700-i2c is not set
# CONFIG_PACKAGE_kmod-iio-fxos8700-spi is not set
# CONFIG_PACKAGE_kmod-iio-hmc5843 is not set
# CONFIG_PACKAGE_kmod-iio-htu21 is not set
# CONFIG_PACKAGE_kmod-iio-kfifo-buf is not set
# CONFIG_PACKAGE_kmod-iio-lsm6dsx is not set
# CONFIG_PACKAGE_kmod-iio-lsm6dsx-i2c is not set
# CONFIG_PACKAGE_kmod-iio-lsm6dsx-spi is not set
# CONFIG_PACKAGE_kmod-iio-si7020 is not set
# CONFIG_PACKAGE_kmod-iio-sps30 is not set
# CONFIG_PACKAGE_kmod-iio-st_accel is not set
# CONFIG_PACKAGE_kmod-iio-st_accel-i2c is not set
# CONFIG_PACKAGE_kmod-iio-st_accel-spi is not set
# CONFIG_PACKAGE_kmod-iio-tsl4531 is not set
# CONFIG_PACKAGE_kmod-industrialio-triggered-buffer is not set
# end of Industrial I/O Modules
#
# Input modules
#
# CONFIG_PACKAGE_kmod-hid is not set
# CONFIG_PACKAGE_kmod-hid-generic is not set
# CONFIG_PACKAGE_kmod-input-core is not set
# CONFIG_PACKAGE_kmod-input-evdev is not set
# CONFIG_PACKAGE_kmod-input-gpio-encoder is not set
# CONFIG_PACKAGE_kmod-input-gpio-keys is not set
# CONFIG_PACKAGE_kmod-input-gpio-keys-polled is not set
# CONFIG_PACKAGE_kmod-input-joydev is not set
# CONFIG_PACKAGE_kmod-input-matrixkmap is not set
# CONFIG_PACKAGE_kmod-input-polldev is not set
# CONFIG_PACKAGE_kmod-input-touchscreen-ads7846 is not set
# CONFIG_PACKAGE_kmod-input-uinput is not set
# end of Input modules
#
# LED modules
#
CONFIG_PACKAGE_kmod-leds-gpio=y
# CONFIG_PACKAGE_kmod-leds-pca963x is not set
# CONFIG_PACKAGE_kmod-ledtrig-activity is not set
# CONFIG_PACKAGE_kmod-ledtrig-default-on is not set
# CONFIG_PACKAGE_kmod-ledtrig-gpio is not set
# CONFIG_PACKAGE_kmod-ledtrig-heartbeat is not set
# CONFIG_PACKAGE_kmod-ledtrig-netdev is not set
# CONFIG_PACKAGE_kmod-ledtrig-oneshot is not set
# CONFIG_PACKAGE_kmod-ledtrig-timer is not set
# CONFIG_PACKAGE_kmod-ledtrig-transient is not set
# end of LED modules
#
# Libraries
#
CONFIG_PACKAGE_kmod-asn1-decoder=y
# CONFIG_PACKAGE_kmod-lib-cordic is not set
CONFIG_PACKAGE_kmod-lib-crc-ccitt=y
# CONFIG_PACKAGE_kmod-lib-crc-itu-t is not set
CONFIG_PACKAGE_kmod-lib-crc16=y
# CONFIG_PACKAGE_kmod-lib-crc32c is not set
# CONFIG_PACKAGE_kmod-lib-crc7 is not set
# CONFIG_PACKAGE_kmod-lib-crc8 is not set
# CONFIG_PACKAGE_kmod-lib-lz4 is not set
CONFIG_PACKAGE_kmod-lib-textsearch=y
# end of Libraries
#
# Native Language Support
#
CONFIG_PACKAGE_kmod-nls-base=y
# CONFIG_PACKAGE_kmod-nls-cp1250 is not set
# CONFIG_PACKAGE_kmod-nls-cp1251 is not set
CONFIG_PACKAGE_kmod-nls-cp437=y
# CONFIG_PACKAGE_kmod-nls-cp775 is not set
# CONFIG_PACKAGE_kmod-nls-cp850 is not set
# CONFIG_PACKAGE_kmod-nls-cp852 is not set
# CONFIG_PACKAGE_kmod-nls-cp862 is not set
# CONFIG_PACKAGE_kmod-nls-cp864 is not set
# CONFIG_PACKAGE_kmod-nls-cp866 is not set
# CONFIG_PACKAGE_kmod-nls-cp932 is not set
# CONFIG_PACKAGE_kmod-nls-cp936 is not set
# CONFIG_PACKAGE_kmod-nls-cp950 is not set
CONFIG_PACKAGE_kmod-nls-iso8859-1=y
# CONFIG_PACKAGE_kmod-nls-iso8859-13 is not set
# CONFIG_PACKAGE_kmod-nls-iso8859-15 is not set
# CONFIG_PACKAGE_kmod-nls-iso8859-2 is not set
# CONFIG_PACKAGE_kmod-nls-iso8859-6 is not set
# CONFIG_PACKAGE_kmod-nls-iso8859-8 is not set
# CONFIG_PACKAGE_kmod-nls-koi8r is not set
CONFIG_PACKAGE_kmod-nls-utf8=y
# end of Native Language Support
#
# Netfilter Extensions
#
# CONFIG_PACKAGE_kmod-arptables is not set
# CONFIG_PACKAGE_kmod-br-netfilter is not set
# CONFIG_PACKAGE_kmod-ebtables is not set
# CONFIG_PACKAGE_kmod-ebtables-ipv4 is not set
# CONFIG_PACKAGE_kmod-ebtables-ipv6 is not set
# CONFIG_PACKAGE_kmod-ebtables-watchers is not set
CONFIG_PACKAGE_kmod-ip6tables=y
# CONFIG_PACKAGE_kmod-ip6tables-extra is not set
# CONFIG_PACKAGE_kmod-ipt-account is not set
# CONFIG_PACKAGE_kmod-ipt-chaos is not set
# CONFIG_PACKAGE_kmod-ipt-checksum is not set
# CONFIG_PACKAGE_kmod-ipt-cluster is not set
# CONFIG_PACKAGE_kmod-ipt-clusterip is not set
# CONFIG_PACKAGE_kmod-ipt-compat-xtables is not set
# CONFIG_PACKAGE_kmod-ipt-condition is not set
CONFIG_PACKAGE_kmod-ipt-conntrack=y
# CONFIG_PACKAGE_kmod-ipt-conntrack-extra is not set
# CONFIG_PACKAGE_kmod-ipt-conntrack-label is not set
CONFIG_PACKAGE_kmod-ipt-core=y
# CONFIG_PACKAGE_kmod-ipt-debug is not set
# CONFIG_PACKAGE_kmod-ipt-delude is not set
# CONFIG_PACKAGE_kmod-ipt-dhcpmac is not set
# CONFIG_PACKAGE_kmod-ipt-dnetmap is not set
CONFIG_PACKAGE_kmod-ipt-extra=y
# CONFIG_PACKAGE_kmod-ipt-filter is not set
CONFIG_PACKAGE_kmod-ipt-fullconenat=y
# CONFIG_PACKAGE_kmod-ipt-fuzzy is not set
# CONFIG_PACKAGE_kmod-ipt-geoip is not set
# CONFIG_PACKAGE_kmod-ipt-hashlimit is not set
# CONFIG_PACKAGE_kmod-ipt-iface is not set
# CONFIG_PACKAGE_kmod-ipt-ipmark is not set
# CONFIG_PACKAGE_kmod-ipt-ipopt is not set
# CONFIG_PACKAGE_kmod-ipt-ipp2p is not set
# CONFIG_PACKAGE_kmod-ipt-iprange is not set
# CONFIG_PACKAGE_kmod-ipt-ipsec is not set
CONFIG_PACKAGE_kmod-ipt-ipset=y
# CONFIG_PACKAGE_kmod-ipt-ipv4options is not set
# CONFIG_PACKAGE_kmod-ipt-led is not set
# CONFIG_PACKAGE_kmod-ipt-length2 is not set
# CONFIG_PACKAGE_kmod-ipt-logmark is not set
# CONFIG_PACKAGE_kmod-ipt-lscan is not set
# CONFIG_PACKAGE_kmod-ipt-lua is not set
CONFIG_PACKAGE_kmod-ipt-nat=y
# CONFIG_PACKAGE_kmod-ipt-nat-extra is not set
# CONFIG_PACKAGE_kmod-ipt-nat6 is not set
# CONFIG_PACKAGE_kmod-ipt-nathelper-rtsp is not set
# CONFIG_PACKAGE_kmod-ipt-nflog is not set
# CONFIG_PACKAGE_kmod-ipt-nfqueue is not set
CONFIG_PACKAGE_kmod-ipt-offload=y
# CONFIG_PACKAGE_kmod-ipt-physdev is not set
# CONFIG_PACKAGE_kmod-ipt-proto is not set
# CONFIG_PACKAGE_kmod-ipt-psd is not set
# CONFIG_PACKAGE_kmod-ipt-quota2 is not set
CONFIG_PACKAGE_kmod-ipt-raw=y
# CONFIG_PACKAGE_kmod-ipt-raw6 is not set
# CONFIG_PACKAGE_kmod-ipt-rpfilter is not set
# CONFIG_PACKAGE_kmod-ipt-rtpengine is not set
# CONFIG_PACKAGE_kmod-ipt-sysrq is not set
# CONFIG_PACKAGE_kmod-ipt-tarpit is not set
# CONFIG_PACKAGE_kmod-ipt-tee is not set
CONFIG_PACKAGE_kmod-ipt-tproxy=y
# CONFIG_PACKAGE_kmod-ipt-u32 is not set
# CONFIG_PACKAGE_kmod-ipt-ulog is not set
# CONFIG_PACKAGE_kmod-netatop is not set
CONFIG_PACKAGE_kmod-nf-conntrack=y
# CONFIG_PACKAGE_kmod-nf-conntrack-netlink is not set
CONFIG_PACKAGE_kmod-nf-conntrack6=y
CONFIG_PACKAGE_kmod-nf-flow=y
CONFIG_PACKAGE_kmod-nf-ipt=y
CONFIG_PACKAGE_kmod-nf-ipt6=y
# CONFIG_PACKAGE_kmod-nf-ipvs is not set
CONFIG_PACKAGE_kmod-nf-nat=y
# CONFIG_PACKAGE_kmod-nf-nat6 is not set
CONFIG_PACKAGE_kmod-nf-nathelper=y
CONFIG_PACKAGE_kmod-nf-nathelper-extra=y
CONFIG_PACKAGE_kmod-nf-reject=y
CONFIG_PACKAGE_kmod-nf-reject6=y
CONFIG_PACKAGE_kmod-nfnetlink=y
# CONFIG_PACKAGE_kmod-nfnetlink-log is not set
# CONFIG_PACKAGE_kmod-nfnetlink-queue is not set
# CONFIG_PACKAGE_kmod-nft-arp is not set
# CONFIG_PACKAGE_kmod-nft-bridge is not set
# CONFIG_PACKAGE_kmod-nft-core is not set
# CONFIG_PACKAGE_kmod-nft-fib is not set
# CONFIG_PACKAGE_kmod-nft-nat is not set
# CONFIG_PACKAGE_kmod-nft-nat6 is not set
# CONFIG_PACKAGE_kmod-nft-netdev is not set
# CONFIG_PACKAGE_kmod-nft-offload is not set
# CONFIG_PACKAGE_kmod-nft-queue is not set
# end of Netfilter Extensions
#
# Network Devices
#
# CONFIG_PACKAGE_kmod-3c59x is not set
# CONFIG_PACKAGE_kmod-8139cp is not set
# CONFIG_PACKAGE_kmod-8139too is not set
# CONFIG_PACKAGE_kmod-alx is not set
# CONFIG_PACKAGE_kmod-atl1 is not set
# CONFIG_PACKAGE_kmod-atl1c is not set
# CONFIG_PACKAGE_kmod-atl1e is not set
# CONFIG_PACKAGE_kmod-atl2 is not set
# CONFIG_PACKAGE_kmod-b44 is not set
# CONFIG_PACKAGE_kmod-be2net is not set
# CONFIG_PACKAGE_kmod-bnx2 is not set
# CONFIG_PACKAGE_kmod-bnx2x is not set
# CONFIG_PACKAGE_kmod-dm9000 is not set
# CONFIG_PACKAGE_kmod-dummy is not set
# CONFIG_PACKAGE_kmod-e100 is not set
# CONFIG_PACKAGE_kmod-e1000 is not set
# CONFIG_PACKAGE_kmod-et131x is not set
# CONFIG_PACKAGE_kmod-ethoc is not set
# CONFIG_PACKAGE_kmod-forcedeth is not set
# CONFIG_PACKAGE_kmod-hfcmulti is not set
# CONFIG_PACKAGE_kmod-hfcpci is not set
# CONFIG_PACKAGE_kmod-i40e is not set
# CONFIG_PACKAGE_kmod-iavf is not set
# CONFIG_PACKAGE_kmod-ifb is not set
# CONFIG_PACKAGE_kmod-igb is not set
# CONFIG_PACKAGE_kmod-igc is not set
# CONFIG_PACKAGE_kmod-ixgbe is not set
# CONFIG_PACKAGE_kmod-ixgbevf is not set
# CONFIG_PACKAGE_kmod-libphy is not set
CONFIG_PACKAGE_kmod-macvlan=y
# CONFIG_PACKAGE_kmod-mdio-gpio is not set
# CONFIG_PACKAGE_kmod-mii is not set
# CONFIG_PACKAGE_kmod-mlx4-core is not set
# CONFIG_PACKAGE_kmod-mlx5-core is not set
# CONFIG_PACKAGE_kmod-natsemi is not set
# CONFIG_PACKAGE_kmod-ne2k-pci is not set
# CONFIG_PACKAGE_kmod-niu is not set
# CONFIG_PACKAGE_kmod-of-mdio is not set
# CONFIG_PACKAGE_kmod-pcnet32 is not set
# CONFIG_PACKAGE_kmod-phy-bcm84881 is not set
# CONFIG_PACKAGE_kmod-phy-broadcom is not set
# CONFIG_PACKAGE_kmod-phy-realtek is not set
# CONFIG_PACKAGE_kmod-phylink is not set
# CONFIG_PACKAGE_kmod-r6040 is not set
# CONFIG_PACKAGE_kmod-r8125 is not set
# CONFIG_PACKAGE_kmod-r8168 is not set
# CONFIG_PACKAGE_kmod-r8169 is not set
# CONFIG_PACKAGE_kmod-sfc is not set
# CONFIG_PACKAGE_kmod-sfc-falcon is not set
# CONFIG_PACKAGE_kmod-sfp is not set
# CONFIG_PACKAGE_kmod-siit is not set
# CONFIG_PACKAGE_kmod-sis190 is not set
# CONFIG_PACKAGE_kmod-sis900 is not set
# CONFIG_PACKAGE_kmod-skge is not set
# CONFIG_PACKAGE_kmod-sky2 is not set
# CONFIG_PACKAGE_kmod-solos-pci is not set
# CONFIG_PACKAGE_kmod-spi-ks8995 is not set
# CONFIG_PACKAGE_kmod-swconfig is not set
# CONFIG_PACKAGE_kmod-switch-bcm53xx is not set
# CONFIG_PACKAGE_kmod-switch-bcm53xx-mdio is not set
# CONFIG_PACKAGE_kmod-switch-ip17xx is not set
# CONFIG_PACKAGE_kmod-switch-mvsw61xx is not set
# CONFIG_PACKAGE_kmod-switch-rtl8306 is not set
# CONFIG_PACKAGE_kmod-switch-rtl8366-smi is not set
# CONFIG_PACKAGE_kmod-switch-rtl8366rb is not set
# CONFIG_PACKAGE_kmod-switch-rtl8366s is not set
# CONFIG_PACKAGE_kmod-switch-rtl8367b is not set
# CONFIG_PACKAGE_kmod-tg3 is not set
# CONFIG_PACKAGE_kmod-tulip is not set
# CONFIG_PACKAGE_kmod-via-rhine is not set
# CONFIG_PACKAGE_kmod-via-velocity is not set
# CONFIG_PACKAGE_kmod-vmxnet3 is not set
# end of Network Devices
#
# Network Support
#
# CONFIG_PACKAGE_kmod-atm is not set
# CONFIG_PACKAGE_kmod-ax25 is not set
# CONFIG_PACKAGE_kmod-batman-adv is not set
# CONFIG_PACKAGE_kmod-bonding is not set
# CONFIG_PACKAGE_kmod-bpf-test is not set
# CONFIG_PACKAGE_kmod-capi is not set
# CONFIG_PACKAGE_kmod-dnsresolver is not set
CONFIG_PACKAGE_kmod-fast-classifier=y
# CONFIG_PACKAGE_kmod-fast-classifier-noload is not set
# CONFIG_PACKAGE_kmod-fou is not set
# CONFIG_PACKAGE_kmod-fou6 is not set
# CONFIG_PACKAGE_kmod-geneve is not set
# CONFIG_PACKAGE_kmod-gre is not set
# CONFIG_PACKAGE_kmod-gre6 is not set
# CONFIG_PACKAGE_kmod-ip6-tunnel is not set
# CONFIG_PACKAGE_kmod-ipip is not set
# CONFIG_PACKAGE_kmod-ipsec is not set
# CONFIG_PACKAGE_kmod-iptunnel6 is not set
# CONFIG_PACKAGE_kmod-isdn4linux is not set
# CONFIG_PACKAGE_kmod-jool is not set
# CONFIG_PACKAGE_kmod-l2tp is not set
# CONFIG_PACKAGE_kmod-l2tp-eth is not set
# CONFIG_PACKAGE_kmod-l2tp-ip is not set
# CONFIG_PACKAGE_kmod-macremapper is not set
# CONFIG_PACKAGE_kmod-macsec is not set
# CONFIG_PACKAGE_kmod-misdn is not set
# CONFIG_PACKAGE_kmod-mpls is not set
# CONFIG_PACKAGE_kmod-nat46 is not set
# CONFIG_PACKAGE_kmod-netem is not set
# CONFIG_PACKAGE_kmod-netlink-diag is not set
# CONFIG_PACKAGE_kmod-nlmon is not set
# CONFIG_PACKAGE_kmod-nsh is not set
# CONFIG_PACKAGE_kmod-openvswitch is not set
# CONFIG_PACKAGE_kmod-openvswitch-geneve is not set
# CONFIG_PACKAGE_kmod-openvswitch-gre is not set
# CONFIG_PACKAGE_kmod-openvswitch-vxlan is not set
# CONFIG_PACKAGE_kmod-pf-ring is not set
# CONFIG_PACKAGE_kmod-pktgen is not set
CONFIG_PACKAGE_kmod-ppp=y
CONFIG_PACKAGE_kmod-mppe=y
# CONFIG_PACKAGE_kmod-ppp-synctty is not set
# CONFIG_PACKAGE_kmod-pppoa is not set
CONFIG_PACKAGE_kmod-pppoe=y
# CONFIG_PACKAGE_kmod-pppol2tp is not set
CONFIG_PACKAGE_kmod-pppox=y
# CONFIG_PACKAGE_kmod-pptp is not set
# CONFIG_PACKAGE_kmod-sched is not set
# CONFIG_PACKAGE_kmod-sched-act-vlan is not set
# CONFIG_PACKAGE_kmod-sched-bpf is not set
# CONFIG_PACKAGE_kmod-sched-cake is not set
# CONFIG_PACKAGE_kmod-sched-cake-virtual is not set
# CONFIG_PACKAGE_kmod-sched-connmark is not set
# CONFIG_PACKAGE_kmod-sched-core is not set
# CONFIG_PACKAGE_kmod-sched-ctinfo is not set
# CONFIG_PACKAGE_kmod-sched-flower is not set
# CONFIG_PACKAGE_kmod-sched-ipset is not set
# CONFIG_PACKAGE_kmod-sched-mqprio is not set
# CONFIG_PACKAGE_kmod-sctp is not set
CONFIG_PACKAGE_kmod-shortcut-fe=y
# CONFIG_PACKAGE_kmod-shortcut-fe-cm is not set
# CONFIG_PACKAGE_kmod-sit is not set
CONFIG_PACKAGE_kmod-slhc=y
# CONFIG_PACKAGE_kmod-slip is not set
CONFIG_PACKAGE_kmod-tcp-bbr=y
# CONFIG_PACKAGE_kmod-trelay is not set
CONFIG_PACKAGE_kmod-tun=y
# CONFIG_PACKAGE_kmod-veth is not set
# CONFIG_PACKAGE_kmod-vxlan is not set
# CONFIG_PACKAGE_kmod-wireguard is not set
# end of Network Support
#
# Other modules
#
# CONFIG_PACKAGE_kmod-6lowpan is not set
# CONFIG_PACKAGE_kmod-ath3k is not set
# CONFIG_PACKAGE_kmod-bcma is not set
# CONFIG_PACKAGE_kmod-bluetooth is not set
# CONFIG_PACKAGE_kmod-bluetooth-6lowpan is not set
# CONFIG_PACKAGE_kmod-bmp085 is not set
# CONFIG_PACKAGE_kmod-bmp085-i2c is not set
# CONFIG_PACKAGE_kmod-bmp085-spi is not set
# CONFIG_PACKAGE_kmod-btmrvl is not set
# CONFIG_PACKAGE_kmod-button-hotplug is not set
# CONFIG_PACKAGE_kmod-dma-ralink is not set
# CONFIG_PACKAGE_kmod-echo is not set
# CONFIG_PACKAGE_kmod-eeprom-93cx6 is not set
# CONFIG_PACKAGE_kmod-eeprom-at24 is not set
# CONFIG_PACKAGE_kmod-eeprom-at25 is not set
# CONFIG_PACKAGE_kmod-gpio-beeper is not set
CONFIG_PACKAGE_kmod-gpio-button-hotplug=y
# CONFIG_PACKAGE_kmod-gpio-dev is not set
# CONFIG_PACKAGE_kmod-gpio-mcp23s08 is not set
# CONFIG_PACKAGE_kmod-gpio-nxp-74hc164 is not set
# CONFIG_PACKAGE_kmod-gpio-pca953x is not set
# CONFIG_PACKAGE_kmod-gpio-pcf857x is not set
# CONFIG_PACKAGE_kmod-hsdma-mtk is not set
# CONFIG_PACKAGE_kmod-ikconfig is not set
# CONFIG_PACKAGE_kmod-it87-wdt is not set
# CONFIG_PACKAGE_kmod-itco-wdt is not set
# CONFIG_PACKAGE_kmod-lp is not set
# CONFIG_PACKAGE_kmod-mmc is not set
# CONFIG_PACKAGE_kmod-mtd-rw is not set
# CONFIG_PACKAGE_kmod-mtdoops is not set
# CONFIG_PACKAGE_kmod-mtdram is not set
# CONFIG_PACKAGE_kmod-mtdtests is not set
# CONFIG_PACKAGE_kmod-parport-pc is not set
# CONFIG_PACKAGE_kmod-ppdev is not set
# CONFIG_PACKAGE_kmod-pps is not set
# CONFIG_PACKAGE_kmod-pps-gpio is not set
# CONFIG_PACKAGE_kmod-pps-ldisc is not set
# CONFIG_PACKAGE_kmod-ptp is not set
# CONFIG_PACKAGE_kmod-random-core is not set
# CONFIG_PACKAGE_kmod-rtc-ds1307 is not set
# CONFIG_PACKAGE_kmod-rtc-ds1374 is not set
# CONFIG_PACKAGE_kmod-rtc-ds1672 is not set
# CONFIG_PACKAGE_kmod-rtc-em3027 is not set
# CONFIG_PACKAGE_kmod-rtc-isl1208 is not set
# CONFIG_PACKAGE_kmod-rtc-pcf2123 is not set
# CONFIG_PACKAGE_kmod-rtc-pcf2127 is not set
# CONFIG_PACKAGE_kmod-rtc-pcf8563 is not set
# CONFIG_PACKAGE_kmod-rtc-pt7c4338 is not set
# CONFIG_PACKAGE_kmod-rtc-rs5c372a is not set
# CONFIG_PACKAGE_kmod-rtc-rx8025 is not set
# CONFIG_PACKAGE_kmod-rtc-s35390a is not set
# CONFIG_PACKAGE_kmod-sdhci is not set
# CONFIG_PACKAGE_kmod-sdhci-mt7620 is not set
# CONFIG_PACKAGE_kmod-serial-8250 is not set
# CONFIG_PACKAGE_kmod-serial-8250-exar is not set
# CONFIG_PACKAGE_kmod-softdog is not set
# CONFIG_PACKAGE_kmod-ssb is not set
# CONFIG_PACKAGE_kmod-tpm is not set
# CONFIG_PACKAGE_kmod-tpm-i2c-atmel is not set
# CONFIG_PACKAGE_kmod-tpm-i2c-infineon is not set
# CONFIG_PACKAGE_kmod-w83627hf-wdt is not set
# CONFIG_PACKAGE_kmod-zram is not set
# end of Other modules
#
# PCMCIA support
#
# end of PCMCIA support
#
# SPI Support
#
# CONFIG_PACKAGE_kmod-mmc-spi is not set
# CONFIG_PACKAGE_kmod-spi-bitbang is not set
# CONFIG_PACKAGE_kmod-spi-dev is not set
# CONFIG_PACKAGE_kmod-spi-gpio is not set
# end of SPI Support
#
# Sound Support
#
# CONFIG_PACKAGE_kmod-sound-core is not set
# end of Sound Support
#
# USB Support
#
# CONFIG_PACKAGE_kmod-chaoskey is not set
# CONFIG_PACKAGE_kmod-usb-acm is not set
# CONFIG_PACKAGE_kmod-usb-atm is not set
# CONFIG_PACKAGE_kmod-usb-cm109 is not set
CONFIG_PACKAGE_kmod-usb-core=y
# CONFIG_PACKAGE_kmod-usb-dwc2 is not set
# CONFIG_PACKAGE_kmod-usb-dwc3 is not set
CONFIG_PACKAGE_kmod-usb-ehci=y
# CONFIG_PACKAGE_kmod-usb-hid is not set
# CONFIG_PACKAGE_kmod-usb-ledtrig-usbport is not set
# CONFIG_PACKAGE_kmod-usb-net is not set
# CONFIG_PACKAGE_kmod-usb-net-aqc111 is not set
# CONFIG_PACKAGE_kmod-usb-net-asix is not set
# CONFIG_PACKAGE_kmod-usb-net-asix-ax88179 is not set
# CONFIG_PACKAGE_kmod-usb-net-cdc-eem is not set
# CONFIG_PACKAGE_kmod-usb-net-cdc-ether is not set
# CONFIG_PACKAGE_kmod-usb-net-cdc-mbim is not set
# CONFIG_PACKAGE_kmod-usb-net-cdc-ncm is not set
# CONFIG_PACKAGE_kmod-usb-net-cdc-subset is not set
# CONFIG_PACKAGE_kmod-usb-net-dm9601-ether is not set
# CONFIG_PACKAGE_kmod-usb-net-hso is not set
# CONFIG_PACKAGE_kmod-usb-net-huawei-cdc-ncm is not set
# CONFIG_PACKAGE_kmod-usb-net-ipheth is not set
# CONFIG_PACKAGE_kmod-usb-net-kalmia is not set
# CONFIG_PACKAGE_kmod-usb-net-kaweth is not set
# CONFIG_PACKAGE_kmod-usb-net-mcs7830 is not set
# CONFIG_PACKAGE_kmod-usb-net-pegasus is not set
# CONFIG_PACKAGE_kmod-usb-net-pl is not set
# CONFIG_PACKAGE_kmod-usb-net-qmi-wwan is not set
# CONFIG_PACKAGE_kmod-usb-net-rndis is not set
# CONFIG_PACKAGE_kmod-usb-net-rtl8150 is not set
# CONFIG_PACKAGE_kmod-usb-net-rtl8152 is not set
# CONFIG_PACKAGE_kmod-usb-net-sierrawireless is not set
# CONFIG_PACKAGE_kmod-usb-net-smsc95xx is not set
# CONFIG_PACKAGE_kmod-usb-net-sr9700 is not set
# CONFIG_PACKAGE_kmod-usb-ohci is not set
# CONFIG_PACKAGE_kmod-usb-ohci-pci is not set
# CONFIG_PACKAGE_kmod-usb-printer is not set
# CONFIG_PACKAGE_kmod-usb-serial is not set
CONFIG_PACKAGE_kmod-usb-storage=y
# CONFIG_PACKAGE_kmod-usb-storage-extras is not set
# CONFIG_PACKAGE_kmod-usb-storage-uas is not set
# CONFIG_PACKAGE_kmod-usb-uhci is not set
# CONFIG_PACKAGE_kmod-usb-wdm is not set
# CONFIG_PACKAGE_kmod-usb-yealink is not set
CONFIG_PACKAGE_kmod-usb2=y
# CONFIG_PACKAGE_kmod-usb2-pci is not set
CONFIG_PACKAGE_kmod-usb3=y
# CONFIG_PACKAGE_kmod-usbip is not set
# CONFIG_PACKAGE_kmod-usbip-client is not set
# CONFIG_PACKAGE_kmod-usbip-server is not set
# CONFIG_PACKAGE_kmod-usbmon is not set
# end of USB Support
#
# Video Support
#
# CONFIG_PACKAGE_kmod-video-core is not set
# end of Video Support
#
# Virtualization
#
# end of Virtualization
#
# Voice over IP
#
# CONFIG_PACKAGE_kmod-dahdi is not set
# end of Voice over IP
#
# W1 support
#
# CONFIG_PACKAGE_kmod-w1 is not set
# end of W1 support
#
# WPAN 802.15.4 Support
#
# CONFIG_PACKAGE_kmod-at86rf230 is not set
# CONFIG_PACKAGE_kmod-atusb is not set
# CONFIG_PACKAGE_kmod-ca8210 is not set
# CONFIG_PACKAGE_kmod-cc2520 is not set
# CONFIG_PACKAGE_kmod-fakelb is not set
# CONFIG_PACKAGE_kmod-ieee802154 is not set
# CONFIG_PACKAGE_kmod-ieee802154-6lowpan is not set
# CONFIG_PACKAGE_kmod-mac802154 is not set
# CONFIG_PACKAGE_kmod-mrf24j40 is not set
# end of WPAN 802.15.4 Support
#
# Wireless Drivers
#
# CONFIG_PACKAGE_kmod-acx-mac80211 is not set
# CONFIG_PACKAGE_kmod-adm8211 is not set
# CONFIG_PACKAGE_kmod-ar5523 is not set
# CONFIG_PACKAGE_kmod-ath is not set
# CONFIG_PACKAGE_kmod-ath10k is not set
# CONFIG_PACKAGE_kmod-ath10k-ct is not set
# CONFIG_PACKAGE_kmod-ath10k-ct-smallbuffers is not set
# CONFIG_PACKAGE_kmod-ath5k is not set
# CONFIG_PACKAGE_kmod-ath6kl-sdio is not set
# CONFIG_PACKAGE_kmod-ath6kl-usb is not set
# CONFIG_PACKAGE_kmod-ath9k is not set
# CONFIG_PACKAGE_kmod-ath9k-htc is not set
# CONFIG_PACKAGE_kmod-b43 is not set
# CONFIG_PACKAGE_kmod-b43legacy is not set
# CONFIG_PACKAGE_kmod-brcmfmac is not set
# CONFIG_PACKAGE_kmod-brcmsmac is not set
# CONFIG_PACKAGE_kmod-brcmutil is not set
# CONFIG_PACKAGE_kmod-carl9170 is not set
CONFIG_PACKAGE_kmod-cfg80211=y
# CONFIG_PACKAGE_CFG80211_TESTMODE is not set
# CONFIG_PACKAGE_kmod-hermes is not set
# CONFIG_PACKAGE_kmod-hermes-pci is not set
# CONFIG_PACKAGE_kmod-hermes-plx is not set
# CONFIG_PACKAGE_kmod-ipw2100 is not set
# CONFIG_PACKAGE_kmod-ipw2200 is not set
# CONFIG_PACKAGE_kmod-iwl-legacy is not set
# CONFIG_PACKAGE_kmod-iwl3945 is not set
# CONFIG_PACKAGE_kmod-iwl4965 is not set
# CONFIG_PACKAGE_kmod-iwlwifi is not set
# CONFIG_PACKAGE_kmod-lib80211 is not set
# CONFIG_PACKAGE_kmod-libertas-sdio is not set
# CONFIG_PACKAGE_kmod-libertas-spi is not set
# CONFIG_PACKAGE_kmod-libertas-usb is not set
# CONFIG_PACKAGE_kmod-libipw is not set
CONFIG_PACKAGE_kmod-mac80211=y
CONFIG_PACKAGE_MAC80211_DEBUGFS=y
# CONFIG_PACKAGE_MAC80211_TRACING is not set
CONFIG_PACKAGE_MAC80211_MESH=y
# CONFIG_PACKAGE_kmod-mac80211-hwsim is not set
# CONFIG_PACKAGE_kmod-mt76 is not set
CONFIG_PACKAGE_kmod-mt76-core=y
# CONFIG_PACKAGE_kmod-mt7601u is not set
# CONFIG_PACKAGE_kmod-mt7603 is not set
# CONFIG_PACKAGE_kmod-mt7603e is not set
CONFIG_PACKAGE_kmod-mt7615-common=y
CONFIG_PACKAGE_kmod-mt7615-firmware=y
# CONFIG_PACKAGE_kmod-mt7615d is not set
# CONFIG_PACKAGE_kmod-mt7615d_dbdc is not set
CONFIG_PACKAGE_kmod-mt7615e=y
# CONFIG_PACKAGE_kmod-mt7663-firmware-ap is not set
# CONFIG_PACKAGE_kmod-mt7663-firmware-sta is not set
# CONFIG_PACKAGE_kmod-mt7663s is not set
# CONFIG_PACKAGE_kmod-mt7663u is not set
# CONFIG_PACKAGE_kmod-mt76x0e is not set
# CONFIG_PACKAGE_kmod-mt76x0u is not set
# CONFIG_PACKAGE_kmod-mt76x2 is not set
# CONFIG_PACKAGE_kmod-mt76x2e is not set
# CONFIG_PACKAGE_kmod-mt76x2u is not set
# CONFIG_PACKAGE_kmod-mt7915e is not set
# CONFIG_PACKAGE_kmod-mwifiex-pcie is not set
# CONFIG_PACKAGE_kmod-mwifiex-sdio is not set
# CONFIG_PACKAGE_kmod-mwl8k is not set
# CONFIG_PACKAGE_kmod-net-prism54 is not set
# CONFIG_PACKAGE_kmod-net-rtl8192su is not set
# CONFIG_PACKAGE_kmod-owl-loader is not set
# CONFIG_PACKAGE_kmod-p54-common is not set
# CONFIG_PACKAGE_kmod-p54-pci is not set
# CONFIG_PACKAGE_kmod-p54-usb is not set
# CONFIG_PACKAGE_kmod-rsi91x is not set
# CONFIG_PACKAGE_kmod-rsi91x-sdio is not set
# CONFIG_PACKAGE_kmod-rsi91x-usb is not set
# CONFIG_PACKAGE_kmod-rt2400-pci is not set
# CONFIG_PACKAGE_kmod-rt2500-pci is not set
# CONFIG_PACKAGE_kmod-rt2500-usb is not set
# CONFIG_PACKAGE_kmod-rt2800-pci is not set
# CONFIG_PACKAGE_kmod-rt2800-usb is not set
# CONFIG_PACKAGE_kmod-rt2x00-lib is not set
# CONFIG_PACKAGE_kmod-rt61-pci is not set
# CONFIG_PACKAGE_kmod-rt73-usb is not set
# CONFIG_PACKAGE_kmod-rtl8180 is not set
# CONFIG_PACKAGE_kmod-rtl8187 is not set
# CONFIG_PACKAGE_kmod-rtl8192ce is not set
# CONFIG_PACKAGE_kmod-rtl8192cu is not set
# CONFIG_PACKAGE_kmod-rtl8192de is not set
# CONFIG_PACKAGE_kmod-rtl8192se is not set
# CONFIG_PACKAGE_kmod-rtl8723bs is not set
# CONFIG_PACKAGE_kmod-rtl8812au-ct is not set
# CONFIG_PACKAGE_kmod-rtl8821ae is not set
# CONFIG_PACKAGE_kmod-rtl8xxxu is not set
# CONFIG_PACKAGE_kmod-rtw88 is not set
# CONFIG_PACKAGE_kmod-wil6210 is not set
# CONFIG_PACKAGE_kmod-wl12xx is not set
# CONFIG_PACKAGE_kmod-wl18xx is not set
# CONFIG_PACKAGE_kmod-wlcore is not set
# CONFIG_PACKAGE_kmod-zd1211rw is not set
# end of Wireless Drivers
# end of Kernel modules
#
# Languages
#
#
# Erlang
#
# CONFIG_PACKAGE_erlang is not set
# CONFIG_PACKAGE_erlang-asn1 is not set
# CONFIG_PACKAGE_erlang-compiler is not set
# CONFIG_PACKAGE_erlang-crypto is not set
# CONFIG_PACKAGE_erlang-erl-interface is not set
# CONFIG_PACKAGE_erlang-hipe is not set
# CONFIG_PACKAGE_erlang-inets is not set
# CONFIG_PACKAGE_erlang-mnesia is not set
# CONFIG_PACKAGE_erlang-os_mon is not set
# CONFIG_PACKAGE_erlang-public-key is not set
# CONFIG_PACKAGE_erlang-reltool is not set
# CONFIG_PACKAGE_erlang-runtime-tools is not set
# CONFIG_PACKAGE_erlang-snmp is not set
# CONFIG_PACKAGE_erlang-ssh is not set
# CONFIG_PACKAGE_erlang-ssl is not set
# CONFIG_PACKAGE_erlang-syntax-tools is not set
# CONFIG_PACKAGE_erlang-tools is not set
# CONFIG_PACKAGE_erlang-xmerl is not set
# end of Erlang
#
# Go
#
# CONFIG_PACKAGE_golang is not set
#
# Configuration
#
CONFIG_GOLANG_EXTERNAL_BOOTSTRAP_ROOT=""
CONFIG_GOLANG_BUILD_CACHE_DIR=""
# CONFIG_GOLANG_MOD_CACHE_WORLD_READABLE is not set
# end of Configuration
# CONFIG_PACKAGE_golang-doc is not set
# CONFIG_PACKAGE_golang-github-jedisct1-dnscrypt-proxy2-dev is not set
# CONFIG_PACKAGE_golang-github-nextdns-nextdns-dev is not set
# CONFIG_PACKAGE_golang-gitlab-yawning-obfs4-dev is not set
# CONFIG_PACKAGE_golang-src is not set
# CONFIG_PACKAGE_golang-torproject-tor-fw-helper-dev is not set
# end of Go
#
# Lua
#
# CONFIG_PACKAGE_dkjson is not set
# CONFIG_PACKAGE_json4lua is not set
# CONFIG_PACKAGE_ldbus is not set
CONFIG_PACKAGE_libiwinfo-lua=y
# CONFIG_PACKAGE_lpeg is not set
# CONFIG_PACKAGE_lsqlite3 is not set
CONFIG_PACKAGE_lua=y
# CONFIG_PACKAGE_lua-bencode is not set
# CONFIG_PACKAGE_lua-bit32 is not set
# CONFIG_PACKAGE_lua-cjson is not set
# CONFIG_PACKAGE_lua-copas is not set
# CONFIG_PACKAGE_lua-coxpcall is not set
# CONFIG_PACKAGE_lua-ev is not set
# CONFIG_PACKAGE_lua-examples is not set
# CONFIG_PACKAGE_lua-libmodbus is not set
# CONFIG_PACKAGE_lua-lzlib is not set
# CONFIG_PACKAGE_lua-md5 is not set
# CONFIG_PACKAGE_lua-mobdebug is not set
# CONFIG_PACKAGE_lua-mosquitto is not set
# CONFIG_PACKAGE_lua-openssl is not set
# CONFIG_PACKAGE_lua-penlight is not set
# CONFIG_PACKAGE_lua-rings is not set
# CONFIG_PACKAGE_lua-rs232 is not set
# CONFIG_PACKAGE_lua-sha2 is not set
# CONFIG_PACKAGE_lua-wsapi-base is not set
# CONFIG_PACKAGE_lua-wsapi-xavante is not set
# CONFIG_PACKAGE_lua-xavante is not set
# CONFIG_PACKAGE_lua5.3 is not set
# CONFIG_PACKAGE_luabitop is not set
# CONFIG_PACKAGE_luac is not set
# CONFIG_PACKAGE_luac5.3 is not set
# CONFIG_PACKAGE_luaexpat is not set
# CONFIG_PACKAGE_luafilesystem is not set
# CONFIG_PACKAGE_luajit is not set
# CONFIG_PACKAGE_lualanes is not set
# CONFIG_PACKAGE_luaposix is not set
# CONFIG_PACKAGE_luarocks is not set
# CONFIG_PACKAGE_luasec is not set
# CONFIG_PACKAGE_luasoap is not set
# CONFIG_PACKAGE_luasocket is not set
# CONFIG_PACKAGE_luasocket5.3 is not set
# CONFIG_PACKAGE_luasql-mysql is not set
# CONFIG_PACKAGE_luasql-pgsql is not set
# CONFIG_PACKAGE_luasql-sqlite3 is not set
# CONFIG_PACKAGE_luasrcdiet is not set
CONFIG_PACKAGE_luci-lib-fs=y
# CONFIG_PACKAGE_luv is not set
# CONFIG_PACKAGE_lzmq is not set
# CONFIG_PACKAGE_uuid is not set
# end of Lua
#
# Node.js
#
# CONFIG_PACKAGE_node is not set
# CONFIG_PACKAGE_node-arduino-firmata is not set
# CONFIG_PACKAGE_node-cylon is not set
# CONFIG_PACKAGE_node-cylon-firmata is not set
# CONFIG_PACKAGE_node-cylon-gpio is not set
# CONFIG_PACKAGE_node-cylon-i2c is not set
# CONFIG_PACKAGE_node-hid is not set
# CONFIG_PACKAGE_node-homebridge is not set
# CONFIG_PACKAGE_node-javascript-obfuscator is not set
# CONFIG_PACKAGE_node-npm is not set
# CONFIG_PACKAGE_node-serialport is not set
# CONFIG_PACKAGE_node-serialport-bindings is not set
# end of Node.js
#
# PHP
#
# CONFIG_PACKAGE_php7 is not set
# end of PHP
#
# Perl
#
# CONFIG_PACKAGE_perl is not set
# end of Perl
#
# Python
#
# CONFIG_PACKAGE_gunicorn3 is not set
# CONFIG_PACKAGE_micropython is not set
# CONFIG_PACKAGE_micropython-lib is not set
# CONFIG_PACKAGE_python-pip-conf is not set
# CONFIG_PACKAGE_python3 is not set
# CONFIG_PACKAGE_python3-aiohttp is not set
# CONFIG_PACKAGE_python3-aiohttp-cors is not set
# CONFIG_PACKAGE_python3-appdirs is not set
# CONFIG_PACKAGE_python3-asgiref is not set
# CONFIG_PACKAGE_python3-asn1crypto is not set
# CONFIG_PACKAGE_python3-astral is not set
# CONFIG_PACKAGE_python3-async-timeout is not set
# CONFIG_PACKAGE_python3-asyncio is not set
# CONFIG_PACKAGE_python3-atomicwrites is not set
# CONFIG_PACKAGE_python3-attrs is not set
# CONFIG_PACKAGE_python3-automat is not set
# CONFIG_PACKAGE_python3-awscli is not set
# CONFIG_PACKAGE_python3-base is not set
# CONFIG_PACKAGE_python3-bcrypt is not set
# CONFIG_PACKAGE_python3-boto3 is not set
# CONFIG_PACKAGE_python3-botocore is not set
# CONFIG_PACKAGE_python3-bottle is not set
# CONFIG_PACKAGE_python3-cached-property is not set
# CONFIG_PACKAGE_python3-cachelib is not set
# CONFIG_PACKAGE_python3-cachetools is not set
# CONFIG_PACKAGE_python3-certifi is not set
# CONFIG_PACKAGE_python3-cffi is not set
# CONFIG_PACKAGE_python3-cgi is not set
# CONFIG_PACKAGE_python3-cgitb is not set
# CONFIG_PACKAGE_python3-chardet is not set
# CONFIG_PACKAGE_python3-click is not set
# CONFIG_PACKAGE_python3-click-log is not set
# CONFIG_PACKAGE_python3-codecs is not set
# CONFIG_PACKAGE_python3-colorama is not set
# CONFIG_PACKAGE_python3-constantly is not set
# CONFIG_PACKAGE_python3-contextlib2 is not set
# CONFIG_PACKAGE_python3-cryptodome is not set
# CONFIG_PACKAGE_python3-cryptodomex is not set
# CONFIG_PACKAGE_python3-cryptography is not set
# CONFIG_PACKAGE_python3-ctypes is not set
# CONFIG_PACKAGE_python3-curl is not set
# CONFIG_PACKAGE_python3-dateutil is not set
# CONFIG_PACKAGE_python3-dbm is not set
# CONFIG_PACKAGE_python3-decimal is not set
# CONFIG_PACKAGE_python3-decorator is not set
# CONFIG_PACKAGE_python3-defusedxml is not set
# CONFIG_PACKAGE_python3-dev is not set
# CONFIG_PACKAGE_python3-distro is not set
# CONFIG_PACKAGE_python3-distutils is not set
# CONFIG_PACKAGE_python3-django is not set
# CONFIG_PACKAGE_python3-django-appconf is not set
# CONFIG_PACKAGE_python3-django-compressor is not set
# CONFIG_PACKAGE_python3-django-cors-headers is not set
# CONFIG_PACKAGE_python3-django-etesync-journal is not set
# CONFIG_PACKAGE_python3-django-formtools is not set
# CONFIG_PACKAGE_python3-django-jsonfield is not set
# CONFIG_PACKAGE_python3-django-jsonfield2 is not set
# CONFIG_PACKAGE_python3-django-picklefield is not set
# CONFIG_PACKAGE_python3-django-postoffice is not set
# CONFIG_PACKAGE_python3-django-ranged-response is not set
# CONFIG_PACKAGE_python3-django-restframework is not set
# CONFIG_PACKAGE_python3-django-restframework39 is not set
# CONFIG_PACKAGE_python3-django-simple-captcha is not set
# CONFIG_PACKAGE_python3-django-statici18n is not set
# CONFIG_PACKAGE_python3-django-webpack-loader is not set
# CONFIG_PACKAGE_python3-django1 is not set
# CONFIG_PACKAGE_python3-dns is not set
# CONFIG_PACKAGE_python3-docker is not set
# CONFIG_PACKAGE_python3-dockerpty is not set
# CONFIG_PACKAGE_python3-docopt is not set
# CONFIG_PACKAGE_python3-docutils is not set
# CONFIG_PACKAGE_python3-dotenv is not set
# CONFIG_PACKAGE_python3-drf-nested-routers is not set
# CONFIG_PACKAGE_python3-email is not set
# CONFIG_PACKAGE_python3-et_xmlfile is not set
# CONFIG_PACKAGE_python3-evdev is not set
# CONFIG_PACKAGE_python3-flask is not set
# CONFIG_PACKAGE_python3-flask-login is not set
# CONFIG_PACKAGE_python3-gdbm is not set
# CONFIG_PACKAGE_python3-gmpy2 is not set
# CONFIG_PACKAGE_python3-gnupg is not set
# CONFIG_PACKAGE_python3-gpiod is not set
# CONFIG_PACKAGE_python3-gunicorn is not set
# CONFIG_PACKAGE_python3-hyperlink is not set
# CONFIG_PACKAGE_python3-idna is not set
# CONFIG_PACKAGE_python3-ifaddr is not set
# CONFIG_PACKAGE_python3-incremental is not set
# CONFIG_PACKAGE_python3-influxdb is not set
# CONFIG_PACKAGE_python3-intelhex is not set
# CONFIG_PACKAGE_python3-itsdangerous is not set
# CONFIG_PACKAGE_python3-jdcal is not set
# CONFIG_PACKAGE_python3-jinja2 is not set
# CONFIG_PACKAGE_python3-jmespath is not set
# CONFIG_PACKAGE_python3-jsonpath-ng is not set
# CONFIG_PACKAGE_python3-jsonschema is not set
# CONFIG_PACKAGE_python3-lib2to3 is not set
# CONFIG_PACKAGE_python3-libmodbus is not set
# CONFIG_PACKAGE_python3-light is not set
#
# Configuration
#
# CONFIG_PYTHON3_BLUETOOTH_SUPPORT is not set
# end of Configuration
# CONFIG_PACKAGE_python3-logging is not set
# CONFIG_PACKAGE_python3-lxml is not set
# CONFIG_PACKAGE_python3-lzma is not set
# CONFIG_PACKAGE_python3-markdown is not set
# CONFIG_PACKAGE_python3-markupsafe is not set
# CONFIG_PACKAGE_python3-maxminddb is not set
# CONFIG_PACKAGE_python3-more-itertools is not set
# CONFIG_PACKAGE_python3-multidict is not set
# CONFIG_PACKAGE_python3-multiprocessing is not set
# CONFIG_PACKAGE_python3-mysqlclient is not set
# CONFIG_PACKAGE_python3-ncurses is not set
# CONFIG_PACKAGE_python3-netdisco is not set
# CONFIG_PACKAGE_python3-netifaces is not set
# CONFIG_PACKAGE_python3-newt is not set
# CONFIG_PACKAGE_python3-oauthlib is not set
# CONFIG_PACKAGE_python3-openpyxl is not set
# CONFIG_PACKAGE_python3-openssl is not set
# CONFIG_PACKAGE_python3-packaging is not set
# CONFIG_PACKAGE_python3-paho-mqtt is not set
# CONFIG_PACKAGE_python3-paramiko is not set
# CONFIG_PACKAGE_python3-parsley is not set
# CONFIG_PACKAGE_python3-passlib is not set
# CONFIG_PACKAGE_python3-pillow is not set
# CONFIG_PACKAGE_python3-pip is not set
# CONFIG_PACKAGE_python3-pkg-resources is not set
# CONFIG_PACKAGE_python3-pluggy is not set
# CONFIG_PACKAGE_python3-ply is not set
# CONFIG_PACKAGE_python3-py is not set
# CONFIG_PACKAGE_python3-pyasn1 is not set
# CONFIG_PACKAGE_python3-pyasn1-modules is not set
# CONFIG_PACKAGE_python3-pycparser is not set
# CONFIG_PACKAGE_python3-pydoc is not set
# CONFIG_PACKAGE_python3-pyjwt is not set
# CONFIG_PACKAGE_python3-pymysql is not set
# CONFIG_PACKAGE_python3-pynacl is not set
# CONFIG_PACKAGE_python3-pyodbc is not set
# CONFIG_PACKAGE_python3-pyopenssl is not set
# CONFIG_PACKAGE_python3-pyotp is not set
# CONFIG_PACKAGE_python3-pyparsing is not set
# CONFIG_PACKAGE_python3-pyroute2 is not set
# CONFIG_PACKAGE_python3-pyrsistent is not set
# CONFIG_PACKAGE_python3-pyserial is not set
# CONFIG_PACKAGE_python3-pytest is not set
# CONFIG_PACKAGE_python3-pytz is not set
# CONFIG_PACKAGE_python3-qrcode is not set
# CONFIG_PACKAGE_python3-rcssmin is not set
# CONFIG_PACKAGE_python3-requests is not set
# CONFIG_PACKAGE_python3-requests-oauthlib is not set
# CONFIG_PACKAGE_python3-rsa is not set
# CONFIG_PACKAGE_python3-ruamel-yaml is not set
# CONFIG_PACKAGE_python3-s3transfer is not set
# CONFIG_PACKAGE_python3-schedule is not set
# CONFIG_PACKAGE_python3-schema is not set
# CONFIG_PACKAGE_python3-seafile-ccnet is not set
# CONFIG_PACKAGE_python3-seafile-server is not set
# CONFIG_PACKAGE_python3-searpc is not set
# CONFIG_PACKAGE_python3-sentry-sdk is not set
# CONFIG_PACKAGE_python3-service-identity is not set
# CONFIG_PACKAGE_python3-setuptools is not set
# CONFIG_PACKAGE_python3-simplejson is not set
# CONFIG_PACKAGE_python3-six is not set
# CONFIG_PACKAGE_python3-slugify is not set
# CONFIG_PACKAGE_python3-smbus is not set
# CONFIG_PACKAGE_python3-speedtest-cli is not set
# CONFIG_PACKAGE_python3-sqlalchemy is not set
# CONFIG_PACKAGE_python3-sqlite3 is not set
# CONFIG_PACKAGE_python3-sqlparse is not set
# CONFIG_PACKAGE_python3-stem is not set
# CONFIG_PACKAGE_python3-sysrepo is not set
# CONFIG_PACKAGE_python3-text-unidecode is not set
# CONFIG_PACKAGE_python3-texttable is not set
# CONFIG_PACKAGE_python3-twisted is not set
# CONFIG_PACKAGE_python3-unidecode is not set
# CONFIG_PACKAGE_python3-unittest is not set
# CONFIG_PACKAGE_python3-urllib is not set
# CONFIG_PACKAGE_python3-urllib3 is not set
# CONFIG_PACKAGE_python3-vobject is not set
# CONFIG_PACKAGE_python3-voluptuous is not set
# CONFIG_PACKAGE_python3-voluptuous-serialize is not set
# CONFIG_PACKAGE_python3-wcwidth is not set
# CONFIG_PACKAGE_python3-websocket-client is not set
# CONFIG_PACKAGE_python3-werkzeug is not set
# CONFIG_PACKAGE_python3-xml is not set
# CONFIG_PACKAGE_python3-xmltodict is not set
# CONFIG_PACKAGE_python3-yaml is not set
# CONFIG_PACKAGE_python3-yarl is not set
# CONFIG_PACKAGE_python3-zeroconf is not set
# CONFIG_PACKAGE_python3-zipp is not set
# CONFIG_PACKAGE_python3-zope-interface is not set
# end of Python
#
# Ruby
#
CONFIG_PACKAGE_ruby=y
#
# Standard Library
#
# CONFIG_PACKAGE_ruby-stdlib is not set
# CONFIG_PACKAGE_ruby-benchmark is not set
CONFIG_PACKAGE_ruby-bigdecimal=y
# CONFIG_PACKAGE_ruby-bundler is not set
# CONFIG_PACKAGE_ruby-cgi is not set
# CONFIG_PACKAGE_ruby-csv is not set
CONFIG_PACKAGE_ruby-date=y
CONFIG_PACKAGE_ruby-dbm=y
# CONFIG_PACKAGE_ruby-debuglib is not set
# CONFIG_PACKAGE_ruby-delegate is not set
# CONFIG_PACKAGE_ruby-dev is not set
# CONFIG_PACKAGE_ruby-did-you-mean is not set
CONFIG_PACKAGE_ruby-digest=y
# CONFIG_RUBY_DIGEST_USE_OPENSSL is not set
# CONFIG_PACKAGE_ruby-drb is not set
CONFIG_PACKAGE_ruby-enc=y
# CONFIG_PACKAGE_ruby-enc-extra is not set
# CONFIG_PACKAGE_ruby-erb is not set
# CONFIG_PACKAGE_ruby-etc is not set
# CONFIG_PACKAGE_ruby-fcntl is not set
# CONFIG_PACKAGE_ruby-fiddle is not set
# CONFIG_PACKAGE_ruby-filelib is not set
# CONFIG_PACKAGE_ruby-fileutils is not set
# CONFIG_PACKAGE_ruby-forwardable is not set
# CONFIG_PACKAGE_ruby-gdbm is not set
# CONFIG_PACKAGE_ruby-gems is not set
# CONFIG_PACKAGE_ruby-getoptlong is not set
# CONFIG_PACKAGE_ruby-io-console is not set
# CONFIG_PACKAGE_ruby-ipaddr is not set
# CONFIG_PACKAGE_ruby-irb is not set
# CONFIG_PACKAGE_ruby-json is not set
# CONFIG_PACKAGE_ruby-logger is not set
# CONFIG_PACKAGE_ruby-matrix is not set
# CONFIG_PACKAGE_ruby-minitest is not set
# CONFIG_PACKAGE_ruby-misc is not set
# CONFIG_PACKAGE_ruby-mkmf is not set
# CONFIG_PACKAGE_ruby-multithread is not set
# CONFIG_PACKAGE_ruby-mutex_m is not set
# CONFIG_PACKAGE_ruby-net is not set
# CONFIG_PACKAGE_ruby-net-pop is not set
# CONFIG_PACKAGE_ruby-net-smtp is not set
# CONFIG_PACKAGE_ruby-net-telnet is not set
# CONFIG_PACKAGE_ruby-nkf is not set
# CONFIG_PACKAGE_ruby-observer is not set
# CONFIG_PACKAGE_ruby-open3 is not set
# CONFIG_PACKAGE_ruby-openssl is not set
# CONFIG_PACKAGE_ruby-optparse is not set
# CONFIG_PACKAGE_ruby-ostruct is not set
# CONFIG_PACKAGE_ruby-powerassert is not set
# CONFIG_PACKAGE_ruby-prettyprint is not set
# CONFIG_PACKAGE_ruby-prime is not set
CONFIG_PACKAGE_ruby-pstore=y
CONFIG_PACKAGE_ruby-psych=y
# CONFIG_PACKAGE_ruby-racc is not set
# CONFIG_PACKAGE_ruby-rake is not set
# CONFIG_PACKAGE_ruby-rbconfig is not set
# CONFIG_PACKAGE_ruby-rdoc is not set
# CONFIG_PACKAGE_ruby-readline is not set
# CONFIG_PACKAGE_ruby-readline-ext is not set
# CONFIG_PACKAGE_ruby-reline is not set
# CONFIG_PACKAGE_ruby-rexml is not set
# CONFIG_PACKAGE_ruby-rinda is not set
# CONFIG_PACKAGE_ruby-ripper is not set
# CONFIG_PACKAGE_ruby-rss is not set
# CONFIG_PACKAGE_ruby-sdbm is not set
# CONFIG_PACKAGE_ruby-singleton is not set
# CONFIG_PACKAGE_ruby-socket is not set
CONFIG_PACKAGE_ruby-stringio=y
CONFIG_PACKAGE_ruby-strscan=y
# CONFIG_PACKAGE_ruby-testunit is not set
# CONFIG_PACKAGE_ruby-time is not set
# CONFIG_PACKAGE_ruby-timeout is not set
# CONFIG_PACKAGE_ruby-tracer is not set
# CONFIG_PACKAGE_ruby-unicodenormalize is not set
# CONFIG_PACKAGE_ruby-uri is not set
# CONFIG_PACKAGE_ruby-webrick is not set
# CONFIG_PACKAGE_ruby-xmlrpc is not set
CONFIG_PACKAGE_ruby-yaml=y
# CONFIG_PACKAGE_ruby-zlib is not set
# end of Ruby
#
# Tcl
#
# CONFIG_PACKAGE_tcl is not set
# end of Tcl
# CONFIG_PACKAGE_chicken-scheme-full is not set
# CONFIG_PACKAGE_chicken-scheme-interpreter is not set
# CONFIG_PACKAGE_slsh is not set
# end of Languages
#
# Libraries
#
#
# Compression
#
# CONFIG_PACKAGE_libbz2 is not set
# CONFIG_PACKAGE_liblz4 is not set
# CONFIG_PACKAGE_liblzma is not set
# CONFIG_PACKAGE_libunrar is not set
# CONFIG_PACKAGE_libzip-gnutls is not set
# CONFIG_PACKAGE_libzip-mbedtls is not set
# CONFIG_PACKAGE_libzip-nossl is not set
# CONFIG_PACKAGE_libzip-openssl is not set
# CONFIG_PACKAGE_libzstd is not set
# end of Compression
#
# Database
#
# CONFIG_PACKAGE_libmariadb is not set
# CONFIG_PACKAGE_libpq is not set
# CONFIG_PACKAGE_libsqlite3 is not set
# CONFIG_PACKAGE_pgsqlodbc is not set
# CONFIG_PACKAGE_psqlodbca is not set
# CONFIG_PACKAGE_psqlodbcw is not set
# CONFIG_PACKAGE_redis-cli is not set
# CONFIG_PACKAGE_redis-full is not set
# CONFIG_PACKAGE_redis-server is not set
# CONFIG_PACKAGE_redis-utils is not set
# CONFIG_PACKAGE_tdb is not set
# CONFIG_PACKAGE_unixodbc is not set
# end of Database
#
# Filesystem
#
# CONFIG_PACKAGE_libacl is not set
# CONFIG_PACKAGE_libattr is not set
# CONFIG_PACKAGE_libfuse is not set
# CONFIG_PACKAGE_libfuse3 is not set
# CONFIG_PACKAGE_libow is not set
# CONFIG_PACKAGE_libow-capi is not set
# CONFIG_PACKAGE_libsysfs is not set
# end of Filesystem
#
# Firewall
#
# CONFIG_PACKAGE_libfko is not set
CONFIG_PACKAGE_libip4tc=y
CONFIG_PACKAGE_libip6tc=y
CONFIG_PACKAGE_libxtables=y
# CONFIG_PACKAGE_libxtables-nft is not set
# end of Firewall
#
# Instant Messaging
#
# CONFIG_PACKAGE_quasselc is not set
# end of Instant Messaging
#
# IoT
#
# CONFIG_PACKAGE_libmraa is not set
# CONFIG_PACKAGE_libmraa-node is not set
# CONFIG_PACKAGE_libupm-a110x is not set
# CONFIG_PACKAGE_libupm-a110x-node is not set
# CONFIG_PACKAGE_libupm-abp is not set
# CONFIG_PACKAGE_libupm-abp-node is not set
# CONFIG_PACKAGE_libupm-ad8232 is not set
# CONFIG_PACKAGE_libupm-ad8232-node is not set
# CONFIG_PACKAGE_libupm-adafruitms1438 is not set
# CONFIG_PACKAGE_libupm-adafruitms1438-node is not set
# CONFIG_PACKAGE_libupm-adafruitss is not set
# CONFIG_PACKAGE_libupm-adafruitss-node is not set
# CONFIG_PACKAGE_libupm-adc121c021 is not set
# CONFIG_PACKAGE_libupm-adc121c021-node is not set
# CONFIG_PACKAGE_libupm-adis16448 is not set
# CONFIG_PACKAGE_libupm-adis16448-node is not set
# CONFIG_PACKAGE_libupm-ads1x15 is not set
# CONFIG_PACKAGE_libupm-ads1x15-node is not set
# CONFIG_PACKAGE_libupm-adxl335 is not set
# CONFIG_PACKAGE_libupm-adxl335-node is not set
# CONFIG_PACKAGE_libupm-adxl345 is not set
# CONFIG_PACKAGE_libupm-adxl345-node is not set
# CONFIG_PACKAGE_libupm-adxrs610 is not set
# CONFIG_PACKAGE_libupm-adxrs610-node is not set
# CONFIG_PACKAGE_libupm-am2315 is not set
# CONFIG_PACKAGE_libupm-am2315-node is not set
# CONFIG_PACKAGE_libupm-apa102 is not set
# CONFIG_PACKAGE_libupm-apa102-node is not set
# CONFIG_PACKAGE_libupm-apds9002 is not set
# CONFIG_PACKAGE_libupm-apds9002-node is not set
# CONFIG_PACKAGE_libupm-apds9930 is not set
# CONFIG_PACKAGE_libupm-apds9930-node is not set
# CONFIG_PACKAGE_libupm-at42qt1070 is not set
# CONFIG_PACKAGE_libupm-at42qt1070-node is not set
# CONFIG_PACKAGE_libupm-bh1749 is not set
# CONFIG_PACKAGE_libupm-bh1749-node is not set
# CONFIG_PACKAGE_libupm-bh1750 is not set
# CONFIG_PACKAGE_libupm-bh1750-node is not set
# CONFIG_PACKAGE_libupm-bh1792 is not set
# CONFIG_PACKAGE_libupm-bh1792-node is not set
# CONFIG_PACKAGE_libupm-biss0001 is not set
# CONFIG_PACKAGE_libupm-biss0001-node is not set
# CONFIG_PACKAGE_libupm-bma220 is not set
# CONFIG_PACKAGE_libupm-bma220-node is not set
# CONFIG_PACKAGE_libupm-bma250e is not set
# CONFIG_PACKAGE_libupm-bma250e-node is not set
# CONFIG_PACKAGE_libupm-bmg160 is not set
# CONFIG_PACKAGE_libupm-bmg160-node is not set
# CONFIG_PACKAGE_libupm-bmi160 is not set
# CONFIG_PACKAGE_libupm-bmi160-node is not set
# CONFIG_PACKAGE_libupm-bmm150 is not set
# CONFIG_PACKAGE_libupm-bmm150-node is not set
# CONFIG_PACKAGE_libupm-bmp280 is not set
# CONFIG_PACKAGE_libupm-bmp280-node is not set
# CONFIG_PACKAGE_libupm-bmpx8x is not set
# CONFIG_PACKAGE_libupm-bmpx8x-node is not set
# CONFIG_PACKAGE_libupm-bmx055 is not set
# CONFIG_PACKAGE_libupm-bmx055-node is not set
# CONFIG_PACKAGE_libupm-bno055 is not set
# CONFIG_PACKAGE_libupm-bno055-node is not set
# CONFIG_PACKAGE_libupm-button is not set
# CONFIG_PACKAGE_libupm-button-node is not set
# CONFIG_PACKAGE_libupm-buzzer is not set
# CONFIG_PACKAGE_libupm-buzzer-node is not set
# CONFIG_PACKAGE_libupm-cjq4435 is not set
# CONFIG_PACKAGE_libupm-cjq4435-node is not set
# CONFIG_PACKAGE_libupm-collision is not set
# CONFIG_PACKAGE_libupm-collision-node is not set
# CONFIG_PACKAGE_libupm-curieimu is not set
# CONFIG_PACKAGE_libupm-curieimu-node is not set
# CONFIG_PACKAGE_libupm-cwlsxxa is not set
# CONFIG_PACKAGE_libupm-cwlsxxa-node is not set
# CONFIG_PACKAGE_libupm-dfrec is not set
# CONFIG_PACKAGE_libupm-dfrec-node is not set
# CONFIG_PACKAGE_libupm-dfrorp is not set
# CONFIG_PACKAGE_libupm-dfrorp-node is not set
# CONFIG_PACKAGE_libupm-dfrph is not set
# CONFIG_PACKAGE_libupm-dfrph-node is not set
# CONFIG_PACKAGE_libupm-ds1307 is not set
# CONFIG_PACKAGE_libupm-ds1307-node is not set
# CONFIG_PACKAGE_libupm-ds1808lc is not set
# CONFIG_PACKAGE_libupm-ds1808lc-node is not set
# CONFIG_PACKAGE_libupm-ds18b20 is not set
# CONFIG_PACKAGE_libupm-ds18b20-node is not set
# CONFIG_PACKAGE_libupm-ds2413 is not set
# CONFIG_PACKAGE_libupm-ds2413-node is not set
# CONFIG_PACKAGE_libupm-ecezo is not set
# CONFIG_PACKAGE_libupm-ecezo-node is not set
# CONFIG_PACKAGE_libupm-ecs1030 is not set
# CONFIG_PACKAGE_libupm-ecs1030-node is not set
# CONFIG_PACKAGE_libupm-ehr is not set
# CONFIG_PACKAGE_libupm-ehr-node is not set
# CONFIG_PACKAGE_libupm-eldriver is not set
# CONFIG_PACKAGE_libupm-eldriver-node is not set
# CONFIG_PACKAGE_libupm-electromagnet is not set
# CONFIG_PACKAGE_libupm-electromagnet-node is not set
# CONFIG_PACKAGE_libupm-emg is not set
# CONFIG_PACKAGE_libupm-emg-node is not set
# CONFIG_PACKAGE_libupm-enc03r is not set
# CONFIG_PACKAGE_libupm-enc03r-node is not set
# CONFIG_PACKAGE_libupm-flex is not set
# CONFIG_PACKAGE_libupm-flex-node is not set
# CONFIG_PACKAGE_libupm-gas is not set
# CONFIG_PACKAGE_libupm-gas-node is not set
# CONFIG_PACKAGE_libupm-gp2y0a is not set
# CONFIG_PACKAGE_libupm-gp2y0a-node is not set
# CONFIG_PACKAGE_libupm-gprs is not set
# CONFIG_PACKAGE_libupm-gprs-node is not set
# CONFIG_PACKAGE_libupm-gsr is not set
# CONFIG_PACKAGE_libupm-gsr-node is not set
# CONFIG_PACKAGE_libupm-guvas12d is not set
# CONFIG_PACKAGE_libupm-guvas12d-node is not set
# CONFIG_PACKAGE_libupm-h3lis331dl is not set
# CONFIG_PACKAGE_libupm-h3lis331dl-node is not set
# CONFIG_PACKAGE_libupm-h803x is not set
# CONFIG_PACKAGE_libupm-h803x-node is not set
# CONFIG_PACKAGE_libupm-hcsr04 is not set
# CONFIG_PACKAGE_libupm-hcsr04-node is not set
# CONFIG_PACKAGE_libupm-hdc1000 is not set
# CONFIG_PACKAGE_libupm-hdc1000-node is not set
# CONFIG_PACKAGE_libupm-hdxxvxta is not set
# CONFIG_PACKAGE_libupm-hdxxvxta-node is not set
# CONFIG_PACKAGE_libupm-hka5 is not set
# CONFIG_PACKAGE_libupm-hka5-node is not set
# CONFIG_PACKAGE_libupm-hlg150h is not set
# CONFIG_PACKAGE_libupm-hlg150h-node is not set
# CONFIG_PACKAGE_libupm-hm11 is not set
# CONFIG_PACKAGE_libupm-hm11-node is not set
# CONFIG_PACKAGE_libupm-hmc5883l is not set
# CONFIG_PACKAGE_libupm-hmc5883l-node is not set
# CONFIG_PACKAGE_libupm-hmtrp is not set
# CONFIG_PACKAGE_libupm-hmtrp-node is not set
# CONFIG_PACKAGE_libupm-hp20x is not set
# CONFIG_PACKAGE_libupm-hp20x-node is not set
# CONFIG_PACKAGE_libupm-ht9170 is not set
# CONFIG_PACKAGE_libupm-ht9170-node is not set
# CONFIG_PACKAGE_libupm-htu21d is not set
# CONFIG_PACKAGE_libupm-htu21d-node is not set
# CONFIG_PACKAGE_libupm-hwxpxx is not set
# CONFIG_PACKAGE_libupm-hwxpxx-node is not set
# CONFIG_PACKAGE_libupm-hx711 is not set
# CONFIG_PACKAGE_libupm-hx711-node is not set
# CONFIG_PACKAGE_libupm-ili9341 is not set
# CONFIG_PACKAGE_libupm-ili9341-node is not set
# CONFIG_PACKAGE_libupm-ims is not set
# CONFIG_PACKAGE_libupm-ims-node is not set
# CONFIG_PACKAGE_libupm-ina132 is not set
# CONFIG_PACKAGE_libupm-ina132-node is not set
# CONFIG_PACKAGE_libupm-interfaces is not set
# CONFIG_PACKAGE_libupm-interfaces-node is not set
# CONFIG_PACKAGE_libupm-isd1820 is not set
# CONFIG_PACKAGE_libupm-isd1820-node is not set
# CONFIG_PACKAGE_libupm-itg3200 is not set
# CONFIG_PACKAGE_libupm-itg3200-node is not set
# CONFIG_PACKAGE_libupm-jhd1313m1 is not set
# CONFIG_PACKAGE_libupm-jhd1313m1-node is not set
# CONFIG_PACKAGE_libupm-joystick12 is not set
# CONFIG_PACKAGE_libupm-joystick12-node is not set
# CONFIG_PACKAGE_libupm-kx122 is not set
# CONFIG_PACKAGE_libupm-kx122-node is not set
# CONFIG_PACKAGE_libupm-kxcjk1013 is not set
# CONFIG_PACKAGE_libupm-kxcjk1013-node is not set
# CONFIG_PACKAGE_libupm-kxtj3 is not set
# CONFIG_PACKAGE_libupm-kxtj3-node is not set
# CONFIG_PACKAGE_libupm-l298 is not set
# CONFIG_PACKAGE_libupm-l298-node is not set
# CONFIG_PACKAGE_libupm-l3gd20 is not set
# CONFIG_PACKAGE_libupm-l3gd20-node is not set
# CONFIG_PACKAGE_libupm-lcd is not set
# CONFIG_PACKAGE_libupm-lcd-node is not set
# CONFIG_PACKAGE_libupm-lcdks is not set
# CONFIG_PACKAGE_libupm-lcdks-node is not set
# CONFIG_PACKAGE_libupm-lcm1602 is not set
# CONFIG_PACKAGE_libupm-lcm1602-node is not set
# CONFIG_PACKAGE_libupm-ldt0028 is not set
# CONFIG_PACKAGE_libupm-ldt0028-node is not set
# CONFIG_PACKAGE_libupm-led is not set
# CONFIG_PACKAGE_libupm-led-node is not set
# CONFIG_PACKAGE_libupm-lidarlitev3 is not set
# CONFIG_PACKAGE_libupm-lidarlitev3-node is not set
# CONFIG_PACKAGE_libupm-light is not set
# CONFIG_PACKAGE_libupm-light-node is not set
# CONFIG_PACKAGE_libupm-linefinder is not set
# CONFIG_PACKAGE_libupm-linefinder-node is not set
# CONFIG_PACKAGE_libupm-lis2ds12 is not set
# CONFIG_PACKAGE_libupm-lis2ds12-node is not set
# CONFIG_PACKAGE_libupm-lis3dh is not set
# CONFIG_PACKAGE_libupm-lis3dh-node is not set
# CONFIG_PACKAGE_libupm-lm35 is not set
# CONFIG_PACKAGE_libupm-lm35-node is not set
# CONFIG_PACKAGE_libupm-lol is not set
# CONFIG_PACKAGE_libupm-lol-node is not set
# CONFIG_PACKAGE_libupm-loudness is not set
# CONFIG_PACKAGE_libupm-loudness-node is not set
# CONFIG_PACKAGE_libupm-lp8860 is not set
# CONFIG_PACKAGE_libupm-lp8860-node is not set
# CONFIG_PACKAGE_libupm-lpd8806 is not set
# CONFIG_PACKAGE_libupm-lpd8806-node is not set
# CONFIG_PACKAGE_libupm-lsm303agr is not set
# CONFIG_PACKAGE_libupm-lsm303agr-node is not set
# CONFIG_PACKAGE_libupm-lsm303d is not set
# CONFIG_PACKAGE_libupm-lsm303d-node is not set
# CONFIG_PACKAGE_libupm-lsm303dlh is not set
# CONFIG_PACKAGE_libupm-lsm303dlh-node is not set
# CONFIG_PACKAGE_libupm-lsm6ds3h is not set
# CONFIG_PACKAGE_libupm-lsm6ds3h-node is not set
# CONFIG_PACKAGE_libupm-lsm6dsl is not set
# CONFIG_PACKAGE_libupm-lsm6dsl-node is not set
# CONFIG_PACKAGE_libupm-lsm9ds0 is not set
# CONFIG_PACKAGE_libupm-lsm9ds0-node is not set
# CONFIG_PACKAGE_libupm-m24lr64e is not set
# CONFIG_PACKAGE_libupm-m24lr64e-node is not set
# CONFIG_PACKAGE_libupm-mag3110 is not set
# CONFIG_PACKAGE_libupm-mag3110-node is not set
# CONFIG_PACKAGE_libupm-max30100 is not set
# CONFIG_PACKAGE_libupm-max30100-node is not set
# CONFIG_PACKAGE_libupm-max31723 is not set
# CONFIG_PACKAGE_libupm-max31723-node is not set
# CONFIG_PACKAGE_libupm-max31855 is not set
# CONFIG_PACKAGE_libupm-max31855-node is not set
# CONFIG_PACKAGE_libupm-max44000 is not set
# CONFIG_PACKAGE_libupm-max44000-node is not set
# CONFIG_PACKAGE_libupm-max44009 is not set
# CONFIG_PACKAGE_libupm-max44009-node is not set
# CONFIG_PACKAGE_libupm-max5487 is not set
# CONFIG_PACKAGE_libupm-max5487-node is not set
# CONFIG_PACKAGE_libupm-maxds3231m is not set
# CONFIG_PACKAGE_libupm-maxds3231m-node is not set
# CONFIG_PACKAGE_libupm-maxsonarez is not set
# CONFIG_PACKAGE_libupm-maxsonarez-node is not set
# CONFIG_PACKAGE_libupm-mb704x is not set
# CONFIG_PACKAGE_libupm-mb704x-node is not set
# CONFIG_PACKAGE_libupm-mcp2515 is not set
# CONFIG_PACKAGE_libupm-mcp2515-node is not set
# CONFIG_PACKAGE_libupm-mcp9808 is not set
# CONFIG_PACKAGE_libupm-mcp9808-node is not set
# CONFIG_PACKAGE_libupm-md is not set
# CONFIG_PACKAGE_libupm-md-node is not set
# CONFIG_PACKAGE_libupm-mg811 is not set
# CONFIG_PACKAGE_libupm-mg811-node is not set
# CONFIG_PACKAGE_libupm-mhz16 is not set
# CONFIG_PACKAGE_libupm-mhz16-node is not set
# CONFIG_PACKAGE_libupm-mic is not set
# CONFIG_PACKAGE_libupm-mic-node is not set
# CONFIG_PACKAGE_libupm-micsv89 is not set
# CONFIG_PACKAGE_libupm-micsv89-node is not set
# CONFIG_PACKAGE_libupm-mlx90614 is not set
# CONFIG_PACKAGE_libupm-mlx90614-node is not set
# CONFIG_PACKAGE_libupm-mma7361 is not set
# CONFIG_PACKAGE_libupm-mma7361-node is not set
# CONFIG_PACKAGE_libupm-mma7455 is not set
# CONFIG_PACKAGE_libupm-mma7455-node is not set
# CONFIG_PACKAGE_libupm-mma7660 is not set
# CONFIG_PACKAGE_libupm-mma7660-node is not set
# CONFIG_PACKAGE_libupm-mma8x5x is not set
# CONFIG_PACKAGE_libupm-mma8x5x-node is not set
# CONFIG_PACKAGE_libupm-mmc35240 is not set
# CONFIG_PACKAGE_libupm-mmc35240-node is not set
# CONFIG_PACKAGE_libupm-moisture is not set
# CONFIG_PACKAGE_libupm-moisture-node is not set
# CONFIG_PACKAGE_libupm-mpl3115a2 is not set
# CONFIG_PACKAGE_libupm-mpl3115a2-node is not set
# CONFIG_PACKAGE_libupm-mpr121 is not set
# CONFIG_PACKAGE_libupm-mpr121-node is not set
# CONFIG_PACKAGE_libupm-mpu9150 is not set
# CONFIG_PACKAGE_libupm-mpu9150-node is not set
# CONFIG_PACKAGE_libupm-mq303a is not set
# CONFIG_PACKAGE_libupm-mq303a-node is not set
# CONFIG_PACKAGE_libupm-ms5611 is not set
# CONFIG_PACKAGE_libupm-ms5611-node is not set
# CONFIG_PACKAGE_libupm-ms5803 is not set
# CONFIG_PACKAGE_libupm-ms5803-node is not set
# CONFIG_PACKAGE_libupm-my9221 is not set
# CONFIG_PACKAGE_libupm-my9221-node is not set
# CONFIG_PACKAGE_libupm-nlgpio16 is not set
# CONFIG_PACKAGE_libupm-nlgpio16-node is not set
# CONFIG_PACKAGE_libupm-nmea_gps is not set
# CONFIG_PACKAGE_libupm-nmea_gps-node is not set
# CONFIG_PACKAGE_libupm-nrf24l01 is not set
# CONFIG_PACKAGE_libupm-nrf24l01-node is not set
# CONFIG_PACKAGE_libupm-nrf8001 is not set
# CONFIG_PACKAGE_libupm-nrf8001-node is not set
# CONFIG_PACKAGE_libupm-nunchuck is not set
# CONFIG_PACKAGE_libupm-nunchuck-node is not set
# CONFIG_PACKAGE_libupm-o2 is not set
# CONFIG_PACKAGE_libupm-o2-node is not set
# CONFIG_PACKAGE_libupm-otp538u is not set
# CONFIG_PACKAGE_libupm-otp538u-node is not set
# CONFIG_PACKAGE_libupm-ozw is not set
# CONFIG_PACKAGE_libupm-ozw-node is not set
# CONFIG_PACKAGE_libupm-p9813 is not set
# CONFIG_PACKAGE_libupm-p9813-node is not set
# CONFIG_PACKAGE_libupm-pca9685 is not set
# CONFIG_PACKAGE_libupm-pca9685-node is not set
# CONFIG_PACKAGE_libupm-pn532 is not set
# CONFIG_PACKAGE_libupm-pn532-node is not set
# CONFIG_PACKAGE_libupm-ppd42ns is not set
# CONFIG_PACKAGE_libupm-ppd42ns-node is not set
# CONFIG_PACKAGE_libupm-pulsensor is not set
# CONFIG_PACKAGE_libupm-pulsensor-node is not set
# CONFIG_PACKAGE_libupm-relay is not set
# CONFIG_PACKAGE_libupm-relay-node is not set
# CONFIG_PACKAGE_libupm-rf22 is not set
# CONFIG_PACKAGE_libupm-rf22-node is not set
# CONFIG_PACKAGE_libupm-rfr359f is not set
# CONFIG_PACKAGE_libupm-rfr359f-node is not set
# CONFIG_PACKAGE_libupm-rgbringcoder is not set
# CONFIG_PACKAGE_libupm-rgbringcoder-node is not set
# CONFIG_PACKAGE_libupm-rhusb is not set
# CONFIG_PACKAGE_libupm-rhusb-node is not set
# CONFIG_PACKAGE_libupm-rn2903 is not set
# CONFIG_PACKAGE_libupm-rn2903-node is not set
# CONFIG_PACKAGE_libupm-rotary is not set
# CONFIG_PACKAGE_libupm-rotary-node is not set
# CONFIG_PACKAGE_libupm-rotaryencoder is not set
# CONFIG_PACKAGE_libupm-rotaryencoder-node is not set
# CONFIG_PACKAGE_libupm-rpr220 is not set
# CONFIG_PACKAGE_libupm-rpr220-node is not set
# CONFIG_PACKAGE_libupm-rsc is not set
# CONFIG_PACKAGE_libupm-rsc-node is not set
# CONFIG_PACKAGE_libupm-scam is not set
# CONFIG_PACKAGE_libupm-scam-node is not set
# CONFIG_PACKAGE_libupm-sensortemplate is not set
# CONFIG_PACKAGE_libupm-sensortemplate-node is not set
# CONFIG_PACKAGE_libupm-servo is not set
# CONFIG_PACKAGE_libupm-servo-node is not set
# CONFIG_PACKAGE_libupm-sht1x is not set
# CONFIG_PACKAGE_libupm-sht1x-node is not set
# CONFIG_PACKAGE_libupm-si1132 is not set
# CONFIG_PACKAGE_libupm-si1132-node is not set
# CONFIG_PACKAGE_libupm-si114x is not set
# CONFIG_PACKAGE_libupm-si114x-node is not set
# CONFIG_PACKAGE_libupm-si7005 is not set
# CONFIG_PACKAGE_libupm-si7005-node is not set
# CONFIG_PACKAGE_libupm-slide is not set
# CONFIG_PACKAGE_libupm-slide-node is not set
# CONFIG_PACKAGE_libupm-sm130 is not set
# CONFIG_PACKAGE_libupm-sm130-node is not set
# CONFIG_PACKAGE_libupm-smartdrive is not set
# CONFIG_PACKAGE_libupm-smartdrive-node is not set
# CONFIG_PACKAGE_libupm-speaker is not set
# CONFIG_PACKAGE_libupm-speaker-node is not set
# CONFIG_PACKAGE_libupm-ssd1351 is not set
# CONFIG_PACKAGE_libupm-ssd1351-node is not set
# CONFIG_PACKAGE_libupm-st7735 is not set
# CONFIG_PACKAGE_libupm-st7735-node is not set
# CONFIG_PACKAGE_libupm-stepmotor is not set
# CONFIG_PACKAGE_libupm-stepmotor-node is not set
# CONFIG_PACKAGE_libupm-sx1276 is not set
# CONFIG_PACKAGE_libupm-sx1276-node is not set
# CONFIG_PACKAGE_libupm-sx6119 is not set
# CONFIG_PACKAGE_libupm-sx6119-node is not set
# CONFIG_PACKAGE_libupm-t3311 is not set
# CONFIG_PACKAGE_libupm-t3311-node is not set
# CONFIG_PACKAGE_libupm-t6713 is not set
# CONFIG_PACKAGE_libupm-t6713-node is not set
# CONFIG_PACKAGE_libupm-ta12200 is not set
# CONFIG_PACKAGE_libupm-ta12200-node is not set
# CONFIG_PACKAGE_libupm-tca9548a is not set
# CONFIG_PACKAGE_libupm-tca9548a-node is not set
# CONFIG_PACKAGE_libupm-tcs3414cs is not set
# CONFIG_PACKAGE_libupm-tcs3414cs-node is not set
# CONFIG_PACKAGE_libupm-tcs37727 is not set
# CONFIG_PACKAGE_libupm-tcs37727-node is not set
# CONFIG_PACKAGE_libupm-teams is not set
# CONFIG_PACKAGE_libupm-teams-node is not set
# CONFIG_PACKAGE_libupm-temperature is not set
# CONFIG_PACKAGE_libupm-temperature-node is not set
# CONFIG_PACKAGE_libupm-tex00 is not set
# CONFIG_PACKAGE_libupm-tex00-node is not set
# CONFIG_PACKAGE_libupm-th02 is not set
# CONFIG_PACKAGE_libupm-th02-node is not set
# CONFIG_PACKAGE_libupm-tm1637 is not set
# CONFIG_PACKAGE_libupm-tm1637-node is not set
# CONFIG_PACKAGE_libupm-tmp006 is not set
# CONFIG_PACKAGE_libupm-tmp006-node is not set
# CONFIG_PACKAGE_libupm-tsl2561 is not set
# CONFIG_PACKAGE_libupm-tsl2561-node is not set
# CONFIG_PACKAGE_libupm-ttp223 is not set
# CONFIG_PACKAGE_libupm-ttp223-node is not set
# CONFIG_PACKAGE_libupm-uartat is not set
# CONFIG_PACKAGE_libupm-uartat-node is not set
# CONFIG_PACKAGE_libupm-uln200xa is not set
# CONFIG_PACKAGE_libupm-uln200xa-node is not set
# CONFIG_PACKAGE_libupm-ultrasonic is not set
# CONFIG_PACKAGE_libupm-ultrasonic-node is not set
# CONFIG_PACKAGE_libupm-urm37 is not set
# CONFIG_PACKAGE_libupm-urm37-node is not set
# CONFIG_PACKAGE_libupm-utilities is not set
# CONFIG_PACKAGE_libupm-utilities-node is not set
# CONFIG_PACKAGE_libupm-vcap is not set
# CONFIG_PACKAGE_libupm-vcap-node is not set
# CONFIG_PACKAGE_libupm-vdiv is not set
# CONFIG_PACKAGE_libupm-vdiv-node is not set
# CONFIG_PACKAGE_libupm-veml6070 is not set
# CONFIG_PACKAGE_libupm-veml6070-node is not set
# CONFIG_PACKAGE_libupm-water is not set
# CONFIG_PACKAGE_libupm-water-node is not set
# CONFIG_PACKAGE_libupm-waterlevel is not set
# CONFIG_PACKAGE_libupm-waterlevel-node is not set
# CONFIG_PACKAGE_libupm-wfs is not set
# CONFIG_PACKAGE_libupm-wfs-node is not set
# CONFIG_PACKAGE_libupm-wheelencoder is not set
# CONFIG_PACKAGE_libupm-wheelencoder-node is not set
# CONFIG_PACKAGE_libupm-wt5001 is not set
# CONFIG_PACKAGE_libupm-wt5001-node is not set
# CONFIG_PACKAGE_libupm-xbee is not set
# CONFIG_PACKAGE_libupm-xbee-node is not set
# CONFIG_PACKAGE_libupm-yg1006 is not set
# CONFIG_PACKAGE_libupm-yg1006-node is not set
# CONFIG_PACKAGE_libupm-zfm20 is not set
# CONFIG_PACKAGE_libupm-zfm20-node is not set
# end of IoT
#
# Languages
#
CONFIG_PACKAGE_libyaml=y
# end of Languages
#
# LibElektra
#
# CONFIG_PACKAGE_libelektra-boost is not set
# CONFIG_PACKAGE_libelektra-core is not set
# CONFIG_PACKAGE_libelektra-cpp is not set
# CONFIG_PACKAGE_libelektra-crypto is not set
# CONFIG_PACKAGE_libelektra-curlget is not set
# CONFIG_PACKAGE_libelektra-dbus is not set
# CONFIG_PACKAGE_libelektra-extra is not set
# CONFIG_PACKAGE_libelektra-lua is not set
# CONFIG_PACKAGE_libelektra-plugins is not set
# CONFIG_PACKAGE_libelektra-python3 is not set
# CONFIG_PACKAGE_libelektra-resolvers is not set
# CONFIG_PACKAGE_libelektra-xerces is not set
# CONFIG_PACKAGE_libelektra-xml is not set
# CONFIG_PACKAGE_libelektra-yajl is not set
# CONFIG_PACKAGE_libelektra-yamlcpp is not set
# CONFIG_PACKAGE_libelektra-zmq is not set
# end of LibElektra
#
# Networking
#
# CONFIG_PACKAGE_libdcwproto is not set
# CONFIG_PACKAGE_libdcwsocket is not set
# CONFIG_PACKAGE_libsctp is not set
# CONFIG_PACKAGE_libuhttpd-mbedtls is not set
# CONFIG_PACKAGE_libuhttpd-nossl is not set
# CONFIG_PACKAGE_libuhttpd-openssl is not set
# CONFIG_PACKAGE_libuhttpd-wolfssl is not set
# CONFIG_PACKAGE_libulfius-gnutls is not set
# CONFIG_PACKAGE_libulfius-nossl is not set
# CONFIG_PACKAGE_libunbound is not set
# CONFIG_PACKAGE_libuwsc-mbedtls is not set
# CONFIG_PACKAGE_libuwsc-nossl is not set
# CONFIG_PACKAGE_libuwsc-openssl is not set
# CONFIG_PACKAGE_libuwsc-wolfssl is not set
# end of Networking
#
# Qt5
#
# CONFIG_PACKAGE_qt5-core is not set
# CONFIG_PACKAGE_qt5-network is not set
# CONFIG_PACKAGE_qt5-sql is not set
# CONFIG_PACKAGE_qt5-xml is not set
# end of Qt5
#
# SSL
#
# CONFIG_PACKAGE_libgnutls is not set
CONFIG_PACKAGE_libmbedtls=y
# CONFIG_LIBMBEDTLS_DEBUG_C is not set
# CONFIG_PACKAGE_libnss is not set
CONFIG_PACKAGE_libopenssl=y
#
# Build Options
#
CONFIG_OPENSSL_OPTIMIZE_SPEED=y
CONFIG_OPENSSL_WITH_ASM=y
CONFIG_OPENSSL_WITH_DEPRECATED=y
# CONFIG_OPENSSL_NO_DEPRECATED is not set
CONFIG_OPENSSL_WITH_ERROR_MESSAGES=y
#
# Protocol Support
#
CONFIG_OPENSSL_WITH_TLS13=y
# CONFIG_OPENSSL_WITH_DTLS is not set
# CONFIG_OPENSSL_WITH_NPN is not set
CONFIG_OPENSSL_WITH_SRP=y
CONFIG_OPENSSL_WITH_CMS=y
#
# Algorithm Selection
#
# CONFIG_OPENSSL_WITH_EC2M is not set
CONFIG_OPENSSL_WITH_CHACHA_POLY1305=y
CONFIG_OPENSSL_PREFER_CHACHA_OVER_GCM=y
CONFIG_OPENSSL_WITH_PSK=y
#
# Less commonly used build options
#
# CONFIG_OPENSSL_WITH_ARIA is not set
# CONFIG_OPENSSL_WITH_CAMELLIA is not set
# CONFIG_OPENSSL_WITH_IDEA is not set
# CONFIG_OPENSSL_WITH_SEED is not set
# CONFIG_OPENSSL_WITH_SM234 is not set
# CONFIG_OPENSSL_WITH_BLAKE2 is not set
# CONFIG_OPENSSL_WITH_MDC2 is not set
# CONFIG_OPENSSL_WITH_WHIRLPOOL is not set
# CONFIG_OPENSSL_WITH_COMPRESSION is not set
# CONFIG_OPENSSL_WITH_RFC3779 is not set
#
# Engine/Hardware Support
#
CONFIG_OPENSSL_ENGINE=y
CONFIG_OPENSSL_ENGINE_BUILTIN=y
CONFIG_OPENSSL_ENGINE_BUILTIN_AFALG=y
CONFIG_OPENSSL_ENGINE_BUILTIN_DEVCRYPTO=y
# CONFIG_OPENSSL_WITH_GOST is not set
CONFIG_PACKAGE_libopenssl-conf=y
# CONFIG_PACKAGE_libopenssl-devcrypto is not set
# CONFIG_PACKAGE_libopenssl1.1 is not set
# CONFIG_PACKAGE_libpolarssl is not set
# CONFIG_PACKAGE_libwolfssl is not set
# end of SSL
#
# Sound
#
# CONFIG_PACKAGE_liblo is not set
# end of Sound
#
# Telephony
#
# CONFIG_PACKAGE_bcg729 is not set
# CONFIG_PACKAGE_dahdi-tools-libtonezone is not set
# CONFIG_PACKAGE_gsmlib is not set
# CONFIG_PACKAGE_libctb is not set
# CONFIG_PACKAGE_libfreetdm is not set
# CONFIG_PACKAGE_libiksemel is not set
# CONFIG_PACKAGE_libks is not set
# CONFIG_PACKAGE_libosip2 is not set
# CONFIG_PACKAGE_libpj is not set
# CONFIG_PACKAGE_libpjlib-util is not set
# CONFIG_PACKAGE_libpjmedia is not set
# CONFIG_PACKAGE_libpjnath is not set
# CONFIG_PACKAGE_libpjsip is not set
# CONFIG_PACKAGE_libpjsip-simple is not set
# CONFIG_PACKAGE_libpjsip-ua is not set
# CONFIG_PACKAGE_libpjsua is not set
# CONFIG_PACKAGE_libpjsua2 is not set
# CONFIG_PACKAGE_libre is not set
# CONFIG_PACKAGE_librem is not set
# CONFIG_PACKAGE_libspandsp is not set
# CONFIG_PACKAGE_libspandsp3 is not set
# CONFIG_PACKAGE_libsrtp2 is not set
# CONFIG_PACKAGE_signalwire-client-c is not set
# CONFIG_PACKAGE_sofia-sip is not set
# end of Telephony
#
# libimobiledevice
#
# CONFIG_PACKAGE_libimobiledevice is not set
# CONFIG_PACKAGE_libirecovery is not set
# CONFIG_PACKAGE_libplist is not set
# CONFIG_PACKAGE_libplistcxx is not set
# CONFIG_PACKAGE_libusbmuxd is not set
# end of libimobiledevice
# CONFIG_PACKAGE_alsa-lib is not set
# CONFIG_PACKAGE_argp-standalone is not set
# CONFIG_PACKAGE_bind-libs is not set
# CONFIG_PACKAGE_bluez-libs is not set
# CONFIG_PACKAGE_boost is not set
# CONFIG_boost-context-exclude is not set
# CONFIG_boost-coroutine-exclude is not set
# CONFIG_boost-fiber-exclude is not set
# CONFIG_PACKAGE_ccid is not set
# CONFIG_PACKAGE_check is not set
# CONFIG_PACKAGE_confuse is not set
# CONFIG_PACKAGE_czmq is not set
# CONFIG_PACKAGE_dtndht is not set
# CONFIG_PACKAGE_getdns is not set
# CONFIG_PACKAGE_giflib is not set
# CONFIG_PACKAGE_glib2 is not set
# CONFIG_PACKAGE_google-authenticator-libpam is not set
# CONFIG_PACKAGE_hidapi is not set
# CONFIG_PACKAGE_ibrcommon is not set
# CONFIG_PACKAGE_ibrdtn is not set
# CONFIG_PACKAGE_icu is not set
# CONFIG_PACKAGE_icu-data-tools is not set
# CONFIG_PACKAGE_icu-full-data is not set
# CONFIG_PACKAGE_jansson is not set
# CONFIG_PACKAGE_json-glib is not set
# CONFIG_PACKAGE_jsoncpp is not set
# CONFIG_PACKAGE_knot-libs is not set
# CONFIG_PACKAGE_knot-libzscanner is not set
# CONFIG_PACKAGE_libaio is not set
# CONFIG_PACKAGE_libantlr3c is not set
# CONFIG_PACKAGE_libao is not set
# CONFIG_PACKAGE_libapr is not set
# CONFIG_PACKAGE_libaprutil is not set
# CONFIG_PACKAGE_libarchive is not set
# CONFIG_PACKAGE_libarchive-noopenssl is not set
# CONFIG_PACKAGE_libasm is not set
# CONFIG_PACKAGE_libavahi-client is not set
# CONFIG_PACKAGE_libavahi-compat-libdnssd is not set
# CONFIG_PACKAGE_libavahi-dbus-support is not set
# CONFIG_PACKAGE_libavahi-nodbus-support is not set
# CONFIG_PACKAGE_libbfd is not set
# CONFIG_PACKAGE_libblkid is not set
CONFIG_PACKAGE_libblobmsg-json=y
# CONFIG_PACKAGE_libbsd is not set
CONFIG_PACKAGE_libcap=y
CONFIG_PACKAGE_libcap-bin=y
CONFIG_PACKAGE_libcap-bin-capsh-shell="/bin/sh"
# CONFIG_PACKAGE_libcap-ng is not set
# CONFIG_PACKAGE_libcares is not set
# CONFIG_PACKAGE_libcgroup is not set
# CONFIG_PACKAGE_libcharset is not set
# CONFIG_PACKAGE_libcoap is not set
# CONFIG_PACKAGE_libcomerr is not set
# CONFIG_PACKAGE_libconfig is not set
# CONFIG_PACKAGE_libcryptopp is not set
# CONFIG_PACKAGE_libcups is not set
CONFIG_PACKAGE_libcurl=y
#
# SSL support
#
CONFIG_LIBCURL_MBEDTLS=y
# CONFIG_LIBCURL_WOLFSSL is not set
# CONFIG_LIBCURL_OPENSSL is not set
# CONFIG_LIBCURL_GNUTLS is not set
# CONFIG_LIBCURL_NOSSL is not set
#
# Supported protocols
#
# CONFIG_LIBCURL_DICT is not set
CONFIG_LIBCURL_FILE=y
CONFIG_LIBCURL_FTP=y
# CONFIG_LIBCURL_GOPHER is not set
CONFIG_LIBCURL_HTTP=y
CONFIG_LIBCURL_COOKIES=y
# CONFIG_LIBCURL_IMAP is not set
# CONFIG_LIBCURL_LDAP is not set
# CONFIG_LIBCURL_POP3 is not set
# CONFIG_LIBCURL_RTSP is not set
# CONFIG_LIBCURL_SSH2 is not set
CONFIG_LIBCURL_NO_SMB="!"
# CONFIG_LIBCURL_SMTP is not set
# CONFIG_LIBCURL_TELNET is not set
# CONFIG_LIBCURL_TFTP is not set
# CONFIG_LIBCURL_NGHTTP2 is not set
#
# Miscellaneous
#
CONFIG_LIBCURL_PROXY=y
# CONFIG_LIBCURL_CRYPTO_AUTH is not set
# CONFIG_LIBCURL_TLS_SRP is not set
# CONFIG_LIBCURL_LIBIDN2 is not set
# CONFIG_LIBCURL_THREADED_RESOLVER is not set
# CONFIG_LIBCURL_ZLIB is not set
# CONFIG_LIBCURL_UNIX_SOCKETS is not set
# CONFIG_LIBCURL_LIBCURL_OPTION is not set
# CONFIG_LIBCURL_VERBOSE is not set
# CONFIG_PACKAGE_libcxx is not set
# CONFIG_PACKAGE_libdaemon is not set
# CONFIG_PACKAGE_libdaq is not set
CONFIG_PACKAGE_libdb47=y
# CONFIG_PACKAGE_libdb47xx is not set
# CONFIG_PACKAGE_libdbi is not set
# CONFIG_PACKAGE_libdbus is not set
# CONFIG_PACKAGE_libdevmapper is not set
# CONFIG_PACKAGE_libdmapsharing is not set
# CONFIG_PACKAGE_libdnet is not set
# CONFIG_PACKAGE_libdouble-conversion is not set
# CONFIG_PACKAGE_libdrm is not set
# CONFIG_PACKAGE_libdw is not set
# CONFIG_PACKAGE_libecdsautil is not set
# CONFIG_PACKAGE_libedit is not set
CONFIG_PACKAGE_libelf=y
# CONFIG_PACKAGE_libesmtp is not set
# CONFIG_PACKAGE_libestr is not set
CONFIG_PACKAGE_libev=y
# CONFIG_PACKAGE_libevdev is not set
# CONFIG_PACKAGE_libevent2 is not set
# CONFIG_PACKAGE_libevent2-core is not set
# CONFIG_PACKAGE_libevent2-extra is not set
# CONFIG_PACKAGE_libevent2-openssl is not set
# CONFIG_PACKAGE_libevent2-pthreads is not set
# CONFIG_PACKAGE_libevhtp is not set
# CONFIG_LIBEVHTP_BUILD_DEPENDS is not set
# CONFIG_PACKAGE_libexif is not set
# CONFIG_PACKAGE_libexpat is not set
# CONFIG_PACKAGE_libexslt is not set
# CONFIG_PACKAGE_libext2fs is not set
# CONFIG_PACKAGE_libextractor is not set
# CONFIG_PACKAGE_libf2fs is not set
# CONFIG_PACKAGE_libfaad2 is not set
# CONFIG_PACKAGE_libfastjson is not set
# CONFIG_PACKAGE_libfdisk is not set
# CONFIG_PACKAGE_libfdt is not set
# CONFIG_PACKAGE_libffi is not set
# CONFIG_PACKAGE_libffmpeg-audio-dec is not set
# CONFIG_PACKAGE_libffmpeg-custom is not set
# CONFIG_PACKAGE_libffmpeg-full is not set
# CONFIG_PACKAGE_libffmpeg-mini is not set
# CONFIG_PACKAGE_libflac is not set
# CONFIG_PACKAGE_libfmt is not set
# CONFIG_PACKAGE_libfreetype is not set
# CONFIG_PACKAGE_libfstrm is not set
# CONFIG_PACKAGE_libftdi is not set
# CONFIG_PACKAGE_libftdi1 is not set
# CONFIG_PACKAGE_libgabe is not set
# CONFIG_PACKAGE_libgcrypt is not set
# CONFIG_PACKAGE_libgd is not set
# CONFIG_PACKAGE_libgd-full is not set
# CONFIG_PACKAGE_libgdbm is not set
# CONFIG_PACKAGE_libgee is not set
CONFIG_PACKAGE_libgmp=y
# CONFIG_PACKAGE_libgnurl is not set
# CONFIG_PACKAGE_libgpg-error is not set
# CONFIG_PACKAGE_libgphoto2 is not set
# CONFIG_PACKAGE_libgpiod is not set
# CONFIG_PACKAGE_libgps is not set
# CONFIG_PACKAGE_libh2o is not set
# CONFIG_PACKAGE_libh2o-evloop is not set
# CONFIG_PACKAGE_libhamlib is not set
# CONFIG_PACKAGE_libhavege is not set
# CONFIG_PACKAGE_libhiredis is not set
# CONFIG_PACKAGE_libhttp-parser is not set
# CONFIG_PACKAGE_libhwloc is not set
# CONFIG_PACKAGE_libi2c is not set
# CONFIG_PACKAGE_libical is not set
# CONFIG_PACKAGE_libiconv is not set
# CONFIG_PACKAGE_libiconv-full is not set
# CONFIG_PACKAGE_libid3tag is not set
# CONFIG_PACKAGE_libidn is not set
# CONFIG_PACKAGE_libidn2 is not set
# CONFIG_PACKAGE_libiio is not set
# CONFIG_PACKAGE_libinotifytools is not set
# CONFIG_PACKAGE_libinput is not set
# CONFIG_PACKAGE_libintl is not set
# CONFIG_PACKAGE_libintl-full is not set
# CONFIG_PACKAGE_libipfs-http-client is not set
# CONFIG_PACKAGE_libiw is not set
CONFIG_PACKAGE_libiwinfo=y
# CONFIG_PACKAGE_libjpeg-turbo is not set
CONFIG_PACKAGE_libjson-c=y
# CONFIG_PACKAGE_libkeyutils is not set
# CONFIG_PACKAGE_libkmod is not set
# CONFIG_PACKAGE_libldns is not set
# CONFIG_PACKAGE_libleptonica is not set
# CONFIG_PACKAGE_libloragw is not set
CONFIG_PACKAGE_libltdl=y
CONFIG_PACKAGE_liblua=y
CONFIG_PACKAGE_liblua5.3=y
# CONFIG_PACKAGE_liblzo is not set
# CONFIG_PACKAGE_libmad is not set
# CONFIG_PACKAGE_libmagic is not set
# CONFIG_PACKAGE_libmaxminddb is not set
# CONFIG_PACKAGE_libmbim is not set
# CONFIG_PACKAGE_libmcrypt is not set
# CONFIG_PACKAGE_libmicrohttpd-no-ssl is not set
# CONFIG_PACKAGE_libmicrohttpd-ssl is not set
# CONFIG_PACKAGE_libmilter-sendmail is not set
CONFIG_PACKAGE_libminiupnpc=y
# CONFIG_PACKAGE_libmms is not set
CONFIG_PACKAGE_libmnl=y
# CONFIG_PACKAGE_libmodbus is not set
# CONFIG_PACKAGE_libmosquitto-nossl is not set
# CONFIG_PACKAGE_libmosquitto-ssl is not set
# CONFIG_PACKAGE_libmount is not set
# CONFIG_PACKAGE_libmpdclient is not set
# CONFIG_PACKAGE_libmpeg2 is not set
# CONFIG_PACKAGE_libmpg123 is not set
CONFIG_PACKAGE_libnatpmp=y
CONFIG_PACKAGE_libncurses=y
# CONFIG_PACKAGE_libndpi is not set
# CONFIG_PACKAGE_libneon is not set
# CONFIG_PACKAGE_libnet-1.2.x is not set
# CONFIG_PACKAGE_libnetconf2 is not set
# CONFIG_PACKAGE_libnetfilter-acct is not set
# CONFIG_PACKAGE_libnetfilter-conntrack is not set
# CONFIG_PACKAGE_libnetfilter-cthelper is not set
# CONFIG_PACKAGE_libnetfilter-cttimeout is not set
# CONFIG_PACKAGE_libnetfilter-log is not set
# CONFIG_PACKAGE_libnetfilter-queue is not set
# CONFIG_PACKAGE_libnetsnmp is not set
# CONFIG_PACKAGE_libnettle is not set
# CONFIG_PACKAGE_libnewt is not set
# CONFIG_PACKAGE_libnfnetlink is not set
# CONFIG_PACKAGE_libnftnl is not set
# CONFIG_PACKAGE_libnghttp2 is not set
# CONFIG_PACKAGE_libnl is not set
# CONFIG_PACKAGE_libnl-core is not set
# CONFIG_PACKAGE_libnl-genl is not set
# CONFIG_PACKAGE_libnl-nf is not set
# CONFIG_PACKAGE_libnl-route is not set
CONFIG_PACKAGE_libnl-tiny=y
# CONFIG_PACKAGE_libnopoll is not set
# CONFIG_PACKAGE_libnpupnp is not set
# CONFIG_PACKAGE_libogg is not set
# CONFIG_PACKAGE_liboil is not set
# CONFIG_PACKAGE_libopcodes is not set
# CONFIG_PACKAGE_libopendkim is not set
# CONFIG_PACKAGE_libopenobex is not set
# CONFIG_PACKAGE_libopensc is not set
# CONFIG_PACKAGE_libopenzwave is not set
# CONFIG_PACKAGE_liboping is not set
# CONFIG_PACKAGE_libopus is not set
# CONFIG_PACKAGE_libopusenc is not set
# CONFIG_PACKAGE_libopusfile is not set
# CONFIG_PACKAGE_liborcania is not set
# CONFIG_PACKAGE_libout123 is not set
# CONFIG_PACKAGE_libowfat is not set
# CONFIG_PACKAGE_libp11 is not set
# CONFIG_PACKAGE_libpagekite is not set
# CONFIG_PACKAGE_libpam is not set
# CONFIG_PACKAGE_libpbc is not set
# CONFIG_PACKAGE_libpcap is not set
# CONFIG_PACKAGE_libpci is not set
# CONFIG_PACKAGE_libpciaccess is not set
CONFIG_PACKAGE_libpcre=y
# CONFIG_PCRE_JIT_ENABLED is not set
# CONFIG_PACKAGE_libpcre16 is not set
# CONFIG_PACKAGE_libpcre2 is not set
# CONFIG_PACKAGE_libpcre2-16 is not set
# CONFIG_PACKAGE_libpcre2-32 is not set
# CONFIG_PACKAGE_libpcre32 is not set
# CONFIG_PACKAGE_libpcrecpp is not set
# CONFIG_PACKAGE_libpcsclite is not set
# CONFIG_PACKAGE_libpfring is not set
# CONFIG_PACKAGE_libpkcs11-spy is not set
# CONFIG_PACKAGE_libpkgconf is not set
# CONFIG_PACKAGE_libpng is not set
# CONFIG_PACKAGE_libpopt is not set
# CONFIG_PACKAGE_libpri is not set
# CONFIG_PACKAGE_libprotobuf-c is not set
# CONFIG_PACKAGE_libpsl is not set
# CONFIG_PACKAGE_libqmi is not set
# CONFIG_PACKAGE_libqrencode is not set
# CONFIG_PACKAGE_libradcli is not set
# CONFIG_PACKAGE_libradiotap is not set
CONFIG_PACKAGE_libreadline=y
# CONFIG_PACKAGE_libredblack is not set
# CONFIG_PACKAGE_librouteros is not set
# CONFIG_PACKAGE_libroxml is not set
# CONFIG_PACKAGE_librrd1 is not set
# CONFIG_PACKAGE_librtlsdr is not set
CONFIG_PACKAGE_libruby=y
# CONFIG_PACKAGE_libsamplerate is not set
# CONFIG_PACKAGE_libsane is not set
# CONFIG_PACKAGE_libsasl2 is not set
# CONFIG_PACKAGE_libsearpc is not set
# CONFIG_PACKAGE_libseccomp is not set
# CONFIG_PACKAGE_libselinux is not set
# CONFIG_PACKAGE_libsensors is not set
# CONFIG_PACKAGE_libsepol is not set
# CONFIG_PACKAGE_libshout is not set
# CONFIG_PACKAGE_libshout-full is not set
# CONFIG_PACKAGE_libshout-nossl is not set
# CONFIG_PACKAGE_libsispmctl is not set
# CONFIG_PACKAGE_libslang2 is not set
# CONFIG_PACKAGE_libslang2-mod-base64 is not set
# CONFIG_PACKAGE_libslang2-mod-chksum is not set
# CONFIG_PACKAGE_libslang2-mod-csv is not set
# CONFIG_PACKAGE_libslang2-mod-fcntl is not set
# CONFIG_PACKAGE_libslang2-mod-fork is not set
# CONFIG_PACKAGE_libslang2-mod-histogram is not set
# CONFIG_PACKAGE_libslang2-mod-iconv is not set
# CONFIG_PACKAGE_libslang2-mod-json is not set
# CONFIG_PACKAGE_libslang2-mod-onig is not set
# CONFIG_PACKAGE_libslang2-mod-pcre is not set
# CONFIG_PACKAGE_libslang2-mod-png is not set
# CONFIG_PACKAGE_libslang2-mod-rand is not set
# CONFIG_PACKAGE_libslang2-mod-select is not set
# CONFIG_PACKAGE_libslang2-mod-slsmg is not set
# CONFIG_PACKAGE_libslang2-mod-socket is not set
# CONFIG_PACKAGE_libslang2-mod-stats is not set
# CONFIG_PACKAGE_libslang2-mod-sysconf is not set
# CONFIG_PACKAGE_libslang2-mod-termios is not set
# CONFIG_PACKAGE_libslang2-mod-varray is not set
# CONFIG_PACKAGE_libslang2-mod-zlib is not set
# CONFIG_PACKAGE_libslang2-modules is not set
# CONFIG_PACKAGE_libsmartcols is not set
# CONFIG_PACKAGE_libsndfile is not set
# CONFIG_PACKAGE_libsoc is not set
# CONFIG_PACKAGE_libsocks is not set
CONFIG_PACKAGE_libsodium=y
#
# Configuration
#
CONFIG_LIBSODIUM_MINIMAL=y
# end of Configuration
# CONFIG_PACKAGE_libsoup is not set
# CONFIG_PACKAGE_libsoxr is not set
# CONFIG_PACKAGE_libspeex is not set
# CONFIG_PACKAGE_libspeexdsp is not set
# CONFIG_PACKAGE_libspice-server is not set
# CONFIG_PACKAGE_libss is not set
# CONFIG_PACKAGE_libssh is not set
# CONFIG_PACKAGE_libssh2 is not set
# CONFIG_PACKAGE_libstoken is not set
# CONFIG_PACKAGE_libstrophe is not set
# CONFIG_PACKAGE_libsysrepo is not set
# CONFIG_PACKAGE_libtalloc is not set
# CONFIG_PACKAGE_libtasn1 is not set
# CONFIG_PACKAGE_libtheora is not set
# CONFIG_PACKAGE_libtiff is not set
# CONFIG_PACKAGE_libtiffxx is not set
# CONFIG_PACKAGE_libtins is not set
# CONFIG_PACKAGE_libtirpc is not set
# CONFIG_PACKAGE_libtorrent is not set
CONFIG_PACKAGE_libubox=y
# CONFIG_PACKAGE_libubox-lua is not set
CONFIG_PACKAGE_libubus=y
CONFIG_PACKAGE_libubus-lua=y
CONFIG_PACKAGE_libuci=y
CONFIG_PACKAGE_libuci-lua=y
CONFIG_PACKAGE_libuclient=y
# CONFIG_PACKAGE_libudev-fbsd is not set
# CONFIG_PACKAGE_libudns is not set
# CONFIG_PACKAGE_libuecc is not set
# CONFIG_PACKAGE_libugpio is not set
# CONFIG_PACKAGE_libunistring is not set
# CONFIG_PACKAGE_libunwind is not set
# CONFIG_PACKAGE_libupnp is not set
# CONFIG_PACKAGE_libupnpp is not set
# CONFIG_PACKAGE_liburcu is not set
# CONFIG_PACKAGE_liburing is not set
# CONFIG_PACKAGE_libusb-1.0 is not set
# CONFIG_PACKAGE_libusb-compat is not set
# CONFIG_PACKAGE_libustream-mbedtls is not set
CONFIG_PACKAGE_libustream-openssl=y
# CONFIG_PACKAGE_libustream-wolfssl is not set
CONFIG_PACKAGE_libuuid=y
CONFIG_PACKAGE_libuv=y
# CONFIG_PACKAGE_libuwifi is not set
# CONFIG_PACKAGE_libv4l is not set
# CONFIG_PACKAGE_libvorbis is not set
# CONFIG_PACKAGE_libvorbisidec is not set
# CONFIG_PACKAGE_libvpx is not set
# CONFIG_PACKAGE_libwebcam is not set
# CONFIG_PACKAGE_libwebp is not set
CONFIG_PACKAGE_libwebsockets-full=y
# CONFIG_PACKAGE_libwebsockets-mbedtls is not set
# CONFIG_PACKAGE_libwebsockets-openssl is not set
# CONFIG_PACKAGE_libwrap is not set
# CONFIG_PACKAGE_libwslay is not set
# CONFIG_PACKAGE_libwxbase is not set
# CONFIG_PACKAGE_libxerces-c is not set
# CONFIG_PACKAGE_libxerces-c-samples is not set
CONFIG_PACKAGE_libxml2=y
# CONFIG_PACKAGE_libxslt is not set
# CONFIG_PACKAGE_libyaml-cpp is not set
# CONFIG_PACKAGE_libyang is not set
# CONFIG_PACKAGE_libyang-cpp is not set
# CONFIG_PACKAGE_libyubikey is not set
# CONFIG_PACKAGE_libzmq-curve is not set
# CONFIG_PACKAGE_libzmq-nc is not set
# CONFIG_PACKAGE_linux-atm is not set
# CONFIG_PACKAGE_lmdb is not set
# CONFIG_PACKAGE_log4cplus is not set
# CONFIG_PACKAGE_loudmouth is not set
# CONFIG_PACKAGE_lttng-ust is not set
# CONFIG_PACKAGE_measurement-kit is not set
# CONFIG_MEASUREMENT_KIT_BUILD_DEPENDS is not set
# CONFIG_PACKAGE_minizip is not set
# CONFIG_PACKAGE_mtdev is not set
# CONFIG_PACKAGE_musl-fts is not set
# CONFIG_PACKAGE_mxml is not set
# CONFIG_PACKAGE_nacl is not set
# CONFIG_PACKAGE_nlohmannjson is not set
# CONFIG_PACKAGE_nspr is not set
# CONFIG_PACKAGE_oniguruma is not set
# CONFIG_PACKAGE_open-isns is not set
# CONFIG_PACKAGE_p11-kit is not set
# CONFIG_PACKAGE_pixman is not set
# CONFIG_PACKAGE_poco is not set
# CONFIG_PACKAGE_poco-all is not set
# CONFIG_PACKAGE_protobuf is not set
# CONFIG_PACKAGE_protobuf-lite is not set
# CONFIG_PACKAGE_pthsem is not set
# CONFIG_PACKAGE_rblibtorrent is not set
# CONFIG_PACKAGE_re2 is not set
CONFIG_PACKAGE_rpcd-mod-rrdns=y
# CONFIG_PACKAGE_sbc is not set
# CONFIG_PACKAGE_serdisplib is not set
# CONFIG_PACKAGE_spice-protocol is not set
CONFIG_PACKAGE_terminfo=y
# CONFIG_PACKAGE_tinycdb is not set
# CONFIG_PACKAGE_uclibcxx is not set
# CONFIG_PACKAGE_uw-imap is not set
# CONFIG_PACKAGE_xmlrpc-c is not set
# CONFIG_PACKAGE_xmlrpc-c-client is not set
# CONFIG_PACKAGE_xmlrpc-c-server is not set
# CONFIG_PACKAGE_yajl is not set
# CONFIG_PACKAGE_yubico-pam is not set
CONFIG_PACKAGE_zlib=y
#
# Configuration
#
# CONFIG_ZLIB_OPTIMIZE_SPEED is not set
# end of Configuration
# end of Libraries
#
# LuCI
#
#
# 1. Collections
#
CONFIG_PACKAGE_luci=y
# CONFIG_PACKAGE_luci-nginx is not set
# CONFIG_PACKAGE_luci-ssl-nginx is not set
# CONFIG_PACKAGE_luci-ssl-openssl is not set
# end of 1. Collections
#
# 2. Modules
#
CONFIG_PACKAGE_luci-base=y
# CONFIG_LUCI_SRCDIET is not set
#
# Translations
#
# CONFIG_LUCI_LANG_hu is not set
# CONFIG_LUCI_LANG_pt is not set
# CONFIG_LUCI_LANG_no is not set
# CONFIG_LUCI_LANG_sk is not set
# CONFIG_LUCI_LANG_el is not set
# CONFIG_LUCI_LANG_uk is not set
# CONFIG_LUCI_LANG_ru is not set
# CONFIG_LUCI_LANG_vi is not set
# CONFIG_LUCI_LANG_de is not set
# CONFIG_LUCI_LANG_ro is not set
# CONFIG_LUCI_LANG_ms is not set
# CONFIG_LUCI_LANG_pl is not set
CONFIG_LUCI_LANG_zh-cn=y
# CONFIG_LUCI_LANG_ko is not set
# CONFIG_LUCI_LANG_he is not set
# CONFIG_LUCI_LANG_zh-tw is not set
# CONFIG_LUCI_LANG_tr is not set
# CONFIG_LUCI_LANG_sv is not set
# CONFIG_LUCI_LANG_ja is not set
# CONFIG_LUCI_LANG_pt-br is not set
# CONFIG_LUCI_LANG_ca is not set
# CONFIG_LUCI_LANG_en is not set
# CONFIG_LUCI_LANG_es is not set
# CONFIG_LUCI_LANG_cs is not set
# CONFIG_LUCI_LANG_fr is not set
# CONFIG_LUCI_LANG_it is not set
# end of Translations
CONFIG_PACKAGE_luci-compat=y
CONFIG_PACKAGE_luci-mod-admin-full=y
# CONFIG_PACKAGE_luci-mod-failsafe is not set
# CONFIG_PACKAGE_luci-mod-freifunk is not set
# CONFIG_PACKAGE_luci-mod-freifunk-community is not set
# CONFIG_PACKAGE_luci-mod-rpc is not set
# end of 2. Modules
#
# 3. Applications
#
# CONFIG_PACKAGE_luci-app-accesscontrol is not set
# CONFIG_PACKAGE_luci-app-adblock is not set
CONFIG_PACKAGE_luci-app-adbyby-plus=y
# CONFIG_PACKAGE_luci-app-adguardhome is not set
# CONFIG_PACKAGE_luci-app-advanced-reboot is not set
# CONFIG_PACKAGE_luci-app-ahcp is not set
# CONFIG_PACKAGE_luci-app-airplay2 is not set
# CONFIG_PACKAGE_luci-app-amule is not set
# CONFIG_PACKAGE_luci-app-aria2 is not set
# CONFIG_PACKAGE_luci-app-arpbind is not set
# CONFIG_PACKAGE_luci-app-asterisk is not set
# CONFIG_PACKAGE_luci-app-attendedsysupgrade is not set
CONFIG_PACKAGE_luci-app-autoreboot=y
# CONFIG_PACKAGE_luci-app-baidupcs-web is not set
# CONFIG_PACKAGE_luci-app-bcp38 is not set
# CONFIG_PACKAGE_luci-app-bird1-ipv4 is not set
# CONFIG_PACKAGE_luci-app-bird1-ipv6 is not set
# CONFIG_PACKAGE_luci-app-bmx6 is not set
# CONFIG_PACKAGE_luci-app-cifs-mount is not set
# CONFIG_PACKAGE_luci-app-cifsd is not set
# CONFIG_PACKAGE_luci-app-cjdns is not set
# CONFIG_PACKAGE_luci-app-clamav is not set
# CONFIG_PACKAGE_luci-app-commands is not set
# CONFIG_PACKAGE_luci-app-control-timewol is not set
# CONFIG_PACKAGE_luci-app-control-webrestriction is not set
# CONFIG_PACKAGE_luci-app-control-weburl is not set
# CONFIG_PACKAGE_luci-app-cshark is not set
CONFIG_PACKAGE_luci-app-ddns=y
# CONFIG_PACKAGE_luci-app-diag-core is not set
# CONFIG_PACKAGE_luci-app-diskman is not set
# CONFIG_PACKAGE_luci-app-diskman_INCLUDE_btrfs_progs is not set
# CONFIG_PACKAGE_luci-app-diskman_INCLUDE_lsblk is not set
# CONFIG_PACKAGE_luci-app-diskman_INCLUDE_mdadm is not set
# CONFIG_PACKAGE_luci-app-dnscrypt-proxy is not set
# CONFIG_PACKAGE_luci-app-dnsforwarder is not set
# CONFIG_PACKAGE_luci-app-dump1090 is not set
# CONFIG_PACKAGE_luci-app-dynapoint is not set
# CONFIG_PACKAGE_luci-app-e2guardian is not set
# CONFIG_PACKAGE_luci-app-familycloud is not set
CONFIG_PACKAGE_luci-app-fileassistant=y
CONFIG_PACKAGE_luci-app-filebrowser=y
CONFIG_PACKAGE_luci-app-filetransfer=y
CONFIG_PACKAGE_luci-app-firewall=y
CONFIG_PACKAGE_luci-app-flowoffload=y
# CONFIG_PACKAGE_luci-app-freifunk-diagnostics is not set
# CONFIG_PACKAGE_luci-app-freifunk-policyrouting is not set
# CONFIG_PACKAGE_luci-app-freifunk-widgets is not set
# CONFIG_PACKAGE_luci-app-frpc is not set
# CONFIG_PACKAGE_luci-app-frps is not set
# CONFIG_PACKAGE_luci-app-fwknopd is not set
CONFIG_PACKAGE_luci-app-guest-wifi=y
# CONFIG_PACKAGE_luci-app-haproxy-tcp is not set
# CONFIG_PACKAGE_luci-app-hd-idle is not set
# CONFIG_PACKAGE_luci-app-hnet is not set
# CONFIG_PACKAGE_luci-app-https-dns-proxy is not set
# CONFIG_PACKAGE_luci-app-ipsec-server is not set
# CONFIG_PACKAGE_luci-app-ipsec-vpnd is not set
# CONFIG_PACKAGE_luci-app-jd-dailybonus is not set
# CONFIG_PACKAGE_luci-app-kodexplorer is not set
# CONFIG_PACKAGE_luci-app-lxc is not set
# CONFIG_PACKAGE_luci-app-meshwizard is not set
# CONFIG_PACKAGE_luci-app-minidlna is not set
# CONFIG_PACKAGE_luci-app-mjpg-streamer is not set
# CONFIG_PACKAGE_luci-app-mtwifi is not set
# CONFIG_PACKAGE_luci-app-music-remote-center is not set
# CONFIG_PACKAGE_luci-app-mwan3 is not set
# CONFIG_PACKAGE_luci-app-mwan3helper is not set
# CONFIG_PACKAGE_luci-app-n2n_v2 is not set
# CONFIG_PACKAGE_luci-app-netdata is not set
# CONFIG_PACKAGE_luci-app-nfs is not set
# CONFIG_PACKAGE_luci-app-nft-qos is not set
# CONFIG_PACKAGE_luci-app-nginx-pingos is not set
# CONFIG_PACKAGE_luci-app-nlbwmon is not set
# CONFIG_PACKAGE_luci-app-noddos is not set
# CONFIG_PACKAGE_luci-app-nps is not set
# CONFIG_PACKAGE_luci-app-ntpc is not set
# CONFIG_PACKAGE_luci-app-ocserv is not set
# CONFIG_PACKAGE_luci-app-olsr is not set
# CONFIG_PACKAGE_luci-app-olsr-services is not set
# CONFIG_PACKAGE_luci-app-olsr-viz is not set
CONFIG_PACKAGE_luci-app-openclash=y
# CONFIG_PACKAGE_luci-app-openvpn is not set
# CONFIG_PACKAGE_luci-app-openvpn-server is not set
# CONFIG_PACKAGE_luci-app-p910nd is not set
# CONFIG_PACKAGE_luci-app-pagekitec is not set
CONFIG_PACKAGE_luci-app-passwall=y
#
# Configuration
#
CONFIG_PACKAGE_luci-app-passwall_INCLUDE_Shadowsocks=y
# CONFIG_PACKAGE_luci-app-passwall_INCLUDE_Shadowsocks_Server is not set
CONFIG_PACKAGE_luci-app-passwall_INCLUDE_ShadowsocksR=y
# CONFIG_PACKAGE_luci-app-passwall_INCLUDE_ShadowsocksR_Server is not set
CONFIG_PACKAGE_luci-app-passwall_INCLUDE_Xray=y
# CONFIG_PACKAGE_luci-app-passwall_INCLUDE_V2ray is not set
# CONFIG_PACKAGE_luci-app-passwall_INCLUDE_Trojan_Plus is not set
# CONFIG_PACKAGE_luci-app-passwall_INCLUDE_Trojan_GO is not set
# CONFIG_PACKAGE_luci-app-passwall_INCLUDE_Brook is not set
# CONFIG_PACKAGE_luci-app-passwall_INCLUDE_NaiveProxy is not set
# CONFIG_PACKAGE_luci-app-passwall_INCLUDE_kcptun is not set
CONFIG_PACKAGE_luci-app-passwall_INCLUDE_haproxy=y
# CONFIG_PACKAGE_luci-app-passwall_INCLUDE_ChinaDNS_NG is not set
CONFIG_PACKAGE_luci-app-passwall_INCLUDE_dns2socks=y
# CONFIG_PACKAGE_luci-app-passwall_INCLUDE_v2ray-plugin is not set
# CONFIG_PACKAGE_luci-app-passwall_INCLUDE_simple-obfs is not set
# end of Configuration
# CONFIG_PACKAGE_luci-app-polipo is not set
# CONFIG_PACKAGE_luci-app-pppoe-relay is not set
# CONFIG_PACKAGE_luci-app-pppoe-server is not set
# CONFIG_PACKAGE_luci-app-pptp-server is not set
# CONFIG_PACKAGE_luci-app-privoxy is not set
# CONFIG_PACKAGE_luci-app-ps3netsrv is not set
# CONFIG_PACKAGE_luci-app-qbittorrent is not set
# CONFIG_PACKAGE_luci-app-qos is not set
# CONFIG_PACKAGE_luci-app-radicale is not set
CONFIG_PACKAGE_luci-app-ramfree=y
# CONFIG_PACKAGE_luci-app-rclone is not set
# CONFIG_PACKAGE_luci-app-rclone_INCLUDE_rclone-webui is not set
# CONFIG_PACKAGE_luci-app-rclone_INCLUDE_rclone-ng is not set
# CONFIG_PACKAGE_luci-app-rclone_INCLUDE_fuse-utils is not set
# CONFIG_PACKAGE_luci-app-rp-pppoe-server is not set
CONFIG_PACKAGE_luci-app-samba=y
# CONFIG_PACKAGE_luci-app-samba4 is not set
# CONFIG_PACKAGE_luci-app-sfe is not set
# CONFIG_PACKAGE_luci-app-shadowsocks-libev is not set
# CONFIG_PACKAGE_luci-app-shairplay is not set
# CONFIG_PACKAGE_luci-app-siitwizard is not set
# CONFIG_PACKAGE_luci-app-simple-adblock is not set
CONFIG_PACKAGE_luci-app-smartdns=y
# CONFIG_PACKAGE_luci-app-socat is not set
# CONFIG_PACKAGE_luci-app-softethervpn is not set
# CONFIG_PACKAGE_luci-app-splash is not set
# CONFIG_PACKAGE_luci-app-sqm is not set
# CONFIG_PACKAGE_luci-app-squid is not set
# CONFIG_PACKAGE_luci-app-ssr-mudb-server is not set
CONFIG_PACKAGE_luci-app-ssr-plus=y
CONFIG_PACKAGE_luci-app-ssr-plus_INCLUDE_Xray=y
# CONFIG_PACKAGE_luci-app-ssr-plus_INCLUDE_Trojan is not set
# CONFIG_PACKAGE_luci-app-ssr-plus_INCLUDE_Redsocks2 is not set
# CONFIG_PACKAGE_luci-app-ssr-plus_INCLUDE_NaiveProxy is not set
# CONFIG_PACKAGE_luci-app-ssr-plus_INCLUDE_V2ray is not set
# CONFIG_PACKAGE_luci-app-ssr-plus_INCLUDE_Trojan-go is not set
# CONFIG_PACKAGE_luci-app-ssr-plus_INCLUDE_Kcptun is not set
# CONFIG_PACKAGE_luci-app-ssr-plus_INCLUDE_V2ray_plugin is not set
# CONFIG_PACKAGE_luci-app-ssr-plus_INCLUDE_ShadowsocksR_Server is not set
# CONFIG_PACKAGE_luci-app-ssrserver-python is not set
# CONFIG_PACKAGE_luci-app-statistics is not set
# CONFIG_PACKAGE_luci-app-syncdial is not set
# CONFIG_PACKAGE_luci-app-syncthing is not set
# CONFIG_PACKAGE_luci-app-timecontrol is not set
# CONFIG_PACKAGE_luci-app-tinyproxy is not set
# CONFIG_PACKAGE_luci-app-transmission is not set
CONFIG_PACKAGE_luci-app-travelmate=y
CONFIG_PACKAGE_luci-app-ttyd=y
# CONFIG_PACKAGE_luci-app-udpxy is not set
# CONFIG_PACKAGE_luci-app-uhttpd is not set
# CONFIG_PACKAGE_luci-app-unblockmusic is not set
# CONFIG_UnblockNeteaseMusic_Go is not set
# CONFIG_UnblockNeteaseMusic_NodeJS is not set
# CONFIG_PACKAGE_luci-app-unbound is not set
CONFIG_PACKAGE_luci-app-upnp=y
# CONFIG_PACKAGE_luci-app-usb-printer is not set
# CONFIG_PACKAGE_luci-app-uugamebooster is not set
# CONFIG_PACKAGE_luci-app-v2ray-server is not set
# CONFIG_PACKAGE_luci-app-verysync is not set
CONFIG_PACKAGE_luci-app-vlmcsd=y
# CONFIG_PACKAGE_luci-app-vnstat is not set
# CONFIG_PACKAGE_luci-app-vpnbypass is not set
CONFIG_PACKAGE_luci-app-vsftpd=y
# CONFIG_PACKAGE_luci-app-watchcat is not set
CONFIG_PACKAGE_luci-app-webadmin=y
CONFIG_PACKAGE_luci-app-wifischedule=y
# CONFIG_PACKAGE_luci-app-wireguard is not set
# CONFIG_PACKAGE_luci-app-wol is not set
# CONFIG_PACKAGE_luci-app-wrtbwmon is not set
# CONFIG_PACKAGE_luci-app-xlnetacc is not set
CONFIG_PACKAGE_luci-app-zerotier=y
# end of 3. Applications
#
# 4. Themes
#
# CONFIG_PACKAGE_luci-theme-argon is not set
CONFIG_PACKAGE_luci-theme-bootstrap=y
# CONFIG_PACKAGE_luci-theme-freifunk-generic is not set
# CONFIG_PACKAGE_luci-theme-material is not set
# CONFIG_PACKAGE_luci-theme-netgear is not set
# end of 4. Themes
#
# 5. Protocols
#
# CONFIG_PACKAGE_luci-proto-3g is not set
# CONFIG_PACKAGE_luci-proto-bonding is not set
# CONFIG_PACKAGE_luci-proto-ipip is not set
# CONFIG_PACKAGE_luci-proto-ipv6 is not set
# CONFIG_PACKAGE_luci-proto-openconnect is not set
CONFIG_PACKAGE_luci-proto-ppp=y
# CONFIG_PACKAGE_luci-proto-qmi is not set
# CONFIG_PACKAGE_luci-proto-relay is not set
# CONFIG_PACKAGE_luci-proto-vpnc is not set
# CONFIG_PACKAGE_luci-proto-wireguard is not set
# end of 5. Protocols
#
# 6. Libraries
#
# CONFIG_PACKAGE_luci-lib-docker is not set
# CONFIG_PACKAGE_luci-lib-dracula is not set
# CONFIG_PACKAGE_luci-lib-httpclient is not set
# CONFIG_PACKAGE_luci-lib-httpprotoutils is not set
CONFIG_PACKAGE_luci-lib-ip=y
# CONFIG_PACKAGE_luci-lib-iptparser is not set
# CONFIG_PACKAGE_luci-lib-jquery-1-4 is not set
# CONFIG_PACKAGE_luci-lib-json is not set
CONFIG_PACKAGE_luci-lib-jsonc=y
# CONFIG_PACKAGE_luci-lib-luaneightbl is not set
CONFIG_PACKAGE_luci-lib-nixio=y
# CONFIG_PACKAGE_luci-lib-px5g is not set
# end of 6. Libraries
#
# 9. Freifunk
#
# CONFIG_PACKAGE_freifunk-common is not set
# CONFIG_PACKAGE_freifunk-firewall is not set
# CONFIG_PACKAGE_freifunk-policyrouting is not set
# CONFIG_PACKAGE_freifunk-watchdog is not set
# CONFIG_PACKAGE_meshwizard is not set
# end of 9. Freifunk
CONFIG_PACKAGE_default-settings=y
CONFIG_PACKAGE_luci-i18n-adbyby-plus-zh-cn=y
CONFIG_PACKAGE_luci-i18n-autoreboot-zh-cn=y
# CONFIG_PACKAGE_luci-i18n-base-ca is not set
# CONFIG_PACKAGE_luci-i18n-base-cs is not set
# CONFIG_PACKAGE_luci-i18n-base-de is not set
# CONFIG_PACKAGE_luci-i18n-base-el is not set
# CONFIG_PACKAGE_luci-i18n-base-en is not set
# CONFIG_PACKAGE_luci-i18n-base-es is not set
# CONFIG_PACKAGE_luci-i18n-base-fr is not set
# CONFIG_PACKAGE_luci-i18n-base-he is not set
# CONFIG_PACKAGE_luci-i18n-base-hu is not set
# CONFIG_PACKAGE_luci-i18n-base-it is not set
# CONFIG_PACKAGE_luci-i18n-base-ja is not set
# CONFIG_PACKAGE_luci-i18n-base-ko is not set
# CONFIG_PACKAGE_luci-i18n-base-ms is not set
# CONFIG_PACKAGE_luci-i18n-base-no is not set
# CONFIG_PACKAGE_luci-i18n-base-pl is not set
# CONFIG_PACKAGE_luci-i18n-base-pt is not set
# CONFIG_PACKAGE_luci-i18n-base-pt-br is not set
# CONFIG_PACKAGE_luci-i18n-base-ro is not set
# CONFIG_PACKAGE_luci-i18n-base-ru is not set
# CONFIG_PACKAGE_luci-i18n-base-sk is not set
# CONFIG_PACKAGE_luci-i18n-base-sv is not set
# CONFIG_PACKAGE_luci-i18n-base-tr is not set
# CONFIG_PACKAGE_luci-i18n-base-uk is not set
# CONFIG_PACKAGE_luci-i18n-base-vi is not set
CONFIG_PACKAGE_luci-i18n-base-zh-cn=y
# CONFIG_PACKAGE_luci-i18n-base-zh-tw is not set
# CONFIG_PACKAGE_luci-i18n-ddns-bg is not set
# CONFIG_PACKAGE_luci-i18n-ddns-ca is not set
# CONFIG_PACKAGE_luci-i18n-ddns-cs is not set
# CONFIG_PACKAGE_luci-i18n-ddns-de is not set
# CONFIG_PACKAGE_luci-i18n-ddns-el is not set
# CONFIG_PACKAGE_luci-i18n-ddns-en is not set
# CONFIG_PACKAGE_luci-i18n-ddns-es is not set
# CONFIG_PACKAGE_luci-i18n-ddns-fr is not set
# CONFIG_PACKAGE_luci-i18n-ddns-he is not set
# CONFIG_PACKAGE_luci-i18n-ddns-hi is not set
# CONFIG_PACKAGE_luci-i18n-ddns-hu is not set
# CONFIG_PACKAGE_luci-i18n-ddns-it is not set
# CONFIG_PACKAGE_luci-i18n-ddns-ja is not set
# CONFIG_PACKAGE_luci-i18n-ddns-ko is not set
# CONFIG_PACKAGE_luci-i18n-ddns-mr is not set
# CONFIG_PACKAGE_luci-i18n-ddns-ms is not set
# CONFIG_PACKAGE_luci-i18n-ddns-no is not set
# CONFIG_PACKAGE_luci-i18n-ddns-pl is not set
# CONFIG_PACKAGE_luci-i18n-ddns-pt is not set
# CONFIG_PACKAGE_luci-i18n-ddns-pt-br is not set
# CONFIG_PACKAGE_luci-i18n-ddns-ro is not set
# CONFIG_PACKAGE_luci-i18n-ddns-ru is not set
# CONFIG_PACKAGE_luci-i18n-ddns-sk is not set
# CONFIG_PACKAGE_luci-i18n-ddns-sv is not set
# CONFIG_PACKAGE_luci-i18n-ddns-tr is not set
# CONFIG_PACKAGE_luci-i18n-ddns-uk is not set
# CONFIG_PACKAGE_luci-i18n-ddns-vi is not set
CONFIG_PACKAGE_luci-i18n-ddns-zh-cn=y
# CONFIG_PACKAGE_luci-i18n-ddns-zh-tw is not set
CONFIG_PACKAGE_luci-i18n-filebrowser-zh-cn=y
CONFIG_PACKAGE_luci-i18n-filetransfer-zh-cn=y
# CONFIG_PACKAGE_luci-i18n-firewall-ca is not set
# CONFIG_PACKAGE_luci-i18n-firewall-cs is not set
# CONFIG_PACKAGE_luci-i18n-firewall-de is not set
# CONFIG_PACKAGE_luci-i18n-firewall-el is not set
# CONFIG_PACKAGE_luci-i18n-firewall-en is not set
# CONFIG_PACKAGE_luci-i18n-firewall-es is not set
# CONFIG_PACKAGE_luci-i18n-firewall-fr is not set
# CONFIG_PACKAGE_luci-i18n-firewall-he is not set
# CONFIG_PACKAGE_luci-i18n-firewall-hu is not set
# CONFIG_PACKAGE_luci-i18n-firewall-it is not set
# CONFIG_PACKAGE_luci-i18n-firewall-ja is not set
# CONFIG_PACKAGE_luci-i18n-firewall-ko is not set
# CONFIG_PACKAGE_luci-i18n-firewall-ms is not set
# CONFIG_PACKAGE_luci-i18n-firewall-no is not set
# CONFIG_PACKAGE_luci-i18n-firewall-pl is not set
# CONFIG_PACKAGE_luci-i18n-firewall-pt is not set
# CONFIG_PACKAGE_luci-i18n-firewall-pt-br is not set
# CONFIG_PACKAGE_luci-i18n-firewall-ro is not set
# CONFIG_PACKAGE_luci-i18n-firewall-ru is not set
# CONFIG_PACKAGE_luci-i18n-firewall-sk is not set
# CONFIG_PACKAGE_luci-i18n-firewall-sv is not set
# CONFIG_PACKAGE_luci-i18n-firewall-tr is not set
# CONFIG_PACKAGE_luci-i18n-firewall-uk is not set
# CONFIG_PACKAGE_luci-i18n-firewall-vi is not set
CONFIG_PACKAGE_luci-i18n-firewall-zh-cn=y
# CONFIG_PACKAGE_luci-i18n-firewall-zh-tw is not set
CONFIG_PACKAGE_luci-i18n-flowoffload-zh-cn=y
CONFIG_PACKAGE_luci-i18n-guest-wifi-zh-cn=y
CONFIG_PACKAGE_luci-i18n-ramfree-zh-cn=y
# CONFIG_PACKAGE_luci-i18n-samba-ca is not set
# CONFIG_PACKAGE_luci-i18n-samba-cs is not set
# CONFIG_PACKAGE_luci-i18n-samba-de is not set
# CONFIG_PACKAGE_luci-i18n-samba-el is not set
# CONFIG_PACKAGE_luci-i18n-samba-en is not set
# CONFIG_PACKAGE_luci-i18n-samba-es is not set
# CONFIG_PACKAGE_luci-i18n-samba-fr is not set
# CONFIG_PACKAGE_luci-i18n-samba-he is not set
# CONFIG_PACKAGE_luci-i18n-samba-hu is not set
# CONFIG_PACKAGE_luci-i18n-samba-it is not set
# CONFIG_PACKAGE_luci-i18n-samba-ja is not set
# CONFIG_PACKAGE_luci-i18n-samba-ms is not set
# CONFIG_PACKAGE_luci-i18n-samba-no is not set
# CONFIG_PACKAGE_luci-i18n-samba-pl is not set
# CONFIG_PACKAGE_luci-i18n-samba-pt is not set
# CONFIG_PACKAGE_luci-i18n-samba-pt-br is not set
# CONFIG_PACKAGE_luci-i18n-samba-ro is not set
# CONFIG_PACKAGE_luci-i18n-samba-ru is not set
# CONFIG_PACKAGE_luci-i18n-samba-sk is not set
# CONFIG_PACKAGE_luci-i18n-samba-sv is not set
# CONFIG_PACKAGE_luci-i18n-samba-tr is not set
# CONFIG_PACKAGE_luci-i18n-samba-uk is not set
# CONFIG_PACKAGE_luci-i18n-samba-vi is not set
CONFIG_PACKAGE_luci-i18n-samba-zh-cn=y
# CONFIG_PACKAGE_luci-i18n-samba-zh-tw is not set
CONFIG_PACKAGE_luci-i18n-smartdns-zh-cn=y
CONFIG_PACKAGE_luci-i18n-ssr-plus-zh-cn=y
# CONFIG_PACKAGE_luci-i18n-ssr-plus-zh_Hans is not set
# CONFIG_PACKAGE_luci-i18n-travelmate-ja is not set
# CONFIG_PACKAGE_luci-i18n-travelmate-pt-br is not set
# CONFIG_PACKAGE_luci-i18n-travelmate-ru is not set
CONFIG_PACKAGE_luci-i18n-ttyd-zh-cn=y
# CONFIG_PACKAGE_luci-i18n-upnp-ca is not set
# CONFIG_PACKAGE_luci-i18n-upnp-cs is not set
# CONFIG_PACKAGE_luci-i18n-upnp-de is not set
# CONFIG_PACKAGE_luci-i18n-upnp-el is not set
# CONFIG_PACKAGE_luci-i18n-upnp-en is not set
# CONFIG_PACKAGE_luci-i18n-upnp-es is not set
# CONFIG_PACKAGE_luci-i18n-upnp-fr is not set
# CONFIG_PACKAGE_luci-i18n-upnp-he is not set
# CONFIG_PACKAGE_luci-i18n-upnp-hu is not set
# CONFIG_PACKAGE_luci-i18n-upnp-it is not set
# CONFIG_PACKAGE_luci-i18n-upnp-ja is not set
# CONFIG_PACKAGE_luci-i18n-upnp-ms is not set
# CONFIG_PACKAGE_luci-i18n-upnp-no is not set
# CONFIG_PACKAGE_luci-i18n-upnp-pl is not set
# CONFIG_PACKAGE_luci-i18n-upnp-pt is not set
# CONFIG_PACKAGE_luci-i18n-upnp-pt-br is not set
# CONFIG_PACKAGE_luci-i18n-upnp-ro is not set
# CONFIG_PACKAGE_luci-i18n-upnp-ru is not set
# CONFIG_PACKAGE_luci-i18n-upnp-sk is not set
# CONFIG_PACKAGE_luci-i18n-upnp-sv is not set
# CONFIG_PACKAGE_luci-i18n-upnp-tr is not set
# CONFIG_PACKAGE_luci-i18n-upnp-uk is not set
# CONFIG_PACKAGE_luci-i18n-upnp-vi is not set
CONFIG_PACKAGE_luci-i18n-upnp-zh-cn=y
# CONFIG_PACKAGE_luci-i18n-upnp-zh-tw is not set
CONFIG_PACKAGE_luci-i18n-vlmcsd-zh-cn=y
CONFIG_PACKAGE_luci-i18n-vsftpd-zh-cn=y
CONFIG_PACKAGE_luci-i18n-webadmin-zh-cn=y
# CONFIG_PACKAGE_luci-i18n-wifischedule-it is not set
# CONFIG_PACKAGE_luci-i18n-wifischedule-ja is not set
# CONFIG_PACKAGE_luci-i18n-wifischedule-pt-br is not set
# CONFIG_PACKAGE_luci-i18n-wifischedule-ru is not set
# CONFIG_PACKAGE_luci-i18n-wifischedule-sv is not set
CONFIG_PACKAGE_luci-i18n-wifischedule-zh-cn=y
CONFIG_PACKAGE_luci-i18n-zerotier-zh-cn=y
# end of LuCI
#
# Mail
#
# CONFIG_PACKAGE_alpine is not set
# CONFIG_PACKAGE_alpine-nossl is not set
# CONFIG_PACKAGE_bogofilter is not set
# CONFIG_PACKAGE_clamsmtp is not set
# CONFIG_PACKAGE_dovecot is not set
# CONFIG_PACKAGE_dovecot-pigeonhole is not set
# CONFIG_PACKAGE_dovecot-utils is not set
# CONFIG_PACKAGE_emailrelay is not set
# CONFIG_PACKAGE_fdm is not set
# CONFIG_PACKAGE_greyfix is not set
# CONFIG_PACKAGE_mailsend is not set
# CONFIG_PACKAGE_mailsend-nossl is not set
# CONFIG_PACKAGE_msmtp is not set
# CONFIG_PACKAGE_msmtp-mta is not set
# CONFIG_PACKAGE_msmtp-nossl is not set
# CONFIG_PACKAGE_msmtp-queue is not set
# CONFIG_PACKAGE_mutt is not set
# CONFIG_PACKAGE_nail is not set
# CONFIG_PACKAGE_opendkim is not set
# CONFIG_PACKAGE_opendkim-tools is not set
# CONFIG_PACKAGE_postfix is not set
#
# Select postfix build options
#
CONFIG_POSTFIX_TLS=y
CONFIG_POSTFIX_SASL=y
CONFIG_POSTFIX_LDAP=y
# CONFIG_POSTFIX_DB is not set
CONFIG_POSTFIX_CDB=y
CONFIG_POSTFIX_SQLITE=y
# CONFIG_POSTFIX_MYSQL is not set
# CONFIG_POSTFIX_PGSQL is not set
CONFIG_POSTFIX_PCRE=y
# CONFIG_POSTFIX_EAI is not set
# end of Select postfix build options
# CONFIG_PACKAGE_ssmtp is not set
# end of Mail
#
# Multimedia
#
#
# Streaming
#
# CONFIG_PACKAGE_oggfwd is not set
# end of Streaming
# CONFIG_PACKAGE_ffmpeg is not set
# CONFIG_PACKAGE_ffprobe is not set
# CONFIG_PACKAGE_fswebcam is not set
# CONFIG_PACKAGE_gerbera is not set
# CONFIG_PACKAGE_gmediarender is not set
# CONFIG_PACKAGE_gphoto2 is not set
# CONFIG_PACKAGE_graphicsmagick is not set
# CONFIG_PACKAGE_grilo is not set
# CONFIG_PACKAGE_grilo-plugins is not set
# CONFIG_PACKAGE_gst1-libav is not set
# CONFIG_PACKAGE_gstreamer1-libs is not set
# CONFIG_PACKAGE_gstreamer1-plugins-bad is not set
# CONFIG_PACKAGE_gstreamer1-plugins-base is not set
# CONFIG_PACKAGE_gstreamer1-plugins-good is not set
# CONFIG_PACKAGE_gstreamer1-plugins-ugly is not set
# CONFIG_PACKAGE_gstreamer1-utils is not set
# CONFIG_PACKAGE_icecast is not set
# CONFIG_PACKAGE_imagemagick is not set
# CONFIG_PACKAGE_lcdgrilo is not set
# CONFIG_PACKAGE_minidlna is not set
# CONFIG_PACKAGE_minisatip is not set
# CONFIG_PACKAGE_mjpg-streamer is not set
# CONFIG_PACKAGE_motion is not set
# CONFIG_PACKAGE_tvheadend is not set
# CONFIG_PACKAGE_v4l2rtspserver is not set
# CONFIG_PACKAGE_vips is not set
# CONFIG_PACKAGE_xupnpd is not set
# CONFIG_PACKAGE_youtube-dl is not set
# end of Multimedia
#
# Network
#
#
# BitTorrent
#
# CONFIG_PACKAGE_mktorrent is not set
# CONFIG_PACKAGE_opentracker is not set
# CONFIG_PACKAGE_opentracker6 is not set
# CONFIG_PACKAGE_qBittorrent is not set
# CONFIG_PACKAGE_rtorrent is not set
# CONFIG_PACKAGE_rtorrent-rpc is not set
# CONFIG_PACKAGE_transmission-cli-openssl is not set
# CONFIG_PACKAGE_transmission-daemon-openssl is not set
# CONFIG_PACKAGE_transmission-remote-openssl is not set
# CONFIG_PACKAGE_transmission-web is not set
# CONFIG_PACKAGE_transmission-web-control is not set
# end of BitTorrent
#
# Captive Portals
#
# CONFIG_PACKAGE_apfree-wifidog is not set
# CONFIG_PACKAGE_coova-chilli is not set
# CONFIG_PACKAGE_nodogsplash is not set
# CONFIG_PACKAGE_opennds is not set
# CONFIG_PACKAGE_wifidog is not set
# CONFIG_PACKAGE_wifidog-tls is not set
# end of Captive Portals
#
# Cloud Manager
#
# CONFIG_PACKAGE_rclone-ng is not set
# CONFIG_PACKAGE_rclone-webui-react is not set
# end of Cloud Manager
#
# Dial-in/up
#
# CONFIG_PACKAGE_rp-pppoe-common is not set
# CONFIG_PACKAGE_rp-pppoe-relay is not set
# CONFIG_PACKAGE_rp-pppoe-server is not set
# end of Dial-in/up
#
# Download Manager
#
# CONFIG_PACKAGE_ariang is not set
# CONFIG_PACKAGE_ariang-nginx is not set
# CONFIG_PACKAGE_leech is not set
# CONFIG_PACKAGE_webui-aria2 is not set
# end of Download Manager
#
# File Transfer
#
# CONFIG_PACKAGE_aria2 is not set
# CONFIG_PACKAGE_atftp is not set
# CONFIG_PACKAGE_atftpd is not set
CONFIG_PACKAGE_curl=y
# CONFIG_PACKAGE_gnurl is not set
# CONFIG_PACKAGE_lftp is not set
# CONFIG_PACKAGE_ps3netsrv is not set
# CONFIG_PACKAGE_rosy-file-server is not set
# CONFIG_PACKAGE_rsync is not set
# CONFIG_PACKAGE_rsyncd is not set
# CONFIG_PACKAGE_vsftpd is not set
CONFIG_PACKAGE_vsftpd-alt=y
CONFIG_VSFTPD_USE_UCI_SCRIPTS=y
# CONFIG_PACKAGE_vsftpd-tls is not set
CONFIG_PACKAGE_wget=y
# CONFIG_PACKAGE_wget-nossl is not set
# end of File Transfer
#
# Filesystem
#
# CONFIG_PACKAGE_davfs2 is not set
# CONFIG_PACKAGE_ksmbd-avahi-service is not set
# CONFIG_PACKAGE_ksmbd-server is not set
# CONFIG_PACKAGE_ksmbd-utils is not set
# CONFIG_PACKAGE_netatalk is not set
# CONFIG_PACKAGE_nfs-kernel-server is not set
# CONFIG_PACKAGE_owftpd is not set
# CONFIG_PACKAGE_owhttpd is not set
# CONFIG_PACKAGE_owserver is not set
# CONFIG_PACKAGE_sshfs is not set
# end of Filesystem
#
# Firewall
#
# CONFIG_PACKAGE_arptables is not set
# CONFIG_PACKAGE_conntrack is not set
# CONFIG_PACKAGE_conntrackd is not set
# CONFIG_PACKAGE_ebtables is not set
# CONFIG_PACKAGE_fwknop is not set
# CONFIG_PACKAGE_fwknopd is not set
# CONFIG_PACKAGE_ip6tables is not set
CONFIG_PACKAGE_iptables=y
# CONFIG_IPTABLES_CONNLABEL is not set
# CONFIG_IPTABLES_NFTABLES is not set
# CONFIG_PACKAGE_iptables-mod-account is not set
# CONFIG_PACKAGE_iptables-mod-chaos is not set
# CONFIG_PACKAGE_iptables-mod-checksum is not set
# CONFIG_PACKAGE_iptables-mod-cluster is not set
# CONFIG_PACKAGE_iptables-mod-clusterip is not set
# CONFIG_PACKAGE_iptables-mod-condition is not set
# CONFIG_PACKAGE_iptables-mod-conntrack-extra is not set
# CONFIG_PACKAGE_iptables-mod-delude is not set
# CONFIG_PACKAGE_iptables-mod-dhcpmac is not set
# CONFIG_PACKAGE_iptables-mod-dnetmap is not set
CONFIG_PACKAGE_iptables-mod-extra=y
# CONFIG_PACKAGE_iptables-mod-filter is not set
CONFIG_PACKAGE_iptables-mod-fullconenat=y
# CONFIG_PACKAGE_iptables-mod-fuzzy is not set
# CONFIG_PACKAGE_iptables-mod-geoip is not set
# CONFIG_PACKAGE_iptables-mod-hashlimit is not set
# CONFIG_PACKAGE_iptables-mod-iface is not set
# CONFIG_PACKAGE_iptables-mod-ipmark is not set
# CONFIG_PACKAGE_iptables-mod-ipopt is not set
# CONFIG_PACKAGE_iptables-mod-ipp2p is not set
# CONFIG_PACKAGE_iptables-mod-iprange is not set
# CONFIG_PACKAGE_iptables-mod-ipsec is not set
# CONFIG_PACKAGE_iptables-mod-ipv4options is not set
# CONFIG_PACKAGE_iptables-mod-led is not set
# CONFIG_PACKAGE_iptables-mod-length2 is not set
# CONFIG_PACKAGE_iptables-mod-logmark is not set
# CONFIG_PACKAGE_iptables-mod-lscan is not set
# CONFIG_PACKAGE_iptables-mod-lua is not set
# CONFIG_PACKAGE_iptables-mod-nat-extra is not set
# CONFIG_PACKAGE_iptables-mod-nflog is not set
# CONFIG_PACKAGE_iptables-mod-nfqueue is not set
# CONFIG_PACKAGE_iptables-mod-physdev is not set
# CONFIG_PACKAGE_iptables-mod-proto is not set
# CONFIG_PACKAGE_iptables-mod-psd is not set
# CONFIG_PACKAGE_iptables-mod-quota2 is not set
# CONFIG_PACKAGE_iptables-mod-rpfilter is not set
# CONFIG_PACKAGE_iptables-mod-rtpengine is not set
# CONFIG_PACKAGE_iptables-mod-sysrq is not set
# CONFIG_PACKAGE_iptables-mod-tarpit is not set
# CONFIG_PACKAGE_iptables-mod-tee is not set
CONFIG_PACKAGE_iptables-mod-tproxy=y
# CONFIG_PACKAGE_iptables-mod-trace is not set
# CONFIG_PACKAGE_iptables-mod-u32 is not set
# CONFIG_PACKAGE_iptables-mod-ulog is not set
# CONFIG_PACKAGE_iptaccount is not set
# CONFIG_PACKAGE_iptgeoip is not set
# CONFIG_PACKAGE_miniupnpc is not set
CONFIG_PACKAGE_miniupnpd=y
# CONFIG_MINIUPNPD_IGDv2 is not set
# CONFIG_PACKAGE_natpmpc is not set
# CONFIG_PACKAGE_nftables-json is not set
# CONFIG_PACKAGE_nftables-nojson is not set
# CONFIG_PACKAGE_shorewall is not set
# CONFIG_PACKAGE_shorewall-core is not set
# CONFIG_PACKAGE_shorewall-lite is not set
# CONFIG_PACKAGE_shorewall6 is not set
# CONFIG_PACKAGE_shorewall6-lite is not set
# CONFIG_PACKAGE_snort is not set
# CONFIG_PACKAGE_snort3 is not set
# end of Firewall
#
# Firewall Tunnel
#
# CONFIG_PACKAGE_iodine is not set
# CONFIG_PACKAGE_iodined is not set
# end of Firewall Tunnel
#
# FreeRADIUS (version 3)
#
# CONFIG_PACKAGE_freeradius3 is not set
# CONFIG_PACKAGE_freeradius3-common is not set
# CONFIG_PACKAGE_freeradius3-utils is not set
# end of FreeRADIUS (version 3)
#
# IP Addresses and Names
#
# CONFIG_PACKAGE_aggregate is not set
# CONFIG_PACKAGE_announce is not set
# CONFIG_PACKAGE_avahi-autoipd is not set
# CONFIG_PACKAGE_avahi-daemon-service-http is not set
# CONFIG_PACKAGE_avahi-daemon-service-ssh is not set
# CONFIG_PACKAGE_avahi-dbus-daemon is not set
# CONFIG_PACKAGE_avahi-dnsconfd is not set
# CONFIG_PACKAGE_avahi-nodbus-daemon is not set
# CONFIG_PACKAGE_avahi-utils is not set
# CONFIG_PACKAGE_bind-check is not set
# CONFIG_PACKAGE_bind-client is not set
# CONFIG_PACKAGE_bind-dig is not set
# CONFIG_PACKAGE_bind-dnssec is not set
# CONFIG_PACKAGE_bind-host is not set
# CONFIG_PACKAGE_bind-nslookup is not set
# CONFIG_PACKAGE_bind-rndc is not set
# CONFIG_PACKAGE_bind-server is not set
# CONFIG_PACKAGE_bind-tools is not set
CONFIG_PACKAGE_ddns-scripts=y
CONFIG_PACKAGE_ddns-scripts_aliyun=y
# CONFIG_PACKAGE_ddns-scripts_cloudflare.com-v4 is not set
CONFIG_PACKAGE_ddns-scripts_dnspod=y
# CONFIG_PACKAGE_ddns-scripts_freedns_42_pl is not set
# CONFIG_PACKAGE_ddns-scripts_godaddy.com-v1 is not set
# CONFIG_PACKAGE_ddns-scripts_no-ip_com is not set
# CONFIG_PACKAGE_ddns-scripts_nsupdate is not set
# CONFIG_PACKAGE_ddns-scripts_route53-v1 is not set
# CONFIG_PACKAGE_dhcp-forwarder is not set
CONFIG_PACKAGE_dns2socks=y
# CONFIG_PACKAGE_dnscrypt-proxy is not set
# CONFIG_PACKAGE_dnscrypt-proxy-resolvers is not set
# CONFIG_PACKAGE_dnsdist is not set
# CONFIG_PACKAGE_drill is not set
# CONFIG_PACKAGE_hostip is not set
# CONFIG_PACKAGE_idn is not set
# CONFIG_PACKAGE_idn2 is not set
# CONFIG_PACKAGE_inadyn is not set
# CONFIG_PACKAGE_isc-dhcp-client-ipv4 is not set
# CONFIG_PACKAGE_isc-dhcp-client-ipv6 is not set
# CONFIG_PACKAGE_isc-dhcp-omshell-ipv4 is not set
# CONFIG_PACKAGE_isc-dhcp-omshell-ipv6 is not set
# CONFIG_PACKAGE_isc-dhcp-relay-ipv4 is not set
# CONFIG_PACKAGE_isc-dhcp-relay-ipv6 is not set
# CONFIG_PACKAGE_isc-dhcp-server-ipv4 is not set
# CONFIG_PACKAGE_isc-dhcp-server-ipv6 is not set
# CONFIG_PACKAGE_kadnode is not set
# CONFIG_PACKAGE_kea-admin is not set
# CONFIG_PACKAGE_kea-ctrl is not set
# CONFIG_PACKAGE_kea-dhcp-ddns is not set
# CONFIG_PACKAGE_kea-dhcp4 is not set
# CONFIG_PACKAGE_kea-dhcp6 is not set
# CONFIG_PACKAGE_kea-lfc is not set
# CONFIG_PACKAGE_kea-libs is not set
# CONFIG_PACKAGE_kea-perfdhcp is not set
# CONFIG_PACKAGE_knot is not set
# CONFIG_PACKAGE_knot-dig is not set
# CONFIG_PACKAGE_knot-host is not set
# CONFIG_PACKAGE_knot-keymgr is not set
# CONFIG_PACKAGE_knot-nsupdate is not set
# CONFIG_PACKAGE_knot-tests is not set
# CONFIG_PACKAGE_knot-zonecheck is not set
# CONFIG_PACKAGE_ldns-examples is not set
# CONFIG_PACKAGE_mdns-utils is not set
# CONFIG_PACKAGE_mdnsd is not set
# CONFIG_PACKAGE_mdnsresponder is not set
# CONFIG_PACKAGE_nsd is not set
# CONFIG_PACKAGE_nsd-control is not set
# CONFIG_PACKAGE_nsd-control-setup is not set
# CONFIG_PACKAGE_nsd-nossl is not set
# CONFIG_PACKAGE_ohybridproxy is not set
# CONFIG_PACKAGE_overture is not set
# CONFIG_PACKAGE_pdns is not set
# CONFIG_PACKAGE_pdns-ixfrdist is not set
# CONFIG_PACKAGE_pdns-recursor is not set
# CONFIG_PACKAGE_pdns-tools is not set
# CONFIG_PACKAGE_stubby is not set
# CONFIG_PACKAGE_tor-hs is not set
# CONFIG_PACKAGE_torsocks is not set
# CONFIG_PACKAGE_unbound-anchor is not set
# CONFIG_PACKAGE_unbound-checkconf is not set
# CONFIG_PACKAGE_unbound-control is not set
# CONFIG_PACKAGE_unbound-control-setup is not set
# CONFIG_PACKAGE_unbound-daemon is not set
# CONFIG_PACKAGE_unbound-host is not set
# CONFIG_PACKAGE_wsdd2 is not set
# CONFIG_PACKAGE_zonestitcher is not set
# end of IP Addresses and Names
#
# Instant Messaging
#
# CONFIG_PACKAGE_bitlbee is not set
# CONFIG_PACKAGE_irssi is not set
# CONFIG_PACKAGE_ngircd is not set
# CONFIG_PACKAGE_ngircd-nossl is not set
# CONFIG_PACKAGE_prosody is not set
# CONFIG_PACKAGE_quassel-irssi is not set
# CONFIG_PACKAGE_umurmur-mbedtls is not set
# CONFIG_PACKAGE_umurmur-openssl is not set
# CONFIG_PACKAGE_znc is not set
# end of Instant Messaging
#
# Linux ATM tools
#
# CONFIG_PACKAGE_atm-aread is not set
# CONFIG_PACKAGE_atm-atmaddr is not set
# CONFIG_PACKAGE_atm-atmdiag is not set
# CONFIG_PACKAGE_atm-atmdump is not set
# CONFIG_PACKAGE_atm-atmloop is not set
# CONFIG_PACKAGE_atm-atmsigd is not set
# CONFIG_PACKAGE_atm-atmswitch is not set
# CONFIG_PACKAGE_atm-atmtcp is not set
# CONFIG_PACKAGE_atm-awrite is not set
# CONFIG_PACKAGE_atm-bus is not set
# CONFIG_PACKAGE_atm-debug-tools is not set
# CONFIG_PACKAGE_atm-diagnostics is not set
# CONFIG_PACKAGE_atm-esi is not set
# CONFIG_PACKAGE_atm-ilmid is not set
# CONFIG_PACKAGE_atm-ilmidiag is not set
# CONFIG_PACKAGE_atm-lecs is not set
# CONFIG_PACKAGE_atm-les is not set
# CONFIG_PACKAGE_atm-mpcd is not set
# CONFIG_PACKAGE_atm-saaldump is not set
# CONFIG_PACKAGE_atm-sonetdiag is not set
# CONFIG_PACKAGE_atm-svc_recv is not set
# CONFIG_PACKAGE_atm-svc_send is not set
# CONFIG_PACKAGE_atm-tools is not set
# CONFIG_PACKAGE_atm-ttcp_atm is not set
# CONFIG_PACKAGE_atm-zeppelin is not set
# CONFIG_PACKAGE_br2684ctl is not set
# end of Linux ATM tools
#
# LoRaWAN
#
# CONFIG_PACKAGE_libloragw-tests is not set
# CONFIG_PACKAGE_libloragw-utils is not set
# end of LoRaWAN
#
# NMAP Suite
#
# CONFIG_PACKAGE_ncat is not set
# CONFIG_PACKAGE_ncat-full is not set
# CONFIG_PACKAGE_ncat-ssl is not set
# CONFIG_PACKAGE_ndiff is not set
# CONFIG_PACKAGE_nmap is not set
# CONFIG_PACKAGE_nmap-full is not set
# CONFIG_PACKAGE_nmap-ssl is not set
# CONFIG_PACKAGE_nping is not set
# CONFIG_PACKAGE_nping-ssl is not set
# end of NMAP Suite
#
# NTRIP
#
# CONFIG_PACKAGE_ntripcaster is not set
# CONFIG_PACKAGE_ntripclient is not set
# CONFIG_PACKAGE_ntripserver is not set
# end of NTRIP
#
# NeteaseMusic
#
# CONFIG_PACKAGE_UnblockNeteaseMusic is not set
# CONFIG_PACKAGE_UnblockNeteaseMusicGo is not set
CONFIG_UnblockNeteaseMusicGo_INCLUDE_GOPROXY=y
# end of NeteaseMusic
#
# OLSR.org network framework
#
# CONFIG_PACKAGE_oonf-dlep-proxy is not set
# CONFIG_PACKAGE_oonf-dlep-radio is not set
# CONFIG_PACKAGE_oonf-init-scripts is not set
# CONFIG_PACKAGE_oonf-olsrd2 is not set
# end of OLSR.org network framework
#
# Open vSwitch
#
# CONFIG_PACKAGE_openvswitch is not set
# CONFIG_PACKAGE_openvswitch-ovn-host is not set
# CONFIG_PACKAGE_openvswitch-ovn-north is not set
# CONFIG_PACKAGE_openvswitch-python3 is not set
# end of Open vSwitch
#
# OpenLDAP
#
# CONFIG_PACKAGE_libopenldap is not set
CONFIG_OPENLDAP_DEBUG=y
# CONFIG_OPENLDAP_CRYPT is not set
# CONFIG_OPENLDAP_MONITOR is not set
# CONFIG_OPENLDAP_DB47 is not set
# CONFIG_OPENLDAP_ICU is not set
# CONFIG_PACKAGE_openldap-server is not set
# CONFIG_PACKAGE_openldap-utils is not set
# end of OpenLDAP
#
# P2P
#
# CONFIG_PACKAGE_amule is not set
# CONFIG_AMULE_CRYPTOPP_STATIC_LINKING is not set
# CONFIG_PACKAGE_antileech is not set
# end of P2P
#
# Printing
#
# CONFIG_PACKAGE_p910nd is not set
# end of Printing
#
# Project V
#
# CONFIG_PACKAGE_v2ray is not set
# CONFIG_PACKAGE_v2ray-plugin is not set
CONFIG_v2ray-plugin_INCLUDE_GOPROXY=y
# end of Project V
#
# Project X
#
CONFIG_PACKAGE_xray=y
#
# Xray Configuration
#
# CONFIG_XRAY_COMPRESS_GOPROXY is not set
CONFIG_XRAY_EXCLUDE_ASSETS=y
CONFIG_XRAY_COMPRESS_UPX=y
# CONFIG_XRAY_COMPATIBILITY_MODE is not set
# end of Xray Configuration
# end of Project X
#
# Routing and Redirection
#
# CONFIG_PACKAGE_babel-pinger is not set
# CONFIG_PACKAGE_babeld is not set
# CONFIG_PACKAGE_batmand is not set
# CONFIG_PACKAGE_bcp38 is not set
# CONFIG_PACKAGE_bfdd is not set
# CONFIG_PACKAGE_bird1-ipv4 is not set
# CONFIG_PACKAGE_bird1-ipv4-uci is not set
# CONFIG_PACKAGE_bird1-ipv6 is not set
# CONFIG_PACKAGE_bird1-ipv6-uci is not set
# CONFIG_PACKAGE_bird1c-ipv4 is not set
# CONFIG_PACKAGE_bird1c-ipv6 is not set
# CONFIG_PACKAGE_bird1cl-ipv4 is not set
# CONFIG_PACKAGE_bird1cl-ipv6 is not set
# CONFIG_PACKAGE_bird2 is not set
# CONFIG_PACKAGE_bird2c is not set
# CONFIG_PACKAGE_bird2cl is not set
# CONFIG_PACKAGE_bmx6 is not set
# CONFIG_PACKAGE_bmx7 is not set
# CONFIG_PACKAGE_cjdns is not set
# CONFIG_PACKAGE_cjdns-tests is not set
# CONFIG_PACKAGE_dcstad is not set
# CONFIG_PACKAGE_dcwapd is not set
# CONFIG_PACKAGE_devlink is not set
# CONFIG_PACKAGE_frr is not set
# CONFIG_PACKAGE_genl is not set
# CONFIG_PACKAGE_igmpproxy is not set
# CONFIG_PACKAGE_ip-bridge is not set
CONFIG_PACKAGE_ip-full=y
# CONFIG_PACKAGE_ip-tiny is not set
# CONFIG_PACKAGE_lldpd is not set
# CONFIG_PACKAGE_mcproxy is not set
# CONFIG_PACKAGE_mrmctl is not set
# CONFIG_PACKAGE_mwan3 is not set
# CONFIG_PACKAGE_nstat is not set
# CONFIG_PACKAGE_olsrd is not set
# CONFIG_PACKAGE_prince is not set
# CONFIG_PACKAGE_quagga is not set
# CONFIG_PACKAGE_rdma is not set
# CONFIG_PACKAGE_relayd is not set
# CONFIG_PACKAGE_smcroute is not set
# CONFIG_PACKAGE_ss is not set
# CONFIG_PACKAGE_sslh is not set
# CONFIG_PACKAGE_tc is not set
# CONFIG_PACKAGE_tcpproxy is not set
# CONFIG_PACKAGE_vis is not set
# CONFIG_PACKAGE_yggdrasil is not set
# end of Routing and Redirection
#
# SSH
#
# CONFIG_PACKAGE_autossh is not set
# CONFIG_PACKAGE_openssh-client is not set
# CONFIG_PACKAGE_openssh-client-utils is not set
# CONFIG_PACKAGE_openssh-keygen is not set
# CONFIG_PACKAGE_openssh-moduli is not set
# CONFIG_PACKAGE_openssh-server is not set
# CONFIG_PACKAGE_openssh-server-pam is not set
# CONFIG_PACKAGE_openssh-sftp-avahi-service is not set
# CONFIG_PACKAGE_openssh-sftp-client is not set
# CONFIG_PACKAGE_openssh-sftp-server is not set
# CONFIG_PACKAGE_sshtunnel is not set
# end of SSH
#
# THC-IPv6 attack and analyzing toolkit
#
# CONFIG_PACKAGE_thc-ipv6-address6 is not set
# CONFIG_PACKAGE_thc-ipv6-alive6 is not set
# CONFIG_PACKAGE_thc-ipv6-covert-send6 is not set
# CONFIG_PACKAGE_thc-ipv6-covert-send6d is not set
# CONFIG_PACKAGE_thc-ipv6-denial6 is not set
# CONFIG_PACKAGE_thc-ipv6-detect-new-ip6 is not set
# CONFIG_PACKAGE_thc-ipv6-detect-sniffer6 is not set
# CONFIG_PACKAGE_thc-ipv6-dnsdict6 is not set
# CONFIG_PACKAGE_thc-ipv6-dnsrevenum6 is not set
# CONFIG_PACKAGE_thc-ipv6-dos-new-ip6 is not set
# CONFIG_PACKAGE_thc-ipv6-dump-router6 is not set
# CONFIG_PACKAGE_thc-ipv6-exploit6 is not set
# CONFIG_PACKAGE_thc-ipv6-fake-advertise6 is not set
# CONFIG_PACKAGE_thc-ipv6-fake-dhcps6 is not set
# CONFIG_PACKAGE_thc-ipv6-fake-dns6d is not set
# CONFIG_PACKAGE_thc-ipv6-fake-dnsupdate6 is not set
# CONFIG_PACKAGE_thc-ipv6-fake-mipv6 is not set
# CONFIG_PACKAGE_thc-ipv6-fake-mld26 is not set
# CONFIG_PACKAGE_thc-ipv6-fake-mld6 is not set
# CONFIG_PACKAGE_thc-ipv6-fake-mldrouter6 is not set
# CONFIG_PACKAGE_thc-ipv6-fake-router26 is not set
# CONFIG_PACKAGE_thc-ipv6-fake-router6 is not set
# CONFIG_PACKAGE_thc-ipv6-fake-solicitate6 is not set
# CONFIG_PACKAGE_thc-ipv6-flood-advertise6 is not set
# CONFIG_PACKAGE_thc-ipv6-flood-dhcpc6 is not set
# CONFIG_PACKAGE_thc-ipv6-flood-mld26 is not set
# CONFIG_PACKAGE_thc-ipv6-flood-mld6 is not set
# CONFIG_PACKAGE_thc-ipv6-flood-mldrouter6 is not set
# CONFIG_PACKAGE_thc-ipv6-flood-router26 is not set
# CONFIG_PACKAGE_thc-ipv6-flood-router6 is not set
# CONFIG_PACKAGE_thc-ipv6-flood-solicitate6 is not set
# CONFIG_PACKAGE_thc-ipv6-fragmentation6 is not set
# CONFIG_PACKAGE_thc-ipv6-fuzz-dhcpc6 is not set
# CONFIG_PACKAGE_thc-ipv6-fuzz-dhcps6 is not set
# CONFIG_PACKAGE_thc-ipv6-fuzz-ip6 is not set
# CONFIG_PACKAGE_thc-ipv6-implementation6 is not set
# CONFIG_PACKAGE_thc-ipv6-implementation6d is not set
# CONFIG_PACKAGE_thc-ipv6-inverse-lookup6 is not set
# CONFIG_PACKAGE_thc-ipv6-kill-router6 is not set
# CONFIG_PACKAGE_thc-ipv6-ndpexhaust6 is not set
# CONFIG_PACKAGE_thc-ipv6-node-query6 is not set
# CONFIG_PACKAGE_thc-ipv6-parasite6 is not set
# CONFIG_PACKAGE_thc-ipv6-passive-discovery6 is not set
# CONFIG_PACKAGE_thc-ipv6-randicmp6 is not set
# CONFIG_PACKAGE_thc-ipv6-redir6 is not set
# CONFIG_PACKAGE_thc-ipv6-rsmurf6 is not set
# CONFIG_PACKAGE_thc-ipv6-sendpees6 is not set
# CONFIG_PACKAGE_thc-ipv6-sendpeesmp6 is not set
# CONFIG_PACKAGE_thc-ipv6-smurf6 is not set
# CONFIG_PACKAGE_thc-ipv6-thcping6 is not set
# CONFIG_PACKAGE_thc-ipv6-toobig6 is not set
# CONFIG_PACKAGE_thc-ipv6-trace6 is not set
# end of THC-IPv6 attack and analyzing toolkit
#
# Tcpreplay
#
# CONFIG_PACKAGE_tcpbridge is not set
# CONFIG_PACKAGE_tcpcapinfo is not set
# CONFIG_PACKAGE_tcpliveplay is not set
# CONFIG_PACKAGE_tcpprep is not set
# CONFIG_PACKAGE_tcpreplay is not set
# CONFIG_PACKAGE_tcpreplay-all is not set
# CONFIG_PACKAGE_tcpreplay-edit is not set
# CONFIG_PACKAGE_tcprewrite is not set
# end of Tcpreplay
#
# Telephony
#
# CONFIG_PACKAGE_asterisk is not set
# CONFIG_PACKAGE_baresip is not set
# CONFIG_PACKAGE_freeswitch is not set
# CONFIG_PACKAGE_kamailio is not set
# CONFIG_PACKAGE_miax is not set
# CONFIG_PACKAGE_pcapsipdump is not set
# CONFIG_PACKAGE_restund is not set
# CONFIG_PACKAGE_rtpengine is not set
# CONFIG_PACKAGE_rtpengine-no-transcode is not set
# CONFIG_PACKAGE_rtpengine-recording is not set
# CONFIG_PACKAGE_rtpproxy is not set
# CONFIG_PACKAGE_sipp is not set
# CONFIG_PACKAGE_siproxd is not set
# CONFIG_PACKAGE_yate is not set
# end of Telephony
#
# Telephony Lantiq
#
# end of Telephony Lantiq
#
# Time Synchronization
#
# CONFIG_PACKAGE_chrony is not set
# CONFIG_PACKAGE_htpdate is not set
# CONFIG_PACKAGE_linuxptp is not set
# CONFIG_PACKAGE_ntp-keygen is not set
# CONFIG_PACKAGE_ntp-utils is not set
# CONFIG_PACKAGE_ntpclient is not set
# CONFIG_PACKAGE_ntpd is not set
# CONFIG_PACKAGE_ntpdate is not set
# end of Time Synchronization
#
# VPN
#
# CONFIG_PACKAGE_chaosvpn is not set
# CONFIG_PACKAGE_fastd is not set
# CONFIG_PACKAGE_libreswan is not set
# CONFIG_PACKAGE_n2n-edge is not set
# CONFIG_PACKAGE_n2n-supernode is not set
# CONFIG_PACKAGE_ocserv is not set
# CONFIG_PACKAGE_openconnect is not set
# CONFIG_PACKAGE_openfortivpn is not set
# CONFIG_PACKAGE_openvpn-easy-rsa is not set
# CONFIG_PACKAGE_openvpn-mbedtls is not set
# CONFIG_PACKAGE_openvpn-nossl is not set
# CONFIG_PACKAGE_openvpn-openssl is not set
# CONFIG_PACKAGE_pptpd is not set
# CONFIG_PACKAGE_softethervpn-base is not set
# CONFIG_PACKAGE_softethervpn-bridge is not set
# CONFIG_PACKAGE_softethervpn-client is not set
# CONFIG_PACKAGE_softethervpn-server is not set
# CONFIG_PACKAGE_softethervpn5-bridge is not set
# CONFIG_PACKAGE_softethervpn5-client is not set
# CONFIG_PACKAGE_softethervpn5-server is not set
# CONFIG_PACKAGE_sstp-client is not set
# CONFIG_PACKAGE_strongswan is not set
# CONFIG_PACKAGE_tinc is not set
# CONFIG_PACKAGE_uanytun is not set
# CONFIG_PACKAGE_uanytun-nettle is not set
# CONFIG_PACKAGE_uanytun-nocrypt is not set
# CONFIG_PACKAGE_uanytun-sslcrypt is not set
# CONFIG_PACKAGE_vpnc is not set
# CONFIG_PACKAGE_vpnc-scripts is not set
# CONFIG_PACKAGE_wireguard is not set
# CONFIG_PACKAGE_xl2tpd is not set
CONFIG_PACKAGE_zerotier=y
#
# Configuration
#
# CONFIG_ZEROTIER_ENABLE_DEBUG is not set
# CONFIG_ZEROTIER_ENABLE_SELFTEST is not set
# end of Configuration
# end of VPN
#
# Version Control Systems
#
# CONFIG_PACKAGE_git is not set
# CONFIG_PACKAGE_git-http is not set
# CONFIG_PACKAGE_subversion-client is not set
# CONFIG_PACKAGE_subversion-libs is not set
# CONFIG_PACKAGE_subversion-server is not set
# end of Version Control Systems
#
# WWAN
#
# CONFIG_PACKAGE_adb-enablemodem is not set
# CONFIG_PACKAGE_comgt is not set
# CONFIG_PACKAGE_comgt-directip is not set
# CONFIG_PACKAGE_umbim is not set
# CONFIG_PACKAGE_uqmi is not set
# end of WWAN
#
# Web Servers/Proxies
#
# CONFIG_PACKAGE_apache is not set
# CONFIG_PACKAGE_cgi-io is not set
# CONFIG_PACKAGE_clamav is not set
# CONFIG_PACKAGE_e2guardian is not set
# CONFIG_PACKAGE_etesync-server is not set
# CONFIG_PACKAGE_freshclam is not set
# CONFIG_PACKAGE_frpc is not set
# CONFIG_PACKAGE_frps is not set
CONFIG_PACKAGE_haproxy=y
# CONFIG_PACKAGE_halog is not set
# CONFIG_PACKAGE_haproxy-nossl is not set
# CONFIG_PACKAGE_kcptun-client is not set
# CONFIG_PACKAGE_kcptun-server is not set
# CONFIG_PACKAGE_lighttpd is not set
# CONFIG_PACKAGE_naiveproxy is not set
# CONFIG_PACKAGE_nginx is not set
CONFIG_NGINX_NOPCRE=y
# CONFIG_PACKAGE_nginx-all-module is not set
# CONFIG_PACKAGE_nginx-mod-luci is not set
# CONFIG_PACKAGE_nginx-mod-luci-ssl is not set
# CONFIG_PACKAGE_nginx-ssl is not set
# CONFIG_PACKAGE_nginx-ssl-util is not set
# CONFIG_PACKAGE_nginx-ssl-util-nopcre is not set
# CONFIG_PACKAGE_nginx-util is not set
CONFIG_PACKAGE_pdnsd-alt=y
# CONFIG_PACKAGE_polipo is not set
# CONFIG_PACKAGE_privoxy is not set
# CONFIG_PACKAGE_radicale is not set
# CONFIG_PACKAGE_radicale2 is not set
# CONFIG_PACKAGE_radicale2-examples is not set
# CONFIG_PACKAGE_redsocks2 is not set
# CONFIG_PACKAGE_shadowsocks-libev-config is not set
CONFIG_PACKAGE_shadowsocks-libev-ss-local=y
CONFIG_PACKAGE_shadowsocks-libev-ss-redir=y
# CONFIG_PACKAGE_shadowsocks-libev-ss-rules is not set
# CONFIG_PACKAGE_shadowsocks-libev-ss-server is not set
# CONFIG_PACKAGE_shadowsocks-libev-ss-tunnel is not set
# CONFIG_PACKAGE_sockd is not set
# CONFIG_PACKAGE_socksify is not set
# CONFIG_PACKAGE_spawn-fcgi is not set
# CONFIG_PACKAGE_squid is not set
# CONFIG_PACKAGE_srelay is not set
# CONFIG_PACKAGE_tinyproxy is not set
# CONFIG_PACKAGE_trojan-go is not set
CONFIG_PACKAGE_uhttpd=y
# CONFIG_PACKAGE_uhttpd-mod-lua is not set
CONFIG_PACKAGE_uhttpd-mod-ubus=y
# CONFIG_PACKAGE_uwsgi is not set
# end of Web Servers/Proxies
#
# Wireless
#
# CONFIG_PACKAGE_aircrack-ng is not set
# CONFIG_PACKAGE_airmon-ng is not set
# CONFIG_PACKAGE_dynapoint is not set
# CONFIG_PACKAGE_hcxdumptool is not set
# CONFIG_PACKAGE_hcxtools is not set
# CONFIG_PACKAGE_horst is not set
# CONFIG_PACKAGE_kismet-client is not set
# CONFIG_PACKAGE_kismet-drone is not set
# CONFIG_PACKAGE_kismet-server is not set
# CONFIG_PACKAGE_mt_wifi is not set
# CONFIG_PACKAGE_pixiewps is not set
# CONFIG_PACKAGE_reaver is not set
# CONFIG_PACKAGE_wavemon is not set
CONFIG_PACKAGE_wifischedule=y
# end of Wireless
#
# WirelessAPD
#
# CONFIG_PACKAGE_eapol-test is not set
# CONFIG_PACKAGE_eapol-test-openssl is not set
# CONFIG_PACKAGE_eapol-test-wolfssl is not set
CONFIG_PACKAGE_hostapd=y
# CONFIG_PACKAGE_hostapd-basic is not set
# CONFIG_PACKAGE_hostapd-basic-openssl is not set
# CONFIG_PACKAGE_hostapd-basic-wolfssl is not set
CONFIG_PACKAGE_hostapd-common=y
# CONFIG_PACKAGE_hostapd-mini is not set
# CONFIG_PACKAGE_hostapd-openssl is not set
# CONFIG_PACKAGE_hostapd-utils is not set
# CONFIG_PACKAGE_hostapd-wolfssl is not set
# CONFIG_PACKAGE_wpa-cli is not set
CONFIG_PACKAGE_wpa-supplicant=y
# CONFIG_WPA_RFKILL_SUPPORT is not set
CONFIG_WPA_MSG_MIN_PRIORITY=3
# CONFIG_WPA_WOLFSSL is not set
# CONFIG_DRIVER_WEXT_SUPPORT is not set
CONFIG_DRIVER_11N_SUPPORT=y
CONFIG_DRIVER_11AC_SUPPORT=y
# CONFIG_DRIVER_11AX_SUPPORT is not set
# CONFIG_DRIVER_11W_SUPPORT is not set
# CONFIG_WPA_ENABLE_WEP is not set
# CONFIG_PACKAGE_wpa-supplicant-basic is not set
# CONFIG_PACKAGE_wpa-supplicant-mesh-openssl is not set
# CONFIG_PACKAGE_wpa-supplicant-mesh-wolfssl is not set
# CONFIG_PACKAGE_wpa-supplicant-mini is not set
# CONFIG_PACKAGE_wpa-supplicant-openssl is not set
# CONFIG_PACKAGE_wpa-supplicant-p2p is not set
# CONFIG_PACKAGE_wpa-supplicant-wolfssl is not set
# CONFIG_PACKAGE_wpad is not set
# CONFIG_PACKAGE_wpad-basic is not set
# CONFIG_PACKAGE_wpad-basic-openssl is not set
# CONFIG_PACKAGE_wpad-basic-wolfssl is not set
# CONFIG_PACKAGE_wpad-mesh-openssl is not set
# CONFIG_PACKAGE_wpad-mesh-wolfssl is not set
# CONFIG_PACKAGE_wpad-mini is not set
# CONFIG_PACKAGE_wpad-openssl is not set
# CONFIG_PACKAGE_wpad-wolfssl is not set
# end of WirelessAPD
#
# arp-scan
#
# CONFIG_PACKAGE_arp-scan is not set
# CONFIG_PACKAGE_arp-scan-database is not set
# end of arp-scan
# CONFIG_PACKAGE_464xlat is not set
# CONFIG_PACKAGE_6in4 is not set
# CONFIG_PACKAGE_6rd is not set
# CONFIG_PACKAGE_6to4 is not set
# CONFIG_PACKAGE_acme is not set
# CONFIG_PACKAGE_acme-dnsapi is not set
# CONFIG_PACKAGE_adblock is not set
CONFIG_PACKAGE_adbyby=y
# CONFIG_PACKAGE_addrwatch is not set
# CONFIG_PACKAGE_ahcpd is not set
# CONFIG_PACKAGE_alfred is not set
# CONFIG_PACKAGE_apcupsd is not set
# CONFIG_PACKAGE_apcupsd-cgi is not set
# CONFIG_PACKAGE_apinger is not set
# CONFIG_PACKAGE_baidupcs-web is not set
# CONFIG_PACKAGE_banip is not set
# CONFIG_PACKAGE_batctl-default is not set
# CONFIG_PACKAGE_batctl-full is not set
# CONFIG_PACKAGE_batctl-tiny is not set
# CONFIG_PACKAGE_beanstalkd is not set
# CONFIG_PACKAGE_bmon is not set
# CONFIG_PACKAGE_boinc is not set
# CONFIG_PACKAGE_brook is not set
# CONFIG_PACKAGE_bwm-ng is not set
# CONFIG_PACKAGE_bwping is not set
# CONFIG_PACKAGE_chat is not set
# CONFIG_PACKAGE_chinadns-ng is not set
# CONFIG_PACKAGE_cifsmount is not set
# CONFIG_PACKAGE_coap-server is not set
# CONFIG_PACKAGE_conserver is not set
# CONFIG_PACKAGE_cshark is not set
# CONFIG_PACKAGE_daemonlogger is not set
# CONFIG_PACKAGE_darkstat is not set
# CONFIG_PACKAGE_dawn is not set
# CONFIG_PACKAGE_dhcpcd is not set
# CONFIG_PACKAGE_dmapd is not set
# CONFIG_PACKAGE_dnscrypt-proxy2 is not set
# CONFIG_PACKAGE_dnsforwarder is not set
# CONFIG_PACKAGE_dnstop is not set
# CONFIG_PACKAGE_ds-lite is not set
# CONFIG_PACKAGE_dsmboot is not set
# CONFIG_PACKAGE_esniper is not set
# CONFIG_PACKAGE_etherwake is not set
# CONFIG_PACKAGE_etherwake-nfqueue is not set
# CONFIG_PACKAGE_ethtool is not set
# CONFIG_PACKAGE_fakeidentd is not set
# CONFIG_PACKAGE_family-dns is not set
# CONFIG_PACKAGE_foolsm is not set
# CONFIG_PACKAGE_fping is not set
# CONFIG_PACKAGE_geth is not set
# CONFIG_PACKAGE_gnunet is not set
# CONFIG_PACKAGE_gre is not set
# CONFIG_PACKAGE_hnet-full is not set
# CONFIG_PACKAGE_hnet-full-l2tp is not set
# CONFIG_PACKAGE_hnet-full-secure is not set
# CONFIG_PACKAGE_hnetd-nossl is not set
# CONFIG_PACKAGE_hnetd-openssl is not set
# CONFIG_PACKAGE_httping is not set
# CONFIG_PACKAGE_httping-nossl is not set
# CONFIG_PACKAGE_https-dns-proxy is not set
# CONFIG_PACKAGE_i2pd is not set
# CONFIG_PACKAGE_ibrdtn-tools is not set
# CONFIG_PACKAGE_ibrdtnd is not set
# CONFIG_PACKAGE_ifstat is not set
# CONFIG_PACKAGE_iftop is not set
# CONFIG_PACKAGE_iiod is not set
# CONFIG_PACKAGE_iperf is not set
# CONFIG_PACKAGE_iperf3 is not set
# CONFIG_PACKAGE_iperf3-ssl is not set
# CONFIG_PACKAGE_ipip is not set
CONFIG_PACKAGE_ipset=y
# CONFIG_PACKAGE_ipset-dns is not set
CONFIG_PACKAGE_ipt2socks=y
# CONFIG_PACKAGE_iptraf-ng is not set
# CONFIG_PACKAGE_iputils-arping is not set
# CONFIG_PACKAGE_iputils-clockdiff is not set
# CONFIG_PACKAGE_iputils-ping is not set
# CONFIG_PACKAGE_iputils-ping6 is not set
# CONFIG_PACKAGE_iputils-tftpd is not set
# CONFIG_PACKAGE_iputils-tracepath is not set
# CONFIG_PACKAGE_iputils-tracepath6 is not set
# CONFIG_PACKAGE_iputils-traceroute6 is not set
# CONFIG_PACKAGE_ipvsadm is not set
CONFIG_PACKAGE_iw=y
# CONFIG_PACKAGE_iw-full is not set
# CONFIG_PACKAGE_jool is not set
# CONFIG_PACKAGE_jool-tools is not set
# CONFIG_PACKAGE_keepalived is not set
# CONFIG_PACKAGE_knxd is not set
# CONFIG_PACKAGE_kplex is not set
# CONFIG_PACKAGE_krb5-client is not set
# CONFIG_PACKAGE_krb5-libs is not set
# CONFIG_PACKAGE_krb5-server is not set
# CONFIG_PACKAGE_krb5-server-extras is not set
CONFIG_PACKAGE_libipset=y
# CONFIG_PACKAGE_libndp is not set
# CONFIG_PACKAGE_linknx is not set
# CONFIG_PACKAGE_lynx is not set
# CONFIG_PACKAGE_mac-telnet-client is not set
# CONFIG_PACKAGE_mac-telnet-discover is not set
# CONFIG_PACKAGE_mac-telnet-ping is not set
# CONFIG_PACKAGE_mac-telnet-server is not set
# CONFIG_PACKAGE_map is not set
# CONFIG_PACKAGE_memcached is not set
CONFIG_PACKAGE_microsocks=y
# CONFIG_PACKAGE_mii-tool is not set
# CONFIG_PACKAGE_mikrotik-btest is not set
# CONFIG_PACKAGE_mini_snmpd is not set
# CONFIG_PACKAGE_minimalist-pcproxy is not set
# CONFIG_PACKAGE_miredo is not set
# CONFIG_PACKAGE_modemmanager is not set
# CONFIG_PACKAGE_mosquitto-client-nossl is not set
# CONFIG_PACKAGE_mosquitto-client-ssl is not set
# CONFIG_PACKAGE_mosquitto-nossl is not set
# CONFIG_PACKAGE_mosquitto-ssl is not set
# CONFIG_PACKAGE_mrd6 is not set
# CONFIG_PACKAGE_mstpd is not set
# CONFIG_PACKAGE_mtr is not set
# CONFIG_PACKAGE_nbd is not set
# CONFIG_PACKAGE_nbd-server is not set
# CONFIG_PACKAGE_ncp is not set
# CONFIG_PACKAGE_ndppd is not set
# CONFIG_PACKAGE_ndptool is not set
# CONFIG_PACKAGE_net-tools-route is not set
# CONFIG_PACKAGE_netcat is not set
# CONFIG_PACKAGE_netdiscover is not set
# CONFIG_PACKAGE_netifyd is not set
# CONFIG_PACKAGE_netperf is not set
# CONFIG_PACKAGE_netsniff-ng is not set
# CONFIG_PACKAGE_nextdns is not set
# CONFIG_PACKAGE_nfdump is not set
# CONFIG_PACKAGE_nlbwmon is not set
# CONFIG_PACKAGE_noddos is not set
# CONFIG_PACKAGE_noping is not set
# CONFIG_PACKAGE_npc is not set
# CONFIG_PACKAGE_nut is not set
# CONFIG_PACKAGE_obfs4proxy is not set
# CONFIG_PACKAGE_odhcp6c is not set
# CONFIG_PACKAGE_odhcpd is not set
# CONFIG_PACKAGE_odhcpd-ipv6only is not set
# CONFIG_PACKAGE_ola is not set
# CONFIG_PACKAGE_omcproxy is not set
# CONFIG_PACKAGE_oor is not set
# CONFIG_PACKAGE_oping is not set
# CONFIG_PACKAGE_ostiary is not set
# CONFIG_PACKAGE_pagekitec is not set
# CONFIG_PACKAGE_pen is not set
# CONFIG_PACKAGE_phantap is not set
# CONFIG_PACKAGE_pimbd is not set
# CONFIG_PACKAGE_pingcheck is not set
# CONFIG_PACKAGE_port-mirroring is not set
CONFIG_PACKAGE_ppp=y
# CONFIG_PACKAGE_ppp-mod-passwordfd is not set
# CONFIG_PACKAGE_ppp-mod-pppoa is not set
CONFIG_PACKAGE_ppp-mod-pppoe=y
# CONFIG_PACKAGE_ppp-mod-pppol2tp is not set
# CONFIG_PACKAGE_ppp-mod-pptp is not set
# CONFIG_PACKAGE_ppp-mod-radius is not set
# CONFIG_PACKAGE_ppp-multilink is not set
# CONFIG_PACKAGE_pppdump is not set
# CONFIG_PACKAGE_pppoe-discovery is not set
# CONFIG_PACKAGE_pppossh is not set
# CONFIG_PACKAGE_pppstats is not set
# CONFIG_PACKAGE_proto-bonding is not set
# CONFIG_PACKAGE_proxychains-ng is not set
# CONFIG_PACKAGE_ptunnel-ng is not set
# CONFIG_PACKAGE_radsecproxy is not set
# CONFIG_PACKAGE_ratechecker is not set
# CONFIG_PACKAGE_redsocks is not set
# CONFIG_PACKAGE_remserial is not set
# CONFIG_PACKAGE_restic-rest-server is not set
# CONFIG_PACKAGE_rpcbind is not set
# CONFIG_PACKAGE_rssileds is not set
# CONFIG_PACKAGE_rsyslog is not set
# CONFIG_PACKAGE_safe-search is not set
# CONFIG_PACKAGE_samba36-client is not set
# CONFIG_PACKAGE_samba36-net is not set
CONFIG_PACKAGE_samba36-server=y
CONFIG_PACKAGE_SAMBA_MAX_DEBUG_LEVEL=-1
# CONFIG_PACKAGE_samba4-admin is not set
# CONFIG_PACKAGE_samba4-client is not set
# CONFIG_PACKAGE_samba4-libs is not set
# CONFIG_PACKAGE_samba4-server is not set
# CONFIG_PACKAGE_samba4-utils is not set
# CONFIG_PACKAGE_scapy is not set
# CONFIG_PACKAGE_sctp is not set
# CONFIG_PACKAGE_sctp-tools is not set
# CONFIG_PACKAGE_seafile-ccnet is not set
# CONFIG_PACKAGE_seafile-seahub is not set
# CONFIG_PACKAGE_seafile-server is not set
# CONFIG_PACKAGE_seafile-server-fuse is not set
# CONFIG_PACKAGE_ser2net is not set
# CONFIG_PACKAGE_shadowsocksr-libev is not set
CONFIG_PACKAGE_shadowsocksr-libev-alt=y
# CONFIG_PACKAGE_shadowsocksr-libev-server is not set
CONFIG_PACKAGE_shadowsocksr-libev-ssr-local=y
# CONFIG_PACKAGE_simple-adblock is not set
CONFIG_PACKAGE_simple-obfs=y
# CONFIG_PACKAGE_simple-obfs-server is not set
#
# Simple-obfs Compile Configuration
#
# CONFIG_SIMPLE_OBFS_STATIC_LINK is not set
# end of Simple-obfs Compile Configuration
CONFIG_PACKAGE_smartdns=y
# CONFIG_PACKAGE_smartsnmpd is not set
# CONFIG_PACKAGE_smbinfo is not set
# CONFIG_PACKAGE_snmp-mibs is not set
# CONFIG_PACKAGE_snmp-utils is not set
# CONFIG_PACKAGE_snmpd is not set
# CONFIG_PACKAGE_snmpd-static is not set
# CONFIG_PACKAGE_snmptrapd is not set
# CONFIG_PACKAGE_socat is not set
# CONFIG_PACKAGE_softflowd is not set
# CONFIG_PACKAGE_soloscli is not set
# CONFIG_PACKAGE_speedtest-netperf is not set
# CONFIG_PACKAGE_spoofer is not set
CONFIG_PACKAGE_ssocks=y
# CONFIG_PACKAGE_ssocksd is not set
# CONFIG_PACKAGE_stunnel is not set
# CONFIG_PACKAGE_switchdev-poller is not set
# CONFIG_PACKAGE_tac_plus is not set
# CONFIG_PACKAGE_tac_plus-pam is not set
# CONFIG_PACKAGE_tayga is not set
# CONFIG_PACKAGE_tcpdump is not set
# CONFIG_PACKAGE_tcpdump-mini is not set
CONFIG_PACKAGE_tcping=y
# CONFIG_PACKAGE_tcpping is not set
# CONFIG_PACKAGE_tgt is not set
# CONFIG_PACKAGE_tor is not set
# CONFIG_PACKAGE_tor-fw-helper is not set
# CONFIG_PACKAGE_tor-gencert is not set
# CONFIG_PACKAGE_tor-geoip is not set
# CONFIG_PACKAGE_tor-resolve is not set
# CONFIG_PACKAGE_trafficshaper is not set
CONFIG_PACKAGE_travelmate=y
# CONFIG_PACKAGE_trojan is not set
# CONFIG_PACKAGE_trojan-plus is not set
# CONFIG_PACKAGE_u2pnpd is not set
# CONFIG_PACKAGE_uacme is not set
CONFIG_PACKAGE_uclient-fetch=y
# CONFIG_PACKAGE_udptunnel is not set
# CONFIG_PACKAGE_udpxy is not set
# CONFIG_PACKAGE_ulogd is not set
# CONFIG_PACKAGE_umdns is not set
# CONFIG_PACKAGE_usbip is not set
# CONFIG_PACKAGE_uugamebooster is not set
# CONFIG_PACKAGE_vallumd is not set
# CONFIG_PACKAGE_verysync is not set
CONFIG_PACKAGE_vlmcsd=y
# CONFIG_PACKAGE_vncrepeater is not set
# CONFIG_PACKAGE_vnstat is not set
# CONFIG_PACKAGE_vnstat2 is not set
# CONFIG_PACKAGE_vpn-policy-routing is not set
# CONFIG_PACKAGE_vpnbypass is not set
# CONFIG_PACKAGE_vti is not set
# CONFIG_PACKAGE_vxlan is not set
# CONFIG_PACKAGE_wakeonlan is not set
# CONFIG_PACKAGE_wol is not set
# CONFIG_PACKAGE_wpan-tools is not set
# CONFIG_PACKAGE_wwan is not set
# CONFIG_PACKAGE_xinetd is not set
# end of Network
#
# Sound
#
# CONFIG_PACKAGE_alsa-utils is not set
# CONFIG_PACKAGE_alsa-utils-seq is not set
# CONFIG_PACKAGE_alsa-utils-tests is not set
# CONFIG_PACKAGE_aserver is not set
# CONFIG_PACKAGE_espeak is not set
# CONFIG_PACKAGE_faad2 is not set
# CONFIG_PACKAGE_fdk-aac is not set
# CONFIG_PACKAGE_forked-daapd is not set
# CONFIG_PACKAGE_ices is not set
# CONFIG_PACKAGE_lame is not set
# CONFIG_PACKAGE_lame-lib is not set
# CONFIG_PACKAGE_liblo-utils is not set
# CONFIG_PACKAGE_madplay is not set
# CONFIG_PACKAGE_madplay-alsa is not set
# CONFIG_PACKAGE_moc is not set
# CONFIG_PACKAGE_mpc is not set
# CONFIG_PACKAGE_mpd-avahi-service is not set
# CONFIG_PACKAGE_mpd-full is not set
# CONFIG_PACKAGE_mpd-mini is not set
# CONFIG_PACKAGE_mpg123 is not set
# CONFIG_PACKAGE_opus-tools is not set
# CONFIG_PACKAGE_pianod is not set
# CONFIG_PACKAGE_pianod-client is not set
# CONFIG_PACKAGE_portaudio is not set
# CONFIG_PACKAGE_pulseaudio-daemon is not set
# CONFIG_PACKAGE_pulseaudio-daemon-avahi is not set
# CONFIG_PACKAGE_shairplay is not set
# CONFIG_PACKAGE_shairport-sync-mbedtls is not set
# CONFIG_PACKAGE_shairport-sync-mini is not set
# CONFIG_PACKAGE_shairport-sync-openssl is not set
# CONFIG_PACKAGE_shine is not set
# CONFIG_PACKAGE_sox is not set
# CONFIG_PACKAGE_squeezelite-full is not set
# CONFIG_PACKAGE_squeezelite-mini is not set
# CONFIG_PACKAGE_svox is not set
# CONFIG_PACKAGE_upmpdcli is not set
# end of Sound
#
# Utilities
#
#
# BigClown
#
# CONFIG_PACKAGE_bigclown-control-tool is not set
# CONFIG_PACKAGE_bigclown-firmware-tool is not set
# CONFIG_PACKAGE_bigclown-mqtt2influxdb is not set
# end of BigClown
#
# Boot Loaders
#
# CONFIG_PACKAGE_fconfig is not set
# CONFIG_PACKAGE_uboot-envtools is not set
# end of Boot Loaders
#
# Compression
#
# CONFIG_PACKAGE_bsdtar is not set
# CONFIG_PACKAGE_bsdtar-noopenssl is not set
# CONFIG_PACKAGE_bzip2 is not set
# CONFIG_PACKAGE_gzip is not set
# CONFIG_PACKAGE_lz4 is not set
# CONFIG_PACKAGE_pigz is not set
# CONFIG_PACKAGE_unrar is not set
CONFIG_PACKAGE_unzip=y
# CONFIG_PACKAGE_xz-utils is not set
# CONFIG_PACKAGE_zipcmp is not set
# CONFIG_PACKAGE_zipmerge is not set
# CONFIG_PACKAGE_ziptool is not set
# CONFIG_PACKAGE_zstd is not set
# end of Compression
#
# Database
#
# CONFIG_PACKAGE_mariadb-common is not set
# CONFIG_PACKAGE_pgsql-cli is not set
# CONFIG_PACKAGE_pgsql-cli-extra is not set
# CONFIG_PACKAGE_pgsql-server is not set
# CONFIG_PACKAGE_rrdcgi1 is not set
# CONFIG_PACKAGE_rrdtool1 is not set
# CONFIG_PACKAGE_sqlite3-cli is not set
# CONFIG_PACKAGE_unixodbc-tools is not set
# end of Database
#
# Disc
#
# CONFIG_PACKAGE_blkdiscard is not set
# CONFIG_PACKAGE_blkid is not set
# CONFIG_PACKAGE_blockdev is not set
# CONFIG_PACKAGE_cfdisk is not set
# CONFIG_PACKAGE_cgdisk is not set
# CONFIG_PACKAGE_eject is not set
# CONFIG_PACKAGE_fdisk is not set
# CONFIG_PACKAGE_findfs is not set
# CONFIG_PACKAGE_fio is not set
# CONFIG_PACKAGE_fixparts is not set
# CONFIG_PACKAGE_gdisk is not set
# CONFIG_PACKAGE_hd-idle is not set
# CONFIG_PACKAGE_hdparm is not set
# CONFIG_PACKAGE_lsblk is not set
# CONFIG_PACKAGE_lvm2 is not set
# CONFIG_PACKAGE_mdadm is not set
# CONFIG_PACKAGE_parted is not set
# CONFIG_PACKAGE_partx-utils is not set
# CONFIG_PACKAGE_sfdisk is not set
# CONFIG_PACKAGE_sgdisk is not set
# CONFIG_PACKAGE_wipefs is not set
# end of Disc
#
# Editors
#
# CONFIG_PACKAGE_joe is not set
# CONFIG_PACKAGE_jupp is not set
# CONFIG_PACKAGE_mg is not set
# CONFIG_PACKAGE_nano is not set
# CONFIG_PACKAGE_vim is not set
# CONFIG_PACKAGE_vim-full is not set
# CONFIG_PACKAGE_vim-fuller is not set
# CONFIG_PACKAGE_vim-help is not set
# CONFIG_PACKAGE_vim-runtime is not set
# CONFIG_PACKAGE_zile is not set
# end of Editors
#
# Encryption
#
# CONFIG_PACKAGE_ccrypt is not set
# CONFIG_PACKAGE_certtool is not set
# CONFIG_PACKAGE_cryptsetup is not set
# CONFIG_PACKAGE_gnupg is not set
# CONFIG_PACKAGE_gnutls-utils is not set
# CONFIG_PACKAGE_gpgv is not set
# CONFIG_PACKAGE_keyctl is not set
# CONFIG_PACKAGE_px5g-mbedtls is not set
# CONFIG_PACKAGE_px5g-standalone is not set
# CONFIG_PACKAGE_stoken is not set
# end of Encryption
#
# Filesystem
#
# CONFIG_PACKAGE_acl is not set
# CONFIG_PACKAGE_antfs-mount is not set
# CONFIG_PACKAGE_attr is not set
# CONFIG_PACKAGE_badblocks is not set
# CONFIG_PACKAGE_btrfs-progs is not set
# CONFIG_PACKAGE_chattr is not set
# CONFIG_PACKAGE_debugfs is not set
# CONFIG_PACKAGE_dosfstools is not set
# CONFIG_PACKAGE_dumpe2fs is not set
# CONFIG_PACKAGE_e2freefrag is not set
# CONFIG_PACKAGE_e2fsprogs is not set
# CONFIG_PACKAGE_e4crypt is not set
# CONFIG_PACKAGE_exfat-fsck is not set
# CONFIG_PACKAGE_exfat-mkfs is not set
# CONFIG_PACKAGE_f2fs-tools is not set
# CONFIG_PACKAGE_f2fsck is not set
# CONFIG_PACKAGE_filefrag is not set
# CONFIG_PACKAGE_fstrim is not set
# CONFIG_PACKAGE_fuse-utils is not set
# CONFIG_PACKAGE_hfsfsck is not set
# CONFIG_PACKAGE_lsattr is not set
# CONFIG_PACKAGE_mkf2fs is not set
# CONFIG_PACKAGE_mkhfs is not set
# CONFIG_PACKAGE_ncdu is not set
# CONFIG_PACKAGE_nfs-utils is not set
# CONFIG_PACKAGE_nfs-utils-libs is not set
# CONFIG_PACKAGE_ntfs-3g is not set
# CONFIG_PACKAGE_ntfs-3g-low is not set
# CONFIG_PACKAGE_ntfs-3g-utils is not set
# CONFIG_PACKAGE_owfs is not set
# CONFIG_PACKAGE_owshell is not set
# CONFIG_PACKAGE_resize2fs is not set
# CONFIG_PACKAGE_squashfs-tools-mksquashfs is not set
# CONFIG_PACKAGE_squashfs-tools-unsquashfs is not set
# CONFIG_PACKAGE_swap-utils is not set
# CONFIG_PACKAGE_sysfsutils is not set
# CONFIG_PACKAGE_tune2fs is not set
# CONFIG_PACKAGE_xfs-admin is not set
# CONFIG_PACKAGE_xfs-fsck is not set
# CONFIG_PACKAGE_xfs-growfs is not set
# CONFIG_PACKAGE_xfs-mkfs is not set
# end of Filesystem
#
# Image Manipulation
#
# CONFIG_PACKAGE_libjpeg-turbo-utils is not set
# CONFIG_PACKAGE_tiff-utils is not set
# end of Image Manipulation
#
# Microcontroller programming
#
# CONFIG_PACKAGE_avrdude is not set
# CONFIG_PACKAGE_dfu-programmer is not set
# CONFIG_PACKAGE_stm32flash is not set
# end of Microcontroller programming
#
# RTKLIB Suite
#
# CONFIG_PACKAGE_convbin is not set
# CONFIG_PACKAGE_pos2kml is not set
# CONFIG_PACKAGE_rnx2rtkp is not set
# CONFIG_PACKAGE_rtkrcv is not set
# CONFIG_PACKAGE_str2str is not set
# end of RTKLIB Suite
#
# Shells
#
CONFIG_PACKAGE_bash=y
# CONFIG_PACKAGE_fish is not set
# CONFIG_PACKAGE_klish is not set
# CONFIG_PACKAGE_mksh is not set
# CONFIG_PACKAGE_tcsh is not set
# CONFIG_PACKAGE_zsh is not set
# end of Shells
#
# Telephony
#
# CONFIG_PACKAGE_dahdi-cfg is not set
# CONFIG_PACKAGE_dahdi-monitor is not set
# CONFIG_PACKAGE_gsm-utils is not set
# CONFIG_PACKAGE_sipgrep is not set
# CONFIG_PACKAGE_sngrep is not set
# end of Telephony
#
# Terminal
#
# CONFIG_PACKAGE_agetty is not set
# CONFIG_PACKAGE_dvtm is not set
# CONFIG_PACKAGE_minicom is not set
# CONFIG_PACKAGE_picocom is not set
# CONFIG_PACKAGE_rtty-mbedtls is not set
# CONFIG_PACKAGE_rtty-nossl is not set
# CONFIG_PACKAGE_rtty-openssl is not set
# CONFIG_PACKAGE_rtty-wolfssl is not set
# CONFIG_PACKAGE_screen is not set
# CONFIG_PACKAGE_script-utils is not set
# CONFIG_PACKAGE_serialconsole is not set
# CONFIG_PACKAGE_setterm is not set
# CONFIG_PACKAGE_tio is not set
# CONFIG_PACKAGE_tmux is not set
CONFIG_PACKAGE_ttyd=y
# CONFIG_PACKAGE_wall is not set
# end of Terminal
#
# Virtualization
#
# end of Virtualization
#
# Zoneinfo
#
# CONFIG_PACKAGE_zoneinfo-africa is not set
# CONFIG_PACKAGE_zoneinfo-all is not set
# CONFIG_PACKAGE_zoneinfo-asia is not set
# CONFIG_PACKAGE_zoneinfo-atlantic is not set
# CONFIG_PACKAGE_zoneinfo-australia-nz is not set
# CONFIG_PACKAGE_zoneinfo-core is not set
# CONFIG_PACKAGE_zoneinfo-europe is not set
# CONFIG_PACKAGE_zoneinfo-india is not set
# CONFIG_PACKAGE_zoneinfo-northamerica is not set
# CONFIG_PACKAGE_zoneinfo-pacific is not set
# CONFIG_PACKAGE_zoneinfo-poles is not set
# CONFIG_PACKAGE_zoneinfo-simple is not set
# CONFIG_PACKAGE_zoneinfo-southamerica is not set
# end of Zoneinfo
#
# libimobiledevice
#
# CONFIG_PACKAGE_idevicerestore is not set
# CONFIG_PACKAGE_irecovery is not set
# CONFIG_PACKAGE_libimobiledevice-utils is not set
# CONFIG_PACKAGE_libusbmuxd-utils is not set
# CONFIG_PACKAGE_plistutil is not set
# CONFIG_PACKAGE_usbmuxd is not set
# end of libimobiledevice
# CONFIG_PACKAGE_acpid is not set
# CONFIG_PACKAGE_adb is not set
# CONFIG_PACKAGE_ap51-flash is not set
# CONFIG_PACKAGE_at is not set
# CONFIG_PACKAGE_bandwidthd is not set
# CONFIG_PACKAGE_bandwidthd-pgsql is not set
# CONFIG_PACKAGE_bandwidthd-php is not set
# CONFIG_PACKAGE_bandwidthd-sqlite is not set
# CONFIG_PACKAGE_banhostlist is not set
# CONFIG_PACKAGE_bc is not set
# CONFIG_PACKAGE_bluelog is not set
# CONFIG_PACKAGE_bluez-daemon is not set
# CONFIG_PACKAGE_bluez-utils is not set
# CONFIG_PACKAGE_bluez-utils-extra is not set
# CONFIG_PACKAGE_bonniexx is not set
# CONFIG_PACKAGE_bsdiff is not set
# CONFIG_PACKAGE_bspatch is not set
# CONFIG_PACKAGE_byobu is not set
# CONFIG_PACKAGE_byobu-utils is not set
# CONFIG_PACKAGE_cache-domains-mbedtls is not set
# CONFIG_PACKAGE_cache-domains-openssl is not set
# CONFIG_PACKAGE_cal is not set
# CONFIG_PACKAGE_canutils is not set
# CONFIG_PACKAGE_cgroup-tools is not set
# CONFIG_PACKAGE_cgroupfs-mount is not set
# CONFIG_PACKAGE_cmdpad is not set
# CONFIG_PACKAGE_coap-client is not set
# CONFIG_PACKAGE_collectd is not set
CONFIG_PACKAGE_coremark=y
CONFIG_PACKAGE_coreutils=y
# CONFIG_PACKAGE_coreutils-b2sum is not set
# CONFIG_PACKAGE_coreutils-base32 is not set
CONFIG_PACKAGE_coreutils-base64=y
# CONFIG_PACKAGE_coreutils-basename is not set
# CONFIG_PACKAGE_coreutils-basenc is not set
# CONFIG_PACKAGE_coreutils-cat is not set
# CONFIG_PACKAGE_coreutils-chcon is not set
# CONFIG_PACKAGE_coreutils-chgrp is not set
# CONFIG_PACKAGE_coreutils-chmod is not set
# CONFIG_PACKAGE_coreutils-chown is not set
# CONFIG_PACKAGE_coreutils-chroot is not set
# CONFIG_PACKAGE_coreutils-cksum is not set
# CONFIG_PACKAGE_coreutils-comm is not set
# CONFIG_PACKAGE_coreutils-cp is not set
# CONFIG_PACKAGE_coreutils-csplit is not set
# CONFIG_PACKAGE_coreutils-cut is not set
# CONFIG_PACKAGE_coreutils-date is not set
# CONFIG_PACKAGE_coreutils-dd is not set
# CONFIG_PACKAGE_coreutils-df is not set
# CONFIG_PACKAGE_coreutils-dir is not set
# CONFIG_PACKAGE_coreutils-dircolors is not set
# CONFIG_PACKAGE_coreutils-dirname is not set
# CONFIG_PACKAGE_coreutils-du is not set
# CONFIG_PACKAGE_coreutils-echo is not set
# CONFIG_PACKAGE_coreutils-env is not set
# CONFIG_PACKAGE_coreutils-expand is not set
# CONFIG_PACKAGE_coreutils-expr is not set
# CONFIG_PACKAGE_coreutils-factor is not set
# CONFIG_PACKAGE_coreutils-false is not set
# CONFIG_PACKAGE_coreutils-fmt is not set
# CONFIG_PACKAGE_coreutils-fold is not set
# CONFIG_PACKAGE_coreutils-groups is not set
# CONFIG_PACKAGE_coreutils-head is not set
# CONFIG_PACKAGE_coreutils-hostid is not set
# CONFIG_PACKAGE_coreutils-id is not set
# CONFIG_PACKAGE_coreutils-install is not set
# CONFIG_PACKAGE_coreutils-join is not set
# CONFIG_PACKAGE_coreutils-kill is not set
# CONFIG_PACKAGE_coreutils-link is not set
# CONFIG_PACKAGE_coreutils-ln is not set
# CONFIG_PACKAGE_coreutils-logname is not set
# CONFIG_PACKAGE_coreutils-ls is not set
# CONFIG_PACKAGE_coreutils-md5sum is not set
# CONFIG_PACKAGE_coreutils-mkdir is not set
# CONFIG_PACKAGE_coreutils-mkfifo is not set
# CONFIG_PACKAGE_coreutils-mknod is not set
# CONFIG_PACKAGE_coreutils-mktemp is not set
# CONFIG_PACKAGE_coreutils-mv is not set
# CONFIG_PACKAGE_coreutils-nice is not set
# CONFIG_PACKAGE_coreutils-nl is not set
CONFIG_PACKAGE_coreutils-nohup=y
# CONFIG_PACKAGE_coreutils-nproc is not set
# CONFIG_PACKAGE_coreutils-numfmt is not set
# CONFIG_PACKAGE_coreutils-od is not set
# CONFIG_PACKAGE_coreutils-paste is not set
# CONFIG_PACKAGE_coreutils-pathchk is not set
# CONFIG_PACKAGE_coreutils-pinky is not set
# CONFIG_PACKAGE_coreutils-pr is not set
# CONFIG_PACKAGE_coreutils-printenv is not set
# CONFIG_PACKAGE_coreutils-printf is not set
# CONFIG_PACKAGE_coreutils-ptx is not set
# CONFIG_PACKAGE_coreutils-pwd is not set
# CONFIG_PACKAGE_coreutils-readlink is not set
# CONFIG_PACKAGE_coreutils-realpath is not set
# CONFIG_PACKAGE_coreutils-rm is not set
# CONFIG_PACKAGE_coreutils-rmdir is not set
# CONFIG_PACKAGE_coreutils-runcon is not set
# CONFIG_PACKAGE_coreutils-seq is not set
# CONFIG_PACKAGE_coreutils-sha1sum is not set
# CONFIG_PACKAGE_coreutils-sha224sum is not set
# CONFIG_PACKAGE_coreutils-sha256sum is not set
# CONFIG_PACKAGE_coreutils-sha384sum is not set
# CONFIG_PACKAGE_coreutils-sha512sum is not set
# CONFIG_PACKAGE_coreutils-shred is not set
# CONFIG_PACKAGE_coreutils-shuf is not set
# CONFIG_PACKAGE_coreutils-sleep is not set
# CONFIG_PACKAGE_coreutils-sort is not set
# CONFIG_PACKAGE_coreutils-split is not set
# CONFIG_PACKAGE_coreutils-stat is not set
# CONFIG_PACKAGE_coreutils-stdbuf is not set
# CONFIG_PACKAGE_coreutils-stty is not set
# CONFIG_PACKAGE_coreutils-sum is not set
# CONFIG_PACKAGE_coreutils-sync is not set
# CONFIG_PACKAGE_coreutils-tac is not set
# CONFIG_PACKAGE_coreutils-tail is not set
# CONFIG_PACKAGE_coreutils-tee is not set
# CONFIG_PACKAGE_coreutils-test is not set
# CONFIG_PACKAGE_coreutils-timeout is not set
# CONFIG_PACKAGE_coreutils-touch is not set
# CONFIG_PACKAGE_coreutils-tr is not set
# CONFIG_PACKAGE_coreutils-true is not set
# CONFIG_PACKAGE_coreutils-truncate is not set
# CONFIG_PACKAGE_coreutils-tsort is not set
# CONFIG_PACKAGE_coreutils-tty is not set
# CONFIG_PACKAGE_coreutils-uname is not set
# CONFIG_PACKAGE_coreutils-unexpand is not set
# CONFIG_PACKAGE_coreutils-uniq is not set
# CONFIG_PACKAGE_coreutils-unlink is not set
# CONFIG_PACKAGE_coreutils-uptime is not set
# CONFIG_PACKAGE_coreutils-users is not set
# CONFIG_PACKAGE_coreutils-vdir is not set
# CONFIG_PACKAGE_coreutils-wc is not set
# CONFIG_PACKAGE_coreutils-who is not set
# CONFIG_PACKAGE_coreutils-whoami is not set
# CONFIG_PACKAGE_coreutils-yes is not set
# CONFIG_PACKAGE_crconf is not set
# CONFIG_PACKAGE_crelay is not set
# CONFIG_PACKAGE_csstidy is not set
# CONFIG_PACKAGE_ct-bugcheck is not set
# CONFIG_PACKAGE_dbus is not set
# CONFIG_PACKAGE_dbus-utils is not set
# CONFIG_PACKAGE_device-observatory is not set
# CONFIG_PACKAGE_dfu-util is not set
# CONFIG_PACKAGE_digitemp is not set
# CONFIG_PACKAGE_digitemp-usb is not set
# CONFIG_PACKAGE_dmesg is not set
# CONFIG_PACKAGE_domoticz is not set
# CONFIG_PACKAGE_dropbearconvert is not set
# CONFIG_PACKAGE_dtc is not set
# CONFIG_PACKAGE_dump1090 is not set
# CONFIG_PACKAGE_ecdsautils is not set
# CONFIG_PACKAGE_elektra-kdb is not set
# CONFIG_PACKAGE_evtest is not set
# CONFIG_PACKAGE_extract is not set
# CONFIG_PACKAGE_fdt-utils is not set
# CONFIG_PACKAGE_file is not set
# CONFIG_PACKAGE_findutils is not set
# CONFIG_PACKAGE_findutils-find is not set
# CONFIG_PACKAGE_findutils-locate is not set
# CONFIG_PACKAGE_findutils-xargs is not set
# CONFIG_PACKAGE_flashrom is not set
# CONFIG_PACKAGE_flashrom-pci is not set
# CONFIG_PACKAGE_flashrom-spi is not set
# CONFIG_PACKAGE_flashrom-usb is not set
# CONFIG_PACKAGE_flent-tools is not set
# CONFIG_PACKAGE_flock is not set
# CONFIG_PACKAGE_fritz-caldata is not set
# CONFIG_PACKAGE_fritz-tffs is not set
# CONFIG_PACKAGE_fritz-tffs-nand is not set
# CONFIG_PACKAGE_ftdi_eeprom is not set
# CONFIG_PACKAGE_gammu is not set
# CONFIG_PACKAGE_gawk is not set
# CONFIG_PACKAGE_gddrescue is not set
# CONFIG_PACKAGE_getopt is not set
# CONFIG_PACKAGE_giflib-utils is not set
# CONFIG_PACKAGE_gkermit is not set
# CONFIG_PACKAGE_gnuplot is not set
# CONFIG_PACKAGE_gpioctl-sysfs is not set
# CONFIG_PACKAGE_gpiod-tools is not set
# CONFIG_PACKAGE_gpsd is not set
# CONFIG_PACKAGE_gpsd-clients is not set
# CONFIG_PACKAGE_grep is not set
# CONFIG_PACKAGE_hamlib is not set
# CONFIG_PACKAGE_haserl is not set
# CONFIG_PACKAGE_hashdeep is not set
# CONFIG_PACKAGE_haveged is not set
# CONFIG_PACKAGE_hplip-common is not set
# CONFIG_PACKAGE_hplip-sane is not set
# CONFIG_PACKAGE_hub-ctrl is not set
# CONFIG_PACKAGE_hwclock is not set
# CONFIG_PACKAGE_hwinfo is not set
# CONFIG_PACKAGE_hwloc-utils is not set
# CONFIG_PACKAGE_i2c-tools is not set
# CONFIG_PACKAGE_iconv is not set
# CONFIG_PACKAGE_iio-utils is not set
# CONFIG_PACKAGE_inotifywait is not set
# CONFIG_PACKAGE_inotifywatch is not set
# CONFIG_PACKAGE_io is not set
# CONFIG_PACKAGE_ipfs-http-client-tests is not set
# CONFIG_PACKAGE_irqbalance is not set
# CONFIG_PACKAGE_iwcap is not set
CONFIG_PACKAGE_iwinfo=y
# CONFIG_PACKAGE_jq is not set
CONFIG_PACKAGE_jshn=y
# CONFIG_PACKAGE_kmod is not set
# CONFIG_PACKAGE_lcd4linux-custom is not set
# CONFIG_PACKAGE_lcdproc-clients is not set
# CONFIG_PACKAGE_lcdproc-drivers is not set
# CONFIG_PACKAGE_lcdproc-server is not set
# CONFIG_PACKAGE_less is not set
# CONFIG_PACKAGE_less-wide is not set
CONFIG_PACKAGE_libjson-script=y
# CONFIG_PACKAGE_libxml2-utils is not set
# CONFIG_PACKAGE_lm-sensors is not set
# CONFIG_PACKAGE_lm-sensors-detect is not set
# CONFIG_PACKAGE_logger is not set
# CONFIG_PACKAGE_logrotate is not set
# CONFIG_PACKAGE_look is not set
# CONFIG_PACKAGE_losetup is not set
# CONFIG_PACKAGE_lrzsz is not set
# CONFIG_PACKAGE_lscpu is not set
# CONFIG_PACKAGE_lsof is not set
# CONFIG_PACKAGE_lxc is not set
# CONFIG_PACKAGE_maccalc is not set
# CONFIG_PACKAGE_macchanger is not set
# CONFIG_PACKAGE_mbedtls-util is not set
# CONFIG_PACKAGE_mbim-utils is not set
# CONFIG_PACKAGE_mbtools is not set
# CONFIG_PACKAGE_mc is not set
# CONFIG_PACKAGE_mcookie is not set
# CONFIG_PACKAGE_micrond is not set
# CONFIG_PACKAGE_mmc-utils is not set
# CONFIG_PACKAGE_more is not set
# CONFIG_PACKAGE_moreutils is not set
# CONFIG_PACKAGE_mosh-client is not set
# CONFIG_PACKAGE_mosh-server is not set
# CONFIG_PACKAGE_mount-utils is not set
# CONFIG_PACKAGE_mpack is not set
# CONFIG_PACKAGE_mt-st is not set
# CONFIG_PACKAGE_namei is not set
# CONFIG_PACKAGE_nand-utils is not set
# CONFIG_PACKAGE_netopeer2-cli is not set
# CONFIG_PACKAGE_netopeer2-keystored is not set
# CONFIG_PACKAGE_netopeer2-server is not set
# CONFIG_PACKAGE_netwhere is not set
# CONFIG_PACKAGE_nnn is not set
# CONFIG_PACKAGE_nsenter is not set
# CONFIG_PACKAGE_nss-utils is not set
# CONFIG_PACKAGE_oath-toolkit is not set
# CONFIG_PACKAGE_open-plc-utils is not set
# CONFIG_PACKAGE_open2300 is not set
# CONFIG_PACKAGE_openobex is not set
# CONFIG_PACKAGE_openobex-apps is not set
# CONFIG_PACKAGE_openocd is not set
# CONFIG_PACKAGE_opensc-utils is not set
CONFIG_PACKAGE_openssl-util=y
# CONFIG_PACKAGE_openzwave is not set
# CONFIG_PACKAGE_openzwave-config is not set
# CONFIG_PACKAGE_owipcalc is not set
# CONFIG_PACKAGE_pciutils is not set
# CONFIG_PACKAGE_pcsc-tools is not set
# CONFIG_PACKAGE_pcscd is not set
# CONFIG_PACKAGE_powertop is not set
# CONFIG_PACKAGE_pps-tools is not set
# CONFIG_PACKAGE_prlimit is not set
# CONFIG_PACKAGE_procps-ng is not set
# CONFIG_PACKAGE_progress is not set
# CONFIG_PACKAGE_prometheus is not set
# CONFIG_PACKAGE_prometheus-node-exporter-lua is not set
# CONFIG_PACKAGE_prometheus-statsd-exporter is not set
# CONFIG_PACKAGE_pservice is not set
# CONFIG_PACKAGE_pv is not set
# CONFIG_PACKAGE_qmi-utils is not set
# CONFIG_PACKAGE_qrencode is not set
# CONFIG_PACKAGE_quota is not set
# CONFIG_PACKAGE_ravpower-mcu is not set
# CONFIG_PACKAGE_rclone is not set
# CONFIG_PACKAGE_readsb is not set
# CONFIG_PACKAGE_relayctl is not set
# CONFIG_PACKAGE_rename is not set
# CONFIG_PACKAGE_restic is not set
# CONFIG_PACKAGE_rng-tools is not set
# CONFIG_PACKAGE_rtl-ais is not set
# CONFIG_PACKAGE_rtl-sdr is not set
# CONFIG_PACKAGE_rtl_433 is not set
# CONFIG_PACKAGE_sane-backends is not set
# CONFIG_PACKAGE_sane-daemon is not set
# CONFIG_PACKAGE_sane-frontends is not set
# CONFIG_PACKAGE_sed is not set
# CONFIG_PACKAGE_serdisplib-tools is not set
# CONFIG_PACKAGE_setserial is not set
# CONFIG_PACKAGE_shadow-utils is not set
CONFIG_PACKAGE_shellsync=y
# CONFIG_PACKAGE_sispmctl is not set
# CONFIG_PACKAGE_slide-switch is not set
# CONFIG_PACKAGE_smartd is not set
# CONFIG_PACKAGE_smartd-mail is not set
# CONFIG_PACKAGE_smartmontools is not set
# CONFIG_PACKAGE_smartmontools-drivedb is not set
# CONFIG_PACKAGE_smstools3 is not set
# CONFIG_PACKAGE_sockread is not set
# CONFIG_PACKAGE_spi-tools is not set
# CONFIG_PACKAGE_spidev-test is not set
# CONFIG_PACKAGE_ssdeep is not set
# CONFIG_PACKAGE_sshpass is not set
# CONFIG_PACKAGE_strace is not set
CONFIG_STRACE_NONE=y
# CONFIG_STRACE_LIBDW is not set
# CONFIG_STRACE_LIBUNWIND is not set
# CONFIG_PACKAGE_stress is not set
# CONFIG_PACKAGE_sumo is not set
# CONFIG_PACKAGE_syncthing is not set
# CONFIG_PACKAGE_sysrepo is not set
# CONFIG_PACKAGE_sysrepocfg is not set
# CONFIG_PACKAGE_sysrepoctl is not set
# CONFIG_PACKAGE_sysstat is not set
# CONFIG_PACKAGE_tar is not set
# CONFIG_PACKAGE_taskwarrior is not set
# CONFIG_PACKAGE_telldus-core is not set
# CONFIG_PACKAGE_temperusb is not set
# CONFIG_PACKAGE_tesseract is not set
# CONFIG_PACKAGE_tini is not set
# CONFIG_PACKAGE_tracertools is not set
# CONFIG_PACKAGE_tree is not set
# CONFIG_PACKAGE_triggerhappy is not set
CONFIG_PACKAGE_ubi-utils=y
# CONFIG_PACKAGE_udns-dnsget is not set
# CONFIG_PACKAGE_udns-ex-rdns is not set
# CONFIG_PACKAGE_udns-rblcheck is not set
# CONFIG_PACKAGE_ugps is not set
# CONFIG_PACKAGE_uledd is not set
# CONFIG_PACKAGE_unshare is not set
# CONFIG_PACKAGE_usb-modeswitch is not set
# CONFIG_PACKAGE_usbreset is not set
# CONFIG_PACKAGE_usbutils is not set
# CONFIG_PACKAGE_uuidd is not set
# CONFIG_PACKAGE_uuidgen is not set
# CONFIG_PACKAGE_uvcdynctrl is not set
# CONFIG_PACKAGE_v4l-utils is not set
# CONFIG_PACKAGE_view1090 is not set
# CONFIG_PACKAGE_viewadsb is not set
# CONFIG_PACKAGE_watchcat is not set
# CONFIG_PACKAGE_whereis is not set
# CONFIG_PACKAGE_which is not set
# CONFIG_PACKAGE_whiptail is not set
# CONFIG_PACKAGE_wifitoggle is not set
# CONFIG_PACKAGE_wipe is not set
# CONFIG_PACKAGE_xsltproc is not set
# CONFIG_PACKAGE_xxd is not set
# CONFIG_PACKAGE_yanglint is not set
# CONFIG_PACKAGE_yara is not set
# CONFIG_PACKAGE_ykclient is not set
# CONFIG_PACKAGE_ykpers is not set
# end of Utilities
#
# Xorg
#
#
# Font-Utils
#
# CONFIG_PACKAGE_fontconfig is not set
# end of Font-Utils
# end of Xorg
CONFIG_OVERRIDE_PKGS="smartdns"
|
6711a56247cd8726f903cdfc198584744fa797cf | 8e2026ac8a0660b5a490dfb895599fb445bb77a0 | /tests/lean/run/record10.lean | bd97747ef01036e1e635de3bb3ec354f0137f02c | [
"Apache-2.0"
] | permissive | pcmoritz/lean | 6a8575115a724af933678d829b4f791a0cb55beb | 35eba0107e4cc8a52778259bb5392300267bfc29 | refs/heads/master | 1,607,896,326,092 | 1,490,752,175,000 | 1,490,752,175,000 | 86,612,290 | 0 | 0 | null | 1,490,809,641,000 | 1,490,809,641,000 | null | UTF-8 | Lean | false | false | 452 | lean | #print prefix semigroup
#print "======================="
structure [class] has_two_muls (A : Type) extends has_mul A renaming mul→mul1,
private has_mul A renaming mul→mul2
#print prefix has_two_muls
#print "======================="
structure [class] another_two_muls (A : Type) extends has_mul A renaming mul→mul1,
has_mul A renaming mul→mul2
|
23f2dcf2fa1ecd518fdbef6ed5bcc4c78cf07ff3 | 206422fb9edabf63def0ed2aa3f489150fb09ccb | /src/data/list/basic.lean | 92706a397bd83cc53b74b07c69e7c8ae2436fff1 | [
"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 | 187,119 | 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
-/
import algebra.order_functions
import control.monad.basic
import data.nat.choose.basic
import order.rel_classes
/-!
# Basic properties of lists
-/
open function nat
namespace list
universes u v w x
variables {α : Type u} {β : Type v} {γ : Type w} {δ : Type x}
attribute [inline] list.head
instance : is_left_id (list α) has_append.append [] :=
⟨ nil_append ⟩
instance : is_right_id (list α) has_append.append [] :=
⟨ append_nil ⟩
instance : is_associative (list α) has_append.append :=
⟨ append_assoc ⟩
theorem cons_ne_nil (a : α) (l : list α) : a::l ≠ [].
theorem cons_ne_self (a : α) (l : list α) : a::l ≠ l :=
mt (congr_arg length) (nat.succ_ne_self _)
theorem head_eq_of_cons_eq {h₁ h₂ : α} {t₁ t₂ : list α} :
(h₁::t₁) = (h₂::t₂) → h₁ = h₂ :=
assume Peq, list.no_confusion Peq (assume Pheq Pteq, Pheq)
theorem tail_eq_of_cons_eq {h₁ h₂ : α} {t₁ t₂ : list α} :
(h₁::t₁) = (h₂::t₂) → t₁ = t₂ :=
assume Peq, list.no_confusion Peq (assume Pheq Pteq, Pteq)
@[simp] theorem cons_injective {a : α} : injective (cons a) :=
assume l₁ l₂, assume Pe, tail_eq_of_cons_eq Pe
theorem cons_inj (a : α) {l l' : list α} : a::l = a::l' ↔ l = l' :=
cons_injective.eq_iff
theorem exists_cons_of_ne_nil {l : list α} (h : l ≠ nil) : ∃ b L, l = b :: L :=
by { induction l with c l', contradiction, use [c,l'], }
/-! ### mem -/
theorem mem_singleton_self (a : α) : a ∈ [a] := mem_cons_self _ _
theorem eq_of_mem_singleton {a b : α} : a ∈ [b] → a = b :=
assume : a ∈ [b], or.elim (eq_or_mem_of_mem_cons this)
(assume : a = b, this)
(assume : a ∈ [], absurd this (not_mem_nil a))
@[simp] theorem mem_singleton {a b : α} : a ∈ [b] ↔ a = b :=
⟨eq_of_mem_singleton, or.inl⟩
theorem mem_of_mem_cons_of_mem {a b : α} {l : list α} : a ∈ b::l → b ∈ l → a ∈ l :=
assume ainbl binl, or.elim (eq_or_mem_of_mem_cons ainbl)
(assume : a = b, begin subst a, exact binl end)
(assume : a ∈ l, this)
theorem eq_or_ne_mem_of_mem {a b : α} {l : list α} (h : a ∈ b :: l) : a = b ∨ (a ≠ b ∧ a ∈ l) :=
classical.by_cases or.inl $ assume : a ≠ b, h.elim or.inl $ assume h, or.inr ⟨this, h⟩
theorem not_mem_append {a : α} {s t : list α} (h₁ : a ∉ s) (h₂ : a ∉ t) : a ∉ s ++ t :=
mt mem_append.1 $ not_or_distrib.2 ⟨h₁, h₂⟩
theorem ne_nil_of_mem {a : α} {l : list α} (h : a ∈ l) : l ≠ [] :=
by intro e; rw e at h; cases h
theorem mem_split {a : α} {l : list α} (h : a ∈ l) : ∃ s t : list α, l = s ++ a :: t :=
begin
induction l with b l ih, {cases h}, rcases h with rfl | h,
{ exact ⟨[], l, rfl⟩ },
{ rcases ih h with ⟨s, t, rfl⟩,
exact ⟨b::s, t, rfl⟩ }
end
theorem mem_of_ne_of_mem {a y : α} {l : list α} (h₁ : a ≠ y) (h₂ : a ∈ y :: l) : a ∈ l :=
or.elim (eq_or_mem_of_mem_cons h₂) (λe, absurd e h₁) (λr, r)
theorem ne_of_not_mem_cons {a b : α} {l : list α} : a ∉ b::l → a ≠ b :=
assume nin aeqb, absurd (or.inl aeqb) nin
theorem not_mem_of_not_mem_cons {a b : α} {l : list α} : a ∉ b::l → a ∉ l :=
assume nin nainl, absurd (or.inr nainl) nin
theorem not_mem_cons_of_ne_of_not_mem {a y : α} {l : list α} : a ≠ y → a ∉ l → a ∉ y::l :=
assume p1 p2, not.intro (assume Pain, absurd (eq_or_mem_of_mem_cons Pain) (not_or p1 p2))
theorem ne_and_not_mem_of_not_mem_cons {a y : α} {l : list α} : a ∉ y::l → a ≠ y ∧ a ∉ l :=
assume p, and.intro (ne_of_not_mem_cons p) (not_mem_of_not_mem_cons p)
theorem mem_map_of_mem (f : α → β) {a : α} {l : list α} (h : a ∈ l) : f a ∈ map f l :=
begin
induction l with b l' ih,
{cases h},
{rcases h with rfl | h,
{exact or.inl rfl},
{exact or.inr (ih h)}}
end
theorem exists_of_mem_map {f : α → β} {b : β} {l : list α} (h : b ∈ map f l) :
∃ a, a ∈ l ∧ f a = b :=
begin
induction l with c l' ih,
{cases h},
{cases (eq_or_mem_of_mem_cons h) with h h,
{exact ⟨c, mem_cons_self _ _, h.symm⟩},
{rcases ih h with ⟨a, ha₁, ha₂⟩,
exact ⟨a, mem_cons_of_mem _ ha₁, ha₂⟩ }}
end
@[simp] theorem mem_map {f : α → β} {b : β} {l : list α} : b ∈ map f l ↔ ∃ a, a ∈ l ∧ f a = b :=
⟨exists_of_mem_map, λ ⟨a, la, h⟩, by rw [← h]; exact mem_map_of_mem f la⟩
theorem mem_map_of_injective {f : α → β} (H : injective f) {a : α} {l : list α} :
f a ∈ map f l ↔ a ∈ l :=
⟨λ m, let ⟨a', m', e⟩ := exists_of_mem_map m in H e ▸ m', mem_map_of_mem _⟩
lemma forall_mem_map_iff {f : α → β} {l : list α} {P : β → Prop} :
(∀ i ∈ l.map f, P i) ↔ ∀ j ∈ l, P (f j) :=
begin
split,
{ assume H j hj,
exact H (f j) (mem_map_of_mem f hj) },
{ assume H i hi,
rcases mem_map.1 hi with ⟨j, hj, ji⟩,
rw ← ji,
exact H j hj }
end
@[simp] lemma map_eq_nil {f : α → β} {l : list α} : list.map f l = [] ↔ l = [] :=
⟨by cases l; simp only [forall_prop_of_true, map, forall_prop_of_false, not_false_iff],
λ h, h.symm ▸ rfl⟩
@[simp] theorem mem_join {a : α} : ∀ {L : list (list α)}, a ∈ join L ↔ ∃ l, l ∈ L ∧ a ∈ l
| [] := ⟨false.elim, λ⟨_, h, _⟩, false.elim h⟩
| (c :: L) := by simp only [join, mem_append, @mem_join L, mem_cons_iff, or_and_distrib_right,
exists_or_distrib, exists_eq_left]
theorem exists_of_mem_join {a : α} {L : list (list α)} : a ∈ join L → ∃ l, l ∈ L ∧ a ∈ l :=
mem_join.1
theorem mem_join_of_mem {a : α} {L : list (list α)} {l} (lL : l ∈ L) (al : a ∈ l) : a ∈ join L :=
mem_join.2 ⟨l, lL, al⟩
@[simp]
theorem mem_bind {b : β} {l : list α} {f : α → list β} : b ∈ list.bind l f ↔ ∃ a ∈ l, b ∈ f a :=
iff.trans mem_join
⟨λ ⟨l', h1, h2⟩, let ⟨a, al, fa⟩ := exists_of_mem_map h1 in ⟨a, al, fa.symm ▸ h2⟩,
λ ⟨a, al, bfa⟩, ⟨f a, mem_map_of_mem _ al, bfa⟩⟩
theorem exists_of_mem_bind {b : β} {l : list α} {f : α → list β} :
b ∈ list.bind l f → ∃ a ∈ l, b ∈ f a :=
mem_bind.1
theorem mem_bind_of_mem {b : β} {l : list α} {f : α → list β} {a} (al : a ∈ l) (h : b ∈ f a) :
b ∈ list.bind l f :=
mem_bind.2 ⟨a, al, h⟩
lemma bind_map {g : α → list β} {f : β → γ} :
∀(l : list α), list.map f (l.bind g) = l.bind (λa, (g a).map f)
| [] := rfl
| (a::l) := by simp only [cons_bind, map_append, bind_map l]
/-! ### length -/
theorem length_eq_zero {l : list α} : length l = 0 ↔ l = [] :=
⟨eq_nil_of_length_eq_zero, λ h, h.symm ▸ rfl⟩
@[simp] lemma length_singleton (a : α) : length [a] = 1 := rfl
theorem length_pos_of_mem {a : α} : ∀ {l : list α}, a ∈ l → 0 < length l
| (b::l) _ := zero_lt_succ _
theorem exists_mem_of_length_pos : ∀ {l : list α}, 0 < length l → ∃ a, a ∈ l
| (b::l) _ := ⟨b, mem_cons_self _ _⟩
theorem length_pos_iff_exists_mem {l : list α} : 0 < length l ↔ ∃ a, a ∈ l :=
⟨exists_mem_of_length_pos, λ ⟨a, h⟩, length_pos_of_mem h⟩
theorem ne_nil_of_length_pos {l : list α} : 0 < length l → l ≠ [] :=
λ h1 h2, lt_irrefl 0 ((length_eq_zero.2 h2).subst h1)
theorem length_pos_of_ne_nil {l : list α} : l ≠ [] → 0 < length l :=
λ h, pos_iff_ne_zero.2 $ λ h0, h $ length_eq_zero.1 h0
theorem length_pos_iff_ne_nil {l : list α} : 0 < length l ↔ l ≠ [] :=
⟨ne_nil_of_length_pos, length_pos_of_ne_nil⟩
theorem length_eq_one {l : list α} : length l = 1 ↔ ∃ a, l = [a] :=
⟨match l with [a], _ := ⟨a, rfl⟩ end, λ ⟨a, e⟩, e.symm ▸ rfl⟩
lemma exists_of_length_succ {n} :
∀ l : list α, l.length = n + 1 → ∃ h t, l = h :: t
| [] H := absurd H.symm $ succ_ne_zero n
| (h :: t) H := ⟨h, t, rfl⟩
@[simp] lemma length_injective_iff : injective (list.length : list α → ℕ) ↔ subsingleton α :=
begin
split,
{ intro h, refine ⟨λ x y, _⟩, suffices : [x] = [y], { simpa using this }, apply h, refl },
{ intros hα l1 l2 hl, induction l1 generalizing l2; cases l2,
{ refl }, { cases hl }, { cases hl },
congr, exactI subsingleton.elim _ _, apply l1_ih, simpa using hl }
end
@[simp] lemma length_injective [subsingleton α] : injective (length : list α → ℕ) :=
length_injective_iff.mpr $ by apply_instance
/-! ### set-theoretic notation of lists -/
lemma empty_eq : (∅ : list α) = [] := by refl
lemma singleton_eq (x : α) : ({x} : list α) = [x] := rfl
lemma insert_neg [decidable_eq α] {x : α} {l : list α} (h : x ∉ l) :
has_insert.insert x l = x :: l :=
if_neg h
lemma insert_pos [decidable_eq α] {x : α} {l : list α} (h : x ∈ l) :
has_insert.insert x l = l :=
if_pos h
lemma doubleton_eq [decidable_eq α] {x y : α} (h : x ≠ y) : ({x, y} : list α) = [x, y] :=
by { rw [insert_neg, singleton_eq], rwa [singleton_eq, mem_singleton] }
/-! ### bounded quantifiers over lists -/
theorem forall_mem_nil (p : α → Prop) : ∀ x ∈ @nil α, p x.
theorem forall_mem_cons : ∀ {p : α → Prop} {a : α} {l : list α},
(∀ x ∈ a :: l, p x) ↔ p a ∧ ∀ x ∈ l, p x :=
ball_cons
theorem forall_mem_of_forall_mem_cons {p : α → Prop} {a : α} {l : list α}
(h : ∀ x ∈ a :: l, p x) :
∀ x ∈ l, p x :=
(forall_mem_cons.1 h).2
theorem forall_mem_singleton {p : α → Prop} {a : α} : (∀ x ∈ [a], p x) ↔ p a :=
by simp only [mem_singleton, forall_eq]
theorem forall_mem_append {p : α → Prop} {l₁ l₂ : list α} :
(∀ x ∈ l₁ ++ l₂, p x) ↔ (∀ x ∈ l₁, p x) ∧ (∀ x ∈ l₂, p x) :=
by simp only [mem_append, or_imp_distrib, forall_and_distrib]
theorem not_exists_mem_nil (p : α → Prop) : ¬ ∃ x ∈ @nil α, p x.
theorem exists_mem_cons_of {p : α → Prop} {a : α} (l : list α) (h : p a) :
∃ x ∈ a :: l, p x :=
bex.intro a (mem_cons_self _ _) h
theorem exists_mem_cons_of_exists {p : α → Prop} {a : α} {l : list α} (h : ∃ x ∈ l, p x) :
∃ x ∈ a :: l, p x :=
bex.elim h (λ x xl px, bex.intro x (mem_cons_of_mem _ xl) px)
theorem or_exists_of_exists_mem_cons {p : α → Prop} {a : α} {l : list α} (h : ∃ x ∈ a :: l, p x) :
p a ∨ ∃ x ∈ l, p x :=
bex.elim h (λ x xal px,
or.elim (eq_or_mem_of_mem_cons xal)
(assume : x = a, begin rw ←this, left, exact px end)
(assume : x ∈ l, or.inr (bex.intro x this px)))
theorem exists_mem_cons_iff (p : α → Prop) (a : α) (l : list α) :
(∃ x ∈ a :: l, p x) ↔ p a ∨ ∃ x ∈ l, p x :=
iff.intro or_exists_of_exists_mem_cons
(assume h, or.elim h (exists_mem_cons_of l) exists_mem_cons_of_exists)
/-! ### list subset -/
theorem subset_def {l₁ l₂ : list α} : l₁ ⊆ l₂ ↔ ∀ ⦃a : α⦄, a ∈ l₁ → a ∈ l₂ := iff.rfl
theorem subset_append_of_subset_left (l l₁ l₂ : list α) : l ⊆ l₁ → l ⊆ l₁++l₂ :=
λ s, subset.trans s $ subset_append_left _ _
theorem subset_append_of_subset_right (l l₁ l₂ : list α) : l ⊆ l₂ → l ⊆ l₁++l₂ :=
λ s, subset.trans s $ subset_append_right _ _
@[simp] theorem cons_subset {a : α} {l m : list α} :
a::l ⊆ m ↔ a ∈ m ∧ l ⊆ m :=
by simp only [subset_def, mem_cons_iff, or_imp_distrib, forall_and_distrib, forall_eq]
theorem cons_subset_of_subset_of_mem {a : α} {l m : list α}
(ainm : a ∈ m) (lsubm : l ⊆ m) : a::l ⊆ m :=
cons_subset.2 ⟨ainm, lsubm⟩
theorem append_subset_of_subset_of_subset {l₁ l₂ l : list α} (l₁subl : l₁ ⊆ l) (l₂subl : l₂ ⊆ l) :
l₁ ++ l₂ ⊆ l :=
λ a h, (mem_append.1 h).elim (@l₁subl _) (@l₂subl _)
@[simp] theorem append_subset_iff {l₁ l₂ l : list α} :
l₁ ++ l₂ ⊆ l ↔ l₁ ⊆ l ∧ l₂ ⊆ l :=
begin
split,
{ intro h, simp only [subset_def] at *, split; intros; simp* },
{ rintro ⟨h1, h2⟩, apply append_subset_of_subset_of_subset h1 h2 }
end
theorem eq_nil_of_subset_nil : ∀ {l : list α}, l ⊆ [] → l = []
| [] s := rfl
| (a::l) s := false.elim $ s $ mem_cons_self a l
theorem eq_nil_iff_forall_not_mem {l : list α} : l = [] ↔ ∀ a, a ∉ l :=
show l = [] ↔ l ⊆ [], from ⟨λ e, e ▸ subset.refl _, eq_nil_of_subset_nil⟩
theorem map_subset {l₁ l₂ : list α} (f : α → β) (H : l₁ ⊆ l₂) : map f l₁ ⊆ map f l₂ :=
λ x, by simp only [mem_map, not_and, exists_imp_distrib, and_imp]; exact λ a h e, ⟨a, H h, e⟩
theorem map_subset_iff {l₁ l₂ : list α} (f : α → β) (h : injective f) :
map f l₁ ⊆ map f l₂ ↔ l₁ ⊆ l₂ :=
begin
refine ⟨_, map_subset f⟩, intros h2 x hx,
rcases mem_map.1 (h2 (mem_map_of_mem f hx)) with ⟨x', hx', hxx'⟩,
cases h hxx', exact hx'
end
/-! ### append -/
lemma append_eq_has_append {L₁ L₂ : list α} : list.append L₁ L₂ = L₁ ++ L₂ := rfl
@[simp] lemma singleton_append {x : α} {l : list α} : [x] ++ l = x :: l := rfl
theorem append_ne_nil_of_ne_nil_left (s t : list α) : s ≠ [] → s ++ t ≠ [] :=
by induction s; intros; contradiction
theorem append_ne_nil_of_ne_nil_right (s t : list α) : t ≠ [] → s ++ t ≠ [] :=
by induction s; intros; contradiction
@[simp] lemma append_eq_nil {p q : list α} : (p ++ q) = [] ↔ p = [] ∧ q = [] :=
by cases p; simp only [nil_append, cons_append, eq_self_iff_true, true_and, false_and]
@[simp] lemma nil_eq_append_iff {a b : list α} : [] = a ++ b ↔ a = [] ∧ b = [] :=
by rw [eq_comm, append_eq_nil]
lemma append_eq_cons_iff {a b c : list α} {x : α} :
a ++ b = x :: c ↔ (a = [] ∧ b = x :: c) ∨ (∃a', a = x :: a' ∧ c = a' ++ b) :=
by cases a; simp only [and_assoc, @eq_comm _ c, nil_append, cons_append, eq_self_iff_true,
true_and, false_and, exists_false, false_or, or_false, exists_and_distrib_left, exists_eq_left']
lemma cons_eq_append_iff {a b c : list α} {x : α} :
(x :: c : list α) = a ++ b ↔ (a = [] ∧ b = x :: c) ∨ (∃a', a = x :: a' ∧ c = a' ++ b) :=
by rw [eq_comm, append_eq_cons_iff]
lemma append_eq_append_iff {a b c d : list α} :
a ++ b = c ++ d ↔ (∃a', c = a ++ a' ∧ b = a' ++ d) ∨ (∃c', a = c ++ c' ∧ d = c' ++ b) :=
begin
induction a generalizing c,
case nil { rw nil_append, split,
{ rintro rfl, left, exact ⟨_, rfl, rfl⟩ },
{ rintro (⟨a', rfl, rfl⟩ | ⟨a', H, rfl⟩), {refl}, {rw [← append_assoc, ← H], refl} } },
case cons : a as ih {
cases c,
{ simp only [cons_append, nil_append, false_and, exists_false, false_or, exists_eq_left'],
exact eq_comm },
{ simp only [cons_append, @eq_comm _ a, ih, and_assoc, and_or_distrib_left,
exists_and_distrib_left] } }
end
@[simp] theorem split_at_eq_take_drop : ∀ (n : ℕ) (l : list α), split_at n l = (take n l, drop n l)
| 0 a := rfl
| (succ n) [] := rfl
| (succ n) (x :: xs) := by simp only [split_at, split_at_eq_take_drop n xs, take, drop]
@[simp] theorem take_append_drop : ∀ (n : ℕ) (l : list α), take n l ++ drop n l = l
| 0 a := rfl
| (succ n) [] := rfl
| (succ n) (x :: xs) := congr_arg (cons x) $ take_append_drop n xs
-- TODO(Leo): cleanup proof after arith dec proc
theorem append_inj :
∀ {s₁ s₂ t₁ t₂ : list α}, s₁ ++ t₁ = s₂ ++ t₂ → length s₁ = length s₂ → s₁ = s₂ ∧ t₁ = t₂
| [] [] t₁ t₂ h hl := ⟨rfl, h⟩
| (a::s₁) [] t₁ t₂ h hl := list.no_confusion $ eq_nil_of_length_eq_zero hl
| [] (b::s₂) t₁ t₂ h hl := list.no_confusion $ eq_nil_of_length_eq_zero hl.symm
| (a::s₁) (b::s₂) t₁ t₂ h hl := list.no_confusion h $ λab hap,
let ⟨e1, e2⟩ := @append_inj s₁ s₂ t₁ t₂ hap (succ.inj hl) in
by rw [ab, e1, e2]; exact ⟨rfl, rfl⟩
theorem append_inj_right {s₁ s₂ t₁ t₂ : list α} (h : s₁ ++ t₁ = s₂ ++ t₂)
(hl : length s₁ = length s₂) : t₁ = t₂ :=
(append_inj h hl).right
theorem append_inj_left {s₁ s₂ t₁ t₂ : list α} (h : s₁ ++ t₁ = s₂ ++ t₂)
(hl : length s₁ = length s₂) : s₁ = s₂ :=
(append_inj h hl).left
theorem append_inj' {s₁ s₂ t₁ t₂ : list α} (h : s₁ ++ t₁ = s₂ ++ t₂) (hl : length t₁ = length t₂) :
s₁ = s₂ ∧ t₁ = t₂ :=
append_inj h $ @nat.add_right_cancel _ (length t₁) _ $
let hap := congr_arg length h in by simp only [length_append] at hap; rwa [← hl] at hap
theorem append_inj_right' {s₁ s₂ t₁ t₂ : list α} (h : s₁ ++ t₁ = s₂ ++ t₂)
(hl : length t₁ = length t₂) : t₁ = t₂ :=
(append_inj' h hl).right
theorem append_inj_left' {s₁ s₂ t₁ t₂ : list α} (h : s₁ ++ t₁ = s₂ ++ t₂)
(hl : length t₁ = length t₂) : s₁ = s₂ :=
(append_inj' h hl).left
theorem append_left_cancel {s t₁ t₂ : list α} (h : s ++ t₁ = s ++ t₂) : t₁ = t₂ :=
append_inj_right h rfl
theorem append_right_cancel {s₁ s₂ t : list α} (h : s₁ ++ t = s₂ ++ t) : s₁ = s₂ :=
append_inj_left' h rfl
theorem append_right_injective (s : list α) : function.injective (λ t, s ++ t) :=
λ t₁ t₂, append_left_cancel
theorem append_right_inj {t₁ t₂ : list α} (s) : s ++ t₁ = s ++ t₂ ↔ t₁ = t₂ :=
(append_right_injective s).eq_iff
theorem append_left_injective (t : list α) : function.injective (λ s, s ++ t) :=
λ s₁ s₂, append_right_cancel
theorem append_left_inj {s₁ s₂ : list α} (t) : s₁ ++ t = s₂ ++ t ↔ s₁ = s₂ :=
(append_left_injective t).eq_iff
theorem map_eq_append_split {f : α → β} {l : list α} {s₁ s₂ : list β}
(h : map f l = s₁ ++ s₂) : ∃ l₁ l₂, l = l₁ ++ l₂ ∧ map f l₁ = s₁ ∧ map f l₂ = s₂ :=
begin
have := h, rw [← take_append_drop (length s₁) l] at this ⊢,
rw map_append at this,
refine ⟨_, _, rfl, append_inj this _⟩,
rw [length_map, length_take, min_eq_left],
rw [← length_map f l, h, length_append],
apply nat.le_add_right
end
/-! ### repeat -/
@[simp] theorem repeat_succ (a : α) (n) : repeat a (n + 1) = a :: repeat a n := rfl
theorem eq_of_mem_repeat {a b : α} : ∀ {n}, b ∈ repeat a n → b = a
| (n+1) h := or.elim h id $ @eq_of_mem_repeat _
theorem eq_repeat_of_mem {a : α} : ∀ {l : list α}, (∀ b ∈ l, b = a) → l = repeat a l.length
| [] H := rfl
| (b::l) H := by cases forall_mem_cons.1 H with H₁ H₂;
unfold length repeat; congr; [exact H₁, exact eq_repeat_of_mem H₂]
theorem eq_repeat' {a : α} {l : list α} : l = repeat a l.length ↔ ∀ b ∈ l, b = a :=
⟨λ h, h.symm ▸ λ b, eq_of_mem_repeat, eq_repeat_of_mem⟩
theorem eq_repeat {a : α} {n} {l : list α} : l = repeat a n ↔ length l = n ∧ ∀ b ∈ l, b = a :=
⟨λ h, h.symm ▸ ⟨length_repeat _ _, λ b, eq_of_mem_repeat⟩,
λ ⟨e, al⟩, e ▸ eq_repeat_of_mem al⟩
theorem repeat_add (a : α) (m n) : repeat a (m + n) = repeat a m ++ repeat a n :=
by induction m; simp only [*, zero_add, succ_add, repeat]; split; refl
theorem repeat_subset_singleton (a : α) (n) : repeat a n ⊆ [a] :=
λ b h, mem_singleton.2 (eq_of_mem_repeat h)
@[simp] theorem map_const (l : list α) (b : β) : map (function.const α b) l = repeat b l.length :=
by induction l; [refl, simp only [*, map]]; split; refl
theorem eq_of_mem_map_const {b₁ b₂ : β} {l : list α} (h : b₁ ∈ map (function.const α b₂) l) :
b₁ = b₂ :=
by rw map_const at h; exact eq_of_mem_repeat h
@[simp] theorem map_repeat (f : α → β) (a : α) (n) : map f (repeat a n) = repeat (f a) n :=
by induction n; [refl, simp only [*, repeat, map]]; split; refl
@[simp] theorem tail_repeat (a : α) (n) : tail (repeat a n) = repeat a n.pred :=
by cases n; refl
@[simp] theorem join_repeat_nil (n : ℕ) : join (repeat [] n) = @nil α :=
by induction n; [refl, simp only [*, repeat, join, append_nil]]
/-! ### pure -/
@[simp] theorem mem_pure {α} (x y : α) :
x ∈ (pure y : list α) ↔ x = y := by simp! [pure,list.ret]
/-! ### bind -/
@[simp] theorem bind_eq_bind {α β} (f : α → list β) (l : list α) :
l >>= f = l.bind f := rfl
@[simp] theorem bind_append (f : α → list β) (l₁ l₂ : list α) :
(l₁ ++ l₂).bind f = l₁.bind f ++ l₂.bind f :=
append_bind _ _ _
@[simp] theorem bind_singleton (f : α → list β) (x : α) : [x].bind f = f x :=
append_nil (f x)
/-! ### concat -/
theorem concat_nil (a : α) : concat [] a = [a] := rfl
theorem concat_cons (a b : α) (l : list α) : concat (a :: l) b = a :: concat l b := rfl
@[simp] theorem concat_eq_append (a : α) (l : list α) : concat l a = l ++ [a] :=
by induction l; simp only [*, concat]; split; refl
theorem init_eq_of_concat_eq {a : α} {l₁ l₂ : list α} : concat l₁ a = concat l₂ a → l₁ = l₂ :=
begin
intro h,
rw [concat_eq_append, concat_eq_append] at h,
exact append_right_cancel h
end
theorem last_eq_of_concat_eq {a b : α} {l : list α} : concat l a = concat l b → a = b :=
begin
intro h,
rw [concat_eq_append, concat_eq_append] at h,
exact head_eq_of_cons_eq (append_left_cancel h)
end
theorem concat_ne_nil (a : α) (l : list α) : concat l a ≠ [] :=
by simp
theorem concat_append (a : α) (l₁ l₂ : list α) : concat l₁ a ++ l₂ = l₁ ++ a :: l₂ :=
by simp
theorem length_concat (a : α) (l : list α) : length (concat l a) = succ (length l) :=
by simp only [concat_eq_append, length_append, length]
theorem append_concat (a : α) (l₁ l₂ : list α) : l₁ ++ concat l₂ a = concat (l₁ ++ l₂) a :=
by simp
/-! ### reverse -/
@[simp] theorem reverse_nil : reverse (@nil α) = [] := rfl
local attribute [simp] reverse_core
@[simp] theorem reverse_cons (a : α) (l : list α) : reverse (a::l) = reverse l ++ [a] :=
have aux : ∀ l₁ l₂, reverse_core l₁ l₂ ++ [a] = reverse_core l₁ (l₂ ++ [a]),
by intro l₁; induction l₁; intros; [refl, simp only [*, reverse_core, cons_append]],
(aux l nil).symm
theorem reverse_core_eq (l₁ l₂ : list α) : reverse_core l₁ l₂ = reverse l₁ ++ l₂ :=
by induction l₁ generalizing l₂; [refl, simp only [*, reverse_core, reverse_cons, append_assoc]];
refl
theorem reverse_cons' (a : α) (l : list α) : reverse (a::l) = concat (reverse l) a :=
by simp only [reverse_cons, concat_eq_append]
@[simp] theorem reverse_singleton (a : α) : reverse [a] = [a] := rfl
@[simp] theorem reverse_append (s t : list α) : reverse (s ++ t) = (reverse t) ++ (reverse s) :=
by induction s; [rw [nil_append, reverse_nil, append_nil],
simp only [*, cons_append, reverse_cons, append_assoc]]
theorem reverse_concat (l : list α) (a : α) : reverse (concat l a) = a :: reverse l :=
by rw [concat_eq_append, reverse_append, reverse_singleton, singleton_append]
@[simp] theorem reverse_reverse (l : list α) : reverse (reverse l) = l :=
by induction l; [refl, simp only [*, reverse_cons, reverse_append]]; refl
@[simp] theorem reverse_involutive : involutive (@reverse α) :=
λ l, reverse_reverse l
@[simp] theorem reverse_injective : injective (@reverse α) :=
reverse_involutive.injective
@[simp] theorem reverse_inj {l₁ l₂ : list α} : reverse l₁ = reverse l₂ ↔ l₁ = l₂ :=
reverse_injective.eq_iff
@[simp] theorem reverse_eq_nil {l : list α} : reverse l = [] ↔ l = [] :=
@reverse_inj _ l []
theorem concat_eq_reverse_cons (a : α) (l : list α) : concat l a = reverse (a :: reverse l) :=
by simp only [concat_eq_append, reverse_cons, reverse_reverse]
@[simp] theorem length_reverse (l : list α) : length (reverse l) = length l :=
by induction l; [refl, simp only [*, reverse_cons, length_append, length]]
@[simp] theorem map_reverse (f : α → β) (l : list α) : map f (reverse l) = reverse (map f l) :=
by induction l; [refl, simp only [*, map, reverse_cons, map_append]]
theorem map_reverse_core (f : α → β) (l₁ l₂ : list α) :
map f (reverse_core l₁ l₂) = reverse_core (map f l₁) (map f l₂) :=
by simp only [reverse_core_eq, map_append, map_reverse]
@[simp] theorem mem_reverse {a : α} {l : list α} : a ∈ reverse l ↔ a ∈ l :=
by induction l; [refl, simp only [*, reverse_cons, mem_append, mem_singleton, mem_cons_iff,
not_mem_nil, false_or, or_false, or_comm]]
@[simp] theorem reverse_repeat (a : α) (n) : reverse (repeat a n) = repeat a n :=
eq_repeat.2 ⟨by simp only [length_reverse, length_repeat],
λ b h, eq_of_mem_repeat (mem_reverse.1 h)⟩
/-! ### is_nil -/
lemma is_nil_iff_eq_nil {l : list α} : l.is_nil ↔ l = [] :=
list.cases_on l (by simp [is_nil]) (by simp [is_nil])
/-! ### init -/
@[simp] theorem length_init : ∀ (l : list α), length (init l) = length l - 1
| [] := rfl
| [a] := rfl
| (a :: b :: l) :=
begin
rw init,
simp only [add_left_inj, length, succ_add_sub_one],
exact length_init (b :: l)
end
/-! ### last -/
@[simp] theorem last_cons {a : α} {l : list α} :
∀ (h₁ : a :: l ≠ nil) (h₂ : l ≠ nil), last (a :: l) h₁ = last l h₂ :=
by {induction l; intros, contradiction, reflexivity}
@[simp] theorem last_append {a : α} (l : list α) (h : l ++ [a] ≠ []) : last (l ++ [a]) h = a :=
by induction l;
[refl, simp only [cons_append, last_cons _ (λ H, cons_ne_nil _ _ (append_eq_nil.1 H).2), *]]
theorem last_concat {a : α} (l : list α) (h : concat l a ≠ []) : last (concat l a) h = a :=
by simp only [concat_eq_append, last_append]
@[simp] theorem last_singleton (a : α) (h : [a] ≠ []) : last [a] h = a := rfl
@[simp] theorem last_cons_cons (a₁ a₂ : α) (l : list α) (h : a₁::a₂::l ≠ []) :
last (a₁::a₂::l) h = last (a₂::l) (cons_ne_nil a₂ l) := rfl
theorem init_append_last : ∀ {l : list α} (h : l ≠ []), init l ++ [last l h] = l
| [] h := absurd rfl h
| [a] h := rfl
| (a::b::l) h :=
begin
rw [init, cons_append, last_cons (cons_ne_nil _ _) (cons_ne_nil _ _)],
congr,
exact init_append_last (cons_ne_nil b l)
end
theorem last_congr {l₁ l₂ : list α} (h₁ : l₁ ≠ []) (h₂ : l₂ ≠ []) (h₃ : l₁ = l₂) :
last l₁ h₁ = last l₂ h₂ :=
by subst l₁
theorem last_mem : ∀ {l : list α} (h : l ≠ []), last l h ∈ l
| [] h := absurd rfl h
| [a] h := or.inl rfl
| (a::b::l) h := or.inr $ by { rw [last_cons_cons], exact last_mem (cons_ne_nil b l) }
lemma last_repeat_succ (a m : ℕ) :
(repeat a m.succ).last (ne_nil_of_length_eq_succ
(show (repeat a m.succ).length = m.succ, by rw length_repeat)) = a :=
begin
induction m with k IH,
{ simp },
{ simpa only [repeat_succ, last] }
end
/-! ### last' -/
@[simp] theorem last'_is_none :
∀ {l : list α}, (last' l).is_none ↔ l = []
| [] := by simp
| [a] := by simp
| (a::b::l) := by simp [@last'_is_none (b::l)]
@[simp] theorem last'_is_some : ∀ {l : list α}, l.last'.is_some ↔ l ≠ []
| [] := by simp
| [a] := by simp
| (a::b::l) := by simp [@last'_is_some (b::l)]
theorem mem_last'_eq_last : ∀ {l : list α} {x : α}, x ∈ l.last' → ∃ h, x = last l h
| [] x hx := false.elim $ by simpa using hx
| [a] x hx := have a = x, by simpa using hx, this ▸ ⟨cons_ne_nil a [], rfl⟩
| (a::b::l) x hx :=
begin
rw last' at hx,
rcases mem_last'_eq_last hx with ⟨h₁, h₂⟩,
use cons_ne_nil _ _,
rwa [last_cons]
end
theorem mem_of_mem_last' {l : list α} {a : α} (ha : a ∈ l.last') : a ∈ l :=
let ⟨h₁, h₂⟩ := mem_last'_eq_last ha in h₂.symm ▸ last_mem _
theorem init_append_last' : ∀ {l : list α} (a ∈ l.last'), init l ++ [a] = l
| [] a ha := (option.not_mem_none a ha).elim
| [a] _ rfl := rfl
| (a :: b :: l) c hc := by { rw [last'] at hc, rw [init, cons_append, init_append_last' _ hc] }
theorem ilast_eq_last' [inhabited α] : ∀ l : list α, l.ilast = l.last'.iget
| [] := by simp [ilast, arbitrary]
| [a] := rfl
| [a, b] := rfl
| [a, b, c] := rfl
| (a :: b :: c :: l) := by simp [ilast, ilast_eq_last' (c :: l)]
@[simp] theorem last'_append_cons : ∀ (l₁ : list α) (a : α) (l₂ : list α),
last' (l₁ ++ a :: l₂) = last' (a :: l₂)
| [] a l₂ := rfl
| [b] a l₂ := rfl
| (b::c::l₁) a l₂ := by rw [cons_append, cons_append, last', ← cons_append, last'_append_cons]
theorem last'_append_of_ne_nil (l₁ : list α) : ∀ {l₂ : list α} (hl₂ : l₂ ≠ []),
last' (l₁ ++ l₂) = last' l₂
| [] hl₂ := by contradiction
| (b::l₂) _ := last'_append_cons l₁ b l₂
/-! ### head(') and tail -/
theorem head_eq_head' [inhabited α] (l : list α) : head l = (head' l).iget :=
by cases l; refl
theorem mem_of_mem_head' {x : α} : ∀ {l : list α}, x ∈ l.head' → x ∈ l
| [] h := (option.not_mem_none _ h).elim
| (a::l) h := by { simp only [head', option.mem_def] at h, exact h ▸ or.inl rfl }
@[simp] theorem head_cons [inhabited α] (a : α) (l : list α) : head (a::l) = a := rfl
@[simp] theorem tail_nil : tail (@nil α) = [] := rfl
@[simp] theorem tail_cons (a : α) (l : list α) : tail (a::l) = l := rfl
@[simp] theorem head_append [inhabited α] (t : list α) {s : list α} (h : s ≠ []) :
head (s ++ t) = head s :=
by {induction s, contradiction, refl}
theorem tail_append_singleton_of_ne_nil {a : α} {l : list α} (h : l ≠ nil) :
tail (l ++ [a]) = tail l ++ [a] :=
by { induction l, contradiction, rw [tail,cons_append,tail], }
theorem cons_head'_tail : ∀ {l : list α} {a : α} (h : a ∈ head' l), a :: tail l = l
| [] a h := by contradiction
| (b::l) a h := by { simp at h, simp [h] }
theorem head_mem_head' [inhabited α] : ∀ {l : list α} (h : l ≠ []), head l ∈ head' l
| [] h := by contradiction
| (a::l) h := rfl
theorem cons_head_tail [inhabited α] {l : list α} (h : l ≠ []) : (head l)::(tail l) = l :=
cons_head'_tail (head_mem_head' h)
@[simp] theorem head'_map (f : α → β) (l) : head' (map f l) = (head' l).map f := by cases l; refl
/-! ### Induction from the right -/
/-- Induction principle from the right for lists: if a property holds for the empty list, and
for `l ++ [a]` if it holds for `l`, then it holds for all lists. The principle is given for
a `Sort`-valued predicate, i.e., it can also be used to construct data. -/
@[elab_as_eliminator] def reverse_rec_on {C : list α → Sort*}
(l : list α) (H0 : C [])
(H1 : ∀ (l : list α) (a : α), C l → C (l ++ [a])) : C l :=
begin
rw ← reverse_reverse l,
induction reverse l,
{ exact H0 },
{ rw reverse_cons, exact H1 _ _ ih }
end
/-- Bidirectional induction principle for lists: if a property holds for the empty list, the
singleton list, and `a :: (l ++ [b])` from `l`, then it holds for all lists. This can be used to
prove statements about palindromes. The principle is given for a `Sort`-valued predicate, i.e., it
can also be used to construct data. -/
def bidirectional_rec {C : list α → Sort*}
(H0 : C []) (H1 : ∀ (a : α), C [a])
(Hn : ∀ (a : α) (l : list α) (b : α), C l → C (a :: (l ++ [b]))) : ∀ l, C l
| [] := H0
| [a] := H1 a
| (a :: b :: l) :=
let l' := init (b :: l), b' := last (b :: l) (cons_ne_nil _ _) in
have length l' < length (a :: b :: l), by { change _ < length l + 2, simp },
begin
rw ←init_append_last (cons_ne_nil b l),
have : C l', from bidirectional_rec l',
exact Hn a l' b' ‹C l'›
end
using_well_founded { rel_tac := λ _ _, `[exact ⟨_, measure_wf list.length⟩] }
/-- Like `bidirectional_rec`, but with the list parameter placed first. -/
@[elab_as_eliminator] def bidirectional_rec_on {C : list α → Sort*}
(l : list α) (H0 : C []) (H1 : ∀ (a : α), C [a])
(Hn : ∀ (a : α) (l : list α) (b : α), C l → C (a :: (l ++ [b]))) : C l :=
bidirectional_rec H0 H1 Hn l
/-! ### sublists -/
@[simp] theorem nil_sublist : Π (l : list α), [] <+ l
| [] := sublist.slnil
| (a :: l) := sublist.cons _ _ a (nil_sublist l)
@[refl, simp] theorem sublist.refl : Π (l : list α), l <+ l
| [] := sublist.slnil
| (a :: l) := sublist.cons2 _ _ a (sublist.refl l)
@[trans] theorem sublist.trans {l₁ l₂ l₃ : list α} (h₁ : l₁ <+ l₂) (h₂ : l₂ <+ l₃) : l₁ <+ l₃ :=
sublist.rec_on h₂ (λ_ s, s)
(λl₂ l₃ a h₂ IH l₁ h₁, sublist.cons _ _ _ (IH l₁ h₁))
(λl₂ l₃ a h₂ IH l₁ h₁, @sublist.cases_on _ (λl₁ l₂', l₂' = a :: l₂ → l₁ <+ a :: l₃) _ _ h₁
(λ_, nil_sublist _)
(λl₁ l₂' a' h₁' e, match a', l₂', e, h₁' with ._, ._, rfl, h₁ :=
sublist.cons _ _ _ (IH _ h₁) end)
(λl₁ l₂' a' h₁' e, match a', l₂', e, h₁' with ._, ._, rfl, h₁ :=
sublist.cons2 _ _ _ (IH _ h₁) end) rfl)
l₁ h₁
@[simp] theorem sublist_cons (a : α) (l : list α) : l <+ a::l :=
sublist.cons _ _ _ (sublist.refl l)
theorem sublist_of_cons_sublist {a : α} {l₁ l₂ : list α} : a::l₁ <+ l₂ → l₁ <+ l₂ :=
sublist.trans (sublist_cons a l₁)
theorem cons_sublist_cons {l₁ l₂ : list α} (a : α) (s : l₁ <+ l₂) : a::l₁ <+ a::l₂ :=
sublist.cons2 _ _ _ s
@[simp] theorem sublist_append_left : Π (l₁ l₂ : list α), l₁ <+ l₁++l₂
| [] l₂ := nil_sublist _
| (a::l₁) l₂ := cons_sublist_cons _ (sublist_append_left l₁ l₂)
@[simp] theorem sublist_append_right : Π (l₁ l₂ : list α), l₂ <+ l₁++l₂
| [] l₂ := sublist.refl _
| (a::l₁) l₂ := sublist.cons _ _ _ (sublist_append_right l₁ l₂)
theorem sublist_cons_of_sublist (a : α) {l₁ l₂ : list α} : l₁ <+ l₂ → l₁ <+ a::l₂ :=
sublist.cons _ _ _
theorem sublist_append_of_sublist_left {l l₁ l₂ : list α} (s : l <+ l₁) : l <+ l₁++l₂ :=
s.trans $ sublist_append_left _ _
theorem sublist_append_of_sublist_right {l l₁ l₂ : list α} (s : l <+ l₂) : l <+ l₁++l₂ :=
s.trans $ sublist_append_right _ _
theorem sublist_of_cons_sublist_cons {l₁ l₂ : list α} : ∀ {a : α}, a::l₁ <+ a::l₂ → l₁ <+ l₂
| ._ (sublist.cons ._ ._ a s) := sublist_of_cons_sublist s
| ._ (sublist.cons2 ._ ._ a s) := s
theorem cons_sublist_cons_iff {l₁ l₂ : list α} {a : α} : a::l₁ <+ a::l₂ ↔ l₁ <+ l₂ :=
⟨sublist_of_cons_sublist_cons, cons_sublist_cons _⟩
@[simp] theorem append_sublist_append_left {l₁ l₂ : list α} : ∀ l, l++l₁ <+ l++l₂ ↔ l₁ <+ l₂
| [] := iff.rfl
| (a::l) := cons_sublist_cons_iff.trans (append_sublist_append_left l)
theorem sublist.append_right {l₁ l₂ : list α} (h : l₁ <+ l₂) (l) : l₁++l <+ l₂++l :=
begin
induction h with _ _ a _ ih _ _ a _ ih,
{ refl },
{ apply sublist_cons_of_sublist a ih },
{ apply cons_sublist_cons a ih }
end
theorem sublist_or_mem_of_sublist {l l₁ l₂ : list α} {a : α} (h : l <+ l₁ ++ a::l₂) :
l <+ l₁ ++ l₂ ∨ a ∈ l :=
begin
induction l₁ with b l₁ IH generalizing l,
{ cases h, { left, exact ‹l <+ l₂› }, { right, apply mem_cons_self } },
{ cases h with _ _ _ h _ _ _ h,
{ exact or.imp_left (sublist_cons_of_sublist _) (IH h) },
{ exact (IH h).imp (cons_sublist_cons _) (mem_cons_of_mem _) } }
end
theorem sublist.reverse {l₁ l₂ : list α} (h : l₁ <+ l₂) : l₁.reverse <+ l₂.reverse :=
begin
induction h with _ _ _ _ ih _ _ a _ ih, {refl},
{ rw reverse_cons, exact sublist_append_of_sublist_left ih },
{ rw [reverse_cons, reverse_cons], exact ih.append_right [a] }
end
@[simp] theorem reverse_sublist_iff {l₁ l₂ : list α} : l₁.reverse <+ l₂.reverse ↔ l₁ <+ l₂ :=
⟨λ h, l₁.reverse_reverse ▸ l₂.reverse_reverse ▸ h.reverse, sublist.reverse⟩
@[simp] theorem append_sublist_append_right {l₁ l₂ : list α} (l) : l₁++l <+ l₂++l ↔ l₁ <+ l₂ :=
⟨λ h, by simpa only [reverse_append, append_sublist_append_left, reverse_sublist_iff]
using h.reverse,
λ h, h.append_right l⟩
theorem sublist.append {l₁ l₂ r₁ r₂ : list α}
(hl : l₁ <+ l₂) (hr : r₁ <+ r₂) : l₁ ++ r₁ <+ l₂ ++ r₂ :=
(hl.append_right _).trans ((append_sublist_append_left _).2 hr)
theorem sublist.subset : Π {l₁ l₂ : list α}, l₁ <+ l₂ → l₁ ⊆ l₂
| ._ ._ sublist.slnil b h := h
| ._ ._ (sublist.cons l₁ l₂ a s) b h := mem_cons_of_mem _ (sublist.subset s h)
| ._ ._ (sublist.cons2 l₁ l₂ a s) b h :=
match eq_or_mem_of_mem_cons h with
| or.inl h := h ▸ mem_cons_self _ _
| or.inr h := mem_cons_of_mem _ (sublist.subset s h)
end
theorem singleton_sublist {a : α} {l} : [a] <+ l ↔ a ∈ l :=
⟨λ h, h.subset (mem_singleton_self _), λ h,
let ⟨s, t, e⟩ := mem_split h in e.symm ▸
(cons_sublist_cons _ (nil_sublist _)).trans (sublist_append_right _ _)⟩
theorem eq_nil_of_sublist_nil {l : list α} (s : l <+ []) : l = [] :=
eq_nil_of_subset_nil $ s.subset
theorem repeat_sublist_repeat (a : α) {m n} : repeat a m <+ repeat a n ↔ m ≤ n :=
⟨λ h, by simpa only [length_repeat] using length_le_of_sublist h,
λ h, by induction h; [refl, simp only [*, repeat_succ, sublist.cons]] ⟩
theorem eq_of_sublist_of_length_eq : ∀ {l₁ l₂ : list α}, l₁ <+ l₂ → length l₁ = length l₂ → l₁ = l₂
| ._ ._ sublist.slnil h := rfl
| ._ ._ (sublist.cons l₁ l₂ a s) h :=
absurd (length_le_of_sublist s) $ not_le_of_gt $ by rw h; apply lt_succ_self
| ._ ._ (sublist.cons2 l₁ l₂ a s) h :=
by rw [length, length] at h; injection h with h; rw eq_of_sublist_of_length_eq s h
theorem eq_of_sublist_of_length_le {l₁ l₂ : list α} (s : l₁ <+ l₂) (h : length l₂ ≤ length l₁) :
l₁ = l₂ :=
eq_of_sublist_of_length_eq s (le_antisymm (length_le_of_sublist s) h)
theorem sublist.antisymm {l₁ l₂ : list α} (s₁ : l₁ <+ l₂) (s₂ : l₂ <+ l₁) : l₁ = l₂ :=
eq_of_sublist_of_length_le s₁ (length_le_of_sublist s₂)
instance decidable_sublist [decidable_eq α] : ∀ (l₁ l₂ : list α), decidable (l₁ <+ l₂)
| [] l₂ := is_true $ nil_sublist _
| (a::l₁) [] := is_false $ λh, list.no_confusion $ eq_nil_of_sublist_nil h
| (a::l₁) (b::l₂) :=
if h : a = b then
decidable_of_decidable_of_iff (decidable_sublist l₁ l₂) $
by rw [← h]; exact ⟨cons_sublist_cons _, sublist_of_cons_sublist_cons⟩
else decidable_of_decidable_of_iff (decidable_sublist (a::l₁) l₂)
⟨sublist_cons_of_sublist _, λs, match a, l₁, s, h with
| a, l₁, sublist.cons ._ ._ ._ s', h := s'
| ._, ._, sublist.cons2 t ._ ._ s', h := absurd rfl h
end⟩
/-! ### index_of -/
section index_of
variable [decidable_eq α]
@[simp] theorem index_of_nil (a : α) : index_of a [] = 0 := rfl
theorem index_of_cons (a b : α) (l : list α) :
index_of a (b::l) = if a = b then 0 else succ (index_of a l) := rfl
theorem index_of_cons_eq {a b : α} (l : list α) : a = b → index_of a (b::l) = 0 :=
assume e, if_pos e
@[simp] theorem index_of_cons_self (a : α) (l : list α) : index_of a (a::l) = 0 :=
index_of_cons_eq _ rfl
@[simp, priority 990]
theorem index_of_cons_ne {a b : α} (l : list α) : a ≠ b → index_of a (b::l) = succ (index_of a l) :=
assume n, if_neg n
theorem index_of_eq_length {a : α} {l : list α} : index_of a l = length l ↔ a ∉ l :=
begin
induction l with b l ih,
{ exact iff_of_true rfl (not_mem_nil _) },
simp only [length, mem_cons_iff, index_of_cons], split_ifs,
{ exact iff_of_false (by rintro ⟨⟩) (λ H, H $ or.inl h) },
{ simp only [h, false_or], rw ← ih, exact succ_inj' }
end
@[simp, priority 980]
theorem index_of_of_not_mem {l : list α} {a : α} : a ∉ l → index_of a l = length l :=
index_of_eq_length.2
theorem index_of_le_length {a : α} {l : list α} : index_of a l ≤ length l :=
begin
induction l with b l ih, {refl},
simp only [length, index_of_cons],
by_cases h : a = b, {rw if_pos h, exact nat.zero_le _},
rw if_neg h, exact succ_le_succ ih
end
theorem index_of_lt_length {a} {l : list α} : index_of a l < length l ↔ a ∈ l :=
⟨λh, by_contradiction $ λ al, ne_of_lt h $ index_of_eq_length.2 al,
λal, lt_of_le_of_ne index_of_le_length $ λ h, index_of_eq_length.1 h al⟩
end index_of
/-! ### nth element -/
theorem nth_le_of_mem : ∀ {a} {l : list α}, a ∈ l → ∃ n h, nth_le l n h = a
| a (_ :: l) (or.inl rfl) := ⟨0, succ_pos _, rfl⟩
| a (b :: l) (or.inr m) :=
let ⟨n, h, e⟩ := nth_le_of_mem m in ⟨n+1, succ_lt_succ h, e⟩
theorem nth_le_nth : ∀ {l : list α} {n} h, nth l n = some (nth_le l n h)
| (a :: l) 0 h := rfl
| (a :: l) (n+1) h := @nth_le_nth l n _
theorem nth_len_le : ∀ {l : list α} {n}, length l ≤ n → nth l n = none
| [] n h := rfl
| (a :: l) (n+1) h := nth_len_le (le_of_succ_le_succ h)
theorem nth_eq_some {l : list α} {n a} : nth l n = some a ↔ ∃ h, nth_le l n h = a :=
⟨λ e,
have h : n < length l, from lt_of_not_ge $ λ hn,
by rw nth_len_le hn at e; contradiction,
⟨h, by rw nth_le_nth h at e;
injection e with e; apply nth_le_mem⟩,
λ ⟨h, e⟩, e ▸ nth_le_nth _⟩
@[simp]
theorem nth_eq_none_iff : ∀ {l : list α} {n}, nth l n = none ↔ length l ≤ n :=
begin
intros, split,
{ intro h, by_contradiction h',
have h₂ : ∃ h, l.nth_le n h = l.nth_le n (lt_of_not_ge h') := ⟨lt_of_not_ge h', rfl⟩,
rw [← nth_eq_some, h] at h₂, cases h₂ },
{ solve_by_elim [nth_len_le] },
end
theorem nth_of_mem {a} {l : list α} (h : a ∈ l) : ∃ n, nth l n = some a :=
let ⟨n, h, e⟩ := nth_le_of_mem h in ⟨n, by rw [nth_le_nth, e]⟩
theorem nth_le_mem : ∀ (l : list α) n h, nth_le l n h ∈ l
| (a :: l) 0 h := mem_cons_self _ _
| (a :: l) (n+1) h := mem_cons_of_mem _ (nth_le_mem l _ _)
theorem nth_mem {l : list α} {n a} (e : nth l n = some a) : a ∈ l :=
let ⟨h, e⟩ := nth_eq_some.1 e in e ▸ nth_le_mem _ _ _
theorem mem_iff_nth_le {a} {l : list α} : a ∈ l ↔ ∃ n h, nth_le l n h = a :=
⟨nth_le_of_mem, λ ⟨n, h, e⟩, e ▸ nth_le_mem _ _ _⟩
theorem mem_iff_nth {a} {l : list α} : a ∈ l ↔ ∃ n, nth l n = some a :=
mem_iff_nth_le.trans $ exists_congr $ λ n, nth_eq_some.symm
lemma nth_zero (l : list α) : l.nth 0 = l.head' := by cases l; refl
lemma nth_injective {α : Type u} {xs : list α} {i j : ℕ}
(h₀ : i < xs.length)
(h₁ : nodup xs)
(h₂ : xs.nth i = xs.nth j) : i = j :=
begin
induction xs with x xs generalizing i j,
{ cases h₀ },
{ cases i; cases j,
case nat.zero nat.zero
{ refl },
case nat.succ nat.succ
{ congr, cases h₁,
apply xs_ih;
solve_by_elim [lt_of_succ_lt_succ] },
iterate 2
{ dsimp at h₂,
cases h₁ with _ _ h h',
cases h x _ rfl,
rw mem_iff_nth,
exact ⟨_, h₂.symm⟩ <|>
exact ⟨_, h₂⟩ } },
end
@[simp] theorem nth_map (f : α → β) : ∀ l n, nth (map f l) n = (nth l n).map f
| [] n := rfl
| (a :: l) 0 := rfl
| (a :: l) (n+1) := nth_map l n
theorem nth_le_map (f : α → β) {l n} (H1 H2) : nth_le (map f l) n H1 = f (nth_le l n H2) :=
option.some.inj $ by rw [← nth_le_nth, nth_map, nth_le_nth]; refl
/-- A version of `nth_le_map` that can be used for rewriting. -/
theorem nth_le_map_rev (f : α → β) {l n} (H) :
f (nth_le l n H) = nth_le (map f l) n ((length_map f l).symm ▸ H) :=
(nth_le_map f _ _).symm
@[simp] theorem nth_le_map' (f : α → β) {l n} (H) :
nth_le (map f l) n H = f (nth_le l n (length_map f l ▸ H)) :=
nth_le_map f _ _
/-- If one has `nth_le L i hi` in a formula and `h : L = L'`, one can not `rw h` in the formula as
`hi` gives `i < L.length` and not `i < L'.length`. The lemma `nth_le_of_eq` can be used to make
such a rewrite, with `rw (nth_le_of_eq h)`. -/
lemma nth_le_of_eq {L L' : list α} (h : L = L') {i : ℕ} (hi : i < L.length) :
nth_le L i hi = nth_le L' i (h ▸ hi) :=
by { congr, exact h}
@[simp] lemma nth_le_singleton (a : α) {n : ℕ} (hn : n < 1) :
nth_le [a] n hn = a :=
have hn0 : n = 0 := le_zero_iff.1 (le_of_lt_succ hn),
by subst hn0; refl
lemma nth_le_zero [inhabited α] {L : list α} (h : 0 < L.length) :
L.nth_le 0 h = L.head :=
by { cases L, cases h, simp, }
lemma nth_le_append : ∀ {l₁ l₂ : list α} {n : ℕ} (hn₁) (hn₂),
(l₁ ++ l₂).nth_le n hn₁ = l₁.nth_le n hn₂
| [] _ n hn₁ hn₂ := (not_lt_zero _ hn₂).elim
| (a::l) _ 0 hn₁ hn₂ := rfl
| (a::l) _ (n+1) hn₁ hn₂ := by simp only [nth_le, cons_append];
exact nth_le_append _ _
lemma nth_le_append_right_aux {l₁ l₂ : list α} {n : ℕ}
(h₁ : l₁.length ≤ n) (h₂ : n < (l₁ ++ l₂).length) : n - l₁.length < l₂.length :=
begin
rw list.length_append at h₂,
convert (nat.sub_lt_sub_right_iff h₁).mpr h₂,
simp,
end
lemma nth_le_append_right : ∀ {l₁ l₂ : list α} {n : ℕ} (h₁ : l₁.length ≤ n) (h₂),
(l₁ ++ l₂).nth_le n h₂ = l₂.nth_le (n - l₁.length) (nth_le_append_right_aux h₁ h₂)
| [] _ n h₁ h₂ := rfl
| (a :: l) _ (n+1) h₁ h₂ :=
begin
dsimp,
conv { to_rhs, congr, skip, rw [←nat.sub_sub, nat.sub.right_comm, nat.add_sub_cancel], },
rw nth_le_append_right (nat.lt_succ_iff.mp h₁),
end
@[simp] lemma nth_le_repeat (a : α) {n m : ℕ} (h : m < (list.repeat a n).length) :
(list.repeat a n).nth_le m h = a :=
eq_of_mem_repeat (nth_le_mem _ _ _)
lemma nth_append {l₁ l₂ : list α} {n : ℕ} (hn : n < l₁.length) :
(l₁ ++ l₂).nth n = l₁.nth n :=
have hn' : n < (l₁ ++ l₂).length := lt_of_lt_of_le hn
(by rw length_append; exact le_add_right _ _),
by rw [nth_le_nth hn, nth_le_nth hn', nth_le_append]
lemma nth_append_right {l₁ l₂ : list α} {n : ℕ} (hn : l₁.length ≤ n) :
(l₁ ++ l₂).nth n = l₂.nth (n - l₁.length) :=
begin
by_cases hl : n < (l₁ ++ l₂).length,
{ rw [nth_le_nth hl, nth_le_nth, nth_le_append_right hn] },
{ rw [nth_len_le (le_of_not_lt hl), nth_len_le],
rw [not_lt, length_append] at hl,
exact nat.le_sub_left_of_add_le hl }
end
lemma last_eq_nth_le : ∀ (l : list α) (h : l ≠ []),
last l h = l.nth_le (l.length - 1) (sub_lt (length_pos_of_ne_nil h) one_pos)
| [] h := rfl
| [a] h := by rw [last_singleton, nth_le_singleton]
| (a :: b :: l) h := by { rw [last_cons, last_eq_nth_le (b :: l)],
refl, exact cons_ne_nil b l }
@[simp] lemma nth_concat_length : ∀ (l : list α) (a : α), (l ++ [a]).nth l.length = some a
| [] a := rfl
| (b::l) a := by rw [cons_append, length_cons, nth, nth_concat_length]
@[ext]
theorem ext : ∀ {l₁ l₂ : list α}, (∀n, nth l₁ n = nth l₂ n) → l₁ = l₂
| [] [] h := rfl
| (a::l₁) [] h := by have h0 := h 0; contradiction
| [] (a'::l₂) h := by have h0 := h 0; contradiction
| (a::l₁) (a'::l₂) h := by have h0 : some a = some a' := h 0; injection h0 with aa;
simp only [aa, ext (λn, h (n+1))]; split; refl
theorem ext_le {l₁ l₂ : list α} (hl : length l₁ = length l₂)
(h : ∀n h₁ h₂, nth_le l₁ n h₁ = nth_le l₂ n h₂) : l₁ = l₂ :=
ext $ λn, if h₁ : n < length l₁
then by rw [nth_le_nth, nth_le_nth, h n h₁ (by rwa [← hl])]
else let h₁ := le_of_not_gt h₁ in by { rw [nth_len_le h₁, nth_len_le], rwa [←hl], }
@[simp] theorem index_of_nth_le [decidable_eq α] {a : α} :
∀ {l : list α} h, nth_le l (index_of a l) h = a
| (b::l) h := by by_cases h' : a = b;
simp only [h', if_pos, if_false, index_of_cons, nth_le, @index_of_nth_le l]
@[simp] theorem index_of_nth [decidable_eq α] {a : α} {l : list α} (h : a ∈ l) :
nth l (index_of a l) = some a :=
by rw [nth_le_nth, index_of_nth_le (index_of_lt_length.2 h)]
theorem nth_le_reverse_aux1 :
∀ (l r : list α) (i h1 h2), nth_le (reverse_core l r) (i + length l) h1 = nth_le r i h2
| [] r i := λh1 h2, rfl
| (a :: l) r i :=
by rw (show i + length (a :: l) = i + 1 + length l, from add_right_comm i (length l) 1);
exact λh1 h2, nth_le_reverse_aux1 l (a :: r) (i+1) h1 (succ_lt_succ h2)
lemma index_of_inj [decidable_eq α] {l : list α} {x y : α}
(hx : x ∈ l) (hy : y ∈ l) : index_of x l = index_of y l ↔ x = y :=
⟨λ h, have nth_le l (index_of x l) (index_of_lt_length.2 hx) =
nth_le l (index_of y l) (index_of_lt_length.2 hy),
by simp only [h],
by simpa only [index_of_nth_le],
λ h, by subst h⟩
theorem nth_le_reverse_aux2 : ∀ (l r : list α) (i : nat) (h1) (h2),
nth_le (reverse_core l r) (length l - 1 - i) h1 = nth_le l i h2
| [] r i h1 h2 := absurd h2 (not_lt_zero _)
| (a :: l) r 0 h1 h2 := begin
have aux := nth_le_reverse_aux1 l (a :: r) 0,
rw zero_add at aux,
exact aux _ (zero_lt_succ _)
end
| (a :: l) r (i+1) h1 h2 := begin
have aux := nth_le_reverse_aux2 l (a :: r) i,
have heq := calc length (a :: l) - 1 - (i + 1)
= length l - (1 + i) : by rw add_comm; refl
... = length l - 1 - i : by rw nat.sub_sub,
rw [← heq] at aux,
apply aux
end
@[simp] theorem nth_le_reverse (l : list α) (i : nat) (h1 h2) :
nth_le (reverse l) (length l - 1 - i) h1 = nth_le l i h2 :=
nth_le_reverse_aux2 _ _ _ _ _
lemma eq_cons_of_length_one {l : list α} (h : l.length = 1) :
l = [l.nth_le 0 (h.symm ▸ zero_lt_one)] :=
begin
refine ext_le (by convert h) (λ n h₁ h₂, _),
simp only [nth_le_singleton],
congr,
exact eq_bot_iff.mpr (nat.lt_succ_iff.mp h₂)
end
lemma modify_nth_tail_modify_nth_tail {f g : list α → list α} (m : ℕ) :
∀n (l:list α), (l.modify_nth_tail f n).modify_nth_tail g (m + n) =
l.modify_nth_tail (λl, (f l).modify_nth_tail g m) n
| 0 l := rfl
| (n+1) [] := rfl
| (n+1) (a::l) := congr_arg (list.cons a) (modify_nth_tail_modify_nth_tail n l)
lemma modify_nth_tail_modify_nth_tail_le
{f g : list α → list α} (m n : ℕ) (l : list α) (h : n ≤ m) :
(l.modify_nth_tail f n).modify_nth_tail g m =
l.modify_nth_tail (λl, (f l).modify_nth_tail g (m - n)) n :=
begin
rcases le_iff_exists_add.1 h with ⟨m, rfl⟩,
rw [nat.add_sub_cancel_left, add_comm, modify_nth_tail_modify_nth_tail]
end
lemma modify_nth_tail_modify_nth_tail_same {f g : list α → list α} (n : ℕ) (l:list α) :
(l.modify_nth_tail f n).modify_nth_tail g n = l.modify_nth_tail (g ∘ f) n :=
by rw [modify_nth_tail_modify_nth_tail_le n n l (le_refl n), nat.sub_self]; refl
lemma modify_nth_tail_id :
∀n (l:list α), l.modify_nth_tail id n = l
| 0 l := rfl
| (n+1) [] := rfl
| (n+1) (a::l) := congr_arg (list.cons a) (modify_nth_tail_id n l)
theorem remove_nth_eq_nth_tail : ∀ n (l : list α), remove_nth l n = modify_nth_tail tail n l
| 0 l := by cases l; refl
| (n+1) [] := rfl
| (n+1) (a::l) := congr_arg (cons _) (remove_nth_eq_nth_tail _ _)
theorem update_nth_eq_modify_nth (a : α) : ∀ n (l : list α),
update_nth l n a = modify_nth (λ _, a) n l
| 0 l := by cases l; refl
| (n+1) [] := rfl
| (n+1) (b::l) := congr_arg (cons _) (update_nth_eq_modify_nth _ _)
theorem modify_nth_eq_update_nth (f : α → α) : ∀ n (l : list α),
modify_nth f n l = ((λ a, update_nth l n (f a)) <$> nth l n).get_or_else l
| 0 l := by cases l; refl
| (n+1) [] := rfl
| (n+1) (b::l) := (congr_arg (cons b)
(modify_nth_eq_update_nth n l)).trans $ by cases nth l n; refl
theorem nth_modify_nth (f : α → α) : ∀ n (l : list α) m,
nth (modify_nth f n l) m = (λ a, if n = m then f a else a) <$> nth l m
| n l 0 := by cases l; cases n; refl
| n [] (m+1) := by cases n; refl
| 0 (a::l) (m+1) := by cases nth l m; refl
| (n+1) (a::l) (m+1) := (nth_modify_nth n l m).trans $
by cases nth l m with b; by_cases n = m;
simp only [h, if_pos, if_true, if_false, option.map_none, option.map_some, mt succ.inj,
not_false_iff]
theorem modify_nth_tail_length (f : list α → list α) (H : ∀ l, length (f l) = length l) :
∀ n l, length (modify_nth_tail f n l) = length l
| 0 l := H _
| (n+1) [] := rfl
| (n+1) (a::l) := @congr_arg _ _ _ _ (+1) (modify_nth_tail_length _ _)
@[simp] theorem modify_nth_length (f : α → α) :
∀ n l, length (modify_nth f n l) = length l :=
modify_nth_tail_length _ (λ l, by cases l; refl)
@[simp] theorem update_nth_length (l : list α) (n) (a : α) :
length (update_nth l n a) = length l :=
by simp only [update_nth_eq_modify_nth, modify_nth_length]
@[simp] theorem nth_modify_nth_eq (f : α → α) (n) (l : list α) :
nth (modify_nth f n l) n = f <$> nth l n :=
by simp only [nth_modify_nth, if_pos]
@[simp] theorem nth_modify_nth_ne (f : α → α) {m n} (l : list α) (h : m ≠ n) :
nth (modify_nth f m l) n = nth l n :=
by simp only [nth_modify_nth, if_neg h, id_map']
theorem nth_update_nth_eq (a : α) (n) (l : list α) :
nth (update_nth l n a) n = (λ _, a) <$> nth l n :=
by simp only [update_nth_eq_modify_nth, nth_modify_nth_eq]
theorem nth_update_nth_of_lt (a : α) {n} {l : list α} (h : n < length l) :
nth (update_nth l n a) n = some a :=
by rw [nth_update_nth_eq, nth_le_nth h]; refl
theorem nth_update_nth_ne (a : α) {m n} (l : list α) (h : m ≠ n) :
nth (update_nth l m a) n = nth l n :=
by simp only [update_nth_eq_modify_nth, nth_modify_nth_ne _ _ h]
@[simp] lemma nth_le_update_nth_eq (l : list α) (i : ℕ) (a : α)
(h : i < (l.update_nth i a).length) : (l.update_nth i a).nth_le i h = a :=
by rw [← option.some_inj, ← nth_le_nth, nth_update_nth_eq, nth_le_nth]; simp * at *
@[simp] lemma nth_le_update_nth_of_ne {l : list α} {i j : ℕ} (h : i ≠ j) (a : α)
(hj : j < (l.update_nth i a).length) :
(l.update_nth i a).nth_le j hj = l.nth_le j (by simpa using hj) :=
by rw [← option.some_inj, ← list.nth_le_nth, list.nth_update_nth_ne _ _ h, list.nth_le_nth]
lemma mem_or_eq_of_mem_update_nth : ∀ {l : list α} {n : ℕ} {a b : α}
(h : a ∈ l.update_nth n b), a ∈ l ∨ a = b
| [] n a b h := false.elim h
| (c::l) 0 a b h := ((mem_cons_iff _ _ _).1 h).elim
or.inr (or.inl ∘ mem_cons_of_mem _)
| (c::l) (n+1) a b h := ((mem_cons_iff _ _ _).1 h).elim
(λ h, h ▸ or.inl (mem_cons_self _ _))
(λ h, (mem_or_eq_of_mem_update_nth h).elim
(or.inl ∘ mem_cons_of_mem _) or.inr)
section insert_nth
variable {a : α}
@[simp] lemma insert_nth_nil (a : α) : insert_nth 0 a [] = [a] := rfl
@[simp] lemma insert_nth_succ_nil (n : ℕ) (a : α) : insert_nth (n + 1) a [] = [] := rfl
lemma length_insert_nth : ∀n as, n ≤ length as → length (insert_nth n a as) = length as + 1
| 0 as h := rfl
| (n+1) [] h := (nat.not_succ_le_zero _ h).elim
| (n+1) (a'::as) h := congr_arg nat.succ $ length_insert_nth n as (nat.le_of_succ_le_succ h)
lemma remove_nth_insert_nth (n:ℕ) (l : list α) : (l.insert_nth n a).remove_nth n = l :=
by rw [remove_nth_eq_nth_tail, insert_nth, modify_nth_tail_modify_nth_tail_same];
from modify_nth_tail_id _ _
lemma insert_nth_remove_nth_of_ge : ∀n m as, n < length as → n ≤ m →
insert_nth m a (as.remove_nth n) = (as.insert_nth (m + 1) a).remove_nth n
| 0 0 [] has _ := (lt_irrefl _ has).elim
| 0 0 (a::as) has hmn := by simp [remove_nth, insert_nth]
| 0 (m+1) (a::as) has hmn := rfl
| (n+1) (m+1) (a::as) has hmn :=
congr_arg (cons a) $
insert_nth_remove_nth_of_ge n m as (nat.lt_of_succ_lt_succ has) (nat.le_of_succ_le_succ hmn)
lemma insert_nth_remove_nth_of_le : ∀n m as, n < length as → m ≤ n →
insert_nth m a (as.remove_nth n) = (as.insert_nth m a).remove_nth (n + 1)
| n 0 (a :: as) has hmn := rfl
| (n + 1) (m + 1) (a :: as) has hmn :=
congr_arg (cons a) $
insert_nth_remove_nth_of_le n m as (nat.lt_of_succ_lt_succ has) (nat.le_of_succ_le_succ hmn)
lemma insert_nth_comm (a b : α) :
∀(i j : ℕ) (l : list α) (h : i ≤ j) (hj : j ≤ length l),
(l.insert_nth i a).insert_nth (j + 1) b = (l.insert_nth j b).insert_nth i a
| 0 j l := by simp [insert_nth]
| (i + 1) 0 l := assume h, (nat.not_lt_zero _ h).elim
| (i + 1) (j+1) [] := by simp
| (i + 1) (j+1) (c::l) :=
assume h₀ h₁,
by simp [insert_nth];
exact insert_nth_comm i j l (nat.le_of_succ_le_succ h₀) (nat.le_of_succ_le_succ h₁)
lemma mem_insert_nth {a b : α} : ∀ {n : ℕ} {l : list α} (hi : n ≤ l.length),
a ∈ l.insert_nth n b ↔ a = b ∨ a ∈ l
| 0 as h := iff.rfl
| (n+1) [] h := (nat.not_succ_le_zero _ h).elim
| (n+1) (a'::as) h := begin
dsimp [list.insert_nth],
erw [list.mem_cons_iff, mem_insert_nth (nat.le_of_succ_le_succ h), list.mem_cons_iff,
← or.assoc, or_comm (a = a'), or.assoc]
end
end insert_nth
/-! ### map -/
@[simp] lemma map_nil (f : α → β) : map f [] = [] := rfl
theorem map_eq_foldr (f : α → β) (l : list α) :
map f l = foldr (λ a bs, f a :: bs) [] l :=
by induction l; simp *
lemma map_congr {f g : α → β} : ∀ {l : list α}, (∀ x ∈ l, f x = g x) → map f l = map g l
| [] _ := rfl
| (a::l) h := let ⟨h₁, h₂⟩ := forall_mem_cons.1 h in
by rw [map, map, h₁, map_congr h₂]
lemma map_eq_map_iff {f g : α → β} {l : list α} : map f l = map g l ↔ (∀ x ∈ l, f x = g x) :=
begin
refine ⟨_, map_congr⟩, intros h x hx,
rw [mem_iff_nth_le] at hx, rcases hx with ⟨n, hn, rfl⟩,
rw [nth_le_map_rev f, nth_le_map_rev g], congr, exact h
end
theorem map_concat (f : α → β) (a : α) (l : list α) : map f (concat l a) = concat (map f l) (f a) :=
by induction l; [refl, simp only [*, concat_eq_append, cons_append, map, map_append]]; split; refl
theorem map_id' {f : α → α} (h : ∀ x, f x = x) (l : list α) : map f l = l :=
by induction l; [refl, simp only [*, map]]; split; refl
theorem eq_nil_of_map_eq_nil {f : α → β} {l : list α} (h : map f l = nil) : l = nil :=
eq_nil_of_length_eq_zero $ by rw [← length_map f l, h]; refl
@[simp] theorem map_join (f : α → β) (L : list (list α)) :
map f (join L) = join (map (map f) L) :=
by induction L; [refl, simp only [*, join, map, map_append]]
theorem bind_ret_eq_map (f : α → β) (l : list α) :
l.bind (list.ret ∘ f) = map f l :=
by unfold list.bind; induction l; simp only [map, join, list.ret, cons_append, nil_append, *];
split; refl
@[simp] theorem map_eq_map {α β} (f : α → β) (l : list α) : f <$> l = map f l := rfl
@[simp] theorem map_tail (f : α → β) (l) : map f (tail l) = tail (map f l) :=
by cases l; refl
@[simp] theorem map_injective_iff {f : α → β} : injective (map f) ↔ injective f :=
begin
split; intros h x y hxy,
{ suffices : [x] = [y], { simpa using this }, apply h, simp [hxy] },
{ induction y generalizing x, simpa using hxy,
cases x, simpa using hxy, simp at hxy, simp [y_ih hxy.2, h hxy.1] }
end
/--
A single `list.map` of a composition of functions is equal to
composing a `list.map` with another `list.map`, fully applied.
This is the reverse direction of `list.map_map`.
-/
lemma comp_map (h : β → γ) (g : α → β) (l : list α) :
map (h ∘ g) l = map h (map g l) := (map_map _ _ _).symm
/--
Composing a `list.map` with another `list.map` is equal to
a single `list.map` of composed functions.
-/
@[simp] lemma map_comp_map (g : β → γ) (f : α → β) :
map g ∘ map f = map (g ∘ f) :=
by { ext l, rw comp_map }
theorem map_filter_eq_foldr (f : α → β) (p : α → Prop) [decidable_pred p] (as : list α) :
map f (filter p as) = foldr (λ a bs, if p a then f a :: bs else bs) [] as :=
by { induction as, { refl }, { simp! [*, apply_ite (map f)] } }
lemma last_map (f : α → β) {l : list α} (hl : l ≠ []) :
(l.map f).last (mt eq_nil_of_map_eq_nil hl) = f (l.last hl) :=
begin
induction l with l_ih l_tl l_ih,
{ apply (hl rfl).elim },
{ cases l_tl,
{ simp },
{ simpa using l_ih } }
end
/-! ### map₂ -/
theorem nil_map₂ (f : α → β → γ) (l : list β) : map₂ f [] l = [] :=
by cases l; refl
theorem map₂_nil (f : α → β → γ) (l : list α) : map₂ f l [] = [] :=
by cases l; refl
@[simp] theorem map₂_flip (f : α → β → γ) :
∀ as bs, map₂ (flip f) bs as = map₂ f as bs
| [] [] := rfl
| [] (b :: bs) := rfl
| (a :: as) [] := rfl
| (a :: as) (b :: bs) := by { simp! [map₂_flip], refl }
/-! ### take, drop -/
@[simp] theorem take_zero (l : list α) : take 0 l = [] := rfl
@[simp] theorem take_nil : ∀ n, take n [] = ([] : list α)
| 0 := rfl
| (n+1) := rfl
theorem take_cons (n) (a : α) (l : list α) : take (succ n) (a::l) = a :: take n l := rfl
@[simp] theorem take_length : ∀ (l : list α), take (length l) l = l
| [] := rfl
| (a::l) := begin change a :: (take (length l) l) = a :: l, rw take_length end
theorem take_all_of_le : ∀ {n} {l : list α}, length l ≤ n → take n l = l
| 0 [] h := rfl
| 0 (a::l) h := absurd h (not_le_of_gt (zero_lt_succ _))
| (n+1) [] h := rfl
| (n+1) (a::l) h :=
begin
change a :: take n l = a :: l,
rw [take_all_of_le (le_of_succ_le_succ h)]
end
@[simp] theorem take_left : ∀ l₁ l₂ : list α, take (length l₁) (l₁ ++ l₂) = l₁
| [] l₂ := rfl
| (a::l₁) l₂ := congr_arg (cons a) (take_left l₁ l₂)
theorem take_left' {l₁ l₂ : list α} {n} (h : length l₁ = n) :
take n (l₁ ++ l₂) = l₁ :=
by rw ← h; apply take_left
theorem take_take : ∀ (n m) (l : list α), take n (take m l) = take (min n m) l
| n 0 l := by rw [min_zero, take_zero, take_nil]
| 0 m l := by rw [zero_min, take_zero, take_zero]
| (succ n) (succ m) nil := by simp only [take_nil]
| (succ n) (succ m) (a::l) := by simp only [take, min_succ_succ, take_take n m l]; split; refl
theorem take_repeat (a : α) : ∀ (n m : ℕ), take n (repeat a m) = repeat a (min n m)
| n 0 := by simp
| 0 m := by simp
| (succ n) (succ m) := by simp [min_succ_succ, take_repeat]
lemma map_take {α β : Type*} (f : α → β) :
∀ (L : list α) (i : ℕ), (L.take i).map f = (L.map f).take i
| [] i := by simp
| L 0 := by simp
| (h :: t) (n+1) := by { dsimp, rw [map_take], }
lemma take_append_of_le_length : ∀ {l₁ l₂ : list α} {n : ℕ},
n ≤ l₁.length → (l₁ ++ l₂).take n = l₁.take n
| l₁ l₂ 0 hn := by simp
| [] l₂ (n+1) hn := absurd hn dec_trivial
| (a::l₁) l₂ (n+1) hn :=
by rw [list.take, list.cons_append, list.take, take_append_of_le_length (le_of_succ_le_succ hn)]
/-- Taking the first `l₁.length + i` elements in `l₁ ++ l₂` is the same as appending the first
`i` elements of `l₂` to `l₁`. -/
lemma take_append {l₁ l₂ : list α} (i : ℕ) :
take (l₁.length + i) (l₁ ++ l₂) = l₁ ++ (take i l₂) :=
begin
induction l₁, { simp },
have : length l₁_tl + 1 + i = (length l₁_tl + i).succ,
by { rw nat.succ_eq_add_one, exact succ_add _ _ },
simp only [cons_append, length, this, take_cons, l₁_ih, eq_self_iff_true, and_self]
end
/-- The `i`-th element of a list coincides with the `i`-th element of any of its prefixes of
length `> i`. Version designed to rewrite from the big list to the small list. -/
lemma nth_le_take (L : list α) {i j : ℕ} (hi : i < L.length) (hj : i < j) :
nth_le L i hi = nth_le (L.take j) i (by { rw length_take, exact lt_min hj hi }) :=
by { rw nth_le_of_eq (take_append_drop j L).symm hi, exact nth_le_append _ _ }
/-- The `i`-th element of a list coincides with the `i`-th element of any of its prefixes of
length `> i`. Version designed to rewrite from the small list to the big list. -/
lemma nth_le_take' (L : list α) {i j : ℕ} (hi : i < (L.take j).length) :
nth_le (L.take j) i hi = nth_le L i (lt_of_lt_of_le hi (by simp [le_refl])) :=
by { simp at hi, rw nth_le_take L _ hi.1 }
lemma nth_take {l : list α} {n m : ℕ} (h : m < n) :
(l.take n).nth m = l.nth m :=
begin
induction n with n hn generalizing l m,
{ simp only [nat.nat_zero_eq_zero] at h,
exact absurd h (not_lt_of_le m.zero_le) },
{ cases l with hd tl,
{ simp only [take_nil] },
{ cases m,
{ simp only [nth, take] },
{ simpa only using hn (nat.lt_of_succ_lt_succ h) } } },
end
@[simp] lemma nth_take_of_succ {l : list α} {n : ℕ} :
(l.take (n + 1)).nth n = l.nth n :=
nth_take (nat.lt_succ_self n)
lemma take_succ {l : list α} {n : ℕ} :
l.take (n + 1) = l.take n ++ (l.nth n).to_list :=
begin
induction l with hd tl hl generalizing n,
{ simp only [option.to_list, nth, take_nil, append_nil]},
{ cases n,
{ simp only [option.to_list, nth, eq_self_iff_true, and_self, take, nil_append] },
{ simp only [hl, cons_append, nth, eq_self_iff_true, and_self, take] } }
end
@[simp] theorem drop_nil : ∀ n, drop n [] = ([] : list α)
| 0 := rfl
| (n+1) := rfl
lemma mem_of_mem_drop {α} {n : ℕ} {l : list α} {x : α}
(h : x ∈ l.drop n) :
x ∈ l :=
begin
induction l generalizing n,
case list.nil : n h
{ simpa using h },
case list.cons : l_hd l_tl l_ih n h
{ cases n; simp only [mem_cons_iff, drop] at h ⊢,
{ exact h },
right, apply l_ih h },
end
@[simp] theorem drop_one : ∀ l : list α, drop 1 l = tail l
| [] := rfl
| (a :: l) := rfl
theorem drop_add : ∀ m n (l : list α), drop (m + n) l = drop m (drop n l)
| m 0 l := rfl
| m (n+1) [] := (drop_nil _).symm
| m (n+1) (a::l) := drop_add m n _
@[simp] theorem drop_left : ∀ l₁ l₂ : list α, drop (length l₁) (l₁ ++ l₂) = l₂
| [] l₂ := rfl
| (a::l₁) l₂ := drop_left l₁ l₂
theorem drop_left' {l₁ l₂ : list α} {n} (h : length l₁ = n) :
drop n (l₁ ++ l₂) = l₂ :=
by rw ← h; apply drop_left
theorem drop_eq_nth_le_cons : ∀ {n} {l : list α} h,
drop n l = nth_le l n h :: drop (n+1) l
| 0 (a::l) h := rfl
| (n+1) (a::l) h := @drop_eq_nth_le_cons n _ _
@[simp] lemma drop_length (l : list α) : l.drop l.length = [] :=
calc l.drop l.length = (l ++ []).drop l.length : by simp
... = [] : drop_left _ _
lemma drop_append_of_le_length : ∀ {l₁ l₂ : list α} {n : ℕ}, n ≤ l₁.length →
(l₁ ++ l₂).drop n = l₁.drop n ++ l₂
| l₁ l₂ 0 hn := by simp
| [] l₂ (n+1) hn := absurd hn dec_trivial
| (a::l₁) l₂ (n+1) hn :=
by rw [drop, cons_append, drop, drop_append_of_le_length (le_of_succ_le_succ hn)]
/-- Dropping the elements up to `l₁.length + i` in `l₁ + l₂` is the same as dropping the elements
up to `i` in `l₂`. -/
lemma drop_append {l₁ l₂ : list α} (i : ℕ) :
drop (l₁.length + i) (l₁ ++ l₂) = drop i l₂ :=
begin
induction l₁, { simp },
have : length l₁_tl + 1 + i = (length l₁_tl + i).succ,
by { rw nat.succ_eq_add_one, exact succ_add _ _ },
simp only [cons_append, length, this, drop, l₁_ih]
end
/-- The `i + j`-th element of a list coincides with the `j`-th element of the list obtained by
dropping the first `i` elements. Version designed to rewrite from the big list to the small list. -/
lemma nth_le_drop (L : list α) {i j : ℕ} (h : i + j < L.length) :
nth_le L (i + j) h = nth_le (L.drop i) j
begin
have A : i < L.length := lt_of_le_of_lt (nat.le.intro rfl) h,
rw (take_append_drop i L).symm at h,
simpa only [le_of_lt A, min_eq_left, add_lt_add_iff_left, length_take, length_append] using h
end :=
begin
have A : length (take i L) = i, by simp [le_of_lt (lt_of_le_of_lt (nat.le.intro rfl) h)],
rw [nth_le_of_eq (take_append_drop i L).symm h, nth_le_append_right];
simp [A]
end
/-- The `i + j`-th element of a list coincides with the `j`-th element of the list obtained by
dropping the first `i` elements. Version designed to rewrite from the small list to the big list. -/
lemma nth_le_drop' (L : list α) {i j : ℕ} (h : j < (L.drop i).length) :
nth_le (L.drop i) j h = nth_le L (i + j) (nat.add_lt_of_lt_sub_left ((length_drop i L) ▸ h)) :=
by rw nth_le_drop
@[simp] theorem drop_drop (n : ℕ) : ∀ (m) (l : list α), drop n (drop m l) = drop (n + m) l
| m [] := by simp
| 0 l := by simp
| (m+1) (a::l) :=
calc drop n (drop (m + 1) (a :: l)) = drop n (drop m l) : rfl
... = drop (n + m) l : drop_drop m l
... = drop (n + (m + 1)) (a :: l) : rfl
theorem drop_take : ∀ (m : ℕ) (n : ℕ) (l : list α),
drop m (take (m + n) l) = take n (drop m l)
| 0 n _ := by simp
| (m+1) n nil := by simp
| (m+1) n (_::l) :=
have h: m + 1 + n = (m+n) + 1, by ac_refl,
by simpa [take_cons, h] using drop_take m n l
lemma map_drop {α β : Type*} (f : α → β) :
∀ (L : list α) (i : ℕ), (L.drop i).map f = (L.map f).drop i
| [] i := by simp
| L 0 := by simp
| (h :: t) (n+1) := by { dsimp, rw [map_drop], }
theorem modify_nth_tail_eq_take_drop (f : list α → list α) (H : f [] = []) :
∀ n l, modify_nth_tail f n l = take n l ++ f (drop n l)
| 0 l := rfl
| (n+1) [] := H.symm
| (n+1) (b::l) := congr_arg (cons b) (modify_nth_tail_eq_take_drop n l)
theorem modify_nth_eq_take_drop (f : α → α) :
∀ n l, modify_nth f n l = take n l ++ modify_head f (drop n l) :=
modify_nth_tail_eq_take_drop _ rfl
theorem modify_nth_eq_take_cons_drop (f : α → α) {n l} (h) :
modify_nth f n l = take n l ++ f (nth_le l n h) :: drop (n+1) l :=
by rw [modify_nth_eq_take_drop, drop_eq_nth_le_cons h]; refl
theorem update_nth_eq_take_cons_drop (a : α) {n l} (h : n < length l) :
update_nth l n a = take n l ++ a :: drop (n+1) l :=
by rw [update_nth_eq_modify_nth, modify_nth_eq_take_cons_drop _ h]
lemma reverse_take {α} {xs : list α} (n : ℕ)
(h : n ≤ xs.length) :
xs.reverse.take n = (xs.drop (xs.length - n)).reverse :=
begin
induction xs generalizing n;
simp only [reverse_cons, drop, reverse_nil, nat.zero_sub, length, take_nil],
cases decidable.lt_or_eq_of_le h with h' h',
{ replace h' := le_of_succ_le_succ h',
rwa [take_append_of_le_length, xs_ih _ h'],
rw [show xs_tl.length + 1 - n = succ (xs_tl.length - n), from _, drop],
{ rwa [succ_eq_add_one, nat.sub_add_comm] },
{ rwa length_reverse } },
{ subst h', rw [length, nat.sub_self, drop],
suffices : xs_tl.length + 1 = (xs_tl.reverse ++ [xs_hd]).length,
by rw [this, take_length, reverse_cons],
rw [length_append, length_reverse], refl }
end
@[simp] lemma update_nth_eq_nil (l : list α) (n : ℕ) (a : α) : l.update_nth n a = [] ↔ l = [] :=
by cases l; cases n; simp only [update_nth]
section take'
variable [inhabited α]
@[simp] theorem take'_length : ∀ n l, length (@take' α _ n l) = n
| 0 l := rfl
| (n+1) l := congr_arg succ (take'_length _ _)
@[simp] theorem take'_nil : ∀ n, take' n (@nil α) = repeat (default _) n
| 0 := rfl
| (n+1) := congr_arg (cons _) (take'_nil _)
theorem take'_eq_take : ∀ {n} {l : list α},
n ≤ length l → take' n l = take n l
| 0 l h := rfl
| (n+1) (a::l) h := congr_arg (cons _) $
take'_eq_take $ le_of_succ_le_succ h
@[simp] theorem take'_left (l₁ l₂ : list α) : take' (length l₁) (l₁ ++ l₂) = l₁ :=
(take'_eq_take (by simp only [length_append, nat.le_add_right])).trans (take_left _ _)
theorem take'_left' {l₁ l₂ : list α} {n} (h : length l₁ = n) :
take' n (l₁ ++ l₂) = l₁ :=
by rw ← h; apply take'_left
end take'
/-! ### foldl, foldr -/
lemma foldl_ext (f g : α → β → α) (a : α)
{l : list β} (H : ∀ a : α, ∀ b ∈ l, f a b = g a b) :
foldl f a l = foldl g a l :=
begin
induction l with hd tl ih generalizing a, {refl},
unfold foldl,
rw [ih (λ a b bin, H a b $ mem_cons_of_mem _ bin), H a hd (mem_cons_self _ _)]
end
lemma foldr_ext (f g : α → β → β) (b : β)
{l : list α} (H : ∀ a ∈ l, ∀ b : β, f a b = g a b) :
foldr f b l = foldr g b l :=
begin
induction l with hd tl ih, {refl},
simp only [mem_cons_iff, or_imp_distrib, forall_and_distrib, forall_eq] at H,
simp only [foldr, ih H.2, H.1]
end
@[simp] theorem foldl_nil (f : α → β → α) (a : α) : foldl f a [] = a := rfl
@[simp] theorem foldl_cons (f : α → β → α) (a : α) (b : β) (l : list β) :
foldl f a (b::l) = foldl f (f a b) l := rfl
@[simp] theorem foldr_nil (f : α → β → β) (b : β) : foldr f b [] = b := rfl
@[simp] theorem foldr_cons (f : α → β → β) (b : β) (a : α) (l : list α) :
foldr f b (a::l) = f a (foldr f b l) := rfl
@[simp] theorem foldl_append (f : α → β → α) :
∀ (a : α) (l₁ l₂ : list β), foldl f a (l₁++l₂) = foldl f (foldl f a l₁) l₂
| a [] l₂ := rfl
| a (b::l₁) l₂ := by simp only [cons_append, foldl_cons, foldl_append (f a b) l₁ l₂]
@[simp] theorem foldr_append (f : α → β → β) :
∀ (b : β) (l₁ l₂ : list α), foldr f b (l₁++l₂) = foldr f (foldr f b l₂) l₁
| b [] l₂ := rfl
| b (a::l₁) l₂ := by simp only [cons_append, foldr_cons, foldr_append b l₁ l₂]
@[simp] theorem foldl_join (f : α → β → α) :
∀ (a : α) (L : list (list β)), foldl f a (join L) = foldl (foldl f) a L
| a [] := rfl
| a (l::L) := by simp only [join, foldl_append, foldl_cons, foldl_join (foldl f a l) L]
@[simp] theorem foldr_join (f : α → β → β) :
∀ (b : β) (L : list (list α)), foldr f b (join L) = foldr (λ l b, foldr f b l) b L
| a [] := rfl
| a (l::L) := by simp only [join, foldr_append, foldr_join a L, foldr_cons]
theorem foldl_reverse (f : α → β → α) (a : α) (l : list β) :
foldl f a (reverse l) = foldr (λx y, f y x) a l :=
by induction l; [refl, simp only [*, reverse_cons, foldl_append, foldl_cons, foldl_nil, foldr]]
theorem foldr_reverse (f : α → β → β) (a : β) (l : list α) :
foldr f a (reverse l) = foldl (λx y, f y x) a l :=
let t := foldl_reverse (λx y, f y x) a (reverse l) in
by rw reverse_reverse l at t; rwa t
@[simp] theorem foldr_eta : ∀ (l : list α), foldr cons [] l = l
| [] := rfl
| (x::l) := by simp only [foldr_cons, foldr_eta l]; split; refl
@[simp] theorem reverse_foldl {l : list α} : reverse (foldl (λ t h, h :: t) [] l) = l :=
by rw ←foldr_reverse; simp
@[simp] theorem foldl_map (g : β → γ) (f : α → γ → α) (a : α) (l : list β) :
foldl f a (map g l) = foldl (λx y, f x (g y)) a l :=
by revert a; induction l; intros; [refl, simp only [*, map, foldl]]
@[simp] theorem foldr_map (g : β → γ) (f : γ → α → α) (a : α) (l : list β) :
foldr f a (map g l) = foldr (f ∘ g) a l :=
by revert a; induction l; intros; [refl, simp only [*, map, foldr]]
theorem foldl_map' {α β: Type u} (g : α → β) (f : α → α → α) (f' : β → β → β)
(a : α) (l : list α) (h : ∀ x y, f' (g x) (g y) = g (f x y)) :
list.foldl f' (g a) (l.map g) = g (list.foldl f a l) :=
begin
induction l generalizing a,
{ simp }, { simp [l_ih, h] }
end
theorem foldr_map' {α β: Type u} (g : α → β) (f : α → α → α) (f' : β → β → β)
(a : α) (l : list α) (h : ∀ x y, f' (g x) (g y) = g (f x y)) :
list.foldr f' (g a) (l.map g) = g (list.foldr f a l) :=
begin
induction l generalizing a,
{ simp }, { simp [l_ih, h] }
end
theorem foldl_hom (l : list γ) (f : α → β) (op : α → γ → α) (op' : β → γ → β) (a : α)
(h : ∀a x, f (op a x) = op' (f a) x) : foldl op' (f a) l = f (foldl op a l) :=
eq.symm $ by { revert a, induction l; intros; [refl, simp only [*, foldl]] }
theorem foldr_hom (l : list γ) (f : α → β) (op : γ → α → α) (op' : γ → β → β) (a : α)
(h : ∀x a, f (op x a) = op' x (f a)) : foldr op' (f a) l = f (foldr op a l) :=
by { revert a, induction l; intros; [refl, simp only [*, foldr]] }
lemma injective_foldl_comp {α : Type*} {l : list (α → α)} {f : α → α}
(hl : ∀ f ∈ l, function.injective f) (hf : function.injective f):
function.injective (@list.foldl (α → α) (α → α) function.comp f l) :=
begin
induction l generalizing f,
{ exact hf },
{ apply l_ih (λ _ h, hl _ (list.mem_cons_of_mem _ h)),
apply function.injective.comp hf,
apply hl _ (list.mem_cons_self _ _) }
end
/- scanl -/
section scanl
variables {f : β → α → β} {b : β} {a : α} {l : list α}
lemma length_scanl :
∀ a l, length (scanl f a l) = l.length + 1
| a [] := rfl
| a (x :: l) := by erw [length_cons, length_cons, length_scanl]
@[simp] lemma scanl_nil (b : β) : scanl f b nil = [b] := rfl
@[simp] lemma scanl_cons :
scanl f b (a :: l) = [b] ++ scanl f (f b a) l :=
by simp only [scanl, eq_self_iff_true, singleton_append, and_self]
@[simp] lemma nth_zero_scanl : (scanl f b l).nth 0 = some b :=
begin
cases l,
{ simp only [nth, scanl_nil] },
{ simp only [nth, scanl_cons, singleton_append] }
end
@[simp] lemma nth_le_zero_scanl {h : 0 < (scanl f b l).length} :
(scanl f b l).nth_le 0 h = b :=
begin
cases l,
{ simp only [nth_le, scanl_nil] },
{ simp only [nth_le, scanl_cons, singleton_append] }
end
lemma nth_succ_scanl {i : ℕ} :
(scanl f b l).nth (i + 1) = ((scanl f b l).nth i).bind (λ x, (l.nth i).map (λ y, f x y)) :=
begin
induction l with hd tl hl generalizing b i,
{ symmetry,
simp only [option.bind_eq_none', nth, forall_2_true_iff, not_false_iff, option.map_none',
scanl_nil, option.not_mem_none, forall_true_iff] },
{ simp only [nth, scanl_cons, singleton_append],
cases i,
{ simp only [option.map_some', nth_zero_scanl, nth, option.some_bind'] },
{ simp only [hl, nth] } }
end
lemma nth_le_succ_scanl {i : ℕ} {h : i + 1 < (scanl f b l).length} :
(scanl f b l).nth_le (i + 1) h =
f ((scanl f b l).nth_le i (nat.lt_of_succ_lt h))
(l.nth_le i (nat.lt_of_succ_lt_succ (lt_of_lt_of_le h (le_of_eq (length_scanl b l))))) :=
begin
induction i with i hi generalizing b l,
{ cases l,
{ simp only [length, zero_add, scanl_nil] at h,
exact absurd h (lt_irrefl 1) },
{ simp only [scanl_cons, singleton_append, nth_le_zero_scanl, nth_le] } },
{ cases l,
{ simp only [length, add_lt_iff_neg_right, scanl_nil] at h,
exact absurd h (not_lt_of_lt nat.succ_pos') },
{ simp_rw scanl_cons,
rw nth_le_append_right _,
{ simpa only [hi, length, succ_add_sub_one] },
{ simp only [length, nat.zero_le, le_add_iff_nonneg_left] } } }
end
end scanl
/- scanr -/
@[simp] theorem scanr_nil (f : α → β → β) (b : β) : scanr f b [] = [b] := rfl
@[simp] theorem scanr_aux_cons (f : α → β → β) (b : β) : ∀ (a : α) (l : list α),
scanr_aux f b (a::l) = (foldr f b (a::l), scanr f b l)
| a [] := rfl
| a (x::l) := let t := scanr_aux_cons x l in
by simp only [scanr, scanr_aux, t, foldr_cons]
@[simp] theorem scanr_cons (f : α → β → β) (b : β) (a : α) (l : list α) :
scanr f b (a::l) = foldr f b (a::l) :: scanr f b l :=
by simp only [scanr, scanr_aux_cons, foldr_cons]; split; refl
section foldl_eq_foldr
-- foldl and foldr coincide when f is commutative and associative
variables {f : α → α → α} (hcomm : commutative f) (hassoc : associative f)
include hassoc
theorem foldl1_eq_foldr1 : ∀ a b l, foldl f a (l++[b]) = foldr f b (a::l)
| a b nil := rfl
| a b (c :: l) :=
by simp only [cons_append, foldl_cons, foldr_cons, foldl1_eq_foldr1 _ _ l]; rw hassoc
include hcomm
theorem foldl_eq_of_comm_of_assoc : ∀ a b l, foldl f a (b::l) = f b (foldl f a l)
| a b nil := hcomm a b
| a b (c::l) := by simp only [foldl_cons];
rw [← foldl_eq_of_comm_of_assoc, right_comm _ hcomm hassoc]; refl
theorem foldl_eq_foldr : ∀ a l, foldl f a l = foldr f a l
| a nil := rfl
| a (b :: l) :=
by simp only [foldr_cons, foldl_eq_of_comm_of_assoc hcomm hassoc]; rw (foldl_eq_foldr a l)
end foldl_eq_foldr
section foldl_eq_foldlr'
variables {f : α → β → α}
variables hf : ∀ a b c, f (f a b) c = f (f a c) b
include hf
theorem foldl_eq_of_comm' : ∀ a b l, foldl f a (b::l) = f (foldl f a l) b
| a b [] := rfl
| a b (c :: l) := by rw [foldl,foldl,foldl,← foldl_eq_of_comm',foldl,hf]
theorem foldl_eq_foldr' : ∀ a l, foldl f a l = foldr (flip f) a l
| a [] := rfl
| a (b :: l) := by rw [foldl_eq_of_comm' hf,foldr,foldl_eq_foldr']; refl
end foldl_eq_foldlr'
section foldl_eq_foldlr'
variables {f : α → β → β}
variables hf : ∀ a b c, f a (f b c) = f b (f a c)
include hf
theorem foldr_eq_of_comm' : ∀ a b l, foldr f a (b::l) = foldr f (f b a) l
| a b [] := rfl
| a b (c :: l) := by rw [foldr,foldr,foldr,hf,← foldr_eq_of_comm']; refl
end foldl_eq_foldlr'
section
variables {op : α → α → α} [ha : is_associative α op] [hc : is_commutative α op]
local notation a * b := op a b
local notation l <*> a := foldl op a l
include ha
lemma foldl_assoc : ∀ {l : list α} {a₁ a₂}, l <*> (a₁ * a₂) = a₁ * (l <*> a₂)
| [] a₁ a₂ := rfl
| (a :: l) a₁ a₂ :=
calc a::l <*> (a₁ * a₂) = l <*> (a₁ * (a₂ * a)) : by simp only [foldl_cons, ha.assoc]
... = a₁ * (a::l <*> a₂) : by rw [foldl_assoc, foldl_cons]
lemma foldl_op_eq_op_foldr_assoc : ∀{l : list α} {a₁ a₂}, (l <*> a₁) * a₂ = a₁ * l.foldr (*) a₂
| [] a₁ a₂ := rfl
| (a :: l) a₁ a₂ := by simp only [foldl_cons, foldr_cons, foldl_assoc, ha.assoc];
rw [foldl_op_eq_op_foldr_assoc]
include hc
lemma foldl_assoc_comm_cons {l : list α} {a₁ a₂} : (a₁ :: l) <*> a₂ = a₁ * (l <*> a₂) :=
by rw [foldl_cons, hc.comm, foldl_assoc]
end
/-! ### mfoldl, mfoldr, mmap -/
section mfoldl_mfoldr
variables {m : Type v → Type w} [monad m]
@[simp] theorem mfoldl_nil (f : β → α → m β) {b} : mfoldl f b [] = pure b := rfl
@[simp] theorem mfoldr_nil (f : α → β → m β) {b} : mfoldr f b [] = pure b := rfl
@[simp] theorem mfoldl_cons {f : β → α → m β} {b a l} :
mfoldl f b (a :: l) = f b a >>= λ b', mfoldl f b' l := rfl
@[simp] theorem mfoldr_cons {f : α → β → m β} {b a l} :
mfoldr f b (a :: l) = mfoldr f b l >>= f a := rfl
theorem mfoldr_eq_foldr (f : α → β → m β) (b l) :
mfoldr f b l = foldr (λ a mb, mb >>= f a) (pure b) l :=
by induction l; simp *
attribute [simp] mmap mmap'
variables [is_lawful_monad m]
theorem mfoldl_eq_foldl (f : β → α → m β) (b l) :
mfoldl f b l = foldl (λ mb a, mb >>= λ b, f b a) (pure b) l :=
begin
suffices h : ∀ (mb : m β),
(mb >>= λ b, mfoldl f b l) = foldl (λ mb a, mb >>= λ b, f b a) mb l,
by simp [←h (pure b)],
induction l; intro,
{ simp },
{ simp only [mfoldl, foldl, ←l_ih] with monad_norm }
end
@[simp] theorem mfoldl_append {f : β → α → m β} : ∀ {b l₁ l₂},
mfoldl f b (l₁ ++ l₂) = mfoldl f b l₁ >>= λ x, mfoldl f x l₂
| _ [] _ := by simp only [nil_append, mfoldl_nil, pure_bind]
| _ (_::_) _ := by simp only [cons_append, mfoldl_cons, mfoldl_append, bind_assoc]
@[simp] theorem mfoldr_append {f : α → β → m β} : ∀ {b l₁ l₂},
mfoldr f b (l₁ ++ l₂) = mfoldr f b l₂ >>= λ x, mfoldr f x l₁
| _ [] _ := by simp only [nil_append, mfoldr_nil, bind_pure]
| _ (_::_) _ := by simp only [mfoldr_cons, cons_append, mfoldr_append, bind_assoc]
end mfoldl_mfoldr
/-! ### prod and sum -/
-- list.sum was already defined in defs.lean, but we couldn't tag it with `to_additive` yet.
attribute [to_additive] list.prod
section monoid
variables [monoid α] {l l₁ l₂ : list α} {a : α}
@[simp, to_additive]
theorem prod_nil : ([] : list α).prod = 1 := rfl
@[to_additive]
theorem prod_singleton : [a].prod = a := one_mul a
@[simp, to_additive]
theorem prod_cons : (a::l).prod = a * l.prod :=
calc (a::l).prod = foldl (*) (a * 1) l : by simp only [list.prod, foldl_cons, one_mul, mul_one]
... = _ : foldl_assoc
@[simp, to_additive]
theorem prod_append : (l₁ ++ l₂).prod = l₁.prod * l₂.prod :=
calc (l₁ ++ l₂).prod = foldl (*) (foldl (*) 1 l₁ * 1) l₂ : by simp [list.prod]
... = l₁.prod * l₂.prod : foldl_assoc
@[simp, to_additive]
theorem prod_join {l : list (list α)} : l.join.prod = (l.map list.prod).prod :=
by induction l; [refl, simp only [*, list.join, map, prod_append, prod_cons]]
theorem prod_ne_zero {R : Type*} [domain R] {L : list R} :
(∀ x ∈ L, (x : _) ≠ 0) → L.prod ≠ 0 :=
list.rec_on L (λ _, one_ne_zero) $ λ hd tl ih H,
by { rw forall_mem_cons at H, rw prod_cons, exact mul_ne_zero H.1 (ih H.2) }
@[to_additive]
theorem prod_eq_foldr : l.prod = foldr (*) 1 l :=
list.rec_on l rfl $ λ a l ihl, by rw [prod_cons, foldr_cons, ihl]
@[to_additive]
theorem prod_hom_rel {α β γ : Type*} [monoid β] [monoid γ] (l : list α) {r : β → γ → Prop}
{f : α → β} {g : α → γ} (h₁ : r 1 1) (h₂ : ∀⦃a b c⦄, r b c → r (f a * b) (g a * c)) :
r (l.map f).prod (l.map g).prod :=
list.rec_on l h₁ (λ a l hl, by simp only [map_cons, prod_cons, h₂ hl])
@[to_additive]
theorem prod_hom [monoid β] (l : list α) (f : α →* β) :
(l.map f).prod = f l.prod :=
by { simp only [prod, foldl_map, f.map_one.symm],
exact l.foldl_hom _ _ _ 1 f.map_mul }
-- `to_additive` chokes on the next few lemmas, so we do them by hand below
@[simp]
lemma prod_take_mul_prod_drop :
∀ (L : list α) (i : ℕ), (L.take i).prod * (L.drop i).prod = L.prod
| [] i := by simp
| L 0 := by simp
| (h :: t) (n+1) := by { dsimp, rw [prod_cons, prod_cons, mul_assoc, prod_take_mul_prod_drop], }
@[simp]
lemma prod_take_succ :
∀ (L : list α) (i : ℕ) (p), (L.take (i + 1)).prod = (L.take i).prod * L.nth_le i p
| [] i p := by cases p
| (h :: t) 0 _ := by simp
| (h :: t) (n+1) _ := by { dsimp, rw [prod_cons, prod_cons, prod_take_succ, mul_assoc], }
/-- A list with product not one must have positive length. -/
lemma length_pos_of_prod_ne_one (L : list α) (h : L.prod ≠ 1) : 0 < L.length :=
by { cases L, { simp at h, cases h, }, { simp, }, }
lemma prod_update_nth : ∀ (L : list α) (n : ℕ) (a : α),
(L.update_nth n a).prod =
(L.take n).prod * (if n < L.length then a else 1) * (L.drop (n + 1)).prod
| (x::xs) 0 a := by simp [update_nth]
| (x::xs) (i+1) a := by simp [update_nth, prod_update_nth xs i a, mul_assoc]
| [] _ _ := by simp [update_nth, (nat.zero_le _).not_lt]
end monoid
section group
variables [group α]
/-- This is the `list.prod` version of `mul_inv_rev` -/
@[to_additive "This is the `list.sum` version of `add_neg_rev`"]
lemma prod_inv_reverse : ∀ (L : list α), L.prod⁻¹ = (L.map (λ x, x⁻¹)).reverse.prod
| [] := by simp
| (x :: xs) := by simp [prod_inv_reverse xs]
/-- A non-commutative variant of `list.prod_reverse` -/
@[to_additive "A non-commutative variant of `list.sum_reverse`"]
lemma prod_reverse_noncomm : ∀ (L : list α), L.reverse.prod = (L.map (λ x, x⁻¹)).prod⁻¹ :=
by simp [prod_inv_reverse]
end group
section comm_group
variables [comm_group α]
/-- This is the `list.prod` version of `mul_inv` -/
@[to_additive "This is the `list.sum` version of `add_neg`"]
lemma prod_inv : ∀ (L : list α), L.prod⁻¹ = (L.map (λ x, x⁻¹)).prod
| [] := by simp
| (x :: xs) := by simp [mul_comm, prod_inv xs]
end comm_group
@[simp]
lemma sum_take_add_sum_drop [add_monoid α] :
∀ (L : list α) (i : ℕ), (L.take i).sum + (L.drop i).sum = L.sum
| [] i := by simp
| L 0 := by simp
| (h :: t) (n+1) := by { dsimp, rw [sum_cons, sum_cons, add_assoc, sum_take_add_sum_drop], }
@[simp]
lemma sum_take_succ [add_monoid α] :
∀ (L : list α) (i : ℕ) (p), (L.take (i + 1)).sum = (L.take i).sum + L.nth_le i p
| [] i p := by cases p
| (h :: t) 0 _ := by simp
| (h :: t) (n+1) _ := by { dsimp, rw [sum_cons, sum_cons, sum_take_succ, add_assoc], }
lemma eq_of_sum_take_eq [add_left_cancel_monoid α] {L L' : list α} (h : L.length = L'.length)
(h' : ∀ i ≤ L.length, (L.take i).sum = (L'.take i).sum) : L = L' :=
begin
apply ext_le h (λ i h₁ h₂, _),
have : (L.take (i + 1)).sum = (L'.take (i + 1)).sum := h' _ (nat.succ_le_of_lt h₁),
rw [sum_take_succ L i h₁, sum_take_succ L' i h₂, h' i (le_of_lt h₁)] at this,
exact add_left_cancel this
end
lemma monotone_sum_take [canonically_ordered_add_monoid α] (L : list α) :
monotone (λ i, (L.take i).sum) :=
begin
apply monotone_of_monotone_nat (λ n, _),
by_cases h : n < L.length,
{ rw sum_take_succ _ _ h,
exact le_add_right (le_refl _) },
{ push_neg at h,
simp [take_all_of_le h, take_all_of_le (le_trans h (nat.le_succ _))] }
end
@[to_additive sum_nonneg]
lemma one_le_prod_of_one_le [ordered_comm_monoid α] {l : list α} (hl₁ : ∀ x ∈ l, (1 : α) ≤ x) :
1 ≤ l.prod :=
begin
induction l with hd tl ih,
{ simp },
rw prod_cons,
exact one_le_mul (hl₁ hd (mem_cons_self hd tl)) (ih (λ x h, hl₁ x (mem_cons_of_mem hd h))),
end
@[to_additive]
lemma single_le_prod [ordered_comm_monoid α] {l : list α} (hl₁ : ∀ x ∈ l, (1 : α) ≤ x) :
∀ x ∈ l, x ≤ l.prod :=
begin
induction l,
{ simp },
simp_rw [prod_cons, forall_mem_cons] at ⊢ hl₁,
split,
{ exact le_mul_of_one_le_right' (one_le_prod_of_one_le hl₁.2) },
{ exact λ x H, le_mul_of_one_le_of_le hl₁.1 (l_ih hl₁.right x H) },
end
@[to_additive all_zero_of_le_zero_le_of_sum_eq_zero]
lemma all_one_of_le_one_le_of_prod_eq_one [ordered_comm_monoid α]
{l : list α} (hl₁ : ∀ x ∈ l, (1 : α) ≤ x) (hl₂ : l.prod = 1) :
∀ x ∈ l, x = (1 : α) :=
λ x hx, le_antisymm (hl₂ ▸ single_le_prod hl₁ _ hx) (hl₁ x hx)
lemma sum_eq_zero_iff [canonically_ordered_add_monoid α] (l : list α) :
l.sum = 0 ↔ ∀ x ∈ l, x = (0 : α) :=
⟨all_zero_of_le_zero_le_of_sum_eq_zero (λ _ _, zero_le _),
begin
induction l,
{ simp },
{ intro h,
rw [sum_cons, add_eq_zero_iff],
rw forall_mem_cons at h,
exact ⟨h.1, l_ih h.2⟩ },
end⟩
/-- A list with sum not zero must have positive length. -/
lemma length_pos_of_sum_ne_zero [add_monoid α] (L : list α) (h : L.sum ≠ 0) : 0 < L.length :=
by { cases L, { simp at h, cases h, }, { simp, }, }
/-- If all elements in a list are bounded below by `1`, then the length of the list is bounded
by the sum of the elements. -/
lemma length_le_sum_of_one_le (L : list ℕ) (h : ∀ i ∈ L, 1 ≤ i) : L.length ≤ L.sum :=
begin
induction L with j L IH h, { simp },
rw [sum_cons, length, add_comm],
exact add_le_add (h _ (set.mem_insert _ _)) (IH (λ i hi, h i (set.mem_union_right _ hi)))
end
-- Now we tie those lemmas back to their multiplicative versions.
attribute [to_additive] prod_take_mul_prod_drop prod_take_succ length_pos_of_prod_ne_one
/-- A list with positive sum must have positive length. -/
-- This is an easy consequence of `length_pos_of_sum_ne_zero`, but often useful in applications.
lemma length_pos_of_sum_pos [ordered_cancel_add_comm_monoid α] (L : list α) (h : 0 < L.sum) :
0 < L.length :=
length_pos_of_sum_ne_zero L (ne_of_gt h)
@[simp, to_additive]
theorem prod_erase [decidable_eq α] [comm_monoid α] {a} :
Π {l : list α}, a ∈ l → a * (l.erase a).prod = l.prod
| (b::l) h :=
begin
rcases eq_or_ne_mem_of_mem h with rfl | ⟨ne, h⟩,
{ simp only [list.erase, if_pos, prod_cons] },
{ simp only [list.erase, if_neg (mt eq.symm ne), prod_cons, prod_erase h, mul_left_comm a b] }
end
lemma dvd_prod [comm_monoid α] {a} {l : list α} (ha : a ∈ l) : a ∣ l.prod :=
let ⟨s, t, h⟩ := mem_split ha in
by rw [h, prod_append, prod_cons, mul_left_comm]; exact dvd_mul_right _ _
@[simp] theorem sum_const_nat (m n : ℕ) : sum (list.repeat m n) = m * n :=
by induction n; [refl, simp only [*, repeat_succ, sum_cons, nat.mul_succ, add_comm]]
theorem dvd_sum [comm_semiring α] {a} {l : list α} (h : ∀ x ∈ l, a ∣ x) : a ∣ l.sum :=
begin
induction l with x l ih,
{ exact dvd_zero _ },
{ rw [list.sum_cons],
exact dvd_add (h _ (mem_cons_self _ _)) (ih (λ x hx, h x (mem_cons_of_mem _ hx))) }
end
@[simp] theorem length_join (L : list (list α)) : length (join L) = sum (map length L) :=
by induction L; [refl, simp only [*, join, map, sum_cons, length_append]]
@[simp] theorem length_bind (l : list α) (f : α → list β) :
length (list.bind l f) = sum (map (length ∘ f) l) :=
by rw [list.bind, length_join, map_map]
lemma exists_lt_of_sum_lt [linear_ordered_cancel_add_comm_monoid β] {l : list α}
(f g : α → β) (h : (l.map f).sum < (l.map g).sum) : ∃ x ∈ l, f x < g x :=
begin
induction l with x l,
{ exfalso, exact lt_irrefl _ h },
{ by_cases h' : f x < g x, exact ⟨x, mem_cons_self _ _, h'⟩,
rcases l_ih _ with ⟨y, h1y, h2y⟩, refine ⟨y, mem_cons_of_mem x h1y, h2y⟩, simp at h,
exact lt_of_add_lt_add_left (lt_of_lt_of_le h $ add_le_add_right (le_of_not_gt h') _) }
end
lemma exists_le_of_sum_le [linear_ordered_cancel_add_comm_monoid β] {l : list α}
(hl : l ≠ []) (f g : α → β) (h : (l.map f).sum ≤ (l.map g).sum) : ∃ x ∈ l, f x ≤ g x :=
begin
cases l with x l,
{ contradiction },
{ by_cases h' : f x ≤ g x, exact ⟨x, mem_cons_self _ _, h'⟩,
rcases exists_lt_of_sum_lt f g _ with ⟨y, h1y, h2y⟩,
exact ⟨y, mem_cons_of_mem x h1y, le_of_lt h2y⟩, simp at h,
exact lt_of_add_lt_add_left (lt_of_le_of_lt h $ add_lt_add_right (lt_of_not_ge h') _) }
end
-- Several lemmas about sum/head/tail for `list ℕ`.
-- These are hard to generalize well, as they rely on the fact that `default ℕ = 0`.
-- We'd like to state this as `L.head * L.tail.prod = L.prod`,
-- but because `L.head` relies on an inhabited instances and
-- returns a garbage value for the empty list, this is not possible.
-- Instead we write the statement in terms of `(L.nth 0).get_or_else 1`,
-- and below, restate the lemma just for `ℕ`.
@[to_additive]
lemma head_mul_tail_prod' [monoid α] (L : list α) :
(L.nth 0).get_or_else 1 * L.tail.prod = L.prod :=
by { cases L, { simp, refl, }, { simp, }, }
lemma head_add_tail_sum (L : list ℕ) : L.head + L.tail.sum = L.sum :=
by { cases L, { simp, refl, }, { simp, }, }
lemma head_le_sum (L : list ℕ) : L.head ≤ L.sum :=
nat.le.intro (head_add_tail_sum L)
lemma tail_sum (L : list ℕ) : L.tail.sum = L.sum - L.head :=
by rw [← head_add_tail_sum L, add_comm, nat.add_sub_cancel]
section
variables {G : Type*} [comm_group G]
attribute [to_additive] alternating_prod
@[simp, to_additive] lemma alternating_prod_nil :
alternating_prod ([] : list G) = 1 := rfl
@[simp, to_additive] lemma alternating_prod_singleton (g : G) :
alternating_prod [g] = g := rfl
@[simp, to_additive alternating_sum_cons_cons']
lemma alternating_prod_cons_cons (g h : G) (l : list G) :
alternating_prod (g :: h :: l) = g * h⁻¹ * alternating_prod l := rfl
lemma alternating_sum_cons_cons {G : Type*} [add_comm_group G] (g h : G) (l : list G) :
alternating_sum (g :: h :: l) = g - h + alternating_sum l :=
by rw [sub_eq_add_neg, alternating_sum]
end
/-! ### join -/
attribute [simp] join
theorem join_eq_nil : ∀ {L : list (list α)}, join L = [] ↔ ∀ l ∈ L, l = []
| [] := iff_of_true rfl (forall_mem_nil _)
| (l::L) := by simp only [join, append_eq_nil, join_eq_nil, forall_mem_cons]
@[simp] theorem join_append (L₁ L₂ : list (list α)) : join (L₁ ++ L₂) = join L₁ ++ join L₂ :=
by induction L₁; [refl, simp only [*, join, cons_append, append_assoc]]
lemma join_join (l : list (list (list α))) : l.join.join = (l.map join).join :=
by { induction l, simp, simp [l_ih] }
/-- In a join, taking the first elements up to an index which is the sum of the lengths of the
first `i` sublists, is the same as taking the join of the first `i` sublists. -/
lemma take_sum_join (L : list (list α)) (i : ℕ) :
L.join.take ((L.map length).take i).sum = (L.take i).join :=
begin
induction L generalizing i, { simp },
cases i, { simp },
simp [take_append, L_ih]
end
/-- In a join, dropping all the elements up to an index which is the sum of the lengths of the
first `i` sublists, is the same as taking the join after dropping the first `i` sublists. -/
lemma drop_sum_join (L : list (list α)) (i : ℕ) :
L.join.drop ((L.map length).take i).sum = (L.drop i).join :=
begin
induction L generalizing i, { simp },
cases i, { simp },
simp [drop_append, L_ih],
end
/-- Taking only the first `i+1` elements in a list, and then dropping the first `i` ones, one is
left with a list of length `1` made of the `i`-th element of the original list. -/
lemma drop_take_succ_eq_cons_nth_le (L : list α) {i : ℕ} (hi : i < L.length) :
(L.take (i+1)).drop i = [nth_le L i hi] :=
begin
induction L generalizing i,
{ simp only [length] at hi, exact (nat.not_succ_le_zero i hi).elim },
cases i, { simp },
have : i < L_tl.length,
{ simp at hi,
exact nat.lt_of_succ_lt_succ hi },
simp [L_ih this],
refl
end
/-- In a join of sublists, taking the slice between the indices `A` and `B - 1` gives back the
original sublist of index `i` if `A` is the sum of the lenghts of sublists of index `< i`, and
`B` is the sum of the lengths of sublists of index `≤ i`. -/
lemma drop_take_succ_join_eq_nth_le (L : list (list α)) {i : ℕ} (hi : i < L.length) :
(L.join.take ((L.map length).take (i+1)).sum).drop ((L.map length).take i).sum = nth_le L i hi :=
begin
have : (L.map length).take i = ((L.take (i+1)).map length).take i, by simp [map_take, take_take],
simp [take_sum_join, this, drop_sum_join, drop_take_succ_eq_cons_nth_le _ hi]
end
/-- Auxiliary lemma to control elements in a join. -/
lemma sum_take_map_length_lt1 (L : list (list α)) {i j : ℕ}
(hi : i < L.length) (hj : j < (nth_le L i hi).length) :
((L.map length).take i).sum + j < ((L.map length).take (i+1)).sum :=
by simp [hi, sum_take_succ, hj]
/-- Auxiliary lemma to control elements in a join. -/
lemma sum_take_map_length_lt2 (L : list (list α)) {i j : ℕ}
(hi : i < L.length) (hj : j < (nth_le L i hi).length) :
((L.map length).take i).sum + j < L.join.length :=
begin
convert lt_of_lt_of_le (sum_take_map_length_lt1 L hi hj) (monotone_sum_take _ hi),
have : L.length = (L.map length).length, by simp,
simp [this, -length_map]
end
/-- The `n`-th element in a join of sublists is the `j`-th element of the `i`th sublist,
where `n` can be obtained in terms of `i` and `j` by adding the lengths of all the sublists
of index `< i`, and adding `j`. -/
lemma nth_le_join (L : list (list α)) {i j : ℕ}
(hi : i < L.length) (hj : j < (nth_le L i hi).length) :
nth_le L.join (((L.map length).take i).sum + j) (sum_take_map_length_lt2 L hi hj) =
nth_le (nth_le L i hi) j hj :=
by rw [nth_le_take L.join (sum_take_map_length_lt2 L hi hj) (sum_take_map_length_lt1 L hi hj),
nth_le_drop, nth_le_of_eq (drop_take_succ_join_eq_nth_le L hi)]
/-- Two lists of sublists are equal iff their joins coincide, as well as the lengths of the
sublists. -/
theorem eq_iff_join_eq (L L' : list (list α)) :
L = L' ↔ L.join = L'.join ∧ map length L = map length L' :=
begin
refine ⟨λ H, by simp [H], _⟩,
rintros ⟨join_eq, length_eq⟩,
apply ext_le,
{ have : length (map length L) = length (map length L'), by rw length_eq,
simpa using this },
{ assume n h₁ h₂,
rw [← drop_take_succ_join_eq_nth_le, ← drop_take_succ_join_eq_nth_le, join_eq, length_eq] }
end
/-! ### lexicographic ordering -/
/-- Given a strict order `<` on `α`, the lexicographic strict order on `list α`, for which
`[a0, ..., an] < [b0, ..., b_k]` if `a0 < b0` or `a0 = b0` and `[a1, ..., an] < [b1, ..., bk]`.
The definition is given for any relation `r`, not only strict orders. -/
inductive lex (r : α → α → Prop) : list α → list α → Prop
| nil {a l} : lex [] (a :: l)
| cons {a l₁ l₂} (h : lex l₁ l₂) : lex (a :: l₁) (a :: l₂)
| rel {a₁ l₁ a₂ l₂} (h : r a₁ a₂) : lex (a₁ :: l₁) (a₂ :: l₂)
namespace lex
theorem cons_iff {r : α → α → Prop} [is_irrefl α r] {a l₁ l₂} :
lex r (a :: l₁) (a :: l₂) ↔ lex r l₁ l₂ :=
⟨λ h, by cases h with _ _ _ _ _ h _ _ _ _ h;
[exact h, exact (irrefl_of r a h).elim], lex.cons⟩
@[simp] theorem not_nil_right (r : α → α → Prop) (l : list α) : ¬ lex r l [].
instance is_order_connected (r : α → α → Prop)
[is_order_connected α r] [is_trichotomous α r] :
is_order_connected (list α) (lex r) :=
⟨λ l₁, match l₁ with
| _, [], c::l₃, nil := or.inr nil
| _, [], c::l₃, rel _ := or.inr nil
| _, [], c::l₃, cons _ := or.inr nil
| _, b::l₂, c::l₃, nil := or.inl nil
| a::l₁, b::l₂, c::l₃, rel h :=
(is_order_connected.conn _ b _ h).imp rel rel
| a::l₁, b::l₂, _::l₃, cons h := begin
rcases trichotomous_of r a b with ab | rfl | ab,
{ exact or.inl (rel ab) },
{ exact (_match _ l₂ _ h).imp cons cons },
{ exact or.inr (rel ab) }
end
end⟩
instance is_trichotomous (r : α → α → Prop) [is_trichotomous α r] :
is_trichotomous (list α) (lex r) :=
⟨λ l₁, match l₁ with
| [], [] := or.inr (or.inl rfl)
| [], b::l₂ := or.inl nil
| a::l₁, [] := or.inr (or.inr nil)
| a::l₁, b::l₂ := begin
rcases trichotomous_of r a b with ab | rfl | ab,
{ exact or.inl (rel ab) },
{ exact (_match l₁ l₂).imp cons
(or.imp (congr_arg _) cons) },
{ exact or.inr (or.inr (rel ab)) }
end
end⟩
instance is_asymm (r : α → α → Prop)
[is_asymm α r] : is_asymm (list α) (lex r) :=
⟨λ l₁, match l₁ with
| a::l₁, b::l₂, lex.rel h₁, lex.rel h₂ := asymm h₁ h₂
| a::l₁, b::l₂, lex.rel h₁, lex.cons h₂ := asymm h₁ h₁
| a::l₁, b::l₂, lex.cons h₁, lex.rel h₂ := asymm h₂ h₂
| a::l₁, b::l₂, lex.cons h₁, lex.cons h₂ :=
by exact _match _ _ h₁ h₂
end⟩
instance is_strict_total_order (r : α → α → Prop)
[is_strict_total_order' α r] : is_strict_total_order' (list α) (lex r) :=
{..is_strict_weak_order_of_is_order_connected}
instance decidable_rel [decidable_eq α] (r : α → α → Prop)
[decidable_rel r] : decidable_rel (lex r)
| l₁ [] := is_false $ λ h, by cases h
| [] (b::l₂) := is_true lex.nil
| (a::l₁) (b::l₂) := begin
haveI := decidable_rel l₁ l₂,
refine decidable_of_iff (r a b ∨ a = b ∧ lex r l₁ l₂) ⟨λ h, _, λ h, _⟩,
{ rcases h with h | ⟨rfl, h⟩,
{ exact lex.rel h },
{ exact lex.cons h } },
{ rcases h with _|⟨_,_,_,h⟩|⟨_,_,_,_,h⟩,
{ exact or.inr ⟨rfl, h⟩ },
{ exact or.inl h } }
end
theorem append_right (r : α → α → Prop) :
∀ {s₁ s₂} t, lex r s₁ s₂ → lex r s₁ (s₂ ++ t)
| _ _ t nil := nil
| _ _ t (cons h) := cons (append_right _ h)
| _ _ t (rel r) := rel r
theorem append_left (R : α → α → Prop) {t₁ t₂} (h : lex R t₁ t₂) :
∀ s, lex R (s ++ t₁) (s ++ t₂)
| [] := h
| (a::l) := cons (append_left l)
theorem imp {r s : α → α → Prop} (H : ∀ a b, r a b → s a b) :
∀ l₁ l₂, lex r l₁ l₂ → lex s l₁ l₂
| _ _ nil := nil
| _ _ (cons h) := cons (imp _ _ h)
| _ _ (rel r) := rel (H _ _ r)
theorem to_ne : ∀ {l₁ l₂ : list α}, lex (≠) l₁ l₂ → l₁ ≠ l₂
| _ _ (cons h) e := to_ne h (list.cons.inj e).2
| _ _ (rel r) e := r (list.cons.inj e).1
theorem ne_iff {l₁ l₂ : list α} (H : length l₁ ≤ length l₂) :
lex (≠) l₁ l₂ ↔ l₁ ≠ l₂ :=
⟨to_ne, λ h, begin
induction l₁ with a l₁ IH generalizing l₂; cases l₂ with b l₂,
{ contradiction },
{ apply nil },
{ exact (not_lt_of_ge H).elim (succ_pos _) },
{ cases classical.em (a = b) with ab ab,
{ subst b, apply cons,
exact IH (le_of_succ_le_succ H) (mt (congr_arg _) h) },
{ exact rel ab } }
end⟩
end lex
--Note: this overrides an instance in core lean
instance has_lt' [has_lt α] : has_lt (list α) := ⟨lex (<)⟩
theorem nil_lt_cons [has_lt α] (a : α) (l : list α) : [] < a :: l :=
lex.nil
instance [linear_order α] : linear_order (list α) :=
linear_order_of_STO' (lex (<))
--Note: this overrides an instance in core lean
instance has_le' [linear_order α] : has_le (list α) :=
preorder.to_has_le _
/-! ### all & any -/
@[simp] theorem all_nil (p : α → bool) : all [] p = tt := rfl
@[simp] theorem all_cons (p : α → bool) (a : α) (l : list α) :
all (a::l) p = (p a && all l p) := rfl
theorem all_iff_forall {p : α → bool} {l : list α} : all l p ↔ ∀ a ∈ l, p a :=
begin
induction l with a l ih,
{ exact iff_of_true rfl (forall_mem_nil _) },
simp only [all_cons, band_coe_iff, ih, forall_mem_cons]
end
theorem all_iff_forall_prop {p : α → Prop} [decidable_pred p]
{l : list α} : all l (λ a, p a) ↔ ∀ a ∈ l, p a :=
by simp only [all_iff_forall, bool.of_to_bool_iff]
@[simp] theorem any_nil (p : α → bool) : any [] p = ff := rfl
@[simp] theorem any_cons (p : α → bool) (a : α) (l : list α) :
any (a::l) p = (p a || any l p) := rfl
theorem any_iff_exists {p : α → bool} {l : list α} : any l p ↔ ∃ a ∈ l, p a :=
begin
induction l with a l ih,
{ exact iff_of_false bool.not_ff (not_exists_mem_nil _) },
simp only [any_cons, bor_coe_iff, ih, exists_mem_cons_iff]
end
theorem any_iff_exists_prop {p : α → Prop} [decidable_pred p]
{l : list α} : any l (λ a, p a) ↔ ∃ a ∈ l, p a :=
by simp [any_iff_exists]
theorem any_of_mem {p : α → bool} {a : α} {l : list α} (h₁ : a ∈ l) (h₂ : p a) : any l p :=
any_iff_exists.2 ⟨_, h₁, h₂⟩
@[priority 500] instance decidable_forall_mem {p : α → Prop} [decidable_pred p] (l : list α) :
decidable (∀ x ∈ l, p x) :=
decidable_of_iff _ all_iff_forall_prop
instance decidable_exists_mem {p : α → Prop} [decidable_pred p] (l : list α) :
decidable (∃ x ∈ l, p x) :=
decidable_of_iff _ any_iff_exists_prop
/-! ### map for partial functions -/
/-- Partial map. If `f : Π a, p a → β` is a partial function defined on
`a : α` satisfying `p`, then `pmap f l h` is essentially the same as `map f l`
but is defined only when all members of `l` satisfy `p`, using the proof
to apply `f`. -/
@[simp] def pmap {p : α → Prop} (f : Π a, p a → β) : Π l : list α, (∀ a ∈ l, p a) → list β
| [] H := []
| (a::l) H := f a (forall_mem_cons.1 H).1 :: pmap l (forall_mem_cons.1 H).2
/-- "Attach" the proof that the elements of `l` are in `l` to produce a new list
with the same elements but in the type `{x // x ∈ l}`. -/
def attach (l : list α) : list {x // x ∈ l} := pmap subtype.mk l (λ a, id)
theorem sizeof_lt_sizeof_of_mem [has_sizeof α] {x : α} {l : list α} (hx : x ∈ l) :
sizeof x < sizeof l :=
begin
induction l with h t ih; cases hx,
{ rw hx, exact lt_add_of_lt_of_nonneg (lt_one_add _) (nat.zero_le _) },
{ exact lt_add_of_pos_of_le (zero_lt_one_add _) (le_of_lt (ih hx)) }
end
theorem pmap_eq_map (p : α → Prop) (f : α → β) (l : list α) (H) :
@pmap _ _ p (λ a _, f a) l H = map f l :=
by induction l; [refl, simp only [*, pmap, map]]; split; refl
theorem pmap_congr {p q : α → Prop} {f : Π a, p a → β} {g : Π a, q a → β}
(l : list α) {H₁ H₂} (h : ∀ a h₁ h₂, f a h₁ = g a h₂) :
pmap f l H₁ = pmap g l H₂ :=
by induction l with _ _ ih; [refl, rw [pmap, pmap, h, ih]]
theorem map_pmap {p : α → Prop} (g : β → γ) (f : Π a, p a → β)
(l H) : map g (pmap f l H) = pmap (λ a h, g (f a h)) l H :=
by induction l; [refl, simp only [*, pmap, map]]; split; refl
theorem pmap_map {p : β → Prop} (g : ∀ b, p b → γ) (f : α → β)
(l H) : pmap g (map f l) H = pmap (λ a h, g (f a) h) l (λ a h, H _ (mem_map_of_mem _ h)) :=
by induction l; [refl, simp only [*, pmap, map]]; split; refl
theorem pmap_eq_map_attach {p : α → Prop} (f : Π a, p a → β)
(l H) : pmap f l H = l.attach.map (λ x, f x.1 (H _ x.2)) :=
by rw [attach, map_pmap]; exact pmap_congr l (λ a h₁ h₂, rfl)
theorem attach_map_val (l : list α) : l.attach.map subtype.val = l :=
by rw [attach, map_pmap]; exact (pmap_eq_map _ _ _ _).trans (map_id l)
@[simp] theorem mem_attach (l : list α) : ∀ x, x ∈ l.attach | ⟨a, h⟩ :=
by have := mem_map.1 (by rw [attach_map_val]; exact h);
{ rcases this with ⟨⟨_, _⟩, m, rfl⟩, exact m }
@[simp] theorem mem_pmap {p : α → Prop} {f : Π a, p a → β}
{l H b} : b ∈ pmap f l H ↔ ∃ a (h : a ∈ l), f a (H a h) = b :=
by simp only [pmap_eq_map_attach, mem_map, mem_attach, true_and, subtype.exists]
@[simp] theorem length_pmap {p : α → Prop} {f : Π a, p a → β}
{l H} : length (pmap f l H) = length l :=
by induction l; [refl, simp only [*, pmap, length]]
@[simp] lemma length_attach (L : list α) : L.attach.length = L.length := length_pmap
@[simp] lemma pmap_eq_nil {p : α → Prop} {f : Π a, p a → β}
{l H} : pmap f l H = [] ↔ l = [] :=
by rw [← length_eq_zero, length_pmap, length_eq_zero]
@[simp] lemma attach_eq_nil (l : list α) : l.attach = [] ↔ l = [] := pmap_eq_nil
lemma last_pmap {α β : Type*} (p : α → Prop) (f : Π a, p a → β)
(l : list α) (hl₁ : ∀ a ∈ l, p a) (hl₂ : l ≠ []) :
(l.pmap f hl₁).last (mt list.pmap_eq_nil.1 hl₂) = f (l.last hl₂) (hl₁ _ (list.last_mem hl₂)) :=
begin
induction l with l_hd l_tl l_ih,
{ apply (hl₂ rfl).elim },
{ cases l_tl,
{ simp },
{ apply l_ih } }
end
lemma nth_pmap {p : α → Prop} (f : Π a, p a → β) {l : list α} (h : ∀ a ∈ l, p a) (n : ℕ) :
nth (pmap f l h) n = option.pmap f (nth l n) (λ x H, h x (nth_mem H)) :=
begin
induction l with hd tl hl generalizing n,
{ simp },
{ cases n; simp [hl] }
end
lemma nth_le_pmap {p : α → Prop} (f : Π a, p a → β) {l : list α} (h : ∀ a ∈ l, p a) {n : ℕ}
(hn : n < (pmap f l h).length) :
nth_le (pmap f l h) n hn = f (nth_le l n (@length_pmap _ _ p f l h ▸ hn))
(h _ (nth_le_mem l n (@length_pmap _ _ p f l h ▸ hn))) :=
begin
induction l with hd tl hl generalizing n,
{ simp only [length, pmap] at hn,
exact absurd hn (not_lt_of_le n.zero_le) },
{ cases n,
{ simp },
{ simpa [hl] } }
end
/-! ### find -/
section find
variables {p : α → Prop} [decidable_pred p] {l : list α} {a : α}
@[simp] theorem find_nil (p : α → Prop) [decidable_pred p] : find p [] = none :=
rfl
@[simp] theorem find_cons_of_pos (l) (h : p a) : find p (a::l) = some a :=
if_pos h
@[simp] theorem find_cons_of_neg (l) (h : ¬ p a) : find p (a::l) = find p l :=
if_neg h
@[simp] theorem find_eq_none : find p l = none ↔ ∀ x ∈ l, ¬ p x :=
begin
induction l with a l IH,
{ exact iff_of_true rfl (forall_mem_nil _) },
rw forall_mem_cons, by_cases h : p a,
{ simp only [find_cons_of_pos _ h, h, not_true, false_and] },
{ rwa [find_cons_of_neg _ h, iff_true_intro h, true_and] }
end
theorem find_some (H : find p l = some a) : p a :=
begin
induction l with b l IH, {contradiction},
by_cases h : p b,
{ rw find_cons_of_pos _ h at H, cases H, exact h },
{ rw find_cons_of_neg _ h at H, exact IH H }
end
@[simp] theorem find_mem (H : find p l = some a) : a ∈ l :=
begin
induction l with b l IH, {contradiction},
by_cases h : p b,
{ rw find_cons_of_pos _ h at H, cases H, apply mem_cons_self },
{ rw find_cons_of_neg _ h at H, exact mem_cons_of_mem _ (IH H) }
end
end find
/-! ### lookmap -/
section lookmap
variables (f : α → option α)
@[simp] theorem lookmap_nil : [].lookmap f = [] := rfl
@[simp] theorem lookmap_cons_none {a : α} (l : list α) (h : f a = none) :
(a :: l).lookmap f = a :: l.lookmap f :=
by simp [lookmap, h]
@[simp] theorem lookmap_cons_some {a b : α} (l : list α) (h : f a = some b) :
(a :: l).lookmap f = b :: l :=
by simp [lookmap, h]
theorem lookmap_some : ∀ l : list α, l.lookmap some = l
| [] := rfl
| (a::l) := rfl
theorem lookmap_none : ∀ l : list α, l.lookmap (λ _, none) = l
| [] := rfl
| (a::l) := congr_arg (cons a) (lookmap_none l)
theorem lookmap_congr {f g : α → option α} :
∀ {l : list α}, (∀ a ∈ l, f a = g a) → l.lookmap f = l.lookmap g
| [] H := rfl
| (a::l) H := begin
cases forall_mem_cons.1 H with H₁ H₂,
cases h : g a with b,
{ simp [h, H₁.trans h, lookmap_congr H₂] },
{ simp [lookmap_cons_some _ _ h, lookmap_cons_some _ _ (H₁.trans h)] }
end
theorem lookmap_of_forall_not {l : list α} (H : ∀ a ∈ l, f a = none) : l.lookmap f = l :=
(lookmap_congr H).trans (lookmap_none l)
theorem lookmap_map_eq (g : α → β) (h : ∀ a (b ∈ f a), g a = g b) :
∀ l : list α, map g (l.lookmap f) = map g l
| [] := rfl
| (a::l) := begin
cases h' : f a with b,
{ simp [h', lookmap_map_eq] },
{ simp [lookmap_cons_some _ _ h', h _ _ h'] }
end
theorem lookmap_id' (h : ∀ a (b ∈ f a), a = b) (l : list α) : l.lookmap f = l :=
by rw [← map_id (l.lookmap f), lookmap_map_eq, map_id]; exact h
theorem length_lookmap (l : list α) : length (l.lookmap f) = length l :=
by rw [← length_map, lookmap_map_eq _ (λ _, ()), length_map]; simp
end lookmap
/-! ### filter_map -/
@[simp] theorem filter_map_nil (f : α → option β) : filter_map f [] = [] := rfl
@[simp] theorem filter_map_cons_none {f : α → option β} (a : α) (l : list α) (h : f a = none) :
filter_map f (a :: l) = filter_map f l :=
by simp only [filter_map, h]
@[simp] theorem filter_map_cons_some (f : α → option β)
(a : α) (l : list α) {b : β} (h : f a = some b) :
filter_map f (a :: l) = b :: filter_map f l :=
by simp only [filter_map, h]; split; refl
lemma filter_map_append {α β : Type*} (l l' : list α) (f : α → option β) :
filter_map f (l ++ l') = filter_map f l ++ filter_map f l' :=
begin
induction l with hd tl hl generalizing l',
{ simp },
{ rw [cons_append, filter_map, filter_map],
cases f hd;
simp only [filter_map, hl, cons_append, eq_self_iff_true, and_self] }
end
theorem filter_map_eq_map (f : α → β) : filter_map (some ∘ f) = map f :=
begin
funext l,
induction l with a l IH, {refl},
simp only [filter_map_cons_some (some ∘ f) _ _ rfl, IH, map_cons], split; refl
end
theorem filter_map_eq_filter (p : α → Prop) [decidable_pred p] :
filter_map (option.guard p) = filter p :=
begin
funext l,
induction l with a l IH, {refl},
by_cases pa : p a,
{ simp only [filter_map, option.guard, IH, if_pos pa, filter_cons_of_pos _ pa], split; refl },
{ simp only [filter_map, option.guard, IH, if_neg pa, filter_cons_of_neg _ pa] }
end
theorem filter_map_filter_map (f : α → option β) (g : β → option γ) (l : list α) :
filter_map g (filter_map f l) = filter_map (λ x, (f x).bind g) l :=
begin
induction l with a l IH, {refl},
cases h : f a with b,
{ rw [filter_map_cons_none _ _ h, filter_map_cons_none, IH],
simp only [h, option.none_bind'] },
rw filter_map_cons_some _ _ _ h,
cases h' : g b with c;
[ rw [filter_map_cons_none _ _ h', filter_map_cons_none, IH],
rw [filter_map_cons_some _ _ _ h', filter_map_cons_some, IH] ];
simp only [h, h', option.some_bind']
end
theorem map_filter_map (f : α → option β) (g : β → γ) (l : list α) :
map g (filter_map f l) = filter_map (λ x, (f x).map g) l :=
by rw [← filter_map_eq_map, filter_map_filter_map]; refl
theorem filter_map_map (f : α → β) (g : β → option γ) (l : list α) :
filter_map g (map f l) = filter_map (g ∘ f) l :=
by rw [← filter_map_eq_map, filter_map_filter_map]; refl
theorem filter_filter_map (f : α → option β) (p : β → Prop) [decidable_pred p] (l : list α) :
filter p (filter_map f l) = filter_map (λ x, (f x).filter p) l :=
by rw [← filter_map_eq_filter, filter_map_filter_map]; refl
theorem filter_map_filter (p : α → Prop) [decidable_pred p] (f : α → option β) (l : list α) :
filter_map f (filter p l) = filter_map (λ x, if p x then f x else none) l :=
begin
rw [← filter_map_eq_filter, filter_map_filter_map], congr,
funext x,
show (option.guard p x).bind f = ite (p x) (f x) none,
by_cases h : p x,
{ simp only [option.guard, if_pos h, option.some_bind'] },
{ simp only [option.guard, if_neg h, option.none_bind'] }
end
@[simp] theorem filter_map_some (l : list α) : filter_map some l = l :=
by rw filter_map_eq_map; apply map_id
@[simp] theorem mem_filter_map (f : α → option β) (l : list α) {b : β} :
b ∈ filter_map f l ↔ ∃ a, a ∈ l ∧ f a = some b :=
begin
induction l with a l IH,
{ split, { intro H, cases H }, { rintro ⟨_, H, _⟩, cases H } },
cases h : f a with b',
{ have : f a ≠ some b, {rw h, intro, contradiction},
simp only [filter_map_cons_none _ _ h, IH, mem_cons_iff,
or_and_distrib_right, exists_or_distrib, exists_eq_left, this, false_or] },
{ have : f a = some b ↔ b = b',
{ split; intro t, {rw t at h; injection h}, {exact t.symm ▸ h} },
simp only [filter_map_cons_some _ _ _ h, IH, mem_cons_iff,
or_and_distrib_right, exists_or_distrib, this, exists_eq_left] }
end
theorem map_filter_map_of_inv (f : α → option β) (g : β → α)
(H : ∀ x : α, (f x).map g = some x) (l : list α) :
map g (filter_map f l) = l :=
by simp only [map_filter_map, H, filter_map_some]
theorem sublist.filter_map (f : α → option β) {l₁ l₂ : list α}
(s : l₁ <+ l₂) : filter_map f l₁ <+ filter_map f l₂ :=
by induction s with l₁ l₂ a s IH l₁ l₂ a s IH;
simp only [filter_map]; cases f a with b;
simp only [filter_map, IH, sublist.cons, sublist.cons2]
theorem sublist.map (f : α → β) {l₁ l₂ : list α}
(s : l₁ <+ l₂) : map f l₁ <+ map f l₂ :=
filter_map_eq_map f ▸ s.filter_map _
/-! ### reduce_option -/
@[simp] lemma reduce_option_cons_of_some (x : α) (l : list (option α)) :
reduce_option (some x :: l) = x :: l.reduce_option :=
by simp only [reduce_option, filter_map, id.def, eq_self_iff_true, and_self]
@[simp] lemma reduce_option_cons_of_none (l : list (option α)) :
reduce_option (none :: l) = l.reduce_option :=
by simp only [reduce_option, filter_map, id.def]
@[simp] lemma reduce_option_nil : @reduce_option α [] = [] := rfl
@[simp] lemma reduce_option_map {l : list (option α)} {f : α → β} :
reduce_option (map (option.map f) l) = map f (reduce_option l) :=
begin
induction l with hd tl hl,
{ simp only [reduce_option_nil, map_nil] },
{ cases hd;
simpa only [true_and, option.map_some', map, eq_self_iff_true,
reduce_option_cons_of_some] using hl },
end
lemma reduce_option_append (l l' : list (option α)) :
(l ++ l').reduce_option = l.reduce_option ++ l'.reduce_option :=
filter_map_append l l' id
lemma reduce_option_length_le (l : list (option α)) :
l.reduce_option.length ≤ l.length :=
begin
induction l with hd tl hl,
{ simp only [reduce_option_nil, length] },
{ cases hd,
{ exact nat.le_succ_of_le hl },
{ simpa only [length, add_le_add_iff_right, reduce_option_cons_of_some] using hl} }
end
lemma reduce_option_length_eq_iff {l : list (option α)} :
l.reduce_option.length = l.length ↔ ∀ x ∈ l, option.is_some x :=
begin
induction l with hd tl hl,
{ simp only [forall_const, reduce_option_nil, not_mem_nil,
forall_prop_of_false, eq_self_iff_true, length, not_false_iff] },
{ cases hd,
{ simp only [mem_cons_iff, forall_eq_or_imp, bool.coe_sort_ff, false_and,
reduce_option_cons_of_none, length, option.is_some_none, iff_false],
intro H,
have := reduce_option_length_le tl,
rw H at this,
exact absurd (nat.lt_succ_self _) (not_lt_of_le this) },
{ simp only [hl, true_and, mem_cons_iff, forall_eq_or_imp, add_left_inj,
bool.coe_sort_tt, length, option.is_some_some, reduce_option_cons_of_some] } }
end
lemma reduce_option_length_lt_iff {l : list (option α)} :
l.reduce_option.length < l.length ↔ none ∈ l :=
begin
convert not_iff_not.mpr reduce_option_length_eq_iff;
simp [lt_iff_le_and_ne, reduce_option_length_le l, option.is_none_iff_eq_none]
end
lemma reduce_option_singleton (x : option α) :
[x].reduce_option = x.to_list :=
by cases x; refl
lemma reduce_option_concat (l : list (option α)) (x : option α) :
(l.concat x).reduce_option = l.reduce_option ++ x.to_list :=
begin
induction l with hd tl hl generalizing x,
{ cases x;
simp [option.to_list] },
{ simp only [concat_eq_append, reduce_option_append] at hl,
cases hd;
simp [hl, reduce_option_append] }
end
lemma reduce_option_concat_of_some (l : list (option α)) (x : α) :
(l.concat (some x)).reduce_option = l.reduce_option.concat x :=
by simp only [reduce_option_nil, concat_eq_append, reduce_option_append, reduce_option_cons_of_some]
lemma reduce_option_mem_iff {l : list (option α)} {x : α} :
x ∈ l.reduce_option ↔ (some x) ∈ l :=
by simp only [reduce_option, id.def, mem_filter_map, exists_eq_right]
lemma reduce_option_nth_iff {l : list (option α)} {x : α} :
(∃ i, l.nth i = some (some x)) ↔ ∃ i, l.reduce_option.nth i = some x :=
by rw [←mem_iff_nth, ←mem_iff_nth, reduce_option_mem_iff]
/-! ### filter -/
section filter
variables {p : α → Prop} [decidable_pred p]
theorem filter_eq_foldr (p : α → Prop) [decidable_pred p] (l : list α) :
filter p l = foldr (λ a out, if p a then a :: out else out) [] l :=
by induction l; simp [*, filter]
lemma filter_congr {p q : α → Prop} [decidable_pred p] [decidable_pred q]
: ∀ {l : list α}, (∀ x ∈ l, p x ↔ q x) → filter p l = filter q l
| [] _ := rfl
| (a::l) h := by rw forall_mem_cons at h; by_cases pa : p a;
[simp only [filter_cons_of_pos _ pa, filter_cons_of_pos _ (h.1.1 pa), filter_congr h.2],
simp only [filter_cons_of_neg _ pa, filter_cons_of_neg _ (mt h.1.2 pa), filter_congr h.2]];
split; refl
@[simp] theorem filter_subset (l : list α) : filter p l ⊆ l :=
(filter_sublist l).subset
theorem of_mem_filter {a : α} : ∀ {l}, a ∈ filter p l → p a
| (b::l) ain :=
if pb : p b then
have a ∈ b :: filter p l, by simpa only [filter_cons_of_pos _ pb] using ain,
or.elim (eq_or_mem_of_mem_cons this)
(assume : a = b, begin rw [← this] at pb, exact pb end)
(assume : a ∈ filter p l, of_mem_filter this)
else
begin simp only [filter_cons_of_neg _ pb] at ain, exact (of_mem_filter ain) end
theorem mem_of_mem_filter {a : α} {l} (h : a ∈ filter p l) : a ∈ l :=
filter_subset l h
theorem mem_filter_of_mem {a : α} : ∀ {l}, a ∈ l → p a → a ∈ filter p l
| (_::l) (or.inl rfl) pa := by rw filter_cons_of_pos _ pa; apply mem_cons_self
| (b::l) (or.inr ain) pa := if pb : p b
then by rw [filter_cons_of_pos _ pb]; apply mem_cons_of_mem; apply mem_filter_of_mem ain pa
else by rw [filter_cons_of_neg _ pb]; apply mem_filter_of_mem ain pa
@[simp] theorem mem_filter {a : α} {l} : a ∈ filter p l ↔ a ∈ l ∧ p a :=
⟨λ h, ⟨mem_of_mem_filter h, of_mem_filter h⟩, λ ⟨h₁, h₂⟩, mem_filter_of_mem h₁ h₂⟩
theorem filter_eq_self {l} : filter p l = l ↔ ∀ a ∈ l, p a :=
begin
induction l with a l ih,
{ exact iff_of_true rfl (forall_mem_nil _) },
rw forall_mem_cons, by_cases p a,
{ rw [filter_cons_of_pos _ h, cons_inj, ih, and_iff_right h] },
{ rw [filter_cons_of_neg _ h],
refine iff_of_false _ (mt and.left h), intro e,
have := filter_sublist l, rw e at this,
exact not_lt_of_ge (length_le_of_sublist this) (lt_succ_self _) }
end
theorem filter_eq_nil {l} : filter p l = [] ↔ ∀ a ∈ l, ¬p a :=
by simp only [eq_nil_iff_forall_not_mem, mem_filter, not_and]
variable (p)
theorem filter_sublist_filter {l₁ l₂} (s : l₁ <+ l₂) : filter p l₁ <+ filter p l₂ :=
filter_map_eq_filter p ▸ s.filter_map _
theorem filter_of_map (f : β → α) (l) : filter p (map f l) = map f (filter (p ∘ f) l) :=
by rw [← filter_map_eq_map, filter_filter_map, filter_map_filter]; refl
@[simp] theorem filter_filter (q) [decidable_pred q] : ∀ l,
filter p (filter q l) = filter (λ a, p a ∧ q a) l
| [] := rfl
| (a :: l) := by by_cases hp : p a; by_cases hq : q a; simp only [hp, hq, filter, if_true, if_false,
true_and, false_and, filter_filter l, eq_self_iff_true]
@[simp] lemma filter_true {h : decidable_pred (λ a : α, true)} (l : list α) :
@filter α (λ _, true) h l = l :=
by convert filter_eq_self.2 (λ _ _, trivial)
@[simp] lemma filter_false {h : decidable_pred (λ a : α, false)} (l : list α) :
@filter α (λ _, false) h l = [] :=
by convert filter_eq_nil.2 (λ _ _, id)
@[simp] theorem span_eq_take_drop : ∀ (l : list α), span p l = (take_while p l, drop_while p l)
| [] := rfl
| (a::l) :=
if pa : p a then by simp only [span, if_pos pa, span_eq_take_drop l, take_while, drop_while]
else by simp only [span, take_while, drop_while, if_neg pa]
@[simp] theorem take_while_append_drop : ∀ (l : list α), take_while p l ++ drop_while p l = l
| [] := rfl
| (a::l) := if pa : p a then by rw [take_while, drop_while, if_pos pa, if_pos pa, cons_append,
take_while_append_drop l]
else by rw [take_while, drop_while, if_neg pa, if_neg pa, nil_append]
@[simp] theorem countp_nil : countp p [] = 0 := rfl
@[simp] theorem countp_cons_of_pos {a : α} (l) (pa : p a) : countp p (a::l) = countp p l + 1 :=
if_pos pa
@[simp] theorem countp_cons_of_neg {a : α} (l) (pa : ¬ p a) : countp p (a::l) = countp p l :=
if_neg pa
theorem countp_eq_length_filter (l) : countp p l = length (filter p l) :=
by induction l with x l ih; [refl, by_cases (p x)];
[simp only [filter_cons_of_pos _ h, countp, ih, if_pos h],
simp only [countp_cons_of_neg _ _ h, ih, filter_cons_of_neg _ h]]; refl
local attribute [simp] countp_eq_length_filter
@[simp] theorem countp_append (l₁ l₂) : countp p (l₁ ++ l₂) = countp p l₁ + countp p l₂ :=
by simp only [countp_eq_length_filter, filter_append, length_append]
theorem countp_pos {l} : 0 < countp p l ↔ ∃ a ∈ l, p a :=
by simp only [countp_eq_length_filter, length_pos_iff_exists_mem, mem_filter, exists_prop]
theorem countp_le_of_sublist {l₁ l₂} (s : l₁ <+ l₂) : countp p l₁ ≤ countp p l₂ :=
by simpa only [countp_eq_length_filter] using length_le_of_sublist (filter_sublist_filter p s)
@[simp] theorem countp_filter {q} [decidable_pred q] (l : list α) :
countp p (filter q l) = countp (λ a, p a ∧ q a) l :=
by simp only [countp_eq_length_filter, filter_filter]
end filter
/-! ### count -/
section count
variable [decidable_eq α]
@[simp] theorem count_nil (a : α) : count a [] = 0 := rfl
theorem count_cons (a b : α) (l : list α) :
count a (b :: l) = if a = b then succ (count a l) else count a l := rfl
theorem count_cons' (a b : α) (l : list α) :
count a (b :: l) = count a l + (if a = b then 1 else 0) :=
begin rw count_cons, split_ifs; refl end
@[simp] theorem count_cons_self (a : α) (l : list α) : count a (a::l) = succ (count a l) :=
if_pos rfl
@[simp, priority 990]
theorem count_cons_of_ne {a b : α} (h : a ≠ b) (l : list α) : count a (b::l) = count a l :=
if_neg h
theorem count_tail : Π (l : list α) (a : α) (h : 0 < l.length),
l.tail.count a = l.count a - ite (a = list.nth_le l 0 h) 1 0
| (_ :: _) a h := by { rw [count_cons], split_ifs; simp }
theorem count_le_of_sublist (a : α) {l₁ l₂} : l₁ <+ l₂ → count a l₁ ≤ count a l₂ :=
countp_le_of_sublist _
theorem count_le_count_cons (a b : α) (l : list α) : count a l ≤ count a (b :: l) :=
count_le_of_sublist _ (sublist_cons _ _)
theorem count_singleton (a : α) : count a [a] = 1 := if_pos rfl
@[simp] theorem count_append (a : α) : ∀ l₁ l₂, count a (l₁ ++ l₂) = count a l₁ + count a l₂ :=
countp_append _
theorem count_concat (a : α) (l : list α) : count a (concat l a) = succ (count a l) :=
by simp [-add_comm]
theorem count_pos {a : α} {l : list α} : 0 < count a l ↔ a ∈ l :=
by simp only [count, countp_pos, exists_prop, exists_eq_right']
@[simp, priority 980]
theorem count_eq_zero_of_not_mem {a : α} {l : list α} (h : a ∉ l) : count a l = 0 :=
by_contradiction $ λ h', h $ count_pos.1 (nat.pos_of_ne_zero h')
theorem not_mem_of_count_eq_zero {a : α} {l : list α} (h : count a l = 0) : a ∉ l :=
λ h', ne_of_gt (count_pos.2 h') h
@[simp] theorem count_repeat (a : α) (n : ℕ) : count a (repeat a n) = n :=
by rw [count, countp_eq_length_filter, filter_eq_self.2, length_repeat];
exact λ b m, (eq_of_mem_repeat m).symm
theorem le_count_iff_repeat_sublist {a : α} {l : list α} {n : ℕ} :
n ≤ count a l ↔ repeat a n <+ l :=
⟨λ h, ((repeat_sublist_repeat a).2 h).trans $
have filter (eq a) l = repeat a (count a l), from eq_repeat.2
⟨by simp only [count, countp_eq_length_filter], λ b m, (of_mem_filter m).symm⟩,
by rw ← this; apply filter_sublist,
λ h, by simpa only [count_repeat] using count_le_of_sublist a h⟩
theorem repeat_count_eq_of_count_eq_length {a : α} {l : list α} (h : count a l = length l) :
repeat a (count a l) = l :=
eq_of_sublist_of_length_eq (le_count_iff_repeat_sublist.mp (le_refl (count a l)))
(eq.trans (length_repeat a (count a l)) h)
@[simp] theorem count_filter {p} [decidable_pred p]
{a} {l : list α} (h : p a) : count a (filter p l) = count a l :=
by simp only [count, countp_filter]; congr; exact
set.ext (λ b, and_iff_left_of_imp (λ e, e ▸ h))
end count
/-! ### prefix, suffix, infix -/
@[simp] theorem prefix_append (l₁ l₂ : list α) : l₁ <+: l₁ ++ l₂ := ⟨l₂, rfl⟩
@[simp] theorem suffix_append (l₁ l₂ : list α) : l₂ <:+ l₁ ++ l₂ := ⟨l₁, rfl⟩
theorem infix_append (l₁ l₂ l₃ : list α) : l₂ <:+: l₁ ++ l₂ ++ l₃ := ⟨l₁, l₃, rfl⟩
@[simp] theorem infix_append' (l₁ l₂ l₃ : list α) : l₂ <:+: l₁ ++ (l₂ ++ l₃) :=
by rw ← list.append_assoc; apply infix_append
theorem nil_prefix (l : list α) : [] <+: l := ⟨l, rfl⟩
theorem nil_suffix (l : list α) : [] <:+ l := ⟨l, append_nil _⟩
@[refl] theorem prefix_refl (l : list α) : l <+: l := ⟨[], append_nil _⟩
@[refl] theorem suffix_refl (l : list α) : l <:+ l := ⟨[], rfl⟩
@[simp] theorem suffix_cons (a : α) : ∀ l, l <:+ a :: l := suffix_append [a]
theorem prefix_concat (a : α) (l) : l <+: concat l a := by simp
theorem infix_of_prefix {l₁ l₂ : list α} : l₁ <+: l₂ → l₁ <:+: l₂ :=
λ⟨t, h⟩, ⟨[], t, h⟩
theorem infix_of_suffix {l₁ l₂ : list α} : l₁ <:+ l₂ → l₁ <:+: l₂ :=
λ⟨t, h⟩, ⟨t, [], by simp only [h, append_nil]⟩
@[refl] theorem infix_refl (l : list α) : l <:+: l := infix_of_prefix $ prefix_refl l
theorem nil_infix (l : list α) : [] <:+: l := infix_of_prefix $ nil_prefix l
theorem infix_cons {L₁ L₂ : list α} {x : α} : L₁ <:+: L₂ → L₁ <:+: x :: L₂ :=
λ⟨LP, LS, H⟩, ⟨x :: LP, LS, H ▸ rfl⟩
@[trans] theorem is_prefix.trans : ∀ {l₁ l₂ l₃ : list α}, l₁ <+: l₂ → l₂ <+: l₃ → l₁ <+: l₃
| l ._ ._ ⟨r₁, rfl⟩ ⟨r₂, rfl⟩ := ⟨r₁ ++ r₂, (append_assoc _ _ _).symm⟩
@[trans] theorem is_suffix.trans : ∀ {l₁ l₂ l₃ : list α}, l₁ <:+ l₂ → l₂ <:+ l₃ → l₁ <:+ l₃
| l ._ ._ ⟨l₁, rfl⟩ ⟨l₂, rfl⟩ := ⟨l₂ ++ l₁, append_assoc _ _ _⟩
@[trans] theorem is_infix.trans : ∀ {l₁ l₂ l₃ : list α}, l₁ <:+: l₂ → l₂ <:+: l₃ → l₁ <:+: l₃
| l ._ ._ ⟨l₁, r₁, rfl⟩ ⟨l₂, r₂, rfl⟩ := ⟨l₂ ++ l₁, r₁ ++ r₂, by simp only [append_assoc]⟩
theorem sublist_of_infix {l₁ l₂ : list α} : l₁ <:+: l₂ → l₁ <+ l₂ :=
λ⟨s, t, h⟩, by rw [← h]; exact (sublist_append_right _ _).trans (sublist_append_left _ _)
theorem sublist_of_prefix {l₁ l₂ : list α} : l₁ <+: l₂ → l₁ <+ l₂ :=
sublist_of_infix ∘ infix_of_prefix
theorem sublist_of_suffix {l₁ l₂ : list α} : l₁ <:+ l₂ → l₁ <+ l₂ :=
sublist_of_infix ∘ infix_of_suffix
theorem reverse_suffix {l₁ l₂ : list α} : reverse l₁ <:+ reverse l₂ ↔ l₁ <+: l₂ :=
⟨λ ⟨r, e⟩, ⟨reverse r,
by rw [← reverse_reverse l₁, ← reverse_append, e, reverse_reverse]⟩,
λ ⟨r, e⟩, ⟨reverse r, by rw [← reverse_append, e]⟩⟩
theorem reverse_prefix {l₁ l₂ : list α} : reverse l₁ <+: reverse l₂ ↔ l₁ <:+ l₂ :=
by rw ← reverse_suffix; simp only [reverse_reverse]
theorem length_le_of_infix {l₁ l₂ : list α} (s : l₁ <:+: l₂) : length l₁ ≤ length l₂ :=
length_le_of_sublist $ sublist_of_infix s
theorem eq_nil_of_infix_nil {l : list α} (s : l <:+: []) : l = [] :=
eq_nil_of_sublist_nil $ sublist_of_infix s
theorem eq_nil_of_prefix_nil {l : list α} (s : l <+: []) : l = [] :=
eq_nil_of_infix_nil $ infix_of_prefix s
theorem eq_nil_of_suffix_nil {l : list α} (s : l <:+ []) : l = [] :=
eq_nil_of_infix_nil $ infix_of_suffix s
theorem infix_iff_prefix_suffix (l₁ l₂ : list α) : l₁ <:+: l₂ ↔ ∃ t, l₁ <+: t ∧ t <:+ l₂ :=
⟨λ⟨s, t, e⟩, ⟨l₁ ++ t, ⟨_, rfl⟩, by rw [← e, append_assoc]; exact ⟨_, rfl⟩⟩,
λ⟨._, ⟨t, rfl⟩, ⟨s, e⟩⟩, ⟨s, t, by rw append_assoc; exact e⟩⟩
theorem eq_of_infix_of_length_eq {l₁ l₂ : list α} (s : l₁ <:+: l₂) :
length l₁ = length l₂ → l₁ = l₂ :=
eq_of_sublist_of_length_eq $ sublist_of_infix s
theorem eq_of_prefix_of_length_eq {l₁ l₂ : list α} (s : l₁ <+: l₂) :
length l₁ = length l₂ → l₁ = l₂ :=
eq_of_sublist_of_length_eq $ sublist_of_prefix s
theorem eq_of_suffix_of_length_eq {l₁ l₂ : list α} (s : l₁ <:+ l₂) :
length l₁ = length l₂ → l₁ = l₂ :=
eq_of_sublist_of_length_eq $ sublist_of_suffix s
theorem prefix_of_prefix_length_le : ∀ {l₁ l₂ l₃ : list α},
l₁ <+: l₃ → l₂ <+: l₃ → length l₁ ≤ length l₂ → l₁ <+: l₂
| [] l₂ l₃ h₁ h₂ _ := nil_prefix _
| (a::l₁) (b::l₂) _ ⟨r₁, rfl⟩ ⟨r₂, e⟩ ll := begin
injection e with _ e', subst b,
rcases prefix_of_prefix_length_le ⟨_, rfl⟩ ⟨_, e'⟩
(le_of_succ_le_succ ll) with ⟨r₃, rfl⟩,
exact ⟨r₃, rfl⟩
end
theorem prefix_or_prefix_of_prefix {l₁ l₂ l₃ : list α}
(h₁ : l₁ <+: l₃) (h₂ : l₂ <+: l₃) : l₁ <+: l₂ ∨ l₂ <+: l₁ :=
(le_total (length l₁) (length l₂)).imp
(prefix_of_prefix_length_le h₁ h₂)
(prefix_of_prefix_length_le h₂ h₁)
theorem suffix_of_suffix_length_le {l₁ l₂ l₃ : list α}
(h₁ : l₁ <:+ l₃) (h₂ : l₂ <:+ l₃) (ll : length l₁ ≤ length l₂) : l₁ <:+ l₂ :=
reverse_prefix.1 $ prefix_of_prefix_length_le
(reverse_prefix.2 h₁) (reverse_prefix.2 h₂) (by simp [ll])
theorem suffix_or_suffix_of_suffix {l₁ l₂ l₃ : list α}
(h₁ : l₁ <:+ l₃) (h₂ : l₂ <:+ l₃) : l₁ <:+ l₂ ∨ l₂ <:+ l₁ :=
(prefix_or_prefix_of_prefix (reverse_prefix.2 h₁) (reverse_prefix.2 h₂)).imp
reverse_prefix.1 reverse_prefix.1
theorem infix_of_mem_join : ∀ {L : list (list α)} {l}, l ∈ L → l <:+: join L
| (_ :: L) l (or.inl rfl) := infix_append [] _ _
| (l' :: L) l (or.inr h) :=
is_infix.trans (infix_of_mem_join h) $ infix_of_suffix $ suffix_append _ _
theorem prefix_append_right_inj {l₁ l₂ : list α} (l) : l ++ l₁ <+: l ++ l₂ ↔ l₁ <+: l₂ :=
exists_congr $ λ r, by rw [append_assoc, append_right_inj]
theorem prefix_cons_inj {l₁ l₂ : list α} (a) : a :: l₁ <+: a :: l₂ ↔ l₁ <+: l₂ :=
prefix_append_right_inj [a]
theorem take_prefix (n) (l : list α) : take n l <+: l := ⟨_, take_append_drop _ _⟩
theorem drop_suffix (n) (l : list α) : drop n l <:+ l := ⟨_, take_append_drop _ _⟩
theorem tail_suffix (l : list α) : tail l <:+ l := by rw ← drop_one; apply drop_suffix
theorem tail_subset (l : list α) : tail l ⊆ l := (sublist_of_suffix (tail_suffix l)).subset
theorem prefix_iff_eq_append {l₁ l₂ : list α} : l₁ <+: l₂ ↔ l₁ ++ drop (length l₁) l₂ = l₂ :=
⟨by rintros ⟨r, rfl⟩; rw drop_left, λ e, ⟨_, e⟩⟩
theorem suffix_iff_eq_append {l₁ l₂ : list α} :
l₁ <:+ l₂ ↔ take (length l₂ - length l₁) l₂ ++ l₁ = l₂ :=
⟨by rintros ⟨r, rfl⟩; simp only [length_append, nat.add_sub_cancel, take_left], λ e, ⟨_, e⟩⟩
theorem prefix_iff_eq_take {l₁ l₂ : list α} : l₁ <+: l₂ ↔ l₁ = take (length l₁) l₂ :=
⟨λ h, append_right_cancel $
(prefix_iff_eq_append.1 h).trans (take_append_drop _ _).symm,
λ e, e.symm ▸ take_prefix _ _⟩
theorem suffix_iff_eq_drop {l₁ l₂ : list α} : l₁ <:+ l₂ ↔ l₁ = drop (length l₂ - length l₁) l₂ :=
⟨λ h, append_left_cancel $
(suffix_iff_eq_append.1 h).trans (take_append_drop _ _).symm,
λ e, e.symm ▸ drop_suffix _ _⟩
instance decidable_prefix [decidable_eq α] : ∀ (l₁ l₂ : list α), decidable (l₁ <+: l₂)
| [] l₂ := is_true ⟨l₂, rfl⟩
| (a::l₁) [] := is_false $ λ ⟨t, te⟩, list.no_confusion te
| (a::l₁) (b::l₂) :=
if h : a = b then
@decidable_of_iff _ _ (by rw [← h, prefix_cons_inj])
(decidable_prefix l₁ l₂)
else
is_false $ λ ⟨t, te⟩, h $ by injection te
-- Alternatively, use mem_tails
instance decidable_suffix [decidable_eq α] : ∀ (l₁ l₂ : list α), decidable (l₁ <:+ l₂)
| [] l₂ := is_true ⟨l₂, append_nil _⟩
| (a::l₁) [] := is_false $ mt (length_le_of_sublist ∘ sublist_of_suffix) dec_trivial
| l₁ l₂ := let len1 := length l₁, len2 := length l₂ in
if hl : len1 ≤ len2 then
decidable_of_iff' (l₁ = drop (len2-len1) l₂) suffix_iff_eq_drop
else is_false $ λ h, hl $ length_le_of_sublist $ sublist_of_suffix h
lemma prefix_take_le_iff {L : list (list (option α))} {m n : ℕ} (hm : m < L.length) :
(take m L) <+: (take n L) ↔ m ≤ n :=
begin
simp only [prefix_iff_eq_take, length_take],
induction m with m IH generalizing L n,
{ simp only [min_eq_left, eq_self_iff_true, nat.zero_le, take] },
{ cases n,
{ simp only [nat.nat_zero_eq_zero, nonpos_iff_eq_zero, take, take_nil],
split,
{ cases L,
{ exact absurd hm (not_lt_of_le m.succ.zero_le) },
{ simp only [forall_prop_of_false, not_false_iff, take] } },
{ intro h,
contradiction } },
{ cases L with l ls,
{ exact absurd hm (not_lt_of_le m.succ.zero_le) },
{ simp only [length] at hm,
specialize @IH ls n (nat.lt_of_succ_lt_succ hm),
simp only [le_of_lt (nat.lt_of_succ_lt_succ hm), min_eq_left] at IH,
simp only [le_of_lt hm, IH, true_and, min_eq_left, eq_self_iff_true, length, take],
exact ⟨nat.succ_le_succ, nat.le_of_succ_le_succ⟩ } } },
end
lemma cons_prefix_iff {l l' : list α} {x y : α} :
x :: l <+: y :: l' ↔ x = y ∧ l <+: l' :=
begin
split,
{ rintro ⟨L, hL⟩,
simp only [cons_append] at hL,
exact ⟨hL.left, ⟨L, hL.right⟩⟩ },
{ rintro ⟨rfl, h⟩,
rwa [prefix_cons_inj] },
end
lemma map_prefix {l l' : list α} (f : α → β) (h : l <+: l') :
l.map f <+: l'.map f :=
begin
induction l with hd tl hl generalizing l',
{ simp only [nil_prefix, map_nil] },
{ cases l' with hd' tl',
{ simpa only using eq_nil_of_prefix_nil h },
{ rw cons_prefix_iff at h,
simp only [h, prefix_cons_inj, hl, map] } },
end
lemma is_prefix.filter_map {l l' : list α} (h : l <+: l') (f : α → option β) :
l.filter_map f <+: l'.filter_map f :=
begin
induction l with hd tl hl generalizing l',
{ simp only [nil_prefix, filter_map_nil] },
{ cases l' with hd' tl',
{ simpa only using eq_nil_of_prefix_nil h },
{ rw cons_prefix_iff at h,
rw [←@singleton_append _ hd _, ←@singleton_append _ hd' _, filter_map_append,
filter_map_append, h.left, prefix_append_right_inj],
exact hl h.right } },
end
lemma is_prefix.reduce_option {l l' : list (option α)} (h : l <+: l') :
l.reduce_option <+: l'.reduce_option :=
h.filter_map id
@[simp] theorem mem_inits : ∀ (s t : list α), s ∈ inits t ↔ s <+: t
| s [] := suffices s = nil ↔ s <+: nil, by simpa only [inits, mem_singleton],
⟨λh, h.symm ▸ prefix_refl [], eq_nil_of_prefix_nil⟩
| s (a::t) :=
suffices (s = nil ∨ ∃ l ∈ inits t, a :: l = s) ↔ s <+: a :: t, by simpa,
⟨λo, match s, o with
| ._, or.inl rfl := ⟨_, rfl⟩
| s, or.inr ⟨r, hr, hs⟩ := let ⟨s, ht⟩ := (mem_inits _ _).1 hr in
by rw [← hs, ← ht]; exact ⟨s, rfl⟩
end, λmi, match s, mi with
| [], ⟨._, rfl⟩ := or.inl rfl
| (b::s), ⟨r, hr⟩ := list.no_confusion hr $ λba (st : s++r = t), or.inr $
by rw ba; exact ⟨_, (mem_inits _ _).2 ⟨_, st⟩, rfl⟩
end⟩
@[simp] theorem mem_tails : ∀ (s t : list α), s ∈ tails t ↔ s <:+ t
| s [] := by simp only [tails, mem_singleton];
exact ⟨λh, by rw h; exact suffix_refl [], eq_nil_of_suffix_nil⟩
| s (a::t) := by simp only [tails, mem_cons_iff, mem_tails s t];
exact show s = a :: t ∨ s <:+ t ↔ s <:+ a :: t, from
⟨λo, match s, t, o with
| ._, t, or.inl rfl := suffix_refl _
| s, ._, or.inr ⟨l, rfl⟩ := ⟨a::l, rfl⟩
end, λe, match s, t, e with
| ._, t, ⟨[], rfl⟩ := or.inl rfl
| s, t, ⟨b::l, he⟩ := list.no_confusion he (λab lt, or.inr ⟨l, lt⟩)
end⟩
lemma inits_cons (a : α) (l : list α) : inits (a :: l) = [] :: l.inits.map (λ t, a :: t) :=
by simp
lemma tails_cons (a : α) (l : list α) : tails (a :: l) = (a :: l) :: l.tails :=
by simp
@[simp]
lemma inits_append : ∀ (s t : list α), inits (s ++ t) = s.inits ++ t.inits.tail.map (λ l, s ++ l)
| [] [] := by simp
| [] (a::t) := by simp
| (a::s) t := by simp [inits_append s t]
@[simp]
lemma tails_append : ∀ (s t : list α), tails (s ++ t) = s.tails.map (λ l, l ++ t) ++ t.tails.tail
| [] [] := by simp
| [] (a::t) := by simp
| (a::s) t := by simp [tails_append s t]
-- the lemma names `inits_eq_tails` and `tails_eq_inits` are like `sublists_eq_sublists'`
lemma inits_eq_tails :
∀ (l : list α), l.inits = (reverse $ map reverse $ tails $ reverse l)
| [] := by simp
| (a :: l) := by simp [inits_eq_tails l, map_eq_map_iff]
lemma tails_eq_inits :
∀ (l : list α), l.tails = (reverse $ map reverse $ inits $ reverse l)
| [] := by simp
| (a :: l) := by simp [tails_eq_inits l, append_left_inj]
lemma inits_reverse (l : list α) : inits (reverse l) = reverse (map reverse l.tails) :=
by { rw tails_eq_inits l, simp [reverse_involutive.comp_self], }
lemma tails_reverse (l : list α) : tails (reverse l) = reverse (map reverse l.inits) :=
by { rw inits_eq_tails l, simp [reverse_involutive.comp_self], }
lemma map_reverse_inits (l : list α) : map reverse l.inits = (reverse $ tails $ reverse l) :=
by { rw inits_eq_tails l, simp [reverse_involutive.comp_self], }
lemma map_reverse_tails (l : list α) : map reverse l.tails = (reverse $ inits $ reverse l) :=
by { rw tails_eq_inits l, simp [reverse_involutive.comp_self], }
instance decidable_infix [decidable_eq α] : ∀ (l₁ l₂ : list α), decidable (l₁ <:+: l₂)
| [] l₂ := is_true ⟨[], l₂, rfl⟩
| (a::l₁) [] := is_false $ λ⟨s, t, te⟩, absurd te $ append_ne_nil_of_ne_nil_left _ _ $
append_ne_nil_of_ne_nil_right _ _ $ λh, list.no_confusion h
| l₁ l₂ := decidable_of_decidable_of_iff (list.decidable_bex (λt, l₁ <+: t) (tails l₂)) $
by refine (exists_congr (λt, _)).trans (infix_iff_prefix_suffix _ _).symm;
exact ⟨λ⟨h1, h2⟩, ⟨h2, (mem_tails _ _).1 h1⟩, λ⟨h2, h1⟩, ⟨(mem_tails _ _).2 h1, h2⟩⟩
/-! ### sublists -/
@[simp] theorem sublists'_nil : sublists' (@nil α) = [[]] := rfl
@[simp, priority 1100] theorem sublists'_singleton (a : α) : sublists' [a] = [[], [a]] := rfl
theorem map_sublists'_aux (g : list β → list γ) (l : list α) (f r) :
map g (sublists'_aux l f r) = sublists'_aux l (g ∘ f) (map g r) :=
by induction l generalizing f r; [refl, simp only [*, sublists'_aux]]
theorem sublists'_aux_append (r' : list (list β)) (l : list α) (f r) :
sublists'_aux l f (r ++ r') = sublists'_aux l f r ++ r' :=
by induction l generalizing f r; [refl, simp only [*, sublists'_aux]]
theorem sublists'_aux_eq_sublists' (l f r) :
@sublists'_aux α β l f r = map f (sublists' l) ++ r :=
by rw [sublists', map_sublists'_aux, ← sublists'_aux_append]; refl
@[simp] theorem sublists'_cons (a : α) (l : list α) :
sublists' (a :: l) = sublists' l ++ map (cons a) (sublists' l) :=
by rw [sublists', sublists'_aux]; simp only [sublists'_aux_eq_sublists', map_id, append_nil]; refl
@[simp] theorem mem_sublists' {s t : list α} : s ∈ sublists' t ↔ s <+ t :=
begin
induction t with a t IH generalizing s,
{ simp only [sublists'_nil, mem_singleton],
exact ⟨λ h, by rw h, eq_nil_of_sublist_nil⟩ },
simp only [sublists'_cons, mem_append, IH, mem_map],
split; intro h, rcases h with h | ⟨s, h, rfl⟩,
{ exact sublist_cons_of_sublist _ h },
{ exact cons_sublist_cons _ h },
{ cases h with _ _ _ h s _ _ h,
{ exact or.inl h },
{ exact or.inr ⟨s, h, rfl⟩ } }
end
@[simp] theorem length_sublists' : ∀ l : list α, length (sublists' l) = 2 ^ length l
| [] := rfl
| (a::l) := by simp only [sublists'_cons, length_append, length_sublists' l, length_map,
length, pow_succ', mul_succ, mul_zero, zero_add]
@[simp] theorem sublists_nil : sublists (@nil α) = [[]] := rfl
@[simp] theorem sublists_singleton (a : α) : sublists [a] = [[], [a]] := rfl
theorem sublists_aux₁_eq_sublists_aux : ∀ l (f : list α → list β),
sublists_aux₁ l f = sublists_aux l (λ ys r, f ys ++ r)
| [] f := rfl
| (a::l) f := by rw [sublists_aux₁, sublists_aux]; simp only [*, append_assoc]
theorem sublists_aux_cons_eq_sublists_aux₁ (l : list α) :
sublists_aux l cons = sublists_aux₁ l (λ x, [x]) :=
by rw [sublists_aux₁_eq_sublists_aux]; refl
theorem sublists_aux_eq_foldr.aux {a : α} {l : list α}
(IH₁ : ∀ (f : list α → list β → list β), sublists_aux l f = foldr f [] (sublists_aux l cons))
(IH₂ : ∀ (f : list α → list (list α) → list (list α)),
sublists_aux l f = foldr f [] (sublists_aux l cons))
(f : list α → list β → list β) : sublists_aux (a::l) f = foldr f [] (sublists_aux (a::l) cons) :=
begin
simp only [sublists_aux, foldr_cons], rw [IH₂, IH₁], congr' 1,
induction sublists_aux l cons with _ _ ih, {refl},
simp only [ih, foldr_cons]
end
theorem sublists_aux_eq_foldr (l : list α) : ∀ (f : list α → list β → list β),
sublists_aux l f = foldr f [] (sublists_aux l cons) :=
suffices _ ∧ ∀ f : list α → list (list α) → list (list α),
sublists_aux l f = foldr f [] (sublists_aux l cons),
from this.1,
begin
induction l with a l IH, {split; intro; refl},
exact ⟨sublists_aux_eq_foldr.aux IH.1 IH.2,
sublists_aux_eq_foldr.aux IH.2 IH.2⟩
end
theorem sublists_aux_cons_cons (l : list α) (a : α) :
sublists_aux (a::l) cons = [a] :: foldr (λys r, ys :: (a :: ys) :: r) [] (sublists_aux l cons) :=
by rw [← sublists_aux_eq_foldr]; refl
theorem sublists_aux₁_append : ∀ (l₁ l₂ : list α) (f : list α → list β),
sublists_aux₁ (l₁ ++ l₂) f = sublists_aux₁ l₁ f ++
sublists_aux₁ l₂ (λ x, f x ++ sublists_aux₁ l₁ (f ∘ (++ x)))
| [] l₂ f := by simp only [sublists_aux₁, nil_append, append_nil]
| (a::l₁) l₂ f := by simp only [sublists_aux₁, cons_append, sublists_aux₁_append l₁, append_assoc];
refl
theorem sublists_aux₁_concat (l : list α) (a : α) (f : list α → list β) :
sublists_aux₁ (l ++ [a]) f = sublists_aux₁ l f ++
f [a] ++ sublists_aux₁ l (λ x, f (x ++ [a])) :=
by simp only [sublists_aux₁_append, sublists_aux₁, append_assoc, append_nil]
theorem sublists_aux₁_bind : ∀ (l : list α)
(f : list α → list β) (g : β → list γ),
(sublists_aux₁ l f).bind g = sublists_aux₁ l (λ x, (f x).bind g)
| [] f g := rfl
| (a::l) f g := by simp only [sublists_aux₁, bind_append, sublists_aux₁_bind l]
theorem sublists_aux_cons_append (l₁ l₂ : list α) :
sublists_aux (l₁ ++ l₂) cons = sublists_aux l₁ cons ++
(do x ← sublists_aux l₂ cons, (++ x) <$> sublists l₁) :=
begin
simp only [sublists, sublists_aux_cons_eq_sublists_aux₁, sublists_aux₁_append, bind_eq_bind,
sublists_aux₁_bind],
congr, funext x, apply congr_arg _,
rw [← bind_ret_eq_map, sublists_aux₁_bind], exact (append_nil _).symm
end
theorem sublists_append (l₁ l₂ : list α) :
sublists (l₁ ++ l₂) = (do x ← sublists l₂, (++ x) <$> sublists l₁) :=
by simp only [map, sublists, sublists_aux_cons_append, map_eq_map, bind_eq_bind,
cons_bind, map_id', append_nil, cons_append, map_id' (λ _, rfl)]; split; refl
@[simp] theorem sublists_concat (l : list α) (a : α) :
sublists (l ++ [a]) = sublists l ++ map (λ x, x ++ [a]) (sublists l) :=
by rw [sublists_append, sublists_singleton, bind_eq_bind, cons_bind, cons_bind, nil_bind,
map_eq_map, map_eq_map, map_id' (append_nil), append_nil]
theorem sublists_reverse (l : list α) : sublists (reverse l) = map reverse (sublists' l) :=
by induction l with hd tl ih; [refl,
simp only [reverse_cons, sublists_append, sublists'_cons, map_append, ih, sublists_singleton,
map_eq_map, bind_eq_bind, map_map, cons_bind, append_nil, nil_bind, (∘)]]
theorem sublists_eq_sublists' (l : list α) : sublists l = map reverse (sublists' (reverse l)) :=
by rw [← sublists_reverse, reverse_reverse]
theorem sublists'_reverse (l : list α) : sublists' (reverse l) = map reverse (sublists l) :=
by simp only [sublists_eq_sublists', map_map, map_id' (reverse_reverse)]
theorem sublists'_eq_sublists (l : list α) : sublists' l = map reverse (sublists (reverse l)) :=
by rw [← sublists'_reverse, reverse_reverse]
theorem sublists_aux_ne_nil : ∀ (l : list α), [] ∉ sublists_aux l cons
| [] := id
| (a::l) := begin
rw [sublists_aux_cons_cons],
refine not_mem_cons_of_ne_of_not_mem (cons_ne_nil _ _).symm _,
have := sublists_aux_ne_nil l, revert this,
induction sublists_aux l cons; intro, {rwa foldr},
simp only [foldr, mem_cons_iff, false_or, not_or_distrib],
exact ⟨ne_of_not_mem_cons this, ih (not_mem_of_not_mem_cons this)⟩
end
@[simp] theorem mem_sublists {s t : list α} : s ∈ sublists t ↔ s <+ t :=
by rw [← reverse_sublist_iff, ← mem_sublists',
sublists'_reverse, mem_map_of_injective reverse_injective]
@[simp] theorem length_sublists (l : list α) : length (sublists l) = 2 ^ length l :=
by simp only [sublists_eq_sublists', length_map, length_sublists', length_reverse]
theorem map_ret_sublist_sublists (l : list α) : map list.ret l <+ sublists l :=
reverse_rec_on l (nil_sublist _) $
λ l a IH, by simp only [map, map_append, sublists_concat]; exact
((append_sublist_append_left _).2 $ singleton_sublist.2 $
mem_map.2 ⟨[], mem_sublists.2 (nil_sublist _), by refl⟩).trans
((append_sublist_append_right _).2 IH)
/-! ### sublists_len -/
/-- Auxiliary function to construct the list of all sublists of a given length. Given an
integer `n`, a list `l`, a function `f` and an auxiliary list `L`, it returns the list made of
of `f` applied to all sublists of `l` of length `n`, concatenated with `L`. -/
def sublists_len_aux {α β : Type*} : ℕ → list α → (list α → β) → list β → list β
| 0 l f r := f [] :: r
| (n+1) [] f r := r
| (n+1) (a::l) f r := sublists_len_aux (n + 1) l f
(sublists_len_aux n l (f ∘ list.cons a) r)
/-- The list of all sublists of a list `l` that are of length `n`. For instance, for
`l = [0, 1, 2, 3]` and `n = 2`, one gets
`[[2, 3], [1, 3], [1, 2], [0, 3], [0, 2], [0, 1]]`. -/
def sublists_len {α : Type*} (n : ℕ) (l : list α) : list (list α) :=
sublists_len_aux n l id []
lemma sublists_len_aux_append {α β γ : Type*} :
∀ (n : ℕ) (l : list α) (f : list α → β) (g : β → γ) (r : list β) (s : list γ),
sublists_len_aux n l (g ∘ f) (r.map g ++ s) =
(sublists_len_aux n l f r).map g ++ s
| 0 l f g r s := rfl
| (n+1) [] f g r s := rfl
| (n+1) (a::l) f g r s := begin
unfold sublists_len_aux,
rw [show ((g ∘ f) ∘ list.cons a) = (g ∘ f ∘ list.cons a), by refl,
sublists_len_aux_append, sublists_len_aux_append]
end
lemma sublists_len_aux_eq {α β : Type*} (l : list α) (n) (f : list α → β) (r) :
sublists_len_aux n l f r = (sublists_len n l).map f ++ r :=
by rw [sublists_len, ← sublists_len_aux_append]; refl
lemma sublists_len_aux_zero {α : Type*} (l : list α) (f : list α → β) (r) :
sublists_len_aux 0 l f r = f [] :: r := by cases l; refl
@[simp] lemma sublists_len_zero {α : Type*} (l : list α) :
sublists_len 0 l = [[]] := sublists_len_aux_zero _ _ _
@[simp] lemma sublists_len_succ_nil {α : Type*} (n) :
sublists_len (n+1) (@nil α) = [] := rfl
@[simp] lemma sublists_len_succ_cons {α : Type*} (n) (a : α) (l) :
sublists_len (n + 1) (a::l) =
sublists_len (n + 1) l ++ (sublists_len n l).map (cons a) :=
by rw [sublists_len, sublists_len_aux, sublists_len_aux_eq,
sublists_len_aux_eq, map_id, append_nil]; refl
@[simp] lemma length_sublists_len {α : Type*} : ∀ n (l : list α),
length (sublists_len n l) = nat.choose (length l) n
| 0 l := by simp
| (n+1) [] := by simp
| (n+1) (a::l) := by simp [-add_comm, nat.choose, *]; apply add_comm
lemma sublists_len_sublist_sublists' {α : Type*} : ∀ n (l : list α),
sublists_len n l <+ sublists' l
| 0 l := singleton_sublist.2 (mem_sublists'.2 (nil_sublist _))
| (n+1) [] := nil_sublist _
| (n+1) (a::l) := begin
rw [sublists_len_succ_cons, sublists'_cons],
exact (sublists_len_sublist_sublists' _ _).append
((sublists_len_sublist_sublists' _ _).map _)
end
lemma sublists_len_sublist_of_sublist
{α : Type*} (n) {l₁ l₂ : list α} (h : l₁ <+ l₂) : sublists_len n l₁ <+ sublists_len n l₂ :=
begin
induction n with n IHn generalizing l₁ l₂, {simp},
induction h with l₁ l₂ a s IH l₁ l₂ a s IH, {refl},
{ refine IH.trans _,
rw sublists_len_succ_cons,
apply sublist_append_left },
{ simp [sublists_len_succ_cons],
exact IH.append ((IHn s).map _) }
end
lemma length_of_sublists_len {α : Type*} : ∀ {n} {l l' : list α},
l' ∈ sublists_len n l → length l' = n
| 0 l l' (or.inl rfl) := rfl
| (n+1) (a::l) l' h := begin
rw [sublists_len_succ_cons, mem_append, mem_map] at h,
rcases h with h | ⟨l', h, rfl⟩,
{ exact length_of_sublists_len h },
{ exact congr_arg (+1) (length_of_sublists_len h) },
end
lemma mem_sublists_len_self {α : Type*} {l l' : list α}
(h : l' <+ l) : l' ∈ sublists_len (length l') l :=
begin
induction h with l₁ l₂ a s IH l₁ l₂ a s IH,
{ exact or.inl rfl },
{ cases l₁ with b l₁,
{ exact or.inl rfl },
{ rw [length, sublists_len_succ_cons],
exact mem_append_left _ IH } },
{ rw [length, sublists_len_succ_cons],
exact mem_append_right _ (mem_map.2 ⟨_, IH, rfl⟩) }
end
@[simp] lemma mem_sublists_len {α : Type*} {n} {l l' : list α} :
l' ∈ sublists_len n l ↔ l' <+ l ∧ length l' = n :=
⟨λ h, ⟨mem_sublists'.1
((sublists_len_sublist_sublists' _ _).subset h),
length_of_sublists_len h⟩,
λ ⟨h₁, h₂⟩, h₂ ▸ mem_sublists_len_self h₁⟩
/-! ### permutations -/
section permutations
@[simp] theorem permutations_aux_nil (is : list α) : permutations_aux [] is = [] :=
by rw [permutations_aux, permutations_aux.rec]
@[simp] theorem permutations_aux_cons (t : α) (ts is : list α) :
permutations_aux (t :: ts) is = foldr (λy r, (permutations_aux2 t ts r y id).2)
(permutations_aux ts (t::is)) (permutations is) :=
by rw [permutations_aux, permutations_aux.rec]; refl
end permutations
/-! ### insert -/
section insert
variable [decidable_eq α]
@[simp] theorem insert_nil (a : α) : insert a nil = [a] := rfl
theorem insert.def (a : α) (l : list α) : insert a l = if a ∈ l then l else a :: l := rfl
@[simp, priority 980]
theorem insert_of_mem {a : α} {l : list α} (h : a ∈ l) : insert a l = l :=
by simp only [insert.def, if_pos h]
@[simp, priority 970]
theorem insert_of_not_mem {a : α} {l : list α} (h : a ∉ l) : insert a l = a :: l :=
by simp only [insert.def, if_neg h]; split; refl
@[simp] theorem mem_insert_iff {a b : α} {l : list α} : a ∈ insert b l ↔ a = b ∨ a ∈ l :=
begin
by_cases h' : b ∈ l,
{ simp only [insert_of_mem h'],
apply (or_iff_right_of_imp _).symm,
exact λ e, e.symm ▸ h' },
simp only [insert_of_not_mem h', mem_cons_iff]
end
@[simp] theorem suffix_insert (a : α) (l : list α) : l <:+ insert a l :=
by by_cases a ∈ l; [simp only [insert_of_mem h], simp only [insert_of_not_mem h, suffix_cons]]
@[simp] theorem mem_insert_self (a : α) (l : list α) : a ∈ insert a l :=
mem_insert_iff.2 (or.inl rfl)
theorem mem_insert_of_mem {a b : α} {l : list α} (h : a ∈ l) : a ∈ insert b l :=
mem_insert_iff.2 (or.inr h)
theorem eq_or_mem_of_mem_insert {a b : α} {l : list α} (h : a ∈ insert b l) : a = b ∨ a ∈ l :=
mem_insert_iff.1 h
@[simp] theorem length_insert_of_mem {a : α} {l : list α} (h : a ∈ l) :
length (insert a l) = length l :=
by rw insert_of_mem h
@[simp] theorem length_insert_of_not_mem {a : α} {l : list α} (h : a ∉ l) :
length (insert a l) = length l + 1 :=
by rw insert_of_not_mem h; refl
end insert
/-! ### erasep -/
section erasep
variables {p : α → Prop} [decidable_pred p]
@[simp] theorem erasep_nil : [].erasep p = [] := rfl
theorem erasep_cons (a : α) (l : list α) :
(a :: l).erasep p = if p a then l else a :: l.erasep p := rfl
@[simp] theorem erasep_cons_of_pos {a : α} {l : list α} (h : p a) : (a :: l).erasep p = l :=
by simp [erasep_cons, h]
@[simp] theorem erasep_cons_of_neg {a : α} {l : list α} (h : ¬ p a) :
(a::l).erasep p = a :: l.erasep p :=
by simp [erasep_cons, h]
theorem erasep_of_forall_not {l : list α}
(h : ∀ a ∈ l, ¬ p a) : l.erasep p = l :=
by induction l with _ _ ih; [refl,
simp [h _ (or.inl rfl), ih (forall_mem_of_forall_mem_cons h)]]
theorem exists_of_erasep {l : list α} {a} (al : a ∈ l) (pa : p a) :
∃ a l₁ l₂, (∀ b ∈ l₁, ¬ p b) ∧ p a ∧ l = l₁ ++ a :: l₂ ∧ l.erasep p = l₁ ++ l₂ :=
begin
induction l with b l IH, {cases al},
by_cases pb : p b,
{ exact ⟨b, [], l, forall_mem_nil _, pb, by simp [pb]⟩ },
{ rcases al with rfl | al, {exact pb.elim pa},
rcases IH al with ⟨c, l₁, l₂, h₁, h₂, h₃, h₄⟩,
exact ⟨c, b::l₁, l₂, forall_mem_cons.2 ⟨pb, h₁⟩,
h₂, by rw h₃; refl, by simp [pb, h₄]⟩ }
end
theorem exists_or_eq_self_of_erasep (p : α → Prop) [decidable_pred p] (l : list α) :
l.erasep p = l ∨ ∃ a l₁ l₂, (∀ b ∈ l₁, ¬ p b) ∧ p a ∧ l = l₁ ++ a :: l₂ ∧ l.erasep p = l₁ ++ l₂ :=
begin
by_cases h : ∃ a ∈ l, p a,
{ rcases h with ⟨a, ha, pa⟩,
exact or.inr (exists_of_erasep ha pa) },
{ simp at h, exact or.inl (erasep_of_forall_not h) }
end
@[simp] theorem length_erasep_of_mem {l : list α} {a} (al : a ∈ l) (pa : p a) :
length (l.erasep p) = pred (length l) :=
by rcases exists_of_erasep al pa with ⟨_, l₁, l₂, _, _, e₁, e₂⟩;
rw e₂; simp [-add_comm, e₁]; refl
theorem erasep_append_left {a : α} (pa : p a) :
∀ {l₁ : list α} (l₂), a ∈ l₁ → (l₁++l₂).erasep p = l₁.erasep p ++ l₂
| (x::xs) l₂ h := begin
by_cases h' : p x; simp [h'],
rw erasep_append_left l₂ (mem_of_ne_of_mem (mt _ h') h),
rintro rfl, exact pa
end
theorem erasep_append_right :
∀ {l₁ : list α} (l₂), (∀ b ∈ l₁, ¬ p b) → (l₁++l₂).erasep p = l₁ ++ l₂.erasep p
| [] l₂ h := rfl
| (x::xs) l₂ h := by simp [(forall_mem_cons.1 h).1,
erasep_append_right _ (forall_mem_cons.1 h).2]
theorem erasep_sublist (l : list α) : l.erasep p <+ l :=
by rcases exists_or_eq_self_of_erasep p l with h | ⟨c, l₁, l₂, h₁, h₂, h₃, h₄⟩;
[rw h, {rw [h₄, h₃], simp}]
theorem erasep_subset (l : list α) : l.erasep p ⊆ l :=
(erasep_sublist l).subset
theorem sublist.erasep {l₁ l₂ : list α} (s : l₁ <+ l₂) : l₁.erasep p <+ l₂.erasep p :=
begin
induction s,
case list.sublist.slnil { refl },
case list.sublist.cons : l₁ l₂ a s IH {
by_cases h : p a; simp [h],
exacts [IH.trans (erasep_sublist _), IH.cons _ _ _] },
case list.sublist.cons2 : l₁ l₂ a s IH {
by_cases h : p a; simp [h],
exacts [s, IH.cons2 _ _ _] }
end
theorem mem_of_mem_erasep {a : α} {l : list α} : a ∈ l.erasep p → a ∈ l :=
@erasep_subset _ _ _ _ _
@[simp] theorem mem_erasep_of_neg {a : α} {l : list α} (pa : ¬ p a) : a ∈ l.erasep p ↔ a ∈ l :=
⟨mem_of_mem_erasep, λ al, begin
rcases exists_or_eq_self_of_erasep p l with h | ⟨c, l₁, l₂, h₁, h₂, h₃, h₄⟩,
{ rwa h },
{ rw h₄, rw h₃ at al,
have : a ≠ c, {rintro rfl, exact pa.elim h₂},
simpa [this] using al }
end⟩
theorem erasep_map (f : β → α) :
∀ (l : list β), (map f l).erasep p = map f (l.erasep (p ∘ f))
| [] := rfl
| (b::l) := by by_cases p (f b); simp [h, erasep_map l]
@[simp] theorem extractp_eq_find_erasep :
∀ l : list α, extractp p l = (find p l, erasep p l)
| [] := rfl
| (a::l) := by by_cases pa : p a; simp [extractp, pa, extractp_eq_find_erasep l]
end erasep
/-! ### erase -/
section erase
variable [decidable_eq α]
@[simp] theorem erase_nil (a : α) : [].erase a = [] := rfl
theorem erase_cons (a b : α) (l : list α) :
(b :: l).erase a = if b = a then l else b :: l.erase a := rfl
@[simp] theorem erase_cons_head (a : α) (l : list α) : (a :: l).erase a = l :=
by simp only [erase_cons, if_pos rfl]
@[simp] theorem erase_cons_tail {a b : α} (l : list α) (h : b ≠ a) :
(b::l).erase a = b :: l.erase a :=
by simp only [erase_cons, if_neg h]; split; refl
theorem erase_eq_erasep (a : α) (l : list α) : l.erase a = l.erasep (eq a) :=
by { induction l with b l, {refl},
by_cases a = b; [simp [h], simp [h, ne.symm h, *]] }
@[simp, priority 980]
theorem erase_of_not_mem {a : α} {l : list α} (h : a ∉ l) : l.erase a = l :=
by rw [erase_eq_erasep, erasep_of_forall_not]; rintro b h' rfl; exact h h'
theorem exists_erase_eq {a : α} {l : list α} (h : a ∈ l) :
∃ l₁ l₂, a ∉ l₁ ∧ l = l₁ ++ a :: l₂ ∧ l.erase a = l₁ ++ l₂ :=
by rcases exists_of_erasep h rfl with ⟨_, l₁, l₂, h₁, rfl, h₂, h₃⟩;
rw erase_eq_erasep; exact ⟨l₁, l₂, λ h, h₁ _ h rfl, h₂, h₃⟩
@[simp] theorem length_erase_of_mem {a : α} {l : list α} (h : a ∈ l) :
length (l.erase a) = pred (length l) :=
by rw erase_eq_erasep; exact length_erasep_of_mem h rfl
theorem erase_append_left {a : α} {l₁ : list α} (l₂) (h : a ∈ l₁) :
(l₁++l₂).erase a = l₁.erase a ++ l₂ :=
by simp [erase_eq_erasep]; exact erasep_append_left (by refl) l₂ h
theorem erase_append_right {a : α} {l₁ : list α} (l₂) (h : a ∉ l₁) :
(l₁++l₂).erase a = l₁ ++ l₂.erase a :=
by rw [erase_eq_erasep, erase_eq_erasep, erasep_append_right];
rintro b h' rfl; exact h h'
theorem erase_sublist (a : α) (l : list α) : l.erase a <+ l :=
by rw erase_eq_erasep; apply erasep_sublist
theorem erase_subset (a : α) (l : list α) : l.erase a ⊆ l :=
(erase_sublist a l).subset
theorem sublist.erase (a : α) {l₁ l₂ : list α} (h : l₁ <+ l₂) : l₁.erase a <+ l₂.erase a :=
by simp [erase_eq_erasep]; exact sublist.erasep h
theorem mem_of_mem_erase {a b : α} {l : list α} : a ∈ l.erase b → a ∈ l :=
@erase_subset _ _ _ _ _
@[simp] theorem mem_erase_of_ne {a b : α} {l : list α} (ab : a ≠ b) : a ∈ l.erase b ↔ a ∈ l :=
by rw erase_eq_erasep; exact mem_erasep_of_neg ab.symm
theorem erase_comm (a b : α) (l : list α) : (l.erase a).erase b = (l.erase b).erase a :=
if ab : a = b then by rw ab else
if ha : a ∈ l then
if hb : b ∈ l then match l, l.erase a, exists_erase_eq ha, hb with
| ._, ._, ⟨l₁, l₂, ha', rfl, rfl⟩, hb :=
if h₁ : b ∈ l₁ then
by rw [erase_append_left _ h₁, erase_append_left _ h₁,
erase_append_right _ (mt mem_of_mem_erase ha'), erase_cons_head]
else
by rw [erase_append_right _ h₁, erase_append_right _ h₁, erase_append_right _ ha',
erase_cons_tail _ ab, erase_cons_head]
end
else by simp only [erase_of_not_mem hb, erase_of_not_mem (mt mem_of_mem_erase hb)]
else by simp only [erase_of_not_mem ha, erase_of_not_mem (mt mem_of_mem_erase ha)]
theorem map_erase [decidable_eq β] {f : α → β} (finj : injective f) {a : α}
(l : list α) : map f (l.erase a) = (map f l).erase (f a) :=
by rw [erase_eq_erasep, erase_eq_erasep, erasep_map]; congr;
ext b; simp [finj.eq_iff]
theorem map_foldl_erase [decidable_eq β] {f : α → β} (finj : injective f) {l₁ l₂ : list α} :
map f (foldl list.erase l₁ l₂) = foldl (λ l a, l.erase (f a)) (map f l₁) l₂ :=
by induction l₂ generalizing l₁; [refl,
simp only [foldl_cons, map_erase finj, *]]
@[simp] theorem count_erase_self (a : α) :
∀ (s : list α), count a (list.erase s a) = pred (count a s)
| [] := by simp
| (h :: t) :=
begin
rw erase_cons,
by_cases p : h = a,
{ rw [if_pos p, count_cons', if_pos p.symm], simp },
{ rw [if_neg p, count_cons', count_cons', if_neg (λ x : a = h, p x.symm), count_erase_self],
simp, }
end
@[simp] theorem count_erase_of_ne {a b : α} (ab : a ≠ b) :
∀ (s : list α), count a (list.erase s b) = count a s
| [] := by simp
| (x :: xs) :=
begin
rw erase_cons,
split_ifs with h,
{ rw [count_cons', h, if_neg ab], simp },
{ rw [count_cons', count_cons', count_erase_of_ne] }
end
end erase
/-! ### diff -/
section diff
variable [decidable_eq α]
@[simp] theorem diff_nil (l : list α) : l.diff [] = l := rfl
@[simp] theorem diff_cons (l₁ l₂ : list α) (a : α) : l₁.diff (a::l₂) = (l₁.erase a).diff l₂ :=
if h : a ∈ l₁ then by simp only [list.diff, if_pos h]
else by simp only [list.diff, if_neg h, erase_of_not_mem h]
@[simp] theorem nil_diff (l : list α) : [].diff l = [] :=
by induction l; [refl, simp only [*, diff_cons, erase_of_not_mem (not_mem_nil _)]]
theorem diff_eq_foldl : ∀ (l₁ l₂ : list α), l₁.diff l₂ = foldl list.erase l₁ l₂
| l₁ [] := rfl
| l₁ (a::l₂) := (diff_cons l₁ l₂ a).trans (diff_eq_foldl _ _)
@[simp] theorem diff_append (l₁ l₂ l₃ : list α) : l₁.diff (l₂ ++ l₃) = (l₁.diff l₂).diff l₃ :=
by simp only [diff_eq_foldl, foldl_append]
@[simp] theorem map_diff [decidable_eq β] {f : α → β} (finj : injective f) {l₁ l₂ : list α} :
map f (l₁.diff l₂) = (map f l₁).diff (map f l₂) :=
by simp only [diff_eq_foldl, foldl_map, map_foldl_erase finj]
theorem diff_sublist : ∀ l₁ l₂ : list α, l₁.diff l₂ <+ l₁
| l₁ [] := sublist.refl _
| l₁ (a::l₂) := calc l₁.diff (a :: l₂) = (l₁.erase a).diff l₂ : diff_cons _ _ _
... <+ l₁.erase a : diff_sublist _ _
... <+ l₁ : list.erase_sublist _ _
theorem diff_subset (l₁ l₂ : list α) : l₁.diff l₂ ⊆ l₁ :=
(diff_sublist _ _).subset
theorem mem_diff_of_mem {a : α} : ∀ {l₁ l₂ : list α}, a ∈ l₁ → a ∉ l₂ → a ∈ l₁.diff l₂
| l₁ [] h₁ h₂ := h₁
| l₁ (b::l₂) h₁ h₂ := by rw diff_cons; exact
mem_diff_of_mem ((mem_erase_of_ne (ne_of_not_mem_cons h₂)).2 h₁) (not_mem_of_not_mem_cons h₂)
theorem sublist.diff_right : ∀ {l₁ l₂ l₃: list α}, l₁ <+ l₂ → l₁.diff l₃ <+ l₂.diff l₃
| l₁ l₂ [] h := h
| l₁ l₂ (a::l₃) h := by simp only
[diff_cons, (h.erase _).diff_right]
theorem erase_diff_erase_sublist_of_sublist {a : α} : ∀ {l₁ l₂ : list α},
l₁ <+ l₂ → (l₂.erase a).diff (l₁.erase a) <+ l₂.diff l₁
| [] l₂ h := erase_sublist _ _
| (b::l₁) l₂ h := if heq : b = a then by simp only [heq, erase_cons_head, diff_cons]
else by simpa only [erase_cons_head, erase_cons_tail _ heq, diff_cons,
erase_comm a b l₂]
using erase_diff_erase_sublist_of_sublist (h.erase b)
end diff
/-! ### enum -/
theorem length_enum_from : ∀ n (l : list α), length (enum_from n l) = length l
| n [] := rfl
| n (a::l) := congr_arg nat.succ (length_enum_from _ _)
theorem length_enum : ∀ (l : list α), length (enum l) = length l := length_enum_from _
@[simp] theorem enum_from_nth : ∀ n (l : list α) m,
nth (enum_from n l) m = (λ a, (n + m, a)) <$> nth l m
| n [] m := rfl
| n (a :: l) 0 := rfl
| n (a :: l) (m+1) := (enum_from_nth (n+1) l m).trans $
by rw [add_right_comm]; refl
@[simp] theorem enum_nth : ∀ (l : list α) n,
nth (enum l) n = (λ a, (n, a)) <$> nth l n :=
by simp only [enum, enum_from_nth, zero_add]; intros; refl
@[simp] theorem enum_from_map_snd : ∀ n (l : list α),
map prod.snd (enum_from n l) = l
| n [] := rfl
| n (a :: l) := congr_arg (cons _) (enum_from_map_snd _ _)
@[simp] theorem enum_map_snd : ∀ (l : list α),
map prod.snd (enum l) = l := enum_from_map_snd _
theorem mem_enum_from {x : α} {i : ℕ} :
∀ {j : ℕ} (xs : list α), (i, x) ∈ xs.enum_from j → j ≤ i ∧ i < j + xs.length ∧ x ∈ xs
| j [] := by simp [enum_from]
| j (y :: ys) :=
suffices i = j ∧ x = y ∨ (i, x) ∈ enum_from (j + 1) ys →
j ≤ i ∧ i < j + (length ys + 1) ∧ (x = y ∨ x ∈ ys),
by simpa [enum_from, mem_enum_from ys],
begin
rintro (h|h),
{ refine ⟨le_of_eq h.1.symm,h.1 ▸ _,or.inl h.2⟩,
apply nat.lt_add_of_pos_right; simp },
{ obtain ⟨hji, hijlen, hmem⟩ := mem_enum_from _ h,
refine ⟨_, _, _⟩,
{ exact le_trans (nat.le_succ _) hji },
{ convert hijlen using 1, ac_refl },
{ simp [hmem] } }
end
/-! ### product -/
@[simp] theorem nil_product (l : list β) : product (@nil α) l = [] := rfl
@[simp] theorem product_cons (a : α) (l₁ : list α) (l₂ : list β)
: product (a::l₁) l₂ = map (λ b, (a, b)) l₂ ++ product l₁ l₂ := rfl
@[simp] theorem product_nil : ∀ (l : list α), product l (@nil β) = []
| [] := rfl
| (a::l) := by rw [product_cons, product_nil]; refl
@[simp] theorem mem_product {l₁ : list α} {l₂ : list β} {a : α} {b : β} :
(a, b) ∈ product l₁ l₂ ↔ a ∈ l₁ ∧ b ∈ l₂ :=
by simp only [product, mem_bind, mem_map, prod.ext_iff, exists_prop,
and.left_comm, exists_and_distrib_left, exists_eq_left, exists_eq_right]
theorem length_product (l₁ : list α) (l₂ : list β) :
length (product l₁ l₂) = length l₁ * length l₂ :=
by induction l₁ with x l₁ IH; [exact (zero_mul _).symm,
simp only [length, product_cons, length_append, IH,
right_distrib, one_mul, length_map, add_comm]]
/-! ### sigma -/
section
variable {σ : α → Type*}
@[simp] theorem nil_sigma (l : Π a, list (σ a)) : (@nil α).sigma l = [] := rfl
@[simp] theorem sigma_cons (a : α) (l₁ : list α) (l₂ : Π a, list (σ a))
: (a::l₁).sigma l₂ = map (sigma.mk a) (l₂ a) ++ l₁.sigma l₂ := rfl
@[simp] theorem sigma_nil : ∀ (l : list α), l.sigma (λ a, @nil (σ a)) = []
| [] := rfl
| (a::l) := by rw [sigma_cons, sigma_nil]; refl
@[simp] theorem mem_sigma {l₁ : list α} {l₂ : Π a, list (σ a)} {a : α} {b : σ a} :
sigma.mk a b ∈ l₁.sigma l₂ ↔ a ∈ l₁ ∧ b ∈ l₂ a :=
by simp only [list.sigma, mem_bind, mem_map, exists_prop, exists_and_distrib_left,
and.left_comm, exists_eq_left, heq_iff_eq, exists_eq_right]
theorem length_sigma (l₁ : list α) (l₂ : Π a, list (σ a)) :
length (l₁.sigma l₂) = (l₁.map (λ a, length (l₂ a))).sum :=
by induction l₁ with x l₁ IH; [refl,
simp only [map, sigma_cons, length_append, length_map, IH, sum_cons]]
end
/-! ### disjoint -/
section disjoint
theorem disjoint.symm {l₁ l₂ : list α} (d : disjoint l₁ l₂) : disjoint l₂ l₁
| a i₂ i₁ := d i₁ i₂
theorem disjoint_comm {l₁ l₂ : list α} : disjoint l₁ l₂ ↔ disjoint l₂ l₁ :=
⟨disjoint.symm, disjoint.symm⟩
theorem disjoint_left {l₁ l₂ : list α} : disjoint l₁ l₂ ↔ ∀ {a}, a ∈ l₁ → a ∉ l₂ := iff.rfl
theorem disjoint_right {l₁ l₂ : list α} : disjoint l₁ l₂ ↔ ∀ {a}, a ∈ l₂ → a ∉ l₁ :=
disjoint_comm
theorem disjoint_iff_ne {l₁ l₂ : list α} : disjoint l₁ l₂ ↔ ∀ a ∈ l₁, ∀ b ∈ l₂, a ≠ b :=
by simp only [disjoint_left, imp_not_comm, forall_eq']
theorem disjoint_of_subset_left {l₁ l₂ l : list α} (ss : l₁ ⊆ l) (d : disjoint l l₂) :
disjoint l₁ l₂
| x m₁ := d (ss m₁)
theorem disjoint_of_subset_right {l₁ l₂ l : list α} (ss : l₂ ⊆ l) (d : disjoint l₁ l) :
disjoint l₁ l₂
| x m m₁ := d m (ss m₁)
theorem disjoint_of_disjoint_cons_left {a : α} {l₁ l₂} : disjoint (a::l₁) l₂ → disjoint l₁ l₂ :=
disjoint_of_subset_left (list.subset_cons _ _)
theorem disjoint_of_disjoint_cons_right {a : α} {l₁ l₂} : disjoint l₁ (a::l₂) → disjoint l₁ l₂ :=
disjoint_of_subset_right (list.subset_cons _ _)
@[simp] theorem disjoint_nil_left (l : list α) : disjoint [] l
| a := (not_mem_nil a).elim
@[simp] theorem disjoint_nil_right (l : list α) : disjoint l [] :=
by rw disjoint_comm; exact disjoint_nil_left _
@[simp, priority 1100] theorem singleton_disjoint {l : list α} {a : α} : disjoint [a] l ↔ a ∉ l :=
by simp only [disjoint, mem_singleton, forall_eq]; refl
@[simp, priority 1100] theorem disjoint_singleton {l : list α} {a : α} : disjoint l [a] ↔ a ∉ l :=
by rw disjoint_comm; simp only [singleton_disjoint]
@[simp] theorem disjoint_append_left {l₁ l₂ l : list α} :
disjoint (l₁++l₂) l ↔ disjoint l₁ l ∧ disjoint l₂ l :=
by simp only [disjoint, mem_append, or_imp_distrib, forall_and_distrib]
@[simp] theorem disjoint_append_right {l₁ l₂ l : list α} :
disjoint l (l₁++l₂) ↔ disjoint l l₁ ∧ disjoint l l₂ :=
disjoint_comm.trans $ by simp only [disjoint_comm, disjoint_append_left]
@[simp] theorem disjoint_cons_left {a : α} {l₁ l₂ : list α} :
disjoint (a::l₁) l₂ ↔ a ∉ l₂ ∧ disjoint l₁ l₂ :=
(@disjoint_append_left _ [a] l₁ l₂).trans $ by simp only [singleton_disjoint]
@[simp] theorem disjoint_cons_right {a : α} {l₁ l₂ : list α} :
disjoint l₁ (a::l₂) ↔ a ∉ l₁ ∧ disjoint l₁ l₂ :=
disjoint_comm.trans $ by simp only [disjoint_comm, disjoint_cons_left]
theorem disjoint_of_disjoint_append_left_left {l₁ l₂ l : list α} (d : disjoint (l₁++l₂) l) :
disjoint l₁ l :=
(disjoint_append_left.1 d).1
theorem disjoint_of_disjoint_append_left_right {l₁ l₂ l : list α} (d : disjoint (l₁++l₂) l) :
disjoint l₂ l :=
(disjoint_append_left.1 d).2
theorem disjoint_of_disjoint_append_right_left {l₁ l₂ l : list α} (d : disjoint l (l₁++l₂)) :
disjoint l l₁ :=
(disjoint_append_right.1 d).1
theorem disjoint_of_disjoint_append_right_right {l₁ l₂ l : list α} (d : disjoint l (l₁++l₂)) :
disjoint l l₂ :=
(disjoint_append_right.1 d).2
theorem disjoint_take_drop {l : list α} {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
/-! ### union -/
section union
variable [decidable_eq α]
@[simp] theorem nil_union (l : list α) : [] ∪ l = l := rfl
@[simp] theorem cons_union (l₁ l₂ : list α) (a : α) : a :: l₁ ∪ l₂ = insert a (l₁ ∪ l₂) := rfl
@[simp] theorem mem_union {l₁ l₂ : list α} {a : α} : 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, *]
theorem mem_union_left {a : α} {l₁ : list α} (h : a ∈ l₁) (l₂ : list α) : a ∈ l₁ ∪ l₂ :=
mem_union.2 (or.inl h)
theorem mem_union_right {a : α} (l₁ : list α) {l₂ : list α} (h : a ∈ l₂) : a ∈ l₁ ∪ l₂ :=
mem_union.2 (or.inr h)
theorem 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, cons_sublist_cons _ s, by simp only [cons_append, cons_union, e, insert_of_not_mem h];
split; refl⟩
theorem suffix_union_right (l₁ l₂ : list α) : l₂ <:+ l₁ ∪ l₂ :=
(sublist_suffix_of_union l₁ l₂).imp (λ a, and.right)
theorem 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
theorem forall_mem_union {p : α → Prop} {l₁ l₂ : list α} :
(∀ x ∈ l₁ ∪ l₂, p x) ↔ (∀ x ∈ l₁, p x) ∧ (∀ x ∈ l₂, p x) :=
by simp only [mem_union, or_imp_distrib, forall_and_distrib]
theorem forall_mem_of_forall_mem_union_left {p : α → Prop} {l₁ l₂ : list α}
(h : ∀ x ∈ l₁ ∪ l₂, p x) : ∀ x ∈ l₁, p x :=
(forall_mem_union.1 h).1
theorem forall_mem_of_forall_mem_union_right {p : α → Prop} {l₁ l₂ : list α}
(h : ∀ x ∈ l₁ ∪ l₂, p x) : ∀ x ∈ l₂, p x :=
(forall_mem_union.1 h).2
end union
/-! ### inter -/
section inter
variable [decidable_eq α]
@[simp] theorem inter_nil (l : list α) : [] ∩ l = [] := rfl
@[simp] theorem inter_cons_of_mem {a : α} (l₁ : list α) {l₂ : list α} (h : a ∈ l₂) :
(a::l₁) ∩ l₂ = a :: (l₁ ∩ l₂) :=
if_pos h
@[simp] theorem inter_cons_of_not_mem {a : α} (l₁ : list α) {l₂ : list α} (h : a ∉ l₂) :
(a::l₁) ∩ l₂ = l₁ ∩ l₂ :=
if_neg h
theorem mem_of_mem_inter_left {l₁ l₂ : list α} {a : α} : a ∈ l₁ ∩ l₂ → a ∈ l₁ :=
mem_of_mem_filter
theorem mem_of_mem_inter_right {l₁ l₂ : list α} {a : α} : a ∈ l₁ ∩ l₂ → a ∈ l₂ :=
of_mem_filter
theorem mem_inter_of_mem_of_mem {l₁ l₂ : list α} {a : α} : a ∈ l₁ → a ∈ l₂ → a ∈ l₁ ∩ l₂ :=
mem_filter_of_mem
@[simp] theorem mem_inter {a : α} {l₁ l₂ : list α} : a ∈ l₁ ∩ l₂ ↔ a ∈ l₁ ∧ a ∈ l₂ :=
mem_filter
theorem inter_subset_left (l₁ l₂ : list α) : l₁ ∩ l₂ ⊆ l₁ :=
filter_subset _
theorem inter_subset_right (l₁ l₂ : list α) : l₁ ∩ l₂ ⊆ l₂ :=
λ a, mem_of_mem_inter_right
theorem subset_inter {l l₁ l₂ : list α} (h₁ : l ⊆ l₁) (h₂ : l ⊆ l₂) : l ⊆ l₁ ∩ l₂ :=
λ a h, mem_inter.2 ⟨h₁ h, h₂ h⟩
theorem inter_eq_nil_iff_disjoint {l₁ l₂ : list α} : l₁ ∩ l₂ = [] ↔ disjoint l₁ l₂ :=
by simp only [eq_nil_iff_forall_not_mem, mem_inter, not_and]; refl
theorem forall_mem_inter_of_forall_left {p : α → Prop} {l₁ : list α} (h : ∀ x ∈ l₁, p x)
(l₂ : list α) :
∀ x, x ∈ l₁ ∩ l₂ → p x :=
ball.imp_left (λ x, mem_of_mem_inter_left) h
theorem forall_mem_inter_of_forall_right {p : α → Prop} (l₁ : list α) {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]; congr
end inter
section choose
variables (p : α → Prop) [decidable_pred p] (l : list α)
lemma choose_spec (hp : ∃ a, a ∈ l ∧ p a) : choose p l hp ∈ l ∧ p (choose p l hp) :=
(choose_x p l hp).property
lemma choose_mem (hp : ∃ a, a ∈ l ∧ p a) : choose p l hp ∈ l := (choose_spec _ _ _).1
lemma choose_property (hp : ∃ a, a ∈ l ∧ p a) : p (choose p l hp) := (choose_spec _ _ _).2
end choose
/-! ### map₂_left' -/
section map₂_left'
-- The definitional equalities for `map₂_left'` can already be used by the
-- simplifie because `map₂_left'` is marked `@[simp]`.
@[simp] theorem map₂_left'_nil_right (f : α → option β → γ) (as) :
map₂_left' f as [] = (as.map (λ a, f a none), []) :=
by cases as; refl
end map₂_left'
/-! ### map₂_right' -/
section map₂_right'
variables (f : option α → β → γ) (a : α) (as : list α) (b : β) (bs : list β)
@[simp] theorem map₂_right'_nil_left :
map₂_right' f [] bs = (bs.map (f none), []) :=
by cases bs; refl
@[simp] theorem map₂_right'_nil_right :
map₂_right' f as [] = ([], as) :=
rfl
@[simp] theorem map₂_right'_nil_cons :
map₂_right' f [] (b :: bs) = (f none b :: bs.map (f none), []) :=
rfl
@[simp] theorem map₂_right'_cons_cons :
map₂_right' f (a :: as) (b :: bs) =
let rec := map₂_right' f as bs in
(f (some a) b :: rec.fst, rec.snd) :=
rfl
end map₂_right'
/-! ### zip_left' -/
section zip_left'
variables (a : α) (as : list α) (b : β) (bs : list β)
@[simp] theorem zip_left'_nil_right :
zip_left' as ([] : list β) = (as.map (λ a, (a, none)), []) :=
by cases as; refl
@[simp] theorem zip_left'_nil_left :
zip_left' ([] : list α) bs = ([], bs) :=
rfl
@[simp] theorem zip_left'_cons_nil :
zip_left' (a :: as) ([] : list β) = ((a, none) :: as.map (λ a, (a, none)), []) :=
rfl
@[simp] theorem zip_left'_cons_cons :
zip_left' (a :: as) (b :: bs) =
let rec := zip_left' as bs in
((a, some b) :: rec.fst, rec.snd) :=
rfl
end zip_left'
/-! ### zip_right' -/
section zip_right'
variables (a : α) (as : list α) (b : β) (bs : list β)
@[simp] theorem zip_right'_nil_left :
zip_right' ([] : list α) bs = (bs.map (λ b, (none, b)), []) :=
by cases bs; refl
@[simp] theorem zip_right'_nil_right :
zip_right' as ([] : list β) = ([], as) :=
rfl
@[simp] theorem zip_right'_nil_cons :
zip_right' ([] : list α) (b :: bs) = ((none, b) :: bs.map (λ b, (none, b)), []) :=
rfl
@[simp] theorem zip_right'_cons_cons :
zip_right' (a :: as) (b :: bs) =
let rec := zip_right' as bs in
((some a, b) :: rec.fst, rec.snd) :=
rfl
end zip_right'
/-! ### map₂_left -/
section map₂_left
variables (f : α → option β → γ) (as : list α)
-- The definitional equalities for `map₂_left` can already be used by the
-- simplifier because `map₂_left` is marked `@[simp]`.
@[simp] theorem map₂_left_nil_right :
map₂_left f as [] = as.map (λ a, f a none) :=
by cases as; refl
theorem map₂_left_eq_map₂_left' : ∀ as bs,
map₂_left f as bs = (map₂_left' f as bs).fst
| [] bs := by simp!
| (a :: as) [] := by simp!
| (a :: as) (b :: bs) := by simp! [*]
theorem map₂_left_eq_map₂ : ∀ as bs,
length as ≤ length bs →
map₂_left f as bs = map₂ (λ a b, f a (some b)) as bs
| [] [] h := by simp!
| [] (b :: bs) h := by simp!
| (a :: as) [] h := by { simp at h, contradiction }
| (a :: as) (b :: bs) h := by { simp at h, simp! [*] }
end map₂_left
/-! ### map₂_right -/
section map₂_right
variables (f : option α → β → γ) (a : α) (as : list α) (b : β) (bs : list β)
@[simp] theorem map₂_right_nil_left :
map₂_right f [] bs = bs.map (f none) :=
by cases bs; refl
@[simp] theorem map₂_right_nil_right :
map₂_right f as [] = [] :=
rfl
@[simp] theorem map₂_right_nil_cons :
map₂_right f [] (b :: bs) = f none b :: bs.map (f none) :=
rfl
@[simp] theorem map₂_right_cons_cons :
map₂_right f (a :: as) (b :: bs) = f (some a) b :: map₂_right f as bs :=
rfl
theorem map₂_right_eq_map₂_right' :
map₂_right f as bs = (map₂_right' f as bs).fst :=
by simp only [map₂_right, map₂_right', map₂_left_eq_map₂_left']
theorem map₂_right_eq_map₂ (h : length bs ≤ length as) :
map₂_right f as bs = map₂ (λ a b, f (some a) b) as bs :=
begin
have : (λ a b, flip f a (some b)) = (flip (λ a b, f (some a) b)) := rfl,
simp only [map₂_right, map₂_left_eq_map₂, map₂_flip, *]
end
end map₂_right
/-! ### zip_left -/
section zip_left
variables (a : α) (as : list α) (b : β) (bs : list β)
@[simp] theorem zip_left_nil_right :
zip_left as ([] : list β) = as.map (λ a, (a, none)) :=
by cases as; refl
@[simp] theorem zip_left_nil_left :
zip_left ([] : list α) bs = [] :=
rfl
@[simp] theorem zip_left_cons_nil :
zip_left (a :: as) ([] : list β) = (a, none) :: as.map (λ a, (a, none)) :=
rfl
@[simp] theorem zip_left_cons_cons :
zip_left (a :: as) (b :: bs) = (a, some b) :: zip_left as bs :=
rfl
theorem zip_left_eq_zip_left' :
zip_left as bs = (zip_left' as bs).fst :=
by simp only [zip_left, zip_left', map₂_left_eq_map₂_left']
end zip_left
/-! ### zip_right -/
section zip_right
variables (a : α) (as : list α) (b : β) (bs : list β)
@[simp] theorem zip_right_nil_left :
zip_right ([] : list α) bs = bs.map (λ b, (none, b)) :=
by cases bs; refl
@[simp] theorem zip_right_nil_right :
zip_right as ([] : list β) = [] :=
rfl
@[simp] theorem zip_right_nil_cons :
zip_right ([] : list α) (b :: bs) = (none, b) :: bs.map (λ b, (none, b)) :=
rfl
@[simp] theorem zip_right_cons_cons :
zip_right (a :: as) (b :: bs) = (some a, b) :: zip_right as bs :=
rfl
theorem zip_right_eq_zip_right' :
zip_right as bs = (zip_right' as bs).fst :=
by simp only [zip_right, zip_right', map₂_right_eq_map₂_right']
end zip_right
/-! ### Miscellaneous lemmas -/
theorem ilast'_mem : ∀ a l, @ilast' α a l ∈ a :: l
| a [] := or.inl rfl
| a (b::l) := or.inr (ilast'_mem b l)
@[simp] lemma nth_le_attach (L : list α) (i) (H : i < L.attach.length) :
(L.attach.nth_le i H).1 = L.nth_le i (length_attach L ▸ H) :=
calc (L.attach.nth_le i H).1
= (L.attach.map subtype.val).nth_le i (by simpa using H) : by rw nth_le_map'
... = L.nth_le i _ : by congr; apply attach_map_val
end list
@[to_additive]
theorem monoid_hom.map_list_prod {α β : Type*} [monoid α] [monoid β] (f : α →* β) (l : list α) :
f l.prod = (l.map f).prod :=
(l.prod_hom f).symm
namespace list
@[to_additive]
theorem prod_map_hom {α β γ : Type*} [monoid β] [monoid γ] (L : list α) (f : α → β) (g : β →* γ) :
(L.map (g ∘ f)).prod = g ((L.map f).prod) :=
by {rw g.map_list_prod, exact congr_arg _ (map_map _ _ _).symm}
theorem sum_map_mul_left {α : Type*} [semiring α] {β : Type*} (L : list β)
(f : β → α) (r : α) :
(L.map (λ b, r * f b)).sum = r * (L.map f).sum :=
sum_map_hom L f $ add_monoid_hom.mul_left r
theorem sum_map_mul_right {α : Type*} [semiring α] {β : Type*} (L : list β)
(f : β → α) (r : α) :
(L.map (λ b, f b * r)).sum = (L.map f).sum * r :=
sum_map_hom L f $ add_monoid_hom.mul_right r
universes u v
@[simp]
theorem mem_map_swap {α : Type u} {β : Type v} (x : α) (y : β) (xs : list (α × β)) :
(y, x) ∈ map prod.swap xs ↔ (x, y) ∈ xs :=
begin
induction xs with x xs,
{ simp only [not_mem_nil, map_nil] },
{ cases x with a b,
simp only [mem_cons_iff, prod.mk.inj_iff, map, prod.swap_prod_mk, prod.exists, xs_ih],
tauto! },
end
lemma slice_eq {α} (xs : list α) (n m : ℕ) :
slice n m xs = xs.take n ++ xs.drop (n+m) :=
begin
induction n generalizing xs,
{ simp [slice] },
{ cases xs; simp [slice, *, nat.succ_add], }
end
lemma sizeof_slice_lt {α} [has_sizeof α] (i j : ℕ) (hj : 0 < j) (xs : list α) (hi : i < xs.length) :
sizeof (list.slice i j xs) < sizeof xs :=
begin
induction xs generalizing i j,
case list.nil : i j h
{ cases hi },
case list.cons : x xs xs_ih i j h
{ cases i; simp only [-slice_eq, list.slice],
{ cases j, cases h,
dsimp only [drop], unfold_wf,
apply @lt_of_le_of_lt _ _ _ xs.sizeof,
{ clear_except,
induction xs generalizing j; unfold_wf,
case list.nil : j
{ refl },
case list.cons : xs_hd xs_tl xs_ih j
{ cases j; unfold_wf, refl,
transitivity, apply xs_ih,
simp }, },
unfold_wf, apply zero_lt_one_add, },
{ unfold_wf, apply xs_ih _ _ h,
apply lt_of_succ_lt_succ hi, } },
end
end list
|
66cadd90f5759332570b834c120eaf8a201325c8 | 5c4a0908390c4938ae21bc616ff2a969ce62fd76 | /library/theories/analysis/metric_space.lean | 386c1ec805dc45500668920e5652c03786d231e2 | [
"Apache-2.0"
] | permissive | Bpalkmim/lean | 968be8a73a06fa6db19073cd463d2093464dc0f6 | 994815bc7793f5765beb693c82341cf01d20d807 | refs/heads/master | 1,610,964,748,106 | 1,455,564,675,000 | 1,455,564,675,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 27,638 | lean | /-
Copyright (c) 2015 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Jeremy Avigad
Metric spaces.
-/
import data.real.complete data.pnat data.list.sort ..topology.basic data.set
open nat real eq.ops classical
structure metric_space [class] (M : Type) : Type :=
(dist : M → M → ℝ)
(dist_self : ∀ x : M, dist x x = 0)
(eq_of_dist_eq_zero : ∀ {x y : M}, dist x y = 0 → x = y)
(dist_comm : ∀ x y : M, dist x y = dist y x)
(dist_triangle : ∀ x y z : M, dist x z ≤ dist x y + dist y z)
namespace analysis
section metric_space_M
variables {M : Type} [metric_space M]
definition dist (x y : M) : ℝ := metric_space.dist x y
proposition dist_self (x : M) : dist x x = 0 := metric_space.dist_self x
proposition eq_of_dist_eq_zero {x y : M} (H : dist x y = 0) : x = y :=
metric_space.eq_of_dist_eq_zero H
proposition dist_comm (x y : M) : dist x y = dist y x := metric_space.dist_comm x y
proposition dist_eq_zero_iff (x y : M) : dist x y = 0 ↔ x = y :=
iff.intro eq_of_dist_eq_zero (suppose x = y, this ▸ !dist_self)
proposition dist_triangle (x y z : M) : dist x z ≤ dist x y + dist y z :=
metric_space.dist_triangle x y z
proposition dist_nonneg (x y : M) : 0 ≤ dist x y :=
have dist x y + dist y x ≥ 0, by rewrite -(dist_self x); apply dist_triangle,
have 2 * dist x y ≥ 0, using this,
by krewrite [-real.one_add_one, right_distrib, +one_mul, dist_comm at {2}]; apply this,
nonneg_of_mul_nonneg_left this two_pos
proposition dist_pos_of_ne {x y : M} (H : x ≠ y) : dist x y > 0 :=
lt_of_le_of_ne !dist_nonneg (suppose 0 = dist x y, H (iff.mp !dist_eq_zero_iff this⁻¹))
proposition ne_of_dist_pos {x y : M} (H : dist x y > 0) : x ≠ y :=
suppose x = y,
have H1 [visible] : dist x x > 0, by rewrite this at {2}; exact H,
by rewrite dist_self at H1; apply not_lt_self _ H1
proposition eq_of_forall_dist_le {x y : M} (H : ∀ ε, ε > 0 → dist x y ≤ ε) : x = y :=
eq_of_dist_eq_zero (eq_zero_of_nonneg_of_forall_le !dist_nonneg H)
/- convergence of a sequence -/
definition converges_to_seq (X : ℕ → M) (y : M) : Prop :=
∀ ⦃ε : ℝ⦄, ε > 0 → ∃ N : ℕ, ∀ ⦃n⦄, n ≥ N → dist (X n) y < ε
-- the same, with ≤ in place of <; easier to prove, harder to use
definition converges_to_seq.intro {X : ℕ → M} {y : M}
(H : ∀ ⦃ε : ℝ⦄, ε > 0 → ∃ N : ℕ, ∀ {n}, n ≥ N → dist (X n) y ≤ ε) :
converges_to_seq X y :=
take ε, assume epos : ε > 0,
have e2pos : ε / 2 > 0, from div_pos_of_pos_of_pos `ε > 0` two_pos,
obtain N HN, from H e2pos,
exists.intro N
(take n, suppose n ≥ N,
calc
dist (X n) y ≤ ε / 2 : HN _ `n ≥ N`
... < ε : div_two_lt_of_pos epos)
notation X `⟶` y `in` `ℕ` := converges_to_seq X y
definition converges_seq [class] (X : ℕ → M) : Prop := ∃ y, X ⟶ y in ℕ
noncomputable definition limit_seq (X : ℕ → M) [H : converges_seq X] : M := some H
proposition converges_to_limit_seq (X : ℕ → M) [H : converges_seq X] :
(X ⟶ limit_seq X in ℕ) :=
some_spec H
proposition converges_to_seq_unique {X : ℕ → M} {y₁ y₂ : M}
(H₁ : X ⟶ y₁ in ℕ) (H₂ : X ⟶ y₂ in ℕ) : y₁ = y₂ :=
eq_of_forall_dist_le
(take ε, suppose ε > 0,
have e2pos : ε / 2 > 0, from div_pos_of_pos_of_pos `ε > 0` two_pos,
obtain N₁ (HN₁ : ∀ {n}, n ≥ N₁ → dist (X n) y₁ < ε / 2), from H₁ e2pos,
obtain N₂ (HN₂ : ∀ {n}, n ≥ N₂ → dist (X n) y₂ < ε / 2), from H₂ e2pos,
let N := max N₁ N₂ in
have dN₁ : dist (X N) y₁ < ε / 2, from HN₁ !le_max_left,
have dN₂ : dist (X N) y₂ < ε / 2, from HN₂ !le_max_right,
have dist y₁ y₂ < ε, from calc
dist y₁ y₂ ≤ dist y₁ (X N) + dist (X N) y₂ : dist_triangle
... = dist (X N) y₁ + dist (X N) y₂ : dist_comm
... < ε / 2 + ε / 2 : add_lt_add dN₁ dN₂
... = ε : add_halves,
show dist y₁ y₂ ≤ ε, from le_of_lt this)
proposition eq_limit_of_converges_to_seq {X : ℕ → M} {y : M} (H : X ⟶ y in ℕ) :
y = @limit_seq M _ X (exists.intro y H) :=
converges_to_seq_unique H (@converges_to_limit_seq M _ X (exists.intro y H))
proposition converges_to_seq_constant (y : M) : (λn, y) ⟶ y in ℕ :=
take ε, assume egt0 : ε > 0,
exists.intro 0
(take n, suppose n ≥ 0,
calc
dist y y = 0 : !dist_self
... < ε : egt0)
proposition converges_to_seq_offset {X : ℕ → M} {y : M} (k : ℕ) (H : X ⟶ y in ℕ) :
(λ n, X (n + k)) ⟶ y in ℕ :=
take ε, suppose ε > 0,
obtain N HN, from H `ε > 0`,
exists.intro N
(take n : ℕ, assume ngtN : n ≥ N,
show dist (X (n + k)) y < ε, from HN (n + k) (le.trans ngtN !le_add_right))
proposition converges_to_seq_offset_left {X : ℕ → M} {y : M} (k : ℕ) (H : X ⟶ y in ℕ) :
(λ n, X (k + n)) ⟶ y in ℕ :=
have aux : (λ n, X (k + n)) = (λ n, X (n + k)), from funext (take n, by rewrite add.comm),
by+ rewrite aux; exact converges_to_seq_offset k H
proposition converges_to_seq_offset_succ {X : ℕ → M} {y : M} (H : X ⟶ y in ℕ) :
(λ n, X (succ n)) ⟶ y in ℕ :=
converges_to_seq_offset 1 H
proposition converges_to_seq_of_converges_to_seq_offset
{X : ℕ → M} {y : M} {k : ℕ} (H : (λ n, X (n + k)) ⟶ y in ℕ) :
X ⟶ y in ℕ :=
take ε, suppose ε > 0,
obtain N HN, from H `ε > 0`,
exists.intro (N + k)
(take n : ℕ, assume nge : n ≥ N + k,
have n - k ≥ N, from nat.le_sub_of_add_le nge,
have dist (X (n - k + k)) y < ε, from HN (n - k) this,
show dist (X n) y < ε, using this,
by rewrite [(nat.sub_add_cancel (le.trans !le_add_left nge)) at this]; exact this)
proposition converges_to_seq_of_converges_to_seq_offset_left
{X : ℕ → M} {y : M} {k : ℕ} (H : (λ n, X (k + n)) ⟶ y in ℕ) :
X ⟶ y in ℕ :=
have aux : (λ n, X (k + n)) = (λ n, X (n + k)), from funext (take n, by rewrite add.comm),
by+ rewrite aux at H; exact converges_to_seq_of_converges_to_seq_offset H
proposition converges_to_seq_of_converges_to_seq_offset_succ
{X : ℕ → M} {y : M} (H : (λ n, X (succ n)) ⟶ y in ℕ) :
X ⟶ y in ℕ :=
@converges_to_seq_of_converges_to_seq_offset M _ X y 1 H
proposition converges_to_seq_offset_iff (X : ℕ → M) (y : M) (k : ℕ) :
((λ n, X (n + k)) ⟶ y in ℕ) ↔ (X ⟶ y in ℕ) :=
iff.intro converges_to_seq_of_converges_to_seq_offset !converges_to_seq_offset
proposition converges_to_seq_offset_left_iff (X : ℕ → M) (y : M) (k : ℕ) :
((λ n, X (k + n)) ⟶ y in ℕ) ↔ (X ⟶ y in ℕ) :=
iff.intro converges_to_seq_of_converges_to_seq_offset_left !converges_to_seq_offset_left
proposition converges_to_seq_offset_succ_iff (X : ℕ → M) (y : M) :
((λ n, X (succ n)) ⟶ y in ℕ) ↔ (X ⟶ y in ℕ) :=
iff.intro converges_to_seq_of_converges_to_seq_offset_succ !converges_to_seq_offset_succ
section
open list
definition r_trans : transitive (@le ℝ _) := λ a b c, !le.trans
definition r_refl : reflexive (@le ℝ _) := λ a, !le.refl
theorem dec_prf_eq (P : Prop) (H1 H2 : decidable P) : H1 = H2 :=
begin
induction H1,
induction H2,
reflexivity,
apply absurd a a_1,
induction H2,
apply absurd a_1 a,
reflexivity
end
-- there's a very ugly part of this proof.
proposition bounded_of_converges_seq {X : ℕ → M} {x : M} (H : X ⟶ x in ℕ) :
∃ K : ℝ, ∀ n : ℕ, dist (X n) x ≤ K :=
begin
cases H zero_lt_one with N HN,
cases em (N = 0),
existsi 1,
intro n,
apply le_of_lt,
apply HN,
rewrite a,
apply zero_le,
let l := map (λ n : ℕ, -dist (X n) x) (upto N),
have Hnenil : l ≠ nil, from (map_ne_nil_of_ne_nil _ (upto_ne_nil_of_ne_zero a)),
existsi max (-list.min (λ a b : ℝ, le a b) l Hnenil) 1,
intro n,
have Hsmn : ∀ m : ℕ, m < N → dist (X m) x ≤ max (-list.min (λ a b : ℝ, le a b) l Hnenil) 1, begin
intro m Hm,
apply le.trans,
rotate 1,
apply le_max_left,
note Hall := min_lemma real.le_total r_trans r_refl Hnenil,
have Hmem : -dist (X m) x ∈ (map (λ (n : ℕ), -dist (X n) x) (upto N)), from mem_map _ (mem_upto_of_lt Hm),
note Hallm' := of_mem_of_all Hmem Hall,
apply le_neg_of_le_neg,
esimp, esimp at Hallm',
have Heqs : (λ (a b : real), classical.prop_decidable (@le.{1} real real.real_has_le a b))
=
(@decidable_le.{1} real
(@decidable_linear_ordered_comm_group.to_decidable_linear_order.{1} real
(@decidable_linear_ordered_comm_ring.to_decidable_linear_ordered_comm_group.{1} real
(@discrete_linear_ordered_field.to_decidable_linear_ordered_comm_ring.{1} real
real.discrete_linear_ordered_field)))),
begin
apply funext, intro, apply funext, intro,
apply dec_prf_eq
end,
rewrite -Heqs,
exact Hallm'
end,
cases em (n < N) with Elt Ege,
apply Hsmn,
exact Elt,
apply le_of_lt,
apply lt_of_lt_of_le,
apply HN,
apply le_of_not_gt Ege,
apply le_max_right
end
end
/- cauchy sequences -/
definition cauchy (X : ℕ → M) : Prop :=
∀ ε : ℝ, ε > 0 → ∃ N, ∀ m n, m ≥ N → n ≥ N → dist (X m) (X n) < ε
proposition cauchy_of_converges_seq (X : ℕ → M) [H : converges_seq X] : cauchy X :=
take ε, suppose ε > 0,
obtain y (Hy : converges_to_seq X y), from H,
have e2pos : ε / 2 > 0, from div_pos_of_pos_of_pos `ε > 0` two_pos,
obtain N₁ (HN₁ : ∀ {n}, n ≥ N₁ → dist (X n) y < ε / 2), from Hy e2pos,
obtain N₂ (HN₂ : ∀ {n}, n ≥ N₂ → dist (X n) y < ε / 2), from Hy e2pos,
let N := max N₁ N₂ in
exists.intro N
(take m n, suppose m ≥ N, suppose n ≥ N,
have m ≥ N₁, from le.trans !le_max_left `m ≥ N`,
have n ≥ N₂, from le.trans !le_max_right `n ≥ N`,
have dN₁ : dist (X m) y < ε / 2, from HN₁ `m ≥ N₁`,
have dN₂ : dist (X n) y < ε / 2, from HN₂ `n ≥ N₂`,
show dist (X m) (X n) < ε, from calc
dist (X m) (X n) ≤ dist (X m) y + dist y (X n) : dist_triangle
... = dist (X m) y + dist (X n) y : dist_comm
... < ε / 2 + ε / 2 : add_lt_add dN₁ dN₂
... = ε : add_halves)
end metric_space_M
/- convergence of a function at a point -/
section metric_space_M_N
variables {M N : Type} [strucM : metric_space M] [strucN : metric_space N]
include strucM strucN
definition converges_to_at (f : M → N) (y : N) (x : M) :=
∀ ⦃ε⦄, ε > 0 → ∃ δ, δ > 0 ∧ ∀ ⦃x'⦄, x' ≠ x ∧ dist x' x < δ → dist (f x') y < ε
notation f `⟶` y `at` x := converges_to_at f y x
definition converges_at [class] (f : M → N) (x : M) :=
∃ y, converges_to_at f y x
noncomputable definition limit_at (f : M → N) (x : M) [H : converges_at f x] : N :=
some H
proposition converges_to_limit_at (f : M → N) (x : M) [H : converges_at f x] :
(f ⟶ limit_at f x at x) :=
some_spec H
section
omit strucN
set_option pp.coercions true
--set_option pp.all true
open pnat rat
section
omit strucM
private lemma of_rat_rat_of_pnat_eq_of_nat_nat_of_pnat (p : pnat) :
of_rat (rat_of_pnat p) = of_nat (nat_of_pnat p) :=
rfl
end
theorem cnv_real_of_cnv_nat {X : ℕ → M} {c : M} (H : ∀ n : ℕ, dist (X n) c < 1 / (real.of_nat n + 1)) :
∀ ε : ℝ, ε > 0 → ∃ N : ℕ, ∀ n : ℕ, n ≥ N → dist (X n) c < ε :=
begin
intros ε Hε,
cases ex_rat_pos_lower_bound_of_pos Hε with q Hq,
cases Hq with Hq1 Hq2,
cases pnat_bound Hq1 with p Hp,
existsi nat_of_pnat p,
intros n Hn,
apply lt_of_lt_of_le,
apply H,
apply le.trans,
rotate 1,
apply Hq2,
have Hrat : of_rat (inv p) ≤ of_rat q, from of_rat_le_of_rat_of_le Hp,
apply le.trans,
rotate 1,
exact Hrat,
change 1 / (of_nat n + 1) ≤ of_rat ((1 : ℚ) / (rat_of_pnat p)),
rewrite [of_rat_divide, of_rat_one],
eapply one_div_le_one_div_of_le,
krewrite -of_rat_zero,
apply of_rat_lt_of_rat_of_lt,
apply rat_of_pnat_is_pos,
krewrite [of_rat_rat_of_pnat_eq_of_nat_nat_of_pnat, -real.of_nat_add],
apply real.of_nat_le_of_nat_of_le,
apply le_add_of_le_right,
assumption
end
end
theorem all_conv_seqs_of_converges_to_at {f : M → N} {c : M} {l : N} (Hconv : f ⟶ l at c) :
∀ X : ℕ → M, ((∀ n : ℕ, ((X n) ≠ c) ∧ (X ⟶ c in ℕ)) → ((λ n : ℕ, f (X n)) ⟶ l in ℕ)) :=
begin
intros X HX,
rewrite [↑converges_to_at at Hconv, ↑converges_to_seq],
intros ε Hε,
cases Hconv Hε with δ Hδ,
cases Hδ with Hδ1 Hδ2,
cases HX 0 with _ HXlim,
cases HXlim Hδ1 with N1 HN1,
existsi N1,
intro n Hn,
apply Hδ2,
split,
apply and.left (HX _),
exact HN1 Hn
end
theorem converges_to_at_of_all_conv_seqs {f : M → N} (c : M) (l : N)
(Hseq : ∀ X : ℕ → M, ((∀ n : ℕ, ((X n) ≠ c) ∧ (X ⟶ c in ℕ)) → ((λ n : ℕ, f (X n)) ⟶ l in ℕ)))
: f ⟶ l at c :=
by_contradiction
(assume Hnot : ¬ (f ⟶ l at c),
obtain ε Hε, from exists_not_of_not_forall Hnot,
let Hε' := iff.mp not_implies_iff_and_not Hε in
obtain (H1 : ε > 0) H2, from Hε',
have H3 [visible] : ∀ δ : ℝ, (δ > 0 → ∃ x' : M, x' ≠ c ∧ dist x' c < δ ∧ dist (f x') l ≥ ε), begin -- tedious!!
intros δ Hδ,
note Hε'' := forall_not_of_not_exists H2,
note H4 := forall_not_of_not_exists H2 δ,
have ¬ (∀ x' : M, x' ≠ c ∧ dist x' c < δ → dist (f x') l < ε), from λ H', H4 (and.intro Hδ H'),
note H5 := exists_not_of_not_forall this,
cases H5 with x' Hx',
existsi x',
note H6 := iff.mp not_implies_iff_and_not Hx',
rewrite and.assoc at H6,
cases H6,
split,
assumption,
cases a_1,
split,
assumption,
apply le_of_not_gt,
assumption
end,
let S : ℕ → M → Prop := λ n x, 0 < dist x c ∧ dist x c < 1 / (of_nat n + 1) ∧ dist (f x) l ≥ ε in
have HS [visible] : ∀ n : ℕ, ∃ m : M, S n m, begin
intro k,
have Hpos : 0 < of_nat k + 1, from of_nat_succ_pos k,
cases H3 (1 / (k + 1)) (one_div_pos_of_pos Hpos) with x' Hx',
cases Hx' with Hne Hx',
cases Hx' with Hdistl Hdistg,
existsi x',
esimp,
split,
apply dist_pos_of_ne,
assumption,
split,
repeat assumption
end,
let X : ℕ → M := λ n, some (HS n) in
have H4 [visible] : ∀ n : ℕ, ((X n) ≠ c) ∧ (X ⟶ c in ℕ), from
(take n, and.intro
(begin
note Hspec := some_spec (HS n),
esimp, esimp at Hspec,
cases Hspec,
apply ne_of_dist_pos,
assumption
end)
(begin
apply cnv_real_of_cnv_nat,
intro m,
note Hspec := some_spec (HS m),
esimp, esimp at Hspec,
cases Hspec with Hspec1 Hspec2,
cases Hspec2,
assumption
end)),
have H5 [visible] : (λ n : ℕ, f (X n)) ⟶ l in ℕ, from Hseq X H4,
begin
note H6 := H5 H1,
cases H6 with Q HQ,
note HQ' := HQ !le.refl,
esimp at HQ',
apply absurd HQ',
apply not_lt_of_ge,
note H7 := some_spec (HS Q),
esimp at H7,
cases H7 with H71 H72,
cases H72,
assumption
end)
end metric_space_M_N
section topology
/- A metric space is a topological space. -/
open set prod topology
variables {V : Type} [Vmet : metric_space V]
include Vmet
definition open_ball (x : V) (ε : ℝ) := {y ∈ univ | dist x y < ε}
theorem open_ball_empty_of_nonpos (x : V) {ε : ℝ} (Hε : ε ≤ 0) : open_ball x ε = ∅ :=
begin
apply eq_empty_of_forall_not_mem,
intro y Hy,
note Hlt := and.right Hy,
apply not_lt_of_ge (dist_nonneg x y),
apply lt_of_lt_of_le Hlt Hε
end
theorem radius_pos_of_nonempty {x : V} {ε : ℝ} {u : V} (Hu : u ∈ open_ball x ε) : ε > 0 :=
begin
apply lt_of_not_ge,
intro Hge,
note Hop := open_ball_empty_of_nonpos x Hge,
rewrite Hop at Hu,
apply not_mem_empty _ Hu
end
theorem mem_open_ball (x : V) {ε : ℝ} (H : ε > 0) : x ∈ open_ball x ε :=
suffices x ∈ univ ∧ dist x x < ε, from this,
and.intro !mem_univ (by rewrite dist_self; assumption)
definition closed_ball (x : V) (ε : ℝ) := {y ∈ univ | dist x y ≤ ε}
theorem closed_ball_eq_comp (x : V) (ε : ℝ) : closed_ball x ε = -{y ∈ univ | dist x y > ε} :=
begin
apply ext,
intro y,
apply iff.intro,
intro Hx,
apply mem_comp,
intro Hxmem,
cases Hxmem with _ Hgt,
cases Hx with _ Hle,
apply not_le_of_gt Hgt Hle,
intro Hx,
note Hx' := not_mem_of_mem_comp Hx,
split,
apply mem_univ,
apply le_of_not_gt,
intro Hgt,
apply Hx',
split,
apply mem_univ,
assumption
end
omit Vmet
definition open_sets_basis (V : Type) [metric_space V] :=
image (λ pair : V × ℝ, open_ball (pr1 pair) (pr2 pair)) univ
definition metric_topology [instance] (V : Type) [metric_space V] : topology V :=
topology.generated_by (open_sets_basis V)
include Vmet
theorem open_ball_mem_open_sets_basis (x : V) (ε : ℝ) : (open_ball x ε) ∈ (open_sets_basis V) :=
mem_image !mem_univ rfl
theorem open_ball_open (x : V) (ε : ℝ) : Open (open_ball x ε) :=
by apply generators_mem_topology_generated_by; apply open_ball_mem_open_sets_basis
theorem closed_ball_closed (x : V) {ε : ℝ} (H : ε > 0) : closed (closed_ball x ε) :=
begin
apply iff.mpr !closed_iff_Open_comp,
rewrite closed_ball_eq_comp,
rewrite comp_comp,
apply Open_of_forall_exists_Open_nbhd,
intro y Hy,
cases Hy with _ Hxy,
existsi open_ball y (dist x y - ε),
split,
apply open_ball_open,
split,
apply mem_open_ball,
apply sub_pos_of_lt Hxy,
intros y' Hy',
cases Hy' with _ Hxy'd,
rewrite dist_comm at Hxy'd,
split,
apply mem_univ,
apply lt_of_not_ge,
intro Hxy',
apply not_lt_self (dist x y),
exact calc
dist x y ≤ dist x y' + dist y' y : dist_triangle
... ≤ ε + dist y' y : add_le_add_right Hxy'
... < ε + (dist x y - ε) : add_lt_add_left Hxy'd
... = dist x y : by rewrite [add.comm, sub_add_cancel]
end
private theorem not_mem_open_basis_of_boundary_pt {s : set V} (a : s ∈ open_sets_basis V) {x : V}
(Hbd : ∀ ε : ℝ, ε > 0 → ∃ v : V, v ∉ s ∧ dist x v < ε) : ¬ x ∈ s :=
begin
intro HxU,
cases a with pr Hpr,
cases pr with y r,
cases Hpr with _ Hs,
rewrite -Hs at HxU,
have H : dist y x < r, from and.right HxU,
cases Hbd _ (sub_pos_of_lt H) with v Hv,
cases Hv with Hv Hvdist,
apply Hv,
rewrite -Hs,
apply and.intro,
apply mem_univ,
apply lt_of_le_of_lt,
apply dist_triangle,
exact x,
esimp,
exact calc
dist y x + dist x v < dist y x + (r - dist y x) : add_lt_add_left Hvdist
... = r : by rewrite [add.comm, sub_add_cancel]
end
private theorem not_mem_intersect_of_boundary_pt {s t : set V} (a : Open s) (a_1 : Open t) {x : V}
(v_0 : (x ∈ s → ¬ (∀ (ε : ℝ), ε > 0 → (∃ (v : V), v ∉ s ∧ dist x v < ε))))
(v_1 : (x ∈ t → ¬ (∀ (ε : ℝ), ε > 0 → (∃ (v : V), v ∉ t ∧ dist x v < ε))))
(Hbd : ∀ (ε : ℝ), ε > 0 → (∃ (v : V), v ∉ s ∩ t ∧ dist x v < ε)) : ¬ (x ∈ s ∩ t) :=
begin
intro HxU,
have Hxs : x ∈ s, from mem_of_mem_inter_left HxU,
have Hxt : x ∈ t, from mem_of_mem_inter_right HxU,
note Hsih := exists_not_of_not_forall (v_0 Hxs),
note Htih := exists_not_of_not_forall (v_1 Hxt),
cases Hsih with ε1 Hε1,
cases Htih with ε2 Hε2,
note Hε1' := iff.mp not_implies_iff_and_not Hε1,
note Hε2' := iff.mp not_implies_iff_and_not Hε2,
cases Hε1' with Hε1p Hε1',
cases Hε2' with Hε2p Hε2',
note Hε1'' := forall_not_of_not_exists Hε1',
note Hε2'' := forall_not_of_not_exists Hε2',
have Hmin : min ε1 ε2 > 0, from lt_min Hε1p Hε2p,
cases Hbd _ Hmin with v Hv,
cases Hv with Hvint Hvdist,
note Hε1v := Hε1'' v,
note Hε2v := Hε2'' v,
cases em (v ∉ s) with Hnm Hmem,
apply Hε1v,
split,
exact Hnm,
apply lt_of_lt_of_le Hvdist,
apply min_le_left,
apply Hε2v,
have Hmem' : v ∈ s, from not_not_elim Hmem,
note Hnm := not_mem_of_mem_of_not_mem_inter_left Hmem' Hvint,
split,
exact Hnm,
apply lt_of_lt_of_le Hvdist,
apply min_le_right
end
private theorem not_mem_sUnion_of_boundary_pt {S : set (set V)} (a : ∀₀ s ∈ S, Open s) {x : V}
(v_0 : ∀ ⦃x_1 : set V⦄,
x_1 ∈ S → x ∈ x_1 → ¬ (∀ (ε : ℝ), ε > 0 → (∃ (v : V), v ∉ x_1 ∧ dist x v < ε)))
(Hbd : ∀ (ε : ℝ), ε > 0 → (∃ (v : V), v ∉ ⋃₀ S ∧ dist x v < ε)) : ¬ x ∈ ⋃₀ S :=
begin
intro HxU,
have Hex : ∃₀ s ∈ S, x ∈ s, from HxU,
cases Hex with s Hs,
cases Hs with Hs Hxs,
cases exists_not_of_not_forall (v_0 Hs Hxs) with ε Hε,
cases iff.mp not_implies_iff_and_not Hε with Hεp Hv,
cases Hbd _ Hεp with v Hv',
cases Hv' with Hvnm Hdist,
apply Hv,
existsi v,
split,
apply not_mem_of_not_mem_sUnion Hvnm Hs,
exact Hdist
end
/-
this should be doable by showing that the open-ball boundary definition
is equivalent to topology.on_boundary, and applying topology.not_open_of_on_boundary.
But the induction hypotheses don't work out nicely.
-/
theorem not_open_of_ex_boundary_pt {U : set V} {x : V} (HxU : x ∈ U)
(Hbd : ∀ ε : ℝ, ε > 0 → ∃ v : V, v ∉ U ∧ dist x v < ε) : ¬ Open U :=
begin
intro HUopen,
induction HUopen,
{apply not_mem_open_basis_of_boundary_pt a Hbd HxU},
{cases Hbd 1 zero_lt_one with v Hv,
cases Hv with Hv _,
exact Hv !mem_univ},
{apply not_mem_intersect_of_boundary_pt a a_1 v_0 v_1 Hbd HxU},
{apply not_mem_sUnion_of_boundary_pt a v_0 Hbd HxU}
end
theorem ex_Open_ball_subset_of_Open_of_nonempty {U : set V} (HU : Open U) {x : V} (Hx : x ∈ U) :
∃ (r : ℝ), r > 0 ∧ open_ball x r ⊆ U :=
begin
let balloon := {r ∈ univ | r > 0 ∧ open_ball x r ⊆ U},
cases em (balloon = ∅),
have H : ∀ r : ℝ, r > 0 → ∃ v : V, v ∉ U ∧ dist x v < r, begin
intro r Hr,
note Hor := iff.mp not_and_iff_not_or_not (forall_not_of_sep_empty a (mem_univ r)),
note Hor' := or.neg_resolve_left Hor Hr,
apply exists_of_not_forall_not,
intro Hall,
apply Hor',
intro y Hy,
cases iff.mp not_and_iff_not_or_not (Hall y) with Hmem Hge,
apply not_not_elim Hmem,
apply absurd (and.right Hy) Hge
end,
apply absurd HU,
apply not_open_of_ex_boundary_pt Hx H,
cases exists_mem_of_ne_empty a with r Hr,
cases Hr with _ Hr,
cases Hr with Hrpos HxrU,
existsi r,
split,
repeat assumption
end
end topology
section continuity
variables {M N : Type} [Hm : metric_space M] [Hn : metric_space N]
include Hm Hn
open topology set
/- continuity at a point -/
-- the ε - δ definition of continuity is equivalent to the topological definition
theorem continuous_at_intro {f : M → N} {x : M}
(H : ∀ ⦃ε⦄, ε > 0 → ∃ δ, δ > 0 ∧ ∀ ⦃x'⦄, dist x' x < δ → dist (f x') (f x) < ε) :
continuous_at f x :=
begin
rewrite ↑continuous_at,
intros U HfU Uopen,
cases ex_Open_ball_subset_of_Open_of_nonempty Uopen HfU with r Hr,
cases Hr with Hr HUr,
cases H Hr with δ Hδ,
cases Hδ with Hδ Hx'δ,
existsi open_ball x δ,
split,
apply mem_open_ball,
exact Hδ,
split,
apply open_ball_open,
intro y Hy,
apply HUr,
cases Hy with y' Hy',
cases Hy' with Hy' Hfy',
cases Hy' with _ Hy',
rewrite dist_comm at Hy',
note Hy'' := Hx'δ Hy',
apply and.intro !mem_univ,
rewrite [-Hfy', dist_comm],
exact Hy''
end
theorem continuous_at_elim {f : M → N} {x : M} (Hfx : continuous_at f x) :
∀ ⦃ε⦄, ε > 0 → ∃ δ, δ > 0 ∧ ∀ ⦃x'⦄, dist x' x < δ → dist (f x') (f x) < ε :=
begin
intros ε Hε,
rewrite [↑continuous_at at Hfx],
cases Hfx (open_ball (f x) ε) (mem_open_ball _ Hε) !open_ball_open with V HV,
cases HV with HVx HV,
cases HV with HV HVf,
cases ex_Open_ball_subset_of_Open_of_nonempty HV HVx with δ Hδ,
cases Hδ with Hδ Hδx,
existsi δ,
split,
exact Hδ,
intro x' Hx',
rewrite dist_comm,
apply and.right,
apply HVf,
existsi x',
split,
apply Hδx,
apply and.intro !mem_univ,
rewrite dist_comm,
apply Hx',
apply rfl
end
theorem continuous_at_of_converges_to_at {f : M → N} {x : M} (Hf : f ⟶ f x at x) :
continuous_at f x :=
continuous_at_intro
(take ε, suppose ε > 0,
obtain δ Hδ, from Hf this,
exists.intro δ (and.intro
(and.left Hδ)
(take x', suppose dist x' x < δ,
if Heq : x' = x then
by rewrite [-Heq, dist_self]; assumption
else
(suffices dist x' x < δ, from and.right Hδ x' (and.intro Heq this),
this))))
theorem converges_to_at_of_continuous_at {f : M → N} {x : M} (Hf : continuous_at f x) :
f ⟶ f x at x :=
take ε, suppose ε > 0,
obtain δ Hδ, from continuous_at_elim Hf this,
exists.intro δ (and.intro
(and.left Hδ)
(take x',
assume H : x' ≠ x ∧ dist x' x < δ,
show dist (f x') (f x) < ε, from and.right Hδ x' (and.right H)))
definition continuous (f : M → N) : Prop := ∀ x, continuous_at f x
theorem converges_seq_comp_of_converges_seq_of_cts [instance] (X : ℕ → M) [HX : converges_seq X] {f : M → N}
(Hf : continuous f) :
converges_seq (λ n, f (X n)) :=
begin
cases HX with xlim Hxlim,
existsi f xlim,
rewrite ↑converges_to_seq at *,
intros ε Hε,
let Hcont := (continuous_at_elim (Hf xlim)) Hε,
cases Hcont with δ Hδ,
cases Hxlim (and.left Hδ) with B HB,
existsi B,
intro n Hn,
apply and.right Hδ,
apply HB Hn
end
omit Hn
theorem id_continuous : continuous (λ x : M, x) :=
begin
intros x,
apply continuous_at_intro,
intro ε Hε,
existsi ε,
split,
assumption,
intros,
assumption
end
end continuity
end analysis
/- complete metric spaces -/
structure complete_metric_space [class] (M : Type) extends metricM : metric_space M : Type :=
(complete : ∀ X, @analysis.cauchy M metricM X → @analysis.converges_seq M metricM X)
namespace analysis
proposition complete (M : Type) [cmM : complete_metric_space M] {X : ℕ → M} (H : cauchy X) :
converges_seq X :=
complete_metric_space.complete X H
end analysis
/- the reals form a metric space -/
noncomputable definition metric_space_real [instance] : metric_space ℝ :=
⦃ metric_space,
dist := λ x y, abs (x - y),
dist_self := λ x, abstract by rewrite [sub_self, abs_zero] end,
eq_of_dist_eq_zero := λ x y, eq_of_abs_sub_eq_zero,
dist_comm := abs_sub,
dist_triangle := abs_sub_le
⦄
|
b246a5267bc739165889c3cd96b04626a8dfe720 | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/category_theory/monoidal/opposite.lean | ff8730fff478e63b7c22e9d6631cfec697711365 | [
"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 | 5,328 | 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 category_theory.monoidal.coherence
/-!
# Monoidal opposites
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
We write `Cᵐᵒᵖ` for the monoidal opposite of a monoidal category `C`.
-/
universes v₁ v₂ u₁ u₂
variables {C : Type u₁}
namespace category_theory
open category_theory.monoidal_category
/-- A type synonym for the monoidal opposite. Use the notation `Cᴹᵒᵖ`. -/
@[nolint has_nonempty_instance]
def monoidal_opposite (C : Type u₁) := C
namespace monoidal_opposite
notation C `ᴹᵒᵖ`:std.prec.max_plus := monoidal_opposite C
/-- Think of an object of `C` as an object of `Cᴹᵒᵖ`. -/
@[pp_nodot]
def mop (X : C) : Cᴹᵒᵖ := X
/-- Think of an object of `Cᴹᵒᵖ` as an object of `C`. -/
@[pp_nodot]
def unmop (X : Cᴹᵒᵖ) : C := X
lemma op_injective : function.injective (mop : C → Cᴹᵒᵖ) := λ _ _, id
lemma unop_injective : function.injective (unmop : Cᴹᵒᵖ → C) := λ _ _, id
@[simp] lemma op_inj_iff (x y : C) : mop x = mop y ↔ x = y := iff.rfl
@[simp] lemma unop_inj_iff (x y : Cᴹᵒᵖ) : unmop x = unmop y ↔ x = y := iff.rfl
attribute [irreducible] monoidal_opposite
@[simp] lemma mop_unmop (X : Cᴹᵒᵖ) : mop (unmop X) = X := rfl
@[simp] lemma unmop_mop (X : C) : unmop (mop X) = X := rfl
instance monoidal_opposite_category [I : category.{v₁} C] : category Cᴹᵒᵖ :=
{ hom := λ X Y, unmop X ⟶ unmop Y,
id := λ X, 𝟙 (unmop X),
comp := λ X Y Z f g, f ≫ g, }
end monoidal_opposite
end category_theory
open category_theory
open category_theory.monoidal_opposite
variables [category.{v₁} C]
/-- The monoidal opposite of a morphism `f : X ⟶ Y` is just `f`, thought of as `mop X ⟶ mop Y`. -/
def quiver.hom.mop {X Y : C} (f : X ⟶ Y) : @quiver.hom Cᴹᵒᵖ _ (mop X) (mop Y) := f
/-- We can think of a morphism `f : mop X ⟶ mop Y` as a morphism `X ⟶ Y`. -/
def quiver.hom.unmop {X Y : Cᴹᵒᵖ} (f : X ⟶ Y) : unmop X ⟶ unmop Y := f
namespace category_theory
lemma mop_inj {X Y : C} :
function.injective (quiver.hom.mop : (X ⟶ Y) → (mop X ⟶ mop Y)) :=
λ _ _ H, congr_arg quiver.hom.unmop H
lemma unmop_inj {X Y : Cᴹᵒᵖ} :
function.injective (quiver.hom.unmop : (X ⟶ Y) → (unmop X ⟶ unmop Y)) :=
λ _ _ H, congr_arg quiver.hom.mop H
@[simp] lemma unmop_mop {X Y : C} {f : X ⟶ Y} : f.mop.unmop = f := rfl
@[simp] lemma mop_unmop {X Y : Cᴹᵒᵖ} {f : X ⟶ Y} : f.unmop.mop = f := rfl
@[simp] lemma mop_comp {X Y Z : C} {f : X ⟶ Y} {g : Y ⟶ Z} :
(f ≫ g).mop = f.mop ≫ g.mop := rfl
@[simp] lemma mop_id {X : C} : (𝟙 X).mop = 𝟙 (mop X) := rfl
@[simp] lemma unmop_comp {X Y Z : Cᴹᵒᵖ} {f : X ⟶ Y} {g : Y ⟶ Z} :
(f ≫ g).unmop = f.unmop ≫ g.unmop := rfl
@[simp] lemma unmop_id {X : Cᴹᵒᵖ} : (𝟙 X).unmop = 𝟙 (unmop X) := rfl
@[simp] lemma unmop_id_mop {X : C} : (𝟙 (mop X)).unmop = 𝟙 X := rfl
@[simp] lemma mop_id_unmop {X : Cᴹᵒᵖ} : (𝟙 (unmop X)).mop = 𝟙 X := rfl
namespace iso
variables {X Y : C}
/-- An isomorphism in `C` gives an isomorphism in `Cᴹᵒᵖ`. -/
@[simps]
def mop (f : X ≅ Y) : mop X ≅ mop Y :=
{ hom := f.hom.mop,
inv := f.inv.mop,
hom_inv_id' := unmop_inj f.hom_inv_id,
inv_hom_id' := unmop_inj f.inv_hom_id }
end iso
variables [monoidal_category.{v₁} C]
open opposite monoidal_category
instance monoidal_category_op : monoidal_category Cᵒᵖ :=
{ tensor_obj := λ X Y, op (unop X ⊗ unop Y),
tensor_hom := λ X₁ Y₁ X₂ Y₂ f g, (f.unop ⊗ g.unop).op,
tensor_unit := op (𝟙_ C),
associator := λ X Y Z, (α_ (unop X) (unop Y) (unop Z)).symm.op,
left_unitor := λ X, (λ_ (unop X)).symm.op,
right_unitor := λ X, (ρ_ (unop X)).symm.op,
associator_naturality' := by { intros, apply quiver.hom.unop_inj, simp, },
left_unitor_naturality' := by { intros, apply quiver.hom.unop_inj, simp, },
right_unitor_naturality' := by { intros, apply quiver.hom.unop_inj, simp, },
triangle' := by { intros, apply quiver.hom.unop_inj, coherence, },
pentagon' := by { intros, apply quiver.hom.unop_inj, coherence, }, }
lemma op_tensor_obj (X Y : Cᵒᵖ) : X ⊗ Y = op (unop X ⊗ unop Y) := rfl
lemma op_tensor_unit : (𝟙_ Cᵒᵖ) = op (𝟙_ C) := rfl
instance monoidal_category_mop : monoidal_category Cᴹᵒᵖ :=
{ tensor_obj := λ X Y, mop (unmop Y ⊗ unmop X),
tensor_hom := λ X₁ Y₁ X₂ Y₂ f g, (g.unmop ⊗ f.unmop).mop,
tensor_unit := mop (𝟙_ C),
associator := λ X Y Z, (α_ (unmop Z) (unmop Y) (unmop X)).symm.mop,
left_unitor := λ X, (ρ_ (unmop X)).mop,
right_unitor := λ X, (λ_ (unmop X)).mop,
associator_naturality' := by { intros, apply unmop_inj, simp, },
left_unitor_naturality' := by { intros, apply unmop_inj, simp, },
right_unitor_naturality' := by { intros, apply unmop_inj, simp, },
triangle' := by { intros, apply unmop_inj, coherence, },
pentagon' := by { intros, apply unmop_inj, coherence, }, }
lemma mop_tensor_obj (X Y : Cᴹᵒᵖ) : X ⊗ Y = mop (unmop Y ⊗ unmop X) := rfl
lemma mop_tensor_unit : (𝟙_ Cᴹᵒᵖ) = mop (𝟙_ C) := rfl
end category_theory
|
c15f615ae60379e6efe0392b68d365d0b6613303 | 827124860511172deb7ee955917c49b2bccd1b3c | /data/containers/utils/option.lean | 7faf7531c80e00f68d85ed30072a84bd683506c5 | [] | no_license | joehendrix/lean-containers | afec24c7de19c935774738ff3a0415362894956c | ef6ff0533eada75f18922039f8312badf12e6124 | refs/heads/master | 1,624,853,911,199 | 1,505,890,599,000 | 1,505,890,599,000 | 103,489,962 | 1 | 1 | null | null | null | null | UTF-8 | Lean | false | false | 543 | lean | /- Additional theroems for option. -/
namespace option
theorem failure_is_none (α : Type _) : (failure : option α) = none := rfl
theorem coe_is_some {α : Type _} (x:α) : (coe x : option α) = some x := rfl
theorem or_else_none {α : Type _} (x : option α) : (x <|> none) = x :=
begin
cases x; trivial,
end
theorem none_or_else {α : Type _} (x : option α) : (none <|> x) = x :=
begin
cases x; trivial,
end
theorem some_or_else {α : Type _} (x : α) (y : option α) : (some x <|> y) = some x :=
begin
trivial,
end
end option
|
a89f8753a291d3a71f3711da8daa161809cf2ae0 | bb31430994044506fa42fd667e2d556327e18dfe | /src/data/nat/cast/basic.lean | adee13377c6d0bae31ed1e5255110d816068a21d | [
"Apache-2.0"
] | permissive | sgouezel/mathlib | 0cb4e5335a2ba189fa7af96d83a377f83270e503 | 00638177efd1b2534fc5269363ebf42a7871df9a | refs/heads/master | 1,674,527,483,042 | 1,673,665,568,000 | 1,673,665,568,000 | 119,598,202 | 0 | 0 | null | 1,517,348,647,000 | 1,517,348,646,000 | null | UTF-8 | Lean | false | false | 9,691 | lean | /-
Copyright (c) 2014 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import algebra.char_zero.defs
import algebra.group_with_zero.commute
import algebra.hom.ring
import algebra.order.group.abs
import algebra.ring.commute
import data.nat.order.basic
import algebra.group.opposite
/-!
# Cast of natural numbers (additional theorems)
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
This file proves additional properties about the *canonical* homomorphism from
the natural numbers into an additive monoid with a one (`nat.cast`).
## Main declarations
* `cast_add_monoid_hom`: `cast` bundled as an `add_monoid_hom`.
* `cast_ring_hom`: `cast` bundled as a `ring_hom`.
-/
variables {α β : Type*}
namespace nat
/-- `coe : ℕ → α` as an `add_monoid_hom`. -/
def cast_add_monoid_hom (α : Type*) [add_monoid_with_one α] : ℕ →+ α :=
{ to_fun := coe,
map_add' := cast_add,
map_zero' := cast_zero }
@[simp] lemma coe_cast_add_monoid_hom [add_monoid_with_one α] :
(cast_add_monoid_hom α : ℕ → α) = coe := rfl
@[simp, norm_cast] theorem cast_mul [non_assoc_semiring α] (m n : ℕ) :
((m * n : ℕ) : α) = m * n :=
by induction n; simp [mul_succ, mul_add, *]
/-- `coe : ℕ → α` as a `ring_hom` -/
def cast_ring_hom (α : Type*) [non_assoc_semiring α] : ℕ →+* α :=
{ to_fun := coe,
map_one' := cast_one,
map_mul' := cast_mul,
.. cast_add_monoid_hom α }
@[simp] lemma coe_cast_ring_hom [non_assoc_semiring α] : (cast_ring_hom α : ℕ → α) = coe := rfl
lemma cast_commute [non_assoc_semiring α] (n : ℕ) (x : α) : commute ↑n x :=
nat.rec_on n (by rw [cast_zero]; exact commute.zero_left x) $
λ n ihn, by rw [cast_succ]; exact ihn.add_left (commute.one_left x)
lemma cast_comm [non_assoc_semiring α] (n : ℕ) (x : α) : (n : α) * x = x * n :=
(cast_commute n x).eq
lemma commute_cast [non_assoc_semiring α] (x : α) (n : ℕ) : commute x n :=
(n.cast_commute x).symm
section ordered_semiring
variables [ordered_semiring α]
@[mono] theorem mono_cast : monotone (coe : ℕ → α) :=
monotone_nat_of_le_succ $ λ n, by rw [nat.cast_succ]; exact le_add_of_nonneg_right zero_le_one
@[simp] theorem cast_nonneg (n : ℕ) : 0 ≤ (n : α) :=
@nat.cast_zero α _ ▸ mono_cast (nat.zero_le n)
section nontrivial
variable [nontrivial α]
lemma cast_add_one_pos (n : ℕ) : 0 < (n : α) + 1 :=
zero_lt_one.trans_le $ le_add_of_nonneg_left n.cast_nonneg
@[simp] lemma cast_pos {n : ℕ} : (0 : α) < n ↔ 0 < n := by cases n; simp [cast_add_one_pos]
end nontrivial
variables [char_zero α] {m n : ℕ}
lemma strict_mono_cast : strict_mono (coe : ℕ → α) :=
mono_cast.strict_mono_of_injective cast_injective
/-- `coe : ℕ → α` as an `order_embedding` -/
@[simps { fully_applied := ff }] def cast_order_embedding : ℕ ↪o α :=
order_embedding.of_strict_mono coe nat.strict_mono_cast
@[simp, norm_cast] lemma cast_le : (m : α) ≤ n ↔ m ≤ n := strict_mono_cast.le_iff_le
@[simp, norm_cast, mono] lemma cast_lt : (m : α) < n ↔ m < n := strict_mono_cast.lt_iff_lt
@[simp, norm_cast] lemma one_lt_cast : 1 < (n : α) ↔ 1 < n := by rw [←cast_one, cast_lt]
@[simp, norm_cast] lemma one_le_cast : 1 ≤ (n : α) ↔ 1 ≤ n := by rw [←cast_one, cast_le]
@[simp, norm_cast] lemma cast_lt_one : (n : α) < 1 ↔ n = 0 :=
by rw [←cast_one, cast_lt, lt_succ_iff, ←bot_eq_zero, le_bot_iff]
@[simp, norm_cast] lemma cast_le_one : (n : α) ≤ 1 ↔ n ≤ 1 := by rw [←cast_one, cast_le]
end ordered_semiring
/-- A version of `nat.cast_sub` that works for `ℝ≥0` and `ℚ≥0`. Note that this proof doesn't work
for `ℕ∞` and `ℝ≥0∞`, so we use type-specific lemmas for these types. -/
@[simp, norm_cast] lemma cast_tsub [canonically_ordered_comm_semiring α] [has_sub α]
[has_ordered_sub α] [contravariant_class α α (+) (≤)] (m n : ℕ) :
↑(m - n) = (m - n : α) :=
begin
cases le_total m n with h h,
{ rw [tsub_eq_zero_of_le h, cast_zero, tsub_eq_zero_of_le],
exact mono_cast h },
{ rcases le_iff_exists_add'.mp h with ⟨m, rfl⟩,
rw [add_tsub_cancel_right, cast_add, add_tsub_cancel_right] }
end
@[simp, norm_cast] theorem cast_min [linear_ordered_semiring α] {a b : ℕ} :
(↑(min a b) : α) = min a b :=
(@mono_cast α _).map_min
@[simp, norm_cast] theorem cast_max [linear_ordered_semiring α] {a b : ℕ} :
(↑(max a b) : α) = max a b :=
(@mono_cast α _).map_max
@[simp, norm_cast] theorem abs_cast [linear_ordered_ring α] (a : ℕ) :
|(a : α)| = a :=
abs_of_nonneg (cast_nonneg a)
lemma coe_nat_dvd [semiring α] {m n : ℕ} (h : m ∣ n) : (m : α) ∣ (n : α) :=
map_dvd (nat.cast_ring_hom α) h
alias coe_nat_dvd ← _root_.has_dvd.dvd.nat_cast
end nat
section add_monoid_hom_class
variables {A B F : Type*} [add_monoid_with_one B]
lemma ext_nat' [add_monoid A] [add_monoid_hom_class F ℕ A] (f g : F) (h : f 1 = g 1) : f = g :=
fun_like.ext f g $ begin
apply nat.rec,
{ simp only [nat.nat_zero_eq_zero, map_zero] },
simp [nat.succ_eq_add_one, h] {contextual := tt}
end
@[ext] lemma add_monoid_hom.ext_nat [add_monoid A] : ∀ {f g : ℕ →+ A}, ∀ h : f 1 = g 1, f = g :=
ext_nat'
variable [add_monoid_with_one A]
-- these versions are primed so that the `ring_hom_class` versions aren't
lemma eq_nat_cast' [add_monoid_hom_class F ℕ A] (f : F) (h1 : f 1 = 1) :
∀ n : ℕ, f n = n
| 0 := by simp
| (n+1) := by rw [map_add, h1, eq_nat_cast' n, nat.cast_add_one]
lemma map_nat_cast' {A} [add_monoid_with_one A] [add_monoid_hom_class F A B]
(f : F) (h : f 1 = 1) : ∀ (n : ℕ), f n = n
| 0 := by simp
| (n+1) := by rw [nat.cast_add, map_add, nat.cast_add, map_nat_cast', nat.cast_one, h, nat.cast_one]
end add_monoid_hom_class
section monoid_with_zero_hom_class
variables {A F : Type*} [mul_zero_one_class A]
/-- If two `monoid_with_zero_hom`s agree on the positive naturals they are equal. -/
theorem ext_nat'' [monoid_with_zero_hom_class F ℕ A] (f g : F)
(h_pos : ∀ {n : ℕ}, 0 < n → f n = g n) : f = g :=
begin
apply fun_like.ext,
rintro (_|n),
{ simp },
exact h_pos n.succ_pos
end
@[ext] theorem monoid_with_zero_hom.ext_nat :
∀ {f g : ℕ →*₀ A}, (∀ {n : ℕ}, 0 < n → f n = g n) → f = g := ext_nat''
end monoid_with_zero_hom_class
section ring_hom_class
variables {R S F : Type*} [non_assoc_semiring R] [non_assoc_semiring S]
@[simp] lemma eq_nat_cast [ring_hom_class F ℕ R] (f : F) : ∀ n, f n = n :=
eq_nat_cast' f $ map_one f
@[simp] lemma map_nat_cast [ring_hom_class F R S] (f : F) : ∀ n : ℕ, f (n : R) = n :=
map_nat_cast' f $ map_one f
lemma ext_nat [ring_hom_class F ℕ R] (f g : F) : f = g :=
ext_nat' f g $ by simp only [map_one]
lemma ne_zero.nat_of_injective {n : ℕ} [h : ne_zero (n : R)]
[ring_hom_class F R S] {f : F} (hf : function.injective f) : ne_zero (n : S) :=
⟨λ h, (ne_zero.nat_cast_ne n R) $ hf $ by simpa only [map_nat_cast, map_zero]⟩
lemma ne_zero.nat_of_ne_zero {R S} [semiring R] [semiring S] {F} [ring_hom_class F R S] (f : F)
{n : ℕ} [hn : ne_zero (n : S)] : ne_zero (n : R) :=
by { apply ne_zero.of_map f, simp only [map_nat_cast, hn] }
end ring_hom_class
namespace ring_hom
/-- This is primed to match `eq_int_cast'`. -/
lemma eq_nat_cast' {R} [non_assoc_semiring R] (f : ℕ →+* R) : f = nat.cast_ring_hom R :=
ring_hom.ext $ eq_nat_cast f
end ring_hom
@[simp, norm_cast] theorem nat.cast_id (n : ℕ) : ↑n = n :=
rfl
@[simp] lemma nat.cast_ring_hom_nat : nat.cast_ring_hom ℕ = ring_hom.id ℕ := rfl
-- I don't think `ring_hom_class` is good here, because of the `subsingleton` TC slowness
instance nat.unique_ring_hom {R : Type*} [non_assoc_semiring R] : unique (ℕ →+* R) :=
{ default := nat.cast_ring_hom R, uniq := ring_hom.eq_nat_cast' }
namespace mul_opposite
variables [add_monoid_with_one α]
@[simp, norm_cast] lemma op_nat_cast (n : ℕ) : op (n : α) = n := rfl
@[simp, norm_cast] lemma unop_nat_cast (n : ℕ) : unop (n : αᵐᵒᵖ) = n := rfl
end mul_opposite
namespace pi
variables {π : α → Type*} [Π a, has_nat_cast (π a)]
instance : has_nat_cast (Π a, π a) :=
by refine_struct { .. }; tactic.pi_instance_derive_field
lemma nat_apply (n : ℕ) (a : α) : (n : Π a, π a) a = n := rfl
@[simp] lemma coe_nat (n : ℕ) : (n : Π a, π a) = λ _, n := rfl
end pi
lemma sum.elim_nat_cast_nat_cast {α β γ : Type*} [has_nat_cast γ] (n : ℕ) :
sum.elim (n : α → γ) (n : β → γ) = n :=
@sum.elim_lam_const_lam_const α β γ n
namespace pi
variables {π : α → Type*} [Π a, add_monoid_with_one (π a)]
instance : add_monoid_with_one (Π a, π a) :=
by refine_struct { .. }; tactic.pi_instance_derive_field
end pi
/-! ### Order dual -/
open order_dual
instance [h : has_nat_cast α] : has_nat_cast αᵒᵈ := h
instance [h : add_monoid_with_one α] : add_monoid_with_one αᵒᵈ := h
instance [h : add_comm_monoid_with_one α] : add_comm_monoid_with_one αᵒᵈ := h
@[simp] lemma to_dual_nat_cast [has_nat_cast α] (n : ℕ) : to_dual (n : α) = n := rfl
@[simp] lemma of_dual_nat_cast [has_nat_cast α] (n : ℕ) : (of_dual n : α) = n := rfl
/-! ### Lexicographic order -/
instance [h : has_nat_cast α] : has_nat_cast (lex α) := h
instance [h : add_monoid_with_one α] : add_monoid_with_one (lex α) := h
instance [h : add_comm_monoid_with_one α] : add_comm_monoid_with_one (lex α) := h
@[simp] lemma to_lex_nat_cast [has_nat_cast α] (n : ℕ) : to_lex (n : α) = n := rfl
@[simp] lemma of_lex_nat_cast [has_nat_cast α] (n : ℕ) : (of_lex n : α) = n := rfl
|
89f6b7bbb8cabf9cba1bd19d430a80298f105286 | 80cc5bf14c8ea85ff340d1d747a127dcadeb966f | /src/data/multiset/fold.lean | bf1ca0366fe5d2cbf62bb0c398e60e4f61afbfdd | [
"Apache-2.0"
] | permissive | lacker/mathlib | f2439c743c4f8eb413ec589430c82d0f73b2d539 | ddf7563ac69d42cfa4a1bfe41db1fed521bd795f | refs/heads/master | 1,671,948,326,773 | 1,601,479,268,000 | 1,601,479,268,000 | 298,686,743 | 0 | 0 | Apache-2.0 | 1,601,070,794,000 | 1,601,070,794,000 | null | UTF-8 | Lean | false | false | 3,767 | lean | /-
Copyright (c) 2017 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Mario Carneiro
-/
import data.multiset.erase_dup
/-!
# The fold operation for a commutative associative operation over a multiset.
-/
namespace multiset
variables {α β : Type*}
/-! ### fold -/
section fold
variables (op : α → α → α) [hc : is_commutative α op] [ha : is_associative α op]
local notation a * b := op a b
include hc ha
/-- `fold op b s` folds a commutative associative operation `op` over
the multiset `s`. -/
def fold : α → multiset α → α := foldr op (left_comm _ hc.comm ha.assoc)
theorem fold_eq_foldr (b : α) (s : multiset α) : fold op b s = foldr op (left_comm _ hc.comm ha.assoc) b s := rfl
@[simp] theorem coe_fold_r (b : α) (l : list α) : fold op b l = l.foldr op b := rfl
theorem coe_fold_l (b : α) (l : list α) : fold op b l = l.foldl op b :=
(coe_foldr_swap op _ b l).trans $ by simp [hc.comm]
theorem fold_eq_foldl (b : α) (s : multiset α) : fold op b s = foldl op (right_comm _ hc.comm ha.assoc) b s :=
quot.induction_on s $ λ l, coe_fold_l _ _ _
@[simp] theorem fold_zero (b : α) : (0 : multiset α).fold op b = b := rfl
@[simp] theorem fold_cons_left : ∀ (b a : α) (s : multiset α),
(a :: s).fold op b = a * s.fold op b := foldr_cons _ _
theorem fold_cons_right (b a : α) (s : multiset α) : (a :: s).fold op b = s.fold op b * a :=
by simp [hc.comm]
theorem fold_cons'_right (b a : α) (s : multiset α) : (a :: s).fold op b = s.fold op (b * a) :=
by rw [fold_eq_foldl, foldl_cons, ← fold_eq_foldl]
theorem fold_cons'_left (b a : α) (s : multiset α) : (a :: s).fold op b = s.fold op (a * b) :=
by rw [fold_cons'_right, hc.comm]
theorem fold_add (b₁ b₂ : α) (s₁ s₂ : multiset α) : (s₁ + s₂).fold op (b₁ * b₂) = s₁.fold op b₁ * s₂.fold op b₂ :=
multiset.induction_on s₂
(by rw [add_zero, fold_zero, ← fold_cons'_right, ← fold_cons_right op])
(by simp {contextual := tt}; cc)
theorem fold_singleton (b a : α) : (a::0 : multiset α).fold op b = a * b := by simp
theorem fold_distrib {f g : β → α} (u₁ u₂ : α) (s : multiset β) :
(s.map (λx, f x * g x)).fold op (u₁ * u₂) = (s.map f).fold op u₁ * (s.map g).fold op u₂ :=
multiset.induction_on s (by simp) (by simp {contextual := tt}; cc)
theorem fold_hom {op' : β → β → β} [is_commutative β op'] [is_associative β op']
{m : α → β} (hm : ∀x y, m (op x y) = op' (m x) (m y)) (b : α) (s : multiset α) :
(s.map m).fold op' (m b) = m (s.fold op b) :=
multiset.induction_on s (by simp) (by simp [hm] {contextual := tt})
theorem fold_union_inter [decidable_eq α] (s₁ s₂ : multiset α) (b₁ b₂ : α) :
(s₁ ∪ s₂).fold op b₁ * (s₁ ∩ s₂).fold op b₂ = s₁.fold op b₁ * s₂.fold op b₂ :=
by rw [← fold_add op, union_add_inter, fold_add op]
@[simp] theorem fold_erase_dup_idem [decidable_eq α] [hi : is_idempotent α op] (s : multiset α) (b : α) :
(erase_dup s).fold op b = s.fold op b :=
multiset.induction_on s (by simp) $ λ a s IH, begin
by_cases a ∈ s; simp [IH, h],
show fold op b s = op a (fold op b s),
rw [← cons_erase h, fold_cons_left, ← ha.assoc, hi.idempotent],
end
end fold
open nat
theorem le_smul_erase_dup [decidable_eq α] (s : multiset α) :
∃ n : ℕ, s ≤ n •ℕ erase_dup s :=
⟨(s.map (λ a, count a s)).fold max 0, le_iff_count.2 $ λ a, begin
rw count_smul, by_cases a ∈ s,
{ refine le_trans _ (mul_le_mul_left _ $ count_pos.2 $ mem_erase_dup.2 h),
have : count a s ≤ fold max 0 (map (λ a, count a s) (a :: erase s a));
[simp [le_max_left], simpa [cons_erase h]] },
{ simp [count_eq_zero.2 h, nat.zero_le] }
end⟩
end multiset
|
0976fccd26722a146dea61eee2b0fdb8fe85a52a | bbecf0f1968d1fba4124103e4f6b55251d08e9c4 | /src/ring_theory/integral_closure.lean | 2ae462db1a8f936a4efc5e25bb3da98b570b7f2a | [
"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 | 33,093 | lean | /-
Copyright (c) 2019 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau
-/
import ring_theory.adjoin.fg
import ring_theory.polynomial.scale_roots
import ring_theory.polynomial.tower
/-!
# Integral closure of a subring.
If A is an R-algebra then `a : A` is integral over R if it is a root of a monic polynomial
with coefficients in R. Enough theory is developed to prove that integral elements
form a sub-R-algebra of A.
## Main definitions
Let `R` be a `comm_ring` and let `A` be an R-algebra.
* `ring_hom.is_integral_elem (f : R →+* A) (x : A)` : `x` is integral with respect to the map `f`,
* `is_integral (x : A)` : `x` is integral over `R`, i.e., is a root of a monic polynomial with
coefficients in `R`.
* `integral_closure R A` : the integral closure of `R` in `A`, regarded as a sub-`R`-algebra of `A`.
-/
open_locale classical
open_locale big_operators
open polynomial submodule
section ring
variables {R S A : Type*}
variables [comm_ring R] [ring A] [ring S] (f : R →+* S)
/-- An element `x` of `A` is said to be integral over `R` with respect to `f`
if it is a root of a monic polynomial `p : polynomial R` evaluated under `f` -/
def ring_hom.is_integral_elem (f : R →+* A) (x : A) :=
∃ p : polynomial R, monic p ∧ eval₂ f x p = 0
/-- A ring homomorphism `f : R →+* A` is said to be integral
if every element `A` is integral with respect to the map `f` -/
def ring_hom.is_integral (f : R →+* A) :=
∀ x : A, f.is_integral_elem x
variables [algebra R A] (R)
/-- An element `x` of an algebra `A` over a commutative ring `R` is said to be *integral*,
if it is a root of some monic polynomial `p : polynomial R`.
Equivalently, the element is integral over `R` with respect to the induced `algebra_map` -/
def is_integral (x : A) : Prop :=
(algebra_map R A).is_integral_elem x
variable (A)
/-- An algebra is integral if every element of the extension is integral over the base ring -/
def algebra.is_integral : Prop :=
(algebra_map R A).is_integral
variables {R A}
lemma ring_hom.is_integral_map {x : R} : f.is_integral_elem (f x) :=
⟨X - C x, monic_X_sub_C _, by simp⟩
theorem is_integral_algebra_map {x : R} : is_integral R (algebra_map R A x) :=
(algebra_map R A).is_integral_map
theorem is_integral_of_noetherian (H : is_noetherian R A) (x : A) :
is_integral R x :=
begin
let leval : (polynomial R →ₗ[R] A) := (aeval x).to_linear_map,
let D : ℕ → submodule R A := λ n, (degree_le R n).map leval,
let M := well_founded.min (is_noetherian_iff_well_founded.1 H)
(set.range D) ⟨_, ⟨0, rfl⟩⟩,
have HM : M ∈ set.range D := well_founded.min_mem _ _ _,
cases HM with N HN,
have HM : ¬M < D (N+1) := well_founded.not_lt_min
(is_noetherian_iff_well_founded.1 H) (set.range D) _ ⟨N+1, rfl⟩,
rw ← HN at HM,
have HN2 : D (N+1) ≤ D N := classical.by_contradiction (λ H, HM
(lt_of_le_not_le (map_mono (degree_le_mono
(with_bot.coe_le_coe.2 (nat.le_succ N)))) H)),
have HN3 : leval (X^(N+1)) ∈ D N,
{ exact HN2 (mem_map_of_mem (mem_degree_le.2 (degree_X_pow_le _))) },
rcases HN3 with ⟨p, hdp, hpe⟩,
refine ⟨X^(N+1) - p, monic_X_pow_sub (mem_degree_le.1 hdp), _⟩,
show leval (X ^ (N + 1) - p) = 0,
rw [linear_map.map_sub, hpe, sub_self]
end
theorem is_integral_of_submodule_noetherian (S : subalgebra R A)
(H : is_noetherian R S.to_submodule) (x : A) (hx : x ∈ S) :
is_integral R x :=
begin
suffices : is_integral R (show S, from ⟨x, hx⟩),
{ rcases this with ⟨p, hpm, hpx⟩,
replace hpx := congr_arg S.val hpx,
refine ⟨p, hpm, eq.trans _ hpx⟩,
simp only [aeval_def, eval₂, sum_def],
rw S.val.map_sum,
refine finset.sum_congr rfl (λ n hn, _),
rw [S.val.map_mul, S.val.map_pow, S.val.commutes, S.val_apply, subtype.coe_mk], },
refine is_integral_of_noetherian H ⟨x, hx⟩
end
end ring
section
variables {R A B S : Type*}
variables [comm_ring R] [comm_ring A] [comm_ring B] [comm_ring S]
variables [algebra R A] [algebra R B] (f : R →+* S)
theorem is_integral_alg_hom (f : A →ₐ[R] B) {x : A} (hx : is_integral R x) : is_integral R (f x) :=
let ⟨p, hp, hpx⟩ :=
hx in ⟨p, hp, by rw [← aeval_def, aeval_alg_hom_apply, aeval_def, hpx, f.map_zero]⟩
@[simp]
theorem is_integral_alg_equiv (f : A ≃ₐ[R] B) {x : A} : is_integral R (f x) ↔ is_integral R x :=
⟨λ h, by simpa using is_integral_alg_hom f.symm.to_alg_hom h, is_integral_alg_hom f.to_alg_hom⟩
theorem is_integral_of_is_scalar_tower [algebra A B] [is_scalar_tower R A B]
(x : B) (hx : is_integral R x) : is_integral A x :=
let ⟨p, hp, hpx⟩ := hx in
⟨p.map $ algebra_map R A, monic_map _ hp,
by rw [← aeval_def, ← is_scalar_tower.aeval_apply, aeval_def, hpx]⟩
theorem is_integral_of_subring {x : A} (T : subring R)
(hx : is_integral T x) : is_integral R x :=
is_integral_of_is_scalar_tower x hx
lemma is_integral.algebra_map [algebra A B] [is_scalar_tower R A B]
{x : A} (h : is_integral R x) :
is_integral R (algebra_map A B x) :=
begin
rcases h with ⟨f, hf, hx⟩,
use [f, hf],
rw [is_scalar_tower.algebra_map_eq R A B, ← hom_eval₂, hx, ring_hom.map_zero]
end
lemma is_integral_algebra_map_iff [algebra A B] [is_scalar_tower R A B]
{x : A} (hAB : function.injective (algebra_map A B)) :
is_integral R (algebra_map A B x) ↔ is_integral R x :=
begin
refine ⟨_, λ h, h.algebra_map⟩,
rintros ⟨f, hf, hx⟩,
use [f, hf],
exact is_scalar_tower.aeval_eq_zero_of_aeval_algebra_map_eq_zero R A B hAB hx,
end
theorem is_integral_iff_is_integral_closure_finite {r : A} :
is_integral R r ↔ ∃ s : set R, s.finite ∧ is_integral (subring.closure s) r :=
begin
split; intro hr,
{ rcases hr with ⟨p, hmp, hpr⟩,
refine ⟨_, set.finite_mem_finset _, p.restriction, monic_restriction.2 hmp, _⟩,
erw [← aeval_def, is_scalar_tower.aeval_apply _ R, map_restriction, aeval_def, hpr] },
rcases hr with ⟨s, hs, hsr⟩,
exact is_integral_of_subring _ hsr
end
theorem fg_adjoin_singleton_of_integral (x : A) (hx : is_integral R x) :
(algebra.adjoin R ({x} : set A)).to_submodule.fg :=
begin
rcases hx with ⟨f, hfm, hfx⟩,
existsi finset.image ((^) x) (finset.range (nat_degree f + 1)),
apply le_antisymm,
{ rw span_le, intros s hs, rw finset.mem_coe at hs,
rcases finset.mem_image.1 hs with ⟨k, hk, rfl⟩, clear hk,
exact (algebra.adjoin R {x}).pow_mem (algebra.subset_adjoin (set.mem_singleton _)) k },
intros r hr, change r ∈ algebra.adjoin R ({x} : set A) at hr,
rw algebra.adjoin_singleton_eq_range_aeval at hr,
rcases (aeval x).mem_range.mp hr with ⟨p, rfl⟩,
rw ← mod_by_monic_add_div p hfm,
rw ← aeval_def at hfx,
rw [alg_hom.map_add, alg_hom.map_mul, hfx, zero_mul, add_zero],
have : degree (p %ₘ f) ≤ degree f := degree_mod_by_monic_le p hfm,
generalize_hyp : p %ₘ f = q at this ⊢,
rw [← sum_C_mul_X_eq q, aeval_def, eval₂_sum, sum_def],
refine sum_mem _ (λ k hkq, _),
rw [eval₂_mul, eval₂_C, eval₂_pow, eval₂_X, ← algebra.smul_def],
refine smul_mem _ _ (subset_span _),
rw finset.mem_coe, refine finset.mem_image.2 ⟨_, _, rfl⟩,
rw [finset.mem_range, nat.lt_succ_iff], refine le_of_not_lt (λ hk, _),
rw [degree_le_iff_coeff_zero] at this,
rw [mem_support_iff] at hkq, apply hkq, apply this,
exact lt_of_le_of_lt degree_le_nat_degree (with_bot.coe_lt_coe.2 hk)
end
theorem fg_adjoin_of_finite {s : set A} (hfs : s.finite)
(his : ∀ x ∈ s, is_integral R x) : (algebra.adjoin R s).to_submodule.fg :=
set.finite.induction_on hfs (λ _, ⟨{1}, submodule.ext $ λ x,
by { erw [algebra.adjoin_empty, finset.coe_singleton, ← one_eq_span, one_eq_range,
linear_map.mem_range, algebra.mem_bot], refl }⟩)
(λ a s has hs ih his, by rw [← set.union_singleton, algebra.adjoin_union_coe_submodule]; exact
fg_mul _ _ (ih $ λ i hi, his i $ set.mem_insert_of_mem a hi)
(fg_adjoin_singleton_of_integral _ $ his a $ set.mem_insert a s)) his
lemma is_noetherian_adjoin_finset [is_noetherian_ring R] (s : finset A)
(hs : ∀ x ∈ s, is_integral R x) :
is_noetherian R (algebra.adjoin R (↑s : set A)) :=
is_noetherian_of_fg_of_noetherian _ (fg_adjoin_of_finite s.finite_to_set hs)
/-- If `S` is a sub-`R`-algebra of `A` and `S` is finitely-generated as an `R`-module,
then all elements of `S` are integral over `R`. -/
theorem is_integral_of_mem_of_fg (S : subalgebra R A)
(HS : S.to_submodule.fg) (x : A) (hx : x ∈ S) : is_integral R x :=
begin
-- say `x ∈ S`. We want to prove that `x` is integral over `R`.
-- Say `S` is generated as an `R`-module by the set `y`.
cases HS with y hy,
-- We can write `x` as `∑ rᵢ yᵢ` for `yᵢ ∈ Y`.
obtain ⟨lx, hlx1, hlx2⟩ :
∃ (l : A →₀ R) (H : l ∈ finsupp.supported R R ↑y), (finsupp.total A A R id) l = x,
{ rwa [←(@finsupp.mem_span_image_iff_total A A R _ _ _ id ↑y x), set.image_id ↑y, hy] },
-- Note that `y ⊆ S`.
have hyS : ∀ {p}, p ∈ y → p ∈ S := λ p hp, show p ∈ S.to_submodule,
by { rw ← hy, exact subset_span hp },
-- Now `S` is a subalgebra so the product of two elements of `y` is also in `S`.
have : ∀ (jk : (↑(y.product y) : set (A × A))), jk.1.1 * jk.1.2 ∈ S.to_submodule :=
λ jk, S.mul_mem (hyS (finset.mem_product.1 jk.2).1) (hyS (finset.mem_product.1 jk.2).2),
rw [← hy, ← set.image_id ↑y] at this, simp only [finsupp.mem_span_image_iff_total] at this,
-- Say `yᵢyⱼ = ∑rᵢⱼₖ yₖ`
choose ly hly1 hly2,
-- Now let `S₀` be the subring of `R` generated by the `rᵢ` and the `rᵢⱼₖ`.
let S₀ : subring R :=
subring.closure ↑(lx.frange ∪ finset.bUnion finset.univ (finsupp.frange ∘ ly)),
-- It suffices to prove that `x` is integral over `S₀`.
refine is_integral_of_subring S₀ _,
letI : comm_ring S₀ := subring.to_comm_ring S₀,
letI : algebra S₀ A := algebra.of_subring S₀,
-- Claim: the `S₀`-module span (in `A`) of the set `y ∪ {1}` is closed under
-- multiplication (indeed, this is the motivation for the definition of `S₀`).
have :
span S₀ (insert 1 ↑y : set A) * span S₀ (insert 1 ↑y : set A) ≤ span S₀ (insert 1 ↑y : set A),
{ rw span_mul_span, refine span_le.2 (λ z hz, _),
rcases set.mem_mul.1 hz with ⟨p, q, rfl | hp, hq, rfl⟩,
{ rw one_mul, exact subset_span hq },
rcases hq with rfl | hq,
{ rw mul_one, exact subset_span (or.inr hp) },
erw ← hly2 ⟨(p, q), finset.mem_product.2 ⟨hp, hq⟩⟩,
rw [finsupp.total_apply, finsupp.sum],
refine (span S₀ (insert 1 ↑y : set A)).sum_mem (λ t ht, _),
have : ly ⟨(p, q), finset.mem_product.2 ⟨hp, hq⟩⟩ t ∈ S₀ :=
subring.subset_closure (finset.mem_union_right _ $ finset.mem_bUnion.2
⟨⟨(p, q), finset.mem_product.2 ⟨hp, hq⟩⟩, finset.mem_univ _,
finsupp.mem_frange.2 ⟨finsupp.mem_support_iff.1 ht, _, rfl⟩⟩),
change (⟨_, this⟩ : S₀) • t ∈ _, exact smul_mem _ _ (subset_span $ or.inr $ hly1 _ ht) },
-- Hence this span is a subring. Call this subring `S₁`.
let S₁ : subring A :=
{ carrier := span S₀ (insert 1 ↑y : set A),
one_mem' := subset_span $ or.inl rfl,
mul_mem' := λ p q hp hq, this $ mul_mem_mul hp hq,
zero_mem' := (span S₀ (insert 1 ↑y : set A)).zero_mem,
add_mem' := λ _ _, (span S₀ (insert 1 ↑y : set A)).add_mem,
neg_mem' := λ _, (span S₀ (insert 1 ↑y : set A)).neg_mem },
have : S₁ = (algebra.adjoin S₀ (↑y : set A)).to_subring,
{ ext z,
suffices : z ∈ span ↥S₀ (insert 1 ↑y : set A) ↔
z ∈ (algebra.adjoin ↥S₀ (y : set A)).to_submodule,
{ simpa },
split; intro hz,
{ exact (span_le.2
(set.insert_subset.2 ⟨(algebra.adjoin S₀ ↑y).one_mem, algebra.subset_adjoin⟩)) hz },
{ rw [subalgebra.mem_to_submodule, algebra.mem_adjoin_iff] at hz,
suffices : subring.closure (set.range ⇑(algebra_map ↥S₀ A) ∪ ↑y) ≤ S₁,
{ exact this hz },
refine subring.closure_le.2 (set.union_subset _ (λ t ht, subset_span $ or.inr ht)),
rw set.range_subset_iff,
intro y,
rw algebra.algebra_map_eq_smul_one,
exact smul_mem _ y (subset_span (or.inl rfl)) } },
have foo : ∀ z, z ∈ S₁ ↔ z ∈ algebra.adjoin ↥S₀ (y : set A),
simp [this],
haveI : is_noetherian_ring ↥S₀ := is_noetherian_subring_closure _ (finset.finite_to_set _),
refine is_integral_of_submodule_noetherian (algebra.adjoin S₀ ↑y)
(is_noetherian_of_fg_of_noetherian _ ⟨insert 1 y,
by { rw [finset.coe_insert], ext z, simp [S₁], convert foo z}⟩) _ _,
rw [← hlx2, finsupp.total_apply, finsupp.sum], refine subalgebra.sum_mem _ (λ r hr, _),
have : lx r ∈ S₀ :=
subring.subset_closure (finset.mem_union_left _ (finset.mem_image_of_mem _ hr)),
change (⟨_, this⟩ : S₀) • r ∈ _,
rw finsupp.mem_supported at hlx1,
exact subalgebra.smul_mem _ (algebra.subset_adjoin $ hlx1 hr) _
end
lemma ring_hom.is_integral_of_mem_closure {x y z : S}
(hx : f.is_integral_elem x) (hy : f.is_integral_elem y)
(hz : z ∈ subring.closure ({x, y} : set S)) :
f.is_integral_elem z :=
begin
letI : algebra R S := f.to_algebra,
have := fg_mul _ _ (fg_adjoin_singleton_of_integral x hx) (fg_adjoin_singleton_of_integral y hy),
rw [← algebra.adjoin_union_coe_submodule, set.singleton_union] at this,
exact is_integral_of_mem_of_fg (algebra.adjoin R {x, y}) this z
(algebra.mem_adjoin_iff.2 $ subring.closure_mono (set.subset_union_right _ _) hz),
end
theorem is_integral_of_mem_closure {x y z : A}
(hx : is_integral R x) (hy : is_integral R y)
(hz : z ∈ subring.closure ({x, y} : set A)) :
is_integral R z :=
(algebra_map R A).is_integral_of_mem_closure hx hy hz
lemma ring_hom.is_integral_zero : f.is_integral_elem 0 :=
f.map_zero ▸ f.is_integral_map
theorem is_integral_zero : is_integral R (0:A) :=
(algebra_map R A).is_integral_zero
lemma ring_hom.is_integral_one : f.is_integral_elem 1 :=
f.map_one ▸ f.is_integral_map
theorem is_integral_one : is_integral R (1:A) :=
(algebra_map R A).is_integral_one
lemma ring_hom.is_integral_add {x y : S}
(hx : f.is_integral_elem x) (hy : f.is_integral_elem y) :
f.is_integral_elem (x + y) :=
f.is_integral_of_mem_closure hx hy $ subring.add_mem _
(subring.subset_closure (or.inl rfl)) (subring.subset_closure (or.inr rfl))
theorem is_integral_add {x y : A}
(hx : is_integral R x) (hy : is_integral R y) :
is_integral R (x + y) :=
(algebra_map R A).is_integral_add hx hy
lemma ring_hom.is_integral_neg {x : S}
(hx : f.is_integral_elem x) : f.is_integral_elem (-x) :=
f.is_integral_of_mem_closure hx hx (subring.neg_mem _ (subring.subset_closure (or.inl rfl)))
theorem is_integral_neg {x : A}
(hx : is_integral R x) : is_integral R (-x) :=
(algebra_map R A).is_integral_neg hx
lemma ring_hom.is_integral_sub {x y : S}
(hx : f.is_integral_elem x) (hy : f.is_integral_elem y) : f.is_integral_elem (x - y) :=
by simpa only [sub_eq_add_neg] using f.is_integral_add hx (f.is_integral_neg hy)
theorem is_integral_sub {x y : A}
(hx : is_integral R x) (hy : is_integral R y) : is_integral R (x - y) :=
(algebra_map R A).is_integral_sub hx hy
lemma ring_hom.is_integral_mul {x y : S}
(hx : f.is_integral_elem x) (hy : f.is_integral_elem y) : f.is_integral_elem (x * y) :=
f.is_integral_of_mem_closure hx hy (subring.mul_mem _
(subring.subset_closure (or.inl rfl)) (subring.subset_closure (or.inr rfl)))
theorem is_integral_mul {x y : A}
(hx : is_integral R x) (hy : is_integral R y) : is_integral R (x * y) :=
(algebra_map R A).is_integral_mul hx hy
variables (R A)
/-- The integral closure of R in an R-algebra A. -/
def integral_closure : subalgebra R A :=
{ carrier := { r | is_integral R r },
zero_mem' := is_integral_zero,
one_mem' := is_integral_one,
add_mem' := λ _ _, is_integral_add,
mul_mem' := λ _ _, is_integral_mul,
algebra_map_mem' := λ x, is_integral_algebra_map }
theorem mem_integral_closure_iff_mem_fg {r : A} :
r ∈ integral_closure R A ↔ ∃ M : subalgebra R A, M.to_submodule.fg ∧ r ∈ M :=
⟨λ hr, ⟨algebra.adjoin R {r}, fg_adjoin_singleton_of_integral _ hr, algebra.subset_adjoin rfl⟩,
λ ⟨M, Hf, hrM⟩, is_integral_of_mem_of_fg M Hf _ hrM⟩
variables {R} {A}
/-- Mapping an integral closure along an `alg_equiv` gives the integral closure. -/
lemma integral_closure_map_alg_equiv (f : A ≃ₐ[R] B) :
(integral_closure R A).map (f : A →ₐ[R] B) = integral_closure R B :=
begin
ext y,
rw subalgebra.mem_map,
split,
{ rintros ⟨x, hx, rfl⟩,
exact is_integral_alg_hom f hx },
{ intro hy,
use [f.symm y, is_integral_alg_hom (f.symm : B →ₐ[R] A) hy],
simp }
end
lemma integral_closure.is_integral (x : integral_closure R A) : is_integral R x :=
let ⟨p, hpm, hpx⟩ := x.2 in ⟨p, hpm, subtype.eq $
by rwa [← aeval_def, subtype.val_eq_coe, ← subalgebra.val_apply, aeval_alg_hom_apply] at hpx⟩
lemma ring_hom.is_integral_of_is_integral_mul_unit (x y : S) (r : R) (hr : f r * y = 1)
(hx : f.is_integral_elem (x * y)) : f.is_integral_elem x :=
begin
obtain ⟨p, ⟨p_monic, hp⟩⟩ := hx,
refine ⟨scale_roots p r, ⟨(monic_scale_roots_iff r).2 p_monic, _⟩⟩,
convert scale_roots_eval₂_eq_zero f hp,
rw [mul_comm x y, ← mul_assoc, hr, one_mul],
end
theorem is_integral_of_is_integral_mul_unit {x y : A} {r : R} (hr : algebra_map R A r * y = 1)
(hx : is_integral R (x * y)) : is_integral R x :=
(algebra_map R A).is_integral_of_is_integral_mul_unit x y r hr hx
/-- Generalization of `is_integral_of_mem_closure` bootstrapped up from that lemma -/
lemma is_integral_of_mem_closure' (G : set A) (hG : ∀ x ∈ G, is_integral R x) :
∀ x ∈ (subring.closure G), is_integral R x :=
λ x hx, subring.closure_induction hx hG is_integral_zero is_integral_one
(λ _ _, is_integral_add) (λ _, is_integral_neg) (λ _ _, is_integral_mul)
lemma is_integral_of_mem_closure'' {S : Type*} [comm_ring S] {f : R →+* S} (G : set S)
(hG : ∀ x ∈ G, f.is_integral_elem x) : ∀ x ∈ (subring.closure G), f.is_integral_elem x :=
λ x hx, @is_integral_of_mem_closure' R S _ _ f.to_algebra G hG x hx
lemma is_integral.pow {x : A} (h : is_integral R x) (n : ℕ) : is_integral R (x ^ n) :=
(integral_closure R A).pow_mem h n
lemma is_integral.nsmul {x : A} (h : is_integral R x) (n : ℕ) : is_integral R (n • x) :=
(integral_closure R A).nsmul_mem h n
lemma is_integral.gsmul {x : A} (h : is_integral R x) (n : ℤ) : is_integral R (n • x) :=
(integral_closure R A).gsmul_mem h n
lemma is_integral.multiset_prod {s : multiset A} (h : ∀ x ∈ s, is_integral R x) :
is_integral R s.prod :=
(integral_closure R A).multiset_prod_mem h
lemma is_integral.multiset_sum {s : multiset A} (h : ∀ x ∈ s, is_integral R x) :
is_integral R s.sum :=
(integral_closure R A).multiset_sum_mem h
lemma is_integral.prod {α : Type*} {s : finset α} (f : α → A) (h : ∀ x ∈ s, is_integral R (f x)) :
is_integral R (∏ x in s, f x) :=
(integral_closure R A).prod_mem h
lemma is_integral.sum {α : Type*} {s : finset α} (f : α → A) (h : ∀ x ∈ s, is_integral R (f x)) :
is_integral R (∑ x in s, f x) :=
(integral_closure R A).sum_mem h
end
section is_integral_closure
/-- `is_integral_closure A R B` is the characteristic predicate stating `A` is
the integral closure of `R` in `B`,
i.e. that an element of `B` is integral over `R` iff it is an element of (the image of) `A`.
-/
class is_integral_closure (A R B : Type*) [comm_ring R] [comm_semiring A] [comm_ring B]
[algebra R B] [algebra A B] : Prop :=
(algebra_map_injective [] : function.injective (algebra_map A B))
(is_integral_iff : ∀ {x : B}, is_integral R x ↔ ∃ y, algebra_map A B y = x)
instance integral_closure.is_integral_closure (R A : Type*) [comm_ring R] [comm_ring A]
[algebra R A] : is_integral_closure (integral_closure R A) R A :=
⟨subtype.coe_injective, λ x, ⟨λ h, ⟨⟨x, h⟩, rfl⟩, by { rintro ⟨⟨_, h⟩, rfl⟩, exact h }⟩⟩
namespace is_integral_closure
variables {R A B : Type*} [comm_ring R] [comm_ring A] [comm_ring B]
variables [algebra R B] [algebra A B] [is_integral_closure A R B]
variables (R) {A} (B)
protected theorem is_integral [algebra R A] [is_scalar_tower R A B] (x : A) : is_integral R x :=
(is_integral_algebra_map_iff (algebra_map_injective A R B)).mp $
show is_integral R (algebra_map A B x), from is_integral_iff.mpr ⟨x, rfl⟩
theorem is_integral_algebra [algebra R A] [is_scalar_tower R A B] :
algebra.is_integral R A :=
λ x, is_integral_closure.is_integral R B x
variables {R} (A) {B}
/-- If `x : B` is integral over `R`, then it is an element of the integral closure of `R` in `B`. -/
noncomputable def mk' (x : B) (hx : is_integral R x) : A :=
classical.some (is_integral_iff.mp hx)
@[simp] lemma algebra_map_mk' (x : B) (hx : is_integral R x) :
algebra_map A B (mk' A x hx) = x :=
classical.some_spec (is_integral_iff.mp hx)
@[simp] lemma mk'_one (h : is_integral R (1 : B) := is_integral_one) :
mk' A 1 h = 1 :=
algebra_map_injective A R B $ by rw [algebra_map_mk', ring_hom.map_one]
@[simp] lemma mk'_zero (h : is_integral R (0 : B) := is_integral_zero) :
mk' A 0 h = 0 :=
algebra_map_injective A R B $ by rw [algebra_map_mk', ring_hom.map_zero]
@[simp] lemma mk'_add (x y : B) (hx : is_integral R x) (hy : is_integral R y) :
mk' A (x + y) (is_integral_add hx hy) = mk' A x hx + mk' A y hy :=
algebra_map_injective A R B $ by simp only [algebra_map_mk', ring_hom.map_add]
@[simp] lemma mk'_mul (x y : B) (hx : is_integral R x) (hy : is_integral R y) :
mk' A (x * y) (is_integral_mul hx hy) = mk' A x hx * mk' A y hy :=
algebra_map_injective A R B $ by simp only [algebra_map_mk', ring_hom.map_mul]
@[simp] lemma mk'_algebra_map [algebra R A] [is_scalar_tower R A B] (x : R)
(h : is_integral R (algebra_map R B x) := is_integral_algebra_map) :
is_integral_closure.mk' A (algebra_map R B x) h = algebra_map R A x :=
algebra_map_injective A R B $ by rw [algebra_map_mk', ← is_scalar_tower.algebra_map_apply]
section lift
variables {R} (A B) {S : Type*} [comm_ring S] [algebra R S] [algebra S B] [is_scalar_tower R S B]
variables [algebra R A] [is_scalar_tower R A B] (h : algebra.is_integral R S)
/-- If `B / S / R` is a tower of ring extensions where `S` is integral over `R`,
then `S` maps (uniquely) into an integral closure `B / A / R`. -/
noncomputable def lift : S →ₐ[R] A :=
{ to_fun := λ x, mk' A (algebra_map S B x) (is_integral.algebra_map (h x)),
map_one' := by simp only [ring_hom.map_one, mk'_one],
map_zero' := by simp only [ring_hom.map_zero, mk'_zero],
map_add' := λ x y, by simp_rw [← mk'_add, ring_hom.map_add],
map_mul' := λ x y, by simp_rw [← mk'_mul, ring_hom.map_mul],
commutes' := λ x, by simp_rw [← is_scalar_tower.algebra_map_apply, mk'_algebra_map] }
@[simp] lemma algebra_map_lift (x : S) : algebra_map A B (lift A B h x) = algebra_map S B x :=
algebra_map_mk' _ _ _
end lift
section equiv
variables (R A B) (A' : Type*) [comm_ring A'] [algebra A' B] [is_integral_closure A' R B]
variables [algebra R A] [algebra R A'] [is_scalar_tower R A B] [is_scalar_tower R A' B]
/-- Integral closures are all isomorphic to each other. -/
noncomputable def equiv : A ≃ₐ[R] A' :=
alg_equiv.of_alg_hom (lift _ B (is_integral_algebra R B)) (lift _ B (is_integral_algebra R B))
(by { ext x, apply algebra_map_injective A' R B, simp })
(by { ext x, apply algebra_map_injective A R B, simp })
@[simp] lemma algebra_map_equiv (x : A) : algebra_map A' B (equiv R A B A' x) = algebra_map A B x :=
algebra_map_lift _ _ _ _
end equiv
end is_integral_closure
end is_integral_closure
section algebra
open algebra
variables {R A B S T : Type*}
variables [comm_ring R] [comm_ring A] [comm_ring B] [comm_ring S] [comm_ring T]
variables [algebra A B] [algebra R B] (f : R →+* S) (g : S →+* T)
lemma is_integral_trans_aux (x : B) {p : polynomial A} (pmonic : monic p) (hp : aeval x p = 0) :
is_integral (adjoin R (↑(p.map $ algebra_map A B).frange : set B)) x :=
begin
generalize hS : (↑(p.map $ algebra_map A B).frange : set B) = S,
have coeffs_mem : ∀ i, (p.map $ algebra_map A B).coeff i ∈ adjoin R S,
{ intro i, by_cases hi : (p.map $ algebra_map A B).coeff i = 0,
{ rw hi, exact subalgebra.zero_mem _ },
rw ← hS,
exact subset_adjoin (coeff_mem_frange _ _ hi) },
obtain ⟨q, hq⟩ : ∃ q : polynomial (adjoin R S), q.map (algebra_map (adjoin R S) B) =
(p.map $ algebra_map A B),
{ rw ← set.mem_range, exact (polynomial.mem_map_range _).2 (λ i, ⟨⟨_, coeffs_mem i⟩, rfl⟩) },
use q,
split,
{ suffices h : (q.map (algebra_map (adjoin R S) B)).monic,
{ refine monic_of_injective _ h,
exact subtype.val_injective },
{ rw hq, exact monic_map _ pmonic } },
{ convert hp using 1,
replace hq := congr_arg (eval x) hq,
convert hq using 1; symmetry; apply eval_map },
end
variables [algebra R A] [is_scalar_tower R A B]
/-- If A is an R-algebra all of whose elements are integral over R,
and x is an element of an A-algebra that is integral over A, then x is integral over R.-/
lemma is_integral_trans (A_int : is_integral R A) (x : B) (hx : is_integral A x) :
is_integral R x :=
begin
rcases hx with ⟨p, pmonic, hp⟩,
let S : set B := ↑(p.map $ algebra_map A B).frange,
refine is_integral_of_mem_of_fg (adjoin R (S ∪ {x})) _ _ (subset_adjoin $ or.inr rfl),
refine fg_trans (fg_adjoin_of_finite (finset.finite_to_set _) (λ x hx, _)) _,
{ rw [finset.mem_coe, frange, finset.mem_image] at hx,
rcases hx with ⟨i, _, rfl⟩,
rw coeff_map,
exact is_integral_alg_hom (is_scalar_tower.to_alg_hom R A B) (A_int _) },
{ apply fg_adjoin_singleton_of_integral,
exact is_integral_trans_aux _ pmonic hp }
end
/-- If A is an R-algebra all of whose elements are integral over R,
and B is an A-algebra all of whose elements are integral over A,
then all elements of B are integral over R.-/
lemma algebra.is_integral_trans (hA : is_integral R A) (hB : is_integral A B) : is_integral R B :=
λ x, is_integral_trans hA x (hB x)
lemma ring_hom.is_integral_trans (hf : f.is_integral) (hg : g.is_integral) :
(g.comp f).is_integral :=
@algebra.is_integral_trans R S T _ _ _ g.to_algebra (g.comp f).to_algebra f.to_algebra
(@is_scalar_tower.of_algebra_map_eq R S T _ _ _ f.to_algebra g.to_algebra (g.comp f).to_algebra
(ring_hom.comp_apply g f)) hf hg
lemma ring_hom.is_integral_of_surjective (hf : function.surjective f) : f.is_integral :=
λ x, (hf x).rec_on (λ y hy, (hy ▸ f.is_integral_map : f.is_integral_elem x))
lemma is_integral_of_surjective (h : function.surjective (algebra_map R A)) : is_integral R A :=
(algebra_map R A).is_integral_of_surjective h
/-- If `R → A → B` is an algebra tower with `A → B` injective,
then if the entire tower is an integral extension so is `R → A` -/
lemma is_integral_tower_bot_of_is_integral (H : function.injective (algebra_map A B))
{x : A} (h : is_integral R (algebra_map A B x)) : is_integral R x :=
begin
rcases h with ⟨p, ⟨hp, hp'⟩⟩,
refine ⟨p, ⟨hp, _⟩⟩,
rw [is_scalar_tower.algebra_map_eq R A B, ← eval₂_map,
eval₂_hom, ← ring_hom.map_zero (algebra_map A B)] at hp',
rw [eval₂_eq_eval_map],
exact H hp',
end
lemma ring_hom.is_integral_tower_bot_of_is_integral (hg : function.injective g)
(hfg : (g.comp f).is_integral) : f.is_integral :=
λ x,
@is_integral_tower_bot_of_is_integral R S T _ _ _ g.to_algebra (g.comp f).to_algebra f.to_algebra
(@is_scalar_tower.of_algebra_map_eq R S T _ _ _ f.to_algebra g.to_algebra (g.comp f).to_algebra
(ring_hom.comp_apply g f)) hg x (hfg (g x))
lemma is_integral_tower_bot_of_is_integral_field {R A B : Type*} [comm_ring R] [field A]
[comm_ring B] [nontrivial B] [algebra R A] [algebra A B] [algebra R B] [is_scalar_tower R A B]
{x : A} (h : is_integral R (algebra_map A B x)) : is_integral R x :=
is_integral_tower_bot_of_is_integral (algebra_map A B).injective h
lemma ring_hom.is_integral_elem_of_is_integral_elem_comp {x : T}
(h : (g.comp f).is_integral_elem x) : g.is_integral_elem x :=
let ⟨p, ⟨hp, hp'⟩⟩ := h in ⟨p.map f, monic_map f hp, by rwa ← eval₂_map at hp'⟩
lemma ring_hom.is_integral_tower_top_of_is_integral (h : (g.comp f).is_integral) : g.is_integral :=
λ x, ring_hom.is_integral_elem_of_is_integral_elem_comp f g (h x)
/-- If `R → A → B` is an algebra tower,
then if the entire tower is an integral extension so is `A → B`. -/
lemma is_integral_tower_top_of_is_integral {x : B} (h : is_integral R x) : is_integral A x :=
begin
rcases h with ⟨p, ⟨hp, hp'⟩⟩,
refine ⟨p.map (algebra_map R A), ⟨monic_map (algebra_map R A) hp, _⟩⟩,
rw [is_scalar_tower.algebra_map_eq R A B, ← eval₂_map] at hp',
exact hp',
end
lemma ring_hom.is_integral_quotient_of_is_integral {I : ideal S} (hf : f.is_integral) :
(ideal.quotient_map I f le_rfl).is_integral :=
begin
rintros ⟨x⟩,
obtain ⟨p, ⟨p_monic, hpx⟩⟩ := hf x,
refine ⟨p.map (ideal.quotient.mk _), ⟨monic_map _ p_monic, _⟩⟩,
simpa only [hom_eval₂, eval₂_map] using congr_arg (ideal.quotient.mk I) hpx
end
lemma is_integral_quotient_of_is_integral {I : ideal A} (hRA : is_integral R A) :
is_integral (I.comap (algebra_map R A)).quotient I.quotient :=
(algebra_map R A).is_integral_quotient_of_is_integral hRA
lemma is_integral_quotient_map_iff {I : ideal S} :
(ideal.quotient_map I f le_rfl).is_integral ↔
((ideal.quotient.mk I).comp f : R →+* I.quotient).is_integral :=
begin
let g := ideal.quotient.mk (I.comap f),
have := ideal.quotient_map_comp_mk le_rfl,
refine ⟨λ h, _, λ h, ring_hom.is_integral_tower_top_of_is_integral g _ (this ▸ h)⟩,
refine this ▸ ring_hom.is_integral_trans g (ideal.quotient_map I f le_rfl) _ h,
exact ring_hom.is_integral_of_surjective g ideal.quotient.mk_surjective,
end
/-- If the integral extension `R → S` is injective, and `S` is a field, then `R` is also a field. -/
lemma is_field_of_is_integral_of_is_field
{R S : Type*} [comm_ring R] [integral_domain R] [comm_ring S] [integral_domain S]
[algebra R S] (H : is_integral R S) (hRS : function.injective (algebra_map R S))
(hS : is_field S) : is_field R :=
begin
refine ⟨⟨0, 1, zero_ne_one⟩, mul_comm, λ a ha, _⟩,
-- Let `a_inv` be the inverse of `algebra_map R S a`,
-- then we need to show that `a_inv` is of the form `algebra_map R S b`.
obtain ⟨a_inv, ha_inv⟩ := hS.mul_inv_cancel (λ h, ha (hRS (trans h (ring_hom.map_zero _).symm))),
-- Let `p : polynomial R` be monic with root `a_inv`,
-- and `q` be `p` with coefficients reversed (so `q(a) = q'(a) * a + 1`).
-- We claim that `q(a) = 0`, so `-q'(a)` is the inverse of `a`.
obtain ⟨p, p_monic, hp⟩ := H a_inv,
use -∑ (i : ℕ) in finset.range p.nat_degree, (p.coeff i) * a ^ (p.nat_degree - i - 1),
-- `q(a) = 0`, because multiplying everything with `a_inv^n` gives `p(a_inv) = 0`.
-- TODO: this could be a lemma for `polynomial.reverse`.
have hq : ∑ (i : ℕ) in finset.range (p.nat_degree + 1), (p.coeff i) * a ^ (p.nat_degree - i) = 0,
{ apply (algebra_map R S).injective_iff.mp hRS,
have a_inv_ne_zero : a_inv ≠ 0 := right_ne_zero_of_mul (mt ha_inv.symm.trans one_ne_zero),
refine (mul_eq_zero.mp _).resolve_right (pow_ne_zero p.nat_degree a_inv_ne_zero),
rw [eval₂_eq_sum_range] at hp,
rw [ring_hom.map_sum, finset.sum_mul],
refine (finset.sum_congr rfl (λ i hi, _)).trans hp,
rw [ring_hom.map_mul, mul_assoc],
congr,
have : a_inv ^ p.nat_degree = a_inv ^ (p.nat_degree - i) * a_inv ^ i,
{ rw [← pow_add a_inv, nat.sub_add_cancel (nat.le_of_lt_succ (finset.mem_range.mp hi))] },
rw [ring_hom.map_pow, this, ← mul_assoc, ← mul_pow, ha_inv, one_pow, one_mul] },
-- Since `q(a) = 0` and `q(a) = q'(a) * a + 1`, we have `a * -q'(a) = 1`.
-- TODO: we could use a lemma for `polynomial.div_X` here.
rw [finset.sum_range_succ_comm, p_monic.coeff_nat_degree, one_mul, nat.sub_self, pow_zero,
add_eq_zero_iff_eq_neg, eq_comm] at hq,
rw [mul_comm, ← neg_mul_eq_neg_mul, finset.sum_mul],
convert hq using 2,
refine finset.sum_congr rfl (λ i hi, _),
have : 1 ≤ p.nat_degree - i := le_sub_of_add_le_left' (finset.mem_range.mp hi),
rw [mul_assoc, ← pow_succ', nat.sub_add_cancel this]
end
end algebra
theorem integral_closure_idem {R : Type*} {A : Type*} [comm_ring R] [comm_ring A] [algebra R A] :
integral_closure (integral_closure R A : set A) A = ⊥ :=
eq_bot_iff.2 $ λ x hx, algebra.mem_bot.2
⟨⟨x, @is_integral_trans _ _ _ _ _ _ _ _ (integral_closure R A).algebra
_ integral_closure.is_integral x hx⟩, rfl⟩
section integral_domain
variables {R S : Type*} [comm_ring R] [comm_ring S] [integral_domain S] [algebra R S]
instance : integral_domain (integral_closure R S) :=
infer_instance
end integral_domain
|
22773d549b7a868dab11ca3ee71267f87ae03460 | 74addaa0e41490cbaf2abd313a764c96df57b05d | /Mathlib/topology/homeomorph_auto.lean | b0d674e53baeb810b16040fcb5e82677e3536a08 | [] | no_license | AurelienSaue/Mathlib4_auto | f538cfd0980f65a6361eadea39e6fc639e9dae14 | 590df64109b08190abe22358fabc3eae000943f2 | refs/heads/master | 1,683,906,849,776 | 1,622,564,669,000 | 1,622,564,669,000 | 371,723,747 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 17,597 | lean | /-
Copyright (c) 2019 Reid Barton. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Patrick Massot, Sébastien Gouëzel, Zhouhang Zhou, Reid Barton
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.topology.dense_embedding
import Mathlib.PostPort
universes u_5 u_6 l u_1 u_2 u_3 u_4 u v
namespace Mathlib
/-- Homeomorphism between `α` and `β`, also called topological isomorphism -/
structure homeomorph (α : Type u_5) (β : Type u_6) [topological_space α] [topological_space β]
extends α ≃ β where
continuous_to_fun :
autoParam (continuous (equiv.to_fun _to_equiv))
(Lean.Syntax.ident Lean.SourceInfo.none
(String.toSubstring "Mathlib.tactic.interactive.continuity'")
(Lean.Name.mkStr
(Lean.Name.mkStr
(Lean.Name.mkStr (Lean.Name.mkStr Lean.Name.anonymous "Mathlib") "tactic")
"interactive")
"continuity'")
[])
continuous_inv_fun :
autoParam (continuous (equiv.inv_fun _to_equiv))
(Lean.Syntax.ident Lean.SourceInfo.none
(String.toSubstring "Mathlib.tactic.interactive.continuity'")
(Lean.Name.mkStr
(Lean.Name.mkStr
(Lean.Name.mkStr (Lean.Name.mkStr Lean.Name.anonymous "Mathlib") "tactic")
"interactive")
"continuity'")
[])
infixl:25 " ≃ₜ " => Mathlib.homeomorph
namespace homeomorph
protected instance has_coe_to_fun {α : Type u_1} {β : Type u_2} [topological_space α]
[topological_space β] : has_coe_to_fun (α ≃ₜ β) :=
has_coe_to_fun.mk (fun (_x : α ≃ₜ β) => α → β) fun (e : α ≃ₜ β) => ⇑(to_equiv e)
@[simp] theorem homeomorph_mk_coe {α : Type u_1} {β : Type u_2} [topological_space α]
[topological_space β] (a : α ≃ β)
(b :
autoParam (continuous (equiv.to_fun a))
(Lean.Syntax.ident Lean.SourceInfo.none
(String.toSubstring "Mathlib.tactic.interactive.continuity'")
(Lean.Name.mkStr
(Lean.Name.mkStr
(Lean.Name.mkStr (Lean.Name.mkStr Lean.Name.anonymous "Mathlib") "tactic")
"interactive")
"continuity'")
[]))
(c :
autoParam (continuous (equiv.inv_fun a))
(Lean.Syntax.ident Lean.SourceInfo.none
(String.toSubstring "Mathlib.tactic.interactive.continuity'")
(Lean.Name.mkStr
(Lean.Name.mkStr
(Lean.Name.mkStr (Lean.Name.mkStr Lean.Name.anonymous "Mathlib") "tactic")
"interactive")
"continuity'")
[])) :
⇑(mk a) = ⇑a :=
rfl
theorem coe_eq_to_equiv {α : Type u_1} {β : Type u_2} [topological_space α] [topological_space β]
(h : α ≃ₜ β) (a : α) : coe_fn h a = coe_fn (to_equiv h) a :=
rfl
theorem to_equiv_injective {α : Type u_1} {β : Type u_2} [topological_space α]
[topological_space β] : function.injective to_equiv :=
sorry
theorem ext {α : Type u_1} {β : Type u_2} [topological_space α] [topological_space β] {h : α ≃ₜ β}
{h' : α ≃ₜ β} (H : ∀ (x : α), coe_fn h x = coe_fn h' x) : h = h' :=
to_equiv_injective (equiv.ext H)
/-- Identity map as a homeomorphism. -/
protected def refl (α : Type u_1) [topological_space α] : α ≃ₜ α :=
mk (equiv.mk (equiv.to_fun (equiv.refl α)) (equiv.inv_fun (equiv.refl α)) sorry sorry)
/-- Composition of two homeomorphisms. -/
protected def trans {α : Type u_1} {β : Type u_2} {γ : Type u_3} [topological_space α]
[topological_space β] [topological_space γ] (h₁ : α ≃ₜ β) (h₂ : β ≃ₜ γ) : α ≃ₜ γ :=
mk
(equiv.mk (equiv.to_fun (equiv.trans (to_equiv h₁) (to_equiv h₂)))
(equiv.inv_fun (equiv.trans (to_equiv h₁) (to_equiv h₂))) sorry sorry)
/-- Inverse of a homeomorphism. -/
protected def symm {α : Type u_1} {β : Type u_2} [topological_space α] [topological_space β]
(h : α ≃ₜ β) : β ≃ₜ α :=
mk
(equiv.mk (equiv.to_fun (equiv.symm (to_equiv h))) (equiv.inv_fun (equiv.symm (to_equiv h)))
sorry sorry)
@[simp] theorem homeomorph_mk_coe_symm {α : Type u_1} {β : Type u_2} [topological_space α]
[topological_space β] (a : α ≃ β)
(b :
autoParam (continuous (equiv.to_fun a))
(Lean.Syntax.ident Lean.SourceInfo.none
(String.toSubstring "Mathlib.tactic.interactive.continuity'")
(Lean.Name.mkStr
(Lean.Name.mkStr
(Lean.Name.mkStr (Lean.Name.mkStr Lean.Name.anonymous "Mathlib") "tactic")
"interactive")
"continuity'")
[]))
(c :
autoParam (continuous (equiv.inv_fun a))
(Lean.Syntax.ident Lean.SourceInfo.none
(String.toSubstring "Mathlib.tactic.interactive.continuity'")
(Lean.Name.mkStr
(Lean.Name.mkStr
(Lean.Name.mkStr (Lean.Name.mkStr Lean.Name.anonymous "Mathlib") "tactic")
"interactive")
"continuity'")
[])) :
⇑(homeomorph.symm (mk a)) = ⇑(equiv.symm a) :=
rfl
protected theorem continuous {α : Type u_1} {β : Type u_2} [topological_space α]
[topological_space β] (h : α ≃ₜ β) : continuous ⇑h :=
continuous_to_fun h
@[simp] theorem apply_symm_apply {α : Type u_1} {β : Type u_2} [topological_space α]
[topological_space β] (h : α ≃ₜ β) (x : β) : coe_fn h (coe_fn (homeomorph.symm h) x) = x :=
equiv.apply_symm_apply (to_equiv h) x
@[simp] theorem symm_apply_apply {α : Type u_1} {β : Type u_2} [topological_space α]
[topological_space β] (h : α ≃ₜ β) (x : α) : coe_fn (homeomorph.symm h) (coe_fn h x) = x :=
equiv.symm_apply_apply (to_equiv h) x
protected theorem bijective {α : Type u_1} {β : Type u_2} [topological_space α]
[topological_space β] (h : α ≃ₜ β) : function.bijective ⇑h :=
equiv.bijective (to_equiv h)
protected theorem injective {α : Type u_1} {β : Type u_2} [topological_space α]
[topological_space β] (h : α ≃ₜ β) : function.injective ⇑h :=
equiv.injective (to_equiv h)
protected theorem surjective {α : Type u_1} {β : Type u_2} [topological_space α]
[topological_space β] (h : α ≃ₜ β) : function.surjective ⇑h :=
equiv.surjective (to_equiv h)
/-- Change the homeomorphism `f` to make the inverse function definitionally equal to `g`. -/
def change_inv {α : Type u_1} {β : Type u_2} [topological_space α] [topological_space β]
(f : α ≃ₜ β) (g : β → α) (hg : function.right_inverse g ⇑f) : α ≃ₜ β :=
(fun (this : g = ⇑(homeomorph.symm f)) => mk (equiv.mk (⇑f) g sorry sorry)) sorry
@[simp] theorem symm_comp_self {α : Type u_1} {β : Type u_2} [topological_space α]
[topological_space β] (h : α ≃ₜ β) : ⇑(homeomorph.symm h) ∘ ⇑h = id :=
funext (symm_apply_apply h)
@[simp] theorem self_comp_symm {α : Type u_1} {β : Type u_2} [topological_space α]
[topological_space β] (h : α ≃ₜ β) : ⇑h ∘ ⇑(homeomorph.symm h) = id :=
funext (apply_symm_apply h)
@[simp] theorem range_coe {α : Type u_1} {β : Type u_2} [topological_space α] [topological_space β]
(h : α ≃ₜ β) : set.range ⇑h = set.univ :=
function.surjective.range_eq (homeomorph.surjective h)
theorem image_symm {α : Type u_1} {β : Type u_2} [topological_space α] [topological_space β]
(h : α ≃ₜ β) : set.image ⇑(homeomorph.symm h) = set.preimage ⇑h :=
funext (equiv.image_eq_preimage (to_equiv (homeomorph.symm h)))
theorem preimage_symm {α : Type u_1} {β : Type u_2} [topological_space α] [topological_space β]
(h : α ≃ₜ β) : set.preimage ⇑(homeomorph.symm h) = set.image ⇑h :=
Eq.symm (funext (equiv.image_eq_preimage (to_equiv h)))
@[simp] theorem image_preimage {α : Type u_1} {β : Type u_2} [topological_space α]
[topological_space β] (h : α ≃ₜ β) (s : set β) : ⇑h '' (⇑h ⁻¹' s) = s :=
equiv.image_preimage (to_equiv h) s
@[simp] theorem preimage_image {α : Type u_1} {β : Type u_2} [topological_space α]
[topological_space β] (h : α ≃ₜ β) (s : set α) : ⇑h ⁻¹' (⇑h '' s) = s :=
equiv.preimage_image (to_equiv h) s
protected theorem inducing {α : Type u_1} {β : Type u_2} [topological_space α] [topological_space β]
(h : α ≃ₜ β) : inducing ⇑h :=
sorry
theorem induced_eq {α : Type u_1} {β : Type u_2} [topological_space α] [topological_space β]
(h : α ≃ₜ β) : topological_space.induced (⇑h) _inst_2 = _inst_1 :=
Eq.symm (inducing.induced (homeomorph.inducing h))
protected theorem quotient_map {α : Type u_1} {β : Type u_2} [topological_space α]
[topological_space β] (h : α ≃ₜ β) : quotient_map ⇑h :=
sorry
theorem coinduced_eq {α : Type u_1} {β : Type u_2} [topological_space α] [topological_space β]
(h : α ≃ₜ β) : topological_space.coinduced (⇑h) _inst_1 = _inst_2 :=
Eq.symm (and.right (homeomorph.quotient_map h))
protected theorem embedding {α : Type u_1} {β : Type u_2} [topological_space α]
[topological_space β] (h : α ≃ₜ β) : embedding ⇑h :=
embedding.mk (homeomorph.inducing h) (equiv.injective (to_equiv h))
theorem compact_image {α : Type u_1} {β : Type u_2} [topological_space α] [topological_space β]
{s : set α} (h : α ≃ₜ β) : is_compact (⇑h '' s) ↔ is_compact s :=
iff.symm (embedding.compact_iff_compact_image (homeomorph.embedding h))
theorem compact_preimage {α : Type u_1} {β : Type u_2} [topological_space α] [topological_space β]
{s : set β} (h : α ≃ₜ β) : is_compact (⇑h ⁻¹' s) ↔ is_compact s :=
eq.mpr (id (Eq._oldrec (Eq.refl (is_compact (⇑h ⁻¹' s) ↔ is_compact s)) (Eq.symm (image_symm h))))
(compact_image (homeomorph.symm h))
protected theorem dense_embedding {α : Type u_1} {β : Type u_2} [topological_space α]
[topological_space β] (h : α ≃ₜ β) : dense_embedding ⇑h :=
dense_embedding.mk
(dense_inducing.mk (inducing.mk (Eq.symm (induced_eq h)))
(function.surjective.dense_range (homeomorph.surjective h)))
(homeomorph.injective h)
@[simp] theorem is_open_preimage {α : Type u_1} {β : Type u_2} [topological_space α]
[topological_space β] (h : α ≃ₜ β) {s : set β} : is_open (⇑h ⁻¹' s) ↔ is_open s :=
quotient_map.is_open_preimage (homeomorph.quotient_map h)
@[simp] theorem is_open_image {α : Type u_1} {β : Type u_2} [topological_space α]
[topological_space β] (h : α ≃ₜ β) {s : set α} : is_open (⇑h '' s) ↔ is_open s :=
sorry
@[simp] theorem is_closed_preimage {α : Type u_1} {β : Type u_2} [topological_space α]
[topological_space β] (h : α ≃ₜ β) {s : set β} : is_closed (⇑h ⁻¹' s) ↔ is_closed s :=
sorry
@[simp] theorem is_closed_image {α : Type u_1} {β : Type u_2} [topological_space α]
[topological_space β] (h : α ≃ₜ β) {s : set α} : is_closed (⇑h '' s) ↔ is_closed s :=
sorry
theorem preimage_closure {α : Type u_1} {β : Type u_2} [topological_space α] [topological_space β]
(h : α ≃ₜ β) (s : set β) : ⇑h ⁻¹' closure s = closure (⇑h ⁻¹' s) :=
sorry
theorem image_closure {α : Type u_1} {β : Type u_2} [topological_space α] [topological_space β]
(h : α ≃ₜ β) (s : set α) : ⇑h '' closure s = closure (⇑h '' s) :=
sorry
protected theorem is_open_map {α : Type u_1} {β : Type u_2} [topological_space α]
[topological_space β] (h : α ≃ₜ β) : is_open_map ⇑h :=
fun (s : set α) => iff.mpr (is_open_image h)
protected theorem is_closed_map {α : Type u_1} {β : Type u_2} [topological_space α]
[topological_space β] (h : α ≃ₜ β) : is_closed_map ⇑h :=
fun (s : set α) => iff.mpr (is_closed_image h)
protected theorem closed_embedding {α : Type u_1} {β : Type u_2} [topological_space α]
[topological_space β] (h : α ≃ₜ β) : closed_embedding ⇑h :=
closed_embedding_of_embedding_closed (homeomorph.embedding h) (homeomorph.is_closed_map h)
@[simp] theorem map_nhds_eq {α : Type u_1} {β : Type u_2} [topological_space α]
[topological_space β] (h : α ≃ₜ β) (x : α) : filter.map (⇑h) (nhds x) = nhds (coe_fn h x) :=
sorry
@[simp] theorem comap_nhds_eq {α : Type u_1} {β : Type u_2} [topological_space α]
[topological_space β] (h : α ≃ₜ β) (y : β) :
filter.comap (⇑h) (nhds y) = nhds (coe_fn (homeomorph.symm h) y) :=
sorry
theorem nhds_eq_comap {α : Type u_1} {β : Type u_2} [topological_space α] [topological_space β]
(h : α ≃ₜ β) (x : α) : nhds x = filter.comap (⇑h) (nhds (coe_fn h x)) :=
eq.mpr
(id
(Eq._oldrec (Eq.refl (nhds x = filter.comap (⇑h) (nhds (coe_fn h x))))
(comap_nhds_eq h (coe_fn h x))))
(eq.mpr
(id
(Eq._oldrec (Eq.refl (nhds x = nhds (coe_fn (homeomorph.symm h) (coe_fn h x))))
(symm_apply_apply h x)))
(Eq.refl (nhds x)))
/-- If an bijective map `e : α ≃ β` is continuous and open, then it is a homeomorphism. -/
def homeomorph_of_continuous_open {α : Type u_1} {β : Type u_2} [topological_space α]
[topological_space β] (e : α ≃ β) (h₁ : continuous ⇑e) (h₂ : is_open_map ⇑e) : α ≃ₜ β :=
mk (equiv.mk (equiv.to_fun e) (equiv.inv_fun e) (equiv.left_inv e) (equiv.right_inv e))
@[simp] theorem comp_continuous_on_iff {α : Type u_1} {β : Type u_2} {γ : Type u_3}
[topological_space α] [topological_space β] [topological_space γ] (h : α ≃ₜ β) (f : γ → α)
(s : set γ) : continuous_on (⇑h ∘ f) s ↔ continuous_on f s :=
iff.symm (inducing.continuous_on_iff (homeomorph.inducing h))
@[simp] theorem comp_continuous_iff {α : Type u_1} {β : Type u_2} {γ : Type u_3}
[topological_space α] [topological_space β] [topological_space γ] (h : α ≃ₜ β) {f : γ → α} :
continuous (⇑h ∘ f) ↔ continuous f :=
iff.symm (inducing.continuous_iff (homeomorph.inducing h))
@[simp] theorem comp_continuous_iff' {α : Type u_1} {β : Type u_2} {γ : Type u_3}
[topological_space α] [topological_space β] [topological_space γ] (h : α ≃ₜ β) {f : β → γ} :
continuous (f ∘ ⇑h) ↔ continuous f :=
iff.symm (quotient_map.continuous_iff (homeomorph.quotient_map h))
/-- If two sets are equal, then they are homeomorphic. -/
def set_congr {α : Type u_1} [topological_space α] {s : set α} {t : set α} (h : s = t) : ↥s ≃ₜ ↥t :=
mk (equiv.mk (equiv.to_fun (equiv.set_congr h)) (equiv.inv_fun (equiv.set_congr h)) sorry sorry)
/-- Sum of two homeomorphisms. -/
def sum_congr {α : Type u_1} {β : Type u_2} {γ : Type u_3} {δ : Type u_4} [topological_space α]
[topological_space β] [topological_space γ] [topological_space δ] (h₁ : α ≃ₜ β) (h₂ : γ ≃ₜ δ) :
α ⊕ γ ≃ₜ β ⊕ δ :=
mk
(equiv.mk (equiv.to_fun (equiv.sum_congr (to_equiv h₁) (to_equiv h₂)))
(equiv.inv_fun (equiv.sum_congr (to_equiv h₁) (to_equiv h₂))) sorry sorry)
/-- Product of two homeomorphisms. -/
def prod_congr {α : Type u_1} {β : Type u_2} {γ : Type u_3} {δ : Type u_4} [topological_space α]
[topological_space β] [topological_space γ] [topological_space δ] (h₁ : α ≃ₜ β) (h₂ : γ ≃ₜ δ) :
α × γ ≃ₜ β × δ :=
mk
(equiv.mk (equiv.to_fun (equiv.prod_congr (to_equiv h₁) (to_equiv h₂)))
(equiv.inv_fun (equiv.prod_congr (to_equiv h₁) (to_equiv h₂))) sorry sorry)
/-- `α × β` is homeomorphic to `β × α`. -/
def prod_comm (α : Type u_1) (β : Type u_2) [topological_space α] [topological_space β] :
α × β ≃ₜ β × α :=
mk
(equiv.mk (equiv.to_fun (equiv.prod_comm α β)) (equiv.inv_fun (equiv.prod_comm α β)) sorry
sorry)
/-- `(α × β) × γ` is homeomorphic to `α × (β × γ)`. -/
def prod_assoc (α : Type u_1) (β : Type u_2) (γ : Type u_3) [topological_space α]
[topological_space β] [topological_space γ] : (α × β) × γ ≃ₜ α × β × γ :=
mk
(equiv.mk (equiv.to_fun (equiv.prod_assoc α β γ)) (equiv.inv_fun (equiv.prod_assoc α β γ)) sorry
sorry)
/-- `ulift α` is homeomorphic to `α`. -/
def ulift {α : Type u} [topological_space α] : ulift α ≃ₜ α :=
mk (equiv.mk (equiv.to_fun equiv.ulift) (equiv.inv_fun equiv.ulift) sorry sorry)
/-- `(α ⊕ β) × γ` is homeomorphic to `α × γ ⊕ β × γ`. -/
def sum_prod_distrib {α : Type u_1} {β : Type u_2} {γ : Type u_3} [topological_space α]
[topological_space β] [topological_space γ] : (α ⊕ β) × γ ≃ₜ α × γ ⊕ β × γ :=
homeomorph.symm
(homeomorph_of_continuous_open (equiv.symm (equiv.sum_prod_distrib α β γ)) sorry sorry)
/-- `α × (β ⊕ γ)` is homeomorphic to `α × β ⊕ α × γ`. -/
def prod_sum_distrib {α : Type u_1} {β : Type u_2} {γ : Type u_3} [topological_space α]
[topological_space β] [topological_space γ] : α × (β ⊕ γ) ≃ₜ α × β ⊕ α × γ :=
homeomorph.trans (prod_comm α (β ⊕ γ))
(homeomorph.trans sum_prod_distrib (sum_congr (prod_comm β α) (prod_comm γ α)))
/-- `(Σ i, σ i) × β` is homeomorphic to `Σ i, (σ i × β)`. -/
def sigma_prod_distrib {β : Type u_2} [topological_space β] {ι : Type u_5} {σ : ι → Type u_6}
[(i : ι) → topological_space (σ i)] :
(sigma fun (i : ι) => σ i) × β ≃ₜ sigma fun (i : ι) => σ i × β :=
homeomorph.symm
(homeomorph_of_continuous_open (equiv.symm (equiv.sigma_prod_distrib σ β)) sorry sorry)
end Mathlib |
2623e5fe6d7e4e308eca0113c0befbf7001417e7 | 8d65764a9e5f0923a67fc435eb1a5a1d02fd80e3 | /src/tactic/lint/frontend.lean | 4e928aad7c338f1576d85cacb687bf6dfcf8f2e1 | [
"Apache-2.0"
] | permissive | troyjlee/mathlib | e18d4b8026e32062ab9e89bc3b003a5d1cfec3f5 | 45e7eb8447555247246e3fe91c87066506c14875 | refs/heads/master | 1,689,248,035,046 | 1,629,470,528,000 | 1,629,470,528,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 13,857 | lean | /-
Copyright (c) 2020 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn, Robert Y. Lewis, Gabriel Ebner
-/
import tactic.lint.basic
/-!
# Linter frontend and commands
This file defines the linter commands which spot common mistakes in the code.
* `#lint`: check all declarations in the current file
* `#lint_mathlib`: check all declarations in mathlib (so excluding core or other projects,
and also excluding the current file)
* `#lint_all`: check all declarations in the environment (the current file and all
imported files)
For a list of default / non-default linters, see the "Linting Commands" user command doc entry.
The command `#list_linters` prints a list of the names of all available linters.
You can append a `*` to any command (e.g. `#lint_mathlib*`) to omit the slow tests (4).
You can append a `-` to any command (e.g. `#lint_mathlib-`) to run a silent lint
that suppresses the output if all checks pass.
A silent lint will fail if any test fails.
You can append a `+` to any command (e.g. `#lint_mathlib+`) to run a verbose lint
that reports the result of each linter, including the successes.
You can append a sequence of linter names to any command to run extra tests, in addition to the
default ones. e.g. `#lint doc_blame_thm` will run all default tests and `doc_blame_thm`.
You can append `only name1 name2 ...` to any command to run a subset of linters, e.g.
`#lint only unused_arguments`
You can add custom linters by defining a term of type `linter` in the `linter` namespace.
A linter defined with the name `linter.my_new_check` can be run with `#lint my_new_check`
or `lint only my_new_check`.
If you add the attribute `@[linter]` to `linter.my_new_check` it will run by default.
Adding the attribute `@[nolint doc_blame unused_arguments]` to a declaration
omits it from only the specified linter checks.
## Tags
sanity check, lint, cleanup, command, tactic
-/
open tactic expr native
setup_tactic_parser
/--
Verbosity for the linter output.
* `low`: only print failing checks, print nothing on success.
* `medium`: only print failing checks, print confirmation on success.
* `high`: print output of every check.
-/
@[derive [decidable_eq, inhabited]]
inductive lint_verbosity | low | medium | high
/-- `get_checks slow extra use_only` produces a list of linters.
`extras` is a list of names that should resolve to declarations with type `linter`.
If `use_only` is true, it only uses the linters in `extra`.
Otherwise, it uses all linters in the environment tagged with `@[linter]`.
If `slow` is false, it only uses the fast default tests. -/
meta def get_checks (slow : bool) (extra : list name) (use_only : bool) :
tactic (list (name × linter)) := do
default ← if use_only then return [] else attribute.get_instances `linter >>= get_linters,
let default := if slow then default else default.filter (λ l, l.2.is_fast),
list.append default <$> get_linters extra
/--
`lint_core all_decls non_auto_decls checks` applies the linters `checks` to the list of
declarations.
If `auto_decls` is false for a linter (default) the linter is applied to `non_auto_decls`.
If `auto_decls` is true, then it is applied to `all_decls`.
The resulting list has one element for each linter, containing the linter as
well as a map from declaration name to warning.
-/
meta def lint_core (all_decls non_auto_decls : list declaration) (checks : list (name × linter)) :
tactic (list (name × linter × rb_map name string)) := do
checks.mmap $ λ ⟨linter_name, linter⟩, do
let test_decls := if linter.auto_decls then all_decls else non_auto_decls,
test_decls ← test_decls.mfilter (λ decl, should_be_linted linter_name decl.to_name),
s ← read,
let results := test_decls.map_async_chunked $ λ decl, prod.mk decl.to_name $
match linter.test decl s with
| result.success w _ := w
| result.exception msg _ _ :=
some $ "LINTER FAILED:\n" ++ msg.elim "(no message)" (λ msg, to_string $ msg ())
end,
let results := results.foldl (λ (results : rb_map name string) warning,
match warning with
| (decl_name, some w) := results.insert decl_name w
| (_, none) := results
end) mk_rb_map,
pure (linter_name, linter, results)
/-- Sorts a map with declaration keys as names by line number. -/
meta def sort_results {α} (e : environment) (results : rb_map name α) : list (name × α) :=
list.reverse $ rb_lmap.values $ rb_lmap.of_list $
results.fold [] $ λ decl linter_warning results,
(((e.decl_pos decl).get_or_else ⟨0,0⟩).line, (decl, linter_warning)) :: results
/-- Formats a linter warning as `#print` command with comment. -/
meta def print_warning (decl_name : name) (warning : string) : format :=
"#print " ++ to_fmt decl_name ++ " /- " ++ warning ++ " -/"
/-- Formats a map of linter warnings using `print_warning`, sorted by line number. -/
meta def print_warnings (env : environment) (results : rb_map name string) : format :=
format.intercalate format.line $ (sort_results env results).map $
λ ⟨decl_name, warning⟩, print_warning decl_name warning
/--
Formats a map of linter warnings grouped by filename with `-- filename` comments.
The first `drop_fn_chars` characters are stripped from the filename.
-/
meta def grouped_by_filename (e : environment) (results : rb_map name string) (drop_fn_chars := 0)
(formatter: rb_map name string → format) : format :=
let results := results.fold (rb_map.mk string (rb_map name string)) $
λ decl_name linter_warning results,
let fn := (e.decl_olean decl_name).get_or_else "" in
results.insert fn (((results.find fn).get_or_else mk_rb_map).insert
decl_name linter_warning) in
let l := results.to_list.reverse.map (λ ⟨fn, results⟩,
("-- " ++ fn.popn drop_fn_chars ++ "\n" ++ formatter results : format)) in
format.intercalate "\n\n" l ++ "\n"
/--
Formats the linter results as Lean code with comments and `#print` commands.
-/
meta def format_linter_results
(env : environment)
(results : list (name × linter × rb_map name string))
(decls non_auto_decls : list declaration)
(group_by_filename : option nat)
(where_desc : string) (slow : bool) (verbose : lint_verbosity) :
format := do
let formatted_results := results.map $ λ ⟨linter_name, linter, results⟩,
let report_str : format := to_fmt "/- The `" ++ to_fmt linter_name ++ "` linter reports: -/\n" in
if ¬ results.empty then
let warnings := match group_by_filename with
| none := print_warnings env results
| some dropped := grouped_by_filename env results dropped (print_warnings env)
end in
report_str ++ "/- " ++ linter.errors_found ++ " -/\n" ++ warnings ++ "\n"
else if verbose = lint_verbosity.high then
"/- OK: " ++ linter.no_errors_found ++ " -/"
else format.nil,
let s := format.intercalate "\n" (formatted_results.filter (λ f, ¬ f.is_nil)),
let s := if verbose = lint_verbosity.low then s else
format!("/- Checking {non_auto_decls.length} declarations (plus " ++
"{decls.length - non_auto_decls.length} automatically generated ones) {where_desc} -/\n\n") ++ s,
let s := if slow then s else s ++ "/- (slow tests skipped) -/\n",
s
/-- The common denominator of `#lint[|mathlib|all]`.
The different commands have different configurations for `l`,
`group_by_filename` and `where_desc`.
If `slow` is false, doesn't do the checks that take a lot of time.
If `verbose` is false, it will suppress messages from passing checks.
By setting `checks` you can customize which checks are performed.
Returns a `name_set` containing the names of all declarations that fail any check in `check`,
and a `format` object describing the failures. -/
meta def lint_aux (decls : list declaration) (group_by_filename : option nat)
(where_desc : string) (slow : bool) (verbose : lint_verbosity) (checks : list (name × linter)) :
tactic (name_set × format) := do
e ← get_env,
let non_auto_decls := decls.filter (λ d, ¬ d.is_auto_or_internal e),
results ← lint_core decls non_auto_decls checks,
let s := format_linter_results e results decls non_auto_decls
group_by_filename where_desc slow verbose,
let ns := name_set.of_list (do (_,_,rs) ← results, rs.keys),
pure (ns, s)
/-- Return the message printed by `#lint` and a `name_set` containing all declarations that fail. -/
meta def lint (slow : bool := tt) (verbose : lint_verbosity := lint_verbosity.medium)
(extra : list name := []) (use_only : bool := ff) : tactic (name_set × format) := do
checks ← get_checks slow extra use_only,
e ← get_env,
let l := e.filter (λ d, e.in_current_file d.to_name),
lint_aux l none "in the current file" slow verbose checks
/-- Returns the declarations considered by the mathlib linter. -/
meta def lint_mathlib_decls : tactic (list declaration) := do
e ← get_env,
ml ← get_mathlib_dir,
pure $ e.filter $ λ d, e.is_prefix_of_file ml d.to_name
/-- Return the message printed by `#lint_mathlib` and a `name_set` containing all declarations
that fail. -/
meta def lint_mathlib (slow : bool := tt) (verbose : lint_verbosity := lint_verbosity.medium)
(extra : list name := []) (use_only : bool := ff) : tactic (name_set × format) := do
checks ← get_checks slow extra use_only,
decls ← lint_mathlib_decls,
mathlib_path_len ← string.length <$> get_mathlib_dir,
lint_aux decls mathlib_path_len "in mathlib (only in imported files)" slow verbose checks
/-- Return the message printed by `#lint_all` and a `name_set` containing all declarations
that fail. -/
meta def lint_all (slow : bool := tt) (verbose : lint_verbosity := lint_verbosity.medium)
(extra : list name := []) (use_only : bool := ff) : tactic (name_set × format) := do
checks ← get_checks slow extra use_only,
e ← get_env,
let l := e.get_decls,
lint_aux l (some 0) "in all imported files (including this one)" slow verbose checks
/-- Parses an optional `only`, followed by a sequence of zero or more identifiers.
Prepends `linter.` to each of these identifiers. -/
private meta def parse_lint_additions : parser (bool × list name) :=
prod.mk <$> only_flag <*> (list.map (name.append `linter) <$> ident*)
/--
Parses a "-" or "+", returning `lint_verbosity.low` or `lint_verbosity.high` respectively,
or returns `none`.
-/
private meta def parse_verbosity : parser (option lint_verbosity) :=
tk "-" >> return lint_verbosity.low <|>
tk "+" >> return lint_verbosity.high <|>
return none
/-- The common denominator of `lint_cmd`, `lint_mathlib_cmd`, `lint_all_cmd` -/
private meta def lint_cmd_aux
(scope : bool → lint_verbosity → list name → bool → tactic (name_set × format)) :
parser unit :=
do verbosity ← parse_verbosity,
fast_only ← optional (tk "*"),
-- allow either order of *-
verbosity ← if verbosity.is_some then return verbosity else parse_verbosity,
let verbosity := verbosity.get_or_else lint_verbosity.medium,
(use_only, extra) ← parse_lint_additions,
(failed, s) ← scope fast_only.is_none verbosity extra use_only,
when (¬ s.is_nil) $ trace s,
when (verbosity = lint_verbosity.low ∧ ¬ failed.empty) $
fail "Linting did not succeed",
when (verbosity = lint_verbosity.medium ∧ failed.empty) $
trace "/- All linting checks passed! -/"
/-- The command `#lint` at the bottom of a file will warn you about some common mistakes
in that file. Usage: `#lint`, `#lint linter_1 linter_2`, `#lint only linter_1 linter_2`.
`#lint-` will suppress the output if all checks pass.
`#lint+` will enable verbose output.
Use the command `#list_linters` to see all available linters. -/
@[user_command] meta def lint_cmd (_ : parse $ tk "#lint") : parser unit :=
lint_cmd_aux @lint
/-- The command `#lint_mathlib` checks all of mathlib for certain mistakes.
Usage: `#lint_mathlib`, `#lint_mathlib linter_1 linter_2`, `#lint_mathlib only linter_1 linter_2`.
`#lint_mathlib-` will suppress the output if all checks pass.
`lint_mathlib+` will enable verbose output.
Use the command `#list_linters` to see all available linters. -/
@[user_command] meta def lint_mathlib_cmd (_ : parse $ tk "#lint_mathlib") : parser unit :=
lint_cmd_aux @lint_mathlib
/-- The command `#lint_all` checks all imported files for certain mistakes.
Usage: `#lint_all`, `#lint_all linter_1 linter_2`, `#lint_all only linter_1 linter_2`.
`#lint_all-` will suppress the output if all checks pass.
`lint_all+` will enable verbose output.
Use the command `#list_linters` to see all available linters. -/
@[user_command] meta def lint_all_cmd (_ : parse $ tk "#lint_all") : parser unit :=
lint_cmd_aux @lint_all
/-- The command `#list_linters` prints a list of all available linters. -/
@[user_command] meta def list_linters (_ : parse $ tk "#list_linters") : parser unit :=
do env ← get_env,
let ns := env.decl_filter_map $ λ dcl,
if (dcl.to_name.get_prefix = `linter) && (dcl.type = `(linter)) then some dcl.to_name else none,
trace "Available linters:\n linters marked with (*) are in the default lint set\n",
ns.mmap' $ λ n, do
b ← has_attribute' `linter n,
trace $ n.pop_prefix.to_string ++ if b then " (*)" else ""
/--
Invoking the hole command `lint` ("Find common mistakes in current file") will print text that
indicates mistakes made in the file above the command. It is equivalent to copying and pasting the
output of `#lint`. On large files, it may take some time before the output appears.
-/
@[hole_command] meta def lint_hole_cmd : hole_command :=
{ name := "Lint",
descr := "Lint: Find common mistakes in current file.",
action := λ es, do (_, s) ← lint, return [(s.to_string,"")] }
add_tactic_doc
{ name := "Lint",
category := doc_category.hole_cmd,
decl_names := [`lint_hole_cmd],
tags := ["linting"] }
|
99f6d492dbd2d6330008eed35d8499a2366f3366 | fa02ed5a3c9c0adee3c26887a16855e7841c668b | /src/tactic/lint/misc.lean | 172dba10b4bd738b4079c582c779c873cb6513fe | [
"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 | 12,375 | lean | /-
Copyright (c) 2020 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn, Robert Y. Lewis
-/
import tactic.lint.basic
/-!
# Various linters
This file defines several small linters:
- `ge_or_gt` checks that `>` and `≥` do not occur in the statement of theorems.
- `dup_namespace` checks that no declaration has a duplicated namespace such as `list.list.monad`.
- `unused_arguments` checks that definitions and theorems do not have unused arguments.
- `doc_blame` checks that every definition has a documentation string.
- `doc_blame_thm` checks that every theorem has a documentation string (not enabled by default).
- `def_lemma` checks that a declaration is a lemma iff its type is a proposition.
- `check_type` checks that the statement of a declaration is well-typed.
-/
open tactic expr
/-!
## Linter against use of `>`/`≥`
-/
/-- The names of `≥` and `>`, mostly disallowed in lemma statements -/
private meta def illegal_ge_gt : list name := [`gt, `ge]
set_option eqn_compiler.max_steps 20000
/--
Checks whether `≥` and `>` occurs in an illegal way in the expression.
The main ways we legally use these orderings are:
- `f (≥)`
- `∃ x ≥ t, b`. This corresponds to the expression
`@Exists α (fun (x : α), (@Exists (x > t) (λ (H : x > t), b)))`
This function returns `tt` when it finds `ge`/`gt`, except in the following patterns
(which are the same for `gt`):
- `f (@ge _ _)`
- `f (&0 ≥ y) (λ x : t, b)`
- `λ H : &0 ≥ t, b`
Here `&0` is the 0-th de Bruijn variable.
-/
private meta def contains_illegal_ge_gt : expr → bool
| (const nm us) := if nm ∈ illegal_ge_gt then tt else ff
| (app f e@(app (app (const nm us) tp) tc)) :=
contains_illegal_ge_gt f || if nm ∈ illegal_ge_gt then ff else contains_illegal_ge_gt e
| (app (app custom_binder (app (app (app (app (const nm us) tp) tc) (var 0)) t))
e@(lam var_name bi var_type body)) :=
contains_illegal_ge_gt e || if nm ∈ illegal_ge_gt then ff else contains_illegal_ge_gt e
| (app f x) := contains_illegal_ge_gt f || contains_illegal_ge_gt x
| (lam `H bi type@(app (app (app (app (const nm us) tp) tc) (var 0)) t) body) :=
contains_illegal_ge_gt body || if nm ∈ illegal_ge_gt then ff else contains_illegal_ge_gt type
| (lam var_name bi var_type body) := contains_illegal_ge_gt var_type || contains_illegal_ge_gt body
| (pi `H bi type@(app (app (app (app (const nm us) tp) tc) (var 0)) t) body) :=
contains_illegal_ge_gt body || if nm ∈ illegal_ge_gt then ff else contains_illegal_ge_gt type
| (pi var_name bi var_type body) := contains_illegal_ge_gt var_type || contains_illegal_ge_gt body
| (elet var_name type assignment body) :=
contains_illegal_ge_gt type || contains_illegal_ge_gt assignment || contains_illegal_ge_gt body
| _ := ff
/-- Checks whether a `>`/`≥` is used in the statement of `d`.
It first does a quick check to see if there is any `≥` or `>` in the statement, and then does a
slower check whether the occurrences of `≥` and `>` are allowed.
Currently it checks only the conclusion of the declaration, to eliminate false positive from
binders such as `∀ ε > 0, ...` -/
private meta def ge_or_gt_in_statement (d : declaration) : tactic (option string) :=
return $ if d.type.contains_constant (λ n, n ∈ illegal_ge_gt) &&
contains_illegal_ge_gt d.type
then some "the type contains ≥/>. Use ≤/< instead."
else none
-- TODO: the commented out code also checks for classicality in statements, but needs fixing
-- TODO: this probably needs to also check whether the argument is a variable or @eq <var> _ _
-- meta def illegal_constants_in_statement (d : declaration) : tactic (option string) :=
-- return $ if d.type.contains_constant (λ n, (n.get_prefix = `classical ∧
-- n.last ∈ ["prop_decidable", "dec", "dec_rel", "dec_eq"]) ∨ n ∈ [`gt, `ge])
-- then
-- let illegal1 := [`classical.prop_decidable, `classical.dec, `classical.dec_rel,
-- `classical.dec_eq],
-- illegal2 := [`gt, `ge],
-- occur1 := illegal1.filter (λ n, d.type.contains_constant (eq n)),
-- occur2 := illegal2.filter (λ n, d.type.contains_constant (eq n)) in
-- some $ sformat!"the type contains the following declarations: {occur1 ++ occur2}." ++
-- (if occur1 = [] then "" else " Add decidability type-class arguments instead.") ++
-- (if occur2 = [] then "" else " Use ≤/< instead.")
-- else none
/-- A linter for checking whether illegal constants (≥, >) appear in a declaration's type. -/
@[linter] meta def linter.ge_or_gt : linter :=
{ test := ge_or_gt_in_statement,
auto_decls := ff,
no_errors_found := "Not using ≥/> in declarations.",
errors_found := "The following declarations use ≥/>, probably in a way where we would prefer
to use ≤/< instead. See note [nolint_ge] for more information.",
is_fast := ff }
/--
Currently, the linter forbids the use of `>` and `≥` in definitions and
statements, as they cause problems in rewrites.
They are still allowed in statements such as `bounded (≥)` or `∀ ε > 0` or `⨆ n ≥ m`,
and the linter allows that.
If you write a pattern where you bind two or more variables, like `∃ n m > 0`, the linter will
flag this as illegal, but it is also allowed. In this case, add the line
```
@[nolint ge_or_gt] -- see Note [nolint_ge]
```
-/
library_note "nolint_ge"
/-!
## Linter for duplicate namespaces
-/
/-- Checks whether a declaration has a namespace twice consecutively in its name -/
private meta def dup_namespace (d : declaration) : tactic (option string) :=
is_instance d.to_name >>= λ is_inst,
return $ let nm := d.to_name.components in if nm.chain' (≠) ∨ is_inst then none
else let s := (nm.find $ λ n, nm.count n ≥ 2).iget.to_string in
some $ "The namespace `" ++ s ++ "` is duplicated in the name"
/-- A linter for checking whether a declaration has a namespace twice consecutively in its name. -/
@[linter] meta def linter.dup_namespace : linter :=
{ test := dup_namespace,
auto_decls := ff,
no_errors_found := "No declarations have a duplicate namespace.",
errors_found := "DUPLICATED NAMESPACES IN NAME:" }
/-!
## Linter for unused arguments
-/
/-- Auxiliary definition for `check_unused_arguments` -/
private meta def check_unused_arguments_aux : list ℕ → ℕ → ℕ → expr → list ℕ | l n n_max e :=
if n > n_max then l else
if ¬ is_lambda e ∧ ¬ is_pi e then l else
let b := e.binding_body in
let l' := if b.has_var_idx 0 then l else n :: l in check_unused_arguments_aux l' (n+1) n_max b
/-- Check which arguments of a declaration are not used.
Prints a list of natural numbers corresponding to which arguments are not used (e.g.
this outputs [1, 4] if the first and fourth arguments are unused).
Checks both the type and the value of `d` for whether the argument is used
(in rare cases an argument is used in the type but not in the value).
We return [] if the declaration was automatically generated.
We print arguments that are larger than the arity of the type of the declaration
(without unfolding definitions). -/
meta def check_unused_arguments (d : declaration) : option (list ℕ) :=
let l := check_unused_arguments_aux [] 1 d.type.pi_arity d.value in
if l = [] then none else
let l2 := check_unused_arguments_aux [] 1 d.type.pi_arity d.type in
(l.filter $ λ n, n ∈ l2).reverse
/-- Check for unused arguments, and print them with their position, variable name, type and whether
the argument is a duplicate.
See also `check_unused_arguments`.
This tactic additionally filters out all unused arguments of type `parse _`. -/
private meta def unused_arguments (d : declaration) : tactic (option string) := do
let ns := check_unused_arguments d,
if ¬ ns.is_some then return none else do
let ns := ns.iget,
(ds, _) ← get_pi_binders d.type,
let ns := ns.map (λ n, (n, (ds.nth $ n - 1).iget)),
let ns := ns.filter (λ x, x.2.type.get_app_fn ≠ const `interactive.parse []),
if ns = [] then return none else do
ds' ← ds.mmap pp,
ns ← ns.mmap (λ ⟨n, b⟩, (λ s, to_fmt "argument " ++ to_fmt n ++ ": " ++ s ++
(if ds.countp (λ b', b.type = b'.type) ≥ 2 then " (duplicate)" else "")) <$> pp b),
return $ some $ ns.to_string_aux tt
/-- A linter object for checking for unused arguments. This is in the default linter set. -/
@[linter] meta def linter.unused_arguments : linter :=
{ test := unused_arguments,
auto_decls := ff,
no_errors_found := "No unused arguments.",
errors_found := "UNUSED ARGUMENTS." }
attribute [nolint unused_arguments] imp_intro
/-!
## Linter for documentation strings
-/
/-- Reports definitions and constants that are missing doc strings -/
private meta def doc_blame_report_defn : declaration → tactic (option string)
| (declaration.defn n _ _ _ _ _) := doc_string n >> return none <|> return "def missing doc string"
| (declaration.cnst n _ _ _) := doc_string n >> return none <|> return "constant missing doc string"
| _ := return none
/-- Reports definitions and constants that are missing doc strings -/
private meta def doc_blame_report_thm : declaration → tactic (option string)
| (declaration.thm n _ _ _) := doc_string n >> return none <|> return "theorem missing doc string"
| _ := return none
/-- A linter for checking definition doc strings -/
@[linter] meta def linter.doc_blame : linter :=
{ test := λ d, mcond (bnot <$> has_attribute' `instance d.to_name)
(doc_blame_report_defn d) (return none),
auto_decls := ff,
no_errors_found := "No definitions are missing documentation.",
errors_found := "DEFINITIONS ARE MISSING DOCUMENTATION STRINGS:" }
/-- A linter for checking theorem doc strings. This is not in the default linter set. -/
meta def linter.doc_blame_thm : linter :=
{ test := doc_blame_report_thm,
auto_decls := ff,
no_errors_found := "No theorems are missing documentation.",
errors_found := "THEOREMS ARE MISSING DOCUMENTATION STRINGS:",
is_fast := ff }
/-!
## Linter for correct usage of `lemma`/`def`
-/
/--
Checks whether the correct declaration constructor (definition or theorem) by
comparing it to its sort. Instances will not be printed.
This test is not very quick: maybe we can speed-up testing that something is a proposition?
This takes almost all of the execution time.
-/
private meta def incorrect_def_lemma (d : declaration) : tactic (option string) :=
if d.is_constant ∨ d.is_axiom
then return none else do
is_instance_d ← is_instance d.to_name,
if is_instance_d then return none else do
-- the following seems to be a little quicker than `is_prop d.type`.
expr.sort n ← infer_type d.type,
is_pattern ← has_attribute' `pattern d.to_name,
return $
if d.is_theorem ↔ n = level.zero then none
else if d.is_theorem then "is a lemma/theorem, should be a def"
else if is_pattern then none -- declarations with `@[pattern]` are allowed to be a `def`.
else "is a def, should be a lemma/theorem"
/-- A linter for checking whether the correct declaration constructor (definition or theorem)
has been used. -/
@[linter] meta def linter.def_lemma : linter :=
{ test := incorrect_def_lemma,
auto_decls := ff,
no_errors_found := "All declarations correctly marked as def/lemma.",
errors_found := "INCORRECT DEF/LEMMA:" }
attribute [nolint def_lemma] classical.dec classical.dec_pred classical.dec_rel classical.dec_eq
/-- Checks whether the statement of a declaration is well-typed. -/
meta def check_type (d : declaration) : tactic (option string) :=
(type_check d.type >> return none) <|> return "The statement doesn't type-check"
/-- A linter for missing checking whether statements of declarations are well-typed. -/
@[linter]
meta def linter.check_type : linter :=
{ test := check_type,
auto_decls := ff,
no_errors_found :=
"The statements of all declarations type-check with default reducibility settings.",
errors_found := "THE STATEMENTS OF THE FOLLOWING DECLARATIONS DO NOT TYPE-CHECK.
Some definitions in the statement are marked `@[irreducible]`, which means that the statement " ++
"is now ill-formed. It is likely that these definitions were locally marked as `@[reducible]` " ++
"or `@[semireducible]`. This can especially cause problems with type class inference or " ++
"`@[simps]`.",
is_fast := tt }
|
a1ed17cf5b2f9a7c1c7145b3169d2ec5545b0737 | 8e2026ac8a0660b5a490dfb895599fb445bb77a0 | /library/init/category/functor.lean | 2a7e2a75a5c76e5c0884c1fc6015b5593147f1f1 | [
"Apache-2.0"
] | permissive | pcmoritz/lean | 6a8575115a724af933678d829b4f791a0cb55beb | 35eba0107e4cc8a52778259bb5392300267bfc29 | refs/heads/master | 1,607,896,326,092 | 1,490,752,175,000 | 1,490,752,175,000 | 86,612,290 | 0 | 0 | null | 1,490,809,641,000 | 1,490,809,641,000 | null | UTF-8 | Lean | false | false | 1,256 | lean | /-
Copyright (c) Luke Nelson and Jared Roesch. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Luke Nelson, Jared Roesch, Sebastian Ullrich
-/
prelude
import init.core init.function init.meta.name
open function
universes u v
section
set_option auto_param.check_exists false
class functor (f : Type u → Type v) : Type (max u+1 v) :=
(map : Π {α β : Type u}, (α → β) → f α → f β)
(infixr ` <$> `:100 := map)
-- ` <$ `
(map_const : Π {α : Type u} (β : Type u), α → f β → f α := λ α β, map ∘ const β)
(map_const_eq : ∀ {α β : Type u}, @map_const α β = map ∘ const β . control_laws_tac)
-- `functor` is indeed a categorical functor
(id_map : Π {α : Type u} (x : f α), id <$> x = x)
(map_comp : Π {α β γ : Type u} (g : α → β) (h : β → γ) (x : f α), (h ∘ g) <$> x = h <$> g <$> x)
end
@[inline] def fmap {f : Type u → Type v} [functor f] {α β : Type u} : (α → β) → f α → f β :=
functor.map
@[inline] def fmap_const {f : Type u → Type v} [functor f] {α : Type u} : Π (β : Type u), α → f β → f α :=
functor.map_const
infixr ` <$> `:100 := fmap
infixr ` <$ `:100 := fmap_const
infixr ` $> `:100 := λ α a b, fmap_const α b a
|
a6ca9950d0e0f91ba0b7beb1fd77e8154afd3c56 | 9ad8d18fbe5f120c22b5e035bc240f711d2cbd7e | /src/data/nat/square_free.lean | be74f25b2fda29348a82c99f6f6fd659e2353483 | [] | no_license | agusakov/lean_lib | c0e9cc29fc7d2518004e224376adeb5e69b5cc1a | f88d162da2f990b87c4d34f5f46bbca2bbc5948e | refs/heads/master | 1,642,141,461,087 | 1,557,395,798,000 | 1,557,395,798,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 6,653 | lean | import data.nat.prime data.multiset
import data.list_extra data.multiset_extra
namespace nat
lemma list.coprime_prod {n : ℕ} {l : list ℕ} (h : list.all_prop (coprime n) l) :
coprime n l.prod :=
begin
induction l with m l ih,
{rw[list.prod_nil],exact coprime_one_right n},
{rw[list.all_prop] at h,rw[list.prod_cons],
exact coprime.mul_right h.left (ih h.right),
}
end
lemma multiset.coprime_prod {n : ℕ} {s : multiset ℕ}
(h : multiset.all_prop (coprime n) s) : coprime n s.prod :=
begin
rcases s with l,
have : quot.mk setoid.r l = (l : multiset ℕ) := rfl, rw[this] at *,
rw[multiset.all_prop_coe] at h,rw[multiset.coe_prod],
exact list.coprime_prod h
end
lemma list.coprime_prod_dvd_of_dvd {l : list ℕ} (hc : l.pairwise coprime)
{n : ℕ} (hd : list.all_prop (λ p, p ∣ n) l) : l.prod ∣ n :=
begin
induction l with m l ih,
{rw[list.prod_nil],exact one_dvd n},
{rw[list.pairwise_cons] at hc,
rw[list.all_prop] at hd,rw[list.prod_cons],
exact coprime.mul_dvd_of_dvd_of_dvd
(list.coprime_prod (list.all_prop_iff.mpr hc.left))
hd.left (ih hc.right hd.right),
}
end
lemma multiset.coprime_prod_dvd_of_dvd {s : multiset ℕ} (hc : s.pairwise coprime)
{n : ℕ} (hd : multiset.all_prop (λ p, p ∣ n) s) : s.prod ∣ n :=
begin
rcases s with l,
have : quot.mk setoid.r l = (l : multiset ℕ) := rfl, rw[this] at *,
have : symmetric coprime := λ n m, coprime.symm,
rw[multiset.pairwise_coe_iff_pairwise this] at hc,
rw[multiset.all_prop_coe] at hd,
rw[multiset.coe_prod],
exact list.coprime_prod_dvd_of_dvd hc hd,
end
lemma list.nodup_prime_coprime
{l : list ℕ} (hd : l.nodup) (hp : list.all_prop nat.prime l) :
l.pairwise coprime :=
begin
let hp' := list.all_prop_iff.mp hp,
apply @list.pairwise.imp_of_mem ℕ ne coprime l _ hd,
{intros p q hpl hql hpq,exact (coprime_primes (hp' p hpl) (hp' q hql)).mpr hpq,},
end
lemma multiset.nodup_prime_coprime
{s : multiset ℕ} (hd : s.nodup) (hp : multiset.all_prop nat.prime s) :
s.pairwise coprime :=
begin
rcases s with l,
have : quot.mk setoid.r l = (l : multiset ℕ) := rfl, rw[this] at *,
rw[multiset.coe_nodup] at hd,
rw[multiset.all_prop_coe] at hp,
have : symmetric coprime := λ n m, coprime.symm,
rw[multiset.pairwise_coe_iff_pairwise this],
exact list.nodup_prime_coprime hd hp,
end
def padic_valuation (p : ℕ) (n : ℕ) : ℕ :=
multiset.count p n.factors
def unique_factors (n : ℕ) :=
(n.factors : multiset ℕ).erase_dup
lemma mem_unique_factors {n : ℕ} (h : n > 0) (p : ℕ) :
p ∈ unique_factors n ↔ p.prime ∧ p ∣ n :=
begin
dsimp[unique_factors],rw[multiset.mem_coe,list.mem_erase_dup],
split,
{intro h0,let h1 := nat.mem_factors h0,
let h2 := (nat.mem_factors_iff_dvd h h1).mp h0,
exact ⟨h1,h2⟩
},{
rintro ⟨h1,h2⟩,exact (nat.mem_factors_iff_dvd h h1).mpr h2,
}
end
lemma unique_factors_coprime (n : ℕ) :
(unique_factors n).pairwise coprime :=
begin
by_cases h : n = 0,
{rw[h],apply multiset.pairwise_zero},
replace h := nat.pos_of_ne_zero h,
apply multiset.nodup_prime_coprime,
{apply multiset.nodup_erase_dup},
{rw[multiset.all_prop_iff],intros p hp,
replace hp := multiset.mem_erase_dup.mp hp,
rw[multiset.mem_coe] at hp,
exact nat.mem_factors hp,
}
end
def prime_power_factors (n : ℕ) :=
(unique_factors n).map (λ p, p ^ (padic_valuation p n))
def prod_factors' (n : ℕ) (h : n > 0) :
(prime_power_factors n).prod = n :=
begin
let f : multiset ℕ := n.factors,
let f₁ := f.erase_dup,
let u := λ p, multiset.prod (multiset.repeat p (multiset.count p f)),
let v := λ p, p ^ (multiset.count p f),
change (f₁.map v).prod = n,
have : v = u := by {ext p,dsimp[u,v],rw[multiset.prod_repeat,nat.pow_eq_pow],},
rw[this],
let e : f.prod = n := by {rw[multiset.coe_prod],exact nat.prod_factors h},
rw[← multiset.eq_repeat_count f,multiset.prod_bind] at e,
exact e,
end
def square_free (n : ℕ) : Prop := ∀ k, (k * k) ∣ (n : ℕ) → k = 1
lemma square_free_iff (n : ℕ) :
square_free n ↔ ∀ p, nat.prime p → ¬ (p * p ∣ n) :=
begin
split,
{intros h p p_prime hp,
exact nat.prime.ne_one p_prime (h p hp),
},{
intros h k hk, by_contradiction hk',
let p := nat.min_fac k,
let p_prime := nat.min_fac_prime hk',
let pp_dvd : p * p ∣ n :=
dvd_trans (mul_dvd_mul k.min_fac_dvd k.min_fac_dvd) hk,
exact (h p p_prime pp_dvd).elim
}
end
def square_free_radical (n : ℕ) : ℕ :=
(n.factors : multiset ℕ).erase_dup.prod
lemma square_free_radical_dvd (n : ℕ) :
(square_free_radical n) ∣ n := begin
by_cases hn : n = 0,
{rw[hn],use 0,rw[mul_zero]},
{
replace hn := nat.pos_of_ne_zero hn,
let fl := n.factors,
let fm : multiset ℕ := fl,
let fs := fm.erase_dup,
let ft := fm - fs,
let hm : fm.prod = n :=
(multiset.coe_prod fl).trans (nat.prod_factors hn),
have : fm = fs + ft :=
(multiset.add_sub_of_le (multiset.erase_dup_le n.factors)).symm,
rw[this,multiset.prod_add] at hm,
use ft.prod,exact hm.symm,
}
end
lemma square_free_radical_primes {n : ℕ} (hn : n > 0)
{p : ℕ} (p_prime : nat.prime p) :
p ∣ (square_free_radical n) ↔ p ∣ n :=
begin
split,
{intro h,exact dvd_trans h (square_free_radical_dvd n)},
{intro p_dvd_n,
let fl := n.factors,
let fm : multiset ℕ := fl,
let fs := fm.erase_dup,
change p ∣ fs.prod,
have : p ∈ fm := (nat.mem_factors_iff_dvd hn p_prime).mpr p_dvd_n,
have : p ∈ fs := multiset.mem_erase_dup.mpr this,
rw[← multiset.cons_erase this,multiset.prod_cons],
apply dvd_mul_right,
}
end
lemma square_free_radical_dvd_iff {n : ℕ} (hn : n > 0) (m : ℕ) :
(square_free_radical n) ∣ m ↔ ∀ p, nat.prime p → p ∣ n → p ∣ m := begin
split,
{intros h p p_prime p_dvd_n,
exact dvd_trans ((square_free_radical_primes hn p_prime).mpr p_dvd_n) h,
},{
intro h,dsimp[square_free_radical],
apply multiset.coprime_prod_dvd_of_dvd (unique_factors_coprime n),
rw[multiset.all_prop_iff],intros p hp,
replace hp := (mem_unique_factors hn p).mp hp,
exact h p hp.left hp.right,
}
end
lemma dvd_square_free_radical {n : ℕ} (hn : n > 0) :
∃ (k : ℕ), n ∣ n.square_free_radical ^ k :=
begin
let f : multiset ℕ := n.factors,
let f₁ := f.erase_dup,
rcases multiset.le_smul_erase_dup f with ⟨k,hk⟩,
use k,change n ∣ f₁.prod ^ k,
let f₂ := add_monoid.smul k f₁, change f ≤ f₂ at hk,
have : f₂.prod = f₁.prod ^ k := by {rw[multiset.prod_smul,nat.pow_eq_pow],},
rw[← this],
have : f.prod = n := by {rw[multiset.coe_prod,nat.prod_factors hn],},
rw[← this,← multiset.add_sub_of_le hk,multiset.prod_add],
apply dvd_mul_right,
end
end nat |
259060e9acc5a77880230bb76e1c9e8f8be0d941 | 9dc8cecdf3c4634764a18254e94d43da07142918 | /counterexamples/homogeneous_prime_not_prime.lean | 9532317504c1c8f898dde5e6a501340d86d2fab4 | [
"Apache-2.0"
] | permissive | jcommelin/mathlib | d8456447c36c176e14d96d9e76f39841f69d2d9b | ee8279351a2e434c2852345c51b728d22af5a156 | refs/heads/master | 1,664,782,136,488 | 1,663,638,983,000 | 1,663,638,983,000 | 132,563,656 | 0 | 0 | Apache-2.0 | 1,663,599,929,000 | 1,525,760,539,000 | Lean | UTF-8 | Lean | false | false | 5,645 | lean | /-
Copyright (c) 2022 Jujian Zhang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin, Eric Wieser, Jujian Zhang
-/
import ring_theory.graded_algebra.homogeneous_ideal
import data.zmod.basic
import tactic.derive_fintype
/-!
# A homogeneous prime that is homogeneously prime but not prime
In `src/ring_theory/graded_algebra/radical.lean`, we assumed that the underline grading is indexed
by a `linear_ordered_cancel_add_comm_monoid` to prove that a homogeneous ideal is prime if and only
if it is homogeneously prime. This file is aimed to show that even if this assumption isn't strictly
necessary, the assumption of "being cancellative" is. We construct a counterexample where the
underlying indexing set is a `linear_ordered_add_comm_monoid` but is not cancellative and the
statement is false.
We achieve this by considering the ring `R=ℤ/4ℤ`. We first give the two element set `ι = {0, 1}` a
structure of linear ordered additive commutative monoid by setting `0 + 0 = 0` and `_ + _ = 1` and
`0 < 1`. Then we use `ι` to grade `R²` by setting `{(a, a) | a ∈ R}` to have grade `0`; and
`{(0, b) | b ∈ R}` to have grade 1. Then the ideal `I = span {(0, 2)} ⊆ ℤ/4ℤ` is homogeneous and not
prime. But it is homogeneously prime, i.e. if `(a, b), (c, d)` are two homogeneous elements then
`(a, b) * (c, d) ∈ I` implies either `(a, b) ∈ I` or `(c, d) ∈ I`.
## Tags
homogeneous, prime
-/
namespace counterexample_not_prime_but_homogeneous_prime
open direct_sum
local attribute [reducible] with_zero
abbreviation two := with_zero unit
instance : linear_ordered_add_comm_monoid two :=
{ add_le_add_left := by delta two with_zero; dec_trivial,
..(_ : linear_order two),
..(_ : add_comm_monoid two)}
section
variables (R : Type*) [comm_ring R]
/-- The grade 0 part of `R²` is `{(a, a) | a ∈ R}`. -/
def submodule_z : submodule R (R × R) :=
{ carrier := { zz | zz.1 = zz.2 },
zero_mem' := rfl,
add_mem' := λ a b ha hb, congr_arg2 (+) ha hb,
smul_mem' := λ a b hb, congr_arg ((*) a) hb }
/-- The grade 1 part of `R²` is `{(0, b) | b ∈ R}`. -/
def submodule_o : submodule R (R × R) := (linear_map.fst R R R).ker
/-- Given the above grading (see `submodule_z` and `submodule_o`),
we turn `R²` into a graded ring. -/
def grading : two → submodule R (R × R)
| 0 := submodule_z R
| 1 := submodule_o R
lemma grading.one_mem : (1 : (R × R)) ∈ grading R 0 :=
eq.refl (1, 1).fst
lemma grading.mul_mem : ∀ ⦃i j : two⦄ {a b : (R × R)} (ha : a ∈ grading R i) (hb : b ∈ grading R j),
a * b ∈ grading R (i + j)
| 0 0 a b (ha : a.1 = a.2) (hb : b.1 = b.2) := show a.1 * b.1 = a.2 * b.2, by rw [ha, hb]
| 0 1 a b (ha : a.1 = a.2) (hb : b.1 = 0) := show a.1 * b.1 = 0, by rw [hb, mul_zero]
| 1 0 a b (ha : a.1 = 0) hb := show a.1 * b.1 = 0, by rw [ha, zero_mul]
| 1 1 a b (ha : a.1 = 0) hb := show a.1 * b.1 = 0, by rw [ha, zero_mul]
end
notation `R` := zmod 4
/-- `R² ≅ {(a, a) | a ∈ R} ⨁ {(0, b) | b ∈ R}` by `(x, y) ↦ (x, x) + (0, y - x)`. -/
def grading.decompose : (R × R) →+ direct_sum two (λ i, grading R i) :=
{ to_fun := λ zz, of (λ i, grading R i) 0 ⟨(zz.1, zz.1), rfl⟩ +
of (λ i, grading R i) 1 ⟨(0, zz.2 - zz.1), rfl⟩,
map_zero' := by { ext1 (_|⟨⟨⟩⟩); refl },
map_add' := begin
rintros ⟨a1, b1⟩ ⟨a2, b2⟩,
rw [add_add_add_comm, ←map_add, ←map_add],
dsimp only [prod.mk_add_mk],
simp_rw [add_sub_add_comm],
congr,
end }
lemma grading.right_inv :
function.right_inverse (coe_linear_map (grading R)) grading.decompose := λ zz,
begin
induction zz using direct_sum.induction_on with i zz d1 d2 ih1 ih2,
{ simp only [map_zero],},
{ rcases i with (_|⟨⟨⟩⟩); rcases zz with ⟨⟨a, b⟩, (hab : _ = _)⟩;
dsimp at hab; cases hab; dec_trivial! },
{ simp only [map_add, ih1, ih2], },
end
lemma grading.left_inv :
function.left_inverse (coe_linear_map (grading R)) grading.decompose := λ zz,
begin
cases zz with a b,
unfold grading.decompose,
simp only [add_monoid_hom.coe_mk, map_add, coe_linear_map_of, subtype.coe_mk, prod.mk_add_mk,
add_zero, add_sub_cancel'_right],
end
instance : graded_algebra (grading R) :=
{ one_mem := grading.one_mem R,
mul_mem := grading.mul_mem R,
decompose' := grading.decompose,
left_inv := by { convert grading.left_inv, },
right_inv := by { convert grading.right_inv, } }
/-- The counterexample is the ideal `I = span {(2, 2)}`. -/
def I : ideal (R × R) := ideal.span {((2, 2) : (R × R))}.
set_option class.instance_max_depth 33
lemma I_not_prime : ¬ I.is_prime :=
begin
rintro ⟨rid1, rid2⟩,
apply rid1, clear rid1, revert rid2,
simp only [I, ideal.mem_span_singleton, ideal.eq_top_iff_one],
dec_trivial, -- this is what we change the max instance depth for, it's only 1 above the default
end
set_option class.instance_max_depth 32
lemma I_is_homogeneous : I.is_homogeneous (grading R) :=
begin
rw ideal.is_homogeneous.iff_exists,
refine ⟨{⟨(2, 2), ⟨0, rfl⟩⟩}, _⟩,
rw set.image_singleton,
refl,
end
lemma homogeneous_mem_or_mem {x y : (R × R)} (hx : set_like.is_homogeneous (grading R) x)
(hy : set_like.is_homogeneous (grading R) y)
(hxy : x * y ∈ I) : x ∈ I ∨ y ∈ I :=
begin
simp only [I, ideal.mem_span_singleton] at hxy ⊢,
cases x, cases y,
obtain ⟨(_|⟨⟨⟩⟩), hx : _ = _⟩ := hx;
obtain ⟨(_|⟨⟨⟩⟩), hy : _ = _⟩ := hy;
dsimp at hx hy;
cases hx; cases hy; clear hx hy;
dec_trivial!,
end
end counterexample_not_prime_but_homogeneous_prime
|
e44ef9b563a27302d1db2034fca05c428ab251f1 | cc104245380aa3287223e0e350a8319e583aba37 | /src/h1.lean | 328a23be2b34218cc24320a2ce469138753382ad | [] | no_license | anca797/group-cohomology | 7d10749d28430d30698e7ec0cc33adbac97fe5e7 | f896dfa5057bd70c6fbb09ee6fdc26a7ffab5e5d | refs/heads/master | 1,591,037,800,699 | 1,561,424,571,000 | 1,561,424,571,000 | 190,891,710 | 3 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 22,655 | lean | import h0
import group_theory.quotient_group
theorem function.lift_aux {X : Type*} {Y : Type*} {Z : Type*} (f : X → Y)
(i : Z → Y) (h2 : set.range f ⊆ set.range i) (x : X) : ∃ z : Z, i z = f x :=
begin
show f x ∈ set.range i,
apply h2,
use x,
end
noncomputable def function.lift {X : Type*} {Y : Type*} {Z : Type*} (f : X → Y)
(i : Z → Y) (h2 : set.range f ⊆ set.range i) :
(X → Z) :=
λ x, classical.some $ function.lift_aux f i h2 x
theorem function.lift_eq {X : Type*} {Y : Type*} {Z : Type*} (f : X → Y)
(i : Z → Y) (h2 : set.range f ⊆ set.range i) (x : X) :
i (function.lift f i h2 x) = f x := classical.some_spec $ function.lift_aux f i h2 x
variables (G : Type*) [group G] (M : Type*) [add_comm_group M]
[G_module G M]
-- definition of cocycle as a subtype
def cocycle (G : Type*) [group G] (M : Type*) [add_comm_group M] [G_module G M] :=
{f : G → M // ∀ g h : G, f (g * h) = f g + g • (f h)}
variable {G} -- I want G to be implicit in this definition
-- so a cocycle is a pair: the function f, and the proof that it satisfies the cocycle identity.
-- This line lets us think about a cocycle as the function.
instance : has_coe_to_fun (cocycle G M) :=
{ F := λ _, G → M,
coe := λ f, f.1}
theorem cocycle.eq (e f : cocycle G M) : (e : G → M) = f → e = f := subtype.eq
@[simp] def cocycle.condition (f : cocycle G M) : ∀ (g h : G), f (g * h) = f g + g • (f h) :=
f.property
namespace cocycle
variable {M}
def mk (m : M) : (cocycle G M) := ⟨λ g, g • m - m,
begin
intros g h,
rw ←G_module.mul,
rw G_module.map_sub,
simp,
end ⟩
variable (M)
/-- The zero cocycle -/
def zero : cocycle G M := ⟨λ g, 0, begin
intro g,
intro h,
symmetry,
calc
0 + g • (0 : M) = g • 0 : zero_add _
... = 0 : g_zero g
end⟩
-- notation
instance : has_zero (cocycle G M) := ⟨zero M⟩
/-- addition of cocycles -/
def add (e f : cocycle G M) : cocycle G M :=
⟨λ g, e g + f g, begin
intro g,
intro h,
rw cocycle.condition M e,
rw cocycle.condition M f,
rw G_module.linear g (e h) (f h),
simp,
/-
calc
e (g * h) + f (g * h) = e g + g • (e h) + f (g * h) : rw e.condition g h
... = e g + g • (e h) + (f g + g • (f h)) : rw f.condition g h
... = e g + g • (e h) + g • (f h) + f g : by simp?
... = e g + g • (e h + f h) + f g : by rw G_module.linear g (e h) (f h)
... = e g + f g + g • (e h + f h) : by add_comm
-/
end⟩
-- notation
instance : has_add (cocycle G M) := ⟨add M⟩
@[simp] lemma cocycle.cast_add (a b : cocycle G M) (x : G) : ((a+b) x = a x + b x) :=
begin
refl,
end
/-- negation of a cocycle -/
def neg (f : cocycle G M) : cocycle G M :=
⟨λ g, -(f g), begin
intro g,
intro h,
rw cocycle.condition M f,
rw neg_add,
rw g_neg g (f h),
/-
calc
- f (g * h) = - (f g + g • (f h)) : rw f.condition g h
... = - f g - g • (f h) :
... = - f g + g (- f h) : by rw g_neg g (f h)
-/
end⟩
-- notation
instance : has_neg (cocycle G M) := ⟨neg M⟩
-- proof that cocycles form a group
instance : add_comm_group (cocycle G M) :=
{ add := (+),
add_assoc := begin
intros a b c,
apply cocycle.eq,
ext x,
simp,
end,
zero := 0,
zero_add := begin
intro a,
apply cocycle.eq,
ext x,
simp,
change a x + 0 = a x,
rw add_zero,
end,
add_zero := begin
intro a,
apply cocycle.eq,
ext x,
change a x + 0 = a x,
rw add_zero,
end,
neg := has_neg.neg,
add_left_neg := begin
intro a,
show -a + a = 0,
apply cocycle.eq,
ext x,
change - a x + a x = 0,
simp,
end,
add_comm := begin
intros a b,
apply cocycle.eq,
ext x,
change a x + b x = b x + a x,
rw add_comm,
end }
def map (G : Type*) [group G]
{A : Type*} [add_comm_group A] [G_module G A]
{B : Type*} [add_comm_group B] [G_module G B]
(f : A → B) [G_module_hom G f] :
cocycle G A → cocycle G B :=
λ c, ⟨λ g, f (c g), begin
intros g h,
rw cocycle.condition A c,
rw G_module_hom.add G f (c g) (g • (c h)),
rw G_module_hom.G_hom f g,
end⟩
noncomputable def lift (G : Type*) [group G]
{A : Type*} [add_comm_group A] [G_module G A]
{B : Type*} [add_comm_group B] [G_module G B]
(f : A → B) [G_module_hom G f] (hf : function.injective f)
(x : cocycle G B) (h : set.range x ⊆ set.range f) : (cocycle G A) :=
⟨function.lift x f h, begin
intros g1 g2,
apply hf,
rw function.lift_eq x f,
rw is_add_group_hom.map_add f,
rw function.lift_eq x f,
rw G_module_hom.G_hom f,
rw function.lift_eq x f,
exact x.property g1 g2,
apply_instance,
end⟩
theorem lift_eq (G : Type*) [group G]
{A : Type*} [add_comm_group A] [G_module G A]
{B : Type*} [add_comm_group B] [G_module G B]
(f : A → B) [G_module_hom G f] (hf : function.injective f)
(x : cocycle G B) (h : set.range x ⊆ set.range f) :
(map G f (lift G f hf x h)) = x :=
begin
apply cocycle.eq,
ext g,
show f (function.lift (x) f h g) = x g,
rw function.lift_eq x f,
end
end cocycle
def coboundary (G : Type*) [group G] (M : Type*) [add_comm_group M] [G_module G M] :=
{f : cocycle G M | ∃ m : M, ∀ g : G, f g = g • m - m}
instance : is_add_subgroup (coboundary G M) :=
{ zero_mem := begin
use 0,
intro g,
rw g_zero g,
simp,
refl,
end,
add_mem := begin
intros a b,
intros ha hb,
cases ha with m hm,
cases hb with n hn,
use m+n,
simp [hm, hn],
end,
neg_mem := begin
intro a,
intro ha,
cases ha with m hm,
use -m,
intro g,
show - a g = _,
simp [hm],
rw g_neg g,
end }
def H1 (G : Type*) [group G] (M : Type*) [add_comm_group M] [G_module G M] :=
quotient_add_group.quotient (coboundary G M)
instance (G : Type*) [group G] (M : Type*) [add_comm_group M] [G_module G M]
: add_comm_group (H1 G M)
:= quotient_add_group.add_comm_group (coboundary G M)
lemma coboundary.map (G : Type*) [group G]
{A : Type*} [add_comm_group A] [G_module G A]
{B : Type*} [add_comm_group B] [G_module G B]
(f : A → B) [G_module_hom G f] (c : cocycle G A) :
c ∈ coboundary G A → cocycle.map G f c ∈ coboundary G B :=
begin
intro hc,
cases hc with m hm,
use f m,
change ∀ (g : G), f (c g) = g • f m - f m,
intro g,
rw hm,
simp,
rw [G_module_hom.add G f (-m) (g • m), G_module_hom.G_hom f g, is_add_group_hom.map_neg f m],
end
/-
bad lean:
unfold coe_fn has_coe_to_fun.coe,
unfold cocycle.map,
dsimp,
unfold coe_fn has_coe_to_fun.coe,
dsimp,
I also used set_option pp.notation false (temporarily) because
I couldn't remember what the actual function name was for the notation ⇑.
in the main Lean window, if you type #print notation ⇑ it tells you the name
of the function, and if you hover over the ⇑ it tells you the keyboard shortcut.
-/
instance (G : Type*) [group G]
{A : Type*} [add_comm_group A] [G_module G A]
{B : Type*} [add_comm_group B] [G_module G B]
(f : A → B) [G_module_hom G f] :
is_add_group_hom (cocycle.map G f) :=
{ map_add := begin
intros a b,
show cocycle.map G f (a + b) = (cocycle.map G f a) + (cocycle.map G f b),
cases a with a ha,
cases b with b hb,
apply cocycle.eq,
ext g,
show f (a g + b g) = f (a g) + f (b g),
rw G_module_hom.add G f (a g) (b g),
end }
--variables
-- {A : Type*} [add_comm_group A] [G_module G A]
-- {B : Type*} [add_comm_group B] [G_module G B]
instance : normal_add_subgroup (coboundary G M) := normal_add_subgroup_of_add_comm_group (coboundary G M)
def H1_f (G : Type*) [group G]
{A : Type*} [add_comm_group A] [G_module G A]
{B : Type*} [add_comm_group B] [G_module G B]
(f : A → B) [G_module_hom G f] :
H1 G A → H1 G B := quotient_add_group.map (coboundary G A) (coboundary G B)
(cocycle.map G f) (coboundary.map G f)
lemma cocycle.map_mk (G : Type*) [group G]
{A : Type*} [add_comm_group A] [G_module G A]
{B : Type*} [add_comm_group B] [G_module G B]
(f : A → B) [G_module_hom G f] (ca : cocycle G A) :
H1_f G f (quotient_add_group.mk ca) = quotient_add_group.mk (cocycle.map G f ca) := rfl
instance (G : Type*) [group G]
{A : Type*} [add_comm_group A] [G_module G A]
{B : Type*} [add_comm_group B] [G_module G B]
(f : A → B) [G_module_hom G f] :
is_add_group_hom (H1_f G f) := quotient_add_group.map_is_add_group_hom
(coboundary G A) (coboundary G B) (cocycle.map G f) (coboundary.map G f)
open set function is_add_group_hom
/- First attempt of delta
noncomputable def delta (G : Type*) [group G]
{A : Type*} [add_comm_group A] [G_module G A]
{B : Type*} [add_comm_group B] [G_module G B]
{C : Type*} [add_comm_group C] [G_module G C]
(f : A → B) [G_module_hom G f]
(g : B → C) [G_module_hom G g]
(hfg : short_exact f g) : H0 G C → H1 G A :=
λ c, begin
rcases hfg with ⟨hf, hg, hfg⟩,
choose b hb using (hg c.val),
apply quotient.mk,
let h : G → A,
{ intro γ,
let b' := γ • b - b,
have hb' : b' ∈ ker g,
{ rw mem_ker,
rw is_add_group_hom.map_sub g,
rw sub_eq_zero,
rw G_module_hom.G_hom g,
rw hb,
exact c.property γ,
apply_instance,
},
change set.range f = ker g at hfg,
rw ←hfg at hb',
choose a ha using hb',
exact a
},
use h,
sorry -- TODO (KMB will try this)
end
-/
noncomputable def delta_b (G : Type*) [group G]
{B : Type*} [add_comm_group B] [G_module G B]
{C : Type*} [add_comm_group C] [G_module G C]
{g : B → C} [G_module_hom G g]
(hg : surjective g) : H0 G C → B :=
λ c, classical.some (hg c.val)
lemma delta_im_b (G : Type*) [group G]
{B : Type*} [add_comm_group B] [G_module G B]
{C : Type*} [add_comm_group C] [G_module G C]
{g : B → C} [G_module_hom G g]
(hg : surjective g) (c : H0 G C) :
g (delta_b G hg c) = c.val := classical.some_spec (hg c.val)
/- c1,c2 : H0 G C then delta_b(c1) + delta_b(c2) - delta_b(c1+c2) is in ker g-/
lemma delta_mem_ker (G : Type*) [group G]
{B : Type*} [add_comm_group B] [G_module G B]
{C : Type*} [add_comm_group C] [G_module G C]
{g : B → C} [G_module_hom G g]
(hg : surjective g) (c1 c2 : H0 G C) :
delta_b G hg c1 + delta_b G hg c2 - delta_b G hg (c1+c2) ∈ ker g :=
begin
rw mem_ker,
rw is_add_group_hom.map_sub g,
rw is_add_group_hom.map_add g,
rw delta_im_b G hg,
rw delta_im_b G hg,
rw delta_im_b G hg,
cases c1 with c1 h1,
cases c2 with c2 h2,
show c1 + c2 - (c1 + c2) = 0,
simp,
end
lemma delta_gb_sub_b_mem_ker (G : Type*) [group G]
{B : Type*} [add_comm_group B] [G_module G B]
{C : Type*} [add_comm_group C] [G_module G C]
{g : B → C} [G_module_hom G g]
(hg : surjective g) (c : H0 G C) (γ : G) :
γ • (delta_b G hg c) - (delta_b G hg c) ∈ ker g :=
by rw [mem_ker, is_add_group_hom.map_sub g, sub_eq_zero,
G_module_hom.G_hom g γ, delta_im_b G hg c, c.property γ]
def delta_cocycle_ex_a (G : Type*) [group G]
{A : Type*} [add_comm_group A] [G_module G A]
{B : Type*} [add_comm_group B] [G_module G B]
{C : Type*} [add_comm_group C] [G_module G C]
{f : A → B} [G_module_hom G f]
{g : B → C} [G_module_hom G g]
(hg : surjective g) (hfg : range f = ker g)
(c : H0 G C) (γ : G) :
∃ a : A, f a = γ • (delta_b G hg c) - (delta_b G hg c) :=
begin
show γ • (delta_b G hg c) - (delta_b G hg c) ∈ range f,
rw hfg,
exact delta_gb_sub_b_mem_ker G hg c γ
end
noncomputable def delta_cocycle_aux (G : Type*) [group G]
{A : Type*} [add_comm_group A] [G_module G A]
{B : Type*} [add_comm_group B] [G_module G B]
{C : Type*} [add_comm_group C] [G_module G C]
{f : A → B} [G_module_hom G f]
{g : B → C} [G_module_hom G g]
(hg : surjective g) (hfg : range f = ker g)
(c : H0 G C) : G → A :=
λ γ, classical.some (delta_cocycle_ex_a G hg hfg c γ)
lemma delta_cocycle_aux_a (G : Type*) [group G]
{A : Type*} [add_comm_group A] [G_module G A]
{B : Type*} [add_comm_group B] [G_module G B]
{C : Type*} [add_comm_group C] [G_module G C]
{f : A → B} [G_module_hom G f]
{g : B → C} [G_module_hom G g]
(hg : surjective g) (hfg : range f = ker g)
(c : H0 G C) (γ : G) : f (delta_cocycle_aux G hg hfg c γ) =
γ • (delta_b G hg c) - (delta_b G hg c) :=
classical.some_spec (delta_cocycle_ex_a G hg hfg c γ)
noncomputable def delta_cocycle (G : Type*) [group G]
{A : Type*} [add_comm_group A] [G_module G A]
{B : Type*} [add_comm_group B] [G_module G B]
{C : Type*} [add_comm_group C] [G_module G C]
{f : A → B} [G_module_hom G f]
{g : B → C} [G_module_hom G g]
(hf : injective f)
(hg : surjective g) (hfg : range f = ker g)
(c : H0 G C) : cocycle G A :=
⟨delta_cocycle_aux G hg hfg c,
begin
intros γ1 γ2,
apply hf,
rw delta_cocycle_aux_a G hg hfg,
rw is_add_group_hom.map_add f,
rw delta_cocycle_aux_a G hg hfg,
rw G_module_hom.G_hom f γ1,
rw delta_cocycle_aux_a G hg hfg,
rw ←G_module.mul,
rw G_module.map_sub,
simp,
end⟩
noncomputable def delta (G : Type*) [group G]
{A : Type*} [add_comm_group A] [G_module G A]
{B : Type*} [add_comm_group B] [G_module G B]
{C : Type*} [add_comm_group C] [G_module G C]
{f : A → B} [G_module_hom G f]
{g : B → C} [G_module_hom G g]
(hf : injective f)
(hg : surjective g) (hfg : range f = ker g)
(c : H0 G C) : H1 G A :=
quotient_add_group.mk (delta_cocycle G hf hg hfg c)
instance
(G : Type*) [group G]
{A : Type*} [add_comm_group A] [G_module G A]
{B : Type*} [add_comm_group B] [G_module G B]
{C : Type*} [add_comm_group C] [G_module G C]
{f : A → B} [G_module_hom G f]
{g : B → C} [G_module_hom G g]
(hf : injective f)
(hg : surjective g) (hfg : range f = ker g)
: is_add_group_hom (delta G hf hg hfg) :=
{ map_add :=
begin
intros a b,
show delta G hf hg hfg (a + b) = (delta G hf hg hfg a) + (delta G hf hg hfg b),
unfold delta,
let Q := (quotient_add_group.mk : cocycle G A → H1 G A),
rw ←is_add_group_hom.map_add Q,
have eq' : ∀ x y : cocycle G A, Q x = Q y ↔ -x + y ∈ coboundary G A := λ x y, quotient_add_group.eq,
show Q (delta_cocycle G hf hg hfg (a+b)) = _,
rw eq',
have h := delta_mem_ker G hg a b,
rw ←hfg at h,
cases h with a' ha',
use a',
intro g,
apply hf,
rw is_add_group_hom.map_sub f,
rw G_module_hom.G_hom f g,
rw ha',
cases a with a ha,
cases b with b hb,
show f
(-delta_cocycle_aux G hg hfg ⟨a + b, _⟩ g +
(delta_cocycle_aux G hg hfg ⟨a, ha⟩ g
+ delta_cocycle_aux G hg hfg ⟨b, hb⟩
g)) = _,
rw is_add_group_hom.map_add f,
rw is_add_group_hom.map_add f,
rw is_add_group_hom.map_neg f,
rw delta_cocycle_aux_a G hg hfg,
rw delta_cocycle_aux_a G hg hfg,
rw delta_cocycle_aux_a G hg hfg,
simp,
rw g_neg,
refl,
end }
/- H0(G,B) -> H0(G,C) -> H1(G,A) -/
lemma h0b_hoc_h1a_exact (G : Type*) [group G]
{A : Type*} [add_comm_group A] [G_module G A]
{B : Type*} [add_comm_group B] [G_module G B]
{C : Type*} [add_comm_group C] [G_module G C]
{f : A → B} [G_module_hom G f]
{g : B → C} [G_module_hom G g]
(hf : injective f)
(hg : surjective g) (hfg : range f = ker g)
: is_exact (H0_f G g) (delta G hf hg hfg) :=
begin
apply subset.antisymm,
{ intros fc h,
rw mem_ker,
cases h with b hb,
cases fc with c fc,
cases b with b propb,
injection hb,
change g b = c at h_1,
unfold delta,
suffices : delta_cocycle G hf hg hfg ⟨c, fc⟩ ∈ ker (quotient_add_group.mk),
rw mem_ker at this,
exact this,
swap, apply_instance,
swap, apply_instance,
rw quotient_add_group.ker_mk,
let b' : B := delta_b G hg ⟨c, fc⟩,
have hb' : b' - b ∈ range f,
have hb'' : b' - b ∈ ker g,
rw mem_ker,
rw is_add_group_hom.map_sub g,
rw delta_im_b G hg ⟨c, fc⟩,
simp,
rw h_1,
simp,
rw hfg,
exact hb'',
cases hb' with a ha,
unfold delta_cocycle,
use a,
intro γ,
apply hf,
rw is_add_group_hom.map_sub f,
rw G_module_hom.G_hom f,
swap, apply_instance,
swap, apply_instance,
show f (delta_cocycle_aux G hg hfg ⟨c, fc⟩ γ) = _,
rw delta_cocycle_aux_a G hg hfg ⟨c, fc⟩ γ,
rw ha,
rw G_module.map_sub,
change γ • b' - b' = γ • b' - γ • b - (b' - b),
rw propb,
simp,
},
{ intros x h,
cases x with c fc,
rw mem_ker at h,
unfold delta at h,
replace h := (mem_ker quotient_add_group.mk).2 h,
rw quotient_add_group.ker_mk (coboundary G A) at h,
cases h with a ha,
let b' : B := delta_b G hg ⟨c, fc⟩,
let b : B := f a,
use b'-b,
intro γ,
have h1 := ha γ,
have h2 := congr_arg f h1,
change f (delta_cocycle_aux G hg hfg ⟨c, fc⟩ γ) = _ at h2,
rw delta_cocycle_aux_a G hg hfg ⟨c, fc⟩ γ at h2,
change γ • b' - b' = _ at h2,
rw is_add_group_hom.map_sub f at h2,
rw G_module_hom.G_hom f at h2,
change γ • b' - b' = γ • b - b at h2,
rw ←sub_eq_zero at h2,
rw G_module.map_sub,
rw ←sub_eq_zero,
swap,
apply_instance,
swap,
apply subtype.eq,
unfold H0_f,
show g (b' - b) = c,
rw is_add_group_hom.map_sub g,
show g (delta_b G hg ⟨c, fc⟩) - g b = _,
rw delta_im_b G hg ⟨c, fc⟩,
have hb' : b ∈ range f,
use a,
have hb : b ∈ ker g,
rw ←hfg,
exact hb',
rw mem_ker at hb,
show c - g b = c,
rw hb,
simp,
rw ←sub_add,
rw ←sub_add at h2,
rw add_comm (γ • b' - γ • b - b') b,
rw add_comm (γ • b' - b' - γ • b) b at h2,
rw ←sub_add_eq_sub_sub_swap (γ • b') b' (γ • b),
rw ←neg_neg (γ • b),
change b + (γ • b' - (b' - (-(γ • b)))) = 0,
rw ←sub_add,
exact h2,
},
end
/- H0(G,C) -> H1(G,A) -> H1(G,B) -/
lemma h0c_h1a_h1b_exact (G : Type*) [group G]
{A : Type*} [add_comm_group A] [G_module G A]
{B : Type*} [add_comm_group B] [G_module G B]
{C : Type*} [add_comm_group C] [G_module G C]
{f : A → B} [G_module_hom G f]
{g : B → C} [G_module_hom G g]
(hf : injective f)
(hg : surjective g) (hfg : range f = ker g)
: is_exact (delta G hf hg hfg) (H1_f G f) :=
begin
apply subset.antisymm,
{ intros fa h,
rw mem_ker,
cases h with c hc,
rw ←hc,
unfold delta,
rw cocycle.map_mk G f (delta_cocycle G hf hg hfg c),
suffices : (cocycle.map G f (delta_cocycle G hf hg hfg c)) ∈ ker (quotient_add_group.mk),
rw mem_ker at this,
exact this,
swap, apply_instance,
swap, apply_instance,
rw quotient_add_group.ker_mk,
use (delta_b G hg c),
intro γ,
change f (delta_cocycle_aux G hg hfg c γ) = _,
exact delta_cocycle_aux_a G hg hfg c γ,
},
{ intros x h,
rw mem_ker at h,
induction x,
swap,
refl,
unfold H1_f at h,
change quotient_add_group.mk (cocycle.map G f x) = 0 at h,
rw ←mem_ker quotient_add_group.mk at h,
swap,
apply_instance,
swap,
apply_instance,
rw quotient_add_group.ker_mk at h,
cases h with b hb,
change ∀ (g : G), f (x g) = g • b - b at hb,
let c : C := g b,
use c,
intro γ,
rw ←sub_eq_zero,
rw ←G_module_hom.G_hom g,
rw ←is_add_group_hom.map_sub g,
rw ←mem_ker g,
rw ←hfg,
rw ←hb,
use x γ,
apply_instance,
change delta G hf hg hfg ⟨c, _⟩ = quotient_add_group.mk x,
unfold delta,
apply quotient_add_group.eq.2,
have hc : ∀ γ : G, γ • c = c,
intro γ,
rw ←sub_eq_zero,
change γ • g b - g b = 0,
rw ←G_module_hom.G_hom g,
rw ←is_add_group_hom.map_sub g,
rw ←mem_ker g,
have h1 : γ • b - b ∈ range f,
rw ←hb,
use x γ,
convert h1,
exact hfg.symm,
apply_instance,
let b' : B := delta_b G hg ⟨c, hc⟩,
have hb' : b - b' ∈ range f,
have hb'' : b - b' ∈ ker g,
rw mem_ker,
rw is_add_group_hom.map_sub g,
rw delta_im_b G hg ⟨c, hc⟩,
simp,
rw hfg,
exact hb'',
cases hb' with a ha,
use a,
intro g',
change - (delta_cocycle_aux G hg hfg ⟨c, hc⟩ g') + x g' = g' • a - a,
apply hf,
rw is_add_group_hom.map_add f,
rw is_add_group_hom.map_neg f,
rw is_add_group_hom.map_sub f,
rw G_module_hom.G_hom f,
rw delta_cocycle_aux_a G hg hfg ⟨c, hc⟩ g',
rw hb,
rw ha,
change - (g' • b' - b') + (g' • b - b) = _,
rw G_module.map_sub,
simp,
apply_instance,
},
end
/- H1(G,A) -> H1(G,B) -> H1(G,C) -/
lemma h1a_h1b_h1c_exact (G : Type*) [group G]
{A : Type*} [add_comm_group A] [G_module G A]
{B : Type*} [add_comm_group B] [G_module G B]
{C : Type*} [add_comm_group C] [G_module G C]
{f : A → B} [G_module_hom G f]
{g : B → C} [G_module_hom G g]
(hf : injective f)
(hg : surjective g) (hfg : range f = ker g)
: is_exact (H1_f G f) (H1_f G g) :=
begin
apply subset.antisymm,
{ intros fb h,
rw mem_ker,
cases h with fa hfa,
induction fa,
swap,
refl,
change H1_f G f (quotient_add_group.mk fa) = _ at hfa,
rw ←hfa,
rw cocycle.map_mk G f fa,
rw cocycle.map_mk G g,
suffices : (cocycle.map G g (cocycle.map G f fa)) ∈ ker (quotient_add_group.mk),
rw mem_ker at this,
exact this,
swap, apply_instance,
swap, apply_instance,
rw quotient_add_group.ker_mk,
use 0,
intro x,
cases fa with fa pfa,
show g (f (fa x)) = _,
rw g_zero,
rw sub_zero,
rw ←mem_ker g,
rw ←hfg,
use fa x,
},
{ intros x h,
induction x,
swap,
refl,
rw mem_ker at h,
unfold H1_f at h,
change quotient_add_group.mk (cocycle.map G g x) = 0 at h,
rw ←mem_ker quotient_add_group.mk at h,
swap,
apply_instance,
swap,
apply_instance,
rw quotient_add_group.ker_mk at h,
cases h with c hc,
rcases (hg c) with ⟨b, rfl⟩,
let y := x - cocycle.mk b,
have hy : range y ⊆ range f,
{
rintros b' ⟨γ, rfl⟩,
rw hfg,
rw mem_ker,
change g ( x γ - (γ • b - b)) = 0,
rw is_add_group_hom.map_sub g,
rw sub_eq_zero,
convert hc γ,
rw is_add_group_hom.map_sub g,
congr',
rw G_module_hom.G_hom g,
apply_instance,
},
let z : cocycle G A := cocycle.lift G f hf y hy,
use quotient_add_group.mk z,
change quotient_add_group.mk (cocycle.map G f (cocycle.lift G f hf y hy)) = quotient_add_group.mk x,
rw cocycle.lift_eq,
apply quotient_add_group.eq.2,
use b,
have hb : -y + x = cocycle.mk b,
{
show -(x - cocycle.mk b) + x = _,
simp,
},
intro g',
rw hb,
refl,
},
end
|
28a993ba8beaf7c15b013c85dda6b58762e4e0e0 | f57749ca63d6416f807b770f67559503fdb21001 | /library/data/nat/bigops.lean | 58e90b2345b412d9cc5450111e74780c5f61e9bd | [
"Apache-2.0"
] | permissive | aliassaf/lean | bd54e85bed07b1ff6f01396551867b2677cbc6ac | f9b069b6a50756588b309b3d716c447004203152 | refs/heads/master | 1,610,982,152,948 | 1,438,916,029,000 | 1,438,916,029,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 5,066 | lean | /-
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Jeremy Avigad
Finite products and sums on the natural numbers.
-/
import data.nat.basic data.nat.order algebra.group_bigops
open list finset
namespace nat
open [classes] algebra
local attribute nat.comm_semiring [instance]
variables {A : Type} [deceqA : decidable_eq A]
/- Prodl -/
definition Prodl (l : list A) (f : A → nat) : nat := algebra.Prodl l f
notation `∏` binders `←` l, r:(scoped f, Prodl l f) := r
theorem Prodl_nil (f : A → nat) : Prodl [] f = 1 := algebra.Prodl_nil f
theorem Prodl_cons (f : A → nat) (a : A) (l : list A) : Prodl (a::l) f = f a * Prodl l f :=
algebra.Prodl_cons f a l
theorem Prodl_append (l₁ l₂ : list A) (f : A → nat) : Prodl (l₁++l₂) f = Prodl l₁ f * Prodl l₂ f :=
algebra.Prodl_append l₁ l₂ f
theorem Prodl_mul (l : list A) (f g : A → nat) :
Prodl l (λx, f x * g x) = Prodl l f * Prodl l g := algebra.Prodl_mul l f g
section deceqA
include deceqA
theorem Prodl_insert_of_mem (f : A → nat) {a : A} {l : list A} (H : a ∈ l) :
Prodl (insert a l) f = Prodl l f := algebra.Prodl_insert_of_mem f H
theorem Prodl_insert_of_not_mem (f : A → nat) {a : A} {l : list A} (H : a ∉ l) :
Prodl (insert a l) f = f a * Prodl l f := algebra.Prodl_insert_of_not_mem f H
theorem Prodl_union {l₁ l₂ : list A} (f : A → nat) (d : disjoint l₁ l₂) :
Prodl (union l₁ l₂) f = Prodl l₁ f * Prodl l₂ f := algebra.Prodl_union f d
theorem Prodl_one (l : list A) : Prodl l (λ x, nat.succ 0) = 1 := algebra.Prodl_one l
end deceqA
/- Prod -/
definition Prod (s : finset A) (f : A → nat) : nat := algebra.Prod s f
notation `∏` binders `∈` s, r:(scoped f, Prod s f) := r
theorem Prod_empty (f : A → nat) : Prod ∅ f = 1 := algebra.Prod_empty f
theorem Prod_mul (s : finset A) (f g : A → nat) : Prod s (λx, f x * g x) = Prod s f * Prod s g :=
algebra.Prod_mul s f g
section deceqA
include deceqA
theorem Prod_insert_of_mem (f : A → nat) {a : A} {s : finset A} (H : a ∈ s) :
Prod (insert a s) f = Prod s f := algebra.Prod_insert_of_mem f H
theorem Prod_insert_of_not_mem (f : A → nat) {a : A} {s : finset A} (H : a ∉ s) :
Prod (insert a s) f = f a * Prod s f := algebra.Prod_insert_of_not_mem f H
theorem Prod_union (f : A → nat) {s₁ s₂ : finset A} (disj : s₁ ∩ s₂ = ∅) :
Prod (s₁ ∪ s₂) f = Prod s₁ f * Prod s₂ f := algebra.Prod_union f disj
theorem Prod_ext {s : finset A} {f g : A → nat} (H : ∀x, x ∈ s → f x = g x) :
Prod s f = Prod s g := algebra.Prod_ext H
theorem Prod_one (s : finset A) : Prod s (λ x, nat.succ 0) = 1 := algebra.Prod_one s
end deceqA
/- Suml -/
definition Suml (l : list A) (f : A → nat) : nat := algebra.Suml l f
notation `∑` binders `←` l, r:(scoped f, Suml l f) := r
theorem Suml_nil (f : A → nat) : Suml [] f = 0 := algebra.Suml_nil f
theorem Suml_cons (f : A → nat) (a : A) (l : list A) : Suml (a::l) f = f a + Suml l f :=
algebra.Suml_cons f a l
theorem Suml_append (l₁ l₂ : list A) (f : A → nat) : Suml (l₁++l₂) f = Suml l₁ f + Suml l₂ f :=
algebra.Suml_append l₁ l₂ f
theorem Suml_add (l : list A) (f g : A → nat) : Suml l (λx, f x + g x) = Suml l f + Suml l g :=
algebra.Suml_add l f g
section deceqA
include deceqA
theorem Suml_insert_of_mem (f : A → nat) {a : A} {l : list A} (H : a ∈ l) :
Suml (insert a l) f = Suml l f := algebra.Suml_insert_of_mem f H
theorem Suml_insert_of_not_mem (f : A → nat) {a : A} {l : list A} (H : a ∉ l) :
Suml (insert a l) f = f a + Suml l f := algebra.Suml_insert_of_not_mem f H
theorem Suml_union {l₁ l₂ : list A} (f : A → nat) (d : disjoint l₁ l₂) :
Suml (union l₁ l₂) f = Suml l₁ f + Suml l₂ f := algebra.Suml_union f d
theorem Suml_zero (l : list A) : Suml l (λ x, zero) = 0 := algebra.Suml_zero l
end deceqA
/- Sum -/
definition Sum (s : finset A) (f : A → nat) : nat := algebra.Sum s f
notation `∑` binders `∈` s, r:(scoped f, Sum s f) := r
theorem Sum_empty (f : A → nat) : Sum ∅ f = 0 := algebra.Sum_empty f
theorem Sum_add (s : finset A) (f g : A → nat) : Sum s (λx, f x + g x) = Sum s f + Sum s g :=
algebra.Sum_add s f g
section deceqA
include deceqA
theorem Sum_insert_of_mem (f : A → nat) {a : A} {s : finset A} (H : a ∈ s) :
Sum (insert a s) f = Sum s f := algebra.Sum_insert_of_mem f H
theorem Sum_insert_of_not_mem (f : A → nat) {a : A} {s : finset A} (H : a ∉ s) :
Sum (insert a s) f = f a + Sum s f := algebra.Sum_insert_of_not_mem f H
theorem Sum_union (f : A → nat) {s₁ s₂ : finset A} (disj : s₁ ∩ s₂ = ∅) :
Sum (s₁ ∪ s₂) f = Sum s₁ f + Sum s₂ f := algebra.Sum_union f disj
theorem Sum_ext {s : finset A} {f g : A → nat} (H : ∀x, x ∈ s → f x = g x) :
Sum s f = Sum s g := algebra.Sum_ext H
theorem Sum_zero (s : finset A) : Sum s (λ x, zero) = 0 := algebra.Sum_zero s
end deceqA
end nat
|
f64e6e91ebf6ab2115c162cf98dc178fe63c7d64 | 67190c9aacc0cac64fb4463d93e84c696a5be896 | /Lists of exercises/List 3/capitulo-05-LucasDomingues.lean | f76ae8f6ef1fd13acad379c071c2926d001a2d54 | [] | no_license | lucasresck/Discrete-Mathematics | ffbaf55943e7ce2c7bc50cef7e3ef66a0212f738 | 0a08081c5f393e5765259d3f1253c3a6dd043dac | refs/heads/master | 1,596,627,857,734 | 1,573,411,500,000 | 1,573,411,500,000 | 212,489,764 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 7,564 | lean | variables A B C D E F P Q R: Prop
open classical
theorem exercise_1 (h1 : ¬ A → false) (h2 : A ∨ ¬ A) : A :=
or.elim h2
(assume h3 : A, h3)
(assume h4 : ¬ A,
have h5 : false, from h1 h4,
show A, from false.elim h5)
theorem exercise_2 (h1 : ¬ A ∨ ¬ B) : ¬ (A ∧ B) :=
assume h2 : A ∧ B,
have h3 : A, from and.left h2,
have h4 : B, from and.right h2,
show false, from or.elim h1
(assume h5 : ¬ A, h5 h3)
(assume h6 : ¬ B, h6 h4)
theorem exercise_3 (h1 : ¬ (A ∧ B)) : ¬ A ∨ ¬ B :=
by_contradiction
(assume h2 : ¬ (¬ A ∨ ¬ B),
have h4 : A, from
by_contradiction
(assume h6 : ¬ A,
have h7 : ¬ A ∨ ¬ B, from or.inl h6,
show false, from h2 h7),
have h5 : B, from
by_contradiction
(assume h6 : ¬ B,
have h7 : ¬ A ∨ ¬ B, from or.inr h6,
show false, from h2 h7),
have h3 : A ∧ B, from and.intro h4 h5,
show false, from h1 h3)
theorem exercise_4 (h1 : ¬ P → (Q ∨ R)) (h2 : ¬ Q) (h3 : ¬ R) : P :=
by_contradiction
(assume h4 : ¬ P,
have h5 : Q ∨ R, from h1 h4,
show false, from or.elim h5
(assume h6 : Q, h2 h6)
(assume h6 : R, h3 h6))
theorem exercise_5 (h1 : A → B) : ¬ A ∨ B :=
by_contradiction
(assume h2 : ¬ (¬ A ∨ B),
have h4 : ¬ A, from
assume h5 : A,
have h7 : B, from h1 h5,
have h6 : ¬ A ∨ B, from or.inr h7,
show false, from h2 h6,
have h3 : ¬ A ∨ B, from or.inl h4,
show false, from h2 h3)
theorem exercise_6 : A → ((A ∧ B) ∨ (A ∧ ¬ B)) :=
assume h1 : A,
by_contradiction
(assume h2 : ¬ (((A ∧ B) ∨ (A ∧ ¬ B))),
have h5 : ¬ B, from
assume h6 : B,
have h8 : A ∧ B, from and.intro h1 h6,
have h7 : (A ∧ B) ∨ (A ∧ ¬ B), from or.inl h8,
show false, from h2 h7,
have h4 : A ∧ ¬ B, from and.intro h1 h5,
have h3 : (A ∧ B) ∨ (A ∧ ¬ B), from or.inr h4,
show false, from h2 h3)
-- Exercise 7
lemma fourth {A B C D E F : Prop} (h1 : A ∨ B) (h2 : C ∨ D) (h3 : E ∨ F) :
(((A ∧ (C ∧ E)) ∨ (A ∧ (C ∧ F))) ∨ ((A ∧ (D ∧ E)) ∨ (A ∧ (D ∧ F)))) ∨
(((B ∧ (C ∧ E)) ∨ (B ∧ (C ∧ F))) ∨ ((B ∧ (D ∧ E)) ∨ (B ∧ (D ∧ F)))) :=
-- I will now suppose very each case above, and include the other terms of conjunction
or.elim h1
(assume h4 : A,
or.elim h2
(assume h5 : C,
or.elim h3
(assume h6 : E,
-- I have now A ∧ C ∧ E, so I can have all the proposition, like bellow
or.inl (or.inl (or.inl (and.intro h4 (and.intro h5 h6)))))
(assume h6 : F,
or.inl (or.inl (or.inr (and.intro h4 (and.intro h5 h6))))))
(assume h5 : D,
or.elim h3
(assume h6 : E,
or.inl (or.inr (or.inl (and.intro h4 (and.intro h5 h6)))))
(assume h6 : F,
or.inl (or.inr (or.inr (and.intro h4 (and.intro h5 h6)))))))
(assume h4 : B,
or.elim h2
(assume h5 : C,
or.elim h3
(assume h6 : E,
or.inr (or.inl (or.inl (and.intro h4 (and.intro h5 h6)))))
(assume h6 : F,
or.inr (or.inl (or.inr (and.intro h4 (and.intro h5 h6))))))
(assume h5 : D,
or.elim h3
(assume h6 : E,
or.inr (or.inr (or.inl (and.intro h4 (and.intro h5 h6)))))
(assume h6 : F,
or.inr (or.inr (or.inr (and.intro h4 (and.intro h5 h6)))))))
lemma third {A B C D E F : Prop} (h1 : (A ∧ (C ∧ E)) ∨ (A ∧ (C ∧ F))): (A ∨ B) ∧ (C ∨ D) ∧ (E ∨ F) :=
or.elim h1
(assume h2 : A ∧ (C ∧ E),
have h3 : A ∨ B, from or.inl (and.left h2),
have h4 : C ∧ E, from and.right h2,
have h5 : C ∨ D, from or.inl (and.left h4),
have h6 : E ∨ F, from or.inl (and.right h4),
and.intro h3 (and.intro h5 h6))
(assume h2 : A ∧ (C ∧ F),
have h3 : A ∨ B, from or.inl (and.left h2),
have h4 : C ∧ F, from and.right h2,
have h5 : C ∨ D, from or.inl (and.left h4),
have h6 : E ∨ F, from or.inr (and.right h4),
and.intro h3 (and.intro h5 h6))
lemma switch {A B : Prop} (h1 : A ∨ B) : B ∨ A :=
or.elim h1
(assume h2 : A, or.inr h2)
(assume h2 : B, or.inl h2)
lemma second {A B C D E F : Prop}
(h1 : ((A ∧ (C ∧ E)) ∨ (A ∧ (C ∧ F))) ∨ ((A ∧ (D ∧ E)) ∨ (A ∧ (D ∧ F)))): (A ∨ B) ∧ (C ∨ D) ∧ (E ∨ F) :=
or.elim h1
(assume h2 : (A ∧ (C ∧ E)) ∨ (A ∧ (C ∧ F)),
third h2)
(assume h2 : (A ∧ (D ∧ E)) ∨ (A ∧ (D ∧ F)),
-- Now I can use third lemma again, but later I will have to switch C and D
have h3 : (A ∨ B) ∧ (D ∨ C) ∧ (E ∨ F), from third h2,
have h4 : A ∨ B, from and.left h3,
have h5 : D ∨ C, from and.left (and.right h3),
have h6 : C ∨ D, from switch h5,
have h7 : E ∨ F, from and.right (and.right h3),
and.intro h4 (and.intro h6 h7))
lemma first {A B C D E F : Prop}
(h1 : (((A ∧ (C ∧ E)) ∨ (A ∧ (C ∧ F))) ∨ ((A ∧ (D ∧ E)) ∨ (A ∧ (D ∧ F)))) ∨
(((B ∧ (C ∧ E)) ∨ (B ∧ (C ∧ F))) ∨ ((B ∧ (D ∧ E)) ∨ (B ∧ (D ∧ F))))): (A ∨ B) ∧ (C ∨ D) ∧ (E ∨ F) :=
or.elim h1
(assume h2 : ((A ∧ (C ∧ E)) ∨ (A ∧ (C ∧ F))) ∨ ((A ∧ (D ∧ E)) ∨ (A ∧ (D ∧ F))),
second h2)
(assume h2 : ((B ∧ (C ∧ E)) ∨ (B ∧ (C ∧ F))) ∨ ((B ∧ (D ∧ E)) ∨ (B ∧ (D ∧ F))),
have h3 : (B ∨ A) ∧ (C ∨ D) ∧ (E ∨ F), from second h2,
have h4 : B ∨ A, from and.left h3,
have h5 : A ∨ B, from switch h4,
have h6 : (C ∨ D) ∧ (E ∨ F), from and.right h3,
and.intro h5 h6)
theorem exercise_7 : (A ∨ B) ∧ (C ∨ D) ∧ (E ∨ F) ↔
(((A ∧ (C ∧ E)) ∨ (A ∧ (C ∧ F))) ∨ ((A ∧ (D ∧ E)) ∨ (A ∧ (D ∧ F)))) ∨
(((B ∧ (C ∧ E)) ∨ (B ∧ (C ∧ F))) ∨ ((B ∧ (D ∧ E)) ∨ (B ∧ (D ∧ F)))) :=
iff.intro
(assume h1 : (A ∨ B) ∧ (C ∨ D) ∧ (E ∨ F),
have h2 : A ∨ B, from h1.left,
have h3 : C ∨ D, from (h1.right).left,
have h4 : E ∨ F, from (h1.right).right,
fourth h2 h3 h4)
(assume h1 : (((A ∧ (C ∧ E)) ∨ (A ∧ (C ∧ F))) ∨ ((A ∧ (D ∧ E)) ∨ (A ∧ (D ∧ F)))) ∨
(((B ∧ (C ∧ E)) ∨ (B ∧ (C ∧ F))) ∨ ((B ∧ (D ∧ E)) ∨ (B ∧ (D ∧ F)))),
first h1)
-- Exercise 8
-- Prove ¬ (A ∧ B) → ¬ A ∨ ¬ B by replacing the sorry's below
-- by proofs.
lemma step1 {A B : Prop} (h₁ : ¬ (A ∧ B)) (h₂ : A) : ¬ A ∨ ¬ B :=
have ¬ B, from
assume h₃ : B,
show false, from h₁ (and.intro h₂ h₃),
show ¬ A ∨ ¬ B, from or.inr this
lemma step2 {A B : Prop} (h₁ : ¬ (A ∧ B)) (h₂ : ¬ (¬ A ∨ ¬ B)) : false :=
have ¬ A, from
assume : A,
have ¬ A ∨ ¬ B, from step1 h₁ ‹A›,
show false, from h₂ this,
show false, from h₂ (or.inl this)
theorem step3 (h : ¬ (A ∧ B)) : ¬ A ∨ ¬ B :=
by_contradiction
(assume h' : ¬ (¬ A ∨ ¬ B),
show false, from step2 h h')
-- Exercise 9
example (h : ¬ B → ¬ A) : A → B :=
assume h1 : A,
by_contradiction
(assume h2 : ¬ B,
show false, from (h h2) h1)
example (h : A → B) : ¬ A ∨ B :=
by_contradiction
(assume h1 : ¬ (¬ A ∨ B),
have h3 : ¬ A, from
assume h4 : A,
have h6 : B, from h h4,
have h5 : ¬ A ∨ B, from or.inr h6,
show false, from h1 h5,
have h2 : ¬ A ∨ B, from or.inl h3,
show false, from h1 h2)
|
19be5a958f6f4787ae2295da0321eee3d957fcda | 2cf781335f4a6706b7452ab07ce323201e2e101f | /lean/deps/sexpr/src/galois/char_reader.lean | 44638e94bb2aaadf092db87d80a95c8b029a3603 | [
"Apache-2.0"
] | permissive | simonjwinwood/reopt-vcg | 697cdd5e68366b5aa3298845eebc34fc97ccfbe2 | 6aca24e759bff4f2230bb58270bac6746c13665e | refs/heads/master | 1,586,353,878,347 | 1,549,667,148,000 | 1,549,667,148,000 | 159,409,828 | 0 | 0 | null | 1,543,358,444,000 | 1,543,358,444,000 | null | UTF-8 | Lean | false | false | 7,733 | lean | /-
This defines an interface for reading characters with one-character lookahead.
-/
import data.buffer
import system.io
import galois.data.list
------------------------------------------------------------------------
-- is_parse_error
class is_parse_error (ε : Type _) :=
(end_of_input {} : ε)
namespace is_parse_error
instance string_is_parse_error : is_parse_error string :=
{ end_of_input := "end of input" }
end is_parse_error
------------------------------------------------------------------------
-- char_reader
/-- A class for a monad that can read characters with a one-byte lookahead. -/
class {u v} char_reader (ε : out_param (Type u)) (m : Type → Type v)
extends is_parse_error ε, monad m, monad_except ε m :=
(at_end {} : m bool)
(peek_char {} : m (option char))
-- Drop the next character
(consume_char {} : m unit)
(read_char {} : m char)
namespace char_reader
section read_while
parameter {m : Type → Type}
parameter [char_reader string m]
parameter (p : char → Prop)
parameter [decidable_pred p]
/-- Append characters to buffer while not at end of file and the predicate is true. -/
def read_while_f :
Π(n:ℕ)
(f : Π(j:ℕ), j < n → char_buffer → m char_buffer),
char_buffer → m char_buffer
| 0 f prev := do
throw "Maximum length exceeded"
| (nat.succ i) f prev := do
mc ← peek_char,
match mc with
| option.none := pure prev
| option.some c :=
if p c then do
consume_char, f i (nat.lt_succ_self _) (prev.push_back c)
else
pure prev
end
/-- @read_append_while n c@ reads up to @n@-characters satisfying @p@ and appends them to @c@. -/
def read_append_while : ℕ → char_buffer → m char_buffer := do
well_founded.fix nat.lt_wf read_while_f
/-- @read_append_while n c@ reads up to @n@-characters satisfying @p@ and appends them to @c@. -/
def read_while (max_count:ℕ) : m char_buffer := do
read_append_while max_count buffer.nil
end read_while
/-- Read whitespace characters until a newline is encountered, then consume the newline. -/
def read_to_newline {m} [char_reader string m] : ℕ → m unit
| nat.zero := throw "out of gas"
| (nat.succ n) := do
c ← read_char,
if c = '\n' then
pure ()
else if c.is_whitespace then
read_to_newline n
else
throw $ "Unexpected character at end of expression " ++ c.to_string
/-- Read up to given number of characters to reach end of file. -/
def read_to_end {m} [char_reader string m] : ℕ → m unit
| nat.zero := throw "out of gas"
| (nat.succ n) := do
b ← at_end,
if b then
pure ()
else
consume_char, read_to_end n
------------------------------------------------------------------------
-- handle_char_reader
/-- A char_reader that reads from a handle. -/
def handle_char_reader (ε:Type) := except_t ε (reader_t io.handle (state_t (option char) io))
namespace handle_char_reader
section
parameter (ε : Type)
local attribute [reducible] handle_char_reader
instance is_monad : monad (handle_char_reader ε) := by apply_instance
instance has_monad_lift : has_monad_lift io (handle_char_reader ε) :=
{ monad_lift := λ_, monad_lift }
instance is_monad_except : monad_except ε (handle_char_reader ε) := by apply_instance
end
/- This uses the handle_char_reader to parse output. -/
protected
def read {ε} {α} (h:io.handle) (mc : option char) (m:handle_char_reader ε α)
: io (except ε α × option char) := do
((m.run).run h).run mc
section
parameter {ε : Type}
local attribute [reducible] handle_char_reader
/-- Return true if the handle is at the end of the stream. -/
protected
def at_end [is_parse_error ε] : handle_char_reader ε bool := do
mc ← get,
match mc with
| option.some c := pure ff
| option.none := do
h ← read,
monad_lift (io.fs.is_eof h)
end
/-- Attempt to read character from handle. -/
protected
def peek_char [is_parse_error ε] : handle_char_reader ε (option char) := do
mc ← get,
match mc with
| option.some c := pure c
| option.none := do
h ← read,
b ← monad_lift (io.fs.read h 1),
if h : b.size = 1 then do
let c := b.read ⟨0, h.symm ▸ zero_lt_one⟩,
put (option.some c) $> c
else
pure option.none
end
protected
def get_char [is_parse_error ε] : handle_char_reader ε char := do
mc ← get,
match mc with
| (option.some c) := put option.none $> c
| option.none := do
h ← read,
b ← monad_lift (io.fs.read h 1),
if h : b.size = 1 then
pure (b.read ⟨0, h.symm ▸ zero_lt_one⟩)
else
throw is_parse_error.end_of_input
end
protected
def consume_char [is_parse_error ε] : handle_char_reader ε unit := get_char $> ()
end
instance is_char_reader (ε:Type) [is_parse_error ε] : char_reader ε (handle_char_reader ε) :=
{ at_end := handle_char_reader.at_end
, peek_char := handle_char_reader.peek_char
, consume_char := handle_char_reader.consume_char
, read_char := handle_char_reader.get_char
}
/-- For some reason, instance resolution fails below without this instance. -/
def string_is_char_reader : char_reader string (handle_char_reader string) :=
@handle_char_reader.is_char_reader string is_parse_error.string_is_parse_error
local attribute [instance] string_is_char_reader
end handle_char_reader
def read_from_handle {α} (h:io.handle) (m:handle_char_reader string α)
: io (except string α) := do
(e, mc) ← handle_char_reader.read h option.none m,
match mc with
| option.none := pure e
| (option.some _) := pure (except.error "")
end
------------------------------------------------------------------------
-- string_char_reader
/-- Character reader that rads from a list of characters in memory. -/
def string_char_reader (ε:Type) := except_t ε (state (list char))
namespace string_char_reader
section
parameter (ε : Type)
local attribute [reducible] string_char_reader
instance is_monad : monad (string_char_reader ε) := by apply_instance
instance is_monad_except : monad_except ε (string_char_reader ε) := by apply_instance
end
/- This uses the string_char_reader to parse output. -/
protected
def read {ε} {α} (s:string) (m:string_char_reader ε α)
: (except ε α × string) := do
let (r,t) := ((m.run).run s.to_list) in
(r, t.as_string)
section
variable {ε : Type}
local attribute [reducible] string_char_reader
/-- Return true if the handle is at the end of the stream. -/
protected
def at_end [is_parse_error ε] : string_char_reader ε bool := do
(λ(l:list char), l.is_empty) <$> get
protected
def peek_char [is_parse_error ε] : string_char_reader ε (option char) := do
s ← get,
match s with
| [] := pure option.none
| (c::s) := pure (option.some c)
end
protected
def get_char [is_parse_error ε] : string_char_reader ε char := do
s ← get,
match s with
| [] := throw is_parse_error.end_of_input
| (c::s) := put s $> c
end
protected
def consume_char [is_parse_error ε] : string_char_reader ε unit := string_char_reader.get_char $> ()
end
instance is_char_reader (ε:Type) [is_parse_error ε] : char_reader ε (string_char_reader ε) :=
{ at_end := string_char_reader.at_end
, peek_char := string_char_reader.peek_char
, consume_char := string_char_reader.consume_char
, read_char := string_char_reader.get_char
}
/-- For some reason, instance resolution fails below without this instance. -/
instance string_is_char_reader : char_reader string (string_char_reader string) :=
@string_char_reader.is_char_reader string is_parse_error.string_is_parse_error
end string_char_reader
/-- Read a string -/
def read_from_string {α} (s:string) (m:string_char_reader string α)
: except string α := (string_char_reader.read s m).1
end char_reader
|
fc6e97dfe42024574f5f47a9895959e514ee0f87 | 6432ea7a083ff6ba21ea17af9ee47b9c371760f7 | /src/Lean/Util/ForEachExpr.lean | d8902efe403b362bd0eca36ed9dcb52feac1f113 | [
"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,465 | lean | /-
Copyright (c) 2020 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
import Lean.Expr
import Lean.Util.MonadCache
namespace Lean
/-!
Remark: we cannot use the caching trick used at `FindExpr` and `ReplaceExpr` because they
may visit the same expression multiple times if they are stored in different memory
addresses. Note that the following code is parametric in a monad `m`.
-/
variable {ω : Type} {m : Type → Type} [STWorld ω m] [MonadLiftT (ST ω) m] [Monad m]
namespace ForEachExpr
partial def visit (g : Expr → m Bool) (e : Expr) : MonadCacheT Expr Unit m Unit :=
checkCache e fun _ => do
if (← g e) then
match e with
| Expr.forallE _ d b _ => do visit g d; visit g b
| Expr.lam _ d b _ => do visit g d; visit g b
| Expr.letE _ t v b _ => do visit g t; visit g v; visit g b
| Expr.app f a => do visit g f; visit g a
| Expr.mdata _ b => visit g b
| Expr.proj _ _ b => visit g b
| _ => pure ()
end ForEachExpr
/-- Apply `f` to each sub-expression of `e`. If `f t` returns false, then t's children are not visited. -/
@[inline] def Expr.forEach' (e : Expr) (f : Expr → m Bool) : m Unit :=
(ForEachExpr.visit f e).run
@[inline] def Expr.forEach (e : Expr) (f : Expr → m Unit) : m Unit :=
e.forEach' fun e => do f e; pure true
end Lean
|
50b675d2eba98a179ff647d8d8cc0d86656e5b94 | cc060cf567f81c404a13ee79bf21f2e720fa6db0 | /lean/20170607-eblast-example.lean | 4abf0ee7cd526e588086e0ac0af3cf0e5fcc9cde | [
"Apache-2.0"
] | permissive | semorrison/proof | cf0a8c6957153bdb206fd5d5a762a75958a82bca | 5ee398aa239a379a431190edbb6022b1a0aa2c70 | refs/heads/master | 1,610,414,502,842 | 1,518,696,851,000 | 1,518,696,851,000 | 78,375,937 | 2 | 1 | null | null | null | null | UTF-8 | Lean | false | false | 1,712 | lean | structure Category :=
( Obj : Type )
( Hom : Obj → Obj → Type )
(compose : Π { X Y Z : Obj }, Hom X Y → Hom Y Z → Hom X Z)
(associativity : ∀ { W X Y Z : Obj } (f : Hom W X) (g : Hom X Y) (h : Hom Y Z),
compose (compose f g) h = compose f (compose g h))
attribute [ematch] Category.associativity
structure Functor (C : Category) (D : Category) :=
(onObjects : C.Obj → D.Obj)
(onMorphisms : Π { X Y : C.Obj },
C.Hom X Y → D.Hom (onObjects X) (onObjects Y))
(functoriality : ∀ { X Y Z : C.Obj } (f : C.Hom X Y) (g : C.Hom Y Z),
onMorphisms (C.compose f g) = D.compose (onMorphisms f) (onMorphisms g))
attribute [simp,ematch] Functor.functoriality
instance Functor_to_onObjects { C D : Category }: has_coe_to_fun (Functor C D) :=
{ F := λ f, C.Obj → D.Obj,
coe := Functor.onObjects }
structure NaturalTransformation { C : Category } { D : Category } ( F G : Functor C D ) :=
(components: Π X : C.Obj, D.Hom (F X) (G X))
(naturality: ∀ { X Y : C.Obj } (f : C.Hom X Y),
D.compose (F.onMorphisms f) (components Y) = D.compose (components X) (G.onMorphisms f))
attribute [ematch] NaturalTransformation.naturality
meta def unfold_coe : tactic unit := tactic.dunfold [ ``has_coe_to_fun.coe ]
definition vertical_composition_of_NaturalTransformations
{ C : Category } { D : Category }
{ F G H : Functor C D }
( α : NaturalTransformation F G )
( β : NaturalTransformation G H ) : NaturalTransformation F H :=
{
components := λ X, D.compose (α.components X) (β.components X),
naturality := begin[smt]
intros,
unfold_coe,
eblast
end
} |
1c920e78271995b1a4855de17f765b9f9eb272f2 | 57c233acf9386e610d99ed20ef139c5f97504ba3 | /src/algebra/group/ulift.lean | 325d4c700945522ee3a6f224ec6b93789bdbc1e2 | [
"Apache-2.0"
] | permissive | robertylewis/mathlib | 3d16e3e6daf5ddde182473e03a1b601d2810952c | 1d13f5b932f5e40a8308e3840f96fc882fae01f0 | refs/heads/master | 1,651,379,945,369 | 1,644,276,960,000 | 1,644,276,960,000 | 98,875,504 | 0 | 0 | Apache-2.0 | 1,644,253,514,000 | 1,501,495,700,000 | Lean | UTF-8 | Lean | false | false | 4,405 | 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 data.equiv.mul_add
/-!
# `ulift` instances for groups and monoids
This file defines instances for group, monoid, semigroup and related structures on `ulift` types.
(Recall `ulift α` is just a "copy" of a type `α` in a higher universe.)
We use `tactic.pi_instance_derive_field`, even though it wasn't intended for this purpose,
which seems to work fine.
We also provide `ulift.mul_equiv : ulift R ≃* R` (and its additive analogue).
-/
universes u v
variables {α : Type u} {x y : ulift.{v} α}
namespace ulift
@[to_additive] instance has_one [has_one α] : has_one (ulift α) := ⟨⟨1⟩⟩
@[simp, to_additive] lemma one_down [has_one α] : (1 : ulift α).down = 1 := rfl
@[to_additive] instance has_mul [has_mul α] : has_mul (ulift α) := ⟨λ f g, ⟨f.down * g.down⟩⟩
@[simp, to_additive] lemma mul_down [has_mul α] : (x * y).down = x.down * y.down := rfl
@[to_additive] instance has_div [has_div α] : has_div (ulift α) := ⟨λ f g, ⟨f.down / g.down⟩⟩
@[simp, to_additive] lemma div_down [has_div α] : (x / y).down = x.down / y.down := rfl
@[to_additive] instance has_inv [has_inv α] : has_inv (ulift α) := ⟨λ f, ⟨f.down⁻¹⟩⟩
@[simp, to_additive] lemma inv_down [has_inv α] : x⁻¹.down = (x.down)⁻¹ := rfl
/--
The multiplicative equivalence between `ulift α` and `α`.
-/
@[to_additive "The additive equivalence between `ulift α` and `α`."]
def _root_.mul_equiv.ulift [has_mul α] : ulift α ≃* α :=
{ map_mul' := λ x y, rfl,
.. equiv.ulift }
@[to_additive]
instance semigroup [semigroup α] : semigroup (ulift α) :=
mul_equiv.ulift.injective.semigroup _ $ λ x y, rfl
@[to_additive]
instance comm_semigroup [comm_semigroup α] : comm_semigroup (ulift α) :=
equiv.ulift.injective.comm_semigroup _ $ λ x y, rfl
@[to_additive]
instance mul_one_class [mul_one_class α] : mul_one_class (ulift α) :=
equiv.ulift.injective.mul_one_class _ rfl $ λ x y, rfl
@[to_additive has_vadd]
instance has_scalar {β : Type*} [has_scalar α β] : has_scalar α (ulift β) :=
⟨λ n x, up (n • x.down)⟩
@[to_additive has_scalar, to_additive_reorder 1]
instance has_pow {β : Type*} [has_pow α β] : has_pow (ulift α) β :=
⟨λ x n, up (x.down ^ n)⟩
@[to_additive]
instance monoid [monoid α] : monoid (ulift α) :=
equiv.ulift.injective.monoid_pow _ rfl (λ _ _, rfl) (λ _ _, rfl)
@[to_additive]
instance comm_monoid [comm_monoid α] : comm_monoid (ulift α) :=
{ .. ulift.monoid, .. ulift.comm_semigroup }
@[to_additive]
instance div_inv_monoid [div_inv_monoid α] : div_inv_monoid (ulift α) :=
equiv.ulift.injective.div_inv_monoid_pow _ rfl (λ _ _, rfl) (λ _, rfl)
(λ _ _, rfl) (λ _ _, rfl) (λ _ _, rfl)
@[to_additive]
instance group [group α] : group (ulift α) :=
equiv.ulift.injective.group_pow _ rfl (λ _ _, rfl) (λ _, rfl)
(λ _ _, rfl) (λ _ _, rfl) (λ _ _, rfl)
@[to_additive]
instance comm_group [comm_group α] : comm_group (ulift α) :=
{ .. ulift.group, .. ulift.comm_semigroup }
@[to_additive add_left_cancel_semigroup]
instance left_cancel_semigroup [left_cancel_semigroup α] :
left_cancel_semigroup (ulift α) :=
equiv.ulift.injective.left_cancel_semigroup _ (λ _ _, rfl)
@[to_additive add_right_cancel_semigroup]
instance right_cancel_semigroup [right_cancel_semigroup α] :
right_cancel_semigroup (ulift α) :=
equiv.ulift.injective.right_cancel_semigroup _ (λ _ _, rfl)
@[to_additive add_left_cancel_monoid]
instance left_cancel_monoid [left_cancel_monoid α] :
left_cancel_monoid (ulift α) :=
{ .. ulift.monoid, .. ulift.left_cancel_semigroup }
@[to_additive add_right_cancel_monoid]
instance right_cancel_monoid [right_cancel_monoid α] :
right_cancel_monoid (ulift α) :=
{ .. ulift.monoid, .. ulift.right_cancel_semigroup }
@[to_additive add_cancel_monoid]
instance cancel_monoid [cancel_monoid α] :
cancel_monoid (ulift α) :=
{ .. ulift.left_cancel_monoid, .. ulift.right_cancel_semigroup }
@[to_additive add_cancel_monoid]
instance cancel_comm_monoid [cancel_comm_monoid α] :
cancel_comm_monoid (ulift α) :=
{ .. ulift.cancel_monoid, .. ulift.comm_semigroup }
-- TODO we don't do `ordered_cancel_comm_monoid` or `ordered_comm_group`
-- We'd need to add instances for `ulift` in `order.basic`.
end ulift
|
0d56fe9dafc011871bb45e7d8a3aa1308a1a51ea | 271e26e338b0c14544a889c31c30b39c989f2e0f | /tests/bench/qsort.lean | d5c85b119bde2a45d29f9f2194265727e8436481 | [
"Apache-2.0"
] | permissive | dgorokho/lean4 | 805f99b0b60c545b64ac34ab8237a8504f89d7d4 | e949a052bad59b1c7b54a82d24d516a656487d8a | refs/heads/master | 1,607,061,363,851 | 1,578,006,086,000 | 1,578,006,086,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 2,403 | lean | abbrev Elem := UInt32
def badRand (seed : Elem) : Elem :=
seed * 1664525 + 1013904223
def mkRandomArray : Nat → Elem → Array Elem → Array Elem
| 0, seed, as => as
| i+1, seed, as => mkRandomArray i (badRand seed) (as.push seed)
partial def checkSortedAux (a : Array Elem) : Nat → IO Unit
| i =>
if i < a.size - 1 then do
unless (a.get! i <= a.get! (i+1)) $ throw (IO.userError "array is not sorted");
checkSortedAux (i+1)
else
pure ()
-- copied from stdlib, but with `UInt32` indices instead of `Nat` (which is more comparable to the other versions)
abbrev Idx := UInt32
instance : HasLift UInt32 Nat := ⟨UInt32.toNat⟩
prefix `↑`:max := coe
@[specialize] private partial def partitionAux {α : Type} [Inhabited α] (lt : α → α → Bool) (hi : Idx) (pivot : α) : Array α → Idx → Idx → Idx × Array α
| as, i, j =>
if j < hi then
if lt (as.get! ↑j) pivot then
let as := as.swap! ↑i ↑j;
partitionAux as (i+1) (j+1)
else
partitionAux as i (j+1)
else
let as := as.swap! ↑i ↑hi;
(i, as)
@[inline] def partition {α : Type} [Inhabited α] (as : Array α) (lt : α → α → Bool) (lo hi : Idx) : Idx × Array α :=
let mid := (lo + hi) / 2;
let as := if lt (as.get! ↑mid) (as.get! ↑lo) then as.swap! ↑lo ↑mid else as;
let as := if lt (as.get! ↑hi) (as.get! ↑lo) then as.swap! ↑lo ↑hi else as;
let as := if lt (as.get! ↑mid) (as.get! ↑hi) then as.swap! ↑mid ↑hi else as;
let pivot := as.get! ↑hi;
partitionAux lt hi pivot as lo lo
@[specialize] partial def qsortAux {α : Type} [Inhabited α] (lt : α → α → Bool) : Array α → Idx → Idx → Array α
| as, low, high =>
if low < high then
let p := partition as lt low high;
-- TODO: fix `partial` support in the equation compiler, it breaks if we use `let (mid, as) := partition as lt low high`
let mid := p.1;
let as := p.2;
let as := qsortAux as low mid;
qsortAux as (mid+1) high
else as
@[inline] def qsort {α : Type} [Inhabited α] (as : Array α) (lt : α → α → Bool) : Array α :=
qsortAux lt as 0 (UInt32.ofNat (as.size - 1))
def main (xs : List String) : IO Unit :=
do
let n := xs.head!.toNat;
n.forM $ fun _ =>
n.forM $ fun i => do
let xs := mkRandomArray i (UInt32.ofNat i) Array.empty;
let xs := qsort xs (fun a b => a < b);
--IO.println xs;
checkSortedAux xs 0
|
34c75d517aab7f6e0906af7cfc7a2dc7d7baea02 | 57fdc8de88f5ea3bfde4325e6ecd13f93a274ab5 | /set_theory/cofinality.lean | 668bfb6f733349e9865a215deefa9f3d1b43b0fd | [
"Apache-2.0"
] | permissive | louisanu/mathlib | 11f56f2d40dc792bc05ee2f78ea37d73e98ecbfe | 2bd5e2159d20a8f20d04fc4d382e65eea775ed39 | refs/heads/master | 1,617,706,993,439 | 1,523,163,654,000 | 1,523,163,654,000 | 124,519,997 | 0 | 0 | Apache-2.0 | 1,520,588,283,000 | 1,520,588,283,000 | null | UTF-8 | Lean | false | false | 16,762 | lean | /-
Copyright (c) 2017 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Mario Carneiro
Cofinality on ordinals, regular cardinals.
-/
import set_theory.ordinal
noncomputable theory
open function cardinal
local attribute [instance] classical.prop_decidable
universes u v w
variables {α : Type*} {r : α → α → Prop}
/-- Cofinality of a reflexive order `≼`. This is the smallest cardinality
of a subset `S : set α` such that `∀ a, ∃ b ∈ S, a ≼ b`. -/
def order.cof (r : α → α → Prop) [is_refl α r] : cardinal :=
@cardinal.min {S : set α // ∀ a, ∃ b ∈ S, r a b}
⟨⟨set.univ, λ a, ⟨a, ⟨⟩, refl _⟩⟩⟩
(λ S, mk S)
theorem order_iso.cof.aux {α : Type u} {β : Type v} {r s}
[is_refl α r] [is_refl β s] (f : r ≃o s) :
cardinal.lift.{u (max u v)} (order.cof r) ≤
cardinal.lift.{v (max u v)} (order.cof s) :=
begin
rw [order.cof, order.cof, lift_min, lift_min, cardinal.le_min],
intro S, cases S with S H, simp [(∘)],
refine le_trans (min_le _ _) _,
{ exact ⟨f ⁻¹' S, λ a,
let ⟨b, bS, h⟩ := H (f a) in ⟨f.symm b, by simp [bS, f.ord', h]⟩⟩ },
{ exact lift_mk_le.{u v (max u v)}.2
⟨⟨λ ⟨x, h⟩, ⟨f x, h⟩, λ ⟨x, h₁⟩ ⟨y, h₂⟩ h₃,
by congr; injection h₃ with h'; exact f.to_equiv.bijective.1 h'⟩⟩ }
end
theorem order_iso.cof {α : Type u} {β : Type v} {r s}
[is_refl α r] [is_refl β s] (f : r ≃o s) :
cardinal.lift.{u (max u v)} (order.cof r) =
cardinal.lift.{v (max u v)} (order.cof s) :=
le_antisymm (order_iso.cof.aux f) (order_iso.cof.aux f.symm)
namespace ordinal
/-- Cofinality of an ordinal. This is the smallest cardinal of a
subset `S` of the ordinal which is unbounded, in the sense
`∀ a, ∃ b ∈ S, a ≤ b`. It is defined for all ordinals, but
`cof 0 = 0` and `cof (succ o) = 1`, so it is only really
interesting on limit ordinals (when it is an infinite cardinal). -/
def cof (o : ordinal.{u}) : cardinal.{u} :=
quot.lift_on o (λ ⟨α, r, _⟩,
@order.cof α (λ x y, ¬ r y x) ⟨λ a, by resetI; apply irrefl⟩) $
λ ⟨α, r, _⟩ ⟨β, s, _⟩ ⟨⟨f, hf⟩⟩, begin
show @order.cof α (λ x y, ¬ r y x) ⟨_⟩ = @order.cof β (λ x y, ¬ s y x) ⟨_⟩,
refine cardinal.lift_inj.1 (@order_iso.cof _ _ _ _ ⟨_⟩ ⟨_⟩ _),
exact ⟨f, λ a b, not_congr hf⟩,
end
theorem le_cof_type [is_well_order α r] {c} : c ≤ cof (type r) ↔
∀ S : set α, (∀ a, ∃ b ∈ S, ¬ r b a) → c ≤ mk S :=
by dsimp [cof, order.cof, type, quotient.mk, quot.lift_on];
rw [cardinal.le_min, subtype.forall]; refl
theorem cof_type_le [is_well_order α r] (S : set α) (h : ∀ a, ∃ b ∈ S, ¬ r b a) :
cof (type r) ≤ mk S :=
le_cof_type.1 (le_refl _) S h
theorem lt_cof_type [is_well_order α r] (S : set α) (hl : mk S < cof (type r)) :
∃ a, ∀ b ∈ S, r b a :=
not_forall_not.1 $ λ h, not_le_of_lt hl $ cof_type_le S (λ a, not_ball.1 (h a))
theorem cof_eq (r : α → α → Prop) [is_well_order α r] :
∃ S : set α, (∀ a, ∃ b ∈ S, ¬ r b a) ∧ mk S = cof (type r) :=
begin
have : ∃ i, cof (type r) = _,
{ dsimp [cof, order.cof, type, quotient.mk, quot.lift_on],
apply cardinal.min_eq },
exact let ⟨⟨S, hl⟩, e⟩ := this in ⟨S, hl, e.symm⟩,
end
theorem ord_cof_eq (r : α → α → Prop) [is_well_order α r] :
∃ S : set α, (∀ a, ∃ b ∈ S, ¬ r b a) ∧ type (subrel r S) = (cof (type r)).ord :=
let ⟨S, hS, e⟩ := cof_eq r, ⟨s, _, e'⟩ := cardinal.ord_eq S,
T : set α := {a | ∃ aS : a ∈ S, ∀ b : S, s b ⟨_, aS⟩ → r b a} in
begin
resetI, suffices,
{ refine ⟨T, this,
le_antisymm _ (cardinal.ord_le.2 $ cof_type_le T this)⟩,
rw [← e, e'],
refine type_le'.2 ⟨order_embedding.of_monotone
(λ a, ⟨a, let ⟨aS, _⟩ := a.2 in aS⟩) (λ a b h, _)⟩,
rcases a with ⟨a, aS, ha⟩, rcases b with ⟨b, bS, hb⟩,
change s ⟨a, _⟩ ⟨b, _⟩,
refine ((trichotomous_of s _ _).resolve_left (λ hn, _)).resolve_left _,
{ exact asymm h (ha _ hn) },
{ intro e, injection e with e, subst b,
exact irrefl _ h } },
{ intro a,
have : {b : S | ¬ r b a} ≠ ∅ := let ⟨b, bS, ba⟩ := hS a in
@set.ne_empty_of_mem S {b | ¬ r b a} ⟨b, bS⟩ ba,
let b := (is_well_order.wf s).min _ this,
have ba : ¬r b a := (is_well_order.wf s).min_mem _ this,
refine ⟨b, ⟨b.2, λ c, not_imp_not.1 $ λ h, _⟩, ba⟩,
rw [show ∀b:S, (⟨b, b.2⟩:S) = b, by intro b; cases b; refl],
exact (is_well_order.wf s).not_lt_min _ this
(is_order_connected.neg_trans r h ba) }
end
theorem lift_cof (o) : (cof o).lift = cof o.lift :=
induction_on o $ begin introsI α r _,
cases lift_type r with _ e, rw e,
apply le_antisymm,
{ refine le_cof_type.2 (λ S H, _),
have : (mk (ulift.up ⁻¹' S)).lift ≤ mk S :=
⟨⟨λ ⟨⟨x, h⟩⟩, ⟨⟨x⟩, h⟩,
λ ⟨⟨x, h₁⟩⟩ ⟨⟨y, h₂⟩⟩ e, by simp at e; congr; injection e⟩⟩,
refine le_trans (cardinal.lift_le.2 $ cof_type_le _ _) this,
exact λ a, let ⟨⟨b⟩, bs, br⟩ := H ⟨a⟩ in ⟨b, bs, br⟩ },
{ rcases cof_eq r with ⟨S, H, e'⟩,
have : mk (ulift.down ⁻¹' S) ≤ (mk S).lift :=
⟨⟨λ ⟨⟨x⟩, h⟩, ⟨⟨x, h⟩⟩,
λ ⟨⟨x⟩, h₁⟩ ⟨⟨y⟩, h₂⟩ e, by simp at e; congr; injections⟩⟩,
rw e' at this,
refine le_trans (cof_type_le _ _) this,
exact λ ⟨a⟩, let ⟨b, bs, br⟩ := H a in ⟨⟨b⟩, bs, br⟩ }
end
theorem cof_le_card (o) : cof o ≤ card o :=
induction_on o $ λ α r _, begin
resetI,
have : mk (@set.univ α) = card (type r) :=
quotient.sound ⟨equiv.set.univ _⟩,
rw ← this, exact cof_type_le set.univ (λ a, ⟨a, ⟨⟩, irrefl a⟩)
end
theorem cof_ord_le (c : cardinal) : cof c.ord ≤ c :=
by simpa using cof_le_card c.ord
@[simp] theorem cof_zero : cof 0 = 0 :=
le_antisymm (by simpa using cof_le_card 0) (cardinal.zero_le _)
@[simp] theorem cof_eq_zero {o} : cof o = 0 ↔ o = 0 :=
⟨induction_on o $ λ α r _ z, by exactI
let ⟨S, hl, e⟩ := cof_eq r in type_eq_zero_iff_empty.2 $
λ ⟨a⟩, let ⟨b, h, _⟩ := hl a in
ne_zero_iff_nonempty.2 (by exact ⟨⟨_, h⟩⟩) (e.trans z),
λ e, by simp [e]⟩
@[simp] theorem cof_succ (o) : cof (succ o) = 1 :=
begin
apply le_antisymm,
{ refine induction_on o (λ α r _, _),
change cof (type _) ≤ _,
rw [← (_ : mk _ = 1)], apply cof_type_le,
{ refine λ a, ⟨sum.inr ⟨()⟩, set.mem_singleton _, _⟩,
rcases a with a|⟨⟨⟨⟩⟩⟩; simp [empty_relation] },
{ rw [cardinal.fintype_card, set.card_singleton], simp } },
{ rw [← cardinal.succ_zero, cardinal.succ_le],
simpa [lt_iff_le_and_ne, cardinal.zero_le] using
λ h, succ_ne_zero o (cof_eq_zero.1 (eq.symm h)) }
end
@[simp] theorem cof_eq_one_iff_is_succ {o} : cof.{u} o = 1 ↔ ∃ a, o = succ a :=
⟨induction_on o $ λ α r _ z, begin
resetI,
rcases cof_eq r with ⟨S, hl, e⟩, rw z at e,
cases ne_zero_iff_nonempty.1 (by rw e; exact one_ne_zero) with a,
refine ⟨typein r a, eq.symm $ quotient.sound
⟨order_iso.of_surjective (order_embedding.of_monotone _
(λ x y, _)) (λ x, _)⟩⟩,
{ apply sum.rec; [exact subtype.val, exact λ _, a] },
{ rcases x with x|⟨⟨⟨⟩⟩⟩; rcases y with y|⟨⟨⟨⟩⟩⟩;
simp [subrel, order.preimage, empty_relation],
exact x.2 },
{ suffices : r x a ∨ ∃ (b : ulift unit), ↑a = x, {simpa},
rcases trichotomous_of r x a with h|h|h,
{ exact or.inl h },
{ exact or.inr ⟨⟨()⟩, h.symm⟩ },
{ rcases hl x with ⟨a', aS, hn⟩,
rw (_ : ↑a = a') at h, {exact absurd h hn},
refine congr_arg subtype.val (_ : a = ⟨a', aS⟩),
haveI := le_one_iff_subsingleton.1 (le_of_eq e),
apply subsingleton.elim } }
end, λ ⟨a, e⟩, by simp [e]⟩
@[simp] theorem cof_add (a b : ordinal) : b ≠ 0 → cof (a + b) = cof b :=
induction_on a $ λ α r _, induction_on b $ λ β s _ b0, begin
resetI,
change cof (type _) = _,
refine eq_of_forall_le_iff (λ c, _),
rw [le_cof_type, le_cof_type],
split; intros H S hS,
{ refine le_trans (H {a | sum.rec_on a (∅:set α) S} (λ a, _)) ⟨⟨_, _⟩⟩,
{ cases a with a b,
{ cases type_ne_zero_iff_nonempty.1 b0 with b,
rcases hS b with ⟨b', bs, _⟩,
exact ⟨sum.inr b', bs, by simp⟩ },
{ rcases hS b with ⟨b', bs, h⟩,
exact ⟨sum.inr b', bs, by simp [h]⟩ } },
{ exact λ a, match a with ⟨sum.inr b, h⟩ := ⟨b, h⟩ end },
{ exact λ a b, match a, b with
⟨sum.inr a, h₁⟩, ⟨sum.inr b, h₂⟩, h := by congr; injection h
end } },
{ refine le_trans (H (sum.inr ⁻¹' S) (λ a, _)) ⟨⟨_, _⟩⟩,
{ rcases hS (sum.inr a) with ⟨a'|b', bs, h⟩; simp at h,
{ cases h }, { exact ⟨b', bs, h⟩ } },
{ exact λ ⟨a, h⟩, ⟨_, h⟩ },
{ exact λ ⟨a, h₁⟩ ⟨b, h₂⟩ h,
by injection h with h; congr; injection h } }
end
@[simp] theorem cof_cof (o : ordinal) : cof (cof o).ord = cof o :=
le_antisymm (le_trans (cof_le_card _) (by simp)) $
induction_on o $ λ α r _, by exactI
let ⟨S, hS, e₁⟩ := ord_cof_eq r,
⟨T, hT, e₂⟩ := cof_eq (subrel r S) in begin
rw e₁ at e₂, rw ← e₂,
refine le_trans (cof_type_le {a | ∃ h, (subtype.mk a h : S) ∈ T} (λ a, _)) ⟨⟨_, _⟩⟩,
{ rcases hS a with ⟨b, bS, br⟩,
rcases hT ⟨b, bS⟩ with ⟨c, cT, cs⟩, cases c with c cS,
exact ⟨c, ⟨cS, cT⟩, is_order_connected.neg_trans r cs br⟩ },
{ exact λ ⟨a, h⟩, ⟨⟨a, h.fst⟩, h.snd⟩ },
{ exact λ ⟨a, ha⟩ ⟨b, hb⟩ h,
by injection h with h; congr; injection h },
end
theorem omega_le_cof {o} : cardinal.omega ≤ cof o ↔ is_limit o :=
begin
rcases zero_or_succ_or_limit o with rfl|⟨o,rfl⟩|l,
{ simp [not_zero_is_limit, cardinal.omega_pos] },
{ simp [not_succ_is_limit, cardinal.one_lt_omega] },
{ simp [l], refine le_of_not_lt (λ h, _),
cases cardinal.lt_omega.1 h with n e,
have := cof_cof o,
rw [e, ord_nat] at this,
cases n,
{ simp at e, simpa [e, not_zero_is_limit] using l },
{ rw [← nat_cast_succ, cof_succ] at this,
rw [← this, cof_eq_one_iff_is_succ] at e,
rcases e with ⟨a, rfl⟩,
exact not_succ_is_limit _ l } }
end
@[simp] theorem cof_omega : cof omega = cardinal.omega :=
le_antisymm
(by rw ← card_omega; apply cof_le_card)
(omega_le_cof.2 omega_is_limit)
theorem cof_eq' (r : α → α → Prop) [is_well_order α r] (h : is_limit (type r)) :
∃ S : set α, (∀ a, ∃ b ∈ S, r a b) ∧ mk S = cof (type r) :=
let ⟨S, H, e⟩ := cof_eq r in
⟨S, λ a,
let a' := enum r _ (h.2 _ (typein_lt_type r a)) in
let ⟨b, h, ab⟩ := H a' in
⟨b, h, (is_order_connected.conn a b a' $ (typein_lt_typein r).1
(by rw typein_enum; apply ordinal.lt_succ_self)).resolve_right ab⟩,
e⟩
theorem cof_sup_le_lift {ι} (f : ι → ordinal) (H : ∀ i, f i < sup f) :
cof (sup f) ≤ (mk ι).lift :=
begin
generalize e : sup f = o,
refine ordinal.induction_on o _ e, introsI α r _ e',
rw e' at H,
refine le_trans (cof_type_le (set.range (λ i, enum r _ (H i))) _)
⟨embedding.of_surjective _⟩,
{ intro a, by_contra h,
apply not_le_of_lt (typein_lt_type r a),
rw [← e', sup_le],
intro i,
simp [set.range] at h,
simpa using le_of_lt ((typein_lt_typein r).2 (h _ i rfl)) },
{ exact λ i, ⟨_, set.mem_range_self i.1⟩ },
{ intro a, rcases a with ⟨_, i, rfl⟩, exact ⟨⟨i⟩, by simp⟩ }
end
theorem cof_sup_le {ι} (f : ι → ordinal) (H : ∀ i, f i < sup.{u u} f) :
cof (sup.{u u} f) ≤ mk ι :=
by simpa using cof_sup_le_lift.{u u} f H
theorem cof_bsup_le_lift {o : ordinal} : ∀ (f : Π a < o, ordinal), (∀ i h, f i h < bsup o f) →
cof (bsup o f) ≤ o.card.lift :=
induction_on o $ λ α r _ f H,
by rw bsup_type; refine cof_sup_le_lift _ _;
rw ← bsup_type; intro a; apply H
theorem cof_bsup_le {o : ordinal} : ∀ (f : Π a < o, ordinal), (∀ i h, f i h < bsup.{u u} o f) →
cof (bsup.{u u} o f) ≤ o.card :=
induction_on o $ λ α r _ f H,
by simpa using cof_bsup_le_lift.{u u} f H
@[simp] theorem cof_univ : cof univ.{u v} = cardinal.univ :=
le_antisymm (cof_le_card _) begin
refine le_of_forall_lt (λ c h, _),
rcases lt_univ'.1 h with ⟨c, rfl⟩,
rcases @cof_eq ordinal.{u} (<) _ with ⟨S, H, Se⟩,
rw [univ, ← lift_cof, ← cardinal.lift_lift, cardinal.lift_lt, ← Se],
refine lt_of_not_ge (λ h, _),
cases cardinal.lift_down h with a e,
refine quotient.induction_on a (λ α e, _) e,
cases quotient.exact e with f,
have f := equiv.ulift.symm.trans f,
let g := λ a, (f a).1,
let o := succ (sup.{u u} g),
rcases H o with ⟨b, h, l⟩,
refine l (lt_succ.2 _),
rw ← show g (f.symm ⟨b, h⟩) = b, by dsimp [g]; simp,
apply le_sup
end
end ordinal
namespace cardinal
open ordinal
local infixr ^ := @pow cardinal.{u} cardinal cardinal.has_pow
/-- A cardinal is a limit if it is not zero or a successor
cardinal. Note that `ω` is a limit cardinal by this definition. -/
def is_limit (c : cardinal) : Prop :=
c ≠ 0 ∧ ∀ x < c, succ x < c
/-- A cardinal is a strong limit if it is not zero and it is
closed under powersets. Note that `ω` is a strong limit by this definition. -/
def is_strong_limit (c : cardinal) : Prop :=
c ≠ 0 ∧ ∀ x < c, 2 ^ x < c
theorem is_strong_limit.is_limit {c} (H : is_strong_limit c) : is_limit c :=
⟨H.1, λ x h, lt_of_le_of_lt (succ_le.2 $ cantor _) (H.2 _ h)⟩
/-- A cardinal is regular if it is infinite and it equals its own cofinality. -/
def is_regular (c : cardinal) : Prop :=
omega ≤ c ∧ c.ord.cof = c
theorem cof_is_regular {o : ordinal} (h : o.is_limit) : is_regular o.cof :=
⟨omega_le_cof.2 h, cof_cof _⟩
theorem omega_is_regular {o : ordinal} (h : o.is_limit) : is_regular omega :=
⟨le_refl _, by simp⟩
theorem succ_is_regular {c : cardinal.{u}} (h : omega ≤ c) : is_regular (succ c) :=
⟨le_trans h (le_of_lt $ lt_succ_self _), begin
refine le_antisymm (cof_ord_le _) (succ_le.2 _),
cases quotient.exists_rep (succ c) with α αe, simp at αe,
rcases ord_eq α with ⟨r, wo, re⟩, resetI,
have := ord_is_limit (le_trans h $ le_of_lt $ lt_succ_self _),
rw [← αe, re] at this ⊢,
rcases cof_eq' r this with ⟨S, H, Se⟩,
rw [← Se],
apply le_imp_le_iff_lt_imp_lt.1 (mul_le_mul_right c),
rw [mul_eq_self h, ← succ_le, ← αe, ← sum_const],
refine le_trans _ (sum_le_sum (λ x:S, card (typein r x)) _ _),
{ simp [typein, sum_mk (λ x:S, {a//r a x})],
refine ⟨embedding.of_surjective _⟩,
{ exact λ x, x.2.1 },
{ exact λ a, let ⟨b, h, ab⟩ := H a in ⟨⟨⟨_, h⟩, _, ab⟩, rfl⟩ } },
{ intro i,
rw [← lt_succ, ← lt_ord, ← αe, re],
apply typein_lt_type }
end⟩
/-- A cardinal is inaccessible if it is an
uncountable regular strong limit cardinal. -/
def is_inaccessible (c : cardinal) :=
omega < c ∧ is_regular c ∧ is_strong_limit c
theorem is_inaccessible.mk {c}
(h₁ : omega < c) (h₂ : c ≤ c.ord.cof) (h₃ : ∀ x < c, 2 ^ x < c) :
is_inaccessible c :=
⟨h₁, ⟨le_of_lt h₁, le_antisymm (cof_ord_le _) h₂⟩,
ne_of_gt (lt_trans omega_pos h₁), h₃⟩
/- Lean's foundations prove the existence of ω many inaccessible
cardinals -/
theorem univ_inaccessible : is_inaccessible (univ.{u v}) :=
is_inaccessible.mk
(by simpa using lift_lt_univ' omega)
(by simp)
(λ c h, begin
rcases lt_univ'.1 h with ⟨c, rfl⟩,
rw ← lift_two_power.{u (max (u+1) v)},
apply lift_lt_univ'
end)
theorem lt_power_cof {c : cardinal.{u}} : omega ≤ c → c < c ^ cof c.ord :=
quotient.induction_on c $ λ α h, begin
rcases ord_eq α with ⟨r, wo, re⟩, resetI,
have := ord_is_limit h,
rw [mk_def, re] at this ⊢,
rcases cof_eq' r this with ⟨S, H, Se⟩,
have := sum_lt_prod (λ a:S, mk {x // r x a}) (λ _, mk α) (λ i, _),
{ simp [Se.symm] at this ⊢,
refine lt_of_le_of_lt _ this,
refine ⟨embedding.of_surjective _⟩,
{ exact λ x, x.2.1 },
{ exact λ a, let ⟨b, h, ab⟩ := H a in ⟨⟨⟨_, h⟩, _, ab⟩, rfl⟩ } },
{ have := typein_lt_type r i,
rwa [← re, lt_ord] at this }
end
theorem lt_cof_power {a b : cardinal} (ha : omega ≤ a) (b1 : 1 < b) :
a < cof (b ^ a).ord :=
begin
have b0 : b ≠ 0 := ne_of_gt (lt_trans zero_lt_one b1),
apply le_imp_le_iff_lt_imp_lt.1 (power_le_power_left $ power_ne_zero a b0),
rw [power_mul, mul_eq_self ha],
exact lt_power_cof (le_trans ha $ le_of_lt $ cantor' _ b1),
end
end cardinal
|
463a67d2c202b3929f493cd0974fcb9626d7d382 | 90edd5cdcf93124fe15627f7304069fdce3442dd | /stage0/src/Lean/Aesop/MutAltTree.lean | 9119148cb326de850404df5ae5c59ee056670ddd | [
"Apache-2.0"
] | permissive | JLimperg/lean4-aesop | 8a9d9cd3ee484a8e67fda2dd9822d76708098712 | 5c4b9a3e05c32f69a4357c3047c274f4b94f9c71 | refs/heads/master | 1,689,415,944,104 | 1,627,383,284,000 | 1,627,383,284,000 | 377,536,770 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 5,201 | lean | /-
Copyright (c) 2021 Jannis Limperg. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jannis Limperg
-/
import Lean.Aesop.Util
universe u
namespace Lean.Aesop
/-! ## Unsafe Construction of `MutAltTree` -/
namespace MutAltTree.Internal
-- Workaround for a compiler bug(?).
-- https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/Defining.20mutable.20rose.20trees
private abbrev Ref σ α := ST.Ref σ α
-- Note that α and ω are not really parameters, and indeed the mk constructor
-- has type `{α ω : Type} → ...`. But if we change the signature to
--
-- MutAltTreeImp (σ : Type) : Type → Type → Type
--
-- the compiler fails.
unsafe inductive MutAltTreeImp (σ α ω : Type) : Type
| mk
(payload : α)
(parent : Option (Ref σ (MutAltTreeImp σ ω α)))
(children : Array (Ref σ (MutAltTreeImp σ ω α)))
structure MutAltTreeSpec (σ) where
MutAltTree : Type → Type → Type
construct :
α →
Option (ST.Ref σ (MutAltTree ω α)) →
Array (ST.Ref σ (MutAltTree ω α)) →
MutAltTree α ω
payload : MutAltTree α ω → α
parent : MutAltTree α ω → Option (Ref σ (MutAltTree ω α))
children : MutAltTree α ω → Array (ST.Ref σ (MutAltTree ω α))
open MutAltTreeImp in
unsafe def MutAltTreeSpecImp σ : MutAltTreeSpec σ where
MutAltTree := MutAltTreeImp σ
construct := mk
payload := fun t => match t with | (mk x _ _) => x
-- The syntax `payload | (mk x _ _) => x` doesn't work here for some reason.
parent := fun t => match t with | (mk _ x _) => x
children := fun t => match t with | (mk _ _ x) => x
@[implementedBy MutAltTreeSpecImp]
constant mutAltTreeSpec σ : MutAltTreeSpec σ := {
MutAltTree := fun α ω => α
construct := fun a _ _ => a
payload := fun a => a
parent := fun _ => arbitrary
children := fun _ => arbitrary
}
end MutAltTree.Internal
open MutAltTree.Internal (mutAltTreeSpec)
/-! ## `MutAltTree` -/
def MutAltTree (σ α ω : Type) : Type :=
(mutAltTreeSpec σ).MutAltTree α ω
abbrev MATRef σ α ω := ST.Ref σ (MutAltTree σ α ω)
namespace MutAltTree
/-! ### Constructors -/
@[inline]
def mk : α → Option (MATRef σ ω α) → Array (MATRef σ ω α) → MutAltTree σ α ω :=
(mutAltTreeSpec σ).construct
instance [Inhabited α] : Inhabited (MutAltTree σ α ω) where
default := mk arbitrary none #[]
/-! ### Getters -/
section Getters
variable (t : MutAltTree σ α ω)
@[inline]
def payload : α :=
(mutAltTreeSpec σ).payload t
@[inline]
def parent : Option (MATRef σ ω α) :=
(mutAltTreeSpec σ).parent t
@[inline]
def children : Array (MATRef σ ω α) :=
(mutAltTreeSpec σ).children t
end Getters
/-! ### Setters -/
@[inline]
def setPayload (a : α) (t : MutAltTree σ α ω) : MutAltTree σ α ω :=
mk a (parent t) (children t)
@[inline]
def setParent (parent : Option (MATRef σ ω α)) (t : MutAltTree σ α ω) : MutAltTree σ α ω :=
mk (payload t) parent (children t)
@[inline]
def setChildren (children : Array (MATRef σ ω α)) (t : MutAltTree σ α ω) :
MutAltTree σ α ω :=
mk (payload t) (parent t) children
/-! ### 'Lenses' -/
@[inline]
def modifyPayload (f : α → α) (t : MutAltTree σ α ω) : MutAltTree σ α ω :=
t.setPayload $ f t.payload
@[inline]
def modifyParent (f : Option (MATRef σ ω α) → Option (MATRef σ ω α))
(t : MutAltTree σ α ω) : MutAltTree σ α ω :=
t.setParent $ f t.parent
@[inline]
def modifyChildren (f : Array (MATRef σ ω α) → Array (MATRef σ ω α))
(t : MutAltTree σ α ω) : MutAltTree σ α ω :=
t.setChildren $ f t.children
/-! ### Traversals -/
variable {σ m} [Monad m] [MonadLiftT (ST σ) m]
partial def visitDown (fα : MATRef σ α ω → m Bool) (fω : MATRef σ ω α → m Bool)
(tref : MATRef σ α ω) : m Unit := do
let continue? ← fα tref
if continue? then
(← tref.get).children.forM $ visitDown fω fα
@[inline]
def visitDown' (fα : MATRef σ α ω → m Bool) (fω : MATRef σ ω α → m Bool) :
Sum (MATRef σ α ω) (MATRef σ ω α) → m Unit
| Sum.inl tref => visitDown fα fω tref
| Sum.inr tref => visitDown fω fα tref
partial def visitUp (fα : MATRef σ α ω → m Bool) (fω : MATRef σ ω α → m Bool)
(tref : MATRef σ α ω) : m Unit := do
let continue? ← fα tref
if continue? then
match (← tref.get).parent with
| none => return ()
| some parent => visitUp fω fα parent
@[inline]
def visitUp'
(fα : MATRef σ α ω → m Bool) (fω : MATRef σ ω α → m Bool) :
Sum (MATRef σ α ω) (MATRef σ ω α) → m Unit
| Sum.inl tref => visitUp fα fω tref
| Sum.inr tref => visitUp fω fα tref
/-! ### Miscellaneous -/
@[inline]
def addChild (c : MATRef σ ω α) (t : MutAltTree σ α ω) : MutAltTree σ α ω :=
t.modifyChildren $ λ cs => cs.push c
def siblings (tref : MATRef σ α ω) : m (Array (MATRef σ α ω)) := do
let t ← tref.get
let (some parent) ← pure t.parent | return #[]
let children := (← parent.get).children
return (← children.filterM λ cref => return not (← cref.ptrEq tref))
end Lean.Aesop.MutAltTree
|
e5d9846ae9dbd636576e90f30f2d117c8e50e5d2 | 406917967313cd8926a5a79666c51fad41d8670f | /lib/Main.lean | ab8794167a6c4bd222c8a850d05aa0adcb931378 | [
"MIT"
] | permissive | hargoniX/lean4-statvfs | a3c15f51e2714f9fd5a77725fc618831838b46ae | 458370ad201d2c2820189a474fd8701ff7a940c5 | refs/heads/main | 1,693,550,798,436 | 1,634,894,543,000 | 1,634,894,543,000 | 417,835,011 | 1 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 565 | lean | /-
Copyright (c) 2021 Henrik Böving. All rights reserved.
Released under MIT license as described in the file LICENSE.
Authors: Henrik Böving
-/
import Statvfs
open System
def main (args : List String) : IO UInt32 := do
if h : args = [] then
IO.println "Missing argument: path"
return 1
else
let path <- FilePath.mk $ args.head h
if h2 : !(←path.pathExists) then
IO.println "Invalid path"
return 1
let stat <- Statvfs.of_path path
IO.println "Printing statvfs information"
IO.println $ repr stat
return 0
|
f02e654d234a2520dc915a28b267db32e42a6097 | 947b78d97130d56365ae2ec264df196ce769371a | /tests/lean/run/def16.lean | ff03909d5696308cbc22b6a238db20c251edefdb | [
"Apache-2.0"
] | permissive | shyamalschandra/lean4 | 27044812be8698f0c79147615b1d5090b9f4b037 | 6e7a883b21eaf62831e8111b251dc9b18f40e604 | refs/heads/master | 1,671,417,126,371 | 1,601,859,995,000 | 1,601,860,020,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 282 | lean | new_frontend
def half : Nat → Nat
| 0 => 0
| 1 => 0
| (x+2) => half x + 1
theorem half0 : half 0 = 0 :=
rfl
theorem half1 : half 1 = 0 :=
rfl
theorem half_succ_succ (a : Nat) : half (a + 2) = half a + 1 :=
rfl
example : half 5 = 2 :=
rfl
example : half 8 = 4 :=
rfl
|
25d0047386e2b20292d76049d415a87e86105953 | 1cc8cf59a317bf12d71a5a8ed03bfc1948c66f10 | /src/problem_sheets/sheet_1/sht01Q01.lean | 54499f4c182822d132ad1789158d786be8c28ae4 | [
"Apache-2.0"
] | permissive | kckennylau/M1P1-lean | 1e4fabf513539669f86a439af6844aa078c239ad | c92e524f3e4e7aec5dc09e05fb8923cc9720dd34 | refs/heads/master | 1,587,503,976,663 | 1,549,715,955,000 | 1,549,715,955,000 | 169,875,735 | 1 | 0 | Apache-2.0 | 1,549,722,917,000 | 1,549,722,917,000 | null | UTF-8 | Lean | false | false | 3,094 | lean | -- This import gives us a working copy of the real numbers ℝ,
-- and functions such as abs : ℝ → ℝ
import data.real.basic
-- This next import gives us several tactics of use to mathematicians:
-- (1) norm_num [to prove basic facts about reals like 2+2 = 4]
-- (2) ring [to prove basic algebra identities like (a+b)^2 = a^2+2ab+b^2]
-- (3) linarith [to prove basic inequalities like x > 0 -> x/2 > 0]
import tactic.linarith
-- These lines switch Lean into "maths proof mode" -- don't worry about them.
-- Basically they tell Lean to use the axiom of choice and the
-- law of the excluded middle, two standard maths facts.
noncomputable theory
local attribute [instance, priority 0] classical.prop_decidable
-- the maths starts here.
-- We introduce the usual mathematical notation for absolute value
local notation `|` x `|` := abs x
theorem Q1a (x y : ℝ) : | x + y | ≤ | x | + | y | :=
begin
-- Lean's definition of abs is abs x = max (x, -x)
-- [or max x (-x), as the computer scientists would write it]
unfold abs,
-- lean's definition of max a b is "if a<=b then b else a"
unfold max,
-- We now have a complicated statement with three "if"s in.
split_ifs,
-- We now have 2^3=8 goals corresponding to all the possibilities
-- x>=0 or x<0, y>=0 or y<0, (x+y)>=0 or (x+y)<0.
repeat {linarith},
-- all of them are easily solvable using the linarith tactic.
end
-- We can solve the remaining parts using part (a).
theorem Q1b (x y : ℝ) : |x + y| ≥ |x| - |y| :=
begin
-- Apply Q1a to x+y and -y, then follow your nose.
have h := Q1a (x + y) (-y),
simp at h,
linarith,
end
theorem Q1c (x y : ℝ) : |x + y| ≥ |y| - |x| :=
begin
-- Apply Q1a to x+y and -x, then follow your nose.
have h := Q1a (x + y) (-x),
simp at h,
linarith,
end
theorem Q1d (x y : ℝ) : |x - y| ≥ | |x| - |y| | :=
begin
-- Lean prefers ≤ to ≥
show _ ≤ _,
-- for this one we need to apply the result that |X| ≤ B ↔ -B ≤ X and X ≤ B
rw abs_le,
-- Now we have two goals:
-- first -|x - y| ≤ |x| - |y|
-- and second |x| - |y| ≤ |x - y|.
-- So we need to split.
split,
{ -- -|x - y| ≤ |x| - |y|
have h := Q1a (x - y) (-x),
simp at *,
linarith },
{ -- |x| - |y| ≤ |x - y|
have h := Q1a (x - y) y,
simp at *,
linarith}
end
theorem Q1e (x y : ℝ) : |x| ≤ |y| + |x - y| :=
begin
have h := Q1a y (x - y),
simp * at *,
end
theorem Q1f (x y : ℝ) : |x| ≥ |y| - |x - y| :=
begin
have h := Q1a (x - y) (-x),
simp * at *,
linarith,
end
theorem Q1g (x y z : ℝ) : |x - y| ≤ |x - z| + |y - z| :=
begin
have h := Q1a (x - z) (z - y),
-- Lean needs more hints with this one.
-- First let's change that y - z into z - y,
rw ←abs_neg (y - z),
-- now get everything into some sort of normal form
simp * at *,
-- unfortunately Lean didn't yet simplify x + (z + (-y + -z))
-- The "convert" tactic says "OK the goal should equal this, so
-- replace the goal with all the bits that aren't exactly equal"
convert h,
-- now we need to prove -y = z + (-y + -z)!
ring,
end
|
4d256d11dd129f538d8be27fa86a1d6ab5ce4aab | 5c7fe6c4a9d4079b5457ffa5f061797d42a1cd65 | /src/exercises/src_04_theorems.lean | aa88559d3de4514c1a4db6bdd7595808c4cee516 | [] | no_license | gihanmarasingha/mth1001_tutorial | 8e0817feeb96e7c1bb3bac49b63e3c9a3a329061 | bb277eebd5013766e1418365b91416b406275130 | refs/heads/master | 1,675,008,746,310 | 1,607,993,443,000 | 1,607,993,443,000 | 321,511,270 | 3 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 2,642 | lean | variables p q r : Prop
namespace mth1001
section theorems
-- Exercise 028:
/-
A theorem is a mechanism for naming a result. By _applying_ a theorem, we can produce new results.
Here is a theorem with its proof left as an exercise.
-/
theorem and_of_and : p ∧ q → q ∧ p :=
begin
sorry
end
/-
The _type_ of any expression can be printed to the Infoview using `#check`.
The type of `and_of_and` is
`∀ (p q : Prop), p ∧ q → q ∧ p`
This means that the theorem takes `p` and `q` propositions (i.e. terms of
type `Prop`) and returns a proof of `p ∧ q → q ∧ p`.
The symbol `∀` is read as 'for all' or 'for every' and is called the
universal quantifier. We'll return to a full explanation of `∀` later.
-/
#check and_of_and
/-
We apply this theorem by subsituting other quantities for `p` and `q`.]
Below, we take `q → r` for `p` and `q ∧ p` for `q` in `and_of_and`.
-/
example : (q → r) ∧ (q ∧ p) → (q ∧ p) ∧ (q → r) :=
and_of_and (q → r) (q ∧ p)
-- Even better, Lean can often infer the arguments to theorems if they
-- are replaced with the `_` placeholder:
example : (q → r) ∧ (q ∧ p) → (q ∧ p) ∧ (q → r) :=
and_of_and _ _
-- We can apply theorems in tactic mode. Using `exact` mimics the term-style proof.
example : (q → r) ∧ (q ∧ p) → (q ∧ p) ∧ (q → r) :=
begin
exact and_of_and _ _,
end
/-
We don't need to use `_` here to explicitly request argument inference; the `apply` tactic
does this automatically.
-/
example : (q → r) ∧ (q ∧ p) → (q ∧ p) ∧ (q → r) :=
begin
apply and_of_and,
end
-- Exercise 029:
-- Give either a tactic-style or term-style proof of the following.
theorem and_assoc1 : (p ∧ q) ∧ r → p ∧ (q ∧ r) :=
sorry
-- Exercise 030:
-- Using the previous theorem, give a one-line proof of the following.
example (a b : Prop) : ((a → b) ∧ b) ∧ (b → a) → (a → b) ∧ (b ∧ (b → a)) :=
sorry
-- Exercise 031:
/-
The next example is more challenging. Use `intro`, `apply`, `exact`,
and the previous two theorems.
-/
example (a b : Prop) : ((a → b) ∧ b) ∧ (b → a) → (b ∧ (b → a)) ∧ (a → b) :=
begin
sorry end
variables s t u : Prop
-- Exercise 032:
/-
Complete the following proof. The only tactics you are permitted to use are `apply` and `exact`
(each as many times as you like). You can only use these tactics with `and_of_and`,
`and_assoc`, or `h`.
-/
theorem and_assoc2 : s ∧ (t ∧ u) → (s ∧ t) ∧ u :=
begin
intro h,
sorry
end
end theorems
/-
SUMMARY:
* Theorems in Lean.
* `#check` to find the type of a theorem.
* Using theorems.
-/
end mth1001
|
9c7cfcfd6bf11fbb317c0fc62b18378ed9dedd3c | 302c785c90d40ad3d6be43d33bc6a558354cc2cf | /src/data/finset/fold.lean | 791971ddb90f2a8208529b7e2f1d4b5bcd78defc | [
"Apache-2.0"
] | permissive | ilitzroth/mathlib | ea647e67f1fdfd19a0f7bdc5504e8acec6180011 | 5254ef14e3465f6504306132fe3ba9cec9ffff16 | refs/heads/master | 1,680,086,661,182 | 1,617,715,647,000 | 1,617,715,647,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 5,786 | lean | /-
Copyright (c) 2017 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import data.finset.basic
import data.multiset.fold
/-!
# The fold operation for a commutative associative operation over a finset.
-/
namespace finset
open multiset
variables {α β γ : Type*}
/-! ### fold -/
section fold
variables (op : β → β → β) [hc : is_commutative β op] [ha : is_associative β op]
local notation a * b := op a b
include hc ha
/-- `fold op b f s` folds the commutative associative operation `op` over the
`f`-image of `s`, i.e. `fold (+) b f {1,2,3} = `f 1 + f 2 + f 3 + b`. -/
def fold (b : β) (f : α → β) (s : finset α) : β := (s.1.map f).fold op b
variables {op} {f : α → β} {b : β} {s : finset α} {a : α}
@[simp] theorem fold_empty : (∅ : finset α).fold op b f = b := rfl
@[simp] theorem fold_insert [decidable_eq α] (h : a ∉ s) :
(insert a s).fold op b f = f a * s.fold op b f :=
by unfold fold; rw [insert_val, ndinsert_of_not_mem h, map_cons, fold_cons_left]
@[simp] theorem fold_singleton : ({a} : finset α).fold op b f = f a * b := rfl
@[simp] theorem fold_map {g : γ ↪ α} {s : finset γ} :
(s.map g).fold op b f = s.fold op b (f ∘ g) :=
by simp only [fold, map, multiset.map_map]
@[simp] theorem fold_image [decidable_eq α] {g : γ → α} {s : finset γ}
(H : ∀ (x ∈ s) (y ∈ s), g x = g y → x = y) : (s.image g).fold op b f = s.fold op b (f ∘ g) :=
by simp only [fold, image_val_of_inj_on H, multiset.map_map]
@[congr] theorem fold_congr {g : α → β} (H : ∀ x ∈ s, f x = g x) : s.fold op b f = s.fold op b g :=
by rw [fold, fold, map_congr H]
theorem fold_op_distrib {f g : α → β} {b₁ b₂ : β} :
s.fold op (b₁ * b₂) (λx, f x * g x) = s.fold op b₁ f * s.fold op b₂ g :=
by simp only [fold, fold_distrib]
theorem fold_hom {op' : γ → γ → γ} [is_commutative γ op'] [is_associative γ op']
{m : β → γ} (hm : ∀x y, m (op x y) = op' (m x) (m y)) :
s.fold op' (m b) (λx, m (f x)) = m (s.fold op b f) :=
by rw [fold, fold, ← fold_hom op hm, multiset.map_map]
theorem fold_union_inter [decidable_eq α] {s₁ s₂ : finset α} {b₁ b₂ : β} :
(s₁ ∪ s₂).fold op b₁ f * (s₁ ∩ s₂).fold op b₂ f = s₁.fold op b₂ f * s₂.fold op b₁ f :=
by unfold fold; rw [← fold_add op, ← map_add, union_val,
inter_val, union_add_inter, map_add, hc.comm, fold_add]
@[simp] theorem fold_insert_idem [decidable_eq α] [hi : is_idempotent β op] :
(insert a s).fold op b f = f a * s.fold op b f :=
begin
by_cases (a ∈ s),
{ rw [← insert_erase h], simp [← ha.assoc, hi.idempotent] },
{ apply fold_insert h },
end
lemma fold_op_rel_iff_and
{r : β → β → Prop} (hr : ∀ {x y z}, r x (op y z) ↔ (r x y ∧ r x z)) {c : β} :
r c (s.fold op b f) ↔ (r c b ∧ ∀ x∈s, r c (f x)) :=
begin
classical,
apply finset.induction_on s, { simp },
clear s, intros a s ha IH,
rw [finset.fold_insert ha, hr, IH, ← and_assoc, and_comm (r c (f a)), and_assoc],
apply and_congr iff.rfl,
split,
{ rintro ⟨h₁, h₂⟩, intros b hb, rw finset.mem_insert at hb,
rcases hb with rfl|hb; solve_by_elim },
{ intro h, split,
{ exact h a (finset.mem_insert_self _ _), },
{ intros b hb, apply h b, rw finset.mem_insert, right, exact hb } }
end
lemma fold_op_rel_iff_or
{r : β → β → Prop} (hr : ∀ {x y z}, r x (op y z) ↔ (r x y ∨ r x z)) {c : β} :
r c (s.fold op b f) ↔ (r c b ∨ ∃ x∈s, r c (f x)) :=
begin
classical,
apply finset.induction_on s, { simp },
clear s, intros a s ha IH,
rw [finset.fold_insert ha, hr, IH, ← or_assoc, or_comm (r c (f a)), or_assoc],
apply or_congr iff.rfl,
split,
{ rintro (h₁|⟨x, hx, h₂⟩),
{ use a, simp [h₁] },
{ refine ⟨x, by simp [hx], h₂⟩ } },
{ rintro ⟨x, hx, h⟩,
rw mem_insert at hx, cases hx,
{ left, rwa hx at h },
{ right, exact ⟨x, hx, h⟩ } }
end
omit hc ha
@[simp]
lemma fold_union_empty_singleton [decidable_eq α] (s : finset α) :
finset.fold (∪) ∅ singleton s = s :=
begin
apply finset.induction_on s,
{ simp only [fold_empty], },
{ intros a s has ih, rw [fold_insert has, ih, insert_eq], }
end
lemma fold_sup_bot_singleton [decidable_eq α] (s : finset α) :
finset.fold (⊔) ⊥ singleton s = s :=
fold_union_empty_singleton s
section order
variables [linear_order β] (c : β)
lemma le_fold_min : c ≤ s.fold min b f ↔ (c ≤ b ∧ ∀ x∈s, c ≤ f x) :=
fold_op_rel_iff_and $ λ x y z, le_min_iff
lemma fold_min_le : s.fold min b f ≤ c ↔ (b ≤ c ∨ ∃ x∈s, f x ≤ c) :=
begin
show _ ≥ _ ↔ _,
apply fold_op_rel_iff_or,
intros x y z,
show _ ≤ _ ↔ _,
exact min_le_iff
end
lemma lt_fold_min : c < s.fold min b f ↔ (c < b ∧ ∀ x∈s, c < f x) :=
fold_op_rel_iff_and $ λ x y z, lt_min_iff
lemma fold_min_lt : s.fold min b f < c ↔ (b < c ∨ ∃ x∈s, f x < c) :=
begin
show _ > _ ↔ _,
apply fold_op_rel_iff_or,
intros x y z,
show _ < _ ↔ _,
exact min_lt_iff
end
lemma fold_max_le : s.fold max b f ≤ c ↔ (b ≤ c ∧ ∀ x∈s, f x ≤ c) :=
begin
show _ ≥ _ ↔ _,
apply fold_op_rel_iff_and,
intros x y z,
show _ ≤ _ ↔ _,
exact max_le_iff
end
lemma le_fold_max : c ≤ s.fold max b f ↔ (c ≤ b ∨ ∃ x∈s, c ≤ f x) :=
fold_op_rel_iff_or $ λ x y z, le_max_iff
lemma fold_max_lt : s.fold max b f < c ↔ (b < c ∧ ∀ x∈s, f x < c) :=
begin
show _ > _ ↔ _,
apply fold_op_rel_iff_and,
intros x y z,
show _ < _ ↔ _,
exact max_lt_iff
end
lemma lt_fold_max : c < s.fold max b f ↔ (c < b ∨ ∃ x∈s, c < f x) :=
fold_op_rel_iff_or $ λ x y z, lt_max_iff
end order
end fold
end finset
|
4699c2175b4e06c9f8f8aced67ccec56bf72301e | e00ea76a720126cf9f6d732ad6216b5b824d20a7 | /src/topology/homeomorph.lean | 8c77e3ca042cd6ffc90b80cd455bd7ae5773e03c | [
"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 | 6,513 | lean | /-
Copyright (c) 2019 Reid Barton. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Patrick Massot, Sébastien Gouëzel, Zhouhang Zhou, Reid Barton
-/
import topology.subset_properties topology.dense_embedding
open set
variables {α : Type*} {β : Type*} {γ : Type*} {δ : Type*}
/-- α and β are homeomorph, also called topological isomoph -/
structure homeomorph (α : Type*) (β : Type*) [topological_space α] [topological_space β]
extends α ≃ β :=
(continuous_to_fun : continuous to_fun)
(continuous_inv_fun : continuous inv_fun)
infix ` ≃ₜ `:25 := homeomorph
namespace homeomorph
variables [topological_space α] [topological_space β] [topological_space γ] [topological_space δ]
instance : has_coe_to_fun (α ≃ₜ β) := ⟨λ_, α → β, λe, e.to_equiv⟩
lemma coe_eq_to_equiv (h : α ≃ₜ β) (a : α) : h a = h.to_equiv a := rfl
protected def refl (α : Type*) [topological_space α] : α ≃ₜ α :=
{ continuous_to_fun := continuous_id, continuous_inv_fun := continuous_id, .. equiv.refl α }
protected def trans (h₁ : α ≃ₜ β) (h₂ : β ≃ₜ γ) : α ≃ₜ γ :=
{ continuous_to_fun := h₂.continuous_to_fun.comp h₁.continuous_to_fun,
continuous_inv_fun := h₁.continuous_inv_fun.comp h₂.continuous_inv_fun,
.. equiv.trans h₁.to_equiv h₂.to_equiv }
protected def symm (h : α ≃ₜ β) : β ≃ₜ α :=
{ continuous_to_fun := h.continuous_inv_fun,
continuous_inv_fun := h.continuous_to_fun,
.. h.to_equiv.symm }
protected lemma continuous (h : α ≃ₜ β) : continuous h := h.continuous_to_fun
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
lemma range_coe (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 :=
funext h.symm.to_equiv.image_eq_preimage
lemma preimage_symm (h : α ≃ₜ β) : preimage h.symm = image h :=
(funext h.to_equiv.image_eq_preimage).symm
lemma induced_eq
{α : Type*} {β : Type*} [tα : topological_space α] [tβ : topological_space β] (h : α ≃ₜ β) :
tβ.induced h = tα :=
le_antisymm
(calc topological_space.induced ⇑h tβ ≤ _ : induced_mono (coinduced_le_iff_le_induced.1 h.symm.continuous)
... ≤ tα : by rw [induced_compose, symm_comp_self, induced_id] ; exact le_refl _)
(coinduced_le_iff_le_induced.1 h.continuous)
lemma coinduced_eq
{α : Type*} {β : Type*} [tα : topological_space α] [tβ : topological_space β] (h : α ≃ₜ β) :
tα.coinduced h = tβ :=
le_antisymm
h.continuous
begin
have : (tβ.coinduced h.symm).coinduced h ≤ tα.coinduced h := coinduced_mono h.symm.continuous,
rwa [coinduced_compose, self_comp_symm, coinduced_id] at this,
end
protected lemma embedding (h : α ≃ₜ β) : embedding h :=
⟨⟨h.induced_eq.symm⟩, h.to_equiv.injective⟩
lemma compact_image {s : set α} (h : α ≃ₜ β) : compact (h '' s) ↔ compact s :=
h.embedding.compact_iff_compact_image.symm
lemma compact_preimage {s : set β} (h : α ≃ₜ β) : compact (h ⁻¹' s) ↔ compact s :=
by rw ← image_symm; exact h.symm.compact_image
protected lemma dense_embedding (h : α ≃ₜ β) : dense_embedding h :=
{ dense := assume a, by rw [h.range_coe, closure_univ]; trivial,
inj := h.to_equiv.injective,
induced := (induced_iff_nhds_eq _).2 (assume a, by rw [← nhds_induced, h.induced_eq]) }
protected lemma is_open_map (h : α ≃ₜ β) : is_open_map h :=
begin
assume s,
rw ← h.preimage_symm,
exact h.symm.continuous s
end
protected lemma is_closed_map (h : α ≃ₜ β) : is_closed_map h :=
begin
assume s,
rw ← h.preimage_symm,
exact continuous_iff_is_closed.1 (h.symm.continuous) _
end
def homeomorph_of_continuous_open (e : α ≃ β) (h₁ : continuous e) (h₂ : is_open_map e) :
α ≃ₜ β :=
{ continuous_to_fun := h₁,
continuous_inv_fun := begin
intros s hs,
convert ← h₂ s hs using 1,
apply e.image_eq_preimage
end,
.. e }
lemma comp_continuous_on_iff (h : α ≃ₜ β) (f : γ → α) (s : set γ) :
continuous_on (h ∘ f) s ↔ continuous_on f s :=
begin
split,
{ assume H,
have : continuous_on (h.symm ∘ (h ∘ f)) s :=
h.symm.continuous.comp_continuous_on H,
rwa [← function.comp.assoc h.symm h f, symm_comp_self h] at this },
{ exact λ H, h.continuous.comp_continuous_on H }
end
lemma comp_continuous_iff (h : α ≃ₜ β) (f : γ → α) :
continuous (h ∘ f) ↔ continuous f :=
by simp [continuous_iff_continuous_on_univ, comp_continuous_on_iff]
protected lemma quotient_map (h : α ≃ₜ β) : quotient_map h :=
⟨h.to_equiv.surjective, h.coinduced_eq.symm⟩
def prod_congr (h₁ : α ≃ₜ β) (h₂ : γ ≃ₜ δ) : α × γ ≃ₜ β × δ :=
{ continuous_to_fun :=
continuous.prod_mk (h₁.continuous.comp continuous_fst) (h₂.continuous.comp continuous_snd),
continuous_inv_fun :=
continuous.prod_mk (h₁.symm.continuous.comp continuous_fst) (h₂.symm.continuous.comp continuous_snd),
.. h₁.to_equiv.prod_congr h₂.to_equiv }
section
variables (α β γ)
def prod_comm : α × β ≃ₜ β × α :=
{ continuous_to_fun := continuous.prod_mk continuous_snd continuous_fst,
continuous_inv_fun := continuous.prod_mk continuous_snd continuous_fst,
.. equiv.prod_comm α β }
def prod_assoc : (α × β) × γ ≃ₜ α × (β × γ) :=
{ continuous_to_fun :=
continuous.prod_mk (continuous_fst.comp continuous_fst)
(continuous.prod_mk (continuous_snd.comp continuous_fst) continuous_snd),
continuous_inv_fun := continuous.prod_mk
(continuous.prod_mk continuous_fst (continuous_fst.comp continuous_snd))
(continuous_snd.comp continuous_snd),
.. equiv.prod_assoc α β γ }
end
section distrib
variables {ι : Type*} {σ : ι → Type*} [Π i, topological_space (σ i)]
def sigma_prod_distrib : ((Σ i, σ i) × β) ≃ₜ (Σ i, (σ i × β)) :=
homeomorph.symm $
homeomorph_of_continuous_open (equiv.sigma_prod_distrib σ β).symm
(continuous_sigma $ λ i,
continuous.prod_mk (continuous_sigma_mk.comp continuous_fst) continuous_snd)
(is_open_map_sigma $ λ i,
(open_embedding.prod open_embedding_sigma_mk open_embedding_id).is_open_map)
end distrib
end homeomorph
|
157ee6e12bdd1088f9c6751f0d84a68ccf4d5eab | 4d2583807a5ac6caaffd3d7a5f646d61ca85d532 | /src/linear_algebra/affine_space/affine_subspace.lean | 5436e5aea11d33f093183f367ddb0e872ed43121 | [
"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 | 51,795 | lean | /-
Copyright (c) 2020 Joseph Myers. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joseph Myers
-/
import linear_algebra.affine_space.affine_equiv
import linear_algebra.tensor_product
import data.set.intervals.unordered_interval
/-!
# Affine spaces
This file defines affine subspaces (over modules) and the affine span of a set of points.
## Main definitions
* `affine_subspace k P` is the type of affine subspaces. Unlike
affine spaces, affine subspaces are allowed to be empty, and lemmas
that do not apply to empty affine subspaces have `nonempty`
hypotheses. There is a `complete_lattice` structure on affine
subspaces.
* `affine_subspace.direction` gives the `submodule` spanned by the
pairwise differences of points in an `affine_subspace`. There are
various lemmas relating to the set of vectors in the `direction`,
and relating the lattice structure on affine subspaces to that on
their directions.
* `affine_span` gives the affine subspace spanned by a set of points,
with `vector_span` giving its direction. `affine_span` is defined
in terms of `span_points`, which gives an explicit description of
the points contained in the affine span; `span_points` itself should
generally only be used when that description is required, with
`affine_span` being the main definition for other purposes. Two
other descriptions of the affine span are proved equivalent: it is
the `Inf` of affine subspaces containing the points, and (if
`[nontrivial k]`) it contains exactly those points that are affine
combinations of points in the given set.
## Implementation notes
`out_param` is used in the definiton of `add_torsor V P` to make `V` an implicit argument (deduced
from `P`) in most cases; `include V` is needed in many cases for `V`, and type classes using it, to
be added as implicit arguments to individual lemmas. As for modules, `k` is an explicit argument
rather than implied by `P` or `V`.
This file only provides purely algebraic definitions and results.
Those depending on analysis or topology are defined elsewhere; see
`analysis.normed_space.add_torsor` and `topology.algebra.affine`.
## References
* https://en.wikipedia.org/wiki/Affine_space
* https://en.wikipedia.org/wiki/Principal_homogeneous_space
-/
noncomputable theory
open_locale big_operators classical affine
open set
section
variables (k : Type*) {V : Type*} {P : Type*} [ring k] [add_comm_group V] [module k V]
variables [affine_space V P]
include V
/-- The submodule spanning the differences of a (possibly empty) set
of points. -/
def vector_span (s : set P) : submodule k V := submodule.span k (s -ᵥ s)
/-- The definition of `vector_span`, for rewriting. -/
lemma vector_span_def (s : set P) : vector_span k s = submodule.span k (s -ᵥ s) :=
rfl
/-- `vector_span` is monotone. -/
lemma vector_span_mono {s₁ s₂ : set P} (h : s₁ ⊆ s₂) : vector_span k s₁ ≤ vector_span k s₂ :=
submodule.span_mono (vsub_self_mono h)
variables (P)
/-- The `vector_span` of the empty set is `⊥`. -/
@[simp] lemma vector_span_empty : vector_span k (∅ : set P) = (⊥ : submodule k V) :=
by rw [vector_span_def, vsub_empty, submodule.span_empty]
variables {P}
/-- The `vector_span` of a single point is `⊥`. -/
@[simp] lemma vector_span_singleton (p : P) : vector_span k ({p} : set P) = ⊥ :=
by simp [vector_span_def]
/-- The `s -ᵥ s` lies within the `vector_span k s`. -/
lemma vsub_set_subset_vector_span (s : set P) : s -ᵥ s ⊆ ↑(vector_span k s) :=
submodule.subset_span
/-- Each pairwise difference is in the `vector_span`. -/
lemma vsub_mem_vector_span {s : set P} {p1 p2 : P} (hp1 : p1 ∈ s) (hp2 : p2 ∈ s) :
p1 -ᵥ p2 ∈ vector_span k s :=
vsub_set_subset_vector_span k s (vsub_mem_vsub hp1 hp2)
/-- The points in the affine span of a (possibly empty) set of
points. Use `affine_span` instead to get an `affine_subspace k P`. -/
def span_points (s : set P) : set P :=
{p | ∃ p1 ∈ s, ∃ v ∈ (vector_span k s), p = v +ᵥ p1}
/-- A point in a set is in its affine span. -/
lemma mem_span_points (p : P) (s : set P) : p ∈ s → p ∈ span_points k s
| hp := ⟨p, hp, 0, submodule.zero_mem _, (zero_vadd V p).symm⟩
/-- A set is contained in its `span_points`. -/
lemma subset_span_points (s : set P) : s ⊆ span_points k s :=
λ p, mem_span_points k p s
/-- The `span_points` of a set is nonempty if and only if that set
is. -/
@[simp] lemma span_points_nonempty (s : set P) :
(span_points k s).nonempty ↔ s.nonempty :=
begin
split,
{ contrapose,
rw [set.not_nonempty_iff_eq_empty, set.not_nonempty_iff_eq_empty],
intro h,
simp [h, span_points] },
{ exact λ h, h.mono (subset_span_points _ _) }
end
/-- Adding a point in the affine span and a vector in the spanning
submodule produces a point in the affine span. -/
lemma vadd_mem_span_points_of_mem_span_points_of_mem_vector_span {s : set P} {p : P} {v : V}
(hp : p ∈ span_points k s) (hv : v ∈ vector_span k s) : v +ᵥ p ∈ span_points k s :=
begin
rcases hp with ⟨p2, ⟨hp2, ⟨v2, ⟨hv2, hv2p⟩⟩⟩⟩,
rw [hv2p, vadd_vadd],
use [p2, hp2, v + v2, (vector_span k s).add_mem hv hv2, rfl]
end
/-- Subtracting two points in the affine span produces a vector in the
spanning submodule. -/
lemma vsub_mem_vector_span_of_mem_span_points_of_mem_span_points {s : set P} {p1 p2 : P}
(hp1 : p1 ∈ span_points k s) (hp2 : p2 ∈ span_points k s) :
p1 -ᵥ p2 ∈ vector_span k s :=
begin
rcases hp1 with ⟨p1a, ⟨hp1a, ⟨v1, ⟨hv1, hv1p⟩⟩⟩⟩,
rcases hp2 with ⟨p2a, ⟨hp2a, ⟨v2, ⟨hv2, hv2p⟩⟩⟩⟩,
rw [hv1p, hv2p, vsub_vadd_eq_vsub_sub (v1 +ᵥ p1a), vadd_vsub_assoc, add_comm, add_sub_assoc],
have hv1v2 : v1 - v2 ∈ vector_span k s,
{ rw sub_eq_add_neg,
apply (vector_span k s).add_mem hv1,
rw ←neg_one_smul k v2,
exact (vector_span k s).smul_mem (-1 : k) hv2 },
refine (vector_span k s).add_mem _ hv1v2,
exact vsub_mem_vector_span k hp1a hp2a
end
end
/-- An `affine_subspace k P` is a subset of an `affine_space V P`
that, if not empty, has an affine space structure induced by a
corresponding subspace of the `module k V`. -/
structure affine_subspace (k : Type*) {V : Type*} (P : Type*) [ring k] [add_comm_group V]
[module k V] [affine_space V P] :=
(carrier : set P)
(smul_vsub_vadd_mem : ∀ (c : k) {p1 p2 p3 : P}, p1 ∈ carrier → p2 ∈ carrier → p3 ∈ carrier →
c • (p1 -ᵥ p2 : V) +ᵥ p3 ∈ carrier)
namespace submodule
variables {k V : Type*} [ring k] [add_comm_group V] [module k V]
/-- Reinterpret `p : submodule k V` as an `affine_subspace k V`. -/
def to_affine_subspace (p : submodule k V) : affine_subspace k V :=
{ carrier := p,
smul_vsub_vadd_mem := λ c p₁ p₂ p₃ h₁ h₂ h₃, p.add_mem (p.smul_mem _ (p.sub_mem h₁ h₂)) h₃ }
end submodule
namespace affine_subspace
variables (k : Type*) {V : Type*} (P : Type*) [ring k] [add_comm_group V] [module k V]
[affine_space V P]
include V
-- TODO Refactor to use `instance : set_like (affine_subspace k P) P :=` instead
instance : has_coe (affine_subspace k P) (set P) := ⟨carrier⟩
instance : has_mem P (affine_subspace k P) := ⟨λ p s, p ∈ (s : set P)⟩
/-- A point is in an affine subspace coerced to a set if and only if
it is in that affine subspace. -/
@[simp] lemma mem_coe (p : P) (s : affine_subspace k P) :
p ∈ (s : set P) ↔ p ∈ s :=
iff.rfl
variables {k P}
/-- The direction of an affine subspace is the submodule spanned by
the pairwise differences of points. (Except in the case of an empty
affine subspace, where the direction is the zero submodule, every
vector in the direction is the difference of two points in the affine
subspace.) -/
def direction (s : affine_subspace k P) : submodule k V := vector_span k (s : set P)
/-- The direction equals the `vector_span`. -/
lemma direction_eq_vector_span (s : affine_subspace k P) :
s.direction = vector_span k (s : set P) :=
rfl
/-- Alternative definition of the direction when the affine subspace
is nonempty. This is defined so that the order on submodules (as used
in the definition of `submodule.span`) can be used in the proof of
`coe_direction_eq_vsub_set`, and is not intended to be used beyond
that proof. -/
def direction_of_nonempty {s : affine_subspace k P} (h : (s : set P).nonempty) :
submodule k V :=
{ carrier := (s : set P) -ᵥ s,
zero_mem' := begin
cases h with p hp,
exact (vsub_self p) ▸ vsub_mem_vsub hp hp
end,
add_mem' := begin
intros a b ha hb,
rcases ha with ⟨p1, p2, hp1, hp2, rfl⟩,
rcases hb with ⟨p3, p4, hp3, hp4, rfl⟩,
rw [←vadd_vsub_assoc],
refine vsub_mem_vsub _ hp4,
convert s.smul_vsub_vadd_mem 1 hp1 hp2 hp3,
rw one_smul
end,
smul_mem' := begin
intros c v hv,
rcases hv with ⟨p1, p2, hp1, hp2, rfl⟩,
rw [←vadd_vsub (c • (p1 -ᵥ p2)) p2],
refine vsub_mem_vsub _ hp2,
exact s.smul_vsub_vadd_mem c hp1 hp2 hp2
end }
/-- `direction_of_nonempty` gives the same submodule as
`direction`. -/
lemma direction_of_nonempty_eq_direction {s : affine_subspace k P} (h : (s : set P).nonempty) :
direction_of_nonempty h = s.direction :=
le_antisymm (vsub_set_subset_vector_span k s) (submodule.span_le.2 set.subset.rfl)
/-- The set of vectors in the direction of a nonempty affine subspace
is given by `vsub_set`. -/
lemma coe_direction_eq_vsub_set {s : affine_subspace k P} (h : (s : set P).nonempty) :
(s.direction : set V) = (s : set P) -ᵥ s :=
direction_of_nonempty_eq_direction h ▸ rfl
/-- A vector is in the direction of a nonempty affine subspace if and
only if it is the subtraction of two vectors in the subspace. -/
lemma mem_direction_iff_eq_vsub {s : affine_subspace k P} (h : (s : set P).nonempty) (v : V) :
v ∈ s.direction ↔ ∃ p1 ∈ s, ∃ p2 ∈ s, v = p1 -ᵥ p2 :=
begin
rw [←set_like.mem_coe, coe_direction_eq_vsub_set h],
exact ⟨λ ⟨p1, p2, hp1, hp2, hv⟩, ⟨p1, hp1, p2, hp2, hv.symm⟩,
λ ⟨p1, hp1, p2, hp2, hv⟩, ⟨p1, p2, hp1, hp2, hv.symm⟩⟩
end
/-- Adding a vector in the direction to a point in the subspace
produces a point in the subspace. -/
lemma vadd_mem_of_mem_direction {s : affine_subspace k P} {v : V} (hv : v ∈ s.direction) {p : P}
(hp : p ∈ s) : v +ᵥ p ∈ s :=
begin
rw mem_direction_iff_eq_vsub ⟨p, hp⟩ at hv,
rcases hv with ⟨p1, hp1, p2, hp2, hv⟩,
rw hv,
convert s.smul_vsub_vadd_mem 1 hp1 hp2 hp,
rw one_smul
end
/-- Subtracting two points in the subspace produces a vector in the
direction. -/
lemma vsub_mem_direction {s : affine_subspace k P} {p1 p2 : P} (hp1 : p1 ∈ s) (hp2 : p2 ∈ s) :
(p1 -ᵥ p2) ∈ s.direction :=
vsub_mem_vector_span k hp1 hp2
/-- Adding a vector to a point in a subspace produces a point in the
subspace if and only if the vector is in the direction. -/
lemma vadd_mem_iff_mem_direction {s : affine_subspace k P} (v : V) {p : P} (hp : p ∈ s) :
v +ᵥ p ∈ s ↔ v ∈ s.direction :=
⟨λ h, by simpa using vsub_mem_direction h hp, λ h, vadd_mem_of_mem_direction h hp⟩
/-- Given a point in an affine subspace, the set of vectors in its
direction equals the set of vectors subtracting that point on the
right. -/
lemma coe_direction_eq_vsub_set_right {s : affine_subspace k P} {p : P} (hp : p ∈ s) :
(s.direction : set V) = (-ᵥ p) '' s :=
begin
rw coe_direction_eq_vsub_set ⟨p, hp⟩,
refine le_antisymm _ _,
{ rintros v ⟨p1, p2, hp1, hp2, rfl⟩,
exact ⟨p1 -ᵥ p2 +ᵥ p,
vadd_mem_of_mem_direction (vsub_mem_direction hp1 hp2) hp,
(vadd_vsub _ _)⟩ },
{ rintros v ⟨p2, hp2, rfl⟩,
exact ⟨p2, p, hp2, hp, rfl⟩ }
end
/-- Given a point in an affine subspace, the set of vectors in its
direction equals the set of vectors subtracting that point on the
left. -/
lemma coe_direction_eq_vsub_set_left {s : affine_subspace k P} {p : P} (hp : p ∈ s) :
(s.direction : set V) = (-ᵥ) p '' s :=
begin
ext v,
rw [set_like.mem_coe, ←submodule.neg_mem_iff, ←set_like.mem_coe,
coe_direction_eq_vsub_set_right hp, set.mem_image_iff_bex, set.mem_image_iff_bex],
conv_lhs { congr, funext, rw [←neg_vsub_eq_vsub_rev, neg_inj] }
end
/-- Given a point in an affine subspace, a vector is in its direction
if and only if it results from subtracting that point on the right. -/
lemma mem_direction_iff_eq_vsub_right {s : affine_subspace k P} {p : P} (hp : p ∈ s) (v : V) :
v ∈ s.direction ↔ ∃ p2 ∈ s, v = p2 -ᵥ p :=
begin
rw [←set_like.mem_coe, coe_direction_eq_vsub_set_right hp],
exact ⟨λ ⟨p2, hp2, hv⟩, ⟨p2, hp2, hv.symm⟩, λ ⟨p2, hp2, hv⟩, ⟨p2, hp2, hv.symm⟩⟩
end
/-- Given a point in an affine subspace, a vector is in its direction
if and only if it results from subtracting that point on the left. -/
lemma mem_direction_iff_eq_vsub_left {s : affine_subspace k P} {p : P} (hp : p ∈ s) (v : V) :
v ∈ s.direction ↔ ∃ p2 ∈ s, v = p -ᵥ p2 :=
begin
rw [←set_like.mem_coe, coe_direction_eq_vsub_set_left hp],
exact ⟨λ ⟨p2, hp2, hv⟩, ⟨p2, hp2, hv.symm⟩, λ ⟨p2, hp2, hv⟩, ⟨p2, hp2, hv.symm⟩⟩
end
/-- Given a point in an affine subspace, a result of subtracting that
point on the right is in the direction if and only if the other point
is in the subspace. -/
lemma vsub_right_mem_direction_iff_mem {s : affine_subspace k P} {p : P} (hp : p ∈ s) (p2 : P) :
p2 -ᵥ p ∈ s.direction ↔ p2 ∈ s :=
begin
rw mem_direction_iff_eq_vsub_right hp,
simp
end
/-- Given a point in an affine subspace, a result of subtracting that
point on the left is in the direction if and only if the other point
is in the subspace. -/
lemma vsub_left_mem_direction_iff_mem {s : affine_subspace k P} {p : P} (hp : p ∈ s) (p2 : P) :
p -ᵥ p2 ∈ s.direction ↔ p2 ∈ s :=
begin
rw mem_direction_iff_eq_vsub_left hp,
simp
end
/-- Two affine subspaces are equal if they have the same points. -/
@[ext] lemma ext {s1 s2 : affine_subspace k P} (h : (s1 : set P) = s2) : s1 = s2 :=
begin
cases s1,
cases s2,
congr,
exact h
end
@[simp] lemma ext_iff (s₁ s₂ : affine_subspace k P) :
(s₁ : set P) = s₂ ↔ s₁ = s₂ :=
⟨ext, by tidy⟩
/-- Two affine subspaces with the same direction and nonempty
intersection are equal. -/
lemma ext_of_direction_eq {s1 s2 : affine_subspace k P} (hd : s1.direction = s2.direction)
(hn : ((s1 : set P) ∩ s2).nonempty) : s1 = s2 :=
begin
ext p,
have hq1 := set.mem_of_mem_inter_left hn.some_mem,
have hq2 := set.mem_of_mem_inter_right hn.some_mem,
split,
{ intro hp,
rw ←vsub_vadd p hn.some,
refine vadd_mem_of_mem_direction _ hq2,
rw ←hd,
exact vsub_mem_direction hp hq1 },
{ intro hp,
rw ←vsub_vadd p hn.some,
refine vadd_mem_of_mem_direction _ hq1,
rw hd,
exact vsub_mem_direction hp hq2 }
end
instance to_add_torsor (s : affine_subspace k P) [nonempty s] : add_torsor s.direction s :=
{ vadd := λ a b, ⟨(a:V) +ᵥ (b:P), vadd_mem_of_mem_direction a.2 b.2⟩,
zero_vadd := by simp,
add_vadd := λ a b c, by { ext, apply add_vadd },
vsub := λ a b, ⟨(a:P) -ᵥ (b:P), (vsub_left_mem_direction_iff_mem a.2 _).mpr b.2 ⟩,
nonempty := by apply_instance,
vsub_vadd' := λ a b, by { ext, apply add_torsor.vsub_vadd' },
vadd_vsub' := λ a b, by { ext, apply add_torsor.vadd_vsub' } }
@[simp, norm_cast] lemma coe_vsub (s : affine_subspace k P) [nonempty s] (a b : s) :
↑(a -ᵥ b) = (a:P) -ᵥ (b:P) :=
rfl
@[simp, norm_cast] lemma coe_vadd (s : affine_subspace k P) [nonempty s] (a : s.direction) (b : s) :
↑(a +ᵥ b) = (a:V) +ᵥ (b:P) :=
rfl
/-- Two affine subspaces with nonempty intersection are equal if and
only if their directions are equal. -/
lemma eq_iff_direction_eq_of_mem {s₁ s₂ : affine_subspace k P} {p : P} (h₁ : p ∈ s₁)
(h₂ : p ∈ s₂) : s₁ = s₂ ↔ s₁.direction = s₂.direction :=
⟨λ h, h ▸ rfl, λ h, ext_of_direction_eq h ⟨p, h₁, h₂⟩⟩
/-- Construct an affine subspace from a point and a direction. -/
def mk' (p : P) (direction : submodule k V) : affine_subspace k P :=
{ carrier := {q | ∃ v ∈ direction, q = v +ᵥ p},
smul_vsub_vadd_mem := λ c p1 p2 p3 hp1 hp2 hp3, begin
rcases hp1 with ⟨v1, hv1, hp1⟩,
rcases hp2 with ⟨v2, hv2, hp2⟩,
rcases hp3 with ⟨v3, hv3, hp3⟩,
use [c • (v1 - v2) + v3,
direction.add_mem (direction.smul_mem c (direction.sub_mem hv1 hv2)) hv3],
simp [hp1, hp2, hp3, vadd_vadd]
end }
/-- An affine subspace constructed from a point and a direction contains
that point. -/
lemma self_mem_mk' (p : P) (direction : submodule k V) :
p ∈ mk' p direction :=
⟨0, ⟨direction.zero_mem, (zero_vadd _ _).symm⟩⟩
/-- An affine subspace constructed from a point and a direction contains
the result of adding a vector in that direction to that point. -/
lemma vadd_mem_mk' {v : V} (p : P) {direction : submodule k V} (hv : v ∈ direction) :
v +ᵥ p ∈ mk' p direction :=
⟨v, hv, rfl⟩
/-- An affine subspace constructed from a point and a direction is
nonempty. -/
lemma mk'_nonempty (p : P) (direction : submodule k V) : (mk' p direction : set P).nonempty :=
⟨p, self_mem_mk' p direction⟩
/-- The direction of an affine subspace constructed from a point and a
direction. -/
@[simp] lemma direction_mk' (p : P) (direction : submodule k V) :
(mk' p direction).direction = direction :=
begin
ext v,
rw mem_direction_iff_eq_vsub (mk'_nonempty _ _),
split,
{ rintros ⟨p1, ⟨v1, hv1, hp1⟩, p2, ⟨v2, hv2, hp2⟩, hv⟩,
rw [hv, hp1, hp2, vadd_vsub_vadd_cancel_right],
exact direction.sub_mem hv1 hv2 },
{ exact λ hv, ⟨v +ᵥ p, vadd_mem_mk' _ hv, p,
self_mem_mk' _ _, (vadd_vsub _ _).symm⟩ }
end
/-- Constructing an affine subspace from a point in a subspace and
that subspace's direction yields the original subspace. -/
@[simp] lemma mk'_eq {s : affine_subspace k P} {p : P} (hp : p ∈ s) : mk' p s.direction = s :=
ext_of_direction_eq (direction_mk' p s.direction)
⟨p, set.mem_inter (self_mem_mk' _ _) hp⟩
/-- If an affine subspace contains a set of points, it contains the
`span_points` of that set. -/
lemma span_points_subset_coe_of_subset_coe {s : set P} {s1 : affine_subspace k P} (h : s ⊆ s1) :
span_points k s ⊆ s1 :=
begin
rintros p ⟨p1, hp1, v, hv, hp⟩,
rw hp,
have hp1s1 : p1 ∈ (s1 : set P) := set.mem_of_mem_of_subset hp1 h,
refine vadd_mem_of_mem_direction _ hp1s1,
have hs : vector_span k s ≤ s1.direction := vector_span_mono k h,
rw set_like.le_def at hs,
rw ←set_like.mem_coe,
exact set.mem_of_mem_of_subset hv hs
end
end affine_subspace
lemma affine_map.line_map_mem
{k V P : Type*} [ring k] [add_comm_group V] [module k V] [add_torsor V P]
{Q : affine_subspace k P} {p₀ p₁ : P} (c : k) (h₀ : p₀ ∈ Q) (h₁ : p₁ ∈ Q) :
affine_map.line_map p₀ p₁ c ∈ Q :=
begin
rw affine_map.line_map_apply,
exact Q.smul_vsub_vadd_mem c h₁ h₀ h₀,
end
section affine_span
variables (k : Type*) {V : Type*} {P : Type*} [ring k] [add_comm_group V] [module k V]
[affine_space V P]
include V
/-- The affine span of a set of points is the smallest affine subspace
containing those points. (Actually defined here in terms of spans in
modules.) -/
def affine_span (s : set P) : affine_subspace k P :=
{ carrier := span_points k s,
smul_vsub_vadd_mem := λ c p1 p2 p3 hp1 hp2 hp3,
vadd_mem_span_points_of_mem_span_points_of_mem_vector_span k hp3
((vector_span k s).smul_mem c
(vsub_mem_vector_span_of_mem_span_points_of_mem_span_points k hp1 hp2)) }
/-- The affine span, converted to a set, is `span_points`. -/
@[simp] lemma coe_affine_span (s : set P) :
(affine_span k s : set P) = span_points k s :=
rfl
/-- A set is contained in its affine span. -/
lemma subset_affine_span (s : set P) : s ⊆ affine_span k s :=
subset_span_points k s
/-- The direction of the affine span is the `vector_span`. -/
lemma direction_affine_span (s : set P) : (affine_span k s).direction = vector_span k s :=
begin
apply le_antisymm,
{ refine submodule.span_le.2 _,
rintros v ⟨p1, p3, ⟨p2, hp2, v1, hv1, hp1⟩, ⟨p4, hp4, v2, hv2, hp3⟩, rfl⟩,
rw [hp1, hp3, vsub_vadd_eq_vsub_sub, vadd_vsub_assoc, set_like.mem_coe],
exact (vector_span k s).sub_mem ((vector_span k s).add_mem hv1
(vsub_mem_vector_span k hp2 hp4)) hv2 },
{ exact vector_span_mono k (subset_span_points k s) }
end
/-- A point in a set is in its affine span. -/
lemma mem_affine_span {p : P} {s : set P} (hp : p ∈ s) : p ∈ affine_span k s :=
mem_span_points k p s hp
end affine_span
namespace affine_subspace
variables {k : Type*} {V : Type*} {P : Type*} [ring k] [add_comm_group V] [module k V]
[S : affine_space V P]
include S
instance : complete_lattice (affine_subspace k P) :=
{ sup := λ s1 s2, affine_span k (s1 ∪ s2),
le_sup_left := λ s1 s2, set.subset.trans (set.subset_union_left s1 s2)
(subset_span_points k _),
le_sup_right := λ s1 s2, set.subset.trans (set.subset_union_right s1 s2)
(subset_span_points k _),
sup_le := λ s1 s2 s3 hs1 hs2, span_points_subset_coe_of_subset_coe (set.union_subset hs1 hs2),
inf := λ s1 s2, mk (s1 ∩ s2)
(λ c p1 p2 p3 hp1 hp2 hp3,
⟨s1.smul_vsub_vadd_mem c hp1.1 hp2.1 hp3.1,
s2.smul_vsub_vadd_mem c hp1.2 hp2.2 hp3.2⟩),
inf_le_left := λ _ _, set.inter_subset_left _ _,
inf_le_right := λ _ _, set.inter_subset_right _ _,
le_inf := λ _ _ _, set.subset_inter,
top := { carrier := set.univ,
smul_vsub_vadd_mem := λ _ _ _ _ _ _ _, set.mem_univ _ },
le_top := λ _ _ _, set.mem_univ _,
bot := { carrier := ∅,
smul_vsub_vadd_mem := λ _ _ _ _, false.elim },
bot_le := λ _ _, false.elim,
Sup := λ s, affine_span k (⋃ s' ∈ s, (s' : set P)),
Inf := λ s, mk (⋂ s' ∈ s, (s' : set P))
(λ c p1 p2 p3 hp1 hp2 hp3, set.mem_bInter_iff.2 $ λ s2 hs2,
s2.smul_vsub_vadd_mem c (set.mem_bInter_iff.1 hp1 s2 hs2)
(set.mem_bInter_iff.1 hp2 s2 hs2)
(set.mem_bInter_iff.1 hp3 s2 hs2)),
le_Sup := λ _ _ h, set.subset.trans (set.subset_bUnion_of_mem h) (subset_span_points k _),
Sup_le := λ _ _ h, span_points_subset_coe_of_subset_coe (set.bUnion_subset h),
Inf_le := λ _ _, set.bInter_subset_of_mem,
le_Inf := λ _ _, set.subset_bInter,
.. partial_order.lift (coe : affine_subspace k P → set P) (λ _ _, ext) }
instance : inhabited (affine_subspace k P) := ⟨⊤⟩
/-- The `≤` order on subspaces is the same as that on the corresponding
sets. -/
lemma le_def (s1 s2 : affine_subspace k P) : s1 ≤ s2 ↔ (s1 : set P) ⊆ s2 :=
iff.rfl
/-- One subspace is less than or equal to another if and only if all
its points are in the second subspace. -/
lemma le_def' (s1 s2 : affine_subspace k P) : s1 ≤ s2 ↔ ∀ p ∈ s1, p ∈ s2 :=
iff.rfl
/-- The `<` order on subspaces is the same as that on the corresponding
sets. -/
lemma lt_def (s1 s2 : affine_subspace k P) : s1 < s2 ↔ (s1 : set P) ⊂ s2 :=
iff.rfl
/-- One subspace is not less than or equal to another if and only if
it has a point not in the second subspace. -/
lemma not_le_iff_exists (s1 s2 : affine_subspace k P) : ¬ s1 ≤ s2 ↔ ∃ p ∈ s1, p ∉ s2 :=
set.not_subset
/-- If a subspace is less than another, there is a point only in the
second. -/
lemma exists_of_lt {s1 s2 : affine_subspace k P} (h : s1 < s2) : ∃ p ∈ s2, p ∉ s1 :=
set.exists_of_ssubset h
/-- A subspace is less than another if and only if it is less than or
equal to the second subspace and there is a point only in the
second. -/
lemma lt_iff_le_and_exists (s1 s2 : affine_subspace k P) : s1 < s2 ↔ s1 ≤ s2 ∧ ∃ p ∈ s2, p ∉ s1 :=
by rw [lt_iff_le_not_le, not_le_iff_exists]
/-- If an affine subspace is nonempty and contained in another with
the same direction, they are equal. -/
lemma eq_of_direction_eq_of_nonempty_of_le {s₁ s₂ : affine_subspace k P}
(hd : s₁.direction = s₂.direction) (hn : (s₁ : set P).nonempty) (hle : s₁ ≤ s₂) :
s₁ = s₂ :=
let ⟨p, hp⟩ := hn in ext_of_direction_eq hd ⟨p, hp, hle hp⟩
variables (k V)
/-- The affine span is the `Inf` of subspaces containing the given
points. -/
lemma affine_span_eq_Inf (s : set P) : affine_span k s = Inf {s' | s ⊆ s'} :=
le_antisymm (span_points_subset_coe_of_subset_coe (set.subset_bInter (λ _ h, h)))
(Inf_le (subset_span_points k _))
variables (P)
/-- The Galois insertion formed by `affine_span` and coercion back to
a set. -/
protected def gi : galois_insertion (affine_span k) (coe : affine_subspace k P → set P) :=
{ choice := λ s _, affine_span k s,
gc := λ s1 s2, ⟨λ h, set.subset.trans (subset_span_points k s1) h,
span_points_subset_coe_of_subset_coe⟩,
le_l_u := λ _, subset_span_points k _,
choice_eq := λ _ _, rfl }
/-- The span of the empty set is `⊥`. -/
@[simp] lemma span_empty : affine_span k (∅ : set P) = ⊥ :=
(affine_subspace.gi k V P).gc.l_bot
/-- The span of `univ` is `⊤`. -/
@[simp] lemma span_univ : affine_span k (set.univ : set P) = ⊤ :=
eq_top_iff.2 $ subset_span_points k _
variables {k V P}
lemma _root_.affine_span_le {s : set P} {Q : affine_subspace k P} :
affine_span k s ≤ Q ↔ s ⊆ (Q : set P) :=
(affine_subspace.gi k V P).gc _ _
variables (k V) {P}
/-- The affine span of a single point, coerced to a set, contains just
that point. -/
@[simp] lemma coe_affine_span_singleton (p : P) : (affine_span k ({p} : set P) : set P) = {p} :=
begin
ext x,
rw [mem_coe, ←vsub_right_mem_direction_iff_mem (mem_affine_span k (set.mem_singleton p)) _,
direction_affine_span],
simp
end
/-- A point is in the affine span of a single point if and only if
they are equal. -/
@[simp] lemma mem_affine_span_singleton (p1 p2 : P) :
p1 ∈ affine_span k ({p2} : set P) ↔ p1 = p2 :=
by simp [←mem_coe]
/-- The span of a union of sets is the sup of their spans. -/
lemma span_union (s t : set P) : affine_span k (s ∪ t) = affine_span k s ⊔ affine_span k t :=
(affine_subspace.gi k V P).gc.l_sup
/-- The span of a union of an indexed family of sets is the sup of
their spans. -/
lemma span_Union {ι : Type*} (s : ι → set P) :
affine_span k (⋃ i, s i) = ⨆ i, affine_span k (s i) :=
(affine_subspace.gi k V P).gc.l_supr
variables (P)
/-- `⊤`, coerced to a set, is the whole set of points. -/
@[simp] lemma top_coe : ((⊤ : affine_subspace k P) : set P) = set.univ :=
rfl
variables {P}
/-- All points are in `⊤`. -/
lemma mem_top (p : P) : p ∈ (⊤ : affine_subspace k P) :=
set.mem_univ p
variables (P)
/-- The direction of `⊤` is the whole module as a submodule. -/
@[simp] lemma direction_top : (⊤ : affine_subspace k P).direction = ⊤ :=
begin
cases S.nonempty with p,
ext v,
refine ⟨imp_intro submodule.mem_top, λ hv, _⟩,
have hpv : (v +ᵥ p -ᵥ p : V) ∈ (⊤ : affine_subspace k P).direction :=
vsub_mem_direction (mem_top k V _) (mem_top k V _),
rwa vadd_vsub at hpv
end
/-- `⊥`, coerced to a set, is the empty set. -/
@[simp] lemma bot_coe : ((⊥ : affine_subspace k P) : set P) = ∅ :=
rfl
lemma bot_ne_top : (⊥ : affine_subspace k P) ≠ ⊤ :=
begin
intros contra,
rw [← ext_iff, bot_coe, top_coe] at contra,
exact set.empty_ne_univ contra,
end
instance : nontrivial (affine_subspace k P) := ⟨⟨⊥, ⊤, bot_ne_top k V P⟩⟩
lemma nonempty_of_affine_span_eq_top {s : set P} (h : affine_span k s = ⊤) : s.nonempty :=
begin
rw ← set.ne_empty_iff_nonempty,
rintros rfl,
rw affine_subspace.span_empty at h,
exact bot_ne_top k V P h,
end
/-- If the affine span of a set is `⊤`, then the vector span of the same set is the `⊤`. -/
lemma vector_span_eq_top_of_affine_span_eq_top {s : set P} (h : affine_span k s = ⊤) :
vector_span k s = ⊤ :=
by rw [← direction_affine_span, h, direction_top]
/-- For a nonempty set, the affine span is `⊤` iff its vector span is `⊤`. -/
lemma affine_span_eq_top_iff_vector_span_eq_top_of_nonempty {s : set P} (hs : s.nonempty) :
affine_span k s = ⊤ ↔ vector_span k s = ⊤ :=
begin
refine ⟨vector_span_eq_top_of_affine_span_eq_top k V P, _⟩,
intros h,
suffices : nonempty (affine_span k s),
{ obtain ⟨p, hp : p ∈ affine_span k s⟩ := this,
rw [eq_iff_direction_eq_of_mem hp (mem_top k V p), direction_affine_span, h, direction_top] },
obtain ⟨x, hx⟩ := hs,
exact ⟨⟨x, mem_affine_span k hx⟩⟩,
end
/-- For a non-trivial space, the affine span of a set is `⊤` iff its vector span is `⊤`. -/
lemma affine_span_eq_top_iff_vector_span_eq_top_of_nontrivial {s : set P} [nontrivial P] :
affine_span k s = ⊤ ↔ vector_span k s = ⊤ :=
begin
cases s.eq_empty_or_nonempty with hs hs,
{ simp [hs, subsingleton_iff_bot_eq_top, add_torsor.subsingleton_iff V P, not_subsingleton], },
{ rw affine_span_eq_top_iff_vector_span_eq_top_of_nonempty k V P hs, },
end
lemma card_pos_of_affine_span_eq_top {ι : Type*} [fintype ι] {p : ι → P}
(h : affine_span k (range p) = ⊤) :
0 < fintype.card ι :=
begin
obtain ⟨-, ⟨i, -⟩⟩ := nonempty_of_affine_span_eq_top k V P h,
exact fintype.card_pos_iff.mpr ⟨i⟩,
end
variables {P}
/-- No points are in `⊥`. -/
lemma not_mem_bot (p : P) : p ∉ (⊥ : affine_subspace k P) :=
set.not_mem_empty p
variables (P)
/-- The direction of `⊥` is the submodule `⊥`. -/
@[simp] lemma direction_bot : (⊥ : affine_subspace k P).direction = ⊥ :=
by rw [direction_eq_vector_span, bot_coe, vector_span_def, vsub_empty, submodule.span_empty]
variables {k V P}
lemma subsingleton_of_subsingleton_span_eq_top {s : set P} (h₁ : s.subsingleton)
(h₂ : affine_span k s = ⊤) : subsingleton P :=
begin
obtain ⟨p, hp⟩ := affine_subspace.nonempty_of_affine_span_eq_top k V P h₂,
have : s = {p}, { exact subset.antisymm (λ q hq, h₁ hq hp) (by simp [hp]), },
rw [this, ← affine_subspace.ext_iff, affine_subspace.coe_affine_span_singleton,
affine_subspace.top_coe, eq_comm, ← subsingleton_iff_singleton (mem_univ _)] at h₂,
exact subsingleton_of_univ_subsingleton h₂,
end
lemma eq_univ_of_subsingleton_span_eq_top {s : set P} (h₁ : s.subsingleton)
(h₂ : affine_span k s = ⊤) : s = (univ : set P) :=
begin
obtain ⟨p, hp⟩ := affine_subspace.nonempty_of_affine_span_eq_top k V P h₂,
have : s = {p}, { exact subset.antisymm (λ q hq, h₁ hq hp) (by simp [hp]), },
rw [this, eq_comm, ← subsingleton_iff_singleton (mem_univ p), subsingleton_univ_iff],
exact subsingleton_of_subsingleton_span_eq_top h₁ h₂,
end
/-- A nonempty affine subspace is `⊤` if and only if its direction is
`⊤`. -/
@[simp] lemma direction_eq_top_iff_of_nonempty {s : affine_subspace k P}
(h : (s : set P).nonempty) : s.direction = ⊤ ↔ s = ⊤ :=
begin
split,
{ intro hd,
rw ←direction_top k V P at hd,
refine ext_of_direction_eq hd _,
simp [h] },
{ rintro rfl,
simp }
end
/-- The inf of two affine subspaces, coerced to a set, is the
intersection of the two sets of points. -/
@[simp] lemma inf_coe (s1 s2 : affine_subspace k P) : ((s1 ⊓ s2) : set P) = s1 ∩ s2 :=
rfl
/-- A point is in the inf of two affine subspaces if and only if it is
in both of them. -/
lemma mem_inf_iff (p : P) (s1 s2 : affine_subspace k P) : p ∈ s1 ⊓ s2 ↔ p ∈ s1 ∧ p ∈ s2 :=
iff.rfl
/-- The direction of the inf of two affine subspaces is less than or
equal to the inf of their directions. -/
lemma direction_inf (s1 s2 : affine_subspace k P) :
(s1 ⊓ s2).direction ≤ s1.direction ⊓ s2.direction :=
begin
repeat { rw [direction_eq_vector_span, vector_span_def] },
exact le_inf
(Inf_le_Inf (λ p hp, trans (vsub_self_mono (inter_subset_left _ _)) hp))
(Inf_le_Inf (λ p hp, trans (vsub_self_mono (inter_subset_right _ _)) hp))
end
/-- If two affine subspaces have a point in common, the direction of
their inf equals the inf of their directions. -/
lemma direction_inf_of_mem {s₁ s₂ : affine_subspace k P} {p : P} (h₁ : p ∈ s₁) (h₂ : p ∈ s₂) :
(s₁ ⊓ s₂).direction = s₁.direction ⊓ s₂.direction :=
begin
ext v,
rw [submodule.mem_inf, ←vadd_mem_iff_mem_direction v h₁, ←vadd_mem_iff_mem_direction v h₂,
←vadd_mem_iff_mem_direction v ((mem_inf_iff p s₁ s₂).2 ⟨h₁, h₂⟩), mem_inf_iff]
end
/-- If two affine subspaces have a point in their inf, the direction
of their inf equals the inf of their directions. -/
lemma direction_inf_of_mem_inf {s₁ s₂ : affine_subspace k P} {p : P} (h : p ∈ s₁ ⊓ s₂) :
(s₁ ⊓ s₂).direction = s₁.direction ⊓ s₂.direction :=
direction_inf_of_mem ((mem_inf_iff p s₁ s₂).1 h).1 ((mem_inf_iff p s₁ s₂).1 h).2
/-- If one affine subspace is less than or equal to another, the same
applies to their directions. -/
lemma direction_le {s1 s2 : affine_subspace k P} (h : s1 ≤ s2) : s1.direction ≤ s2.direction :=
begin
repeat { rw [direction_eq_vector_span, vector_span_def] },
exact vector_span_mono k h
end
/-- If one nonempty affine subspace is less than another, the same
applies to their directions -/
lemma direction_lt_of_nonempty {s1 s2 : affine_subspace k P} (h : s1 < s2)
(hn : (s1 : set P).nonempty) : s1.direction < s2.direction :=
begin
cases hn with p hp,
rw lt_iff_le_and_exists at h,
rcases h with ⟨hle, p2, hp2, hp2s1⟩,
rw set_like.lt_iff_le_and_exists,
use [direction_le hle, p2 -ᵥ p, vsub_mem_direction hp2 (hle hp)],
intro hm,
rw vsub_right_mem_direction_iff_mem hp p2 at hm,
exact hp2s1 hm
end
/-- The sup of the directions of two affine subspaces is less than or
equal to the direction of their sup. -/
lemma sup_direction_le (s1 s2 : affine_subspace k P) :
s1.direction ⊔ s2.direction ≤ (s1 ⊔ s2).direction :=
begin
repeat { rw [direction_eq_vector_span, vector_span_def] },
exact sup_le
(Inf_le_Inf (λ p hp, set.subset.trans (vsub_self_mono (le_sup_left : s1 ≤ s1 ⊔ s2)) hp))
(Inf_le_Inf (λ p hp, set.subset.trans (vsub_self_mono (le_sup_right : s2 ≤ s1 ⊔ s2)) hp))
end
/-- The sup of the directions of two nonempty affine subspaces with
empty intersection is less than the direction of their sup. -/
lemma sup_direction_lt_of_nonempty_of_inter_empty {s1 s2 : affine_subspace k P}
(h1 : (s1 : set P).nonempty) (h2 : (s2 : set P).nonempty) (he : (s1 ∩ s2 : set P) = ∅) :
s1.direction ⊔ s2.direction < (s1 ⊔ s2).direction :=
begin
cases h1 with p1 hp1,
cases h2 with p2 hp2,
rw set_like.lt_iff_le_and_exists,
use [sup_direction_le s1 s2, p2 -ᵥ p1,
vsub_mem_direction ((le_sup_right : s2 ≤ s1 ⊔ s2) hp2) ((le_sup_left : s1 ≤ s1 ⊔ s2) hp1)],
intro h,
rw submodule.mem_sup at h,
rcases h with ⟨v1, hv1, v2, hv2, hv1v2⟩,
rw [←sub_eq_zero, sub_eq_add_neg, neg_vsub_eq_vsub_rev, add_comm v1, add_assoc,
←vadd_vsub_assoc, ←neg_neg v2, add_comm, ←sub_eq_add_neg, ←vsub_vadd_eq_vsub_sub,
vsub_eq_zero_iff_eq] at hv1v2,
refine set.nonempty.ne_empty _ he,
use [v1 +ᵥ p1, vadd_mem_of_mem_direction hv1 hp1],
rw hv1v2,
exact vadd_mem_of_mem_direction (submodule.neg_mem _ hv2) hp2
end
/-- If the directions of two nonempty affine subspaces span the whole
module, they have nonempty intersection. -/
lemma inter_nonempty_of_nonempty_of_sup_direction_eq_top {s1 s2 : affine_subspace k P}
(h1 : (s1 : set P).nonempty) (h2 : (s2 : set P).nonempty)
(hd : s1.direction ⊔ s2.direction = ⊤) : ((s1 : set P) ∩ s2).nonempty :=
begin
by_contradiction h,
rw set.not_nonempty_iff_eq_empty at h,
have hlt := sup_direction_lt_of_nonempty_of_inter_empty h1 h2 h,
rw hd at hlt,
exact not_top_lt hlt
end
/-- If the directions of two nonempty affine subspaces are complements
of each other, they intersect in exactly one point. -/
lemma inter_eq_singleton_of_nonempty_of_is_compl {s1 s2 : affine_subspace k P}
(h1 : (s1 : set P).nonempty) (h2 : (s2 : set P).nonempty)
(hd : is_compl s1.direction s2.direction) : ∃ p, (s1 : set P) ∩ s2 = {p} :=
begin
cases inter_nonempty_of_nonempty_of_sup_direction_eq_top h1 h2 hd.sup_eq_top with p hp,
use p,
ext q,
rw set.mem_singleton_iff,
split,
{ rintros ⟨hq1, hq2⟩,
have hqp : q -ᵥ p ∈ s1.direction ⊓ s2.direction :=
⟨vsub_mem_direction hq1 hp.1, vsub_mem_direction hq2 hp.2⟩,
rwa [hd.inf_eq_bot, submodule.mem_bot, vsub_eq_zero_iff_eq] at hqp },
{ exact λ h, h.symm ▸ hp }
end
/-- Coercing a subspace to a set then taking the affine span produces
the original subspace. -/
@[simp] lemma affine_span_coe (s : affine_subspace k P) : affine_span k (s : set P) = s :=
begin
refine le_antisymm _ (subset_span_points _ _),
rintros p ⟨p1, hp1, v, hv, rfl⟩,
exact vadd_mem_of_mem_direction hv hp1
end
end affine_subspace
section affine_space'
variables (k : Type*) {V : Type*} {P : Type*} [ring k] [add_comm_group V] [module k V]
[affine_space V P]
variables {ι : Type*}
include V
open affine_subspace set
/-- The `vector_span` is the span of the pairwise subtractions with a
given point on the left. -/
lemma vector_span_eq_span_vsub_set_left {s : set P} {p : P} (hp : p ∈ s) :
vector_span k s = submodule.span k ((-ᵥ) p '' s) :=
begin
rw vector_span_def,
refine le_antisymm _ (submodule.span_mono _),
{ rw submodule.span_le,
rintros v ⟨p1, p2, hp1, hp2, hv⟩,
rw ←vsub_sub_vsub_cancel_left p1 p2 p at hv,
rw [←hv, set_like.mem_coe, submodule.mem_span],
exact λ m hm, submodule.sub_mem _ (hm ⟨p2, hp2, rfl⟩) (hm ⟨p1, hp1, rfl⟩) },
{ rintros v ⟨p2, hp2, hv⟩,
exact ⟨p, p2, hp, hp2, hv⟩ }
end
/-- The `vector_span` is the span of the pairwise subtractions with a
given point on the right. -/
lemma vector_span_eq_span_vsub_set_right {s : set P} {p : P} (hp : p ∈ s) :
vector_span k s = submodule.span k ((-ᵥ p) '' s) :=
begin
rw vector_span_def,
refine le_antisymm _ (submodule.span_mono _),
{ rw submodule.span_le,
rintros v ⟨p1, p2, hp1, hp2, hv⟩,
rw ←vsub_sub_vsub_cancel_right p1 p2 p at hv,
rw [←hv, set_like.mem_coe, submodule.mem_span],
exact λ m hm, submodule.sub_mem _ (hm ⟨p1, hp1, rfl⟩) (hm ⟨p2, hp2, rfl⟩) },
{ rintros v ⟨p2, hp2, hv⟩,
exact ⟨p2, p, hp2, hp, hv⟩ }
end
/-- The `vector_span` is the span of the pairwise subtractions with a
given point on the left, excluding the subtraction of that point from
itself. -/
lemma vector_span_eq_span_vsub_set_left_ne {s : set P} {p : P} (hp : p ∈ s) :
vector_span k s = submodule.span k ((-ᵥ) p '' (s \ {p})) :=
begin
conv_lhs { rw [vector_span_eq_span_vsub_set_left k hp, ←set.insert_eq_of_mem hp,
←set.insert_diff_singleton, set.image_insert_eq] },
simp [submodule.span_insert_eq_span]
end
/-- The `vector_span` is the span of the pairwise subtractions with a
given point on the right, excluding the subtraction of that point from
itself. -/
lemma vector_span_eq_span_vsub_set_right_ne {s : set P} {p : P} (hp : p ∈ s) :
vector_span k s = submodule.span k ((-ᵥ p) '' (s \ {p})) :=
begin
conv_lhs { rw [vector_span_eq_span_vsub_set_right k hp, ←set.insert_eq_of_mem hp,
←set.insert_diff_singleton, set.image_insert_eq] },
simp [submodule.span_insert_eq_span]
end
/-- The `vector_span` is the span of the pairwise subtractions with a
given point on the right, excluding the subtraction of that point from
itself. -/
lemma vector_span_eq_span_vsub_finset_right_ne {s : finset P} {p : P} (hp : p ∈ s) :
vector_span k (s : set P) = submodule.span k ((s.erase p).image (-ᵥ p)) :=
by simp [vector_span_eq_span_vsub_set_right_ne _ (finset.mem_coe.mpr hp)]
/-- The `vector_span` of the image of a function is the span of the
pairwise subtractions with a given point on the left, excluding the
subtraction of that point from itself. -/
lemma vector_span_image_eq_span_vsub_set_left_ne (p : ι → P) {s : set ι} {i : ι} (hi : i ∈ s) :
vector_span k (p '' s) = submodule.span k ((-ᵥ) (p i) '' (p '' (s \ {i}))) :=
begin
conv_lhs { rw [vector_span_eq_span_vsub_set_left k (set.mem_image_of_mem p hi),
←set.insert_eq_of_mem hi, ←set.insert_diff_singleton, set.image_insert_eq,
set.image_insert_eq] },
simp [submodule.span_insert_eq_span]
end
/-- The `vector_span` of the image of a function is the span of the
pairwise subtractions with a given point on the right, excluding the
subtraction of that point from itself. -/
lemma vector_span_image_eq_span_vsub_set_right_ne (p : ι → P) {s : set ι} {i : ι} (hi : i ∈ s) :
vector_span k (p '' s) = submodule.span k ((-ᵥ (p i)) '' (p '' (s \ {i}))) :=
begin
conv_lhs { rw [vector_span_eq_span_vsub_set_right k (set.mem_image_of_mem p hi),
←set.insert_eq_of_mem hi, ←set.insert_diff_singleton, set.image_insert_eq,
set.image_insert_eq] },
simp [submodule.span_insert_eq_span]
end
/-- The `vector_span` of an indexed family is the span of the pairwise
subtractions with a given point on the left. -/
lemma vector_span_range_eq_span_range_vsub_left (p : ι → P) (i0 : ι) :
vector_span k (set.range p) = submodule.span k (set.range (λ (i : ι), p i0 -ᵥ p i)) :=
by rw [vector_span_eq_span_vsub_set_left k (set.mem_range_self i0), ←set.range_comp]
/-- The `vector_span` of an indexed family is the span of the pairwise
subtractions with a given point on the right. -/
lemma vector_span_range_eq_span_range_vsub_right (p : ι → P) (i0 : ι) :
vector_span k (set.range p) = submodule.span k (set.range (λ (i : ι), p i -ᵥ p i0)) :=
by rw [vector_span_eq_span_vsub_set_right k (set.mem_range_self i0), ←set.range_comp]
/-- The `vector_span` of an indexed family is the span of the pairwise
subtractions with a given point on the left, excluding the subtraction
of that point from itself. -/
lemma vector_span_range_eq_span_range_vsub_left_ne (p : ι → P) (i₀ : ι) :
vector_span k (set.range p) = submodule.span k (set.range (λ (i : {x // x ≠ i₀}), p i₀ -ᵥ p i)) :=
begin
rw [←set.image_univ, vector_span_image_eq_span_vsub_set_left_ne k _ (set.mem_univ i₀)],
congr' with v,
simp only [set.mem_range, set.mem_image, set.mem_diff, set.mem_singleton_iff, subtype.exists,
subtype.coe_mk],
split,
{ rintros ⟨x, ⟨i₁, ⟨⟨hi₁u, hi₁⟩, rfl⟩⟩, hv⟩,
exact ⟨i₁, hi₁, hv⟩ },
{ exact λ ⟨i₁, hi₁, hv⟩, ⟨p i₁, ⟨i₁, ⟨set.mem_univ _, hi₁⟩, rfl⟩, hv⟩ }
end
/-- The `vector_span` of an indexed family is the span of the pairwise
subtractions with a given point on the right, excluding the subtraction
of that point from itself. -/
lemma vector_span_range_eq_span_range_vsub_right_ne (p : ι → P) (i₀ : ι) :
vector_span k (set.range p) = submodule.span k (set.range (λ (i : {x // x ≠ i₀}), p i -ᵥ p i₀)) :=
begin
rw [←set.image_univ, vector_span_image_eq_span_vsub_set_right_ne k _ (set.mem_univ i₀)],
congr' with v,
simp only [set.mem_range, set.mem_image, set.mem_diff, set.mem_singleton_iff, subtype.exists,
subtype.coe_mk],
split,
{ rintros ⟨x, ⟨i₁, ⟨⟨hi₁u, hi₁⟩, rfl⟩⟩, hv⟩,
exact ⟨i₁, hi₁, hv⟩ },
{ exact λ ⟨i₁, hi₁, hv⟩, ⟨p i₁, ⟨i₁, ⟨set.mem_univ _, hi₁⟩, rfl⟩, hv⟩ }
end
/-- The affine span of a set is nonempty if and only if that set
is. -/
lemma affine_span_nonempty (s : set P) :
(affine_span k s : set P).nonempty ↔ s.nonempty :=
span_points_nonempty k s
/-- The affine span of a nonempty set is nonempty. -/
instance {s : set P} [nonempty s] : nonempty (affine_span k s) :=
((affine_span_nonempty k s).mpr (nonempty_subtype.mp ‹_›)).to_subtype
variables {k}
/-- Suppose a set of vectors spans `V`. Then a point `p`, together
with those vectors added to `p`, spans `P`. -/
lemma affine_span_singleton_union_vadd_eq_top_of_span_eq_top {s : set V} (p : P)
(h : submodule.span k (set.range (coe : s → V)) = ⊤) :
affine_span k ({p} ∪ (λ v, v +ᵥ p) '' s) = ⊤ :=
begin
convert ext_of_direction_eq _
⟨p,
mem_affine_span k (set.mem_union_left _ (set.mem_singleton _)),
mem_top k V p⟩,
rw [direction_affine_span, direction_top,
vector_span_eq_span_vsub_set_right k
((set.mem_union_left _ (set.mem_singleton _)) : p ∈ _), eq_top_iff, ←h],
apply submodule.span_mono,
rintros v ⟨v', rfl⟩,
use (v' : V) +ᵥ p,
simp
end
variables (k)
/-- `affine_span` is monotone. -/
@[mono]
lemma affine_span_mono {s₁ s₂ : set P} (h : s₁ ⊆ s₂) : affine_span k s₁ ≤ affine_span k s₂ :=
span_points_subset_coe_of_subset_coe (set.subset.trans h (subset_affine_span k _))
/-- Taking the affine span of a set, adding a point and taking the
span again produces the same results as adding the point to the set
and taking the span. -/
lemma affine_span_insert_affine_span (p : P) (ps : set P) :
affine_span k (insert p (affine_span k ps : set P)) = affine_span k (insert p ps) :=
by rw [set.insert_eq, set.insert_eq, span_union, span_union, affine_span_coe]
/-- If a point is in the affine span of a set, adding it to that set
does not change the affine span. -/
lemma affine_span_insert_eq_affine_span {p : P} {ps : set P} (h : p ∈ affine_span k ps) :
affine_span k (insert p ps) = affine_span k ps :=
begin
rw ←mem_coe at h,
rw [←affine_span_insert_affine_span, set.insert_eq_of_mem h, affine_span_coe]
end
end affine_space'
namespace affine_subspace
variables {k : Type*} {V : Type*} {P : Type*} [ring k] [add_comm_group V] [module k V]
[affine_space V P]
include V
/-- The direction of the sup of two nonempty affine subspaces is the
sup of the two directions and of any one difference between points in
the two subspaces. -/
lemma direction_sup {s1 s2 : affine_subspace k P} {p1 p2 : P} (hp1 : p1 ∈ s1) (hp2 : p2 ∈ s2) :
(s1 ⊔ s2).direction = s1.direction ⊔ s2.direction ⊔ k ∙ (p2 -ᵥ p1) :=
begin
refine le_antisymm _ _,
{ change (affine_span k ((s1 : set P) ∪ s2)).direction ≤ _,
rw ←mem_coe at hp1,
rw [direction_affine_span, vector_span_eq_span_vsub_set_right k (set.mem_union_left _ hp1),
submodule.span_le],
rintros v ⟨p3, hp3, rfl⟩,
cases hp3,
{ rw [sup_assoc, sup_comm, set_like.mem_coe, submodule.mem_sup],
use [0, submodule.zero_mem _, p3 -ᵥ p1, vsub_mem_direction hp3 hp1],
rw zero_add },
{ rw [sup_assoc, set_like.mem_coe, submodule.mem_sup],
use [0, submodule.zero_mem _, p3 -ᵥ p1],
rw [and_comm, zero_add],
use rfl,
rw [←vsub_add_vsub_cancel p3 p2 p1, submodule.mem_sup],
use [p3 -ᵥ p2, vsub_mem_direction hp3 hp2, p2 -ᵥ p1,
submodule.mem_span_singleton_self _] } },
{ refine sup_le (sup_direction_le _ _) _,
rw [direction_eq_vector_span, vector_span_def],
exact Inf_le_Inf (λ p hp, set.subset.trans
(set.singleton_subset_iff.2
(vsub_mem_vsub (mem_span_points k p2 _ (set.mem_union_right _ hp2))
(mem_span_points k p1 _ (set.mem_union_left _ hp1))))
hp) }
end
/-- The direction of the span of the result of adding a point to a
nonempty affine subspace is the sup of the direction of that subspace
and of any one difference between that point and a point in the
subspace. -/
lemma direction_affine_span_insert {s : affine_subspace k P} {p1 p2 : P} (hp1 : p1 ∈ s) :
(affine_span k (insert p2 (s : set P))).direction = submodule.span k {p2 -ᵥ p1} ⊔ s.direction :=
begin
rw [sup_comm, ←set.union_singleton, ←coe_affine_span_singleton k V p2],
change (s ⊔ affine_span k {p2}).direction = _,
rw [direction_sup hp1 (mem_affine_span k (set.mem_singleton _)), direction_affine_span],
simp
end
/-- Given a point `p1` in an affine subspace `s`, and a point `p2`, a
point `p` is in the span of `s` with `p2` added if and only if it is a
multiple of `p2 -ᵥ p1` added to a point in `s`. -/
lemma mem_affine_span_insert_iff {s : affine_subspace k P} {p1 : P} (hp1 : p1 ∈ s) (p2 p : P) :
p ∈ affine_span k (insert p2 (s : set P)) ↔
∃ (r : k) (p0 : P) (hp0 : p0 ∈ s), p = r • (p2 -ᵥ p1 : V) +ᵥ p0 :=
begin
rw ←mem_coe at hp1,
rw [←vsub_right_mem_direction_iff_mem (mem_affine_span k (set.mem_insert_of_mem _ hp1)),
direction_affine_span_insert hp1, submodule.mem_sup],
split,
{ rintros ⟨v1, hv1, v2, hv2, hp⟩,
rw submodule.mem_span_singleton at hv1,
rcases hv1 with ⟨r, rfl⟩,
use [r, v2 +ᵥ p1, vadd_mem_of_mem_direction hv2 hp1],
symmetry' at hp,
rw [←sub_eq_zero, ←vsub_vadd_eq_vsub_sub, vsub_eq_zero_iff_eq] at hp,
rw [hp, vadd_vadd] },
{ rintros ⟨r, p3, hp3, rfl⟩,
use [r • (p2 -ᵥ p1), submodule.mem_span_singleton.2 ⟨r, rfl⟩, p3 -ᵥ p1,
vsub_mem_direction hp3 hp1],
rw [vadd_vsub_assoc, add_comm] }
end
end affine_subspace
section maps
variables {k V₁ P₁ V₂ P₂ : Type*} [ring k]
variables [add_comm_group V₁] [module k V₁] [add_torsor V₁ P₁]
variables [add_comm_group V₂] [module k V₂] [add_torsor V₂ P₂]
include V₁ V₂
variables (f : P₁ →ᵃ[k] P₂)
@[simp] lemma affine_map.vector_span_image_eq_submodule_map {s : set P₁} :
submodule.map f.linear (vector_span k s) = vector_span k (f '' s) :=
by simp [f.image_vsub_image, vector_span_def]
namespace affine_subspace
/-- The image of an affine subspace under an affine map as an affine subspace. -/
def map (s : affine_subspace k P₁) : affine_subspace k P₂ :=
{ carrier := f '' s,
smul_vsub_vadd_mem :=
begin
rintros t - - - ⟨p₁, h₁, rfl⟩ ⟨p₂, h₂, rfl⟩ ⟨p₃, h₃, rfl⟩,
use t • (p₁ -ᵥ p₂) +ᵥ p₃,
suffices : t • (p₁ -ᵥ p₂) +ᵥ p₃ ∈ s, { by simp [this], },
exact s.smul_vsub_vadd_mem t h₁ h₂ h₃,
end }
@[simp] lemma map_coe (s : affine_subspace k P₁) : (s.map f : set P₂) = f '' s := rfl
@[simp] lemma map_bot : (⊥ : affine_subspace k P₁).map f = ⊥ :=
by { rw ← ext_iff, exact image_empty f, }
@[simp] lemma map_direction (s : affine_subspace k P₁) :
(s.map f).direction = s.direction.map f.linear :=
by simp [direction_eq_vector_span]
lemma map_span (s : set P₁) :
(affine_span k s).map f = affine_span k (f '' s) :=
begin
rcases s.eq_empty_or_nonempty with rfl | ⟨p, hp⟩, { simp, },
apply ext_of_direction_eq,
{ simp [direction_affine_span], },
{ exact ⟨f p, mem_image_of_mem f (subset_affine_span k _ hp),
subset_affine_span k _ (mem_image_of_mem f hp)⟩, },
end
end affine_subspace
namespace affine_map
@[simp] lemma map_top_of_surjective (hf : function.surjective f) : affine_subspace.map f ⊤ = ⊤ :=
begin
rw ← affine_subspace.ext_iff,
exact image_univ_of_surjective hf,
end
lemma span_eq_top_of_surjective {s : set P₁}
(hf : function.surjective f) (h : affine_span k s = ⊤) :
affine_span k (f '' s) = ⊤ :=
by rw [← affine_subspace.map_span, h, map_top_of_surjective f hf]
end affine_map
lemma affine_equiv.span_eq_top_iff {s : set P₁} (e : P₁ ≃ᵃ[k] P₂) :
affine_span k s = ⊤ ↔ affine_span k (e '' s) = ⊤ :=
begin
refine ⟨(e : P₁ →ᵃ[k] P₂).span_eq_top_of_surjective e.surjective, _⟩,
intros h,
have : s = e.symm '' (e '' s), { simp [← image_comp], },
rw this,
exact (e.symm : P₂ →ᵃ[k] P₁).span_eq_top_of_surjective e.symm.surjective h,
end
end maps
|
31fa169ae532733ffc54c21d1b4f04967499ce83 | 36938939954e91f23dec66a02728db08a7acfcf9 | /lean4/deps/smtlib/src/SMTLIB/Syntax.lean | 8dd96c9b4478cbd06288a09a8ff0a4edb7c6bf4c | [] | no_license | pnwamk/reopt-vcg | f8b56dd0279392a5e1c6aee721be8138e6b558d3 | c9f9f185fbefc25c36c4b506bbc85fd1a03c3b6d | refs/heads/master | 1,631,145,017,772 | 1,593,549,019,000 | 1,593,549,143,000 | 254,191,418 | 0 | 0 | null | 1,586,377,077,000 | 1,586,377,077,000 | null | UTF-8 | Lean | false | false | 31,645 | lean | -- Following the SMTLIB reference v2.6
import Galois.Init.Nat
import Galois.Data.List
import Galois.Data.SExp
import SMTLIB.IdGen
abbrev SExpr := WellFormedSExp.SExp String
namespace SExpr
open WellFormedSExp
open WellFormedSExp.SExp
class HasToSExpr (a : Type) := (toSExpr : a -> SExpr)
open HasToSExpr
instance SExpr.HasToSExpr : HasToSExpr SExpr := ⟨id⟩
instance List.HasToSExpr {a : Type} [HasToSExpr a] : HasToSExpr (List a) :=
⟨fun ss => list $ ss.map HasToSExpr.toSExpr⟩
instance Nat.HasToSExpr : HasToSExpr Nat := ⟨atom ∘ Nat.repr⟩
instance String.HasToSExpr : HasToSExpr String := ⟨atom⟩
protected
def app (f : SExpr) (args : List SExpr) : SExpr := list (f :: args)
end SExpr
export SExpr.HasToSExpr (toSExpr)
export SMT.IdGen
namespace SMT
open WellFormedSExp
open WellFormedSExp.SExp
open SExpr
-- SMTLIB specific sexpr stuff
def indexed (f : SExpr) (args : List SExpr) : SExpr :=
list $ (atom "_")::f::args
inductive sort : Type
| smt_bool : sort
| bitvec : Nat -> sort
| array : sort -> sort -> sort
namespace sort
def bv8 := bitvec 8
def bv16 := bitvec 16
def bv32 := bitvec 32
def bv64 := bitvec 64
-- protected def hasDecEq : ∀(a b : sort), Decidable (a = b)
-- | smt_bool, bitvec _ => isFalse (λ h => sort.noConfusion h)
-- | smt_bool, array _ _ => isFalse (λ h => sort.noConfusion h)
-- | bitvec _, smt_bool => isFalse (λ h => sort.noConfusion h)
-- | bitvec _, array _ _ => isFalse (λ h => sort.noConfusion h)
-- | array _ _, bitvec _ => isFalse (λ h => sort.noConfusion h)
-- | array _ _, smt_bool => isFalse (λ h => sort.noConfusion h)
-- | smt_bool, smt_bool => isTrue rfl
-- | bitvec x, bitvec y =>
-- match decEq x y with
-- | isTrue hxy => isTrue (Eq.subst hxy rfl)
-- | isFalse nxy => isFalse (λ h => sort.noConfusion h (λ hxy => absurd hxy nxy))
-- | array a b, array c d =>
-- match hasDecEq a c with
-- | isTrue hac =>
-- match hasDecEq b d with
-- | isTrue hbd => isTrue (Eq.subst hac (Eq.subst hbd rfl))
-- | isFalse nbd => isFalse (λ h => sort.noConfusion h (λ _ hnb => absurd hnb nbd))
-- | isFalse nac => isFalse (λ h => sort.noConfusion h (λ hac _ => absurd hac nac))
-- instance : DecidableEq sort := sort.hasDecEq
protected def beq : sort → sort → Bool
| smt_bool, smt_bool => true
| bitvec n, bitvec m => n == m
| array a b, array c d => beq a c && beq b d
| _, _ => false
instance : HasBeq sort := ⟨sort.beq⟩
protected
def to_sexpr : sort -> SExpr
| smt_bool => atom "Bool"
| bitvec n => indexed (atom "BitVec") [atom n.repr]
| array k v => list [atom "Array", to_sexpr k, to_sexpr v]
instance : HasToSExpr sort := ⟨sort.to_sexpr⟩
-- *MkDecEq> putStrLn $ mkDecEq "sort" [("smt_bool", []), ("bitvec", [False]), ("array", [True, True])] "decidable_eq"
protected def decidable_eq : ∀(e e' : sort), Decidable (e = e')
| smt_bool, smt_bool => isTrue rfl
| (bitvec c1), (bitvec c1') =>
(match decEq c1 c1' with
| (isTrue h1) => isTrue (h1 ▸ rfl)
| (isFalse nh) => isFalse (fun h => sort.noConfusion h $ fun h1' => absurd h1' nh))
| (array c1 c2), (array c1' c2') =>
(match decidable_eq c1 c1', decidable_eq c2 c2' with
| (isTrue h1), (isTrue h2) => isTrue (h1 ▸ h2 ▸ rfl)
| (isFalse nh), _ => isFalse (fun h => sort.noConfusion h $ fun h1' h2' => absurd h1' nh)
| (isTrue _), (isFalse nh) => isFalse (fun h => sort.noConfusion h $ fun h1' h2' => absurd h2' nh))
| smt_bool, (bitvec _) => isFalse (fun h => sort.noConfusion h)
| smt_bool, (array _ _) => isFalse (fun h => sort.noConfusion h)
| (bitvec _), smt_bool => isFalse (fun h => sort.noConfusion h)
| (bitvec _), (array _ _) => isFalse (fun h => sort.noConfusion h)
| (array _ _), smt_bool => isFalse (fun h => sort.noConfusion h)
| (array _ _), (bitvec _) => isFalse (fun h => sort.noConfusion h)
instance : DecidableEq sort := sort.decidable_eq
def toString (s:sort) : String := (sort.to_sexpr s).toString
instance : HasToString sort := ⟨sort.toString⟩
end sort
namespace Raw
-- We use lowercase names for types to avoid clashing with Lean
-- This gets around having to have a list of args in term, which currently seems to break lean's
-- rec function support and codegen
-- Basically a list.
inductive const_sort : Type
| base : sort -> const_sort
| fsort : sort -> const_sort -> const_sort
namespace const_sort
def smt_bool := base sort.smt_bool
def bitvec (n : Nat) := base (sort.bitvec n)
def array (k v : sort) := base (sort.array k v)
end const_sort
def symbol := String
namespace symbol
instance : HasToSExpr symbol := ⟨atom⟩ -- maybe should quote?
end symbol
-- S3.2
inductive spec_constant : Type
| numeral : Nat -> spec_constant
| decimal : Nat -> Nat -> spec_constant
| binary : Nat -> Nat -> spec_constant -- nbits and value, subsumes hex (FIXME?)
| string : String -> spec_constant
namespace spec_constant
-- FIXME: copied from bitvec!
section to_hex
-- [0 ..< x]
protected def to_hex_with_leading_zeros : List Char → Nat → Nat → String
| prev, 0, _ => prev.asString
| prev, (Nat.succ w), x =>
let c := (Nat.land x 0xf).digitChar;
to_hex_with_leading_zeros (c::prev) w (Nat.shiftr x 4)
--- Print word as hex
def pp_bin (n : Nat) (v : Nat) : String :=
if n % 4 = 0
then "#x" ++ spec_constant.to_hex_with_leading_zeros [] (n / 4) v
else "#b" ++ (List.map (fun i => if Nat.test_bit v i then '1' else '0') (Nat.upto0_lt n)).asString
end to_hex
protected
def to_sexpr : spec_constant -> SExpr
| numeral n => toSExpr n
| decimal n f => atom (toString n ++ "." ++ toString f)
| binary n v => atom (pp_bin n v)
| string s => toSExpr s
instance : HasToSExpr spec_constant := ⟨spec_constant.to_sexpr⟩
end spec_constant
namespace builtin_identifier
open sort
open Nat
abbrev unop (a : sort) (b : sort) : const_sort :=
const_sort.fsort a (const_sort.base b)
abbrev binop (a : sort) (b : sort) (c : sort) : const_sort :=
const_sort.fsort a (const_sort.fsort b (const_sort.base c))
abbrev ternop (a : sort) (b : sort) (c : sort) (d : sort) : const_sort :=
const_sort.fsort a (binop b c d)
abbrev quadop (a : sort) (b : sort) (c : sort) (d : sort) (e : sort) : const_sort :=
const_sort.fsort a (ternop b c d e)
end builtin_identifier
section
open sort
open Nat
open builtin_identifier
def nary (s : sort) (t : sort) : Nat -> const_sort
| zero => const_sort.base t
| succ n => const_sort.fsort s (nary n)
-- distinct is a term as it has arbitrary arity
inductive builtin_identifier : const_sort -> Type
-- * Core theory
| true : builtin_identifier const_sort.smt_bool
| false : builtin_identifier const_sort.smt_bool
| not : builtin_identifier (unop smt_bool smt_bool)
| impl : builtin_identifier (binop smt_bool smt_bool smt_bool)
| and : builtin_identifier (binop smt_bool smt_bool smt_bool)
| or : builtin_identifier (binop smt_bool smt_bool smt_bool)
| xor : builtin_identifier (binop smt_bool smt_bool smt_bool)
| eq (s : sort) : builtin_identifier (binop s s smt_bool)
| smt_ite (s : sort) : builtin_identifier (const_sort.fsort smt_bool (binop s s s))
| distinct (s : sort) (arity : Nat)
: builtin_identifier (nary s smt_bool arity)
-- * Arrays
| select (k v : sort) : builtin_identifier (binop (array k v) k v)
| store (k v : sort) : builtin_identifier (ternop (array k v) k v (array k v))
-- CVC4 specific
| eqrange (k v : sort) : builtin_identifier (quadop (array k v) (array k v) k k smt_bool)
-- * BitVecs
-- hex/binary literals
| concat (n : Nat) (m : Nat) : builtin_identifier (binop (bitvec n) (bitvec m) (bitvec (n + m)))
| extract (n : Nat) (i : Nat) (j : Nat)
: builtin_identifier (unop (bitvec n) (bitvec (i + 1 - j)))
-- -- unops
| bvnot (n : Nat) : builtin_identifier (unop (bitvec n) (bitvec n))
| bvneg (n : Nat) : builtin_identifier (unop (bitvec n) (bitvec n))
-- -- binops
| bvand (n : Nat) : builtin_identifier (binop (bitvec n) (bitvec n) (bitvec n))
| bvor (n : Nat) : builtin_identifier (binop (bitvec n) (bitvec n) (bitvec n))
| bvadd (n : Nat) : builtin_identifier (binop (bitvec n) (bitvec n) (bitvec n))
| bvmul (n : Nat) : builtin_identifier (binop (bitvec n) (bitvec n) (bitvec n))
| bvudiv (n : Nat) : builtin_identifier (binop (bitvec n) (bitvec n) (bitvec n))
| bvurem (n : Nat) : builtin_identifier (binop (bitvec n) (bitvec n) (bitvec n))
| bvshl (n : Nat) : builtin_identifier (binop (bitvec n) (bitvec n) (bitvec n))
| bvlshr (n : Nat) : builtin_identifier (binop (bitvec n) (bitvec n) (bitvec n))
-- comparison
| bvult (n : Nat) : builtin_identifier (binop (bitvec n) (bitvec n) smt_bool)
-- Functions defined by SMT as abbrevs.
| bvnand (n : Nat) : builtin_identifier (binop (bitvec n) (bitvec n) (bitvec n))
| bvnor (n : Nat) : builtin_identifier (binop (bitvec n) (bitvec n) (bitvec n))
| bvxor (n : Nat) : builtin_identifier (binop (bitvec n) (bitvec n) (bitvec n))
| bvxnor (n : Nat) : builtin_identifier (binop (bitvec n) (bitvec n) (bitvec n))
| bvcomp (n : Nat) : builtin_identifier (binop (bitvec n) (bitvec n) (bitvec 1))
| bvsub (n : Nat) : builtin_identifier (binop (bitvec n) (bitvec n) (bitvec n))
| bvsdiv (n : Nat) : builtin_identifier (binop (bitvec n) (bitvec n) (bitvec n))
| bvsrem (n : Nat) : builtin_identifier (binop (bitvec n) (bitvec n) (bitvec n))
| bvsmod (n : Nat) : builtin_identifier (binop (bitvec n) (bitvec n) (bitvec n))
| bvashr (n : Nat) : builtin_identifier (binop (bitvec n) (bitvec n) (bitvec n))
-- Defined, param by i >= 1
| repeat (i : Nat) (n : Nat) : builtin_identifier (unop (bitvec n) (bitvec (i * n)))
-- Defined, param by i >= 0
| zero_extend (i : Nat) (n : Nat) : builtin_identifier (unop (bitvec n) (bitvec (n + i)))
| sign_extend (i : Nat) (n : Nat) : builtin_identifier (unop (bitvec n) (bitvec (n + i)))
| rotate_left (i : Nat) (n : Nat) : builtin_identifier (unop (bitvec n) (bitvec n))
| rotate_right (i : Nat) (n : Nat) : builtin_identifier (unop (bitvec n) (bitvec n))
| bvule (n : Nat) : builtin_identifier (binop (bitvec n) (bitvec n) smt_bool)
| bvugt (n : Nat) : builtin_identifier (binop (bitvec n) (bitvec n) smt_bool)
| bvuge (n : Nat) : builtin_identifier (binop (bitvec n) (bitvec n) smt_bool)
| bvslt (n : Nat) : builtin_identifier (binop (bitvec n) (bitvec n) smt_bool)
| bvsle (n : Nat) : builtin_identifier (binop (bitvec n) (bitvec n) smt_bool)
| bvsgt (n : Nat) : builtin_identifier (binop (bitvec n) (bitvec n) smt_bool)
| bvsge (n : Nat) : builtin_identifier (binop (bitvec n) (bitvec n) smt_bool)
end
namespace builtin_identifier
protected
def to_sexpr : forall {cs : const_sort}, builtin_identifier cs -> SExpr
-- * Core theory
| _, true => atom "true"
| _, false => atom "false"
| _, not => atom "not"
| _, impl => atom "=>"
| _, and => atom "and"
| _, or => atom "or"
| _, xor => atom "xor"
| _, eq _ => atom "="
| _, smt_ite _ => atom "ite"
| _, distinct _ _ => atom "distinct"
| _, select _ _ => atom "select"
| _, store _ _ => atom "store"
| _, eqrange _ _ => atom "eqrange"
-- * BitVecs
-- hex/binary literals
| _, concat _ _ => atom "concat"
| _, extract _ i j => indexed (atom "extract") [toSExpr i, toSExpr j]
-- unops
| _, bvnot _ => atom "bvnot"
| _, bvneg _ => atom "bvneg"
-- binops
| _, bvand _ => atom "bvand"
| _, bvor _ => atom "bvor"
| _, bvadd _ => atom "bvadd"
| _, bvmul _ => atom "bvmul"
| _, bvudiv _ => atom "bvudiv"
| _, bvurem _ => atom "bvurem"
| _, bvshl _ => atom "bvshl"
| _, bvlshr _ => atom "bvlshr"
-- comparison
| _, bvult _ => atom "bvult"
| _, bvnand _ => atom "bvnand"
| _, bvnor _ => atom "bvnor"
| _, bvxor _ => atom "bvxor"
| _, bvxnor _ => atom "bvxnor"
| _, bvcomp _ => atom "bvcomp"
| _, bvsub _ => atom "bvsub"
| _, bvsdiv _ => atom "bvsdiv"
| _, bvsrem _ => atom "bvsrem"
| _, bvsmod _ => atom "bvsmod"
| _, bvashr _ => atom "bvashr"
| _, repeat i _ => indexed (atom "repeat") [toSExpr i]
| _, zero_extend i _ => indexed (atom "zero_extend") [toSExpr i]
| _, sign_extend i _ => indexed (atom "sign_extend") [toSExpr i]
| _, rotate_left i _ => indexed (atom "rotate_left") [toSExpr i]
| _, rotate_right i _ => indexed (atom "rotate_right") [toSExpr i]
| _, bvule _ => atom "bvule"
| _, bvugt _ => atom "bvugt"
| _, bvuge _ => atom "bvuge"
| _, bvslt _ => atom "bvslt"
| _, bvsle _ => atom "bvsle"
| _, bvsgt _ => atom "bvsgt"
| _, bvsge _ => atom "bvsge"
instance {cs : const_sort} : HasToSExpr (builtin_identifier cs) := ⟨builtin_identifier.to_sexpr⟩
end builtin_identifier
inductive identifier : const_sort -> Type
| symbol (cs : const_sort) : symbol -> identifier cs
| builtin {cs : const_sort} : builtin_identifier cs -> identifier cs
namespace identifier
protected
def to_sexpr : forall {cs : const_sort}, identifier cs -> SExpr
| _, symbol _ s => atom s
| _, builtin bi => toSExpr bi
instance {cs : const_sort} : HasToSExpr (identifier cs) := ⟨identifier.to_sexpr⟩
end identifier
inductive sorted_var : sort -> Type
| mk (s : sort) : symbol -> sorted_var s
namespace sorted_var
protected
def to_sexpr : forall {s : sort}, sorted_var s -> SExpr
| _, mk s v => toSExpr [toSExpr v, toSExpr s]
instance {s : sort} : HasToSExpr (sorted_var s) := ⟨sorted_var.to_sexpr⟩
end sorted_var
-- S3.6
-- Use typed terms?
inductive term : const_sort -> Type
| const (s : sort) : spec_constant -> term (const_sort.base s)
| identifier {cs : const_sort} : identifier cs -> term cs
| app {s : sort} {cs : const_sort} : term (const_sort.fsort s cs)
-> term (const_sort.base s) -> term cs
| smt_let {s t : sort} : symbol -> term (const_sort.base t)
-> term (const_sort.base s)
-> term (const_sort.base s) -- single binding only
| smt_forall {s : sort} : sorted_var s -> term const_sort.smt_bool -> term const_sort.smt_bool
| smt_exists {s : sort} : sorted_var s -> term const_sort.smt_bool -> term const_sort.smt_bool
namespace term
-- Include a proof that relates the length of the sexpr list to the arity of the cs?x
protected
def to_sexpr_aux : forall {cs : const_sort} (t : term cs), List SExpr -> SExpr
| _, const _ sc, _ => toSExpr sc
-- identifier with base type, like 'true'
| _, identifier ident, [] => toSExpr ident
| _, identifier ident, args => SExpr.app (toSExpr ident) args
| _, app f x, args => to_sexpr_aux f (to_sexpr_aux x [] :: args)
| _, smt_let v e body, _ => toSExpr [atom "let"
, toSExpr [toSExpr [toSExpr v, to_sexpr_aux e []]]
, to_sexpr_aux body []]
| _, smt_forall v body, _ => SExpr.app (atom "forall") [toSExpr [toSExpr v], to_sexpr_aux body []]
| _, smt_exists v body, _ => SExpr.app (atom "exists") [toSExpr [toSExpr v], to_sexpr_aux body []]
instance {cs : const_sort} : HasToSExpr (term cs) := ⟨fun tm => term.to_sexpr_aux tm []⟩
end term
inductive logic
| all
namespace logic
def toString : logic → String
| all => "ALL"
end logic
inductive option
| produceModels : Bool → option
namespace option
def toSExprs : option → List SExpr
| produceModels b => [atom ":produce-models", (if b then (atom "true") else (atom "false"))]
end option
-- Scripts and Commands (S3.9)
inductive command
| assert : term const_sort.smt_bool -> command
| setLogic : logic → command
| setOption : option → command
| checkSatAssuming : List (term const_sort.smt_bool) → command
| comment : String → command
| exit : command
-- | check_sat : command
-- Not supported yet
-- | ( declare-datatype ⟨symbol⟩ ⟨datatype_dec⟩)
-- | ( declare-datatypes ( ⟨sort_dec ⟩n+1 ) ( ⟨datatype_dec ⟩n+1 ) ) | ( declare-fun ⟨symbol ⟩ ( ⟨sort ⟩∗ ) ⟨sort ⟩ )
-- | ( declare-sort ⟨symbol ⟩ ⟨numeral ⟩ ) -- not yet supported
-- | ( define-fun-rec ⟨function_def ⟩ )
-- | ( define-funs-rec ( ⟨function_dec⟩n+1 ) ( ⟨term⟩n+1 ) )
-- | ( define-sort ⟨symbol ⟩ ( ⟨symbol ⟩∗ ) ⟨sort ⟩ )
-- Syntactic sugar for declare-fun
-- | declare-const ⟨symbol ⟩ ⟨sort ⟩ )
| declare_fun : symbol -> List sort -> sort -> command
| define_fun : symbol -> List (Sigma sorted_var)
-> forall (s : sort), term (const_sort.base s) -> command
-- | echo : String -> command
-- | ( get-assertions )
-- | ( get-assignment )
-- | ( get-info ⟨info_flag ⟩ )
-- | ( get-model )
-- | ( get-option ⟨keyword ⟩ )
-- | ( get-proof )
-- | ( get-unsat-assumptions )
-- | ( get-unsat-core )
-- | ( get-value ( ⟨term⟩+ ) )
-- | ( pop ⟨numeral ⟩ )
-- | ( push ⟨numeral ⟩ )
-- | ( reset )
-- | ( reset-assertions )
-- | ( set-info ⟨attribute ⟩ )
-- | ( set-logic ⟨symbol ⟩ )
-- | ( set-option ⟨option⟩ )
namespace command
def to_sexpr_sigma : Sigma sorted_var -> SExpr
| Sigma.mk _ tm => toSExpr tm
protected
def to_sexpr : command -> SExpr
| assert tm => SExpr.app (atom "assert") [toSExpr tm]
| declare_fun s args r => SExpr.app (atom "declare-fun") [toSExpr s, toSExpr (args.map toSExpr), toSExpr r]
| define_fun s args r b => SExpr.app (atom "define-fun") [toSExpr s, toSExpr (args.map to_sexpr_sigma), toSExpr r
, toSExpr b]
| setLogic l =>
SExpr.app (atom "set-logic") [atom l.toString]
| setOption opt =>
SExpr.app (atom "set-option") opt.toSExprs
| checkSatAssuming assumptions =>
list [(atom "check-sat-assuming"), list $ assumptions.map toSExpr]
| comment content =>
let body : List Char := content.data.joinMap (λ c => if c == '\n' then ['\n',';',' '] else [c]);
atom $ "; " ++ body.asString ++ "\n"
| exit => SExpr.app (atom "exit") []
instance : HasToSExpr command := ⟨command.to_sexpr⟩
def isComment : command → Bool
| comment _ => true
| _ => false
end command
end Raw
-- *** Exported API ***
open sort
def term (s : sort) := Raw.term (Raw.const_sort.base s)
instance term.HasToSExpr (s : sort) : HasToSExpr (term s) :=
inferInstanceAs (HasToSExpr (Raw.term (Raw.const_sort.base s)))
def symbol := Raw.symbol
@[reducible]
def command := Raw.command
-- def identifier := Raw.identifier
@[reducible]
def args_to_type (ss : List sort) (res : sort) : Type
:= List.foldr (fun x t => term x -> t) (term res) ss
-- | [], res => term res
-- | (x :: xs), res => term x -> args_to_type xs res
-- -- given ident [a, b, c] and d, turns teram a -> term b -> term c -> term d into (ident [a, b, c])
-- def app_ident_aux (cs : const_sort) (ident : identifier cs)
-- : sorted_list term cs.args -> args_to_type cs.args cs.result
-- | nil => Raw.term.app_ident ident args.reverse
-- | (s :: ss), args => fun (t_s : term s) => app_ident_aux ss (t_s :: args)
-- def app_ident {args : List sort} {res : sort} (ident : identifier args res) : args_to_type args res
-- := app_ident_aux res ident args []
section
open Raw.term
open Raw.builtin_identifier
open Raw.identifier
open Raw.command
open Raw (const_sort)
open Raw.const_sort (fsort base)
open Raw (spec_constant)
open Raw.spec_constant
def const_sort_to_type : const_sort -> Type
| base s => term s
| fsort s t => term s -> const_sort_to_type t
def mk_symbol (sym : symbol) (s : sort) : term s :=
Raw.term.identifier (Raw.identifier.symbol (Raw.const_sort.base s) sym)
namespace Raw.identifier
-- inductive sorted_list (f : sort -> Type) : List sort -> Type
-- | nil : sorted_list []
-- | cons {s : sort} {ss : List sort} : f s -> sorted_list ss -> sorted_list (s :: ss)
protected
def expand_ident_aux : forall {cs : const_sort}, Raw.term cs -> const_sort_to_type cs
| base s, i => i
| fsort s t, i => fun x => expand_ident_aux (app i x)
def expand_ident {cs : const_sort} (i : Raw.identifier cs) : const_sort_to_type cs :=
Raw.identifier.expand_ident_aux (identifier i)
end Raw.identifier
private
def unop {s t : sort} (i : Raw.builtin_identifier (Raw.builtin_identifier.unop s t)) (a : term s)
: term t := app (identifier (builtin i)) a
private
def binop {a b c : sort} (i : Raw.builtin_identifier (Raw.builtin_identifier.binop a b c))
(x : term a) (y : term b) : term c := app (app (identifier (builtin i)) x) y
private
def ternop {a b c d : sort}
(i : Raw.builtin_identifier (Raw.builtin_identifier.ternop a b c d))
(x : term a) (y : term b) (z : term c) : term d
:= app (app (app (identifier (builtin i)) x) y) z
private
def quadop {a b c d e : sort}
(i : Raw.builtin_identifier (Raw.builtin_identifier.quadop a b c d e))
(w : term a) (x : term b) (y : term c) (z : term d) : term e
:= app (app (app (app (identifier (builtin i)) w) x) y) z
-- Builtin terms
def true : term smt_bool := identifier (builtin true)
def false : term smt_bool := identifier (builtin false)
def not : term smt_bool -> term smt_bool := unop not
def impl : term smt_bool -> term smt_bool -> term smt_bool := binop impl
def and : term smt_bool -> term smt_bool -> term smt_bool := binop and
def or : term smt_bool -> term smt_bool -> term smt_bool := binop or
def xor : term smt_bool -> term smt_bool -> term smt_bool := binop xor
def eq {a : sort} : term a -> term a -> term smt_bool := binop (eq a)
-- FIXME
-- def distinct {a : sort} : List (term a) -> term smt_bool := Raw.term.distinct
def smt_ite {a : sort} : term smt_bool -> term a -> term a -> term a := ternop (smt_ite a)
-- Arrays
def select (k v : sort) : term (array k v) -> term k -> term v :=
binop (select k v)
def store (k v : sort) : term (array k v) -> term k -> term v -> term (array k v) :=
ternop (store k v)
def eqrange {k v : sort} : term (array k v) -> term (array k v) -> term k -> term k -> term smt_bool
:= quadop (eqrange k v)
-- BitVecs
-- hex/binary literals
def bvimm (n v : Nat) : term (bitvec n) := const (bitvec n) (binary n v)
-- c.f. bitvec.of_int
def bvimm' (n : Nat) : Int -> term (bitvec n)
| Int.ofNat x => bvimm n x
| Int.negSucc x => bvimm n (Nat.ldiff (2^n-1) x)
def bvAsConst {n : Nat} : term (bitvec n) -> Option Nat
| const _ (binary _ v) => some v
| _ => none
def concat {n m : Nat} : term (bitvec n) -> term (bitvec m) -> term (bitvec (n + m)) :=
binop (concat n m)
def extract {n : Nat} (i : Nat) (j : Nat) : term (bitvec n) -> term (bitvec (i + 1 - j)) :=
unop (extract n i j)
def bvnot {n : Nat} : term (bitvec n) -> term (bitvec n) := unop (bvnot n)
def bvneg {n : Nat} : term (bitvec n) -> term (bitvec n) := unop (bvneg n)
-- binops
def bvand {n : Nat} : term (bitvec n) -> term (bitvec n) -> term (bitvec n) := binop (bvand n)
def bvor {n : Nat} : term (bitvec n) -> term (bitvec n) -> term (bitvec n) := binop (bvor n)
def bvadd {n : Nat} : term (bitvec n) -> term (bitvec n) -> term (bitvec n) := binop (bvadd n)
def bvmul {n : Nat} : term (bitvec n) -> term (bitvec n) -> term (bitvec n) := binop (bvmul n)
def bvudiv {n : Nat} : term (bitvec n) -> term (bitvec n) -> term (bitvec n) := binop (bvudiv n)
def bvurem {n : Nat} : term (bitvec n) -> term (bitvec n) -> term (bitvec n) := binop (bvurem n)
def bvshl {n : Nat} : term (bitvec n) -> term (bitvec n) -> term (bitvec n) := binop (bvshl n)
def bvlshr {n : Nat} : term (bitvec n) -> term (bitvec n) -> term (bitvec n) := binop (bvlshr n)
-- comparison
def bvult {n : Nat} : term (bitvec n) -> term (bitvec n) -> term smt_bool := binop (bvult n)
-- Functions defined by SMT as abbrevs.
def bvnand {n : Nat} : term (bitvec n) -> term (bitvec n) -> term (bitvec n) := binop (bvnand n)
def bvnor {n : Nat} : term (bitvec n) -> term (bitvec n) -> term (bitvec n) := binop (bvnor n)
def bvxor {n : Nat} : term (bitvec n) -> term (bitvec n) -> term (bitvec n) := binop (bvxor n)
def bvxnor {n : Nat} : term (bitvec n) -> term (bitvec n) -> term (bitvec n) := binop (bvxnor n)
def bvcomp {n : Nat} : term (bitvec n) -> term (bitvec n) -> term (bitvec 1) := binop (bvcomp n)
def bvsub {n : Nat} : term (bitvec n) -> term (bitvec n) -> term (bitvec n) := binop (bvsub n)
def bvsdiv {n : Nat} : term (bitvec n) -> term (bitvec n) -> term (bitvec n) := binop (bvsdiv n)
def bvsrem {n : Nat} : term (bitvec n) -> term (bitvec n) -> term (bitvec n) := binop (bvsrem n)
def bvsmod {n : Nat} : term (bitvec n) -> term (bitvec n) -> term (bitvec n) := binop (bvsmod n)
def bvashr {n : Nat} : term (bitvec n) -> term (bitvec n) -> term (bitvec n) := binop (bvashr n)
-- Defined, param by i >= 1
def repeat {n : Nat} (i : Nat) : term (bitvec n) -> term (bitvec (i * n)) := unop (repeat i n)
-- Defined, param by i >= 0
def zero_extend {n : Nat} (i : Nat) : term (bitvec n) -> term (bitvec (n + i)) := unop (zero_extend i n)
def sign_extend {n : Nat} (i : Nat) : term (bitvec n) -> term (bitvec (n + i)) := unop (sign_extend i n)
def rotate_left {n : Nat} (i : Nat) : term (bitvec n) -> term (bitvec n) := unop (rotate_left i n)
def rotate_right {n : Nat} (i : Nat) : term (bitvec n) -> term (bitvec n) := unop (rotate_right i n)
def bvule {n : Nat} : term (bitvec n) -> term (bitvec n) -> term smt_bool := binop (bvule n)
def bvugt {n : Nat} : term (bitvec n) -> term (bitvec n) -> term smt_bool := binop (bvugt n)
def bvuge {n : Nat} : term (bitvec n) -> term (bitvec n) -> term smt_bool := binop (bvuge n)
def bvslt {n : Nat} : term (bitvec n) -> term (bitvec n) -> term smt_bool := binop (bvslt n)
def bvsle {n : Nat} : term (bitvec n) -> term (bitvec n) -> term smt_bool := binop (bvsle n)
def bvsgt {n : Nat} : term (bitvec n) -> term (bitvec n) -> term smt_bool := binop (bvsgt n)
def bvsge {n : Nat} : term (bitvec n) -> term (bitvec n) -> term smt_bool := binop (bvsge n)
-- Pure version, doesn't touch the symbol name
def smt_let {s t : sort} (v : symbol) (e : term s) (body : term s -> term t) : term t :=
let v_e := mk_symbol v s;
Raw.term.smt_let v e (body v_e)
-- Scripts and Commands
def script : Type := List command
structure SMTState :=
(idGen : IdGen)
(script : script)
def smtM := StateM SMTState
instance : Monad smtM := inferInstanceAs (Monad (StateM SMTState))
instance : MonadState SMTState smtM := inferInstanceAs (MonadState SMTState (StateM SMTState))
/-- Generate a fresh symbol in the monad, if possible simply using the suggested string. --/
def freshSymbol (suggestedStr : String) : smtM String := do
(idGen', sym) ← (λ (g:IdGen) => g.genId suggestedStr) <$> SMTState.idGen <$> get;
modify (λ s => {s with idGen := idGen'});
pure sym
def runsmtM {a : Type} (idGen : IdGen) (m : smtM a) : (a × IdGen × script) :=
let r := StateT.run m { idGen := idGen, script := [] };
(r.fst, (r.snd.idGen, r.snd.script.reverse))
theorem const_sort_to_type_fold {res : sort} : forall {args : List sort},
const_sort_to_type (List.foldr fsort (base res) args) = args_to_type args res -- := sorryAx _
| [] => rfl
| hd :: tl => congrArg (fun r => (term hd -> r)) (@const_sort_to_type_fold tl)
def declare_fun (s : String) (args : List sort) (res : sort) : smtM (args_to_type args res) := do
s' <- freshSymbol s;
let ident := Raw.identifier.symbol (List.foldr fsort (base res) args) s';
do modify (fun st => {st with script := (declare_fun s' args res) :: st.script });
pure (Eq.mp const_sort_to_type_fold ident.expand_ident)
def inst_args_aux (res : sort) :
forall (args : List sort) (body : args_to_type args res) (acc : List (Sigma Raw.sorted_var)),
smtM (List (Sigma Raw.sorted_var) × term res)
| [], body, acc => pure (acc.reverse, body)
| hd :: tl, f, acc => do
s <- freshSymbol "arg";
let arg := mk_symbol s hd;
inst_args_aux tl (f arg) (Sigma.mk hd (Raw.sorted_var.mk hd s) :: acc)
def inst_args (res : sort) (args : List sort) (body : args_to_type args res)
: smtM (List (Sigma Raw.sorted_var) × term res) :=
inst_args_aux res args body []
def define_fun (s : String) (args : List sort) (res : sort) (body : args_to_type args res)
: smtM (args_to_type args res) := do
s' <- freshSymbol s;
let ident := Raw.identifier.symbol (List.foldr fsort (base res) args) s';
(args', body') <- inst_args res args body;
do modify (fun st => {st with script := (define_fun s' args' res body') :: st.script });
pure (Eq.mp const_sort_to_type_fold ident.expand_ident)
def is_atomic : forall {s : const_sort}, Raw.term s -> Bool
| _, Raw.term.const _ _ => Bool.true
| _, Raw.term.identifier _ => Bool.true
| _, Raw.term.app _ _ => Bool.false
| _, Raw.term.smt_let _ _ _ => Bool.false
| _, Raw.term.smt_forall _ _ => Bool.false
| _, Raw.term.smt_exists _ _ => Bool.false
-- Names the const if it is non-trivial, otherwise returns the original term
def name_term (name : String) {s : sort} (tm : term s) : smtM (term s) :=
if is_atomic tm then pure tm else define_fun name [] s tm
def assert (b : term smt_bool) : smtM Unit :=
modify (fun st => {st with script := (Raw.command.assert b) :: st.script })
def comment (content : String) : smtM Unit :=
modify (fun st => {st with script := (Raw.command.comment content) :: st.script })
def setLogic (l : Raw.logic) : smtM Unit :=
modify (fun st => {st with script := (Raw.command.setLogic l) :: st.script })
def setOption (o : Raw.option) : smtM Unit :=
modify (fun st => {st with script := (Raw.command.setOption o) :: st.script })
def setProduceModels (b : Bool) : smtM Unit :=
modify (fun st => {st with script := (Raw.command.setOption (Raw.option.produceModels b)) :: st.script})
def checkSatAssuming (bs : List (term smt_bool)) : smtM Unit :=
modify (fun st => {st with script := (Raw.command.checkSatAssuming bs) :: st.script })
def exit : smtM Unit :=
modify (fun st => {st with script := Raw.command.exit :: st.script })
def ex1 : smtM Unit :=
do f <- declare_fun "f" [smt_bool, smt_bool] smt_bool;
assert (f true false)
def liftCommand (c : command) : smtM Unit :=
modify (fun st => {st with script := c :: st.script })
inductive CheckSatResult
| sat : CheckSatResult
| unsat : CheckSatResult
| unknown : CheckSatResult
| unsupported : CheckSatResult
| unrecognized : String → CheckSatResult
def parseCheckSatResult (rawStr : String) : CheckSatResult :=
match rawStr.trim with
| "sat" => CheckSatResult.sat
| "unsat" => CheckSatResult.unsat
| "unknown" => CheckSatResult.unknown
| "unsupported" => CheckSatResult.unsupported
| other => CheckSatResult.unrecognized other
-- #check true
-- #check false
-- #eval toString (List.map toSExpr (runsmtM ex1))
/-- Converts a command to a string terminated by a newline.--/
def command.toLine (c:command) : String :=
let cStr := (WellFormedSExp.SExp.toString (toSExpr c));
if c.isComment
then cStr
else cStr ++ "\n"
end
end SMT
|
2ec309a8acfba704b7ae833b154ab9254b722c93 | 35677d2df3f081738fa6b08138e03ee36bc33cad | /src/tactic/restate_axiom.lean | cc933bb41b5a4d5886d91a538c56e69f965e22bf | [
"Apache-2.0"
] | permissive | gebner/mathlib | eab0150cc4f79ec45d2016a8c21750244a2e7ff0 | cc6a6edc397c55118df62831e23bfbd6e6c6b4ab | refs/heads/master | 1,625,574,853,976 | 1,586,712,827,000 | 1,586,712,827,000 | 99,101,412 | 1 | 0 | Apache-2.0 | 1,586,716,389,000 | 1,501,667,958,000 | Lean | UTF-8 | Lean | false | false | 3,223 | lean | /-
Copyright (c) 2017 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import data.buffer.parser tactic.doc_commands
open lean.parser tactic interactive parser
/--
`restate_axiom` takes a structure field, and makes a new, definitionally simplified copy of it.
If the existing field name ends with a `'`, the new field just has the prime removed. Otherwise,
we append `_lemma`.
The main application is to provide clean versions of structure fields that have been tagged with
an auto_param.
-/
meta def restate_axiom (d : declaration) (new_name : name) : tactic unit :=
do (levels, type, value, reducibility, trusted) ← pure (match d.to_definition with
| declaration.defn name levels type value reducibility trusted :=
(levels, type, value, reducibility, trusted)
| _ := undefined
end),
(s, u) ← mk_simp_set ff [] [],
new_type ← (s.dsimplify [] type) <|> pure (type),
prop ← is_prop new_type,
let new_decl := if prop then
declaration.thm new_name levels new_type (task.pure value)
else
declaration.defn new_name levels new_type value reducibility trusted,
updateex_env $ λ env, env.add new_decl
private meta def name_lemma (old : name) (new : option name := none) : tactic name :=
match new with
| none :=
match old.components.reverse with
| last :: most := (do let last := last.to_string,
let last := if last.to_list.ilast = ''' then
(last.to_list.reverse.drop 1).reverse.as_string
else last ++ "_lemma",
return (mk_str_name old.get_prefix last)) <|> failed
| nil := undefined
end
| (some new) := return (mk_str_name old.get_prefix new.to_string)
end
/--
`restate_axiom` makes a new copy of a structure field, first definitionally simplifying the type.
This is useful to remove `auto_param` or `opt_param` from the statement.
As an example, we have:
```lean
structure A :=
(x : ℕ)
(a' : x = 1 . skip)
example (z : A) : z.x = 1 := by rw A.a' -- rewrite tactic failed, lemma is not an equality nor a iff
restate_axiom A.a'
example (z : A) : z.x = 1 := by rw A.a
```
By default, `restate_axiom` names the new lemma by removing a trailing `'`, or otherwise appending
`_lemma` if there is no trailing `'`. You can also give `restate_axiom` a second argument to
specify the new name, as in
```lean
restate_axiom A.a f
example (z : A) : z.x = 1 := by rw A.f
```
-/
@[user_command] meta def restate_axiom_cmd (meta_info : decl_meta_info)
(_ : parse $ tk "restate_axiom") : lean.parser unit :=
do from_lemma ← ident,
new_name ← optional ident,
from_lemma_fully_qualified ← resolve_constant from_lemma,
d ← get_decl from_lemma_fully_qualified <|>
fail ("declaration " ++ to_string from_lemma ++ " not found"),
do {
new_name ← name_lemma from_lemma_fully_qualified new_name,
restate_axiom d new_name
}
add_tactic_doc
{ name := "restate_axiom",
category := doc_category.cmd,
decl_names := [`restate_axiom_cmd],
tags := ["renaming", "environment"] }
|
3088ee5a34acd53013302072f6cfc67439a3c215 | bdb33f8b7ea65f7705fc342a178508e2722eb851 | /set_theory/zfc.lean | c7e9193771b31611054290e2f903a823d228d276 | [
"Apache-2.0"
] | permissive | rwbarton/mathlib | 939ae09bf8d6eb1331fc2f7e067d39567e10e33d | c13c5ea701bb1eec057e0a242d9f480a079105e9 | refs/heads/master | 1,584,015,335,862 | 1,524,142,167,000 | 1,524,142,167,000 | 130,614,171 | 0 | 0 | Apache-2.0 | 1,548,902,667,000 | 1,524,437,371,000 | Lean | UTF-8 | Lean | false | false | 29,849 | lean | import data.set.basic
universes u v
/-- The type of `n`-ary functions `α → α → ... → α`. -/
def arity (α : Type u) : nat → Type u
| 0 := α
| (n+1) := α → arity n
/-- The type of pre-sets in universe `u`. A pre-set
is a family of pre-sets indexed by a type in `Type u`.
The ZFC universe is defined as a quotient of this
to ensure extensionality. -/
inductive pSet : Type (u+1)
| mk (α : Type u) (A : α → pSet) : pSet
namespace pSet
/-- The underlying type of a pre-set -/
def type : pSet → Type u
| ⟨α, A⟩ := α
/-- The underlying pre-set family of a pre-set -/
def func : Π (x : pSet), x.type → pSet
| ⟨α, A⟩ := A
theorem mk_type_func : Π (x : pSet), mk x.type x.func = x
| ⟨α, A⟩ := rfl
/-- Two pre-sets are extensionally equivalent if every
element of the first family is extensionally equivalent to
some element of the second family and vice-versa. -/
def equiv (x y : pSet) : Prop :=
pSet.rec (λα z m ⟨β, B⟩, (∀a, ∃b, m a (B b)) ∧ (∀b, ∃a, m a (B b))) x y
theorem equiv.refl (x) : equiv x x :=
pSet.rec_on x $ λα A IH, ⟨λa, ⟨a, IH a⟩, λa, ⟨a, IH a⟩⟩
theorem equiv.euc {x} : Π {y z}, equiv x y → equiv z y → equiv x z :=
pSet.rec_on x $ λα A IH y, pSet.rec_on y $ λβ B _ ⟨γ, Γ⟩ ⟨αβ, βα⟩ ⟨γβ, βγ⟩,
⟨λa, let ⟨b, ab⟩ := αβ a, ⟨c, bc⟩ := βγ b in ⟨c, IH a ab bc⟩,
λc, let ⟨b, cb⟩ := γβ c, ⟨a, ba⟩ := βα b in ⟨a, IH a ba cb⟩⟩
theorem equiv.symm {x y} : equiv x y → equiv y x :=
equiv.euc (equiv.refl y)
theorem equiv.trans {x y z} (h1 : equiv x y) (h2 : equiv y z) : equiv x z :=
equiv.euc h1 (equiv.symm h2)
instance setoid : setoid pSet :=
⟨pSet.equiv, equiv.refl, λx y, equiv.symm, λx y z, equiv.trans⟩
protected def subset : pSet → pSet → Prop
| ⟨α, A⟩ ⟨β, B⟩ := ∀a, ∃b, equiv (A a) (B b)
instance : has_subset pSet := ⟨pSet.subset⟩
theorem equiv.ext : Π (x y : pSet), equiv x y ↔ (x ⊆ y ∧ y ⊆ x)
| ⟨α, A⟩ ⟨β, B⟩ :=
⟨λ⟨αβ, βα⟩, ⟨αβ, λb, let ⟨a, h⟩ := βα b in ⟨a, equiv.symm h⟩⟩,
λ⟨αβ, βα⟩, ⟨αβ, λb, let ⟨a, h⟩ := βα b in ⟨a, equiv.symm h⟩⟩⟩
theorem subset.congr_left : Π {x y z : pSet}, equiv x y → (x ⊆ z ↔ y ⊆ z)
| ⟨α, A⟩ ⟨β, B⟩ ⟨γ, Γ⟩ ⟨αβ, βα⟩ :=
⟨λαγ b, let ⟨a, ba⟩ := βα b, ⟨c, ac⟩ := αγ a in ⟨c, equiv.trans (equiv.symm ba) ac⟩,
λβγ a, let ⟨b, ab⟩ := αβ a, ⟨c, bc⟩ := βγ b in ⟨c, equiv.trans ab bc⟩⟩
theorem subset.congr_right : Π {x y z : pSet}, equiv x y → (z ⊆ x ↔ z ⊆ y)
| ⟨α, A⟩ ⟨β, B⟩ ⟨γ, Γ⟩ ⟨αβ, βα⟩ :=
⟨λγα c, let ⟨a, ca⟩ := γα c, ⟨b, ab⟩ := αβ a in ⟨b, equiv.trans ca ab⟩,
λγβ c, let ⟨b, cb⟩ := γβ c, ⟨a, ab⟩ := βα b in ⟨a, equiv.trans cb (equiv.symm ab)⟩⟩
/-- `x ∈ y` as pre-sets if `x` is extensionally equivalent to a member
of the family `y`. -/
def mem : pSet → pSet → Prop
| x ⟨β, B⟩ := ∃b, equiv x (B b)
instance : has_mem pSet.{u} pSet.{u} := ⟨mem⟩
theorem mem.mk {α: Type u} (A : α → pSet) (a : α) : A a ∈ mk α A :=
show mem (A a) ⟨α, A⟩, from ⟨a, equiv.refl (A a)⟩
theorem mem.ext : Π {x y : pSet.{u}}, (∀w:pSet.{u}, w ∈ x ↔ w ∈ y) → equiv x y
| ⟨α, A⟩ ⟨β, B⟩ h := ⟨λa, (h (A a)).1 (mem.mk A a),
λb, let ⟨a, ha⟩ := (h (B b)).2 (mem.mk B b) in ⟨a, equiv.symm ha⟩⟩
theorem mem.congr_right : Π {x y : pSet.{u}}, equiv x y → (∀{w:pSet.{u}}, w ∈ x ↔ w ∈ y)
| ⟨α, A⟩ ⟨β, B⟩ ⟨αβ, βα⟩ w :=
⟨λ⟨a, ha⟩, let ⟨b, hb⟩ := αβ a in ⟨b, equiv.trans ha hb⟩,
λ⟨b, hb⟩, let ⟨a, ha⟩ := βα b in ⟨a, equiv.euc hb ha⟩⟩
theorem equiv_iff_mem {x y : pSet.{u}} : equiv x y ↔ (∀{w:pSet.{u}}, w ∈ x ↔ w ∈ y) :=
⟨mem.congr_right, match x, y with
| ⟨α, A⟩, ⟨β, B⟩, h := ⟨λ a, h.1 (mem.mk A a), λ b,
let ⟨a, h⟩ := h.2 (mem.mk B b) in ⟨a, h.symm⟩⟩
end⟩
theorem mem.congr_left : Π {x y : pSet.{u}}, equiv x y → (∀{w : pSet.{u}}, x ∈ w ↔ y ∈ w)
| x y h ⟨α, A⟩ := ⟨λ⟨a, ha⟩, ⟨a, equiv.trans (equiv.symm h) ha⟩, λ⟨a, ha⟩, ⟨a, equiv.trans h ha⟩⟩
/-- Convert a pre-set to a `set` of pre-sets. -/
def to_set (u : pSet.{u}) : set pSet.{u} := {x | x ∈ u}
/-- Two pre-sets are equivalent iff they have the same members. -/
theorem equiv.eq {x y : pSet} : equiv x y ↔ to_set x = to_set y :=
equiv_iff_mem.trans (set.set_eq_def _ _).symm
instance : has_coe pSet (set pSet) := ⟨to_set⟩
/-- The empty pre-set -/
protected def empty : pSet := ⟨ulift empty, λe, match e with end⟩
instance : has_emptyc pSet := ⟨pSet.empty⟩
theorem mem_empty (x : pSet.{u}) : x ∉ (∅:pSet.{u}) := λe, match e with end
/-- Insert an element into a pre-set -/
protected def insert : pSet → pSet → pSet
| u ⟨α, A⟩ := ⟨option α, λo, option.rec u A o⟩
instance : has_insert pSet pSet := ⟨pSet.insert⟩
/-- The n-th von Neumann ordinal -/
def of_nat : ℕ → pSet
| 0 := ∅
| (n+1) := pSet.insert (of_nat n) (of_nat n)
/-- The von Neumann ordinal ω -/
def omega : pSet := ⟨ulift ℕ, λn, of_nat n.down⟩
/-- The separation operation `{x ∈ a | p x}` -/
protected def sep (p : set pSet) : pSet → pSet
| ⟨α, A⟩ := ⟨{a // p (A a)}, λx, A x.1⟩
instance : has_sep pSet pSet := ⟨pSet.sep⟩
/-- The powerset operator -/
def powerset : pSet → pSet
| ⟨α, A⟩ := ⟨set α, λp, ⟨{a // p a}, λx, A x.1⟩⟩
theorem mem_powerset : Π {x y : pSet}, y ∈ powerset x ↔ y ⊆ x
| ⟨α, A⟩ ⟨β, B⟩ := ⟨λ⟨p, e⟩, (subset.congr_left e).2 $ λ⟨a, pa⟩, ⟨a, equiv.refl (A a)⟩,
λβα, ⟨{a | ∃b, equiv (B b) (A a)}, λb, let ⟨a, ba⟩ := βα b in ⟨⟨a, b, ba⟩, ba⟩,
λ⟨a, b, ba⟩, ⟨b, ba⟩⟩⟩
/-- The set union operator -/
def Union : pSet → pSet
| ⟨α, A⟩ := ⟨Σx, (A x).type, λ⟨x, y⟩, (A x).func y⟩
theorem mem_Union : Π {x y : pSet.{u}}, y ∈ Union x ↔ ∃ z:pSet.{u}, ∃_:z ∈ x, y ∈ z
| ⟨α, A⟩ y :=
⟨λ⟨⟨a, c⟩, (e : equiv y ((A a).func c))⟩,
have func (A a) c ∈ mk (A a).type (A a).func, from mem.mk (A a).func c,
⟨_, mem.mk _ _, (mem.congr_left e).2 (by rwa mk_type_func at this)⟩,
λ⟨⟨β, B⟩, ⟨a, (e:equiv (mk β B) (A a))⟩, ⟨b, yb⟩⟩,
by rw ←(mk_type_func (A a)) at e; exact
let ⟨βt, tβ⟩ := e, ⟨c, bc⟩ := βt b in ⟨⟨a, c⟩, equiv.trans yb bc⟩⟩
/-- The image of a function -/
def image (f : pSet.{u} → pSet.{u}) : pSet.{u} → pSet
| ⟨α, A⟩ := ⟨α, λa, f (A a)⟩
theorem mem_image {f : pSet.{u} → pSet.{u}} (H : ∀{x y}, equiv x y → equiv (f x) (f y)) :
Π {x y : pSet.{u}}, y ∈ image f x ↔ ∃z ∈ x, equiv y (f z)
| ⟨α, A⟩ y := ⟨λ⟨a, ya⟩, ⟨A a, mem.mk A a, ya⟩, λ⟨z, ⟨a, za⟩, yz⟩, ⟨a, equiv.trans yz (H za)⟩⟩
/-- Universe lift operation -/
protected def lift : pSet.{u} → pSet.{max u v}
| ⟨α, A⟩ := ⟨ulift α, λ⟨x⟩, lift (A x)⟩
/-- Embedding of one universe in another -/
def embed : pSet.{max (u+1) v} := ⟨ulift.{v u+1} pSet, λ⟨x⟩, pSet.lift.{u (max (u+1) v)} x⟩
theorem lift_mem_embed : Π (x : pSet.{u}), pSet.lift.{u (max (u+1) v)} x ∈ embed.{u v} :=
λx, ⟨⟨x⟩, equiv.refl _⟩
/-- Function equivalence is defined so that `f ~ g` iff
`∀ x y, x ~ y → f x ~ g y`. This extends to equivalence of n-ary
functions. -/
def arity.equiv : Π {n}, arity pSet.{u} n → arity pSet.{u} n → Prop
| 0 a b := equiv a b
| (n+1) a b := ∀ x y, equiv x y → arity.equiv (a x) (b y)
/-- `resp n` is the collection of n-ary functions on `pSet` that respect
equivalence, i.e. when the inputs are equivalent the output is as well. -/
def resp (n) := { x : arity pSet.{u} n // arity.equiv x x }
def resp.f {n} (f : resp (n+1)) (x : pSet) : resp n :=
⟨f.1 x, f.2 _ _ $ equiv.refl x⟩
def resp.equiv {n} (a b : resp n) : Prop := arity.equiv a.1 b.1
theorem resp.refl {n} (a : resp n) : resp.equiv a a := a.2
theorem resp.euc : Π {n} {a b c : resp n}, resp.equiv a b → resp.equiv c b → resp.equiv a c
| 0 a b c hab hcb := equiv.euc hab hcb
| (n+1) a b c hab hcb := by delta resp.equiv; simp [arity.equiv]; exact λx y h,
@resp.euc n (a.f x) (b.f y) (c.f y) (hab _ _ h) (hcb _ _ $ equiv.refl y)
instance resp.setoid {n} : setoid (resp n) :=
⟨resp.equiv, resp.refl, λx y h, resp.euc (resp.refl y) h, λx y z h1 h2, resp.euc h1 $ resp.euc (resp.refl z) h2⟩
end pSet
/-- The ZFC universe of sets consists of the type of pre-sets,
quotiented by extensional equivalence. -/
def Set : Type (u+1) := quotient pSet.setoid.{u}
namespace pSet
namespace resp
def eval_aux : Π {n}, { f : resp n → arity Set.{u} n // ∀ (a b : resp n), resp.equiv a b → f a = f b }
| 0 := ⟨λa, ⟦a.1⟧, λa b h, quotient.sound h⟩
| (n+1) := let F : resp (n + 1) → arity Set (n + 1) := λa, @quotient.lift _ _ pSet.setoid
(λx, eval_aux.1 (a.f x)) (λb c h, eval_aux.2 _ _ (a.2 _ _ h)) in
⟨F, λb c h, funext $ @quotient.ind _ _ (λq, F b q = F c q) $ λz,
eval_aux.2 (resp.f b z) (resp.f c z) (h _ _ (equiv.refl z))⟩
/-- An equivalence-respecting function yields an n-ary Set function. -/
def eval (n) : resp n → arity Set.{u} n := eval_aux.1
@[simp] def eval_val {n f x} : (@eval (n+1) f : Set → arity Set n) ⟦x⟧ = eval n (resp.f f x) := rfl
end resp
/-- A set function is "definable" if it is the image of some n-ary pre-set
function. This isn't exactly definability, but is useful as a sufficient
condition for functions that have a computable image. -/
@[class] inductive definable (n) : arity Set.{u} n → Type (u+1)
| mk (f) : definable (resp.eval _ f)
attribute [instance] definable.mk
def definable.eq_mk {n} (f) : Π {s : arity Set.{u} n} (H : resp.eval _ f = s), definable n s
| ._ rfl := ⟨f⟩
def definable.resp {n} : Π (s : arity Set.{u} n) [definable n s], resp n
| ._ ⟨f⟩ := f
theorem definable.eq {n} : Π (s : arity Set.{u} n) [H : definable n s], (@definable.resp n s H).eval _ = s
| ._ ⟨f⟩ := rfl
end pSet
namespace classical
open pSet
noncomputable theorem all_definable : Π {n} (F : arity Set.{u} n), definable n F
| 0 F := let p := @quotient.exists_rep pSet _ F in
definable.eq_mk ⟨some p, equiv.refl _⟩ (some_spec p)
| (n+1) (F : arity Set.{u} (n + 1)) := begin
have I := λx, (all_definable (F x)),
refine definable.eq_mk ⟨λx:pSet, (@definable.resp _ _ (I ⟦x⟧)).1, _⟩ _,
{ dsimp [arity.equiv],
introsI x y h,
rw @quotient.sound pSet _ _ _ h,
exact (definable.resp (F ⟦y⟧)).2 },
exact funext (λq, quotient.induction_on q $ λx,
by simp [resp.f]; exact @definable.eq _ (F ⟦x⟧) (I ⟦x⟧))
end
end classical
namespace Set
open pSet
def mk : pSet → Set := quotient.mk
@[simp] theorem mk_eq (x : pSet) : @eq Set ⟦x⟧ (mk x) := rfl
def mem : Set → Set → Prop :=
quotient.lift₂ pSet.mem
(λx y x' y' hx hy, propext (iff.trans (mem.congr_left hx) (mem.congr_right hy)))
instance : has_mem Set Set := ⟨mem⟩
/-- Convert a ZFC set into a `set` of sets -/
def to_set (u : Set.{u}) : set Set.{u} := {x | x ∈ u}
protected def subset (x y : Set.{u}) :=
∀ ⦃z⦄, z ∈ x → z ∈ y
instance has_subset : has_subset Set :=
⟨Set.subset⟩
theorem subset_iff : Π (x y : pSet), mk x ⊆ mk y ↔ x ⊆ y
| ⟨α, A⟩ ⟨β, B⟩ := ⟨λh a, @h ⟦A a⟧ (mem.mk A a),
λh z, quotient.induction_on z (λz ⟨a, za⟩, let ⟨b, ab⟩ := h a in ⟨b, equiv.trans za ab⟩)⟩
theorem ext {x y : Set.{u}} : (∀z:Set.{u}, z ∈ x ↔ z ∈ y) → x = y :=
quotient.induction_on₂ x y (λu v h, quotient.sound (mem.ext (λw, h ⟦w⟧)))
theorem ext_iff {x y : Set.{u}} : (∀z:Set.{u}, z ∈ x ↔ z ∈ y) ↔ x = y :=
⟨ext, λh, by simp [h]⟩
/-- The empty set -/
def empty : Set := mk ∅
instance : has_emptyc Set := ⟨empty⟩
instance : inhabited Set := ⟨∅⟩
@[simp] theorem mem_empty (x) : x ∉ (∅:Set.{u}) :=
quotient.induction_on x pSet.mem_empty
theorem eq_empty (x : Set.{u}) : x = ∅ ↔ ∀y:Set.{u}, y ∉ x :=
⟨λh, by rw h; exact mem_empty,
λh, ext (λy, ⟨λyx, absurd yx (h y), λy0, absurd y0 (mem_empty _)⟩)⟩
/-- `insert x y` is the set `{x} ∪ y` -/
protected def insert : Set → Set → Set :=
resp.eval 2 ⟨pSet.insert, λu v uv ⟨α, A⟩ ⟨β, B⟩ ⟨αβ, βα⟩,
⟨λo, match o with
| some a := let ⟨b, hb⟩ := αβ a in ⟨some b, hb⟩
| none := ⟨none, uv⟩
end, λo, match o with
| some b := let ⟨a, ha⟩ := βα b in ⟨some a, ha⟩
| none := ⟨none, uv⟩
end⟩⟩
instance : has_insert Set Set := ⟨Set.insert⟩
@[simp] theorem mem_insert {x y z : Set.{u}} : x ∈ insert y z ↔ x = y ∨ x ∈ z :=
quotient.induction_on₃ x y z
(λx y ⟨α, A⟩, show x ∈ pSet.mk (option α) (λo, option.rec y A o) ↔
mk x = mk y ∨ x ∈ pSet.mk α A, from
⟨λm, match m with
| ⟨some a, ha⟩ := or.inr ⟨a, ha⟩
| ⟨none, h⟩ := or.inl (quotient.sound h)
end, λm, match m with
| or.inr ⟨a, ha⟩ := ⟨some a, ha⟩
| or.inl h := ⟨none, quotient.exact h⟩
end⟩)
@[simp] theorem mem_singleton {x y : Set.{u}} : x ∈ @singleton Set.{u} Set.{u} _ _ y ↔ x = y :=
iff.trans mem_insert ⟨λo, or.rec (λh, h) (λn, absurd n (mem_empty _)) o, or.inl⟩
@[simp] theorem mem_singleton' {x y : Set.{u}} : x ∈ @insert Set.{u} Set.{u} _ y ∅ ↔ x = y := mem_singleton
@[simp] theorem mem_pair {x y z : Set.{u}} : x ∈ ({y, z} : Set) ↔ x = y ∨ x = z :=
iff.trans mem_insert $ iff.trans or.comm $ let m := @mem_singleton x y in ⟨or.imp_left m.1, or.imp_left m.2⟩
/-- `omega` is the first infinite von Neumann ordinal -/
def omega : Set := mk omega
@[simp] theorem omega_zero : ∅ ∈ omega :=
show pSet.mem ∅ pSet.omega, from ⟨⟨0⟩, equiv.refl _⟩
@[simp] theorem omega_succ {n} : n ∈ omega.{u} → insert n n ∈ omega.{u} :=
quotient.induction_on n (λx ⟨⟨n⟩, h⟩, ⟨⟨n+1⟩,
have Set.insert ⟦x⟧ ⟦x⟧ = Set.insert ⟦of_nat n⟧ ⟦of_nat n⟧, by rw (@quotient.sound pSet _ _ _ h),
quotient.exact this⟩)
/-- `{x ∈ a | p x}` is the set of elements in `a` satisfying `p` -/
protected def sep (p : Set → Prop) : Set → Set :=
resp.eval 1 ⟨pSet.sep (λy, p ⟦y⟧), λ⟨α, A⟩ ⟨β, B⟩ ⟨αβ, βα⟩,
⟨λ⟨a, pa⟩, let ⟨b, hb⟩ := αβ a in ⟨⟨b, by rwa ←(@quotient.sound pSet _ _ _ hb)⟩, hb⟩,
λ⟨b, pb⟩, let ⟨a, ha⟩ := βα b in ⟨⟨a, by rwa (@quotient.sound pSet _ _ _ ha)⟩, ha⟩⟩⟩
instance : has_sep Set Set := ⟨Set.sep⟩
@[simp] theorem mem_sep {p : Set.{u} → Prop} {x y : Set.{u}} : y ∈ {y ∈ x | p y} ↔ y ∈ x ∧ p y :=
quotient.induction_on₂ x y (λ⟨α, A⟩ y,
⟨λ⟨⟨a, pa⟩, h⟩, ⟨⟨a, h⟩, by rw (@quotient.sound pSet _ _ _ h); exact pa⟩,
λ⟨⟨a, h⟩, pa⟩, ⟨⟨a, by rw ←(@quotient.sound pSet _ _ _ h); exact pa⟩, h⟩⟩)
/-- The powerset operation, the collection of subsets of a set -/
def powerset : Set → Set :=
resp.eval 1 ⟨powerset, λ⟨α, A⟩ ⟨β, B⟩ ⟨αβ, βα⟩,
⟨λp, ⟨{b | ∃a, p a ∧ equiv (A a) (B b)},
λ⟨a, pa⟩, let ⟨b, ab⟩ := αβ a in ⟨⟨b, a, pa, ab⟩, ab⟩,
λ⟨b, a, pa, ab⟩, ⟨⟨a, pa⟩, ab⟩⟩,
λq, ⟨{a | ∃b, q b ∧ equiv (A a) (B b)},
λ⟨a, b, qb, ab⟩, ⟨⟨b, qb⟩, ab⟩,
λ⟨b, qb⟩, let ⟨a, ab⟩ := βα b in ⟨⟨a, b, qb, ab⟩, ab⟩⟩⟩⟩
@[simp] theorem mem_powerset {x y : Set} : y ∈ powerset x ↔ y ⊆ x :=
quotient.induction_on₂ x y (λ⟨α, A⟩ ⟨β, B⟩,
show (⟨β, B⟩ : pSet) ∈ (pSet.powerset ⟨α, A⟩) ↔ _,
by simp [mem_powerset, subset_iff])
theorem Union_lem {α β : Type u} (A : α → pSet) (B : β → pSet)
(αβ : ∀a, ∃b, equiv (A a) (B b)) : ∀a, ∃b, (equiv ((Union ⟨α, A⟩).func a) ((Union ⟨β, B⟩).func b))
| ⟨a, c⟩ := let ⟨b, hb⟩ := αβ a in
begin
induction ea : A a with γ Γ,
induction eb : B b with δ Δ,
rw [ea, eb] at hb,
cases hb with γδ δγ,
exact
let c : type (A a) := c, ⟨d, hd⟩ := γδ (by rwa ea at c) in
have equiv ((A a).func c) ((B b).func (eq.rec d (eq.symm eb))), from
match A a, B b, ea, eb, c, d, hd with ._, ._, rfl, rfl, x, y, hd := hd end,
⟨⟨b, eq.rec d (eq.symm eb)⟩, this⟩
end
/-- The union operator, the collection of elements of elements of a set -/
def Union : Set → Set :=
resp.eval 1 ⟨pSet.Union, λ⟨α, A⟩ ⟨β, B⟩ ⟨αβ, βα⟩,
⟨Union_lem A B αβ, λa, exists.elim (Union_lem B A (λb,
exists.elim (βα b) (λc hc, ⟨c, equiv.symm hc⟩)) a) (λb hb, ⟨b, equiv.symm hb⟩)⟩⟩
notation `⋃` := Union
@[simp] theorem mem_Union {x y : Set.{u}} : y ∈ Union x ↔ ∃ z ∈ x, y ∈ z :=
quotient.induction_on₂ x y (λx y, iff.trans mem_Union
⟨λ⟨z, h⟩, ⟨⟦z⟧, h⟩, λ⟨z, h⟩, quotient.induction_on z (λz h, ⟨z, h⟩) h⟩)
@[simp] theorem Union_singleton {x : Set.{u}} : Union {x} = x :=
ext $ λy, by simp; exact ⟨λ⟨z, zx, yz⟩, by subst z; exact yz, λyx, ⟨x, by simp, yx⟩⟩
theorem singleton_inj {x y : Set.{u}} (H : ({x} : Set) = {y}) : x = y :=
let this := congr_arg Union H in by rwa [Union_singleton, Union_singleton] at this
/-- The binary union operation -/
protected def union (x y : Set.{u}) : Set.{u} := ⋃ {x, y}
/-- The binary intersection operation -/
protected def inter (x y : Set.{u}) : Set.{u} := {z ∈ x | z ∈ y}
/-- The set difference operation -/
protected def diff (x y : Set.{u}) : Set.{u} := {z ∈ x | z ∉ y}
instance : has_union Set := ⟨Set.union⟩
instance : has_inter Set := ⟨Set.inter⟩
instance : has_sdiff Set := ⟨Set.diff⟩
@[simp] theorem mem_union {x y z : Set.{u}} : z ∈ x ∪ y ↔ z ∈ x ∨ z ∈ y :=
iff.trans mem_Union
⟨λ⟨w, wxy, zw⟩, match mem_pair.1 wxy with
| or.inl wx := or.inl (by rwa ←wx)
| or.inr wy := or.inr (by rwa ←wy)
end, λzxy, match zxy with
| or.inl zx := ⟨x, mem_pair.2 (or.inl rfl), zx⟩
| or.inr zy := ⟨y, mem_pair.2 (or.inr rfl), zy⟩
end⟩
@[simp] theorem mem_inter {x y z : Set.{u}} : z ∈ x ∩ y ↔ z ∈ x ∧ z ∈ y :=
@@mem_sep (λz:Set.{u}, z ∈ y)
@[simp] theorem mem_diff {x y z : Set.{u}} : z ∈ x \ y ↔ z ∈ x ∧ z ∉ y :=
@@mem_sep (λz:Set.{u}, z ∉ y)
theorem induction_on {p : Set → Prop} (x) (h : ∀x, (∀y ∈ x, p y) → p x) : p x :=
quotient.induction_on x $ λu, pSet.rec_on u $ λα A IH, h _ $ λy,
show @has_mem.mem _ _ Set.has_mem y ⟦⟨α, A⟩⟧ → p y, from
quotient.induction_on y (λv ⟨a, ha⟩, by rw (@quotient.sound pSet _ _ _ ha); exact IH a)
theorem regularity (x : Set.{u}) (h : x ≠ ∅) : ∃ y ∈ x, x ∩ y = ∅ :=
classical.by_contradiction $ λne, h $ (eq_empty x).2 $ λy,
induction_on y $ λz (IH : ∀w:Set.{u}, w ∈ z → w ∉ x), show z ∉ x, from λzx,
ne ⟨z, zx, (eq_empty _).2 (λw wxz, let ⟨wx, wz⟩ := mem_inter.1 wxz in IH w wz wx)⟩
/-- The image of a (definable) set function -/
def image (f : Set → Set) [H : definable 1 f] : Set → Set :=
let r := @definable.resp 1 f _ in
resp.eval 1 ⟨image r.1, λx y e, mem.ext $ λz,
iff.trans (mem_image r.2) $ iff.trans (by exact
⟨λ⟨w, h1, h2⟩, ⟨w, (mem.congr_right e).1 h1, h2⟩,
λ⟨w, h1, h2⟩, ⟨w, (mem.congr_right e).2 h1, h2⟩⟩) $
iff.symm (mem_image r.2)⟩
theorem image.mk : Π (f : Set.{u} → Set.{u}) [H : definable 1 f] (x) {y} (h : y ∈ x), f y ∈ @image f H x
| ._ ⟨F⟩ x y := quotient.induction_on₂ x y $ λ⟨α, A⟩ y ⟨a, ya⟩, ⟨a, F.2 _ _ ya⟩
@[simp] theorem mem_image : Π {f : Set.{u} → Set.{u}} [H : definable 1 f] {x y : Set.{u}}, y ∈ @image f H x ↔ ∃z ∈ x, f z = y
| ._ ⟨F⟩ x y := quotient.induction_on₂ x y $ λ⟨α, A⟩ y,
⟨λ⟨a, ya⟩, ⟨⟦A a⟧, mem.mk A a, eq.symm $ quotient.sound ya⟩,
λ⟨z, hz, e⟩, e ▸ image.mk _ _ hz⟩
/-- Kuratowski ordered pair -/
def pair (x y : Set.{u}) : Set.{u} := {{x}, {x, y}}
/-- A subset of pairs `{(a, b) ∈ x × y | p a b}` -/
def pair_sep (p : Set.{u} → Set.{u} → Prop) (x y : Set.{u}) : Set.{u} :=
{z ∈ powerset (powerset (x ∪ y)) | ∃a ∈ x, ∃b ∈ y, z = pair a b ∧ p a b}
@[simp] theorem mem_pair_sep {p} {x y z : Set.{u}} : z ∈ pair_sep p x y ↔ ∃a ∈ x, ∃b ∈ y, z = pair a b ∧ p a b := by
refine iff.trans mem_sep ⟨and.right, λe, ⟨_, e⟩⟩; exact
let ⟨a, ax, b, bY, ze, pab⟩ := e in by rw ze; exact
mem_powerset.2 (λu uz, mem_powerset.2 $ (mem_pair.1 uz).elim
(λua, by rw ua; exact λv vu, by rw mem_singleton.1 vu; exact mem_union.2 (or.inl ax))
(λuab, by rw uab; exact λv vu, (mem_pair.1 vu).elim
(λva, by rw va; exact mem_union.2 (or.inl ax))
(λvb, by rw vb; exact mem_union.2 (or.inr bY))))
theorem pair_inj {x y x' y' : Set.{u}} (H : pair x y = pair x' y') : x = x' ∧ y = y' := begin
have ae := ext_iff.2 H,
simp [pair] at ae,
have : x = x',
{ cases (ae {x}).1 (by simp) with h h,
{ exact singleton_inj h },
{ have m : x' ∈ ({x} : Set),
{ rw h, simp },
simp at m, simp [*] } },
subst x',
have he : y = x → y = y',
{ intro yx, subst y,
cases (ae {x, y'}).2 (by simp) with xy'x xy'xx,
{ have y'x : y' ∈ ({x} : Set) := by rw ← xy'x; simp,
simp at y'x, simp [*] },
{ have yxx := (ext_iff.2 xy'xx y').1 (by simp),
simp at yxx, subst y' } },
have xyxy' := (ae {x, y}).1 (by simp),
cases xyxy' with xyx xyy',
{ have yx := (ext_iff.2 xyx y).1 (by simp),
simp at yx, simp [he yx] },
{ have yxy' := (ext_iff.2 xyy' y).1 (by simp),
simp at yxy',
cases yxy' with yx yy',
{ simp [he yx] },
{ simp [yy'] } }
end
/-- The cartesian product, `{(a, b) | a ∈ x, b ∈ y}` -/
def prod : Set.{u} → Set.{u} → Set.{u} := pair_sep (λa b, true)
@[simp] theorem mem_prod {x y z : Set.{u}} : z ∈ prod x y ↔ ∃a ∈ x, ∃b ∈ y, z = pair a b :=
by simp [prod]
@[simp] theorem pair_mem_prod {x y a b : Set.{u}} : pair a b ∈ prod x y ↔ a ∈ x ∧ b ∈ y :=
⟨λh, let ⟨a', a'x, b', b'y, e⟩ := mem_prod.1 h in
match a', b', pair_inj e, a'x, b'y with ._, ._, ⟨rfl, rfl⟩, ax, bY := ⟨ax, bY⟩ end,
λ⟨ax, bY⟩, by simp; exact ⟨a, ax, b, bY, rfl⟩⟩
/-- `is_func x y f` is the assertion `f : x → y` where `f` is a ZFC function
(a set of ordered pairs) -/
def is_func (x y f : Set.{u}) : Prop :=
f ⊆ prod x y ∧ ∀z:Set.{u}, z ∈ x → ∃! w, pair z w ∈ f
/-- `funs x y` is `y ^ x`, the set of all set functions `x → y` -/
def funs (x y : Set.{u}) : Set.{u} :=
{f ∈ powerset (prod x y) | is_func x y f}
@[simp] theorem mem_funs {x y f : Set.{u}} : f ∈ funs x y ↔ is_func x y f :=
by simp [funs]; exact and_iff_right_of_imp and.left
-- TODO(Mario): Prove this computably
noncomputable instance map_definable_aux (f : Set → Set) [H : definable 1 f] : definable 1 (λy, pair y (f y)) :=
@classical.all_definable 1 _
/-- Graph of a function: `map f x` is the ZFC function which maps `a ∈ x` to `f a` -/
noncomputable def map (f : Set → Set) [H : definable 1 f] : Set → Set :=
image (λy, pair y (f y))
@[simp] theorem mem_map {f : Set → Set} [H : definable 1 f] {x y : Set} : y ∈ map f x ↔ ∃z ∈ x, pair z (f z) = y :=
mem_image
theorem map_unique {f : Set.{u} → Set.{u}} [H : definable 1 f] {x z : Set.{u}} (zx : z ∈ x) : ∃! w, pair z w ∈ map f x :=
⟨f z, image.mk _ _ zx, λy yx, let ⟨w, wx, we⟩ := mem_image.1 yx, ⟨wz, fy⟩ := pair_inj we in by rw[←fy, wz]⟩
@[simp] theorem map_is_func {f : Set → Set} [H : definable 1 f] {x y : Set} : is_func x y (map f x) ↔ ∀z ∈ x, f z ∈ y :=
⟨λ⟨ss, h⟩ z zx, let ⟨t, t1, t2⟩ := h z zx in by rw (t2 (f z) (image.mk _ _ zx)); exact (pair_mem_prod.1 (ss t1)).right,
λh, ⟨λy yx, let ⟨z, zx, ze⟩ := mem_image.1 yx in by rw ←ze; exact pair_mem_prod.2 ⟨zx, h z zx⟩,
λz, map_unique⟩⟩
end Set
def Class := set Set
namespace Class
instance : has_subset Class := ⟨set.subset⟩
instance : has_sep Set Class := ⟨set.sep⟩
instance : has_emptyc Class := ⟨λ a, false⟩
instance : has_insert Set Class := ⟨set.insert⟩
instance : has_union Class := ⟨set.union⟩
instance : has_inter Class := ⟨set.inter⟩
instance : has_neg Class := ⟨set.compl⟩
instance : has_sdiff Class := ⟨set.diff⟩
/-- Coerce a set into a class -/
def of_Set (x : Set.{u}) : Class.{u} := {y | y ∈ x}
instance : has_coe Set Class := ⟨of_Set⟩
/-- The universal class -/
def univ : Class := set.univ
/-- Assert that `A` is a set satisfying `p` -/
def to_Set (p : Set.{u} → Prop) (A : Class.{u}) : Prop := ∃x, ↑x = A ∧ p x
/-- `A ∈ B` if `A` is a set which is a member of `B` -/
protected def mem (A B : Class.{u}) : Prop := to_Set.{u} B A
instance : has_mem Class Class := ⟨Class.mem⟩
theorem mem_univ {A : Class.{u}} : A ∈ univ.{u} ↔ ∃ x : Set.{u}, ↑x = A :=
exists_congr $ λx, and_true _
/-- Convert a conglomerate (a collection of classes) into a class -/
def Cong_to_Class (x : set Class.{u}) : Class.{u} := {y | ↑y ∈ x}
/-- Convert a class into a conglomerate (a collection of classes) -/
def Class_to_Cong (x : Class.{u}) : set Class.{u} := {y | y ∈ x}
/-- The power class of a class is the class of all subclasses that are sets -/
def powerset (x : Class) : Class := Cong_to_Class (set.powerset x)
/-- The union of a class is the class of all members of sets in the class -/
def Union (x : Class) : Class := set.sUnion (Class_to_Cong x)
notation `⋃` := Union
theorem of_Set.inj {x y : Set.{u}} (h : (x : Class.{u}) = y) : x = y :=
Set.ext $ λz, by change (x : Class.{u}) z ↔ (y : Class.{u}) z; simp [*]
@[simp] theorem to_Set_of_Set (p : Set.{u} → Prop) (x : Set.{u}) : to_Set p x ↔ p x :=
⟨λ⟨y, yx, py⟩, by rwa of_Set.inj yx at py, λpx, ⟨x, rfl, px⟩⟩
@[simp] theorem mem_hom_left (x : Set.{u}) (A : Class.{u}) : (x : Class.{u}) ∈ A ↔ A x :=
to_Set_of_Set _ _
@[simp] theorem mem_hom_right (x y : Set.{u}) : (y : Class.{u}) x ↔ x ∈ y := iff.refl _
@[simp] theorem subset_hom (x y : Set.{u}) : (x : Class.{u}) ⊆ y ↔ x ⊆ y := iff.refl _
@[simp] theorem sep_hom (p : Set.{u} → Prop) (x : Set.{u}) : (↑{y ∈ x | p y} : Class.{u}) = {y ∈ x | p y} :=
set.ext $ λy, Set.mem_sep
@[simp] theorem empty_hom : ↑(∅ : Set.{u}) = (∅ : Class.{u}) :=
set.ext $ λy, show _ ↔ false, by simp; exact Set.mem_empty y
@[simp] theorem insert_hom (x y : Set.{u}) : (@insert Set.{u} Class.{u} _ x y) = ↑(insert x y) :=
set.ext $ λz, iff.symm Set.mem_insert
@[simp] theorem union_hom (x y : Set.{u}) : (x : Class.{u}) ∪ y = (x ∪ y : Set.{u}) :=
set.ext $ λz, iff.symm Set.mem_union
@[simp] theorem inter_hom (x y : Set.{u}) : (x : Class.{u}) ∩ y = (x ∩ y : Set.{u}) :=
set.ext $ λz, iff.symm Set.mem_inter
@[simp] theorem diff_hom (x y : Set.{u}) : (x : Class.{u}) \ y = (x \ y : Set.{u}) :=
set.ext $ λz, iff.symm Set.mem_diff
@[simp] theorem powerset_hom (x : Set.{u}) : powerset.{u} x = Set.powerset x :=
set.ext $ λz, iff.symm Set.mem_powerset
@[simp] theorem Union_hom (x : Set.{u}) : Union.{u} x = Set.Union x :=
set.ext $ λz, by refine iff.trans _ (iff.symm Set.mem_Union); exact
⟨λ⟨._, ⟨a, rfl, ax⟩, za⟩, ⟨a, ax, za⟩, λ⟨a, ax, za⟩, ⟨_, ⟨a, rfl, ax⟩, za⟩⟩
/-- The definite description operator, which is {x} if `{a | p a} = {x}`
and ∅ otherwise -/
def iota (p : Set → Prop) : Class := Union {x | ∀y, p y ↔ y = x}
theorem iota_val (p : Set → Prop) (x : Set) (H : ∀y, p y ↔ y = x) : iota p = ↑x :=
set.ext $ λy, ⟨λ⟨._, ⟨x', rfl, h⟩, yx'⟩, by rwa ←((H x').1 $ (h x').2 rfl), λyx, ⟨_, ⟨x, rfl, H⟩, yx⟩⟩
/-- Unlike the other set constructors, the `iota` definite descriptor
is a set for any set input, but not constructively so, so there is no
associated `(Set → Prop) → Set` function. -/
theorem iota_ex (p) : iota.{u} p ∈ univ.{u} :=
mem_univ.2 $ or.elim (classical.em $ ∃x, ∀y, p y ↔ y = x)
(λ⟨x, h⟩, ⟨x, eq.symm $ iota_val p x h⟩)
(λhn, ⟨∅, by simp; exact set.ext (λz, ⟨false.rec _, λ⟨._, ⟨x, rfl, H⟩, zA⟩, hn ⟨x, H⟩⟩)⟩)
/-- Function value -/
def fval (F A : Class.{u}) : Class.{u} := iota (λy, to_Set (λx, F (Set.pair x y)) A)
infixl `′`:100 := fval
theorem fval_ex (F A : Class.{u}) : F ′ A ∈ univ.{u} := iota_ex _
end Class
namespace Set
@[simp] theorem map_fval {f : Set.{u} → Set.{u}} [H : pSet.definable 1 f] {x y : Set.{u}} (h : y ∈ x) :
(Set.map f x ′ y : Class.{u}) = f y :=
Class.iota_val _ _ (λz, by simp; exact
⟨λ⟨w, wz, pr⟩, let ⟨wy, fw⟩ := Set.pair_inj pr in by rw[←fw, wy],
λe, by cases e; exact ⟨_, h, rfl⟩⟩)
variables (x : Set.{u}) (h : ∅ ∉ x)
/-- A choice function on the set of nonempty sets `x` -/
noncomputable def choice : Set := @map (λy, classical.epsilon (λz, z ∈ y)) (classical.all_definable _) x
include h
theorem choice_mem_aux (y : Set.{u}) (yx : y ∈ x) : classical.epsilon (λz:Set.{u}, z ∈ y) ∈ y :=
@classical.epsilon_spec _ (λz:Set.{u}, z ∈ y) $ classical.by_contradiction $ λn, h $
by rwa ←((eq_empty y).2 $ λz zx, n ⟨z, zx⟩)
theorem choice_is_func : is_func x (Union x) (choice x) :=
(@map_is_func _ (classical.all_definable _) _ _).2 $ λy yx, by simp; exact ⟨y, yx, choice_mem_aux x h y yx⟩
theorem choice_mem (y : Set.{u}) (yx : y ∈ x) : (choice x ′ y : Class.{u}) ∈ (y : Class.{u}) :=
by delta choice; rw map_fval yx; simp [choice_mem_aux x h y yx]
end Set
|
6cf8c1783e4e1a2b5ca78c4a22f978a864775d20 | e151e9053bfd6d71740066474fc500a087837323 | /src/hott/function.lean | 0bb359e982c0ae6c26686e6deefeba0b456071dd | [
"Apache-2.0"
] | permissive | daniel-carranza/hott3 | 15bac2d90589dbb952ef15e74b2837722491963d | 913811e8a1371d3a5751d7d32ff9dec8aa6815d9 | refs/heads/master | 1,610,091,349,670 | 1,596,222,336,000 | 1,596,222,336,000 | 241,957,822 | 0 | 0 | Apache-2.0 | 1,582,222,839,000 | 1,582,222,838,000 | null | UTF-8 | Lean | false | false | 14,843 | lean | /-
Copyright (c) 2015 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Floris van Doorn
Ported from Coq HoTT
Theorems about embeddings and surjections
-/
import .hit.trunc .types.equiv .cubical.square .types.nat.hott
universes u v w
hott_theory
namespace hott
open hott.equiv hott.sigma trunc is_trunc hott.pi hott.is_equiv fiber hott.prod pointed hott.nat
variables {A : Type _} {B : Type _} {C : Type _} (f f' : A → B) {b : B}
/- the image of a map is the (-1)-truncated fiber -/
@[hott] def image' (f : A → B) (b : B) : Type _ := ∥ fiber f b ∥
@[hott, instance] def is_prop_image' (f : A → B) (b : B) : is_prop (image' f b) :=
is_trunc_trunc _ _
@[hott] def image (f : A → B) (b : B) : Prop := Prop.mk (image' f b) (by apply_instance)
@[hott] def total_image {A B : Type _} (f : A → B) : Type _ := Σx, image f x
@[hott, class] def is_embedding (f : A → B) := Π(a a' : A), is_equiv (ap f : a = a' → f a = f a')
@[hott, class] def is_surjective (f : A → B) := Π(b : B), image f b
@[hott, class] def is_split_surjective (f : A → B) := Π(b : B), fiber f b
@[hott, class] structure is_retraction (f : A → B) :=
(sect : B → A)
(right_inverse : Π(b : B), f (sect b) = b)
@[hott, class] structure is_section (f : A → B) :=
(retr : B → A)
(left_inverse : Π(a : A), retr (f a) = a)
@[hott, class] structure is_constant (f : A → B) :=
(pt : B)
(eq : Π(a : A), f a = pt)
@[hott, class] structure is_conditionally_constant (f : A → B) :=
(g : ∥A∥ → B)
(eq : Π(a : A), f a = g (tr a))
section image
@[hott] protected def image.mk {f : A → B} {b : B} (a : A) (p : f a = b)
: image f b :=
tr (fiber.mk a p)
@[hott, induction] protected def image.rec {f : A → B} {b : B} {P : image' f b → Type _}
[HP : Πv, is_prop (P v)] (H : Π(a : A) (p : f a = b), P (image.mk a p)) (v : image' f b) : P v :=
begin dsimp [image'] at *, hinduction v with v, hinduction v with a p, exact H a p end
@[hott] def image.elim {A B : Type _} {f : A → B} {C : Type _} [is_prop C] {b : B}
(H : image f b) (H' : ∀ (a : A), f a = b → C) : C :=
begin
refine (trunc.elim _ H),
intro H'', cases H'' with a Ha, exact H' a Ha
end
@[hott] def image.equiv_exists {A B : Type _} {f : A → B} {b : B} : image f b ≃ ∃a, f a = b :=
trunc_equiv_trunc _ (fiber.sigma_char _ _)
@[hott] def image_pathover {f : A → B} {x y : B} (p : x = y) (u : image f x) (v : image f y) :
u =[p; λb, image f b] v :=
is_prop.elimo _ _ _
@[hott] def total_image.rec
{A B : Type _} {f : A → B} {C : total_image f → Type _} [H : Πx, is_prop (C x)]
(g : Πa, C ⟨f a, image.mk a idp⟩)
(x : total_image f) : C x :=
begin
induction x with b v,
refine @image.rec _ _ _ _ _ (λv, H ⟨b, v⟩) _ v,
intros a p,
induction p, exact g a
end
/- total_image.elim_set is in hit.prop_trunc to avoid dependency cycle -/
end image
namespace function
abbreviation sect := @is_retraction.sect
abbreviation right_inverse := @is_retraction.right_inverse
abbreviation retr := @is_section.retr
abbreviation left_inverse := @is_section.left_inverse
@[hott, instance] def is_equiv_ap_of_embedding [H : is_embedding f] (a a' : A)
: is_equiv (ap f : a = a' → f a = f a') :=
H a a'
@[hott] def ap_inv_idp {a : A} {H : is_equiv (ap f : a = a → f a = f a)}
: (ap f)⁻¹ᶠ idp = idp :> a = a :=
left_inv (ap f) idp
variable {f}
@[hott, reducible] def is_injective_of_is_embedding [H : is_embedding f] {a a' : A}
: f a = f a' → a = a' :=
(ap f)⁻¹ᶠ
@[hott] def is_embedding_of_is_injective [HA : is_set A] [HB : is_set B]
(H : Π(a a' : A), f a = f a' → a = a') : is_embedding f :=
begin
intros a a',
fapply adjointify,
{exact (H a a')},
{intro p, apply is_set.elim},
{intro p, apply is_set.elim}
end
variable (f)
@[hott, instance] def is_prop_is_embedding : is_prop (is_embedding f) :=
by dsimp [is_embedding]; apply_instance
@[hott] def is_embedding_equiv_is_injective [HA : is_set A] [HB : is_set B]
: is_embedding f ≃ (Π(a a' : A), f a = f a' → a = a') :=
begin
fapply equiv.MK,
{ apply @is_injective_of_is_embedding},
{ apply is_embedding_of_is_injective},
{ intro H, apply is_prop.elim},
{ intro H, apply is_prop.elim, }
end
@[hott] def is_prop_fiber_of_is_embedding [H : is_embedding f] (b : B) :
is_prop (fiber f b) :=
begin
apply is_prop.mk, intros v w,
induction v with a p, induction w with a' q, induction q,
fapply fiber_eq,
{ apply is_injective_of_is_embedding p},
{ dsimp [is_injective_of_is_embedding], symmetry, apply right_inv}
end
@[hott] def is_prop_fun_of_is_embedding [H : is_embedding f] : is_trunc_fun -1 f :=
is_prop_fiber_of_is_embedding f
@[hott] def is_embedding_of_is_prop_fun [H : is_trunc_fun -1 f] : is_embedding f :=
begin
intros a a', fapply adjointify,
{ intro p, exact ap point (@is_prop.elim (fiber f (f a')) _ (fiber.mk a p) (fiber.mk a' idp))},
{ intro p, rwr [←ap_compose],
exact ap_con_eq (@point_eq _ _ f (f a')) (is_prop.elim ⟨a, p⟩ ⟨a', idp⟩) },
{ intro p, induction p, apply ap02 point (is_prop_elim_self _) }
end
variable {f}
@[hott] def is_surjective_rec_on {P : Type _} (H : is_surjective f) (b : B) [Pt : is_prop P]
(IH : fiber f b → P) : P :=
trunc.rec_on (H b) IH
variable (f)
@[hott, instance] def is_surjective_of_is_split_surjective [H : is_split_surjective f]
: is_surjective f :=
λb, tr (H b)
@[hott, instance] def is_prop_is_surjective : is_prop (is_surjective f) :=
begin dsimp [is_surjective], apply_instance end
@[hott] def is_surjective_cancel_right {A B C : Type _} (g : B → C) (f : A → B)
[H : is_surjective (g ∘ f)] : is_surjective g :=
begin
intro c,
have := H c,
hinduction H c with q p, hinduction p with a p,
exact tr (fiber.mk (f a) p)
end
@[hott, instance] def is_weakly_constant_ap [H : is_weakly_constant f] (a a' : A) :
is_weakly_constant (ap f : a = a' → f a = f a') :=
λp q : a = a',
have Π{b c : A} {r : b = c}, (H a b)⁻¹ ⬝ H a c = ap f r, from
(λb c r, by hinduction r; apply con.left_inv),
this⁻¹ ⬝ this
@[hott, instance] def is_constant_ap [H : is_constant f] (a a' : A)
: is_constant (ap f : a = a' → f a = f a') :=
begin
unfreezeI; induction H with b q,
fapply is_constant.mk,
{ exact q a ⬝ (q a')⁻¹},
{ intro p, induction p, exact (con.right_inv _)⁻¹}
end
@[hott, instance] def is_contr_is_retraction [H : is_equiv f] : is_contr (is_retraction f) :=
begin
have H2 : (Σ(g : B → A), Πb, f (g b) = b) ≃ is_retraction f,
begin
fapply equiv.MK,
{intro x, induction x with g p, constructor, exact p},
{intro h, induction h, apply sigma.mk, assumption},
{intro h, induction h, reflexivity},
{intro x, induction x, reflexivity},
end,
apply is_trunc_equiv_closed, exact H2,
apply is_equiv.is_contr_right_inverse
end
@[hott, instance] def is_contr_is_section [H : is_equiv f] : is_contr (is_section f) :=
begin
have H2 : (Σ(g : B → A), Πa, g (f a) = a) ≃ is_section f,
begin
fapply equiv.MK,
{intro x, induction x with g p, constructor, exact p},
{intro h, induction h with h hp, apply sigma.mk, exact hp },
{intro h, induction h, reflexivity},
{intro x, induction x, reflexivity},
end,
apply is_trunc_equiv_closed, exact H2,
apply is_trunc_equiv_closed,
{apply sigma_equiv_sigma_right, intro g, apply eq_equiv_homotopy (g ∘ f) id},
apply is_trunc_equiv_closed,
{apply fiber.sigma_char},
apply is_contr_fiber_of_is_equiv _,
exact to_is_equiv (arrow_equiv_arrow_left_rev A (equiv.mk f H)),
end
@[hott, instance] def is_embedding_of_is_equiv [H : is_equiv f] : is_embedding f :=
λa a', by apply_instance
@[hott] def is_equiv_of_is_surjective_of_is_embedding
[H : is_embedding f] [H' : is_surjective f] : is_equiv f :=
@is_equiv_of_is_contr_fun _ _ _
(λb, is_surjective_rec_on H' b
(λa, is_contr.mk a
(λa',
fiber_eq ((ap f)⁻¹ᶠ ((point_eq a) ⬝ (point_eq a')⁻¹))
(by rwr (right_inv (ap f)); rwr inv_con_cancel_right))))
@[hott] def is_split_surjective_of_is_retraction [H : is_retraction f] : is_split_surjective f :=
λb, fiber.mk (sect f b) (right_inverse f b)
@[hott, instance] def is_constant_compose_point (b : B)
: is_constant (f ∘ point : fiber f b → B) :=
is_constant.mk b (λv, by induction v with a p;exact p)
@[hott] def is_embedding_of_is_prop_fiber [H : Π(b : B), is_prop (fiber f b)] : is_embedding f :=
is_embedding_of_is_prop_fun _
@[hott, instance] def is_retraction_of_is_equiv [H : is_equiv f] : is_retraction f :=
is_retraction.mk f⁻¹ᶠ (right_inv f)
@[hott, instance] def is_section_of_is_equiv [H : is_equiv f] : is_section f :=
is_section.mk f⁻¹ᶠ (left_inv f)
@[hott] def is_equiv_of_is_section_of_is_retraction [H1 : is_retraction f] [H2 : is_section f]
: is_equiv f :=
let g := sect f in let h := retr f in
adjointify f
g
(right_inverse f)
(λa, calc
g (f a) = h (f (g (f a))) : (left_inverse _ _)⁻¹
... = h (f a) : by rwr right_inverse f _
... = a : left_inverse _ _)
section
local attribute [instance] [priority 10000] is_equiv_of_is_section_of_is_retraction
--local attribute [instance] [priority 1] trunctype.struct -- remove after #842 is closed
variable (f)
@[hott] def is_prop_is_retraction_prod_is_section : is_prop (is_retraction f × is_section f) :=
begin
apply is_prop_of_imp_is_contr, intro H, induction H with H1 H2,
resetI, apply_instance,
end
end
@[hott, instance] def is_retraction_trunc_functor (r : A → B) [H : is_retraction r]
(n : trunc_index) : is_retraction (trunc_functor n r) :=
is_retraction.mk
(trunc_functor n (sect r))
(λb,
((trunc_functor_compose n r (sect r)) b)⁻¹
⬝ trunc_homotopy n (right_inverse r) b
⬝ trunc_functor_id n B b)
-- @[hott] lemma 3.11.7
@[hott] def is_contr_retract (r : A → B) [H : is_retraction r] : is_contr A → is_contr B :=
begin
intro CA,
applyI is_contr.mk (r (center A)),
intro b,
exact ap r (center_eq (is_retraction.sect r b)) ⬝ (is_retraction.right_inverse r b)
end
local attribute [instance] is_prop_is_retraction_prod_is_section
@[hott] def is_retraction_prod_is_section_equiv_is_equiv
: (is_retraction f × is_section f) ≃ is_equiv f :=
begin
apply equiv_of_is_prop,
intro H, induction H, apply is_equiv_of_is_section_of_is_retraction _; assumption,
intro H, resetI, split, apply_instance, apply_instance
end
@[hott] def is_retraction_equiv_is_split_surjective :
is_retraction f ≃ is_split_surjective f :=
begin
fapply equiv.MK,
{ intro H, induction H with g p, intro b, constructor, exact p b},
{ intro H, constructor, intro b, exact point_eq (H b)},
{ intro H, apply eq_of_homotopy, intro b, dsimp,
hinduction H b with q a p, refl },
{ intro H, induction H with g p, reflexivity},
end
@[hott] def is_embedding_compose (g : B → C) (f : A → B)
(H₁ : is_embedding g) (H₂ : is_embedding f) : is_embedding (g ∘ f) :=
begin
intros a a', apply is_equiv.homotopy_closed (ap g ∘ ap f),
symmetry, exact ap_compose g f,
apply is_equiv_compose,
end
@[hott] def is_surjective_compose (g : B → C) (f : A → B)
(H₁ : is_surjective g) (H₂ : is_surjective f) : is_surjective (g ∘ f) :=
begin
intro c, hinduction H₁ c with x p, hinduction p with b p,
hinduction H₂ b with y q, hinduction q with a q,
exact image.mk a (ap g q ⬝ p)
end
@[hott] def is_split_surjective_compose (g : B → C) (f : A → B)
(H₁ : is_split_surjective g) (H₂ : is_split_surjective f) : is_split_surjective (g ∘ f) :=
begin
intro c, hinduction H₁ c with x b p, hinduction H₂ b with y a q,
exact fiber.mk a (ap g q ⬝ p)
end
@[hott] def is_injective_compose (g : B → C) (f : A → B)
(H₁ : Π⦃b b'⦄, g b = g b' → b = b') (H₂ : Π⦃a a'⦄, f a = f a' → a = a')
⦃a a' : A⦄ (p : g (f a) = g (f a')) : a = a' :=
H₂ (H₁ p)
@[hott, instance] def is_embedding_pr1 {A : Type _} (B : A → Type _) [H : Π a, is_prop (B a)]
: is_embedding (@sigma.fst A B) :=
λv v', to_is_equiv (sigma_eq_equiv v v' ⬝e sigma_equiv_of_is_contr_right _)
variables {f f'}
@[hott] def is_embedding_homotopy_closed (p : f ~ f') (H : is_embedding f) : is_embedding f' :=
begin
intros a a', fapply is_equiv_of_equiv_of_homotopy,
exact equiv.mk (ap f) (by apply_instance) ⬝e
equiv_eq_closed_left _ (p a) ⬝e equiv_eq_closed_right _ (p a'),
intro q, exact (eq_bot_of_square (transpose (natural_square p q)))⁻¹
end
@[hott] def is_embedding_homotopy_closed_rev (p : f' ~ f) (H : is_embedding f) : is_embedding f' :=
is_embedding_homotopy_closed p⁻¹ʰᵗʸ H
@[hott] def is_surjective_homotopy_closed (p : f ~ f') (H : is_surjective f) : is_surjective f' :=
begin
intro b, hinduction H b with x q, hinduction q with a q,
exact image.mk a ((p a)⁻¹ ⬝ q)
end
@[hott] def is_surjective_homotopy_closed_rev (p : f' ~ f) (H : is_surjective f) :
is_surjective f' :=
is_surjective_homotopy_closed p⁻¹ʰᵗʸ H
@[hott] def is_equiv_ap1_gen_of_is_embedding {A B : Type _} (f : A → B) [is_embedding f]
{a a' : A} {b b' : B} (q : f a = b) (q' : f a' = b') : is_equiv (ap1_gen f q q') :=
begin
induction q, induction q',
exact is_equiv.homotopy_closed _ (ap1_gen_idp_left f)⁻¹ʰᵗʸ,
end
@[hott] def is_equiv_ap1_of_is_embedding {A B : Type*} (f : A →* B) [is_embedding f] :
is_equiv (Ω→ f) :=
is_equiv_ap1_gen_of_is_embedding f (respect_pt f) (respect_pt f)
@[hott] def loop_pequiv_loop_of_is_embedding {A B : Type*} (f : A →* B)
[is_embedding f] : Ω A ≃* Ω B :=
pequiv_of_pmap (Ω→ f) (is_equiv_ap1_of_is_embedding f)
@[hott] def loopn_pequiv_loopn_of_is_embedding (n : ℕ) [H : is_succ n]
{A B : Type*} (f : A →* B) [is_embedding f] : Ω[n] A ≃* Ω[n] B :=
begin
unfreezeI, induction H with n,
exact loopn_succ_in _ _ ⬝e*
loopn_pequiv_loopn n (loop_pequiv_loop_of_is_embedding f) ⬝e*
(loopn_succ_in _ _)⁻¹ᵉ*
end
/-
The definitions
is_surjective_of_is_equiv
is_equiv_equiv_is_embedding_times_is_surjective
are in types.trunc
See types.arrow_2 for retractions
-/
end function
end hott |
03a3a50295779456793a9b3a5a5be007e4384814 | f3849be5d845a1cb97680f0bbbe03b85518312f0 | /tests/lean/private_structure.lean | bfcd2087b3483ea3eefc6d18607fd2f50b452b3e | [
"Apache-2.0"
] | permissive | bjoeris/lean | 0ed95125d762b17bfcb54dad1f9721f953f92eeb | 4e496b78d5e73545fa4f9a807155113d8e6b0561 | refs/heads/master | 1,611,251,218,281 | 1,495,337,658,000 | 1,495,337,658,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 533 | lean | namespace foo
private structure point :=
(x : nat) (y : nat)
definition bla := point
definition mk : bla := point.mk 10 10
#check bla
#check point
#check point.mk
#check point.rec
#check point.rec_on
#check point.cases_on
#check point.x
#check point.y
end foo
open foo
-- point is not visible anymore
#check bla
#check point
#check point.mk
#check point.rec
#check point.rec_on
#check point.cases_on
#check point.no_confusion
#check point.x
#check point.y
set_option pp.all true
#print bla
#check (⟨1, 2⟩ : bla)
#check mk
|
414dbba9c4c125c1ab12787ced717e1b2ac217da | 7c92a46ce39266c13607ecdef7f228688f237182 | /src/Spa/localization_Huber.lean | 70e917ac8bff5a37414b3eb6675f73a4f5c0999d | [
"Apache-2.0"
] | permissive | asym57/lean-perfectoid-spaces | 3217d01f6ddc0d13e9fb68651749469750420767 | 359187b429f254a946218af4411d45f08705c83e | refs/heads/master | 1,609,457,937,251 | 1,577,542,616,000 | 1,577,542,675,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 7,239 | lean | import Huber_ring.localization
import Spa.rational_open_data
/-!
# Extending continuous valuations on Huber rings
In this file, we extend continuous valuations on Huber rings R
to rational localizations R(T/s) and their completions.
This is an important step in the definition of the structure presheaf on the adic spectrum.
-/
noncomputable theory
local attribute [instance] valued.subgroups_basis valued.uniform_space
local postfix `⁺` : 66 := λ A : Huber_pair, A.plus
variables {A : Huber_pair}
{Γ₀ : Type*} [linear_ordered_comm_group_with_zero Γ₀] {v : valuation A Γ₀}
{rd : spa.rational_open_data A} (hv : valuation.is_continuous v)
namespace Huber_pair
open valuation linear_ordered_structure
local attribute [instance] set.pointwise_mul_action
local notation `A⟮T/s⟯` := spa.rational_open_data.localization rd
local notation `s` := rd.s
local notation `T` := rd.T
/-- An auxilliary definition that constructs s as unit in the valuation field
of a valuation v, under the assumption that v s ≠ 0.-/
def unit_s (hs : v s ≠ 0) : units (valuation_field v) :=
units.mk0 (valuation_field_mk v s) $ valuation_field_mk_ne_zero v s hs
example : (λ r, localization.of (valuation_ID_mk v r)) = valuation_field_mk v := rfl
/--The set T/s (for some rational open subset D(T,s)) considered as subset of the valuation field.-/
def v_T_over_s (hs : v s ≠ 0) : set (valuation_field v) :=
((unit_s hs)⁻¹ : v.valuation_field) • ((valuation_field_mk v) '' rd.T)
lemma v_T_over_s_le_one (hs : v s ≠ 0) (hT2 : ∀ t : A, t ∈ T → v t ≤ v s) :
v_T_over_s hs ⊆ {x : valuation_field v | valuation_field.canonical_valuation v x ≤ 1} :=
begin
let v' := valuation_field.canonical_valuation v,
intros k Hk,
show v' k ≤ 1,
let u := unit_s hs,
have remember_this : valuation_field_mk v s = u.val := rfl,
unfold v_T_over_s at Hk,
rw set.mem_smul_set at Hk,
rcases Hk with ⟨l, Hl, rfl⟩,
rw v'.map_mul,
rcases Hl with ⟨t, ht, rfl⟩,
change v' (↑(unit_s hs)⁻¹) * _ ≤ _,
rw mul_comm,
apply le_of_le_mul_right
(group_with_zero.unit_ne_zero $ units.map (v' : v.valuation_field →* (value_monoid v)) u),
show v' _ * v' _ * v' u ≤ _,
rw [mul_assoc, one_mul, ← v'.map_mul, units.inv_mul, v'.map_one, mul_one],
change canonical_valuation v t ≤ v' u.val,
rw ← remember_this,
change _ ≤ canonical_valuation v s,
rw canonical_valuation_is_equiv v,
exact hT2 _ ht,
end
lemma v_le_one_is_bounded {R : Type*} [comm_ring R] (v : valuation R Γ₀) :
is_bounded {x : valuation_field v | valuation_field.canonical_valuation v x ≤ 1} :=
begin
let v' := valuation_field.canonical_valuation v,
intros U HU,
rcases subgroups_basis.mem_nhds_zero.mp HU with ⟨_, ⟨γ, rfl⟩, H⟩,
let V := {k : valuation_field v | v' k < ↑γ},
use V,
existsi _, swap,
{ rw subgroups_basis.mem_nhds_zero,
use [V, set.mem_range_self _] },
intros w Hw b Hb,
change V ⊆ U at H,
change v' w < γ at Hw,
change v' b ≤ 1 at Hb,
apply set.mem_of_mem_of_subset _ H,
change v' (w * b) < γ,
rw v'.map_mul,
exact actual_ordered_comm_monoid.mul_lt_of_lt_of_nongt_one' Hw Hb,
end
lemma v_le_one_is_power_bounded {R : Type*} [comm_ring R] (v : valuation R Γ₀) :
is_power_bounded_subset {x : valuation_field v | valuation_field.canonical_valuation v x ≤ 1} :=
begin
let v' := valuation_field.canonical_valuation v,
refine is_bounded.subset _ (v_le_one_is_bounded v),
intros x hx,
induction hx with a ha a b ha' hb' ha hb,
{ assumption },
{ show v' 1 ≤ 1, rw v'.map_one, },
{ show v' (a * b) ≤ 1, rw v'.map_mul,
exact actual_ordered_comm_monoid.mul_nongt_one' ha hb, }
end
lemma v_T_over_s_is_power_bounded (hs : v s ≠ 0) (hT2 : ∀ t : A, t ∈ T → v t ≤ v s) :
is_power_bounded_subset (v_T_over_s hs) :=
begin
apply power_bounded.subset (v_T_over_s_le_one hs hT2),
exact v_le_one_is_power_bounded v
end
/--The natural map from the localization A⟮T/s⟯ of a Huber pair A
at a rational open subset R(T/s)
to the valuation field of a valuation that does not have s in its support.-/
noncomputable def to_valuation_field (hs : v s ≠ 0) : A⟮T/s⟯ → (valuation_field v) :=
Huber_ring.away.lift T s (valuation_field_mk v) (unit_s hs) rfl
/-- The natural map from A⟮T/s⟯ to the valuation field is a ring homomorphism. -/
instance (hs : v s ≠ 0) : is_ring_hom (to_valuation_field hs) :=
by delta to_valuation_field; apply_instance
local attribute [instance] valued.subgroups_basis
theorem to_valuation_field_cts' (hs : v s ≠ 0)(hT2 : ∀ t : A, t ∈ T → v t ≤ v s) (hv : is_continuous v) :
continuous (to_valuation_field hs) :=
Huber_ring.away.lift_continuous T s (by convert subgroups_basis.nonarchimedean)
(continuous_valuation_field_mk_of_continuous v hv) _ rfl (rd.Hopen)
(v_T_over_s_is_power_bounded hs hT2)
-- now we need that the triangles commute when we fix v but change s.
theorem to_valuation_field_commutes (r1 r2 : spa.rational_open_data A) (h : r1 ≤ r2)
(hs1 : v r1.s ≠ 0) (hs2 : v r2.s ≠ 0) :
to_valuation_field hs1 = (to_valuation_field hs2) ∘ (spa.rational_open_data.localization_map h) :=
begin
refine localization.funext
(to_valuation_field hs1 : localization A (powers r1.s) → valuation_field v)
((to_valuation_field hs2) ∘ (spa.rational_open_data.localization_map h) :
localization A (powers r1.s) → valuation_field v) _,
intro r,
delta to_valuation_field spa.rational_open_data.localization_map function.comp,
erw Huber_ring.away.lift_of,
erw Huber_ring.away.lift_of,
change _ = Huber_ring.away.lift (r2.T) (r2.s) _ _ _ (localization.of r),
rw Huber_ring.away.lift_of,
end
namespace rational_open_data
lemma to_valuation_field_cts_aux {r : spa.rational_open_data A} {v : spa A}
(hv : v ∈ r.open_set) : (Spv.out v.1) (r.s) ≠ 0 := hv.2
/-- The natural map from A(T/s) to the valuation field of a valuation v contained in
the rational open subset R(T/s). -/
def to_valuation_field {r : spa.rational_open_data A} {v : spa A} (hv : v ∈ r.open_set) :
spa.rational_open_data.localization r → valuation_field (Spv.out (v.val)) :=
(to_valuation_field $ to_valuation_field_cts_aux hv)
/-- The natural map from A(T/s) to the valuation field of a valuation v contained in
the rational open subset R(T/s) is a ring homomorphism. -/
instance {r : spa.rational_open_data A} {v : spa A} (hv : v ∈ r.open_set) :
is_ring_hom (to_valuation_field hv) := by {delta to_valuation_field, apply_instance}
/-- If v : spa A is in D(T,s) then the map A(T/s) -> K_v is continuous -/
theorem to_valuation_field_cts {r : spa.rational_open_data A} {v : spa A}
(hv : v ∈ r.open_set) : continuous (to_valuation_field hv) :=
Huber_pair.to_valuation_field_cts' hv.2 hv.1 v.2.1
-- Now we need to show that if r1 <= r2 then these to_valuation_field maps
-- are compatible.
theorem to_valuation_field_commutes {r1 r2 : spa.rational_open_data A} {v : spa A}
(hv1 : v ∈ r1.open_set) (hv2 : v ∈ r2.open_set) (h : r1 ≤ r2) :
(to_valuation_field hv1) =
(to_valuation_field hv2) ∘ (spa.rational_open_data.localization_map h) :=
to_valuation_field_commutes r1 r2 h hv1.2 hv2.2
end rational_open_data
end Huber_pair
|
b7e31eecbbbd8088dad1cdb6ab38fb1f4f68e490 | 6432ea7a083ff6ba21ea17af9ee47b9c371760f7 | /tests/lean/run/parray1.lean | e31abef640bdf01c21c61b708457fa00769dd881 | [
"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 | 360 | lean | import Lean.Data.PersistentArray
def check [BEq α] (as : List α) : Bool :=
as.toPArray'.foldr (.::.) [] == as
def tst1 : IO Unit := do
assert! check [1, 2, 3]
assert! check ([] : List Nat)
assert! check (List.iota 17)
assert! check (List.iota 533)
assert! check (List.iota 1000)
assert! check (List.iota 2600)
IO.println "done"
#eval tst1
|
958ee70ff37db3690172a87ce0af40b30e6423d2 | cf39355caa609c0f33405126beee2739aa3cb77e | /tests/lean/run/1442.lean | e23576db6dc8c73d5ecd244e6557b7974a7b3d52 | [
"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 | 692 | lean | protected def rel : ℤ × ℤ → ℤ × ℤ → Prop
| ⟨n₁, d₁⟩ ⟨n₂, d₂⟩ := n₁ * d₂ = n₂ * d₁
private def mul' : ℤ × ℤ → ℤ × ℤ → ℤ × ℤ
| ⟨n₁, d₁⟩ ⟨n₂, d₂⟩ := ⟨n₁ * n₂, d₁ * d₂⟩
instance a : is_associative ℤ (*) := ⟨int.mul_assoc⟩
instance c : is_commutative ℤ (*) := ⟨int.mul_comm⟩
example : ∀(a b c d : ℤ × ℤ), rel a c → rel b d → rel (mul' a b) (mul' c d) :=
λ⟨n₁, d₁⟩ ⟨n₂, d₂⟩ ⟨n₃, d₃⟩ ⟨n₄, d₄⟩,
assume (h₁ : n₁ * d₃ = n₃ * d₁) (h₂ : n₂ * d₄ = n₄ * d₂),
show (n₁ * n₂) * (d₃ * d₄) = (n₃ * n₄) * (d₁ * d₂),
by cc
|
a927bc73a9b55745b8fda75a34f9e2a3119c80c1 | c7e0fa0422da099d4b66b195c60455d87facee0d | /complex.lean | 2e71bcb2c534552e1dc71d06005f863338ca21b0 | [] | no_license | viljamivirolainen/linear | 12d725a90a44ae2760f59e9a9d9dd12aae36300a | dcf28df05e06da1b4fc76bce61b8fa0741300dc8 | refs/heads/master | 1,678,895,327,362 | 1,516,045,398,000 | 1,516,045,398,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 201 | lean | import smt.arith
def complex := real × real
notation `ℂ` := complex
-- Oh god, it's noncomputable, HELP
noncomputable def add : ℂ → ℂ → ℂ
| ⟨a, b⟩ ⟨c, d⟩ := ⟨a + c, b + d⟩
|
bd510032f7374276e87320b605240219b0f33174 | cf39355caa609c0f33405126beee2739aa3cb77e | /tests/lean/auto_quote_error.lean | ea2c2851cdae4f0b91a842aa3decf47f64963284 | [
"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 | 120 | lean | example (a b c : nat) : a = b → b = c → c = a :=
begin
intro h1,
intro h2,
exact eq.symm (eq.trans h1 _),
end
|
25e738c3ca18e7058b8df913fa174f881f7a8c41 | 947fa6c38e48771ae886239b4edce6db6e18d0fb | /src/data/nat/cast.lean | 17c0199b286ec06533a1af53e7924f875b3f219c | [
"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 | 9,081 | lean | /-
Copyright (c) 2014 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import data.nat.basic
import data.nat.cast.defs
import algebra.group.pi
import tactic.pi_instances
import data.sum.basic
/-!
# Cast of natural numbers (additional theorems)
This file proves additional properties about the *canonical* homomorphism from
the natural numbers into an additive monoid with a one (`nat.cast`).
## Main declarations
* `cast_add_monoid_hom`: `cast` bundled as an `add_monoid_hom`.
* `cast_ring_hom`: `cast` bundled as a `ring_hom`.
-/
namespace nat
variables {α : Type*}
/-- `coe : ℕ → α` as an `add_monoid_hom`. -/
def cast_add_monoid_hom (α : Type*) [add_monoid_with_one α] : ℕ →+ α :=
{ to_fun := coe,
map_add' := cast_add,
map_zero' := cast_zero }
@[simp] lemma coe_cast_add_monoid_hom [add_monoid_with_one α] :
(cast_add_monoid_hom α : ℕ → α) = coe := rfl
@[simp, norm_cast] theorem cast_mul [non_assoc_semiring α] (m n : ℕ) :
((m * n : ℕ) : α) = m * n :=
by induction n; simp [mul_succ, mul_add, *]
/-- `coe : ℕ → α` as a `ring_hom` -/
def cast_ring_hom (α : Type*) [non_assoc_semiring α] : ℕ →+* α :=
{ to_fun := coe,
map_one' := cast_one,
map_mul' := cast_mul,
.. cast_add_monoid_hom α }
@[simp] lemma coe_cast_ring_hom [non_assoc_semiring α] : (cast_ring_hom α : ℕ → α) = coe := rfl
lemma cast_commute [non_assoc_semiring α] (n : ℕ) (x : α) : commute ↑n x :=
nat.rec_on n (by rw [cast_zero]; exact commute.zero_left x) $
λ n ihn, by rw [cast_succ]; exact ihn.add_left (commute.one_left x)
lemma cast_comm [non_assoc_semiring α] (n : ℕ) (x : α) : (n : α) * x = x * n :=
(cast_commute n x).eq
lemma commute_cast [non_assoc_semiring α] (x : α) (n : ℕ) : commute x n :=
(n.cast_commute x).symm
section
variables [ordered_semiring α]
@[mono] theorem mono_cast : monotone (coe : ℕ → α) :=
monotone_nat_of_le_succ $ λ n, by rw [nat.cast_succ]; exact le_add_of_nonneg_right zero_le_one
@[simp] theorem cast_nonneg (n : ℕ) : 0 ≤ (n : α) :=
@nat.cast_zero α _ ▸ mono_cast (nat.zero_le n)
variable [nontrivial α]
@[simp, norm_cast] theorem cast_le {m n : ℕ} :
(m : α) ≤ n ↔ m ≤ n :=
strict_mono_cast.le_iff_le
@[simp, norm_cast, mono] 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 :=
(@mono_cast α _).map_min
@[simp, norm_cast] theorem cast_max [linear_ordered_semiring α] {a b : ℕ} :
(↑(max a b) : α) = max a b :=
(@mono_cast α _).map_max
@[simp, norm_cast] theorem abs_cast [linear_ordered_ring α] (a : ℕ) :
|(a : α)| = a :=
abs_of_nonneg (cast_nonneg a)
lemma coe_nat_dvd [semiring α] {m n : ℕ} (h : m ∣ n) : (m : α) ∣ (n : α) :=
map_dvd (nat.cast_ring_hom α) h
alias coe_nat_dvd ← _root_.has_dvd.dvd.nat_cast
end nat
namespace prod
variables {α : Type*} {β : Type*} [add_monoid_with_one α] [add_monoid_with_one β]
instance : add_monoid_with_one (α × β) :=
{ nat_cast := λ n, (n, n),
nat_cast_zero := congr_arg2 prod.mk nat.cast_zero nat.cast_zero,
nat_cast_succ := λ n, congr_arg2 prod.mk (nat.cast_succ _) (nat.cast_succ _),
.. prod.add_monoid, .. prod.has_one }
@[simp] lemma fst_nat_cast (n : ℕ) : (n : α × β).fst = n :=
by induction n; simp *
@[simp] lemma snd_nat_cast (n : ℕ) : (n : α × β).snd = n :=
by induction n; simp *
end prod
section add_monoid_hom_class
variables {A B F : Type*} [add_monoid_with_one B]
lemma ext_nat' [add_monoid A] [add_monoid_hom_class F ℕ A] (f g : F) (h : f 1 = g 1) : f = g :=
fun_like.ext f g $ begin
apply nat.rec,
{ simp only [nat.nat_zero_eq_zero, map_zero] },
simp [nat.succ_eq_add_one, h] {contextual := tt}
end
@[ext] lemma add_monoid_hom.ext_nat [add_monoid A] : ∀ {f g : ℕ →+ A}, ∀ h : f 1 = g 1, f = g :=
ext_nat'
variable [add_monoid_with_one A]
-- these versions are primed so that the `ring_hom_class` versions aren't
lemma eq_nat_cast' [add_monoid_hom_class F ℕ A] (f : F) (h1 : f 1 = 1) :
∀ n : ℕ, f n = n
| 0 := by simp
| (n+1) := by rw [map_add, h1, eq_nat_cast' n, nat.cast_add_one]
lemma map_nat_cast' {A} [add_monoid_with_one A] [add_monoid_hom_class F A B]
(f : F) (h : f 1 = 1) : ∀ (n : ℕ), f n = n
| 0 := by simp
| (n+1) := by rw [nat.cast_add, map_add, nat.cast_add, map_nat_cast', nat.cast_one, h, nat.cast_one]
end add_monoid_hom_class
section monoid_with_zero_hom_class
variables {A F : Type*} [mul_zero_one_class A]
/-- If two `monoid_with_zero_hom`s agree on the positive naturals they are equal. -/
theorem ext_nat'' [monoid_with_zero_hom_class F ℕ A] (f g : F)
(h_pos : ∀ {n : ℕ}, 0 < n → f n = g n) : f = g :=
begin
apply fun_like.ext,
rintro (_|n),
{ simp },
exact h_pos n.succ_pos
end
@[ext] theorem monoid_with_zero_hom.ext_nat :
∀ {f g : ℕ →*₀ A}, (∀ {n : ℕ}, 0 < n → f n = g n) → f = g := ext_nat''
end monoid_with_zero_hom_class
section ring_hom_class
variables {R S F : Type*} [non_assoc_semiring R] [non_assoc_semiring S]
@[simp] lemma eq_nat_cast [ring_hom_class F ℕ R] (f : F) : ∀ n, f n = n :=
eq_nat_cast' f $ map_one f
@[simp] lemma map_nat_cast [ring_hom_class F R S] (f : F) : ∀ n : ℕ, f (n : R) = n :=
map_nat_cast' f $ map_one f
lemma ext_nat [ring_hom_class F ℕ R] (f g : F) : f = g :=
ext_nat' f g $ by simp only [map_one]
end ring_hom_class
namespace ring_hom
/-- This is primed to match `ring_hom.eq_int_cast'`. -/
lemma eq_nat_cast' {R} [non_assoc_semiring R] (f : ℕ →+* R) : f = nat.cast_ring_hom R :=
ring_hom.ext $ eq_nat_cast f
end ring_hom
@[simp, norm_cast] theorem nat.cast_id (n : ℕ) : ↑n = n :=
rfl
@[simp] lemma nat.cast_ring_hom_nat : nat.cast_ring_hom ℕ = ring_hom.id ℕ := rfl
@[simp] theorem nat.cast_with_bot (n : ℕ) :
@coe ℕ (with_bot ℕ) (@coe_to_lift _ _ nat.cast_coe) n = n := rfl
-- I don't think `ring_hom_class` is good here, because of the `subsingleton` TC slowness
instance nat.unique_ring_hom {R : Type*} [non_assoc_semiring R] : unique (ℕ →+* R) :=
{ default := nat.cast_ring_hom R, uniq := ring_hom.eq_nat_cast' }
namespace mul_opposite
variables {α : Type*} [add_monoid_with_one α]
@[simp, norm_cast] lemma op_nat_cast (n : ℕ) : op (n : α) = n := rfl
@[simp, norm_cast] lemma unop_nat_cast (n : ℕ) : unop (n : αᵐᵒᵖ) = n := rfl
end mul_opposite
namespace with_top
variables {α : Type*}
variables [add_monoid_with_one α]
@[simp, norm_cast] lemma coe_nat : ∀ (n : ℕ), ((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 :=
⟨lt_of_lt_of_le (coe_lt_coe.mpr zero_lt_one),
λ 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
namespace pi
variables {α : Type*} {β : α → Type*} [∀ a, has_nat_cast (β a)]
instance : has_nat_cast (∀ a, β a) :=
by refine_struct { .. }; tactic.pi_instance_derive_field
lemma nat_apply (n : ℕ) (a : α) : (n : ∀ a, β a) a = n := rfl
@[simp] lemma coe_nat (n : ℕ) : (n : ∀ a, β a) = λ _, n := rfl
end pi
lemma sum.elim_nat_cast_nat_cast {α β γ : Type*} [has_nat_cast γ] (n : ℕ) :
sum.elim (n : α → γ) (n : β → γ) = n :=
@sum.elim_lam_const_lam_const α β γ n
namespace pi
variables {α : Type*} {β : α → Type*} [∀ a, add_monoid_with_one (β a)]
instance : add_monoid_with_one (∀ a, β a) :=
by refine_struct { .. }; tactic.pi_instance_derive_field
end pi
|
119ba6b60d673c011ac8e5d98321fe117c31712c | a9d0fb7b0e4f802bd3857b803e6c5c23d87fef91 | /hott/algebra/category/functor/attributes.hlean | a97ba8b275682fbe9f18e4d9ad7a03d1c286d10b | [
"Apache-2.0"
] | permissive | soonhokong/lean-osx | 4a954262c780e404c1369d6c06516161d07fcb40 | 3670278342d2f4faa49d95b46d86642d7875b47c | refs/heads/master | 1,611,410,334,552 | 1,474,425,686,000 | 1,474,425,686,000 | 12,043,103 | 5 | 1 | null | null | null | null | UTF-8 | Lean | false | false | 6,516 | hlean | /-
Copyright (c) 2015 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn
Attributes of functors (full, faithful, split essentially surjective, ...)
Adjoint functors, isomorphisms and equivalences have their own file
-/
import ..constructions.functor function arity
open eq functor trunc prod is_equiv iso equiv function is_trunc
namespace category
variables {C D E : Precategory} {F : C ⇒ D} {G : D ⇒ C}
definition faithful [class] (F : C ⇒ D) := Π⦃c c' : C⦄ ⦃f f' : c ⟶ c'⦄, F f = F f' → f = f'
definition full [class] (F : C ⇒ D) := Π⦃c c' : C⦄, is_surjective (@(to_fun_hom F) c c')
definition fully_faithful [class] (F : C ⇒ D) := Π(c c' : C), is_equiv (@(to_fun_hom F) c c')
definition split_essentially_surjective [class] (F : C ⇒ D) := Π(d : D), Σ(c : C), F c ≅ d
definition essentially_surjective [class] (F : C ⇒ D) := Π(d : D), ∃(c : C), F c ≅ d
definition is_weak_equivalence [class] (F : C ⇒ D) :=
fully_faithful F × essentially_surjective F
definition is_equiv_of_fully_faithful [instance] (F : C ⇒ D)
[H : fully_faithful F] (c c' : C) : is_equiv (@(to_fun_hom F) c c') :=
!H
definition hom_inv [reducible] (F : C ⇒ D) [H : fully_faithful F] (c c' : C) (f : F c ⟶ F c')
: c ⟶ c' :=
(to_fun_hom F)⁻¹ᶠ f
definition reflect_is_iso [constructor] (F : C ⇒ D) [H : fully_faithful F] {c c' : C}
(f : c ⟶ c') [H : is_iso (F f)] : is_iso f :=
begin
fconstructor,
{ exact (to_fun_hom F)⁻¹ᶠ (F f)⁻¹},
{ apply eq_of_fn_eq_fn' (to_fun_hom F),
rewrite [respect_comp,right_inv (to_fun_hom F),respect_id,left_inverse]},
{ apply eq_of_fn_eq_fn' (to_fun_hom F),
rewrite [respect_comp,right_inv (to_fun_hom F),respect_id,right_inverse]},
end
definition reflect_iso [constructor] (F : C ⇒ D) [H : fully_faithful F] {c c' : C}
(f : F c ≅ F c') : c ≅ c' :=
begin
fconstructor,
{ exact (to_fun_hom F)⁻¹ᶠ f},
{ have H : is_iso (F ((to_fun_hom F)⁻¹ᶠ f)), from
have H' : is_iso (to_hom f), from _,
(right_inv (to_fun_hom F) (to_hom f))⁻¹ ▸ H',
exact reflect_is_iso F _},
end
theorem reflect_inverse (F : C ⇒ D) [H : fully_faithful F] {c c' : C} (f : c ⟶ c')
[H' : is_iso f] : (to_fun_hom F)⁻¹ᶠ (F f)⁻¹ = f⁻¹ :=
@inverse_eq_inverse _ _ _ _ _ _ (reflect_is_iso F f) H' idp
definition hom_equiv_F_hom_F [constructor] (F : C ⇒ D)
[H : fully_faithful F] (c c' : C) : (c ⟶ c') ≃ (F c ⟶ F c') :=
equiv.mk _ !H
definition iso_of_F_iso_F (F : C ⇒ D)
[H : fully_faithful F] (c c' : C) (g : F c ≅ F c') : c ≅ c' :=
begin
induction g with g G, induction G with h p q, fapply iso.MK,
{ rexact (to_fun_hom F)⁻¹ᶠ g},
{ rexact (to_fun_hom F)⁻¹ᶠ h},
{ exact abstract begin
apply eq_of_fn_eq_fn' (to_fun_hom F),
rewrite [respect_comp, respect_id,
right_inv (to_fun_hom F), right_inv (to_fun_hom F), p],
end end},
{ exact abstract begin
apply eq_of_fn_eq_fn' (to_fun_hom F),
rewrite [respect_comp, respect_id,
right_inv (to_fun_hom F), right_inv (@(to_fun_hom F) c' c), q],
end end}
end
definition iso_equiv_F_iso_F [constructor] (F : C ⇒ D)
[H : fully_faithful F] (c c' : C) : (c ≅ c') ≃ (F c ≅ F c') :=
begin
fapply equiv.MK,
{ exact to_fun_iso F},
{ apply iso_of_F_iso_F},
{ exact abstract begin
intro f, induction f with f F', induction F' with g p q, apply iso_eq,
esimp [iso_of_F_iso_F], apply right_inv end end},
{ exact abstract begin
intro f, induction f with f F', induction F' with g p q, apply iso_eq,
esimp [iso_of_F_iso_F], apply right_inv end end},
end
definition full_of_fully_faithful [instance] (F : C ⇒ D) [H : fully_faithful F] : full F :=
λc c' g, tr (fiber.mk ((@(to_fun_hom F) c c')⁻¹ᶠ g) !right_inv)
definition faithful_of_fully_faithful [instance] (F : C ⇒ D) [H : fully_faithful F]
: faithful F :=
λc c' f f' p, is_injective_of_is_embedding p
definition is_embedding_of_faithful [instance] (F : C ⇒ D) [H : faithful F] (c c' : C)
: is_embedding (to_fun_hom F : c ⟶ c' → F c ⟶ F c') :=
begin
apply is_embedding_of_is_injective,
apply H
end
definition is_surjective_of_full [instance] (F : C ⇒ D) [H : full F] (c c' : C)
: is_surjective (to_fun_hom F : c ⟶ c' → F c ⟶ F c') :=
@H c c'
definition fully_faithful_of_full_of_faithful (H : faithful F) (K : full F)
: fully_faithful F :=
begin
intro c c',
apply is_equiv_of_is_surjective_of_is_embedding,
end
theorem is_prop_fully_faithful [instance] (F : C ⇒ D) : is_prop (fully_faithful F) :=
by unfold fully_faithful; exact _
theorem is_prop_full [instance] (F : C ⇒ D) : is_prop (full F) :=
by unfold full; exact _
theorem is_prop_faithful [instance] (F : C ⇒ D) : is_prop (faithful F) :=
by unfold faithful; exact _
theorem is_prop_essentially_surjective [instance] (F : C ⇒ D)
: is_prop (essentially_surjective F) :=
by unfold essentially_surjective; exact _
theorem is_prop_is_weak_equivalence [instance] (F : C ⇒ D) : is_prop (is_weak_equivalence F) :=
by unfold is_weak_equivalence; exact _
definition fully_faithful_equiv (F : C ⇒ D) : fully_faithful F ≃ (faithful F × full F) :=
equiv_of_is_prop (λH, (faithful_of_fully_faithful F, full_of_fully_faithful F))
(λH, fully_faithful_of_full_of_faithful (pr1 H) (pr2 H))
/- alternative proof using direct calculation with equivalences
definition fully_faithful_equiv (F : C ⇒ D) : fully_faithful F ≃ (faithful F × full F) :=
calc
fully_faithful F
≃ (Π(c c' : C), is_embedding (to_fun_hom F) × is_surjective (to_fun_hom F))
: pi_equiv_pi_right (λc, pi_equiv_pi_right
(λc', !is_equiv_equiv_is_embedding_times_is_surjective))
... ≃ (Π(c : C), (Π(c' : C), is_embedding (to_fun_hom F)) ×
(Π(c' : C), is_surjective (to_fun_hom F)))
: pi_equiv_pi_right (λc, !equiv_prod_corec)
... ≃ (Π(c c' : C), is_embedding (to_fun_hom F)) × full F
: equiv_prod_corec
... ≃ faithful F × full F
: prod_equiv_prod_right (pi_equiv_pi_right (λc, pi_equiv_pi_right
(λc', !is_embedding_equiv_is_injective)))
-/
end category
|
40524c0c0fe6cb2c90cf5012be2e4251d3dec017 | e00ea76a720126cf9f6d732ad6216b5b824d20a7 | /src/algebra/group/to_additive.lean | ec32d4058e2b70912534fff8c05913786c3ffeda | [
"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 | 9,872 | lean | /-
Copyright (c) 2017 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Yury Kudryashov.
-/
import tactic.basic tactic.transport tactic.algebra
/-!
# Transport multiplicative to additive
This file defines an attribute `to_additive` that can be used to
automatically transport theorems and definitions (but not inductive
types and structures) from multiplicative theory to additive theory.
To use this attribute, just write
```
@[to_additive]
theorem mul_comm' {α} [comm_semigroup α] (x y : α) : x * y = y * x := comm_semigroup.mul_comm
```
This code will generate a theorem named `add_comm'`. It is also
possible to manually specify the name of the new declaration, and
provide a documentation string.
The transport tries to do the right thing in most cases using several
heuristics described below. However, in some cases it fails, and
requires manual intervention.
## Implementation notes
### Handling of hidden definitions
Before transporting the “main” declaration `src`, `to_additive` first
scans its type and value for names starting with `src`, and transports
them. This includes auxiliary definitions like `src._match_1`,
`src._proof_1`.
After transporting the “main” declaration, `to_additive` transports
its equational lemmas.
### Structure fields and constructors
If `src` is a structure, then `to_additive` automatically adds
structure fields to its mapping, and similarly for constructors of
inductive types.
For new structures this means that `to_additive` automatically handles
coercions, and for old structures it does the same, if ancestry
information is present in `@[ancestor]` attributes.
### Name generation
* If `@[to_additive]` is called without a `name` argument, then the
new name is autogenerated. First, it takes the longest prefix of
the source name that is already known to `to_additive`, and replaces
this prefix with its additive counterpart. Second, it takes the last
part of the name (i.e., after the last dot), and replaces common
name parts (“mul”, “one”, “inv”, “prod”) with their additive versions.
* If `@[to_additive]` is called with a `name` argument `new_name`
/without a dot/, then `to_additive` updates the prefix as described
above, then replaces the last part of the name with `new_name`.
* If `@[to_additive]` is called with a `name` argument
`new_namespace.new_name` /with a dot/, then `to_additive` uses this
new name as is.
As a safety check, in the first two cases `to_additive` double checks
that the new name differs from the original one.
### Missing features
* Automatically transport structures and other inductive types.
* Handle `protected` attribute. Currently all new definitions are public.
* For structures, automatically generate theorems like `group α ↔
add_group (additive α)`.
* Mapping of prefixes that do not correspond to any definition, see
`quotient_group`.
* Rewrite rules for the last part of the name that work in more
cases. E.g., we can replace `monoid` with `add_monoid` etc.
-/
namespace to_additive
open tactic exceptional
@[user_attribute]
meta def aux_attr : user_attribute (name_map name) name :=
{ name := `to_additive_aux,
descr := "Auxiliary attribute for `to_additive`. DON'T USE IT",
cache_cfg := ⟨λ ns,
ns.mfoldl
(λ dict n',
let n := match n' with
| name.mk_string s pre := if s = "_to_additive" then pre else n'
| _ := n'
end
in dict.insert n <$> aux_attr.get_param n')
mk_name_map, []⟩,
parser := lean.parser.ident }
meta def map_namespace (src tgt : name) : command :=
do let n := src.mk_string "_to_additive",
let decl := declaration.thm n [] `(unit) (pure (reflect ())),
add_decl decl,
aux_attr.set n tgt tt
@[derive has_reflect, derive inhabited]
structure value_type := (tgt : name) (doc : option string)
/-- Dictionary of words used by `to_additive.guess_name` to autogenerate
names. -/
meta def tokens_dict : native.rb_map string string :=
native.rb_map.of_list $
[("mul", "add"), ("one", "zero"), ("inv", "neg"), ("prod", "sum")]
/-- Autogenerate target name for `to_additive`. -/
meta def guess_name : string → string :=
string.map_tokens '_' $ list.map $
string.map_tokens ''' $ list.map $
λ s, (tokens_dict.find s).get_or_else s
meta def target_name (src tgt : name) (dict : name_map name) : tactic name :=
(if tgt.get_prefix ≠ name.anonymous -- `tgt` is a full name
then pure tgt
else match src with
| (name.mk_string s pre) :=
do let tgt_auto := guess_name s,
guard (tgt.to_string ≠ tgt_auto)
<|> trace ("`to_additive " ++ src.to_string ++ "`: remove `name` argument"),
pure $ name.mk_string
(if tgt = name.anonymous then tgt_auto else tgt.to_string)
(pre.map_prefix dict.find)
| _ := fail ("to_additive: can't transport " ++ src.to_string)
end) >>=
(λ res,
if res = src
then fail ("to_additive: can't transport " ++ src.to_string ++ " to itself")
else pure res)
meta def parser : lean.parser value_type :=
do
tgt ← optional lean.parser.ident,
e ← optional interactive.types.texpr,
doc ← match e with
| some pe := some <$> ((to_expr pe >>= eval_expr string) : tactic string)
| none := pure none
end,
return ⟨tgt.get_or_else name.anonymous, doc⟩
private meta def proceed_fields_aux (src tgt : name) (prio : ℕ) (f : name → tactic (list string)) :
command :=
do
src_fields ← f src,
tgt_fields ← f tgt,
guard (src_fields.length = tgt_fields.length) <|>
fail ("Failed to map fields of " ++ src.to_string),
(src_fields.zip tgt_fields).mmap' $
λ names, guard (names.fst = names.snd) <|>
aux_attr.set (src.append names.fst) (tgt.append names.snd) tt prio
meta def proceed_fields (env : environment) (src tgt : name) (prio : ℕ) : command :=
let aux := proceed_fields_aux src tgt prio in
do
aux (λ n, pure $ list.map name.to_string $ (env.structure_fields n).get_or_else []) >>
aux (λ n, (list.map (λ (x : name), "to_" ++ x.to_string) <$>
(ancestor_attr.get_param n <|> pure []))) >>
aux (λ n, (env.constructors_of n).mmap $
λ cs, match cs with
| (name.mk_string s pre) :=
(guard (pre = n) <|> fail "Bad constructor name") >>
pure s
| _ := fail "Bad constructor name"
end)
@[user_attribute]
protected meta def attr : user_attribute unit value_type :=
{ name := `to_additive,
descr := "Transport multiplicative to additive",
parser := parser,
after_set := some $ λ src prio persistent, do
guard persistent <|> fail "`to_additive` can't be used as a local attribute",
env ← get_env,
val ← attr.get_param src,
dict ← aux_attr.get_cache,
tgt ← target_name src val.tgt dict,
aux_attr.set src tgt tt,
let dict := dict.insert src tgt,
if env.contains tgt
then proceed_fields env src tgt prio
else do
transport_with_prefix_dict dict src tgt
[`reducible, `simp, `instance, `refl, `symm, `trans, `elab_as_eliminator],
match val.doc with
| some doc := add_doc_string tgt doc
| none := skip
end }
end to_additive
/- map operations -/
attribute [to_additive] has_mul has_one has_inv
/- map structures -/
attribute [to_additive add_semigroup] semigroup
attribute [to_additive add_comm_semigroup] comm_semigroup
attribute [to_additive add_left_cancel_semigroup] left_cancel_semigroup
attribute [to_additive add_right_cancel_semigroup] right_cancel_semigroup
attribute [to_additive add_monoid] monoid
attribute [to_additive add_comm_monoid] comm_monoid
attribute [to_additive add_group] group
attribute [to_additive add_comm_group] comm_group
/- map theorems -/
attribute [to_additive] mul_assoc
attribute [to_additive add_semigroup_to_is_eq_associative] semigroup_to_is_associative
attribute [to_additive] mul_comm
attribute [to_additive add_comm_semigroup_to_is_eq_commutative] comm_semigroup_to_is_commutative
attribute [to_additive] mul_left_comm
attribute [to_additive] mul_right_comm
attribute [to_additive] mul_left_cancel
attribute [to_additive] mul_right_cancel
attribute [to_additive] mul_left_cancel_iff
attribute [to_additive] mul_right_cancel_iff
attribute [to_additive] one_mul
attribute [to_additive] mul_one
attribute [to_additive] mul_left_inv
attribute [to_additive] inv_mul_self
attribute [to_additive] inv_mul_cancel_left
attribute [to_additive] inv_mul_cancel_right
attribute [to_additive] inv_eq_of_mul_eq_one
attribute [to_additive neg_zero] one_inv
attribute [to_additive] inv_inv
attribute [to_additive] mul_right_inv
attribute [to_additive] mul_inv_self
attribute [to_additive] inv_inj
attribute [to_additive] group.mul_left_cancel
attribute [to_additive] group.mul_right_cancel
attribute [to_additive to_left_cancel_add_semigroup] group.to_left_cancel_semigroup
attribute [to_additive to_right_cancel_add_semigroup] group.to_right_cancel_semigroup
attribute [to_additive] mul_inv_cancel_left
attribute [to_additive] mul_inv_cancel_right
attribute [to_additive neg_add_rev] mul_inv_rev
attribute [to_additive] eq_inv_of_eq_inv
attribute [to_additive] eq_inv_of_mul_eq_one
attribute [to_additive] eq_mul_inv_of_mul_eq
attribute [to_additive] eq_inv_mul_of_mul_eq
attribute [to_additive] inv_mul_eq_of_eq_mul
attribute [to_additive] mul_inv_eq_of_eq_mul
attribute [to_additive] eq_mul_of_mul_inv_eq
attribute [to_additive] eq_mul_of_inv_mul_eq
attribute [to_additive] mul_eq_of_eq_inv_mul
attribute [to_additive] mul_eq_of_eq_mul_inv
attribute [to_additive neg_add] mul_inv
|
105b8b38421b294229502746679f32d6ea022932 | a0e23cfdd129a671bf3154ee1a8a3a72bf4c7940 | /src/Lean/Util/MonadCache.lean | 8b507d0837f42855b62b9744c32d6d84ce12a490 | [
"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 | 4,654 | 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 Std.Data.HashMap
namespace Lean
/-- Interface for caching results. -/
class MonadCache (α β : Type) (m : Type → Type) where
findCached? : α → m (Option β)
cache : α → β → m Unit
/-- If entry `a := b` is already in the cache, then return `b`.
Otherwise, execute `b ← f ()`, store `a := b` in the cache and return `b`. -/
@[inline] def checkCache {α β : Type} {m : Type → Type} [MonadCache α β m] [Monad m] (a : α) (f : Unit → m β) : m β := do
match (← MonadCache.findCached? a) with
| some b => pure b
| none => do
let b ← f ()
MonadCache.cache a b
pure b
instance {α β ρ : Type} {m : Type → Type} [MonadCache α β m] : MonadCache α β (ReaderT ρ m) where
findCached? a r := MonadCache.findCached? a
cache a b r := MonadCache.cache a b
instance {α β ε : Type} {m : Type → Type} [MonadCache α β m] [Monad m] : MonadCache α β (ExceptT ε m) where
findCached? a := ExceptT.lift $ MonadCache.findCached? a
cache a b := ExceptT.lift $ MonadCache.cache a b
open Std (HashMap)
/-- Adapter for implementing `MonadCache` interface using `HashMap`s.
We just have to specify how to extract/modify the `HashMap`. -/
class MonadHashMapCacheAdapter (α β : Type) (m : Type → Type) [BEq α] [Hashable α] where
getCache : m (HashMap α β)
modifyCache : (HashMap α β → HashMap α β) → m Unit
namespace MonadHashMapCacheAdapter
@[inline] def findCached? {α β : Type} {m : Type → Type} [BEq α] [Hashable α] [Monad m] [MonadHashMapCacheAdapter α β m] (a : α) : m (Option β) := do
let c ← getCache
pure (c.find? a)
@[inline] def cache {α β : Type} {m : Type → Type} [BEq α] [Hashable α] [MonadHashMapCacheAdapter α β m] (a : α) (b : β) : m Unit :=
modifyCache fun s => s.insert a b
instance {α β : Type} {m : Type → Type} [BEq α] [Hashable α] [Monad m] [MonadHashMapCacheAdapter α β m] : MonadCache α β m where
findCached? := MonadHashMapCacheAdapter.findCached?
cache := MonadHashMapCacheAdapter.cache
end MonadHashMapCacheAdapter
def MonadCacheT {ω} (α β : Type) (m : Type → Type) [STWorld ω m] [BEq α] [Hashable α] := StateRefT (HashMap α β) m
namespace MonadCacheT
variable {ω α β : Type} {m : Type → Type} [STWorld ω m] [BEq α] [Hashable α] [MonadLiftT (ST ω) m] [Monad m]
instance : MonadHashMapCacheAdapter α β (MonadCacheT α β m) where
getCache := (get : StateRefT' ..)
modifyCache f := (modify f : StateRefT' ..)
@[inline] def run {σ} (x : MonadCacheT α β m σ) : m σ :=
x.run' Std.mkHashMap
instance : Monad (MonadCacheT α β m) := inferInstanceAs (Monad (StateRefT' _ _ _))
instance : MonadLift m (MonadCacheT α β m) := inferInstanceAs (MonadLift m (StateRefT' _ _ _))
instance (ε) [MonadExceptOf ε m] : MonadExceptOf ε (MonadCacheT α β m) := inferInstanceAs (MonadExceptOf ε (StateRefT' _ _ _))
instance : MonadControl m (MonadCacheT α β m) := inferInstanceAs (MonadControl m (StateRefT' _ _ _))
instance [MonadFinally m] : MonadFinally (MonadCacheT α β m) := inferInstanceAs (MonadFinally (StateRefT' _ _ _))
instance [MonadRef m] : MonadRef (MonadCacheT α β m) := inferInstanceAs (MonadRef (StateRefT' _ _ _))
end MonadCacheT
/- Similar to `MonadCacheT`, but using `StateT` instead of `StateRefT` -/
def MonadStateCacheT (α β : Type) (m : Type → Type) [BEq α] [Hashable α] := StateT (HashMap α β) m
namespace MonadStateCacheT
variable {ω α β : Type} {m : Type → Type} [STWorld ω m] [BEq α] [Hashable α] [MonadLiftT (ST ω) m] [Monad m]
instance : MonadHashMapCacheAdapter α β (MonadStateCacheT α β m) where
getCache := (get : StateT ..)
modifyCache f := (modify f : StateT ..)
@[inline] def run {σ} (x : MonadStateCacheT α β m σ) : m σ :=
x.run' Std.mkHashMap
instance : Monad (MonadStateCacheT α β m) := inferInstanceAs (Monad (StateT _ _))
instance : MonadLift m (MonadStateCacheT α β m) := inferInstanceAs (MonadLift m (StateT _ _))
instance (ε) [MonadExceptOf ε m] : MonadExceptOf ε (MonadStateCacheT α β m) := inferInstanceAs (MonadExceptOf ε (StateT _ _))
instance : MonadControl m (MonadStateCacheT α β m) := inferInstanceAs (MonadControl m (StateT _ _))
instance [MonadFinally m] : MonadFinally (MonadStateCacheT α β m) := inferInstanceAs (MonadFinally (StateT _ _))
instance [MonadRef m] : MonadRef (MonadStateCacheT α β m) := inferInstanceAs (MonadRef (StateT _ _))
end MonadStateCacheT
end Lean
|
83f2a9d028528d5d3bcf1d1a4a5190f87135deb9 | ae1e94c332e17c7dc7051ce976d5a9eebe7ab8a5 | /tests/lean/run/evalBuiltinInit.lean | 8345727f82d2c62d7ab8d167cafcb74c3d57093d | [
"Apache-2.0"
] | permissive | dupuisf/lean4 | d082d13b01243e1de29ae680eefb476961221eef | 6a39c65bd28eb0e28c3870188f348c8914502718 | refs/heads/master | 1,676,948,755,391 | 1,610,665,114,000 | 1,610,665,114,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 198 | lean | #lang lean4
import Lean
-- option should be ignored when evaluating a `[builtinInit]` decl
set_option interpreter.prefer_native false
#eval toString Lean.PrettyPrinter.formatterAttribute.defn.name
|
0de9176346f5461b427161608ab6bd0027a06237 | a9d0fb7b0e4f802bd3857b803e6c5c23d87fef91 | /tests/lean/run/rw_set4.lean | c4e8004b680cf43b98ab503c90e71c4da1156bef | [
"Apache-2.0"
] | permissive | soonhokong/lean-osx | 4a954262c780e404c1369d6c06516161d07fcb40 | 3670278342d2f4faa49d95b46d86642d7875b47c | refs/heads/master | 1,611,410,334,552 | 1,474,425,686,000 | 1,474,425,686,000 | 12,043,103 | 5 | 1 | null | null | null | null | UTF-8 | Lean | false | false | 382 | lean | open tactic
attribute [congr, priority std.priority.default+1]
theorem forall_congr_prop_eq {P₁ P₂ Q₁ Q₂ : Prop} :
P₁ = P₂ → (P₂ → Q₁ = Q₂) → (P₁ → Q₁) = (P₂ → Q₂) :=
sorry
print [congr] congr
example (A : Type) (a b c : A) : (a = b) → (a = c) → a = b := by simp
example (A : Type) (a b c : A) : (a = c) → (a = b) → a = b := by simp
|
cf84e1472b244570088f2cb299a7e261802389ec | e2fc96178628c7451e998a0db2b73877d0648be5 | /src/classes/context_free/closure_properties/complement.lean | befec207d9e54c5905b2b948908d3d5a907b032e | [
"BSD-2-Clause"
] | permissive | madvorak/grammars | cd324ae19b28f7b8be9c3ad010ef7bf0fabe5df2 | 1447343a45fcb7821070f1e20b57288d437323a6 | refs/heads/main | 1,692,383,644,884 | 1,692,032,429,000 | 1,692,032,429,000 | 453,948,141 | 7 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 701 | lean | import classes.context_free.closure_properties.union
import classes.context_free.closure_properties.intersection
/-- The class of context-free languages isn't closed under complement. -/
theorem nnyCF_of_complement_CF : ¬ (∀ T : Type, ∀ L : language T,
is_CF L → is_CF (Lᶜ)
) :=
begin
intro h,
have nny := nnyCF_of_CF_i_CF,
push_neg at nny,
rcases nny with ⟨T, L₁, L₂, ⟨hL₁, hL₂⟩, hyp_neg⟩,
specialize h T,
have hu := CF_of_CF_u_CF (L₁ᶜ) (L₂ᶜ) ⟨h L₁ hL₁, h L₂ hL₂⟩,
have contra := h (L₁ᶜ + L₂ᶜ) hu,
apply hyp_neg,
-- golfed by Eric Wieser
rwa [language.add_def, set.compl_union, compl_compl, compl_compl] at contra,
end
|
224a0d9e90df6d781999abe0128085f8a9e1308f | 57c233acf9386e610d99ed20ef139c5f97504ba3 | /src/algebra/direct_sum/ring.lean | 4b6fafa5e3d4dee5f8eb0b71e16125c4b76e5475 | [
"Apache-2.0"
] | permissive | robertylewis/mathlib | 3d16e3e6daf5ddde182473e03a1b601d2810952c | 1d13f5b932f5e40a8308e3840f96fc882fae01f0 | refs/heads/master | 1,651,379,945,369 | 1,644,276,960,000 | 1,644,276,960,000 | 98,875,504 | 0 | 0 | Apache-2.0 | 1,644,253,514,000 | 1,501,495,700,000 | Lean | UTF-8 | Lean | false | false | 19,158 | lean | /-
Copyright (c) 2021 Eric Wieser. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Wieser
-/
import group_theory.subgroup.basic
import algebra.graded_monoid
import algebra.direct_sum.basic
import algebra.big_operators.pi
/-!
# Additively-graded multiplicative structures on `⨁ i, A i`
This module provides a set of heterogeneous typeclasses for defining a multiplicative structure
over `⨁ i, A i` such that `(*) : A i → A j → A (i + j)`; that is to say, `A` forms an
additively-graded ring. The typeclasses are:
* `direct_sum.gnon_unital_non_assoc_semiring A`
* `direct_sum.gsemiring A`
* `direct_sum.gcomm_semiring A`
Respectively, these imbue the external direct sum `⨁ i, A i` with:
* `direct_sum.non_unital_non_assoc_semiring`
* `direct_sum.semiring`, `direct_sum.ring`
* `direct_sum.comm_semiring`, `direct_sum.comm_ring`
the base ring `A 0` with:
* `direct_sum.grade_zero.non_unital_non_assoc_semiring`
* `direct_sum.grade_zero.semiring`, `direct_sum.grade_zero.ring`
* `direct_sum.grade_zero.comm_semiring`, `direct_sum.grade_zero.comm_ring`
and the `i`th grade `A i` with `A 0`-actions (`•`) defined as left-multiplication:
* `direct_sum.grade_zero.has_scalar (A 0)`, `direct_sum.grade_zero.smul_with_zero (A 0)`
* `direct_sum.grade_zero.module (A 0)`
* (nothing)
Note that in the presence of these instances, `⨁ i, A i` itself inherits an `A 0`-action.
`direct_sum.of_zero_ring_hom : A 0 →+* ⨁ i, A i` provides `direct_sum.of A 0` as a ring
homomorphism.
`direct_sum.to_semiring` extends `direct_sum.to_add_monoid` to produce a `ring_hom`.
## Direct sums of subobjects
Additionally, this module provides helper functions to construct `gsemiring` and `gcomm_semiring`
instances for:
* `A : ι → submonoid S`:
`direct_sum.gsemiring.of_add_submonoids`, `direct_sum.gcomm_semiring.of_add_submonoids`.
* `A : ι → subgroup S`:
`direct_sum.gsemiring.of_add_subgroups`, `direct_sum.gcomm_semiring.of_add_subgroups`.
* `A : ι → submodule S`:
`direct_sum.gsemiring.of_submodules`, `direct_sum.gcomm_semiring.of_submodules`.
If `complete_lattice.independent (set.range A)`, these provide a gradation of `⨆ i, A i`, and the
mapping `⨁ i, A i →+ ⨆ i, A i` can be obtained as
`direct_sum.to_monoid (λ i, add_submonoid.inclusion $ le_supr A i)`.
## tags
graded ring, filtered ring, direct sum, add_submonoid
-/
set_option old_structure_cmd true
variables {ι : Type*} [decidable_eq ι]
namespace direct_sum
open_locale direct_sum
/-! ### Typeclasses -/
section defs
variables (A : ι → Type*)
/-- A graded version of `non_unital_non_assoc_semiring`. -/
class gnon_unital_non_assoc_semiring [has_add ι] [Π i, add_comm_monoid (A i)] extends
graded_monoid.ghas_mul A :=
(mul_zero : ∀ {i j} (a : A i), mul a (0 : A j) = 0)
(zero_mul : ∀ {i j} (b : A j), mul (0 : A i) b = 0)
(mul_add : ∀ {i j} (a : A i) (b c : A j), mul a (b + c) = mul a b + mul a c)
(add_mul : ∀ {i j} (a b : A i) (c : A j), mul (a + b) c = mul a c + mul b c)
end defs
section defs
variables (A : ι → Type*)
/-- A graded version of `semiring`. -/
class gsemiring [add_monoid ι] [Π i, add_comm_monoid (A i)] extends
gnon_unital_non_assoc_semiring A, graded_monoid.gmonoid A
/-- A graded version of `comm_semiring`. -/
class gcomm_semiring [add_comm_monoid ι] [Π i, add_comm_monoid (A i)] extends
gsemiring A, graded_monoid.gcomm_monoid A
end defs
lemma of_eq_of_graded_monoid_eq {A : ι → Type*} [Π (i : ι), add_comm_monoid (A i)]
{i j : ι} {a : A i} {b : A j} (h : graded_monoid.mk i a = graded_monoid.mk j b) :
direct_sum.of A i a = direct_sum.of A j b :=
dfinsupp.single_eq_of_sigma_eq h
variables (A : ι → Type*)
/-! ### Instances for `⨁ i, A i` -/
section one
variables [has_zero ι] [graded_monoid.ghas_one A] [Π i, add_comm_monoid (A i)]
instance : has_one (⨁ i, A i) :=
{ one := direct_sum.of (λ i, A i) 0 graded_monoid.ghas_one.one }
end one
section mul
variables [has_add ι] [Π i, add_comm_monoid (A i)] [gnon_unital_non_assoc_semiring A]
open add_monoid_hom (flip_apply coe_comp comp_hom_apply_apply)
/-- The piecewise multiplication from the `has_mul` instance, as a bundled homomorphism. -/
@[simps]
def gmul_hom {i j} : A i →+ A j →+ A (i + j) :=
{ to_fun := λ a,
{ to_fun := λ b, graded_monoid.ghas_mul.mul a b,
map_zero' := gnon_unital_non_assoc_semiring.mul_zero _,
map_add' := gnon_unital_non_assoc_semiring.mul_add _ },
map_zero' := add_monoid_hom.ext $ λ a, gnon_unital_non_assoc_semiring.zero_mul a,
map_add' := λ a₁ a₂, add_monoid_hom.ext $ λ b, gnon_unital_non_assoc_semiring.add_mul _ _ _}
/-- The multiplication from the `has_mul` instance, as a bundled homomorphism. -/
def mul_hom : (⨁ i, A i) →+ (⨁ i, A i) →+ ⨁ i, A i :=
direct_sum.to_add_monoid $ λ i,
add_monoid_hom.flip $ direct_sum.to_add_monoid $ λ j, add_monoid_hom.flip $
(direct_sum.of A _).comp_hom.comp $ gmul_hom A
instance : non_unital_non_assoc_semiring (⨁ i, A i) :=
{ mul := λ a b, mul_hom A a b,
zero := 0,
add := (+),
zero_mul := λ a, by simp only [add_monoid_hom.map_zero, add_monoid_hom.zero_apply],
mul_zero := λ a, by simp only [add_monoid_hom.map_zero],
left_distrib := λ a b c, by simp only [add_monoid_hom.map_add],
right_distrib := λ a b c, by simp only [add_monoid_hom.map_add, add_monoid_hom.add_apply],
.. direct_sum.add_comm_monoid _ _}
variables {A}
lemma mul_hom_of_of {i j} (a : A i) (b : A j) :
mul_hom A (of _ i a) (of _ j b) = of _ (i + j) (graded_monoid.ghas_mul.mul a b) :=
begin
unfold mul_hom,
rw [to_add_monoid_of, flip_apply, to_add_monoid_of, flip_apply, coe_comp, function.comp_app,
comp_hom_apply_apply, coe_comp, function.comp_app, gmul_hom_apply_apply],
end
lemma of_mul_of {i j} (a : A i) (b : A j) :
of _ i a * of _ j b = of _ (i + j) (graded_monoid.ghas_mul.mul a b) :=
mul_hom_of_of a b
end mul
section semiring
variables [Π i, add_comm_monoid (A i)] [add_monoid ι] [gsemiring A]
open add_monoid_hom (flip_hom coe_comp comp_hom_apply_apply flip_apply flip_hom_apply)
private lemma one_mul (x : ⨁ i, A i) : 1 * x = x :=
suffices mul_hom A 1 = add_monoid_hom.id (⨁ i, A i),
from add_monoid_hom.congr_fun this x,
begin
apply add_hom_ext, intros i xi,
unfold has_one.one,
rw mul_hom_of_of,
exact of_eq_of_graded_monoid_eq (one_mul $ graded_monoid.mk i xi),
end
private lemma mul_one (x : ⨁ i, A i) : x * 1 = x :=
suffices (mul_hom A).flip 1 = add_monoid_hom.id (⨁ i, A i),
from add_monoid_hom.congr_fun this x,
begin
apply add_hom_ext, intros i xi,
unfold has_one.one,
rw [flip_apply, mul_hom_of_of],
exact of_eq_of_graded_monoid_eq (mul_one $ graded_monoid.mk i xi),
end
private lemma mul_assoc (a b c : ⨁ i, A i) : a * b * c = a * (b * c) :=
suffices (mul_hom A).comp_hom.comp (mul_hom A) -- `λ a b c, a * b * c` as a bundled hom
= (add_monoid_hom.comp_hom flip_hom $ -- `λ a b c, a * (b * c)` as a bundled hom
(mul_hom A).flip.comp_hom.comp (mul_hom A)).flip,
from add_monoid_hom.congr_fun (add_monoid_hom.congr_fun (add_monoid_hom.congr_fun this a) b) c,
begin
ext ai ax bi bx ci cx : 6,
dsimp only [coe_comp, function.comp_app, comp_hom_apply_apply, flip_apply, flip_hom_apply],
rw [mul_hom_of_of, mul_hom_of_of, mul_hom_of_of, mul_hom_of_of],
exact of_eq_of_graded_monoid_eq (mul_assoc (graded_monoid.mk ai ax) ⟨bi, bx⟩ ⟨ci, cx⟩),
end
/-- The `semiring` structure derived from `gsemiring A`. -/
instance semiring : semiring (⨁ i, A i) :=
{ one := 1,
mul := (*),
zero := 0,
add := (+),
one_mul := one_mul A,
mul_one := mul_one A,
mul_assoc := mul_assoc A,
..direct_sum.non_unital_non_assoc_semiring _, }
lemma of_pow {i} (a : A i) (n : ℕ) :
of _ i a ^ n = of _ (n • i) (graded_monoid.gmonoid.gnpow _ a) :=
begin
induction n with n,
{ exact of_eq_of_graded_monoid_eq (pow_zero $ graded_monoid.mk _ a).symm, },
{ rw [pow_succ, n_ih, of_mul_of],
exact of_eq_of_graded_monoid_eq (pow_succ (graded_monoid.mk _ a) n).symm, },
end
lemma of_list_dprod {α} (l : list α) (fι : α → ι) (fA : Π a, A (fι a)) :
of A _ (l.dprod fι fA) = (l.map $ λ a, of A (fι a) (fA a)).prod :=
begin
induction l,
{ simp only [list.map_nil, list.prod_nil, list.dprod_nil],
refl },
{ simp only [list.map_cons, list.prod_cons, list.dprod_cons, ←l_ih, direct_sum.of_mul_of],
refl },
end
lemma list_prod_of_fn_of_eq_dprod (n : ℕ) (fι : fin n → ι) (fA : Π a, A (fι a)) :
(list.of_fn $ λ a, of A (fι a) (fA a)).prod = of A _ ((list.fin_range n).dprod fι fA) :=
by rw [list.of_fn_eq_map, of_list_dprod]
open_locale big_operators
/-- A heavily unfolded version of the definition of multiplication -/
lemma mul_eq_sum_support_ghas_mul
[Π (i : ι) (x : A i), decidable (x ≠ 0)] (a a' : ⨁ i, A i) :
a * a' =
∑ (ij : ι × ι) in (dfinsupp.support a).product (dfinsupp.support a'),
direct_sum.of _ _ (graded_monoid.ghas_mul.mul (a ij.fst) (a' ij.snd)) :=
begin
change direct_sum.mul_hom _ a a' = _,
dsimp [direct_sum.mul_hom, direct_sum.to_add_monoid, dfinsupp.lift_add_hom_apply],
simp only [dfinsupp.sum_add_hom_apply, dfinsupp.sum, dfinsupp.finset_sum_apply,
add_monoid_hom.coe_sum, finset.sum_apply, add_monoid_hom.flip_apply,
add_monoid_hom.comp_hom_apply_apply, add_monoid_hom.comp_apply,
direct_sum.gmul_hom_apply_apply],
rw finset.sum_product,
end
end semiring
section comm_semiring
variables [Π i, add_comm_monoid (A i)] [add_comm_monoid ι] [gcomm_semiring A]
private lemma mul_comm (a b : ⨁ i, A i) : a * b = b * a :=
suffices mul_hom A = (mul_hom A).flip,
from add_monoid_hom.congr_fun (add_monoid_hom.congr_fun this a) b,
begin
apply add_hom_ext, intros ai ax, apply add_hom_ext, intros bi bx,
rw [add_monoid_hom.flip_apply, mul_hom_of_of, mul_hom_of_of],
exact of_eq_of_graded_monoid_eq (gcomm_semiring.mul_comm ⟨ai, ax⟩ ⟨bi, bx⟩),
end
/-- The `comm_semiring` structure derived from `gcomm_semiring A`. -/
instance comm_semiring : comm_semiring (⨁ i, A i) :=
{ one := 1,
mul := (*),
zero := 0,
add := (+),
mul_comm := mul_comm A,
..direct_sum.semiring _, }
end comm_semiring
section ring
variables [Π i, add_comm_group (A i)] [add_comm_monoid ι] [gsemiring A]
/-- The `ring` derived from `gsemiring A`. -/
instance ring : ring (⨁ i, A i) :=
{ one := 1,
mul := (*),
zero := 0,
add := (+),
neg := has_neg.neg,
..(direct_sum.semiring _),
..(direct_sum.add_comm_group _), }
end ring
section comm_ring
variables [Π i, add_comm_group (A i)] [add_comm_monoid ι] [gcomm_semiring A]
/-- The `comm_ring` derived from `gcomm_semiring A`. -/
instance comm_ring : comm_ring (⨁ i, A i) :=
{ one := 1,
mul := (*),
zero := 0,
add := (+),
neg := has_neg.neg,
..(direct_sum.ring _),
..(direct_sum.comm_semiring _), }
end comm_ring
/-! ### Instances for `A 0`
The various `g*` instances are enough to promote the `add_comm_monoid (A 0)` structure to various
types of multiplicative structure.
-/
section grade_zero
section one
variables [has_zero ι] [graded_monoid.ghas_one A] [Π i, add_comm_monoid (A i)]
@[simp] lemma of_zero_one : of _ 0 (1 : A 0) = 1 := rfl
end one
section mul
variables [add_monoid ι] [Π i, add_comm_monoid (A i)] [gnon_unital_non_assoc_semiring A]
@[simp] lemma of_zero_smul {i} (a : A 0) (b : A i) : of _ _ (a • b) = of _ _ a * of _ _ b :=
(of_eq_of_graded_monoid_eq (graded_monoid.mk_zero_smul a b)).trans (of_mul_of _ _).symm
@[simp] lemma of_zero_mul (a b : A 0) : of _ 0 (a * b) = of _ 0 a * of _ 0 b:=
of_zero_smul A a b
instance grade_zero.non_unital_non_assoc_semiring : non_unital_non_assoc_semiring (A 0) :=
function.injective.non_unital_non_assoc_semiring (of A 0) dfinsupp.single_injective
(of A 0).map_zero (of A 0).map_add (of_zero_mul A)
instance grade_zero.smul_with_zero (i : ι) : smul_with_zero (A 0) (A i) :=
begin
letI := smul_with_zero.comp_hom (⨁ i, A i) (of A 0).to_zero_hom,
refine dfinsupp.single_injective.smul_with_zero (of A i).to_zero_hom (of_zero_smul A),
end
end mul
section semiring
variables [Π i, add_comm_monoid (A i)] [add_monoid ι] [gsemiring A]
/-- The `semiring` structure derived from `gsemiring A`. -/
instance grade_zero.semiring : semiring (A 0) :=
function.injective.semiring (of A 0) dfinsupp.single_injective
(of A 0).map_zero (of_zero_one A) (of A 0).map_add (of_zero_mul A)
/-- `of A 0` is a `ring_hom`, using the `direct_sum.grade_zero.semiring` structure. -/
def of_zero_ring_hom : A 0 →+* (⨁ i, A i) :=
{ map_one' := of_zero_one A, map_mul' := of_zero_mul A, ..(of _ 0) }
/-- Each grade `A i` derives a `A 0`-module structure from `gsemiring A`. Note that this results
in an overall `module (A 0) (⨁ i, A i)` structure via `direct_sum.module`.
-/
instance grade_zero.module {i} : module (A 0) (A i) :=
begin
letI := module.comp_hom (⨁ i, A i) (of_zero_ring_hom A),
exact dfinsupp.single_injective.module (A 0) (of A i) (λ a, of_zero_smul A a),
end
end semiring
section comm_semiring
variables [Π i, add_comm_monoid (A i)] [add_comm_monoid ι] [gcomm_semiring A]
/-- The `comm_semiring` structure derived from `gcomm_semiring A`. -/
instance grade_zero.comm_semiring : comm_semiring (A 0) :=
function.injective.comm_semiring (of A 0) dfinsupp.single_injective
(of A 0).map_zero (of_zero_one A) (of A 0).map_add (of_zero_mul A)
end comm_semiring
section ring
variables [Π i, add_comm_group (A i)] [add_comm_monoid ι] [gsemiring A]
/-- The `ring` derived from `gsemiring A`. -/
instance grade_zero.ring : ring (A 0) :=
function.injective.ring (of A 0) dfinsupp.single_injective
(of A 0).map_zero (of_zero_one A) (of A 0).map_add (of_zero_mul A)
(of A 0).map_neg (of A 0).map_sub
end ring
section comm_ring
variables [Π i, add_comm_group (A i)] [add_comm_monoid ι] [gcomm_semiring A]
/-- The `comm_ring` derived from `gcomm_semiring A`. -/
instance grade_zero.comm_ring : comm_ring (A 0) :=
function.injective.comm_ring (of A 0) dfinsupp.single_injective
(of A 0).map_zero (of_zero_one A) (of A 0).map_add (of_zero_mul A)
(of A 0).map_neg (of A 0).map_sub
end comm_ring
end grade_zero
section to_semiring
variables {R : Type*} [Π i, add_comm_monoid (A i)] [add_monoid ι] [gsemiring A] [semiring R]
variables {A}
/-- If two ring homomorphisms from `⨁ i, A i` are equal on each `of A i y`,
then they are equal.
See note [partially-applied ext lemmas]. -/
@[ext]
lemma ring_hom_ext' ⦃F G : (⨁ i, A i) →+* R⦄
(h : ∀ i, (↑F : _ →+ R).comp (of A i) = (↑G : _ →+ R).comp (of A i)) : F = G :=
ring_hom.coe_add_monoid_hom_injective $ direct_sum.add_hom_ext' h
/-- Two `ring_hom`s out of a direct sum are equal if they agree on the generators. -/
lemma ring_hom_ext ⦃f g : (⨁ i, A i) →+* R⦄ (h : ∀ i x, f (of A i x) = g (of A i x)) :
f = g :=
ring_hom_ext' $ λ i, add_monoid_hom.ext $ h i
/-- A family of `add_monoid_hom`s preserving `direct_sum.ghas_one.one` and `direct_sum.ghas_mul.mul`
describes a `ring_hom`s on `⨁ i, A i`. This is a stronger version of `direct_sum.to_monoid`.
Of particular interest is the case when `A i` are bundled subojects, `f` is the family of
coercions such as `add_submonoid.subtype (A i)`, and the `[gsemiring A]` structure originates from
`direct_sum.gsemiring.of_add_submonoids`, in which case the proofs about `ghas_one` and `ghas_mul`
can be discharged by `rfl`. -/
@[simps]
def to_semiring
(f : Π i, A i →+ R) (hone : f _ (graded_monoid.ghas_one.one) = 1)
(hmul : ∀ {i j} (ai : A i) (aj : A j), f _ (graded_monoid.ghas_mul.mul ai aj) = f _ ai * f _ aj) :
(⨁ i, A i) →+* R :=
{ to_fun := to_add_monoid f,
map_one' := begin
change (to_add_monoid f) (of _ 0 _) = 1,
rw to_add_monoid_of,
exact hone
end,
map_mul' := begin
rw (to_add_monoid f).map_mul_iff,
ext xi xv yi yv : 4,
show to_add_monoid f (of A xi xv * of A yi yv) =
to_add_monoid f (of A xi xv) * to_add_monoid f (of A yi yv),
rw [of_mul_of, to_add_monoid_of, to_add_monoid_of, to_add_monoid_of],
exact hmul _ _,
end,
.. to_add_monoid f}
@[simp] lemma to_semiring_of (f : Π i, A i →+ R) (hone hmul) (i : ι) (x : A i) :
to_semiring f hone hmul (of _ i x) = f _ x :=
to_add_monoid_of f i x
@[simp] lemma to_semiring_coe_add_monoid_hom (f : Π i, A i →+ R) (hone hmul):
(to_semiring f hone hmul : (⨁ i, A i) →+ R) = to_add_monoid f := rfl
/-- Families of `add_monoid_hom`s preserving `direct_sum.ghas_one.one` and `direct_sum.ghas_mul.mul`
are isomorphic to `ring_hom`s on `⨁ i, A i`. This is a stronger version of `dfinsupp.lift_add_hom`.
-/
@[simps]
def lift_ring_hom :
{f : Π {i}, A i →+ R //
f (graded_monoid.ghas_one.one) = 1 ∧
∀ {i j} (ai : A i) (aj : A j), f (graded_monoid.ghas_mul.mul ai aj) = f ai * f aj} ≃
((⨁ i, A i) →+* R) :=
{ to_fun := λ f, to_semiring f.1 f.2.1 f.2.2,
inv_fun := λ F,
⟨λ i, (F : (⨁ i, A i) →+ R).comp (of _ i), begin
simp only [add_monoid_hom.comp_apply, ring_hom.coe_add_monoid_hom],
rw ←F.map_one,
refl
end, λ i j ai aj, begin
simp only [add_monoid_hom.comp_apply, ring_hom.coe_add_monoid_hom],
rw [←F.map_mul, of_mul_of],
end⟩,
left_inv := λ f, begin
ext xi xv,
exact to_add_monoid_of f.1 xi xv,
end,
right_inv := λ F, begin
apply ring_hom.coe_add_monoid_hom_injective,
ext xi xv,
simp only [ring_hom.coe_add_monoid_hom_mk,
direct_sum.to_add_monoid_of,
add_monoid_hom.mk_coe,
add_monoid_hom.comp_apply, to_semiring_coe_add_monoid_hom],
end}
end to_semiring
end direct_sum
/-! ### Concrete instances -/
section uniform
variables (ι)
/-- A direct sum of copies of a `semiring` inherits the multiplication structure. -/
instance non_unital_non_assoc_semiring.direct_sum_gnon_unital_non_assoc_semiring
{R : Type*} [add_monoid ι] [non_unital_non_assoc_semiring R] :
direct_sum.gnon_unital_non_assoc_semiring (λ i : ι, R) :=
{ mul_zero := λ i j, mul_zero,
zero_mul := λ i j, zero_mul,
mul_add := λ i j, mul_add,
add_mul := λ i j, add_mul,
..has_mul.ghas_mul ι }
/-- A direct sum of copies of a `semiring` inherits the multiplication structure. -/
instance semiring.direct_sum_gsemiring {R : Type*} [add_monoid ι] [semiring R] :
direct_sum.gsemiring (λ i : ι, R) :=
{ ..non_unital_non_assoc_semiring.direct_sum_gnon_unital_non_assoc_semiring ι, ..monoid.gmonoid ι }
open_locale direct_sum
-- To check `has_mul.ghas_mul_mul` matches
example {R : Type*} [add_monoid ι] [semiring R] (i j : ι) (a b : R) :
(direct_sum.of _ i a * direct_sum.of _ j b : ⨁ i, R) = direct_sum.of _ (i + j) (by exact a * b) :=
by rw [direct_sum.of_mul_of, has_mul.ghas_mul_mul]
/-- A direct sum of copies of a `comm_semiring` inherits the commutative multiplication structure.
-/
instance comm_semiring.direct_sum_gcomm_semiring {R : Type*} [add_comm_monoid ι] [comm_semiring R] :
direct_sum.gcomm_semiring (λ i : ι, R) :=
{ ..comm_monoid.gcomm_monoid ι, ..semiring.direct_sum_gsemiring ι }
end uniform
|
2bab92d575fba7c2b29145ec5a461404ec297e6f | 947b78d97130d56365ae2ec264df196ce769371a | /tests/lean/run/typeclass_metas_internal_goals3.lean | 8bb076e0bd29574b0f8e4a77e208a0d4a08f974e | [
"Apache-2.0"
] | permissive | shyamalschandra/lean4 | 27044812be8698f0c79147615b1d5090b9f4b037 | 6e7a883b21eaf62831e8111b251dc9b18f40e604 | refs/heads/master | 1,671,417,126,371 | 1,601,859,995,000 | 1,601,860,020,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 604 | lean | new_frontend
class Base (α : Type) := (u:Unit)
class Depends (α : Type) [Base α] := (u:Unit)
class Top := (u:Unit)
instance AllBase {α : Type} : Base α := {u:=()}
instance DependsNotConstrainingImplicit {α : Type} /- [Base α] -/ {_:Base α} : Depends α := {u:=()}
instance BaseAsImplicit₁ {α : Type} {_:Base α} [Depends α] : Top := {u:=()}
instance BaseAsInstImplicit {α : Type} [Base α] [Depends α] : Top := {u:=()}
instance BaseAsImplicit₂ {α : Type} {_:Base α} [Depends α] : Top := {u:=()}
axiom K : Type
instance BaseK : Base K := {u:=()}
set_option pp.all true
#synth Top
|
fdc6666a3f1055b4a85f1fdac33d75e2a6f300fa | a9d0fb7b0e4f802bd3857b803e6c5c23d87fef91 | /tests/lean/run/opt1.lean | c036a552231b44e6c2c4587fd30ab0b81c024b7f | [
"Apache-2.0"
] | permissive | soonhokong/lean-osx | 4a954262c780e404c1369d6c06516161d07fcb40 | 3670278342d2f4faa49d95b46d86642d7875b47c | refs/heads/master | 1,611,410,334,552 | 1,474,425,686,000 | 1,474,425,686,000 | 12,043,103 | 5 | 1 | null | null | null | null | UTF-8 | Lean | false | false | 442 | lean | vm_eval options.get_string options.mk `opt1 "<empty>"
vm_eval options.get_string (options.set_string options.mk `opt1 "val1") `opt1 "<empty>"
vm_eval if (options.mk = options.mk) then bool.tt else bool.ff
vm_eval if (options.mk = (options.set_string options.mk `opt1 "val1")) then bool.tt else bool.ff
vm_eval options.get_nat (options.set_nat options.mk `opt1 10) `opt1 0
vm_eval options.get_nat (options.set_nat options.mk `opt1 10) `opt2 0
|
86594cc7c4aeb9ee17b26e788251e6790e9556f5 | e39f04f6ff425fe3b3f5e26a8998b817d1dba80f | /data/finsupp.lean | acbb17bdf9a880b59b562488ec98a0e63d3c6a36 | [
"Apache-2.0"
] | permissive | kristychoi/mathlib | c504b5e8f84e272ea1d8966693c42de7523bf0ec | 257fd84fe98927ff4a5ffe044f68c4e9d235cc75 | refs/heads/master | 1,586,520,722,896 | 1,544,030,145,000 | 1,544,031,933,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 40,465 | 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
Type of functions with finite support.
Functions with finite support provide the basis for the following concrete instances:
* ℕ →₀ α: Polynomials (where α is a ring)
* (σ →₀ ℕ) →₀ α: Multivariate Polynomials (again α is a ring, and σ are variable names)
* α →₀ ℕ: Multisets
* α →₀ ℤ: Abelian groups freely generated by α
* β →₀ α: Linear combinations over β where α is the scalar ring
Most of the theory assumes that the range is a commutative monoid. This gives us the big sum
operator as a powerful way to construct `finsupp` elements.
A general advice is to not use α →₀ β directly, as the type class setup might not be fitting.
The best is to define a copy and select the instances best suited.
-/
import data.finset data.set.finite algebra.big_operators algebra.module
open finset
variables {α : Type*} {β : Type*} {γ : Type*} {δ : Type*} {ι : Type*}
{α₁ : Type*} {α₂ : Type*} {β₁ : Type*} {β₂ : Type*}
reserve infix ` →₀ `:25
/-- `finsupp α β`, denoted `α →₀ β`, is the type of functions `f : α → β` such that
`f x = 0` for all but finitely many `x`. -/
structure finsupp (α : Type*) (β : Type*) [has_zero β] :=
(support : finset α)
(to_fun : α → β)
(mem_support_to_fun : ∀a, a ∈ support ↔ to_fun a ≠ 0)
infix →₀ := finsupp
namespace finsupp
section basic
variable [has_zero β]
instance : has_coe_to_fun (α →₀ β) := ⟨λ_, α → β, finsupp.to_fun⟩
instance : has_zero (α →₀ β) := ⟨⟨∅, (λ_, 0), λ _, ⟨false.elim, λ H, H rfl⟩⟩⟩
@[simp] lemma zero_apply {a : α} : (0 : α →₀ β) a = 0 := rfl
@[simp] lemma support_zero : (0 : α →₀ β).support = ∅ := rfl
instance : inhabited (α →₀ β) := ⟨0⟩
@[simp] lemma mem_support_iff {f : α →₀ β} : ∀{a:α}, a ∈ f.support ↔ f a ≠ 0 :=
f.mem_support_to_fun
lemma not_mem_support_iff {f : α →₀ β} {a} : a ∉ f.support ↔ f a = 0 :=
by haveI := classical.dec; exact not_iff_comm.1 mem_support_iff.symm
@[extensionality]
lemma ext : ∀{f g : α →₀ β}, (∀a, f a = g a) → f = g
| ⟨s, f, hf⟩ ⟨t, g, hg⟩ h :=
begin
have : f = g, { funext a, exact h a },
subst this,
have : s = t, { ext a, exact (hf a).trans (hg a).symm },
subst this
end
@[simp] lemma support_eq_empty [decidable_eq β] {f : α →₀ β} : f.support = ∅ ↔ f = 0 :=
⟨assume h, ext $ assume a, by_contradiction $ λ H, (finset.ext.1 h a).1 $
mem_support_iff.2 H, by rintro rfl; refl⟩
instance [decidable_eq α] [decidable_eq β] : decidable_eq (α →₀ β) :=
assume f g, decidable_of_iff (f.support = g.support ∧ (∀a∈f.support, f a = g a))
⟨assume ⟨h₁, h₂⟩, ext $ assume a,
if h : a ∈ f.support then h₂ a h else
have hf : f a = 0, by rwa [mem_support_iff, not_not] at h,
have hg : g a = 0, by rwa [h₁, mem_support_iff, not_not] at h,
by rw [hf, hg],
by rintro rfl; exact ⟨rfl, λ _ _, rfl⟩⟩
lemma finite_supp (f : α →₀ β) : set.finite {a | f a ≠ 0} :=
⟨set.fintype_of_finset f.support (λ _, mem_support_iff)⟩
lemma support_subset_iff {s : set α} {f : α →₀ β} [decidable_eq α] :
↑f.support ⊆ s ↔ (∀a∉s, f a = 0) :=
by simp only [set.subset_def, mem_coe, mem_support_iff];
exact forall_congr (assume a, @not_imp_comm _ _ (classical.dec _) (classical.dec _))
end basic
section single
variables [decidable_eq α] [decidable_eq β] [has_zero β] {a a' : α} {b : β}
/-- `single a b` is the finitely supported function which has
value `b` at `a` and zero otherwise. -/
def single (a : α) (b : β) : α →₀ β :=
⟨if b = 0 then ∅ else finset.singleton a, λ a', if a = a' then b else 0, λ a', begin
by_cases hb : b = 0; by_cases a = a';
simp only [hb, h, if_pos, if_false, mem_singleton],
{ exact ⟨false.elim, λ H, H rfl⟩ },
{ exact ⟨false.elim, λ H, H rfl⟩ },
{ exact ⟨λ _, hb, λ _, rfl⟩ },
{ exact ⟨λ H _, h H.symm, λ H, (H rfl).elim⟩ }
end⟩
lemma single_apply : (single a b : α →₀ β) a' = if a = a' then b else 0 := rfl
@[simp] lemma single_eq_same : (single a b : α →₀ β) a = b := if_pos rfl
@[simp] lemma single_eq_of_ne (h : a ≠ a') : (single a b : α →₀ β) a' = 0 := if_neg h
@[simp] lemma single_zero : (single a 0 : α →₀ β) = 0 :=
ext $ assume a',
begin
by_cases h : a = a',
{ rw [h, single_eq_same, zero_apply] },
{ rw [single_eq_of_ne h, zero_apply] }
end
lemma support_single_ne_zero (hb : b ≠ 0) : (single a b).support = {a} :=
if_neg hb
lemma support_single_subset : (single a b).support ⊆ {a} :=
show ite _ _ _ ⊆ _, by split_ifs; [exact empty_subset _, exact subset.refl _]
end single
section on_finset
variables [decidable_eq β] [has_zero β]
/-- `on_finset s f hf` is the finsupp function representing `f` restricted to the set `s`.
The function needs to be 0 outside of `s`. Use this when the set needs filtered anyway, otherwise
often better set representation is available. -/
def on_finset (s : finset α) (f : α → β) (hf : ∀a, f a ≠ 0 → a ∈ s) : α →₀ β :=
⟨s.filter (λa, f a ≠ 0), f,
assume a, classical.by_cases
(assume h : f a = 0, by rw mem_filter; exact ⟨and.right, λ H, (H h).elim⟩)
(assume h : f a ≠ 0, by rw mem_filter; simp only [iff_true_intro h, hf a h, true_and])⟩
@[simp] lemma on_finset_apply {s : finset α} {f : α → β} {hf a} :
(on_finset s f hf : α →₀ β) a = f a :=
rfl
@[simp] lemma support_on_finset_subset {s : finset α} {f : α → β} {hf} :
(on_finset s f hf).support ⊆ s := filter_subset _
end on_finset
section map_range
variables [has_zero β₁] [has_zero β₂] [decidable_eq β₂]
/-- The composition of `f : β₁ → β₂` and `g : α →₀ β₁` is
`map_range f hf g : α →₀ β₂`, well defined when `f 0 = 0`. -/
def map_range (f : β₁ → β₂) (hf : f 0 = 0) (g : α →₀ β₁) : α →₀ β₂ :=
on_finset g.support (f ∘ g) $
assume a, by rw [mem_support_iff, not_imp_not]; exact λ H, (congr_arg f H).trans hf
@[simp] lemma map_range_apply {f : β₁ → β₂} {hf : f 0 = 0} {g : α →₀ β₁} {a : α} :
map_range f hf g a = f (g a) :=
rfl
@[simp] lemma map_range_zero {f : β₁ → β₂} {hf : f 0 = 0} : map_range f hf (0 : α →₀ β₁) = 0 :=
finsupp.ext $ λ a, by simp [hf]
lemma support_map_range {f : β₁ → β₂} {hf : f 0 = 0} {g : α →₀ β₁} :
(map_range f hf g).support ⊆ g.support :=
support_on_finset_subset
variables [decidable_eq α] [decidable_eq β₁]
@[simp] lemma map_range_single {f : β₁ → β₂} {hf : f 0 = 0} {a : α} {b : β₁} :
map_range f hf (single a b) = single a (f b) :=
finsupp.ext $ λ a', show f (ite _ _ _) = ite _ _ _, by split_ifs; [refl, exact hf]
end map_range
section zip_with
variables [has_zero β] [has_zero β₁] [has_zero β₂] [decidable_eq α] [decidable_eq β]
/-- `zip_with f hf g₁ g₂` is the finitely supported function satisfying
`zip_with f hf g₁ g₂ a = f (g₁ a) (g₂ a)`, and well defined when `f 0 0 = 0`. -/
def zip_with (f : β₁ → β₂ → β) (hf : f 0 0 = 0) (g₁ : α →₀ β₁) (g₂ : α →₀ β₂) : (α →₀ β) :=
on_finset (g₁.support ∪ g₂.support) (λa, f (g₁ a) (g₂ a)) $ λ a H, begin
haveI := classical.dec_eq β₁,
simp only [mem_union, mem_support_iff, ne], rw [← not_and_distrib],
rintro ⟨h₁, h₂⟩, rw [h₁, h₂] at H, exact H hf
end
@[simp] lemma zip_with_apply
{f : β₁ → β₂ → β} {hf : f 0 0 = 0} {g₁ : α →₀ β₁} {g₂ : α →₀ β₂} {a : α} :
zip_with f hf g₁ g₂ a = f (g₁ a) (g₂ a) := rfl
lemma support_zip_with {f : β₁ → β₂ → β} {hf : f 0 0 = 0} {g₁ : α →₀ β₁} {g₂ : α →₀ β₂} :
(zip_with f hf g₁ g₂).support ⊆ g₁.support ∪ g₂.support :=
support_on_finset_subset
end zip_with
section erase
variables [decidable_eq α] [decidable_eq β]
def erase [has_zero β] (a : α) (f : α →₀ β) : α →₀ β :=
⟨f.support.erase a, (λa', if a' = a then 0 else f a'),
assume a', by rw [mem_erase, mem_support_iff]; split_ifs;
[exact ⟨λ H _, H.1 h, λ H, (H rfl).elim⟩,
exact and_iff_right h]⟩
@[simp] lemma support_erase [has_zero β] {a : α} {f : α →₀ β} :
(f.erase a).support = f.support.erase a :=
rfl
@[simp] lemma erase_same [has_zero β] {a : α} {f : α →₀ β} : (f.erase a) a = 0 :=
if_pos rfl
@[simp] lemma erase_ne [has_zero β] {a a' : α} {f : α →₀ β} (h : a' ≠ a) : (f.erase a) a' = f a' :=
if_neg h
end erase
-- [to_additive finsupp.sum] for finsupp.prod doesn't work, the equation lemmas are not generated
/-- `sum f g` is the sum of `g a (f a)` over the support of `f`. -/
def sum [has_zero β] [add_comm_monoid γ] (f : α →₀ β) (g : α → β → γ) : γ :=
f.support.sum (λa, g a (f a))
/-- `prod f g` is the product of `g a (f a)` over the support of `f`. -/
@[to_additive finsupp.sum]
def prod [has_zero β] [comm_monoid γ] (f : α →₀ β) (g : α → β → γ) : γ :=
f.support.prod (λa, g a (f a))
attribute [to_additive finsupp.sum.equations._eqn_1] finsupp.prod.equations._eqn_1
@[to_additive finsupp.sum_map_range_index]
lemma prod_map_range_index [has_zero β₁] [has_zero β₂] [comm_monoid γ] [decidable_eq β₂]
{f : β₁ → β₂} {hf : f 0 = 0} {g : α →₀ β₁} {h : α → β₂ → γ} (h0 : ∀a, h a 0 = 1) :
(map_range f hf g).prod h = g.prod (λa b, h a (f b)) :=
finset.prod_subset support_map_range $ λ _ _ H,
by rw [not_mem_support_iff.1 H, h0]
@[to_additive finsupp.sum_zero_index]
lemma prod_zero_index [add_comm_monoid β] [comm_monoid γ] {h : α → β → γ} :
(0 : α →₀ β).prod h = 1 := rfl
section decidable
variables [decidable_eq α] [decidable_eq β]
section add_monoid
variables [add_monoid β]
@[to_additive finsupp.sum_single_index]
lemma prod_single_index [comm_monoid γ] {a : α} {b : β} {h : α → β → γ} (h_zero : h a 0 = 1) :
(single a b).prod h = h a b :=
begin
by_cases h : b = 0,
{ simp only [h, h_zero, single_zero]; refl },
{ simp only [finsupp.prod, support_single_ne_zero h, insert_empty_eq_singleton,
prod_singleton, single_eq_same] }
end
instance : has_add (α →₀ β) := ⟨zip_with (+) (add_zero 0)⟩
@[simp] lemma add_apply {g₁ g₂ : α →₀ β} {a : α} : (g₁ + g₂) a = g₁ a + g₂ a :=
rfl
lemma support_add {g₁ g₂ : α →₀ β} : (g₁ + g₂).support ⊆ g₁.support ∪ g₂.support :=
support_zip_with
lemma support_add_eq {g₁ g₂ : α →₀ β} (h : disjoint g₁.support g₂.support):
(g₁ + g₂).support = g₁.support ∪ g₂.support :=
le_antisymm support_zip_with $ assume a ha,
(finset.mem_union.1 ha).elim
(assume ha, have a ∉ g₂.support, from disjoint_left.1 h ha,
by simp only [mem_support_iff, not_not] at *;
simpa only [add_apply, this, add_zero])
(assume ha, have a ∉ g₁.support, from disjoint_right.1 h ha,
by simp only [mem_support_iff, not_not] at *;
simpa only [add_apply, this, zero_add])
@[simp] lemma single_add {a : α} {b₁ b₂ : β} : single a (b₁ + b₂) = single a b₁ + single a b₂ :=
ext $ assume a',
begin
by_cases h : a = a',
{ rw [h, add_apply, single_eq_same, single_eq_same, single_eq_same] },
{ rw [add_apply, single_eq_of_ne h, single_eq_of_ne h, single_eq_of_ne h, zero_add] }
end
instance : add_monoid (α →₀ β) :=
{ add_monoid .
zero := 0,
add := (+),
add_assoc := assume ⟨s, f, hf⟩ ⟨t, g, hg⟩ ⟨u, h, hh⟩, ext $ assume a, add_assoc _ _ _,
zero_add := assume ⟨s, f, hf⟩, ext $ assume a, zero_add _,
add_zero := assume ⟨s, f, hf⟩, ext $ assume a, add_zero _ }
lemma single_add_erase {a : α} {f : α →₀ β} : single a (f a) + f.erase a = f :=
ext $ λ a',
if h : a = a' then by subst h; simp only [add_apply, single_eq_same, erase_same, add_zero]
else by simp only [add_apply, single_eq_of_ne h, zero_add, erase_ne (ne.symm h)]
lemma erase_add_single {a : α} {f : α →₀ β} : f.erase a + single a (f a) = f :=
ext $ λ a',
if h : a = a' then by subst h; simp only [add_apply, single_eq_same, erase_same, zero_add]
else by simp only [add_apply, single_eq_of_ne h, add_zero, erase_ne (ne.symm h)]
@[elab_as_eliminator]
protected theorem induction {p : (α →₀ β) → Prop} (f : α →₀ β)
(h0 : p 0) (ha : ∀a b (f : α →₀ β), a ∉ f.support → b ≠ 0 → p f → p (single a b + f)) :
p f :=
suffices ∀s (f : α →₀ β), f.support = s → p f, from this _ _ rfl,
assume s, finset.induction_on s (λ f hf, by rwa [support_eq_empty.1 hf]) $
assume a s has ih f hf,
suffices p (single a (f a) + f.erase a), by rwa [single_add_erase] at this,
begin
apply ha,
{ rw [support_erase, mem_erase], exact λ H, H.1 rfl },
{ rw [← mem_support_iff, hf], exact mem_insert_self _ _ },
{ apply ih _ _,
rw [support_erase, hf, finset.erase_insert has] }
end
lemma induction₂ {p : (α →₀ β) → Prop} (f : α →₀ β)
(h0 : p 0) (ha : ∀a b (f : α →₀ β), a ∉ f.support → b ≠ 0 → p f → p (f + single a b)) :
p f :=
suffices ∀s (f : α →₀ β), f.support = s → p f, from this _ _ rfl,
assume s, finset.induction_on s (λ f hf, by rwa [support_eq_empty.1 hf]) $
assume a s has ih f hf,
suffices p (f.erase a + single a (f a)), by rwa [erase_add_single] at this,
begin
apply ha,
{ rw [support_erase, mem_erase], exact λ H, H.1 rfl },
{ rw [← mem_support_iff, hf], exact mem_insert_self _ _ },
{ apply ih _ _,
rw [support_erase, hf, finset.erase_insert has] }
end
lemma map_range_add [decidable_eq β₁] [decidable_eq β₂] [add_monoid β₁] [add_monoid β₂]
{f : β₁ → β₂} {hf : f 0 = 0} (hf' : ∀ x y, f (x + y) = f x + f y) (v₁ v₂ : α →₀ β₁) :
map_range f hf (v₁ + v₂) = map_range f hf v₁ + map_range f hf v₂ :=
finsupp.ext $ λ a, by simp [hf']
end add_monoid
instance [add_comm_monoid β] : add_comm_monoid (α →₀ β) :=
{ add_comm := assume ⟨s, f, _⟩ ⟨t, g, _⟩, ext $ assume a, add_comm _ _,
.. finsupp.add_monoid }
instance [add_group β] : add_group (α →₀ β) :=
{ neg := map_range (has_neg.neg) neg_zero,
add_left_neg := assume ⟨s, f, _⟩, ext $ assume x, add_left_neg _,
.. finsupp.add_monoid }
lemma single_multiset_sum [add_comm_monoid β] [decidable_eq α] [decidable_eq β]
(s : multiset β) (a : α) : single a s.sum = (s.map (single a)).sum :=
multiset.induction_on s single_zero $ λ a s ih,
by rw [multiset.sum_cons, single_add, ih, multiset.map_cons, multiset.sum_cons]
lemma single_finset_sum [add_comm_monoid β] [decidable_eq α] [decidable_eq β]
(s : finset γ) (f : γ → β) (a : α) : single a (s.sum f) = s.sum (λb, single a (f b)) :=
begin
transitivity,
apply single_multiset_sum,
rw [multiset.map_map],
refl
end
lemma single_sum [has_zero γ] [add_comm_monoid β] [decidable_eq α] [decidable_eq β]
(s : δ →₀ γ) (f : δ → γ → β) (a : α) : single a (s.sum f) = s.sum (λd c, single a (f d c)) :=
single_finset_sum _ _ _
@[to_additive finsupp.sum_neg_index]
lemma prod_neg_index [add_group β] [comm_monoid γ]
{g : α →₀ β} {h : α → β → γ} (h0 : ∀a, h a 0 = 1) :
(-g).prod h = g.prod (λa b, h a (- b)) :=
prod_map_range_index h0
@[simp] lemma neg_apply [add_group β] {g : α →₀ β} {a : α} : (- g) a = - g a := rfl
@[simp] lemma sub_apply [add_group β] {g₁ g₂ : α →₀ β} {a : α} : (g₁ - g₂) a = g₁ a - g₂ a := rfl
@[simp] lemma support_neg [add_group β] {f : α →₀ β} : support (-f) = support f :=
finset.subset.antisymm
support_map_range
(calc support f = support (- (- f)) : congr_arg support (neg_neg _).symm
... ⊆ support (- f) : support_map_range)
instance [add_comm_group β] : add_comm_group (α →₀ β) :=
{ add_comm := add_comm, ..finsupp.add_group }
@[simp] lemma sum_apply [has_zero β₁] [add_comm_monoid β]
{f : α₁ →₀ β₁} {g : α₁ → β₁ → α →₀ β} {a₂ : α} :
(f.sum g) a₂ = f.sum (λa₁ b, g a₁ b a₂) :=
(finset.sum_hom (λf : α →₀ β, f a₂) rfl (assume a b, rfl)).symm
lemma support_sum [has_zero β₁] [add_comm_monoid β]
{f : α₁ →₀ β₁} {g : α₁ → β₁ → (α →₀ β)} :
(f.sum g).support ⊆ f.support.bind (λa, (g a (f a)).support) :=
have ∀a₁ : α, f.sum (λ (a : α₁) (b : β₁), (g a b) a₁) ≠ 0 →
(∃ (a : α₁), f a ≠ 0 ∧ ¬ (g a (f a)) a₁ = 0),
from assume a₁ h,
let ⟨a, ha, ne⟩ := finset.exists_ne_zero_of_sum_ne_zero h in
⟨a, mem_support_iff.mp ha, ne⟩,
by simpa only [finset.subset_iff, mem_support_iff, finset.mem_bind, sum_apply, exists_prop] using this
@[simp] lemma sum_zero [add_comm_monoid β] [add_comm_monoid γ] {f : α →₀ β} :
f.sum (λa b, (0 : γ)) = 0 :=
finset.sum_const_zero
@[simp] lemma sum_add [add_comm_monoid β] [add_comm_monoid γ] {f : α →₀ β}
{h₁ h₂ : α → β → γ} :
f.sum (λa b, h₁ a b + h₂ a b) = f.sum h₁ + f.sum h₂ :=
finset.sum_add_distrib
@[simp] lemma sum_neg [add_comm_monoid β] [add_comm_group γ] {f : α →₀ β}
{h : α → β → γ} : f.sum (λa b, - h a b) = - f.sum h :=
finset.sum_hom (@has_neg.neg γ _) neg_zero (assume a b, neg_add _ _)
@[simp] lemma sum_sub [add_comm_monoid β] [add_comm_group γ] {f : α →₀ β}
{h₁ h₂ : α → β → γ} :
f.sum (λa b, h₁ a b - h₂ a b) = f.sum h₁ - f.sum h₂ :=
by rw [sub_eq_add_neg, ←sum_neg, ←sum_add]; refl
@[simp] lemma sum_single [add_comm_monoid β] (f : α →₀ β) :
f.sum single = f :=
have ∀a:α, f.sum (λa' b, ite (a' = a) b 0) =
({a} : finset α).sum (λa', ite (a' = a) (f a') 0),
begin
intro a,
by_cases h : a ∈ f.support,
{ have : (finset.singleton a : finset α) ⊆ f.support,
{ simpa only [finset.subset_iff, mem_singleton, forall_eq] },
refine (finset.sum_subset this (λ _ _ H, _)).symm,
exact if_neg (mt mem_singleton.2 H) },
{ transitivity (f.support.sum (λa, (0 : β))),
{ refine (finset.sum_congr rfl $ λ a' ha', if_neg _),
rintro rfl, exact h ha' },
{ rw [sum_const_zero, insert_empty_eq_singleton, sum_singleton,
if_pos rfl, not_mem_support_iff.1 h] } }
end,
ext $ assume a, by simp only [sum_apply, single_apply, this,
insert_empty_eq_singleton, sum_singleton, if_pos]
@[to_additive finsupp.sum_add_index]
lemma prod_add_index [add_comm_monoid β] [comm_monoid γ] {f g : α →₀ β}
{h : α → β → γ} (h_zero : ∀a, h a 0 = 1) (h_add : ∀a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :
(f + g).prod h = f.prod h * g.prod h :=
have f_eq : (f.support ∪ g.support).prod (λa, h a (f a)) = f.prod h,
from (finset.prod_subset (finset.subset_union_left _ _) $
by intros _ _ H; rw [not_mem_support_iff.1 H, h_zero]).symm,
have g_eq : (f.support ∪ g.support).prod (λa, h a (g a)) = g.prod h,
from (finset.prod_subset (finset.subset_union_right _ _) $
by intros _ _ H; rw [not_mem_support_iff.1 H, h_zero]).symm,
calc (f + g).support.prod (λa, h a ((f + g) a)) =
(f.support ∪ g.support).prod (λa, h a ((f + g) a)) :
finset.prod_subset support_add $
by intros _ _ H; rw [not_mem_support_iff.1 H, h_zero]
... = (f.support ∪ g.support).prod (λa, h a (f a)) *
(f.support ∪ g.support).prod (λa, h a (g a)) :
by simp only [add_apply, h_add, finset.prod_mul_distrib]
... = _ : by rw [f_eq, g_eq]
lemma sum_sub_index [add_comm_group β] [add_comm_group γ] {f g : α →₀ β}
{h : α → β → γ} (h_sub : ∀a b₁ b₂, h a (b₁ - b₂) = h a b₁ - h a b₂) :
(f - g).sum h = f.sum h - g.sum h :=
have h_zero : ∀a, h a 0 = 0,
from assume a,
have h a (0 - 0) = h a 0 - h a 0, from h_sub a 0 0,
by simpa only [sub_self] using this,
have h_neg : ∀a b, h a (- b) = - h a b,
from assume a b,
have h a (0 - b) = h a 0 - h a b, from h_sub a 0 b,
by simpa only [h_zero, zero_sub] using this,
have h_add : ∀a b₁ b₂, h a (b₁ + b₂) = h a b₁ + h a b₂,
from assume a b₁ b₂,
have h a (b₁ - (- b₂)) = h a b₁ - h a (- b₂), from h_sub a b₁ (-b₂),
by simpa only [h_neg, sub_neg_eq_add] using this,
calc (f - g).sum h = (f + - g).sum h : rfl
... = f.sum h + - g.sum h : by simp only [sum_add_index h_zero h_add, sum_neg_index h_zero, h_neg, sum_neg]
... = f.sum h - g.sum h : rfl
@[to_additive finsupp.sum_finset_sum_index]
lemma prod_finset_sum_index [add_comm_monoid β] [comm_monoid γ] [decidable_eq ι]
{s : finset ι} {g : ι → α →₀ β}
{h : α → β → γ} (h_zero : ∀a, h a 0 = 1) (h_add : ∀a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂):
s.prod (λi, (g i).prod h) = (s.sum g).prod h :=
finset.induction_on s rfl $ λ a s has ih,
by rw [prod_insert has, ih, sum_insert has, prod_add_index h_zero h_add]
@[to_additive finsupp.sum_sum_index]
lemma prod_sum_index
[decidable_eq α₁] [add_comm_monoid β₁] [add_comm_monoid β] [comm_monoid γ]
{f : α₁ →₀ β₁} {g : α₁ → β₁ → α →₀ β}
{h : α → β → γ} (h_zero : ∀a, h a 0 = 1) (h_add : ∀a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂):
(f.sum g).prod h = f.prod (λa b, (g a b).prod h) :=
(prod_finset_sum_index h_zero h_add).symm
lemma multiset_sum_sum_index
[decidable_eq α] [decidable_eq β] [add_comm_monoid β] [add_comm_monoid γ]
(f : multiset (α →₀ β)) (h : α → β → γ)
(h₀ : ∀a, h a 0 = 0) (h₁ : ∀ (a : α) (b₁ b₂ : β), h a (b₁ + b₂) = h a b₁ + h a b₂) :
(f.sum.sum h) = (f.map $ λg:α →₀ β, g.sum h).sum :=
multiset.induction_on f rfl $ assume a s ih,
by rw [multiset.sum_cons, multiset.map_cons, multiset.sum_cons, sum_add_index h₀ h₁, ih]
lemma multiset_map_sum [has_zero β] {f : α →₀ β} {m : γ → δ} {h : α → β → multiset γ} :
multiset.map m (f.sum h) = f.sum (λa b, (h a b).map m) :=
(finset.sum_hom _ (multiset.map_zero m) (multiset.map_add m)).symm
lemma multiset_sum_sum [has_zero β] [add_comm_monoid γ] {f : α →₀ β} {h : α → β → multiset γ} :
multiset.sum (f.sum h) = f.sum (λa b, multiset.sum (h a b)) :=
begin
refine (finset.sum_hom multiset.sum _ _).symm,
exact multiset.sum_zero,
exact multiset.sum_add
end
section map_domain
variables [decidable_eq α₁] [decidable_eq α₂] [add_comm_monoid β] {v v₁ v₂ : α →₀ β}
/-- Given `f : α₁ → α₂` and `v : α₁ →₀ β`, `map_domain f v : α₂ →₀ β`
is the finitely supported function whose value at `a : α₂` is the sum
of `v x` over all `x` such that `f x = a`. -/
def map_domain (f : α₁ → α₂) (v : α₁ →₀ β) : α₂ →₀ β :=
v.sum $ λa, single (f a)
lemma map_domain_id : map_domain id v = v := sum_single _
lemma map_domain_comp {f : α → α₁} {g : α₁ → α₂} :
map_domain (g ∘ f) v = map_domain g (map_domain f v) :=
begin
refine ((sum_sum_index _ _).trans _).symm,
{ intros, exact single_zero },
{ intros, exact single_add },
refine sum_congr rfl (λ _ _, sum_single_index _),
{ exact single_zero }
end
lemma map_domain_single {f : α → α₁} {a : α} {b : β} : map_domain f (single a b) = single (f a) b :=
sum_single_index single_zero
@[simp] lemma map_domain_zero {f : α → α₂} : map_domain f 0 = (0 : α₂ →₀ β) :=
sum_zero_index
lemma map_domain_congr {f g : α → α₂} (h : ∀x∈v.support, f x = g x) :
v.map_domain f = v.map_domain g :=
finset.sum_congr rfl $ λ _ H, by simp only [h _ H]
lemma map_domain_add {f : α → α₂} : map_domain f (v₁ + v₂) = map_domain f v₁ + map_domain f v₂ :=
sum_add_index (λ _, single_zero) (λ _ _ _, single_add)
lemma map_domain_finset_sum [decidable_eq ι] {f : α → α₂} {s : finset ι} {v : ι → α →₀ β} :
map_domain f (s.sum v) = s.sum (λi, map_domain f (v i)) :=
eq.symm $ sum_finset_sum_index (λ _, single_zero) (λ _ _ _, single_add)
lemma map_domain_sum [has_zero β₁] {f : α → α₂} {s : α →₀ β₁} {v : α → β₁ → α →₀ β} :
map_domain f (s.sum v) = s.sum (λa b, map_domain f (v a b)) :=
eq.symm $ sum_finset_sum_index (λ _, single_zero) (λ _ _ _, single_add)
lemma map_domain_support {f : α → α₂} {s : α →₀ β} :
(s.map_domain f).support ⊆ s.support.image f :=
finset.subset.trans support_sum $
finset.subset.trans (finset.bind_mono $ assume a ha, support_single_subset) $
by rw [finset.bind_singleton]; exact subset.refl _
@[to_additive finsupp.sum_map_domain_index]
lemma prod_map_domain_index [comm_monoid γ] {f : α → α₂} {s : α →₀ β}
{h : α₂ → β → γ} (h_zero : ∀a, h a 0 = 1) (h_add : ∀a b₁ b₂, h a (b₁ + b₂) = h a b₁ * h a b₂) :
(s.map_domain f).prod h = s.prod (λa b, h (f a) b) :=
(prod_sum_index h_zero h_add).trans $ prod_congr rfl $ λ _ _, prod_single_index (h_zero _)
end map_domain
/-- The product of `f g : α →₀ β` is the finitely supported function
whose value at `a` is the sum of `f x * g y` over all pairs `x, y`
such that `x + y = a`. (Think of the product of multivariate
polynomials where `α` is the monoid of monomial exponents.) -/
instance [has_add α] [semiring β] : has_mul (α →₀ β) :=
⟨λf g, f.sum $ λa₁ b₁, g.sum $ λa₂ b₂, single (a₁ + a₂) (b₁ * b₂)⟩
lemma mul_def [has_add α] [semiring β] {f g : α →₀ β} :
f * g = (f.sum $ λa₁ b₁, g.sum $ λa₂ b₂, single (a₁ + a₂) (b₁ * b₂)) := rfl
/-- The unit of the multiplication is `single 0 1`, i.e. the function
that is 1 at 0 and zero elsewhere. -/
instance [has_zero α] [has_zero β] [has_one β] : has_one (α →₀ β) :=
⟨single 0 1⟩
lemma one_def [has_zero α] [has_zero β] [has_one β] : 1 = (single 0 1 : α →₀ β) := rfl
section filter
section has_zero
variables [has_zero β] (p : α → Prop) [decidable_pred p] (f : α →₀ β)
/-- `filter p f` is the function which is `f a` if `p a` is true and 0 otherwise. -/
def filter (p : α → Prop) [decidable_pred p] (f : α →₀ β) : α →₀ β :=
on_finset f.support (λa, if p a then f a else 0) $ λ a H,
mem_support_iff.2 $ λ h, by rw [h, if_t_t] at H; exact H rfl
@[simp] lemma filter_apply_pos {a : α} (h : p a) : f.filter p a = f a :=
if_pos h
@[simp] lemma filter_apply_neg {a : α} (h : ¬ p a) : f.filter p a = 0 :=
if_neg h
@[simp] lemma support_filter : (f.filter p).support = f.support.filter p :=
finset.ext.mpr $ assume a, if H : p a
then by simp only [mem_support_iff, filter_apply_pos _ _ H, mem_filter, H, and_true]
else by simp only [mem_support_iff, filter_apply_neg _ _ H, mem_filter, H, and_false, ne.def, ne_self_iff_false]
@[simp] lemma filter_single_of_pos
{a : α} {b : β} (h : p a) : (single a b).filter p = single a b :=
finsupp.ext $ λ x, begin
by_cases h' : p x; simp [h'],
rw single_eq_of_ne, rintro rfl, exact h' h
end
@[simp] lemma filter_single_of_neg
{a : α} {b : β} (h : ¬ p a) : (single a b).filter p = 0 :=
finsupp.ext $ λ x, begin
by_cases h' : p x; simp [h'],
rw single_eq_of_ne, rintro rfl, exact h h'
end
end has_zero
lemma filter_pos_add_filter_neg [add_monoid β] (f : α →₀ β) (p : α → Prop) [decidable_pred p] :
f.filter p + f.filter (λa, ¬ p a) = f :=
finsupp.ext $ assume a, if H : p a
then by simp only [add_apply, filter_apply_pos, filter_apply_neg, H, not_not, add_zero]
else by simp only [add_apply, filter_apply_pos, filter_apply_neg, H, not_false_iff, zero_add]
end filter
section subtype_domain
variables {α' : Type*} [has_zero δ] {p : α → Prop} [decidable_pred p]
section zero
variables [has_zero β] {v v' : α' →₀ β}
/-- `subtype_domain p f` is the restriction of the finitely supported function
`f` to the subtype `p`. -/
def subtype_domain (p : α → Prop) [decidable_pred p] (f : α →₀ β) : (subtype p →₀ β) :=
⟨f.support.subtype p, f ∘ subtype.val, λ a, by simp only [mem_subtype, mem_support_iff]⟩
@[simp] lemma support_subtype_domain {f : α →₀ β} :
(subtype_domain p f).support = f.support.subtype p :=
rfl
@[simp] lemma subtype_domain_apply {a : subtype p} {v : α →₀ β} :
(subtype_domain p v) a = v (a.val) :=
rfl
@[simp] lemma subtype_domain_zero : subtype_domain p (0 : α →₀ β) = 0 :=
rfl
@[to_additive finsupp.sum_subtype_domain_index]
lemma prod_subtype_domain_index [comm_monoid γ] {v : α →₀ β}
{h : α → β → γ} (hp : ∀x∈v.support, p x) :
(v.subtype_domain p).prod (λa b, h a.1 b) = v.prod h :=
prod_bij (λp _, p.val)
(λ _, mem_subtype.1)
(λ _ _, rfl)
(λ _ _ _ _, subtype.eq)
(λ b hb, ⟨⟨b, hp b hb⟩, mem_subtype.2 hb, rfl⟩)
end zero
section monoid
variables [add_monoid β] {v v' : α' →₀ β}
@[simp] lemma subtype_domain_add {v v' : α →₀ β} :
(v + v').subtype_domain p = v.subtype_domain p + v'.subtype_domain p :=
ext $ λ _, rfl
@[simp] lemma filter_add {v v' : α →₀ β} :
(v + v').filter p = v.filter p + v'.filter p :=
ext $ λ a, by by_cases p a; simp [h]
end monoid
section comm_monoid
variables [add_comm_monoid β]
lemma subtype_domain_sum {s : finset γ} {h : γ → α →₀ β} :
(s.sum h).subtype_domain p = s.sum (λc, (h c).subtype_domain p) :=
eq.symm (finset.sum_hom _ subtype_domain_zero $ assume v v', subtype_domain_add)
lemma subtype_domain_finsupp_sum {s : γ →₀ δ} {h : γ → δ → α →₀ β} :
(s.sum h).subtype_domain p = s.sum (λc d, (h c d).subtype_domain p) :=
subtype_domain_sum
end comm_monoid
section group
variables [add_group β] {v v' : α' →₀ β}
@[simp] lemma subtype_domain_neg {v : α →₀ β} :
(- v).subtype_domain p = - v.subtype_domain p :=
ext $ λ _, rfl
@[simp] lemma subtype_domain_sub {v v' : α →₀ β} :
(v - v').subtype_domain p = v.subtype_domain p - v'.subtype_domain p :=
ext $ λ _, rfl
end group
end subtype_domain
section multiset
def to_multiset (f : α →₀ ℕ) : multiset α :=
f.sum (λa n, add_monoid.smul n {a})
@[simp] lemma count_to_multiset [decidable_eq α] (f : α →₀ ℕ) (a : α) :
f.to_multiset.count a = f a :=
calc f.to_multiset.count a = f.sum (λx n, (add_monoid.smul n {x} : multiset α).count a) :
(finset.sum_hom _ (multiset.count_zero a) (multiset.count_add a)).symm
... = f.sum (λx n, n * ({x} : multiset α).count a) : by simp only [multiset.count_smul]
... = f.sum (λx n, n * (x :: 0 : multiset α).count a) : rfl
... = f a * (a :: 0 : multiset α).count a : sum_eq_single _
(λ a' _ H, by simp only [multiset.count_cons_of_ne (ne.symm H), multiset.count_zero, mul_zero])
(λ H, by simp only [not_mem_support_iff.1 H, zero_mul])
... = f a : by simp only [multiset.count_singleton, mul_one]
def of_multiset [decidable_eq α] (m : multiset α) : α →₀ ℕ :=
on_finset m.to_finset (λa, m.count a) $ λ a H, multiset.mem_to_finset.2 $
by_contradiction (mt multiset.count_eq_zero.2 H)
@[simp] lemma of_multiset_apply [decidable_eq α] (m : multiset α) (a : α) :
of_multiset m a = m.count a :=
rfl
def equiv_multiset [decidable_eq α] : (α →₀ ℕ) ≃ (multiset α) :=
⟨ to_multiset, of_multiset,
assume f, finsupp.ext $ λ a, by rw [of_multiset_apply, count_to_multiset],
assume m, multiset.ext.2 $ λ a, by rw [count_to_multiset, of_multiset_apply] ⟩
lemma mem_support_multiset_sum [decidable_eq α] [decidable_eq β] [add_comm_monoid β]
{s : multiset (α →₀ β)} (a : α) :
a ∈ s.sum.support → ∃f∈s, a ∈ (f : α →₀ β).support :=
multiset.induction_on s false.elim
begin
assume f s ih ha,
by_cases a ∈ f.support,
{ exact ⟨f, multiset.mem_cons_self _ _, h⟩ },
{ simp only [multiset.sum_cons, mem_support_iff, add_apply,
not_mem_support_iff.1 h, zero_add] at ha,
rcases ih (mem_support_iff.2 ha) with ⟨f', h₀, h₁⟩,
exact ⟨f', multiset.mem_cons_of_mem h₀, h₁⟩ }
end
lemma mem_support_finset_sum [decidable_eq α] [decidable_eq β] [add_comm_monoid β]
{s : finset γ} {h : γ → α →₀ β} (a : α) (ha : a ∈ (s.sum h).support) : ∃c∈s, a ∈ (h c).support :=
let ⟨f, hf, hfa⟩ := mem_support_multiset_sum a ha in
let ⟨c, hc, eq⟩ := multiset.mem_map.1 hf in
⟨c, hc, eq.symm ▸ hfa⟩
lemma mem_support_single [decidable_eq α] [decidable_eq β] [has_zero β] (a a' : α) (b : β) :
a ∈ (single a' b).support ↔ a = a' ∧ b ≠ 0 :=
⟨λ H : (a ∈ ite _ _ _), if h : b = 0
then by rw if_pos h at H; exact H.elim
else ⟨by rw if_neg h at H; exact mem_singleton.1 H, h⟩,
λ ⟨h1, h2⟩, show a ∈ ite _ _ _, by rw [if_neg h2]; exact mem_singleton.2 h1⟩
end multiset
section curry_uncurry
protected def curry [decidable_eq α] [decidable_eq β] [decidable_eq γ] [add_comm_monoid γ]
(f : (α × β) →₀ γ) : α →₀ (β →₀ γ) :=
f.sum $ λp c, single p.1 (single p.2 c)
lemma sum_curry_index
[decidable_eq α] [decidable_eq β] [decidable_eq γ] [add_comm_monoid γ] [add_comm_monoid δ]
(f : (α × β) →₀ γ) (g : α → β → γ → δ)
(hg₀ : ∀ a b, g a b 0 = 0) (hg₁ : ∀a b c₀ c₁, g a b (c₀ + c₁) = g a b c₀ + g a b c₁) :
f.curry.sum (λa f, f.sum (g a)) = f.sum (λp c, g p.1 p.2 c) :=
begin
rw [finsupp.curry],
transitivity,
{ exact sum_sum_index (assume a, sum_zero_index)
(assume a b₀ b₁, sum_add_index (assume a, hg₀ _ _) (assume c d₀ d₁, hg₁ _ _ _ _)) },
congr, funext p c,
transitivity,
{ exact sum_single_index sum_zero_index },
exact sum_single_index (hg₀ _ _)
end
protected def uncurry [decidable_eq α] [decidable_eq β] [decidable_eq γ] [add_comm_monoid γ]
(f : α →₀ (β →₀ γ)) : (α × β) →₀ γ :=
f.sum $ λa g, g.sum $ λb c, single (a, b) c
def finsupp_prod_equiv [add_comm_monoid γ] [decidable_eq α] [decidable_eq β] [decidable_eq γ] :
((α × β) →₀ γ) ≃ (α →₀ (β →₀ γ)) :=
by refine ⟨finsupp.curry, finsupp.uncurry, λ f, _, λ f, _⟩; simp only [
finsupp.curry, finsupp.uncurry, sum_sum_index, sum_zero_index, sum_add_index,
sum_single_index, single_zero, single_add, eq_self_iff_true, forall_true_iff,
forall_3_true_iff, prod.mk.eta, (single_sum _ _ _).symm, sum_single]
end curry_uncurry
section
variables [add_monoid α] [semiring β]
-- TODO: the simplifier unfolds 0 in the instance proof!
private lemma zero_mul (f : α →₀ β) : 0 * f = 0 := by simp only [mul_def, sum_zero_index]
private lemma mul_zero (f : α →₀ β) : f * 0 = 0 := by simp only [mul_def, sum_zero_index, sum_zero]
private lemma left_distrib (a b c : α →₀ β) : a * (b + c) = a * b + a * c :=
by simp only [mul_def, sum_add_index, mul_add, _root_.mul_zero, single_zero, single_add,
eq_self_iff_true, forall_true_iff, forall_3_true_iff, sum_add]
private lemma right_distrib (a b c : α →₀ β) : (a + b) * c = a * c + b * c :=
by simp only [mul_def, sum_add_index, add_mul, _root_.mul_zero, _root_.zero_mul, single_zero, single_add,
eq_self_iff_true, forall_true_iff, forall_3_true_iff, sum_zero, sum_add]
def to_semiring : semiring (α →₀ β) :=
{ one := 1,
mul := (*),
one_mul := assume f, by simp only [mul_def, one_def, sum_single_index, _root_.zero_mul, single_zero, sum_zero,
zero_add, one_mul, sum_single],
mul_one := assume f, by simp only [mul_def, one_def, sum_single_index, _root_.mul_zero, single_zero, sum_zero,
add_zero, mul_one, sum_single],
zero_mul := zero_mul,
mul_zero := mul_zero,
mul_assoc := assume f g h, by simp only [mul_def, sum_sum_index, sum_zero_index, sum_add_index, sum_single_index,
single_zero, single_add, eq_self_iff_true, forall_true_iff, forall_3_true_iff,
add_mul, mul_add, add_assoc, mul_assoc, _root_.zero_mul, _root_.mul_zero, sum_zero, sum_add],
left_distrib := left_distrib,
right_distrib := right_distrib,
.. finsupp.add_comm_monoid }
end
local attribute [instance] to_semiring
def to_comm_semiring [add_comm_monoid α] [comm_semiring β] : comm_semiring (α →₀ β) :=
{ mul_comm := assume f g,
begin
simp only [mul_def, finsupp.sum, mul_comm],
rw [finset.sum_comm],
simp only [add_comm]
end,
.. finsupp.to_semiring }
local attribute [instance] to_comm_semiring
def to_ring [add_monoid α] [ring β] : ring (α →₀ β) :=
{ neg := has_neg.neg,
add_left_neg := add_left_neg,
.. finsupp.to_semiring }
def to_comm_ring [add_comm_monoid α] [comm_ring β] : comm_ring (α →₀ β) :=
{ mul_comm := mul_comm, .. finsupp.to_ring}
lemma single_mul_single [has_add α] [semiring β] {a₁ a₂ : α} {b₁ b₂ : β}:
single a₁ b₁ * single a₂ b₂ = single (a₁ + a₂) (b₁ * b₂) :=
(sum_single_index (by simp only [_root_.zero_mul, single_zero, sum_zero])).trans
(sum_single_index (by rw [_root_.mul_zero, single_zero]))
lemma prod_single [decidable_eq ι] [add_comm_monoid α] [comm_semiring β]
{s : finset ι} {a : ι → α} {b : ι → β} :
s.prod (λi, single (a i) (b i)) = single (s.sum a) (s.prod b) :=
finset.induction_on s rfl $ λ a s has ih, by rw [prod_insert has, ih,
single_mul_single, sum_insert has, prod_insert has]
section
variables (α β)
def to_has_scalar' {R:semiring γ} [add_comm_monoid β] [semimodule γ β] : has_scalar γ (α →₀ β) := ⟨λa v, v.map_range ((•) a) (smul_zero _)⟩
local attribute [instance] to_has_scalar'
@[simp] lemma smul_apply' {R:semiring γ} [add_comm_monoid β] [semimodule γ β] {a : α} {b : γ} {v : α →₀ β} :
(b • v) a = b • (v a) := rfl
def to_semimodule {R:semiring γ} [add_comm_monoid β] [semimodule γ β] : semimodule γ (α →₀ β) :=
{ smul := (•),
smul_add := λ a x y, finsupp.ext $ λ _, smul_add _ _ _,
add_smul := λ a x y, finsupp.ext $ λ _, add_smul _ _ _,
one_smul := λ x, finsupp.ext $ λ _, one_smul _,
mul_smul := λ r s x, finsupp.ext $ λ _, mul_smul _ _ _,
zero_smul := λ x, finsupp.ext $ λ _, zero_smul _,
smul_zero := λ x, finsupp.ext $ λ _, smul_zero _ }
def to_module {R:ring γ} [add_comm_group β] [module γ β] : module γ (α →₀ β) :=
{ ..to_semimodule α β }
variables {α β}
lemma support_smul {R:semiring γ} [add_comm_monoid β] [semimodule γ β] {b : γ} {g : α →₀ β} :
(b • g).support ⊆ g.support :=
λ a, by simp; exact mt (λ h, h.symm ▸ smul_zero _)
section
variables {α' : Type*} [has_zero δ] {p : α → Prop} [decidable_pred p]
@[simp] lemma filter_smul {R:semiring γ} [add_comm_monoid β] [semimodule γ β]
{b : γ} {v : α →₀ β} : (b • v).filter p = b • v.filter p :=
ext $ λ a, by by_cases p a; simp [h]
end
lemma map_domain_smul {α'} [decidable_eq α'] {R:semiring γ} [add_comm_monoid β] [semimodule γ β]
{f : α → α'} (b : γ) (v : α →₀ β) : map_domain f (b • v) = b • map_domain f v :=
begin
change map_domain f (map_range _ _ _) = map_range _ _ _,
apply finsupp.induction v, {simp},
intros a b v' hv₁ hv₂ IH,
rw [map_range_add, map_domain_add, IH, map_domain_add, map_range_add,
map_range_single, map_domain_single, map_domain_single, map_range_single];
apply smul_add
end
@[simp] lemma smul_single {R:semiring γ} [add_comm_monoid β] [semimodule γ β]
(c : γ) (a : α) (b : β) : c • finsupp.single a b = finsupp.single a (c • b) :=
ext $ λ a', by by_cases a = a'; [{subst h, simp}, simp [h]]
end
def to_has_scalar [ring β] : has_scalar β (α →₀ β) := to_has_scalar' α β
local attribute [instance] to_has_scalar
@[simp] lemma smul_apply [ring β] {a : α} {b : β} {v : α →₀ β} :
(b • v) a = b • (v a) := rfl
lemma sum_smul_index [ring β] [add_comm_monoid γ] {g : α →₀ β} {b : β} {h : α → β → γ}
(h0 : ∀i, h i 0 = 0) : (b • g).sum h = g.sum (λi a, h i (b * a)) :=
finsupp.sum_map_range_index h0
end decidable
section
variables [semiring β] [semiring γ]
lemma sum_mul (b : γ) (s : α →₀ β) {f : α → β → γ} :
(s.sum f) * b = s.sum (λ a c, (f a (s a)) * b) :=
by simp only [finsupp.sum, finset.sum_mul]
lemma mul_sum [semiring β] [semiring γ] (b : γ) (s : α →₀ β) {f : α → β → γ} :
b * (s.sum f) = s.sum (λ a c, b * (f a (s a))) :=
by simp only [finsupp.sum, finset.mul_sum]
end
end finsupp
|
a6402838f9cb53c773ac700ca83d576a261e43e3 | d406927ab5617694ec9ea7001f101b7c9e3d9702 | /src/topology/sheaves/sheaf_of_functions.lean | c4608b98ca1924267fffc964bf811053eecbc9c3 | [
"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 | 3,942 | lean | /-
Copyright (c) 2020 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin, Scott Morrison
-/
import topology.sheaves.presheaf_of_functions
import topology.sheaves.sheaf_condition.unique_gluing
/-!
# Sheaf conditions for presheaves of (continuous) functions.
We show that
* `Top.presheaf.to_Type_is_sheaf`: not-necessarily-continuous functions into a type form a sheaf
* `Top.presheaf.to_Types_is_sheaf`: in fact, these may be dependent functions into a type family
For
* `Top.sheaf_to_Top`: continuous functions into a topological space form a sheaf
please see `topology/sheaves/local_predicate.lean`, where we set up a general framework
for constructing sub(pre)sheaves of the sheaf of dependent functions.
## Future work
Obviously there's more to do:
* sections of a fiber bundle
* various classes of smooth and structure preserving functions
* functions into spaces with algebraic structure, which the sections inherit
-/
open category_theory
open category_theory.limits
open topological_space
open topological_space.opens
universe u
noncomputable theory
variables (X : Top.{u})
open Top
namespace Top.presheaf
/--
We show that the presheaf of functions to a type `T`
(no continuity assumptions, just plain functions)
form a sheaf.
In fact, the proof is identical when we do this for dependent functions to a type family `T`,
so we do the more general case.
-/
lemma to_Types_is_sheaf (T : X → Type u) : (presheaf_to_Types X T).is_sheaf :=
is_sheaf_of_is_sheaf_unique_gluing_types _ $ λ ι U sf hsf,
-- We use the sheaf condition in terms of unique gluing
-- U is a family of open sets, indexed by `ι` and `sf` is a compatible family of sections.
-- In the informal comments below, I'll just write `U` to represent the union.
begin
-- Our first goal is to define a function "lifted" to all of `U`.
-- We do this one point at a time. Using the axiom of choice, we can pick for each
-- `x : supr U` an index `i : ι` such that `x` lies in `U i`
choose index index_spec using λ x : supr U, opens.mem_supr.mp x.2,
-- Using this data, we can glue our functions together to a single section
let s : Π x : supr U, T x := λ x, sf (index x) ⟨x.1, index_spec x⟩,
refine ⟨s,_,_⟩,
{ intro i,
ext x,
-- Now we need to verify that this lifted function restricts correctly to each set `U i`.
-- Of course, the difficulty is that at any given point `x ∈ U i`,
-- we may have used the axiom of choice to pick a different `j` with `x ∈ U j`
-- when defining the function.
-- Thus we'll need to use the fact that the restrictions are compatible.
convert congr_fun (hsf (index ⟨x,_⟩) i) ⟨x,⟨index_spec ⟨x.1,_⟩,x.2⟩⟩,
ext,
refl },
{ -- Now we just need to check that the lift we picked was the only possible one.
-- So we suppose we had some other gluing `t` of our sections
intros t ht,
-- and observe that we need to check that it agrees with our choice
-- for each `f : s .X` and each `x ∈ supr U`.
ext x,
convert congr_fun (ht (index x)) ⟨x.1,index_spec x⟩,
ext,
refl }
end
-- We verify that the non-dependent version is an immediate consequence:
/--
The presheaf of not-necessarily-continuous functions to
a target type `T` satsifies the sheaf condition.
-/
lemma to_Type_is_sheaf (T : Type u) : (presheaf_to_Type X T).is_sheaf :=
to_Types_is_sheaf X (λ _, T)
end Top.presheaf
namespace Top
/--
The sheaf of not-necessarily-continuous functions on `X` with values in type family
`T : X → Type u`.
-/
def sheaf_to_Types (T : X → Type u) : sheaf (Type u) X :=
⟨presheaf_to_Types X T, presheaf.to_Types_is_sheaf _ _⟩
/--
The sheaf of not-necessarily-continuous functions on `X` with values in a type `T`.
-/
def sheaf_to_Type (T : Type u) : sheaf (Type u) X :=
⟨presheaf_to_Type X T, presheaf.to_Type_is_sheaf _ _⟩
end Top
|
c5b1a63774c9783df34478d9067e1a809fa64e17 | b82c5bb4c3b618c23ba67764bc3e93f4999a1a39 | /src/formal_ml/radon_nikodym.lean | ad898b36924e262849d043496b20a900c8bf2ba6 | [
"Apache-2.0"
] | permissive | nouretienne/formal-ml | 83c4261016955bf9bcb55bd32b4f2621b44163e0 | 40b6da3b6e875f47412d50c7cd97936cb5091a2b | refs/heads/master | 1,671,216,448,724 | 1,600,472,285,000 | 1,600,472,285,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 83,315 | 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 measure_theory.measurable_space
import measure_theory.measure_space
import measure_theory.outer_measure
import measure_theory.lebesgue_measure
import measure_theory.integration
import measure_theory.set_integral
import measure_theory.borel_space
import data.set.countable
import formal_ml.nnreal
import formal_ml.sum
import formal_ml.core
import formal_ml.measurable_space
import formal_ml.semiring
import formal_ml.real_measurable_space
import formal_ml.set
import formal_ml.filter_util
import topology.instances.ennreal
import formal_ml.integral
import formal_ml.int
import formal_ml.with_density_compose_eq_multiply
import formal_ml.hahn
/-
The Lebesgue-Radon-Nikodym theorem, while it delves deeply into the nuances of
measure theory, provides the foundation for statistics and probability. Specifically,
continuous random variables can be represented by a density function. The
Lebesgue-Radon-Nikodym theorem (and the Radon-Nikodym theorem) exactly characterize
what probability measures have this simple representation: specifically, those that
are absolutely continuous with respect to the Lebesgue measure. This theorem, like
the fundamental theorem of calculus, provides a deep insight that can be easily used
even by those who do not understand the nuances of the proof.
-/
lemma ennreal.ne_zero_iff_zero_lt {x:ennreal}:x ≠ 0 ↔ 0 < x :=
begin
split;intros A1,
{
apply lt_of_not_le,
intro B1,
apply A1,
simp at B1,
apply B1,
},
{
intros C1,
subst x,
simp at A1,
apply A1,
},
end
lemma real.sub_le_sub_of_le_of_le_of_le {a b c d:real}:
a ≤ b → c ≤ d → a ≤ b - c + d :=
begin
intros A1 A2,
apply le_trans A1,
have B1:b - c + c ≤ b - c + d,
{
apply add_le_add,
apply le_refl _,
apply A2,
},
simp at B1,
apply B1
end
lemma nnreal.sub_le_sub_of_le_of_le_of_le {a b c d:nnreal}:
a ≤ b → c ≤ d → d ≤ a → a ≤ b - c + d :=
begin
intros A1 A2 A3,
rw ← nnreal.coe_le_coe,
rw nnreal.coe_add,
rw nnreal.coe_sub,
apply real.sub_le_sub_of_le_of_le_of_le,
{
rw nnreal.coe_le_coe,
apply A1,
},
{
rw nnreal.coe_le_coe,
apply A2,
},
apply le_trans A2,
apply le_trans A3,
apply le_trans A1,
apply le_refl _,
end
lemma ennreal.sub_le_sub_of_le_of_le_of_le {a b c d:ennreal}:
a ≤ b → c ≤ d → d ≤ a → a - d ≤ b - c :=
begin
cases a;cases b;cases c;cases d;try {simp},
intros A1 A2 A3,
have B1:(a:ennreal) ≤ (b:ennreal) - (c:ennreal) + (d:ennreal),
{
rw ← ennreal.coe_sub,
rw ← ennreal.coe_add,
rw ennreal.coe_le_coe,
apply nnreal.sub_le_sub_of_le_of_le_of_le A1 A2 A3,
},
apply B1,
end
lemma nnreal.mul_lt_mul_of_pos_of_lt
{a b c:nnreal}:(0 < a) → (b < c) → (a * b < a * c) :=
begin
intros A1 A2,
apply mul_lt_mul',
apply le_refl _,
apply A2,
simp,
apply A1,
end
/-
It is hard to generalize this.
-/
lemma nnreal.mul_pos_iff_pos_pos
{a b:nnreal}:(0 < a * b) ↔ (0 < a)∧ (0 < b) :=
begin
split;intros A1,
{
rw zero_lt_iff_ne_zero at A1,
repeat {rw zero_lt_iff_ne_zero},
split;intro B1;apply A1,
{
rw B1,
rw zero_mul,
},
{
rw B1,
rw mul_zero,
},
},
{
have C1:0 ≤ a * 0,
{
simp,
},
apply lt_of_le_of_lt C1,
apply nnreal.mul_lt_mul_of_pos_of_lt,
apply A1.left,
apply A1.right,
},
end
lemma nnreal.inv_mul_eq_inv_mul_inv {a b:nnreal}:(a * b)⁻¹=a⁻¹ * b⁻¹ :=
begin
rw nnreal.mul_inv,
rw mul_comm,
end
lemma nnreal.le_zero_iff {a:nnreal}:a ≤ 0 ↔ a=0 :=
begin
simp
end
lemma nnreal.pos_iff {a:nnreal}:0 < a ↔ a ≠ 0 :=
begin
split;intros B1,
{
intros C1,
subst a,
simp at B1,
apply B1,
},
{
apply by_contradiction,
intros D1,
apply B1,
rw ← @nnreal.le_zero_iff a,
apply le_of_not_lt D1,
},
end
lemma ennreal.inv_mul_eq_inv_mul_inv {a b:ennreal}:(a≠ 0) → (b≠ 0) → (a * b)⁻¹=a⁻¹ * b⁻¹ :=
begin
cases a;simp;cases b;simp,
intros A1 A2,
rw ← ennreal.coe_mul,
repeat {rw ← ennreal.coe_inv},
rw ← ennreal.coe_mul,
rw ennreal.coe_eq_coe,
apply @nnreal.inv_mul_eq_inv_mul_inv a b,
apply A2,
apply A1,
rw ← @nnreal.pos_iff (a * b),
rw nnreal.mul_pos_iff_pos_pos,
repeat {rw zero_lt_iff_ne_zero},
apply and.intro A1 A2,
end
lemma ennreal.div_dist {a b c:ennreal}:(b≠ 0) → (c≠ 0) → a/(b * c)=(a/b)/c :=
begin
intros A1 A2,
rw ennreal.div_def,
rw ennreal.inv_mul_eq_inv_mul_inv,
rw ← mul_assoc,
rw ennreal.div_def,
rw ennreal.div_def,
apply A1,
apply A2,
end
lemma ennreal.div_eq_zero_iff {a b:ennreal}:a/b=0 ↔ (a = 0) ∨ (b = ⊤) :=
begin
cases a;cases b;split;simp;intros A1;simp;simp at A1,
end
/-
Helper function to lift nnreal.exists_unit_frac_lt_pos to ennreal.
-/
lemma ennreal.exists_unit_frac_lt_pos' {ε:nnreal}:0 < ε → (∃ n:ℕ, (1/((n:ennreal) + 1)) < (ε:ennreal)) :=
begin
intros A1,
-- simp at A1,
have C1:= nnreal.exists_unit_frac_lt_pos A1,
cases C1 with n A1,
apply exists.intro n,
have D1:((1:nnreal):ennreal) = 1 := rfl,
rw ← D1,
have D2:((n:nnreal):ennreal) = (n:ennreal),
{
simp,
},
rw ← D2,
rw ← ennreal.coe_add,
rw ← ennreal.coe_div,
rw ennreal.coe_lt_coe,
apply A1,
simp,
end
lemma ennreal.exists_unit_frac_lt_pos {ε:ennreal}:0 < ε → (∃ n:ℕ, (1/((n:ennreal) + 1)) < ε) :=
begin
cases ε,
{
intros A1,
have B1:(0:nnreal) < (1:nnreal),
{
apply zero_lt_one,
},
have B1:=ennreal.exists_unit_frac_lt_pos' B1,
cases B1 with n B1,
apply exists.intro n,
apply lt_of_lt_of_le B1,
simp,
},
{
intros A1,
simp at A1,
have C1:= ennreal.exists_unit_frac_lt_pos' A1,
apply C1,
},
end
lemma ennreal.zero_of_le_all_unit_frac {x:ennreal}:
(∀ (n:ℕ), (x ≤ 1/((n:ennreal) + 1))) → (x = 0) :=
begin
intros A1,
rw ← not_exists_not at A1,
apply by_contradiction,
intros B1,
apply A1,
have B2:0 < x,
{
rw zero_lt_iff_ne_zero,
apply B1,
},
have B3:= ennreal.exists_unit_frac_lt_pos B2,
cases B3 with n B3,
apply exists.intro n,
apply not_le_of_lt,
apply B3,
end
lemma ennreal.unit_frac_pos {n:ℕ}:(1/((n:ennreal) + 1))>0 :=
begin
simp,
intros B1,
rw ennreal.add_eq_top at B1,
simp at B1,
apply B1,
end
lemma ennreal.div_eq_top_iff {a b:ennreal}:a/b=⊤ ↔
((a = ⊤)∧(b≠ ⊤) )∨ ((a≠ 0)∧(b=0)):=
begin
rw ennreal.div_def,
cases a;cases b;simp,
end
lemma ennreal.unit_frac_ne_top {n:ℕ}:(1/((n:ennreal) + 1))≠ ⊤ :=
begin
intro A1,
rw ennreal.div_eq_top_iff at A1,
simp at A1,
apply A1,
end
lemma nnreal.mul_le_mul_left' (a b:nnreal) (H:a≤ b) (c:nnreal):
c * a ≤ c * b :=
begin
cases (classical.em (c = 0)) with B1 B1,
{
subst c,
simp,
},
{
have C1:0 < c,
{
rw zero_lt_iff,
intro C1A,
apply B1,
apply C1A,
},
rw mul_le_mul_left,
apply H,
apply C1,
},
end
lemma ennreal.mul_le_mul_left' (a b:ennreal) (H:a≤ b) (c:ennreal):
c * a ≤ c * b :=
begin
revert H,
cases c;cases a;cases b;try {simp},
{
intros A1,
rw ennreal.top_mul,
rw ennreal.top_mul,
cases (classical.em (a = 0)) with B1 B1,
{
subst a,
simp,
},
{
have B2:0 < a,
{
rw zero_lt_iff_ne_zero,
intro B2A,
rw B2A at B1,
simp at B1,
apply B1,
},
have B3:0 < b,
{
apply lt_of_lt_of_le B2 A1,
},
have B4:(b:ennreal) ≠ 0,
{
rw zero_lt_iff_ne_zero at B3,
intros B4A,
apply B3,
simp at B4A,
apply B4A,
},
rw if_neg B4,
simp,
},
},
{
apply le_refl _,
},
{
rw ennreal.mul_top,
cases (classical.em (c = 0)) with D1 D1,
{
subst c,
simp,
},
{
have E1:¬((c:ennreal) = 0),
{
intro E1A,
apply D1,
simp at E1A,
apply E1A,
},
rw if_neg E1,
simp,
},
},
rw ← ennreal.coe_mul,
rw ← ennreal.coe_mul,
rw ennreal.coe_le_coe,
intro F1,
apply nnreal.mul_le_mul_left',
apply F1,
end
lemma lt_eq_le_compl {δ α:Type*}
[linear_order α] {f g : δ → α}:{a | f a < g a} ={a | g a ≤ f a}ᶜ :=
begin
apply set.ext,
intros ω;split;intros A3A;simp;simp at A3A;apply A3A,
end
lemma is_measurable_lt {δ α:Type*} [measurable_space δ] [measurable_space α] [topological_space α]
[opens_measurable_space α]
[linear_order α] [order_closed_topology α] [topological_space.second_countable_topology α]
{f g : δ → α} (hf : measurable f) (hg : measurable g) :
is_measurable {a | f a < g a} :=
begin
rw lt_eq_le_compl,
apply is_measurable.compl,
apply is_measurable_le,
repeat {assumption},
end
lemma ennreal.lt_add_self {a b:ennreal}:a < ⊤ → 0 < b → a < a + b :=
begin
cases a;cases b;simp,
intros A1,
rw ← ennreal.coe_add,
rw ennreal.coe_lt_coe,
simp,
apply A1,
end
---------------------------End theorems to move----------------------------------
lemma simple_restrict_eq_indicator_const {Ω:Type*} {M:measurable_space Ω}
(S:set Ω) (x:ennreal):(is_measurable S) →
⇑((measure_theory.simple_func.const Ω x).restrict S) = (set.indicator S (λ ω:Ω, x)) :=
begin
intro A1,
rw measure_theory.simple_func.coe_restrict,
rw measure_theory.simple_func.coe_const,
apply A1,
end
lemma with_density_const_apply {Ω:Type*} {M:measurable_space Ω} (μ:measure_theory.measure Ω)
{k:ennreal} {S:set Ω}:is_measurable S →
μ.with_density (λ ω:Ω, k) S = k * μ S :=
begin
intros B1,
rw measure_theory.with_density_apply2,
rw ← simple_restrict_eq_indicator_const,
rw integral_const_restrict_def,
refl,
apply B1,
apply B1,
apply B1,
end
lemma measure_theory.measure.le_zero_iff {Ω:Type*} [measurable_space Ω]
(μ:measure_theory.measure Ω):μ ≤ 0 ↔ μ = 0 :=
begin
split;intros A1,
{
apply le_antisymm A1,
apply measure_theory.measure.zero_le,
},
{
rw A1,
apply le_refl _,
},
end
lemma measure_theory.measure.sub_eq_zero_if_le {Ω:Type*} [measurable_space Ω]
(μ ν:measure_theory.measure Ω):μ ≤ ν → μ - ν = 0 :=
begin
intros A1,
rw ← measure_theory.measure.le_zero_iff,
rw measure_theory.measure.sub_def,
apply @Inf_le (measure_theory.measure Ω) _ _,
simp [A1],
end
lemma measure_sub_add {α:Type*} [M:measurable_space α]
{μ ν:measure_theory.measure α} (H:ν ≤ μ)
[H2:measure_theory.finite_measure ν]:μ = ν + (measure_sub H) :=
begin
apply measure_theory.measure.ext,
intros s A3,
simp,
rw measure_sub_apply,
rw add_comm,
rw ennreal.sub_add_cancel_of_le,
apply H,
repeat {apply A3},
end
lemma measure_sub_eq {α:Type*} [M:measurable_space α]
(μ ν:measure_theory.measure α) (H:ν ≤ μ)
(H2:measure_theory.finite_measure ν):(μ - ν) = (measure_sub H) :=
begin
rw measure_theory.measure.sub_def,
have A1B:μ = ν + measure_sub H :=
measure_sub_add H,
apply le_antisymm,
{
have A1:μ ≤ (measure_sub H) + ν,
{
rw add_comm,
rw ← A1B,
apply le_refl μ,
},
have A2:(measure_sub H) ∈ {d|μ ≤ d + ν} := A1,
apply Inf_le A2,
},
{
apply @le_Inf (measure_theory.measure α) _,
intros b B1,
simp at B1,
rw A1B at B1,
rw add_comm at B1,
apply measure_theory.measure.le_of_add_le_add_right B1,
},
end
lemma le_of_le_measure_sub {α:Type*} [M:measurable_space α]
{μ ν₁ ν₂:measure_theory.measure α} [H2:measure_theory.finite_measure μ]
[H3:measure_theory.finite_measure ν₁]
(H:ν₁ ≤ μ):
ν₂ ≤ (measure_sub H) → ν₁ + ν₂ ≤ μ :=
begin
intro A1,
have B1:μ = ν₁ + (measure_sub H),
{
apply measure_sub_add,
},
rw B1,
apply measure_theory.measure.add_le_add_left,
apply A1,
end
lemma measure_theory.measure.sub_apply {Ω:Type*} [measurable_space Ω]
(μ ν:measure_theory.measure Ω) {S:set Ω} [A2:measure_theory.finite_measure ν]:
is_measurable S →
ν ≤ μ → (μ - ν) S = μ S - ν S :=
begin
intros A1 A3,
rw measure_sub_eq μ ν A3 A2,
apply measure_sub_apply,
apply A1,
end
lemma measure_theory.measure.restrict_apply_subset {Ω:Type*} [measurable_space Ω]
(μ:measure_theory.measure Ω) {S T:set Ω}:is_measurable S →
S ⊆ T →
(μ.restrict T) S = μ S :=
begin
intros A1 A3,
rw measure_theory.measure.restrict_apply A1,
simp [set.inter_eq_self_of_subset_left,A3],
end
lemma measure_theory.measure.restrict_apply_self {Ω:Type*} [measurable_space Ω]
(μ:measure_theory.measure Ω) {S:set Ω} (H:is_measurable S):
(μ.restrict S) S = μ S :=
begin
rw measure_theory.measure.restrict_apply H,
simp,
end
lemma restrict_le_restrict_of_le_on_subsets {Ω:Type*} [measurable_space Ω]
(μ ν:measure_theory.measure Ω) {S:set Ω}:
le_on_subsets μ ν S →
(μ.restrict S) ≤ ν.restrict S :=
begin
intros A1,
rw le_on_subsets_def at A1,
rw measure_theory.measure.le_iff,
intros T B1,
rw measure_theory.measure.restrict_apply,
rw measure_theory.measure.restrict_apply,
apply A1.right,
simp,
apply is_measurable.inter,
apply B1,
apply A1.left,
repeat {apply B1},
end
/-
Not required, but completes the connection between le_on_subsets and restrict.
-/
lemma le_on_subsets_of_is_measurable_of_restrict_le_restrict {Ω:Type*} [measurable_space Ω]
(μ ν:measure_theory.measure Ω) {S:set Ω}:is_measurable S →
(μ.restrict S) ≤ ν.restrict S →
le_on_subsets μ ν S :=
begin
intros A1 A2,
rw measure_theory.measure.le_iff at A2,
rw le_on_subsets_def,
apply and.intro A1,
intros X B1 B2,
have B3 := A2 X B2,
rw measure_theory.measure.restrict_apply_subset μ B2 B1 at B3,
rw measure_theory.measure.restrict_apply_subset ν B2 B1 at B3,
apply B3,
end
lemma measure_theory.outer_measure.Inf_gen_nonempty3 {α:Type*} (m : set (measure_theory.outer_measure α))
(t:set α) :m.nonempty →
measure_theory.outer_measure.Inf_gen m t =
(⨅ (μ : measure_theory.outer_measure α) (H:μ∈ m), μ t) :=
begin
intro A1,
have B1:∃ μ:measure_theory.outer_measure α, μ ∈ m,
{
rw set.nonempty_def at A1,
apply A1,
},
cases B1 with μ B1,
rw measure_theory.outer_measure.Inf_gen_nonempty2 _ μ B1,
end
lemma measure_theory.outer_measure.of_function_def2
{α : Type*} (m : set α → ennreal) (m_empty : m ∅ = 0) (s:set α):
(measure_theory.outer_measure.of_function m m_empty) s
= ⨅{f : ℕ → set α} (h : s ⊆ ⋃i, f i), ∑'i, m (f i) := rfl
lemma set.Union_inter_eq_inter_Union {α
β:Type*} {f:α → set β} {T:set β}:
(⋃ (a:α), f a ∩ T) = T ∩ (⋃ (a:α), f a) :=
begin
apply set.ext,
intro b,split;intros B1;simp;simp at B1;
apply and.intro B1.right B1.left,
end
lemma set.Union_union_eq_union_Union {α
β:Type*} [NE:nonempty α] {f:α → set β} {T:set β}:
(⋃ (a:α), f a ∪ T) = T ∪ (⋃ (a:α), f a) :=
begin
apply set.ext,
intro b,split;intros B1;simp;simp at B1,
{
cases B1 with a B2,
cases B2 with B3 B4,
{
right,
apply exists.intro a B3,
},
{
left,
apply B4,
},
},
{
cases B1 with C1 C2,
{
apply nonempty.elim NE,
intro a,
apply exists.intro a,
right,
apply C1,
},
{
cases C2 with a C3,
apply exists.intro a,
left,
apply C3,
},
},
end
lemma set.subset_union_compl_of_inter_subset {α:Type*} {A B C:set α}:A ∩ B ⊆ C →
A ⊆ C ∪ Bᶜ :=
begin
intro D1,
rw set.subset_def,
intros x D2,
rw set.subset_def at D1,
simp,
cases (classical.em (x∈ B)) with D3 D3,
{
left,
apply D1,
simp [D2,D3],
},
{
right,
apply D3,
},
end
lemma infi_le_trans {α β:Type*} [complete_lattice β] (a:α) (f:α → β)
(b:β):(f a ≤ b) → (⨅ (c:α), (f c)) ≤ b :=
begin
intros A1,
apply le_trans _ A1,
apply @infi_le _ _ _,
end
/-
I saw this pattern a bunch below. It could be more widely used.
-/
lemma infi_set_le_trans {α β:Type*} [complete_lattice β] (a:α) (P:α → Prop) (f:α → β)
(b:β):(P a) → (f a ≤ b) → (⨅ (c:α) (H:P c), f c) ≤ b :=
begin
intros A1 A2,
apply infi_le_trans a,
rw infi_prop_def A1,
apply A2,
end
lemma infi_set_image {α β γ:Type*} [complete_lattice γ] (S:set α) (f:α → β)
(g:β → γ):(⨅ (c∈ (f '' S)), g c) = ⨅ (a∈ S), (g ∘ f) a :=
begin
apply le_antisymm;simp,
{
intros a B1,
apply infi_le_trans (f a),
apply infi_le_trans a,
rw infi_prop_def,
apply and.intro B1,
refl,
},
{
intros b a2 C1 C2,
apply infi_le_trans a2,
rw infi_prop_def C1,
rw C2,
},
end
--Note that this does not hold true for empty S.
--If S2.nonempty, but S2 ∩ T = ∅, then ⊤ (S2 ∩ T) = 0, but ⊤ (S2) = ⊤.
lemma measure_theory.outer_measure.Inf_restrict {Ω:Type*} [measurable_space Ω]
(S:set (measure_theory.outer_measure Ω)) {T:set Ω}:
is_measurable T → (S.nonempty) →
measure_theory.outer_measure.restrict T (Inf S) = Inf ((measure_theory.outer_measure.restrict T) '' S) :=
begin
intros A1 B1,
apply measure_theory.outer_measure.ext,
intros S2,
rw measure_theory.outer_measure.restrict_apply,
rw measure_theory.outer_measure.Inf_eq_of_function_Inf_gen,
rw measure_theory.outer_measure.Inf_eq_of_function_Inf_gen,
rw measure_theory.outer_measure.of_function_def2,
rw measure_theory.outer_measure.of_function_def2,
have E1:((measure_theory.outer_measure.restrict T) '' S).nonempty,
{
apply set.nonempty_image_of_nonempty B1,
},
apply le_antisymm,
{
simp,
intros f C1,
let g := λ n, (f n) ∩ T,
begin
have C2:g = (λ n, (f n) ∩ T) := rfl,
have C3: (∑' (i:ℕ), measure_theory.outer_measure.Inf_gen S (g i)) ≤
∑' (i : ℕ), measure_theory.outer_measure.Inf_gen (⇑(measure_theory.outer_measure.restrict T) '' S) (f i),
{
apply ennreal.tsum_le_tsum,
intro n,
rw measure_theory.outer_measure.Inf_gen_nonempty3 _ _ B1,
rw measure_theory.outer_measure.Inf_gen_nonempty3 _ _ E1,
simp,
intros μ' μ C3A C3B,
subst μ',
rw measure_theory.outer_measure.restrict_apply,
rw C2,
simp,
have C3C:(⨅ (H : μ ∈ S),
μ (f n ∩ T)) ≤ μ (f n ∩ T),
{
rw infi_prop_def,
apply le_refl _,
apply C3A,
},
apply le_trans _ C3C,
apply @infi_le ennreal _ _,
},
apply le_trans _ C3,
have C4:(⨅ (h : S2 ∩ T ⊆ ⋃ (i : ℕ), g i),
(∑' (i:ℕ), measure_theory.outer_measure.Inf_gen S (g i))) ≤
(∑' (i:ℕ), measure_theory.outer_measure.Inf_gen S (g i)),
{
rw infi_prop_def,
apply le_refl _,
rw C2,
simp,
rw set.Union_inter_eq_inter_Union,
simp,
apply set.subset.trans _ C1,
apply set.inter_subset_left,
},
apply le_trans _ C4,
apply @infi_le ennreal _ _,
end
},
{
simp,
intros h D1,
let g := λ n, (h n) ∪ Tᶜ,
begin
have D2:g = λ n, (h n) ∪ Tᶜ := rfl,
apply @infi_set_le_trans (ℕ → set Ω) ennreal _ g,
{
rw D2,
simp,
rw set.Union_union_eq_union_Union,
rw set.union_comm,
apply set.subset_union_compl_of_inter_subset,
apply D1,
},
{
apply ennreal.tsum_le_tsum,
intro n,
rw measure_theory.outer_measure.Inf_gen_nonempty3 _ _ B1,
rw measure_theory.outer_measure.Inf_gen_nonempty3 _ _ E1,
rw infi_set_image,
simp,
intros μ D3,
apply @infi_set_le_trans (measure_theory.outer_measure Ω) ennreal _ μ,
apply D3,
{
rw D2,
simp,
rw set.inter_distrib_right,
simp,
apply μ.mono,
simp,
},
},
end
},
end
lemma measure_theory.measure.lift_linear_def {α β:Type*} [measurable_space α] [Mβ:measurable_space β]
(f : measure_theory.outer_measure α →ₗ[ennreal] measure_theory.outer_measure β)
(H:∀ (μ : measure_theory.measure α), Mβ ≤ (f μ.to_outer_measure).caratheodory)
{μ:measure_theory.measure α}:
(measure_theory.measure.lift_linear f H μ) = (f (μ.to_outer_measure)).to_measure (H μ) :=
begin
apply measure_theory.measure.ext,
intros S B1,
unfold measure_theory.measure.lift_linear,
simp,
end
lemma measure_theory.outer_measure.to_measure_to_outer_measure_eq_trim {Ω:Type*} [M:measurable_space Ω]
{μ:measure_theory.outer_measure Ω} (H:M ≤ (μ).caratheodory):
(μ.to_measure H).to_outer_measure = μ.trim :=
begin
apply measure_theory.outer_measure.ext,
intros S,
unfold measure_theory.outer_measure.to_measure measure_theory.measure.to_outer_measure
measure_theory.outer_measure.trim
measure_theory.measure.of_measurable,
simp,
refl,
end
lemma infi_prop_false2 {α:Type*} [complete_lattice α]
{P:Prop} {v:P→ α} (H:¬P):(⨅ (H2:P), v H2) = ⊤ :=
begin
apply le_antisymm,
{
simp,
},
{
apply @le_infi α _ _,
intro H2,
exfalso,
apply H,
apply H2,
},
end
lemma measure_theory.extend_top {α : Type*} {P : α → Prop}
{m : Π (s : α), P s → ennreal} {s : α}: ( ¬P s)→
measure_theory.extend m s = ⊤ :=
begin
intros A1,
unfold measure_theory.extend,
rw infi_prop_false2,
apply A1,
end
--Unused.
lemma measure_theory.le_extend2 {α:Type*} [measurable_space α] {x:ennreal}
{h:Π (s:set α), (is_measurable s) → ennreal} (s:set α):
(Π (H:is_measurable s), (x ≤ h s H)) → (x ≤ measure_theory.extend h s) :=
begin
intros A1,
cases (classical.em (is_measurable s)) with B1 B1,
{
apply le_trans (A1 B1),
apply measure_theory.le_extend,
},
{
rw measure_theory.extend_top B1,
simp,
},
end
/-
This is a result that must be proven directly for restrict, but has
larger implications.
I am curious whether this follows from
lift_linear constraint on the catheodary measurable space of the output outer
measure of restrict. That would be a more general result, implying that this would
hold for all places where lift_linear was used.
-/
lemma measure_theory.outer_measure.restrict_trimmed_of_trimmed {Ω:Type*} [M:measurable_space Ω]
{μ:measure_theory.outer_measure Ω} {S:set Ω}:is_measurable S → μ.trim = μ →
(measure_theory.outer_measure.restrict S μ).trim = (measure_theory.outer_measure.restrict S μ) :=
begin
intros A2 A1,
apply measure_theory.outer_measure.ext,
unfold measure_theory.outer_measure.trim,
unfold measure_theory.induced_outer_measure,
intros T,
simp,
rw measure_theory.outer_measure.of_function_def2,
apply le_antisymm,
{
have B1:μ (T ∩ S) = μ.trim (T ∩ S),
{
rw A1,
},
rw B1,
unfold measure_theory.outer_measure.trim,
unfold measure_theory.induced_outer_measure,
rw measure_theory.outer_measure.of_function_def2,
simp,
intros h B2,
let g := λ (n:ℕ), (h n) ∪ Sᶜ,
begin
have B3:g = λ (n:ℕ), (h n) ∪ Sᶜ := rfl,
have B4:(∑' (i : ℕ), measure_theory.extend (λ (s : set Ω) (_x : is_measurable s),
μ (s ∩ S)) (g i)) ≤
∑' (i : ℕ), measure_theory.extend (λ (s : set Ω) (_x : is_measurable s),
μ s) (h i),
{
apply ennreal.tsum_le_tsum,
intros n,
apply measure_theory.le_extend2,
intro B4A,
rw measure_theory.extend_eq,
rw B3,
simp,
rw set.inter_distrib_right,
simp,
apply measure_theory.outer_measure.mono',
simp,
rw B3,
simp,
apply is_measurable.union B4A (is_measurable.compl A2),
},
apply le_trans _ B4,
clear B4,
have B5:(⨅ (h : T ⊆ ⋃ (i : ℕ), g i),
∑' (i : ℕ), measure_theory.extend
(λ (s : set Ω) (_x : is_measurable s), μ (s ∩ S)) (g i)) ≤
∑' (i : ℕ), measure_theory.extend
(λ (s : set Ω) (_x : is_measurable s), μ (s ∩ S)) (g i),
{
rw infi_prop_def,
apply le_refl _,
rw B3,
simp,
rw set.Union_union_eq_union_Union,
rw set.union_comm,
apply set.subset_union_compl_of_inter_subset B2,
},
apply le_trans _ B5,
apply @infi_le ennreal _ _,
end
},
{
simp,
intros h C1,
let g := λ n:ℕ, h n ∩ S,
begin
have C2:g = λ n:ℕ, h n ∩ S := rfl,
have C3:μ (T ∩ S) ≤ μ(set.Union g),
{
apply measure_theory.outer_measure.mono',
rw C2,
rw set.Union_inter_eq_inter_Union,
rw set.inter_comm S,
simp,
apply set.subset.trans _ C1,
simp,
},
apply le_trans C3,
have C4:μ(set.Union g) ≤ ∑' (i:ℕ), μ (g i),
{
apply measure_theory.outer_measure.Union,
},
apply le_trans C4,
apply ennreal.tsum_le_tsum,
intro n,
cases (classical.em (is_measurable (h n))) with C5 C5,
{
apply le_trans _ (measure_theory.le_extend _ C5),
rw C2,
apply le_refl _,
},
{
rw measure_theory.extend_top C5,
simp,
},
end
},
end
lemma measure_theory.measure.to_outer_measure.restrict' {Ω:Type*} [measurable_space Ω]
{μ:measure_theory.measure Ω} {S:set Ω}:is_measurable S →
(μ.restrict S).to_outer_measure = measure_theory.outer_measure.restrict S (μ.to_outer_measure) :=
begin
intros A1,
apply measure_theory.outer_measure.ext,
intro T,
rw measure_theory.outer_measure.restrict_apply,
simp,
unfold measure_theory.measure.restrict,
unfold measure_theory.measure.restrictₗ,
rw measure_theory.measure.lift_linear_def,
rw measure.apply,
rw measure_theory.to_measure_to_outer_measure,
--rw measure_theory.outer_measure.to_measure_to_outer_measure_eq_trim,
rw measure_theory.outer_measure.restrict_trimmed_of_trimmed A1,
simp,
apply measure_theory.measure.trimmed,
end
lemma compose_image {α β γ:Type*} {f:α → β} {g:β → γ} {S:set α}:
g '' (f '' S) = (g ∘ f) '' S :=
begin
ext c,
split;
intros B1;simp;simp at B1;apply B1,
end
lemma measure_theory.measure.Inf_restrict {Ω:Type*} [measurable_space Ω]
(S:set (measure_theory.measure Ω)) {T:set Ω}:S.nonempty → is_measurable T →
(Inf S).restrict T = Inf ((λ μ:measure_theory.measure Ω,μ.restrict T) '' S) :=
begin
intros AX A1,
apply measure_theory.measure.ext,
intros S2 B1,
rw measure_theory.measure.Inf_apply B1,
rw measure_theory.measure.restrict_apply B1,
rw measure_theory.measure.Inf_apply (is_measurable.inter B1 A1),
have B3:(measure_theory.measure.to_outer_measure '' ((λ (μ : measure_theory.measure Ω), μ.restrict T) '' S))
= (measure_theory.outer_measure.restrict T) ''( measure_theory.measure.to_outer_measure '' S),
{
rw compose_image,
rw compose_image,
have B3A:(measure_theory.measure.to_outer_measure ∘ λ (μ : measure_theory.measure Ω), μ.restrict T) = (measure_theory.outer_measure.restrict T) ∘ (measure_theory.measure.to_outer_measure),
{
apply funext,
intro μ,
simp,
apply measure_theory.measure.to_outer_measure.restrict',
apply A1,
},
rw B3A,
},
rw B3,
rw ← measure_theory.outer_measure.Inf_restrict _ A1,
rw measure_theory.outer_measure.restrict_apply,
apply set.nonempty_image_of_nonempty,
apply AX,
end
lemma set.subset_self {α:Type*} (S:set α):S ⊆ S :=
begin
rw set.subset_def,
intros x A1,
apply A1,
end
lemma measure_theory.measure.restrict_le_restrict_of_le {Ω:Type*} [measurable_space Ω]
(μ ν:measure_theory.measure Ω) {S:set Ω}:
μ ≤ ν → μ.restrict S ≤ ν.restrict S :=
begin
intros A1,
apply measure_theory.measure.restrict_mono,
apply set.subset_self,
apply A1,
end
lemma measure_theory.measure_partition_apply {Ω:Type*} [M:measurable_space Ω]
(μ:measure_theory.measure Ω) (S T:set Ω):is_measurable S → is_measurable T →
μ T = μ (S ∩ T) + μ (Sᶜ ∩ T) :=
begin
intros A1 A2,
rw set.inter_comm,
rw set.inter_comm Sᶜ,
have B1:T = (T∩ S) ∪ (T∩ Sᶜ),
{
rw set.union_inter_compl,
},
--have B2:μ T =
rw ← @measure_theory.measure_union Ω M μ (T∩ S) _,
rw ← B1,
apply set.disjoint_inter_compl,
apply is_measurable.inter,
apply A2,
apply A1,
apply is_measurable.inter,
apply A2,
apply is_measurable.compl,
apply A1,
end
lemma measure_theory.measure.le_of_partition {Ω:Type*} [M:measurable_space Ω]
(μ ν:measure_theory.measure Ω) {S T:set Ω}:is_measurable S →
is_measurable T →
μ (S ∩ T) ≤ ν (S ∩ T) →
μ (Sᶜ ∩ T) ≤ ν (Sᶜ ∩ T) →
μ T ≤ ν T :=
begin
intros A1 A2 A3 A4,
rw measure_theory.measure_partition_apply μ S T,
rw measure_theory.measure_partition_apply ν S T,
have B1:μ (S ∩ T) + μ (Sᶜ ∩ T) ≤ ν (S ∩ T) + μ (Sᶜ ∩ T),
{
apply add_le_add_right A3,
},
apply le_trans B1,
apply add_le_add_left A4,
repeat {assumption},
end
lemma Inf_le_Inf' {α:Type*} [complete_lattice α] {S T:set α}:(∀ t∈ T, ∃ s∈ S,
s ≤ t) → Inf S ≤ Inf T :=
begin
intros A1,
apply @le_Inf,
intros t B1,
have B2 := A1 t B1,
cases B2 with s B2,
cases B2 with B2 B3,
apply le_trans _ B3,
apply @Inf_le,
apply B2
end
lemma measure_theory.outer_measure.le_top_caratheodory {Ω:Type*} [M:measurable_space Ω]:
M ≤ (⊤:measure_theory.outer_measure Ω).caratheodory :=
begin
rw measure_theory.outer_measure.top_caratheodory,
simp
end
lemma measure_theory.measure.of_measurable_apply' {α:Type*} [M:measurable_space α]
(m : Π (s : set α), is_measurable s → ennreal)
(m0 : m ∅ is_measurable.empty = 0)
(mU : ∀ {{f : ℕ → set α}} (h : ∀i, is_measurable (f i)),
pairwise (disjoint on f) →
m (⋃i, f i) (is_measurable.Union h) = (∑'i, m (f i) (h i))) (S:set α):
measure_theory.measure.of_measurable m m0 mU S =
measure_theory.induced_outer_measure m _ m0 S :=
begin
unfold measure_theory.measure.of_measurable,
simp,
rw measure.apply,
end
lemma measure_theory.outer_measure.top_eq {Ω:Type*} [M:measurable_space Ω]:
⇑(⊤:measure_theory.outer_measure Ω) = (λ (s:set Ω), (@ite (s=∅) (classical.prop_decidable (s=∅)) ennreal 0 ⊤)) :=
begin
apply funext,
intro S,
cases (classical.em (S = ∅)) with B1 B1,
{
rw if_pos,
subst S,
apply measure_theory.outer_measure.empty',
apply B1,
},
{
rw if_neg,
apply measure_theory.outer_measure.top_apply,
rw ← set.ne_empty_iff_nonempty,
apply B1,
apply B1,
},
end
lemma measure_theory.outer_measure.extend_top {Ω:Type*} [M:measurable_space Ω]:
(measure_theory.extend (λ (s : set Ω) (_x : is_measurable s), (⊤:measure_theory.outer_measure Ω) s))=(λ (s:set Ω), (@ite (s=∅) (classical.prop_decidable (s=∅)) ennreal 0 ⊤)) :=
begin
apply funext,
intro S,
rw measure_theory.outer_measure.top_eq,
cases (classical.em (is_measurable S)) with B1 B1,
{
unfold measure_theory.extend,
rw infi_prop_def,
apply B1,
},
{
unfold measure_theory.extend,
rw infi_prop_false,
rw if_neg,
intros B2,
apply B1,
subst S,
simp,
apply B1,
},
end
lemma measure_theory.outer_measure.extend_top' {Ω:Type*} [M:measurable_space Ω]:
(measure_theory.extend (λ (s : set Ω) (_x : is_measurable s), (⊤:measure_theory.outer_measure Ω) s))=(⊤:measure_theory.outer_measure Ω) :=
begin
rw measure_theory.outer_measure.extend_top,
rw measure_theory.outer_measure.top_eq,
end
lemma subst_apply_empty_zero {Ω:Type*} {f g:set Ω → ennreal}:(f = g) → (f ∅ = 0) → (g ∅ = 0) :=
begin
intros A1 A2,
subst f,
apply A2,
end
lemma measure_theory.outer_measure.of_function_subst {Ω:Type*} [M:measurable_space Ω]
{f g:set Ω → ennreal} {P:f ∅ = 0} (H:f = g):
measure_theory.outer_measure.of_function f P =
measure_theory.outer_measure.of_function g (subst_apply_empty_zero H P) :=
begin
subst g,
end
lemma measure_theory.outer_measure.of_function_eq' {Ω:Type*} [M:measurable_space Ω]
{μ:measure_theory.outer_measure Ω} (H:μ ∅ = 0):
measure_theory.outer_measure.of_function (⇑μ) H = μ :=
begin
apply measure_theory.outer_measure.ext,
intro S,
apply measure_theory.outer_measure.of_function_eq,
{
intros T B1,
apply measure_theory.outer_measure.mono',
apply B1,
},
{
intros f,
apply measure_theory.outer_measure.Union_nat,
},
end
lemma measure_theory.outer_measure.top_eq_trim {Ω:Type*} [M:measurable_space Ω]:
(⊤:measure_theory.outer_measure Ω).trim = ⊤ :=
begin
unfold measure_theory.outer_measure.trim,
unfold measure_theory.induced_outer_measure,
have B1:= @measure_theory.outer_measure.extend_top' Ω M,
rw measure_theory.outer_measure.of_function_subst B1,
rw measure_theory.outer_measure.of_function_eq',
end
lemma measure_theory.outer_measure.top_to_measure_to_outer_measure_eq_top {Ω:Type*} [M:measurable_space Ω]:
((⊤:measure_theory.outer_measure Ω).to_measure measure_theory.outer_measure.le_top_caratheodory).to_outer_measure = ⊤ :=
begin
apply measure_theory.outer_measure.ext,
intro S,
unfold measure_theory.outer_measure.to_measure,
simp,
rw measure_theory.measure.of_measurable_apply',
unfold measure_theory.induced_outer_measure,
have B1:= @measure_theory.outer_measure.extend_top' Ω M,
rw measure_theory.outer_measure.of_function_subst B1,
rw measure_theory.outer_measure.of_function_eq',
end
/-
One could extract many monotone relationships from this:
induced_outer_measure, extend, of_function, et cetera.
However, I wouldn't be surprised to find them in the library.
-/
lemma measure_theory.outer_measure.trim_monotone {Ω:Type*} [M:measurable_space Ω]
(μ ν:measure_theory.outer_measure Ω):μ ≤ ν → μ.trim ≤ ν.trim :=
begin
intros A1,
rw outer_measure_measure_of_le,
unfold measure_theory.outer_measure.trim,
unfold measure_theory.induced_outer_measure,
unfold measure_theory.outer_measure.of_function,
intros S,
simp,
intros f B1,
have B2:(∑' (i : ℕ), measure_theory.extend (λ (s : set Ω) (_x : is_measurable s), μ s) (f i)) ≤
∑' (i : ℕ), measure_theory.extend (λ (s : set Ω) (_x : is_measurable s), ν s) (f i),
{
apply ennreal.tsum_le_tsum,
unfold measure_theory.extend,
intros n,
simp,
intros B2A,
rw infi_prop_def,
apply A1,
apply B2A,
},
apply le_trans _ B2,
have B3:(⨅ (h : S ⊆ ⋃ (i : ℕ), f i),(∑' (i : ℕ), measure_theory.extend (λ (s : set Ω) (_x : is_measurable s), μ s) (f i))) = ∑' (i : ℕ), measure_theory.extend (λ (s : set Ω) (_x : is_measurable s), μ s) (f i),
{
rw infi_prop_def,
apply B1,
},
rw ← B3,
apply @infi_le ennreal _ _,
end
lemma measure_theory.measure.to_outer_measure_eq_top {Ω:Type*} [M:measurable_space Ω]:
(⊤:measure_theory.measure Ω).to_outer_measure = ⊤ :=
begin
rw ← measure_theory.measure.trimmed,
rw ← @top_le_iff (measure_theory.outer_measure Ω) _,
have B1:((⊤:measure_theory.outer_measure Ω).to_measure measure_theory.outer_measure.le_top_caratheodory).to_outer_measure.trim ≤ (⊤:measure_theory.measure Ω).to_outer_measure.trim,
{
apply measure_theory.outer_measure.trim_monotone,
apply measure_theory.measure.to_outer_measure_le.mpr,
simp
},
rw measure_theory.outer_measure.top_to_measure_to_outer_measure_eq_top at B1,
rw measure_theory.outer_measure.top_eq_trim at B1,
apply B1,
end
lemma measure_theory.measure.top_apply {Ω:Type*} [M:measurable_space Ω]
{S:set Ω}:S.nonempty → (⊤:measure_theory.measure Ω)(S) = (⊤:ennreal) :=
begin
intro A1,
rw measure.apply,
rw measure_theory.measure.to_outer_measure_eq_top,
simp,
rw measure_theory.outer_measure.top_apply A1,
end
lemma measure_theory.measure.le_add {Ω:Type*} [M:measurable_space Ω] {μ ν:measure_theory.measure Ω}:μ ≤ μ + ν :=
begin
rw measure_theory.measure.le_iff,
intros S B1,
simp,
apply le_add_nonnegative _ _,
end
lemma measure_theory.measure.sub_restrict_comm {Ω:Type*} [M:measurable_space Ω]
(μ ν:measure_theory.measure Ω) {S:set Ω}:is_measurable S →
(μ - ν).restrict S = (μ.restrict S) - (ν.restrict S) :=
begin
intro A1,
rw measure_theory.measure.sub_def,
rw measure_theory.measure.sub_def,
have G1:{d : measure_theory.measure Ω | μ ≤ d + ν}.nonempty,
{
apply @set.nonempty_of_mem _ _ μ,
simp,
apply measure_theory.measure.le_add,
},
rw measure_theory.measure.Inf_restrict _ G1 A1,
apply le_antisymm,
{
apply @Inf_le_Inf' (measure_theory.measure Ω) _,
intros t B1,
simp at B1,
apply exists.intro (t.restrict S),
split,
{
simp,
apply exists.intro (t + (⊤:measure_theory.measure Ω).restrict Sᶜ),
split,
{
rw add_assoc,
rw add_comm _ ν,
rw ← add_assoc,
rw measure_theory.measure.le_iff,
intros T E1,
have E2:is_measurable (S ∩ T) := is_measurable.inter A1 E1,
--rw measure_theory.measure.add_apply,
apply measure_theory.measure.le_of_partition _ _ A1 E1;
rw measure_theory.measure.add_apply,
{
rw measure_theory.measure.restrict_apply E2,
rw set.inter_assoc,
rw set.inter_comm _ Sᶜ,
rw ← set.inter_assoc,
rw set.inter_compl_self,
simp,
rw measure_theory.measure.le_iff at B1,
have B2 := B1 (S ∩ T) E2,
rw measure_theory.measure.add_apply at B2,
rw measure_theory.measure.restrict_apply E2 at B2,
rw measure_theory.measure.restrict_apply E2 at B2,
have E3:S ∩ T ∩ S = S ∩ T,
{
rw set.inter_eq_self_of_subset_left,
apply set.inter_subset_left S T,
},
rw E3 at B2,
apply B2,
},
cases (@set.eq_empty_or_nonempty _ (Sᶜ ∩ T)) with E4 E4,
{
rw E4,
simp,
},
{
rw measure_theory.measure.restrict_apply,
have E5:Sᶜ ∩ T ∩ Sᶜ = Sᶜ ∩ T,
{
rw set.inter_eq_self_of_subset_left,
apply set.inter_subset_left Sᶜ T,
},
rw E5,
have E6:(⊤:measure_theory.measure Ω)(Sᶜ ∩ T) = (⊤:ennreal),
{
apply measure_theory.measure.top_apply,
apply E4,
},
rw E6,
simp,
apply is_measurable.inter (is_measurable.compl A1) E1,
},
},
{
apply measure_theory.measure.ext,
intros T D1,
rw measure_theory.measure.restrict_apply D1,
rw measure_theory.measure.restrict_apply D1,
rw measure_theory.measure.add_apply,
rw measure_theory.measure.restrict_apply (is_measurable.inter D1 A1),
have D2:T ∩ S ∩ Sᶜ = ∅,
{
rw set.inter_assoc,
simp,
},
rw D2,
simp,
},
},
{
apply measure_theory.measure.restrict_le_self,
},
},
{
apply @Inf_le_Inf' (measure_theory.measure Ω) _,
intros s C1,
simp at C1,
cases C1 with t C1,
cases C1 with C1 C2,
subst s,
apply exists.intro (t.restrict S),
split,
{
simp,
rw ← measure_theory.measure.restrict_add,
apply measure_theory.measure.restrict_le_restrict_of_le,
apply C1,
},
{
apply le_refl _,
},
},
end
lemma jordan_decomposition_junior_zero {Ω:Type*} [measurable_space Ω]
(μ ν:measure_theory.measure Ω) (S:set Ω)
-- [measure_theory.finite_measure ν]
:le_on_subsets μ ν S →
(μ - ν) S = 0 :=
begin
intro A1,
have B1 := le_on_subsets_is_measurable A1,
rw ← measure_theory.measure.restrict_apply_self _ B1,
rw measure_theory.measure.sub_restrict_comm,
rw measure_theory.measure.sub_eq_zero_if_le,
simp,
apply restrict_le_restrict_of_le_on_subsets _ _ A1,
apply B1,
end
--This works with EITHER ν or μ being finite, or even ν S < ⊤.
lemma jordan_decomposition_junior_apply {Ω:Type*} [measurable_space Ω]
(μ ν:measure_theory.measure Ω) (S:set Ω) [AX:measure_theory.finite_measure ν]:
le_on_subsets ν μ S →
(μ - ν) S = μ S - ν S :=
begin
intros A1,
have B1 := le_on_subsets_is_measurable A1,
rw ← measure_theory.measure.restrict_apply_self _ B1,
rw measure_theory.measure.sub_restrict_comm,
have B2:measure_theory.finite_measure (ν.restrict S),
{
apply measure_theory.finite_measure_restrict,
},
rw @measure_theory.measure.sub_apply Ω _ _ _ S B2,
rw measure_theory.measure.restrict_apply_self,
rw measure_theory.measure.restrict_apply_self,
apply B1,
apply B1,
apply B1,
{
--rw le_on_subsets_def at A1,
apply restrict_le_restrict_of_le_on_subsets,
apply A1,
},
apply B1,
end
/-
A jordan decomposition of subtraction.
-/
lemma jordan_decomposition_nonneg_sub {Ω:Type*} [measurable_space Ω]
(μ ν:measure_theory.measure Ω) (S T:set Ω) [A1:measure_theory.finite_measure μ]:
is_measurable T → (le_on_subsets μ ν S) → (le_on_subsets ν μ Sᶜ) →
(ν - μ) T = ν (S ∩ T) - μ (S ∩ T) :=
begin
intros A3 A4 A5,
have A2:is_measurable S,
{
apply le_on_subsets_is_measurable A4,
},
have B1:(ν - μ) T = (ν - μ) (S∩ T) + (ν - μ) (Sᶜ ∩ T),
{
rw measure_theory.measure_partition_apply,
apply A2,
apply A3,
},
have B2:(ν - μ) (S∩ T) = ν (S ∩ T) - μ (S ∩ T),
{
apply jordan_decomposition_junior_apply,
apply le_on_subsets_subset _ _ _ _ A4,
simp,
apply is_measurable.inter A2 A3,
},
have B3:(ν - μ) (Sᶜ ∩ T) = 0,
{
apply jordan_decomposition_junior_zero,
apply le_on_subsets_subset _ _ _ _ A5,
simp,
apply is_measurable.inter (is_measurable.compl A2) A3,
},
rw B1,
rw B2,
rw B3,
rw add_zero,
end
lemma jordan_decomposition_nonneg_sub' {Ω:Type*} [measurable_space Ω]
(μ ν:measure_theory.measure Ω) (S:set Ω) (T:set Ω)
[A1:measure_theory.finite_measure μ]:
(le_on_subsets μ ν S) → (le_on_subsets ν μ Sᶜ) →
(is_measurable T) →
(ν - μ) T = (ν.restrict S) T - (μ.restrict S) T :=
begin
intros A2 A3 B1,
rw jordan_decomposition_nonneg_sub μ ν S T B1 A2 A3,
rw measure_theory.measure.restrict_apply B1,
rw measure_theory.measure.restrict_apply B1,
rw set.inter_comm T,
end
lemma measure_theory.measure.add_compl_inter {Ω:Type*} [measurable_space Ω]
(μ:measure_theory.measure Ω) (S T:set Ω):(is_measurable S) →
(is_measurable T) →
(μ T = μ (S ∩ T) + μ (Sᶜ ∩ T)) :=
begin
intros A1 A2,
have A3:T = (S∩ T) ∪ (Sᶜ ∩ T),
{
rw ← set.inter_distrib_right,
rw set.union_compl_self,
simp,
},
have A4:μ T = μ ( (S∩ T) ∪ (Sᶜ ∩ T)),
{
rw ← A3,
},
rw A4,
rw measure_theory.measure_union,
rw set.inter_comm,
rw set.inter_comm _ T,
apply set.disjoint_inter_compl,
apply is_measurable.inter A1 A2,
apply is_measurable.inter (is_measurable.compl A1) A2,
end
lemma le_on_subsets_inter {Ω:Type*} [measurable_space Ω]
{μ ν:measure_theory.measure Ω} {T U:set Ω}:is_measurable U →
le_on_subsets μ ν T → μ (T ∩ U) ≤ ν (T ∩ U) :=
begin
intros A1 A2,
rw le_on_subsets_def at A2,
apply A2.right,
simp,
apply is_measurable.inter A2.left A1,
end
--This may be gotten by easier methods.
lemma measure_theory.measure.sub_le_sub {Ω:Type*} [measurable_space Ω]
(μ ν:measure_theory.measure Ω) (T:set Ω) [A1:measure_theory.finite_measure μ]:
is_measurable T → (ν T - μ T) ≤ (ν - μ) T :=
begin
intros A2,
have B1 := hahn_unsigned_inequality_decomp ν μ,
cases B1 with U B1,
have C1 := le_on_subsets_is_measurable B1.left,
rw jordan_decomposition_nonneg_sub μ ν Uᶜ,
{
have C2:ν T = ν (U ∩ T) + ν (Uᶜ ∩ T),
{
apply measure_theory.measure.add_compl_inter _ _ _ C1 A2,
},
rw C2,
have C3:μ T = μ (U ∩ T) + μ (Uᶜ ∩ T),
{
apply measure_theory.measure.add_compl_inter _ _ _ C1 A2,
},
rw C3,
simp,
rw add_comm (μ (U ∩ T)) (μ (Uᶜ ∩ T)),
rw ← add_assoc,
have C4:ν (Uᶜ ∩ T) ≤ ν (Uᶜ ∩ T) - μ (Uᶜ ∩ T) + μ (Uᶜ ∩ T),
{
apply ennreal.le_sub_add_self,
},
have C5 := add_le_add_right C4 (μ (U ∩ T)),
apply le_trans _ C5,
rw add_comm,
apply add_le_add_left _ _,
apply le_on_subsets_inter A2 B1.left,
},
--apply A1,---???
apply A2,
apply B1.right,
simp,
apply B1.left,
end
lemma measure_theory.measure.is_support_def {α:Type*} [measurable_space α]
(μ:measure_theory.measure α) (S:set α):
μ.is_support S = (is_measurable S ∧ μ (Sᶜ) = 0) := rfl
def measure_theory.measure.perpendicular {α:Type*} [measurable_space α]
(μ ν:measure_theory.measure α):Prop :=
(∃ S T:set α, μ.is_support S ∧ ν.is_support T ∧
disjoint S T)
lemma measure_theory.measure.perpendicular_def {α:Type*} [measurable_space α]
(μ ν:measure_theory.measure α):μ.perpendicular ν =
(∃ S T:set α, μ.is_support S ∧ ν.is_support T ∧
disjoint S T) := rfl
lemma measure_theory.measure.perpendicular_def2 {α:Type*} [measurable_space α]
(μ ν:measure_theory.measure α):μ.perpendicular ν ↔
(∃ S:set α, is_measurable S ∧ μ S = 0 ∧ ν (Sᶜ) = 0) :=
begin
rw measure_theory.measure.perpendicular_def,
split;intros B1,
{
cases B1 with S B1,
cases B1 with T B1,
cases B1 with B1 B2,
cases B2 with B2 B3,
rw measure_theory.measure.is_support_def at B1,
rw measure_theory.measure.is_support_def at B2,
apply exists.intro T,
split,
{
apply B2.left,
},
split,
{
cases B1 with C1 C2,
rw ← ennreal.le_zero_iff,
rw ← ennreal.le_zero_iff at C2,
apply le_trans _ C2,
apply measure_theory.measure_mono,
rw set.disjoint_iff_inter_eq_empty at B3,
rw set.inter_comm at B3,
rw ← set.subset_compl_iff_disjoint at B3,
apply B3,
},
{
apply B2.right,
},
},
{
cases B1 with S B1,
apply exists.intro Sᶜ,
apply exists.intro S,
split,
{
rw measure_theory.measure.is_support_def,
apply and.intro (is_measurable.compl (B1.left)),
simp,
apply B1.right.left,
},
split,
{
rw measure_theory.measure.is_support_def,
apply and.intro (B1.left) (B1.right.right),
},
{
rw set.disjoint_iff_inter_eq_empty,
rw ← set.subset_compl_iff_disjoint,
apply set.subset.refl Sᶜ,
},
},
end
lemma measure_theory.measure.perpendicular_intro {α:Type*} [measurable_space α]
(μ ν:measure_theory.measure α) {S:set α}:is_measurable S →
μ S = 0 → ν (Sᶜ) = 0 →
μ.perpendicular ν :=
begin
intros A1 A2 A3,
rw measure_theory.measure.perpendicular_def2,
apply exists.intro S (and.intro A1 (and.intro A2 A3)),
end
lemma measure_theory.measure.not_perpendicular {α:Type*} [measurable_space α]
(μ ν:measure_theory.measure α) {S:set α}:(¬(μ.perpendicular ν)) → is_measurable S →
μ S = 0 → 0 < ν (Sᶜ) :=
begin
intros A1 A2 A3,
rw zero_lt_iff_ne_zero,
intros A4,
apply A1,
apply measure_theory.measure.perpendicular_intro μ ν A2 A3 A4,
end
lemma measure_theory.measure.perpendicular_symmetric' {α:Type*} [measurable_space α]
(μ ν:measure_theory.measure α):(μ.perpendicular ν) →
(ν.perpendicular μ) :=
begin
intro A1,
rw measure_theory.measure.perpendicular_def2,
rw measure_theory.measure.perpendicular_def2 at A1,
cases A1 with S A1,
apply exists.intro Sᶜ,
apply and.intro (is_measurable.compl A1.left),
apply and.intro A1.right.right,
simp,
apply A1.right.left,
end
lemma measure_theory.measure.perpendicular_symmetric {α:Type*} [measurable_space α]
(μ ν:measure_theory.measure α):(μ.perpendicular ν) ↔
(ν.perpendicular μ) :=
begin
split;apply measure_theory.measure.perpendicular_symmetric',
end
lemma measure_theory.measure.perpendicular_of_le {α:Type*}
[measurable_space α] {μ ν ν':measure_theory.measure α}:μ.perpendicular ν →
ν' ≤ ν → μ.perpendicular ν' :=
begin
intros A1 A2,
rw measure_theory.measure.perpendicular_def2,
rw measure_theory.measure.perpendicular_def2 at A1,
cases A1 with S A1,
apply exists.intro S,
apply and.intro A1.left,
apply and.intro (A1.right.left),
rw ← ennreal.le_zero_iff,
rw ← A1.right.right,
apply A2,
apply is_measurable.compl (A1.left),
end
lemma measure_theory.measure.sub_le {α:Type*}
[measurable_space α] {μ ν:measure_theory.measure α}:μ - ν ≤ μ :=
begin
rw measure_theory.measure.sub_def,
apply @Inf_le (measure_theory.measure α) _ _,
simp,
apply measure_theory.measure.le_add,
end
lemma measure_theory.measure.perpendicular_of_sub {α:Type*} [measurable_space α]
{μ ν ν':measure_theory.measure α}:μ.perpendicular ν → (μ.perpendicular (ν - ν')) :=
begin
intros A1,
apply measure_theory.measure.perpendicular_of_le A1,
apply measure_theory.measure.sub_le,
end
lemma measure_theory.measure.smul_finite {α:Type*} [measurable_space α]
{μ:measure_theory.measure α} {ε:ennreal} [measure_theory.finite_measure μ]:
ε ≠ ⊤ → (measure_theory.finite_measure (ε• μ)) :=
begin
intros A1,
apply measure_theory.finite_measure_of_lt_top,
rw ennreal_smul_measure_apply,
apply ennreal.mul_lt_top,
rw lt_top_iff_ne_top,
apply A1,
apply measure_theory.measure_lt_top,
--apply A2,
simp,
end
lemma set.compl_Union_eq_Inter_compl {α β:Type*} {f:α → set β}:(⋃ n, f n)ᶜ = (⋂ n, (f n)ᶜ) :=
begin
ext b,
split;intros A1;simp;simp at A1;apply A1,
end
lemma le_on_subsets_of_zero {α:Type*} [measurable_space α] {μ:measure_theory.measure α}
(ν:measure_theory.measure α) {S:set α}:is_measurable S → μ S = 0 → le_on_subsets μ ν S :=
begin
intros A1 A2,
rw le_on_subsets_def,
apply and.intro A1,
intros X B1 B2,
have B3:μ X ≤ μ S,
{
apply measure_theory.measure_mono,
apply B1,
},
apply le_trans B3,
rw A2,
simp,
end
lemma measure_theory.measure.sub_zero_eq_self {α:Type*} [measurable_space α] {μ ν:measure_theory.measure α} {S:set α} [A2:measure_theory.finite_measure μ]:is_measurable S →
μ S = 0 →
(ν - μ) S = ν S :=
begin
intros A1 A4,
have B1 := le_on_subsets_of_zero ν A1 A4,
rw jordan_decomposition_junior_apply,
rw A4,
simp,
--apply A2,
apply B1,
end
lemma measure_theory.measure.perpendicular_of {α:Type*} [M:measurable_space α]
{μ ν:measure_theory.measure α} [A2:measure_theory.finite_measure μ]
[A3:measure_theory.finite_measure ν]:
(∀ ε:ennreal, ε > 0 → μ.perpendicular (ν - (ε • μ)) ) →
μ.perpendicular ν :=
begin
intros A1,
have B1:∀ n:ℕ,(∃ S:set α, is_measurable S ∧ μ S = 0 ∧
(ν - ((1/((n:ennreal) + 1))• μ)) (Sᶜ) = 0),
{
intros n,
have B1A:(1/((n:ennreal) + 1))>0,
{
apply ennreal.unit_frac_pos,
},
have B1B := A1 _ B1A,
rw measure_theory.measure.perpendicular_def2 at B1B,
apply B1B,
},
have B2 := classical.some_func B1,
cases B2 with f B2,
let T := ⋃ n, f n,
begin
have C1:T = ⋃ n, f n := rfl,
have C2:Tᶜ = ⋂ n, (f n)ᶜ,
{
rw C1,
rw set.compl_Union_eq_Inter_compl,
},
have C3:is_measurable T,
{
rw C1,
apply is_measurable.Union,
intro n,
apply (B2 n).left,
},
have C4:is_measurable Tᶜ,
{
apply is_measurable.compl C3,
},
have I1:∀ (n:ℕ), Tᶜ ⊆ (f n)ᶜ,
{
intro n,
rw C2,
apply @set.Inter_subset α ℕ (λ n, (f n)ᶜ),
},
have I2:∀ (n:ℕ), μ Tᶜ ≤ μ (f n)ᶜ,
{
intro n,
apply @measure_theory.measure_mono α M μ _ _ (I1 n),
},
apply @measure_theory.measure.perpendicular_intro α _ μ ν T,
{
apply is_measurable.Union,
intro n,
apply (B2 n).left,
},
{
rw C1,
rw ← ennreal.le_zero_iff,
have D1:=@measure_theory.measure.Union_nat α _ μ f,
apply le_trans D1,
rw ennreal.le_zero_iff,
have E1:(λ n, μ (f n)) = (λ (n:ℕ), (0:ennreal)),
{
apply funext,
intro n,
apply (B2 n).right.left,
},
rw E1,
simp,
},
{
--rw C2,
have H1:ν (Tᶜ)/(μ (Tᶜ)) = 0,
{
apply ennreal.zero_of_le_all_unit_frac,
intro n,
apply ennreal.div_le_of_le_mul,
have H1X:measure_theory.finite_measure ((1 / ((n:ennreal) + 1)) • μ),
{
apply measure_theory.measure.smul_finite,
{
apply ennreal.unit_frac_ne_top,
},
},
--have H1B := H1A n,
have H1B:(ν) Tᶜ - ((1 / ((n:ennreal) + 1)) • μ) Tᶜ ≤
(ν - (1 / ((n:ennreal) + 1)) • μ) Tᶜ,
{
apply @measure_theory.measure.sub_le_sub α M ((1 / ((n:ennreal) + 1)) • μ) ν
Tᶜ H1X C4,
},
have H1C:(ν) Tᶜ - ((1 / ((n:ennreal) + 1)) • μ) Tᶜ = 0,
--have H1B:(ν - (1 / ((n:ennreal) + 1)) • μ) Tᶜ = 0,
{
rw ← ennreal.le_zero_iff,
apply le_trans H1B,
rw ← (B2 n).right.right,
apply measure_theory.measure_mono (I1 n),
},
rw ennreal_smul_measure_apply at H1C,
apply ennreal.le_of_sub_eq_zero,
apply H1C,
apply C4,
},
rw ennreal.div_eq_zero_iff at H1,
cases H1 with H1 H1,
{
apply H1,
},
{
exfalso,
apply measure_theory.measure_ne_top μ Tᶜ H1,
},
},
end
end
lemma measure_theory.measure.exists_of_not_perpendicular {α:Type*} [measurable_space α]
(μ:measure_theory.measure α) {ν:measure_theory.measure α} [A1:measure_theory.finite_measure μ] [A2:measure_theory.finite_measure ν]:
(¬ (μ.perpendicular ν)) →
(∃ ε:ennreal, ε > 0 ∧ ¬μ.perpendicular (ν - (ε • μ)) ) :=
begin
intros A3,
apply classical.exists_of_not_forall_not,
intros B1,
apply A3,
apply measure_theory.measure.perpendicular_of,
intros ε C1,
have C2 := B1 ε,
simp at C2,
apply C2,
apply C1,
end
lemma measure_theory.measure.sub_add_cancel_of_le {α:Type*} [measurable_space α] {μ ν:measure_theory.measure α} [measure_theory.finite_measure μ]:
μ ≤ ν → ν - μ + μ = ν :=
begin
intros A1,
apply measure_theory.measure.ext,
intros S B1,
rw measure_theory.measure.add_apply,
rw jordan_decomposition_junior_apply,
rw ennreal.sub_add_cancel_of_le,
apply A1,
apply B1,
--apply A2,
rw le_on_subsets_def,
apply and.intro B1,
intros X' C1 C2,
apply A1,
apply C2,
end
/-
This is taken from a step in Tao's proof of the Lebesgue-Radon-Nikodym Theorem.
By the Hahn Decomposition Theorem, we can find a set where μ ≤ ν and μ S > 0.
-/
lemma measure_theory.measure.perpendicular_sub_elim {α:Type*} [measurable_space α]
(μ:measure_theory.measure α) {ν:measure_theory.measure α}
[A2:measure_theory.finite_measure ν]:
¬(μ.perpendicular (ν - μ)) →
∃ (S:set α), is_measurable S ∧ le_on_subsets μ ν S ∧ 0 < μ S :=
begin
intros A3,
have B1:=hahn_unsigned_inequality_decomp μ ν,
cases B1 with X B1,
have B2 := jordan_decomposition_junior_zero ν μ Xᶜ B1.right,
have B3 := le_on_subsets_is_measurable B1.right,
have B4:¬((ν - μ).perpendicular μ),
{
intro B4A,
apply A3,
apply measure_theory.measure.perpendicular_symmetric',
apply B4A,
},
have B5 := measure_theory.measure.not_perpendicular (ν - μ) μ B4 B3 B2,
simp at B5,
apply exists.intro X,
apply and.intro (le_on_subsets_is_measurable B1.left)
(and.intro B1.left B5),
end
lemma ennreal_smul_smul_measure_assoc {Ω:Type*} [N:measurable_space Ω]
(μ:measure_theory.measure Ω) {a b:ennreal}:(a * b) • μ = a • (b • μ) :=
begin
apply measure_theory.measure.ext,
intros S B1,
repeat {rw ennreal_smul_measure_apply _ _ S B1},
rw mul_assoc,
end
lemma measure_theory.measure.perpendicular_zero {Ω:Type*} [N:measurable_space Ω] (μ:measure_theory.measure Ω):
(μ.perpendicular 0) :=
begin
rw measure_theory.measure.perpendicular_def2,
apply exists.intro (∅:set Ω),
split,
apply is_measurable.empty,
split,
apply measure_theory.measure_empty,
simp,
end
lemma measure_theory.measure.perpendicular_smul' {Ω:Type*} [N:measurable_space Ω] (μ ν:measure_theory.measure Ω) {k:ennreal}:
(μ.perpendicular ν) → (k • μ).perpendicular ν :=
begin
intros A2,
rw measure_theory.measure.perpendicular_def2,
rw measure_theory.measure.perpendicular_def2 at A2,
cases A2 with S A2,
apply exists.intro S,
apply and.intro (A2.left),
apply and.intro _ A2.right.right,
rw ennreal_smul_measure_apply,
rw A2.right.left,
simp,
apply A2.left,
end
lemma measure_theory.measure.perpendicular_smul {Ω:Type*} [N:measurable_space Ω] (μ ν:measure_theory.measure Ω) {k:ennreal}: 0 < k →
(k • μ).perpendicular ν → μ.perpendicular ν :=
begin
intros A1 A2,
rw measure_theory.measure.perpendicular_def2,
rw measure_theory.measure.perpendicular_def2 at A2,
cases A2 with S A2,
apply exists.intro S,
apply and.intro A2.left,
apply and.intro _ A2.right.right,
have B1 := A2.right.left,
rw ennreal_smul_measure_apply _ _ _ A2.left at B1,
simp at B1,
cases B1 with B1 B1,
{
exfalso,
rw zero_lt_iff_ne_zero at A1,
apply A1,
apply B1,
},
{
apply B1,
},
end
lemma measure_theory.measure.restrict_integral_eq_integral_indicator {Ω:Type*} [M:measurable_space Ω]
(μ:measure_theory.measure Ω) {S:set Ω} {f:Ω → ennreal}:
(is_measurable S) →
(μ.restrict S).integral f = μ.integral (S.indicator f) :=
begin
intros A1,
unfold measure_theory.measure.integral,
rw measure_theory.lintegral_indicator,
apply A1,
end
lemma integral_eq {Ω:Type*} [M:measurable_space Ω]
(μ:measure_theory.measure Ω) {f g:Ω → ennreal}:(f = g) →
μ.integral f = μ.integral g :=
begin
intros A1,
rw A1,
end
lemma with_density_indicator_eq_restrict {Ω:Type*} [M:measurable_space Ω]
(μ:measure_theory.measure Ω) {S:set Ω} {f:Ω → ennreal}:
(is_measurable S) →
μ.with_density (set.indicator S f) = (μ.restrict S).with_density f :=
begin
intros A1,
apply measure_theory.measure.ext,
intros T B1,
rw measure_theory.with_density_apply2,
rw measure_theory.with_density_apply2,
rw measure_theory.measure.restrict_integral_eq_integral_indicator,
{
rw set.indicator_indicator,
rw set.indicator_indicator,
rw set.inter_comm,
},
{
apply A1,
},
{
apply B1,
},
{
apply B1,
},
end
lemma scalar_as_with_density {Ω:Type*} {M:measurable_space Ω} (μ:measure_theory.measure Ω)
{k:ennreal}:
(k•μ) = μ.with_density (λ ω:Ω, k) :=
begin
apply measure_theory.measure.ext,
intros S B1,
rw with_density_const_apply,
rw ennreal_smul_measure_apply,
apply B1,
apply B1,
end
lemma with_density_indicator_eq_restrict_smul {Ω:Type*} [M:measurable_space Ω] (μ:measure_theory.measure Ω) {S:set Ω} {k:ennreal}:(is_measurable S) → μ.with_density (set.indicator S (λ ω:Ω, k)) = k • μ.restrict S :=
begin
intro A1,
rw with_density_indicator_eq_restrict,
rw scalar_as_with_density,
apply A1,
end
lemma smul_restrict_comm {Ω:Type*} [M:measurable_space Ω] (μ:measure_theory.measure Ω) {S:set Ω} {k:ennreal}:(is_measurable S) → (k • μ).restrict S = k • μ.restrict S :=
begin
intros A1,
apply measure_theory.measure.ext,
intros T B1,
rw ennreal_smul_measure_apply _ _ _ B1,
rw measure_theory.measure.restrict_apply B1,
rw measure_theory.measure.restrict_apply B1,
rw ennreal_smul_measure_apply _ _ _ (is_measurable.inter B1 A1),
end
/-
In the full version of Lebesgue-Radon-Nikodym theorem, μ is an unsigned
σ-finite measure, and ν is a signed σ-finite measure.
The first stage of the proof focuses on finite, unsigned measures
(see lebesgue_radon_nikodym_unsigned_finite). In that proof,
there is a need to prove that if two measures are not perpendicular, then there
exists some nontrivial f where μ.with_density f set.univ > 0 and
μ.with_density f ≤ ν. In Tao's An Epsilon of Room, this is to show that
taking the f which maximizes μ.with_density f set.univ subject to
μ.with_density f ≤ ν, when subtracted from ν, leaves a measure perpendicular to μ.
-/
lemma lebesgue_radon_nikodym_junior {Ω:Type*} [N:measurable_space Ω]
(μ ν:measure_theory.measure Ω) [A1:measure_theory.finite_measure μ]
[A2:measure_theory.finite_measure ν]:
¬(μ.perpendicular ν) →
∃ f:Ω → ennreal,
measurable f ∧
μ.with_density f ≤ ν ∧
0 < μ.with_density f (set.univ) :=
begin
intros A3,
have B1 := measure_theory.measure.exists_of_not_perpendicular μ A3,
cases B1 with ε B1,
have B2:¬((ε • μ).perpendicular (ν - ε • μ)),
{
intro B2A,
apply B1.right,
apply measure_theory.measure.perpendicular_smul _ _ B1.left,
apply B2A,
},
have B3 := measure_theory.measure.perpendicular_sub_elim _ B2,
cases B3 with S B3,
let f := (set.indicator S (λ ω:Ω, ε)),
begin
have C1:f = (set.indicator S (λ ω:Ω, ε)) := rfl,
apply exists.intro f,
split,
{
apply measurable_set_indicator,
apply B3.left,
apply measurable_const,
},
split,
{
rw C1,
rw with_density_indicator_eq_restrict_smul _ B3.left,
rw ← smul_restrict_comm _ B3.left,
apply le_trans _ (@measure_theory.measure.restrict_le_self _ _ _ S),
apply restrict_le_restrict_of_le_on_subsets,
apply B3.right.left,
},
{
have C2:0 < μ S,
{
have C2A := B3.right.right,
rw ennreal_smul_measure_apply _ _ _ B3.left at C2A,
simp at C2A,
apply C2A.right,
},
rw C1,
rw with_density_indicator_eq_restrict_smul _ B3.left,
rw ennreal_smul_measure_apply _ _ _ (is_measurable.univ),
rw measure_theory.measure.restrict_apply is_measurable.univ,
simp,
apply and.intro (B1.left) C2,
},
end
end
lemma set.indicator_sup {Ω:Type*} {x y:Ω → ennreal} {S:set Ω}:
(∀ ω∈ S, x ω ≤ y ω) →
set.indicator S (x ⊔ y) = set.indicator S y :=
begin
intros A1,
apply funext,
intro ω,
cases (classical.em (ω ∈ S)) with B1 B1,
{
repeat {rw set.indicator_of_mem B1},
simp,
rw max_eq_right,
apply A1,
apply B1,
},
{
repeat {rw set.indicator_of_not_mem B1},
},
end
lemma sup_indicator_partition {α:Type*} {x y:α → ennreal}:
(x ⊔ y) = set.indicator {ω|y ω < x ω} x + set.indicator {ω|x ω ≤ y ω} y :=
begin
apply funext,
intro a,
simp,
cases (classical.em (x a ≤ y a)) with B1 B1,
{
rw max_eq_right B1,
rw set.indicator_of_not_mem,
rw set.indicator_of_mem,
simp,
apply B1,
simp,
apply B1,
},
{
have B2:=lt_of_not_le B1,
have B3:=le_of_lt B2,
rw max_eq_left B3,
rw set.indicator_of_mem,
rw set.indicator_of_not_mem,
simp,
apply B1,
apply B2,
},
end
lemma with_density_le_sup_apply {Ω:Type*} {M:measurable_space Ω} (μ:measure_theory.measure Ω)
{x y:Ω → ennreal} {S:set Ω}:
(is_measurable S) →
(∀ ω∈ S, x ω ≤ y ω) →
μ.with_density (x ⊔ y) S =
μ.with_density y S :=
begin
intros A3 A4,
rw measure_theory.with_density_apply2 _ _ _ A3,
rw measure_theory.with_density_apply2 _ _ _ A3,
rw set.indicator_sup A4,
end
lemma le_on_subsets_with_density_of_le {Ω:Type*} {M:measurable_space Ω} (μ:measure_theory.measure Ω)
{x y:Ω → ennreal} {S:set Ω}:
(is_measurable S) →
(∀ ω∈ S, x ω ≤ y ω) →
le_on_subsets (μ.with_density x) (μ.with_density y) S :=
begin
intros A3 A4,
rw le_on_subsets_def,
apply and.intro A3,
intros X' B1 B2,
apply with_density_le_with_density B2,
intros ω C1,
apply A4 ω,
apply B1,
apply C1,
end
lemma measure_theory.measure.sup_def {Ω:Type*} [measurable_space Ω] {μ ν:measure_theory.measure Ω}:μ ⊔ ν = Inf {d|μ ≤ d ∧ ν ≤ d} := rfl
lemma measure_theory.measure.le_sup {Ω:Type*} [measurable_space Ω] {μ ν d:measure_theory.measure Ω}:(∀ c, μ ≤ c → ν ≤ c → d ≤ c) → d ≤ μ ⊔ ν :=
begin
rw measure_theory.measure.sup_def,
intro A1,
apply @le_Inf (measure_theory.measure Ω) _,
intros c B1,
apply A1;simp at B1,
apply B1.left,
apply B1.right,
end
lemma measure_theory.measure.le_restrict_add_restrict {Ω:Type*} [measurable_space Ω] {μ ν:measure_theory.measure Ω}
{S:set Ω}:le_on_subsets μ ν S → le_on_subsets ν μ Sᶜ →
μ ≤ μ.restrict Sᶜ + ν.restrict S :=
begin
intros A1 A2,
have B1:is_measurable S := le_on_subsets_is_measurable A1,
rw measure_theory.measure.le_iff,
intros T C1,
rw measure_theory.measure_partition_apply μ S T B1 C1,
rw measure_theory.measure.add_apply,
rw add_comm,
apply @add_le_add ennreal _,
{
rw measure_theory.measure.restrict_apply C1,
rw set.inter_comm,
apply le_refl _,
},
{
rw measure_theory.measure.restrict_apply C1,
rw set.inter_comm,
rw le_on_subsets_def at A1,
apply A1.right,
apply set.inter_subset_right,
apply is_measurable.inter C1 B1,
},
end
lemma measure_theory.measure.sup_eq {Ω:Type*} [measurable_space Ω] {μ ν:measure_theory.measure Ω}
(S:set Ω):le_on_subsets μ ν S → le_on_subsets ν μ Sᶜ →
(μ ⊔ ν) = μ.restrict Sᶜ + ν.restrict S :=
begin
intros A1 A2,
have D1:is_measurable S := le_on_subsets_is_measurable A1,
apply le_antisymm,
{
apply @sup_le (measure_theory.measure Ω) _,
{
apply measure_theory.measure.le_restrict_add_restrict A1 A2,
},
{
rw add_comm,
have B1:ν.restrict Sᶜᶜ = ν.restrict S,
{
simp,
},
rw ← B1,
apply measure_theory.measure.le_restrict_add_restrict,
apply A2,
simp,
apply A1,
},
},
{
apply measure_theory.measure.le_sup,
intros c C1 C2,
rw measure_theory.measure.le_iff,
intros T C3,
simp,
rw measure_theory.measure.restrict_apply C3,
rw measure_theory.measure.restrict_apply C3,
rw measure_theory.measure_partition_apply c S,
rw add_comm,
apply @add_le_add ennreal _,
rw set.inter_comm,
apply C2,
apply is_measurable.inter D1 C3,
rw set.inter_comm,
apply C1,
apply is_measurable.inter (is_measurable.compl D1) C3,
apply D1,
apply C3,
},
end
lemma set.indicator_add_comm {α β:Type*} [ordered_add_comm_monoid β] {f g:α → β} {S:set α}:
S.indicator (f + g) = S.indicator f + S.indicator g :=
begin
apply funext,
intros a,
simp,
cases (classical.em (a∈ S)) with B1 B1,
{
repeat {rw set.indicator_of_mem B1},
simp,
},
{
repeat {rw set.indicator_of_not_mem B1},
simp,
},
end
lemma measure_theory.measure.with_density_restrict_comm {Ω:Type*} [M:measurable_space Ω] (μ:measure_theory.measure Ω)
{x:Ω → ennreal} {S:set Ω}:is_measurable S → (μ.with_density x).restrict S = (μ.restrict S).with_density x :=
begin
intros A1,
apply measure_theory.measure.ext,
intros T B1,
rw measure_theory.with_density_apply2,
rw measure_theory.measure.restrict_integral_eq_integral_indicator,
rw measure_theory.measure.restrict_apply,
rw set.indicator_indicator,
rw set.inter_comm,
rw measure_theory.with_density_apply2,
repeat {assumption <|> apply is_measurable.inter},
end
lemma measure_theory.measure.with_density_add {Ω:Type*} {M:measurable_space Ω} (μ:measure_theory.measure Ω)
{x y:Ω → ennreal}:measurable x → measurable y → μ.with_density (x + y) = μ.with_density x + μ.with_density y :=
begin
intros A1 A2,
apply measure_theory.measure.ext,
intros S B1,
rw measure_theory.measure.add_apply,
rw measure_theory.with_density_apply2 ,
rw measure_theory.with_density_apply2 ,
rw measure_theory.with_density_apply2 ,
rw set.indicator_add_comm,
rw measure_theory.measure.integral_add,
repeat{assumption <|> apply measurable_set_indicator},
end
lemma with_density_sup' {Ω:Type*} {M:measurable_space Ω} (μ:measure_theory.measure Ω)
{x y:Ω → ennreal}:measurable x → measurable y →
μ.with_density (x ⊔ y) =
(μ.with_density x).restrict {ω:Ω|y ω < x ω}
+
(μ.with_density y).restrict {ω:Ω|x ω ≤ y ω} :=
begin
intros A1 A2,
rw sup_indicator_partition,
rw measure_theory.measure.with_density_add,
rw with_density_indicator_eq_restrict,
rw with_density_indicator_eq_restrict,
rw measure_theory.measure.with_density_restrict_comm,
rw measure_theory.measure.with_density_restrict_comm,
repeat {assumption <|> apply is_measurable_le <|> apply is_measurable_lt <|> apply measurable_set_indicator},
end
--Oh dear. This may not be true: instead it might be an inequality.
lemma with_density_sup {Ω:Type*} {M:measurable_space Ω} (μ:measure_theory.measure Ω)
{x y:Ω → ennreal}:measurable x → measurable y →
μ.with_density (x ⊔ y) =
measure_theory.measure.with_density μ x ⊔ measure_theory.measure.with_density μ y :=
begin
intros A1 A2,
rw with_density_sup' μ A1 A2,
rw measure_theory.measure.sup_eq {ω:Ω|x ω ≤ y ω},
rw lt_eq_le_compl,
{
apply le_on_subsets_with_density_of_le,
apply is_measurable_le A1 A2,
simp,
},
{
apply le_on_subsets_with_density_of_le,
apply is_measurable.compl (is_measurable_le A1 A2),
simp,
intros ω B3,
apply le_of_lt B3,
},
end
def measure_theory.finite_measure_sub {Ω:Type*} [M:measurable_space Ω]
(μ ν:measure_theory.measure Ω) [measure_theory.finite_measure ν]:
measure_theory.finite_measure (ν - μ) :=
begin
apply measure_theory.finite_measure_of_le (ν - μ) ν,
apply measure_theory.measure.sub_le,
end
lemma lebesgue_radon_nikodym_finite_unsigned {Ω:Type*} {N:measurable_space Ω} (μ ν:measure_theory.measure Ω) [A1:measure_theory.finite_measure μ]
[A2:measure_theory.finite_measure ν]:
∃ f:Ω → ennreal,
∃ μ₂:measure_theory.measure Ω,
measurable f ∧
ν = μ.with_density f + μ₂ ∧
μ.perpendicular μ₂ :=
begin
let S := {f:Ω → ennreal|measurable f ∧ (μ.with_density f ≤ ν)},
let M := Sup ((λ f, μ.with_density f set.univ) '' S),
begin
have A4:S = {f:Ω → ennreal|measurable f ∧ (μ.with_density f ≤ ν)} := rfl,
have B2:M = Sup ((λ f, μ.with_density f set.univ) '' S)
:= rfl,
have B3:M < ⊤,
{
-- Because μ is finite.
-- Or, because ν is finite, and μ... is less than ν.
have B3A:M ≤ ν set.univ,
{
rw B2,
apply @Sup_le ennreal _,
intros b B3A1,
simp at B3A1,
cases B3A1 with f B3A1,
cases B3A1 with B3A1 B3A2,
subst b,
apply B3A1.right,
apply is_measurable.univ,
},
apply lt_of_le_of_lt B3A,
apply measure_theory.measure_lt_top,
},
have B1:∃ h:ℕ → Ω → ennreal,
(∀ n, h n ∈ S) ∧
(monotone h) ∧
(μ.with_density (supr h) set.univ) = M,
{
-- have B1A:=
apply @Sup_apply_eq_supr_apply_of_closed' (Ω → ennreal)
_ S (λ f:Ω → ennreal, μ.with_density f set.univ) _ _,
--cases B1A with h B1A,
{ -- ⊢ S.nonempty
apply @set.nonempty_of_mem (Ω → ennreal) S 0,
rw A4,
simp,
split,
apply @measurable_const ennreal Ω _ N 0,
rw with_density.zero,
apply measure_theory.measure.zero_le,
},
{ -- ⊢ ∀ a ∈ S, ∀ b ∈ S, a ⊔ b ∈ S
intros a B1B1 b B1B2,
cases B1B1 with B1B1 B1B3,
cases B1B2 with B1B2 B1B4,
simp,
split,
{
apply measurable_sup B1B1 B1B2,
},
{
rw (with_density_sup μ B1B1 B1B2),
simp,
apply and.intro B1B3 B1B4,
},
},
{ -- ⊢ ∀ a ∈ S,∀ b ∈ S,a ≤ b →
-- (μ.with_density a set.univ ≤ μ.with_density b set.univ),
intros a B1C b B1D B1E,
simp,
rw A4 at B1C,
rw A4 at B1D,
apply with_density_le_with_density,
simp,
intros ω B1F,
apply B1E,
},
{
-- ⊢ ∀ (f : ℕ → Ω → ennreal),
-- set.range f ⊆ S →
-- monotone f →
-- supr ((λ (f : Ω → ennreal), ⇑(μ.with_density f) set.univ) ∘ f) =
-- (λ (f : Ω → ennreal), ⇑(μ.with_density f) set.univ) (supr f)
intros f B1G B1H,
simp,
rw supr_with_density_apply_eq_with_density_supr_apply _ _ B1H,
simp,
intros n,
rw A4 at B1G,
unfold set.range at B1G,
rw set.subset_def at B1G,
simp at B1G,
apply (B1G (f n) n _).left,
refl,
},
},
cases B1 with h B1,
have B4:∀ n, measurable (h n),
{
intros n,
have B4A := (B1.left n),
rw A4 at B4A,
apply B4A.left,
},
let g := supr h,
begin
apply exists.intro g,
have A5:g = supr h := rfl,
have A6:μ.with_density g set.univ = M,
{
rw A5,
rw ← B1.right.right,
},
have A7:μ.with_density g ≤ ν,
{
rw measure_theory.measure.le_iff,
intros S A7A,
rw ← supr_with_density_apply_eq_with_density_supr_apply,
apply @supr_le ennreal _ _,
intros i,
have A7B := (B1.left i),
simp at A7B,
apply A7B.right,
apply A7A,
apply A7A,
apply B4,
apply B1.right.left,
},
apply exists.intro (ν - μ.with_density g),
have C4:ν = μ.with_density g + (ν - μ.with_density g),
{
rw add_comm,
have C4A:measure_theory.finite_measure (μ.with_density g),
{
apply measure_theory.finite_measure_of_lt_top,
rw A6,
apply B3,
},
rw @measure_theory.measure.sub_add_cancel_of_le Ω N (μ.with_density g) ν C4A,
apply A7,
},
have C5:measurable g,
{
rw A5,
apply @measurable_supr_of_measurable,
apply B4,
},
apply and.intro C5,
apply and.intro C4,
{
apply by_contradiction,
intros C1,
have C2X:=measure_theory.finite_measure_sub (μ.with_density g) ν,
have C2 := @lebesgue_radon_nikodym_junior Ω N
μ (ν - μ.with_density g) A1 C2X C1,
cases C2 with f C2,
have D1:M < μ.with_density (f + g) set.univ,
{
rw measure_theory.measure.with_density_add,
rw measure_theory.measure.add_apply,
rw A6,
rw add_comm,
apply ennreal.lt_add_self,
apply B3,
apply C2.right.right,
apply C2.left,
apply C5,
},
apply not_le_of_lt D1,
rw B2,
apply @le_Sup ennreal _,
simp,
apply exists.intro (f + g),
split,
split,
{
apply measurable.add,
apply C2.left,
apply C5,
},
{
rw C4,
rw measure_theory.measure.with_density_add,
rw add_comm,
apply measure_theory.measure.add_le_add,
apply le_refl _,
apply C2.right.left,
apply C2.left,
apply C5,
--apply @add_le_add (measure_theory.measure Ω) _,
},
refl,
},
end
end
end
--Note that the Radon-Nikodym derivative is not necessarily unique.
def is_radon_nikodym_deriv {Ω:Type*} {M:measurable_space Ω} (ν μ:measure_theory.measure Ω) (f:Ω → ennreal):Prop :=
(measurable f) ∧ μ.with_density f = ν
lemma is_radon_nikodym_deriv_elim {Ω:Type*} {M:measurable_space Ω} (ν μ:measure_theory.measure Ω) (f:Ω → ennreal) (S:set Ω):
(is_radon_nikodym_deriv ν μ f) →
(is_measurable S) →
(μ.integral (set.indicator S f) = ν S) :=
begin
intros A1 A2,
unfold is_radon_nikodym_deriv at A1,
cases A1 with A3 A1,
subst ν,
rw measure_theory.with_density_apply2,
apply A2,
end
lemma measurable_of_is_radon_nikodym_deriv {Ω:Type*} {M:measurable_space Ω} (ν μ:measure_theory.measure Ω) (f:Ω → ennreal) (S:set Ω):
(is_radon_nikodym_deriv ν μ f) →
(measurable f) :=
begin
intro A1,
cases A1 with A1 A2,
apply A1,
end
lemma is_radon_nikodym_deriv_intro {Ω:Type*} {M:measurable_space Ω} (ν μ:measure_theory.measure Ω) (f:Ω → ennreal):
(measurable f) →
(∀ S:set Ω, (is_measurable S) →
(μ.integral (set.indicator S f) = ν S)) →
(is_radon_nikodym_deriv ν μ f) :=
begin
intros A1 A2,
unfold is_radon_nikodym_deriv,
split,
apply A1,
apply measure_theory.measure.ext,
intros S A3,
rw measure_theory.with_density_apply2,
apply A2,
repeat {apply A3},
end
/-
As we move on to the later theorems, we need to be able to say that two
functions are "almost everywhere equal". Specifically, given two radon-nikodym
derivatives of a measure, they are equal almost everywhere according to the
base measure.
-/
-- There used to be a definition close to this, measure_theory,measure.a_e, and
-- This used to be ∀ᶠ a in μ.a_e, P a
-- For now, we use a local definition.
def measure_theory.measure.all_ae {Ω:Type*} {M:measurable_space Ω} (μ:measure_theory.measure Ω) (P:Ω → Prop):Prop :=
(μ ({ω:Ω|(P ω)}ᶜ)) = 0
lemma measure_theory.measure.all_ae_def2 {Ω:Type*} {M:measurable_space Ω} (μ:measure_theory.measure Ω) (P:Ω → Prop):
μ.all_ae P = ( (μ ({ω:Ω|(P ω)}ᶜ)) = 0) :=
begin
unfold measure_theory.measure.all_ae,
end
lemma measure_theory.measure.all_ae_and {Ω:Type*} {M:measurable_space Ω} (μ:measure_theory.measure Ω) (P Q:Ω → Prop):
(μ.all_ae P) →
(μ.all_ae Q) →
(μ.all_ae (λ a, P a ∧ Q a)) :=
begin
intros A1 A2,
rw measure_theory.measure.all_ae_def2,
have A3:{ω:Ω| P ω ∧ Q ω}ᶜ = ({ω:Ω|P ω}ᶜ) ∪ ({ω:Ω|Q ω}ᶜ),
{
ext ω,
split;intros A3A;simp;simp at A3A,
{
have A3B:P ω ∨ ¬(P ω) := classical.em (P ω),
cases A3B,
{
apply or.inr (A3A A3B),
},
{
apply or.inl A3B,
},
},
{
cases A3A,
{
intro A3B,
exfalso,
apply A3A,
apply A3B,
},
{
intro A3B,
apply A3A,
},
},
},
rw A3,
have A4:(⊥:ennreal)=(0:ennreal) := rfl,
rw ← A4,
rw ← le_bot_iff,
apply le_trans (measure_theory.measure_union_le ({ω:Ω|P ω}ᶜ) ({ω:Ω|Q ω}ᶜ)),
rw measure_theory.measure.all_ae_def2 at A1,
rw measure_theory.measure.all_ae_def2 at A2,
rw A1,
rw A2,
simp,
end
lemma measure_theory.all_ae_imp {Ω:Type*} {M:measurable_space Ω} (μ:measure_theory.measure Ω) (P Q:Ω → Prop):
(μ.all_ae (λ a, P a → Q a)) →
(μ.all_ae P) →
(μ.all_ae Q) :=
begin
intros A1 A2,
rw measure_theory.measure.all_ae_def2 at A1,
rw measure_theory.measure.all_ae_def2 at A2,
rw measure_theory.measure.all_ae_def2,
have A3:{ω:Ω|Q ω}ᶜ ⊆ ({ω:Ω|P ω → Q ω}ᶜ) ∪ ({ω:Ω|P ω}ᶜ),
{
rw set.subset_def,
intro ω,
simp,
intro A3A,
cases (classical.em (P ω)) with A3B A3B,
{
apply or.inl (and.intro A3B A3A),
},
{
apply or.inr A3B,
},
},
have A4:(⊥:ennreal)=(0:ennreal) := rfl,
rw ← A4,
rw ← le_bot_iff,
apply le_trans (measure_theory.measure_mono A3),
apply le_trans (measure_theory.measure_union_le ({ω:Ω|P ω → Q ω}ᶜ) ({ω:Ω|P ω}ᶜ)),
rw A1,
rw A2,
simp,
end
lemma measure_theory.all_ae2_of_all {Ω:Type*} {M:measurable_space Ω} (μ:measure_theory.measure Ω) (P:Ω → Prop):
(∀ a, P a) →
(μ.all_ae P) :=
begin
intro A1,
rw measure_theory.measure.all_ae_def2,
have A2:{ω:Ω|P ω}ᶜ = ∅,
{
ext ω,split;intros A2A,
exfalso,
simp at A2A,
apply A2A,
apply A1,
exfalso,
apply A2A,
},
rw A2,
simp,
end
lemma measure_theory.not_ae {Ω:Type*} {M:measurable_space Ω} (μ:measure_theory.measure Ω) (P:Ω → Prop):
(∃ S:set Ω, (μ S > 0) ∧ (∀ ω∈ S, ¬ (P ω)) )→
(¬(μ.all_ae P)) :=
begin
intros A1 A2,
cases A1 with S A3,
cases A3 with A3 A4,
rw measure_theory.measure.all_ae_def2 at A2,
have A5:S⊆ {ω:Ω|P ω}ᶜ,
{
rw set.subset_def,
intro ω,
intro A5A,
apply A4 _ A5A,
},
have A6 := measure_theory.outer_measure.mono (μ.to_outer_measure) A5,
have A7 := lt_of_lt_of_le A3 A6,
rw measure.apply at A2,
rw A2 at A7,
apply lt_irrefl (0:ennreal) A7,
end
/-
Notice that it is not necessarily the case that a measurable set exists.
For example, consider where Ω = {a,b}.
The measurable sets are {} and {a,b}, where μ ∅ = 0 and μ {a,b} = 1.
Define (P a) and (¬P b).
Thus S={a}, which is not measurable.
-/
lemma measure_theory.not_ae_elim {Ω:Type*} {M:measurable_space Ω} (μ:measure_theory.measure Ω) (P:Ω → Prop):
(¬(μ.all_ae P)) →
(∃ S:set Ω, (μ S > 0) ∧ (∀ ω∈ S, ¬ (P ω)) ) :=
begin
intro A1,
rw measure_theory.measure.all_ae_def2 at A1,
have A2 := ennreal.eq_zero_or_zero_lt A1,
apply exists.intro ({ω : Ω | P ω}ᶜ),
split,
apply A2,
intros ω A3,
simp at A3,
apply A3,
end
|
e03992efd45355f49b7010333a23585cbfbf6f16 | 75db7e3219bba2fbf41bf5b905f34fcb3c6ca3f2 | /library/data/nat/basic.lean | aa9db5fedc0df7fe1701ba98df1d9af1f644c1ea | [
"Apache-2.0"
] | permissive | jroesch/lean | 30ef0860fa905d35b9ad6f76de1a4f65c9af6871 | 3de4ec1a6ce9a960feb2a48eeea8b53246fa34f2 | refs/heads/master | 1,586,090,835,348 | 1,455,142,203,000 | 1,455,142,277,000 | 51,536,958 | 1 | 0 | null | 1,455,215,811,000 | 1,455,215,811,000 | null | UTF-8 | Lean | false | false | 7,828 | lean | /-
Copyright (c) 2014 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn, Leonardo de Moura, Jeremy Avigad
Basic operations on the natural numbers.
-/
import ..num algebra.ring
open binary eq.ops
namespace nat
/- a variant of add, defined by recursion on the first argument -/
definition addl (x y : ℕ) : ℕ :=
nat.rec y (λ n r, succ r) x
infix ` ⊕ `:65 := addl
theorem addl_succ_right (n m : ℕ) : n ⊕ succ m = succ (n ⊕ m) :=
nat.induction_on n
rfl
(λ n₁ ih, calc
succ n₁ ⊕ succ m = succ (n₁ ⊕ succ m) : rfl
... = succ (succ (n₁ ⊕ m)) : ih
... = succ (succ n₁ ⊕ m) : rfl)
theorem add_eq_addl (x : ℕ) : ∀y, x + y = x ⊕ y :=
nat.induction_on x
(λ y, nat.induction_on y
rfl
(λ y₁ ih, calc
0 + succ y₁ = succ (0 + y₁) : rfl
... = succ (0 ⊕ y₁) : {ih}
... = 0 ⊕ (succ y₁) : rfl))
(λ x₁ ih₁ y, nat.induction_on y
(calc
succ x₁ + 0 = succ (x₁ + 0) : rfl
... = succ (x₁ ⊕ 0) : {ih₁ 0}
... = succ x₁ ⊕ 0 : rfl)
(λ y₁ ih₂, calc
succ x₁ + succ y₁ = succ (succ x₁ + y₁) : rfl
... = succ (succ x₁ ⊕ y₁) : {ih₂}
... = succ x₁ ⊕ succ y₁ : addl_succ_right))
/- successor and predecessor -/
theorem succ_ne_zero [simp] (n : ℕ) : succ n ≠ 0 :=
by contradiction
theorem add_one_ne_zero [simp] (n : ℕ) : n + 1 ≠ 0 :=
by contradiction
-- add_rewrite succ_ne_zero
theorem pred_zero [simp] : pred 0 = 0 :=
rfl
theorem pred_succ [simp] (n : ℕ) : pred (succ n) = n :=
rfl
theorem eq_zero_or_eq_succ_pred (n : ℕ) : n = 0 ∨ n = succ (pred n) :=
nat.induction_on n
(or.inl rfl)
(take m IH, or.inr
(show succ m = succ (pred (succ m)), from congr_arg succ !pred_succ⁻¹))
theorem exists_eq_succ_of_ne_zero {n : ℕ} (H : n ≠ 0) : ∃k : ℕ, n = succ k :=
exists.intro _ (or_resolve_right !eq_zero_or_eq_succ_pred H)
theorem succ.inj {n m : ℕ} (H : succ n = succ m) : n = m :=
nat.no_confusion H imp.id
abbreviation eq_of_succ_eq_succ := @succ.inj
theorem succ_ne_self {n : ℕ} : succ n ≠ n :=
nat.induction_on n
(take H : 1 = 0,
have ne : 1 ≠ 0, from !succ_ne_zero,
absurd H ne)
(take k IH H, IH (succ.inj H))
theorem discriminate {B : Prop} {n : ℕ} (H1: n = 0 → B) (H2 : ∀m, n = succ m → B) : B :=
have H : n = n → B, from nat.cases_on n H1 H2,
H rfl
theorem two_step_induction_on {P : ℕ → Prop} (a : ℕ) (H1 : P 0) (H2 : P 1)
(H3 : ∀ (n : ℕ) (IH1 : P n) (IH2 : P (succ n)), P (succ (succ n))) : P a :=
have stronger : P a ∧ P (succ a), from
nat.induction_on a
(and.intro H1 H2)
(take k IH,
have IH1 : P k, from and.elim_left IH,
have IH2 : P (succ k), from and.elim_right IH,
and.intro IH2 (H3 k IH1 IH2)),
and.elim_left stronger
theorem sub_induction {P : ℕ → ℕ → Prop} (n m : ℕ) (H1 : ∀m, P 0 m)
(H2 : ∀n, P (succ n) 0) (H3 : ∀n m, P n m → P (succ n) (succ m)) : P n m :=
have general : ∀m, P n m, from nat.induction_on n H1
(take k : ℕ,
assume IH : ∀m, P k m,
take m : ℕ,
nat.cases_on m (H2 k) (take l, (H3 k l (IH l)))),
general m
/- addition -/
protected theorem add_zero (n : ℕ) : n + 0 = n :=
rfl
theorem add_succ (n m : ℕ) : n + succ m = succ (n + m) :=
rfl
/-
Remark: we use 'local attributes' because in the end of the file
we show not is a comm_semiring, and we will automatically inherit
the associated [simp] lemmas from algebra
-/
local attribute nat.add_zero nat.add_succ [simp]
protected theorem zero_add (n : ℕ) : 0 + n = n :=
by rec_simp
theorem succ_add (n m : ℕ) : (succ n) + m = succ (n + m) :=
by rec_simp
local attribute nat.zero_add nat.succ_add [simp]
protected theorem add_comm (n m : ℕ) : n + m = m + n :=
by rec_simp
theorem succ_add_eq_succ_add (n m : ℕ) : succ n + m = n + succ m :=
by simp
protected theorem add_assoc (n m k : ℕ) : (n + m) + k = n + (m + k) :=
by rec_simp
protected theorem add_left_comm : Π (n m k : ℕ), n + (m + k) = m + (n + k) :=
left_comm nat.add_comm nat.add_assoc
local attribute nat.add_comm nat.add_assoc nat.add_left_comm [simp]
protected theorem add_right_comm : Π (n m k : ℕ), n + m + k = n + k + m :=
right_comm nat.add_comm nat.add_assoc
protected theorem add_left_cancel {n m k : ℕ} : n + m = n + k → m = k :=
nat.induction_on n
(by simp)
(take a iH,
-- TODO(Leo): replace with forward reasoning after we add strategies for it.
assert succ (a + m) = succ (a + k) → a + m = a + k, from !succ.inj,
by inst_simp)
protected theorem add_right_cancel {n m k : ℕ} (H : n + m = k + m) : n = k :=
have H2 : m + n = m + k, by simp,
nat.add_left_cancel H2
theorem eq_zero_of_add_eq_zero_right {n m : ℕ} : n + m = 0 → n = 0 :=
nat.induction_on n
(by simp)
(take k iH, assume H : succ k + m = 0,
absurd
(show succ (k + m) = 0, by simp)
!succ_ne_zero)
theorem eq_zero_of_add_eq_zero_left {n m : ℕ} (H : n + m = 0) : m = 0 :=
eq_zero_of_add_eq_zero_right (!nat.add_comm ⬝ H)
theorem eq_zero_and_eq_zero_of_add_eq_zero {n m : ℕ} (H : n + m = 0) : n = 0 ∧ m = 0 :=
and.intro (eq_zero_of_add_eq_zero_right H) (eq_zero_of_add_eq_zero_left H)
theorem add_one (n : ℕ) : n + 1 = succ n := rfl
local attribute add_one [simp]
theorem one_add (n : ℕ) : 1 + n = succ n :=
by simp
theorem succ_eq_add_one (n : ℕ) : succ n = n + 1 :=
rfl
/- multiplication -/
protected theorem mul_zero (n : ℕ) : n * 0 = 0 :=
rfl
theorem mul_succ (n m : ℕ) : n * succ m = n * m + n :=
rfl
local attribute nat.mul_zero nat.mul_succ [simp]
-- commutativity, distributivity, associativity, identity
protected theorem zero_mul (n : ℕ) : 0 * n = 0 :=
by rec_simp
theorem succ_mul (n m : ℕ) : (succ n) * m = (n * m) + m :=
by rec_simp
local attribute nat.zero_mul nat.succ_mul [simp]
protected theorem mul_comm (n m : ℕ) : n * m = m * n :=
by rec_simp
protected theorem right_distrib (n m k : ℕ) : (n + m) * k = n * k + m * k :=
by rec_simp
protected theorem left_distrib (n m k : ℕ) : n * (m + k) = n * m + n * k :=
by rec_simp
local attribute nat.mul_comm nat.right_distrib nat.left_distrib [simp]
protected theorem mul_assoc (n m k : ℕ) : (n * m) * k = n * (m * k) :=
by rec_simp
local attribute nat.mul_assoc [simp]
protected theorem mul_one (n : ℕ) : n * 1 = n :=
calc
n * 1 = n * 0 + n : mul_succ
... = n : by simp
local attribute nat.mul_one [simp]
protected theorem one_mul (n : ℕ) : 1 * n = n :=
by simp
local attribute nat.one_mul [simp]
theorem eq_zero_or_eq_zero_of_mul_eq_zero {n m : ℕ} : n * m = 0 → n = 0 ∨ m = 0 :=
nat.cases_on n (by simp)
(take n',
nat.cases_on m
(by simp)
(take m', assume H,
absurd
(show succ (succ n' * m' + n') = 0, by simp)
!succ_ne_zero))
protected definition comm_semiring [reducible] [trans_instance] : comm_semiring nat :=
⦃comm_semiring,
add := nat.add,
add_assoc := nat.add_assoc,
zero := nat.zero,
zero_add := nat.zero_add,
add_zero := nat.add_zero,
add_comm := nat.add_comm,
mul := nat.mul,
mul_assoc := nat.mul_assoc,
one := nat.succ nat.zero,
one_mul := nat.one_mul,
mul_one := nat.mul_one,
left_distrib := nat.left_distrib,
right_distrib := nat.right_distrib,
zero_mul := nat.zero_mul,
mul_zero := nat.mul_zero,
mul_comm := nat.mul_comm⦄
end nat
section
open nat
definition iterate {A : Type} (op : A → A) : ℕ → A → A
| 0 := λ a, a
| (succ k) := λ a, op (iterate k a)
notation f`^[`n`]` := iterate f n
end
|
b6d61417461e8150785f26a61b41bf9ec40041c4 | 5756a081670ba9c1d1d3fca7bd47cb4e31beae66 | /Mathport/Binary/TranslateExpr.lean | b967c6e38a3c8cfb8bb23464fb60ec2d7b8bcc10 | [
"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,498 | lean | /-
Copyright (c) 2021 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Daniel Selsam
Lean3 uses snake_case for everything.
As of now, Lean4 uses:
- camelCase for defs
- PascalCase for types
- snake_case for proofs
-/
import Lean
import Mathport.Util.Misc
import Mathport.Util.String
import Mathport.Binary.Basic
import Mathport.Binary.Number
import Mathport.Binary.Decode
import Mathport.Binary.TranslateName
import Mathport.Binary.Heterogenize
namespace Mathport.Binary
open Lean Lean.Meta Mathlib.Prelude.Rename
/--
Return true iff `declName` is one of the auxiliary definitions/projections
used to implement coercions (also in Lean 3)
-/
def isCoeDecl (declName : Name) : Bool :=
declName == ``Coe.coe || declName == ``CoeTC.coe || declName == ``CoeHead.coe ||
declName == ``CoeTail.coe || declName == ``CoeHTCT.coe || declName == ``CoeDep.coe ||
declName == ``CoeT.coe || declName == ``CoeFun.coe || declName == ``CoeSort.coe ||
declName == ``Lean.Internal.liftCoeM || declName == ``Lean.Internal.coeM ||
declName == `CoeT.coeₓ || declName == `coeT || declName == `coeToLift || declName == `coeBaseₓ ||
declName == `coe || declName == `liftT || declName == `lift || declName == `HasLiftT.lift ||
declName == `coeB
/-- Expand coercions occurring in `e` (+ Lean 3 defs) -/
partial def expandCoe (e : Expr) : MetaM Expr :=
withReducibleAndInstances do
transform e (pre := step)
where
step (e : Expr) : MetaM TransformStep := do
let f := e.getAppFn
if !f.isConst then
return .continue
else
let declName := f.constName!
if isCoeDecl declName then
match (← unfoldDefinition? e) with
| none => return .continue
| some e' =>
let mut e' := e'.headBeta
while e'.getAppFn.isProj do
if let some f ← reduceProj? e'.getAppFn then
e' := (mkAppN f e'.getAppArgs).headBeta
else
return .continue
return .visit e'
else
return .continue
instance : ToExpr Syntax.Preresolved where
toTypeExpr := mkConst ``Syntax.Preresolved
toExpr
| .namespace ns => mkApp (mkConst ``Syntax.Preresolved.namespace) (toExpr ns)
| .decl n fields => mkApp2 (mkConst ``Syntax.Preresolved.decl) (toExpr n) (toExpr fields)
def trExprCore (ctx : Context) (cmdCtx : Elab.Command.Context) (cmdState : Elab.Command.State) (e : Expr) (ind? : Option (Name × Expr × List Name)) : MetaM Expr := do
match ind? with
| none => core e
| some ⟨indName, indType, lps⟩ =>
withLocalDeclD indName indType fun x => do
let e := e.replace fun e => if e.isConstOf indName then some x else none
let e ← core e
let e := e.replace fun e =>
if e == x then some (mkConst indName $ lps.map mkLevelParam)
else if !e.hasFVar then (some e)
else none
pure e
where
core e := do
let mut e := e
e ← replaceConstNames e
e ← Meta.transform e (post := replaceSorryPlaceholders)
e ← expandCoe e
e ← translateNumbers e
if let some (_, ap4) := (getRenameMap cmdState.env).find? `auto_param then
e ← Meta.transform e (pre := translateAutoParams ap4)
e ← heterogenize e
reflToRfl e
replaceConstNames (e : Expr) : MetaM Expr := pure <|
e.replaceConstNames fun n => (getRenameMap cmdState.env).find? n |>.map (·.2)
reflToRfl (e : Expr) : MetaM Expr := pure <|
e.replace fun e =>
if e.isAppOfArity `Eq.refl 2 then
some $ e.withApp fun f args => mkAppN (mkConst `rfl f.constLevels!) args
else none
replaceSorryPlaceholders (e : Expr) : MetaM TransformStep := do
if e.isAppOfArity sorryPlaceholderName 1 then
let type := e.appArg!
let e ← mkSorry type (synthetic := false)
return TransformStep.done e
else
return TransformStep.done e
translateAutoParams (ap4 : Name) (e : Expr) : MetaM TransformStep :=
-- def auto_param : Sort u → name → Sort u :=
-- λ (α : Sort u) (tac_name : name), α
if e.isAppOfArity ap4 2 then do
let level := e.getAppFn.constLevels!.head!
let type := e.getArg! 0
let tacName3 := e.getArg! 1
try
let tacName3 ← decodeName tacName3
let tacName ← mkCandidateLean4NameForKindIO tacName3 ExprKind.eDef
let substr : Expr := mkAppN (mkConst ``String.toSubstring) #[toExpr $ tacName.toString]
let tacSyntax := mkAppN (mkConst ``Lean.Syntax.ident) #[mkConst ``Lean.SourceInfo.none, substr, toExpr tacName, toExpr ([] : List Syntax.Preresolved)]
let e' := mkAppN (mkConst ``autoParam [level]) #[type, tacSyntax]
unless ← Meta.isDefEq e e' do throwError "[translateAutoParams] introduced non-defeq, {e} != {e'}"
pure $ TransformStep.done e'
catch ex => do
-- they prove theorems about auto_param!
println! "[decode] {(← ex.toMessageData.toString)}"
-- strip the auto_param?
pure .continue
else
pure .continue
mkCandidateLean4NameForKindIO (n3 : Name) (eKind : ExprKind) : IO Name := do
(mkCandidateLean4NameForKind n3 eKind).toIO ctx {} cmdCtx cmdState
def trExpr (e : Expr) (ind? : Option (Name × Expr × List Name) := none) : BinportM Expr := do
let ctx ← read
let cmdCtx ← readThe Elab.Command.Context
let cmdState ← getThe Elab.Command.State
liftMetaM $ trExprCore ctx cmdCtx cmdState e ind?
end Mathport.Binary
|
90f868c47892680f57ff7c1e2988588b2e0600b8 | 4bcaca5dc83d49803f72b7b5920b75b6e7d9de2d | /stage0/src/Lean/Data/Json/Basic.lean | 6d61cf165806efc2926a6acfa5002182cf5c0ae5 | [
"Apache-2.0"
] | permissive | subfish-zhou/leanprover-zh_CN.github.io | 30b9fba9bd790720bd95764e61ae796697d2f603 | 8b2985d4a3d458ceda9361ac454c28168d920d3f | refs/heads/master | 1,689,709,967,820 | 1,632,503,056,000 | 1,632,503,056,000 | 409,962,097 | 1 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 7,079 | lean | /-
Copyright (c) 2019 Gabriel Ebner. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Gabriel Ebner, Marc Huisinga
-/
import Std.Data.RBTree
namespace Lean
-- mantissa * 10^-exponent
structure JsonNumber where
mantissa : Int
exponent : Nat
deriving DecidableEq
namespace JsonNumber
protected def fromNat (n : Nat) : JsonNumber := ⟨n, 0⟩
protected def fromInt (n : Int) : JsonNumber := ⟨n, 0⟩
instance : Coe Nat JsonNumber := ⟨JsonNumber.fromNat⟩
instance : Coe Int JsonNumber := ⟨JsonNumber.fromInt⟩
private partial def countDigits (n : Nat) : Nat :=
let rec loop (n digits : Nat) : Nat :=
if n ≤ 9 then
digits
else
loop (n/10) (digits+1)
loop n 1
-- convert mantissa * 10^-exponent to 0.mantissa * 10^exponent
protected def normalize : JsonNumber → Int × Nat × Int
| ⟨m, e⟩ => do
if m = 0 then (0, 0, 0)
else
let sign : Int := if m > 0 then 1 else -1
let mut mAbs := m.natAbs
let nDigits := countDigits mAbs
-- eliminate trailing zeros
for _ in [0:nDigits] do
if mAbs % 10 = 0 then
mAbs := mAbs / 10
else
break
(sign, mAbs, -(e : Int) + nDigits)
-- todo (Dany): We should have an Ordering version of this.
def lt (a b : JsonNumber) : Bool :=
let (as, am, ae) := a.normalize
let (bs, bm, be) := b.normalize
match (as, bs) with
| (-1, 1) => true
| (1, -1) => false
| _ =>
let ((am, ae), (bm, be)) :=
if as = -1 && bs = -1 then
((bm, be), (am, ae))
else
((am, ae), (bm, be))
let amDigits := countDigits am
let bmDigits := countDigits bm
-- align the mantissas
let (am, bm) :=
if amDigits < bmDigits then
(am * 10^(bmDigits - amDigits), bm)
else
(am, bm * 10^(amDigits - bmDigits))
if ae < be then true
else if ae > be then false
else am < bm
def ltProp : LT JsonNumber :=
⟨fun a b => lt a b = true⟩
instance : LT JsonNumber :=
ltProp
instance (a b : JsonNumber) : Decidable (a < b) :=
inferInstanceAs (Decidable (lt a b = true))
instance : Ord JsonNumber where
compare x y :=
if x < y then Ordering.lt
else if x > y then Ordering.gt
else Ordering.eq
protected def toString : JsonNumber → String
| ⟨m, 0⟩ => m.repr
| ⟨m, e⟩ =>
let sign := if m ≥ 0 then "" else "-"
let m := m.natAbs
-- if there are too many zeroes after the decimal, we
-- use exponents to compress the representation.
-- this is mostly done for memory usage reasons:
-- the size of the representation would otherwise
-- grow exponentially in the value of exponent.
let exp : Int := 9 + countDigits m - (e : Int)
let exp := if exp < 0 then exp else 0
let e' := (10 : Int) ^ (e - exp.natAbs)
let left := (m / e').repr
let right := e' + coe m % e'
|>.repr.toSubstring.drop 1
|>.dropRightWhile (fun c => c = '0')
|>.toString
let exp := if exp = 0 then "" else "e" ++ exp.repr
s!"{sign}{left}.{right}{exp}"
-- shift a JsonNumber by a specified amount of places to the left
protected def shiftl : JsonNumber → Nat → JsonNumber
-- if s ≤ e, then 10 ^ (s - e) = 1, and hence the mantissa remains unchanged.
-- otherwise, the expression pads the mantissa with zeroes
-- to accomodate for the remaining places to shift.
| ⟨m, e⟩, s => ⟨m * (10 ^ (s - e) : Nat), e - s⟩
-- shift a JsonNumber by a specified amount of places to the right
protected def shiftr : JsonNumber → Nat → JsonNumber
| ⟨m, e⟩, s => ⟨m, e + s⟩
instance : ToString JsonNumber := ⟨JsonNumber.toString⟩
instance : Repr JsonNumber where
reprPrec | ⟨m, e⟩, _ => Std.Format.bracket "⟨" (repr m ++ "," ++ repr e) "⟩"
end JsonNumber
def strLt (a b : String) := Decidable.decide (a < b)
open Std (RBNode RBNode.leaf)
inductive Json where
| null
| bool (b : Bool)
| num (n : JsonNumber)
| str (s : String)
| arr (elems : Array Json)
-- uses RBNode instead of RBMap because RBMap is a def
-- and thus currently cannot be used to define a type that
-- is recursive in one of its parameters
| obj (kvPairs : RBNode String (fun _ => Json))
deriving Inhabited
namespace Json
private partial def beq' : Json → Json → Bool
| null, null => true
| bool a, bool b => a == b
| num a, num b => a == b
| str a, str b => a == b
| arr a, arr b =>
let _ : BEq Json := ⟨beq'⟩
a == b
| obj a, obj b =>
let _ : BEq Json := ⟨beq'⟩
let szA := a.fold (init := 0) (fun a _ _ => a + 1)
let szB := b.fold (init := 0) (fun a _ _ => a + 1)
szA == szB && a.all fun field fa =>
match b.find compare field with
| none => false
| some fb => fa == fb
| _, _ => false
instance : BEq Json where
beq := beq'
-- HACK(Marc): temporary ugliness until we can use RBMap for JSON objects
def mkObj (o : List (String × Json)) : Json :=
obj $ do
let mut kvPairs := RBNode.leaf
for ⟨k, v⟩ in o do
kvPairs := kvPairs.insert compare k v
kvPairs
instance : Coe Nat Json := ⟨fun n => Json.num n⟩
instance : Coe Int Json := ⟨fun n => Json.num n⟩
instance : Coe String Json := ⟨Json.str⟩
instance : Coe Bool Json := ⟨Json.bool⟩
def isNull : Json -> Bool
| null => true
| _ => false
def getObj? : Json → Except String (RBNode String (fun _ => Json))
| obj kvs => kvs
| _ => throw "object expected"
def getArr? : Json → Except String (Array Json)
| arr a => a
| _ => throw "array expected"
def getStr? : Json → Except String String
| str s => s
| _ => throw "String expected"
def getNat? : Json → Except String Nat
| (n : Nat) => n
| _ => throw "Natural number expected"
def getInt? : Json → Except String Int
| (i : Int) => i
| _ => throw "Integer expected"
def getBool? : Json → Except String Bool
| (b : Bool) => b
| _ => throw "Bool expected"
def getNum? : Json → Except String JsonNumber
| num n => n
| _ => throw "number expected"
def getObjVal? : Json → String → Except String Json
| obj kvs, k =>
match kvs.find compare k with
| some v => v
| none => throw s!"property not found: {k}"
| _ , _ => throw "object expected"
def getArrVal? : Json → Nat → Except String Json
| arr a, i =>
match a.get? i with
| some v => v
| none => throw s!"index out of bounds: {i}"
| _ , _ => throw "array expected"
def getObjValD (j : Json) (k : String) : Json :=
(j.getObjVal? k).toOption.getD null
def setObjVal! : Json → String → Json → Json
| obj kvs, k, v => obj <| kvs.insert compare k v
| j , _, _ => panic! "Json.setObjVal!: not an object: {j}"
inductive Structured where
| arr (elems : Array Json)
| obj (kvPairs : RBNode String (fun _ => Json))
instance : Coe (Array Json) Structured := ⟨Structured.arr⟩
instance : Coe (RBNode String (fun _ => Json)) Structured := ⟨Structured.obj⟩
end Json
end Lean
|
722442372d36e9d891e2c05713fc55116df180ff | cf39355caa609c0f33405126beee2739aa3cb77e | /tests/lean/bad_structures2.lean | 66d3f4b99750c61e63dd0c0cd743ab6f7a13f1b9 | [
"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 | 407 | lean | structure foo :=
(x : bool)
structure boo :=
(x : nat)
structure bla extends foo, boo
structure boo2 :=
{x : bool}
structure bla extends foo, boo2
structure bla extends foo :=
(x : nat)
structure bla extends foo :=
( : nat)
structure bla extends foo :=
mk :: y z : nat
structure bla2 extends nat
structure bla2 extends Type
structure bla2 : Prop :=
(x : Prop)
structure bla3 : Prop :=
(x : nat)
|
29b983ee268ba5c3df8d656778945a4dfc51cd9d | 437dc96105f48409c3981d46fb48e57c9ac3a3e4 | /src/algebra/group_power.lean | 77cd9a6a970940a96e380c68d43e5103f5672e88 | [
"Apache-2.0"
] | permissive | dan-c-k/mathlib | 08efec79bd7481ee6da9cc44c24a653bff4fbe0d | 96efc220f6225bc7a5ed8349900391a33a38cc56 | refs/heads/master | 1,658,082,847,093 | 1,589,013,201,000 | 1,589,013,201,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 29,577 | lean | /-
Copyright (c) 2015 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Robert Y. Lewis
-/
import data.int.basic
import data.equiv.basic
/-!
# Power operations on monoids and groups
The power operation on monoids and groups.
We separate this from group, because it depends on `ℕ`,
which in turn depends on other parts of algebra.
## Notation
The class `has_pow α β` provides the notation `a^b` for powers.
We define instances of `has_pow M ℕ`, for monoids `M`, and `has_pow G ℤ` for groups `G`.
## Implementation details
We adopt the convention that `0^0 = 1`.
-/
universes u v w x y z u₁ u₂
variables {M : Type u} {N : Type v} {G : Type w} {H : Type x} {A : Type y} {B : Type z}
{R : Type u₁} {S : Type u₂}
/-- The power operation in a monoid. `a^n = a*a*...*a` n times. -/
def monoid.pow [has_mul M] [has_one M] (a : M) : ℕ → M
| 0 := 1
| (n+1) := a * monoid.pow n
/-- The scalar multiplication in an additive monoid.
`n • a = a+a+...+a` n times. -/
def add_monoid.smul [has_add A] [has_zero A] (n : ℕ) (a : A) : A :=
@monoid.pow (multiplicative A) _ { one := (0 : A) } a n
precedence `•`:70
localized "infix ` • ` := add_monoid.smul" in add_monoid
@[priority 5] instance monoid.has_pow [monoid M] : has_pow M ℕ := ⟨monoid.pow⟩
/-!
### (Additive) monoid
-/
section monoid
variables [monoid M] [monoid N] [add_monoid A] [add_monoid B]
@[simp] theorem pow_zero (a : M) : a^0 = 1 := rfl
@[simp] theorem add_monoid.zero_smul (a : A) : 0 • a = 0 := rfl
theorem pow_succ (a : M) (n : ℕ) : a^(n+1) = a * a^n := rfl
theorem succ_smul (a : A) (n : ℕ) : (n+1)•a = a + n•a := rfl
@[simp] theorem pow_one (a : M) : a^1 = a := mul_one _
@[simp] theorem add_monoid.one_smul (a : A) : 1•a = a := add_zero _
@[simp] lemma pow_ite (P : Prop) [decidable P] (a : M) (b c : ℕ) :
a ^ (if P then b else c) = if P then a ^ b else a ^ c :=
by split_ifs; refl
@[simp] lemma ite_pow (P : Prop) [decidable P] (a b : M) (c : ℕ) :
(if P then a else b) ^ c = if P then a ^ c else b ^ c :=
by split_ifs; refl
@[simp] lemma pow_boole (P : Prop) [decidable P] (a : M) :
a ^ (if P then 1 else 0) = if P then a else 1 :=
by simp
theorem pow_mul_comm' (a : M) (n : ℕ) : a^n * a = a * a^n :=
by induction n with n ih; [rw [pow_zero, one_mul, mul_one],
rw [pow_succ, mul_assoc, ih]]
theorem smul_add_comm' : ∀ (a : A) (n : ℕ), n•a + a = a + n•a :=
@pow_mul_comm' (multiplicative A) _
theorem pow_succ' (a : M) (n : ℕ) : a^(n+1) = a^n * a :=
by rw [pow_succ, pow_mul_comm']
theorem succ_smul' (a : A) (n : ℕ) : (n+1)•a = n•a + a :=
by rw [succ_smul, smul_add_comm']
theorem pow_two (a : M) : a^2 = a * a :=
show a*(a*1)=a*a, by rw mul_one
theorem two_smul' (a : A) : 2•a = a + a :=
show a+(a+0)=a+a, by rw add_zero
theorem pow_add (a : M) (m n : ℕ) : a^(m + n) = a^m * a^n :=
by induction n with n ih; [rw [add_zero, pow_zero, mul_one],
rw [pow_succ, ← pow_mul_comm', ← mul_assoc, ← ih, ← pow_succ']]; refl
theorem add_monoid.add_smul : ∀ (a : A) (m n : ℕ), (m + n)•a = m•a + n•a :=
@pow_add (multiplicative A) _
@[simp] theorem one_pow (n : ℕ) : (1 : M)^n = 1 :=
by induction n with n ih; [refl, rw [pow_succ, ih, one_mul]]
@[simp] theorem add_monoid.smul_zero (n : ℕ) : n•(0 : A) = 0 :=
by induction n with n ih; [refl, rw [succ_smul, ih, zero_add]]
theorem pow_mul (a : M) (m n : ℕ) : a^(m * n) = (a^m)^n :=
by induction n with n ih; [rw mul_zero, rw [nat.mul_succ, pow_add, pow_succ', ih]]; refl
theorem add_monoid.mul_smul' : ∀ (a : A) (m n : ℕ), m * n • a = n•(m•a) :=
@pow_mul (multiplicative A) _
theorem pow_mul' (a : M) (m n : ℕ) : a^(m * n) = (a^n)^m :=
by rw [mul_comm, pow_mul]
theorem add_monoid.mul_smul (a : A) (m n : ℕ) : m * n • a = m•(n•a) :=
by rw [mul_comm, add_monoid.mul_smul']
@[simp] theorem add_monoid.smul_one [has_one A] : ∀ n : ℕ, n • (1 : A) = n :=
add_monoid_hom.eq_nat_cast
⟨λ n, n • (1 : A), add_monoid.zero_smul _, λ _ _, add_monoid.add_smul _ _ _⟩
(add_monoid.one_smul _)
theorem pow_bit0 (a : M) (n : ℕ) : a ^ bit0 n = a^n * a^n := pow_add _ _ _
theorem bit0_smul (a : A) (n : ℕ) : bit0 n • a = n•a + n•a := add_monoid.add_smul _ _ _
theorem pow_bit1 (a : M) (n : ℕ) : a ^ bit1 n = a^n * a^n * a :=
by rw [bit1, pow_succ', pow_bit0]
theorem bit1_smul : ∀ (a : A) (n : ℕ), bit1 n • a = n•a + n•a + a :=
@pow_bit1 (multiplicative A) _
theorem pow_mul_comm (a : M) (m n : ℕ) : a^m * a^n = a^n * a^m :=
by rw [←pow_add, ←pow_add, add_comm]
theorem smul_add_comm : ∀ (a : A) (m n : ℕ), m•a + n•a = n•a + m•a :=
@pow_mul_comm (multiplicative A) _
@[simp, priority 500]
theorem list.prod_repeat (a : M) (n : ℕ) : (list.repeat a n).prod = a ^ n :=
by induction n with n ih; [refl, rw [list.repeat_succ, list.prod_cons, ih]]; refl
@[simp, priority 500]
theorem list.sum_repeat : ∀ (a : A) (n : ℕ), (list.repeat a n).sum = n • a :=
@list.prod_repeat (multiplicative A) _
theorem monoid_hom.map_pow (f : M →* N) (a : M) : ∀(n : ℕ), f (a ^ n) = (f a) ^ n
| 0 := f.map_one
| (n+1) := by rw [pow_succ, pow_succ, f.map_mul, monoid_hom.map_pow]
theorem monoid_hom.iterate_map_pow (f : M →* M) (a) (n m : ℕ) : f^[n] (a^m) = (f^[n] a)^m :=
show f^[n] ((λ x, x^m) a) = (λ x, x^m) (f^[n] a),
from nat.iterate₁ $ λ x, f.map_pow x m
theorem add_monoid_hom.map_smul (f : A →+ B) (a : A) (n : ℕ) : f (n • a) = n • f a :=
f.to_multiplicative.map_pow a n
theorem add_monoid_hom.iterate_map_smul (f : A →+ A) (a : A) (n m : ℕ) :
f^[n] (m • a) = m • (f^[n] a) :=
f.to_multiplicative.iterate_map_pow a n m
theorem is_monoid_hom.map_pow (f : M → N) [is_monoid_hom f] (a : M) :
∀(n : ℕ), f (a ^ n) = (f a) ^ n :=
(monoid_hom.of f).map_pow a
theorem is_add_monoid_hom.map_smul (f : A → B) [is_add_monoid_hom f] (a : A) (n : ℕ) :
f (n • a) = n • f a :=
(add_monoid_hom.of f).map_smul a n
@[simp, norm_cast] lemma units.coe_pow (u : units M) (n : ℕ) : ((u ^ n : units M) : M) = u ^ n :=
(units.coe_hom M).map_pow u n
end monoid
@[simp] theorem nat.pow_eq_pow (p q : ℕ) :
@has_pow.pow _ _ monoid.has_pow p q = p ^ q :=
by induction q with q ih; [refl, rw [nat.pow_succ, pow_succ, mul_comm, ih]]
@[simp] theorem nat.smul_eq_mul (m n : ℕ) : m • n = m * n :=
by induction m with m ih; [rw [add_monoid.zero_smul, zero_mul],
rw [succ_smul', ih, nat.succ_mul]]
/-!
### Commutative (additive) monoid
-/
section comm_monoid
variables [comm_monoid M] [add_comm_monoid A]
theorem mul_pow (a b : M) (n : ℕ) : (a * b)^n = a^n * b^n :=
by induction n with n ih; [exact (mul_one _).symm,
simp only [pow_succ, ih, mul_assoc, mul_left_comm]]
theorem add_monoid.smul_add : ∀ (a b : A) (n : ℕ), n•(a + b) = n•a + n•b :=
@mul_pow (multiplicative A) _
instance pow.is_monoid_hom (n : ℕ) : is_monoid_hom ((^ n) : M → M) :=
{ map_mul := λ _ _, mul_pow _ _ _, map_one := one_pow _ }
instance add_monoid.smul.is_add_monoid_hom (n : ℕ) : is_add_monoid_hom (add_monoid.smul n : A → A) :=
{ map_add := λ _ _, add_monoid.smul_add _ _ _, map_zero := add_monoid.smul_zero _ }
end comm_monoid
section group
variables [group G] [group H] [add_group A] [add_group B]
section nat
@[simp] theorem inv_pow (a : G) (n : ℕ) : (a⁻¹)^n = (a^n)⁻¹ :=
by induction n with n ih; [exact one_inv.symm,
rw [pow_succ', pow_succ, ih, mul_inv_rev]]
@[simp] theorem add_monoid.neg_smul : ∀ (a : A) (n : ℕ), n•(-a) = -(n•a) :=
@inv_pow (multiplicative A) _
theorem pow_sub (a : G) {m n : ℕ} (h : n ≤ m) : a^(m - n) = a^m * (a^n)⁻¹ :=
have h1 : m - n + n = m, from nat.sub_add_cancel h,
have h2 : a^(m - n) * a^n = a^m, by rw [←pow_add, h1],
eq_mul_inv_of_mul_eq h2
theorem add_monoid.smul_sub : ∀ (a : A) {m n : ℕ}, n ≤ m → (m - n)•a = m•a - n•a :=
@pow_sub (multiplicative A) _
theorem pow_inv_comm (a : G) (m n : ℕ) : (a⁻¹)^m * a^n = a^n * (a⁻¹)^m :=
by rw inv_pow; exact inv_comm_of_comm (pow_mul_comm _ _ _)
theorem add_monoid.smul_neg_comm : ∀ (a : A) (m n : ℕ), m•(-a) + n•a = n•a + m•(-a) :=
@pow_inv_comm (multiplicative A) _
end nat
open int
/--
The power operation in a group. This extends `monoid.pow` to negative integers
with the definition `a^(-n) = (a^n)⁻¹`.
-/
def gpow (a : G) : ℤ → G
| (of_nat n) := a^n
| -[1+n] := (a^(nat.succ n))⁻¹
/--
The scalar multiplication by integers on an additive group.
This extends `add_monoid.smul` to negative integers
with the definition `(-n) • a = -(n • a)`.
-/
def gsmul (n : ℤ) (a : A) : A :=
@gpow (multiplicative A) _ a n
@[priority 10] instance group.has_pow : has_pow G ℤ := ⟨gpow⟩
localized "infix ` • `:70 := gsmul" in add_group
localized "infix ` •ℕ `:70 := add_monoid.smul" in smul
localized "infix ` •ℤ `:70 := gsmul" in smul
@[simp] theorem gpow_coe_nat (a : G) (n : ℕ) : a ^ (n:ℤ) = a ^ n := rfl
@[simp] theorem gsmul_coe_nat (a : A) (n : ℕ) : (n:ℤ) • a = n •ℕ a := rfl
theorem gpow_of_nat (a : G) (n : ℕ) : a ^ of_nat n = a ^ n := rfl
theorem gsmul_of_nat (a : A) (n : ℕ) : of_nat n • a = n •ℕ a := rfl
@[simp] theorem gpow_neg_succ (a : G) (n : ℕ) : a ^ -[1+n] = (a ^ n.succ)⁻¹ := rfl
@[simp] theorem gsmul_neg_succ (a : A) (n : ℕ) : -[1+n] • a = - (n.succ •ℕ a) := rfl
local attribute [ematch] le_of_lt
open nat
@[simp] theorem gpow_zero (a : G) : a ^ (0:ℤ) = 1 := rfl
@[simp] theorem zero_gsmul (a : A) : (0:ℤ) • a = 0 := rfl
@[simp] theorem gpow_one (a : G) : a ^ (1:ℤ) = a := mul_one _
@[simp] theorem one_gsmul (a : A) : (1:ℤ) • a = a := add_zero _
@[simp] theorem one_gpow : ∀ (n : ℤ), (1 : G) ^ n = 1
| (n : ℕ) := one_pow _
| -[1+ n] := show _⁻¹=(1:G), by rw [_root_.one_pow, one_inv]
@[simp] theorem gsmul_zero : ∀ (n : ℤ), n • (0 : A) = 0 :=
@one_gpow (multiplicative A) _
@[simp] theorem gpow_neg (a : G) : ∀ (n : ℤ), a ^ -n = (a ^ n)⁻¹
| (n+1:ℕ) := rfl
| 0 := one_inv.symm
| -[1+ n] := (inv_inv _).symm
@[simp] theorem neg_gsmul : ∀ (a : A) (n : ℤ), -n • a = -(n • a) :=
@gpow_neg (multiplicative A) _
theorem gpow_neg_one (x : G) : x ^ (-1:ℤ) = x⁻¹ := congr_arg has_inv.inv $ pow_one x
theorem neg_one_gsmul (x : A) : (-1:ℤ) • x = -x := congr_arg has_neg.neg $ add_monoid.one_smul x
theorem gsmul_one [has_one A] (n : ℤ) : n • (1 : A) = n :=
by cases n; simp
theorem inv_gpow (a : G) : ∀n:ℤ, a⁻¹ ^ n = (a ^ n)⁻¹
| (n : ℕ) := inv_pow a n
| -[1+ n] := congr_arg has_inv.inv $ inv_pow a (n+1)
theorem gsmul_neg (a : A) (n : ℤ) : gsmul n (- a) = - gsmul n a :=
@inv_gpow (multiplicative A) _ a n
private lemma gpow_add_aux (a : G) (m n : nat) :
a ^ ((of_nat m) + -[1+n]) = a ^ of_nat m * a ^ -[1+n] :=
or.elim (nat.lt_or_ge m (nat.succ n))
(assume h1 : m < succ n,
have h2 : m ≤ n, from le_of_lt_succ h1,
suffices a ^ -[1+ n-m] = a ^ of_nat m * a ^ -[1+n],
by rwa [of_nat_add_neg_succ_of_nat_of_lt h1],
show (a ^ nat.succ (n - m))⁻¹ = a ^ of_nat m * a ^ -[1+n],
by rw [← succ_sub h2, pow_sub _ (le_of_lt h1), mul_inv_rev, inv_inv]; refl)
(assume : m ≥ succ n,
suffices a ^ (of_nat (m - succ n)) = (a ^ (of_nat m)) * (a ^ -[1+ n]),
by rw [of_nat_add_neg_succ_of_nat_of_ge]; assumption,
suffices a ^ (m - succ n) = a ^ m * (a ^ n.succ)⁻¹, from this,
by rw pow_sub; assumption)
theorem gpow_add (a : G) : ∀ (i j : ℤ), a ^ (i + j) = a ^ i * a ^ j
| (of_nat m) (of_nat n) := pow_add _ _ _
| (of_nat m) -[1+n] := gpow_add_aux _ _ _
| -[1+m] (of_nat n) := by rw [add_comm, gpow_add_aux,
gpow_neg_succ, gpow_of_nat, ← inv_pow, ← pow_inv_comm]
| -[1+m] -[1+n] :=
suffices (a ^ (m + succ (succ n)))⁻¹ = (a ^ m.succ)⁻¹ * (a ^ n.succ)⁻¹, from this,
by rw [← succ_add_eq_succ_add, add_comm, _root_.pow_add, mul_inv_rev]
theorem add_gsmul : ∀ (a : A) (i j : ℤ), (i + j) • a = i • a + j • a :=
@gpow_add (multiplicative A) _
theorem gpow_add_one (a : G) (i : ℤ) : a ^ (i + 1) = a ^ i * a :=
by rw [gpow_add, gpow_one]
theorem add_one_gsmul : ∀ (a : A) (i : ℤ), (i + 1) • a = i • a + a :=
@gpow_add_one (multiplicative A) _
theorem gpow_one_add (a : G) (i : ℤ) : a ^ (1 + i) = a * a ^ i :=
by rw [gpow_add, gpow_one]
theorem one_add_gsmul : ∀ (a : A) (i : ℤ), (1 + i) • a = a + i • a :=
@gpow_one_add (multiplicative A) _
theorem gpow_mul_comm (a : G) (i j : ℤ) : a ^ i * a ^ j = a ^ j * a ^ i :=
by rw [← gpow_add, ← gpow_add, add_comm]
theorem gsmul_add_comm : ∀ (a : A) (i j), i • a + j • a = j • a + i • a :=
@gpow_mul_comm (multiplicative A) _
theorem gpow_mul (a : G) : ∀ m n : ℤ, a ^ (m * n) = (a ^ m) ^ n
| (m : ℕ) (n : ℕ) := pow_mul _ _ _
| (m : ℕ) -[1+ n] := (gpow_neg _ (m * succ n)).trans $
show (a ^ (m * succ n))⁻¹ = _, by rw pow_mul; refl
| -[1+ m] (n : ℕ) := (gpow_neg _ (succ m * n)).trans $
show (a ^ (m.succ * n))⁻¹ = _, by rw [pow_mul, ← inv_pow]; refl
| -[1+ m] -[1+ n] := (pow_mul a (succ m) (succ n)).trans $
show _ = (_⁻¹^_)⁻¹, by rw [inv_pow, inv_inv]
theorem gsmul_mul' : ∀ (a : A) (m n : ℤ), m * n • a = n • (m • a) :=
@gpow_mul (multiplicative A) _
theorem gpow_mul' (a : G) (m n : ℤ) : a ^ (m * n) = (a ^ n) ^ m :=
by rw [mul_comm, gpow_mul]
theorem gsmul_mul (a : A) (m n : ℤ) : m * n • a = m • (n • a) :=
by rw [mul_comm, gsmul_mul']
theorem gpow_bit0 (a : G) (n : ℤ) : a ^ bit0 n = a ^ n * a ^ n := gpow_add _ _ _
theorem bit0_gsmul (a : A) (n : ℤ) : bit0 n • a = n • a + n • a := gpow_add _ _ _
theorem gpow_bit1 (a : G) (n : ℤ) : a ^ bit1 n = a ^ n * a ^ n * a :=
by rw [bit1, gpow_add]; simp [gpow_bit0]
theorem bit1_gsmul : ∀ (a : A) (n : ℤ), bit1 n • a = n • a + n • a + a :=
@gpow_bit1 (multiplicative A) _
theorem monoid_hom.map_gpow (f : G →* H) (a : G) (n : ℤ) : f (a ^ n) = f a ^ n :=
by cases n; [exact f.map_pow _ _, exact (f.map_inv _).trans (congr_arg _ $ f.map_pow _ _)]
theorem add_monoid_hom.map_gsmul (f : A →+ B) (a : A) (n : ℤ) : f (n • a) = n • f a :=
f.to_multiplicative.map_gpow a n
end group
open_locale smul
section comm_group
variables [comm_group G] [add_comm_group A]
theorem mul_gpow (a b : G) : ∀ n:ℤ, (a * b)^n = a^n * b^n
| (n : ℕ) := mul_pow a b n
| -[1+ n] := show _⁻¹=_⁻¹*_⁻¹, by rw [mul_pow, mul_inv_rev, mul_comm]
theorem gsmul_add : ∀ (a b : A) (n : ℤ), n •ℤ (a + b) = n •ℤ a + n •ℤ b :=
@mul_gpow (multiplicative A) _
theorem gsmul_sub (a b : A) (n : ℤ) : gsmul n (a - b) = gsmul n a - gsmul n b :=
by simp only [gsmul_add, gsmul_neg, sub_eq_add_neg]
instance gpow.is_group_hom (n : ℤ) : is_group_hom ((^ n) : G → G) :=
{ map_mul := λ _ _, mul_gpow _ _ n }
instance gsmul.is_add_group_hom (n : ℤ) : is_add_group_hom (gsmul n : A → A) :=
{ map_add := λ _ _, gsmul_add _ _ n }
end comm_group
@[simp] lemma with_bot.coe_smul [add_monoid A] (a : A) (n : ℕ) :
((add_monoid.smul n a : A) : with_bot A) = add_monoid.smul n a :=
add_monoid_hom.map_smul ⟨_, with_bot.coe_zero, with_bot.coe_add⟩ a n
theorem add_monoid.smul_eq_mul' [semiring R] (a : R) (n : ℕ) : n • a = a * n :=
by induction n with n ih; [rw [add_monoid.zero_smul, nat.cast_zero, mul_zero],
rw [succ_smul', ih, nat.cast_succ, mul_add, mul_one]]
theorem add_monoid.smul_eq_mul [semiring R] (n : ℕ) (a : R) : n • a = n * a :=
by rw [add_monoid.smul_eq_mul', nat.mul_cast_comm]
theorem add_monoid.mul_smul_left [semiring R] (a b : R) (n : ℕ) : n • (a * b) = a * (n • b) :=
by rw [add_monoid.smul_eq_mul', add_monoid.smul_eq_mul', mul_assoc]
theorem add_monoid.mul_smul_assoc [semiring R] (a b : R) (n : ℕ) : n • (a * b) = n • a * b :=
by rw [add_monoid.smul_eq_mul, add_monoid.smul_eq_mul, mul_assoc]
lemma zero_pow [semiring R] : ∀ {n : ℕ}, 0 < n → (0 : R) ^ n = 0
| (n+1) _ := zero_mul _
@[simp, norm_cast] theorem nat.cast_pow [semiring R] (n m : ℕ) : (↑(n ^ m) : R) = ↑n ^ m :=
by induction m with m ih; [exact nat.cast_one, rw [nat.pow_succ, pow_succ', nat.cast_mul, ih]]
@[simp, norm_cast] theorem int.coe_nat_pow (n m : ℕ) : ((n ^ m : ℕ) : ℤ) = n ^ m :=
by induction m with m ih; [exact int.coe_nat_one, rw [nat.pow_succ, pow_succ', int.coe_nat_mul, ih]]
theorem int.nat_abs_pow (n : ℤ) (k : ℕ) : int.nat_abs (n ^ k) = (int.nat_abs n) ^ k :=
by induction k with k ih; [refl, rw [pow_succ', int.nat_abs_mul, nat.pow_succ, ih]]
namespace ring_hom
variables [semiring R] [semiring S]
@[simp] lemma map_pow (f : R →+* S) (a) :
∀ n : ℕ, f (a ^ n) = (f a) ^ n :=
f.to_monoid_hom.map_pow a
variable (f : R →+* R)
lemma iterate_map_pow (a) (n m : ℕ) : f^[n] (a^m) = (f^[n] a)^m :=
f.to_monoid_hom.iterate_map_pow a n m
lemma iterate_map_smul (a) (n m : ℕ) : f^[n] (m • a) = m • (f^[n] a) :=
f.to_add_monoid_hom.iterate_map_smul a n m
end ring_hom
lemma is_semiring_hom.map_pow [semiring R] [semiring S] (f : R → S) [is_semiring_hom f] (a) :
∀ n : ℕ, f (a ^ n) = (f a) ^ n :=
is_monoid_hom.map_pow f a
theorem neg_one_pow_eq_or [ring R] : ∀ n : ℕ, (-1 : R)^n = 1 ∨ (-1 : R)^n = -1
| 0 := or.inl rfl
| (n+1) := (neg_one_pow_eq_or n).swap.imp
(λ h, by rw [pow_succ, h, neg_one_mul, neg_neg])
(λ h, by rw [pow_succ, h, mul_one])
lemma pow_dvd_pow [comm_semiring R] (a : R) {m n : ℕ} (h : m ≤ n) :
a ^ m ∣ a ^ n := ⟨a ^ (n - m), by rw [← pow_add, nat.add_sub_cancel' h]⟩
theorem gsmul_eq_mul [ring R] (a : R) : ∀ n, n •ℤ a = n * a
| (n : ℕ) := add_monoid.smul_eq_mul _ _
| -[1+ n] := show -(_•_)=-_*_, by rw [neg_mul_eq_neg_mul_symm, add_monoid.smul_eq_mul, nat.cast_succ]
theorem gsmul_eq_mul' [ring R] (a : R) (n : ℤ) : n •ℤ a = a * n :=
by rw [gsmul_eq_mul, int.mul_cast_comm]
theorem mul_gsmul_left [ring R] (a b : R) (n : ℤ) : n •ℤ (a * b) = a * (n •ℤ b) :=
by rw [gsmul_eq_mul', gsmul_eq_mul', mul_assoc]
theorem mul_gsmul_assoc [ring R] (a b : R) (n : ℤ) : n •ℤ (a * b) = n •ℤ a * b :=
by rw [gsmul_eq_mul, gsmul_eq_mul, mul_assoc]
@[simp]
lemma gsmul_int_int (a b : ℤ) : a •ℤ b = a * b := by simp [gsmul_eq_mul]
lemma gsmul_int_one (n : ℤ) : n •ℤ 1 = n := by simp
@[simp, norm_cast] theorem int.cast_pow [ring R] (n : ℤ) (m : ℕ) : (↑(n ^ m) : R) = ↑n ^ m :=
by induction m with m ih; [exact int.cast_one,
rw [pow_succ, pow_succ, int.cast_mul, ih]]
lemma neg_one_pow_eq_pow_mod_two [ring R] {n : ℕ} : (-1 : R) ^ n = -1 ^ (n % 2) :=
by rw [← nat.mod_add_div n 2, pow_add, pow_mul]; simp [pow_two]
theorem sq_sub_sq [comm_ring R] (a b : R) : a ^ 2 - b ^ 2 = (a + b) * (a - b) :=
by rw [pow_two, pow_two, mul_self_sub_mul_self]
theorem pow_eq_zero [domain R] {x : R} {n : ℕ} (H : x^n = 0) : x = 0 :=
begin
induction n with n ih,
{ rw pow_zero at H,
rw [← mul_one x, H, mul_zero] },
exact or.cases_on (mul_eq_zero.1 H) id ih
end
@[field_simps] theorem pow_ne_zero [domain R] {a : R} (n : ℕ) (h : a ≠ 0) : a ^ n ≠ 0 :=
mt pow_eq_zero h
theorem add_monoid.smul_nonneg [ordered_add_comm_monoid R] {a : R} (H : 0 ≤ a) : ∀ n : ℕ, 0 ≤ n • a
| 0 := le_refl _
| (n+1) := add_nonneg' H (add_monoid.smul_nonneg n)
lemma pow_abs [decidable_linear_ordered_comm_ring R] (a : R) (n : ℕ) : (abs a)^n = abs (a^n) :=
by induction n with n ih; [exact (abs_one).symm,
rw [pow_succ, pow_succ, ih, abs_mul]]
lemma abs_neg_one_pow [decidable_linear_ordered_comm_ring R] (n : ℕ) : abs ((-1 : R)^n) = 1 :=
by rw [←pow_abs, abs_neg, abs_one, one_pow]
namespace add_monoid
variable [ordered_add_comm_monoid A]
theorem smul_le_smul {a : A} {n m : ℕ} (ha : 0 ≤ a) (h : n ≤ m) : n • a ≤ m • a :=
let ⟨k, hk⟩ := nat.le.dest h in
calc n • a = n • a + 0 : (add_zero _).symm
... ≤ n • a + k • a : add_le_add_left' (smul_nonneg ha _)
... = m • a : by rw [← hk, add_smul]
lemma smul_le_smul_of_le_right {a b : A} (hab : a ≤ b) : ∀ i : ℕ, i • a ≤ i • b
| 0 := by simp
| (k+1) := add_le_add' hab (smul_le_smul_of_le_right _)
end add_monoid
namespace canonically_ordered_semiring
variable [canonically_ordered_comm_semiring R]
theorem pow_pos {a : R} (H : 0 < a) : ∀ n : ℕ, 0 < a ^ n
| 0 := canonically_ordered_semiring.zero_lt_one
| (n+1) := canonically_ordered_semiring.mul_pos.2 ⟨H, pow_pos n⟩
lemma pow_le_pow_of_le_left {a b : R} (hab : a ≤ b) : ∀ i : ℕ, a^i ≤ b^i
| 0 := by simp
| (k+1) := canonically_ordered_semiring.mul_le_mul hab (pow_le_pow_of_le_left k)
theorem one_le_pow_of_one_le {a : R} (H : 1 ≤ a) (n : ℕ) : 1 ≤ a ^ n :=
by simpa only [one_pow] using pow_le_pow_of_le_left H n
theorem pow_le_one {a : R} (H : a ≤ 1) (n : ℕ) : a ^ n ≤ 1:=
by simpa only [one_pow] using pow_le_pow_of_le_left H n
end canonically_ordered_semiring
section linear_ordered_semiring
variable [linear_ordered_semiring R]
theorem pow_pos {a : R} (H : 0 < a) : ∀ (n : ℕ), 0 < a ^ n
| 0 := zero_lt_one
| (n+1) := mul_pos H (pow_pos _)
theorem pow_nonneg {a : R} (H : 0 ≤ a) : ∀ (n : ℕ), 0 ≤ a ^ n
| 0 := zero_le_one
| (n+1) := mul_nonneg H (pow_nonneg _)
theorem pow_lt_pow_of_lt_left {x y : R} {n : ℕ} (Hxy : x < y) (Hxpos : 0 ≤ x) (Hnpos : 0 < n) :
x ^ n < y ^ n :=
begin
cases lt_or_eq_of_le Hxpos,
{ rw ←nat.sub_add_cancel Hnpos,
induction (n - 1), { simpa only [pow_one] },
rw [pow_add, pow_add, nat.succ_eq_add_one, pow_one, pow_one],
apply mul_lt_mul ih (le_of_lt Hxy) h (le_of_lt (pow_pos (lt_trans h Hxy) _)) },
{ rw [←h, zero_pow Hnpos], apply pow_pos (by rwa ←h at Hxy : 0 < y),}
end
theorem pow_right_inj {x y : R} {n : ℕ} (Hxpos : 0 ≤ x) (Hypos : 0 ≤ y) (Hnpos : 0 < n)
(Hxyn : x ^ n = y ^ n) : x = y :=
begin
rcases lt_trichotomy x y with hxy | rfl | hyx,
{ exact absurd Hxyn (ne_of_lt (pow_lt_pow_of_lt_left hxy Hxpos Hnpos)) },
{ refl },
{ exact absurd Hxyn (ne_of_gt (pow_lt_pow_of_lt_left hyx Hypos Hnpos)) },
end
theorem one_le_pow_of_one_le {a : R} (H : 1 ≤ a) : ∀ (n : ℕ), 1 ≤ a ^ n
| 0 := le_refl _
| (n+1) := by simpa only [mul_one] using mul_le_mul H (one_le_pow_of_one_le n)
zero_le_one (le_trans zero_le_one H)
/-- Bernoulli's inequality. This version works for semirings but requires
an additional hypothesis `0 ≤ a * a`. -/
theorem one_add_mul_le_pow' {a : R} (Hsqr : 0 ≤ a * a) (H : 0 ≤ 1 + a) :
∀ (n : ℕ), 1 + n • a ≤ (1 + a) ^ n
| 0 := le_of_eq $ add_zero _
| (n+1) :=
calc 1 + (n + 1) • a ≤ (1 + a) * (1 + n • a) :
by simpa [succ_smul, mul_add, add_mul, add_monoid.mul_smul_left, add_comm, add_left_comm]
using add_monoid.smul_nonneg Hsqr n
... ≤ (1 + a)^(n+1) : mul_le_mul_of_nonneg_left (one_add_mul_le_pow' n) H
theorem pow_le_pow {a : R} {n m : ℕ} (ha : 1 ≤ a) (h : n ≤ m) : a ^ n ≤ a ^ m :=
let ⟨k, hk⟩ := nat.le.dest h in
calc a ^ n = a ^ n * 1 : (mul_one _).symm
... ≤ a ^ n * a ^ k : mul_le_mul_of_nonneg_left
(one_le_pow_of_one_le ha _)
(pow_nonneg (le_trans zero_le_one ha) _)
... = a ^ m : by rw [←hk, pow_add]
lemma pow_lt_pow {a : R} {n m : ℕ} (h : 1 < a) (h2 : n < m) : a ^ n < a ^ m :=
begin
have h' : 1 ≤ a := le_of_lt h,
have h'' : 0 < a := lt_trans zero_lt_one h,
cases m, cases h2, rw [pow_succ, ←one_mul (a ^ n)],
exact mul_lt_mul h (pow_le_pow h' (nat.le_of_lt_succ h2)) (pow_pos h'' _) (le_of_lt h'')
end
lemma pow_le_pow_of_le_left {a b : R} (ha : 0 ≤ a) (hab : a ≤ b) : ∀ i : ℕ, a^i ≤ b^i
| 0 := by simp
| (k+1) := mul_le_mul hab (pow_le_pow_of_le_left _) (pow_nonneg ha _) (le_trans ha hab)
lemma lt_of_pow_lt_pow {a b : R} (n : ℕ) (hb : 0 ≤ b) (h : a ^ n < b ^ n) : a < b :=
lt_of_not_ge $ λ hn, not_lt_of_ge (pow_le_pow_of_le_left hb hn _) h
private lemma pow_lt_pow_of_lt_one_aux {a : R} (h : 0 < a) (ha : a < 1) (i : ℕ) :
∀ k : ℕ, a ^ (i + k + 1) < a ^ i
| 0 :=
begin
simp only [add_zero],
rw ←one_mul (a^i), exact mul_lt_mul ha (le_refl _) (pow_pos h _) zero_le_one
end
| (k+1) :=
begin
rw ←one_mul (a^i),
apply mul_lt_mul ha _ _ zero_le_one,
{ apply le_of_lt, apply pow_lt_pow_of_lt_one_aux },
{ show 0 < a ^ (i + (k + 1) + 0), apply pow_pos h }
end
private lemma pow_le_pow_of_le_one_aux {a : R} (h : 0 ≤ a) (ha : a ≤ 1) (i : ℕ) :
∀ k : ℕ, a ^ (i + k) ≤ a ^ i
| 0 := by simp
| (k+1) := by rw [←add_assoc, ←one_mul (a^i)];
exact mul_le_mul ha (pow_le_pow_of_le_one_aux _) (pow_nonneg h _) zero_le_one
lemma pow_lt_pow_of_lt_one {a : R} (h : 0 < a) (ha : a < 1)
{i j : ℕ} (hij : i < j) : a ^ j < a ^ i :=
let ⟨k, hk⟩ := nat.exists_eq_add_of_lt hij in
by rw hk; exact pow_lt_pow_of_lt_one_aux h ha _ _
lemma pow_le_pow_of_le_one {a : R} (h : 0 ≤ a) (ha : a ≤ 1)
{i j : ℕ} (hij : i ≤ j) : a ^ j ≤ a ^ i :=
let ⟨k, hk⟩ := nat.exists_eq_add_of_le hij in
by rw hk; exact pow_le_pow_of_le_one_aux h ha _ _
lemma pow_le_one {x : R} : ∀ (n : ℕ) (h0 : 0 ≤ x) (h1 : x ≤ 1), x ^ n ≤ 1
| 0 h0 h1 := le_refl (1 : R)
| (n+1) h0 h1 := mul_le_one h1 (pow_nonneg h0 _) (pow_le_one n h0 h1)
end linear_ordered_semiring
theorem pow_two_nonneg [linear_ordered_ring R] (a : R) : 0 ≤ a ^ 2 :=
by { rw pow_two, exact mul_self_nonneg _ }
/-- Bernoulli's inequality for `n : ℕ`, `-2 ≤ a`. -/
theorem one_add_mul_le_pow [linear_ordered_ring R] {a : R} (H : -2 ≤ a) :
∀ (n : ℕ), 1 + n • a ≤ (1 + a) ^ n
| 0 := le_of_eq $ add_zero _
| 1 := by simp
| (n+2) :=
have H' : 0 ≤ 2 + a,
from neg_le_iff_add_nonneg.1 H,
have 0 ≤ n • (a * a * (2 + a)) + a * a,
from add_nonneg (add_monoid.smul_nonneg (mul_nonneg (mul_self_nonneg a) H') n)
(mul_self_nonneg a),
calc 1 + (n + 2) • a ≤ 1 + (n + 2) • a + (n • (a * a * (2 + a)) + a * a) :
(le_add_iff_nonneg_right _).2 this
... = (1 + a) * (1 + a) * (1 + n • a) :
by { simp only [add_mul, mul_add, mul_two, mul_one, one_mul, succ_smul, add_monoid.smul_add,
add_monoid.mul_smul_assoc, (add_monoid.mul_smul_left _ _ _).symm],
ac_refl }
... ≤ (1 + a) * (1 + a) * (1 + a)^n :
mul_le_mul_of_nonneg_left (one_add_mul_le_pow n) (mul_self_nonneg (1 + a))
... = (1 + a)^(n + 2) : by simp only [pow_succ, mul_assoc]
/-- Bernoulli's inequality reformulated to estimate `a^n`. -/
theorem one_add_sub_mul_le_pow [linear_ordered_ring R]
{a : R} (H : -1 ≤ a) (n : ℕ) : 1 + n • (a - 1) ≤ a ^ n :=
have -2 ≤ a - 1, by { rw [bit0, neg_add], exact sub_le_sub_right H 1 },
by simpa only [add_sub_cancel'_right] using one_add_mul_le_pow this n
namespace int
lemma units_pow_two (u : units ℤ) : u ^ 2 = 1 :=
(units_eq_one_or u).elim (λ h, h.symm ▸ rfl) (λ h, h.symm ▸ rfl)
lemma units_pow_eq_pow_mod_two (u : units ℤ) (n : ℕ) : u ^ n = u ^ (n % 2) :=
by conv {to_lhs, rw ← nat.mod_add_div n 2}; rw [pow_add, pow_mul, units_pow_two, one_pow, mul_one]
end int
@[simp] lemma neg_square {α} [ring α] (z : α) : (-z)^2 = z^2 :=
by simp [pow, monoid.pow]
lemma of_add_smul [add_monoid A] (x : A) (n : ℕ) :
multiplicative.of_add (n • x) = (multiplicative.of_add x)^n := rfl
lemma of_add_gsmul [add_group A] (x : A) (n : ℤ) :
multiplicative.of_add (n •ℤ x) = (multiplicative.of_add x)^n := rfl
variables (M G A)
/-- Monoid homomorphisms from `multiplicative ℕ` are defined by the image
of `multiplicative.of_add 1`. -/
def powers_hom [monoid M] : M ≃ (multiplicative ℕ →* M) :=
{ to_fun := λ x, ⟨λ n, x ^ n.to_add, pow_zero x, λ m n, pow_add x m n⟩,
inv_fun := λ f, f (multiplicative.of_add 1),
left_inv := pow_one,
right_inv := λ f, monoid_hom.ext $ λ n, by { simp [← f.map_pow, ← of_add_smul] } }
/-- Monoid homomorphisms from `multiplicative ℤ` are defined by the image
of `multiplicative.of_add 1`. -/
def gpowers_hom [group G] : G ≃ (multiplicative ℤ →* G) :=
{ to_fun := λ x, ⟨λ n, x ^ n.to_add, gpow_zero x, λ m n, gpow_add x m n⟩,
inv_fun := λ f, f (multiplicative.of_add 1),
left_inv := gpow_one,
right_inv := λ f, monoid_hom.ext $ λ n, by { simp [← f.map_gpow, ← of_add_gsmul ] } }
/-- Additive homomorphisms from `ℕ` are defined by the image of `1`. -/
def multiples_hom [add_monoid A] : A ≃ (ℕ →+ A) :=
{ to_fun := λ x, ⟨λ n, n • x, add_monoid.zero_smul x, λ m n, add_monoid.add_smul _ _ _⟩,
inv_fun := λ f, f 1,
left_inv := add_monoid.one_smul,
right_inv := λ f, add_monoid_hom.ext $ λ n, by simp [← f.map_smul] }
/-- Additive homomorphisms from `ℤ` are defined by the image of `1`. -/
def gmultiples_hom [add_group A] : A ≃ (ℤ →+ A) :=
{ to_fun := λ x, ⟨λ n, n •ℤ x, zero_gsmul x, λ m n, add_gsmul _ _ _⟩,
inv_fun := λ f, f 1,
left_inv := one_gsmul,
right_inv := λ f, add_monoid_hom.ext $ λ n, by simp [← f.map_gsmul] }
variables {M G A}
@[simp] lemma powers_hom_apply [monoid M] (x : M) (n : multiplicative ℕ) :
powers_hom M x n = x ^ n.to_add := rfl
@[simp] lemma powers_hom_symm_apply [monoid M] (f : multiplicative ℕ →* M) :
(powers_hom M).symm f = f (multiplicative.of_add 1) := rfl
lemma mnat_monoid_hom_eq [monoid M] (f : multiplicative ℕ →* M) (n : multiplicative ℕ) :
f n = (f (multiplicative.of_add 1)) ^ n.to_add :=
by rw [← powers_hom_symm_apply, ← powers_hom_apply, equiv.apply_symm_apply]
lemma mnat_monoid_hom_ext [monoid M] ⦃f g : multiplicative ℕ →* M⦄
(h : f (multiplicative.of_add 1) = g (multiplicative.of_add 1)) : f = g :=
monoid_hom.ext $ λ n, by rw [mnat_monoid_hom_eq f, mnat_monoid_hom_eq g, h]
|
05892f12c425956429d26631b7f827bb532a0828 | a9d0fb7b0e4f802bd3857b803e6c5c23d87fef91 | /tests/lean/run/600c.lean | fc503a7ed77dc4dd2d095ca2238df7fa218b1d0f | [
"Apache-2.0"
] | permissive | soonhokong/lean-osx | 4a954262c780e404c1369d6c06516161d07fcb40 | 3670278342d2f4faa49d95b46d86642d7875b47c | refs/heads/master | 1,611,410,334,552 | 1,474,425,686,000 | 1,474,425,686,000 | 12,043,103 | 5 | 1 | null | null | null | null | UTF-8 | Lean | false | false | 95 | lean | /- /- -/ -/
/- - /--/-/
/-/-/--/-/-/
/--/
/------------/
/---/
/- ---/
/-
-/
----/
print "ok"
|
e2ab7459a5429b5e4c234ac9ba474ae788797311 | 6432ea7a083ff6ba21ea17af9ee47b9c371760f7 | /tests/lean/run/elseCaseArrow.lean | c3c4358109b7b94d8a218b8e5264e6a4a065b7e0 | [
"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 | 241 | lean | def f1 (x : Nat) (p : Nat × Nat) : IO Unit := do
match x with
| 0 => let (y, _) ← pure p
| _ => pure ()
def f2 (x : Nat) (p : Nat × Nat) : IO Unit := do
let mut y := 0
match x with
| 0 => (y, _) ← pure p
| _ => pure ()
|
9cf18e7e51bee90148f788cdcb36c74cd9572904 | 4d2583807a5ac6caaffd3d7a5f646d61ca85d532 | /src/algebra/linear_recurrence.lean | 929df10a668307057c37bdcb50ffaf7a524e2068 | [
"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 | 8,243 | lean | /-
Copyright (c) 2020 Anatole Dedecker. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anatole Dedecker
-/
import data.polynomial.ring_division
import linear_algebra.dimension
import algebra.polynomial.big_operators
/-!
# Linear recurrence
Informally, a "linear recurrence" is an assertion of the form
`∀ n : ℕ, u (n + d) = a 0 * u n + a 1 * u (n+1) + ... + a (d-1) * u (n+d-1)`,
where `u` is a sequence, `d` is the *order* of the recurrence and the `a i`
are its *coefficients*.
In this file, we define the structure `linear_recurrence` so that
`linear_recurrence.mk d a` represents the above relation, and we call
a sequence `u` which verifies it a *solution* of the linear recurrence.
We prove a few basic lemmas about this concept, such as :
* the space of solutions is a submodule of `(ℕ → α)` (i.e a vector space if `α`
is a field)
* the function that maps a solution `u` to its first `d` terms builds a `linear_equiv`
between the solution space and `fin d → α`, aka `α ^ d`. As a consequence, two
solutions are equal if and only if their first `d` terms are equals.
* a geometric sequence `q ^ n` is solution iff `q` is a root of a particular polynomial,
which we call the *characteristic polynomial* of the recurrence
Of course, although we can inductively generate solutions (cf `mk_sol`), the
interesting part would be to determinate closed-forms for the solutions.
This is currently *not implemented*, as we are waiting for definition and
properties of eigenvalues and eigenvectors.
-/
noncomputable theory
open finset
open_locale big_operators
/-- A "linear recurrence relation" over a commutative semiring is given by its
order `n` and `n` coefficients. -/
structure linear_recurrence (α : Type*) [comm_semiring α] := (order : ℕ) (coeffs : fin order → α)
instance (α : Type*) [comm_semiring α] : inhabited (linear_recurrence α) :=
⟨⟨0, default _⟩⟩
namespace linear_recurrence
section comm_semiring
variables {α : Type*} [comm_semiring α] (E : linear_recurrence α)
/-- We say that a sequence `u` is solution of `linear_recurrence order coeffs` when we have
`u (n + order) = ∑ i : fin order, coeffs i * u (n + i)` for any `n`. -/
def is_solution (u : ℕ → α) :=
∀ n, u (n + E.order) = ∑ i, E.coeffs i * u (n + i)
/-- A solution of a `linear_recurrence` which satisfies certain initial conditions.
We will prove this is the only such solution. -/
def mk_sol (init : fin E.order → α) : ℕ → α
| n := if h : n < E.order then init ⟨n, h⟩ else
∑ k : fin E.order,
have n - E.order + k < n :=
begin
rw [add_comm, ← add_tsub_assoc_of_le (not_lt.mp h), tsub_lt_iff_left],
{ exact add_lt_add_right k.is_lt n },
{ convert add_le_add (zero_le (k : ℕ)) (not_lt.mp h),
simp only [zero_add] }
end,
E.coeffs k * mk_sol (n - E.order + k)
/-- `E.mk_sol` indeed gives solutions to `E`. -/
lemma is_sol_mk_sol (init : fin E.order → α) : E.is_solution (E.mk_sol init) :=
λ n, by rw mk_sol; simp
/-- `E.mk_sol init`'s first `E.order` terms are `init`. -/
lemma mk_sol_eq_init (init : fin E.order → α) : ∀ n : fin E.order, E.mk_sol init n = init n :=
λ n, by { rw mk_sol, simp only [n.is_lt, dif_pos, fin.mk_coe, fin.eta] }
/-- If `u` is a solution to `E` and `init` designates its first `E.order` values,
then `∀ n, u n = E.mk_sol init n`. -/
lemma eq_mk_of_is_sol_of_eq_init {u : ℕ → α} {init : fin E.order → α}
(h : E.is_solution u) (heq : ∀ n : fin E.order, u n = init n) :
∀ n, u n = E.mk_sol init n
| n := if h' : n < E.order
then by rw mk_sol; simp only [h', dif_pos]; exact_mod_cast heq ⟨n, h'⟩
else begin
rw [mk_sol, ← tsub_add_cancel_of_le (le_of_not_lt h'), h (n-E.order)],
simp [h'],
congr' with k,
exact have wf : n - E.order + k < n :=
begin
rw [add_comm, ← add_tsub_assoc_of_le (not_lt.mp h'), tsub_lt_iff_left],
{ exact add_lt_add_right k.is_lt n },
{ convert add_le_add (zero_le (k : ℕ)) (not_lt.mp h'),
simp only [zero_add] }
end,
by rw eq_mk_of_is_sol_of_eq_init
end
/-- If `u` is a solution to `E` and `init` designates its first `E.order` values,
then `u = E.mk_sol init`. This proves that `E.mk_sol init` is the only solution
of `E` whose first `E.order` values are given by `init`. -/
lemma eq_mk_of_is_sol_of_eq_init' {u : ℕ → α} {init : fin E.order → α}
(h : E.is_solution u) (heq : ∀ n : fin E.order, u n = init n) : u = E.mk_sol init :=
funext (E.eq_mk_of_is_sol_of_eq_init h heq)
/-- The space of solutions of `E`, as a `submodule` over `α` of the module `ℕ → α`. -/
def sol_space : submodule α (ℕ → α) :=
{ carrier := {u | E.is_solution u},
zero_mem' := λ n, by simp,
add_mem' := λ u v hu hv n, by simp [mul_add, sum_add_distrib, hu n, hv n],
smul_mem' := λ a u hu n, by simp [hu n, mul_sum]; congr'; ext; ac_refl }
/-- Defining property of the solution space : `u` is a solution
iff it belongs to the solution space. -/
lemma is_sol_iff_mem_sol_space (u : ℕ → α) : E.is_solution u ↔ u ∈ E.sol_space :=
iff.rfl
/-- The function that maps a solution `u` of `E` to its first
`E.order` terms as a `linear_equiv`. -/
def to_init :
E.sol_space ≃ₗ[α] (fin E.order → α) :=
{ to_fun := λ u x, (u : ℕ → α) x,
map_add' := λ u v, by { ext, simp },
map_smul' := λ a u, by { ext, simp },
inv_fun := λ u, ⟨E.mk_sol u, E.is_sol_mk_sol u⟩,
left_inv := λ u, by ext n; symmetry; apply E.eq_mk_of_is_sol_of_eq_init u.2; intros k; refl,
right_inv := λ u, function.funext_iff.mpr (λ n, E.mk_sol_eq_init u n) }
/-- Two solutions are equal iff they are equal on `range E.order`. -/
lemma sol_eq_of_eq_init (u v : ℕ → α) (hu : E.is_solution u) (hv : E.is_solution v) :
u = v ↔ set.eq_on u v ↑(range E.order) :=
begin
refine iff.intro (λ h x hx, h ▸ rfl) _,
intro h,
set u' : ↥(E.sol_space) := ⟨u, hu⟩,
set v' : ↥(E.sol_space) := ⟨v, hv⟩,
change u'.val = v'.val,
suffices h' : u' = v', from h' ▸ rfl,
rw [← E.to_init.to_equiv.apply_eq_iff_eq, linear_equiv.coe_to_equiv],
ext x,
exact_mod_cast h (mem_range.mpr x.2)
end
/-! `E.tuple_succ` maps `![s₀, s₁, ..., sₙ]` to `![s₁, ..., sₙ, ∑ (E.coeffs i) * sᵢ]`,
where `n := E.order`. This operation is quite useful for determining closed-form
solutions of `E`. -/
/-- `E.tuple_succ` maps `![s₀, s₁, ..., sₙ]` to `![s₁, ..., sₙ, ∑ (E.coeffs i) * sᵢ]`,
where `n := E.order`. -/
def tuple_succ : (fin E.order → α) →ₗ[α] (fin E.order → α) :=
{ to_fun := λ X i, if h : (i : ℕ) + 1 < E.order then X ⟨i+1, h⟩ else (∑ i, E.coeffs i * X i),
map_add' := λ x y,
begin
ext i,
split_ifs ; simp [h, mul_add, sum_add_distrib],
end,
map_smul' := λ x y,
begin
ext i,
split_ifs ; simp [h, mul_sum],
exact sum_congr rfl (λ x _, by ac_refl),
end }
end comm_semiring
section field
variables {α : Type*} [field α] (E : linear_recurrence α)
/-- The dimension of `E.sol_space` is `E.order`. -/
lemma sol_space_dim : module.rank α E.sol_space = E.order :=
@dim_fin_fun α _ E.order ▸ E.to_init.dim_eq
end field
section comm_ring
variables {α : Type*} [comm_ring α] (E : linear_recurrence α)
/-- The characteristic polynomial of `E` is
`X ^ E.order - ∑ i : fin E.order, (E.coeffs i) * X ^ i`. -/
def char_poly : polynomial α :=
polynomial.monomial E.order 1 - (∑ i : fin E.order, polynomial.monomial i (E.coeffs i))
/-- The geometric sequence `q^n` is a solution of `E` iff
`q` is a root of `E`'s characteristic polynomial. -/
lemma geom_sol_iff_root_char_poly (q : α) : E.is_solution (λ n, q^n) ↔ E.char_poly.is_root q :=
begin
rw [char_poly, polynomial.is_root.def, polynomial.eval],
simp only [polynomial.eval₂_finset_sum, one_mul,
ring_hom.id_apply, polynomial.eval₂_monomial, polynomial.eval₂_sub],
split,
{ intro h,
simpa [sub_eq_zero] using h 0 },
{ intros h n,
simp only [pow_add, sub_eq_zero.mp h, mul_sum],
exact sum_congr rfl (λ _ _, by ring) }
end
end comm_ring
end linear_recurrence
|
13db253220e9c2dfebf53b85cfe7bc49c519a85b | ff5230333a701471f46c57e8c115a073ebaaa448 | /tests/lean/1952.lean | e21dcaff4cb18358f064943cbd9ecbd87bf57f2c | [
"Apache-2.0"
] | permissive | stanford-cs242/lean | f81721d2b5d00bc175f2e58c57b710d465e6c858 | 7bd861261f4a37326dcf8d7a17f1f1f330e4548c | refs/heads/master | 1,600,957,431,849 | 1,576,465,093,000 | 1,576,465,093,000 | 225,779,423 | 0 | 3 | Apache-2.0 | 1,575,433,936,000 | 1,575,433,935,000 | null | UTF-8 | Lean | false | false | 431 | lean | structure foo :=
(fn : nat → nat)
(fn_ax : ∀ a : nat, fn a = a)
/-
set_option pp.all true
set_option pp.universes false -- universes are probably irrelevant
set_option pp.purify_metavars false
set_option trace.type_context.is_def_eq true
set_option trace.type_context.is_def_eq_detail true
-/
def bla : foo := { fn_ax := λ x, rfl }
instance foo2 (α : Type) : group α := { mul_assoc := λ x y z, rfl }
|
7a8040c8af94a300d9c65b8b5f478cd47a310441 | b70031c8e2c5337b91d7e70f1e0c5f528f7b0e77 | /src/analysis/calculus/deriv.lean | 4bbf6b4bc0f7625edf41138b58542e8db7fa566d | [
"Apache-2.0"
] | permissive | molodiuc/mathlib | cae2ba3ef1601c1f42ca0b625c79b061b63fef5b | 98ebe5a6739fbe254f9ee9d401882d4388f91035 | refs/heads/master | 1,674,237,127,059 | 1,606,353,533,000 | 1,606,353,533,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 71,914 | 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 :=
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 :=
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 :=
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 :=
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 continuous : continuous (λx, p.eval x) :=
p.differentiable.continuous
protected lemma continuous_on : continuous_on (λx, p.eval x) s :=
p.continuous.continuous_on
protected lemma continuous_at : continuous_at (λx, p.eval x) x :=
p.continuous.continuous_at
protected lemma continuous_within_at : continuous_within_at (λx, p.eval x) s x :=
p.continuous_at.continuous_within_at
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
|
4c999378713e65c53147b7c98e49f41d38b6fe03 | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/algebra/lie/non_unital_non_assoc_algebra.lean | 3d6397abd99385c02de35ee623095e340033e905 | [
"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 | 3,774 | 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.hom.non_unital_alg
import algebra.lie.basic
/-!
# Lie algebras as non-unital, non-associative algebras
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
The definition of Lie algebras uses the `has_bracket` typeclass for multiplication whereas we have a
separate `has_mul` typeclass used for general algebras.
It is useful to have a special typeclass for Lie algebras because:
* it enables us to use the traditional notation `⁅x, y⁆` for the Lie multiplication,
* associative algebras carry a natural Lie algebra structure via the ring commutator and so we need
them to carry both `has_mul` and `has_bracket` simultaneously,
* more generally, Poisson algebras (not yet defined) need both typeclasses.
However there are times when it is convenient to be able to regard a Lie algebra as a general
algebra and we provide some basic definitions for doing so here.
## Main definitions
* `commutator_ring` turns a Lie ring into a `non_unital_non_assoc_semiring` by turning its
`has_bracket` (denoted `⁅, ⁆`) into a `has_mul` (denoted `*`).
* `lie_hom.to_non_unital_alg_hom`
## Tags
lie algebra, non-unital, non-associative
-/
universes u v w
variables (R : Type u) (L : Type v) [comm_ring R] [lie_ring L] [lie_algebra R L]
/-- Type synonym for turning a `lie_ring` into a `non_unital_non_assoc_semiring`.
A `lie_ring` can be regarded as a `non_unital_non_assoc_semiring` by turning its
`has_bracket` (denoted `⁅, ⁆`) into a `has_mul` (denoted `*`). -/
def commutator_ring (L : Type v) : Type v := L
/-- A `lie_ring` can be regarded as a `non_unital_non_assoc_semiring` by turning its
`has_bracket` (denoted `⁅, ⁆`) into a `has_mul` (denoted `*`). -/
instance : non_unital_non_assoc_semiring (commutator_ring L) :=
show non_unital_non_assoc_semiring L, from
{ mul := has_bracket.bracket,
left_distrib := lie_add,
right_distrib := add_lie,
zero_mul := zero_lie,
mul_zero := lie_zero,
.. (infer_instance : add_comm_monoid L) }
namespace lie_algebra
instance (L : Type v) [nonempty L] : nonempty (commutator_ring L) :=
‹nonempty L›
instance (L : Type v) [inhabited L] : inhabited (commutator_ring L) :=
‹inhabited L›
instance : lie_ring (commutator_ring L) :=
show lie_ring L, by apply_instance
instance : lie_algebra R (commutator_ring L) :=
show lie_algebra R L, by apply_instance
/-- Regarding the `lie_ring` of a `lie_algebra` as a `non_unital_non_assoc_semiring`, we can
reinterpret the `smul_lie` law as an `is_scalar_tower`. -/
instance is_scalar_tower : is_scalar_tower R (commutator_ring L) (commutator_ring L) := ⟨smul_lie⟩
/-- Regarding the `lie_ring` of a `lie_algebra` as a `non_unital_non_assoc_semiring`, we can
reinterpret the `lie_smul` law as an `smul_comm_class`. -/
instance smul_comm_class : smul_comm_class R (commutator_ring L) (commutator_ring L) :=
⟨λ t x y, (lie_smul t x y).symm⟩
end lie_algebra
namespace lie_hom
variables {R L} {L₂ : Type w} [lie_ring L₂] [lie_algebra R L₂]
/-- Regarding the `lie_ring` of a `lie_algebra` as a `non_unital_non_assoc_semiring`, we can
regard a `lie_hom` as a `non_unital_alg_hom`. -/
@[simps]
def to_non_unital_alg_hom (f : L →ₗ⁅R⁆ L₂) : commutator_ring L →ₙₐ[R] commutator_ring L₂ :=
{ to_fun := f,
map_zero' := f.map_zero,
map_mul' := f.map_lie,
..f }
lemma to_non_unital_alg_hom_injective :
function.injective (to_non_unital_alg_hom : _ → (commutator_ring L →ₙₐ[R] commutator_ring L₂)) :=
λ f g h, ext $ non_unital_alg_hom.congr_fun h
end lie_hom
|
de89c585fd2e6191d5b226b5ce5285003c413518 | d1bbf1801b3dcb214451d48214589f511061da63 | /src/data/int/basic.lean | dd997115eef8035a2750b2139caf014fa5d3b791 | [
"Apache-2.0"
] | permissive | cheraghchi/mathlib | 5c366f8c4f8e66973b60c37881889da8390cab86 | f29d1c3038422168fbbdb2526abf7c0ff13e86db | refs/heads/master | 1,676,577,831,283 | 1,610,894,638,000 | 1,610,894,638,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 51,444 | lean | /-
Copyright (c) 2016 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad
The integers, with addition, multiplication, and subtraction.
-/
import data.nat.basic
import algebra.order_functions
open nat
namespace int
instance : inhabited ℤ := ⟨int.zero⟩
instance : nontrivial ℤ :=
⟨⟨0, 1, int.zero_ne_one⟩⟩
instance : comm_ring int :=
{ add := int.add,
add_assoc := int.add_assoc,
zero := int.zero,
zero_add := int.zero_add,
add_zero := int.add_zero,
neg := int.neg,
add_left_neg := int.add_left_neg,
add_comm := int.add_comm,
mul := int.mul,
mul_assoc := int.mul_assoc,
one := int.one,
one_mul := int.one_mul,
mul_one := int.mul_one,
sub := int.sub,
left_distrib := int.distrib_left,
right_distrib := int.distrib_right,
mul_comm := int.mul_comm }
/-! ### Extra instances to short-circuit type class resolution -/
-- instance : has_sub int := by apply_instance -- This is in core
instance : add_comm_monoid int := by apply_instance
instance : add_monoid int := by apply_instance
instance : monoid int := by apply_instance
instance : comm_monoid int := by apply_instance
instance : comm_semigroup int := by apply_instance
instance : semigroup int := by apply_instance
instance : add_comm_semigroup int := by apply_instance
instance : add_semigroup int := by apply_instance
instance : comm_semiring int := by apply_instance
instance : semiring int := by apply_instance
instance : ring int := by apply_instance
instance : distrib int := by apply_instance
instance : linear_ordered_comm_ring int :=
{ add_le_add_left := @int.add_le_add_left,
mul_pos := @int.mul_pos,
zero_le_one := le_of_lt int.zero_lt_one,
.. int.comm_ring, .. int.linear_order, .. int.nontrivial }
instance : linear_ordered_add_comm_group int :=
by apply_instance
theorem abs_eq_nat_abs : ∀ a : ℤ, abs a = nat_abs a
| (n : ℕ) := abs_of_nonneg $ coe_zero_le _
| -[1+ n] := abs_of_nonpos $ le_of_lt $ neg_succ_lt_zero _
theorem nat_abs_abs (a : ℤ) : nat_abs (abs a) = nat_abs a :=
by rw [abs_eq_nat_abs]; refl
theorem sign_mul_abs (a : ℤ) : sign a * abs a = a :=
by rw [abs_eq_nat_abs, sign_mul_nat_abs]
@[simp] lemma default_eq_zero : default ℤ = 0 := rfl
meta instance : has_to_format ℤ := ⟨λ z, to_string z⟩
meta instance : has_reflect ℤ := by tactic.mk_has_reflect_instance
attribute [simp] int.coe_nat_add int.coe_nat_mul int.coe_nat_zero int.coe_nat_one int.coe_nat_succ
attribute [simp] int.of_nat_eq_coe int.bodd
@[simp] theorem add_def {a b : ℤ} : int.add a b = a + b := rfl
@[simp] theorem mul_def {a b : ℤ} : int.mul a b = a * b := rfl
@[simp] theorem coe_nat_mul_neg_succ (m n : ℕ) : (m : ℤ) * -[1+ n] = -(m * succ n) := rfl
@[simp] theorem neg_succ_mul_coe_nat (m n : ℕ) : -[1+ m] * n = -(succ m * n) := rfl
@[simp] theorem neg_succ_mul_neg_succ (m n : ℕ) : -[1+ m] * -[1+ n] = succ m * succ n := rfl
@[simp, norm_cast]
theorem coe_nat_le {m n : ℕ} : (↑m : ℤ) ≤ ↑n ↔ m ≤ n := coe_nat_le_coe_nat_iff m n
@[simp, norm_cast]
theorem coe_nat_lt {m n : ℕ} : (↑m : ℤ) < ↑n ↔ m < n := coe_nat_lt_coe_nat_iff m n
@[simp, norm_cast]
theorem coe_nat_inj' {m n : ℕ} : (↑m : ℤ) = ↑n ↔ m = n := int.coe_nat_eq_coe_nat_iff m n
@[simp] theorem coe_nat_pos {n : ℕ} : (0 : ℤ) < n ↔ 0 < n :=
by rw [← int.coe_nat_zero, coe_nat_lt]
@[simp] theorem coe_nat_eq_zero {n : ℕ} : (n : ℤ) = 0 ↔ n = 0 :=
by rw [← int.coe_nat_zero, coe_nat_inj']
theorem coe_nat_ne_zero {n : ℕ} : (n : ℤ) ≠ 0 ↔ n ≠ 0 :=
not_congr coe_nat_eq_zero
@[simp] lemma coe_nat_nonneg (n : ℕ) : 0 ≤ (n : ℤ) := coe_nat_le.2 (nat.zero_le _)
lemma coe_nat_ne_zero_iff_pos {n : ℕ} : (n : ℤ) ≠ 0 ↔ 0 < n :=
⟨λ h, nat.pos_of_ne_zero (coe_nat_ne_zero.1 h),
λ h, (ne_of_lt (coe_nat_lt.2 h)).symm⟩
lemma coe_nat_succ_pos (n : ℕ) : 0 < (n.succ : ℤ) := int.coe_nat_pos.2 (succ_pos n)
@[simp, norm_cast] theorem coe_nat_abs (n : ℕ) : abs (n : ℤ) = n :=
abs_of_nonneg (coe_nat_nonneg n)
/-! ### succ and pred -/
/-- Immediate successor of an integer: `succ n = n + 1` -/
def succ (a : ℤ) := a + 1
/-- Immediate predecessor of an integer: `pred n = n - 1` -/
def pred (a : ℤ) := a - 1
theorem nat_succ_eq_int_succ (n : ℕ) : (nat.succ n : ℤ) = int.succ n := rfl
theorem pred_succ (a : ℤ) : pred (succ a) = a := add_sub_cancel _ _
theorem succ_pred (a : ℤ) : succ (pred a) = a := sub_add_cancel _ _
theorem neg_succ (a : ℤ) : -succ a = pred (-a) := neg_add _ _
theorem succ_neg_succ (a : ℤ) : succ (-succ a) = -a :=
by rw [neg_succ, succ_pred]
theorem neg_pred (a : ℤ) : -pred a = succ (-a) :=
by rw [eq_neg_of_eq_neg (neg_succ (-a)).symm, neg_neg]
theorem pred_neg_pred (a : ℤ) : pred (-pred a) = -a :=
by rw [neg_pred, pred_succ]
theorem pred_nat_succ (n : ℕ) : pred (nat.succ n) = n := pred_succ n
theorem neg_nat_succ (n : ℕ) : -(nat.succ n : ℤ) = pred (-n) := neg_succ n
theorem succ_neg_nat_succ (n : ℕ) : succ (-nat.succ n) = -n := succ_neg_succ n
theorem lt_succ_self (a : ℤ) : a < succ a :=
lt_add_of_pos_right _ zero_lt_one
theorem pred_self_lt (a : ℤ) : pred a < a :=
sub_lt_self _ zero_lt_one
theorem add_one_le_iff {a b : ℤ} : a + 1 ≤ b ↔ a < b := iff.rfl
theorem lt_add_one_iff {a b : ℤ} : a < b + 1 ↔ a ≤ b :=
@add_le_add_iff_right _ _ a b 1
lemma le_add_one {a b : ℤ} (h : a ≤ b) : a ≤ b + 1 :=
le_of_lt (int.lt_add_one_iff.mpr h)
theorem sub_one_lt_iff {a b : ℤ} : a - 1 < b ↔ a ≤ b :=
sub_lt_iff_lt_add.trans lt_add_one_iff
theorem le_sub_one_iff {a b : ℤ} : a ≤ b - 1 ↔ a < b :=
le_sub_iff_add_le
@[elab_as_eliminator] protected lemma induction_on {p : ℤ → Prop}
(i : ℤ) (hz : p 0) (hp : ∀i : ℕ, p i → p (i + 1)) (hn : ∀i : ℕ, p (-i) → p (-i - 1)) : p i :=
begin
induction i,
{ induction i,
{ exact hz },
{ exact hp _ i_ih } },
{ have : ∀n:ℕ, p (- n),
{ intro n, induction n,
{ simp [hz] },
{ convert hn _ n_ih using 1, simp [sub_eq_neg_add] } },
exact this (i + 1) }
end
/-- Inductively define a function on `ℤ` by defining it at `b`, for the `succ` of a number greater
than `b`, and the `pred` of a number less than `b`. -/
protected def induction_on' {C : ℤ → Sort*} (z : ℤ) (b : ℤ) :
C b → (∀ k, b ≤ k → C k → C (k + 1)) → (∀ k ≤ b, C k → C (k - 1)) → C z :=
λ H0 Hs Hp,
begin
rw ←sub_add_cancel z b,
induction (z - b) with n n,
{ induction n with n ih, { rwa [of_nat_zero, zero_add] },
rw [of_nat_succ, add_assoc, add_comm 1 b, ←add_assoc],
exact Hs _ (le_add_of_nonneg_left (of_nat_nonneg _)) ih },
{ induction n with n ih,
{ rw [neg_succ_of_nat_eq, ←of_nat_eq_coe, of_nat_zero, zero_add, neg_add_eq_sub],
exact Hp _ (le_refl _) H0 },
{ rw [neg_succ_of_nat_coe', nat.succ_eq_add_one, ←neg_succ_of_nat_coe, sub_add_eq_add_sub],
exact Hp _ (le_of_lt (add_lt_of_neg_of_le (neg_succ_lt_zero _) (le_refl _))) ih } }
end
/-! ### nat abs -/
attribute [simp] nat_abs nat_abs_of_nat nat_abs_zero nat_abs_one
theorem nat_abs_add_le (a b : ℤ) : nat_abs (a + b) ≤ nat_abs a + nat_abs b :=
begin
have : ∀ (a b : ℕ), nat_abs (sub_nat_nat a (nat.succ b)) ≤ nat.succ (a + b),
{ refine (λ a b : ℕ, sub_nat_nat_elim a b.succ
(λ m n i, n = b.succ → nat_abs i ≤ (m + b).succ) _ _ rfl);
intros i n e,
{ subst e, rw [add_comm _ i, add_assoc],
exact nat.le_add_right i (b.succ + b).succ },
{ apply succ_le_succ,
rw [← succ.inj e, ← add_assoc, add_comm],
apply nat.le_add_right } },
cases a; cases b with b b; simp [nat_abs, nat.succ_add];
try {refl}; [skip, rw add_comm a b]; apply this
end
theorem nat_abs_neg_of_nat (n : ℕ) : nat_abs (neg_of_nat n) = n :=
by cases n; refl
theorem nat_abs_mul (a b : ℤ) : nat_abs (a * b) = (nat_abs a) * (nat_abs b) :=
by cases a; cases b;
simp only [← int.mul_def, int.mul, nat_abs_neg_of_nat, eq_self_iff_true, int.nat_abs]
lemma nat_abs_mul_nat_abs_eq {a b : ℤ} {c : ℕ} (h : a * b = (c : ℤ)) :
a.nat_abs * b.nat_abs = c :=
by rw [← nat_abs_mul, h, nat_abs_of_nat]
@[simp] lemma nat_abs_mul_self' (a : ℤ) : (nat_abs a * nat_abs a : ℤ) = a * a :=
by rw [← int.coe_nat_mul, nat_abs_mul_self]
theorem neg_succ_of_nat_eq' (m : ℕ) : -[1+ m] = -m - 1 :=
by simp [neg_succ_of_nat_eq, sub_eq_neg_add]
lemma nat_abs_ne_zero_of_ne_zero {z : ℤ} (hz : z ≠ 0) : z.nat_abs ≠ 0 :=
λ h, hz $ int.eq_zero_of_nat_abs_eq_zero h
@[simp] lemma nat_abs_eq_zero {a : ℤ} : a.nat_abs = 0 ↔ a = 0 :=
⟨int.eq_zero_of_nat_abs_eq_zero, λ h, h.symm ▸ rfl⟩
lemma nat_abs_lt_nat_abs_of_nonneg_of_lt {a b : ℤ} (w₁ : 0 ≤ a) (w₂ : a < b) :
a.nat_abs < b.nat_abs :=
begin
lift b to ℕ using le_trans w₁ (le_of_lt w₂),
lift a to ℕ using w₁,
simpa using w₂,
end
lemma nat_abs_eq_iff_mul_self_eq {a b : ℤ} : a.nat_abs = b.nat_abs ↔ a * a = b * b :=
begin
rw [← abs_eq_iff_mul_self_eq, abs_eq_nat_abs, abs_eq_nat_abs],
exact int.coe_nat_inj'.symm
end
lemma nat_abs_lt_iff_mul_self_lt {a b : ℤ} : a.nat_abs < b.nat_abs ↔ a * a < b * b :=
begin
rw [← abs_lt_iff_mul_self_lt, abs_eq_nat_abs, abs_eq_nat_abs],
exact int.coe_nat_lt.symm
end
lemma nat_abs_le_iff_mul_self_le {a b : ℤ} : a.nat_abs ≤ b.nat_abs ↔ a * a ≤ b * b :=
begin
rw [← abs_le_iff_mul_self_le, abs_eq_nat_abs, abs_eq_nat_abs],
exact int.coe_nat_le.symm
end
lemma nat_abs_eq_iff_sq_eq {a b : ℤ} : a.nat_abs = b.nat_abs ↔ a ^ 2 = b ^ 2 :=
by { rw [pow_two, pow_two], exact nat_abs_eq_iff_mul_self_eq }
lemma nat_abs_lt_iff_sq_lt {a b : ℤ} : a.nat_abs < b.nat_abs ↔ a ^ 2 < b ^ 2 :=
by { rw [pow_two, pow_two], exact nat_abs_lt_iff_mul_self_lt }
lemma nat_abs_le_iff_sq_le {a b : ℤ} : a.nat_abs ≤ b.nat_abs ↔ a ^ 2 ≤ b ^ 2 :=
by { rw [pow_two, pow_two], exact nat_abs_le_iff_mul_self_le }
/-! ### `/` -/
@[simp] theorem of_nat_div (m n : ℕ) : of_nat (m / n) = (of_nat m) / (of_nat n) := rfl
@[simp, norm_cast] theorem coe_nat_div (m n : ℕ) : ((m / n : ℕ) : ℤ) = m / n := rfl
theorem neg_succ_of_nat_div (m : ℕ) {b : ℤ} (H : 0 < b) :
-[1+m] / b = -(m / b + 1) :=
match b, eq_succ_of_zero_lt H with ._, ⟨n, rfl⟩ := rfl end
@[simp] protected theorem div_neg : ∀ (a b : ℤ), a / -b = -(a / b)
| (m : ℕ) 0 := show of_nat (m / 0) = -(m / 0 : ℕ), by rw nat.div_zero; refl
| (m : ℕ) (n+1:ℕ) := rfl
| 0 -[1+ n] := rfl
| (m+1:ℕ) -[1+ n] := (neg_neg _).symm
| -[1+ m] 0 := rfl
| -[1+ m] (n+1:ℕ) := rfl
| -[1+ m] -[1+ n] := rfl
theorem div_of_neg_of_pos {a b : ℤ} (Ha : a < 0) (Hb : 0 < b) : a / b = -((-a - 1) / b + 1) :=
match a, b, eq_neg_succ_of_lt_zero Ha, eq_succ_of_zero_lt Hb with
| ._, ._, ⟨m, rfl⟩, ⟨n, rfl⟩ :=
by change (- -[1+ m] : ℤ) with (m+1 : ℤ); rw add_sub_cancel; refl
end
protected theorem div_nonneg {a b : ℤ} (Ha : 0 ≤ a) (Hb : 0 ≤ b) : 0 ≤ a / b :=
match a, b, eq_coe_of_zero_le Ha, eq_coe_of_zero_le Hb with
| ._, ._, ⟨m, rfl⟩, ⟨n, rfl⟩ := coe_zero_le _
end
protected theorem div_nonpos {a b : ℤ} (Ha : 0 ≤ a) (Hb : b ≤ 0) : a / b ≤ 0 :=
nonpos_of_neg_nonneg $ by rw [← int.div_neg]; exact int.div_nonneg Ha (neg_nonneg_of_nonpos Hb)
theorem div_neg' {a b : ℤ} (Ha : a < 0) (Hb : 0 < b) : a / b < 0 :=
match a, b, eq_neg_succ_of_lt_zero Ha, eq_succ_of_zero_lt Hb with
| ._, ._, ⟨m, rfl⟩, ⟨n, rfl⟩ := neg_succ_lt_zero _
end
-- Will be generalized to Euclidean domains.
protected theorem zero_div : ∀ (b : ℤ), 0 / b = 0
| 0 := rfl
| (n+1:ℕ) := rfl
| -[1+ n] := rfl
local attribute [simp] -- Will be generalized to Euclidean domains.
protected theorem div_zero : ∀ (a : ℤ), a / 0 = 0
| 0 := rfl
| (n+1:ℕ) := rfl
| -[1+ n] := rfl
@[simp] protected theorem div_one : ∀ (a : ℤ), a / 1 = a
| 0 := rfl
| (n+1:ℕ) := congr_arg of_nat (nat.div_one _)
| -[1+ n] := congr_arg neg_succ_of_nat (nat.div_one _)
theorem div_eq_zero_of_lt {a b : ℤ} (H1 : 0 ≤ a) (H2 : a < b) : a / b = 0 :=
match a, b, eq_coe_of_zero_le H1, eq_succ_of_zero_lt (lt_of_le_of_lt H1 H2), H2 with
| ._, ._, ⟨m, rfl⟩, ⟨n, rfl⟩, H2 :=
congr_arg of_nat $ nat.div_eq_of_lt $ lt_of_coe_nat_lt_coe_nat H2
end
theorem div_eq_zero_of_lt_abs {a b : ℤ} (H1 : 0 ≤ a) (H2 : a < abs b) : a / b = 0 :=
match b, abs b, abs_eq_nat_abs b, H2 with
| (n : ℕ), ._, rfl, H2 := div_eq_zero_of_lt H1 H2
| -[1+ n], ._, rfl, H2 := neg_injective $ by rw [← int.div_neg]; exact div_eq_zero_of_lt H1 H2
end
protected theorem add_mul_div_right (a b : ℤ) {c : ℤ} (H : c ≠ 0) :
(a + b * c) / c = a / c + b :=
have ∀ {k n : ℕ} {a : ℤ}, (a + n * k.succ) / k.succ = a / k.succ + n, from
λ k n a, match a with
| (m : ℕ) := congr_arg of_nat $ nat.add_mul_div_right _ _ k.succ_pos
| -[1+ m] := show ((n * k.succ:ℕ) - m.succ : ℤ) / k.succ =
n - (m / k.succ + 1 : ℕ), begin
cases lt_or_ge m (n*k.succ) with h h,
{ rw [← int.coe_nat_sub h,
← int.coe_nat_sub ((nat.div_lt_iff_lt_mul _ _ k.succ_pos).2 h)],
apply congr_arg of_nat,
rw [mul_comm, nat.mul_sub_div], rwa mul_comm },
{ change (↑(n * nat.succ k) - (m + 1) : ℤ) / ↑(nat.succ k) =
↑n - ((m / nat.succ k : ℕ) + 1),
rw [← sub_sub, ← sub_sub, ← neg_sub (m:ℤ), ← neg_sub _ (n:ℤ),
← int.coe_nat_sub h,
← int.coe_nat_sub ((nat.le_div_iff_mul_le _ _ k.succ_pos).2 h),
← neg_succ_of_nat_coe', ← neg_succ_of_nat_coe'],
{ apply congr_arg neg_succ_of_nat,
rw [mul_comm, nat.sub_mul_div], rwa mul_comm } }
end
end,
have ∀ {a b c : ℤ}, 0 < c → (a + b * c) / c = a / c + b, from
λ a b c H, match c, eq_succ_of_zero_lt H, b with
| ._, ⟨k, rfl⟩, (n : ℕ) := this
| ._, ⟨k, rfl⟩, -[1+ n] :=
show (a - n.succ * k.succ) / k.succ = (a / k.succ) - n.succ, from
eq_sub_of_add_eq $ by rw [← this, sub_add_cancel]
end,
match lt_trichotomy c 0 with
| or.inl hlt := neg_inj.1 $ by rw [← int.div_neg, neg_add, ← int.div_neg, ← neg_mul_neg];
apply this (neg_pos_of_neg hlt)
| or.inr (or.inl heq) := absurd heq H
| or.inr (or.inr hgt) := this hgt
end
protected theorem add_mul_div_left (a : ℤ) {b : ℤ} (c : ℤ) (H : b ≠ 0) :
(a + b * c) / b = a / b + c :=
by rw [mul_comm, int.add_mul_div_right _ _ H]
protected theorem add_div_of_dvd_right {a b c : ℤ} (H : c ∣ b) :
(a + b) / c = a / c + b / c :=
begin
by_cases h1 : c = 0,
{ simp [h1] },
cases H with k hk,
rw hk,
change c ≠ 0 at h1,
rw [mul_comm c k, int.add_mul_div_right _ _ h1, ←zero_add (k * c), int.add_mul_div_right _ _ h1,
int.zero_div, zero_add]
end
protected theorem add_div_of_dvd_left {a b c : ℤ} (H : c ∣ a) :
(a + b) / c = a / c + b / c :=
by rw [add_comm, int.add_div_of_dvd_right H, add_comm]
@[simp] protected theorem mul_div_cancel (a : ℤ) {b : ℤ} (H : b ≠ 0) : a * b / b = a :=
by have := int.add_mul_div_right 0 a H;
rwa [zero_add, int.zero_div, zero_add] at this
@[simp] protected theorem mul_div_cancel_left {a : ℤ} (b : ℤ) (H : a ≠ 0) : a * b / a = b :=
by rw [mul_comm, int.mul_div_cancel _ H]
@[simp] protected theorem div_self {a : ℤ} (H : a ≠ 0) : a / a = 1 :=
by have := int.mul_div_cancel 1 H; rwa one_mul at this
/-! ### mod -/
theorem of_nat_mod (m n : nat) : (m % n : ℤ) = of_nat (m % n) := rfl
@[simp, norm_cast] theorem coe_nat_mod (m n : ℕ) : (↑(m % n) : ℤ) = ↑m % ↑n := rfl
theorem neg_succ_of_nat_mod (m : ℕ) {b : ℤ} (bpos : 0 < b) :
-[1+m] % b = b - 1 - m % b :=
by rw [sub_sub, add_comm]; exact
match b, eq_succ_of_zero_lt bpos with ._, ⟨n, rfl⟩ := rfl end
@[simp] theorem mod_neg : ∀ (a b : ℤ), a % -b = a % b
| (m : ℕ) n := @congr_arg ℕ ℤ _ _ (λ i, ↑(m % i)) (nat_abs_neg _)
| -[1+ m] n := @congr_arg ℕ ℤ _ _ (λ i, sub_nat_nat i (nat.succ (m % i))) (nat_abs_neg _)
@[simp] theorem mod_abs (a b : ℤ) : a % (abs b) = a % b :=
abs_by_cases (λ i, a % i = a % b) rfl (mod_neg _ _)
local attribute [simp] -- Will be generalized to Euclidean domains.
theorem zero_mod (b : ℤ) : 0 % b = 0 :=
congr_arg of_nat $ nat.zero_mod _
local attribute [simp] -- Will be generalized to Euclidean domains.
theorem mod_zero : ∀ (a : ℤ), a % 0 = a
| (m : ℕ) := congr_arg of_nat $ nat.mod_zero _
| -[1+ m] := congr_arg neg_succ_of_nat $ nat.mod_zero _
local attribute [simp] -- Will be generalized to Euclidean domains.
theorem mod_one : ∀ (a : ℤ), a % 1 = 0
| (m : ℕ) := congr_arg of_nat $ nat.mod_one _
| -[1+ m] := show (1 - (m % 1).succ : ℤ) = 0, by rw nat.mod_one; refl
theorem mod_eq_of_lt {a b : ℤ} (H1 : 0 ≤ a) (H2 : a < b) : a % b = a :=
match a, b, eq_coe_of_zero_le H1, eq_coe_of_zero_le (le_trans H1 (le_of_lt H2)), H2 with
| ._, ._, ⟨m, rfl⟩, ⟨n, rfl⟩, H2 :=
congr_arg of_nat $ nat.mod_eq_of_lt (lt_of_coe_nat_lt_coe_nat H2)
end
theorem mod_nonneg : ∀ (a : ℤ) {b : ℤ}, b ≠ 0 → 0 ≤ a % b
| (m : ℕ) n H := coe_zero_le _
| -[1+ m] n H :=
sub_nonneg_of_le $ coe_nat_le_coe_nat_of_le $ nat.mod_lt _ (nat_abs_pos_of_ne_zero H)
theorem mod_lt_of_pos (a : ℤ) {b : ℤ} (H : 0 < b) : a % b < b :=
match a, b, eq_succ_of_zero_lt H with
| (m : ℕ), ._, ⟨n, rfl⟩ := coe_nat_lt_coe_nat_of_lt (nat.mod_lt _ (nat.succ_pos _))
| -[1+ m], ._, ⟨n, rfl⟩ := sub_lt_self _ (coe_nat_lt_coe_nat_of_lt $ nat.succ_pos _)
end
theorem mod_lt (a : ℤ) {b : ℤ} (H : b ≠ 0) : a % b < abs b :=
by rw [← mod_abs]; exact mod_lt_of_pos _ (abs_pos.2 H)
theorem mod_add_div_aux (m n : ℕ) : (n - (m % n + 1) - (n * (m / n) + n) : ℤ) = -[1+ m] :=
begin
rw [← sub_sub, neg_succ_of_nat_coe, sub_sub (n:ℤ)],
apply eq_neg_of_eq_neg,
rw [neg_sub, sub_sub_self, add_right_comm],
exact @congr_arg ℕ ℤ _ _ (λi, (i + 1 : ℤ)) (nat.mod_add_div _ _).symm
end
theorem mod_add_div : ∀ (a b : ℤ), a % b + b * (a / b) = a
| (m : ℕ) 0 := congr_arg of_nat (nat.mod_add_div _ _)
| (m : ℕ) (n+1:ℕ) := congr_arg of_nat (nat.mod_add_div _ _)
| 0 -[1+ n] := rfl
| (m+1:ℕ) -[1+ n] := show (_ + -(n+1) * -((m + 1) / (n + 1) : ℕ) : ℤ) = _,
by rw [neg_mul_neg]; exact congr_arg of_nat (nat.mod_add_div _ _)
| -[1+ m] 0 := by rw [mod_zero, int.div_zero]; refl
| -[1+ m] (n+1:ℕ) := mod_add_div_aux m n.succ
| -[1+ m] -[1+ n] := mod_add_div_aux m n.succ
theorem mod_def (a b : ℤ) : a % b = a - b * (a / b) :=
eq_sub_of_add_eq (mod_add_div _ _)
@[simp] theorem add_mul_mod_self {a b c : ℤ} : (a + b * c) % c = a % c :=
if cz : c = 0 then by rw [cz, mul_zero, add_zero] else
by rw [mod_def, mod_def, int.add_mul_div_right _ _ cz,
mul_add, mul_comm, add_sub_add_right_eq_sub]
@[simp] theorem add_mul_mod_self_left (a b c : ℤ) : (a + b * c) % b = a % b :=
by rw [mul_comm, add_mul_mod_self]
@[simp] theorem add_mod_self {a b : ℤ} : (a + b) % b = a % b :=
by have := add_mul_mod_self_left a b 1; rwa mul_one at this
@[simp] theorem add_mod_self_left {a b : ℤ} : (a + b) % a = b % a :=
by rw [add_comm, add_mod_self]
@[simp] theorem mod_add_mod (m n k : ℤ) : (m % n + k) % n = (m + k) % n :=
by have := (add_mul_mod_self_left (m % n + k) n (m / n)).symm;
rwa [add_right_comm, mod_add_div] at this
@[simp] theorem add_mod_mod (m n k : ℤ) : (m + n % k) % k = (m + n) % k :=
by rw [add_comm, mod_add_mod, add_comm]
lemma add_mod (a b n : ℤ) : (a + b) % n = ((a % n) + (b % n)) % n :=
by rw [add_mod_mod, mod_add_mod]
theorem add_mod_eq_add_mod_right {m n k : ℤ} (i : ℤ) (H : m % n = k % n) :
(m + i) % n = (k + i) % n :=
by rw [← mod_add_mod, ← mod_add_mod k, H]
theorem add_mod_eq_add_mod_left {m n k : ℤ} (i : ℤ) (H : m % n = k % n) :
(i + m) % n = (i + k) % n :=
by rw [add_comm, add_mod_eq_add_mod_right _ H, add_comm]
theorem mod_add_cancel_right {m n k : ℤ} (i) : (m + i) % n = (k + i) % n ↔
m % n = k % n :=
⟨λ H, by have := add_mod_eq_add_mod_right (-i) H;
rwa [add_neg_cancel_right, add_neg_cancel_right] at this,
add_mod_eq_add_mod_right _⟩
theorem mod_add_cancel_left {m n k i : ℤ} :
(i + m) % n = (i + k) % n ↔ m % n = k % n :=
by rw [add_comm, add_comm i, mod_add_cancel_right]
theorem mod_sub_cancel_right {m n k : ℤ} (i) : (m - i) % n = (k - i) % n ↔
m % n = k % n :=
mod_add_cancel_right _
theorem mod_eq_mod_iff_mod_sub_eq_zero {m n k : ℤ} : m % n = k % n ↔ (m - k) % n = 0 :=
(mod_sub_cancel_right k).symm.trans $ by simp
@[simp] theorem mul_mod_left (a b : ℤ) : (a * b) % b = 0 :=
by rw [← zero_add (a * b), add_mul_mod_self, zero_mod]
@[simp] theorem mul_mod_right (a b : ℤ) : (a * b) % a = 0 :=
by rw [mul_comm, mul_mod_left]
lemma mul_mod (a b n : ℤ) : (a * b) % n = ((a % n) * (b % n)) % n :=
begin
conv_lhs {
rw [←mod_add_div a n, ←mod_add_div b n, right_distrib, left_distrib, left_distrib,
mul_assoc, mul_assoc, ←left_distrib n _ _, add_mul_mod_self_left,
mul_comm _ (n * (b / n)), mul_assoc, add_mul_mod_self_left] }
end
@[simp] lemma neg_mod_two (i : ℤ) : (-i) % 2 = i % 2 :=
begin
apply int.mod_eq_mod_iff_mod_sub_eq_zero.mpr,
convert int.mul_mod_right 2 (-i),
simp only [two_mul, sub_eq_add_neg]
end
local attribute [simp] -- Will be generalized to Euclidean domains.
theorem mod_self {a : ℤ} : a % a = 0 :=
by have := mul_mod_left 1 a; rwa one_mul at this
@[simp] theorem mod_mod_of_dvd (n : int) {m k : int} (h : m ∣ k) : n % k % m = n % m :=
begin
conv { to_rhs, rw ←mod_add_div n k },
rcases h with ⟨t, rfl⟩, rw [mul_assoc, add_mul_mod_self_left]
end
@[simp] theorem mod_mod (a b : ℤ) : a % b % b = a % b :=
by conv {to_rhs, rw [← mod_add_div a b, add_mul_mod_self_left]}
lemma sub_mod (a b n : ℤ) : (a - b) % n = ((a % n) - (b % n)) % n :=
begin
apply (mod_add_cancel_right b).mp,
rw [sub_add_cancel, ← add_mod_mod, sub_add_cancel, mod_mod]
end
/-! ### properties of `/` and `%` -/
@[simp] theorem mul_div_mul_of_pos {a : ℤ} (b c : ℤ) (H : 0 < a) : a * b / (a * c) = b / c :=
suffices ∀ (m k : ℕ) (b : ℤ), (m.succ * b / (m.succ * k) : ℤ) = b / k, from
match a, eq_succ_of_zero_lt H, c, eq_coe_or_neg c with
| ._, ⟨m, rfl⟩, ._, ⟨k, or.inl rfl⟩ := this _ _ _
| ._, ⟨m, rfl⟩, ._, ⟨k, or.inr rfl⟩ :=
by rw [← neg_mul_eq_mul_neg, int.div_neg, int.div_neg];
apply congr_arg has_neg.neg; apply this
end,
λ m k b, match b, k with
| (n : ℕ), k := congr_arg of_nat (nat.mul_div_mul _ _ m.succ_pos)
| -[1+ n], 0 := by rw [int.coe_nat_zero, mul_zero, int.div_zero, int.div_zero]
| -[1+ n], k+1 := congr_arg neg_succ_of_nat $
show (m.succ * n + m) / (m.succ * k.succ) = n / k.succ, begin
apply nat.div_eq_of_lt_le,
{ refine le_trans _ (nat.le_add_right _ _),
rw [← nat.mul_div_mul _ _ m.succ_pos],
apply nat.div_mul_le_self },
{ change m.succ * n.succ ≤ _,
rw [mul_left_comm],
apply nat.mul_le_mul_left,
apply (nat.div_lt_iff_lt_mul _ _ k.succ_pos).1,
apply nat.lt_succ_self }
end
end
@[simp] theorem mul_div_mul_of_pos_left (a : ℤ) {b : ℤ} (c : ℤ) (H : 0 < b) :
a * b / (c * b) = a / c :=
by rw [mul_comm, mul_comm c, mul_div_mul_of_pos _ _ H]
@[simp] theorem mul_mod_mul_of_pos {a : ℤ} (b c : ℤ) (H : 0 < a) : a * b % (a * c) = a * (b % c) :=
by rw [mod_def, mod_def, mul_div_mul_of_pos _ _ H, mul_sub_left_distrib, mul_assoc]
theorem lt_div_add_one_mul_self (a : ℤ) {b : ℤ} (H : 0 < b) : a < (a / b + 1) * b :=
by { rw [add_mul, one_mul, mul_comm, ← sub_lt_iff_lt_add', ← mod_def],
exact mod_lt_of_pos _ H }
theorem abs_div_le_abs : ∀ (a b : ℤ), abs (a / b) ≤ abs a :=
suffices ∀ (a : ℤ) (n : ℕ), abs (a / n) ≤ abs a, from
λ a b, match b, eq_coe_or_neg b with
| ._, ⟨n, or.inl rfl⟩ := this _ _
| ._, ⟨n, or.inr rfl⟩ := by rw [int.div_neg, abs_neg]; apply this
end,
λ a n, by rw [abs_eq_nat_abs, abs_eq_nat_abs]; exact
coe_nat_le_coe_nat_of_le (match a, n with
| (m : ℕ), n := nat.div_le_self _ _
| -[1+ m], 0 := nat.zero_le _
| -[1+ m], n+1 := nat.succ_le_succ (nat.div_le_self _ _)
end)
theorem div_le_self {a : ℤ} (b : ℤ) (Ha : 0 ≤ a) : a / b ≤ a :=
by have := le_trans (le_abs_self _) (abs_div_le_abs a b);
rwa [abs_of_nonneg Ha] at this
theorem mul_div_cancel_of_mod_eq_zero {a b : ℤ} (H : a % b = 0) : b * (a / b) = a :=
by have := mod_add_div a b; rwa [H, zero_add] at this
theorem div_mul_cancel_of_mod_eq_zero {a b : ℤ} (H : a % b = 0) : a / b * b = a :=
by rw [mul_comm, mul_div_cancel_of_mod_eq_zero H]
lemma mod_two_eq_zero_or_one (n : ℤ) : n % 2 = 0 ∨ n % 2 = 1 :=
have h : n % 2 < 2 := abs_of_nonneg (show 0 ≤ (2 : ℤ), from dec_trivial) ▸ int.mod_lt _ dec_trivial,
have h₁ : 0 ≤ n % 2 := int.mod_nonneg _ dec_trivial,
match (n % 2), h, h₁ with
| (0 : ℕ) := λ _ _, or.inl rfl
| (1 : ℕ) := λ _ _, or.inr rfl
| (k + 2 : ℕ) := λ h _, absurd h dec_trivial
| -[1+ a] := λ _ h₁, absurd h₁ dec_trivial
end
/-! ### dvd -/
@[norm_cast] theorem coe_nat_dvd {m n : ℕ} : (↑m : ℤ) ∣ ↑n ↔ m ∣ n :=
⟨λ ⟨a, ae⟩, m.eq_zero_or_pos.elim
(λm0, by simp [m0] at ae; simp [ae, m0])
(λm0l, by {
cases eq_coe_of_zero_le (@nonneg_of_mul_nonneg_left ℤ _ m a
(by simp [ae.symm]) (by simpa using m0l)) with k e,
subst a, exact ⟨k, int.coe_nat_inj ae⟩ }),
λ ⟨k, e⟩, dvd.intro k $ by rw [e, int.coe_nat_mul]⟩
theorem coe_nat_dvd_left {n : ℕ} {z : ℤ} : (↑n : ℤ) ∣ z ↔ n ∣ z.nat_abs :=
by rcases nat_abs_eq z with eq | eq; rw eq; simp [coe_nat_dvd]
theorem coe_nat_dvd_right {n : ℕ} {z : ℤ} : z ∣ (↑n : ℤ) ↔ z.nat_abs ∣ n :=
by rcases nat_abs_eq z with eq | eq; rw eq; simp [coe_nat_dvd]
theorem dvd_antisymm {a b : ℤ} (H1 : 0 ≤ a) (H2 : 0 ≤ b) : a ∣ b → b ∣ a → a = b :=
begin
rw [← abs_of_nonneg H1, ← abs_of_nonneg H2, abs_eq_nat_abs, abs_eq_nat_abs],
rw [coe_nat_dvd, coe_nat_dvd, coe_nat_inj'],
apply nat.dvd_antisymm
end
theorem dvd_of_mod_eq_zero {a b : ℤ} (H : b % a = 0) : a ∣ b :=
⟨b / a, (mul_div_cancel_of_mod_eq_zero H).symm⟩
theorem mod_eq_zero_of_dvd : ∀ {a b : ℤ}, a ∣ b → b % a = 0
| a ._ ⟨c, rfl⟩ := mul_mod_right _ _
theorem dvd_iff_mod_eq_zero (a b : ℤ) : a ∣ b ↔ b % a = 0 :=
⟨mod_eq_zero_of_dvd, dvd_of_mod_eq_zero⟩
/-- If `a % b = c` then `b` divides `a - c`. -/
lemma dvd_sub_of_mod_eq {a b c : ℤ} (h : a % b = c) : b ∣ a - c :=
begin
have hx : a % b % b = c % b, { rw h },
rw [mod_mod, ←mod_sub_cancel_right c, sub_self, zero_mod] at hx,
exact dvd_of_mod_eq_zero hx
end
theorem nat_abs_dvd {a b : ℤ} : (a.nat_abs : ℤ) ∣ b ↔ a ∣ b :=
(nat_abs_eq a).elim (λ e, by rw ← e) (λ e, by rw [← neg_dvd_iff_dvd, ← e])
theorem dvd_nat_abs {a b : ℤ} : a ∣ b.nat_abs ↔ a ∣ b :=
(nat_abs_eq b).elim (λ e, by rw ← e) (λ e, by rw [← dvd_neg_iff_dvd, ← e])
instance decidable_dvd : @decidable_rel ℤ (∣) :=
assume a n, decidable_of_decidable_of_iff (by apply_instance) (dvd_iff_mod_eq_zero _ _).symm
protected theorem div_mul_cancel {a b : ℤ} (H : b ∣ a) : a / b * b = a :=
div_mul_cancel_of_mod_eq_zero (mod_eq_zero_of_dvd H)
protected theorem mul_div_cancel' {a b : ℤ} (H : a ∣ b) : a * (b / a) = b :=
by rw [mul_comm, int.div_mul_cancel H]
protected theorem mul_div_assoc (a : ℤ) : ∀ {b c : ℤ}, c ∣ b → (a * b) / c = a * (b / c)
| ._ c ⟨d, rfl⟩ := if cz : c = 0 then by simp [cz] else
by rw [mul_left_comm, int.mul_div_cancel_left _ cz, int.mul_div_cancel_left _ cz]
theorem div_dvd_div : ∀ {a b c : ℤ} (H1 : a ∣ b) (H2 : b ∣ c), b / a ∣ c / a
| a ._ ._ ⟨b, rfl⟩ ⟨c, rfl⟩ := if az : a = 0 then by simp [az] else
by rw [int.mul_div_cancel_left _ az, mul_assoc, int.mul_div_cancel_left _ az];
apply dvd_mul_right
protected theorem eq_mul_of_div_eq_right {a b c : ℤ} (H1 : b ∣ a) (H2 : a / b = c) :
a = b * c :=
by rw [← H2, int.mul_div_cancel' H1]
protected theorem div_eq_of_eq_mul_right {a b c : ℤ} (H1 : b ≠ 0) (H2 : a = b * c) :
a / b = c :=
by rw [H2, int.mul_div_cancel_left _ H1]
protected theorem eq_div_of_mul_eq_right {a b c : ℤ} (H1 : a ≠ 0) (H2 : a * b = c) :
b = c / a :=
eq.symm $ int.div_eq_of_eq_mul_right H1 H2.symm
protected theorem div_eq_iff_eq_mul_right {a b c : ℤ} (H : b ≠ 0) (H' : b ∣ a) :
a / b = c ↔ a = b * c :=
⟨int.eq_mul_of_div_eq_right H', int.div_eq_of_eq_mul_right H⟩
protected theorem div_eq_iff_eq_mul_left {a b c : ℤ} (H : b ≠ 0) (H' : b ∣ a) :
a / b = c ↔ a = c * b :=
by rw mul_comm; exact int.div_eq_iff_eq_mul_right H H'
protected theorem eq_mul_of_div_eq_left {a b c : ℤ} (H1 : b ∣ a) (H2 : a / b = c) :
a = c * b :=
by rw [mul_comm, int.eq_mul_of_div_eq_right H1 H2]
protected theorem div_eq_of_eq_mul_left {a b c : ℤ} (H1 : b ≠ 0) (H2 : a = c * b) :
a / b = c :=
int.div_eq_of_eq_mul_right H1 (by rw [mul_comm, H2])
theorem neg_div_of_dvd : ∀ {a b : ℤ} (H : b ∣ a), -a / b = -(a / b)
| ._ b ⟨c, rfl⟩ := if bz : b = 0 then by simp [bz] else
by rw [neg_mul_eq_mul_neg, int.mul_div_cancel_left _ bz, int.mul_div_cancel_left _ bz]
theorem div_sign : ∀ a b, a / sign b = a * sign b
| a (n+1:ℕ) := by unfold sign; simp
| a 0 := by simp [sign]
| a -[1+ n] := by simp [sign]
@[simp] theorem sign_mul : ∀ a b, sign (a * b) = sign a * sign b
| a 0 := by simp
| 0 b := by simp
| (m+1:ℕ) (n+1:ℕ) := rfl
| (m+1:ℕ) -[1+ n] := rfl
| -[1+ m] (n+1:ℕ) := rfl
| -[1+ m] -[1+ n] := rfl
protected theorem sign_eq_div_abs (a : ℤ) : sign a = a / (abs a) :=
if az : a = 0 then by simp [az] else
(int.div_eq_of_eq_mul_left (mt abs_eq_zero.1 az)
(sign_mul_abs _).symm).symm
theorem mul_sign : ∀ (i : ℤ), i * sign i = nat_abs i
| (n+1:ℕ) := mul_one _
| 0 := mul_zero _
| -[1+ n] := mul_neg_one _
theorem le_of_dvd {a b : ℤ} (bpos : 0 < b) (H : a ∣ b) : a ≤ b :=
match a, b, eq_succ_of_zero_lt bpos, H with
| (m : ℕ), ._, ⟨n, rfl⟩, H := coe_nat_le_coe_nat_of_le $
nat.le_of_dvd n.succ_pos $ coe_nat_dvd.1 H
| -[1+ m], ._, ⟨n, rfl⟩, _ :=
le_trans (le_of_lt $ neg_succ_lt_zero _) (coe_zero_le _)
end
theorem eq_one_of_dvd_one {a : ℤ} (H : 0 ≤ a) (H' : a ∣ 1) : a = 1 :=
match a, eq_coe_of_zero_le H, H' with
| ._, ⟨n, rfl⟩, H' := congr_arg coe $
nat.eq_one_of_dvd_one $ coe_nat_dvd.1 H'
end
theorem eq_one_of_mul_eq_one_right {a b : ℤ} (H : 0 ≤ a) (H' : a * b = 1) : a = 1 :=
eq_one_of_dvd_one H ⟨b, H'.symm⟩
theorem eq_one_of_mul_eq_one_left {a b : ℤ} (H : 0 ≤ b) (H' : a * b = 1) : b = 1 :=
eq_one_of_mul_eq_one_right H (by rw [mul_comm, H'])
lemma of_nat_dvd_of_dvd_nat_abs {a : ℕ} : ∀ {z : ℤ} (haz : a ∣ z.nat_abs), ↑a ∣ z
| (int.of_nat _) haz := int.coe_nat_dvd.2 haz
| -[1+k] haz :=
begin
change ↑a ∣ -(k+1 : ℤ),
apply dvd_neg_of_dvd,
apply int.coe_nat_dvd.2,
exact haz
end
lemma dvd_nat_abs_of_of_nat_dvd {a : ℕ} : ∀ {z : ℤ} (haz : ↑a ∣ z), a ∣ z.nat_abs
| (int.of_nat _) haz := int.coe_nat_dvd.1 (int.dvd_nat_abs.2 haz)
| -[1+k] haz :=
have haz' : (↑a:ℤ) ∣ (↑(k+1):ℤ), from dvd_of_dvd_neg haz,
int.coe_nat_dvd.1 haz'
lemma pow_dvd_of_le_of_pow_dvd {p m n : ℕ} {k : ℤ} (hmn : m ≤ n) (hdiv : ↑(p ^ n) ∣ k) :
↑(p ^ m) ∣ k :=
begin
induction k,
{ apply int.coe_nat_dvd.2,
apply pow_dvd_of_le_of_pow_dvd hmn,
apply int.coe_nat_dvd.1 hdiv },
{ change -[1+k] with -(↑(k+1) : ℤ),
apply dvd_neg_of_dvd,
apply int.coe_nat_dvd.2,
apply pow_dvd_of_le_of_pow_dvd hmn,
apply int.coe_nat_dvd.1,
apply dvd_of_dvd_neg,
exact hdiv }
end
lemma dvd_of_pow_dvd {p k : ℕ} {m : ℤ} (hk : 1 ≤ k) (hpk : ↑(p^k) ∣ m) : ↑p ∣ m :=
by rw ←pow_one p; exact pow_dvd_of_le_of_pow_dvd hk hpk
/-- If `n > 0` then `m` is not divisible by `n` iff it is between `n * k` and `n * (k + 1)`
for some `k`. -/
lemma exists_lt_and_lt_iff_not_dvd (m : ℤ) {n : ℤ} (hn : 0 < n) :
(∃ k, n * k < m ∧ m < n * (k + 1)) ↔ ¬ n ∣ m :=
begin
split,
{ rintro ⟨k, h1k, h2k⟩ ⟨l, rfl⟩, rw [mul_lt_mul_left hn] at h1k h2k,
rw [lt_add_one_iff, ← not_lt] at h2k, exact h2k h1k },
{ intro h, rw [dvd_iff_mod_eq_zero, ← ne.def] at h,
have := (mod_nonneg m hn.ne.symm).lt_of_ne h.symm,
simp only [← mod_add_div m n] {single_pass := tt},
refine ⟨m / n, lt_add_of_pos_left _ this, _⟩,
rw [add_comm _ (1 : ℤ), left_distrib, mul_one], exact add_lt_add_right (mod_lt_of_pos _ hn) _ }
end
/-! ### `/` and ordering -/
protected theorem div_mul_le (a : ℤ) {b : ℤ} (H : b ≠ 0) : a / b * b ≤ a :=
le_of_sub_nonneg $ by rw [mul_comm, ← mod_def]; apply mod_nonneg _ H
protected theorem div_le_of_le_mul {a b c : ℤ} (H : 0 < c) (H' : a ≤ b * c) : a / c ≤ b :=
le_of_mul_le_mul_right (le_trans (int.div_mul_le _ (ne_of_gt H)) H') H
protected theorem mul_lt_of_lt_div {a b c : ℤ} (H : 0 < c) (H3 : a < b / c) : a * c < b :=
lt_of_not_ge $ mt (int.div_le_of_le_mul H) (not_le_of_gt H3)
protected theorem mul_le_of_le_div {a b c : ℤ} (H1 : 0 < c) (H2 : a ≤ b / c) : a * c ≤ b :=
le_trans (mul_le_mul_of_nonneg_right H2 (le_of_lt H1)) (int.div_mul_le _ (ne_of_gt H1))
protected theorem le_div_of_mul_le {a b c : ℤ} (H1 : 0 < c) (H2 : a * c ≤ b) : a ≤ b / c :=
le_of_lt_add_one $ lt_of_mul_lt_mul_right
(lt_of_le_of_lt H2 (lt_div_add_one_mul_self _ H1)) (le_of_lt H1)
protected theorem le_div_iff_mul_le {a b c : ℤ} (H : 0 < c) : a ≤ b / c ↔ a * c ≤ b :=
⟨int.mul_le_of_le_div H, int.le_div_of_mul_le H⟩
protected theorem div_le_div {a b c : ℤ} (H : 0 < c) (H' : a ≤ b) : a / c ≤ b / c :=
int.le_div_of_mul_le H (le_trans (int.div_mul_le _ (ne_of_gt H)) H')
protected theorem div_lt_of_lt_mul {a b c : ℤ} (H : 0 < c) (H' : a < b * c) : a / c < b :=
lt_of_not_ge $ mt (int.mul_le_of_le_div H) (not_le_of_gt H')
protected theorem lt_mul_of_div_lt {a b c : ℤ} (H1 : 0 < c) (H2 : a / c < b) : a < b * c :=
lt_of_not_ge $ mt (int.le_div_of_mul_le H1) (not_le_of_gt H2)
protected theorem div_lt_iff_lt_mul {a b c : ℤ} (H : 0 < c) : a / c < b ↔ a < b * c :=
⟨int.lt_mul_of_div_lt H, int.div_lt_of_lt_mul H⟩
protected theorem le_mul_of_div_le {a b c : ℤ} (H1 : 0 ≤ b) (H2 : b ∣ a) (H3 : a / b ≤ c) :
a ≤ c * b :=
by rw [← int.div_mul_cancel H2]; exact mul_le_mul_of_nonneg_right H3 H1
protected theorem lt_div_of_mul_lt {a b c : ℤ} (H1 : 0 ≤ b) (H2 : b ∣ c) (H3 : a * b < c) :
a < c / b :=
lt_of_not_ge $ mt (int.le_mul_of_div_le H1 H2) (not_le_of_gt H3)
protected theorem lt_div_iff_mul_lt {a b : ℤ} (c : ℤ) (H : 0 < c) (H' : c ∣ b) :
a < b / c ↔ a * c < b :=
⟨int.mul_lt_of_lt_div H, int.lt_div_of_mul_lt (le_of_lt H) H'⟩
theorem div_pos_of_pos_of_dvd {a b : ℤ} (H1 : 0 < a) (H2 : 0 ≤ b) (H3 : b ∣ a) : 0 < a / b :=
int.lt_div_of_mul_lt H2 H3 (by rwa zero_mul)
theorem div_eq_div_of_mul_eq_mul {a b c d : ℤ} (H2 : d ∣ c) (H3 : b ≠ 0)
(H4 : d ≠ 0) (H5 : a * d = b * c) :
a / b = c / d :=
int.div_eq_of_eq_mul_right H3 $
by rw [← int.mul_div_assoc _ H2]; exact
(int.div_eq_of_eq_mul_left H4 H5.symm).symm
theorem eq_mul_div_of_mul_eq_mul_of_dvd_left {a b c d : ℤ} (hb : b ≠ 0) (hbc : b ∣ c)
(h : b * a = c * d) : a = c / b * d :=
begin
cases hbc with k hk,
subst hk,
rw [int.mul_div_cancel_left _ hb],
rw mul_assoc at h,
apply mul_left_cancel' hb h
end
/-- If an integer with larger absolute value divides an integer, it is
zero. -/
lemma eq_zero_of_dvd_of_nat_abs_lt_nat_abs {a b : ℤ} (w : a ∣ b) (h : nat_abs b < nat_abs a) :
b = 0 :=
begin
rw [←nat_abs_dvd, ←dvd_nat_abs, coe_nat_dvd] at w,
rw ←nat_abs_eq_zero,
exact eq_zero_of_dvd_of_lt w h
end
lemma eq_zero_of_dvd_of_nonneg_of_lt {a b : ℤ} (w₁ : 0 ≤ a) (w₂ : a < b) (h : b ∣ a) : a = 0 :=
eq_zero_of_dvd_of_nat_abs_lt_nat_abs h (nat_abs_lt_nat_abs_of_nonneg_of_lt w₁ w₂)
/-- If two integers are congruent to a sufficiently large modulus,
they are equal. -/
lemma eq_of_mod_eq_of_nat_abs_sub_lt_nat_abs {a b c : ℤ} (h1 : a % b = c)
(h2 : nat_abs (a - c) < nat_abs b) :
a = c :=
eq_of_sub_eq_zero (eq_zero_of_dvd_of_nat_abs_lt_nat_abs (dvd_sub_of_mod_eq h1) h2)
theorem of_nat_add_neg_succ_of_nat_of_lt {m n : ℕ}
(h : m < n.succ) : of_nat m + -[1+n] = -[1+ n - m] :=
begin
change sub_nat_nat _ _ = _,
have h' : n.succ - m = (n - m).succ,
apply succ_sub,
apply le_of_lt_succ h,
simp [*, sub_nat_nat]
end
theorem of_nat_add_neg_succ_of_nat_of_ge {m n : ℕ}
(h : n.succ ≤ m) : of_nat m + -[1+n] = of_nat (m - n.succ) :=
begin
change sub_nat_nat _ _ = _,
have h' : n.succ - m = 0,
apply sub_eq_zero_of_le h,
simp [*, sub_nat_nat]
end
@[simp] theorem neg_add_neg (m n : ℕ) : -[1+m] + -[1+n] = -[1+nat.succ(m+n)] := rfl
/-! ### to_nat -/
theorem to_nat_eq_max : ∀ (a : ℤ), (to_nat a : ℤ) = max a 0
| (n : ℕ) := (max_eq_left (coe_zero_le n)).symm
| -[1+ n] := (max_eq_right (le_of_lt (neg_succ_lt_zero n))).symm
@[simp] lemma to_nat_zero : (0 : ℤ).to_nat = 0 := rfl
@[simp] lemma to_nat_one : (1 : ℤ).to_nat = 1 := rfl
@[simp] theorem to_nat_of_nonneg {a : ℤ} (h : 0 ≤ a) : (to_nat a : ℤ) = a :=
by rw [to_nat_eq_max, max_eq_left h]
@[simp] lemma to_nat_sub_of_le (a b : ℤ) (h : b ≤ a) : (to_nat (a + -b) : ℤ) = a + - b :=
int.to_nat_of_nonneg (sub_nonneg_of_le h)
@[simp] theorem to_nat_coe_nat (n : ℕ) : to_nat ↑n = n := rfl
@[simp] lemma to_nat_coe_nat_add_one {n : ℕ} : ((n : ℤ) + 1).to_nat = n + 1 := rfl
theorem le_to_nat (a : ℤ) : a ≤ to_nat a :=
by rw [to_nat_eq_max]; apply le_max_left
@[simp] theorem to_nat_le {a : ℤ} {n : ℕ} : to_nat a ≤ n ↔ a ≤ n :=
by rw [(coe_nat_le_coe_nat_iff _ _).symm, to_nat_eq_max, max_le_iff];
exact and_iff_left (coe_zero_le _)
@[simp] theorem lt_to_nat {n : ℕ} {a : ℤ} : n < to_nat a ↔ (n : ℤ) < a :=
le_iff_le_iff_lt_iff_lt.1 to_nat_le
theorem to_nat_le_to_nat {a b : ℤ} (h : a ≤ b) : to_nat a ≤ to_nat b :=
by rw to_nat_le; exact le_trans h (le_to_nat b)
theorem to_nat_lt_to_nat {a b : ℤ} (hb : 0 < b) : to_nat a < to_nat b ↔ a < b :=
⟨λ h, begin cases a, exact lt_to_nat.1 h, exact lt_trans (neg_succ_of_nat_lt_zero a) hb, end,
λ h, begin rw lt_to_nat, cases a, exact h, exact hb end⟩
theorem lt_of_to_nat_lt {a b : ℤ} (h : to_nat a < to_nat b) : a < b :=
(to_nat_lt_to_nat $ lt_to_nat.1 $ lt_of_le_of_lt (nat.zero_le _) h).1 h
lemma to_nat_add {a b : ℤ} (ha : 0 ≤ a) (hb : 0 ≤ b) :
(a + b).to_nat = a.to_nat + b.to_nat :=
begin
lift a to ℕ using ha,
lift b to ℕ using hb,
norm_cast,
end
lemma to_nat_add_one {a : ℤ} (h : 0 ≤ a) : (a + 1).to_nat = a.to_nat + 1 :=
to_nat_add h (zero_le_one)
/-- If `n : ℕ`, then `int.to_nat' n = some n`, if `n : ℤ` is negative, then `int.to_nat' n = none`.
-/
def to_nat' : ℤ → option ℕ
| (n : ℕ) := some n
| -[1+ n] := none
theorem mem_to_nat' : ∀ (a : ℤ) (n : ℕ), n ∈ to_nat' a ↔ a = n
| (m : ℕ) n := option.some_inj.trans coe_nat_inj'.symm
| -[1+ m] n := by split; intro h; cases h
lemma to_nat_zero_of_neg : ∀ {z : ℤ}, z < 0 → z.to_nat = 0
| (-[1+n]) _ := rfl
| (int.of_nat n) h := (not_le_of_gt h $ int.of_nat_nonneg n).elim
/-! ### units -/
@[simp] theorem units_nat_abs (u : units ℤ) : nat_abs u = 1 :=
units.ext_iff.1 $ nat.units_eq_one ⟨nat_abs u, nat_abs ↑u⁻¹,
by rw [← nat_abs_mul, units.mul_inv]; refl,
by rw [← nat_abs_mul, units.inv_mul]; refl⟩
theorem units_eq_one_or (u : units ℤ) : u = 1 ∨ u = -1 :=
by simpa only [units.ext_iff, units_nat_abs] using nat_abs_eq u
lemma units_inv_eq_self (u : units ℤ) : u⁻¹ = u :=
(units_eq_one_or u).elim (λ h, h.symm ▸ rfl) (λ h, h.symm ▸ rfl)
@[simp] lemma units_mul_self (u : units ℤ) : u * u = 1 :=
(units_eq_one_or u).elim (λ h, h.symm ▸ rfl) (λ h, h.symm ▸ rfl)
-- `units.coe_mul` is a "wrong turn" for the simplifier, this undoes it and simplifies further
@[simp] lemma units_coe_mul_self (u : units ℤ) : (u * u : ℤ) = 1 :=
by rw [←units.coe_mul, units_mul_self, units.coe_one]
/-! ### bitwise ops -/
@[simp] lemma bodd_zero : bodd 0 = ff := rfl
@[simp] lemma bodd_one : bodd 1 = tt := rfl
lemma bodd_two : bodd 2 = ff := rfl
@[simp, norm_cast] lemma bodd_coe (n : ℕ) : int.bodd n = nat.bodd n := rfl
@[simp] lemma bodd_sub_nat_nat (m n : ℕ) : bodd (sub_nat_nat m n) = bxor m.bodd n.bodd :=
by apply sub_nat_nat_elim m n (λ m n i, bodd i = bxor m.bodd n.bodd); intros;
simp; cases i.bodd; simp
@[simp] lemma bodd_neg_of_nat (n : ℕ) : bodd (neg_of_nat n) = n.bodd :=
by cases n; simp; refl
@[simp] lemma bodd_neg (n : ℤ) : bodd (-n) = bodd n :=
by cases n; simp [has_neg.neg, int.coe_nat_eq, int.neg, bodd, -of_nat_eq_coe]
@[simp] lemma bodd_add (m n : ℤ) : bodd (m + n) = bxor (bodd m) (bodd n) :=
by cases m with m m; cases n with n n; unfold has_add.add;
simp [int.add, -of_nat_eq_coe, bool.bxor_comm]
@[simp] lemma bodd_mul (m n : ℤ) : bodd (m * n) = bodd m && bodd n :=
by cases m with m m; cases n with n n;
simp [← int.mul_def, int.mul, -of_nat_eq_coe, bool.bxor_comm]
theorem bodd_add_div2 : ∀ n, cond (bodd n) 1 0 + 2 * div2 n = n
| (n : ℕ) :=
by rw [show (cond (bodd n) 1 0 : ℤ) = (cond (bodd n) 1 0 : ℕ),
by cases bodd n; refl]; exact congr_arg of_nat n.bodd_add_div2
| -[1+ n] := begin
refine eq.trans _ (congr_arg neg_succ_of_nat n.bodd_add_div2),
dsimp [bodd], cases nat.bodd n; dsimp [cond, bnot, div2, int.mul],
{ change -[1+ 2 * nat.div2 n] = _, rw zero_add },
{ rw [zero_add, add_comm], refl }
end
theorem div2_val : ∀ n, div2 n = n / 2
| (n : ℕ) := congr_arg of_nat n.div2_val
| -[1+ n] := congr_arg neg_succ_of_nat n.div2_val
lemma bit0_val (n : ℤ) : bit0 n = 2 * n := (two_mul _).symm
lemma bit1_val (n : ℤ) : bit1 n = 2 * n + 1 := congr_arg (+(1:ℤ)) (bit0_val _)
lemma bit_val (b n) : bit b n = 2 * n + cond b 1 0 :=
by { cases b, apply (bit0_val n).trans (add_zero _).symm, apply bit1_val }
lemma bit_decomp (n : ℤ) : bit (bodd n) (div2 n) = n :=
(bit_val _ _).trans $ (add_comm _ _).trans $ bodd_add_div2 _
/-- Defines a function from `ℤ` conditionally, if it is defined for odd and even integers separately
using `bit`. -/
def {u} bit_cases_on {C : ℤ → Sort u} (n) (h : ∀ b n, C (bit b n)) : C n :=
by rw [← bit_decomp n]; apply h
@[simp] lemma bit_zero : bit ff 0 = 0 := rfl
@[simp] lemma bit_coe_nat (b) (n : ℕ) : bit b n = nat.bit b n :=
by rw [bit_val, nat.bit_val]; cases b; refl
@[simp] lemma bit_neg_succ (b) (n : ℕ) : bit b -[1+ n] = -[1+ nat.bit (bnot b) n] :=
by rw [bit_val, nat.bit_val]; cases b; refl
@[simp] lemma bodd_bit (b n) : bodd (bit b n) = b :=
by rw bit_val; simp; cases b; cases bodd n; refl
@[simp] lemma bodd_bit0 (n : ℤ) : bodd (bit0 n) = ff := bodd_bit ff n
@[simp] lemma bodd_bit1 (n : ℤ) : bodd (bit1 n) = tt := bodd_bit tt n
@[simp] lemma div2_bit (b n) : div2 (bit b n) = n :=
begin
rw [bit_val, div2_val, add_comm, int.add_mul_div_left, (_ : (_/2:ℤ) = 0), zero_add],
cases b, all_goals {exact dec_trivial}
end
lemma bit0_ne_bit1 (m n : ℤ) : bit0 m ≠ bit1 n :=
mt (congr_arg bodd) $ by simp
lemma bit1_ne_bit0 (m n : ℤ) : bit1 m ≠ bit0 n :=
(bit0_ne_bit1 _ _).symm
lemma bit1_ne_zero (m : ℤ) : bit1 m ≠ 0 :=
by simpa only [bit0_zero] using bit1_ne_bit0 m 0
@[simp] lemma test_bit_zero (b) : ∀ n, test_bit (bit b n) 0 = b
| (n : ℕ) := by rw [bit_coe_nat]; apply nat.test_bit_zero
| -[1+ n] := by rw [bit_neg_succ]; dsimp [test_bit]; rw [nat.test_bit_zero];
clear test_bit_zero; cases b; refl
@[simp] lemma test_bit_succ (m b) : ∀ n, test_bit (bit b n) (nat.succ m) = test_bit n m
| (n : ℕ) := by rw [bit_coe_nat]; apply nat.test_bit_succ
| -[1+ n] := by rw [bit_neg_succ]; dsimp [test_bit]; rw [nat.test_bit_succ]
private meta def bitwise_tac : tactic unit := `[
funext m,
funext n,
cases m with m m; cases n with n n; try {refl},
all_goals {
apply congr_arg of_nat <|> apply congr_arg neg_succ_of_nat,
try {dsimp [nat.land, nat.ldiff, nat.lor]},
try {rw [
show nat.bitwise (λ a b, a && bnot b) n m =
nat.bitwise (λ a b, b && bnot a) m n, from
congr_fun (congr_fun (@nat.bitwise_swap (λ a b, b && bnot a) rfl) n) m]},
apply congr_arg (λ f, nat.bitwise f m n),
funext a,
funext b,
cases a; cases b; refl
},
all_goals {unfold nat.land nat.ldiff nat.lor}
]
theorem bitwise_or : bitwise bor = lor := by bitwise_tac
theorem bitwise_and : bitwise band = land := by bitwise_tac
theorem bitwise_diff : bitwise (λ a b, a && bnot b) = ldiff := by bitwise_tac
theorem bitwise_xor : bitwise bxor = lxor := by bitwise_tac
@[simp] lemma bitwise_bit (f : bool → bool → bool) (a m b n) :
bitwise f (bit a m) (bit b n) = bit (f a b) (bitwise f m n) :=
begin
cases m with m m; cases n with n n;
repeat { rw [← int.coe_nat_eq] <|> rw bit_coe_nat <|> rw bit_neg_succ };
unfold bitwise nat_bitwise bnot;
[ induction h : f ff ff,
induction h : f ff tt,
induction h : f tt ff,
induction h : f tt tt ],
all_goals {
unfold cond, rw nat.bitwise_bit,
repeat { rw bit_coe_nat <|> rw bit_neg_succ <|> rw bnot_bnot } },
all_goals { unfold bnot {fail_if_unchanged := ff}; rw h; refl }
end
@[simp] lemma lor_bit (a m b n) : lor (bit a m) (bit b n) = bit (a || b) (lor m n) :=
by rw [← bitwise_or, bitwise_bit]
@[simp] lemma land_bit (a m b n) : land (bit a m) (bit b n) = bit (a && b) (land m n) :=
by rw [← bitwise_and, bitwise_bit]
@[simp] lemma ldiff_bit (a m b n) : ldiff (bit a m) (bit b n) = bit (a && bnot b) (ldiff m n) :=
by rw [← bitwise_diff, bitwise_bit]
@[simp] lemma lxor_bit (a m b n) : lxor (bit a m) (bit b n) = bit (bxor a b) (lxor m n) :=
by rw [← bitwise_xor, bitwise_bit]
@[simp] lemma lnot_bit (b) : ∀ n, lnot (bit b n) = bit (bnot b) (lnot n)
| (n : ℕ) := by simp [lnot]
| -[1+ n] := by simp [lnot]
@[simp] lemma test_bit_bitwise (f : bool → bool → bool) (m n k) :
test_bit (bitwise f m n) k = f (test_bit m k) (test_bit n k) :=
begin
induction k with k IH generalizing m n;
apply bit_cases_on m; intros a m';
apply bit_cases_on n; intros b n';
rw bitwise_bit,
{ simp [test_bit_zero] },
{ simp [test_bit_succ, IH] }
end
@[simp] lemma test_bit_lor (m n k) : test_bit (lor m n) k = test_bit m k || test_bit n k :=
by rw [← bitwise_or, test_bit_bitwise]
@[simp] lemma test_bit_land (m n k) : test_bit (land m n) k = test_bit m k && test_bit n k :=
by rw [← bitwise_and, test_bit_bitwise]
@[simp]
lemma test_bit_ldiff (m n k) : test_bit (ldiff m n) k = test_bit m k && bnot (test_bit n k) :=
by rw [← bitwise_diff, test_bit_bitwise]
@[simp] lemma test_bit_lxor (m n k) : test_bit (lxor m n) k = bxor (test_bit m k) (test_bit n k) :=
by rw [← bitwise_xor, test_bit_bitwise]
@[simp] lemma test_bit_lnot : ∀ n k, test_bit (lnot n) k = bnot (test_bit n k)
| (n : ℕ) k := by simp [lnot, test_bit]
| -[1+ n] k := by simp [lnot, test_bit]
lemma shiftl_add : ∀ (m : ℤ) (n : ℕ) (k : ℤ), shiftl m (n + k) = shiftl (shiftl m n) k
| (m : ℕ) n (k:ℕ) := congr_arg of_nat (nat.shiftl_add _ _ _)
| -[1+ m] n (k:ℕ) := congr_arg neg_succ_of_nat (nat.shiftl'_add _ _ _ _)
| (m : ℕ) n -[1+k] := sub_nat_nat_elim n k.succ
(λ n k i, shiftl ↑m i = nat.shiftr (nat.shiftl m n) k)
(λ i n, congr_arg coe $
by rw [← nat.shiftl_sub, nat.add_sub_cancel_left]; apply nat.le_add_right)
(λ i n, congr_arg coe $
by rw [add_assoc, nat.shiftr_add, ← nat.shiftl_sub, nat.sub_self]; refl)
| -[1+ m] n -[1+k] := sub_nat_nat_elim n k.succ
(λ n k i, shiftl -[1+ m] i = -[1+ nat.shiftr (nat.shiftl' tt m n) k])
(λ i n, congr_arg neg_succ_of_nat $
by rw [← nat.shiftl'_sub, nat.add_sub_cancel_left]; apply nat.le_add_right)
(λ i n, congr_arg neg_succ_of_nat $
by rw [add_assoc, nat.shiftr_add, ← nat.shiftl'_sub, nat.sub_self]; refl)
lemma shiftl_sub (m : ℤ) (n : ℕ) (k : ℤ) : shiftl m (n - k) = shiftr (shiftl m n) k :=
shiftl_add _ _ _
@[simp] lemma shiftl_neg (m n : ℤ) : shiftl m (-n) = shiftr m n := rfl
@[simp] lemma shiftr_neg (m n : ℤ) : shiftr m (-n) = shiftl m n := by rw [← shiftl_neg, neg_neg]
@[simp] lemma shiftl_coe_nat (m n : ℕ) : shiftl m n = nat.shiftl m n := rfl
@[simp] lemma shiftr_coe_nat (m n : ℕ) : shiftr m n = nat.shiftr m n := by cases n; refl
@[simp] lemma shiftl_neg_succ (m n : ℕ) : shiftl -[1+ m] n = -[1+ nat.shiftl' tt m n] := rfl
@[simp]
lemma shiftr_neg_succ (m n : ℕ) : shiftr -[1+ m] n = -[1+ nat.shiftr m n] := by cases n; refl
lemma shiftr_add : ∀ (m : ℤ) (n k : ℕ), shiftr m (n + k) = shiftr (shiftr m n) k
| (m : ℕ) n k := by rw [shiftr_coe_nat, shiftr_coe_nat,
← int.coe_nat_add, shiftr_coe_nat, nat.shiftr_add]
| -[1+ m] n k := by rw [shiftr_neg_succ, shiftr_neg_succ,
← int.coe_nat_add, shiftr_neg_succ, nat.shiftr_add]
lemma shiftl_eq_mul_pow : ∀ (m : ℤ) (n : ℕ), shiftl m n = m * ↑(2 ^ n)
| (m : ℕ) n := congr_arg coe (nat.shiftl_eq_mul_pow _ _)
| -[1+ m] n := @congr_arg ℕ ℤ _ _ (λi, -i) (nat.shiftl'_tt_eq_mul_pow _ _)
lemma shiftr_eq_div_pow : ∀ (m : ℤ) (n : ℕ), shiftr m n = m / ↑(2 ^ n)
| (m : ℕ) n := by rw shiftr_coe_nat; exact congr_arg coe (nat.shiftr_eq_div_pow _ _)
| -[1+ m] n := begin
rw [shiftr_neg_succ, neg_succ_of_nat_div, nat.shiftr_eq_div_pow], refl,
exact coe_nat_lt_coe_nat_of_lt (pow_pos dec_trivial _)
end
lemma one_shiftl (n : ℕ) : shiftl 1 n = (2 ^ n : ℕ) :=
congr_arg coe (nat.one_shiftl _)
@[simp] lemma zero_shiftl : ∀ n : ℤ, shiftl 0 n = 0
| (n : ℕ) := congr_arg coe (nat.zero_shiftl _)
| -[1+ n] := congr_arg coe (nat.zero_shiftr _)
@[simp] lemma zero_shiftr (n) : shiftr 0 n = 0 := zero_shiftl _
/-! ### Least upper bound property for integers -/
section classical
open_locale classical
theorem exists_least_of_bdd {P : ℤ → Prop}
(Hbdd : ∃ b : ℤ, ∀ z : ℤ, P z → b ≤ z)
(Hinh : ∃ z : ℤ, P z) : ∃ lb : ℤ, P lb ∧ (∀ z : ℤ, P z → lb ≤ z) :=
let ⟨b, Hb⟩ := Hbdd in
have EX : ∃ n : ℕ, P (b + n), from
let ⟨elt, Helt⟩ := Hinh in
match elt, le.dest (Hb _ Helt), Helt with
| ._, ⟨n, rfl⟩, Hn := ⟨n, Hn⟩
end,
⟨b + (nat.find EX : ℤ), nat.find_spec EX, λ z h,
match z, le.dest (Hb _ h), h with
| ._, ⟨n, rfl⟩, h := add_le_add_left
(int.coe_nat_le.2 $ nat.find_min' _ h) _
end⟩
theorem exists_greatest_of_bdd {P : ℤ → Prop}
(Hbdd : ∃ b : ℤ, ∀ z : ℤ, P z → z ≤ b)
(Hinh : ∃ z : ℤ, P z) : ∃ ub : ℤ, P ub ∧ (∀ z : ℤ, P z → z ≤ ub) :=
have Hbdd' : ∃ (b : ℤ), ∀ (z : ℤ), P (-z) → b ≤ z, from
let ⟨b, Hb⟩ := Hbdd in ⟨-b, λ z h, neg_le.1 (Hb _ h)⟩,
have Hinh' : ∃ z : ℤ, P (-z), from
let ⟨elt, Helt⟩ := Hinh in ⟨-elt, by rw [neg_neg]; exact Helt⟩,
let ⟨lb, Plb, al⟩ := exists_least_of_bdd Hbdd' Hinh' in
⟨-lb, Plb, λ z h, le_neg.1 $ al _ $ by rwa neg_neg⟩
end classical
end int
attribute [irreducible] int.nonneg
|
2a3fc88c99aa27e4d68530b0e0dd84d5d74048de | 618003631150032a5676f229d13a079ac875ff77 | /src/ring_theory/ideal_operations.lean | ceea29cd69ef95043d27c547bae1824abdb511aa | [
"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 | 34,496 | lean | /-
Copyright (c) 2018 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau
More operations on modules and ideals.
-/
import data.nat.choose
import data.equiv.ring
import ring_theory.algebra_operations
universes u v w x
namespace submodule
variables {R : Type u} {M : Type v}
variables [comm_ring R] [add_comm_group M] [module R M]
instance has_scalar' : has_scalar (ideal R) (submodule R M) :=
⟨λ I N, ⨆ r : I, N.map (r.1 • linear_map.id)⟩
def annihilator (N : submodule R M) : ideal R :=
(linear_map.lsmul R N).ker
def colon (N P : submodule R M) : ideal R :=
annihilator (P.map N.mkq)
variables {I J : ideal R} {N N₁ N₂ P P₁ P₂ : submodule R M}
theorem mem_annihilator {r} : r ∈ N.annihilator ↔ ∀ n ∈ N, r • n = (0:M) :=
⟨λ hr n hn, congr_arg subtype.val (linear_map.ext_iff.1 (linear_map.mem_ker.1 hr) ⟨n, hn⟩),
λ h, linear_map.mem_ker.2 $ linear_map.ext $ λ n, subtype.eq $ h n.1 n.2⟩
theorem mem_annihilator' {r} : r ∈ N.annihilator ↔ N ≤ comap (r • linear_map.id) ⊥ :=
mem_annihilator.trans ⟨λ H n hn, (mem_bot R).2 $ H n hn, λ H n hn, (mem_bot R).1 $ H hn⟩
theorem annihilator_bot : (⊥ : submodule R M).annihilator = ⊤ :=
(ideal.eq_top_iff_one _).2 $ mem_annihilator'.2 bot_le
theorem annihilator_eq_top_iff : N.annihilator = ⊤ ↔ N = ⊥ :=
⟨λ H, eq_bot_iff.2 $ λ (n:M) hn, (mem_bot R).2 $ one_smul R n ▸ mem_annihilator.1 ((ideal.eq_top_iff_one _).1 H) n hn,
λ H, H.symm ▸ annihilator_bot⟩
theorem annihilator_mono (h : N ≤ P) : P.annihilator ≤ N.annihilator :=
λ r hrp, mem_annihilator.2 $ λ n hn, mem_annihilator.1 hrp n $ h hn
theorem annihilator_supr (ι : Sort w) (f : ι → submodule R M) :
(annihilator ⨆ i, f i) = ⨅ i, annihilator (f i) :=
le_antisymm (le_infi $ λ i, annihilator_mono $ le_supr _ _)
(λ r H, mem_annihilator'.2 $ supr_le $ λ i,
have _ := (mem_infi _).1 H i, mem_annihilator'.1 this)
theorem mem_colon {r} : r ∈ N.colon P ↔ ∀ p ∈ P, r • p ∈ N :=
mem_annihilator.trans ⟨λ H p hp, (quotient.mk_eq_zero N).1 (H (quotient.mk p) (mem_map_of_mem hp)),
λ H m ⟨p, hp, hpm⟩, hpm ▸ (N.mkq).map_smul r p ▸ (quotient.mk_eq_zero N).2 $ H p hp⟩
theorem mem_colon' {r} : r ∈ N.colon P ↔ P ≤ comap (r • linear_map.id) N :=
mem_colon
theorem colon_mono (hn : N₁ ≤ N₂) (hp : P₁ ≤ P₂) : N₁.colon P₂ ≤ N₂.colon P₁ :=
λ r hrnp, mem_colon.2 $ λ p₁ hp₁, hn $ mem_colon.1 hrnp p₁ $ hp hp₁
theorem infi_colon_supr (ι₁ : Sort w) (f : ι₁ → submodule R M)
(ι₂ : Sort x) (g : ι₂ → submodule R M) :
(⨅ i, f i).colon (⨆ j, g j) = ⨅ i j, (f i).colon (g j) :=
le_antisymm (le_infi $ λ i, le_infi $ λ j, colon_mono (infi_le _ _) (le_supr _ _))
(λ r H, mem_colon'.2 $ supr_le $ λ j, map_le_iff_le_comap.1 $ le_infi $ λ i,
map_le_iff_le_comap.2 $ mem_colon'.1 $ have _ := ((mem_infi _).1 H i),
have _ := ((mem_infi _).1 this j), this)
theorem smul_mem_smul {r} {n} (hr : r ∈ I) (hn : n ∈ N) : r • n ∈ I • N :=
(le_supr _ ⟨r, hr⟩ : _ ≤ I • N) ⟨n, hn, rfl⟩
theorem smul_le {P : submodule R M} : I • N ≤ P ↔ ∀ (r ∈ I) (n ∈ N), r • n ∈ P :=
⟨λ H r hr n hn, H $ smul_mem_smul hr hn,
λ H, supr_le $ λ r, map_le_iff_le_comap.2 $ λ n hn, H r.1 r.2 n hn⟩
@[elab_as_eliminator]
theorem smul_induction_on {p : M → Prop} {x} (H : x ∈ I • N)
(Hb : ∀ (r ∈ I) (n ∈ N), p (r • n)) (H0 : p 0)
(H1 : ∀ x y, p x → p y → p (x + y))
(H2 : ∀ (c:R) n, p n → p (c • n)) : p x :=
(@smul_le _ _ _ _ _ _ _ ⟨p, H0, H1, H2⟩).2 Hb H
theorem mem_smul_span_singleton {I : ideal R} {m : M} {x : M} :
x ∈ I • span R ({m} : set M) ↔ ∃ y ∈ I, y • m = x :=
⟨λ hx, smul_induction_on hx
(λ r hri n hnm, let ⟨s, hs⟩ := mem_span_singleton.1 hnm in ⟨r * s, I.mul_mem_right hri, hs ▸ mul_smul r s m⟩)
⟨0, I.zero_mem, by rw [zero_smul]⟩
(λ m1 m2 ⟨y1, hyi1, hy1⟩ ⟨y2, hyi2, hy2⟩, ⟨y1 + y2, I.add_mem hyi1 hyi2, by rw [add_smul, hy1, hy2]⟩)
(λ c r ⟨y, hyi, hy⟩, ⟨c * y, I.mul_mem_left hyi, by rw [mul_smul, hy]⟩),
λ ⟨y, hyi, hy⟩, hy ▸ smul_mem_smul hyi (subset_span $ set.mem_singleton m)⟩
theorem smul_le_right : I • N ≤ N :=
smul_le.2 $ λ r hr n, N.smul_mem r
theorem smul_mono (hij : I ≤ J) (hnp : N ≤ P) : I • N ≤ J • P :=
smul_le.2 $ λ r hr n hn, smul_mem_smul (hij hr) (hnp hn)
theorem smul_mono_left (h : I ≤ J) : I • N ≤ J • N :=
smul_mono h (le_refl N)
theorem smul_mono_right (h : N ≤ P) : I • N ≤ I • P :=
smul_mono (le_refl I) h
variables (I J N P)
@[simp] theorem smul_bot : I • (⊥ : submodule R M) = ⊥ :=
eq_bot_iff.2 $ smul_le.2 $ λ r hri s hsb,
(submodule.mem_bot R).2 $ ((submodule.mem_bot R).1 hsb).symm ▸ smul_zero r
@[simp] theorem bot_smul : (⊥ : ideal R) • N = ⊥ :=
eq_bot_iff.2 $ smul_le.2 $ λ r hrb s hsi,
(submodule.mem_bot R).2 $ ((submodule.mem_bot R).1 hrb).symm ▸ zero_smul _ s
@[simp] theorem top_smul : (⊤ : ideal R) • N = N :=
le_antisymm smul_le_right $ λ r hri, one_smul R r ▸ smul_mem_smul mem_top hri
theorem smul_sup : I • (N ⊔ P) = I • N ⊔ I • P :=
le_antisymm (smul_le.2 $ λ r hri m hmnp, let ⟨n, hn, p, hp, hnpm⟩ := mem_sup.1 hmnp in
mem_sup.2 ⟨_, smul_mem_smul hri hn, _, smul_mem_smul hri hp, hnpm ▸ (smul_add _ _ _).symm⟩)
(sup_le (smul_mono_right le_sup_left)
(smul_mono_right le_sup_right))
theorem sup_smul : (I ⊔ J) • N = I • N ⊔ J • N :=
le_antisymm (smul_le.2 $ λ r hrij n hn, let ⟨ri, hri, rj, hrj, hrijr⟩ := mem_sup.1 hrij in
mem_sup.2 ⟨_, smul_mem_smul hri hn, _, smul_mem_smul hrj hn, hrijr ▸ (add_smul _ _ _).symm⟩)
(sup_le (smul_mono_left le_sup_left)
(smul_mono_left le_sup_right))
theorem smul_assoc : (I • J) • N = I • (J • N) :=
le_antisymm (smul_le.2 $ λ rs hrsij t htn,
smul_induction_on hrsij
(λ r hr s hs, (@smul_eq_mul R _ r s).symm ▸ smul_smul r s t ▸ smul_mem_smul hr (smul_mem_smul hs htn))
((zero_smul R t).symm ▸ submodule.zero_mem _)
(λ x y, (add_smul x y t).symm ▸ submodule.add_mem _)
(λ r s h, (@smul_eq_mul R _ r s).symm ▸ smul_smul r s t ▸ submodule.smul_mem _ _ h))
(smul_le.2 $ λ r hr sn hsn, suffices J • N ≤ submodule.comap (r • linear_map.id) ((I • J) • N), from this hsn,
smul_le.2 $ λ s hs n hn, show r • (s • n) ∈ (I • J) • N, from mul_smul r s n ▸ smul_mem_smul (smul_mem_smul hr hs) hn)
variables (S : set R) (T : set M)
theorem span_smul_span : (ideal.span S) • (span R T) =
span R (⋃ (s ∈ S) (t ∈ T), {s • t}) :=
le_antisymm (smul_le.2 $ λ r hrS n hnT, span_induction hrS
(λ r hrS, span_induction hnT
(λ n hnT, subset_span $ set.mem_bUnion hrS $
set.mem_bUnion hnT $ set.mem_singleton _)
((smul_zero r : r • 0 = (0:M)).symm ▸ submodule.zero_mem _)
(λ x y, (smul_add r x y).symm ▸ submodule.add_mem _)
(λ c m, by rw [smul_smul, mul_comm, mul_smul]; exact submodule.smul_mem _ _))
((zero_smul R n).symm ▸ submodule.zero_mem _)
(λ r s, (add_smul r s n).symm ▸ submodule.add_mem _)
(λ c r, by rw [smul_eq_mul, mul_smul]; exact submodule.smul_mem _ _)) $
span_le.2 $ set.bUnion_subset $ λ r hrS, set.bUnion_subset $ λ n hnT, set.singleton_subset_iff.2 $
smul_mem_smul (subset_span hrS) (subset_span hnT)
end submodule
namespace ideal
section chinese_remainder
variables {R : Type u} [comm_ring R] {ι : Type v}
theorem exists_sub_one_mem_and_mem (s : finset ι) {f : ι → ideal R}
(hf : ∀ i ∈ s, ∀ j ∈ s, i ≠ j → f i ⊔ f j = ⊤) (i : ι) (his : i ∈ s) :
∃ r : R, r - 1 ∈ f i ∧ ∀ j ∈ s, j ≠ i → r ∈ f j :=
begin
have : ∀ j ∈ s, j ≠ i → ∃ r : R, ∃ H : r - 1 ∈ f i, r ∈ f j,
{ intros j hjs hji, specialize hf i his j hjs hji.symm,
rw [eq_top_iff_one, submodule.mem_sup] at hf,
rcases hf with ⟨r, hri, s, hsj, hrs⟩, refine ⟨1 - r, _, _⟩,
{ rw [sub_right_comm, sub_self, zero_sub], exact (f i).neg_mem hri },
{ rw [← hrs, add_sub_cancel'], exact hsj } },
classical,
have : ∃ g : ι → R, (∀ j, g j - 1 ∈ f i) ∧ ∀ j ∈ s, j ≠ i → g j ∈ f j,
{ choose g hg1 hg2,
refine ⟨λ j, if H : j ∈ s ∧ j ≠ i then g j H.1 H.2 else 1, λ j, _, λ j, _⟩,
{ split_ifs with h, { apply hg1 }, rw sub_self, exact (f i).zero_mem },
{ intros hjs hji, rw dif_pos, { apply hg2 }, exact ⟨hjs, hji⟩ } },
rcases this with ⟨g, hgi, hgj⟩, use (s.erase i).prod g, split,
{ rw [← quotient.eq, quotient.mk_one, quotient.mk_prod],
apply finset.prod_eq_one, intros, rw [← quotient.mk_one, quotient.eq], apply hgi },
intros j hjs hji, rw [← quotient.eq_zero_iff_mem, quotient.mk_prod],
refine finset.prod_eq_zero (finset.mem_erase_of_ne_of_mem hji hjs) _,
rw quotient.eq_zero_iff_mem, exact hgj j hjs hji
end
theorem exists_sub_mem [fintype ι] {f : ι → ideal R}
(hf : ∀ i j, i ≠ j → f i ⊔ f j = ⊤) (g : ι → R) :
∃ r : R, ∀ i, r - g i ∈ f i :=
begin
have : ∃ φ : ι → R, (∀ i, φ i - 1 ∈ f i) ∧ (∀ i j, i ≠ j → φ i ∈ f j),
{ have := exists_sub_one_mem_and_mem (finset.univ : finset ι) (λ i _ j _ hij, hf i j hij),
choose φ hφ,
existsi λ i, φ i (finset.mem_univ i),
exact ⟨λ i, (hφ i _).1, λ i j hij, (hφ i _).2 j (finset.mem_univ j) hij.symm⟩ },
rcases this with ⟨φ, hφ1, hφ2⟩,
use finset.univ.sum (λ i, g i * φ i),
intros i,
rw [← quotient.eq, quotient.mk_sum],
refine eq.trans (finset.sum_eq_single i _ _) _,
{ intros j _ hji, rw quotient.eq_zero_iff_mem, exact (f i).mul_mem_left (hφ2 j i hji) },
{ intros hi, exact (hi $ finset.mem_univ i).elim },
specialize hφ1 i, rw [← quotient.eq, quotient.mk_one] at hφ1,
rw [quotient.mk_mul, hφ1, mul_one]
end
def quotient_inf_to_pi_quotient (f : ι → ideal R) :
(⨅ i, f i).quotient →+* Π i, (f i).quotient :=
begin
refine quotient.lift (⨅ i, f i) _ _,
{ convert @@pi.ring_hom (λ i, quotient (f i)) (λ i, ring.to_semiring) ring.to_semiring
(λ i, quotient.mk_hom (f i)) },
{ intros r hr,
rw submodule.mem_infi at hr,
ext i,
exact quotient.eq_zero_iff_mem.2 (hr i) }
end
theorem bijective_quotient_inf_to_pi_quotient [fintype ι] {f : ι → ideal R}
(hf : ∀ i j, i ≠ j → f i ⊔ f j = ⊤) :
function.bijective (quotient_inf_to_pi_quotient f) :=
⟨λ x y, quotient.induction_on₂' x y $ λ r s hrs, quotient.eq.2 $
(submodule.mem_infi _).2 $ λ i, quotient.eq.1 $
show quotient_inf_to_pi_quotient f (quotient.mk' r) i = _, by rw hrs; refl,
λ g, let ⟨r, hr⟩ := exists_sub_mem hf (λ i, quotient.out' (g i)) in
⟨quotient.mk _ r, funext $ λ i, quotient.out_eq' (g i) ▸ quotient.eq.2 (hr i)⟩⟩
/-- Chinese Remainder Theorem. Eisenbud Ex.2.6. Similar to Atiyah-Macdonald 1.10 and Stacks 00DT -/
noncomputable def quotient_inf_ring_equiv_pi_quotient [fintype ι] (f : ι → ideal R)
(hf : ∀ i j, i ≠ j → f i ⊔ f j = ⊤) :
(⨅ i, f i).quotient ≃+* Π i, (f i).quotient :=
{ .. equiv.of_bijective (bijective_quotient_inf_to_pi_quotient hf),
.. quotient_inf_to_pi_quotient f }
end chinese_remainder
section mul_and_radical
variables {R : Type u} [comm_ring R]
variables {I J K L: ideal R}
instance : has_mul (ideal R) := ⟨(•)⟩
theorem mul_mem_mul {r s} (hr : r ∈ I) (hs : s ∈ J) : r * s ∈ I * J :=
submodule.smul_mem_smul hr hs
theorem mul_mem_mul_rev {r s} (hr : r ∈ I) (hs : s ∈ J) : s * r ∈ I * J :=
mul_comm r s ▸ mul_mem_mul hr hs
theorem mul_le : I * J ≤ K ↔ ∀ (r ∈ I) (s ∈ J), r * s ∈ K :=
submodule.smul_le
lemma mul_le_left : I * J ≤ J :=
ideal.mul_le.2 (λ r hr s, ideal.mul_mem_left _)
lemma mul_le_right : I * J ≤ I :=
ideal.mul_le.2 (λ r hr s hs, ideal.mul_mem_right _ hr)
@[simp] lemma sup_mul_right_self : I ⊔ (I * J) = I :=
sup_eq_left.2 ideal.mul_le_right
@[simp] lemma sup_mul_left_self : I ⊔ (J * I) = I :=
sup_eq_left.2 ideal.mul_le_left
@[simp] lemma mul_right_self_sup : (I * J) ⊔ I = I :=
sup_eq_right.2 ideal.mul_le_right
@[simp] lemma mul_left_self_sup : (J * I) ⊔ I = I :=
sup_eq_right.2 ideal.mul_le_left
variables (I J K)
protected theorem mul_comm : I * J = J * I :=
le_antisymm (mul_le.2 $ λ r hrI s hsJ, mul_mem_mul_rev hsJ hrI)
(mul_le.2 $ λ r hrJ s hsI, mul_mem_mul_rev hsI hrJ)
protected theorem mul_assoc : (I * J) * K = I * (J * K) :=
submodule.smul_assoc I J K
theorem span_mul_span (S T : set R) : span S * span T =
span ⋃ (s ∈ S) (t ∈ T), {s * t} :=
submodule.span_smul_span S T
variables {I J K}
theorem mul_le_inf : I * J ≤ I ⊓ J :=
mul_le.2 $ λ r hri s hsj, ⟨I.mul_mem_right hri, J.mul_mem_left hsj⟩
theorem mul_eq_inf_of_coprime (h : I ⊔ J = ⊤) : I * J = I ⊓ J :=
le_antisymm mul_le_inf $ λ r ⟨hri, hrj⟩,
let ⟨s, hsi, t, htj, hst⟩ := submodule.mem_sup.1 ((eq_top_iff_one _).1 h) in
mul_one r ▸ hst ▸ (mul_add r s t).symm ▸ ideal.add_mem (I * J) (mul_mem_mul_rev hsi hrj) (mul_mem_mul hri htj)
variables (I)
theorem mul_bot : I * ⊥ = ⊥ :=
submodule.smul_bot I
theorem bot_mul : ⊥ * I = ⊥ :=
submodule.bot_smul I
theorem mul_top : I * ⊤ = I :=
ideal.mul_comm ⊤ I ▸ submodule.top_smul I
theorem top_mul : ⊤ * I = I :=
submodule.top_smul I
variables {I}
theorem mul_mono (hik : I ≤ K) (hjl : J ≤ L) : I * J ≤ K * L :=
submodule.smul_mono hik hjl
theorem mul_mono_left (h : I ≤ J) : I * K ≤ J * K :=
submodule.smul_mono_left h
theorem mul_mono_right (h : J ≤ K) : I * J ≤ I * K :=
submodule.smul_mono_right h
variables (I J K)
theorem mul_sup : I * (J ⊔ K) = I * J ⊔ I * K :=
submodule.smul_sup I J K
theorem sup_mul : (I ⊔ J) * K = I * K ⊔ J * K :=
submodule.sup_smul I J K
variables {I J K}
lemma pow_le_pow {m n : ℕ} (h : m ≤ n) :
I^n ≤ I^m :=
begin
cases nat.exists_eq_add_of_le h with k hk,
rw [hk, pow_add],
exact le_trans (mul_le_inf) (inf_le_left)
end
/-- The radical of an ideal `I` consists of the elements `r` such that `r^n ∈ I` for some `n`. -/
def radical (I : ideal R) : ideal R :=
{ carrier := { r | ∃ n : ℕ, r ^ n ∈ I },
zero := ⟨1, (pow_one (0:R)).symm ▸ I.zero_mem⟩,
add := λ x y ⟨m, hxmi⟩ ⟨n, hyni⟩, ⟨m + n,
(add_pow x y (m + n)).symm ▸ I.sum_mem $
show ∀ c ∈ finset.range (nat.succ (m + n)), x ^ c * y ^ (m + n - c) * (nat.choose (m + n) c) ∈ I,
from λ c hc, or.cases_on (le_total c m)
(λ hcm, I.mul_mem_right $ I.mul_mem_left $ nat.add_comm n m ▸ (nat.add_sub_assoc hcm n).symm ▸
(pow_add y n (m-c)).symm ▸ I.mul_mem_right hyni)
(λ hmc, I.mul_mem_right $ I.mul_mem_right $ nat.add_sub_cancel' hmc ▸
(pow_add x m (c-m)).symm ▸ I.mul_mem_right hxmi)⟩,
smul := λ r s ⟨n, hsni⟩, ⟨n, show (r * s)^n ∈ I,
from (mul_pow r s n).symm ▸ I.mul_mem_left hsni⟩ }
theorem le_radical : I ≤ radical I :=
λ r hri, ⟨1, (pow_one r).symm ▸ hri⟩
variables (R)
theorem radical_top : (radical ⊤ : ideal R) = ⊤ :=
(eq_top_iff_one _).2 ⟨0, submodule.mem_top⟩
variables {R}
theorem radical_mono (H : I ≤ J) : radical I ≤ radical J :=
λ r ⟨n, hrni⟩, ⟨n, H hrni⟩
variables (I)
theorem radical_idem : radical (radical I) = radical I :=
le_antisymm (λ r ⟨n, k, hrnki⟩, ⟨n * k, (pow_mul r n k).symm ▸ hrnki⟩) le_radical
variables {I}
theorem radical_eq_top : radical I = ⊤ ↔ I = ⊤ :=
⟨λ h, (eq_top_iff_one _).2 $ let ⟨n, hn⟩ := (eq_top_iff_one _).1 h in
@one_pow R _ n ▸ hn, λ h, h.symm ▸ radical_top R⟩
theorem is_prime.radical (H : is_prime I) : radical I = I :=
le_antisymm (λ r ⟨n, hrni⟩, H.mem_of_pow_mem n hrni) le_radical
variables (I J)
theorem radical_sup : radical (I ⊔ J) = radical (radical I ⊔ radical J) :=
le_antisymm (radical_mono $ sup_le_sup le_radical le_radical) $
λ r ⟨n, hrnij⟩, let ⟨s, hs, t, ht, hst⟩ := submodule.mem_sup.1 hrnij in
@radical_idem _ _ (I ⊔ J) ▸ ⟨n, hst ▸ ideal.add_mem _
(radical_mono le_sup_left hs) (radical_mono le_sup_right ht)⟩
theorem radical_inf : radical (I ⊓ J) = radical I ⊓ radical J :=
le_antisymm (le_inf (radical_mono inf_le_left) (radical_mono inf_le_right))
(λ r ⟨⟨m, hrm⟩, ⟨n, hrn⟩⟩, ⟨m + n, (pow_add r m n).symm ▸ I.mul_mem_right hrm,
(pow_add r m n).symm ▸ J.mul_mem_left hrn⟩)
theorem radical_mul : radical (I * J) = radical I ⊓ radical J :=
le_antisymm (radical_inf I J ▸ radical_mono $ @mul_le_inf _ _ I J)
(λ r ⟨⟨m, hrm⟩, ⟨n, hrn⟩⟩, ⟨m + n, (pow_add r m n).symm ▸ mul_mem_mul hrm hrn⟩)
variables {I J}
theorem is_prime.radical_le_iff (hj : is_prime J) :
radical I ≤ J ↔ I ≤ J :=
⟨le_trans le_radical, λ hij r ⟨n, hrni⟩, hj.mem_of_pow_mem n $ hij hrni⟩
theorem radical_eq_Inf (I : ideal R) :
radical I = Inf { J : ideal R | I ≤ J ∧ is_prime J } :=
le_antisymm (le_Inf $ λ J hJ, hJ.2.radical_le_iff.2 hJ.1) $
λ r hr, classical.by_contradiction $ λ hri,
let ⟨m, (hrm : r ∉ radical m), him, hm⟩ := zorn.zorn_partial_order₀ {K : ideal R | r ∉ radical K}
(λ c hc hcc y hyc, ⟨Sup c, λ ⟨n, hrnc⟩, let ⟨y, hyc, hrny⟩ :=
(submodule.mem_Sup_of_directed ⟨y, hyc⟩ hcc.directed_on).1 hrnc in hc hyc ⟨n, hrny⟩,
λ z, le_Sup⟩) I hri in
have ∀ x ∉ m, r ∈ radical (m ⊔ span {x}) := λ x hxm, classical.by_contradiction $ λ hrmx, hxm $
hm (m ⊔ span {x}) hrmx le_sup_left ▸ (le_sup_right : _ ≤ m ⊔ span {x}) (subset_span $ set.mem_singleton _),
have is_prime m, from ⟨by rintro rfl; rw radical_top at hrm; exact hrm trivial,
λ x y hxym, classical.or_iff_not_imp_left.2 $ λ hxm, classical.by_contradiction $ λ hym,
let ⟨n, hrn⟩ := this _ hxm, ⟨p, hpm, q, hq, hpqrn⟩ := submodule.mem_sup.1 hrn, ⟨c, hcxq⟩ := mem_span_singleton'.1 hq in
let ⟨k, hrk⟩ := this _ hym, ⟨f, hfm, g, hg, hfgrk⟩ := submodule.mem_sup.1 hrk, ⟨d, hdyg⟩ := mem_span_singleton'.1 hg in
hrm ⟨n + k, by rw [pow_add, ← hpqrn, ← hcxq, ← hfgrk, ← hdyg, add_mul, mul_add (c*x), mul_assoc c x (d*y), mul_left_comm x, ← mul_assoc];
refine m.add_mem (m.mul_mem_right hpm) (m.add_mem (m.mul_mem_left hfm) (m.mul_mem_left hxym))⟩⟩,
hrm $ this.radical.symm ▸ (Inf_le ⟨him, this⟩ : Inf {J : ideal R | I ≤ J ∧ is_prime J} ≤ m) hr
instance : comm_semiring (ideal R) := submodule.comm_semiring
@[simp] lemma add_eq_sup : I + J = I ⊔ J := rfl
@[simp] lemma zero_eq_bot : (0 : ideal R) = ⊥ := rfl
@[simp] lemma one_eq_top : (1 : ideal R) = ⊤ :=
by erw [submodule.one_eq_map_top, submodule.map_id]
variables (I)
theorem radical_pow (n : ℕ) (H : n > 0) : radical (I^n) = radical I :=
nat.rec_on n (not.elim dec_trivial) (λ n ih H,
or.cases_on (lt_or_eq_of_le $ nat.le_of_lt_succ H)
(λ H, calc radical (I^(n+1))
= radical I ⊓ radical (I^n) : radical_mul _ _
... = radical I ⊓ radical I : by rw ih H
... = radical I : inf_idem)
(λ H, H ▸ (pow_one I).symm ▸ rfl)) H
end mul_and_radical
section map_and_comap
variables {R : Type u} {S : Type v} [comm_ring R] [comm_ring S]
variables (f : R →+* S)
variables {I J : ideal R} {K L : ideal S}
def map (I : ideal R) : ideal S :=
span (f '' I)
/-- `I.comap f` is the preimage of `I` under `f`. -/
def comap (I : ideal S) : ideal R :=
{ carrier := f ⁻¹' I,
zero := by simp only [set.mem_preimage, f.map_zero, I.mem_coe, I.zero_mem],
add := λ x y hx hy, show f (x + y) ∈ I, by { rw f.map_add, exact I.add_mem hx hy },
smul := λ c x hx, show f (c * x) ∈ I, by { rw f.map_mul, exact I.mul_mem_left hx } }
variables {f}
theorem map_mono (h : I ≤ J) : map f I ≤ map f J :=
span_mono $ set.image_subset _ h
theorem mem_map_of_mem {x} (h : x ∈ I) : f x ∈ map f I :=
subset_span ⟨x, h, rfl⟩
theorem map_le_iff_le_comap :
map f I ≤ K ↔ I ≤ comap f K :=
span_le.trans set.image_subset_iff
@[simp] theorem mem_comap {x} : x ∈ comap f K ↔ f x ∈ K := iff.rfl
theorem comap_mono (h : K ≤ L) : comap f K ≤ comap f L :=
set.preimage_mono (λ x hx, h hx)
variables (f)
theorem comap_ne_top (hK : K ≠ ⊤) : comap f K ≠ ⊤ :=
(ne_top_iff_one _).2 $ by rw [mem_comap, f.map_one];
exact (ne_top_iff_one _).1 hK
theorem is_prime.comap [hK : K.is_prime] : (comap f K).is_prime :=
⟨comap_ne_top _ hK.1, λ x y,
by simp only [mem_comap, f.map_mul]; apply hK.2⟩
variables (I J K L)
theorem map_top : map f ⊤ = ⊤ :=
(eq_top_iff_one _).2 $ subset_span ⟨1, trivial, f.map_one⟩
theorem map_mul : map f (I * J) = map f I * map f J :=
le_antisymm (map_le_iff_le_comap.2 $ mul_le.2 $ λ r hri s hsj,
show f (r * s) ∈ _, by rw f.map_mul;
exact mul_mem_mul (mem_map_of_mem hri) (mem_map_of_mem hsj))
(trans_rel_right _ (span_mul_span _ _) $ span_le.2 $
set.bUnion_subset $ λ i ⟨r, hri, hfri⟩,
set.bUnion_subset $ λ j ⟨s, hsj, hfsj⟩,
set.singleton_subset_iff.2 $ hfri ▸ hfsj ▸
by rw [← f.map_mul];
exact mem_map_of_mem (mul_mem_mul hri hsj))
variable (f)
lemma gc_map_comap : galois_connection (ideal.map f) (ideal.comap f) :=
λ I J, ideal.map_le_iff_le_comap
@[simp] lemma comap_id : I.comap (ring_hom.id R) = I :=
ideal.ext $ λ _, iff.rfl
@[simp] lemma map_id : I.map (ring_hom.id R) = I :=
(gc_map_comap (ring_hom.id R)).l_unique galois_connection.id comap_id
lemma comap_comap {T : Type*} [comm_ring T] {I : ideal T} (f : R →+* S)
(g : S →+*T) : (I.comap g).comap f = I.comap (g.comp f) := rfl
lemma map_map {T : Type*} [comm_ring T] {I : ideal R} (f : R →+* S)
(g : S →+*T) : (I.map f).map g = I.map (g.comp f) :=
((gc_map_comap f).compose _ _ _ _ (gc_map_comap g)).l_unique
(gc_map_comap (g.comp f)) (λ _, comap_comap _ _)
variables {f I J K L}
lemma map_le_of_le_comap : I ≤ K.comap f → I.map f ≤ K :=
(gc_map_comap f).l_le
lemma le_comap_of_map_le : I.map f ≤ K → I ≤ K.comap f :=
(gc_map_comap f).le_u
lemma le_comap_map : I ≤ (I.map f).comap f :=
(gc_map_comap f).le_u_l _
lemma map_comap_le : (K.comap f).map f ≤ K :=
(gc_map_comap f).l_u_le _
@[simp] lemma comap_top : (⊤ : ideal S).comap f = ⊤ :=
(gc_map_comap f).u_top
@[simp] lemma map_bot : (⊥ : ideal R).map f = ⊥ :=
(gc_map_comap f).l_bot
variables (f I J K L)
@[simp] lemma map_comap_map : ((I.map f).comap f).map f = I.map f :=
congr_fun (gc_map_comap f).l_u_l_eq_l I
@[simp] lemma comap_map_comap : ((K.comap f).map f).comap f = K.comap f :=
congr_fun (gc_map_comap f).u_l_u_eq_u K
lemma map_sup : (I ⊔ J).map f = I.map f ⊔ J.map f :=
(gc_map_comap f).l_sup
theorem comap_inf : comap f (K ⊓ L) = comap f K ⊓ comap f L := rfl
variables {ι : Sort*}
lemma map_supr (K : ι → ideal R) : (supr K).map f = ⨆ i, (K i).map f :=
(gc_map_comap f).l_supr
lemma comap_infi (K : ι → ideal S) : (infi K).comap f = ⨅ i, (K i).comap f :=
(gc_map_comap f).u_infi
lemma map_Sup (s : set (ideal R)): (Sup s).map f = ⨆ I ∈ s, (I : ideal R).map f :=
(gc_map_comap f).l_Sup
lemma comap_Inf (s : set (ideal S)): (Inf s).comap f = ⨅ I ∈ s, (I : ideal S).comap f :=
(gc_map_comap f).u_Inf
theorem comap_radical : comap f (radical K) = radical (comap f K) :=
le_antisymm (λ r ⟨n, hfrnk⟩, ⟨n, show f (r ^ n) ∈ K,
from (f.map_pow r n).symm ▸ hfrnk⟩)
(λ r ⟨n, hfrnk⟩, ⟨n, f.map_pow r n ▸ hfrnk⟩)
@[simp] lemma map_quotient_self :
map (quotient.mk_hom I) I = ⊥ :=
eq_bot_iff.2 $ ideal.map_le_iff_le_comap.2 $ λ x hx,
(submodule.mem_bot I.quotient).2 $ ideal.quotient.eq_zero_iff_mem.2 hx
variables {I J K L}
theorem map_inf_le : map f (I ⊓ J) ≤ map f I ⊓ map f J :=
(gc_map_comap f).monotone_l.map_inf_le _ _
theorem map_radical_le : map f (radical I) ≤ radical (map f I) :=
map_le_iff_le_comap.2 $ λ r ⟨n, hrni⟩, ⟨n, f.map_pow r n ▸ mem_map_of_mem hrni⟩
theorem le_comap_sup : comap f K ⊔ comap f L ≤ comap f (K ⊔ L) :=
(gc_map_comap f).monotone_u.le_map_sup _ _
theorem le_comap_mul : comap f K * comap f L ≤ comap f (K * L) :=
map_le_iff_le_comap.1 $ (map_mul f (comap f K) (comap f L)).symm ▸
mul_mono (map_le_iff_le_comap.2 $ le_refl _) (map_le_iff_le_comap.2 $ le_refl _)
section surjective
variables (hf : function.surjective f)
include hf
open function
theorem map_comap_of_surjective (I : ideal S) :
map f (comap f I) = I :=
le_antisymm (map_le_iff_le_comap.2 (le_refl _))
(λ s hsi, let ⟨r, hfrs⟩ := hf s in
hfrs ▸ (mem_map_of_mem $ show f r ∈ I, from hfrs.symm ▸ hsi))
/-- `map` and `comap` are adjoint, and the composition `map f ∘ comap f` is the
identity -/
def gi_map_comap : galois_insertion (map f) (comap f) :=
galois_insertion.monotone_intro
((gc_map_comap f).monotone_u)
((gc_map_comap f).monotone_l)
(λ _, le_comap_map)
(map_comap_of_surjective _ hf)
lemma map_surjective_of_surjective : surjective (map f) :=
(gi_map_comap f hf).l_surjective
lemma comap_injective_of_surjective : injective (comap f) :=
(gi_map_comap f hf).u_injective
lemma map_sup_comap_of_surjective (I J : ideal S) : (I.comap f ⊔ J.comap f).map f = I ⊔ J :=
(gi_map_comap f hf).l_sup_u _ _
lemma map_supr_comap_of_surjective (K : ι → ideal S) : (⨆i, (K i).comap f).map f = supr K :=
(gi_map_comap f hf).l_supr_u _
lemma map_inf_comap_of_surjective (I J : ideal S) : (I.comap f ⊓ J.comap f).map f = I ⊓ J :=
(gi_map_comap f hf).l_inf_u _ _
lemma map_infi_comap_of_surjective (K : ι → ideal S) : (⨅i, (K i).comap f).map f = infi K :=
(gi_map_comap f hf).l_infi_u _
theorem mem_image_of_mem_map_of_surjective {I : ideal R} {y}
(H : y ∈ map f I) : y ∈ f '' I :=
submodule.span_induction H (λ _, id) ⟨0, I.zero_mem, f.map_zero⟩
(λ y1 y2 ⟨x1, hx1i, hxy1⟩ ⟨x2, hx2i, hxy2⟩, ⟨x1 + x2, I.add_mem hx1i hx2i, hxy1 ▸ hxy2 ▸ f.map_add _ _⟩)
(λ c y ⟨x, hxi, hxy⟩, let ⟨d, hdc⟩ := hf c in ⟨d • x, I.smul_mem _ hxi, hdc ▸ hxy ▸ f.map_mul _ _⟩)
theorem comap_map_of_surjective (I : ideal R) :
comap f (map f I) = I ⊔ comap f ⊥ :=
le_antisymm (assume r h, let ⟨s, hsi, hfsr⟩ := mem_image_of_mem_map_of_surjective f hf h in
submodule.mem_sup.2 ⟨s, hsi, r - s, (submodule.mem_bot S).2 $ by rw [f.map_sub, hfsr, sub_self],
add_sub_cancel'_right s r⟩)
(sup_le (map_le_iff_le_comap.1 (le_refl _)) (comap_mono bot_le))
/-- Correspondence theorem -/
def order_iso_of_surjective :
((≤) : ideal S → ideal S → Prop) ≃o
((≤) : { p : ideal R // comap f ⊥ ≤ p } → { p : ideal R // comap f ⊥ ≤ p } → Prop) :=
{ to_fun := λ J, ⟨comap f J, comap_mono bot_le⟩,
inv_fun := λ I, map f I.1,
left_inv := λ J, map_comap_of_surjective f hf J,
right_inv := λ I, subtype.eq $ show comap f (map f I.1) = I.1,
from (comap_map_of_surjective f hf I).symm ▸ le_antisymm
(sup_le (le_refl _) I.2) le_sup_left,
ord' := λ I1 I2, ⟨comap_mono, λ H, map_comap_of_surjective f hf I1 ▸
map_comap_of_surjective f hf I2 ▸ map_mono H⟩ }
def le_order_embedding_of_surjective :
((≤) : ideal S → ideal S → Prop) ≼o ((≤) : ideal R → ideal R → Prop) :=
(order_iso_of_surjective f hf).to_order_embedding.trans (subtype.order_embedding _ _)
def lt_order_embedding_of_surjective :
((<) : ideal S → ideal S → Prop) ≼o ((<) : ideal R → ideal R → Prop) :=
(le_order_embedding_of_surjective f hf).lt_embedding_of_le_embedding
end surjective
end map_and_comap
section jacobson
variables {R : Type u} [comm_ring R]
/-- The Jacobson radical of `I` is the infimum of all maximal ideals containing `I`. -/
def jacobson (I : ideal R) : ideal R :=
Inf {J : ideal R | I ≤ J ∧ is_maximal J}
theorem jacobson_eq_top_iff {I : ideal R} : jacobson I = ⊤ ↔ I = ⊤ :=
⟨λ H, classical.by_contradiction $ λ hi, let ⟨M, hm, him⟩ := exists_le_maximal I hi in
lt_top_iff_ne_top.1 (lt_of_le_of_lt (show jacobson I ≤ M, from Inf_le ⟨him, hm⟩) $ lt_top_iff_ne_top.2 hm.1) H,
λ H, eq_top_iff.2 $ le_Inf $ λ J ⟨hij, hj⟩, H ▸ hij⟩
theorem mem_jacobson_iff {I : ideal R} {x : R} :
x ∈ jacobson I ↔ ∀ y, ∃ z, x * y * z + z - 1 ∈ I :=
⟨λ hx y, classical.by_cases
(assume hxy : I ⊔ span {x * y + 1} = ⊤,
let ⟨p, hpi, q, hq, hpq⟩ := submodule.mem_sup.1 ((eq_top_iff_one _).1 hxy) in
let ⟨r, hr⟩ := mem_span_singleton.1 hq in
⟨r, by rw [← one_mul r, ← mul_assoc, ← add_mul, mul_one, ← hr, ← hpq, ← neg_sub, add_sub_cancel]; exact I.neg_mem hpi⟩)
(assume hxy : I ⊔ span {x * y + 1} ≠ ⊤,
let ⟨M, hm1, hm2⟩ := exists_le_maximal _ hxy in
suffices x ∉ M, from (this $ mem_Inf.1 hx ⟨le_trans le_sup_left hm2, hm1⟩).elim,
λ hxm, hm1.1 $ (eq_top_iff_one _).2 $ add_sub_cancel' (x * y) 1 ▸ M.sub_mem
(le_trans le_sup_right hm2 $ mem_span_singleton.2 $ dvd_refl _)
(M.mul_mem_right hxm)),
λ hx, mem_Inf.2 $ λ M ⟨him, hm⟩, classical.by_contradiction $ λ hxm,
let ⟨y, hy⟩ := hm.exists_inv hxm, ⟨z, hz⟩ := hx (-y) in
hm.1 $ (eq_top_iff_one _).2 $ sub_sub_cancel (x * -y * z + z) 1 ▸ M.sub_mem
(by rw [← one_mul z, ← mul_assoc, ← add_mul, mul_one, mul_neg_eq_neg_mul_symm, neg_add_eq_sub, ← neg_sub,
neg_mul_eq_neg_mul_symm, neg_mul_eq_mul_neg, mul_comm x y]; exact M.mul_mem_right hy)
(him hz)⟩
end jacobson
section is_local
variables {R : Type u} [comm_ring R]
/-- An ideal `I` is local iff its Jacobson radical is maximal. -/
@[class] def is_local (I : ideal R) : Prop :=
is_maximal (jacobson I)
theorem is_local_of_is_maximal_radical {I : ideal R} (hi : is_maximal (radical I)) : is_local I :=
have radical I = jacobson I,
from le_antisymm (le_Inf $ λ M ⟨him, hm⟩, hm.is_prime.radical_le_iff.2 him)
(Inf_le ⟨le_radical, hi⟩),
show is_maximal (jacobson I), from this ▸ hi
theorem is_local.le_jacobson {I J : ideal R} (hi : is_local I) (hij : I ≤ J) (hj : J ≠ ⊤) : J ≤ jacobson I :=
let ⟨M, hm, hjm⟩ := exists_le_maximal J hj in
le_trans hjm $ le_of_eq $ eq.symm $ hi.eq_of_le hm.1 $ Inf_le ⟨le_trans hij hjm, hm⟩
theorem is_local.mem_jacobson_or_exists_inv {I : ideal R} (hi : is_local I) (x : R) :
x ∈ jacobson I ∨ ∃ y, y * x - 1 ∈ I :=
classical.by_cases
(assume h : I ⊔ span {x} = ⊤,
let ⟨p, hpi, q, hq, hpq⟩ := submodule.mem_sup.1 ((eq_top_iff_one _).1 h) in
let ⟨r, hr⟩ := mem_span_singleton.1 hq in
or.inr ⟨r, by rw [← hpq, mul_comm, ← hr, ← neg_sub, add_sub_cancel]; exact I.neg_mem hpi⟩)
(assume h : I ⊔ span {x} ≠ ⊤,
or.inl $ le_trans le_sup_right (hi.le_jacobson le_sup_left h) $ mem_span_singleton.2 $ dvd_refl x)
end is_local
section is_primary
variables {R : Type u} [comm_ring R]
/-- A proper ideal `I` is primary iff `xy ∈ I` implies `x ∈ I` or `y ∈ radical I`. -/
def is_primary (I : ideal R) : Prop :=
I ≠ ⊤ ∧ ∀ {x y : R}, x * y ∈ I → x ∈ I ∨ y ∈ radical I
theorem is_primary.to_is_prime (I : ideal R) (hi : is_prime I) : is_primary I :=
⟨hi.1, λ x y hxy, (hi.2 hxy).imp id $ λ hyi, le_radical hyi⟩
theorem mem_radical_of_pow_mem {I : ideal R} {x : R} {m : ℕ} (hx : x ^ m ∈ radical I) : x ∈ radical I :=
radical_idem I ▸ ⟨m, hx⟩
theorem is_prime_radical {I : ideal R} (hi : is_primary I) : is_prime (radical I) :=
⟨mt radical_eq_top.1 hi.1, λ x y ⟨m, hxy⟩, begin
rw mul_pow at hxy, cases hi.2 hxy,
{ exact or.inl ⟨m, h⟩ },
{ exact or.inr (mem_radical_of_pow_mem h) }
end⟩
theorem is_primary_inf {I J : ideal R} (hi : is_primary I) (hj : is_primary J)
(hij : radical I = radical J) : is_primary (I ⊓ J) :=
⟨ne_of_lt $ lt_of_le_of_lt inf_le_left (lt_top_iff_ne_top.2 hi.1), λ x y ⟨hxyi, hxyj⟩,
begin
rw [radical_inf, hij, inf_idem],
cases hi.2 hxyi with hxi hyi, cases hj.2 hxyj with hxj hyj,
{ exact or.inl ⟨hxi, hxj⟩ },
{ exact or.inr hyj },
{ rw hij at hyi, exact or.inr hyi }
end⟩
theorem is_primary_of_is_maximal_radical {I : ideal R} (hi : is_maximal (radical I)) : is_primary I :=
have radical I = jacobson I,
from le_antisymm (le_Inf $ λ M ⟨him, hm⟩, hm.is_prime.radical_le_iff.2 him)
(Inf_le ⟨le_radical, hi⟩),
⟨ne_top_of_lt $ lt_of_le_of_lt le_radical (lt_top_iff_ne_top.2 hi.1),
λ x y hxy, ((is_local_of_is_maximal_radical hi).mem_jacobson_or_exists_inv y).symm.imp
(λ ⟨z, hz⟩, by rw [← mul_one x, ← sub_sub_cancel (z * y) 1, mul_sub, mul_left_comm]; exact
I.sub_mem (I.mul_mem_left hxy) (I.mul_mem_left hz))
(this ▸ id)⟩
end is_primary
end ideal
namespace ring_hom
variables {R : Type u} {S : Type v} [comm_ring R]
section comm_ring
variables [comm_ring S] (f : R →+* S)
/-- Kernel of a ring homomorphism as an ideal of the domain. -/
def ker : ideal R := ideal.comap f ⊥
/-- An element is in the kernel if and only if it maps to zero.-/
lemma mem_ker {r} : r ∈ ker f ↔ f r = 0 :=
by rw [ker, ideal.mem_comap, submodule.mem_bot]
lemma ker_eq : ((ker f) : set R) = is_add_group_hom.ker f := rfl
lemma inj_iff_ker_eq_bot : function.injective f ↔ ker f = ⊥ :=
by rw [←submodule.ext'_iff, ker_eq]; exact is_add_group_hom.inj_iff_trivial_ker f
lemma ker_eq_bot_iff_eq_zero : ker f = ⊥ ↔ ∀ x, f x = 0 → x = 0 :=
by rw [←submodule.ext'_iff, ker_eq]; exact is_add_group_hom.trivial_ker_iff_eq_zero f
/-- If the target is not the zero ring, then one is not in the kernel.-/
lemma not_one_mem_ker [nonzero S] (f : R →+* S) : (1:R) ∉ ker f :=
by { rw [mem_ker, f.map_one], exact one_ne_zero }
end comm_ring
/-- The kernel of a homomorphism to an integral domain is a prime ideal.-/
lemma ker_is_prime [integral_domain S] (f : R →+* S) :
(ker f).is_prime :=
⟨by { rw [ne.def, ideal.eq_top_iff_one], exact not_one_mem_ker f },
λ x y, by simpa only [mem_ker, f.map_mul] using @eq_zero_or_eq_zero_of_mul_eq_zero S _ _ _ _ _⟩
end ring_hom
namespace ideal
variables {R : Type*} {S : Type*} [comm_ring R] [comm_ring S]
lemma map_eq_bot_iff_le_ker {I : ideal R} (f : R →+* S) : I.map f = ⊥ ↔ I ≤ f.ker :=
by rw [ring_hom.ker, eq_bot_iff, map_le_iff_le_comap]
end ideal
namespace submodule
variables {R : Type u} {M : Type v}
variables [comm_ring R] [add_comm_group M] [module R M]
-- It is even a semialgebra. But those aren't in mathlib yet.
instance semimodule_submodule : semimodule (ideal R) (submodule R M) :=
{ smul_add := smul_sup,
add_smul := sup_smul,
mul_smul := smul_assoc,
one_smul := by simp,
zero_smul := bot_smul,
smul_zero := smul_bot }
end submodule
|
f59badb33c287eeb0847b26df7925477970db3a2 | c777c32c8e484e195053731103c5e52af26a25d1 | /src/analysis/inner_product_space/gram_schmidt_ortho.lean | a46b0f5b0a442edcdf0994f3cd116416b4f69a20 | [
"Apache-2.0"
] | permissive | kbuzzard/mathlib | 2ff9e85dfe2a46f4b291927f983afec17e946eb8 | 58537299e922f9c77df76cb613910914a479c1f7 | refs/heads/master | 1,685,313,702,744 | 1,683,974,212,000 | 1,683,974,212,000 | 128,185,277 | 1 | 0 | null | 1,522,920,600,000 | 1,522,920,600,000 | null | UTF-8 | Lean | false | false | 17,560 | lean | /-
Copyright (c) 2022 Jiale Miao. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jiale Miao, Kevin Buzzard, Alexander Bentkamp
-/
import analysis.inner_product_space.pi_L2
import linear_algebra.matrix.block
/-!
# Gram-Schmidt Orthogonalization and Orthonormalization
In this file we introduce Gram-Schmidt Orthogonalization and Orthonormalization.
The Gram-Schmidt process takes a set of vectors as input
and outputs a set of orthogonal vectors which have the same span.
## Main results
- `gram_schmidt` : the Gram-Schmidt process
- `gram_schmidt_orthogonal` :
`gram_schmidt` produces an orthogonal system of vectors.
- `span_gram_schmidt` :
`gram_schmidt` preserves span of vectors.
- `gram_schmidt_ne_zero` :
If the input vectors of `gram_schmidt` are linearly independent,
then the output vectors are non-zero.
- `gram_schmidt_basis` :
The basis produced by the Gram-Schmidt process when given a basis as input.
- `gram_schmidt_normed` :
the normalized `gram_schmidt` (i.e each vector in `gram_schmidt_normed` has unit length.)
- `gram_schmidt_orthornormal` :
`gram_schmidt_normed` produces an orthornormal system of vectors.
- `gram_schmidt_orthonormal_basis`: orthonormal basis constructed by the Gram-Schmidt process from
an indexed set of vectors of the right size
-/
open_locale big_operators
open finset submodule finite_dimensional
variables (𝕜 : Type*) {E : Type*} [is_R_or_C 𝕜] [normed_add_comm_group E] [inner_product_space 𝕜 E]
variables {ι : Type*} [linear_order ι] [locally_finite_order_bot ι] [is_well_order ι (<)]
local attribute [instance] is_well_order.to_has_well_founded
local notation `⟪`x`, `y`⟫` := @inner 𝕜 _ _ x y
/-- The Gram-Schmidt process takes a set of vectors as input
and outputs a set of orthogonal vectors which have the same span. -/
noncomputable def gram_schmidt (f : ι → E) : ι → E
| n := f n - ∑ i : Iio n, orthogonal_projection (𝕜 ∙ gram_schmidt i) (f n)
using_well_founded { dec_tac := `[exact mem_Iio.1 i.2] }
/-- This lemma uses `∑ i in` instead of `∑ i :`.-/
lemma gram_schmidt_def (f : ι → E) (n : ι):
gram_schmidt 𝕜 f n = f n - ∑ i in Iio n,
orthogonal_projection (𝕜 ∙ gram_schmidt 𝕜 f i) (f n) :=
by { rw [←sum_attach, attach_eq_univ, gram_schmidt], refl }
lemma gram_schmidt_def' (f : ι → E) (n : ι):
f n = gram_schmidt 𝕜 f n + ∑ i in Iio n,
orthogonal_projection (𝕜 ∙ gram_schmidt 𝕜 f i) (f n) :=
by rw [gram_schmidt_def, sub_add_cancel]
lemma gram_schmidt_def'' (f : ι → E) (n : ι):
f n = gram_schmidt 𝕜 f n
+ ∑ i in Iio n, (⟪gram_schmidt 𝕜 f i, f n⟫ / ‖gram_schmidt 𝕜 f i‖ ^ 2) • gram_schmidt 𝕜 f i :=
begin
convert gram_schmidt_def' 𝕜 f n,
ext i,
rw orthogonal_projection_singleton,
end
@[simp] lemma gram_schmidt_zero {ι : Type*} [linear_order ι] [locally_finite_order ι]
[order_bot ι] [is_well_order ι (<)] (f : ι → E) : gram_schmidt 𝕜 f ⊥ = f ⊥ :=
by rw [gram_schmidt_def, Iio_eq_Ico, finset.Ico_self, finset.sum_empty, sub_zero]
/-- **Gram-Schmidt Orthogonalisation**:
`gram_schmidt` produces an orthogonal system of vectors. -/
theorem gram_schmidt_orthogonal (f : ι → E) {a b : ι} (h₀ : a ≠ b) :
⟪gram_schmidt 𝕜 f a, gram_schmidt 𝕜 f b⟫ = 0 :=
begin
suffices : ∀ a b : ι, a < b → ⟪gram_schmidt 𝕜 f a, gram_schmidt 𝕜 f b⟫ = 0,
{ cases h₀.lt_or_lt with ha hb,
{ exact this _ _ ha, },
{ rw inner_eq_zero_symm,
exact this _ _ hb, }, },
clear h₀ a b,
intros a b h₀,
revert a,
apply well_founded.induction (@is_well_founded.wf ι (<) _) b,
intros b ih a h₀,
simp only [gram_schmidt_def 𝕜 f b, inner_sub_right, inner_sum,
orthogonal_projection_singleton, inner_smul_right],
rw finset.sum_eq_single_of_mem a (finset.mem_Iio.mpr h₀),
{ by_cases h : gram_schmidt 𝕜 f a = 0,
{ simp only [h, inner_zero_left, zero_div, zero_mul, sub_zero], },
{ rw [← inner_self_eq_norm_sq_to_K, div_mul_cancel, sub_self],
rwa [inner_self_ne_zero], }, },
simp_intros i hi hia only [finset.mem_range],
simp only [mul_eq_zero, div_eq_zero_iff, inner_self_eq_zero],
right,
cases hia.lt_or_lt with hia₁ hia₂,
{ rw inner_eq_zero_symm,
exact ih a h₀ i hia₁ },
{ exact ih i (mem_Iio.1 hi) a hia₂ }
end
/-- This is another version of `gram_schmidt_orthogonal` using `pairwise` instead. -/
theorem gram_schmidt_pairwise_orthogonal (f : ι → E) :
pairwise (λ a b, ⟪gram_schmidt 𝕜 f a, gram_schmidt 𝕜 f b⟫ = 0) :=
λ a b, gram_schmidt_orthogonal 𝕜 f
lemma gram_schmidt_inv_triangular (v : ι → E) {i j : ι} (hij : i < j) :
⟪gram_schmidt 𝕜 v j, v i⟫ = 0 :=
begin
rw gram_schmidt_def'' 𝕜 v,
simp only [inner_add_right, inner_sum, inner_smul_right],
set b : ι → E := gram_schmidt 𝕜 v,
convert zero_add (0:𝕜),
{ exact gram_schmidt_orthogonal 𝕜 v hij.ne' },
apply finset.sum_eq_zero,
rintros k hki',
have hki : k < i := by simpa using hki',
have : ⟪b j, b k⟫ = 0 := gram_schmidt_orthogonal 𝕜 v (hki.trans hij).ne',
simp [this],
end
open submodule set order
lemma mem_span_gram_schmidt (f : ι → E) {i j : ι} (hij : i ≤ j) :
f i ∈ span 𝕜 (gram_schmidt 𝕜 f '' Iic j) :=
begin
rw [gram_schmidt_def' 𝕜 f i],
simp_rw orthogonal_projection_singleton,
exact submodule.add_mem _ (subset_span $ mem_image_of_mem _ hij)
(submodule.sum_mem _ $ λ k hk, smul_mem (span 𝕜 (gram_schmidt 𝕜 f '' Iic j)) _ $
subset_span $ mem_image_of_mem (gram_schmidt 𝕜 f) $ (finset.mem_Iio.1 hk).le.trans hij),
end
lemma gram_schmidt_mem_span (f : ι → E) :
∀ {j i}, i ≤ j → gram_schmidt 𝕜 f i ∈ span 𝕜 (f '' Iic j)
| j := λ i hij,
begin
rw [gram_schmidt_def 𝕜 f i],
simp_rw orthogonal_projection_singleton,
refine submodule.sub_mem _ (subset_span (mem_image_of_mem _ hij))
(submodule.sum_mem _ $ λ k hk, _),
let hkj : k < j := (finset.mem_Iio.1 hk).trans_le hij,
exact smul_mem _ _ (span_mono (image_subset f $ Iic_subset_Iic.2 hkj.le) $
gram_schmidt_mem_span le_rfl),
end
using_well_founded { dec_tac := `[assumption] }
lemma span_gram_schmidt_Iic (f : ι → E) (c : ι) :
span 𝕜 (gram_schmidt 𝕜 f '' Iic c) = span 𝕜 (f '' Iic c) :=
span_eq_span (set.image_subset_iff.2 $ λ i, gram_schmidt_mem_span _ _) $
set.image_subset_iff.2 $ λ i, mem_span_gram_schmidt _ _
lemma span_gram_schmidt_Iio (f : ι → E) (c : ι) :
span 𝕜 (gram_schmidt 𝕜 f '' Iio c) = span 𝕜 (f '' Iio c) :=
span_eq_span
(set.image_subset_iff.2 $ λ i hi, span_mono (image_subset _ $ Iic_subset_Iio.2 hi) $
gram_schmidt_mem_span _ _ le_rfl) $
set.image_subset_iff.2 $ λ i hi, span_mono (image_subset _ $ Iic_subset_Iio.2 hi) $
mem_span_gram_schmidt _ _ le_rfl
/-- `gram_schmidt` preserves span of vectors. -/
lemma span_gram_schmidt (f : ι → E) : span 𝕜 (range (gram_schmidt 𝕜 f)) = span 𝕜 (range f) :=
span_eq_span (range_subset_iff.2 $ λ i, span_mono (image_subset_range _ _) $
gram_schmidt_mem_span _ _ le_rfl) $
range_subset_iff.2 $ λ i, span_mono (image_subset_range _ _) $ mem_span_gram_schmidt _ _ le_rfl
lemma gram_schmidt_of_orthogonal {f : ι → E} (hf : pairwise (λ i j, ⟪f i, f j⟫ = 0)) :
gram_schmidt 𝕜 f = f :=
begin
ext i,
rw gram_schmidt_def,
transitivity f i - 0,
{ congr,
apply finset.sum_eq_zero,
intros j hj,
rw coe_eq_zero,
suffices : span 𝕜 (f '' set.Iic j) ⟂ 𝕜 ∙ f i,
{ apply orthogonal_projection_mem_subspace_orthogonal_complement_eq_zero,
rw mem_orthogonal_singleton_iff_inner_left,
rw ←mem_orthogonal_singleton_iff_inner_right,
exact this (gram_schmidt_mem_span 𝕜 f (le_refl j)) },
rw is_ortho_span,
rintros u ⟨k, hk, rfl⟩ v (rfl : v = f i),
apply hf,
exact (lt_of_le_of_lt hk (finset.mem_Iio.mp hj)).ne },
{ simp },
end
variables {𝕜}
lemma gram_schmidt_ne_zero_coe
{f : ι → E} (n : ι) (h₀ : linear_independent 𝕜 (f ∘ (coe : set.Iic n → ι))) :
gram_schmidt 𝕜 f n ≠ 0 :=
begin
by_contra h,
have h₁ : f n ∈ span 𝕜 (f '' Iio n),
{ rw [← span_gram_schmidt_Iio 𝕜 f n, gram_schmidt_def' _ f, h, zero_add],
apply submodule.sum_mem _ _,
simp_intros a ha only [finset.mem_Ico],
simp only [set.mem_image, set.mem_Iio, orthogonal_projection_singleton],
apply submodule.smul_mem _ _ _,
rw finset.mem_Iio at ha,
refine subset_span ⟨a, ha, by refl⟩ },
have h₂ : (f ∘ (coe : set.Iic n → ι)) ⟨n, le_refl n⟩
∈ span 𝕜 (f ∘ (coe : set.Iic n → ι) '' Iio ⟨n, le_refl n⟩),
{ rw [image_comp],
convert h₁ using 3,
ext i,
simpa using @le_of_lt _ _ i n },
apply linear_independent.not_mem_span_image h₀ _ h₂,
simp only [set.mem_Iio, lt_self_iff_false, not_false_iff]
end
/-- If the input vectors of `gram_schmidt` are linearly independent,
then the output vectors are non-zero. -/
lemma gram_schmidt_ne_zero {f : ι → E} (n : ι) (h₀ : linear_independent 𝕜 f) :
gram_schmidt 𝕜 f n ≠ 0 :=
gram_schmidt_ne_zero_coe _ (linear_independent.comp h₀ _ subtype.coe_injective)
/-- `gram_schmidt` produces a triangular matrix of vectors when given a basis. -/
lemma gram_schmidt_triangular {i j : ι} (hij : i < j) (b : basis ι 𝕜 E) :
b.repr (gram_schmidt 𝕜 b i) j = 0 :=
begin
have : gram_schmidt 𝕜 b i ∈ span 𝕜 (gram_schmidt 𝕜 b '' set.Iio j),
from subset_span ((set.mem_image _ _ _).2 ⟨i, hij, rfl⟩),
have : gram_schmidt 𝕜 b i ∈ span 𝕜 (b '' set.Iio j),
by rwa [← span_gram_schmidt_Iio 𝕜 b j],
have : ↑(((b.repr) (gram_schmidt 𝕜 b i)).support) ⊆ set.Iio j,
from basis.repr_support_subset_of_mem_span b (set.Iio j) this,
exact (finsupp.mem_supported' _ _).1
((finsupp.mem_supported 𝕜 _).2 this) j set.not_mem_Iio_self,
end
/-- `gram_schmidt` produces linearly independent vectors when given linearly independent vectors. -/
lemma gram_schmidt_linear_independent {f : ι → E} (h₀ : linear_independent 𝕜 f) :
linear_independent 𝕜 (gram_schmidt 𝕜 f) :=
linear_independent_of_ne_zero_of_inner_eq_zero
(λ i, gram_schmidt_ne_zero _ h₀) (λ i j, gram_schmidt_orthogonal 𝕜 f)
/-- When given a basis, `gram_schmidt` produces a basis. -/
noncomputable def gram_schmidt_basis (b : basis ι 𝕜 E) : basis ι 𝕜 E :=
basis.mk
(gram_schmidt_linear_independent b.linear_independent)
((span_gram_schmidt 𝕜 b).trans b.span_eq).ge
lemma coe_gram_schmidt_basis (b : basis ι 𝕜 E) :
(gram_schmidt_basis b : ι → E) = gram_schmidt 𝕜 b := basis.coe_mk _ _
variables (𝕜)
/-- the normalized `gram_schmidt`
(i.e each vector in `gram_schmidt_normed` has unit length.) -/
noncomputable def gram_schmidt_normed (f : ι → E) (n : ι) : E :=
(‖gram_schmidt 𝕜 f n‖ : 𝕜)⁻¹ • (gram_schmidt 𝕜 f n)
variables {𝕜}
lemma gram_schmidt_normed_unit_length_coe
{f : ι → E} (n : ι) (h₀ : linear_independent 𝕜 (f ∘ (coe : set.Iic n → ι))) :
‖gram_schmidt_normed 𝕜 f n‖ = 1 :=
by simp only [gram_schmidt_ne_zero_coe n h₀,
gram_schmidt_normed, norm_smul_inv_norm, ne.def, not_false_iff]
lemma gram_schmidt_normed_unit_length {f : ι → E} (n : ι) (h₀ : linear_independent 𝕜 f) :
‖gram_schmidt_normed 𝕜 f n‖ = 1 :=
gram_schmidt_normed_unit_length_coe _ (linear_independent.comp h₀ _ subtype.coe_injective)
lemma gram_schmidt_normed_unit_length' {f : ι → E} {n : ι} (hn : gram_schmidt_normed 𝕜 f n ≠ 0) :
‖gram_schmidt_normed 𝕜 f n‖ = 1 :=
begin
rw gram_schmidt_normed at *,
rw [norm_smul_inv_norm],
simpa using hn,
end
/-- **Gram-Schmidt Orthonormalization**:
`gram_schmidt_normed` applied to a linearly independent set of vectors produces an orthornormal
system of vectors. -/
theorem gram_schmidt_orthonormal {f : ι → E} (h₀ : linear_independent 𝕜 f) :
orthonormal 𝕜 (gram_schmidt_normed 𝕜 f) :=
begin
unfold orthonormal,
split,
{ simp only [gram_schmidt_normed_unit_length, h₀, eq_self_iff_true, implies_true_iff], },
{ intros i j hij,
simp only [gram_schmidt_normed, inner_smul_left, inner_smul_right, is_R_or_C.conj_inv,
is_R_or_C.conj_of_real, mul_eq_zero, inv_eq_zero, is_R_or_C.of_real_eq_zero, norm_eq_zero],
repeat { right },
exact gram_schmidt_orthogonal 𝕜 f hij }
end
/-- **Gram-Schmidt Orthonormalization**:
`gram_schmidt_normed` produces an orthornormal system of vectors after removing the vectors which
become zero in the process. -/
lemma gram_schmidt_orthonormal' (f : ι → E) :
orthonormal 𝕜 (λ i : {i | gram_schmidt_normed 𝕜 f i ≠ 0}, gram_schmidt_normed 𝕜 f i) :=
begin
refine ⟨λ i, gram_schmidt_normed_unit_length' i.prop, _⟩,
rintros i j (hij : ¬ _),
rw subtype.ext_iff at hij,
simp [gram_schmidt_normed, inner_smul_left, inner_smul_right, gram_schmidt_orthogonal 𝕜 f hij],
end
lemma span_gram_schmidt_normed (f : ι → E) (s : set ι) :
span 𝕜 (gram_schmidt_normed 𝕜 f '' s) = span 𝕜 (gram_schmidt 𝕜 f '' s) :=
begin
refine span_eq_span (set.image_subset_iff.2 $ λ i hi, smul_mem _ _ $ subset_span $
mem_image_of_mem _ hi)
(set.image_subset_iff.2 $ λ i hi, span_mono (image_subset _ $ singleton_subset_set_iff.2 hi) _),
simp only [coe_singleton, set.image_singleton],
by_cases h : gram_schmidt 𝕜 f i = 0,
{ simp [h] },
{ refine mem_span_singleton.2 ⟨‖gram_schmidt 𝕜 f i‖, smul_inv_smul₀ _ _⟩,
exact_mod_cast (norm_ne_zero_iff.2 h) }
end
lemma span_gram_schmidt_normed_range (f : ι → E) :
span 𝕜 (range (gram_schmidt_normed 𝕜 f)) = span 𝕜 (range (gram_schmidt 𝕜 f)) :=
by simpa only [image_univ.symm] using span_gram_schmidt_normed f univ
section orthonormal_basis
variables [fintype ι] [finite_dimensional 𝕜 E] (h : finrank 𝕜 E = fintype.card ι) (f : ι → E)
include h
/-- Given an indexed family `f : ι → E` of vectors in an inner product space `E`, for which the
size of the index set is the dimension of `E`, produce an orthonormal basis for `E` which agrees
with the orthonormal set produced by the Gram-Schmidt orthonormalization process on the elements of
`ι` for which this process gives a nonzero number. -/
noncomputable def gram_schmidt_orthonormal_basis : orthonormal_basis ι 𝕜 E :=
((gram_schmidt_orthonormal' f).exists_orthonormal_basis_extension_of_card_eq h).some
lemma gram_schmidt_orthonormal_basis_apply {f : ι → E} {i : ι}
(hi : gram_schmidt_normed 𝕜 f i ≠ 0) :
gram_schmidt_orthonormal_basis h f i = gram_schmidt_normed 𝕜 f i :=
((gram_schmidt_orthonormal' f).exists_orthonormal_basis_extension_of_card_eq h).some_spec i hi
lemma gram_schmidt_orthonormal_basis_apply_of_orthogonal {f : ι → E}
(hf : pairwise (λ i j, ⟪f i, f j⟫ = 0)) {i : ι} (hi : f i ≠ 0) :
gram_schmidt_orthonormal_basis h f i = (‖f i‖⁻¹ : 𝕜) • f i :=
begin
have H : gram_schmidt_normed 𝕜 f i = (‖f i‖⁻¹ : 𝕜) • f i,
{ rw [gram_schmidt_normed, gram_schmidt_of_orthogonal 𝕜 hf] },
rw [gram_schmidt_orthonormal_basis_apply h, H],
simpa [H] using hi,
end
lemma inner_gram_schmidt_orthonormal_basis_eq_zero {f : ι → E} {i : ι}
(hi : gram_schmidt_normed 𝕜 f i = 0) (j : ι) :
⟪gram_schmidt_orthonormal_basis h f i, f j⟫ = 0 :=
begin
rw ←mem_orthogonal_singleton_iff_inner_right,
suffices : span 𝕜 (gram_schmidt_normed 𝕜 f '' Iic j) ⟂ 𝕜 ∙ gram_schmidt_orthonormal_basis h f i,
{ apply this,
rw span_gram_schmidt_normed,
exact mem_span_gram_schmidt 𝕜 f le_rfl },
rw is_ortho_span,
rintros u ⟨k, hk, rfl⟩ v (rfl : v = _),
by_cases hk : gram_schmidt_normed 𝕜 f k = 0,
{ rw [hk, inner_zero_left] },
rw ← gram_schmidt_orthonormal_basis_apply h hk,
have : k ≠ i,
{ rintros rfl,
exact hk hi },
exact (gram_schmidt_orthonormal_basis h f).orthonormal.2 this,
end
lemma gram_schmidt_orthonormal_basis_inv_triangular {i j : ι} (hij : i < j) :
⟪gram_schmidt_orthonormal_basis h f j, f i⟫ = 0 :=
begin
by_cases hi : gram_schmidt_normed 𝕜 f j = 0,
{ rw inner_gram_schmidt_orthonormal_basis_eq_zero h hi },
{ simp [gram_schmidt_orthonormal_basis_apply h hi, gram_schmidt_normed, inner_smul_left,
gram_schmidt_inv_triangular 𝕜 f hij] }
end
lemma gram_schmidt_orthonormal_basis_inv_triangular' {i j : ι} (hij : i < j) :
(gram_schmidt_orthonormal_basis h f).repr (f i) j = 0 :=
by simpa [orthonormal_basis.repr_apply_apply]
using gram_schmidt_orthonormal_basis_inv_triangular h f hij
/-- Given an indexed family `f : ι → E` of vectors in an inner product space `E`, for which the
size of the index set is the dimension of `E`, the matrix of coefficients of `f` with respect to the
orthonormal basis `gram_schmidt_orthonormal_basis` constructed from `f` is upper-triangular. -/
lemma gram_schmidt_orthonormal_basis_inv_block_triangular :
((gram_schmidt_orthonormal_basis h f).to_basis.to_matrix f).block_triangular id :=
λ i j, gram_schmidt_orthonormal_basis_inv_triangular' h f
lemma gram_schmidt_orthonormal_basis_det :
(gram_schmidt_orthonormal_basis h f).to_basis.det f =
∏ i, ⟪gram_schmidt_orthonormal_basis h f i, f i⟫ :=
begin
convert matrix.det_of_upper_triangular (gram_schmidt_orthonormal_basis_inv_block_triangular h f),
ext i,
exact ((gram_schmidt_orthonormal_basis h f).repr_apply_apply (f i) i).symm,
end
end orthonormal_basis
|
1938b9c7aa9a727ebf047d68206e135ca0968dac | bb31430994044506fa42fd667e2d556327e18dfe | /src/analysis/locally_convex/balanced_core_hull.lean | f7c65b6274326abb0fdad4c9ee2bca209e3da9e4 | [
"Apache-2.0"
] | permissive | sgouezel/mathlib | 0cb4e5335a2ba189fa7af96d83a377f83270e503 | 00638177efd1b2534fc5269363ebf42a7871df9a | refs/heads/master | 1,674,527,483,042 | 1,673,665,568,000 | 1,673,665,568,000 | 119,598,202 | 0 | 0 | null | 1,517,348,647,000 | 1,517,348,646,000 | null | UTF-8 | Lean | false | false | 9,630 | lean | /-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import analysis.locally_convex.basic
/-!
# Balanced Core and Balanced Hull
## Main definitions
* `balanced_core`: The largest balanced subset of a set `s`.
* `balanced_hull`: The smallest balanced superset of a set `s`.
## Main statements
* `balanced_core_eq_Inter`: Characterization of the balanced core as an intersection over subsets.
* `nhds_basis_closed_balanced`: The closed balanced sets form a basis of the neighborhood filter.
## Implementation details
The balanced core and hull are implemented differently: for the core we take the obvious definition
of the union over all balanced sets that are contained in `s`, whereas for the hull, we take the
union over `r • s`, for `r` the scalars with `‖r‖ ≤ 1`. We show that `balanced_hull` has the
defining properties of a hull in `balanced.hull_minimal` and `subset_balanced_hull`.
For the core we need slightly stronger assumptions to obtain a characterization as an intersection,
this is `balanced_core_eq_Inter`.
## References
* [Bourbaki, *Topological Vector Spaces*][bourbaki1987]
## Tags
balanced
-/
open set
open_locale pointwise topological_space filter
variables {𝕜 E ι : Type*}
section balanced_hull
section semi_normed_ring
variables [semi_normed_ring 𝕜]
section has_smul
variables (𝕜) [has_smul 𝕜 E] {s t : set E} {x : E}
/-- The largest balanced subset of `s`.-/
def balanced_core (s : set E) := ⋃₀ {t : set E | balanced 𝕜 t ∧ t ⊆ s}
/-- Helper definition to prove `balanced_core_eq_Inter`-/
def balanced_core_aux (s : set E) := ⋂ (r : 𝕜) (hr : 1 ≤ ‖r‖), r • s
/-- The smallest balanced superset of `s`.-/
def balanced_hull (s : set E) := ⋃ (r : 𝕜) (hr : ‖r‖ ≤ 1), r • s
variables {𝕜}
lemma balanced_core_subset (s : set E) : balanced_core 𝕜 s ⊆ s := sUnion_subset $ λ t ht, ht.2
lemma balanced_core_empty : balanced_core 𝕜 (∅ : set E) = ∅ :=
eq_empty_of_subset_empty (balanced_core_subset _)
lemma mem_balanced_core_iff : x ∈ balanced_core 𝕜 s ↔ ∃ t, balanced 𝕜 t ∧ t ⊆ s ∧ x ∈ t :=
by simp_rw [balanced_core, mem_sUnion, mem_set_of_eq, exists_prop, and_assoc]
lemma smul_balanced_core_subset (s : set E) {a : 𝕜} (ha : ‖a‖ ≤ 1) :
a • balanced_core 𝕜 s ⊆ balanced_core 𝕜 s :=
begin
rintro x ⟨y, hy, rfl⟩,
rw mem_balanced_core_iff at hy,
rcases hy with ⟨t, ht1, ht2, hy⟩,
exact ⟨t, ⟨ht1, ht2⟩, ht1 a ha (smul_mem_smul_set hy)⟩,
end
lemma balanced_core_balanced (s : set E) : balanced 𝕜 (balanced_core 𝕜 s) :=
λ _, smul_balanced_core_subset s
/-- The balanced core of `t` is maximal in the sense that it contains any balanced subset
`s` of `t`.-/
lemma balanced.subset_core_of_subset (hs : balanced 𝕜 s) (h : s ⊆ t) : s ⊆ balanced_core 𝕜 t :=
subset_sUnion_of_mem ⟨hs, h⟩
lemma mem_balanced_core_aux_iff : x ∈ balanced_core_aux 𝕜 s ↔ ∀ r : 𝕜, 1 ≤ ‖r‖ → x ∈ r • s :=
mem_Inter₂
lemma mem_balanced_hull_iff : x ∈ balanced_hull 𝕜 s ↔ ∃ (r : 𝕜) (hr : ‖r‖ ≤ 1), x ∈ r • s :=
mem_Union₂
/-- The balanced hull of `s` is minimal in the sense that it is contained in any balanced superset
`t` of `s`. -/
lemma balanced.hull_subset_of_subset (ht : balanced 𝕜 t) (h : s ⊆ t) : balanced_hull 𝕜 s ⊆ t :=
λ x hx, by { obtain ⟨r, hr, y, hy, rfl⟩ := mem_balanced_hull_iff.1 hx, exact ht.smul_mem hr (h hy) }
end has_smul
section module
variables [add_comm_group E] [module 𝕜 E] {s : set E}
lemma balanced_core_zero_mem (hs : (0 : E) ∈ s) : (0 : E) ∈ balanced_core 𝕜 s :=
mem_balanced_core_iff.2 ⟨0, balanced_zero, zero_subset.2 hs, zero_mem_zero⟩
lemma balanced_core_nonempty_iff : (balanced_core 𝕜 s).nonempty ↔ (0 : E) ∈ s :=
⟨λ h, zero_subset.1 $ (zero_smul_set h).superset.trans $ (balanced_core_balanced s (0 : 𝕜) $
norm_zero.trans_le zero_le_one).trans $ balanced_core_subset _,
λ h, ⟨0, balanced_core_zero_mem h⟩⟩
variables (𝕜)
lemma subset_balanced_hull [norm_one_class 𝕜] {s : set E} : s ⊆ balanced_hull 𝕜 s :=
λ _ hx, mem_balanced_hull_iff.2 ⟨1, norm_one.le, _, hx, one_smul _ _⟩
variables {𝕜}
lemma balanced_hull.balanced (s : set E) : balanced 𝕜 (balanced_hull 𝕜 s) :=
begin
intros a ha,
simp_rw [balanced_hull, smul_set_Union₂, subset_def, mem_Union₂],
rintro x ⟨r, hr, hx⟩,
rw ←smul_assoc at hx,
exact ⟨a • r, (semi_normed_ring.norm_mul _ _).trans (mul_le_one ha (norm_nonneg r) hr), hx⟩,
end
end module
end semi_normed_ring
section normed_field
variables [normed_field 𝕜] [add_comm_group E] [module 𝕜 E] {s t : set E}
@[simp] lemma balanced_core_aux_empty : balanced_core_aux 𝕜 (∅ : set E) = ∅ :=
begin
simp_rw [balanced_core_aux, Inter₂_eq_empty_iff, smul_set_empty],
exact λ _, ⟨1, norm_one.ge, not_mem_empty _⟩,
end
lemma balanced_core_aux_subset (s : set E) : balanced_core_aux 𝕜 s ⊆ s :=
λ x hx, by simpa only [one_smul] using mem_balanced_core_aux_iff.1 hx 1 norm_one.ge
lemma balanced_core_aux_balanced (h0 : (0 : E) ∈ balanced_core_aux 𝕜 s):
balanced 𝕜 (balanced_core_aux 𝕜 s) :=
begin
rintro a ha x ⟨y, hy, rfl⟩,
obtain rfl | h := eq_or_ne a 0,
{ rwa zero_smul },
rw mem_balanced_core_aux_iff at ⊢ hy,
intros r hr,
have h'' : 1 ≤ ‖a⁻¹ • r‖,
{ rw [norm_smul, norm_inv],
exact one_le_mul_of_one_le_of_one_le (one_le_inv (norm_pos_iff.mpr h) ha) hr },
have h' := hy (a⁻¹ • r) h'',
rwa [smul_assoc, mem_inv_smul_set_iff₀ h] at h',
end
lemma balanced_core_aux_maximal (h : t ⊆ s) (ht : balanced 𝕜 t) : t ⊆ balanced_core_aux 𝕜 s :=
begin
refine λ x hx, mem_balanced_core_aux_iff.2 (λ r hr, _),
rw mem_smul_set_iff_inv_smul_mem₀ (norm_pos_iff.mp $ zero_lt_one.trans_le hr),
refine h (ht.smul_mem _ hx),
rw norm_inv,
exact inv_le_one hr,
end
lemma balanced_core_subset_balanced_core_aux : balanced_core 𝕜 s ⊆ balanced_core_aux 𝕜 s :=
balanced_core_aux_maximal (balanced_core_subset s) (balanced_core_balanced s)
lemma balanced_core_eq_Inter (hs : (0 : E) ∈ s) :
balanced_core 𝕜 s = ⋂ (r : 𝕜) (hr : 1 ≤ ‖r‖), r • s :=
begin
refine balanced_core_subset_balanced_core_aux.antisymm _,
refine (balanced_core_aux_balanced _).subset_core_of_subset (balanced_core_aux_subset s),
exact balanced_core_subset_balanced_core_aux (balanced_core_zero_mem hs),
end
lemma subset_balanced_core (ht : (0 : E) ∈ t) (hst : ∀ (a : 𝕜) (ha : ‖a‖ ≤ 1), a • s ⊆ t) :
s ⊆ balanced_core 𝕜 t :=
begin
rw balanced_core_eq_Inter ht,
refine subset_Inter₂ (λ a ha, _),
rw ←smul_inv_smul₀ (norm_pos_iff.mp $ zero_lt_one.trans_le ha) s,
refine smul_set_mono (hst _ _),
rw [norm_inv],
exact inv_le_one ha,
end
end normed_field
end balanced_hull
/-! ### Topological properties -/
section topology
variables [nontrivially_normed_field 𝕜] [add_comm_group E] [module 𝕜 E] [topological_space E]
[has_continuous_smul 𝕜 E] {U : set E}
protected lemma is_closed.balanced_core (hU : is_closed U) : is_closed (balanced_core 𝕜 U) :=
begin
by_cases h : (0 : E) ∈ U,
{ rw balanced_core_eq_Inter h,
refine is_closed_Inter (λ a, _),
refine is_closed_Inter (λ ha, _),
have ha' := lt_of_lt_of_le zero_lt_one ha,
rw norm_pos_iff at ha',
refine is_closed_map_smul_of_ne_zero ha' U hU },
convert is_closed_empty,
contrapose! h,
exact balanced_core_nonempty_iff.mp (set.nonempty_iff_ne_empty.2 h),
end
lemma balanced_core_mem_nhds_zero (hU : U ∈ 𝓝 (0 : E)) : balanced_core 𝕜 U ∈ 𝓝 (0 : E) :=
begin
-- Getting neighborhoods of the origin for `0 : 𝕜` and `0 : E`
obtain ⟨r, V, hr, hV, hrVU⟩ : ∃ (r : ℝ) (V : set E), 0 < r ∧ V ∈ 𝓝 (0 : E) ∧
∀ (c : 𝕜) (y : E), ‖c‖ < r → y ∈ V → c • y ∈ U,
{ have h : filter.tendsto (λ (x : 𝕜 × E), x.fst • x.snd) (𝓝 (0,0)) (𝓝 0),
from continuous_smul.tendsto' (0, 0) _ (smul_zero _),
simpa only [← prod.exists', ← prod.forall', ← and_imp, ← and.assoc, exists_prop]
using h.basis_left (normed_add_comm_group.nhds_zero_basis_norm_lt.prod_nhds
((𝓝 _).basis_sets)) U hU },
rcases normed_field.exists_norm_lt 𝕜 hr with ⟨y, hy₀, hyr⟩,
rw [norm_pos_iff] at hy₀,
have : y • V ∈ 𝓝 (0 : E) := (set_smul_mem_nhds_zero_iff hy₀).mpr hV,
-- It remains to show that `y • V ⊆ balanced_core 𝕜 U`
refine filter.mem_of_superset this (subset_balanced_core (mem_of_mem_nhds hU) $ λ a ha, _),
rw [smul_smul],
rintro _ ⟨z, hz, rfl⟩,
refine hrVU _ _ _ hz,
rw [norm_mul, ← one_mul r],
exact mul_lt_mul' ha hyr (norm_nonneg y) one_pos
end
variables (𝕜 E)
lemma nhds_basis_balanced : (𝓝 (0 : E)).has_basis
(λ (s : set E), s ∈ 𝓝 (0 : E) ∧ balanced 𝕜 s) id :=
filter.has_basis_self.mpr
(λ s hs, ⟨balanced_core 𝕜 s, balanced_core_mem_nhds_zero hs,
balanced_core_balanced s, balanced_core_subset s⟩)
lemma nhds_basis_closed_balanced [regular_space E] : (𝓝 (0 : E)).has_basis
(λ (s : set E), s ∈ 𝓝 (0 : E) ∧ is_closed s ∧ balanced 𝕜 s) id :=
begin
refine (closed_nhds_basis 0).to_has_basis (λ s hs, _) (λ s hs, ⟨s, ⟨hs.1, hs.2.1⟩, rfl.subset⟩),
refine ⟨balanced_core 𝕜 s, ⟨balanced_core_mem_nhds_zero hs.1, _⟩, balanced_core_subset s⟩,
exact ⟨hs.2.balanced_core, balanced_core_balanced s⟩
end
end topology
|
18b3d09ad922ca87f61f93bea97654d578451546 | 7cef822f3b952965621309e88eadf618da0c8ae9 | /src/ring_theory/algebra.lean | 7dda0a004de8b73a2c4806ded19ddd6c0d9d5a58 | [
"Apache-2.0"
] | permissive | rmitta/mathlib | 8d90aee30b4db2b013e01f62c33f297d7e64a43d | 883d974b608845bad30ae19e27e33c285200bf84 | refs/heads/master | 1,585,776,832,544 | 1,576,874,096,000 | 1,576,874,096,000 | 153,663,165 | 0 | 2 | Apache-2.0 | 1,544,806,490,000 | 1,539,884,365,000 | Lean | UTF-8 | Lean | false | false | 22,511 | lean | /-
Copyright (c) 2018 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau
Algebra over Commutative Ring (under category)
-/
import data.polynomial data.mv_polynomial
import data.complex.basic
import data.matrix.basic
import linear_algebra.tensor_product
import ring_theory.subring
noncomputable theory
universes u v w u₁ v₁
open lattice
open_locale tensor_product
section prio
-- We set this priority to 0 later in this file
set_option default_priority 200 -- see Note [default priority]
/-- The category of R-algebras where R is a commutative
ring is the under category R ↓ CRing. In the categorical
setting we have a forgetful functor R-Alg ⥤ R-Mod.
However here it extends module in order to preserve
definitional equality in certain cases. -/
class algebra (R : Type u) (A : Type v) [comm_ring R] [ring A] extends has_scalar R A :=
(to_fun : R → A) [hom : is_ring_hom to_fun]
(commutes' : ∀ r x, x * to_fun r = to_fun r * x)
(smul_def' : ∀ r x, r • x = to_fun r * x)
end prio
def algebra_map {R : Type u} (A : Type v) [comm_ring R] [ring A] [algebra R A] (x : R) : A :=
algebra.to_fun A x
namespace algebra
variables {R : Type u} {S : Type v} {A : Type w}
variables [comm_ring R] [comm_ring S] [ring A] [algebra R A]
instance : is_ring_hom (algebra_map A : R → A) := algebra.hom _ A
variables (A)
@[simp] lemma map_add (r s : R) : algebra_map A (r + s) = algebra_map A r + algebra_map A s :=
is_ring_hom.map_add _
@[simp] lemma map_neg (r : R) : algebra_map A (-r) = -algebra_map A r :=
is_ring_hom.map_neg _
@[simp] lemma map_sub (r s : R) : algebra_map A (r - s) = algebra_map A r - algebra_map A s :=
is_ring_hom.map_sub _
@[simp] lemma map_mul (r s : R) : algebra_map A (r * s) = algebra_map A r * algebra_map A s :=
is_ring_hom.map_mul _
variables (R)
@[simp] lemma map_zero : algebra_map A (0 : R) = 0 :=
is_ring_hom.map_zero _
@[simp] lemma map_one : algebra_map A (1 : R) = 1 :=
is_ring_hom.map_one _
variables {R A}
/-- Creating an algebra from a morphism in CRing. -/
def of_ring_hom (i : R → S) (hom : is_ring_hom i) : algebra R S :=
{ smul := λ c x, i c * x,
to_fun := i,
commutes' := λ _ _, mul_comm _ _,
smul_def' := λ c x, rfl }
lemma smul_def'' (r : R) (x : A) : r • x = algebra_map A r * x :=
algebra.smul_def' r x
@[priority 200] -- see Note [lower instance priority]
instance to_module : module R A :=
{ one_smul := by simp [smul_def''],
mul_smul := by simp [smul_def'', mul_assoc],
smul_add := by simp [smul_def'', mul_add],
smul_zero := by simp [smul_def''],
add_smul := by simp [smul_def'', add_mul],
zero_smul := by simp [smul_def''] }
-- from now on, we don't want to use the following instance anymore
attribute [instance, priority 0] algebra.to_has_scalar
lemma smul_def (r : R) (x : A) : r • x = algebra_map A r * x :=
algebra.smul_def' r x
theorem commutes (r : R) (x : A) : x * algebra_map A r = algebra_map A r * x :=
algebra.commutes' r x
theorem left_comm (r : R) (x y : A) : x * (algebra_map A r * y) = algebra_map A r * (x * y) :=
by rw [← mul_assoc, commutes, mul_assoc]
@[simp] lemma mul_smul_comm (s : R) (x y : A) :
x * (s • y) = s • (x * y) :=
by rw [smul_def, smul_def, left_comm]
@[simp] lemma smul_mul_assoc (r : R) (x y : A) :
(r • x) * y = r • (x * y) :=
by rw [smul_def, smul_def, mul_assoc]
/-- R[X] is the generator of the category R-Alg. -/
instance polynomial (R : Type u) [comm_ring R] : algebra R (polynomial R) :=
{ to_fun := polynomial.C,
commutes' := λ _ _, mul_comm _ _,
smul_def' := λ c p, (polynomial.C_mul' c p).symm,
.. polynomial.module }
/-- The algebra of multivariate polynomials. -/
instance mv_polynomial (R : Type u) [comm_ring R]
(ι : Type v) : algebra R (mv_polynomial ι R) :=
{ to_fun := mv_polynomial.C,
commutes' := λ _ _, mul_comm _ _,
smul_def' := λ c p, (mv_polynomial.C_mul' c p).symm,
.. mv_polynomial.module }
/-- Creating an algebra from a subring. This is the dual of ring extension. -/
instance of_subring (S : set R) [is_subring S] : algebra S R :=
of_ring_hom subtype.val ⟨rfl, λ _ _, rfl, λ _ _, rfl⟩
variables (R A)
/-- The multiplication in an algebra is a bilinear map. -/
def lmul : A →ₗ A →ₗ A :=
linear_map.mk₂ R (*)
(λ x y z, add_mul x y z)
(λ c x y, by rw [smul_def, smul_def, mul_assoc _ x y])
(λ x y z, mul_add x y z)
(λ c x y, by rw [smul_def, smul_def, left_comm])
def lmul_left (r : A) : A →ₗ A :=
lmul R A r
def lmul_right (r : A) : A →ₗ A :=
(lmul R A).flip r
variables {R A}
@[simp] lemma lmul_apply (p q : A) : lmul R A p q = p * q := rfl
@[simp] lemma lmul_left_apply (p q : A) : lmul_left R A p q = p * q := rfl
@[simp] lemma lmul_right_apply (p q : A) : lmul_right R A p q = q * p := rfl
end algebra
instance module.endomorphism_algebra (R : Type u) (M : Type v)
[comm_ring R] [add_comm_group M] [module R M] : algebra R (M →ₗ[R] M) :=
{ to_fun := (λ r, r • linear_map.id),
hom := by apply is_ring_hom.mk; intros; ext; simp [mul_smul, add_smul],
commutes' := by intros; ext; simp,
smul_def' := by intros; ext; simp }
set_option class.instance_max_depth 40
instance matrix_algebra (n : Type u) (R : Type v)
[fintype n] [decidable_eq n] [comm_ring R] : algebra R (matrix n n R) :=
{ to_fun := (λ r, r • 1),
hom := { map_one := by simp,
map_mul := by { intros, simp [mul_smul], },
map_add := by { intros, simp [add_smul], } },
commutes' := by { intros, simp },
smul_def' := by { intros, simp } }
set_option old_structure_cmd true
/-- Defining the homomorphism in the category R-Alg. -/
structure alg_hom (R : Type u) (A : Type v) (B : Type w)
[comm_ring R] [ring A] [ring B] [algebra R A] [algebra R B] extends ring_hom A B :=
(commutes' : ∀ r : R, to_fun (algebra_map A r) = algebra_map B r)
infixr ` →ₐ `:25 := alg_hom _
notation A ` →ₐ[`:25 R `] ` B := alg_hom R A B
namespace alg_hom
variables {R : Type u} {A : Type v} {B : Type w} {C : Type u₁} {D : Type v₁}
variables {rR : comm_ring R} {rA : ring A} {rB : ring B} {rC : ring C} {rD : ring D}
variables {aA : algebra R A} {aB : algebra R B} {aC : algebra R C} {aD : algebra R D}
include R rR rA rB aA aB
instance : has_coe_to_fun (A →ₐ[R] B) := ⟨_, λ f, f.to_fun⟩
instance : has_coe (A →ₐ[R] B) (A →+* B) := ⟨alg_hom.to_ring_hom⟩
variables (φ : A →ₐ[R] B)
instance : is_ring_hom ⇑φ := ring_hom.is_ring_hom φ.to_ring_hom
@[ext]
theorem ext {φ₁ φ₂ : A →ₐ[R] B} (H : ∀ x, φ₁ x = φ₂ x) : φ₁ = φ₂ :=
by cases φ₁; cases φ₂; congr' 1; ext; apply H
theorem commutes (r : R) : φ (algebra_map A r) = algebra_map B r := φ.commutes' r
@[simp] lemma map_add (r s : A) : φ (r + s) = φ r + φ s :=
is_ring_hom.map_add _
@[simp] lemma map_zero : φ 0 = 0 :=
is_ring_hom.map_zero _
@[simp] lemma map_neg (x) : φ (-x) = -φ x :=
is_ring_hom.map_neg _
@[simp] lemma map_sub (x y) : φ (x - y) = φ x - φ y :=
is_ring_hom.map_sub _
@[simp] lemma map_mul (x y) : φ (x * y) = φ x * φ y :=
is_ring_hom.map_mul _
@[simp] lemma map_one : φ 1 = 1 :=
is_ring_hom.map_one _
/-- R-Alg ⥤ R-Mod -/
def to_linear_map : A →ₗ B :=
{ to_fun := φ,
add := φ.map_add,
smul := λ (c : R) x, by rw [algebra.smul_def, φ.map_mul, φ.commutes c, algebra.smul_def] }
@[simp] lemma to_linear_map_apply (p : A) : φ.to_linear_map p = φ p := rfl
theorem to_linear_map_inj {φ₁ φ₂ : A →ₐ[R] B} (H : φ₁.to_linear_map = φ₂.to_linear_map) : φ₁ = φ₂ :=
ext $ λ x, show φ₁.to_linear_map x = φ₂.to_linear_map x, by rw H
variables (R A)
omit rB aB
variables [rR] [rA] [aA]
protected def id : A →ₐ[R] A :=
{ commutes' := λ _, rfl,
..ring_hom.id A }
variables {R A rR rA aA}
@[simp] lemma id_to_linear_map :
(alg_hom.id R A).to_linear_map = @linear_map.id R A _ _ _ := rfl
@[simp] lemma id_apply (p : A) : alg_hom.id R A p = p := rfl
include rB rC aB aC
def comp (φ₁ : B →ₐ[R] C) (φ₂ : A →ₐ[R] B) : A →ₐ[R] C :=
{ commutes' := λ r : R, by rw [← φ₁.commutes, ← φ₂.commutes]; refl,
.. φ₁.to_ring_hom.comp ↑φ₂ }
@[simp] lemma comp_to_linear_map (f : A →ₐ[R] B) (g : B →ₐ[R] C) :
(g.comp f).to_linear_map = g.to_linear_map.comp f.to_linear_map := rfl
@[simp] lemma comp_apply (φ₁ : B →ₐ[R] C) (φ₂ : A →ₐ[R] B) (p : A) :
φ₁.comp φ₂ p = φ₁ (φ₂ p) := rfl
omit rC aC
@[simp] theorem comp_id : φ.comp (alg_hom.id R A) = φ :=
ext $ λ x, rfl
@[simp] theorem id_comp : (alg_hom.id R B).comp φ = φ :=
ext $ λ x, rfl
include rC aC rD aD
theorem comp_assoc (φ₁ : C →ₐ[R] D) (φ₂ : B →ₐ[R] C) (φ₃ : A →ₐ[R] B) :
(φ₁.comp φ₂).comp φ₃ = φ₁.comp (φ₂.comp φ₃) :=
ext $ λ x, rfl
end alg_hom
namespace algebra
variables (R : Type u) (S : Type v) (A : Type w)
include R S A
/-- `comap R S A` is a type alias for `A`, and has an R-algebra structure defined on it
when `algebra R S` and `algebra S A`. -/
/- This is done to avoid a type class search with meta-variables `algebra R ?m_1` and
`algebra ?m_1 A -/
/- The `nolint` attribute is added because it has unused arguments `R` and `S`, but these are necessary for synthesizing the
appropriate type classes -/
@[nolint] def comap : Type w := A
def comap.to_comap : A → comap R S A := id
def comap.of_comap : comap R S A → A := id
omit R S A
variables [comm_ring R] [comm_ring S] [ring A] [algebra R S] [algebra S A]
instance comap.ring : ring (comap R S A) := _inst_3
instance comap.comm_ring (R : Type u) (S : Type v) (A : Type w)
[comm_ring R] [comm_ring S] [comm_ring A] [algebra R S] [algebra S A] :
comm_ring (comap R S A) := _inst_8
instance comap.module : module S (comap R S A) := show module S A, by apply_instance
instance comap.has_scalar : has_scalar S (comap R S A) := show has_scalar S A, by apply_instance
set_option class.instance_max_depth 40
/-- R ⟶ S induces S-Alg ⥤ R-Alg -/
instance comap.algebra : algebra R (comap R S A) :=
{ smul := λ r x, (algebra_map S r • x : A),
to_fun := (algebra_map A : S → A) ∘ algebra_map S,
hom := by letI : is_ring_hom (algebra_map A) := _inst_5.hom; apply_instance,
commutes' := λ r x, algebra.commutes _ _,
smul_def' := λ _ _, algebra.smul_def _ _ }
def to_comap : S →ₐ[R] comap R S A :=
{ commutes' := λ r, rfl,
..ring_hom.of (algebra_map A : S → A) }
theorem to_comap_apply (x) : to_comap R S A x = (algebra_map A : S → A) x := rfl
end algebra
namespace alg_hom
variables {R : Type u} {S : Type v} {A : Type w} {B : Type u₁}
variables [comm_ring R] [comm_ring S] [ring A] [ring B]
variables [algebra R S] [algebra S A] [algebra S B] (φ : A →ₐ[S] B)
include R
/-- R ⟶ S induces S-Alg ⥤ R-Alg -/
def comap : algebra.comap R S A →ₐ[R] algebra.comap R S B :=
{ commutes' := λ r, φ.commutes (algebra_map S r)
..φ }
end alg_hom
namespace polynomial
variables (R : Type u) (A : Type v)
variables [comm_ring R] [comm_ring A] [algebra R A]
variables (x : A)
/-- A → Hom[R-Alg](R[X],A) -/
def aeval : polynomial R →ₐ[R] A :=
{ commutes' := λ r, eval₂_C _ _,
..ring_hom.of (eval₂ (algebra_map A) x) }
theorem aeval_def (p : polynomial R) : aeval R A x p = eval₂ (algebra_map A) x p := rfl
@[simp] lemma aeval_X : aeval R A x X = x := eval₂_X _ x
@[simp] lemma aeval_C (r : R) : aeval R A x (C r) = algebra_map A r := eval₂_C _ x
instance aeval.is_ring_hom : is_ring_hom (aeval R A x) :=
by apply_instance
theorem eval_unique (φ : polynomial R →ₐ[R] A) (p) :
φ p = eval₂ (algebra_map A) (φ X) p :=
begin
apply polynomial.induction_on p,
{ intro r, rw eval₂_C, exact φ.commutes r },
{ intros f g ih1 ih2,
rw [is_ring_hom.map_add φ, ih1, ih2, eval₂_add] },
{ intros n r ih,
rw [pow_succ', ← mul_assoc, is_ring_hom.map_mul φ, eval₂_mul (algebra_map A : R → A), eval₂_X, ih] }
end
end polynomial
namespace mv_polynomial
variables (R : Type u) (A : Type v)
variables [comm_ring R] [comm_ring A] [algebra R A]
variables (σ : set A)
/-- (ι → A) → Hom[R-Alg](R[ι],A) -/
def aeval : mv_polynomial σ R →ₐ[R] A :=
{ commutes' := λ r, eval₂_C _ _ _
..ring_hom.of (eval₂ (algebra_map A) subtype.val) }
theorem aeval_def (p : mv_polynomial σ R) : aeval R A σ p = eval₂ (algebra_map A) subtype.val p := rfl
@[simp] lemma aeval_X (s : σ) : aeval R A σ (X s) = s := eval₂_X _ _ _
@[simp] lemma aeval_C (r : R) : aeval R A σ (C r) = algebra_map A r := eval₂_C _ _ _
instance aeval.is_ring_hom : is_ring_hom (aeval R A σ) :=
by apply_instance
variables (ι : Type w)
theorem eval_unique (φ : mv_polynomial ι R →ₐ[R] A) (p) :
φ p = eval₂ (algebra_map A) (φ ∘ X) p :=
begin
apply mv_polynomial.induction_on p,
{ intro r, rw eval₂_C, exact φ.commutes r },
{ intros f g ih1 ih2,
rw [is_ring_hom.map_add φ, ih1, ih2, eval₂_add] },
{ intros p j ih,
rw [is_ring_hom.map_mul φ, eval₂_mul, eval₂_X, ih] }
end
end mv_polynomial
namespace rat
instance algebra_rat {α} [field α] [char_zero α] : algebra ℚ α :=
algebra.of_ring_hom rat.cast (by apply_instance)
end rat
namespace complex
instance algebra_over_reals : algebra ℝ ℂ :=
algebra.of_ring_hom coe $ by constructor; intros; simp [one_re]
instance : has_scalar ℝ ℂ := { smul := λ r c, ↑r * c}
end complex
structure subalgebra (R : Type u) (A : Type v)
[comm_ring R] [ring A] [algebra R A] : Type v :=
(carrier : set A) [subring : is_subring carrier]
(range_le' : set.range (algebra_map A : R → A) ≤ carrier)
namespace subalgebra
variables {R : Type u} {A : Type v}
variables [comm_ring R] [ring A] [algebra R A]
include R
instance : has_coe (subalgebra R A) (set A) :=
⟨λ S, S.carrier⟩
lemma range_le (S : subalgebra R A) : set.range (algebra_map A : R → A) ≤ S := S.range_le'
instance : has_mem A (subalgebra R A) :=
⟨λ x S, x ∈ (S : set A)⟩
variables {A}
theorem mem_coe {x : A} {s : subalgebra R A} : x ∈ (s : set A) ↔ x ∈ s :=
iff.rfl
@[ext] theorem ext {S T : subalgebra R A}
(h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=
by cases S; cases T; congr; ext x; exact h x
variables (S : subalgebra R A)
instance : is_subring (S : set A) := S.subring
instance : ring S := @@subtype.ring _ S.is_subring
instance (R : Type u) (A : Type v) {rR : comm_ring R} [comm_ring A]
{aA : algebra R A} (S : subalgebra R A) : comm_ring S := @@subtype.comm_ring _ S.is_subring
instance algebra : algebra R S :=
{ smul := λ (c:R) x, ⟨c • x.1,
by rw algebra.smul_def; exact @@is_submonoid.mul_mem _ S.2.2 (S.3 ⟨c, rfl⟩) x.2⟩,
to_fun := λ r, ⟨algebra_map A r, S.range_le ⟨r, rfl⟩⟩,
hom := ⟨subtype.eq $ algebra.map_one R A, λ x y, subtype.eq $ algebra.map_mul A x y,
λ x y, subtype.eq $ algebra.map_add A x y⟩,
commutes' := λ c x, subtype.eq $ by apply _inst_3.4,
smul_def' := λ c x, subtype.eq $ by apply _inst_3.5 }
instance to_algebra (R : Type u) (A : Type v) [comm_ring R] [comm_ring A]
[algebra R A] (S : subalgebra R A) : algebra S A :=
algebra.of_subring _
def val : S →ₐ[R] A :=
by refine_struct { to_fun := subtype.val }; intros; refl
def to_submodule : submodule R A :=
{ carrier := S,
zero := (0:S).2,
add := λ x y hx hy, (⟨x, hx⟩ + ⟨y, hy⟩ : S).2,
smul := λ c x hx, (algebra.smul_def c x).symm ▸ (⟨algebra_map A c, S.range_le ⟨c, rfl⟩⟩ * ⟨x, hx⟩:S).2 }
instance coe_to_submodule : has_coe (subalgebra R A) (submodule R A) :=
⟨to_submodule⟩
instance to_submodule.is_subring : is_subring ((S : submodule R A) : set A) := S.2
instance : partial_order (subalgebra R A) :=
{ le := λ S T, (S : set A) ≤ (T : set A),
le_refl := λ _, le_refl _,
le_trans := λ _ _ _, le_trans,
le_antisymm := λ S T hst hts, ext $ λ x, ⟨@hst x, @hts x⟩ }
def comap {R : Type u} {S : Type v} {A : Type w}
[comm_ring R] [comm_ring S] [ring A] [algebra R S] [algebra S A]
(iSB : subalgebra S A) : subalgebra R (algebra.comap R S A) :=
{ carrier := (iSB : set A),
subring := iSB.is_subring,
range_le' := λ a ⟨r, hr⟩, hr ▸ iSB.range_le ⟨_, rfl⟩ }
def under {R : Type u} {A : Type v} [comm_ring R] [comm_ring A]
{i : algebra R A} (S : subalgebra R A)
(T : subalgebra S A) : subalgebra R A :=
{ carrier := T,
range_le' := (λ a ⟨r, hr⟩, hr ▸ T.range_le ⟨⟨algebra_map A r, S.range_le ⟨r, rfl⟩⟩, rfl⟩) }
end subalgebra
namespace alg_hom
variables {R : Type u} {A : Type v} {B : Type w}
variables [comm_ring R] [ring A] [ring B] [algebra R A] [algebra R B]
variables (φ : A →ₐ[R] B)
protected def range : subalgebra R B :=
{ carrier := set.range φ,
subring :=
{ one_mem := ⟨1, φ.map_one⟩,
mul_mem := λ y₁ y₂ ⟨x₁, hx₁⟩ ⟨x₂, hx₂⟩, ⟨x₁ * x₂, hx₁ ▸ hx₂ ▸ φ.map_mul x₁ x₂⟩ },
range_le' := λ y ⟨r, hr⟩, ⟨algebra_map A r, hr ▸ φ.commutes r⟩ }
end alg_hom
namespace algebra
variables {R : Type u} (A : Type v)
variables [comm_ring R] [ring A] [algebra R A]
include R
variables (R)
instance id : algebra R R :=
algebra.of_ring_hom id $ by apply_instance
namespace id
@[simp] lemma map_eq_self (x : R) : algebra_map R x = x := rfl
@[simp] lemma smul_eq_mul (x y : R) : x • y = x * y := rfl
end id
def of_id : R →ₐ A :=
{ commutes' := λ _, rfl, .. ring_hom.of (algebra_map A) }
variables {R}
theorem of_id_apply (r) : of_id R A r = algebra_map A r := rfl
variables (R) {A}
def adjoin (s : set A) : subalgebra R A :=
{ carrier := ring.closure (set.range (algebra_map A : R → A) ∪ s),
range_le' := le_trans (set.subset_union_left _ _) ring.subset_closure }
variables {R}
protected lemma gc : galois_connection (adjoin R : set A → subalgebra R A) coe :=
λ s S, ⟨λ H, le_trans (le_trans (set.subset_union_right _ _) ring.subset_closure) H,
λ H, ring.closure_subset $ set.union_subset S.range_le H⟩
protected def gi : galois_insertion (adjoin R : set A → subalgebra R A) coe :=
{ choice := λ s hs, adjoin R s,
gc := algebra.gc,
le_l_u := λ S, (algebra.gc (S : set A) (adjoin R S)).1 $ le_refl _,
choice_eq := λ _ _, rfl }
instance : complete_lattice (subalgebra R A) :=
galois_insertion.lift_complete_lattice algebra.gi
theorem mem_bot {x : A} : x ∈ (⊥ : subalgebra R A) ↔ x ∈ set.range (algebra_map A : R → A) :=
suffices (⊥ : subalgebra R A) = (of_id R A).range, by rw this; refl,
le_antisymm bot_le $ subalgebra.range_le _
theorem mem_top {x : A} : x ∈ (⊤ : subalgebra R A) :=
ring.mem_closure $ or.inr trivial
def to_top : A →ₐ[R] (⊤ : subalgebra R A) :=
by refine_struct { to_fun := λ x, (⟨x, mem_top⟩ : (⊤ : subalgebra R A)) }; intros; refl
end algebra
section int
variables (R : Type*) [comm_ring R]
/-- CRing ⥤ ℤ-Alg -/
def alg_hom_int
{R : Type u} [comm_ring R] [algebra ℤ R]
{S : Type v} [comm_ring S] [algebra ℤ S]
(f : R → S) [is_ring_hom f] : R →ₐ[ℤ] S :=
{ commutes' := λ i, by change (ring_hom.of f).to_fun with f; exact
int.induction_on i (by rw [algebra.map_zero, algebra.map_zero, is_ring_hom.map_zero f])
(λ i ih, by rw [algebra.map_add, algebra.map_add, algebra.map_one, algebra.map_one];
rw [is_ring_hom.map_add f, is_ring_hom.map_one f, ih])
(λ i ih, by rw [algebra.map_sub, algebra.map_sub, algebra.map_one, algebra.map_one];
rw [is_ring_hom.map_sub f, is_ring_hom.map_one f, ih]),
..ring_hom.of f }
/-- CRing ⥤ ℤ-Alg -/
instance algebra_int : algebra ℤ R :=
{ to_fun := coe,
commutes' := λ _ _, mul_comm _ _,
smul_def' := λ _ _, gsmul_eq_mul _ _ }
variables {R}
/-- CRing ⥤ ℤ-Alg -/
def subalgebra_of_subring (S : set R) [is_subring S] : subalgebra ℤ R :=
{ carrier := S, range_le' := λ x ⟨i, h⟩, h ▸ int.induction_on i
(by rw algebra.map_zero; exact is_add_submonoid.zero_mem _)
(λ i hi, by rw [algebra.map_add, algebra.map_one]; exact is_add_submonoid.add_mem hi (is_submonoid.one_mem _))
(λ i hi, by rw [algebra.map_sub, algebra.map_one]; exact is_add_subgroup.sub_mem _ _ _ hi (is_submonoid.one_mem _)) }
@[simp] lemma mem_subalgebra_of_subring {x : R} {S : set R} [is_subring S] :
x ∈ subalgebra_of_subring S ↔ x ∈ S :=
iff.rfl
section span_int
open submodule
lemma span_int_eq_add_group_closure (s : set R) :
↑(span ℤ s) = add_group.closure s :=
set.subset.antisymm (λ x hx, span_induction hx
(λ _, add_group.mem_closure)
(is_add_submonoid.zero_mem _)
(λ a b ha hb, is_add_submonoid.add_mem ha hb)
(λ n a ha, by { exact is_add_subgroup.gsmul_mem ha }))
(add_group.closure_subset subset_span)
@[simp] lemma span_int_eq (s : set R) [is_add_subgroup s] :
(↑(span ℤ s) : set R) = s :=
by rw [span_int_eq_add_group_closure, add_group.closure_add_subgroup]
end span_int
end int
section restrict_scalars
/- In this section, we describe restriction of scalars: if `S` is an algebra over `R`, then
`S`-modules are also `R`-modules. -/
variables (R : Type*) [comm_ring R] (S : Type*) [comm_ring S] [algebra R S]
(E : Type*) [add_comm_group E] [module S E] {F : Type*} [add_comm_group F] [module S F]
/-- When `E` is a module over a ring `S`, and `S` is an algebra over `R`, then `E` inherits a
module structure over `R`, called `module.restrict S R E`.
Not registered as an instance as `S` can not be inferred. -/
def module.restrict_scalars : module R E :=
{ smul := λc x, (algebra_map S c) • x,
one_smul := by simp,
mul_smul := by simp [mul_smul],
smul_add := by simp [smul_add],
smul_zero := by simp [smul_zero],
add_smul := by simp [add_smul],
zero_smul := by simp [zero_smul] }
variables {S E}
local attribute [instance] module.restrict_scalars
/-- The `R`-linear map induced by an `S`-linear map when `S` is an algebra over `R`. -/
def linear_map.restrict_scalars (f : E →ₗ[S] F) : E →ₗ[R] F :=
{ to_fun := f.to_fun,
add := λx y, f.map_add x y,
smul := λc x, f.map_smul (algebra_map S c) x }
@[simp, squash_cast] lemma linear_map.coe_restrict_scalars_eq_coe (f : E →ₗ[S] F) :
(f.restrict_scalars R : E → F) = f := rfl
/- 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
end restrict_scalars
|
a45ab22f5dac357fc257650a61a802aa08558404 | 2a70b774d16dbdf5a533432ee0ebab6838df0948 | /_target/deps/mathlib/src/topology/metric_space/basic.lean | 0b16764981680104ae6642bac0840873c040e72e | [
"Apache-2.0"
] | permissive | hjvromen/lewis | 40b035973df7c77ebf927afab7878c76d05ff758 | 105b675f73630f028ad5d890897a51b3c1146fb0 | refs/heads/master | 1,677,944,636,343 | 1,676,555,301,000 | 1,676,555,301,000 | 327,553,599 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 77,270 | lean | /-
Copyright (c) 2015, 2017 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Metric spaces.
Authors: Jeremy Avigad, Robert Y. Lewis, Johannes Hölzl, Mario Carneiro, Sébastien Gouëzel
Many definitions and theorems expected on metric spaces are already introduced on uniform spaces and
topological spaces. For example:
open and closed sets, compactness, completeness, continuity and uniform continuity
-/
import topology.metric_space.emetric_space
import topology.algebra.ordered
open set filter classical topological_space
noncomputable theory
open_locale uniformity topological_space big_operators filter nnreal
universes u v w
variables {α : Type u} {β : Type v} {γ : Type w}
/-- Construct a uniform structure from a distance function and metric space axioms -/
def uniform_space_of_dist
(dist : α → α → ℝ)
(dist_self : ∀ x : α, dist x x = 0)
(dist_comm : ∀ x y : α, dist x y = dist y x)
(dist_triangle : ∀ x y z : α, dist x z ≤ dist x y + dist y z) : uniform_space α :=
uniform_space.of_core {
uniformity := (⨅ ε>0, 𝓟 {p:α×α | dist p.1 p.2 < ε}),
refl := le_infi $ assume ε, le_infi $
by simp [set.subset_def, id_rel, dist_self, (>)] {contextual := tt},
comp := le_infi $ assume ε, le_infi $ assume h, lift'_le
(mem_infi_sets (ε / 2) $ mem_infi_sets (div_pos h zero_lt_two) (subset.refl _)) $
have ∀ (a b c : α), dist a c < ε / 2 → dist c b < ε / 2 → dist a b < ε,
from assume a b c hac hcb,
calc dist a b ≤ dist a c + dist c b : dist_triangle _ _ _
... < ε / 2 + ε / 2 : add_lt_add hac hcb
... = ε : by rw [div_add_div_same, add_self_div_two],
by simpa [comp_rel],
symm := tendsto_infi.2 $ assume ε, tendsto_infi.2 $ assume h,
tendsto_infi' ε $ tendsto_infi' h $ tendsto_principal_principal.2 $ by simp [dist_comm] }
/-- The distance function (given an ambient metric space on `α`), which returns
a nonnegative real number `dist x y` given `x y : α`. -/
class has_dist (α : Type*) := (dist : α → α → ℝ)
export has_dist (dist)
-- the uniform structure and the emetric space structure are embedded in the metric space structure
-- to avoid instance diamond issues. See Note [forgetful inheritance].
/-- Metric space
Each metric space induces a canonical `uniform_space` and hence a canonical `topological_space`.
This is enforced in the type class definition, by extending the `uniform_space` structure. When
instantiating a `metric_space` structure, the uniformity fields are not necessary, they will be
filled in by default. In the same way, each metric space induces an emetric space structure.
It is included in the structure, but filled in by default.
-/
class metric_space (α : Type u) extends has_dist α : Type u :=
(dist_self : ∀ x : α, dist x x = 0)
(eq_of_dist_eq_zero : ∀ {x y : α}, dist x y = 0 → x = y)
(dist_comm : ∀ x y : α, dist x y = dist y x)
(dist_triangle : ∀ x y z : α, dist x z ≤ dist x y + dist y z)
(edist : α → α → ennreal := λx y, ennreal.of_real (dist x y))
(edist_dist : ∀ x y : α, edist x y = ennreal.of_real (dist x y) . control_laws_tac)
(to_uniform_space : uniform_space α := uniform_space_of_dist dist dist_self dist_comm dist_triangle)
(uniformity_dist : 𝓤 α = ⨅ ε>0, 𝓟 {p:α×α | dist p.1 p.2 < ε} . control_laws_tac)
variables [metric_space α]
@[priority 100] -- see Note [lower instance priority]
instance metric_space.to_uniform_space' : uniform_space α :=
metric_space.to_uniform_space
@[priority 200] -- see Note [lower instance priority]
instance metric_space.to_has_edist : has_edist α := ⟨metric_space.edist⟩
@[simp] theorem dist_self (x : α) : dist x x = 0 := metric_space.dist_self x
theorem eq_of_dist_eq_zero {x y : α} : dist x y = 0 → x = y :=
metric_space.eq_of_dist_eq_zero
theorem dist_comm (x y : α) : dist x y = dist y x := metric_space.dist_comm x y
theorem edist_dist (x y : α) : edist x y = ennreal.of_real (dist x y) :=
metric_space.edist_dist x y
@[simp] theorem dist_eq_zero {x y : α} : dist x y = 0 ↔ x = y :=
iff.intro eq_of_dist_eq_zero (assume : x = y, this ▸ dist_self _)
@[simp] theorem zero_eq_dist {x y : α} : 0 = dist x y ↔ x = y :=
by rw [eq_comm, dist_eq_zero]
theorem dist_triangle (x y z : α) : dist x z ≤ dist x y + dist y z :=
metric_space.dist_triangle x y z
theorem dist_triangle_left (x y z : α) : dist x y ≤ dist z x + dist z y :=
by rw dist_comm z; apply dist_triangle
theorem dist_triangle_right (x y z : α) : dist x y ≤ dist x z + dist y z :=
by rw dist_comm y; apply dist_triangle
lemma dist_triangle4 (x y z w : α) :
dist x w ≤ dist x y + dist y z + dist z w :=
calc
dist x w ≤ dist x z + dist z w : dist_triangle x z w
... ≤ (dist x y + dist y z) + dist z w : add_le_add_right (metric_space.dist_triangle x y z) _
lemma dist_triangle4_left (x₁ y₁ x₂ y₂ : α) :
dist x₂ y₂ ≤ dist x₁ y₁ + (dist x₁ x₂ + dist y₁ y₂) :=
by rw [add_left_comm, dist_comm x₁, ← add_assoc]; apply dist_triangle4
lemma dist_triangle4_right (x₁ y₁ x₂ y₂ : α) :
dist x₁ y₁ ≤ dist x₁ x₂ + dist y₁ y₂ + dist x₂ y₂ :=
by rw [add_right_comm, dist_comm y₁]; apply dist_triangle4
/-- The triangle (polygon) inequality for sequences of points; `finset.Ico` version. -/
lemma dist_le_Ico_sum_dist (f : ℕ → α) {m n} (h : m ≤ n) :
dist (f m) (f n) ≤ ∑ i in finset.Ico m n, dist (f i) (f (i + 1)) :=
begin
revert n,
apply nat.le_induction,
{ simp only [finset.sum_empty, finset.Ico.self_eq_empty, dist_self] },
{ assume n hn hrec,
calc dist (f m) (f (n+1)) ≤ dist (f m) (f n) + dist _ _ : dist_triangle _ _ _
... ≤ ∑ i in finset.Ico m n, _ + _ : add_le_add hrec (le_refl _)
... = ∑ i in finset.Ico m (n+1), _ :
by rw [finset.Ico.succ_top hn, finset.sum_insert, add_comm]; simp }
end
/-- The triangle (polygon) inequality for sequences of points; `finset.range` version. -/
lemma dist_le_range_sum_dist (f : ℕ → α) (n : ℕ) :
dist (f 0) (f n) ≤ ∑ i in finset.range n, dist (f i) (f (i + 1)) :=
finset.Ico.zero_bot n ▸ dist_le_Ico_sum_dist f (nat.zero_le n)
/-- A version of `dist_le_Ico_sum_dist` with each intermediate distance replaced
with an upper estimate. -/
lemma dist_le_Ico_sum_of_dist_le {f : ℕ → α} {m n} (hmn : m ≤ n)
{d : ℕ → ℝ} (hd : ∀ {k}, m ≤ k → k < n → dist (f k) (f (k + 1)) ≤ d k) :
dist (f m) (f n) ≤ ∑ i in finset.Ico m n, d i :=
le_trans (dist_le_Ico_sum_dist f hmn) $
finset.sum_le_sum $ λ k hk, hd (finset.Ico.mem.1 hk).1 (finset.Ico.mem.1 hk).2
/-- A version of `dist_le_range_sum_dist` with each intermediate distance replaced
with an upper estimate. -/
lemma dist_le_range_sum_of_dist_le {f : ℕ → α} (n : ℕ)
{d : ℕ → ℝ} (hd : ∀ {k}, k < n → dist (f k) (f (k + 1)) ≤ d k) :
dist (f 0) (f n) ≤ ∑ i in finset.range n, d i :=
finset.Ico.zero_bot n ▸ dist_le_Ico_sum_of_dist_le (zero_le n) (λ _ _, hd)
theorem swap_dist : function.swap (@dist α _) = dist :=
by funext x y; exact dist_comm _ _
theorem abs_dist_sub_le (x y z : α) : abs (dist x z - dist y z) ≤ dist x y :=
abs_sub_le_iff.2
⟨sub_le_iff_le_add.2 (dist_triangle _ _ _),
sub_le_iff_le_add.2 (dist_triangle_left _ _ _)⟩
theorem dist_nonneg {x y : α} : 0 ≤ dist x y :=
have 2 * dist x y ≥ 0,
from calc 2 * dist x y = dist x y + dist y x : by rw [dist_comm x y, two_mul]
... ≥ 0 : by rw ← dist_self x; apply dist_triangle,
nonneg_of_mul_nonneg_left this zero_lt_two
@[simp] theorem dist_le_zero {x y : α} : dist x y ≤ 0 ↔ x = y :=
by simpa [le_antisymm_iff, dist_nonneg] using @dist_eq_zero _ _ x y
@[simp] theorem dist_pos {x y : α} : 0 < dist x y ↔ x ≠ y :=
by simpa only [not_le] using not_congr dist_le_zero
@[simp] theorem abs_dist {a b : α} : abs (dist a b) = dist a b :=
abs_of_nonneg dist_nonneg
theorem eq_of_forall_dist_le {x y : α} (h : ∀ ε > 0, dist x y ≤ ε) : x = y :=
eq_of_dist_eq_zero (eq_of_le_of_forall_le_of_dense dist_nonneg h)
/-- Distance as a nonnegative real number. -/
def nndist (a b : α) : ℝ≥0 := ⟨dist a b, dist_nonneg⟩
/--Express `nndist` in terms of `edist`-/
lemma nndist_edist (x y : α) : nndist x y = (edist x y).to_nnreal :=
by simp [nndist, edist_dist, nnreal.of_real, max_eq_left dist_nonneg, ennreal.of_real]
/--Express `edist` in terms of `nndist`-/
lemma edist_nndist (x y : α) : edist x y = ↑(nndist x y) :=
by { rw [edist_dist, nndist, ennreal.of_real_eq_coe_nnreal] }
@[simp, norm_cast] lemma ennreal_coe_nndist (x y : α) : ↑(nndist x y) = edist x y :=
(edist_nndist x y).symm
@[simp, norm_cast] lemma edist_lt_coe {x y : α} {c : ℝ≥0} :
edist x y < c ↔ nndist x y < c :=
by rw [edist_nndist, ennreal.coe_lt_coe]
@[simp, norm_cast] lemma edist_le_coe {x y : α} {c : ℝ≥0} :
edist x y ≤ c ↔ nndist x y ≤ c :=
by rw [edist_nndist, ennreal.coe_le_coe]
/--In a metric space, the extended distance is always finite-/
lemma edist_ne_top (x y : α) : edist x y ≠ ⊤ :=
by rw [edist_dist x y]; apply ennreal.coe_ne_top
/--In a metric space, the extended distance is always finite-/
lemma edist_lt_top {α : Type*} [metric_space α] (x y : α) : edist x y < ⊤ :=
ennreal.lt_top_iff_ne_top.2 (edist_ne_top x y)
/--`nndist x x` vanishes-/
@[simp] lemma nndist_self (a : α) : nndist a a = 0 := (nnreal.coe_eq_zero _).1 (dist_self a)
/--Express `dist` in terms of `nndist`-/
lemma dist_nndist (x y : α) : dist x y = ↑(nndist x y) := rfl
@[simp, norm_cast] lemma coe_nndist (x y : α) : ↑(nndist x y) = dist x y :=
(dist_nndist x y).symm
@[simp, norm_cast] lemma dist_lt_coe {x y : α} {c : ℝ≥0} :
dist x y < c ↔ nndist x y < c :=
iff.rfl
@[simp, norm_cast] lemma dist_le_coe {x y : α} {c : ℝ≥0} :
dist x y ≤ c ↔ nndist x y ≤ c :=
iff.rfl
/--Express `nndist` in terms of `dist`-/
lemma nndist_dist (x y : α) : nndist x y = nnreal.of_real (dist x y) :=
by rw [dist_nndist, nnreal.of_real_coe]
/--Deduce the equality of points with the vanishing of the nonnegative distance-/
theorem eq_of_nndist_eq_zero {x y : α} : nndist x y = 0 → x = y :=
by simp only [← nnreal.eq_iff, ← dist_nndist, imp_self, nnreal.coe_zero, dist_eq_zero]
theorem nndist_comm (x y : α) : nndist x y = nndist y x :=
by simpa only [dist_nndist, nnreal.coe_eq] using dist_comm x y
/--Characterize the equality of points with the vanishing of the nonnegative distance-/
@[simp] theorem nndist_eq_zero {x y : α} : nndist x y = 0 ↔ x = y :=
by simp only [← nnreal.eq_iff, ← dist_nndist, imp_self, nnreal.coe_zero, dist_eq_zero]
@[simp] theorem zero_eq_nndist {x y : α} : 0 = nndist x y ↔ x = y :=
by simp only [← nnreal.eq_iff, ← dist_nndist, imp_self, nnreal.coe_zero, zero_eq_dist]
/--Triangle inequality for the nonnegative distance-/
theorem nndist_triangle (x y z : α) : nndist x z ≤ nndist x y + nndist y z :=
by simpa [nnreal.coe_le_coe] using dist_triangle x y z
theorem nndist_triangle_left (x y z : α) : nndist x y ≤ nndist z x + nndist z y :=
by simpa [nnreal.coe_le_coe] using dist_triangle_left x y z
theorem nndist_triangle_right (x y z : α) : nndist x y ≤ nndist x z + nndist y z :=
by simpa [nnreal.coe_le_coe] using dist_triangle_right x y z
/--Express `dist` in terms of `edist`-/
lemma dist_edist (x y : α) : dist x y = (edist x y).to_real :=
by rw [edist_dist, ennreal.to_real_of_real (dist_nonneg)]
namespace metric
/- instantiate metric space as a topology -/
variables {x y z : α} {ε ε₁ ε₂ : ℝ} {s : set α}
/-- `ball x ε` is the set of all points `y` with `dist y x < ε` -/
def ball (x : α) (ε : ℝ) : set α := {y | dist y x < ε}
@[simp] theorem mem_ball : y ∈ ball x ε ↔ dist y x < ε := iff.rfl
theorem mem_ball' : y ∈ ball x ε ↔ dist x y < ε := by rw dist_comm; refl
@[simp] lemma nonempty_ball (h : 0 < ε) : (ball x ε).nonempty :=
⟨x, by simp [h]⟩
lemma ball_eq_ball (ε : ℝ) (x : α) :
uniform_space.ball x {p | dist p.2 p.1 < ε} = metric.ball x ε := rfl
lemma ball_eq_ball' (ε : ℝ) (x : α) :
uniform_space.ball x {p | dist p.1 p.2 < ε} = metric.ball x ε :=
by { ext, simp [dist_comm, uniform_space.ball] }
/-- `closed_ball x ε` is the set of all points `y` with `dist y x ≤ ε` -/
def closed_ball (x : α) (ε : ℝ) := {y | dist y x ≤ ε}
@[simp] theorem mem_closed_ball : y ∈ closed_ball x ε ↔ dist y x ≤ ε := iff.rfl
/-- `sphere x ε` is the set of all points `y` with `dist y x = ε` -/
def sphere (x : α) (ε : ℝ) := {y | dist y x = ε}
@[simp] theorem mem_sphere : y ∈ sphere x ε ↔ dist y x = ε := iff.rfl
theorem mem_closed_ball' : y ∈ closed_ball x ε ↔ dist x y ≤ ε :=
by { rw dist_comm, refl }
lemma nonempty_closed_ball (h : 0 ≤ ε) : (closed_ball x ε).nonempty :=
⟨x, by simp [h]⟩
theorem ball_subset_closed_ball : ball x ε ⊆ closed_ball x ε :=
assume y (hy : _ < _), le_of_lt hy
theorem sphere_subset_closed_ball : sphere x ε ⊆ closed_ball x ε :=
λ y, le_of_eq
theorem sphere_disjoint_ball : disjoint (sphere x ε) (ball x ε) :=
λ y ⟨hy₁, hy₂⟩, absurd hy₁ $ ne_of_lt hy₂
@[simp] theorem ball_union_sphere : ball x ε ∪ sphere x ε = closed_ball x ε :=
set.ext $ λ y, (@le_iff_lt_or_eq ℝ _ _ _).symm
@[simp] theorem sphere_union_ball : sphere x ε ∪ ball x ε = closed_ball x ε :=
by rw [union_comm, ball_union_sphere]
@[simp] theorem closed_ball_diff_sphere : closed_ball x ε \ sphere x ε = ball x ε :=
by rw [← ball_union_sphere, set.union_diff_cancel_right sphere_disjoint_ball.symm]
@[simp] theorem closed_ball_diff_ball : closed_ball x ε \ ball x ε = sphere x ε :=
by rw [← ball_union_sphere, set.union_diff_cancel_left sphere_disjoint_ball.symm]
theorem pos_of_mem_ball (hy : y ∈ ball x ε) : 0 < ε :=
lt_of_le_of_lt dist_nonneg hy
theorem mem_ball_self (h : 0 < ε) : x ∈ ball x ε :=
show dist x x < ε, by rw dist_self; assumption
theorem mem_closed_ball_self (h : 0 ≤ ε) : x ∈ closed_ball x ε :=
show dist x x ≤ ε, by rw dist_self; assumption
theorem mem_ball_comm : x ∈ ball y ε ↔ y ∈ ball x ε :=
by simp [dist_comm]
theorem ball_subset_ball (h : ε₁ ≤ ε₂) : ball x ε₁ ⊆ ball x ε₂ :=
λ y (yx : _ < ε₁), lt_of_lt_of_le yx h
theorem closed_ball_subset_closed_ball {α : Type u} [metric_space α] {ε₁ ε₂ : ℝ} {x : α} (h : ε₁ ≤ ε₂) :
closed_ball x ε₁ ⊆ closed_ball x ε₂ :=
λ y (yx : _ ≤ ε₁), le_trans yx h
theorem ball_disjoint (h : ε₁ + ε₂ ≤ dist x y) : ball x ε₁ ∩ ball y ε₂ = ∅ :=
eq_empty_iff_forall_not_mem.2 $ λ z ⟨h₁, h₂⟩,
not_lt_of_le (dist_triangle_left x y z)
(lt_of_lt_of_le (add_lt_add h₁ h₂) h)
theorem ball_disjoint_same (h : ε ≤ dist x y / 2) : ball x ε ∩ ball y ε = ∅ :=
ball_disjoint $ by rwa [← two_mul, ← le_div_iff' (@zero_lt_two ℝ _ _)]
theorem ball_subset (h : dist x y ≤ ε₂ - ε₁) : ball x ε₁ ⊆ ball y ε₂ :=
λ z zx, by rw ← add_sub_cancel'_right ε₁ ε₂; exact
lt_of_le_of_lt (dist_triangle z x y) (add_lt_add_of_lt_of_le zx h)
theorem ball_half_subset (y) (h : y ∈ ball x (ε / 2)) : ball y (ε / 2) ⊆ ball x ε :=
ball_subset $ by rw sub_self_div_two; exact le_of_lt h
theorem exists_ball_subset_ball (h : y ∈ ball x ε) : ∃ ε' > 0, ball y ε' ⊆ ball x ε :=
⟨_, sub_pos.2 h, ball_subset $ by rw sub_sub_self⟩
@[simp] theorem ball_eq_empty_iff_nonpos : ball x ε = ∅ ↔ ε ≤ 0 :=
eq_empty_iff_forall_not_mem.trans
⟨λ h, le_of_not_gt $ λ ε0, h _ $ mem_ball_self ε0,
λ ε0 y h, not_lt_of_le ε0 $ pos_of_mem_ball h⟩
@[simp] theorem closed_ball_eq_empty_iff_neg : closed_ball x ε = ∅ ↔ ε < 0 :=
eq_empty_iff_forall_not_mem.trans
⟨λ h, not_le.1 $ λ ε0, h x $ mem_closed_ball_self ε0,
λ ε0 y h, not_lt_of_le (mem_closed_ball.1 h) (lt_of_lt_of_le ε0 dist_nonneg)⟩
@[simp] lemma ball_zero : ball x 0 = ∅ :=
by rw [ball_eq_empty_iff_nonpos]
@[simp] lemma closed_ball_zero : closed_ball x 0 = {x} :=
set.ext $ λ y, dist_le_zero
theorem uniformity_basis_dist :
(𝓤 α).has_basis (λ ε : ℝ, 0 < ε) (λ ε, {p:α×α | dist p.1 p.2 < ε}) :=
begin
rw ← metric_space.uniformity_dist.symm,
refine has_basis_binfi_principal _ nonempty_Ioi,
exact λ r (hr : 0 < r) p (hp : 0 < p), ⟨min r p, lt_min hr hp,
λ x (hx : dist _ _ < _), lt_of_lt_of_le hx (min_le_left r p),
λ x (hx : dist _ _ < _), lt_of_lt_of_le hx (min_le_right r p)⟩
end
/-- Given `f : β → ℝ`, if `f` sends `{i | p i}` to a set of positive numbers
accumulating to zero, then `f i`-neighborhoods of the diagonal form a basis of `𝓤 α`.
For specific bases see `uniformity_basis_dist`, `uniformity_basis_dist_inv_nat_succ`,
and `uniformity_basis_dist_inv_nat_pos`. -/
protected theorem mk_uniformity_basis {β : Type*} {p : β → Prop} {f : β → ℝ}
(hf₀ : ∀ i, p i → 0 < f i) (hf : ∀ ⦃ε⦄, 0 < ε → ∃ i (hi : p i), f i ≤ ε) :
(𝓤 α).has_basis p (λ i, {p:α×α | dist p.1 p.2 < f i}) :=
begin
refine ⟨λ s, uniformity_basis_dist.mem_iff.trans _⟩,
split,
{ rintros ⟨ε, ε₀, hε⟩,
obtain ⟨i, hi, H⟩ : ∃ i (hi : p i), f i ≤ ε, from hf ε₀,
exact ⟨i, hi, λ x (hx : _ < _), hε $ lt_of_lt_of_le hx H⟩ },
{ exact λ ⟨i, hi, H⟩, ⟨f i, hf₀ i hi, H⟩ }
end
theorem uniformity_basis_dist_inv_nat_succ :
(𝓤 α).has_basis (λ _, true) (λ n:ℕ, {p:α×α | dist p.1 p.2 < 1 / (↑n+1) }) :=
metric.mk_uniformity_basis (λ n _, div_pos zero_lt_one $ nat.cast_add_one_pos n)
(λ ε ε0, (exists_nat_one_div_lt ε0).imp $ λ n hn, ⟨trivial, le_of_lt hn⟩)
theorem uniformity_basis_dist_inv_nat_pos :
(𝓤 α).has_basis (λ n:ℕ, 0<n) (λ n:ℕ, {p:α×α | dist p.1 p.2 < 1 / ↑n }) :=
metric.mk_uniformity_basis (λ n hn, div_pos zero_lt_one $ nat.cast_pos.2 hn)
(λ ε ε0, let ⟨n, hn⟩ := exists_nat_one_div_lt ε0 in ⟨n+1, nat.succ_pos n, le_of_lt hn⟩)
/-- Given `f : β → ℝ`, if `f` sends `{i | p i}` to a set of positive numbers
accumulating to zero, then closed neighborhoods of the diagonal of sizes `{f i | p i}`
form a basis of `𝓤 α`.
Currently we have only one specific basis `uniformity_basis_dist_le` based on this constructor.
More can be easily added if needed in the future. -/
protected theorem mk_uniformity_basis_le {β : Type*} {p : β → Prop} {f : β → ℝ}
(hf₀ : ∀ x, p x → 0 < f x) (hf : ∀ ε, 0 < ε → ∃ x (hx : p x), f x ≤ ε) :
(𝓤 α).has_basis p (λ x, {p:α×α | dist p.1 p.2 ≤ f x}) :=
begin
refine ⟨λ s, uniformity_basis_dist.mem_iff.trans _⟩,
split,
{ rintros ⟨ε, ε₀, hε⟩,
rcases exists_between ε₀ with ⟨ε', hε'⟩,
rcases hf ε' hε'.1 with ⟨i, hi, H⟩,
exact ⟨i, hi, λ x (hx : _ ≤ _), hε $ lt_of_le_of_lt (le_trans hx H) hε'.2⟩ },
{ exact λ ⟨i, hi, H⟩, ⟨f i, hf₀ i hi, λ x (hx : _ < _), H (le_of_lt hx)⟩ }
end
/-- Contant size closed neighborhoods of the diagonal form a basis
of the uniformity filter. -/
theorem uniformity_basis_dist_le :
(𝓤 α).has_basis (λ ε : ℝ, 0 < ε) (λ ε, {p:α×α | dist p.1 p.2 ≤ ε}) :=
metric.mk_uniformity_basis_le (λ _, id) (λ ε ε₀, ⟨ε, ε₀, le_refl ε⟩)
theorem mem_uniformity_dist {s : set (α×α)} :
s ∈ 𝓤 α ↔ (∃ε>0, ∀{a b:α}, dist a b < ε → (a, b) ∈ s) :=
uniformity_basis_dist.mem_uniformity_iff
/-- A constant size neighborhood of the diagonal is an entourage. -/
theorem dist_mem_uniformity {ε:ℝ} (ε0 : 0 < ε) :
{p:α×α | dist p.1 p.2 < ε} ∈ 𝓤 α :=
mem_uniformity_dist.2 ⟨ε, ε0, λ a b, id⟩
theorem uniform_continuous_iff [metric_space β] {f : α → β} :
uniform_continuous f ↔ ∀ ε > 0, ∃ δ > 0,
∀{a b:α}, dist a b < δ → dist (f a) (f b) < ε :=
uniformity_basis_dist.uniform_continuous_iff uniformity_basis_dist
lemma uniform_continuous_on_iff [metric_space β] {f : α → β} {s : set α} :
uniform_continuous_on f s ↔ ∀ ε > 0, ∃ δ > 0, ∀ x y ∈ s, dist x y < δ → dist (f x) (f y) < ε :=
begin
dsimp [uniform_continuous_on],
rw (metric.uniformity_basis_dist.inf_principal (s.prod s)).tendsto_iff metric.uniformity_basis_dist,
simp only [and_imp, exists_prop, prod.forall, mem_inter_eq, gt_iff_lt, mem_set_of_eq, mem_prod],
finish,
end
theorem uniform_embedding_iff [metric_space β] {f : α → β} :
uniform_embedding f ↔ function.injective f ∧ uniform_continuous f ∧
∀ δ > 0, ∃ ε > 0, ∀ {a b : α}, dist (f a) (f b) < ε → dist a b < δ :=
uniform_embedding_def'.trans $ and_congr iff.rfl $ and_congr iff.rfl
⟨λ H δ δ0, let ⟨t, tu, ht⟩ := H _ (dist_mem_uniformity δ0),
⟨ε, ε0, hε⟩ := mem_uniformity_dist.1 tu in
⟨ε, ε0, λ a b h, ht _ _ (hε h)⟩,
λ H s su, let ⟨δ, δ0, hδ⟩ := mem_uniformity_dist.1 su, ⟨ε, ε0, hε⟩ := H _ δ0 in
⟨_, dist_mem_uniformity ε0, λ a b h, hδ (hε h)⟩⟩
/-- A map between metric spaces is a uniform embedding if and only if the distance between `f x`
and `f y` is controlled in terms of the distance between `x` and `y` and conversely. -/
theorem uniform_embedding_iff' [metric_space β] {f : α → β} :
uniform_embedding f ↔
(∀ ε > 0, ∃ δ > 0, ∀ {a b : α}, dist a b < δ → dist (f a) (f b) < ε) ∧
(∀ δ > 0, ∃ ε > 0, ∀ {a b : α}, dist (f a) (f b) < ε → dist a b < δ) :=
begin
split,
{ assume h,
exact ⟨uniform_continuous_iff.1 (uniform_embedding_iff.1 h).2.1,
(uniform_embedding_iff.1 h).2.2⟩ },
{ rintros ⟨h₁, h₂⟩,
refine uniform_embedding_iff.2 ⟨_, uniform_continuous_iff.2 h₁, h₂⟩,
assume x y hxy,
have : dist x y ≤ 0,
{ refine le_of_forall_lt' (λδ δpos, _),
rcases h₂ δ δpos with ⟨ε, εpos, hε⟩,
have : dist (f x) (f y) < ε, by simpa [hxy],
exact hε this },
simpa using this }
end
theorem totally_bounded_iff {s : set α} :
totally_bounded s ↔ ∀ ε > 0, ∃t : set α, finite t ∧ s ⊆ ⋃y∈t, ball y ε :=
⟨λ H ε ε0, H _ (dist_mem_uniformity ε0),
λ H r ru, let ⟨ε, ε0, hε⟩ := mem_uniformity_dist.1 ru,
⟨t, ft, h⟩ := H ε ε0 in
⟨t, ft, subset.trans h $ Union_subset_Union $ λ y, Union_subset_Union $ λ yt z, hε⟩⟩
/-- A metric space space is totally bounded if one can reconstruct up to any ε>0 any element of the
space from finitely many data. -/
lemma totally_bounded_of_finite_discretization {s : set α}
(H : ∀ε > (0 : ℝ), ∃ (β : Type u) [fintype β] (F : s → β),
∀x y, F x = F y → dist (x:α) y < ε) :
totally_bounded s :=
begin
cases s.eq_empty_or_nonempty with hs hs,
{ rw hs, exact totally_bounded_empty },
rcases hs with ⟨x0, hx0⟩,
haveI : inhabited s := ⟨⟨x0, hx0⟩⟩,
refine totally_bounded_iff.2 (λ ε ε0, _),
rcases H ε ε0 with ⟨β, fβ, F, hF⟩,
resetI,
let Finv := function.inv_fun F,
refine ⟨range (subtype.val ∘ Finv), finite_range _, λ x xs, _⟩,
let x' := Finv (F ⟨x, xs⟩),
have : F x' = F ⟨x, xs⟩ := function.inv_fun_eq ⟨⟨x, xs⟩, rfl⟩,
simp only [set.mem_Union, set.mem_range],
exact ⟨_, ⟨F ⟨x, xs⟩, rfl⟩, hF _ _ this.symm⟩
end
theorem finite_approx_of_totally_bounded {s : set α} (hs : totally_bounded s) :
∀ ε > 0, ∃ t ⊆ s, finite t ∧ s ⊆ ⋃y∈t, ball y ε :=
begin
intros ε ε_pos,
rw totally_bounded_iff_subset at hs,
exact hs _ (dist_mem_uniformity ε_pos),
end
/-- Expressing locally uniform convergence on a set using `dist`. -/
lemma tendsto_locally_uniformly_on_iff {ι : Type*} [topological_space β]
{F : ι → β → α} {f : β → α} {p : filter ι} {s : set β} :
tendsto_locally_uniformly_on F f p s ↔
∀ ε > 0, ∀ x ∈ s, ∃ t ∈ 𝓝[s] x, ∀ᶠ n in p, ∀ y ∈ t, dist (f y) (F n y) < ε :=
begin
refine ⟨λ H ε hε, H _ (dist_mem_uniformity hε), λ H u hu x hx, _⟩,
rcases mem_uniformity_dist.1 hu with ⟨ε, εpos, hε⟩,
rcases H ε εpos x hx with ⟨t, ht, Ht⟩,
exact ⟨t, ht, Ht.mono (λ n hs x hx, hε (hs x hx))⟩
end
/-- Expressing uniform convergence on a set using `dist`. -/
lemma tendsto_uniformly_on_iff {ι : Type*}
{F : ι → β → α} {f : β → α} {p : filter ι} {s : set β} :
tendsto_uniformly_on F f p s ↔ ∀ ε > 0, ∀ᶠ n in p, ∀ x ∈ s, dist (f x) (F n x) < ε :=
begin
refine ⟨λ H ε hε, H _ (dist_mem_uniformity hε), λ H u hu, _⟩,
rcases mem_uniformity_dist.1 hu with ⟨ε, εpos, hε⟩,
exact (H ε εpos).mono (λ n hs x hx, hε (hs x hx))
end
/-- Expressing locally uniform convergence using `dist`. -/
lemma tendsto_locally_uniformly_iff {ι : Type*} [topological_space β]
{F : ι → β → α} {f : β → α} {p : filter ι} :
tendsto_locally_uniformly F f p ↔
∀ ε > 0, ∀ (x : β), ∃ t ∈ 𝓝 x, ∀ᶠ n in p, ∀ y ∈ t, dist (f y) (F n y) < ε :=
by simp only [← tendsto_locally_uniformly_on_univ, tendsto_locally_uniformly_on_iff,
nhds_within_univ, mem_univ, forall_const, exists_prop]
/-- Expressing uniform convergence using `dist`. -/
lemma tendsto_uniformly_iff {ι : Type*}
{F : ι → β → α} {f : β → α} {p : filter ι} :
tendsto_uniformly F f p ↔ ∀ ε > 0, ∀ᶠ n in p, ∀ x, dist (f x) (F n x) < ε :=
by { rw [← tendsto_uniformly_on_univ, tendsto_uniformly_on_iff], simp }
protected lemma cauchy_iff {f : filter α} :
cauchy f ↔ ne_bot f ∧ ∀ ε > 0, ∃ t ∈ f, ∀ x y ∈ t, dist x y < ε :=
uniformity_basis_dist.cauchy_iff
theorem nhds_basis_ball : (𝓝 x).has_basis (λ ε:ℝ, 0 < ε) (ball x) :=
nhds_basis_uniformity uniformity_basis_dist
theorem mem_nhds_iff : s ∈ 𝓝 x ↔ ∃ε>0, ball x ε ⊆ s :=
nhds_basis_ball.mem_iff
theorem eventually_nhds_iff {p : α → Prop} :
(∀ᶠ y in 𝓝 x, p y) ↔ ∃ε>0, ∀ ⦃y⦄, dist y x < ε → p y :=
mem_nhds_iff
lemma eventually_nhds_iff_ball {p : α → Prop} :
(∀ᶠ y in 𝓝 x, p y) ↔ ∃ ε>0, ∀ y ∈ ball x ε, p y :=
mem_nhds_iff
theorem nhds_basis_closed_ball : (𝓝 x).has_basis (λ ε:ℝ, 0 < ε) (closed_ball x) :=
nhds_basis_uniformity uniformity_basis_dist_le
theorem nhds_basis_ball_inv_nat_succ :
(𝓝 x).has_basis (λ _, true) (λ n:ℕ, ball x (1 / (↑n+1))) :=
nhds_basis_uniformity uniformity_basis_dist_inv_nat_succ
theorem nhds_basis_ball_inv_nat_pos :
(𝓝 x).has_basis (λ n, 0<n) (λ n:ℕ, ball x (1 / ↑n)) :=
nhds_basis_uniformity uniformity_basis_dist_inv_nat_pos
theorem is_open_iff : is_open s ↔ ∀x∈s, ∃ε>0, ball x ε ⊆ s :=
by simp only [is_open_iff_mem_nhds, mem_nhds_iff]
theorem is_open_ball : is_open (ball x ε) :=
is_open_iff.2 $ λ y, exists_ball_subset_ball
theorem ball_mem_nhds (x : α) {ε : ℝ} (ε0 : 0 < ε) : ball x ε ∈ 𝓝 x :=
mem_nhds_sets is_open_ball (mem_ball_self ε0)
theorem closed_ball_mem_nhds (x : α) {ε : ℝ} (ε0 : 0 < ε) : closed_ball x ε ∈ 𝓝 x :=
mem_sets_of_superset (ball_mem_nhds x ε0) ball_subset_closed_ball
theorem nhds_within_basis_ball {s : set α} :
(𝓝[s] x).has_basis (λ ε:ℝ, 0 < ε) (λ ε, ball x ε ∩ s) :=
nhds_within_has_basis nhds_basis_ball s
theorem mem_nhds_within_iff {t : set α} : s ∈ 𝓝[t] x ↔ ∃ε>0, ball x ε ∩ t ⊆ s :=
nhds_within_basis_ball.mem_iff
theorem tendsto_nhds_within_nhds_within [metric_space β] {t : set β} {f : α → β} {a b} :
tendsto f (𝓝[s] a) (𝓝[t] b) ↔
∀ ε > 0, ∃ δ > 0, ∀{x:α}, x ∈ s → dist x a < δ → f x ∈ t ∧ dist (f x) b < ε :=
(nhds_within_basis_ball.tendsto_iff nhds_within_basis_ball).trans $
by simp only [inter_comm, mem_inter_iff, and_imp, mem_ball]
theorem tendsto_nhds_within_nhds [metric_space β] {f : α → β} {a b} :
tendsto f (𝓝[s] a) (𝓝 b) ↔
∀ ε > 0, ∃ δ > 0, ∀{x:α}, x ∈ s → dist x a < δ → dist (f x) b < ε :=
by { rw [← nhds_within_univ b, tendsto_nhds_within_nhds_within],
simp only [mem_univ, true_and] }
theorem tendsto_nhds_nhds [metric_space β] {f : α → β} {a b} :
tendsto f (𝓝 a) (𝓝 b) ↔
∀ ε > 0, ∃ δ > 0, ∀{x:α}, dist x a < δ → dist (f x) b < ε :=
nhds_basis_ball.tendsto_iff nhds_basis_ball
theorem continuous_at_iff [metric_space β] {f : α → β} {a : α} :
continuous_at f a ↔
∀ ε > 0, ∃ δ > 0, ∀{x:α}, dist x a < δ → dist (f x) (f a) < ε :=
by rw [continuous_at, tendsto_nhds_nhds]
theorem continuous_within_at_iff [metric_space β] {f : α → β} {a : α} {s : set α} :
continuous_within_at f s a ↔
∀ ε > 0, ∃ δ > 0, ∀{x:α}, x ∈ s → dist x a < δ → dist (f x) (f a) < ε :=
by rw [continuous_within_at, tendsto_nhds_within_nhds]
theorem continuous_on_iff [metric_space β] {f : α → β} {s : set α} :
continuous_on f s ↔
∀ (b ∈ s) (ε > 0), ∃ δ > 0, ∀a ∈ s, dist a b < δ → dist (f a) (f b) < ε :=
by simp [continuous_on, continuous_within_at_iff]
theorem continuous_iff [metric_space β] {f : α → β} :
continuous f ↔
∀b (ε > 0), ∃ δ > 0, ∀a, dist a b < δ → dist (f a) (f b) < ε :=
continuous_iff_continuous_at.trans $ forall_congr $ λ b, tendsto_nhds_nhds
theorem tendsto_nhds {f : filter β} {u : β → α} {a : α} :
tendsto u f (𝓝 a) ↔ ∀ ε > 0, ∀ᶠ x in f, dist (u x) a < ε :=
nhds_basis_ball.tendsto_right_iff
theorem continuous_at_iff' [topological_space β] {f : β → α} {b : β} :
continuous_at f b ↔
∀ ε > 0, ∀ᶠ x in 𝓝 b, dist (f x) (f b) < ε :=
by rw [continuous_at, tendsto_nhds]
theorem continuous_within_at_iff' [topological_space β] {f : β → α} {b : β} {s : set β} :
continuous_within_at f s b ↔
∀ ε > 0, ∀ᶠ x in 𝓝[s] b, dist (f x) (f b) < ε :=
by rw [continuous_within_at, tendsto_nhds]
theorem continuous_on_iff' [topological_space β] {f : β → α} {s : set β} :
continuous_on f s ↔
∀ (b ∈ s) (ε > 0), ∀ᶠ x in 𝓝[s] b, dist (f x) (f b) < ε :=
by simp [continuous_on, continuous_within_at_iff']
theorem continuous_iff' [topological_space β] {f : β → α} :
continuous f ↔ ∀a (ε > 0), ∀ᶠ x in 𝓝 a, dist (f x) (f a) < ε :=
continuous_iff_continuous_at.trans $ forall_congr $ λ b, tendsto_nhds
theorem tendsto_at_top [nonempty β] [semilattice_sup β] {u : β → α} {a : α} :
tendsto u at_top (𝓝 a) ↔ ∀ε>0, ∃N, ∀n≥N, dist (u n) a < ε :=
(at_top_basis.tendsto_iff nhds_basis_ball).trans $
by { simp only [exists_prop, true_and], refl }
lemma is_open_singleton_iff {X : Type*} [metric_space X] {x : X} :
is_open ({x} : set X) ↔ ∃ ε > 0, ∀ y, dist y x < ε → y = x :=
by simp [is_open_iff, subset_singleton_iff, mem_ball]
/-- Given a point `x` in a discrete subset `s` of a metric space, there is an open ball
centered at `x` and intersecting `s` only at `x`. -/
lemma exists_ball_inter_eq_singleton_of_mem_discrete [discrete_topology s] {x : α} (hx : x ∈ s) :
∃ ε > 0, metric.ball x ε ∩ s = {x} :=
nhds_basis_ball.exists_inter_eq_singleton_of_mem_discrete hx
/-- Given a point `x` in a discrete subset `s` of a metric space, there is a closed ball
of positive radius centered at `x` and intersecting `s` only at `x`. -/
lemma exists_closed_ball_inter_eq_singleton_of_discrete [discrete_topology s] {x : α} (hx : x ∈ s) :
∃ ε > 0, metric.closed_ball x ε ∩ s = {x} :=
nhds_basis_closed_ball.exists_inter_eq_singleton_of_mem_discrete hx
end metric
open metric
@[priority 100] -- see Note [lower instance priority]
instance metric_space.to_separated : separated_space α :=
separated_def.2 $ λ x y h, eq_of_forall_dist_le $
λ ε ε0, le_of_lt (h _ (dist_mem_uniformity ε0))
/-Instantiate a metric space as an emetric space. Before we can state the instance,
we need to show that the uniform structure coming from the edistance and the
distance coincide. -/
/-- Expressing the uniformity in terms of `edist` -/
protected lemma metric.uniformity_basis_edist :
(𝓤 α).has_basis (λ ε:ennreal, 0 < ε) (λ ε, {p | edist p.1 p.2 < ε}) :=
⟨begin
intro t,
refine mem_uniformity_dist.trans ⟨_, _⟩; rintro ⟨ε, ε0, Hε⟩,
{ use [ennreal.of_real ε, ennreal.of_real_pos.2 ε0],
rintros ⟨a, b⟩,
simp only [edist_dist, ennreal.of_real_lt_of_real_iff ε0],
exact Hε },
{ rcases ennreal.lt_iff_exists_real_btwn.1 ε0 with ⟨ε', _, ε0', hε⟩,
rw [ennreal.of_real_pos] at ε0',
refine ⟨ε', ε0', λ a b h, Hε (lt_trans _ hε)⟩,
rwa [edist_dist, ennreal.of_real_lt_of_real_iff ε0'] }
end⟩
theorem metric.uniformity_edist : 𝓤 α = (⨅ ε>0, 𝓟 {p:α×α | edist p.1 p.2 < ε}) :=
metric.uniformity_basis_edist.eq_binfi
/-- A metric space induces an emetric space -/
@[priority 100] -- see Note [lower instance priority]
instance metric_space.to_emetric_space : emetric_space α :=
{ edist := edist,
edist_self := by simp [edist_dist],
eq_of_edist_eq_zero := assume x y h, by simpa [edist_dist] using h,
edist_comm := by simp only [edist_dist, dist_comm]; simp,
edist_triangle := assume x y z, begin
simp only [edist_dist, ← ennreal.of_real_add, dist_nonneg],
rw ennreal.of_real_le_of_real_iff _,
{ exact dist_triangle _ _ _ },
{ simpa using add_le_add (dist_nonneg : 0 ≤ dist x y) dist_nonneg }
end,
uniformity_edist := metric.uniformity_edist,
..‹metric_space α› }
/-- Balls defined using the distance or the edistance coincide -/
lemma metric.emetric_ball {x : α} {ε : ℝ} : emetric.ball x (ennreal.of_real ε) = ball x ε :=
begin
ext y,
simp only [emetric.mem_ball, mem_ball, edist_dist],
exact ennreal.of_real_lt_of_real_iff_of_nonneg dist_nonneg
end
/-- Balls defined using the distance or the edistance coincide -/
lemma metric.emetric_ball_nnreal {x : α} {ε : ℝ≥0} : emetric.ball x ε = ball x ε :=
by { convert metric.emetric_ball, simp }
/-- Closed balls defined using the distance or the edistance coincide -/
lemma metric.emetric_closed_ball {x : α} {ε : ℝ} (h : 0 ≤ ε) :
emetric.closed_ball x (ennreal.of_real ε) = closed_ball x ε :=
by ext y; simp [edist_dist]; rw ennreal.of_real_le_of_real_iff h
/-- Closed balls defined using the distance or the edistance coincide -/
lemma metric.emetric_closed_ball_nnreal {x : α} {ε : ℝ≥0} :
emetric.closed_ball x ε = closed_ball x ε :=
by { convert metric.emetric_closed_ball ε.2, simp }
/-- Build a new metric space from an old one where the bundled uniform structure is provably
(but typically non-definitionaly) equal to some given uniform structure.
See Note [forgetful inheritance].
-/
def metric_space.replace_uniformity {α} [U : uniform_space α] (m : metric_space α)
(H : @uniformity _ U = @uniformity _ emetric_space.to_uniform_space') :
metric_space α :=
{ dist := @dist _ m.to_has_dist,
dist_self := dist_self,
eq_of_dist_eq_zero := @eq_of_dist_eq_zero _ _,
dist_comm := dist_comm,
dist_triangle := dist_triangle,
edist := edist,
edist_dist := edist_dist,
to_uniform_space := U,
uniformity_dist := H.trans metric_space.uniformity_dist }
/-- One gets a metric space from an emetric space if the edistance
is everywhere finite, by pushing the edistance to reals. We set it up so that the edist and the
uniformity are defeq in the metric space and the emetric space. In this definition, the distance
is given separately, to be able to prescribe some expression which is not defeq to the push-forward
of the edistance to reals. -/
def emetric_space.to_metric_space_of_dist {α : Type u} [e : emetric_space α]
(dist : α → α → ℝ)
(edist_ne_top : ∀x y: α, edist x y ≠ ⊤)
(h : ∀x y, dist x y = ennreal.to_real (edist x y)) :
metric_space α :=
let m : metric_space α :=
{ dist := dist,
eq_of_dist_eq_zero := λx y hxy, by simpa [h, ennreal.to_real_eq_zero_iff, edist_ne_top x y] using hxy,
dist_self := λx, by simp [h],
dist_comm := λx y, by simp [h, emetric_space.edist_comm],
dist_triangle := λx y z, begin
simp only [h],
rw [← ennreal.to_real_add (edist_ne_top _ _) (edist_ne_top _ _),
ennreal.to_real_le_to_real (edist_ne_top _ _)],
{ exact edist_triangle _ _ _ },
{ simp [ennreal.add_eq_top, edist_ne_top] }
end,
edist := λx y, edist x y,
edist_dist := λx y, by simp [h, ennreal.of_real_to_real, edist_ne_top] } in
m.replace_uniformity $ by { rw [uniformity_edist, metric.uniformity_edist], refl }
/-- One gets a metric space from an emetric space if the edistance
is everywhere finite, by pushing the edistance to reals. We set it up so that the edist and the
uniformity are defeq in the metric space and the emetric space. -/
def emetric_space.to_metric_space {α : Type u} [e : emetric_space α] (h : ∀x y: α, edist x y ≠ ⊤) :
metric_space α :=
emetric_space.to_metric_space_of_dist (λx y, ennreal.to_real (edist x y)) h (λx y, rfl)
/-- A very useful criterion to show that a space is complete is to show that all sequences
which satisfy a bound of the form `dist (u n) (u m) < B N` for all `n m ≥ N` are
converging. This is often applied for `B N = 2^{-N}`, i.e., with a very fast convergence to
`0`, which makes it possible to use arguments of converging series, while this is impossible
to do in general for arbitrary Cauchy sequences. -/
theorem metric.complete_of_convergent_controlled_sequences (B : ℕ → real) (hB : ∀n, 0 < B n)
(H : ∀u : ℕ → α, (∀N n m : ℕ, N ≤ n → N ≤ m → dist (u n) (u m) < B N) → ∃x, tendsto u at_top (𝓝 x)) :
complete_space α :=
begin
-- this follows from the same criterion in emetric spaces. We just need to translate
-- the convergence assumption from `dist` to `edist`
apply emetric.complete_of_convergent_controlled_sequences (λn, ennreal.of_real (B n)),
{ simp [hB] },
{ assume u Hu,
apply H,
assume N n m hn hm,
rw [← ennreal.of_real_lt_of_real_iff (hB N), ← edist_dist],
exact Hu N n m hn hm }
end
theorem metric.complete_of_cauchy_seq_tendsto :
(∀ u : ℕ → α, cauchy_seq u → ∃a, tendsto u at_top (𝓝 a)) → complete_space α :=
emetric.complete_of_cauchy_seq_tendsto
section real
/-- Instantiate the reals as a metric space. -/
instance real.metric_space : metric_space ℝ :=
{ dist := λx y, abs (x - y),
dist_self := by simp [abs_zero],
eq_of_dist_eq_zero := by simp [sub_eq_zero],
dist_comm := assume x y, abs_sub _ _,
dist_triangle := assume x y z, abs_sub_le _ _ _ }
theorem real.dist_eq (x y : ℝ) : dist x y = abs (x - y) := rfl
theorem real.dist_0_eq_abs (x : ℝ) : dist x 0 = abs x :=
by simp [real.dist_eq]
instance : order_topology ℝ :=
order_topology_of_nhds_abs $ λ x, begin
simp only [show ∀ r, {b : ℝ | abs (x - b) < r} = ball x r,
by simp [abs_sub, ball, real.dist_eq]],
apply le_antisymm,
{ simp [le_infi_iff],
exact λ ε ε0, mem_nhds_sets (is_open_ball) (mem_ball_self ε0) },
{ intros s h,
rcases mem_nhds_iff.1 h with ⟨ε, ε0, ss⟩,
exact mem_infi_sets _ (mem_infi_sets ε0 (mem_principal_sets.2 ss)) },
end
lemma closed_ball_Icc {x r : ℝ} : closed_ball x r = Icc (x-r) (x+r) :=
by ext y; rw [mem_closed_ball, dist_comm, real.dist_eq,
abs_sub_le_iff, mem_Icc, ← sub_le_iff_le_add', sub_le]
/-- Special case of the sandwich theorem; see `tendsto_of_tendsto_of_tendsto_of_le_of_le'` for the
general case. -/
lemma squeeze_zero' {α} {f g : α → ℝ} {t₀ : filter α} (hf : ∀ᶠ t in t₀, 0 ≤ f t)
(hft : ∀ᶠ t in t₀, f t ≤ g t) (g0 : tendsto g t₀ (nhds 0)) : tendsto f t₀ (𝓝 0) :=
tendsto_of_tendsto_of_tendsto_of_le_of_le' tendsto_const_nhds g0 hf hft
/-- Special case of the sandwich theorem; see `tendsto_of_tendsto_of_tendsto_of_le_of_le`
and `tendsto_of_tendsto_of_tendsto_of_le_of_le'` for the general case. -/
lemma squeeze_zero {α} {f g : α → ℝ} {t₀ : filter α} (hf : ∀t, 0 ≤ f t) (hft : ∀t, f t ≤ g t)
(g0 : tendsto g t₀ (𝓝 0)) : tendsto f t₀ (𝓝 0) :=
squeeze_zero' (eventually_of_forall hf) (eventually_of_forall hft) g0
theorem metric.uniformity_eq_comap_nhds_zero :
𝓤 α = comap (λp:α×α, dist p.1 p.2) (𝓝 (0 : ℝ)) :=
by { ext s,
simp [mem_uniformity_dist, (nhds_basis_ball.comap _).mem_iff, subset_def, real.dist_0_eq_abs] }
lemma cauchy_seq_iff_tendsto_dist_at_top_0 [nonempty β] [semilattice_sup β] {u : β → α} :
cauchy_seq u ↔ tendsto (λ (n : β × β), dist (u n.1) (u n.2)) at_top (𝓝 0) :=
by rw [cauchy_seq_iff_tendsto, metric.uniformity_eq_comap_nhds_zero, tendsto_comap_iff,
prod.map_def]
lemma tendsto_uniformity_iff_dist_tendsto_zero {ι : Type*} {f : ι → α × α} {p : filter ι} :
tendsto f p (𝓤 α) ↔ tendsto (λ x, dist (f x).1 (f x).2) p (𝓝 0) :=
by rw [metric.uniformity_eq_comap_nhds_zero, tendsto_comap_iff]
lemma filter.tendsto.congr_dist {ι : Type*} {f₁ f₂ : ι → α} {p : filter ι} {a : α}
(h₁ : tendsto f₁ p (𝓝 a)) (h : tendsto (λ x, dist (f₁ x) (f₂ x)) p (𝓝 0)) :
tendsto f₂ p (𝓝 a) :=
h₁.congr_uniformity $ tendsto_uniformity_iff_dist_tendsto_zero.2 h
alias filter.tendsto.congr_dist ← tendsto_of_tendsto_of_dist
lemma tendsto_iff_of_dist {ι : Type*} {f₁ f₂ : ι → α} {p : filter ι} {a : α}
(h : tendsto (λ x, dist (f₁ x) (f₂ x)) p (𝓝 0)) :
tendsto f₁ p (𝓝 a) ↔ tendsto f₂ p (𝓝 a) :=
uniform.tendsto_congr $ tendsto_uniformity_iff_dist_tendsto_zero.2 h
end real
section cauchy_seq
variables [nonempty β] [semilattice_sup β]
/-- In a metric space, Cauchy sequences are characterized by the fact that, eventually,
the distance between its elements is arbitrarily small -/
@[nolint ge_or_gt] -- see Note [nolint_ge]
theorem metric.cauchy_seq_iff {u : β → α} :
cauchy_seq u ↔ ∀ε>0, ∃N, ∀m n≥N, dist (u m) (u n) < ε :=
uniformity_basis_dist.cauchy_seq_iff
/-- A variation around the metric characterization of Cauchy sequences -/
theorem metric.cauchy_seq_iff' {u : β → α} :
cauchy_seq u ↔ ∀ε>0, ∃N, ∀n≥N, dist (u n) (u N) < ε :=
uniformity_basis_dist.cauchy_seq_iff'
/-- If the distance between `s n` and `s m`, `n, m ≥ N` is bounded above by `b N`
and `b` converges to zero, then `s` is a Cauchy sequence. -/
lemma cauchy_seq_of_le_tendsto_0 {s : β → α} (b : β → ℝ)
(h : ∀ n m N : β, N ≤ n → N ≤ m → dist (s n) (s m) ≤ b N) (h₀ : tendsto b at_top (nhds 0)) :
cauchy_seq s :=
metric.cauchy_seq_iff.2 $ λ ε ε0,
(metric.tendsto_at_top.1 h₀ ε ε0).imp $ λ N hN m n hm hn,
calc dist (s m) (s n) ≤ b N : h m n N hm hn
... ≤ abs (b N) : le_abs_self _
... = dist (b N) 0 : by rw real.dist_0_eq_abs; refl
... < ε : (hN _ (le_refl N))
/-- A Cauchy sequence on the natural numbers is bounded. -/
theorem cauchy_seq_bdd {u : ℕ → α} (hu : cauchy_seq u) :
∃ R > 0, ∀ m n, dist (u m) (u n) < R :=
begin
rcases metric.cauchy_seq_iff'.1 hu 1 zero_lt_one with ⟨N, hN⟩,
suffices : ∃ R > 0, ∀ n, dist (u n) (u N) < R,
{ rcases this with ⟨R, R0, H⟩,
exact ⟨_, add_pos R0 R0, λ m n,
lt_of_le_of_lt (dist_triangle_right _ _ _) (add_lt_add (H m) (H n))⟩ },
let R := finset.sup (finset.range N) (λ n, nndist (u n) (u N)),
refine ⟨↑R + 1, add_pos_of_nonneg_of_pos R.2 zero_lt_one, λ n, _⟩,
cases le_or_lt N n,
{ exact lt_of_lt_of_le (hN _ h) (le_add_of_nonneg_left R.2) },
{ have : _ ≤ R := finset.le_sup (finset.mem_range.2 h),
exact lt_of_le_of_lt this (lt_add_of_pos_right _ zero_lt_one) }
end
/-- Yet another metric characterization of Cauchy sequences on integers. This one is often the
most efficient. -/
lemma cauchy_seq_iff_le_tendsto_0 {s : ℕ → α} : cauchy_seq s ↔ ∃ b : ℕ → ℝ,
(∀ n, 0 ≤ b n) ∧
(∀ n m N : ℕ, N ≤ n → N ≤ m → dist (s n) (s m) ≤ b N) ∧
tendsto b at_top (𝓝 0) :=
⟨λ hs, begin
/- `s` is a Cauchy sequence. The sequence `b` will be constructed by taking
the supremum of the distances between `s n` and `s m` for `n m ≥ N`.
First, we prove that all these distances are bounded, as otherwise the Sup
would not make sense. -/
let S := λ N, (λ(p : ℕ × ℕ), dist (s p.1) (s p.2)) '' {p | p.1 ≥ N ∧ p.2 ≥ N},
have hS : ∀ N, ∃ x, ∀ y ∈ S N, y ≤ x,
{ rcases cauchy_seq_bdd hs with ⟨R, R0, hR⟩,
refine λ N, ⟨R, _⟩, rintro _ ⟨⟨m, n⟩, _, rfl⟩,
exact le_of_lt (hR m n) },
have bdd : bdd_above (range (λ(p : ℕ × ℕ), dist (s p.1) (s p.2))),
{ rcases cauchy_seq_bdd hs with ⟨R, R0, hR⟩,
use R, rintro _ ⟨⟨m, n⟩, rfl⟩, exact le_of_lt (hR m n) },
-- Prove that it bounds the distances of points in the Cauchy sequence
have ub : ∀ m n N, N ≤ m → N ≤ n → dist (s m) (s n) ≤ Sup (S N) :=
λ m n N hm hn, real.le_Sup _ (hS N) ⟨⟨_, _⟩, ⟨hm, hn⟩, rfl⟩,
have S0m : ∀ n, (0:ℝ) ∈ S n := λ n, ⟨⟨n, n⟩, ⟨le_refl _, le_refl _⟩, dist_self _⟩,
have S0 := λ n, real.le_Sup _ (hS n) (S0m n),
-- Prove that it tends to `0`, by using the Cauchy property of `s`
refine ⟨λ N, Sup (S N), S0, ub, metric.tendsto_at_top.2 (λ ε ε0, _)⟩,
refine (metric.cauchy_seq_iff.1 hs (ε/2) (half_pos ε0)).imp (λ N hN n hn, _),
rw [real.dist_0_eq_abs, abs_of_nonneg (S0 n)],
refine lt_of_le_of_lt (real.Sup_le_ub _ ⟨_, S0m _⟩ _) (half_lt_self ε0),
rintro _ ⟨⟨m', n'⟩, ⟨hm', hn'⟩, rfl⟩,
exact le_of_lt (hN _ _ (le_trans hn hm') (le_trans hn hn'))
end,
λ ⟨b, _, b_bound, b_lim⟩, cauchy_seq_of_le_tendsto_0 b b_bound b_lim⟩
end cauchy_seq
/-- Metric space structure pulled back by an injective function. Injectivity is necessary to
ensure that `dist x y = 0` only if `x = y`. -/
def metric_space.induced {α β} (f : α → β) (hf : function.injective f)
(m : metric_space β) : metric_space α :=
{ dist := λ x y, dist (f x) (f y),
dist_self := λ x, dist_self _,
eq_of_dist_eq_zero := λ x y h, hf (dist_eq_zero.1 h),
dist_comm := λ x y, dist_comm _ _,
dist_triangle := λ x y z, dist_triangle _ _ _,
edist := λ x y, edist (f x) (f y),
edist_dist := λ x y, edist_dist _ _,
to_uniform_space := uniform_space.comap f m.to_uniform_space,
uniformity_dist := begin
apply @uniformity_dist_of_mem_uniformity _ _ _ _ _ (λ x y, dist (f x) (f y)),
refine λ s, mem_comap_sets.trans _,
split; intro H,
{ rcases H with ⟨r, ru, rs⟩,
rcases mem_uniformity_dist.1 ru with ⟨ε, ε0, hε⟩,
refine ⟨ε, ε0, λ a b h, rs (hε _)⟩, exact h },
{ rcases H with ⟨ε, ε0, hε⟩,
exact ⟨_, dist_mem_uniformity ε0, λ ⟨a, b⟩, hε⟩ }
end }
instance subtype.metric_space {α : Type*} {p : α → Prop} [t : metric_space α] :
metric_space (subtype p) :=
metric_space.induced coe (λ x y, subtype.ext) t
theorem subtype.dist_eq {p : α → Prop} (x y : subtype p) : dist x y = dist (x : α) y := rfl
section nnreal
instance : metric_space ℝ≥0 := by unfold nnreal; apply_instance
lemma nnreal.dist_eq (a b : ℝ≥0) : dist a b = abs ((a:ℝ) - b) := rfl
lemma nnreal.nndist_eq (a b : ℝ≥0) :
nndist a b = max (a - b) (b - a) :=
begin
wlog h : a ≤ b,
{ apply nnreal.coe_eq.1,
rw [nnreal.sub_eq_zero h, max_eq_right (zero_le $ b - a), ← dist_nndist, nnreal.dist_eq,
nnreal.coe_sub h, abs, neg_sub],
apply max_eq_right,
linarith [nnreal.coe_le_coe.2 h] },
rwa [nndist_comm, max_comm]
end
end nnreal
section prod
instance prod.metric_space_max [metric_space β] : metric_space (α × β) :=
{ dist := λ x y, max (dist x.1 y.1) (dist x.2 y.2),
dist_self := λ x, by simp,
eq_of_dist_eq_zero := λ x y h, begin
cases max_le_iff.1 (le_of_eq h) with h₁ h₂,
exact prod.ext_iff.2 ⟨dist_le_zero.1 h₁, dist_le_zero.1 h₂⟩
end,
dist_comm := λ x y, by simp [dist_comm],
dist_triangle := λ x y z, max_le
(le_trans (dist_triangle _ _ _) (add_le_add (le_max_left _ _) (le_max_left _ _)))
(le_trans (dist_triangle _ _ _) (add_le_add (le_max_right _ _) (le_max_right _ _))),
edist := λ x y, max (edist x.1 y.1) (edist x.2 y.2),
edist_dist := assume x y, begin
have : monotone ennreal.of_real := assume x y h, ennreal.of_real_le_of_real h,
rw [edist_dist, edist_dist, ← this.map_max]
end,
uniformity_dist := begin
refine uniformity_prod.trans _,
simp only [uniformity_basis_dist.eq_binfi, comap_infi],
rw ← infi_inf_eq, congr, funext,
rw ← infi_inf_eq, congr, funext,
simp [inf_principal, ext_iff, max_lt_iff]
end,
to_uniform_space := prod.uniform_space }
lemma prod.dist_eq [metric_space β] {x y : α × β} :
dist x y = max (dist x.1 y.1) (dist x.2 y.2) := rfl
end prod
theorem uniform_continuous_dist : uniform_continuous (λp:α×α, dist p.1 p.2) :=
metric.uniform_continuous_iff.2 (λ ε ε0, ⟨ε/2, half_pos ε0,
begin
suffices,
{ intros p q h, cases p with p₁ p₂, cases q with q₁ q₂,
cases max_lt_iff.1 h with h₁ h₂, clear h,
dsimp at h₁ h₂ ⊢,
rw real.dist_eq,
refine abs_sub_lt_iff.2 ⟨_, _⟩,
{ revert p₁ p₂ q₁ q₂ h₁ h₂, exact this },
{ apply this; rwa dist_comm } },
intros p₁ p₂ q₁ q₂ h₁ h₂,
have := add_lt_add
(abs_sub_lt_iff.1 (lt_of_le_of_lt (abs_dist_sub_le p₁ q₁ p₂) h₁)).1
(abs_sub_lt_iff.1 (lt_of_le_of_lt (abs_dist_sub_le p₂ q₂ q₁) h₂)).1,
rwa [add_halves, dist_comm p₂, sub_add_sub_cancel, dist_comm q₂] at this
end⟩)
theorem uniform_continuous.dist [uniform_space β] {f g : β → α}
(hf : uniform_continuous f) (hg : uniform_continuous g) :
uniform_continuous (λb, dist (f b) (g b)) :=
uniform_continuous_dist.comp (hf.prod_mk hg)
theorem continuous_dist : continuous (λp:α×α, dist p.1 p.2) :=
uniform_continuous_dist.continuous
theorem continuous.dist [topological_space β] {f g : β → α}
(hf : continuous f) (hg : continuous g) : continuous (λb, dist (f b) (g b)) :=
continuous_dist.comp (hf.prod_mk hg : _)
theorem filter.tendsto.dist {f g : β → α} {x : filter β} {a b : α}
(hf : tendsto f x (𝓝 a)) (hg : tendsto g x (𝓝 b)) :
tendsto (λx, dist (f x) (g x)) x (𝓝 (dist a b)) :=
(continuous_dist.tendsto (a, b)).comp (hf.prod_mk_nhds hg)
lemma nhds_comap_dist (a : α) : (𝓝 (0 : ℝ)).comap (λa', dist a' a) = 𝓝 a :=
by simp only [@nhds_eq_comap_uniformity α, metric.uniformity_eq_comap_nhds_zero,
comap_comap, (∘), dist_comm]
lemma tendsto_iff_dist_tendsto_zero {f : β → α} {x : filter β} {a : α} :
(tendsto f x (𝓝 a)) ↔ (tendsto (λb, dist (f b) a) x (𝓝 0)) :=
by rw [← nhds_comap_dist a, tendsto_comap_iff]
lemma uniform_continuous_nndist : uniform_continuous (λp:α×α, nndist p.1 p.2) :=
uniform_continuous_subtype_mk uniform_continuous_dist _
lemma uniform_continuous.nndist [uniform_space β] {f g : β → α} (hf : uniform_continuous f)
(hg : uniform_continuous g) :
uniform_continuous (λ b, nndist (f b) (g b)) :=
uniform_continuous_nndist.comp (hf.prod_mk hg)
lemma continuous_nndist : continuous (λp:α×α, nndist p.1 p.2) :=
uniform_continuous_nndist.continuous
lemma continuous.nndist [topological_space β] {f g : β → α}
(hf : continuous f) (hg : continuous g) : continuous (λb, nndist (f b) (g b)) :=
continuous_nndist.comp (hf.prod_mk hg : _)
theorem filter.tendsto.nndist {f g : β → α} {x : filter β} {a b : α}
(hf : tendsto f x (𝓝 a)) (hg : tendsto g x (𝓝 b)) :
tendsto (λx, nndist (f x) (g x)) x (𝓝 (nndist a b)) :=
(continuous_nndist.tendsto (a, b)).comp (hf.prod_mk_nhds hg)
namespace metric
variables {x y z : α} {ε ε₁ ε₂ : ℝ} {s : set α}
theorem is_closed_ball : is_closed (closed_ball x ε) :=
is_closed_le (continuous_id.dist continuous_const) continuous_const
lemma is_closed_sphere : is_closed (sphere x ε) :=
is_closed_eq (continuous_id.dist continuous_const) continuous_const
@[simp] theorem closure_closed_ball : closure (closed_ball x ε) = closed_ball x ε :=
is_closed_ball.closure_eq
theorem closure_ball_subset_closed_ball : closure (ball x ε) ⊆ closed_ball x ε :=
closure_minimal ball_subset_closed_ball is_closed_ball
theorem frontier_ball_subset_sphere : frontier (ball x ε) ⊆ sphere x ε :=
frontier_lt_subset_eq (continuous_id.dist continuous_const) continuous_const
theorem frontier_closed_ball_subset_sphere : frontier (closed_ball x ε) ⊆ sphere x ε :=
frontier_le_subset_eq (continuous_id.dist continuous_const) continuous_const
theorem ball_subset_interior_closed_ball : ball x ε ⊆ interior (closed_ball x ε) :=
interior_maximal ball_subset_closed_ball is_open_ball
/-- ε-characterization of the closure in metric spaces-/
theorem mem_closure_iff {α : Type u} [metric_space α] {s : set α} {a : α} :
a ∈ closure s ↔ ∀ε>0, ∃b ∈ s, dist a b < ε :=
(mem_closure_iff_nhds_basis nhds_basis_ball).trans $
by simp only [mem_ball, dist_comm]
lemma mem_closure_range_iff {α : Type u} [metric_space α] {e : β → α} {a : α} :
a ∈ closure (range e) ↔ ∀ε>0, ∃ k : β, dist a (e k) < ε :=
by simp only [mem_closure_iff, exists_range_iff]
lemma mem_closure_range_iff_nat {α : Type u} [metric_space α] {e : β → α} {a : α} :
a ∈ closure (range e) ↔ ∀n : ℕ, ∃ k : β, dist a (e k) < 1 / ((n : ℝ) + 1) :=
(mem_closure_iff_nhds_basis nhds_basis_ball_inv_nat_succ).trans $
by simp only [mem_ball, dist_comm, exists_range_iff, forall_const]
theorem mem_of_closed' {α : Type u} [metric_space α] {s : set α} (hs : is_closed s)
{a : α} : a ∈ s ↔ ∀ε>0, ∃b ∈ s, dist a b < ε :=
by simpa only [hs.closure_eq] using @mem_closure_iff _ _ s a
end metric
section pi
open finset
variables {π : β → Type*} [fintype β] [∀b, metric_space (π b)]
/-- A finite product of metric spaces is a metric space, with the sup distance. -/
instance metric_space_pi : metric_space (Πb, π b) :=
begin
/- we construct the instance from the emetric space instance to avoid checking again that the
uniformity is the same as the product uniformity, but we register nevertheless a nice formula
for the distance -/
refine emetric_space.to_metric_space_of_dist
(λf g, ((sup univ (λb, nndist (f b) (g b)) : ℝ≥0) : ℝ)) _ _,
show ∀ (x y : Π (b : β), π b), edist x y ≠ ⊤,
{ assume x y,
rw ← lt_top_iff_ne_top,
have : (⊥ : ennreal) < ⊤ := ennreal.coe_lt_top,
simp [edist_pi_def, finset.sup_lt_iff this, edist_lt_top] },
show ∀ (x y : Π (b : β), π b), ↑(sup univ (λ (b : β), nndist (x b) (y b))) =
ennreal.to_real (sup univ (λ (b : β), edist (x b) (y b))),
{ assume x y,
simp only [edist_nndist],
norm_cast }
end
lemma nndist_pi_def (f g : Πb, π b) : nndist f g = sup univ (λb, nndist (f b) (g b)) :=
subtype.eta _ _
lemma dist_pi_def (f g : Πb, π b) :
dist f g = (sup univ (λb, nndist (f b) (g b)) : ℝ≥0) := rfl
lemma dist_pi_lt_iff {f g : Πb, π b} {r : ℝ} (hr : 0 < r) :
dist f g < r ↔ ∀b, dist (f b) (g b) < r :=
begin
lift r to ℝ≥0 using hr.le,
simp [dist_pi_def, finset.sup_lt_iff (show ⊥ < r, from hr)],
end
lemma dist_pi_le_iff {f g : Πb, π b} {r : ℝ} (hr : 0 ≤ r) :
dist f g ≤ r ↔ ∀b, dist (f b) (g b) ≤ r :=
begin
lift r to ℝ≥0 using hr,
simp [nndist_pi_def]
end
lemma nndist_le_pi_nndist (f g : Πb, π b) (b : β) : nndist (f b) (g b) ≤ nndist f g :=
by { rw [nndist_pi_def], exact finset.le_sup (finset.mem_univ b) }
lemma dist_le_pi_dist (f g : Πb, π b) (b : β) : dist (f b) (g b) ≤ dist f g :=
by simp only [dist_nndist, nnreal.coe_le_coe, nndist_le_pi_nndist f g b]
/-- An open ball in a product space is a product of open balls. The assumption `0 < r`
is necessary for the case of the empty product. -/
lemma ball_pi (x : Πb, π b) {r : ℝ} (hr : 0 < r) :
ball x r = { y | ∀b, y b ∈ ball (x b) r } :=
by { ext p, simp [dist_pi_lt_iff hr] }
/-- A closed ball in a product space is a product of closed balls. The assumption `0 ≤ r`
is necessary for the case of the empty product. -/
lemma closed_ball_pi (x : Πb, π b) {r : ℝ} (hr : 0 ≤ r) :
closed_ball x r = { y | ∀b, y b ∈ closed_ball (x b) r } :=
by { ext p, simp [dist_pi_le_iff hr] }
end pi
section compact
/-- Any compact set in a metric space can be covered by finitely many balls of a given positive
radius -/
lemma finite_cover_balls_of_compact {α : Type u} [metric_space α] {s : set α}
(hs : is_compact s) {e : ℝ} (he : 0 < e) :
∃t ⊆ s, finite t ∧ s ⊆ ⋃x∈t, ball x e :=
begin
apply hs.elim_finite_subcover_image,
{ simp [is_open_ball] },
{ intros x xs,
simp,
exact ⟨x, ⟨xs, by simpa⟩⟩ }
end
alias finite_cover_balls_of_compact ← is_compact.finite_cover_balls
end compact
section proper_space
open metric
/-- A metric space is proper if all closed balls are compact. -/
class proper_space (α : Type u) [metric_space α] : Prop :=
(compact_ball : ∀x:α, ∀r, is_compact (closed_ball x r))
lemma tendsto_dist_right_cocompact_at_top [proper_space α] (x : α) :
tendsto (λ y, dist y x) (cocompact α) at_top :=
(has_basis_cocompact.tendsto_iff at_top_basis).2 $ λ r hr,
⟨closed_ball x r, proper_space.compact_ball x r, λ y hy, (not_le.1 $ mt mem_closed_ball.2 hy).le⟩
lemma tendsto_dist_left_cocompact_at_top [proper_space α] (x : α) :
tendsto (dist x) (cocompact α) at_top :=
by simpa only [dist_comm] using tendsto_dist_right_cocompact_at_top x
/-- If all closed balls of large enough radius are compact, then the space is proper. Especially
useful when the lower bound for the radius is 0. -/
lemma proper_space_of_compact_closed_ball_of_le
(R : ℝ) (h : ∀x:α, ∀r, R ≤ r → is_compact (closed_ball x r)) :
proper_space α :=
⟨begin
assume x r,
by_cases hr : R ≤ r,
{ exact h x r hr },
{ have : closed_ball x r = closed_ball x R ∩ closed_ball x r,
{ symmetry,
apply inter_eq_self_of_subset_right,
exact closed_ball_subset_closed_ball (le_of_lt (not_le.1 hr)) },
rw this,
exact (h x R (le_refl _)).inter_right is_closed_ball }
end⟩
/- A compact metric space is proper -/
@[priority 100] -- see Note [lower instance priority]
instance proper_of_compact [compact_space α] : proper_space α :=
⟨assume x r, is_closed_ball.compact⟩
/-- A proper space is locally compact -/
@[priority 100] -- see Note [lower instance priority]
instance locally_compact_of_proper [proper_space α] :
locally_compact_space α :=
begin
apply locally_compact_of_compact_nhds,
intros x,
existsi closed_ball x 1,
split,
{ apply mem_nhds_iff.2,
existsi (1 : ℝ),
simp,
exact ⟨zero_lt_one, ball_subset_closed_ball⟩ },
{ apply proper_space.compact_ball }
end
/-- A proper space is complete -/
@[priority 100] -- see Note [lower instance priority]
instance complete_of_proper [proper_space α] : complete_space α :=
⟨begin
intros f hf,
/- We want to show that the Cauchy filter `f` is converging. It suffices to find a closed
ball (therefore compact by properness) where it is nontrivial. -/
have A : ∃ t ∈ f, ∀ x y ∈ t, dist x y < 1 := (metric.cauchy_iff.1 hf).2 1 zero_lt_one,
rcases A with ⟨t, ⟨t_fset, ht⟩⟩,
rcases hf.1.nonempty_of_mem t_fset with ⟨x, xt⟩,
have : t ⊆ closed_ball x 1 := by intros y yt; simp [dist_comm]; apply le_of_lt (ht x y xt yt),
have : closed_ball x 1 ∈ f := f.sets_of_superset t_fset this,
rcases (compact_iff_totally_bounded_complete.1 (proper_space.compact_ball x 1)).2 f hf (le_principal_iff.2 this)
with ⟨y, _, hy⟩,
exact ⟨y, hy⟩
end⟩
/-- A proper metric space is separable, and therefore second countable. Indeed, any ball is
compact, and therefore admits a countable dense subset. Taking a countable union over the balls
centered at a fixed point and with integer radius, one obtains a countable set which is
dense in the whole space. -/
@[priority 100] -- see Note [lower instance priority]
instance second_countable_of_proper [proper_space α] :
second_countable_topology α :=
begin
/- It suffices to show that `α` admits a countable dense subset. -/
suffices : separable_space α,
{ resetI, apply emetric.second_countable_of_separable },
constructor,
/- We show that the space admits a countable dense subset. The case where the space is empty
is special, and trivial. -/
rcases _root_.em (nonempty α) with (⟨⟨x⟩⟩|hα), swap,
{ exact ⟨∅, countable_empty, λ x, (hα ⟨x⟩).elim⟩ },
/- When the space is not empty, we take a point `x` in the space, and then a countable set
`T r` which is dense in the closed ball `closed_ball x r` for each `r`. Then the set
`t = ⋃ T n` (where the union is over all integers `n`) is countable, as a countable union
of countable sets, and dense in the space by construction. -/
choose T T_sub T_count T_closure using
show ∀ (r:ℝ), ∃ t ⊆ closed_ball x r, (countable (t : set α) ∧ closed_ball x r = closure t),
from assume r, emetric.countable_closure_of_compact (proper_space.compact_ball _ _),
use [⋃n:ℕ, T (n : ℝ), countable_Union (λ n, T_count n)],
intro y,
rcases exists_nat_gt (dist y x) with ⟨n, n_large⟩,
have h : y ∈ closed_ball x (n : ℝ) := n_large.le,
rw [T_closure] at h,
exact closure_mono (subset_Union _ _) h
end
/-- A finite product of proper spaces is proper. -/
instance pi_proper_space {π : β → Type*} [fintype β] [∀b, metric_space (π b)]
[h : ∀b, proper_space (π b)] : proper_space (Πb, π b) :=
begin
refine proper_space_of_compact_closed_ball_of_le 0 (λx r hr, _),
rw closed_ball_pi _ hr,
apply compact_pi_infinite (λb, _),
apply (h b).compact_ball
end
end proper_space
namespace metric
section second_countable
open topological_space
/-- A metric space is second countable if, for every `ε > 0`, there is a countable set which is
`ε`-dense. -/
lemma second_countable_of_almost_dense_set
(H : ∀ε > (0 : ℝ), ∃ s : set α, countable s ∧ (∀x, ∃y ∈ s, dist x y ≤ ε)) :
second_countable_topology α :=
begin
choose T T_dense using H,
have I1 : ∀n:ℕ, (n:ℝ) + 1 > 0 :=
λn, lt_of_lt_of_le zero_lt_one (le_add_of_nonneg_left (nat.cast_nonneg _)),
have I : ∀n:ℕ, (n+1 : ℝ)⁻¹ > 0 := λn, inv_pos.2 (I1 n),
let t := ⋃n:ℕ, T (n+1)⁻¹ (I n),
have count_t : countable t := by finish [countable_Union],
have dense_t : dense t,
{ refine (λx, mem_closure_iff.2 (λε εpos, _)),
rcases exists_nat_gt ε⁻¹ with ⟨n, hn⟩,
have : ε⁻¹ < n + 1 := lt_of_lt_of_le hn (le_add_of_nonneg_right zero_le_one),
have nε : ((n:ℝ)+1)⁻¹ < ε := (inv_lt (I1 n) εpos).2 this,
rcases (T_dense (n+1)⁻¹ (I n)).2 x with ⟨y, yT, Dxy⟩,
have : y ∈ t := mem_of_mem_of_subset yT (by apply subset_Union (λ (n:ℕ), T (n+1)⁻¹ (I n))),
exact ⟨y, this, lt_of_le_of_lt Dxy nε⟩ },
haveI : separable_space α := ⟨⟨t, ⟨count_t, dense_t⟩⟩⟩,
exact emetric.second_countable_of_separable α
end
/-- A metric space space is second countable if one can reconstruct up to any `ε>0` any element of
the space from countably many data. -/
lemma second_countable_of_countable_discretization {α : Type u} [metric_space α]
(H : ∀ε > (0 : ℝ), ∃ (β : Type*) [encodable β] (F : α → β), ∀x y, F x = F y → dist x y ≤ ε) :
second_countable_topology α :=
begin
cases (univ : set α).eq_empty_or_nonempty with hs hs,
{ haveI : compact_space α := ⟨by rw hs; exact compact_empty⟩, by apply_instance },
rcases hs with ⟨x0, hx0⟩,
letI : inhabited α := ⟨x0⟩,
refine second_countable_of_almost_dense_set (λε ε0, _),
rcases H ε ε0 with ⟨β, fβ, F, hF⟩,
resetI,
let Finv := function.inv_fun F,
refine ⟨range Finv, ⟨countable_range _, λx, _⟩⟩,
let x' := Finv (F x),
have : F x' = F x := function.inv_fun_eq ⟨x, rfl⟩,
exact ⟨x', mem_range_self _, hF _ _ this.symm⟩
end
end second_countable
end metric
lemma lebesgue_number_lemma_of_metric
{s : set α} {ι} {c : ι → set α} (hs : is_compact s)
(hc₁ : ∀ i, is_open (c i)) (hc₂ : s ⊆ ⋃ i, c i) :
∃ δ > 0, ∀ x ∈ s, ∃ i, ball x δ ⊆ c i :=
let ⟨n, en, hn⟩ := lebesgue_number_lemma hs hc₁ hc₂,
⟨δ, δ0, hδ⟩ := mem_uniformity_dist.1 en in
⟨δ, δ0, assume x hx, let ⟨i, hi⟩ := hn x hx in
⟨i, assume y hy, hi (hδ (mem_ball'.mp hy))⟩⟩
lemma lebesgue_number_lemma_of_metric_sUnion
{s : set α} {c : set (set α)} (hs : is_compact s)
(hc₁ : ∀ t ∈ c, is_open t) (hc₂ : s ⊆ ⋃₀ c) :
∃ δ > 0, ∀ x ∈ s, ∃ t ∈ c, ball x δ ⊆ t :=
by rw sUnion_eq_Union at hc₂;
simpa using lebesgue_number_lemma_of_metric hs (by simpa) hc₂
namespace metric
/-- Boundedness of a subset of a metric space. We formulate the definition to work
even in the empty space. -/
def bounded (s : set α) : Prop :=
∃C, ∀x y ∈ s, dist x y ≤ C
section bounded
variables {x : α} {s t : set α} {r : ℝ}
@[simp] lemma bounded_empty : bounded (∅ : set α) :=
⟨0, by simp⟩
lemma bounded_iff_mem_bounded : bounded s ↔ ∀ x ∈ s, bounded s :=
⟨λ h _ _, h, λ H,
s.eq_empty_or_nonempty.elim
(λ hs, hs.symm ▸ bounded_empty)
(λ ⟨x, hx⟩, H x hx)⟩
/-- Subsets of a bounded set are also bounded -/
lemma bounded.subset (incl : s ⊆ t) : bounded t → bounded s :=
Exists.imp $ λ C hC x y hx hy, hC x y (incl hx) (incl hy)
/-- Closed balls are bounded -/
lemma bounded_closed_ball : bounded (closed_ball x r) :=
⟨r + r, λ y z hy hz, begin
simp only [mem_closed_ball] at *,
calc dist y z ≤ dist y x + dist z x : dist_triangle_right _ _ _
... ≤ r + r : add_le_add hy hz
end⟩
/-- Open balls are bounded -/
lemma bounded_ball : bounded (ball x r) :=
bounded_closed_ball.subset ball_subset_closed_ball
/-- Given a point, a bounded subset is included in some ball around this point -/
lemma bounded_iff_subset_ball (c : α) : bounded s ↔ ∃r, s ⊆ closed_ball c r :=
begin
split; rintro ⟨C, hC⟩,
{ cases s.eq_empty_or_nonempty with h h,
{ subst s, exact ⟨0, by simp⟩ },
{ rcases h with ⟨x, hx⟩,
exact ⟨C + dist x c, λ y hy, calc
dist y c ≤ dist y x + dist x c : dist_triangle _ _ _
... ≤ C + dist x c : add_le_add_right (hC y x hy hx) _⟩ } },
{ exact bounded_closed_ball.subset hC }
end
lemma bounded_closure_of_bounded (h : bounded s) : bounded (closure s) :=
begin
cases h with C h,
replace h : ∀ p : α × α, p ∈ set.prod s s → dist p.1 p.2 ∈ { d | d ≤ C },
{ rintros ⟨x, y⟩ ⟨x_in, y_in⟩,
exact h x y x_in y_in },
use C,
suffices : ∀ p : α × α, p ∈ closure (set.prod s s) → dist p.1 p.2 ∈ { d | d ≤ C },
{ rw closure_prod_eq at this,
intros x y x_in y_in,
exact this (x, y) (mk_mem_prod x_in y_in) },
intros p p_in,
have := map_mem_closure continuous_dist p_in h,
rwa (is_closed_le' C).closure_eq at this
end
alias bounded_closure_of_bounded ← bounded.closure
/-- The union of two bounded sets is bounded iff each of the sets is bounded -/
@[simp] lemma bounded_union :
bounded (s ∪ t) ↔ bounded s ∧ bounded t :=
⟨λh, ⟨h.subset (by simp), h.subset (by simp)⟩,
begin
rintro ⟨hs, ht⟩,
refine bounded_iff_mem_bounded.2 (λ x _, _),
rw bounded_iff_subset_ball x at hs ht ⊢,
rcases hs with ⟨Cs, hCs⟩, rcases ht with ⟨Ct, hCt⟩,
exact ⟨max Cs Ct, union_subset
(subset.trans hCs $ closed_ball_subset_closed_ball $ le_max_left _ _)
(subset.trans hCt $ closed_ball_subset_closed_ball $ le_max_right _ _)⟩,
end⟩
/-- A finite union of bounded sets is bounded -/
lemma bounded_bUnion {I : set β} {s : β → set α} (H : finite I) :
bounded (⋃i∈I, s i) ↔ ∀i ∈ I, bounded (s i) :=
finite.induction_on H (by simp) $ λ x I _ _ IH,
by simp [or_imp_distrib, forall_and_distrib, IH]
/-- A compact set is bounded -/
lemma bounded_of_compact {s : set α} (h : is_compact s) : bounded s :=
-- We cover the compact set by finitely many balls of radius 1,
-- and then argue that a finite union of bounded sets is bounded
let ⟨t, ht, fint, subs⟩ := finite_cover_balls_of_compact h zero_lt_one in
bounded.subset subs $ (bounded_bUnion fint).2 $ λ i hi, bounded_ball
alias bounded_of_compact ← is_compact.bounded
/-- A finite set is bounded -/
lemma bounded_of_finite {s : set α} (h : finite s) : bounded s :=
h.is_compact.bounded
/-- A singleton is bounded -/
lemma bounded_singleton {x : α} : bounded ({x} : set α) :=
bounded_of_finite $ finite_singleton _
/-- Characterization of the boundedness of the range of a function -/
lemma bounded_range_iff {f : β → α} : bounded (range f) ↔ ∃C, ∀x y, dist (f x) (f y) ≤ C :=
exists_congr $ λ C, ⟨
λ H x y, H _ _ ⟨x, rfl⟩ ⟨y, rfl⟩,
by rintro H _ _ ⟨x, rfl⟩ ⟨y, rfl⟩; exact H x y⟩
/-- In a compact space, all sets are bounded -/
lemma bounded_of_compact_space [compact_space α] : bounded s :=
compact_univ.bounded.subset (subset_univ _)
/-- The Heine–Borel theorem:
In a proper space, a set is compact if and only if it is closed and bounded -/
lemma compact_iff_closed_bounded [proper_space α] :
is_compact s ↔ is_closed s ∧ bounded s :=
⟨λ h, ⟨h.is_closed, h.bounded⟩, begin
rintro ⟨hc, hb⟩,
cases s.eq_empty_or_nonempty with h h, {simp [h, compact_empty]},
rcases h with ⟨x, hx⟩,
rcases (bounded_iff_subset_ball x).1 hb with ⟨r, hr⟩,
exact compact_of_is_closed_subset (proper_space.compact_ball x r) hc hr
end⟩
/-- The image of a proper space under an expanding onto map is proper. -/
lemma proper_image_of_proper [proper_space α] [metric_space β] (f : α → β)
(f_cont : continuous f) (hf : range f = univ) (C : ℝ)
(hC : ∀x y, dist x y ≤ C * dist (f x) (f y)) : proper_space β :=
begin
apply proper_space_of_compact_closed_ball_of_le 0 (λx₀ r hr, _),
let K := f ⁻¹' (closed_ball x₀ r),
have A : is_closed K :=
continuous_iff_is_closed.1 f_cont (closed_ball x₀ r) is_closed_ball,
have B : bounded K := ⟨max C 0 * (r + r), λx y hx hy, calc
dist x y ≤ C * dist (f x) (f y) : hC x y
... ≤ max C 0 * dist (f x) (f y) : mul_le_mul_of_nonneg_right (le_max_left _ _) (dist_nonneg)
... ≤ max C 0 * (dist (f x) x₀ + dist (f y) x₀) :
mul_le_mul_of_nonneg_left (dist_triangle_right (f x) (f y) x₀) (le_max_right _ _)
... ≤ max C 0 * (r + r) : begin
simp only [mem_closed_ball, mem_preimage] at hx hy,
exact mul_le_mul_of_nonneg_left (add_le_add hx hy) (le_max_right _ _)
end⟩,
have : is_compact K := compact_iff_closed_bounded.2 ⟨A, B⟩,
have C : is_compact (f '' K) := this.image f_cont,
have : f '' K = closed_ball x₀ r,
by { rw image_preimage_eq_of_subset, rw hf, exact subset_univ _ },
rwa this at C
end
end bounded
section diam
variables {s : set α} {x y z : α}
/-- The diameter of a set in a metric space. To get controllable behavior even when the diameter
should be infinite, we express it in terms of the emetric.diameter -/
def diam (s : set α) : ℝ := ennreal.to_real (emetric.diam s)
/-- The diameter of a set is always nonnegative -/
lemma diam_nonneg : 0 ≤ diam s := ennreal.to_real_nonneg
lemma diam_subsingleton (hs : s.subsingleton) : diam s = 0 :=
by simp only [diam, emetric.diam_subsingleton hs, ennreal.zero_to_real]
/-- The empty set has zero diameter -/
@[simp] lemma diam_empty : diam (∅ : set α) = 0 :=
diam_subsingleton subsingleton_empty
/-- A singleton has zero diameter -/
@[simp] lemma diam_singleton : diam ({x} : set α) = 0 :=
diam_subsingleton subsingleton_singleton
-- Does not work as a simp-lemma, since {x, y} reduces to (insert y {x})
lemma diam_pair : diam ({x, y} : set α) = dist x y :=
by simp only [diam, emetric.diam_pair, dist_edist]
-- Does not work as a simp-lemma, since {x, y, z} reduces to (insert z (insert y {x}))
lemma diam_triple :
metric.diam ({x, y, z} : set α) = max (max (dist x y) (dist x z)) (dist y z) :=
begin
simp only [metric.diam, emetric.diam_triple, dist_edist],
rw [ennreal.to_real_max, ennreal.to_real_max];
apply_rules [ne_of_lt, edist_lt_top, max_lt]
end
/-- If the distance between any two points in a set is bounded by some constant `C`,
then `ennreal.of_real C` bounds the emetric diameter of this set. -/
lemma ediam_le_of_forall_dist_le {C : ℝ} (h : ∀ (x ∈ s) (y ∈ s), dist x y ≤ C) :
emetric.diam s ≤ ennreal.of_real C :=
emetric.diam_le_of_forall_edist_le $
λ x hx y hy, (edist_dist x y).symm ▸ ennreal.of_real_le_of_real (h x hx y hy)
/-- If the distance between any two points in a set is bounded by some non-negative constant,
this constant bounds the diameter. -/
lemma diam_le_of_forall_dist_le {C : ℝ} (h₀ : 0 ≤ C) (h : ∀ (x ∈ s) (y ∈ s), dist x y ≤ C) :
diam s ≤ C :=
ennreal.to_real_le_of_le_of_real h₀ (ediam_le_of_forall_dist_le h)
/-- If the distance between any two points in a nonempty set is bounded by some constant,
this constant bounds the diameter. -/
lemma diam_le_of_forall_dist_le_of_nonempty (hs : s.nonempty) {C : ℝ}
(h : ∀ (x ∈ s) (y ∈ s), dist x y ≤ C) : diam s ≤ C :=
have h₀ : 0 ≤ C, from let ⟨x, hx⟩ := hs in le_trans dist_nonneg (h x hx x hx),
diam_le_of_forall_dist_le h₀ h
/-- The distance between two points in a set is controlled by the diameter of the set. -/
lemma dist_le_diam_of_mem' (h : emetric.diam s ≠ ⊤) (hx : x ∈ s) (hy : y ∈ s) :
dist x y ≤ diam s :=
begin
rw [diam, dist_edist],
rw ennreal.to_real_le_to_real (edist_ne_top _ _) h,
exact emetric.edist_le_diam_of_mem hx hy
end
/-- Characterize the boundedness of a set in terms of the finiteness of its emetric.diameter. -/
lemma bounded_iff_ediam_ne_top : bounded s ↔ emetric.diam s ≠ ⊤ :=
iff.intro
(λ ⟨C, hC⟩, ne_top_of_le_ne_top ennreal.of_real_ne_top
(ediam_le_of_forall_dist_le $ λ x hx y hy, hC x y hx hy))
(λ h, ⟨diam s, λ x y hx hy, dist_le_diam_of_mem' h hx hy⟩)
lemma bounded.ediam_ne_top (h : bounded s) : emetric.diam s ≠ ⊤ :=
bounded_iff_ediam_ne_top.1 h
/-- The distance between two points in a set is controlled by the diameter of the set. -/
lemma dist_le_diam_of_mem (h : bounded s) (hx : x ∈ s) (hy : y ∈ s) : dist x y ≤ diam s :=
dist_le_diam_of_mem' h.ediam_ne_top hx hy
/-- An unbounded set has zero diameter. If you would prefer to get the value ∞, use `emetric.diam`.
This lemma makes it possible to avoid side conditions in some situations -/
lemma diam_eq_zero_of_unbounded (h : ¬(bounded s)) : diam s = 0 :=
begin
simp only [bounded_iff_ediam_ne_top, not_not, ne.def] at h,
simp [diam, h]
end
/-- If `s ⊆ t`, then the diameter of `s` is bounded by that of `t`, provided `t` is bounded. -/
lemma diam_mono {s t : set α} (h : s ⊆ t) (ht : bounded t) : diam s ≤ diam t :=
begin
unfold diam,
rw ennreal.to_real_le_to_real (bounded.subset h ht).ediam_ne_top ht.ediam_ne_top,
exact emetric.diam_mono h
end
/-- The diameter of a union is controlled by the sum of the diameters, and the distance between
any two points in each of the sets. This lemma is true without any side condition, since it is
obviously true if `s ∪ t` is unbounded. -/
lemma diam_union {t : set α} (xs : x ∈ s) (yt : y ∈ t) : diam (s ∪ t) ≤ diam s + dist x y + diam t :=
begin
classical, by_cases H : bounded (s ∪ t),
{ have hs : bounded s, from H.subset (subset_union_left _ _),
have ht : bounded t, from H.subset (subset_union_right _ _),
rw [bounded_iff_ediam_ne_top] at H hs ht,
rw [dist_edist, diam, diam, diam, ← ennreal.to_real_add, ← ennreal.to_real_add,
ennreal.to_real_le_to_real];
repeat { apply ennreal.add_ne_top.2; split }; try { assumption };
try { apply edist_ne_top },
exact emetric.diam_union xs yt },
{ rw [diam_eq_zero_of_unbounded H],
apply_rules [add_nonneg, diam_nonneg, dist_nonneg] }
end
/-- If two sets intersect, the diameter of the union is bounded by the sum of the diameters. -/
lemma diam_union' {t : set α} (h : (s ∩ t).nonempty) : diam (s ∪ t) ≤ diam s + diam t :=
begin
rcases h with ⟨x, ⟨xs, xt⟩⟩,
simpa using diam_union xs xt
end
/-- The diameter of a closed ball of radius `r` is at most `2 r`. -/
lemma diam_closed_ball {r : ℝ} (h : 0 ≤ r) : diam (closed_ball x r) ≤ 2 * r :=
diam_le_of_forall_dist_le (mul_nonneg (le_of_lt zero_lt_two) h) $ λa ha b hb, calc
dist a b ≤ dist a x + dist b x : dist_triangle_right _ _ _
... ≤ r + r : add_le_add ha hb
... = 2 * r : by simp [mul_two, mul_comm]
/-- The diameter of a ball of radius `r` is at most `2 r`. -/
lemma diam_ball {r : ℝ} (h : 0 ≤ r) : diam (ball x r) ≤ 2 * r :=
le_trans (diam_mono ball_subset_closed_ball bounded_closed_ball) (diam_closed_ball h)
end diam
end metric
|
2c66fe5f115155aacaff2a03990d4211bdf3c7e8 | fef48cac17c73db8662678da38fd75888db97560 | /src/point6.lean | 06c9e72b6ee5f870c22b72c44ee2fa2b7522b5c0 | [] | no_license | kbuzzard/lean-squares-in-fibonacci | 6c0d924f799d6751e19798bb2530ee602ec7087e | 8cea20e5ce88ab7d17b020932d84d316532a84a8 | refs/heads/master | 1,584,524,504,815 | 1,582,387,156,000 | 1,582,387,156,000 | 134,576,655 | 3 | 1 | null | 1,541,538,497,000 | 1,527,083,406,000 | Lean | UTF-8 | Lean | false | false | 2,068 | lean | import definitions
import point3
-- 2F(m+n) = F(m) L(n) + L(m) F(n)
lemma two_mul_Fib_add (m n : ℤ) : 2 * Fib (m + n) = Fib m * Luc n + Luc m * Fib n :=
by rw [Fib, Fib, Fib, Luc, Luc, gpow_add, units.coe_mul, Zalpha.mul_r, two_mul];
rw [α_Fib, α_Fib, β_Fib, β_Fib];
have Hm := Fib_add_two (m-1);
have Hn := Fib_add_two (n-1);
rw [bit0, ← add_assoc, sub_add_cancel] at Hm Hn;
simp [Hm, Hn, mul_add, add_mul]
lemma two_mul_fib_add (m n : ℕ) : 2 * fib (m + n) = fib m * luc n + luc m * fib n :=
int.coe_nat_inj $ by rw [int.coe_nat_add, int.coe_nat_mul, int.coe_nat_mul, int.coe_nat_mul];
rw [← fib_down, ← fib_down, ← fib_down, ← luc_down, ← luc_down, ← two_mul_Fib_add]; refl
-- L(4n) + 2 = L(2n)^2
lemma Luc_four_mul (n : ℤ) : Luc (4 * n) = Luc (2 * n) * Luc (2 * n) - 2 :=
Zalpha.of_int_inj.1 $ by have := Luc_αβ; simp at this;
simp [this, add_mul, mul_add];
rw [← units.coe_mul, ← units.coe_mul, ← units.coe_mul, ← units.coe_mul];
rw [← mul_gpow, ← mul_gpow, ← mul_gpow, ← mul_gpow]; simp;
rw [gpow_mul (-1 : units ℤα)];
have : (-1 : units ℤα)^(2:ℤ) = 1 := rfl;
simp [this]; rw [bit0, add_mul, gpow_add, gpow_add, mul_gpow, mul_gpow]; ring
lemma luc_four_mul (n : ℕ) : luc (4 * n) + 2 = luc (2 * n) * luc (2 * n) :=
int.coe_nat_inj $ begin
simp, rw [← luc_down, ← luc_down],
change (2 : ℤ) + Luc (4 * n) = _,
rw [Luc_four_mul]; ring end
-- F(2n) = F(n) L(n)
lemma fib_two_mul (n : ℕ) : fib (2 * n) = fib n * luc n :=
nat.bit0_inj $ by rw [bit0, ← two_mul, two_mul n, two_mul_fib_add, mul_comm]; refl
-- L(2n) ∣ 2(F(m+4n) + F(m))
lemma luc_two_mul_dvd (m n : ℕ) : luc (2 * n) ∣ 2 * (fib (m + 4 * n) + fib m) :=
⟨luc (2 * n) * fib m + luc m * fib (2 * n),
by rw [mul_add, mul_add, two_mul_fib_add, mul_comm (fib m), add_right_comm, ← add_mul, luc_four_mul];
conv in (4 * n) { change ((2 * 2) * n) };
rw [mul_assoc 2, fib_two_mul]; ac_refl⟩
-- TODO: if ¬(3 ∣ n) then fib (m + 4*n) ≡ −fib m [MOD (luc (2*n))] |
24fb7021ed14a5d8133ea0c2a7bcd2ecf9d878ad | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/number_theory/ramification_inertia.lean | 91585ce4cc595a12582ad251ce67400e04dcdaf6 | [
"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 | 39,158 | lean | /-
Copyright (c) 2022 Anne Baanen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anne Baanen
-/
import linear_algebra.free_module.finite.rank
import ring_theory.dedekind_domain.ideal
/-!
# Ramification index and inertia degree
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
Given `P : ideal S` lying over `p : ideal R` for the ring extension `f : R →+* S`
(assuming `P` and `p` are prime or maximal where needed),
the **ramification index** `ideal.ramification_idx f p P` is the multiplicity of `P` in `map f p`,
and the **inertia degree** `ideal.inertia_deg f p P` is the degree of the field extension
`(S / P) : (R / p)`.
## Main results
The main theorem `ideal.sum_ramification_inertia` states that for all coprime `P` lying over `p`,
`Σ P, ramification_idx f p P * inertia_deg f p P` equals the degree of the field extension
`Frac(S) : Frac(R)`.
## Implementation notes
Often the above theory is set up in the case where:
* `R` is the ring of integers of a number field `K`,
* `L` is a finite separable extension of `K`,
* `S` is the integral closure of `R` in `L`,
* `p` and `P` are maximal ideals,
* `P` is an ideal lying over `p`
We will try to relax the above hypotheses as much as possible.
## Notation
In this file, `e` stands for the ramification index and `f` for the inertia degree of `P` over `p`,
leaving `p` and `P` implicit.
-/
namespace ideal
universes u v
variables {R : Type u} [comm_ring R]
variables {S : Type v} [comm_ring S] (f : R →+* S)
variables (p : ideal R) (P : ideal S)
open finite_dimensional
open unique_factorization_monoid
section dec_eq
open_locale classical
/-- The ramification index of `P` over `p` is the largest exponent `n` such that
`p` is contained in `P^n`.
In particular, if `p` is not contained in `P^n`, then the ramification index is 0.
If there is no largest such `n` (e.g. because `p = ⊥`), then `ramification_idx` is
defined to be 0.
-/
noncomputable def ramification_idx : ℕ :=
Sup {n | map f p ≤ P ^ n}
variables {f p P}
lemma ramification_idx_eq_find (h : ∃ n, ∀ k, map f p ≤ P ^ k → k ≤ n) :
ramification_idx f p P = nat.find h :=
nat.Sup_def h
lemma ramification_idx_eq_zero (h : ∀ n : ℕ, ∃ k, map f p ≤ P ^ k ∧ n < k) :
ramification_idx f p P = 0 :=
dif_neg (by push_neg; exact h)
lemma ramification_idx_spec {n : ℕ} (hle : map f p ≤ P ^ n) (hgt : ¬ map f p ≤ P ^ (n + 1)) :
ramification_idx f p P = n :=
begin
have : ∀ (k : ℕ), map f p ≤ P ^ k → k ≤ n,
{ intros k hk,
refine le_of_not_lt (λ hnk, _),
exact hgt (hk.trans (ideal.pow_le_pow hnk)) },
rw ramification_idx_eq_find ⟨n, this⟩,
{ refine le_antisymm (nat.find_min' _ this) (le_of_not_gt (λ (h : nat.find _ < n), _)),
obtain this' := nat.find_spec ⟨n, this⟩,
exact h.not_le (this' _ hle) },
end
lemma ramification_idx_lt {n : ℕ} (hgt : ¬ (map f p ≤ P ^ n)) :
ramification_idx f p P < n :=
begin
cases n,
{ simpa using hgt },
rw nat.lt_succ_iff,
have : ∀ k, map f p ≤ P ^ k → k ≤ n,
{ refine λ k hk, le_of_not_lt (λ hnk, _),
exact hgt (hk.trans (ideal.pow_le_pow hnk)) },
rw ramification_idx_eq_find ⟨n, this⟩,
exact nat.find_min' ⟨n, this⟩ this
end
@[simp] lemma ramification_idx_bot : ramification_idx f ⊥ P = 0 :=
dif_neg $ not_exists.mpr $ λ n hn, n.lt_succ_self.not_le (hn _ (by simp))
@[simp] lemma ramification_idx_of_not_le (h : ¬ map f p ≤ P) : ramification_idx f p P = 0 :=
ramification_idx_spec (by simp) (by simpa using h)
lemma ramification_idx_ne_zero {e : ℕ} (he : e ≠ 0)
(hle : map f p ≤ P ^ e) (hnle : ¬ map f p ≤ P ^ (e + 1)):
ramification_idx f p P ≠ 0 :=
by rwa ramification_idx_spec hle hnle
lemma le_pow_of_le_ramification_idx {n : ℕ} (hn : n ≤ ramification_idx f p P) :
map f p ≤ P ^ n :=
begin
contrapose! hn,
exact ramification_idx_lt hn
end
lemma le_pow_ramification_idx :
map f p ≤ P ^ ramification_idx f p P :=
le_pow_of_le_ramification_idx (le_refl _)
lemma le_comap_pow_ramification_idx :
p ≤ comap f (P ^ ramification_idx f p P) :=
map_le_iff_le_comap.mp le_pow_ramification_idx
lemma le_comap_of_ramification_idx_ne_zero (h : ramification_idx f p P ≠ 0) : p ≤ comap f P :=
ideal.map_le_iff_le_comap.mp $ le_pow_ramification_idx.trans $ ideal.pow_le_self $ h
namespace is_dedekind_domain
variables [is_domain S] [is_dedekind_domain S]
lemma ramification_idx_eq_normalized_factors_count
(hp0 : map f p ≠ ⊥) (hP : P.is_prime) (hP0 : P ≠ ⊥) :
ramification_idx f p P = (normalized_factors (map f p)).count P :=
begin
have hPirr := (ideal.prime_of_is_prime hP0 hP).irreducible,
refine ramification_idx_spec (ideal.le_of_dvd _) (mt ideal.dvd_iff_le.mpr _);
rw [dvd_iff_normalized_factors_le_normalized_factors (pow_ne_zero _ hP0) hp0,
normalized_factors_pow, normalized_factors_irreducible hPirr, normalize_eq,
multiset.nsmul_singleton, ← multiset.le_count_iff_replicate_le],
{ exact (nat.lt_succ_self _).not_le },
end
lemma ramification_idx_eq_factors_count (hp0 : map f p ≠ ⊥) (hP : P.is_prime) (hP0 : P ≠ ⊥) :
ramification_idx f p P = (factors (map f p)).count P :=
by rw [is_dedekind_domain.ramification_idx_eq_normalized_factors_count hp0 hP hP0,
factors_eq_normalized_factors]
lemma ramification_idx_ne_zero (hp0 : map f p ≠ ⊥) (hP : P.is_prime) (le : map f p ≤ P) :
ramification_idx f p P ≠ 0 :=
begin
have hP0 : P ≠ ⊥,
{ unfreezingI { rintro rfl },
have := le_bot_iff.mp le,
contradiction },
have hPirr := (ideal.prime_of_is_prime hP0 hP).irreducible,
rw is_dedekind_domain.ramification_idx_eq_normalized_factors_count hp0 hP hP0,
obtain ⟨P', hP', P'_eq⟩ :=
exists_mem_normalized_factors_of_dvd hp0 hPirr (ideal.dvd_iff_le.mpr le),
rwa [multiset.count_ne_zero, associated_iff_eq.mp P'_eq],
end
end is_dedekind_domain
variables (f p P)
local attribute [instance] ideal.quotient.field
/-- The inertia degree of `P : ideal S` lying over `p : ideal R` is the degree of the
extension `(S / P) : (R / p)`.
We do not assume `P` lies over `p` in the definition; we return `0` instead.
See `inertia_deg_algebra_map` for the common case where `f = algebra_map R S`
and there is an algebra structure `R / p → S / P`.
-/
noncomputable def inertia_deg [hp : p.is_maximal] : ℕ :=
if hPp : comap f P = p
then @finrank (R ⧸ p) (S ⧸ P) _ _ $ @algebra.to_module _ _ _ _ $ ring_hom.to_algebra $
ideal.quotient.lift p (P^.quotient.mk^.comp f) $
λ a ha, quotient.eq_zero_iff_mem.mpr $ mem_comap.mp $ hPp.symm ▸ ha
else 0
-- Useful for the `nontriviality` tactic using `comap_eq_of_scalar_tower_quotient`.
@[simp] lemma inertia_deg_of_subsingleton [hp : p.is_maximal] [hQ : subsingleton (S ⧸ P)] :
inertia_deg f p P = 0 :=
begin
have := ideal.quotient.subsingleton_iff.mp hQ,
unfreezingI { subst this },
exact dif_neg (λ h, hp.ne_top $ h.symm.trans comap_top)
end
@[simp] lemma inertia_deg_algebra_map [algebra R S] [algebra (R ⧸ p) (S ⧸ P)]
[is_scalar_tower R (R ⧸ p) (S ⧸ P)]
[hp : p.is_maximal] :
inertia_deg (algebra_map R S) p P = finrank (R ⧸ p) (S ⧸ P) :=
begin
nontriviality (S ⧸ P) using [inertia_deg_of_subsingleton, finrank_zero_of_subsingleton],
have := comap_eq_of_scalar_tower_quotient (algebra_map (R ⧸ p) (S ⧸ P)).injective,
rw [inertia_deg, dif_pos this],
congr,
refine algebra.algebra_ext _ _ (λ x', quotient.induction_on' x' $ λ x, _),
change ideal.quotient.lift p _ _ (ideal.quotient.mk p x) =
algebra_map _ _ (ideal.quotient.mk p x),
rw [ideal.quotient.lift_mk, ← ideal.quotient.algebra_map_eq, ← is_scalar_tower.algebra_map_eq,
← ideal.quotient.algebra_map_eq, ← is_scalar_tower.algebra_map_apply]
end
end dec_eq
section finrank_quotient_map
open_locale big_operators
open_locale non_zero_divisors
variables [algebra R S]
variables {K : Type*} [field K] [algebra R K] [hRK : is_fraction_ring R K]
variables {L : Type*} [field L] [algebra S L] [is_fraction_ring S L]
variables {V V' V'' : Type*}
variables [add_comm_group V] [module R V] [module K V] [is_scalar_tower R K V]
variables [add_comm_group V'] [module R V'] [module S V'] [is_scalar_tower R S V']
variables [add_comm_group V''] [module R V'']
variables (K)
include hRK
/-- Let `V` be a vector space over `K = Frac(R)`, `S / R` a ring extension
and `V'` a module over `S`. If `b`, in the intersection `V''` of `V` and `V'`,
is linear independent over `S` in `V'`, then it is linear independent over `R` in `V`.
The statement we prove is actually slightly more general:
* it suffices that the inclusion `algebra_map R S : R → S` is nontrivial
* the function `f' : V'' → V'` doesn't need to be injective
-/
lemma finrank_quotient_map.linear_independent_of_nontrivial
[is_domain R] [is_dedekind_domain R] (hRS : (algebra_map R S).ker ≠ ⊤)
(f : V'' →ₗ[R] V) (hf : function.injective f) (f' : V'' →ₗ[R] V')
{ι : Type*} {b : ι → V''} (hb' : linear_independent S (f' ∘ b)) :
linear_independent K (f ∘ b) :=
begin
contrapose! hb' with hb,
-- Informally, if we have a nontrivial linear dependence with coefficients `g` in `K`,
-- then we can find a linear dependence with coefficients `I.quotient.mk g'` in `R/I`,
-- where `I = ker (algebra_map R S)`.
-- We make use of the same principle but stay in `R` everywhere.
simp only [linear_independent_iff', not_forall] at hb ⊢,
obtain ⟨s, g, eq, j', hj's, hj'g⟩ := hb,
use s,
obtain ⟨a, hag, j, hjs, hgI⟩ :=
ideal.exist_integer_multiples_not_mem hRS s g hj's hj'g,
choose g'' hg'' using hag,
letI := classical.prop_decidable,
let g' := λ i, if h : i ∈ s then g'' i h else 0,
have hg' : ∀ i ∈ s, algebra_map _ _ (g' i) = a * g i,
{ intros i hi, exact (congr_arg _ (dif_pos hi)).trans (hg'' i hi) },
-- Because `R/I` is nontrivial, we can lift `g` to a nontrivial linear dependence in `S`.
have hgI : algebra_map R S (g' j) ≠ 0,
{ simp only [fractional_ideal.mem_coe_ideal, not_exists, not_and'] at hgI,
exact hgI _ (hg' j hjs) },
refine ⟨λ i, algebra_map R S (g' i), _, j, hjs, hgI⟩,
have eq : f (∑ i in s, g' i • (b i)) = 0,
{ rw [linear_map.map_sum, ← smul_zero a, ← eq, finset.smul_sum, finset.sum_congr rfl],
intros i hi,
rw [linear_map.map_smul, ← is_scalar_tower.algebra_map_smul K, hg' i hi, ← smul_assoc,
smul_eq_mul],
apply_instance },
simp only [is_scalar_tower.algebra_map_smul, ← linear_map.map_smul, ← linear_map.map_sum,
(f.map_eq_zero_iff hf).mp eq, linear_map.map_zero],
end
open_locale matrix
variables {K}
omit hRK
/-- If `b` mod `p` spans `S/p` as `R/p`-space, then `b` itself spans `Frac(S)` as `K`-space.
Here,
* `p` is an ideal of `R` such that `R / p` is nontrivial
* `K` is a field that has an embedding of `R` (in particular we can take `K = Frac(R)`)
* `L` is a field extension of `K`
* `S` is the integral closure of `R` in `L`
More precisely, we avoid quotients in this statement and instead require that `b ∪ pS` spans `S`.
-/
lemma finrank_quotient_map.span_eq_top [is_domain R] [is_domain S] [algebra K L] [is_noetherian R S]
[algebra R L] [is_scalar_tower R S L] [is_scalar_tower R K L] [is_integral_closure S R L]
[no_zero_smul_divisors R K]
(hp : p ≠ ⊤)
(b : set S) (hb' : submodule.span R b ⊔ (p.map (algebra_map R S)).restrict_scalars R = ⊤) :
submodule.span K (algebra_map S L '' b) = ⊤ :=
begin
have hRL : function.injective (algebra_map R L),
{ rw is_scalar_tower.algebra_map_eq R K L,
exact (algebra_map K L).injective.comp (no_zero_smul_divisors.algebra_map_injective R K) },
-- Let `M` be the `R`-module spanned by the proposed basis elements.
set M : submodule R S := submodule.span R b with hM,
-- Then `S / M` is generated by some finite set of `n` vectors `a`.
letI h : module.finite R (S ⧸ M) :=
module.finite.of_surjective (submodule.mkq _) (submodule.quotient.mk_surjective _),
obtain ⟨n, a, ha⟩ := @@module.finite.exists_fin _ _ _ h,
-- Because the image of `p` in `S / M` is `⊤`,
have smul_top_eq : p • (⊤ : submodule R (S ⧸ M)) = ⊤,
{ calc p • ⊤ = submodule.map M.mkq (p • ⊤) :
by rw [submodule.map_smul'', submodule.map_top, M.range_mkq]
... = ⊤ : by rw [ideal.smul_top_eq_map, (submodule.map_mkq_eq_top M _).mpr hb'] },
-- we can write the elements of `a` as `p`-linear combinations of other elements of `a`.
have exists_sum : ∀ x : (S ⧸ M), ∃ a' : fin n → R, (∀ i, a' i ∈ p) ∧ ∑ i, a' i • a i = x,
{ intro x,
obtain ⟨a'', ha'', hx⟩ := (submodule.mem_ideal_smul_span_iff_exists_sum p a x).1 _,
{ refine ⟨λ i, a'' i, λ i, ha'' _, _⟩,
rw [← hx, finsupp.sum_fintype],
exact λ _, zero_smul _ _ },
{ rw [ha, smul_top_eq],
exact submodule.mem_top } },
choose A' hA'p hA' using λ i, exists_sum (a i),
-- This gives us a(n invertible) matrix `A` such that `det A ∈ (M = span R b)`,
let A : matrix (fin n) (fin n) R := A' - 1,
let B := A.adjugate,
have A_smul : ∀ i, ∑ j, A i j • a j = 0,
{ intros,
simp only [A, pi.sub_apply, sub_smul, finset.sum_sub_distrib, hA', matrix.one_apply, ite_smul,
one_smul, zero_smul, finset.sum_ite_eq, finset.mem_univ, if_true, sub_self] },
-- since `span S {det A} / M = 0`.
have d_smul : ∀ i, A.det • a i = 0,
{ intro i,
calc A.det • a i = ∑ j, (B ⬝ A) i j • a j : _
... = ∑ k, B i k • ∑ j, (A k j • a j) : _
... = 0 : finset.sum_eq_zero (λ k _, _),
{ simp only [matrix.adjugate_mul, pi.smul_apply, matrix.one_apply, mul_ite, ite_smul,
smul_eq_mul, mul_one, mul_zero, one_smul, zero_smul, finset.sum_ite_eq, finset.mem_univ,
if_true] },
{ simp only [matrix.mul_apply, finset.smul_sum, finset.sum_smul, smul_smul],
rw finset.sum_comm },
{ rw [A_smul, smul_zero] } },
-- In the rings of integers we have the desired inclusion.
have span_d : (submodule.span S ({algebra_map R S A.det} : set S)).restrict_scalars R ≤ M,
{ intros x hx,
rw submodule.restrict_scalars_mem at hx,
obtain ⟨x', rfl⟩ := submodule.mem_span_singleton.mp hx,
rw [smul_eq_mul, mul_comm, ← algebra.smul_def] at ⊢ hx,
rw [← submodule.quotient.mk_eq_zero, submodule.quotient.mk_smul],
obtain ⟨a', _, quot_x_eq⟩ := exists_sum (submodule.quotient.mk x'),
simp_rw [← quot_x_eq, finset.smul_sum, smul_comm A.det, d_smul, smul_zero,
finset.sum_const_zero] },
-- So now we lift everything to the fraction field.
refine top_le_iff.mp (calc ⊤ = (ideal.span {algebra_map R L A.det}).restrict_scalars K : _
... ≤ submodule.span K (algebra_map S L '' b) : _),
-- Because `det A ≠ 0`, we have `span L {det A} = ⊤`.
{ rw [eq_comm, submodule.restrict_scalars_eq_top_iff, ideal.span_singleton_eq_top],
refine is_unit.mk0 _ ((map_ne_zero_iff ((algebra_map R L)) hRL).mpr (
@ne_zero_of_map _ _ _ _ _ _ (ideal.quotient.mk p) _ _)),
haveI := ideal.quotient.nontrivial hp,
calc ideal.quotient.mk p (A.det)
= matrix.det ((ideal.quotient.mk p).map_matrix A) :
by rw [ring_hom.map_det, ring_hom.map_matrix_apply]
... = matrix.det ((ideal.quotient.mk p).map_matrix (A' - 1)) : rfl
... = matrix.det (λ i j, (ideal.quotient.mk p) (A' i j) -
(1 : matrix (fin n) (fin n) (R ⧸ p)) i j) : _
... = matrix.det (-1 : matrix (fin n) (fin n) (R ⧸ p)) : _
... = (-1 : R ⧸ p) ^ n : by rw [matrix.det_neg, fintype.card_fin, matrix.det_one, mul_one]
... ≠ 0 : is_unit.ne_zero (is_unit_one.neg.pow _),
{ refine congr_arg matrix.det (matrix.ext (λ i j, _)),
rw [map_sub, ring_hom.map_matrix_apply, map_one],
refl },
{ refine congr_arg matrix.det (matrix.ext (λ i j, _)),
rw [ideal.quotient.eq_zero_iff_mem.mpr (hA'p i j), zero_sub],
refl } },
-- And we conclude `L = span L {det A} ≤ span K b`, so `span K b` spans everything.
{ intros x hx,
rw [submodule.restrict_scalars_mem, is_scalar_tower.algebra_map_apply R S L] at hx,
refine is_fraction_ring.ideal_span_singleton_map_subset R _ hRL span_d hx,
haveI : no_zero_smul_divisors R L := no_zero_smul_divisors.of_algebra_map_injective hRL,
rw ← is_fraction_ring.is_algebraic_iff' R S,
intros x,
exact is_integral.is_algebraic _ (is_integral_of_noetherian infer_instance _) },
end
include hRK
variables (K L)
/-- If `p` is a maximal ideal of `R`, and `S` is the integral closure of `R` in `L`,
then the dimension `[S/pS : R/p]` is equal to `[Frac(S) : Frac(R)]`. -/
lemma finrank_quotient_map [is_domain R] [is_domain S] [is_dedekind_domain R]
[algebra K L] [algebra R L] [is_scalar_tower R K L] [is_scalar_tower R S L]
[is_integral_closure S R L]
[hp : p.is_maximal] [is_noetherian R S] :
finrank (R ⧸ p) (S ⧸ map (algebra_map R S) p) = finrank K L :=
begin
-- Choose an arbitrary basis `b` for `[S/pS : R/p]`.
-- We'll use the previous results to turn it into a basis on `[Frac(S) : Frac(R)]`.
letI : field (R ⧸ p) := ideal.quotient.field _,
let ι := module.free.choose_basis_index (R ⧸ p) (S ⧸ map (algebra_map R S) p),
let b : basis ι (R ⧸ p) (S ⧸ map (algebra_map R S) p) := module.free.choose_basis _ _,
-- Namely, choose a representative `b' i : S` for each `b i : S / pS`.
let b' : ι → S := λ i, (ideal.quotient.mk_surjective (b i)).some,
have b_eq_b' : ⇑ b = (submodule.mkq _).restrict_scalars R ∘ b' :=
funext (λ i, (ideal.quotient.mk_surjective (b i)).some_spec.symm),
-- We claim `b'` is a basis for `Frac(S)` over `Frac(R)` because it is linear independent
-- and spans the whole of `Frac(S)`.
let b'' : ι → L := algebra_map S L ∘ b',
have b''_li : linear_independent _ b'' := _,
have b''_sp : submodule.span _ (set.range b'') = ⊤ := _,
-- Since the two bases have the same index set, the spaces have the same dimension.
let c : basis ι K L := basis.mk b''_li b''_sp.ge,
rw [finrank_eq_card_basis b, finrank_eq_card_basis c],
-- It remains to show that the basis is indeed linear independent and spans the whole space.
{ rw set.range_comp,
refine finrank_quotient_map.span_eq_top p hp.ne_top _ (top_le_iff.mp _),
-- The nicest way to show `S ≤ span b' ⊔ pS` is by reducing both sides modulo pS.
-- However, this would imply distinguishing between `pS` as `S`-ideal,
-- and `pS` as `R`-submodule, since they have different (non-defeq) quotients.
-- Instead we'll lift `x mod pS ∈ span b` to `y ∈ span b'` for some `y - x ∈ pS`.
intros x hx,
have mem_span_b :
((submodule.mkq (map (algebra_map R S) p)) x :
S ⧸ map (algebra_map R S) p) ∈ submodule.span (R ⧸ p) (set.range b) := b.mem_span _,
rw [← @submodule.restrict_scalars_mem R,
submodule.restrict_scalars_span R (R ⧸ p) ideal.quotient.mk_surjective,
b_eq_b', set.range_comp, ← submodule.map_span]
at mem_span_b,
obtain ⟨y, y_mem, y_eq⟩ := submodule.mem_map.mp mem_span_b,
suffices : y + -(y - x) ∈ _, { simpa },
rw [linear_map.restrict_scalars_apply, submodule.mkq_apply, submodule.mkq_apply,
submodule.quotient.eq] at y_eq,
exact add_mem (submodule.mem_sup_left y_mem) (neg_mem $ submodule.mem_sup_right y_eq) },
{ have := b.linear_independent, rw b_eq_b' at this,
convert finrank_quotient_map.linear_independent_of_nontrivial K _
((algebra.linear_map S L).restrict_scalars R) _
((submodule.mkq _).restrict_scalars R)
this,
{ rw [quotient.algebra_map_eq, ideal.mk_ker],
exact hp.ne_top },
{ exact is_fraction_ring.injective S L } },
end
end finrank_quotient_map
section fact_le_comap
local notation `e` := ramification_idx f p P
/-- `R / p` has a canonical map to `S / (P ^ e)`, where `e` is the ramification index
of `P` over `p`. -/
noncomputable instance quotient.algebra_quotient_pow_ramification_idx :
algebra (R ⧸ p) (S ⧸ (P ^ e)) :=
quotient.algebra_quotient_of_le_comap (ideal.map_le_iff_le_comap.mp le_pow_ramification_idx)
@[simp] lemma quotient.algebra_map_quotient_pow_ramification_idx (x : R) :
algebra_map (R ⧸ p) (S ⧸ P ^ e) (ideal.quotient.mk p x) = ideal.quotient.mk _ (f x) :=
rfl
variables [hfp : ne_zero (ramification_idx f p P)]
include hfp
/-- If `P` lies over `p`, then `R / p` has a canonical map to `S / P`.
This can't be an instance since the map `f : R → S` is generally not inferrable.
-/
def quotient.algebra_quotient_of_ramification_idx_ne_zero :
algebra (R ⧸ p) (S ⧸ P) :=
quotient.algebra_quotient_of_le_comap (le_comap_of_ramification_idx_ne_zero hfp.out)
-- In this file, the value for `f` can be inferred.
local attribute [instance] ideal.quotient.algebra_quotient_of_ramification_idx_ne_zero
@[simp] lemma quotient.algebra_map_quotient_of_ramification_idx_ne_zero (x : R) :
algebra_map (R ⧸ p) (S ⧸ P) (ideal.quotient.mk p x) = ideal.quotient.mk _ (f x) :=
rfl
omit hfp
/-- The inclusion `(P^(i + 1) / P^e) ⊂ (P^i / P^e)`. -/
@[simps]
def pow_quot_succ_inclusion (i : ℕ) :
ideal.map (P^e)^.quotient.mk (P ^ (i + 1)) →ₗ[R ⧸ p] ideal.map (P^e)^.quotient.mk (P ^ i) :=
{ to_fun := λ x, ⟨x, ideal.map_mono (ideal.pow_le_pow i.le_succ) x.2⟩,
map_add' := λ x y, rfl,
map_smul' := λ c x, rfl }
lemma pow_quot_succ_inclusion_injective (i : ℕ) :
function.injective (pow_quot_succ_inclusion f p P i) :=
begin
rw [← linear_map.ker_eq_bot, linear_map.ker_eq_bot'],
rintro ⟨x, hx⟩ hx0,
rw subtype.ext_iff at hx0 ⊢,
rwa pow_quot_succ_inclusion_apply_coe at hx0
end
/-- `S ⧸ P` embeds into the quotient by `P^(i+1) ⧸ P^e` as a subspace of `P^i ⧸ P^e`.
See `quotient_to_quotient_range_pow_quot_succ` for this as a linear map,
and `quotient_range_pow_quot_succ_inclusion_equiv` for this as a linear equivalence.
-/
noncomputable def quotient_to_quotient_range_pow_quot_succ_aux {i : ℕ} {a : S} (a_mem : a ∈ P^i) :
S ⧸ P → ((P ^ i).map (P ^ e)^.quotient.mk ⧸ (pow_quot_succ_inclusion f p P i).range) :=
quotient.map' (λ (x : S), ⟨_, ideal.mem_map_of_mem _ (ideal.mul_mem_left _ x a_mem)⟩)
(λ x y h, begin
rw submodule.quotient_rel_r_def at ⊢ h,
simp only [_root_.map_mul, linear_map.mem_range],
refine ⟨⟨_, ideal.mem_map_of_mem _ (ideal.mul_mem_mul h a_mem)⟩, _⟩,
ext,
rw [pow_quot_succ_inclusion_apply_coe, subtype.coe_mk, submodule.coe_sub, subtype.coe_mk,
subtype.coe_mk, _root_.map_mul, map_sub, sub_mul]
end)
lemma quotient_to_quotient_range_pow_quot_succ_aux_mk {i : ℕ} {a : S} (a_mem : a ∈ P^i) (x : S) :
quotient_to_quotient_range_pow_quot_succ_aux f p P a_mem (submodule.quotient.mk x) =
submodule.quotient.mk ⟨_, ideal.mem_map_of_mem _ (ideal.mul_mem_left _ x a_mem)⟩ :=
by apply quotient.map'_mk'
include hfp
/-- `S ⧸ P` embeds into the quotient by `P^(i+1) ⧸ P^e` as a subspace of `P^i ⧸ P^e`. -/
noncomputable def quotient_to_quotient_range_pow_quot_succ {i : ℕ} {a : S} (a_mem : a ∈ P^i) :
S ⧸ P →ₗ[R ⧸ p] ((P ^ i).map (P ^ e)^.quotient.mk ⧸ (pow_quot_succ_inclusion f p P i).range) :=
{ to_fun := quotient_to_quotient_range_pow_quot_succ_aux f p P a_mem,
map_add' := begin
intros x y, refine quotient.induction_on' x (λ x, quotient.induction_on' y (λ y, _)),
simp only [submodule.quotient.mk'_eq_mk, ← submodule.quotient.mk_add,
quotient_to_quotient_range_pow_quot_succ_aux_mk, add_mul],
refine congr_arg submodule.quotient.mk _,
ext,
refl
end,
map_smul' := begin
intros x y, refine quotient.induction_on' x (λ x, quotient.induction_on' y (λ y, _)),
simp only [submodule.quotient.mk'_eq_mk, ← submodule.quotient.mk_add,
quotient_to_quotient_range_pow_quot_succ_aux_mk, ring_hom.id_apply],
refine congr_arg submodule.quotient.mk _,
ext,
simp only [subtype.coe_mk, _root_.map_mul, algebra.smul_def, submodule.coe_mk, mul_assoc,
ideal.quotient.mk_eq_mk, submodule.coe_smul_of_tower,
ideal.quotient.algebra_map_quotient_pow_ramification_idx]
end }
lemma quotient_to_quotient_range_pow_quot_succ_mk {i : ℕ} {a : S} (a_mem : a ∈ P^i) (x : S) :
quotient_to_quotient_range_pow_quot_succ f p P a_mem (submodule.quotient.mk x) =
submodule.quotient.mk ⟨_, ideal.mem_map_of_mem _ (ideal.mul_mem_left _ x a_mem)⟩ :=
quotient_to_quotient_range_pow_quot_succ_aux_mk f p P a_mem x
lemma quotient_to_quotient_range_pow_quot_succ_injective [is_domain S] [is_dedekind_domain S]
[P.is_prime] {i : ℕ} (hi : i < e) {a : S} (a_mem : a ∈ P^i) (a_not_mem : a ∉ P^(i + 1)) :
function.injective (quotient_to_quotient_range_pow_quot_succ f p P a_mem) :=
λ x, quotient.induction_on' x $ λ x y, quotient.induction_on' y $ λ y h,
begin
have Pe_le_Pi1 : P^e ≤ P^(i + 1) := ideal.pow_le_pow hi,
simp only [submodule.quotient.mk'_eq_mk, quotient_to_quotient_range_pow_quot_succ_mk,
submodule.quotient.eq, linear_map.mem_range, subtype.ext_iff, subtype.coe_mk,
submodule.coe_sub] at ⊢ h,
rcases h with ⟨⟨⟨z⟩, hz⟩, h⟩,
rw [submodule.quotient.quot_mk_eq_mk, ideal.quotient.mk_eq_mk, ideal.mem_quotient_iff_mem_sup,
sup_eq_left.mpr Pe_le_Pi1] at hz,
rw [pow_quot_succ_inclusion_apply_coe, subtype.coe_mk, submodule.quotient.quot_mk_eq_mk,
ideal.quotient.mk_eq_mk, ← map_sub, ideal.quotient.eq, ← sub_mul] at h,
exact (ideal.is_prime.mul_mem_pow _
((submodule.sub_mem_iff_right _ hz).mp (Pe_le_Pi1 h))).resolve_right a_not_mem,
end
lemma quotient_to_quotient_range_pow_quot_succ_surjective [is_domain S] [is_dedekind_domain S]
(hP0 : P ≠ ⊥) [hP : P.is_prime] {i : ℕ} (hi : i < e)
{a : S} (a_mem : a ∈ P^i) (a_not_mem : a ∉ P^(i + 1)) :
function.surjective (quotient_to_quotient_range_pow_quot_succ f p P a_mem) :=
begin
rintro ⟨⟨⟨x⟩, hx⟩⟩,
have Pe_le_Pi : P^e ≤ P^i := ideal.pow_le_pow hi.le,
have Pe_le_Pi1 : P^e ≤ P^(i + 1) := ideal.pow_le_pow hi,
rw [submodule.quotient.quot_mk_eq_mk, ideal.quotient.mk_eq_mk, ideal.mem_quotient_iff_mem_sup,
sup_eq_left.mpr Pe_le_Pi] at hx,
suffices hx' : x ∈ ideal.span {a} ⊔ P^(i+1),
{ obtain ⟨y', hy', z, hz, rfl⟩ := submodule.mem_sup.mp hx',
obtain ⟨y, rfl⟩ := ideal.mem_span_singleton.mp hy',
refine ⟨submodule.quotient.mk y, _⟩,
simp only [submodule.quotient.quot_mk_eq_mk, quotient_to_quotient_range_pow_quot_succ_mk,
submodule.quotient.eq, linear_map.mem_range, subtype.ext_iff, subtype.coe_mk,
submodule.coe_sub],
refine ⟨⟨_, ideal.mem_map_of_mem _ (submodule.neg_mem _ hz)⟩, _⟩,
rw [pow_quot_succ_inclusion_apply_coe, subtype.coe_mk, ideal.quotient.mk_eq_mk, map_add,
mul_comm y a, sub_add_cancel', map_neg] },
letI := classical.dec_eq (ideal S),
rw [sup_eq_prod_inf_factors _ (pow_ne_zero _ hP0), normalized_factors_pow,
normalized_factors_irreducible ((ideal.prime_iff_is_prime hP0).mpr hP).irreducible,
normalize_eq, multiset.nsmul_singleton, multiset.inter_replicate, multiset.prod_replicate],
rw [← submodule.span_singleton_le_iff_mem, ideal.submodule_span_eq] at a_mem a_not_mem,
rwa [ideal.count_normalized_factors_eq a_mem a_not_mem, min_eq_left i.le_succ],
{ intro ha,
rw ideal.span_singleton_eq_bot.mp ha at a_not_mem,
have := (P^(i+1)).zero_mem,
contradiction },
end
/-- Quotienting `P^i / P^e` by its subspace `P^(i+1) ⧸ P^e` is
`R ⧸ p`-linearly isomorphic to `S ⧸ P`. -/
noncomputable def quotient_range_pow_quot_succ_inclusion_equiv [is_domain S] [is_dedekind_domain S]
[P.is_prime] (hP : P ≠ ⊥) {i : ℕ} (hi : i < e) :
((P ^ i).map (P ^ e)^.quotient.mk ⧸ (pow_quot_succ_inclusion f p P i).range) ≃ₗ[R ⧸ p] S ⧸ P :=
begin
choose a a_mem a_not_mem using set_like.exists_of_lt
(ideal.strict_anti_pow P hP (ideal.is_prime.ne_top infer_instance) (le_refl i.succ)),
refine (linear_equiv.of_bijective _ ⟨_, _⟩).symm,
{ exact quotient_to_quotient_range_pow_quot_succ f p P a_mem },
{ exact quotient_to_quotient_range_pow_quot_succ_injective f p P hi a_mem a_not_mem },
{ exact quotient_to_quotient_range_pow_quot_succ_surjective f p P hP hi a_mem a_not_mem }
end
/-- Since the inclusion `(P^(i + 1) / P^e) ⊂ (P^i / P^e)` has a kernel isomorphic to `P / S`,
`[P^i / P^e : R / p] = [P^(i+1) / P^e : R / p] + [P / S : R / p]` -/
lemma rank_pow_quot_aux [is_domain S] [is_dedekind_domain S] [p.is_maximal] [P.is_prime]
(hP0 : P ≠ ⊥) {i : ℕ} (hi : i < e) :
module.rank (R ⧸ p) (ideal.map (P^e)^.quotient.mk (P ^ i)) =
module.rank (R ⧸ p) (S ⧸ P) + module.rank (R ⧸ p) (ideal.map (P^e)^.quotient.mk (P ^ (i + 1))) :=
begin
letI : field (R ⧸ p) := ideal.quotient.field _,
rw [rank_eq_of_injective _ (pow_quot_succ_inclusion_injective f p P i),
(quotient_range_pow_quot_succ_inclusion_equiv f p P hP0 hi).symm.rank_eq],
exact (rank_quotient_add_rank (linear_map.range (pow_quot_succ_inclusion f p P i))).symm,
end
lemma rank_pow_quot [is_domain S] [is_dedekind_domain S] [p.is_maximal] [P.is_prime]
(hP0 : P ≠ ⊥) (i : ℕ) (hi : i ≤ e) :
module.rank (R ⧸ p) (ideal.map (P^e)^.quotient.mk (P ^ i)) =
(e - i) • module.rank (R ⧸ p) (S ⧸ P) :=
begin
refine @nat.decreasing_induction' _ i e (λ j lt_e le_j ih, _) hi _,
{ rw [rank_pow_quot_aux f p P _ lt_e, ih, ← succ_nsmul, nat.sub_succ, ← nat.succ_eq_add_one,
nat.succ_pred_eq_of_pos (nat.sub_pos_of_lt lt_e)],
assumption },
{ rw [nat.sub_self, zero_nsmul, map_quotient_self],
exact rank_bot (R ⧸ p) (S ⧸ (P^e)) }
end
omit hfp
/-- If `p` is a maximal ideal of `R`, `S` extends `R` and `P^e` lies over `p`,
then the dimension `[S/(P^e) : R/p]` is equal to `e * [S/P : R/p]`. -/
lemma rank_prime_pow_ramification_idx [is_domain S] [is_dedekind_domain S] [p.is_maximal]
[P.is_prime] (hP0 : P ≠ ⊥) (he : e ≠ 0) :
module.rank (R ⧸ p) (S ⧸ P^e) =
e • @module.rank (R ⧸ p) (S ⧸ P) _ _ (@algebra.to_module _ _ _ _ $
@@quotient.algebra_quotient_of_ramification_idx_ne_zero _ _ _ _ _ ⟨he⟩) :=
begin
letI : ne_zero e := ⟨he⟩,
have := rank_pow_quot f p P hP0 0 (nat.zero_le e),
rw [pow_zero, nat.sub_zero, ideal.one_eq_top, ideal.map_top] at this,
exact (rank_top (R ⧸ p) _).symm.trans this
end
/-- If `p` is a maximal ideal of `R`, `S` extends `R` and `P^e` lies over `p`,
then the dimension `[S/(P^e) : R/p]`, as a natural number, is equal to `e * [S/P : R/p]`. -/
lemma finrank_prime_pow_ramification_idx [is_domain S] [is_dedekind_domain S]
(hP0 : P ≠ ⊥) [p.is_maximal] [P.is_prime] (he : e ≠ 0) :
finrank (R ⧸ p) (S ⧸ P^e) =
e * @finrank (R ⧸ p) (S ⧸ P) _ _ (@algebra.to_module _ _ _ _ $
@@quotient.algebra_quotient_of_ramification_idx_ne_zero _ _ _ _ _ ⟨he⟩) :=
begin
letI : ne_zero e := ⟨he⟩,
letI : algebra (R ⧸ p) (S ⧸ P) := quotient.algebra_quotient_of_ramification_idx_ne_zero f p P,
letI := ideal.quotient.field p,
have hdim := rank_prime_pow_ramification_idx _ _ _ hP0 he,
by_cases hP : finite_dimensional (R ⧸ p) (S ⧸ P),
{ haveI := hP,
haveI := (finite_dimensional_iff_of_rank_eq_nsmul he hdim).mpr hP,
refine cardinal.nat_cast_injective _,
rw [finrank_eq_rank', nat.cast_mul, finrank_eq_rank', hdim, nsmul_eq_mul] },
have hPe := mt (finite_dimensional_iff_of_rank_eq_nsmul he hdim).mp hP,
simp only [finrank_of_infinite_dimensional hP, finrank_of_infinite_dimensional hPe, mul_zero],
end
end fact_le_comap
section factors_map
open_locale classical
/-! ## Properties of the factors of `p.map (algebra_map R S)` -/
variables [is_domain S] [is_dedekind_domain S] [algebra R S]
lemma factors.ne_bot (P : (factors (map (algebra_map R S) p)).to_finset) :
(P : ideal S) ≠ ⊥ :=
(prime_of_factor _ (multiset.mem_to_finset.mp P.2)).ne_zero
instance factors.is_prime (P : (factors (map (algebra_map R S) p)).to_finset) :
is_prime (P : ideal S) :=
ideal.is_prime_of_prime (prime_of_factor _ (multiset.mem_to_finset.mp P.2))
lemma factors.ramification_idx_ne_zero (P : (factors (map (algebra_map R S) p)).to_finset) :
ramification_idx (algebra_map R S) p P ≠ 0 :=
is_dedekind_domain.ramification_idx_ne_zero
(ne_zero_of_mem_factors (multiset.mem_to_finset.mp P.2))
(factors.is_prime p P)
(ideal.le_of_dvd (dvd_of_mem_factors (multiset.mem_to_finset.mp P.2)))
instance factors.fact_ramification_idx_ne_zero (P : (factors (map (algebra_map R S) p)).to_finset) :
ne_zero (ramification_idx (algebra_map R S) p P) :=
⟨factors.ramification_idx_ne_zero p P⟩
local attribute [instance] quotient.algebra_quotient_of_ramification_idx_ne_zero
instance factors.is_scalar_tower
(P : (factors (map (algebra_map R S) p)).to_finset) :
is_scalar_tower R (R ⧸ p) (S ⧸ (P : ideal S)) :=
is_scalar_tower.of_algebra_map_eq (λ x, by simp)
local attribute [instance] ideal.quotient.field
lemma factors.finrank_pow_ramification_idx [p.is_maximal]
(P : (factors (map (algebra_map R S) p)).to_finset) :
finrank (R ⧸ p) (S ⧸ (P : ideal S) ^ ramification_idx (algebra_map R S) p P) =
ramification_idx (algebra_map R S) p P * inertia_deg (algebra_map R S) p P :=
begin
rw [finrank_prime_pow_ramification_idx, inertia_deg_algebra_map],
exact factors.ne_bot p P,
end
instance factors.finite_dimensional_quotient [is_noetherian R S] [p.is_maximal]
(P : (factors (map (algebra_map R S) p)).to_finset) :
finite_dimensional (R ⧸ p) (S ⧸ (P : ideal S)) :=
is_noetherian.iff_fg.mp $
is_noetherian_of_tower R $
is_noetherian_of_surjective S (ideal.quotient.mkₐ _ _).to_linear_map $
linear_map.range_eq_top.mpr ideal.quotient.mk_surjective
lemma factors.inertia_deg_ne_zero [is_noetherian R S] [p.is_maximal]
(P : (factors (map (algebra_map R S) p)).to_finset) :
inertia_deg (algebra_map R S) p P ≠ 0 :=
by { rw inertia_deg_algebra_map, exact (finite_dimensional.finrank_pos_iff.mpr infer_instance).ne' }
instance factors.finite_dimensional_quotient_pow [is_noetherian R S] [p.is_maximal]
(P : (factors (map (algebra_map R S) p)).to_finset) :
finite_dimensional (R ⧸ p) (S ⧸ (P : ideal S) ^ ramification_idx (algebra_map R S) p P) :=
begin
refine finite_dimensional.finite_dimensional_of_finrank _,
rw [pos_iff_ne_zero, factors.finrank_pow_ramification_idx],
exact mul_ne_zero (factors.ramification_idx_ne_zero p P) (factors.inertia_deg_ne_zero p P)
end
universes w
/-- **Chinese remainder theorem** for a ring of integers: if the prime ideal `p : ideal R`
factors in `S` as `∏ i, P i ^ e i`, then `S ⧸ I` factors as `Π i, R ⧸ (P i ^ e i)`. -/
noncomputable def factors.pi_quotient_equiv
(p : ideal R) (hp : map (algebra_map R S) p ≠ ⊥) :
(S ⧸ map (algebra_map R S) p) ≃+* Π (P : (factors (map (algebra_map R S) p)).to_finset),
S ⧸ ((P : ideal S) ^ ramification_idx (algebra_map R S) p P) :=
(is_dedekind_domain.quotient_equiv_pi_factors hp).trans $
(@ring_equiv.Pi_congr_right (factors (map (algebra_map R S) p)).to_finset
(λ P, S ⧸ (P : ideal S) ^ (factors (map (algebra_map R S) p)).count P)
(λ P, S ⧸ (P : ideal S) ^ ramification_idx (algebra_map R S) p P) _ _
(λ P : (factors (map (algebra_map R S) p)).to_finset, ideal.quot_equiv_of_eq $
by rw is_dedekind_domain.ramification_idx_eq_factors_count hp
(factors.is_prime p P) (factors.ne_bot p P)))
@[simp] lemma factors.pi_quotient_equiv_mk
(p : ideal R) (hp : map (algebra_map R S) p ≠ ⊥) (x : S) :
factors.pi_quotient_equiv p hp (ideal.quotient.mk _ x) = λ P, ideal.quotient.mk _ x :=
rfl
@[simp] lemma factors.pi_quotient_equiv_map
(p : ideal R) (hp : map (algebra_map R S) p ≠ ⊥) (x : R) :
factors.pi_quotient_equiv p hp (algebra_map _ _ x) =
λ P, ideal.quotient.mk _ (algebra_map _ _ x) :=
rfl
variables (S)
/-- **Chinese remainder theorem** for a ring of integers: if the prime ideal `p : ideal R`
factors in `S` as `∏ i, P i ^ e i`,
then `S ⧸ I` factors `R ⧸ I`-linearly as `Π i, R ⧸ (P i ^ e i)`. -/
noncomputable def factors.pi_quotient_linear_equiv
(p : ideal R) (hp : map (algebra_map R S) p ≠ ⊥) :
(S ⧸ map (algebra_map R S) p) ≃ₗ[R ⧸ p] Π (P : (factors (map (algebra_map R S) p)).to_finset),
S ⧸ ((P : ideal S) ^ ramification_idx (algebra_map R S) p P) :=
{ map_smul' := begin
rintro ⟨c⟩ ⟨x⟩, ext P,
simp only [ideal.quotient.mk_algebra_map,
factors.pi_quotient_equiv_mk, factors.pi_quotient_equiv_map, submodule.quotient.quot_mk_eq_mk,
pi.algebra_map_apply, ring_equiv.to_fun_eq_coe, pi.mul_apply,
ideal.quotient.algebra_map_quotient_map_quotient, ideal.quotient.mk_eq_mk, algebra.smul_def,
_root_.map_mul, ring_hom_comp_triple.comp_apply],
congr
end,
.. factors.pi_quotient_equiv p hp }
variables {S}
open_locale big_operators
/-- The **fundamental identity** of ramification index `e` and inertia degree `f`:
for `P` ranging over the primes lying over `p`, `∑ P, e P * f P = [Frac(S) : Frac(R)]`;
here `S` is a finite `R`-module (and thus `Frac(S) : Frac(R)` is a finite extension) and `p`
is maximal.
-/
theorem sum_ramification_inertia (K L : Type*) [field K] [field L]
[is_domain R] [is_dedekind_domain R]
[algebra R K] [is_fraction_ring R K] [algebra S L] [is_fraction_ring S L]
[algebra K L] [algebra R L] [is_scalar_tower R S L] [is_scalar_tower R K L]
[is_noetherian R S] [is_integral_closure S R L] [p.is_maximal] (hp0 : p ≠ ⊥) :
∑ P in (factors (map (algebra_map R S) p)).to_finset,
ramification_idx (algebra_map R S) p P * inertia_deg (algebra_map R S) p P =
finrank K L :=
begin
set e := ramification_idx (algebra_map R S) p,
set f := inertia_deg (algebra_map R S) p,
have inj_RL : function.injective (algebra_map R L),
{ rw [is_scalar_tower.algebra_map_eq R K L, ring_hom.coe_comp],
exact (ring_hom.injective _).comp (is_fraction_ring.injective R K) },
have inj_RS : function.injective (algebra_map R S),
{ refine function.injective.of_comp (show function.injective (algebra_map S L ∘ _), from _),
rw [← ring_hom.coe_comp, ← is_scalar_tower.algebra_map_eq],
exact inj_RL },
calc ∑ P in (factors (map (algebra_map R S) p)).to_finset, e P * f P
= ∑ P in (factors (map (algebra_map R S) p)).to_finset.attach,
finrank (R ⧸ p) (S ⧸ (P : ideal S)^(e P)) : _
... = finrank (R ⧸ p) (Π P : (factors (map (algebra_map R S) p)).to_finset,
(S ⧸ (P : ideal S)^(e P))) :
(finrank_pi_fintype (R ⧸ p)).symm
... = finrank (R ⧸ p) (S ⧸ map (algebra_map R S) p) : _
... = finrank K L : _,
{ rw ← finset.sum_attach,
refine finset.sum_congr rfl (λ P _, _),
rw factors.finrank_pow_ramification_idx },
{ refine linear_equiv.finrank_eq (factors.pi_quotient_linear_equiv S p _).symm,
rwa [ne.def, ideal.map_eq_bot_iff_le_ker, (ring_hom.injective_iff_ker_eq_bot _).mp inj_RS,
le_bot_iff] },
{ exact finrank_quotient_map p K L },
end
end factors_map
end ideal
|
d8f20e7cd8062bd1aa2a75773290ebb7123ed757 | 302c785c90d40ad3d6be43d33bc6a558354cc2cf | /src/analysis/normed_space/dual.lean | 52d183756304d0ee4ffe9bdb50cfd91bf2edd3e2 | [
"Apache-2.0"
] | permissive | ilitzroth/mathlib | ea647e67f1fdfd19a0f7bdc5504e8acec6180011 | 5254ef14e3465f6504306132fe3ba9cec9ffff16 | refs/heads/master | 1,680,086,661,182 | 1,617,715,647,000 | 1,617,715,647,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 11,857 | lean | /-
Copyright (c) 2020 Heather Macbeth. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Heather Macbeth, Frédéric Dupuis
-/
import analysis.normed_space.hahn_banach
import analysis.normed_space.inner_product
/-!
# The topological dual of a normed space
In this file we define the topological dual of a normed space, and the bounded linear map from
a normed space into its double dual.
We also prove that, for base field `𝕜` with `[is_R_or_C 𝕜]`, this map is an isometry.
We then consider inner product spaces, with base field over `ℝ` (the corresponding results for `ℂ`
will require the definition of conjugate-linear maps). We define `to_dual_map`, a continuous linear
map from `E` to its dual, which maps an element `x` of the space to `λ y, ⟪x, y⟫`. We check
(`to_dual_map_isometry`) that this map is an isometry onto its image, and particular is injective.
We also define `to_dual'` as the function taking taking a vector to its dual for a base field `𝕜`
with `[is_R_or_C 𝕜]`; this is a function and not a linear map.
Finally, under the hypothesis of completeness (i.e., for Hilbert spaces), we prove the Fréchet-Riesz
representation (`to_dual_map_eq_top`), which states the surjectivity: every element of the dual
of a Hilbert space `E` has the form `λ u, ⟪x, u⟫` for some `x : E`. This permits the map
`to_dual_map` to be upgraded to an (isometric) continuous linear equivalence, `to_dual`, between a
Hilbert space and its dual.
## References
* [M. Einsiedler and T. Ward, *Functional Analysis, Spectral Theory, and Applications*]
[EinsiedlerWard2017]
## Tags
dual, Fréchet-Riesz
-/
noncomputable theory
open_locale classical
universes u v
namespace normed_space
section general
variables (𝕜 : Type*) [nondiscrete_normed_field 𝕜]
variables (E : Type*) [normed_group E] [normed_space 𝕜 E]
/-- The topological dual of a normed space `E`. -/
@[derive [has_coe_to_fun, normed_group, normed_space 𝕜]] def dual := E →L[𝕜] 𝕜
instance : inhabited (dual 𝕜 E) := ⟨0⟩
/-- The inclusion of a normed space in its double (topological) dual. -/
def inclusion_in_double_dual' (x : E) : (dual 𝕜 (dual 𝕜 E)) :=
linear_map.mk_continuous
{ to_fun := λ f, f x,
map_add' := by simp,
map_smul' := by simp }
∥x∥
(λ f, by { rw mul_comm, exact f.le_op_norm x } )
@[simp] lemma dual_def (x : E) (f : dual 𝕜 E) :
((inclusion_in_double_dual' 𝕜 E) x) f = f x := rfl
lemma double_dual_bound (x : E) : ∥(inclusion_in_double_dual' 𝕜 E) x∥ ≤ ∥x∥ :=
begin
apply continuous_linear_map.op_norm_le_bound,
{ simp },
{ intros f, rw mul_comm, exact f.le_op_norm x, }
end
/-- The inclusion of a normed space in its double (topological) dual, considered
as a bounded linear map. -/
def inclusion_in_double_dual : E →L[𝕜] (dual 𝕜 (dual 𝕜 E)) :=
linear_map.mk_continuous
{ to_fun := λ (x : E), (inclusion_in_double_dual' 𝕜 E) x,
map_add' := λ x y, by { ext, simp },
map_smul' := λ (c : 𝕜) x, by { ext, simp } }
1
(λ x, by { convert double_dual_bound _ _ _, simp } )
end general
section bidual_isometry
variables {𝕜 : Type v} [is_R_or_C 𝕜]
{E : Type u} [normed_group E] [normed_space 𝕜 E]
/-- If one controls the norm of every `f x`, then one controls the norm of `x`.
Compare `continuous_linear_map.op_norm_le_bound`. -/
lemma norm_le_dual_bound (x : E) {M : ℝ} (hMp: 0 ≤ M) (hM : ∀ (f : dual 𝕜 E), ∥f x∥ ≤ M * ∥f∥) :
∥x∥ ≤ M :=
begin
classical,
by_cases h : x = 0,
{ simp only [h, hMp, norm_zero] },
{ obtain ⟨f, hf⟩ : ∃ g : E →L[𝕜] 𝕜, _ := exists_dual_vector x h,
calc ∥x∥ = ∥norm' 𝕜 x∥ : (norm_norm' _ _ _).symm
... = ∥f x∥ : by rw hf.2
... ≤ M * ∥f∥ : hM f
... = M : by rw [hf.1, mul_one] }
end
/-- The inclusion of a normed space in its double dual is an isometry onto its image.-/
lemma inclusion_in_double_dual_isometry (x : E) : ∥inclusion_in_double_dual 𝕜 E x∥ = ∥x∥ :=
begin
apply le_antisymm,
{ exact double_dual_bound 𝕜 E x },
{ rw continuous_linear_map.norm_def,
apply real.lb_le_Inf _ continuous_linear_map.bounds_nonempty,
rintros c ⟨hc1, hc2⟩,
exact norm_le_dual_bound x hc1 hc2 },
end
end bidual_isometry
end normed_space
namespace inner_product_space
open is_R_or_C continuous_linear_map
section is_R_or_C
variables (𝕜 : Type*)
variables {E : Type*} [is_R_or_C 𝕜] [inner_product_space 𝕜 E]
local notation `⟪`x`, `y`⟫` := @inner 𝕜 E _ x y
local postfix `†`:90 := @is_R_or_C.conj 𝕜 _
/--
Given some `x` in an inner product space, we can define its dual as the continuous linear map
`λ y, ⟪x, y⟫`. Consider using `to_dual` or `to_dual_map` instead in the real case.
-/
def to_dual' : E →+ normed_space.dual 𝕜 E :=
{ to_fun := λ x, linear_map.mk_continuous
{ to_fun := λ y, ⟪x, y⟫,
map_add' := λ _ _, inner_add_right,
map_smul' := λ _ _, inner_smul_right }
∥x∥
(λ y, by { rw [is_R_or_C.norm_eq_abs], exact abs_inner_le_norm _ _ }),
map_zero' := by { ext z, simp },
map_add' := λ x y, by { ext z, simp [inner_add_left] } }
@[simp] lemma to_dual'_apply {x y : E} : to_dual' 𝕜 x y = ⟪x, y⟫ := rfl
/-- In an inner product space, the norm of the dual of a vector `x` is `∥x∥` -/
@[simp] lemma norm_to_dual'_apply (x : E) : ∥to_dual' 𝕜 x∥ = ∥x∥ :=
begin
refine le_antisymm _ _,
{ exact linear_map.mk_continuous_norm_le _ (norm_nonneg _) _ },
{ cases eq_or_lt_of_le (norm_nonneg x) with h h,
{ have : x = 0 := norm_eq_zero.mp (eq.symm h),
simp [this] },
{ refine (mul_le_mul_right h).mp _,
calc ∥x∥ * ∥x∥ = ∥x∥ ^ 2 : by ring
... = re ⟪x, x⟫ : norm_sq_eq_inner _
... ≤ abs ⟪x, x⟫ : re_le_abs _
... = ∥to_dual' 𝕜 x x∥ : by simp [norm_eq_abs]
... ≤ ∥to_dual' 𝕜 x∥ * ∥x∥ : le_op_norm (to_dual' 𝕜 x) x } }
end
variables (E)
lemma to_dual'_isometry : isometry (@to_dual' 𝕜 E _ _) :=
add_monoid_hom.isometry_of_norm _ (norm_to_dual'_apply 𝕜)
/--
Fréchet-Riesz representation: any `ℓ` in the dual of a Hilbert space `E` is of the form
`λ u, ⟪y, u⟫` for some `y : E`, i.e. `to_dual'` is surjective.
-/
lemma to_dual'_surjective [complete_space E] : function.surjective (@to_dual' 𝕜 E _ _) :=
begin
intros ℓ,
set Y := ker ℓ with hY,
by_cases htriv : Y = ⊤,
{ have hℓ : ℓ = 0,
{ have h' := linear_map.ker_eq_top.mp htriv,
rw [←coe_zero] at h',
apply coe_injective,
exact h' },
exact ⟨0, by simp [hℓ]⟩ },
{ have Ycomplete := is_complete_ker ℓ,
rw [← submodule.orthogonal_eq_bot_iff Ycomplete, ←hY] at htriv,
change Yᗮ ≠ ⊥ at htriv,
rw [submodule.ne_bot_iff] at htriv,
obtain ⟨z : E, hz : z ∈ Yᗮ, z_ne_0 : z ≠ 0⟩ := htriv,
refine ⟨((ℓ z)† / ⟪z, z⟫) • z, _⟩,
ext x,
have h₁ : (ℓ z) • x - (ℓ x) • z ∈ Y,
{ rw [mem_ker, map_sub, map_smul, map_smul, algebra.id.smul_eq_mul, algebra.id.smul_eq_mul,
mul_comm],
exact sub_self (ℓ x * ℓ z) },
have h₂ : (ℓ z) * ⟪z, x⟫ = (ℓ x) * ⟪z, z⟫,
{ have h₃ := calc
0 = ⟪z, (ℓ z) • x - (ℓ x) • z⟫ : by { rw [(Y.mem_orthogonal' z).mp hz], exact h₁ }
... = ⟪z, (ℓ z) • x⟫ - ⟪z, (ℓ x) • z⟫ : by rw [inner_sub_right]
... = (ℓ z) * ⟪z, x⟫ - (ℓ x) * ⟪z, z⟫ : by simp [inner_smul_right],
exact sub_eq_zero.mp (eq.symm h₃) },
have h₄ := calc
⟪((ℓ z)† / ⟪z, z⟫) • z, x⟫ = (ℓ z) / ⟪z, z⟫ * ⟪z, x⟫
: by simp [inner_smul_left, conj_div, conj_conj]
... = (ℓ z) * ⟪z, x⟫ / ⟪z, z⟫
: by rw [←div_mul_eq_mul_div]
... = (ℓ x) * ⟪z, z⟫ / ⟪z, z⟫
: by rw [h₂]
... = ℓ x
: begin
have : ⟪z, z⟫ ≠ 0,
{ change z = 0 → false at z_ne_0,
rwa ←inner_self_eq_zero at z_ne_0 },
field_simp [this]
end,
exact h₄ }
end
end is_R_or_C
section real
variables {F : Type*} [inner_product_space ℝ F]
/-- In a real inner product space `F`, the function that takes a vector `x` in `F` to its dual
`λ y, ⟪x, y⟫` is a continuous linear map. If the space is complete (i.e. is a Hilbert space),
consider using `to_dual` instead. -/
-- TODO extend to `is_R_or_C` (requires a definition of conjugate linear maps)
def to_dual_map : F →L[ℝ] (normed_space.dual ℝ F) :=
linear_map.mk_continuous
{ to_fun := to_dual' ℝ,
map_add' := λ x y, by { ext, simp [inner_add_left] },
map_smul' := λ c x, by { ext, simp [inner_smul_left] } }
1
(λ x, by simp only [norm_to_dual'_apply, one_mul, linear_map.coe_mk])
@[simp] lemma to_dual_map_apply {x y : F} : to_dual_map x y = ⟪x, y⟫_ℝ := rfl
/-- In an inner product space, the norm of the dual of a vector `x` is `∥x∥` -/
@[simp] lemma norm_to_dual_map_apply (x : F) : ∥to_dual_map x∥ = ∥x∥ := norm_to_dual'_apply _ _
lemma to_dual_map_isometry : isometry (@to_dual_map F _) :=
add_monoid_hom.isometry_of_norm _ norm_to_dual_map_apply
lemma to_dual_map_injective : function.injective (@to_dual_map F _) :=
(@to_dual_map_isometry F _).injective
@[simp] lemma ker_to_dual_map : (@to_dual_map F _).ker = ⊥ :=
linear_map.ker_eq_bot.mpr to_dual_map_injective
@[simp] lemma to_dual_map_eq_iff_eq {x y : F} : to_dual_map x = to_dual_map y ↔ x = y :=
((linear_map.ker_eq_bot).mp (@ker_to_dual_map F _)).eq_iff
variables [complete_space F]
/--
Fréchet-Riesz representation: any `ℓ` in the dual of a real Hilbert space `F` is of the form
`λ u, ⟪y, u⟫` for some `y` in `F`. See `inner_product_space.to_dual` for the continuous linear
equivalence thus induced.
-/
-- TODO extend to `is_R_or_C` (requires a definition of conjugate linear maps)
lemma range_to_dual_map : (@to_dual_map F _).range = ⊤ :=
linear_map.range_eq_top.mpr (to_dual'_surjective ℝ F)
/--
Fréchet-Riesz representation: If `F` is a Hilbert space, the function that takes a vector in `F` to
its dual is a continuous linear equivalence. -/
def to_dual : F ≃L[ℝ] (normed_space.dual ℝ F) :=
continuous_linear_equiv.of_isometry to_dual_map.to_linear_map to_dual_map_isometry range_to_dual_map
/--
Fréchet-Riesz representation: If `F` is a Hilbert space, the function that takes a vector in `F` to
its dual is an isometry. -/
def isometric.to_dual : F ≃ᵢ normed_space.dual ℝ F :=
{ to_equiv := to_dual.to_linear_equiv.to_equiv,
isometry_to_fun := to_dual'_isometry ℝ F}
@[simp] lemma to_dual_apply {x y : F} : to_dual x y = ⟪x, y⟫_ℝ := rfl
@[simp] lemma to_dual_eq_iff_eq {x y : F} : to_dual x = to_dual y ↔ x = y :=
(@to_dual F _ _).injective.eq_iff
lemma to_dual_eq_iff_eq' {x x' : F} : (∀ y : F, ⟪x, y⟫_ℝ = ⟪x', y⟫_ℝ) ↔ x = x' :=
begin
split,
{ intros h,
have : to_dual x = to_dual x' → x = x' := to_dual_eq_iff_eq.mp,
apply this,
simp_rw [←to_dual_apply] at h,
ext z,
exact h z },
{ rintros rfl y,
refl }
end
@[simp] lemma norm_to_dual_apply (x : F) : ∥to_dual x∥ = ∥x∥ := norm_to_dual_map_apply x
/-- In a Hilbert space, the norm of a vector in the dual space is the norm of its corresponding
primal vector. -/
lemma norm_to_dual_symm_apply (ℓ : normed_space.dual ℝ F) : ∥to_dual.symm ℓ∥ = ∥ℓ∥ :=
begin
have : ℓ = to_dual (to_dual.symm ℓ) := by simp only [continuous_linear_equiv.apply_symm_apply],
conv_rhs { rw [this] },
refine eq.symm (norm_to_dual_apply _),
end
end real
end inner_product_space
|
bdede40321fabe059b5a72da6da5de5abcdd772a | d406927ab5617694ec9ea7001f101b7c9e3d9702 | /src/category_theory/limits/constructions/over/default.lean | e4085355f2824c00c686844d9d468db9e7ccc221 | [
"Apache-2.0"
] | permissive | alreadydone/mathlib | dc0be621c6c8208c581f5170a8216c5ba6721927 | c982179ec21091d3e102d8a5d9f5fe06c8fafb73 | refs/heads/master | 1,685,523,275,196 | 1,670,184,141,000 | 1,670,184,141,000 | 287,574,545 | 0 | 0 | Apache-2.0 | 1,670,290,714,000 | 1,597,421,623,000 | Lean | UTF-8 | Lean | false | false | 2,799 | lean | /-
Copyright (c) 2018 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin, Reid Barton, Bhavik Mehta
-/
import category_theory.limits.connected
import category_theory.limits.constructions.over.products
import category_theory.limits.constructions.over.connected
import category_theory.limits.constructions.limits_of_products_and_equalizers
import category_theory.limits.constructions.equalizers
/-!
# Limits in the over category
Declare instances for limits in the over category: If `C` has finite wide pullbacks, `over B` has
finite limits, and if `C` has arbitrary wide pullbacks then `over B` has limits.
-/
universes w v u -- morphism levels before object levels. See note [category_theory universes].
open category_theory category_theory.limits
variables {C : Type u} [category.{v} C]
variable {X : C}
namespace category_theory.over
/-- Make sure we can derive pullbacks in `over B`. -/
instance {B : C} [has_pullbacks C] : has_pullbacks (over B) :=
begin
letI : has_limits_of_shape (ulift_hom.{v} (ulift.{v} walking_cospan)) C :=
has_limits_of_shape_of_equivalence (ulift_hom_ulift_category.equiv.{v} _),
letI : category (ulift_hom.{v} (ulift.{v} walking_cospan)) := infer_instance,
exact has_limits_of_shape_of_equivalence (ulift_hom_ulift_category.equiv.{v v} _).symm,
end
/-- Make sure we can derive equalizers in `over B`. -/
instance {B : C} [has_equalizers C] : has_equalizers (over B) :=
begin
letI : has_limits_of_shape (ulift_hom.{v} (ulift.{v} walking_parallel_pair)) C :=
has_limits_of_shape_of_equivalence (ulift_hom_ulift_category.equiv.{v} _),
letI : category (ulift_hom.{v} (ulift.{v} walking_parallel_pair)) := infer_instance,
exact has_limits_of_shape_of_equivalence (ulift_hom_ulift_category.equiv.{v v} _).symm,
end
instance has_finite_limits {B : C} [has_finite_wide_pullbacks C] : has_finite_limits (over B) :=
begin
apply @has_finite_limits_of_has_equalizers_and_finite_products _ _ _ _,
{ exact construct_products.over_finite_products_of_finite_wide_pullbacks, },
{ apply @has_equalizers_of_has_pullbacks_and_binary_products _ _ _ _,
{ haveI : has_pullbacks C := ⟨by apply_instance⟩,
exact construct_products.over_binary_product_of_pullback },
{ apply_instance, } }
end
instance has_limits {B : C} [has_wide_pullbacks.{w} C] : has_limits_of_size.{w} (over B) :=
begin
apply @has_limits_of_has_equalizers_and_products _ _ _ _,
{ exact construct_products.over_products_of_wide_pullbacks },
{ apply @has_equalizers_of_has_pullbacks_and_binary_products _ _ _ _,
{ haveI : has_pullbacks C := ⟨infer_instance⟩,
exact construct_products.over_binary_product_of_pullback },
{ apply_instance, } }
end
end category_theory.over
|
8b2849c1068f16fc41f302196f052868e971e711 | 7d5ad87afb17e514aee234fcf0a24412eed6384f | /src/independence.lean | c721bba0c40f6721d339dfe7cc031b22764130df | [] | no_license | digama0/flypitch | 764f849eaef59c045dfbeca142a0f827973e70c1 | 2ec14b8da6a3964f09521d17e51f363d255b030f | refs/heads/master | 1,586,980,069,651 | 1,547,078,141,000 | 1,547,078,283,000 | 164,965,135 | 1 | 0 | null | 1,547,082,858,000 | 1,547,082,857,000 | null | UTF-8 | Lean | false | false | 1,925 | lean | import .fol .zfc .completeness
local attribute [instance, priority 0] classical.prop_decidable
open fol
/- Statement of the independence of the continuum hypothesis -/
open zfc
section independence
/- ¬ (T ⊢' f) is implied by ∃ M : Model T, M ⊢ ∼ f -/
lemma unprovable_of_model_negation {L : Language} {T : Theory L} {hT : is_consistent T} {f : sentence L} (S : Structure L) (hS : S ⊨ T) {h_nonempty : nonempty S} (hS' : S ⊨ ∼f) : ¬ (T ⊢' f) :=
begin
revert hS', by_contra, have H : ¬S ⊨ f ∧ T ⊢' f, by {simp at a, exact a},
suffices : S ⊨ f, by {apply false_of_Model_absurd ⟨S, hS⟩ this (by exact H.left)},
apply (completeness T f).mp H.right, repeat{assumption}
end
lemma independence_of_exhibit_models {L : Language} {T : Theory L} {hT : is_consistent T} {f : sentence L} (M1 : Model T) (H1 : M1 ⊨ f) (M2 : Model T) (H2 : M2 ⊨ ∼f) {h_nonempty1 : nonempty M1.fst} {h_nonempty2 : nonempty M2.fst} : ((¬ T ⊢' f) ∧ (¬ T ⊢' ∼f)) :=
by exact ⟨by {apply unprovable_of_model_negation, exact hT, exact M2.snd, repeat{assumption}},
by {apply unprovable_of_model_negation, exact hT, exact M1.snd, assumption, simpa}⟩
--TODO(everyone)
theorem ZFC_consistent : is_consistent ZFC :=
begin
apply (model_existence ZFC).mpr, sorry
end
--TODO(everyone)
theorem CH_consistent : ∃ M : Model ZFC, (nonempty M.fst) ∧ M ⊨ continuum_hypothesis := sorry
--TODO(everyone)
theorem neg_CH_consistent : ∃ M : Model ZFC,(nonempty M.fst) ∧ M ⊨ ∼ continuum_hypothesis := sorry
theorem independence_of_CH : (¬ ZFC ⊢' continuum_hypothesis) ∧ (¬ ZFC ⊢' ∼ continuum_hypothesis) :=
begin
have := CH_consistent, have := neg_CH_consistent, repeat{auto_cases},
apply @independence_of_exhibit_models L_ZFC ZFC ZFC_consistent continuum_hypothesis,
show Model ZFC, exact this_w_1, show Model ZFC, exact this_w, repeat{assumption}
end
end independence
|
d017d591d45ff957b5094ed210f8e7e4091cc3a1 | 97c8e5d8aca4afeebb5b335f26a492c53680efc8 | /ground_zero/theorems/prop.lean | a57ef6dd165f46c2b776fde88c6a137e51e70c0a | [] | no_license | jfrancese/lean | cf32f0d8d5520b6f0e9d3987deb95841c553c53c | 06e7efaecce4093d97fb5ecc75479df2ef1dbbdb | refs/heads/master | 1,587,915,151,351 | 1,551,012,140,000 | 1,551,012,140,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 2,982 | lean | import ground_zero.HITs.interval ground_zero.HITs.truncation
open ground_zero.structures (prop contr hset prop_is_set)
open ground_zero.types.equiv (transport transport_composition)
open ground_zero.types
namespace ground_zero
namespace theorems.prop
universes u v w
def product_prop {α : Sort u} {β : Sort v}
(h : prop α) (g : prop β) : prop (α × β) := begin
intros a b,
cases a with x y, cases b with u v,
have p := h x u, have q := g y v,
induction p, induction q, reflexivity
end
def prop_equiv_lemma {α : Sort u} {β : Sort v}
(F : prop α) (G : prop β) (f : α → β) (g : β → α) : α ≃ β :=
begin
existsi f, split; existsi g,
{ intro x, apply F }, { intro y, apply G }
end
def contr_equiv_unit {α : Sort u} (h : contr α) : α ≃ types.unit := begin
existsi (λ _, types.unit.star), split;
existsi (λ _, h.point),
{ intro x, apply h.intro },
{ intro x, cases x, reflexivity }
end
lemma uniq_does_not_add_new_paths {α : Sort u} (a b : ∥α∥) (p : a = b :> ∥α∥) :
HITs.truncation.uniq a b = p :> a = b :> ∥α∥ :=
prop_is_set HITs.truncation.uniq (HITs.truncation.uniq a b) p
lemma prop_is_prop {α : Sort u} : prop (prop α) := begin
intros f g,
have p := λ a b, (prop_is_set f) (f a b) (g a b),
apply HITs.interval.dfunext, intro a,
apply HITs.interval.dfunext, intro b,
exact p a b
end
lemma prop_equiv {π : Type u} (h : prop π) : π ≃ ∥π∥ := begin
existsi HITs.truncation.elem,
split; existsi (HITs.truncation.rec h id); intro x,
{ reflexivity },
{ apply HITs.truncation.uniq }
end
lemma prop_from_equiv {π : Type u} (e : π ≃ ∥π∥) : prop π := begin
cases e with f H, cases H with linv rinv,
cases linv with g α, cases rinv with h β,
intros a b,
transitivity, exact (α a)⁻¹,
symmetry, transitivity, exact (α b)⁻¹,
apply eq.map g, exact HITs.truncation.uniq (f b) (f a)
end
theorem prop_exercise (π : Type u) : (prop π) ≃ (π ≃ ∥π∥) :=
begin
existsi @prop_equiv π, split; existsi prop_from_equiv,
{ intro x, apply prop_is_prop },
{ intro x, simp,
cases x with f H,
cases H with linv rinv,
cases linv with f α,
cases rinv with g β,
admit }
end
lemma comp_qinv₁ {α : Sort u} {β : Sort v} {γ : Sort w}
(f : α → β) (g : β → α) (H : is_qinv f g) :
qinv (λ (h : γ → α), f ∘ h) := begin
existsi (λ h, g ∘ h), split,
{ intro h, apply HITs.interval.funext,
intro x, exact H.pr₁ (h x) },
{ intro h, apply HITs.interval.funext,
intro x, exact H.pr₂ (h x) }
end
lemma comp_qinv₂ {α : Sort u} {β : Sort v} {γ : Sort w}
(f : α → β) (g : β → α) (H : is_qinv f g) :
qinv (λ (h : β → γ), h ∘ f) := begin
existsi (λ h, h ∘ g), split,
{ intro h, apply HITs.interval.funext,
intro x, apply eq.map h, exact H.pr₂ x },
{ intro h, apply HITs.interval.funext,
intro x, apply eq.map h, exact H.pr₁ x }
end
end theorems.prop
end ground_zero |
0b6bbf0f3207ec1f9f5f55d0084391150048275f | ce6917c5bacabee346655160b74a307b4a5ab620 | /src/ch5/ex0206.lean | c16d72d991baca718fe086b23c69867ae142bda4 | [] | no_license | Ailrun/Theorem_Proving_in_Lean | ae6a23f3c54d62d401314d6a771e8ff8b4132db2 | 2eb1b5caf93c6a5a555c79e9097cf2ba5a66cf68 | refs/heads/master | 1,609,838,270,467 | 1,586,846,743,000 | 1,586,846,743,000 | 240,967,761 | 1 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 138 | lean | example : ∀ a b c : ℕ, a = b → a = c → c = b :=
begin
intros,
apply eq.trans,
apply eq.symm,
assumption,
assumption
end
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.