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
|
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
3517983137be1d7ea8d20272db061ad35296b315
|
d5ff69c5608a867046609101d89910f1257aaf8c
|
/src/2020/functions/bijection_game.lean
|
58a3427700bdc15f0302747d4961919519508189
|
[] |
no_license
|
jiaminglimjm/M40001_lean
|
c299ff574a22d3a636a2b9720dc9b5e853a3bab0
|
c8bd8922f37f3e10e2d448f226798ebd0a2af232
|
refs/heads/master
| 1,672,312,761,737
| 1,603,095,035,000
| 1,603,095,035,000
| 304,831,347
| 0
| 0
| null | 1,603,094,893,000
| 1,602,922,986,000
| null |
UTF-8
|
Lean
| false
| false
| 1,454
|
lean
|
import tactic
-- Let's make bijections between β, β€ and β.
#check infinite
#print prefix infinite
#print infinite
#print int.infinite
#check infinite.of_injective
example : infinite β := by apply_instance
example : infinite β€ := by show_term {apply_instance}
#check rat.of_int
example : infinite β := infinite.of_injective (coe : β€ β β)
begin
intros a b,
intro h,
exact (rat.coe_int_inj a b).mp h,
end
namespace countably_infinite
example (a b : β) : 2 * a = 2 * b β a = b := by
begin
intro h,
apply mul_left_cancel' _ h,
norm_num,
end
def bool_times_nat : bool Γ β β β :=
{ to_fun := Ξ» bn, if bn.1 = tt then bn.2 * 2 else bn.2 * 2 + 1,
inv_fun := Ξ» d, β¨d % 2 = 0, d / 2β©,
left_inv := begin
intro bn,
cases bn with b n,
cases b,
-- TODO -- make snippet
{ suffices : Β¬(1 + 2 * n) % 2 = 0 β§ (1 + 2 * n) / 2 = n,
simpa [mul_comm, add_comm],
have h : (1 + 2 * n) % 2 = 1,
simp,
split,
{ simp },
{ have h2 := nat.mod_add_div (1 + 2 * n) 2,
have h3 : 2 * ((1 + 2 * n) / 2) = 2 * n β
(1 + 2 * n) / 2 = n := Ξ» h, mul_left_cancel' _ h,
simp * at *, cc } },
{ simp }
end
,
right_inv := begin
intro n,
suffices : ite (n % 2 = 0) (n / 2 * 2) (n / 2 * 2 + 1) = n,
simpa,
split_ifs,
end
}
example (X : Type) (h : X β β) : X β X Γ bool := sorry
end countably_infinite
|
e3c389e3ea1ce80e8f8a0c06afffada5c90feb06
|
b7f22e51856f4989b970961f794f1c435f9b8f78
|
/library/data/nat/examples/fib2.lean
|
2ff8e444f0274206a485a572cbf3575c0ff728bc
|
[
"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
| 1,166
|
lean
|
/-
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Leonardo de Moura
Show that tail recursive fib is equal to standard one.
-/
import data.nat
open nat
definition fib : nat β nat
| 0 := 1
| 1 := 1
| (n+2) := fib (n+1) + fib n
private definition fib_fast_aux : nat β nat β nat β nat
| 0 i j := j
| (n+1) i j := fib_fast_aux n j (j+i)
lemma fib_fast_aux_lemma : β n m, fib_fast_aux n (fib m) (fib (succ m)) = fib (succ (n + m))
| 0 m := by rewrite zero_add
| (succ n) m :=
begin
have ih : fib_fast_aux n (fib (succ m)) (fib (succ (succ m))) = fib (succ (n + succ m)), from fib_fast_aux_lemma n (succ m),
have hβ : fib (succ m) + fib m = fib (succ (succ m)), from rfl,
unfold fib_fast_aux, rewrite [hβ, ih, succ_add, add_succ]
end
definition fib_fast (n: nat) :=
fib_fast_aux n 0 1
lemma fib_fast_eq_fib : β n, fib_fast n = fib n
| 0 := rfl
| (succ n) :=
begin
have hβ : fib_fast_aux n (fib 0) (fib 1) = fib (succ n), from !fib_fast_aux_lemma,
unfold fib_fast, unfold fib_fast_aux, krewrite hβ
end
|
be2db7a90e3f73c5c746e270fcdeb45ddde7b6dc
|
b3fced0f3ff82d577384fe81653e47df68bb2fa1
|
/src/topology/local_homeomorph.lean
|
42bbe797d9e0ef0477f933e7961197ecc1923995
|
[
"Apache-2.0"
] |
permissive
|
ratmice/mathlib
|
93b251ef5df08b6fd55074650ff47fdcc41a4c75
|
3a948a6a4cd5968d60e15ed914b1ad2f4423af8d
|
refs/heads/master
| 1,599,240,104,318
| 1,572,981,183,000
| 1,572,981,183,000
| 219,830,178
| 0
| 0
|
Apache-2.0
| 1,572,980,897,000
| 1,572,980,896,000
| null |
UTF-8
|
Lean
| false
| false
| 27,695
|
lean
|
/-
Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: SΓ©bastien GouΓ«zel
-/
import data.equiv.local_equiv topology.continuous_on topology.homeomorph
/-!
# Local homeomorphisms
This file defines homeomorphisms between open subsets of topological spaces. An element `e` of
`local_homeomorph Ξ± Ξ²` is an extension of `local_equiv Ξ± Ξ²`, i.e., it is a pair of functions
`e.to_fun` and `e.inv_fun`, inverse of each other on the sets `e.source` and `e.target`.
Additionally, we require that these sets are open, and that the functions are continuous on them.
Equivalently, they are homeomorphisms there.
Contrary to equivs, we do not register the coercion to functions and we use explicitly to_fun and
inv_fun: coercions create unification problems for manifolds.
## Main definitions
`homeomorph.to_local_homeomorph`: associating a local homeomorphism to a homeomorphism, with
source = target = univ
`local_homeomorph.symm` : the inverse of a local homeomorphism
`local_homeomorph.trans` : the composition of two local homeomorphisms
`local_homeomorph.refl` : the identity local homeomorphism
`local_homeomorph.of_set`: the identity on a set `s`
`eq_on_source` : equivalence relation describing the "right" notion of equality for local
homeomorphisms
## Implementation notes
Most statements are copied from their local_equiv versions, although some care is required
especially when restricting to subsets, as these should be open subsets.
For design notes, see `local_equiv.lean`.
-/
open function set
variables {Ξ± : Type*} {Ξ² : Type*} {Ξ³ : Type*} {Ξ΄ : Type*}
[topological_space Ξ±] [topological_space Ξ²] [topological_space Ξ³] [topological_space Ξ΄]
/-- local homeomorphisms, defined on open subsets of the space -/
structure local_homeomorph (Ξ± : Type*) (Ξ² : Type*) [topological_space Ξ±] [topological_space Ξ²]
extends local_equiv Ξ± Ξ² :=
(open_source : is_open source)
(open_target : is_open target)
(continuous_to_fun : continuous_on to_fun source)
(continuous_inv_fun : continuous_on inv_fun target)
/-- A homeomorphism induces a local homeomorphism on the whole space -/
def homeomorph.to_local_homeomorph (e : homeomorph Ξ± Ξ²) :
local_homeomorph Ξ± Ξ² :=
{ open_source := is_open_univ,
open_target := is_open_univ,
continuous_to_fun := by { erw β continuous_iff_continuous_on_univ, exact e.continuous_to_fun },
continuous_inv_fun := by { erw β continuous_iff_continuous_on_univ, exact e.continuous_inv_fun },
..e.to_equiv.to_local_equiv }
namespace local_homeomorph
variables (e : local_homeomorph Ξ± Ξ²) (e' : local_homeomorph Ξ² Ξ³)
lemma eq_of_local_equiv_eq {e e' : local_homeomorph Ξ± Ξ²}
(h : e.to_local_equiv = e'.to_local_equiv) : e = e' :=
begin
cases e, cases e',
dsimp at *,
induction h,
refl
end
/-- Two local homeomorphisms are equal when they have equal to_fun, inv_fun and source. It is not
sufficient to have equal to_fun and source, as this only determines inv_fun on the target. This
would only be true for a weaker notion of equality, arguably the right one, called `eq_on_source`. -/
@[extensionality]
protected lemma ext (e' : local_homeomorph Ξ± Ξ²) (h : βx, e.to_fun x = e'.to_fun x)
(hinv: βx, e.inv_fun x = e'.inv_fun x) (hs : e.source = e'.source) : e = e' :=
eq_of_local_equiv_eq (local_equiv.ext e.to_local_equiv e'.to_local_equiv h hinv hs)
/-- The inverse of a local homeomorphism -/
protected def symm : local_homeomorph Ξ² Ξ± :=
{ open_source := e.open_target,
open_target := e.open_source,
continuous_to_fun := e.continuous_inv_fun,
continuous_inv_fun := e.continuous_to_fun,
..e.to_local_equiv.symm }
@[simp] lemma symm_to_local_equiv : e.symm.to_local_equiv = e.to_local_equiv.symm := rfl
@[simp] lemma symm_to_fun : e.symm.to_fun = e.inv_fun := rfl
@[simp] lemma symm_inv_fun : e.symm.inv_fun = e.to_fun := rfl
@[simp] lemma symm_source : e.symm.source = e.target := rfl
@[simp] lemma symm_target : e.symm.target = e.source := rfl
@[simp] lemma symm_symm : e.symm.symm = e := eq_of_local_equiv_eq $ by simp
/-- A local homeomorphism is continuous at any point of its source -/
lemma continuous_at_to_fun {x : Ξ±} (h : x β e.source) : continuous_at e.to_fun x :=
(e.continuous_to_fun x h).continuous_at (mem_nhds_sets e.open_source h)
/-- A local homeomorphism inverse is continuous at any point of its target -/
lemma continuous_at_inv_fun {x : Ξ²} (h : x β e.target) : continuous_at e.inv_fun x :=
e.symm.continuous_at_to_fun h
/-- Preimage of interior or interior of preimage coincide for local homeomorphisms, when restricted
to the source. -/
lemma preimage_interior (s : set Ξ²) :
e.source β© e.to_fun β»ΒΉ' (interior s) = e.source β© interior (e.to_fun β»ΒΉ' s) :=
begin
apply subset.antisymm,
{ exact e.continuous_to_fun.preimage_interior_subset_interior_preimage e.open_source },
{ calc e.source β© interior (e.to_fun β»ΒΉ' s)
= (e.source β© e.to_fun β»ΒΉ' e.target) β© interior (e.to_fun β»ΒΉ' s) : begin
congr,
apply (inter_eq_self_of_subset_left _).symm,
apply e.to_local_equiv.source_subset_preimage_target,
end
... = (e.source β© interior (e.to_fun β»ΒΉ' s)) β© (e.to_fun β»ΒΉ' e.target) :
by simp [inter_comm, inter_assoc]
... = (e.source β© e.to_fun β»ΒΉ' (e.inv_fun β»ΒΉ' (interior (e.to_fun β»ΒΉ' s)))) β© (e.to_fun β»ΒΉ' e.target) :
by rw e.to_local_equiv.source_inter_preimage_inv_preimage
... = e.source β© e.to_fun β»ΒΉ' (e.target β© e.inv_fun β»ΒΉ' (interior (e.to_fun β»ΒΉ' s))) :
by rw [inter_comm e.target, preimage_inter, inter_assoc]
... β e.source β© e.to_fun β»ΒΉ' (e.target β© interior (e.inv_fun β»ΒΉ' (e.to_fun β»ΒΉ' s))) : begin
apply inter_subset_inter (subset.refl _) (preimage_mono _),
exact e.continuous_inv_fun.preimage_interior_subset_interior_preimage e.open_target
end
... = e.source β© e.to_fun β»ΒΉ' (interior (e.target β© e.inv_fun β»ΒΉ' (e.to_fun β»ΒΉ' s))) :
by rw [interior_inter, interior_eq_of_open e.open_target]
... = e.source β© e.to_fun β»ΒΉ' (interior (e.target β© s)) :
by rw e.to_local_equiv.target_inter_inv_preimage_preimage
... = e.source β© e.to_fun β»ΒΉ' e.target β© e.to_fun β»ΒΉ' (interior s) :
by rw [interior_inter, preimage_inter, interior_eq_of_open e.open_target, inter_assoc]
... = e.source β© e.to_fun β»ΒΉ' (interior s) : begin
congr,
apply inter_eq_self_of_subset_left,
apply e.to_local_equiv.source_subset_preimage_target
end }
end
/-- The image of an open set in the source is open. -/
lemma image_open_of_open {s : set Ξ±} (hs : is_open s) (h : s β e.source) : is_open (e.to_fun '' s) :=
begin
have : e.to_fun '' s = e.target β© e.inv_fun β»ΒΉ' s :=
e.to_local_equiv.image_eq_target_inter_inv_preimage h,
rw this,
exact e.continuous_inv_fun.preimage_open_of_open e.open_target hs
end
/-- Restricting a local homeomorphism `e` to `e.source β© s` when `s` is open. This is sometimes hard
to use because of the openness assumption, but it has the advantage that when it can
be used then its local_equiv is defeq to local_equiv.restr -/
protected def restr_open (s : set Ξ±) (hs : is_open s) :
local_homeomorph Ξ± Ξ² :=
{ open_source := is_open_inter e.open_source hs,
open_target := (continuous_on_open_iff e.open_target).1 e.continuous_inv_fun s hs,
continuous_to_fun := e.continuous_to_fun.mono (inter_subset_left _ _),
continuous_inv_fun := e.continuous_inv_fun.mono (inter_subset_left _ _),
..e.to_local_equiv.restr s}
@[simp] lemma restr_open_source (s : set Ξ±) (hs : is_open s) :
(e.restr_open s hs).source = e.source β© s := rfl
@[simp] lemma restr_open_to_local_equiv (s : set Ξ±) (hs : is_open s) :
(e.restr_open s hs).to_local_equiv = e.to_local_equiv.restr s := rfl
/-- Restricting a local homeomorphism `e` to `e.source β© interior s`. We use the interior to make
sure that the restriction is well defined whatever the set s, since local homeomorphisms are by
definition defined on open sets. In applications where `s` is open, this coincides with the
restriction of local equivalences -/
protected def restr (s : set Ξ±) : local_homeomorph Ξ± Ξ² :=
e.restr_open (interior s) is_open_interior
@[simp] lemma restr_to_fun (s : set Ξ±) : (e.restr s).to_fun = e.to_fun := rfl
@[simp] lemma restr_inv_fun (s : set Ξ±) : (e.restr s).inv_fun = e.inv_fun := rfl
@[simp] lemma restr_source (s : set Ξ±) : (e.restr s).source = e.source β© interior s := rfl
@[simp] lemma restr_target (s : set Ξ±) :
(e.restr s).target = e.target β© e.inv_fun β»ΒΉ' (interior s) := rfl
@[simp] lemma restr_to_local_equiv (s : set Ξ±) :
(e.restr s).to_local_equiv = (e.to_local_equiv).restr (interior s) := rfl
lemma restr_source' (s : set Ξ±) (hs : is_open s) : (e.restr s).source = e.source β© s :=
by rw [e.restr_source, interior_eq_of_open hs]
lemma restr_to_local_equiv' (s : set Ξ±) (hs : is_open s):
(e.restr s).to_local_equiv = e.to_local_equiv.restr s :=
by rw [e.restr_to_local_equiv, interior_eq_of_open hs]
lemma restr_eq_of_source_subset {e : local_homeomorph Ξ± Ξ²} {s : set Ξ±} (h : e.source β s) :
e.restr s = e :=
begin
apply eq_of_local_equiv_eq,
rw restr_to_local_equiv,
apply local_equiv.restr_eq_of_source_subset,
have := interior_mono h,
rwa interior_eq_of_open (e.open_source) at this
end
@[simp] lemma restr_univ {e : local_homeomorph Ξ± Ξ²} : e.restr univ = e :=
restr_eq_of_source_subset (subset_univ _)
lemma restr_source_inter (s : set Ξ±) : e.restr (e.source β© s) = e.restr s :=
begin
refine local_homeomorph.ext _ _ (Ξ»x, rfl) (Ξ»x, rfl) _,
simp [interior_eq_of_open e.open_source],
rw [β inter_assoc, inter_self]
end
/-- The identity on the whole space as a local homeomorphism. -/
protected def refl (Ξ± : Type*) [topological_space Ξ±] : local_homeomorph Ξ± Ξ± :=
(homeomorph.refl Ξ±).to_local_homeomorph
@[simp] lemma refl_source : (local_homeomorph.refl Ξ±).source = univ := rfl
@[simp] lemma refl_target : (local_homeomorph.refl Ξ±).target = univ := rfl
@[simp] lemma refl_symm : (local_homeomorph.refl Ξ±).symm = local_homeomorph.refl Ξ± := rfl
@[simp] lemma refl_to_fun : (local_homeomorph.refl Ξ±).to_fun = id := rfl
@[simp] lemma refl_inv_fun : (local_homeomorph.refl Ξ±).inv_fun = id := rfl
@[simp] lemma refl_local_equiv : (local_homeomorph.refl Ξ±).to_local_equiv = local_equiv.refl Ξ± := rfl
section
variables {s : set Ξ±} (hs : is_open s)
/-- The identity local equiv on a set `s` -/
def of_set (s : set Ξ±) (hs : is_open s) : local_homeomorph Ξ± Ξ± :=
{ open_source := hs,
open_target := hs,
continuous_to_fun := continuous_id.continuous_on,
continuous_inv_fun := continuous_id.continuous_on,
..local_equiv.of_set s }
@[simp] lemma of_set_source : (of_set s hs).source = s := rfl
@[simp] lemma of_set_target : (of_set s hs).target = s := rfl
@[simp] lemma of_set_to_fun : (of_set s hs).to_fun = id := rfl
@[simp] lemma of_set_inv_fun : (of_set s hs).inv_fun = id := rfl
@[simp] lemma of_set_symm : (of_set s hs).symm = of_set s hs := rfl
@[simp] lemma of_set_to_local_equiv : (of_set s hs).to_local_equiv = local_equiv.of_set s := rfl
end
/-- Composition of two local homeomorphisms when the target of the first and the source of
the second coincide. -/
protected def trans' (h : e.target = e'.source) : local_homeomorph Ξ± Ξ³ :=
{ open_source := e.open_source,
open_target := e'.open_target,
continuous_to_fun := begin
apply continuous_on.comp e'.continuous_to_fun e.continuous_to_fun,
rw β h,
exact e.to_local_equiv.source_subset_preimage_target
end,
continuous_inv_fun := begin
apply continuous_on.comp e.continuous_inv_fun e'.continuous_inv_fun,
rw h,
exact e'.to_local_equiv.target_subset_preimage_source
end,
..local_equiv.trans' e.to_local_equiv e'.to_local_equiv h }
/-- Composing two local homeomorphisms, by restricting to the maximal domain where their
composition is well defined. -/
protected def trans : local_homeomorph Ξ± Ξ³ :=
local_homeomorph.trans' (e.symm.restr_open e'.source e'.open_source).symm
(e'.restr_open e.target e.open_target) (by simp [inter_comm])
@[simp] lemma trans_to_local_equiv :
(e.trans e').to_local_equiv = e.to_local_equiv.trans e'.to_local_equiv := rfl
@[simp] lemma trans_to_fun : (e.trans e').to_fun = e'.to_fun β e.to_fun := rfl
@[simp] lemma trans_inv_fun : (e.trans e').inv_fun = e.inv_fun β e'.inv_fun := rfl
lemma trans_symm_eq_symm_trans_symm : (e.trans e').symm = e'.symm.trans e.symm :=
by cases e; cases e'; refl
/- This could be considered as a simp lemma, but there are many situations where it makes something
simple into something more complicated. -/
lemma trans_source : (e.trans e').source = e.source β© e.to_fun β»ΒΉ' e'.source :=
local_equiv.trans_source e.to_local_equiv e'.to_local_equiv
lemma trans_source' : (e.trans e').source = e.source β© e.to_fun β»ΒΉ' (e.target β© e'.source) :=
local_equiv.trans_source' e.to_local_equiv e'.to_local_equiv
lemma trans_source'' : (e.trans e').source = e.inv_fun '' (e.target β© e'.source) :=
local_equiv.trans_source'' e.to_local_equiv e'.to_local_equiv
lemma image_trans_source : e.to_fun '' (e.trans e').source = e.target β© e'.source :=
local_equiv.image_trans_source e.to_local_equiv e'.to_local_equiv
lemma trans_target : (e.trans e').target = e'.target β© e'.inv_fun β»ΒΉ' e.target := rfl
lemma trans_target' : (e.trans e').target = e'.target β© e'.inv_fun β»ΒΉ' (e'.source β© e.target) :=
trans_source' e'.symm e.symm
lemma trans_target'' : (e.trans e').target = e'.to_fun '' (e'.source β© e.target) :=
trans_source'' e'.symm e.symm
lemma inv_image_trans_target : e'.inv_fun '' (e.trans e').target = e'.source β© e.target :=
image_trans_source e'.symm e.symm
lemma trans_assoc (e'' : local_homeomorph Ξ³ Ξ΄) :
(e.trans e').trans e'' = e.trans (e'.trans e'') :=
eq_of_local_equiv_eq $ local_equiv.trans_assoc e.to_local_equiv e'.to_local_equiv e''.to_local_equiv
@[simp] lemma trans_refl : e.trans (local_homeomorph.refl Ξ²) = e :=
eq_of_local_equiv_eq $ local_equiv.trans_refl e.to_local_equiv
@[simp] lemma refl_trans : (local_homeomorph.refl Ξ±).trans e = e :=
eq_of_local_equiv_eq $ local_equiv.refl_trans e.to_local_equiv
lemma trans_of_set {s : set Ξ²} (hs : is_open s) :
e.trans (of_set s hs) = e.restr (e.to_fun β»ΒΉ' s) :=
local_homeomorph.ext _ _ (Ξ»x, rfl) (Ξ»x, rfl) $
by simp [local_equiv.trans_source, (e.preimage_interior _).symm, interior_eq_of_open hs]
lemma trans_of_set' {s : set Ξ²} (hs : is_open s) :
e.trans (of_set s hs) = e.restr (e.source β© e.to_fun β»ΒΉ' s) :=
by rw [trans_of_set, restr_source_inter]
lemma of_set_trans {s : set Ξ±} (hs : is_open s) :
(of_set s hs).trans e = e.restr s :=
local_homeomorph.ext _ _ (Ξ»x, rfl) (Ξ»x, rfl) $
by simp [local_equiv.trans_source, interior_eq_of_open hs, inter_comm]
lemma of_set_trans' {s : set Ξ±} (hs : is_open s) :
(of_set s hs).trans e = e.restr (e.source β© s) :=
by rw [of_set_trans, restr_source_inter]
lemma restr_trans (s : set Ξ±) :
(e.restr s).trans e' = (e.trans e').restr s :=
eq_of_local_equiv_eq $ local_equiv.restr_trans e.to_local_equiv e'.to_local_equiv (interior s)
/-- `eq_on_source e e'` means that `e` and `e'` have the same source, and coincide there. They
should really be considered the same local equiv. -/
def eq_on_source (e e' : local_homeomorph Ξ± Ξ²) : Prop :=
e.source = e'.source β§ (βx β e.source, e.to_fun x = e'.to_fun x)
lemma eq_on_source_iff (e e' : local_homeomorph Ξ± Ξ²) :
eq_on_source e e' β local_equiv.eq_on_source e.to_local_equiv e'.to_local_equiv :=
by refl
/-- `eq_on_source` is an equivalence relation -/
instance : setoid (local_homeomorph Ξ± Ξ²) :=
{ r := eq_on_source,
iseqv := β¨
Ξ»e, (@local_equiv.eq_on_source_setoid Ξ± Ξ²).iseqv.1 e.to_local_equiv,
Ξ»e e' h, (@local_equiv.eq_on_source_setoid Ξ± Ξ²).iseqv.2.1 ((eq_on_source_iff e e').1 h),
Ξ»e e' e'' h h', (@local_equiv.eq_on_source_setoid Ξ± Ξ²).iseqv.2.2
((eq_on_source_iff e e').1 h) ((eq_on_source_iff e' e'').1 h')β© }
lemma eq_on_source_refl : e β e := setoid.refl _
/-- If two local homeomorphisms are equivalent, so are their inverses -/
lemma eq_on_source_symm {e e' : local_homeomorph Ξ± Ξ²} (h : e β e') : e.symm β e'.symm :=
local_equiv.eq_on_source_symm h
/-- Two equivalent local homeomorphisms have the same source -/
lemma source_eq_of_eq_on_source {e e' : local_homeomorph Ξ± Ξ²} (h : e β e') : e.source = e'.source :=
h.1
/-- Two equivalent local homeomorphisms have the same target -/
lemma target_eq_of_eq_on_source {e e' : local_homeomorph Ξ± Ξ²} (h : e β e') : e.target = e'.target :=
(eq_on_source_symm h).1
/-- Two equivalent local homeomorphisms have coinciding `to_fun` on the source -/
lemma apply_eq_of_eq_on_source {e e' : local_homeomorph Ξ± Ξ²} (h : e β e') {x : Ξ±} (hx : x β e.source) :
e.to_fun x = e'.to_fun x :=
h.2 x hx
/-- Two equivalent local homeomorphisms have coinciding `inv_fun` on the target -/
lemma inv_apply_eq_of_eq_on_source {e e' : local_homeomorph Ξ± Ξ²} (h : e β e') {x : Ξ²} (hx : x β e.target) :
e.inv_fun x = e'.inv_fun x :=
(eq_on_source_symm h).2 x hx
/-- Composition of local homeomorphisms respects equivalence -/
lemma eq_on_source_trans {e e' : local_homeomorph Ξ± Ξ²} {f f' : local_homeomorph Ξ² Ξ³}
(he : e β e') (hf : f β f') : e.trans f β e'.trans f' :=
begin
change local_equiv.eq_on_source (e.trans f).to_local_equiv (e'.trans f').to_local_equiv,
simp only [trans_to_local_equiv],
apply local_equiv.eq_on_source_trans,
exact he,
exact hf
end
/-- Restriction of local homeomorphisms respects equivalence -/
lemma eq_on_source_restr {e e' : local_homeomorph Ξ± Ξ²} (he : e β e') (s : set Ξ±) :
e.restr s β e'.restr s :=
local_equiv.eq_on_source_restr he _
/-- Composition of a local homeomorphism and its inverse is equivalent to the restriction of the
identity to the source -/
lemma trans_self_symm :
e.trans e.symm β local_homeomorph.of_set e.source e.open_source :=
local_equiv.trans_self_symm _
lemma trans_symm_self :
e.symm.trans e β local_homeomorph.of_set e.target e.open_target :=
e.symm.trans_self_symm
lemma eq_of_eq_on_source_univ {e e' : local_homeomorph Ξ± Ξ²} (h : e β e')
(s : e.source = univ) (t : e.target = univ) : e = e' :=
eq_of_local_equiv_eq $ local_equiv.eq_of_eq_on_source_univ _ _ h s t
section prod
/-- The product of two local homeomorphisms, as a local homeomorphism on the product space. -/
def prod (e : local_homeomorph Ξ± Ξ²) (e' : local_homeomorph Ξ³ Ξ΄) : local_homeomorph (Ξ± Γ Ξ³) (Ξ² Γ Ξ΄) :=
{ open_source := is_open_prod e.open_source e'.open_source,
open_target := is_open_prod e.open_target e'.open_target,
continuous_to_fun := continuous_on.prod
(continuous_on.comp e.continuous_to_fun continuous_fst.continuous_on (prod_subset_preimage_fst _ _))
(continuous_on.comp e'.continuous_to_fun continuous_snd.continuous_on (prod_subset_preimage_snd _ _)),
continuous_inv_fun := continuous_on.prod
(continuous_on.comp e.continuous_inv_fun continuous_fst.continuous_on (prod_subset_preimage_fst _ _))
(continuous_on.comp e'.continuous_inv_fun continuous_snd.continuous_on (prod_subset_preimage_snd _ _)),
..e.to_local_equiv.prod e'.to_local_equiv }
@[simp] lemma prod_to_local_equiv (e : local_homeomorph Ξ± Ξ²) (e' : local_homeomorph Ξ³ Ξ΄) :
(e.prod e').to_local_equiv = e.to_local_equiv.prod e'.to_local_equiv := rfl
@[simp] lemma prod_source (e : local_homeomorph Ξ± Ξ²) (e' : local_homeomorph Ξ³ Ξ΄) :
(e.prod e').source = set.prod e.source e'.source := rfl
@[simp] lemma prod_target (e : local_homeomorph Ξ± Ξ²) (e' : local_homeomorph Ξ³ Ξ΄) :
(e.prod e').target = set.prod e.target e'.target := rfl
@[simp] lemma prod_to_fun (e : local_homeomorph Ξ± Ξ²) (e' : local_homeomorph Ξ³ Ξ΄) :
(e.prod e').to_fun = (Ξ»p, (e.to_fun p.1, e'.to_fun p.2)) := rfl
@[simp] lemma prod_inv_fun (e : local_homeomorph Ξ± Ξ²) (e' : local_homeomorph Ξ³ Ξ΄) :
(e.prod e').inv_fun = (Ξ»p, (e.inv_fun p.1, e'.inv_fun p.2)) := rfl
end prod
section continuity
/-- Continuity within a set at a point can be read under right composition with a local
homeomorphism, if the point is in its target -/
lemma continuous_within_at_iff_continuous_within_at_comp_right
{f : Ξ² β Ξ³} {s : set Ξ²} {x : Ξ²} (h : x β e.target) :
continuous_within_at f s x β
continuous_within_at (f β e.to_fun) (e.to_fun β»ΒΉ' s) (e.inv_fun x) :=
begin
split,
{ assume f_cont,
have : e.to_fun (e.inv_fun x) = x := e.right_inv h,
rw β this at f_cont,
have : e.source β nhds (e.inv_fun x) := mem_nhds_sets e.open_source (e.map_target h),
rw [β continuous_within_at_inter this, inter_comm],
exact continuous_within_at.comp f_cont
((e.continuous_at_to_fun (e.map_target h)).continuous_within_at) (inter_subset_right _ _) },
{ assume fe_cont,
have : continuous_within_at ((f β e.to_fun) β e.inv_fun) (s β© e.target) x,
{ apply continuous_within_at.comp fe_cont,
apply (e.continuous_at_inv_fun h).continuous_within_at,
assume x hx,
simp [hx.1, hx.2, e.map_target] },
have : continuous_within_at f (s β© e.target) x :=
continuous_within_at.congr this (Ξ»y hy, by simp [hy.2]) (by simp [h]),
rwa continuous_within_at_inter at this,
exact mem_nhds_sets e.open_target h }
end
/-- Continuity at a point can be read under right composition with a local homeomorphism, if the
point is in its target -/
lemma continuous_at_iff_continuous_at_comp_right
{f : Ξ² β Ξ³} {x : Ξ²} (h : x β e.target) :
continuous_at f x β continuous_at (f β e.to_fun) (e.inv_fun x) :=
by rw [β continuous_within_at_univ, e.continuous_within_at_iff_continuous_within_at_comp_right h,
preimage_univ, continuous_within_at_univ]
/-- A function is continuous on a set if and only if its composition with a local homeomorphism
on the right is continuous on the corresponding set. -/
lemma continuous_on_iff_continuous_on_comp_right {f : Ξ² β Ξ³} {s : set Ξ²} (h : s β e.target) :
continuous_on f s β continuous_on (f β e.to_fun) (e.source β© e.to_fun β»ΒΉ' s) :=
begin
split,
{ assume f_cont x hx,
have := e.continuous_within_at_iff_continuous_within_at_comp_right (e.map_source hx.1),
rw e.left_inv hx.1 at this,
have A := f_cont _ hx.2,
rw this at A,
exact A.mono (inter_subset_right _ _), },
{ assume fe_cont x hx,
have := e.continuous_within_at_iff_continuous_within_at_comp_right (h hx),
rw this,
have : e.source β nhds (e.inv_fun x) := mem_nhds_sets e.open_source (e.map_target (h hx)),
rw [β continuous_within_at_inter this, inter_comm],
exact fe_cont _ (by simp [hx, h hx, e.map_target (h hx)]) }
end
/-- Continuity within a set at a point can be read under left composition with a local
homeomorphism if a neighborhood of the initial point is sent to the source of the local
homeomorphism-/
lemma continuous_within_at_iff_continuous_within_at_comp_left
{f : Ξ³ β Ξ±} {s : set Ξ³} {x : Ξ³} (hx : f x β e.source) (h : f β»ΒΉ' e.source β nhds_within x s) :
continuous_within_at f s x β continuous_within_at (e.to_fun β f) s x :=
begin
rw [β continuous_within_at_inter' h, β continuous_within_at_inter' h],
split,
{ assume f_cont,
have : e.source β nhds (f x) := mem_nhds_sets e.open_source hx,
apply continuous_within_at.comp (e.continuous_to_fun (f x) hx) f_cont (inter_subset_right _ _) },
{ assume fe_cont,
have : continuous_within_at (e.inv_fun β (e.to_fun β f)) (s β© f β»ΒΉ' e.source) x,
{ have : continuous_within_at e.inv_fun univ (e.to_fun (f x))
:= (e.continuous_at_inv_fun (e.map_source hx)).continuous_within_at,
exact continuous_within_at.comp this fe_cont (subset_univ _) },
exact this.congr (Ξ»y hy, by simp [e.left_inv hy.2]) (by simp [e.left_inv hx]) }
end
/-- Continuity at a point can be read under left composition with a local homeomorphism if a
neighborhood of the initial point is sent to the source of the local homeomorphism-/
lemma continuous_at_iff_continuous_at_comp_left
{f : Ξ³ β Ξ±} {x : Ξ³} (h : f β»ΒΉ' e.source β nhds x) :
continuous_at f x β continuous_at (e.to_fun β f) x :=
begin
have hx : f x β e.source := (mem_of_nhds h : _),
have h' : f β»ΒΉ' e.source β nhds_within x univ, by rwa nhds_within_univ,
rw [β continuous_within_at_univ, β continuous_within_at_univ,
e.continuous_within_at_iff_continuous_within_at_comp_left hx h']
end
/-- A function is continuous on a set if and only if its composition with a local homeomorphism
on the left is continuous on the corresponding set. -/
lemma continuous_on_iff_continuous_on_comp_left {f : Ξ³ β Ξ±} {s : set Ξ³} (h : s β f β»ΒΉ' e.source) :
continuous_on f s β continuous_on (e.to_fun β f) s :=
begin
split,
{ assume f_cont,
exact continuous_on.comp e.continuous_to_fun f_cont h },
{ assume fe_cont,
have : continuous_on (e.inv_fun β e.to_fun β f) s,
{ apply continuous_on.comp e.continuous_inv_fun fe_cont,
assume x hx,
have : f x β e.source := h hx,
simp [this] },
refine continuous_on.congr_mono this (Ξ»x hx, _) (subset.refl _),
have : f x β e.source := h hx,
simp [this] }
end
end continuity
/-- If a local homeomorphism has source and target equal to univ, then it induces a homeomorphism
between the whole spaces, expressed in this definition. -/
def to_homeomorph_of_source_eq_univ_target_eq_univ (h : e.source = (univ : set Ξ±))
(h' : e.target = univ) : homeomorph Ξ± Ξ² :=
{ to_fun := e.to_fun,
inv_fun := e.inv_fun,
left_inv := Ξ»x, e.left_inv $ by { rw h, exact mem_univ _ },
right_inv := Ξ»x, e.right_inv $ by { rw h', exact mem_univ _ },
continuous_to_fun := begin
rw [continuous_iff_continuous_on_univ],
convert e.continuous_to_fun,
rw h
end,
continuous_inv_fun := begin
rw [continuous_iff_continuous_on_univ],
convert e.continuous_inv_fun,
rw h'
end }
@[simp] lemma to_homeomorph_to_fun (h : e.source = (univ : set Ξ±)) (h' : e.target = univ) :
(e.to_homeomorph_of_source_eq_univ_target_eq_univ h h').to_fun = e.to_fun := rfl
@[simp] lemma to_homeomorph_inv_fun (h : e.source = (univ : set Ξ±)) (h' : e.target = univ) :
(e.to_homeomorph_of_source_eq_univ_target_eq_univ h h').inv_fun = e.inv_fun := rfl
end local_homeomorph
namespace homeomorph
variables (e : homeomorph Ξ± Ξ²) (e' : homeomorph Ξ² Ξ³)
/- Register as simp lemmas that the fields of a local homeomorphism built from a homeomorphism
correspond to the fields of the original homeomorphism. -/
@[simp] lemma to_local_homeomorph_source : e.to_local_homeomorph.source = univ := rfl
@[simp] lemma to_local_homeomorph_target : e.to_local_homeomorph.target = univ := rfl
@[simp] lemma to_local_homeomorph_to_fun : e.to_local_homeomorph.to_fun = e.to_fun := rfl
@[simp] lemma to_local_homeomorph_inv_fun : e.to_local_homeomorph.inv_fun = e.inv_fun := rfl
@[simp] lemma refl_to_local_homeomorph :
(homeomorph.refl Ξ±).to_local_homeomorph = local_homeomorph.refl Ξ± := rfl
@[simp] lemma symm_to_local_homeomorph : e.symm.to_local_homeomorph = e.to_local_homeomorph.symm := rfl
@[simp] lemma trans_to_local_homeomorph :
(e.trans e').to_local_homeomorph = e.to_local_homeomorph.trans e'.to_local_homeomorph :=
local_homeomorph.eq_of_local_equiv_eq $ equiv.trans_to_local_equiv _ _
end homeomorph
|
5ec5dd4e283d1ccd194d42257e9528c60fe8f7a5
|
ae1e94c332e17c7dc7051ce976d5a9eebe7ab8a5
|
/src/Leanpkg/Resolve.lean
|
fc379eeefe78093557b474c918cf7a051d72db05
|
[
"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
| 3,329
|
lean
|
/-
Copyright (c) 2017 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Gabriel Ebner, Sebastian Ullrich
-/
import Leanpkg.Manifest
import Leanpkg.Proc
import Leanpkg.Git
namespace Leanpkg
def Assignment := List (String Γ String)
namespace Assignment
def empty : Assignment := []
def contains (a : Assignment) (s : String) : Bool :=
(a.lookup s).isSome
def insert (a : Assignment) (k v : String) : Assignment :=
if a.contains k then a else (k, v) :: a
def fold {Ξ±} (i : Ξ±) (f : Ξ± β String β String β Ξ±) : Assignment β Ξ± :=
List.foldl (fun a β¨k, vβ© => f a k v) i
end Assignment
abbrev Solver := StateT Assignment IO
def notYetAssigned (d : String) : Solver Bool := do
Β¬ (β get).contains d
def resolvedPath (d : String) : Solver String := do
let some path β pure ((β get).lookup d) | unreachable!
path
-- TODO(gabriel): windows?
def resolveDir (absOrRel : String) (base : String) : String :=
if absOrRel.front = '/' then
absOrRel -- absolute
else
base ++ "/" ++ absOrRel
def materialize (relpath : String) (dep : Dependency) : Solver Unit :=
match dep.src with
| Source.path dir => do
let depdir := resolveDir dir relpath
IO.println s!"{dep.name}: using local path {depdir}"
modify (Β·.insert dep.name depdir)
| Source.git url rev branch => do
let depdir := "build/deps/" ++ dep.name
let alreadyThere β IO.isDir depdir
if alreadyThere then
IO.print s!"{dep.name}: trying to update {depdir} to revision {rev}"
IO.println (match branch with | none => "" | some branch => "@" ++ branch)
let hash β gitParseOriginRevision depdir rev
let revEx β gitRevisionExists depdir hash
unless revEx do
execCmd {cmd := "git", args := #["fetch"], cwd := depdir}
else
IO.println s!"{dep.name}: cloning {url} to {depdir}"
execCmd {cmd := "git", args := #["clone", url, depdir]}
let hash β gitParseOriginRevision depdir rev
execCmd {cmd := "git", args := #["checkout", "--detach", hash], cwd := depdir}
modify (Β·.insert dep.name depdir)
def solveDepsCore (relPath : String) (d : Manifest) : (maxDepth : Nat) β Solver Unit
| 0 => throw <| IO.userError "maximum dependency resolution depth reached"
| maxDepth + 1 => do
let deps β d.dependencies.filterM (notYetAssigned Β·.name)
deps.forM (materialize relPath)
for dep in deps do
let p β resolvedPath dep.name
let d' β Manifest.fromFile $ p ++ "/" ++ "leanpkg.toml"
unless d'.name = dep.name do
throw <| IO.userError <| d.name ++ " (in " ++ relPath ++ ") depends on " ++ d'.name ++
", but resolved dependency has name " ++ dep.name ++ " (in " ++ p ++ ")"
solveDepsCore p d' maxDepth
def solveDeps (d : Manifest) : IO Assignment := do
let (_, assg) β (solveDepsCore "." d 1024).run <| Assignment.empty.insert d.name "."
assg
def constructPathCore (depname : String) (dirname : String) : IO String := do
let path β Manifest.effectivePath (β Manifest.fromFile $ dirname ++ "/" ++ leanpkgTomlFn)
return dirname ++ "/" ++ path
def constructPath (assg : Assignment) : IO (List String) := do
assg.reverse.mapM fun β¨depname, dirnameβ© => constructPathCore depname dirname
end Leanpkg
|
af3e87af711e68fc0e2e6daae6f8925769cbd687
|
fa02ed5a3c9c0adee3c26887a16855e7841c668b
|
/src/data/equiv/embedding.lean
|
666ab82e4d65283dedc7533cc9225c893998eb0f
|
[
"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
| 3,779
|
lean
|
/-
Copyright (c) 2021 Eric Rodriguez. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Rodriguez
-/
import logic.embedding
import data.set.lattice
/-!
# Equivalences on embeddings
This file shows some advanced equivalences on embeddings, useful for constructing larger
embeddings from smaller ones.
-/
open function.embedding
namespace equiv
/-- Embeddings from a sum type are equivalent to two separate embeddings with disjoint ranges. -/
def sum_embedding_equiv_prod_embedding_disjoint {Ξ± Ξ² Ξ³ : Type*} :
((Ξ± β Ξ²) βͺ Ξ³) β {f : (Ξ± βͺ Ξ³) Γ (Ξ² βͺ Ξ³) // disjoint (set.range f.1) (set.range f.2)} :=
{ to_fun := Ξ» f, β¨(inl.trans f, inr.trans f),
begin
rintros _ β¨β¨a, hβ©, β¨b, rflβ©β©,
simp only [trans_apply, inl_apply, inr_apply] at h,
have : sum.inl a = sum.inr b := f.injective h,
simp only at this,
assumption
endβ©,
inv_fun := Ξ» β¨β¨f, gβ©, disjβ©,
β¨Ξ» x, match x with
| (sum.inl a) := f a
| (sum.inr b) := g b
end,
begin
rintros (aβ|bβ) (aβ|bβ) f_eq;
simp only [equiv.coe_fn_symm_mk, sum.elim_inl, sum.elim_inr] at f_eq,
{ rw f.injective f_eq },
{ simp! only at f_eq, exfalso, exact disj β¨β¨aβ, by simpβ©, β¨bβ, by simp [f_eq]β©β© },
{ simp! only at f_eq, exfalso, exact disj β¨β¨aβ, by simpβ©, β¨bβ, by simp [f_eq]β©β© },
{ rw g.injective f_eq }
endβ©,
left_inv := Ξ» f, by { dsimp only, ext, cases x; simp! },
right_inv := Ξ» β¨β¨f, gβ©, _β©, by { simp only [prod.mk.inj_iff], split; ext; simp! } }
/-- Embeddings whose range lies within a set are equivalent to embeddings to that set.
This is `function.embedding.cod_restrict` as an equiv. -/
def cod_restrict (Ξ± : Type*) {Ξ² : Type*} (bs : set Ξ²) :
{f : Ξ± βͺ Ξ² // β a, f a β bs} β (Ξ± βͺ bs) :=
{ to_fun := Ξ» f, (f : Ξ± βͺ Ξ²).cod_restrict bs f.prop,
inv_fun := Ξ» f, β¨f.trans (function.embedding.subtype _), Ξ» a, (f a).propβ©,
left_inv := Ξ» x, by ext; refl,
right_inv := Ξ» x, by ext; refl }
/-- Pairs of embeddings with disjoint ranges are equivalent to a dependent sum of embeddings,
in which the second embedding cannot take values in the range of the first. -/
def prod_embedding_disjoint_equiv_sigma_embedding_restricted {Ξ± Ξ² Ξ³ : Type*} :
{f : (Ξ± βͺ Ξ³) Γ (Ξ² βͺ Ξ³) // disjoint (set.range f.1) (set.range f.2)} β
(Ξ£ f : Ξ± βͺ Ξ³, Ξ² βͺ β₯((set.range f)αΆ)) :=
(subtype_prod_equiv_sigma_subtype $
Ξ» (a : Ξ± βͺ Ξ³) (b : Ξ² βͺ _), disjoint (set.range a) (set.range b)).trans $
equiv.sigma_congr_right $ Ξ» a,
(subtype_equiv_prop begin
ext f,
rw [βset.range_subset_iff, set.subset_compl_iff_disjoint],
exact disjoint.comm.trans disjoint_iff,
end).trans (cod_restrict _ _)
/-- A combination of the above results, allowing us to turn one embedding over a sum type
into two dependent embeddings, the second of which avoids any members of the range
of the first. This is helpful for constructing larger embeddings out of smaller ones. -/
def sum_embedding_equiv_sigma_embedding_restricted {Ξ± Ξ² Ξ³ : Type*} :
((Ξ± β Ξ²) βͺ Ξ³) β (Ξ£ f : Ξ± βͺ Ξ³, Ξ² βͺ β₯((set.range f)αΆ))
:= equiv.trans sum_embedding_equiv_prod_embedding_disjoint
prod_embedding_disjoint_equiv_sigma_embedding_restricted
/-- Embeddings from a single-member type are equivalent to members of the target type. -/
def unique_embedding_equiv_result {Ξ± Ξ² : Type*} [unique Ξ±] : (Ξ± βͺ Ξ²) β Ξ² :=
{ to_fun := Ξ» f, f (default Ξ±),
inv_fun := Ξ» x, β¨Ξ» _, x, Ξ» _ _ _, subsingleton.elim _ _β©,
left_inv := Ξ» _, by { ext, simp_rw [function.embedding.coe_fn_mk], congr },
right_inv := Ξ» _, by simp }
end equiv
|
8314ed4003181108bbfebedcecc39fd3d78687eb
|
37336e9dcf558f325cf43bdf45bab5d8e455a3b4
|
/M1F/2017-18/Example_Sheet_01/Question_07/M1F_sheet01_question07.lean
|
e8663d80199f3628202321a6cc930ebc556f6bdf
|
[] |
no_license
|
rafaelbailo/xena
|
bfeab41b3b401c812689a4879d58f2ad046240b5
|
fad865c3d1bac6279f9a77e8aa6ba7e0cd572e06
|
refs/heads/master
| 1,626,002,809,060
| 1,507,793,086,000
| 1,507,793,086,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 590
|
lean
|
import topology.real
-- real numbers live in here in Lean 3.3.0 mathlib
-- NB you need mathlib installed to get this working.
-- of_rat is the injection from the rationals to the reals.
def A : set β := { x | x^2 < 3}
def B : set β := {x | (β y : β€, x = of_rat y) β§ x^2 < 3}
def C : set β := {x | x^3 < 3}
theorem part_a : of_rat (1/2) β A β© B := sorry
theorem part_b : of_rat (1/2) β A βͺ B := sorry
theorem part_c : A β C := sorry
theorem part_d : B β C := sorry
theorem part_e : C β A βͺ B := sorry
theorem part_f : (A β© B) βͺ C = (A βͺ B) β© C := sorry
|
a945a11253288a4f246428dd8c5073c7cc30f330
|
618003631150032a5676f229d13a079ac875ff77
|
/src/data/list/zip.lean
|
1539eab5120d39790002956f9ca8389cd2a19b76
|
[
"Apache-2.0"
] |
permissive
|
awainverse/mathlib
|
939b68c8486df66cfda64d327ad3d9165248c777
|
ea76bd8f3ca0a8bf0a166a06a475b10663dec44a
|
refs/heads/master
| 1,659,592,962,036
| 1,590,987,592,000
| 1,590,987,592,000
| 268,436,019
| 1
| 0
|
Apache-2.0
| 1,590,990,500,000
| 1,590,990,500,000
| null |
UTF-8
|
Lean
| false
| false
| 5,453
|
lean
|
/-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Kenny Lau
-/
import data.list.basic
universes u v w z
variables {Ξ± : Type u} {Ξ² : Type v} {Ξ³ : Type w} {Ξ΄ : Type z}
open nat
namespace list
/- zip & unzip -/
@[simp] theorem zip_cons_cons (a : Ξ±) (b : Ξ²) (lβ : list Ξ±) (lβ : list Ξ²) :
zip (a :: lβ) (b :: lβ) = (a, b) :: zip lβ lβ := rfl
@[simp] theorem zip_nil_left (l : list Ξ±) : zip ([] : list Ξ²) l = [] := rfl
@[simp] theorem zip_nil_right (l : list Ξ±) : zip l ([] : list Ξ²) = [] :=
by cases l; refl
@[simp] theorem zip_swap : β (lβ : list Ξ±) (lβ : list Ξ²),
(zip lβ lβ).map prod.swap = zip lβ lβ
| [] lβ := (zip_nil_right _).symm
| lβ [] := by rw zip_nil_right; refl
| (a::lβ) (b::lβ) := by simp only [zip_cons_cons, map_cons, zip_swap lβ lβ, prod.swap_prod_mk]; split; refl
@[simp] theorem length_zip : β (lβ : list Ξ±) (lβ : list Ξ²),
length (zip lβ lβ) = min (length lβ) (length lβ)
| [] lβ := rfl
| lβ [] := by simp only [length, zip_nil_right, min_zero]
| (a::lβ) (b::lβ) := by by simp only [length, zip_cons_cons, length_zip lβ lβ, min_add_add_right]
theorem zip_append : β {lβ lβ rβ rβ : list Ξ±} (h : length lβ = length lβ),
zip (lβ ++ rβ) (lβ ++ rβ) = zip lβ lβ ++ zip rβ rβ
| [] lβ rβ rβ h := by simp only [eq_nil_of_length_eq_zero h.symm]; refl
| lβ [] rβ rβ h := by simp only [eq_nil_of_length_eq_zero h]; refl
| (a::lβ) (b::lβ) rβ rβ h := by simp only [cons_append, zip_cons_cons, zip_append (succ_inj h)]; split; refl
theorem zip_map (f : Ξ± β Ξ³) (g : Ξ² β Ξ΄) : β (lβ : list Ξ±) (lβ : list Ξ²),
zip (lβ.map f) (lβ.map g) = (zip lβ lβ).map (prod.map f g)
| [] lβ := rfl
| lβ [] := by simp only [map, zip_nil_right]
| (a::lβ) (b::lβ) := by simp only [map, zip_cons_cons, zip_map lβ lβ, prod.map]; split; refl
theorem zip_map_left (f : Ξ± β Ξ³) (lβ : list Ξ±) (lβ : list Ξ²) :
zip (lβ.map f) lβ = (zip lβ lβ).map (prod.map f id) :=
by rw [β zip_map, map_id]
theorem zip_map_right (f : Ξ² β Ξ³) (lβ : list Ξ±) (lβ : list Ξ²) :
zip lβ (lβ.map f) = (zip lβ lβ).map (prod.map id f) :=
by rw [β zip_map, map_id]
theorem zip_map' (f : Ξ± β Ξ²) (g : Ξ± β Ξ³) : β (l : list Ξ±),
zip (l.map f) (l.map g) = l.map (Ξ» a, (f a, g a))
| [] := rfl
| (a::l) := by simp only [map, zip_cons_cons, zip_map' l]; split; refl
theorem mem_zip {a b} : β {lβ : list Ξ±} {lβ : list Ξ²},
(a, b) β zip lβ lβ β a β lβ β§ b β lβ
| (_::lβ) (_::lβ) (or.inl rfl) := β¨or.inl rfl, or.inl rflβ©
| (a'::lβ) (b'::lβ) (or.inr h) := by split; simp only [mem_cons_iff, or_true, mem_zip h]
@[simp] theorem unzip_nil : unzip (@nil (Ξ± Γ Ξ²)) = ([], []) := rfl
@[simp] theorem unzip_cons (a : Ξ±) (b : Ξ²) (l : list (Ξ± Γ Ξ²)) :
unzip ((a, b) :: l) = (a :: (unzip l).1, b :: (unzip l).2) :=
by rw unzip; cases unzip l; refl
theorem unzip_eq_map : β (l : list (Ξ± Γ Ξ²)), unzip l = (l.map prod.fst, l.map prod.snd)
| [] := rfl
| ((a, b) :: l) := by simp only [unzip_cons, map_cons, unzip_eq_map l]
theorem unzip_left (l : list (Ξ± Γ Ξ²)) : (unzip l).1 = l.map prod.fst :=
by simp only [unzip_eq_map]
theorem unzip_right (l : list (Ξ± Γ Ξ²)) : (unzip l).2 = l.map prod.snd :=
by simp only [unzip_eq_map]
theorem unzip_swap (l : list (Ξ± Γ Ξ²)) : unzip (l.map prod.swap) = (unzip l).swap :=
by simp only [unzip_eq_map, map_map]; split; refl
theorem zip_unzip : β (l : list (Ξ± Γ Ξ²)), zip (unzip l).1 (unzip l).2 = l
| [] := rfl
| ((a, b) :: l) := by simp only [unzip_cons, zip_cons_cons, zip_unzip l]; split; refl
theorem unzip_zip_left : β {lβ : list Ξ±} {lβ : list Ξ²}, length lβ β€ length lβ β
(unzip (zip lβ lβ)).1 = lβ
| [] lβ h := rfl
| lβ [] h := by rw eq_nil_of_length_eq_zero (eq_zero_of_le_zero h); refl
| (a::lβ) (b::lβ) h := by simp only [zip_cons_cons, unzip_cons, unzip_zip_left (le_of_succ_le_succ h)]; split; refl
theorem unzip_zip_right {lβ : list Ξ±} {lβ : list Ξ²} (h : length lβ β€ length lβ) :
(unzip (zip lβ lβ)).2 = lβ :=
by rw [β zip_swap, unzip_swap]; exact unzip_zip_left h
theorem unzip_zip {lβ : list Ξ±} {lβ : list Ξ²} (h : length lβ = length lβ) :
unzip (zip lβ lβ) = (lβ, lβ) :=
by rw [β @prod.mk.eta _ _ (unzip (zip lβ lβ)),
unzip_zip_left (le_of_eq h), unzip_zip_right (ge_of_eq h)]
@[simp] theorem length_revzip (l : list Ξ±) : length (revzip l) = length l :=
by simp only [revzip, length_zip, length_reverse, min_self]
@[simp] theorem unzip_revzip (l : list Ξ±) : (revzip l).unzip = (l, l.reverse) :=
unzip_zip (length_reverse l).symm
@[simp] theorem revzip_map_fst (l : list Ξ±) : (revzip l).map prod.fst = l :=
by rw [β unzip_left, unzip_revzip]
@[simp] theorem revzip_map_snd (l : list Ξ±) : (revzip l).map prod.snd = l.reverse :=
by rw [β unzip_right, unzip_revzip]
theorem reverse_revzip (l : list Ξ±) : reverse l.revzip = revzip l.reverse :=
by rw [β zip_unzip.{u u} (revzip l).reverse, unzip_eq_map]; simp; simp [revzip]
theorem revzip_swap (l : list Ξ±) : (revzip l).map prod.swap = revzip l.reverse :=
by simp [revzip]
end list
|
e56356f4d638df8df14b0b8ee119db5526effbd9
|
36938939954e91f23dec66a02728db08a7acfcf9
|
/lean/deps/galois_stdlib/src/galois/data/buffer.lean
|
29af7a83d4a72d12494a049825bb8edae36c0133
|
[
"Apache-2.0"
] |
permissive
|
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
| 12,974
|
lean
|
/-
Provides a decidable_eq instance for buffer.
-/
import data.buffer
import galois.algebra.ordered_group
import galois.data.array
import galois.data.char
import galois.data.fin
import galois.data.nat
namespace galois
namespace buffer
open buffer
section
variable {Ξ±:Type _}
open galois
-- Taken from mathlib
@[simp]
lemma to_list_append_list (b : buffer Ξ±) (xs : list Ξ±)
: to_list (append_list b xs) = to_list b ++ xs :=
begin
induction xs generalizing b,
case list.nil { simp [append_list], },
case list.cons : h r ind {
cases b,
simp! [to_list, to_array, ind],
},
end
-- Taken from mathlib
lemma ext : β (bβ bβ : buffer Ξ±), to_list bβ = to_list bβ β bβ = bβ
| β¨nβ, aββ© β¨nβ, aββ© h :=
begin
simp [to_list, to_array, array] at h,
have e : nβ = nβ,
{
rw [βarray.to_list_length aβ, βarray.to_list_length aβ, h],
},
subst e,
have g : aβ == list.to_array (aβ.to_list) := h βΈ (array.to_list_to_array aβ).symm,
rw eq_of_heq (g.trans (array.to_list_to_array aβ))
end
end
@[simp]
theorem size_append_array {Ξ±} {n : nat} (nz : n > 0) (x : buffer Ξ±) (y : array n Ξ±) (j : nat) (j_lt : j < n)
: buffer.size (buffer.append_array nz x y j j_lt) = x.size + j + 1 :=
begin
revert x,
induction j,
case nat.zero {
intro x,
cases x,
simp [append_array, size],
},
case nat.succ : j ind {
intro x,
cases x with m b,
simp [append_array, ind],
simp [size, nat.succ_add, nat.add_succ],
},
end
/- Size of appending to buffers is sum of their sizes.-/
@[simp]
theorem size_append {Ξ±} (x y : buffer Ξ±)
: (x ++ y).size = x.size + y.size :=
begin
cases y with n b,
cases n,
case nat.zero { simp [size, append, buffer.append], },
case nat.succ : n {
simp [size, append, buffer.append, size_append_array, nat.succ_add],
}
end
@[simp]
theorem to_list_length {Ξ±} (b: buffer Ξ±)
: list.length (buffer.to_list b) = b.size :=
begin
simp only [buffer.to_list, size, array.to_list_length],
end
/-- Replace nil.to_list with empty list. -/
@[simp]
theorem nil_to_list (Ξ±:Type _) : (@buffer.nil Ξ±).to_list = [] := refl []
/-- Convert read to list read so we can use list lemmas -/
theorem read_to_nth_le {Ξ±} (b: buffer Ξ±) (i:fin b.size)
: buffer.read b i = list.nth_le b.to_list i.val ((to_list_length b).symm βΈ i.is_lt) :=
begin
cases b with n a,
simp only [buffer.read, to_list, array.to_list_nth_le', to_array],
end
/-- Empty buffer converted to array is same as array.nil -/
@[simp]
theorem to_array_mk_buffer {Ξ±} : to_array mk_buffer = @array.nil Ξ± :=
begin
apply array.ext,
intro i,
have h : false := fin.elim0 i,
contradiction,
end
/-- Converting list to bufer and back is round trip. -/
theorem to_list_to_buffer {Ξ±} (l:list Ξ±) : buffer.to_list (list.to_buffer l) = l :=
begin
unfold list.to_buffer,
simp only [to_list_append_list],
simp only [to_list, to_array_mk_buffer, array.to_list_nil, list.nil_append],
end
/- Simplify functions calling through as_string -/
theorem to_char_buffer_as_string (l:list char)
: l.as_string.to_char_buffer = l.to_buffer := eq.refl l.to_buffer
@[simp]
theorem size_push_back {Ξ±} (b:buffer Ξ±) (c:Ξ±)
: (buffer.push_back b c).size = b.size + 1 :=
begin
cases b,
trivial,
end
@[simp]
theorem size_append_list {Ξ±} (b:buffer Ξ±) (l:list Ξ±)
: (buffer.append_list b l).size = l.length + b.size :=
begin
revert b,
induction l,
case list.nil {
intro b,
simp [buffer.append_list, nat.zero_add],
},
case list.cons : x r ind {
intro b,
simp only [buffer.append_list, ind, size_push_back, list.length_cons,
nat.add_succ, nat.add_zero, nat.succ_add],
},
end
/- Prove definition of reading from concatenation of two buffers. -/
theorem read_append_array {Ξ±} {n:β} (nz : n > 0) (x : buffer Ξ±) (b : array n Ξ±) (j:β) (j_lt : j < n)
(i : fin (append_array nz x b j j_lt).size)
: read (append_array nz x b j j_lt) i =
if h : i.val < x.size then
x.read β¨i.val, hβ©
else
let q : n + (i.val - x.size) - (j + 1) < n :=
begin
cases i with i i_lt,
let nz_lt : 0 < n := nz,
simp only [nat.sub_lt_to_add, nz_lt, or_true, and_true],
apply nat.add_lt_add_left,
have x_le := le_of_not_lt h,
simp [nat.sub_lt_to_add, x_le],
simp [size_append_array] at i_lt,
exact i_lt,
end in
array.read b β¨n + (i.val - x.size) - (j + 1), qβ© :=
begin
revert x,
induction j,
case nat.zero {
intros x i,
cases i with i i_lt,
cases x with m a,
dsimp [append_array, buffer.read, size],
simp [array.read_push_back_lt_iff],
cases (decide (i < m)),
case decidable.is_true : lt {
simp [lt],
},
case decidable.is_false : not_lt {
simp [not_lt],
dsimp [append_array, size] at i_lt,
have p : i β€ m := nat.le_of_lt_succ i_lt,
have q : i-m=0 := nat.sub_eq_zero_of_le p,
simp [q],
},
},
case nat.succ : j ind {
intros x i,
cases i with i i_outer_lt,
cases x with m a,
dsimp [append_array, size],
simp [ind],
dsimp [size],
cases nat.lt_trichotomy i m,
case or.inl : i_lt {
have i_lt_m_p_1 : i < m + 1 := nat.lt_succ_of_lt i_lt,
simp [i_lt, i_lt_m_p_1, buffer.read, array.read_push_back_lt_iff],
},
case or.inr : i_geq {
cases i_geq,
case or.inl : i_eq {
have i_lt_m_p_1 : i < m + 1, { simp [i_eq, nat.zero_lt_succ, nat.sub_self], },
simp [i_lt_m_p_1, i_eq, buffer.read, array.read_push_back_lt_iff],
apply (congr_arg (array.read b)),
apply fin.eq_of_veq,
simp [nat.succ_add, nat.add_succ, nat.sub_sub, nat.sub_self],
},
case or.inr : i_gt {
have not_i_lt_m : Β¬ (i < m) := not_lt_of_lt i_gt,
have not_i_lt_m_p_1 : Β¬ (i < m + 1), {
apply not_lt_of_le,
exact i_gt,
},
simp [not_i_lt_m, not_i_lt_m_p_1],
apply (congr_arg (array.read b)),
apply fin.eq_of_veq,
have not_i_m_zero : Β¬(i - m = 0), {
intro eq_zero,
have not_i_gt := not_lt_of_ge (nat.le_of_sub_eq_zero eq_zero),
exact (not_i_gt i_gt),
},
simp [fin.val, nat.succ_add, nat.add_succ, nat.sub_succ
, nat.add_pred, nat.pred_sub, not_i_m_zero],
},
},
},
end
/-- Proof needed for starting theorem about read of append. -/
theorem read_append.pr1 {Ξ±} (x y : buffer Ξ±) (i : fin ((x++y).size)) (h : Β¬(i.val < x.size ))
: i.val - buffer.size x < buffer.size y :=
begin
have q : buffer.size x β€ i.val := le_of_not_lt h,
simp [nat.sub_lt_left_iff_lt_add q],
exact trans_rel_left _ i.is_lt (size_append _ _),
end
/- Prove definition of reading from concatenation of two buffers. -/
theorem read_append {Ξ±} (x y : buffer Ξ±) (i : fin ((x++y).size))
: (x ++ y).read i =
if h : i.val < x.size then
x.read β¨i.val, hβ©
else
y.read β¨i.val - x.size, read_append.pr1 x y i hβ© :=
begin
cases y with n b,
cases n,
case nat.zero {
cases i with i i_lt,
dsimp [has_append.append, buffer.append] at i_lt,
-- Simplify left-hand side
dsimp [has_append.append, buffer.append],
-- Simplify right-hand side
simp [i_lt],
},
case nat.succ : n {
cases i with i i_lt,
dsimp [has_append.append, buffer.append],
simp [read_append_array ],
dsimp [fin.val],
cases decide (i < size x),
case decidable.is_true : i_lt { simp [i_lt], },
case decidable.is_false : not_i_lt {
simp [not_i_lt, buffer.read, nat.add_sub_cancel_left],
apply congr_arg (array.read b),
exact fin.eq_of_veq (eq.refl _),
},
},
end
/- Lexicographic reflexive ordering of buffers -/
protected
def le {Ξ±} [h:linear_order Ξ±] : buffer Ξ± β buffer Ξ± β Prop
| β¨m,aβ© β¨n,bβ© := array.lex_le a b
instance {Ξ±} [h:linear_order Ξ±] : has_le (buffer Ξ±) := β¨buffer.leβ©
instance decidable_le {Ξ±} [h:linear_order Ξ±] [r:decidable_rel (h.lt)]
: Ξ (x y : buffer Ξ±), decidable (x β€ y)
| β¨m,aβ© β¨n,bβ© :=
begin
simp [has_le.le, buffer.le],
apply_instance,
end
/- Lexicographic strict ordering of buffers -/
protected
def lt {Ξ±} [h:linear_order Ξ±] : buffer Ξ± β buffer Ξ± β Prop
| β¨m,aβ© β¨n,bβ© := array.lex_lt a b
instance {Ξ±} [h:linear_order Ξ±] : has_lt (buffer Ξ±) := β¨buffer.ltβ©
instance decidable_lt {Ξ±} [h:linear_order Ξ±] [r:decidable_rel (h.lt)]
: Ξ (x y : buffer Ξ±), decidable (x < y)
| β¨m,aβ© β¨n,bβ© :=
begin
simp [has_lt.lt, buffer.lt],
apply_instance,
end
/- Take a specific range of elements out of a buffer. -/
def slice {Ξ±} : Ξ (b : buffer Ξ±) (s e : β) (s_le_e : s β€ e), buffer Ξ±
| β¨n, aβ© s e s_le_e :=
if e_le_n : e β€ n then
β¨e - s, a.slice s e s_le_e e_le_nβ©
else if s_le_n : s β€ n then
β¨n - s, a.slice s n s_le_n (nat.le_refl _)β©
else
β¨0, array.nilβ©
/- Take a specific range of elements out of a buffer. -/
@[simp]
theorem size_slice {Ξ±} (b : buffer Ξ±) (s e : β) (s_le_e : s β€ e) :
size (slice b s e s_le_e) = min e b.size - s :=
begin
cases b with n a,
cases (decide (e β€ n)),
case decidable.is_true : e_le_n {
simp [slice, e_le_n, size, min_eq_left],
},
case decidable.is_false : not_e_le_n {
have n_le_e : n β€ e := le_of_not_ge not_e_le_n,
simp [slice, not_e_le_n, size, min_eq_right n_le_e],
cases (decide (s β€ n)),
case decidable.is_true : s_le_n {
simp [s_le_n, n_le_e, min_eq_right],
},
case decidable.is_false : not_s_le_n {
simp [not_s_le_n],
have n_le_s : n β€ s := le_of_not_ge not_s_le_n,
apply (eq.symm (nat.sub_eq_zero_of_le n_le_s)),
},
},
end
/-- Introduce a non-dependent function for reading. -/
def try_read {Ξ±} (b:buffer Ξ±) (i:β) : option Ξ± :=
if i_lt : i < b.size then
option.some (b.read β¨i, i_ltβ©)
else
option.none
/- Simplify some (read ...) -/
theorem some_read_is_try_read {Ξ±} (x:buffer Ξ±) (i:fin x.size)
: option.some (read x i) = try_read x i.val :=
begin
simp [try_read, i.is_lt],
end
/-- Lemma to force simplification of size, but only when buffer uses explicit constructor. -/
theorem size_ctor {Ξ±} (m:β) (a:array m Ξ±) : size (β¨m,aβ©) = m := by trivial
/- Lemma that uses the index to a slice to show it is bounded by size of buffer. -/
theorem slice_index_bound {Ξ±} {b:buffer Ξ±} {s e :β} {pr : s β€ e}
(i:fin (size (slice b s e pr)))
: s + i.val < b.size :=
begin
cases b with m a,
cases i with i i_lt,
simp [size_slice, nat.lt_sub_right_iff_add_lt] at i_lt,
exact calc s + i < min e m : i_lt
... β€ m : min_le_right _ _,
end
/- Simplify reading from slice -/
theorem read_slice {Ξ±} {b:buffer Ξ±} {s e :β} {s_le_e : s β€ e} (i:fin (size (slice b s e s_le_e)))
: read (slice b s e s_le_e) i = read b β¨s + i.val, slice_index_bound iβ© :=
begin
cases b with m a,
cases i with i i_lt,
apply option.some.inj,
simp [some_read_is_try_read],
cases (decide (e β€ m)),
case decidable.is_true : e_le_m {
simp [size_slice, size_ctor, min_eq_left e_le_m] at i_lt,
-- Reduce to array slice
simp [slice, e_le_m, buffer.read],
-- Simplify away try_read
have s_i_lt_m : s+i < m :=
calc s + i < e : nat.add_lt_of_lt_sub_left i_lt
... β€ m : e_le_m,
simp [try_read, size_ctor, i_lt, s_i_lt_m, buffer.read],
-- Simplify array theorem
simp [array.read_slice],
apply congr_arg _ (fin.eq_of_veq (eq.refl _)),
},
case decidable.is_false : not_e_le_m {
have m_le_e : m β€ e := le_of_not_ge not_e_le_m,
simp [size_slice, size_ctor, min_eq_right m_le_e] at i_lt,
simp [slice, not_e_le_m, buffer.read],
cases (decide (s β€ m)),
case decidable.is_true : s_le_m {
-- Reduce to array slice
simp [s_le_m],
-- Simplify away try_read
have s_i_lt_m : s+i < m := nat.add_lt_of_lt_sub_left i_lt,
simp [try_read, size_ctor, i_lt, s_i_lt_m, buffer.read],
-- Simplify array theorem
simp [array.read_slice],
apply congr_arg _ (fin.eq_of_veq (eq.refl _)),
},
case decidable.is_false : not_s_le_m {
-- Show i must be less than zero.
have m_le_s : m β€ s := le_of_not_ge not_s_le_m,
have m_sub_s_eq_0 := nat.sub_eq_zero_of_le m_le_s,
simp [m_sub_s_eq_0] at i_lt,
-- Use i_lt : i < 0 to discharge proof
exact (false.elim (nat.not_lt_zero _ i_lt)),
},
},
end
end buffer
namespace string
open string
/- Simplify functions calling through as_string -/
theorem to_char_buffer_as_string (l:list char)
: to_char_buffer (list.as_string l) = list.to_buffer l := eq.refl l.to_buffer
theorem to_char_buffer_buffer_to_string (b:char_buffer) : to_char_buffer (buffer.to_string b) = b :=
begin
apply buffer.ext,
simp [buffer.to_string],
simp [to_char_buffer_as_string],
simp [buffer.to_list_to_buffer],
simp [buffer.to_list],
end
end string
end galois
|
2c5c64d90d489a4e04b35f1e5345fcd56dd1d28f
|
80cc5bf14c8ea85ff340d1d747a127dcadeb966f
|
/src/analysis/complex/basic.lean
|
41c059ef38ddc574ee6d4c5a71d745a487ec76a7
|
[
"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
| 7,781
|
lean
|
/-
Copyright (c) SΓ©bastien GouΓ«zel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: SΓ©bastien GouΓ«zel
-/
import analysis.calculus.deriv
import analysis.normed_space.finite_dimension
/-!
# Normed space structure on `β`.
This file gathers basic facts on complex numbers of an analytic nature.
## Main results
This file registers `β` as a normed field, expresses basic properties of the norm, and gives
tools on the real vector space structure of `β`. Notably, in the namespace `complex`,
it defines functions:
* `continuous_linear_map.re`
* `continuous_linear_map.im`
* `continuous_linear_map.of_real`
They are bundled versions of the real part, the imaginary part, and the embedding of `β` in `β`,
as continuous `β`-linear maps.
`has_deriv_at_real_of_complex` expresses that, if a function on `β` is differentiable (over `β`),
then its restriction to `β` is differentiable over `β`, with derivative the real part of the
complex derivative.
-/
noncomputable theory
namespace complex
instance : normed_field β :=
{ norm := abs,
dist_eq := Ξ» _ _, rfl,
norm_mul' := abs_mul,
.. complex.field }
instance : nondiscrete_normed_field β :=
{ non_trivial := β¨2, by simp [norm]; norm_numβ© }
instance normed_algebra_over_reals : normed_algebra β β :=
{ norm_algebra_map_eq := abs_of_real,
..complex.algebra_over_reals }
@[simp] lemma norm_eq_abs (z : β) : β₯zβ₯ = abs z := rfl
@[simp] lemma norm_real (r : β) : β₯(r : β)β₯ = β₯rβ₯ := abs_of_real _
@[simp] lemma norm_rat (r : β) : β₯(r : β)β₯ = _root_.abs (r : β) :=
suffices β₯((r : β) : β)β₯ = _root_.abs r, by simpa,
by rw [norm_real, real.norm_eq_abs]
@[simp] lemma norm_nat (n : β) : β₯(n : β)β₯ = n := abs_of_nat _
@[simp] lemma norm_int {n : β€} : β₯(n : β)β₯ = _root_.abs n :=
suffices β₯((n : β) : β)β₯ = _root_.abs n, by simpa,
by rw [norm_real, real.norm_eq_abs]
lemma norm_int_of_nonneg {n : β€} (hn : 0 β€ n) : β₯(n : β)β₯ = n :=
by rw [norm_int, _root_.abs_of_nonneg]; exact int.cast_nonneg.2 hn
/-- Over the complex numbers, any finite-dimensional spaces is proper (and therefore complete).
We can register this as an instance, as it will not cause problems in instance resolution since
the properness of `β` is already known and there is no metavariable. -/
instance finite_dimensional.proper
(E : Type) [normed_group E] [normed_space β E] [finite_dimensional β E] : proper_space E :=
finite_dimensional.proper β E
attribute [instance, priority 900] complex.finite_dimensional.proper
/-- A complex normed vector space is also a real normed vector space. -/
@[priority 900]
instance normed_space.restrict_scalars_real (E : Type*) [normed_group E] [normed_space β E] :
normed_space β E := normed_space.restrict_scalars' β β E
/-- The space of continuous linear maps over `β`, from a real vector space to a complex vector
space, is a normed vector space over `β`. -/
instance continuous_linear_map.real_smul_complex (E : Type*) [normed_group E] [normed_space β E]
(F : Type*) [normed_group F] [normed_space β F] :
normed_space β (E βL[β] F) :=
continuous_linear_map.normed_space_extend_scalars
/-- Continuous linear map version of the real part function, from `β` to `β`. -/
def continuous_linear_map.re : β βL[β] β :=
linear_map.re.mk_continuous 1 $ Ξ»x, begin
change _root_.abs (x.re) β€ 1 * abs x,
rw one_mul,
exact abs_re_le_abs x
end
@[simp] lemma continuous_linear_map.re_coe :
(coe (continuous_linear_map.re) : β ββ[β] β) = linear_map.re := rfl
@[simp] lemma continuous_linear_map.re_apply (z : β) :
(continuous_linear_map.re : β β β) z = z.re := rfl
@[simp] lemma continuous_linear_map.re_norm :
β₯continuous_linear_map.reβ₯ = 1 :=
begin
apply le_antisymm (linear_map.mk_continuous_norm_le _ zero_le_one _),
calc 1 = β₯continuous_linear_map.re (1 : β)β₯ : by simp
... β€ β₯continuous_linear_map.reβ₯ : by { apply continuous_linear_map.unit_le_op_norm, simp }
end
/-- Continuous linear map version of the real part function, from `β` to `β`. -/
def continuous_linear_map.im : β βL[β] β :=
linear_map.im.mk_continuous 1 $ Ξ»x, begin
change _root_.abs (x.im) β€ 1 * abs x,
rw one_mul,
exact complex.abs_im_le_abs x
end
@[simp] lemma continuous_linear_map.im_coe :
(coe (continuous_linear_map.im) : β ββ[β] β) = linear_map.im := rfl
@[simp] lemma continuous_linear_map.im_apply (z : β) :
(continuous_linear_map.im : β β β) z = z.im := rfl
@[simp] lemma continuous_linear_map.im_norm :
β₯continuous_linear_map.imβ₯ = 1 :=
begin
apply le_antisymm (linear_map.mk_continuous_norm_le _ zero_le_one _),
calc 1 = β₯continuous_linear_map.im (I : β)β₯ : by simp
... β€ β₯continuous_linear_map.imβ₯ :
by { apply continuous_linear_map.unit_le_op_norm, rw β abs_I, exact le_refl _ }
end
/-- Continuous linear map version of the canonical embedding of `β` in `β`. -/
def continuous_linear_map.of_real : β βL[β] β :=
linear_map.of_real.mk_continuous 1 $ Ξ»x, by simp
@[simp] lemma continuous_linear_map.of_real_coe :
(coe (continuous_linear_map.of_real) : β ββ[β] β) = linear_map.of_real := rfl
@[simp] lemma continuous_linear_map.of_real_apply (x : β) :
(continuous_linear_map.of_real : β β β) x = x := rfl
@[simp] lemma continuous_linear_map.of_real_norm :
β₯continuous_linear_map.of_realβ₯ = 1 :=
begin
apply le_antisymm (linear_map.mk_continuous_norm_le _ zero_le_one _),
calc 1 = β₯continuous_linear_map.of_real (1 : β)β₯ : by simp
... β€ β₯continuous_linear_map.of_realβ₯ :
by { apply continuous_linear_map.unit_le_op_norm, simp }
end
lemma continuous_linear_map.of_real_isometry :
isometry continuous_linear_map.of_real :=
continuous_linear_map.isometry_iff_norm_image_eq_norm.2 (Ξ»x, by simp)
end complex
section real_deriv_of_complex
/-! ### Differentiability of the restriction to `β` of complex functions -/
open complex
variables {e : β β β} {e' : β} {z : β}
/--
A preliminary lemma for `has_deriv_at_real_of_complex`,
which we only separate out to keep the maximum compile time per declaration low.
-/
lemma has_deriv_at_real_of_complex_aux (h : has_deriv_at e e' z) :
has_deriv_at (βcontinuous_linear_map.re β Ξ» {z : β}, e (continuous_linear_map.of_real z))
(((continuous_linear_map.re.comp
((continuous_linear_map.smul_right (1 : β βL[β] β) e').restrict_scalars β)).comp
continuous_linear_map.of_real) (1 : β))
z :=
begin
have A : has_fderiv_at continuous_linear_map.of_real continuous_linear_map.of_real z :=
continuous_linear_map.of_real.has_fderiv_at,
have B : has_fderiv_at e ((continuous_linear_map.smul_right 1 e' : β βL[β] β).restrict_scalars β)
(continuous_linear_map.of_real z) :=
(has_deriv_at_iff_has_fderiv_at.1 h).restrict_scalars β,
have C : has_fderiv_at continuous_linear_map.re continuous_linear_map.re
(e (continuous_linear_map.of_real z)) := continuous_linear_map.re.has_fderiv_at,
exact has_fderiv_at_iff_has_deriv_at.1 (C.comp z (B.comp z A)),
end
/-- If a complex function is differentiable at a real point, then the induced real function is also
differentiable at this point, with a derivative equal to the real part of the complex derivative. -/
theorem has_deriv_at_real_of_complex (h : has_deriv_at e e' z) :
has_deriv_at (Ξ»x:β, (e x).re) e'.re z :=
begin
rw (show (Ξ»x:β, (e x).re) = (continuous_linear_map.re : β β β) β e β (continuous_linear_map.of_real : β β β),
by { ext x, refl }),
simpa using has_deriv_at_real_of_complex_aux h,
end
end real_deriv_of_complex
|
3090a57e7233041737554d8214ed3ae83a87d56a
|
7a76361040c55ae1eba5856c1a637593117a6556
|
/src/lectures/love00_preface_demo.lean
|
ad912da09bee71e3c729623cdea20ff2335c1850
|
[] |
no_license
|
rgreenblatt/fpv2021
|
c2cbe7b664b648cef7d240a654d6bdf97a559272
|
c65d72e48c8fa827d2040ed6ea86c2be62db36fa
|
refs/heads/main
| 1,692,245,693,819
| 1,633,364,621,000
| 1,633,364,621,000
| 407,231,487
| 0
| 0
| null | 1,631,808,608,000
| 1,631,808,608,000
| null |
UTF-8
|
Lean
| false
| false
| 3,273
|
lean
|
import data.nat.prime
import tactic.linarith
/-! # LoVe Preface
## Proof Assistants
Proof assistants (also called interactive theorem provers)
* check and help develop formal proofs;
* can be used to prove big theorems, not only logic puzzles;
* can be tedious to use;
* are highly addictive (think video games).
A selection of proof assistants, classified by logical foundations:
* set theory: Isabelle/ZF, Metamath, Mizar;
* simple type theory: HOL4, HOL Light, Isabelle/HOL;
* **dependent type theory**: Agda, Coq, **Lean**, Matita, PVS.
## Success Stories
Mathematics:
* the four-color theorem (in Coq);
* the odd-order theorem (in Coq);
* the Kepler conjecture (in HOL Light and Isabelle/HOL).
Computer science:
* hardware
* operating systems
* programming language theory
* compilers
* security
## Lean
Lean is a proof assistant developed primarily by Leonardo de Moura (Microsoft
Research) since 2012.
Its mathematical library, `mathlib`, is developed by a user community.
We use community version 3.20.0. We use its basic libraries, `mathlib`, and
`LoVelib`. Lean is a research project.
Strengths:
* highly expressive logic based on a dependent type theory called the
**calculus of inductive constructions**;
* extended with classical axioms and quotient types;
* metaprogramming framework;
* modern user interface;
* documentation;
* open source;
* wonderful user community.
## This Course
### Web Site
https://cs.brown.edu/courses/cs1951x/
### Repository (Demos, Exercises, Homework)
https://github.com/BrownCS1951x/fpv2021
The file you are currently looking at is a demo.
For each chapter of the Hitchhiker's Guide, there will be approximately
one demo, one exercise sheet, and one homework.
* Demos will be covered in class. These are "lecture notes."
We'll post skeletons of the demos before class, and completed demos after class.
* Exercises are ungraded practice problems for you to use to learn.
Sometimes we'll cover exercise problems in class. Occasionally we may run
class like a lab, giving you time to work on exercise problems with us around.
* Homeworks are for you to do on your own, and submit via Gradescope.
### The Hitchhiker's Guide to Logical Verification
https://cs.brown.edu/courses/cs1951x/static_files/main.pdf
The lecture notes consist of a preface and 13 chapters. They cover the same
material as the corresponding lectures but with more details. Sometimes there
will not be enough time to cover everything in class, so reading the lecture
notes will be necessary.
Download this version, not others that you might find online!
## Our Goal
We want you to
* master fundamental theory and techniques in interactive theorem proving;
* familiarize yourselves with some application areas;
* develop some practical skills you can apply on a larger project (as a hobby,
for an MSc or PhD, or in industry);
* feel ready to move to another proof assistant and apply what you have learned;
* understand the domain well enough to start reading scientific papers.
This course is neither a pure logical foundations course nor a Lean tutorial.
Lean is our vehicle, not an end in itself.
-/
open nat
open_locale nat
theorem infinitude_of_primes : β N, β p β₯ N, prime p :=
sorry
|
6972065e8678d485cf8a01cb9d2113d9e7006215
|
c3f2fcd060adfa2ca29f924839d2d925e8f2c685
|
/library/data/sigma.lean
|
2f1b811266c6d789aa5ab5dd0eba84ebcb758001
|
[
"Apache-2.0"
] |
permissive
|
respu/lean
|
6582d19a2f2838a28ecd2b3c6f81c32d07b5341d
|
8c76419c60b63d0d9f7bc04ebb0b99812d0ec654
|
refs/heads/master
| 1,610,882,451,231
| 1,427,747,084,000
| 1,427,747,429,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 3,481
|
lean
|
/-
Copyright (c) 2014 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Module: data.sigma
Author: Leonardo de Moura, Jeremy Avigad, Floris van Doorn
Sigma types, aka dependent sum.
-/
import logic.cast
open inhabited eq.ops sigma.ops
namespace sigma
universe variables u v
variables {A A' : Type.{u}} {B : A β Type.{v}} {B' : A' β Type.{v}}
definition unpack {C : (Ξ£a, B a) β Type} {u : Ξ£a, B a} (H : C β¨u.1 , u.2β©) : C u :=
destruct u (Ξ»x y H, H) H
theorem dpair_eq {aβ aβ : A} {bβ : B aβ} {bβ : B aβ} (Hβ : aβ = aβ) (Hβ : eq.rec_on Hβ bβ = bβ) :
β¨aβ, bββ© = β¨aβ, bββ© :=
dcongr_arg2 mk Hβ Hβ
theorem dpair_heq {a : A} {a' : A'} {b : B a} {b' : B' a'}
(HB : B == B') (Ha : a == a') (Hb : b == b') : β¨a, bβ© == β¨a', b'β© :=
hcongr_arg4 @mk (heq.type_eq Ha) HB Ha Hb
protected theorem equal {pβ pβ : Ξ£a : A, B a} :
β(Hβ : pβ.1 = pβ.1) (Hβ : eq.rec_on Hβ pβ.2 = pβ.2), pβ = pβ :=
destruct pβ (take aβ bβ, destruct pβ (take aβ bβ Hβ Hβ, dpair_eq Hβ Hβ))
protected theorem hequal {p : Ξ£a : A, B a} {p' : Ξ£a' : A', B' a'} (HB : B == B') :
β(Hβ : p.1 == p'.1) (Hβ : p.2 == p'.2), p == p' :=
destruct p (take aβ bβ, destruct p' (take aβ bβ Hβ Hβ, dpair_heq HB Hβ Hβ))
protected definition is_inhabited [instance] [Hβ : inhabited A] [Hβ : inhabited (B (default A))] :
inhabited (sigma B) :=
inhabited.destruct Hβ (Ξ»a, inhabited.destruct Hβ (Ξ»b, inhabited.mk β¨default A, bβ©))
theorem eq_rec_dpair_commute {C : Ξ a, B a β Type} {a a' : A} (H : a = a') (b : B a) (c : C a b) :
eq.rec_on H β¨b, cβ© = β¨eq.rec_on H b, eq.rec_on (dcongr_arg2 C H rfl) cβ© :=
eq.drec_on H (dpair_eq rfl (!eq.rec_on_idβ»ΒΉ))
variables {C : Ξ a, B a β Type} {D : Ξ a b, C a b β Type}
definition dtrip (a : A) (b : B a) (c : C a b) := β¨a, b, cβ©
definition dquad (a : A) (b : B a) (c : C a b) (d : D a b c) := β¨a, b, c, dβ©
definition pr1' [reducible] (x : Ξ£ a, B a) := x.1
definition pr2' [reducible] (x : Ξ£ a b, C a b) := x.2.1
definition pr3 [reducible] (x : Ξ£ a b, C a b) := x.2.2
definition pr3' [reducible] (x : Ξ£ a b c, D a b c) := x.2.2.1
definition pr4 [reducible] (x : Ξ£ a b c, D a b c) := x.2.2.2
theorem dtrip_eq {aβ aβ : A} {bβ : B aβ} {bβ : B aβ} {cβ : C aβ bβ} {cβ : C aβ bβ}
(Hβ : aβ = aβ) (Hβ : eq.rec_on Hβ bβ = bβ) (Hβ : cast (dcongr_arg2 C Hβ Hβ) cβ = cβ) :
β¨aβ, bβ, cββ© = β¨aβ, bβ, cββ© :=
dcongr_arg3 dtrip Hβ Hβ Hβ
theorem ndtrip_eq {A B : Type} {C : A β B β Type} {aβ aβ : A} {bβ bβ : B}
{cβ : C aβ bβ} {cβ : C aβ bβ} (Hβ : aβ = aβ) (Hβ : bβ = bβ)
(Hβ : cast (congr_arg2 C Hβ Hβ) cβ = cβ) : β¨aβ, bβ, cββ© = β¨aβ, bβ, cββ© :=
hdcongr_arg3 dtrip Hβ (heq.of_eq Hβ) Hβ
theorem ndtrip_equal {A B : Type} {C : A β B β Type} {pβ pβ : Ξ£a b, C a b} :
β(Hβ : pr1 pβ = pr1 pβ) (Hβ : pr2' pβ = pr2' pβ)
(Hβ : eq.rec_on (congr_arg2 C Hβ Hβ) (pr3 pβ) = pr3 pβ), pβ = pβ :=
destruct pβ (take aβ qβ, destruct qβ (take bβ cβ, destruct pβ (take aβ qβ, destruct qβ
(take bβ cβ Hβ Hβ Hβ, ndtrip_eq Hβ Hβ Hβ))))
end sigma
|
52f233acc29075cace1beca7eeda1b73ca2b1eb7
|
cf39355caa609c0f33405126beee2739aa3cb77e
|
/tests/lean/run/io_fs_2.lean
|
4a0cdc9be3612e34e77184788c07219c11008b8d
|
[
"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
| 2,115
|
lean
|
import system.io
open io io.fs
def TEST_DIR : string := "_test_dir"
def TEST_DIR1 : string := "_test_dir1"
def TEST_DIR2 : string := "_test_dir2"
def TEST_FILE_1 : string := "_test_file1"
def TEST_FILE_2 : string := "_test_file2"
meta def ycheck (s : string) (t : io bool) : io unit :=
do r β t,
if r then return ()
else io.fail sformat!"ycheck: {s}"
meta def ncheck (s : string) (t : io bool) : io unit :=
do r β t,
if Β¬r then return ()
else io.fail sformat!"ncheck: {s}"
meta def go_dir : io unit :=
do rmdir TEST_DIR,
ncheck "dir exists now" $ dir_exists TEST_DIR,
ycheck "mkdir" $ mkdir TEST_DIR,
ycheck "dir exists now" $ dir_exists TEST_DIR,
ncheck "file exists now" $ file_exists TEST_DIR,
ycheck "rmdir" $ rmdir TEST_DIR,
ncheck "dir exists now'" $ dir_exists TEST_DIR,
return ()
meta def go_dir_recursive : io unit :=
do let combined := TEST_DIR1 ++ "/" ++ TEST_DIR2,
rmdir $ combined,
rmdir TEST_DIR1,
ycheck "mkdir rec" $ mkdir combined tt,
ycheck "dir exists now1" $ dir_exists TEST_DIR1,
ycheck "dir exists now2" $ dir_exists combined,
ycheck "rmdir2" $ rmdir $ combined,
ycheck "dir exists now1'" $ dir_exists TEST_DIR1,
ncheck "dir exists now2'" $ dir_exists combined,
ycheck "rmdir" $ rmdir $ TEST_DIR1,
ncheck "dir exists now1''" $ dir_exists TEST_DIR1,
ncheck "dir exists now2''" $ dir_exists combined,
return ()
meta def go_file : io unit :=
do remove TEST_FILE_1 <|> return (),
remove TEST_FILE_2 <|> return (),
ncheck "file1 exists now" $ file_exists TEST_FILE_1,
mk_file_handle TEST_FILE_1 io.mode.write >>= close,
ycheck "file1 exists now'" $ file_exists TEST_FILE_1,
ncheck "dir exists now" $ dir_exists TEST_FILE_1,
rename TEST_FILE_1 TEST_FILE_2,
ncheck "file1 exists now''" $ file_exists TEST_FILE_1,
ycheck "file2 exists now" $ file_exists TEST_FILE_2,
remove TEST_FILE_2,
ncheck "file2 exists now" $ file_exists TEST_FILE_2,
return ()
run_cmd (tactic.unsafe_run_io go_dir)
run_cmd (tactic.unsafe_run_io go_dir_recursive)
run_cmd (tactic.unsafe_run_io go_file)
|
05287f9b3b3f8e1eeef84a6f1f6bd707cfbb3653
|
ae1e94c332e17c7dc7051ce976d5a9eebe7ab8a5
|
/tests/lean/run/anonymousCtor.lean
|
d9f8427c86776b243e50157e8db73858efcefb5b
|
[
"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
| 95
|
lean
|
#lang lean4
inductive S
| mk : List S β String β S
def f (s : String) : S :=
β¨[], sβ©
|
59caef5f9f1ba5771b289fa6587ea03560b490ab
|
efd582de089592b7c646b48c90e85d8db560e581
|
/src/matrix_cookbook/2_derivatives.lean
|
50c71b5eeff218318ddc074df9279cb8faa3141a
|
[
"MIT"
] |
permissive
|
Daniel-Packer/lean-matrix-cookbook
|
3e44ce059a16e5334d6c95f8e9b87acbdeb838e9
|
d7d5079e2513c2800f76915f1f30953c9676673c
|
refs/heads/master
| 1,693,182,725,966
| 1,636,125,196,000
| 1,636,125,196,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 6,418
|
lean
|
import linear_algebra.matrix.nonsingular_inverse
import linear_algebra.matrix.trace
import analysis.calculus.deriv
import data.matrix.kronecker
import data.matrix.hadamard
import analysis.special_functions.exp_log
/-! # Derivatives -/
variables {ΞΉ : Type*} {R : Type*} {m n p : Type*}
variables [fintype m] [fintype n] [fintype p]
variables [decidable_eq m] [decidable_eq n] [decidable_eq p]
namespace matrix_cookbook
variables [nondiscrete_normed_field R]
attribute [instance] matrix.normed_group matrix.normed_space
local notation `Tr` := matrix.trace _ R _
local notation `Tr'` := matrix.trace _ β _
open_locale matrix kronecker
open matrix
/-! TODO: is this what is actually meant by `β(XY) = (βX)Y + X(βY)`? -/
lemma eq_33 (A : matrix m n R) : deriv (Ξ» x : R, A) = 0 := deriv_const' _
lemma eq_34 (c : R) (X : R β matrix m n R) (hX : differentiable R X) :
deriv (c β’ X) = c β’ deriv X := funext $ Ξ» _, deriv_const_smul c (hX _)
lemma eq_35 (X Y : R β matrix m n R) (hX : differentiable R X) (hY : differentiable R Y) :
deriv (X + Y) = deriv X + deriv Y := funext $ Ξ» _, deriv_add (hX _) (hY _)
lemma eq_36 (X : R β matrix m m R) (hX : differentiable R X) :
deriv (Ξ» a, Tr (X a)) = Ξ» a, Tr (deriv X a) := sorry
lemma eq_37 (X : R β matrix m n R) (Y : R β matrix n p R) (hX : differentiable R X) (hY : differentiable R Y) :
deriv (Ξ» a, (X a) β¬ (Y a)) = Ξ» a, deriv X a β¬ Y a + X a β¬ deriv Y a := sorry
lemma eq_38 (X Y : R β matrix n p R) (hX : differentiable R X) (hY : differentiable R Y) :
deriv (Ξ» a, (X a) β (Y a)) = Ξ» a, deriv X a β Y a + X a β deriv Y a := sorry
lemma eq_39 (X Y : R β matrix n p R) (hX : differentiable R X) (hY : differentiable R Y) :
deriv (Ξ» a, (X a) ββ (Y a)) = Ξ» a, deriv X a ββ Y a + X a ββ deriv Y a := sorry
lemma eq_40 (X : R β matrix n n R) (hX : differentiable R X) :
deriv (Ξ» a, (X a)β»ΒΉ) = Ξ» a, -(X a)β»ΒΉ * deriv X a * (X a)β»ΒΉ := sorry
lemma eq_41 (X : R β matrix n n R) (hX : differentiable R X) :
deriv (Ξ» a, det (X a)) = Ξ» a, Tr (adjugate (X a) * deriv X a) := sorry
lemma eq_42 (X : R β matrix n n R) (hX : differentiable R X) :
deriv (Ξ» a, det (X a)) = Ξ» a, det (X a) β’ Tr ((X a)β»ΒΉ * deriv X a) := sorry
lemma eq_43 (X : β β matrix n n β) (hX : differentiable β X) :
deriv (Ξ» a, real.log (det (X a))) = Ξ» a, Tr' ((X a)β»ΒΉ * deriv X a) := sorry
lemma eq_44 (X : R β matrix m n R) (hX : differentiable R X) :
deriv (Ξ» a, (X a)α΅) = Ξ» a, (deriv X a)α΅ := sorry
lemma eq_45 [star_ring R] (X : R β matrix m n R) (hX : differentiable R X) :
deriv (Ξ» a, (X a)α΄΄) = Ξ» a, (deriv X a)α΄΄ := sorry
/-! ## Derivatives of a Determinant -/
/-! ### General form -/
lemma eq_46 (X : R β matrix n n R) (hX : differentiable R X) :
deriv (Ξ» a, det (X a)) = Ξ» a, det (X a) β’ Tr ((X a)β»ΒΉ * deriv X a) := eq_42 X hX -- this suggests we might have 42 stated strangely
-- lemma eq_47 : sorry := sorry
-- lemma eq_48 : sorry := sorry
/-! ### Linear forms -/
-- lemma eq_49 : sorry := sorry
-- lemma eq_50 : sorry := sorry
-- lemma eq_51 : sorry := sorry
/-! ### Square forms -/
-- lemma eq_52 : sorry := sorry
-- lemma eq_53 : sorry := sorry
-- lemma eq_54 : sorry := sorry
/-! ### Other nonlinear forms -/
-- lemma eq_55 : sorry := sorry
-- lemma eq_56 : sorry := sorry
-- lemma eq_57 : sorry := sorry
-- lemma eq_58 : sorry := sorry
/-! ## Derivatives of an Inverse -/
-- lemma eq_59 : sorry := sorry
-- lemma eq_60 : sorry := sorry
-- lemma eq_61 : sorry := sorry
-- lemma eq_62 : sorry := sorry
-- lemma eq_63 : sorry := sorry
-- lemma eq_64 : sorry := sorry
/-! ## Derivatives of Eigenvalues -/
-- lemma eq_65 : sorry := sorry
-- lemma eq_66 : sorry := sorry
-- lemma eq_67 : sorry := sorry
-- lemma eq_68 : sorry := sorry
/-! ## Derivatives of Matrices, Vectors, and Scalar forms -/
/-! ### First order -/
-- lemma eq_69 : sorry := sorry
-- lemma eq_70 : sorry := sorry
-- lemma eq_71 : sorry := sorry
-- lemma eq_72 : sorry := sorry
-- lemma eq_73 : sorry := sorry
-- lemma eq_74 : sorry := sorry
-- lemma eq_75 : sorry := sorry
/-! ### Second order -/
-- lemma eq_76 : sorry := sorry
-- lemma eq_77 : sorry := sorry
-- lemma eq_78 : sorry := sorry
-- lemma eq_79 : sorry := sorry
-- lemma eq_80 : sorry := sorry
-- lemma eq_81 : sorry := sorry
-- lemma eq_82 : sorry := sorry
-- lemma eq_83 : sorry := sorry
-- lemma eq_84 : sorry := sorry
-- lemma eq_85 : sorry := sorry
-- lemma eq_86 : sorry := sorry
-- lemma eq_87 : sorry := sorry
-- lemma eq_88 : sorry := sorry
-- lemma eq_89 : sorry := sorry
/-! ### Higher order and non-linear -/
-- lemma eq_90 : sorry := sorry
-- lemma eq_91 : sorry := sorry
-- lemma eq_92 : sorry := sorry
-- lemma eq_93 : sorry := sorry
-- lemma eq_94 : sorry := sorry
-- lemma eq_95 : sorry := sorry
/-! ### Gradient and hessian -/
-- lemma eq_96 : sorry := sorry
-- lemma eq_97 : sorry := sorry
-- lemma eq_98 : sorry := sorry
/-! ## Derivatives of Traces -/
/-! ### First order -/
-- lemma eq_99 : sorry := sorry
-- lemma eq_100 : sorry := sorry
-- lemma eq_101 : sorry := sorry
-- lemma eq_102 : sorry := sorry
-- lemma eq_103 : sorry := sorry
-- lemma eq_104 : sorry := sorry
-- lemma eq_105 : sorry := sorry
/-! ### Second order -/
-- eqs 106-120
/-! ### Higher order -/
-- lemma eq_121 : sorry := sorry
-- lemma eq_122 : sorry := sorry
-- lemma eq_123 : sorry := sorry
/-! ### Other -/
-- lemma eq_124 : sorry := sorry
-- lemma eq_125 : sorry := sorry
-- lemma eq_126 : sorry := sorry
-- lemma eq_127 : sorry := sorry
-- lemma eq_128 : sorry := sorry
/-! ## Derivatives of Vector norms -/
/-! ### Two-norm -/
-- lemma eq_129 : sorry := sorry
-- lemma eq_130 : sorry := sorry
-- lemma eq_131 : sorry := sorry
/-! ## Derivatives of matrix norms -/
/-! ### Frobenius norm -/
-- lemma eq_132 : sorry := sorry
/-! ## Derivatives of structured matrices -/
-- lemma eq_133 : sorry := sorry
-- lemma eq_134 : sorry := sorry
/-! ### The Chain Rule -/
-- lemma eq_135 : sorry := sorry
-- lemma eq_136 : sorry := sorry
-- lemma eq_147 : sorry := sorry
/-! ### Symmetric -/
-- lemma eq_138 : sorry := sorry
-- lemma eq_139 : sorry := sorry
-- lemma eq_140 : sorry := sorry
-- lemma eq_141 : sorry := sorry
/-! ### Diagonal -/
-- lemma eq_142 : sorry := sorry
/-! ### Toeplitz -/
-- lemma eq_143 : sorry := sorry
-- lemma eq_144 : sorry := sorry
end matrix_cookbook
|
93af760e01e59fbcbe8228f339c5ccd54cb084a5
|
94e33a31faa76775069b071adea97e86e218a8ee
|
/src/group_theory/specific_groups/cyclic.lean
|
3499df0fee3b921ff0698655436b649c25ab70d1
|
[
"Apache-2.0"
] |
permissive
|
urkud/mathlib
|
eab80095e1b9f1513bfb7f25b4fa82fa4fd02989
|
6379d39e6b5b279df9715f8011369a301b634e41
|
refs/heads/master
| 1,658,425,342,662
| 1,658,078,703,000
| 1,658,078,703,000
| 186,910,338
| 0
| 0
|
Apache-2.0
| 1,568,512,083,000
| 1,557,958,709,000
|
Lean
|
UTF-8
|
Lean
| false
| false
| 22,218
|
lean
|
/-
Copyright (c) 2018 Johannes HΓΆlzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes HΓΆlzl
-/
import algebra.big_operators.order
import data.nat.totient
import group_theory.order_of_element
import tactic.group
import group_theory.exponent
/-!
# Cyclic groups
A group `G` is called cyclic if there exists an element `g : G` such that every element of `G` is of
the form `g ^ n` for some `n : β`. This file only deals with the predicate on a group to be cyclic.
For the concrete cyclic group of order `n`, see `data.zmod.basic`.
## Main definitions
* `is_cyclic` is a predicate on a group stating that the group is cyclic.
## Main statements
* `is_cyclic_of_prime_card` proves that a finite group of prime order is cyclic.
* `is_simple_group_of_prime_card`, `is_simple_group.is_cyclic`,
and `is_simple_group.prime_card` classify finite simple abelian groups.
* `is_cyclic.exponent_eq_card`: For a finite cyclic group `G`, the exponent is equal to
the group's cardinality.
* `is_cyclic.exponent_eq_zero_of_infinite`: Infinite cyclic groups have exponent zero.
* `is_cyclic.iff_exponent_eq_card`: A finite commutative group is cyclic iff its exponent
is equal to its cardinality.
## Tags
cyclic group
-/
universe u
variables {Ξ± : Type u} {a : Ξ±}
section cyclic
open_locale big_operators
local attribute [instance] set_fintype
open subgroup
/-- A group is called *cyclic* if it is generated by a single element. -/
class is_add_cyclic (Ξ± : Type u) [add_group Ξ±] : Prop :=
(exists_generator [] : β g : Ξ±, β x, x β add_subgroup.zmultiples g)
/-- A group is called *cyclic* if it is generated by a single element. -/
@[to_additive is_add_cyclic] class is_cyclic (Ξ± : Type u) [group Ξ±] : Prop :=
(exists_generator [] : β g : Ξ±, β x, x β zpowers g)
@[priority 100, to_additive is_add_cyclic_of_subsingleton]
instance is_cyclic_of_subsingleton [group Ξ±] [subsingleton Ξ±] : is_cyclic Ξ± :=
β¨β¨1, Ξ» x, by { rw subsingleton.elim x 1, exact mem_zpowers 1 }β©β©
/-- A cyclic group is always commutative. This is not an `instance` because often we have a better
proof of `comm_group`. -/
@[to_additive "A cyclic group is always commutative. This is not an `instance` because often we have
a better proof of `add_comm_group`."]
def is_cyclic.comm_group [hg : group Ξ±] [is_cyclic Ξ±] : comm_group Ξ± :=
{ mul_comm := Ξ» x y,
let β¨g, hgβ© := is_cyclic.exists_generator Ξ±,
β¨n, hnβ© := hg x,
β¨m, hmβ© := hg y in
hm βΈ hn βΈ zpow_mul_comm _ _ _,
..hg }
variables [group Ξ±]
@[to_additive monoid_add_hom.map_add_cyclic]
lemma monoid_hom.map_cyclic {G : Type*} [group G] [h : is_cyclic G] (Ο : G β* G) :
β m : β€, β g : G, Ο g = g ^ m :=
begin
obtain β¨h, hGβ© := is_cyclic.exists_generator G,
obtain β¨m, hmβ© := hG (Ο h),
refine β¨m, Ξ» g, _β©,
obtain β¨n, rflβ© := hG g,
rw [monoid_hom.map_zpow, βhm, βzpow_mul, βzpow_mul'],
end
@[to_additive is_add_cyclic_of_order_of_eq_card]
lemma is_cyclic_of_order_of_eq_card [fintype Ξ±] (x : Ξ±)
(hx : order_of x = fintype.card Ξ±) : is_cyclic Ξ± :=
begin
classical,
use x,
simp_rw [β set_like.mem_coe, β set.eq_univ_iff_forall],
rw [βfintype.card_congr (equiv.set.univ Ξ±), order_eq_card_zpowers] at hx,
exact set.eq_of_subset_of_card_le (set.subset_univ _) (ge_of_eq hx),
end
/-- A finite group of prime order is cyclic. -/
@[to_additive is_add_cyclic_of_prime_card]
lemma is_cyclic_of_prime_card {Ξ± : Type u} [group Ξ±] [fintype Ξ±] {p : β} [hp : fact p.prime]
(h : fintype.card Ξ± = p) : is_cyclic Ξ± :=
β¨begin
obtain β¨g, hgβ© : β g : Ξ±, g β 1 := fintype.exists_ne_of_one_lt_card (h.symm βΈ hp.1.one_lt) 1,
classical, -- for fintype (subgroup.zpowers g)
have : fintype.card (subgroup.zpowers g) β£ p,
{ rw βh,
apply card_subgroup_dvd_card },
rw nat.dvd_prime hp.1 at this,
cases this,
{ rw fintype.card_eq_one_iff at this,
cases this with t ht,
suffices : g = 1,
{ contradiction },
have hgt := ht β¨g, by { change g β subgroup.zpowers g, exact subgroup.mem_zpowers g }β©,
rw [βht 1] at hgt,
change (β¨_, _β© : subgroup.zpowers g) = β¨_, _β© at hgt,
simpa using hgt },
{ use g,
intro x,
rw [βh] at this,
rw subgroup.eq_top_of_card_eq _ this,
exact subgroup.mem_top _ }
endβ©
@[to_additive add_order_of_eq_card_of_forall_mem_zmultiples]
lemma order_of_eq_card_of_forall_mem_zpowers [fintype Ξ±]
{g : Ξ±} (hx : β x, x β zpowers g) : order_of g = fintype.card Ξ± :=
begin
classical,
rw order_eq_card_zpowers,
apply fintype.card_of_finset',
simpa using hx
end
@[to_additive infinite.add_order_of_eq_zero_of_forall_mem_zmultiples]
lemma infinite.order_of_eq_zero_of_forall_mem_zpowers [infinite Ξ±] {g : Ξ±}
(h : β x, x β zpowers g) : order_of g = 0 :=
begin
classical,
rw order_of_eq_zero_iff',
refine Ξ» n hn hgn, _,
have ho := order_of_pos' ((is_of_fin_order_iff_pow_eq_one g).mpr β¨n, hn, hgnβ©),
obtain β¨x, hxβ© := infinite.exists_not_mem_finset
(finset.image (pow g) $ finset.range $ order_of g),
apply hx,
rw [βmem_powers_iff_mem_range_order_of' g x ho, submonoid.mem_powers_iff],
obtain β¨k, hkβ© := h x,
obtain β¨k, rfl | rflβ© := k.eq_coe_or_neg,
{ exact β¨k, by exact_mod_cast hkβ© },
let t : β€ := -k % (order_of g),
rw zpow_eq_mod_order_of at hk,
have : 0 β€ t := int.mod_nonneg (-k) (by exact_mod_cast ho.ne'),
refine β¨t.to_nat, _β©,
rwa [βzpow_coe_nat, int.to_nat_of_nonneg this]
end
@[to_additive bot.is_add_cyclic]
instance bot.is_cyclic {Ξ± : Type u} [group Ξ±] : is_cyclic (β₯ : subgroup Ξ±) :=
β¨β¨1, Ξ» x, β¨0, subtype.eq $ (zpow_zero (1 : Ξ±)).trans $ eq.symm (subgroup.mem_bot.1 x.2)β©β©β©
@[to_additive add_subgroup.is_add_cyclic]
instance subgroup.is_cyclic {Ξ± : Type u} [group Ξ±] [is_cyclic Ξ±] (H : subgroup Ξ±) : is_cyclic H :=
by haveI := classical.prop_decidable; exact
let β¨g, hgβ© := is_cyclic.exists_generator Ξ± in
if hx : β (x : Ξ±), x β H β§ x β (1 : Ξ±) then
let β¨x, hxβ, hxββ© := hx in
let β¨k, hkβ© := hg x in
have hex : β n : β, 0 < n β§ g ^ n β H,
from β¨k.nat_abs, nat.pos_of_ne_zero
(Ξ» h, hxβ $ by rw [β hk, int.eq_zero_of_nat_abs_eq_zero h, zpow_zero]),
match k, hk with
| (k : β), hk := by rw [int.nat_abs_of_nat, β zpow_coe_nat, hk]; exact hxβ
| -[1+ k], hk := by rw [int.nat_abs_of_neg_succ_of_nat,
β subgroup.inv_mem_iff H]; simp * at *
endβ©,
β¨β¨β¨g ^ nat.find hex, (nat.find_spec hex).2β©,
Ξ» β¨x, hxβ©, let β¨k, hkβ© := hg x in
have hkβ : g ^ ((nat.find hex : β€) * (k / nat.find hex)) β zpowers (g ^ nat.find hex),
from β¨k / nat.find hex, by rw [β zpow_coe_nat, zpow_mul]β©,
have hkβ : g ^ ((nat.find hex : β€) * (k / nat.find hex)) β H,
by { rw zpow_mul, apply H.zpow_mem, exact_mod_cast (nat.find_spec hex).2 },
have hkβ : g ^ (k % nat.find hex) β H,
from (subgroup.mul_mem_cancel_right H hkβ).1 $
by rw [β zpow_add, int.mod_add_div, hk]; exact hx,
have hkβ : k % nat.find hex = (k % nat.find hex).nat_abs,
by rw int.nat_abs_of_nonneg (int.mod_nonneg _
(int.coe_nat_ne_zero_iff_pos.2 (nat.find_spec hex).1)),
have hkβ
: g ^ (k % nat.find hex ).nat_abs β H,
by rwa [β zpow_coe_nat, β hkβ],
have hkβ : (k % (nat.find hex : β€)).nat_abs = 0,
from by_contradiction (Ξ» h,
nat.find_min hex (int.coe_nat_lt.1 $ by rw [β hkβ];
exact int.mod_lt_of_pos _ (int.coe_nat_pos.2 (nat.find_spec hex).1))
β¨nat.pos_of_ne_zero h, hkβ
β©),
β¨k / (nat.find hex : β€), subtype.ext_iff_val.2 begin
suffices : g ^ ((nat.find hex : β€) * (k / nat.find hex)) = x,
{ simpa [zpow_mul] },
rw [int.mul_div_cancel' (int.dvd_of_mod_eq_zero (int.eq_zero_of_nat_abs_eq_zero hkβ)), hk]
endβ©β©β©
else
have H = (β₯ : subgroup Ξ±), from subgroup.ext $ Ξ» x, β¨Ξ» h, by simp at *; tauto,
Ξ» h, by rw [subgroup.mem_bot.1 h]; exact H.one_memβ©,
by clear _let_match; substI this; apply_instance
open finset nat
section classical
open_locale classical
@[to_additive is_add_cyclic.card_pow_eq_one_le]
lemma is_cyclic.card_pow_eq_one_le [decidable_eq Ξ±] [fintype Ξ±] [is_cyclic Ξ±] {n : β}
(hn0 : 0 < n) : (univ.filter (Ξ» a : Ξ±, a ^ n = 1)).card β€ n :=
let β¨g, hgβ© := is_cyclic.exists_generator Ξ± in
calc (univ.filter (Ξ» a : Ξ±, a ^ n = 1)).card
β€ ((zpowers (g ^ (fintype.card Ξ± / (nat.gcd n (fintype.card Ξ±))))) : set Ξ±).to_finset.card :
card_le_of_subset (Ξ» x hx, let β¨m, hmβ© := show x β submonoid.powers g,
from mem_powers_iff_mem_zpowers.2 $ hg x in
set.mem_to_finset.2 β¨(m / (fintype.card Ξ± / (nat.gcd n (fintype.card Ξ±))) : β),
have hgmn : g ^ (m * nat.gcd n (fintype.card Ξ±)) = 1,
by rw [pow_mul, hm, β pow_gcd_card_eq_one_iff]; exact (mem_filter.1 hx).2,
begin
rw [zpow_coe_nat, β pow_mul, nat.mul_div_cancel_left', hm],
refine dvd_of_mul_dvd_mul_right (gcd_pos_of_pos_left (fintype.card Ξ±) hn0) _,
conv_lhs
{ rw [nat.div_mul_cancel (nat.gcd_dvd_right _ _),
βorder_of_eq_card_of_forall_mem_zpowers hg] },
exact order_of_dvd_of_pow_eq_one hgmn
endβ©)
... β€ n :
let β¨m, hmβ© := nat.gcd_dvd_right n (fintype.card Ξ±) in
have hm0 : 0 < m, from nat.pos_of_ne_zero $
Ξ» hm0, by { rw [hm0, mul_zero, fintype.card_eq_zero_iff] at hm, exact hm.elim' 1 },
begin
simp only [set.to_finset_card, set_like.coe_sort_coe],
rw [βorder_eq_card_zpowers, order_of_pow g, order_of_eq_card_of_forall_mem_zpowers hg],
rw [hm] {occs := occurrences.pos [2,3]},
rw [nat.mul_div_cancel_left _ (gcd_pos_of_pos_left _ hn0), gcd_mul_left_left,
hm, nat.mul_div_cancel _ hm0],
exact le_of_dvd hn0 (nat.gcd_dvd_left _ _)
end
end classical
@[to_additive]
lemma is_cyclic.exists_monoid_generator [fintype Ξ±]
[is_cyclic Ξ±] : β x : Ξ±, β y : Ξ±, y β submonoid.powers x :=
by { simp_rw [mem_powers_iff_mem_zpowers], exact is_cyclic.exists_generator Ξ± }
section
variables [decidable_eq Ξ±] [fintype Ξ±]
@[to_additive]
lemma is_cyclic.image_range_order_of (ha : β x : Ξ±, x β zpowers a) :
finset.image (Ξ» i, a ^ i) (range (order_of a)) = univ :=
begin
simp_rw [βset_like.mem_coe] at ha,
simp only [image_range_order_of, set.eq_univ_iff_forall.mpr ha, set.to_finset_univ],
end
@[to_additive]
lemma is_cyclic.image_range_card (ha : β x : Ξ±, x β zpowers a) :
finset.image (Ξ» i, a ^ i) (range (fintype.card Ξ±)) = univ :=
by rw [β order_of_eq_card_of_forall_mem_zpowers ha, is_cyclic.image_range_order_of ha]
end
section totient
variables [decidable_eq Ξ±] [fintype Ξ±]
(hn : β n : β, 0 < n β (univ.filter (Ξ» a : Ξ±, a ^ n = 1)).card β€ n)
include hn
private lemma card_pow_eq_one_eq_order_of_aux (a : Ξ±) :
(finset.univ.filter (Ξ» b : Ξ±, b ^ order_of a = 1)).card = order_of a :=
le_antisymm
(hn _ (order_of_pos a))
(calc order_of a = @fintype.card (zpowers a) (id _) : order_eq_card_zpowers
... β€ @fintype.card (β(univ.filter (Ξ» b : Ξ±, b ^ order_of a = 1)) : set Ξ±)
(fintype.of_finset _ (Ξ» _, iff.rfl)) :
@fintype.card_le_of_injective (zpowers a)
(β(univ.filter (Ξ» b : Ξ±, b ^ order_of a = 1)) : set Ξ±)
(id _) (id _) (Ξ» b, β¨b.1, mem_filter.2 β¨mem_univ _,
let β¨i, hiβ© := b.2 in
by rw [β hi, β zpow_coe_nat, β zpow_mul, mul_comm, zpow_mul, zpow_coe_nat,
pow_order_of_eq_one, one_zpow]β©β©) (Ξ» _ _ h, subtype.eq (subtype.mk.inj h))
... = (univ.filter (Ξ» b : Ξ±, b ^ order_of a = 1)).card : fintype.card_of_finset _ _)
open_locale nat -- use Ο for nat.totient
private lemma card_order_of_eq_totient_auxβ :
β {d : β}, d β£ fintype.card Ξ± β 0 < (univ.filter (Ξ» a : Ξ±, order_of a = d)).card β
(univ.filter (Ξ» a : Ξ±, order_of a = d)).card = Ο d :=
begin
intros d hd hd0,
induction d using nat.strong_rec' with d IH,
rcases d.eq_zero_or_pos with rfl | hd_pos,
{ cases fintype.card_ne_zero (eq_zero_of_zero_dvd hd) },
rcases card_pos.1 hd0 with β¨a, ha'β©,
have ha : order_of a = d := (mem_filter.1 ha').2,
have h1 : β m in d.proper_divisors, (univ.filter (Ξ» a : Ξ±, order_of a = m)).card =
β m in d.proper_divisors, Ο m,
{ refine finset.sum_congr rfl (Ξ» m hm, _),
simp only [mem_filter, mem_range, mem_proper_divisors] at hm,
refine IH m hm.2 (hm.1.trans hd) (finset.card_pos.2 β¨a ^ (d / m), _β©),
simp only [mem_filter, mem_univ, order_of_pow a, ha, true_and,
nat.gcd_eq_right (div_dvd_of_dvd hm.1), nat.div_div_self hm.1 hd_pos] },
have h2 : β m in d.divisors, (univ.filter (Ξ» a : Ξ±, order_of a = m)).card =
β m in d.divisors, Ο m,
{ rw [βfilter_dvd_eq_divisors hd_pos.ne', sum_card_order_of_eq_card_pow_eq_one hd_pos,
filter_dvd_eq_divisors hd_pos.ne', sum_totient, βha, card_pow_eq_one_eq_order_of_aux hn a] },
simpa [divisors_eq_proper_divisors_insert_self_of_pos hd_pos, βh1] using h2,
end
lemma card_order_of_eq_totient_auxβ {d : β} (hd : d β£ fintype.card Ξ±) :
(univ.filter (Ξ» a : Ξ±, order_of a = d)).card = Ο d :=
begin
let c := fintype.card Ξ±,
have hc0 : 0 < c := fintype.card_pos_iff.2 β¨1β©,
apply card_order_of_eq_totient_auxβ hn hd,
by_contradiction h0,
simp only [not_lt, _root_.le_zero_iff, card_eq_zero] at h0,
apply lt_irrefl c,
calc
c = β m in c.divisors, (univ.filter (Ξ» a : Ξ±, order_of a = m)).card : by
{ simp only [βfilter_dvd_eq_divisors hc0.ne', sum_card_order_of_eq_card_pow_eq_one hc0],
apply congr_arg card,
simp }
... = β m in c.divisors.erase d, (univ.filter (Ξ» a : Ξ±, order_of a = m)).card : by
{ rw eq_comm,
refine (sum_subset (erase_subset _ _) (Ξ» m hmβ hmβ, _)),
have : m = d, by { contrapose! hmβ, exact mem_erase_of_ne_of_mem hmβ hmβ },
simp [this, h0] }
... β€ β m in c.divisors.erase d, Ο m : by
{ refine sum_le_sum (Ξ» m hm, _),
have hmc : m β£ c, { simp only [mem_erase, mem_divisors] at hm, tauto },
rcases (filter (Ξ» (a : Ξ±), order_of a = m) univ).card.eq_zero_or_pos with h1 | h1,
{ simp [h1] }, { simp [card_order_of_eq_totient_auxβ hn hmc h1] } }
... < β m in c.divisors, Ο m :
sum_erase_lt_of_pos (mem_divisors.2 β¨hd, hc0.ne'β©) (totient_pos (pos_of_dvd_of_pos hd hc0))
... = c : sum_totient _
end
lemma is_cyclic_of_card_pow_eq_one_le : is_cyclic Ξ± :=
have (univ.filter (Ξ» a : Ξ±, order_of a = fintype.card Ξ±)).nonempty,
from (card_pos.1 $
by rw [card_order_of_eq_totient_auxβ hn dvd_rfl];
exact totient_pos (fintype.card_pos_iff.2 β¨1β©)),
let β¨x, hxβ© := this in
is_cyclic_of_order_of_eq_card x (finset.mem_filter.1 hx).2
lemma is_add_cyclic_of_card_pow_eq_one_le {Ξ±} [add_group Ξ±] [decidable_eq Ξ±] [fintype Ξ±]
(hn : β n : β, 0 < n β (univ.filter (Ξ» a : Ξ±, n β’ a = 0)).card β€ n) : is_add_cyclic Ξ± :=
begin
obtain β¨g, hgβ© := @is_cyclic_of_card_pow_eq_one_le (multiplicative Ξ±) _ _ _ hn,
exact β¨β¨g, hgβ©β©
end
attribute [to_additive is_cyclic_of_card_pow_eq_one_le] is_add_cyclic_of_card_pow_eq_one_le
end totient
lemma is_cyclic.card_order_of_eq_totient [is_cyclic Ξ±] [fintype Ξ±]
{d : β} (hd : d β£ fintype.card Ξ±) : (univ.filter (Ξ» a : Ξ±, order_of a = d)).card = totient d :=
begin
classical,
apply card_order_of_eq_totient_auxβ (Ξ» n, is_cyclic.card_pow_eq_one_le) hd
end
lemma is_add_cyclic.card_order_of_eq_totient {Ξ±} [add_group Ξ±] [is_add_cyclic Ξ±] [fintype Ξ±] {d : β}
(hd : d β£ fintype.card Ξ±) : (univ.filter (Ξ» a : Ξ±, add_order_of a = d)).card = totient d :=
begin
obtain β¨g, hgβ© := id βΉis_add_cyclic Ξ±βΊ,
exact @is_cyclic.card_order_of_eq_totient (multiplicative Ξ±) _ β¨β¨g, hgβ©β© _ _ hd
end
attribute [to_additive is_cyclic.card_order_of_eq_totient] is_add_cyclic.card_order_of_eq_totient
/-- A finite group of prime order is simple. -/
@[to_additive]
lemma is_simple_group_of_prime_card {Ξ± : Type u} [group Ξ±] [fintype Ξ±] {p : β} [hp : fact p.prime]
(h : fintype.card Ξ± = p) : is_simple_group Ξ± :=
β¨begin
have h' := nat.prime.one_lt (fact.out p.prime),
rw β h at h',
haveI := fintype.one_lt_card_iff_nontrivial.1 h',
apply exists_pair_ne Ξ±,
end, Ξ» H Hn, begin
classical,
have hcard := card_subgroup_dvd_card H,
rw [h, dvd_prime (fact.out p.prime)] at hcard,
refine hcard.imp (Ξ» h1, _) (Ξ» hp, _),
{ haveI := fintype.card_le_one_iff_subsingleton.1 (le_of_eq h1),
apply eq_bot_of_subsingleton },
{ exact eq_top_of_card_eq _ (hp.trans h.symm) }
endβ©
end cyclic
section quotient_center
open subgroup
variables {G : Type*} {H : Type*} [group G] [group H]
/-- A group is commutative if the quotient by the center is cyclic.
Also see `comm_group_of_cycle_center_quotient` for the `comm_group` instance. -/
@[to_additive commutative_of_add_cyclic_center_quotient "A group is commutative if the quotient by
the center is cyclic. Also see `add_comm_group_of_cycle_center_quotient`
for the `add_comm_group` instance."]
lemma commutative_of_cyclic_center_quotient [is_cyclic H] (f : G β* H)
(hf : f.ker β€ center G) (a b : G) : a * b = b * a :=
let β¨β¨x, y, (hxy : f y = x)β©, (hx : β a : f.range, a β zpowers _)β© :=
is_cyclic.exists_generator f.range in
let β¨m, hmβ© := hx β¨f a, a, rflβ© in
let β¨n, hnβ© := hx β¨f b, b, rflβ© in
have hm : x ^ m = f a, by simpa [subtype.ext_iff] using hm,
have hn : x ^ n = f b, by simpa [subtype.ext_iff] using hn,
have ha : y ^ (-m) * a β center G,
from hf (by rw [f.mem_ker, f.map_mul, f.map_zpow, hxy, zpow_neg, hm, inv_mul_self]),
have hb : y ^ (-n) * b β center G,
from hf (by rw [f.mem_ker, f.map_mul, f.map_zpow, hxy, zpow_neg, hn, inv_mul_self]),
calc a * b = y ^ m * ((y ^ (-m) * a) * y ^ n) * (y ^ (-n) * b) : by simp [mul_assoc]
... = y ^ m * (y ^ n * (y ^ (-m) * a)) * (y ^ (-n) * b) : by rw [mem_center_iff.1 ha]
... = y ^ m * y ^ n * y ^ (-m) * (a * (y ^ (-n) * b)) : by simp [mul_assoc]
... = y ^ m * y ^ n * y ^ (-m) * ((y ^ (-n) * b) * a) : by rw [mem_center_iff.1 hb]
... = b * a : by group
/-- A group is commutative if the quotient by the center is cyclic. -/
@[to_additive commutative_of_add_cycle_center_quotient "A group is commutative if the quotient by
the center is cyclic."]
def comm_group_of_cycle_center_quotient [is_cyclic H] (f : G β* H)
(hf : f.ker β€ center G) : comm_group G :=
{ mul_comm := commutative_of_cyclic_center_quotient f hf,
..show group G, by apply_instance }
end quotient_center
namespace is_simple_group
section comm_group
variables [comm_group Ξ±] [is_simple_group Ξ±]
@[priority 100, to_additive is_simple_add_group.is_add_cyclic]
instance : is_cyclic Ξ± :=
begin
cases subsingleton_or_nontrivial Ξ± with hi hi; haveI := hi,
{ apply is_cyclic_of_subsingleton },
{ obtain β¨g, hgβ© := exists_ne (1 : Ξ±),
refine β¨β¨g, Ξ» x, _β©β©,
cases is_simple_order.eq_bot_or_eq_top (subgroup.zpowers g) with hb ht,
{ exfalso,
apply hg,
rw [β subgroup.mem_bot, β hb],
apply subgroup.mem_zpowers },
{ rw ht,
apply subgroup.mem_top } }
end
@[to_additive]
theorem prime_card [fintype Ξ±] : (fintype.card Ξ±).prime :=
begin
have h0 : 0 < fintype.card Ξ± := fintype.card_pos_iff.2 (by apply_instance),
obtain β¨g, hgβ© := is_cyclic.exists_generator Ξ±,
rw nat.prime_def_lt'',
refine β¨fintype.one_lt_card_iff_nontrivial.2 infer_instance, Ξ» n hn, _β©,
refine (is_simple_order.eq_bot_or_eq_top (subgroup.zpowers (g ^ n))).symm.imp _ _,
{ intro h,
have hgo := order_of_pow g,
rw [order_of_eq_card_of_forall_mem_zpowers hg, nat.gcd_eq_right_iff_dvd.1 hn,
order_of_eq_card_of_forall_mem_zpowers, eq_comm,
nat.div_eq_iff_eq_mul_left (nat.pos_of_dvd_of_pos hn h0) hn] at hgo,
{ exact (mul_left_cancelβ (ne_of_gt h0) ((mul_one (fintype.card Ξ±)).trans hgo)).symm },
{ intro x,
rw h,
exact subgroup.mem_top _ } },
{ intro h,
apply le_antisymm (nat.le_of_dvd h0 hn),
rw β order_of_eq_card_of_forall_mem_zpowers hg,
apply order_of_le_of_pow_eq_one (nat.pos_of_dvd_of_pos hn h0),
rw [β subgroup.mem_bot, β h],
exact subgroup.mem_zpowers _ }
end
end comm_group
end is_simple_group
@[to_additive add_comm_group.is_simple_iff_is_add_cyclic_and_prime_card]
theorem comm_group.is_simple_iff_is_cyclic_and_prime_card [fintype Ξ±] [comm_group Ξ±] :
is_simple_group Ξ± β is_cyclic Ξ± β§ (fintype.card Ξ±).prime :=
begin
split,
{ introI h,
exact β¨is_simple_group.is_cyclic, is_simple_group.prime_cardβ© },
{ rintro β¨hc, hpβ©,
haveI : fact (fintype.card Ξ±).prime := β¨hpβ©,
exact is_simple_group_of_prime_card rfl }
end
section exponent
open monoid
@[to_additive] lemma is_cyclic.exponent_eq_card [group Ξ±] [is_cyclic Ξ±] [fintype Ξ±] :
exponent Ξ± = fintype.card Ξ± :=
begin
obtain β¨g, hgβ© := is_cyclic.exists_generator Ξ±,
apply nat.dvd_antisymm,
{ rw [βlcm_order_eq_exponent, finset.lcm_dvd_iff],
exact Ξ» b _, order_of_dvd_card_univ },
rw βorder_of_eq_card_of_forall_mem_zpowers hg,
exact order_dvd_exponent _
end
@[to_additive] lemma is_cyclic.of_exponent_eq_card [comm_group Ξ±] [fintype Ξ±]
(h : exponent Ξ± = fintype.card Ξ±) : is_cyclic Ξ± :=
let β¨g, _, hgβ© := finset.mem_image.mp (finset.max'_mem _ _) in
is_cyclic_of_order_of_eq_card g $ hg.trans $ exponent_eq_max'_order_of.symm.trans h
@[to_additive] lemma is_cyclic.iff_exponent_eq_card [comm_group Ξ±] [fintype Ξ±] :
is_cyclic Ξ± β exponent Ξ± = fintype.card Ξ± :=
β¨Ξ» h, by exactI is_cyclic.exponent_eq_card, is_cyclic.of_exponent_eq_cardβ©
@[to_additive] lemma is_cyclic.exponent_eq_zero_of_infinite [group Ξ±] [is_cyclic Ξ±] [infinite Ξ±] :
exponent Ξ± = 0 :=
let β¨g, hgβ© := is_cyclic.exists_generator Ξ± in
exponent_eq_zero_of_order_zero $ infinite.order_of_eq_zero_of_forall_mem_zpowers hg
end exponent
|
74396b833ef3d3a98d51e2a888d884c91665a957
|
f57749ca63d6416f807b770f67559503fdb21001
|
/hott/types/nat/hott.hlean
|
81fd9102755f0c8eb7fb64ff80ddcd39a612a3cd
|
[
"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
| 3,325
|
hlean
|
/-
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
Theorems about the natural numbers specific to HoTT
-/
import .basic
open is_trunc unit empty eq equiv
namespace nat
definition is_hprop_le [instance] (n m : β) : is_hprop (n β€ m) :=
begin
assert lem : Ξ {n m : β} (p : n β€ m) (q : n = m), p = q βΈ le.refl n,
{ intros, cases p,
{ assert H' : q = idp, apply is_hset.elim,
cases H', reflexivity},
{ cases q, exfalso, apply not_succ_le_self a}},
apply is_hprop.mk, intro H1 H2, induction H2,
{ apply lem},
{ cases H1,
{ exfalso, apply not_succ_le_self a},
{ exact ap le.step !v_0}},
end
definition le_equiv_succ_le_succ (n m : β) : (n β€ m) β (succ n β€ succ m) :=
equiv_of_is_hprop succ_le_succ le_of_succ_le_succ
definition le_succ_equiv_pred_le (n m : β) : (n β€ succ m) β (pred n β€ m) :=
equiv_of_is_hprop pred_le_pred le_succ_of_pred_le
set_option pp.beta false
set_option pp.implicit true
set_option pp.coercions true
theorem lt_by_cases_lt {a b : β} {P : Type} (H1 : a < b β P) (H2 : a = b β P)
(H3 : a > b β P) (H : a < b) : lt.by_cases H1 H2 H3 = H1 H :=
begin
unfold lt.by_cases, induction (lt.trichotomy a b) with H' H',
{ esimp, exact ap H1 !is_hprop.elim},
{ exfalso, cases H' with H' H', apply lt.irrefl, exact H' βΈ H, exact lt.asymm H H'}
end
theorem lt_by_cases_eq {a b : β} {P : Type} (H1 : a < b β P) (H2 : a = b β P)
(H3 : a > b β P) (H : a = b) : lt.by_cases H1 H2 H3 = H2 H :=
begin
unfold lt.by_cases, induction (lt.trichotomy a b) with H' H',
{ exfalso, apply lt.irrefl, exact H βΈ H'},
{ cases H' with H' H', esimp, exact ap H2 !is_hprop.elim, exfalso, apply lt.irrefl, exact H βΈ H'}
end
theorem lt_by_cases_ge {a b : β} {P : Type} (H1 : a < b β P) (H2 : a = b β P)
(H3 : a > b β P) (H : a > b) : lt.by_cases H1 H2 H3 = H3 H :=
begin
unfold lt.by_cases, induction (lt.trichotomy a b) with H' H',
{ exfalso, exact lt.asymm H H'},
{ cases H' with H' H', exfalso, apply lt.irrefl, exact H' βΈ H, esimp, exact ap H3 !is_hprop.elim}
end
theorem lt_ge_by_cases_lt {n m : β} {P : Type} (H1 : n < m β P) (H2 : n β₯ m β P)
(H : n < m) : lt_ge_by_cases H1 H2 = H1 H :=
by apply lt_by_cases_lt
theorem lt_ge_by_cases_ge {n m : β} {P : Type} (H1 : n < m β P) (H2 : n β₯ m β P)
(H : n β₯ m) : lt_ge_by_cases H1 H2 = H2 H :=
begin
unfold [lt_ge_by_cases,lt.by_cases], induction (lt.trichotomy n m) with H' H',
{ exfalso, apply lt.irrefl, exact lt_of_le_of_lt H H'},
{ cases H' with H' H'; all_goals (esimp; apply ap H2 !is_hprop.elim)}
end
theorem lt_ge_by_cases_le {n m : β} {P : Type} {H1 : n β€ m β P} {H2 : n β₯ m β P}
(H : n β€ m) (Heq : Ξ (p : n = m), H1 (le_of_eq p) = H2 (le_of_eq pβ»ΒΉ))
: lt_ge_by_cases (Ξ»H', H1 (le_of_lt H')) H2 = H1 H :=
begin
unfold [lt_ge_by_cases,lt.by_cases], induction (lt.trichotomy n m) with H' H',
{ esimp, apply ap H1 !is_hprop.elim},
{ cases H' with H' H',
esimp, exact !Heqβ»ΒΉ β¬ ap H1 !is_hprop.elim,
exfalso, apply lt.irrefl, apply lt_of_le_of_lt H H'}
end
end nat
|
809e2575841f4836bdceea7bae93fa399de1f330
|
6432ea7a083ff6ba21ea17af9ee47b9c371760f7
|
/tests/lean/run/missingSizeOfArrayGetThm.lean
|
058e020c0a26b9b15c308932f56fc27bfc74e686
|
[
"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
| 430
|
lean
|
inductive Node (Data : Type) : Type where
| empty : Node Data
| node (children : Array (Node Data)) : Node Data
| leaf (data : Data) : Node Data
def Node.FixedBranching (n : Nat) : Node Data β Prop
| empty => True
| node children => children.size = n β§ β i, (children.get i).FixedBranching n
| leaf _ => True
structure MNode (Data : Type) (m : Nat) where
node : Node Data
fix_branching : node.FixedBranching m
|
caf7eb1ad6c525f5ec244dc55a12b1c7ace0525c
|
ff5230333a701471f46c57e8c115a073ebaaa448
|
/tests/lean/run/mrw.lean
|
6b8130151b0c5fd869e13d895243b3693db9275d
|
[
"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
| 134
|
lean
|
example (n : nat) : β x, x + n = n + 1 :=
begin
constructor,
fail_if_success {rw [zero_add] {unify := ff}},
rw [add_comm]
end
|
961402fc91389c363001e6f5f00215bad040c6fa
|
618003631150032a5676f229d13a079ac875ff77
|
/src/analysis/mean_inequalities.lean
|
82e15ed80cc9b42a28fab77437651f986ec4bf4f
|
[
"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
| 6,816
|
lean
|
/-
Copyright (c) 2019 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import analysis.convex.specific_functions
import analysis.special_functions.pow
/-!
# Mean value inequalities
In this file we prove various inequalities between mean values:
arithmetic mean, geometric mean, generalized mean (natural and integer
cases).
For generalized means we only prove
$\left( β_j w_j z_j \right)^n β€ β_j w_j z_j^n$ because standard versions would
require $\sqrt[n]{x}$ which is not implemented in `mathlib` yet.
Probably a better approach to the generalized means inequality is to
prove `convex_on_rpow` in `analysis/convex/specific_functions` first,
then apply it.
It is not yet clear which versions will be useful in the future, so we
provide two different forms of most inequalities : for `β` and for
`ββ₯0`. For the AM-GM inequality we also prove special cases for `n=2`
and `n=3`.
-/
universes u v
open real finset
open_locale classical nnreal
variables {ΞΉ : Type u} (s : finset ΞΉ)
/-- Geometric mean is less than or equal to the arithmetic mean, weighted version
for functions on `finset`s. -/
theorem real.am_gm_weighted (w z : ΞΉ β β)
(hw : β i β s, 0 β€ w i) (hw' : s.sum w = 1) (hz : β i β s, 0 β€ z i) :
s.prod (Ξ» i, (z i) ^ (w i)) β€ s.sum (Ξ» i, w i * z i) :=
begin
let s' := s.filter (Ξ» i, w i β 0),
rw [β sum_filter_ne_zero] at hw',
suffices : s'.prod (Ξ» i, (z i) ^ (w i)) β€ s'.sum (Ξ» i, w i * z i),
{ have A : β i β s, i β s' β w i = 0,
{ intros i hi hi',
simpa only [hi, mem_filter, ne.def, true_and, not_not] using hi' },
have B : β i β s, i β s' β (z i) ^ (w i) = 1,
from Ξ» i hi hi', by rw [A i hi hi', rpow_zero],
have C : β i β s, i β s' β w i * z i = 0,
from Ξ» i hi hi', by rw [A i hi hi', zero_mul],
rwa [β prod_subset s.filter_subset B, β sum_subset s.filter_subset C] },
have A : β i β s', i β s β§ w i β 0, from Ξ» i hi, mem_filter.1 hi,
replace hz : β i β s', 0 β€ z i := Ξ» i hi, hz i (A i hi).1,
replace hw : β i β s', 0 β€ w i := Ξ» i hi, hw i (A i hi).1,
by_cases B : β i β s', z i = 0,
{ rcases B with β¨i, imem, hziβ©,
rw [prod_eq_zero imem],
{ exact sum_nonneg (Ξ» j hj, mul_nonneg (hw j hj) (hz j hj)) },
{ rw hzi, exact zero_rpow (A i imem).2 } },
{ replace hz : β i β s', 0 < z i,
from Ξ» i hi, lt_of_le_of_ne (hz _ hi) (Ξ» h, B β¨i, hi, h.symmβ©),
have := convex_on_exp.map_sum_le hw hw' (Ξ» i _, set.mem_univ $ log (z i)),
simp only [exp_sum, (β), smul_eq_mul, mul_comm (w _) (log _)] at this,
convert this using 1,
{ exact prod_congr rfl (Ξ» i hi, rpow_def_of_pos (hz i hi) _) },
{ exact sum_congr rfl (Ξ» i hi, congr_arg _ (exp_log $ hz i hi).symm) } }
end
theorem nnreal.am_gm_weighted (w z : ΞΉ β ββ₯0) (hw' : s.sum w = 1) :
s.prod (Ξ» i, (z i) ^ (w i:β)) β€ s.sum (Ξ» i, w i * z i) :=
begin
rw [β nnreal.coe_le_coe, nnreal.coe_prod, nnreal.coe_sum],
refine real.am_gm_weighted _ _ _ (Ξ» i _, (w i).coe_nonneg) _ (Ξ» i _, (z i).coe_nonneg),
assumption_mod_cast
end
theorem nnreal.am_gm2_weighted (wβ wβ pβ pβ : ββ₯0) (hw : wβ + wβ = 1) :
pβ ^ (wβ:β) * pβ ^ (wβ:β) β€ wβ * pβ + wβ * pβ :=
begin
have := nnreal.am_gm_weighted (univ : finset (fin 2)) (fin.cons wβ $ fin.cons wβ fin_zero_elim)
(fin.cons pβ $ fin.cons pβ $ fin_zero_elim),
simp only [fin.prod_univ_succ, fin.sum_univ_succ, fin.prod_univ_zero, fin.sum_univ_zero,
fin.cons_succ, fin.cons_zero, add_zero, mul_one] at this,
exact this hw
end
theorem real.am_gm2_weighted {wβ wβ pβ pβ : β} (hwβ : 0 β€ wβ) (hwβ : 0 β€ wβ)
(hpβ : 0 β€ pβ) (hpβ : 0 β€ pβ) (hw : wβ + wβ = 1) :
pβ ^ wβ * pβ ^ wβ β€ wβ * pβ + wβ * pβ :=
nnreal.am_gm2_weighted β¨wβ, hwββ© β¨wβ, hwββ© β¨pβ, hpββ© β¨pβ, hpββ© $ nnreal.coe_eq.1 $ by assumption
theorem nnreal.am_gm3_weighted (wβ wβ wβ pβ pβ pβ : ββ₯0) (hw : wβ + wβ + wβ = 1) :
pβ ^ (wβ:β) * pβ ^ (wβ:β) * pβ ^ (wβ:β) β€ wβ * pβ + wβ * pβ + wβ * pβ:=
begin
have := nnreal.am_gm_weighted (univ : finset (fin 3))
(fin.cons wβ $ fin.cons wβ $ fin.cons wβ fin_zero_elim)
(fin.cons pβ $ fin.cons pβ $ fin.cons pβ fin_zero_elim),
simp only [fin.prod_univ_succ, fin.sum_univ_succ, fin.prod_univ_zero, fin.sum_univ_zero,
fin.cons_succ, fin.cons_zero, add_zero, mul_one, (add_assoc _ _ _).symm,
(mul_assoc _ _ _).symm] at this,
exact this hw
end
/-- Young's inequality, `ββ₯0` version -/
theorem nnreal.young_inequality (a b : ββ₯0) {p q : ββ₯0} (hp : 1 < p) (hq : 1 < q)
(hpq : 1/p + 1/q = 1) : a * b β€ a^(p:β) / p + b^(q:β) / q :=
begin
have := nnreal.am_gm2_weighted (1/p) (1/q) (a^(p:β)) (b^(q:β)) hpq,
simp only [β nnreal.rpow_mul, one_div_eq_inv, nnreal.coe_div, nnreal.coe_one] at this,
rw [mul_inv_cancel, mul_inv_cancel, nnreal.rpow_one, nnreal.rpow_one] at this,
{ ring at β’ this,
convert this;
{ rw [nnreal.div_def, nnreal.div_def], ring } },
{ exact ne_of_gt (lt_trans zero_lt_one hq) },
{ exact ne_of_gt (lt_trans zero_lt_one hp) }
end
/-- Young's inequality, `β` version -/
theorem real.young_inequality {a b : β} (ha : 0 β€ a) (hb : 0 β€ b)
{p q : β} (hp : 1 < p) (hq : 1 < q) (hpq : 1/p + 1/q = 1) :
a * b β€ a^p / p + b^q / q :=
@nnreal.young_inequality β¨a, haβ© β¨b, hbβ© β¨p, le_trans zero_le_one (le_of_lt hp)β©
β¨q, le_trans zero_le_one (le_of_lt hq)β© hp hq (nnreal.coe_eq.1 hpq)
theorem real.pow_am_le_am_pow (w z : ΞΉ β β) (hw : β i β s, 0 β€ w i)
(hw' : s.sum w = 1) (hz : β i β s, 0 β€ z i) (n : β) :
(s.sum (Ξ» i, w i * z i)) ^ n β€ s.sum (Ξ» i, w i * z i ^ n) :=
(convex_on_pow n).map_sum_le hw hw' hz
theorem nnreal.pow_am_le_am_pow (w z : ΞΉ β ββ₯0) (hw' : s.sum w = 1) (n : β) :
(s.sum (Ξ» i, w i * z i)) ^ n β€ s.sum (Ξ» i, w i * z i ^ n) :=
begin
rw [β nnreal.coe_le_coe],
push_cast,
refine (convex_on_pow n).map_sum_le (Ξ» i _, (w i).coe_nonneg) _ (Ξ» i _, (z i).coe_nonneg),
assumption_mod_cast
end
theorem real.pow_am_le_am_pow_of_even (w z : ΞΉ β β) (hw : β i β s, 0 β€ w i)
(hw' : s.sum w = 1) {n : β} (hn : n.even) :
(s.sum (Ξ» i, w i * z i)) ^ n β€ s.sum (Ξ» i, w i * z i ^ n) :=
(convex_on_pow_of_even hn).map_sum_le hw hw' (Ξ» _ _, trivial)
theorem real.fpow_am_le_am_fpow (w z : ΞΉ β β) (hw : β i β s, 0 β€ w i)
(hw' : s.sum w = 1) (hz : β i β s, 0 < z i) (m : β€) :
(s.sum (Ξ» i, w i * z i)) ^ m β€ s.sum (Ξ» i, w i * z i ^ m) :=
(convex_on_fpow m).map_sum_le hw hw' hz
|
136c51a8a961daa9467854d064e33fc23634403f
|
c777c32c8e484e195053731103c5e52af26a25d1
|
/src/linear_algebra/span.lean
|
54c850ab6fabd557be8d03803544af90dbd401cb
|
[
"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
| 35,886
|
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, Kevin Buzzard, Yury Kudryashov, FrΓ©dΓ©ric Dupuis,
Heather Macbeth
-/
import linear_algebra.basic
import order.compactly_generated
import order.omega_complete_partial_order
/-!
# The span of a set of vectors, as a submodule
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
* `submodule.span s` is defined to be the smallest submodule containing the set `s`.
## Notations
* We introduce the notation `R β v` for the span of a singleton, `submodule.span R {v}`. This is
`\.`, not the same as the scalar multiplication `β’`/`\bub`.
-/
variables {R Rβ K M Mβ V S : Type*}
namespace submodule
open function set
open_locale pointwise
section add_comm_monoid
variables [semiring R] [add_comm_monoid M] [module R M]
variables {x : M} (p p' : submodule R M)
variables [semiring Rβ] {Οββ : R β+* Rβ}
variables [add_comm_monoid Mβ] [module Rβ Mβ]
section
variables (R)
/-- The span of a set `s β M` is the smallest submodule of M that contains `s`. -/
def span (s : set M) : submodule R M := Inf {p | s β p}
end
variables {s t : set M}
lemma mem_span : x β span R s β β p : submodule R M, s β p β x β p := mem_Interβ
lemma subset_span : s β span R s :=
Ξ» x h, mem_span.2 $ Ξ» p hp, hp h
lemma span_le {p} : span R s β€ p β s β p :=
β¨subset.trans subset_span, Ξ» ss x h, mem_span.1 h _ ssβ©
lemma span_mono (h : s β t) : span R s β€ span R t :=
span_le.2 $ subset.trans h subset_span
lemma span_monotone : monotone (span R : set M β submodule R M) :=
Ξ» _ _, span_mono
lemma span_eq_of_le (hβ : s β p) (hβ : p β€ span R s) : span R s = p :=
le_antisymm (span_le.2 hβ) hβ
lemma span_eq : span R (p : set M) = p :=
span_eq_of_le _ (subset.refl _) subset_span
lemma span_eq_span (hs : s β span R t) (ht : t β span R s) : span R s = span R t :=
le_antisymm (span_le.2 hs) (span_le.2 ht)
/-- A version of `submodule.span_eq` for when the span is by a smaller ring. -/
@[simp] lemma span_coe_eq_restrict_scalars
[semiring S] [has_smul S R] [module S M] [is_scalar_tower S R M] :
span S (p : set M) = p.restrict_scalars S :=
span_eq (p.restrict_scalars S)
lemma map_span [ring_hom_surjective Οββ] (f : M βββ[Οββ] Mβ) (s : set M) :
(span R s).map f = span Rβ (f '' s) :=
eq.symm $ span_eq_of_le _ (set.image_subset f subset_span) $
map_le_iff_le_comap.2 $ span_le.2 $ Ξ» x hx, subset_span β¨x, hx, rflβ©
alias submodule.map_span β _root_.linear_map.map_span
lemma map_span_le [ring_hom_surjective Οββ] (f : M βββ[Οββ] Mβ) (s : set M)
(N : submodule Rβ Mβ) : map f (span R s) β€ N β β m β s, f m β N :=
begin
rw [f.map_span, span_le, set.image_subset_iff],
exact iff.rfl
end
alias submodule.map_span_le β _root_.linear_map.map_span_le
@[simp] lemma span_insert_zero : span R (insert (0 : M) s) = span R s :=
begin
refine le_antisymm _ (submodule.span_mono (set.subset_insert 0 s)),
rw [span_le, set.insert_subset],
exact β¨by simp only [set_like.mem_coe, submodule.zero_mem], submodule.subset_spanβ©,
end
/- See also `span_preimage_eq` below. -/
lemma span_preimage_le (f : M βββ[Οββ] Mβ) (s : set Mβ) :
span R (f β»ΒΉ' s) β€ (span Rβ s).comap f :=
by { rw [span_le, comap_coe], exact preimage_mono (subset_span), }
alias submodule.span_preimage_le β _root_.linear_map.span_preimage_le
lemma closure_subset_span {s : set M} :
(add_submonoid.closure s : set M) β span R s :=
(@add_submonoid.closure_le _ _ _ (span R s).to_add_submonoid).mpr subset_span
lemma closure_le_to_add_submonoid_span {s : set M} :
add_submonoid.closure s β€ (span R s).to_add_submonoid :=
closure_subset_span
@[simp] lemma span_closure {s : set M} : span R (add_submonoid.closure s : set M) = span R s :=
le_antisymm (span_le.mpr closure_subset_span) (span_mono add_submonoid.subset_closure)
/-- An induction principle for span membership. If `p` holds for 0 and all elements of `s`, and is
preserved under addition and scalar multiplication, then `p` holds for all elements of the span of
`s`. -/
@[elab_as_eliminator] lemma span_induction {p : M β Prop} (h : x β span R s)
(Hs : β x β s, p x) (H0 : p 0)
(H1 : β x y, p x β p y β p (x + y))
(H2 : β (a:R) x, p x β p (a β’ x)) : p x :=
(@span_le _ _ _ _ _ _ β¨p, H1, H0, H2β©).2 Hs h
/-- A dependent version of `submodule.span_induction`. -/
lemma span_induction' {p : Ξ x, x β span R s β Prop}
(Hs : β x (h : x β s), p x (subset_span h))
(H0 : p 0 (submodule.zero_mem _))
(H1 : β x hx y hy, p x hx β p y hy β p (x + y) (submodule.add_mem _ βΉ_βΊ βΉ_βΊ))
(H2 : β (a : R) x hx, p x hx β p (a β’ x) (submodule.smul_mem _ _ βΉ_βΊ)) {x} (hx : x β span R s) :
p x hx :=
begin
refine exists.elim _ (Ξ» (hx : x β span R s) (hc : p x hx), hc),
refine span_induction hx (Ξ» m hm, β¨subset_span hm, Hs m hmβ©) β¨zero_mem _, H0β©
(Ξ» x y hx hy, exists.elim hx $ Ξ» hx' hx, exists.elim hy $ Ξ» hy' hy,
β¨add_mem hx' hy', H1 _ _ _ _ hx hyβ©) (Ξ» r x hx, exists.elim hx $ Ξ» hx' hx,
β¨smul_mem _ _ hx', H2 r _ _ hxβ©)
end
@[simp] lemma span_span_coe_preimage : span R ((coe : span R s β M) β»ΒΉ' s) = β€ :=
eq_top_iff.2 $ Ξ» x, subtype.rec_on x $ Ξ» x hx _, begin
refine span_induction' (Ξ» x hx, _) _ (Ξ» x y _ _, _) (Ξ» r x _, _) hx,
{ exact subset_span hx },
{ exact zero_mem _ },
{ exact add_mem },
{ exact smul_mem _ _ }
end
lemma span_nat_eq_add_submonoid_closure (s : set M) :
(span β s).to_add_submonoid = add_submonoid.closure s :=
begin
refine eq.symm (add_submonoid.closure_eq_of_le subset_span _),
apply add_submonoid.to_nat_submodule.symm.to_galois_connection.l_le _,
rw span_le,
exact add_submonoid.subset_closure,
end
@[simp] lemma span_nat_eq (s : add_submonoid M) : (span β (s : set M)).to_add_submonoid = s :=
by rw [span_nat_eq_add_submonoid_closure, s.closure_eq]
lemma span_int_eq_add_subgroup_closure {M : Type*} [add_comm_group M] (s : set M) :
(span β€ s).to_add_subgroup = add_subgroup.closure s :=
eq.symm $ add_subgroup.closure_eq_of_le _ subset_span $ Ξ» x hx, span_induction hx
(Ξ» x hx, add_subgroup.subset_closure hx) (add_subgroup.zero_mem _)
(Ξ» _ _, add_subgroup.add_mem _) (Ξ» _ _ _, add_subgroup.zsmul_mem _ βΉ_βΊ _)
@[simp] lemma span_int_eq {M : Type*} [add_comm_group M] (s : add_subgroup M) :
(span β€ (s : set M)).to_add_subgroup = s :=
by rw [span_int_eq_add_subgroup_closure, s.closure_eq]
section
variables (R M)
/-- `span` forms a Galois insertion with the coercion from submodule to set. -/
protected def gi : galois_insertion (@span R M _ _ _) coe :=
{ choice := Ξ» s _, span R s,
gc := Ξ» s t, span_le,
le_l_u := Ξ» s, subset_span,
choice_eq := Ξ» s h, rfl }
end
@[simp] lemma span_empty : span R (β
: set M) = β₯ :=
(submodule.gi R M).gc.l_bot
@[simp] lemma span_univ : span R (univ : set M) = β€ :=
eq_top_iff.2 $ set_like.le_def.2 $ subset_span
lemma span_union (s t : set M) : span R (s βͺ t) = span R s β span R t :=
(submodule.gi R M).gc.l_sup
lemma span_Union {ΞΉ} (s : ΞΉ β set M) : span R (β i, s i) = β¨ i, span R (s i) :=
(submodule.gi R M).gc.l_supr
lemma span_Unionβ {ΞΉ} {ΞΊ : ΞΉ β Sort*} (s : Ξ i, ΞΊ i β set M) :
span R (β i j, s i j) = β¨ i j, span R (s i j) :=
(submodule.gi R M).gc.l_suprβ
lemma span_attach_bUnion [decidable_eq M] {Ξ± : Type*} (s : finset Ξ±) (f : s β finset M) :
span R (s.attach.bUnion f : set M) = β¨ x, span R (f x) :=
by simpa [span_Union]
lemma sup_span : p β span R s = span R (p βͺ s) :=
by rw [submodule.span_union, p.span_eq]
lemma span_sup : span R s β p = span R (s βͺ p) :=
by rw [submodule.span_union, p.span_eq]
/- Note that the character `β` U+2219 used below is different from the scalar multiplication
character `β’` U+2022 and the matrix multiplication character `β¬` U+2B1D. -/
notation R` β `:1000 x := span R (@singleton _ _ set.has_singleton x)
lemma span_eq_supr_of_singleton_spans (s : set M) : span R s = β¨ x β s, R β x :=
by simp only [βspan_Union, set.bUnion_of_singleton s]
lemma span_range_eq_supr {ΞΉ : Type*} {v : ΞΉ β M} : span R (range v) = β¨ i, R β v i :=
by rw [span_eq_supr_of_singleton_spans, supr_range]
lemma span_smul_le (s : set M) (r : R) :
span R (r β’ s) β€ span R s :=
begin
rw span_le,
rintros _ β¨x, hx, rflβ©,
exact smul_mem (span R s) r (subset_span hx),
end
lemma subset_span_trans {U V W : set M} (hUV : U β submodule.span R V)
(hVW : V β submodule.span R W) :
U β submodule.span R W :=
(submodule.gi R M).gc.le_u_l_trans hUV hVW
/-- See `submodule.span_smul_eq` (in `ring_theory.ideal.operations`) for
`span R (r β’ s) = r β’ span R s` that holds for arbitrary `r` in a `comm_semiring`. -/
lemma span_smul_eq_of_is_unit (s : set M) (r : R) (hr : is_unit r) :
span R (r β’ s) = span R s :=
begin
apply le_antisymm,
{ apply span_smul_le },
{ convert span_smul_le (r β’ s) ((hr.unit β»ΒΉ : _) : R),
rw smul_smul,
erw hr.unit.inv_val,
rw one_smul }
end
@[simp] theorem coe_supr_of_directed {ΞΉ} [hΞΉ : nonempty ΞΉ]
(S : ΞΉ β submodule R M) (H : directed (β€) S) :
((supr S : submodule R M) : set M) = β i, S i :=
begin
refine subset.antisymm _ (Union_subset $ le_supr S),
suffices : (span R (β i, (S i : set M)) : set M) β β (i : ΞΉ), β(S i),
by simpa only [span_Union, span_eq] using this,
refine (Ξ» x hx, span_induction hx (Ξ» _, id) _ _ _);
simp only [mem_Union, exists_imp_distrib],
{ exact hΞΉ.elim (Ξ» i, β¨i, (S i).zero_memβ©) },
{ intros x y i hi j hj,
rcases H i j with β¨k, ik, jkβ©,
exact β¨k, add_mem (ik hi) (jk hj)β© },
{ exact Ξ» a x i hi, β¨i, smul_mem _ a hiβ© },
end
@[simp] theorem mem_supr_of_directed {ΞΉ} [nonempty ΞΉ]
(S : ΞΉ β submodule R M) (H : directed (β€) S) {x} :
x β supr S β β i, x β S i :=
by { rw [β set_like.mem_coe, coe_supr_of_directed S H, mem_Union], refl }
theorem mem_Sup_of_directed {s : set (submodule R M)}
{z} (hs : s.nonempty) (hdir : directed_on (β€) s) :
z β Sup s β β y β s, z β y :=
begin
haveI : nonempty s := hs.to_subtype,
simp only [Sup_eq_supr', mem_supr_of_directed _ hdir.directed_coe, set_coe.exists, subtype.coe_mk]
end
@[norm_cast, simp] lemma coe_supr_of_chain (a : β βo submodule R M) :
(β(β¨ k, a k) : set M) = β k, (a k : set M) :=
coe_supr_of_directed a a.monotone.directed_le
/-- We can regard `coe_supr_of_chain` as the statement that `coe : (submodule R M) β set M` is
Scott continuous for the Ο-complete partial order induced by the complete lattice structures. -/
lemma coe_scott_continuous : omega_complete_partial_order.continuous'
(coe : submodule R M β set M) :=
β¨set_like.coe_mono, coe_supr_of_chainβ©
@[simp] lemma mem_supr_of_chain (a : β βo submodule R M) (m : M) :
m β (β¨ k, a k) β β k, m β a k :=
mem_supr_of_directed a a.monotone.directed_le
section
variables {p p'}
lemma mem_sup : x β p β p' β β (y β p) (z β p'), y + z = x :=
β¨Ξ» h, begin
rw [β span_eq p, β span_eq p', β span_union] at h,
apply span_induction h,
{ rintro y (h | h),
{ exact β¨y, h, 0, by simp, by simpβ© },
{ exact β¨0, by simp, y, h, by simpβ© } },
{ exact β¨0, by simp, 0, by simpβ© },
{ rintro _ _ β¨yβ, hyβ, zβ, hzβ, rflβ© β¨yβ, hyβ, zβ, hzβ, rflβ©,
exact β¨_, add_mem hyβ hyβ, _, add_mem hzβ hzβ, by simp [add_assoc]; ccβ© },
{ rintro a _ β¨y, hy, z, hz, rflβ©,
exact β¨_, smul_mem _ a hy, _, smul_mem _ a hz, by simp [smul_add]β© }
end,
by rintro β¨y, hy, z, hz, rflβ©; exact add_mem
((le_sup_left : p β€ p β p') hy)
((le_sup_right : p' β€ p β p') hz)β©
lemma mem_sup' : x β p β p' β β (y : p) (z : p'), (y:M) + z = x :=
mem_sup.trans $ by simp only [set_like.exists, coe_mk]
variables (p p')
lemma coe_sup : β(p β p') = (p + p' : set M) :=
by { ext, rw [set_like.mem_coe, mem_sup, set.mem_add], simp, }
lemma sup_to_add_submonoid :
(p β p').to_add_submonoid = p.to_add_submonoid β p'.to_add_submonoid :=
begin
ext x,
rw [mem_to_add_submonoid, mem_sup, add_submonoid.mem_sup],
refl,
end
lemma sup_to_add_subgroup {R M : Type*} [ring R] [add_comm_group M] [module R M]
(p p' : submodule R M) :
(p β p').to_add_subgroup = p.to_add_subgroup β p'.to_add_subgroup :=
begin
ext x,
rw [mem_to_add_subgroup, mem_sup, add_subgroup.mem_sup],
refl,
end
end
lemma mem_span_singleton_self (x : M) : x β R β x := subset_span rfl
lemma nontrivial_span_singleton {x : M} (h : x β 0) : nontrivial (R β x) :=
β¨begin
use [0, x, submodule.mem_span_singleton_self x],
intros H,
rw [eq_comm, submodule.mk_eq_zero] at H,
exact h H
endβ©
lemma mem_span_singleton {y : M} : x β (R β y) β β a:R, a β’ y = x :=
β¨Ξ» h, begin
apply span_induction h,
{ rintro y (rfl|β¨β¨β©β©), exact β¨1, by simpβ© },
{ exact β¨0, by simpβ© },
{ rintro _ _ β¨a, rflβ© β¨b, rflβ©,
exact β¨a + b, by simp [add_smul]β© },
{ rintro a _ β¨b, rflβ©,
exact β¨a * b, by simp [smul_smul]β© }
end,
by rintro β¨a, y, rflβ©; exact
smul_mem _ _ (subset_span $ by simp)β©
lemma le_span_singleton_iff {s : submodule R M} {vβ : M} :
s β€ (R β vβ) β β v β s, β r : R, r β’ vβ = v :=
by simp_rw [set_like.le_def, mem_span_singleton]
variables (R)
lemma span_singleton_eq_top_iff (x : M) : (R β x) = β€ β β v, β r : R, r β’ x = v :=
by { rw [eq_top_iff, le_span_singleton_iff], tauto }
@[simp] lemma span_zero_singleton : (R β (0:M)) = β₯ :=
by { ext, simp [mem_span_singleton, eq_comm] }
lemma span_singleton_eq_range (y : M) : β(R β y) = range ((β’ y) : R β M) :=
set.ext $ Ξ» x, mem_span_singleton
lemma span_singleton_smul_le {S} [monoid S] [has_smul S R] [mul_action S M]
[is_scalar_tower S R M] (r : S) (x : M) : (R β (r β’ x)) β€ R β x :=
begin
rw [span_le, set.singleton_subset_iff, set_like.mem_coe],
exact smul_of_tower_mem _ _ (mem_span_singleton_self _)
end
lemma span_singleton_group_smul_eq {G} [group G] [has_smul G R] [mul_action G M]
[is_scalar_tower G R M] (g : G) (x : M) : (R β (g β’ x)) = R β x :=
begin
refine le_antisymm (span_singleton_smul_le R g x) _,
convert span_singleton_smul_le R (gβ»ΒΉ) (g β’ x),
exact (inv_smul_smul g x).symm
end
variables {R}
lemma span_singleton_smul_eq {r : R} (hr : is_unit r) (x : M) : (R β (r β’ x)) = R β x :=
begin
lift r to RΛ£ using hr,
rw βunits.smul_def,
exact span_singleton_group_smul_eq R r x,
end
lemma disjoint_span_singleton {K E : Type*} [division_ring K] [add_comm_group E] [module K E]
{s : submodule K E} {x : E} :
disjoint s (K β x) β (x β s β x = 0) :=
begin
refine disjoint_def.trans β¨Ξ» H hx, H x hx $ subset_span $ mem_singleton x, _β©,
assume H y hy hyx,
obtain β¨c, rflβ© := mem_span_singleton.1 hyx,
by_cases hc : c = 0,
{ rw [hc, zero_smul] },
{ rw [s.smul_mem_iff hc] at hy,
rw [H hy, smul_zero] }
end
lemma disjoint_span_singleton' {K E : Type*} [division_ring K] [add_comm_group E] [module K E]
{p : submodule K E} {x : E} (x0 : x β 0) :
disjoint p (K β x) β x β p :=
disjoint_span_singleton.trans β¨Ξ» hβ hβ, x0 (hβ hβ), Ξ» hβ hβ, (hβ hβ).elimβ©
lemma mem_span_singleton_trans {x y z : M} (hxy : x β R β y) (hyz : y β R β z) :
x β R β z :=
begin
rw [β set_like.mem_coe, β singleton_subset_iff] at *,
exact submodule.subset_span_trans hxy hyz
end
lemma mem_span_insert {y} : x β span R (insert y s) β β (a:R) (z β span R s), x = a β’ y + z :=
begin
simp only [β union_singleton, span_union, mem_sup, mem_span_singleton, exists_prop,
exists_exists_eq_and],
rw [exists_comm],
simp only [eq_comm, add_comm, exists_and_distrib_left]
end
lemma mem_span_pair {x y z : M} : z β span R ({x, y} : set M) β β a b : R, a β’ x + b β’ y = z :=
by simp_rw [mem_span_insert, mem_span_singleton, exists_prop, exists_exists_eq_and, eq_comm]
lemma span_insert (x) (s : set M) : span R (insert x s) = span R ({x} : set M) β span R s :=
by rw [insert_eq, span_union]
lemma span_insert_eq_span (h : x β span R s) : span R (insert x s) = span R s :=
span_eq_of_le _ (set.insert_subset.mpr β¨h, subset_spanβ©) (span_mono $ subset_insert _ _)
lemma span_span : span R (span R s : set M) = span R s := span_eq _
variables (R S s)
/-- If `R` is "smaller" ring than `S` then the span by `R` is smaller than the span by `S`. -/
lemma span_le_restrict_scalars [semiring S] [has_smul R S] [module S M] [is_scalar_tower R S M] :
span R s β€ (span S s).restrict_scalars R :=
submodule.span_le.2 submodule.subset_span
/-- A version of `submodule.span_le_restrict_scalars` with coercions. -/
@[simp] lemma span_subset_span [semiring S] [has_smul R S] [module S M] [is_scalar_tower R S M] :
β(span R s) β (span S s : set M) :=
span_le_restrict_scalars R S s
/-- Taking the span by a large ring of the span by the small ring is the same as taking the span
by just the large ring. -/
lemma span_span_of_tower [semiring S] [has_smul R S] [module S M] [is_scalar_tower R S M] :
span S (span R s : set M) = span S s :=
le_antisymm (span_le.2 $ span_subset_span R S s) (span_mono subset_span)
variables {R S s}
lemma span_eq_bot : span R (s : set M) = β₯ β β x β s, (x:M) = 0 :=
eq_bot_iff.trans β¨
Ξ» H x h, (mem_bot R).1 $ H $ subset_span h,
Ξ» H, span_le.2 (Ξ» x h, (mem_bot R).2 $ H x h)β©
@[simp] lemma span_singleton_eq_bot : (R β x) = β₯ β x = 0 :=
span_eq_bot.trans $ by simp
@[simp] lemma span_zero : span R (0 : set M) = β₯ := by rw [βsingleton_zero, span_singleton_eq_bot]
lemma span_singleton_eq_span_singleton {R M : Type*} [ring R] [add_comm_group M] [module R M]
[no_zero_smul_divisors R M] {x y : M} : (R β x) = (R β y) β β z : RΛ£, z β’ x = y :=
begin
by_cases hx : x = 0,
{ rw [hx, span_zero_singleton, eq_comm, span_singleton_eq_bot],
exact β¨Ξ» hy, β¨1, by rw [hy, smul_zero]β©, Ξ» β¨_, hzβ©, by rw [β hz, smul_zero]β© },
by_cases hy : y = 0,
{ rw [hy, span_zero_singleton, span_singleton_eq_bot],
exact β¨Ξ» hx, β¨1, by rw [hx, smul_zero]β©, Ξ» β¨z, hzβ©, (smul_eq_zero_iff_eq z).mp hzβ© },
split,
{ intro hxy,
cases mem_span_singleton.mp (by { rw [hxy], apply mem_span_singleton_self }) with v hv,
cases mem_span_singleton.mp (by { rw [β hxy], apply mem_span_singleton_self }) with i hi,
have vi : v * i = 1 :=
by { rw [β one_smul R y, β hi, smul_smul] at hv, exact smul_left_injective R hy hv },
have iv : i * v = 1 :=
by { rw [β one_smul R x, β hv, smul_smul] at hi, exact smul_left_injective R hx hi },
exact β¨β¨v, i, vi, ivβ©, hvβ© },
{ rintro β¨v, rflβ©,
rw span_singleton_group_smul_eq }
end
@[simp] lemma span_image [ring_hom_surjective Οββ] (f : M βββ[Οββ] Mβ) :
span Rβ (f '' s) = map f (span R s) :=
(map_span f s).symm
lemma apply_mem_span_image_of_mem_span
[ring_hom_surjective Οββ] (f : M βββ[Οββ] Mβ) {x : M} {s : set M} (h : x β submodule.span R s) :
f x β submodule.span Rβ (f '' s) :=
begin
rw submodule.span_image,
exact submodule.mem_map_of_mem h
end
@[simp] lemma map_subtype_span_singleton {p : submodule R M} (x : p) :
map p.subtype (R β x) = R β (x : M) :=
by simp [β span_image]
/-- `f` is an explicit argument so we can `apply` this theorem and obtain `h` as a new goal. -/
lemma not_mem_span_of_apply_not_mem_span_image
[ring_hom_surjective Οββ] (f : M βββ[Οββ] Mβ) {x : M} {s : set M}
(h : f x β submodule.span Rβ (f '' s)) :
x β submodule.span R s :=
h.imp (apply_mem_span_image_of_mem_span f)
lemma supr_span {ΞΉ : Sort*} (p : ΞΉ β set M) : (β¨ i, span R (p i)) = span R (β i, p i) :=
le_antisymm (supr_le $ Ξ» i, span_mono $ subset_Union _ i) $
span_le.mpr $ Union_subset $ Ξ» i m hm, mem_supr_of_mem i $ subset_span hm
lemma supr_eq_span {ΞΉ : Sort*} (p : ΞΉ β submodule R M) : (β¨ i, p i) = span R (β i, β(p i)) :=
by simp_rw [β supr_span, span_eq]
lemma supr_to_add_submonoid {ΞΉ : Sort*} (p : ΞΉ β submodule R M) :
(β¨ i, p i).to_add_submonoid = β¨ i, (p i).to_add_submonoid :=
begin
refine le_antisymm (Ξ» x, _) (supr_le $ Ξ» i, to_add_submonoid_mono $ le_supr _ i),
simp_rw [supr_eq_span, add_submonoid.supr_eq_closure, mem_to_add_submonoid, coe_to_add_submonoid],
intros hx,
refine submodule.span_induction hx (Ξ» x hx, _) _ (Ξ» x y hx hy, _) (Ξ» r x hx, _),
{ exact add_submonoid.subset_closure hx },
{ exact add_submonoid.zero_mem _ },
{ exact add_submonoid.add_mem _ hx hy },
{ apply add_submonoid.closure_induction hx,
{ rintros x β¨_, β¨i, rflβ©, hix : x β p iβ©,
apply add_submonoid.subset_closure (set.mem_Union.mpr β¨i, _β©),
exact smul_mem _ r hix },
{ rw smul_zero,
exact add_submonoid.zero_mem _ },
{ intros x y hx hy,
rw smul_add,
exact add_submonoid.add_mem _ hx hy, } }
end
/-- An induction principle for elements of `β¨ i, p i`.
If `C` holds for `0` and all elements of `p i` for all `i`, and is preserved under addition,
then it holds for all elements of the supremum of `p`. -/
@[elab_as_eliminator]
lemma supr_induction {ΞΉ : Sort*} (p : ΞΉ β submodule R M) {C : M β Prop} {x : M} (hx : x β β¨ i, p i)
(hp : β i (x β p i), C x)
(h0 : C 0)
(hadd : β x y, C x β C y β C (x + y)) : C x :=
begin
rw [βmem_to_add_submonoid, supr_to_add_submonoid] at hx,
exact add_submonoid.supr_induction _ hx hp h0 hadd,
end
/-- A dependent version of `submodule.supr_induction`. -/
@[elab_as_eliminator]
lemma supr_induction' {ΞΉ : Sort*} (p : ΞΉ β submodule R M) {C : Ξ x, (x β β¨ i, p i) β Prop}
(hp : β i (x β p i), C x (mem_supr_of_mem i βΉ_βΊ))
(h0 : C 0 (zero_mem _))
(hadd : β x y hx hy, C x hx β C y hy β C (x + y) (add_mem βΉ_βΊ βΉ_βΊ))
{x : M} (hx : x β β¨ i, p i) : C x hx :=
begin
refine exists.elim _ (Ξ» (hx : x β β¨ i, p i) (hc : C x hx), hc),
refine supr_induction p hx (Ξ» i x hx, _) _ (Ξ» x y, _),
{ exact β¨_, hp _ _ hxβ© },
{ exact β¨_, h0β© },
{ rintro β¨_, Cxβ© β¨_, Cyβ©,
refine β¨_, hadd _ _ _ _ Cx Cyβ© },
end
@[simp] lemma span_singleton_le_iff_mem (m : M) (p : submodule R M) : (R β m) β€ p β m β p :=
by rw [span_le, singleton_subset_iff, set_like.mem_coe]
lemma singleton_span_is_compact_element (x : M) :
complete_lattice.is_compact_element (span R {x} : submodule R M) :=
begin
rw complete_lattice.is_compact_element_iff_le_of_directed_Sup_le,
intros d hemp hdir hsup,
have : x β Sup d, from (set_like.le_def.mp hsup) (mem_span_singleton_self x),
obtain β¨y, β¨hyd, hxyβ©β© := (mem_Sup_of_directed hemp hdir).mp this,
exact β¨y, β¨hyd, by simpa only [span_le, singleton_subset_iff]β©β©,
end
/-- The span of a finite subset is compact in the lattice of submodules. -/
lemma finset_span_is_compact_element (S : finset M) :
complete_lattice.is_compact_element (span R S : submodule R M) :=
begin
rw span_eq_supr_of_singleton_spans,
simp only [finset.mem_coe],
rw βfinset.sup_eq_supr,
exact complete_lattice.finset_sup_compact_of_compact S
(Ξ» x _, singleton_span_is_compact_element x),
end
/-- The span of a finite subset is compact in the lattice of submodules. -/
lemma finite_span_is_compact_element (S : set M) (h : S.finite) :
complete_lattice.is_compact_element (span R S : submodule R M) :=
finite.coe_to_finset h βΈ (finset_span_is_compact_element h.to_finset)
instance : is_compactly_generated (submodule R M) :=
β¨Ξ» s, β¨(Ξ» x, span R {x}) '' s, β¨Ξ» t ht, begin
rcases (set.mem_image _ _ _).1 ht with β¨x, hx, rflβ©,
apply singleton_span_is_compact_element,
end, by rw [Sup_eq_supr, supr_image, βspan_eq_supr_of_singleton_spans, span_eq]β©β©β©
/-- A submodule is equal to the supremum of the spans of the submodule's nonzero elements. -/
lemma submodule_eq_Sup_le_nonzero_spans (p : submodule R M) :
p = Sup {T : submodule R M | β (m : M) (hm : m β p) (hz : m β 0), T = span R {m}} :=
begin
let S := {T : submodule R M | β (m : M) (hm : m β p) (hz : m β 0), T = span R {m}},
apply le_antisymm,
{ intros m hm, by_cases h : m = 0,
{ rw h, simp },
{ exact @le_Sup _ _ S _ β¨m, β¨hm, β¨h, rflβ©β©β© m (mem_span_singleton_self m) } },
{ rw Sup_le_iff, rintros S β¨_, β¨_, β¨_, rflβ©β©β©, rwa span_singleton_le_iff_mem }
end
lemma lt_sup_iff_not_mem {I : submodule R M} {a : M} : I < I β (R β a) β a β I :=
begin
split,
{ intro h,
by_contra akey,
have h1 : I β (R β a) β€ I,
{ simp only [sup_le_iff],
split,
{ exact le_refl I, },
{ exact (span_singleton_le_iff_mem a I).mpr akey, } },
have h2 := gt_of_ge_of_gt h1 h,
exact lt_irrefl I h2, },
{ intro h,
apply set_like.lt_iff_le_and_exists.mpr, split,
simp only [le_sup_left],
use a,
split, swap, { assumption, },
{ have : (R β a) β€ I β (R β a) := le_sup_right,
exact this (mem_span_singleton_self a), } },
end
lemma mem_supr {ΞΉ : Sort*} (p : ΞΉ β submodule R M) {m : M} :
(m β β¨ i, p i) β (β N, (β i, p i β€ N) β m β N) :=
begin
rw [β span_singleton_le_iff_mem, le_supr_iff],
simp only [span_singleton_le_iff_mem],
end
section
open_locale classical
/-- For every element in the span of a set, there exists a finite subset of the set
such that the element is contained in the span of the subset. -/
lemma mem_span_finite_of_mem_span {S : set M} {x : M} (hx : x β span R S) :
β T : finset M, βT β S β§ x β span R (T : set M) :=
begin
refine span_induction hx (Ξ» x hx, _) _ _ _,
{ refine β¨{x}, _, _β©,
{ rwa [finset.coe_singleton, set.singleton_subset_iff] },
{ rw finset.coe_singleton,
exact submodule.mem_span_singleton_self x } },
{ use β
, simp },
{ rintros x y β¨X, hX, hxXβ© β¨Y, hY, hyYβ©,
refine β¨X βͺ Y, _, _β©,
{ rw finset.coe_union,
exact set.union_subset hX hY },
rw [finset.coe_union, span_union, mem_sup],
exact β¨x, hxX, y, hyY, rflβ©, },
{ rintros a x β¨T, hT, h2β©,
exact β¨T, hT, smul_mem _ _ h2β© }
end
end
variables {M' : Type*} [add_comm_monoid M'] [module R M'] (qβ qβ' : submodule R M')
/-- The product of two submodules is a submodule. -/
def prod : submodule R (M Γ M') :=
{ carrier := p ΓΛ’ qβ,
smul_mem' := by rintro a β¨x, yβ© β¨hx, hyβ©; exact β¨smul_mem _ a hx, smul_mem _ a hyβ©,
.. p.to_add_submonoid.prod qβ.to_add_submonoid }
@[simp] lemma prod_coe : (prod p qβ : set (M Γ M')) = p ΓΛ’ qβ := rfl
@[simp] lemma mem_prod {p : submodule R M} {q : submodule R M'} {x : M Γ M'} :
x β prod p q β x.1 β p β§ x.2 β q := set.mem_prod
lemma span_prod_le (s : set M) (t : set M') :
span R (s ΓΛ’ t) β€ prod (span R s) (span R t) :=
span_le.2 $ set.prod_mono subset_span subset_span
@[simp] lemma prod_top : (prod β€ β€ : submodule R (M Γ M')) = β€ :=
by ext; simp
@[simp] lemma prod_bot : (prod β₯ β₯ : submodule R (M Γ M')) = β₯ :=
by ext β¨x, yβ©; simp [prod.zero_eq_mk]
lemma prod_mono {p p' : submodule R M} {q q' : submodule R M'} :
p β€ p' β q β€ q' β prod p q β€ prod p' q' := prod_mono
@[simp] lemma prod_inf_prod : prod p qβ β prod p' qβ' = prod (p β p') (qβ β qβ') :=
set_like.coe_injective set.prod_inter_prod
@[simp] lemma prod_sup_prod : prod p qβ β prod p' qβ' = prod (p β p') (qβ β qβ') :=
begin
refine le_antisymm (sup_le
(prod_mono le_sup_left le_sup_left)
(prod_mono le_sup_right le_sup_right)) _,
simp [set_like.le_def], intros xx yy hxx hyy,
rcases mem_sup.1 hxx with β¨x, hx, x', hx', rflβ©,
rcases mem_sup.1 hyy with β¨y, hy, y', hy', rflβ©,
refine mem_sup.2 β¨(x, y), β¨hx, hyβ©, (x', y'), β¨hx', hy'β©, rflβ©
end
end add_comm_monoid
section add_comm_group
variables [ring R] [add_comm_group M] [module R M]
@[simp] lemma span_neg (s : set M) : span R (-s) = span R s :=
calc span R (-s) = span R ((-linear_map.id : M ββ[R] M) '' s) : by simp
... = map (-linear_map.id) (span R s) : ((-linear_map.id).map_span _).symm
... = span R s : by simp
lemma mem_span_insert' {x y} {s : set M} : x β span R (insert y s) β β(a:R), x + a β’ y β span R s :=
begin
rw mem_span_insert, split,
{ rintro β¨a, z, hz, rflβ©, exact β¨-a, by simp [hz, add_assoc]β© },
{ rintro β¨a, hβ©, exact β¨-a, _, h, by simp [add_comm, add_left_comm]β© }
end
instance : is_modular_lattice (submodule R M) :=
β¨Ξ» x y z xz a ha, begin
rw [mem_inf, mem_sup] at ha,
rcases ha with β¨β¨b, hb, c, hc, rflβ©, hazβ©,
rw mem_sup,
refine β¨b, hb, c, mem_inf.2 β¨hc, _β©, rflβ©,
rw [β add_sub_cancel c b, add_comm],
apply z.sub_mem haz (xz hb),
endβ©
end add_comm_group
section add_comm_group
variables [semiring R] [semiring Rβ]
variables [add_comm_group M] [module R M] [add_comm_group Mβ] [module Rβ Mβ]
variables {Οββ : R β+* Rβ} [ring_hom_surjective Οββ]
variables {F : Type*} [sc : semilinear_map_class F Οββ M Mβ]
include sc
lemma comap_map_eq (f : F) (p : submodule R M) :
comap f (map f p) = p β (linear_map.ker f) :=
begin
refine le_antisymm _ (sup_le (le_comap_map _ _) (comap_mono bot_le)),
rintro x β¨y, hy, eβ©,
exact mem_sup.2 β¨y, hy, x - y, by simpa using sub_eq_zero.2 e.symm, by simpβ©
end
lemma comap_map_eq_self {f : F} {p : submodule R M} (h : linear_map.ker f β€ p) :
comap f (map f p) = p :=
by rw [submodule.comap_map_eq, sup_of_le_left h]
omit sc
end add_comm_group
end submodule
namespace linear_map
open submodule function
section add_comm_group
variables [semiring R] [semiring Rβ]
variables [add_comm_group M] [add_comm_group Mβ]
variables [module R M] [module Rβ Mβ]
variables {Οββ : R β+* Rβ} [ring_hom_surjective Οββ]
variables {F : Type*} [sc : semilinear_map_class F Οββ M Mβ]
include R
include sc
protected lemma map_le_map_iff (f : F) {p p'} : map f p β€ map f p' β p β€ p' β ker f :=
by rw [map_le_iff_le_comap, submodule.comap_map_eq]
theorem map_le_map_iff' {f : F} (hf : ker f = β₯) {p p'} :
map f p β€ map f p' β p β€ p' :=
by rw [linear_map.map_le_map_iff, hf, sup_bot_eq]
theorem map_injective {f : F} (hf : ker f = β₯) : injective (map f) :=
Ξ» p p' h, le_antisymm ((map_le_map_iff' hf).1 (le_of_eq h)) ((map_le_map_iff' hf).1 (ge_of_eq h))
theorem map_eq_top_iff {f : F} (hf : range f = β€) {p : submodule R M} :
p.map f = β€ β p β linear_map.ker f = β€ :=
by simp_rw [β top_le_iff, β hf, range_eq_map, linear_map.map_le_map_iff]
end add_comm_group
section
variables (R) (M) [semiring R] [add_comm_monoid M] [module R M]
/-- Given an element `x` of a module `M` over `R`, the natural map from
`R` to scalar multiples of `x`.-/
@[simps] def to_span_singleton (x : M) : R ββ[R] M := linear_map.id.smul_right x
/-- The range of `to_span_singleton x` is the span of `x`.-/
lemma span_singleton_eq_range (x : M) : (R β x) = (to_span_singleton R M x).range :=
submodule.ext $ Ξ» y, by {refine iff.trans _ linear_map.mem_range.symm, exact mem_span_singleton }
@[simp] lemma to_span_singleton_one (x : M) : to_span_singleton R M x 1 = x := one_smul _ _
@[simp] lemma to_span_singleton_zero : to_span_singleton R M 0 = 0 := by { ext, simp, }
end
section add_comm_monoid
variables [semiring R] [add_comm_monoid M] [module R M]
variables [semiring Rβ] [add_comm_monoid Mβ] [module Rβ Mβ]
variables {Οββ : R β+* Rβ}
/-- If two linear maps are equal on a set `s`, then they are equal on `submodule.span s`.
See also `linear_map.eq_on_span'` for a version using `set.eq_on`. -/
lemma eq_on_span {s : set M} {f g : M βββ[Οββ] Mβ} (H : set.eq_on f g s) β¦xβ¦ (h : x β span R s) :
f x = g x :=
by apply span_induction h H; simp {contextual := tt}
/-- If two linear maps are equal on a set `s`, then they are equal on `submodule.span s`.
This version uses `set.eq_on`, and the hidden argument will expand to `h : x β (span R s : set M)`.
See `linear_map.eq_on_span` for a version that takes `h : x β span R s` as an argument. -/
lemma eq_on_span' {s : set M} {f g : M βββ[Οββ] Mβ} (H : set.eq_on f g s) :
set.eq_on f g (span R s : set M) :=
eq_on_span H
/-- If `s` generates the whole module and linear maps `f`, `g` are equal on `s`, then they are
equal. -/
lemma ext_on {s : set M} {f g : M βββ[Οββ] Mβ} (hv : span R s = β€) (h : set.eq_on f g s) :
f = g :=
linear_map.ext (Ξ» x, eq_on_span h (eq_top_iff'.1 hv _))
/-- If the range of `v : ΞΉ β M` generates the whole module and linear maps `f`, `g` are equal at
each `v i`, then they are equal. -/
lemma ext_on_range {ΞΉ : Type*} {v : ΞΉ β M} {f g : M βββ[Οββ] Mβ} (hv : span R (set.range v) = β€)
(h : βi, f (v i) = g (v i)) : f = g :=
ext_on hv (set.forall_range_iff.2 h)
end add_comm_monoid
section field
variables {K V} [field K] [add_comm_group V] [module K V]
noncomputable theory
open_locale classical
lemma span_singleton_sup_ker_eq_top (f : V ββ[K] K) {x : V} (hx : f x β 0) :
(K β x) β f.ker = β€ :=
eq_top_iff.2 (Ξ» y hy, submodule.mem_sup.2 β¨(f y * (f x)β»ΒΉ) β’ x,
submodule.mem_span_singleton.2 β¨f y * (f x)β»ΒΉ, rflβ©,
β¨y - (f y * (f x)β»ΒΉ) β’ x,
by rw [linear_map.mem_ker, f.map_sub, f.map_smul, smul_eq_mul, mul_assoc,
inv_mul_cancel hx, mul_one, sub_self],
by simp only [add_sub_cancel'_right]β©β©)
variables (K V)
lemma ker_to_span_singleton {x : V} (h : x β 0) : (to_span_singleton K V x).ker = β₯ :=
begin
ext c, split,
{ intros hc, rw submodule.mem_bot, rw mem_ker at hc, by_contra hc',
have : x = 0,
calc x = cβ»ΒΉ β’ (c β’ x) : by rw [β mul_smul, inv_mul_cancel hc', one_smul]
... = cβ»ΒΉ β’ ((to_span_singleton K V x) c) : rfl
... = 0 : by rw [hc, smul_zero],
tauto },
{ rw [mem_ker, submodule.mem_bot], intros h, rw h, simp }
end
end field
end linear_map
open linear_map
namespace linear_equiv
section field
variables (K V) [field K] [add_comm_group V] [module K V]
/-- Given a nonzero element `x` of a vector space `V` over a field `K`, the natural
map from `K` to the span of `x`, with invertibility check to consider it as an
isomorphism.-/
def to_span_nonzero_singleton (x : V) (h : x β 0) : K ββ[K] (K β x) :=
linear_equiv.trans
(linear_equiv.of_injective
(linear_map.to_span_singleton K V x) (ker_eq_bot.1 $ linear_map.ker_to_span_singleton K V h))
(linear_equiv.of_eq (to_span_singleton K V x).range (K β x)
(span_singleton_eq_range K V x).symm)
lemma to_span_nonzero_singleton_one (x : V) (h : x β 0) :
linear_equiv.to_span_nonzero_singleton K V x h 1 =
(β¨x, submodule.mem_span_singleton_self xβ© : K β x) :=
begin
apply set_like.coe_eq_coe.mp,
have : β(to_span_nonzero_singleton K V x h 1) = to_span_singleton K V x 1 := rfl,
rw [this, to_span_singleton_one, submodule.coe_mk],
end
/-- Given a nonzero element `x` of a vector space `V` over a field `K`, the natural map
from the span of `x` to `K`.-/
abbreviation coord (x : V) (h : x β 0) : (K β x) ββ[K] K :=
(to_span_nonzero_singleton K V x h).symm
lemma coord_self (x : V) (h : x β 0) :
(coord K V x h) (β¨x, submodule.mem_span_singleton_self xβ© : K β x) = 1 :=
by rw [β to_span_nonzero_singleton_one K V x h, linear_equiv.symm_apply_apply]
end field
end linear_equiv
|
74805452e23aca135cf3a12dddb0e9bbee3ef919
|
fa02ed5a3c9c0adee3c26887a16855e7841c668b
|
/src/linear_algebra/dual.lean
|
d89b4bf590847629b02f497ebf82151bfdaaab12
|
[
"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
| 24,717
|
lean
|
/-
Copyright (c) 2019 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin, Fabian GlΓΆckle
-/
import linear_algebra.finite_dimensional
import linear_algebra.projection
/-!
# Dual vector spaces
The dual space of an R-module M is the R-module of linear maps `M β R`.
## Main definitions
* `dual R M` defines the dual space of M over R.
* Given a basis for an `R`-module `M`, `basis.to_dual` produces a map from `M` to `dual R M`.
* Given families of vectors `e` and `Ξ΅`, `dual_pair e Ξ΅` states that these families have the
characteristic properties of a basis and a dual.
* `dual_annihilator W` is the submodule of `dual R M` where every element annihilates `W`.
## Main results
* `to_dual_equiv` : the linear equivalence between the dual module and primal module,
given a finite basis.
* `dual_pair.basis` and `dual_pair.eq_dual`: if `e` and `Ξ΅` form a dual pair, `e` is a basis and
`Ξ΅` is its dual basis.
* `quot_equiv_annihilator`: the quotient by a subspace is isomorphic to its dual annihilator.
## Notation
We sometimes use `V'` as local notation for `dual K V`.
## TODO
ErdΓΆs-Kaplansky theorem about the dimension of a dual vector space in case of infinite dimension.
-/
noncomputable theory
namespace module
variables (R : Type*) (M : Type*)
variables [comm_semiring R] [add_comm_monoid M] [module R M]
/-- The dual space of an R-module M is the R-module of linear maps `M β R`. -/
@[derive [add_comm_monoid, module R]] def dual := M ββ[R] R
instance {S : Type*} [comm_ring S] {N : Type*} [add_comm_group N] [module S N] :
add_comm_group (dual S N) := by {unfold dual, apply_instance}
namespace dual
instance : inhabited (dual R M) := by dunfold dual; apply_instance
instance : has_coe_to_fun (dual R M) := β¨_, linear_map.to_funβ©
/-- Maps a module M to the dual of the dual of M. See `module.erange_coe` and
`module.eval_equiv`. -/
def eval : M ββ[R] (dual R (dual R M)) := linear_map.flip linear_map.id
@[simp] lemma eval_apply (v : M) (a : dual R M) : eval R M v a = a v :=
begin
dunfold eval,
rw [linear_map.flip_apply, linear_map.id_apply]
end
variables {R M} {M' : Type*} [add_comm_monoid M'] [module R M']
/-- The transposition of linear maps, as a linear map from `M ββ[R] M'` to
`dual R M' ββ[R] dual R M`. -/
def transpose : (M ββ[R] M') ββ[R] (dual R M' ββ[R] dual R M) :=
(linear_map.llcomp R M M' R).flip
lemma transpose_apply (u : M ββ[R] M') (l : dual R M') : transpose u l = l.comp u := rfl
variables {M'' : Type*} [add_comm_monoid M''] [module R M'']
lemma transpose_comp (u : M' ββ[R] M'') (v : M ββ[R] M') :
transpose (u.comp v) = (transpose v).comp (transpose u) := rfl
end dual
end module
namespace basis
universes u v w
open module module.dual submodule linear_map cardinal function
variables {R M K V ΞΉ : Type*}
section comm_semiring
variables [comm_semiring R] [add_comm_monoid M] [module R M] [decidable_eq ΞΉ]
variables (b : basis ΞΉ R M)
/-- The linear map from a vector space equipped with basis to its dual vector space,
taking basis elements to corresponding dual basis elements. -/
def to_dual : M ββ[R] module.dual R M :=
b.constr β $ Ξ» v, b.constr β $ Ξ» w, if w = v then (1 : R) else 0
lemma to_dual_apply (i j : ΞΉ) :
b.to_dual (b i) (b j) = if i = j then 1 else 0 :=
by { erw [constr_basis b, constr_basis b], ac_refl }
@[simp] lemma to_dual_total_left (f : ΞΉ ββ R) (i : ΞΉ) :
b.to_dual (finsupp.total ΞΉ M R b f) (b i) = f i :=
begin
rw [finsupp.total_apply, finsupp.sum, linear_map.map_sum, linear_map.sum_apply],
simp_rw [linear_map.map_smul, linear_map.smul_apply, to_dual_apply, smul_eq_mul,
mul_boole, finset.sum_ite_eq'],
split_ifs with h,
{ refl },
{ rw finsupp.not_mem_support_iff.mp h }
end
@[simp] lemma to_dual_total_right (f : ΞΉ ββ R) (i : ΞΉ) :
b.to_dual (b i) (finsupp.total ΞΉ M R b f) = f i :=
begin
rw [finsupp.total_apply, finsupp.sum, linear_map.map_sum],
simp_rw [linear_map.map_smul, to_dual_apply, smul_eq_mul, mul_boole, finset.sum_ite_eq],
split_ifs with h,
{ refl },
{ rw finsupp.not_mem_support_iff.mp h }
end
lemma to_dual_apply_left (m : M) (i : ΞΉ) : b.to_dual m (b i) = b.repr m i :=
by rw [β b.to_dual_total_left, b.total_repr]
lemma to_dual_apply_right (i : ΞΉ) (m : M) : b.to_dual (b i) m = b.repr m i :=
by rw [β b.to_dual_total_right, b.total_repr]
lemma coe_to_dual_self (i : ΞΉ) : b.to_dual (b i) = b.coord i :=
by { ext, apply to_dual_apply_right }
/-- `h.to_dual_flip v` is the linear map sending `w` to `h.to_dual w v`. -/
def to_dual_flip (m : M) : (M ββ[R] R) := b.to_dual.flip m
lemma to_dual_flip_apply (mβ mβ : M) : b.to_dual_flip mβ mβ = b.to_dual mβ mβ := rfl
lemma to_dual_eq_repr (m : M) (i : ΞΉ) : b.to_dual m (b i) = b.repr m i :=
b.to_dual_apply_left m i
lemma to_dual_eq_equiv_fun [fintype ΞΉ] (m : M) (i : ΞΉ) : b.to_dual m (b i) = b.equiv_fun m i :=
by rw [b.equiv_fun_apply, to_dual_eq_repr]
lemma to_dual_inj (m : M) (a : b.to_dual m = 0) : m = 0 :=
begin
rw [β mem_bot R, β b.repr.ker, mem_ker, linear_equiv.coe_coe],
apply finsupp.ext,
intro b,
rw [β to_dual_eq_repr, a],
refl
end
theorem to_dual_ker : b.to_dual.ker = β₯ :=
ker_eq_bot'.mpr b.to_dual_inj
theorem to_dual_range [fin : fintype ΞΉ] : b.to_dual.range = β€ :=
begin
rw eq_top_iff',
intro f,
rw linear_map.mem_range,
let lin_comb : ΞΉ ββ R := finsupp.on_finset fin.elems (Ξ» i, f.to_fun (b i)) _,
{ use finsupp.total ΞΉ M R b lin_comb,
apply b.ext,
{ intros i,
rw [b.to_dual_eq_repr _ i, repr_total b],
{ refl } } },
{ intros a _,
apply fin.complete }
end
end comm_semiring
section comm_ring
variables [comm_ring R] [add_comm_group M] [module R M] [decidable_eq ΞΉ]
variables (b : basis ΞΉ R M)
/-- A vector space is linearly equivalent to its dual space. -/
@[simps]
def to_dual_equiv [fintype ΞΉ] : M ββ[R] (dual R M) :=
linear_equiv.of_bijective b.to_dual b.to_dual_ker b.to_dual_range
/-- Maps a basis for `V` to a basis for the dual space. -/
def dual_basis [fintype ΞΉ] : basis ΞΉ R (dual R M) :=
b.map b.to_dual_equiv
-- We use `j = i` to match `basis.repr_self`
lemma dual_basis_apply_self [fintype ΞΉ] (i j : ΞΉ) :
b.dual_basis i (b j) = if j = i then 1 else 0 :=
by { convert b.to_dual_apply i j using 2, rw @eq_comm _ j i }
lemma total_dual_basis [fintype ΞΉ] (f : ΞΉ ββ R) (i : ΞΉ) :
finsupp.total ΞΉ (dual R M) R b.dual_basis f (b i) = f i :=
begin
rw [finsupp.total_apply, finsupp.sum_fintype, linear_map.sum_apply],
{ simp_rw [linear_map.smul_apply, smul_eq_mul, dual_basis_apply_self, mul_boole,
finset.sum_ite_eq, if_pos (finset.mem_univ i)] },
{ intro, rw zero_smul },
end
lemma dual_basis_repr [fintype ΞΉ] (l : dual R M) (i : ΞΉ) :
b.dual_basis.repr l i = l (b i) :=
by rw [β total_dual_basis b, basis.total_repr b.dual_basis l]
lemma dual_basis_equiv_fun [fintype ΞΉ] (l : dual R M) (i : ΞΉ) :
b.dual_basis.equiv_fun l i = l (b i) :=
by rw [basis.equiv_fun_apply, dual_basis_repr]
lemma dual_basis_apply [fintype ΞΉ] (i : ΞΉ) (m : M) : b.dual_basis i m = b.repr m i :=
b.to_dual_apply_right i m
@[simp] lemma coe_dual_basis [fintype ΞΉ] :
βb.dual_basis = b.coord :=
by { ext i x, apply dual_basis_apply }
@[simp] lemma to_dual_to_dual [fintype ΞΉ] :
b.dual_basis.to_dual.comp b.to_dual = dual.eval R M :=
begin
refine b.ext (Ξ» i, b.dual_basis.ext (Ξ» j, _)),
rw [linear_map.comp_apply, to_dual_apply_left, coe_to_dual_self, β coe_dual_basis,
dual.eval_apply, basis.repr_self, finsupp.single_apply, dual_basis_apply_self]
end
theorem eval_ker {ΞΉ : Type*} (b : basis ΞΉ R M) :
(dual.eval R M).ker = β₯ :=
begin
rw ker_eq_bot',
intros m hm,
simp_rw [linear_map.ext_iff, dual.eval_apply, zero_apply] at hm,
exact (basis.forall_coord_eq_zero_iff _).mp (Ξ» i, hm (b.coord i))
end
lemma eval_range {ΞΉ : Type*} [fintype ΞΉ] (b : basis ΞΉ R M) :
(eval R M).range = β€ :=
begin
classical,
rw [β b.to_dual_to_dual, range_comp, b.to_dual_range, map_top, to_dual_range _],
apply_instance
end
/-- A module with a basis is linearly equivalent to the dual of its dual space. -/
def eval_equiv {ΞΉ : Type*} [fintype ΞΉ] (b : basis ΞΉ R M) : M ββ[R] dual R (dual R M) :=
linear_equiv.of_bijective (eval R M) b.eval_ker b.eval_range
@[simp] lemma eval_equiv_to_linear_map {ΞΉ : Type*} [fintype ΞΉ] (b : basis ΞΉ R M) :
(b.eval_equiv).to_linear_map = dual.eval R M := rfl
end comm_ring
/-- `simp` normal form version of `total_dual_basis` -/
@[simp] lemma total_coord [comm_ring R] [add_comm_group M] [module R M] [fintype ΞΉ]
(b : basis ΞΉ R M) (f : ΞΉ ββ R) (i : ΞΉ) :
finsupp.total ΞΉ (dual R M) R b.coord f (b i) = f i :=
by { haveI := classical.dec_eq ΞΉ, rw [β coe_dual_basis, total_dual_basis] }
-- TODO(jmc): generalize to rings, once `module.rank` is generalized
theorem dual_dim_eq [field K] [add_comm_group V] [module K V] [fintype ΞΉ] (b : basis ΞΉ K V) :
cardinal.lift (module.rank K V) = module.rank K (dual K V) :=
begin
classical,
have := linear_equiv.dim_eq_lift b.to_dual_equiv,
simp only [cardinal.lift_umax] at this,
rw [this, β cardinal.lift_umax],
apply cardinal.lift_id,
end
end basis
namespace module
variables {K V : Type*}
variables [field K] [add_comm_group V] [module K V]
open module module.dual submodule linear_map cardinal basis finite_dimensional
theorem eval_ker : (eval K V).ker = β₯ :=
by { classical, exact (basis.of_vector_space K V).eval_ker }
-- TODO(jmc): generalize to rings, once `module.rank` is generalized
theorem dual_dim_eq [finite_dimensional K V] :
cardinal.lift (module.rank K V) = module.rank K (dual K V) :=
(basis.of_vector_space K V).dual_dim_eq
lemma erange_coe [finite_dimensional K V] : (eval K V).range = β€ :=
by { classical, exact (basis.of_vector_space K V).eval_range }
variables (K V)
/-- A vector space is linearly equivalent to the dual of its dual space. -/
def eval_equiv [finite_dimensional K V] : V ββ[K] dual K (dual K V) :=
linear_equiv.of_bijective (eval K V) eval_ker (erange_coe)
variables {K V}
@[simp] lemma eval_equiv_to_linear_map [finite_dimensional K V] :
(eval_equiv K V).to_linear_map = dual.eval K V := rfl
end module
section dual_pair
open module
variables {R M ΞΉ : Type*}
variables [comm_ring R] [add_comm_group M] [module R M] [decidable_eq ΞΉ]
/-- `e` and `Ξ΅` have characteristic properties of a basis and its dual -/
@[nolint has_inhabited_instance]
structure dual_pair (e : ΞΉ β M) (Ξ΅ : ΞΉ β (dual R M)) :=
(eval : β i j : ΞΉ, Ξ΅ i (e j) = if i = j then 1 else 0)
(total : β {m : M}, (β i, Ξ΅ i m = 0) β m = 0)
[finite : β m : M, fintype {i | Ξ΅ i m β 0}]
end dual_pair
namespace dual_pair
open module module.dual linear_map function
variables {R M ΞΉ : Type*}
variables [comm_ring R] [add_comm_group M] [module R M]
variables {e : ΞΉ β M} {Ξ΅ : ΞΉ β dual R M}
/-- The coefficients of `v` on the basis `e` -/
def coeffs [decidable_eq ΞΉ] (h : dual_pair e Ξ΅) (m : M) : ΞΉ ββ R :=
{ to_fun := Ξ» i, Ξ΅ i m,
support := by { haveI := h.finite m, exact {i : ΞΉ | Ξ΅ i m β 0}.to_finset },
mem_support_to_fun := by {intro i, rw set.mem_to_finset, exact iff.rfl } }
@[simp] lemma coeffs_apply [decidable_eq ΞΉ] (h : dual_pair e Ξ΅) (m : M) (i : ΞΉ) :
h.coeffs m i = Ξ΅ i m := rfl
/-- linear combinations of elements of `e`.
This is a convenient abbreviation for `finsupp.total _ M R e l` -/
def lc {ΞΉ} (e : ΞΉ β M) (l : ΞΉ ββ R) : M := l.sum (Ξ» (i : ΞΉ) (a : R), a β’ (e i))
lemma lc_def (e : ΞΉ β M) (l : ΞΉ ββ R) : lc e l = finsupp.total _ _ _ e l := rfl
variables [decidable_eq ΞΉ] (h : dual_pair e Ξ΅)
include h
lemma dual_lc (l : ΞΉ ββ R) (i : ΞΉ) : Ξ΅ i (dual_pair.lc e l) = l i :=
begin
erw linear_map.map_sum,
simp only [h.eval, map_smul, smul_eq_mul],
rw finset.sum_eq_single i,
{ simp },
{ intros q q_in q_ne,
simp [q_ne.symm] },
{ intro p_not_in,
simp [finsupp.not_mem_support_iff.1 p_not_in] },
end
@[simp]
lemma coeffs_lc (l : ΞΉ ββ R) : h.coeffs (dual_pair.lc e l) = l :=
by { ext i, rw [h.coeffs_apply, h.dual_lc] }
/-- For any m : M n, \sum_{p β Q n} (Ξ΅ p m) β’ e p = m -/
@[simp]
lemma lc_coeffs (m : M) : dual_pair.lc e (h.coeffs m) = m :=
begin
refine eq_of_sub_eq_zero (h.total _),
intros i,
simp [-sub_eq_add_neg, linear_map.map_sub, h.dual_lc, sub_eq_zero]
end
/-- `(h : dual_pair e Ξ΅).basis` shows the family of vectors `e` forms a basis. -/
@[simps]
def basis : basis ΞΉ R M :=
basis.of_repr
{ to_fun := coeffs h,
inv_fun := lc e,
left_inv := lc_coeffs h,
right_inv := coeffs_lc h,
map_add' := Ξ» v w, by { ext i, exact (Ξ΅ i).map_add v w },
map_smul' := Ξ» c v, by { ext i, exact (Ξ΅ i).map_smul c v } }
@[simp] lemma coe_basis : βh.basis = e :=
by { ext i, rw basis.apply_eq_iff, ext j,
rw [h.basis_repr_apply, coeffs_apply, h.eval, finsupp.single_apply],
convert if_congr eq_comm rfl rfl } -- `convert` to get rid of a `decidable_eq` mismatch
lemma mem_of_mem_span {H : set ΞΉ} {x : M} (hmem : x β submodule.span R (e '' H)) :
β i : ΞΉ, Ξ΅ i x β 0 β i β H :=
begin
intros i hi,
rcases (finsupp.mem_span_image_iff_total _).mp hmem with β¨l, supp_l, rflβ©,
apply not_imp_comm.mp ((finsupp.mem_supported' _ _).mp supp_l i),
rwa [β lc_def, h.dual_lc] at hi
end
lemma coe_dual_basis [fintype ΞΉ] : βh.basis.dual_basis = Ξ΅ :=
funext (Ξ» i, h.basis.ext (Ξ» j, by rw [h.basis.dual_basis_apply_self, h.coe_basis, h.eval,
if_congr eq_comm rfl rfl]))
end dual_pair
namespace submodule
universes u v w
variables {R : Type u} {M : Type v} [comm_ring R] [add_comm_group M] [module R M]
variable {W : submodule R M}
/-- The `dual_restrict` of a submodule `W` of `M` is the linear map from the
dual of `M` to the dual of `W` such that the domain of each linear map is
restricted to `W`. -/
def dual_restrict (W : submodule R M) :
module.dual R M ββ[R] module.dual R W :=
linear_map.dom_restrict' W
@[simp] lemma dual_restrict_apply
(W : submodule R M) (Ο : module.dual R M) (x : W) :
W.dual_restrict Ο x = Ο (x : M) := rfl
/-- The `dual_annihilator` of a submodule `W` is the set of linear maps `Ο` such
that `Ο w = 0` for all `w β W`. -/
def dual_annihilator {R : Type u} {M : Type v} [comm_ring R] [add_comm_group M]
[module R M] (W : submodule R M) : submodule R $ module.dual R M :=
W.dual_restrict.ker
@[simp] lemma mem_dual_annihilator (Ο : module.dual R M) :
Ο β W.dual_annihilator β β w β W, Ο w = 0 :=
begin
refine linear_map.mem_ker.trans _,
simp_rw [linear_map.ext_iff, dual_restrict_apply],
exact β¨Ξ» h w hw, h β¨w, hwβ©, Ξ» h w, h w.1 w.2β©
end
lemma dual_restrict_ker_eq_dual_annihilator (W : submodule R M) :
W.dual_restrict.ker = W.dual_annihilator :=
rfl
lemma dual_annihilator_sup_eq_inf_dual_annihilator (U V : submodule R M) :
(U β V).dual_annihilator = U.dual_annihilator β V.dual_annihilator :=
begin
ext Ο,
rw [mem_inf, mem_dual_annihilator, mem_dual_annihilator, mem_dual_annihilator],
split; intro h,
{ refine β¨_, _β©;
intros x hx,
exact h x (mem_sup.2 β¨x, hx, 0, zero_mem _, add_zero _β©),
exact h x (mem_sup.2 β¨0, zero_mem _, x, hx, zero_add _β©) },
{ simp_rw mem_sup,
rintro _ β¨x, hx, y, hy, rflβ©,
rw [linear_map.map_add, h.1 _ hx, h.2 _ hy, add_zero] }
end
/-- The pullback of a submodule in the dual space along the evaluation map. -/
def dual_annihilator_comap (Ξ¦ : submodule R (module.dual R M)) : submodule R M :=
Ξ¦.dual_annihilator.comap (module.dual.eval R M)
lemma mem_dual_annihilator_comap_iff {Ξ¦ : submodule R (module.dual R M)} (x : M) :
x β Ξ¦.dual_annihilator_comap β β Ο β Ξ¦, (Ο x : R) = 0 :=
by simp_rw [dual_annihilator_comap, mem_comap, mem_dual_annihilator, module.dual.eval_apply]
end submodule
namespace subspace
open submodule linear_map
universes u v w
-- We work in vector spaces because `exists_is_compl` only hold for vector spaces
variables {K : Type u} {V : Type v} [field K] [add_comm_group V] [module K V]
/-- Given a subspace `W` of `V` and an element of its dual `Ο`, `dual_lift W Ο` is
the natural extension of `Ο` to an element of the dual of `V`.
That is, `dual_lift W Ο` sends `w β W` to `Ο x` and `x` in the complement of `W` to `0`. -/
noncomputable def dual_lift (W : subspace K V) :
module.dual K W ββ[K] module.dual K V :=
let h := classical.indefinite_description _ W.exists_is_compl in
(linear_map.of_is_compl_prod h.2).comp (linear_map.inl _ _ _)
variable {W : subspace K V}
@[simp] lemma dual_lift_of_subtype {Ο : module.dual K W} (w : W) :
W.dual_lift Ο (w : V) = Ο w :=
by { erw of_is_compl_left_apply _ w, refl }
lemma dual_lift_of_mem {Ο : module.dual K W} {w : V} (hw : w β W) :
W.dual_lift Ο w = Ο β¨w, hwβ© :=
dual_lift_of_subtype β¨w, hwβ©
@[simp] lemma dual_restrict_comp_dual_lift (W : subspace K V) :
W.dual_restrict.comp W.dual_lift = 1 :=
by { ext Ο x, simp }
lemma dual_restrict_left_inverse (W : subspace K V) :
function.left_inverse W.dual_restrict W.dual_lift :=
Ξ» x, show W.dual_restrict.comp W.dual_lift x = x,
by { rw [dual_restrict_comp_dual_lift], refl }
lemma dual_lift_right_inverse (W : subspace K V) :
function.right_inverse W.dual_lift W.dual_restrict :=
W.dual_restrict_left_inverse
lemma dual_restrict_surjective :
function.surjective W.dual_restrict :=
W.dual_lift_right_inverse.surjective
lemma dual_lift_injective : function.injective W.dual_lift :=
W.dual_restrict_left_inverse.injective
/-- The quotient by the `dual_annihilator` of a subspace is isomorphic to the
dual of that subspace. -/
noncomputable def quot_annihilator_equiv (W : subspace K V) :
W.dual_annihilator.quotient ββ[K] module.dual K W :=
(quot_equiv_of_eq _ _ W.dual_restrict_ker_eq_dual_annihilator).symm.trans $
W.dual_restrict.quot_ker_equiv_of_surjective dual_restrict_surjective
/-- The natural isomorphism forom the dual of a subspace `W` to `W.dual_lift.range`. -/
noncomputable def dual_equiv_dual (W : subspace K V) :
module.dual K W ββ[K] W.dual_lift.range :=
linear_equiv.of_injective _ $ ker_eq_bot.2 dual_lift_injective
lemma dual_equiv_dual_def (W : subspace K V) :
W.dual_equiv_dual.to_linear_map = W.dual_lift.range_restrict := rfl
@[simp] lemma dual_equiv_dual_apply (Ο : module.dual K W) :
W.dual_equiv_dual Ο = β¨W.dual_lift Ο, mem_range.2 β¨Ο, rflβ©β© := rfl
section
open_locale classical
open finite_dimensional
variables {Vβ : Type*} [add_comm_group Vβ] [module K Vβ]
instance [H : finite_dimensional K V] : finite_dimensional K (module.dual K V) :=
linear_equiv.finite_dimensional (basis.of_vector_space K V).to_dual_equiv
variables [finite_dimensional K V] [finite_dimensional K Vβ]
@[simp] lemma dual_finrank_eq :
finrank K (module.dual K V) = finrank K V :=
linear_equiv.finrank_eq (basis.of_vector_space K V).to_dual_equiv.symm
/-- The quotient by the dual is isomorphic to its dual annihilator. -/
noncomputable def quot_dual_equiv_annihilator (W : subspace K V) :
W.dual_lift.range.quotient ββ[K] W.dual_annihilator :=
linear_equiv.quot_equiv_of_quot_equiv $
linear_equiv.trans W.quot_annihilator_equiv W.dual_equiv_dual
/-- The quotient by a subspace is isomorphic to its dual annihilator. -/
noncomputable def quot_equiv_annihilator (W : subspace K V) :
W.quotient ββ[K] W.dual_annihilator :=
begin
refine linear_equiv.trans _ W.quot_dual_equiv_annihilator,
refine linear_equiv.quot_equiv_of_equiv _ (basis.of_vector_space K V).to_dual_equiv,
exact (basis.of_vector_space K W).to_dual_equiv.trans W.dual_equiv_dual
end
open finite_dimensional
@[simp]
lemma finrank_dual_annihilator_comap_eq {Ξ¦ : subspace K (module.dual K V)} :
finrank K Ξ¦.dual_annihilator_comap = finrank K Ξ¦.dual_annihilator :=
begin
rw [submodule.dual_annihilator_comap, β module.eval_equiv_to_linear_map],
exact linear_equiv.finrank_eq (linear_equiv.of_submodule' _ _),
end
lemma finrank_add_finrank_dual_annihilator_comap_eq
(W : subspace K (module.dual K V)) :
finrank K W + finrank K W.dual_annihilator_comap = finrank K V :=
begin
rw [finrank_dual_annihilator_comap_eq, W.quot_equiv_annihilator.finrank_eq.symm, add_comm,
submodule.finrank_quotient_add_finrank, subspace.dual_finrank_eq],
end
end
end subspace
variables {R : Type*} [comm_ring R] {Mβ : Type*} {Mβ : Type*}
variables [add_comm_group Mβ] [module R Mβ] [add_comm_group Mβ] [module R Mβ]
open module
/-- Given a linear map `f : Mβ ββ[R] Mβ`, `f.dual_map` is the linear map between the dual of
`Mβ` and `Mβ` such that it maps the functional `Ο` to `Ο β f`. -/
def linear_map.dual_map (f : Mβ ββ[R] Mβ) : dual R Mβ ββ[R] dual R Mβ :=
linear_map.lcomp R R f
@[simp] lemma linear_map.dual_map_apply (f : Mβ ββ[R] Mβ) (g : dual R Mβ) (x : Mβ) :
f.dual_map g x = g (f x) :=
linear_map.lcomp_apply f g x
@[simp] lemma linear_map.dual_map_id :
(linear_map.id : Mβ ββ[R] Mβ).dual_map = linear_map.id :=
by { ext, refl }
lemma linear_map.dual_map_comp_dual_map {Mβ : Type*} [add_comm_group Mβ] [module R Mβ]
(f : Mβ ββ[R] Mβ) (g : Mβ ββ[R] Mβ) :
f.dual_map.comp g.dual_map = (g.comp f).dual_map :=
rfl
/-- The `linear_equiv` version of `linear_map.dual_map`. -/
def linear_equiv.dual_map (f : Mβ ββ[R] Mβ) : dual R Mβ ββ[R] dual R Mβ :=
{ inv_fun := f.symm.to_linear_map.dual_map,
left_inv :=
begin
intro Ο, ext x,
simp only [linear_map.dual_map_apply, linear_equiv.coe_to_linear_map,
linear_map.to_fun_eq_coe, linear_equiv.apply_symm_apply]
end,
right_inv :=
begin
intro Ο, ext x,
simp only [linear_map.dual_map_apply, linear_equiv.coe_to_linear_map,
linear_map.to_fun_eq_coe, linear_equiv.symm_apply_apply]
end,
.. f.to_linear_map.dual_map }
@[simp] lemma linear_equiv.dual_map_apply (f : Mβ ββ[R] Mβ) (g : dual R Mβ) (x : Mβ) :
f.dual_map g x = g (f x) :=
linear_map.lcomp_apply f g x
@[simp] lemma linear_equiv.dual_map_refl :
(linear_equiv.refl R Mβ).dual_map = linear_equiv.refl R (dual R Mβ) :=
by { ext, refl }
@[simp] lemma linear_equiv.dual_map_symm {f : Mβ ββ[R] Mβ} :
(linear_equiv.dual_map f).symm = linear_equiv.dual_map f.symm := rfl
lemma linear_equiv.dual_map_trans {Mβ : Type*} [add_comm_group Mβ] [module R Mβ]
(f : Mβ ββ[R] Mβ) (g : Mβ ββ[R] Mβ) :
g.dual_map.trans f.dual_map = (f.trans g).dual_map :=
rfl
namespace linear_map
variable (f : Mβ ββ[R] Mβ)
lemma ker_dual_map_eq_dual_annihilator_range :
f.dual_map.ker = f.range.dual_annihilator :=
begin
ext Ο, split; intro hΟ,
{ rw mem_ker at hΟ,
rw submodule.mem_dual_annihilator,
rintro y β¨x, rflβ©,
rw [β dual_map_apply, hΟ, zero_apply] },
{ ext x,
rw dual_map_apply,
rw submodule.mem_dual_annihilator at hΟ,
exact hΟ (f x) β¨x, rflβ© }
end
lemma range_dual_map_le_dual_annihilator_ker :
f.dual_map.range β€ f.ker.dual_annihilator :=
begin
rintro _ β¨Ο, rflβ©,
simp_rw [submodule.mem_dual_annihilator, mem_ker],
rintro x hx,
rw [dual_map_apply, hx, map_zero]
end
section finite_dimensional
variables {K : Type*} [field K] {Vβ : Type*} {Vβ : Type*}
variables [add_comm_group Vβ] [module K Vβ] [add_comm_group Vβ] [module K Vβ]
open finite_dimensional
variable [finite_dimensional K Vβ]
@[simp] lemma finrank_range_dual_map_eq_finrank_range (f : Vβ ββ[K] Vβ) :
finrank K f.dual_map.range = finrank K f.range :=
begin
have := submodule.finrank_quotient_add_finrank f.range,
rw [(subspace.quot_equiv_annihilator f.range).finrank_eq,
β ker_dual_map_eq_dual_annihilator_range] at this,
conv_rhs at this { rw β subspace.dual_finrank_eq },
refine add_left_injective (finrank K f.dual_map.ker) _,
change _ + _ = _ + _,
rw [finrank_range_add_finrank_ker f.dual_map, add_comm, this],
end
lemma range_dual_map_eq_dual_annihilator_ker [finite_dimensional K Vβ] (f : Vβ ββ[K] Vβ) :
f.dual_map.range = f.ker.dual_annihilator :=
begin
refine eq_of_le_of_finrank_eq f.range_dual_map_le_dual_annihilator_ker _,
have := submodule.finrank_quotient_add_finrank f.ker,
rw (subspace.quot_equiv_annihilator f.ker).finrank_eq at this,
refine add_left_injective (finrank K f.ker) _,
simp_rw [this, finrank_range_dual_map_eq_finrank_range],
exact finrank_range_add_finrank_ker f,
end
end finite_dimensional
end linear_map
|
7bf4e45c52715a76fbae151efcd019e4160eec96
|
4d2583807a5ac6caaffd3d7a5f646d61ca85d532
|
/src/computability/language.lean
|
da3e23981ef011b1cf67829972decd95e53827f3
|
[
"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
| 6,747
|
lean
|
/-
Copyright (c) 2020 Fox Thomson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Fox Thomson
-/
import algebra.group_power.order
import data.list.join
import data.set.lattice
/-!
# Languages
This file contains the definition and operations on formal languages over an alphabet. Note strings
are implemented as lists over the alphabet.
The operations in this file define a [Kleene algebra](https://en.wikipedia.org/wiki/Kleene_algebra)
over the languages.
-/
universes u v
variables {Ξ± : Type u}
/-- A language is a set of strings over an alphabet. -/
@[derive [has_mem (list Ξ±), has_singleton (list Ξ±), has_insert (list Ξ±), complete_boolean_algebra]]
def language (Ξ±) := set (list Ξ±)
namespace language
local attribute [reducible] language
/-- Zero language has no elements. -/
instance : has_zero (language Ξ±) := β¨(β
: set _)β©
/-- `1 : language Ξ±` contains only one element `[]`. -/
instance : has_one (language Ξ±) := β¨{[]}β©
instance : inhabited (language Ξ±) := β¨0β©
/-- The sum of two languages is the union of -/
instance : has_add (language Ξ±) := β¨set.unionβ©
instance : has_mul (language Ξ±) := β¨set.image2 (++)β©
lemma zero_def : (0 : language Ξ±) = (β
: set _) := rfl
lemma one_def : (1 : language Ξ±) = {[]} := rfl
lemma add_def (l m : language Ξ±) : l + m = l βͺ m := rfl
lemma mul_def (l m : language Ξ±) : l * m = set.image2 (++) l m := rfl
/-- The star of a language `L` is the set of all strings which can be written by concatenating
strings from `L`. -/
def star (l : language Ξ±) : language Ξ± :=
{ x | β S : list (list Ξ±), x = S.join β§ β y β S, y β l}
lemma star_def (l : language Ξ±) :
l.star = { x | β S : list (list Ξ±), x = S.join β§ β y β S, y β l} := rfl
@[simp] lemma mem_one (x : list Ξ±) : x β (1 : language Ξ±) β x = [] := by refl
@[simp] lemma mem_add (l m : language Ξ±) (x : list Ξ±) : x β l + m β x β l β¨ x β m :=
by simp [add_def]
lemma mem_mul (l m : language Ξ±) (x : list Ξ±) : x β l * m β β a b, a β l β§ b β m β§ a ++ b = x :=
by simp [mul_def]
lemma mem_star (l : language Ξ±) (x : list Ξ±) :
x β l.star β β S : list (list Ξ±), x = S.join β§ β y β S, y β l :=
iff.rfl
instance : semiring (language Ξ±) :=
{ add := (+),
add_assoc := set.union_assoc,
zero := 0,
zero_add := set.empty_union,
add_zero := set.union_empty,
add_comm := set.union_comm,
mul := (*),
mul_assoc := Ξ» l m n,
by simp only [mul_def, set.image2_image2_left, set.image2_image2_right, list.append_assoc],
zero_mul := by simp [zero_def, mul_def],
mul_zero := by simp [zero_def, mul_def],
one := 1,
one_mul := Ξ» l, by simp [mul_def, one_def],
mul_one := Ξ» l, by simp [mul_def, one_def],
left_distrib := Ξ» l m n, by simp only [mul_def, add_def, set.image2_union_right],
right_distrib := Ξ» l m n, by simp only [mul_def, add_def, set.image2_union_left] }
@[simp] lemma add_self (l : language Ξ±) : l + l = l := sup_idem
lemma star_def_nonempty (l : language Ξ±) :
l.star = {x | β S : list (list Ξ±), x = S.join β§ β y β S, y β l β§ y β []} :=
begin
ext x,
split,
{ rintro β¨S, rfl, hβ©,
refine β¨S.filter (Ξ» l, Β¬list.empty l), by simp, Ξ» y hy, _β©,
rw [list.mem_filter, list.empty_iff_eq_nil] at hy,
exact β¨h y hy.1, hy.2β© },
{ rintro β¨S, hx, hβ©,
exact β¨S, hx, Ξ» y hy, (h y hy).1β© }
end
lemma le_iff (l m : language Ξ±) : l β€ m β l + m = m := sup_eq_right.symm
lemma le_mul_congr {lβ lβ mβ mβ : language Ξ±} : lβ β€ mβ β lβ β€ mβ β lβ * lβ β€ mβ * mβ :=
begin
intros hβ hβ x hx,
simp only [mul_def, exists_and_distrib_left, set.mem_image2, set.image_prod] at hx β’,
tauto
end
lemma le_add_congr {lβ lβ mβ mβ : language Ξ±} : lβ β€ mβ β lβ β€ mβ β lβ + lβ β€ mβ + mβ := sup_le_sup
lemma mem_supr {ΞΉ : Sort v} {l : ΞΉ β language Ξ±} {x : list Ξ±} :
x β (β¨ i, l i) β β i, x β l i :=
set.mem_Union
lemma supr_mul {ΞΉ : Sort v} (l : ΞΉ β language Ξ±) (m : language Ξ±) :
(β¨ i, l i) * m = β¨ i, l i * m :=
set.image2_Union_left _ _ _
lemma mul_supr {ΞΉ : Sort v} (l : ΞΉ β language Ξ±) (m : language Ξ±) :
m * (β¨ i, l i) = β¨ i, m * l i :=
set.image2_Union_right _ _ _
lemma supr_add {ΞΉ : Sort v} [nonempty ΞΉ] (l : ΞΉ β language Ξ±) (m : language Ξ±) :
(β¨ i, l i) + m = β¨ i, l i + m := supr_sup
lemma add_supr {ΞΉ : Sort v} [nonempty ΞΉ] (l : ΞΉ β language Ξ±) (m : language Ξ±) :
m + (β¨ i, l i) = β¨ i, m + l i := sup_supr
lemma mem_pow {l : language Ξ±} {x : list Ξ±} {n : β} :
x β l ^ n β β S : list (list Ξ±), x = S.join β§ S.length = n β§ β y β S, y β l :=
begin
induction n with n ihn generalizing x,
{ simp only [mem_one, pow_zero, list.length_eq_zero],
split,
{ rintro rfl, exact β¨[], rfl, rfl, Ξ» y h, h.elimβ© },
{ rintro β¨_, rfl, rfl, _β©, refl } },
{ simp only [pow_succ, mem_mul, ihn],
split,
{ rintro β¨a, b, ha, β¨S, rfl, rfl, hSβ©, rflβ©,
exact β¨a :: S, rfl, rfl, list.forall_mem_cons.2 β¨ha, hSβ©β© },
{ rintro β¨_|β¨a, Sβ©, rfl, hn, hSβ©; cases hn,
rw list.forall_mem_cons at hS,
exact β¨a, _, hS.1, β¨S, rfl, rfl, hS.2β©, rflβ© } }
end
lemma star_eq_supr_pow (l : language Ξ±) : l.star = β¨ i : β, l ^ i :=
begin
ext x,
simp only [mem_star, mem_supr, mem_pow],
split,
{ rintro β¨S, rfl, hSβ©, exact β¨_, S, rfl, rfl, hSβ© },
{ rintro β¨_, S, rfl, rfl, hSβ©, exact β¨S, rfl, hSβ© }
end
lemma mul_self_star_comm (l : language Ξ±) : l.star * l = l * l.star :=
by simp only [star_eq_supr_pow, mul_supr, supr_mul, β pow_succ, β pow_succ']
@[simp] lemma one_add_self_mul_star_eq_star (l : language Ξ±) : 1 + l * l.star = l.star :=
begin
simp only [star_eq_supr_pow, mul_supr, β pow_succ, β pow_zero l],
exact sup_supr_nat_succ _
end
@[simp] lemma one_add_star_mul_self_eq_star (l : language Ξ±) : 1 + l.star * l = l.star :=
by rw [mul_self_star_comm, one_add_self_mul_star_eq_star]
lemma star_mul_le_right_of_mul_le_right (l m : language Ξ±) : l * m β€ m β l.star * m β€ m :=
begin
intro h,
rw [star_eq_supr_pow, supr_mul],
refine supr_le _,
intro n,
induction n with n ih,
{ simp },
rw [pow_succ', mul_assoc (l^n) l m],
exact le_trans (le_mul_congr (le_refl _) h) ih,
end
lemma star_mul_le_left_of_mul_le_left (l m : language Ξ±) : m * l β€ m β m * l.star β€ m :=
begin
intro h,
rw [star_eq_supr_pow, mul_supr],
refine supr_le _,
intro n,
induction n with n ih,
{ simp },
rw [pow_succ, βmul_assoc m l (l^n)],
exact le_trans (le_mul_congr h (le_refl _)) ih
end
end language
|
17ccf4b2387a994e651bb976f473799735a7e9c8
|
624f6f2ae8b3b1adc5f8f67a365c51d5126be45a
|
/tests/lean/run/meta2.lean
|
092de79beece71870661eaae814cddf7cb221710
|
[
"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
| 16,649
|
lean
|
import Init.Lean.Meta
open Lean
open Lean.Meta
set_option trace.Meta true
set_option trace.Meta.isDefEq.step false
set_option trace.Meta.isDefEq.delta false
set_option trace.Meta.isDefEq.assign false
def print (msg : MessageData) : MetaM Unit :=
trace! `Meta.debug msg
def check (x : MetaM Bool) : MetaM Unit :=
unlessM x $ throw $ Exception.other "check failed"
def getAssignment (m : Expr) : MetaM Expr :=
do v? β getExprMVarAssignment? m.mvarId!;
match v? with
| some v => pure v
| none => throw $ Exception.other "metavariable is not assigned"
def nat := mkConst `Nat
def boolE := mkConst `Bool
def succ := mkConst `Nat.succ
def zero := mkConst `Nat.zero
def add := mkConst `Nat.add
def io := mkConst `IO
def type := mkSort levelOne
def tst1 : MetaM Unit :=
do print "----- tst1 -----";
mvar β mkFreshExprMVar nat;
check $ isExprDefEq mvar (mkNatLit 10);
check $ isExprDefEq mvar (mkNatLit 10);
pure ()
#eval tst1
def tst2 : MetaM Unit :=
do print "----- tst2 -----";
mvar β mkFreshExprMVar nat;
check $ isExprDefEq (mkApp succ mvar) (mkApp succ (mkNatLit 10));
check $ isExprDefEq mvar (mkNatLit 10);
pure ()
#eval tst2
def tst3 : MetaM Unit :=
do print "----- tst3 -----";
let t := mkLambda `x BinderInfo.default nat $ mkBVar 0;
mvar β mkFreshExprMVar (mkForall `x BinderInfo.default nat nat);
lambdaTelescope t $ fun xs _ => do {
let x := xs.get! 0;
check $ isExprDefEq (mkApp mvar x) (mkAppN add #[x, mkAppN add #[mkNatLit 10, x]]);
pure ()
};
v β getAssignment mvar;
print v;
pure ()
#eval tst3
def tst4 : MetaM Unit :=
do print "----- tst4 -----";
let t := mkLambda `x BinderInfo.default nat $ mkBVar 0;
lambdaTelescope t $ fun xs _ => do {
let x := xs.get! 0;
mvar β mkFreshExprMVar (mkForall `x BinderInfo.default nat nat);
-- the following `isExprDefEq` fails because `x` is also in the context of `mvar`
check $ not <$> isExprDefEq (mkApp mvar x) (mkAppN add #[x, mkAppN add #[mkNatLit 10, x]]);
check $ approxDefEq $ isExprDefEq (mkApp mvar x) (mkAppN add #[x, mkAppN add #[mkNatLit 10, x]]);
v β getAssignment mvar;
print v;
pure ()
};
pure ()
#eval tst4
def mkAppC (c : Name) (xs : Array Expr) : MetaM Expr :=
do r β mkAppM c xs;
check r;
pure r
def mkProd (a b : Expr) : MetaM Expr := mkAppC `Prod #[a, b]
def mkPair (a b : Expr) : MetaM Expr := mkAppC `Prod.mk #[a, b]
def mkFst (s : Expr) : MetaM Expr := mkAppC `Prod.fst #[s]
def mkSnd (s : Expr) : MetaM Expr := mkAppC `Prod.snd #[s]
def mkId (a : Expr) : MetaM Expr := mkAppC `id #[a]
def tst5 : MetaM Unit :=
do print "----- tst5 -----";
pβ β mkPair (mkNatLit 1) (mkNatLit 2);
x β mkFst pβ;
print x;
v β whnf x;
print v;
v β withTransparency TransparencyMode.reducible $ whnf x;
print v;
x β mkId x;
print x;
prod β mkProd nat nat;
m β mkFreshExprMVar prod;
y β mkFst m;
check $ isExprDefEq y x;
print y
#eval tst5
def tst6 : MetaM Unit :=
do print "----- tst6 -----";
withLocalDecl `x nat BinderInfo.default $ fun x => do
m β mkFreshExprMVar nat;
let t := mkAppN add #[m, mkNatLit 4];
let s := mkAppN add #[x, mkNatLit 3];
check $ not <$> isExprDefEq t s;
let s := mkAppN add #[x, mkNatLit 6];
check $ isExprDefEq t s;
v β getAssignment m;
check $ pure $ v == mkAppN add #[x, mkNatLit 2];
print v;
m β mkFreshExprMVar nat;
let t := mkAppN add #[m, mkNatLit 4];
let s := mkNatLit 3;
check $ not <$> isExprDefEq t s;
let s := mkNatLit 10;
check $ isExprDefEq t s;
v β getAssignment m;
check $ pure $ v == mkNatLit 6;
print v;
pure ()
#eval tst6
def mkArrow (d b : Expr) : Expr := mkForall `_ BinderInfo.default d b
def tst7 : MetaM Unit :=
do print "----- tst7 -----";
withLocalDecl `x type BinderInfo.default $ fun x => do
m1 β mkFreshExprMVar (mkArrow type type);
m2 β mkFreshExprMVar type;
let t := mkApp io x;
-- we need to use foApprox to solve `?m1 ?m2 =?= IO x`
check $ not <$> isDefEq (mkApp m1 m2) t;
check $ approxDefEq $ isDefEq (mkApp m1 m2) t;
v β getAssignment m1;
check $ pure $ v == io;
v β getAssignment m2;
check $ pure $ v == x;
pure ()
#eval tst7
def tst8 : MetaM Unit :=
do print "----- tst8 -----";
let add := mkAppN (mkConst `HasAdd.add [levelOne]) #[nat, mkConst `Nat.HasAdd];
let t := mkAppN add #[mkNatLit 2, mkNatLit 3];
t β withTransparency TransparencyMode.reducible $ whnf t;
print t;
t β whnf t;
print t;
t β reduce t;
print t;
pure ()
#eval tst8
def tst9 : MetaM Unit :=
do print "----- tst9 -----";
env β getEnv;
print (toString $ Lean.isReducible env `Prod.fst);
print (toString $ Lean.isReducible env `HasAdd.add);
pure ()
#eval tst9
def tst10 : MetaM Unit :=
do print "----- tst10 -----";
t β withLocalDecl `x nat BinderInfo.default $ fun x => do {
let b := mkAppN add #[x, mkAppN add #[mkNatLit 2, mkNatLit 3]];
mkLambda #[x] b
};
print t;
t β reduce t;
print t;
pure ()
#eval tst10
def tst11 : MetaM Unit :=
do print "----- tst11 -----";
check $ isType nat;
check $ isType (mkArrow nat nat);
check $ not <$> isType add;
check $ not <$> isType (mkNatLit 1);
withLocalDecl `x nat BinderInfo.default $ fun x => do {
check $ not <$> isType x;
check $ not <$> (mkLambda #[x] x >>= isType);
check $ not <$> (mkLambda #[x] nat >>= isType);
t β mkEq x (mkNatLit 0) >>= mkForall #[x];
print t;
check $ isType t;
pure ()
};
pure ()
#eval tst11
def tst12 : MetaM Unit :=
do print "----- tst12 -----";
withLocalDecl `x nat BinderInfo.default $ fun x => do {
t β mkEqRefl x >>= mkLambda #[x];
print t;
type β inferType t;
print type;
isProofQuick t >>= fun b => print (toString b);
isProofQuick nat >>= fun b => print (toString b);
isProofQuick type >>= fun b => print (toString b);
pure ()
};
pure ()
#eval tst12
def tst13 : MetaM Unit :=
do print "----- tst13 -----";
mβ β mkFreshExprMVar (mkArrow type type);
mβ β mkFreshExprMVar (mkApp mβ nat);
t β mkId mβ;
print t;
r β abstractMVars t;
print r.expr;
(_, _, e) β openAbstractMVarsResult r;
print e;
pure ()
def mkDecEq (type : Expr) : MetaM Expr := mkAppC `DecidableEq #[type]
def mkStateM (Ο : Expr) : MetaM Expr := mkAppC `StateM #[Ο]
def mkMonad (m : Expr) : MetaM Expr := mkAppC `Monad #[m]
def mkMonadState (Ο m : Expr) : MetaM Expr := mkAppC `MonadState #[Ο, m]
def mkHasAdd (a : Expr) : MetaM Expr := mkAppC `HasAdd #[a]
def mkHasToString (a : Expr) : MetaM Expr := mkAppC `HasToString #[a]
def tst14 : MetaM Unit :=
do print "----- tst14 -----";
stateM β mkStateM nat;
print stateM;
monad β mkMonad stateM;
globalInsts β getGlobalInstances;
insts β globalInsts.getUnify monad;
print insts;
pure ()
#eval tst14
def tst15 : MetaM Unit :=
do print "----- tst15 -----";
inst β mkHasAdd nat;
r β synthInstance inst;
print r;
pure ()
#eval tst15
def tst16 : MetaM Unit :=
do print "----- tst16 -----";
prod β mkProd nat nat;
inst β mkHasToString prod;
print inst;
r β synthInstance inst;
print r;
pure ()
#eval tst16
def tst17 : MetaM Unit :=
do print "----- tst17 -----";
prod β mkProd nat nat;
prod β mkProd boolE prod;
inst β mkHasToString prod;
print inst;
r β synthInstance inst;
print r;
pure ()
#eval tst17
def tst18 : MetaM Unit :=
do print "----- tst18 -----";
decEqNat β mkDecEq nat;
r β synthInstance decEqNat;
print r;
pure ()
#eval tst18
def tst19 : MetaM Unit :=
do print "----- tst19 -----";
stateM β mkStateM nat;
print stateM;
monad β mkMonad stateM;
print monad;
r β synthInstance monad;
print r;
pure ()
#eval tst19
def tst20 : MetaM Unit :=
do print "----- tst20 -----";
stateM β mkStateM nat;
print stateM;
monadState β mkMonadState nat stateM;
print monadState;
r β synthInstance monadState;
print r;
pure ()
#eval tst20
def tst21 : MetaM Unit :=
do print "----- tst21 -----";
withLocalDeclD `x nat $ fun x => do
withLocalDeclD `y nat $ fun y => do
withLocalDeclD `z nat $ fun z => do
eqβ β mkEq x y;
eqβ β mkEq y z;
withLocalDeclD `hβ eqβ $ fun hβ => do
withLocalDeclD `hβ eqβ $ fun hβ => do
h β mkEqTrans hβ hβ;
h β mkEqSymm h;
h β mkCongrArg succ h;
hβ β mkEqRefl succ;
h β mkCongr hβ h;
t β inferType h;
check h;
print h;
print t;
h β mkCongrFun hβ x;
t β inferType h;
check h;
print t;
pure ()
#eval tst21
def tst22 : MetaM Unit :=
do print "----- tst22 -----";
withLocalDeclD `x nat $ fun x => do
withLocalDeclD `y nat $ fun y => do
t β mkAppC `HasAdd.add #[x, y];
print t;
t β mkAppC `HasAdd.add #[y, x];
print t;
t β mkAppC `HasToString.toString #[x];
print t;
pure ()
#eval tst22
def test1 : Nat := (fun x y => x + y) 0 1
def tst23 : MetaM Unit :=
do print "----- tst23 -----";
cinfo β getConstInfo `test1;
let v := cinfo.value?.get!;
print v;
print v.headBeta
#eval tst23
def tst24 : MetaM Unit :=
do print "----- tst24 -----";
m1 β mkFreshExprMVar (mkArrow nat (mkArrow type type));
m2 β mkFreshExprMVar type;
zero β mkAppM `HasZero.zero #[nat];
idNat β mkAppM `Id #[nat];
let lhs := mkAppB m1 zero m2;
print zero;
print idNat;
print lhs;
check $ fullApproxDefEq $ isDefEq lhs idNat;
pure ()
#eval tst24
def tst25 : MetaM Unit :=
do print "----- tst25 -----";
withLocalDecl `Ξ± type BinderInfo.default $ fun Ξ± =>
withLocalDecl `Ξ² type BinderInfo.default $ fun Ξ² =>
withLocalDecl `Ο type BinderInfo.default $ fun Ο => do {
(t1, n) β mkForallUsedOnly #[Ξ±, Ξ², Ο] $ mkArrow Ξ± Ξ²;
print t1;
check $ pure $ n == 2;
(t2, n) β mkForallUsedOnly #[Ξ±, Ξ², Ο] $ mkArrow Ξ± (mkArrow Ξ² Ο);
check $ pure $ n == 3;
print t2;
(t3, n) β mkForallUsedOnly #[Ξ±, Ξ², Ο] $ Ξ±;
check $ pure $ n == 1;
print t3;
(t4, n) β mkForallUsedOnly #[Ξ±, Ξ², Ο] $ Ο;
check $ pure $ n == 1;
print t4;
(t5, n) β mkForallUsedOnly #[Ξ±, Ξ², Ο] $ nat;
check $ pure $ n == 0;
print t5;
pure ()
};
pure ()
#eval tst25
def tst26 : MetaM Unit := do
print "----- tst26 -----";
m1 β mkFreshExprMVar (mkArrow nat nat);
m2 β mkFreshExprMVar nat;
m3 β mkFreshExprMVar nat;
check $ approxDefEq $ isDefEq (mkApp m1 m2) m3;
check $ do { b β isExprMVarAssigned $ m1.mvarId!; pure (!b) };
check $ isExprMVarAssigned $ m3.mvarId!;
pure ()
section
set_option ppOld false
#eval tst26
end
section
set_option trace.Meta.isDefEq.step true
set_option trace.Meta.isDefEq.delta true
set_option trace.Meta.isDefEq.assign true
def tst27 : MetaM Unit := do
print "----- tst27 -----";
m β mkFreshExprMVar nat;
check $ isDefEq (mkNatLit 1) (mkApp (mkConst `Nat.succ) m);
pure ()
#eval tst27
end
def tst28 : MetaM Unit := do
print "----- tst28 -----";
withLocalDecl `x nat BinderInfo.default $ fun x =>
withLocalDecl `y nat BinderInfo.default $ fun y =>
withLocalDecl `z nat BinderInfo.default $ fun z => do
t1 β mkAppM `HasAdd.add #[x, y];
t1 β mkAppM `HasAdd.add #[x, t1];
t1 β mkAppM `HasAdd.add #[t1, t1];
t2 β mkAppM `HasAdd.add #[z, y];
t3 β mkAppM `Eq #[t2, t1];
t3 β mkForall #[z] t3;
m β mkFreshExprMVar nat;
p β mkAppM `HasAdd.add #[x, m];
print t3;
r β kabstract t3 p;
print r;
p β mkAppM `HasAdd.add #[x, y];
r β kabstract t3 p;
print r;
pure ()
#eval tst28
def norm : Level β Level := @Lean.Level.normalize
def tst29 : MetaM Unit := do
print "----- tst29 -----";
let u := mkLevelParam `u;
let v := mkLevelParam `v;
let u1 := mkLevelSucc u;
let m := mkLevelMax levelOne u1;
print (norm m);
check $ pure $ norm m == u1;
let m := mkLevelMax u1 levelOne;
print (norm m);
check $ pure $ norm m == u1;
let m := mkLevelMax (mkLevelMax levelOne (mkLevelSucc u1)) (mkLevelSucc levelOne);
check $ pure $ norm m == mkLevelSucc u1;
print m;
print (norm m);
let m := mkLevelMax (mkLevelMax (mkLevelSucc (mkLevelSucc u1)) (mkLevelSucc u1)) (mkLevelSucc levelOne);
print m;
print (norm m);
check $ pure $ norm m == mkLevelSucc (mkLevelSucc u1);
let m := mkLevelMax (mkLevelMax (mkLevelSucc v) (mkLevelSucc u1)) (mkLevelSucc levelOne);
print m;
print (norm m);
pure ()
#eval tst29
def tst30 : MetaM Unit := do
print "----- tst30 -----";
m1 β mkFreshExprMVar nat;
m2 β mkFreshExprMVar (mkArrow nat nat);
withLocalDecl `x nat BinderInfo.default $ fun x => do
let t := mkApp succ $ mkApp m2 x;
print t;
check $ approxDefEq $ isDefEq m1 t;
r β instantiateMVars m1;
print r;
r β instantiateMVars m2;
print r;
pure ()
#eval tst30
def tst31 : MetaM Unit := do
print "----- tst31 -----";
m β mkFreshExprMVar nat;
let t := mkLet `x nat zero m;
print t;
check $ isDefEq t m;
pure ()
def tst32 : MetaM Unit := do
print "----- tst32 -----";
withLocalDecl `a nat BinderInfo.default $ fun a => do
withLocalDecl `b nat BinderInfo.default $ fun b => do
aeqb β mkEq a b;
withLocalDecl `h2 aeqb BinderInfo.default $ fun h2 => do
t β mkEq (mkApp2 add a a) a;
print t;
let motive := Lean.mkLambda `x BinderInfo.default nat (mkApp3 (mkConst `Eq [levelOne]) nat (mkApp2 add a (mkBVar 0)) a);
withLocalDecl `h1 t BinderInfo.default $ fun h1 => do
r β mkEqNDRec motive h1 h2;
print r;
rType β inferType r >>= whnf;
print rType;
check r;
pure ()
#eval tst32
def tst33 : MetaM Unit := do
print "----- tst33 -----";
withLocalDecl `a nat BinderInfo.default $ fun a => do
withLocalDecl `b nat BinderInfo.default $ fun b => do
aeqb β mkEq a b;
withLocalDecl `h2 aeqb BinderInfo.default $ fun h2 => do
t β mkEq (mkApp2 add a a) a;
let motive :=
Lean.mkLambda `x BinderInfo.default nat $
Lean.mkLambda `h BinderInfo.default (mkApp3 (mkConst `Eq [levelOne]) nat a (mkBVar 0)) $
(mkApp3 (mkConst `Eq [levelOne]) nat (mkApp2 add a (mkBVar 1)) a);
withLocalDecl `h1 t BinderInfo.default $ fun h1 => do
r β mkEqRec motive h1 h2;
print r;
rType β inferType r >>= whnf;
print rType;
check r;
pure ()
#eval tst33
def tst34 : MetaM Unit := do
print "----- tst34 -----";
let type := mkSort levelOne;
withLocalDecl `Ξ± type BinderInfo.default $ fun Ξ± => do
m β mkFreshExprMVar type;
t β mkLambda #[Ξ±] (mkArrow m m);
print t;
pure ()
set_option pp.purify_metavars false
#eval tst34
def tst35 : MetaM Unit := do
print "----- tst35 -----";
let type := mkSort levelOne;
withLocalDecl `Ξ± type BinderInfo.default $ fun Ξ± => do
m1 β mkFreshExprMVar type;
m2 β mkFreshExprMVar (mkArrow nat type);
let v := mkLambda `x BinderInfo.default nat m1;
assignExprMVar m2.mvarId! v;
let w := mkApp m2 zero;
t1 β mkLambda #[Ξ±] (mkArrow w w);
print t1;
m3 β mkFreshExprMVar type;
t2 β mkLambda #[Ξ±] (mkArrow (mkBVar 0) (mkBVar 1));
print t2;
check $ isDefEq t1 t2;
pure ()
#eval tst35
#check @Id
def tst36 : MetaM Unit := do
print "----- tst36 -----";
let type := mkSort levelOne;
m1 β mkFreshExprMVar (mkArrow type type);
withLocalDecl `Ξ± type BinderInfo.default $ fun Ξ± => do
m2 β mkFreshExprMVar type;
t β mkAppM `Id #[m2];
check $ approxDefEq $ isDefEq (mkApp m1 Ξ±) t;
check $ approxDefEq $ isDefEq m1 (mkConst `Id [levelZero]);
pure ()
#eval tst36
def tst37 : MetaM Unit := do
print "----- tst37 -----";
m1 β mkFreshExprMVar (mkArrow nat (mkArrow type type));
m2 β mkFreshExprMVar (mkArrow nat type);
withLocalDecl `v nat BinderInfo.default $ fun v => do
let lhs := mkApp2 m1 v (mkApp m2 v);
rhs β mkAppM `StateM #[nat, nat];
print lhs;
print rhs;
check $ approxDefEq $ isDefEq lhs rhs;
pure ()
#eval tst37
def tst38 : MetaM Unit := do
print "----- tst37 -----";
m1 β mkFreshExprMVar nat;
withLocalDecl `x nat BinderInfo.default $ fun x => do
m2 β mkFreshExprMVar type;
withLocalDecl `y m2 BinderInfo.default $ fun y => do
m3 β mkFreshExprMVar (mkArrow m2 nat);
let rhs := mkApp m3 y;
check $ approxDefEq $ isDefEq m2 nat;
print m2;
check $ getAssignment m2 >>= fun v => pure $ v == nat;
check $ approxDefEq $ isDefEq m1 rhs;
print m2;
check $ getAssignment m2 >>= fun v => pure $ v == nat;
pure ()
set_option pp.all true
set_option trace.Meta.isDefEq.step true
set_option trace.Meta.isDefEq.delta true
set_option trace.Meta.isDefEq.assign true
#eval tst38
|
6bf4660bcb8144e6a3efd6ad73fdd4e865001e6e
|
94e33a31faa76775069b071adea97e86e218a8ee
|
/src/data/polynomial/cardinal.lean
|
6d74d7eb4df8ec86989c0471d061c838e8bb2705
|
[
"Apache-2.0"
] |
permissive
|
urkud/mathlib
|
eab80095e1b9f1513bfb7f25b4fa82fa4fd02989
|
6379d39e6b5b279df9715f8011369a301b634e41
|
refs/heads/master
| 1,658,425,342,662
| 1,658,078,703,000
| 1,658,078,703,000
| 186,910,338
| 0
| 0
|
Apache-2.0
| 1,568,512,083,000
| 1,557,958,709,000
|
Lean
|
UTF-8
|
Lean
| false
| false
| 798
|
lean
|
/-
Copyright (c) 2021 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes
-/
import data.mv_polynomial.cardinal
import data.mv_polynomial.equiv
/-!
# Cardinality of Polynomial Ring
The reuslt in this file is that the cardinality of `polynomial R` is at most the maximum
of `#R` and `β΅β`.
-/
universe u
open_locale cardinal polynomial
open cardinal
namespace polynomial
lemma cardinal_mk_le_max {R : Type u} [comm_semiring R] : #R[X] β€ max (#R) β΅β :=
calc #R[X] = #(mv_polynomial punit.{u + 1} R) :
cardinal.eq.2 β¨(mv_polynomial.punit_alg_equiv.{u u} R).to_equiv.symmβ©
... β€ _ : mv_polynomial.cardinal_mk_le_max
... β€ _ : by rw [max_assoc, max_eq_right (lt_aleph_0_of_finite punit).le]
end polynomial
|
699646e923def490a165e7b14272e355e48e9571
|
d1a52c3f208fa42c41df8278c3d280f075eb020c
|
/stage0/src/Lean/Parser/Attr.lean
|
69785a09dc71401a5e905c5b437f5dbf8c48064b
|
[
"Apache-2.0",
"LLVM-exception",
"NCSA",
"LGPL-3.0-only",
"LicenseRef-scancode-inner-net-2.0",
"BSD-3-Clause",
"LGPL-2.0-or-later",
"Spencer-94",
"LGPL-2.1-or-later",
"HPND",
"LicenseRef-scancode-pcre",
"ISC",
"LGPL-2.1-only",
"LicenseRef-scancode-other-permissive",
"SunPro",
"CMU-Mach"
] |
permissive
|
cipher1024/lean4
|
6e1f98bb58e7a92b28f5364eb38a14c8d0aae393
|
69114d3b50806264ef35b57394391c3e738a9822
|
refs/heads/master
| 1,642,227,983,603
| 1,642,011,696,000
| 1,642,011,696,000
| 228,607,691
| 0
| 0
|
Apache-2.0
| 1,576,584,269,000
| 1,576,584,268,000
| null |
UTF-8
|
Lean
| false
| false
| 2,048
|
lean
|
/-
Copyright (c) 2020 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
import Lean.Parser.Basic
import Lean.Parser.Extra
namespace Lean.Parser
builtin_initialize
registerBuiltinParserAttribute `builtinPrioParser `prio LeadingIdentBehavior.both
registerBuiltinDynamicParserAttribute `prioParser `prio
builtin_initialize
registerBuiltinParserAttribute `builtinAttrParser `attr LeadingIdentBehavior.symbol
registerBuiltinDynamicParserAttribute `attrParser `attr
@[inline] def priorityParser (rbp : Nat := 0) : Parser :=
categoryParser `prio rbp
@[inline] def attrParser (rbp : Nat := 0) : Parser :=
categoryParser `attr rbp
attribute [runBuiltinParserAttributeHooks]
priorityParser attrParser
namespace Priority
@[builtinPrioParser] def numPrio := checkPrec maxPrec >> numLit
attribute [runBuiltinParserAttributeHooks] numPrio
end Priority
namespace Attr
@[builtinAttrParser] def simple := leading_parser ident >> optional (priorityParser <|> ident)
/- Remark, We can't use `simple` for `class`, `instance`, `export`, and `macro` because they are keywords. -/
@[builtinAttrParser] def Β«macroΒ» := leading_parser "macro " >> ident
@[builtinAttrParser] def Β«exportΒ» := leading_parser "export " >> ident
/- We don't use `simple` for recursor because the argument is not a priority-/
@[builtinAttrParser] def recursor := leading_parser nonReservedSymbol "recursor " >> numLit
@[builtinAttrParser] def Β«classΒ» := leading_parser "class"
@[builtinAttrParser] def Β«instanceΒ» := leading_parser "instance" >> optional priorityParser
@[builtinAttrParser] def defaultInstance := leading_parser nonReservedSymbol "defaultInstance " >> optional priorityParser
def externEntry := leading_parser optional ident >> optional (nonReservedSymbol "inline ") >> strLit
@[builtinAttrParser] def extern := leading_parser nonReservedSymbol "extern " >> optional numLit >> many externEntry
end Attr
end Lean.Parser
|
5266d4df8a1c9b6863dda66781f7a553d7c7c58e
|
be30445afb85fcb2041b437059d21f9a84dff894
|
/abstract.hlean
|
6daaf00e19db6e31375f6063e4e6cdb72557f0c1
|
[
"Apache-2.0"
] |
permissive
|
EgbertRijke/GraphModel
|
784efde97299c4f3cb1760369e8a260e02caafd5
|
2a473880764093dd151554a913292ed465e80e62
|
refs/heads/master
| 1,609,477,731,119
| 1,476,299,056,000
| 1,476,299,056,000
| 58,213,801
| 6
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 20,772
|
hlean
|
import types
open eq funext
universe variable u
-- We attempt to formalize a weak notion of model of type theory using only homotopy-invariant
-- tools. We have two examples in mind:
-- - it should be possible to obtain such a model from a univalent universe,
-- - given a univalent universe, there should be a model or (reflexive) graphs.
--
-- It turns out that what we formalize here is a theory of structures and dependent structures,
-- containing all the ways in which one could manipulate these. From another point of view, this
-- is a theory of contexts and dependent contexts. It is a direct generalization of Cartmell's
-- contextual categories, which were reformulated as C-systems and B-systems by Voevodsky. The
-- weak notion of model we formalize here is a homotopified notion of E-system, which was
-- developed by the author. B-systems form a subcategory of E-systems, for which the inclusion
-- functor is full and faithful.
namespace model -- open the name space model
-- The base structure of a model consists of
-- - a type of contexts,
-- - a family of dependent stuctures over the type of contexts,
-- - a family of terms of dependent structures
-- In other words, it looks like
--
-- base.tm ---->> base.fam ---->> base.ctx.
structure base : Type :=
-- contexts
( ctx : Type.{u})
-- dependent structures
( fam : ctx β Type.{u})
-- terms
( tm : Ξ β¦Ξ : ctxβ¦, fam Ξ β Type.{u})
namespace base -- Open the namespace model.base
-- One operation we can always define on bases, is that if AA is an indexed base, then we can take
-- the total space at the level of contexts to obtain a new base β« AA.
definition total {I : Type.{u}} (AA : I β base) : base :=
mk
-- contexts
( Ξ£ (i : I), @base.ctx (AA i))
-- families
( sigma.rec (Ξ» i, @base.fam (AA i)))
-- terms
( sigma.rec (Ξ» i, @base.tm (AA i)))
-- A homomorphism of bases, is simply a three-fold map sending
-- - the contexts to the contexts,
-- - the dependent structures to the dependent structures
-- - the terms to the terms
-- In a diagram, a homomorphism of bases can be indicated as
--
-- base.tm AA -----> base.tm BB
-- | |
-- | |
-- V V
-- base.fam AA -----> base.fam BB
-- | |
-- | |
-- V V
-- base.ctx AA -----> base.ctx BB
-- We add the notion of homomorphism of bases to the namespace model.base
structure hom (AA BB : base) : Type :=
-- action on contexts
( action_ctx : base.ctx AA β base.ctx BB)
-- action on dependent structures
( action_fam : Ξ β¦Ξ : base.ctx AAβ¦, base.fam AA Ξ β base.fam BB (action_ctx Ξ))
-- action on terms
( action_tm : Ξ β¦Ξ : base.ctx AAβ¦ β¦A : base.fam AA Ξβ¦, base.tm AA A β base.tm BB (action_fam A))
-- infixr ` βbase ` : 50 := base.hom
namespace hom -- Open the namespace model.base.hom
-- We add the identity homomorphism and composition to the namespace base.hom of base homomorphisms.
definition id (AA : base) : hom AA AA :=
mk
-- action on contexts
( id)
-- action on families
( Ξ» Ξ, id)
-- action on terms
( Ξ» Ξ A, id)
definition compose {AA BB CC : base} (f : hom AA BB) (g : hom BB CC) : hom AA CC :=
mk
-- action on contexts
( Ξ» Ξ, action_ctx g (action_ctx f Ξ))
-- action on families
( Ξ» Ξ A, action_fam g (action_fam f A))
-- action on terms
( Ξ» Ξ A x, action_tm g (action_tm f x))
definition total {I J : Type} (k : I β J) {AA : I β base} {BB : J β base}
( f : Ξ (i : I), hom (AA i) (BB (k i))) : hom (total AA) (total BB) :=
mk
-- action on contexts
( sigma.rec (Ξ» i Ξ, sigma.mk (k i) (action_ctx (f i) Ξ)))
-- action on families
( sigma.rec (Ξ» i Ξ, @action_fam _ _ (f i) Ξ))
-- action on terms
( sigma.rec (Ξ» i Ξ, @action_tm _ _ (f i) Ξ))
end hom
-- Before we extend the base structure to a base structure with context extension, we define the type of the operation of context extension.
definition has_ctxext (AA : base) : Type :=
Ξ (Ξ : ctx AA), (fam AA Ξ) β (ctx AA)
end base
-- We start adding ingredients to the base structure, by adding context extension into the mix.
structure e0base extends AA : base :=
-- context extension
( ctxext : base.has_ctxext AA)
-- when base is a class, the following should work
-- ( ctxext : base.has_ctxext)
namespace e0base -- Open the namespace model.e0base
-- If we are given a base, we can make it a base with context extension by adding context extension.
definition from_base (AA : base) : base.has_ctxext AA β e0base :=
e0base.mk
( base.ctx AA)
( base.fam AA)
( base.tm AA)
-- A homomorphism of bases with context extension is simply a homomorphism of bases which preserves context extension. We first define the type that witnesses whether context extension is preserved, and then we will define homomorphisms of bases with context extension.
definition ty_pres_ctxext {AA BB : e0base} (f : base.hom AA BB) : Type :=
Ξ (Ξ : ctx AA) (A : fam AA Ξ),
base.hom.action_ctx f (ctxext AA Ξ A) = ctxext BB (base.hom.action_ctx f Ξ) (base.hom.action_fam f A)
structure hom (AA BB : e0base) extends f : base.hom AA BB :=
( pres_ctxext : ty_pres_ctxext f)
definition hom.from_basehom {AA BB : e0base} (f : base.hom AA BB) : ty_pres_ctxext f β hom AA BB :=
hom.mk
-- action on contexts
( base.hom.action_ctx f)
-- action on families
( base.hom.action_fam f)
-- action on terms
( base.hom.action_tm f)
-- notation AA `βe0base` BB := hom AA BB
-- Given a context Ξ in a base with context extension, we can find the base for a new model.
definition slice {AA : e0base} (Ξ : e0base.ctx AA) : base :=
base.mk
-- contexts
( fam AA Ξ)
-- families
( Ξ» A, fam AA (ctxext AA Ξ A))
-- terms
( Ξ» A P, tm AA P)
definition slice.total (AA : e0base) : e0base :=
e0base.from_base (base.total (@slice AA))
-- context extension
(sigma.rec (Ξ» Ξ A P, @sigma.mk (ctx AA) (fam AA) (ctxext AA Ξ A) P))
namespace hom -- Open the namespace model.e0base.hom
-- Given a base homomorphism between bases with context extension, we define a slice operation on homomorphisms.
definition slice {AA BB : e0base} (f : hom AA BB) (Ξ : ctx AA) :
base.hom (slice Ξ) (slice (action_ctx f Ξ)) :=
base.hom.mk
-- action on contexts
(Ξ» A, action_fam f A)
-- action on families
(Ξ» A P, transport (fam BB) (pres_ctxext f Ξ A) (action_fam f P))
-- action on terms
(Ξ» A P x, transportD (tm BB) (pres_ctxext f Ξ A) _ (action_tm f x))
-- Furthermore, we can extend context extension to a base homomorphism.
definition ctxext (AA : e0base) : base.hom (@base.total (ctx AA) (@e0base.slice AA)) AA :=
base.hom.mk
-- action on contexts
(sigma.rec (ctxext AA))
-- action on families
(sigma.rec (Ξ» Ξ A, id))
-- action on terms
(sigma.rec (Ξ» Ξ A P, id))
end hom
end e0base
definition has_famext (AA : e0base) : Type :=
Ξ {Ξ : e0base.ctx AA} (A : e0base.fam AA Ξ), (e0base.fam AA (e0base.ctxext AA Ξ A)) β (e0base.fam AA Ξ)
definition has_empstr (AA : e0base) : Type :=
Ξ (Ξ : e0base.ctx AA), e0base.fam AA Ξ
structure pre_ebase extends AA : e0base :=
-- family extension
( famext : has_famext AA)
-- empty structure
( empstr : has_empstr AA)
definition pre_ebase.from_e0base (AA : e0base) : has_famext AA β has_empstr AA β pre_ebase :=
pre_ebase.mk
-- contexts
( e0base.ctx AA)
-- families
( e0base.fam AA)
-- terms
( e0base.tm AA)
-- context extension
( e0base.ctxext AA)
namespace pre_ebase -- opens the namespace model.pre_ebase
definition e0slice (AA : pre_ebase) (Ξ : pre_ebase.ctx AA) : e0base :=
e0base.from_base (@e0base.slice AA Ξ) (@pre_ebase.famext AA Ξ)
-- We will now formalize what it means to preserve family extension.
-- The idea behind this definition, is that f : AA β BB preserves
-- family extension precisely when we can define for each Ξ : ctx AA
-- a base homomorphism
--
-- slice (f/Ξ) : slice (AA/Ξ) β slice (BB/(f Ξ)),
--
-- such that the square of base homomorphisms
--
-- β« (slice (f/Ξ))
-- β« (slice (AA/Ξ)) ----------------> β« (slice (BB/(f Ξ)))
-- | |
-- hom.famext | | hom.famext
-- V V
-- AA/Ξ -------------------------> BB/(f Ξ)
-- f/Ξ
--
-- commutes. We also formalize this below.
definition ty_pres_famext {AA BB : pre_ebase} (f : e0base.hom AA BB) : Type :=
Ξ (Ξ : ctx AA),
-- Since family extension is context extension in the slice model,
-- we give a specification in terms of context extension
@e0base.ty_pres_ctxext
-- The domain e0base
(e0slice AA Ξ)
-- The codomain e0base
(e0slice BB (e0base.hom.action_ctx f Ξ))
-- The base homomorphism between them
(e0base.hom.slice f Ξ)
definition ty_pres_empstr {AA BB : pre_ebase} (f : e0base.hom AA BB) : Type :=
Ξ (Ξ : ctx AA), e0base.hom.action_fam f (empstr AA Ξ) = empstr BB (e0base.hom.action_ctx f Ξ)
structure hom (AA BB : pre_ebase) extends f : e0base.hom AA BB :=
-- preserves family extension
( pres_famext : ty_pres_famext f)
-- preserves the empty structure
( pres_empstr : ty_pres_empstr f)
definition hom.from_e0basehom {AA BB : pre_ebase} (f : e0base.hom AA BB) :
ty_pres_famext f β ty_pres_empstr f β hom AA BB :=
hom.mk
-- action on contexts
( e0base.hom.action_ctx f)
-- action on families
( e0base.hom.action_fam f)
-- action on terms
( e0base.hom.action_tm f)
-- preserves context extension
( e0base.hom.pres_ctxext f)
definition slice_of_e0slice (AA : pre_ebase) (Ξ : ctx AA) : (e0base.ctx (e0slice AA Ξ)) β base :=
@e0base.slice (e0slice AA Ξ)
namespace hom -- open the namespace model.pre_ebase.hom
-- We extend the definition of pre_ebase.e0slice to homomorphisms of e0bases,
-- so that the slice of a pre-ebase homomorphism gets the structure of an
-- e0base homomorphism.
definition e0slice {AA BB : pre_ebase} (f : hom AA BB) (Ξ : ctx AA) :
e0base.hom (pre_ebase.e0slice AA Ξ) (pre_ebase.e0slice BB (action_ctx f Ξ)) :=
e0base.hom.from_basehom
( e0base.hom.slice f Ξ)
( pres_famext f Ξ)
end hom
end pre_ebase
/--
-- We now extend the notion of base to the notion of extension base, by adding
-- - context extension
-- - family extension
-- - an empty structure, which is a right unit for context extension and a unit (both left and
-- right) for family extension,
-- - associativity for context extension and family extension
-- We do not (yet) require further coherence laws for associativity.
--
-- Note that the equations are formulated as equations between dependent functions, as opposed
-- to families of equations. This makes it slightly easier, in my experience, to formulate the
-- requirement that these equations should be preserved, in the formalization of later aspects
-- of models of type theory.
structure ebase extends e0base :=
-- family extension
( famext : Ξ β¦Ξ : ctxβ¦ (A : fam Ξ), fam (ctxext Ξ A) β fam Ξ)
-- empty structure
( empstr : Ξ (Ξ : ctx), fam Ξ)
-- context extension is associative
( c_assoc : (Ξ» Ξ A P, ctxext (ctxext Ξ A) P) = (Ξ» Ξ A P, ctxext Ξ (famext A P)))
-- family extension is associative
( f_assoc : pathover
( Ξ» (e : Ξ {Ξ : ctx} (A : fam Ξ), fam (ctxext Ξ A) β ctx),
Ξ {Ξ : ctx} (A : fam Ξ) (P: fam (ctxext Ξ A)), fam (e A P) β fam Ξ)
( Ξ» Ξ A P (Q : fam (ctxext (ctxext Ξ A) P)), famext A (famext P Q))
( c_assoc)
( Ξ» Ξ A P (Q' : fam (ctxext Ξ (famext A P))), famext (famext A P) Q'))
-- the empty structure is neutral for context extension
( c_unit : (Ξ» (Ξ : ctx), Ξ) = (Ξ» Ξ, ctxext Ξ (empstr Ξ)))
-- the empty structure is neutral for family extension from the left
( f_unit_left : pathover
( Ξ» (e : ctx β ctx), Ξ {Ξ : ctx}, fam (e Ξ) β fam Ξ)
( Ξ» Ξ A, A )
( c_unit)
( Ξ» Ξ A', famext (empstr Ξ) A'))
-- the empty structure is neutral for family extension from the right
( f_unit_right : (Ξ» Ξ A, famext A (empstr (ctxext Ξ A))) = (Ξ» Ξ A, A))
open ebase
-- We open the name space model.ebase, so that we can freely use its ingredients.
-- A pre-homomorphism of ebases is a homomorphism which preserves the operations of context
-- extension, family extension and the empty structure. However, a pre-homomorphism of ebases is
-- not yet required to preserve the further equations in the structure of an ebase. This
-- requires a more elaborate formalization, in which it is useful to have the auxilary notion of
-- pre-homomorphism of ebases available.
structure prehom_ebase (AA BB : ebase) extends e0base.hom AA BB :=
-- preservation of family extension
( pres_famext :
Ξ β¦Ξ : ctx AAβ¦ (A : fam AA Ξ) (P : fam AA (ctxext AA Ξ A)),
action_fam (famext AA A P) = famext BB (action_fam A) ((pres_ctxext Ξ A) βΈ (action_fam P)))
-- preservation of the empty structure
( pres_empstr : Ξ (Ξ : ctx AA), action_fam (empstr AA Ξ) = empstr BB (action_ctx Ξ))
-- Our current goal is to formalize what it means for a pre-homomorphism of
open prehom_ebase
-- Note that, if Ξ and Ξ are equal contexts, and P is a dependent structure over Ξ, then we can transport P along the equality p : Ξ = Ξ. This results in a dependent structure p βΈ P over Ξ. In the following definition, we formalize that ctxext Ξ P and ctxext Ξ (p βΈ P) are again equal contexts, in this situation.
definition pres_ext_c_1c_aux (BB : ebase) :
Ξ (Ξ Ξ : ctx BB) (p : Ξ = Ξ) (P : fam BB Ξ), ctxext BB Ξ P = ctxext BB Ξ (p βΈ P) :=
begin
intros Ξ Ξ p,
induction p,
intro P, reflexivity
end
-- In the following definition we formalize what it means for a pre-homomorphism of ebases to preserve
definition pres_ext_c_1c {AA BB : ebase} (f : prehom_ebase AA BB) :
Ξ (Ξ : ctx AA) (A : fam AA Ξ) (P : fam AA (ctxext AA Ξ A)),
action_ctx f (ctxext AA (ctxext AA Ξ A) P)
=
ctxext BB (ctxext BB (action_ctx f Ξ) (action_fam f A)) ( (pres_ctxext f Ξ A) βΈ (action_fam f P)) :=
begin
intros Ξ A P,
refine (pres_ctxext f (ctxext AA Ξ A) P) β¬ _,
apply pres_ext_c_1c_aux BB
end
definition pres_ext_c_2f {AA BB : ebase} (f : prehom_ebase AA BB) :
Ξ (Ξ : ctx AA) (A : fam AA Ξ) (P : fam AA (ctxext AA Ξ A)),
action_ctx f (ctxext AA Ξ (famext AA A P))
=
ctxext BB (action_ctx f Ξ) (famext BB (action_fam f A) ((pres_ctxext f Ξ A) βΈ (action_fam f P))) :=
begin
intros Ξ A P,
exact (pres_ctxext f Ξ (famext AA A P)) β¬ (ap (ctxext BB (action_ctx f Ξ)) (pres_famext f A P))
end
-- In the following structure we extend the notion of pre-homomorphism of extension bases to the notion of homomorphism of extension bases. In other words, we formalize the conditions that a pre-homomorphism of extension bases preserves the equalities that are part of the structure of extension bases.
--
-- We use function extensionality to express preservation of associativity conveniently.
structure hom_ebase (AA BB : ebase) extends prehom_ebase AA BB :=
-- preservation of c_assoc
( pres_c_assoc :
pathover
( Ξ» (e : Ξ (XX : ebase) (Ξ : ctx XX) (A : fam XX Ξ), fam XX (ctxext XX Ξ A) β ctx XX),
Ξ (Ξ : ctx AA) (A : fam AA Ξ) (P : fam AA (ctxext AA Ξ A)),
action_ctx (e AA Ξ A P) = e BB (action_ctx Ξ) (action_fam A) ((pres_ctxext Ξ A) βΈ action_fam P))
( pres_ext_c_1c β¦ prehom_ebase,
action_ctx := action_ctx,
action_fam := action_fam,
action_tm := action_tm,
pres_ctxext := pres_ctxext,
pres_famext := pres_famext,
pres_empstr := pres_empstr
β¦ )
( eq_of_homotopy c_assoc)
( pres_ext_c_2f β¦ prehom_ebase,
action_ctx := action_ctx,
action_fam := action_fam,
action_tm := action_tm,
pres_ctxext := pres_ctxext,
pres_famext := pres_famext,
pres_empstr := pres_empstr
β¦ )
) --there should be a better way to do this.
/- Ξ (Ξ : base.ctx AA) (A : base.fam AA Ξ) (P : base.fam AA (ebase.ctxext AA Ξ A)),
@pathover
-- base type
( Ξ (XX : ebase) (Ξ' : ebase.ctx XX) (A' : ebase.fam XX Ξ'),
ebase.fam XX (ebase.ctxext XX Ξ' A') β ebase.ctx XX)
-- base point domain
( Ξ» XX Ξ' A' P', ebase.ctxext XX (ebase.ctxext XX Ξ' A') P')
-- family
( Ξ» e, action_ctx (e AA Ξ A P) = e BB (action_ctx Ξ) (action_fam A) ((pres_ctxext Ξ A) βΈ (action_fam P)))
-- fiber point domain
( (pres_ctxext (ctxext Ξ A) P) β¬ _ )
-- base point codomain
( Ξ» XX Ξ' A' P', ebase.ctxext XX Ξ' (ebase.famext XX A' P'))
-- base path
( eq_of_homotopy (Ξ» (XX : ebase), eq_of_homotopy3 (ebase.c_assoc XX)))
-- fiber point codomain
( (pres_ctxext Ξ (ebase.famext A P)) β¬ _ ))
-/
-- preservation of f_assoc
( pres_f_assoc : Ξ β¦Ξ : base.ctx AAβ¦ (A : base.fam AA Ξ) (P : base.fam AA (ebase.ctxext AA Ξ A)) (Q : base.fam AA (ebase.ctxext AA (ebase.ctxext AA Ξ A) P)), ap (action_fam (ebase.f_assoc AA A P Q)) = ebase.f_assoc BB (action_fam A) ((pres_ctxext Ξ A) βΈ P) (Q) )
definition slice_ebase.{v} (AA : ebase.{v}) (Ξ : base.ctx AA) : ebase.{v} :=
begin
fapply ebase.mk,
-- contexts
exact ebase.fam AA Ξ,
-- dependent structures
intro A,
exact ebase.fam AA (ebase.ctxext AA Ξ A),
-- terms
intros A P,
exact base.tm AA P,
repeat exact sorry
end
definition slice_ext (AA : base) (ee : is_pre_ebase AA) (Ξ : base.ctx AA) : hom_base (slice_base AA ee Ξ) AA :=
begin
fapply hom_base.mk,
-- action on contexts (is context extension)
intro A,
exact is_pre_ebase.ctxext ee Ξ A,
-- action on dependent structures (is identity)
intro A P,
exact P,
-- action on terms (is identity)
intro A P f,
exact f,
end
structure is_ebase (AA : base) (ee : is_pre_ebase AA) : Type :=
( is_hom_ctxext : Ξ (Ξ : base.ctx AA), is_hom_pre_ebase (slice_ext AA ee Ξ))
-- We introduce the Ξ -constructor
definition ty_pi0 (AA : e0base) : Type := Ξ {Ξ : e0base.ctx AA} (A : e0base.fam AA Ξ), base.hom (e0base.slice (e0base.ctxext AA Ξ A)) (e0base.slice Ξ)
structure pi0base extends AA : e0base :=
(pi : ty_pi0 AA)
definition pi0base.from_e0base (AA : e0base) : ty_pi0 AA β pi0base :=
pi0base.mk (e0base.ctx AA) (e0base.fam AA) (e0base.tm AA) (e0base.ctxext AA)
--/
end model
|
74863ca41b59ff3c0e6639015a65f331361a6152
|
5756a081670ba9c1d1d3fca7bd47cb4e31beae66
|
/Mathport/Util/Heartbeats.lean
|
275eb4c09fdba59e5ca7bcb8dbc5599381b62e6e
|
[
"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
| 840
|
lean
|
/-
Copyright (c) 2023 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Gabriel Ebner
-/
namespace Mathport
@[extern "lean_set_max_heartbeat"]
opaque setMaxHeartbeat (max : USize) : BaseIO Unit
@[extern "lean_reset_heartbeat"]
opaque resetHeartbeat : BaseIO Unit
def withMaxHeartbeat [Monad m] [MonadFinally m] [MonadLiftT BaseIO m]
(max : USize) (k : m Ξ±) : m Ξ± := do
resetHeartbeat
setMaxHeartbeat max
try
k
finally
setMaxHeartbeat 0
@[noinline]
private unsafe def withMaxHeartbeatPureImpl (max : USize) (k : {_ : Unit} β Ξ±) : Ξ± :=
unsafeBaseIO do withMaxHeartbeat max do return @k (β pure ())
@[implemented_by withMaxHeartbeatPureImpl]
opaque withMaxHeartbeatPure {Ξ± : Type} (max : USize) (k : {_ : Unit} β Ξ±) : Ξ± :=
@k ()
|
7d3e1d63944bd2231eb6a598184fed6848f045ed
|
947fa6c38e48771ae886239b4edce6db6e18d0fb
|
/src/linear_algebra/basis.lean
|
fda0c874741b2b7254601f69ccd8ed206b38804d
|
[
"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
| 52,160
|
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, Alexander Bentkamp
-/
import algebra.big_operators.finsupp
import algebra.big_operators.finprod
import data.fintype.card
import linear_algebra.finsupp
import linear_algebra.linear_independent
import linear_algebra.linear_pmap
import linear_algebra.projection
/-!
# Bases
This file defines bases in a module or vector space.
It is inspired by Isabelle/HOL's linear algebra, and hence indirectly by HOL Light.
## Main definitions
All definitions are given for families of vectors, i.e. `v : ΞΉ β M` where `M` is the module or
vector space and `ΞΉ : Type*` is an arbitrary indexing type.
* `basis ΞΉ R M` is the type of `ΞΉ`-indexed `R`-bases for a module `M`,
represented by a linear equiv `M ββ[R] ΞΉ ββ R`.
* the basis vectors of a basis `b : basis ΞΉ R M` are available as `b i`, where `i : ΞΉ`
* `basis.repr` is the isomorphism sending `x : M` to its coordinates `basis.repr x : ΞΉ ββ R`.
The converse, turning this isomorphism into a basis, is called `basis.of_repr`.
* If `ΞΉ` is finite, there is a variant of `repr` called `basis.equiv_fun b : M ββ[R] ΞΉ β R`
(saving you from having to work with `finsupp`). The converse, turning this isomorphism into
a basis, is called `basis.of_equiv_fun`.
* `basis.constr hv f` constructs a linear map `Mβ ββ[R] Mβ` given the values `f : ΞΉ β Mβ` at the
basis elements `βb : ΞΉ β Mβ`.
* `basis.reindex` uses an equiv to map a basis to a different indexing set.
* `basis.map` uses a linear equiv to map a basis to a different module.
## Main statements
* `basis.mk`: a linear independent set of vectors spanning the whole module determines a basis
* `basis.ext` states that two linear maps are equal if they coincide on a basis.
Similar results are available for linear equivs (if they coincide on the basis vectors),
elements (if their coordinates coincide) and the functions `b.repr` and `βb`.
* `basis.of_vector_space` states that every vector space has a basis.
## Implementation notes
We use families instead of sets because it allows us to say that two identical vectors are linearly
dependent. For bases, this is useful as well because we can easily derive ordered bases by using an
ordered index type `ΞΉ`.
## Tags
basis, bases
-/
noncomputable theory
universe u
open function set submodule
open_locale classical big_operators
variables {ΞΉ : Type*} {ΞΉ' : Type*} {R : Type*} {K : Type*}
variables {M : Type*} {M' M'' : Type*} {V : Type u} {V' : Type*}
section module
variables [semiring R]
variables [add_comm_monoid M] [module R M] [add_comm_monoid M'] [module R M']
section
variables (ΞΉ) (R) (M)
/-- A `basis ΞΉ R M` for a module `M` is the type of `ΞΉ`-indexed `R`-bases of `M`.
The basis vectors are available as `coe_fn (b : basis ΞΉ R M) : ΞΉ β M`.
To turn a linear independent family of vectors spanning `M` into a basis, use `basis.mk`.
They are internally represented as linear equivs `M ββ[R] (ΞΉ ββ R)`,
available as `basis.repr`.
-/
structure basis := of_repr :: (repr : M ββ[R] (ΞΉ ββ R))
end
namespace basis
instance : inhabited (basis ΞΉ R (ΞΉ ββ R)) := β¨basis.of_repr (linear_equiv.refl _ _)β©
variables (b bβ : basis ΞΉ R M) (i : ΞΉ) (c : R) (x : M)
section repr
/-- `b i` is the `i`th basis vector. -/
instance : has_coe_to_fun (basis ΞΉ R M) (Ξ» _, ΞΉ β M) :=
{ coe := Ξ» b i, b.repr.symm (finsupp.single i 1) }
@[simp] lemma coe_of_repr (e : M ββ[R] (ΞΉ ββ R)) :
β(of_repr e) = Ξ» i, e.symm (finsupp.single i 1) :=
rfl
protected lemma injective [nontrivial R] : injective b :=
b.repr.symm.injective.comp (Ξ» _ _, (finsupp.single_left_inj (one_ne_zero : (1 : R) β 0)).mp)
lemma repr_symm_single_one : b.repr.symm (finsupp.single i 1) = b i := rfl
lemma repr_symm_single : b.repr.symm (finsupp.single i c) = c β’ b i :=
calc b.repr.symm (finsupp.single i c)
= b.repr.symm (c β’ finsupp.single i 1) : by rw [finsupp.smul_single', mul_one]
... = c β’ b i : by rw [linear_equiv.map_smul, repr_symm_single_one]
@[simp] lemma repr_self : b.repr (b i) = finsupp.single i 1 :=
linear_equiv.apply_symm_apply _ _
lemma repr_self_apply (j) [decidable (i = j)] :
b.repr (b i) j = if i = j then 1 else 0 :=
by rw [repr_self, finsupp.single_apply]
@[simp] lemma repr_symm_apply (v) : b.repr.symm v = finsupp.total ΞΉ M R b v :=
calc b.repr.symm v = b.repr.symm (v.sum finsupp.single) : by simp
... = β i in v.support, b.repr.symm (finsupp.single i (v i)) :
by rw [finsupp.sum, linear_equiv.map_sum]
... = finsupp.total ΞΉ M R b v :
by simp [repr_symm_single, finsupp.total_apply, finsupp.sum]
@[simp] lemma coe_repr_symm : βb.repr.symm = finsupp.total ΞΉ M R b :=
linear_map.ext (Ξ» v, b.repr_symm_apply v)
@[simp] lemma repr_total (v) : b.repr (finsupp.total _ _ _ b v) = v :=
by { rw β b.coe_repr_symm, exact b.repr.apply_symm_apply v }
@[simp] lemma total_repr : finsupp.total _ _ _ b (b.repr x) = x :=
by { rw β b.coe_repr_symm, exact b.repr.symm_apply_apply x }
lemma repr_range : (b.repr : M ββ[R] (ΞΉ ββ R)).range = finsupp.supported R R univ :=
by rw [linear_equiv.range, finsupp.supported_univ]
lemma mem_span_repr_support {ΞΉ : Type*} (b : basis ΞΉ R M) (m : M) :
m β span R (b '' (b.repr m).support) :=
(finsupp.mem_span_image_iff_total _).2 β¨b.repr m, (by simp [finsupp.mem_supported_support])β©
lemma repr_support_subset_of_mem_span {ΞΉ : Type*}
(b : basis ΞΉ R M) (s : set ΞΉ) {m : M} (hm : m β span R (b '' s)) : β(b.repr m).support β s :=
begin
rcases (finsupp.mem_span_image_iff_total _).1 hm with β¨l, hl, hlmβ©,
rwa [βhlm, repr_total, βfinsupp.mem_supported R l]
end
end repr
section coord
/-- `b.coord i` is the linear function giving the `i`'th coordinate of a vector
with respect to the basis `b`.
`b.coord i` is an element of the dual space. In particular, for
finite-dimensional spaces it is the `ΞΉ`th basis vector of the dual space.
-/
@[simps]
def coord : M ββ[R] R := (finsupp.lapply i) ββ βb.repr
lemma forall_coord_eq_zero_iff {x : M} :
(β i, b.coord i x = 0) β x = 0 :=
iff.trans
(by simp only [b.coord_apply, finsupp.ext_iff, finsupp.zero_apply])
b.repr.map_eq_zero_iff
/-- The sum of the coordinates of an element `m : M` with respect to a basis. -/
noncomputable def sum_coords : M ββ[R] R :=
finsupp.lsum β (Ξ» i, linear_map.id) ββ (b.repr : M ββ[R] ΞΉ ββ R)
@[simp] lemma coe_sum_coords : (b.sum_coords : M β R) = Ξ» m, (b.repr m).sum (Ξ» i, id) :=
rfl
lemma coe_sum_coords_eq_finsum : (b.sum_coords : M β R) = Ξ» m, βαΆ i, b.coord i m :=
begin
ext m,
simp only [basis.sum_coords, basis.coord, finsupp.lapply_apply, linear_map.id_coe,
linear_equiv.coe_coe, function.comp_app, finsupp.coe_lsum, linear_map.coe_comp,
finsum_eq_sum _ (b.repr m).finite_support, finsupp.sum, finset.finite_to_set_to_finset,
id.def, finsupp.fun_support_eq],
end
@[simp] lemma coe_sum_coords_of_fintype [fintype ΞΉ] : (b.sum_coords : M β R) = β i, b.coord i :=
begin
ext m,
simp only [sum_coords, finsupp.sum_fintype, linear_map.id_coe, linear_equiv.coe_coe, coord_apply,
id.def, fintype.sum_apply, implies_true_iff, eq_self_iff_true, finsupp.coe_lsum,
linear_map.coe_comp],
end
@[simp] lemma sum_coords_self_apply : b.sum_coords (b i) = 1 :=
by simp only [basis.sum_coords, linear_map.id_coe, linear_equiv.coe_coe, id.def, basis.repr_self,
function.comp_app, finsupp.coe_lsum, linear_map.coe_comp, finsupp.sum_single_index]
end coord
section ext
variables {Rβ : Type*} [semiring Rβ] {Ο : R β+* Rβ} {Ο' : Rβ β+* R}
variables [ring_hom_inv_pair Ο Ο'] [ring_hom_inv_pair Ο' Ο]
variables {Mβ : Type*} [add_comm_monoid Mβ] [module Rβ Mβ]
/-- Two linear maps are equal if they are equal on basis vectors. -/
theorem ext {fβ fβ : M βββ[Ο] Mβ} (h : β i, fβ (b i) = fβ (b i)) : fβ = fβ :=
by { ext x,
rw [β b.total_repr x, finsupp.total_apply, finsupp.sum],
simp only [linear_map.map_sum, linear_map.map_smulββ, h] }
include Ο'
/-- Two linear equivs are equal if they are equal on basis vectors. -/
theorem ext' {fβ fβ : M βββ[Ο] Mβ} (h : β i, fβ (b i) = fβ (b i)) : fβ = fβ :=
by { ext x,
rw [β b.total_repr x, finsupp.total_apply, finsupp.sum],
simp only [linear_equiv.map_sum, linear_equiv.map_smulββ, h] }
omit Ο'
/-- Two elements are equal if their coordinates are equal. -/
theorem ext_elem {x y : M}
(h : β i, b.repr x i = b.repr y i) : x = y :=
by { rw [β b.total_repr x, β b.total_repr y], congr' 1, ext i, exact h i }
lemma repr_eq_iff {b : basis ΞΉ R M} {f : M ββ[R] ΞΉ ββ R} :
βb.repr = f β β i, f (b i) = finsupp.single i 1 :=
β¨Ξ» h i, h βΈ b.repr_self i,
Ξ» h, b.ext (Ξ» i, (b.repr_self i).trans (h i).symm)β©
lemma repr_eq_iff' {b : basis ΞΉ R M} {f : M ββ[R] ΞΉ ββ R} :
b.repr = f β β i, f (b i) = finsupp.single i 1 :=
β¨Ξ» h i, h βΈ b.repr_self i,
Ξ» h, b.ext' (Ξ» i, (b.repr_self i).trans (h i).symm)β©
lemma apply_eq_iff {b : basis ΞΉ R M} {x : M} {i : ΞΉ} :
b i = x β b.repr x = finsupp.single i 1 :=
β¨Ξ» h, h βΈ b.repr_self i,
Ξ» h, b.repr.injective ((b.repr_self i).trans h.symm)β©
/-- An unbundled version of `repr_eq_iff` -/
lemma repr_apply_eq (f : M β ΞΉ β R)
(hadd : β x y, f (x + y) = f x + f y) (hsmul : β (c : R) (x : M), f (c β’ x) = c β’ f x)
(f_eq : β i, f (b i) = finsupp.single i 1) (x : M) (i : ΞΉ) :
b.repr x i = f x i :=
begin
let f_i : M ββ[R] R :=
{ to_fun := Ξ» x, f x i,
map_add' := Ξ» _ _, by rw [hadd, pi.add_apply],
map_smul' := Ξ» _ _, by { simp [hsmul, pi.smul_apply] } },
have : (finsupp.lapply i) ββ βb.repr = f_i,
{ refine b.ext (Ξ» j, _),
show b.repr (b j) i = f (b j) i,
rw [b.repr_self, f_eq] },
calc b.repr x i = f_i x : by { rw β this, refl }
... = f x i : rfl
end
/-- Two bases are equal if they assign the same coordinates. -/
lemma eq_of_repr_eq_repr {bβ bβ : basis ΞΉ R M} (h : β x i, bβ.repr x i = bβ.repr x i) :
bβ = bβ :=
have bβ.repr = bβ.repr, by { ext, apply h },
by { cases bβ, cases bβ, simpa }
/-- Two bases are equal if their basis vectors are the same. -/
@[ext] lemma eq_of_apply_eq {bβ bβ : basis ΞΉ R M} (h : β i, bβ i = bβ i) : bβ = bβ :=
suffices bβ.repr = bβ.repr, by { cases bβ, cases bβ, simpa },
repr_eq_iff'.mpr (Ξ» i, by rw [h, bβ.repr_self])
end ext
section map
variables (f : M ββ[R] M')
/-- Apply the linear equivalence `f` to the basis vectors. -/
@[simps] protected def map : basis ΞΉ R M' :=
of_repr (f.symm.trans b.repr)
@[simp] lemma map_apply (i) : b.map f i = f (b i) := rfl
end map
section map_coeffs
variables {R' : Type*} [semiring R'] [module R' M] (f : R β+* R') (h : β c (x : M), f c β’ x = c β’ x)
include f h b
local attribute [instance] has_smul.comp.is_scalar_tower
/-- If `R` and `R'` are isomorphic rings that act identically on a module `M`,
then a basis for `M` as `R`-module is also a basis for `M` as `R'`-module.
See also `basis.algebra_map_coeffs` for the case where `f` is equal to `algebra_map`.
-/
@[simps {simp_rhs := tt}]
def map_coeffs : basis ΞΉ R' M :=
begin
letI : module R' R := module.comp_hom R (βf.symm : R' β+* R),
haveI : is_scalar_tower R' R M :=
{ smul_assoc := Ξ» x y z, begin dsimp [(β’)], rw [mul_smul, βh, f.apply_symm_apply], end },
exact (of_repr $ (b.repr.restrict_scalars R').trans $
finsupp.map_range.linear_equiv (module.comp_hom.to_linear_equiv f.symm).symm )
end
lemma map_coeffs_apply (i : ΞΉ) : b.map_coeffs f h i = b i :=
apply_eq_iff.mpr $ by simp [f.to_add_equiv_eq_coe]
@[simp] lemma coe_map_coeffs : (b.map_coeffs f h : ΞΉ β M) = b :=
funext $ b.map_coeffs_apply f h
end map_coeffs
section reindex
variables (b' : basis ΞΉ' R M')
variables (e : ΞΉ β ΞΉ')
/-- `b.reindex (e : ΞΉ β ΞΉ')` is a basis indexed by `ΞΉ'` -/
def reindex : basis ΞΉ' R M :=
basis.of_repr (b.repr.trans (finsupp.dom_lcongr e))
lemma reindex_apply (i' : ΞΉ') : b.reindex e i' = b (e.symm i') :=
show (b.repr.trans (finsupp.dom_lcongr e)).symm (finsupp.single i' 1) =
b.repr.symm (finsupp.single (e.symm i') 1),
by rw [linear_equiv.symm_trans_apply, finsupp.dom_lcongr_symm, finsupp.dom_lcongr_single]
@[simp] lemma coe_reindex : (b.reindex e : ΞΉ' β M) = b β e.symm :=
funext (b.reindex_apply e)
@[simp] lemma coe_reindex_repr : ((b.reindex e).repr x : ΞΉ' β R) = b.repr x β e.symm :=
funext $ Ξ» i',
show (finsupp.dom_lcongr e : _ ββ[R] _) (b.repr x) i' = _,
by simp
@[simp] lemma reindex_repr (i' : ΞΉ') : (b.reindex e).repr x i' = b.repr x (e.symm i') :=
by rw coe_reindex_repr
@[simp] lemma reindex_refl : b.reindex (equiv.refl ΞΉ) = b :=
eq_of_apply_eq $ Ξ» i, by simp
/-- `simp` normal form version of `range_reindex` -/
@[simp] lemma range_reindex' : set.range (b β e.symm) = set.range b :=
by rw [range_comp, equiv.range_eq_univ, set.image_univ]
lemma range_reindex : set.range (b.reindex e) = set.range b :=
by rw [coe_reindex, range_reindex']
/-- `b.reindex_range` is a basis indexed by `range b`, the basis vectors themselves. -/
def reindex_range : basis (range b) R M :=
if h : nontrivial R then
by letI := h; exact b.reindex (equiv.of_injective b (basis.injective b))
else
by letI : subsingleton R := not_nontrivial_iff_subsingleton.mp h; exact
basis.of_repr (module.subsingleton_equiv R M (range b))
lemma finsupp.single_apply_left {Ξ± Ξ² Ξ³ : Type*} [has_zero Ξ³]
{f : Ξ± β Ξ²} (hf : function.injective f)
(x z : Ξ±) (y : Ξ³) :
finsupp.single (f x) y (f z) = finsupp.single x y z :=
by simp [finsupp.single_apply, hf.eq_iff]
lemma reindex_range_self (i : ΞΉ) (h := set.mem_range_self i) :
b.reindex_range β¨b i, hβ© = b i :=
begin
by_cases htr : nontrivial R,
{ letI := htr,
simp [htr, reindex_range, reindex_apply, equiv.apply_of_injective_symm b.injective,
subtype.coe_mk] },
{ letI : subsingleton R := not_nontrivial_iff_subsingleton.mp htr,
letI := module.subsingleton R M,
simp [reindex_range] }
end
lemma reindex_range_repr_self (i : ΞΉ) :
b.reindex_range.repr (b i) = finsupp.single β¨b i, mem_range_self iβ© 1 :=
calc b.reindex_range.repr (b i) = b.reindex_range.repr (b.reindex_range β¨b i, mem_range_self iβ©) :
congr_arg _ (b.reindex_range_self _ _).symm
... = finsupp.single β¨b i, mem_range_self iβ© 1 : b.reindex_range.repr_self _
@[simp] lemma reindex_range_apply (x : range b) : b.reindex_range x = x :=
by { rcases x with β¨bi, β¨i, rflβ©β©, exact b.reindex_range_self i, }
lemma reindex_range_repr' (x : M) {bi : M} {i : ΞΉ} (h : b i = bi) :
b.reindex_range.repr x β¨bi, β¨i, hβ©β© = b.repr x i :=
begin
nontriviality,
subst h,
refine (b.repr_apply_eq (Ξ» x i, b.reindex_range.repr x β¨b i, _β©) _ _ _ x i).symm,
{ intros x y,
ext i,
simp only [pi.add_apply, linear_equiv.map_add, finsupp.coe_add] },
{ intros c x,
ext i,
simp only [pi.smul_apply, linear_equiv.map_smul, finsupp.coe_smul] },
{ intros i,
ext j,
simp only [reindex_range_repr_self],
refine @finsupp.single_apply_left _ _ _ _ (Ξ» i, (β¨b i, _β© : set.range b)) _ _ _ _,
exact Ξ» i j h, b.injective (subtype.mk.inj h) }
end
@[simp] lemma reindex_range_repr (x : M) (i : ΞΉ) (h := set.mem_range_self i) :
b.reindex_range.repr x β¨b i, hβ© = b.repr x i :=
b.reindex_range_repr' _ rfl
section fintype
variables [fintype ΞΉ]
/-- `b.reindex_finset_range` is a basis indexed by `finset.univ.image b`,
the finite set of basis vectors themselves. -/
def reindex_finset_range : basis (finset.univ.image b) R M :=
b.reindex_range.reindex ((equiv.refl M).subtype_equiv (by simp))
lemma reindex_finset_range_self (i : ΞΉ) (h := finset.mem_image_of_mem b (finset.mem_univ i)) :
b.reindex_finset_range β¨b i, hβ© = b i :=
by { rw [reindex_finset_range, reindex_apply, reindex_range_apply], refl }
@[simp] lemma reindex_finset_range_apply (x : finset.univ.image b) :
b.reindex_finset_range x = x :=
by { rcases x with β¨bi, hbiβ©, rcases finset.mem_image.mp hbi with β¨i, -, rflβ©,
exact b.reindex_finset_range_self i }
lemma reindex_finset_range_repr_self (i : ΞΉ) :
b.reindex_finset_range.repr (b i) =
finsupp.single β¨b i, finset.mem_image_of_mem b (finset.mem_univ i)β© 1 :=
begin
ext β¨bi, hbiβ©,
rw [reindex_finset_range, reindex_repr, reindex_range_repr_self],
convert finsupp.single_apply_left ((equiv.refl M).subtype_equiv _).symm.injective _ _ _,
refl
end
@[simp] lemma reindex_finset_range_repr (x : M) (i : ΞΉ)
(h := finset.mem_image_of_mem b (finset.mem_univ i)) :
b.reindex_finset_range.repr x β¨b i, hβ© = b.repr x i :=
by simp [reindex_finset_range]
end fintype
end reindex
protected lemma linear_independent : linear_independent R b :=
linear_independent_iff.mpr $ Ξ» l hl,
calc l = b.repr (finsupp.total _ _ _ b l) : (b.repr_total l).symm
... = 0 : by rw [hl, linear_equiv.map_zero]
protected lemma ne_zero [nontrivial R] (i) : b i β 0 :=
b.linear_independent.ne_zero i
protected lemma mem_span (x : M) : x β span R (range b) :=
by { rw [β b.total_repr x, finsupp.total_apply, finsupp.sum],
exact submodule.sum_mem _ (Ξ» i hi, submodule.smul_mem _ _ (submodule.subset_span β¨i, rflβ©)) }
protected lemma span_eq : span R (range b) = β€ :=
eq_top_iff.mpr $ Ξ» x _, b.mem_span x
lemma index_nonempty (b : basis ΞΉ R M) [nontrivial M] : nonempty ΞΉ :=
begin
obtain β¨x, y, neβ© : β (x y : M), x β y := nontrivial.exists_pair_ne,
obtain β¨i, _β© := not_forall.mp (mt b.ext_elem ne),
exact β¨iβ©
end
section constr
variables (S : Type*) [semiring S] [module S M']
variables [smul_comm_class R S M']
/-- Construct a linear map given the value at the basis.
This definition is parameterized over an extra `semiring S`,
such that `smul_comm_class R S M'` holds.
If `R` is commutative, you can set `S := R`; if `R` is not commutative,
you can recover an `add_equiv` by setting `S := β`.
See library note [bundled maps over different rings].
-/
def constr : (ΞΉ β M') ββ[S] (M ββ[R] M') :=
{ to_fun := Ξ» f, (finsupp.total M' M' R id).comp $ (finsupp.lmap_domain R R f) ββ βb.repr,
inv_fun := Ξ» f i, f (b i),
left_inv := Ξ» f, by { ext, simp },
right_inv := Ξ» f, by { refine b.ext (Ξ» i, _), simp },
map_add' := Ξ» f g, by { refine b.ext (Ξ» i, _), simp },
map_smul' := Ξ» c f, by { refine b.ext (Ξ» i, _), simp } }
theorem constr_def (f : ΞΉ β M') :
b.constr S f = (finsupp.total M' M' R id) ββ ((finsupp.lmap_domain R R f) ββ βb.repr) :=
rfl
theorem constr_apply (f : ΞΉ β M') (x : M) :
b.constr S f x = (b.repr x).sum (Ξ» b a, a β’ f b) :=
by { simp only [constr_def, linear_map.comp_apply, finsupp.lmap_domain_apply, finsupp.total_apply],
rw finsupp.sum_map_domain_index; simp [add_smul] }
@[simp] lemma constr_basis (f : ΞΉ β M') (i : ΞΉ) :
(b.constr S f : M β M') (b i) = f i :=
by simp [basis.constr_apply, b.repr_self]
lemma constr_eq {g : ΞΉ β M'} {f : M ββ[R] M'}
(h : βi, g i = f (b i)) : b.constr S g = f :=
b.ext $ Ξ» i, (b.constr_basis S g i).trans (h i)
lemma constr_self (f : M ββ[R] M') : b.constr S (Ξ» i, f (b i)) = f :=
b.constr_eq S $ Ξ» x, rfl
lemma constr_range [nonempty ΞΉ] {f : ΞΉ β M'} :
(b.constr S f).range = span R (range f) :=
by rw [b.constr_def S f, linear_map.range_comp, linear_map.range_comp, linear_equiv.range,
β finsupp.supported_univ, finsupp.lmap_domain_supported, βset.image_univ,
β finsupp.span_image_eq_map_total, set.image_id]
@[simp]
lemma constr_comp (f : M' ββ[R] M') (v : ΞΉ β M') :
b.constr S (f β v) = f.comp (b.constr S v) :=
b.ext (Ξ» i, by simp only [basis.constr_basis, linear_map.comp_apply])
end constr
section equiv
variables (b' : basis ΞΉ' R M') (e : ΞΉ β ΞΉ')
variables [add_comm_monoid M''] [module R M'']
/-- If `b` is a basis for `M` and `b'` a basis for `M'`, and the index types are equivalent,
`b.equiv b' e` is a linear equivalence `M ββ[R] M'`, mapping `b i` to `b' (e i)`. -/
protected def equiv : M ββ[R] M' :=
b.repr.trans (b'.reindex e.symm).repr.symm
@[simp] lemma equiv_apply : b.equiv b' e (b i) = b' (e i) :=
by simp [basis.equiv]
@[simp] lemma equiv_refl :
b.equiv b (equiv.refl ΞΉ) = linear_equiv.refl R M :=
b.ext' (Ξ» i, by simp)
@[simp] lemma equiv_symm : (b.equiv b' e).symm = b'.equiv b e.symm :=
b'.ext' $ Ξ» i, (b.equiv b' e).injective (by simp)
@[simp] lemma equiv_trans {ΞΉ'' : Type*} (b'' : basis ΞΉ'' R M'')
(e : ΞΉ β ΞΉ') (e' : ΞΉ' β ΞΉ'') :
(b.equiv b' e).trans (b'.equiv b'' e') = b.equiv b'' (e.trans e') :=
b.ext' (Ξ» i, by simp)
@[simp]
lemma map_equiv (b : basis ΞΉ R M) (b' : basis ΞΉ' R M') (e : ΞΉ β ΞΉ') :
b.map (b.equiv b' e) = b'.reindex e.symm :=
by { ext i, simp }
end equiv
section prod
variables (b' : basis ΞΉ' R M')
/-- `basis.prod` maps a `ΞΉ`-indexed basis for `M` and a `ΞΉ'`-indexed basis for `M'`
to a `ΞΉ β ΞΉ'`-index basis for `M Γ M'`.
For the specific case of `R Γ R`, see also `basis.fin_two_prod`. -/
protected def prod : basis (ΞΉ β ΞΉ') R (M Γ M') :=
of_repr ((b.repr.prod b'.repr).trans (finsupp.sum_finsupp_lequiv_prod_finsupp R).symm)
@[simp]
lemma prod_repr_inl (x) (i) : (b.prod b').repr x (sum.inl i) = b.repr x.1 i := rfl
@[simp]
lemma prod_repr_inr (x) (i) : (b.prod b').repr x (sum.inr i) = b'.repr x.2 i := rfl
lemma prod_apply_inl_fst (i) :
(b.prod b' (sum.inl i)).1 = b i :=
b.repr.injective $ by
{ ext j,
simp only [basis.prod, basis.coe_of_repr, linear_equiv.symm_trans_apply, linear_equiv.prod_symm,
linear_equiv.prod_apply, b.repr.apply_symm_apply, linear_equiv.symm_symm, repr_self,
equiv.to_fun_as_coe, finsupp.fst_sum_finsupp_lequiv_prod_finsupp],
apply finsupp.single_apply_left sum.inl_injective }
lemma prod_apply_inr_fst (i) :
(b.prod b' (sum.inr i)).1 = 0 :=
b.repr.injective $ by
{ ext i,
simp only [basis.prod, basis.coe_of_repr, linear_equiv.symm_trans_apply, linear_equiv.prod_symm,
linear_equiv.prod_apply, b.repr.apply_symm_apply, linear_equiv.symm_symm, repr_self,
equiv.to_fun_as_coe, finsupp.fst_sum_finsupp_lequiv_prod_finsupp, linear_equiv.map_zero,
finsupp.zero_apply],
apply finsupp.single_eq_of_ne sum.inr_ne_inl }
lemma prod_apply_inl_snd (i) :
(b.prod b' (sum.inl i)).2 = 0 :=
b'.repr.injective $ by
{ ext j,
simp only [basis.prod, basis.coe_of_repr, linear_equiv.symm_trans_apply, linear_equiv.prod_symm,
linear_equiv.prod_apply, b'.repr.apply_symm_apply, linear_equiv.symm_symm, repr_self,
equiv.to_fun_as_coe, finsupp.snd_sum_finsupp_lequiv_prod_finsupp, linear_equiv.map_zero,
finsupp.zero_apply],
apply finsupp.single_eq_of_ne sum.inl_ne_inr }
lemma prod_apply_inr_snd (i) :
(b.prod b' (sum.inr i)).2 = b' i :=
b'.repr.injective $ by
{ ext i,
simp only [basis.prod, basis.coe_of_repr, linear_equiv.symm_trans_apply, linear_equiv.prod_symm,
linear_equiv.prod_apply, b'.repr.apply_symm_apply, linear_equiv.symm_symm, repr_self,
equiv.to_fun_as_coe, finsupp.snd_sum_finsupp_lequiv_prod_finsupp],
apply finsupp.single_apply_left sum.inr_injective }
@[simp]
lemma prod_apply (i) :
b.prod b' i = sum.elim (linear_map.inl R M M' β b) (linear_map.inr R M M' β b') i :=
by { ext; cases i; simp only [prod_apply_inl_fst, sum.elim_inl, linear_map.inl_apply,
prod_apply_inr_fst, sum.elim_inr, linear_map.inr_apply,
prod_apply_inl_snd, prod_apply_inr_snd, comp_app] }
end prod
section no_zero_smul_divisors
-- Can't be an instance because the basis can't be inferred.
protected lemma no_zero_smul_divisors [no_zero_divisors R] (b : basis ΞΉ R M) :
no_zero_smul_divisors R M :=
β¨Ξ» c x hcx, or_iff_not_imp_right.mpr (Ξ» hx, begin
rw [β b.total_repr x, β linear_map.map_smul] at hcx,
have := linear_independent_iff.mp b.linear_independent (c β’ b.repr x) hcx,
rw smul_eq_zero at this,
exact this.resolve_right (Ξ» hr, hx (b.repr.map_eq_zero_iff.mp hr))
end)β©
protected lemma smul_eq_zero [no_zero_divisors R] (b : basis ΞΉ R M) {c : R} {x : M} :
c β’ x = 0 β c = 0 β¨ x = 0 :=
@smul_eq_zero _ _ _ _ _ b.no_zero_smul_divisors _ _
lemma _root_.eq_bot_of_rank_eq_zero [no_zero_divisors R] (b : basis ΞΉ R M) (N : submodule R M)
(rank_eq : β {m : β} (v : fin m β N),
linear_independent R (coe β v : fin m β M) β m = 0) :
N = β₯ :=
begin
rw submodule.eq_bot_iff,
intros x hx,
contrapose! rank_eq with x_ne,
refine β¨1, Ξ» _, β¨x, hxβ©, _, one_ne_zeroβ©,
rw fintype.linear_independent_iff,
rintros g sum_eq i,
cases i,
simp only [function.const_apply, fin.default_eq_zero, submodule.coe_mk, finset.univ_unique,
function.comp_const, finset.sum_singleton] at sum_eq,
convert (b.smul_eq_zero.mp sum_eq).resolve_right x_ne
end
end no_zero_smul_divisors
section singleton
/-- `basis.singleton ΞΉ R` is the basis sending the unique element of `ΞΉ` to `1 : R`. -/
protected def singleton (ΞΉ R : Type*) [unique ΞΉ] [semiring R] :
basis ΞΉ R R :=
of_repr
{ to_fun := Ξ» x, finsupp.single default x,
inv_fun := Ξ» f, f default,
left_inv := Ξ» x, by simp,
right_inv := Ξ» f, finsupp.unique_ext (by simp),
map_add' := Ξ» x y, by simp,
map_smul' := Ξ» c x, by simp }
@[simp] lemma singleton_apply (ΞΉ R : Type*) [unique ΞΉ] [semiring R] (i) :
basis.singleton ΞΉ R i = 1 :=
apply_eq_iff.mpr (by simp [basis.singleton])
@[simp] lemma singleton_repr (ΞΉ R : Type*) [unique ΞΉ] [semiring R] (x i) :
(basis.singleton ΞΉ R).repr x i = x :=
by simp [basis.singleton, unique.eq_default i]
lemma basis_singleton_iff
{R M : Type*} [ring R] [nontrivial R] [add_comm_group M] [module R M] [no_zero_smul_divisors R M]
(ΞΉ : Type*) [unique ΞΉ] :
nonempty (basis ΞΉ R M) β β x β 0, β y : M, β r : R, r β’ x = y :=
begin
fsplit,
{ rintro β¨bβ©,
refine β¨b default, b.linear_independent.ne_zero _, _β©,
simpa [span_singleton_eq_top_iff, set.range_unique] using b.span_eq },
{ rintro β¨x, nz, wβ©,
refine β¨of_repr $ linear_equiv.symm
{ to_fun := Ξ» f, f default β’ x,
inv_fun := Ξ» y, finsupp.single default (w y).some,
left_inv := Ξ» f, finsupp.unique_ext _,
right_inv := Ξ» y, _,
map_add' := Ξ» y z, _,
map_smul' := Ξ» c y, _ }β©,
{ rw [finsupp.add_apply, add_smul] },
{ rw [finsupp.smul_apply, smul_assoc], simp },
{ refine smul_left_injective _ nz _,
simp only [finsupp.single_eq_same],
exact (w (f default β’ x)).some_spec },
{ simp only [finsupp.single_eq_same],
exact (w y).some_spec } }
end
end singleton
section empty
variables (M)
/-- If `M` is a subsingleton and `ΞΉ` is empty, this is the unique `ΞΉ`-indexed basis for `M`. -/
protected def empty [subsingleton M] [is_empty ΞΉ] : basis ΞΉ R M :=
of_repr 0
instance empty_unique [subsingleton M] [is_empty ΞΉ] : unique (basis ΞΉ R M) :=
{ default := basis.empty M, uniq := Ξ» β¨xβ©, congr_arg of_repr $ subsingleton.elim _ _ }
end empty
end basis
section fintype
open basis
open fintype
variables [fintype ΞΉ] (b : basis ΞΉ R M)
/-- A module over `R` with a finite basis is linearly equivalent to functions from its basis to `R`.
-/
def basis.equiv_fun : M ββ[R] (ΞΉ β R) :=
linear_equiv.trans b.repr
({ to_fun := coe_fn,
map_add' := finsupp.coe_add,
map_smul' := finsupp.coe_smul,
..finsupp.equiv_fun_on_fintype } : (ΞΉ ββ R) ββ[R] (ΞΉ β R))
/-- A module over a finite ring that admits a finite basis is finite. -/
def module.fintype_of_fintype [fintype R] : fintype M :=
fintype.of_equiv _ b.equiv_fun.to_equiv.symm
theorem module.card_fintype [fintype R] [fintype M] :
card M = (card R) ^ (card ΞΉ) :=
calc card M = card (ΞΉ β R) : card_congr b.equiv_fun.to_equiv
... = card R ^ card ΞΉ : card_fun
/-- Given a basis `v` indexed by `ΞΉ`, the canonical linear equivalence between `ΞΉ β R` and `M` maps
a function `x : ΞΉ β R` to the linear combination `β_i x i β’ v i`. -/
@[simp] lemma basis.equiv_fun_symm_apply (x : ΞΉ β R) :
b.equiv_fun.symm x = β i, x i β’ b i :=
by simp [basis.equiv_fun, finsupp.total_apply, finsupp.sum_fintype]
@[simp]
lemma basis.equiv_fun_apply (u : M) : b.equiv_fun u = b.repr u := rfl
@[simp] lemma basis.map_equiv_fun (f : M ββ[R] M') :
(b.map f).equiv_fun = f.symm.trans b.equiv_fun :=
rfl
lemma basis.sum_equiv_fun (u : M) : β i, b.equiv_fun u i β’ b i = u :=
begin
conv_rhs { rw β b.total_repr u },
simp [finsupp.total_apply, finsupp.sum_fintype, b.equiv_fun_apply]
end
lemma basis.sum_repr (u : M) : β i, b.repr u i β’ b i = u :=
b.sum_equiv_fun u
@[simp]
lemma basis.equiv_fun_self (i j : ΞΉ) : b.equiv_fun (b i) j = if i = j then 1 else 0 :=
by { rw [b.equiv_fun_apply, b.repr_self_apply] }
/-- Define a basis by mapping each vector `x : M` to its coordinates `e x : ΞΉ β R`,
as long as `ΞΉ` is finite. -/
def basis.of_equiv_fun (e : M ββ[R] (ΞΉ β R)) : basis ΞΉ R M :=
basis.of_repr $ e.trans $ linear_equiv.symm $ finsupp.linear_equiv_fun_on_fintype R R ΞΉ
@[simp] lemma basis.of_equiv_fun_repr_apply (e : M ββ[R] (ΞΉ β R)) (x : M) (i : ΞΉ) :
(basis.of_equiv_fun e).repr x i = e x i := rfl
@[simp] lemma basis.coe_of_equiv_fun (e : M ββ[R] (ΞΉ β R)) :
(basis.of_equiv_fun e : ΞΉ β M) = Ξ» i, e.symm (function.update 0 i 1) :=
funext $ Ξ» i, e.injective $ funext $ Ξ» j,
by simp [basis.of_equiv_fun, βfinsupp.single_eq_pi_single, finsupp.single_eq_update]
@[simp] lemma basis.of_equiv_fun_equiv_fun
(v : basis ΞΉ R M) : basis.of_equiv_fun v.equiv_fun = v :=
begin
ext j,
simp only [basis.equiv_fun_symm_apply, basis.coe_of_equiv_fun],
simp_rw [function.update_apply, ite_smul],
simp only [finset.mem_univ, if_true, pi.zero_apply, one_smul, finset.sum_ite_eq', zero_smul],
end
variables (S : Type*) [semiring S] [module S M']
variables [smul_comm_class R S M']
@[simp] theorem basis.constr_apply_fintype (f : ΞΉ β M') (x : M) :
(b.constr S f : M β M') x = β i, (b.equiv_fun x i) β’ f i :=
by simp [b.constr_apply, b.equiv_fun_apply, finsupp.sum_fintype]
end fintype
end module
section comm_semiring
namespace basis
variables [comm_semiring R]
variables [add_comm_monoid M] [module R M] [add_comm_monoid M'] [module R M']
variables (b : basis ΞΉ R M) (b' : basis ΞΉ' R M')
/-- If `b` is a basis for `M` and `b'` a basis for `M'`,
and `f`, `g` form a bijection between the basis vectors,
`b.equiv' b' f g hf hg hgf hfg` is a linear equivalence `M ββ[R] M'`, mapping `b i` to `f (b i)`.
-/
def equiv' (f : M β M') (g : M' β M)
(hf : β i, f (b i) β range b') (hg : β i, g (b' i) β range b)
(hgf : βi, g (f (b i)) = b i) (hfg : βi, f (g (b' i)) = b' i) :
M ββ[R] M' :=
{ inv_fun := b'.constr R (g β b'),
left_inv :=
have (b'.constr R (g β b')).comp (b.constr R (f β b)) = linear_map.id,
from (b.ext $ Ξ» i, exists.elim (hf i)
(Ξ» i' hi', by rw [linear_map.comp_apply, b.constr_basis, function.comp_apply, β hi',
b'.constr_basis, function.comp_apply, hi', hgf, linear_map.id_apply])),
Ξ» x, congr_arg (Ξ» (h : M ββ[R] M), h x) this,
right_inv :=
have (b.constr R (f β b)).comp (b'.constr R (g β b')) = linear_map.id,
from (b'.ext $ Ξ» i, exists.elim (hg i)
(Ξ» i' hi', by rw [linear_map.comp_apply, b'.constr_basis, function.comp_apply, β hi',
b.constr_basis, function.comp_apply, hi', hfg, linear_map.id_apply])),
Ξ» x, congr_arg (Ξ» (h : M' ββ[R] M'), h x) this,
.. b.constr R (f β b) }
@[simp] lemma equiv'_apply (f : M β M') (g : M' β M) (hf hg hgf hfg) (i : ΞΉ) :
b.equiv' b' f g hf hg hgf hfg (b i) = f (b i) :=
b.constr_basis R _ _
@[simp] lemma equiv'_symm_apply (f : M β M') (g : M' β M) (hf hg hgf hfg) (i : ΞΉ') :
(b.equiv' b' f g hf hg hgf hfg).symm (b' i) = g (b' i) :=
b'.constr_basis R _ _
lemma sum_repr_mul_repr {ΞΉ'} [fintype ΞΉ'] (b' : basis ΞΉ' R M) (x : M) (i : ΞΉ) :
β (j : ΞΉ'), b.repr (b' j) i * b'.repr x j = b.repr x i :=
begin
conv_rhs { rw [β b'.sum_repr x] },
simp_rw [linear_equiv.map_sum, linear_equiv.map_smul, finset.sum_apply'],
refine finset.sum_congr rfl (Ξ» j _, _),
rw [finsupp.smul_apply, smul_eq_mul, mul_comm]
end
end basis
end comm_semiring
section module
open linear_map
variables {v : ΞΉ β M}
variables [ring R] [add_comm_group M] [add_comm_group M'] [add_comm_group M'']
variables [module R M] [module R M'] [module R M'']
variables {c d : R} {x y : M}
variables (b : basis ΞΉ R M)
namespace basis
/--
Any basis is a maximal linear independent set.
-/
lemma maximal [nontrivial R] (b : basis ΞΉ R M) : b.linear_independent.maximal :=
Ξ» w hi h,
begin
-- If `range w` is strictly bigger than `range b`,
apply le_antisymm h,
-- then choose some `x β range w \ range b`,
intros x p,
by_contradiction q,
-- and write it in terms of the basis.
have e := b.total_repr x,
-- This then expresses `x` as a linear combination
-- of elements of `w` which are in the range of `b`,
let u : ΞΉ βͺ w := β¨Ξ» i, β¨b i, h β¨i, rflβ©β©, Ξ» i i' r,
b.injective (by simpa only [subtype.mk_eq_mk] using r)β©,
have r : β i, b i = u i := Ξ» i, rfl,
simp_rw [finsupp.total_apply, r] at e,
change (b.repr x).sum (Ξ» (i : ΞΉ) (a : R), (Ξ» (x : w) (r : R), r β’ (x : M)) (u i) a) =
((β¨x, pβ© : w) : M) at e,
rw [βfinsupp.sum_emb_domain, βfinsupp.total_apply] at e,
-- Now we can contradict the linear independence of `hi`
refine hi.total_ne_of_not_mem_support _ _ e,
simp only [finset.mem_map, finsupp.support_emb_domain],
rintro β¨j, -, Wβ©,
simp only [embedding.coe_fn_mk, subtype.mk_eq_mk, βr] at W,
apply q β¨j, Wβ©,
end
section mk
variables (hli : linear_independent R v) (hsp : β€ β€ span R (range v))
/-- A linear independent family of vectors spanning the whole module is a basis. -/
protected noncomputable def mk : basis ΞΉ R M :=
basis.of_repr
{ inv_fun := finsupp.total _ _ _ v,
left_inv := Ξ» x, hli.total_repr β¨x, _β©,
right_inv := Ξ» x, hli.repr_eq rfl,
.. hli.repr.comp (linear_map.id.cod_restrict _ (Ξ» h, hsp submodule.mem_top)) }
@[simp] lemma mk_repr :
(basis.mk hli hsp).repr x = hli.repr β¨x, hsp submodule.mem_topβ© :=
rfl
lemma mk_apply (i : ΞΉ) : basis.mk hli hsp i = v i :=
show finsupp.total _ _ _ v _ = v i, by simp
@[simp] lemma coe_mk : β(basis.mk hli hsp) = v :=
funext (mk_apply _ _)
variables {hli hsp}
/-- Given a basis, the `i`th element of the dual basis evaluates to 1 on the `i`th element of the
basis. -/
lemma mk_coord_apply_eq (i : ΞΉ) :
(basis.mk hli hsp).coord i (v i) = 1 :=
show hli.repr β¨v i, submodule.subset_span (mem_range_self i)β© i = 1,
by simp [hli.repr_eq_single i]
/-- Given a basis, the `i`th element of the dual basis evaluates to 0 on the `j`th element of the
basis if `j β i`. -/
lemma mk_coord_apply_ne {i j : ΞΉ} (h : j β i) :
(basis.mk hli hsp).coord i (v j) = 0 :=
show hli.repr β¨v j, submodule.subset_span (mem_range_self j)β© i = 0,
by simp [hli.repr_eq_single j, h]
/-- Given a basis, the `i`th element of the dual basis evaluates to the Kronecker delta on the
`j`th element of the basis. -/
lemma mk_coord_apply {i j : ΞΉ} :
(basis.mk hli hsp).coord i (v j) = if j = i then 1 else 0 :=
begin
cases eq_or_ne j i,
{ simp only [h, if_true, eq_self_iff_true, mk_coord_apply_eq i], },
{ simp only [h, if_false, mk_coord_apply_ne h], },
end
end mk
section span
variables (hli : linear_independent R v)
/-- A linear independent family of vectors is a basis for their span. -/
protected noncomputable def span : basis ΞΉ R (span R (range v)) :=
basis.mk (linear_independent_span hli) $
begin
intros x _,
have hβ : (coe : span R (range v) β M) '' set.range (Ξ» i, subtype.mk (v i) _) = range v,
{ rw β set.range_comp,
refl },
have hβ : map (submodule.subtype _) (span R (set.range (Ξ» i, subtype.mk (v i) _)))
= span R (range v),
{ rw [β span_image, submodule.coe_subtype, hβ] },
have hβ : (x : M) β map (submodule.subtype _) (span R (set.range (Ξ» i, subtype.mk (v i) _))),
{ rw hβ, apply subtype.mem x },
rcases mem_map.1 hβ with β¨y, hyβ, hyββ©,
have h_x_eq_y : x = y,
{ rw [subtype.ext_iff, β hyβ], simp },
rwa h_x_eq_y
end
protected lemma span_apply (i : ΞΉ) : (basis.span hli i : M) = v i :=
congr_arg (coe : span R (range v) β M) $ basis.mk_apply (linear_independent_span hli) _ i
end span
lemma group_smul_span_eq_top
{G : Type*} [group G] [distrib_mul_action G R] [distrib_mul_action G M]
[is_scalar_tower G R M] {v : ΞΉ β M} (hv : submodule.span R (set.range v) = β€) {w : ΞΉ β G} :
submodule.span R (set.range (w β’ v)) = β€ :=
begin
rw eq_top_iff,
intros j hj,
rw β hv at hj,
rw submodule.mem_span at hj β’,
refine Ξ» p hp, hj p (Ξ» u hu, _),
obtain β¨i, rflβ© := hu,
have : ((w i)β»ΒΉ β’ 1 : R) β’ w i β’ v i β p := p.smul_mem ((w i)β»ΒΉ β’ 1 : R) (hp β¨i, rflβ©),
rwa [smul_one_smul, inv_smul_smul] at this,
end
/-- Given a basis `v` and a map `w` such that for all `i`, `w i` are elements of a group,
`group_smul` provides the basis corresponding to `w β’ v`. -/
def group_smul {G : Type*} [group G] [distrib_mul_action G R] [distrib_mul_action G M]
[is_scalar_tower G R M] [smul_comm_class G R M] (v : basis ΞΉ R M) (w : ΞΉ β G) :
basis ΞΉ R M :=
@basis.mk ΞΉ R M (w β’ v) _ _ _
(v.linear_independent.group_smul w) (group_smul_span_eq_top v.span_eq).ge
lemma group_smul_apply {G : Type*} [group G] [distrib_mul_action G R] [distrib_mul_action G M]
[is_scalar_tower G R M] [smul_comm_class G R M] {v : basis ΞΉ R M} {w : ΞΉ β G} (i : ΞΉ) :
v.group_smul w i = (w β’ v : ΞΉ β M) i :=
mk_apply
(v.linear_independent.group_smul w) (group_smul_span_eq_top v.span_eq).ge i
lemma units_smul_span_eq_top {v : ΞΉ β M} (hv : submodule.span R (set.range v) = β€)
{w : ΞΉ β RΛ£} : submodule.span R (set.range (w β’ v)) = β€ :=
group_smul_span_eq_top hv
/-- Given a basis `v` and a map `w` such that for all `i`, `w i` is a unit, `smul_of_is_unit`
provides the basis corresponding to `w β’ v`. -/
def units_smul (v : basis ΞΉ R M) (w : ΞΉ β RΛ£) :
basis ΞΉ R M :=
@basis.mk ΞΉ R M (w β’ v) _ _ _
(v.linear_independent.units_smul w) (units_smul_span_eq_top v.span_eq).ge
lemma units_smul_apply {v : basis ΞΉ R M} {w : ΞΉ β RΛ£} (i : ΞΉ) :
v.units_smul w i = w i β’ v i :=
mk_apply
(v.linear_independent.units_smul w) (units_smul_span_eq_top v.span_eq).ge i
/-- A version of `smul_of_units` that uses `is_unit`. -/
def is_unit_smul (v : basis ΞΉ R M) {w : ΞΉ β R} (hw : β i, is_unit (w i)):
basis ΞΉ R M :=
units_smul v (Ξ» i, (hw i).unit)
lemma is_unit_smul_apply {v : basis ΞΉ R M} {w : ΞΉ β R} (hw : β i, is_unit (w i)) (i : ΞΉ) :
v.is_unit_smul hw i = w i β’ v i :=
units_smul_apply i
section fin
/-- Let `b` be a basis for a submodule `N` of `M`. If `y : M` is linear independent of `N`
and `y` and `N` together span the whole of `M`, then there is a basis for `M`
whose basis vectors are given by `fin.cons y b`. -/
noncomputable def mk_fin_cons {n : β} {N : submodule R M} (y : M) (b : basis (fin n) R N)
(hli : β (c : R) (x β N), c β’ y + x = 0 β c = 0)
(hsp : β (z : M), β (c : R), z + c β’ y β N) :
basis (fin (n + 1)) R M :=
have span_b : submodule.span R (set.range (N.subtype β b)) = N,
{ rw [set.range_comp, submodule.span_image, b.span_eq, submodule.map_subtype_top] },
@basis.mk _ _ _ (fin.cons y (N.subtype β b) : fin (n + 1) β M) _ _ _
((b.linear_independent.map' N.subtype (submodule.ker_subtype _)) .fin_cons' _ _ $
by { rintros c β¨x, hxβ© hc, rw span_b at hx, exact hli c x hx hc })
(Ξ» x _, by { rw [fin.range_cons, submodule.mem_span_insert', span_b], exact hsp x })
@[simp] lemma coe_mk_fin_cons {n : β} {N : submodule R M} (y : M) (b : basis (fin n) R N)
(hli : β (c : R) (x β N), c β’ y + x = 0 β c = 0)
(hsp : β (z : M), β (c : R), z + c β’ y β N) :
(mk_fin_cons y b hli hsp : fin (n + 1) β M) = fin.cons y (coe β b) :=
coe_mk _ _
/-- Let `b` be a basis for a submodule `N β€ O`. If `y β O` is linear independent of `N`
and `y` and `N` together span the whole of `O`, then there is a basis for `O`
whose basis vectors are given by `fin.cons y b`. -/
noncomputable def mk_fin_cons_of_le {n : β} {N O : submodule R M}
(y : M) (yO : y β O) (b : basis (fin n) R N) (hNO : N β€ O)
(hli : β (c : R) (x β N), c β’ y + x = 0 β c = 0)
(hsp : β (z β O), β (c : R), z + c β’ y β N) :
basis (fin (n + 1)) R O :=
mk_fin_cons β¨y, yOβ© (b.map (submodule.comap_subtype_equiv_of_le hNO).symm)
(Ξ» c x hc hx, hli c x (submodule.mem_comap.mp hc) (congr_arg coe hx))
(Ξ» z, hsp z z.2)
@[simp] lemma coe_mk_fin_cons_of_le {n : β} {N O : submodule R M}
(y : M) (yO : y β O) (b : basis (fin n) R N) (hNO : N β€ O)
(hli : β (c : R) (x β N), c β’ y + x = 0 β c = 0)
(hsp : β (z β O), β (c : R), z + c β’ y β N) :
(mk_fin_cons_of_le y yO b hNO hli hsp : fin (n + 1) β O) =
fin.cons β¨y, yOβ© (submodule.of_le hNO β b) :=
coe_mk_fin_cons _ _ _ _
/-- The basis of `R Γ R` given by the two vectors `(1, 0)` and `(0, 1)`. -/
protected def fin_two_prod (R : Type*) [semiring R] : basis (fin 2) R (R Γ R) :=
basis.of_equiv_fun (linear_equiv.fin_two_arrow R R).symm
@[simp] lemma fin_two_prod_zero (R : Type*) [semiring R] : basis.fin_two_prod R 0 = (1, 0) :=
by simp [basis.fin_two_prod]
@[simp] lemma fin_two_prod_one (R : Type*) [semiring R] : basis.fin_two_prod R 1 = (0, 1) :=
by simp [basis.fin_two_prod]
@[simp] lemma coe_fin_two_prod_repr {R : Type*} [semiring R] (x : R Γ R) :
β((basis.fin_two_prod R).repr x) = ![x.fst, x.snd] :=
rfl
end fin
end basis
end module
section induction
variables [ring R] [is_domain R]
variables [add_comm_group M] [module R M] {b : ΞΉ β M}
/-- If `N` is a submodule with finite rank, do induction on adjoining a linear independent
element to a submodule. -/
def submodule.induction_on_rank_aux (b : basis ΞΉ R M) (P : submodule R M β Sort*)
(ih : β (N : submodule R M),
(β (N' β€ N) (x β N), (β (c : R) (y β N'), c β’ x + y = (0 : M) β c = 0) β P N') β P N)
(n : β) (N : submodule R M)
(rank_le : β {m : β} (v : fin m β N),
linear_independent R (coe β v : fin m β M) β m β€ n) :
P N :=
begin
haveI : decidable_eq M := classical.dec_eq M,
have Pbot : P β₯,
{ apply ih,
intros N N_le x x_mem x_ortho,
exfalso,
simpa using x_ortho 1 0 N.zero_mem },
induction n with n rank_ih generalizing N,
{ suffices : N = β₯,
{ rwa this },
apply eq_bot_of_rank_eq_zero b _ (Ξ» m v hv, nat.le_zero_iff.mp (rank_le v hv)) },
apply ih,
intros N' N'_le x x_mem x_ortho,
apply rank_ih,
intros m v hli,
refine nat.succ_le_succ_iff.mp (rank_le (fin.cons β¨x, x_memβ© (Ξ» i, β¨v i, N'_le (v i).2β©)) _),
convert hli.fin_cons' x _ _,
{ ext i, refine fin.cases _ _ i; simp },
{ intros c y hcy,
refine x_ortho c y (submodule.span_le.mpr _ y.2) hcy,
rintros _ β¨z, rflβ©,
exact (v z).2 }
end
end induction
section division_ring
variables [division_ring K] [add_comm_group V] [add_comm_group V'] [module K V] [module K V']
variables {v : ΞΉ β V} {s t : set V} {x y z : V}
include K
open submodule
namespace basis
section exists_basis
/-- If `s` is a linear independent set of vectors, we can extend it to a basis. -/
noncomputable def extend (hs : linear_independent K (coe : s β V)) :
basis _ K V :=
basis.mk
(@linear_independent.restrict_of_comp_subtype _ _ _ id _ _ _ _ (hs.linear_independent_extend _))
(set_like.coe_subset_coe.mp $ by simpa using hs.subset_span_extend (subset_univ s))
lemma extend_apply_self (hs : linear_independent K (coe : s β V))
(x : hs.extend _) :
basis.extend hs x = x :=
basis.mk_apply _ _ _
@[simp] lemma coe_extend (hs : linear_independent K (coe : s β V)) :
β(basis.extend hs) = coe :=
funext (extend_apply_self hs)
lemma range_extend (hs : linear_independent K (coe : s β V)) :
range (basis.extend hs) = hs.extend (subset_univ _) :=
by rw [coe_extend, subtype.range_coe_subtype, set_of_mem_eq]
/-- If `v` is a linear independent family of vectors, extend it to a basis indexed by a sum type. -/
noncomputable def sum_extend (hs : linear_independent K v) :
basis (ΞΉ β _) K V :=
let s := set.range v,
e : ΞΉ β s := equiv.of_injective v hs.injective,
b := hs.to_subtype_range.extend (subset_univ (set.range v)) in
(basis.extend hs.to_subtype_range).reindex $ equiv.symm $
calc ΞΉ β (b \ s : set V) β s β (b \ s : set V) : equiv.sum_congr e (equiv.refl _)
... β b : equiv.set.sum_diff_subset (hs.to_subtype_range.subset_extend _)
lemma subset_extend {s : set V} (hs : linear_independent K (coe : s β V)) :
s β hs.extend (set.subset_univ _) :=
hs.subset_extend _
section
variables (K V)
/-- A set used to index `basis.of_vector_space`. -/
noncomputable def of_vector_space_index : set V :=
(linear_independent_empty K V).extend (subset_univ _)
/-- Each vector space has a basis. -/
noncomputable def of_vector_space : basis (of_vector_space_index K V) K V :=
basis.extend (linear_independent_empty K V)
lemma of_vector_space_apply_self (x : of_vector_space_index K V) :
of_vector_space K V x = x :=
basis.mk_apply _ _ _
@[simp] lemma coe_of_vector_space :
β(of_vector_space K V) = coe :=
funext (Ξ» x, of_vector_space_apply_self K V x)
lemma of_vector_space_index.linear_independent :
linear_independent K (coe : of_vector_space_index K V β V) :=
by { convert (of_vector_space K V).linear_independent, ext x, rw of_vector_space_apply_self }
lemma range_of_vector_space :
range (of_vector_space K V) = of_vector_space_index K V :=
range_extend _
lemma exists_basis : β s : set V, nonempty (basis s K V) :=
β¨of_vector_space_index K V, β¨of_vector_space K Vβ©β©
end
end exists_basis
end basis
open fintype
variables (K V)
theorem vector_space.card_fintype [fintype K] [fintype V] :
β n : β, card V = (card K) ^ n :=
β¨card (basis.of_vector_space_index K V), module.card_fintype (basis.of_vector_space K V)β©
section atoms_of_submodule_lattice
variables {K V}
/-- For a module over a division ring, the span of a nonzero element is an atom of the
lattice of submodules. -/
lemma nonzero_span_atom (v : V) (hv : v β 0) : is_atom (span K {v} : submodule K V) :=
begin
split,
{ rw submodule.ne_bot_iff, exact β¨v, β¨mem_span_singleton_self v, hvβ©β© },
{ intros T hT, by_contra, apply hT.2,
change (span K {v}) β€ T,
simp_rw [span_singleton_le_iff_mem, β ne.def, submodule.ne_bot_iff] at *,
rcases h with β¨s, β¨hs, hzβ©β©,
cases (mem_span_singleton.1 (hT.1 hs)) with a ha,
have h : a β 0, by { intro h, rw [h, zero_smul] at ha, exact hz ha.symm },
apply_fun (Ξ» x, aβ»ΒΉ β’ x) at ha,
simp_rw [β mul_smul, inv_mul_cancel h, one_smul, ha] at *, exact smul_mem T _ hs},
end
/-- The atoms of the lattice of submodules of a module over a division ring are the
submodules equal to the span of a nonzero element of the module. -/
lemma atom_iff_nonzero_span (W : submodule K V) :
is_atom W β β (v : V) (hv : v β 0), W = span K {v} :=
begin
refine β¨Ξ» h, _, Ξ» h, _ β©,
{ cases h with hbot h,
rcases ((submodule.ne_bot_iff W).1 hbot) with β¨v, β¨hW, hvβ©β©,
refine β¨v, β¨hv, _β©β©,
by_contra heq,
specialize h (span K {v}),
rw [span_singleton_eq_bot, lt_iff_le_and_ne] at h,
exact hv (h β¨(span_singleton_le_iff_mem v W).2 hW, ne.symm heqβ©) },
{ rcases h with β¨v, β¨hv, rflβ©β©, exact nonzero_span_atom v hv },
end
/-- The lattice of submodules of a module over a division ring is atomistic. -/
instance : is_atomistic (submodule K V) :=
{ eq_Sup_atoms :=
begin
intro W,
use {T : submodule K V | β (v : V) (hv : v β W) (hz : v β 0), T = span K {v}},
refine β¨submodule_eq_Sup_le_nonzero_spans W, _β©,
rintros _ β¨w, β¨_, β¨hw, rflβ©β©β©, exact nonzero_span_atom w hw
end }
end atoms_of_submodule_lattice
end division_ring
section field
variables [field K] [add_comm_group V] [add_comm_group V'] [module K V] [module K V']
variables {v : ΞΉ β V} {s t : set V} {x y z : V}
lemma linear_map.exists_left_inverse_of_injective (f : V ββ[K] V')
(hf_inj : f.ker = β₯) : βg:V' ββ[K] V, g.comp f = linear_map.id :=
begin
let B := basis.of_vector_space_index K V,
let hB := basis.of_vector_space K V,
have hBβ : _ := hB.linear_independent.to_subtype_range,
have : linear_independent K (Ξ» x, x : f '' B β V'),
{ have hβ : linear_independent K (Ξ» (x : β₯(βf '' range (basis.of_vector_space _ _))), βx) :=
@linear_independent.image_subtype _ _ _ _ _ _ _ _ _ f hBβ
(show disjoint _ _, by simp [hf_inj]),
rwa [basis.range_of_vector_space K V] at hβ },
let C := this.extend (subset_univ _),
have BC := this.subset_extend (subset_univ _),
let hC := basis.extend this,
haveI : inhabited V := β¨0β©,
refine β¨hC.constr K (C.restrict (inv_fun f)), hB.ext (Ξ» b, _)β©,
rw image_subset_iff at BC,
have fb_eq : f b = hC β¨f b, BC b.2β©,
{ change f b = basis.extend this _,
rw [basis.extend_apply_self, subtype.coe_mk] },
dsimp [hB],
rw [basis.of_vector_space_apply_self, fb_eq, hC.constr_basis],
exact left_inverse_inv_fun (linear_map.ker_eq_bot.1 hf_inj) _
end
lemma submodule.exists_is_compl (p : submodule K V) : β q : submodule K V, is_compl p q :=
let β¨f, hfβ© := p.subtype.exists_left_inverse_of_injective p.ker_subtype in
β¨f.ker, linear_map.is_compl_of_proj $ linear_map.ext_iff.1 hfβ©
instance module.submodule.is_complemented : is_complemented (submodule K V) :=
β¨submodule.exists_is_complβ©
lemma linear_map.exists_right_inverse_of_surjective (f : V ββ[K] V')
(hf_surj : f.range = β€) : βg:V' ββ[K] V, f.comp g = linear_map.id :=
begin
let C := basis.of_vector_space_index K V',
let hC := basis.of_vector_space K V',
haveI : inhabited V := β¨0β©,
use hC.constr K (C.restrict (inv_fun f)),
refine hC.ext (Ξ» c, _),
rw [linear_map.comp_apply, hC.constr_basis],
simp [right_inverse_inv_fun (linear_map.range_eq_top.1 hf_surj) c]
end
/-- Any linear map `f : p ββ[K] V'` defined on a subspace `p` can be extended to the whole
space. -/
lemma linear_map.exists_extend {p : submodule K V} (f : p ββ[K] V') :
β g : V ββ[K] V', g.comp p.subtype = f :=
let β¨g, hgβ© := p.subtype.exists_left_inverse_of_injective p.ker_subtype in
β¨f.comp g, by rw [linear_map.comp_assoc, hg, f.comp_id]β©
open submodule linear_map
/-- If `p < β€` is a subspace of a vector space `V`, then there exists a nonzero linear map
`f : V ββ[K] K` such that `p β€ ker f`. -/
lemma submodule.exists_le_ker_of_lt_top (p : submodule K V) (hp : p < β€) :
β f β (0 : V ββ[K] K), p β€ ker f :=
begin
rcases set_like.exists_of_lt hp with β¨v, -, hpvβ©, clear hp,
rcases (linear_pmap.sup_span_singleton β¨p, 0β© v (1 : K) hpv).to_fun.exists_extend with β¨f, hfβ©,
refine β¨f, _, _β©,
{ rintro rfl, rw [linear_map.zero_comp] at hf,
have := linear_pmap.sup_span_singleton_apply_mk β¨p, 0β© v (1 : K) hpv 0 p.zero_mem 1,
simpa using (linear_map.congr_fun hf _).trans this },
{ refine Ξ» x hx, mem_ker.2 _,
have := linear_pmap.sup_span_singleton_apply_mk β¨p, 0β© v (1 : K) hpv x hx 0,
simpa using (linear_map.congr_fun hf _).trans this }
end
theorem quotient_prod_linear_equiv (p : submodule K V) :
nonempty (((V β§Έ p) Γ p) ββ[K] V) :=
let β¨q, hqβ© := p.exists_is_compl in nonempty.intro $
((quotient_equiv_of_is_compl p q hq).prod (linear_equiv.refl _ _)).trans
(prod_equiv_of_is_compl q p hq.symm)
end field
|
61ab22257e4163ea7ff26767f60d2ee53b56e011
|
4fa161becb8ce7378a709f5992a594764699e268
|
/src/measure_theory/set_integral.lean
|
4ba1b93072c392ee2c60069d1d00bc372d2796dc
|
[
"Apache-2.0"
] |
permissive
|
laughinggas/mathlib
|
e4aa4565ae34e46e834434284cb26bd9d67bc373
|
86dcd5cda7a5017c8b3c8876c89a510a19d49aad
|
refs/heads/master
| 1,669,496,232,688
| 1,592,831,995,000
| 1,592,831,995,000
| 274,155,979
| 0
| 0
|
Apache-2.0
| 1,592,835,190,000
| 1,592,835,189,000
| null |
UTF-8
|
Lean
| false
| false
| 14,976
|
lean
|
/-
Copyright (c) 2020 Zhouhang Zhou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Zhouhang Zhou
-/
import measure_theory.bochner_integration
import measure_theory.indicator_function
import measure_theory.lebesgue_measure
/-!
# Set integral
Integrate a function over a subset of a measure space.
## Main definitions
`measurable_on`, `integrable_on`, `integral_on`
## Notation
`β« a in s, f a` is `measure_theory.integral (s.indicator f)`
-/
noncomputable theory
open set filter topological_space measure_theory measure_theory.simple_func
open_locale classical topological_space interval big_operators
universes u v w
variables {Ξ± : Type u} {Ξ² : Type v} {Ξ³ : Type w}
section measurable_on
variables [measurable_space Ξ±] [measurable_space Ξ²] [has_zero Ξ²] {s : set Ξ±} {f : Ξ± β Ξ²}
/-- `measurable_on s f` means `f` is measurable over the set `s`. -/
def measurable_on (s : set Ξ±) (f : Ξ± β Ξ²) : Prop := measurable (s.indicator f)
@[simp] lemma measurable_on_empty (f : Ξ± β Ξ²) : measurable_on β
f :=
by { rw [measurable_on, indicator_empty], exact measurable_const }
@[simp] lemma measurable.measurable_on_univ (hf : measurable f) : measurable_on univ f :=
hf.if is_measurable.univ measurable_const
@[simp] lemma measurable_on_singleton {Ξ±} [topological_space Ξ±] [t1_space Ξ±]
[measurable_space Ξ±] [opens_measurable_space Ξ±] {a : Ξ±} {f : Ξ± β Ξ²} :
measurable_on {a} f :=
Ξ» s hs, show is_measurable ((indicator {a} f)β»ΒΉ' s),
begin
rw indicator_preimage,
refine is_measurable.union _ (is_measurable_singleton.compl.inter $ measurable_const.preimage hs),
by_cases h : a β fβ»ΒΉ' s,
{ rw inter_eq_self_of_subset_left,
{ exact is_measurable_singleton },
rwa singleton_subset_iff },
rw [singleton_inter_eq_empty.2 h],
exact is_measurable.empty
end
lemma is_measurable.inter_preimage {B : set Ξ²}
(hs : is_measurable s) (hB : is_measurable B) (hf : measurable_on s f):
is_measurable (s β© f β»ΒΉ' B) :=
begin
replace hf : is_measurable ((indicator s f)β»ΒΉ' B) := hf B hB,
rw indicator_preimage at hf,
replace hf := hf.diff _,
rwa union_diff_cancel_right at hf,
{ assume a, simp {contextual := tt} },
exact hs.compl.inter (measurable_const.preimage hB)
end
lemma measurable.measurable_on (hs : is_measurable s) (hf : measurable f) : measurable_on s f :=
hf.if hs measurable_const
lemma measurable_on.subset {t : set Ξ±} (hs : is_measurable s) (h : s β t) (hf : measurable_on t f) :
measurable_on s f :=
begin
have : measurable_on s (indicator t f) := measurable.measurable_on hs hf,
simp only [measurable_on, indicator_indicator] at this,
rwa [inter_eq_self_of_subset_left h] at this
end
lemma measurable_on.union {t : set Ξ±} {f : Ξ± β Ξ²}
(hs : is_measurable s) (ht : is_measurable t) (hsm : measurable_on s f) (htm : measurable_on t f) :
measurable_on (s βͺ t) f :=
begin
assume B hB,
show is_measurable ((indicator (s βͺ t) f)β»ΒΉ' B),
rw indicator_preimage,
refine is_measurable.union _ ((hs.union ht).compl.inter (measurable_const.preimage hB)),
simp only [union_inter_distrib_right],
exact (hs.inter_preimage hB hsm).union (ht.inter_preimage hB htm)
end
end measurable_on
section integrable_on
variables [measure_space Ξ±] [normed_group Ξ²] {s t : set Ξ±} {f g : Ξ± β Ξ²}
/-- `integrable_on s f` means `f` is integrable over the set `s`. -/
def integrable_on (s : set Ξ±) (f : Ξ± β Ξ²) : Prop := integrable (s.indicator f)
lemma integrable_on_congr (h : βx, x β s β f x = g x) : integrable_on s f β integrable_on s g :=
by simp only [integrable_on, indicator_congr h]
lemma integrable_on_congr_ae (h : ββ x, x β s β f x = g x) :
integrable_on s f β integrable_on s g :=
by { apply integrable_congr_ae, exact indicator_congr_ae h }
@[simp] lemma integrable_on_empty (f : Ξ± β Ξ²) : integrable_on β
f :=
by { simp only [integrable_on, indicator_empty], apply integrable_zero }
lemma measure_theory.integrable.integrable_on (s : set Ξ±) (hf : integrable f) : integrable_on s f :=
by { refine integrable_of_le (Ξ»a, _) hf, apply norm_indicator_le_norm_self }
lemma integrable_on.subset (h : s β t) : integrable_on t f β integrable_on s f :=
by { apply integrable_of_le_ae, filter_upwards [] norm_indicator_le_of_subset h _ }
variables {π : Type*} [normed_field π] [normed_space π Ξ²]
lemma integrable_on.smul (s : set Ξ±) (c : π) {f : Ξ± β Ξ²} :
integrable_on s f β integrable_on s (Ξ»a, c β’ f a) :=
by { simp only [integrable_on, indicator_smul], apply integrable.smul }
lemma integrable_on.mul_left (s : set Ξ±) (r : β) {f : Ξ± β β} (hf : integrable_on s f) :
integrable_on s (Ξ»a, r * f a) :=
by { simp only [smul_eq_mul.symm], exact hf.smul s r }
lemma integrable_on.mul_right (s : set Ξ±) (r : β) {f : Ξ± β β} (hf : integrable_on s f) :
integrable_on s (Ξ»a, f a * r) :=
by { simp only [mul_comm], exact hf.mul_left _ _ }
lemma integrable_on.divide (s : set Ξ±) (r : β) {f : Ξ± β β} (hf : integrable_on s f) :
integrable_on s (Ξ»a, f a / r) :=
by { simp only [div_eq_mul_inv], exact hf.mul_right _ _ }
lemma integrable_on.add [measurable_space Ξ²] [opens_measurable_space Ξ²]
(hfm : measurable_on s f) (hfi : integrable_on s f) (hgm : measurable_on s g)
(hgi : integrable_on s g) : integrable_on s (Ξ»a, f a + g a) :=
by { rw [integrable_on, indicator_add], exact hfi.add hfm hgm hgi }
lemma integrable_on.neg (hf : integrable_on s f) : integrable_on s (Ξ»a, -f a) :=
by { rw [integrable_on, indicator_neg], exact hf.neg }
lemma integrable_on.sub [measurable_space Ξ²] [opens_measurable_space Ξ²]
(hfm : measurable_on s f) (hfi : integrable_on s f) (hgm : measurable_on s g)
(hgi : integrable_on s g) : integrable_on s (Ξ»a, f a - g a) :=
by { rw [integrable_on, indicator_sub], exact hfi.sub hfm hgm hgi }
lemma integrable_on.union [measurable_space Ξ²] [opens_measurable_space Ξ²]
(hs : is_measurable s) (ht : is_measurable t) (hsm : measurable_on s f)
(hsi : integrable_on s f) (htm : measurable_on t f) (hti : integrable_on t f) :
integrable_on (s βͺ t) f :=
begin
rw β union_diff_self,
rw [integrable_on, indicator_union_of_disjoint],
{ refine integrable.add hsm hsi (htm.subset _ _) (hti.subset _),
{ exact ht.diff hs },
{ exact diff_subset _ _ },
{ exact diff_subset _ _ } },
exact disjoint_diff
end
lemma integrable_on_norm_iff (s : set Ξ±) (f : Ξ± β Ξ²) :
integrable_on s (Ξ»a, β₯f aβ₯) β integrable_on s f :=
begin
simp only [integrable_on],
convert β integrable_norm_iff (indicator s f),
funext,
apply norm_indicator_eq_indicator_norm
end
end integrable_on
section integral_on
variables [measure_space Ξ±]
[normed_group Ξ²] [second_countable_topology Ξ²] [normed_space β Ξ²] [complete_space Ξ²]
[measurable_space Ξ²] [borel_space Ξ²]
{s t : set Ξ±} {f g : Ξ± β Ξ²}
open set
notation `β«` binders ` in ` s `, ` r:(scoped f, measure_theory.integral (set.indicator s f)) := r
lemma integral_on_undef (h : Β¬ (measurable_on s f β§ integrable_on s f)) : (β« a in s, f a) = 0 :=
integral_undef h
lemma integral_on_non_measurable (h : Β¬ measurable_on s f) : (β« a in s, f a) = 0 :=
integral_non_measurable h
lemma integral_on_non_integrable (h : Β¬ integrable_on s f) : (β« a in s, f a) = 0 :=
integral_non_integrable h
variables (Ξ²)
lemma integral_on_zero (s : set Ξ±) : (β« a in s, (0:Ξ²)) = 0 :=
by simp
variables {Ξ²}
lemma integral_on_congr (h : β a β s, f a = g a) : (β« a in s, f a) = (β« a in s, g a) :=
by simp only [indicator_congr h]
lemma integral_on_congr_of_ae_eq (hf : measurable_on s f) (hg : measurable_on s g)
(h : ββ a, a β s β f a = g a) : (β« a in s, f a) = (β« a in s, g a) :=
integral_congr_ae hf hg (indicator_congr_ae h)
lemma integral_on_congr_of_set (hsm : measurable_on s f) (htm : measurable_on t f)
(h : ββ a, a β s β a β t) : (β« a in s, f a) = (β« a in t, f a) :=
integral_congr_ae hsm htm $ indicator_congr_of_set h
variables (s t)
lemma integral_on_smul (r : β) (f : Ξ± β Ξ²) : (β« a in s, r β’ (f a)) = r β’ (β« a in s, f a) :=
by rw [β integral_smul, indicator_smul]
lemma integral_on_mul_left (r : β) (f : Ξ± β β) : (β« a in s, r * (f a)) = r * (β« a in s, f a) :=
integral_on_smul s r f
lemma integral_on_mul_right (r : β) (f : Ξ± β β) : (β« a in s, (f a) * r) = (β« a in s, f a) * r :=
by { simp only [mul_comm], exact integral_on_mul_left s r f }
lemma integral_on_div (r : β) (f : Ξ± β β) : (β« a in s, (f a) / r) = (β« a in s, f a) / r :=
by { simp only [div_eq_mul_inv], apply integral_on_mul_right }
lemma integral_on_neg (f : Ξ± β Ξ²) : (β« a in s, -f a) = - (β« a in s, f a) :=
by { simp only [indicator_neg], exact integral_neg _ }
variables {s t}
lemma integral_on_add {s : set Ξ±} (hfm : measurable_on s f) (hfi : integrable_on s f) (hgm : measurable_on s g)
(hgi : integrable_on s g) : (β« a in s, f a + g a) = (β« a in s, f a) + (β« a in s, g a) :=
by { simp only [indicator_add], exact integral_add hfm hfi hgm hgi }
lemma integral_on_sub (hfm : measurable_on s f) (hfi : integrable_on s f) (hgm : measurable_on s g)
(hgi : integrable_on s g) : (β« a in s, f a - g a) = (β« a in s, f a) - (β« a in s, g a) :=
by { simp only [indicator_sub], exact integral_sub hfm hfi hgm hgi }
lemma integral_on_le_integral_on_ae {f g : Ξ± β β} (hfm : measurable_on s f) (hfi : integrable_on s f)
(hgm : measurable_on s g) (hgi : integrable_on s g) (h : ββ a, a β s β f a β€ g a) :
(β« a in s, f a) β€ (β« a in s, g a) :=
begin
apply integral_le_integral_ae hfm hfi hgm hgi,
apply indicator_le_indicator_ae,
exact h
end
lemma integral_on_le_integral_on {f g : Ξ± β β} (hfm : measurable_on s f) (hfi : integrable_on s f)
(hgm : measurable_on s g) (hgi : integrable_on s g) (h : β a, a β s β f a β€ g a) :
(β« a in s, f a) β€ (β« a in s, g a) :=
integral_on_le_integral_on_ae hfm hfi hgm hgi $ by filter_upwards [] h
lemma integral_on_union (hsm : measurable_on s f) (hsi : integrable_on s f)
(htm : measurable_on t f) (hti : integrable_on t f) (h : disjoint s t) :
(β« a in (s βͺ t), f a) = (β« a in s, f a) + (β« a in t, f a) :=
by { rw [indicator_union_of_disjoint h, integral_add hsm hsi htm hti] }
lemma integral_on_union_ae (hs : is_measurable s) (ht : is_measurable t) (hsm : measurable_on s f)
(hsi : integrable_on s f) (htm : measurable_on t f) (hti : integrable_on t f) (h : ββ a, a β s β© t) :
(β« a in (s βͺ t), f a) = (β« a in s, f a) + (β« a in t, f a) :=
begin
have := integral_congr_ae _ _ (indicator_union_ae h f),
rw [this, integral_add hsm hsi htm hti],
{ exact hsm.union hs ht htm },
{ exact measurable.add hsm htm }
end
lemma integral_on_nonneg_of_ae {f : Ξ± β β} (hf : ββ a, a β s β 0 β€ f a) : (0:β) β€ (β« a in s, f a) :=
integral_nonneg_of_ae $ by { filter_upwards [hf] Ξ» a h, indicator_nonneg' h }
lemma integral_on_nonneg {f : Ξ± β β} (hf : β a, a β s β 0 β€ f a) : (0:β) β€ (β« a in s, f a) :=
integral_on_nonneg_of_ae $ univ_mem_sets' hf
lemma integral_on_nonpos_of_ae {f : Ξ± β β} (hf : ββ a, a β s β f a β€ 0) : (β« a in s, f a) β€ 0 :=
integral_nonpos_of_nonpos_ae $ by { filter_upwards [hf] Ξ» a h, indicator_nonpos' h }
lemma integral_on_nonpos {f : Ξ± β β} (hf : β a, a β s β f a β€ 0) : (β« a in s, f a) β€ 0 :=
integral_on_nonpos_of_ae $ univ_mem_sets' hf
lemma tendsto_integral_on_of_monotone {s : β β set Ξ±} {f : Ξ± β Ξ²} (hsm : βi, is_measurable (s i))
(h_mono : monotone s) (hfm : measurable_on (Union s) f) (hfi : integrable_on (Union s) f) :
tendsto (Ξ»i, β« a in (s i), f a) at_top (nhds (β« a in (Union s), f a)) :=
let bound : Ξ± β β := indicator (Union s) (Ξ»a, β₯f aβ₯) in
begin
apply tendsto_integral_of_dominated_convergence,
{ assume i, exact hfm.subset (hsm i) (subset_Union _ _) },
{ assumption },
{ show integrable_on (Union s) (Ξ»a, β₯f aβ₯), rwa integrable_on_norm_iff },
{ assume i, apply ae_of_all,
assume a,
rw [norm_indicator_eq_indicator_norm],
exact indicator_le_indicator_of_subset (subset_Union _ _) (Ξ»a, norm_nonneg _) _ },
{ filter_upwards [] Ξ»a, le_trans (tendsto_indicator_of_monotone _ h_mono _ _) (pure_le_nhds _) }
end
lemma tendsto_integral_on_of_antimono (s : β β set Ξ±) (f : Ξ± β Ξ²) (hsm : βi, is_measurable (s i))
(h_mono : βi j, i β€ j β s j β s i) (hfm : measurable_on (s 0) f) (hfi : integrable_on (s 0) f) :
tendsto (Ξ»i, β« a in (s i), f a) at_top (nhds (β« a in (Inter s), f a)) :=
let bound : Ξ± β β := indicator (s 0) (Ξ»a, β₯f aβ₯) in
begin
apply tendsto_integral_of_dominated_convergence,
{ assume i, refine hfm.subset (hsm i) (h_mono _ _ (zero_le _)) },
{ exact hfm.subset (is_measurable.Inter hsm) (Inter_subset _ _) },
{ show integrable_on (s 0) (Ξ»a, β₯f aβ₯), rwa integrable_on_norm_iff },
{ assume i, apply ae_of_all,
assume a,
rw [norm_indicator_eq_indicator_norm],
refine indicator_le_indicator_of_subset (h_mono _ _ (zero_le _)) (Ξ»a, norm_nonneg _) _ },
{ filter_upwards [] Ξ»a, le_trans (tendsto_indicator_of_antimono _ h_mono _ _) (pure_le_nhds _) }
end
-- TODO : prove this for an encodable type
-- by proving an encodable version of `filter.is_countably_generated_at_top_finset_nat `
lemma integral_on_Union (s : β β set Ξ±) (f : Ξ± β Ξ²) (hm : βi, is_measurable (s i))
(hd : β i j, i β j β s i β© s j = β
) (hfm : measurable_on (Union s) f) (hfi : integrable_on (Union s) f) :
(β« a in (Union s), f a) = β'i, β« a in s i, f a :=
suffices h : tendsto (Ξ»n:finset β, β i in n, β« a in s i, f a) at_top (π $ (β« a in (Union s), f a)),
by { rwa tsum_eq_has_sum },
begin
have : (Ξ»n:finset β, β i in n, β« a in s i, f a) = Ξ»n:finset β, β« a in (βiβn, s i), f a,
{ funext,
rw [β integral_finset_sum, indicator_finset_bUnion],
{ assume i hi j hj hij, exact hd i j hij },
{ assume i, refine hfm.subset (hm _) (subset_Union _ _) },
{ assume i, refine hfi.subset (subset_Union _ _) } },
rw this,
refine tendsto_integral_filter_of_dominated_convergence _ _ _ _ _ _ _,
{ exact indicator (Union s) (Ξ» a, β₯f aβ₯) },
{ exact is_countably_generated_at_top_finset_nat },
{ refine univ_mem_sets' (Ξ» n, _),
simp only [mem_set_of_eq],
refine hfm.subset (is_measurable.Union (Ξ» i, is_measurable.Union_Prop (Ξ»h, hm _)))
(bUnion_subset_Union _ _), },
{ assumption },
{ refine univ_mem_sets' (Ξ» n, univ_mem_sets' $ _),
simp only [mem_set_of_eq],
assume a,
rw β norm_indicator_eq_indicator_norm,
refine norm_indicator_le_of_subset (bUnion_subset_Union _ _) _ _ },
{ rw [β integrable_on, integrable_on_norm_iff], assumption },
{ filter_upwards [] Ξ»a, le_trans (tendsto_indicator_bUnion_finset _ _ _) (pure_le_nhds _) }
end
end integral_on
|
f9f56aa338fd70563b0a21d297a10d27d8e23a5b
|
b7f22e51856f4989b970961f794f1c435f9b8f78
|
/tests/lean/unfold_rec3.lean
|
8ee62ebf2aa29a0a20ab86401d5bb218e6a1a47d
|
[
"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
| 244
|
lean
|
open nat
definition nrec [recursor] := @nat.rec
definition myadd x y :=
nrec y (Ξ» n r, succ r) x
theorem myadd_zero : β n, myadd n 0 = n :=
begin
intro n, induction n with n ih,
reflexivity,
esimp [myadd],
state,
rewrite ih
end
|
4afb46ee3ebbb8aa34eb53c1733a2c7681407d17
|
fa02ed5a3c9c0adee3c26887a16855e7841c668b
|
/src/algebra/group_power/identities.lean
|
ad41dc3407a13aaa8278eaf69ec1517218b069d7
|
[
"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
| 3,195
|
lean
|
/-
Copyright (c) 2020 Bryan Gin-ge Chen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Bryan Gin-ge Chen, Kevin Lacker
-/
import tactic.ring
/-!
# Identities
This file contains some "named" commutative ring identities.
-/
variables {R : Type*} [comm_ring R]
{a b xβ xβ xβ xβ xβ
xβ xβ xβ yβ yβ yβ yβ yβ
yβ yβ yβ n : R}
/--
Brahmagupta-Fibonacci identity or Diophantus identity, see
<https://en.wikipedia.org/wiki/Brahmagupta%E2%80%93Fibonacci_identity>.
This sign choice here corresponds to the signs obtained by multiplying two complex numbers.
-/
theorem sq_add_sq_mul_sq_add_sq :
(xβ^2 + xβ^2) * (yβ^2 + yβ^2) = (xβ*yβ - xβ*yβ)^2 + (xβ*yβ + xβ*yβ)^2 :=
by ring
/--
Brahmagupta's identity, see <https://en.wikipedia.org/wiki/Brahmagupta%27s_identity>
-/
theorem sq_add_mul_sq_mul_sq_add_mul_sq :
(xβ^2 + n*xβ^2) * (yβ^2 + n*yβ^2) = (xβ*yβ - n*xβ*yβ)^2 + n*(xβ*yβ + xβ*yβ)^2 :=
by ring
/--
Sophie Germain's identity, see <https://www.cut-the-knot.org/blue/SophieGermainIdentity.shtml>.
-/
theorem pow_four_add_four_mul_pow_four : a^4 + 4*b^4 = ((a - b)^2 + b^2) * ((a + b)^2 + b^2) :=
by ring
/--
Sophie Germain's identity, see <https://www.cut-the-knot.org/blue/SophieGermainIdentity.shtml>.
-/
theorem pow_four_add_four_mul_pow_four' :
a^4 + 4*b^4 = (a^2 - 2*a*b + 2*b^2) * (a^2 + 2*a*b + 2*b^2) :=
by ring
/--
Euler's four-square identity, see <https://en.wikipedia.org/wiki/Euler%27s_four-square_identity>.
This sign choice here corresponds to the signs obtained by multiplying two quaternions.
-/
theorem sum_four_sq_mul_sum_four_sq : (xβ^2 + xβ^2 + xβ^2 + xβ^2) * (yβ^2 + yβ^2 + yβ^2 + yβ^2) =
(xβ*yβ - xβ*yβ - xβ*yβ - xβ*yβ)^2 + (xβ*yβ + xβ*yβ + xβ*yβ - xβ*yβ)^2 +
(xβ*yβ - xβ*yβ + xβ*yβ + xβ*yβ)^2 + (xβ*yβ + xβ*yβ - xβ*yβ + xβ*yβ)^2 :=
by ring
/--
Degen's eight squares identity, see <https://en.wikipedia.org/wiki/Degen%27s_eight-square_identity>.
This sign choice here corresponds to the signs obtained by multiplying two octonions.
-/
theorem sum_eight_sq_mul_sum_eight_sq : (xβ^2 + xβ^2 + xβ^2 + xβ^2 + xβ
^2 + xβ^2 + xβ^2 + xβ^2) *
(yβ^2 + yβ^2 + yβ^2 + yβ^2 + yβ
^2 + yβ^2 + yβ^2 + yβ^2) =
(xβ*yβ - xβ*yβ - xβ*yβ - xβ*yβ - xβ
*yβ
- xβ*yβ - xβ*yβ - xβ*yβ)^2 +
(xβ*yβ + xβ*yβ + xβ*yβ - xβ*yβ + xβ
*yβ - xβ*yβ
- xβ*yβ + xβ*yβ)^2 +
(xβ*yβ - xβ*yβ + xβ*yβ + xβ*yβ + xβ
*yβ + xβ*yβ - xβ*yβ
- xβ*yβ)^2 +
(xβ*yβ + xβ*yβ - xβ*yβ + xβ*yβ + xβ
*yβ - xβ*yβ + xβ*yβ - xβ*yβ
)^2 +
(xβ*yβ
- xβ*yβ - xβ*yβ - xβ*yβ + xβ
*yβ + xβ*yβ + xβ*yβ + xβ*yβ)^2 +
(xβ*yβ + xβ*yβ
- xβ*yβ + xβ*yβ - xβ
*yβ + xβ*yβ - xβ*yβ + xβ*yβ)^2 +
(xβ*yβ + xβ*yβ + xβ*yβ
- xβ*yβ - xβ
*yβ + xβ*yβ + xβ*yβ - xβ*yβ)^2 +
(xβ*yβ - xβ*yβ + xβ*yβ + xβ*yβ
- xβ
*yβ - xβ*yβ + xβ*yβ + xβ*yβ)^2 :=
by ring
|
65e188ba795e24620270f63d3cebc92a5a389acb
|
d406927ab5617694ec9ea7001f101b7c9e3d9702
|
/src/group_theory/group_action/quotient.lean
|
a0c81928181a78ee3d3a20525a488cd2fffea77b
|
[
"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
| 15,479
|
lean
|
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Thomas Browning
-/
import algebra.hom.group_action
import data.fintype.big_operators
import dynamics.periodic_pts
import group_theory.group_action.conj_act
import group_theory.commutator
import group_theory.coset
/-!
# Properties of group actions involving quotient groups
This file proves properties of group actions which use the quotient group construction, notably
* the orbit-stabilizer theorem `card_orbit_mul_card_stabilizer_eq_card_group`
* the class formula `card_eq_sum_card_group_div_card_stabilizer'`
* Burnside's lemma `sum_card_fixed_by_eq_card_orbits_mul_card_group`
-/
universes u v w
variables {Ξ± : Type u} {Ξ² : Type v} {Ξ³ : Type w}
open function
open_locale big_operators
namespace mul_action
variables [group Ξ±]
section quotient_action
open subgroup mul_opposite quotient_group
variables (Ξ²) [monoid Ξ²] [mul_action Ξ² Ξ±] (H : subgroup Ξ±)
/-- A typeclass for when a `mul_action Ξ² Ξ±` descends to the quotient `Ξ± β§Έ H`. -/
class quotient_action : Prop :=
(inv_mul_mem : β (b : Ξ²) {a a' : Ξ±}, aβ»ΒΉ * a' β H β (b β’ a)β»ΒΉ * (b β’ a') β H)
/-- A typeclass for when an `add_action Ξ² Ξ±` descends to the quotient `Ξ± β§Έ H`. -/
class _root_.add_action.quotient_action {Ξ± : Type*} (Ξ² : Type*) [add_group Ξ±] [add_monoid Ξ²]
[add_action Ξ² Ξ±] (H : add_subgroup Ξ±) : Prop :=
(inv_mul_mem : β (b : Ξ²) {a a' : Ξ±}, -a + a' β H β -(b +α΅₯ a) + (b +α΅₯ a') β H)
attribute [to_additive add_action.quotient_action] mul_action.quotient_action
@[to_additive] instance left_quotient_action : quotient_action Ξ± H :=
β¨Ξ» _ _ _ _, by rwa [smul_eq_mul, smul_eq_mul, mul_inv_rev, mul_assoc, inv_mul_cancel_left]β©
@[to_additive] instance right_quotient_action : quotient_action H.normalizer.opposite H :=
β¨Ξ» b c _ _, by rwa [smul_def, smul_def, smul_eq_mul_unop, smul_eq_mul_unop, mul_inv_rev, βmul_assoc,
mem_normalizer_iff'.mp b.prop, mul_assoc, mul_inv_cancel_left]β©
@[to_additive] instance right_quotient_action' [hH : H.normal] : quotient_action Ξ±α΅α΅α΅ H :=
β¨Ξ» _ _ _ _, by rwa [smul_eq_mul_unop, smul_eq_mul_unop, mul_inv_rev, mul_assoc, hH.mem_comm_iff,
mul_assoc, mul_inv_cancel_right]β©
@[to_additive] instance quotient [quotient_action Ξ² H] : mul_action Ξ² (Ξ± β§Έ H) :=
{ smul := Ξ» b, quotient.map' ((β’) b) (Ξ» a a' h, left_rel_apply.mpr $
quotient_action.inv_mul_mem b $ left_rel_apply.mp h),
one_smul := Ξ» q, quotient.induction_on' q (Ξ» a, congr_arg quotient.mk' (one_smul Ξ² a)),
mul_smul := Ξ» b b' q, quotient.induction_on' q (Ξ» a, congr_arg quotient.mk' (mul_smul b b' a)) }
variables {Ξ²}
@[simp, to_additive] lemma quotient.smul_mk [quotient_action Ξ² H] (b : Ξ²) (a : Ξ±) :
(b β’ quotient_group.mk a : Ξ± β§Έ H) = quotient_group.mk (b β’ a) := rfl
@[simp, to_additive] lemma quotient.smul_coe [quotient_action Ξ² H] (b : Ξ²) (a : Ξ±) :
(b β’ a : Ξ± β§Έ H) = β(b β’ a) := rfl
@[simp, to_additive] lemma quotient.mk_smul_out' [quotient_action Ξ² H] (b : Ξ²) (q : Ξ± β§Έ H) :
quotient_group.mk (b β’ q.out') = b β’ q :=
by rw [βquotient.smul_mk, quotient_group.out_eq']
@[simp, to_additive] lemma quotient.coe_smul_out' [quotient_action Ξ² H] (b : Ξ²) (q : Ξ± β§Έ H) :
β(b β’ q.out') = b β’ q :=
quotient.mk_smul_out' H b q
lemma _root_.quotient_group.out'_conj_pow_minimal_period_mem
(a : Ξ±) (q : Ξ± β§Έ H) : q.out'β»ΒΉ * a ^ function.minimal_period ((β’) a) q * q.out' β H :=
by rw [mul_assoc, βquotient_group.eq', quotient_group.out_eq', βsmul_eq_mul, quotient.mk_smul_out',
eq_comm, pow_smul_eq_iff_minimal_period_dvd]
end quotient_action
open quotient_group
/-- The canonical map to the left cosets. -/
def _root_.mul_action_hom.to_quotient (H : subgroup Ξ±) : Ξ± β[Ξ±] Ξ± β§Έ H :=
β¨coe, quotient.smul_coe Hβ©
@[simp] lemma _root_.mul_action_hom.to_quotient_apply (H : subgroup Ξ±) (g : Ξ±) :
mul_action_hom.to_quotient H g = g := rfl
@[to_additive] instance mul_left_cosets_comp_subtype_val (H I : subgroup Ξ±) :
mul_action I (Ξ± β§Έ H) :=
mul_action.comp_hom (Ξ± β§Έ H) (subgroup.subtype I)
variables (Ξ±) {Ξ²} [mul_action Ξ± Ξ²] (x : Ξ²)
/-- The canonical map from the quotient of the stabilizer to the set. -/
@[to_additive "The canonical map from the quotient of the stabilizer to the set. "]
def of_quotient_stabilizer (g : Ξ± β§Έ (mul_action.stabilizer Ξ± x)) : Ξ² :=
quotient.lift_on' g (β’x) $ Ξ» g1 g2 H,
calc g1 β’ x
= g1 β’ (g1β»ΒΉ * g2) β’ x : congr_arg _ ((left_rel_apply.mp H).symm)
... = g2 β’ x : by rw [smul_smul, mul_inv_cancel_left]
@[simp, to_additive] theorem of_quotient_stabilizer_mk (g : Ξ±) :
of_quotient_stabilizer Ξ± x (quotient_group.mk g) = g β’ x :=
rfl
@[to_additive] theorem of_quotient_stabilizer_mem_orbit (g) :
of_quotient_stabilizer Ξ± x g β orbit Ξ± x :=
quotient.induction_on' g $ Ξ» g, β¨g, rflβ©
@[to_additive] theorem of_quotient_stabilizer_smul (g : Ξ±)
(g' : Ξ± β§Έ (mul_action.stabilizer Ξ± x)) :
of_quotient_stabilizer Ξ± x (g β’ g') = g β’ of_quotient_stabilizer Ξ± x g' :=
quotient.induction_on' g' $ Ξ» _, mul_smul _ _ _
@[to_additive] theorem injective_of_quotient_stabilizer :
function.injective (of_quotient_stabilizer Ξ± x) :=
Ξ» yβ yβ, quotient.induction_onβ' yβ yβ $ Ξ» gβ gβ (H : gβ β’ x = gβ β’ x), quotient.sound' $
by { rw [left_rel_apply], show (gββ»ΒΉ * gβ) β’ x = x, rw [mul_smul, β H, inv_smul_smul] }
/-- Orbit-stabilizer theorem. -/
@[to_additive "Orbit-stabilizer theorem."]
noncomputable def orbit_equiv_quotient_stabilizer (b : Ξ²) :
orbit Ξ± b β Ξ± β§Έ (stabilizer Ξ± b) :=
equiv.symm $ equiv.of_bijective
(Ξ» g, β¨of_quotient_stabilizer Ξ± b g, of_quotient_stabilizer_mem_orbit Ξ± b gβ©)
β¨Ξ» x y hxy, injective_of_quotient_stabilizer Ξ± b (by convert congr_arg subtype.val hxy),
Ξ» β¨b, β¨g, hgbβ©β©, β¨g, subtype.eq hgbβ©β©
/-- Orbit-stabilizer theorem. -/
@[to_additive "Orbit-stabilizer theorem."]
noncomputable def orbit_prod_stabilizer_equiv_group (b : Ξ²) :
orbit Ξ± b Γ stabilizer Ξ± b β Ξ± :=
(equiv.prod_congr (orbit_equiv_quotient_stabilizer Ξ± _) (equiv.refl _)).trans
subgroup.group_equiv_quotient_times_subgroup.symm
/-- Orbit-stabilizer theorem. -/
@[to_additive "Orbit-stabilizer theorem."]
lemma card_orbit_mul_card_stabilizer_eq_card_group (b : Ξ²) [fintype Ξ±] [fintype $ orbit Ξ± b]
[fintype $ stabilizer Ξ± b] :
fintype.card (orbit Ξ± b) * fintype.card (stabilizer Ξ± b) = fintype.card Ξ± :=
by rw [β fintype.card_prod, fintype.card_congr (orbit_prod_stabilizer_equiv_group Ξ± b)]
@[simp, to_additive] theorem orbit_equiv_quotient_stabilizer_symm_apply (b : Ξ²) (a : Ξ±) :
((orbit_equiv_quotient_stabilizer Ξ± b).symm a : Ξ²) = a β’ b :=
rfl
@[simp, to_additive] lemma stabilizer_quotient {G} [group G] (H : subgroup G) :
mul_action.stabilizer G ((1 : G) : G β§Έ H) = H :=
by { ext, simp [quotient_group.eq] }
variable (Ξ²)
local notation `Ξ©` := (quotient $ orbit_rel Ξ± Ξ²)
/-- **Class formula** : given `G` a group acting on `X` and `Ο` a function mapping each orbit of `X`
under this action (that is, each element of the quotient of `X` by the relation `orbit_rel G X`) to
an element in this orbit, this gives a (noncomputable) bijection between `X` and the disjoint union
of `G/Stab(Ο(Ο))` over all orbits `Ο`. In most cases you'll want `Ο` to be `quotient.out'`, so we
provide `mul_action.self_equiv_sigma_orbits_quotient_stabilizer` as a special case. -/
@[to_additive "**Class formula** : given `G` an additive group acting on `X` and `Ο` a function
mapping each orbit of `X` under this action (that is, each element of the quotient of `X` by the
relation `orbit_rel G X`) to an element in this orbit, this gives a (noncomputable) bijection
between `X` and the disjoint union of `G/Stab(Ο(Ο))` over all orbits `Ο`. In most cases you'll want
`Ο` to be `quotient.out'`, so we provide `add_action.self_equiv_sigma_orbits_quotient_stabilizer`
as a special case. "]
noncomputable def self_equiv_sigma_orbits_quotient_stabilizer' {Ο : Ξ© β Ξ²}
(hΟ : left_inverse quotient.mk' Ο) : Ξ² β Ξ£ (Ο : Ξ©), Ξ± β§Έ (stabilizer Ξ± (Ο Ο)) :=
calc Ξ²
β Ξ£ (Ο : Ξ©), orbit_rel.quotient.orbit Ο : self_equiv_sigma_orbits' Ξ± Ξ²
... β Ξ£ (Ο : Ξ©), Ξ± β§Έ (stabilizer Ξ± (Ο Ο)) :
equiv.sigma_congr_right (Ξ» Ο,
(equiv.set.of_eq $ orbit_rel.quotient.orbit_eq_orbit_out _ hΟ).trans $
orbit_equiv_quotient_stabilizer Ξ± (Ο Ο))
/-- **Class formula** for a finite group acting on a finite type. See
`mul_action.card_eq_sum_card_group_div_card_stabilizer` for a specialized version using
`quotient.out'`. -/
@[to_additive "**Class formula** for a finite group acting on a finite type. See
`add_action.card_eq_sum_card_add_group_div_card_stabilizer` for a specialized version using
`quotient.out'`."]
lemma card_eq_sum_card_group_div_card_stabilizer' [fintype Ξ±] [fintype Ξ²] [fintype Ξ©]
[Ξ (b : Ξ²), fintype $ stabilizer Ξ± b] {Ο : Ξ© β Ξ²} (hΟ : left_inverse quotient.mk' Ο) :
fintype.card Ξ² = β (Ο : Ξ©), fintype.card Ξ± / fintype.card (stabilizer Ξ± (Ο Ο)) :=
begin
classical,
have : β Ο : Ξ©, fintype.card Ξ± / fintype.card β₯(stabilizer Ξ± (Ο Ο)) =
fintype.card (Ξ± β§Έ stabilizer Ξ± (Ο Ο)),
{ intro Ο,
rw [fintype.card_congr (@subgroup.group_equiv_quotient_times_subgroup Ξ± _ (stabilizer Ξ± $ Ο Ο)),
fintype.card_prod, nat.mul_div_cancel],
exact fintype.card_pos_iff.mpr (by apply_instance) },
simp_rw [this, β fintype.card_sigma, fintype.card_congr
(self_equiv_sigma_orbits_quotient_stabilizer' Ξ± Ξ² hΟ)],
end
/-- **Class formula**. This is a special case of
`mul_action.self_equiv_sigma_orbits_quotient_stabilizer'` with `Ο = quotient.out'`. -/
@[to_additive "**Class formula**. This is a special case of
`add_action.self_equiv_sigma_orbits_quotient_stabilizer'` with `Ο = quotient.out'`. "]
noncomputable def self_equiv_sigma_orbits_quotient_stabilizer :
Ξ² β Ξ£ (Ο : Ξ©), Ξ± β§Έ (stabilizer Ξ± Ο.out') :=
self_equiv_sigma_orbits_quotient_stabilizer' Ξ± Ξ² quotient.out_eq'
/-- **Class formula** for a finite group acting on a finite type. -/
@[to_additive "**Class formula** for a finite group acting on a finite type."]
lemma card_eq_sum_card_group_div_card_stabilizer [fintype Ξ±] [fintype Ξ²] [fintype Ξ©]
[Ξ (b : Ξ²), fintype $ stabilizer Ξ± b] :
fintype.card Ξ² = β (Ο : Ξ©), fintype.card Ξ± / fintype.card (stabilizer Ξ± Ο.out') :=
card_eq_sum_card_group_div_card_stabilizer' Ξ± Ξ² quotient.out_eq'
/-- **Burnside's lemma** : a (noncomputable) bijection between the disjoint union of all
`{x β X | g β’ x = x}` for `g β G` and the product `G Γ X/G`, where `G` is a group acting on `X` and
`X/G`denotes the quotient of `X` by the relation `orbit_rel G X`. -/
@[to_additive "**Burnside's lemma** : a (noncomputable) bijection between the disjoint union of all
`{x β X | g β’ x = x}` for `g β G` and the product `G Γ X/G`, where `G` is an additive group acting
on `X` and `X/G`denotes the quotient of `X` by the relation `orbit_rel G X`. "]
noncomputable def sigma_fixed_by_equiv_orbits_prod_group :
(Ξ£ (a : Ξ±), (fixed_by Ξ± Ξ² a)) β Ξ© Γ Ξ± :=
calc (Ξ£ (a : Ξ±), fixed_by Ξ± Ξ² a)
β {ab : Ξ± Γ Ξ² // ab.1 β’ ab.2 = ab.2} :
(equiv.subtype_prod_equiv_sigma_subtype _).symm
... β {ba : Ξ² Γ Ξ± // ba.2 β’ ba.1 = ba.1} :
(equiv.prod_comm Ξ± Ξ²).subtype_equiv (Ξ» ab, iff.rfl)
... β Ξ£ (b : Ξ²), stabilizer Ξ± b :
equiv.subtype_prod_equiv_sigma_subtype (Ξ» (b : Ξ²) a, a β stabilizer Ξ± b)
... β Ξ£ (Οb : (Ξ£ (Ο : Ξ©), orbit Ξ± Ο.out')), stabilizer Ξ± (Οb.2 : Ξ²) :
(self_equiv_sigma_orbits Ξ± Ξ²).sigma_congr_left'
... β Ξ£ (Ο : Ξ©), (Ξ£ (b : orbit Ξ± Ο.out'), stabilizer Ξ± (b : Ξ²)) :
equiv.sigma_assoc (Ξ» (Ο : Ξ©) (b : orbit Ξ± Ο.out'), stabilizer Ξ± (b : Ξ²))
... β Ξ£ (Ο : Ξ©), (Ξ£ (b : orbit Ξ± Ο.out'), stabilizer Ξ± Ο.out') :
equiv.sigma_congr_right (Ξ» Ο, equiv.sigma_congr_right $
Ξ» β¨b, hbβ©, (stabilizer_equiv_stabilizer_of_orbit_rel hb).to_equiv)
... β Ξ£ (Ο : Ξ©), orbit Ξ± Ο.out' Γ stabilizer Ξ± Ο.out' :
equiv.sigma_congr_right (Ξ» Ο, equiv.sigma_equiv_prod _ _)
... β Ξ£ (Ο : Ξ©), Ξ± :
equiv.sigma_congr_right (Ξ» Ο, orbit_prod_stabilizer_equiv_group Ξ± Ο.out')
... β Ξ© Γ Ξ± :
equiv.sigma_equiv_prod Ξ© Ξ±
/-- **Burnside's lemma** : given a finite group `G` acting on a set `X`, the average number of
elements fixed by each `g β G` is the number of orbits. -/
@[to_additive "**Burnside's lemma** : given a finite additive group `G` acting on a set `X`,
the average number of elements fixed by each `g β G` is the number of orbits. "]
lemma sum_card_fixed_by_eq_card_orbits_mul_card_group [fintype Ξ±] [Ξ a, fintype $ fixed_by Ξ± Ξ² a]
[fintype Ξ©] :
β (a : Ξ±), fintype.card (fixed_by Ξ± Ξ² a) = fintype.card Ξ© * fintype.card Ξ± :=
by rw [β fintype.card_prod, β fintype.card_sigma,
fintype.card_congr (sigma_fixed_by_equiv_orbits_prod_group Ξ± Ξ²)]
@[to_additive] instance is_pretransitive_quotient (G) [group G] (H : subgroup G) :
is_pretransitive G (G β§Έ H) :=
{ exists_smul_eq := begin
rintros β¨xβ© β¨yβ©,
refine β¨y * xβ»ΒΉ, quotient_group.eq.mpr _β©,
simp only [smul_eq_mul, H.one_mem, mul_left_inv, inv_mul_cancel_right],
end }
end mul_action
namespace subgroup
variables {G : Type*} [group G] (H : subgroup G)
lemma normal_core_eq_ker :
H.normal_core = (mul_action.to_perm_hom G (G β§Έ H)).ker :=
begin
refine le_antisymm (Ξ» g hg, equiv.perm.ext (Ξ» q, quotient_group.induction_on q
(Ξ» g', (mul_action.quotient.smul_mk H g g').trans (quotient_group.eq.mpr _))))
(subgroup.normal_le_normal_core.mpr (Ξ» g hg, _)),
{ rw [smul_eq_mul, mul_inv_rev, βinv_inv g', inv_inv],
exact H.normal_core.inv_mem hg g'β»ΒΉ },
{ rw [βH.inv_mem_iff, βmul_one gβ»ΒΉ, βquotient_group.eq, βmul_one g],
exact (mul_action.quotient.smul_mk H g 1).symm.trans (equiv.perm.ext_iff.mp hg (1 : G)) },
end
open quotient_group
/-- Cosets of the centralizer of an element embed into the set of commutators. -/
noncomputable def quotient_centralizer_embedding (g : G) :
G β§Έ centralizer (zpowers (g : G)) βͺ commutator_set G :=
((mul_action.orbit_equiv_quotient_stabilizer (conj_act G) g).trans (quotient_equiv_of_eq
(conj_act.stabilizer_eq_centralizer g))).symm.to_embedding.trans β¨Ξ» x, β¨x * gβ»ΒΉ,
let β¨_, x, rflβ© := x in β¨x, g, rflβ©β©, Ξ» x y, subtype.ext β mul_right_cancel β subtype.ext_iff.mpβ©
lemma quotient_centralizer_embedding_apply (g : G) (x : G) :
quotient_centralizer_embedding g x = β¨β
x, gβ, x, g, rflβ© :=
rfl
/-- If `G` is generated by `S`, then the quotient by the center embeds into `S`-indexed sequences
of commutators. -/
noncomputable def quotient_center_embedding {S : set G} (hS : closure S = β€) :
G β§Έ center G βͺ S β commutator_set G :=
(quotient_equiv_of_eq (center_eq_infi' S hS)).to_embedding.trans ((quotient_infi_embedding _).trans
(function.embedding.Pi_congr_right (Ξ» g, quotient_centralizer_embedding g)))
lemma quotient_center_embedding_apply {S : set G} (hS : closure S = β€) (g : G) (s : S) :
quotient_center_embedding hS g s = β¨β
g, sβ, g, s, rflβ© :=
rfl
end subgroup
|
cfc1df44ba2ce6246f6ace257b1cee098532b59a
|
9dc8cecdf3c4634764a18254e94d43da07142918
|
/src/data/holor.lean
|
db5bee610d7f07b0c5bd07b4d1f43425440547f0
|
[
"Apache-2.0"
] |
permissive
|
jcommelin/mathlib
|
d8456447c36c176e14d96d9e76f39841f69d2d9b
|
ee8279351a2e434c2852345c51b728d22af5a156
|
refs/heads/master
| 1,664,782,136,488
| 1,663,638,983,000
| 1,663,638,983,000
| 132,563,656
| 0
| 0
|
Apache-2.0
| 1,663,599,929,000
| 1,525,760,539,000
|
Lean
|
UTF-8
|
Lean
| false
| false
| 14,759
|
lean
|
/-
Copyright (c) 2018 Alexander Bentkamp. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Alexander Bentkamp
-/
import algebra.module.pi
import algebra.big_operators.basic
/-!
# Basic properties of holors
Holors are indexed collections of tensor coefficients. Confusingly,
they are often called tensors in physics and in the neural network
community.
A holor is simply a multidimensional array of values. The size of a
holor is specified by a `list β`, whose length is called the dimension
of the holor.
The tensor product of `xβ : holor Ξ± dsβ` and `xβ : holor Ξ± dsβ` is the
holor given by `(xβ β xβ) (iβ ++ iβ) = xβ iβ * xβ iβ`. A holor is "of
rank at most 1" if it is a tensor product of one-dimensional holors.
The CP rank of a holor `x` is the smallest N such that `x` is the sum
of N holors of rank at most 1.
Based on the tensor library found in <https://www.isa-afp.org/entries/Deep_Learning.html>
## References
* <https://en.wikipedia.org/wiki/Tensor_rank_decomposition>
-/
universes u
open list
open_locale big_operators
/-- `holor_index ds` is the type of valid index tuples used to identify an entry of a holor
of dimensions `ds`. -/
def holor_index (ds : list β) : Type := {is : list β // forallβ (<) is ds}
namespace holor_index
variables {dsβ dsβ dsβ : list β}
def take : Ξ {dsβ : list β}, holor_index (dsβ ++ dsβ) β holor_index dsβ
| ds is := β¨ list.take (length ds) is.1, forallβ_take_append is.1 ds dsβ is.2 β©
def drop : Ξ {dsβ : list β}, holor_index (dsβ ++ dsβ) β holor_index dsβ
| ds is := β¨ list.drop (length ds) is.1, forallβ_drop_append is.1 ds dsβ is.2 β©
lemma cast_type (is : list β) (eq : dsβ = dsβ) (h : forallβ (<) is dsβ) :
(cast (congr_arg holor_index eq) β¨is, hβ©).val = is :=
by subst eq; refl
def assoc_right :
holor_index (dsβ ++ dsβ ++ dsβ) β holor_index (dsβ ++ (dsβ ++ dsβ)) :=
cast (congr_arg holor_index (append_assoc dsβ dsβ dsβ))
def assoc_left :
holor_index (dsβ ++ (dsβ ++ dsβ)) β holor_index (dsβ ++ dsβ ++ dsβ) :=
cast (congr_arg holor_index (append_assoc dsβ dsβ dsβ).symm)
lemma take_take :
β t : holor_index (dsβ ++ dsβ ++ dsβ),
t.assoc_right.take = t.take.take
| β¨ is , h β© := subtype.eq $ by simp [assoc_right,take, cast_type, list.take_take,
nat.le_add_right, min_eq_left]
lemma drop_take :
β t : holor_index (dsβ ++ dsβ ++ dsβ),
t.assoc_right.drop.take = t.take.drop
| β¨ is , h β© := subtype.eq (by simp [assoc_right, take, drop, cast_type, list.drop_take])
lemma drop_drop :
β t : holor_index (dsβ ++ dsβ ++ dsβ),
t.assoc_right.drop.drop = t.drop
| β¨ is , h β© := subtype.eq (by simp [add_comm, assoc_right, drop, cast_type, list.drop_drop])
end holor_index
/-- Holor (indexed collections of tensor coefficients) -/
def holor (Ξ± : Type u) (ds : list β) := holor_index ds β Ξ±
namespace holor
variables {Ξ± : Type} {d : β} {ds : list β} {dsβ : list β} {dsβ : list β} {dsβ : list β}
instance [inhabited Ξ±] : inhabited (holor Ξ± ds) := β¨Ξ» t, defaultβ©
instance [has_zero Ξ±] : has_zero (holor Ξ± ds) := β¨Ξ» t, 0β©
instance [has_add Ξ±] : has_add (holor Ξ± ds) := β¨Ξ» x y t, x t + y tβ©
instance [has_neg Ξ±] : has_neg (holor Ξ± ds) := β¨Ξ» a t, - a tβ©
instance [add_semigroup Ξ±] : add_semigroup (holor Ξ± ds) :=
by refine_struct { add := (+), .. }; tactic.pi_instance_derive_field
instance [add_comm_semigroup Ξ±] : add_comm_semigroup (holor Ξ± ds) :=
by refine_struct { add := (+), .. }; tactic.pi_instance_derive_field
instance [add_monoid Ξ±] : add_monoid (holor Ξ± ds) :=
by refine_struct { zero := (0 : holor Ξ± ds), add := (+), nsmul := Ξ» n x i, n β’ (x i) };
tactic.pi_instance_derive_field
instance [add_comm_monoid Ξ±] : add_comm_monoid (holor Ξ± ds) :=
by refine_struct { zero := (0 : holor Ξ± ds), add := (+), nsmul := add_monoid.nsmul };
tactic.pi_instance_derive_field
instance [add_group Ξ±] : add_group (holor Ξ± ds) :=
by refine_struct { zero := (0 : holor Ξ± ds), add := (+), nsmul := add_monoid.nsmul,
zsmul := Ξ» n x i, n β’ (x i) };
tactic.pi_instance_derive_field
instance [add_comm_group Ξ±] : add_comm_group (holor Ξ± ds) :=
by refine_struct { zero := (0 : holor Ξ± ds), add := (+), nsmul := add_monoid.nsmul,
zsmul := sub_neg_monoid.zsmul };
tactic.pi_instance_derive_field
/- scalar product -/
instance [has_mul Ξ±] : has_smul Ξ± (holor Ξ± ds) :=
β¨Ξ» a x, Ξ» t, a * x tβ©
instance [semiring Ξ±] : module Ξ± (holor Ξ± ds) := pi.module _ _ _
/-- The tensor product of two holors. -/
def mul [s : has_mul Ξ±] (x : holor Ξ± dsβ) (y : holor Ξ± dsβ) : holor Ξ± (dsβ ++ dsβ) :=
Ξ» t, x (t.take) * y (t.drop)
local infix ` β ` : 70 := mul
lemma cast_type (eq : dsβ = dsβ) (a : holor Ξ± dsβ) :
cast (congr_arg (holor Ξ±) eq) a = (Ξ» t, a (cast (congr_arg holor_index eq.symm) t)) :=
by subst eq; refl
def assoc_right :
holor Ξ± (dsβ ++ dsβ ++ dsβ) β holor Ξ± (dsβ ++ (dsβ ++ dsβ)) :=
cast (congr_arg (holor Ξ±) (append_assoc dsβ dsβ dsβ))
def assoc_left :
holor Ξ± (dsβ ++ (dsβ ++ dsβ)) β holor Ξ± (dsβ ++ dsβ ++ dsβ) :=
cast (congr_arg (holor Ξ±) (append_assoc dsβ dsβ dsβ).symm)
lemma mul_assoc0 [semigroup Ξ±] (x : holor Ξ± dsβ) (y : holor Ξ± dsβ) (z : holor Ξ± dsβ) :
x β y β z = (x β (y β z)).assoc_left :=
funext (assume t : holor_index (dsβ ++ dsβ ++ dsβ),
begin
rw assoc_left,
unfold mul,
rw mul_assoc,
rw [βholor_index.take_take, βholor_index.drop_take, βholor_index.drop_drop],
rw cast_type,
refl,
rw append_assoc
end)
lemma mul_assoc [semigroup Ξ±] (x : holor Ξ± dsβ) (y : holor Ξ± dsβ) (z : holor Ξ± dsβ) :
mul (mul x y) z == (mul x (mul y z)) :=
by simp [cast_heq, mul_assoc0, assoc_left].
lemma mul_left_distrib [distrib Ξ±] (x : holor Ξ± dsβ) (y : holor Ξ± dsβ) (z : holor Ξ± dsβ) :
x β (y + z) = x β y + x β z :=
funext (Ξ»t, left_distrib (x (holor_index.take t)) (y (holor_index.drop t)) (z (holor_index.drop t)))
lemma mul_right_distrib [distrib Ξ±] (x : holor Ξ± dsβ) (y : holor Ξ± dsβ) (z : holor Ξ± dsβ) :
(x + y) β z = x β z + y β z :=
funext $ Ξ»t, add_mul (x (holor_index.take t)) (y (holor_index.take t)) (z (holor_index.drop t))
@[simp] lemma zero_mul {Ξ± : Type} [ring Ξ±] (x : holor Ξ± dsβ) :
(0 : holor Ξ± dsβ) β x = 0 :=
funext (Ξ» t, zero_mul (x (holor_index.drop t)))
@[simp] lemma mul_zero {Ξ± : Type} [ring Ξ±] (x : holor Ξ± dsβ) :
x β (0 :holor Ξ± dsβ) = 0 :=
funext (Ξ» t, mul_zero (x (holor_index.take t)))
lemma mul_scalar_mul [monoid Ξ±] (x : holor Ξ± []) (y : holor Ξ± ds) :
x β y = x β¨[], forallβ.nilβ© β’ y :=
by simp [mul, has_smul.smul, holor_index.take, holor_index.drop]
/- holor slices -/
/-- A slice is a subholor consisting of all entries with initial index i. -/
def slice (x : holor Ξ± (d :: ds)) (i : β) (h : i < d) : holor Ξ± ds :=
(Ξ» is : holor_index ds, x β¨ i :: is.1, forallβ.cons h is.2β©)
/-- The 1-dimensional "unit" holor with 1 in the `j`th position. -/
def unit_vec [monoid Ξ±] [add_monoid Ξ±] (d : β) (j : β) : holor Ξ± [d] :=
Ξ» ti, if ti.1 = [j] then 1 else 0
lemma holor_index_cons_decomp (p: holor_index (d :: ds) β Prop) :
Ξ (t : holor_index (d :: ds)),
(β i is, Ξ h : t.1 = i :: is, p β¨ i :: is, begin rw [βh], exact t.2 end β© ) β p t
| β¨[], hforallββ© hp := absurd (forallβ_nil_left_iff.1 hforallβ) (cons_ne_nil d ds)
| β¨(i :: is), hforallββ© hp := hp i is rfl
/-- Two holors are equal if all their slices are equal. -/
lemma slice_eq (x : holor Ξ± (d :: ds)) (y : holor Ξ± (d :: ds))
(h : slice x = slice y) : x = y :=
funext $ Ξ» t : holor_index (d :: ds), holor_index_cons_decomp (Ξ» t, x t = y t) t $ Ξ» i is hiis,
have hiisdds: forallβ (<) (i :: is) (d :: ds), begin rw [βhiis], exact t.2 end,
have hid: i<d, from (forallβ_cons.1 hiisdds).1,
have hisds: forallβ (<) is ds, from (forallβ_cons.1 hiisdds).2,
calc
x β¨i :: is, _β© = slice x i hid β¨is, hisdsβ© : congr_arg (Ξ» t, x t) (subtype.eq rfl)
... = slice y i hid β¨is, hisdsβ© : by rw h
... = y β¨i :: is, _β© : congr_arg (Ξ» t, y t) (subtype.eq rfl)
lemma slice_unit_vec_mul [ring Ξ±] {i : β} {j : β}
(hid : i < d) (x : holor Ξ± ds) :
slice (unit_vec d j β x) i hid = if i=j then x else 0 :=
funext $ Ξ» t : holor_index ds, if h : i = j
then by simp [slice, mul, holor_index.take, unit_vec, holor_index.drop, h]
else by simp [slice, mul, holor_index.take, unit_vec, holor_index.drop, h]; refl
lemma slice_add [has_add Ξ±] (i : β) (hid : i < d) (x : holor Ξ± (d :: ds)) (y : holor Ξ± (d :: ds)) :
slice x i hid + slice y i hid = slice (x + y) i hid := funext (Ξ» t, by simp [slice,(+)])
lemma slice_zero [has_zero Ξ±] (i : β) (hid : i < d) :
slice (0 : holor Ξ± (d :: ds)) i hid = 0 := rfl
lemma slice_sum [add_comm_monoid Ξ±] {Ξ² : Type}
(i : β) (hid : i < d) (s : finset Ξ²) (f : Ξ² β holor Ξ± (d :: ds)) :
β x in s, slice (f x) i hid = slice (β x in s, f x) i hid :=
begin
letI := classical.dec_eq Ξ²,
refine finset.induction_on s _ _,
{ simp [slice_zero] },
{ intros _ _ h_not_in ih,
rw [finset.sum_insert h_not_in, ih, slice_add, finset.sum_insert h_not_in] }
end
/-- The original holor can be recovered from its slices by multiplying with unit vectors and
summing up. -/
@[simp] lemma sum_unit_vec_mul_slice [ring Ξ±] (x : holor Ξ± (d :: ds)) :
β i in (finset.range d).attach,
unit_vec d i β slice x i (nat.succ_le_of_lt (finset.mem_range.1 i.prop)) = x :=
begin
apply slice_eq _ _ _,
ext i hid,
rw [βslice_sum],
simp only [slice_unit_vec_mul hid],
rw finset.sum_eq_single (subtype.mk i $ finset.mem_range.2 hid),
{ simp },
{ assume (b : {x // x β finset.range d}) (hb : b β (finset.range d).attach) (hbi : b β β¨i, _β©),
have hbi' : i β b,
{ simpa only [ne.def, subtype.ext_iff, subtype.coe_mk] using hbi.symm },
simp [hbi'] },
{ assume hid' : subtype.mk i _ β finset.attach (finset.range d),
exfalso,
exact absurd (finset.mem_attach _ _) hid' }
end
/- CP rank -/
/-- `cprank_max1 x` means `x` has CP rank at most 1, that is,
it is the tensor product of 1-dimensional holors. -/
inductive cprank_max1 [has_mul Ξ±]: Ξ {ds}, holor Ξ± ds β Prop
| nil (x : holor Ξ± []) :
cprank_max1 x
| cons {d} {ds} (x : holor Ξ± [d]) (y : holor Ξ± ds) :
cprank_max1 y β cprank_max1 (x β y)
/-- `cprank_max N x` means `x` has CP rank at most `N`, that is,
it can be written as the sum of N holors of rank at most 1. -/
inductive cprank_max [has_mul Ξ±] [add_monoid Ξ±] : β β Ξ {ds}, holor Ξ± ds β Prop
| zero {ds} :
cprank_max 0 (0 : holor Ξ± ds)
| succ n {ds} (x : holor Ξ± ds) (y : holor Ξ± ds) :
cprank_max1 x β cprank_max n y β cprank_max (n+1) (x + y)
lemma cprank_max_nil [monoid Ξ±] [add_monoid Ξ±] (x : holor Ξ± nil) : cprank_max 1 x :=
have h : _, from cprank_max.succ 0 x 0 (cprank_max1.nil x) (cprank_max.zero),
by rwa [add_zero x, zero_add] at h
lemma cprank_max_1 [monoid Ξ±] [add_monoid Ξ±] {x : holor Ξ± ds}
(h : cprank_max1 x) : cprank_max 1 x :=
have h' : _, from cprank_max.succ 0 x 0 h cprank_max.zero,
by rwa [zero_add, add_zero] at h'
lemma cprank_max_add [monoid Ξ±] [add_monoid Ξ±]:
β {m : β} {n : β} {x : holor Ξ± ds} {y : holor Ξ± ds},
cprank_max m x β cprank_max n y β cprank_max (m + n) (x + y)
| 0 n x y (cprank_max.zero) hy := by simp [hy]
| (m+1) n _ y (cprank_max.succ k xβ xβ hxβ hxβ) hy :=
begin
simp only [add_comm, add_assoc],
apply cprank_max.succ,
{ assumption },
{ exact cprank_max_add hxβ hy }
end
lemma cprank_max_mul [ring Ξ±] :
β (n : β) (x : holor Ξ± [d]) (y : holor Ξ± ds), cprank_max n y β cprank_max n (x β y)
| 0 x _ (cprank_max.zero) := by simp [mul_zero x, cprank_max.zero]
| (n+1) x _ (cprank_max.succ k yβ yβ hyβ hyβ) :=
begin
rw mul_left_distrib,
rw nat.add_comm,
apply cprank_max_add,
{ exact cprank_max_1 (cprank_max1.cons _ _ hyβ) },
{ exact cprank_max_mul k x yβ hyβ }
end
lemma cprank_max_sum [ring Ξ±] {Ξ²} {n : β} (s : finset Ξ²) (f : Ξ² β holor Ξ± ds) :
(β x β s, cprank_max n (f x)) β cprank_max (s.card * n) (β x in s, f x) :=
by letI := classical.dec_eq Ξ²;
exact finset.induction_on s
(by simp [cprank_max.zero])
(begin
assume x s (h_x_notin_s : x β s) ih h_cprank,
simp only [finset.sum_insert h_x_notin_s,finset.card_insert_of_not_mem h_x_notin_s],
rw nat.right_distrib,
simp only [nat.one_mul, nat.add_comm],
have ih' : cprank_max (finset.card s * n) (β x in s, f x),
{ apply ih,
assume (x : Ξ²) (h_x_in_s: x β s),
simp only [h_cprank, finset.mem_insert_of_mem, h_x_in_s] },
exact (cprank_max_add (h_cprank x (finset.mem_insert_self x s)) ih')
end)
lemma cprank_max_upper_bound [ring Ξ±] : Ξ {ds}, β x : holor Ξ± ds, cprank_max ds.prod x
| [] x := cprank_max_nil x
| (d :: ds) x :=
have h_summands : Ξ (i : {x // x β finset.range d}),
cprank_max ds.prod (unit_vec d i.1 β slice x i.1 (mem_range.1 i.2)),
from Ξ» i, cprank_max_mul _ _ _ (cprank_max_upper_bound (slice x i.1 (mem_range.1 i.2))),
have h_dds_prod : (list.cons d ds).prod = finset.card (finset.range d) * prod ds,
by simp [finset.card_range],
have cprank_max (finset.card (finset.attach (finset.range d)) * prod ds)
(β i in finset.attach (finset.range d), unit_vec d (i.val)βslice x (i.val) (mem_range.1 i.2)),
from cprank_max_sum (finset.range d).attach _ (Ξ» i _, h_summands i),
have h_cprank_max_sum : cprank_max (finset.card (finset.range d) * prod ds)
(β i in finset.attach (finset.range d), unit_vec d (i.val)βslice x (i.val) (mem_range.1 i.2)),
by rwa [finset.card_attach] at this,
begin
rw [βsum_unit_vec_mul_slice x],
rw [h_dds_prod],
exact h_cprank_max_sum,
end
/-- The CP rank of a holor `x`: the smallest N such that
`x` can be written as the sum of N holors of rank at most 1. -/
noncomputable def cprank [ring Ξ±] (x : holor Ξ± ds) : nat :=
@nat.find (Ξ» n, cprank_max n x) (classical.dec_pred _) β¨ds.prod, cprank_max_upper_bound xβ©
lemma cprank_upper_bound [ring Ξ±] :
Ξ {ds}, β x : holor Ξ± ds, cprank x β€ ds.prod :=
Ξ» ds (x : holor Ξ± ds),
by letI := classical.dec_pred (Ξ» (n : β), cprank_max n x);
exact nat.find_min'
β¨ds.prod, show (Ξ» n, cprank_max n x) ds.prod, from cprank_max_upper_bound xβ©
(cprank_max_upper_bound x)
end holor
|
bc3ccabcbcd48b8a833af5c6315014f5bf8aa62a
|
63abd62053d479eae5abf4951554e1064a4c45b4
|
/src/linear_algebra/adic_completion.lean
|
0bf620df633aa5fbc6627e473a0a229a566d0d3b
|
[
"Apache-2.0"
] |
permissive
|
Lix0120/mathlib
|
0020745240315ed0e517cbf32e738d8f9811dd80
|
e14c37827456fc6707f31b4d1d16f1f3a3205e91
|
refs/heads/master
| 1,673,102,855,024
| 1,604,151,044,000
| 1,604,151,044,000
| 308,930,245
| 0
| 0
|
Apache-2.0
| 1,604,164,710,000
| 1,604,163,547,000
| null |
UTF-8
|
Lean
| false
| false
| 7,702
|
lean
|
/-
Copyright (c) 2020 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau
-/
import linear_algebra.smodeq
import ring_theory.ideal.operations
/-!
# Completion of a module with respect to an ideal.
In this file we define the notions of Hausdorff, precomplete, and complete for an `R`-module `M`
with respect to an ideal `I`:
## Main definitions
- `is_Hausdorff I M`: this says that the intersection of `I^n M` is `0`.
- `is_precomplete I M`: this says that every Cauchy sequence converges.
- `is_adic_complete I M`: this says that `M` is Hausdorff and precomplete.
- `Hausdorffification I M`: this is the universal Hausdorff module with a map from `M`.
- `completion I M`: if `I` is finitely generated, then this is the universal complete module (TODO)
with a map from `M`. This map is injective iff `M` is Hausdorff and surjective iff `M` is
precomplete.
-/
open submodule
variables {R : Type*} [comm_ring R] (I : ideal R)
variables (M : Type*) [add_comm_group M] [module R M]
variables {N : Type*} [add_comm_group N] [module R N]
/-- A module `M` is Hausdorff with respect to an ideal `I` if `β I^n M = 0`. -/
@[class] def is_Hausdorff : Prop :=
β x : M, (β n : β, x β‘ 0 [SMOD (I ^ n β’ β€ : submodule R M)]) β x = 0
/-- A module `M` is precomplete with respect to an ideal `I` if every Cauchy sequence converges. -/
@[class] def is_precomplete : Prop :=
β f : β β M, (β {m n}, m β€ n β f m β‘ f n [SMOD (I ^ m β’ β€ : submodule R M)]) β
β L : M, β n, f n β‘ L [SMOD (I ^ n β’ β€ : submodule R M)]
/-- A module `M` is `I`-adically complete if it is Hausdorff and precomplete. -/
@[class] def is_adic_complete : Prop :=
is_Hausdorff I M β§ is_precomplete I M
/-- The Hausdorffification of a module with respect to an ideal. -/
@[reducible] def Hausdorffification : Type* :=
(β¨
n : β, I ^ n β’ β€ : submodule R M).quotient
/-- The completion of a module with respect to an ideal. This is not necessarily Hausdorff.
In fact, this is only complete if the ideal is finitely generated. -/
def adic_completion : submodule R (Ξ n : β, (I ^ n β’ β€ : submodule R M).quotient) :=
{ carrier := { f | β {m n} (h : m β€ n), liftq _ (mkq _)
(by { rw ker_mkq, exact smul_mono (ideal.pow_le_pow h) (le_refl _) }) (f n) = f m },
zero_mem' := Ξ» m n hmn, by rw [pi.zero_apply, pi.zero_apply, linear_map.map_zero],
add_mem' := Ξ» f g hf hg m n hmn, by rw [pi.add_apply, pi.add_apply,
linear_map.map_add, hf hmn, hg hmn],
smul_mem' := Ξ» c f hf m n hmn, by rw [pi.smul_apply, pi.smul_apply, linear_map.map_smul, hf hmn] }
namespace is_Hausdorff
instance bot : is_Hausdorff (β₯ : ideal R) M :=
Ξ» x hx, by simpa only [pow_one β₯, bot_smul, smodeq.bot] using hx 1
variables {M}
protected theorem subsingleton (h : is_Hausdorff (β€ : ideal R) M) : subsingleton M :=
β¨Ξ» x y, eq_of_sub_eq_zero $ h (x - y) $ Ξ» n, by { rw [ideal.top_pow, top_smul], exact smodeq.top }β©
variables (M)
@[priority 100] instance of_subsingleton [subsingleton M] : is_Hausdorff I M :=
Ξ» x _, subsingleton.elim _ _
variables {I M}
theorem infi_pow_smul (h : is_Hausdorff I M) :
(β¨
n : β, I ^ n β’ β€ : submodule R M) = β₯ :=
eq_bot_iff.2 $ Ξ» x hx, (mem_bot _).2 $ h x $ Ξ» n, smodeq.zero.2 $
(mem_infi $ Ξ» n : β, I ^ n β’ β€).1 hx n
end is_Hausdorff
namespace Hausdorffification
/-- The canonical linear map to the Hausdorffification. -/
def of : M ββ[R] Hausdorffification I M := mkq _
variables {I M}
@[elab_as_eliminator]
lemma induction_on {C : Hausdorffification I M β Prop} (x : Hausdorffification I M)
(ih : β x, C (of I M x)) : C x :=
quotient.induction_on' x ih
variables (I M)
instance : is_Hausdorff I (Hausdorffification I M) :=
Ξ» x, quotient.induction_on' x $ Ξ» x hx, (quotient.mk_eq_zero _).2 $ (mem_infi _).2 $ Ξ» n, begin
have := comap_map_mkq (β¨
n : β, I ^ n β’ β€ : submodule R M) (I ^ n β’ β€),
simp only [sup_of_le_right (infi_le (Ξ» n, (I ^ n β’ β€ : submodule R M)) n)] at this,
rw [β this, map_smul'', mem_comap, map_top, range_mkq, β smodeq.zero], exact hx n
end
variables {M} [h : is_Hausdorff I N]
include h
/-- universal property of Hausdorffification: any linear map to a Hausdorff module extends to a
unique map from the Hausdorffification. -/
def lift (f : M ββ[R] N) : Hausdorffification I M ββ[R] N :=
liftq _ f $ map_le_iff_le_comap.1 $ h.infi_pow_smul βΈ le_infi (Ξ» n,
le_trans (map_mono $ infi_le _ n) $ by { rw map_smul'', exact smul_mono (le_refl _) le_top })
theorem lift_of (f : M ββ[R] N) (x : M) : lift I f (of I M x) = f x := rfl
theorem lift_comp_of (f : M ββ[R] N) : (lift I f).comp (of I M) = f :=
linear_map.ext $ Ξ» _, rfl
/-- Uniqueness of lift. -/
theorem lift_eq (f : M ββ[R] N) (g : Hausdorffification I M ββ[R] N) (hg : g.comp (of I M) = f) :
g = lift I f :=
linear_map.ext $ Ξ» x, induction_on x $ Ξ» x, by rw [lift_of, β hg, linear_map.comp_apply]
end Hausdorffification
namespace is_precomplete
instance bot : is_precomplete (β₯ : ideal R) M :=
begin
refine Ξ» f hf, β¨f 1, Ξ» n, _β©, cases n,
{ rw [pow_zero, ideal.one_eq_top, top_smul], exact smodeq.top },
specialize hf (nat.le_add_left 1 n),
rw [pow_one, bot_smul, smodeq.bot] at hf, rw hf
end
instance top : is_precomplete (β€ : ideal R) M :=
Ξ» f hf, β¨0, Ξ» n, by { rw [ideal.top_pow, top_smul], exact smodeq.top }β©
@[priority 100] instance of_subsingleton [subsingleton M] : is_precomplete I M :=
Ξ» f hf, β¨0, Ξ» n, by rw subsingleton.elim (f n) 0β©
end is_precomplete
namespace adic_completion
/-- The canonical linear map to the completion. -/
def of : M ββ[R] adic_completion I M :=
{ to_fun := Ξ» x, β¨Ξ» n, mkq _ x, Ξ» m n hmn, rflβ©,
map_add' := Ξ» x y, rfl,
map_smul' := Ξ» c x, rfl }
@[simp] lemma of_apply (x : M) (n : β) : (of I M x).1 n = mkq _ x := rfl
/-- Linearly evaluating a sequence in the completion at a given input. -/
def eval (n : β) : adic_completion I M ββ[R] (I ^ n β’ β€ : submodule R M).quotient :=
{ to_fun := Ξ» f, f.1 n,
map_add' := Ξ» f g, rfl,
map_smul' := Ξ» c f, rfl }
@[simp] lemma coe_eval (n : β) :
(eval I M n : adic_completion I M β (I ^ n β’ β€ : submodule R M).quotient) = Ξ» f, f.1 n := rfl
lemma eval_apply (n : β) (f : adic_completion I M) : eval I M n f = f.1 n := rfl
lemma eval_of (n : β) (x : M) : eval I M n (of I M x) = mkq _ x := rfl
@[simp] lemma eval_comp_of (n : β) : (eval I M n).comp (of I M) = mkq _ := rfl
@[simp] lemma range_eval (n : β) : (eval I M n).range = β€ :=
linear_map.range_eq_top.2 $ Ξ» x, quotient.induction_on' x $ Ξ» x, β¨of I M x, rflβ©
variables {I M}
@[ext] lemma ext {x y : adic_completion I M} (h : β n, eval I M n x = eval I M n y) : x = y :=
subtype.eq $ funext h
variables (I M)
instance : is_Hausdorff I (adic_completion I M) :=
Ξ» x hx, ext $ Ξ» n, smul_induction_on (smodeq.zero.1 $ hx n)
(Ξ» r hr x _, ((eval I M n).map_smul r x).symm βΈ quotient.induction_on' (eval I M n x)
(Ξ» x, smodeq.zero.2 $ smul_mem_smul hr mem_top))
rfl
(Ξ» _ _ ih1 ih2, by rw [linear_map.map_add, ih1, ih2, linear_map.map_zero, add_zero])
(Ξ» c _ ih, by rw [linear_map.map_smul, ih, linear_map.map_zero, smul_zero])
end adic_completion
namespace is_adic_complete
instance bot : is_adic_complete (β₯ : ideal R) M :=
β¨by apply_instance, by apply_instanceβ©
protected theorem subsingleton (h : is_adic_complete (β€ : ideal R) M) : subsingleton M :=
h.1.subsingleton
@[priority 100] instance of_subsingleton [subsingleton M] : is_adic_complete I M :=
β¨by apply_instance, by apply_instanceβ©
end is_adic_complete
|
2dc3034e0fce3d806a1fe26571e328ea5bb25832
|
95dcf8dea2baf2b4b0a60d438f27c35ae3dd3990
|
/src/category_theory/instances/topological_spaces.lean
|
77ff2856e1f1278646f93121fa2b3e6a5764cbff
|
[
"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,122
|
lean
|
-- Copyright (c) 2017 Scott Morrison. All rights reserved.
-- Released under Apache 2.0 license as described in the file LICENSE.
-- Authors: Patrick Massot, Scott Morrison, Mario Carneiro
import category_theory.concrete_category
import category_theory.full_subcategory
import category_theory.functor_category
import category_theory.adjunction
import category_theory.limits.types
import category_theory.natural_isomorphism
import category_theory.eq_to_hom
import topology.basic
import topology.opens
import order.galois_connection
open category_theory
open category_theory.nat_iso
open topological_space
universe u
namespace category_theory.instances
/-- The category of topological spaces and continuous maps. -/
@[reducible] def Top : Type (u+1) := bundled topological_space
instance (x : Top) : topological_space x := x.str
namespace Top
instance : concrete_category @continuous := β¨@continuous_id, @continuous.compβ©
-- local attribute [class] continuous
-- instance {R S : Top} (f : R βΆ S) : continuous (f : R β S) := f.2
section
open category_theory.limits
variables {J : Type u} [small_category J]
def limit (F : J β₯€ Top.{u}) : cone F :=
{ X := β¨limit (F β forget), β¨ j, (F.obj j).str.induced (limit.Ο (F β forget) j)β©,
Ο :=
{ app := Ξ» j, β¨limit.Ο (F β forget) j, continuous_iff_induced_le.mpr (lattice.le_supr _ j)β©,
naturality' := Ξ» j j' f, subtype.eq ((limit.cone (F β forget)).Ο.naturality f) } }
def limit_is_limit (F : J β₯€ Top.{u}) : is_limit (limit F) :=
by refine is_limit.of_faithful forget (limit.is_limit _) (Ξ» s, β¨_, _β©) (Ξ» s, rfl);
exact continuous_iff_le_coinduced.mpr (lattice.supr_le $ Ξ» j,
induced_le_iff_le_coinduced.mpr $ continuous_iff_le_coinduced.mp (s.Ο.app j).property)
instance : has_limits.{u} Top.{u} :=
Ξ» J π₯ F, by exactI { cone := limit F, is_limit := limit_is_limit F }
instance : preserves_limits (forget : Top.{u} β₯€ Type u) :=
Ξ» J π₯ F, by exactI preserves_limit_of_preserves_limit_cone
(limit.is_limit F) (limit.is_limit (F β forget))
def colimit (F : J β₯€ Top.{u}) : cocone F :=
{ X := β¨colimit (F β forget), β¨
j, (F.obj j).str.coinduced (colimit.ΞΉ (F β forget) j)β©,
ΞΉ :=
{ app := Ξ» j, β¨colimit.ΞΉ (F β forget) j, continuous_iff_le_coinduced.mpr (lattice.infi_le _ j)β©,
naturality' := Ξ» j j' f, subtype.eq ((colimit.cocone (F β forget)).ΞΉ.naturality f) } }
def colimit_is_colimit (F : J β₯€ Top.{u}) : is_colimit (colimit F) :=
by refine is_colimit.of_faithful forget (colimit.is_colimit _) (Ξ» s, β¨_, _β©) (Ξ» s, rfl);
exact continuous_iff_induced_le.mpr (lattice.le_infi $ Ξ» j,
induced_le_iff_le_coinduced.mpr $ continuous_iff_le_coinduced.mp (s.ΞΉ.app j).property)
instance : has_colimits.{u} Top.{u} :=
Ξ» J π₯ F, by exactI { cocone := colimit F, is_colimit := colimit_is_colimit F }
instance : preserves_colimits (forget : Top.{u} β₯€ Type u) :=
Ξ» J π₯ F, by exactI preserves_colimit_of_preserves_colimit_cocone
(colimit.is_colimit F) (colimit.is_colimit (F β forget))
end
def discrete : Type u β₯€ Top.{u} :=
{ obj := Ξ» X, β¨X, β€β©,
map := Ξ» X Y f, β¨f, continuous_topβ© }
def trivial : Type u β₯€ Top.{u} :=
{ obj := Ξ» X, β¨X, β₯β©,
map := Ξ» X Y f, β¨f, continuous_botβ© }
def adjβ : adjunction discrete forget :=
{ hom_equiv := Ξ» X Y,
{ to_fun := Ξ» f, f,
inv_fun := Ξ» f, β¨f, continuous_topβ©,
left_inv := by tidy,
right_inv := by tidy },
unit := { app := Ξ» X, id },
counit := { app := Ξ» X, β¨id, continuous_topβ© } }
def adjβ : adjunction forget trivial :=
{ hom_equiv := Ξ» X Y,
{ to_fun := Ξ» f, β¨f, continuous_botβ©,
inv_fun := Ξ» f, f,
left_inv := by tidy,
right_inv := by tidy },
unit := { app := Ξ» X, β¨id, continuous_botβ© },
counit := { app := Ξ» X, id } }
end Top
variables {X : Top.{u}}
instance : small_category (opens X) := by apply_instance
def nbhd (x : X.Ξ±) := { U : opens X // x β U }
def nbhds (x : X.Ξ±) : small_category (nbhd x) := begin unfold nbhd, apply_instance end
end category_theory.instances
open category_theory.instances
namespace topological_space.opens
/-- `opens.map f` gives the functor from open sets in Y to open set in X,
given by taking preimages under f. -/
def map
{X Y : Top.{u}} (f : X βΆ Y) : opens Y β₯€ opens X :=
{ obj := Ξ» U, β¨ f.val β»ΒΉ' U, f.property _ U.property β©,
map := Ξ» U V i, β¨ β¨ Ξ» a b, i.down.down b β© β© }.
@[simp] lemma map_id_obj (X : Top.{u}) (U : opens X) : (map (π X)).obj U = U := by tidy
@[simp] def map_id (X : Top.{u}) : map (π X) β
functor.id (opens X) :=
{ hom := { app := Ξ» U, π U },
inv := { app := Ξ» U, π U } }
-- We could make f g implicit here, but it's nice to be able to see when
-- they are the identity (often!)
def map_iso {X Y : Top.{u}} (f g : X βΆ Y) (h : f = g) : map f β
map g :=
nat_iso.of_components (Ξ» U, eq_to_iso (congr_fun (congr_arg _ (congr_arg _ h)) _) ) (by obviously)
@[simp] def map_iso_id {X : Top.{u}} (h) : map_iso (π X) (π X) h = iso.refl (map _) := rfl
end topological_space.opens
|
6e32e5c2964bec3bc2af1e6c722e84814244d9b3
|
6df8d5ae3acf20ad0d7f0247d2cee1957ef96df1
|
/Exams/exam_1.lean
|
8011a9c6a14579ef1f6e7a460918aa3bd8ec47e2
|
[] |
no_license
|
derekjohnsonva/CS2102
|
8ed45daa6658e6121bac0f6691eac6147d08246d
|
b3f507d4be824a2511838a1054d04fc9aef3304c
|
refs/heads/master
| 1,648,529,162,527
| 1,578,851,859,000
| 1,578,851,859,000
| 233,433,207
| 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 7,628
|
lean
|
-- CS2102 F19 Exam #1
--Derek Johnson dej3tc
--10/10/19
/-
#1 [10 points]
Complete the following definitions to give examples of
literal values of specified types. Use lambda expressions
to complete the questions involving function types. Make
functions (lambda expressions) simple: we don't care what
the functions do, just that they are of the right types.
-/
open nat
def x := Ξ» (n:β), n
def n : β := 1
def s : string := "CS"
def b : bool := tt
def f1 : β β bool := Ξ» (n: β), tt
def f2 : (β β β) β bool := Ξ» x,tt
def f3 : (β β β) β (β β β) := Ξ» x,x
def t1 : Type := nat
def t2 : Type β Type := Ξ» (Ξ± : Type), Ξ±
/-
#2 [10 points]
Complete the following recursive function definition
so that the function computes the sum of the natural
numbers from 0 to (and including) a given value, n.
-/
def sumto : β β β
| 0 := 0
| (nat.succ n') := nat.succ n' + sumto(n')
/-
#3. [5 points]
We have seen that we can write function *specifications*
in the language of predicate logic, and specifically in
the language of pure functional programming. We also know
we can, and generally do, write *implementations* in the
language of imperative programming (e.g., in Python or in
Java). Complete the following sentence by filling in the
blanks to explain the esssential tradeoff between function
specifications, in the langugae of predicate logic, and
function implementations written in imperative programming
languages, respectively.
Specifications are generally understandable but less efficient
while implementations are generally the opposite: less
understandable but more efficient.
-/
/-
# 4. [10 points]
Natural languages, such as English and Mandarin, are very
powerful, but they have some fundamental weaknesses when it
comes to writing and verifying precise specifications and
claims about properties of algorithms and programs. It is
for this reason that computer scientists often prefer to
write express such things using mathematical logic instead
of natural language.
Name three fundamental weaknesses of natural language when
it comes to carrying out such tasks. You may given one-word
answers if you wish.
A. Ambiguous
B. Not Machine Checkable
C. Too Verbose (in some situations)
-/
/-
#5. [10 points]
What logical proposition expresses the claim that a given
implementation, I, of a function of type β β β, is correct
with respect to a specification, S, of the same function?
Answer: For all natural numbers, implementation I will
hold to / be true for specification S.
-/
/-
#6. [10 points]
What Boolean functions do the following definitions define?
-/
def mystery1 : bool β bool β bool
| tt tt := ff
| ff ff := ff
| _ _ := tt
/-
Answer: Not Equal To
-/
def mystery2 : bool β bool β bool
| tt ff := ff
| _ _ := tt
/-
Answer: Not (a, not b)
-/
/-
#7. [10 points]
Define a function that takes a string, s, and a natural
number, n, and that returns value of type (list string)
in which s is repeated n times. Give you answer by
completing the following definition: fill in underscores
with the answers that are needed. Note that the list
namespace is not open by default, so prefix constructor
names with "list." as we do for the first (base) case.
-/
def repeat : string β β β list string
| s nat.zero := list.nil
| s (nat.succ n') := list.cons s (repeat s n')
#eval repeat "hello" 3
/-
#8. [10 points]
Definea a polymorphic function that takes (1) a type, Ξ±,
(2) a value, s : Ξ±, and (3) a natural number, n, and that
returns a list in which the value, a, is repeated n times.
Make the type argument to this function implicit. Replace
underscores as necessary to give a complete answer. Note
again that the list namespace is not open, so use "fully
qualified" constructor names.
-/
def poly_repeat {Ξ± : Type} : Ξ± β β β list Ξ±
| s nat.zero := list.nil
| s (nat.succ n') := list.cons s (poly_repeat s n')
#eval poly_repeat "hello" 3
/-
#9. [10 points]
Define a data type, an enumerated type, friend_or_foe,
with just two terms, one called friend, one called foe.
Then define a function called eval that takes two terms,
F1 and F2, of this type and returns a term of this type,
where the function implements the following table:
F1 F2 result
friend friend friend
friend foe foe
foe friend foe
foe foe friend
-/
-- Answer here
inductive friend_or_foe : Type
| friend : friend_or_foe
| foe : friend_or_foe
open friend_or_foe
def eval : friend_or_foe β friend_or_foe β friend_or_foe
| friend friend := friend
| friend foe := foe
| foe friend := foe
| foe foe := friend
/-
#10. [10 points]
We studied the higher-order function, map. In particular,
we implemented a version of it, which we called mmap, for
functions of type β β β, and for lists of type (list β).
The function is reproduced next for your reference. Read
and recall how the function works, then continue on to the
questions that follow.
-/
def mmap : (β β β) β list β β list β
| f [] := []
| f (list.cons h t) := list.cons (f h) (mmap f t)
-- An example application of this function
#eval mmap (Ξ» n, n + 1) [1, 2, 3, 4, 5]
/-
A. Write a polymorphic version of this function, called
pmap, that takes (1) two type arguments, Ξ± and Ξ², (2) a
function of type Ξ± β Ξ², and (3) a list of values of type
Ξ±, and that returns the list of values obtained by
applying the given function to each value in the given
list. Make Ξ± and Ξ² implicit arguments.
-/
-- Answer here
def pmap {Ξ± Ξ² : Type} : (Ξ± β Ξ²) β list Ξ± β list Ξ²
| f [] := []
| f (list.cons h t) := list.cons (f h) (pmap f t)
/-
B.
Use #eval to evaluate an application of pmap to a function
of type β to bool and a non-empty list of natural numbers.
Use a lambda abstraction to give the function argument. It
does not matter to us what value the function returns.
-/
-- Answer here
def tttt:= Ξ» (n:β), tt
def list1 := [1,2,3,4,5]
#eval pmap (Ξ» (n:β), tt) [1,2,3,4,5]
/-
#11. [10 points]
Define a data type, prod3_nat, with one constructor,
triple, that takes three natural numbers as arguments,
yielding a term of type prod3_nat. Then write three
"projection functions", prod3_nat_fst, prod3_nat_snd,
and prod3_nat_thd, each of which takes a prod3_nat value
and returns its corresponding component element. Hint:
look to see how we defined the prod type, its pair
constructor, and its two projection functions.
-/
inductive prod3_nat : Type
| triple (a :β ) (b:β ) (c : β ) : prod3_nat
def prod3_nat_fst : prod3_nat β β
| (prod3_nat.triple a b c) := a
def prod3_nat_snd : prod3_nat β β
| (prod3_nat.triple a b c) := b
def prod3_nat_thd : prod3_nat β β
| (prod3_nat.triple a b c) := c
def ss := prod3_nat.triple 2 3 4
#eval prod3_nat_fst ss
/-
Extra credit. Define prod3 as a version
of prod3_nat that is polymorphic in each of
its three components; define polymorphic
projection functions; and then use them to
define a function, rotate_right, that takes
a triple, (a, b, c), and returns the triple
(c, a, b). (Call your type arguments Ξ±,
Ξ², and Ξ³ - alpha, beta, and gamma).
-/
inductive prod3 (Ξ± Ξ² Ξ³ : Type) : Type
| triple (a : Ξ±) (b : Ξ²) (y : Ξ³) : prod3
def prod3_fst {Ξ± Ξ² Ξ³ : Type}: prod3 Ξ± Ξ² Ξ³ β Ξ±
| (prod3.triple a b c) := a
def prod3_snd {Ξ± Ξ² Ξ³ : Type} : prod3 Ξ± Ξ² Ξ³ β Ξ²
| (prod3.triple a b c) := b
def prod3_thd {Ξ± Ξ² Ξ³ : Type} : prod3 Ξ± Ξ² Ξ³ β Ξ³
| (prod3.triple a b c) := c
def rotate_right {Ξ± Ξ² Ξ³ : Type} : prod3 Ξ± Ξ² Ξ³ β prod3 Ξ³ Ξ± Ξ²
| (prod3.triple a b c) := prod3.triple c a b
|
185847859f5bbaa3fbd272d3ad6c0cd8c2c04680
|
63abd62053d479eae5abf4951554e1064a4c45b4
|
/src/algebra/lie/classical.lean
|
0427cc686d174634e62a8bec1d613e93ad691fd0
|
[
"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
| 13,507
|
lean
|
/-
Copyright (c) 2020 Oliver Nash. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Oliver Nash
-/
import algebra.invertible
import algebra.lie.basic
import linear_algebra.matrix
/-!
# Classical Lie algebras
This file is the place to find definitions and basic properties of the classical Lie algebras:
* Aβ = sl(l+1)
* Bβ β so(l+1, l) β so(2l+1)
* Cβ = sp(l)
* Dβ β so(l, l) β so(2l)
## Main definitions
* `lie_algebra.special_linear.sl`
* `lie_algebra.symplectic.sp`
* `lie_algebra.orthogonal.so`
* `lie_algebra.orthogonal.so'`
* `lie_algebra.orthogonal.so_indefinite_equiv`
* `lie_algebra.orthogonal.type_D`
* `lie_algebra.orthogonal.type_B`
* `lie_algebra.orthogonal.type_D_equiv_so'`
* `lie_algebra.orthogonal.type_B_equiv_so'`
## Implementation notes
### Matrices or endomorphisms
Given a finite type and a commutative ring, the corresponding square matrices are equivalent to the
endomorphisms of the corresponding finite-rank free module as Lie algebras, see `lie_equiv_matrix'`.
We can thus define the classical Lie algebras as Lie subalgebras either of matrices or of
endomorphisms. We have opted for the former. At the time of writing (August 2020) it is unclear
which approach should be preferred so the choice should be assumed to be somewhat arbitrary.
### Diagonal quadratic form or diagonal Cartan subalgebra
For the algebras of type `B` and `D`, there are two natural definitions. For example since the
the `2l Γ 2l` matrix:
$$
J = \left[\begin{array}{cc}
0_l & 1_l\\\\
1_l & 0_l
\end{array}\right]
$$
defines a symmetric bilinear form equivalent to that defined by the identity matrix `I`, we can
define the algebras of type `D` to be the Lie subalgebra of skew-adjoint matrices either for `J` or
for `I`. Both definitions have their advantages (in particular the `J`-skew-adjoint matrices define
a Lie algebra for which the diagonal matrices form a Cartan subalgebra) and so we provide both.
We thus also provide equivalences `type_D_equiv_so'`, `so_indefinite_equiv` which show the two
definitions are equivalent. Similarly for the algebras of type `B`.
## Tags
classical lie algebra, special linear, symplectic, orthogonal
-/
universes uβ uβ
namespace lie_algebra
open_locale matrix
variables (n p q l : Type*) (R : Type uβ)
variables [fintype n] [fintype l] [fintype p] [fintype q]
variables [decidable_eq n] [decidable_eq p] [decidable_eq q] [decidable_eq l]
variables [comm_ring R]
@[simp] lemma matrix_trace_commutator_zero (X Y : matrix n n R) : matrix.trace n R R β
X, Yβ = 0 :=
begin
-- TODO: if we use matrix.mul here, we get a timeout
change matrix.trace n R R (X * Y - Y * X) = 0,
erw [linear_map.map_sub, matrix.trace_mul_comm, sub_self]
end
namespace special_linear
/-- The special linear Lie algebra: square matrices of trace zero. -/
def sl : lie_subalgebra R (matrix n n R) :=
{ lie_mem := Ξ» X Y _ _, linear_map.mem_ker.2 $ matrix_trace_commutator_zero _ _ _ _,
..linear_map.ker (matrix.trace n R R) }
lemma sl_bracket (A B : sl n R) : β
A, Bβ.val = A.val β¬ B.val - B.val β¬ A.val := rfl
section elementary_basis
variables {n} (i j : n)
/-- It is useful to define these matrices for explicit calculations in sl n R. -/
abbreviation E : matrix n n R := Ξ» i' j', if i = i' β§ j = j' then 1 else 0
@[simp] lemma E_apply_one : E R i j i j = 1 := if_pos (and.intro rfl rfl)
@[simp] lemma E_apply_zero (i' j' : n) (h : Β¬(i = i' β§ j = j')) : E R i j i' j' = 0 := if_neg h
@[simp] lemma E_diag_zero (h : j β i) : matrix.diag n R R (E R i j) = 0 :=
begin
ext k, rw matrix.diag_apply,
suffices : Β¬(i = k β§ j = k), by exact if_neg this,
rintros β¨eβ, eββ©, apply h, subst eβ, exact eβ,
end
lemma E_trace_zero (h : j β i) : matrix.trace n R R (E R i j) = 0 := by simp [h]
/-- When j β i, the elementary matrices are elements of sl n R, in fact they are part of a natural
basis of sl n R. -/
def Eb (h : j β i) : sl n R :=
β¨E R i j, by { change E R i j β linear_map.ker (matrix.trace n R R), simp [E_trace_zero R i j h], }β©
@[simp] lemma Eb_val (h : j β i) : (Eb R i j h).val = E R i j := rfl
end elementary_basis
lemma sl_non_abelian [nontrivial R] (h : 1 < fintype.card n) : Β¬lie_algebra.is_abelian β₯(sl n R) :=
begin
rcases fintype.exists_pair_of_one_lt_card h with β¨j, i, hijβ©,
let A := Eb R i j hij,
let B := Eb R j i hij.symm,
intros c,
have c' : A.val β¬ B.val = B.val β¬ A.val := by { rw [βsub_eq_zero, βsl_bracket, c.abelian], refl, },
have : (1 : R) = 0 := by simpa [matrix.mul_apply, hij] using (congr_fun (congr_fun c' i) i),
exact one_ne_zero this,
end
end special_linear
namespace symplectic
/-- The matrix defining the canonical skew-symmetric bilinear form. -/
def J : matrix (l β l) (l β l) R := matrix.from_blocks 0 (-1) 1 0
/-- The symplectic Lie algebra: skew-adjoint matrices with respect to the canonical skew-symmetric
bilinear form. -/
def sp : lie_subalgebra R (matrix (l β l) (l β l) R) :=
skew_adjoint_matrices_lie_subalgebra (J l R)
end symplectic
namespace orthogonal
/-- The definite orthogonal Lie subalgebra: skew-adjoint matrices with respect to the symmetric
bilinear form defined by the identity matrix. -/
def so : lie_subalgebra R (matrix n n R) :=
skew_adjoint_matrices_lie_subalgebra (1 : matrix n n R)
@[simp] lemma mem_so (A : matrix n n R) : A β so n R β Aα΅ = -A :=
begin
erw mem_skew_adjoint_matrices_submodule,
simp only [matrix.is_skew_adjoint, matrix.is_adjoint_pair, matrix.mul_one, matrix.one_mul],
end
/-- The indefinite diagonal matrix with `p` 1s and `q` -1s. -/
def indefinite_diagonal : matrix (p β q) (p β q) R :=
matrix.diagonal $ sum.elim (Ξ» _, 1) (Ξ» _, -1)
/-- The indefinite orthogonal Lie subalgebra: skew-adjoint matrices with respect to the symmetric
bilinear form defined by the indefinite diagonal matrix. -/
def so' : lie_subalgebra R (matrix (p β q) (p β q) R) :=
skew_adjoint_matrices_lie_subalgebra $ indefinite_diagonal p q R
/-- A matrix for transforming the indefinite diagonal bilinear form into the definite one, provided
the parameter `i` is a square root of -1. -/
def Pso (i : R) : matrix (p β q) (p β q) R :=
matrix.diagonal $ sum.elim (Ξ» _, 1) (Ξ» _, i)
lemma Pso_inv {i : R} (hi : i*i = -1) : (Pso p q R i) * (Pso p q R (-i)) = 1 :=
begin
ext x y, rcases x; rcases y,
{ -- x y : p
by_cases h : x = y; simp [Pso, indefinite_diagonal, h], },
{ -- x : p, y : q
simp [Pso, indefinite_diagonal], },
{ -- x : q, y : p
simp [Pso, indefinite_diagonal], },
{ -- x y : q
by_cases h : x = y; simp [Pso, indefinite_diagonal, h, hi], },
end
lemma is_unit_Pso {i : R} (hi : i*i = -1) : is_unit (Pso p q R i) :=
β¨{ val := Pso p q R i,
inv := Pso p q R (-i),
val_inv := Pso_inv p q R hi,
inv_val := by { apply matrix.nonsing_inv_left_right, exact Pso_inv p q R hi, }, },
rflβ©
lemma indefinite_diagonal_transform {i : R} (hi : i*i = -1) :
(Pso p q R i)α΅ β¬ (indefinite_diagonal p q R) β¬ (Pso p q R i) = 1 :=
begin
ext x y, rcases x; rcases y,
{ -- x y : p
by_cases h : x = y; simp [Pso, indefinite_diagonal, h], },
{ -- x : p, y : q
simp [Pso, indefinite_diagonal], },
{ -- x : q, y : p
simp [Pso, indefinite_diagonal], },
{ -- x y : q
by_cases h : x = y; simp [Pso, indefinite_diagonal, h, hi], },
end
/-- An equivalence between the indefinite and definite orthogonal Lie algebras, over a ring
containing a square root of -1. -/
noncomputable def so_indefinite_equiv {i : R} (hi : i*i = -1) : so' p q R βββ
Rβ so (p β q) R :=
begin
apply (skew_adjoint_matrices_lie_subalgebra_equiv
(indefinite_diagonal p q R) (Pso p q R i) (is_unit_Pso p q R hi)).trans,
apply lie_algebra.equiv.of_eq,
ext A, rw indefinite_diagonal_transform p q R hi, refl,
end
lemma so_indefinite_equiv_apply {i : R} (hi : i*i = -1) (A : so' p q R) :
(so_indefinite_equiv p q R hi A : matrix (p β q) (p β q) R) = (Pso p q R i)β»ΒΉ β¬ (A : matrix (p β q) (p β q) R) β¬ (Pso p q R i) :=
by erw [lie_algebra.equiv.trans_apply, lie_algebra.equiv.of_eq_apply,
skew_adjoint_matrices_lie_subalgebra_equiv_apply]
/-- A matrix defining a canonical even-rank symmetric bilinear form.
It looks like this as a `2l x 2l` matrix of `l x l` blocks:
[ 0 1 ]
[ 1 0 ]
-/
def JD : matrix (l β l) (l β l) R := matrix.from_blocks 0 1 1 0
/-- The classical Lie algebra of type D as a Lie subalgebra of matrices associated to the matrix
`JD`. -/
def type_D := skew_adjoint_matrices_lie_subalgebra (JD l R)
/-- A matrix transforming the bilinear form defined by the matrix `JD` into a split-signature
diagonal matrix.
It looks like this as a `2l x 2l` matrix of `l x l` blocks:
[ 1 -1 ]
[ 1 1 ]
-/
def PD : matrix (l β l) (l β l) R := matrix.from_blocks 1 (-1) 1 1
/-- The split-signature diagonal matrix. -/
def S := indefinite_diagonal l l R
lemma S_as_blocks : S l R = matrix.from_blocks 1 0 0 (-1) :=
begin
rw [β matrix.diagonal_one, matrix.diagonal_neg, matrix.from_blocks_diagonal],
refl,
end
lemma JD_transform : (PD l R)α΅ β¬ (JD l R) β¬ (PD l R) = (2 : R) β’ (S l R) :=
begin
have h : (PD l R)α΅ β¬ (JD l R) = matrix.from_blocks 1 1 1 (-1) := by
{ simp [PD, JD, matrix.from_blocks_transpose, matrix.from_blocks_multiply], },
erw [h, S_as_blocks, matrix.from_blocks_multiply, matrix.from_blocks_smul],
congr; simp [two_smul],
end
lemma PD_inv [invertible (2 : R)] : (PD l R) * (β
(2 : R) β’ (PD l R)α΅) = 1 :=
begin
have h : β
(2 : R) β’ (1 : matrix l l R) + β
(2 : R) β’ 1 = 1 := by
rw [β smul_add, β (two_smul R _), smul_smul, inv_of_mul_self, one_smul],
erw [matrix.from_blocks_transpose, matrix.from_blocks_smul, matrix.mul_eq_mul,
matrix.from_blocks_multiply],
simp [h],
end
lemma is_unit_PD [invertible (2 : R)] : is_unit (PD l R) :=
β¨{ val := PD l R,
inv := β
(2 : R) β’ (PD l R)α΅,
val_inv := PD_inv l R,
inv_val := by { apply matrix.nonsing_inv_left_right, exact PD_inv l R, }, },
rflβ©
/-- An equivalence between two possible definitions of the classical Lie algebra of type D. -/
noncomputable def type_D_equiv_so' [invertible (2 : R)] :
type_D l R βββ
Rβ so' l l R :=
begin
apply (skew_adjoint_matrices_lie_subalgebra_equiv (JD l R) (PD l R) (is_unit_PD l R)).trans,
apply lie_algebra.equiv.of_eq,
ext A,
rw [JD_transform, β unit_of_invertible_val (2 : R), lie_subalgebra.mem_coe,
mem_skew_adjoint_matrices_lie_subalgebra_unit_smul],
refl,
end
/-- A matrix defining a canonical odd-rank symmetric bilinear form.
It looks like this as a `(2l+1) x (2l+1)` matrix of blocks:
[ 2 0 0 ]
[ 0 0 1 ]
[ 0 1 0 ]
where sizes of the blocks are:
[`1 x 1` `1 x l` `1 x l`]
[`l x 1` `l x l` `l x l`]
[`l x 1` `l x l` `l x l`]
-/
def JB := matrix.from_blocks ((2 : R) β’ 1 : matrix unit unit R) 0 0 (JD l R)
/-- The classical Lie algebra of type B as a Lie subalgebra of matrices associated to the matrix
`JB`. -/
def type_B := skew_adjoint_matrices_lie_subalgebra (JB l R)
/-- A matrix transforming the bilinear form defined by the matrix `JB` into an
almost-split-signature diagonal matrix.
It looks like this as a `(2l+1) x (2l+1)` matrix of blocks:
[ 1 0 0 ]
[ 0 1 -1 ]
[ 0 1 1 ]
where sizes of the blocks are:
[`1 x 1` `1 x l` `1 x l`]
[`l x 1` `l x l` `l x l`]
[`l x 1` `l x l` `l x l`]
-/
def PB := matrix.from_blocks (1 : matrix unit unit R) 0 0 (PD l R)
lemma PB_inv [invertible (2 : R)] : (PB l R) * (matrix.from_blocks 1 0 0 (PD l R)β»ΒΉ) = 1 :=
begin
simp [PB, matrix.from_blocks_multiply, (PD l R).mul_nonsing_inv, is_unit_PD,
β (PD l R).is_unit_iff_is_unit_det]
end
lemma is_unit_PB [invertible (2 : R)] : is_unit (PB l R) :=
β¨{ val := PB l R,
inv := matrix.from_blocks 1 0 0 (PD l R)β»ΒΉ,
val_inv := PB_inv l R,
inv_val := by { apply matrix.nonsing_inv_left_right, exact PB_inv l R, }, },
rflβ©
lemma JB_transform : (PB l R)α΅ β¬ (JB l R) β¬ (PB l R) = (2 : R) β’ matrix.from_blocks 1 0 0 (S l R) :=
by simp [PB, JB, JD_transform, matrix.from_blocks_transpose, matrix.from_blocks_multiply,
matrix.from_blocks_smul]
lemma indefinite_diagonal_assoc :
indefinite_diagonal (unit β l) l R =
matrix.reindex_lie_equiv (equiv.sum_assoc unit l l).symm
(matrix.from_blocks 1 0 0 (indefinite_diagonal l l R)) :=
begin
ext i j,
rcases i with β¨β¨iβ | iββ© | iββ©;
rcases j with β¨β¨jβ | jββ© | jββ©;
simp [indefinite_diagonal, matrix.diagonal],
end
/-- An equivalence between two possible definitions of the classical Lie algebra of type B. -/
noncomputable def type_B_equiv_so' [invertible (2 : R)] :
type_B l R βββ
Rβ so' (unit β l) l R :=
begin
apply (skew_adjoint_matrices_lie_subalgebra_equiv (JB l R) (PB l R) (is_unit_PB l R)).trans,
symmetry,
apply (skew_adjoint_matrices_lie_subalgebra_equiv_transpose
(indefinite_diagonal (unit β l) l R)
(matrix.reindex_alg_equiv (equiv.sum_assoc punit l l)) (matrix.reindex_transpose _ _)).trans,
apply lie_algebra.equiv.of_eq,
ext A,
rw [JB_transform, β unit_of_invertible_val (2 : R), lie_subalgebra.mem_coe, lie_subalgebra.mem_coe,
mem_skew_adjoint_matrices_lie_subalgebra_unit_smul],
simpa [indefinite_diagonal_assoc],
end
end orthogonal
end lie_algebra
|
67f89994ce6ad78b850bfcabf98b3ccd9a632708
|
cc060cf567f81c404a13ee79bf21f2e720fa6db0
|
/lean/20171217-issue-1552.lean
|
1b1dde552e3472fb2f4480bec10668739ff173d3
|
[
"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
| 2,136
|
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 }
-- attribute [reducible] lift_t coe_t coe_b has_coe_to_fun.coe
set_option pp.all true
@[ematch] def FX { C D : Category } { F : Functor C D } { X : C.Obj } : F X = F.onObjects X :=
begin
unfold coe_fn,
unfold has_coe_to_fun.coe,
end
structure NaturalTransformation { C : Category } { D : Category } ( F G : Functor C D ) :=
(components: Ξ X : C.Obj, D.Hom (F X) (G X))
-- With this definition of components (not using the coercion) the `eblast` below works.
-- (components: Ξ X : C.Obj, D.Hom (F.onObjects X) (G.onObjects 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
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
intros,
dunfold coe_fn,
dunfold has_coe_to_fun.coe,
begin[smt]
eblast,
end
end
}
|
720259c257d46e22a941d8aa8c8f920d31030f5f
|
6432ea7a083ff6ba21ea17af9ee47b9c371760f7
|
/tests/lean/529.lean
|
2cef8973f8b39df7a87468b239ab70bcb28e5bf3
|
[
"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
| 422
|
lean
|
import Lean
namespace Foo
def f (x y : Nat) := x + y + x
scoped infix:65 " ++ " => f
end Foo
open Foo in
def f1 (x : Nat) := x ++ x
#print f1
def f2 (x : Nat) := open Foo in x ++ x
#print f2
open Foo in
#print f1
open Lean.Parser.Command in
def syntaxMatcher : Unit :=
match Lean.Syntax.missing with
| `(declId|$id:ident$[.{$ls,*}]?) => () -- unknown parser declId
| _ => ()
|
5582ef9f0bcd034d6c81014379f9ae3a06810f3b
|
f4bff2062c030df03d65e8b69c88f79b63a359d8
|
/src/game/series/tempLevel01.lean
|
f94acbebfd28a4be734b6731bc8aab820020f509
|
[
"Apache-2.0"
] |
permissive
|
adastra7470/real-number-game
|
776606961f52db0eb824555ed2f8e16f92216ea3
|
f9dcb7d9255a79b57e62038228a23346c2dc301b
|
refs/heads/master
| 1,669,221,575,893
| 1,594,669,800,000
| 1,594,669,800,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 2,117
|
lean
|
import game.series.L01defs
namespace xena
-- begin hide
-- if we want to use sigma notation, use
-- import algebra.big_operators
-- open_locale big_operators
-- https://leanprover-community.github.io/mathlib_docs/algebra/big_operators.html
-- end hide
/-
If $\sum a_n$ converges, then $a_n \to 0$.
We take the approach of showing that $(S_n) β M$ then $(S_{n+1}) β M$,
and then using the fact that $a_{n+1} = S_{n+1} - S_n$.
-/
def kth_partial_sum (a : β β β) (k : β) := (finset.range (k+1)).sum a
def seq_partials_over (a : β β β ) : β β β := (Ξ» (n : β), kth_partial_sum a n )
def series_converges (a : β β β) := is_convergent (seq_partials_over a)
/- Lemma
If partial sum sequence of $a_n$ convergent, $a_n β 0$.
-/
lemma seqlim_0_if_sum_converges (a : β β β) :
series_converges a β is_limit a 0 :=
begin
intro h,
cases h with M Mislimit,
-- shift_rule to show that shifted sequence of partial sums also tends to M
have fact := shift_rule (seq_partials_over a) 1 M,
have fact2 := iff.mp fact Mislimit,
-- express `a (m+1)` using partial sums, sum_range_succ seems best way
have fact3 : β m : β, kth_partial_sum a (m+1)
= a (m+1) + kth_partial_sum a (m),
intro m, from finset.sum_range_succ a (m+1),
--we really want fact4, but sum_range_succ couldn't do it directly?
have fact4 : β (m : β), a (m + 1) = kth_partial_sum a (m+1) - kth_partial_sum a (m),
intro n,
specialize fact3 n, -- do I need to do this to reorganise inside quantiifer?
linarith,
-- we can rewrite our goal in terms of `a` shifted by +1
have fact5 : is_limit a 0 β is_limit (Ξ» (m : β), a (m+1)) 0,
from shift_rule a 1 0,
rw fact5,
have fact6:
(Ξ» (n : β), a (n + 1)) = Ξ» (n: β), (kth_partial_sum a (n + 1) - kth_partial_sum a n),
exact funext fact4, -- suggest gave me this!
rw fact6,
unfold seq_partials_over at Mislimit fact2, -- just for clarity
have fact7 := lim_linear
(Ξ» (n : β), kth_partial_sum a (n + 1))
(Ξ» (n : β), kth_partial_sum a n)
M M 1 (-1) fact2 Mislimit,
simp at fact7,
exact fact7,
end
end xena
|
46d686936d98b1140576cfc85e68949a1ca756e9
|
aa3f8992ef7806974bc1ffd468baa0c79f4d6643
|
/library/logic/axioms/classical.lean
|
26a8b3f4a5865f330a6f7c1ed9482ef224497bec
|
[
"Apache-2.0"
] |
permissive
|
codyroux/lean
|
7f8dff750722c5382bdd0a9a9275dc4bb2c58dd3
|
0cca265db19f7296531e339192e9b9bae4a31f8b
|
refs/heads/master
| 1,610,909,964,159
| 1,407,084,399,000
| 1,416,857,075,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 1,813
|
lean
|
-- Copyright (c) 2014 Microsoft Corporation. All rights reserved.
-- Released under Apache 2.0 license as described in the file LICENSE.
-- Author: Leonardo de Moura
-- logic.axioms.classical
-- ======================
import logic.quantifiers logic.cast algebra.relation
open eq.ops
axiom prop_complete (a : Prop) : a = true β¨ a = false
theorem cases (P : Prop β Prop) (H1 : P true) (H2 : P false) (a : Prop) : P a :=
or.elim (prop_complete a)
(assume Ht : a = true, Htβ»ΒΉ βΈ H1)
(assume Hf : a = false, Hfβ»ΒΉ βΈ H2)
theorem cases_on (a : Prop) {P : Prop β Prop} (H1 : P true) (H2 : P false) : P a :=
cases P H1 H2 a
-- this supercedes the em in decidable
theorem em (a : Prop) : a β¨ Β¬a :=
or.elim (prop_complete a)
(assume Ht : a = true, or.inl (eq_true_elim Ht))
(assume Hf : a = false, or.inr (eq_false_elim Hf))
theorem prop_complete_swapped (a : Prop) : a = false β¨ a = true :=
cases (Ξ» x, x = false β¨ x = true)
(or.inr rfl)
(or.inl rfl)
a
theorem propext {a b : Prop} (Hab : a β b) (Hba : b β a) : a = b :=
or.elim (prop_complete a)
(assume Hat, or.elim (prop_complete b)
(assume Hbt, Hat β¬ Hbtβ»ΒΉ)
(assume Hbf, false_elim (Hbf βΈ (Hab (eq_true_elim Hat)))))
(assume Haf, or.elim (prop_complete b)
(assume Hbt, false_elim (Haf βΈ (Hba (eq_true_elim Hbt))))
(assume Hbf, Haf β¬ Hbfβ»ΒΉ))
theorem iff_to_eq {a b : Prop} (H : a β b) : a = b :=
iff.elim (assume H1 H2, propext H1 H2) H
theorem iff_eq_eq {a b : Prop} : (a β b) = (a = b) :=
propext
(assume H, iff_to_eq H)
(assume H, eq_to_iff H)
open relation
theorem iff_congruence [instance] (P : Prop β Prop) : congruence iff iff P :=
congruence.mk
(take (a b : Prop),
assume H : a β b,
show P a β P b, from eq_to_iff (iff_to_eq H βΈ eq.refl (P a)))
|
b4f4889ec6eec31c56c9dc1de01f3fe8768977d2
|
74addaa0e41490cbaf2abd313a764c96df57b05d
|
/Mathlib/Lean3Lib/init/data/string/basic_auto.lean
|
81ea8e834121accec7b4c242fb98e56a5b08c47a
|
[] |
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
| 5,198
|
lean
|
/-
Copyright (c) 2016 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Leonardo de Moura
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.data.list.basic
import Mathlib.Lean3Lib.init.data.char.basic
universes l u_1
namespace Mathlib
/- In the VM, strings are implemented using a dynamic array and UTF-8 encoding.
TODO: we currently cannot mark string_imp as private because
we need to bind string_imp.mk and string_imp.cases_on in the VM.
-/
structure string_imp where
data : List char
def string := string_imp
def list.as_string (s : List char) : string := string_imp.mk s
namespace string
protected instance has_lt : HasLess string :=
{ Less := fun (sβ sβ : string) => string_imp.data sβ < string_imp.data sβ }
/- Remark: this function has a VM builtin efficient implementation. -/
protected instance has_decidable_lt (sβ : string) (sβ : string) : Decidable (sβ < sβ) :=
list.has_decidable_lt (string_imp.data sβ) (string_imp.data sβ)
protected instance has_decidable_eq : DecidableEq string := fun (_x : string) => sorry
def empty : string := string_imp.mk []
def length : string β β := sorry
/- The internal implementation uses dynamic arrays and will perform destructive updates
if the string is not shared. -/
def push : string β char β string := sorry
/- The internal implementation uses dynamic arrays and will perform destructive updates
if the string is not shared. -/
def append : string β string β string := sorry
/- O(n) in the VM, where n is the length of the string -/
def to_list : string β List char := sorry
def fold {Ξ± : Type u_1} (a : Ξ±) (f : Ξ± β char β Ξ±) (s : string) : Ξ± := list.foldl f a (to_list s)
/- In the VM, the string iterator is implemented as a pointer to the string being iterated + index.
TODO: we currently cannot mark interator_imp as private because
we need to bind string_imp.mk and string_imp.cases_on in the VM.
-/
structure iterator_imp where
fst : List char
snd : List char
def iterator := iterator_imp
def mk_iterator : string β iterator := sorry
namespace iterator
def curr : iterator β char := sorry
/- In the VM, `set_curr` is constant time if the string being iterated is not shared and linear time
if it is. -/
def set_curr : iterator β char β iterator := sorry
def next : iterator β iterator := sorry
def prev : iterator β iterator := sorry
def has_next : iterator β Bool := sorry
def has_prev : iterator β Bool := sorry
def insert : iterator β string β iterator := sorry
def remove : iterator β β β iterator := sorry
/- In the VM, `to_string` is a constant time operation. -/
def to_string : iterator β string := sorry
def to_end : iterator β iterator := sorry
def next_to_string : iterator β string := sorry
def prev_to_string : iterator β string := sorry
protected def extract_core : List char β List char β Option (List char) := sorry
def extract : iterator β iterator β Option string := sorry
end iterator
end string
/- The following definitions do not have builtin support in the VM -/
protected instance string.inhabited : Inhabited string := { default := string.empty }
protected instance string.has_sizeof : SizeOf string := { sizeOf := string.length }
protected instance string.has_append : Append string := { append := string.append }
namespace string
def str : string β char β string := push
def is_empty (s : string) : Bool := to_bool (length s = 0)
def front (s : string) : char := iterator.curr (mk_iterator s)
def back (s : string) : char := iterator.curr (iterator.prev (iterator.to_end (mk_iterator s)))
def join (l : List string) : string := list.foldl (fun (r s : string) => r ++ s) empty l
def singleton (c : char) : string := push empty c
def intercalate (s : string) (ss : List string) : string :=
list.as_string (list.intercalate (to_list s) (list.map to_list ss))
namespace iterator
def nextn : iterator β β β iterator := sorry
def prevn : iterator β β β iterator := sorry
end iterator
def pop_back (s : string) : string :=
iterator.prev_to_string (iterator.prev (iterator.to_end (mk_iterator s)))
def popn_back (s : string) (n : β) : string :=
iterator.prev_to_string (iterator.prevn (iterator.to_end (mk_iterator s)) n)
def backn (s : string) (n : β) : string :=
iterator.next_to_string (iterator.prevn (iterator.to_end (mk_iterator s)) n)
end string
protected def char.to_string (c : char) : string := string.singleton c
def string.to_nat (s : string) : β := to_nat_core (string.mk_iterator s) (string.length s) 0
namespace string
theorem empty_ne_str (c : char) (s : string) : empty β str s c := sorry
theorem str_ne_empty (c : char) (s : string) : str s c β empty := ne.symm (empty_ne_str c s)
theorem str_ne_str_left {cβ : char} {cβ : char} (sβ : string) (sβ : string) :
cβ β cβ β str sβ cβ β str sβ cβ :=
sorry
theorem str_ne_str_right (cβ : char) (cβ : char) {sβ : string} {sβ : string} :
sβ β sβ β str sβ cβ β str sβ cβ :=
sorry
end Mathlib
|
19ed879ec59a617175139616f73703fc334ead98
|
82e44445c70db0f03e30d7be725775f122d72f3e
|
/src/geometry/manifold/conformal_groupoid.lean
|
423283f79a1ec155c2ffbe5ba45f8fdf4b12f96b
|
[
"Apache-2.0"
] |
permissive
|
stjordanis/mathlib
|
51e286d19140e3788ef2c470bc7b953e4991f0c9
|
2568d41bca08f5d6bf39d915434c8447e21f42ee
|
refs/heads/master
| 1,631,748,053,501
| 1,627,938,886,000
| 1,627,938,886,000
| 228,728,358
| 0
| 0
|
Apache-2.0
| 1,576,630,588,000
| 1,576,630,587,000
| null |
UTF-8
|
Lean
| false
| false
| 1,056
|
lean
|
/-
Copyright (c) 2021 Yourong Zang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yourong Zang
-/
import analysis.calculus.conformal
import geometry.manifold.charted_space
/-!
# Conformal Groupoid
In this file we define the groupoid of conformal maps on normed spaces.
## Main definitions
* `conformal_groupoid`: the groupoid of conformal local homeomorphisms.
## Tags
conformal, groupoid
-/
variables {X : Type*} [normed_group X] [normed_space β X]
/-- The pregroupoid of conformal maps. -/
def conformal_pregroupoid : pregroupoid X :=
{ property := Ξ» f u, β x, x β u β conformal_at f x,
comp := Ξ» f g u v hf hg hu hv huv x hx, (hg (f x) hx.2).comp x (hf x hx.1),
id_mem := Ξ» x hx, conformal_at_id x,
locality := Ξ» f u hu h x hx, let β¨v, hβ, hβ, hββ© := h x hx in hβ x β¨hx, hββ©,
congr := Ξ» f g u hu h hf x hx, (hf x hx).congr hx hu h, }
/-- The groupoid of conformal maps. -/
def conformal_groupoid : structure_groupoid X := conformal_pregroupoid.groupoid
|
9d90053d907fa808ea2c6e94e5e6b33970cc5b88
|
da3a76c514d38801bae19e8a9e496dc31f8e5866
|
/library/init/meta/interactive.lean
|
3b6616f5962463a7ce12f016e8a99ebaefc69888
|
[
"Apache-2.0"
] |
permissive
|
cipher1024/lean
|
270c1ac5781e6aee12f5c8d720d267563a164beb
|
f5cbdff8932dd30c6dd8eec68f3059393b4f8b3a
|
refs/heads/master
| 1,611,223,459,029
| 1,487,566,573,000
| 1,487,566,573,000
| 83,356,543
| 0
| 0
| null | 1,488,229,336,000
| 1,488,229,336,000
| null |
UTF-8
|
Lean
| false
| false
| 23,658
|
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.meta.tactic init.meta.rewrite_tactic init.meta.simp_tactic
import init.meta.smt.congruence_closure init.category.combinators
import init.meta.lean.parser init.meta.quote
open lean
open lean.parser
local postfix ?:9001 := optional
local postfix *:9001 := many
local notation p ` ?: `:100 d := (Ξ» o, option.get_or_else o d) <$> p?
namespace interactive
/-- (parse p) as the parameter type of an interactive tactic will instruct the Lean parser
to run `p` when parsing the parameter and to pass the parsed value as an argument
to the tactic. -/
@[reducible] meta def parse {Ξ± : Type} [has_quote Ξ±] (p : parser Ξ±) : Type := Ξ±
namespace types
variables {Ξ± Ξ² : Type}
meta def list_of (p : parser Ξ±) := tk "[" *> sep_by "," p <* tk "]"
/-- A 'tactic expression', which uses right-binding power 2 so that it is terminated by
'<|>' (rbp 2), ';' (rbp 1), and ',' (rbp 0). It should be used for any (potentially)
trailing expression parameters. -/
meta def texpr := qexpr 2
meta def using_ident := (tk "using" *> ident)?
meta def with_ident_list := (tk "with" *> ident*) ?: []
meta def without_ident_list := (tk "without" *> ident*) ?: []
meta def location := (tk "at" *> ident*) ?: []
meta def qexpr_list := list_of (qexpr 0)
meta def opt_qexpr_list := qexpr_list ?: []
meta def qexpr_list_or_texpr := qexpr_list <|> return <$> texpr
end types
end interactive
namespace tactic
meta def report_resolve_name_failure {Ξ± : Type} (e : expr) (n : name) : tactic Ξ± :=
if e^.is_choice_macro
then fail ("failed to resolve name '" ++ to_string n ++ "', it is overloaded")
else fail ("failed to resolve name '" ++ to_string n ++ "', unexpected result")
/- allows metavars and report errors -/
meta def i_to_expr (q : pexpr) : tactic expr :=
to_expr q tt tt
/- doesn't allows metavars and report errors -/
meta def i_to_expr_strict (q : pexpr) : tactic expr :=
to_expr q ff tt
namespace interactive
open interactive interactive.types expr
/-
itactic: parse a nested "interactive" tactic. That is, parse
`(` tactic `)`
-/
meta def itactic : Type :=
tactic unit
/-
irtactic: parse a nested "interactive" tactic. That is, parse
`(` tactic `)`
It is similar to itactic, but the interactive mode will report errors
when any of the nested tactics fail. This is good for tactics such as async and abstract.
-/
meta def irtactic : Type :=
tactic unit
/--
This tactic applies to a goal that is either a Pi/forall or starts with a let binder.
If the current goal is a Pi/forall `β x:T, U` (resp `let x:=t in U`) then intro puts `x:T` (resp `x:=t`) in the local context. The new subgoal target is `U`.
If the goal is an arrow `T β U`, then it puts in the local context either `h:T`, and the new goal target is `U`.
If the goal is neither a Pi/forall nor starting with a let definition,
the tactic `intro` applies the tactic `whnf` until the tactic `intro` can be applied or the goal is not `head-reducible`.
-/
meta def intro : parse ident? β tactic unit
| none := intro1 >> skip
| (some h) := tactic.intro h >> skip
/--
Similar to `intro` tactic. The tactic `intros` will keep introducing new hypotheses until the goal target is not a Pi/forall or let binder.
The variant `intros h_1 ... h_n` introduces `n` new hypotheses using the given identifiers to name them.
-/
meta def intros : parse ident* β tactic unit
| [] := tactic.intros >> skip
| hs := intro_lst hs >> skip
/--
The tactic `rename hβ hβ` renames hypothesis `hβ` into `hβ` in the current local context.
-/
meta def rename : parse ident β parse ident β tactic unit :=
tactic.rename
/--
This tactic applies to any goal.
The argument term is a term well-formed in the local context of the main goal.
The tactic apply tries to match the current goal against the conclusion of the type of term.
If it succeeds, then the tactic returns as many subgoals as the number of non-dependent premises
that have not been fixed by type inference or type class resolution.
The tactic `apply` uses higher-order pattern matching, type class resolution, and
first-order unification with dependent types.
-/
meta def apply (q : parse texpr) : tactic unit :=
i_to_expr q >>= tactic.apply
/--
Similar to the `apply` tactic, but it also creates subgoals for dependent premises
that have not been fixed by type inference or type class resolution.
-/
meta def fapply (q : parse texpr) : tactic unit :=
i_to_expr q >>= tactic.fapply
/--
This tactic tries to close the main goal `... |- U` using type class resolution.
It succeeds if it generates a term of type `U` using type class resolution.
-/
meta def apply_instance : tactic unit :=
tactic.apply_instance
/--
This tactic applies to any goal. It behaves like `exact` with a big difference:
the user can leave some holes `_` in the term.
`refine` will generate as many subgoals as there are holes in the term.
Note that some holes may be implicit.
The type of holes must be either synthesized by the system or declared by
an explicit type ascription like (e.g., `(_ : nat β Prop)`).
-/
meta def refine (q : parse texpr) : tactic unit :=
tactic.refine q tt
/--
This tactic looks in the local context for an hypothesis which type is equal to the goal target.
If it is the case, the subgoal is proved. Otherwise, it fails.
-/
meta def assumption : tactic unit :=
tactic.assumption
/--
This tactic applies to any goal. `change U` replaces the main goal target `T` with `U`
providing that `U` is well-formed with respect to the main goal local context,
and `T` and `U` are definitionally equal.
-/
meta def change (q : parse texpr) : tactic unit :=
i_to_expr q >>= tactic.change
/--
This tactic applies to any goal. It gives directly the exact proof
term of the goal. Let `T` be our goal, let `p` be a term of type `U` then
`exact p` succeeds iff `T` and `U` are definitionally equal.
-/
meta def exact (q : parse texpr) : tactic unit :=
do tgt : expr β target,
i_to_expr_strict ``(%%q : %%tgt) >>= tactic.exact
private meta def get_locals : list name β tactic (list expr)
| [] := return []
| (n::ns) := do h β get_local n, hs β get_locals ns, return (h::hs)
/--
`revert hβ ... hβ` applies to any goal with hypotheses `hβ` ... `hβ`.
It moves the hypotheses and its dependencies to the goal target.
This tactic is the inverse of `intro`.
-/
meta def revert (ids : parse ident*) : tactic unit :=
do hs β get_locals ids, revert_lst hs, skip
/- Return (some a) iff p is of the form (- a) -/
private meta def is_neg (p : pexpr) : option pexpr :=
/- Remark: we use the low-level to_raw_expr and of_raw_expr to be able to
pattern match pre-terms. This is a low-level trick (aka hack). -/
match pexpr.to_raw_expr p with
| (app (const c []) arg) := if c = `neg then some (pexpr.of_raw_expr arg) else none
| _ := none
end
private meta def resolve_name' (n : name) : tactic expr :=
do {
e β resolve_name n,
match e with
| expr.const n _ := mk_const n -- create metavars for universe levels
| _ := return e
end
}
/- Version of to_expr that tries to bypass the elaborator if `p` is just a constant or local constant.
This is not an optimization, by skipping the elaborator we make sure that unwanted resolution is used.
Example: the elaborator will force any unassigned ?A that must have be an instance of (has_one ?A) to nat.
Remark: another benefit is that auxiliary temporary metavariables do not appear in error messages. -/
private meta def to_expr' (p : pexpr) : tactic expr :=
let e := pexpr.to_raw_expr p in
match e with
| (const c []) := do new_e β resolve_name' c, save_type_info new_e e, return new_e
| (local_const c _ _ _) := do new_e β resolve_name' c, save_type_info new_e e, return new_e
| _ := i_to_expr p
end
private meta def maybe_save_info : option pos β tactic unit
| (some p) := save_info p.1 p.2
| none := skip
private meta def symm_expr := bool Γ expr Γ option pos
private meta def to_symm_expr_list : list pexpr β tactic (list symm_expr)
| [] := return []
| (p::ps) :=
match is_neg p with
| some a := do r β to_expr' a, rs β to_symm_expr_list ps, return ((tt, r, pexpr.pos p) :: rs)
| none := do r β to_expr' p, rs β to_symm_expr_list ps, return ((ff, r, pexpr.pos p) :: rs)
end
private meta def rw_goal : transparency β list symm_expr β tactic unit
| m [] := return ()
| m ((symm, e, pos)::es) := maybe_save_info pos >> rewrite_core m tt tt occurrences.all symm e >> rw_goal m es
private meta def rw_hyp : transparency β list symm_expr β name β tactic unit
| m [] hname := return ()
| m ((symm, e, pos)::es) hname :=
do h β get_local hname,
maybe_save_info pos,
rewrite_at_core m tt tt occurrences.all symm e h,
rw_hyp m es hname
private meta def rw_hyps : transparency β list symm_expr β list name β tactic unit
| m es [] := return ()
| m es (h::hs) := rw_hyp m es h >> rw_hyps m es hs
private meta def rw_core (m : transparency) (hs : parse qexpr_list_or_texpr) (loc : parse location) : tactic unit :=
do hlist β to_symm_expr_list hs,
match loc with
| [] := rw_goal m hlist >> try (reflexivity reducible)
| hs := rw_hyps m hlist hs >> try (reflexivity reducible)
end
meta def rewrite : parse qexpr_list_or_texpr β parse location β tactic unit :=
rw_core reducible
meta def rw : parse qexpr_list_or_texpr β parse location β tactic unit :=
rewrite
/- rewrite followed by assumption -/
meta def rwa (q : parse qexpr_list_or_texpr) (l : parse location) : tactic unit :=
rewrite q l >> try assumption
meta def erewrite : parse qexpr_list_or_texpr β parse location β tactic unit :=
rw_core semireducible
meta def erw : parse qexpr_list_or_texpr β parse location β tactic unit :=
erewrite
private meta def get_type_name (e : expr) : tactic name :=
do e_type β infer_type e >>= whnf,
(const I ls) β return $ get_app_fn e_type,
return I
meta def induction (p : parse texpr) (rec_name : parse using_ident) (ids : parse with_ident_list) : tactic unit :=
do e β i_to_expr p, tactic.induction e ids rec_name, return ()
meta def cases (p : parse texpr) (ids : parse with_ident_list) : tactic unit :=
do e β i_to_expr p,
tactic.cases e ids
meta def destruct (p : parse texpr) : tactic unit :=
i_to_expr p >>= tactic.destruct
meta def generalize (p : parse qexpr) (x : parse ident) : tactic unit :=
do e β i_to_expr p,
tactic.generalize e x
meta def trivial : tactic unit :=
tactic.triv <|> tactic.reflexivity <|> tactic.contradiction <|> fail "trivial tactic failed"
/-- Closes the main goal using sorry. -/
meta def admit : tactic unit := tactic.admit
/--
This tactic applies to any goal. The contradiction tactic attempts to find in the current local context an hypothesis that is equivalent to
an empty inductive type (e.g. `false`), a hypothesis of the form `c_1 ... = c_2 ...` where `c_1` and `c_2` are distinct constructors,
or two contradictory hypotheses.
-/
meta def contradiction : tactic unit :=
tactic.contradiction
meta def repeat : itactic β tactic unit :=
tactic.repeat
meta def try : itactic β tactic unit :=
tactic.try
meta def solve1 : itactic β tactic unit :=
tactic.solve1
meta def abstract (id : parse ident? ) (tac : irtactic) : tactic unit :=
tactic.abstract tac id
meta def all_goals : itactic β tactic unit :=
tactic.all_goals
meta def any_goals : itactic β tactic unit :=
tactic.any_goals
meta def focus (tac : irtactic) : tactic unit :=
tactic.focus [tac]
/--
This tactic applies to any goal. `assert h : T` adds a new hypothesis of name `h` and type `T` to the current goal and opens a new subgoal with target `T`.
The new subgoal becomes the main goal.
-/
meta def assert (h : parse ident) (q : parse $ tk ":" *> texpr) : tactic unit :=
do e β i_to_expr_strict q,
tactic.assert h e
meta def define (h : parse ident) (q : parse $ tk ":" *> texpr) : tactic unit :=
do e β i_to_expr_strict q,
tactic.define h e
/--
This tactic applies to any goal. `assertv h : T := p` adds a new hypothesis of name `h` and type `T` to the current goal if `p` a term of type `T`.
-/
meta def assertv (h : parse ident) (qβ : parse $ tk ":" *> texpr) (qβ : parse $ tk ":=" *> texpr) : tactic unit :=
do t β i_to_expr_strict qβ,
v β i_to_expr_strict ``(%%qβ : %%t),
tactic.assertv h t v
meta def definev (h : parse ident) (qβ : parse $ tk ":" *> texpr) (qβ : parse $ tk ":=" *> texpr) : tactic unit :=
do t β i_to_expr_strict qβ,
v β i_to_expr_strict ``(%%qβ : %%t),
tactic.definev h t v
meta def note (h : parse ident) (q : parse $ tk ":=" *> texpr) : tactic unit :=
do p β i_to_expr_strict q,
tactic.note h p
meta def pose (h : parse ident) (q : parse $ tk ":=" *> texpr) : tactic unit :=
do p β i_to_expr_strict q,
tactic.pose h p
/--
This tactic displays the current state in the tracing buffer.
-/
meta def trace_state : tactic unit :=
tactic.trace_state
/--
`trace a` displays `a` in the tracing buffer.
-/
meta def trace {Ξ± : Type} [has_to_tactic_format Ξ±] (a : Ξ±) : tactic unit :=
tactic.trace a
meta def existsi (e : parse texpr) : tactic unit :=
i_to_expr e >>= tactic.existsi
/--
This tactic applies to a goal such that its conclusion is an inductive type (say `I`).
It tries to apply each constructor of `I` until it succeeds.
-/
meta def constructor : tactic unit :=
tactic.constructor
meta def left : tactic unit :=
tactic.left
meta def right : tactic unit :=
tactic.right
meta def split : tactic unit :=
tactic.split
meta def exfalso : tactic unit :=
tactic.exfalso
/--
The injection tactic is based on the fact that constructors of inductive datatypes are injections.
That means that if `c` is a constructor of an inductive datatype,
and if `(c tβ)` and `(c tβ)` are two terms that are equal then `tβ` and `tβ` are equal too.
If `q` is a proof of a statement of conclusion `tβ = tβ`,
then injection applies injectivity to derive the equality of all arguments of `tβ` and `tβ` placed in the same positions.
For example, from `(a::b) = (c::d)` we derive `a=c` and `b=d`.
To use this tactic `tβ` and `tβ` should be constructor applications of the same constructor.
Given `h : a::b = c::d`, the tactic `injection h` adds to new hypothesis with types `a = c` and `b = d`
to the main goal. The tactic `injection h with hβ hβ` uses the names `hβ` an `hβ` to name the new
hypotheses.
-/
meta def injection (q : parse texpr) (hs : parse with_ident_list) : tactic unit :=
do e β i_to_expr q, tactic.injection_with e hs
private meta def add_simps : simp_lemmas β list name β tactic simp_lemmas
| s [] := return s
| s (n::ns) := do s' β s^.add_simp n, add_simps s' ns
private meta def report_invalid_simp_lemma {Ξ± : Type} (n : name): tactic Ξ± :=
fail ("invalid simplification lemma '" ++ to_string n ++ "' (use command 'set_option trace.simp_lemmas true' for more details)")
private meta def simp_lemmas.resolve_and_add (s : simp_lemmas) (n : name) (ref : expr) : tactic simp_lemmas :=
do
e β resolve_name n,
match e with
| expr.const n _ :=
(do b β is_valid_simp_lemma_cnst reducible n, guard b, save_const_type_info n ref, s^.add_simp n)
<|>
(do eqns β get_eqn_lemmas_for tt n, guard (eqns^.length > 0), save_const_type_info n ref, add_simps s eqns)
<|>
report_invalid_simp_lemma n
| _ :=
(do b β is_valid_simp_lemma reducible e, guard b, try (save_type_info e ref), s^.add e)
<|>
report_invalid_simp_lemma n
end
private meta def simp_lemmas.add_pexpr (s : simp_lemmas) (p : pexpr) : tactic simp_lemmas :=
let e := pexpr.to_raw_expr p in
match e with
| (const c []) := simp_lemmas.resolve_and_add s c e
| (local_const c _ _ _) := simp_lemmas.resolve_and_add s c e
| _ := do new_e β i_to_expr p, s^.add new_e
end
private meta def simp_lemmas.append_pexprs : simp_lemmas β list pexpr β tactic simp_lemmas
| s [] := return s
| s (l::ls) := do new_s β simp_lemmas.add_pexpr s l, simp_lemmas.append_pexprs new_s ls
private meta def mk_simp_set (attr_names : list name) (hs : list pexpr) (ex : list name) : tactic simp_lemmas :=
do sβ β join_user_simp_lemmas attr_names,
sβ β simp_lemmas.append_pexprs sβ hs,
return $ simp_lemmas.erase sβ ex
private meta def simp_goal (cfg : simp_config) : simp_lemmas β tactic unit
| s := do
(new_target, Heq) β target >>= simplify_core cfg s `eq,
tactic.assert `Htarget new_target, swap,
Ht β get_local `Htarget,
mk_eq_mpr Heq Ht >>= tactic.exact
private meta def simp_hyp (cfg : simp_config) (s : simp_lemmas) (h_name : name) : tactic unit :=
do h β get_local h_name,
htype β infer_type h,
(new_htype, eqpr) β simplify_core cfg s `eq htype,
tactic.assert (expr.local_pp_name h) new_htype,
mk_eq_mp eqpr h >>= tactic.exact,
try $ tactic.clear h
private meta def simp_hyps (cfg : simp_config) : simp_lemmas β list name β tactic unit
| s [] := skip
| s (h::hs) := simp_hyp cfg s h >> simp_hyps s hs
private meta def simp_core (cfg : simp_config) (ctx : list expr) (hs : list pexpr) (attr_names : list name) (ids : list name) (loc : list name) : tactic unit :=
do s β mk_simp_set attr_names hs ids,
s β s^.append ctx,
match loc : _ β tactic unit with
| [] := simp_goal cfg s
| _ := simp_hyps cfg s loc
end,
try tactic.triv, try (tactic.reflexivity reducible)
/--
This tactic uses lemmas and hypotheses to simplify the main goal target or non-dependent hypotheses.
It has many variants.
- `simp` simplifies the main goal target using lemmas tagged with the attribute `[simp]`.
- `simp [h_1, ..., h_n]` simplifies the main goal target using the lemmas tagged with the attribute `[simp]` and the given `h_i`s.
The `h_i`'s are terms. If a `h_i` is a definition `f`, then the equational lemmas associated with `f` are used.
This is a convenient way to "unfold" `f`.
- `simp without id_1 ... id_n` simplifies the main goal target using the lemmas tagged with the attribute `[simp]`,
but removes the ones named `id_i`s.
- `simp at h` simplifies the non dependent hypothesis `h : T`. The tactic fails if the target or another hypothesis depends on `h`.
- `simp with attr` simplifies the main goal target using the lemmas tagged with the attribute `[attr]`.
-/
meta def simp (hs : parse opt_qexpr_list) (attr_names : parse with_ident_list) (ids : parse without_ident_list) (loc : parse location)
(cfg : simp_config := {}) : tactic unit :=
simp_core cfg [] hs attr_names ids loc
/--
Similar to the `simp` tactic, but adds all applicable hypotheses as simplification rules.
-/
meta def simp_using_hs (hs : parse opt_qexpr_list) (attr_names : parse with_ident_list) (ids : parse without_ident_list)
(cfg : simp_config := {}) : tactic unit :=
do ctx β collect_ctx_simps,
simp_core cfg ctx hs attr_names ids []
meta def simph (hs : parse opt_qexpr_list) (attr_names : parse with_ident_list) (ids : parse without_ident_list)
(cfg : simp_config := {}) : tactic unit :=
simp_using_hs hs attr_names ids cfg
meta def simp_intros (ids : parse ident*) (hs : parse opt_qexpr_list) (attr_names : parse with_ident_list)
(wo_ids : parse without_ident_list) (cfg : simp_config := {}) : tactic unit :=
do s β mk_simp_set attr_names hs wo_ids,
match ids with
| [] := simp_intros_using s cfg
| ns := simp_intro_lst_using ns s cfg
end,
try triv >> try (reflexivity reducible)
meta def simph_intros (ids : parse ident*) (hs : parse opt_qexpr_list) (attr_names : parse with_ident_list)
(wo_ids : parse without_ident_list) (cfg : simp_config := {}) : tactic unit :=
do s β mk_simp_set attr_names hs wo_ids,
match ids with
| [] := simph_intros_using s cfg
| ns := simph_intro_lst_using ns s cfg
end,
try triv >> try (reflexivity reducible)
private meta def dsimp_hyps (s : simp_lemmas) : list name β tactic unit
| [] := skip
| (h::hs) := get_local h >>= dsimp_at_core s
meta def dsimp (es : parse opt_qexpr_list) (attr_names : parse with_ident_list) (ids : parse without_ident_list) : parse location β tactic unit
| [] := do s β mk_simp_set attr_names es ids, tactic.dsimp_core s
| hs := do s β mk_simp_set attr_names es ids, dsimp_hyps s hs
/--
This tactic applies to a goal that has the form `t ~ u` where `~` is a reflexive relation.
That is, a relation which has a reflexivity lemma tagged with the attribute `[refl]`.
The tactic checks whether `t` and `u` are definitionally equal and then solves the goal.
-/
meta def reflexivity : tactic unit :=
tactic.reflexivity
/--
Shorter name for the tactic `reflexivity`.
-/
meta def refl : tactic unit :=
tactic.reflexivity
meta def symmetry : tactic unit :=
tactic.symmetry
meta def transitivity : tactic unit :=
tactic.transitivity
meta def ac_reflexivity : tactic unit :=
tactic.ac_refl
meta def ac_refl : tactic unit :=
tactic.ac_refl
meta def cc : tactic unit :=
tactic.cc
meta def subst (q : parse texpr) : tactic unit :=
i_to_expr q >>= tactic.subst >> try (tactic.reflexivity reducible)
meta def clear : parse ident* β tactic unit :=
tactic.clear_lst
private meta def to_qualified_name_core : name β list name β tactic name
| n [] := fail $ "unknown declaration '" ++ to_string n ++ "'"
| n (ns::nss) := do
curr β return $ ns ++ n,
env β get_env,
if env^.contains curr then return curr
else to_qualified_name_core n nss
private meta def to_qualified_name (n : name) : tactic name :=
do env β get_env,
if env^.contains n then return n
else do
ns β open_namespaces,
to_qualified_name_core n ns
private meta def to_qualified_names : list name β tactic (list name)
| [] := return []
| (c::cs) := do new_c β to_qualified_name c, new_cs β to_qualified_names cs, return (new_c::new_cs)
private meta def dunfold_hyps : list name β list name β tactic unit
| cs [] := skip
| cs (h::hs) := get_local h >>= dunfold_at cs >> dunfold_hyps cs hs
meta def dunfold : parse ident* β parse location β tactic unit
| cs [] := do new_cs β to_qualified_names cs, tactic.dunfold new_cs
| cs hs := do new_cs β to_qualified_names cs, dunfold_hyps new_cs hs
/- TODO(Leo): add support for non-refl lemmas -/
meta def unfold : parse ident* β parse location β tactic unit :=
dunfold
private meta def dunfold_hyps_occs : name β occurrences β list name β tactic unit
| c occs [] := skip
| c occs (h::hs) := get_local h >>= dunfold_core_at occs [c] >> dunfold_hyps_occs c occs hs
meta def dunfold_occs : parse ident β parse location β list nat β tactic unit
| c [] ps := do new_c β to_qualified_name c, tactic.dunfold_occs_of ps new_c
| c hs ps := do new_c β to_qualified_name c, dunfold_hyps_occs new_c (occurrences.pos ps) hs
/- TODO(Leo): add support for non-refl lemmas -/
meta def unfold_occs : parse ident β parse location β list nat β tactic unit :=
dunfold_occs
private meta def delta_hyps : list name β list name β tactic unit
| cs [] := skip
| cs (h::hs) := get_local h >>= delta_at cs >> dunfold_hyps cs hs
meta def delta : parse ident* β parse location β tactic unit
| cs [] := do new_cs β to_qualified_names cs, tactic.delta new_cs
| cs hs := do new_cs β to_qualified_names cs, delta_hyps new_cs hs
end interactive
end tactic
|
7ae15ab595e5d9a12a4b9a304b9794c2cd92304f
|
e00ea76a720126cf9f6d732ad6216b5b824d20a7
|
/src/tactic/omega/int/main.lean
|
7fa0b5ae7bd6f840b804f985b0151106ece08b41
|
[
"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,297
|
lean
|
/- Copyright (c) 2019 Seul Baek. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Seul Baek
Main procedure for linear integer arithmetic. -/
import tactic.omega.prove_unsats
import tactic.omega.int.dnf
import tactic.omega.misc
open tactic
namespace omega
namespace int
open_locale omega.int
run_cmd mk_simp_attr `sugar
attribute [sugar]
ne not_le not_lt
int.lt_iff_add_one_le
or_false false_or
and_true true_and
ge gt mul_add add_mul
one_mul mul_one
mul_comm sub_eq_add_neg
classical.imp_iff_not_or
classical.iff_iff_not_or_and_or_not
meta def desugar := `[try {simp only with sugar}]
lemma univ_close_of_unsat_clausify (m : nat) (p : preform) :
clauses.unsat (dnf (Β¬* p)) β univ_close p (Ξ» x, 0) m | h1 :=
begin
apply univ_close_of_valid,
apply valid_of_unsat_not,
apply unsat_of_clauses_unsat,
exact h1
end
/-- Given a (p : preform), return the expr of a (t : univ_close m p) -/
meta def prove_univ_close (m : nat) (p : preform) : tactic expr :=
do x β prove_unsats (dnf (Β¬*p)),
return `(univ_close_of_unsat_clausify %%`(m) %%`(p) %%x)
/-- Reification to imtermediate shadow syntax that retains exprs -/
meta def to_exprterm : expr β tactic exprterm
| `(- %%x) := --return (exprterm.exp (-1 : int) x)
( do z β eval_expr' int x,
return (exprterm.cst (-z : int)) ) <|>
( return $ exprterm.exp (-1 : int) x )
| `(%%mx * %%zx) :=
do z β eval_expr' int zx,
return (exprterm.exp z mx)
| `(%%t1x + %%t2x) :=
do t1 β to_exprterm t1x,
t2 β to_exprterm t2x,
return (exprterm.add t1 t2)
| x :=
( do z β eval_expr' int x,
return (exprterm.cst z) ) <|>
( return $ exprterm.exp 1 x )
/-- Reification to imtermediate shadow syntax that retains exprs -/
meta def to_exprform : expr β tactic exprform
| `(%%tx1 = %%tx2) :=
do t1 β to_exprterm tx1,
t2 β to_exprterm tx2,
return (exprform.eq t1 t2)
| `(%%tx1 β€ %%tx2) :=
do t1 β to_exprterm tx1,
t2 β to_exprterm tx2,
return (exprform.le t1 t2)
| `(Β¬ %%px) := do p β to_exprform px, return (exprform.not p)
| `(%%px β¨ %%qx) :=
do p β to_exprform px,
q β to_exprform qx,
return (exprform.or p q)
| `(%%px β§ %%qx) :=
do p β to_exprform px,
q β to_exprform qx,
return (exprform.and p q)
| `(_ β %%px) := to_exprform px
| x := trace "Cannot reify expr : " >> trace x >> failed
/-- List of all unreified exprs -/
meta def exprterm.exprs : exprterm β list expr
| (exprterm.cst _) := []
| (exprterm.exp _ x) := [x]
| (exprterm.add t s) := list.union t.exprs s.exprs
/-- List of all unreified exprs -/
meta def exprform.exprs : exprform β list expr
| (exprform.eq t s) := list.union t.exprs s.exprs
| (exprform.le t s) := list.union t.exprs s.exprs
| (exprform.not p) := p.exprs
| (exprform.or p q) := list.union p.exprs q.exprs
| (exprform.and p q) := list.union p.exprs q.exprs
/-- Reification to an intermediate shadow syntax which eliminates exprs,
but still includes non-canonical terms -/
meta def exprterm.to_preterm (xs : list expr) : exprterm β tactic preterm
| (exprterm.cst k) := return & k
| (exprterm.exp k x) :=
let m := xs.index_of x in
if m < xs.length
then return (k ** m)
else failed
| (exprterm.add xa xb) :=
do a β xa.to_preterm,
b β xb.to_preterm,
return (a +* b)
/-- Reification to an intermediate shadow syntax which eliminates exprs,
but still includes non-canonical terms -/
meta def exprform.to_preform (xs : list expr) : exprform β tactic preform
| (exprform.eq xa xb) :=
do a β xa.to_preterm xs,
b β xb.to_preterm xs,
return (a =* b)
| (exprform.le xa xb) :=
do a β xa.to_preterm xs,
b β xb.to_preterm xs,
return (a β€* b)
| (exprform.not xp) :=
do p β xp.to_preform,
return Β¬* p
| (exprform.or xp xq) :=
do p β xp.to_preform,
q β xq.to_preform,
return (p β¨* q)
| (exprform.and xp xq) :=
do p β xp.to_preform,
q β xq.to_preform,
return (p β§* q)
/-- Reification to an intermediate shadow syntax which eliminates exprs,
but still includes non-canonical terms. -/
meta def to_preform (x : expr) : tactic (preform Γ nat) :=
do xf β to_exprform x,
let xs := xf.exprs,
f β xf.to_preform xs,
return (f, xs.length)
/-- Return expr of proof of current LIA goal -/
meta def prove : tactic expr :=
do (p,m) β target >>= to_preform,
prove_univ_close m p
/-- Succeed iff argument is the expr of β€ -/
meta def eq_int (x : expr) : tactic unit :=
if x = `(int) then skip else failed
/-- Check whether argument is expr of a well-formed formula of LIA-/
meta def wff : expr β tactic unit
| `(Β¬ %%px) := wff px
| `(%%px β¨ %%qx) := wff px >> wff qx
| `(%%px β§ %%qx) := wff px >> wff qx
| `(%%px β %%qx) := wff px >> wff qx
| `(%%(expr.pi _ _ px qx)) :=
monad.cond
(if expr.has_var px then return tt else is_prop px)
(wff px >> wff qx)
(eq_int px >> wff qx)
| `(@has_lt.lt %%dx %%h _ _) := eq_int dx
| `(@has_le.le %%dx %%h _ _) := eq_int dx
| `(@eq %%dx _ _) := eq_int dx
| `(@ge %%dx %%h _ _) := eq_int dx
| `(@gt %%dx %%h _ _) := eq_int dx
| `(@ne %%dx _ _) := eq_int dx
| `(true) := skip
| `(false) := skip
| _ := failed
/-- Succeed iff argument is expr of term whose type is wff -/
meta def wfx (x : expr) : tactic unit :=
infer_type x >>= wff
/-- Intro all universal quantifiers over β€ -/
meta def intro_ints_core : tactic unit :=
do x β target,
match x with
| (expr.pi _ _ `(int) _) := intro_fresh >> intro_ints_core
| _ := skip
end
meta def intro_ints : tactic unit :=
do (expr.pi _ _ `(int) _) β target,
intro_ints_core
/-- If the goal has universal quantifiers over integers, introduce all of them.
Otherwise, revert all hypotheses that are formulas of linear integer arithmetic. -/
meta def preprocess : tactic unit :=
intro_ints <|> (revert_cond_all wfx >> desugar)
end int
end omega
open omega.int
/-- The core omega tactic for integers. -/
meta def omega_int (is_manual : bool) : tactic unit :=
desugar ; (if is_manual then skip else preprocess) ; prove >>= apply >> skip
|
657065186feebc9dffc2bc19821d2eec53dd19bb
|
9cba98daa30c0804090f963f9024147a50292fa0
|
/geom/spacetime.lean
|
f77dc0de1a7792099b64c4140175d9c6ed8f904b
|
[] |
no_license
|
kevinsullivan/phys
|
dcb192f7b3033797541b980f0b4a7e75d84cea1a
|
ebc2df3779d3605ff7a9b47eeda25c2a551e011f
|
refs/heads/master
| 1,637,490,575,500
| 1,629,899,064,000
| 1,629,899,064,000
| 168,012,884
| 0
| 3
| null | 1,629,644,436,000
| 1,548,699,832,000
|
Lean
|
UTF-8
|
Lean
| false
| false
| 19,483
|
lean
|
import .geom3d
import ..time.time
open_locale affine
section foo
universes u
#check add_maps
abbreviation geom3d_stamped_frame :=
(mk_prod_spc (geom3d_std_space) time_std_space).frame_type
abbreviation geom3d_stamped_space (f : geom3d_stamped_frame) := spc scalar f
def geom3d_stamped_std_frame :=
(mk_prod_spc (geom3d_std_space) time_std_space).frame
def geom3d_stamped_std_space : geom3d_stamped_space geom3d_stamped_std_frame :=
(mk_prod_spc (geom3d_std_space) time_std_space)
structure position3d_stamped {f : geom3d_stamped_frame} (s : geom3d_stamped_space f ) extends point s
@[ext] lemma position3d_stamped.ext : β {f : geom3d_stamped_frame} {s : geom3d_stamped_space f } (x y : position3d_stamped s),
x.to_point = y.to_point β x = y :=
begin
intros f s x y e,
cases x,
cases y,
simp *,
have hβ : ({to_point := x} : position3d_stamped s).to_point = x := rfl,
simp [hβ] at e,
exact e
end
def position3d_stamped.coords {f : geom3d_stamped_frame} {s : geom3d_stamped_space f } (t :position3d_stamped s) :=
t.to_point.coords
def position3d_stamped.x {f : geom3d_stamped_frame} {s : geom3d_stamped_space f } (t :position3d_stamped s) : scalar :=
(t.to_point.coords 0).coord
def position3d_stamped.y {f : geom3d_stamped_frame} {s : geom3d_stamped_space f } (t :position3d_stamped s) : scalar :=
(t.to_point.coords 1).coord
def position3d_stamped.z {f : geom3d_stamped_frame} {s : geom3d_stamped_space f } (t :position3d_stamped s) : scalar :=
(t.to_point.coords 2).coord
@[simp]
def mk_position3d_stamped' {f : geom3d_stamped_frame} (s : geom3d_stamped_space f ) (p : point s) : position3d_stamped s := position3d_stamped.mk p
@[simp]
def mk_position3d_stamped {f : geom3d_stamped_frame} (s : geom3d_stamped_space f ) (kβ kβ kβ kβ : scalar) : position3d_stamped s := position3d_stamped.mk (mk_point s β¨[kβ,kβ,kβ, kβ],rflβ©)
@[simp]
def mk_position3d_stamped'' {f1 f2 f3 : geom1d_frame } { s1 : geom1d_space f1} {s2 : geom1d_space f2} { s3 : geom1d_space f3}
{f4 : time_frame} {s4 : time_space f4}
(p1 : position1d s1) (p2 : position1d s2) (p3 : position1d s3 ) (p4 : time s4)
: position3d_stamped (mk_prod_spc (mk_prod_spc (mk_prod_spc s1 s2) s3) s4) :=
β¨mk_point_prod (mk_point_prod (mk_point_prod p1.to_point p2.to_point) p3.to_point) p4.to_pointβ©
structure displacement3d_stamped {f : geom3d_stamped_frame} (s : geom3d_stamped_space f ) extends vectr s
@[ext] lemma displacement3d_stamped.ext : β {f : geom3d_stamped_frame} {s : geom3d_stamped_space f } (x y : displacement3d_stamped s),
x.to_vectr = y.to_vectr β x = y :=
begin
intros f s x y e,
cases x,
cases y,
simp *,
have hβ : ({to_vectr := x} : displacement3d_stamped s).to_vectr = x := rfl,
simp [hβ] at e,
exact e
end
def displacement3d_stamped.coords {f : geom3d_stamped_frame} {s : geom3d_stamped_space f } (d :displacement3d_stamped s) :=
d.to_vectr.coords
def displacement3d_stamped.x {f : geom3d_stamped_frame} {s : geom3d_stamped_space f } (t :displacement3d_stamped s) : scalar :=
(t.to_vectr.coords 0).coord
def displacement3d_stamped.y {f : geom3d_stamped_frame} {s : geom3d_stamped_space f } (t :displacement3d_stamped s) : scalar :=
(t.to_vectr.coords 1).coord
def displacement3d_stamped.z {f : geom3d_stamped_frame} {s : geom3d_stamped_space f } (t :displacement3d_stamped s) : scalar :=
(t.to_vectr.coords 2).coord
@[simp]
def mk_displacement3d_stamped' {f : geom3d_stamped_frame} (s : geom3d_stamped_space f ) (v : vectr s) : displacement3d_stamped s := displacement3d_stamped.mk v
@[simp]
def mk_displacement3d_stamped {f : geom3d_stamped_frame} (s : geom3d_stamped_space f ) (kβ kβ kβ kβ : scalar)
: displacement3d_stamped s := displacement3d_stamped.mk (mk_vectr s β¨[kβ,kβ,kβ,kβ],rflβ©)
@[simp]
def mk_displacement3d_stamped'' {f1 f2 f3 : geom1d_frame } { s1 : geom1d_space f1} {s2 : geom1d_space f2} { s3 : geom1d_space f3}
{f4 : time_frame} {s4 : time_space f4}
(p1 : displacement1d s1) (p2 : displacement1d s2) (p3 : displacement1d s3 ) (p4 : time s4)
: displacement3d_stamped (mk_prod_spc (mk_prod_spc (mk_prod_spc s1 s2) s3) s4) :=
β¨mk_vectr_prod (mk_vectr_prod (mk_vectr_prod p1.to_vectr p2.to_vectr) p3.to_vectr) (mk_vectr s4 β¨[(p4.coords 0).coord],rflβ©)β©
@[simp]
def mk_geom3d_stamped_frame {parent : geom3d_stamped_frame} {s : spc scalar parent} (p : position3d_stamped s)
(v0 : displacement3d s) (v1 : displacement3d s) (v2 : displacement3d s)
: geom3d_stamped_frame :=
(mk_frame p.to_point β¨(Ξ»i, if i = 0 then (mk_displacement3d_stamped v0.x v0.y v0.z 0) else if i = 1 then v1.to_vectr else v2.to_vectr),sorry,sorryβ©)
end foo
section bar
#check quot
#check quotient
/-
*************************************
Instantiate module scalar (vector scalar)
*************************************
-/
namespace geom3d
variables {f : geom3d_stamped_frame} {s : geom3d_stamped_space f }
@[simp]
def add_displacement3d_stamped_displacement3d_stamped (v3 v2 : displacement3d_stamped s) : displacement3d_stamped s :=
mk_displacement3d_stamped' s (v3.to_vectr + v2.to_vectr)
@[simp]
def smul_displacement3d_stamped (k : scalar) (v : displacement3d_stamped s) : displacement3d_stamped s :=
mk_displacement3d_stamped' s (k β’ v.to_vectr)
@[simp]
def neg_displacement3d_stamped (v : displacement3d_stamped s) : displacement3d_stamped s :=
mk_displacement3d_stamped' s ((-1 : scalar) β’ v.to_vectr)
@[simp]
def sub_displacement3d_stamped_displacement3d_stamped (v3 v2 : displacement3d_stamped s) : displacement3d_stamped s := -- v3-v2
add_displacement3d_stamped_displacement3d_stamped v3 (neg_displacement3d_stamped v2)
instance has_add_displacement3d_stamped : has_add (displacement3d_stamped s) := β¨ add_displacement3d_stamped_displacement3d_stamped β©
lemma add_assoc_displacement3d_stamped : β a b c : displacement3d_stamped s, a + b + c = a + (b + c) := begin
intros,
ext,
--cases a,
repeat {
have p3 : (a + b + c).to_vec = a.to_vec + b.to_vec + c.to_vec := rfl,
have p2 : (a + (b + c)).to_vec = a.to_vec + (b.to_vec + c.to_vec) := rfl,
rw [p3,p2],
cc
},
admit
end
instance add_semigroup_displacement3d_stamped : add_semigroup (displacement3d_stamped s) := β¨ add_displacement3d_stamped_displacement3d_stamped, add_assoc_displacement3d_stampedβ©
@[simp]
def displacement3d_stamped_zero := mk_displacement3d_stamped s 0 0 0 0
instance has_zero_displacement3d_stamped : has_zero (displacement3d_stamped s) := β¨displacement3d_stamped_zeroβ©
lemma zero_add_displacement3d_stamped : β a : displacement3d_stamped s, 0 + a = a :=
begin
intros,--ext,
ext,
admit,
-- let h0 : (0 + a).to_vec = (0 : vectr s).to_vec + a.to_vec := rfl,
--simp [h0],
--exact zero_add _,
--exact zero_add _,
end
lemma add_zero_displacement3d_stamped : β a : displacement3d_stamped s, a + 0 = a :=
begin
intros,ext,
admit,
--exact add_zero _,
--exact add_zero _,
end
@[simp]
def nsmul_displacement3d_stamped : β β (displacement3d_stamped s) β (displacement3d_stamped s)
| nat.zero v := displacement3d_stamped_zero
--| 3 v := v
| (nat.succ n) v := (add_displacement3d_stamped_displacement3d_stamped) v (nsmul_displacement3d_stamped n v)
instance add_monoid_displacement3d_stamped : add_monoid (displacement3d_stamped s) := β¨
-- add_semigroup
add_displacement3d_stamped_displacement3d_stamped,
add_assoc_displacement3d_stamped,
-- has_zero
displacement3d_stamped_zero,
-- new structure
@zero_add_displacement3d_stamped f s,
add_zero_displacement3d_stamped,
nsmul_displacement3d_stamped
β©
instance has_neg_displacement3d_stamped : has_neg (displacement3d_stamped s) := β¨neg_displacement3d_stampedβ©
instance has_sub_displacement3d_stamped : has_sub (displacement3d_stamped s) := β¨ sub_displacement3d_stamped_displacement3d_stampedβ©
lemma sub_eq_add_neg_displacement3d_stamped : β a b : displacement3d_stamped s, a - b = a + -b :=
begin
intros,ext,
refl,
end
instance sub_neg_monoid_displacement3d_stamped : sub_neg_monoid (displacement3d_stamped s) :=
{
neg := neg_displacement3d_stamped ,
..(show add_monoid (displacement3d_stamped s), by apply_instance)
}
lemma add_left_neg_displacement3d_stamped : β a : displacement3d_stamped s, -a + a = 0 :=
begin
intros,
ext,
/- repeat {
have h0 : (-a + a).to_vec = -a.to_vec + a.to_vec := rfl,
simp [h0],
have : (0:vec scalar) = (0:displacement3d_stamped s).to_vectr.to_vec := rfl,
simp *,
}-/
admit,
end
instance : add_group (displacement3d_stamped s) := {
add_left_neg := begin
exact add_left_neg_displacement3d_stamped,
end,
..(show sub_neg_monoid (displacement3d_stamped s), by apply_instance),
}
lemma add_comm_displacement3d_stamped : β a b : displacement3d_stamped s, a + b = b + a :=
begin
intros,
ext,
/-repeat {
have p3 : (a + b).to_vec = a.to_vec + b.to_vec:= rfl,
have p2 : (b + a).to_vec = b.to_vec + a.to_vec := rfl,
rw [p3,p2],
cc
}
-/
admit,
end
instance add_comm_semigroup_displacement3d_stamped : add_comm_semigroup (displacement3d_stamped s) := β¨
-- add_semigroup
add_displacement3d_stamped_displacement3d_stamped,
add_assoc_displacement3d_stamped,
add_comm_displacement3d_stamped,
β©
instance add_comm_monoid_displacement3d_stamped : add_comm_monoid (displacement3d_stamped s) := {
add_comm := begin
exact add_comm_displacement3d_stamped
end,
..(show add_monoid (displacement3d_stamped s), by apply_instance)
}
instance has_scalar_displacement3d_stamped : has_scalar scalar (displacement3d_stamped s) := β¨
smul_displacement3d_stamped,
β©
lemma one_smul_displacement3d_stamped : β b : displacement3d_stamped s, (1 : scalar) β’ b = b := begin
intros,ext,
/-repeat {
have h0 : ((3:scalar) β’ b).to_vec = ((3:scalar)β’(b.to_vec)) := rfl,
rw [h0],
simp *,
}-/
admit,
end
lemma mul_smul_displacement3d_stamped : β (x y : scalar) (b : displacement3d_stamped s), (x * y) β’ b = x β’ y β’ b :=
begin
intros,
cases b,
ext,
exact mul_assoc x y _,
end
instance mul_action_displacement3d_stamped : mul_action scalar (displacement3d_stamped s) := β¨
one_smul_displacement3d_stamped,
mul_smul_displacement3d_stamped,
β©
lemma smul_add_displacement3d_stamped : β(r : scalar) (x y : displacement3d_stamped s), r β’ (x + y) = r β’ x + r β’ y := begin
intros, ext,
repeat {
have h0 : (r β’ (x + y)).to_vec = (r β’ (x.to_vec + y.to_vec)) := rfl,
have h3 : (rβ’x + rβ’y).to_vec = (rβ’x.to_vec + rβ’y.to_vec) := rfl,
rw [h0,h3],
simp *,
}
,admit,
end
lemma smul_zero_displacement3d_stamped : β(r : scalar), r β’ (0 : displacement3d_stamped s) = 0 := begin
admit--intros, ext, exact mul_zero _, exact mul_zero _
end
instance distrib_mul_action_K_displacement3d_stamped : distrib_mul_action scalar (displacement3d_stamped s) := β¨
smul_add_displacement3d_stamped,
smul_zero_displacement3d_stamped,
β©
-- renaming vs template due to clash with name "s" for prevailing variable
lemma add_smul_displacement3d_stamped : β (a b : scalar) (x : displacement3d_stamped s), (a + b) β’ x = a β’ x + b β’ x :=
begin
intros,
ext,
exact right_distrib _ _ _,
end
lemma zero_smul_displacement3d_stamped : β (x : displacement3d_stamped s), (0 : scalar) β’ x = 0 := begin
intros,
ext,
admit,--exact zero_mul _, exact zero_mul _
end
instance module_K_displacement3d_stamped : module scalar (displacement3d_stamped s) := β¨ add_smul_displacement3d_stamped, zero_smul_displacement3d_stamped β©
instance add_comm_group_displacement3d_stamped : add_comm_group (displacement3d_stamped s) := {
add_comm := begin
exact add_comm_displacement3d_stamped
end,
..(show add_group (displacement3d_stamped s), by apply_instance)
}
instance : module scalar (displacement3d_stamped s) := @geom3d.module_K_displacement3d_stamped f s
/-
********************
*** Affine space ***
********************
-/
/-
Affine operations
-/
instance : has_add (displacement3d_stamped s) := β¨add_displacement3d_stamped_displacement3d_stampedβ©
instance : has_zero (displacement3d_stamped s) := β¨displacement3d_stamped_zeroβ©
instance : has_neg (displacement3d_stamped s) := β¨neg_displacement3d_stampedβ©
/-
Lemmas needed to implement affine space API
-/
@[simp]
def sub_position3d_stamped_position3d_stamped {f : geom3d_stamped_frame} {s : geom3d_stamped_space f } (p3 p2 : position3d_stamped s) : displacement3d_stamped s :=
mk_displacement3d_stamped' s (p3.to_point -α΅₯ p2.to_point)
@[simp]
def add_position3d_stamped_displacement3d_stamped {f : geom3d_stamped_frame} {s : geom3d_stamped_space f } (p : position3d_stamped s) (v : displacement3d_stamped s) : position3d_stamped s :=
mk_position3d_stamped' s (v.to_vectr +α΅₯ p.to_point) -- reorder assumes order is irrelevant
@[simp]
def add_displacement3d_stamped_position3d_stamped {f : geom3d_stamped_frame} {s : geom3d_stamped_space f } (v : displacement3d_stamped s) (p : position3d_stamped s) : position3d_stamped s :=
mk_position3d_stamped' s (v.to_vectr +α΅₯ p.to_point)
--@[simp]
--def aff_displacement3d_stamped_group_action : displacement3d_stamped s β position3d_stamped s β position3d_stamped s := add_displacement3d_stamped_position3d_stamped scalar
instance : has_vadd (displacement3d_stamped s) (position3d_stamped s) := β¨add_displacement3d_stamped_position3d_stampedβ©
lemma zero_displacement3d_stamped_vadd'_a3 : β p : position3d_stamped s, (0 : displacement3d_stamped s) +α΅₯ p = p := begin
intros,
ext,--exact zero_add _,
admit--exact add_zero _
end
lemma displacement3d_stamped_add_assoc'_a3 : β (g3 g2 : displacement3d_stamped s) (p : position3d_stamped s), g3 +α΅₯ (g2 +α΅₯ p) = (g3 + g2) +α΅₯ p := begin
intros, ext,
repeat {
have h0 : (g3 +α΅₯ (g2 +α΅₯ p)).to_pt = (g3.to_vec +α΅₯ (g2.to_vec +α΅₯ p.to_pt)) := rfl,
have h3 : (g3 + g2 +α΅₯ p).to_pt = (g3.to_vec +α΅₯ g2.to_vec +α΅₯ p.to_pt) := rfl,
rw [h0,h3],
simp *,
simp [has_vadd.vadd, has_add.add, add_semigroup.add, add_zero_class.add, add_monoid.add, sub_neg_monoid.add,
add_group.add, distrib.add, ring.add, division_ring.add],
cc,
},
admit,
end
instance displacement3d_stamped_add_action: add_action (displacement3d_stamped s) (position3d_stamped s) :=
β¨ zero_displacement3d_stamped_vadd'_a3,
begin
let h0 := displacement3d_stamped_add_assoc'_a3,
intros,
exact (h0 gβ gβ p).symm
endβ©
--@[simp]
--def aff_geom3d_group_sub : position3d_stamped s β position3d_stamped s β displacement3d_stamped s := sub_geom3d_position3d_stamped scalar
instance position3d_stamped_has_vsub : has_vsub (displacement3d_stamped s) (position3d_stamped s) := β¨ sub_position3d_stamped_position3d_stampedβ©
instance : nonempty (position3d_stamped s) := β¨mk_position3d_stamped s 0 0 0 0β©
lemma position3d_stamped_vsub_vadd_a3 : β (p3 p2 : (position3d_stamped s)), (p3 -α΅₯ p2) +α΅₯ p2 = p3 := begin
/-intros, ext,
--repeat {
have h0 : (p3 -α΅₯ p2 +α΅₯ p2).to_pt = (p3.to_pt -α΅₯ p2.to_pt +α΅₯ p2.to_pt) := rfl,
rw h0,
simp [has_vsub.vsub, has_sub.sub, sub_neg_monoid.sub, add_group.sub, add_comm_group.sub, ring.sub, division_ring.sub],
simp [has_vadd.vadd, has_add.add, distrib.add, ring.add, division_ring.add],
let h0 : field.add p2.to_pt.to_prod.fst (field.sub p3.to_pt.to_prod.fst p2.to_pt.to_prod.fst) =
field.add (field.sub p3.to_pt.to_prod.fst p2.to_pt.to_prod.fst) p2.to_pt.to_prod.fst := add_comm _ _,
rw h0,
exact sub_add_cancel _ _,
have h0 : (p3 -α΅₯ p2 +α΅₯ p2).to_pt = (p3.to_pt -α΅₯ p2.to_pt +α΅₯ p2.to_pt) := rfl,
rw h0,
simp [has_vsub.vsub, has_sub.sub, sub_neg_monoid.sub, add_group.sub, add_comm_group.sub, ring.sub, division_ring.sub],
simp [has_vadd.vadd, has_add.add, distrib.add, ring.add, division_ring.add],
let h0 : field.add p2.to_pt.to_prod.snd (field.sub p3.to_pt.to_prod.snd p2.to_pt.to_prod.snd) =
field.add (field.sub p3.to_pt.to_prod.snd p2.to_pt.to_prod.snd) p2.to_pt.to_prod.snd := add_comm _ _,
rw h0,
exact sub_add_cancel _ _,-/
admit
end
lemma position3d_stamped_vadd_vsub_a3 : β (g : displacement3d_stamped s) (p : position3d_stamped s), g +α΅₯ p -α΅₯ p = g :=
begin
intros, ext,
repeat {
have h0 : ((g +α΅₯ p -α΅₯ p) : displacement3d_stamped s).to_vectr = (g.to_vectr +α΅₯ p.to_point -α΅₯ p.to_point) := rfl,
rw h0,
simp *,
}
end
instance aff_geom3d_stamped_torsor : add_torsor (displacement3d_stamped s) (position3d_stamped s) :=
β¨
begin
exact position3d_stamped_vsub_vadd_a3,
end,
begin
exact position3d_stamped_vadd_vsub_a3,
end,
β©
open_locale affine
--instance : affine_space (displacement3d_stamped s) (position3d_stamped s) := @geom3d.aff_geom3d_torsor f s
end geom3d -- ha ha
end bar
/-
Newer version
Tradeoff - Does not directly extend from affine equiv. Base class is an equiv on points and vectrs
Extension methods are provided to directly transform Times and Duration between frames
-/
@[ext]
structure geom3d_stamped_transform {f3 : geom3d_stamped_frame} {f2 : geom3d_stamped_frame} (sp3 : geom3d_stamped_space f3) (sp2 : geom3d_stamped_space f2)
extends fm_tr sp3 sp2
def geom3d_stamped_space.mk_geom3d_stamped_transform_to {f3 : geom3d_stamped_frame} (s3 : geom3d_stamped_space f3) : Ξ {f2 : geom3d_stamped_frame} (s2 : geom3d_stamped_space f2),
geom3d_stamped_transform s3 s2 := --(position3d_stamped s2) βα΅[scalar] (position3d_stamped s3) :=
Ξ» f2 s2,
β¨s3.fm_tr s2β©
def geom3d_stamped_transform.symm
{f3 : geom3d_stamped_frame} {f2 : geom3d_stamped_frame} {sp3 : geom3d_stamped_space f3} {sp2 : geom3d_stamped_space f2} (ttr : geom3d_stamped_transform sp3 sp2)
: geom3d_stamped_transform sp2 sp3 := β¨(ttr.1).symmβ©
def geom3d_stamped_transform.trans
{f3 : geom3d_stamped_frame} {f2 : geom3d_stamped_frame} {f3 : geom3d_stamped_frame} {sp3 : geom3d_stamped_space f3} {sp2 : geom3d_stamped_space f2} {sp3 : geom3d_stamped_space f3}
(ttr : geom3d_stamped_transform sp3 sp2)
: geom3d_stamped_transform sp2 sp3 β geom3d_stamped_transform sp3 sp3 := Ξ»ttr_, β¨(ttr.1).trans ttr_.1β©
def geom3d_stamped_transform.transform_position3d_stamped
{f3 : geom3d_stamped_frame} {s3 : geom3d_stamped_space f3}
{f2 : geom3d_stamped_frame} {s2 : geom3d_stamped_space f2}
(tr: geom3d_stamped_transform s3 s2 ) : position3d_stamped s3 β position3d_stamped s2 :=
Ξ»t : position3d_stamped s3,
β¨tr.to_fm_tr.to_equiv t.to_pointβ©
def geom3d_stamped_transform.transform_displacement3d_stamped
{f3 : geom3d_stamped_frame} {s3 : geom3d_stamped_space f3}
{f2 : geom3d_stamped_frame} {s2 : geom3d_stamped_space f2}
(tr: geom3d_stamped_transform s3 s2 ) : displacement3d_stamped s3 β displacement3d_stamped s2 :=
Ξ»d,
let as_pt : point s3 := β¨Ξ»i, mk_pt scalar (d.coords i).coordβ© in
let tr_pt := (tr.to_equiv as_pt) in
β¨β¨Ξ»i, mk_vec scalar (tr_pt.coords i).coordβ©β©
|
d99b2a8a05de7414c9bba338c55fe266da5188bf
|
d1a52c3f208fa42c41df8278c3d280f075eb020c
|
/src/Lean/Elab/PreDefinition.lean
|
f8a296e3e2438e8af02a24156226d4a684a2e415
|
[
"Apache-2.0",
"LLVM-exception",
"NCSA",
"LGPL-3.0-only",
"LicenseRef-scancode-inner-net-2.0",
"BSD-3-Clause",
"LGPL-2.0-or-later",
"Spencer-94",
"LGPL-2.1-or-later",
"HPND",
"LicenseRef-scancode-pcre",
"ISC",
"LGPL-2.1-only",
"LicenseRef-scancode-other-permissive",
"SunPro",
"CMU-Mach"
] |
permissive
|
cipher1024/lean4
|
6e1f98bb58e7a92b28f5364eb38a14c8d0aae393
|
69114d3b50806264ef35b57394391c3e738a9822
|
refs/heads/master
| 1,642,227,983,603
| 1,642,011,696,000
| 1,642,011,696,000
| 228,607,691
| 0
| 0
|
Apache-2.0
| 1,576,584,269,000
| 1,576,584,268,000
| null |
UTF-8
|
Lean
| false
| false
| 323
|
lean
|
/-
Copyright (c) 2020 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
import Lean.Elab.PreDefinition.Basic
import Lean.Elab.PreDefinition.Structural
import Lean.Elab.PreDefinition.Main
import Lean.Elab.PreDefinition.MkInhabitant
|
0c34c8aec9eb69b8c9ae17874762f3ac04110c9f
|
26ac254ecb57ffcb886ff709cf018390161a9225
|
/src/data/sym2.lean
|
cfe2cf630195ca570f66fc0d4ecb6db18eee5040
|
[
"Apache-2.0"
] |
permissive
|
eric-wieser/mathlib
|
42842584f584359bbe1fc8b88b3ff937c8acd72d
|
d0df6b81cd0920ad569158c06a3fd5abb9e63301
|
refs/heads/master
| 1,669,546,404,255
| 1,595,254,668,000
| 1,595,254,668,000
| 281,173,504
| 0
| 0
|
Apache-2.0
| 1,595,263,582,000
| 1,595,263,581,000
| null |
UTF-8
|
Lean
| false
| false
| 10,271
|
lean
|
/-
Copyright (c) 2020 Kyle Miller All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Kyle Miller.
-/
import tactic.linarith
import data.sym
open function
open sym
/-!
# The symmetric square
This file defines the symmetric square, which is `Ξ± Γ Ξ±` modulo
swapping. This is also known as the type of unordered pairs.
More generally, the symmetric square is the second symmetric power
(see `data.sym`). The equivalence is `sym2.equiv_sym`.
From the point of view that an unordered pair is equivalent to a
multiset of cardinality two (see `sym2.equiv_multiset`), there is a
`has_mem` instance `sym2.mem`, which is a `Prop`-valued membership
test. Given `a β z` for `z : sym2 Ξ±`, it does not appear to be
possible, in general, to *computably* give the other element in the
pair. For this, `sym2.vmem a z` is a `Type`-valued membership test
that gives a way to obtain the other element with `sym2.vmem.other`.
Recall that an undirected graph (allowing self loops, but no multiple
edges) is equivalent to a symmetric relation on the vertex type `Ξ±`.
Given a symmetric relation on `Ξ±`, the corresponding edge set is
constructed by `sym2.from_rel`.
## Notation
The symmetric square has a setoid instance, so `β¦(a, b)β§` denotes a
term of the symmetric square.
## Tags
symmetric square, unordered pairs, symmetric powers
-/
namespace sym2
variables {Ξ± : Type*}
/--
This is the relation capturing the notion of pairs equivalent up to permutations.
-/
inductive rel (Ξ± : Type*) : (Ξ± Γ Ξ±) β (Ξ± Γ Ξ±) β Prop
| refl (x y : Ξ±) : rel (x, y) (x, y)
| swap (x y : Ξ±) : rel (x, y) (y, x)
attribute [refl] rel.refl
@[symm] lemma rel.symm {x y : Ξ± Γ Ξ±} : rel Ξ± x y β rel Ξ± y x :=
by { intro a, cases a, exact a, apply rel.swap }
@[trans] lemma rel.trans {x y z : Ξ± Γ Ξ±} : rel Ξ± x y β rel Ξ± y z β rel Ξ± x z :=
by { intros a b, cases_matching* rel _ _ _; apply rel.refl <|> apply rel.swap }
lemma rel.is_equivalence : equivalence (rel Ξ±) :=
begin
split, { intros x, cases x, refl },
split, { apply rel.symm },
{ intros x y z a b, apply rel.trans a b },
end
instance rel.setoid (Ξ± : Type*) : setoid (Ξ± Γ Ξ±) :=
β¨rel Ξ±, rel.is_equivalenceβ©
end sym2
/--
`sym2 Ξ±` is the symmetric square of `Ξ±`, which, in other words, is the
type of unordered pairs.
It is equivalent in a natural way to multisets of cardinality 2 (see
`sym2.equiv_multiset`).
-/
@[reducible]
def sym2 (Ξ± : Type*) := quotient (sym2.rel.setoid Ξ±)
namespace sym2
universe u
variables {Ξ± : Type u}
lemma eq_swap {a b : Ξ±} : β¦(a, b)β§ = β¦(b, a)β§ :=
by { rw quotient.eq, apply rel.swap }
lemma congr_right (a b c : Ξ±) : β¦(a, b)β§ = β¦(a, c)β§ β b = c :=
begin
split,
intro h, rw quotient.eq at h, cases h; refl,
intro h, apply congr_arg _ h,
end
/--
The functor `sym2` is functorial, and this function constructs the induced maps.
-/
def map {Ξ± Ξ² : Type*} (f : Ξ± β Ξ²) : sym2 Ξ± β sym2 Ξ² :=
quotient.map (prod.map f f) begin
rintros β¨aβ, aββ© β¨bβ, bββ© h,
cases h,
apply rel.refl,
apply rel.swap,
end
@[simp]
lemma map_id : sym2.map (@id Ξ±) = id :=
by tidy
lemma map_comp {Ξ± Ξ² Ξ³: Type*} {g : Ξ² β Ξ³} {f : Ξ± β Ξ²} : sym2.map (g β f) = sym2.map g β sym2.map f :=
by tidy
section membership
/-! ### Declarations about membership -/
/--
This is a predicate that determines whether a given term is a member of a term of the
symmetric square. From this point of view, the symmetric square is the subtype of
cardinality-two multisets on `Ξ±`.
-/
def mem (x : Ξ±) (z : sym2 Ξ±) : Prop :=
β (y : Ξ±), z = β¦(x, y)β§
instance : has_mem Ξ± (sym2 Ξ±) := β¨memβ©
lemma mk_has_mem (x y : Ξ±) : x β β¦(x, y)β§ :=
β¨y, rflβ©
/--
This is a type-valued version of the membership predicate `mem` that contains the other
element `y` of `z` such that `z = β¦(x, y)β§`. It is a subsingleton already,
so there is no need to apply `trunc` to the type.
-/
@[nolint has_inhabited_instance]
def vmem (x : Ξ±) (z : sym2 Ξ±) : Type u :=
{y : Ξ± // z = β¦(x, y)β§}
instance (x : Ξ±) (z : sym2 Ξ±) : subsingleton {y : Ξ± // z = β¦(x, y)β§} :=
β¨by { rintros β¨a, haβ© β¨b, hbβ©, rw ha at hb, rw congr_right at hb, tidy, }β©
/--
The `vmem` version of `mk_has_mem`.
-/
def mk_has_vmem (x y : Ξ±) : vmem x β¦(x, y)β§ :=
β¨y, rflβ©
instance {a : Ξ±} {z : sym2 Ξ±} : has_lift (vmem a z) (mem a z) := β¨Ξ» h, β¨h.val, h.propertyβ©β©
/--
Given an element of a term of the symmetric square (using `vmem`), retrieve the other element.
-/
def vmem.other {a : Ξ±} {p : sym2 Ξ±} (h : vmem a p) : Ξ± := h.val
/--
The defining property of the other element is that it can be used to
reconstruct the term of the symmetric square.
-/
lemma vmem_other_spec {a : Ξ±} {z : sym2 Ξ±} (h : vmem a z) : z = β¦(a, h.other)β§ :=
by { dunfold vmem.other, tidy, }
/--
This is the `mem`-based version of `other`.
-/
noncomputable def mem.other {a : Ξ±} {z : sym2 Ξ±} (h : a β z) : Ξ± :=
classical.some h
lemma mem_other_spec {a : Ξ±} {z : sym2 Ξ±} (h : a β z) :
β¦(a, h.other)β§ = z :=
begin
dunfold mem.other,
exact (classical.some_spec h).symm,
end
lemma other_is_mem_other {a : Ξ±} {z : sym2 Ξ±} (h : vmem a z) (h' : a β z) :
h.other = mem.other h' :=
by rw [βcongr_right a, βvmem_other_spec h, mem_other_spec]
lemma eq_iff {x y z w : Ξ±} :
β¦(x, y)β§ = β¦(z, w)β§ β (x = z β§ y = w) β¨ (x = w β§ y = z) :=
begin
split; intro h,
{ rw quotient.eq at h, cases h; tidy, },
{ cases h; rw [h.1, h.2], rw eq_swap, }
end
lemma mem_iff {a b c : Ξ±} : a β β¦(b, c)β§ β a = b β¨ a = c :=
begin
split,
{ intro h, cases h, rw eq_iff at h_h, tidy },
{ intro h, cases h, rw h, apply mk_has_mem,
rw h, rw eq_swap, apply mk_has_mem, }
end
end membership
/--
A type `Ξ±` is naturally included in the diagonal of `Ξ± Γ Ξ±`, and this function gives the image
of this diagonal in `sym2 Ξ±`.
-/
def diag (x : Ξ±) : sym2 Ξ± := β¦(x, x)β§
/--
A predicate for testing whether an element of `sym2 Ξ±` is on the diagonal.
-/
def is_diag (z : sym2 Ξ±) : Prop :=
z β set.range (@diag Ξ±)
lemma is_diag_iff_proj_eq (z : Ξ± Γ Ξ±) : is_diag β¦zβ§ β z.1 = z.2 :=
begin
cases z with a b,
split,
{ intro h, cases h with x h, dsimp [diag] at h,
cases eq_iff.mp h with h h; rw [βh.1, βh.2], },
{ intro h, dsimp at h, rw h, use b, simp [diag], },
end
instance is_diag.decidable_pred (Ξ± : Type u) [decidable_eq Ξ±] : decidable_pred (@is_diag Ξ±) :=
begin
intro z,
induction z,
change decidable (is_diag β¦zβ§),
rw is_diag_iff_proj_eq,
apply_instance,
apply subsingleton.elim,
end
section relations
/-! ### Declarations about symmetric relations -/
variables {r : Ξ± β Ξ± β Prop}
/--
Symmetric relations define a set on `sym2 Ξ±` by taking all those pairs
of elements that are related.
-/
def from_rel (sym : symmetric r) : set (sym2 Ξ±) :=
Ξ» z, quotient.rec_on z (Ξ» z, r z.1 z.2)
begin
intros z w p,
cases p,
simp,
simp,
split; apply sym,
end
@[simp]
lemma from_rel_proj_prop {sym : symmetric r} {z : Ξ± Γ Ξ±} : β¦zβ§ β from_rel sym β r z.1 z.2 :=
by tidy
@[simp]
lemma from_rel_prop {sym : symmetric r} {a b : Ξ±} : β¦(a, b)β§ β from_rel sym β r a b :=
by simp only [from_rel_proj_prop]
lemma from_rel_irreflexive {sym : symmetric r} :
irreflexive r β β {z}, z β from_rel sym β Β¬is_diag z :=
begin
split,
{ intros h z hr hd,
induction z,
have hd' := (is_diag_iff_proj_eq _).mp hd,
have hr' := from_rel_proj_prop.mp hr,
rw hd' at hr',
exact h _ hr',
refl, },
{ intros h x hr,
rw β @from_rel_prop _ _ sym at hr,
exact h hr β¨x, rflβ©, }
end
end relations
section sym_equiv
/-! ### Equivalence to the second symmetric power -/
local attribute [instance] vector.perm.is_setoid
private def from_vector {Ξ± : Type*} : vector Ξ± 2 β Ξ± Γ Ξ±
| β¨[a, b], hβ© := (a, b)
private lemma perm_card_two_iff {Ξ± : Type*} {aβ bβ aβ bβ : Ξ±} :
[aβ, bβ].perm [aβ, bβ] β (aβ = aβ β§ bβ = bβ) β¨ (aβ = bβ β§ bβ = aβ) :=
begin
split, swap,
intro h, cases h; rw [h.1, h.2], apply list.perm.swap', refl,
intro h,
rw βmultiset.coe_eq_coe at h,
repeat {rw βmultiset.cons_coe at h},
repeat {rw multiset.cons_eq_cons at h},
cases h,
{ cases h, cases h_right,
left, simp [h_left, h_right.1],
simp at h_right, tauto, },
{ rcases h.2 with β¨cs, h'β©,
repeat {rw multiset.cons_eq_cons at h'},
simp only [multiset.zero_ne_cons, multiset.coe_nil_eq_zero, exists_false, or_false, and_false, false_and] at h',
right, simp [h'.1.1, h'.2.1], },
end
/--
The symmetric square is equivalent to length-2 vectors up to permutations.
-/
def sym2_equiv_sym' {Ξ± : Type*} : equiv (sym2 Ξ±) (sym' Ξ± 2) :=
{ to_fun := quotient.map (Ξ» (x : Ξ± Γ Ξ±), β¨[x.1, x.2], rflβ©) (begin
intros x y h, cases h, refl, apply list.perm.swap', refl,
end),
inv_fun := quotient.map from_vector (begin
rintros β¨x, hxβ© β¨y, hyβ© h,
cases x with x0 x, simp at hx, tauto,
cases x with x1 x, simp at hx, exfalso, linarith [hx],
cases x with x2 x, swap, simp at hx, exfalso, linarith [hx],
cases y with y0 y, simp at hy, tauto,
cases y with y1 y, simp at hy, exfalso, linarith [hy],
cases y with y2 y, swap, simp at hy, exfalso, linarith [hy],
cases perm_card_two_iff.mp h; rw [h_1.1, h_1.2],
refl,
apply sym2.rel.swap,
end),
left_inv := by tidy,
right_inv := begin
intro x,
induction x,
cases x with x hx,
cases x with x0 x, simp at hx, tauto,
cases x with x1 x, simp at hx, exfalso, linarith [hx],
cases x with x2 x, swap, simp at hx, exfalso, linarith [hx],
refl,
refl,
end }
/--
The symmetric square is equivalent to the second symmetric power.
-/
def equiv_sym (Ξ± : Type*) : sym2 Ξ± β sym Ξ± 2 :=
equiv.trans sym2_equiv_sym' (sym_equiv_sym' Ξ± 2).symm
/--
The symmetric square is equivalent to multisets of cardinality
two. (This is currently a synonym for `equiv_sym`, but it's provided
in case the definition for `sym` changes.)
-/
def equiv_multiset (Ξ± : Type*) : sym2 Ξ± β {s : multiset Ξ± // s.card = 2} :=
equiv_sym Ξ±
end sym_equiv
end sym2
|
193280ee396c44dfbeba9c783fd7ffeb4fe581d2
|
b7fc5b86b12212bea5542eb2c9d9f0988fd78697
|
/src/solutions/wednesday/topological_spaces.lean
|
f55ec7ba2f18ccddfab0c1e2748a60d74c0368c1
|
[] |
no_license
|
stjordanis/lftcm2020
|
3b16591aec853c8546d9c8b69c0bf3f5f3956fee
|
1f3485e4dafdc587b451ec5144a1d8d3ec9b411e
|
refs/heads/master
| 1,675,958,865,413
| 1,609,901,722,000
| 1,609,901,722,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 19,529
|
lean
|
import tactic
import data.set.finite
import data.real.basic -- for metrics
/-
# (Re)-Building topological spaces in Lean
Mathlib has a large library of results on topological spaces, including various
constructions, separation axioms, Tychonoff's theorem, sheaves, Stone-Δech
compactification, Heine-Cantor, to name but a few.
See https://leanprover-community.github.io/theories/topology.html which for a
(subset) of what's in library.
But today we will ignore all that, and build our own version of topological
spaces from scratch!
(On Friday morning Patrick Massot will lead a session exploring the existing
mathlib library in more detail)
To get this file run either `leanproject get lftcm2020`, if you didn't already or cd to
that folder and run `git pull; leanproject get-mathlib-cache`, this is
`src/exercise_sources/wednesday/topological_spaces.lean`.
The exercises are spread throughout, you needn't do them in order! They are marked as
short, medium and long, so I suggest you try some short ones first.
First a little setup, we will be making definitions involving the real numbers,
the theory of which is not computable, and we'll use sets.
-/
noncomputable theory
open set
/-!
## What is a topological space:
There are many definitions: one from Wikipedia:
A topological space is an ordered pair (X, Ο), where X is a set and Ο is a
collection of subsets of X, satisfying the following axioms:
- The empty set and X itself belong to Ο.
- Any arbitrary (finite or infinite) union of members of Ο still belongs to Ο.
- The intersection of any finite number of members of Ο still belongs to Ο.
We can formalize this as follows: -/
class topological_space_wiki :=
(X : Type) -- the underlying Type that the topology will be on
(Ο : set (set X)) -- the set of open subsets of X
(empty_mem : β
β Ο) -- empty set is open
(univ_mem : univ β Ο) -- whole space is open
(union : β B β Ο, ββ B β Ο) -- arbitrary unions (sUnions) of members of Ο are open
(inter : β (B β Ο) (h : finite B), ββ B β Ο) -- finite intersections of
-- members of Ο are open
/-
Before we go on we should be sure we want to use this as our definition.
-/
-- omit
/- (Changing your definitions later can be less of a hassle in formalized
mathematics than pen and paper maths as the proof assistant will tell you
exactly which steps in which proofs you broke, it can also be more of a hassle
as you actually have to fix things, so its still best to get it right
the first time!) -/
-- omit
@[ext]
class topological_space (X : Type) :=
(is_open : set X β Prop) -- why set X β Prop not set (set X)? former plays
-- nicer with typeclasses later
(empty_mem : is_open β
)
(univ_mem : is_open univ)
(union : β (B : set (set X)) (h : β b β B, is_open b), is_open (ββ B))
(inter : β (A B : set X) (hA : is_open A) (hB : is_open B), is_open (A β© B))
namespace topological_space
/- We can now work with topological spaces like this. -/
example (X : Type) [topological_space X] (U V W : set X) (hU : is_open U) (hV : is_open V)
(hW : is_open W) : is_open (U β© V β© W) :=
begin
apply inter _ _ _ hW,
exact inter _ _ hU hV,
end
/- ## Exercise 0 [short]:
One of the axioms of a topological space we have here is unnecessary, it follows
from the others. If we remove it we'll have less work to do each time we want to
create a new topological space so:
1. Identify and remove the unneeded axiom, make sure to remove it throughout the file.
2. Add the axiom back as a lemma with the same name and prove it based on the
others, so that the _interface_ is the same. -/
-- omit
lemma empty_mem' (X : Type) [topological_space X] : is_open (β
: set X) :=
begin
convert union (β
: set (set X)) _; simp,
end
-- omit
/- Defining a basic topology now works like so: -/
def discrete (X : Type) : topological_space X :=
{ is_open := Ξ» U, true, -- everything is open
empty_mem := trivial,
univ_mem := trivial,
union := begin intros B h, trivial, end,
inter := begin intros A hA B hB, trivial, end }
/- ## Exercise 1 [medium]:
One way me might want to create topological spaces in practice is to take
the coarsest possible topological space containing a given set of is_open.
To define this we might say we want to define what `is_open` is given the set
of generators.
So we want to define the predicate `is_open` by declaring that each generator
will be open, the intersection of two opens will be open, and each union of a
set of opens will be open, and finally the empty and whole space (`univ`) must
be open. The cleanest way to do this is as an inductive definition.
The exercise is to make this definition of the topological space generated by a
given set in Lean.
### Hint:
As a hint for this exercise take a look at the following definition of a
constructible set of a topological space, defined by saying that an intersection
of an open and a closed set is constructible and that the union of any pair of
constructible sets is constructible.
(Bonus exercise: mathlib doesn't have any theory of constructible sets, make one and PR
it! [arbitrarily long!], or just prove that open and closed sets are constructible for now) -/
inductive is_constructible {X : Type} (T : topological_space X) : set X β Prop
/- Given two open sets in `T`, the intersection of one with the complement of
the other open is locally closed, hence constructible: -/
| locally_closed : β (A B : set X), is_open A β is_open B β is_constructible (A β© BαΆ)
-- Given two constructible sets their union is constructible:
| union : β A B, is_constructible A β is_constructible B β is_constructible (A βͺ B)
-- For example we can now use this definition to prove the empty set is constructible
example {X : Type} (T : topological_space X) : is_constructible T β
:=
begin
-- The intersection of the whole space (open) with the empty set (closed) is
-- locally closed, hence constructible
have := is_constructible.locally_closed univ univ T.univ_mem T.univ_mem,
-- but simp knows that's just the empty set (`simp` uses `this` automatically)
simpa,
end
/-- The open sets of the least topology containing a collection of basic sets. -/
inductive generated_open (X : Type) (g : set (set X)) : set X β Prop
-- The exercise: Add a definition here defining which sets are generated by `g` like the
-- `is_constructible` definition above.
-- omit
| basic : β s β g, generated_open s
| univ : generated_open univ
| inter : βs t, generated_open s β generated_open t β generated_open (s β© t)
| sUnion : βk, (β s β k, generated_open s) β generated_open (ββ k)
lemma generated_open.empty (X : Type) (g : set (set X)) : generated_open X g β
:=
begin
have := generated_open.sUnion (β
: set (set X)),
simpa,
end
-- omit
/-- The smallest topological space containing the collection `g` of basic sets -/
def generate_from (X : Type) (g : set (set X)) : topological_space X :=
{ is_open := generated_open X g,
empty_mem := /- inline sorry -/generated_open.empty X g/- inline sorry -/,
univ_mem := /- inline sorry -/generated_open.univ/- inline sorry -/,
inter := /- inline sorry -/generated_open.inter/- inline sorry -/,
union := /- inline sorry -/generated_open.sUnion/- inline sorry -/ }
/- ## Exercise 2 [short]:
Define the indiscrete topology on any type using this.
(To do it without this it is surprisingly fiddly to prove that the set `{β
, univ}`
actually forms a topology) -/
def indiscrete (X : Type) : topological_space X :=
/- inline sorry -/ generate_from X β
/- inline sorry -/
end topological_space
open topological_space
/- Now it is quite easy to give a topology on the product of a pair of
topological spaces. -/
instance prod.topological_space (X Y : Type) [topological_space X]
[topological_space Y] : topological_space (X Γ Y) :=
topological_space.generate_from (X Γ Y) {U | β (Ux : set X) (Uy : set Y)
(hx : is_open Ux) (hy : is_open Uy), U = set.prod Ux Uy}
-- the proof of this is bit long so I've left it out for the purpose of this file!
lemma is_open_prod_iff (X Y : Type) [topological_space X] [topological_space Y]
{s : set (X Γ Y)} :
is_open s β (βa b, (a, b) β s β βu v, is_open u β§ is_open v β§
a β u β§ b β v β§ set.prod u v β s) := sorry
/- # Metric spaces -/
open_locale big_operators
class metric_space_basic (X : Type) :=
(dist : X β X β β)
(dist_eq_zero_iff : β x y, dist x y = 0 β x = y)
(dist_symm : β x y, dist x y = dist y x)
(triangle : β x y z, dist x z β€ dist x y + dist y z)
namespace metric_space_basic
open topological_space
/- ## Exercise 3 [short]:
We have defined a metric space with a metric landing in β, and made no mention of
nonnegativity, (this is in line with the philosophy of using the easiest axioms for our
definitions as possible, to make it easier to define individual metrics). Show that we
really did define the usual notion of metric space. -/
lemma dist_nonneg {X : Type} [metric_space_basic X] (x y : X) : 0 β€ dist x y :=
-- sorry
begin
have := calc 0 = dist x x : by rw (dist_eq_zero_iff x x).mpr rfl
... β€ dist x y + dist y x : triangle x y x
... = dist x y + dist x y : by rw dist_symm
... = 2 * dist x y : by rw two_mul (dist x y),
linarith,
end
-- sorry
/- From a metric space we get an induced topological space structure like so: -/
instance {X : Type} [metric_space_basic X] : topological_space X :=
generate_from X { B | β (x : X) r, B = {y | dist x y < r} }
end metric_space_basic
open metric_space_basic
/- So far so good, now lets define the product of two metric spaces:
## Exercise 4 [medium]:
Fill in the proofs here.
Hint: the computer can do boring casework you would never dream of in real life.
`max` is defined as `if x < y then y else x` and the `split_ifs` tactic will
break apart if statements. -/
instance prod.metric_space_basic (X Y : Type) [metric_space_basic X] [metric_space_basic Y] :
metric_space_basic (X Γ Y) :=
{ dist := Ξ» u v, max (dist u.fst v.fst) (dist u.snd v.snd),
dist_eq_zero_iff :=
-- sorry
begin intros u v,
split; intro h,
{ have hf := dist_nonneg u.fst v.fst,
have hs := dist_nonneg u.snd v.snd,
have := max_le_iff.mp (le_of_eq h),
ext; rw β dist_eq_zero_iff; linarith, },
{ rw [h, (dist_eq_zero_iff _ _).mpr, (dist_eq_zero_iff _ _).mpr, max_self]; refl, },
end
-- sorry
,
dist_symm := /- inline sorry -/ begin intros u v, simp [metric_space_basic.dist_symm], end /- inline sorry -/,
triangle :=
-- sorry
begin
intros x y z,
have hf := triangle x.fst y.fst z.fst,
have hs := triangle x.snd y.snd z.snd,
simp only [max],
split_ifs; linarith,
end
-- sorry
}
/- β‘ Let's try to prove a simple lemma involving the product topology: β‘ -/
-- omit
set_option pp.all false
set_option trace.class_instances false
set_option trace.type_context.is_def_eq_detail false
-- omit
set_option trace.type_context.is_def_eq false
example (X : Type) [metric_space_basic X] : is_open {xy : X Γ X | dist xy.fst xy.snd < 100 } :=
begin
-- rw is_open_prod_iff X X,
-- this fails, why? Because we have two subtly different topologies on the product
-- they are equal but the proof that they are equal is nontrivial and the
-- typeclass mechanism can't see that they automatically to apply. We need to change
-- our set-up.
sorry,
end
/- Note that lemma works fine when there is only one topology involved. -/
lemma diag_closed (X : Type) [topological_space X] : is_open {xy : X Γ X | xy.fst β xy.snd } :=
begin
rw is_open_prod_iff X X,
sorry, -- Don't try and fill this in: see below!
end
/- ## Exercise 5 [short]:
The previous lemma isn't true! It requires a separation axiom. Define a `class`
that posits that the topology on a type `X` satisfies this axiom. Mathlib uses
`T_i` naming scheme for these axioms. -/
class t2_space (X : Type) [topological_space X] :=
(t2 : /- inline sorry -/ β (x y : X) (h : x β y), β (Ux Uy : set X) (hUx : is_open Ux) (hUy : is_open Uy) (hx : x β Ux) (hy : y β Uy), Ux β© Uy = β
/- inline sorry -/)
/- (Bonus exercises [medium], the world is your oyster: prove the correct
version of the above lemma `diag_closed`, prove that the discrete topology is t2,
or that any metric topology is t2, ). -/
-- omit
example (X : Type) [topological_space X] [t2_space X] : is_open {xy : X Γ X | xy.fst β xy.snd } :=
begin
rw is_open_prod_iff X X,
intros x y h,
obtain β¨Ux, Uy, hUx, hUy, hx, hy, hxyβ© := t2_space.t2 x y h,
use [Ux, Uy, hUx, hUy, hx, hy],
rintros β¨tx, tyβ© β¨ht1, ht2β©,
dsimp,
intro txy,
rw txy at *,
have : ty β Ux β© Uy := β¨ht1, ht2β©,
rw hxy at this,
exact this, -- exact not_mem_empty ty this,
end
-- omit
/- Let's fix the broken example from earlier, by redefining the topology on a metric space.
We have unfortunately created two topologies on `X Γ Y`, one via `prod.topology`
that we defined earlier as the product of the two topologies coming from the
respective metric space structures. And one coming from the metric on the product.
These are equal, i.e. the same topology (otherwise mathematically the product
would not be a good definition). However they are not definitionally equal, there
is as nontrivial proof to show they are the same. The typeclass system (which finds
the relevant topological space instance when we use lemmas involving topological
spaces) isn't able to check that topological space structures which are equal
for some nontrivial reason are equal on the fly so it gets stuck.
We can use `extends` to say that a metric space is an extra structure on top of
being a topological space so we are making a choice of topology for each metric space.
This may not be *definitionally* equal to the induced topology, but we should add the
axiom that the metric and the topology are equal to stop us from creating a metric
inducing a different topology to the topological structure we chose. -/
class metric_space (X : Type) extends topological_space X, metric_space_basic X :=
(compatible : β U, is_open U β generated_open X { B | β (x : X) r, B = {y | dist x y < r}} U)
namespace metric_space
open topological_space
/- This might seem a bit inconvenient to have to define a topological space each time
we want a metric space.
We would still like a way of making a `metric_space` just given a metric and some
properties it satisfies, i.e. a `metric_space_basic`, so we should setup a metric space
constructor from a `metric_space_basic` by setting the topology to be the induced one. -/
def of_basic {X : Type} (m : metric_space_basic X) : metric_space X :=
{ compatible := begin intros, refl, /- this should work when the above parts are complete -/ end,
..m,
..@metric_space_basic.topological_space X m }
/- Now lets define the product of two metric spaces properly -/
instance {X Y : Type} [metric_space X] [metric_space Y] : metric_space (X Γ Y) :=
{ compatible :=
begin
-- Let's not fill this in for the demo, let me know if you do it!
-- sorry
rintros U,
rw is_open_prod_iff,
split; intro h,
sorry,
sorry,
-- sorry
end,
..prod.topological_space X Y,
..prod.metric_space_basic X Y, }
/- unregister the bad instance we defined earlier -/
local attribute [-instance] metric_space_basic.topological_space
/- Now this will work, there is only one topological space on the product, we can
rewrite like we tried to before a lemma about topologies our result on metric spaces,
as there is only one topology here.
## Exercise 6 [long?]:
Complete the proof of the example (you can generalise the 100 too if it makes it
feel less silly). -/
example (X : Type) [metric_space X] : is_open {xy : X Γ X | dist xy.fst xy.snd < 100 } :=
begin
rw is_open_prod_iff X X,
-- sorry
intros x y h,
use [{t | dist x t < 50 - dist x y / 2}, {t | dist y t < 50 - dist x y / 2}],
split,
{ rw compatible,
apply generated_open.basic,
use [x, 50 - dist x y / 2], },
split,
{ rw compatible,
apply generated_open.basic,
use [y, 50 - dist x y / 2], },
split,
{ dsimp,
rw (metric_space_basic.dist_eq_zero_iff x x).mpr rfl,
change dist x y < 100 at h,
linarith, },
split,
{ dsimp,
rw (metric_space_basic.dist_eq_zero_iff y y).mpr rfl,
change dist x y < 100 at h,
linarith, },
rintros β¨tx, tyβ© β¨htx, htyβ©,
dsimp at *,
calc dist tx ty β€ dist tx x + dist x ty : triangle tx x ty
... β€ dist tx x + dist x y + dist y ty : by linarith [triangle x y ty]
... = dist x tx + dist x y + dist y ty : by rw dist_symm
... < 100 : by linarith,
-- sorry
end
end metric_space
namespace topological_space
/- As mentioned, there are many definitions of a topological space, for instance
one can define them via specifying a set of closed sets satisfying various
axioms, this is equivalent and sometimes more convenient.
We _could_ create two distinct Types defined by different data and provide an
equivalence between theses types, e.g. `topological_space_via_open_sets` and
`topological_space_via_closed_sets`, but this would quickly get unwieldy.
What's better is to make an alternative _constructor_ for our original
topological space. This is a function takes a set of subsets satisfying the
axioms to be the closed sets of a topological space and creates the
topological space defined by the corresponding set of open sets.
## Exercise 7 [medium]:
Complete the following constructor of a topological space from a set of subsets
of a given type `X` satisfying the axioms for the closed sets of a topology.
Hint: there are many useful lemmas about complements in mathlib, with names
involving `compl`, like `compl_empty`, `compl_univ`, `compl_compl`, `compl_sUnion`,
`mem_compl_image`, `compl_inter`, `compl_compl'`, `you can #check them to see what they say. -/
def mk_closed_sets
(X : Type)
(Ο : set (set X))
(empty_mem : β
β Ο)
(univ_mem : univ β Ο)
(inter : β B β Ο, ββ B β Ο)
(union : β (A β Ο) (B β Ο), A βͺ B β Ο) :
topological_space X := {
is_open := Ξ» U, U β compl '' Ο, -- the corresponding `is_open`
empty_mem :=
-- sorry
begin
use univ,
split,
assumption,
exact compl_univ,
end
-- sorry
,
univ_mem :=
-- sorry
begin
use β
,
split,
assumption,
exact compl_empty,
end
-- sorry
,
union :=
-- sorry
begin
intros B hB,
use (ββ B)αΆ,
split,
{ rw compl_sUnion,
apply inter,
intros b hb,
have := hB bαΆ ((mem_compl_image b B).mp hb),
rw mem_compl_image at this,
simpa, },
exact compl_compl',
end
-- sorry
,
inter :=
-- sorry
begin
rintros A B β¨Ac, hA, rflβ© β¨Bc, hB, rflβ©,
rw [mem_compl_image, compl_inter, compl_compl, compl_compl],
exact union _ hA _ hB,
end
-- sorry
}
/- Here are some more exercises:
## Exercise 8 [medium/long]:
Define the cofinite topology on any type (PR it to mathlib?).
## Exercise 9 [medium/long]:
Define a normed space?
## Exercise 10 [medium/long]:
Define more separation axioms?
-/
end topological_space
|
0ca02b89eda87e824be88da10b138c840c499bc9
|
9dc8cecdf3c4634764a18254e94d43da07142918
|
/src/order/category/NonemptyFinLinOrd.lean
|
b8a1b4a25f0f19fe548fff7126c5436472700d88
|
[
"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
| 3,251
|
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 data.fintype.order
import order.category.LinearOrder
/-!
# Nonempty finite linear orders
This defines `NonemptyFinLinOrd`, the category of nonempty finite linear orders with monotone maps.
This is the index category for simplicial objects.
-/
universes u v
open category_theory
/-- A typeclass for nonempty finite linear orders. -/
class nonempty_fin_lin_ord (Ξ± : Type*) extends fintype Ξ±, linear_order Ξ± :=
(nonempty : nonempty Ξ± . tactic.apply_instance)
attribute [instance] nonempty_fin_lin_ord.nonempty
@[priority 100]
instance nonempty_fin_lin_ord.to_bounded_order (Ξ± : Type*) [nonempty_fin_lin_ord Ξ±] :
bounded_order Ξ± :=
fintype.to_bounded_order Ξ±
instance punit.nonempty_fin_lin_ord : nonempty_fin_lin_ord punit := { }
instance fin.nonempty_fin_lin_ord (n : β) : nonempty_fin_lin_ord (fin (n+1)) := { }
instance ulift.nonempty_fin_lin_ord (Ξ± : Type u) [nonempty_fin_lin_ord Ξ±] :
nonempty_fin_lin_ord (ulift.{v} Ξ±) :=
{ .. linear_order.lift' equiv.ulift (equiv.injective _) }
instance (Ξ± : Type*) [nonempty_fin_lin_ord Ξ±] : nonempty_fin_lin_ord Ξ±α΅α΅ :=
{ ..order_dual.fintype Ξ± }
/-- The category of nonempty finite linear orders. -/
def NonemptyFinLinOrd := bundled nonempty_fin_lin_ord
namespace NonemptyFinLinOrd
instance : bundled_hom.parent_projection @nonempty_fin_lin_ord.to_linear_order := β¨β©
attribute [derive [large_category, concrete_category]] NonemptyFinLinOrd
instance : has_coe_to_sort NonemptyFinLinOrd Type* := bundled.has_coe_to_sort
/-- Construct a bundled `NonemptyFinLinOrd` from the underlying type and typeclass. -/
def of (Ξ± : Type*) [nonempty_fin_lin_ord Ξ±] : NonemptyFinLinOrd := bundled.of Ξ±
@[simp] lemma coe_of (Ξ± : Type*) [nonempty_fin_lin_ord Ξ±] : β₯(of Ξ±) = Ξ± := rfl
instance : inhabited NonemptyFinLinOrd := β¨of punitβ©
instance (Ξ± : NonemptyFinLinOrd) : nonempty_fin_lin_ord Ξ± := Ξ±.str
instance has_forget_to_LinearOrder : has_forgetβ NonemptyFinLinOrd LinearOrder :=
bundled_hom.forgetβ _ _
/-- Constructs an equivalence between nonempty finite linear orders from an order isomorphism
between them. -/
@[simps] def iso.mk {Ξ± Ξ² : NonemptyFinLinOrd.{u}} (e : Ξ± βo Ξ²) : Ξ± β
Ξ² :=
{ hom := e,
inv := e.symm,
hom_inv_id' := by { ext, exact e.symm_apply_apply x },
inv_hom_id' := by { ext, exact e.apply_symm_apply x } }
/-- `order_dual` as a functor. -/
@[simps] def dual : NonemptyFinLinOrd β₯€ NonemptyFinLinOrd :=
{ obj := Ξ» X, of Xα΅α΅, map := Ξ» X Y, order_hom.dual }
/-- The equivalence between `FinPartialOrder` and itself induced by `order_dual` both ways. -/
@[simps functor inverse] def dual_equiv : NonemptyFinLinOrd β NonemptyFinLinOrd :=
equivalence.mk dual dual
(nat_iso.of_components (Ξ» X, iso.mk $ order_iso.dual_dual X) $ Ξ» X Y f, rfl)
(nat_iso.of_components (Ξ» X, iso.mk $ order_iso.dual_dual X) $ Ξ» X Y f, rfl)
end NonemptyFinLinOrd
lemma NonemptyFinLinOrd_dual_comp_forget_to_LinearOrder :
NonemptyFinLinOrd.dual β forgetβ NonemptyFinLinOrd LinearOrder =
forgetβ NonemptyFinLinOrd LinearOrder β LinearOrder.dual := rfl
|
f9ba55fcbe44b1f3ad383e48bc17d9ee0ad79d23
|
bbecf0f1968d1fba4124103e4f6b55251d08e9c4
|
/src/number_theory/function_field.lean
|
745e5f77ad3f2a9dfaef2536d8902b377c176c65
|
[
"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
| 4,283
|
lean
|
/-
Copyright (c) 2021 Anne Baanen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anne Baanen, Ashvni Narayanan
-/
import ring_theory.algebraic
import ring_theory.localization
import ring_theory.integrally_closed
/-!
# Function fields
This file defines a function field and the ring of integers corresponding to it.
## Main definitions
- `function_field Fq F` states that `F` is a function field over the (finite) field `Fq`,
i.e. it is a finite extension of the field of rational polynomials in one variable over `Fq`.
- `function_field.ring_of_integers` defines the ring of integers corresponding to a function field
as the integral closure of `polynomial Fq` in the function field.
## Implementation notes
The definitions that involve a field of fractions choose a canonical field of fractions,
but are independent of that choice. We also omit assumptions like `finite Fq` or
`is_scalar_tower (polynomial Fq) (fraction_ring (polynomial Fq)) F` in definitions,
adding them back in lemmas when they are needed.
## References
* [D. Marcus, *Number Fields*][marcus1977number]
* [J.W.S. Cassels, A. FrΓΆlich, *Algebraic Number Theory*][cassels1967algebraic]
* [P. Samuel, *Algebraic Theory of Numbers*][samuel1970algebraic]
## Tags
function field, ring of integers
-/
noncomputable theory
variables (Fq F : Type) [field Fq] [field F]
/-- `F` is a function field over the finite field `Fq` if it is a finite
extension of the field of rational polynomials in one variable over `Fq`.
Note that `F` can be a function field over multiple, non-isomorphic, `Fq`.
-/
abbreviation function_field [algebra (fraction_ring (polynomial Fq)) F] : Prop :=
finite_dimensional (fraction_ring (polynomial Fq)) F
/-- `F` is a function field over `Fq` iff it is a finite extension of `Fq(t)`. -/
protected lemma function_field_iff (Fqt : Type*) [field Fqt]
[algebra (polynomial Fq) Fqt] [is_fraction_ring (polynomial Fq) Fqt]
[algebra (fraction_ring (polynomial Fq)) F] [algebra Fqt F]
[algebra (polynomial Fq) F] [is_scalar_tower (polynomial Fq) Fqt F]
[is_scalar_tower (polynomial Fq) (fraction_ring (polynomial Fq)) F] :
function_field Fq F β finite_dimensional Fqt F :=
begin
let e := fraction_ring.alg_equiv (polynomial Fq) Fqt,
have : β c (x : F), e c β’ x = c β’ x,
{ intros c x,
rw [algebra.smul_def, algebra.smul_def],
congr,
refine congr_fun _ c,
refine is_localization.ext (non_zero_divisors (polynomial Fq)) _ _ _ _ _ _ _;
intros; simp only [alg_equiv.map_one, ring_hom.map_one, alg_equiv.map_mul, ring_hom.map_mul,
alg_equiv.commutes, β is_scalar_tower.algebra_map_apply], },
split; intro h; resetI,
{ let b := finite_dimensional.fin_basis (fraction_ring (polynomial Fq)) F,
exact finite_dimensional.of_fintype_basis (b.map_coeffs e this) },
{ let b := finite_dimensional.fin_basis Fqt F,
refine finite_dimensional.of_fintype_basis (b.map_coeffs e.symm _),
intros c x, convert (this (e.symm c) x).symm; simp },
end
namespace function_field
/-- The function field analogue of `number_field.ring_of_integers`:
`function_field.ring_of_integers Fq Fqt F` is the integral closure of `Fq[t]` in `F`.
We don't actually assume `F` is a function field over `Fq` in the definition,
only when proving its properties.
-/
def ring_of_integers [algebra (polynomial Fq) F] := integral_closure (polynomial Fq) F
namespace ring_of_integers
variables [algebra (polynomial Fq) F]
instance : integral_domain (ring_of_integers Fq F) :=
(ring_of_integers Fq F).integral_domain
instance : is_integral_closure (ring_of_integers Fq F) (polynomial Fq) F :=
integral_closure.is_integral_closure _ _
variables [algebra (fraction_ring (polynomial Fq)) F] [function_field Fq F]
variables [is_scalar_tower (polynomial Fq) (fraction_ring (polynomial Fq)) F]
instance : is_fraction_ring (ring_of_integers Fq F) F :=
integral_closure.is_fraction_ring_of_finite_extension (fraction_ring (polynomial Fq)) F
instance : is_integrally_closed (ring_of_integers Fq F) :=
integral_closure.is_integrally_closed_of_finite_extension (fraction_ring (polynomial Fq))
-- TODO: show `ring_of_integers Fq F` is a Dedekind domain
end ring_of_integers
end function_field
|
98885f5a0b5f88e5e95296a4326e3f5836853db5
|
2a70b774d16dbdf5a533432ee0ebab6838df0948
|
/_target/deps/mathlib/src/linear_algebra/matrix.lean
|
01350ea12c5f6c5160909cec235f772ee7cdb652
|
[
"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
| 38,431
|
lean
|
/-
Copyright (c) 2019 Johannes HΓΆlzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Johannes HΓΆlzl, Patrick Massot, Casper Putz
-/
import linear_algebra.finite_dimensional
import linear_algebra.nonsingular_inverse
import linear_algebra.multilinear
import linear_algebra.dual
/-!
# Linear maps and matrices
This file defines the maps to send matrices to a linear map,
and to send linear maps between modules with a finite bases
to matrices. This defines a linear equivalence between linear maps
between finite-dimensional vector spaces and matrices indexed by
the respective bases.
It also defines the trace of an endomorphism, and the determinant of a family of vectors with
respect to some basis.
Some results are proved about the linear map corresponding to a
diagonal matrix (`range`, `ker` and `rank`).
## Main definitions
In the list below, and in all this file, `R` is a commutative ring (semiring
is sometimes enough), `M` and its variations are `R`-modules, `ΞΉ`, `ΞΊ`, `n` and `m` are finite
types used for indexing.
* `linear_map.to_matrix`: given bases `vβ : ΞΉ β Mβ` and `vβ : ΞΊ β Mβ`,
the `R`-linear equivalence from `Mβ ββ[R] Mβ` to `matrix ΞΊ ΞΉ R`
* `matrix.to_lin`: the inverse of `linear_map.to_matrix`
* `linear_map.to_matrix'`: the `R`-linear equivalence from `(n β R) ββ[R] (m β R)`
to `matrix n m R` (with the standard basis on `n β R` and `m β R`)
* `matrix.to_lin'`: the inverse of `linear_map.to_matrix'`
* `alg_equiv_matrix`: given a basis indexed by `n`, the `R`-algebra equivalence between
`R`-endomorphisms of `M` and `matrix n n R`
* `matrix.trace`: the trace of a square matrix
* `linear_map.trace`: the trace of an endomorphism
* `is_basis.to_matrix`: the matrix whose columns are a given family of vectors in a given basis
* `is_basis.to_matrix_equiv`: given a basis, the linear equivalence between families of vectors
and matrices arising from `is_basis.to_matrix`
* `is_basis.det`: the determinant of a family of vectors with respect to a basis, as a multilinear
map
## Tags
linear_map, matrix, linear_equiv, diagonal, det, trace
-/
noncomputable theory
open linear_map matrix set submodule
open_locale big_operators
open_locale matrix
universes u v w
section to_matrix'
variables {R : Type*} [comm_ring R]
variables {l m n : Type*} [fintype l] [fintype m] [fintype n]
instance [decidable_eq m] [decidable_eq n] (R) [fintype R] : fintype (matrix m n R) :=
by unfold matrix; apply_instance
/-- `matrix.mul_vec M` is a linear map. -/
def matrix.mul_vec_lin (M : matrix m n R) : (n β R) ββ[R] (m β R) :=
{ to_fun := M.mul_vec,
map_add' := Ξ» v w, funext (Ξ» i, dot_product_add _ _ _),
map_smul' := Ξ» c v, funext (Ξ» i, dot_product_smul _ _ _) }
@[simp] lemma matrix.mul_vec_lin_apply (M : matrix m n R) (v : n β R) :
matrix.mul_vec_lin M v = M.mul_vec v := rfl
variables [decidable_eq n]
@[simp] lemma matrix.mul_vec_std_basis (M : matrix m n R) (i j) :
M.mul_vec (std_basis R (Ξ» _, R) j 1) i = M i j :=
begin
have : (β j', M i j' * if j = j' then 1 else 0) = M i j,
{ simp_rw [mul_boole, finset.sum_ite_eq, finset.mem_univ, if_true] },
convert this,
ext,
split_ifs with h; simp only [std_basis_apply],
{ rw [h, function.update_same] },
{ rw [function.update_noteq (ne.symm h), pi.zero_apply] }
end
/-- Linear maps `(n β R) ββ[R] (m β R)` are linearly equivalent to `matrix m n R`. -/
def linear_map.to_matrix' : ((n β R) ββ[R] (m β R)) ββ[R] matrix m n R :=
{ to_fun := Ξ» f i j, f (std_basis R (Ξ» _, R) j 1) i,
inv_fun := matrix.mul_vec_lin,
right_inv := Ξ» M, by { ext i j, simp only [matrix.mul_vec_std_basis, matrix.mul_vec_lin_apply] },
left_inv := Ξ» f, begin
apply (pi.is_basis_fun R n).ext,
intro j, ext i,
simp only [matrix.mul_vec_std_basis, matrix.mul_vec_lin_apply]
end,
map_add' := Ξ» f g, by { ext i j, simp only [pi.add_apply, linear_map.add_apply] },
map_smul' := Ξ» c f, by { ext i j, simp only [pi.smul_apply, linear_map.smul_apply] } }
/-- A `matrix m n R` is linearly equivalent to a linear map `(n β R) ββ[R] (m β R)`. -/
def matrix.to_lin' : matrix m n R ββ[R] ((n β R) ββ[R] (m β R)) :=
linear_map.to_matrix'.symm
@[simp] lemma linear_map.to_matrix'_symm :
(linear_map.to_matrix'.symm : matrix m n R ββ[R] _) = matrix.to_lin' :=
rfl
@[simp] lemma matrix.to_lin'_symm :
(matrix.to_lin'.symm : ((n β R) ββ[R] (m β R)) ββ[R] _) = linear_map.to_matrix' :=
rfl
@[simp] lemma linear_map.to_matrix'_to_lin' (M : matrix m n R) :
linear_map.to_matrix' (matrix.to_lin' M) = M :=
linear_map.to_matrix'.apply_symm_apply M
@[simp] lemma matrix.to_lin'_to_matrix' (f : (n β R) ββ[R] (m β R)) :
matrix.to_lin' (linear_map.to_matrix' f) = f :=
matrix.to_lin'.apply_symm_apply f
@[simp] lemma linear_map.to_matrix'_apply (f : (n β R) ββ[R] (m β R)) (i j) :
linear_map.to_matrix' f i j = f (Ξ» j', if j' = j then 1 else 0) i :=
begin
simp only [linear_map.to_matrix', linear_equiv.mk_apply],
congr,
ext j',
split_ifs with h,
{ rw [h, std_basis_same] },
apply std_basis_ne _ _ _ _ h
end
@[simp] lemma matrix.to_lin'_apply (M : matrix m n R) (v : n β R) :
matrix.to_lin' M v = M.mul_vec v := rfl
@[simp] lemma matrix.to_lin'_one :
matrix.to_lin' (1 : matrix n n R) = id :=
by { ext, simp }
@[simp] lemma linear_map.to_matrix'_id :
(linear_map.to_matrix' (linear_map.id : (n β R) ββ[R] (n β R))) = 1 :=
by { ext, rw [matrix.one_apply, linear_map.to_matrix'_apply, id_apply] }
@[simp] lemma matrix.to_lin'_mul [decidable_eq m] (M : matrix l m R) (N : matrix m n R) :
matrix.to_lin' (M β¬ N) = (matrix.to_lin' M).comp (matrix.to_lin' N) :=
by { ext, simp }
lemma linear_map.to_matrix'_comp [decidable_eq l]
(f : (n β R) ββ[R] (m β R)) (g : (l β R) ββ[R] (n β R)) :
(f.comp g).to_matrix' = f.to_matrix' β¬ g.to_matrix' :=
suffices (f.comp g) = (f.to_matrix' β¬ g.to_matrix').to_lin',
by rw [this, linear_map.to_matrix'_to_lin'],
by rw [matrix.to_lin'_mul, matrix.to_lin'_to_matrix', matrix.to_lin'_to_matrix']
lemma linear_map.to_matrix'_mul [decidable_eq m]
(f g : (m β R) ββ[R] (m β R)) :
(f * g).to_matrix' = f.to_matrix' β¬ g.to_matrix' :=
linear_map.to_matrix'_comp f g
end to_matrix'
section to_matrix
variables {R : Type*} [comm_ring R]
variables {l m n : Type*} [fintype l] [fintype m] [fintype n] [decidable_eq n]
variables {Mβ Mβ : Type*} [add_comm_group Mβ] [add_comm_group Mβ] [module R Mβ] [module R Mβ]
variables {vβ : n β Mβ} (hvβ : is_basis R vβ) {vβ : m β Mβ} (hvβ : is_basis R vβ)
/-- Given bases of two modules `Mβ` and `Mβ` over a commutative ring `R`, we get a linear
equivalence between linear maps `Mβ ββ Mβ` and matrices over `R` indexed by the bases. -/
def linear_map.to_matrix : (Mβ ββ[R] Mβ) ββ[R] matrix m n R :=
linear_equiv.trans (linear_equiv.arrow_congr hvβ.equiv_fun hvβ.equiv_fun) linear_map.to_matrix'
/-- Given bases of two modules `Mβ` and `Mβ` over a commutative ring `R`, we get a linear
equivalence between matrices over `R` indexed by the bases and linear maps `Mβ ββ Mβ`. -/
def matrix.to_lin : matrix m n R ββ[R] (Mβ ββ[R] Mβ) :=
(linear_map.to_matrix hvβ hvβ).symm
@[simp] lemma linear_map.to_matrix_symm :
(linear_map.to_matrix hvβ hvβ).symm = matrix.to_lin hvβ hvβ :=
rfl
@[simp] lemma matrix.to_lin_symm :
(matrix.to_lin hvβ hvβ).symm = linear_map.to_matrix hvβ hvβ :=
rfl
@[simp] lemma matrix.to_lin_to_matrix (f : Mβ ββ[R] Mβ) :
matrix.to_lin hvβ hvβ (linear_map.to_matrix hvβ hvβ f) = f :=
by rw [β matrix.to_lin_symm, linear_equiv.apply_symm_apply]
@[simp] lemma linear_map.to_matrix_to_lin (M : matrix m n R) :
linear_map.to_matrix hvβ hvβ (matrix.to_lin hvβ hvβ M) = M :=
by rw [β matrix.to_lin_symm, linear_equiv.symm_apply_apply]
lemma linear_map.to_matrix_apply (f : Mβ ββ[R] Mβ) (i : m) (j : n) :
linear_map.to_matrix hvβ hvβ f i j = hvβ.equiv_fun (f (vβ j)) i :=
begin
rw [linear_map.to_matrix, linear_equiv.trans_apply, linear_map.to_matrix'_apply,
linear_equiv.arrow_congr_apply, is_basis.equiv_fun_symm_apply, finset.sum_eq_single j,
if_pos rfl, one_smul],
{ intros j' _ hj',
rw [if_neg hj', zero_smul] },
{ intro hj,
have := finset.mem_univ j,
contradiction }
end
lemma linear_map.to_matrix_transpose_apply (f : Mβ ββ[R] Mβ) (j : n) :
(linear_map.to_matrix hvβ hvβ f)α΅ j = hvβ.equiv_fun (f (vβ j)) :=
funext $ Ξ» i, f.to_matrix_apply _ _ i j
lemma linear_map.to_matrix_apply' (f : Mβ ββ[R] Mβ) (i : m) (j : n) :
linear_map.to_matrix hvβ hvβ f i j = hvβ.repr (f (vβ j)) i :=
linear_map.to_matrix_apply hvβ hvβ f i j
lemma linear_map.to_matrix_transpose_apply' (f : Mβ ββ[R] Mβ) (j : n) :
(linear_map.to_matrix hvβ hvβ f)α΅ j = hvβ.repr (f (vβ j)) :=
linear_map.to_matrix_transpose_apply hvβ hvβ f j
lemma matrix.to_lin_apply (M : matrix m n R) (v : Mβ) :
matrix.to_lin hvβ hvβ M v = β j, M.mul_vec (hvβ.equiv_fun v) j β’ vβ j :=
show hvβ.equiv_fun.symm (matrix.to_lin' M (hvβ.equiv_fun v)) = _,
by rw [matrix.to_lin'_apply, hvβ.equiv_fun_symm_apply]
@[simp] lemma matrix.to_lin_self (M : matrix m n R) (i : n) :
matrix.to_lin hvβ hvβ M (vβ i) = β j, M j i β’ vβ j :=
by simp only [matrix.to_lin_apply, matrix.mul_vec, dot_product, hvβ.equiv_fun_self, mul_boole,
finset.sum_ite_eq, finset.mem_univ, if_true]
@[simp]
lemma linear_map.to_matrix_id : linear_map.to_matrix hvβ hvβ id = 1 :=
begin
ext i j,
simp [linear_map.to_matrix_apply, is_basis.equiv_fun, matrix.one_apply, finsupp.single, eq_comm]
end
@[simp]
lemma matrix.to_lin_one : matrix.to_lin hvβ hvβ 1 = id :=
by rw [β linear_map.to_matrix_id hvβ, matrix.to_lin_to_matrix]
theorem linear_map.to_matrix_range [decidable_eq Mβ] [decidable_eq Mβ]
(f : Mβ ββ[R] Mβ) (k : m) (i : n) :
linear_map.to_matrix hvβ.range hvβ.range f β¨vβ k, mem_range_self kβ© β¨vβ i, mem_range_self iβ© =
linear_map.to_matrix hvβ hvβ f k i :=
by simp_rw [linear_map.to_matrix_apply, subtype.coe_mk, is_basis.equiv_fun_apply, hvβ.range_repr]
variables {Mβ : Type*} [add_comm_group Mβ] [module R Mβ] {vβ : l β Mβ} (hvβ : is_basis R vβ)
lemma linear_map.to_matrix_comp [decidable_eq m] (f : Mβ ββ[R] Mβ) (g : Mβ ββ[R] Mβ) :
linear_map.to_matrix hvβ hvβ (f.comp g) =
linear_map.to_matrix hvβ hvβ f β¬ linear_map.to_matrix hvβ hvβ g :=
by simp_rw [linear_map.to_matrix, linear_equiv.trans_apply,
linear_equiv.arrow_congr_comp _ hvβ.equiv_fun, linear_map.to_matrix'_comp]
lemma linear_map.to_matrix_mul (f g : Mβ ββ[R] Mβ) :
linear_map.to_matrix hvβ hvβ (f * g) =
linear_map.to_matrix hvβ hvβ f β¬ linear_map.to_matrix hvβ hvβ g :=
by { rw [show (@has_mul.mul (Mβ ββ[R] Mβ) _) = linear_map.comp, from rfl,
linear_map.to_matrix_comp hvβ hvβ hvβ f g] }
lemma matrix.to_lin_mul [decidable_eq m] (A : matrix l m R) (B : matrix m n R) :
matrix.to_lin hvβ hvβ (A β¬ B) =
(matrix.to_lin hvβ hvβ A).comp (matrix.to_lin hvβ hvβ B) :=
begin
apply (linear_map.to_matrix hvβ hvβ).injective,
haveI : decidable_eq l := Ξ» _ _, classical.prop_decidable _,
rw linear_map.to_matrix_comp hvβ hvβ hvβ,
repeat { rw linear_map.to_matrix_to_lin },
end
end to_matrix
section is_basis_to_matrix
variables {ΞΉ ΞΉ' : Type*} [fintype ΞΉ] [fintype ΞΉ']
variables {R M : Type*} [comm_ring R] [add_comm_group M] [module R M]
open function matrix
/-- From a basis `e : ΞΉ β M` and a family of vectors `v : ΞΉ' β M`, make the matrix whose columns
are the vectors `v i` written in the basis `e`. -/
def is_basis.to_matrix {e : ΞΉ β M} (he : is_basis R e) (v : ΞΉ' β M) : matrix ΞΉ ΞΉ' R :=
Ξ» i j, he.equiv_fun (v j) i
variables {e : ΞΉ β M} (he : is_basis R e) (v : ΞΉ' β M) (i : ΞΉ) (j : ΞΉ')
namespace is_basis
lemma to_matrix_apply : he.to_matrix v i j = he.equiv_fun (v j) i :=
rfl
lemma to_matrix_transpose_apply : (he.to_matrix v)α΅ j = he.repr (v j) :=
funext $ (Ξ» _, rfl)
lemma to_matrix_eq_to_matrix_constr [decidable_eq ΞΉ] (v : ΞΉ β M) :
he.to_matrix v = linear_map.to_matrix he he (he.constr v) :=
by { ext, simp [is_basis.to_matrix_apply, linear_map.to_matrix_apply] }
@[simp] lemma to_matrix_self [decidable_eq ΞΉ] : he.to_matrix e = 1 :=
begin
rw is_basis.to_matrix,
ext i j,
simp [is_basis.equiv_fun, matrix.one_apply, finsupp.single, eq_comm]
end
lemma to_matrix_update [decidable_eq ΞΉ'] (x : M) :
he.to_matrix (function.update v j x) = matrix.update_column (he.to_matrix v) j (he.repr x) :=
begin
ext i' k,
rw [is_basis.to_matrix, matrix.update_column_apply, he.to_matrix_apply],
split_ifs,
{ rw [h, update_same j x v, he.equiv_fun_apply] },
{ rw update_noteq h },
end
@[simp] lemma sum_to_matrix_smul_self : β (i : ΞΉ), he.to_matrix v i j β’ e i = v j :=
begin
conv_rhs { rw β he.total_repr (v j) },
rw [finsupp.total_apply, finsupp.sum_fintype],
{ refl },
simp
end
@[simp] lemma to_lin_to_matrix [decidable_eq ΞΉ'] (hv : is_basis R v) :
matrix.to_lin hv he (he.to_matrix v) = id :=
hv.ext (Ξ» i, by rw [to_lin_self, id_apply, he.sum_to_matrix_smul_self])
/-- From a basis `e : ΞΉ β M`, build a linear equivalence between families of vectors `v : ΞΉ β M`,
and matrices, making the matrix whose columns are the vectors `v i` written in the basis `e`. -/
def to_matrix_equiv {e : ΞΉ β M} (he : is_basis R e) : (ΞΉ β M) ββ[R] matrix ΞΉ ΞΉ R :=
{ to_fun := he.to_matrix,
map_add' := Ξ» v w, begin
ext i j,
change _ = _ + _,
simp [he.to_matrix_apply]
end,
map_smul' := begin
intros c v,
ext i j,
simp [he.to_matrix_apply]
end,
inv_fun := Ξ» m j, β i, (m i j) β’ e i,
left_inv := begin
intro v,
ext j,
simp [he.to_matrix_apply, he.equiv_fun_total (v j)]
end,
right_inv := begin
intros x,
ext k l,
simp [he.to_matrix_apply, he.equiv_fun.map_sum, he.equiv_fun.map_smul,
fintype.sum_apply k (Ξ» i, x i l β’ he.equiv_fun (e i)),
he.equiv_fun_self]
end }
end is_basis
section mul_linear_map_to_matrix
variables {N : Type*} [add_comm_group N] [module R N]
variables {b : ΞΉ β M} {b' : ΞΉ' β M} {c : ΞΉ β N} {c' : ΞΉ' β N}
variables (hb : is_basis R b) (hb' : is_basis R b') (hc : is_basis R c) (hc' : is_basis R c')
variables (f : M ββ[R] N)
@[simp] lemma is_basis_to_matrix_mul_linear_map_to_matrix [decidable_eq ΞΉ'] :
hc.to_matrix c' β¬ linear_map.to_matrix hb' hc' f = linear_map.to_matrix hb' hc f :=
(matrix.to_lin hb' hc).injective
(by rw [to_lin_to_matrix, to_lin_mul hb' hc' hc, to_lin_to_matrix, hc.to_lin_to_matrix, id_comp])
@[simp] lemma linear_map_to_matrix_mul_is_basis_to_matrix [decidable_eq ΞΉ] [decidable_eq ΞΉ'] :
linear_map.to_matrix hb' hc' f β¬ hb'.to_matrix b = linear_map.to_matrix hb hc' f :=
(matrix.to_lin hb hc').injective
(by rw [to_lin_to_matrix, to_lin_mul hb hb' hc', to_lin_to_matrix, hb'.to_lin_to_matrix, comp_id])
end mul_linear_map_to_matrix
end is_basis_to_matrix
open_locale matrix
section det
open linear_map matrix
variables {R : Type} [comm_ring R]
variables {M : Type*} [add_comm_group M] [module R M]
variables {M' : Type*} [add_comm_group M'] [module R M']
variables {ΞΉ : Type*} [decidable_eq ΞΉ] [fintype ΞΉ] {v : ΞΉ β M} {v' : ΞΉ β M'}
lemma linear_equiv.is_unit_det (f : M ββ[R] M') (hv : is_basis R v) (hv' : is_basis R v') :
is_unit (linear_map.to_matrix hv hv' f).det :=
begin
apply is_unit_det_of_left_inverse,
simpa using (linear_map.to_matrix_comp hv hv' hv f.symm f).symm
end
/-- Builds a linear equivalence from a linear map whose determinant in some bases is a unit. -/
def linear_equiv.of_is_unit_det {f : M ββ[R] M'} {hv : is_basis R v} {hv' : is_basis R v'}
(h : is_unit (linear_map.to_matrix hv hv' f).det) : M ββ[R] M' :=
{ to_fun := f,
map_add' := f.map_add,
map_smul' := f.map_smul,
inv_fun := to_lin hv' hv (to_matrix hv hv' f)β»ΒΉ,
left_inv := Ξ» x,
calc to_lin hv' hv (to_matrix hv hv' f)β»ΒΉ (f x)
= to_lin hv hv ((to_matrix hv hv' f)β»ΒΉ β¬ to_matrix hv hv' f) x :
by { rw [to_lin_mul hv hv' hv, to_lin_to_matrix, linear_map.comp_apply] }
... = x : by simp [h],
right_inv := Ξ» x,
calc f (to_lin hv' hv (to_matrix hv hv' f)β»ΒΉ x)
= to_lin hv' hv' (to_matrix hv hv' f β¬ (to_matrix hv hv' f)β»ΒΉ) x :
by { rw [to_lin_mul hv' hv hv', linear_map.comp_apply, to_lin_to_matrix hv hv'] }
... = x : by simp [h],
}
variables {e : ΞΉ β M} (he : is_basis R e)
/-- The determinant of a family of vectors with respect to some basis, as an alternating
multilinear map. -/
def is_basis.det : alternating_map R M R ΞΉ :=
{ to_fun := Ξ» v, det (he.to_matrix v),
map_add' := begin
intros v i x y,
simp only [he.to_matrix_update, linear_map.map_add],
apply det_update_column_add
end,
map_smul' := begin
intros u i c x,
simp only [he.to_matrix_update, algebra.id.smul_eq_mul, map_smul_of_tower],
apply det_update_column_smul
end,
map_eq_zero_of_eq' := begin
intros v i j h hij,
rw [βfunction.update_eq_self i v, h, βdet_transpose, he.to_matrix_update,
βupdate_row_transpose, βhe.to_matrix_transpose_apply],
apply det_zero_of_row_eq hij,
rw [update_row_ne hij.symm, update_row_self],
end }
lemma is_basis.det_apply (v : ΞΉ β M) : he.det v = det (he.to_matrix v) := rfl
lemma is_basis.det_self : he.det e = 1 :=
by simp [he.det_apply]
lemma is_basis.iff_det {v : ΞΉ β M} : is_basis R v β is_unit (he.det v) :=
begin
split,
{ intro hv,
suffices : is_unit (linear_map.to_matrix he he (linear_equiv_of_is_basis he hv $ equiv.refl ΞΉ)).det,
{ rw [is_basis.det_apply, is_basis.to_matrix_eq_to_matrix_constr],
exact this },
apply linear_equiv.is_unit_det },
{ intro h,
rw [is_basis.det_apply, is_basis.to_matrix_eq_to_matrix_constr] at h,
convert linear_equiv.is_basis he (linear_equiv.of_is_unit_det h),
ext i,
exact (constr_basis he).symm },
end
end det
section transpose
variables {K Vβ Vβ ΞΉβ ΞΉβ : Type*} [field K]
[add_comm_group Vβ] [vector_space K Vβ]
[add_comm_group Vβ] [vector_space K Vβ]
[fintype ΞΉβ] [fintype ΞΉβ] [decidable_eq ΞΉβ] [decidable_eq ΞΉβ]
{Bβ : ΞΉβ β Vβ} (hβ : is_basis K Bβ)
{Bβ : ΞΉβ β Vβ} (hβ : is_basis K Bβ)
@[simp] lemma linear_map.to_matrix_transpose (u : Vβ ββ[K] Vβ) :
linear_map.to_matrix hβ.dual_basis_is_basis hβ.dual_basis_is_basis (module.dual.transpose u) =
(linear_map.to_matrix hβ hβ u)α΅ :=
begin
ext i j,
simp only [linear_map.to_matrix_apply, module.dual.transpose_apply, hβ.dual_basis_equiv_fun,
hβ.dual_basis_apply, matrix.transpose_apply, linear_map.comp_apply]
end
lemma linear_map.to_matrix_symm_transpose (M : matrix ΞΉβ ΞΉβ K) :
(linear_map.to_matrix hβ.dual_basis_is_basis hβ.dual_basis_is_basis).symm Mα΅ =
module.dual.transpose (matrix.to_lin hβ hβ M) :=
begin
apply (linear_map.to_matrix hβ.dual_basis_is_basis hβ.dual_basis_is_basis).injective,
rw [linear_equiv.apply_symm_apply],
ext i j,
simp only [linear_map.to_matrix_apply, module.dual.transpose_apply, hβ.dual_basis_equiv_fun,
hβ.dual_basis_apply, matrix.transpose_apply, linear_map.comp_apply, if_true,
matrix.to_lin_apply, linear_equiv.map_smul, mul_boole, algebra.id.smul_eq_mul,
linear_equiv.map_sum, is_basis.equiv_fun_self, fintype.sum_apply, finset.sum_ite_eq',
finset.sum_ite_eq, is_basis.equiv_fun_symm_apply, pi.smul_apply, matrix.to_lin_apply,
matrix.mul_vec, matrix.dot_product, is_basis.equiv_fun_self, finset.mem_univ]
end
end transpose
namespace matrix
section trace
variables {m : Type*} [fintype m] (n : Type*) [fintype n]
variables (R : Type v) (M : Type w) [semiring R] [add_comm_monoid M] [semimodule R M]
/--
The diagonal of a square matrix.
-/
def diag : (matrix n n M) ββ[R] n β M :=
{ to_fun := Ξ» A i, A i i,
map_add' := by { intros, ext, refl, },
map_smul' := by { intros, ext, refl, } }
variables {n} {R} {M}
@[simp] lemma diag_apply (A : matrix n n M) (i : n) : diag n R M A i = A i i := rfl
@[simp] lemma diag_one [decidable_eq n] :
diag n R R 1 = Ξ» i, 1 := by { dunfold diag, ext, simp [one_apply_eq] }
@[simp] lemma diag_transpose (A : matrix n n M) : diag n R M Aα΅ = diag n R M A := rfl
variables (n) (R) (M)
/--
The trace of a square matrix.
-/
def trace : (matrix n n M) ββ[R] M :=
{ to_fun := Ξ» A, β i, diag n R M A i,
map_add' := by { intros, apply finset.sum_add_distrib, },
map_smul' := by { intros, simp [finset.smul_sum], } }
variables {n} {R} {M}
@[simp] lemma trace_diag (A : matrix n n M) : trace n R M A = β i, diag n R M A i := rfl
@[simp] lemma trace_one [decidable_eq n] :
trace n R R 1 = fintype.card n :=
have h : trace n R R 1 = β i, diag n R R 1 i := rfl,
by simp_rw [h, diag_one, finset.sum_const, nsmul_one]; refl
@[simp] lemma trace_transpose (A : matrix n n M) : trace n R M Aα΅ = trace n R M A := rfl
@[simp] lemma trace_transpose_mul (A : matrix m n R) (B : matrix n m R) :
trace n R R (Aα΅ β¬ Bα΅) = trace m R R (A β¬ B) := finset.sum_comm
lemma trace_mul_comm {S : Type v} [comm_ring S] (A : matrix m n S) (B : matrix n m S) :
trace n S S (B β¬ A) = trace m S S (A β¬ B) :=
by rw [βtrace_transpose, βtrace_transpose_mul, transpose_mul]
end trace
section ring
variables {n : Type*} [fintype n] [decidable_eq n] {R : Type v} [comm_ring R]
open linear_map matrix
lemma proj_diagonal (i : n) (w : n β R) :
(proj i).comp (to_lin' (diagonal w)) = (w i) β’ proj i :=
by ext j; simp [mul_vec_diagonal]
lemma diagonal_comp_std_basis (w : n β R) (i : n) :
(diagonal w).to_lin'.comp (std_basis R (Ξ»_:n, R) i) = (w i) β’ std_basis R (Ξ»_:n, R) i :=
begin
ext j,
simp_rw [linear_map.comp_apply, to_lin'_apply, mul_vec_diagonal, linear_map.smul_apply,
pi.smul_apply, algebra.id.smul_eq_mul],
by_cases i = j,
{ subst h },
{ rw [std_basis_ne R (Ξ»_:n, R) _ _ (ne.symm h), _root_.mul_zero, _root_.mul_zero] }
end
lemma diagonal_to_lin' (w : n β R) :
(diagonal w).to_lin' = linear_map.pi (Ξ»i, w i β’ linear_map.proj i) :=
by ext v j; simp [mul_vec_diagonal]
/-- An invertible matrix yields a linear equivalence from the free module to itself. -/
def to_linear_equiv (P : matrix n n R) (h : is_unit P) : (n β R) ββ[R] (n β R) :=
have h' : is_unit P.det := P.is_unit_iff_is_unit_det.mp h,
{ inv_fun := Pβ»ΒΉ.to_lin',
left_inv := Ξ» v,
show (Pβ»ΒΉ.to_lin'.comp P.to_lin') v = v,
by rw [β matrix.to_lin'_mul, P.nonsing_inv_mul h', matrix.to_lin'_one, linear_map.id_apply],
right_inv := Ξ» v,
show (P.to_lin'.comp Pβ»ΒΉ.to_lin') v = v,
by rw [β matrix.to_lin'_mul, P.mul_nonsing_inv h', matrix.to_lin'_one, linear_map.id_apply],
..P.to_lin' }
@[simp] lemma to_linear_equiv_apply (P : matrix n n R) (h : is_unit P) :
(β(P.to_linear_equiv h) : module.End R (n β R)) = P.to_lin' := rfl
@[simp] lemma to_linear_equiv_symm_apply (P : matrix n n R) (h : is_unit P) :
(β(P.to_linear_equiv h).symm : module.End R (n β R)) = Pβ»ΒΉ.to_lin' := rfl
end ring
section vector_space
variables {m n : Type*} [fintype m] [fintype n]
variables {K : Type u} [field K] -- maybe try to relax the universe constraint
open linear_map matrix
lemma rank_vec_mul_vec {m n : Type u} [fintype m] [fintype n] [decidable_eq n]
(w : m β K) (v : n β K) :
rank (vec_mul_vec w v).to_lin' β€ 1 :=
begin
rw [vec_mul_vec_eq, to_lin'_mul],
refine le_trans (rank_comp_le1 _ _) _,
refine le_trans (rank_le_domain _) _,
rw [dim_fun', β cardinal.lift_eq_nat_iff.mpr (cardinal.fintype_card unit), cardinal.mk_unit],
exact le_of_eq (cardinal.lift_one)
end
lemma ker_diagonal_to_lin' [decidable_eq m] (w : m β K) :
ker (diagonal w).to_lin' = (β¨iβ{i | w i = 0 }, range (std_basis K (Ξ»i, K) i)) :=
begin
rw [β comap_bot, β infi_ker_proj],
simp only [comap_infi, (ker_comp _ _).symm, proj_diagonal, ker_smul'],
have : univ β {i : m | w i = 0} βͺ {i : m | w i = 0}αΆ, { rw set.union_compl_self },
exact (supr_range_std_basis_eq_infi_ker_proj K (Ξ»i:m, K)
disjoint_compl_right this (finite.of_fintype _)).symm
end
lemma range_diagonal [decidable_eq m] (w : m β K) :
(diagonal w).to_lin'.range = (β¨ i β {i | w i β 0}, (std_basis K (Ξ»i, K) i).range) :=
begin
dsimp only [mem_set_of_eq],
rw [β map_top, β supr_range_std_basis, map_supr],
congr, funext i,
rw [β linear_map.range_comp, diagonal_comp_std_basis, β range_smul']
end
lemma rank_diagonal [decidable_eq m] [decidable_eq K] (w : m β K) :
rank (diagonal w).to_lin' = fintype.card { i // w i β 0 } :=
begin
have hu : univ β {i : m | w i = 0}αΆ βͺ {i : m | w i = 0}, { rw set.compl_union_self },
have hd : disjoint {i : m | w i β 0} {i : m | w i = 0} := disjoint_compl_left,
have hβ := supr_range_std_basis_eq_infi_ker_proj K (Ξ»i:m, K) hd hu (finite.of_fintype _),
have hβ := @infi_ker_proj_equiv K _ _ (Ξ»i:m, K) _ _ _ _ (by simp; apply_instance) hd hu,
rw [rank, range_diagonal, hβ, β@dim_fun' K],
apply linear_equiv.dim_eq,
apply hβ,
end
end vector_space
section finite_dimensional
variables {m n : Type*} [fintype m] [fintype n]
variables {R : Type v} [field R]
instance : finite_dimensional R (matrix m n R) :=
linear_equiv.finite_dimensional (linear_equiv.uncurry R m n).symm
/--
The dimension of the space of finite dimensional matrices
is the product of the number of rows and columns.
-/
@[simp] lemma findim_matrix :
finite_dimensional.findim R (matrix m n R) = fintype.card m * fintype.card n :=
by rw [@linear_equiv.findim_eq R (matrix m n R) _ _ _ _ _ _ (linear_equiv.uncurry R m n),
finite_dimensional.findim_fintype_fun_eq_card, fintype.card_prod]
end finite_dimensional
section reindexing
variables {l m n : Type*} [fintype l] [fintype m] [fintype n]
variables {l' m' n' : Type*} [fintype l'] [fintype m'] [fintype n']
variables {R : Type v}
/-- The natural map that reindexes a matrix's rows and columns with equivalent types is an
equivalence. -/
def reindex (eβ : m β m') (eβ : n β n') : matrix m n R β matrix m' n' R :=
{ to_fun := Ξ» M i j, M (eβ.symm i) (eβ.symm j),
inv_fun := Ξ» M i j, M (eβ i) (eβ j),
left_inv := Ξ» M, by simp,
right_inv := Ξ» M, by simp, }
@[simp] lemma reindex_apply (eβ : m β m') (eβ : n β n') (M : matrix m n R) :
reindex eβ eβ M = Ξ» i j, M (eβ.symm i) (eβ.symm j) :=
rfl
@[simp] lemma reindex_symm_apply (eβ : m β m') (eβ : n β n') (M : matrix m' n' R) :
(reindex eβ eβ).symm M = Ξ» i j, M (eβ i) (eβ j) :=
rfl
/-- The natural map that reindexes a matrix's rows and columns with equivalent types is a linear
equivalence. -/
def reindex_linear_equiv [semiring R] (eβ : m β m') (eβ : n β n') :
matrix m n R ββ[R] matrix m' n' R :=
{ map_add' := Ξ» M N, rfl,
map_smul' := Ξ» M N, rfl,
..(reindex eβ eβ)}
@[simp] lemma reindex_linear_equiv_apply [semiring R]
(eβ : m β m') (eβ : n β n') (M : matrix m n R) :
reindex_linear_equiv eβ eβ M = Ξ» i j, M (eβ.symm i) (eβ.symm j) :=
rfl
@[simp] lemma reindex_linear_equiv_symm_apply [semiring R]
(eβ : m β m') (eβ : n β n') (M : matrix m' n' R) :
(reindex_linear_equiv eβ eβ).symm M = Ξ» i j, M (eβ i) (eβ j) :=
rfl
lemma reindex_mul [semiring R]
(eβ : m β m') (eβ : n β n') (eβ : l β l') (M : matrix m n R) (N : matrix n l R) :
(reindex_linear_equiv eβ eβ M) β¬ (reindex_linear_equiv eβ eβ N) = reindex_linear_equiv eβ eβ (M β¬ N) :=
begin
ext i j,
dsimp only [matrix.mul, matrix.dot_product],
rw [βfinset.univ_map_equiv_to_embedding eβ, finset.sum_map finset.univ eβ.to_embedding],
simp,
end
/-- For square matrices, the natural map that reindexes a matrix's rows and columns with equivalent
types is an equivalence of algebras. -/
def reindex_alg_equiv [comm_semiring R] [decidable_eq m] [decidable_eq n]
(e : m β n) : matrix m m R ββ[R] matrix n n R :=
{ map_mul' := Ξ» M N, by simp only [reindex_mul, linear_equiv.to_fun_apply, mul_eq_mul],
commutes' := Ξ» r, by { ext, simp [algebra_map, algebra.to_ring_hom], by_cases h : i = j; simp [h], },
..(reindex_linear_equiv e e) }
@[simp] lemma reindex_alg_equiv_apply [comm_semiring R] [decidable_eq m] [decidable_eq n]
(e : m β n) (M : matrix m m R) :
reindex_alg_equiv e M = Ξ» i j, M (e.symm i) (e.symm j) :=
rfl
@[simp] lemma reindex_alg_equiv_symm_apply [comm_semiring R] [decidable_eq m] [decidable_eq n]
(e : m β n) (M : matrix n n R) :
(reindex_alg_equiv e).symm M = Ξ» i j, M (e i) (e j) :=
rfl
lemma reindex_transpose (eβ : m β m') (eβ : n β n') (M : matrix m n R) :
(reindex eβ eβ M)α΅ = (reindex eβ eβ Mα΅) :=
rfl
/-- `simp` version of `det_reindex_self`
`det_reindex_self` is not a good simp lemma because `reindex_apply` fires before.
So we have this lemma to continue from there. -/
@[simp]
lemma det_reindex_self' [decidable_eq m] [decidable_eq n] [comm_ring R]
(e : m β n) (A : matrix m m R) :
det (Ξ» i j, A (e.symm i) (e.symm j)) = det A :=
begin
unfold det,
apply finset.sum_bij' (Ξ» Ο _, equiv.perm_congr e.symm Ο) _ _ (Ξ» Ο _, equiv.perm_congr e Ο),
{ intros Ο _, ext, simp only [equiv.symm_symm, equiv.perm_congr_apply, equiv.apply_symm_apply] },
{ intros Ο _, ext, simp only [equiv.symm_symm, equiv.perm_congr_apply, equiv.symm_apply_apply] },
{ intros Ο _, apply finset.mem_univ },
{ intros Ο _, apply finset.mem_univ },
intros Ο _,
simp_rw [equiv.perm_congr_apply, equiv.symm_symm],
congr,
{ convert (equiv.perm.sign_perm_congr e.symm Ο).symm },
apply finset.prod_bij' (Ξ» i _, e.symm i) _ _ (Ξ» i _, e i),
{ intros, simp_rw equiv.apply_symm_apply },
{ intros, simp_rw equiv.symm_apply_apply },
{ intros, apply finset.mem_univ },
{ intros, apply finset.mem_univ },
{ intros, simp_rw equiv.apply_symm_apply },
end
/-- Reindexing both indices along the same equivalence preserves the determinant.
For the `simp` version of this lemma, see `det_reindex_self'`.
-/
lemma det_reindex_self [decidable_eq m] [decidable_eq n] [comm_ring R]
(e : m β n) (A : matrix m m R) :
det (reindex e e A) = det A :=
det_reindex_self' e A
/-- Reindexing both indices along the same equivalence preserves the determinant.
For the `simp` version of this lemma, see `det_reindex_self'`.
-/
lemma det_reindex_linear_equiv_self [decidable_eq m] [decidable_eq n] [comm_ring R]
(e : m β n) (A : matrix m m R) :
det (reindex_linear_equiv e e A) = det A :=
det_reindex_self' e A
/-- Reindexing both indices along the same equivalence preserves the determinant.
For the `simp` version of this lemma, see `det_reindex_self'`.
-/
lemma det_reindex_alg_equiv [decidable_eq m] [decidable_eq n] [comm_ring R]
(e : m β n) (A : matrix m m R) :
det (reindex_alg_equiv e A) = det A :=
det_reindex_self' e A
end reindexing
end matrix
namespace linear_map
open_locale matrix
/-- The trace of an endomorphism given a basis. -/
def trace_aux (R : Type u) [comm_ring R] {M : Type v} [add_comm_group M] [module R M]
{ΞΉ : Type w} [decidable_eq ΞΉ] [fintype ΞΉ] {b : ΞΉ β M} (hb : is_basis R b) :
(M ββ[R] M) ββ[R] R :=
(matrix.trace ΞΉ R R).comp $ linear_map.to_matrix hb hb
@[simp] lemma trace_aux_def (R : Type u) [comm_ring R] {M : Type v} [add_comm_group M] [module R M]
{ΞΉ : Type w} [decidable_eq ΞΉ] [fintype ΞΉ] {b : ΞΉ β M} (hb : is_basis R b) (f : M ββ[R] M) :
trace_aux R hb f = matrix.trace ΞΉ R R (linear_map.to_matrix hb hb f) :=
rfl
theorem trace_aux_eq' (R : Type u) [comm_ring R] {M : Type v} [add_comm_group M] [module R M]
{ΞΉ : Type w} [decidable_eq ΞΉ] [fintype ΞΉ] {b : ΞΉ β M} (hb : is_basis R b)
{ΞΊ : Type w} [decidable_eq ΞΊ] [fintype ΞΊ] {c : ΞΊ β M} (hc : is_basis R c) :
trace_aux R hb = trace_aux R hc :=
linear_map.ext $ Ξ» f,
calc matrix.trace ΞΉ R R (linear_map.to_matrix hb hb f)
= matrix.trace ΞΉ R R (linear_map.to_matrix hb hb ((linear_map.id.comp f).comp linear_map.id)) :
by rw [linear_map.id_comp, linear_map.comp_id]
... = matrix.trace ΞΉ R R (linear_map.to_matrix hc hb linear_map.id β¬
linear_map.to_matrix hc hc f β¬
linear_map.to_matrix hb hc linear_map.id) :
by rw [linear_map.to_matrix_comp _ hc, linear_map.to_matrix_comp _ hc]
... = matrix.trace ΞΊ R R (linear_map.to_matrix hc hc f β¬
linear_map.to_matrix hb hc linear_map.id β¬
linear_map.to_matrix hc hb linear_map.id) :
by rw [matrix.mul_assoc, matrix.trace_mul_comm]
... = matrix.trace ΞΊ R R (linear_map.to_matrix hc hc ((f.comp linear_map.id).comp linear_map.id)) :
by rw [linear_map.to_matrix_comp _ hb, linear_map.to_matrix_comp _ hc]
... = matrix.trace ΞΊ R R (linear_map.to_matrix hc hc f) :
by rw [linear_map.comp_id, linear_map.comp_id]
open_locale classical
theorem trace_aux_range (R : Type u) [comm_ring R] {M : Type v} [add_comm_group M] [module R M]
{ΞΉ : Type w} [decidable_eq ΞΉ] [fintype ΞΉ] {b : ΞΉ β M} (hb : is_basis R b) :
trace_aux R hb.range = trace_aux R hb :=
linear_map.ext $ Ξ» f, if H : 0 = 1 then eq_of_zero_eq_one H _ _ else
begin
haveI : nontrivial R := β¨β¨0, 1, Hβ©β©,
change β i : set.range b, _ = β i : ΞΉ, _, simp_rw [matrix.diag_apply], symmetry,
convert (equiv.of_injective _ hb.injective).sum_comp _, ext i,
exact (linear_map.to_matrix_range hb hb f i i).symm
end
/-- where `ΞΉ` and `ΞΊ` can reside in different universes -/
theorem trace_aux_eq (R : Type u) [comm_ring R] {M : Type v} [add_comm_group M] [module R M]
{ΞΉ : Type*} [decidable_eq ΞΉ] [fintype ΞΉ] {b : ΞΉ β M} (hb : is_basis R b)
{ΞΊ : Type*} [decidable_eq ΞΊ] [fintype ΞΊ] {c : ΞΊ β M} (hc : is_basis R c) :
trace_aux R hb = trace_aux R hc :=
calc trace_aux R hb
= trace_aux R hb.range : by rw trace_aux_range R hb
... = trace_aux R hc.range : trace_aux_eq' _ _ _
... = trace_aux R hc : by rw trace_aux_range R hc
/-- Trace of an endomorphism independent of basis. -/
def trace (R : Type u) [comm_ring R] (M : Type v) [add_comm_group M] [module R M] :
(M ββ[R] M) ββ[R] R :=
if H : β s : finset M, is_basis R (Ξ» x, x : (βs : set M) β M)
then trace_aux R (classical.some_spec H)
else 0
theorem trace_eq_matrix_trace (R : Type u) [comm_ring R] {M : Type v} [add_comm_group M] [module R M]
{ΞΉ : Type w} [fintype ΞΉ] [decidable_eq ΞΉ] {b : ΞΉ β M} (hb : is_basis R b) (f : M ββ[R] M) :
trace R M f = matrix.trace ΞΉ R R (linear_map.to_matrix hb hb f) :=
have β s : finset M, is_basis R (Ξ» x, x : (βs : set M) β M),
from β¨finset.univ.image b,
by { rw [finset.coe_image, finset.coe_univ, set.image_univ], exact hb.range }β©,
by { rw [trace, dif_pos this, β trace_aux_def], congr' 1, apply trace_aux_eq }
theorem trace_mul_comm (R : Type u) [comm_ring R] {M : Type v} [add_comm_group M] [module R M]
(f g : M ββ[R] M) : trace R M (f * g) = trace R M (g * f) :=
if H : β s : finset M, is_basis R (Ξ» x, x : (βs : set M) β M) then let β¨s, hbβ© := H in
by { simp_rw [trace_eq_matrix_trace R hb, linear_map.to_matrix_mul], apply matrix.trace_mul_comm }
else by rw [trace, dif_neg H, linear_map.zero_apply, linear_map.zero_apply]
section finite_dimensional
variables {K : Type*} [field K]
variables {V : Type*} [add_comm_group V] [vector_space K V] [finite_dimensional K V]
variables {W : Type*} [add_comm_group W] [vector_space K W] [finite_dimensional K W]
instance : finite_dimensional K (V ββ[K] W) :=
begin
classical,
cases finite_dimensional.exists_is_basis_finset K V with bV hbV,
cases finite_dimensional.exists_is_basis_finset K W with bW hbW,
apply linear_equiv.finite_dimensional (linear_map.to_matrix hbV hbW).symm,
end
/--
The dimension of the space of linear transformations is the product of the dimensions of the
domain and codomain.
-/
@[simp] lemma findim_linear_map :
finite_dimensional.findim K (V ββ[K] W) =
(finite_dimensional.findim K V) * (finite_dimensional.findim K W) :=
begin
classical,
cases finite_dimensional.exists_is_basis_finset K V with bV hbV,
cases finite_dimensional.exists_is_basis_finset K W with bW hbW,
rw [linear_equiv.findim_eq (linear_map.to_matrix hbV hbW), matrix.findim_matrix,
finite_dimensional.findim_eq_card_basis hbV, finite_dimensional.findim_eq_card_basis hbW,
mul_comm],
end
end finite_dimensional
end linear_map
/-- The natural equivalence between linear endomorphisms of finite free modules and square matrices
is compatible with the algebra structures. -/
def alg_equiv_matrix' {R : Type v} [comm_ring R] {n : Type*} [fintype n] [decidable_eq n] :
module.End R (n β R) ββ[R] matrix n n R :=
{ map_mul' := linear_map.to_matrix'_comp,
map_add' := linear_map.to_matrix'.map_add,
commutes' := Ξ» r, by { change (r β’ (linear_map.id : module.End R _)).to_matrix' = r β’ 1,
rw βlinear_map.to_matrix'_id, refl, },
..linear_map.to_matrix' }
/-- A linear equivalence of two modules induces an equivalence of algebras of their
endomorphisms. -/
def linear_equiv.alg_conj {R : Type v} [comm_ring R] {Mβ Mβ : Type*}
[add_comm_group Mβ] [module R Mβ] [add_comm_group Mβ] [module R Mβ] (e : Mβ ββ[R] Mβ) :
module.End R Mβ ββ[R] module.End R Mβ :=
{ map_mul' := Ξ» f g, by apply e.arrow_congr_comp,
map_add' := e.conj.map_add,
commutes' := Ξ» r, by { change e.conj (r β’ linear_map.id) = r β’ linear_map.id,
rw [linear_equiv.map_smul, linear_equiv.conj_id], },
..e.conj }
/-- A basis of a module induces an equivalence of algebras from the endomorphisms of the module to
square matrices. -/
def alg_equiv_matrix {R : Type v} {M : Type w} {n : Type*} [fintype n]
[comm_ring R] [add_comm_group M] [module R M] [decidable_eq n] {b : n β M} (h : is_basis R b) :
module.End R M ββ[R] matrix n n R :=
h.equiv_fun.alg_conj.trans alg_equiv_matrix'
|
3b7adf3b0ce13f18f8acda910edbdabcc2191daf
|
947b78d97130d56365ae2ec264df196ce769371a
|
/tests/lean/run/intromacro.lean
|
d62157ee14f96a37997073e7718da9efbae055c4
|
[
"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
| 571
|
lean
|
new_frontend
structure S :=
(x y z : Nat := 0)
def f1 : Nat Γ Nat β S β Nat :=
by {
intro (x, y);
intro β¨a, b, cβ©;
exact x+y+a
}
theorem ex1 : f1 (10, 20) { x := 10 } = 40 :=
rfl
def f2 : Nat Γ Nat β S β Nat :=
by {
intro (a, b) { y := y, .. };
exact a+b+y
}
#eval f2 (10, 20) { y := 5 }
theorem ex2 : f2 (10, 20) { y := 5 } = 35 :=
rfl
def f3 : Nat Γ Nat β S β S β Nat :=
by {
intro (a, b) { y := y, .. } s;
exact a+b+y+s.x
}
#eval f3 (10, 20) { y := 5 } { x := 1 }
theorem ex3 : f3 (10, 20) { y := 5 } { x := 1 } = 36 :=
rfl
|
180e43aad29d13f2aa0240db03b827107b41e5fc
|
3dd1b66af77106badae6edb1c4dea91a146ead30
|
/tests/lean/run/let1.lean
|
38cb8b8dffdac511f76be480b728fb9cfc2e8be2
|
[
"Apache-2.0"
] |
permissive
|
silky/lean
|
79c20c15c93feef47bb659a2cc139b26f3614642
|
df8b88dca2f8da1a422cb618cd476ef5be730546
|
refs/heads/master
| 1,610,737,587,697
| 1,406,574,534,000
| 1,406,574,534,000
| 22,362,176
| 1
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 177
|
lean
|
import standard
check
let f x y := x β§ y,
g x := f x x,
a := g true
in Ξ» (x : a),
let h x y := f x (g y),
b := h
in b
|
398914ded65320cb82b95f1180093794af72d331
|
1fbca480c1574e809ae95a3eda58188ff42a5e41
|
/src/util/control/monad/state.lean
|
f0449e5f521f276ee3fb959ae08b2c70e8fc6f4a
|
[] |
no_license
|
unitb/lean-lib
|
560eea0acf02b1fd4bcaac9986d3d7f1a4290e7e
|
439b80e606b4ebe4909a08b1d77f4f5c0ee3dee9
|
refs/heads/master
| 1,610,706,025,400
| 1,570,144,245,000
| 1,570,144,245,000
| 99,579,229
| 5
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 374
|
lean
|
universes u v
namespace state_t
variables {Ο Ξ± : Type u}
variables {m : Type u β Type u}
variables [monad m]
variables [is_lawful_monad m]
open is_lawful_monad
lemma get_bind (s : Ο) (f : Ο β state_t Ο m Ξ±)
: (get >>= f).run s = (f s).run s :=
by { simp [bind,state_t.bind,get,state_t.get,monad_state.lift,pure_bind,has_pure.pure,bind._match_1] }
end state_t
|
c78b342881c086ca47568e2b13a66bd41ad8ca1b
|
f3a5af2927397cf346ec0e24312bfff077f00425
|
/src/game/world10/level4.lean
|
04e0c686e9a233e44bcb4047003ce5b6501860a6
|
[
"Apache-2.0"
] |
permissive
|
ImperialCollegeLondon/natural_number_game
|
05c39e1586408cfb563d1a12e1085a90726ab655
|
f29b6c2884299fc63fdfc81ae5d7daaa3219f9fd
|
refs/heads/master
| 1,688,570,964,990
| 1,636,908,242,000
| 1,636,908,242,000
| 195,403,790
| 277
| 84
|
Apache-2.0
| 1,694,547,955,000
| 1,562,328,792,000
|
Lean
|
UTF-8
|
Lean
| false
| false
| 294
|
lean
|
import game.world10.level3 -- hide
namespace mynat -- hide
/-
# Inequality world.
## Level 4: `zero_le`
Another easy one.
-/
/- Lemma
For all naturals $a$, $0\leq a$.
-/
lemma zero_le (a : mynat) : 0 β€ a :=
begin [nat_num_game]
use a,
rw zero_add,
refl,
end
end mynat -- hide
|
a925e70d835005673fd7332333ef42b7ff5c3ab4
|
da3a76c514d38801bae19e8a9e496dc31f8e5866
|
/library/init/meta/vm.lean
|
e752435a83738fcc6e8b4f99ee63f686adb987cb
|
[
"Apache-2.0"
] |
permissive
|
cipher1024/lean
|
270c1ac5781e6aee12f5c8d720d267563a164beb
|
f5cbdff8932dd30c6dd8eec68f3059393b4f8b3a
|
refs/heads/master
| 1,611,223,459,029
| 1,487,566,573,000
| 1,487,566,573,000
| 83,356,543
| 0
| 0
| null | 1,488,229,336,000
| 1,488,229,336,000
| null |
UTF-8
|
Lean
| false
| false
| 6,394
|
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.meta.tactic init.data.option.basic
meta constant vm_obj : Type
inductive vm_obj_kind
| simple | constructor | closure | native_closure | mpz
| name | level | expr | declaration
| environment | tactic_state | format
| options | other
namespace vm_obj
meta constant kind : vm_obj β vm_obj_kind
/- For simple and constructor vm_obj's, it returns the constructor tag/index.
Return 0 otherwise. -/
meta constant cidx : vm_obj β nat
/- For closure vm_obj's, it returns the internal function index. -/
meta constant fn_idx : vm_obj β nat
/- For constructor vm_obj's, it returns the data stored in the object.
For closure vm_obj's, it returns the local arguments captured by the closure. -/
meta constant fields : vm_obj β list vm_obj
/- For simple and mpz vm_obj's -/
meta constant to_nat : vm_obj β nat
/- For name vm_obj's, it returns the name wrapped by the vm_obj. -/
meta constant to_name : vm_obj β name
/- For level vm_obj's, it returns the universe level wrapped by the vm_obj. -/
meta constant to_level : vm_obj β level
/- For expr vm_obj's, it returns the expression wrapped by the vm_obj. -/
meta constant to_expr : vm_obj β expr
/- For declaration vm_obj's, it returns the declaration wrapped by the vm_obj. -/
meta constant to_declaration : vm_obj β declaration
/- For environment vm_obj's, it returns the environment wrapped by the vm_obj. -/
meta constant to_environment : vm_obj β environment
/- For tactic_state vm_obj's, it returns the tactic_state object wrapped by the vm_obj. -/
meta constant to_tactic_state : vm_obj β tactic_state
/- For format vm_obj's, it returns the format object wrapped by the vm_obj. -/
meta constant to_format : vm_obj β format
end vm_obj
meta constant vm_decl : Type
inductive vm_decl_kind
| bytecode | builtin | cfun
/- Information for local variables and arguments on the VM stack.
Remark: type is only available if it is a closed term at compilation time. -/
meta structure vm_local_info :=
(id : name) (type : option expr)
namespace vm_decl
meta constant kind : vm_decl β vm_decl_kind
meta constant to_name : vm_decl β name
/- Internal function index associated with the given VM declaration. -/
meta constant idx : vm_decl β nat
/- Number of arguments needed to execute the given VM declaration. -/
meta constant arity : vm_decl β nat
/- Return (line, column) if available -/
meta constant pos : vm_decl β option (nat Γ nat)
/- Return .olean file where the given VM declaration was imported from. -/
meta constant olean : vm_decl β option string
/- Return names .olean file where the given VM declaration was imported from. -/
meta constant args_info : vm_decl β list vm_local_info
end vm_decl
meta constant vm_core : Type β Type
meta constant vm_core.map {Ξ± Ξ² : Type} : (Ξ± β Ξ²) β vm_core Ξ± β vm_core Ξ²
meta constant vm_core.ret {Ξ± : Type} : Ξ± β vm_core Ξ±
meta constant vm_core.bind {Ξ± Ξ² : Type} : vm_core Ξ± β (Ξ± β vm_core Ξ²) β vm_core Ξ²
meta instance : monad vm_core :=
{map := @vm_core.map, ret := @vm_core.ret, bind := @vm_core.bind}
@[reducible] meta def vm (Ξ± : Type) : Type := option_t vm_core Ξ±
namespace vm
meta constant get_env : vm environment
meta constant get_decl : name β vm vm_decl
meta constant get_options : vm options
meta constant stack_size : vm nat
/- Return the vm_obj stored at the given position on the execution stack.
It fails if position >= vm.stack_size -/
meta constant stack_obj : nat β vm vm_obj
/- Return (name, type) for the object at the given position on the execution stack.
It fails if position >= vm.stack_size.
The name is anonymous if vm_obj is a transient value created by the compiler.
Type information is only recorded if the type is a closed term at compilation time. -/
meta constant stack_obj_info : nat β vm (name Γ option expr)
/- Pretty print the vm_obj at the given position on the execution stack. -/
meta constant pp_stack_obj : nat β vm format
/- Pretty print the given expression. -/
meta constant pp_expr : expr β vm format
/- Number of frames on the call stack. -/
meta constant call_stack_size : vm nat
/- Return the function name at the given stack frame.
Action fails if position >= vm.call_stack_size. -/
meta constant call_stack_fn : nat β vm name
/- Return the range [start, end) for the given stack frame.
Action fails if position >= vm.call_stack_size.
The values start and end correspond to positions at the execution stack.
We have that 0 <= start < end <= vm.stack_size -/
meta constant call_stack_var_range : nat β vm (nat Γ nat)
/- Return the name of the function on top of the call stack. -/
meta constant curr_fn : vm name
/- Return the base stack pointer for the frame on top of the call stack. -/
meta constant bp : vm nat
/- Return the program counter. -/
meta constant pc : vm nat
/- Convert the given vm_obj into a string -/
meta constant obj_to_string : vm_obj β vm string
meta constant put_str : string β vm unit
meta constant get_line : vm string
/- Return tt if end of the input stream has been reached.
For example, this can happen if the user presses Ctrl-D -/
meta constant eof : vm bool
/- Return the list of declarations tagged with the given attribute. -/
meta constant get_attribute : name β vm (list name)
meta def trace {Ξ± : Type} [has_to_format Ξ±] (a : Ξ±) : vm unit :=
do fmt β return $ to_fmt a,
return $ _root_.trace_fmt fmt (Ξ» u, ())
end vm
meta structure vm_monitor (s : Type) :=
(init : s) (step : s β vm s)
/- Registers a new virtual machine monitor. The argument must be the name of a definition of type
`vm_monitor S`. The command will override the last monitor.
If option 'debugger' is true, then the VM will initialize the vm_monitor state using the
'init' field, and will invoke the function 'step' before each instruction is invoked. -/
meta constant vm_monitor.register : name β command
|
8f73b3abea4848b848f3ec659708ded51fd3ce6b
|
bb31430994044506fa42fd667e2d556327e18dfe
|
/src/topology/algebra/order/floor.lean
|
be5a80187cd7a3eecf444a3bc9c8939999596123
|
[
"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,543
|
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 algebra.order.floor
import topology.order.basic
/-!
# Topological facts about `int.floor`, `int.ceil` and `int.fract`
This file proves statements about limits and continuity of functions involving `floor`, `ceil` and
`fract`.
## Main declarations
* `tendsto_floor_at_top`, `tendsto_floor_at_bot`, `tendsto_ceil_at_top`, `tendsto_ceil_at_bot`:
`int.floor` and `int.ceil` tend to +-β in +-β.
* `continuous_on_floor`: `int.floor` is continuous on `Ico n (n + 1)`, because constant.
* `continuous_on_ceil`: `int.ceil` is continuous on `Ioc n (n + 1)`, because constant.
* `continuous_on_fract`: `int.fract` is continuous on `Ico n (n + 1)`.
* `continuous_on.comp_fract`: Precomposing a continuous function satisfying `f 0 = f 1` with
`int.fract` yields another continuous function.
-/
open filter function int set
open_locale topological_space
variables {Ξ± Ξ² Ξ³ : Type*} [linear_ordered_ring Ξ±] [floor_ring Ξ±]
lemma tendsto_floor_at_top : tendsto (floor : Ξ± β β€) at_top at_top :=
floor_mono.tendsto_at_top_at_top $ Ξ» b, β¨(b + 1 : β€),
by { rw floor_int_cast, exact (lt_add_one _).le }β©
lemma tendsto_floor_at_bot : tendsto (floor : Ξ± β β€) at_bot at_bot :=
floor_mono.tendsto_at_bot_at_bot $ Ξ» b, β¨b, (floor_int_cast _).leβ©
lemma tendsto_ceil_at_top : tendsto (ceil : Ξ± β β€) at_top at_top :=
ceil_mono.tendsto_at_top_at_top $ Ξ» b, β¨b, (ceil_int_cast _).geβ©
lemma tendsto_ceil_at_bot : tendsto (ceil : Ξ± β β€) at_bot at_bot :=
ceil_mono.tendsto_at_bot_at_bot $ Ξ» b, β¨(b - 1 : β€),
by { rw ceil_int_cast, exact (sub_one_lt _).le }β©
variables [topological_space Ξ±]
lemma continuous_on_floor (n : β€) : continuous_on (Ξ» x, floor x : Ξ± β Ξ±) (Ico n (n+1) : set Ξ±) :=
(continuous_on_congr $ floor_eq_on_Ico' n).mpr continuous_on_const
lemma continuous_on_ceil (n : β€) : continuous_on (Ξ» x, ceil x : Ξ± β Ξ±) (Ioc (n-1) n : set Ξ±) :=
(continuous_on_congr $ ceil_eq_on_Ioc' n).mpr continuous_on_const
lemma tendsto_floor_right' [order_closed_topology Ξ±] (n : β€) :
tendsto (Ξ» x, floor x : Ξ± β Ξ±) (π[β₯] n) (π n) :=
begin
rw β nhds_within_Ico_eq_nhds_within_Ici (lt_add_one (n : Ξ±)),
simpa only [floor_int_cast] using
(continuous_on_floor n _ (left_mem_Ico.mpr $ lt_add_one (_ : Ξ±))).tendsto
end
lemma tendsto_ceil_left' [order_closed_topology Ξ±] (n : β€) :
tendsto (Ξ» x, ceil x : Ξ± β Ξ±) (π[β€] n) (π n) :=
begin
rw β nhds_within_Ioc_eq_nhds_within_Iic (sub_one_lt (n : Ξ±)),
simpa only [ceil_int_cast] using
(continuous_on_ceil _ _ (right_mem_Ioc.mpr $ sub_one_lt (_ : Ξ±))).tendsto
end
lemma tendsto_floor_right [order_closed_topology Ξ±] (n : β€) :
tendsto (Ξ» x, floor x : Ξ± β Ξ±) (π[β₯] n) (π[β₯] n) :=
tendsto_nhds_within_of_tendsto_nhds_of_eventually_within _ (tendsto_floor_right' _)
begin
refine (eventually_nhds_within_of_forall $ Ξ» x (hx : (n : Ξ±) β€ x), _),
change _ β€ _,
norm_cast,
convert β floor_mono hx,
rw floor_eq_iff,
exact β¨le_rfl, lt_add_one _β©
end
lemma tendsto_ceil_left [order_closed_topology Ξ±] (n : β€) :
tendsto (Ξ» x, ceil x : Ξ± β Ξ±) (π[β€] n) (π[β€] n) :=
tendsto_nhds_within_of_tendsto_nhds_of_eventually_within _ (tendsto_ceil_left' _)
begin
refine (eventually_nhds_within_of_forall $ Ξ» x (hx : x β€ (n : Ξ±)), _),
change _ β€ _,
norm_cast,
convert β ceil_mono hx,
rw ceil_eq_iff,
exact β¨sub_one_lt _, le_rflβ©
end
lemma tendsto_floor_left [order_closed_topology Ξ±] (n : β€) :
tendsto (Ξ» x, floor x : Ξ± β Ξ±) (π[<] n) (π[β€] (n-1)) :=
begin
rw β nhds_within_Ico_eq_nhds_within_Iio (sub_one_lt (n : Ξ±)),
convert (tendsto_nhds_within_congr $ (Ξ» x hx, (floor_eq_on_Ico' (n-1) x hx).symm))
(tendsto_nhds_within_of_tendsto_nhds_of_eventually_within _ tendsto_const_nhds
(eventually_of_forall (Ξ» _, mem_Iic.mpr $ le_rfl)));
norm_cast <|> apply_instance,
ring
end
lemma tendsto_ceil_right [order_closed_topology Ξ±] (n : β€) :
tendsto (Ξ» x, ceil x : Ξ± β Ξ±) (π[>] n) (π[β₯] (n+1)) :=
begin
rw β nhds_within_Ioc_eq_nhds_within_Ioi (lt_add_one (n : Ξ±)),
convert (tendsto_nhds_within_congr $ (Ξ» x hx, (ceil_eq_on_Ioc' (n+1) x hx).symm))
(tendsto_nhds_within_of_tendsto_nhds_of_eventually_within _ tendsto_const_nhds
(eventually_of_forall (Ξ» _, mem_Ici.mpr $ le_rfl)));
norm_cast <|> apply_instance,
ring
end
lemma tendsto_floor_left' [order_closed_topology Ξ±] (n : β€) :
tendsto (Ξ» x, floor x : Ξ± β Ξ±) (π[<] n) (π (n-1)) :=
begin
rw β nhds_within_univ,
exact tendsto_nhds_within_mono_right (subset_univ _) (tendsto_floor_left n),
end
lemma tendsto_ceil_right' [order_closed_topology Ξ±] (n : β€) :
tendsto (Ξ» x, ceil x : Ξ± β Ξ±) (π[>] n) (π (n+1)) :=
begin
rw β nhds_within_univ,
exact tendsto_nhds_within_mono_right (subset_univ _) (tendsto_ceil_right n),
end
lemma continuous_on_fract [topological_add_group Ξ±] (n : β€) :
continuous_on (fract : Ξ± β Ξ±) (Ico n (n+1) : set Ξ±) :=
continuous_on_id.sub (continuous_on_floor n)
lemma tendsto_fract_left' [order_closed_topology Ξ±] [topological_add_group Ξ±]
(n : β€) : tendsto (fract : Ξ± β Ξ±) (π[<] n) (π 1) :=
begin
convert (tendsto_nhds_within_of_tendsto_nhds tendsto_id).sub (tendsto_floor_left' n);
[{norm_cast, ring}, apply_instance, apply_instance]
end
lemma tendsto_fract_left [order_closed_topology Ξ±] [topological_add_group Ξ±]
(n : β€) : tendsto (fract : Ξ± β Ξ±) (π[<] n) (π[<] 1) :=
tendsto_nhds_within_of_tendsto_nhds_of_eventually_within _
(tendsto_fract_left' _) (eventually_of_forall fract_lt_one)
lemma tendsto_fract_right' [order_closed_topology Ξ±] [topological_add_group Ξ±]
(n : β€) : tendsto (fract : Ξ± β Ξ±) (π[β₯] n) (π 0) :=
begin
convert (tendsto_nhds_within_of_tendsto_nhds tendsto_id).sub (tendsto_floor_right' n);
[exact (sub_self _).symm, apply_instance, apply_instance]
end
lemma tendsto_fract_right [order_closed_topology Ξ±] [topological_add_group Ξ±]
(n : β€) : tendsto (fract : Ξ± β Ξ±) (π[β₯] n) (π[β₯] 0) :=
tendsto_nhds_within_of_tendsto_nhds_of_eventually_within _
(tendsto_fract_right' _) (eventually_of_forall fract_nonneg)
local notation `I` := (Icc 0 1 : set Ξ±)
variables [order_topology Ξ±] [topological_add_group Ξ±] [topological_space Ξ²] [topological_space Ξ³]
/-- Do not use this, use `continuous_on.comp_fract` instead. -/
lemma continuous_on.comp_fract' {f : Ξ² β Ξ± β Ξ³}
(h : continuous_on (uncurry f) $ univ ΓΛ’ I) (hf : β s, f s 0 = f s 1) :
continuous (Ξ» st : Ξ² Γ Ξ±, f st.1 $ fract st.2) :=
begin
change continuous ((uncurry f) β (prod.map id (fract))),
rw continuous_iff_continuous_at,
rintro β¨s, tβ©,
by_cases ht : t = floor t,
{ rw ht,
rw β continuous_within_at_univ,
have : (univ : set (Ξ² Γ Ξ±)) β (univ ΓΛ’ Iio ββtβ) βͺ (univ ΓΛ’ Ici ββtβ),
{ rintros p -,
rw β prod_union,
exact β¨trivial, lt_or_le p.2 _β© },
refine continuous_within_at.mono _ this,
refine continuous_within_at.union _ _,
{ simp only [continuous_within_at, fract_int_cast, nhds_within_prod_eq,
nhds_within_univ, id.def, comp_app, prod.map_mk],
have : (uncurry f) (s, 0) = (uncurry f) (s, (1 : Ξ±)),
by simp [uncurry, hf],
rw this,
refine (h _ β¨β¨β©, by exact_mod_cast right_mem_Icc.2 (zero_le_one' Ξ±)β©).tendsto.comp _,
rw [nhds_within_prod_eq, nhds_within_univ],
rw nhds_within_Icc_eq_nhds_within_Iic (zero_lt_one' Ξ±),
exact tendsto_id.prod_map
(tendsto_nhds_within_mono_right Iio_subset_Iic_self $ tendsto_fract_left _) },
{ simp only [continuous_within_at, fract_int_cast, nhds_within_prod_eq,
nhds_within_univ, id.def, comp_app, prod.map_mk],
refine (h _ β¨β¨β©, by exact_mod_cast left_mem_Icc.2 (zero_le_one' Ξ±)β©).tendsto.comp _,
rw [nhds_within_prod_eq, nhds_within_univ,
nhds_within_Icc_eq_nhds_within_Ici (zero_lt_one' Ξ±)],
exact tendsto_id.prod_map (tendsto_fract_right _) } },
{ have : t β Ioo (floor t : Ξ±) ((floor t : Ξ±) + 1),
from β¨lt_of_le_of_ne (floor_le t) (ne.symm ht), lt_floor_add_one _β©,
apply (h ((prod.map _ fract) _) β¨trivial, β¨fract_nonneg _, (fract_lt_one _).leβ©β©).tendsto.comp,
simp only [nhds_prod_eq, nhds_within_prod_eq, nhds_within_univ, id.def, prod.map_mk],
exact continuous_at_id.tendsto.prod_map
(tendsto_nhds_within_of_tendsto_nhds_of_eventually_within _
(((continuous_on_fract _ _ (Ioo_subset_Ico_self this)).mono
Ioo_subset_Ico_self).continuous_at (Ioo_mem_nhds this.1 this.2))
(eventually_of_forall (Ξ» x, β¨fract_nonneg _, (fract_lt_one _).leβ©)) ) }
end
lemma continuous_on.comp_fract
{s : Ξ² β Ξ±}
{f : Ξ² β Ξ± β Ξ³}
(h : continuous_on (uncurry f) $ univ ΓΛ’ Icc 0 1)
(hs : continuous s)
(hf : β s, f s 0 = f s 1) :
continuous (Ξ» x : Ξ², f x $ int.fract (s x)) :=
(h.comp_fract' hf).comp (continuous_id.prod_mk hs)
/-- A special case of `continuous_on.comp_fract`. -/
lemma continuous_on.comp_fract'' {f : Ξ± β Ξ²} (h : continuous_on f I) (hf : f 0 = f 1) :
continuous (f β fract) :=
continuous_on.comp_fract (h.comp continuous_on_snd $ Ξ» x hx, (mem_prod.mp hx).2)
continuous_id (Ξ» _, hf)
|
218e771b921761af8438910de79e6b7657fb6eeb
|
63abd62053d479eae5abf4951554e1064a4c45b4
|
/src/ring_theory/valuation/basic.lean
|
6d4bc91c8e0d14cca52390033c2c73c44651be2d
|
[
"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
| 15,590
|
lean
|
/-
Copyright (c) 2020 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kevin Buzzard, Johan Commelin, Patrick Massot
-/
import algebra.linear_ordered_comm_group_with_zero
import algebra.group_power
import ring_theory.ideal.operations
import algebra.punit_instances
/-!
# The basics of valuation theory.
The basic theory of valuations (non-archimedean norms) on a commutative ring,
following T. Wedhorn's unpublished notes βAdic Spacesβ ([wedhorn_adic]).
The definition of a valuation we use here is Definition 1.22 of [wedhorn_adic].
A valuation on a ring `R` is a monoid homomorphism `v` to a linearly ordered
commutative group with zero, that in addition satisfies the following two axioms:
* `v 0 = 0`
* `β x y, v (x + y) β€ max (v x) (v y)`
`valuation R Ξβ`is the type of valuations `R β Ξβ`, with a coercion to the underlying
function. If `v` is a valuation from `R` to `Ξβ` then the induced group
homomorphism `units(R) β Ξβ` is called `unit_map v`.
The equivalence "relation" `is_equiv vβ vβ : Prop` defined in 1.27 of [wedhorn_adic] is not strictly
speaking a relation, because `vβ : valuation R Ξβ` and `vβ : valuation R Ξβ` might
not have the same type. This corresponds in ZFC to the set-theoretic difficulty
that the class of all valuations (as `Ξβ` varies) on a ring `R` is not a set.
The "relation" is however reflexive, symmetric and transitive in the obvious
sense. Note that we use 1.27(iii) of [wedhorn_adic] as the definition of equivalence.
The support of a valuation `v : valuation R Ξβ` is `supp v`. If `J` is an ideal of `R`
with `h : J β supp v` then the induced valuation
on R / J = `ideal.quotient J` is `on_quot v h`.
## Main definitions
* `valuation R Ξβ`, the type of valuations on `R` with values in `Ξβ`
* `valuation.is_equiv`, the heterogeneous equivalence relation on valuations
* `valuation.supp`, the support of a valuation
-/
open_locale classical big_operators
noncomputable theory
open function ideal
-- universes u uβ uβ uβ -- v is used for valuations
variables {R : Type*} -- This will be a ring, assumed commutative in some sections
variables {Ξβ : Type*} [linear_ordered_comm_group_with_zero Ξβ]
variables {Ξ'β : Type*} [linear_ordered_comm_group_with_zero Ξ'β]
variables {Ξ''β : Type*} [linear_ordered_comm_group_with_zero Ξ''β]
set_option old_structure_cmd true
section
variables (R) (Ξβ) [ring R]
/-- The type of Ξβ-valued valuations on R. -/
@[nolint has_inhabited_instance]
structure valuation extends R β* Ξβ :=
(map_zero' : to_fun 0 = 0)
(map_add' : β x y, to_fun (x + y) β€ max (to_fun x) (to_fun y))
run_cmd tactic.add_doc_string `valuation.to_monoid_hom "The `monoid_hom` underlying a valuation."
end
namespace valuation
section basic
variables (R) (Ξβ) [ring R]
/-- A valuation is coerced to the underlying function R β Ξβ. -/
instance : has_coe_to_fun (valuation R Ξβ) := { F := Ξ» _, R β Ξβ, coe := valuation.to_fun }
/-- A valuation is coerced to a monoid morphism R β Ξβ. -/
instance : has_coe (valuation R Ξβ) (R β* Ξβ) := β¨valuation.to_monoid_homβ©
variables {R} {Ξβ} (v : valuation R Ξβ) {x y z : R}
@[simp, norm_cast] lemma coe_coe : ((v : R β* Ξβ) : R β Ξβ) = v := rfl
@[simp] lemma map_zero : v 0 = 0 := v.map_zero'
@[simp] lemma map_one : v 1 = 1 := v.map_one'
@[simp] lemma map_mul : β x y, v (x * y) = v x * v y := v.map_mul'
@[simp] lemma map_add : β x y, v (x + y) β€ max (v x) (v y) := v.map_add'
lemma map_add_le {x y g} (hx : v x β€ g) (hy : v y β€ g) : v (x + y) β€ g :=
le_trans (v.map_add x y) $ max_le hx hy
lemma map_add_lt {x y g} (hx : v x < g) (hy : v y < g) : v (x + y) < g :=
lt_of_le_of_lt (v.map_add x y) $ max_lt hx hy
lemma map_sum_le {ΞΉ : Type*} {s : finset ΞΉ} {f : ΞΉ β R} {g : Ξβ} (hf : β i β s, v (f i) β€ g) :
v (β i in s, f i) β€ g :=
begin
refine finset.induction_on s
(Ξ» _, trans_rel_right (β€) v.map_zero zero_le') (Ξ» a s has ih hf, _) hf,
rw finset.forall_mem_insert at hf, rw finset.sum_insert has,
exact v.map_add_le hf.1 (ih hf.2)
end
lemma map_sum_lt {ΞΉ : Type*} {s : finset ΞΉ} {f : ΞΉ β R} {g : Ξβ} (hg : g β 0)
(hf : β i β s, v (f i) < g) : v (β i in s, f i) < g :=
begin
refine finset.induction_on s
(Ξ» _, trans_rel_right (<) v.map_zero (zero_lt_iff.2 hg)) (Ξ» a s has ih hf, _) hf,
rw finset.forall_mem_insert at hf, rw finset.sum_insert has,
exact v.map_add_lt hf.1 (ih hf.2)
end
lemma map_sum_lt' {ΞΉ : Type*} {s : finset ΞΉ} {f : ΞΉ β R} {g : Ξβ} (hg : 0 < g)
(hf : β i β s, v (f i) < g) : v (β i in s, f i) < g :=
v.map_sum_lt (ne_of_gt hg) hf
@[simp] lemma map_pow : β x (n:β), v (x^n) = (v x)^n :=
v.to_monoid_hom.map_pow
@[ext] lemma ext {vβ vβ : valuation R Ξβ} (h : β r, vβ r = vβ r) : vβ = vβ :=
by { cases vβ, cases vβ, congr, funext r, exact h r }
lemma ext_iff {vβ vβ : valuation R Ξβ} : vβ = vβ β β r, vβ r = vβ r :=
β¨Ξ» h r, congr_arg _ h, extβ©
-- The following definition is not an instance, because we have more than one `v` on a given `R`.
-- In addition, type class inference would not be able to infer `v`.
/-- A valuation gives a preorder on the underlying ring. -/
def to_preorder : preorder R := preorder.lift v
/-- If `v` is a valuation on a division ring then `v(x) = 0` iff `x = 0`. -/
@[simp] lemma zero_iff {K : Type*} [division_ring K]
(v : valuation K Ξβ) {x : K} : v x = 0 β x = 0 :=
begin
split ; intro h,
{ contrapose! h,
exact ((is_unit.mk0 _ h).map (v : K β* Ξβ)).ne_zero },
{ exact h.symm βΈ v.map_zero },
end
lemma ne_zero_iff {K : Type*} [division_ring K]
(v : valuation K Ξβ) {x : K} : v x β 0 β x β 0 :=
not_iff_not_of_iff v.zero_iff
@[simp] lemma map_inv {K : Type*} [division_ring K]
(v : valuation K Ξβ) {x : K} : v xβ»ΒΉ = (v x)β»ΒΉ :=
begin
by_cases h : x = 0,
{ subst h, rw [inv_zero, v.map_zero, inv_zero] },
{ apply eq_inv_of_mul_right_eq_one,
rw [β v.map_mul, mul_inv_cancel h, v.map_one] }
end
lemma map_units_inv (x : units R) : v (xβ»ΒΉ : units R) = (v x)β»ΒΉ :=
eq_inv_of_mul_right_eq_one $ by rw [β v.map_mul, units.mul_inv, v.map_one]
@[simp] theorem unit_map_eq (u : units R) :
(units.map (v : R β* Ξβ) u : Ξβ) = v u := rfl
theorem map_neg_one : v (-1) = 1 :=
begin
apply eq_one_of_pow_eq_one (nat.succ_ne_zero 1) (_ : _ ^ 2 = _),
rw [pow_two, β v.map_mul, neg_one_mul, neg_neg, v.map_one],
end
@[simp] lemma map_neg (x : R) : v (-x) = v x :=
calc v (-x) = v (-1 * x) : by rw [neg_one_mul]
... = v (-1) * v x : map_mul _ _ _
... = v x : by rw [v.map_neg_one, one_mul]
lemma map_sub_swap (x y : R) : v (x - y) = v (y - x) :=
calc v (x - y) = v (-(y - x)) : by rw show x - y = -(y-x), by abel
... = _ : map_neg _ _
lemma map_sub_le_max (x y : R) : v (x - y) β€ max (v x) (v y) :=
calc v (x - y) = v (x + -y) : by rw [sub_eq_add_neg]
... β€ max (v x) (v $ -y) : v.map_add _ _
... = max (v x) (v y) : by rw map_neg
lemma map_add_of_distinct_val (h : v x β v y) : v (x + y) = max (v x) (v y) :=
begin
suffices : Β¬v (x + y) < max (v x) (v y),
from or_iff_not_imp_right.1 (le_iff_eq_or_lt.1 (v.map_add x y)) this,
intro h',
wlog vyx : v y < v x using x y,
{ apply lt_or_gt_of_ne h.symm },
{ rw max_eq_left_of_lt vyx at h',
apply lt_irrefl (v x),
calc v x = v ((x+y) - y) : by simp
... β€ max (v $ x + y) (v y) : map_sub_le_max _ _ _
... < v x : max_lt h' vyx },
{ apply this h.symm,
rwa [add_comm, max_comm] at h' }
end
lemma map_eq_of_sub_lt (h : v (y - x) < v x) : v y = v x :=
begin
have := valuation.map_add_of_distinct_val v (ne_of_gt h).symm,
rw max_eq_right (le_of_lt h) at this,
simpa using this
end
/-- A ring homomorphism S β R induces a map valuation R Ξβ β valuation S Ξβ -/
def comap {S : Type*} [ring S] (f : S β+* R) (v : valuation R Ξβ) :
valuation S Ξβ :=
by refine_struct { to_fun := v β f, .. }; intros;
simp only [comp_app, map_one, map_mul, map_zero, map_add,
f.map_one, f.map_mul, f.map_zero, f.map_add]
@[simp] lemma comap_id : v.comap (ring_hom.id R) = v := ext $ Ξ» r, rfl
lemma comap_comp {Sβ : Type*} {Sβ : Type*} [ring Sβ] [ring Sβ] (f : Sβ β+* Sβ) (g : Sβ β+* R) :
v.comap (g.comp f) = (v.comap g).comap f :=
ext $ Ξ» r, rfl
/-- A β€-preserving group homomorphism Ξβ β Ξ'β induces a map valuation R Ξβ β valuation R Ξ'β. -/
def map (f : Ξβ β* Ξ'β) (hβ : f 0 = 0) (hf : monotone f) (v : valuation R Ξβ) : valuation R Ξ'β :=
{ to_fun := f β v,
map_zero' := show f (v 0) = 0, by rw [v.map_zero, hβ],
map_add' := Ξ» r s,
calc f (v (r + s)) β€ f (max (v r) (v s)) : hf (v.map_add r s)
... = max (f (v r)) (f (v s)) : hf.map_max,
.. monoid_hom.comp f (v : R β* Ξβ) }
/-- Two valuations on R are defined to be equivalent if they induce the same preorder on R. -/
def is_equiv (vβ : valuation R Ξβ) (vβ : valuation R Ξ'β) : Prop :=
β r s, vβ r β€ vβ s β vβ r β€ vβ s
end basic -- end of section
namespace is_equiv
variables [ring R]
variables {v : valuation R Ξβ}
variables {vβ : valuation R Ξβ} {vβ : valuation R Ξ'β} {vβ : valuation R Ξ''β}
@[refl] lemma refl : v.is_equiv v :=
Ξ» _ _, iff.refl _
@[symm] lemma symm (h : vβ.is_equiv vβ) : vβ.is_equiv vβ :=
Ξ» _ _, iff.symm (h _ _)
@[trans] lemma trans (hββ : vβ.is_equiv vβ) (hββ : vβ.is_equiv vβ) : vβ.is_equiv vβ :=
Ξ» _ _, iff.trans (hββ _ _) (hββ _ _)
lemma of_eq {v' : valuation R Ξβ} (h : v = v') : v.is_equiv v' :=
by { subst h }
lemma map {v' : valuation R Ξβ} (f : Ξβ β* Ξ'β) (hβ : f 0 = 0) (hf : monotone f) (inf : injective f)
(h : v.is_equiv v') :
(v.map f hβ hf).is_equiv (v'.map f hβ hf) :=
let H : strict_mono f := strict_mono_of_monotone_of_injective hf inf in
Ξ» r s,
calc f (v r) β€ f (v s) β v r β€ v s : by rw H.le_iff_le
... β v' r β€ v' s : h r s
... β f (v' r) β€ f (v' s) : by rw H.le_iff_le
/-- `comap` preserves equivalence. -/
lemma comap {S : Type*} [ring S] (f : S β+* R) (h : vβ.is_equiv vβ) :
(vβ.comap f).is_equiv (vβ.comap f) :=
Ξ» r s, h (f r) (f s)
lemma val_eq (h : vβ.is_equiv vβ) {r s : R} :
vβ r = vβ s β vβ r = vβ s :=
by simpa only [le_antisymm_iff] using and_congr (h r s) (h s r)
lemma ne_zero (h : vβ.is_equiv vβ) {r : R} :
vβ r β 0 β vβ r β 0 :=
begin
have : vβ r β vβ 0 β vβ r β vβ 0 := not_iff_not_of_iff h.val_eq,
rwa [vβ.map_zero, vβ.map_zero] at this,
end
end is_equiv -- end of namespace
lemma is_equiv_of_map_strict_mono [ring R] {v : valuation R Ξβ}
(f : Ξβ β* Ξ'β) (hβ : f 0 = 0) (H : strict_mono f) :
is_equiv (v.map f hβ (H.monotone)) v :=
Ξ» x y, β¨H.le_iff_le.mp, Ξ» h, H.monotone hβ©
lemma is_equiv_of_val_le_one {K : Type*} [division_ring K]
(v : valuation K Ξβ) (v' : valuation K Ξ'β) (h : β {x:K}, v x β€ 1 β v' x β€ 1) :
v.is_equiv v' :=
begin
intros x y,
by_cases hy : y = 0, { simp [hy, zero_iff], },
rw show y = 1 * y, by rw one_mul,
rw [β (inv_mul_cancel_right' hy x)],
iterate 2 {rw [v.map_mul _ y, v'.map_mul _ y]},
rw [v.map_one, v'.map_one],
split; intro H,
{ apply mul_le_mul_right',
replace hy := v.ne_zero_iff.mpr hy,
replace H := le_of_le_mul_right hy H,
rwa h at H, },
{ apply mul_le_mul_right',
replace hy := v'.ne_zero_iff.mpr hy,
replace H := le_of_le_mul_right hy H,
rwa h, },
end
section supp
variables [comm_ring R]
variables (v : valuation R Ξβ)
/-- The support of a valuation `v : R β Ξβ` is the ideal of `R` where `v` vanishes. -/
def supp : ideal R :=
{ carrier := {x | v x = 0},
zero_mem' := map_zero v,
add_mem' := Ξ» x y hx hy, le_zero_iff.mp $
calc v (x + y) β€ max (v x) (v y) : v.map_add x y
... β€ 0 : max_le (le_zero_iff.mpr hx) (le_zero_iff.mpr hy),
smul_mem' := Ξ» c x hx, calc v (c * x)
= v c * v x : map_mul v c x
... = v c * 0 : congr_arg _ hx
... = 0 : mul_zero _ }
@[simp] lemma mem_supp_iff (x : R) : x β supp v β v x = 0 := iff.rfl
-- @[simp] lemma mem_supp_iff' (x : R) : x β (supp v : set R) β v x = 0 := iff.rfl
/-- The support of a valuation is a prime ideal. -/
instance : ideal.is_prime (supp v) :=
β¨Ξ» (h : v.supp = β€), one_ne_zero $ show (1 : Ξβ) = 0,
from calc 1 = v 1 : v.map_one.symm
... = 0 : show (1:R) β supp v, by { rw h, trivial },
Ξ» x y hxy, begin
show v x = 0 β¨ v y = 0,
change v (x * y) = 0 at hxy,
rw [v.map_mul x y] at hxy,
exact eq_zero_or_eq_zero_of_mul_eq_zero hxy
endβ©
lemma map_add_supp (a : R) {s : R} (h : s β supp v) : v (a + s) = v a :=
begin
have aux : β a s, v s = 0 β v (a + s) β€ v a,
{ intros a' s' h', refine le_trans (v.map_add a' s') (max_le (le_refl _) _), simp [h'], },
apply le_antisymm (aux a s h),
calc v a = v (a + s + -s) : by simp
... β€ v (a + s) : aux (a + s) (-s) (by rwa βideal.neg_mem_iff at h)
end
/-- If `hJ : J β supp v` then `on_quot_val hJ` is the induced function on R/J as a function.
Note: it's just the function; the valuation is `on_quot hJ`. -/
def on_quot_val {J : ideal R} (hJ : J β€ supp v) :
J.quotient β Ξβ :=
Ξ» q, quotient.lift_on' q v $ Ξ» a b h,
calc v a = v (b + (a - b)) : by simp
... = v b : v.map_add_supp b (hJ h)
/-- The extension of valuation v on R to valuation on R/J if J β supp v -/
def on_quot {J : ideal R} (hJ : J β€ supp v) :
valuation J.quotient Ξβ :=
{ to_fun := v.on_quot_val hJ,
map_zero' := v.map_zero,
map_one' := v.map_one,
map_mul' := Ξ» xbar ybar, quotient.indβ' v.map_mul xbar ybar,
map_add' := Ξ» xbar ybar, quotient.indβ' v.map_add xbar ybar }
@[simp] lemma on_quot_comap_eq {J : ideal R} (hJ : J β€ supp v) :
(v.on_quot hJ).comap (ideal.quotient.mk J) = v :=
ext $ Ξ» r,
begin
refine @quotient.lift_on_beta _ _ (J.quotient_rel) v (Ξ» a b h, _) _,
calc v a = v (b + (a - b)) : by simp
... = v b : v.map_add_supp b (hJ h)
end
lemma comap_supp {S : Type*} [comm_ring S] (f : S β+* R) :
supp (v.comap f) = ideal.comap f v.supp :=
ideal.ext $ Ξ» x,
begin
rw [mem_supp_iff, ideal.mem_comap, mem_supp_iff],
refl,
end
lemma self_le_supp_comap (J : ideal R) (v : valuation (quotient J) Ξβ) :
J β€ (v.comap (ideal.quotient.mk J)).supp :=
by { rw [comap_supp, β ideal.map_le_iff_le_comap], simp }
@[simp] lemma comap_on_quot_eq (J : ideal R) (v : valuation J.quotient Ξβ) :
(v.comap (ideal.quotient.mk J)).on_quot (v.self_le_supp_comap J) = v :=
ext $ by { rintro β¨xβ©, refl }
/-- The quotient valuation on R/J has support supp(v)/J if J β supp v. -/
lemma supp_quot {J : ideal R} (hJ : J β€ supp v) :
supp (v.on_quot hJ) = (supp v).map (ideal.quotient.mk J) :=
begin
apply le_antisymm,
{ rintro β¨xβ© hx,
apply ideal.subset_span,
exact β¨x, hx, rflβ© },
{ rw ideal.map_le_iff_le_comap,
intros x hx, exact hx }
end
lemma supp_quot_supp : supp (v.on_quot (le_refl _)) = 0 :=
by { rw supp_quot, exact ideal.map_quotient_self _ }
end supp -- end of section
end valuation
|
a068e3c98a399bf631942423bc0ff220dfef520f
|
624f6f2ae8b3b1adc5f8f67a365c51d5126be45a
|
/stage0/src/Init/Lean/Elab/StrategyAttrs.lean
|
12709cf1d9f38069f5fbe0906bd03930033d4b35
|
[
"Apache-2.0"
] |
permissive
|
mhuisi/lean4
|
28d35a4febc2e251c7f05492e13f3b05d6f9b7af
|
dda44bc47f3e5d024508060dac2bcb59fd12e4c0
|
refs/heads/master
| 1,621,225,489,283
| 1,585,142,689,000
| 1,585,142,689,000
| 250,590,438
| 0
| 2
|
Apache-2.0
| 1,602,443,220,000
| 1,585,327,814,000
|
C
|
UTF-8
|
Lean
| false
| false
| 1,649
|
lean
|
/-
Copyright (c) 2019 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
prelude
import Init.Lean.Attributes
namespace Lean
/-
Elaborator strategies available in the Lean3 elaborator.
We want to support a more general approach, but we need to provide
the strategy selection attributes while we rely on the Lean3 elaborator.
-/
inductive ElaboratorStrategy
| simple | withExpectedType | asEliminator
instance ElaboratorStrategy.inhabited : Inhabited ElaboratorStrategy :=
β¨ElaboratorStrategy.withExpectedTypeβ©
def mkElaboratorStrategyAttrs : IO (EnumAttributes ElaboratorStrategy) :=
registerEnumAttributes `elaboratorStrategy
[(`elabWithExpectedType, "instructs elaborator that the arguments of the function application (f ...) should be elaborated using information about the expected type", ElaboratorStrategy.withExpectedType),
(`elabSimple, "instructs elaborator that the arguments of the function application (f ...) should be elaborated from left to right, and without propagating information from the expected type to its arguments", ElaboratorStrategy.simple),
(`elabAsEliminator, "instructs elaborator that the arguments of the function application (f ...) should be elaborated as f were an eliminator", ElaboratorStrategy.asEliminator)]
@[init mkElaboratorStrategyAttrs]
constant elaboratorStrategyAttrs : EnumAttributes ElaboratorStrategy := arbitrary _
@[export lean_get_elaborator_strategy]
def getElaboratorStrategy (env : Environment) (n : Name) : Option ElaboratorStrategy :=
elaboratorStrategyAttrs.getValue env n
end Lean
|
05c4786c150eae4a7e2ccae8f3ea89bb16422998
|
9dd3f3912f7321eb58ee9aa8f21778ad6221f87c
|
/tests/lean/run/e4.lean
|
bba6aba47bffe57f4a230012327da86484cdfd38
|
[
"Apache-2.0"
] |
permissive
|
bre7k30/lean
|
de893411bcfa7b3c5572e61b9e1c52951b310aa4
|
5a924699d076dab1bd5af23a8f910b433e598d7a
|
refs/heads/master
| 1,610,900,145,817
| 1,488,006,845,000
| 1,488,006,845,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 665
|
lean
|
prelude
definition Prop := Sort.{0}
definition false : Prop := βx : Prop, x
check false
theorem false.elim (C : Prop) (H : false) : C
:= H C
definition Eq {A : Type} (a b : A)
:= β P : A β Prop, P a β P b
check Eq
infix `=`:50 := Eq
theorem refl {A : Type} (a : A) : a = a
:= Ξ» P H, H
definition true : Prop
:= false = false
theorem trivial : true
:= refl false
attribute [elab_as_eliminator]
theorem subst {A : Type} {P : A -> Prop} {a b : A} (H1 : a = b) (H2 : P a) : P b
:= H1 _ H2
theorem symm {A : Type} {a b : A} (H : a = b) : b = a
:= subst H (refl a)
theorem trans {A : Type} {a b c : A} (H1 : a = b) (H2 : b = c) : a = c
:= subst H2 H1
|
a1b50cc5d09b66ab9bfcb2f2bad04b108c58e09b
|
c45b34bfd44d8607a2e8762c926e3cfaa7436201
|
/uexp/src/uexp/rules/pushJoinThroughUnionOnRight.lean
|
ef36d7190af50de50a93c1329022c00fcc4d4616
|
[
"BSD-2-Clause"
] |
permissive
|
Shamrock-Frost/Cosette
|
b477c442c07e45082348a145f19ebb35a7f29392
|
24cbc4adebf627f13f5eac878f04ffa20d1209af
|
refs/heads/master
| 1,619,721,304,969
| 1,526,082,841,000
| 1,526,082,841,000
| 121,695,605
| 1
| 0
| null | 1,518,737,210,000
| 1,518,737,210,000
| null |
UTF-8
|
Lean
| false
| false
| 1,804
|
lean
|
import ..sql
import ..tactics
import ..u_semiring
import ..extra_constants
import ..UDP
set_option profiler true
open Expr
open Proj
open Pred
open SQL
open tree
notation `int` := datatypes.int
definition rule:
forall ( Ξ scm_t scm_account scm_bonus scm_dept scm_emp: Schema) (rel_t: relation scm_t) (rel_account: relation scm_account) (rel_bonus: relation scm_bonus) (rel_dept: relation scm_dept) (rel_emp: relation scm_emp) (t_k0 : Column int scm_t) (t_c1 : Column int scm_t) (t_f1_a0 : Column int scm_t) (t_f2_a0 : Column int scm_t) (t_f0_c0 : Column int scm_t) (t_f1_c0 : Column int scm_t) (t_f0_c1 : Column int scm_t) (t_f1_c2 : Column int scm_t) (t_f2_c3 : Column int scm_t) (account_acctno : Column int scm_account) (account_type : Column int scm_account) (account_balance : Column int scm_account) (bonus_ename : Column int scm_bonus) (bonus_job : Column int scm_bonus) (bonus_sal : Column int scm_bonus) (bonus_comm : Column int scm_bonus) (dept_deptno : Column int scm_dept) (dept_name : Column int scm_dept) (emp_empno : Column int scm_emp) (emp_ename : Column int scm_emp) (emp_job : Column int scm_emp) (emp_mgr : Column int scm_emp) (emp_hiredate : Column int scm_emp) (emp_comm : Column int scm_emp) (emp_sal : Column int scm_emp) (emp_deptno : Column int scm_emp) (emp_slacker : Column int scm_emp),
denoteSQL
((SELECT1 (rightβ
leftβ
emp_sal) FROM1 (product (table rel_emp) (((SELECT * FROM1 (table rel_emp) )) UNION ALL ((SELECT * FROM1 (table rel_emp) )))) ) : SQL Ξ _) =
denoteSQL ((SELECT1 (rightβ
rightβ
emp_sal) FROM1 (((SELECT * FROM1 (product (table rel_emp) (table rel_emp)) )) UNION ALL ((SELECT * FROM1 (product (table rel_emp) (table rel_emp)) ))) ) : SQL Ξ _) :=
begin
intros,
unfold_all_denotations,
funext,
simp,
UDP,
end
|
aefd61c1cef32b14a165d4caa3886042c59e44af
|
3af272061d36e7f3f0521cceaa3a847ed4e03af9
|
/src/hecke_operator.lean
|
f983bcf9e89e0146d3e448db5516119a5e85612f
|
[] |
no_license
|
semorrison/kbb
|
fdab0929d21dca880d835081814225a95f946187
|
229bd06e840bc7a7438b8fee6802a4f8024419e3
|
refs/heads/master
| 1,585,351,834,355
| 1,539,848,241,000
| 1,539,848,241,000
| 147,323,315
| 2
| 1
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 3,071
|
lean
|
import .SL2Z_generators
import .modular_forms
local notation `β` := upper_half_space
local notation `Mat` := integral_matrices_with_determinant
lemma pos_det' {m : β€} (h : m > 0) {A : Mat m} : β(A.a) * β(A.d) - β(A.b) * β(A.c) > (0 : β) :=
begin
cases A with a b c d det,
rw βdet at h,
rw [βint.cast_mul, βint.cast_mul, βint.cast_sub],
suffices : (0 : β) < β(a * d - b * c), exact this,
rwa int.cast_pos
end
lemma aux_10 {m : β€} (h : m > 0) (A : Mat m) (z : β) : (β(A.c) * βz + β(A.d)) β (0 : β) :=
have H1 : (β(A.a) : β) * β(A.d) - β(A.b) * β(A.c) > 0,
by rw [β int.cast_mul, β int.cast_mul, β int.cast_sub];
from int.cast_pos.2 (trans_rel_left _ h A.det.symm),
have _ := preserve_β.aux H1 z.2,
by simpa only [complex.of_real_int_cast]
theorem M_trans_SL2Z_M {m : β€} {h : m > 0} {M : SL2Z} {A : Mat m} :
M_trans h (SL2Z_M m M A) = SL2Z_H M β (M_trans h A) :=
begin
funext z, apply subtype.eq,
change _/_=_/_,
have H3 := aux_10 h A z,
have H4 := aux_10 zero_lt_one M (M_trans h A z),
unfold M_trans Β«MΓΆbius_transformΒ» at H4 β’,
simp only [subtype.coe_mk, complex.of_real_int_cast] with SL2Z at H3 H4 β’,
rw β mul_div_mul_right _ H4 H3,
conv { to_rhs,
rw [add_mul, add_mul, mul_assoc, mul_assoc],
rw [div_mul_cancel _ H3] },
simp only [int.cast_add, int.cast_mul],
congr' 1; simp only [add_mul, mul_add, mul_assoc, add_left_comm, add_assoc]
end
set_option eqn_compiler.zeta true
noncomputable def Hecke_operator {k : β} (m : β€) (h : m > 0) (f : is_Petersson_weight_ k) :
is_Petersson_weight_ k :=
begin
let orbits := quotient (action_rel (SL2Z_M m)),
letI h_orbits : fintype orbits := SL2Z_M.finiteness m (ne_of_gt h),
refine β¨Ξ»z:β,
(m^k : β) * (finset.univ : finset orbits).sum (Ξ»o, quotient.lift_on' o _ _), _β©,
refine Ξ»A, 1 / (A.c * z + A.d)^k * f.1 (M_trans h A z),
{ rcases f with β¨f, weight_fβ©,
rintros A B β¨M, Hβ©,
change 1 / (β(A.c) * βz + β(A.d)) ^ k * f (M_trans h A z) = 1 / (β(B.c) * βz + β(B.d)) ^ k * f (M_trans h B z),
rw β H,
rw M_trans_SL2Z_M,
simp [-one_div_eq_inv],
rw (weight_f M _),
rw β mul_assoc,
congr' 1,
dsimp[M_trans, Β«MΓΆbius_transformΒ»],
ring,
rw pow_inv,
rw pow_inv,
rw β mul_pow,
congr' 1,
-- Patrick claims this goal is true -- and so does Johan
repeat {sorry} },
{ dsimp [is_Petersson_weight_],
intros M z,
conv { to_rhs, rw β mul_assoc, congr, rw mul_comm },
conv { to_rhs, rw mul_assoc, rw finset.mul_sum, },
congr' 1,
refine finset.sum_bij _ _ _ _ _,
-- Define the function given by right multiplication with M
-- The other goals should be straightforward
-- funext o,
-- rcases o with β¨Aβ©,
-- dsimp [quotient.lift_on',quotient.lift_on,quot.lift_on],
-- rcases f with β¨f, weight_fβ©,
-- dsimp [is_Petersson_weight_] at weight_f,
-- simp,
-- dsimp [SL2Z_H,M_trans,Β«MΓΆbius_transformΒ»],
-- simp,
sorry }
end
|
7792c70ac2e8129aca98a5c4336b63ea237a9348
|
cf39355caa609c0f33405126beee2739aa3cb77e
|
/tests/lean/run/match_pattern2.lean
|
f0e3c6cee3e74b751f3694683d6f1a7f593b67f4
|
[
"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
| 1,423
|
lean
|
open tactic list expr
private meta definition pattern_telescope : expr β list expr β tactic (list expr Γ expr Γ expr)
| e ps :=
if expr.is_pi e = tt then do
n β mk_fresh_name,
p β return $ local_const n (binding_name e) (binding_info e) (binding_domain e),
new_e β return $ instantiate_var (binding_body e) p,
pattern_telescope new_e (p :: ps)
else do
(lhs, rhs) β match_eq e,
return (reverse ps, lhs, rhs)
meta definition mk_pattern_for_constant : name β tactic pattern
| n :=
do env β get_env,
d : declaration β returnex $ environment.get env n,
ls : list level β return $ map level.param (declaration.univ_params d),
(some type) β return $ declaration.instantiate_type_univ_params d ls | failed,
(es, lhs, rhs) β pattern_telescope type [],
p : pattern β mk_pattern ls es lhs [] [rhs, app_of_list (expr.const n ls) es],
return p
open nat
constant add.comm (a b : nat) : a + b = b + a
example (a b : nat) (H : a + b + a + b = 0) : true :=
by do
a β get_local `a, b β get_local `b,
H β get_local `H >>= infer_type,
(lhs, rhs) β match_eq H,
p β mk_pattern_for_constant $ `add.comm,
(_, [rhs_inst, prf]) β match_pattern p lhs | failed,
trace "match rhs",
trace rhs_inst,
trace "proof lhs = rhs",
trace prf,
prf_type β infer_type prf,
trace "proof type:",
trace prf_type,
constructor
|
6b2983a4cc1e0e79660a4a9ba7136eaa43c18efc
|
a4673261e60b025e2c8c825dfa4ab9108246c32e
|
/stage0/src/Lean/Elab/Tactic/Match.lean
|
2d856a4b6e8350ec01dfb6d12d4e6ff3e7eb50b0
|
[
"Apache-2.0"
] |
permissive
|
jcommelin/lean4
|
c02dec0cc32c4bccab009285475f265f17d73228
|
2909313475588cc20ac0436e55548a4502050d0a
|
refs/heads/master
| 1,674,129,550,893
| 1,606,415,348,000
| 1,606,415,348,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 2,170
|
lean
|
/-
Copyright (c) 2020 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
import Lean.Elab.Match
import Lean.Elab.Tactic.Basic
import Lean.Elab.Tactic.Induction
namespace Lean.Elab.Tactic
structure AuxMatchTermState :=
(nextIdx : Nat := 1)
(cases : Array Syntax := #[])
private def mkAuxiliaryMatchTermAux (parentTag : Name) (matchTac : Syntax) : StateT AuxMatchTermState MacroM Syntax := do
let matchAlts := matchTac[4]
let alts := matchAlts[1].getArgs
let newAlts β alts.mapSepElemsM fun alt => do
let alt := alt.setKind `Lean.Parser.Term.matchAlt
let holeOrTacticSeq := alt[2]
if holeOrTacticSeq.isOfKind `Lean.Parser.Term.syntheticHole then
pure alt
else if holeOrTacticSeq.isOfKind `Lean.Parser.Term.hole then
let s β get
let tag := if alts.size > 1 then parentTag ++ (`match).appendIndexAfter s.nextIdx else parentTag
let holeName := mkIdentFrom holeOrTacticSeq tag
let newHole β `(?$holeName:ident)
modify fun s => { s with nextIdx := s.nextIdx + 1}
pure $ alt.setArg 2 newHole
else withFreshMacroScope do
let newHole β `(?rhs)
let newHoleId := newHole[1]
let newCase β `(tactic| case $newHoleId => $holeOrTacticSeq:tacticSeq )
modify fun s => { s with cases := s.cases.push newCase }
pure $ alt.setArg 2 newHole
let result := matchTac.setKind `Lean.Parser.Term.Β«matchΒ»
let result := result.setArg 4 (matchAlts.setArg 1 (mkNullNode newAlts))
pure result
private def mkAuxiliaryMatchTerm (parentTag : Name) (matchTac : Syntax) : MacroM (Syntax Γ Array Syntax) := do
let (matchTerm, s) β mkAuxiliaryMatchTermAux parentTag matchTac |>.run {}
pure (matchTerm, s.cases)
@[builtinTactic Lean.Parser.Tactic.match] def evalMatch : Tactic := fun stx => do
let tag β getMainTag
let (matchTerm, cases) β liftMacroM $ mkAuxiliaryMatchTerm tag stx
let refineMatchTerm β `(tactic| refine $matchTerm)
let stxNew := mkNullNode (#[refineMatchTerm] ++ cases)
withMacroExpansion stx stxNew $ evalTactic stxNew
end Lean.Elab.Tactic
|
b448d9d854b37a85cae62fae86b88e6aecfd52e4
|
e00ea76a720126cf9f6d732ad6216b5b824d20a7
|
/src/measure_theory/set_integral.lean
|
53dc9298204dee5ad25e9b32132f015ecb3c076b
|
[
"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
| 14,712
|
lean
|
/-
Copyright (c) 2020 Zhouhang Zhou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Zhouhang Zhou
-/
import measure_theory.bochner_integration
import measure_theory.indicator_function
import measure_theory.lebesgue_measure
/-!
# Set integral
Integrate a function over a subset of a measure space.
## Main definitions
`measurable_on`, `integrable_on`, `integral_on`
## Notation
`β« a in s, f a` is `measure_theory.integral (s.indicator f)`
-/
noncomputable theory
open set filter topological_space measure_theory measure_theory.simple_func
open_locale classical topological_space interval
universes u v w
variables {Ξ± : Type u} {Ξ² : Type v} {Ξ³ : Type w}
section measurable_on
variables [measurable_space Ξ±] [measurable_space Ξ²] [has_zero Ξ²] {s : set Ξ±} {f : Ξ± β Ξ²}
/-- `measurable_on s f` means `f` is measurable over the set `s`. -/
def measurable_on (s : set Ξ±) (f : Ξ± β Ξ²) : Prop := measurable (s.indicator f)
@[simp] lemma measurable_on_empty (f : Ξ± β Ξ²) : measurable_on β
f :=
by { rw [measurable_on, indicator_empty], exact measurable_const }
@[simp] lemma measurable.measurable_on_univ (hf : measurable f) : measurable_on univ f :=
hf.if is_measurable.univ measurable_const
@[simp] lemma measurable_on_singleton {Ξ±} [topological_space Ξ±] [t1_space Ξ±] {a : Ξ±} {f : Ξ± β Ξ²} :
measurable_on {a} f :=
Ξ» s hs, show is_measurable ((indicator {a} f)β»ΒΉ' s),
begin
rw indicator_preimage,
refine is_measurable.union _ (is_measurable_singleton.compl.inter $ measurable_const.preimage hs),
by_cases h : a β fβ»ΒΉ' s,
{ rw inter_eq_self_of_subset_left,
{ exact is_measurable_singleton },
rwa singleton_subset_iff },
rw [singleton_inter_eq_empty.2 h],
exact is_measurable.empty
end
lemma is_measurable.inter_preimage {B : set Ξ²}
(hs : is_measurable s) (hB : is_measurable B) (hf : measurable_on s f):
is_measurable (s β© f β»ΒΉ' B) :=
begin
replace hf : is_measurable ((indicator s f)β»ΒΉ' B) := hf B hB,
rw indicator_preimage at hf,
replace hf := hf.diff _,
rwa union_diff_cancel_right at hf,
{ assume a, simp {contextual := tt} },
exact hs.compl.inter (measurable_const.preimage hB)
end
lemma measurable.measurable_on (hs : is_measurable s) (hf : measurable f) : measurable_on s f :=
hf.if hs measurable_const
lemma measurable_on.subset {t : set Ξ±} (hs : is_measurable s) (h : s β t) (hf : measurable_on t f) :
measurable_on s f :=
begin
have : measurable_on s (indicator t f) := measurable.measurable_on hs hf,
simp only [measurable_on, indicator_indicator] at this,
rwa [inter_eq_self_of_subset_left h] at this
end
lemma measurable_on.union {t : set Ξ±} {f : Ξ± β Ξ²}
(hs : is_measurable s) (ht : is_measurable t) (hsm : measurable_on s f) (htm : measurable_on t f) :
measurable_on (s βͺ t) f :=
begin
assume B hB,
show is_measurable ((indicator (s βͺ t) f)β»ΒΉ' B),
rw indicator_preimage,
refine is_measurable.union _ ((hs.union ht).compl.inter (measurable_const.preimage hB)),
simp only [union_inter_distrib_right],
exact (hs.inter_preimage hB hsm).union (ht.inter_preimage hB htm)
end
end measurable_on
section integrable_on
variables [measure_space Ξ±] [normed_group Ξ²] {s t : set Ξ±} {f g : Ξ± β Ξ²}
/-- `integrable_on s f` means `f` is integrable over the set `s`. -/
def integrable_on (s : set Ξ±) (f : Ξ± β Ξ²) : Prop := integrable (s.indicator f)
lemma integrable_on_congr (h : βx, x β s β f x = g x) : integrable_on s f β integrable_on s g :=
by simp only [integrable_on, indicator_congr h]
lemma integrable_on_congr_ae (h : ββ x, x β s β f x = g x) :
integrable_on s f β integrable_on s g :=
by { apply integrable_congr_ae, exact indicator_congr_ae h }
@[simp] lemma integrable_on_empty (f : Ξ± β Ξ²) : integrable_on β
f :=
by { simp only [integrable_on, indicator_empty], apply integrable_zero }
lemma measure_theory.integrable.integrable_on (s : set Ξ±) (hf : integrable f) : integrable_on s f :=
by { refine integrable_of_le (Ξ»a, _) hf, apply norm_indicator_le_norm_self }
lemma integrable_on.subset (h : s β t) : integrable_on t f β integrable_on s f :=
by { apply integrable_of_le_ae, filter_upwards [] norm_indicator_le_of_subset h _ }
variables {π : Type*} [normed_field π] [normed_space π Ξ²]
lemma integrable_on.smul (s : set Ξ±) (c : π) {f : Ξ± β Ξ²} :
integrable_on s f β integrable_on s (Ξ»a, c β’ f a) :=
by { simp only [integrable_on, indicator_smul], apply integrable.smul }
lemma integrable_on.mul_left (s : set Ξ±) (r : β) {f : Ξ± β β} (hf : integrable_on s f) :
integrable_on s (Ξ»a, r * f a) :=
by { simp only [smul_eq_mul.symm], exact hf.smul s r }
lemma integrable_on.mul_right (s : set Ξ±) (r : β) {f : Ξ± β β} (hf : integrable_on s f) :
integrable_on s (Ξ»a, f a * r) :=
by { simp only [mul_comm], exact hf.mul_left _ _ }
lemma integrable_on.divide (s : set Ξ±) (r : β) {f : Ξ± β β} (hf : integrable_on s f) :
integrable_on s (Ξ»a, f a / r) :=
by { simp only [div_eq_mul_inv], exact hf.mul_right _ _ }
lemma integrable_on.add (hfm : measurable_on s f) (hfi : integrable_on s f) (hgm : measurable_on s g)
(hgi : integrable_on s g) : integrable_on s (Ξ»a, f a + g a) :=
by { rw [integrable_on, indicator_add], exact hfi.add hfm hgm hgi }
lemma integrable_on.neg (hf : integrable_on s f) : integrable_on s (Ξ»a, -f a) :=
by { rw [integrable_on, indicator_neg], exact hf.neg }
lemma integrable_on.sub (hfm : measurable_on s f) (hfi : integrable_on s f) (hgm : measurable_on s g)
(hgi : integrable_on s g) : integrable_on s (Ξ»a, f a - g a) :=
by { rw [integrable_on, indicator_sub], exact hfi.sub hfm hgm hgi }
lemma integrable_on.union (hs : is_measurable s) (ht : is_measurable t) (hsm : measurable_on s f)
(hsi : integrable_on s f) (htm : measurable_on t f) (hti : integrable_on t f) :
integrable_on (s βͺ t) f :=
begin
rw β union_diff_self,
rw [integrable_on, indicator_union_of_disjoint],
{ refine integrable.add hsm hsi (htm.subset _ _) (hti.subset _),
{ exact ht.diff hs },
{ exact diff_subset _ _ },
{ exact diff_subset _ _ } },
exact disjoint_diff
end
lemma integrable_on_norm_iff (s : set Ξ±) (f : Ξ± β Ξ²) :
integrable_on s (Ξ»a, β₯f aβ₯) β integrable_on s f :=
begin
simp only [integrable_on],
convert integrable_norm_iff (indicator s f),
funext,
rw norm_indicator_eq_indicator_norm,
end
end integrable_on
section integral_on
variables [measure_space Ξ±]
[normed_group Ξ²] [second_countable_topology Ξ²] [normed_space β Ξ²] [complete_space Ξ²]
{s t : set Ξ±} {f g : Ξ± β Ξ²}
open set
notation `β«` binders ` in ` s `, ` r:(scoped f, measure_theory.integral (set.indicator s f)) := r
lemma integral_on_undef (h : Β¬ (measurable_on s f β§ integrable_on s f)) : (β« a in s, f a) = 0 :=
integral_undef h
lemma integral_on_non_measurable (h : Β¬ measurable_on s f) : (β« a in s, f a) = 0 :=
integral_non_measurable h
lemma integral_on_non_integrable (h : Β¬ integrable_on s f) : (β« a in s, f a) = 0 :=
integral_non_integrable h
variables (Ξ²)
lemma integral_on_zero (s : set Ξ±) : (β« a in s, (0:Ξ²)) = 0 :=
by simp
variables {Ξ²}
lemma integral_on_congr (h : β a β s, f a = g a) : (β« a in s, f a) = (β« a in s, g a) :=
by simp only [indicator_congr h]
lemma integral_on_congr_of_ae_eq (hf : measurable_on s f) (hg : measurable_on s g)
(h : ββ a, a β s β f a = g a) : (β« a in s, f a) = (β« a in s, g a) :=
integral_congr_ae hf hg (indicator_congr_ae h)
lemma integral_on_congr_of_set (hsm : measurable_on s f) (htm : measurable_on t f)
(h : ββ a, a β s β a β t) : (β« a in s, f a) = (β« a in t, f a) :=
integral_congr_ae hsm htm $ indicator_congr_of_set h
variables (s t)
lemma integral_on_smul (r : β) (f : Ξ± β Ξ²) : (β« a in s, r β’ (f a)) = r β’ (β« a in s, f a) :=
by rw [β integral_smul, indicator_smul]
lemma integral_on_mul_left (r : β) (f : Ξ± β β) : (β« a in s, r * (f a)) = r * (β« a in s, f a) :=
integral_on_smul s r f
lemma integral_on_mul_right (r : β) (f : Ξ± β β) : (β« a in s, (f a) * r) = (β« a in s, f a) * r :=
by { simp only [mul_comm], exact integral_on_mul_left s r f }
lemma integral_on_div (r : β) (f : Ξ± β β) : (β« a in s, (f a) / r) = (β« a in s, f a) / r :=
by { simp only [div_eq_mul_inv], apply integral_on_mul_right }
lemma integral_on_neg (f : Ξ± β Ξ²) : (β« a in s, -f a) = - (β« a in s, f a) :=
by { simp only [indicator_neg], exact integral_neg _ }
variables {s t}
lemma integral_on_add {s : set Ξ±} (hfm : measurable_on s f) (hfi : integrable_on s f) (hgm : measurable_on s g)
(hgi : integrable_on s g) : (β« a in s, f a + g a) = (β« a in s, f a) + (β« a in s, g a) :=
by { simp only [indicator_add], exact integral_add hfm hfi hgm hgi }
lemma integral_on_sub (hfm : measurable_on s f) (hfi : integrable_on s f) (hgm : measurable_on s g)
(hgi : integrable_on s g) : (β« a in s, f a - g a) = (β« a in s, f a) - (β« a in s, g a) :=
by { simp only [indicator_sub], exact integral_sub hfm hfi hgm hgi }
lemma integral_on_le_integral_on_ae {f g : Ξ± β β} (hfm : measurable_on s f) (hfi : integrable_on s f)
(hgm : measurable_on s g) (hgi : integrable_on s g) (h : ββ a, a β s β f a β€ g a) :
(β« a in s, f a) β€ (β« a in s, g a) :=
begin
apply integral_le_integral_ae hfm hfi hgm hgi,
apply indicator_le_indicator_ae,
exact h
end
lemma integral_on_le_integral_on {f g : Ξ± β β} (hfm : measurable_on s f) (hfi : integrable_on s f)
(hgm : measurable_on s g) (hgi : integrable_on s g) (h : β a, a β s β f a β€ g a) :
(β« a in s, f a) β€ (β« a in s, g a) :=
integral_on_le_integral_on_ae hfm hfi hgm hgi $ by filter_upwards [] h
lemma integral_on_union (hsm : measurable_on s f) (hsi : integrable_on s f)
(htm : measurable_on t f) (hti : integrable_on t f) (h : disjoint s t) :
(β« a in (s βͺ t), f a) = (β« a in s, f a) + (β« a in t, f a) :=
by { rw [indicator_union_of_disjoint h, integral_add hsm hsi htm hti] }
lemma integral_on_union_ae (hs : is_measurable s) (ht : is_measurable t) (hsm : measurable_on s f)
(hsi : integrable_on s f) (htm : measurable_on t f) (hti : integrable_on t f) (h : ββ a, a β s β© t) :
(β« a in (s βͺ t), f a) = (β« a in s, f a) + (β« a in t, f a) :=
begin
have := integral_congr_ae _ _ (indicator_union_ae h f),
rw [this, integral_add hsm hsi htm hti],
{ exact hsm.union hs ht htm },
{ exact measurable.add hsm htm }
end
lemma integral_on_nonneg_of_ae {f : Ξ± β β} (hf : ββ a, a β s β 0 β€ f a) : (0:β) β€ (β« a in s, f a) :=
integral_nonneg_of_ae $ by { filter_upwards [hf] Ξ» a h, indicator_nonneg' h }
lemma integral_on_nonneg {f : Ξ± β β} (hf : β a, a β s β 0 β€ f a) : (0:β) β€ (β« a in s, f a) :=
integral_on_nonneg_of_ae $ univ_mem_sets' hf
lemma integral_on_nonpos_of_ae {f : Ξ± β β} (hf : ββ a, a β s β f a β€ 0) : (β« a in s, f a) β€ 0 :=
integral_nonpos_of_nonpos_ae $ by { filter_upwards [hf] Ξ» a h, indicator_nonpos' h }
lemma integral_on_nonpos {f : Ξ± β β} (hf : β a, a β s β f a β€ 0) : (β« a in s, f a) β€ 0 :=
integral_on_nonpos_of_ae $ univ_mem_sets' hf
lemma tendsto_integral_on_of_monotone {s : β β set Ξ±} {f : Ξ± β Ξ²} (hsm : βi, is_measurable (s i))
(h_mono : monotone s) (hfm : measurable_on (Union s) f) (hfi : integrable_on (Union s) f) :
tendsto (Ξ»i, β« a in (s i), f a) at_top (nhds (β« a in (Union s), f a)) :=
let bound : Ξ± β β := indicator (Union s) (Ξ»a, β₯f aβ₯) in
begin
apply tendsto_integral_of_dominated_convergence,
{ assume i, exact hfm.subset (hsm i) (subset_Union _ _) },
{ assumption },
{ show integrable_on (Union s) (Ξ»a, β₯f aβ₯), rwa integrable_on_norm_iff },
{ assume i, apply all_ae_of_all,
assume a,
rw [norm_indicator_eq_indicator_norm],
exact indicator_le_indicator_of_subset (subset_Union _ _) (Ξ»a, norm_nonneg _) _ },
{ filter_upwards [] Ξ»a, le_trans (tendsto_indicator_of_monotone _ h_mono _ _) (pure_le_nhds _) }
end
lemma tendsto_integral_on_of_antimono (s : β β set Ξ±) (f : Ξ± β Ξ²) (hsm : βi, is_measurable (s i))
(h_mono : βi j, i β€ j β s j β s i) (hfm : measurable_on (s 0) f) (hfi : integrable_on (s 0) f) :
tendsto (Ξ»i, β« a in (s i), f a) at_top (nhds (β« a in (Inter s), f a)) :=
let bound : Ξ± β β := indicator (s 0) (Ξ»a, β₯f aβ₯) in
begin
apply tendsto_integral_of_dominated_convergence,
{ assume i, refine hfm.subset (hsm i) (h_mono _ _ (zero_le _)) },
{ exact hfm.subset (is_measurable.Inter hsm) (Inter_subset _ _) },
{ show integrable_on (s 0) (Ξ»a, β₯f aβ₯), rwa integrable_on_norm_iff },
{ assume i, apply all_ae_of_all,
assume a,
rw [norm_indicator_eq_indicator_norm],
refine indicator_le_indicator_of_subset (h_mono _ _ (zero_le _)) (Ξ»a, norm_nonneg _) _ },
{ filter_upwards [] Ξ»a, le_trans (tendsto_indicator_of_antimono _ h_mono _ _) (pure_le_nhds _) }
end
-- TODO : prove this for an encodable type
-- by proving an encodable version of `filter.has_countable_basis_at_top_finset_nat`
lemma integral_on_Union (s : β β set Ξ±) (f : Ξ± β Ξ²) (hm : βi, is_measurable (s i))
(hd : β i j, i β j β s i β© s j = β
) (hfm : measurable_on (Union s) f) (hfi : integrable_on (Union s) f) :
(β« a in (Union s), f a) = βi, β« a in s i, f a :=
suffices h : tendsto (Ξ»n:finset β, n.sum (Ξ» i, β« a in s i, f a)) at_top (π $ (β« a in (Union s), f a)),
by { rwa tsum_eq_has_sum },
begin
have : (Ξ»n:finset β, n.sum (Ξ» i, β« a in s i, f a)) = Ξ»n:finset β, β« a in (βiβn, s i), f a,
{ funext,
rw [β integral_finset_sum, indicator_finset_bUnion],
{ assume i hi j hj hij, exact hd i j hij },
{ assume i, refine hfm.subset (hm _) (subset_Union _ _) },
{ assume i, refine hfi.subset (subset_Union _ _) } },
rw this,
refine tendsto_integral_filter_of_dominated_convergence _ _ _ _ _ _ _,
{ exact indicator (Union s) (Ξ» a, β₯f aβ₯) },
{ exact has_countable_basis_at_top_finset_nat },
{ refine univ_mem_sets' (Ξ» n, _),
simp only [mem_set_of_eq],
refine hfm.subset (is_measurable.Union (Ξ» i, is_measurable.Union_Prop (Ξ»h, hm _)))
(bUnion_subset_Union _ _), },
{ assumption },
{ refine univ_mem_sets' (Ξ» n, univ_mem_sets' $ _),
simp only [mem_set_of_eq],
assume a,
rw β norm_indicator_eq_indicator_norm,
refine norm_indicator_le_of_subset (bUnion_subset_Union _ _) _ _ },
{ rw [β integrable_on, integrable_on_norm_iff], assumption },
{ filter_upwards [] Ξ»a, le_trans (tendsto_indicator_bUnion_finset _ _ _) (pure_le_nhds _) }
end
end integral_on
|
256d5d9828e87ec9364b0254e2d45509fa28c5b4
|
fa02ed5a3c9c0adee3c26887a16855e7841c668b
|
/src/group_theory/specific_groups/dihedral.lean
|
8fb3cbccb2f80e110d697751deab2c68b19a3dcf
|
[
"Apache-2.0"
] |
permissive
|
jjgarzella/mathlib
|
96a345378c4e0bf26cf604aed84f90329e4896a2
|
395d8716c3ad03747059d482090e2bb97db612c8
|
refs/heads/master
| 1,686,480,124,379
| 1,625,163,323,000
| 1,625,163,323,000
| 281,190,421
| 2
| 0
|
Apache-2.0
| 1,595,268,170,000
| 1,595,268,169,000
| null |
UTF-8
|
Lean
| false
| false
| 5,528
|
lean
|
/-
Copyright (c) 2020 Shing Tak Lam. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Shing Tak Lam
-/
import data.zmod.basic
import group_theory.order_of_element
/-!
# Dihedral Groups
We define the dihedral groups `dihedral_group n`, with elements `r i` and `sr i` for `i : zmod n`.
For `n β 0`, `dihedral_group n` represents the symmetry group of the regular `n`-gon. `r i`
represents the rotations of the `n`-gon by `2Οi/n`, and `sr i` represents the reflections of the
`n`-gon. `dihedral_group 0` corresponds to the infinite dihedral group.
-/
/--
For `n β 0`, `dihedral_group n` represents the symmetry group of the regular `n`-gon.
`r i` represents the rotations of the `n`-gon by `2Οi/n`, and `sr i` represents the reflections of
the `n`-gon. `dihedral_group 0` corresponds to the infinite dihedral group.
-/
@[derive decidable_eq]
inductive dihedral_group (n : β) : Type
| r : zmod n β dihedral_group
| sr : zmod n β dihedral_group
namespace dihedral_group
variables {n : β}
/--
Multiplication of the dihedral group.
-/
private def mul : dihedral_group n β dihedral_group n β dihedral_group n
| (r i) (r j) := r (i + j)
| (r i) (sr j) := sr (j - i)
| (sr i) (r j) := sr (i + j)
| (sr i) (sr j) := r (j - i)
/--
The identity `1` is the rotation by `0`.
-/
private def one : dihedral_group n := r 0
instance : inhabited (dihedral_group n) := β¨oneβ©
/--
The inverse of a an element of the dihedral group.
-/
private def inv : dihedral_group n β dihedral_group n
| (r i) := r (-i)
| (sr i) := sr i
/--
The group structure on `dihedral_group n`.
-/
instance : group (dihedral_group n) :=
{ mul := mul,
mul_assoc :=
begin
rintros (a | a) (b | b) (c | c);
simp only [mul];
ring,
end,
one := one,
one_mul :=
begin
rintros (a | a),
exact congr_arg r (zero_add a),
exact congr_arg sr (sub_zero a),
end,
mul_one := begin
rintros (a | a),
exact congr_arg r (add_zero a),
exact congr_arg sr (add_zero a),
end,
inv := inv,
mul_left_inv := begin
rintros (a | a),
exact congr_arg r (neg_add_self a),
exact congr_arg r (sub_self a),
end }
@[simp] lemma r_mul_r (i j : zmod n) : r i * r j = r (i + j) := rfl
@[simp] lemma r_mul_sr (i j : zmod n) : r i * sr j = sr (j - i) := rfl
@[simp] lemma sr_mul_r (i j : zmod n) : sr i * r j = sr (i + j) := rfl
@[simp] lemma sr_mul_sr (i j : zmod n) : sr i * sr j = r (j - i) := rfl
lemma one_def : (1 : dihedral_group n) = r 0 := rfl
private def fintype_helper : (zmod n β zmod n) β dihedral_group n :=
{ inv_fun := Ξ» i, match i with
| (r j) := sum.inl j
| (sr j) := sum.inr j
end,
to_fun := Ξ» i, match i with
| (sum.inl j) := r j
| (sum.inr j) := sr j
end,
left_inv := by rintro (x | x); refl,
right_inv := by rintro (x | x); refl }
/--
If `0 < n`, then `dihedral_group n` is a finite group.
-/
instance [fact (0 < n)] : fintype (dihedral_group n) := fintype.of_equiv _ fintype_helper
instance : nontrivial (dihedral_group n) := β¨β¨r 0, sr 0, dec_trivialβ©β©
/--
If `0 < n`, then `dihedral_group n` has `2n` elements.
-/
lemma card [fact (0 < n)] : fintype.card (dihedral_group n) = 2 * n :=
by rw [β fintype.card_eq.mpr β¨fintype_helperβ©, fintype.card_sum, zmod.card, two_mul]
@[simp] lemma r_one_pow (k : β) : (r 1 : dihedral_group n) ^ k = r k :=
begin
induction k with k IH,
{ refl },
{ rw [pow_succ, IH, r_mul_r],
congr' 1,
norm_cast,
rw nat.one_add }
end
@[simp] lemma r_one_pow_n : (r (1 : zmod n))^n = 1 :=
begin
cases n,
{ rw pow_zero },
{ rw [r_one_pow, one_def],
congr' 1,
exact zmod.nat_cast_self _, }
end
@[simp] lemma sr_mul_self (i : zmod n) : sr i * sr i = 1 := by rw [sr_mul_sr, sub_self, one_def]
/--
If `0 < n`, then `sr i` has order 2.
-/
@[simp] lemma order_of_sr (i : zmod n) : order_of (sr i) = 2 :=
begin
rw order_of_eq_prime _ _,
{ exact β¨nat.prime_twoβ© },
rw [sq, sr_mul_self],
dec_trivial,
end
/--
If `0 < n`, then `r 1` has order `n`.
-/
@[simp] lemma order_of_r_one : order_of (r 1 : dihedral_group n) = n :=
begin
by_cases hnpos : 0 < n,
{ haveI : fact (0 < n) := β¨hnposβ©,
cases lt_or_eq_of_le (nat.le_of_dvd hnpos (order_of_dvd_of_pow_eq_one (@r_one_pow_n n)))
with h h,
{ have h1 : (r 1 : dihedral_group n)^(order_of (r 1)) = 1,
{ exact pow_order_of_eq_one _ },
rw r_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,
apply absurd h2.symm,
apply ne_of_lt,
exact absurd h2.symm (ne_of_lt (order_of_pos _)) },
{ exact h } },
{ simp only [not_lt, nonpos_iff_eq_zero] at hnpos,
rw hnpos,
apply order_of_eq_zero,
rw is_of_fin_order_iff_pow_eq_one,
push_neg,
intros m hm,
rw [r_one_pow, one_def],
by_contradiction,
rw not_not at h,
have h' : (m : zmod 0) = 0,
{ exact r.inj h, },
have h'' : m = 0,
{ simp only [int.coe_nat_eq_zero, int.nat_cast_eq_coe_nat] at h',
exact h', },
rw h'' at hm,
apply nat.lt_irrefl,
exact hm },
end
/--
If `0 < n`, then `i : zmod n` has order `n / gcd n i`.
-/
lemma order_of_r [fact (0 < n)] (i : zmod n) : order_of (r i) = n / nat.gcd n i.val :=
begin
conv_lhs { rw βzmod.nat_cast_zmod_val i },
rw [βr_one_pow, order_of_pow, order_of_r_one]
end
end dihedral_group
|
fc22ab8236e74e372614014c6d0b019558dfbc73
|
737dc4b96c97368cb66b925eeea3ab633ec3d702
|
/src/Lean/Meta/Tactic/Cases.lean
|
3633caa6898706376b55cb11d48e097dbfb31f7b
|
[
"Apache-2.0"
] |
permissive
|
Bioye97/lean4
|
1ace34638efd9913dc5991443777b01a08983289
|
bc3900cbb9adda83eed7e6affeaade7cfd07716d
|
refs/heads/master
| 1,690,589,820,211
| 1,631,051,000,000
| 1,631,067,598,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 16,995
|
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.Meta.AppBuilder
import Lean.Meta.Tactic.Induction
import Lean.Meta.Tactic.Injection
import Lean.Meta.Tactic.Assert
import Lean.Meta.Tactic.Subst
namespace Lean.Meta
private def throwInductiveTypeExpected {Ξ±} (type : Expr) : MetaM Ξ± := do
throwError "failed to compile pattern matching, inductive type expected{indentExpr type}"
def getInductiveUniverseAndParams (type : Expr) : MetaM (List Level Γ Array Expr) := do
let type β whnfD type
matchConstInduct type.getAppFn (fun _ => throwInductiveTypeExpected type) fun val us =>
let I := type.getAppFn
let Iargs := type.getAppArgs
let params := Iargs.extract 0 val.numParams
pure (us, params)
private def mkEqAndProof (lhs rhs : Expr) : MetaM (Expr Γ Expr) := do
let lhsType β inferType lhs
let rhsType β inferType rhs
let u β getLevel lhsType
if (β isDefEq lhsType rhsType) then
pure (mkApp3 (mkConst `Eq [u]) lhsType lhs rhs, mkApp2 (mkConst `Eq.refl [u]) lhsType lhs)
else
pure (mkApp4 (mkConst `HEq [u]) lhsType lhs rhsType rhs, mkApp2 (mkConst `HEq.refl [u]) lhsType lhs)
private partial def withNewEqs {Ξ±} (targets targetsNew : Array Expr) (k : Array Expr β Array Expr β MetaM Ξ±) : MetaM Ξ± :=
let rec loop (i : Nat) (newEqs : Array Expr) (newRefls : Array Expr) := do
if h : i < targets.size then
let (newEqType, newRefl) β mkEqAndProof targets[i] targetsNew[i]
withLocalDeclD `h newEqType fun newEq => do
loop (i+1) (newEqs.push newEq) (newRefls.push newRefl)
else
k newEqs newRefls
loop 0 #[] #[]
def generalizeTargetsEq (mvarId : MVarId) (motiveType : Expr) (targets : Array Expr) : MetaM MVarId :=
withMVarContext mvarId do
checkNotAssigned mvarId `generalizeTargets
let (typeNew, eqRefls) β
forallTelescopeReducing motiveType fun targetsNew _ => do
unless targetsNew.size == targets.size do
throwError "invalid number of targets #{targets.size}, motive expects #{targetsNew.size}"
withNewEqs targets targetsNew fun eqs eqRefls => do
let type β getMVarType mvarId
let typeNew β mkForallFVars eqs type
let typeNew β mkForallFVars targetsNew typeNew
pure (typeNew, eqRefls)
let mvarNew β mkFreshExprSyntheticOpaqueMVar typeNew (β getMVarTag mvarId)
assignExprMVar mvarId (mkAppN (mkAppN mvarNew targets) eqRefls)
pure mvarNew.mvarId!
structure GeneralizeIndicesSubgoal where
mvarId : MVarId
indicesFVarIds : Array FVarId
fvarId : FVarId
numEqs : Nat
/--
Similar to `generalizeTargets` but customized for the `casesOn` motive.
Given a metavariable `mvarId` representing the
```
Ctx, h : I A j, D |- T
```
where `fvarId` is `h`s id, and the type `I A j` is an inductive datatype where `A` are parameters,
and `j` the indices. Generate the goal
```
Ctx, h : I A j, D, j' : J, h' : I A j' |- j == j' -> h == h' -> T
```
Remark: `(j == j' -> h == h')` is a "telescopic" equality.
Remark: `j` is sequence of terms, and `j'` a sequence of free variables.
The result contains the fields
- `mvarId`: the new goal
- `indicesFVarIds`: `j'` ids
- `fvarId`: `h'` id
- `numEqs`: number of equations in the target -/
def generalizeIndices (mvarId : MVarId) (fvarId : FVarId) : MetaM GeneralizeIndicesSubgoal :=
withMVarContext mvarId do
let lctx β getLCtx
let localInsts β getLocalInstances
checkNotAssigned mvarId `generalizeIndices
let fvarDecl β getLocalDecl fvarId
let type β whnf fvarDecl.type
type.withApp fun f args => matchConstInduct f (fun _ => throwTacticEx `generalizeIndices mvarId "inductive type expected") fun val _ => do
unless val.numIndices > 0 do throwTacticEx `generalizeIndices mvarId "indexed inductive type expected"
unless args.size == val.numIndices + val.numParams do throwTacticEx `generalizeIndices mvarId "ill-formed inductive datatype"
let indices := args.extract (args.size - val.numIndices) args.size
let IA := mkAppN f (args.extract 0 val.numParams) -- `I A`
let IAType β inferType IA
forallTelescopeReducing IAType fun newIndices _ => do
let newType := mkAppN IA newIndices
withLocalDeclD fvarDecl.userName newType fun h' =>
withNewEqs indices newIndices fun newEqs newRefls => do
let (newEqType, newRefl) β mkEqAndProof fvarDecl.toExpr h'
let newRefls := newRefls.push newRefl
withLocalDeclD `h newEqType fun newEq => do
let newEqs := newEqs.push newEq
/- auxType `forall (j' : J) (h' : I A j'), j == j' -> h == h' -> target -/
let target β getMVarType mvarId
let tag β getMVarTag mvarId
let auxType β mkForallFVars newEqs target
let auxType β mkForallFVars #[h'] auxType
let auxType β mkForallFVars newIndices auxType
let newMVar β mkFreshExprMVarAt lctx localInsts auxType MetavarKind.syntheticOpaque tag
/- assign mvarId := newMVar indices h refls -/
assignExprMVar mvarId (mkAppN (mkApp (mkAppN newMVar indices) fvarDecl.toExpr) newRefls)
let (indicesFVarIds, newMVarId) β introNP newMVar.mvarId! newIndices.size
let (fvarId, newMVarId) β intro1P newMVarId
pure {
mvarId := newMVarId,
indicesFVarIds := indicesFVarIds,
fvarId := fvarId,
numEqs := newEqs.size
}
structure CasesSubgoal extends InductionSubgoal where
ctorName : Name
namespace Cases
structure Context where
inductiveVal : InductiveVal
casesOnVal : DefinitionVal
nminors : Nat := inductiveVal.ctors.length
majorDecl : LocalDecl
majorTypeFn : Expr
majorTypeArgs : Array Expr
majorTypeIndices : Array Expr := majorTypeArgs.extract (majorTypeArgs.size - inductiveVal.numIndices) majorTypeArgs.size
private def mkCasesContext? (majorFVarId : FVarId) : MetaM (Option Context) := do
let env β getEnv
if !env.contains `Eq || !env.contains `HEq then
pure none
else
let majorDecl β getLocalDecl majorFVarId
let majorType β whnf majorDecl.type
majorType.withApp fun f args => matchConstInduct f (fun _ => pure none) fun ival _ =>
if args.size != ival.numIndices + ival.numParams then pure none
else match env.find? (Name.mkStr ival.name "casesOn") with
| ConstantInfo.defnInfo cval =>
pure $ some {
inductiveVal := ival,
casesOnVal := cval,
majorDecl := majorDecl,
majorTypeFn := f,
majorTypeArgs := args
}
| _ => pure none
/-
We say the major premise has independent indices IF
1- its type is *not* an indexed inductive family, OR
2- its type is an indexed inductive family, but all indices are distinct free variables, and
all local declarations different from the major and its indices do not depend on the indices.
-/
private def hasIndepIndices (ctx : Context) : MetaM Bool := do
if ctx.majorTypeIndices.isEmpty then
pure true
else if ctx.majorTypeIndices.any $ fun idx => !idx.isFVar then
/- One of the indices is not a free variable. -/
pure false
else if ctx.majorTypeIndices.size.any fun i => i.any fun j => ctx.majorTypeIndices[i] == ctx.majorTypeIndices[j] then
/- An index ocurrs more than once -/
pure false
else
let lctx β getLCtx
let mctx β getMCtx
pure $ lctx.all fun decl =>
decl.fvarId == ctx.majorDecl.fvarId || -- decl is the major
ctx.majorTypeIndices.any (fun index => decl.fvarId == index.fvarId!) || -- decl is one of the indices
mctx.findLocalDeclDependsOn decl (fun fvarId => ctx.majorTypeIndices.all $ fun idx => idx.fvarId! != fvarId) -- or does not depend on any index
private def elimAuxIndices (sβ : GeneralizeIndicesSubgoal) (sβ : Array CasesSubgoal) : MetaM (Array CasesSubgoal) :=
let indicesFVarIds := sβ.indicesFVarIds
sβ.mapM fun s => do
indicesFVarIds.foldlM (init := s) fun s indexFVarId =>
match s.subst.get indexFVarId with
| Expr.fvar indexFVarId' _ =>
(do let mvarId β clear s.mvarId indexFVarId'; pure { s with mvarId := mvarId, subst := s.subst.erase indexFVarId })
<|>
(pure s)
| _ => pure s
/-
Convert `s` into an array of `CasesSubgoal`, by attaching the corresponding constructor name,
and adding the substitution `majorFVarId -> ctor_i us params fields` into each subgoal. -/
private def toCasesSubgoals (s : Array InductionSubgoal) (ctorNames : Array Name) (majorFVarId : FVarId) (us : List Level) (params : Array Expr)
: Array CasesSubgoal :=
s.mapIdx fun i s =>
let ctorName := ctorNames[i]
let ctorApp := mkAppN (mkAppN (mkConst ctorName us) params) s.fields
let s := { s with subst := s.subst.insert majorFVarId ctorApp }
{ ctorName := ctorName,
toInductionSubgoal := s }
/- Convert heterogeneous equality into a homegeneous one -/
private def heqToEq (mvarId : MVarId) (eqDecl : LocalDecl) : MetaM MVarId := do
/- Convert heterogeneous equality into a homegeneous one -/
let prf β mkEqOfHEq (mkFVar eqDecl.fvarId)
let aEqb β whnf (β inferType prf)
let mvarId β assert mvarId eqDecl.userName aEqb prf
clear mvarId eqDecl.fvarId
partial def unifyEqs (numEqs : Nat) (mvarId : MVarId) (subst : FVarSubst) (caseName? : Option Name := none): MetaM (Option (MVarId Γ FVarSubst)) := do
if numEqs == 0 then
pure (some (mvarId, subst))
else
let (eqFVarId, mvarId) β intro1 mvarId
withMVarContext mvarId do
let eqDecl β getLocalDecl eqFVarId
if eqDecl.type.isHEq then
let mvarId β heqToEq mvarId eqDecl
unifyEqs numEqs mvarId subst caseName?
else match eqDecl.type.eq? with
| none => throwError "equality expected{indentExpr eqDecl.type}"
| some (Ξ±, a, b) =>
/-
Remark: we do not check `isDefeq` here because we would fail to substitute equalities
such as `x = t` and `t = x` when `x` and `t` are proofs (proof irrelanvance).
-/
/- Remark: we use `let rec` here because otherwise the compiler would generate an insane amount of code.
We can remove the `rec` after we fix the eagerly inlining issue in the compiler. -/
let rec substEq (symm : Bool) := do
/- TODO: support for acyclicity (e.g., `xs β x :: xs`) -/
/- Remark: `substCore` fails if the equation is of the form `x = x` -/
if let some (substNew, mvarId) β observing? (substCore mvarId eqFVarId symm subst) then
unifyEqs (numEqs - 1) mvarId substNew caseName?
else if (β isDefEq a b) then
/- Skip equality -/
unifyEqs (numEqs - 1) (β clear mvarId eqFVarId) subst caseName?
else
throwError "dependent elimination failed, failed to solve equation{indentExpr eqDecl.type}"
let rec injection (a b : Expr) := do
let env β getEnv
if a.isConstructorApp env && b.isConstructorApp env then
/- ctor_i ... = ctor_j ... -/
match (β injectionCore mvarId eqFVarId) with
| InjectionResultCore.solved => pure none -- this alternative has been solved
| InjectionResultCore.subgoal mvarId numEqsNew => unifyEqs (numEqs - 1 + numEqsNew) mvarId subst caseName?
else
let a' β whnf a
let b' β whnf b
if a' != a || b' != b then
/- Reduced lhs/rhs of current equality -/
let prf := mkFVar eqFVarId
let aEqb' β mkEq a' b'
let mvarId β assert mvarId eqDecl.userName aEqb' prf
let mvarId β clear mvarId eqFVarId
unifyEqs numEqs mvarId subst caseName?
else
match caseName? with
| none => throwError "dependent elimination failed, failed to solve equation{indentExpr eqDecl.type}"
| some caseName => throwError "dependent elimination failed, failed to solve equation{indentExpr eqDecl.type}\nat case {mkConst caseName}"
let a β instantiateMVars a
let b β instantiateMVars b
match a, b with
| Expr.fvar aFVarId _, Expr.fvar bFVarId _ =>
/- x = y -/
let aDecl β getLocalDecl aFVarId
let bDecl β getLocalDecl bFVarId
substEq (aDecl.index < bDecl.index)
| Expr.fvar .., _ => /- x = t -/ substEq (symm := false)
| _, Expr.fvar .. => /- t = x -/ substEq (symm := true)
| a, b =>
if (β isDefEq a b) then
/- Skip equality -/
unifyEqs (numEqs - 1) (β clear mvarId eqFVarId) subst caseName?
else
injection a b
private def unifyCasesEqs (numEqs : Nat) (subgoals : Array CasesSubgoal) : MetaM (Array CasesSubgoal) :=
subgoals.foldlM (init := #[]) fun subgoals s => do
match (β unifyEqs numEqs s.mvarId s.subst s.ctorName) with
| none => pure subgoals
| some (mvarId, subst) =>
pure $ subgoals.push { s with
mvarId := mvarId,
subst := subst,
fields := s.fields.map (subst.apply Β·)
}
private def inductionCasesOn (mvarId : MVarId) (majorFVarId : FVarId) (givenNames : Array AltVarNames) (ctx : Context)
: MetaM (Array CasesSubgoal) := do
withMVarContext mvarId do
let majorType β inferType (mkFVar majorFVarId)
let (us, params) β getInductiveUniverseAndParams majorType
let casesOn := mkCasesOnName ctx.inductiveVal.name
let ctors := ctx.inductiveVal.ctors.toArray
let s β induction mvarId majorFVarId casesOn givenNames
return toCasesSubgoals s ctors majorFVarId us params
def cases (mvarId : MVarId) (majorFVarId : FVarId) (givenNames : Array AltVarNames := #[]) : MetaM (Array CasesSubgoal) :=
withMVarContext mvarId do
checkNotAssigned mvarId `cases
let context? β mkCasesContext? majorFVarId
match context? with
| none => throwTacticEx `cases mvarId "not applicable to the given hypothesis"
| some ctx =>
/- Remark: if caller does not need a `FVarSubst` (variable substitution), and `hasIndepIndices ctx` is true,
then we can also use the simple case. This is a minor optimization, and we currently do not even
allow callers to specify whether they want the `FVarSubst` or not. -/
if ctx.inductiveVal.numIndices == 0 then
-- Simple case
inductionCasesOn mvarId majorFVarId givenNames ctx
else
let sβ β generalizeIndices mvarId majorFVarId
trace[Meta.Tactic.cases] "after generalizeIndices\n{MessageData.ofGoal sβ.mvarId}"
let sβ β inductionCasesOn sβ.mvarId sβ.fvarId givenNames ctx
let sβ β elimAuxIndices sβ sβ
unifyCasesEqs sβ.numEqs sβ
end Cases
def cases (mvarId : MVarId) (majorFVarId : FVarId) (givenNames : Array AltVarNames := #[]) : MetaM (Array CasesSubgoal) :=
Cases.cases mvarId majorFVarId givenNames
def casesRec (mvarId : MVarId) (p : LocalDecl β MetaM Bool) : MetaM (List MVarId) :=
saturate mvarId fun mvarId =>
withMVarContext mvarId do
for localDecl in (β getLCtx) do
if (β p localDecl) then
let r? β observing? do
let r β cases mvarId localDecl.fvarId
return r.toList.map (Β·.mvarId)
if r?.isSome then
return r?
return none
def casesAnd (mvarId : MVarId) : MetaM MVarId := do
let mvarIds β casesRec mvarId fun localDecl => return (β instantiateMVars localDecl.type).isAppOfArity ``And 2
exactlyOne mvarIds
def substEqs (mvarId : MVarId) : MetaM MVarId := do
let mvarIds β casesRec mvarId fun localDecl => do
let type β instantiateMVars localDecl.type
return type.isEq || type.isHEq
exactlyOne mvarIds
structure ByCasesSubgoal where
mvarId : MVarId
fvarId : FVarId
def byCases (mvarId : MVarId) (p : Expr) (hName : Name := `h) : MetaM (ByCasesSubgoal Γ ByCasesSubgoal) := do
let mvarId β assert mvarId `hByCases (mkOr p (mkNot p)) (mkEM p)
let (fvarId, mvarId) β intro1 mvarId
let #[sβ, sβ] β cases mvarId fvarId #[{ varNames := [hName] }, { varNames := [hName] }] |
throwError "'byCases' tactic failed, unexpected number of subgoals"
return ((β toByCasesSubgoal sβ), (β toByCasesSubgoal sβ))
where
toByCasesSubgoal (s : CasesSubgoal) : MetaM ByCasesSubgoal := do
let #[Expr.fvar fvarId ..] β pure s.fields | throwError "'byCases' tactic failed, unexpected new hypothesis"
return { mvarId := s.mvarId, fvarId }
builtin_initialize registerTraceClass `Meta.Tactic.cases
end Lean.Meta
|
bf050da66c475f40b2c68700e96f290c77aecde6
|
31f556cdeb9239ffc2fad8f905e33987ff4feab9
|
/src/Lean/CoreM.lean
|
ab84d1d1c165073ea7e8ee4f56d0fbb2f22c35df
|
[
"Apache-2.0",
"LLVM-exception",
"NCSA",
"LGPL-3.0-only",
"LicenseRef-scancode-inner-net-2.0",
"BSD-3-Clause",
"LGPL-2.0-or-later",
"Spencer-94",
"LGPL-2.1-or-later",
"HPND",
"LicenseRef-scancode-pcre",
"ISC",
"LGPL-2.1-only",
"LicenseRef-scancode-other-permissive",
"SunPro",
"CMU-Mach"
] |
permissive
|
tobiasgrosser/lean4
|
ce0fd9cca0feba1100656679bf41f0bffdbabb71
|
ebdbdc10436a4d9d6b66acf78aae7a23f5bd073f
|
refs/heads/master
| 1,673,103,412,948
| 1,664,930,501,000
| 1,664,930,501,000
| 186,870,185
| 0
| 0
|
Apache-2.0
| 1,665,129,237,000
| 1,557,939,901,000
|
Lean
|
UTF-8
|
Lean
| false
| false
| 13,437
|
lean
|
/-
Copyright (c) 2020 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
import Lean.Util.RecDepth
import Lean.Util.Trace
import Lean.Log
import Lean.Eval
import Lean.ResolveName
import Lean.Elab.InfoTree.Types
import Lean.MonadEnv
namespace Lean
namespace Core
register_builtin_option maxHeartbeats : Nat := {
defValue := 200000
descr := "maximum amount of heartbeats per command. A heartbeat is number of (small) memory allocations (in thousands), 0 means no limit"
}
def getMaxHeartbeats (opts : Options) : Nat :=
maxHeartbeats.get opts * 1000
abbrev InstantiateLevelCache := PersistentHashMap Name (List Level Γ Expr)
/-- Cache for the `CoreM` monad -/
structure Cache where
instLevelType : InstantiateLevelCache := {}
instLevelValue : InstantiateLevelCache := {}
deriving Inhabited
/-- State for the CoreM monad. -/
structure State where
/-- Current environment. -/
env : Environment
/-- Next macro scope. We use macro scopes to avoid accidental name capture. -/
nextMacroScope : MacroScope := firstFrontendMacroScope + 1
/-- Name generator for producing unique `FVarId`s, `MVarId`s, and `LMVarId`s -/
ngen : NameGenerator := {}
/-- Trace messages -/
traceState : TraceState := {}
/-- Cache for instantiating universe polymorphic declarations. -/
cache : Cache := {}
/-- Message log. -/
messages : MessageLog := {}
/-- Info tree. We have the info tree here because we want to update it while adding attributes. -/
infoState : Elab.InfoState := {}
deriving Inhabited
/-- Context for the CoreM monad. -/
structure Context where
/-- Name of the file being compiled. -/
fileName : String
/-- Auxiliary datastructure for converting `String.Pos` into Line/Column number. -/
fileMap : FileMap
options : Options := {}
currRecDepth : Nat := 0
maxRecDepth : Nat := 1000
ref : Syntax := Syntax.missing
currNamespace : Name := Name.anonymous
openDecls : List OpenDecl := []
initHeartbeats : Nat := 0
maxHeartbeats : Nat := getMaxHeartbeats options
currMacroScope : MacroScope := firstFrontendMacroScope
/-- CoreM is a monad for manipulating the Lean environment.
It is the base monad for `MetaM`.
The main features it provides are:
- name generator state
- environment state
- Lean options context
- the current open namespace
-/
abbrev CoreM := ReaderT Context <| StateRefT State (EIO Exception)
-- Make the compiler generate specialized `pure`/`bind` so we do not have to optimize through the
-- whole monad stack at every use site. May eventually be covered by `deriving`.
instance : Monad CoreM := let i := inferInstanceAs (Monad CoreM); { pure := i.pure, bind := i.bind }
instance : Inhabited (CoreM Ξ±) where
default := fun _ _ => throw default
instance : MonadRef CoreM where
getRef := return (β read).ref
withRef ref x := withReader (fun ctx => { ctx with ref := ref }) x
instance : MonadEnv CoreM where
getEnv := return (β get).env
modifyEnv f := modify fun s => { s with env := f s.env, cache := {} }
instance : MonadOptions CoreM where
getOptions := return (β read).options
instance : MonadWithOptions CoreM where
withOptions f x := withReader (fun ctx => { ctx with options := f ctx.options }) x
instance : AddMessageContext CoreM where
addMessageContext := addMessageContextPartial
instance : MonadNameGenerator CoreM where
getNGen := return (β get).ngen
setNGen ngen := modify fun s => { s with ngen := ngen }
instance : MonadRecDepth CoreM where
withRecDepth d x := withReader (fun ctx => { ctx with currRecDepth := d }) x
getRecDepth := return (β read).currRecDepth
getMaxRecDepth := return (β read).maxRecDepth
instance : MonadResolveName CoreM where
getCurrNamespace := return (β read).currNamespace
getOpenDecls := return (β read).openDecls
protected def withFreshMacroScope (x : CoreM Ξ±) : CoreM Ξ± := do
let fresh β modifyGetThe Core.State (fun st => (st.nextMacroScope, { st with nextMacroScope := st.nextMacroScope + 1 }))
withReader (fun ctx => { ctx with currMacroScope := fresh }) x
instance : MonadQuotation CoreM where
getCurrMacroScope := return (β read).currMacroScope
getMainModule := return (β get).env.mainModule
withFreshMacroScope := Core.withFreshMacroScope
instance : Elab.MonadInfoTree CoreM where
getInfoState := return (β get).infoState
modifyInfoState f := modify fun s => { s with infoState := f s.infoState }
@[inline] def modifyCache (f : Cache β Cache) : CoreM Unit :=
modify fun β¨env, next, ngen, trace, cache, messages, infoStateβ© => β¨env, next, ngen, trace, f cache, messages, infoStateβ©
@[inline] def modifyInstLevelTypeCache (f : InstantiateLevelCache β InstantiateLevelCache) : CoreM Unit :=
modifyCache fun β¨cβ, cββ© => β¨f cβ, cββ©
@[inline] def modifyInstLevelValueCache (f : InstantiateLevelCache β InstantiateLevelCache) : CoreM Unit :=
modifyCache fun β¨cβ, cββ© => β¨cβ, f cββ©
def instantiateTypeLevelParams (c : ConstantInfo) (us : List Level) : CoreM Expr := do
if let some (us', r) := (β get).cache.instLevelType.find? c.name then
if us == us' then
return r
let r := c.instantiateTypeLevelParams us
modifyInstLevelTypeCache fun s => s.insert c.name (us, r)
return r
def instantiateValueLevelParams (c : ConstantInfo) (us : List Level) : CoreM Expr := do
if let some (us', r) := (β get).cache.instLevelValue.find? c.name then
if us == us' then
return r
let r := c.instantiateValueLevelParams us
modifyInstLevelValueCache fun s => s.insert c.name (us, r)
return r
@[inline] def liftIOCore (x : IO Ξ±) : CoreM Ξ± := do
let ref β getRef
IO.toEIO (fun (err : IO.Error) => Exception.error ref (toString err)) x
instance : MonadLift IO CoreM where
monadLift := liftIOCore
instance : MonadTrace CoreM where
getTraceState := return (β get).traceState
modifyTraceState f := modify fun s => { s with traceState := f s.traceState }
/-- Restore backtrackable parts of the state. -/
def restore (b : State) : CoreM Unit :=
modify fun s => { s with env := b.env, messages := b.messages, infoState := b.infoState }
private def mkFreshNameImp (n : Name) : CoreM Name := do
let fresh β modifyGet fun s => (s.nextMacroScope, { s with nextMacroScope := s.nextMacroScope + 1 })
return addMacroScope (β getEnv).mainModule n fresh
def mkFreshUserName (n : Name) : CoreM Name :=
mkFreshNameImp n
@[inline] def CoreM.run (x : CoreM Ξ±) (ctx : Context) (s : State) : EIO Exception (Ξ± Γ State) :=
(x ctx).run s
@[inline] def CoreM.run' (x : CoreM Ξ±) (ctx : Context) (s : State) : EIO Exception Ξ± :=
Prod.fst <$> x.run ctx s
@[inline] def CoreM.toIO (x : CoreM Ξ±) (ctx : Context) (s : State) : IO (Ξ± Γ State) := do
match (β (x.run { ctx with initHeartbeats := (β IO.getNumHeartbeats) } s).toIO') with
| Except.error (Exception.error _ msg) => throw <| IO.userError (β msg.toString)
| Except.error (Exception.internal id _) => throw <| IO.userError <| "internal exception #" ++ toString id.idx
| Except.ok a => return a
instance [MetaEval Ξ±] : MetaEval (CoreM Ξ±) where
eval env opts x _ := do
let x : CoreM Ξ± := do try x finally printTraces
let (a, s) β x.toIO { maxRecDepth := maxRecDepth.get opts, options := opts, fileName := "<CoreM>", fileMap := default } { env := env }
MetaEval.eval s.env opts a (hideUnit := true)
-- withIncRecDepth for a monad `m` such that `[MonadControlT CoreM n]`
protected def withIncRecDepth [Monad m] [MonadControlT CoreM m] (x : m Ξ±) : m Ξ± :=
controlAt CoreM fun runInBase => withIncRecDepth (runInBase x)
def throwMaxHeartbeat (moduleName : Name) (optionName : Name) (max : Nat) : CoreM Unit := do
let msg := s!"(deterministic) timeout at '{moduleName}', maximum number of heartbeats ({max/1000}) has been reached (use 'set_option {optionName} <num>' to set the limit)"
throw <| Exception.error (β getRef) (MessageData.ofFormat (Std.Format.text msg))
def checkMaxHeartbeatsCore (moduleName : String) (optionName : Name) (max : Nat) : CoreM Unit := do
unless max == 0 do
let numHeartbeats β IO.getNumHeartbeats
if numHeartbeats - (β read).initHeartbeats > max then
throwMaxHeartbeat moduleName optionName max
def checkMaxHeartbeats (moduleName : String) : CoreM Unit := do
checkMaxHeartbeatsCore moduleName `maxHeartbeats (β read).maxHeartbeats
private def withCurrHeartbeatsImp (x : CoreM Ξ±) : CoreM Ξ± := do
let heartbeats β IO.getNumHeartbeats
withReader (fun ctx => { ctx with initHeartbeats := heartbeats }) x
def withCurrHeartbeats [Monad m] [MonadControlT CoreM m] (x : m Ξ±) : m Ξ± :=
controlAt CoreM fun runInBase => withCurrHeartbeatsImp (runInBase x)
def setMessageLog (messages : MessageLog) : CoreM Unit :=
modify fun s => { s with messages := messages }
def resetMessageLog : CoreM Unit :=
setMessageLog {}
def getMessageLog : CoreM MessageLog :=
return (β get).messages
instance : MonadLog CoreM where
getRef := getRef
getFileMap := return (β read).fileMap
getFileName := return (β read).fileName
hasErrors := return (β get).messages.hasErrors
logMessage msg := do
let ctx β read
let msg := { msg with data := MessageData.withNamingContext { currNamespace := ctx.currNamespace, openDecls := ctx.openDecls } msg.data };
modify fun s => { s with messages := s.messages.add msg }
end Core
export Core (CoreM mkFreshUserName checkMaxHeartbeats withCurrHeartbeats)
@[inline] def withAtLeastMaxRecDepth [MonadFunctorT CoreM m] (max : Nat) : m Ξ± β m Ξ± :=
monadMap (m := CoreM) <| withReader (fun ctx => { ctx with maxRecDepth := Nat.max max ctx.maxRecDepth })
@[inline] def catchInternalId [Monad m] [MonadExcept Exception m] (id : InternalExceptionId) (x : m Ξ±) (h : Exception β m Ξ±) : m Ξ± := do
try
x
catch ex => match ex with
| .error .. => throw ex
| .internal id' _ => if id == id' then h ex else throw ex
@[inline] def catchInternalIds [Monad m] [MonadExcept Exception m] (ids : List InternalExceptionId) (x : m Ξ±) (h : Exception β m Ξ±) : m Ξ± := do
try
x
catch ex => match ex with
| .error .. => throw ex
| .internal id _ => if ids.contains id then h ex else throw ex
/--
Return true if `ex` was generated by `throwMaxHeartbeat`.
This function is a bit hackish. The heartbeat exception should probably be an internal exception.
We used a similar hack at `Exception.isMaxRecDepth` -/
def Exception.isMaxHeartbeat (ex : Exception) : Bool :=
match ex with
| Exception.error _ (MessageData.ofFormat (Std.Format.text msg)) => "(deterministic) timeout".isPrefixOf msg
| _ => false
/-- Creates the expression `d β b` -/
def mkArrow (d b : Expr) : CoreM Expr :=
return Lean.mkForall (β mkFreshUserName `x) BinderInfo.default d b
def addDecl (decl : Declaration) : CoreM Unit := do
if !(β MonadLog.hasErrors) && decl.hasSorry then
logWarning "declaration uses 'sorry'"
match (β getEnv).addDecl decl with
| Except.ok env => setEnv env
| Except.error ex => throwKernelException ex
private def supportedRecursors :=
#[``Empty.rec, ``False.rec, ``Eq.ndrec, ``Eq.rec, ``Eq.recOn, ``Eq.casesOn, ``False.casesOn, ``Empty.casesOn, ``And.rec, ``And.casesOn]
/-- This is a temporary workaround for generating better error messages for the compiler. It can be deleted after we
rewrite the remaining parts of the compiler in Lean. -/
private def checkUnsupported [Monad m] [MonadEnv m] [MonadError m] (decl : Declaration) : m Unit := do
let env β getEnv
decl.forExprM fun e =>
let unsupportedRecursor? := e.find? fun
| Expr.const declName .. =>
((isAuxRecursor env declName && !isCasesOnRecursor env declName) || isRecCore env declName)
&& !supportedRecursors.contains declName
| _ => false
match unsupportedRecursor? with
| some (Expr.const declName ..) => throwError "code generator does not support recursor '{declName}' yet, consider using 'match ... with' and/or structural recursion"
| _ => pure ()
-- Forward declaration
@[extern "lean_lcnf_compile_decls"]
opaque compileDeclsNew (declNames : List Name) : CoreM Unit
def compileDecl (decl : Declaration) : CoreM Unit := do
compileDeclsNew (Compiler.getDeclNamesForCodeGen decl)
match (β getEnv).compileDecl (β getOptions) decl with
| Except.ok env => setEnv env
| Except.error (KernelException.other msg) =>
checkUnsupported decl -- Generate nicer error message for unsupported recursors and axioms
throwError msg
| Except.error ex =>
throwKernelException ex
def compileDecls (decls : List Name) : CoreM Unit := do
compileDeclsNew decls
match (β getEnv).compileDecls (β getOptions) decls with
| Except.ok env => setEnv env
| Except.error (KernelException.other msg) =>
throwError msg
| Except.error ex =>
throwKernelException ex
def addAndCompile (decl : Declaration) : CoreM Unit := do
addDecl decl;
compileDecl decl
def ImportM.runCoreM (x : CoreM Ξ±) : ImportM Ξ± := do
let ctx β read
let (a, _) β x.toIO { options := ctx.opts, fileName := "<ImportM>", fileMap := default } { env := ctx.env }
return a
end Lean
|
1d345bb17a9560e96cd151899b9ee06a57a85710
|
4d2583807a5ac6caaffd3d7a5f646d61ca85d532
|
/src/order/rel_iso.lean
|
7abe2d404713da5ce927b42c5ee45a238e8d321e
|
[
"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
| 35,469
|
lean
|
/-
Copyright (c) 2017 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import algebra.group.defs
import data.equiv.set
import logic.embedding
import order.rel_classes
/-!
# Relation homomorphisms, embeddings, isomorphisms
This file defines relation homomorphisms, embeddings, isomorphisms and order embeddings and
isomorphisms.
## Main declarations
* `rel_hom`: Relation homomorphism. A `rel_hom r s` is a function `f : Ξ± β Ξ²` such that
`r a b β s (f a) (f b)`.
* `rel_embedding`: Relation embedding. A `rel_embedding r s` is an embedding `f : Ξ± βͺ Ξ²` such that
`r a b β s (f a) (f b)`.
* `rel_iso`: Relation isomorphism. A `rel_iso r s` is an equivalence `f : Ξ± β Ξ²` such that
`r a b β s (f a) (f b)`.
* `order_embedding`: Relation embedding. An `order_embedding Ξ± Ξ²` is an embedding `f : Ξ± βͺ Ξ²` such
that `a β€ b β f a β€ f b`. Defined as an abbreviation of `@rel_embedding Ξ± Ξ² (β€) (β€)`.
* `order_iso`: Relation isomorphism. An `order_iso Ξ± Ξ²` is an equivalence `f : Ξ± β Ξ²` such that
`a β€ b β f a β€ f b`. Defined as an abbreviation of `@rel_iso Ξ± Ξ² (β€) (β€)`.
* `sum_lex_congr`, `prod_lex_congr`: Creates a relation homomorphism between two `sum_lex` or two
`prod_lex` from relation homomorphisms between their arguments.
## Notation
* `βr`: `rel_hom`
* `βͺr`: `rel_embedding`
* `βr`: `rel_iso`
* `βͺo`: `order_embedding`
* `βo`: `order_iso`
-/
open function
universes u v w
variables {Ξ± Ξ² Ξ³ : Type*} {r : Ξ± β Ξ± β Prop} {s : Ξ² β Ξ² β Prop} {t : Ξ³ β Ξ³ β Prop}
/-- A relation homomorphism with respect to a given pair of relations `r` and `s`
is a function `f : Ξ± β Ξ²` such that `r a b β s (f a) (f b)`. -/
@[nolint has_inhabited_instance]
structure rel_hom {Ξ± Ξ² : Type*} (r : Ξ± β Ξ± β Prop) (s : Ξ² β Ξ² β Prop) :=
(to_fun : Ξ± β Ξ²)
(map_rel' : β {a b}, r a b β s (to_fun a) (to_fun b))
infix ` βr `:25 := rel_hom
namespace rel_hom
instance : has_coe_to_fun (r βr s) (Ξ» _, Ξ± β Ξ²) := β¨Ξ» o, o.to_funβ©
initialize_simps_projections rel_hom (to_fun β apply)
theorem map_rel (f : r βr s) : β {a b}, r a b β s (f a) (f b) := f.map_rel'
@[simp] theorem coe_fn_mk (f : Ξ± β Ξ²) (o) :
(@rel_hom.mk _ _ r s f o : Ξ± β Ξ²) = f := rfl
@[simp] theorem coe_fn_to_fun (f : r βr s) : (f.to_fun : Ξ± β Ξ²) = f := rfl
/-- The map `coe_fn : (r βr s) β (Ξ± β Ξ²)` is injective. -/
theorem coe_fn_injective : @function.injective (r βr s) (Ξ± β Ξ²) coe_fn
| β¨fβ, oββ© β¨fβ, oββ© h := by { congr, exact h }
@[ext] theorem ext β¦f g : r βr sβ¦ (h : β x, f x = g x) : f = g :=
coe_fn_injective (funext h)
theorem ext_iff {f g : r βr s} : f = g β β x, f x = g x :=
β¨Ξ» h x, h βΈ rfl, Ξ» h, ext hβ©
/-- Identity map is a relation homomorphism. -/
@[refl, simps] protected def id (r : Ξ± β Ξ± β Prop) : r βr r :=
β¨Ξ» x, x, Ξ» a b x, xβ©
/-- Composition of two relation homomorphisms is a relation homomorphism. -/
@[trans, simps] protected def comp (g : s βr t) (f : r βr s) : r βr t :=
β¨Ξ» x, g (f x), Ξ» a b h, g.2 (f.2 h)β©
/-- A relation homomorphism is also a relation homomorphism between dual relations. -/
protected def swap (f : r βr s) : swap r βr swap s :=
β¨f, Ξ» a b, f.map_relβ©
/-- A function is a relation homomorphism from the preimage relation of `s` to `s`. -/
def preimage (f : Ξ± β Ξ²) (s : Ξ² β Ξ² β Prop) : f β»ΒΉ'o s βr s := β¨f, Ξ» a b, idβ©
protected theorem is_irrefl : β (f : r βr s) [is_irrefl Ξ² s], is_irrefl Ξ± r
| β¨f, oβ© β¨Hβ© := β¨Ξ» a h, H _ (o h)β©
protected theorem is_asymm : β (f : r βr s) [is_asymm Ξ² s], is_asymm Ξ± r
| β¨f, oβ© β¨Hβ© := β¨Ξ» a b hβ hβ, H _ _ (o hβ) (o hβ)β©
protected theorem acc (f : r βr s) (a : Ξ±) : acc s (f a) β acc r a :=
begin
generalize h : f a = b, intro ac,
induction ac with _ H IH generalizing a, subst h,
exact β¨_, Ξ» a' h, IH (f a') (f.map_rel h) _ rflβ©
end
protected theorem well_founded : β (f : r βr s) (h : well_founded s), well_founded r
| f β¨Hβ© := β¨Ξ» a, f.acc _ (H _)β©
lemma map_inf {Ξ± Ξ² : Type*} [semilattice_inf Ξ±] [linear_order Ξ²]
(a : ((<) : Ξ² β Ξ² β Prop) βr ((<) : Ξ± β Ξ± β Prop)) (m n : Ξ²) : a (m β n) = a m β a n :=
begin
symmetry, cases le_or_lt n m with h,
{ rw [inf_eq_right.mpr h, inf_eq_right], exact strict_mono.monotone (Ξ» x y, a.map_rel) h, },
{ rw [inf_eq_left.mpr (le_of_lt h), inf_eq_left], exact le_of_lt (a.map_rel h), },
end
lemma map_sup {Ξ± Ξ² : Type*} [semilattice_sup Ξ±] [linear_order Ξ²]
(a : ((>) : Ξ² β Ξ² β Prop) βr ((>) : Ξ± β Ξ± β Prop)) (m n : Ξ²) : a (m β n) = a m β a n :=
begin
symmetry, cases le_or_lt m n with h,
{ rw [sup_eq_right.mpr h, sup_eq_right], exact strict_mono.monotone (Ξ» x y, a.swap.map_rel) h, },
{ rw [sup_eq_left.mpr (le_of_lt h), sup_eq_left], exact le_of_lt (a.map_rel h), },
end
end rel_hom
/-- An increasing function is injective -/
lemma injective_of_increasing (r : Ξ± β Ξ± β Prop) (s : Ξ² β Ξ² β Prop) [is_trichotomous Ξ± r]
[is_irrefl Ξ² s] (f : Ξ± β Ξ²) (hf : β {x y}, r x y β s (f x) (f y)) : injective f :=
begin
intros x y hxy,
rcases trichotomous_of r x y with h | h | h,
have := hf h, rw hxy at this, exfalso, exact irrefl_of s (f y) this,
exact h,
have := hf h, rw hxy at this, exfalso, exact irrefl_of s (f y) this
end
/-- An increasing function is injective -/
lemma rel_hom.injective_of_increasing [is_trichotomous Ξ± r]
[is_irrefl Ξ² s] (f : r βr s) : injective f :=
injective_of_increasing r s f (Ξ» x y, f.map_rel)
theorem surjective.well_founded_iff {f : Ξ± β Ξ²} (hf : surjective f)
(o : β {a b}, r a b β s (f a) (f b)) : well_founded r β well_founded s :=
iff.intro (begin
apply rel_hom.well_founded,
refine rel_hom.mk _ _,
{exact classical.some hf.has_right_inverse},
intros a b h, apply o.2, convert h,
iterate 2 { apply classical.some_spec hf.has_right_inverse },
end) (rel_hom.well_founded β¨f, Ξ» _ _, o.1β©)
/-- A relation embedding with respect to a given pair of relations `r` and `s`
is an embedding `f : Ξ± βͺ Ξ²` such that `r a b β s (f a) (f b)`. -/
structure rel_embedding {Ξ± Ξ² : Type*} (r : Ξ± β Ξ± β Prop) (s : Ξ² β Ξ² β Prop) extends Ξ± βͺ Ξ² :=
(map_rel_iff' : β {a b}, s (to_embedding a) (to_embedding b) β r a b)
infix ` βͺr `:25 := rel_embedding
/-- An order embedding is an embedding `f : Ξ± βͺ Ξ²` such that `a β€ b β (f a) β€ (f b)`.
This definition is an abbreviation of `rel_embedding (β€) (β€)`. -/
abbreviation order_embedding (Ξ± Ξ² : Type*) [has_le Ξ±] [has_le Ξ²] :=
@rel_embedding Ξ± Ξ² (β€) (β€)
infix ` βͺo `:25 := order_embedding
/-- The induced relation on a subtype is an embedding under the natural inclusion. -/
definition subtype.rel_embedding {X : Type*} (r : X β X β Prop) (p : X β Prop) :
((subtype.val : subtype p β X) β»ΒΉ'o r) βͺr r :=
β¨embedding.subtype p, Ξ» x y, iff.rflβ©
theorem preimage_equivalence {Ξ± Ξ²} (f : Ξ± β Ξ²) {s : Ξ² β Ξ² β Prop}
(hs : equivalence s) : equivalence (f β»ΒΉ'o s) :=
β¨Ξ» a, hs.1 _, Ξ» a b h, hs.2.1 h, Ξ» a b c hβ hβ, hs.2.2 hβ hββ©
namespace rel_embedding
/-- A relation embedding is also a relation homomorphism -/
def to_rel_hom (f : r βͺr s) : (r βr s) :=
{ to_fun := f.to_embedding.to_fun,
map_rel' := Ξ» x y, (map_rel_iff' f).mpr }
instance : has_coe (r βͺr s) (r βr s) := β¨to_rel_homβ©
-- see Note [function coercion]
instance : has_coe_to_fun (r βͺr s) (Ξ» _, Ξ± β Ξ²) := β¨Ξ» o, o.to_embeddingβ©
/-- See Note [custom simps projection]. We need to specify this projection explicitly in this case,
because it is a composition of multiple projections. -/
def simps.apply (h : r βͺr s) : Ξ± β Ξ² := h
initialize_simps_projections rel_embedding (to_embedding_to_fun β apply, -to_embedding)
@[simp] lemma to_rel_hom_eq_coe (f : r βͺr s) : f.to_rel_hom = f := rfl
@[simp] lemma coe_coe_fn (f : r βͺr s) : ((f : r βr s) : Ξ± β Ξ²) = f := rfl
theorem injective (f : r βͺr s) : injective f := f.inj'
theorem map_rel_iff (f : r βͺr s) : β {a b}, s (f a) (f b) β r a b := f.map_rel_iff'
@[simp] theorem coe_fn_mk (f : Ξ± βͺ Ξ²) (o) :
(@rel_embedding.mk _ _ r s f o : Ξ± β Ξ²) = f := rfl
@[simp] theorem coe_fn_to_embedding (f : r βͺr s) : (f.to_embedding : Ξ± β Ξ²) = f := rfl
/-- The map `coe_fn : (r βͺr s) β (Ξ± β Ξ²)` is injective. -/
theorem coe_fn_injective : @function.injective (r βͺr s) (Ξ± β Ξ²) coe_fn
| β¨β¨fβ, hββ©, oββ© β¨β¨fβ, hββ©, oββ© h := by { congr, exact h }
@[ext] theorem ext β¦f g : r βͺr sβ¦ (h : β x, f x = g x) : f = g :=
coe_fn_injective (funext h)
theorem ext_iff {f g : r βͺr s} : f = g β β x, f x = g x :=
β¨Ξ» h x, h βΈ rfl, Ξ» h, ext hβ©
/-- Identity map is a relation embedding. -/
@[refl, simps] protected def refl (r : Ξ± β Ξ± β Prop) : r βͺr r :=
β¨embedding.refl _, Ξ» a b, iff.rflβ©
/-- Composition of two relation embeddings is a relation embedding. -/
@[trans] protected def trans (f : r βͺr s) (g : s βͺr t) : r βͺr t :=
β¨f.1.trans g.1, Ξ» a b, by simp [f.map_rel_iff, g.map_rel_iff]β©
instance (r : Ξ± β Ξ± β Prop) : inhabited (r βͺr r) := β¨rel_embedding.refl _β©
theorem trans_apply (f : r βͺr s) (g : s βͺr t) (a : Ξ±) : (f.trans g) a = g (f a) := rfl
@[simp] theorem coe_trans (f : r βͺr s) (g : s βͺr t) : β(f.trans g) = g β f := rfl
/-- A relation embedding is also a relation embedding between dual relations. -/
protected def swap (f : r βͺr s) : swap r βͺr swap s :=
β¨f.to_embedding, Ξ» a b, f.map_rel_iffβ©
/-- If `f` is injective, then it is a relation embedding from the
preimage relation of `s` to `s`. -/
def preimage (f : Ξ± βͺ Ξ²) (s : Ξ² β Ξ² β Prop) : f β»ΒΉ'o s βͺr s := β¨f, Ξ» a b, iff.rflβ©
theorem eq_preimage (f : r βͺr s) : r = f β»ΒΉ'o s :=
by { ext a b, exact f.map_rel_iff.symm }
protected theorem is_irrefl (f : r βͺr s) [is_irrefl Ξ² s] : is_irrefl Ξ± r :=
β¨Ξ» a, mt f.map_rel_iff.2 (irrefl (f a))β©
protected theorem is_refl (f : r βͺr s) [is_refl Ξ² s] : is_refl Ξ± r :=
β¨Ξ» a, f.map_rel_iff.1 $ refl _β©
protected theorem is_symm (f : r βͺr s) [is_symm Ξ² s] : is_symm Ξ± r :=
β¨Ξ» a b, imp_imp_imp f.map_rel_iff.2 f.map_rel_iff.1 symmβ©
protected theorem is_asymm (f : r βͺr s) [is_asymm Ξ² s] : is_asymm Ξ± r :=
β¨Ξ» a b hβ hβ, asymm (f.map_rel_iff.2 hβ) (f.map_rel_iff.2 hβ)β©
protected theorem is_antisymm : β (f : r βͺr s) [is_antisymm Ξ² s], is_antisymm Ξ± r
| β¨f, oβ© β¨Hβ© := β¨Ξ» a b hβ hβ, f.inj' (H _ _ (o.2 hβ) (o.2 hβ))β©
protected theorem is_trans : β (f : r βͺr s) [is_trans Ξ² s], is_trans Ξ± r
| β¨f, oβ© β¨Hβ© := β¨Ξ» a b c hβ hβ, o.1 (H _ _ _ (o.2 hβ) (o.2 hβ))β©
protected theorem is_total : β (f : r βͺr s) [is_total Ξ² s], is_total Ξ± r
| β¨f, oβ© β¨Hβ© := β¨Ξ» a b, (or_congr o o).1 (H _ _)β©
protected theorem is_preorder : β (f : r βͺr s) [is_preorder Ξ² s], is_preorder Ξ± r
| f H := by exactI {..f.is_refl, ..f.is_trans}
protected theorem is_partial_order : β (f : r βͺr s) [is_partial_order Ξ² s], is_partial_order Ξ± r
| f H := by exactI {..f.is_preorder, ..f.is_antisymm}
protected theorem is_linear_order : β (f : r βͺr s) [is_linear_order Ξ² s], is_linear_order Ξ± r
| f H := by exactI {..f.is_partial_order, ..f.is_total}
protected theorem is_strict_order : β (f : r βͺr s) [is_strict_order Ξ² s], is_strict_order Ξ± r
| f H := by exactI {..f.is_irrefl, ..f.is_trans}
protected theorem is_trichotomous : β (f : r βͺr s) [is_trichotomous Ξ² s], is_trichotomous Ξ± r
| β¨f, oβ© β¨Hβ© := β¨Ξ» a b, (or_congr o (or_congr f.inj'.eq_iff o)).1 (H _ _)β©
protected theorem is_strict_total_order' :
β (f : r βͺr s) [is_strict_total_order' Ξ² s], is_strict_total_order' Ξ± r
| f H := by exactI {..f.is_trichotomous, ..f.is_strict_order}
protected theorem acc (f : r βͺr s) (a : Ξ±) : acc s (f a) β acc r a :=
begin
generalize h : f a = b, intro ac,
induction ac with _ H IH generalizing a, subst h,
exact β¨_, Ξ» a' h, IH (f a') (f.map_rel_iff.2 h) _ rflβ©
end
protected theorem well_founded : β (f : r βͺr s) (h : well_founded s), well_founded r
| f β¨Hβ© := β¨Ξ» a, f.acc _ (H _)β©
protected theorem is_well_order : β (f : r βͺr s) [is_well_order Ξ² s], is_well_order Ξ± r
| f H := by exactI {wf := f.well_founded H.wf, ..f.is_strict_total_order'}
/--
To define an relation embedding from an antisymmetric relation `r` to a reflexive relation `s` it
suffices to give a function together with a proof that it satisfies `s (f a) (f b) β r a b`.
-/
def of_map_rel_iff (f : Ξ± β Ξ²) [is_antisymm Ξ± r] [is_refl Ξ² s]
(hf : β a b, s (f a) (f b) β r a b) : r βͺr s :=
{ to_fun := f,
inj' := Ξ» x y h, antisymm ((hf _ _).1 (h βΈ refl _)) ((hf _ _).1 (h βΈ refl _)),
map_rel_iff' := hf }
@[simp]
lemma of_map_rel_iff_coe (f : Ξ± β Ξ²) [is_antisymm Ξ± r] [is_refl Ξ² s]
(hf : β a b, s (f a) (f b) β r a b) :
β(of_map_rel_iff f hf : r βͺr s) = f :=
rfl
/-- It suffices to prove `f` is monotone between strict relations
to show it is a relation embedding. -/
def of_monotone [is_trichotomous Ξ± r] [is_asymm Ξ² s] (f : Ξ± β Ξ²)
(H : β a b, r a b β s (f a) (f b)) : r βͺr s :=
begin
haveI := @is_asymm.is_irrefl Ξ² s _,
refine β¨β¨f, Ξ» a b e, _β©, Ξ» a b, β¨Ξ» h, _, H _ _β©β©,
{ refine ((@trichotomous _ r _ a b).resolve_left _).resolve_right _;
exact Ξ» h, @irrefl _ s _ _ (by simpa [e] using H _ _ h) },
{ refine (@trichotomous _ r _ a b).resolve_right (or.rec (Ξ» e, _) (Ξ» h', _)),
{ subst e, exact irrefl _ h },
{ exact asymm (H _ _ h') h } }
end
@[simp] theorem of_monotone_coe [is_trichotomous Ξ± r] [is_asymm Ξ² s] (f : Ξ± β Ξ²) (H) :
(@of_monotone _ _ r s _ _ f H : Ξ± β Ξ²) = f := rfl
/-- Embeddings of partial orders that preserve `<` also preserve `β€`. -/
def order_embedding_of_lt_embedding [partial_order Ξ±] [partial_order Ξ²]
(f : ((<) : Ξ± β Ξ± β Prop) βͺr ((<) : Ξ² β Ξ² β Prop)) :
Ξ± βͺo Ξ² :=
{ map_rel_iff' := by { intros, simp [le_iff_lt_or_eq,f.map_rel_iff, f.injective.eq_iff] }, .. f }
@[simp]
lemma order_embedding_of_lt_embedding_apply [partial_order Ξ±] [partial_order Ξ²]
{f : ((<) : Ξ± β Ξ± β Prop) βͺr ((<) : Ξ² β Ξ² β Prop)} {x : Ξ±} :
order_embedding_of_lt_embedding f x = f x := rfl
end rel_embedding
namespace order_embedding
variables [preorder Ξ±] [preorder Ξ²] (f : Ξ± βͺo Ξ²)
/-- `<` is preserved by order embeddings of preorders. -/
def lt_embedding : ((<) : Ξ± β Ξ± β Prop) βͺr ((<) : Ξ² β Ξ² β Prop) :=
{ map_rel_iff' := by intros; simp [lt_iff_le_not_le, f.map_rel_iff], .. f }
@[simp] lemma lt_embedding_apply (x : Ξ±) : f.lt_embedding x = f x := rfl
@[simp] theorem le_iff_le {a b} : (f a) β€ (f b) β a β€ b := f.map_rel_iff
@[simp] theorem lt_iff_lt {a b} : f a < f b β a < b :=
f.lt_embedding.map_rel_iff
@[simp] lemma eq_iff_eq {a b} : f a = f b β a = b := f.injective.eq_iff
protected theorem monotone : monotone f := Ξ» x y, f.le_iff_le.2
protected theorem strict_mono : strict_mono f := Ξ» x y, f.lt_iff_lt.2
protected theorem acc (a : Ξ±) : acc (<) (f a) β acc (<) a :=
f.lt_embedding.acc a
protected theorem well_founded :
well_founded ((<) : Ξ² β Ξ² β Prop) β well_founded ((<) : Ξ± β Ξ± β Prop) :=
f.lt_embedding.well_founded
protected theorem is_well_order [is_well_order Ξ² (<)] : is_well_order Ξ± (<) :=
f.lt_embedding.is_well_order
/-- An order embedding is also an order embedding between dual orders. -/
protected def dual : order_dual Ξ± βͺo order_dual Ξ² :=
β¨f.to_embedding, Ξ» a b, f.map_rel_iffβ©
/--
To define an order embedding from a partial order to a preorder it suffices to give a function
together with a proof that it satisfies `f a β€ f b β a β€ b`.
-/
def of_map_le_iff {Ξ± Ξ²} [partial_order Ξ±] [preorder Ξ²] (f : Ξ± β Ξ²)
(hf : β a b, f a β€ f b β a β€ b) : Ξ± βͺo Ξ² :=
rel_embedding.of_map_rel_iff f hf
@[simp] lemma coe_of_map_le_iff {Ξ± Ξ²} [partial_order Ξ±] [preorder Ξ²] {f : Ξ± β Ξ²} (h) :
β(of_map_le_iff f h) = f := rfl
/-- A strictly monotone map from a linear order is an order embedding. --/
def of_strict_mono {Ξ± Ξ²} [linear_order Ξ±] [preorder Ξ²] (f : Ξ± β Ξ²)
(h : strict_mono f) : Ξ± βͺo Ξ² :=
of_map_le_iff f (Ξ» _ _, h.le_iff_le)
@[simp] lemma coe_of_strict_mono {Ξ± Ξ²} [linear_order Ξ±] [preorder Ξ²] {f : Ξ± β Ξ²}
(h : strict_mono f) : β(of_strict_mono f h) = f := rfl
/-- Embedding of a subtype into the ambient type as an `order_embedding`. -/
@[simps {fully_applied := ff}] def subtype (p : Ξ± β Prop) : subtype p βͺo Ξ± :=
β¨embedding.subtype p, Ξ» x y, iff.rflβ©
end order_embedding
/-- A relation isomorphism is an equivalence that is also a relation embedding. -/
structure rel_iso {Ξ± Ξ² : Type*} (r : Ξ± β Ξ± β Prop) (s : Ξ² β Ξ² β Prop) extends Ξ± β Ξ² :=
(map_rel_iff' : β {a b}, s (to_equiv a) (to_equiv b) β r a b)
infix ` βr `:25 := rel_iso
/-- An order isomorphism is an equivalence such that `a β€ b β (f a) β€ (f b)`.
This definition is an abbreviation of `rel_iso (β€) (β€)`. -/
abbreviation order_iso (Ξ± Ξ² : Type*) [has_le Ξ±] [has_le Ξ²] := @rel_iso Ξ± Ξ² (β€) (β€)
infix ` βo `:25 := order_iso
namespace rel_iso
/-- Convert an `rel_iso` to an `rel_embedding`. This function is also available as a coercion
but often it is easier to write `f.to_rel_embedding` than to write explicitly `r` and `s`
in the target type. -/
def to_rel_embedding (f : r βr s) : r βͺr s :=
β¨f.to_equiv.to_embedding, f.map_rel_iff'β©
instance : has_coe (r βr s) (r βͺr s) := β¨to_rel_embeddingβ©
-- see Note [function coercion]
instance : has_coe_to_fun (r βr s) (Ξ» _, Ξ± β Ξ²) := β¨Ξ» f, fβ©
@[simp] lemma to_rel_embedding_eq_coe (f : r βr s) : f.to_rel_embedding = f := rfl
@[simp] lemma coe_coe_fn (f : r βr s) : ((f : r βͺr s) : Ξ± β Ξ²) = f := rfl
theorem map_rel_iff (f : r βr s) : β {a b}, s (f a) (f b) β r a b := f.map_rel_iff'
@[simp] theorem coe_fn_mk (f : Ξ± β Ξ²) (o : β β¦a bβ¦, s (f a) (f b) β r a b) :
(rel_iso.mk f o : Ξ± β Ξ²) = f := rfl
@[simp] theorem coe_fn_to_equiv (f : r βr s) : (f.to_equiv : Ξ± β Ξ²) = f := rfl
theorem to_equiv_injective : injective (to_equiv : (r βr s) β Ξ± β Ξ²)
| β¨eβ, oββ© β¨eβ, oββ© h := by { congr, exact h }
/-- The map `coe_fn : (r βr s) β (Ξ± β Ξ²)` is injective. Lean fails to parse
`function.injective (Ξ» e : r βr s, (e : Ξ± β Ξ²))`, so we use a trick to say the same. -/
theorem coe_fn_injective : @function.injective (r βr s) (Ξ± β Ξ²) coe_fn :=
equiv.coe_fn_injective.comp to_equiv_injective
@[ext] theorem ext β¦f g : r βr sβ¦ (h : β x, f x = g x) : f = g :=
coe_fn_injective (funext h)
theorem ext_iff {f g : r βr s} : f = g β β x, f x = g x :=
β¨Ξ» h x, h βΈ rfl, Ξ» h, ext hβ©
/-- Inverse map of a relation isomorphism is a relation isomorphism. -/
@[symm] protected def symm (f : r βr s) : s βr r :=
β¨f.to_equiv.symm, Ξ» a b, by erw [β f.map_rel_iff, f.1.apply_symm_apply, f.1.apply_symm_apply]β©
/-- See Note [custom simps projection]. We need to specify this projection explicitly in this case,
because it is a composition of multiple projections. -/
def simps.apply (h : r βr s) : Ξ± β Ξ² := h
/-- See Note [custom simps projection]. -/
def simps.symm_apply (h : r βr s) : Ξ² β Ξ± := h.symm
initialize_simps_projections rel_iso
(to_equiv_to_fun β apply, to_equiv_inv_fun β symm_apply, -to_equiv)
/-- Identity map is a relation isomorphism. -/
@[refl, simps apply] protected def refl (r : Ξ± β Ξ± β Prop) : r βr r :=
β¨equiv.refl _, Ξ» a b, iff.rflβ©
/-- Composition of two relation isomorphisms is a relation isomorphism. -/
@[trans, simps apply] protected def trans (fβ : r βr s) (fβ : s βr t) : r βr t :=
β¨fβ.to_equiv.trans fβ.to_equiv, Ξ» a b, fβ.map_rel_iff.trans fβ.map_rel_iffβ©
instance (r : Ξ± β Ξ± β Prop) : inhabited (r βr r) := β¨rel_iso.refl _β©
@[simp] lemma default_def (r : Ξ± β Ξ± β Prop) : default (r βr r) = rel_iso.refl r := rfl
/-- a relation isomorphism is also a relation isomorphism between dual relations. -/
protected def swap (f : r βr s) : (swap r) βr (swap s) :=
β¨f.to_equiv, Ξ» _ _, f.map_rel_iffβ©
@[simp] theorem coe_fn_symm_mk (f o) : ((@rel_iso.mk _ _ r s f o).symm : Ξ² β Ξ±) = f.symm :=
rfl
@[simp] theorem apply_symm_apply (e : r βr s) (x : Ξ²) : e (e.symm x) = x :=
e.to_equiv.apply_symm_apply x
@[simp] theorem symm_apply_apply (e : r βr s) (x : Ξ±) : e.symm (e x) = x :=
e.to_equiv.symm_apply_apply x
theorem rel_symm_apply (e : r βr s) {x y} : r x (e.symm y) β s (e x) y :=
by rw [β e.map_rel_iff, e.apply_symm_apply]
theorem symm_apply_rel (e : r βr s) {x y} : r (e.symm x) y β s x (e y) :=
by rw [β e.map_rel_iff, e.apply_symm_apply]
protected lemma bijective (e : r βr s) : bijective e := e.to_equiv.bijective
protected lemma injective (e : r βr s) : injective e := e.to_equiv.injective
protected lemma surjective (e : r βr s) : surjective e := e.to_equiv.surjective
@[simp] lemma range_eq (e : r βr s) : set.range e = set.univ := e.surjective.range_eq
@[simp] lemma eq_iff_eq (f : r βr s) {a b} : f a = f b β a = b :=
f.injective.eq_iff
/-- Any equivalence lifts to a relation isomorphism between `s` and its preimage. -/
protected def preimage (f : Ξ± β Ξ²) (s : Ξ² β Ξ² β Prop) : f β»ΒΉ'o s βr s := β¨f, Ξ» a b, iff.rflβ©
/-- A surjective relation embedding is a relation isomorphism. -/
@[simps apply]
noncomputable def of_surjective (f : r βͺr s) (H : surjective f) : r βr s :=
β¨equiv.of_bijective f β¨f.injective, Hβ©, Ξ» a b, f.map_rel_iffβ©
/--
Given relation isomorphisms `rβ βr sβ` and `rβ βr sβ`, construct a relation isomorphism for the
lexicographic orders on the sum.
-/
def sum_lex_congr {Ξ±β Ξ±β Ξ²β Ξ²β rβ rβ sβ sβ}
(eβ : @rel_iso Ξ±β Ξ²β rβ sβ) (eβ : @rel_iso Ξ±β Ξ²β rβ sβ) :
sum.lex rβ rβ βr sum.lex sβ sβ :=
β¨equiv.sum_congr eβ.to_equiv eβ.to_equiv, Ξ» a b,
by cases eβ with f hf; cases eβ with g hg;
cases a; cases b; simp [hf, hg]β©
/--
Given relation isomorphisms `rβ βr sβ` and `rβ βr sβ`, construct a relation isomorphism for the
lexicographic orders on the product.
-/
def prod_lex_congr {Ξ±β Ξ±β Ξ²β Ξ²β rβ rβ sβ sβ}
(eβ : @rel_iso Ξ±β Ξ²β rβ sβ) (eβ : @rel_iso Ξ±β Ξ²β rβ sβ) :
prod.lex rβ rβ βr prod.lex sβ sβ :=
β¨equiv.prod_congr eβ.to_equiv eβ.to_equiv,
Ξ» a b, by simp [prod.lex_def, eβ.map_rel_iff, eβ.map_rel_iff]β©
instance : group (r βr r) :=
{ one := rel_iso.refl r,
mul := Ξ» fβ fβ, fβ.trans fβ,
inv := rel_iso.symm,
mul_assoc := Ξ» fβ fβ fβ, rfl,
one_mul := Ξ» f, ext $ Ξ» _, rfl,
mul_one := Ξ» f, ext $ Ξ» _, rfl,
mul_left_inv := Ξ» f, ext f.symm_apply_apply }
@[simp] lemma coe_one : β(1 : r βr r) = id := rfl
@[simp] lemma coe_mul (eβ eβ : r βr r) : β(eβ * eβ) = eβ β eβ := rfl
lemma mul_apply (eβ eβ : r βr r) (x : Ξ±) : (eβ * eβ) x = eβ (eβ x) := rfl
@[simp] lemma inv_apply_self (e : r βr r) (x) : eβ»ΒΉ (e x) = x := e.symm_apply_apply x
@[simp] lemma apply_inv_self (e : r βr r) (x) : e (eβ»ΒΉ x) = x := e.apply_symm_apply x
end rel_iso
namespace order_iso
section has_le
variables [has_le Ξ±] [has_le Ξ²] [has_le Ξ³]
/-- Reinterpret an order isomorphism as an order embedding. -/
def to_order_embedding (e : Ξ± βo Ξ²) : Ξ± βͺo Ξ² :=
e.to_rel_embedding
@[simp] lemma coe_to_order_embedding (e : Ξ± βo Ξ²) :
β(e.to_order_embedding) = e := rfl
protected lemma bijective (e : Ξ± βo Ξ²) : bijective e := e.to_equiv.bijective
protected lemma injective (e : Ξ± βo Ξ²) : injective e := e.to_equiv.injective
protected lemma surjective (e : Ξ± βo Ξ²) : surjective e := e.to_equiv.surjective
@[simp] lemma range_eq (e : Ξ± βo Ξ²) : set.range e = set.univ := e.surjective.range_eq
@[simp] lemma apply_eq_iff_eq (e : Ξ± βo Ξ²) {x y : Ξ±} : e x = e y β x = y :=
e.to_equiv.apply_eq_iff_eq
/-- Identity order isomorphism. -/
def refl (Ξ± : Type*) [has_le Ξ±] : Ξ± βo Ξ± := rel_iso.refl (β€)
@[simp] lemma coe_refl : β(refl Ξ±) = id := rfl
lemma refl_apply (x : Ξ±) : refl Ξ± x = x := rfl
@[simp] lemma refl_to_equiv : (refl Ξ±).to_equiv = equiv.refl Ξ± := rfl
/-- Inverse of an order isomorphism. -/
def symm (e : Ξ± βo Ξ²) : Ξ² βo Ξ± := e.symm
@[simp] lemma apply_symm_apply (e : Ξ± βo Ξ²) (x : Ξ²) : e (e.symm x) = x :=
e.to_equiv.apply_symm_apply x
@[simp] lemma symm_apply_apply (e : Ξ± βo Ξ²) (x : Ξ±) : e.symm (e x) = x :=
e.to_equiv.symm_apply_apply x
@[simp] lemma symm_refl (Ξ± : Type*) [has_le Ξ±] : (refl Ξ±).symm = refl Ξ± := rfl
lemma apply_eq_iff_eq_symm_apply (e : Ξ± βo Ξ²) (x : Ξ±) (y : Ξ²) : e x = y β x = e.symm y :=
e.to_equiv.apply_eq_iff_eq_symm_apply
theorem symm_apply_eq (e : Ξ± βo Ξ²) {x : Ξ±} {y : Ξ²} : e.symm y = x β y = e x :=
e.to_equiv.symm_apply_eq
@[simp] lemma symm_symm (e : Ξ± βo Ξ²) : e.symm.symm = e := by { ext, refl }
lemma symm_injective : injective (symm : (Ξ± βo Ξ²) β (Ξ² βo Ξ±)) :=
Ξ» e e' h, by rw [β e.symm_symm, h, e'.symm_symm]
@[simp] lemma to_equiv_symm (e : Ξ± βo Ξ²) : e.to_equiv.symm = e.symm.to_equiv := rfl
@[simp] lemma symm_image_image (e : Ξ± βo Ξ²) (s : set Ξ±) : e.symm '' (e '' s) = s :=
e.to_equiv.symm_image_image s
@[simp] lemma image_symm_image (e : Ξ± βo Ξ²) (s : set Ξ²) : e '' (e.symm '' s) = s :=
e.to_equiv.image_symm_image s
lemma image_eq_preimage (e : Ξ± βo Ξ²) (s : set Ξ±) : e '' s = e.symm β»ΒΉ' s :=
e.to_equiv.image_eq_preimage s
@[simp] lemma preimage_symm_preimage (e : Ξ± βo Ξ²) (s : set Ξ±) : e β»ΒΉ' (e.symm β»ΒΉ' s) = s :=
e.to_equiv.preimage_symm_preimage s
@[simp] lemma symm_preimage_preimage (e : Ξ± βo Ξ²) (s : set Ξ²) : e.symm β»ΒΉ' (e β»ΒΉ' s) = s :=
e.to_equiv.symm_preimage_preimage s
@[simp] lemma image_preimage (e : Ξ± βo Ξ²) (s : set Ξ²) : e '' (e β»ΒΉ' s) = s :=
e.to_equiv.image_preimage s
@[simp] lemma preimage_image (e : Ξ± βo Ξ²) (s : set Ξ±) : e β»ΒΉ' (e '' s) = s :=
e.to_equiv.preimage_image s
/-- Composition of two order isomorphisms is an order isomorphism. -/
@[trans] def trans (e : Ξ± βo Ξ²) (e' : Ξ² βo Ξ³) : Ξ± βo Ξ³ := e.trans e'
@[simp] lemma coe_trans (e : Ξ± βo Ξ²) (e' : Ξ² βo Ξ³) : β(e.trans e') = e' β e := rfl
lemma trans_apply (e : Ξ± βo Ξ²) (e' : Ξ² βo Ξ³) (x : Ξ±) : e.trans e' x = e' (e x) := rfl
@[simp] lemma refl_trans (e : Ξ± βo Ξ²) : (refl Ξ±).trans e = e := by { ext x, refl }
@[simp] lemma trans_refl (e : Ξ± βo Ξ²) : e.trans (refl Ξ²) = e := by { ext x, refl }
end has_le
open set
section le
variables [has_le Ξ±] [has_le Ξ²] [has_le Ξ³]
@[simp] lemma le_iff_le (e : Ξ± βo Ξ²) {x y : Ξ±} : e x β€ e y β x β€ y := e.map_rel_iff
lemma le_symm_apply (e : Ξ± βo Ξ²) {x : Ξ±} {y : Ξ²} : x β€ e.symm y β e x β€ y :=
e.rel_symm_apply
lemma symm_apply_le (e : Ξ± βo Ξ²) {x : Ξ±} {y : Ξ²} : e.symm y β€ x β y β€ e x :=
e.symm_apply_rel
end le
variables [preorder Ξ±] [preorder Ξ²] [preorder Ξ³]
protected lemma monotone (e : Ξ± βo Ξ²) : monotone e := e.to_order_embedding.monotone
protected lemma strict_mono (e : Ξ± βo Ξ²) : strict_mono e := e.to_order_embedding.strict_mono
@[simp] lemma lt_iff_lt (e : Ξ± βo Ξ²) {x y : Ξ±} : e x < e y β x < y :=
e.to_order_embedding.lt_iff_lt
/-- To show that `f : Ξ± β Ξ²`, `g : Ξ² β Ξ±` make up an order isomorphism of linear orders,
it suffices to prove `cmp a (g b) = cmp (f a) b`. --/
def of_cmp_eq_cmp {Ξ± Ξ²} [linear_order Ξ±] [linear_order Ξ²] (f : Ξ± β Ξ²) (g : Ξ² β Ξ±)
(h : β (a : Ξ±) (b : Ξ²), cmp a (g b) = cmp (f a) b) : Ξ± βo Ξ² :=
have gf : β (a : Ξ±), a = g (f a) := by { intro, rw [βcmp_eq_eq_iff, h, cmp_self_eq_eq] },
{ to_fun := f,
inv_fun := g,
left_inv := Ξ» a, (gf a).symm,
right_inv := by { intro, rw [βcmp_eq_eq_iff, βh, cmp_self_eq_eq] },
map_rel_iff' := by { intros, apply le_iff_le_of_cmp_eq_cmp, convert (h _ _).symm, apply gf } }
/-- Order isomorphism between two equal sets. -/
def set_congr (s t : set Ξ±) (h : s = t) : s βo t :=
{ to_equiv := equiv.set_congr h,
map_rel_iff' := Ξ» x y, iff.rfl }
/-- Order isomorphism between `univ : set Ξ±` and `Ξ±`. -/
def set.univ : (set.univ : set Ξ±) βo Ξ± :=
{ to_equiv := equiv.set.univ Ξ±,
map_rel_iff' := Ξ» x y, iff.rfl }
/-- Order isomorphism between `Ξ± β Ξ²` and `Ξ²`, where `Ξ±` has a unique element. -/
@[simps to_equiv apply] def fun_unique (Ξ± Ξ² : Type*) [unique Ξ±] [preorder Ξ²] :
(Ξ± β Ξ²) βo Ξ² :=
{ to_equiv := equiv.fun_unique Ξ± Ξ²,
map_rel_iff' := Ξ» f g, by simp [pi.le_def, unique.forall_iff] }
@[simp] lemma fun_unique_symm_apply {Ξ± Ξ² : Type*} [unique Ξ±] [preorder Ξ²] :
((fun_unique Ξ± Ξ²).symm : Ξ² β Ξ± β Ξ²) = function.const Ξ± := rfl
end order_iso
namespace equiv
variables [preorder Ξ±] [preorder Ξ²]
/-- If `e` is an equivalence with monotone forward and inverse maps, then `e` is an
order isomorphism. -/
def to_order_iso (e : Ξ± β Ξ²) (hβ : monotone e) (hβ : monotone e.symm) :
Ξ± βo Ξ² :=
β¨e, Ξ» x y, β¨Ξ» h, by simpa only [e.symm_apply_apply] using hβ h, Ξ» h, hβ hβ©β©
@[simp] lemma coe_to_order_iso (e : Ξ± β Ξ²) (hβ : monotone e) (hβ : monotone e.symm) :
β(e.to_order_iso hβ hβ) = e := rfl
@[simp] lemma to_order_iso_to_equiv (e : Ξ± β Ξ²) (hβ : monotone e) (hβ : monotone e.symm) :
(e.to_order_iso hβ hβ).to_equiv = e := rfl
end equiv
/-- If a function `f` is strictly monotone on a set `s`, then it defines an order isomorphism
between `s` and its image. -/
protected noncomputable def strict_mono_on.order_iso {Ξ± Ξ²} [linear_order Ξ±] [preorder Ξ²]
(f : Ξ± β Ξ²) (s : set Ξ±) (hf : strict_mono_on f s) :
s βo f '' s :=
{ to_equiv := hf.inj_on.bij_on_image.equiv _,
map_rel_iff' := Ξ» x y, hf.le_iff_le x.2 y.2 }
/-- A strictly monotone function from a linear order is an order isomorphism between its domain and
its range. -/
protected noncomputable def strict_mono.order_iso {Ξ± Ξ²} [linear_order Ξ±] [preorder Ξ²] (f : Ξ± β Ξ²)
(h_mono : strict_mono f) : Ξ± βo set.range f :=
{ to_equiv := equiv.of_injective f h_mono.injective,
map_rel_iff' := Ξ» a b, h_mono.le_iff_le }
/-- A strictly monotone surjective function from a linear order is an order isomorphism. -/
noncomputable def strict_mono.order_iso_of_surjective {Ξ± Ξ²} [linear_order Ξ±] [preorder Ξ²]
(f : Ξ± β Ξ²) (h_mono : strict_mono f) (h_surj : surjective f) : Ξ± βo Ξ² :=
(h_mono.order_iso f).trans $ (order_iso.set_congr _ _ h_surj.range_eq).trans order_iso.set.univ
/-- `subrel r p` is the inherited relation on a subset. -/
def subrel (r : Ξ± β Ξ± β Prop) (p : set Ξ±) : p β p β Prop :=
(coe : p β Ξ±) β»ΒΉ'o r
@[simp] theorem subrel_val (r : Ξ± β Ξ± β Prop) (p : set Ξ±)
{a b} : subrel r p a b β r a.1 b.1 := iff.rfl
namespace subrel
/-- The relation embedding from the inherited relation on a subset. -/
protected def rel_embedding (r : Ξ± β Ξ± β Prop) (p : set Ξ±) :
subrel r p βͺr r := β¨embedding.subtype _, Ξ» a b, iff.rflβ©
@[simp] theorem rel_embedding_apply (r : Ξ± β Ξ± β Prop) (p a) :
subrel.rel_embedding r p a = a.1 := rfl
instance (r : Ξ± β Ξ± β Prop) [is_well_order Ξ± r]
(p : set Ξ±) : is_well_order p (subrel r p) :=
rel_embedding.is_well_order (subrel.rel_embedding r p)
end subrel
/-- Restrict the codomain of a relation embedding. -/
def rel_embedding.cod_restrict (p : set Ξ²) (f : r βͺr s) (H : β a, f a β p) : r βͺr subrel s p :=
β¨f.to_embedding.cod_restrict p H, f.map_rel_iff'β©
@[simp] theorem rel_embedding.cod_restrict_apply (p) (f : r βͺr s) (H a) :
rel_embedding.cod_restrict p f H a = β¨f a, H aβ© := rfl
/-- An order isomorphism is also an order isomorphism between dual orders. -/
protected def order_iso.dual [has_le Ξ±] [has_le Ξ²] (f : Ξ± βo Ξ²) :
order_dual Ξ± βo order_dual Ξ² := β¨f.to_equiv, Ξ» _ _, f.map_rel_iffβ©
section lattice_isos
lemma order_iso.map_bot' [has_le Ξ±] [partial_order Ξ²] (f : Ξ± βo Ξ²) {x : Ξ±} {y : Ξ²}
(hx : β x', x β€ x') (hy : β y', y β€ y') : f x = y :=
by { refine le_antisymm _ (hy _), rw [β f.apply_symm_apply y, f.map_rel_iff], apply hx }
lemma order_iso.map_bot [has_le Ξ±] [partial_order Ξ²] [order_bot Ξ±] [order_bot Ξ²] (f : Ξ± βo Ξ²) :
f β₯ = β₯ :=
f.map_bot' (Ξ» _, bot_le) (Ξ» _, bot_le)
lemma order_iso.map_top' [has_le Ξ±] [partial_order Ξ²] (f : Ξ± βo Ξ²) {x : Ξ±} {y : Ξ²}
(hx : β x', x' β€ x) (hy : β y', y' β€ y) : f x = y :=
f.dual.map_bot' hx hy
lemma order_iso.map_top [has_le Ξ±] [partial_order Ξ²] [order_top Ξ±] [order_top Ξ²] (f : Ξ± βo Ξ²) :
f β€ = β€ :=
f.dual.map_bot
lemma order_embedding.map_inf_le [semilattice_inf Ξ±] [semilattice_inf Ξ²]
(f : Ξ± βͺo Ξ²) (x y : Ξ±) :
f (x β y) β€ f x β f y :=
f.monotone.map_inf_le x y
lemma order_iso.map_inf [semilattice_inf Ξ±] [semilattice_inf Ξ²]
(f : Ξ± βo Ξ²) (x y : Ξ±) :
f (x β y) = f x β f y :=
begin
refine (f.to_order_embedding.map_inf_le x y).antisymm _,
simpa [β f.symm.le_iff_le] using f.symm.to_order_embedding.map_inf_le (f x) (f y)
end
/-- Note that this goal could also be stated `(disjoint on f) a b` -/
lemma disjoint.map_order_iso [semilattice_inf_bot Ξ±] [semilattice_inf_bot Ξ²] {a b : Ξ±}
(f : Ξ± βo Ξ²) (ha : disjoint a b) : disjoint (f a) (f b) :=
begin
rw [disjoint, βf.map_inf, βf.map_bot],
exact f.monotone ha,
end
@[simp] lemma disjoint_map_order_iso_iff [semilattice_inf_bot Ξ±] [semilattice_inf_bot Ξ²] {a b : Ξ±}
(f : Ξ± βo Ξ²) : disjoint (f a) (f b) β disjoint a b :=
β¨Ξ» h, f.symm_apply_apply a βΈ f.symm_apply_apply b βΈ h.map_order_iso f.symm, Ξ» h, h.map_order_iso fβ©
lemma order_embedding.le_map_sup [semilattice_sup Ξ±] [semilattice_sup Ξ²]
(f : Ξ± βͺo Ξ²) (x y : Ξ±) :
f x β f y β€ f (x β y) :=
f.monotone.le_map_sup x y
lemma order_iso.map_sup [semilattice_sup Ξ±] [semilattice_sup Ξ²]
(f : Ξ± βo Ξ²) (x y : Ξ±) :
f (x β y) = f x β f y :=
f.dual.map_inf x y
section bounded_lattice
variables [bounded_lattice Ξ±] [bounded_lattice Ξ²] (f : Ξ± βo Ξ²)
include f
lemma order_iso.is_compl {x y : Ξ±} (h : is_compl x y) : is_compl (f x) (f y) :=
β¨by { rw [β f.map_bot, β f.map_inf, f.map_rel_iff], exact h.1 },
by { rw [β f.map_top, β f.map_sup, f.map_rel_iff], exact h.2 }β©
theorem order_iso.is_compl_iff {x y : Ξ±} :
is_compl x y β is_compl (f x) (f y) :=
β¨f.is_compl, Ξ» h, begin
rw [β f.symm_apply_apply x, β f.symm_apply_apply y],
exact f.symm.is_compl h,
endβ©
lemma order_iso.is_complemented
[is_complemented Ξ±] : is_complemented Ξ² :=
β¨Ξ» x, begin
obtain β¨y, hyβ© := exists_is_compl (f.symm x),
rw β f.symm_apply_apply y at hy,
refine β¨f y, f.symm.is_compl_iff.2 hyβ©,
endβ©
theorem order_iso.is_complemented_iff :
is_complemented Ξ± β is_complemented Ξ² :=
β¨by { introI, exact f.is_complemented }, by { introI, exact f.symm.is_complemented }β©
end bounded_lattice
end lattice_isos
|
99cf52574057fefad7e4db5b05008fd3a9da0251
|
22e97a5d648fc451e25a06c668dc03ac7ed7bc25
|
/src/order/fixed_points.lean
|
a403c99fdf957eb7bb904f22e3d08d0e0218a6dc
|
[
"Apache-2.0"
] |
permissive
|
keeferrowan/mathlib
|
f2818da875dbc7780830d09bd4c526b0764a4e50
|
aad2dfc40e8e6a7e258287a7c1580318e865817e
|
refs/heads/master
| 1,661,736,426,952
| 1,590,438,032,000
| 1,590,438,032,000
| 266,892,663
| 0
| 0
|
Apache-2.0
| 1,590,445,835,000
| 1,590,445,835,000
| null |
UTF-8
|
Lean
| false
| false
| 8,788
|
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, Kenny Lau
Fixed point construction on complete lattices.
-/
import order.complete_lattice
universes u v w
variables {Ξ± : Type u} {Ξ² : Type v} {Ξ³ : Type w}
/-- The set of fixed points of a self-map -/
def fixed_points (f : Ξ± β Ξ±) : set Ξ± := { x | f x = x }
section fixedpoint
variables [complete_lattice Ξ±] {f : Ξ± β Ξ±}
/-- Least fixed point of a monotone function -/
def lfp (f : Ξ± β Ξ±) : Ξ± := Inf {a | f a β€ a}
/-- Greatest fixed point of a monotone function -/
def gfp (f : Ξ± β Ξ±) : Ξ± := Sup {a | a β€ f a}
theorem lfp_le {a : Ξ±} (h : f a β€ a) : lfp f β€ a :=
Inf_le h
theorem le_lfp {a : Ξ±} (h : βb, f b β€ b β a β€ b) : a β€ lfp f :=
le_Inf h
theorem lfp_eq (m : monotone f) : lfp f = f (lfp f) :=
have f (lfp f) β€ lfp f,
from le_lfp $ assume b, assume h : f b β€ b, le_trans (m (lfp_le h)) h,
le_antisymm (lfp_le (m this)) this
theorem lfp_induct {p : Ξ± β Prop} (m : monotone f)
(step : βa, p a β a β€ lfp f β p (f a)) (sup : βs, (βaβs, p a) β p (Sup s)) :
p (lfp f) :=
let s := {a | a β€ lfp f β§ p a} in
have p_s : p (Sup s),
from sup s (assume a β¨_, hβ©, h),
have Sup s β€ lfp f,
from le_lfp $ assume a, assume h : f a β€ a, Sup_le $ assume b β¨b_le, _β©, le_trans b_le (lfp_le h),
have Sup s = lfp f,
from le_antisymm this $ lfp_le $ le_Sup
β¨le_trans (m this) $ ge_of_eq $ lfp_eq m, step _ p_s thisβ©,
this βΈ p_s
theorem monotone_lfp : monotone (@lfp Ξ± _) :=
assume f g, assume : f β€ g, le_lfp $ assume a, assume : g a β€ a, lfp_le $ le_trans (βΉf β€ gβΊ a) this
theorem le_gfp {a : Ξ±} (h : a β€ f a) : a β€ gfp f :=
le_Sup h
theorem gfp_le {a : Ξ±} (h : βb, b β€ f b β b β€ a) : gfp f β€ a :=
Sup_le h
theorem gfp_eq (m : monotone f) : gfp f = f (gfp f) :=
have gfp f β€ f (gfp f),
from gfp_le $ assume b, assume h : b β€ f b, le_trans h (m (le_gfp h)),
le_antisymm this (le_gfp (m this))
theorem gfp_induct {p : Ξ± β Prop} (m : monotone f)
(step : βa, p a β gfp f β€ a β p (f a)) (inf : βs, (βaβs, p a) β p (Inf s)) :
p (gfp f) :=
let s := {a | gfp f β€ a β§ p a} in
have p_s : p (Inf s),
from inf s (assume a β¨_, hβ©, h),
have gfp f β€ Inf s,
from gfp_le $ assume a, assume h : a β€ f a, le_Inf $ assume b β¨le_b, _β©, le_trans (le_gfp h) le_b,
have Inf s = gfp f,
from le_antisymm (le_gfp $ Inf_le
β¨le_trans (le_of_eq $ gfp_eq m) (m this), step _ p_s thisβ©) this,
this βΈ p_s
theorem monotone_gfp : monotone (@gfp Ξ± _) :=
assume f g, assume : f β€ g, gfp_le $ assume a, assume : a β€ f a, le_gfp $ le_trans this (βΉf β€ gβΊ a)
end fixedpoint
section fixedpoint_eqn
variables [complete_lattice Ξ±] [complete_lattice Ξ²] {f : Ξ² β Ξ±} {g : Ξ± β Ξ²}
-- Rolling rule
theorem lfp_comp (m_f : monotone f) (m_g : monotone g) : lfp (f β g) = f (lfp (g β f)) :=
le_antisymm
(lfp_le $ m_f $ ge_of_eq $ lfp_eq $ m_g.comp m_f)
(le_lfp $ assume a fg_le,
le_trans (m_f $ lfp_le $ show (g β f) (g a) β€ g a, from m_g fg_le) fg_le)
theorem gfp_comp (m_f : monotone f) (m_g : monotone g) : gfp (f β g) = f (gfp (g β f)) :=
le_antisymm
(gfp_le $ assume a fg_le,
le_trans fg_le $ m_f $ le_gfp $ show g a β€ (g β f) (g a), from m_g fg_le)
(le_gfp $ m_f $ le_of_eq $ gfp_eq $ m_g.comp m_f)
-- Diagonal rule
theorem lfp_lfp {h : Ξ± β Ξ± β Ξ±} (m : ββ¦a b c dβ¦, a β€ b β c β€ d β h a c β€ h b d) :
lfp (lfp β h) = lfp (Ξ»x, h x x) :=
let f := lfp (lfp β h) in
have f_eq : f = lfp (h f),
from lfp_eq $ monotone.comp monotone_lfp (assume a b h x, m h (le_refl _)) ,
le_antisymm
(lfp_le $ lfp_le $ ge_of_eq $ lfp_eq $ assume a b h, m h h)
(lfp_le $ ge_of_eq $
calc f = lfp (h f) : f_eq
... = h f (lfp (h f)) : lfp_eq $ assume a b h, m (le_refl _) h
... = h f f : congr_arg (h f) f_eq.symm)
theorem gfp_gfp {h : Ξ± β Ξ± β Ξ±} (m : ββ¦a b c dβ¦, a β€ b β c β€ d β h a c β€ h b d) :
gfp (gfp β h) = gfp (Ξ»x, h x x) :=
let f := gfp (gfp β h) in
have f_eq : f = gfp (h f),
from gfp_eq $ monotone.comp monotone_gfp (assume a b h x, m h (le_refl _)),
le_antisymm
(le_gfp $ le_of_eq $
calc f = gfp (h f) : f_eq
... = h f (gfp (h f)) : gfp_eq $ assume a b h, m (le_refl _) h
... = h f f : congr_arg (h f) f_eq.symm)
(le_gfp $ le_gfp $ le_of_eq $ gfp_eq $ assume a b h, m h h)
end fixedpoint_eqn
/- The complete lattice of fixed points of a function f -/
namespace fixed_points
variables [complete_lattice Ξ±] (f : Ξ± β Ξ±) (hf : monotone f)
def prev (x : Ξ±) : Ξ± := gfp (Ξ» z, x β f z)
def next (x : Ξ±) : Ξ± := lfp (Ξ» z, x β f z)
variable {f}
theorem prev_le {x : Ξ±} : prev f x β€ x := gfp_le $ Ξ» z hz, le_trans hz inf_le_left
lemma prev_eq (hf : monotone f) {a : Ξ±} (h : f a β€ a) : prev f a = f (prev f a) :=
calc prev f a = a β f (prev f a) :
gfp_eq $ show monotone (Ξ»z, a β f z), from assume x y h, inf_le_inf_left _ (hf h)
... = f (prev f a) :
inf_of_le_right $ le_trans (hf prev_le) h
def prev_fixed (hf : monotone f) (a : Ξ±) (h : f a β€ a) : fixed_points f :=
β¨prev f a, (prev_eq hf h).symmβ©
theorem next_le {x : Ξ±} : x β€ next f x := le_lfp $ Ξ» z hz, le_trans le_sup_left hz
lemma next_eq (hf : monotone f) {a : Ξ±} (h : a β€ f a) : next f a = f (next f a) :=
calc next f a = a β f (next f a) :
lfp_eq $ show monotone (Ξ»z, a β f z), from assume x y h, sup_le_sup_left (hf h) _
... = f (next f a) :
sup_of_le_right $ le_trans h (hf next_le)
def next_fixed (hf : monotone f) (a : Ξ±) (h : a β€ f a) : fixed_points f :=
β¨next f a, (next_eq hf h).symmβ©
variable f
theorem sup_le_f_of_fixed_points (x y : fixed_points f) : x.1 β y.1 β€ f (x.1 β y.1) :=
sup_le
(x.2 βΈ (hf $ show x.1 β€ f x.1 β y.1, from x.2.symm βΈ le_sup_left))
(y.2 βΈ (hf $ show y.1 β€ x.1 β f y.1, from y.2.symm βΈ le_sup_right))
theorem f_le_inf_of_fixed_points (x y : fixed_points f) : f (x.1 β y.1) β€ x.1 β y.1 :=
le_inf
(x.2 βΈ (hf $ show f (x.1) β y.1 β€ x.1, from x.2.symm βΈ inf_le_left))
(y.2 βΈ (hf $ show x.1 β f (y.1) β€ y.1, from y.2.symm βΈ inf_le_right))
theorem Sup_le_f_of_fixed_points (A : set Ξ±) (HA : A β fixed_points f) : Sup A β€ f (Sup A) :=
Sup_le $ Ξ» x hxA, (HA hxA) βΈ (hf $ le_Sup hxA)
theorem f_le_Inf_of_fixed_points (A : set Ξ±) (HA : A β fixed_points f) : f (Inf A) β€ Inf A :=
le_Inf $ Ξ» x hxA, (HA hxA) βΈ (hf $ Inf_le hxA)
/-- The fixed points of `f` form a complete lattice.
This cannot be an instance, since it depends on the monotonicity of `f`. -/
protected def complete_lattice : complete_lattice (fixed_points f) :=
{ le := Ξ»x y, x.1 β€ y.1,
le_refl := Ξ» x, le_refl x,
le_trans := Ξ» x y z, le_trans,
le_antisymm := Ξ» x y hx hy, subtype.eq $ le_antisymm hx hy,
sup := Ξ» x y, next_fixed hf (x.1 β y.1) (sup_le_f_of_fixed_points f hf x y),
le_sup_left := Ξ» x y, show x.1 β€ _, from le_trans le_sup_left next_le,
le_sup_right := Ξ» x y, show y.1 β€ _, from le_trans le_sup_right next_le,
sup_le := Ξ» x y z hxz hyz, lfp_le $ sup_le (sup_le hxz hyz) (z.2.symm βΈ le_refl z.1),
inf := Ξ» x y, prev_fixed hf (x.1 β y.1) (f_le_inf_of_fixed_points f hf x y),
inf_le_left := Ξ» x y, show _ β€ x.1, from le_trans prev_le inf_le_left,
inf_le_right := Ξ» x y, show _ β€ y.1, from le_trans prev_le inf_le_right,
le_inf := Ξ» x y z hxy hxz, le_gfp $ le_inf (le_inf hxy hxz) (x.2.symm βΈ le_refl x),
top := prev_fixed hf β€ le_top,
le_top := Ξ» β¨x, Hβ©, le_gfp $ le_inf le_top (H.symm βΈ le_refl x),
bot := next_fixed hf β₯ bot_le,
bot_le := Ξ» β¨x, Hβ©, lfp_le $ sup_le bot_le (H.symm βΈ le_refl x),
Sup := Ξ» A, next_fixed hf (Sup $ subtype.val '' A)
(Sup_le_f_of_fixed_points f hf (subtype.val '' A) (Ξ» z β¨x, hxβ©, hx.2 βΈ x.2)),
le_Sup := Ξ» A x hxA, show x.1 β€ _, from le_trans
(le_Sup $ show x.1 β subtype.val '' A, from β¨x, hxA, rflβ©)
next_le,
Sup_le := Ξ» A x Hx, lfp_le $ sup_le (Sup_le $ Ξ» z β¨y, hyA, hyzβ©, hyz βΈ Hx y hyA) (x.2.symm βΈ le_refl x),
Inf := Ξ» A, prev_fixed hf (Inf $ subtype.val '' A)
(f_le_Inf_of_fixed_points f hf (subtype.val '' A) (Ξ» z β¨x, hxβ©, hx.2 βΈ x.2)),
le_Inf := Ξ» A x Hx, le_gfp $ le_inf (le_Inf $ Ξ» z β¨y, hyA, hyzβ©, hyz βΈ Hx y hyA) (x.2.symm βΈ le_refl x.1),
Inf_le := Ξ» A x hxA, show _ β€ x.1, from le_trans
prev_le
(Inf_le $ show x.1 β subtype.val '' A, from β¨x, hxA, rflβ©) }
end fixed_points
|
095cfcb81fa34a950728755714f10b5154dec78c
|
d406927ab5617694ec9ea7001f101b7c9e3d9702
|
/src/algebra/order/to_interval_mod.lean
|
2f0e79874c36a25cfe0c1cd2b75951401a233b33
|
[
"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
| 22,615
|
lean
|
/-
Copyright (c) 2022 Joseph Myers. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joseph Myers
-/
import algebra.module.basic
import algebra.order.archimedean
import algebra.periodic
import group_theory.quotient_group
/-!
# Reducing to an interval modulo its length
This file defines operations that reduce a number (in an `archimedean`
`linear_ordered_add_comm_group`) to a number in a given interval, modulo the length of that
interval.
## Main definitions
* `to_Ico_div a hb x` (where `hb : 0 < b`): The unique integer such that this multiple of `b`,
added to `x`, is in `Ico a (a + b)`.
* `to_Ico_mod a hb x` (where `hb : 0 < b`): Reduce `x` to the interval `Ico a (a + b)`.
* `to_Ioc_div a hb x` (where `hb : 0 < b`): The unique integer such that this multiple of `b`,
added to `x`, is in `Ioc a (a + b)`.
* `to_Ioc_mod a hb x` (where `hb : 0 < b`): Reduce `x` to the interval `Ioc a (a + b)`.
-/
noncomputable theory
section linear_ordered_add_comm_group
variables {Ξ± : Type*} [linear_ordered_add_comm_group Ξ±] [archimedean Ξ±]
/-- The unique integer such that this multiple of `b`, added to `x`, is in `Ico a (a + b)`. -/
def to_Ico_div (a : Ξ±) {b : Ξ±} (hb : 0 < b) (x : Ξ±) : β€ :=
(exists_unique_add_zsmul_mem_Ico hb x a).some
lemma add_to_Ico_div_zsmul_mem_Ico (a : Ξ±) {b : Ξ±} (hb : 0 < b) (x : Ξ±) :
x + to_Ico_div a hb x β’ b β set.Ico a (a + b) :=
(exists_unique_add_zsmul_mem_Ico hb x a).some_spec.1
lemma eq_to_Ico_div_of_add_zsmul_mem_Ico {a b x : Ξ±} (hb : 0 < b) {y : β€}
(hy : x + y β’ b β set.Ico a (a + b)) : y = to_Ico_div a hb x :=
(exists_unique_add_zsmul_mem_Ico hb x a).some_spec.2 y hy
/-- The unique integer such that this multiple of `b`, added to `x`, is in `Ioc a (a + b)`. -/
def to_Ioc_div (a : Ξ±) {b : Ξ±} (hb : 0 < b) (x : Ξ±) : β€ :=
(exists_unique_add_zsmul_mem_Ioc hb x a).some
lemma add_to_Ioc_div_zsmul_mem_Ioc (a : Ξ±) {b : Ξ±} (hb : 0 < b) (x : Ξ±) :
x + to_Ioc_div a hb x β’ b β set.Ioc a (a + b) :=
(exists_unique_add_zsmul_mem_Ioc hb x a).some_spec.1
lemma eq_to_Ioc_div_of_add_zsmul_mem_Ioc {a b x : Ξ±} (hb : 0 < b) {y : β€}
(hy : x + y β’ b β set.Ioc a (a + b)) : y = to_Ioc_div a hb x :=
(exists_unique_add_zsmul_mem_Ioc hb x a).some_spec.2 y hy
/-- Reduce `x` to the interval `Ico a (a + b)`. -/
def to_Ico_mod (a : Ξ±) {b : Ξ±} (hb : 0 < b) (x : Ξ±) : Ξ± := x + to_Ico_div a hb x β’ b
/-- Reduce `x` to the interval `Ioc a (a + b)`. -/
def to_Ioc_mod (a : Ξ±) {b : Ξ±} (hb : 0 < b) (x : Ξ±) : Ξ± := x + to_Ioc_div a hb x β’ b
lemma to_Ico_mod_mem_Ico (a : Ξ±) {b : Ξ±} (hb : 0 < b) (x : Ξ±) :
to_Ico_mod a hb x β set.Ico a (a + b) :=
add_to_Ico_div_zsmul_mem_Ico a hb x
lemma to_Ico_mod_mem_Ico' {b : Ξ±} (hb : 0 < b) (x : Ξ±) :
to_Ico_mod 0 hb x β set.Ico 0 b :=
by { convert to_Ico_mod_mem_Ico 0 hb x, exact (zero_add b).symm, }
lemma to_Ioc_mod_mem_Ioc (a : Ξ±) {b : Ξ±} (hb : 0 < b) (x : Ξ±) :
to_Ioc_mod a hb x β set.Ioc a (a + b) :=
add_to_Ioc_div_zsmul_mem_Ioc a hb x
lemma left_le_to_Ico_mod (a : Ξ±) {b : Ξ±} (hb : 0 < b) (x : Ξ±) : a β€ to_Ico_mod a hb x :=
(set.mem_Ico.1 (to_Ico_mod_mem_Ico a hb x)).1
lemma left_lt_to_Ioc_mod (a : Ξ±) {b : Ξ±} (hb : 0 < b) (x : Ξ±) : a < to_Ioc_mod a hb x :=
(set.mem_Ioc.1 (to_Ioc_mod_mem_Ioc a hb x)).1
lemma to_Ico_mod_lt_right (a : Ξ±) {b : Ξ±} (hb : 0 < b) (x : Ξ±) : to_Ico_mod a hb x < a + b :=
(set.mem_Ico.1 (to_Ico_mod_mem_Ico a hb x)).2
lemma to_Ioc_mod_le_right (a : Ξ±) {b : Ξ±} (hb : 0 < b) (x : Ξ±) : to_Ioc_mod a hb x β€ a + b :=
(set.mem_Ioc.1 (to_Ioc_mod_mem_Ioc a hb x)).2
@[simp] lemma self_add_to_Ico_div_zsmul (a : Ξ±) {b : Ξ±} (hb : 0 < b) (x : Ξ±) :
x + to_Ico_div a hb x β’ b = to_Ico_mod a hb x :=
rfl
@[simp] lemma self_add_to_Ioc_div_zsmul (a : Ξ±) {b : Ξ±} (hb : 0 < b) (x : Ξ±) :
x + to_Ioc_div a hb x β’ b = to_Ioc_mod a hb x :=
rfl
@[simp] lemma to_Ico_div_zsmul_add_self (a : Ξ±) {b : Ξ±} (hb : 0 < b) (x : Ξ±) :
to_Ico_div a hb x β’ b + x = to_Ico_mod a hb x :=
by rw [add_comm, to_Ico_mod]
@[simp] lemma to_Ioc_div_zsmul_add_self (a : Ξ±) {b : Ξ±} (hb : 0 < b) (x : Ξ±) :
to_Ioc_div a hb x β’ b + x = to_Ioc_mod a hb x :=
by rw [add_comm, to_Ioc_mod]
@[simp] lemma to_Ico_mod_sub_self (a : Ξ±) {b : Ξ±} (hb : 0 < b) (x : Ξ±) :
to_Ico_mod a hb x - x = to_Ico_div a hb x β’ b :=
by rw [to_Ico_mod, add_sub_cancel']
@[simp] lemma to_Ioc_mod_sub_self (a : Ξ±) {b : Ξ±} (hb : 0 < b) (x : Ξ±) :
to_Ioc_mod a hb x - x = to_Ioc_div a hb x β’ b :=
by rw [to_Ioc_mod, add_sub_cancel']
@[simp] lemma self_sub_to_Ico_mod (a : Ξ±) {b : Ξ±} (hb : 0 < b) (x : Ξ±) :
x - to_Ico_mod a hb x = -to_Ico_div a hb x β’ b :=
by rw [to_Ico_mod, sub_add_cancel', neg_smul]
@[simp] lemma self_sub_to_Ioc_mod (a : Ξ±) {b : Ξ±} (hb : 0 < b) (x : Ξ±) :
x - to_Ioc_mod a hb x = -to_Ioc_div a hb x β’ b :=
by rw [to_Ioc_mod, sub_add_cancel', neg_smul]
@[simp] lemma to_Ico_mod_sub_to_Ico_div_zsmul (a : Ξ±) {b : Ξ±} (hb : 0 < b) (x : Ξ±) :
to_Ico_mod a hb x - to_Ico_div a hb x β’ b = x :=
by rw [to_Ico_mod, add_sub_cancel]
@[simp] lemma to_Ioc_mod_sub_to_Ioc_div_zsmul (a : Ξ±) {b : Ξ±} (hb : 0 < b) (x : Ξ±) :
to_Ioc_mod a hb x - to_Ioc_div a hb x β’ b = x :=
by rw [to_Ioc_mod, add_sub_cancel]
@[simp] lemma to_Ico_div_zsmul_sub_to_Ico_mod (a : Ξ±) {b : Ξ±} (hb : 0 < b) (x : Ξ±) :
to_Ico_div a hb x β’ b - to_Ico_mod a hb x = -x :=
by rw [βneg_sub, to_Ico_mod_sub_to_Ico_div_zsmul]
@[simp] lemma to_Ioc_div_zsmul_sub_to_Ioc_mod (a : Ξ±) {b : Ξ±} (hb : 0 < b) (x : Ξ±) :
to_Ioc_div a hb x β’ b - to_Ioc_mod a hb x = -x :=
by rw [βneg_sub, to_Ioc_mod_sub_to_Ioc_div_zsmul]
lemma to_Ico_mod_eq_iff {a b x y : Ξ±} (hb : 0 < b) :
to_Ico_mod a hb x = y β a β€ y β§ y < a + b β§ β z : β€, y - x = z β’ b :=
begin
refine β¨Ξ» h, β¨h βΈ left_le_to_Ico_mod a hb x,
h βΈ to_Ico_mod_lt_right a hb x,
to_Ico_div a hb x,
h βΈ to_Ico_mod_sub_self a hb xβ©,
Ξ» h, _β©,
rcases h with β¨ha, hab, z, hzβ©,
rw sub_eq_iff_eq_add' at hz,
subst hz,
rw eq_to_Ico_div_of_add_zsmul_mem_Ico hb (set.mem_Ico.2 β¨ha, habβ©),
refl
end
lemma to_Ioc_mod_eq_iff {a b x y : Ξ±} (hb : 0 < b) :
to_Ioc_mod a hb x = y β a < y β§ y β€ a + b β§ β z : β€, y - x = z β’ b :=
begin
refine β¨Ξ» h, β¨h βΈ left_lt_to_Ioc_mod a hb x,
h βΈ to_Ioc_mod_le_right a hb x,
to_Ioc_div a hb x,
h βΈ to_Ioc_mod_sub_self a hb xβ©,
Ξ» h, _β©,
rcases h with β¨ha, hab, z, hzβ©,
rw sub_eq_iff_eq_add' at hz,
subst hz,
rw eq_to_Ioc_div_of_add_zsmul_mem_Ioc hb (set.mem_Ioc.2 β¨ha, habβ©),
refl
end
@[simp] lemma to_Ico_div_apply_left (a : Ξ±) {b : Ξ±} (hb : 0 < b) : to_Ico_div a hb a = 0 :=
begin
refine (eq_to_Ico_div_of_add_zsmul_mem_Ico hb _).symm,
simp [hb]
end
@[simp] lemma to_Ioc_div_apply_left (a : Ξ±) {b : Ξ±} (hb : 0 < b) : to_Ioc_div a hb a = 1 :=
begin
refine (eq_to_Ioc_div_of_add_zsmul_mem_Ioc hb _).symm,
simp [hb]
end
@[simp] lemma to_Ico_mod_apply_left (a : Ξ±) {b : Ξ±} (hb : 0 < b) : to_Ico_mod a hb a = a :=
begin
rw to_Ico_mod_eq_iff hb,
refine β¨le_refl _, lt_add_of_pos_right _ hb, 0, _β©,
simp
end
@[simp] lemma to_Ioc_mod_apply_left (a : Ξ±) {b : Ξ±} (hb : 0 < b) : to_Ioc_mod a hb a = a + b :=
begin
rw to_Ioc_mod_eq_iff hb,
refine β¨lt_add_of_pos_right _ hb, le_refl _, 1, _β©,
simp
end
lemma to_Ico_div_apply_right (a : Ξ±) {b : Ξ±} (hb : 0 < b) :
to_Ico_div a hb (a + b) = -1 :=
begin
refine (eq_to_Ico_div_of_add_zsmul_mem_Ico hb _).symm,
simp [hb]
end
lemma to_Ioc_div_apply_right (a : Ξ±) {b : Ξ±} (hb : 0 < b) :
to_Ioc_div a hb (a + b) = 0 :=
begin
refine (eq_to_Ioc_div_of_add_zsmul_mem_Ioc hb _).symm,
simp [hb]
end
lemma to_Ico_mod_apply_right (a : Ξ±) {b : Ξ±} (hb : 0 < b) : to_Ico_mod a hb (a + b) = a :=
begin
rw to_Ico_mod_eq_iff hb,
refine β¨le_refl _, lt_add_of_pos_right _ hb, -1, _β©,
simp
end
lemma to_Ioc_mod_apply_right (a : Ξ±) {b : Ξ±} (hb : 0 < b) :
to_Ioc_mod a hb (a + b) = a + b :=
begin
rw to_Ioc_mod_eq_iff hb,
refine β¨lt_add_of_pos_right _ hb, le_refl _, 0, _β©,
simp
end
@[simp] lemma to_Ico_div_add_zsmul (a : Ξ±) {b : Ξ±} (hb : 0 < b) (x : Ξ±) (m : β€) :
to_Ico_div a hb (x + m β’ b) = to_Ico_div a hb x - m :=
begin
refine (eq_to_Ico_div_of_add_zsmul_mem_Ico hb _).symm,
convert add_to_Ico_div_zsmul_mem_Ico a hb x using 1,
simp [sub_smul]
end
@[simp] lemma to_Ioc_div_add_zsmul (a : Ξ±) {b : Ξ±} (hb : 0 < b) (x : Ξ±) (m : β€) :
to_Ioc_div a hb (x + m β’ b) = to_Ioc_div a hb x - m :=
begin
refine (eq_to_Ioc_div_of_add_zsmul_mem_Ioc hb _).symm,
convert add_to_Ioc_div_zsmul_mem_Ioc a hb x using 1,
simp [sub_smul]
end
@[simp] lemma to_Ico_div_zsmul_add (a : Ξ±) {b : Ξ±} (hb : 0 < b) (x : Ξ±) (m : β€) :
to_Ico_div a hb (m β’ b + x) = to_Ico_div a hb x - m :=
by rw [add_comm, to_Ico_div_add_zsmul]
@[simp] lemma to_Ioc_div_zsmul_add (a : Ξ±) {b : Ξ±} (hb : 0 < b) (x : Ξ±) (m : β€) :
to_Ioc_div a hb (m β’ b + x) = to_Ioc_div a hb x - m :=
by rw [add_comm, to_Ioc_div_add_zsmul]
@[simp] lemma to_Ico_div_sub_zsmul (a : Ξ±) {b : Ξ±} (hb : 0 < b) (x : Ξ±) (m : β€) :
to_Ico_div a hb (x - m β’ b) = to_Ico_div a hb x + m :=
by rw [sub_eq_add_neg, βneg_smul, to_Ico_div_add_zsmul, sub_neg_eq_add]
@[simp] lemma to_Ioc_div_sub_zsmul (a : Ξ±) {b : Ξ±} (hb : 0 < b) (x : Ξ±) (m : β€) :
to_Ioc_div a hb (x - m β’ b) = to_Ioc_div a hb x + m :=
by rw [sub_eq_add_neg, βneg_smul, to_Ioc_div_add_zsmul, sub_neg_eq_add]
@[simp] lemma to_Ico_div_add_right (a : Ξ±) {b : Ξ±} (hb : 0 < b) (x : Ξ±) :
to_Ico_div a hb (x + b) = to_Ico_div a hb x - 1 :=
begin
convert to_Ico_div_add_zsmul a hb x 1,
exact (one_zsmul _).symm
end
@[simp] lemma to_Ioc_div_add_right (a : Ξ±) {b : Ξ±} (hb : 0 < b) (x : Ξ±) :
to_Ioc_div a hb (x + b) = to_Ioc_div a hb x - 1 :=
begin
convert to_Ioc_div_add_zsmul a hb x 1,
exact (one_zsmul _).symm
end
@[simp] lemma to_Ico_div_add_left (a : Ξ±) {b : Ξ±} (hb : 0 < b) (x : Ξ±) :
to_Ico_div a hb (b + x) = to_Ico_div a hb x - 1 :=
by rw [add_comm, to_Ico_div_add_right]
@[simp] lemma to_Ioc_div_add_left (a : Ξ±) {b : Ξ±} (hb : 0 < b) (x : Ξ±) :
to_Ioc_div a hb (b + x) = to_Ioc_div a hb x - 1 :=
by rw [add_comm, to_Ioc_div_add_right]
@[simp] lemma to_Ico_div_sub (a : Ξ±) {b : Ξ±} (hb : 0 < b) (x : Ξ±) :
to_Ico_div a hb (x - b) = to_Ico_div a hb x + 1 :=
begin
convert to_Ico_div_sub_zsmul a hb x 1,
exact (one_zsmul _).symm
end
@[simp] lemma to_Ioc_div_sub (a : Ξ±) {b : Ξ±} (hb : 0 < b) (x : Ξ±) :
to_Ioc_div a hb (x - b) = to_Ioc_div a hb x + 1 :=
begin
convert to_Ioc_div_sub_zsmul a hb x 1,
exact (one_zsmul _).symm
end
lemma to_Ico_div_sub' (a : Ξ±) {b : Ξ±} (hb : 0 < b) (x y : Ξ±) :
to_Ico_div a hb (x - y) = to_Ico_div (a + y) hb x :=
begin
rw eq_comm,
apply eq_to_Ico_div_of_add_zsmul_mem_Ico,
rw sub_add_eq_add_sub,
obtain β¨hc, hoβ© := add_to_Ico_div_zsmul_mem_Ico (a + y) hb x,
rw add_right_comm at ho,
exact β¨le_sub_iff_add_le.mpr hc, sub_lt_iff_lt_add.mpr hoβ©,
end
lemma to_Ioc_div_sub' (a : Ξ±) {b : Ξ±} (hb : 0 < b) (x y : Ξ±) :
to_Ioc_div a hb (x - y) = to_Ioc_div (a + y) hb x :=
begin
rw eq_comm,
apply eq_to_Ioc_div_of_add_zsmul_mem_Ioc,
rw sub_add_eq_add_sub,
obtain β¨ho, hcβ© := add_to_Ioc_div_zsmul_mem_Ioc (a + y) hb x,
rw add_right_comm at hc,
exact β¨lt_sub_iff_add_lt.mpr ho, sub_le_iff_le_add.mpr hcβ©,
end
lemma to_Ico_div_add_right' (a : Ξ±) {b : Ξ±} (hb : 0 < b) (x y : Ξ±) :
to_Ico_div a hb (x + y) = to_Ico_div (a - y) hb x :=
by rw [βsub_neg_eq_add, to_Ico_div_sub', sub_eq_add_neg]
lemma to_Ioc_div_add_right' (a : Ξ±) {b : Ξ±} (hb : 0 < b) (x y : Ξ±) :
to_Ioc_div a hb (x + y) = to_Ioc_div (a - y) hb x :=
by rw [βsub_neg_eq_add, to_Ioc_div_sub', sub_eq_add_neg]
lemma to_Ico_div_neg (a : Ξ±) {b : Ξ±} (hb : 0 < b) (x : Ξ±) :
to_Ico_div a hb (-x) = 1 - to_Ioc_div (-a) hb x :=
begin
suffices : to_Ico_div a hb (-x) = -(to_Ioc_div (-(a + b)) hb x),
{ rwa [neg_add, βsub_eq_add_neg, βto_Ioc_div_add_right', to_Ioc_div_add_right, neg_sub] at this },
rw [eq_neg_iff_eq_neg, eq_comm],
apply eq_to_Ioc_div_of_add_zsmul_mem_Ioc,
obtain β¨hc, hoβ© := add_to_Ico_div_zsmul_mem_Ico a hb (-x),
rw [βneg_lt_neg_iff, neg_add (-x), neg_neg, βneg_smul] at ho,
rw [βneg_le_neg_iff, neg_add (-x), neg_neg, βneg_smul] at hc,
refine β¨ho, hc.trans_eq _β©,
rw [neg_add, neg_add_cancel_right],
end
lemma to_Ioc_div_neg (a : Ξ±) {b : Ξ±} (hb : 0 < b) (x : Ξ±) :
to_Ioc_div a hb (-x) = 1 - to_Ico_div (-a) hb x :=
by rw [βneg_neg x, to_Ico_div_neg, neg_neg, neg_neg, sub_sub_cancel]
@[simp] lemma to_Ico_mod_add_zsmul (a : Ξ±) {b : Ξ±} (hb : 0 < b) (x : Ξ±) (m : β€) :
to_Ico_mod a hb (x + m β’ b) = to_Ico_mod a hb x :=
begin
rw [to_Ico_mod, to_Ico_div_add_zsmul, to_Ico_mod, sub_smul],
abel
end
@[simp] lemma to_Ioc_mod_add_zsmul (a : Ξ±) {b : Ξ±} (hb : 0 < b) (x : Ξ±) (m : β€) :
to_Ioc_mod a hb (x + m β’ b) = to_Ioc_mod a hb x :=
begin
rw [to_Ioc_mod, to_Ioc_div_add_zsmul, to_Ioc_mod, sub_smul],
abel
end
@[simp] lemma to_Ico_mod_zsmul_add (a : Ξ±) {b : Ξ±} (hb : 0 < b) (x : Ξ±) (m : β€) :
to_Ico_mod a hb (m β’ b + x) = to_Ico_mod a hb x :=
by rw [add_comm, to_Ico_mod_add_zsmul]
@[simp] lemma to_Ioc_mod_zsmul_add (a : Ξ±) {b : Ξ±} (hb : 0 < b) (x : Ξ±) (m : β€) :
to_Ioc_mod a hb (m β’ b + x) = to_Ioc_mod a hb x :=
by rw [add_comm, to_Ioc_mod_add_zsmul]
@[simp] lemma to_Ico_mod_sub_zsmul (a : Ξ±) {b : Ξ±} (hb : 0 < b) (x : Ξ±) (m : β€) :
to_Ico_mod a hb (x - m β’ b) = to_Ico_mod a hb x :=
by rw [sub_eq_add_neg, βneg_smul, to_Ico_mod_add_zsmul]
@[simp] lemma to_Ioc_mod_sub_zsmul (a : Ξ±) {b : Ξ±} (hb : 0 < b) (x : Ξ±) (m : β€) :
to_Ioc_mod a hb (x - m β’ b) = to_Ioc_mod a hb x :=
by rw [sub_eq_add_neg, βneg_smul, to_Ioc_mod_add_zsmul]
@[simp] lemma to_Ico_mod_add_right (a : Ξ±) {b : Ξ±} (hb : 0 < b) (x : Ξ±) :
to_Ico_mod a hb (x + b) = to_Ico_mod a hb x :=
begin
convert to_Ico_mod_add_zsmul a hb x 1,
exact (one_zsmul _).symm
end
@[simp] lemma to_Ioc_mod_add_right (a : Ξ±) {b : Ξ±} (hb : 0 < b) (x : Ξ±) :
to_Ioc_mod a hb (x + b) = to_Ioc_mod a hb x :=
begin
convert to_Ioc_mod_add_zsmul a hb x 1,
exact (one_zsmul _).symm
end
@[simp] lemma to_Ico_mod_add_left (a : Ξ±) {b : Ξ±} (hb : 0 < b) (x : Ξ±) :
to_Ico_mod a hb (b + x) = to_Ico_mod a hb x :=
by rw [add_comm, to_Ico_mod_add_right]
@[simp] lemma to_Ioc_mod_add_left (a : Ξ±) {b : Ξ±} (hb : 0 < b) (x : Ξ±) :
to_Ioc_mod a hb (b + x) = to_Ioc_mod a hb x :=
by rw [add_comm, to_Ioc_mod_add_right]
@[simp] lemma to_Ico_mod_sub (a : Ξ±) {b : Ξ±} (hb : 0 < b) (x : Ξ±) :
to_Ico_mod a hb (x - b) = to_Ico_mod a hb x :=
begin
convert to_Ico_mod_sub_zsmul a hb x 1,
exact (one_zsmul _).symm
end
@[simp] lemma to_Ioc_mod_sub (a : Ξ±) {b : Ξ±} (hb : 0 < b) (x : Ξ±) :
to_Ioc_mod a hb (x - b) = to_Ioc_mod a hb x :=
begin
convert to_Ioc_mod_sub_zsmul a hb x 1,
exact (one_zsmul _).symm
end
lemma to_Ico_mod_sub' (a : Ξ±) {b : Ξ±} (hb : 0 < b) (x y : Ξ±) :
to_Ico_mod a hb (x - y) = to_Ico_mod (a + y) hb x - y :=
by simp_rw [to_Ico_mod, to_Ico_div_sub', sub_add_eq_add_sub]
lemma to_Ioc_mod_sub' (a : Ξ±) {b : Ξ±} (hb : 0 < b) (x y : Ξ±) :
to_Ioc_mod a hb (x - y) = to_Ioc_mod (a + y) hb x - y :=
by simp_rw [to_Ioc_mod, to_Ioc_div_sub', sub_add_eq_add_sub]
lemma to_Ico_mod_add_right' (a : Ξ±) {b : Ξ±} (hb : 0 < b) (x y : Ξ±) :
to_Ico_mod a hb (x + y) = to_Ico_mod (a - y) hb x + y :=
by simp_rw [to_Ico_mod, to_Ico_div_add_right', add_right_comm]
lemma to_Ioc_mod_add_right' (a : Ξ±) {b : Ξ±} (hb : 0 < b) (x y : Ξ±) :
to_Ioc_mod a hb (x + y) = to_Ioc_mod (a - y) hb x + y :=
by simp_rw [to_Ioc_mod, to_Ioc_div_add_right', add_right_comm]
lemma to_Ico_mod_neg (a : Ξ±) {b : Ξ±} (hb : 0 < b) (x : Ξ±) :
to_Ico_mod a hb (-x) = b - to_Ioc_mod (-a) hb x :=
begin
simp_rw [to_Ico_mod, to_Ioc_mod, to_Ico_div_neg, sub_smul, one_smul],
abel,
end
lemma to_Ioc_mod_neg (a : Ξ±) {b : Ξ±} (hb : 0 < b) (x : Ξ±) :
to_Ioc_mod a hb (-x) = b - to_Ico_mod (-a) hb x :=
begin
simp_rw [to_Ioc_mod, to_Ico_mod, to_Ioc_div_neg, sub_smul, one_smul],
abel,
end
lemma to_Ico_mod_eq_to_Ico_mod (a : Ξ±) {b x y : Ξ±} (hb : 0 < b) :
to_Ico_mod a hb x = to_Ico_mod a hb y β β z : β€, y - x = z β’ b :=
begin
refine β¨Ξ» h, β¨to_Ico_div a hb x - to_Ico_div a hb y, _β©, Ξ» h, _β©,
{ conv_lhs { rw [βto_Ico_mod_sub_to_Ico_div_zsmul a hb x,
βto_Ico_mod_sub_to_Ico_div_zsmul a hb y] },
rw [h, sub_smul],
abel },
{ rcases h with β¨z, hzβ©,
rw sub_eq_iff_eq_add at hz,
rw [hz, to_Ico_mod_zsmul_add] }
end
lemma to_Ioc_mod_eq_to_Ioc_mod (a : Ξ±) {b x y : Ξ±} (hb : 0 < b) :
to_Ioc_mod a hb x = to_Ioc_mod a hb y β β z : β€, y - x = z β’ b :=
begin
refine β¨Ξ» h, β¨to_Ioc_div a hb x - to_Ioc_div a hb y, _β©, Ξ» h, _β©,
{ conv_lhs { rw [βto_Ioc_mod_sub_to_Ioc_div_zsmul a hb x,
βto_Ioc_mod_sub_to_Ioc_div_zsmul a hb y] },
rw [h, sub_smul],
abel },
{ rcases h with β¨z, hzβ©,
rw sub_eq_iff_eq_add at hz,
rw [hz, to_Ioc_mod_zsmul_add] }
end
lemma to_Ico_mod_eq_self {a b x : Ξ±} (hb : 0 < b) : to_Ico_mod a hb x = x β a β€ x β§ x < a + b :=
begin
rw to_Ico_mod_eq_iff,
refine β¨Ξ» h, β¨h.1, h.2.1β©, Ξ» h, β¨h.1, h.2, 0, _β©β©,
simp
end
lemma to_Ioc_mod_eq_self {a b x : Ξ±} (hb : 0 < b) : to_Ioc_mod a hb x = x β a < x β§ x β€ a + b :=
begin
rw to_Ioc_mod_eq_iff,
refine β¨Ξ» h, β¨h.1, h.2.1β©, Ξ» h, β¨h.1, h.2, 0, _β©β©,
simp
end
@[simp] lemma to_Ico_mod_to_Ico_mod (aβ aβ : Ξ±) {b : Ξ±} (hb : 0 < b) (x : Ξ±) :
to_Ico_mod aβ hb (to_Ico_mod aβ hb x) = to_Ico_mod aβ hb x :=
begin
rw to_Ico_mod_eq_to_Ico_mod,
exact β¨-to_Ico_div aβ hb x, self_sub_to_Ico_mod aβ hb xβ©
end
@[simp] lemma to_Ico_mod_to_Ioc_mod (aβ aβ : Ξ±) {b : Ξ±} (hb : 0 < b) (x : Ξ±) :
to_Ico_mod aβ hb (to_Ioc_mod aβ hb x) = to_Ico_mod aβ hb x :=
begin
rw to_Ico_mod_eq_to_Ico_mod,
exact β¨-to_Ioc_div aβ hb x, self_sub_to_Ioc_mod aβ hb xβ©
end
@[simp] lemma to_Ioc_mod_to_Ioc_mod (aβ aβ : Ξ±) {b : Ξ±} (hb : 0 < b) (x : Ξ±) :
to_Ioc_mod aβ hb (to_Ioc_mod aβ hb x) = to_Ioc_mod aβ hb x :=
begin
rw to_Ioc_mod_eq_to_Ioc_mod,
exact β¨-to_Ioc_div aβ hb x, self_sub_to_Ioc_mod aβ hb xβ©
end
@[simp] lemma to_Ioc_mod_to_Ico_mod (aβ aβ : Ξ±) {b : Ξ±} (hb : 0 < b) (x : Ξ±) :
to_Ioc_mod aβ hb (to_Ico_mod aβ hb x) = to_Ioc_mod aβ hb x :=
begin
rw to_Ioc_mod_eq_to_Ioc_mod,
exact β¨-to_Ico_div aβ hb x, self_sub_to_Ico_mod aβ hb xβ©
end
lemma to_Ico_mod_periodic (a : Ξ±) {b : Ξ±} (hb : 0 < b) : function.periodic (to_Ico_mod a hb) b :=
to_Ico_mod_add_right a hb
lemma to_Ioc_mod_periodic (a : Ξ±) {b : Ξ±} (hb : 0 < b) : function.periodic (to_Ioc_mod a hb) b :=
to_Ioc_mod_add_right a hb
/-- `to_Ico_mod` as an equiv from the quotient. -/
@[simps symm_apply]
def quotient_add_group.equiv_Ico_mod (a : Ξ±) {b : Ξ±} (hb : 0 < b) :
(Ξ± β§Έ add_subgroup.zmultiples b) β set.Ico a (a + b) :=
{ to_fun := Ξ» x, β¨(to_Ico_mod_periodic a hb).lift x,
quotient_add_group.induction_on' x $ to_Ico_mod_mem_Ico a hbβ©,
inv_fun := coe,
right_inv := Ξ» x, subtype.ext $ (to_Ico_mod_eq_self hb).mpr x.prop,
left_inv := Ξ» x, begin
induction x using quotient_add_group.induction_on',
dsimp,
rw [quotient_add_group.eq_iff_sub_mem, to_Ico_mod_sub_self],
apply add_subgroup.zsmul_mem_zmultiples,
end }
@[simp]
lemma quotient_add_group.equiv_Ico_mod_coe (a : Ξ±) {b : Ξ±} (hb : 0 < b) (x : Ξ±) :
quotient_add_group.equiv_Ico_mod a hb βx = β¨to_Ico_mod a hb x, to_Ico_mod_mem_Ico a hb _β© :=
rfl
/-- `to_Ioc_mod` as an equiv from the quotient. -/
@[simps symm_apply]
def quotient_add_group.equiv_Ioc_mod (a : Ξ±) {b : Ξ±} (hb : 0 < b) :
(Ξ± β§Έ add_subgroup.zmultiples b) β set.Ioc a (a + b) :=
{ to_fun := Ξ» x, β¨(to_Ioc_mod_periodic a hb).lift x,
quotient_add_group.induction_on' x $ to_Ioc_mod_mem_Ioc a hbβ©,
inv_fun := coe,
right_inv := Ξ» x, subtype.ext $ (to_Ioc_mod_eq_self hb).mpr x.prop,
left_inv := Ξ» x, begin
induction x using quotient_add_group.induction_on',
dsimp,
rw [quotient_add_group.eq_iff_sub_mem, to_Ioc_mod_sub_self],
apply add_subgroup.zsmul_mem_zmultiples,
end }
@[simp]
lemma quotient_add_group.equiv_Ioc_mod_coe (a : Ξ±) {b : Ξ±} (hb : 0 < b) (x : Ξ±) :
quotient_add_group.equiv_Ioc_mod a hb βx = β¨to_Ioc_mod a hb x, to_Ioc_mod_mem_Ioc a hb _β© :=
rfl
end linear_ordered_add_comm_group
section linear_ordered_field
variables {Ξ± : Type*} [linear_ordered_field Ξ±] [floor_ring Ξ±]
lemma to_Ico_div_eq_neg_floor (a : Ξ±) {b : Ξ±} (hb : 0 < b) (x : Ξ±) :
to_Ico_div a hb x = -β(x - a) / bβ :=
begin
refine (eq_to_Ico_div_of_add_zsmul_mem_Ico hb _).symm,
rw [set.mem_Ico, zsmul_eq_mul, int.cast_neg, neg_mul, βsub_nonneg, add_comm, add_sub_assoc,
add_comm, βsub_eq_add_neg],
refine β¨int.sub_floor_div_mul_nonneg _ hb, _β©,
rw [add_comm a, βsub_lt_iff_lt_add, add_sub_assoc, add_comm, βsub_eq_add_neg],
exact int.sub_floor_div_mul_lt _ hb
end
lemma to_Ioc_div_eq_floor (a : Ξ±) {b : Ξ±} (hb : 0 < b) (x : Ξ±) :
to_Ioc_div a hb x = β(a + b - x) / bβ :=
begin
refine (eq_to_Ioc_div_of_add_zsmul_mem_Ioc hb _).symm,
rw [set.mem_Ioc, zsmul_eq_mul, βsub_nonneg, sub_add_eq_sub_sub],
refine β¨_, int.sub_floor_div_mul_nonneg _ hbβ©,
rw [βadd_lt_add_iff_right b, add_assoc, add_comm x, βsub_lt_iff_lt_add, add_comm (_ * _),
βsub_lt_iff_lt_add],
exact int.sub_floor_div_mul_lt _ hb
end
lemma to_Ico_div_zero_one (x : Ξ±) : to_Ico_div (0 : Ξ±) zero_lt_one x = -βxβ :=
by simp [to_Ico_div_eq_neg_floor]
lemma to_Ico_mod_eq_add_fract_mul (a : Ξ±) {b : Ξ±} (hb : 0 < b) (x : Ξ±) :
to_Ico_mod a hb x = a + int.fract ((x - a) / b) * b :=
begin
rw [to_Ico_mod, to_Ico_div_eq_neg_floor, int.fract],
field_simp [hb.ne.symm],
ring
end
lemma to_Ico_mod_eq_fract_mul {b : Ξ±} (hb : 0 < b) (x : Ξ±) :
to_Ico_mod 0 hb x = int.fract (x / b) * b :=
by simp [to_Ico_mod_eq_add_fract_mul]
lemma to_Ioc_mod_eq_sub_fract_mul (a : Ξ±) {b : Ξ±} (hb : 0 < b) (x : Ξ±) :
to_Ioc_mod a hb x = a + b - int.fract ((a + b - x) / b) * b :=
begin
rw [to_Ioc_mod, to_Ioc_div_eq_floor, int.fract],
field_simp [hb.ne.symm],
ring
end
lemma to_Ico_mod_zero_one (x : Ξ±) : to_Ico_mod (0 : Ξ±) zero_lt_one x = int.fract x :=
by simp [to_Ico_mod_eq_add_fract_mul]
end linear_ordered_field
|
8b89373c67da2bda60d29c1166f7be86bf943507
|
80cc5bf14c8ea85ff340d1d747a127dcadeb966f
|
/src/data/finsupp/lattice.lean
|
8144dd6568635b6e565eb87730e7e861f9c7f9d9
|
[
"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
| 4,240
|
lean
|
/-
Copyright (c) 2020 Aaron Anderson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Aaron Anderson
-/
import data.finsupp.basic
import algebra.ordered_group
/-!
# Lattice structure on finsupps
This file provides instances of ordered structures on finsupps.
-/
open_locale classical
noncomputable theory
variables {Ξ± : Type*} {Ξ² : Type*} [has_zero Ξ²] {ΞΌ : Type*} [canonically_ordered_add_monoid ΞΌ]
variables {Ξ³ : Type*} [canonically_linear_ordered_add_monoid Ξ³]
namespace finsupp
lemma le_def [partial_order Ξ²] {a b : Ξ± ββ Ξ²} : a β€ b β β (s : Ξ±), a s β€ b s := by refl
instance : order_bot (Ξ± ββ ΞΌ) :=
{ bot := 0, bot_le := by simp [finsupp.le_def, β bot_eq_zero], .. finsupp.partial_order}
instance [semilattice_inf Ξ²] : semilattice_inf (Ξ± ββ Ξ²) :=
{ inf := zip_with (β) inf_idem,
inf_le_left := Ξ» a b c, inf_le_left,
inf_le_right := Ξ» a b c, inf_le_right,
le_inf := Ξ» a b c h1 h2 s, le_inf (h1 s) (h2 s),
..finsupp.partial_order, }
@[simp]
lemma inf_apply [semilattice_inf Ξ²] {a : Ξ±} {f g : Ξ± ββ Ξ²} : (f β g) a = f a β g a := rfl
@[simp]
lemma support_inf {f g : Ξ± ββ Ξ³} : (f β g).support = f.support β© g.support :=
begin
ext, simp only [inf_apply, mem_support_iff, ne.def,
finset.mem_union, finset.mem_filter, finset.mem_inter],
rw [β decidable.not_or_iff_and_not, β not_congr],
rw inf_eq_min, unfold min, split_ifs;
{ try {apply or_iff_left_of_imp}, try {apply or_iff_right_of_imp}, intro con, rw con at h,
revert h, simp, }
end
instance [semilattice_sup Ξ²] : semilattice_sup (Ξ± ββ Ξ²) :=
{ sup := zip_with (β) sup_idem,
le_sup_left := Ξ» a b c, le_sup_left,
le_sup_right := Ξ» a b c, le_sup_right,
sup_le := Ξ» a b c h1 h2 s, sup_le (h1 s) (h2 s),
..finsupp.partial_order, }
@[simp]
lemma sup_apply [semilattice_sup Ξ²] {a : Ξ±} {f g : Ξ± ββ Ξ²} : (f β g) a = f a β g a := rfl
@[simp]
lemma support_sup
{f g : Ξ± ββ Ξ³} : (f β g).support = f.support βͺ g.support :=
begin
ext, simp only [finset.mem_union, mem_support_iff, sup_apply, ne.def, β bot_eq_zero],
rw sup_eq_bot_iff, tauto,
end
instance lattice [lattice Ξ²] : lattice (Ξ± ββ Ξ²) :=
{ .. finsupp.semilattice_inf, .. finsupp.semilattice_sup}
instance semilattice_inf_bot : semilattice_inf_bot (Ξ± ββ Ξ³) :=
{ ..finsupp.order_bot, ..finsupp.lattice}
lemma of_multiset_strict_mono : strict_mono (@finsupp.of_multiset Ξ±) :=
begin
unfold strict_mono, intros, rw lt_iff_le_and_ne at *, split,
{ rw finsupp.le_iff, intros s hs, repeat {rw finsupp.of_multiset_apply},
rw multiset.le_iff_count at a_1, apply a_1.left },
{ have h := a_1.right, contrapose h, simp at *,
apply finsupp.equiv_multiset.symm.injective h }
end
lemma bot_eq_zero : (β₯ : Ξ± ββ Ξ³) = 0 := rfl
lemma disjoint_iff {x y : Ξ± ββ Ξ³} : disjoint x y β disjoint x.support y.support :=
begin
unfold disjoint, repeat {rw le_bot_iff},
rw [finsupp.bot_eq_zero, β finsupp.support_eq_empty, finsupp.support_inf], refl,
end
/-- The lattice of `finsupp`s to `β` is order-isomorphic to that of `multiset`s. -/
def order_iso_multiset :
(Ξ± ββ β) βo multiset Ξ± :=
β¨finsupp.equiv_multiset, begin
intros a b, unfold finsupp.equiv_multiset, dsimp,
rw multiset.le_iff_count, simp only [finsupp.count_to_multiset], refl
end β©
@[simp] lemma order_iso_multiset_apply {f : Ξ± ββ β} : order_iso_multiset f = f.to_multiset := rfl
@[simp] lemma order_iso_multiset_symm_apply {s : multiset Ξ±} :
order_iso_multiset.symm s = s.to_finsupp :=
by { conv_rhs { rw β (rel_iso.apply_symm_apply order_iso_multiset) s}, simp }
variable [partial_order Ξ²]
/-- The order on `finsupp`s over a partial order embeds into the order on functions -/
def order_embedding_to_fun :
(Ξ± ββ Ξ²) βͺo (Ξ± β Ξ²) :=
β¨β¨Ξ» (f : Ξ± ββ Ξ²) (a : Ξ±), f a, Ξ» f g h, finsupp.ext (Ξ» a, by { dsimp at h, rw h,} )β©,
Ξ» a b, le_defβ©
@[simp] lemma order_embedding_to_fun_apply {f : Ξ± ββ Ξ²} {a : Ξ±} :
order_embedding_to_fun f a = f a := rfl
lemma monotone_to_fun : monotone (finsupp.to_fun : (Ξ± ββ Ξ²) β (Ξ± β Ξ²)) := Ξ» f g h a, le_def.1 h a
end finsupp
|
d81bd98998132476f272c0f2a3d3a5f5863f7b1b
|
74addaa0e41490cbaf2abd313a764c96df57b05d
|
/Mathlib/order/filter/interval_auto.lean
|
c9b2b97cb7b019969bbe971d82e9ff3379fea76b
|
[] |
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
| 12,821
|
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 Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.data.set.intervals.ord_connected
import Mathlib.order.filter.lift
import Mathlib.order.filter.at_top_bot
import Mathlib.PostPort
universes u_1 l u_2
namespace Mathlib
/-!
# Convergence of intervals
If both `a` and `b` tend to some filter `lβ`, sometimes this implies that `Ixx a b` tends to
`lβ.lift' powerset`, i.e., for any `s β lβ` eventually `Ixx a b` becomes a subset of `s`. Here and
below `Ixx` is one of `Icc`, `Ico`, `Ioc`, and `Ioo`. We define `filter.tendsto_Ixx_class Ixx lβ lβ`
to be a typeclass representing this property.
The instances provide the best `lβ` for a given `lβ`. In many cases `lβ = lβ` but sometimes we can
drop an endpoint from an interval: e.g., we prove `tendsto_Ixx_class Ico (π $ Iic a) (π $ Iio a)`,
i.e., if `uβ n` and `uβ n` belong eventually to `Iic a`, then the interval `Ico (uβ n) (uβ n)` is
eventually included in `Iio a`.
The next table shows βoutputβ filters `lβ` for different values of `Ixx` and `lβ`. The instances
that need topology are defined in `topology/algebra/ordered`.
| Input filter | `Ixx = Icc` | `Ixx = Ico` | `Ixx = Ioc` | `Ixx = Ioo` |
| -----------: | :-----------: | :-----------: | :-----------: | :-----------: |
| `at_top` | `at_top` | `at_top` | `at_top` | `at_top` |
| `at_bot` | `at_bot` | `at_bot` | `at_bot` | `at_bot` |
| `pure a` | `pure a` | `β₯` | `β₯` | `β₯` |
| `π (Iic a)` | `π (Iic a)` | `π (Iio a)` | `π (Iic a)` | `π (Iio a)` |
| `π (Ici a)` | `π (Ici a)` | `π (Ici a)` | `π (Ioi a)` | `π (Ioi a)` |
| `π (Ioi a)` | `π (Ioi a)` | `π (Ioi a)` | `π (Ioi a)` | `π (Ioi a)` |
| `π (Iio a)` | `π (Iio a)` | `π (Iio a)` | `π (Iio a)` | `π (Iio a)` |
| `π a` | `π a` | `π a` | `π a` | `π a` |
| `π[Iic a] b` | `π[Iic a] b` | `π[Iio a] b` | `π[Iic a] b` | `π[Iio a] b` |
| `π[Ici a] b` | `π[Ici a] b` | `π[Ici a] b` | `π[Ioi a] b` | `π[Ioi a] b` |
| `π[Ioi a] b` | `π[Ioi a] b` | `π[Ioi a] b` | `π[Ioi a] b` | `π[Ioi a] b` |
| `π[Iio a] b` | `π[Iio a] b` | `π[Iio a] b` | `π[Iio a] b` | `π[Iio a] b` |
-/
namespace filter
/-- A pair of filters `lβ`, `lβ` has `tendsto_Ixx_class Ixx` property if `Ixx a b` tends to
`lβ.lift' powerset` as `a` and `b` tend to `lβ`. In all instances `Ixx` is one of `Icc`, `Ico`,
`Ioc`, or `Ioo`. The instances provide the best `lβ` for a given `lβ`. In many cases `lβ = lβ` but
sometimes we can drop an endpoint from an interval: e.g., we prove `tendsto_Ixx_class Ico (π $ Iic
a) (π $ Iio a)`, i.e., if `uβ n` and `uβ n` belong eventually to `Iic a`, then the interval `Ico (uβ
n) (uβ n)` is eventually included in `Iio a`.
We mark `lβ` as an `out_param` so that Lean can automatically find an appropriate `lβ` based on
`Ixx` and `lβ`. This way, e.g., `tendsto.Ico hβ hβ` works without specifying explicitly `lβ`. -/
class tendsto_Ixx_class {Ξ± : Type u_1} [preorder Ξ±] (Ixx : Ξ± β Ξ± β set Ξ±) (lβ : filter Ξ±)
(lβ : outParam (filter Ξ±))
where
tendsto_Ixx :
tendsto (fun (p : Ξ± Γ Ξ±) => Ixx (prod.fst p) (prod.snd p)) (filter.prod lβ lβ)
(filter.lift' lβ set.powerset)
theorem tendsto.Icc {Ξ± : Type u_1} {Ξ² : Type u_2} [preorder Ξ±] {lβ : filter Ξ±} {lβ : filter Ξ±}
[tendsto_Ixx_class set.Icc lβ lβ] {lb : filter Ξ²} {uβ : Ξ² β Ξ±} {uβ : Ξ² β Ξ±}
(hβ : tendsto uβ lb lβ) (hβ : tendsto uβ lb lβ) :
tendsto (fun (x : Ξ²) => set.Icc (uβ x) (uβ x)) lb (filter.lift' lβ set.powerset) :=
tendsto.comp tendsto_Ixx_class.tendsto_Ixx (tendsto.prod_mk hβ hβ)
theorem tendsto.Ioc {Ξ± : Type u_1} {Ξ² : Type u_2} [preorder Ξ±] {lβ : filter Ξ±} {lβ : filter Ξ±}
[tendsto_Ixx_class set.Ioc lβ lβ] {lb : filter Ξ²} {uβ : Ξ² β Ξ±} {uβ : Ξ² β Ξ±}
(hβ : tendsto uβ lb lβ) (hβ : tendsto uβ lb lβ) :
tendsto (fun (x : Ξ²) => set.Ioc (uβ x) (uβ x)) lb (filter.lift' lβ set.powerset) :=
tendsto.comp tendsto_Ixx_class.tendsto_Ixx (tendsto.prod_mk hβ hβ)
theorem tendsto.Ico {Ξ± : Type u_1} {Ξ² : Type u_2} [preorder Ξ±] {lβ : filter Ξ±} {lβ : filter Ξ±}
[tendsto_Ixx_class set.Ico lβ lβ] {lb : filter Ξ²} {uβ : Ξ² β Ξ±} {uβ : Ξ² β Ξ±}
(hβ : tendsto uβ lb lβ) (hβ : tendsto uβ lb lβ) :
tendsto (fun (x : Ξ²) => set.Ico (uβ x) (uβ x)) lb (filter.lift' lβ set.powerset) :=
tendsto.comp tendsto_Ixx_class.tendsto_Ixx (tendsto.prod_mk hβ hβ)
theorem tendsto.Ioo {Ξ± : Type u_1} {Ξ² : Type u_2} [preorder Ξ±] {lβ : filter Ξ±} {lβ : filter Ξ±}
[tendsto_Ixx_class set.Ioo lβ lβ] {lb : filter Ξ²} {uβ : Ξ² β Ξ±} {uβ : Ξ² β Ξ±}
(hβ : tendsto uβ lb lβ) (hβ : tendsto uβ lb lβ) :
tendsto (fun (x : Ξ²) => set.Ioo (uβ x) (uβ x)) lb (filter.lift' lβ set.powerset) :=
tendsto.comp tendsto_Ixx_class.tendsto_Ixx (tendsto.prod_mk hβ hβ)
theorem tendsto_Ixx_class_principal {Ξ± : Type u_1} [preorder Ξ±] {s : set Ξ±} {t : set Ξ±}
{Ixx : Ξ± β Ξ± β set Ξ±} :
tendsto_Ixx_class Ixx (principal s) (principal t) β
β (x : Ξ±), x β s β β (y : Ξ±), y β s β Ixx x y β t :=
sorry
theorem tendsto_Ixx_class_inf {Ξ± : Type u_1} [preorder Ξ±] {lβ : filter Ξ±} {lβ' : filter Ξ±}
{lβ : filter Ξ±} {lβ' : filter Ξ±} {Ixx : Ξ± β Ξ± β set Ξ±} [h : tendsto_Ixx_class Ixx lβ lβ]
[h' : tendsto_Ixx_class Ixx lβ' lβ'] : tendsto_Ixx_class Ixx (lβ β lβ') (lβ β lβ') :=
sorry
theorem tendsto_Ixx_class_of_subset {Ξ± : Type u_1} [preorder Ξ±] {lβ : filter Ξ±} {lβ : filter Ξ±}
{Ixx : Ξ± β Ξ± β set Ξ±} {Ixx' : Ξ± β Ξ± β set Ξ±} (h : β (a b : Ξ±), Ixx a b β Ixx' a b)
[h' : tendsto_Ixx_class Ixx' lβ lβ] : tendsto_Ixx_class Ixx lβ lβ :=
tendsto_Ixx_class.mk
(tendsto_lift'_powerset_mono tendsto_Ixx_class.tendsto_Ixx
(eventually_of_forall (iff.mpr prod.forall h)))
theorem has_basis.tendsto_Ixx_class {Ξ± : Type u_1} [preorder Ξ±] {ΞΉ : Type u_2} {p : ΞΉ β Prop}
{s : ΞΉ β set Ξ±} {l : filter Ξ±} (hl : has_basis l p s) {Ixx : Ξ± β Ξ± β set Ξ±}
(H : β (i : ΞΉ), p i β β (x : Ξ±), x β s i β β (y : Ξ±), y β s i β Ixx x y β s i) :
tendsto_Ixx_class Ixx l l :=
sorry
protected instance tendsto_Icc_at_top_at_top {Ξ± : Type u_1} [preorder Ξ±] :
tendsto_Ixx_class set.Icc at_top at_top :=
has_basis.tendsto_Ixx_class (has_basis_infi_principal_finite fun (a : Ξ±) => set.Ici a)
fun (s : set Ξ±) (hs : set.finite s) =>
set.ord_connected_bInter fun (i : Ξ±) (hi : i β s) => set.ord_connected_Ici
protected instance tendsto_Ico_at_top_at_top {Ξ± : Type u_1} [preorder Ξ±] :
tendsto_Ixx_class set.Ico at_top at_top :=
tendsto_Ixx_class_of_subset fun (_x _x_1 : Ξ±) => set.Ico_subset_Icc_self
protected instance tendsto_Ioc_at_top_at_top {Ξ± : Type u_1} [preorder Ξ±] :
tendsto_Ixx_class set.Ioc at_top at_top :=
tendsto_Ixx_class_of_subset fun (_x _x_1 : Ξ±) => set.Ioc_subset_Icc_self
protected instance tendsto_Ioo_at_top_at_top {Ξ± : Type u_1} [preorder Ξ±] :
tendsto_Ixx_class set.Ioo at_top at_top :=
tendsto_Ixx_class_of_subset fun (_x _x_1 : Ξ±) => set.Ioo_subset_Icc_self
protected instance tendsto_Icc_at_bot_at_bot {Ξ± : Type u_1} [preorder Ξ±] :
tendsto_Ixx_class set.Icc at_bot at_bot :=
has_basis.tendsto_Ixx_class (has_basis_infi_principal_finite fun (a : Ξ±) => set.Iic a)
fun (s : set Ξ±) (hs : set.finite s) =>
set.ord_connected_bInter fun (i : Ξ±) (hi : i β s) => set.ord_connected_Iic
protected instance tendsto_Ico_at_bot_at_bot {Ξ± : Type u_1} [preorder Ξ±] :
tendsto_Ixx_class set.Ico at_bot at_bot :=
tendsto_Ixx_class_of_subset fun (_x _x_1 : Ξ±) => set.Ico_subset_Icc_self
protected instance tendsto_Ioc_at_bot_at_bot {Ξ± : Type u_1} [preorder Ξ±] :
tendsto_Ixx_class set.Ioc at_bot at_bot :=
tendsto_Ixx_class_of_subset fun (_x _x_1 : Ξ±) => set.Ioc_subset_Icc_self
protected instance tendsto_Ioo_at_bot_at_bot {Ξ± : Type u_1} [preorder Ξ±] :
tendsto_Ixx_class set.Ioo at_bot at_bot :=
tendsto_Ixx_class_of_subset fun (_x _x_1 : Ξ±) => set.Ioo_subset_Icc_self
protected instance ord_connected.tendsto_Icc {Ξ± : Type u_1} [preorder Ξ±] {s : set Ξ±}
[set.ord_connected s] : tendsto_Ixx_class set.Icc (principal s) (principal s) :=
iff.mpr tendsto_Ixx_class_principal _inst_2
protected instance tendsto_Ico_Ici_Ici {Ξ± : Type u_1} [preorder Ξ±] {a : Ξ±} :
tendsto_Ixx_class set.Ico (principal (set.Ici a)) (principal (set.Ici a)) :=
tendsto_Ixx_class_of_subset fun (_x _x_1 : Ξ±) => set.Ico_subset_Icc_self
protected instance tendsto_Ico_Ioi_Ioi {Ξ± : Type u_1} [preorder Ξ±] {a : Ξ±} :
tendsto_Ixx_class set.Ico (principal (set.Ioi a)) (principal (set.Ioi a)) :=
tendsto_Ixx_class_of_subset fun (_x _x_1 : Ξ±) => set.Ico_subset_Icc_self
protected instance tendsto_Ico_Iic_Iio {Ξ± : Type u_1} [preorder Ξ±] {a : Ξ±} :
tendsto_Ixx_class set.Ico (principal (set.Iic a)) (principal (set.Iio a)) :=
iff.mpr tendsto_Ixx_class_principal
fun (a_1 : Ξ±) (ha : a_1 β set.Iic a) (b : Ξ±) (hb : b β set.Iic a) (x : Ξ±)
(hx : x β set.Ico a_1 b) => lt_of_lt_of_le (and.right hx) hb
protected instance tendsto_Ico_Iio_Iio {Ξ± : Type u_1} [preorder Ξ±] {a : Ξ±} :
tendsto_Ixx_class set.Ico (principal (set.Iio a)) (principal (set.Iio a)) :=
tendsto_Ixx_class_of_subset fun (_x _x_1 : Ξ±) => set.Ico_subset_Icc_self
protected instance tendsto_Ioc_Ici_Ioi {Ξ± : Type u_1} [preorder Ξ±] {a : Ξ±} :
tendsto_Ixx_class set.Ioc (principal (set.Ici a)) (principal (set.Ioi a)) :=
iff.mpr tendsto_Ixx_class_principal
fun (x : Ξ±) (hx : x β set.Ici a) (y : Ξ±) (hy : y β set.Ici a) (t : Ξ±) (ht : t β set.Ioc x y) =>
lt_of_le_of_lt hx (and.left ht)
protected instance tendsto_Ioc_Iic_Iic {Ξ± : Type u_1} [preorder Ξ±] {a : Ξ±} :
tendsto_Ixx_class set.Ioc (principal (set.Iic a)) (principal (set.Iic a)) :=
tendsto_Ixx_class_of_subset fun (_x _x_1 : Ξ±) => set.Ioc_subset_Icc_self
protected instance tendsto_Ioc_Iio_Iio {Ξ± : Type u_1} [preorder Ξ±] {a : Ξ±} :
tendsto_Ixx_class set.Ioc (principal (set.Iio a)) (principal (set.Iio a)) :=
tendsto_Ixx_class_of_subset fun (_x _x_1 : Ξ±) => set.Ioc_subset_Icc_self
protected instance tendsto_Ioc_Ioi_Ioi {Ξ± : Type u_1} [preorder Ξ±] {a : Ξ±} :
tendsto_Ixx_class set.Ioc (principal (set.Ioi a)) (principal (set.Ioi a)) :=
tendsto_Ixx_class_of_subset fun (_x _x_1 : Ξ±) => set.Ioc_subset_Icc_self
protected instance tendsto_Ioo_Ici_Ioi {Ξ± : Type u_1} [preorder Ξ±] {a : Ξ±} :
tendsto_Ixx_class set.Ioo (principal (set.Ici a)) (principal (set.Ioi a)) :=
tendsto_Ixx_class_of_subset fun (_x _x_1 : Ξ±) => set.Ioo_subset_Ioc_self
protected instance tendsto_Ioo_Iic_Iio {Ξ± : Type u_1} [preorder Ξ±] {a : Ξ±} :
tendsto_Ixx_class set.Ioo (principal (set.Iic a)) (principal (set.Iio a)) :=
tendsto_Ixx_class_of_subset fun (_x _x_1 : Ξ±) => set.Ioo_subset_Ico_self
protected instance tendsto_Ioo_Ioi_Ioi {Ξ± : Type u_1} [preorder Ξ±] {a : Ξ±} :
tendsto_Ixx_class set.Ioo (principal (set.Ioi a)) (principal (set.Ioi a)) :=
tendsto_Ixx_class_of_subset fun (_x _x_1 : Ξ±) => set.Ioo_subset_Ioc_self
protected instance tendsto_Ioo_Iio_Iio {Ξ± : Type u_1} [preorder Ξ±] {a : Ξ±} :
tendsto_Ixx_class set.Ioo (principal (set.Iio a)) (principal (set.Iio a)) :=
tendsto_Ixx_class_of_subset fun (_x _x_1 : Ξ±) => set.Ioo_subset_Ioc_self
protected instance tendsto_Icc_pure_pure {Ξ² : Type u_2} [partial_order Ξ²] {a : Ξ²} :
tendsto_Ixx_class set.Icc (pure a) (pure a) :=
eq.mpr
(id
(Eq._oldrec (Eq.refl (tendsto_Ixx_class set.Icc (pure a) (pure a)))
(Eq.symm (principal_singleton a))))
(iff.mpr tendsto_Ixx_class_principal set.ord_connected_singleton)
protected instance tendsto_Ico_pure_bot {Ξ² : Type u_2} [partial_order Ξ²] {a : Ξ²} :
tendsto_Ixx_class set.Ico (pure a) β₯ :=
sorry
protected instance tendsto_Ioc_pure_bot {Ξ² : Type u_2} [partial_order Ξ²] {a : Ξ²} :
tendsto_Ixx_class set.Ioc (pure a) β₯ :=
sorry
protected instance tendsto_Ioo_pure_bot {Ξ² : Type u_2} [partial_order Ξ²] {a : Ξ²} :
tendsto_Ixx_class set.Ioo (pure a) β₯ :=
tendsto_Ixx_class_of_subset fun (_x _x_1 : Ξ²) => set.Ioo_subset_Ioc_self
end Mathlib
|
fff4daed97953b63b9af5e16199aac24aaff3ee6
|
4d2583807a5ac6caaffd3d7a5f646d61ca85d532
|
/src/algebra/algebra/tower.lean
|
67678dd229c7fe2340f1795c19f07757d74e2799
|
[
"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
| 11,909
|
lean
|
/-
Copyright (c) 2020 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau
-/
import algebra.algebra.subalgebra
/-!
# Towers of algebras
In this file we prove basic facts about towers of algebra.
An algebra tower A/S/R is expressed by having instances of `algebra A S`,
`algebra R S`, `algebra R A` and `is_scalar_tower R S A`, the later asserting the
compatibility condition `(r β’ s) β’ a = r β’ (s β’ a)`.
An important definition is `to_alg_hom R S A`, the canonical `R`-algebra homomorphism `S ββ[R] A`.
-/
open_locale pointwise
universes u v w uβ vβ
variables (R : Type u) (S : Type v) (A : Type w) (B : Type uβ) (M : Type vβ)
namespace algebra
variables [comm_semiring R] [semiring A] [algebra R A]
variables [add_comm_monoid M] [module R M] [module A M] [is_scalar_tower R A M]
variables {A}
/-- The `R`-algebra morphism `A β End (M)` corresponding to the representation of the algebra `A`
on the `R`-module `M`.
This is a stronger version of `distrib_mul_action.to_linear_map`, and could also have been
called `algebra.to_module_End`. -/
def lsmul : A ββ[R] module.End R M :=
{ to_fun := distrib_mul_action.to_linear_map R M,
map_one' := linear_map.ext $ Ξ» _, one_smul A _,
map_mul' := Ξ» a b, linear_map.ext $ smul_assoc a b,
map_zero' := linear_map.ext $ Ξ» _, zero_smul A _,
map_add' := Ξ» a b, linear_map.ext $ Ξ» _, add_smul _ _ _,
commutes' := Ξ» r, linear_map.ext $ algebra_map_smul A r, }
@[simp] lemma lsmul_coe (a : A) : (lsmul R M a : M β M) = (β’) a := rfl
lemma lmul_algebra_map (x : R) :
lmul R A (algebra_map R A x) = algebra.lsmul R A x :=
eq.symm $ linear_map.ext $ smul_def x
end algebra
namespace is_scalar_tower
section module
variables [comm_semiring R] [semiring A] [algebra R A]
variables [add_comm_monoid M] [module R M] [module A M] [is_scalar_tower R A M]
variables {R} (A) {M}
theorem algebra_map_smul (r : R) (x : M) : algebra_map R A r β’ x = r β’ x :=
by rw [algebra.algebra_map_eq_smul_one, smul_assoc, one_smul]
end module
section semiring
variables [comm_semiring R] [comm_semiring S] [semiring A] [semiring B]
variables [algebra R S] [algebra S A] [algebra S B]
variables {R S A}
theorem of_algebra_map_eq [algebra R A]
(h : β x, algebra_map R A x = algebra_map S A (algebra_map R S x)) :
is_scalar_tower R S A :=
β¨Ξ» x y z, by simp_rw [algebra.smul_def, ring_hom.map_mul, mul_assoc, h]β©
/-- See note [partially-applied ext lemmas]. -/
theorem of_algebra_map_eq' [algebra R A]
(h : algebra_map R A = (algebra_map S A).comp (algebra_map R S)) :
is_scalar_tower R S A :=
of_algebra_map_eq $ ring_hom.ext_iff.1 h
variables (R S A)
instance subalgebra (Sβ : subalgebra R S) : is_scalar_tower Sβ S A :=
of_algebra_map_eq $ Ξ» x, rfl
variables [algebra R A] [algebra R B]
variables [is_scalar_tower R S A] [is_scalar_tower R S B]
theorem algebra_map_eq :
algebra_map R A = (algebra_map S A).comp (algebra_map R S) :=
ring_hom.ext $ Ξ» x, by simp_rw [ring_hom.comp_apply, algebra.algebra_map_eq_smul_one,
smul_assoc, one_smul]
theorem algebra_map_apply (x : R) : algebra_map R A x = algebra_map S A (algebra_map R S x) :=
by rw [algebra_map_eq R S A, ring_hom.comp_apply]
instance subalgebra' (Sβ : subalgebra R S) : is_scalar_tower R Sβ A :=
@is_scalar_tower.of_algebra_map_eq R Sβ A _ _ _ _ _ _ $ Ξ» _,
(is_scalar_tower.algebra_map_apply R S A _ : _)
@[ext] lemma algebra.ext {S : Type u} {A : Type v} [comm_semiring S] [semiring A]
(h1 h2 : algebra S A) (h : β {r : S} {x : A}, (by haveI := h1; exact r β’ x) = r β’ x) : h1 = h2 :=
begin
unfreezingI { cases h1 with f1 g1 h11 h12, cases h2 with f2 g2 h21 h22, cases f1, cases f2, },
congr',
{ ext r x, exact h },
{ ext r, erw [β mul_one (g1 r), β h12, β mul_one (g2 r), β h22, h], refl, },
end
/-- In a tower, the canonical map from the middle element to the top element is an
algebra homomorphism over the bottom element. -/
def to_alg_hom : S ββ[R] A :=
{ commutes' := Ξ» _, (algebra_map_apply _ _ _ _).symm,
.. algebra_map S A }
lemma to_alg_hom_apply (y : S) : to_alg_hom R S A y = algebra_map S A y := rfl
@[simp] lemma coe_to_alg_hom : β(to_alg_hom R S A) = algebra_map S A :=
ring_hom.ext $ Ξ» _, rfl
@[simp] lemma coe_to_alg_hom' : (to_alg_hom R S A : S β A) = algebra_map S A :=
rfl
variables {R S A B}
@[simp, priority 900] lemma _root_.alg_hom.map_algebra_map (f : A ββ[S] B) (r : R) :
f (algebra_map R A r) = algebra_map R B r :=
by rw [algebra_map_apply R S A r, f.commutes, β algebra_map_apply R S B]
variables (R)
@[simp, priority 900] lemma _root_.alg_hom.comp_algebra_map_of_tower (f : A ββ[S] B) :
(f : A β+* B).comp (algebra_map R A) = algebra_map R B :=
ring_hom.ext f.map_algebra_map
variables (R) {S A B}
-- conflicts with is_scalar_tower.subalgebra
@[priority 999] instance subsemiring (U : subsemiring S) : is_scalar_tower U S A :=
of_algebra_map_eq $ Ξ» x, rfl
@[nolint instance_priority]
instance of_ring_hom {R A B : Type*} [comm_semiring R] [comm_semiring A] [comm_semiring B]
[algebra R A] [algebra R B] (f : A ββ[R] B) :
@is_scalar_tower R A B _ (f.to_ring_hom.to_algebra.to_has_scalar) _ :=
by { letI := (f : A β+* B).to_algebra, exact of_algebra_map_eq (Ξ» x, (f.commutes x).symm) }
end semiring
end is_scalar_tower
section homs
variables [comm_semiring R] [comm_semiring S] [semiring A] [semiring B]
variables [algebra R S] [algebra S A] [algebra S B]
variables [algebra R A] [algebra R B]
variables [is_scalar_tower R S A] [is_scalar_tower R S B]
variables (R) {A S B}
open is_scalar_tower
namespace alg_hom
/-- R βΆ S induces S-Alg β₯€ R-Alg -/
def restrict_scalars (f : A ββ[S] B) : A ββ[R] B :=
{ commutes' := Ξ» r, by { rw [algebra_map_apply R S A, algebra_map_apply R S B],
exact f.commutes (algebra_map R S r) },
.. (f : A β+* B) }
lemma restrict_scalars_apply (f : A ββ[S] B) (x : A) : f.restrict_scalars R x = f x := rfl
@[simp] lemma coe_restrict_scalars (f : A ββ[S] B) : (f.restrict_scalars R : A β+* B) = f := rfl
@[simp] lemma coe_restrict_scalars' (f : A ββ[S] B) : (restrict_scalars R f : A β B) = f := rfl
lemma restrict_scalars_injective :
function.injective (restrict_scalars R : (A ββ[S] B) β (A ββ[R] B)) :=
Ξ» f g h, alg_hom.ext (alg_hom.congr_fun h : _)
end alg_hom
namespace alg_equiv
/-- R βΆ S induces S-Alg β₯€ R-Alg -/
def restrict_scalars (f : A ββ[S] B) : A ββ[R] B :=
{ commutes' := Ξ» r, by { rw [algebra_map_apply R S A, algebra_map_apply R S B],
exact f.commutes (algebra_map R S r) },
.. (f : A β+* B) }
lemma restrict_scalars_apply (f : A ββ[S] B) (x : A) : f.restrict_scalars R x = f x := rfl
@[simp] lemma coe_restrict_scalars (f : A ββ[S] B) : (f.restrict_scalars R : A β+* B) = f := rfl
@[simp] lemma coe_restrict_scalars' (f : A ββ[S] B) : (restrict_scalars R f : A β B) = f := rfl
lemma restrict_scalars_injective :
function.injective (restrict_scalars R : (A ββ[S] B) β (A ββ[R] B)) :=
Ξ» f g h, alg_equiv.ext (alg_equiv.congr_fun h : _)
end alg_equiv
end homs
namespace subalgebra
open is_scalar_tower
section semiring
variables (R) {S A B} [comm_semiring R] [comm_semiring S] [semiring A] [semiring B]
variables [algebra R S] [algebra S A] [algebra R A] [algebra S B] [algebra R B]
variables [is_scalar_tower R S A] [is_scalar_tower R S B]
/-- Given a scalar tower `R`, `S`, `A` of algebras, reinterpret an `S`-subalgebra of `A` an as an
`R`-subalgebra. -/
def restrict_scalars (U : subalgebra S A) : subalgebra R A :=
{ algebra_map_mem' := Ξ» x, by { rw algebra_map_apply R S A, exact U.algebra_map_mem _ },
.. U }
@[simp] lemma coe_restrict_scalars {U : subalgebra S A} :
(restrict_scalars R U : set A) = (U : set A) := rfl
@[simp] lemma restrict_scalars_top : restrict_scalars R (β€ : subalgebra S A) = β€ :=
set_like.coe_injective rfl
@[simp] lemma restrict_scalars_to_submodule {U : subalgebra S A} :
(U.restrict_scalars R).to_submodule = U.to_submodule.restrict_scalars R :=
set_like.coe_injective rfl
@[simp] lemma mem_restrict_scalars {U : subalgebra S A} {x : A} :
x β restrict_scalars R U β x β U := iff.rfl
lemma restrict_scalars_injective :
function.injective (restrict_scalars R : subalgebra S A β subalgebra R A) :=
Ξ» U V H, ext $ Ξ» x, by rw [β mem_restrict_scalars R, H, mem_restrict_scalars]
/-- Produces an `R`-algebra map from `U.restrict_scalars R` given an `S`-algebra map from `U`.
This is a special case of `alg_hom.restrict_scalars` that can be helpful in elaboration. -/
@[simp]
def of_restrict_scalars (U : subalgebra S A) (f : U ββ[S] B) : U.restrict_scalars R ββ[R] B :=
f.restrict_scalars R
end semiring
end subalgebra
namespace is_scalar_tower
open subalgebra
variables [comm_semiring R] [comm_semiring S] [comm_semiring A]
variables [algebra R S] [algebra S A] [algebra R A] [is_scalar_tower R S A]
theorem adjoin_range_to_alg_hom (t : set A) :
(algebra.adjoin (to_alg_hom R S A).range t).restrict_scalars R =
(algebra.adjoin S t).restrict_scalars R :=
subalgebra.ext $ Ξ» z,
show z β subsemiring.closure (set.range (algebra_map (to_alg_hom R S A).range A) βͺ t : set A) β
z β subsemiring.closure (set.range (algebra_map S A) βͺ t : set A),
from suffices set.range (algebra_map (to_alg_hom R S A).range A) = set.range (algebra_map S A),
by rw this,
by { ext z, exact β¨Ξ» β¨β¨x, y, h1β©, h2β©, β¨y, h2 βΈ h1β©, Ξ» β¨y, hyβ©, β¨β¨z, y, hyβ©, rflβ©β© }
end is_scalar_tower
section semiring
variables {R S A}
variables [comm_semiring R] [semiring S] [add_comm_monoid A]
variables [algebra R S] [module S A] [module R A] [is_scalar_tower R S A]
namespace submodule
open is_scalar_tower
theorem smul_mem_span_smul_of_mem {s : set S} {t : set A} {k : S} (hks : k β span R s)
{x : A} (hx : x β t) : k β’ x β span R (s β’ t) :=
span_induction hks (Ξ» c hc, subset_span $ set.mem_smul.2 β¨c, x, hc, hx, rflβ©)
(by { rw zero_smul, exact zero_mem _ })
(Ξ» cβ cβ ihβ ihβ, by { rw add_smul, exact add_mem _ ihβ ihβ })
(Ξ» b c hc, by { rw is_scalar_tower.smul_assoc, exact smul_mem _ _ hc })
theorem smul_mem_span_smul {s : set S} (hs : span R s = β€) {t : set A} {k : S}
{x : A} (hx : x β span R t) :
k β’ x β span R (s β’ t) :=
span_induction hx (Ξ» x hx, smul_mem_span_smul_of_mem (hs.symm βΈ mem_top) hx)
(by { rw smul_zero, exact zero_mem _ })
(Ξ» x y ihx ihy, by { rw smul_add, exact add_mem _ ihx ihy })
(Ξ» c x hx, smul_comm c k x βΈ smul_mem _ _ hx)
theorem smul_mem_span_smul' {s : set S} (hs : span R s = β€) {t : set A} {k : S}
{x : A} (hx : x β span R (s β’ t)) :
k β’ x β span R (s β’ t) :=
span_induction hx (Ξ» x hx, let β¨p, q, hp, hq, hpqβ© := set.mem_smul.1 hx in
by { rw [β hpq, smul_smul], exact smul_mem_span_smul_of_mem (hs.symm βΈ mem_top) hq })
(by { rw smul_zero, exact zero_mem _ })
(Ξ» x y ihx ihy, by { rw smul_add, exact add_mem _ ihx ihy })
(Ξ» c x hx, smul_comm c k x βΈ smul_mem _ _ hx)
theorem span_smul {s : set S} (hs : span R s = β€) (t : set A) :
span R (s β’ t) = (span S t).restrict_scalars R :=
le_antisymm (span_le.2 $ Ξ» x hx, let β¨p, q, hps, hqt, hpqxβ© := set.mem_smul.1 hx in
hpqx βΈ (span S t).smul_mem p (subset_span hqt)) $
Ξ» p hp, span_induction hp (Ξ» x hx, one_smul S x βΈ smul_mem_span_smul hs (subset_span hx))
(zero_mem _)
(Ξ» _ _, add_mem _)
(Ξ» k x hx, smul_mem_span_smul' hs hx)
end submodule
end semiring
section ring
namespace algebra
variables [comm_semiring R] [ring A] [algebra R A]
variables [add_comm_group M] [module A M] [module R M] [is_scalar_tower R A M]
lemma lsmul_injective [no_zero_smul_divisors A M] {x : A} (hx : x β 0) :
function.injective (lsmul R M x) :=
smul_right_injective _ hx
end algebra
end ring
|
08fedf41a3ce6e81ea2e4500f249347db29bc4cd
|
a8a8012e62ebc4c8550b92736c0b20faab882ba0
|
/ccat.hlean
|
20d484a440b33d511e19eddedee4b0ce8165c396
|
[] |
no_license
|
fpvandoorn/Bergen-Lean
|
d02d173f79492498b0ee042ae6699a984108c6ef
|
40638f1e04b6c681858127e85546c9012b62ab63
|
refs/heads/master
| 1,610,398,839,774
| 1,484,840,344,000
| 1,484,840,344,000
| 79,229,751
| 0
| 2
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 3,231
|
hlean
|
-- A "concrete infinity-category", a subcategory of the inf-category of types
-- An object consists of a type plus some data
-- The arrows are the 'good' maps
import types.equiv
import .equiv
import .typeclass
open eq equiv is_equiv function typeclass
structure cCat.{u v} extends CC:typeclass.{u v} : Type.{(max u v)+1} :=
(good : Ξ {A B : obj CC} , (A β B) β Type.{u})
(idwd : Ξ (A : obj CC), good (Ξ» (x : A) , x))
(invwd : Ξ {A B : obj CC} (e : A β B) , good e β good eβ»ΒΉ)
(compwd : Ξ {A B C : obj CC} (g : B β C) (f : A β B), good g β good f β good (g β f))
(coh_unitr : Ξ {A B : obj CC} (g : A β B) (p : good g) ,
compwd g (Ξ» x , x) p (idwd A) = p)
namespace cCat
variables {CC : cCat}
structure arr (A B : obj CC) :=
(to_fun : A β B)
(wd : good CC to_fun)
infix ` β* `:30 := arr
attribute arr.to_fun [coercion]
definition arr_inj {A B : obj CC} {f g : A β B} {p : good CC f} {q : good CC g}
(f_is_g : f = g) (p_is_q : p =[ f_is_g ] q) : arr.mk f p = arr.mk g q :=
begin
induction f_is_g,
apply congr_arg _ _ (arr.mk f),
apply eq_of_pathover_idp p_is_q
end
definition arr_eta {A B : obj CC} (f : arr A B) : f = arr.mk (arr.to_fun f) (arr.wd f) :=
begin
induction f,
reflexivity
end
definition arr_inj' {A B : obj CC} {f g : A β* B} (p : arr.to_fun f = arr.to_fun g) (q : arr.wd f =[ p ] arr.wd g) : f = g :=
begin
transitivity _,
apply arr_eta,
transitivity _,
apply arr_inj,
exact q,
symmetry,
exact arr_eta g
end
definition id (A : obj CC) : A β* A :=
arr.mk (Ξ» x , x) (idwd CC A)
definition comp {A B C : obj CC} (g : B β* C) (f : A β* B) : A β* C :=
begin
apply arr.mk (g β f),
apply compwd CC g f (arr.wd g) (arr.wd f)
end
infix ` β* `:50 := comp
definition unitr {A B : obj CC} (f : A β* B) : f β* id A = f :=
begin
fapply arr_inj',
reflexivity,
apply pathover_idp_of_eq,
apply coh_unitr
end
structure cequiv (A B : obj CC) extends e:equiv A B, arr A B
infix ` β* `:25 := cequiv
namespace cequiv
variables {A B : obj CC}
protected definition cong {f g : A β B}
(is_equiv_f : is_equiv f) (is_equiv_g : is_equiv g)
(good_f : good CC f) (good_g : good CC g)
(p : f = g) : good_f =[ p ] good_g β
cequiv.mk f is_equiv_f good_f = cequiv.mk g is_equiv_g good_g :=
begin
induction p,
intros good_hom,
refine congr_arg2 is_equiv_f is_equiv_g _ _ (cequiv.mk f) _ _,
refine @eq_of_pathover_idp (A β B) is_equiv f is_equiv_f is_equiv_g _,
apply !is_trunc.is_prop.elimo,
exact @eq_of_pathover_idp (A β B) (@good CC A B) f good_f good_g good_hom
end
protected definition eta (f : A β* B) : cequiv.mk f (cequiv.to_is_equiv f) (cequiv.wd f) = f :=
begin
induction f,
reflexivity
end
protected definition symm [symm] [constructor] (f : A β* B) : B β* A :=
begin
fconstructor,
{ exact fβ»ΒΉα΅ },
{ apply is_equiv_inv },
{ apply invwd, exact arr.wd f }
end
end cequiv
end cCat open cCat
|
40413a2352c24e212f28bb8df1c3295a7addf75b
|
a0e23cfdd129a671bf3154ee1a8a3a72bf4c7940
|
/src/Lean/Compiler/IR/EmitC.lean
|
81f40e17d916e7ee987c4983054f90144b6e5430
|
[
"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
| 25,512
|
lean
|
/-
Copyright (c) 2019 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
import Lean.Runtime
import Lean.Compiler.NameMangling
import Lean.Compiler.ExportAttr
import Lean.Compiler.InitAttr
import Lean.Compiler.IR.CompilerM
import Lean.Compiler.IR.EmitUtil
import Lean.Compiler.IR.NormIds
import Lean.Compiler.IR.SimpCase
import Lean.Compiler.IR.Boxing
namespace Lean.IR.EmitC
open ExplicitBoxing (requiresBoxedVersion mkBoxedName isBoxedName)
def leanMainFn := "_lean_main"
structure Context where
env : Environment
modName : Name
jpMap : JPParamsMap := {}
mainFn : FunId := arbitrary
mainParams : Array Param := #[]
abbrev M := ReaderT Context (EStateM String String)
def getEnv : M Environment := Context.env <$> read
def getModName : M Name := Context.modName <$> read
def getDecl (n : Name) : M Decl := do
let env β getEnv
match findEnvDecl env n with
| some d => pure d
| none => throw s!"unknown declaration '{n}'"
@[inline] def emit {Ξ± : Type} [ToString Ξ±] (a : Ξ±) : M Unit :=
modify fun out => out ++ toString a
@[inline] def emitLn {Ξ± : Type} [ToString Ξ±] (a : Ξ±) : M Unit := do
emit a; emit "\n"
def emitLns {Ξ± : Type} [ToString Ξ±] (as : List Ξ±) : M Unit :=
as.forM fun a => emitLn a
def argToCString (x : Arg) : String :=
match x with
| Arg.var x => toString x
| _ => "lean_box(0)"
def emitArg (x : Arg) : M Unit :=
emit (argToCString x)
def toCType : IRType β String
| IRType.float => "double"
| IRType.uint8 => "uint8_t"
| IRType.uint16 => "uint16_t"
| IRType.uint32 => "uint32_t"
| IRType.uint64 => "uint64_t"
| IRType.usize => "size_t"
| IRType.object => "lean_object*"
| IRType.tobject => "lean_object*"
| IRType.irrelevant => "lean_object*"
| IRType.struct _ _ => panic! "not implemented yet"
| IRType.union _ _ => panic! "not implemented yet"
def throwInvalidExportName {Ξ± : Type} (n : Name) : M Ξ± :=
throw s!"invalid export name '{n}'"
def toCName (n : Name) : M String := do
let env β getEnv;
-- TODO: we should support simple export names only
match getExportNameFor env n with
| some (Name.str Name.anonymous s _) => pure s
| some _ => throwInvalidExportName n
| none => if n == `main then pure leanMainFn else pure n.mangle
def emitCName (n : Name) : M Unit :=
toCName n >>= emit
def toCInitName (n : Name) : M String := do
let env β getEnv;
-- TODO: we should support simple export names only
match getExportNameFor env n with
| some (Name.str Name.anonymous s _) => pure $ "_init_" ++ s
| some _ => throwInvalidExportName n
| none => pure ("_init_" ++ n.mangle)
def emitCInitName (n : Name) : M Unit :=
toCInitName n >>= emit
def emitFnDeclAux (decl : Decl) (cppBaseName : String) (addExternForConsts : Bool) : M Unit := do
let ps := decl.params
let env β getEnv
if ps.isEmpty then
if isClosedTermName env decl.name then emit "static "
else if addExternForConsts then emit "extern "
emit (toCType decl.resultType ++ " " ++ cppBaseName)
unless ps.isEmpty do
emit "("
-- We omit irrelevant parameters for extern constants
let ps := if isExternC env decl.name then ps.filter (fun p => !p.ty.isIrrelevant) else ps
if ps.size > closureMaxArgs && isBoxedName decl.name then
emit "lean_object**"
else
ps.size.forM fun i => do
if i > 0 then emit ", "
emit (toCType ps[i].ty)
emit ")"
emitLn ";"
def emitFnDecl (decl : Decl) (addExternForConsts : Bool) : M Unit := do
let cppBaseName β toCName decl.name
emitFnDeclAux decl cppBaseName addExternForConsts
def emitExternDeclAux (decl : Decl) (cNameStr : String) : M Unit := do
let cName := Name.mkSimple cNameStr
let env β getEnv
let extC := isExternC env decl.name
emitFnDeclAux decl cNameStr (!extC)
def emitFnDecls : M Unit := do
let env β getEnv
let decls := getDecls env
let modDecls : NameSet := decls.foldl (fun s d => s.insert d.name) {}
let usedDecls : NameSet := decls.foldl (fun s d => collectUsedDecls env d (s.insert d.name)) {}
let usedDecls := usedDecls.toList
usedDecls.forM fun n => do
let decl β getDecl n;
match getExternNameFor env `c decl.name with
| some cName => emitExternDeclAux decl cName
| none => emitFnDecl decl (!modDecls.contains n)
def emitMainFn : M Unit := do
let d β getDecl `main
match d with
| Decl.fdecl (f := f) (xs := xs) (type := t) (body := b) .. => do
unless xs.size == 2 || xs.size == 1 do throw "invalid main function, incorrect arity when generating code"
let env β getEnv
let usesLeanAPI := usesModuleFrom env `Lean
if usesLeanAPI then
emitLn "void lean_initialize();"
else
emitLn "void lean_initialize_runtime_module();";
emitLn "
#if defined(WIN32) || defined(_WIN32)
#include <windows.h>
#endif
int main(int argc, char ** argv) {
#if defined(WIN32) || defined(_WIN32)
SetErrorMode(SEM_FAILCRITICALERRORS);
#endif
lean_object* in; lean_object* res;";
if usesLeanAPI then
emitLn "lean_initialize();"
else
emitLn "lean_initialize_runtime_module();"
let modName β getModName
/- We disable panic messages because they do not mesh well with extracted closed terms.
See issue #534. We can remove this workaround after we implement issue #467. -/
emitLn "lean_set_panic_messages(false);"
emitLn ("res = " ++ mkModuleInitializationFunctionName modName ++ "(lean_io_mk_world());")
emitLn "lean_set_panic_messages(true);"
emitLns ["lean_io_mark_end_initialization();",
"if (lean_io_result_is_ok(res)) {",
"lean_dec_ref(res);",
"lean_init_task_manager();"];
if xs.size == 2 then
emitLns ["in = lean_box(0);",
"int i = argc;",
"while (i > 1) {",
" lean_object* n;",
" i--;",
" n = lean_alloc_ctor(1,2,0); lean_ctor_set(n, 0, lean_mk_string(argv[i])); lean_ctor_set(n, 1, in);",
" in = n;",
"}"]
emitLn ("res = " ++ leanMainFn ++ "(in, lean_io_mk_world());")
else
emitLn ("res = " ++ leanMainFn ++ "(lean_io_mk_world());")
emitLn "}"
emitLns ["if (lean_io_result_is_ok(res)) {",
" int ret = lean_unbox(lean_io_result_get_value(res));",
" lean_dec_ref(res);",
" return ret;",
"} else {",
" lean_io_result_show_error(res);",
" lean_dec_ref(res);",
" return 1;",
"}"]
emitLn "}"
| other => throw "function declaration expected"
def hasMainFn : M Bool := do
let env β getEnv
let decls := getDecls env
pure $ decls.any (fun d => d.name == `main)
def emitMainFnIfNeeded : M Unit := do
if (β hasMainFn) then emitMainFn
def emitFileHeader : M Unit := do
let env β getEnv
let modName β getModName
emitLn "// Lean compiler output"
emitLn ("// Module: " ++ toString modName)
emit "// Imports:"
env.imports.forM fun m => emit (" " ++ toString m)
emitLn ""
emitLn "#include <lean/lean.h>"
emitLns [
"#if defined(__clang__)",
"#pragma clang diagnostic ignored \"-Wunused-parameter\"",
"#pragma clang diagnostic ignored \"-Wunused-label\"",
"#elif defined(__GNUC__) && !defined(__CLANG__)",
"#pragma GCC diagnostic ignored \"-Wunused-parameter\"",
"#pragma GCC diagnostic ignored \"-Wunused-label\"",
"#pragma GCC diagnostic ignored \"-Wunused-but-set-variable\"",
"#endif",
"#ifdef __cplusplus",
"extern \"C\" {",
"#endif"
]
def emitFileFooter : M Unit :=
emitLns [
"#ifdef __cplusplus",
"}",
"#endif"
]
def throwUnknownVar {Ξ± : Type} (x : VarId) : M Ξ± :=
throw s!"unknown variable '{x}'"
def getJPParams (j : JoinPointId) : M (Array Param) := do
let ctx β read;
match ctx.jpMap.find? j with
| some ps => pure ps
| none => throw "unknown join point"
def declareVar (x : VarId) (t : IRType) : M Unit := do
emit (toCType t); emit " "; emit x; emit "; "
def declareParams (ps : Array Param) : M Unit :=
ps.forM fun p => declareVar p.x p.ty
partial def declareVars : FnBody β Bool β M Bool
| e@(FnBody.vdecl x t _ b), d => do
let ctx β read
if isTailCallTo ctx.mainFn e then
pure d
else
declareVar x t; declareVars b true
| FnBody.jdecl j xs _ b, d => do declareParams xs; declareVars b (d || xs.size > 0)
| e, d => if e.isTerminal then pure d else declareVars e.body d
def emitTag (x : VarId) (xType : IRType) : M Unit := do
if xType.isObj then do
emit "lean_obj_tag("; emit x; emit ")"
else
emit x
def isIf (alts : Array Alt) : Option (Nat Γ FnBody Γ FnBody) :=
if alts.size != 2 then none
else match alts[0] with
| Alt.ctor c b => some (c.cidx, b, alts[1].body)
| _ => none
def emitInc (x : VarId) (n : Nat) (checkRef : Bool) : M Unit := do
emit $
if checkRef then (if n == 1 then "lean_inc" else "lean_inc_n")
else (if n == 1 then "lean_inc_ref" else "lean_inc_ref_n")
emit "("; emit x
if n != 1 then emit ", "; emit n
emitLn ");"
def emitDec (x : VarId) (n : Nat) (checkRef : Bool) : M Unit := do
emit (if checkRef then "lean_dec" else "lean_dec_ref");
emit "("; emit x;
if n != 1 then emit ", "; emit n
emitLn ");"
def emitDel (x : VarId) : M Unit := do
emit "lean_free_object("; emit x; emitLn ");"
def emitSetTag (x : VarId) (i : Nat) : M Unit := do
emit "lean_ctor_set_tag("; emit x; emit ", "; emit i; emitLn ");"
def emitSet (x : VarId) (i : Nat) (y : Arg) : M Unit := do
emit "lean_ctor_set("; emit x; emit ", "; emit i; emit ", "; emitArg y; emitLn ");"
def emitOffset (n : Nat) (offset : Nat) : M Unit := do
if n > 0 then
emit "sizeof(void*)*"; emit n;
if offset > 0 then emit " + "; emit offset
else
emit offset
def emitUSet (x : VarId) (n : Nat) (y : VarId) : M Unit := do
emit "lean_ctor_set_usize("; emit x; emit ", "; emit n; emit ", "; emit y; emitLn ");"
def emitSSet (x : VarId) (n : Nat) (offset : Nat) (y : VarId) (t : IRType) : M Unit := do
match t with
| IRType.float => emit "lean_ctor_set_float"
| IRType.uint8 => emit "lean_ctor_set_uint8"
| IRType.uint16 => emit "lean_ctor_set_uint16"
| IRType.uint32 => emit "lean_ctor_set_uint32"
| IRType.uint64 => emit "lean_ctor_set_uint64"
| _ => throw "invalid instruction";
emit "("; emit x; emit ", "; emitOffset n offset; emit ", "; emit y; emitLn ");"
def emitJmp (j : JoinPointId) (xs : Array Arg) : M Unit := do
let ps β getJPParams j
unless xs.size == ps.size do throw "invalid goto"
xs.size.forM fun i => do
let p := ps[i]
let x := xs[i]
emit p.x; emit " = "; emitArg x; emitLn ";"
emit "goto "; emit j; emitLn ";"
def emitLhs (z : VarId) : M Unit := do
emit z; emit " = "
def emitArgs (ys : Array Arg) : M Unit :=
ys.size.forM fun i => do
if i > 0 then emit ", "
emitArg ys[i]
def emitCtorScalarSize (usize : Nat) (ssize : Nat) : M Unit := do
if usize == 0 then emit ssize
else if ssize == 0 then emit "sizeof(size_t)*"; emit usize
else emit "sizeof(size_t)*"; emit usize; emit " + "; emit ssize
def emitAllocCtor (c : CtorInfo) : M Unit := do
emit "lean_alloc_ctor("; emit c.cidx; emit ", "; emit c.size; emit ", "
emitCtorScalarSize c.usize c.ssize; emitLn ");"
def emitCtorSetArgs (z : VarId) (ys : Array Arg) : M Unit :=
ys.size.forM fun i => do
emit "lean_ctor_set("; emit z; emit ", "; emit i; emit ", "; emitArg ys[i]; emitLn ");"
def emitCtor (z : VarId) (c : CtorInfo) (ys : Array Arg) : M Unit := do
emitLhs z;
if c.size == 0 && c.usize == 0 && c.ssize == 0 then do
emit "lean_box("; emit c.cidx; emitLn ");"
else do
emitAllocCtor c; emitCtorSetArgs z ys
def emitReset (z : VarId) (n : Nat) (x : VarId) : M Unit := do
emit "if (lean_is_exclusive("; emit x; emitLn ")) {";
n.forM fun i => do
emit " lean_ctor_release("; emit x; emit ", "; emit i; emitLn ");"
emit " "; emitLhs z; emit x; emitLn ";";
emitLn "} else {";
emit " lean_dec_ref("; emit x; emitLn ");";
emit " "; emitLhs z; emitLn "lean_box(0);";
emitLn "}"
def emitReuse (z : VarId) (x : VarId) (c : CtorInfo) (updtHeader : Bool) (ys : Array Arg) : M Unit := do
emit "if (lean_is_scalar("; emit x; emitLn ")) {";
emit " "; emitLhs z; emitAllocCtor c;
emitLn "} else {";
emit " "; emitLhs z; emit x; emitLn ";";
if updtHeader then emit " lean_ctor_set_tag("; emit z; emit ", "; emit c.cidx; emitLn ");"
emitLn "}";
emitCtorSetArgs z ys
def emitProj (z : VarId) (i : Nat) (x : VarId) : M Unit := do
emitLhs z; emit "lean_ctor_get("; emit x; emit ", "; emit i; emitLn ");"
def emitUProj (z : VarId) (i : Nat) (x : VarId) : M Unit := do
emitLhs z; emit "lean_ctor_get_usize("; emit x; emit ", "; emit i; emitLn ");"
def emitSProj (z : VarId) (t : IRType) (n offset : Nat) (x : VarId) : M Unit := do
emitLhs z;
match t with
| IRType.float => emit "lean_ctor_get_float"
| IRType.uint8 => emit "lean_ctor_get_uint8"
| IRType.uint16 => emit "lean_ctor_get_uint16"
| IRType.uint32 => emit "lean_ctor_get_uint32"
| IRType.uint64 => emit "lean_ctor_get_uint64"
| _ => throw "invalid instruction"
emit "("; emit x; emit ", "; emitOffset n offset; emitLn ");"
def toStringArgs (ys : Array Arg) : List String :=
ys.toList.map argToCString
def emitSimpleExternalCall (f : String) (ps : Array Param) (ys : Array Arg) : M Unit := do
emit f; emit "("
-- We must remove irrelevant arguments to extern calls.
discard <| ys.size.foldM
(fun i (first : Bool) =>
if ps[i].ty.isIrrelevant then
pure first
else do
unless first do emit ", "
emitArg ys[i]
pure false)
true
emitLn ");"
pure ()
def emitExternCall (f : FunId) (ps : Array Param) (extData : ExternAttrData) (ys : Array Arg) : M Unit :=
match getExternEntryFor extData `c with
| some (ExternEntry.standard _ extFn) => emitSimpleExternalCall extFn ps ys
| some (ExternEntry.inline _ pat) => do emit (expandExternPattern pat (toStringArgs ys)); emitLn ";"
| some (ExternEntry.foreign _ extFn) => emitSimpleExternalCall extFn ps ys
| _ => throw s!"failed to emit extern application '{f}'"
def emitFullApp (z : VarId) (f : FunId) (ys : Array Arg) : M Unit := do
emitLhs z
let decl β getDecl f
match decl with
| Decl.extern _ ps _ extData => emitExternCall f ps extData ys
| _ =>
emitCName f
if ys.size > 0 then emit "("; emitArgs ys; emit ")"
emitLn ";"
def emitPartialApp (z : VarId) (f : FunId) (ys : Array Arg) : M Unit := do
let decl β getDecl f
let arity := decl.params.size;
emitLhs z; emit "lean_alloc_closure((void*)("; emitCName f; emit "), "; emit arity; emit ", "; emit ys.size; emitLn ");";
ys.size.forM fun i => do
let y := ys[i]
emit "lean_closure_set("; emit z; emit ", "; emit i; emit ", "; emitArg y; emitLn ");"
def emitApp (z : VarId) (f : VarId) (ys : Array Arg) : M Unit :=
if ys.size > closureMaxArgs then do
emit "{ lean_object* _aargs[] = {"; emitArgs ys; emitLn "};";
emitLhs z; emit "lean_apply_m("; emit f; emit ", "; emit ys.size; emitLn ", _aargs); }"
else do
emitLhs z; emit "lean_apply_"; emit ys.size; emit "("; emit f; emit ", "; emitArgs ys; emitLn ");"
def emitBoxFn (xType : IRType) : M Unit :=
match xType with
| IRType.usize => emit "lean_box_usize"
| IRType.uint32 => emit "lean_box_uint32"
| IRType.uint64 => emit "lean_box_uint64"
| IRType.float => emit "lean_box_float"
| other => emit "lean_box"
def emitBox (z : VarId) (x : VarId) (xType : IRType) : M Unit := do
emitLhs z; emitBoxFn xType; emit "("; emit x; emitLn ");"
def emitUnbox (z : VarId) (t : IRType) (x : VarId) : M Unit := do
emitLhs z;
match t with
| IRType.usize => emit "lean_unbox_usize"
| IRType.uint32 => emit "lean_unbox_uint32"
| IRType.uint64 => emit "lean_unbox_uint64"
| IRType.float => emit "lean_unbox_float"
| other => emit "lean_unbox";
emit "("; emit x; emitLn ");"
def emitIsShared (z : VarId) (x : VarId) : M Unit := do
emitLhs z; emit "!lean_is_exclusive("; emit x; emitLn ");"
def emitIsTaggedPtr (z : VarId) (x : VarId) : M Unit := do
emitLhs z; emit "!lean_is_scalar("; emit x; emitLn ");"
def toHexDigit (c : Nat) : String :=
String.singleton c.digitChar
def quoteString (s : String) : String :=
let q := "\"";
let q := s.foldl
(fun q c => q ++
if c == '\n' then "\\n"
else if c == '\n' then "\\t"
else if c == '\\' then "\\\\"
else if c == '\"' then "\\\""
else if c.toNat <= 31 then
"\\x" ++ toHexDigit (c.toNat / 16) ++ toHexDigit (c.toNat % 16)
-- TODO(Leo): we should use `\unnnn` for escaping unicode characters.
else String.singleton c)
q;
q ++ "\""
def emitNumLit (t : IRType) (v : Nat) : M Unit := do
if t.isObj then
if v < UInt32.size then
emit "lean_unsigned_to_nat("; emit v; emit "u)"
else
emit "lean_cstr_to_nat(\""; emit v; emit "\")"
else
emit v
def emitLit (z : VarId) (t : IRType) (v : LitVal) : M Unit := do
emitLhs z;
match v with
| LitVal.num v => emitNumLit t v; emitLn ";"
| LitVal.str v => emit "lean_mk_string("; emit (quoteString v); emitLn ");"
def emitVDecl (z : VarId) (t : IRType) (v : Expr) : M Unit :=
match v with
| Expr.ctor c ys => emitCtor z c ys
| Expr.reset n x => emitReset z n x
| Expr.reuse x c u ys => emitReuse z x c u ys
| Expr.proj i x => emitProj z i x
| Expr.uproj i x => emitUProj z i x
| Expr.sproj n o x => emitSProj z t n o x
| Expr.fap c ys => emitFullApp z c ys
| Expr.pap c ys => emitPartialApp z c ys
| Expr.ap x ys => emitApp z x ys
| Expr.box t x => emitBox z x t
| Expr.unbox x => emitUnbox z t x
| Expr.isShared x => emitIsShared z x
| Expr.isTaggedPtr x => emitIsTaggedPtr z x
| Expr.lit v => emitLit z t v
def isTailCall (x : VarId) (v : Expr) (b : FnBody) : M Bool := do
let ctx β read;
match v, b with
| Expr.fap f _, FnBody.ret (Arg.var y) => pure $ f == ctx.mainFn && x == y
| _, _ => pure false
def paramEqArg (p : Param) (x : Arg) : Bool :=
match x with
| Arg.var x => p.x == x
| _ => false
/-
Given `[p_0, ..., p_{n-1}]`, `[y_0, ..., y_{n-1}]`, representing the assignments
```
p_0 := y_0,
...
p_{n-1} := y_{n-1}
```
Return true iff we have `(i, j)` where `j > i`, and `y_j == p_i`.
That is, we have
```
p_i := y_i,
...
p_j := p_i, -- p_i was overwritten above
```
-/
def overwriteParam (ps : Array Param) (ys : Array Arg) : Bool :=
let n := ps.size;
n.any $ fun i =>
let p := ps[i]
(i+1, n).anyI fun j => paramEqArg p ys[j]
def emitTailCall (v : Expr) : M Unit :=
match v with
| Expr.fap _ ys => do
let ctx β read
let ps := ctx.mainParams
unless ps.size == ys.size do throw "invalid tail call"
if overwriteParam ps ys then
emitLn "{"
ps.size.forM fun i => do
let p := ps[i]
let y := ys[i]
unless paramEqArg p y do
emit (toCType p.ty); emit " _tmp_"; emit i; emit " = "; emitArg y; emitLn ";"
ps.size.forM fun i => do
let p := ps[i]
let y := ys[i]
unless paramEqArg p y do emit p.x; emit " = _tmp_"; emit i; emitLn ";"
emitLn "}"
else
ys.size.forM fun i => do
let p := ps[i]
let y := ys[i]
unless paramEqArg p y do emit p.x; emit " = "; emitArg y; emitLn ";"
emitLn "goto _start;"
| _ => throw "bug at emitTailCall"
mutual
partial def emitIf (x : VarId) (xType : IRType) (tag : Nat) (t : FnBody) (e : FnBody) : M Unit := do
emit "if ("; emitTag x xType; emit " == "; emit tag; emitLn ")";
emitFnBody t;
emitLn "else";
emitFnBody e
partial def emitCase (x : VarId) (xType : IRType) (alts : Array Alt) : M Unit :=
match isIf alts with
| some (tag, t, e) => emitIf x xType tag t e
| _ => do
emit "switch ("; emitTag x xType; emitLn ") {";
let alts := ensureHasDefault alts;
alts.forM fun alt => do
match alt with
| Alt.ctor c b => emit "case "; emit c.cidx; emitLn ":"; emitFnBody b
| Alt.default b => emitLn "default: "; emitFnBody b
emitLn "}"
partial def emitBlock (b : FnBody) : M Unit := do
match b with
| FnBody.jdecl j xs v b => emitBlock b
| d@(FnBody.vdecl x t v b) =>
let ctx β read
if isTailCallTo ctx.mainFn d then
emitTailCall v
else
emitVDecl x t v
emitBlock b
| FnBody.inc x n c p b =>
unless p do emitInc x n c
emitBlock b
| FnBody.dec x n c p b =>
unless p do emitDec x n c
emitBlock b
| FnBody.del x b => emitDel x; emitBlock b
| FnBody.setTag x i b => emitSetTag x i; emitBlock b
| FnBody.set x i y b => emitSet x i y; emitBlock b
| FnBody.uset x i y b => emitUSet x i y; emitBlock b
| FnBody.sset x i o y t b => emitSSet x i o y t; emitBlock b
| FnBody.mdata _ b => emitBlock b
| FnBody.ret x => emit "return "; emitArg x; emitLn ";"
| FnBody.case _ x xType alts => emitCase x xType alts
| FnBody.jmp j xs => emitJmp j xs
| FnBody.unreachable => emitLn "lean_internal_panic_unreachable();"
partial def emitJPs : FnBody β M Unit
| FnBody.jdecl j xs v b => do emit j; emitLn ":"; emitFnBody v; emitJPs b
| e => do unless e.isTerminal do emitJPs e.body
partial def emitFnBody (b : FnBody) : M Unit := do
emitLn "{"
let declared β declareVars b false
if declared then emitLn ""
emitBlock b
emitJPs b
emitLn "}"
end
def emitDeclAux (d : Decl) : M Unit := do
let env β getEnv
let (vMap, jpMap) := mkVarJPMaps d
withReader (fun ctx => { ctx with jpMap := jpMap }) do
unless hasInitAttr env d.name do
match d with
| Decl.fdecl (f := f) (xs := xs) (type := t) (body := b) .. =>
let baseName β toCName f;
if xs.size == 0 then
emit "static "
emit (toCType t); emit " ";
if xs.size > 0 then
emit baseName;
emit "(";
if xs.size > closureMaxArgs && isBoxedName d.name then
emit "lean_object** _args"
else
xs.size.forM fun i => do
if i > 0 then emit ", "
let x := xs[i]
emit (toCType x.ty); emit " "; emit x.x
emit ")"
else
emit ("_init_" ++ baseName ++ "()")
emitLn " {";
if xs.size > closureMaxArgs && isBoxedName d.name then
xs.size.forM fun i => do
let x := xs[i]
emit "lean_object* "; emit x.x; emit " = _args["; emit i; emitLn "];"
emitLn "_start:";
withReader (fun ctx => { ctx with mainFn := f, mainParams := xs }) (emitFnBody b);
emitLn "}"
| _ => pure ()
def emitDecl (d : Decl) : M Unit := do
let d := d.normalizeIds; -- ensure we don't have gaps in the variable indices
try
emitDeclAux d
catch err =>
throw s!"{err}\ncompiling:\n{d}"
def emitFns : M Unit := do
let env β getEnv;
let decls := getDecls env;
decls.reverse.forM emitDecl
def emitMarkPersistent (d : Decl) (n : Name) : M Unit := do
if d.resultType.isObj then
emit "lean_mark_persistent("
emitCName n
emitLn ");"
def emitDeclInit (d : Decl) : M Unit := do
let env β getEnv
let n := d.name
if isIOUnitInitFn env n then
emit "res = "; emitCName n; emitLn "(lean_io_mk_world());"
emitLn "if (lean_io_result_is_error(res)) return res;"
emitLn "lean_dec_ref(res);"
else if d.params.size == 0 then
match getInitFnNameFor? env d.name with
| some initFn =>
emit "res = "; emitCName initFn; emitLn "(lean_io_mk_world());"
emitLn "if (lean_io_result_is_error(res)) return res;"
emitCName n; emitLn " = lean_io_result_get_value(res);"
emitMarkPersistent d n
emitLn "lean_dec_ref(res);"
| _ =>
emitCName n; emit " = "; emitCInitName n; emitLn "();"; emitMarkPersistent d n
def emitInitFn : M Unit := do
let env β getEnv
let modName β getModName
env.imports.forM fun imp => emitLn ("lean_object* " ++ mkModuleInitializationFunctionName imp.module ++ "(lean_object*);")
emitLns [
"static bool _G_initialized = false;",
"lean_object* " ++ mkModuleInitializationFunctionName modName ++ "(lean_object* w) {",
"lean_object * res;",
"if (_G_initialized) return lean_io_result_mk_ok(lean_box(0));",
"_G_initialized = true;"
]
env.imports.forM fun imp => emitLns [
"res = " ++ mkModuleInitializationFunctionName imp.module ++ "(lean_io_mk_world());",
"if (lean_io_result_is_error(res)) return res;",
"lean_dec_ref(res);"]
let decls := getDecls env
decls.reverse.forM emitDeclInit
emitLns ["return lean_io_result_mk_ok(lean_box(0));", "}"]
def main : M Unit := do
emitFileHeader
emitFnDecls
emitFns
emitInitFn
emitMainFnIfNeeded
emitFileFooter
end EmitC
@[export lean_ir_emit_c]
def emitC (env : Environment) (modName : Name) : Except String String :=
match (EmitC.main { env := env, modName := modName }).run "" with
| EStateM.Result.ok _ s => Except.ok s
| EStateM.Result.error err _ => Except.error err
end Lean.IR
|
6567599d52b8ceffc308a991182af486e9d57acd
|
4727251e0cd73359b15b664c3170e5d754078599
|
/src/algebra/quandle.lean
|
866d9c0752fe89d7d449250e0af588251cfabc0d
|
[
"Apache-2.0"
] |
permissive
|
Vierkantor/mathlib
|
0ea59ac32a3a43c93c44d70f441c4ee810ccceca
|
83bc3b9ce9b13910b57bda6b56222495ebd31c2f
|
refs/heads/master
| 1,658,323,012,449
| 1,652,256,003,000
| 1,652,256,003,000
| 209,296,341
| 0
| 1
|
Apache-2.0
| 1,568,807,655,000
| 1,568,807,655,000
| null |
UTF-8
|
Lean
| false
| false
| 24,691
|
lean
|
/-
Copyright (c) 2020 Kyle Miller. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kyle Miller
-/
import algebra.hom.equiv
import data.zmod.basic
import tactic.group
/-!
# Racks and Quandles
This file defines racks and quandles, algebraic structures for sets
that bijectively act on themselves with a self-distributivity
property. If `R` is a rack and `act : R β (R β R)` is the self-action,
then the self-distributivity is, equivalently, that
```
act (act x y) = act x * act y * (act x)β»ΒΉ
```
where multiplication is composition in `R β R` as a group.
Quandles are racks such that `act x x = x` for all `x`.
One example of a quandle (not yet in mathlib) is the action of a Lie
algebra on itself, defined by `act x y = Ad (exp x) y`.
Quandles and racks were independently developed by multiple
mathematicians. David Joyce introduced quandles in his thesis
[Joyce1982] to define an algebraic invariant of knot and link
complements that is analogous to the fundamental group of the
exterior, and he showed that the quandle associated to an oriented
knot is invariant up to orientation-reversed mirror image. Racks were
used by Fenn and Rourke for framed codimension-2 knots and
links.[FennRourke1992]
The name "rack" came from wordplay by Conway and Wraith for the "wrack
and ruin" of forgetting everything but the conjugation operation for a
group.
## Main definitions
* `shelf` is a type with a self-distributive action
* `rack` is a shelf whose action for each element is invertible
* `quandle` is a rack whose action for an element fixes that element
* `quandle.conj` defines a quandle of a group acting on itself by conjugation.
* `shelf_hom` is homomorphisms of shelves, racks, and quandles.
* `rack.envel_group` gives the universal group the rack maps to as a conjugation quandle.
* `rack.opp` gives the rack with the action replaced by its inverse.
## Main statements
* `rack.envel_group` is left adjoint to `quandle.conj` (`to_envel_group.map`).
The universality statements are `to_envel_group.univ` and `to_envel_group.univ_uniq`.
## Notation
The following notation is localized in `quandles`:
* `x β y` is `shelf.act x y`
* `x ββ»ΒΉ y` is `rack.inv_act x y`
* `S ββ S'` is `shelf_hom S S'`
Use `open_locale quandles` to use these.
## Todo
* If `g` is the Lie algebra of a Lie group `G`, then `(x β y) = Ad (exp x) x` forms a quandle.
* If `X` is a symmetric space, then each point has a corresponding involution that acts on `X`,
forming a quandle.
* Alexander quandle with `a β b = t * b + (1 - t) * b`, with `a` and `b` elements
of a module over `Z[t,tβ»ΒΉ]`.
* If `G` is a group, `H` a subgroup, and `z` in `H`, then there is a quandle `(G/H;z)` defined by
`yH β xH = yzyβ»ΒΉxH`. Every homogeneous quandle (i.e., a quandle `Q` whose automorphism group acts
transitively on `Q` as a set) is isomorphic to such a quandle.
There is a generalization to this arbitrary quandles in [Joyce's paper (Theorem 7.2)][Joyce1982].
## Tags
rack, quandle
-/
open mul_opposite
universes u v
/--
A *shelf* is a structure with a self-distributive binary operation.
The binary operation is regarded as a left action of the type on itself.
-/
class shelf (Ξ± : Type u) :=
(act : Ξ± β Ξ± β Ξ±)
(self_distrib : β {x y z : Ξ±}, act x (act y z) = act (act x y) (act x z))
/--
The type of homomorphisms between shelves.
This is also the notion of rack and quandle homomorphisms.
-/
@[ext]
structure shelf_hom (Sβ : Type*) (Sβ : Type*) [shelf Sβ] [shelf Sβ] :=
(to_fun : Sβ β Sβ)
(map_act' : β {x y : Sβ}, to_fun (shelf.act x y) = shelf.act (to_fun x) (to_fun y))
/--
A *rack* is an automorphic set (a set with an action on itself by
bijections) that is self-distributive. It is a shelf such that each
element's action is invertible.
The notations `x β y` and `x ββ»ΒΉ y` denote the action and the
inverse action, respectively, and they are right associative.
-/
class rack (Ξ± : Type u) extends shelf Ξ± :=
(inv_act : Ξ± β Ξ± β Ξ±)
(left_inv : β x, function.left_inverse (inv_act x) (act x))
(right_inv : β x, function.right_inverse (inv_act x) (act x))
localized "infixr ` β `:65 := shelf.act" in quandles
localized "infixr ` ββ»ΒΉ `:65 := rack.inv_act" in quandles
localized "infixr ` ββ `:25 := shelf_hom" in quandles
open_locale quandles
namespace rack
variables {R : Type*} [rack R]
lemma self_distrib {x y z : R} : x β (y β z) = (x β y) β (x β z) :=
shelf.self_distrib
/--
A rack acts on itself by equivalences.
-/
def act (x : R) : R β R :=
{ to_fun := shelf.act x,
inv_fun := inv_act x,
left_inv := left_inv x,
right_inv := right_inv x }
@[simp] lemma act_apply (x y : R) : act x y = x β y := rfl
@[simp] lemma act_symm_apply (x y : R) : (act x).symm y = x ββ»ΒΉ y := rfl
@[simp] lemma inv_act_apply (x y : R) : (act x)β»ΒΉ y = x ββ»ΒΉ y := rfl
@[simp] lemma inv_act_act_eq (x y : R) : x ββ»ΒΉ x β y = y := left_inv x y
@[simp] lemma act_inv_act_eq (x y : R) : x β x ββ»ΒΉ y = y := right_inv x y
lemma left_cancel (x : R) {y y' : R} : x β y = x β y' β y = y' :=
by { split, apply (act x).injective, rintro rfl, refl }
lemma left_cancel_inv (x : R) {y y' : R} : x ββ»ΒΉ y = x ββ»ΒΉ y' β y = y' :=
by { split, apply (act x).symm.injective, rintro rfl, refl }
lemma self_distrib_inv {x y z : R} : x ββ»ΒΉ y ββ»ΒΉ z = (x ββ»ΒΉ y) ββ»ΒΉ (x ββ»ΒΉ z) :=
begin
rw [βleft_cancel (x ββ»ΒΉ y), right_inv, βleft_cancel x, right_inv, self_distrib],
repeat {rw right_inv },
end
/--
The *adjoint action* of a rack on itself is `op'`, and the adjoint
action of `x β y` is the conjugate of the action of `y` by the action
of `x`. It is another way to understand the self-distributivity axiom.
This is used in the natural rack homomorphism `to_conj` from `R` to
`conj (R β R)` defined by `op'`.
-/
lemma ad_conj {R : Type*} [rack R] (x y : R) :
act (x β y) = act x * act y * (act x)β»ΒΉ :=
begin
apply @mul_right_cancel _ _ _ (act x), ext z,
simp only [inv_mul_cancel_right],
apply self_distrib.symm,
end
/--
The opposite rack, swapping the roles of `β` and `ββ»ΒΉ`.
-/
instance opposite_rack : rack Rα΅α΅α΅ :=
{ act := Ξ» x y, op (inv_act (unop x) (unop y)),
self_distrib := mul_opposite.rec $ Ξ» x, mul_opposite.rec $ Ξ» y, mul_opposite.rec $ Ξ» z, begin
simp only [unop_op, op_inj],
exact self_distrib_inv,
end,
inv_act := Ξ» x y, op (shelf.act (unop x) (unop y)),
left_inv := mul_opposite.rec $ Ξ» x, mul_opposite.rec $ Ξ» y, by simp,
right_inv := mul_opposite.rec $ Ξ» x, mul_opposite.rec $ Ξ» y, by simp }
@[simp] lemma op_act_op_eq {x y : R} : (op x) β (op y) = op (x ββ»ΒΉ y) := rfl
@[simp] lemma op_inv_act_op_eq {x y : R} : (op x) ββ»ΒΉ (op y) = op (x β y) := rfl
@[simp]
lemma self_act_act_eq {x y : R} : (x β x) β y = x β y :=
by { rw [βright_inv x y, βself_distrib] }
@[simp]
lemma self_inv_act_inv_act_eq {x y : R} : (x ββ»ΒΉ x) ββ»ΒΉ y = x ββ»ΒΉ y :=
by { have h := @self_act_act_eq _ _ (op x) (op y), simpa using h }
@[simp]
lemma self_act_inv_act_eq {x y : R} : (x β x) ββ»ΒΉ y = x ββ»ΒΉ y :=
by { rw βleft_cancel (x β x), rw right_inv, rw self_act_act_eq, rw right_inv }
@[simp]
lemma self_inv_act_act_eq {x y : R} : (x ββ»ΒΉ x) β y = x β y :=
by { have h := @self_act_inv_act_eq _ _ (op x) (op y), simpa using h }
lemma self_act_eq_iff_eq {x y : R} : x β x = y β y β x = y :=
begin
split, swap, rintro rfl, refl,
intro h,
transitivity (x β x) ββ»ΒΉ (x β x),
rw [βleft_cancel (x β x), right_inv, self_act_act_eq],
rw [h, βleft_cancel (y β y), right_inv, self_act_act_eq],
end
lemma self_inv_act_eq_iff_eq {x y : R} : x ββ»ΒΉ x = y ββ»ΒΉ y β x = y :=
by { have h := @self_act_eq_iff_eq _ _ (op x) (op y), simpa using h }
/--
The map `x β¦ x β x` is a bijection. (This has applications for the
regular isotopy version of the Reidemeister I move for knot diagrams.)
-/
def self_apply_equiv (R : Type*) [rack R] : R β R :=
{ to_fun := Ξ» x, x β x,
inv_fun := Ξ» x, x ββ»ΒΉ x,
left_inv := Ξ» x, by simp,
right_inv := Ξ» x, by simp }
/--
An involutory rack is one for which `rack.op R x` is an involution for every x.
-/
def is_involutory (R : Type*) [rack R] : Prop := β x : R, function.involutive (shelf.act x)
lemma involutory_inv_act_eq_act {R : Type*} [rack R] (h : is_involutory R) (x y : R) :
x ββ»ΒΉ y = x β y :=
begin
rw [βleft_cancel x, right_inv],
exact ((h x).left_inverse y).symm,
end
/--
An abelian rack is one for which the mediality axiom holds.
-/
def is_abelian (R : Type*) [rack R] : Prop :=
β (x y z w : R), (x β y) β (z β w) = (x β z) β (y β w)
/--
Associative racks are uninteresting.
-/
lemma assoc_iff_id {R : Type*} [rack R] {x y z : R} :
x β y β z = (x β y) β z β x β z = z :=
by { rw self_distrib, rw left_cancel }
end rack
namespace shelf_hom
variables {Sβ : Type*} {Sβ : Type*} {Sβ : Type*} [shelf Sβ] [shelf Sβ] [shelf Sβ]
instance : has_coe_to_fun (Sβ ββ Sβ) (Ξ» _, Sβ β Sβ) := β¨shelf_hom.to_funβ©
@[simp] lemma to_fun_eq_coe (f : Sβ ββ Sβ) : f.to_fun = f := rfl
@[simp] lemma map_act (f : Sβ ββ Sβ) {x y : Sβ} : f (x β y) = f x β f y := map_act' f
/-- The identity homomorphism -/
def id (S : Type*) [shelf S] : S ββ S :=
{ to_fun := id,
map_act' := by simp }
instance inhabited (S : Type*) [shelf S] : inhabited (S ββ S) :=
β¨id Sβ©
/-- The composition of shelf homomorphisms -/
def comp (g : Sβ ββ Sβ) (f : Sβ ββ Sβ) : Sβ ββ Sβ :=
{ to_fun := g.to_fun β f.to_fun,
map_act' := by simp }
@[simp]
lemma comp_apply (g : Sβ ββ Sβ) (f : Sβ ββ Sβ) (x : Sβ) :
(g.comp f) x = g (f x) := rfl
end shelf_hom
/--
A quandle is a rack such that each automorphism fixes its corresponding element.
-/
class quandle (Ξ± : Type*) extends rack Ξ± :=
(fix : β {x : Ξ±}, act x x = x)
namespace quandle
open rack
variables {Q : Type*} [quandle Q]
attribute [simp] fix
@[simp]
lemma fix_inv {x : Q} : x ββ»ΒΉ x = x :=
by { rw βleft_cancel x, simp }
instance opposite_quandle : quandle Qα΅α΅α΅ :=
{ fix := Ξ» x, by { induction x using mul_opposite.rec, simp } }
/--
The conjugation quandle of a group. Each element of the group acts by
the corresponding inner automorphism.
-/
@[nolint has_inhabited_instance]
def conj (G : Type*) := G
instance conj.quandle (G : Type*) [group G] : quandle (conj G) :=
{ act := (Ξ» x, @mul_aut.conj G _ x),
self_distrib := Ξ» x y z, begin
dsimp only [mul_equiv.coe_to_equiv, mul_aut.conj_apply, conj],
group,
end,
inv_act := (Ξ» x, (@mul_aut.conj G _ x).symm),
left_inv := Ξ» x y, by { dsimp [act, conj], group },
right_inv := Ξ» x y, by { dsimp [act, conj], group },
fix := Ξ» x, by simp }
@[simp]
lemma conj_act_eq_conj {G : Type*} [group G] (x y : conj G) :
x β y = ((x : G) * (y : G) * (x : G)β»ΒΉ : G) := rfl
lemma conj_swap {G : Type*} [group G] (x y : conj G) :
x β y = y β y β x = x :=
begin
dsimp [conj] at *, split,
repeat { intro h, conv_rhs { rw eq_mul_inv_of_mul_eq (eq_mul_inv_of_mul_eq h) }, simp, },
end
/--
`conj` is functorial
-/
def conj.map {G : Type*} {H : Type*} [group G] [group H] (f : G β* H) : conj G ββ conj H :=
{ to_fun := f,
map_act' := by simp }
instance {G : Type*} {H : Type*} [group G] [group H] : has_lift (G β* H) (conj G ββ conj H) :=
{ lift := conj.map }
/--
The dihedral quandle. This is the conjugation quandle of the dihedral group restrict to flips.
Used for Fox n-colorings of knots.
-/
@[nolint has_inhabited_instance]
def dihedral (n : β) := zmod n
/--
The operation for the dihedral quandle. It does not need to be an equivalence
because it is an involution (see `dihedral_act.inv`).
-/
def dihedral_act (n : β) (a : zmod n) : zmod n β zmod n :=
Ξ» b, 2 * a - b
lemma dihedral_act.inv (n : β) (a : zmod n) : function.involutive (dihedral_act n a) :=
by { intro b, dsimp [dihedral_act], ring }
instance (n : β) : quandle (dihedral n) :=
{ act := dihedral_act n,
self_distrib := Ξ» x y z, begin
dsimp [dihedral_act], ring,
end,
inv_act := dihedral_act n,
left_inv := Ξ» x, (dihedral_act.inv n x).left_inverse,
right_inv := Ξ» x, (dihedral_act.inv n x).right_inverse,
fix := Ξ» x, begin
dsimp [dihedral_act], ring,
end }
end quandle
namespace rack
/--
This is the natural rack homomorphism to the conjugation quandle of the group `R β R`
that acts on the rack.
-/
def to_conj (R : Type*) [rack R] : R ββ quandle.conj (R β R) :=
{ to_fun := act,
map_act' := ad_conj }
section envel_group
/-!
### Universal enveloping group of a rack
The universal enveloping group `envel_group R` of a rack `R` is the
universal group such that every rack homomorphism `R ββ conj G` is
induced by a unique group homomorphism `envel_group R β* G`.
For quandles, Joyce called this group `AdConj R`.
The `envel_group` functor is left adjoint to the `conj` forgetful
functor, and the way we construct the enveloping group is via a
technique that should work for left adjoints of forgetful functors in
general. It involves thinking a little about 2-categories, but the
payoff is that the map `envel_group R β* G` has a nice description.
Let's think of a group as being a one-object category. The first step
is to define `pre_envel_group`, which gives formal expressions for all
the 1-morphisms and includes the unit element, elements of `R`,
multiplication, and inverses. To introduce relations, the second step
is to define `pre_envel_group_rel'`, which gives formal expressions
for all 2-morphisms between the 1-morphisms. The 2-morphisms include
associativity, multiplication by the unit, multiplication by inverses,
compatibility with multiplication and inverses (`congr_mul` and
`congr_inv`), the axioms for an equivalence relation, and,
importantly, the relationship between conjugation and the rack action
(see `rack.ad_conj`).
None of this forms a 2-category yet, for example due to lack of
associativity of `trans`. The `pre_envel_group_rel` relation is a
`Prop`-valued version of `pre_envel_group_rel'`, and making it
`Prop`-valued essentially introduces enough 3-isomorphisms so that
every pair of compatible 2-morphisms is isomorphic. Now, while
composition in `pre_envel_group` does not strictly satisfy the category
axioms, `pre_envel_group` and `pre_envel_group_rel'` do form a weak
2-category.
Since we just want a 1-category, the last step is to quotient
`pre_envel_group` by `pre_envel_group_rel'`, and the result is the
group `envel_group`.
For a homomorphism `f : R ββ conj G`, how does
`envel_group.map f : envel_group R β* G` work? Let's think of `G` as
being a 2-category with one object, a 1-morphism per element of `G`,
and a single 2-morphism called `eq.refl` for each 1-morphism. We
define the map using a "higher `quotient.lift`" -- not only do we
evaluate elements of `pre_envel_group` as expressions in `G` (this is
`to_envel_group.map_aux`), but we evaluate elements of
`pre_envel_group'` as expressions of 2-morphisms of `G` (this is
`to_envel_group.map_aux.well_def`). That is to say,
`to_envel_group.map_aux.well_def` recursively evaluates formal
expressions of 2-morphisms as equality proofs in `G`. Now that all
morphisms are accounted for, the map descends to a homomorphism
`envel_group R β* G`.
Note: `Type`-valued relations are not common. The fact it is
`Type`-valued is what makes `to_envel_group.map_aux.well_def` have
well-founded recursion.
-/
/--
Free generators of the enveloping group.
-/
inductive pre_envel_group (R : Type u) : Type u
| unit : pre_envel_group
| incl (x : R) : pre_envel_group
| mul (a b : pre_envel_group) : pre_envel_group
| inv (a : pre_envel_group) : pre_envel_group
instance pre_envel_group.inhabited (R : Type u) : inhabited (pre_envel_group R) :=
β¨pre_envel_group.unitβ©
open pre_envel_group
/--
Relations for the enveloping group. This is a type-valued relation because
`to_envel_group.map_aux.well_def` inducts on it to show `to_envel_group.map`
is well-defined. The relation `pre_envel_group_rel` is the `Prop`-valued version,
which is used to define `envel_group` itself.
-/
inductive pre_envel_group_rel' (R : Type u) [rack R] :
pre_envel_group R β pre_envel_group R β Type u
| refl {a : pre_envel_group R} : pre_envel_group_rel' a a
| symm {a b : pre_envel_group R} (hab : pre_envel_group_rel' a b) : pre_envel_group_rel' b a
| trans {a b c : pre_envel_group R}
(hab : pre_envel_group_rel' a b) (hbc : pre_envel_group_rel' b c) : pre_envel_group_rel' a c
| congr_mul {a b a' b' : pre_envel_group R}
(ha : pre_envel_group_rel' a a') (hb : pre_envel_group_rel' b b') :
pre_envel_group_rel' (mul a b) (mul a' b')
| congr_inv {a a' : pre_envel_group R} (ha : pre_envel_group_rel' a a') :
pre_envel_group_rel' (inv a) (inv a')
| assoc (a b c : pre_envel_group R) : pre_envel_group_rel' (mul (mul a b) c) (mul a (mul b c))
| one_mul (a : pre_envel_group R) : pre_envel_group_rel' (mul unit a) a
| mul_one (a : pre_envel_group R) : pre_envel_group_rel' (mul a unit) a
| mul_left_inv (a : pre_envel_group R) : pre_envel_group_rel' (mul (inv a) a) unit
| act_incl (x y : R) :
pre_envel_group_rel' (mul (mul (incl x) (incl y)) (inv (incl x))) (incl (x β y))
instance pre_envel_group_rel'.inhabited (R : Type u) [rack R] :
inhabited (pre_envel_group_rel' R unit unit) :=
β¨pre_envel_group_rel'.reflβ©
/--
The `pre_envel_group_rel` relation as a `Prop`. Used as the relation for `pre_envel_group.setoid`.
-/
inductive pre_envel_group_rel (R : Type u) [rack R] : pre_envel_group R β pre_envel_group R β Prop
| rel {a b : pre_envel_group R} (r : pre_envel_group_rel' R a b) : pre_envel_group_rel a b
/--
A quick way to convert a `pre_envel_group_rel'` to a `pre_envel_group_rel`.
-/
lemma pre_envel_group_rel'.rel {R : Type u} [rack R] {a b : pre_envel_group R} :
pre_envel_group_rel' R a b β pre_envel_group_rel R a b :=
pre_envel_group_rel.rel
@[refl]
lemma pre_envel_group_rel.refl {R : Type u} [rack R] {a : pre_envel_group R} :
pre_envel_group_rel R a a :=
pre_envel_group_rel.rel pre_envel_group_rel'.refl
@[symm]
lemma pre_envel_group_rel.symm {R : Type u} [rack R] {a b : pre_envel_group R} :
pre_envel_group_rel R a b β pre_envel_group_rel R b a
| β¨rβ© := r.symm.rel
@[trans]
lemma pre_envel_group_rel.trans {R : Type u} [rack R] {a b c : pre_envel_group R} :
pre_envel_group_rel R a b β pre_envel_group_rel R b c β pre_envel_group_rel R a c
| β¨rabβ© β¨rbcβ© := (rab.trans rbc).rel
instance pre_envel_group.setoid (R : Type*) [rack R] : setoid (pre_envel_group R) :=
{ r := pre_envel_group_rel R,
iseqv := begin
split, apply pre_envel_group_rel.refl,
split, apply pre_envel_group_rel.symm,
apply pre_envel_group_rel.trans
end }
/--
The universal enveloping group for the rack R.
-/
def envel_group (R : Type*) [rack R] := quotient (pre_envel_group.setoid R)
-- Define the `group` instances in two steps so `inv` can be inferred correctly.
-- TODO: is there a non-invasive way of defining the instance directly?
instance (R : Type*) [rack R] : div_inv_monoid (envel_group R) :=
{ mul := Ξ» a b, quotient.lift_onβ a b
(Ξ» a b, β¦pre_envel_group.mul a bβ§)
(Ξ» a b a' b' β¨haβ© β¨hbβ©,
quotient.sound (pre_envel_group_rel'.congr_mul ha hb).rel),
one := β¦unitβ§,
inv := Ξ» a, quotient.lift_on a
(Ξ» a, β¦pre_envel_group.inv aβ§)
(Ξ» a a' β¨haβ©,
quotient.sound (pre_envel_group_rel'.congr_inv ha).rel),
mul_assoc := Ξ» a b c,
quotient.induction_onβ a b c (Ξ» a b c, quotient.sound (pre_envel_group_rel'.assoc a b c).rel),
one_mul := Ξ» a,
quotient.induction_on a (Ξ» a, quotient.sound (pre_envel_group_rel'.one_mul a).rel),
mul_one := Ξ» a,
quotient.induction_on a (Ξ» a, quotient.sound (pre_envel_group_rel'.mul_one a).rel),}
instance (R : Type*) [rack R] : group (envel_group R) :=
{ mul_left_inv := Ξ» a,
quotient.induction_on a (Ξ» a, quotient.sound (pre_envel_group_rel'.mul_left_inv a).rel),
.. envel_group.div_inv_monoid _ }
instance envel_group.inhabited (R : Type*) [rack R] : inhabited (envel_group R) := β¨1β©
/--
The canonical homomorphism from a rack to its enveloping group.
Satisfies universal properties given by `to_envel_group.map` and `to_envel_group.univ`.
-/
def to_envel_group (R : Type*) [rack R] : R ββ quandle.conj (envel_group R) :=
{ to_fun := Ξ» x, β¦incl xβ§,
map_act' := Ξ» x y, quotient.sound (pre_envel_group_rel'.act_incl x y).symm.rel }
/--
The preliminary definition of the induced map from the enveloping group.
See `to_envel_group.map`.
-/
def to_envel_group.map_aux {R : Type*} [rack R] {G : Type*} [group G]
(f : R ββ quandle.conj G) : pre_envel_group R β G
| unit := 1
| (incl x) := f x
| (mul a b) := to_envel_group.map_aux a * to_envel_group.map_aux b
| (inv a) := (to_envel_group.map_aux a)β»ΒΉ
namespace to_envel_group.map_aux
open pre_envel_group_rel'
/--
Show that `to_envel_group.map_aux` sends equivalent expressions to equal terms.
-/
lemma well_def {R : Type*} [rack R] {G : Type*} [group G] (f : R ββ quandle.conj G) :
Ξ {a b : pre_envel_group R}, pre_envel_group_rel' R a b β
to_envel_group.map_aux f a = to_envel_group.map_aux f b
| a b refl := rfl
| a b (symm h) := (well_def h).symm
| a b (trans hac hcb) := eq.trans (well_def hac) (well_def hcb)
| _ _ (congr_mul ha hb) := by { simp [to_envel_group.map_aux, well_def ha, well_def hb] }
| _ _ (congr_inv ha) := by { simp [to_envel_group.map_aux, well_def ha] }
| _ _ (assoc a b c) := by { apply mul_assoc }
| _ _ (one_mul a) := by { simp [to_envel_group.map_aux] }
| _ _ (mul_one a) := by { simp [to_envel_group.map_aux] }
| _ _ (mul_left_inv a) := by { simp [to_envel_group.map_aux] }
| _ _ (act_incl x y) := by { simp [to_envel_group.map_aux] }
end to_envel_group.map_aux
/--
Given a map from a rack to a group, lift it to being a map from the enveloping group.
More precisely, the `envel_group` functor is left adjoint to `quandle.conj`.
-/
def to_envel_group.map {R : Type*} [rack R] {G : Type*} [group G] :
(R ββ quandle.conj G) β (envel_group R β* G) :=
{ to_fun := Ξ» f,
{ to_fun := Ξ» x, quotient.lift_on x (to_envel_group.map_aux f)
(Ξ» a b β¨habβ©, to_envel_group.map_aux.well_def f hab),
map_one' := begin
change quotient.lift_on β¦rack.pre_envel_group.unitβ§ (to_envel_group.map_aux f) _ = 1,
simp [to_envel_group.map_aux],
end,
map_mul' := Ξ» x y, quotient.induction_onβ x y (Ξ» x y, begin
change quotient.lift_on β¦mul x yβ§ (to_envel_group.map_aux f) _ = _,
simp [to_envel_group.map_aux],
end) },
inv_fun := Ξ» F, (quandle.conj.map F).comp (to_envel_group R),
left_inv := Ξ» f, by { ext, refl },
right_inv := Ξ» F, monoid_hom.ext $ Ξ» x, quotient.induction_on x $ Ξ» x, begin
induction x,
{ exact F.map_one.symm, },
{ refl, },
{ have hm : β¦x_a.mul x_bβ§ = @has_mul.mul (envel_group R) _ β¦x_aβ§ β¦x_bβ§ := rfl,
rw [hm, F.map_mul, monoid_hom.map_mul, βx_ih_a, βx_ih_b] },
{ have hm : β¦x_a.invβ§ = @has_inv.inv (envel_group R) _ β¦x_aβ§ := rfl,
rw [hm, F.map_inv, monoid_hom.map_inv, x_ih], }
end, }
/--
Given a homomorphism from a rack to a group, it factors through the enveloping group.
-/
lemma to_envel_group.univ (R : Type*) [rack R] (G : Type*) [group G]
(f : R ββ quandle.conj G) :
(quandle.conj.map (to_envel_group.map f)).comp (to_envel_group R) = f :=
to_envel_group.map.symm_apply_apply f
/--
The homomorphism `to_envel_group.map f` is the unique map that fits into the commutative
triangle in `to_envel_group.univ`.
-/
lemma to_envel_group.univ_uniq (R : Type*) [rack R] (G : Type*) [group G]
(f : R ββ quandle.conj G)
(g : envel_group R β* G) (h : f = (quandle.conj.map g).comp (to_envel_group R)) :
g = to_envel_group.map f :=
h.symm βΈ (to_envel_group.map.apply_symm_apply g).symm
/--
The induced group homomorphism from the enveloping group into bijections of the rack,
using `rack.to_conj`. Satisfies the property `envel_action_prop`.
This gives the rack `R` the structure of an augmented rack over `envel_group R`.
-/
def envel_action {R : Type*} [rack R] : envel_group R β* (R β R) :=
to_envel_group.map (to_conj R)
@[simp]
lemma envel_action_prop {R : Type*} [rack R] (x y : R) :
envel_action (to_envel_group R x) y = x β y := rfl
end envel_group
end rack
|
dee4d0cacdf4fe1631fb7689ae3e7b95440d452d
|
9028d228ac200bbefe3a711342514dd4e4458bff
|
/src/data/real/pi.lean
|
2da53d93d1554e0c32ffd92650e3a7698d93eff0
|
[
"Apache-2.0"
] |
permissive
|
mcncm/mathlib
|
8d25099344d9d2bee62822cb9ed43aa3e09fa05e
|
fde3d78cadeec5ef827b16ae55664ef115e66f57
|
refs/heads/master
| 1,672,743,316,277
| 1,602,618,514,000
| 1,602,618,514,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 7,382
|
lean
|
/-
Copyright (c) 2019 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn
-/
import analysis.special_functions.trigonometric
namespace real
lemma pi_gt_sqrt_two_add_series (n : β) : 2 ^ (n+1) * sqrt (2 - sqrt_two_add_series 0 n) < pi :=
begin
have : sqrt (2 - sqrt_two_add_series 0 n) / 2 * 2 ^ (n+2) < pi,
{ rw [β lt_div_iff, βsin_pi_over_two_pow_succ], apply sin_lt, apply div_pos pi_pos,
all_goals { apply pow_pos, norm_num } },
apply lt_of_le_of_lt (le_of_eq _) this,
rw [pow_succ _ (n+1), βmul_assoc, div_mul_cancel, mul_comm], norm_num
end
lemma pi_lt_sqrt_two_add_series (n : β) :
pi < 2 ^ (n+1) * sqrt (2 - sqrt_two_add_series 0 n) + 1 / 4 ^ n :=
begin
have : pi < (sqrt (2 - sqrt_two_add_series 0 n) / 2 + 1 / (2 ^ n) ^ 3 / 4) * 2 ^ (n+2),
{ rw [β div_lt_iff, β sin_pi_over_two_pow_succ],
refine lt_of_lt_of_le (lt_add_of_sub_right_lt (sin_gt_sub_cube _ _)) _,
{ apply div_pos pi_pos, apply pow_pos, norm_num },
{ rw div_le_iff',
{ refine le_trans pi_le_four _,
simp only [show ((4 : β) = 2 ^ 2), by norm_num, mul_one],
apply pow_le_pow, norm_num, apply le_add_of_nonneg_left, apply nat.zero_le },
{ apply pow_pos, norm_num }},
apply add_le_add_left, rw div_le_div_right,
rw [le_div_iff, βmul_pow],
refine le_trans _ (le_of_eq (one_pow 3)), apply pow_le_pow_of_le_left,
{ apply le_of_lt, apply mul_pos, apply div_pos pi_pos, apply pow_pos, norm_num, apply pow_pos,
norm_num },
rw β le_div_iff,
refine le_trans ((div_le_div_right _).mpr pi_le_four) _, apply pow_pos, norm_num,
rw [pow_succ, pow_succ, βmul_assoc, βdiv_div_eq_div_mul],
convert le_refl _,
all_goals { repeat {apply pow_pos}, norm_num }},
apply lt_of_lt_of_le this (le_of_eq _), rw [add_mul], congr' 1,
{ rw [pow_succ _ (n+1), βmul_assoc, div_mul_cancel, mul_comm], norm_num },
rw [pow_succ, βpow_mul, mul_comm n 2, pow_mul, show (2 : β) ^ 2 = 4, by norm_num, pow_succ,
pow_succ, βmul_assoc (2 : β), show (2 : β) * 2 = 4, by norm_num, βmul_assoc, div_mul_cancel,
mul_comm ((2 : β) ^ n), βdiv_div_eq_div_mul, div_mul_cancel],
apply pow_ne_zero, norm_num, norm_num
end
/-- From an upper bound on `sqrt_two_add_series 0 n = 2 cos (pi / 2 ^ (n+1))` of the form
`sqrt_two_add_series 0 n β€ 2 - (a / 2 ^ (n + 1)) ^ 2)`, one can deduce the lower bound `a < pi`
thanks to basic trigonometric inequalities as expressed in `pi_gt_sqrt_two_add_series`. -/
theorem pi_lower_bound_start (n : β) {a}
(h : sqrt_two_add_series ((0:β) / (1:β)) n β€ 2 - (a / 2 ^ (n + 1)) ^ 2) : a < pi :=
begin
refine lt_of_le_of_lt _ (pi_gt_sqrt_two_add_series n), rw [mul_comm],
refine (div_le_iff (pow_pos (by norm_num) _ : (0 : β) < _)).mp (le_sqrt_of_sqr_le _),
rwa [le_sub, show (0:β) = (0:β)/(1:β), by rw [nat.cast_zero, zero_div]],
end
lemma sqrt_two_add_series_step_up (c d : β) {a b n : β} {z : β}
(hz : sqrt_two_add_series (c/d) n β€ z) (hb : 0 < b) (hd : 0 < d)
(h : (2 * b + a) * d ^ 2 β€ c ^ 2 * b) : sqrt_two_add_series (a/b) (n+1) β€ z :=
begin
refine le_trans _ hz, rw sqrt_two_add_series_succ, apply sqrt_two_add_series_monotone_left,
have hb' : 0 < (b:β) := nat.cast_pos.2 hb,
have hd' : 0 < (d:β) := nat.cast_pos.2 hd,
rw [sqrt_le_left (div_nonneg c.cast_nonneg d.cast_nonneg), div_pow,
add_div_eq_mul_add_div _ _ (ne_of_gt hb'), div_le_div_iff hb' (pow_pos hd' _)],
exact_mod_cast h
end
/-- Create a proof of `a < pi` for a fixed rational number `a`, given a witness, which is a
sequence of rational numbers `sqrt 2 < r 1 < r 2 < ... < r n < 2` satisfying the property that
`sqrt (2 + r i) β€ r(i+1)`, where `r 0 = 0` and `sqrt (2 - r n) β₯ a/2^(n+1)`. -/
meta def pi_lower_bound (l : list β) : tactic unit :=
do let n := l.length,
tactic.apply `(@pi_lower_bound_start %%(reflect n)),
l.mmap' (Ξ» r, do
let a := r.num.to_nat, let b := r.denom,
(() <$ tactic.apply `(@sqrt_two_add_series_step_up %%(reflect a) %%(reflect b)));
[tactic.skip, `[norm_num1], `[norm_num1], `[norm_num1]]),
`[simp only [sqrt_two_add_series, nat.cast_bit0, nat.cast_bit1, nat.cast_one, nat.cast_zero]],
`[norm_num1]
/-- From a lower bound on `sqrt_two_add_series 0 n = 2 cos (pi / 2 ^ (n+1))` of the form
`2 - ((a - 1 / 4 ^ n) / 2 ^ (n + 1)) ^ 2 β€ sqrt_two_add_series 0 n`, one can deduce the upper bound
`pi < a` thanks to basic trigonometric formulas as expressed in `pi_lt_sqrt_two_add_series`. -/
theorem pi_upper_bound_start (n : β) {a}
(h : 2 - ((a - 1 / 4 ^ n) / 2 ^ (n + 1)) ^ 2 β€ sqrt_two_add_series ((0:β) / (1:β)) n)
(hβ : 1 / 4 ^ n β€ a) : pi < a :=
begin
refine lt_of_lt_of_le (pi_lt_sqrt_two_add_series n) _,
rw [β le_sub_iff_add_le, β le_div_iff', sqrt_le_left, sub_le],
{ rwa [nat.cast_zero, zero_div] at h },
{ exact div_nonneg (sub_nonneg.2 hβ) (pow_nonneg (le_of_lt zero_lt_two) _) },
{ exact pow_pos zero_lt_two _ }
end
lemma sqrt_two_add_series_step_down (a b : β) {c d n : β} {z : β}
(hz : z β€ sqrt_two_add_series (a/b) n) (hb : 0 < b) (hd : 0 < d)
(h : a ^ 2 * d β€ (2 * d + c) * b ^ 2) : z β€ sqrt_two_add_series (c/d) (n+1) :=
begin
apply le_trans hz, rw sqrt_two_add_series_succ, apply sqrt_two_add_series_monotone_left,
apply le_sqrt_of_sqr_le,
have hb' : 0 < (b:β) := nat.cast_pos.2 hb,
have hd' : 0 < (d:β) := nat.cast_pos.2 hd,
rw [div_pow, add_div_eq_mul_add_div _ _ (ne_of_gt hd'), div_le_div_iff (pow_pos hb' _) hd'],
exact_mod_cast h
end
/-- Create a proof of `pi < a` for a fixed rational number `a`, given a witness, which is a
sequence of rational numbers `sqrt 2 < r 1 < r 2 < ... < r n < 2` satisfying the property that
`sqrt (2 + r i) β₯ r(i+1)`, where `r 0 = 0` and `sqrt (2 - r n) β₯ (a - 1/4^n) / 2^(n+1)`. -/
meta def pi_upper_bound (l : list β) : tactic unit :=
do let n := l.length,
(() <$ tactic.apply `(@pi_upper_bound_start %%(reflect n))); [pure (), `[norm_num1]],
l.mmap' (Ξ» r, do
let a := r.num.to_nat, let b := r.denom,
(() <$ tactic.apply `(@sqrt_two_add_series_step_down %%(reflect a) %%(reflect b)));
[pure (), `[norm_num1], `[norm_num1], `[norm_num1]]),
`[simp only [sqrt_two_add_series, nat.cast_bit0, nat.cast_bit1, nat.cast_one, nat.cast_zero]],
`[norm_num]
lemma pi_gt_three : 3 < pi := by pi_lower_bound [23/16]
lemma pi_gt_314 : 3.14 < pi := by pi_lower_bound [99/70, 874/473, 1940/989, 1447/727]
lemma pi_lt_315 : pi < 3.15 := by pi_upper_bound [140/99, 279/151, 51/26, 412/207]
lemma pi_gt_31415 : 3.1415 < pi := by pi_lower_bound [
11482/8119, 5401/2923, 2348/1197, 11367/5711, 25705/12868, 23235/11621]
lemma pi_lt_31416 : pi < 3.1416 := by pi_upper_bound [
4756/3363, 101211/54775, 505534/257719, 83289/41846,
411278/205887, 438142/219137, 451504/225769, 265603/132804, 849938/424971]
lemma pi_gt_3141592 : 3.141592 < pi := by pi_lower_bound [
11482/8119, 7792/4217, 54055/27557, 949247/476920, 3310126/1657059,
2635492/1318143, 1580265/790192, 1221775/610899, 3612247/1806132, 849943/424972]
lemma pi_lt_3141593 : pi < 3.141593 := by pi_upper_bound [
27720/19601, 56935/30813, 49359/25163, 258754/130003, 113599/56868, 1101994/551163,
8671537/4336095, 3877807/1938940, 52483813/26242030, 56946167/28473117, 23798415/11899211]
end real
|
65bcabe36f25e05bf6bede2bf893a12a78ad44ac
|
6432ea7a083ff6ba21ea17af9ee47b9c371760f7
|
/tests/lean/run/1968.lean
|
4c82d8a6bafd7beb66f694d71ef578c846aafd23
|
[
"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,316
|
lean
|
inductive type
| bv : Nat β type
| bit : type
open type
-- This is a "parameterized List" where `plist f types` contains
-- an element of Type `f tp` for each corresponding element `tp β types`.
inductive plist (f : type β Type) : List type β Type
| nil : plist f []
| cons {h:type} {r:List type} : f h β plist f r β plist f (h::r)
-- Operations on values; the first argument contains the types of
-- inputs, and the second for the return Type.
inductive op : List type β type β Type
| neq (tp:type) : op [tp, tp] bit
| mul (w : Nat) : op [bv w, bv w] (bv w)
-- Denotes expressions that evaluate to a number given a memory State and register to value map.
inductive value : type β Type
| const (w : Nat) : value (bv w)
| op {args:List type} {tp:type} : op args tp β plist value args β value tp
--- This creates a plist (borrowed from the List notation).
open value
-- This works
-- #eval value.op (op.mul 32) [[[ const 32, const 32 ]]]
-- This also works
-- instance bvMul (w : Nat) : Mul (value (bv w)) := β¨fun x y => w value.op (op.mul w) [[[x, y]]]β©
-- #eval const 32 * const 32
-- This works
-- #eval value.op (op.neq (bv 32)) [[[ const 32, const 32 ]]]
-- def neq {tp:type} (x y : value tp) : value bit := value.op (op.neq tp) [[[x, y]]]
-- #eval neq (const 32) (const 32)
|
128cba9597371e8ee8d3e11cd68e80e8706c278b
|
2a70b774d16dbdf5a533432ee0ebab6838df0948
|
/_target/deps/mathlib/src/data/finset/sort.lean
|
fe97168fd968c81914d201599596effe26faa2ef
|
[
"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
| 8,210
|
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.finset.lattice
import data.multiset.sort
import data.list.nodup_equiv_fin
/-!
# Construct a sorted list from a finset.
-/
namespace finset
open multiset nat
variables {Ξ± Ξ² : Type*}
/-! ### sort -/
section sort
variables (r : Ξ± β Ξ± β Prop) [decidable_rel r]
[is_trans Ξ± r] [is_antisymm Ξ± r] [is_total Ξ± r]
/-- `sort s` constructs a sorted list from the unordered set `s`.
(Uses merge sort algorithm.) -/
def sort (s : finset Ξ±) : list Ξ± := sort r s.1
@[simp] theorem sort_sorted (s : finset Ξ±) : list.sorted r (sort r s) :=
sort_sorted _ _
@[simp] theorem sort_eq (s : finset Ξ±) : β(sort r s) = s.1 :=
sort_eq _ _
@[simp] theorem sort_nodup (s : finset Ξ±) : (sort r s).nodup :=
(by rw sort_eq; exact s.2 : @multiset.nodup Ξ± (sort r s))
@[simp] theorem sort_to_finset [decidable_eq Ξ±] (s : finset Ξ±) : (sort r s).to_finset = s :=
list.to_finset_eq (sort_nodup r s) βΈ eq_of_veq (sort_eq r s)
@[simp] theorem mem_sort {s : finset Ξ±} {a : Ξ±} : a β sort r s β a β s :=
multiset.mem_sort _
@[simp] theorem length_sort {s : finset Ξ±} : (sort r s).length = s.card :=
multiset.length_sort _
end sort
section sort_linear_order
variables [linear_order Ξ±]
theorem sort_sorted_lt (s : finset Ξ±) : list.sorted (<) (sort (β€) s) :=
(sort_sorted _ _).impβ (@lt_of_le_of_ne _ _) (sort_nodup _ _)
lemma sorted_zero_eq_min'_aux (s : finset Ξ±) (h : 0 < (s.sort (β€)).length) (H : s.nonempty) :
(s.sort (β€)).nth_le 0 h = s.min' H :=
begin
let l := s.sort (β€),
apply le_antisymm,
{ have : s.min' H β l := (finset.mem_sort (β€)).mpr (s.min'_mem H),
obtain β¨i, i_lt, hiβ© : β i (hi : i < l.length), l.nth_le i hi = s.min' H :=
list.mem_iff_nth_le.1 this,
rw β hi,
exact list.nth_le_of_sorted_of_le (s.sort_sorted (β€)) (nat.zero_le i) },
{ have : l.nth_le 0 h β s := (finset.mem_sort (β€)).1 (list.nth_le_mem l 0 h),
exact s.min'_le _ this }
end
lemma sorted_zero_eq_min' {s : finset Ξ±} {h : 0 < (s.sort (β€)).length} :
(s.sort (β€)).nth_le 0 h = s.min' (card_pos.1 $ by rwa length_sort at h) :=
sorted_zero_eq_min'_aux _ _ _
lemma min'_eq_sorted_zero {s : finset Ξ±} {h : s.nonempty} :
s.min' h = (s.sort (β€)).nth_le 0 (by { rw length_sort, exact card_pos.2 h }) :=
(sorted_zero_eq_min'_aux _ _ _).symm
lemma sorted_last_eq_max'_aux (s : finset Ξ±) (h : (s.sort (β€)).length - 1 < (s.sort (β€)).length)
(H : s.nonempty) : (s.sort (β€)).nth_le ((s.sort (β€)).length - 1) h = s.max' H :=
begin
let l := s.sort (β€),
apply le_antisymm,
{ have : l.nth_le ((s.sort (β€)).length - 1) h β s :=
(finset.mem_sort (β€)).1 (list.nth_le_mem l _ h),
exact s.le_max' _ this },
{ have : s.max' H β l := (finset.mem_sort (β€)).mpr (s.max'_mem H),
obtain β¨i, i_lt, hiβ© : β i (hi : i < l.length), l.nth_le i hi = s.max' H :=
list.mem_iff_nth_le.1 this,
rw β hi,
have : i β€ l.length - 1 := nat.le_pred_of_lt i_lt,
exact list.nth_le_of_sorted_of_le (s.sort_sorted (β€)) (nat.le_pred_of_lt i_lt) },
end
lemma sorted_last_eq_max' {s : finset Ξ±} {h : (s.sort (β€)).length - 1 < (s.sort (β€)).length} :
(s.sort (β€)).nth_le ((s.sort (β€)).length - 1) h =
s.max' (by { rw length_sort at h, exact card_pos.1 (lt_of_le_of_lt bot_le h) }) :=
sorted_last_eq_max'_aux _ _ _
lemma max'_eq_sorted_last {s : finset Ξ±} {h : s.nonempty} :
s.max' h = (s.sort (β€)).nth_le ((s.sort (β€)).length - 1)
(by simpa using sub_lt (card_pos.mpr h) zero_lt_one) :=
(sorted_last_eq_max'_aux _ _ _).symm
/-- Given a finset `s` of cardinality `k` in a linear order `Ξ±`, the map `order_iso_of_fin s h`
is the increasing bijection between `fin k` and `s` as an `order_iso`. Here, `h` is a proof that
the cardinality of `s` is `k`. We use this instead of an iso `fin s.card βo s` to avoid
casting issues in further uses of this function. -/
def order_iso_of_fin (s : finset Ξ±) {k : β} (h : s.card = k) : fin k βo (s : set Ξ±) :=
order_iso.trans (fin.cast ((length_sort (β€)).trans h).symm) $
(s.sort_sorted_lt.nth_le_iso _).trans $ order_iso.set_congr _ _ $
set.ext $ Ξ» x, mem_sort _
/-- Given a finset `s` of cardinality `k` in a linear order `Ξ±`, the map `order_emb_of_fin s h` is
the increasing bijection between `fin k` and `s` as an order embedding into `Ξ±`. Here, `h` is a
proof that the cardinality of `s` is `k`. We use this instead of an embedding `fin s.card βͺo Ξ±` to
avoid casting issues in further uses of this function. -/
def order_emb_of_fin (s : finset Ξ±) {k : β} (h : s.card = k) : fin k βͺo Ξ± :=
(order_iso_of_fin s h).to_order_embedding.trans (order_embedding.subtype _)
@[simp] lemma coe_order_iso_of_fin_apply (s : finset Ξ±) {k : β} (h : s.card = k) (i : fin k) :
β(order_iso_of_fin s h i) = order_emb_of_fin s h i :=
rfl
lemma order_iso_of_fin_symm_apply (s : finset Ξ±) {k : β} (h : s.card = k) (x : (s : set Ξ±)) :
β((s.order_iso_of_fin h).symm x) = (s.sort (β€)).index_of x :=
rfl
lemma order_emb_of_fin_apply (s : finset Ξ±) {k : β} (h : s.card = k) (i : fin k) :
s.order_emb_of_fin h i = (s.sort (β€)).nth_le i (by { rw [length_sort, h], exact i.2 }) :=
rfl
@[simp] lemma range_order_emb_of_fin (s : finset Ξ±) {k : β} (h : s.card = k) :
set.range (s.order_emb_of_fin h) = s :=
by simp [order_emb_of_fin, set.range_comp coe (s.order_iso_of_fin h)]
/-- The bijection `order_emb_of_fin s h` sends `0` to the minimum of `s`. -/
lemma order_emb_of_fin_zero {s : finset Ξ±} {k : β} (h : s.card = k) (hz : 0 < k) :
order_emb_of_fin s h β¨0, hzβ© = s.min' (card_pos.mp (h.symm βΈ hz)) :=
by simp only [order_emb_of_fin_apply, subtype.coe_mk, sorted_zero_eq_min']
/-- The bijection `order_emb_of_fin s h` sends `k-1` to the maximum of `s`. -/
lemma order_emb_of_fin_last {s : finset Ξ±} {k : β} (h : s.card = k) (hz : 0 < k) :
order_emb_of_fin s h β¨k-1, buffer.lt_aux_2 hzβ© = s.max' (card_pos.mp (h.symm βΈ hz)) :=
by simp [order_emb_of_fin_apply, max'_eq_sorted_last, h]
/-- `order_emb_of_fin {a} h` sends any argument to `a`. -/
@[simp] lemma order_emb_of_fin_singleton (a : Ξ±) (i : fin 1) :
order_emb_of_fin {a} (card_singleton a) i = a :=
by rw [subsingleton.elim i β¨0, zero_lt_oneβ©, order_emb_of_fin_zero _ zero_lt_one, min'_singleton]
/-- Any increasing map `f` from `fin k` to a finset of cardinality `k` has to coincide with
the increasing bijection `order_emb_of_fin s h`. -/
lemma order_emb_of_fin_unique {s : finset Ξ±} {k : β} (h : s.card = k) {f : fin k β Ξ±}
(hfs : β x, f x β s) (hmono : strict_mono f) : f = s.order_emb_of_fin h :=
begin
apply fin.strict_mono_unique hmono (s.order_emb_of_fin h).strict_mono,
rw [range_order_emb_of_fin, β set.image_univ, β coe_fin_range, β coe_image, coe_inj],
refine eq_of_subset_of_card_le (Ξ» x hx, _) _,
{ rcases mem_image.1 hx with β¨x, hx, rflβ©, exact hfs x },
{ rw [h, card_image_of_injective _ hmono.injective, fin_range_card] }
end
/-- An order embedding `f` from `fin k` to a finset of cardinality `k` has to coincide with
the increasing bijection `order_emb_of_fin s h`. -/
lemma order_emb_of_fin_unique' {s : finset Ξ±} {k : β} (h : s.card = k) {f : fin k βͺo Ξ±}
(hfs : β x, f x β s) : f = s.order_emb_of_fin h :=
rel_embedding.ext $ function.funext_iff.1 $ order_emb_of_fin_unique h hfs f.strict_mono
/-- Two parametrizations `order_emb_of_fin` of the same set take the same value on `i` and `j` if
and only if `i = j`. Since they can be defined on a priori not defeq types `fin k` and `fin l`
(although necessarily `k = l`), the conclusion is rather written `(i : β) = (j : β)`. -/
@[simp] lemma order_emb_of_fin_eq_order_emb_of_fin_iff
{k l : β} {s : finset Ξ±} {i : fin k} {j : fin l} {h : s.card = k} {h' : s.card = l} :
s.order_emb_of_fin h i = s.order_emb_of_fin h' j β (i : β) = (j : β) :=
begin
substs k l,
exact (s.order_emb_of_fin rfl).eq_iff_eq.trans (fin.ext_iff _ _)
end
end sort_linear_order
instance [has_repr Ξ±] : has_repr (finset Ξ±) := β¨Ξ» s, repr s.1β©
end finset
|
d469d2daa9cc336802a24e1224a1242cba1ba00e
|
cf39355caa609c0f33405126beee2739aa3cb77e
|
/tests/lean/run/def5.lean
|
954f13833b53394cd339118b385671b1c318269c
|
[
"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
| 97
|
lean
|
section
parameter (A : Type)
definition f : A β A :=
Ξ» x, x
#check f
end
#check f
|
d7b7bc4768b674a80327e0b89a6548779a4c8621
|
7cef822f3b952965621309e88eadf618da0c8ae9
|
/src/topology/algebra/group.lean
|
d01af58cfbc7cb1073c1f3119f09a276c9935d6c
|
[
"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
| 16,842
|
lean
|
/-
Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes HΓΆlzl, Mario Carneiro, Patrick Massot
Theory of topological groups.
-/
import data.equiv.algebra
import algebra.pointwise order.filter.pointwise
import group_theory.quotient_group
import topology.algebra.monoid topology.homeomorph
open classical set lattice filter topological_space
open_locale classical topological_space
universes u v w
variables {Ξ± : Type u} {Ξ² : Type v} {Ξ³ : Type w}
section topological_group
section prio
set_option default_priority 100 -- see Note [default priority]
/-- A topological (additive) group is a group in which the addition and negation operations are
continuous. -/
class topological_add_group (Ξ± : Type u) [topological_space Ξ±] [add_group Ξ±]
extends topological_add_monoid Ξ± : Prop :=
(continuous_neg : continuous (Ξ»a:Ξ±, -a))
/-- A topological group is a group in which the multiplication and inversion operations are
continuous. -/
@[to_additive topological_add_group]
class topological_group (Ξ± : Type*) [topological_space Ξ±] [group Ξ±]
extends topological_monoid Ξ± : Prop :=
(continuous_inv : continuous (Ξ»a:Ξ±, aβ»ΒΉ))
end prio
variables [topological_space Ξ±] [group Ξ±]
@[to_additive]
lemma continuous_inv [topological_group Ξ±] : continuous (Ξ»x:Ξ±, xβ»ΒΉ) :=
topological_group.continuous_inv Ξ±
@[to_additive]
lemma continuous.inv [topological_group Ξ±] [topological_space Ξ²] {f : Ξ² β Ξ±}
(hf : continuous f) : continuous (Ξ»x, (f x)β»ΒΉ) :=
continuous_inv.comp hf
@[to_additive]
lemma continuous_on.inv [topological_group Ξ±] [topological_space Ξ²] {f : Ξ² β Ξ±} {s : set Ξ²}
(hf : continuous_on f s) : continuous_on (Ξ»x, (f x)β»ΒΉ) s :=
continuous_inv.comp_continuous_on hf
/-- If a function converges to a value in a multiplicative topological group, then its inverse
converges to the inverse of this value. For the version in normed fields assuming additionally
that the limit is nonzero, use `tendsto.inv'`. -/
@[to_additive]
lemma filter.tendsto.inv [topological_group Ξ±] {f : Ξ² β Ξ±} {x : filter Ξ²} {a : Ξ±}
(hf : tendsto f x (π a)) : tendsto (Ξ»x, (f x)β»ΒΉ) x (π aβ»ΒΉ) :=
tendsto.comp (continuous_iff_continuous_at.mp (topological_group.continuous_inv Ξ±) a) hf
@[to_additive topological_add_group]
instance [topological_group Ξ±] [topological_space Ξ²] [group Ξ²] [topological_group Ξ²] :
topological_group (Ξ± Γ Ξ²) :=
{ continuous_inv := continuous_fst.inv.prod_mk continuous_snd.inv }
attribute [instance] prod.topological_add_group
@[to_additive]
protected def homeomorph.mul_left [topological_group Ξ±] (a : Ξ±) : Ξ± ββ Ξ± :=
{ continuous_to_fun := continuous_const.mul continuous_id,
continuous_inv_fun := continuous_const.mul continuous_id,
.. equiv.mul_left a }
@[to_additive]
lemma is_open_map_mul_left [topological_group Ξ±] (a : Ξ±) : is_open_map (Ξ» x, a * x) :=
(homeomorph.mul_left a).is_open_map
@[to_additive]
lemma is_closed_map_mul_left [topological_group Ξ±] (a : Ξ±) : is_closed_map (Ξ» x, a * x) :=
(homeomorph.mul_left a).is_closed_map
@[to_additive]
protected def homeomorph.mul_right
{Ξ± : Type*} [topological_space Ξ±] [group Ξ±] [topological_group Ξ±] (a : Ξ±) :
Ξ± ββ Ξ± :=
{ continuous_to_fun := continuous_id.mul continuous_const,
continuous_inv_fun := continuous_id.mul continuous_const,
.. equiv.mul_right a }
@[to_additive]
lemma is_open_map_mul_right [topological_group Ξ±] (a : Ξ±) : is_open_map (Ξ» x, x * a) :=
(homeomorph.mul_right a).is_open_map
@[to_additive]
lemma is_closed_map_mul_right [topological_group Ξ±] (a : Ξ±) : is_closed_map (Ξ» x, x * a) :=
(homeomorph.mul_right a).is_closed_map
@[to_additive]
protected def homeomorph.inv (Ξ± : Type*) [topological_space Ξ±] [group Ξ±] [topological_group Ξ±] :
Ξ± ββ Ξ± :=
{ continuous_to_fun := continuous_inv,
continuous_inv_fun := continuous_inv,
.. equiv.inv Ξ± }
@[to_additive exists_nhds_half]
lemma exists_nhds_split [topological_group Ξ±] {s : set Ξ±} (hs : s β π (1 : Ξ±)) :
β V β π (1 : Ξ±), β v w β V, v * w β s :=
begin
have : ((Ξ»a:Ξ±ΓΞ±, a.1 * a.2) β»ΒΉ' s) β π ((1, 1) : Ξ± Γ Ξ±) :=
tendsto_mul (by simpa using hs),
rw nhds_prod_eq at this,
rcases mem_prod_iff.1 this with β¨Vβ, Hβ, Vβ, Hβ, Hβ©,
exact β¨Vβ β© Vβ, inter_mem_sets Hβ Hβ, assume v w β¨hv, _β© β¨_, hwβ©, @H (v, w) β¨hv, hwβ©β©
end
@[to_additive exists_nhds_half_neg]
lemma exists_nhds_split_inv [topological_group Ξ±] {s : set Ξ±} (hs : s β π (1 : Ξ±)) :
β V β π (1 : Ξ±), β v w β V, v * wβ»ΒΉ β s :=
begin
have : tendsto (Ξ»a:Ξ±ΓΞ±, a.1 * (a.2)β»ΒΉ) ((π (1:Ξ±)).prod (π (1:Ξ±))) (π 1),
{ simpa using (@tendsto_fst Ξ± Ξ± (π 1) (π 1)).mul tendsto_snd.inv },
have : ((Ξ»a:Ξ±ΓΞ±, a.1 * (a.2)β»ΒΉ) β»ΒΉ' s) β (π (1:Ξ±)).prod (π (1:Ξ±)) :=
this (by simpa using hs),
rcases mem_prod_iff.1 this with β¨Vβ, Hβ, Vβ, Hβ, Hβ©,
exact β¨Vβ β© Vβ, inter_mem_sets Hβ Hβ, assume v w β¨hv, _β© β¨_, hwβ©, @H (v, w) β¨hv, hwβ©β©
end
@[to_additive exists_nhds_quarter]
lemma exists_nhds_split4 [topological_group Ξ±] {u : set Ξ±} (hu : u β π (1 : Ξ±)) :
β V β π (1 : Ξ±), β {v w s t}, v β V β w β V β s β V β t β V β v * w * s * t β u :=
begin
rcases exists_nhds_split hu with β¨W, W_nhd, hβ©,
rcases exists_nhds_split W_nhd with β¨V, V_nhd, h'β©,
existsi [V, V_nhd],
intros v w s t v_in w_in s_in t_in,
simpa [mul_assoc] using h _ _ (h' v w v_in w_in) (h' s t s_in t_in)
end
section
variable (Ξ±)
@[to_additive]
lemma nhds_one_symm [topological_group Ξ±] : comap (Ξ»r:Ξ±, rβ»ΒΉ) (π (1 : Ξ±)) = π (1 : Ξ±) :=
begin
have lim : tendsto (Ξ»r:Ξ±, rβ»ΒΉ) (π 1) (π 1),
{ simpa using (@tendsto_id Ξ± (π 1)).inv },
refine comap_eq_of_inverse _ _ lim lim,
{ funext x, simp },
end
end
@[to_additive]
lemma nhds_translation_mul_inv [topological_group Ξ±] (x : Ξ±) :
comap (Ξ»y:Ξ±, y * xβ»ΒΉ) (π 1) = π x :=
begin
refine comap_eq_of_inverse (Ξ»y:Ξ±, y * x) _ _ _,
{ funext x; simp },
{ suffices : tendsto (Ξ»y:Ξ±, y * xβ»ΒΉ) (π x) (π (x * xβ»ΒΉ)), { simpa },
exact tendsto_id.mul tendsto_const_nhds },
{ suffices : tendsto (Ξ»y:Ξ±, y * x) (π 1) (π (1 * x)), { simpa },
exact tendsto_id.mul tendsto_const_nhds }
end
@[to_additive]
lemma topological_group.ext {G : Type*} [group G] {t t' : topological_space G}
(tg : @topological_group G t _) (tg' : @topological_group G t' _)
(h : @nhds G t 1 = @nhds G t' 1) : t = t' :=
eq_of_nhds_eq_nhds $ Ξ» x, by
rw [β @nhds_translation_mul_inv G t _ _ x , β @nhds_translation_mul_inv G t' _ _ x , β h]
end topological_group
section quotient_topological_group
variables [topological_space Ξ±] [group Ξ±] [topological_group Ξ±] (N : set Ξ±) [normal_subgroup N]
@[to_additive]
instance {Ξ± : Type u} [group Ξ±] [topological_space Ξ±] (N : set Ξ±) [normal_subgroup N] :
topological_space (quotient_group.quotient N) :=
by dunfold quotient_group.quotient; apply_instance
open quotient_group
@[to_additive quotient_add_group_saturate]
lemma quotient_group_saturate {Ξ± : Type u} [group Ξ±] (N : set Ξ±) [normal_subgroup N] (s : set Ξ±) :
(coe : Ξ± β quotient N) β»ΒΉ' ((coe : Ξ± β quotient N) '' s) = (β x : N, (Ξ» y, y*x.1) '' s) :=
begin
ext x,
simp only [mem_preimage, mem_image, mem_Union, quotient_group.eq],
split,
{ exact assume β¨a, a_in, hβ©, β¨β¨_, hβ©, a, a_in, mul_inv_cancel_left _ _β© },
{ exact assume β¨β¨i, hiβ©, a, ha, eqβ©,
β¨a, ha, by simp only [eq.symm, (mul_assoc _ _ _).symm, inv_mul_cancel_left, hi]β© }
end
@[to_additive]
lemma quotient_group.open_coe : is_open_map (coe : Ξ± β quotient N) :=
begin
intros s s_op,
change is_open ((coe : Ξ± β quotient N) β»ΒΉ' (coe '' s)),
rw quotient_group_saturate N s,
apply is_open_Union,
rintro β¨n, _β©,
exact is_open_map_mul_right n s s_op
end
@[to_additive topological_add_group_quotient]
instance topological_group_quotient : topological_group (quotient N) :=
{ continuous_mul := begin
have cont : continuous ((coe : Ξ± β quotient N) β (Ξ» (p : Ξ± Γ Ξ±), p.fst * p.snd)) :=
continuous_quot_mk.comp continuous_mul,
have quot : quotient_map (Ξ» p : Ξ± Γ Ξ±, ((p.1:quotient N), (p.2:quotient N))),
{ apply is_open_map.to_quotient_map,
{ exact is_open_map.prod (quotient_group.open_coe N) (quotient_group.open_coe N) },
{ exact (continuous_quot_mk.comp continuous_fst).prod_mk
(continuous_quot_mk.comp continuous_snd) },
{ rintro β¨β¨xβ©, β¨yβ©β©,
exact β¨(x, y), rflβ© } },
exact (quotient_map.continuous_iff quot).2 cont,
end,
continuous_inv := begin
apply continuous_quotient_lift,
change continuous ((coe : Ξ± β quotient N) β (Ξ» (a : Ξ±), aβ»ΒΉ)),
exact continuous_quot_mk.comp continuous_inv
end }
attribute [instance] topological_add_group_quotient
end quotient_topological_group
section topological_add_group
variables [topological_space Ξ±] [add_group Ξ±]
lemma continuous.sub [topological_add_group Ξ±] [topological_space Ξ²] {f : Ξ² β Ξ±} {g : Ξ² β Ξ±}
(hf : continuous f) (hg : continuous g) : continuous (Ξ»x, f x - g x) :=
by simp; exact hf.add hg.neg
lemma continuous_sub [topological_add_group Ξ±] : continuous (Ξ»p:Ξ±ΓΞ±, p.1 - p.2) :=
continuous_fst.sub continuous_snd
lemma continuous_on.sub [topological_add_group Ξ±] [topological_space Ξ²] {f : Ξ² β Ξ±} {g : Ξ² β Ξ±} {s : set Ξ²}
(hf : continuous_on f s) (hg : continuous_on g s) : continuous_on (Ξ»x, f x - g x) s :=
continuous_sub.comp_continuous_on (hf.prod hg)
lemma filter.tendsto.sub [topological_add_group Ξ±] {f : Ξ² β Ξ±} {g : Ξ² β Ξ±} {x : filter Ξ²} {a b : Ξ±}
(hf : tendsto f x (π a)) (hg : tendsto g x (π b)) : tendsto (Ξ»x, f x - g x) x (π (a - b)) :=
by simp; exact hf.add hg.neg
lemma nhds_translation [topological_add_group Ξ±] (x : Ξ±) : comap (Ξ»y:Ξ±, y - x) (π 0) = π x :=
nhds_translation_add_neg x
end topological_add_group
section prio
set_option default_priority 100 -- see Note [default priority]
/-- additive group with a neighbourhood around 0.
Only used to construct a topology and uniform space.
This is currently only available for commutative groups, but it can be extended to
non-commutative groups too.
-/
class add_group_with_zero_nhd (Ξ± : Type u) extends add_comm_group Ξ± :=
(Z : filter Ξ±)
(zero_Z {} : pure 0 β€ Z)
(sub_Z {} : tendsto (Ξ»p:Ξ±ΓΞ±, p.1 - p.2) (Z.prod Z) Z)
end prio
namespace add_group_with_zero_nhd
variables (Ξ±) [add_group_with_zero_nhd Ξ±]
local notation `Z` := add_group_with_zero_nhd.Z
@[priority 100] -- see Note [lower instance priority]
instance : topological_space Ξ± :=
topological_space.mk_of_nhds $ Ξ»a, map (Ξ»x, x + a) (Z Ξ±)
variables {Ξ±}
lemma neg_Z : tendsto (Ξ»a:Ξ±, - a) (Z Ξ±) (Z Ξ±) :=
have tendsto (Ξ»a, (0:Ξ±)) (Z Ξ±) (Z Ξ±),
by refine le_trans (assume h, _) zero_Z; simp [univ_mem_sets'] {contextual := tt},
have tendsto (Ξ»a:Ξ±, 0 - a) (Z Ξ±) (Z Ξ±), from
sub_Z.comp (tendsto.prod_mk this tendsto_id),
by simpa
lemma add_Z : tendsto (Ξ»p:Ξ±ΓΞ±, p.1 + p.2) ((Z Ξ±).prod (Z Ξ±)) (Z Ξ±) :=
suffices tendsto (Ξ»p:Ξ±ΓΞ±, p.1 - -p.2) ((Z Ξ±).prod (Z Ξ±)) (Z Ξ±),
by simpa,
sub_Z.comp (tendsto.prod_mk tendsto_fst (neg_Z.comp tendsto_snd))
lemma exists_Z_half {s : set Ξ±} (hs : s β Z Ξ±) : β V β Z Ξ±, β v w β V, v + w β s :=
begin
have : ((Ξ»a:Ξ±ΓΞ±, a.1 + a.2) β»ΒΉ' s) β (Z Ξ±).prod (Z Ξ±) := add_Z (by simpa using hs),
rcases mem_prod_iff.1 this with β¨Vβ, Hβ, Vβ, Hβ, Hβ©,
exact β¨Vβ β© Vβ, inter_mem_sets Hβ Hβ, assume v w β¨hv, _β© β¨_, hwβ©, @H (v, w) β¨hv, hwβ©β©
end
lemma nhds_eq (a : Ξ±) : π a = map (Ξ»x, x + a) (Z Ξ±) :=
topological_space.nhds_mk_of_nhds _ _
(assume a, calc pure a = map (Ξ»x, x + a) (pure 0) : by simp
... β€ _ : map_mono zero_Z)
(assume b s hs,
let β¨t, ht, eqtβ© := exists_Z_half hs in
have t0 : (0:Ξ±) β t, by simpa using zero_Z ht,
begin
refine β¨(Ξ»x:Ξ±, x + b) '' t, image_mem_map ht, _, _β©,
{ refine set.image_subset_iff.2 (assume b hbt, _),
simpa using eqt 0 b t0 hbt },
{ rintros _ β¨c, hb, rflβ©,
refine (Z Ξ±).sets_of_superset ht (assume x hxt, _),
simpa using eqt _ _ hxt hb }
end)
lemma nhds_zero_eq_Z : π 0 = Z Ξ± := by simp [nhds_eq]; exact filter.map_id
@[priority 100] -- see Note [lower instance priority]
instance : topological_add_monoid Ξ± :=
β¨ continuous_iff_continuous_at.2 $ assume β¨a, bβ©,
begin
rw [continuous_at, nhds_prod_eq, nhds_eq, nhds_eq, nhds_eq, filter.prod_map_map_eq,
tendsto_map'_iff],
suffices : tendsto ((Ξ»x:Ξ±, (a + b) + x) β (Ξ»p:Ξ±ΓΞ±,p.1 + p.2)) (filter.prod (Z Ξ±) (Z Ξ±))
(map (Ξ»x:Ξ±, (a + b) + x) (Z Ξ±)),
{ simpa [(β)] },
exact tendsto_map.comp add_Z
endβ©
@[priority 100] -- see Note [lower instance priority]
instance : topological_add_group Ξ± :=
β¨continuous_iff_continuous_at.2 $ assume a,
begin
rw [continuous_at, nhds_eq, nhds_eq, tendsto_map'_iff],
suffices : tendsto ((Ξ»x:Ξ±, x - a) β (Ξ»x:Ξ±, -x)) (Z Ξ±) (map (Ξ»x:Ξ±, x - a) (Z Ξ±)),
{ simpa [(β)] },
exact tendsto_map.comp neg_Z
endβ©
end add_group_with_zero_nhd
section filter_mul
local attribute [instance]
set.pointwise_one set.pointwise_mul set.pointwise_add filter.pointwise_mul filter.pointwise_add
filter.pointwise_one
section
variables [topological_space Ξ±] [group Ξ±] [topological_group Ξ±]
@[to_additive]
lemma is_open_pointwise_mul_left {s t : set Ξ±} : is_open t β is_open (s * t) := Ξ» ht,
begin
have : βa, is_open ((Ξ» (x : Ξ±), a * x) '' t),
assume a, apply is_open_map_mul_left, exact ht,
rw pointwise_mul_eq_Union_mul_left,
exact is_open_Union (Ξ»a, is_open_Union $ Ξ»ha, this _),
end
@[to_additive]
lemma is_open_pointwise_mul_right {s t : set Ξ±} : is_open s β is_open (s * t) := Ξ» hs,
begin
have : βa, is_open ((Ξ» (x : Ξ±), x * a) '' s),
assume a, apply is_open_map_mul_right, exact hs,
rw pointwise_mul_eq_Union_mul_right,
exact is_open_Union (Ξ»a, is_open_Union $ Ξ»ha, this _),
end
variables (Ξ±)
lemma topological_group.t1_space (h : @is_closed Ξ± _ {1}) : t1_space Ξ± :=
β¨assume x, by { convert is_closed_map_mul_right x _ h, simp }β©
lemma topological_group.regular_space [t1_space Ξ±] : regular_space Ξ± :=
β¨assume s a hs ha,
let f := Ξ» p : Ξ± Γ Ξ±, p.1 * (p.2)β»ΒΉ in
have hf : continuous f :=
continuous_mul.comp (continuous_fst.prod_mk (continuous_inv.comp continuous_snd)),
-- a β -s implies f (a, 1) β -s, and so (a, 1) β fβ»ΒΉ' (-s);
-- and so can find tβ tβ open such that a β tβ Γ tβ β fβ»ΒΉ' (-s)
let β¨tβ, tβ, htβ, htβ, a_mem_tβ, one_mem_tβ, t_subsetβ© :=
is_open_prod_iff.1 (hf _ (is_open_compl_iff.2 hs)) a (1:Ξ±) (by simpa [f]) in
begin
use s * tβ,
use is_open_pointwise_mul_left htβ,
use Ξ» x hx, β¨x, hx, 1, one_mem_tβ, (mul_one _).symmβ©,
apply inf_principal_eq_bot,
rw mem_nhds_sets_iff,
refine β¨tβ, _, htβ, a_mem_tββ©,
rintros x hx β¨y, hy, z, hz, yzβ©,
have : x * zβ»ΒΉ β -s := (prod_subset_iff.1 t_subset) x hx z hz,
have : x * zβ»ΒΉ β s, rw yz, simpa,
contradiction
endβ©
local attribute [instance] topological_group.regular_space
lemma topological_group.t2_space [t1_space Ξ±] : t2_space Ξ± := regular_space.t2_space Ξ±
end
section
variables [topological_space Ξ±] [comm_group Ξ±] [topological_group Ξ±]
@[to_additive]
lemma nhds_pointwise_mul (x y : Ξ±) : π (x * y) = π x * π y :=
filter_eq $ set.ext $ assume s,
begin
rw [β nhds_translation_mul_inv x, β nhds_translation_mul_inv y, β nhds_translation_mul_inv (x*y)],
split,
{ rintros β¨t, ht, tsβ©,
rcases exists_nhds_split ht with β¨V, V_mem, hβ©,
refine β¨(Ξ»a, a * xβ»ΒΉ) β»ΒΉ' V, β¨V, V_mem, subset.refl _β©,
(Ξ»a, a * yβ»ΒΉ) β»ΒΉ' V, β¨V, V_mem, subset.refl _β©, _β©,
rintros a β¨v, v_mem, w, w_mem, rflβ©,
apply ts,
simpa [mul_comm, mul_assoc, mul_left_comm] using h (v * xβ»ΒΉ) (w * yβ»ΒΉ) v_mem w_mem },
{ rintros β¨a, β¨b, hb, baβ©, c, β¨d, hd, dcβ©, acβ©,
refine β¨b β© d, inter_mem_sets hb hd, assume v, _β©,
simp only [preimage_subset_iff, mul_inv_rev, mem_preimage] at *,
rintros β¨vb, vdβ©,
refine ac β¨v * yβ»ΒΉ, _, y, _, _β©,
{ rw β mul_assoc _ _ _ at vb, exact ba _ vb },
{ apply dc y, rw mul_right_inv, exact mem_of_nhds hd },
{ simp only [inv_mul_cancel_right] } }
end
@[to_additive]
lemma nhds_is_mul_hom : is_mul_hom (Ξ»x:Ξ±, π x) := β¨Ξ»_ _, nhds_pointwise_mul _ _β©
end
end filter_mul
|
226ee6562c3bcccbc2bebf35af91ce9837cd866e
|
4a092885406df4e441e9bb9065d9405dacb94cd8
|
/src/Spa.lean
|
cd15b8f1eb19f620b680cb929083787c41380b5c
|
[
"Apache-2.0"
] |
permissive
|
semorrison/lean-perfectoid-spaces
|
78c1572cedbfae9c3e460d8aaf91de38616904d8
|
bb4311dff45791170bcb1b6a983e2591bee88a19
|
refs/heads/master
| 1,588,841,765,494
| 1,554,805,620,000
| 1,554,805,620,000
| 180,353,546
| 0
| 1
| null | 1,554,809,880,000
| 1,554,809,880,000
| null |
UTF-8
|
Lean
| false
| false
| 22,522
|
lean
|
import ring_theory.localization
import ring_theory.subring
import continuous_valuations
import Huber_pair
import Huber_ring.localization
import for_mathlib.nonarchimedean.basic
import for_mathlib.data.set.finite
import for_mathlib.uniform_space.ring -- need completions of rings plus UMP
import for_mathlib.group -- some stupid lemma about units
universes uβ uβ uβ
local attribute [instance, priority 0] classical.prop_decidable
open set function Spv valuation
variables {Ξ : Type*} [linear_ordered_comm_group Ξ]
-- Wedhorn def 7.23.
definition Spa (A : Huber_pair) : set (Spv A) :=
{v | v.is_continuous β§ β r β AβΊ, v r β€ 1}
lemma mk_mem_Spa {A : Huber_pair} {v : valuation A Ξ} :
mk v β Spa A β v.is_continuous β§ β r β AβΊ, v r β€ 1 :=
begin
apply and_congr,
{ apply is_equiv.is_continuous_iff,
apply out_mk, },
{ apply forall_congr,
intro r,
apply forall_congr,
intro hr,
convert (out_mk v) r 1;
rw [valuation.map_one] }
end
namespace Spa
variable {A : Huber_pair}
instance : has_coe (Spa A) (Spv A) := β¨subtype.valβ©
definition basic_open (r s : A) : set (Spa A) :=
{v | v r β€ v s β§ v s β 0 }
lemma mk_mem_basic_open {r s : A} {v : valuation A Ξ} {hv : mk v β Spa A} :
(β¨mk v, hvβ© : Spa A) β basic_open r s β v r β€ v s β§ v s β 0 :=
begin
apply and_congr,
{ apply out_mk, },
{ apply (out_mk v).ne_zero, },
end
instance (A : Huber_pair) : topological_space (Spa A) :=
topological_space.generate_from {U : set (Spa A) | β r s : A, U = basic_open r s}
lemma basic_open.is_open (r s : A) : is_open (basic_open r s) :=
topological_space.generate_open.basic (basic_open r s) β¨r, s, rflβ©
lemma basic_open_eq (s : A) : basic_open s s = {v | v s β 0} :=
set.ext $ Ξ» v, β¨Ξ» h, h.right, Ξ» h, β¨le_refl _, hβ©β©
-- should only be applied with (Hfin : fintype T) and (Hopen: is_open (span T))
definition rational_open (s : A) (T : set A) : set (Spa A) :=
{v | (β t β T, (v t β€ v s)) β§ (v s β 0)}
-- Here's everything in one package.
structure rational_open_data (A : Huber_pair) :=
(s : A)
(T : set A)
(Tfin : fintype T)
(Hopen : is_open ((ideal.span T) : set A))
instance (r : rational_open_data A) : fintype r.T := r.Tfin
namespace rational_open_data
def ext (rβ rβ : rational_open_data A) (hs : rβ.s = rβ.s) (hT : rβ.T = rβ.T) :
rβ = rβ :=
begin
cases rβ, cases rβ,
congr; assumption
end
def rational_open (r : rational_open_data A) : set (Spa A) :=
rational_open r.s r.T
def localization (r : rational_open_data A) := Huber_ring.away r.T r.s
instance (r : rational_open_data A) : ring_with_zero_nhd (localization r) :=
Huber_ring.away.ring_with_zero_nhd r.T r.s r.Hopen
instance (r : rational_open_data A) : comm_ring (localization r) :=
by unfold localization; apply_instance
open algebra
instance (r : rational_open_data A) : algebra A (localization r) := Huber_ring.away.algebra r.T r.s
/- In this file, we are going to take a projective limit over a preordered set of rings,
to make a presheaf. The underlying type of this preorder is `rational_open_data A`.
The correct preorder on rational open data:
def correct_preorder : preorder (rational_open_data A) :=
{ le := Ξ» r1 r2, rational_open r1 β rational_open r2,
le_refl := Ξ» _ _, id,
le_trans := Ξ» _ _ _, subset.trans,
}
One can prove (in maths) that r1 β€ r2 iff there's a continuous R-algebra morphism
of Huber pairs localization r2 β localization r1. I think the β direction of this
iff is straightforward (but I didn't think about it too carefully). However we
definitely cannot prove the β direction of this iff in this repo yet because we
don't have enough API for cont. Here is an indication
of part of the problem. localization r2 is just A[1/r2.s]. But we cannot prove yet r2.s is
invertible in localization.r1, even though we know it doesn't canish anywhere on
rational_open r2 and hence on rational_open r1, because the fact that it doesn't vanish anywhere
on rational_open r1 only means that it's not in any prime ideal corresponding
to a *continuous* valuation on localization r1; one would now need to prove that every maximal ideal
is the support of a continuous valuation, which is Wedhorn 7.52(2). This is not
too bad -- but it is work that we have not yet done. This is not the whole story though;
we would also need that r1.T is power-bounded in localization.r2
and this looks worse: it's Wedhorn 7.52(1). Everything is do-able, but it's just *long*.
Long as in "thousands more lines of code".
We have to work with a weaker preorder then, because haven't made a good enough
API for continuous valuations. We basically work with the preorder r1 β€ r2 iff
there's a continuous R-algebra map localization r2 β localization r1, i.e, we
define our way around the problem. We are fortunate in that we can prove
(in maths) that the projective limit over this preorder agrees with the projective
limit over the correct preorder.
-/
-- note: I don't think we ever use le_refl or le_trans
instance : preorder (rational_open_data A) :=
{ le := Ξ» r1 r2, β k : A, r1.s * k = r2.s β§
β tβ β r1.T, β tβ β r2.T, β N : β, r2.s ^ N * tβ = r2.s ^ N * (tβ * k),
le_refl := Ξ» r, β¨1, mul_one _, Ξ» t ht, β¨t, ht, 0, by rw mul_oneβ©β©,
le_trans := Ξ» a b c β¨k, hk, habβ© β¨l, hl, hbcβ©, β¨k * l, by rw [βmul_assoc, hk, hl],
Ξ» ta hta, begin
rcases hab ta hta with β¨tb, htb, Nab, h1β©,
rcases hbc tb htb with β¨hc, htc, Nbc, h2β©,
use hc, use htc, use (Nab + Nbc),
rw [βmul_assoc, pow_add, mul_assoc, h2, βhl, mul_pow, mul_pow],
rw (show b.s ^ Nab * l ^ Nab * (b.s ^ Nbc * l ^ Nbc * (tb * l)) =
b.s ^ Nab * tb * (l ^ Nab * (b.s ^ Nbc * l ^ Nbc * l)), by ring),
rw h1,
ring
endβ©
}
-- our preorder is weaker than the preorder we're supposed to have but don't. However
-- the projective limit we take over our preorder is provably (in maths) equal to
-- the projective limit that we cannot even formalise. The thing we definitely need
-- is that if r1 β€ r2 then there's a map localization r1 β localization r2
/-- This awful function produces r1.s as a unit in localization r2 -/
noncomputable def s_inv_aux (r1 r2 : rational_open_data A) (h : r1 β€ r2) : units (localization r2) :=
@units.unit_of_mul_left_eq_unit _ _
((of_id A (localization r2)).to_fun r1.s)
((of_id A (localization r2)).to_fun (classical.some h))
(localization.to_units (β¨r2.s, 1, by simpβ© : powers r2.s)) (begin
suffices : (of_id A (localization r2)).to_fun (r1.s * classical.some h) =
(localization.to_units (β¨r2.s, 1, by simpβ© : powers r2.s)).val,
convert this,
convert (is_ring_hom.map_mul _).symm,
apply_instance, -- stupid type class inference
rw (classical.some_spec h).1,
refl,
end)
noncomputable def rational_open_subset.restriction {r1 r2 : rational_open_data A} (h : r1 β€ r2) :
localization r1 β localization r2 :=
Huber_ring.away.lift r1.T r1.s
( show ((s_inv_aux r1 r2 h)β»ΒΉ).inv = (of_id A (localization r2)).to_fun r1.s, from rfl)
def localization.nonarchimedean (r : rational_open_data A) :
topological_add_group.nonarchimedean (localization r) :=
of_submodules_comm.nonarchimedean
section
open localization submodule Huber_ring.away
local attribute [instance] set.pointwise_mul_comm_semiring
local attribute [instance] set.mul_action
def localization.power_bounded_data (r : rational_open_data A) : set (localization r) :=
let s_inv : localization r := ((to_units β¨r.s, β¨1, by simpβ©β©)β»ΒΉ : units (localization r)) in
(s_inv β’ of_id A (localization r) '' r.T)
set_option class.instance_max_depth 50
theorem localization.power_bounded (r : rational_open_data A) :
is_power_bounded_subset (localization.power_bounded_data r) :=
begin
apply bounded.subset,
work_on_goal 0 { apply add_group.subset_closure },
show is_bounded (ring.closure (localization.power_bounded_data r)),
intros U hU,
rw of_submodules_comm.nhds_zero at hU,
cases hU with V hV,
refine β¨_, mem_nhds_sets (of_submodules_comm.is_open V) _, _β©,
{ rw submodule.mem_coe,
exact submodule.zero_mem _ },
{ intros v hv b hb,
apply hV,
rw mul_comm,
rw submodule.mem_coe at hv β’,
convert submodule.smul_mem _ _ hv,
work_on_goal 1 { exact β¨b, hbβ© },
refl }
end
end
-- To prove continuity I need to check that something is power-bounded; that's where
-- the work is here. The claim could be factored out, it's the 40 line begin/end block.
lemma rational_open_subset.restriction_is_cts {r1 r2 : rational_open_data A} (h : r1 β€ r2) :
continuous (rational_open_subset.restriction h) := Huber_ring.away.lift_continuous r1.T r1.s
(localization.nonarchimedean r2)
(Huber_ring.away.of_continuous r2.T r2.s
(show ((localization.to_units (β¨r2.s, 1, by simpβ© : powers r2.s))β»ΒΉ : units (localization r2)).inv =
(of_id A (localization r2)).to_fun r2.s, from rfl) r2.Hopen) _ _ (begin
refine power_bounded.subset _ (localization.power_bounded r2),
intros x hx,
rcases hx with β¨y, hy, hz, β¨tβ, htβ, rflβ©, rflβ©,
rw mem_singleton_iff at hy, rw hy, clear hy, clear y,
let h' := h, -- need it later
rcases h with β¨a, ha, hββ©,
rcases hβ tβ htβ with β¨tβ, htβ, N, hNβ©,
show β(s_inv_aux r1 r2 _)β»ΒΉ * to_fun (localization r2) tβ β
localization.mk 1 β¨r2.s, _β© β’ (of_id β₯A (localization r2)).to_fun '' r2.T,
rw mem_smul_set,
use (of_id β₯A (localization r2)).to_fun tβ,
existsi _, swap,
rw mem_image, use tβ, use htβ,
rw [βunits.mul_left_inj (s_inv_aux r1 r2 h'), units.mul_inv_cancel_left],
show to_fun (localization r2) tβ = to_fun (localization r2) (r1.s) *
(localization.mk 1 β¨r2.s, _β© * to_fun (localization r2) tβ),
rw [mul_comm, mul_assoc],
rw βunits.mul_left_inj (localization.to_units (β¨r2.s, 1, by simpβ© : powers r2.s)),
rw βmul_assoc,
-- t1=s1*(1/s2 * t2) in r2
have : β(localization.to_units (β¨r2.s, 1, by simpβ© : powers r2.s)) *
localization.mk (1 : A) (β¨r2.s, 1, by simpβ© : powers r2.s) = 1,
convert units.mul_inv _,
rw [this, one_mul], clear this,
show to_fun (localization r2) r2.s * _ = _,
rw βunits.mul_left_inj (localization.to_units (β¨r2.s ^ N, N, rflβ© : powers r2.s)),
show to_fun (localization r2) (r2.s ^ N) * _ = to_fun (localization r2) (r2.s ^ N) * _,
have hrh : is_ring_hom (to_fun (localization r2)) := begin
change is_ring_hom ((of_id β₯A (localization r2)).to_fun),
apply_instance,
end,
rw β@is_ring_hom.map_mul _ _ _ _ (to_fun (localization r2)) hrh,
rw β@is_ring_hom.map_mul _ _ _ _ (to_fun (localization r2)) hrh,
rw β@is_ring_hom.map_mul _ _ _ _ (to_fun (localization r2)) hrh,
rw β@is_ring_hom.map_mul _ _ _ _ (to_fun (localization r2)) hrh,
congr' 1,
rw [βmul_assoc _ tβ, hN],
rw βha, ring,
end)
-- Note: I don't think we ever use this.
noncomputable def insert_s (r : rational_open_data A) : rational_open_data A :=
{ s := r.s,
T := insert r.s r.T,
Tfin := set.fintype_insert r.s r.T, -- noncomputable!
Hopen := submodule.is_open_of_open_submodule
β¨ideal.span (r.T), r.Hopen, ideal.span_mono $ set.subset_insert _ _β©
}
-- not sure we ever use this
/-
noncomputable def inter_aux (r1 r2 : rational_open_data A) : rational_open_data A :=
{ s := r1.s * r2.s,
T := r1.T * r2.T,
Tfin := by apply_instance,
Hopen := sorry /-
need "product of open subgroups is open in a Huber ring" (because subgroup is open
iff it contains I^N for some ideal of definition)
-/
}
-/
end rational_open_data
lemma mk_mem_rational_open {s : A} {T : set A} {v : valuation A Ξ} {hv : mk v β Spa A} :
(β¨mk v, hvβ© : Spa A) β rational_open s T β (β t β T, (v t β€ v s)) β§ (v s β 0) :=
begin
apply and_congr,
{ apply forall_congr,
intro t,
apply forall_congr,
intro ht,
apply out_mk },
{ apply (out_mk v).ne_zero }
end
definition rational_open_bInter (s : A) (T : set A) :
rational_open s T = (β t β T, basic_open t s) β© {v | v s β 0} :=
begin
ext v,
split; rintros β¨hβ, hββ©; split; try { exact hβ },
{ erw set.mem_bInter_iff,
intros t ht,
split,
{ exact hβ t ht, },
{ exact hβ } },
{ intros t ht,
erw set.mem_bInter_iff at hβ,
exact (hβ t ht).1 }
end
lemma rational_open_add_s (s : A) (T : set A) :
rational_open s T = rational_open s (insert s T) :=
begin
ext v,
split; rintros β¨hβ, hββ©; split; try { exact hβ }; intros t ht,
{ cases ht,
{ rw ht, exact le_refl _ },
{ exact hβ t ht } },
{ apply hβ t,
exact mem_insert_of_mem _ ht }
end
lemma rational_open.is_open (s : A) (T : set A) [h : fintype T] :
is_open (rational_open s T) :=
begin
rw rational_open_bInter,
apply is_open_inter,
{ apply is_open_bInter β¨hβ©,
intros,
apply basic_open.is_open },
{ rw β basic_open_eq s,
apply basic_open.is_open },
end
lemma rational_open_inter.auxβ {sβ sβ : A} {Tβ Tβ : set A}
(hβ : sβ β Tβ) (hβ : sβ β Tβ) :
rational_open sβ Tβ β© rational_open sβ Tβ β
rational_open (sβ * sβ) ((*) <$> Tβ <*> Tβ) :=
begin
rintros v β¨β¨hvβ, hsββ©, β¨hvβ, hsββ©β©,
split,
{ rintros t β¨_, β¨tβ, htβ, rflβ©, β¨tβ, htβ, htβ©β©,
subst ht,
convert le_trans
(linear_ordered_comm_monoid.mul_le_mul_right (hvβ tβ htβ) _)
(linear_ordered_comm_monoid.mul_le_mul_left (hvβ tβ htβ) _);
apply valuation.map_mul },
{ rw with_zero.ne_zero_iff_exists at hsβ hsβ,
cases hsβ with Ξ³β hΞ³β,
cases hsβ with Ξ³β hΞ³β,
erw [valuation.map_mul, hΞ³β, hΞ³β],
exact with_zero.coe_ne_zero },
end
lemma rational_open_inter.auxβ {sβ sβ : A} {Tβ Tβ : set A}
(hβ : sβ β Tβ) (hβ : sβ β Tβ) :
rational_open (sβ * sβ) ((*) <$> Tβ <*> Tβ) β
rational_open sβ Tβ β© rational_open sβ Tβ :=
begin
rintros v β¨hv, hsβ©,
have vmuls : v (sβ * sβ) = v sβ * v sβ := valuation.map_mul _ _ _,
have hsβ : v sβ β 0 := Ξ» H, by simpa [-coe_fn_coe_base, vmuls, H] using hs,
have hsβ : v sβ β 0 := Ξ» H, by simpa [-coe_fn_coe_base, vmuls, H] using hs,
split; split;
try { assumption };
intros t ht;
rw with_zero.ne_zero_iff_exists at hsβ hsβ,
{ suffices H : v t * v sβ β€ v sβ * v sβ,
{ cases hsβ with Ξ³ hΞ³,
rw hΞ³ at H,
have := linear_ordered_comm_monoid.mul_le_mul_right H Ξ³β»ΒΉ,
simp [mul_assoc, -coe_fn_coe_base] at this,
erw [mul_one, mul_one] at this,
exact this },
{ erw [β valuation.map_mul, β valuation.map_mul],
exact hv (t * sβ) β¨_, β¨t, ht, rflβ©, β¨sβ, hβ, rflβ©β©, } },
{ suffices H : v sβ * v t β€ v sβ * v sβ,
{ cases hsβ with Ξ³ hΞ³,
rw hΞ³ at H,
have := linear_ordered_comm_monoid.mul_le_mul_left H Ξ³β»ΒΉ,
erw [β mul_assoc, β mul_assoc] at this,
simp [-coe_fn_coe_base] at this,
erw [one_mul, one_mul] at this,
exact this },
{ erw [β valuation.map_mul, β valuation.map_mul],
exact hv _ β¨_, β¨sβ, hβ, rflβ©, β¨t, ht, rflβ©β© } },
end
lemma rational_open_inter {sβ sβ : A} {Tβ Tβ : set A} (hβ : sβ β Tβ) (hβ : sβ β Tβ) :
rational_open sβ Tβ β© rational_open sβ Tβ =
rational_open (sβ * sβ) ((*) <$> Tβ <*> Tβ) :=
le_antisymm (rational_open_inter.auxβ hβ hβ) (rational_open_inter.auxβ hβ hβ)
@[simp] lemma rational_open_singleton {r s : A} :
rational_open s {r} = basic_open r s :=
begin
apply le_antisymm; rintros v β¨hβ, hββ©; split;
intros; simp [*] at *,
end
@[simp] lemma basic_open_eq_univ : basic_open (1 : A) (1 : A) = univ :=
univ_subset_iff.1 $ Ξ» v h, β¨le_refl _,by erw valuation.map_one; exact one_ne_zeroβ©
@[simp] lemma rational_open_eq_univ : rational_open (1 : A) {(1 : A)} = univ :=
by simp
def rational_basis (A : Huber_pair) : set (set (Spa A)) :=
{U : set (Spa A) | β {s : A} {T : set A} {hfin : fintype T} {hopen : is_open (ideal.span T).carrier},
U = rational_open s T }
lemma rational_basis.is_basis.auxβ (sβ sβ : A) (Tβ Tβ : set A) :
(*) <$> Tβ <*> Tβ β (*) <$> (insert sβ Tβ) <*> (insert sβ Tβ) :=
begin
rintros t β¨_, β¨tβ, htβ, rflβ©, β¨tβ, htβ, htβ©β©,
exact β¨_, β¨tβ, mem_insert_of_mem _ htβ, rflβ©, β¨tβ, mem_insert_of_mem _ htβ, htβ©β©
end
-- Current status: proof is broken with 2 sorries.
-- KMB remarks that we don't need this result yet so he's commenting it out for now.
-- We might well need it though!
/-
lemma rational_basis.is_basis : topological_space.is_topological_basis (rational_basis A) :=
begin
split,
{ rintros Uβ β¨sβ, Tβ, hfinβ, hopenβ, Hββ© Uβ β¨sβ, Tβ, hfinβ, hopenβ, Hββ© v hv,
use Uβ β© Uβ,
rw rational_open_add_s at Hβ Hβ,
split,
{ simp only [Hβ, Hβ, rational_open_inter, set.mem_insert_iff, true_or, eq_self_iff_true],
resetI,
refine β¨_, _, infer_instance, _, rflβ©,
-- jmc: what follows is a sketch. We can fill the gaps once we know more about topological rings
have foo := ideal.span_mono (rational_basis.is_basis.auxβ sβ sβ Tβ Tβ),
suffices : is_open (ideal.span ((*) <$> Tβ <*> Tβ)).carrier,
{ sorry /- use "foo" from two lines up -/ },
{ -- See the remarks in Wedhorn 7.30.(5).
sorry } },
{ exact β¨hv, subset.refl _β© } },
split,
{ apply le_antisymm,
{ exact subset_univ _ },
{ apply subset_sUnion_of_mem,
refine β¨(1 : A), {(1 : A)}, infer_instance, _, by simpβ©,
rw ideal.span_singleton_one,
exact is_open_univ, } },
{ apply le_antisymm,
{ delta Spa.topological_space,
rw generate_from_le_iff_subset_is_open,
rintros U β¨r, s, Hβ©,
rw [H, β rational_open_singleton],
refine topological_space.generate_open.basic _ β¨s, {r}, infer_instance, _, rflβ©,
sorry -- is this even true? I guess we shouldn't do the rw 2 lines up.
-- Instead, we should use a smarter argument that I haven't cooked up yet.
},
{ rw generate_from_le_iff_subset_is_open,
rintros U β¨s, T, hT, hT', Hβ©,
subst H,
haveI := hT,
exact rational_open.is_open s T,
} }
end
-/
-- KMB remarks that we don't need the presheaf on the basic either
/-
namespace rational_open
def presheaf.aux (s : A) (T : set A) := localization.away s
instance (s : A) (T : set A) : comm_ring (presheaf.aux s T) :=
by delta presheaf.aux; apply_instance
-- Definition of A\left(\frac T s\right) as a topological ring
def presheaf.topology (rod : rational_open_data A) :
topological_space (presheaf.aux rod.s rod.T) := sorry
/-
let As := presheaf.aux s T in
let Sβ : set As := localization.of '' A.RHuber.Aβ in
let T' : set As := localization.of '' T in
let Sβ : set As := (*) (((localization.to_units s)β»ΒΉ : units As) : As) '' T' in -- need to update mathlib
let S : set As := Sβ βͺ Sβ in
let D := ring.closure S in
let I := classical.some A.RHuber.Aβ_is_ring_of_definition.2 in
adic_topology (I * D)
-- let As := presheaf.aux s T in sorry
/-let D := ring.closure ((localize s) '' A.RHuber.Aβ βͺ (((Ξ» x, x*sβ»ΒΉ) β localize s) '' T)) in
begin
let nhd := Ξ» n : β, mul_ideal (pow_ideal ((localize s) '' A.Rplus) n) D,
sorry
end-/
-/
def presheaf' (s : A) (T : set A) [Hfin : fintype T]
(Hopen : _root_.is_open ((ideal.span T) : set A)) : Type* := sorry
-- ring_completion presheaf.aux s T
end rational_open
-/
section
open topological_space
def rational_open_data_subsets (U : opens (Spa A)) :=
{ r : rational_open_data A // r.rational_open β U}
def rational_open_data_subsets.map {U V : opens (Spa A)} (hUV : U β€ V)
(rd : rational_open_data_subsets U) :
rational_open_data_subsets V :=
β¨rd.val, set.subset.trans rd.property hUVβ©
instance (r : rational_open_data A) : uniform_space (rational_open_data.localization r) :=
topological_add_group.to_uniform_space _
def rational_open_data.presheaf (r : rational_open_data A) :=
ring_completion (rational_open_data.localization r)
def presheaf (U : opens (Spa A)) :=
{f : Ξ (rd : rational_open_data_subsets U), ring_completion (rational_open_data.localization rd.1) //
β (rd1 rd2 : rational_open_data_subsets U) (h : rd1.1 β€ rd2.1),
ring_completion.map (rational_open_data.rational_open_subset.restriction h) (f rd1) = (f rd2)} -- agrees on overlaps
def presheaf.map {U V : opens (Spa A)} (hUV : U β€ V) :
presheaf V β presheaf U :=
Ξ» f, β¨Ξ» rd, f.val β¨rd.val, set.subset.trans rd.2 hUVβ©,
begin
intros,
let X := f.2 (rational_open_data_subsets.map hUV rd1)
(rational_open_data_subsets.map hUV rd2) h,
exact X,
endβ©
lemma presheaf.map_id (U : opens (Spa A)) :
presheaf.map (le_refl U) = id :=
by { delta presheaf.map, tidy }
lemma presheaf.map_comp {U V W : opens (Spa A)} (hUV : U β€ V) (hVW : V β€ W) :
presheaf.map hUV β presheaf.map hVW = presheaf.map (le_trans hUV hVW) :=
by { delta presheaf.map, tidy }
end
instance (rd : rational_open_data A): uniform_add_group (rational_open_data.localization rd) :=
topological_add_group_is_uniform
noncomputable
example (rd : rational_open_data A): ring (ring_completion (rational_open_data.localization rd))
:= by apply_instance
end Spa
-- remember that a rational open is not actually `rational_open s T` in full
-- generality -- we also need that T is finite and that T generates an open ideal in A.
-- The construction on p73/74 (note typo in first line of p74 -- ideal should be I.D)
-- gives A<T/s> (need completion) and A<T/s>^+ (need integral closure).
-- Once we have this, we see mid way through p75 that the definition of the presheaf
-- on V is proj lim of O_X(U) as U runs through rationals opens in V. This gets
-- the projective limit topology and then we have a presheaf (hopefully this is
-- straightforward) of complete topological rings (need proj lim of complete is complete)
-- We then need the valuations on the stalks (this is direct limit in cat of rings, forget
-- the topology). This will be fiddly but not impossible.
-- We then have an object in V^pre and I think then everything should follow.
|
f1a822956f2782baa11a6bc28503a056225ab5b8
|
4d2583807a5ac6caaffd3d7a5f646d61ca85d532
|
/src/ring_theory/eisenstein_criterion.lean
|
f5966efa52132b9ae7058e4a91aa450c4cf7d754
|
[
"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
| 5,553
|
lean
|
/-
Copyright (c) 2020 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes
-/
import ring_theory.prime
import ring_theory.polynomial.content
/-!
# Eisenstein's criterion
A proof of a slight generalisation of Eisenstein's criterion for the irreducibility of
a polynomial over an integral domain.
-/
open polynomial ideal.quotient
variables {R : Type*} [comm_ring R]
namespace polynomial
namespace eisenstein_criterion_aux
/- Section for auxiliary lemmas used in the proof of `irreducible_of_eisenstein_criterion`-/
lemma map_eq_C_mul_X_pow_of_forall_coeff_mem {f : polynomial R} {P : ideal R}
(hfP : β (n : β), βn < f.degree β f.coeff n β P) (hf0 : f β 0) :
map (mk P) f = C ((mk P) f.leading_coeff) * X ^ f.nat_degree :=
polynomial.ext (Ξ» n, begin
rcases lt_trichotomy βn (degree f) with h | h | h,
{ erw [coeff_map, eq_zero_iff_mem.2 (hfP n h), coeff_C_mul, coeff_X_pow, if_neg, mul_zero],
rintro rfl, exact not_lt_of_ge degree_le_nat_degree h },
{ have : nat_degree f = n, from nat_degree_eq_of_degree_eq_some h.symm,
rw [coeff_C_mul, coeff_X_pow, if_pos this.symm, mul_one, leading_coeff, this, coeff_map] },
{ rw [coeff_eq_zero_of_degree_lt, coeff_eq_zero_of_degree_lt],
{ refine lt_of_le_of_lt (degree_C_mul_X_pow_le _ _) _,
rwa β degree_eq_nat_degree hf0 },
{ exact lt_of_le_of_lt (degree_map_le _ _) h } }
end)
lemma le_nat_degree_of_map_eq_mul_X_pow {n : β}
{P : ideal R} (hP : P.is_prime) {q : polynomial R} {c : polynomial P.quotient}
(hq : map (mk P) q = c * X ^ n) (hc0 : c.degree = 0) : n β€ q.nat_degree :=
with_bot.coe_le_coe.1
(calc βn = degree (q.map (mk P)) :
by rw [hq, degree_mul, hc0, zero_add, degree_pow, degree_X, nsmul_one, nat.cast_with_bot]
... β€ degree q : degree_map_le _ _
... β€ nat_degree q : degree_le_nat_degree)
lemma eval_zero_mem_ideal_of_eq_mul_X_pow {n : β} {P : ideal R}
{q : polynomial R} {c : polynomial P.quotient}
(hq : map (mk P) q = c * X ^ n) (hn0 : 0 < n) : eval 0 q β P :=
by rw [β coeff_zero_eq_eval_zero, β eq_zero_iff_mem, β coeff_map,
coeff_zero_eq_eval_zero, hq, eval_mul, eval_pow, eval_X, zero_pow hn0, mul_zero]
lemma is_unit_of_nat_degree_eq_zero_of_forall_dvd_is_unit {p q : polynomial R}
(hu : β (x : R), C x β£ p * q β is_unit x) (hpm : p.nat_degree = 0) :
is_unit p :=
begin
rw [eq_C_of_degree_le_zero (nat_degree_eq_zero_iff_degree_le_zero.1 hpm), is_unit_C],
refine hu _ _,
rw [β eq_C_of_degree_le_zero (nat_degree_eq_zero_iff_degree_le_zero.1 hpm)],
exact dvd_mul_right _ _
end
end eisenstein_criterion_aux
open eisenstein_criterion_aux
variables [is_domain R]
/-- If `f` is a non constant polynomial with coefficients in `R`, and `P` is a prime ideal in `R`,
then if every coefficient in `R` except the leading coefficient is in `P`, and
the trailing coefficient is not in `P^2` and no non units in `R` divide `f`, then `f` is
irreducible. -/
theorem irreducible_of_eisenstein_criterion {f : polynomial R} {P : ideal R} (hP : P.is_prime)
(hfl : f.leading_coeff β P)
(hfP : β n : β, βn < degree f β f.coeff n β P)
(hfd0 : 0 < degree f) (h0 : f.coeff 0 β P^2)
(hu : f.is_primitive) : irreducible f :=
have hf0 : f β 0, from Ξ» _, by simp only [*, not_true, submodule.zero_mem, coeff_zero] at *,
have hf : f.map (mk P) = C (mk P (leading_coeff f)) * X ^ nat_degree f,
from map_eq_C_mul_X_pow_of_forall_coeff_mem hfP hf0,
have hfd0 : 0 < f.nat_degree, from with_bot.coe_lt_coe.1
(lt_of_lt_of_le hfd0 degree_le_nat_degree),
β¨mt degree_eq_zero_of_is_unit (Ξ» h, by simp only [*, lt_irrefl] at *),
begin
rintros p q rfl,
rw [map_mul] at hf,
rcases mul_eq_mul_prime_pow (show prime (X : polynomial (ideal.quotient P)),
from monic_X.prime_of_degree_eq_one degree_X) hf with
β¨m, n, b, c, hmnd, hbc, hp, hqβ©,
have hmn : 0 < m β 0 < n β false,
{ assume hm0 hn0,
refine h0 _,
rw [coeff_zero_eq_eval_zero, eval_mul, sq],
exact ideal.mul_mem_mul
(eval_zero_mem_ideal_of_eq_mul_X_pow hp hm0)
(eval_zero_mem_ideal_of_eq_mul_X_pow hq hn0) },
have hpql0 : (mk P) (p * q).leading_coeff β 0,
{ rwa [ne.def, eq_zero_iff_mem] },
have hp0 : p β 0, from Ξ» h, by simp only [*, zero_mul, eq_self_iff_true, not_true, ne.def] at *,
have hq0 : q β 0, from Ξ» h, by simp only [*, eq_self_iff_true, not_true, ne.def, mul_zero] at *,
have hbc0 : degree b = 0 β§ degree c = 0,
{ apply_fun degree at hbc,
rwa [degree_C hpql0, degree_mul, eq_comm, nat.with_bot.add_eq_zero_iff] at hbc },
have hmp : m β€ nat_degree p,
from le_nat_degree_of_map_eq_mul_X_pow hP hp hbc0.1,
have hnq : n β€ nat_degree q,
from le_nat_degree_of_map_eq_mul_X_pow hP hq hbc0.2,
have hpmqn : p.nat_degree = m β§ q.nat_degree = n,
{ rw [nat_degree_mul hp0 hq0] at hmnd,
clear_except hmnd hmp hnq,
contrapose hmnd,
apply ne_of_lt,
rw not_and_distrib at hmnd,
cases hmnd,
{ exact add_lt_add_of_lt_of_le (lt_of_le_of_ne hmp (ne.symm hmnd)) hnq },
{ exact add_lt_add_of_le_of_lt hmp (lt_of_le_of_ne hnq (ne.symm hmnd)) } },
obtain rfl | rfl : m = 0 β¨ n = 0,
{ rwa [pos_iff_ne_zero, pos_iff_ne_zero, imp_false, not_not,
β or_iff_not_imp_left] at hmn },
{ exact or.inl (is_unit_of_nat_degree_eq_zero_of_forall_dvd_is_unit hu hpmqn.1) },
{ exact or.inr (is_unit_of_nat_degree_eq_zero_of_forall_dvd_is_unit
(by simpa only [mul_comm] using hu) hpmqn.2) }
endβ©
end polynomial
|
ec7d56357796a2fec53a1ba8bd7b0fdc3e9a66c6
|
3dc4623269159d02a444fe898d33e8c7e7e9461b
|
/.github/workflows/geo/Omega.lean
|
bdd9f18efee484f379c00c135c7e9a8f200cb246
|
[] |
no_license
|
Or7ando/lean
|
cc003e6c41048eae7c34aa6bada51c9e9add9e66
|
d41169cf4e416a0d42092fb6bdc14131cee9dd15
|
refs/heads/master
| 1,650,600,589,722
| 1,587,262,906,000
| 1,587,262,906,000
| 255,387,160
| 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 1,820
|
lean
|
import .global
import .ideals
universes u
local notation `Ring` := CommRing.{u}
local notation `Set` := Type u
namespace Omega
def Ξ©_obj (A : Ring):= ideal A
def Ξ©_map (A B :Ring)(Ο : A βΆ B) : Ξ©_obj A β Ξ©_obj B:= Ξ» I,begin
exact ideal.map Ο I,
end
def Ξ© : Ring β₯€ Set :=
{
obj := Ξ» A, ideal A,
map := Ξ» A B Ο, ideal.map Ο,
map_id' := Ξ» A, begin
funext I,
exact ideal.ideal_id A I,
end,
map_comp' := Ξ» X Y Z f g, begin
funext I,
exact ideal.ideal_comp X Y Z I f g,
end,
}
-- instance (A : Ring) : has_mem(Ξ©.obj(A)) := β¨Ξ» x, β©
end Omega
namespace Omega_2
open Omega
variables (A :Ring)
def square_ideal_app (A : Ring) : ideal A β ideal A := Ξ» I, begin
exact (I * I),
end
def square_ideal_naturality (A B :Ring) (Ο : A βΆ B) :
Ξ©.map Ο β« square_ideal_app B = square_ideal_app A β« Ξ©.map Ο := begin
rw [category_theory.types_comp,category_theory.types_comp],
funext I,
rw [ show (Ξ©.map Ο β square_ideal_app A) I = ideal.map Ο (I * I),from rfl,ideal.map_mul Ο I I],
exact rfl,
end
def square_ideal : Ξ© βΆ Ξ© :=
{
app := Ξ» A : Ring, square_ideal_app A,
naturality' := square_ideal_naturality,
}
end Omega_2
-- namespace ONE
-- def ONE_map (A B : Ring) (Ο : A βΆ B) : (β₯ : ideal A) β (β₯ : ideal B)
-- := Ξ» I, begin
-- have Hyp : ideal.map Ο (β₯) = β₯ ,
-- exact ideal.map_bot Ο,
-- exact ideal.map Ο I,
-- end
-- def ONE : Ring β₯€ Set :=
-- {
-- obj := Ξ» A, {I : ideal A | I = β₯ },
-- map := ONE_map,
-- -- map_id' := Ξ» A, begin
-- -- funext I,
-- -- exact ideal.ideal_id A I,
-- -- end,
-- -- map_comp' := Ξ» X Y Z f g, begin
-- -- funext I,
-- -- exact ideal.ideal_comp X Y Z I f g,
-- -- end,
-- }
-- end ONE
|
789989d77414204d40652a036f21b489765eff81
|
b7f22e51856f4989b970961f794f1c435f9b8f78
|
/library/init/default.lean
|
1f7bcbb7d07c2fbf70bce70ce26bffccff445ef9
|
[
"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
| 450
|
lean
|
/-
Copyright (c) 2014 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
prelude
import init.datatypes init.reserved_notation init.tactic init.logic
import init.relation init.wf init.nat init.wf_k init.prod
import init.bool init.num init.sigma init.measurable init.setoid init.quot
import init.funext init.function init.subtype init.classical init.simplifier
|
2015af8982ac5c916f3226c31f33ecb94c564eac
|
c777c32c8e484e195053731103c5e52af26a25d1
|
/src/topology/algebra/module/multilinear.lean
|
efa86ed869ffc24e7a71c47c394f74073dd0ebf0
|
[
"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
| 22,458
|
lean
|
/-
Copyright (c) 2020 SΓ©bastien GouΓ«zel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: SΓ©bastien GouΓ«zel
-/
import topology.algebra.module.basic
import linear_algebra.multilinear.basic
/-!
# Continuous multilinear maps
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
We define continuous multilinear maps as maps from `Ξ (i : ΞΉ), Mβ i` to `Mβ` which are multilinear
and continuous, by extending the space of multilinear maps with a continuity assumption.
Here, `Mβ i` and `Mβ` are modules over a ring `R`, and `ΞΉ` is an arbitrary type, and all these
spaces are also topological spaces.
## Main definitions
* `continuous_multilinear_map R Mβ Mβ` is the space of continuous multilinear maps from
`Ξ (i : ΞΉ), Mβ i` to `Mβ`. We show that it is an `R`-module.
## Implementation notes
We mostly follow the API of multilinear maps.
## Notation
We introduce the notation `M [Γn]βL[R] M'` for the space of continuous `n`-multilinear maps from
`M^n` to `M'`. This is a particular case of the general notion (where we allow varying dependent
types as the arguments of our continuous multilinear maps), but arguably the most important one,
especially when defining iterated derivatives.
-/
open function fin set
open_locale big_operators
universes u v w wβ wβ' wβ wβ wβ
variables {R : Type u} {ΞΉ : Type v} {n : β} {M : fin n.succ β Type w} {Mβ : ΞΉ β Type wβ}
{Mβ' : ΞΉ β Type wβ'} {Mβ : Type wβ} {Mβ : Type wβ} {Mβ : Type wβ}
/-- Continuous multilinear maps over the ring `R`, from `Ξ i, Mβ i` to `Mβ` where `Mβ i` and `Mβ`
are modules over `R` with a topological structure. In applications, there will be compatibility
conditions between the algebraic and the topological structures, but this is not needed for the
definition. -/
structure continuous_multilinear_map (R : Type u) {ΞΉ : Type v} (Mβ : ΞΉ β Type wβ) (Mβ : Type wβ)
[semiring R] [βi, add_comm_monoid (Mβ i)] [add_comm_monoid Mβ]
[βi, module R (Mβ i)] [module R Mβ] [βi, topological_space (Mβ i)] [topological_space Mβ]
extends multilinear_map R Mβ Mβ :=
(cont : continuous to_fun)
notation M `[Γ`:25 n `]βL[`:25 R `] ` M' := continuous_multilinear_map R (Ξ» (i : fin n), M) M'
namespace continuous_multilinear_map
section semiring
variables [semiring R]
[Ξ i, add_comm_monoid (M i)] [Ξ i, add_comm_monoid (Mβ i)] [Ξ i, add_comm_monoid (Mβ' i)]
[add_comm_monoid Mβ] [add_comm_monoid Mβ] [add_comm_monoid Mβ] [Ξ i, module R (M i)]
[Ξ i, module R (Mβ i)] [Ξ i, module R (Mβ' i)] [module R Mβ]
[module R Mβ] [module R Mβ]
[Ξ i, topological_space (M i)] [Ξ i, topological_space (Mβ i)] [Ξ i, topological_space (Mβ' i)]
[topological_space Mβ] [topological_space Mβ] [topological_space Mβ]
(f f' : continuous_multilinear_map R Mβ Mβ)
theorem to_multilinear_map_injective :
function.injective (continuous_multilinear_map.to_multilinear_map :
continuous_multilinear_map R Mβ Mβ β multilinear_map R Mβ Mβ)
| β¨f, hfβ© β¨g, hgβ© rfl := rfl
instance continuous_map_class :
continuous_map_class (continuous_multilinear_map R Mβ Mβ) (Ξ i, Mβ i) Mβ :=
{ coe := Ξ» f, f.to_fun,
coe_injective' := Ξ» f g h, to_multilinear_map_injective $ multilinear_map.coe_injective h,
map_continuous := continuous_multilinear_map.cont }
instance : has_coe_to_fun (continuous_multilinear_map R Mβ Mβ) (Ξ» _, (Ξ i, Mβ i) β Mβ) :=
β¨Ξ» f, fβ©
/-- See Note [custom simps projection]. We need to specify this projection explicitly in this case,
because it is a composition of multiple projections. -/
def simps.apply (Lβ : continuous_multilinear_map R Mβ Mβ) (v : Ξ i, Mβ i) : Mβ := Lβ v
initialize_simps_projections continuous_multilinear_map
(-to_multilinear_map, to_multilinear_map_to_fun β apply)
@[continuity] lemma coe_continuous : continuous (f : (Ξ i, Mβ i) β Mβ) := f.cont
@[simp] lemma coe_coe : (f.to_multilinear_map : (Ξ i, Mβ i) β Mβ) = f := rfl
@[ext] theorem ext {f f' : continuous_multilinear_map R Mβ Mβ} (H : β x, f x = f' x) : f = f' :=
fun_like.ext _ _ H
theorem ext_iff {f f' : continuous_multilinear_map R Mβ Mβ} : f = f' β β x, f x = f' x :=
by rw [β to_multilinear_map_injective.eq_iff, multilinear_map.ext_iff]; refl
@[simp] lemma map_add [decidable_eq ΞΉ] (m : Ξ i, Mβ i) (i : ΞΉ) (x y : Mβ i) :
f (update m i (x + y)) = f (update m i x) + f (update m i y) :=
f.map_add' m i x y
@[simp] lemma map_smul [decidable_eq ΞΉ] (m : Ξ i, Mβ i) (i : ΞΉ) (c : R) (x : Mβ i) :
f (update m i (c β’ x)) = c β’ f (update m i x) :=
f.map_smul' m i c x
lemma map_coord_zero {m : Ξ i, Mβ i} (i : ΞΉ) (h : m i = 0) : f m = 0 :=
f.to_multilinear_map.map_coord_zero i h
@[simp] lemma map_zero [nonempty ΞΉ] : f 0 = 0 :=
f.to_multilinear_map.map_zero
instance : has_zero (continuous_multilinear_map R Mβ Mβ) :=
β¨{ cont := continuous_const, ..(0 : multilinear_map R Mβ Mβ) }β©
instance : inhabited (continuous_multilinear_map R Mβ Mβ) := β¨0β©
@[simp] lemma zero_apply (m : Ξ i, Mβ i) : (0 : continuous_multilinear_map R Mβ Mβ) m = 0 := rfl
@[simp] lemma to_multilinear_map_zero :
(0 : continuous_multilinear_map R Mβ Mβ).to_multilinear_map = 0 :=
rfl
section has_smul
variables {R' R'' A : Type*} [monoid R'] [monoid R''] [semiring A]
[Ξ i, module A (Mβ i)] [module A Mβ]
[distrib_mul_action R' Mβ] [has_continuous_const_smul R' Mβ] [smul_comm_class A R' Mβ]
[distrib_mul_action R'' Mβ] [has_continuous_const_smul R'' Mβ] [smul_comm_class A R'' Mβ]
instance : has_smul R' (continuous_multilinear_map A Mβ Mβ) :=
β¨Ξ» c f, { cont := f.cont.const_smul c, .. c β’ f.to_multilinear_map }β©
@[simp] lemma smul_apply (f : continuous_multilinear_map A Mβ Mβ) (c : R') (m : Ξ i, Mβ i) :
(c β’ f) m = c β’ f m := rfl
@[simp] lemma to_multilinear_map_smul (c : R') (f : continuous_multilinear_map A Mβ Mβ) :
(c β’ f).to_multilinear_map = c β’ f.to_multilinear_map :=
rfl
instance [smul_comm_class R' R'' Mβ] :
smul_comm_class R' R'' (continuous_multilinear_map A Mβ Mβ) :=
β¨Ξ» cβ cβ f, ext $ Ξ» x, smul_comm _ _ _β©
instance [has_smul R' R''] [is_scalar_tower R' R'' Mβ] :
is_scalar_tower R' R'' (continuous_multilinear_map A Mβ Mβ) :=
β¨Ξ» cβ cβ f, ext $ Ξ» x, smul_assoc _ _ _β©
instance [distrib_mul_action R'α΅α΅α΅ Mβ] [is_central_scalar R' Mβ] :
is_central_scalar R' (continuous_multilinear_map A Mβ Mβ) :=
β¨Ξ» cβ f, ext $ Ξ» x, op_smul_eq_smul _ _β©
instance : mul_action R' (continuous_multilinear_map A Mβ Mβ) :=
function.injective.mul_action to_multilinear_map to_multilinear_map_injective (Ξ» _ _, rfl)
end has_smul
section has_continuous_add
variable [has_continuous_add Mβ]
instance : has_add (continuous_multilinear_map R Mβ Mβ) :=
β¨Ξ» f f', β¨f.to_multilinear_map + f'.to_multilinear_map, f.cont.add f'.contβ©β©
@[simp] lemma add_apply (m : Ξ i, Mβ i) : (f + f') m = f m + f' m := rfl
@[simp] lemma to_multilinear_map_add (f g : continuous_multilinear_map R Mβ Mβ) :
(f + g).to_multilinear_map = f.to_multilinear_map + g.to_multilinear_map :=
rfl
instance add_comm_monoid : add_comm_monoid (continuous_multilinear_map R Mβ Mβ) :=
to_multilinear_map_injective.add_comm_monoid _ rfl (Ξ» _ _, rfl) (Ξ» _ _, rfl)
/-- Evaluation of a `continuous_multilinear_map` at a vector as an `add_monoid_hom`. -/
def apply_add_hom (m : Ξ i, Mβ i) : continuous_multilinear_map R Mβ Mβ β+ Mβ :=
β¨Ξ» f, f m, rfl, Ξ» _ _, rflβ©
@[simp] lemma sum_apply {Ξ± : Type*} (f : Ξ± β continuous_multilinear_map R Mβ Mβ)
(m : Ξ i, Mβ i) {s : finset Ξ±} : (β a in s, f a) m = β a in s, f a m :=
(apply_add_hom m).map_sum f s
end has_continuous_add
/-- If `f` is a continuous multilinear map, then `f.to_continuous_linear_map m i` is the continuous
linear map obtained by fixing all coordinates but `i` equal to those of `m`, and varying the
`i`-th coordinate. -/
def to_continuous_linear_map [decidable_eq ΞΉ] (m : Ξ i, Mβ i) (i : ΞΉ) : Mβ i βL[R] Mβ :=
{ cont := f.cont.comp (continuous_const.update i continuous_id),
.. f.to_multilinear_map.to_linear_map m i }
/-- The cartesian product of two continuous multilinear maps, as a continuous multilinear map. -/
def prod (f : continuous_multilinear_map R Mβ Mβ) (g : continuous_multilinear_map R Mβ Mβ) :
continuous_multilinear_map R Mβ (Mβ Γ Mβ) :=
{ cont := f.cont.prod_mk g.cont,
.. f.to_multilinear_map.prod g.to_multilinear_map }
@[simp] lemma prod_apply
(f : continuous_multilinear_map R Mβ Mβ) (g : continuous_multilinear_map R Mβ Mβ) (m : Ξ i, Mβ i) :
(f.prod g) m = (f m, g m) := rfl
/-- Combine a family of continuous multilinear maps with the same domain and codomains `M' i` into a
continuous multilinear map taking values in the space of functions `Ξ i, M' i`. -/
def pi {ΞΉ' : Type*} {M' : ΞΉ' β Type*} [Ξ i, add_comm_monoid (M' i)] [Ξ i, topological_space (M' i)]
[Ξ i, module R (M' i)] (f : Ξ i, continuous_multilinear_map R Mβ (M' i)) :
continuous_multilinear_map R Mβ (Ξ i, M' i) :=
{ cont := continuous_pi $ Ξ» i, (f i).coe_continuous,
to_multilinear_map := multilinear_map.pi (Ξ» i, (f i).to_multilinear_map) }
@[simp] lemma coe_pi {ΞΉ' : Type*} {M' : ΞΉ' β Type*} [Ξ i, add_comm_monoid (M' i)]
[Ξ i, topological_space (M' i)] [Ξ i, module R (M' i)]
(f : Ξ i, continuous_multilinear_map R Mβ (M' i)) :
β(pi f) = Ξ» m j, f j m :=
rfl
lemma pi_apply {ΞΉ' : Type*} {M' : ΞΉ' β Type*} [Ξ i, add_comm_monoid (M' i)]
[Ξ i, topological_space (M' i)] [Ξ i, module R (M' i)]
(f : Ξ i, continuous_multilinear_map R Mβ (M' i)) (m : Ξ i, Mβ i) (j : ΞΉ') :
pi f m j = f j m :=
rfl
section
variables (R Mβ)
/-- The evaluation map from `ΞΉ β Mβ` to `Mβ` is multilinear at a given `i` when `ΞΉ` is subsingleton.
-/
@[simps to_multilinear_map apply]
def of_subsingleton [subsingleton ΞΉ] (i' : ΞΉ) : continuous_multilinear_map R (Ξ» _ : ΞΉ, Mβ) Mβ :=
{ to_multilinear_map := multilinear_map.of_subsingleton R _ i',
cont := continuous_apply _ }
variables (Mβ) {Mβ}
/-- The constant map is multilinear when `ΞΉ` is empty. -/
@[simps to_multilinear_map apply]
def const_of_is_empty [is_empty ΞΉ] (m : Mβ) : continuous_multilinear_map R Mβ Mβ :=
{ to_multilinear_map := multilinear_map.const_of_is_empty R _ m,
cont := continuous_const }
end
/-- If `g` is continuous multilinear and `f` is a collection of continuous linear maps,
then `g (fβ mβ, ..., fβ mβ)` is again a continuous multilinear map, that we call
`g.comp_continuous_linear_map f`. -/
def comp_continuous_linear_map
(g : continuous_multilinear_map R Mβ' Mβ) (f : Ξ i : ΞΉ, Mβ i βL[R] Mβ' i) :
continuous_multilinear_map R Mβ Mβ :=
{ cont := g.cont.comp $ continuous_pi $ Ξ»j, (f j).cont.comp $ continuous_apply _,
.. g.to_multilinear_map.comp_linear_map (Ξ» i, (f i).to_linear_map) }
@[simp] lemma comp_continuous_linear_map_apply (g : continuous_multilinear_map R Mβ' Mβ)
(f : Ξ i : ΞΉ, Mβ i βL[R] Mβ' i) (m : Ξ i, Mβ i) :
g.comp_continuous_linear_map f m = g (Ξ» i, f i $ m i) :=
rfl
/-- Composing a continuous multilinear map with a continuous linear map gives again a
continuous multilinear map. -/
def _root_.continuous_linear_map.comp_continuous_multilinear_map
(g : Mβ βL[R] Mβ) (f : continuous_multilinear_map R Mβ Mβ) :
continuous_multilinear_map R Mβ Mβ :=
{ cont := g.cont.comp f.cont,
.. g.to_linear_map.comp_multilinear_map f.to_multilinear_map }
@[simp] lemma _root_.continuous_linear_map.comp_continuous_multilinear_map_coe (g : Mβ βL[R] Mβ)
(f : continuous_multilinear_map R Mβ Mβ) :
((g.comp_continuous_multilinear_map f) : (Ξ i, Mβ i) β Mβ) =
(g : Mβ β Mβ) β (f : (Ξ i, Mβ i) β Mβ) :=
by { ext m, refl }
/-- `continuous_multilinear_map.pi` as an `equiv`. -/
@[simps]
def pi_equiv {ΞΉ' : Type*} {M' : ΞΉ' β Type*} [Ξ i, add_comm_monoid (M' i)]
[Ξ i, topological_space (M' i)] [Ξ i, module R (M' i)] :
(Ξ i, continuous_multilinear_map R Mβ (M' i)) β
continuous_multilinear_map R Mβ (Ξ i, M' i) :=
{ to_fun := continuous_multilinear_map.pi,
inv_fun := Ξ» f i, (continuous_linear_map.proj i : _ βL[R] M' i).comp_continuous_multilinear_map f,
left_inv := Ξ» f, by { ext, refl },
right_inv := Ξ» f, by { ext, refl } }
/-- In the specific case of continuous multilinear maps on spaces indexed by `fin (n+1)`, where one
can build an element of `Ξ (i : fin (n+1)), M i` using `cons`, one can express directly the
additivity of a multilinear map along the first variable. -/
lemma cons_add (f : continuous_multilinear_map R M Mβ) (m : Ξ (i : fin n), M i.succ) (x y : M 0) :
f (cons (x+y) m) = f (cons x m) + f (cons y m) :=
f.to_multilinear_map.cons_add m x y
/-- In the specific case of continuous multilinear maps on spaces indexed by `fin (n+1)`, where one
can build an element of `Ξ (i : fin (n+1)), M i` using `cons`, one can express directly the
multiplicativity of a multilinear map along the first variable. -/
lemma cons_smul
(f : continuous_multilinear_map R M Mβ) (m : Ξ (i : fin n), M i.succ) (c : R) (x : M 0) :
f (cons (c β’ x) m) = c β’ f (cons x m) :=
f.to_multilinear_map.cons_smul m c x
lemma map_piecewise_add [decidable_eq ΞΉ] (m m' : Ξ i, Mβ i) (t : finset ΞΉ) :
f (t.piecewise (m + m') m') = β s in t.powerset, f (s.piecewise m m') :=
f.to_multilinear_map.map_piecewise_add _ _ _
/-- Additivity of a continuous multilinear map along all coordinates at the same time,
writing `f (m + m')` as the sum of `f (s.piecewise m m')` over all sets `s`. -/
lemma map_add_univ [decidable_eq ΞΉ] [fintype ΞΉ] (m m' : Ξ i, Mβ i) :
f (m + m') = β s : finset ΞΉ, f (s.piecewise m m') :=
f.to_multilinear_map.map_add_univ _ _
section apply_sum
open fintype finset
variables {Ξ± : ΞΉ β Type*} [fintype ΞΉ] (g : Ξ i, Ξ± i β Mβ i) (A : Ξ i, finset (Ξ± i))
/-- If `f` is continuous multilinear, then `f (Ξ£_{jβ β Aβ} gβ jβ, ..., Ξ£_{jβ β Aβ} gβ jβ)` is the
sum of `f (gβ (r 1), ..., gβ (r n))` where `r` ranges over all functions with `r 1 β Aβ`, ...,
`r n β Aβ`. This follows from multilinearity by expanding successively with respect to each
coordinate. -/
lemma map_sum_finset [decidable_eq ΞΉ] :
f (Ξ» i, β j in A i, g i j) = β r in pi_finset A, f (Ξ» i, g i (r i)) :=
f.to_multilinear_map.map_sum_finset _ _
/-- If `f` is continuous multilinear, then `f (Ξ£_{jβ} gβ jβ, ..., Ξ£_{jβ} gβ jβ)` is the sum of
`f (gβ (r 1), ..., gβ (r n))` where `r` ranges over all functions `r`. This follows from
multilinearity by expanding successively with respect to each coordinate. -/
lemma map_sum [decidable_eq ΞΉ] [β i, fintype (Ξ± i)] :
f (Ξ» i, β j, g i j) = β r : Ξ i, Ξ± i, f (Ξ» i, g i (r i)) :=
f.to_multilinear_map.map_sum _
end apply_sum
section restrict_scalar
variables (R) {A : Type*} [semiring A] [has_smul R A] [Ξ (i : ΞΉ), module A (Mβ i)]
[module A Mβ] [β i, is_scalar_tower R A (Mβ i)] [is_scalar_tower R A Mβ]
/-- Reinterpret an `A`-multilinear map as an `R`-multilinear map, if `A` is an algebra over `R`
and their actions on all involved modules agree with the action of `R` on `A`. -/
def restrict_scalars (f : continuous_multilinear_map A Mβ Mβ) :
continuous_multilinear_map R Mβ Mβ :=
{ to_multilinear_map := f.to_multilinear_map.restrict_scalars R,
cont := f.cont }
@[simp] lemma coe_restrict_scalars (f : continuous_multilinear_map A Mβ Mβ) :
β(f.restrict_scalars R) = f := rfl
end restrict_scalar
end semiring
section ring
variables [ring R] [βi, add_comm_group (Mβ i)] [add_comm_group Mβ]
[βi, module R (Mβ i)] [module R Mβ] [βi, topological_space (Mβ i)] [topological_space Mβ]
(f f' : continuous_multilinear_map R Mβ Mβ)
@[simp] lemma map_sub [decidable_eq ΞΉ] (m : Ξ i, Mβ i) (i : ΞΉ) (x y : Mβ i) :
f (update m i (x - y)) = f (update m i x) - f (update m i y) :=
f.to_multilinear_map.map_sub _ _ _ _
section topological_add_group
variable [topological_add_group Mβ]
instance : has_neg (continuous_multilinear_map R Mβ Mβ) :=
β¨Ξ» f, {cont := f.cont.neg, ..(-f.to_multilinear_map)}β©
@[simp] lemma neg_apply (m : Ξ i, Mβ i) : (-f) m = - (f m) := rfl
instance : has_sub (continuous_multilinear_map R Mβ Mβ) :=
β¨Ξ» f g, { cont := f.cont.sub g.cont, .. (f.to_multilinear_map - g.to_multilinear_map) }β©
@[simp] lemma sub_apply (m : Ξ i, Mβ i) : (f - f') m = f m - f' m := rfl
instance : add_comm_group (continuous_multilinear_map R Mβ Mβ) :=
to_multilinear_map_injective.add_comm_group _
rfl (Ξ» _ _, rfl) (Ξ» _, rfl) (Ξ» _ _, rfl) (Ξ» _ _, rfl) (Ξ» _ _, rfl)
end topological_add_group
end ring
section comm_semiring
variables [comm_semiring R]
[βi, add_comm_monoid (Mβ i)] [add_comm_monoid Mβ]
[βi, module R (Mβ i)] [module R Mβ]
[βi, topological_space (Mβ i)] [topological_space Mβ]
(f : continuous_multilinear_map R Mβ Mβ)
lemma map_piecewise_smul [decidable_eq ΞΉ] (c : ΞΉ β R) (m : Ξ i, Mβ i) (s : finset ΞΉ) :
f (s.piecewise (Ξ» i, c i β’ m i) m) = (β i in s, c i) β’ f m :=
f.to_multilinear_map.map_piecewise_smul _ _ _
/-- Multiplicativity of a continuous multilinear map along all coordinates at the same time,
writing `f (Ξ» i, c i β’ m i)` as `(β i, c i) β’ f m`. -/
lemma map_smul_univ [fintype ΞΉ] (c : ΞΉ β R) (m : Ξ i, Mβ i) :
f (Ξ» i, c i β’ m i) = (β i, c i) β’ f m :=
f.to_multilinear_map.map_smul_univ _ _
end comm_semiring
section distrib_mul_action
variables {R' R'' A : Type*} [monoid R'] [monoid R''] [semiring A]
[Ξ i, add_comm_monoid (Mβ i)] [add_comm_monoid Mβ]
[Ξ i, topological_space (Mβ i)] [topological_space Mβ]
[Ξ i, module A (Mβ i)] [module A Mβ]
[distrib_mul_action R' Mβ] [has_continuous_const_smul R' Mβ] [smul_comm_class A R' Mβ]
[distrib_mul_action R'' Mβ] [has_continuous_const_smul R'' Mβ] [smul_comm_class A R'' Mβ]
instance [has_continuous_add Mβ] : distrib_mul_action R' (continuous_multilinear_map A Mβ Mβ) :=
function.injective.distrib_mul_action
β¨to_multilinear_map, to_multilinear_map_zero, to_multilinear_map_addβ©
to_multilinear_map_injective (Ξ» _ _, rfl)
end distrib_mul_action
section module
variables {R' A : Type*} [semiring R'] [semiring A]
[Ξ i, add_comm_monoid (Mβ i)] [add_comm_monoid Mβ]
[Ξ i, topological_space (Mβ i)] [topological_space Mβ] [has_continuous_add Mβ]
[Ξ i, module A (Mβ i)] [module A Mβ]
[module R' Mβ] [has_continuous_const_smul R' Mβ] [smul_comm_class A R' Mβ]
/-- The space of continuous multilinear maps over an algebra over `R` is a module over `R`, for the
pointwise addition and scalar multiplication. -/
instance : module R' (continuous_multilinear_map A Mβ Mβ) :=
function.injective.module _ β¨to_multilinear_map, to_multilinear_map_zero, to_multilinear_map_addβ©
to_multilinear_map_injective (Ξ» _ _, rfl)
/-- Linear map version of the map `to_multilinear_map` associating to a continuous multilinear map
the corresponding multilinear map. -/
@[simps] def to_multilinear_map_linear :
continuous_multilinear_map A Mβ Mβ ββ[R'] multilinear_map A Mβ Mβ :=
{ to_fun := to_multilinear_map,
map_add' := to_multilinear_map_add,
map_smul' := to_multilinear_map_smul }
/-- `continuous_multilinear_map.pi` as a `linear_equiv`. -/
@[simps {simp_rhs := tt}]
def pi_linear_equiv {ΞΉ' : Type*} {M' : ΞΉ' β Type*}
[Ξ i, add_comm_monoid (M' i)] [Ξ i, topological_space (M' i)] [β i, has_continuous_add (M' i)]
[Ξ i, module R' (M' i)] [Ξ i, module A (M' i)] [β i, smul_comm_class A R' (M' i)]
[Ξ i, has_continuous_const_smul R' (M' i)] :
(Ξ i, continuous_multilinear_map A Mβ (M' i)) ββ[R']
continuous_multilinear_map A Mβ (Ξ i, M' i) :=
{ map_add' := Ξ» x y, rfl,
map_smul' := Ξ» c x, rfl,
.. pi_equiv }
end module
section comm_algebra
variables (R ΞΉ) (A : Type*) [fintype ΞΉ] [comm_semiring R] [comm_semiring A] [algebra R A]
[topological_space A] [has_continuous_mul A]
/-- The continuous multilinear map on `A^ΞΉ`, where `A` is a normed commutative algebra
over `π`, associating to `m` the product of all the `m i`.
See also `continuous_multilinear_map.mk_pi_algebra_fin`. -/
protected def mk_pi_algebra : continuous_multilinear_map R (Ξ» i : ΞΉ, A) A :=
{ cont := continuous_finset_prod _ $ Ξ» i hi, continuous_apply _,
to_multilinear_map := multilinear_map.mk_pi_algebra R ΞΉ A}
@[simp] lemma mk_pi_algebra_apply (m : ΞΉ β A) :
continuous_multilinear_map.mk_pi_algebra R ΞΉ A m = β i, m i :=
rfl
end comm_algebra
section algebra
variables (R n) (A : Type*) [comm_semiring R] [semiring A] [algebra R A]
[topological_space A] [has_continuous_mul A]
/-- The continuous multilinear map on `A^n`, where `A` is a normed algebra over `π`, associating to
`m` the product of all the `m i`.
See also: `continuous_multilinear_map.mk_pi_algebra`. -/
protected def mk_pi_algebra_fin : A [Γn]βL[R] A :=
{ cont := begin
change continuous (Ξ» m, (list.of_fn m).prod),
simp_rw list.of_fn_eq_map,
exact continuous_list_prod _ (Ξ» i hi, continuous_apply _),
end,
to_multilinear_map := multilinear_map.mk_pi_algebra_fin R n A}
variables {R n A}
@[simp] lemma mk_pi_algebra_fin_apply (m : fin n β A) :
continuous_multilinear_map.mk_pi_algebra_fin R n A m = (list.of_fn m).prod :=
rfl
end algebra
section smul_right
variables [comm_semiring R] [Ξ i, add_comm_monoid (Mβ i)] [add_comm_monoid Mβ]
[Ξ i, module R (Mβ i)] [module R Mβ] [topological_space R] [Ξ i, topological_space (Mβ i)]
[topological_space Mβ] [has_continuous_smul R Mβ] (f : continuous_multilinear_map R Mβ R) (z : Mβ)
/-- Given a continuous `R`-multilinear map `f` taking values in `R`, `f.smul_right z` is the
continuous multilinear map sending `m` to `f m β’ z`. -/
@[simps to_multilinear_map apply] def smul_right : continuous_multilinear_map R Mβ Mβ :=
{ to_multilinear_map := f.to_multilinear_map.smul_right z,
cont := f.cont.smul continuous_const }
end smul_right
end continuous_multilinear_map
|
4fd2d5c8cc559a66975f7267e5ba7151e5bdba9b
|
959e3de53426c90b7318223ba1036f0845387f67
|
/library/init/default.lean
|
c42e3d7b92ca1d587156d7cde86260aa9a2002d8
|
[
"Apache-2.0"
] |
permissive
|
huma23/lean
|
2fdb93e43ac8708473f341a64d434802f1a42cdd
|
75602eca5e23d2c426ef9103fb6eeb3130e36f1e
|
refs/heads/master
| 1,586,375,625,362
| 1,543,501,870,000
| 1,543,501,870,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 555
|
lean
|
/-
Copyright (c) 2014 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
prelude
import init.core init.logic init.category init.data.basic
import init.propext init.cc_lemmas init.funext init.category.combinators init.function init.classical
import init.util init.coe init.wf init.meta init.meta.well_founded_tactics init.algebra init.data
@[user_attribute]
meta def debugger.attr : user_attribute :=
{ name := `breakpoint,
descr := "breakpoint for debugger" }
|
a86e0da5c75a5bd8fadf4495ae3c74d1ee14f34e
|
4727251e0cd73359b15b664c3170e5d754078599
|
/src/analysis/normed_space/dual.lean
|
d04111b91b3e1788cc9f8e7c7bac7f1e2fed206a
|
[
"Apache-2.0"
] |
permissive
|
Vierkantor/mathlib
|
0ea59ac32a3a43c93c44d70f441c4ee810ccceca
|
83bc3b9ce9b13910b57bda6b56222495ebd31c2f
|
refs/heads/master
| 1,658,323,012,449
| 1,652,256,003,000
| 1,652,256,003,000
| 209,296,341
| 0
| 1
|
Apache-2.0
| 1,568,807,655,000
| 1,568,807,655,000
| null |
UTF-8
|
Lean
| false
| false
| 10,130
|
lean
|
/-
Copyright (c) 2020 Heather Macbeth. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Heather Macbeth
-/
import analysis.normed_space.hahn_banach
import analysis.normed_space.is_R_or_C
import analysis.locally_convex.polar
/-!
# The topological dual of a normed space
In this file we define the topological dual `normed_space.dual` of a normed space, and the
continuous linear map `normed_space.inclusion_in_double_dual` from a normed space into its double
dual.
For base field `π = β` or `π = β`, this map is actually an isometric embedding; we provide a
version `normed_space.inclusion_in_double_dual_li` of the map which is of type a bundled linear
isometric embedding, `E ββα΅’[π] (dual π (dual π E))`.
Since a lot of elementary properties don't require `eq_of_dist_eq_zero` we start setting up the
theory for `semi_normed_group` and we specialize to `normed_group` when needed.
## Main definitions
* `inclusion_in_double_dual` and `inclusion_in_double_dual_li` are the inclusion of a normed space
in its double dual, considered as a bounded linear map and as a linear isometry, respectively.
* `polar π s` is the subset of `dual π E` consisting of those functionals `x'` for which
`β₯x' zβ₯ β€ 1` for every `z β s`.
## Tags
dual
-/
noncomputable theory
open_locale classical topological_space
universes u v
namespace normed_space
section general
variables (π : Type*) [nondiscrete_normed_field π]
variables (E : Type*) [semi_normed_group E] [normed_space π E]
variables (F : Type*) [normed_group F] [normed_space π F]
/-- The topological dual of a seminormed space `E`. -/
@[derive [inhabited, semi_normed_group, normed_space π]] def dual := E βL[π] π
instance : add_monoid_hom_class (dual π E) E π := continuous_linear_map.add_monoid_hom_class
instance : has_coe_to_fun (dual π E) (Ξ» _, E β π) := continuous_linear_map.to_fun
instance : normed_group (dual π F) := continuous_linear_map.to_normed_group
instance [finite_dimensional π E] : finite_dimensional π (dual π E) :=
continuous_linear_map.finite_dimensional
/-- 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)) :=
continuous_linear_map.apply π π
@[simp] lemma dual_def (x : E) (f : dual π E) : inclusion_in_double_dual π E x f = f x := rfl
lemma inclusion_in_double_dual_norm_eq :
β₯inclusion_in_double_dual π Eβ₯ = β₯(continuous_linear_map.id π (dual π E))β₯ :=
continuous_linear_map.op_norm_flip _
lemma inclusion_in_double_dual_norm_le : β₯inclusion_in_double_dual π Eβ₯ β€ 1 :=
by { rw inclusion_in_double_dual_norm_eq, exact continuous_linear_map.norm_id_le }
lemma double_dual_bound (x : E) : β₯(inclusion_in_double_dual π E) xβ₯ β€ β₯xβ₯ :=
by simpa using continuous_linear_map.le_of_op_norm_le _ (inclusion_in_double_dual_norm_le π E) x
/-- The dual pairing as a bilinear form. -/
def dual_pairing : (dual π E) ββ[π] E ββ[π] π := continuous_linear_map.coe_lm π
@[simp] lemma dual_pairing_apply {v : dual π E} {x : E} : dual_pairing π E v x = v x := rfl
lemma dual_pairing_separating_left : (dual_pairing π E).separating_left :=
begin
rw [linear_map.separating_left_iff_ker_eq_bot, linear_map.ker_eq_bot],
exact continuous_linear_map.coe_injective,
end
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β, hfxβ© : β f : E βL[π] π, β₯fβ₯ = 1 β§ f x = β₯xβ₯ := exists_dual_vector π x h,
calc β₯xβ₯ = β₯(β₯xβ₯ : π)β₯ : is_R_or_C.norm_coe_norm.symm
... = β₯f xβ₯ : by rw hfx
... β€ M * β₯fβ₯ : hM f
... = M : by rw [hfβ, mul_one] }
end
lemma eq_zero_of_forall_dual_eq_zero {x : E} (h : β f : dual π E, f x = (0 : π)) : x = 0 :=
norm_le_zero_iff.mp (norm_le_dual_bound π x le_rfl (Ξ» f, by simp [h f]))
lemma eq_zero_iff_forall_dual_eq_zero (x : E) : x = 0 β β g : dual π E, g x = 0 :=
β¨Ξ» hx, by simp [hx], Ξ» h, eq_zero_of_forall_dual_eq_zero π hβ©
lemma eq_iff_forall_dual_eq {x y : E} :
x = y β β g : dual π E, g x = g y :=
begin
rw [β sub_eq_zero, eq_zero_iff_forall_dual_eq_zero π (x - y)],
simp [sub_eq_zero],
end
/-- The inclusion of a normed space in its double dual is an isometry onto its image.-/
def inclusion_in_double_dual_li : E ββα΅’[π] (dual π (dual π E)) :=
{ norm_map' := begin
intros x,
apply le_antisymm,
{ exact double_dual_bound π E x },
rw continuous_linear_map.norm_def,
refine le_cInf continuous_linear_map.bounds_nonempty _,
rintros c β¨hc1, hc2β©,
exact norm_le_dual_bound π x hc1 hc2
end,
.. inclusion_in_double_dual π E }
end bidual_isometry
section polar_sets
open metric set normed_space
/-- Given a subset `s` in a normed space `E` (over a field `π`), the polar
`polar π s` is the subset of `dual π E` consisting of those functionals which
evaluate to something of norm at most one at all points `z β s`. -/
def polar (π : Type*) [nondiscrete_normed_field π]
{E : Type*} [semi_normed_group E] [normed_space π E] : set E β set (dual π E) :=
(dual_pairing π E).flip.polar
variables (π : Type*) [nondiscrete_normed_field π]
variables {E : Type*} [semi_normed_group E] [normed_space π E]
lemma mem_polar_iff {x' : dual π E} (s : set E) : x' β polar π s β β z β s, β₯x' zβ₯ β€ 1 := iff.rfl
@[simp] lemma polar_univ : polar π (univ : set E) = {(0 : dual π E)} :=
(dual_pairing π E).flip.polar_univ
(linear_map.flip_separating_right.mpr (dual_pairing_separating_left π E))
lemma is_closed_polar (s : set E) : is_closed (polar π s) :=
begin
dunfold normed_space.polar,
simp only [linear_map.polar_eq_Inter, linear_map.flip_apply],
refine is_closed_bInter (Ξ» z hz, _),
exact is_closed_Iic.preimage (continuous_linear_map.apply π π z).continuous.norm
end
@[simp] lemma polar_closure (s : set E) : polar π (closure s) = polar π s :=
((dual_pairing π E).flip.polar_antitone subset_closure).antisymm $
(dual_pairing π E).flip.polar_gc.l_le $
closure_minimal ((dual_pairing π E).flip.polar_gc.le_u_l s) $
(is_closed_polar _ _).preimage (inclusion_in_double_dual π E).continuous
variables {π}
/-- If `x'` is a dual element such that the norms `β₯x' zβ₯` are bounded for `z β s`, then a
small scalar multiple of `x'` is in `polar π s`. -/
lemma smul_mem_polar {s : set E} {x' : dual π E} {c : π}
(hc : β z, z β s β β₯ x' z β₯ β€ β₯cβ₯) : cβ»ΒΉ β’ x' β polar π s :=
begin
by_cases c_zero : c = 0, { simp only [c_zero, inv_zero, zero_smul],
exact (dual_pairing π E).flip.zero_mem_polar _ },
have eq : β z, β₯ cβ»ΒΉ β’ (x' z) β₯ = β₯ cβ»ΒΉ β₯ * β₯ x' z β₯ := Ξ» z, norm_smul cβ»ΒΉ _,
have le : β z, z β s β β₯ cβ»ΒΉ β’ (x' z) β₯ β€ β₯ cβ»ΒΉ β₯ * β₯ c β₯,
{ intros z hzs,
rw eq z,
apply mul_le_mul (le_of_eq rfl) (hc z hzs) (norm_nonneg _) (norm_nonneg _), },
have cancel : β₯ cβ»ΒΉ β₯ * β₯ c β₯ = 1,
by simp only [c_zero, norm_eq_zero, ne.def, not_false_iff,
inv_mul_cancel, norm_inv],
rwa cancel at le,
end
lemma polar_ball_subset_closed_ball_div {c : π} (hc : 1 < β₯cβ₯) {r : β} (hr : 0 < r) :
polar π (ball (0 : E) r) β closed_ball (0 : dual π E) (β₯cβ₯ / r) :=
begin
intros x' hx',
rw mem_polar_iff at hx',
simp only [polar, mem_set_of_eq, mem_closed_ball_zero_iff, mem_ball_zero_iff] at *,
have hcr : 0 < β₯cβ₯ / r, from div_pos (zero_lt_one.trans hc) hr,
refine continuous_linear_map.op_norm_le_of_shell hr hcr.le hc (Ξ» x hβ hβ, _),
calc β₯x' xβ₯ β€ 1 : hx' _ hβ
... β€ (β₯cβ₯ / r) * β₯xβ₯ : (inv_pos_le_iff_one_le_mul' hcr).1 (by rwa inv_div)
end
variables (π)
lemma closed_ball_inv_subset_polar_closed_ball {r : β} :
closed_ball (0 : dual π E) rβ»ΒΉ β polar π (closed_ball (0 : E) r) :=
Ξ» x' hx' x hx,
calc β₯x' xβ₯ β€ β₯x'β₯ * β₯xβ₯ : x'.le_op_norm x
... β€ rβ»ΒΉ * r :
mul_le_mul (mem_closed_ball_zero_iff.1 hx') (mem_closed_ball_zero_iff.1 hx)
(norm_nonneg _) (dist_nonneg.trans hx')
... = r / r : inv_mul_eq_div _ _
... β€ 1 : div_self_le_one r
/-- The `polar` of closed ball in a normed space `E` is the closed ball of the dual with
inverse radius. -/
lemma polar_closed_ball
{π : Type*} [is_R_or_C π] {E : Type*} [normed_group E] [normed_space π E] {r : β} (hr : 0 < r) :
polar π (closed_ball (0 : E) r) = closed_ball (0 : dual π E) rβ»ΒΉ :=
begin
refine subset.antisymm _ (closed_ball_inv_subset_polar_closed_ball _),
intros x' h,
simp only [mem_closed_ball_zero_iff],
refine continuous_linear_map.op_norm_le_of_ball hr (inv_nonneg.mpr hr.le) (Ξ» z hz, _),
simpa only [one_div] using linear_map.bound_of_ball_bound' hr 1 x'.to_linear_map h z
end
/-- Given a neighborhood `s` of the origin in a normed space `E`, the dual norms
of all elements of the polar `polar π s` are bounded by a constant. -/
lemma bounded_polar_of_mem_nhds_zero {s : set E} (s_nhd : s β π (0 : E)) :
bounded (polar π s) :=
begin
obtain β¨a, haβ© : β a : π, 1 < β₯aβ₯ := normed_field.exists_one_lt_norm π,
obtain β¨r, r_pos, r_ballβ© : β (r : β) (hr : 0 < r), ball 0 r β s :=
metric.mem_nhds_iff.1 s_nhd,
exact bounded_closed_ball.mono (((dual_pairing π E).flip.polar_antitone r_ball).trans $
polar_ball_subset_closed_ball_div ha r_pos)
end
end polar_sets
end normed_space
|
b7402549876e5e37ee5905ac2d1cbaa25f264c61
|
d406927ab5617694ec9ea7001f101b7c9e3d9702
|
/src/measure_theory/integral/integral_eq_improper.lean
|
c0814a8b2b8301b83676b59f59ea275f6fa6ec70
|
[
"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
| 36,196
|
lean
|
/-
Copyright (c) 2021 Anatole Dedecker. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anatole Dedecker, Bhavik Mehta
-/
import measure_theory.integral.interval_integral
import order.filter.at_top_bot
import measure_theory.function.jacobian
/-!
# Links between an integral and its "improper" version
In its current state, mathlib only knows how to talk about definite ("proper") integrals,
in the sense that it treats integrals over `[x, +β)` the same as it treats integrals over
`[y, z]`. For example, the integral over `[1, +β)` is **not** defined to be the limit of
the integral over `[1, x]` as `x` tends to `+β`, which is known as an **improper integral**.
Indeed, the "proper" definition is stronger than the "improper" one. The usual counterexample
is `x β¦ sin(x)/x`, which has an improper integral over `[1, +β)` but no definite integral.
Although definite integrals have better properties, they are hardly usable when it comes to
computing integrals on unbounded sets, which is much easier using limits. Thus, in this file,
we prove various ways of studying the proper integral by studying the improper one.
## Definitions
The main definition of this file is `measure_theory.ae_cover`. It is a rather technical
definition whose sole purpose is generalizing and factoring proofs. Given an index type `ΞΉ`, a
countably generated filter `l` over `ΞΉ`, and an `ΞΉ`-indexed family `Ο` of subsets of a measurable
space `Ξ±` equipped with a measure `ΞΌ`, one should think of a hypothesis `hΟ : ae_cover ΞΌ l Ο` as
a sufficient condition for being able to interpret `β« x, f x βΞΌ` (if it exists) as the limit
of `β« x in Ο i, f x βΞΌ` as `i` tends to `l`.
When using this definition with a measure restricted to a set `s`, which happens fairly often,
one should not try too hard to use a `ae_cover` of subsets of `s`, as it often makes proofs
more complicated than necessary. See for example the proof of
`measure_theory.integrable_on_Iic_of_interval_integral_norm_tendsto` where we use `(Ξ» x, Ioi x)`
as an `ae_cover` w.r.t. `ΞΌ.restrict (Iic b)`, instead of using `(Ξ» x, Ioc x b)`.
## Main statements
- `measure_theory.ae_cover.lintegral_tendsto_of_countably_generated` : if `Ο` is a `ae_cover ΞΌ l`,
where `l` is a countably generated filter, and if `f` is a measurable `ennreal`-valued function,
then `β«β» x in Ο n, f x βΞΌ` tends to `β«β» x, f x βΞΌ` as `n` tends to `l`
- `measure_theory.ae_cover.integrable_of_integral_norm_tendsto` : if `Ο` is a `ae_cover ΞΌ l`,
where `l` is a countably generated filter, if `f` is measurable and integrable on each `Ο n`,
and if `β« x in Ο n, βf xβ βΞΌ` tends to some `I : β` as n tends to `l`, then `f` is integrable
- `measure_theory.ae_cover.integral_tendsto_of_countably_generated` : if `Ο` is a `ae_cover ΞΌ l`,
where `l` is a countably generated filter, and if `f` is measurable and integrable (globally),
then `β« x in Ο n, f x βΞΌ` tends to `β« x, f x βΞΌ` as `n` tends to `+β`.
We then specialize these lemmas to various use cases involving intervals, which are frequent
in analysis.
-/
open measure_theory filter set topological_space
open_locale ennreal nnreal topological_space
namespace measure_theory
section ae_cover
variables {Ξ± ΞΉ : Type*} [measurable_space Ξ±] (ΞΌ : measure Ξ±) (l : filter ΞΉ)
/-- A sequence `Ο` of subsets of `Ξ±` is a `ae_cover` w.r.t. a measure `ΞΌ` and a filter `l`
if almost every point (w.r.t. `ΞΌ`) of `Ξ±` eventually belongs to `Ο n` (w.r.t. `l`), and if
each `Ο n` is measurable.
This definition is a technical way to avoid duplicating a lot of proofs.
It should be thought of as a sufficient condition for being able to interpret
`β« x, f x βΞΌ` (if it exists) as the limit of `β« x in Ο n, f x βΞΌ` as `n` tends to `l`.
See for example `measure_theory.ae_cover.lintegral_tendsto_of_countably_generated`,
`measure_theory.ae_cover.integrable_of_integral_norm_tendsto` and
`measure_theory.ae_cover.integral_tendsto_of_countably_generated`. -/
structure ae_cover (Ο : ΞΉ β set Ξ±) : Prop :=
(ae_eventually_mem : βα΅ x βΞΌ, βαΆ i in l, x β Ο i)
(measurable : β i, measurable_set $ Ο i)
variables {ΞΌ} {l}
section preorder_Ξ±
variables [preorder Ξ±] [topological_space Ξ±] [order_closed_topology Ξ±]
[opens_measurable_space Ξ±] {a b : ΞΉ β Ξ±}
(ha : tendsto a l at_bot) (hb : tendsto b l at_top)
lemma ae_cover_Icc :
ae_cover ΞΌ l (Ξ» i, Icc (a i) (b i)) :=
{ ae_eventually_mem := ae_of_all ΞΌ (Ξ» x,
(ha.eventually $ eventually_le_at_bot x).mp $
(hb.eventually $ eventually_ge_at_top x).mono $
Ξ» i hbi hai, β¨hai, hbiβ© ),
measurable := Ξ» i, measurable_set_Icc }
lemma ae_cover_Ici :
ae_cover ΞΌ l (Ξ» i, Ici $ a i) :=
{ ae_eventually_mem := ae_of_all ΞΌ (Ξ» x,
(ha.eventually $ eventually_le_at_bot x).mono $
Ξ» i hai, hai ),
measurable := Ξ» i, measurable_set_Ici }
lemma ae_cover_Iic :
ae_cover ΞΌ l (Ξ» i, Iic $ b i) :=
{ ae_eventually_mem := ae_of_all ΞΌ (Ξ» x,
(hb.eventually $ eventually_ge_at_top x).mono $
Ξ» i hbi, hbi ),
measurable := Ξ» i, measurable_set_Iic }
end preorder_Ξ±
section linear_order_Ξ±
variables [linear_order Ξ±] [topological_space Ξ±] [order_closed_topology Ξ±]
[opens_measurable_space Ξ±] {a b : ΞΉ β Ξ±}
(ha : tendsto a l at_bot) (hb : tendsto b l at_top)
lemma ae_cover_Ioo [no_min_order Ξ±] [no_max_order Ξ±] :
ae_cover ΞΌ l (Ξ» i, Ioo (a i) (b i)) :=
{ ae_eventually_mem := ae_of_all ΞΌ (Ξ» x,
(ha.eventually $ eventually_lt_at_bot x).mp $
(hb.eventually $ eventually_gt_at_top x).mono $
Ξ» i hbi hai, β¨hai, hbiβ© ),
measurable := Ξ» i, measurable_set_Ioo }
lemma ae_cover_Ioc [no_min_order Ξ±] : ae_cover ΞΌ l (Ξ» i, Ioc (a i) (b i)) :=
{ ae_eventually_mem := ae_of_all ΞΌ (Ξ» x,
(ha.eventually $ eventually_lt_at_bot x).mp $
(hb.eventually $ eventually_ge_at_top x).mono $
Ξ» i hbi hai, β¨hai, hbiβ© ),
measurable := Ξ» i, measurable_set_Ioc }
lemma ae_cover_Ico [no_max_order Ξ±] : ae_cover ΞΌ l (Ξ» i, Ico (a i) (b i)) :=
{ ae_eventually_mem := ae_of_all ΞΌ (Ξ» x,
(ha.eventually $ eventually_le_at_bot x).mp $
(hb.eventually $ eventually_gt_at_top x).mono $
Ξ» i hbi hai, β¨hai, hbiβ© ),
measurable := Ξ» i, measurable_set_Ico }
lemma ae_cover_Ioi [no_min_order Ξ±] :
ae_cover ΞΌ l (Ξ» i, Ioi $ a i) :=
{ ae_eventually_mem := ae_of_all ΞΌ (Ξ» x,
(ha.eventually $ eventually_lt_at_bot x).mono $
Ξ» i hai, hai ),
measurable := Ξ» i, measurable_set_Ioi }
lemma ae_cover_Iio [no_max_order Ξ±] :
ae_cover ΞΌ l (Ξ» i, Iio $ b i) :=
{ ae_eventually_mem := ae_of_all ΞΌ (Ξ» x,
(hb.eventually $ eventually_gt_at_top x).mono $
Ξ» i hbi, hbi ),
measurable := Ξ» i, measurable_set_Iio }
end linear_order_Ξ±
section finite_intervals
variables [linear_order Ξ±] [topological_space Ξ±] [order_closed_topology Ξ±]
[opens_measurable_space Ξ±] {a b : ΞΉ β Ξ±} {A B : Ξ±}
(ha : tendsto a l (π A)) (hb : tendsto b l (π B))
lemma ae_cover_Ioo_of_Icc :
ae_cover (ΞΌ.restrict $ Ioo A B) l (Ξ» i, Icc (a i) (b i)) :=
{ ae_eventually_mem := (ae_restrict_iff' measurable_set_Ioo).mpr (
ae_of_all ΞΌ (Ξ» x hx,
(ha.eventually $ eventually_le_nhds hx.left).mp $
(hb.eventually $ eventually_ge_nhds hx.right).mono $
Ξ» i hbi hai, β¨hai, hbiβ©)),
measurable := Ξ» i, measurable_set_Icc, }
lemma ae_cover_Ioo_of_Ico :
ae_cover (ΞΌ.restrict $ Ioo A B) l (Ξ» i, Ico (a i) (b i)) :=
{ ae_eventually_mem := (ae_restrict_iff' measurable_set_Ioo).mpr (
ae_of_all ΞΌ (Ξ» x hx,
(ha.eventually $ eventually_le_nhds hx.left).mp $
(hb.eventually $ eventually_gt_nhds hx.right).mono $
Ξ» i hbi hai, β¨hai, hbiβ©)),
measurable := Ξ» i, measurable_set_Ico, }
lemma ae_cover_Ioo_of_Ioc :
ae_cover (ΞΌ.restrict $ Ioo A B) l (Ξ» i, Ioc (a i) (b i)) :=
{ ae_eventually_mem := (ae_restrict_iff' measurable_set_Ioo).mpr (
ae_of_all ΞΌ (Ξ» x hx,
(ha.eventually $ eventually_lt_nhds hx.left).mp $
(hb.eventually $ eventually_ge_nhds hx.right).mono $
Ξ» i hbi hai, β¨hai, hbiβ©)),
measurable := Ξ» i, measurable_set_Ioc, }
lemma ae_cover_Ioo_of_Ioo :
ae_cover (ΞΌ.restrict $ Ioo A B) l (Ξ» i, Ioo (a i) (b i)) :=
{ ae_eventually_mem := (ae_restrict_iff' measurable_set_Ioo).mpr (
ae_of_all ΞΌ (Ξ» x hx,
(ha.eventually $ eventually_lt_nhds hx.left).mp $
(hb.eventually $ eventually_gt_nhds hx.right).mono $
Ξ» i hbi hai, β¨hai, hbiβ©)),
measurable := Ξ» i, measurable_set_Ioo, }
variables [has_no_atoms ΞΌ]
lemma ae_cover_Ioc_of_Icc (ha : tendsto a l (π A)) (hb : tendsto b l (π B)) :
ae_cover (ΞΌ.restrict $ Ioc A B) l (Ξ» i, Icc (a i) (b i)) :=
by simp [measure.restrict_congr_set Ioo_ae_eq_Ioc.symm, ae_cover_Ioo_of_Icc ha hb]
lemma ae_cover_Ioc_of_Ico (ha : tendsto a l (π A)) (hb : tendsto b l (π B)) :
ae_cover (ΞΌ.restrict $ Ioc A B) l (Ξ» i, Ico (a i) (b i)) :=
by simp [measure.restrict_congr_set Ioo_ae_eq_Ioc.symm, ae_cover_Ioo_of_Ico ha hb]
lemma ae_cover_Ioc_of_Ioc (ha : tendsto a l (π A)) (hb : tendsto b l (π B)) :
ae_cover (ΞΌ.restrict $ Ioc A B) l (Ξ» i, Ioc (a i) (b i)) :=
by simp [measure.restrict_congr_set Ioo_ae_eq_Ioc.symm, ae_cover_Ioo_of_Ioc ha hb]
lemma ae_cover_Ioc_of_Ioo (ha : tendsto a l (π A)) (hb : tendsto b l (π B)) :
ae_cover (ΞΌ.restrict $ Ioc A B) l (Ξ» i, Ioo (a i) (b i)) :=
by simp [measure.restrict_congr_set Ioo_ae_eq_Ioc.symm, ae_cover_Ioo_of_Ioo ha hb]
lemma ae_cover_Ico_of_Icc (ha : tendsto a l (π A)) (hb : tendsto b l (π B)) :
ae_cover (ΞΌ.restrict $ Ico A B) l (Ξ» i, Icc (a i) (b i)) :=
by simp [measure.restrict_congr_set Ioo_ae_eq_Ico.symm, ae_cover_Ioo_of_Icc ha hb]
lemma ae_cover_Ico_of_Ico (ha : tendsto a l (π A)) (hb : tendsto b l (π B)) :
ae_cover (ΞΌ.restrict $ Ico A B) l (Ξ» i, Ico (a i) (b i)) :=
by simp [measure.restrict_congr_set Ioo_ae_eq_Ico.symm, ae_cover_Ioo_of_Ico ha hb]
lemma ae_cover_Ico_of_Ioc (ha : tendsto a l (π A)) (hb : tendsto b l (π B)) :
ae_cover (ΞΌ.restrict $ Ico A B) l (Ξ» i, Ioc (a i) (b i)) :=
by simp [measure.restrict_congr_set Ioo_ae_eq_Ico.symm, ae_cover_Ioo_of_Ioc ha hb]
lemma ae_cover_Ico_of_Ioo (ha : tendsto a l (π A)) (hb : tendsto b l (π B)) :
ae_cover (ΞΌ.restrict $ Ico A B) l (Ξ» i, Ioo (a i) (b i)) :=
by simp [measure.restrict_congr_set Ioo_ae_eq_Ico.symm, ae_cover_Ioo_of_Ioo ha hb]
lemma ae_cover_Icc_of_Icc (ha : tendsto a l (π A)) (hb : tendsto b l (π B)) :
ae_cover (ΞΌ.restrict $ Icc A B) l (Ξ» i, Icc (a i) (b i)) :=
by simp [measure.restrict_congr_set Ioo_ae_eq_Icc.symm, ae_cover_Ioo_of_Icc ha hb]
lemma ae_cover_Icc_of_Ico (ha : tendsto a l (π A)) (hb : tendsto b l (π B)) :
ae_cover (ΞΌ.restrict $ Icc A B) l (Ξ» i, Ico (a i) (b i)) :=
by simp [measure.restrict_congr_set Ioo_ae_eq_Icc.symm, ae_cover_Ioo_of_Ico ha hb]
lemma ae_cover_Icc_of_Ioc (ha : tendsto a l (π A)) (hb : tendsto b l (π B)) :
ae_cover (ΞΌ.restrict $ Icc A B) l (Ξ» i, Ioc (a i) (b i)) :=
by simp [measure.restrict_congr_set Ioo_ae_eq_Icc.symm, ae_cover_Ioo_of_Ioc ha hb]
lemma ae_cover_Icc_of_Ioo (ha : tendsto a l (π A)) (hb : tendsto b l (π B)) :
ae_cover (ΞΌ.restrict $ Icc A B) l (Ξ» i, Ioo (a i) (b i)) :=
by simp [measure.restrict_congr_set Ioo_ae_eq_Icc.symm, ae_cover_Ioo_of_Ioo ha hb]
end finite_intervals
lemma ae_cover.restrict {Ο : ΞΉ β set Ξ±} (hΟ : ae_cover ΞΌ l Ο) {s : set Ξ±} :
ae_cover (ΞΌ.restrict s) l Ο :=
{ ae_eventually_mem := ae_restrict_of_ae hΟ.ae_eventually_mem,
measurable := hΟ.measurable }
lemma ae_cover_restrict_of_ae_imp {s : set Ξ±} {Ο : ΞΉ β set Ξ±}
(hs : measurable_set s) (ae_eventually_mem : βα΅ x βΞΌ, x β s β βαΆ n in l, x β Ο n)
(measurable : β n, measurable_set $ Ο n) :
ae_cover (ΞΌ.restrict s) l Ο :=
{ ae_eventually_mem := by rwa ae_restrict_iff' hs,
measurable := measurable }
lemma ae_cover.inter_restrict {Ο : ΞΉ β set Ξ±} (hΟ : ae_cover ΞΌ l Ο)
{s : set Ξ±} (hs : measurable_set s) :
ae_cover (ΞΌ.restrict s) l (Ξ» i, Ο i β© s) :=
ae_cover_restrict_of_ae_imp hs
(hΟ.ae_eventually_mem.mono (Ξ» x hx hxs, hx.mono $ Ξ» i hi, β¨hi, hxsβ©))
(Ξ» i, (hΟ.measurable i).inter hs)
lemma ae_cover.ae_tendsto_indicator {Ξ² : Type*} [has_zero Ξ²] [topological_space Ξ²]
(f : Ξ± β Ξ²) {Ο : ΞΉ β set Ξ±} (hΟ : ae_cover ΞΌ l Ο) :
βα΅ x βΞΌ, tendsto (Ξ» i, (Ο i).indicator f x) l (π $ f x) :=
hΟ.ae_eventually_mem.mono (Ξ» x hx, tendsto_const_nhds.congr' $
hx.mono $ Ξ» n hn, (indicator_of_mem hn _).symm)
lemma ae_cover.ae_measurable {Ξ² : Type*} [measurable_space Ξ²] [l.is_countably_generated] [l.ne_bot]
{f : Ξ± β Ξ²} {Ο : ΞΉ β set Ξ±} (hΟ : ae_cover ΞΌ l Ο)
(hfm : β i, ae_measurable f (ΞΌ.restrict $ Ο i)) : ae_measurable f ΞΌ :=
begin
obtain β¨u, huβ© := l.exists_seq_tendsto,
have := ae_measurable_Union_iff.mpr (Ξ» (n : β), hfm (u n)),
rwa measure.restrict_eq_self_of_ae_mem at this,
filter_upwards [hΟ.ae_eventually_mem] with x hx using
let β¨i, hiβ© := (hu.eventually hx).exists in mem_Union.mpr β¨i, hiβ©
end
lemma ae_cover.ae_strongly_measurable {Ξ² : Type*} [topological_space Ξ²] [pseudo_metrizable_space Ξ²]
[l.is_countably_generated] [l.ne_bot]
{f : Ξ± β Ξ²} {Ο : ΞΉ β set Ξ±} (hΟ : ae_cover ΞΌ l Ο)
(hfm : β i, ae_strongly_measurable f (ΞΌ.restrict $ Ο i)) : ae_strongly_measurable f ΞΌ :=
begin
obtain β¨u, huβ© := l.exists_seq_tendsto,
have := ae_strongly_measurable_Union_iff.mpr (Ξ» (n : β), hfm (u n)),
rwa measure.restrict_eq_self_of_ae_mem at this,
filter_upwards [hΟ.ae_eventually_mem] with x hx using
let β¨i, hiβ© := (hu.eventually hx).exists in mem_Union.mpr β¨i, hiβ©
end
end ae_cover
lemma ae_cover.comp_tendsto {Ξ± ΞΉ ΞΉ' : Type*} [measurable_space Ξ±] {ΞΌ : measure Ξ±} {l : filter ΞΉ}
{l' : filter ΞΉ'} {Ο : ΞΉ β set Ξ±} (hΟ : ae_cover ΞΌ l Ο)
{u : ΞΉ' β ΞΉ} (hu : tendsto u l' l) :
ae_cover ΞΌ l' (Ο β u) :=
{ ae_eventually_mem := hΟ.ae_eventually_mem.mono (Ξ» x hx, hu.eventually hx),
measurable := Ξ» i, hΟ.measurable (u i) }
section ae_cover_Union_Inter_countable
variables {Ξ± ΞΉ : Type*} [countable ΞΉ]
[measurable_space Ξ±] {ΞΌ : measure Ξ±}
lemma ae_cover.bUnion_Iic_ae_cover [preorder ΞΉ] {Ο : ΞΉ β set Ξ±} (hΟ : ae_cover ΞΌ at_top Ο) :
ae_cover ΞΌ at_top (Ξ» (n : ΞΉ), β k (h : k β Iic n), Ο k) :=
{ ae_eventually_mem := hΟ.ae_eventually_mem.mono
(Ξ» x h, h.mono (Ξ» i hi, mem_bUnion right_mem_Iic hi)),
measurable := Ξ» i, measurable_set.bUnion (to_countable _) (Ξ» n _, hΟ.measurable n) }
lemma ae_cover.bInter_Ici_ae_cover [semilattice_sup ΞΉ] [nonempty ΞΉ] {Ο : ΞΉ β set Ξ±}
(hΟ : ae_cover ΞΌ at_top Ο) : ae_cover ΞΌ at_top (Ξ» (n : ΞΉ), β k (h : k β Ici n), Ο k) :=
{ ae_eventually_mem := hΟ.ae_eventually_mem.mono
begin
intros x h,
rw eventually_at_top at *,
rcases h with β¨i, hiβ©,
use i,
intros j hj,
exact mem_bInter (Ξ» k hk, hi k (le_trans hj hk)),
end,
measurable := Ξ» i, measurable_set.bInter (to_countable _) (Ξ» n _, hΟ.measurable n) }
end ae_cover_Union_Inter_countable
section lintegral
variables {Ξ± ΞΉ : Type*} [measurable_space Ξ±] {ΞΌ : measure Ξ±} {l : filter ΞΉ}
private lemma lintegral_tendsto_of_monotone_of_nat {Ο : β β set Ξ±}
(hΟ : ae_cover ΞΌ at_top Ο) (hmono : monotone Ο) {f : Ξ± β ββ₯0β} (hfm : ae_measurable f ΞΌ) :
tendsto (Ξ» i, β«β» x in Ο i, f x βΞΌ) at_top (π $ β«β» x, f x βΞΌ) :=
let F := Ξ» n, (Ο n).indicator f in
have keyβ : β n, ae_measurable (F n) ΞΌ, from Ξ» n, hfm.indicator (hΟ.measurable n),
have keyβ : βα΅ (x : Ξ±) βΞΌ, monotone (Ξ» n, F n x), from ae_of_all _
(Ξ» x i j hij, indicator_le_indicator_of_subset (hmono hij) (Ξ» x, zero_le $ f x) x),
have keyβ : βα΅ (x : Ξ±) βΞΌ, tendsto (Ξ» n, F n x) at_top (π (f x)), from hΟ.ae_tendsto_indicator f,
(lintegral_tendsto_of_tendsto_of_monotone keyβ keyβ keyβ).congr
(Ξ» n, lintegral_indicator f (hΟ.measurable n))
lemma ae_cover.lintegral_tendsto_of_nat {Ο : β β set Ξ±} (hΟ : ae_cover ΞΌ at_top Ο)
{f : Ξ± β ββ₯0β} (hfm : ae_measurable f ΞΌ) :
tendsto (Ξ» i, β«β» x in Ο i, f x βΞΌ) at_top (π $ β«β» x, f x βΞΌ) :=
begin
have limβ := lintegral_tendsto_of_monotone_of_nat (hΟ.bInter_Ici_ae_cover)
(Ξ» i j hij, bInter_subset_bInter_left (Ici_subset_Ici.mpr hij)) hfm,
have limβ := lintegral_tendsto_of_monotone_of_nat (hΟ.bUnion_Iic_ae_cover)
(Ξ» i j hij, bUnion_subset_bUnion_left (Iic_subset_Iic.mpr hij)) hfm,
have leβ := Ξ» n, lintegral_mono_set (bInter_subset_of_mem left_mem_Ici),
have leβ := Ξ» n, lintegral_mono_set (subset_bUnion_of_mem right_mem_Iic),
exact tendsto_of_tendsto_of_tendsto_of_le_of_le limβ limβ leβ leβ
end
lemma ae_cover.lintegral_tendsto_of_countably_generated [l.is_countably_generated]
{Ο : ΞΉ β set Ξ±} (hΟ : ae_cover ΞΌ l Ο) {f : Ξ± β ββ₯0β}
(hfm : ae_measurable f ΞΌ) : tendsto (Ξ» i, β«β» x in Ο i, f x βΞΌ) l (π $ β«β» x, f x βΞΌ) :=
tendsto_of_seq_tendsto (Ξ» u hu, (hΟ.comp_tendsto hu).lintegral_tendsto_of_nat hfm)
lemma ae_cover.lintegral_eq_of_tendsto [l.ne_bot] [l.is_countably_generated]
{Ο : ΞΉ β set Ξ±} (hΟ : ae_cover ΞΌ l Ο) {f : Ξ± β ββ₯0β} (I : ββ₯0β)
(hfm : ae_measurable f ΞΌ) (htendsto : tendsto (Ξ» i, β«β» x in Ο i, f x βΞΌ) l (π I)) :
β«β» x, f x βΞΌ = I :=
tendsto_nhds_unique (hΟ.lintegral_tendsto_of_countably_generated hfm) htendsto
lemma ae_cover.supr_lintegral_eq_of_countably_generated [nonempty ΞΉ] [l.ne_bot]
[l.is_countably_generated] {Ο : ΞΉ β set Ξ±} (hΟ : ae_cover ΞΌ l Ο) {f : Ξ± β ββ₯0β}
(hfm : ae_measurable f ΞΌ) : (β¨ (i : ΞΉ), β«β» x in Ο i, f x βΞΌ) = β«β» x, f x βΞΌ :=
begin
have := hΟ.lintegral_tendsto_of_countably_generated hfm,
refine csupr_eq_of_forall_le_of_forall_lt_exists_gt
(Ξ» i, lintegral_mono' measure.restrict_le_self le_rfl) (Ξ» w hw, _),
rcases exists_between hw with β¨m, hmβ, hmββ©,
rcases (eventually_ge_of_tendsto_gt hmβ this).exists with β¨i, hiβ©,
exact β¨i, lt_of_lt_of_le hmβ hiβ©,
end
end lintegral
section integrable
variables {Ξ± ΞΉ E : Type*} [measurable_space Ξ±] {ΞΌ : measure Ξ±} {l : filter ΞΉ}
[normed_add_comm_group E]
lemma ae_cover.integrable_of_lintegral_nnnorm_bounded [l.ne_bot] [l.is_countably_generated]
{Ο : ΞΉ β set Ξ±} (hΟ : ae_cover ΞΌ l Ο) {f : Ξ± β E} (I : β) (hfm : ae_strongly_measurable f ΞΌ)
(hbounded : βαΆ i in l, β«β» x in Ο i, βf xββ βΞΌ β€ ennreal.of_real I) :
integrable f ΞΌ :=
begin
refine β¨hfm, (le_of_tendsto _ hbounded).trans_lt ennreal.of_real_lt_topβ©,
exact hΟ.lintegral_tendsto_of_countably_generated hfm.ennnorm
end
lemma ae_cover.integrable_of_lintegral_nnnorm_tendsto [l.ne_bot] [l.is_countably_generated]
{Ο : ΞΉ β set Ξ±} (hΟ : ae_cover ΞΌ l Ο) {f : Ξ± β E} (I : β)
(hfm : ae_strongly_measurable f ΞΌ)
(htendsto : tendsto (Ξ» i, β«β» x in Ο i, βf xββ βΞΌ) l (π $ ennreal.of_real I)) :
integrable f ΞΌ :=
begin
refine hΟ.integrable_of_lintegral_nnnorm_bounded (max 1 (I + 1)) hfm _,
refine htendsto.eventually (ge_mem_nhds _),
refine (ennreal.of_real_lt_of_real_iff (lt_max_of_lt_left zero_lt_one)).2 _,
exact lt_max_of_lt_right (lt_add_one I),
end
lemma ae_cover.integrable_of_lintegral_nnnorm_bounded' [l.ne_bot] [l.is_countably_generated]
{Ο : ΞΉ β set Ξ±} (hΟ : ae_cover ΞΌ l Ο) {f : Ξ± β E} (I : ββ₯0) (hfm : ae_strongly_measurable f ΞΌ)
(hbounded : βαΆ i in l, β«β» x in Ο i, βf xββ βΞΌ β€ I) :
integrable f ΞΌ :=
hΟ.integrable_of_lintegral_nnnorm_bounded I hfm
(by simpa only [ennreal.of_real_coe_nnreal] using hbounded)
lemma ae_cover.integrable_of_lintegral_nnnorm_tendsto' [l.ne_bot] [l.is_countably_generated]
{Ο : ΞΉ β set Ξ±} (hΟ : ae_cover ΞΌ l Ο) {f : Ξ± β E} (I : ββ₯0)
(hfm : ae_strongly_measurable f ΞΌ)
(htendsto : tendsto (Ξ» i, β«β» x in Ο i, βf xββ βΞΌ) l (π I)) :
integrable f ΞΌ :=
hΟ.integrable_of_lintegral_nnnorm_tendsto I hfm
(by simpa only [ennreal.of_real_coe_nnreal] using htendsto)
lemma ae_cover.integrable_of_integral_norm_bounded [l.ne_bot] [l.is_countably_generated]
{Ο : ΞΉ β set Ξ±} (hΟ : ae_cover ΞΌ l Ο) {f : Ξ± β E}
(I : β) (hfi : β i, integrable_on f (Ο i) ΞΌ)
(hbounded : βαΆ i in l, β« x in Ο i, βf xβ βΞΌ β€ I) :
integrable f ΞΌ :=
begin
have hfm : ae_strongly_measurable f ΞΌ :=
hΟ.ae_strongly_measurable (Ξ» i, (hfi i).ae_strongly_measurable),
refine hΟ.integrable_of_lintegral_nnnorm_bounded I hfm _,
conv at hbounded in (integral _ _)
{ rw integral_eq_lintegral_of_nonneg_ae (ae_of_all _ (Ξ» x, @norm_nonneg E _ (f x)))
hfm.norm.restrict },
conv at hbounded in (ennreal.of_real _) { dsimp, rw β coe_nnnorm, rw ennreal.of_real_coe_nnreal },
refine hbounded.mono (Ξ» i hi, _),
rw βennreal.of_real_to_real (ne_top_of_lt (hfi i).2),
apply ennreal.of_real_le_of_real hi,
end
lemma ae_cover.integrable_of_integral_norm_tendsto [l.ne_bot] [l.is_countably_generated]
{Ο : ΞΉ β set Ξ±} (hΟ : ae_cover ΞΌ l Ο) {f : Ξ± β E}
(I : β) (hfi : β i, integrable_on f (Ο i) ΞΌ)
(htendsto : tendsto (Ξ» i, β« x in Ο i, βf xβ βΞΌ) l (π I)) :
integrable f ΞΌ :=
let β¨I', hI'β© := htendsto.is_bounded_under_le in hΟ.integrable_of_integral_norm_bounded I' hfi hI'
lemma ae_cover.integrable_of_integral_bounded_of_nonneg_ae [l.ne_bot] [l.is_countably_generated]
{Ο : ΞΉ β set Ξ±} (hΟ : ae_cover ΞΌ l Ο) {f : Ξ± β β} (I : β)
(hfi : β i, integrable_on f (Ο i) ΞΌ) (hnng : βα΅ x βΞΌ, 0 β€ f x)
(hbounded : βαΆ i in l, β« x in Ο i, f x βΞΌ β€ I) :
integrable f ΞΌ :=
hΟ.integrable_of_integral_norm_bounded I hfi $ hbounded.mono $ Ξ» i hi,
(integral_congr_ae $ ae_restrict_of_ae $ hnng.mono $ Ξ» x, real.norm_of_nonneg).le.trans hi
lemma ae_cover.integrable_of_integral_tendsto_of_nonneg_ae [l.ne_bot] [l.is_countably_generated]
{Ο : ΞΉ β set Ξ±} (hΟ : ae_cover ΞΌ l Ο) {f : Ξ± β β} (I : β)
(hfi : β i, integrable_on f (Ο i) ΞΌ) (hnng : βα΅ x βΞΌ, 0 β€ f x)
(htendsto : tendsto (Ξ» i, β« x in Ο i, f x βΞΌ) l (π I)) :
integrable f ΞΌ :=
let β¨I', hI'β© := htendsto.is_bounded_under_le in
hΟ.integrable_of_integral_bounded_of_nonneg_ae I' hfi hnng hI'
end integrable
section integral
variables {Ξ± ΞΉ E : Type*} [measurable_space Ξ±] {ΞΌ : measure Ξ±} {l : filter ΞΉ}
[normed_add_comm_group E] [normed_space β E] [complete_space E]
lemma ae_cover.integral_tendsto_of_countably_generated [l.is_countably_generated]
{Ο : ΞΉ β set Ξ±} (hΟ : ae_cover ΞΌ l Ο) {f : Ξ± β E} (hfi : integrable f ΞΌ) :
tendsto (Ξ» i, β« x in Ο i, f x βΞΌ) l (π $ β« x, f x βΞΌ) :=
suffices h : tendsto (Ξ» i, β« (x : Ξ±), (Ο i).indicator f x βΞΌ) l (π (β« (x : Ξ±), f x βΞΌ)),
by { convert h, ext n, rw integral_indicator (hΟ.measurable n) },
tendsto_integral_filter_of_dominated_convergence (Ξ» x, βf xβ)
(eventually_of_forall $ Ξ» i, hfi.ae_strongly_measurable.indicator $ hΟ.measurable i)
(eventually_of_forall $ Ξ» i, ae_of_all _ $ Ξ» x, norm_indicator_le_norm_self _ _)
hfi.norm (hΟ.ae_tendsto_indicator f)
/-- Slight reformulation of
`measure_theory.ae_cover.integral_tendsto_of_countably_generated`. -/
lemma ae_cover.integral_eq_of_tendsto [l.ne_bot] [l.is_countably_generated]
{Ο : ΞΉ β set Ξ±} (hΟ : ae_cover ΞΌ l Ο) {f : Ξ± β E}
(I : E) (hfi : integrable f ΞΌ)
(h : tendsto (Ξ» n, β« x in Ο n, f x βΞΌ) l (π I)) :
β« x, f x βΞΌ = I :=
tendsto_nhds_unique (hΟ.integral_tendsto_of_countably_generated hfi) h
lemma ae_cover.integral_eq_of_tendsto_of_nonneg_ae [l.ne_bot] [l.is_countably_generated]
{Ο : ΞΉ β set Ξ±} (hΟ : ae_cover ΞΌ l Ο) {f : Ξ± β β} (I : β)
(hnng : 0 β€α΅[ΞΌ] f) (hfi : β n, integrable_on f (Ο n) ΞΌ)
(htendsto : tendsto (Ξ» n, β« x in Ο n, f x βΞΌ) l (π I)) :
β« x, f x βΞΌ = I :=
have hfi' : integrable f ΞΌ,
from hΟ.integrable_of_integral_tendsto_of_nonneg_ae I hfi hnng htendsto,
hΟ.integral_eq_of_tendsto I hfi' htendsto
end integral
section integrable_of_interval_integral
variables {ΞΉ E : Type*} {ΞΌ : measure β}
{l : filter ΞΉ} [filter.ne_bot l] [is_countably_generated l]
[normed_add_comm_group E]
{a b : ΞΉ β β} {f : β β E}
lemma integrable_of_interval_integral_norm_bounded
(I : β) (hfi : β i, integrable_on f (Ioc (a i) (b i)) ΞΌ)
(ha : tendsto a l at_bot) (hb : tendsto b l at_top)
(h : βαΆ i in l, β« x in a i .. b i, βf xβ βΞΌ β€ I) :
integrable f ΞΌ :=
begin
have hΟ : ae_cover ΞΌ l _ := ae_cover_Ioc ha hb,
refine hΟ.integrable_of_integral_norm_bounded I hfi (h.mp _),
filter_upwards [ha.eventually (eventually_le_at_bot 0), hb.eventually (eventually_ge_at_top 0)]
with i hai hbi ht,
rwa βinterval_integral.integral_of_le (hai.trans hbi)
end
/-- If `f` is integrable on intervals `Ioc (a i) (b i)`,
where `a i` tends to -β and `b i` tends to β, and
`β« x in a i .. b i, βf xβ βΞΌ` converges to `I : β` along a filter `l`,
then `f` is integrable on the interval (-β, β) -/
lemma integrable_of_interval_integral_norm_tendsto
(I : β) (hfi : β i, integrable_on f (Ioc (a i) (b i)) ΞΌ)
(ha : tendsto a l at_bot) (hb : tendsto b l at_top)
(h : tendsto (Ξ» i, β« x in a i .. b i, βf xβ βΞΌ) l (π I)) :
integrable f ΞΌ :=
let β¨I', hI'β© := h.is_bounded_under_le in
integrable_of_interval_integral_norm_bounded I' hfi ha hb hI'
lemma integrable_on_Iic_of_interval_integral_norm_bounded (I b : β)
(hfi : β i, integrable_on f (Ioc (a i) b) ΞΌ) (ha : tendsto a l at_bot)
(h : βαΆ i in l, (β« x in a i .. b, βf xβ βΞΌ) β€ I) :
integrable_on f (Iic b) ΞΌ :=
begin
have hΟ : ae_cover (ΞΌ.restrict $ Iic b) l _ := ae_cover_Ioi ha,
have hfi : β i, integrable_on f (Ioi (a i)) (ΞΌ.restrict $ Iic b),
{ intro i,
rw [integrable_on, measure.restrict_restrict (hΟ.measurable i)],
exact hfi i },
refine hΟ.integrable_of_integral_norm_bounded I hfi (h.mp _),
filter_upwards [ha.eventually (eventually_le_at_bot b)] with i hai,
rw [interval_integral.integral_of_le hai, measure.restrict_restrict (hΟ.measurable i)],
exact id
end
/-- If `f` is integrable on intervals `Ioc (a i) b`,
where `a i` tends to -β, and
`β« x in a i .. b, βf xβ βΞΌ` converges to `I : β` along a filter `l`,
then `f` is integrable on the interval (-β, b) -/
lemma integrable_on_Iic_of_interval_integral_norm_tendsto (I b : β)
(hfi : β i, integrable_on f (Ioc (a i) b) ΞΌ) (ha : tendsto a l at_bot)
(h : tendsto (Ξ» i, β« x in a i .. b, βf xβ βΞΌ) l (π I)) :
integrable_on f (Iic b) ΞΌ :=
let β¨I', hI'β© := h.is_bounded_under_le in
integrable_on_Iic_of_interval_integral_norm_bounded I' b hfi ha hI'
lemma integrable_on_Ioi_of_interval_integral_norm_bounded (I a : β)
(hfi : β i, integrable_on f (Ioc a (b i)) ΞΌ) (hb : tendsto b l at_top)
(h : βαΆ i in l, (β« x in a .. b i, βf xβ βΞΌ) β€ I) :
integrable_on f (Ioi a) ΞΌ :=
begin
have hΟ : ae_cover (ΞΌ.restrict $ Ioi a) l _ := ae_cover_Iic hb,
have hfi : β i, integrable_on f (Iic (b i)) (ΞΌ.restrict $ Ioi a),
{ intro i,
rw [integrable_on, measure.restrict_restrict (hΟ.measurable i), inter_comm],
exact hfi i },
refine hΟ.integrable_of_integral_norm_bounded I hfi (h.mp _),
filter_upwards [hb.eventually (eventually_ge_at_top a)] with i hbi,
rw [interval_integral.integral_of_le hbi, measure.restrict_restrict (hΟ.measurable i),
inter_comm],
exact id
end
/-- If `f` is integrable on intervals `Ioc a (b i)`,
where `b i` tends to β, and
`β« x in a .. b i, βf xβ βΞΌ` converges to `I : β` along a filter `l`,
then `f` is integrable on the interval (a, β) -/
lemma integrable_on_Ioi_of_interval_integral_norm_tendsto (I a : β)
(hfi : β i, integrable_on f (Ioc a (b i)) ΞΌ) (hb : tendsto b l at_top)
(h : tendsto (Ξ» i, β« x in a .. b i, βf xβ βΞΌ) l (π $ I)) :
integrable_on f (Ioi a) ΞΌ :=
let β¨I', hI'β© := h.is_bounded_under_le in
integrable_on_Ioi_of_interval_integral_norm_bounded I' a hfi hb hI'
lemma integrable_on_Ioc_of_interval_integral_norm_bounded {I aβ bβ : β}
(hfi : β i, integrable_on f $ Ioc (a i) (b i))
(ha : tendsto a l $ π aβ) (hb : tendsto b l $ π bβ)
(h : βαΆ i in l, (β« x in Ioc (a i) (b i), βf xβ) β€ I) : integrable_on f (Ioc aβ bβ) :=
begin
refine (ae_cover_Ioc_of_Ioc ha hb).integrable_of_integral_norm_bounded I
(Ξ» i, (hfi i).restrict measurable_set_Ioc) (eventually.mono h _),
intros i hi, simp only [measure.restrict_restrict measurable_set_Ioc],
refine le_trans (set_integral_mono_set (hfi i).norm _ _) hi,
{ apply ae_of_all, simp only [pi.zero_apply, norm_nonneg, forall_const] },
{ apply ae_of_all, intros c hc, exact hc.1 },
end
lemma integrable_on_Ioc_of_interval_integral_norm_bounded_left {I aβ b : β}
(hfi : β i, integrable_on f $ Ioc (a i) b) (ha : tendsto a l $ π aβ)
(h : βαΆ i in l, (β« x in Ioc (a i) b, βf xβ ) β€ I) : integrable_on f (Ioc aβ b) :=
integrable_on_Ioc_of_interval_integral_norm_bounded hfi ha tendsto_const_nhds h
lemma integrable_on_Ioc_of_interval_integral_norm_bounded_right {I a bβ : β}
(hfi : β i, integrable_on f $ Ioc a (b i)) (hb : tendsto b l $ π bβ)
(h : βαΆ i in l, (β« x in Ioc a (b i), βf xβ ) β€ I) : integrable_on f (Ioc a bβ) :=
integrable_on_Ioc_of_interval_integral_norm_bounded hfi tendsto_const_nhds hb h
end integrable_of_interval_integral
section integral_of_interval_integral
variables {ΞΉ E : Type*} {ΞΌ : measure β}
{l : filter ΞΉ} [is_countably_generated l]
[normed_add_comm_group E] [normed_space β E] [complete_space E]
{a b : ΞΉ β β} {f : β β E}
lemma interval_integral_tendsto_integral
(hfi : integrable f ΞΌ) (ha : tendsto a l at_bot) (hb : tendsto b l at_top) :
tendsto (Ξ» i, β« x in a i .. b i, f x βΞΌ) l (π $ β« x, f x βΞΌ) :=
begin
let Ο := Ξ» i, Ioc (a i) (b i),
have hΟ : ae_cover ΞΌ l Ο := ae_cover_Ioc ha hb,
refine (hΟ.integral_tendsto_of_countably_generated hfi).congr' _,
filter_upwards [ha.eventually (eventually_le_at_bot 0), hb.eventually (eventually_ge_at_top 0)]
with i hai hbi,
exact (interval_integral.integral_of_le (hai.trans hbi)).symm
end
lemma interval_integral_tendsto_integral_Iic (b : β)
(hfi : integrable_on f (Iic b) ΞΌ) (ha : tendsto a l at_bot) :
tendsto (Ξ» i, β« x in a i .. b, f x βΞΌ) l (π $ β« x in Iic b, f x βΞΌ) :=
begin
let Ο := Ξ» i, Ioi (a i),
have hΟ : ae_cover (ΞΌ.restrict $ Iic b) l Ο := ae_cover_Ioi ha,
refine (hΟ.integral_tendsto_of_countably_generated hfi).congr' _,
filter_upwards [ha.eventually (eventually_le_at_bot $ b)] with i hai,
rw [interval_integral.integral_of_le hai, measure.restrict_restrict (hΟ.measurable i)],
refl,
end
lemma interval_integral_tendsto_integral_Ioi (a : β)
(hfi : integrable_on f (Ioi a) ΞΌ) (hb : tendsto b l at_top) :
tendsto (Ξ» i, β« x in a .. b i, f x βΞΌ) l (π $ β« x in Ioi a, f x βΞΌ) :=
begin
let Ο := Ξ» i, Iic (b i),
have hΟ : ae_cover (ΞΌ.restrict $ Ioi a) l Ο := ae_cover_Iic hb,
refine (hΟ.integral_tendsto_of_countably_generated hfi).congr' _,
filter_upwards [hb.eventually (eventually_ge_at_top $ a)] with i hbi,
rw [interval_integral.integral_of_le hbi, measure.restrict_restrict (hΟ.measurable i),
inter_comm],
refl,
end
end integral_of_interval_integral
section Ioi_change_variables
open real
open_locale interval
variables {E : Type*} {ΞΌ : measure β} {f : β β E}
[normed_add_comm_group E] [normed_space β E] [complete_space E]
/-- Change-of-variables formula for `Ioi` integrals of vector-valued functions, proved by taking
limits from the result for finite intervals. -/
lemma integral_comp_smul_deriv_Ioi {f f' : β β β} {g : β β E} {a : β}
(hf : continuous_on f $ Ici a)
(hft : tendsto f at_top at_top)
(hff' : β x β Ioi a, has_deriv_within_at f (f' x) (Ioi x) x)
(hg_cont : continuous_on g $ f '' Ioi a)
(hg1 : integrable_on g $ f '' Ici a)
(hg2 : integrable_on (Ξ» x, f' x β’ (g β f) x) (Ici a)) :
β« x in Ioi a, f' x β’ (g β f) x = β« u in Ioi (f a), g u :=
begin
have eq : β b : β, a < b β β« x in a..b, f' x β’ (g β f) x = β« u in f a .. f b, g u,
{ intros b hb,
have i1 : Ioo (min a b) (max a b) β Ioi a,
{ rw min_eq_left hb.le, exact Ioo_subset_Ioi_self },
have i2 : [a, b] β Ici a,
{ rw interval_of_le hb.le, exact Icc_subset_Ici_self },
refine interval_integral.integral_comp_smul_deriv''' (hf.mono i2)
(Ξ» x hx, hff' x $ mem_of_mem_of_subset hx i1) (hg_cont.mono $ image_subset _ _)
(hg1.mono_set $ image_subset _ _) (hg2.mono_set i2),
{ rw min_eq_left hb.le, exact Ioo_subset_Ioi_self },
{ rw interval_of_le hb.le, exact Icc_subset_Ici_self } },
rw integrable_on_Ici_iff_integrable_on_Ioi at hg2,
have t2 := interval_integral_tendsto_integral_Ioi _ hg2 tendsto_id,
have : Ioi (f a) β f '' Ici a := (Ioi_subset_Ici_self.trans $
is_preconnected.intermediate_value_Ici is_preconnected_Ici left_mem_Ici
(le_principal_iff.mpr $ Ici_mem_at_top _) hf hft),
have t1 := (interval_integral_tendsto_integral_Ioi _ (hg1.mono_set this) tendsto_id).comp hft,
exact tendsto_nhds_unique (tendsto.congr' (eventually_eq_of_mem (Ioi_mem_at_top a) eq) t2) t1,
end
/-- Change-of-variables formula for `Ioi` integrals of scalar-valued functions -/
lemma integral_comp_mul_deriv_Ioi {f f' : β β β} {g : β β β} {a : β}
(hf : continuous_on f $ Ici a)
(hft : tendsto f at_top at_top)
(hff' : β x β Ioi a, has_deriv_within_at f (f' x) (Ioi x) x)
(hg_cont : continuous_on g $ f '' Ioi a)
(hg1 : integrable_on g $ f '' Ici a)
(hg2 : integrable_on (Ξ» x, (g β f) x * f' x) (Ici a)) :
β« x in Ioi a, (g β f) x * f' x = β« u in Ioi (f a), g u :=
begin
have hg2' : integrable_on (Ξ» x, f' x β’ (g β f) x) (Ici a) := by simpa [mul_comm] using hg2,
simpa [mul_comm] using integral_comp_smul_deriv_Ioi hf hft hff' hg_cont hg1 hg2',
end
/-- Substitution `y = x ^ p` in integrals over `Ioi 0` -/
lemma integral_comp_rpow_Ioi (g : β β E) {p : β} (hp : p β 0) :
β« x in Ioi 0, (|p| * x ^ (p - 1)) β’ g (x ^ p) = β« y in Ioi 0, g y :=
begin
let S := Ioi (0 : β),
have a1 : β x:β, x β S β has_deriv_within_at (Ξ» (t:β), t ^ p) (p * x ^ (p - 1)) S x :=
Ξ» x hx, (has_deriv_at_rpow_const (or.inl (mem_Ioi.mp hx).ne')).has_deriv_within_at,
have a2 : inj_on (Ξ» x:β, x ^ p) S,
{ rcases lt_or_gt_of_ne hp,
{ apply strict_anti_on.inj_on,
intros x hx y hy hxy,
rw [βinv_lt_inv (rpow_pos_of_pos hx p) (rpow_pos_of_pos hy p),
βrpow_neg (le_of_lt hx), βrpow_neg (le_of_lt hy)],
exact rpow_lt_rpow (le_of_lt hx) hxy (neg_pos.mpr h), },
exact strict_mono_on.inj_on (Ξ» x hx y hy hxy, rpow_lt_rpow (mem_Ioi.mp hx).le hxy h),},
have a3 : (Ξ» (t : β), t ^ p) '' S = S,
{ ext1, rw mem_image, split,
{ rintro β¨y, hy, rflβ©, exact rpow_pos_of_pos hy p },
{ intro hx, refine β¨x ^ (1 / p), rpow_pos_of_pos hx _, _β©,
rw [βrpow_mul (le_of_lt hx), one_div_mul_cancel hp, rpow_one], } },
have := integral_image_eq_integral_abs_deriv_smul measurable_set_Ioi a1 a2 g,
rw a3 at this, rw this,
refine set_integral_congr measurable_set_Ioi _,
intros x hx, dsimp only,
rw [abs_mul, abs_of_nonneg (rpow_nonneg_of_nonneg (le_of_lt hx) _)],
end
lemma integral_comp_rpow_Ioi_of_pos {g : β β E} {p : β} (hp : 0 < p) :
β« x in Ioi 0, (p * x ^ (p - 1)) β’ g (x ^ p) = β« y in Ioi 0, g y :=
begin
convert integral_comp_rpow_Ioi g hp.ne',
funext, congr, rw abs_of_nonneg hp.le,
end
end Ioi_change_variables
end measure_theory
|
e2033a2f495a6518420cec66ee05dfa198a8d1fb
|
a4673261e60b025e2c8c825dfa4ab9108246c32e
|
/stage0/src/Lean/CoreM.lean
|
d9d92813f8bb48dc337d69415f246aca4c6ab45d
|
[
"Apache-2.0"
] |
permissive
|
jcommelin/lean4
|
c02dec0cc32c4bccab009285475f265f17d73228
|
2909313475588cc20ac0436e55548a4502050d0a
|
refs/heads/master
| 1,674,129,550,893
| 1,606,415,348,000
| 1,606,415,348,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 4,511
|
lean
|
/-
Copyright (c) 2020 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
import Lean.Util.RecDepth
import Lean.Util.Trace
import Lean.Environment
import Lean.Exception
import Lean.InternalExceptionId
import Lean.Eval
import Lean.MonadEnv
import Lean.ResolveName
namespace Lean
namespace Core
structure State :=
(env : Environment)
(nextMacroScope : MacroScope := firstFrontendMacroScope + 1)
(ngen : NameGenerator := {})
(traceState : TraceState := {})
instance : Inhabited State := β¨{ env := arbitrary }β©
structure Context :=
(options : Options := {})
(currRecDepth : Nat := 0)
(maxRecDepth : Nat := 1000)
(ref : Syntax := Syntax.missing)
(currNamespace : Name := Name.anonymous)
(openDecls : List OpenDecl := [])
abbrev CoreM := ReaderT Context $ StateRefT State (EIO Exception)
instance : Inhabited (CoreM Ξ±) := β¨fun _ _ => throw arbitraryβ©
instance : MonadRef CoreM := {
getRef := do let ctx β read; pure ctx.ref,
withRef := fun ref x => withReader (fun ctx => { ctx with ref := ref }) x
}
instance : MonadEnv CoreM := {
getEnv := do pure (β get).env,
modifyEnv := fun f => modify fun s => { s with env := f s.env }
}
instance : MonadOptions CoreM := {
getOptions := do pure (β read).options
}
instance : AddMessageContext CoreM := {
addMessageContext := addMessageContextPartial
}
instance : MonadNameGenerator CoreM := {
getNGen := do pure (β get).ngen,
setNGen := fun ngen => modify fun s => { s with ngen := ngen } }
instance : MonadRecDepth CoreM := {
withRecDepth := fun d x => withReader (fun ctx => { ctx with currRecDepth := d }) x,
getRecDepth := do pure (β read).currRecDepth,
getMaxRecDepth := do pure (β read).maxRecDepth
}
instance : MonadResolveName CoreM := {
getCurrNamespace := do pure (β read).currNamespace,
getOpenDecls := do pure (β read).openDecls
}
@[inline] def liftIOCore (x : IO Ξ±) : CoreM Ξ± := do
let ref β getRef
IO.toEIO (fun (err : IO.Error) => Exception.error ref (toString err)) x
instance : MonadLift IO CoreM := {
monadLift := liftIOCore
}
instance : MonadTrace CoreM := {
getTraceState := do pure (β get).traceState,
modifyTraceState := fun f => modify fun s => { s with traceState := f s.traceState }
}
private def mkFreshNameImp (n : Name) : CoreM Name := do
let fresh β modifyGet fun s => (s.nextMacroScope, { s with nextMacroScope := s.nextMacroScope + 1 })
let env β getEnv
pure $ addMacroScope env.mainModule n fresh
def mkFreshUserName [MonadLiftT CoreM m] (n : Name) : m Name :=
liftM $ mkFreshNameImp n
@[inline] def CoreM.run (x : CoreM Ξ±) (ctx : Context) (s : State) : EIO Exception (Ξ± Γ State) :=
(x ctx).run s
@[inline] def CoreM.run' (x : CoreM Ξ±) (ctx : Context) (s : State) : EIO Exception Ξ± :=
Prod.fst <$> x.run ctx s
@[inline] def CoreM.toIO (x : CoreM Ξ±) (ctx : Context) (s : State) : IO (Ξ± Γ State) := do
match (β (x.run ctx s).toIO') with
| Except.error (Exception.error _ msg) => do let e β msg.toString; throw $ IO.userError e
| Except.error (Exception.internal id _) => throw $ IO.userError $ "internal exception #" ++ toString id.idx
| Except.ok a => pure a
instance [MetaEval Ξ±] : MetaEval (CoreM Ξ±) := {
eval := fun env opts x _ => do
let x : CoreM Ξ± := do try x finally printTraces
let (a, s) β x.toIO { maxRecDepth := getMaxRecDepth opts, options := opts } { env := env }
MetaEval.eval s.env opts a (hideUnit := true)
}
-- withIncRecDepth for a monad `m` such that `[MonadControlT CoreM n]`
protected def withIncRecDepth [Monad m] [MonadControlT CoreM m] (x : m Ξ±) : m Ξ± :=
controlAt CoreM fun runInBase => withIncRecDepth (runInBase x)
end Core
export Core (CoreM mkFreshUserName)
@[inline] def catchInternalId [Monad m] [MonadExcept Exception m] (id : InternalExceptionId) (x : m Ξ±) (h : Exception β m Ξ±) : m Ξ± := do
try
x
catch ex => match ex with
| Exception.error _ _ => throw ex
| Exception.internal id' _ => if id == id' then h ex else throw ex
@[inline] def catchInternalIds [Monad m] [MonadExcept Exception m] (ids : List InternalExceptionId) (x : m Ξ±) (h : Exception β m Ξ±) : m Ξ± := do
try
x
catch ex => match ex with
| Exception.error _ _ => throw ex
| Exception.internal id _ => if ids.contains id then h ex else throw ex
end Lean
|
53739bd0ddbadf0bb9192b1241b3bc2c1718ceb5
|
510e96af568b060ed5858226ad954c258549f143
|
/data/nat/sub.lean
|
fb7a836f37eae1da10a3c70503e606785392cc03
|
[] |
no_license
|
Shamrock-Frost/library_dev
|
cb6d1739237d81e17720118f72ba0a6db8a5906b
|
0245c71e4931d3aceeacf0aea776454f6ee03c9c
|
refs/heads/master
| 1,609,481,034,595
| 1,500,165,215,000
| 1,500,165,347,000
| 97,350,162
| 0
| 0
| null | 1,500,164,969,000
| 1,500,164,969,000
| null |
UTF-8
|
Lean
| false
| false
| 6,258
|
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, Jeremy Avigad
Subtraction on the natural numbers, as well as min, max, and distance.
-/
namespace nat
/- interaction with inequalities -/
protected theorem le_sub_add (n m : β) : n β€ n - m + m :=
or.elim (le_total n m)
(suppose n β€ m, begin rw [sub_eq_zero_of_le this, zero_add], exact this end)
(suppose m β€ n, begin rw (nat.sub_add_cancel this) end)
protected theorem sub_eq_of_eq_add {n m k : β} (h : k = n + m) : k - n = m :=
begin rw [h, nat.add_sub_cancel_left] end
protected theorem lt_of_sub_pos {m n : β} (h : n - m > 0) : m < n :=
lt_of_not_ge
(suppose m β₯ n,
have n - m = 0, from sub_eq_zero_of_le this,
begin rw this at h, exact lt_irrefl _ h end)
protected theorem lt_of_sub_lt_sub_right {n m k : β} (h : n - k < m - k) : n < m :=
lt_of_not_ge
(suppose m β€ n,
have m - k β€ n - k, from nat.sub_le_sub_right this _,
not_le_of_gt h this)
protected theorem lt_of_sub_lt_sub_left {n m k : β} (h : n - m < n - k) : k < m :=
lt_of_not_ge
(suppose m β€ k,
have n - k β€ n - m, from nat.sub_le_sub_left _ this,
not_le_of_gt h this)
protected theorem sub_lt_self {m n : β} (hβ : m > 0) (hβ : n > 0) : m - n < m :=
calc
m - n = succ (pred m) - succ (pred n) : by rw [succ_pred_eq_of_pos hβ, succ_pred_eq_of_pos hβ]
... = pred m - pred n : by rw succ_sub_succ
... β€ pred m : sub_le _ _
... < succ (pred m) : lt_succ_self _
... = m : succ_pred_eq_of_pos hβ
protected theorem le_sub_of_add_le {m n k : β} (h : m + k β€ n) : m β€ n - k :=
calc
m = m + k - k : by rw nat.add_sub_cancel
... β€ n - k : nat.sub_le_sub_right h k
protected theorem lt_sub_of_add_lt {m n k : β} (h : m + k < n) : m < n - k :=
lt_of_succ_le (nat.le_sub_of_add_le (calc
succ m + k = succ (m + k) : by rw succ_add
... β€ n : succ_le_of_lt h))
protected theorem add_lt_of_lt_sub {m n k : β} (h : m < n - k) : m + k < n :=
@nat.lt_of_sub_lt_sub_right _ _ k (by rwa nat.add_sub_cancel)
protected theorem sub_lt_of_lt_add {k n m : nat} (hβ : k < n + m) (hβ : n β€ k) : k - n < m :=
have succ k β€ n + m, from succ_le_of_lt hβ,
have succ (k - n) β€ m, from
calc succ (k - n) = succ k - n : by rw (succ_sub hβ)
... β€ n + m - n : nat.sub_le_sub_right this n
... = m : by rw nat.add_sub_cancel_left,
lt_of_succ_le this
/- distance -/
definition dist (n m : β) := (n - m) + (m - n)
theorem dist.def (n m : β) : dist n m = (n - m) + (m - n) := rfl
@[simp]
theorem dist_comm (n m : β) : dist n m = dist m n :=
by simp [dist.def]
@[simp]
theorem dist_self (n : β) : dist n n = 0 :=
by simp [dist.def, nat.sub_self]
theorem eq_of_dist_eq_zero {n m : β} (h : dist n m = 0) : n = m :=
have n - m = 0, from eq_zero_of_add_eq_zero_right h,
have n β€ m, from nat.le_of_sub_eq_zero this,
have m - n = 0, from eq_zero_of_add_eq_zero_left h,
have m β€ n, from nat.le_of_sub_eq_zero this,
le_antisymm βΉn β€ mβΊ βΉm β€ nβΊ
theorem dist_eq_zero {n m : β} (h : n = m) : dist n m = 0 :=
begin rw [h, dist_self] end
theorem dist_eq_sub_of_le {n m : β} (h : n β€ m) : dist n m = m - n :=
begin rw [dist.def, sub_eq_zero_of_le h, zero_add] end
theorem dist_eq_sub_of_ge {n m : β} (h : n β₯ m) : dist n m = n - m :=
begin rw [dist_comm], apply dist_eq_sub_of_le h end
theorem dist_zero_right (n : β) : dist n 0 = n :=
eq.trans (dist_eq_sub_of_ge (zero_le n)) (nat.sub_zero n)
theorem dist_zero_left (n : β) : dist 0 n = n :=
eq.trans (dist_eq_sub_of_le (zero_le n)) (nat.sub_zero n)
theorem dist_add_add_right (n k m : β) : dist (n + k) (m + k) = dist n m :=
calc
dist (n + k) (m + k) = ((n + k) - (m + k)) + ((m + k)-(n + k)) : rfl
... = (n - m) + ((m + k) - (n + k)) : by rw nat.add_sub_add_right
... = (n - m) + (m - n) : by rw nat.add_sub_add_right
theorem dist_add_add_left (k n m : β) : dist (k + n) (k + m) = dist n m :=
begin rw [add_comm k n, add_comm k m], apply dist_add_add_right end
theorem dist_eq_intro {n m k l : β} (h : n + m = k + l) : dist n k = dist l m :=
calc
dist n k = dist (n + m) (k + m) : by rw dist_add_add_right
... = dist (k + l) (k + m) : by rw h
... = dist l m : by rw dist_add_add_left
protected theorem sub_lt_sub_add_sub (n m k : β) : n - k β€ (n - m) + (m - k) :=
or.elim (le_total k m)
(suppose k β€ m,
begin rw βnat.add_sub_assoc this, apply nat.sub_le_sub_right, apply nat.le_sub_add end)
(suppose k β₯ m,
begin rw [sub_eq_zero_of_le this, add_zero], apply nat.sub_le_sub_left, exact this end)
theorem dist.triangle_inequality (n m k : β) : dist n k β€ dist n m + dist m k :=
have dist n m + dist m k = (n - m) + (m - k) + ((k - m) + (m - n)), by simp [dist.def],
begin
rw [this, dist.def], apply add_le_add, repeat { apply nat.sub_lt_sub_add_sub }
end
theorem dist_mul_right (n k m : β) : dist (n * k) (m * k) = dist n m * k :=
by rw [dist.def, dist.def, right_distrib, nat.mul_sub_right_distrib, nat.mul_sub_right_distrib]
theorem dist_mul_left (k n m : β) : dist (k * n) (k * m) = k * dist n m :=
by rw [mul_comm k n, mul_comm k m, dist_mul_right, mul_comm]
-- TODO(Jeremy): do when we have max and minx
--lemma dist_eq_max_sub_min {i j : nat} : dist i j = (max i j) - min i j :=
--sorry
/-
or.elim (lt_or_ge i j)
(suppose i < j,
by rw [max_eq_right_of_lt this, min_eq_left_of_lt this, dist_eq_sub_of_lt this])
(suppose i β₯ j,
by rw [max_eq_left this , min_eq_right this, dist_eq_sub_of_ge this])
-/
lemma dist_succ_succ {i j : nat} : dist (succ i) (succ j) = dist i j :=
by simp [dist.def, succ_sub_succ]
lemma dist_pos_of_ne {i j : nat} : i β j β dist i j > 0 :=
assume hne, nat.lt_by_cases
(suppose i < j,
begin rw [dist_eq_sub_of_le (le_of_lt this)], apply nat.sub_pos_of_lt this end)
(suppose i = j, by contradiction)
(suppose i > j,
begin rw [dist_eq_sub_of_ge (le_of_lt this)], apply nat.sub_pos_of_lt this end)
end nat
|
3f7282b89029a1de943e7d3c050291b568759799
|
2a70b774d16dbdf5a533432ee0ebab6838df0948
|
/_target/deps/mathlib/src/data/list/sort.lean
|
14c930c1c7ff9f90a31c7010e5ce4e7888751007
|
[
"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
| 13,206
|
lean
|
/-
Copyright (c) 2016 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Jeremy Avigad
-/
import data.list.perm
import data.list.chain
/-!
# Sorting algorithms on lists
In this file we define `list.sorted r l` to be an alias for `pairwise r l`. This alias is preferred
in the case that `r` is a `<` or `β€`-like relation. Then we define two sorting algorithms:
`list.insertion_sort` and `list.merge_sort`, and prove their correctness.
-/
open list.perm
namespace list
/-!
### The predicate `list.sorted`
-/
section sorted
universe variable uu
variables {Ξ± : Type uu} {r : Ξ± β Ξ± β Prop}
/-- `sorted r l` is the same as `pairwise r l`, preferred in the case that `r`
is a `<` or `β€`-like relation (transitive and antisymmetric or asymmetric) -/
def sorted := @pairwise
instance decidable_sorted [decidable_rel r] (l : list Ξ±) : decidable (sorted r l) :=
list.decidable_pairwise _
@[simp] theorem sorted_nil : sorted r [] := pairwise.nil
theorem sorted_of_sorted_cons {a : Ξ±} {l : list Ξ±} : sorted r (a :: l) β sorted r l :=
pairwise_of_pairwise_cons
theorem sorted.tail {r : Ξ± β Ξ± β Prop} {l : list Ξ±} (h : sorted r l) : sorted r l.tail :=
h.tail
theorem rel_of_sorted_cons {a : Ξ±} {l : list Ξ±} : sorted r (a :: l) β
β b β l, r a b :=
rel_of_pairwise_cons
@[simp] theorem sorted_cons {a : Ξ±} {l : list Ξ±} :
sorted r (a :: l) β (β b β l, r a b) β§ sorted r l :=
pairwise_cons
protected theorem sorted.nodup {r : Ξ± β Ξ± β Prop} [is_irrefl Ξ± r] {l : list Ξ±} (h : sorted r l) :
nodup l :=
h.nodup
theorem eq_of_perm_of_sorted [is_antisymm Ξ± r]
{lβ lβ : list Ξ±} (p : lβ ~ lβ) (sβ : sorted r lβ) (sβ : sorted r lβ) : lβ = lβ :=
begin
induction sβ with a lβ hβ sβ IH generalizing lβ,
{ exact p.nil_eq },
{ have : a β lβ := p.subset (mem_cons_self _ _),
rcases mem_split this with β¨uβ, vβ, rflβ©,
have p' := (perm_cons a).1 (p.trans perm_middle),
have := IH p' (pairwise_of_sublist (by simp) sβ), subst lβ,
change a::uβ ++ vβ = uβ ++ ([a] ++ vβ), rw β append_assoc, congr,
have : β (x : Ξ±) (h : x β uβ), x = a := Ξ» x m,
antisymm ((pairwise_append.1 sβ).2.2 _ m a (mem_cons_self _ _))
(hβ _ (by simp [m])),
rw [(@eq_repeat _ a (length uβ + 1) (a::uβ)).2,
(@eq_repeat _ a (length uβ + 1) (uβ++[a])).2];
split; simp [iff_true_intro this, or_comm] }
end
@[simp] theorem sorted_singleton (a : Ξ±) : sorted r [a] := pairwise_singleton _ _
lemma nth_le_of_sorted_of_le [is_refl Ξ± r] {l : list Ξ±}
(h : l.sorted r) {a b : β} {ha : a < l.length} {hb : b < l.length} (hab : a β€ b) :
r (l.nth_le a ha) (l.nth_le b hb) :=
begin
cases eq_or_lt_of_le hab with H H,
{ induction H, exact refl _ },
{ exact list.pairwise_iff_nth_le.1 h a b hb H }
end
end sorted
section sort
universe variable uu
variables {Ξ± : Type uu} (r : Ξ± β Ξ± β Prop) [decidable_rel r]
local infix ` βΌ ` : 50 := r
/-! ### Insertion sort -/
section insertion_sort
/-- `ordered_insert a l` inserts `a` into `l` at such that
`ordered_insert a l` is sorted if `l` is. -/
@[simp] def ordered_insert (a : Ξ±) : list Ξ± β list Ξ±
| [] := [a]
| (b :: l) := if a βΌ b then a :: b :: l else b :: ordered_insert l
/-- `insertion_sort l` returns `l` sorted using the insertion sort algorithm. -/
@[simp] def insertion_sort : list Ξ± β list Ξ±
| [] := []
| (b :: l) := ordered_insert r b (insertion_sort l)
@[simp] lemma ordered_insert_nil (a : Ξ±) : [].ordered_insert r a = [a] := rfl
theorem ordered_insert_length : Ξ (L : list Ξ±) (a : Ξ±), (L.ordered_insert r a).length = L.length + 1
| [] a := rfl
| (hd :: tl) a := by { dsimp [ordered_insert], split_ifs; simp [ordered_insert_length], }
/-- An alternative definition of `ordered_insert` using `take_while` and `drop_while`. -/
lemma ordered_insert_eq_take_drop (a : Ξ±) : β l : list Ξ±,
l.ordered_insert r a = l.take_while (Ξ» b, Β¬(a βΌ b)) ++ (a :: l.drop_while (Ξ» b, Β¬(a βΌ b)))
| [] := rfl
| (b :: l) := by { dsimp only [ordered_insert], split_ifs; simp [take_while, drop_while, *] }
lemma insertion_sort_cons_eq_take_drop (a : Ξ±) (l : list Ξ±) :
insertion_sort r (a :: l) = (insertion_sort r l).take_while (Ξ» b, Β¬(a βΌ b)) ++
(a :: (insertion_sort r l).drop_while (Ξ» b, Β¬(a βΌ b))) :=
ordered_insert_eq_take_drop r a _
section correctness
open perm
theorem perm_ordered_insert (a) : β l : list Ξ±, ordered_insert r a l ~ a :: l
| [] := perm.refl _
| (b :: l) := by by_cases a βΌ b; [simp [ordered_insert, h],
simpa [ordered_insert, h] using
((perm_ordered_insert l).cons _).trans (perm.swap _ _ _)]
theorem ordered_insert_count [decidable_eq Ξ±] (L : list Ξ±) (a b : Ξ±) :
count a (L.ordered_insert r b) = count a L + if (a = b) then 1 else 0 :=
begin
rw [(L.perm_ordered_insert r b).count_eq, count_cons],
split_ifs; simp only [nat.succ_eq_add_one, add_zero],
end
theorem perm_insertion_sort : β l : list Ξ±, insertion_sort r l ~ l
| [] := perm.nil
| (b :: l) := by simpa [insertion_sort] using
(perm_ordered_insert _ _ _).trans ((perm_insertion_sort l).cons b)
variable {r}
/-- If `l` is already `list.sorted` with respect to `r`, then `insertion_sort` does not change
it. -/
lemma sorted.insertion_sort_eq : β {l : list Ξ±} (h : sorted r l), insertion_sort r l = l
| [] _ := rfl
| [a] _ := rfl
| (a :: b :: l) h :=
begin
rw [insertion_sort, sorted.insertion_sort_eq, ordered_insert, if_pos],
exacts [rel_of_sorted_cons h _ (or.inl rfl), h.tail]
end
section total_and_transitive
variables [is_total Ξ± r] [is_trans Ξ± r]
theorem sorted.ordered_insert (a : Ξ±) : β l, sorted r l β sorted r (ordered_insert r a l)
| [] h := sorted_singleton a
| (b :: l) h := begin
by_cases h' : a βΌ b,
{ simpa [ordered_insert, h', h] using Ξ» b' bm, trans h' (rel_of_sorted_cons h _ bm) },
{ suffices : β (b' : Ξ±), b' β ordered_insert r a l β r b b',
{ simpa [ordered_insert, h', (sorted_of_sorted_cons h).ordered_insert l] },
intros b' bm,
cases (show b' = a β¨ b' β l, by simpa using
(perm_ordered_insert _ _ _).subset bm) with be bm,
{ subst b', exact (total_of r _ _).resolve_left h' },
{ exact rel_of_sorted_cons h _ bm } }
end
variable (r)
/-- The list `list.insertion_sort r l` is `list.sorted` with respect to `r`. -/
theorem sorted_insertion_sort : β l, sorted r (insertion_sort r l)
| [] := sorted_nil
| (a :: l) := (sorted_insertion_sort l).ordered_insert a _
end total_and_transitive
end correctness
end insertion_sort
/-! ### Merge sort -/
section merge_sort
-- TODO(Jeremy): observation: if instead we write (a :: (split l).1, b :: (split l).2), the
-- equation compiler can't prove the third equation
/-- Split `l` into two lists of approximately equal length.
split [1, 2, 3, 4, 5] = ([1, 3, 5], [2, 4]) -/
@[simp] def split : list Ξ± β list Ξ± Γ list Ξ±
| [] := ([], [])
| (a :: l) := let (lβ, lβ) := split l in (a :: lβ, lβ)
theorem split_cons_of_eq (a : Ξ±) {l lβ lβ : list Ξ±} (h : split l = (lβ, lβ)) :
split (a :: l) = (a :: lβ, lβ) :=
by rw [split, h]; refl
theorem length_split_le : β {l lβ lβ : list Ξ±},
split l = (lβ, lβ) β length lβ β€ length l β§ length lβ β€ length l
| [] ._ ._ rfl := β¨nat.le_refl 0, nat.le_refl 0β©
| (a::l) lβ' lβ' h := begin
cases e : split l with lβ lβ,
injection (split_cons_of_eq _ e).symm.trans h, substs lβ' lβ',
cases length_split_le e with hβ hβ,
exact β¨nat.succ_le_succ hβ, nat.le_succ_of_le hββ©
end
theorem length_split_lt {a b} {l lβ lβ : list Ξ±} (h : split (a::b::l) = (lβ, lβ)) :
length lβ < length (a::b::l) β§ length lβ < length (a::b::l) :=
begin
cases e : split l with lβ' lβ',
injection (split_cons_of_eq _ (split_cons_of_eq _ e)).symm.trans h, substs lβ lβ,
cases length_split_le e with hβ hβ,
exact β¨nat.succ_le_succ (nat.succ_le_succ hβ), nat.succ_le_succ (nat.succ_le_succ hβ)β©
end
theorem perm_split : β {l lβ lβ : list Ξ±}, split l = (lβ, lβ) β l ~ lβ ++ lβ
| [] ._ ._ rfl := perm.refl _
| (a::l) lβ' lβ' h := begin
cases e : split l with lβ lβ,
injection (split_cons_of_eq _ e).symm.trans h, substs lβ' lβ',
exact ((perm_split e).trans perm_append_comm).cons a,
end
/-- Merge two sorted lists into one in linear time.
merge [1, 2, 4, 5] [0, 1, 3, 4] = [0, 1, 1, 2, 3, 4, 4, 5] -/
def merge : list Ξ± β list Ξ± β list Ξ±
| [] l' := l'
| l [] := l
| (a :: l) (b :: l') := if a βΌ b then a :: merge l (b :: l') else b :: merge (a :: l) l'
include r
/-- Implementation of a merge sort algorithm to sort a list. -/
def merge_sort : list Ξ± β list Ξ±
| [] := []
| [a] := [a]
| (a::b::l) := begin
cases e : split (a::b::l) with lβ lβ,
cases length_split_lt e with hβ hβ,
exact merge r (merge_sort lβ) (merge_sort lβ)
end
using_well_founded {
rel_tac := Ξ»_ _, `[exact β¨_, inv_image.wf length nat.lt_wfβ©],
dec_tac := tactic.assumption }
theorem merge_sort_cons_cons {a b} {l lβ lβ : list Ξ±}
(h : split (a::b::l) = (lβ, lβ)) :
merge_sort r (a::b::l) = merge r (merge_sort r lβ) (merge_sort r lβ) :=
begin
suffices : β (L : list Ξ±) h1, @@and.rec
(Ξ» a a (_ : length lβ < length l + 1 + 1 β§
length lβ < length l + 1 + 1), L) h1 h1 = L,
{ simp [merge_sort, h], apply this },
intros, cases h1, refl
end
section correctness
theorem perm_merge : β (l l' : list Ξ±), merge r l l' ~ l ++ l'
| [] [] := perm.nil
| [] (b :: l') := by simp [merge]
| (a :: l) [] := by simp [merge]
| (a :: l) (b :: l') := begin
by_cases a βΌ b,
{ simpa [merge, h] using perm_merge _ _ },
{ suffices : b :: merge r (a :: l) l' ~ a :: (l ++ b :: l'), {simpa [merge, h]},
exact ((perm_merge _ _).cons _).trans ((swap _ _ _).trans (perm_middle.symm.cons _)) }
end
theorem perm_merge_sort : β l : list Ξ±, merge_sort r l ~ l
| [] := perm.refl _
| [a] := perm.refl _
| (a::b::l) := begin
cases e : split (a::b::l) with lβ lβ,
cases length_split_lt e with hβ hβ,
rw [merge_sort_cons_cons r e],
apply (perm_merge r _ _).trans,
exact ((perm_merge_sort lβ).append (perm_merge_sort lβ)).trans (perm_split e).symm
end
using_well_founded {
rel_tac := Ξ»_ _, `[exact β¨_, inv_image.wf length nat.lt_wfβ©],
dec_tac := tactic.assumption }
@[simp] lemma length_merge_sort (l : list Ξ±) : (merge_sort r l).length = l.length :=
(perm_merge_sort r _).length_eq
section total_and_transitive
variables {r} [is_total Ξ± r] [is_trans Ξ± r]
theorem sorted.merge : β {l l' : list Ξ±}, sorted r l β sorted r l' β sorted r (merge r l l')
| [] [] hβ hβ := sorted_nil
| [] (b :: l') hβ hβ := by simpa [merge] using hβ
| (a :: l) [] hβ hβ := by simpa [merge] using hβ
| (a :: l) (b :: l') hβ hβ := begin
by_cases a βΌ b,
{ suffices : β (b' : Ξ±) (_ : b' β merge r l (b :: l')), r a b',
{ simpa [merge, h, (sorted_of_sorted_cons hβ).merge hβ] },
intros b' bm,
rcases (show b' = b β¨ b' β l β¨ b' β l', by simpa [or.left_comm] using
(perm_merge _ _ _).subset bm) with be | bl | bl',
{ subst b', assumption },
{ exact rel_of_sorted_cons hβ _ bl },
{ exact trans h (rel_of_sorted_cons hβ _ bl') } },
{ suffices : β (b' : Ξ±) (_ : b' β merge r (a :: l) l'), r b b',
{ simpa [merge, h, hβ.merge (sorted_of_sorted_cons hβ)] },
intros b' bm,
have ba : b βΌ a := (total_of r _ _).resolve_left h,
rcases (show b' = a β¨ b' β l β¨ b' β l', by simpa using
(perm_merge _ _ _).subset bm) with be | bl | bl',
{ subst b', assumption },
{ exact trans ba (rel_of_sorted_cons hβ _ bl) },
{ exact rel_of_sorted_cons hβ _ bl' } }
end
variable (r)
theorem sorted_merge_sort : β l : list Ξ±, sorted r (merge_sort r l)
| [] := sorted_nil
| [a] := sorted_singleton _
| (a::b::l) := begin
cases e : split (a::b::l) with lβ lβ,
cases length_split_lt e with hβ hβ,
rw [merge_sort_cons_cons r e],
exact (sorted_merge_sort lβ).merge (sorted_merge_sort lβ)
end
using_well_founded {
rel_tac := Ξ»_ _, `[exact β¨_, inv_image.wf length nat.lt_wfβ©],
dec_tac := tactic.assumption }
theorem merge_sort_eq_self [is_antisymm Ξ± r] {l : list Ξ±} : sorted r l β merge_sort r l = l :=
eq_of_perm_of_sorted (perm_merge_sort _ _) (sorted_merge_sort _ _)
theorem merge_sort_eq_insertion_sort [is_antisymm Ξ± r] (l : list Ξ±) :
merge_sort r l = insertion_sort r l :=
eq_of_perm_of_sorted ((perm_merge_sort r l).trans (perm_insertion_sort r l).symm)
(sorted_merge_sort r l) (sorted_insertion_sort r l)
end total_and_transitive
end correctness
end merge_sort
end sort
/- try them out! -/
--#eval insertion_sort (Ξ» m n : β, m β€ n) [5, 27, 221, 95, 17, 43, 7, 2, 98, 567, 23, 12]
--#eval merge_sort (Ξ» m n : β, m β€ n) [5, 27, 221, 95, 17, 43, 7, 2, 98, 567, 23, 12]
end list
|
d1544727d381534fc86c80b74165b747fb8b6663
|
0c6b99c0daded009943e570c13367c8cc7d3bcae
|
/chapter16.lean
|
bb2bc62a5695bf3d5f8ae4809d74560eeb559cb3
|
[] |
no_license
|
TateKennington/logic-and-proof-exercises
|
e3c5c5b12b6238b47b0c5acf8717923bd471a535
|
acca8882026e7b643453eb096d3021cd043005bd
|
refs/heads/main
| 1,687,638,489,616
| 1,626,858,474,000
| 1,626,858,474,000
| 371,871,374
| 4
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 1,403
|
lean
|
import data.set data.int.basic data.set
open function int set
section
def g (x : β€) : β€ := -x
def h (x : β€) : β€ := 2 * x + 3
example : injective h :=
assume xβ xβ,
assume :2 * xβ + 3 = 2 * xβ + 3,
have 2 * xβ = 2 * xβ, from add_right_cancel this,
show xβ = xβ, from mul_left_cancel' (dec_trivial) this
example : surjective g :=
assume y,
have g (-y) = y, from calc
g (-y) = -(-y): rfl
... = y: neg_neg y,
exists.intro (-y) this
example (A B : Type) (u : A β B) (v1 : B β A) (v2 : B β A)
(h1 : left_inverse v1 u) (h2 : right_inverse v2 u) : v1 = v2 :=
funext
(assume x,
calc
v1 x = v1 (u (v2 x)) : by rw h2
... = v2 x : by rw h1)
end
section
variables {X Y : Type}
variable f : X β Y
variables A B : set X
example : f '' (A β© B) β f '' A β© f '' B :=
assume y,
assume h1 : y β f '' (A β© B),
show y β f '' A β© f '' B, from
exists.elim h1 $
assume x h,
have feq: f x = y, from and.right h,
have x β A β© B, from and.left h,
have x β A, from and.left βΉx β A β© BβΊ,
have y β f '' A, from exists.intro x $ β¨this, feqβ©,
have x β B, from and.right βΉx β A β© BβΊ,
have y β f '' B, from exists.intro x $ β¨this, feqβ©,
β¨βΉy β f '' AβΊ, βΉy β f '' BβΊβ©
end
|
4e2e15d8db1d88502b83f944b5e362fdf787f272
|
d6124c8dbe5661dcc5b8c9da0a56fbf1f0480ad6
|
/Papyrus/IR/AddressSpace.lean
|
c3500e0edec08752d24c4b3aa9b76cf87bf9e7e0
|
[
"Apache-2.0"
] |
permissive
|
xubaiw/lean4-papyrus
|
c3fbbf8ba162eb5f210155ae4e20feb2d32c8182
|
02e82973a5badda26fc0f9fd15b3d37e2eb309e0
|
refs/heads/master
| 1,691,425,756,824
| 1,632,122,825,000
| 1,632,123,075,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 739
|
lean
|
namespace Papyrus
/-- A numerically indexed address space. -/
structure AddressSpace where
index : UInt32
deriving BEq, Repr
namespace AddressSpace
/-- The default address space (i.e., 0). -/
def default := mk 0
/-- Make an address space from a `Nat`. -/
def ofNat (n : Nat) := mk n.toUInt32
/-- Make an address space from a `UInt32`. -/
def ofUInt32 (n : UInt32) := mk n
/-- Convert an address space tp a `Nat`. -/
def toNat (self : AddressSpace) : Nat := self.index.toNat
/-- Convert an address space to a `UInt32`. -/
def toUInt32 (self : AddressSpace) : UInt32 := self.index
end AddressSpace
instance : Inhabited AddressSpace := β¨AddressSpace.defaultβ©
instance {n} : OfNat AddressSpace n := β¨AddressSpace.ofNat nβ©
|
3d5a7450cbd283cabf2c1a5baf204c04eda7979e
|
4efff1f47634ff19e2f786deadd394270a59ecd2
|
/src/data/nat/choose.lean
|
5426c254164935a3056a4ad889c20472b05f26d6
|
[
"Apache-2.0"
] |
permissive
|
agjftucker/mathlib
|
d634cd0d5256b6325e3c55bb7fb2403548371707
|
87fe50de17b00af533f72a102d0adefe4a2285e8
|
refs/heads/master
| 1,625,378,131,941
| 1,599,166,526,000
| 1,599,166,526,000
| 160,748,509
| 0
| 0
|
Apache-2.0
| 1,544,141,789,000
| 1,544,141,789,000
| null |
UTF-8
|
Lean
| false
| false
| 6,297
|
lean
|
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Bhavik Mehta, Patrick Stevens
-/
import tactic.linarith
import tactic.omega
import algebra.big_operators.ring
import algebra.big_operators.intervals
import algebra.big_operators.order
open nat
open_locale big_operators
lemma nat.prime.dvd_choose_add {p a b : β} (hap : a < p) (hbp : b < p) (h : p β€ a + b)
(hp : prime p) : p β£ choose (a + b) a :=
have hβ : p β£ fact (a + b), from hp.dvd_fact.2 h,
have hβ : Β¬p β£ fact a, from mt hp.dvd_fact.1 (not_le_of_gt hap),
have hβ : Β¬p β£ fact b, from mt hp.dvd_fact.1 (not_le_of_gt hbp),
by
rw [β choose_mul_fact_mul_fact (le.intro rfl), mul_assoc, hp.dvd_mul, hp.dvd_mul,
norm_num.sub_nat_pos (a + b) a b rfl] at hβ;
exact hβ.resolve_right (not_or_distrib.2 β¨hβ, hββ©)
lemma nat.prime.dvd_choose_self {p k : β} (hk : 0 < k) (hkp : k < p) (hp : prime p) :
p β£ choose p k :=
begin
have r : k + (p - k) = p,
by rw [β nat.add_sub_assoc (nat.le_of_lt hkp) k, nat.add_sub_cancel_left],
have e : p β£ choose (k + (p - k)) k,
by exact nat.prime.dvd_choose_add hkp (sub_lt (lt.trans hk hkp) hk) (by rw r) hp,
rwa r at e,
end
/-- Show that choose is increasing for small values of the right argument. -/
lemma choose_le_succ_of_lt_half_left {r n : β} (h : r < n/2) :
choose n r β€ choose n (r+1) :=
begin
refine le_of_mul_le_mul_right _ (nat.lt_sub_left_of_add_lt (lt_of_lt_of_le h (nat.div_le_self n 2))),
rw β choose_succ_right_eq,
apply nat.mul_le_mul_left,
rw [β nat.lt_iff_add_one_le, nat.lt_sub_left_iff_add_lt, β mul_two],
exact lt_of_lt_of_le (mul_lt_mul_of_pos_right h zero_lt_two) (nat.div_mul_le_self n 2),
end
/-- Show that for small values of the right argument, the middle value is largest. -/
private lemma choose_le_middle_of_le_half_left {n r : β} (hr : r β€ n/2) :
choose n r β€ choose n (n/2) :=
decreasing_induction
(Ξ» _ k a,
(eq_or_lt_of_le a).elim
(Ξ» t, t.symm βΈ le_refl _)
(Ξ» h, trans (choose_le_succ_of_lt_half_left h) (k h)))
hr (Ξ» _, le_refl _) hr
/-- `choose n r` is maximised when `r` is `n/2`. -/
lemma choose_le_middle (r n : β) : nat.choose n r β€ nat.choose n (n/2) :=
begin
cases le_or_gt r n with b b,
{ cases le_or_lt r (n/2) with a h,
{ apply choose_le_middle_of_le_half_left a },
{ rw β choose_symm b,
apply choose_le_middle_of_le_half_left,
rw [div_lt_iff_lt_mul' zero_lt_two] at h,
rw [le_div_iff_mul_le' zero_lt_two, nat.mul_sub_right_distrib, nat.sub_le_iff,
mul_two, nat.add_sub_cancel],
exact le_of_lt h } },
{ rw nat.choose_eq_zero_of_lt b,
apply nat.zero_le }
end
section binomial
open finset
variables {Ξ± : Type*}
/-- A version of the binomial theorem for noncommutative semirings. -/
theorem commute.add_pow [semiring Ξ±] {x y : Ξ±} (h : commute x y) (n : β) :
(x + y) ^ n = β m in range (n + 1), x ^ m * y ^ (n - m) * choose n m :=
begin
let t : β β β β Ξ± := Ξ» n m, x ^ m * (y ^ (n - m)) * (choose n m),
change (x + y) ^ n = β m in range (n + 1), t n m,
have h_first : β n, t n 0 = y ^ n :=
Ξ» n, by { dsimp [t], rw[choose_zero_right, nat.cast_one, mul_one, one_mul] },
have h_last : β n, t n n.succ = 0 :=
Ξ» n, by { dsimp [t], rw [choose_succ_self, nat.cast_zero, mul_zero] },
have h_middle : β (n i : β), (i β finset.range n.succ) β
((t n.succ) β nat.succ) i = x * (t n i) + y * (t n i.succ) :=
begin
intros n i h_mem,
have h_le : i β€ n := nat.le_of_lt_succ (finset.mem_range.mp h_mem),
dsimp [t],
rw [choose_succ_succ, nat.cast_add, mul_add],
congr' 1,
{ rw[pow_succ x, succ_sub_succ, mul_assoc, mul_assoc, mul_assoc] },
{ rw[β mul_assoc y, β mul_assoc y, (h.symm.pow_right i.succ).eq],
by_cases h_eq : i = n,
{ rw [h_eq, choose_succ_self, nat.cast_zero, mul_zero, mul_zero] },
{ rw[succ_sub (lt_of_le_of_ne h_le h_eq)],
rw[pow_succ y, mul_assoc, mul_assoc, mul_assoc, mul_assoc] } }
end,
induction n with n ih,
{ rw [pow_zero, sum_range_succ, range_zero, sum_empty, add_zero],
dsimp [t], rw [choose_self, nat.cast_one, mul_one, mul_one] },
{ rw[sum_range_succ', h_first],
rw[finset.sum_congr rfl (h_middle n), finset.sum_add_distrib, add_assoc],
rw[pow_succ (x + y), ih, add_mul, finset.mul_sum, finset.mul_sum],
congr' 1,
rw[finset.sum_range_succ', finset.sum_range_succ, h_first, h_last,
mul_zero, zero_add, pow_succ] }
end
/-- The binomial theorem-/
theorem add_pow [comm_semiring Ξ±] (x y : Ξ±) (n : β) :
(x + y) ^ n = β m in range (n + 1), x ^ m * y ^ (n - m) * choose n m :=
(commute.all x y).add_pow n
/-- The sum of entries in a row of Pascal's triangle -/
theorem sum_range_choose (n : β) :
β m in range (n + 1), choose n m = 2 ^ n :=
by simpa using (add_pow 1 1 n).symm
/-!
# Specific facts about binomial coefficients and their sums
-/
lemma sum_range_choose_halfway (m : nat) :
β i in range (m + 1), nat.choose (2 * m + 1) i = 4 ^ m :=
have β i in range (m + 1), choose (2 * m + 1) (2 * m + 1 - i) =
β i in range (m + 1), choose (2 * m + 1) i,
from sum_congr rfl $ Ξ» i hi, choose_symm $ by linarith [mem_range.1 hi],
(nat.mul_right_inj zero_lt_two).1 $
calc 2 * (β i in range (m + 1), nat.choose (2 * m + 1) i) =
(β i in range (m + 1), nat.choose (2 * m + 1) i) +
β i in range (m + 1), nat.choose (2 * m + 1) (2 * m + 1 - i) :
by rw [two_mul, this]
... = (β i in range (m + 1), nat.choose (2 * m + 1) i) +
β i in Ico (m + 1) (2 * m + 2), nat.choose (2 * m + 1) i :
by { rw [range_eq_Ico, sum_Ico_reflect], { congr, omega }, omega }
... = β i in range (2 * m + 2), nat.choose (2 * m + 1) i : sum_range_add_sum_Ico _ (by omega)
... = 2^(2 * m + 1) : sum_range_choose (2 * m + 1)
... = 2 * 4^m : by { rw [nat.pow_succ, mul_comm, nat.pow_mul], refl }
lemma choose_middle_le_pow (n : β) : choose (2 * n + 1) n β€ 4 ^ n :=
begin
have t : choose (2 * n + 1) n β€ β i in finset.range (n + 1), choose (2 * n + 1) i :=
finset.single_le_sum (Ξ» x _, by linarith) (finset.self_mem_range_succ n),
simpa [sum_range_choose_halfway n] using t
end
end binomial
|
f2fc9b7188bb483cfacff08aab09fe3e38f7ad6e
|
8cae430f0a71442d02dbb1cbb14073b31048e4b0
|
/src/ring_theory/dedekind_domain/ideal.lean
|
be1aed2e252fddb8f7346bbf5958485a4e460aa4
|
[
"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
| 66,275
|
lean
|
/-
Copyright (c) 2020 Kenji Nakagawa. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenji Nakagawa, Anne Baanen, Filippo A. E. Nuccio
-/
import algebra.algebra.subalgebra.pointwise
import algebraic_geometry.prime_spectrum.maximal
import algebraic_geometry.prime_spectrum.noetherian
import order.hom.basic
import ring_theory.dedekind_domain.basic
import ring_theory.fractional_ideal
import ring_theory.principal_ideal_domain
import ring_theory.chain_of_divisors
/-!
# Dedekind domains and ideals
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
In this file, we show a ring is a Dedekind domain iff all fractional ideals are invertible.
Then we prove some results on the unique factorization monoid structure of the ideals.
## Main definitions
- `is_dedekind_domain_inv` alternatively defines a Dedekind domain as an integral domain where
every nonzero fractional ideal is invertible.
- `is_dedekind_domain_inv_iff` shows that this does note depend on the choice of field of
fractions.
- `is_dedekind_domain.height_one_spectrum` defines the type of nonzero prime ideals of `R`.
## Main results:
- `is_dedekind_domain_iff_is_dedekind_domain_inv`
- `ideal.unique_factorization_monoid`
## Implementation notes
The definitions that involve a field of fractions choose a canonical field of fractions,
but are independent of that choice. The `..._iff` lemmas express this independence.
Often, definitions assume that Dedekind domains are not fields. We found it more practical
to add a `(h : Β¬ is_field A)` assumption whenever this is explicitly needed.
## References
* [D. Marcus, *Number Fields*][marcus1977number]
* [J.W.S. Cassels, A. FrΓΆlich, *Algebraic Number Theory*][cassels1967algebraic]
* [J. Neukirch, *Algebraic Number Theory*][Neukirch1992]
## Tags
dedekind domain, dedekind ring
-/
variables (R A K : Type*) [comm_ring R] [comm_ring A] [field K]
open_locale non_zero_divisors polynomial
variables [is_domain A]
section inverse
namespace fractional_ideal
variables {Rβ : Type*} [comm_ring Rβ] [is_domain Rβ] [algebra Rβ K] [is_fraction_ring Rβ K]
variables {I J : fractional_ideal Rββ° K}
noncomputable instance : has_inv (fractional_ideal Rββ° K) := β¨Ξ» I, 1 / Iβ©
lemma inv_eq : Iβ»ΒΉ = 1 / I := rfl
lemma inv_zero' : (0 : fractional_ideal Rββ° K)β»ΒΉ = 0 := div_zero
lemma inv_nonzero {J : fractional_ideal Rββ° K} (h : J β 0) :
Jβ»ΒΉ = β¨(1 : fractional_ideal Rββ° K) / J, fractional_div_of_nonzero hβ© := div_nonzero _
lemma coe_inv_of_nonzero {J : fractional_ideal Rββ° K} (h : J β 0) :
(βJβ»ΒΉ : submodule Rβ K) = is_localization.coe_submodule K β€ / J :=
by { rwa inv_nonzero _, refl, assumption }
variables {K}
lemma mem_inv_iff (hI : I β 0) {x : K} : x β Iβ»ΒΉ β β y β I, x * y β (1 : fractional_ideal Rββ° K) :=
mem_div_iff_of_nonzero hI
lemma inv_anti_mono (hI : I β 0) (hJ : J β 0) (hIJ : I β€ J) : Jβ»ΒΉ β€ Iβ»ΒΉ :=
Ξ» x, by { simp only [mem_inv_iff hI, mem_inv_iff hJ], exact Ξ» h y hy, h y (hIJ hy) }
lemma le_self_mul_inv {I : fractional_ideal Rββ° K} (hI : I β€ (1 : fractional_ideal Rββ° K)) :
I β€ I * Iβ»ΒΉ :=
le_self_mul_one_div hI
variables (K)
lemma coe_ideal_le_self_mul_inv (I : ideal Rβ) : (I : fractional_ideal Rββ° K) β€ I * Iβ»ΒΉ :=
le_self_mul_inv coe_ideal_le_one
/-- `Iβ»ΒΉ` is the inverse of `I` if `I` has an inverse. -/
theorem right_inverse_eq (I J : fractional_ideal Rββ° K) (h : I * J = 1) : J = Iβ»ΒΉ :=
begin
have hI : I β 0 := ne_zero_of_mul_eq_one I J h,
suffices h' : I * (1 / I) = 1,
{ exact (congr_arg units.inv $
@units.ext _ _ (units.mk_of_mul_eq_one _ _ h) (units.mk_of_mul_eq_one _ _ h') rfl) },
apply le_antisymm,
{ apply mul_le.mpr _,
intros x hx y hy,
rw mul_comm,
exact (mem_div_iff_of_nonzero hI).mp hy x hx },
rw β h,
apply mul_left_mono I,
apply (le_div_iff_of_nonzero hI).mpr _,
intros y hy x hx,
rw mul_comm,
exact mul_mem_mul hx hy
end
theorem mul_inv_cancel_iff {I : fractional_ideal Rββ° K} : I * Iβ»ΒΉ = 1 β β J, I * J = 1 :=
β¨Ξ» h, β¨Iβ»ΒΉ, hβ©, Ξ» β¨J, hJβ©, by rwa β right_inverse_eq K I J hJβ©
lemma mul_inv_cancel_iff_is_unit {I : fractional_ideal Rββ° K} : I * Iβ»ΒΉ = 1 β is_unit I :=
(mul_inv_cancel_iff K).trans is_unit_iff_exists_inv.symm
variables {K' : Type*} [field K'] [algebra Rβ K'] [is_fraction_ring Rβ K']
@[simp] lemma map_inv (I : fractional_ideal Rββ° K) (h : K ββ[Rβ] K') :
(Iβ»ΒΉ).map (h : K ββ[Rβ] K') = (I.map h)β»ΒΉ :=
by rw [inv_eq, map_div, map_one, inv_eq]
open submodule submodule.is_principal
@[simp] lemma span_singleton_inv (x : K) : (span_singleton Rββ° x)β»ΒΉ = span_singleton _ xβ»ΒΉ :=
one_div_span_singleton x
@[simp] lemma span_singleton_div_span_singleton (x y : K) :
span_singleton Rββ° x / span_singleton Rββ° y = span_singleton Rββ° (x / y) :=
by rw [div_span_singleton, mul_comm, span_singleton_mul_span_singleton, div_eq_mul_inv]
lemma span_singleton_div_self {x : K} (hx : x β 0) :
span_singleton Rββ° x / span_singleton Rββ° x = 1 :=
by rw [span_singleton_div_span_singleton, div_self hx, span_singleton_one]
lemma coe_ideal_span_singleton_div_self {x : Rβ} (hx : x β 0) :
(ideal.span ({x} : set Rβ) : fractional_ideal Rββ° K) / ideal.span ({x} : set Rβ) = 1 :=
by rw [coe_ideal_span_singleton, span_singleton_div_self K $
(map_ne_zero_iff _ $ no_zero_smul_divisors.algebra_map_injective Rβ K).mpr hx]
lemma span_singleton_mul_inv {x : K} (hx : x β 0) :
span_singleton Rββ° x * (span_singleton Rββ° x)β»ΒΉ = 1 :=
by rw [span_singleton_inv, span_singleton_mul_span_singleton, mul_inv_cancel hx, span_singleton_one]
lemma coe_ideal_span_singleton_mul_inv {x : Rβ} (hx : x β 0) :
(ideal.span ({x} : set Rβ) : fractional_ideal Rββ° K) * (ideal.span ({x} : set Rβ))β»ΒΉ = 1 :=
by rw [coe_ideal_span_singleton, span_singleton_mul_inv K $
(map_ne_zero_iff _ $ no_zero_smul_divisors.algebra_map_injective Rβ K).mpr hx]
lemma span_singleton_inv_mul {x : K} (hx : x β 0) :
(span_singleton Rββ° x)β»ΒΉ * span_singleton Rββ° x = 1 :=
by rw [mul_comm, span_singleton_mul_inv K hx]
lemma coe_ideal_span_singleton_inv_mul {x : Rβ} (hx : x β 0) :
(ideal.span ({x} : set Rβ) : fractional_ideal Rββ° K)β»ΒΉ * ideal.span ({x} : set Rβ) = 1 :=
by rw [mul_comm, coe_ideal_span_singleton_mul_inv K hx]
lemma mul_generator_self_inv {Rβ : Type*} [comm_ring Rβ] [algebra Rβ K] [is_localization Rββ° K]
(I : fractional_ideal Rββ° K) [submodule.is_principal (I : submodule Rβ K)] (h : I β 0) :
I * span_singleton _ (generator (I : submodule Rβ K))β»ΒΉ = 1 :=
begin
-- Rewrite only the `I` that appears alone.
conv_lhs { congr, rw eq_span_singleton_of_principal I },
rw [span_singleton_mul_span_singleton, mul_inv_cancel, span_singleton_one],
intro generator_I_eq_zero,
apply h,
rw [eq_span_singleton_of_principal I, generator_I_eq_zero, span_singleton_zero]
end
lemma invertible_of_principal (I : fractional_ideal Rββ° K)
[submodule.is_principal (I : submodule Rβ K)] (h : I β 0) : I * Iβ»ΒΉ = 1 :=
(mul_div_self_cancel_iff).mpr
β¨span_singleton _ (generator (I : submodule Rβ K))β»ΒΉ, mul_generator_self_inv _ I hβ©
lemma invertible_iff_generator_nonzero (I : fractional_ideal Rββ° K)
[submodule.is_principal (I : submodule Rβ K)] :
I * Iβ»ΒΉ = 1 β generator (I : submodule Rβ K) β 0 :=
begin
split,
{ intros hI hg,
apply ne_zero_of_mul_eq_one _ _ hI,
rw [eq_span_singleton_of_principal I, hg, span_singleton_zero] },
{ intro hg,
apply invertible_of_principal,
rw [eq_span_singleton_of_principal I],
intro hI,
have := mem_span_singleton_self _ (generator (I : submodule Rβ K)),
rw [hI, mem_zero_iff] at this,
contradiction }
end
lemma is_principal_inv (I : fractional_ideal Rββ° K)
[submodule.is_principal (I : submodule Rβ K)] (h : I β 0) :
submodule.is_principal (Iβ»ΒΉ).1 :=
begin
rw [val_eq_coe, is_principal_iff],
use (generator (I : submodule Rβ K))β»ΒΉ,
have hI : I * span_singleton _ ((generator (I : submodule Rβ K))β»ΒΉ) = 1,
apply mul_generator_self_inv _ I h,
exact (right_inverse_eq _ I (span_singleton _ ((generator (I : submodule Rβ K))β»ΒΉ)) hI).symm
end
noncomputable instance : inv_one_class (fractional_ideal Rββ° K) :=
{ inv_one := div_one,
..fractional_ideal.has_one,
..fractional_ideal.has_inv K }
end fractional_ideal
/--
A Dedekind domain is an integral domain such that every fractional ideal has an inverse.
This is equivalent to `is_dedekind_domain`.
In particular we provide a `fractional_ideal.comm_group_with_zero` instance,
assuming `is_dedekind_domain A`, which implies `is_dedekind_domain_inv`. For **integral** ideals,
`is_dedekind_domain`(`_inv`) implies only `ideal.cancel_comm_monoid_with_zero`.
-/
def is_dedekind_domain_inv : Prop :=
β I β (β₯ : fractional_ideal Aβ° (fraction_ring A)), I * Iβ»ΒΉ = 1
open fractional_ideal
variables {R A K}
lemma is_dedekind_domain_inv_iff [algebra A K] [is_fraction_ring A K] :
is_dedekind_domain_inv A β (β I β (β₯ : fractional_ideal Aβ° K), I * Iβ»ΒΉ = 1) :=
begin
let h := map_equiv (fraction_ring.alg_equiv A K),
refine h.to_equiv.forall_congr (Ξ» I, _),
rw β h.to_equiv.apply_eq_iff_eq,
simp [is_dedekind_domain_inv, show βh.to_equiv = h, from rfl],
end
lemma fractional_ideal.adjoin_integral_eq_one_of_is_unit [algebra A K] [is_fraction_ring A K]
(x : K) (hx : is_integral A x) (hI : is_unit (adjoin_integral Aβ° x hx)) :
adjoin_integral Aβ° x hx = 1 :=
begin
set I := adjoin_integral Aβ° x hx,
have mul_self : I * I = I,
{ apply coe_to_submodule_injective, simp },
convert congr_arg (* Iβ»ΒΉ) mul_self;
simp only [(mul_inv_cancel_iff_is_unit K).mpr hI, mul_assoc, mul_one],
end
namespace is_dedekind_domain_inv
variables [algebra A K] [is_fraction_ring A K] (h : is_dedekind_domain_inv A)
include h
lemma mul_inv_eq_one {I : fractional_ideal Aβ° K} (hI : I β 0) : I * Iβ»ΒΉ = 1 :=
is_dedekind_domain_inv_iff.mp h I hI
lemma inv_mul_eq_one {I : fractional_ideal Aβ° K} (hI : I β 0) : Iβ»ΒΉ * I = 1 :=
(mul_comm _ _).trans (h.mul_inv_eq_one hI)
protected lemma is_unit {I : fractional_ideal Aβ° K} (hI : I β 0) : is_unit I :=
is_unit_of_mul_eq_one _ _ (h.mul_inv_eq_one hI)
lemma is_noetherian_ring : is_noetherian_ring A :=
begin
refine is_noetherian_ring_iff.mpr β¨Ξ» (I : ideal A), _β©,
by_cases hI : I = β₯,
{ rw hI, apply submodule.fg_bot },
have hI : (I : fractional_ideal Aβ° (fraction_ring A)) β 0 := coe_ideal_ne_zero.mpr hI,
exact I.fg_of_is_unit (is_fraction_ring.injective A (fraction_ring A)) (h.is_unit hI)
end
lemma integrally_closed : is_integrally_closed A :=
begin
-- It suffices to show that for integral `x`,
-- `A[x]` (which is a fractional ideal) is in fact equal to `A`.
refine β¨Ξ» x hx, _β©,
rw [β set.mem_range, β algebra.mem_bot, β subalgebra.mem_to_submodule, algebra.to_submodule_bot,
β coe_span_singleton Aβ° (1 : fraction_ring A), span_singleton_one,
β fractional_ideal.adjoin_integral_eq_one_of_is_unit x hx (h.is_unit _)],
{ exact mem_adjoin_integral_self Aβ° x hx },
{ exact Ξ» h, one_ne_zero (eq_zero_iff.mp h 1 (subalgebra.one_mem _)) },
end
open ring
lemma dimension_le_one : dimension_le_one A :=
begin
-- We're going to show that `P` is maximal because any (maximal) ideal `M`
-- that is strictly larger would be `β€`.
rintros P P_ne hP,
refine ideal.is_maximal_def.mpr β¨hP.ne_top, Ξ» M hM, _β©,
-- We may assume `P` and `M` (as fractional ideals) are nonzero.
have P'_ne : (P : fractional_ideal Aβ° (fraction_ring A)) β 0 := coe_ideal_ne_zero.mpr P_ne,
have M'_ne : (M : fractional_ideal Aβ° (fraction_ring A)) β 0 :=
coe_ideal_ne_zero.mpr (lt_of_le_of_lt bot_le hM).ne',
-- In particular, we'll show `Mβ»ΒΉ * P β€ P`
suffices : (Mβ»ΒΉ * P : fractional_ideal Aβ° (fraction_ring A)) β€ P,
{ rw [eq_top_iff, β coe_ideal_le_coe_ideal (fraction_ring A), coe_ideal_top],
calc (1 : fractional_ideal Aβ° (fraction_ring A)) = _ * _ * _ : _
... β€ _ * _ : mul_right_mono (Pβ»ΒΉ * M : fractional_ideal Aβ° (fraction_ring A)) this
... = M : _,
{ rw [mul_assoc, β mul_assoc βP, h.mul_inv_eq_one P'_ne, one_mul, h.inv_mul_eq_one M'_ne] },
{ rw [β mul_assoc βP, h.mul_inv_eq_one P'_ne, one_mul] },
{ apply_instance } },
-- Suppose we have `x β Mβ»ΒΉ * P`, then in fact `x = algebra_map _ _ y` for some `y`.
intros x hx,
have le_one : (Mβ»ΒΉ * P : fractional_ideal Aβ° (fraction_ring A)) β€ 1,
{ rw [β h.inv_mul_eq_one M'_ne],
exact mul_left_mono _ ((coe_ideal_le_coe_ideal (fraction_ring A)).mpr hM.le) },
obtain β¨y, hy, rflβ© := (mem_coe_ideal _).mp (le_one hx),
-- Since `M` is strictly greater than `P`, let `z β M \ P`.
obtain β¨z, hzM, hzpβ© := set_like.exists_of_lt hM,
-- We have `z * y β M * (Mβ»ΒΉ * P) = P`.
have zy_mem := mul_mem_mul (mem_coe_ideal_of_mem Aβ° hzM) hx,
rw [β ring_hom.map_mul, β mul_assoc, h.mul_inv_eq_one M'_ne, one_mul] at zy_mem,
obtain β¨zy, hzy, zy_eqβ© := (mem_coe_ideal Aβ°).mp zy_mem,
rw is_fraction_ring.injective A (fraction_ring A) zy_eq at hzy,
-- But `P` is a prime ideal, so `z β P` implies `y β P`, as desired.
exact mem_coe_ideal_of_mem Aβ° (or.resolve_left (hP.mem_or_mem hzy) hzp)
end
/-- Showing one side of the equivalence between the definitions
`is_dedekind_domain_inv` and `is_dedekind_domain` of Dedekind domains. -/
theorem is_dedekind_domain : is_dedekind_domain A :=
β¨h.is_noetherian_ring, h.dimension_le_one, h.integrally_closedβ©
end is_dedekind_domain_inv
variables [algebra A K] [is_fraction_ring A K]
/-- Specialization of `exists_prime_spectrum_prod_le_and_ne_bot_of_domain` to Dedekind domains:
Let `I : ideal A` be a nonzero ideal, where `A` is a Dedekind domain that is not a field.
Then `exists_prime_spectrum_prod_le_and_ne_bot_of_domain` states we can find a product of prime
ideals that is contained within `I`. This lemma extends that result by making the product minimal:
let `M` be a maximal ideal that contains `I`, then the product including `M` is contained within `I`
and the product excluding `M` is not contained within `I`. -/
lemma exists_multiset_prod_cons_le_and_prod_not_le [is_dedekind_domain A]
(hNF : Β¬ is_field A) {I M : ideal A} (hI0 : I β β₯) (hIM : I β€ M) [hM : M.is_maximal] :
β (Z : multiset (prime_spectrum A)),
(M ::β (Z.map prime_spectrum.as_ideal)).prod β€ I β§
Β¬ (multiset.prod (Z.map prime_spectrum.as_ideal) β€ I) :=
begin
-- Let `Z` be a minimal set of prime ideals such that their product is contained in `J`.
obtain β¨Zβ, hZββ© := prime_spectrum.exists_prime_spectrum_prod_le_and_ne_bot_of_domain hNF hI0,
obtain β¨Z, β¨hZI, hprodZβ©, h_eraseZβ© := multiset.well_founded_lt.has_min
(Ξ» Z, (Z.map prime_spectrum.as_ideal).prod β€ I β§ (Z.map prime_spectrum.as_ideal).prod β β₯)
β¨Zβ, hZββ©,
have hZM : multiset.prod (Z.map prime_spectrum.as_ideal) β€ M := le_trans hZI hIM,
have hZ0 : Z β 0, { rintro rfl, simpa [hM.ne_top] using hZM },
obtain β¨_, hPZ', hPMβ© := (hM.is_prime.multiset_prod_le (mt multiset.map_eq_zero.mp hZ0)).mp hZM,
-- Then in fact there is a `P β Z` with `P β€ M`.
obtain β¨P, hPZ, rflβ© := multiset.mem_map.mp hPZ',
classical,
have := multiset.map_erase prime_spectrum.as_ideal prime_spectrum.ext P Z,
obtain β¨hP0, hZP0β© : P.as_ideal β β₯ β§ ((Z.erase P).map prime_spectrum.as_ideal).prod β β₯,
{ rwa [ne.def, β multiset.cons_erase hPZ', multiset.prod_cons, ideal.mul_eq_bot,
not_or_distrib, β this] at hprodZ },
-- By maximality of `P` and `M`, we have that `P β€ M` implies `P = M`.
have hPM' := (is_dedekind_domain.dimension_le_one _ hP0 P.is_prime).eq_of_le hM.ne_top hPM,
substI hPM',
-- By minimality of `Z`, erasing `P` from `Z` is exactly what we need.
refine β¨Z.erase P, _, _β©,
{ convert hZI,
rw [this, multiset.cons_erase hPZ'] },
{ refine Ξ» h, h_eraseZ (Z.erase P) β¨h, _β© (multiset.erase_lt.mpr hPZ),
exact hZP0 }
end
namespace fractional_ideal
open ideal
lemma exists_not_mem_one_of_ne_bot [is_dedekind_domain A]
(hNF : Β¬ is_field A) {I : ideal A} (hI0 : I β β₯) (hI1 : I β β€) :
β x : K, x β (Iβ»ΒΉ : fractional_ideal Aβ° K) β§ x β (1 : fractional_ideal Aβ° K) :=
begin
-- WLOG, let `I` be maximal.
suffices : β {M : ideal A} (hM : M.is_maximal),
β x : K, x β (Mβ»ΒΉ : fractional_ideal Aβ° K) β§ x β (1 : fractional_ideal Aβ° K),
{ obtain β¨M, hM, hIMβ© : β (M : ideal A), is_maximal M β§ I β€ M := ideal.exists_le_maximal I hI1,
resetI,
have hM0 := (M.bot_lt_of_maximal hNF).ne',
obtain β¨x, hxM, hx1β© := this hM,
refine β¨x, inv_anti_mono _ _ ((coe_ideal_le_coe_ideal _).mpr hIM) hxM, hx1β©;
rw coe_ideal_ne_zero; assumption },
-- Let `a` be a nonzero element of `M` and `J` the ideal generated by `a`.
intros M hM,
resetI,
obtain β¨β¨a, haMβ©, ha0β© := submodule.nonzero_mem_of_bot_lt (M.bot_lt_of_maximal hNF),
replace ha0 : a β 0 := subtype.coe_injective.ne ha0,
let J : ideal A := ideal.span {a},
have hJ0 : J β β₯ := mt ideal.span_singleton_eq_bot.mp ha0,
have hJM : J β€ M := ideal.span_le.mpr (set.singleton_subset_iff.mpr haM),
have hM0 : β₯ < M := M.bot_lt_of_maximal hNF,
-- Then we can find a product of prime (hence maximal) ideals contained in `J`,
-- such that removing element `M` from the product is not contained in `J`.
obtain β¨Z, hle, hnleβ© := exists_multiset_prod_cons_le_and_prod_not_le hNF hJ0 hJM,
-- Choose an element `b` of the product that is not in `J`.
obtain β¨b, hbZ, hbJβ© := set_like.not_le_iff_exists.mp hnle,
have hnz_fa : algebra_map A K a β 0 :=
mt ((injective_iff_map_eq_zero _).mp (is_fraction_ring.injective A K) a) ha0,
have hb0 : algebra_map A K b β 0 :=
mt ((injective_iff_map_eq_zero _).mp (is_fraction_ring.injective A K) b)
(Ξ» h, hbJ $ h.symm βΈ J.zero_mem),
-- Then `b aβ»ΒΉ : K` is in `Mβ»ΒΉ` but not in `1`.
refine β¨algebra_map A K b * (algebra_map A K a)β»ΒΉ, (mem_inv_iff _).mpr _, _β©,
{ exact coe_ideal_ne_zero.mpr hM0.ne' },
{ rintro yβ hyβ,
obtain β¨y, h_Iy, rflβ© := (mem_coe_ideal _).mp hyβ,
rw [mul_comm, β mul_assoc, β ring_hom.map_mul],
have h_yb : y * b β J,
{ apply hle,
rw multiset.prod_cons,
exact submodule.smul_mem_smul h_Iy hbZ },
rw ideal.mem_span_singleton' at h_yb,
rcases h_yb with β¨c, hcβ©,
rw [β hc, ring_hom.map_mul, mul_assoc, mul_inv_cancel hnz_fa, mul_one],
apply coe_mem_one },
{ refine mt (mem_one_iff _).mp _,
rintros β¨x', hβ_absβ©,
rw [β div_eq_mul_inv, eq_div_iff_mul_eq hnz_fa, β ring_hom.map_mul] at hβ_abs,
have := ideal.mem_span_singleton'.mpr β¨x', is_fraction_ring.injective A K hβ_absβ©,
contradiction },
end
lemma one_mem_inv_coe_ideal {I : ideal A} (hI : I β β₯) :
(1 : K) β (I : fractional_ideal Aβ° K)β»ΒΉ :=
begin
rw mem_inv_iff (coe_ideal_ne_zero.mpr hI),
intros y hy,
rw one_mul,
exact coe_ideal_le_one hy,
assumption
end
lemma mul_inv_cancel_of_le_one [h : is_dedekind_domain A]
{I : ideal A} (hI0 : I β β₯) (hI : ((I * Iβ»ΒΉ)β»ΒΉ : fractional_ideal Aβ° K) β€ 1) :
(I * Iβ»ΒΉ : fractional_ideal Aβ° K) = 1 :=
begin
-- Handle a few trivial cases.
by_cases hI1 : I = β€,
{ rw [hI1, coe_ideal_top, one_mul, inv_one] },
by_cases hNF : is_field A,
{ letI := hNF.to_field, rcases hI1 (I.eq_bot_or_top.resolve_left hI0) },
-- We'll show a contradiction with `exists_not_mem_one_of_ne_bot`:
-- `Jβ»ΒΉ = (I * Iβ»ΒΉ)β»ΒΉ` cannot have an element `x β 1`, so it must equal `1`.
obtain β¨J, hJβ© : β (J : ideal A), (J : fractional_ideal Aβ° K) = I * Iβ»ΒΉ :=
le_one_iff_exists_coe_ideal.mp mul_one_div_le_one,
by_cases hJ0 : J = β₯,
{ subst hJ0,
refine absurd _ hI0,
rw [eq_bot_iff, β coe_ideal_le_coe_ideal K, hJ],
exact coe_ideal_le_self_mul_inv K I,
apply_instance },
by_cases hJ1 : J = β€,
{ rw [β hJ, hJ1, coe_ideal_top] },
obtain β¨x, hx, hx1β© : β (x : K),
x β (J : fractional_ideal Aβ° K)β»ΒΉ β§ x β (1 : fractional_ideal Aβ° K) :=
exists_not_mem_one_of_ne_bot hNF hJ0 hJ1,
contrapose! hx1 with h_abs,
rw hJ at hx,
exact hI hx,
end
/-- Nonzero integral ideals in a Dedekind domain are invertible.
We will use this to show that nonzero fractional ideals are invertible,
and finally conclude that fractional ideals in a Dedekind domain form a group with zero.
-/
lemma coe_ideal_mul_inv [h : is_dedekind_domain A] (I : ideal A) (hI0 : I β β₯) :
(I * Iβ»ΒΉ : fractional_ideal Aβ° K) = 1 :=
begin
-- We'll show `1 β€ Jβ»ΒΉ = (I * Iβ»ΒΉ)β»ΒΉ β€ 1`.
apply mul_inv_cancel_of_le_one hI0,
by_cases hJ0 : (I * Iβ»ΒΉ : fractional_ideal Aβ° K) = 0,
{ rw [hJ0, inv_zero'], exact zero_le _ },
intros x hx,
-- In particular, we'll show all `x β Jβ»ΒΉ` are integral.
suffices : x β integral_closure A K,
{ rwa [is_integrally_closed.integral_closure_eq_bot, algebra.mem_bot, set.mem_range,
β mem_one_iff] at this;
assumption },
-- For that, we'll find a subalgebra that is f.g. as a module and contains `x`.
-- `A` is a noetherian ring, so we just need to find a subalgebra between `{x}` and `Iβ»ΒΉ`.
rw mem_integral_closure_iff_mem_fg,
have x_mul_mem : β b β (Iβ»ΒΉ : fractional_ideal Aβ° K), x * b β (Iβ»ΒΉ : fractional_ideal Aβ° K),
{ intros b hb,
rw mem_inv_iff at β’ hx,
swap, { exact coe_ideal_ne_zero.mpr hI0 },
swap, { exact hJ0 },
simp only [mul_assoc, mul_comm b] at β’ hx,
intros y hy,
exact hx _ (mul_mem_mul hy hb) },
-- It turns out the subalgebra consisting of all `p(x)` for `p : A[X]` works.
refine β¨alg_hom.range (polynomial.aeval x : A[X] ββ[A] K),
is_noetherian_submodule.mp (is_noetherian Iβ»ΒΉ) _ (Ξ» y hy, _),
β¨polynomial.X, polynomial.aeval_X xβ©β©,
obtain β¨p, rflβ© := (alg_hom.mem_range _).mp hy,
rw polynomial.aeval_eq_sum_range,
refine submodule.sum_mem _ (Ξ» i hi, submodule.smul_mem _ _ _),
clear hi,
induction i with i ih,
{ rw pow_zero, exact one_mem_inv_coe_ideal hI0 },
{ show x ^ i.succ β (Iβ»ΒΉ : fractional_ideal Aβ° K),
rw pow_succ, exact x_mul_mem _ ih },
end
/-- Nonzero fractional ideals in a Dedekind domain are units.
This is also available as `_root_.mul_inv_cancel`, using the
`comm_group_with_zero` instance defined below.
-/
protected theorem mul_inv_cancel [is_dedekind_domain A]
{I : fractional_ideal Aβ° K} (hne : I β 0) : I * Iβ»ΒΉ = 1 :=
begin
obtain β¨a, J, ha, hJβ© :
β (a : A) (aI : ideal A), a β 0 β§ I = span_singleton Aβ° (algebra_map _ _ a)β»ΒΉ * aI :=
exists_eq_span_singleton_mul I,
suffices hβ : I * (span_singleton Aβ° (algebra_map _ _ a) * Jβ»ΒΉ) = 1,
{ rw mul_inv_cancel_iff,
exact β¨span_singleton Aβ° (algebra_map _ _ a) * Jβ»ΒΉ, hββ© },
subst hJ,
rw [mul_assoc, mul_left_comm (J : fractional_ideal Aβ° K), coe_ideal_mul_inv, mul_one,
span_singleton_mul_span_singleton, inv_mul_cancel, span_singleton_one],
{ exact mt ((injective_iff_map_eq_zero (algebra_map A K)).mp
(is_fraction_ring.injective A K) _) ha },
{ exact coe_ideal_ne_zero.mp (right_ne_zero_of_mul hne) }
end
lemma mul_right_le_iff [is_dedekind_domain A] {J : fractional_ideal Aβ° K}
(hJ : J β 0) : β {I I'}, I * J β€ I' * J β I β€ I' :=
begin
intros I I',
split,
{ intros h, convert mul_right_mono Jβ»ΒΉ h;
rw [mul_assoc, fractional_ideal.mul_inv_cancel hJ, mul_one] },
{ exact Ξ» h, mul_right_mono J h }
end
lemma mul_left_le_iff [is_dedekind_domain A] {J : fractional_ideal Aβ° K}
(hJ : J β 0) {I I'} : J * I β€ J * I' β I β€ I' :=
by convert mul_right_le_iff hJ using 1; simp only [mul_comm]
lemma mul_right_strict_mono [is_dedekind_domain A] {I : fractional_ideal Aβ° K}
(hI : I β 0) : strict_mono (* I) :=
strict_mono_of_le_iff_le (Ξ» _ _, (mul_right_le_iff hI).symm)
lemma mul_left_strict_mono [is_dedekind_domain A] {I : fractional_ideal Aβ° K}
(hI : I β 0) : strict_mono ((*) I) :=
strict_mono_of_le_iff_le (Ξ» _ _, (mul_left_le_iff hI).symm)
/--
This is also available as `_root_.div_eq_mul_inv`, using the
`comm_group_with_zero` instance defined below.
-/
protected lemma div_eq_mul_inv [is_dedekind_domain A] (I J : fractional_ideal Aβ° K) :
I / J = I * Jβ»ΒΉ :=
begin
by_cases hJ : J = 0,
{ rw [hJ, div_zero, inv_zero', mul_zero] },
refine le_antisymm ((mul_right_le_iff hJ).mp _) ((le_div_iff_mul_le hJ).mpr _),
{ rw [mul_assoc, mul_comm Jβ»ΒΉ, fractional_ideal.mul_inv_cancel hJ, mul_one, mul_le],
intros x hx y hy,
rw [mem_div_iff_of_nonzero hJ] at hx,
exact hx y hy },
rw [mul_assoc, mul_comm Jβ»ΒΉ, fractional_ideal.mul_inv_cancel hJ, mul_one],
exact le_refl I
end
end fractional_ideal
/-- `is_dedekind_domain` and `is_dedekind_domain_inv` are equivalent ways
to express that an integral domain is a Dedekind domain. -/
theorem is_dedekind_domain_iff_is_dedekind_domain_inv :
is_dedekind_domain A β is_dedekind_domain_inv A :=
β¨Ξ» h I hI, by exactI fractional_ideal.mul_inv_cancel hI, Ξ» h, h.is_dedekind_domainβ©
end inverse
section is_dedekind_domain
variables {R A} [is_dedekind_domain A] [algebra A K] [is_fraction_ring A K]
open fractional_ideal
open ideal
noncomputable instance fractional_ideal.semifield :
semifield (fractional_ideal Aβ° K) :=
{ inv := Ξ» I, Iβ»ΒΉ,
inv_zero := inv_zero' _,
div := (/),
div_eq_mul_inv := fractional_ideal.div_eq_mul_inv,
mul_inv_cancel := Ξ» I, fractional_ideal.mul_inv_cancel,
.. fractional_ideal.comm_semiring, .. coe_ideal_injective.nontrivial }
/-- Fractional ideals have cancellative multiplication in a Dedekind domain.
Although this instance is a direct consequence of the instance
`fractional_ideal.comm_group_with_zero`, we define this instance to provide
a computable alternative.
-/
instance fractional_ideal.cancel_comm_monoid_with_zero :
cancel_comm_monoid_with_zero (fractional_ideal Aβ° K) :=
{ .. fractional_ideal.comm_semiring, -- Project out the computable fields first.
.. (by apply_instance : cancel_comm_monoid_with_zero (fractional_ideal Aβ° K)) }
instance ideal.cancel_comm_monoid_with_zero :
cancel_comm_monoid_with_zero (ideal A) :=
{ .. ideal.idem_comm_semiring,
.. function.injective.cancel_comm_monoid_with_zero (coe_ideal_hom Aβ° (fraction_ring A))
coe_ideal_injective (ring_hom.map_zero _) (ring_hom.map_one _) (ring_hom.map_mul _)
(ring_hom.map_pow _) }
instance ideal.is_domain :
is_domain (ideal A) :=
{ .. (infer_instance : is_cancel_mul_zero _), .. ideal.nontrivial }
/-- For ideals in a Dedekind domain, to divide is to contain. -/
lemma ideal.dvd_iff_le {I J : ideal A} : (I β£ J) β J β€ I :=
β¨ideal.le_of_dvd,
Ξ» h, begin
by_cases hI : I = β₯,
{ have hJ : J = β₯, { rwa [hI, β eq_bot_iff] at h },
rw [hI, hJ] },
have hI' : (I : fractional_ideal Aβ° (fraction_ring A)) β 0 := coe_ideal_ne_zero.mpr hI,
have : (I : fractional_ideal Aβ° (fraction_ring A))β»ΒΉ * J β€ 1 := le_trans
(mul_left_mono (βI)β»ΒΉ ((coe_ideal_le_coe_ideal _).mpr h))
(le_of_eq (inv_mul_cancel hI')),
obtain β¨H, hHβ© := le_one_iff_exists_coe_ideal.mp this,
use H,
refine coe_ideal_injective
(show (J : fractional_ideal Aβ° (fraction_ring A)) = β(I * H), from _),
rw [coe_ideal_mul, hH, β mul_assoc, mul_inv_cancel hI', one_mul]
endβ©
lemma ideal.dvd_not_unit_iff_lt {I J : ideal A} :
dvd_not_unit I J β J < I :=
β¨Ξ» β¨hI, H, hunit, hmulβ©, lt_of_le_of_ne (ideal.dvd_iff_le.mp β¨H, hmulβ©)
(mt (Ξ» h, have H = 1, from mul_left_cancelβ hI (by rw [β hmul, h, mul_one]),
show is_unit H, from this.symm βΈ is_unit_one) hunit),
Ξ» h, dvd_not_unit_of_dvd_of_not_dvd (ideal.dvd_iff_le.mpr (le_of_lt h))
(mt ideal.dvd_iff_le.mp (not_le_of_lt h))β©
instance : wf_dvd_monoid (ideal A) :=
{ well_founded_dvd_not_unit :=
have well_founded ((>) : ideal A β ideal A β Prop) :=
is_noetherian_iff_well_founded.mp
(is_noetherian_ring_iff.mp is_dedekind_domain.is_noetherian_ring),
by { convert this, ext, rw ideal.dvd_not_unit_iff_lt } }
instance ideal.unique_factorization_monoid :
unique_factorization_monoid (ideal A) :=
{ irreducible_iff_prime := Ξ» P,
β¨Ξ» hirr, β¨hirr.ne_zero, hirr.not_unit, Ξ» I J, begin
have : P.is_maximal,
{ refine β¨β¨mt ideal.is_unit_iff.mpr hirr.not_unit, _β©β©,
intros J hJ,
obtain β¨J_ne, H, hunit, P_eqβ© := ideal.dvd_not_unit_iff_lt.mpr hJ,
exact ideal.is_unit_iff.mp ((hirr.is_unit_or_is_unit P_eq).resolve_right hunit) },
rw [ideal.dvd_iff_le, ideal.dvd_iff_le, ideal.dvd_iff_le,
set_like.le_def, set_like.le_def, set_like.le_def],
contrapose!,
rintros β¨β¨x, x_mem, x_not_memβ©, β¨y, y_mem, y_not_memβ©β©,
exact β¨x * y, ideal.mul_mem_mul x_mem y_mem,
mt this.is_prime.mem_or_mem (not_or x_not_mem y_not_mem)β©,
endβ©,
prime.irreducibleβ©,
.. ideal.wf_dvd_monoid }
instance ideal.normalization_monoid : normalization_monoid (ideal A) :=
normalization_monoid_of_unique_units
@[simp] lemma ideal.dvd_span_singleton {I : ideal A} {x : A} :
I β£ ideal.span {x} β x β I :=
ideal.dvd_iff_le.trans (ideal.span_le.trans set.singleton_subset_iff)
lemma ideal.is_prime_of_prime {P : ideal A} (h : prime P) : is_prime P :=
begin
refine β¨_, Ξ» x y hxy, _β©,
{ unfreezingI { rintro rfl },
rw β ideal.one_eq_top at h,
exact h.not_unit is_unit_one },
{ simp only [β ideal.dvd_span_singleton, β ideal.span_singleton_mul_span_singleton] at β’ hxy,
exact h.dvd_or_dvd hxy }
end
theorem ideal.prime_of_is_prime {P : ideal A} (hP : P β β₯) (h : is_prime P) : prime P :=
begin
refine β¨hP, mt ideal.is_unit_iff.mp h.ne_top, Ξ» I J hIJ, _β©,
simpa only [ideal.dvd_iff_le] using (h.mul_le.mp (ideal.le_of_dvd hIJ)),
end
/-- In a Dedekind domain, the (nonzero) prime elements of the monoid with zero `ideal A`
are exactly the prime ideals. -/
theorem ideal.prime_iff_is_prime {P : ideal A} (hP : P β β₯) :
prime P β is_prime P :=
β¨ideal.is_prime_of_prime, ideal.prime_of_is_prime hPβ©
/-- In a Dedekind domain, the the prime ideals are the zero ideal together with the prime elements
of the monoid with zero `ideal A`. -/
theorem ideal.is_prime_iff_bot_or_prime {P : ideal A} :
is_prime P β P = β₯ β¨ prime P :=
β¨Ξ» hp, (eq_or_ne P β₯).imp_right $ Ξ» hp0, (ideal.prime_of_is_prime hp0 hp),
Ξ» hp, hp.elim (Ξ» h, h.symm βΈ ideal.bot_prime) ideal.is_prime_of_primeβ©
lemma ideal.strict_anti_pow (I : ideal A) (hI0 : I β β₯) (hI1 : I β β€) :
strict_anti ((^) I : β β ideal A) :=
strict_anti_nat_of_succ_lt $ Ξ» e, ideal.dvd_not_unit_iff_lt.mp
β¨pow_ne_zero _ hI0, I, mt is_unit_iff.mp hI1, pow_succ' I eβ©
lemma ideal.pow_lt_self (I : ideal A) (hI0 : I β β₯) (hI1 : I β β€) (e : β) (he : 2 β€ e) : I^e < I :=
by convert I.strict_anti_pow hI0 hI1 he; rw pow_one
lemma ideal.exists_mem_pow_not_mem_pow_succ (I : ideal A) (hI0 : I β β₯) (hI1 : I β β€) (e : β) :
β x β I^e, x β I^(e+1) :=
set_like.exists_of_lt (I.strict_anti_pow hI0 hI1 e.lt_succ_self)
open unique_factorization_monoid
lemma ideal.eq_prime_pow_of_succ_lt_of_le {P I : ideal A} [P_prime : P.is_prime] (hP : P β β₯)
{i : β} (hlt : P ^ (i + 1) < I) (hle : I β€ P ^ i) :
I = P ^ i :=
begin
letI := classical.dec_eq (ideal A),
refine le_antisymm hle _,
have P_prime' := ideal.prime_of_is_prime hP P_prime,
have : I β β₯ := (lt_of_le_of_lt bot_le hlt).ne',
have := pow_ne_zero i hP,
have := pow_ne_zero (i + 1) hP,
rw [β ideal.dvd_not_unit_iff_lt, dvd_not_unit_iff_normalized_factors_lt_normalized_factors,
normalized_factors_pow, normalized_factors_irreducible P_prime'.irreducible,
multiset.nsmul_singleton, multiset.lt_replicate_succ]
at hlt,
rw [β ideal.dvd_iff_le, dvd_iff_normalized_factors_le_normalized_factors, normalized_factors_pow,
normalized_factors_irreducible P_prime'.irreducible, multiset.nsmul_singleton],
all_goals { assumption }
end
lemma ideal.pow_succ_lt_pow {P : ideal A} [P_prime : P.is_prime] (hP : P β β₯)
(i : β) :
P ^ (i + 1) < P ^ i :=
lt_of_le_of_ne (ideal.pow_le_pow (nat.le_succ _))
(mt (pow_eq_pow_iff hP (mt ideal.is_unit_iff.mp P_prime.ne_top)).mp i.succ_ne_self)
lemma associates.le_singleton_iff (x : A) (n : β) (I : ideal A) :
associates.mk I^n β€ associates.mk (ideal.span {x}) β x β I^n :=
begin
rw [β associates.dvd_eq_le, β associates.mk_pow, associates.mk_dvd_mk, ideal.dvd_span_singleton],
end
open fractional_ideal
variables {A K}
/-- Strengthening of `is_localization.exist_integer_multiples`:
Let `J β β€` be an ideal in a Dedekind domain `A`, and `f β 0` a finite collection
of elements of `K = Frac(A)`, then we can multiply the elements of `f` by some `a : K`
to find a collection of elements of `A` that is not completely contained in `J`. -/
lemma ideal.exist_integer_multiples_not_mem
{J : ideal A} (hJ : J β β€) {ΞΉ : Type*} (s : finset ΞΉ) (f : ΞΉ β K)
{j} (hjs : j β s) (hjf : f j β 0) :
β a : K, (β i β s, is_localization.is_integer A (a * f i)) β§
β i β s, (a * f i) β (J : fractional_ideal Aβ° K) :=
begin
-- Consider the fractional ideal `I` spanned by the `f`s.
let I : fractional_ideal Aβ° K := span_finset A s f,
have hI0 : I β 0 := span_finset_ne_zero.mpr β¨j, hjs, hjfβ©,
-- We claim the multiplier `a` we're looking for is in `Iβ»ΒΉ \ (J / I)`.
suffices : βJ / I < Iβ»ΒΉ,
{ obtain β¨_, a, hI, hpIβ© := set_like.lt_iff_le_and_exists.mp this,
rw mem_inv_iff hI0 at hI,
refine β¨a, Ξ» i hi, _, _β©,
-- By definition, `a β Iβ»ΒΉ` multiplies elements of `I` into elements of `1`,
-- in other words, `a * f i` is an integer.
{ exact (mem_one_iff _).mp (hI (f i)
(submodule.subset_span (set.mem_image_of_mem f hi))) },
{ contrapose! hpI,
-- And if all `a`-multiples of `I` are an element of `J`,
-- then `a` is actually an element of `J / I`, contradiction.
refine (mem_div_iff_of_nonzero hI0).mpr (Ξ» y hy, submodule.span_induction hy _ _ _ _),
{ rintros _ β¨i, hi, rflβ©, exact hpI i hi },
{ rw mul_zero, exact submodule.zero_mem _ },
{ intros x y hx hy, rw mul_add, exact submodule.add_mem _ hx hy },
{ intros b x hx, rw mul_smul_comm, exact submodule.smul_mem _ b hx } } },
-- To show the inclusion of `J / I` into `Iβ»ΒΉ = 1 / I`, note that `J < I`.
calc βJ / I = βJ * Iβ»ΒΉ : div_eq_mul_inv βJ I
... < 1 * Iβ»ΒΉ : mul_right_strict_mono (inv_ne_zero hI0) _
... = Iβ»ΒΉ : one_mul _,
{ rw [β coe_ideal_top],
-- And multiplying by `Iβ»ΒΉ` is indeed strictly monotone.
exact strict_mono_of_le_iff_le (Ξ» _ _, (coe_ideal_le_coe_ideal K).symm)
(lt_top_iff_ne_top.mpr hJ) },
end
section gcd
namespace ideal
/-! ### GCD and LCM of ideals in a Dedekind domain
We show that the gcd of two ideals in a Dedekind domain is just their supremum,
and the lcm is their infimum, and use this to instantiate `normalized_gcd_monoid (ideal A)`.
-/
@[simp] lemma sup_mul_inf (I J : ideal A) : (I β J) * (I β J) = I * J :=
begin
letI := classical.dec_eq (ideal A),
letI := classical.dec_eq (associates (ideal A)),
letI := unique_factorization_monoid.to_normalized_gcd_monoid (ideal A),
have hgcd : gcd I J = I β J,
{ rw [gcd_eq_normalize _ _, normalize_eq],
{ rw [dvd_iff_le, sup_le_iff, β dvd_iff_le, β dvd_iff_le],
exact β¨gcd_dvd_left _ _, gcd_dvd_right _ _β© },
{ rw [dvd_gcd_iff, dvd_iff_le, dvd_iff_le],
simp } },
have hlcm : lcm I J = I β J,
{ rw [lcm_eq_normalize _ _, normalize_eq],
{ rw [lcm_dvd_iff, dvd_iff_le, dvd_iff_le],
simp },
{ rw [dvd_iff_le, le_inf_iff, β dvd_iff_le, β dvd_iff_le],
exact β¨dvd_lcm_left _ _, dvd_lcm_right _ _β© } },
rw [β hgcd, β hlcm, associated_iff_eq.mp (gcd_mul_lcm _ _)],
apply_instance
end
/-- Ideals in a Dedekind domain have gcd and lcm operators that (trivially) are compatible with
the normalization operator. -/
instance : normalized_gcd_monoid (ideal A) :=
{ gcd := (β),
gcd_dvd_left := Ξ» _ _, by simpa only [dvd_iff_le] using le_sup_left,
gcd_dvd_right := Ξ» _ _, by simpa only [dvd_iff_le] using le_sup_right,
dvd_gcd := Ξ» _ _ _, by simpa only [dvd_iff_le] using sup_le,
lcm := (β),
lcm_zero_left := Ξ» _, by simp only [zero_eq_bot, bot_inf_eq],
lcm_zero_right := Ξ» _, by simp only [zero_eq_bot, inf_bot_eq],
gcd_mul_lcm := Ξ» _ _, by rw [associated_iff_eq, sup_mul_inf],
normalize_gcd := Ξ» _ _, normalize_eq _,
normalize_lcm := Ξ» _ _, normalize_eq _,
.. ideal.normalization_monoid }
-- In fact, any lawful gcd and lcm would equal sup and inf respectively.
@[simp] lemma gcd_eq_sup (I J : ideal A) : gcd I J = I β J := rfl
@[simp]
lemma lcm_eq_inf (I J : ideal A) : lcm I J = I β J := rfl
lemma inf_eq_mul_of_coprime {I J : ideal A} (coprime : I β J = β€) :
I β J = I * J :=
by rw [β associated_iff_eq.mp (gcd_mul_lcm I J), lcm_eq_inf I J, gcd_eq_sup, coprime, top_mul]
end ideal
end gcd
end is_dedekind_domain
section is_dedekind_domain
variables {T : Type*} [comm_ring T] [is_domain T] [is_dedekind_domain T] {I J : ideal T}
open_locale classical
open multiset unique_factorization_monoid ideal
lemma prod_normalized_factors_eq_self (hI : I β β₯) : (normalized_factors I).prod = I :=
associated_iff_eq.1 (normalized_factors_prod hI)
lemma count_le_of_ideal_ge {I J : ideal T} (h : I β€ J) (hI : I β β₯) (K : ideal T) :
count K (normalized_factors J) β€ count K (normalized_factors I) :=
le_iff_count.1 ((dvd_iff_normalized_factors_le_normalized_factors (ne_bot_of_le_ne_bot hI h) hI).1
(dvd_iff_le.2 h)) _
lemma sup_eq_prod_inf_factors (hI : I β β₯) (hJ : J β β₯) :
I β J = (normalized_factors I β© normalized_factors J).prod :=
begin
have H : normalized_factors (normalized_factors I β© normalized_factors J).prod =
normalized_factors I β© normalized_factors J,
{ apply normalized_factors_prod_of_prime,
intros p hp,
rw mem_inter at hp,
exact prime_of_normalized_factor p hp.left },
have := (multiset.prod_ne_zero_of_prime (normalized_factors I β© normalized_factors J)
(Ξ» _ h, prime_of_normalized_factor _ (multiset.mem_inter.1 h).1)),
apply le_antisymm,
{ rw [sup_le_iff, β dvd_iff_le, β dvd_iff_le],
split,
{ rw [dvd_iff_normalized_factors_le_normalized_factors this hI, H],
exact inf_le_left },
{ rw [dvd_iff_normalized_factors_le_normalized_factors this hJ, H],
exact inf_le_right } },
{ rw [β dvd_iff_le, dvd_iff_normalized_factors_le_normalized_factors,
normalized_factors_prod_of_prime, le_iff_count],
{ intro a,
rw multiset.count_inter,
exact le_min (count_le_of_ideal_ge le_sup_left hI a)
(count_le_of_ideal_ge le_sup_right hJ a) },
{ intros p hp,
rw mem_inter at hp,
exact prime_of_normalized_factor p hp.left },
{ exact ne_bot_of_le_ne_bot hI le_sup_left },
{ exact this } },
end
lemma irreducible_pow_sup (hI : I β β₯) (hJ : irreducible J) (n : β) :
J^n β I = J^(min ((normalized_factors I).count J) n) :=
by rw [sup_eq_prod_inf_factors (pow_ne_zero n hJ.ne_zero) hI, min_comm,
normalized_factors_of_irreducible_pow hJ, normalize_eq J, replicate_inter, prod_replicate]
lemma irreducible_pow_sup_of_le (hJ : irreducible J) (n : β)
(hn : βn β€ multiplicity J I) : J^n β I = J^n :=
begin
by_cases hI : I = β₯,
{ simp [*] at *, },
rw [irreducible_pow_sup hI hJ, min_eq_right],
rwa [multiplicity_eq_count_normalized_factors hJ hI, part_enat.coe_le_coe, normalize_eq J] at hn
end
lemma irreducible_pow_sup_of_ge (hI : I β β₯) (hJ : irreducible J) (n : β)
(hn : multiplicity J I β€ n) : J^n β I = J ^ (multiplicity J I).get (part_enat.dom_of_le_coe hn) :=
begin
rw [irreducible_pow_sup hI hJ, min_eq_left],
congr,
{ rw [β part_enat.coe_inj, part_enat.coe_get, multiplicity_eq_count_normalized_factors hJ hI,
normalize_eq J] },
{ rwa [multiplicity_eq_count_normalized_factors hJ hI, part_enat.coe_le_coe, normalize_eq J]
at hn }
end
end is_dedekind_domain
/-!
### Height one spectrum of a Dedekind domain
If `R` is a Dedekind domain of Krull dimension 1, the maximal ideals of `R` are exactly its nonzero
prime ideals.
We define `height_one_spectrum` and provide lemmas to recover the facts that prime ideals of height
one are prime and irreducible.
-/
namespace is_dedekind_domain
variables [is_domain R] [is_dedekind_domain R]
/-- The height one prime spectrum of a Dedekind domain `R` is the type of nonzero prime ideals of
`R`. Note that this equals the maximal spectrum if `R` has Krull dimension 1. -/
@[ext, nolint has_nonempty_instance unused_arguments]
structure height_one_spectrum :=
(as_ideal : ideal R)
(is_prime : as_ideal.is_prime)
(ne_bot : as_ideal β β₯)
attribute [instance] height_one_spectrum.is_prime
variables (v : height_one_spectrum R) {R}
namespace height_one_spectrum
instance is_maximal : v.as_ideal.is_maximal := dimension_le_one v.as_ideal v.ne_bot v.is_prime
lemma prime : prime v.as_ideal := ideal.prime_of_is_prime v.ne_bot v.is_prime
lemma irreducible : irreducible v.as_ideal :=
unique_factorization_monoid.irreducible_iff_prime.mpr v.prime
lemma associates_irreducible : _root_.irreducible $ associates.mk v.as_ideal :=
(associates.irreducible_mk _).mpr v.irreducible
/-- An equivalence between the height one and maximal spectra for rings of Krull dimension 1. -/
def equiv_maximal_spectrum (hR : Β¬is_field R) : height_one_spectrum R β maximal_spectrum R :=
{ to_fun := Ξ» v, β¨v.as_ideal, dimension_le_one v.as_ideal v.ne_bot v.is_primeβ©,
inv_fun := Ξ» v,
β¨v.as_ideal, v.is_maximal.is_prime, ring.ne_bot_of_is_maximal_of_not_is_field v.is_maximal hRβ©,
left_inv := Ξ» β¨_, _, _β©, rfl,
right_inv := Ξ» β¨_, _β©, rfl }
variables (R K)
/-- A Dedekind domain is equal to the intersection of its localizations at all its height one
non-zero prime ideals viewed as subalgebras of its field of fractions. -/
theorem infi_localization_eq_bot [algebra R K] [hK : is_fraction_ring R K] :
(β¨
v : height_one_spectrum R,
localization.subalgebra.of_field K _ v.as_ideal.prime_compl_le_non_zero_divisors) = β₯ :=
begin
ext x,
rw [algebra.mem_infi],
split,
by_cases hR : is_field R,
{ rcases function.bijective_iff_has_inverse.mp
(is_field.localization_map_bijective (flip non_zero_divisors.ne_zero rfl : 0 β Rβ°) hR)
with β¨algebra_map_inv, _, algebra_map_right_invβ©,
exact Ξ» _, algebra.mem_bot.mpr β¨algebra_map_inv x, algebra_map_right_inv xβ©,
exact hK },
all_goals { rw [β maximal_spectrum.infi_localization_eq_bot, algebra.mem_infi] },
{ exact Ξ» hx β¨v, hvβ©, hx ((equiv_maximal_spectrum hR).symm β¨v, hvβ©) },
{ exact Ξ» hx β¨v, hv, hbotβ©, hx β¨v, dimension_le_one v hbot hvβ© }
end
end height_one_spectrum
end is_dedekind_domain
section
open ideal
variables {R} {A} [is_dedekind_domain A] {I : ideal R} {J : ideal A}
/-- The map from ideals of `R` dividing `I` to the ideals of `A` dividing `J` induced by
a homomorphism `f : R/I β+* A/J` -/
@[simps]
def ideal_factors_fun_of_quot_hom {f : R β§Έ I β+* A β§Έ J} (hf : function.surjective f ) :
{p : ideal R | p β£ I} βo {p : ideal A | p β£ J} :=
{ to_fun := Ξ» X, β¨comap J^.quotient.mk (map f (map I^.quotient.mk X)),
begin
have : (J^.quotient.mk).ker β€ comap J^.quotient.mk (map f (map I^.quotient.mk X)),
{ exact ker_le_comap J^.quotient.mk },
rw mk_ker at this,
exact dvd_iff_le.mpr this,
end β©,
monotone' :=
begin
rintros β¨X, hXβ© β¨Y, hYβ© h,
rw [β subtype.coe_le_coe, subtype.coe_mk, subtype.coe_mk] at h β’,
rw [subtype.coe_mk, comap_le_comap_iff_of_surjective J^.quotient.mk quotient.mk_surjective,
map_le_iff_le_comap, subtype.coe_mk, comap_map_of_surjective _ hf (map I^.quotient.mk Y)],
suffices : map I^.quotient.mk X β€ map I^.quotient.mk Y,
{ exact le_sup_of_le_left this },
rwa [map_le_iff_le_comap, comap_map_of_surjective I^.quotient.mk quotient.mk_surjective,
β ring_hom.ker_eq_comap_bot, mk_ker, sup_eq_left.mpr $ le_of_dvd hY],
end }
@[simp]
lemma ideal_factors_fun_of_quot_hom_id :
ideal_factors_fun_of_quot_hom (ring_hom.id (A β§Έ J)).is_surjective = order_hom.id :=
order_hom.ext _ _ (funext $ Ξ» X, by simp only [ideal_factors_fun_of_quot_hom, map_id,
order_hom.coe_fun_mk, order_hom.id_coe, id.def, comap_map_of_surjective J^.quotient.mk
quotient.mk_surjective, β ring_hom.ker_eq_comap_bot J^.quotient.mk, mk_ker, sup_eq_left.mpr
(dvd_iff_le.mp X.prop), subtype.coe_eta] )
variables {B : Type*} [comm_ring B] [is_domain B] [is_dedekind_domain B] {L : ideal B}
lemma ideal_factors_fun_of_quot_hom_comp {f : R β§Έ I β+* A β§Έ J} {g : A β§Έ J β+* B β§Έ L}
(hf : function.surjective f) (hg : function.surjective g) :
(ideal_factors_fun_of_quot_hom hg).comp (ideal_factors_fun_of_quot_hom hf)
= ideal_factors_fun_of_quot_hom (show function.surjective (g.comp f), from hg.comp hf) :=
begin
refine order_hom.ext _ _ (funext $ Ξ» x, _),
rw [ideal_factors_fun_of_quot_hom, ideal_factors_fun_of_quot_hom, order_hom.comp_coe,
order_hom.coe_fun_mk, order_hom.coe_fun_mk, function.comp_app,
ideal_factors_fun_of_quot_hom, order_hom.coe_fun_mk, subtype.mk_eq_mk, subtype.coe_mk,
map_comap_of_surjective J^.quotient.mk quotient.mk_surjective, map_map],
end
variables [is_domain R] [is_dedekind_domain R] (f : R β§Έ I β+* A β§Έ J)
/-- The bijection between ideals of `R` dividing `I` and the ideals of `A` dividing `J` induced by
an isomorphism `f : R/I β
A/J`. -/
@[simps]
def ideal_factors_equiv_of_quot_equiv : {p : ideal R | p β£ I} βo {p : ideal A | p β£ J} :=
order_iso.of_hom_inv
(ideal_factors_fun_of_quot_hom (show function.surjective
(f : R β§ΈI β+* A β§Έ J), from f.surjective))
(ideal_factors_fun_of_quot_hom (show function.surjective
(f.symm : A β§ΈJ β+* R β§Έ I), from f.symm.surjective))
(by simp only [β ideal_factors_fun_of_quot_hom_id, order_hom.coe_eq, order_hom.coe_eq,
ideal_factors_fun_of_quot_hom_comp, β ring_equiv.to_ring_hom_eq_coe,
β ring_equiv.to_ring_hom_eq_coe, β ring_equiv.to_ring_hom_trans, ring_equiv.symm_trans_self,
ring_equiv.to_ring_hom_refl])
(by simp only [β ideal_factors_fun_of_quot_hom_id, order_hom.coe_eq, order_hom.coe_eq,
ideal_factors_fun_of_quot_hom_comp, β ring_equiv.to_ring_hom_eq_coe,
β ring_equiv.to_ring_hom_eq_coe, β ring_equiv.to_ring_hom_trans, ring_equiv.self_trans_symm,
ring_equiv.to_ring_hom_refl])
lemma ideal_factors_equiv_of_quot_equiv_symm :
(ideal_factors_equiv_of_quot_equiv f).symm = ideal_factors_equiv_of_quot_equiv f.symm := rfl
lemma ideal_factors_equiv_of_quot_equiv_is_dvd_iso {L M : ideal R} (hL : L β£ I) (hM : M β£ I) :
(ideal_factors_equiv_of_quot_equiv f β¨L, hLβ© : ideal A) β£
ideal_factors_equiv_of_quot_equiv f β¨M, hMβ© β L β£ M :=
begin
suffices : ideal_factors_equiv_of_quot_equiv f β¨M, hMβ© β€
ideal_factors_equiv_of_quot_equiv f β¨L, hLβ© β (β¨M, hMβ© : {p : ideal R | p β£ I}) β€ β¨L, hLβ©,
{ rw [dvd_iff_le, dvd_iff_le, subtype.coe_le_coe, this, subtype.mk_le_mk] },
exact (ideal_factors_equiv_of_quot_equiv f).le_iff_le,
end
open unique_factorization_monoid
variables [decidable_eq (ideal R)] [decidable_eq (ideal A)]
lemma ideal_factors_equiv_of_quot_equiv_mem_normalized_factors_of_mem_normalized_factors
(hJ : J β β₯) {L : ideal R} (hL : L β normalized_factors I) :
β(ideal_factors_equiv_of_quot_equiv f
β¨L, dvd_of_mem_normalized_factors hLβ©) β normalized_factors J :=
begin
by_cases hI : I = β₯,
{ exfalso,
rw [hI, bot_eq_zero, normalized_factors_zero, β multiset.empty_eq_zero] at hL,
exact hL, },
{ apply mem_normalized_factors_factor_dvd_iso_of_mem_normalized_factors hI hJ hL _,
rintros β¨l, hlβ© β¨l', hl'β©,
rw [subtype.coe_mk, subtype.coe_mk],
apply ideal_factors_equiv_of_quot_equiv_is_dvd_iso f }
end
/-- The bijection between the sets of normalized factors of I and J induced by a ring
isomorphism `f : R/I β
A/J`. -/
@[simps apply]
def normalized_factors_equiv_of_quot_equiv (hI : I β β₯) (hJ : J β β₯) :
{L : ideal R | L β normalized_factors I } β {M : ideal A | M β normalized_factors J } :=
{ to_fun := Ξ» j, β¨ideal_factors_equiv_of_quot_equiv f β¨βj, dvd_of_mem_normalized_factors j.propβ©,
ideal_factors_equiv_of_quot_equiv_mem_normalized_factors_of_mem_normalized_factors f hJ j.propβ©,
inv_fun := Ξ» j, β¨(ideal_factors_equiv_of_quot_equiv f).symm
β¨βj, dvd_of_mem_normalized_factors j.propβ©, by { rw ideal_factors_equiv_of_quot_equiv_symm,
exact ideal_factors_equiv_of_quot_equiv_mem_normalized_factors_of_mem_normalized_factors
f.symm hI j.prop} β©,
left_inv := Ξ» β¨j, hjβ©, by simp,
right_inv := Ξ» β¨j, hjβ©, by simp }
@[simp]
lemma normalized_factors_equiv_of_quot_equiv_symm (hI : I β β₯) (hJ : J β β₯) :
(normalized_factors_equiv_of_quot_equiv f hI hJ).symm =
normalized_factors_equiv_of_quot_equiv f.symm hJ hI :=
rfl
variable [decidable_rel ((β£) : ideal R β ideal R β Prop)]
variable [decidable_rel ((β£) : ideal A β ideal A β Prop)]
/-- The map `normalized_factors_equiv_of_quot_equiv` preserves multiplicities. -/
lemma normalized_factors_equiv_of_quot_equiv_multiplicity_eq_multiplicity (hI : I β β₯) (hJ : J β β₯)
(L : ideal R) (hL : L β normalized_factors I) :
multiplicity β(normalized_factors_equiv_of_quot_equiv f hI hJ β¨L, hLβ©) J = multiplicity L I :=
begin
rw [normalized_factors_equiv_of_quot_equiv, equiv.coe_fn_mk, subtype.coe_mk],
exact multiplicity_factor_dvd_iso_eq_multiplicity_of_mem_normalized_factor hI hJ hL
(Ξ» β¨l, hlβ© β¨l', hl'β©, ideal_factors_equiv_of_quot_equiv_is_dvd_iso f hl hl'),
end
end
section chinese_remainder
open ideal unique_factorization_monoid
open_locale big_operators
variables {R}
lemma ring.dimension_le_one.prime_le_prime_iff_eq (h : ring.dimension_le_one R)
{P Q : ideal R} [hP : P.is_prime] [hQ : Q.is_prime] (hP0 : P β β₯) :
P β€ Q β P = Q :=
β¨(h P hP0 hP).eq_of_le hQ.ne_top, eq.leβ©
lemma ideal.coprime_of_no_prime_ge {I J : ideal R} (h : β P, I β€ P β J β€ P β Β¬ is_prime P) :
I β J = β€ :=
begin
by_contra hIJ,
obtain β¨P, hP, hIJβ© := ideal.exists_le_maximal _ hIJ,
exact h P (le_trans le_sup_left hIJ) (le_trans le_sup_right hIJ) hP.is_prime
end
section dedekind_domain
variables {R} [is_domain R] [is_dedekind_domain R]
lemma ideal.is_prime.mul_mem_pow (I : ideal R) [hI : I.is_prime] {a b : R} {n : β}
(h : a * b β I^n) : a β I β¨ b β I^n :=
begin
cases n, { simp },
by_cases hI0 : I = β₯, { simpa [pow_succ, hI0] using h },
simp only [β submodule.span_singleton_le_iff_mem, ideal.submodule_span_eq, β ideal.dvd_iff_le,
β ideal.span_singleton_mul_span_singleton] at h β’,
by_cases ha : I β£ span {a},
{ exact or.inl ha },
rw mul_comm at h,
exact or.inr (prime.pow_dvd_of_dvd_mul_right ((ideal.prime_iff_is_prime hI0).mpr hI) _ ha h),
end
section
open_locale classical
lemma ideal.count_normalized_factors_eq {p x : ideal R} [hp : p.is_prime] {n : β}
(hle : x β€ p^n) (hlt : Β¬ (x β€ p^(n+1))) :
(normalized_factors x).count p = n :=
count_normalized_factors_eq'
((ideal.is_prime_iff_bot_or_prime.mp hp).imp_right prime.irreducible)
(by { haveI : unique (ideal R)Λ£ := ideal.unique_units, apply normalize_eq })
(by convert ideal.dvd_iff_le.mpr hle) (by convert mt ideal.le_of_dvd hlt)
/- Warning: even though a pure term-mode proof typechecks (the `by convert` can simply be
removed), it's slower to the point of a possible timeout. -/
end
lemma ideal.le_mul_of_no_prime_factors
{I J K : ideal R} (coprime : β P, J β€ P β K β€ P β Β¬ is_prime P) (hJ : I β€ J) (hK : I β€ K) :
I β€ J * K :=
begin
simp only [β ideal.dvd_iff_le] at coprime hJ hK β’,
by_cases hJ0 : J = 0,
{ simpa only [hJ0, zero_mul] using hJ },
obtain β¨I', rflβ© := hK,
rw mul_comm,
exact mul_dvd_mul_left K
(unique_factorization_monoid.dvd_of_dvd_mul_right_of_no_prime_factors hJ0
(Ξ» P hPJ hPK, mt ideal.is_prime_of_prime (coprime P hPJ hPK))
hJ)
end
lemma ideal.le_of_pow_le_prime {I P : ideal R} [hP : P.is_prime] {n : β} (h : I^n β€ P) : I β€ P :=
begin
by_cases hP0 : P = β₯,
{ simp only [hP0, le_bot_iff] at β’ h,
exact pow_eq_zero h },
rw β ideal.dvd_iff_le at β’ h,
exact ((ideal.prime_iff_is_prime hP0).mpr hP).dvd_of_dvd_pow h
end
lemma ideal.pow_le_prime_iff {I P : ideal R} [hP : P.is_prime] {n : β} (hn : n β 0) :
I^n β€ P β I β€ P :=
β¨ideal.le_of_pow_le_prime, Ξ» h, trans (ideal.pow_le_self hn) hβ©
lemma ideal.prod_le_prime {ΞΉ : Type*} {s : finset ΞΉ} {f : ΞΉ β ideal R} {P : ideal R}
[hP : P.is_prime] :
β i in s, f i β€ P β β i β s, f i β€ P :=
begin
by_cases hP0 : P = β₯,
{ simp only [hP0, le_bot_iff],
rw [β ideal.zero_eq_bot, finset.prod_eq_zero_iff] },
simp only [β ideal.dvd_iff_le],
exact ((ideal.prime_iff_is_prime hP0).mpr hP).dvd_finset_prod_iff _
end
/-- The intersection of distinct prime powers in a Dedekind domain is the product of these
prime powers. -/
lemma is_dedekind_domain.inf_prime_pow_eq_prod {ΞΉ : Type*}
(s : finset ΞΉ) (f : ΞΉ β ideal R) (e : ΞΉ β β)
(prime : β i β s, prime (f i)) (coprime : β i j β s, i β j β f i β f j) :
s.inf (Ξ» i, f i ^ e i) = β i in s, f i ^ e i :=
begin
letI := classical.dec_eq ΞΉ,
revert prime coprime,
refine s.induction _ _,
{ simp },
intros a s ha ih prime coprime,
specialize ih (Ξ» i hi, prime i (finset.mem_insert_of_mem hi))
(Ξ» i hi j hj, coprime i (finset.mem_insert_of_mem hi) j (finset.mem_insert_of_mem hj)),
rw [finset.inf_insert, finset.prod_insert ha, ih],
refine le_antisymm (ideal.le_mul_of_no_prime_factors _ inf_le_left inf_le_right) ideal.mul_le_inf,
intros P hPa hPs hPp,
haveI := hPp,
obtain β¨b, hb, hPbβ© := ideal.prod_le_prime.mp hPs,
haveI := ideal.is_prime_of_prime (prime a (finset.mem_insert_self a s)),
haveI := ideal.is_prime_of_prime (prime b (finset.mem_insert_of_mem hb)),
refine coprime a (finset.mem_insert_self a s) b (finset.mem_insert_of_mem hb) _
(((is_dedekind_domain.dimension_le_one.prime_le_prime_iff_eq _).mp
(ideal.le_of_pow_le_prime hPa)).trans
((is_dedekind_domain.dimension_le_one.prime_le_prime_iff_eq _).mp
(ideal.le_of_pow_le_prime hPb)).symm),
{ unfreezingI { rintro rfl }, contradiction },
{ exact (prime a (finset.mem_insert_self a s)).ne_zero },
{ exact (prime b (finset.mem_insert_of_mem hb)).ne_zero },
end
/-- **Chinese remainder theorem** for a Dedekind domain: if the ideal `I` factors as
`β i, P i ^ e i`, then `R β§Έ I` factors as `Ξ i, R β§Έ (P i ^ e i)`. -/
noncomputable def is_dedekind_domain.quotient_equiv_pi_of_prod_eq {ΞΉ : Type*} [fintype ΞΉ]
(I : ideal R) (P : ΞΉ β ideal R) (e : ΞΉ β β)
(prime : β i, prime (P i)) (coprime : β i j, i β j β P i β P j) (prod_eq : (β i, P i ^ e i) = I) :
R β§Έ I β+* Ξ i, R β§Έ (P i ^ e i) :=
(ideal.quot_equiv_of_eq (by { simp only [β prod_eq, finset.inf_eq_infi, finset.mem_univ, cinfi_pos,
β is_dedekind_domain.inf_prime_pow_eq_prod _ _ _ (Ξ» i _, prime i) (Ξ» i _ j _, coprime i j)] }))
.trans $
ideal.quotient_inf_ring_equiv_pi_quotient _ (Ξ» i j hij, ideal.coprime_of_no_prime_ge (begin
intros P hPi hPj hPp,
haveI := hPp,
haveI := ideal.is_prime_of_prime (prime i), haveI := ideal.is_prime_of_prime (prime j),
exact coprime i j hij
(((is_dedekind_domain.dimension_le_one.prime_le_prime_iff_eq (prime i).ne_zero).mp
(ideal.le_of_pow_le_prime hPi)).trans
((is_dedekind_domain.dimension_le_one.prime_le_prime_iff_eq (prime j).ne_zero).mp
(ideal.le_of_pow_le_prime hPj)).symm)
end))
open_locale classical
/-- **Chinese remainder theorem** for a Dedekind domain: `R β§Έ I` factors as `Ξ i, R β§Έ (P i ^ e i)`,
where `P i` ranges over the prime factors of `I` and `e i` over the multiplicities. -/
noncomputable def is_dedekind_domain.quotient_equiv_pi_factors {I : ideal R} (hI : I β β₯) :
R β§Έ I β+* Ξ (P : (factors I).to_finset), R β§Έ ((P : ideal R) ^ (factors I).count P) :=
is_dedekind_domain.quotient_equiv_pi_of_prod_eq _ _ _
(Ξ» (P : (factors I).to_finset), prime_of_factor _ (multiset.mem_to_finset.mp P.prop))
(Ξ» i j hij, subtype.coe_injective.ne hij)
(calc β (P : (factors I).to_finset), (P : ideal R) ^ (factors I).count (P : ideal R)
= β P in (factors I).to_finset, P ^ (factors I).count P
: (factors I).to_finset.prod_coe_sort (Ξ» P, P ^ (factors I).count P)
... = ((factors I).map (Ξ» P, P)).prod : (finset.prod_multiset_map_count (factors I) id).symm
... = (factors I).prod : by rw multiset.map_id'
... = I : (@associated_iff_eq (ideal R) _ ideal.unique_units _ _).mp (factors_prod hI))
@[simp] lemma is_dedekind_domain.quotient_equiv_pi_factors_mk {I : ideal R} (hI : I β β₯)
(x : R) : is_dedekind_domain.quotient_equiv_pi_factors hI (ideal.quotient.mk I x) =
Ξ» P, ideal.quotient.mk _ x :=
rfl
/-- **Chinese remainder theorem**, specialized to two ideals. -/
noncomputable def ideal.quotient_mul_equiv_quotient_prod (I J : ideal R)
(coprime : I β J = β€) :
(R β§Έ (I * J)) β+* (R β§Έ I) Γ R β§Έ J :=
ring_equiv.trans
(ideal.quot_equiv_of_eq (inf_eq_mul_of_coprime coprime).symm)
(ideal.quotient_inf_equiv_quotient_prod I J coprime)
/-- **Chinese remainder theorem** for a Dedekind domain: if the ideal `I` factors as
`β i in s, P i ^ e i`, then `R β§Έ I` factors as `Ξ (i : s), R β§Έ (P i ^ e i)`.
This is a version of `is_dedekind_domain.quotient_equiv_pi_of_prod_eq` where we restrict
the product to a finite subset `s` of a potentially infinite indexing type `ΞΉ`.
-/
noncomputable def is_dedekind_domain.quotient_equiv_pi_of_finset_prod_eq {ΞΉ : Type*} {s : finset ΞΉ}
(I : ideal R) (P : ΞΉ β ideal R) (e : ΞΉ β β)
(prime : β i β s, prime (P i)) (coprime : β (i j β s), i β j β P i β P j)
(prod_eq : (β i in s, P i ^ e i) = I) :
R β§Έ I β+* Ξ (i : s), R β§Έ (P i ^ e i) :=
is_dedekind_domain.quotient_equiv_pi_of_prod_eq I (Ξ» (i : s), P i) (Ξ» (i : s), e i)
(Ξ» i, prime i i.2)
(Ξ» i j h, coprime i i.2 j j.2 (subtype.coe_injective.ne h))
(trans (finset.prod_coe_sort s (Ξ» i, P i ^ e i)) prod_eq)
/-- Corollary of the Chinese remainder theorem: given elements `x i : R / P i ^ e i`,
we can choose a representative `y : R` such that `y β‘ x i (mod P i ^ e i)`.-/
lemma is_dedekind_domain.exists_representative_mod_finset {ΞΉ : Type*} {s : finset ΞΉ}
(P : ΞΉ β ideal R) (e : ΞΉ β β)
(prime : β i β s, prime (P i)) (coprime : β (i j β s), i β j β P i β P j)
(x : Ξ (i : s), R β§Έ (P i ^ e i)) :
β y, β i (hi : i β s), ideal.quotient.mk (P i ^ e i) y = x β¨i, hiβ© :=
begin
let f := is_dedekind_domain.quotient_equiv_pi_of_finset_prod_eq _ P e prime coprime rfl,
obtain β¨y, rflβ© := f.surjective x,
obtain β¨z, rflβ© := ideal.quotient.mk_surjective y,
exact β¨z, Ξ» i hi, rflβ©
end
/-- Corollary of the Chinese remainder theorem: given elements `x i : R`,
we can choose a representative `y : R` such that `y - x i β P i ^ e i`.-/
lemma is_dedekind_domain.exists_forall_sub_mem_ideal {ΞΉ : Type*} {s : finset ΞΉ}
(P : ΞΉ β ideal R) (e : ΞΉ β β)
(prime : β i β s, prime (P i)) (coprime : β (i j β s), i β j β P i β P j)
(x : s β R) :
β y, β i (hi : i β s), y - x β¨i, hiβ© β P i ^ e i :=
begin
obtain β¨y, hyβ© := is_dedekind_domain.exists_representative_mod_finset P e prime coprime
(Ξ» i, ideal.quotient.mk _ (x i)),
exact β¨y, Ξ» i hi, ideal.quotient.eq.mp (hy i hi)β©
end
end dedekind_domain
end chinese_remainder
section PID
open multiplicity unique_factorization_monoid ideal
variables {R} [is_domain R] [is_principal_ideal_ring R]
lemma span_singleton_dvd_span_singleton_iff_dvd {a b : R} :
(ideal.span {a}) β£ (ideal.span ({b} : set R)) β a β£ b :=
β¨Ξ» h, mem_span_singleton.mp (dvd_iff_le.mp h (mem_span_singleton.mpr (dvd_refl b))),
Ξ» h, dvd_iff_le.mpr (Ξ» d hd, mem_span_singleton.mpr (dvd_trans h (mem_span_singleton.mp hd)))β©
lemma singleton_span_mem_normalized_factors_of_mem_normalized_factors [normalization_monoid R]
[decidable_eq R] [decidable_eq (ideal R)] {a b : R} (ha : a β normalized_factors b) :
ideal.span ({a} : set R) β normalized_factors (ideal.span ({b} : set R)) :=
begin
by_cases hb : b = 0,
{ rw [ideal.span_singleton_eq_bot.mpr hb, bot_eq_zero, normalized_factors_zero],
rw [hb, normalized_factors_zero] at ha,
simpa only [multiset.not_mem_zero] },
{ suffices : prime (ideal.span ({a} : set R)),
{ obtain β¨c, hc, hc'β© := exists_mem_normalized_factors_of_dvd _ this.irreducible
(dvd_iff_le.mpr (span_singleton_le_span_singleton.mpr (dvd_of_mem_normalized_factors ha))),
rwa associated_iff_eq.mp hc',
{ by_contra,
exact hb (span_singleton_eq_bot.mp h) } },
rw prime_iff_is_prime,
exact (span_singleton_prime (prime_of_normalized_factor a ha).ne_zero).mpr
(prime_of_normalized_factor a ha),
by_contra,
exact (prime_of_normalized_factor a ha).ne_zero (span_singleton_eq_bot.mp h) },
end
lemma multiplicity_eq_multiplicity_span [decidable_rel ((β£) : R β R β Prop)]
[decidable_rel ((β£) : ideal R β ideal R β Prop)] {a b : R} :
multiplicity (ideal.span {a}) (ideal.span ({b} : set R)) = multiplicity a b :=
begin
by_cases h : finite a b,
{ rw β part_enat.coe_get (finite_iff_dom.mp h),
refine (multiplicity.unique
(show (ideal.span {a})^(((multiplicity a b).get h)) β£ (ideal.span {b}), from _) _).symm ;
rw [ideal.span_singleton_pow, span_singleton_dvd_span_singleton_iff_dvd],
exact pow_multiplicity_dvd h ,
{ exact multiplicity.is_greatest ((part_enat.lt_coe_iff _ _).mpr (exists.intro
(finite_iff_dom.mp h) (nat.lt_succ_self _))) } },
{ suffices : Β¬ (finite (ideal.span ({a} : set R)) (ideal.span ({b} : set R))),
{ rw [finite_iff_dom, part_enat.not_dom_iff_eq_top] at h this,
rw [h, this] },
refine not_finite_iff_forall.mpr (Ξ» n, by {rw [ideal.span_singleton_pow,
span_singleton_dvd_span_singleton_iff_dvd], exact not_finite_iff_forall.mp h n }) }
end
variables [decidable_eq R] [decidable_eq (ideal R)] [normalization_monoid R]
/-- The bijection between the (normalized) prime factors of `r` and the (normalized) prime factors
of `span {r}` -/
@[simps]
noncomputable def normalized_factors_equiv_span_normalized_factors {r : R} (hr : r β 0) :
{d : R | d β normalized_factors r} β
{I : ideal R | I β normalized_factors (ideal.span ({r} : set R))} :=
equiv.of_bijective
(Ξ» d, β¨ideal.span {βd}, singleton_span_mem_normalized_factors_of_mem_normalized_factors d.propβ©)
begin
split,
{ rintros β¨a, haβ© β¨b, hbβ© h,
rw [subtype.mk_eq_mk, ideal.span_singleton_eq_span_singleton, subtype.coe_mk,
subtype.coe_mk] at h,
exact subtype.mk_eq_mk.mpr (mem_normalized_factors_eq_of_associated ha hb h) },
{ rintros β¨i, hiβ©,
letI : i.is_principal := infer_instance,
letI : i.is_prime := is_prime_of_prime (prime_of_normalized_factor i hi),
obtain β¨a, ha, ha'β© := exists_mem_normalized_factors_of_dvd hr
(submodule.is_principal.prime_generator_of_is_prime i
(prime_of_normalized_factor i hi).ne_zero).irreducible _,
{ use β¨a, haβ©,
simp only [subtype.coe_mk, subtype.mk_eq_mk, β span_singleton_eq_span_singleton.mpr ha',
ideal.span_singleton_generator] },
{exact (submodule.is_principal.mem_iff_generator_dvd i).mp (((show ideal.span {r} β€ i, from
dvd_iff_le.mp (dvd_of_mem_normalized_factors hi))) (mem_span_singleton.mpr (dvd_refl r))) } }
end
variables [decidable_rel ((β£) : R β R β Prop)] [decidable_rel ((β£) : ideal R β ideal R β Prop)]
/-- The bijection `normalized_factors_equiv_span_normalized_factors` between the set of prime
factors of `r` and the set of prime factors of the ideal `β¨rβ©` preserves multiplicities. -/
lemma multiplicity_normalized_factors_equiv_span_normalized_factors_eq_multiplicity {r d: R}
(hr : r β 0) (hd : d β normalized_factors r) :
multiplicity d r =
multiplicity (normalized_factors_equiv_span_normalized_factors hr β¨d, hdβ© : ideal R)
(ideal.span {r}) :=
by simp only [normalized_factors_equiv_span_normalized_factors, multiplicity_eq_multiplicity_span,
subtype.coe_mk, equiv.of_bijective_apply]
/-- The bijection `normalized_factors_equiv_span_normalized_factors.symm` between the set of prime
factors of the ideal `β¨rβ©` and the set of prime factors of `r` preserves multiplicities. -/
lemma multiplicity_normalized_factors_equiv_span_normalized_factors_symm_eq_multiplicity
{r : R} (hr : r β 0) (I : {I : ideal R | I β normalized_factors (ideal.span ({r} : set R))}) :
multiplicity ((normalized_factors_equiv_span_normalized_factors hr).symm I : R) r =
multiplicity (I : ideal R) (ideal.span {r}) :=
begin
obtain β¨x, hxβ© := (normalized_factors_equiv_span_normalized_factors hr).surjective I,
obtain β¨a, haβ© := x,
rw [hx.symm, equiv.symm_apply_apply, subtype.coe_mk,
multiplicity_normalized_factors_equiv_span_normalized_factors_eq_multiplicity hr ha, hx],
end
end PID
|
a359ba89b32423ac22a9933699e406a3e924d0ca
|
86f6f4f8d827a196a32bfc646234b73328aeb306
|
/examples/logic/unnamed_2179.lean
|
bcafa61e52cc52016215fe1129384d70ab2204e9
|
[] |
no_license
|
jamescheuk91/mathematics_in_lean
|
09f1f87d2b0dce53464ff0cbe592c568ff59cf5e
|
4452499264e2975bca2f42565c0925506ba5dda3
|
refs/heads/master
| 1,679,716,410,967
| 1,613,957,947,000
| 1,613,957,947,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 138
|
lean
|
import data.real.basic
-- BEGIN
def converges_to (s : β β β) (a : β) :=
β Ξ΅ > 0, β N, β n β₯ N, abs (s n - a) < Ξ΅
-- END
|
ddbdea5b48a6c76e94efa5e97be7708010a35abe
|
c777c32c8e484e195053731103c5e52af26a25d1
|
/src/analysis/calculus/mean_value.lean
|
4238fa2836b406a1042067339034ebcec0f1d90c
|
[
"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
| 74,794
|
lean
|
/-
Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov
-/
import analysis.calculus.local_extr
import analysis.convex.slope
import analysis.convex.normed
import data.is_R_or_C.basic
import topology.instances.real_vector_space
/-!
# The mean value inequality and equalities
In this file we prove the following facts:
* `convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s`
and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with
constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the
derivative from a fixed linear map. This lemma and its versions are formulated using `is_R_or_C`,
so they work both for real and complex derivatives.
* `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x β€ B x` or
`βf xβ β€ B x` from upper estimates on `f'` or `βf'β`, respectively. These lemmas differ by
their assumptions:
* `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`;
* `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative
or its norm is less than `B' x`;
* `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `βf xβ = B x`;
* `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`;
* name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]`
and has a right derivative at every point of `[a, b)`, and (2) the lemma has
a counterpart assuming that `B` is differentiable everywhere on `β`
* `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above
by a constant `C`, then `βf x - f aβ β€ C * βx - aβ`; several versions deal with
right derivative and derivative within `[a, b]` (`has_deriv_within_at` or `deriv_within`).
* `convex.is_const_of_fderiv_within_eq_zero` : if a function has derivative `0` on a convex set `s`,
then it is a constant on `s`.
* `exists_ratio_has_deriv_at_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` :
Cauchy's Mean Value Theorem.
* `exists_has_deriv_at_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem.
* `domain_mvt` : Lagrange's Mean Value Theorem, applied to a segment in a convex domain.
* `convex.image_sub_lt_mul_sub_of_deriv_lt`, `convex.mul_sub_lt_image_sub_of_lt_deriv`,
`convex.image_sub_le_mul_sub_of_deriv_le`, `convex.mul_sub_le_image_sub_of_le_deriv`,
if `β x, C (</β€/>/β₯) (f' x)`, then `C * (y - x) (</β€/>/β₯) (f y - f x)` whenever `x < y`.
* `convex.monotone_on_of_deriv_nonneg`, `convex.antitone_on_of_deriv_nonpos`,
`convex.strict_mono_of_deriv_pos`, `convex.strict_anti_of_deriv_neg` :
if the derivative of a function is non-negative/non-positive/positive/negative, then
the function is monotone/antitone/strictly monotone/strictly monotonically
decreasing.
* `convex_on_of_deriv_monotone_on`, `convex_on_of_deriv2_nonneg` : if the derivative of a function
is increasing or its second derivative is nonnegative, then the original function is convex.
* `strict_fderiv_of_cont_diff` : a C^1 function over the reals is strictly differentiable. (This
is a corollary of the mean value inequality.)
-/
variables {E : Type*} [normed_add_comm_group E] [normed_space β E]
{F : Type*} [normed_add_comm_group F] [normed_space β F]
open metric set asymptotics continuous_linear_map filter
open_locale classical topology nnreal
/-! ### One-dimensional fencing inequalities -/
/-- General fencing theorem for continuous functions with an estimate on the derivative.
Let `f` and `B` be continuous functions on `[a, b]` such that
* `f a β€ B a`;
* `B` has right derivative `B'` at every point of `[a, b)`;
* for each `x β [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)`
is bounded above by a function `f'`;
* we have `f' x < B' x` whenever `f x = B x`.
Then `f x β€ B x` everywhere on `[a, b]`. -/
lemma image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : β β β} {a b : β}
(hf : continuous_on f (Icc a b))
-- `hf'` actually says `liminf (f z - f x) / (z - x) β€ f' x`
(hf' : β x β Ico a b, β r, f' x < r β βαΆ z in π[>] x, slope f x z < r)
{B B' : β β β} (ha : f a β€ B a) (hB : continuous_on B (Icc a b))
(hB' : β x β Ico a b, has_deriv_within_at B (B' x) (Ici x) x)
(bound : β x β Ico a b, f x = B x β f' x < B' x) :
β β¦xβ¦, x β Icc a b β f x β€ B x :=
begin
change Icc a b β {x | f x β€ B x},
set s := {x | f x β€ B x} β© Icc a b,
have A : continuous_on (Ξ» x, (f x, B x)) (Icc a b), from hf.prod hB,
have : is_closed s,
{ simp only [s, inter_comm],
exact A.preimage_closed_of_closed is_closed_Icc order_closed_topology.is_closed_le' },
apply this.Icc_subset_of_forall_exists_gt ha,
rintros x β¨hxB : f x β€ B x, xabβ© y hy,
cases hxB.lt_or_eq with hxB hxB,
{ -- If `f x < B x`, then all we need is continuity of both sides
refine nonempty_of_mem (inter_mem _ (Ioc_mem_nhds_within_Ioi β¨le_rfl, hyβ©)),
have : βαΆ x in π[Icc a b] x, f x < B x,
from A x (Ico_subset_Icc_self xab)
(is_open.mem_nhds (is_open_lt continuous_fst continuous_snd) hxB),
have : βαΆ x in π[>] x, f x < B x,
from nhds_within_le_of_mem (Icc_mem_nhds_within_Ioi xab) this,
exact this.mono (Ξ» y, le_of_lt) },
{ rcases exists_between (bound x xab hxB) with β¨r, hfr, hrBβ©,
specialize hf' x xab r hfr,
have HB : βαΆ z in π[>] x, r < slope B x z,
from (has_deriv_within_at_iff_tendsto_slope' $ lt_irrefl x).1
(hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB),
obtain β¨z, hfz, hzB, hzβ© :
β z, slope f x z < r β§ r < slope B x z β§ z β Ioc x y,
from (hf'.and_eventually (HB.and (Ioc_mem_nhds_within_Ioi β¨le_rfl, hyβ©))).exists,
refine β¨z, _, hzβ©,
have := (hfz.trans hzB).le,
rwa [slope_def_field, slope_def_field, div_le_div_right (sub_pos.2 hz.1), hxB,
sub_le_sub_iff_right] at this }
end
/-- General fencing theorem for continuous functions with an estimate on the derivative.
Let `f` and `B` be continuous functions on `[a, b]` such that
* `f a β€ B a`;
* `B` has derivative `B'` everywhere on `β`;
* for each `x β [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)`
is bounded above by a function `f'`;
* we have `f' x < B' x` whenever `f x = B x`.
Then `f x β€ B x` everywhere on `[a, b]`. -/
lemma image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : β β β} {a b : β}
(hf : continuous_on f (Icc a b))
-- `hf'` actually says `liminf (f z - f x) / (z - x) β€ f' x`
(hf' : β x β Ico a b, β r, f' x < r β βαΆ z in π[>] x, slope f x z < r)
{B B' : β β β} (ha : f a β€ B a) (hB : β x, has_deriv_at B (B' x) x)
(bound : β x β Ico a b, f x = B x β f' x < B' x) :
β β¦xβ¦, x β Icc a b β f x β€ B x :=
image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha
(Ξ» x hx, (hB x).continuous_at.continuous_within_at)
(Ξ» x hx, (hB x).has_deriv_within_at) bound
/-- General fencing theorem for continuous functions with an estimate on the derivative.
Let `f` and `B` be continuous functions on `[a, b]` such that
* `f a β€ B a`;
* `B` has right derivative `B'` at every point of `[a, b)`;
* for each `x β [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)`
is bounded above by `B'`.
Then `f x β€ B x` everywhere on `[a, b]`. -/
lemma image_le_of_liminf_slope_right_le_deriv_boundary {f : β β β} {a b : β}
(hf : continuous_on f (Icc a b))
{B B' : β β β} (ha : f a β€ B a) (hB : continuous_on B (Icc a b))
(hB' : β x β Ico a b, has_deriv_within_at B (B' x) (Ici x) x)
-- `bound` actually says `liminf (f z - f x) / (z - x) β€ B' x`
(bound : β x β Ico a b, β r, B' x < r β βαΆ z in π[>] x, slope f x z < r) :
β β¦xβ¦, x β Icc a b β f x β€ B x :=
begin
have Hr : β x β Icc a b, β r > 0, f x β€ B x + r * (x - a),
{ intros x hx r hr,
apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound,
{ rwa [sub_self, mul_zero, add_zero] },
{ exact hB.add (continuous_on_const.mul
(continuous_id.continuous_on.sub continuous_on_const)) },
{ assume x hx,
exact (hB' x hx).add (((has_deriv_within_at_id x (Ici x)).sub_const a).const_mul r) },
{ assume x hx _,
rw [mul_one],
exact (lt_add_iff_pos_right _).2 hr },
exact hx },
assume x hx,
have : continuous_within_at (Ξ» r, B x + r * (x - a)) (Ioi 0) 0,
from continuous_within_at_const.add (continuous_within_at_id.mul continuous_within_at_const),
convert continuous_within_at_const.closure_le _ this (Hr x hx); simp
end
/-- General fencing theorem for continuous functions with an estimate on the derivative.
Let `f` and `B` be continuous functions on `[a, b]` such that
* `f a β€ B a`;
* `B` has right derivative `B'` at every point of `[a, b)`;
* `f` has right derivative `f'` at every point of `[a, b)`;
* we have `f' x < B' x` whenever `f x = B x`.
Then `f x β€ B x` everywhere on `[a, b]`. -/
lemma image_le_of_deriv_right_lt_deriv_boundary' {f f' : β β β} {a b : β}
(hf : continuous_on f (Icc a b))
(hf' : β x β Ico a b, has_deriv_within_at f (f' x) (Ici x) x)
{B B' : β β β} (ha : f a β€ B a) (hB : continuous_on B (Icc a b))
(hB' : β x β Ico a b, has_deriv_within_at B (B' x) (Ici x) x)
(bound : β x β Ico a b, f x = B x β f' x < B' x) :
β β¦xβ¦, x β Icc a b β f x β€ B x :=
image_le_of_liminf_slope_right_lt_deriv_boundary' hf
(Ξ» x hx r hr, (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound
/-- General fencing theorem for continuous functions with an estimate on the derivative.
Let `f` and `B` be continuous functions on `[a, b]` such that
* `f a β€ B a`;
* `B` has derivative `B'` everywhere on `β`;
* `f` has right derivative `f'` at every point of `[a, b)`;
* we have `f' x < B' x` whenever `f x = B x`.
Then `f x β€ B x` everywhere on `[a, b]`. -/
lemma image_le_of_deriv_right_lt_deriv_boundary {f f' : β β β} {a b : β}
(hf : continuous_on f (Icc a b))
(hf' : β x β Ico a b, has_deriv_within_at f (f' x) (Ici x) x)
{B B' : β β β} (ha : f a β€ B a) (hB : β x, has_deriv_at B (B' x) x)
(bound : β x β Ico a b, f x = B x β f' x < B' x) :
β β¦xβ¦, x β Icc a b β f x β€ B x :=
image_le_of_deriv_right_lt_deriv_boundary' hf hf' ha
(Ξ» x hx, (hB x).continuous_at.continuous_within_at)
(Ξ» x hx, (hB x).has_deriv_within_at) bound
/-- General fencing theorem for continuous functions with an estimate on the derivative.
Let `f` and `B` be continuous functions on `[a, b]` such that
* `f a β€ B a`;
* `B` has derivative `B'` everywhere on `β`;
* `f` has right derivative `f'` at every point of `[a, b)`;
* we have `f' x β€ B' x` on `[a, b)`.
Then `f x β€ B x` everywhere on `[a, b]`. -/
lemma image_le_of_deriv_right_le_deriv_boundary {f f' : β β β} {a b : β}
(hf : continuous_on f (Icc a b))
(hf' : β x β Ico a b, has_deriv_within_at f (f' x) (Ici x) x)
{B B' : β β β} (ha : f a β€ B a) (hB : continuous_on B (Icc a b))
(hB' : β x β Ico a b, has_deriv_within_at B (B' x) (Ici x) x)
(bound : β x β Ico a b, f' x β€ B' x) :
β β¦xβ¦, x β Icc a b β f x β€ B x :=
image_le_of_liminf_slope_right_le_deriv_boundary hf ha hB hB' $
assume x hx r hr, (hf' x hx).liminf_right_slope_le (lt_of_le_of_lt (bound x hx) hr)
/-! ### Vector-valued functions `f : β β E` -/
section
variables {f : β β E} {a b : β}
/-- General fencing theorem for continuous functions with an estimate on the derivative.
Let `f` and `B` be continuous functions on `[a, b]` such that
* `βf aβ β€ B a`;
* `B` has right derivative at every point of `[a, b)`;
* for each `x β [a, b)` the right-side limit inferior of `(βf zβ - βf xβ) / (z - x)`
is bounded above by a function `f'`;
* we have `f' x < B' x` whenever `βf xβ = B x`.
Then `βf xβ β€ B x` everywhere on `[a, b]`. -/
lemma image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary {E : Type*}
[normed_add_comm_group E] {f : β β E} {f' : β β β} (hf : continuous_on f (Icc a b))
-- `hf'` actually says `liminf (βf zβ - βf xβ) / (z - x) β€ f' x`
(hf' : β x β Ico a b, β r, f' x < r β
βαΆ z in π[>] x, slope (norm β f) x z < r)
{B B' : β β β} (ha : βf aβ β€ B a) (hB : continuous_on B (Icc a b))
(hB' : β x β Ico a b, has_deriv_within_at B (B' x) (Ici x) x)
(bound : β x β Ico a b, βf xβ = B x β f' x < B' x) :
β β¦xβ¦, x β Icc a b β βf xβ β€ B x :=
image_le_of_liminf_slope_right_lt_deriv_boundary' (continuous_norm.comp_continuous_on hf) hf'
ha hB hB' bound
/-- General fencing theorem for continuous functions with an estimate on the norm of the derivative.
Let `f` and `B` be continuous functions on `[a, b]` such that
* `βf aβ β€ B a`;
* `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`;
* the norm of `f'` is strictly less than `B'` whenever `βf xβ = B x`.
Then `βf xβ β€ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions
to make this theorem work for piecewise differentiable functions.
-/
lemma image_norm_le_of_norm_deriv_right_lt_deriv_boundary' {f' : β β E}
(hf : continuous_on f (Icc a b))
(hf' : β x β Ico a b, has_deriv_within_at f (f' x) (Ici x) x)
{B B' : β β β} (ha : βf aβ β€ B a) (hB : continuous_on B (Icc a b))
(hB' : β x β Ico a b, has_deriv_within_at B (B' x) (Ici x) x)
(bound : β x β Ico a b, βf xβ = B x β βf' xβ < B' x) :
β β¦xβ¦, x β Icc a b β βf xβ β€ B x :=
image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary hf
(Ξ» x hx r hr, (hf' x hx).liminf_right_slope_norm_le hr) ha hB hB' bound
/-- General fencing theorem for continuous functions with an estimate on the norm of the derivative.
Let `f` and `B` be continuous functions on `[a, b]` such that
* `βf aβ β€ B a`;
* `f` has right derivative `f'` at every point of `[a, b)`;
* `B` has derivative `B'` everywhere on `β`;
* the norm of `f'` is strictly less than `B'` whenever `βf xβ = B x`.
Then `βf xβ β€ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions
to make this theorem work for piecewise differentiable functions.
-/
lemma image_norm_le_of_norm_deriv_right_lt_deriv_boundary {f' : β β E}
(hf : continuous_on f (Icc a b))
(hf' : β x β Ico a b, has_deriv_within_at f (f' x) (Ici x) x)
{B B' : β β β} (ha : βf aβ β€ B a) (hB : β x, has_deriv_at B (B' x) x)
(bound : β x β Ico a b, βf xβ = B x β βf' xβ < B' x) :
β β¦xβ¦, x β Icc a b β βf xβ β€ B x :=
image_norm_le_of_norm_deriv_right_lt_deriv_boundary' hf hf' ha
(Ξ» x hx, (hB x).continuous_at.continuous_within_at)
(Ξ» x hx, (hB x).has_deriv_within_at) bound
/-- General fencing theorem for continuous functions with an estimate on the norm of the derivative.
Let `f` and `B` be continuous functions on `[a, b]` such that
* `βf aβ β€ B a`;
* `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`;
* we have `βf' xβ β€ B x` everywhere on `[a, b)`.
Then `βf xβ β€ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions
to make this theorem work for piecewise differentiable functions.
-/
lemma image_norm_le_of_norm_deriv_right_le_deriv_boundary' {f' : β β E}
(hf : continuous_on f (Icc a b))
(hf' : β x β Ico a b, has_deriv_within_at f (f' x) (Ici x) x)
{B B' : β β β} (ha : βf aβ β€ B a) (hB : continuous_on B (Icc a b))
(hB' : β x β Ico a b, has_deriv_within_at B (B' x) (Ici x) x)
(bound : β x β Ico a b, βf' xβ β€ B' x) :
β β¦xβ¦, x β Icc a b β βf xβ β€ B x :=
image_le_of_liminf_slope_right_le_deriv_boundary (continuous_norm.comp_continuous_on hf) ha hB hB' $
(Ξ» x hx r hr, (hf' x hx).liminf_right_slope_norm_le (lt_of_le_of_lt (bound x hx) hr))
/-- General fencing theorem for continuous functions with an estimate on the norm of the derivative.
Let `f` and `B` be continuous functions on `[a, b]` such that
* `βf aβ β€ B a`;
* `f` has right derivative `f'` at every point of `[a, b)`;
* `B` has derivative `B'` everywhere on `β`;
* we have `βf' xβ β€ B x` everywhere on `[a, b)`.
Then `βf xβ β€ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions
to make this theorem work for piecewise differentiable functions.
-/
lemma image_norm_le_of_norm_deriv_right_le_deriv_boundary {f' : β β E}
(hf : continuous_on f (Icc a b))
(hf' : β x β Ico a b, has_deriv_within_at f (f' x) (Ici x) x)
{B B' : β β β} (ha : βf aβ β€ B a) (hB : β x, has_deriv_at B (B' x) x)
(bound : β x β Ico a b, βf' xβ β€ B' x) :
β β¦xβ¦, x β Icc a b β βf xβ β€ B x :=
image_norm_le_of_norm_deriv_right_le_deriv_boundary' hf hf' ha
(Ξ» x hx, (hB x).continuous_at.continuous_within_at)
(Ξ» x hx, (hB x).has_deriv_within_at) bound
/-- A function on `[a, b]` with the norm of the right derivative bounded by `C`
satisfies `βf x - f aβ β€ C * (x - a)`. -/
theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : β β E} {C : β}
(hf : continuous_on f (Icc a b))
(hf' : β x β Ico a b, has_deriv_within_at f (f' x) (Ici x) x)
(bound : βx β Ico a b, βf' xβ β€ C) :
β x β Icc a b, βf x - f aβ β€ C * (x - a) :=
begin
let g := Ξ» x, f x - f a,
have hg : continuous_on g (Icc a b), from hf.sub continuous_on_const,
have hg' : β x β Ico a b, has_deriv_within_at g (f' x) (Ici x) x,
{ assume x hx,
simpa using (hf' x hx).sub (has_deriv_within_at_const _ _ _) },
let B := Ξ» x, C * (x - a),
have hB : β x, has_deriv_at B C x,
{ assume x,
simpa using (has_deriv_at_const x C).mul ((has_deriv_at_id x).sub (has_deriv_at_const x a)) },
convert image_norm_le_of_norm_deriv_right_le_deriv_boundary hg hg' _ hB bound,
simp only [g, B], rw [sub_self, norm_zero, sub_self, mul_zero]
end
/-- A function on `[a, b]` with the norm of the derivative within `[a, b]`
bounded by `C` satisfies `βf x - f aβ β€ C * (x - a)`, `has_deriv_within_at`
version. -/
theorem norm_image_sub_le_of_norm_deriv_le_segment' {f' : β β E} {C : β}
(hf : β x β Icc a b, has_deriv_within_at f (f' x) (Icc a b) x)
(bound : βx β Ico a b, βf' xβ β€ C) :
β x β Icc a b, βf x - f aβ β€ C * (x - a) :=
begin
refine norm_image_sub_le_of_norm_deriv_right_le_segment
(Ξ» x hx, (hf x hx).continuous_within_at) (Ξ» x hx, _) bound,
exact (hf x $ Ico_subset_Icc_self hx).nhds_within (Icc_mem_nhds_within_Ici hx)
end
/-- A function on `[a, b]` with the norm of the derivative within `[a, b]`
bounded by `C` satisfies `βf x - f aβ β€ C * (x - a)`, `deriv_within`
version. -/
theorem norm_image_sub_le_of_norm_deriv_le_segment {C : β} (hf : differentiable_on β f (Icc a b))
(bound : βx β Ico a b, βderiv_within f (Icc a b) xβ β€ C) :
β x β Icc a b, βf x - f aβ β€ C * (x - a) :=
begin
refine norm_image_sub_le_of_norm_deriv_le_segment' _ bound,
exact Ξ» x hx, (hf x hx).has_deriv_within_at
end
/-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]`
bounded by `C` satisfies `βf 1 - f 0β β€ C`, `has_deriv_within_at`
version. -/
theorem norm_image_sub_le_of_norm_deriv_le_segment_01' {f' : β β E} {C : β}
(hf : β x β Icc (0:β) 1, has_deriv_within_at f (f' x) (Icc (0:β) 1) x)
(bound : βx β Ico (0:β) 1, βf' xβ β€ C) :
βf 1 - f 0β β€ C :=
by simpa only [sub_zero, mul_one]
using norm_image_sub_le_of_norm_deriv_le_segment' hf bound 1 (right_mem_Icc.2 zero_le_one)
/-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]`
bounded by `C` satisfies `βf 1 - f 0β β€ C`, `deriv_within` version. -/
theorem norm_image_sub_le_of_norm_deriv_le_segment_01 {C : β}
(hf : differentiable_on β f (Icc (0:β) 1))
(bound : βx β Ico (0:β) 1, βderiv_within f (Icc (0:β) 1) xβ β€ C) :
βf 1 - f 0β β€ C :=
by simpa only [sub_zero, mul_one]
using norm_image_sub_le_of_norm_deriv_le_segment hf bound 1 (right_mem_Icc.2 zero_le_one)
theorem constant_of_has_deriv_right_zero (hcont : continuous_on f (Icc a b))
(hderiv : β x β Ico a b, has_deriv_within_at f 0 (Ici x) x) :
β x β Icc a b, f x = f a :=
by simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using
Ξ» x hx, norm_image_sub_le_of_norm_deriv_right_le_segment
hcont hderiv (Ξ» y hy, by rw norm_le_zero_iff) x hx
theorem constant_of_deriv_within_zero (hdiff : differentiable_on β f (Icc a b))
(hderiv : β x β Ico a b, deriv_within f (Icc a b) x = 0) :
β x β Icc a b, f x = f a :=
begin
have H : β x β Ico a b, βderiv_within f (Icc a b) xβ β€ 0 :=
by simpa only [norm_le_zero_iff] using Ξ» x hx, hderiv x hx,
simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using
Ξ» x hx, norm_image_sub_le_of_norm_deriv_le_segment hdiff H x hx,
end
variables {f' g : β β E}
/-- If two continuous functions on `[a, b]` have the same right derivative and are equal at `a`,
then they are equal everywhere on `[a, b]`. -/
theorem eq_of_has_deriv_right_eq
(derivf : β x β Ico a b, has_deriv_within_at f (f' x) (Ici x) x)
(derivg : β x β Ico a b, has_deriv_within_at g (f' x) (Ici x) x)
(fcont : continuous_on f (Icc a b)) (gcont : continuous_on g (Icc a b))
(hi : f a = g a) :
β y β Icc a b, f y = g y :=
begin
simp only [β @sub_eq_zero _ _ (f _)] at hi β’,
exact hi βΈ constant_of_has_deriv_right_zero (fcont.sub gcont)
(Ξ» y hy, by simpa only [sub_self] using (derivf y hy).sub (derivg y hy)),
end
/-- If two differentiable functions on `[a, b]` have the same derivative within `[a, b]` everywhere
on `[a, b)` and are equal at `a`, then they are equal everywhere on `[a, b]`. -/
theorem eq_of_deriv_within_eq (fdiff : differentiable_on β f (Icc a b))
(gdiff : differentiable_on β g (Icc a b))
(hderiv : eq_on (deriv_within f (Icc a b)) (deriv_within g (Icc a b)) (Ico a b))
(hi : f a = g a) :
β y β Icc a b, f y = g y :=
begin
have A : β y β Ico a b, has_deriv_within_at f (deriv_within f (Icc a b) y) (Ici y) y :=
Ξ» y hy, (fdiff y (mem_Icc_of_Ico hy)).has_deriv_within_at.nhds_within
(Icc_mem_nhds_within_Ici hy),
have B : β y β Ico a b, has_deriv_within_at g (deriv_within g (Icc a b) y) (Ici y) y :=
Ξ» y hy, (gdiff y (mem_Icc_of_Ico hy)).has_deriv_within_at.nhds_within
(Icc_mem_nhds_within_Ici hy),
exact eq_of_has_deriv_right_eq A (Ξ» y hy, (hderiv hy).symm βΈ B y hy) fdiff.continuous_on
gdiff.continuous_on hi
end
end
/-!
### Vector-valued functions `f : E β G`
Theorems in this section work both for real and complex differentiable functions. We use assumptions
`[is_R_or_C π] [normed_space π E] [normed_space π G]` to achieve this result. For the domain `E` we
also assume `[normed_space β E]` to have a notion of a `convex` set. -/
section
variables {π G : Type*} [is_R_or_C π] [normed_space π E] [normed_add_comm_group G]
[normed_space π G]
namespace convex
variables {f : E β G} {C : β} {s : set E} {x y : E} {f' : E β E βL[π] G} {Ο : E βL[π] G}
/-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then
the function is `C`-Lipschitz. Version with `has_fderiv_within`. -/
theorem norm_image_sub_le_of_norm_has_fderiv_within_le
(hf : β x β s, has_fderiv_within_at f (f' x) s x) (bound : βxβs, βf' xβ β€ C)
(hs : convex β s) (xs : x β s) (ys : y β s) : βf y - f xβ β€ C * βy - xβ :=
begin
letI : normed_space β G := restrict_scalars.normed_space β π G,
/- By composition with `t β¦ x + t β’ (y-x)`, we reduce to a statement for functions defined
on `[0,1]`, for which it is proved in `norm_image_sub_le_of_norm_deriv_le_segment`.
We just have to check the differentiability of the composition and bounds on its derivative,
which is straightforward but tedious for lack of automation. -/
have C0 : 0 β€ C := le_trans (norm_nonneg _) (bound x xs),
set g : β β E := Ξ» t, x + t β’ (y - x),
have Dg : β t, has_deriv_at g (y-x) t,
{ assume t,
simpa only [one_smul] using ((has_deriv_at_id t).smul_const (y - x)).const_add x },
have segm : Icc 0 1 β g β»ΒΉ' s,
{ rw [β image_subset_iff, β segment_eq_image'],
apply hs.segment_subset xs ys },
have : f x = f (g 0), by { simp only [g], rw [zero_smul, add_zero] },
rw this,
have : f y = f (g 1), by { simp only [g], rw [one_smul, add_sub_cancel'_right] },
rw this,
have D2: β t β Icc (0:β) 1, has_deriv_within_at (f β g) (f' (g t) (y - x)) (Icc 0 1) t,
{ intros t ht,
have : has_fderiv_within_at f ((f' (g t)).restrict_scalars β) s (g t),
from hf (g t) (segm ht),
exact this.comp_has_deriv_within_at _ (Dg t).has_deriv_within_at segm },
apply norm_image_sub_le_of_norm_deriv_le_segment_01' D2,
refine Ξ» t ht, le_of_op_norm_le _ _ _,
exact bound (g t) (segm $ Ico_subset_Icc_self ht)
end
/-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on
`s`, then the function is `C`-Lipschitz on `s`. Version with `has_fderiv_within` and
`lipschitz_on_with`. -/
theorem lipschitz_on_with_of_nnnorm_has_fderiv_within_le {C : ββ₯0}
(hf : β x β s, has_fderiv_within_at f (f' x) s x) (bound : βxβs, βf' xββ β€ C)
(hs : convex β s) : lipschitz_on_with C f s :=
begin
rw lipschitz_on_with_iff_norm_sub_le,
intros x x_in y y_in,
exact hs.norm_image_sub_le_of_norm_has_fderiv_within_le hf bound y_in x_in
end
/-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β G` be a function
differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is
continuous within `s` at `x`. Then for any number `K : ββ₯0` larger than `βf' xββ`, `f` is
`K`-Lipschitz on some neighborhood of `x` within `s`. See also
`convex.exists_nhds_within_lipschitz_on_with_of_has_fderiv_within_at` for a version that claims
existence of `K` instead of an explicit estimate. -/
lemma exists_nhds_within_lipschitz_on_with_of_has_fderiv_within_at_of_nnnorm_lt
(hs : convex β s) {f : E β G} (hder : βαΆ y in π[s] x, has_fderiv_within_at f (f' y) s y)
(hcont : continuous_within_at f' s x) (K : ββ₯0) (hK : βf' xββ < K) :
β t β π[s] x, lipschitz_on_with K f t :=
begin
obtain β¨Ξ΅, Ξ΅0, hΞ΅β© :
β Ξ΅ > 0, ball x Ξ΅ β© s β {y | has_fderiv_within_at f (f' y) s y β§ βf' yββ < K},
from mem_nhds_within_iff.1 (hder.and $ hcont.nnnorm.eventually (gt_mem_nhds hK)),
rw inter_comm at hΞ΅,
refine β¨s β© ball x Ξ΅, inter_mem_nhds_within _ (ball_mem_nhds _ Ξ΅0), _β©,
exact (hs.inter (convex_ball _ _)).lipschitz_on_with_of_nnnorm_has_fderiv_within_le
(Ξ» y hy, (hΞ΅ hy).1.mono (inter_subset_left _ _)) (Ξ» y hy, (hΞ΅ hy).2.le)
end
/-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β G` be a function
differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is
continuous within `s` at `x`. Then for any number `K : ββ₯0` larger than `βf' xββ`, `f` is Lipschitz
on some neighborhood of `x` within `s`. See also
`convex.exists_nhds_within_lipschitz_on_with_of_has_fderiv_within_at_of_nnnorm_lt` for a version
with an explicit estimate on the Lipschitz constant. -/
lemma exists_nhds_within_lipschitz_on_with_of_has_fderiv_within_at
(hs : convex β s) {f : E β G} (hder : βαΆ y in π[s] x, has_fderiv_within_at f (f' y) s y)
(hcont : continuous_within_at f' s x) :
β K (t β π[s] x), lipschitz_on_with K f t :=
(exists_gt _).imp $
hs.exists_nhds_within_lipschitz_on_with_of_has_fderiv_within_at_of_nnnorm_lt hder hcont
/-- The mean value theorem on a convex set: if the derivative of a function within this set is
bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv_within`. -/
theorem norm_image_sub_le_of_norm_fderiv_within_le
(hf : differentiable_on π f s) (bound : βxβs, βfderiv_within π f s xβ β€ C)
(hs : convex β s) (xs : x β s) (ys : y β s) : βf y - f xβ β€ C * βy - xβ :=
hs.norm_image_sub_le_of_norm_has_fderiv_within_le (Ξ» x hx, (hf x hx).has_fderiv_within_at)
bound xs ys
/-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on
`s`, then the function is `C`-Lipschitz on `s`. Version with `fderiv_within` and
`lipschitz_on_with`. -/
theorem lipschitz_on_with_of_nnnorm_fderiv_within_le {C : ββ₯0}
(hf : differentiable_on π f s) (bound : β x β s, βfderiv_within π f s xββ β€ C)
(hs : convex β s) : lipschitz_on_with C f s:=
hs.lipschitz_on_with_of_nnnorm_has_fderiv_within_le (Ξ» x hx, (hf x hx).has_fderiv_within_at) bound
/-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`,
then the function is `C`-Lipschitz. Version with `fderiv`. -/
theorem norm_image_sub_le_of_norm_fderiv_le
(hf : β x β s, differentiable_at π f x) (bound : βxβs, βfderiv π f xβ β€ C)
(hs : convex β s) (xs : x β s) (ys : y β s) : βf y - f xβ β€ C * βy - xβ :=
hs.norm_image_sub_le_of_norm_has_fderiv_within_le
(Ξ» x hx, (hf x hx).has_fderiv_at.has_fderiv_within_at) bound xs ys
/-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on
`s`, then the function is `C`-Lipschitz on `s`. Version with `fderiv` and `lipschitz_on_with`. -/
theorem lipschitz_on_with_of_nnnorm_fderiv_le {C : ββ₯0}
(hf : β x β s, differentiable_at π f x) (bound : βxβs, βfderiv π f xββ β€ C)
(hs : convex β s) : lipschitz_on_with C f s :=
hs.lipschitz_on_with_of_nnnorm_has_fderiv_within_le
(Ξ» x hx, (hf x hx).has_fderiv_at.has_fderiv_within_at) bound
/-- Variant of the mean value inequality on a convex set, using a bound on the difference between
the derivative and a fixed linear map, rather than a bound on the derivative itself. Version with
`has_fderiv_within`. -/
theorem norm_image_sub_le_of_norm_has_fderiv_within_le'
(hf : β x β s, has_fderiv_within_at f (f' x) s x) (bound : βxβs, βf' x - Οβ β€ C)
(hs : convex β s) (xs : x β s) (ys : y β s) : βf y - f x - Ο (y - x)β β€ C * βy - xβ :=
begin
/- We subtract `Ο` to define a new function `g` for which `g' = 0`, for which the previous theorem
applies, `convex.norm_image_sub_le_of_norm_has_fderiv_within_le`. Then, we just need to glue
together the pieces, expressing back `f` in terms of `g`. -/
let g := Ξ»y, f y - Ο y,
have hg : β x β s, has_fderiv_within_at g (f' x - Ο) s x :=
Ξ» x xs, (hf x xs).sub Ο.has_fderiv_within_at,
calc βf y - f x - Ο (y - x)β = βf y - f x - (Ο y - Ο x)β : by simp
... = β(f y - Ο y) - (f x - Ο x)β : by abel
... = βg y - g xβ : by simp
... β€ C * βy - xβ : convex.norm_image_sub_le_of_norm_has_fderiv_within_le hg bound hs xs ys,
end
/-- Variant of the mean value inequality on a convex set. Version with `fderiv_within`. -/
theorem norm_image_sub_le_of_norm_fderiv_within_le'
(hf : differentiable_on π f s) (bound : βxβs, βfderiv_within π f s x - Οβ β€ C)
(hs : convex β s) (xs : x β s) (ys : y β s) : βf y - f x - Ο (y - x)β β€ C * βy - xβ :=
hs.norm_image_sub_le_of_norm_has_fderiv_within_le' (Ξ» x hx, (hf x hx).has_fderiv_within_at)
bound xs ys
/-- Variant of the mean value inequality on a convex set. Version with `fderiv`. -/
theorem norm_image_sub_le_of_norm_fderiv_le'
(hf : β x β s, differentiable_at π f x) (bound : βxβs, βfderiv π f x - Οβ β€ C)
(hs : convex β s) (xs : x β s) (ys : y β s) : βf y - f x - Ο (y - x)β β€ C * βy - xβ :=
hs.norm_image_sub_le_of_norm_has_fderiv_within_le'
(Ξ» x hx, (hf x hx).has_fderiv_at.has_fderiv_within_at) bound xs ys
/-- If a function has zero FrΓ©chet derivative at every point of a convex set,
then it is a constant on this set. -/
theorem is_const_of_fderiv_within_eq_zero (hs : convex β s) (hf : differentiable_on π f s)
(hf' : β x β s, fderiv_within π f s x = 0) (hx : x β s) (hy : y β s) :
f x = f y :=
have bound : β x β s, βfderiv_within π f s xβ β€ 0,
from Ξ» x hx, by simp only [hf' x hx, norm_zero],
by simpa only [(dist_eq_norm _ _).symm, zero_mul, dist_le_zero, eq_comm]
using hs.norm_image_sub_le_of_norm_fderiv_within_le hf bound hx hy
theorem _root_.is_const_of_fderiv_eq_zero (hf : differentiable π f) (hf' : β x, fderiv π f x = 0)
(x y : E) :
f x = f y :=
convex_univ.is_const_of_fderiv_within_eq_zero hf.differentiable_on
(Ξ» x _, by rw fderiv_within_univ; exact hf' x) trivial trivial
end convex
namespace convex
variables {f f' : π β G} {s : set π} {x y : π}
/-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is
bounded by `C`, then the function is `C`-Lipschitz. Version with `has_deriv_within`. -/
theorem norm_image_sub_le_of_norm_has_deriv_within_le {C : β}
(hf : β x β s, has_deriv_within_at f (f' x) s x) (bound : βxβs, βf' xβ β€ C)
(hs : convex β s) (xs : x β s) (ys : y β s) : βf y - f xβ β€ C * βy - xβ :=
convex.norm_image_sub_le_of_norm_has_fderiv_within_le (Ξ» x hx, (hf x hx).has_fderiv_within_at)
(Ξ» x hx, le_trans (by simp) (bound x hx)) hs xs ys
/-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is
bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`.
Version with `has_deriv_within` and `lipschitz_on_with`. -/
theorem lipschitz_on_with_of_nnnorm_has_deriv_within_le {C : ββ₯0} (hs : convex β s)
(hf : β x β s, has_deriv_within_at f (f' x) s x) (bound : βxβs, βf' xββ β€ C) :
lipschitz_on_with C f s :=
convex.lipschitz_on_with_of_nnnorm_has_fderiv_within_le (Ξ» x hx, (hf x hx).has_fderiv_within_at)
(Ξ» x hx, le_trans (by simp) (bound x hx)) hs
/-- The mean value theorem on a convex set in dimension 1: if the derivative of a function within
this set is bounded by `C`, then the function is `C`-Lipschitz. Version with `deriv_within` -/
theorem norm_image_sub_le_of_norm_deriv_within_le {C : β}
(hf : differentiable_on π f s) (bound : βxβs, βderiv_within f s xβ β€ C)
(hs : convex β s) (xs : x β s) (ys : y β s) : βf y - f xβ β€ C * βy - xβ :=
hs.norm_image_sub_le_of_norm_has_deriv_within_le (Ξ» x hx, (hf x hx).has_deriv_within_at)
bound xs ys
/-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is
bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`.
Version with `deriv_within` and `lipschitz_on_with`. -/
theorem lipschitz_on_with_of_nnnorm_deriv_within_le {C : ββ₯0} (hs : convex β s)
(hf : differentiable_on π f s) (bound : βxβs, βderiv_within f s xββ β€ C) :
lipschitz_on_with C f s :=
hs.lipschitz_on_with_of_nnnorm_has_deriv_within_le (Ξ» x hx, (hf x hx).has_deriv_within_at) bound
/-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is
bounded by `C`, then the function is `C`-Lipschitz. Version with `deriv`. -/
theorem norm_image_sub_le_of_norm_deriv_le {C : β}
(hf : β x β s, differentiable_at π f x) (bound : βxβs, βderiv f xβ β€ C)
(hs : convex β s) (xs : x β s) (ys : y β s) : βf y - f xβ β€ C * βy - xβ :=
hs.norm_image_sub_le_of_norm_has_deriv_within_le
(Ξ» x hx, (hf x hx).has_deriv_at.has_deriv_within_at) bound xs ys
/-- The mean value theorem on a convex set in dimension 1: if the derivative of a function is
bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`.
Version with `deriv` and `lipschitz_on_with`. -/
theorem lipschitz_on_with_of_nnnorm_deriv_le {C : ββ₯0}
(hf : β x β s, differentiable_at π f x) (bound : βxβs, βderiv f xββ β€ C)
(hs : convex β s) : lipschitz_on_with C f s :=
hs.lipschitz_on_with_of_nnnorm_has_deriv_within_le
(Ξ» x hx, (hf x hx).has_deriv_at.has_deriv_within_at) bound
/-- The mean value theorem set in dimension 1: if the derivative of a function is bounded by `C`,
then the function is `C`-Lipschitz. Version with `deriv` and `lipschitz_with`. -/
theorem _root_.lipschitz_with_of_nnnorm_deriv_le {C : ββ₯0} (hf : differentiable π f)
(bound : β x, βderiv f xββ β€ C) : lipschitz_with C f :=
lipschitz_on_univ.1 $ convex_univ.lipschitz_on_with_of_nnnorm_deriv_le (Ξ» x hx, hf x)
(Ξ» x hx, bound x)
/-- If `f : π β G`, `π = R` or `π = β`, is differentiable everywhere and its derivative equal zero,
then it is a constant function. -/
theorem _root_.is_const_of_deriv_eq_zero (hf : differentiable π f) (hf' : β x, deriv f x = 0)
(x y : π) :
f x = f y :=
is_const_of_fderiv_eq_zero hf (Ξ» z, by { ext, simp [β deriv_fderiv, hf'] }) _ _
end convex
end
/-! ### Functions `[a, b] β β`. -/
section interval
-- Declare all variables here to make sure they come in a correct order
variables (f f' : β β β) {a b : β} (hab : a < b) (hfc : continuous_on f (Icc a b))
(hff' : β x β Ioo a b, has_deriv_at f (f' x) x) (hfd : differentiable_on β f (Ioo a b))
(g g' : β β β) (hgc : continuous_on g (Icc a b)) (hgg' : β x β Ioo a b, has_deriv_at g (g' x) x)
(hgd : differentiable_on β g (Ioo a b))
include hab hfc hff' hgc hgg'
/-- Cauchy's **Mean Value Theorem**, `has_deriv_at` version. -/
lemma exists_ratio_has_deriv_at_eq_ratio_slope :
β c β Ioo a b, (g b - g a) * f' c = (f b - f a) * g' c :=
begin
let h := Ξ» x, (g b - g a) * f x - (f b - f a) * g x,
have hI : h a = h b,
{ simp only [h], ring },
let h' := Ξ» x, (g b - g a) * f' x - (f b - f a) * g' x,
have hhh' : β x β Ioo a b, has_deriv_at h (h' x) x,
from Ξ» x hx, ((hff' x hx).const_mul (g b - g a)).sub ((hgg' x hx).const_mul (f b - f a)),
have hhc : continuous_on h (Icc a b),
from (continuous_on_const.mul hfc).sub (continuous_on_const.mul hgc),
rcases exists_has_deriv_at_eq_zero h h' hab hhc hI hhh' with β¨c, cmem, hcβ©,
exact β¨c, cmem, sub_eq_zero.1 hcβ©
end
omit hfc hgc
/-- Cauchy's **Mean Value Theorem**, extended `has_deriv_at` version. -/
lemma exists_ratio_has_deriv_at_eq_ratio_slope' {lfa lga lfb lgb : β}
(hff' : β x β Ioo a b, has_deriv_at f (f' x) x) (hgg' : β x β Ioo a b, has_deriv_at g (g' x) x)
(hfa : tendsto f (π[>] a) (π lfa)) (hga : tendsto g (π[>] a) (π lga))
(hfb : tendsto f (π[<] b) (π lfb)) (hgb : tendsto g (π[<] b) (π lgb)) :
β c β Ioo a b, (lgb - lga) * (f' c) = (lfb - lfa) * (g' c) :=
begin
let h := Ξ» x, (lgb - lga) * f x - (lfb - lfa) * g x,
have hha : tendsto h (π[>] a) (π $ lgb * lfa - lfb * lga),
{ have : tendsto h (π[>] a)(π $ (lgb - lga) * lfa - (lfb - lfa) * lga) :=
(tendsto_const_nhds.mul hfa).sub (tendsto_const_nhds.mul hga),
convert this using 2,
ring },
have hhb : tendsto h (π[<] b) (π $ lgb * lfa - lfb * lga),
{ have : tendsto h (π[<] b)(π $ (lgb - lga) * lfb - (lfb - lfa) * lgb) :=
(tendsto_const_nhds.mul hfb).sub (tendsto_const_nhds.mul hgb),
convert this using 2,
ring },
let h' := Ξ» x, (lgb - lga) * f' x - (lfb - lfa) * g' x,
have hhh' : β x β Ioo a b, has_deriv_at h (h' x) x,
{ intros x hx,
exact ((hff' x hx).const_mul _ ).sub (((hgg' x hx)).const_mul _) },
rcases exists_has_deriv_at_eq_zero' hab hha hhb hhh' with β¨c, cmem, hcβ©,
exact β¨c, cmem, sub_eq_zero.1 hcβ©
end
include hfc
omit hgg'
/-- Lagrange's Mean Value Theorem, `has_deriv_at` version -/
lemma exists_has_deriv_at_eq_slope : β c β Ioo a b, f' c = (f b - f a) / (b - a) :=
begin
rcases exists_ratio_has_deriv_at_eq_ratio_slope f f' hab hfc hff'
id 1 continuous_id.continuous_on (Ξ» x hx, has_deriv_at_id x) with β¨c, cmem, hcβ©,
use [c, cmem],
simp only [_root_.id, pi.one_apply, mul_one] at hc,
rw [β hc, mul_div_cancel_left],
exact ne_of_gt (sub_pos.2 hab)
end
omit hff'
/-- Cauchy's Mean Value Theorem, `deriv` version. -/
lemma exists_ratio_deriv_eq_ratio_slope :
β c β Ioo a b, (g b - g a) * (deriv f c) = (f b - f a) * (deriv g c) :=
exists_ratio_has_deriv_at_eq_ratio_slope f (deriv f) hab hfc
(Ξ» x hx, ((hfd x hx).differentiable_at $ is_open.mem_nhds is_open_Ioo hx).has_deriv_at)
g (deriv g) hgc $
Ξ» x hx, ((hgd x hx).differentiable_at $ is_open.mem_nhds is_open_Ioo hx).has_deriv_at
omit hfc
/-- Cauchy's Mean Value Theorem, extended `deriv` version. -/
lemma exists_ratio_deriv_eq_ratio_slope' {lfa lga lfb lgb : β}
(hdf : differentiable_on β f $ Ioo a b) (hdg : differentiable_on β g $ Ioo a b)
(hfa : tendsto f (π[>] a) (π lfa)) (hga : tendsto g (π[>] a) (π lga))
(hfb : tendsto f (π[<] b) (π lfb)) (hgb : tendsto g (π[<] b) (π lgb)) :
β c β Ioo a b, (lgb - lga) * (deriv f c) = (lfb - lfa) * (deriv g c) :=
exists_ratio_has_deriv_at_eq_ratio_slope' _ _ hab _ _
(Ξ» x hx, ((hdf x hx).differentiable_at $ Ioo_mem_nhds hx.1 hx.2).has_deriv_at)
(Ξ» x hx, ((hdg x hx).differentiable_at $ Ioo_mem_nhds hx.1 hx.2).has_deriv_at)
hfa hga hfb hgb
/-- Lagrange's **Mean Value Theorem**, `deriv` version. -/
lemma exists_deriv_eq_slope : β c β Ioo a b, deriv f c = (f b - f a) / (b - a) :=
exists_has_deriv_at_eq_slope f (deriv f) hab hfc
(Ξ» x hx, ((hfd x hx).differentiable_at $ is_open.mem_nhds is_open_Ioo hx).has_deriv_at)
end interval
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y β D`,
`x < y`. -/
theorem convex.mul_sub_lt_image_sub_of_lt_deriv {D : set β} (hD : convex β D) {f : β β β}
(hf : continuous_on f D) (hf' : differentiable_on β f (interior D))
{C} (hf'_gt : β x β interior D, C < deriv f x) :
β x y β D, x < y β C * (y - x) < f y - f x :=
begin
assume x hx y hy hxy,
have hxyD : Icc x y β D, from hD.ord_connected.out hx hy,
have hxyD' : Ioo x y β interior D,
from subset_sUnion_of_mem β¨is_open_Ioo, subset.trans Ioo_subset_Icc_self hxyDβ©,
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x),
from exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD'),
have : C < (f y - f x) / (y - x), by { rw [β ha], exact hf'_gt _ (hxyD' a_mem) },
exact (lt_div_iff (sub_pos.2 hxy)).1 this
end
/-- Let `f : β β β` be a differentiable function. If `C < f'`, then `f` grows faster than
`C * x`, i.e., `C * (y - x) < f y - f x` whenever `x < y`. -/
theorem mul_sub_lt_image_sub_of_lt_deriv {f : β β β} (hf : differentiable β f)
{C} (hf'_gt : β x, C < deriv f x) β¦x yβ¦ (hxy : x < y) :
C * (y - x) < f y - f x :=
convex_univ.mul_sub_lt_image_sub_of_lt_deriv hf.continuous.continuous_on hf.differentiable_on
(Ξ» x _, hf'_gt x) x trivial y trivial hxy
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C β€ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) β€ f y - f x` whenever `x, y β D`,
`x β€ y`. -/
theorem convex.mul_sub_le_image_sub_of_le_deriv {D : set β} (hD : convex β D) {f : β β β}
(hf : continuous_on f D) (hf' : differentiable_on β f (interior D))
{C} (hf'_ge : β x β interior D, C β€ deriv f x) :
β x y β D, x β€ y β C * (y - x) β€ f y - f x :=
begin
assume x hx y hy hxy,
cases eq_or_lt_of_le hxy with hxy' hxy', by rw [hxy', sub_self, sub_self, mul_zero],
have hxyD : Icc x y β D, from hD.ord_connected.out hx hy,
have hxyD' : Ioo x y β interior D,
from subset_sUnion_of_mem β¨is_open_Ioo, subset.trans Ioo_subset_Icc_self hxyDβ©,
obtain β¨a, a_mem, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x),
from exists_deriv_eq_slope f hxy' (hf.mono hxyD) (hf'.mono hxyD'),
have : C β€ (f y - f x) / (y - x), by { rw [β ha], exact hf'_ge _ (hxyD' a_mem) },
exact (le_div_iff (sub_pos.2 hxy')).1 this
end
/-- Let `f : β β β` be a differentiable function. If `C β€ f'`, then `f` grows at least as fast
as `C * x`, i.e., `C * (y - x) β€ f y - f x` whenever `x β€ y`. -/
theorem mul_sub_le_image_sub_of_le_deriv {f : β β β} (hf : differentiable β f)
{C} (hf'_ge : β x, C β€ deriv f x) β¦x yβ¦ (hxy : x β€ y) :
C * (y - x) β€ f y - f x :=
convex_univ.mul_sub_le_image_sub_of_le_deriv hf.continuous.continuous_on hf.differentiable_on
(Ξ» x _, hf'_ge x) x trivial y trivial hxy
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' < C`, then
`f` grows slower than `C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x, y β D`,
`x < y`. -/
theorem convex.image_sub_lt_mul_sub_of_deriv_lt {D : set β} (hD : convex β D) {f : β β β}
(hf : continuous_on f D) (hf' : differentiable_on β f (interior D))
{C} (lt_hf' : β x β interior D, deriv f x < C) :
β x y β D, x < y β f y - f x < C * (y - x) :=
begin
assume x hx y hy hxy,
have hf'_gt : β x β interior D, -C < deriv (Ξ» y, -f y) x,
{ assume x hx,
rw [deriv.neg, neg_lt_neg_iff],
exact lt_hf' x hx },
simpa [-neg_lt_neg_iff]
using neg_lt_neg (hD.mul_sub_lt_image_sub_of_lt_deriv hf.neg hf'.neg hf'_gt x hx y hy hxy)
end
/-- Let `f : β β β` be a differentiable function. If `f' < C`, then `f` grows slower than
`C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x < y`. -/
theorem image_sub_lt_mul_sub_of_deriv_lt {f : β β β} (hf : differentiable β f)
{C} (lt_hf' : β x, deriv f x < C) β¦x yβ¦ (hxy : x < y) :
f y - f x < C * (y - x) :=
convex_univ.image_sub_lt_mul_sub_of_deriv_lt hf.continuous.continuous_on hf.differentiable_on
(Ξ» x _, lt_hf' x) x trivial y trivial hxy
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' β€ C`, then
`f` grows at most as fast as `C * x` on `D`, i.e., `f y - f x β€ C * (y - x)` whenever `x, y β D`,
`x β€ y`. -/
theorem convex.image_sub_le_mul_sub_of_deriv_le {D : set β} (hD : convex β D) {f : β β β}
(hf : continuous_on f D) (hf' : differentiable_on β f (interior D))
{C} (le_hf' : β x β interior D, deriv f x β€ C) :
β x y β D, x β€ y β f y - f x β€ C * (y - x) :=
begin
assume x hx y hy hxy,
have hf'_ge : β x β interior D, -C β€ deriv (Ξ» y, -f y) x,
{ assume x hx,
rw [deriv.neg, neg_le_neg_iff],
exact le_hf' x hx },
simpa [-neg_le_neg_iff]
using neg_le_neg (hD.mul_sub_le_image_sub_of_le_deriv hf.neg hf'.neg hf'_ge x hx y hy hxy)
end
/-- Let `f : β β β` be a differentiable function. If `f' β€ C`, then `f` grows at most as fast
as `C * x`, i.e., `f y - f x β€ C * (y - x)` whenever `x β€ y`. -/
theorem image_sub_le_mul_sub_of_deriv_le {f : β β β} (hf : differentiable β f)
{C} (le_hf' : β x, deriv f x β€ C) β¦x yβ¦ (hxy : x β€ y) :
f y - f x β€ C * (y - x) :=
convex_univ.image_sub_le_mul_sub_of_deriv_le hf.continuous.continuous_on hf.differentiable_on
(Ξ» x _, le_hf' x) x trivial y trivial hxy
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is positive, then
`f` is a strictly monotone function on `D`.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem convex.strict_mono_on_of_deriv_pos {D : set β} (hD : convex β D) {f : β β β}
(hf : continuous_on f D) (hf' : β x β interior D, 0 < deriv f x) :
strict_mono_on f D :=
begin
rintro x hx y hy,
simpa only [zero_mul, sub_pos] using hD.mul_sub_lt_image_sub_of_lt_deriv hf _ hf' x hx y hy,
exact Ξ» z hz, (differentiable_at_of_deriv_ne_zero (hf' z hz).ne').differentiable_within_at,
end
/-- Let `f : β β β` be a differentiable function. If `f'` is positive, then
`f` is a strictly monotone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly positive. -/
theorem strict_mono_of_deriv_pos {f : β β β} (hf' : β x, 0 < deriv f x) : strict_mono f :=
strict_mono_on_univ.1 $ convex_univ.strict_mono_on_of_deriv_pos
(Ξ» z _, (differentiable_at_of_deriv_ne_zero (hf' z).ne').differentiable_within_at
.continuous_within_at)
(Ξ» x _, hf' x)
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonnegative, then
`f` is a monotone function on `D`. -/
theorem convex.monotone_on_of_deriv_nonneg {D : set β} (hD : convex β D) {f : β β β}
(hf : continuous_on f D) (hf' : differentiable_on β f (interior D))
(hf'_nonneg : β x β interior D, 0 β€ deriv f x) :
monotone_on f D :=
Ξ» x hx y hy hxy, by simpa only [zero_mul, sub_nonneg]
using hD.mul_sub_le_image_sub_of_le_deriv hf hf' hf'_nonneg x hx y hy hxy
/-- Let `f : β β β` be a differentiable function. If `f'` is nonnegative, then
`f` is a monotone function. -/
theorem monotone_of_deriv_nonneg {f : β β β} (hf : differentiable β f) (hf' : β x, 0 β€ deriv f x) :
monotone f :=
monotone_on_univ.1 $ convex_univ.monotone_on_of_deriv_nonneg hf.continuous.continuous_on
hf.differentiable_on (Ξ» x _, hf' x)
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is negative, then
`f` is a strictly antitone function on `D`. -/
theorem convex.strict_anti_on_of_deriv_neg {D : set β} (hD : convex β D) {f : β β β}
(hf : continuous_on f D) (hf' : β x β interior D, deriv f x < 0) :
strict_anti_on f D :=
Ξ» x hx y, by simpa only [zero_mul, sub_lt_zero]
using hD.image_sub_lt_mul_sub_of_deriv_lt hf
(Ξ» z hz, (differentiable_at_of_deriv_ne_zero (hf' z hz).ne).differentiable_within_at) hf' x hx y
/-- Let `f : β β β` be a differentiable function. If `f'` is negative, then
`f` is a strictly antitone function.
Note that we don't require differentiability explicitly as it already implied by the derivative
being strictly negative. -/
theorem strict_anti_of_deriv_neg {f : β β β} (hf' : β x, deriv f x < 0) :
strict_anti f :=
strict_anti_on_univ.1 $ convex_univ.strict_anti_on_of_deriv_neg
(Ξ» z _, (differentiable_at_of_deriv_ne_zero (hf' z).ne).differentiable_within_at
.continuous_within_at)
(Ξ» x _, hf' x)
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonpositive, then
`f` is an antitone function on `D`. -/
theorem convex.antitone_on_of_deriv_nonpos {D : set β} (hD : convex β D) {f : β β β}
(hf : continuous_on f D) (hf' : differentiable_on β f (interior D))
(hf'_nonpos : β x β interior D, deriv f x β€ 0) :
antitone_on f D :=
Ξ» x hx y hy hxy, by simpa only [zero_mul, sub_nonpos]
using hD.image_sub_le_mul_sub_of_deriv_le hf hf' hf'_nonpos x hx y hy hxy
/-- Let `f : β β β` be a differentiable function. If `f'` is nonpositive, then
`f` is an antitone function. -/
theorem antitone_of_deriv_nonpos {f : β β β} (hf : differentiable β f) (hf' : β x, deriv f x β€ 0) :
antitone f :=
antitone_on_univ.1 $ convex_univ.antitone_on_of_deriv_nonpos hf.continuous.continuous_on
hf.differentiable_on (Ξ» x _, hf' x)
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is monotone on the interior, then `f` is convex on `D`. -/
theorem monotone_on.convex_on_of_deriv {D : set β} (hD : convex β D) {f : β β β}
(hf : continuous_on f D) (hf' : differentiable_on β f (interior D))
(hf'_mono : monotone_on (deriv f) (interior D)) :
convex_on β D f :=
convex_on_of_slope_mono_adjacent hD
begin
intros x y z hx hz hxy hyz,
-- First we prove some trivial inclusions
have hxzD : Icc x z β D, from hD.ord_connected.out hx hz,
have hxyD : Icc x y β D, from subset.trans (Icc_subset_Icc_right $ le_of_lt hyz) hxzD,
have hxyD' : Ioo x y β interior D,
from subset_sUnion_of_mem β¨is_open_Ioo, subset.trans Ioo_subset_Icc_self hxyDβ©,
have hyzD : Icc y z β D, from subset.trans (Icc_subset_Icc_left $ le_of_lt hxy) hxzD,
have hyzD' : Ioo y z β interior D,
from subset_sUnion_of_mem β¨is_open_Ioo, subset.trans Ioo_subset_Icc_self hyzDβ©,
-- Then we apply MVT to both `[x, y]` and `[y, z]`
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x),
from exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD'),
obtain β¨b, β¨hyb, hbzβ©, hbβ© : β b β Ioo y z, deriv f b = (f z - f y) / (z - y),
from exists_deriv_eq_slope f hyz (hf.mono hyzD) (hf'.mono hyzD'),
rw [β ha, β hb],
exact hf'_mono (hxyD' β¨hxa, hayβ©) (hyzD' β¨hyb, hbzβ©) (hay.trans hyb).le
end
/-- If a function `f` is continuous on a convex set `D β β`, is differentiable on its interior,
and `f'` is antitone on the interior, then `f` is concave on `D`. -/
theorem antitone_on.concave_on_of_deriv {D : set β} (hD : convex β D) {f : β β β}
(hf : continuous_on f D) (hf' : differentiable_on β f (interior D))
(h_anti : antitone_on (deriv f) (interior D)) :
concave_on β D f :=
begin
have : monotone_on (deriv (-f)) (interior D),
{ intros x hx y hy hxy,
convert neg_le_neg (h_anti hx hy hxy);
convert deriv.neg },
exact neg_convex_on_iff.mp (this.convex_on_of_deriv hD hf.neg hf'.neg),
end
lemma strict_mono_on.exists_slope_lt_deriv_aux {x y : β} {f : β β β}
(hf : continuous_on f (Icc x y)) (hxy : x < y)
(hf'_mono : strict_mono_on (deriv f) (Ioo x y)) (h : β w β Ioo x y, deriv f w β 0) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a :=
begin
have A : differentiable_on β f (Ioo x y),
from Ξ» w wmem, (differentiable_at_of_deriv_ne_zero (h w wmem)).differentiable_within_at,
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x),
from exists_deriv_eq_slope f hxy hf A,
rcases nonempty_Ioo.2 hay with β¨b, β¨hab, hbyβ©β©,
refine β¨b, β¨hxa.trans hab, hbyβ©, _β©,
rw β ha,
exact hf'_mono β¨hxa, hayβ© β¨hxa.trans hab, hbyβ© hab
end
lemma strict_mono_on.exists_slope_lt_deriv {x y : β} {f : β β β}
(hf : continuous_on f (Icc x y)) (hxy : x < y)
(hf'_mono : strict_mono_on (deriv f) (Ioo x y)) :
β a β Ioo x y, (f y - f x) / (y - x) < deriv f a :=
begin
by_cases h : β w β Ioo x y, deriv f w β 0,
{ apply strict_mono_on.exists_slope_lt_deriv_aux hf hxy hf'_mono h },
{ push_neg at h,
rcases h with β¨w, β¨hxw, hwyβ©, hwβ©,
obtain β¨a, β¨hxa, hawβ©, haβ© : β (a : β) (H : a β Ioo x w), (f w - f x) / (w - x) < deriv f a,
{ apply strict_mono_on.exists_slope_lt_deriv_aux _ hxw _ _,
{ exact hf.mono (Icc_subset_Icc le_rfl hwy.le) },
{ exact hf'_mono.mono (Ioo_subset_Ioo le_rfl hwy.le) },
{ assume z hz,
rw β hw,
apply ne_of_lt,
exact hf'_mono β¨hz.1, hz.2.trans hwyβ© β¨hxw, hwyβ© hz.2 } },
obtain β¨b, β¨hwb, hbyβ©, hbβ© : β (b : β) (H : b β Ioo w y), (f y - f w) / (y - w) < deriv f b,
{ apply strict_mono_on.exists_slope_lt_deriv_aux _ hwy _ _,
{ refine hf.mono (Icc_subset_Icc hxw.le le_rfl), },
{ exact hf'_mono.mono (Ioo_subset_Ioo hxw.le le_rfl) },
{ assume z hz,
rw β hw,
apply ne_of_gt,
exact hf'_mono β¨hxw, hwyβ© β¨hxw.trans hz.1, hz.2β© hz.1, } },
refine β¨b, β¨hxw.trans hwb, hbyβ©, _β©,
simp only [div_lt_iff, hxy, hxw, hwy, sub_pos] at β’ ha hb,
have : deriv f a * (w - x) < deriv f b * (w - x),
{ apply mul_lt_mul _ le_rfl (sub_pos.2 hxw) _,
{ exact hf'_mono β¨hxa, haw.trans hwyβ© β¨hxw.trans hwb, hbyβ© (haw.trans hwb) },
{ rw β hw,
exact (hf'_mono β¨hxw, hwyβ© β¨hxw.trans hwb, hbyβ© hwb).le } },
linarith }
end
lemma strict_mono_on.exists_deriv_lt_slope_aux {x y : β} {f : β β β}
(hf : continuous_on f (Icc x y)) (hxy : x < y)
(hf'_mono : strict_mono_on (deriv f) (Ioo x y)) (h : β w β Ioo x y, deriv f w β 0) :
β a β Ioo x y, deriv f a < (f y - f x) / (y - x) :=
begin
have A : differentiable_on β f (Ioo x y),
from Ξ» w wmem, (differentiable_at_of_deriv_ne_zero (h w wmem)).differentiable_within_at,
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, deriv f a = (f y - f x) / (y - x),
from exists_deriv_eq_slope f hxy hf A,
rcases nonempty_Ioo.2 hxa with β¨b, β¨hxb, hbaβ©β©,
refine β¨b, β¨hxb, hba.trans hayβ©, _β©,
rw β ha,
exact hf'_mono β¨hxb, hba.trans hayβ© β¨hxa, hayβ© hba
end
lemma strict_mono_on.exists_deriv_lt_slope {x y : β} {f : β β β}
(hf : continuous_on f (Icc x y)) (hxy : x < y)
(hf'_mono : strict_mono_on (deriv f) (Ioo x y)) :
β a β Ioo x y, deriv f a < (f y - f x) / (y - x) :=
begin
by_cases h : β w β Ioo x y, deriv f w β 0,
{ apply strict_mono_on.exists_deriv_lt_slope_aux hf hxy hf'_mono h },
{ push_neg at h,
rcases h with β¨w, β¨hxw, hwyβ©, hwβ©,
obtain β¨a, β¨hxa, hawβ©, haβ© : β (a : β) (H : a β Ioo x w), deriv f a < (f w - f x) / (w - x),
{ apply strict_mono_on.exists_deriv_lt_slope_aux _ hxw _ _,
{ exact hf.mono (Icc_subset_Icc le_rfl hwy.le) },
{ exact hf'_mono.mono (Ioo_subset_Ioo le_rfl hwy.le) },
{ assume z hz,
rw β hw,
apply ne_of_lt,
exact hf'_mono β¨hz.1, hz.2.trans hwyβ© β¨hxw, hwyβ© hz.2 } },
obtain β¨b, β¨hwb, hbyβ©, hbβ© : β (b : β) (H : b β Ioo w y), deriv f b < (f y - f w) / (y - w),
{ apply strict_mono_on.exists_deriv_lt_slope_aux _ hwy _ _,
{ refine hf.mono (Icc_subset_Icc hxw.le le_rfl), },
{ exact hf'_mono.mono (Ioo_subset_Ioo hxw.le le_rfl) },
{ assume z hz,
rw β hw,
apply ne_of_gt,
exact hf'_mono β¨hxw, hwyβ© β¨hxw.trans hz.1, hz.2β© hz.1, } },
refine β¨a, β¨hxa, haw.trans hwyβ©, _β©,
simp only [lt_div_iff, hxy, hxw, hwy, sub_pos] at β’ ha hb,
have : deriv f a * (y - w) < deriv f b * (y - w),
{ apply mul_lt_mul _ le_rfl (sub_pos.2 hwy) _,
{ exact hf'_mono β¨hxa, haw.trans hwyβ© β¨hxw.trans hwb, hbyβ© (haw.trans hwb) },
{ rw β hw,
exact (hf'_mono β¨hxw, hwyβ© β¨hxw.trans hwb, hbyβ© hwb).le } },
linarith }
end
/-- If a function `f` is continuous on a convex set `D β β`, and `f'` is strictly monotone on the
interior, then `f` is strictly convex on `D`.
Note that we don't require differentiability, since it is guaranteed at all but at most
one point by the strict monotonicity of `f'`. -/
lemma strict_mono_on.strict_convex_on_of_deriv {D : set β} (hD : convex β D) {f : β β β}
(hf : continuous_on f D) (hf' : strict_mono_on (deriv f) (interior D)) :
strict_convex_on β D f :=
strict_convex_on_of_slope_strict_mono_adjacent hD
begin
intros x y z hx hz hxy hyz,
-- First we prove some trivial inclusions
have hxzD : Icc x z β D, from hD.ord_connected.out hx hz,
have hxyD : Icc x y β D, from subset.trans (Icc_subset_Icc_right $ le_of_lt hyz) hxzD,
have hxyD' : Ioo x y β interior D,
from subset_sUnion_of_mem β¨is_open_Ioo, subset.trans Ioo_subset_Icc_self hxyDβ©,
have hyzD : Icc y z β D, from subset.trans (Icc_subset_Icc_left $ le_of_lt hxy) hxzD,
have hyzD' : Ioo y z β interior D,
from subset_sUnion_of_mem β¨is_open_Ioo, subset.trans Ioo_subset_Icc_self hyzDβ©,
-- Then we get points `a` and `b` in each interval `[x, y]` and `[y, z]` where the derivatives
-- can be compared to the slopes between `x, y` and `y, z` respectively.
obtain β¨a, β¨hxa, hayβ©, haβ© : β a β Ioo x y, (f y - f x) / (y - x) < deriv f a,
from strict_mono_on.exists_slope_lt_deriv (hf.mono hxyD) hxy (hf'.mono hxyD'),
obtain β¨b, β¨hyb, hbzβ©, hbβ© : β b β Ioo y z, deriv f b < (f z - f y) / (z - y),
from strict_mono_on.exists_deriv_lt_slope (hf.mono hyzD) hyz (hf'.mono hyzD'),
apply ha.trans (lt_trans _ hb),
exact hf' (hxyD' β¨hxa, hayβ©) (hyzD' β¨hyb, hbzβ©) (hay.trans hyb),
end
/-- If a function `f` is continuous on a convex set `D β β` and `f'` is strictly antitone on the
interior, then `f` is strictly concave on `D`.
Note that we don't require differentiability, since it is guaranteed at all but at most
one point by the strict antitonicity of `f'`. -/
lemma strict_anti_on.strict_concave_on_of_deriv {D : set β} (hD : convex β D) {f : β β β}
(hf : continuous_on f D) (h_anti : strict_anti_on (deriv f) (interior D)) :
strict_concave_on β D f :=
begin
have : strict_mono_on (deriv (-f)) (interior D),
{ intros x hx y hy hxy,
convert neg_lt_neg (h_anti hx hy hxy);
convert deriv.neg },
exact neg_strict_convex_on_iff.mp (this.strict_convex_on_of_deriv hD hf.neg),
end
/-- If a function `f` is differentiable and `f'` is monotone on `β` then `f` is convex. -/
theorem monotone.convex_on_univ_of_deriv {f : β β β} (hf : differentiable β f)
(hf'_mono : monotone (deriv f)) : convex_on β univ f :=
(hf'_mono.monotone_on _).convex_on_of_deriv convex_univ hf.continuous.continuous_on
hf.differentiable_on
/-- If a function `f` is differentiable and `f'` is antitone on `β` then `f` is concave. -/
theorem antitone.concave_on_univ_of_deriv {f : β β β} (hf : differentiable β f)
(hf'_anti : antitone (deriv f)) : concave_on β univ f :=
(hf'_anti.antitone_on _).concave_on_of_deriv convex_univ hf.continuous.continuous_on
hf.differentiable_on
/-- If a function `f` is continuous and `f'` is strictly monotone on `β` then `f` is strictly
convex. Note that we don't require differentiability, since it is guaranteed at all but at most
one point by the strict monotonicity of `f'`. -/
lemma strict_mono.strict_convex_on_univ_of_deriv {f : β β β} (hf : continuous f)
(hf'_mono : strict_mono (deriv f)) : strict_convex_on β univ f :=
(hf'_mono.strict_mono_on _).strict_convex_on_of_deriv convex_univ hf.continuous_on
/-- If a function `f` is continuous and `f'` is strictly antitone on `β` then `f` is strictly
concave. Note that we don't require differentiability, since it is guaranteed at all but at most
one point by the strict antitonicity of `f'`. -/
lemma strict_anti.strict_concave_on_univ_of_deriv {f : β β β} (hf : continuous f)
(hf'_anti : strict_anti (deriv f)) : strict_concave_on β univ f :=
(hf'_anti.strict_anti_on _).strict_concave_on_of_deriv convex_univ hf.continuous_on
/-- If a function `f` is continuous on a convex set `D β β`, is twice differentiable on its
interior, and `f''` is nonnegative on the interior, then `f` is convex on `D`. -/
theorem convex_on_of_deriv2_nonneg {D : set β} (hD : convex β D) {f : β β β}
(hf : continuous_on f D) (hf' : differentiable_on β f (interior D))
(hf'' : differentiable_on β (deriv f) (interior D))
(hf''_nonneg : β x β interior D, 0 β€ (deriv^[2] f x)) :
convex_on β D f :=
(hD.interior.monotone_on_of_deriv_nonneg hf''.continuous_on (by rwa interior_interior)
$ by rwa interior_interior).convex_on_of_deriv hD hf hf'
/-- If a function `f` is continuous on a convex set `D β β`, is twice differentiable on its
interior, and `f''` is nonpositive on the interior, then `f` is concave on `D`. -/
theorem concave_on_of_deriv2_nonpos {D : set β} (hD : convex β D) {f : β β β}
(hf : continuous_on f D) (hf' : differentiable_on β f (interior D))
(hf'' : differentiable_on β (deriv f) (interior D))
(hf''_nonpos : β x β interior D, deriv^[2] f x β€ 0) :
concave_on β D f :=
(hD.interior.antitone_on_of_deriv_nonpos hf''.continuous_on (by rwa interior_interior)
$ by rwa interior_interior).concave_on_of_deriv hD hf hf'
/-- If a function `f` is continuous on a convex set `D β β` and `f''` is strictly positive on the
interior, then `f` is strictly convex on `D`.
Note that we don't require twice differentiability explicitly as it is already implied by the second
derivative being strictly positive, except at at most one point. -/
lemma strict_convex_on_of_deriv2_pos {D : set β} (hD : convex β D) {f : β β β}
(hf : continuous_on f D) (hf'' : β x β interior D, 0 < (deriv^[2] f) x) :
strict_convex_on β D f :=
(hD.interior.strict_mono_on_of_deriv_pos (Ξ» z hz,
(differentiable_at_of_deriv_ne_zero (hf'' z hz).ne').differentiable_within_at
.continuous_within_at) $ by rwa interior_interior).strict_convex_on_of_deriv hD hf
/-- If a function `f` is continuous on a convex set `D β β` and `f''` is strictly negative on the
interior, then `f` is strictly concave on `D`.
Note that we don't require twice differentiability explicitly as it already implied by the second
derivative being strictly negative, except at at most one point. -/
lemma strict_concave_on_of_deriv2_neg {D : set β} (hD : convex β D) {f : β β β}
(hf : continuous_on f D) (hf'' : β x β interior D, deriv^[2] f x < 0) :
strict_concave_on β D f :=
(hD.interior.strict_anti_on_of_deriv_neg (Ξ» z hz,
(differentiable_at_of_deriv_ne_zero (hf'' z hz).ne).differentiable_within_at
.continuous_within_at) $ by rwa interior_interior).strict_concave_on_of_deriv hD hf
/-- If a function `f` is twice differentiable on a open convex set `D β β` and
`f''` is nonnegative on `D`, then `f` is convex on `D`. -/
theorem convex_on_of_deriv2_nonneg' {D : set β} (hD : convex β D) {f : β β β}
(hf' : differentiable_on β f D) (hf'' : differentiable_on β (deriv f) D)
(hf''_nonneg : β x β D, 0 β€ (deriv^[2] f) x) : convex_on β D f :=
convex_on_of_deriv2_nonneg hD hf'.continuous_on (hf'.mono interior_subset)
(hf''.mono interior_subset) (Ξ» x hx, hf''_nonneg x (interior_subset hx))
/-- If a function `f` is twice differentiable on an open convex set `D β β` and
`f''` is nonpositive on `D`, then `f` is concave on `D`. -/
theorem concave_on_of_deriv2_nonpos' {D : set β} (hD : convex β D) {f : β β β}
(hf' : differentiable_on β f D) (hf'' : differentiable_on β (deriv f) D)
(hf''_nonpos : β x β D, deriv^[2] f x β€ 0) : concave_on β D f :=
concave_on_of_deriv2_nonpos hD hf'.continuous_on (hf'.mono interior_subset)
(hf''.mono interior_subset) (Ξ» x hx, hf''_nonpos x (interior_subset hx))
/-- If a function `f` is continuous on a convex set `D β β` and `f''` is strictly positive on `D`,
then `f` is strictly convex on `D`.
Note that we don't require twice differentiability explicitly as it is already implied by the second
derivative being strictly positive, except at at most one point. -/
lemma strict_convex_on_of_deriv2_pos' {D : set β} (hD : convex β D)
{f : β β β} (hf : continuous_on f D) (hf'' : β x β D, 0 < (deriv^[2] f) x) :
strict_convex_on β D f :=
strict_convex_on_of_deriv2_pos hD hf $ Ξ» x hx, hf'' x (interior_subset hx)
/-- If a function `f` is continuous on a convex set `D β β` and `f''` is strictly negative on `D`,
then `f` is strictly concave on `D`.
Note that we don't require twice differentiability explicitly as it is already implied by the second
derivative being strictly negative, except at at most one point. -/
lemma strict_concave_on_of_deriv2_neg' {D : set β} (hD : convex β D)
{f : β β β} (hf : continuous_on f D) (hf'' : β x β D, deriv^[2] f x < 0) :
strict_concave_on β D f :=
strict_concave_on_of_deriv2_neg hD hf $ Ξ» x hx, hf'' x (interior_subset hx)
/-- If a function `f` is twice differentiable on `β`, and `f''` is nonnegative on `β`,
then `f` is convex on `β`. -/
theorem convex_on_univ_of_deriv2_nonneg {f : β β β} (hf' : differentiable β f)
(hf'' : differentiable β (deriv f)) (hf''_nonneg : β x, 0 β€ (deriv^[2] f) x) :
convex_on β univ f :=
convex_on_of_deriv2_nonneg' convex_univ hf'.differentiable_on
hf''.differentiable_on (Ξ» x _, hf''_nonneg x)
/-- If a function `f` is twice differentiable on `β`, and `f''` is nonpositive on `β`,
then `f` is concave on `β`. -/
theorem concave_on_univ_of_deriv2_nonpos {f : β β β} (hf' : differentiable β f)
(hf'' : differentiable β (deriv f)) (hf''_nonpos : β x, deriv^[2] f x β€ 0) :
concave_on β univ f :=
concave_on_of_deriv2_nonpos' convex_univ hf'.differentiable_on
hf''.differentiable_on (Ξ» x _, hf''_nonpos x)
/-- If a function `f` is continuous on `β`, and `f''` is strictly positive on `β`,
then `f` is strictly convex on `β`.
Note that we don't require twice differentiability explicitly as it is already implied by the second
derivative being strictly positive, except at at most one point. -/
lemma strict_convex_on_univ_of_deriv2_pos {f : β β β} (hf : continuous f)
(hf'' : β x, 0 < (deriv^[2] f) x) :
strict_convex_on β univ f :=
strict_convex_on_of_deriv2_pos' convex_univ hf.continuous_on $ Ξ» x _, hf'' x
/-- If a function `f` is continuous on `β`, and `f''` is strictly negative on `β`,
then `f` is strictly concave on `β`.
Note that we don't require twice differentiability explicitly as it is already implied by the second
derivative being strictly negative, except at at most one point. -/
lemma strict_concave_on_univ_of_deriv2_neg {f : β β β} (hf : continuous f)
(hf'' : β x, deriv^[2] f x < 0) :
strict_concave_on β univ f :=
strict_concave_on_of_deriv2_neg' convex_univ hf.continuous_on $ Ξ» x _, hf'' x
/-! ### Functions `f : E β β` -/
/-- Lagrange's Mean Value Theorem, applied to convex domains. -/
theorem domain_mvt
{f : E β β} {s : set E} {x y : E} {f' : E β (E βL[β] β)}
(hf : β x β s, has_fderiv_within_at f (f' x) s x) (hs : convex β s) (xs : x β s) (ys : y β s) :
β z β segment β x y, f y - f x = f' z (y - x) :=
begin
have hIccIoo := @Ioo_subset_Icc_self β _ 0 1,
-- parametrize segment
set g : β β E := Ξ» t, x + t β’ (y - x),
have hseg : β t β Icc (0:β) 1, g t β segment β x y,
{ rw segment_eq_image',
simp only [mem_image, and_imp, add_right_inj],
intros t ht, exact β¨t, ht, rflβ© },
have hseg' : Icc 0 1 β g β»ΒΉ' s,
{ rw β image_subset_iff, unfold image, change β _, _,
intros z Hz, rw mem_set_of_eq at Hz, rcases Hz with β¨t, Ht, hgtβ©,
rw β hgt, exact hs.segment_subset xs ys (hseg t Ht) },
-- derivative of pullback of f under parametrization
have hfg: β t β Icc (0:β) 1, has_deriv_within_at (f β g)
((f' (g t) : E β β) (y-x)) (Icc (0:β) 1) t,
{ intros t Ht,
have hg : has_deriv_at g (y-x) t,
{ have := ((has_deriv_at_id t).smul_const (y - x)).const_add x,
rwa one_smul at this },
exact (hf (g t) $ hseg' Ht).comp_has_deriv_within_at _ hg.has_deriv_within_at hseg' },
-- apply 1-variable mean value theorem to pullback
have hMVT : β (t β Ioo (0:β) 1), ((f' (g t) : E β β) (y-x)) = (f (g 1) - f (g 0)) / (1 - 0),
{ refine exists_has_deriv_at_eq_slope (f β g) _ (by norm_num) _ _,
{ exact Ξ» t Ht, (hfg t Ht).continuous_within_at },
{ exact Ξ» t Ht, (hfg t $ hIccIoo Ht).has_deriv_at (Icc_mem_nhds Ht.1 Ht.2) } },
-- reinterpret on domain
rcases hMVT with β¨t, Ht, hMVT'β©,
use g t, refine β¨hseg t $ hIccIoo Ht, _β©,
simp [g, hMVT'],
end
section is_R_or_C
/-!
### Vector-valued functions `f : E β F`. Strict differentiability.
A `C^1` function is strictly differentiable, when the field is `β` or `β`. This follows from the
mean value inequality on balls, which is a particular case of the above results after restricting
the scalars to `β`. Note that it does not make sense to talk of a convex set over `β`, but balls
make sense and are enough. Many formulations of the mean value inequality could be generalized to
balls over `β` or `β`. For now, we only include the ones that we need.
-/
variables {π : Type*} [is_R_or_C π] {G : Type*} [normed_add_comm_group G] [normed_space π G]
{H : Type*} [normed_add_comm_group H] [normed_space π H] {f : G β H} {f' : G β G βL[π] H} {x : G}
/-- Over the reals or the complexes, a continuously differentiable function is strictly
differentiable. -/
lemma has_strict_fderiv_at_of_has_fderiv_at_of_continuous_at
(hder : βαΆ y in π x, has_fderiv_at f (f' y) y) (hcont : continuous_at f' x) :
has_strict_fderiv_at f (f' x) x :=
begin
-- turn little-o definition of strict_fderiv into an epsilon-delta statement
refine is_o_iff.mpr (Ξ» c hc, metric.eventually_nhds_iff_ball.mpr _),
-- the correct Ξ΅ is the modulus of continuity of f'
rcases metric.mem_nhds_iff.mp (inter_mem hder (hcont $ ball_mem_nhds _ hc)) with β¨Ξ΅, Ξ΅0, hΞ΅β©,
refine β¨Ξ΅, Ξ΅0, _β©,
-- simplify formulas involving the product E Γ E
rintros β¨a, bβ© h,
rw [β ball_prod_same, prod_mk_mem_set_prod_eq] at h,
-- exploit the choice of Ξ΅ as the modulus of continuity of f'
have hf' : β x' β ball x Ξ΅, βf' x' - f' xβ β€ c,
{ intros x' H', rw β dist_eq_norm, exact le_of_lt (hΞ΅ H').2 },
-- apply mean value theorem
letI : normed_space β G := restrict_scalars.normed_space β π G,
refine (convex_ball _ _).norm_image_sub_le_of_norm_has_fderiv_within_le' _ hf' h.2 h.1,
exact Ξ» y hy, (hΞ΅ hy).1.has_fderiv_within_at
end
/-- Over the reals or the complexes, a continuously differentiable function is strictly
differentiable. -/
lemma has_strict_deriv_at_of_has_deriv_at_of_continuous_at {f f' : π β G} {x : π}
(hder : βαΆ y in π x, has_deriv_at f (f' y) y) (hcont : continuous_at f' x) :
has_strict_deriv_at f (f' x) x :=
has_strict_fderiv_at_of_has_fderiv_at_of_continuous_at (hder.mono (Ξ» y hy, hy.has_fderiv_at)) $
(smul_rightL π π G 1).continuous.continuous_at.comp hcont
end is_R_or_C
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.