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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
36f47cc2798bf9d8d2cfea604f1d52b7d469cb20 | 74addaa0e41490cbaf2abd313a764c96df57b05d | /Mathlib/data/real/basic.lean | a2202fbf3dad6688510b3b84b34448614a43a849 | [] | 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 | 15,354 | lean | /-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Floris van Doorn
The (classical) real numbers β. This is a direct construction
from Cauchy sequences.
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.order.conditionally_complete_lattice
import Mathlib.data.real.cau_seq_completion
import Mathlib.algebra.archimedean
import Mathlib.algebra.star.basic
import Mathlib.PostPort
namespace Mathlib
/-- The type `β` of real numbers constructed as equivalence classes of Cauchy sequences of rational
numbers. -/
def real :=
cau_seq.completion.Cauchy
notation:1024 "β" => Mathlib.real
namespace real
def comm_ring_aux : comm_ring β :=
cau_seq.completion.Cauchy.comm_ring
protected instance comm_ring : comm_ring β :=
comm_ring.mk comm_ring.add comm_ring.add_assoc comm_ring.zero comm_ring.zero_add comm_ring.add_zero comm_ring.neg
comm_ring.sub comm_ring.add_left_neg comm_ring.add_comm comm_ring.mul comm_ring.mul_assoc comm_ring.one
comm_ring.one_mul comm_ring.mul_one comm_ring.left_distrib comm_ring.right_distrib comm_ring.mul_comm
/- Extra instances to short-circuit type class resolution -/
protected instance ring : ring β :=
comm_ring.to_ring β
protected instance comm_semiring : comm_semiring β :=
comm_ring.to_comm_semiring
protected instance semiring : semiring β :=
ring.to_semiring
protected instance add_comm_group : add_comm_group β :=
ring.to_add_comm_group β
protected instance add_group : add_group β :=
add_comm_group.to_add_group β
protected instance add_comm_monoid : add_comm_monoid β :=
add_comm_group.to_add_comm_monoid β
protected instance add_monoid : add_monoid β :=
sub_neg_monoid.to_add_monoid β
protected instance add_left_cancel_semigroup : add_left_cancel_semigroup β :=
add_left_cancel_monoid.to_add_left_cancel_semigroup β
protected instance add_right_cancel_semigroup : add_right_cancel_semigroup β :=
add_right_cancel_monoid.to_add_right_cancel_semigroup β
protected instance add_comm_semigroup : add_comm_semigroup β :=
add_comm_monoid.to_add_comm_semigroup β
protected instance add_semigroup : add_semigroup β :=
add_monoid.to_add_semigroup β
protected instance comm_monoid : comm_monoid β :=
comm_semiring.to_comm_monoid β
protected instance monoid : monoid β :=
ring.to_monoid β
protected instance comm_semigroup : comm_semigroup β :=
comm_ring.to_comm_semigroup β
protected instance semigroup : semigroup β :=
monoid.to_semigroup β
protected instance inhabited : Inhabited β :=
{ default := 0 }
/-- The real numbers are a *-ring, with the trivial *-structure. -/
protected instance star_ring : star_ring β :=
star_ring_of_comm
/-- Coercion `β` β `β` as a `ring_hom`. Note that this
is `cau_seq.completion.of_rat`, not `rat.cast`. -/
def of_rat : β β+* β :=
ring_hom.mk cau_seq.completion.of_rat sorry sorry sorry sorry
/-- Make a real number from a Cauchy sequence of rationals (by taking the equivalence class). -/
def mk (x : cau_seq β abs) : β :=
cau_seq.completion.mk x
theorem of_rat_sub (x : β) (y : β) : coe_fn of_rat (x - y) = coe_fn of_rat x - coe_fn of_rat y :=
congr_arg mk (cau_seq.const_sub x y)
protected instance has_lt : HasLess β :=
{ Less := fun (x y : β) => quotient.lift_onβ x y Less sorry }
@[simp] theorem mk_lt {f : cau_seq β abs} {g : cau_seq β abs} : mk f < mk g β f < g :=
iff.rfl
theorem mk_eq {f : cau_seq β abs} {g : cau_seq β abs} : mk f = mk g β f β g :=
cau_seq.completion.mk_eq
theorem quotient_mk_eq_mk (f : cau_seq β abs) : quotient.mk f = mk f :=
rfl
theorem mk_eq_mk {f : cau_seq β abs} : cau_seq.completion.mk f = mk f :=
rfl
@[simp] theorem mk_pos {f : cau_seq β abs} : 0 < mk f β cau_seq.pos f :=
iff_of_eq (congr_arg cau_seq.pos (sub_zero f))
protected def le (x : β) (y : β) :=
x < y β¨ x = y
protected instance has_le : HasLessEq β :=
{ LessEq := real.le }
@[simp] theorem mk_le {f : cau_seq β abs} {g : cau_seq β abs} : mk f β€ mk g β f β€ g :=
or_congr iff.rfl quotient.eq
theorem add_lt_add_iff_left {a : β} {b : β} (c : β) : c + a < c + b β a < b := sorry
protected instance partial_order : partial_order β :=
partial_order.mk LessEq Less sorry sorry sorry
protected instance preorder : preorder β :=
partial_order.to_preorder β
theorem of_rat_lt {x : β} {y : β} : coe_fn of_rat x < coe_fn of_rat y β x < y :=
cau_seq.const_lt
protected theorem zero_lt_one : 0 < 1 :=
iff.mpr of_rat_lt zero_lt_one
protected theorem mul_pos {a : β} {b : β} : 0 < a β 0 < b β 0 < a * b := sorry
protected instance ordered_ring : ordered_ring β :=
ordered_ring.mk comm_ring.add comm_ring.add_assoc comm_ring.zero comm_ring.zero_add comm_ring.add_zero comm_ring.neg
comm_ring.sub comm_ring.add_left_neg comm_ring.add_comm comm_ring.mul comm_ring.mul_assoc comm_ring.one
comm_ring.one_mul comm_ring.mul_one comm_ring.left_distrib comm_ring.right_distrib partial_order.le partial_order.lt
partial_order.le_refl partial_order.le_trans partial_order.le_antisymm sorry sorry real.mul_pos
protected instance ordered_semiring : ordered_semiring β :=
ordered_ring.to_ordered_semiring
protected instance ordered_add_comm_group : ordered_add_comm_group β :=
ordered_ring.to_ordered_add_comm_group β
protected instance ordered_cancel_add_comm_monoid : ordered_cancel_add_comm_monoid β :=
ordered_semiring.to_ordered_cancel_add_comm_monoid β
protected instance ordered_add_comm_monoid : ordered_add_comm_monoid β :=
ordered_cancel_add_comm_monoid.to_ordered_add_comm_monoid
protected instance has_one : HasOne β :=
monoid.to_has_one β
protected instance has_zero : HasZero β :=
mul_zero_class.to_has_zero β
protected instance has_mul : Mul β :=
distrib.to_has_mul β
protected instance has_add : Add β :=
distrib.to_has_add β
protected instance has_sub : Sub β :=
sub_neg_monoid.to_has_sub β
protected instance nontrivial : nontrivial β :=
nontrivial.mk (Exists.intro 0 (Exists.intro 1 (ne_of_lt real.zero_lt_one)))
protected instance linear_order : linear_order β :=
linear_order.mk partial_order.le partial_order.lt partial_order.le_refl partial_order.le_trans partial_order.le_antisymm
sorry (fun (a b : β) => classical.prop_decidable (a β€ b)) Mathlib.decidable_eq_of_decidable_le
Mathlib.decidable_lt_of_decidable_le
protected instance linear_ordered_comm_ring : linear_ordered_comm_ring β :=
linear_ordered_comm_ring.mk ordered_ring.add ordered_ring.add_assoc ordered_ring.zero ordered_ring.zero_add
ordered_ring.add_zero ordered_ring.neg ordered_ring.sub ordered_ring.add_left_neg ordered_ring.add_comm
ordered_ring.mul ordered_ring.mul_assoc ordered_ring.one ordered_ring.one_mul ordered_ring.mul_one
ordered_ring.left_distrib ordered_ring.right_distrib ordered_ring.le ordered_ring.lt ordered_ring.le_refl
ordered_ring.le_trans ordered_ring.le_antisymm ordered_ring.add_le_add_left ordered_ring.zero_le_one
ordered_ring.mul_pos linear_order.le_total linear_order.decidable_le linear_order.decidable_eq
linear_order.decidable_lt nontrivial.exists_pair_ne comm_ring.mul_comm
/- Extra instances to short-circuit type class resolution -/
protected instance linear_ordered_ring : linear_ordered_ring β :=
linear_ordered_comm_ring.to_linear_ordered_ring β
protected instance linear_ordered_semiring : linear_ordered_semiring β :=
linear_ordered_comm_ring.to_linear_ordered_semiring
protected instance domain : domain β :=
domain.mk comm_ring.add comm_ring.add_assoc comm_ring.zero comm_ring.zero_add comm_ring.add_zero comm_ring.neg
comm_ring.sub comm_ring.add_left_neg comm_ring.add_comm comm_ring.mul comm_ring.mul_assoc comm_ring.one
comm_ring.one_mul comm_ring.mul_one comm_ring.left_distrib comm_ring.right_distrib nontrivial.exists_pair_ne sorry
protected instance linear_ordered_field : linear_ordered_field β := sorry
/- Extra instances to short-circuit type class resolution -/
protected instance linear_ordered_add_comm_group : linear_ordered_add_comm_group β :=
linear_ordered_ring.to_linear_ordered_add_comm_group
protected instance field : field β :=
linear_ordered_field.to_field β
protected instance division_ring : division_ring β :=
field.to_division_ring
protected instance integral_domain : integral_domain β :=
field.to_integral_domain
protected instance distrib_lattice : distrib_lattice β :=
Mathlib.distrib_lattice_of_linear_order
protected instance lattice : lattice β :=
Mathlib.lattice_of_linear_order
protected instance semilattice_inf : semilattice_inf β :=
lattice.to_semilattice_inf β
protected instance semilattice_sup : semilattice_sup β :=
lattice.to_semilattice_sup β
protected instance has_inf : has_inf β :=
semilattice_inf.to_has_inf β
protected instance has_sup : has_sup β :=
semilattice_sup.to_has_sup β
protected instance decidable_lt (a : β) (b : β) : Decidable (a < b) :=
has_lt.lt.decidable a b
protected instance decidable_le (a : β) (b : β) : Decidable (a β€ b) :=
has_le.le.decidable a b
protected instance decidable_eq (a : β) (b : β) : Decidable (a = b) :=
quotient.decidable_eq a b
@[simp] theorem of_rat_eq_cast (x : β) : coe_fn of_rat x = βx :=
ring_hom.eq_rat_cast of_rat
theorem le_mk_of_forall_le {x : β} {f : cau_seq β abs} : (β (i : β), β (j : β), j β₯ i β x β€ β(coe_fn f j)) β x β€ mk f := sorry
theorem mk_le_of_forall_le {f : cau_seq β abs} {x : β} : (β (i : β), β (j : β), j β₯ i β β(coe_fn f j) β€ x) β mk f β€ x := sorry
theorem mk_near_of_forall_near {f : cau_seq β abs} {x : β} {Ξ΅ : β} (H : β (i : β), β (j : β), j β₯ i β abs (β(coe_fn f j) - x) β€ Ξ΅) : abs (mk f - x) β€ Ξ΅ := sorry
protected instance archimedean : archimedean β :=
iff.mpr archimedean_iff_rat_le fun (x : β) => quotient.induction_on x fun (f : cau_seq β abs) => sorry
/- mark `real` irreducible in order to prevent `auto_cases` unfolding reals,
since users rarely want to consider real numbers as Cauchy sequences.
Marking `comm_ring_aux` `irreducible` is done to ensure that there are no problems
with non definitionally equal instances, caused by making `real` irreducible-/
protected instance floor_ring : floor_ring β :=
archimedean.floor_ring β
theorem is_cau_seq_iff_lift {f : β β β} : is_cau_seq abs f β is_cau_seq abs fun (i : β) => β(f i) := sorry
theorem of_near (f : β β β) (x : β) (h : β (Ξ΅ : β), Ξ΅ > 0 β β (i : β), β (j : β), j β₯ i β abs (β(f j) - x) < Ξ΅) : β (h' : is_cau_seq abs f), mk { val := f, property := h' } = x := sorry
theorem exists_floor (x : β) : β (ub : β€), βub β€ x β§ β (z : β€), βz β€ x β z β€ ub := sorry
theorem exists_sup (S : set β) : (β (x : β), x β S) β (β (x : β), β (y : β), y β S β y β€ x) β β (x : β), β (y : β), x β€ y β β (z : β), z β S β z β€ y := sorry
protected instance has_Sup : has_Sup β :=
has_Sup.mk
fun (S : set β) =>
dite ((β (x : β), x β S) β§ β (x : β), β (y : β), y β S β y β€ x)
(fun (h : (β (x : β), x β S) β§ β (x : β), β (y : β), y β S β y β€ x) => classical.some sorry)
fun (h : Β¬((β (x : β), x β S) β§ β (x : β), β (y : β), y β S β y β€ x)) => 0
theorem Sup_def (S : set β) : Sup S =
dite ((β (x : β), x β S) β§ β (x : β), β (y : β), y β S β y β€ x)
(fun (h : (β (x : β), x β S) β§ β (x : β), β (y : β), y β S β y β€ x) =>
classical.some (exists_sup S (and.left h) (and.right h)))
fun (h : Β¬((β (x : β), x β S) β§ β (x : β), β (y : β), y β S β y β€ x)) => 0 :=
rfl
theorem Sup_le (S : set β) (hβ : β (x : β), x β S) (hβ : β (x : β), β (y : β), y β S β y β€ x) {y : β} : Sup S β€ y β β (z : β), z β S β z β€ y := sorry
-- this proof times out without this
theorem lt_Sup (S : set β) (hβ : β (x : β), x β S) (hβ : β (x : β), β (y : β), y β S β y β€ x) {y : β} : y < Sup S β β (z : β), β (H : z β S), y < z := sorry
theorem le_Sup (S : set β) (hβ : β (x : β), β (y : β), y β S β y β€ x) {x : β} (xS : x β S) : x β€ Sup S :=
iff.mp (Sup_le S (Exists.intro x xS) hβ) (le_refl (Sup S)) x xS
theorem Sup_le_ub (S : set β) (hβ : β (x : β), x β S) {ub : β} (hβ : β (y : β), y β S β y β€ ub) : Sup S β€ ub :=
iff.mpr (Sup_le S hβ (Exists.intro ub hβ)) hβ
protected theorem is_lub_Sup {s : set β} {a : β} {b : β} (ha : a β s) (hb : b β upper_bounds s) : is_lub s (Sup s) :=
{ left := fun (x : β) (xs : x β s) => le_Sup s (Exists.intro b hb) xs,
right := fun (u : β) (h : u β upper_bounds s) => Sup_le_ub s (Exists.intro a ha) h }
protected instance has_Inf : has_Inf β :=
has_Inf.mk fun (S : set β) => -Sup (set_of fun (x : β) => -x β S)
theorem Inf_def (S : set β) : Inf S = -Sup (set_of fun (x : β) => -x β S) :=
rfl
theorem le_Inf (S : set β) (hβ : β (x : β), x β S) (hβ : β (x : β), β (y : β), y β S β x β€ y) {y : β} : y β€ Inf S β β (z : β), z β S β y β€ z := sorry
-- this proof times out without this
theorem Inf_lt (S : set β) (hβ : β (x : β), x β S) (hβ : β (x : β), β (y : β), y β S β x β€ y) {y : β} : Inf S < y β β (z : β), β (H : z β S), z < y := sorry
theorem Inf_le (S : set β) (hβ : β (x : β), β (y : β), y β S β x β€ y) {x : β} (xS : x β S) : Inf S β€ x :=
iff.mp (le_Inf S (Exists.intro x xS) hβ) (le_refl (Inf S)) x xS
theorem lb_le_Inf (S : set β) (hβ : β (x : β), x β S) {lb : β} (hβ : β (y : β), y β S β lb β€ y) : lb β€ Inf S :=
iff.mpr (le_Inf S hβ (Exists.intro lb hβ)) hβ
protected instance conditionally_complete_linear_order : conditionally_complete_linear_order β :=
conditionally_complete_linear_order.mk lattice.sup linear_order.le linear_order.lt linear_order.le_refl
linear_order.le_trans linear_order.le_antisymm lattice.le_sup_left lattice.le_sup_right lattice.sup_le lattice.inf
lattice.inf_le_left lattice.inf_le_right lattice.le_inf Sup Inf sorry sorry sorry sorry linear_order.le_total
(classical.dec_rel LessEq) linear_order.decidable_eq linear_order.decidable_lt
theorem Sup_empty : Sup β
= 0 := sorry
theorem Sup_of_not_bdd_above {s : set β} (hs : Β¬bdd_above s) : Sup s = 0 :=
dif_neg fun (h : (β (x : β), x β s) β§ β (x : β), β (y : β), y β s β y β€ x) => hs (and.right h)
theorem Sup_univ : Sup set.univ = 0 := sorry
theorem Inf_empty : Inf β
= 0 := sorry
theorem Inf_of_not_bdd_below {s : set β} (hs : Β¬bdd_below s) : Inf s = 0 := sorry
theorem cau_seq_converges (f : cau_seq β abs) : β (x : β), f β cau_seq.const abs x := sorry
protected instance abs.cau_seq.is_complete : cau_seq.is_complete β abs :=
cau_seq.is_complete.mk cau_seq_converges
|
aae6b4ffa71669c193159c36f979a49ee035c4b4 | d406927ab5617694ec9ea7001f101b7c9e3d9702 | /src/data/real/cardinality.lean | 58db59e8ab65a26c595a86442a0a8ec3c56d415e | [
"Apache-2.0"
] | permissive | alreadydone/mathlib | dc0be621c6c8208c581f5170a8216c5ba6721927 | c982179ec21091d3e102d8a5d9f5fe06c8fafb73 | refs/heads/master | 1,685,523,275,196 | 1,670,184,141,000 | 1,670,184,141,000 | 287,574,545 | 0 | 0 | Apache-2.0 | 1,670,290,714,000 | 1,597,421,623,000 | Lean | UTF-8 | Lean | false | false | 9,603 | 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.specific_limits.basic
import data.rat.denumerable
import data.set.pointwise.interval
import set_theory.cardinal.continuum
/-!
# The cardinality of the reals
This file shows that the real numbers have cardinality continuum, i.e. `#β = π `.
We show that `#β β€ π ` by noting that every real number is determined by a Cauchy-sequence of the
form `β β β`, which has cardinality `π `. To show that `#β β₯ π ` we define an injection from
`{0, 1} ^ β` to `β` with `f β¦ Ξ£ n, f n * (1 / 3) ^ n`.
We conclude that all intervals with distinct endpoints have cardinality continuum.
## Main definitions
* `cardinal.cantor_function` is the function that sends `f` in `{0, 1} ^ β` to `β` by
`f β¦ Ξ£' n, f n * (1 / 3) ^ n`
## Main statements
* `cardinal.mk_real : #β = π `: the reals have cardinality continuum.
* `cardinal.not_countable_real`: the universal set of real numbers is not countable.
We can use this same proof to show that all the other sets in this file are not countable.
* 8 lemmas of the form `mk_Ixy_real` for `x,y β {i,o,c}` state that intervals on the reals
have cardinality continuum.
## Notation
* `π ` : notation for `cardinal.continuum` in locale `cardinal`, defined in `set_theory.continuum`.
## Tags
continuum, cardinality, reals, cardinality of the reals
-/
open nat set
open_locale cardinal
noncomputable theory
namespace cardinal
variables {c : β} {f g : β β bool} {n : β}
/-- The body of the sum in `cantor_function`.
`cantor_function_aux c f n = c ^ n` if `f n = tt`;
`cantor_function_aux c f n = 0` if `f n = ff`. -/
def cantor_function_aux (c : β) (f : β β bool) (n : β) : β := cond (f n) (c ^ n) 0
@[simp] lemma cantor_function_aux_tt (h : f n = tt) : cantor_function_aux c f n = c ^ n :=
by simp [cantor_function_aux, h]
@[simp] lemma cantor_function_aux_ff (h : f n = ff) : cantor_function_aux c f n = 0 :=
by simp [cantor_function_aux, h]
lemma cantor_function_aux_nonneg (h : 0 β€ c) : 0 β€ cantor_function_aux c f n :=
by { cases h' : f n; simp [h'], apply pow_nonneg h }
lemma cantor_function_aux_eq (h : f n = g n) :
cantor_function_aux c f n = cantor_function_aux c g n :=
by simp [cantor_function_aux, h]
lemma cantor_function_aux_succ (f : β β bool) :
(Ξ» n, cantor_function_aux c f (n + 1)) = Ξ» n, c * cantor_function_aux c (Ξ» n, f (n + 1)) n :=
by { ext n, cases h : f (n + 1); simp [h, pow_succ] }
lemma summable_cantor_function (f : β β bool) (h1 : 0 β€ c) (h2 : c < 1) :
summable (cantor_function_aux c f) :=
begin
apply (summable_geometric_of_lt_1 h1 h2).summable_of_eq_zero_or_self,
intro n, cases h : f n; simp [h]
end
/-- `cantor_function c (f : β β bool)` is `Ξ£ n, f n * c ^ n`, where `tt` is interpreted as `1` and
`ff` is interpreted as `0`. It is implemented using `cantor_function_aux`. -/
def cantor_function (c : β) (f : β β bool) : β := β' n, cantor_function_aux c f n
lemma cantor_function_le (h1 : 0 β€ c) (h2 : c < 1) (h3 : β n, f n β g n) :
cantor_function c f β€ cantor_function c g :=
begin
apply tsum_le_tsum _ (summable_cantor_function f h1 h2) (summable_cantor_function g h1 h2),
intro n, cases h : f n, simp [h, cantor_function_aux_nonneg h1],
replace h3 : g n = tt := h3 n h, simp [h, h3]
end
lemma cantor_function_succ (f : β β bool) (h1 : 0 β€ c) (h2 : c < 1) :
cantor_function c f = cond (f 0) 1 0 + c * cantor_function c (Ξ» n, f (n+1)) :=
begin
rw [cantor_function, tsum_eq_zero_add (summable_cantor_function f h1 h2)],
rw [cantor_function_aux_succ, tsum_mul_left, cantor_function_aux, pow_zero],
refl
end
/-- `cantor_function c` is strictly increasing with if `0 < c < 1/2`, if we endow `β β bool` with a
lexicographic order. The lexicographic order doesn't exist for these infinitary products, so we
explicitly write out what it means. -/
lemma increasing_cantor_function (h1 : 0 < c) (h2 : c < 1 / 2) {n : β} {f g : β β bool}
(hn : β(k < n), f k = g k) (fn : f n = ff) (gn : g n = tt) :
cantor_function c f < cantor_function c g :=
begin
have h3 : c < 1, { apply h2.trans, norm_num },
induction n with n ih generalizing f g,
{ let f_max : β β bool := Ξ» n, nat.rec ff (Ξ» _ _, tt) n,
have hf_max : βn, f n β f_max n,
{ intros n hn, cases n, rw [fn] at hn, contradiction, apply rfl },
let g_min : β β bool := Ξ» n, nat.rec tt (Ξ» _ _, ff) n,
have hg_min : βn, g_min n β g n,
{ intros n hn, cases n, rw [gn], apply rfl, contradiction },
apply (cantor_function_le (le_of_lt h1) h3 hf_max).trans_lt,
refine lt_of_lt_of_le _ (cantor_function_le (le_of_lt h1) h3 hg_min),
have : c / (1 - c) < 1,
{ rw [div_lt_one, lt_sub_iff_add_lt],
{ convert add_lt_add h2 h2, norm_num },
rwa sub_pos },
convert this,
{ rw [cantor_function_succ _ (le_of_lt h1) h3, div_eq_mul_inv,
βtsum_geometric_of_lt_1 (le_of_lt h1) h3],
apply zero_add },
{ convert tsum_eq_single 0 _,
{ apply_instance },
{ intros n hn, cases n, contradiction, refl } } },
rw [cantor_function_succ f (le_of_lt h1) h3, cantor_function_succ g (le_of_lt h1) h3],
rw [hn 0 $ zero_lt_succ n],
apply add_lt_add_left, rw mul_lt_mul_left h1, exact ih (Ξ» k hk, hn _ $ nat.succ_lt_succ hk) fn gn
end
/-- `cantor_function c` is injective if `0 < c < 1/2`. -/
lemma cantor_function_injective (h1 : 0 < c) (h2 : c < 1 / 2) :
function.injective (cantor_function c) :=
begin
intros f g hfg, classical, by_contra h, revert hfg,
have : βn, f n β g n,
{ rw [βnot_forall], intro h', apply h, ext, apply h' },
let n := nat.find this,
have hn : β (k : β), k < n β f k = g k,
{ intros k hk, apply of_not_not, exact nat.find_min this hk },
cases fn : f n,
{ apply ne_of_lt, refine increasing_cantor_function h1 h2 hn fn _,
apply eq_tt_of_not_eq_ff, rw [βfn], apply ne.symm, exact nat.find_spec this },
{ apply ne_of_gt, refine increasing_cantor_function h1 h2 (Ξ» k hk, (hn k hk).symm) _ fn,
apply eq_ff_of_not_eq_tt, rw [βfn], apply ne.symm, exact nat.find_spec this }
end
/-- The cardinality of the reals, as a type. -/
lemma mk_real : #β = π :=
begin
apply le_antisymm,
{ rw real.equiv_Cauchy.cardinal_eq,
apply mk_quotient_le.trans, apply (mk_subtype_le _).trans_eq,
rw [β power_def, mk_nat, mk_rat, aleph_0_power_aleph_0] },
{ convert mk_le_of_injective (cantor_function_injective _ _),
rw [βpower_def, mk_bool, mk_nat, two_power_aleph_0], exact 1 / 3, norm_num, norm_num }
end
/-- The cardinality of the reals, as a set. -/
lemma mk_univ_real : #(set.univ : set β) = π :=
by rw [mk_univ, mk_real]
/-- **Non-Denumerability of the Continuum**: The reals are not countable. -/
lemma not_countable_real : Β¬ (set.univ : set β).countable :=
by { rw [β le_aleph_0_iff_set_countable, not_le, mk_univ_real], apply cantor }
/-- The cardinality of the interval (a, β). -/
lemma mk_Ioi_real (a : β) : #(Ioi a) = π :=
begin
refine le_antisymm (mk_real βΈ mk_set_le _) _,
rw [β not_lt], intro h,
refine ne_of_lt _ mk_univ_real,
have hu : Iio a βͺ {a} βͺ Ioi a = set.univ,
{ convert Iic_union_Ioi, exact Iio_union_right },
rw β hu,
refine lt_of_le_of_lt (mk_union_le _ _) _,
refine lt_of_le_of_lt (add_le_add_right (mk_union_le _ _) _) _,
have h2 : (Ξ» x, a + a - x) '' Ioi a = Iio a,
{ convert image_const_sub_Ioi _ _, simp },
rw β h2,
refine add_lt_of_lt (cantor _).le _ h,
refine add_lt_of_lt (cantor _).le (mk_image_le.trans_lt h) _,
rw mk_singleton,
exact one_lt_aleph_0.trans (cantor _)
end
/-- The cardinality of the interval [a, β). -/
lemma mk_Ici_real (a : β) : #(Ici a) = π :=
le_antisymm (mk_real βΈ mk_set_le _) (mk_Ioi_real a βΈ mk_le_mk_of_subset Ioi_subset_Ici_self)
/-- The cardinality of the interval (-β, a). -/
lemma mk_Iio_real (a : β) : #(Iio a) = π :=
begin
refine le_antisymm (mk_real βΈ mk_set_le _) _,
have h2 : (Ξ» x, a + a - x) '' Iio a = Ioi a,
{ convert image_const_sub_Iio _ _, simp },
exact mk_Ioi_real a βΈ h2 βΈ mk_image_le
end
/-- The cardinality of the interval (-β, a]. -/
lemma mk_Iic_real (a : β) : #(Iic a) = π :=
le_antisymm (mk_real βΈ mk_set_le _) (mk_Iio_real a βΈ mk_le_mk_of_subset Iio_subset_Iic_self)
/-- The cardinality of the interval (a, b). -/
lemma mk_Ioo_real {a b : β} (h : a < b) : #(Ioo a b) = π :=
begin
refine le_antisymm (mk_real βΈ mk_set_le _) _,
have h1 : #((Ξ» x, x - a) '' Ioo a b) β€ #(Ioo a b) := mk_image_le,
refine le_trans _ h1,
rw [image_sub_const_Ioo, sub_self],
replace h := sub_pos_of_lt h,
have h2 : #(has_inv.inv '' Ioo 0 (b - a)) β€ #(Ioo 0 (b - a)) := mk_image_le,
refine le_trans _ h2,
rw [image_inv, inv_Ioo_0_left h, mk_Ioi_real]
end
/-- The cardinality of the interval [a, b). -/
lemma mk_Ico_real {a b : β} (h : a < b) : #(Ico a b) = π :=
le_antisymm (mk_real βΈ mk_set_le _) (mk_Ioo_real h βΈ mk_le_mk_of_subset Ioo_subset_Ico_self)
/-- The cardinality of the interval [a, b]. -/
lemma mk_Icc_real {a b : β} (h : a < b) : #(Icc a b) = π :=
le_antisymm (mk_real βΈ mk_set_le _) (mk_Ioo_real h βΈ mk_le_mk_of_subset Ioo_subset_Icc_self)
/-- The cardinality of the interval (a, b]. -/
lemma mk_Ioc_real {a b : β} (h : a < b) : #(Ioc a b) = π :=
le_antisymm (mk_real βΈ mk_set_le _) (mk_Ioo_real h βΈ mk_le_mk_of_subset Ioo_subset_Ioc_self)
end cardinal
|
529d4f30e6b47e4089eb01725f0cfe71dd1fd13b | a45212b1526d532e6e83c44ddca6a05795113ddc | /src/category_theory/bifunctor.lean | d27e04b8023c4271ac0fc6c58234c4671f71618c | [
"Apache-2.0"
] | permissive | fpvandoorn/mathlib | b21ab4068db079cbb8590b58fda9cc4bc1f35df4 | b3433a51ea8bc07c4159c1073838fc0ee9b8f227 | refs/heads/master | 1,624,791,089,608 | 1,556,715,231,000 | 1,556,715,231,000 | 165,722,980 | 5 | 0 | Apache-2.0 | 1,552,657,455,000 | 1,547,494,646,000 | Lean | UTF-8 | Lean | false | false | 1,899 | lean | -- Copyright (c) 2017 Scott Morrison. All rights reserved.
-- Released under Apache 2.0 license as described in the file LICENSE.
-- Authors: Stephen Morgan, Scott Morrison
import category_theory.products
open category_theory
namespace category_theory.bifunctor
universes vβ vβ vβ uβ uβ uβ
variable {C : Type uβ}
variable [π : category.{vβ+1} C]
variable {D : Type uβ}
variable [π : category.{vβ+1} D]
variable {E : Type uβ}
variable [β° : category.{vβ+1} E]
include π π β°
@[simp] lemma map_id (F : (C Γ D) β₯€ E) (X : C) (Y : D) :
F.map ((π X, π Y) : (X, Y) βΆ (X, Y)) = π (F.obj (X, Y)) :=
F.map_id (X, Y)
@[simp] lemma map_id_comp (F : (C Γ D) β₯€ E) (W : C) {X Y Z : D} (f : X βΆ Y) (g : Y βΆ Z) :
F.map ((π W, f β« g) : (W, X) βΆ (W, Z)) =
F.map ((π W, f) : (W, X) βΆ (W, Y)) β« F.map ((π W, g) : (W, Y) βΆ (W, Z)) :=
by rw [βfunctor.map_comp,prod_comp,category.comp_id]
@[simp] lemma map_comp_id (F : (C Γ D) β₯€ E) (X Y Z : C) (W : D) (f : X βΆ Y) (g : Y βΆ Z) :
F.map ((f β« g, π W) : (X, W) βΆ (Z, W)) =
F.map ((f, π W) : (X, W) βΆ (Y, W)) β« F.map ((g, π W) : (Y, W) βΆ (Z, W)) :=
by rw [βfunctor.map_comp,prod_comp,category.comp_id]
@[simp] lemma diagonal (F : (C Γ D) β₯€ E) (X X' : C) (f : X βΆ X') (Y Y' : D) (g : Y βΆ Y') :
F.map ((π X, g) : (X, Y) βΆ (X, Y')) β« F.map ((f, π Y') : (X, Y') βΆ (X', Y')) =
F.map ((f, g) : (X, Y) βΆ (X', Y')) :=
by rw [βfunctor.map_comp, prod_comp, category.id_comp, category.comp_id]
@[simp] lemma diagonal' (F : (C Γ D) β₯€ E) (X X' : C) (f : X βΆ X') (Y Y' : D) (g : Y βΆ Y') :
F.map ((f, π Y) : (X, Y) βΆ (X', Y)) β« F.map ((π X', g) : (X', Y) βΆ (X', Y')) =
F.map ((f, g) : (X, Y) βΆ (X', Y')) :=
by rw [βfunctor.map_comp, prod_comp, category.id_comp, category.comp_id]
end category_theory.bifunctor
|
d52ba6694fe0952820558c29c5034571f0c92821 | c780ac8c1c0dd4de0fb63981226f2b53b62fe298 | /src/finite_field.lean | 92b8af8ed21e233f0a975dc16ff516adf3d661e2 | [] | no_license | jmvlangen/finite_fields | 0672670245ccf62b2967d9c5edc2f60c53fc141f | 757bd91636e0b3508ee21c92be775eb9d908391e | refs/heads/master | 1,586,987,952,433 | 1,549,629,122,000 | 1,549,629,122,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 6,168 | lean | import algebra.char_p
import data.zmod.basic
import data.equiv.algebra
import vector_space
universes u v
namespace char_p
variable {Ξ± : Type u}
variable [ring Ξ±]
open nat
--char_p
lemma char_p_eq_mod (n : β) [char_p Ξ± n] (k : β) : (k : Ξ±) = (k % n : β) :=
calc (k : Ξ±) = (k % n + n * (k / n) : β) : by rw [mod_add_div]
... = β(k % n) + βn * β(k / n) : by rw [cast_add, cast_mul]
... = β(k % n) + 0 : by rw [char_p.cast_eq_zero Ξ± n, zero_mul]
... = β(k % n) : by rw [add_zero]
end char_p
namespace zmod
variable {n : β+}
variable (Ξ± : Type u)
variables [ring Ξ±]
open char_p nat
--zmod n or char_p
def cast : zmod n β Ξ± := nat.cast β fin.val
--zmod n or char_p
instance cast_is_ring_hom [char_p Ξ± n] : is_ring_hom (cast Ξ±) :=
{ map_one := by rw βcast_one; exact eq.symm (char_p_eq_mod n 1),
map_mul := assume x y : zmod n, show β((x * y).val) = β(x.val) * β(y.val), from
by rw [zmod.mul_val, βchar_p_eq_mod, cast_mul],
map_add := assume x y : zmod n, show β((x + y).val) = β(x.val) + β(y.val), from
by rw [zmod.add_val, βchar_p_eq_mod, cast_add] }
open is_ring_hom
--zmod n or char_p
instance to_module [char_p Ξ± n] : module (zmod n) Ξ± :=
module.of_core
{ smul := Ξ» r x, (cast Ξ±) r * x,
smul_add := Ξ» r x y, by unfold has_scalar.smul; rw[mul_add]; refl,
add_smul := Ξ» r s x, by unfold has_scalar.smul;
rw[map_add (cast Ξ±), add_mul]; apply_instance,
mul_smul := Ξ» r s x, by unfold has_scalar.smul;
rw[map_mul (cast Ξ±), mul_assoc]; apply_instance,
one_smul := Ξ» x, show (cast Ξ±) 1 * x = _,
by rw[map_one (cast Ξ±), one_mul]; apply_instance }
instance to_module' {m : β} {hm : m > 0} [hc : char_p Ξ± m] : module (zmod β¨m, hmβ©) Ξ± :=
@zmod.to_module β¨m, hmβ© Ξ± _ hc
end zmod
namespace char_p
variables (Ξ± : Type u) [ring Ξ±]
open function nat
--char_p
lemma ne_zero [fintype Ξ±] [decidable_eq Ξ±] (p : β) [char_p Ξ± p] : p β 0 :=
(assume h : p = 0,
have β n : β, (n : Ξ±) = 0 β n = 0, from
assume (n : β) (hβ : (n : Ξ±) = 0),
have 0 β£ n, from h βΈ (cast_eq_zero_iff Ξ± p n).mp hβ,
show n = 0, from zero_dvd_iff.mp this,
have char_zero Ξ±, from add_group.char_zero_of_inj_zero this,
have ht : injective nat.cast, from @cast_injective Ξ± _ _ this,
have hf : Β¬injective nat.cast, from @set.not_injective_nat_fintype Ξ± _ _ _,
absurd ht hf)
end char_p
section integral_domain
variables (Ξ± : Type u) [integral_domain Ξ±]
open nat function char_p
--integral_domain
lemma char_p_ne_one (p : β) [hc : char_p Ξ± p] : p β 1 :=
assume hp : p = 1,
have (β1 : Ξ±) = 0, from (cast_eq_zero_iff Ξ± p 1).mpr (hp βΈ (dvd_refl p)),
have ( 1 : Ξ±) = 0, from @cast_one Ξ± _ _ βΈ this,
absurd this one_ne_zero
--integral_domain
lemma char_p_prime_of_ge_two (p : β) [hc : char_p Ξ± p] (hp : p β₯ 2) : nat.prime p :=
suffices βd β£ p, d = 1 β¨ d = p, from β¨hp, thisβ©,
assume (d : β) (hdvd : β e, p = d * e),
let β¨e, hmulβ© := hdvd in
have (p : Ξ±) = 0, from (cast_eq_zero_iff Ξ± p p).mpr (dvd_refl p),
have (d : Ξ±) * e = 0, from (@cast_mul Ξ± _ d e) βΈ (hmul βΈ this),
or.elim (no_zero_divisors.eq_zero_or_eq_zero_of_mul_eq_zero (d : Ξ±) e this)
(assume hd : (d : Ξ±) = 0,
have p β£ d, from (cast_eq_zero_iff Ξ± p d).mp hd,
show d = 1 β¨ d = p, from or.inr (dvd_antisymm β¨e, hmulβ© this))
(assume he : (e : Ξ±) = 0,
have p β£ e, from (cast_eq_zero_iff Ξ± p e).mp he,
have e β£ p, from dvd_of_mul_left_eq d (eq.symm hmul),
have e = p, from dvd_antisymm βΉe β£ pβΊ βΉp β£ eβΊ,
have hβ : p > 0, from gt_of_ge_of_gt hp (nat.zero_lt_succ 1),
have d * p = 1 * p, by rw βΉe = pβΊ at hmul; rw [one_mul]; exact eq.symm hmul,
show d = 1 β¨ d = p, from or.inl (eq_of_mul_eq_mul_right hβ this))
--integral_domain
lemma char_p_prime_or_zero (p : β) [hc : char_p Ξ± p] : nat.prime p β¨ p = 0 :=
match p, hc with
| 0, _ := or.inr rfl
| 1, hc := absurd (eq.refl (1 : β)) (@char_p_ne_one Ξ± _ (1 : β) hc)
| (m+2), hc := or.inl (@char_p_prime_of_ge_two Ξ± _ (m+2) hc (nat.le_add_left 2 m))
end
--integral_domain
lemma char_p_prime [fintype Ξ±] [decidable_eq Ξ±] (p : β) [char_p Ξ± p] : nat.prime p :=
or.resolve_right (char_p_prime_or_zero Ξ± p) (char_p.ne_zero Ξ± p)
lemma ring_char_prime [fintype Ξ±] [decidable_eq Ξ±] : nat.prime (ring_char Ξ±) :=
@char_p_prime Ξ± _ _ _ (ring_char Ξ±) β¨ring_char.spec Ξ±β©
end integral_domain
namespace finite_field
open fintype
variables (Ξ± : Type u) {Ξ² : Type v}
variables [discrete_field Ξ±] [fintype Ξ±]
variables [discrete_field Ξ²] [fintype Ξ²]
--finite field
theorem fin_field_card (p : β) [char_p Ξ± p] :
β (n : β+), nat.prime p β§ card Ξ± = p^(n : β) :=
have hp : nat.prime p, from char_p_prime Ξ± p,
have V : vector_space (zmodp p hp) Ξ±, from {..zmod.to_module' Ξ±},
let β¨n, hβ© := @vector_space.card_fin _ _ _ _ _ _ V _ in
have hn : n > 0, from or.resolve_left (nat.eq_zero_or_pos n)
(assume h0 : n = 0,
have card Ξ± = 1, by rw[βnat.pow_zero (card _), βh0]; exact h,
have (1 : Ξ±) = 0, from (fintype.card_le_one_iff.mp (le_of_eq this)) 1 0,
absurd this one_ne_zero),
β¨β¨n, hnβ©, hp, fintype.card_fin p βΈ hβ©
theorem fin_field_card_exists :
β (p : β) (n : β+), nat.prime p β§ card Ξ± = p^(n : β) :=
let β¨p, hcβ© := char_p.exists Ξ± in
β¨p, @fin_field_card Ξ± _ _ p hcβ©
theorem finite_field.exists : β (p : β) (n : β+), nat.prime p β
β (Ξ± : Type*) [hf : field Ξ±] [hfin : fintype Ξ±], @card Ξ± hfin = p^(n : β) :=
sorry
theorem finite_field.unique : card Ξ± = card Ξ² β (Ξ± βr Ξ²) :=
sorry
def fin_field (p : β) (n : β+) {hp : nat.prime p} :=
classical.some (finite_field.exists p n hp)
notation `π½_[` p `;` n `]` := fin_field p n --find better notation?
variables {p : β} {n : β+} {hp : nat.prime p}
noncomputable instance : field π½_[p;n] :=
classical.some (classical.some_spec (finite_field.exists p n hp))
noncomputable instance : fintype π½_[p;n] :=
classical.some (classical.some_spec $ classical.some_spec (finite_field.exists p n hp))
end finite_field
|
7e907d5c72a533a3cacc75773441a4ef2eb397c5 | fa02ed5a3c9c0adee3c26887a16855e7841c668b | /src/algebra/homology/homology.lean | 50511df3d3e29017cefbed281ff017e83523bb29 | [
"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 | 7,755 | lean | /-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import algebra.homology.image_to_kernel
import algebra.homology.homological_complex
import category_theory.graded_object
/-!
# The homology of a complex
Given `C : homological_complex V c`, we have `C.cycles i` and `C.boundaries i`,
both defined as subobjects of `C.X i`.
We show these are functorial with respect to chain maps,
as `C.cycles_map f i` and `C.boundaries_map f i`.
As a consequence we construct `homology_functor i : homological_complex V c β₯€ V`,
computing the `i`-th homology.
-/
universes v u
open category_theory category_theory.limits
variables {ΞΉ : Type*}
variables {V : Type u} [category.{v} V] [has_zero_morphisms V]
variables {c : complex_shape ΞΉ} (C : homological_complex V c)
open_locale classical
noncomputable theory
namespace homological_complex
variables [has_zero_object V]
section cycles
variables [has_kernels V]
/-- The cycles at index `i`, as a subobject. -/
def cycles (i : ΞΉ) : subobject (C.X i) :=
kernel_subobject (C.d_from i)
@[simp, reassoc]
lemma cycles_arrow_d_from (i : ΞΉ) : (C.cycles i).arrow β« C.d_from i = 0 :=
by { dsimp [cycles], simp, }
lemma cycles_eq_kernel_subobject {i j : ΞΉ} (r : c.rel i j) :
C.cycles i = kernel_subobject (C.d i j) :=
C.kernel_from_eq_kernel r
/--
The underlying object of `C.cycles i` is isomorphic to `kernel (C.d i j)`,
for any `j` such that `rel i j`.
-/
def cycles_iso_kernel {i j : ΞΉ} (r : c.rel i j) :
(C.cycles i : V) β
kernel (C.d i j) :=
subobject.iso_of_eq _ _ (C.cycles_eq_kernel_subobject r) βͺβ«
kernel_subobject_iso (C.d i j)
lemma cycles_eq_top {i} (h : c.next i = none) : C.cycles i = β€ :=
begin
rw eq_top_iff,
apply le_kernel_subobject,
rw [C.d_from_eq_zero h, comp_zero],
end
end cycles
section boundaries
variables [has_images V]
/-- The boundaries at index `i`, as a subobject. -/
abbreviation boundaries (C : homological_complex V c) (j : ΞΉ) : subobject (C.X j) :=
image_subobject (C.d_to j)
lemma boundaries_eq_image_subobject [has_equalizers V] {i j : ΞΉ} (r : c.rel i j) :
C.boundaries j = image_subobject (C.d i j) :=
C.image_to_eq_image r
/--
The underlying object of `C.boundaries j` is isomorphic to `image (C.d i j)`,
for any `i` such that `rel i j`.
-/
def boundaries_iso_image [has_equalizers V] {i j : ΞΉ} (r : c.rel i j) :
(C.boundaries j : V) β
image (C.d i j) :=
subobject.iso_of_eq _ _ (C.boundaries_eq_image_subobject r) βͺβ«
image_subobject_iso (C.d i j)
lemma boundaries_eq_bot {j} (h : c.prev j = none) : C.boundaries j = β₯ :=
begin
rw eq_bot_iff,
refine image_subobject_le _ 0 _,
rw [C.d_to_eq_zero h, zero_comp],
end
end boundaries
section
variables [has_kernels V] [has_images V]
lemma boundaries_le_cycles (C : homological_complex V c) (i : ΞΉ) :
C.boundaries i β€ C.cycles i :=
image_le_kernel _ _ (C.d_to_comp_d_from i)
/--
The canonical map from `boundaries i` to `cycles i`.
-/
abbreviation boundaries_to_cycles (C : homological_complex V c) (i : ΞΉ) :
(C.boundaries i : V) βΆ (C.cycles i : V) :=
image_to_kernel _ _ (C.d_to_comp_d_from i)
/-- Prefer `boundaries_to_cycles`. -/
@[simp] lemma image_to_kernel_as_boundaries_to_cycles (C : homological_complex V c) (i : ΞΉ) (h) :
(C.boundaries i).of_le (C.cycles i) h = C.boundaries_to_cycles i :=
rfl
@[simp, reassoc]
lemma boundaries_to_cycles_arrow (C : homological_complex V c) (i : ΞΉ) :
C.boundaries_to_cycles i β« (C.cycles i).arrow = (C.boundaries i).arrow :=
by { dsimp [cycles], simp, }
variables [has_cokernels V]
/--
The homology of a complex at index `i`.
-/
abbreviation homology (C : homological_complex V c) (i : ΞΉ) : V :=
homology (C.d_to i) (C.d_from i) (C.d_to_comp_d_from i)
end
end homological_complex
open homological_complex
/-! Computing the cycles is functorial. -/
section
variables [has_zero_object V] [has_kernels V]
variables {Cβ Cβ Cβ : homological_complex V c} (f : Cβ βΆ Cβ)
/--
The morphism between cycles induced by a chain map.
-/
abbreviation cycles_map (f : Cβ βΆ Cβ) (i : ΞΉ) : (Cβ.cycles i : V) βΆ (Cβ.cycles i : V) :=
subobject.factor_thru _ ((Cβ.cycles i).arrow β« f.f i) (kernel_subobject_factors _ _ (by simp))
@[simp] lemma cycles_map_arrow (f : Cβ βΆ Cβ) (i : ΞΉ) :
(cycles_map f i) β« (Cβ.cycles i).arrow = (Cβ.cycles i).arrow β« f.f i :=
by { simp, }
@[simp] lemma cycles_map_id (i : ΞΉ) : cycles_map (π Cβ) i = π _ :=
by { dunfold cycles_map, simp, }
@[simp] lemma cycles_map_comp (f : Cβ βΆ Cβ) (g : Cβ βΆ Cβ) (i : ΞΉ) :
cycles_map (f β« g) i = cycles_map f i β« cycles_map g i :=
by { dunfold cycles_map, simp [subobject.factor_thru_right], }
variables (V c)
/-- Cycles as a functor. -/
@[simps]
def cycles_functor (i : ΞΉ) : homological_complex V c β₯€ V :=
{ obj := Ξ» C, C.cycles i,
map := Ξ» Cβ Cβ f, cycles_map f i, }
end
/-! Computing the boundaries is functorial. -/
section
variables [has_zero_object V] [has_images V] [has_image_maps V]
variables {Cβ Cβ Cβ : homological_complex V c} (f : Cβ βΆ Cβ)
/--
The morphism between boundaries induced by a chain map.
-/
abbreviation boundaries_map (f : Cβ βΆ Cβ) (i : ΞΉ) : (Cβ.boundaries i : V) βΆ (Cβ.boundaries i : V) :=
image_subobject_map (f.sq_to i)
variables (V c)
/-- Boundaries as a functor. -/
@[simps]
def boundaries_functor (i : ΞΉ) : homological_complex V c β₯€ V :=
{ obj := Ξ» C, C.boundaries i,
map := Ξ» Cβ Cβ f, image_subobject_map (f.sq_to i), }
end
section
/-! The `boundaries_to_cycles` morphisms are natural. -/
variables [has_zero_object V] [has_equalizers V] [has_images V] [has_image_maps V]
variables {Cβ Cβ : homological_complex V c} (f : Cβ βΆ Cβ)
@[simp, reassoc]
lemma boundaries_to_cycles_naturality (i : ΞΉ) :
boundaries_map f i β« Cβ.boundaries_to_cycles i = Cβ.boundaries_to_cycles i β« cycles_map f i :=
by { ext, simp, }
variables (V c)
/-- The natural transformation from the boundaries functor to the cycles functor. -/
@[simps] def boundaries_to_cycles_nat_trans (i : ΞΉ) :
boundaries_functor V c i βΆ cycles_functor V c i :=
{ app := Ξ» C, C.boundaries_to_cycles i,
naturality' := Ξ» Cβ Cβ f, boundaries_to_cycles_naturality f i, }
/-- The `i`-th homology, as a functor to `V`. -/
@[simps] def homology_functor [has_cokernels V] (i : ΞΉ) :
homological_complex V c β₯€ V :=
-- It would be nice if we could just write
-- `cokernel (boundaries_to_cycles_nat_trans V c i)`
-- here, but universe implementation details get in the way...
{ obj := Ξ» C, C.homology i,
map := Ξ» Cβ Cβ f, _root_.homology.map _ _ (f.sq_to i) (f.sq_from i) rfl,
map_id' :=
begin
intros, ext1,
simp only [homology.Ο_map, kernel_subobject_map_id, hom.sq_from_id,
category.id_comp, category.comp_id]
end,
map_comp' :=
begin
intros, ext1,
simp only [hom.sq_from_comp, kernel_subobject_map_comp, homology.Ο_map_assoc,
homology.Ο_map, category.assoc]
end }
/-- The homology functor from `ΞΉ`-indexed complexes to `ΞΉ`-graded objects in `V`. -/
@[simps] def graded_homology_functor [has_cokernels V] :
homological_complex V c β₯€ graded_object ΞΉ V :=
{ obj := Ξ» C i, C.homology i,
map := Ξ» C C' f i, (homology_functor V c i).map f,
map_id' :=
begin
intros, ext,
simp only [pi.id_apply, homology.Ο_map, homology_functor_map, kernel_subobject_map_id,
hom.sq_from_id, category.id_comp, category.comp_id]
end,
map_comp' :=
begin
intros, ext,
simp only [hom.sq_from_comp, kernel_subobject_map_comp, homology.Ο_map_assoc,
pi.comp_apply, homology.Ο_map, homology_functor_map, category.assoc]
end }
end
|
aa5c2048a69aa91ff3dcdcf0db2f418900b127fd | 0d22ec5e0205ec4203aae2ddf07e1f695ff21a61 | /src/polynomial_derivations.lean | 23f1958bebbd2c0d2de2dc7ec17bc835222daf00 | [
"Apache-2.0"
] | permissive | shingtaklam1324/step3-06-q8-lean | 4611fda6b002797d38d3f625253960dcfeb2a987 | 20e5161fab8b5c3c2dd051bd707a26f1dc50dac2 | refs/heads/master | 1,649,936,589,910 | 1,585,242,273,000 | 1,585,242,273,000 | 250,318,324 | 2 | 0 | Apache-2.0 | 1,585,389,271,000 | 1,585,241,690,000 | Lean | UTF-8 | Lean | false | false | 5,021 | 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 tactic
data.polynomial
data.real.basic
-- set_option profiler true
/-!
# Polynomial derivations
We prove the structure theorem for polynomial derivations.
# Main definitions
* `polynomial_derivation (R : Type) [comm_ring R]` : the type of `R`-derivations on `R[X]`.
# Main statements
We prove the structure theorem, that every polynomial derivation is equal to
an R[X]-linear multiple of polynomial differentiation.
Proof that there
is an equivalence between polynomials and polynomial derivations, sending
a polynomial h to the derivation mapping f to h*derivative(f).
proof that differentiation is a derivation.
# Further work
-/
-- start of file
/-- A polynomial derivation on a ring R is a function d : R[X] β R[X] satisfying
three axioms:
map_add : β {f g : polynomial R} , d (f + g) = d f + d g
map_C_mul : β (k : R) (f : polynomial R), d (C k * f) = C k * d f
map_mul : β (f g : polynomial R) , d (f * g) = f * d g + g * d f
-/
structure polynomial_derivation (R : Type) [comm_ring R] :=
(to_fun : polynomial R β polynomial R) -- Delta
(map_add' : β (f g : polynomial R), to_fun (f + g) = to_fun f + to_fun g)
(map_C_mul' : β (k : R) (f : polynomial R), to_fun (polynomial.C k * f) = polynomial.C k * to_fun f)
(map_mul' : β (f g : polynomial R), to_fun (f * g) = f * to_fun g + g * to_fun f)
open polynomial
namespace polynomial_derivation
variables {R : Type} [comm_ring R]
/-- think of a polynomial derivation as a function from R[X] to R[X] -/
instance : has_coe_to_fun (polynomial_derivation R) :=
{ F := Ξ» _, polynomial R β polynomial R,
coe := to_fun
}
@[simp]
theorem map_add (d : polynomial_derivation R) : β {f g : polynomial R}, d (f + g) = d f + d g := d.map_add'
@[simp]
theorem map_mul (d : polynomial_derivation R): β (f g : polynomial R), d (f * g) = f * d g + g * d f := d.map_mul'
@[simp]
theorem map_C_mul (d : polynomial_derivation R): β (k : R) (f : polynomial R), d (C k * f) = C k * d f := d.map_C_mul'
@[simp]
lemma map_one (d : polynomial_derivation R) : d 1 = 0 :=
begin
have hd : d 1 + d 1 = d 1 := begin
conv begin
to_rhs, rw (show (1 : polynomial R) = 1 * 1, by simp),
end,
rw map_mul, ring,
end,
rwa add_left_eq_self at hd,
end
@[simp]
lemma map_C (d : polynomial_derivation R) (a : R) : d (C a) = 0 :=
by rw [(show C a = C a * (1 : polynomial R), from (mul_one _).symm),
map_C_mul, map_one, mul_zero]
lemma map_pow_succ_aux (n : β)
(d : polynomial_derivation R) :
X * ((βn + 1) * X ^ n * d X) + X * X ^ n * d X =
(βn + 1 + 1) * (X * X ^ n) * d X := by ring
-- Leibniz rule
lemma map_pow_succ (d : polynomial_derivation R) (n : β) : d (X ^ (n + 1)) = (n + 1)*X^n * d(X) :=
begin
induction n with n IH,
{simp},
rw pow_succ, rw map_mul,
rw IH,
simp only [pow_succ, nat.succ_eq_add_one],
push_cast,
exact map_pow_succ_aux n d,
end
lemma structure_theorem_aux' (a : R) (n : β) (d : polynomial_derivation R) : C a * X ^ n * d X + X * (d X * derivative (C a * X ^ n)) =
d X * (derivative (C a * X ^ n) * X + C a * X ^ n * 1) := by ring
/-- structure theorem for polynomial derivations -/
theorem structure_theorem (d : polynomial_derivation R) (f : polynomial R): d f = d X * polynomial.derivative f :=
begin
apply f.induction_on,
{intro a, simp [map_C]},
{ intros _ _ hp hq,
rw [map_add, hp, hq, derivative_add, mul_add],},
intros n a h,
rw [pow_succ, mul_comm X, βmul_assoc, map_mul, derivative_mul, h, derivative_X],
exact structure_theorem_aux' a n d,
end
@[ext] theorem ext : β {dβ dβ : polynomial_derivation R} (H : β f, dβ f = dβ f), dβ = dβ
| β¨_, _, _, _β© β¨_, _, _, _β© H := by congr; exact funext H
lemma structure_classification_aux1
(j : polynomial R)
(k : R)
(f : polynomial R) :
j * (0 * f + C k * derivative f) = C k * (j * derivative f) := by ring
lemma structure_classification_aux2
(j f g : polynomial R) :
j * (derivative f * g + f * derivative g) =
f * (j * derivative g) + g * (j * derivative f) := by ring
noncomputable definition structure_classification (R : Type) [comm_ring R] :
polynomial_derivation R β polynomial R :=
{ to_fun := Ξ» d, d X,
inv_fun := Ξ» j,
{ to_fun := Ξ» f, j * f.derivative,
map_add' := Ξ» _ _, by rw [derivative_add, mul_add],
map_C_mul' := begin
intros,
rw [derivative_mul, derivative_C],
exact structure_classification_aux1 j k f,
end,
map_mul' := begin
intros,
rw derivative_mul,
exact structure_classification_aux2 j f g,
end },
left_inv := begin
intro d,
ext1 f,
rw structure_theorem d f,
refl,
end,
right_inv := begin
intro p,
change p * derivative X = p,
simp only [mul_one, polynomial.derivative_X],
end }
end polynomial_derivation |
526bd9c2897d01bf520b3b1964c85b1cbbad5668 | 87a08a8e9b222ec02f3327dca4ae24590c1b3de9 | /src/measure_theory/measure_space.lean | 5565e4f4e45c64bcc9c57dd9d960961780c63fe5 | [
"Apache-2.0"
] | permissive | naussicaa/mathlib | 86d05223517a39e80920549a8052f9cf0e0b77b8 | 1ef2c2df20cf45c21675d855436228c7ae02d47a | refs/heads/master | 1,592,104,950,080 | 1,562,073,069,000 | 1,562,073,069,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 35,098 | 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
Measure spaces -- measures
Measures are restricted to a measurable space (associated by the type class `measurable_space`).
This allows us to prove equalities between measures by restricting to a generating set of the
measurable space.
On the other hand, the `ΞΌ.measure s` projection (i.e. the measure of `s` on the measure space `ΞΌ`)
is the _outer_ measure generated by `ΞΌ`. This gives us a unrestricted monotonicity rule and it is
somehow well-behaved on non-measurable sets.
This allows us for the `lebesgue` measure space to have the `borel` measurable space, but still be
a complete measure.
-/
import data.set.lattice data.set.finite
import topology.instances.ennreal
measure_theory.outer_measure
noncomputable theory
open classical set lattice filter finset function
local attribute [instance] prop_decidable
universes u v w x
namespace measure_theory
section of_measurable
parameters {Ξ± : Type*} [measurable_space Ξ±]
parameters (m : Ξ (s : set Ξ±), is_measurable s β ennreal)
parameters (m0 : m β
is_measurable.empty = 0)
include m0
/-- Measure projection which is β for non-measurable sets.
`measure'` is mainly used to derive the outer measure, for the main `measure` projection. -/
def measure' (s : set Ξ±) : ennreal := β¨
h : is_measurable s, m s h
lemma measure'_eq {s} (h : is_measurable s) : measure' s = m s h :=
by simp [measure', h]
lemma measure'_empty : measure' β
= 0 :=
(measure'_eq is_measurable.empty).trans m0
lemma measure'_Union_nat
{f : β β set Ξ±}
(hm : βi, is_measurable (f i))
(mU : m (βi, f i) (is_measurable.Union hm) = (βi, m (f i) (hm i))) :
measure' (βi, f i) = (βi, measure' (f i)) :=
(measure'_eq _).trans $ mU.trans $
by congr; funext i; rw measure'_eq
/-- outer measure of a measure -/
def outer_measure' : outer_measure Ξ± :=
outer_measure.of_function measure' measure'_empty
lemma measure'_Union_le_tsum_nat'
(mU : β {f : β β set Ξ±} (hm : βi, is_measurable (f i)),
m (βi, f i) (is_measurable.Union hm) β€ (βi, m (f i) (hm i)))
(s : β β set Ξ±) :
measure' (βi, s i) β€ (βi, measure' (s i)) :=
begin
by_cases h : βi, is_measurable (s i),
{ rw [measure'_eq _ _ (is_measurable.Union h),
congr_arg tsum _], {apply mU h},
funext i, apply measure'_eq _ _ (h i) },
{ cases not_forall.1 h with i hi,
exact le_trans (le_infi $ Ξ» h, hi.elim h) (ennreal.le_tsum i) }
end
parameter (mU : β {f : β β set Ξ±} (hm : βi, is_measurable (f i)),
pairwise (disjoint on f) β
m (βi, f i) (is_measurable.Union hm) = (βi, m (f i) (hm i)))
include mU
lemma measure'_Union
{Ξ²} [encodable Ξ²] {f : Ξ² β set Ξ±}
(hd : pairwise (disjoint on f)) (hm : βi, is_measurable (f i)) :
measure' (βi, f i) = (βi, measure' (f i)) :=
begin
rw [encodable.Union_decode2, outer_measure.Union_aux],
{ exact measure'_Union_nat _ _
(Ξ» n, encodable.Union_decode2_cases is_measurable.empty hm)
(mU _ (measurable_space.Union_decode2_disjoint_on hd)) },
{ apply measure'_empty },
end
lemma measure'_union {sβ sβ : set Ξ±}
(hd : disjoint sβ sβ) (hβ : is_measurable sβ) (hβ : is_measurable sβ) :
measure' (sβ βͺ sβ) = measure' sβ + measure' sβ :=
begin
rw [union_eq_Union, measure'_Union _ _ @mU
(pairwise_disjoint_on_bool.2 hd) (bool.forall_bool.2 β¨hβ, hββ©),
tsum_fintype],
change _+_ = _, simp
end
lemma measure'_mono {sβ sβ : set Ξ±} (hβ : is_measurable sβ) (hs : sβ β sβ) :
measure' sβ β€ measure' sβ :=
le_infi $ Ξ» hβ, begin
have := measure'_union _ _ @mU disjoint_diff hβ (hβ.diff hβ),
rw union_diff_cancel hs at this,
rw β measure'_eq m m0 _,
exact le_iff_exists_add.2 β¨_, thisβ©
end
lemma measure'_Union_le_tsum_nat : β (s : β β set Ξ±),
measure' (βi, s i) β€ (βi, measure' (s i)) :=
measure'_Union_le_tsum_nat' $ Ξ» f h, begin
simp [Union_disjointed.symm] {single_pass := tt},
rw [mU (is_measurable.disjointed h) disjoint_disjointed],
refine ennreal.tsum_le_tsum (Ξ» i, _),
rw [β measure'_eq m m0, β measure'_eq m m0],
exact measure'_mono _ _ @mU (is_measurable.disjointed h _) (inter_subset_left _ _)
end
lemma outer_measure'_eq {s : set Ξ±} (hs : is_measurable s) :
outer_measure' s = m s hs :=
by rw β measure'_eq m m0 hs; exact
(le_antisymm (outer_measure.of_function_le _ _ _) $
le_infi $ Ξ» f, le_infi $ Ξ» hf,
le_trans (measure'_mono _ _ @mU hs hf) $
measure'_Union_le_tsum_nat _ _ @mU _)
lemma outer_measure'_eq_measure' {s : set Ξ±} (hs : is_measurable s) :
outer_measure' s = measure' s :=
by rw [measure'_eq m m0 hs, outer_measure'_eq m m0 @mU hs]
end of_measurable
namespace outer_measure
variables {Ξ± : Type*} [measurable_space Ξ±] (m : outer_measure Ξ±)
def trim : outer_measure Ξ± :=
outer_measure' (Ξ» s _, m s) m.empty
theorem trim_ge : m β€ m.trim :=
Ξ» s, le_infi $ Ξ» f, le_infi $ Ξ» hs,
le_trans (m.mono hs) $ le_trans (m.Union_nat f) $
ennreal.tsum_le_tsum $ Ξ» i, le_infi $ Ξ» hf, le_refl _
theorem trim_eq {s : set Ξ±} (hs : is_measurable s) : m.trim s = m s :=
le_antisymm (le_trans (of_function_le _ _ _) (infi_le _ hs)) (trim_ge _ _)
theorem trim_congr {mβ mβ : outer_measure Ξ±}
(H : β {s : set Ξ±}, is_measurable s β mβ s = mβ s) :
mβ.trim = mβ.trim :=
by unfold trim; congr; funext s hs; exact H hs
theorem trim_le_trim {mβ mβ : outer_measure Ξ±} (H : mβ β€ mβ) : mβ.trim β€ mβ.trim :=
Ξ» s, infi_le_infi $ Ξ» f, infi_le_infi $ Ξ» hs,
ennreal.tsum_le_tsum $ Ξ» b, infi_le_infi $ Ξ» hf, H _
theorem le_trim_iff {mβ mβ : outer_measure Ξ±} : mβ β€ mβ.trim β
β s, is_measurable s β mβ s β€ mβ s :=
le_of_function.trans $ forall_congr $ Ξ» s, le_infi_iff
theorem trim_eq_infi (s : set Ξ±) : m.trim s = β¨
t (st : s β t) (ht : is_measurable t), m t :=
begin
refine le_antisymm
(le_infi $ Ξ» t, le_infi $ Ξ» st, le_infi $ Ξ» ht, _)
(le_infi $ Ξ» f, le_infi $ Ξ» hf, _),
{ rw β trim_eq m ht, exact (trim m).mono st },
{ by_cases h : βi, is_measurable (f i),
{ refine infi_le_of_le _ (infi_le_of_le hf $
infi_le_of_le (is_measurable.Union h) _),
rw congr_arg tsum _, {exact m.Union_nat _},
funext i, exact measure'_eq _ _ (h i) },
{ cases not_forall.1 h with i hi,
exact le_trans (le_infi $ Ξ» h, hi.elim h) (ennreal.le_tsum i) } }
end
theorem trim_eq_infi' (s : set Ξ±) : m.trim s = β¨
t : {t // s β t β§ is_measurable t}, m t.1 :=
by simp [infi_subtype, infi_and, trim_eq_infi]
theorem trim_trim (m : outer_measure Ξ±) : m.trim.trim = m.trim :=
le_antisymm (le_trim_iff.2 $ Ξ» s hs, by simp [trim_eq _ hs, le_refl]) (trim_ge _)
theorem trim_zero : (0 : outer_measure Ξ±).trim = 0 :=
ext $ Ξ» s, le_antisymm
(le_trans ((trim 0).mono (subset_univ s)) $
le_of_eq $ trim_eq _ is_measurable.univ)
(zero_le _)
theorem trim_add (mβ mβ : outer_measure Ξ±) : (mβ + mβ).trim = mβ.trim + mβ.trim :=
ext $ Ξ» s, begin
simp [trim_eq_infi'],
rw ennreal.infi_add_infi,
rintro β¨tβ, stβ, htββ© β¨tβ, stβ, htββ©,
exact β¨β¨_, subset_inter_iff.2 β¨stβ, stββ©, htβ.inter htββ©,
add_le_add'
(mβ.mono' (inter_subset_left _ _))
(mβ.mono' (inter_subset_right _ _))β©,
end
theorem trim_sum_ge {ΞΉ} (m : ΞΉ β outer_measure Ξ±) : sum (Ξ» i, (m i).trim) β€ (sum m).trim :=
Ξ» s, by simp [trim_eq_infi]; exact
Ξ» t st ht, ennreal.tsum_le_tsum (Ξ» i,
infi_le_of_le t $ infi_le_of_le st $ infi_le _ ht)
end outer_measure
structure measure (Ξ± : Type*) [measurable_space Ξ±] extends outer_measure Ξ± :=
(m_Union {f : β β set Ξ±} :
(βi, is_measurable (f i)) β pairwise (disjoint on f) β
measure_of (βi, f i) = (βi, measure_of (f i)))
(trimmed : to_outer_measure.trim = to_outer_measure)
/-- Measure projections for a measure space.
For measurable sets this returns the measure assigned by the `measure_of` field in `measure`.
But we can extend this to _all_ sets, but using the outer measure. This gives us monotonicity and
subadditivity for all sets.
-/
instance measure.has_coe_to_fun {Ξ±} [measurable_space Ξ±] : has_coe_to_fun (measure Ξ±) :=
β¨Ξ» _, set Ξ± β ennreal, Ξ» m, m.to_outer_measureβ©
namespace measure
def of_measurable {Ξ±} [measurable_space Ξ±]
(m : Ξ (s : set Ξ±), is_measurable s β ennreal)
(m0 : m β
is_measurable.empty = 0)
(mU : β {f : β β set Ξ±} (h : βi, is_measurable (f i)),
pairwise (disjoint on f) β
m (βi, f i) (is_measurable.Union h) = (βi, m (f i) (h i))) :
measure Ξ± :=
{ m_Union := Ξ» f hf hd,
show outer_measure' m m0 (Union f) =
β i, outer_measure' m m0 (f i), begin
rw [outer_measure'_eq m m0 @mU, mU hf hd],
congr, funext n, rw outer_measure'_eq m m0 @mU
end,
trimmed :=
show (outer_measure' m m0).trim = outer_measure' m m0, begin
unfold outer_measure.trim,
congr, funext s hs,
exact outer_measure'_eq m m0 @mU hs
end,
..outer_measure' m m0 }
lemma of_measurable_apply {Ξ±} [measurable_space Ξ±]
{m : Ξ (s : set Ξ±), is_measurable s β ennreal}
{m0 : m β
is_measurable.empty = 0}
{mU : β {f : β β set Ξ±} (h : βi, is_measurable (f i)),
pairwise (disjoint on f) β
m (βi, f i) (is_measurable.Union h) = (βi, m (f i) (h i))}
(s : set Ξ±) (hs : is_measurable s) :
of_measurable m m0 @mU s = m s hs :=
outer_measure'_eq m m0 @mU hs
@[extensionality] lemma ext {Ξ±} [measurable_space Ξ±] :
β {ΞΌβ ΞΌβ : measure Ξ±}, (βs, is_measurable s β ΞΌβ s = ΞΌβ s) β ΞΌβ = ΞΌβ
| β¨mβ, uβ, hββ© β¨mβ, uβ, hββ© h := by congr; rw [β hβ, β hβ];
exact outer_measure.trim_congr h
end measure
section
variables {Ξ± : Type*} {Ξ² : Type*} [measurable_space Ξ±] {ΞΌ ΞΌβ ΞΌβ : measure Ξ±} {s sβ sβ : set Ξ±}
@[simp] lemma to_outer_measure_apply (s) : ΞΌ.to_outer_measure s = ΞΌ s := rfl
lemma measure_eq_trim (s) : ΞΌ s = ΞΌ.to_outer_measure.trim s :=
by rw ΞΌ.trimmed; refl
lemma measure_eq_infi (s) : ΞΌ s = β¨
t (st : s β t) (ht : is_measurable t), ΞΌ t :=
by rw [measure_eq_trim, outer_measure.trim_eq_infi]; refl
lemma measure_eq_outer_measure' :
ΞΌ s = outer_measure' (Ξ» s _, ΞΌ s) ΞΌ.empty s :=
measure_eq_trim _
lemma to_outer_measure_eq_outer_measure' :
ΞΌ.to_outer_measure = outer_measure' (Ξ» s _, ΞΌ s) ΞΌ.empty :=
ΞΌ.trimmed.symm
lemma measure_eq_measure' (hs : is_measurable s) :
ΞΌ s = measure' (Ξ» s _, ΞΌ s) ΞΌ.empty s :=
by rw [measure_eq_outer_measure',
outer_measure'_eq_measure' (Ξ» s _, ΞΌ s) _ ΞΌ.m_Union hs]
@[simp] lemma measure_empty : ΞΌ β
= 0 := ΞΌ.empty
lemma measure_mono (h : sβ β sβ) : ΞΌ sβ β€ ΞΌ sβ := ΞΌ.mono h
lemma measure_mono_null (h : sβ β sβ) (hβ : ΞΌ sβ = 0) : ΞΌ sβ = 0 :=
by rw [β le_zero_iff_eq, β hβ]; exact measure_mono h
lemma exists_is_measurable_superset_of_measure_eq_zero {s : set Ξ±} (h : ΞΌ s = 0) :
βt, s β t β§ is_measurable t β§ ΞΌ t = 0 :=
begin
rw [measure_eq_infi] at h,
have h := (infi_eq_bot _).1 h,
choose t ht using show βn:β, βt, s β t β§ is_measurable t β§ ΞΌ t < nβ»ΒΉ,
{ assume n,
have : (0 : ennreal) < nβ»ΒΉ :=
(zero_lt_iff_ne_zero.2 $ ennreal.inv_ne_zero.2 $ ennreal.nat_ne_top _),
rcases h _ this with β¨t, htβ©,
use [t],
simpa [(>), infi_lt_iff, -add_comm] using ht },
refine β¨βn, t n, subset_Inter (Ξ»n, (ht n).1), is_measurable.Inter (Ξ»n, (ht n).2.1), _β©,
refine eq_of_le_of_forall_le_of_dense bot_le (assume r hr, _),
rcases ennreal.exists_inv_nat_lt (ne_of_gt hr) with β¨n, hnβ©,
calc ΞΌ (βn, t n) β€ ΞΌ (t n) : measure_mono (Inter_subset _ _)
... β€ nβ»ΒΉ : le_of_lt (ht n).2.2
... β€ r : le_of_lt hn
end
theorem measure_Union_le {Ξ²} [encodable Ξ²] (s : Ξ² β set Ξ±) : ΞΌ (βi, s i) β€ (βi, ΞΌ (s i)) :=
ΞΌ.to_outer_measure.Union _
lemma measure_Union_null {Ξ²} [encodable Ξ²] {s : Ξ² β set Ξ±} :
(β i, ΞΌ (s i) = 0) β ΞΌ (βi, s i) = 0 :=
ΞΌ.to_outer_measure.Union_null
theorem measure_union_le (sβ sβ : set Ξ±) : ΞΌ (sβ βͺ sβ) β€ ΞΌ sβ + ΞΌ sβ :=
ΞΌ.to_outer_measure.union _ _
lemma measure_union_null {sβ sβ : set Ξ±} : ΞΌ sβ = 0 β ΞΌ sβ = 0 β ΞΌ (sβ βͺ sβ) = 0 :=
ΞΌ.to_outer_measure.union_null
lemma measure_Union {Ξ²} [encodable Ξ²] {f : Ξ² β set Ξ±}
(hn : pairwise (disjoint on f)) (h : βi, is_measurable (f i)) :
ΞΌ (βi, f i) = (βi, ΞΌ (f i)) :=
by rw [measure_eq_measure' (is_measurable.Union h),
measure'_Union (Ξ» s _, ΞΌ s) _ ΞΌ.m_Union hn h];
simp [measure_eq_measure', h]
lemma measure_union (hd : disjoint sβ sβ) (hβ : is_measurable sβ) (hβ : is_measurable sβ) :
ΞΌ (sβ βͺ sβ) = ΞΌ sβ + ΞΌ sβ :=
by rw [measure_eq_measure' (hβ.union hβ),
measure'_union (Ξ» s _, ΞΌ s) _ ΞΌ.m_Union hd hβ hβ];
simp [measure_eq_measure', hβ, hβ]
lemma measure_bUnion {s : set Ξ²} {f : Ξ² β set Ξ±} (hs : countable s)
(hd : pairwise_on s (disjoint on f)) (h : βbβs, is_measurable (f b)) :
ΞΌ (βbβs, f b) = βp:s, ΞΌ (f p.1) :=
begin
haveI := hs.to_encodable,
rw [β measure_Union, bUnion_eq_Union],
{ rintro β¨i, hiβ© β¨j, hjβ© ij x β¨hβ, hββ©,
exact hd i hi j hj (mt subtype.eq' ij:_) β¨hβ, hββ© },
{ simpa }
end
lemma measure_sUnion {S : set (set Ξ±)} (hs : countable S)
(hd : pairwise_on S disjoint) (h : βsβS, is_measurable s) :
ΞΌ (ββ S) = βs:S, ΞΌ s.1 :=
by rw [sUnion_eq_bUnion, measure_bUnion hs hd h]
lemma measure_diff {sβ sβ : set Ξ±} (h : sβ β sβ)
(hβ : is_measurable sβ) (hβ : is_measurable sβ)
(h_fin : ΞΌ sβ < β€) : ΞΌ (sβ \ sβ) = ΞΌ sβ - ΞΌ sβ :=
begin
refine (ennreal.add_sub_self' h_fin).symm.trans _,
rw [β measure_union disjoint_diff hβ (hβ.diff hβ), union_diff_cancel h]
end
lemma measure_Union_eq_supr_nat {s : β β set Ξ±} (h : βi, is_measurable (s i)) (hs : monotone s) :
ΞΌ (βi, s i) = (β¨i, ΞΌ (s i)) :=
begin
refine le_antisymm _ (supr_le $ Ξ» i, measure_mono $ subset_Union _ _),
rw [β Union_disjointed,
measure_Union disjoint_disjointed (is_measurable.disjointed h),
ennreal.tsum_eq_supr_nat],
refine supr_le (Ξ» n, _),
cases n, {apply zero_le _},
suffices : sum (finset.range n.succ) (Ξ» i, ΞΌ (disjointed s i)) = ΞΌ (s n),
{ rw this, exact le_supr _ n },
rw [β Union_disjointed_of_mono hs, measure_Union, tsum_eq_sum],
{ apply sum_congr rfl, intros i hi,
simp [finset.mem_range.1 hi] },
{ intros i hi, simp [mt finset.mem_range.2 hi] },
{ rintro i j ij x β¨β¨_, β¨_, rflβ©, hββ©, β¨_, β¨_, rflβ©, hββ©β©,
exact disjoint_disjointed i j ij β¨hβ, hββ© },
{ intro i,
by_cases h' : i < n.succ; simp [h', is_measurable.empty],
apply is_measurable.disjointed h }
end
lemma measure_Inter_eq_infi_nat {s : β β set Ξ±}
(h : βi, is_measurable (s i)) (hs : βi j, i β€ j β s j β s i)
(hfin : βi, ΞΌ (s i) < β€) :
ΞΌ (βi, s i) = (β¨
i, ΞΌ (s i)) :=
begin
rcases hfin with β¨k, hkβ©,
rw [β ennreal.sub_sub_cancel (by exact hk) (infi_le _ k),
ennreal.sub_infi,
β ennreal.sub_sub_cancel (by exact hk) (measure_mono (Inter_subset _ k)),
β measure_diff (Inter_subset _ k) (h k) (is_measurable.Inter h)
(lt_of_le_of_lt (measure_mono (Inter_subset _ k)) hk),
diff_Inter, measure_Union_eq_supr_nat],
{ congr, funext i,
cases le_total k i with ik ik,
{ exact measure_diff (hs _ _ ik) (h k) (h i)
(lt_of_le_of_lt (measure_mono (hs _ _ ik)) hk) },
{ rw [diff_eq_empty.2 (hs _ _ ik), measure_empty,
ennreal.sub_eq_zero_of_le (measure_mono (hs _ _ ik))] } },
{ exact Ξ» i, (h k).diff (h i) },
{ exact Ξ» i j ij, diff_subset_diff_right (hs _ _ ij) }
end
lemma measure_eq_inter_diff {ΞΌ : measure Ξ±} {s t : set Ξ±}
(hs : is_measurable s) (ht : is_measurable t) :
ΞΌ s = ΞΌ (s β© t) + ΞΌ (s \ t) :=
have hd : disjoint (s β© t) (s \ t) := assume a β¨β¨_, hsβ©, _, hnsβ©, hns hs ,
by rw [β measure_union hd (hs.inter ht) (hs.diff ht), inter_union_diff s t]
lemma tendsto_measure_Union {ΞΌ : measure Ξ±} {s : β β set Ξ±}
(hs : βn, is_measurable (s n)) (hm : monotone s) :
tendsto (ΞΌ β s) at_top (nhds (ΞΌ (βn, s n))) :=
begin
rw measure_Union_eq_supr_nat hs hm,
exact tendsto_at_top_supr_nat (ΞΌ β s) (assume n m hnm, measure_mono $ hm $ hnm)
end
lemma tendsto_measure_Inter {ΞΌ : measure Ξ±} {s : β β set Ξ±}
(hs : βn, is_measurable (s n)) (hm : βn m, n β€ m β s m β s n) (hf : βi, ΞΌ (s i) < β€):
tendsto (ΞΌ β s) at_top (nhds (ΞΌ (βn, s n))) :=
begin
rw measure_Inter_eq_infi_nat hs hm hf,
exact tendsto_at_top_infi_nat (ΞΌ β s) (assume n m hnm, measure_mono $ hm _ _ $ hnm),
end
end
def outer_measure.to_measure {Ξ±} (m : outer_measure Ξ±)
[ms : measurable_space Ξ±] (h : ms β€ m.caratheodory) :
measure Ξ± :=
measure.of_measurable (Ξ» s _, m s) m.empty
(Ξ» f hf hd, m.Union_eq_of_caratheodory (Ξ» i, h _ (hf i)) hd)
lemma le_to_outer_measure_caratheodory {Ξ±} [ms : measurable_space Ξ±]
(ΞΌ : measure Ξ±) : ms β€ ΞΌ.to_outer_measure.caratheodory :=
begin
assume s hs,
rw to_outer_measure_eq_outer_measure',
refine outer_measure.caratheodory_is_measurable (Ξ» t, le_infi $ Ξ» ht, _),
rw [β measure_eq_measure' (ht.inter hs),
β measure_eq_measure' (ht.diff hs),
β measure_union _ (ht.inter hs) (ht.diff hs),
inter_union_diff],
exact le_refl _,
exact Ξ» x β¨β¨_, hββ©, _, hββ©, hβ hβ
end
lemma to_measure_to_outer_measure {Ξ±} (m : outer_measure Ξ±)
[ms : measurable_space Ξ±] (h : ms β€ m.caratheodory) :
(m.to_measure h).to_outer_measure = m.trim := rfl
@[simp] lemma to_measure_apply {Ξ±} (m : outer_measure Ξ±)
[ms : measurable_space Ξ±] (h : ms β€ m.caratheodory)
{s : set Ξ±} (hs : is_measurable s) :
m.to_measure h s = m s := m.trim_eq hs
lemma to_outer_measure_to_measure {Ξ± : Type*} [ms : measurable_space Ξ±] {ΞΌ : measure Ξ±} :
ΞΌ.to_outer_measure.to_measure (le_to_outer_measure_caratheodory _) = ΞΌ :=
measure.ext $ Ξ» s, ΞΌ.to_outer_measure.trim_eq
namespace measure
variables {Ξ± : Type*} {Ξ² : Type*} {Ξ³ : Type*}
[measurable_space Ξ±] [measurable_space Ξ²] [measurable_space Ξ³]
instance : has_zero (measure Ξ±) :=
β¨{ to_outer_measure := 0,
m_Union := Ξ» f hf hd, tsum_zero.symm,
trimmed := outer_measure.trim_zero }β©
@[simp] theorem zero_to_outer_measure :
(0 : measure Ξ±).to_outer_measure = 0 := rfl
@[simp] theorem zero_apply (s : set Ξ±) : (0 : measure Ξ±) s = 0 := rfl
instance : inhabited (measure Ξ±) := β¨0β©
instance : has_add (measure Ξ±) :=
β¨Ξ»ΞΌβ ΞΌβ, {
to_outer_measure := ΞΌβ.to_outer_measure + ΞΌβ.to_outer_measure,
m_Union := Ξ»s hs hd,
show ΞΌβ (β i, s i) + ΞΌβ (β i, s i) = β i, ΞΌβ (s i) + ΞΌβ (s i),
by rw [ennreal.tsum_add, measure_Union hd hs, measure_Union hd hs],
trimmed := by rw [outer_measure.trim_add, ΞΌβ.trimmed, ΞΌβ.trimmed] }β©
@[simp] theorem add_to_outer_measure (ΞΌβ ΞΌβ : measure Ξ±) :
(ΞΌβ + ΞΌβ).to_outer_measure = ΞΌβ.to_outer_measure + ΞΌβ.to_outer_measure := rfl
@[simp] theorem add_apply (ΞΌβ ΞΌβ : measure Ξ±) (s : set Ξ±) :
(ΞΌβ + ΞΌβ) s = ΞΌβ s + ΞΌβ s := rfl
instance : add_comm_monoid (measure Ξ±) :=
{ zero := 0,
add := (+),
add_assoc := assume a b c, ext $ assume s hs, add_assoc _ _ _,
add_comm := assume a b, ext $ assume s hs, add_comm _ _,
zero_add := assume a, ext $ assume s hs, zero_add _,
add_zero := assume a, ext $ assume s hs, add_zero _ }
instance : partial_order (measure Ξ±) :=
{ le := Ξ»mβ mβ, β s, is_measurable s β mβ s β€ mβ s,
le_refl := assume m s hs, le_refl _,
le_trans := assume mβ mβ mβ hβ hβ s hs, le_trans (hβ s hs) (hβ s hs),
le_antisymm := assume mβ mβ hβ hβ, ext $
assume s hs, le_antisymm (hβ s hs) (hβ s hs) }
theorem le_iff {ΞΌβ ΞΌβ : measure Ξ±} :
ΞΌβ β€ ΞΌβ β β s, is_measurable s β ΞΌβ s β€ ΞΌβ s := iff.rfl
theorem to_outer_measure_le {ΞΌβ ΞΌβ : measure Ξ±} :
ΞΌβ.to_outer_measure β€ ΞΌβ.to_outer_measure β ΞΌβ β€ ΞΌβ :=
by rw [β ΞΌβ.trimmed, outer_measure.le_trim_iff]; refl
theorem le_iff' {ΞΌβ ΞΌβ : measure Ξ±} :
ΞΌβ β€ ΞΌβ β β s, ΞΌβ s β€ ΞΌβ s :=
to_outer_measure_le.symm
section
variables {m : set (measure Ξ±)} {ΞΌ : measure Ξ±}
lemma Inf_caratheodory (s : set Ξ±) (hs : is_measurable s) :
(Inf (measure.to_outer_measure '' m)).caratheodory.is_measurable s :=
begin
rw [outer_measure.Inf_eq_of_function_Inf_gen],
refine outer_measure.caratheodory_is_measurable (assume t, _),
by_cases ht : t = β
, { simp [ht] },
simp only [outer_measure.Inf_gen_nonempty1 _ _ ht, le_infi_iff, ball_image_iff,
to_outer_measure_apply, measure_eq_infi t],
assume ΞΌ hΞΌ u htu hu,
have hm : β{s t}, s β t β outer_measure.Inf_gen (to_outer_measure '' m) s β€ ΞΌ t,
{ assume s t hst,
rw [outer_measure.Inf_gen_nonempty2 _ _ (mem_image_of_mem _ hΞΌ)],
refine infi_le_of_le (ΞΌ.to_outer_measure) (infi_le_of_le (mem_image_of_mem _ hΞΌ) _),
rw [to_outer_measure_apply],
refine measure_mono hst },
rw [measure_eq_inter_diff hu hs],
refine add_le_add' (hm $ inter_subset_inter_left _ htu) (hm $ diff_subset_diff_left htu)
end
instance : has_Inf (measure Ξ±) :=
β¨Ξ»m, (Inf (to_outer_measure '' m)).to_measure $ Inf_caratheodoryβ©
lemma Inf_apply {m : set (measure Ξ±)} {s : set Ξ±} (hs : is_measurable s) :
Inf m s = Inf (to_outer_measure '' m) s :=
to_measure_apply _ _ hs
private lemma Inf_le (h : ΞΌ β m) : Inf m β€ ΞΌ :=
have Inf (to_outer_measure '' m) β€ ΞΌ.to_outer_measure := Inf_le (mem_image_of_mem _ h),
assume s hs, by rw [Inf_apply hs, β to_outer_measure_apply]; exact this s
private lemma le_Inf (h : βΞΌ' β m, ΞΌ β€ ΞΌ') : ΞΌ β€ Inf m :=
have ΞΌ.to_outer_measure β€ Inf (to_outer_measure '' m) :=
le_Inf $ ball_image_of_ball $ assume ΞΌ hΞΌ, to_outer_measure_le.2 $ h _ hΞΌ,
assume s hs, by rw [Inf_apply hs, β to_outer_measure_apply]; exact this s
instance : has_Sup (measure Ξ±) := β¨Ξ»s, Inf {ΞΌ' | βΞΌβs, ΞΌ β€ ΞΌ' }β©
private lemma le_Sup (h : ΞΌ β m) : ΞΌ β€ Sup m := le_Inf $ assume ΞΌ' h', h' _ h
private lemma Sup_le (h : βΞΌ' β m, ΞΌ' β€ ΞΌ) : Sup m β€ ΞΌ := Inf_le h
instance : order_bot (measure Ξ±) :=
{ bot := 0, bot_le := assume a s hs, bot_le, .. measure.partial_order }
instance : order_top (measure Ξ±) :=
{ top := (β€ : outer_measure Ξ±).to_measure (by rw [outer_measure.top_caratheodory]; exact le_top),
le_top := assume a s hs,
by by_cases s = β
; simp [h, to_measure_apply β€ _ hs, outer_measure.top_apply],
.. measure.partial_order }
instance : complete_lattice (measure Ξ±) :=
{ Inf := Inf,
Sup := Sup,
inf := Ξ»a b, Inf {a, b},
sup := Ξ»a b, Sup {a, b},
le_Sup := assume s ΞΌ h, le_Sup h,
Sup_le := assume s ΞΌ h, Sup_le h,
Inf_le := assume s ΞΌ h, Inf_le h,
le_Inf := assume s ΞΌ h, le_Inf h,
le_sup_left := assume a b, le_Sup $ by simp,
le_sup_right := assume a b, le_Sup $ by simp,
sup_le := assume a b c hac hbc, Sup_le $ by simp [*, or_imp_distrib] {contextual := tt},
inf_le_left := assume a b, Inf_le $ by simp,
inf_le_right := assume a b, Inf_le $ by simp,
le_inf := assume a b c hac hbc, le_Inf $ by simp [*, or_imp_distrib] {contextual := tt},
.. measure.partial_order, .. measure.lattice.order_top, .. measure.lattice.order_bot }
end
def map (f : Ξ± β Ξ²) (ΞΌ : measure Ξ±) : measure Ξ² :=
if hf : measurable f then
(ΞΌ.to_outer_measure.map f).to_measure $ Ξ» s hs t,
le_to_outer_measure_caratheodory ΞΌ _ (hf _ hs) (f β»ΒΉ' t)
else 0
variables {ΞΌ Ξ½ : measure Ξ±}
@[simp] theorem map_apply {f : Ξ± β Ξ²} (hf : measurable f)
{s : set Ξ²} (hs : is_measurable s) :
(map f ΞΌ : measure Ξ²) s = ΞΌ (f β»ΒΉ' s) :=
by rw [map, dif_pos hf, to_measure_apply _ _ hs]; refl
@[simp] lemma map_id : map id ΞΌ = ΞΌ :=
ext $ Ξ» s, map_apply measurable_id
lemma map_map {g : Ξ² β Ξ³} {f : Ξ± β Ξ²} (hg : measurable g) (hf : measurable f) :
map g (map f ΞΌ) = map (g β f) ΞΌ :=
ext $ Ξ» s hs,
by simp [hf, hg, hs, hg.preimage hs, hg.comp hf];
rw β preimage_comp
/-- The dirac measure. -/
def dirac (a : Ξ±) : measure Ξ± :=
(outer_measure.dirac a).to_measure (by simp)
@[simp] lemma dirac_apply (a : Ξ±) {s : set Ξ±} (hs : is_measurable s) :
(dirac a : measure Ξ±) s = β¨ h : a β s, 1 :=
to_measure_apply _ _ hs
/-- Sum of an indexed family of measures. -/
def sum {ΞΉ : Type*} (f : ΞΉ β measure Ξ±) : measure Ξ± :=
(outer_measure.sum (Ξ» i, (f i).to_outer_measure)).to_measure $
le_trans
(by exact le_infi (Ξ» i, le_to_outer_measure_caratheodory _))
(outer_measure.le_sum_caratheodory _)
/-- Counting measure on any measurable space. -/
def count : measure Ξ± := sum dirac
@[class] def is_complete {Ξ±} {_:measurable_space Ξ±} (ΞΌ : measure Ξ±) : Prop :=
β s, ΞΌ s = 0 β is_measurable s
/-- The "almost everywhere" filter of co-null sets. -/
def a_e (ΞΌ : measure Ξ±) : filter Ξ± :=
{ sets := {s | ΞΌ (-s) = 0},
univ_sets := by simp [measure_empty],
inter_sets := Ξ» s t hs ht, by simp [compl_inter]; exact measure_union_null hs ht,
sets_of_superset := Ξ» s t hs hst, measure_mono_null (set.compl_subset_compl.2 hst) hs }
lemma mem_a_e_iff (s : set Ξ±) : s β ΞΌ.a_e.sets β ΞΌ (- s) = 0 := iff.refl _
end measure
end measure_theory
section is_complete
open measure_theory
variables {Ξ± : Type*} [measurable_space Ξ±] (ΞΌ : measure Ξ±)
def is_null_measurable (s : set Ξ±) : Prop :=
β t z, s = t βͺ z β§ is_measurable t β§ ΞΌ z = 0
theorem is_null_measurable_iff {ΞΌ : measure Ξ±} {s : set Ξ±} :
is_null_measurable ΞΌ s β
β t, t β s β§ is_measurable t β§ ΞΌ (s \ t) = 0 :=
begin
split,
{ rintro β¨t, z, rfl, ht, hzβ©,
refine β¨t, set.subset_union_left _ _, ht, measure_mono_null _ hzβ©,
simp [union_diff_left, diff_subset] },
{ rintro β¨t, st, ht, hzβ©,
exact β¨t, _, (union_diff_cancel st).symm, ht, hzβ© }
end
theorem is_null_measurable_measure_eq {ΞΌ : measure Ξ±} {s t : set Ξ±}
(st : t β s) (hz : ΞΌ (s \ t) = 0) : ΞΌ s = ΞΌ t :=
begin
refine le_antisymm _ (measure_mono st),
have := measure_union_le t (s \ t),
rw [union_diff_cancel st, hz] at this, simpa
end
theorem is_measurable.is_null_measurable
{s : set Ξ±} (hs : is_measurable s) : is_null_measurable ΞΌ s :=
β¨s, β
, by simp, hs, ΞΌ.emptyβ©
theorem is_null_measurable_of_complete [c : ΞΌ.is_complete]
{s : set Ξ±} : is_null_measurable ΞΌ s β is_measurable s :=
β¨by rintro β¨t, z, rfl, ht, hzβ©; exact
is_measurable.union ht (c _ hz),
Ξ» h, h.is_null_measurable _β©
variables {ΞΌ}
theorem is_null_measurable.union_null {s z : set Ξ±}
(hs : is_null_measurable ΞΌ s) (hz : ΞΌ z = 0) :
is_null_measurable ΞΌ (s βͺ z) :=
begin
rcases hs with β¨t, z', rfl, ht, hz'β©,
exact β¨t, z' βͺ z, set.union_assoc _ _ _, ht, le_zero_iff_eq.1
(le_trans (measure_union_le _ _) $ by simp [hz, hz'])β©
end
theorem null_is_null_measurable {z : set Ξ±}
(hz : ΞΌ z = 0) : is_null_measurable ΞΌ z :=
by simpa using (is_measurable.empty.is_null_measurable _).union_null hz
theorem is_null_measurable.Union_nat {s : β β set Ξ±}
(hs : β i, is_null_measurable ΞΌ (s i)) :
is_null_measurable ΞΌ (Union s) :=
begin
choose t ht using assume i, is_null_measurable_iff.1 (hs i),
simp [forall_and_distrib] at ht,
rcases ht with β¨st, ht, hzβ©,
refine is_null_measurable_iff.2
β¨Union t, Union_subset_Union st, is_measurable.Union ht,
measure_mono_null _ (measure_Union_null hz)β©,
rw [diff_subset_iff, β Union_union_distrib],
exact Union_subset_Union (Ξ» i, by rw β diff_subset_iff)
end
theorem is_measurable.diff_null {s z : set Ξ±}
(hs : is_measurable s) (hz : ΞΌ z = 0) :
is_null_measurable ΞΌ (s \ z) :=
begin
rw measure_eq_infi at hz,
choose f hf using show β q : {q:β//q>0}, β t:set Ξ±,
z β t β§ is_measurable t β§ ΞΌ t < (nnreal.of_real q.1 : ennreal),
{ rintro β¨Ξ΅, Ξ΅0β©,
have : 0 < (nnreal.of_real Ξ΅ : ennreal), { simpa using Ξ΅0 },
rw β hz at this, simpa [infi_lt_iff] },
refine is_null_measurable_iff.2 β¨s \ Inter f,
diff_subset_diff_right (subset_Inter (Ξ» i, (hf i).1)),
hs.diff (is_measurable.Inter (Ξ» i, (hf i).2.1)),
measure_mono_null _ (le_zero_iff_eq.1 $ le_of_not_lt $ Ξ» h, _)β©,
{ exact Inter f },
{ rw [diff_subset_iff, diff_union_self],
exact subset.trans (diff_subset _ _) (subset_union_left _ _) },
rcases ennreal.lt_iff_exists_rat_btwn.1 h with β¨Ξ΅, Ξ΅0', Ξ΅0, hβ©,
simp at Ξ΅0,
apply not_le_of_lt (lt_trans (hf β¨Ξ΅, Ξ΅0β©).2.2 h),
exact measure_mono (Inter_subset _ _)
end
theorem is_null_measurable.diff_null {s z : set Ξ±}
(hs : is_null_measurable ΞΌ s) (hz : ΞΌ z = 0) :
is_null_measurable ΞΌ (s \ z) :=
begin
rcases hs with β¨t, z', rfl, ht, hz'β©,
rw [set.union_diff_distrib],
exact (ht.diff_null hz).union_null (measure_mono_null (diff_subset _ _) hz')
end
theorem is_null_measurable.compl {s : set Ξ±}
(hs : is_null_measurable ΞΌ s) :
is_null_measurable ΞΌ (-s) :=
begin
rcases hs with β¨t, z, rfl, ht, hzβ©,
rw compl_union,
exact ht.compl.diff_null hz
end
def null_measurable {Ξ± : Type u} [measurable_space Ξ±]
(ΞΌ : measure Ξ±) : measurable_space Ξ± :=
{ is_measurable := is_null_measurable ΞΌ,
is_measurable_empty := is_measurable.empty.is_null_measurable _,
is_measurable_compl := Ξ» s hs, hs.compl,
is_measurable_Union := Ξ» f, is_null_measurable.Union_nat }
def completion {Ξ± : Type u} [measurable_space Ξ±] (ΞΌ : measure Ξ±) :
@measure_theory.measure Ξ± (null_measurable ΞΌ) :=
{ to_outer_measure := ΞΌ.to_outer_measure,
m_Union := Ξ» s hs hd, show ΞΌ (Union s) = β i, ΞΌ (s i), begin
choose t ht using assume i, is_null_measurable_iff.1 (hs i),
simp [forall_and_distrib] at ht, rcases ht with β¨st, ht, hzβ©,
rw is_null_measurable_measure_eq (Union_subset_Union st),
{ rw measure_Union _ ht,
{ congr, funext i,
exact (is_null_measurable_measure_eq (st i) (hz i)).symm },
{ rintro i j ij x β¨hβ, hββ©,
exact hd i j ij β¨st i hβ, st j hββ© } },
{ refine measure_mono_null _ (measure_Union_null hz),
rw [diff_subset_iff, β Union_union_distrib],
exact Union_subset_Union (Ξ» i, by rw β diff_subset_iff) }
end,
trimmed := begin
letI := null_measurable ΞΌ,
refine le_antisymm (Ξ» s, _) (outer_measure.trim_ge _),
rw outer_measure.trim_eq_infi,
dsimp, clear _inst,
rw measure_eq_infi s,
exact infi_le_infi (Ξ» t, infi_le_infi $ Ξ» st,
infi_le_infi2 $ Ξ» ht, β¨ht.is_null_measurable _, le_refl _β©)
end }
instance completion.is_complete {Ξ± : Type u} [measurable_space Ξ±] (ΞΌ : measure Ξ±) :
(completion ΞΌ).is_complete :=
Ξ» z hz, null_is_null_measurable hz
end is_complete
namespace measure_theory
/-- A measure space is a measurable space equipped with a
measure, referred to as `volume`. -/
class measure_space (Ξ± : Type*) extends measurable_space Ξ± :=
(ΞΌ {} : measure Ξ±)
section measure_space
variables {Ξ± : Type*} [measure_space Ξ±] {sβ sβ : set Ξ±}
open measure_space
def volume : set Ξ± β ennreal := @ΞΌ Ξ± _
@[simp] lemma volume_empty : volume (β
: set Ξ±) = 0 := ΞΌ.empty
lemma volume_mono : sβ β sβ β volume sβ β€ volume sβ := measure_mono
lemma volume_mono_null : sβ β sβ β volume sβ = 0 β volume sβ = 0 :=
measure_mono_null
theorem volume_Union_le {Ξ²} [encodable Ξ²] :
β (s : Ξ² β set Ξ±), volume (βi, s i) β€ (βi, volume (s i)) :=
measure_Union_le
lemma volume_Union_null {Ξ²} [encodable Ξ²] {s : Ξ² β set Ξ±} :
(β i, volume (s i) = 0) β volume (βi, s i) = 0 :=
measure_Union_null
theorem volume_union_le : β (sβ sβ : set Ξ±), volume (sβ βͺ sβ) β€ volume sβ + volume sβ :=
measure_union_le
lemma volume_union_null : volume sβ = 0 β volume sβ = 0 β volume (sβ βͺ sβ) = 0 :=
measure_union_null
lemma volume_Union {Ξ²} [encodable Ξ²] {f : Ξ² β set Ξ±} :
pairwise (disjoint on f) β (βi, is_measurable (f i)) β
volume (βi, f i) = (βi, volume (f i)) :=
measure_Union
lemma volume_union : disjoint sβ sβ β is_measurable sβ β is_measurable sβ β
volume (sβ βͺ sβ) = volume sβ + volume sβ :=
measure_union
lemma volume_bUnion {Ξ²} {s : set Ξ²} {f : Ξ² β set Ξ±} : countable s β
pairwise_on s (disjoint on f) β (βbβs, is_measurable (f b)) β
volume (βbβs, f b) = βp:s, volume (f p.1) :=
measure_bUnion
lemma volume_sUnion {S : set (set Ξ±)} : countable S β
pairwise_on S disjoint β (βsβS, is_measurable s) β
volume (ββ S) = βs:S, volume s.1 :=
measure_sUnion
lemma volume_bUnion_finset {Ξ²} {s : finset Ξ²} {f : Ξ² β set Ξ±}
(hd : pairwise_on βs (disjoint on f)) (hm : βbβs, is_measurable (f b)) :
volume (βbβs, f b) = s.sum (Ξ»p, volume (f p)) :=
show volume (βbβ(βs : set Ξ²), f b) = s.sum (Ξ»p, volume (f p)),
begin
rw [volume_bUnion (countable_finite (finset.finite_to_set s)) hd hm, tsum_eq_sum],
{ show s.attach.sum (Ξ»b:(βs : set Ξ²), volume (f b)) = s.sum (Ξ»b, volume (f b)),
exact @finset.sum_attach _ _ s _ (Ξ»b, volume (f b)) },
simp
end
lemma volume_diff : sβ β sβ β is_measurable sβ β is_measurable sβ β
volume sβ < β€ β volume (sβ \ sβ) = volume sβ - volume sβ :=
measure_diff
/-- `ββ a:Ξ±, p a` states that the property `p` is almost everywhere true in the measure space
associated with `Ξ±`. This means that the measure of the complementary of `p` is `0`.
In a probability measure, the measure of `p` is `1`, when `p` is measurable.
-/
def all_ae (p : Ξ± β Prop) : Prop := { a | p a } β (@measure_space.ΞΌ Ξ± _).a_e
notation `ββ` binders `, ` r:(scoped P, all_ae P) := r
lemma all_ae_congr {p q : Ξ± β Prop} (h : ββ a, p a β q a) : (ββ a, p a) β (ββ a, q a) :=
iff.intro
(assume h', by filter_upwards [h, h'] assume a hpq hp, hpq.1 hp)
(assume h', by filter_upwards [h, h'] assume a hpq hq, hpq.2 hq)
lemma all_ae_iff {p : Ξ± β Prop} : (ββ a, p a) β volume { a | Β¬ p a } = 0 := iff.refl _
lemma all_ae_of_all {p : Ξ± β Prop} : (βa, p a) β ββ a, p a := assume h,
by {rw all_ae_iff, convert volume_empty, simp only [h, not_true], reflexivity}
lemma all_ae_all_iff {ΞΉ : Type*} [encodable ΞΉ] {p : Ξ± β ΞΉ β Prop} :
(ββ a, βi, p a i) β (βi, ββ a, p a i):=
begin
refine iff.intro (assume h i, _) (assume h, _),
{ filter_upwards [h] assume a ha, ha i },
{ have h := measure_Union_null h,
rw [β compl_Inter] at h,
filter_upwards [h] assume a, mem_Inter.1 }
end
end measure_space
end measure_theory
|
7f7fdeb026f7a0203f9583929f04944218d91783 | 75db7e3219bba2fbf41bf5b905f34fcb3c6ca3f2 | /tests/lean/run/using_bug2.lean | cf457f683ba74d61614a2e19e19ccccbece9938b | [
"Apache-2.0"
] | permissive | jroesch/lean | 30ef0860fa905d35b9ad6f76de1a4f65c9af6871 | 3de4ec1a6ce9a960feb2a48eeea8b53246fa34f2 | refs/heads/master | 1,586,090,835,348 | 1,455,142,203,000 | 1,455,142,277,000 | 51,536,958 | 1 | 0 | null | 1,455,215,811,000 | 1,455,215,811,000 | null | UTF-8 | Lean | false | false | 412 | lean | variable {A : Type}
variable {f : A β A β A}
variable {finv : A β A}
premise (h : β x y : A, finv (f x y) = y)
theorem fooβ : β x y z : A, f x y = f x z β y = z :=
Ξ» x y z, assume e, using h, from sorry
theorem fooβ : β x y z : A, f x y = f x z β y = z :=
Ξ» x y z, assume e,
assert sβ : finv (f x y) = finv (f x z), by rewrite e,
show y = z, using h, by rewrite *h at sβ; exact sβ
|
d67e663964a5a0c4ae0af8fe84f6763785814cba | 947b78d97130d56365ae2ec264df196ce769371a | /tests/lean/run/induction1.lean | d5d2c458ca9bd6599f11524ede7704bef472eec0 | [
"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 | 2,424 | lean | new_frontend
@[recursor 4]
def Or.elim2 {p q r : Prop} (major : p β¨ q) (left : p β r) (right : q β r) : r :=
Or.elim major left right
theorem tst0 {p q : Prop } (h : p β¨ q) : q β¨ p :=
by {
induction h;
{ apply Or.inr; assumption };
{ apply Or.inl; assumption }
}
theorem tst0' {p q : Prop } (h : p β¨ q) : q β¨ p := by
induction h
focus
apply Or.inr
assumption
focus
apply Or.inl
assumption
theorem tst1 {p q : Prop } (h : p β¨ q) : q β¨ p := by
induction h with
| inr h2 => exact Or.inl h2
| inl h1 => exact Or.inr h1
theorem tst2 {p q : Prop } (h : p β¨ q) : q β¨ p := by
induction h using elim2 with
| left _ => apply Or.inr; assumption
| right _ => apply Or.inl; assumption
theorem tst3 {p q : Prop } (h : p β¨ q) : q β¨ p := by
induction h using elim2 with
| right h => exact Or.inl h
| left h => exact Or.inr h
theorem tst4 {p q : Prop } (h : p β¨ q) : q β¨ p := by
induction h using elim2 with
| right h => ?myright
| left h => ?myleft
case myleft => exact Or.inr h
case myright => exact Or.inl h
theorem tst5 {p q : Prop } (h : p β¨ q) : q β¨ p := by
induction h using elim2 with
| right h => _
| left h =>
refine Or.inr ?_
exact h
case right => exact Or.inl h
theorem tst6 {p q : Prop } (h : p β¨ q) : q β¨ p :=
by {
cases h with
| inr h2 => exact Or.inl h2
| inl h1 => exact Or.inr h1
}
theorem tst7 {Ξ± : Type} (xs : List Ξ±) (h : (a : Ξ±) β (as : List Ξ±) β xs β a :: as) : xs = [] :=
by {
induction xs with
| nil => exact rfl
| cons z zs ih => exact absurd rfl (h z zs)
}
theorem tst8 {Ξ± : Type} (xs : List Ξ±) (h : (a : Ξ±) β (as : List Ξ±) β xs β a :: as) : xs = [] :=
by {
induction xs;
exact rfl;
exact absurd rfl $ h _ _
}
theorem tst9 {Ξ± : Type} (xs : List Ξ±) (h : (a : Ξ±) β (as : List Ξ±) β xs β a :: as) : xs = [] :=
by cases xs with
| nil => exact rfl
| cons z zs => exact absurd rfl (h z zs)
theorem tst10 {p q : Prop } (hβ : p β q) (hβ : p) : q :=
by induction hβ using Iff.elim with
| _ h _ => exact h hβ
def Iff2 (m p q : Prop) := p β q
theorem tst11 {p q r : Prop } (hβ : Iff2 r p q) (hβ : p) : q :=
by induction hβ using Iff.elim with
| _ h _ => exact h hβ
theorem tst12 {p q : Prop } (hβ : p β¨ q) (hβ : p β q) (hβ : p) : q := by
failIfSuccess induction hβ using Iff.elim
induction hβ using Iff.elim with
| _ h _ =>
exact h hβ
|
a81b8f8222a91dc5b43f7f308e9501f7597d35cf | 1b8c143de090d160f4629428a34dd6a2addf5264 | /Chap2.hlean | 7ba523fa907aab1f4ef3e08368891f0b869d4b36 | [] | no_license | BinderDavid/HoTT-StudyGroup | 23a86e220b6ce70eb49c3a9bf990443e292416d6 | 8baea70970f2aa59cce5396cf69c3dd1d2b461b1 | refs/heads/master | 1,620,090,578,419 | 1,494,946,912,000 | 1,494,946,912,000 | 71,147,801 | 3 | 2 | null | null | null | null | UTF-8 | Lean | false | false | 1,854 | hlean | -- Homotopy Type Theory Book, formalization of the theorems in the book order
-- (David Binder)
--Nicer pretty printer, print types of bound variables
set_option pp.binder_types true
--Show the type of the identity eliminator
check @eq.rec -- Ξ {A : Type} {a : A}
-- {C : Ξ {a_1 : A}, a = a_1 β Type}, Any type family over a_1 and proofs a = a_1
-- C a (eq.refl a) β Induction step
-- (Ξ {a_1 : A} (n : a = a_1), C a_1 n) Result of the Eliminator
-- The type shows that Lean uses Based Path Induction instead of J
-- Chapter 2.1: Types are higher groupoids
section chap2
--Lemma 2.1.1: Symmetry
--Define a type family P_symm
definition P_symm (A : Type) (a : A) := Ξ» (x : A)(n : a = x), x = a
check P_symm
--Proof:
theorem symm (A : Type) (a b : A) : a = b β b = a :=
have IndHyp : P_symm A a a (eq.refl a),
from eq.refl a, --The induction case is proved with refl
have Elim : Ξ {a_1 : A} (n : a = a_1), P_symm A a a_1 n , --The eq.rec applied to the induction case gives the eliminator
from @eq.rec A a (P_symm A a) IndHyp,
assume Hab : a = b, --We assume a = b
show b = a,
from @Elim b Hab --And therefore get b = a
--Lemma 2.1.2: Transitivity
--Type family:
definition P_trans (A : Type) (a : A) := Ξ» (x : A)(n : a = x), Ξ c : A, x = c β a = c
check P_trans
--Proof:
theorem trans' (A : Type) (a b c : A) : a = b β (b = c β a = c) :=
have IndHyp : P_trans A a a (eq.refl a),
from Ξ» c : A, id,
have Elim : Ξ {a_1 : A} (n : a = a_1), P_trans A a a_1 n, from
@eq.rec A a (P_trans A a) IndHyp,
assume Hab : a = b,
(@Elim b Hab) c
--Lemma 2.1.4
end chap2
|
47fd76ce18bd31e862b4785d9696f02cad374ce6 | 6094e25ea0b7699e642463b48e51b2ead6ddc23f | /tests/lean/run/vector.lean | 6c270907cd481ca7654414ea12692c01c2ab1303 | [
"Apache-2.0"
] | permissive | gbaz/lean | a7835c4e3006fbbb079e8f8ffe18aacc45adebfb | a501c308be3acaa50a2c0610ce2e0d71becf8032 | refs/heads/master | 1,611,198,791,433 | 1,451,339,111,000 | 1,451,339,111,000 | 48,713,797 | 0 | 0 | null | 1,451,338,939,000 | 1,451,338,939,000 | null | UTF-8 | Lean | false | false | 4,892 | lean | import logic data.nat.basic data.prod data.unit
open nat prod
inductive vector (A : Type) : nat β Type :=
| vnil {} : vector A zero
| vcons : Ξ {n : nat}, A β vector A n β vector A (succ n)
namespace vector
-- print definition no_confusion
infixr `::` := vcons
local abbreviation no_confusion := @vector.no_confusion
local abbreviation below := @vector.below
theorem vcons.injβ {A : Type} {n : nat} (aβ aβ : A) (vβ vβ : vector A n) : vcons aβ vβ = vcons aβ vβ β aβ = aβ :=
begin
intro h, apply (no_confusion h), intros, assumption
end
theorem vcons.injβ {A : Type} {n : nat} (aβ aβ : A) (vβ vβ : vector A n) : vcons aβ vβ = vcons aβ vβ β vβ = vβ :=
begin
intro h, apply heq.to_eq, apply (no_confusion h), intros, eassumption,
end
set_option pp.universes true
check @below
namespace manual
section
universe variables lβ lβ
variable {A : Type.{lβ}}
variable {C : Ξ (n : nat), vector A n β Type.{lβ}}
definition brec_on {n : nat} (v : vector A n) (H : Ξ (n : nat) (v : vector A n), @vector.below A C n v β C n v) : C n v :=
have general : C n v Γ @vector.below A C n v, from
vector.rec_on v
(pair (H zero vnil poly_unit.star) poly_unit.star)
(Ξ» (nβ : nat) (aβ : A) (vβ : vector A nβ) (rβ : C nβ vβ Γ @vector.below A C nβ vβ),
have b : @vector.below A C _ (vcons aβ vβ), from
rβ,
have c : C (succ nβ) (vcons aβ vβ), from
H (succ nβ) (vcons aβ vβ) b,
pair c b),
prβ general
end
end manual
-- check vector.brec_on
definition bw := @below
definition sum {n : nat} (v : vector nat n) : nat :=
vector.brec_on v (Ξ» (n : nat) (v : vector nat n),
vector.cases_on v
(Ξ» (B : bw vnil), zero)
(Ξ» (nβ : nat) (a : nat) (vβ : vector nat nβ) (B : bw (vcons a vβ)),
a + prβ B))
example : sum (10 :: 20 :: vnil) = 30 :=
rfl
definition addk {n : nat} (v : vector nat n) (k : nat) : vector nat n :=
vector.brec_on v (Ξ» (n : nat) (v : vector nat n),
vector.cases_on v
(Ξ» (B : bw vnil), vnil)
(Ξ» (nβ : nat) (aβ : nat) (vβ : vector nat nβ) (B : bw (vcons aβ vβ)),
vcons (aβ+k) (prβ B)))
example : addk (1 :: 2 :: vnil) 3 = 4 :: 5 :: vnil :=
rfl
definition append.{l} {A : Type.{l+1}} {n m : nat} (w : vector A m) (v : vector A n) : vector A (n + m) :=
vector.brec_on w (Ξ» (n : nat) (w : vector A n),
vector.cases_on w
(Ξ» (B : bw vnil), v)
(Ξ» (nβ : nat) (aβ : A) (vβ : vector A nβ) (B : bw (vcons aβ vβ)),
vcons aβ (prβ B)))
example : append ((1:nat) :: 2 :: vnil) (3 :: vnil) = 1 :: 2 :: 3 :: vnil :=
rfl
definition head {A : Type} {n : nat} (v : vector A (succ n)) : A :=
vector.cases_on v
(Ξ» H : succ n = 0, nat.no_confusion H)
(Ξ»n' h t (H : succ n = succ n'), h)
rfl
definition tail {A : Type} {n : nat} (v : vector A (succ n)) : vector A n :=
@vector.cases_on A (Ξ»n' v, succ n = n' β vector A (pred n')) (succ n) v
(Ξ» H : succ n = 0, nat.no_confusion H)
(Ξ» (n' : nat) (h : A) (t : vector A n') (H : succ n = succ n'),
t)
rfl
definition add {n : nat} (w v : vector nat n) : vector nat n :=
@vector.brec_on nat (Ξ» (n : nat) (v : vector nat n), vector nat n β vector nat n) n w
(Ξ» (n : nat) (w : vector nat n),
vector.cases_on w
(Ξ» (B : bw vnil) (w : vector nat zero), vnil)
(Ξ» (nβ : nat) (aβ : nat) (vβ : vector nat nβ) (B : bw (vcons aβ vβ)) (v : vector nat (succ nβ)),
vcons (aβ + head v) (prβ B (tail v)))) v
example : add (1 :: 2 :: vnil) (3 :: 5 :: vnil) = 4 :: 7 :: vnil :=
rfl
definition map {A B C : Type} {n : nat} (f : A β B β C) (w : vector A n) (v : vector B n) : vector C n :=
let P := Ξ» (n : nat) (v : vector A n), vector B n β vector C n in
@vector.brec_on A P n w
(Ξ» (n : nat) (w : vector A n),
begin
cases w with [n', hβ, tβ],
show @below A P zero vnil β vector B zero β vector C zero, from
Ξ» b v, vnil,
show @below A P (succ n') (hβ :: tβ) β vector B (succ n') β vector C (succ n'), from
Ξ» b v,
begin
cases v with [n', hβ, tβ],
have r : vector B n' β vector C n', from prβ b,
exact ((f hβ hβ) :: r tβ),
end
end) v
theorem map_nil_nil {A B C : Type} (f : A β B β C) : map f vnil vnil = vnil :=
rfl
theorem map_cons_cons {A B C : Type} (f : A β B β C) (a : A) (b : B) {n : nat} (va : vector A n) (vb : vector B n) :
map f (a :: va) (b :: vb) = f a b :: map f va vb :=
rfl
example : map nat.add (1 :: 2 :: vnil) (3 :: 5 :: vnil) = 4 :: 7 :: vnil :=
rfl
print definition map
end vector
|
c42f73d3acb8f92941d8f06277d2c3a70d7a063e | bb31430994044506fa42fd667e2d556327e18dfe | /src/measure_theory/measure/doubling.lean | c293a057d4dd6eed9dd125cf5ecb6fe158cdff29 | [
"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 | 6,961 | lean | /-
Copyright (c) 2022 Oliver Nash. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Oliver Nash
-/
import analysis.special_functions.log.base
import measure_theory.measure.measure_space_def
/-!
# Doubling measures
A doubling measure `ΞΌ` on a metric space is a measure for which there exists a constant `C` such
that for all sufficiently small radii `Ξ΅`, and for any centre, the measure of a ball of radius
`2 * Ξ΅` is bounded by `C` times the measure of the concentric ball of radius `Ξ΅`.
This file records basic files on doubling measures.
## Main definitions
* `is_doubling_measure`: the definition of a doubling measure (as a typeclass).
* `is_doubling_measure.doubling_constant`: a function yielding the doubling constant `C` appearing
in the definition of a doubling measure.
-/
noncomputable theory
open set filter metric measure_theory topological_space
open_locale ennreal nnreal topological_space
/-- A measure `ΞΌ` is said to be a doubling measure if there exists a constant `C` such that for
all sufficiently small radii `Ξ΅`, and for any centre, the measure of a ball of radius `2 * Ξ΅` is
bounded by `C` times the measure of the concentric ball of radius `Ξ΅`.
Note: it is important that this definition makes a demand only for sufficiently small `Ξ΅`. For
example we want hyperbolic space to carry the instance `is_doubling_measure volume` but volumes grow
exponentially in hyperbolic space. To be really explicit, consider the hyperbolic plane of
curvature -1, the area of a disc of radius `Ξ΅` is `A(Ξ΅) = 2Ο(cosh(Ξ΅) - 1)` so `A(2Ξ΅)/A(Ξ΅) ~ exp(Ξ΅)`.
-/
class is_doubling_measure {Ξ± : Type*} [metric_space Ξ±] [measurable_space Ξ±] (ΞΌ : measure Ξ±) :=
(exists_measure_closed_ball_le_mul [] :
β (C : ββ₯0), βαΆ Ξ΅ in π[>] 0, β x, ΞΌ (closed_ball x (2 * Ξ΅)) β€ C * ΞΌ (closed_ball x Ξ΅))
namespace is_doubling_measure
variables {Ξ± : Type*} [metric_space Ξ±] [measurable_space Ξ±] (ΞΌ : measure Ξ±) [is_doubling_measure ΞΌ]
/-- A doubling constant for a doubling measure.
See also `is_doubling_measure.scaling_constant_of`. -/
def doubling_constant : ββ₯0 := classical.some $ exists_measure_closed_ball_le_mul ΞΌ
lemma exists_measure_closed_ball_le_mul' :
βαΆ Ξ΅ in π[>] 0, β x, ΞΌ (closed_ball x (2 * Ξ΅)) β€ doubling_constant ΞΌ * ΞΌ (closed_ball x Ξ΅) :=
classical.some_spec $ exists_measure_closed_ball_le_mul ΞΌ
lemma exists_eventually_forall_measure_closed_ball_le_mul (K : β) :
β (C : ββ₯0), βαΆ Ξ΅ in π[>] 0, β x t (ht : t β€ K),
ΞΌ (closed_ball x (t * Ξ΅)) β€ C * ΞΌ (closed_ball x Ξ΅) :=
begin
let C := doubling_constant ΞΌ,
have hΞΌ : β (n : β), βαΆ Ξ΅ in π[>] 0, β x,
ΞΌ (closed_ball x (2^n * Ξ΅)) β€ β(C^n) * ΞΌ (closed_ball x Ξ΅),
{ intros n,
induction n with n ih, { simp, },
replace ih := eventually_nhds_within_pos_mul_left (two_pos : 0 < (2 : β)) ih,
refine (ih.and (exists_measure_closed_ball_le_mul' ΞΌ)).mono (Ξ» Ξ΅ hΞ΅ x, _),
calc ΞΌ (closed_ball x (2^(n + 1) * Ξ΅))
= ΞΌ (closed_ball x (2^n * (2 * Ξ΅))) : by rw [pow_succ', mul_assoc]
... β€ β(C^n) * ΞΌ (closed_ball x (2 * Ξ΅)) : hΞ΅.1 x
... β€ β(C^n) * (C * ΞΌ (closed_ball x Ξ΅)) : ennreal.mul_left_mono (hΞ΅.2 x)
... = β(C^(n + 1)) * ΞΌ (closed_ball x Ξ΅) : by rw [β mul_assoc, pow_succ', ennreal.coe_mul], },
rcases lt_or_le K 1 with hK | hK,
{ refine β¨1, _β©,
simp only [ennreal.coe_one, one_mul],
exact eventually_mem_nhds_within.mono (Ξ» Ξ΅ hΞ΅ x t ht,
measure_mono $ closed_ball_subset_closed_ball (by nlinarith [mem_Ioi.mp hΞ΅])), },
{ refine β¨C^βreal.logb 2 Kββ, ((hΞΌ βreal.logb 2 Kββ).and eventually_mem_nhds_within).mono
(Ξ» Ξ΅ hΞ΅ x t ht, le_trans (measure_mono $ closed_ball_subset_closed_ball _) (hΞ΅.1 x))β©,
refine mul_le_mul_of_nonneg_right (ht.trans _) (mem_Ioi.mp hΞ΅.2).le,
conv_lhs { rw β real.rpow_logb two_pos (by norm_num) (by linarith : 0 < K), },
rw β real.rpow_nat_cast,
exact real.rpow_le_rpow_of_exponent_le one_le_two (nat.le_ceil (real.logb 2 K)), },
end
/-- A variant of `is_doubling_measure.doubling_constant` which allows for scaling the radius by
values other than `2`. -/
def scaling_constant_of (K : β) : ββ₯0 :=
max (classical.some $ exists_eventually_forall_measure_closed_ball_le_mul ΞΌ K) 1
@[simp] lemma one_le_scaling_constant_of (K : β) : 1 β€ scaling_constant_of ΞΌ K :=
le_max_of_le_right $ le_refl 1
lemma eventually_measure_mul_le_scaling_constant_of_mul (K : β) :
β (R : β), 0 < R β§ β x t r (ht : t β Ioc 0 K) (hr : r β€ R),
ΞΌ (closed_ball x (t * r)) β€ scaling_constant_of ΞΌ K * ΞΌ (closed_ball x r) :=
begin
have h := classical.some_spec (exists_eventually_forall_measure_closed_ball_le_mul ΞΌ K),
rcases mem_nhds_within_Ioi_iff_exists_Ioc_subset.1 h with β¨R, Rpos, hRβ©,
refine β¨R, Rpos, Ξ» x t r ht hr, _β©,
rcases lt_trichotomy r 0 with rneg|rfl|rpos,
{ have : t * r < 0, from mul_neg_of_pos_of_neg ht.1 rneg,
simp only [closed_ball_eq_empty.2 this, measure_empty, zero_le'] },
{ simp only [mul_zero, closed_ball_zero],
refine le_mul_of_one_le_of_le _ le_rfl,
apply ennreal.one_le_coe_iff.2 (le_max_right _ _) },
{ apply (hR β¨rpos, hrβ© x t ht.2).trans _,
exact ennreal.mul_le_mul (ennreal.coe_le_coe.2 (le_max_left _ _)) le_rfl }
end
lemma eventually_measure_le_scaling_constant_mul (K : β) :
βαΆ r in π[>] 0, β x,
ΞΌ (closed_ball x (K * r)) β€ scaling_constant_of ΞΌ K * ΞΌ (closed_ball x r) :=
begin
filter_upwards [classical.some_spec (exists_eventually_forall_measure_closed_ball_le_mul ΞΌ K)]
with r hr x,
exact (hr x K le_rfl).trans (ennreal.mul_le_mul (ennreal.coe_le_coe.2 (le_max_left _ _)) le_rfl)
end
lemma eventually_measure_le_scaling_constant_mul' (K : β) (hK : 0 < K) :
βαΆ r in π[>] 0, β x,
ΞΌ (closed_ball x r) β€ scaling_constant_of ΞΌ Kβ»ΒΉ * ΞΌ (closed_ball x (K * r)) :=
begin
convert eventually_nhds_within_pos_mul_left hK (eventually_measure_le_scaling_constant_mul ΞΌ Kβ»ΒΉ),
ext,
simp [inv_mul_cancel_leftβ hK.ne'],
end
/-- A scale below which the doubling measure `ΞΌ` satisfies good rescaling properties when one
multiplies the radius of balls by at most `K`, as stated
in `measure_mul_le_scaling_constant_of_mul`. -/
def scaling_scale_of (K : β) : β :=
(eventually_measure_mul_le_scaling_constant_of_mul ΞΌ K).some
lemma scaling_scale_of_pos (K : β) : 0 < scaling_scale_of ΞΌ K :=
(eventually_measure_mul_le_scaling_constant_of_mul ΞΌ K).some_spec.1
lemma measure_mul_le_scaling_constant_of_mul {K : β} {x : Ξ±} {t r : β}
(ht : t β Ioc 0 K) (hr : r β€ scaling_scale_of ΞΌ K) :
ΞΌ (closed_ball x (t * r)) β€ scaling_constant_of ΞΌ K * ΞΌ (closed_ball x r) :=
(eventually_measure_mul_le_scaling_constant_of_mul ΞΌ K).some_spec.2 x t r ht hr
end is_doubling_measure
|
fd56a14cd14adb57c7964d6039a129ff192214c6 | fe25de614feb5587799621c41487aaee0d083b08 | /src/Std/Data/HashSet.lean | 6369abd1c19a2007754ee2a8b70ff1975e07f7f9 | [
"Apache-2.0"
] | permissive | pollend/lean4 | e8469c2f5fb8779b773618c3267883cf21fb9fac | c913886938c4b3b83238a3f99673c6c5a9cec270 | refs/heads/master | 1,687,973,251,481 | 1,628,039,739,000 | 1,628,039,739,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 6,195 | lean | /-
Copyright (c) 2019 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Leonardo de Moura
-/
namespace Std
universe u v w
def HashSetBucket (Ξ± : Type u) :=
{ b : Array (List Ξ±) // b.size > 0 }
def HashSetBucket.update {Ξ± : Type u} (data : HashSetBucket Ξ±) (i : USize) (d : List Ξ±) (h : i.toNat < data.val.size) : HashSetBucket Ξ± :=
β¨ data.val.uset i d h,
by erw [Array.size_set]; exact data.property β©
structure HashSetImp (Ξ± : Type u) where
size : Nat
buckets : HashSetBucket Ξ±
def mkHashSetImp {Ξ± : Type u} (nbuckets := 8) : HashSetImp Ξ± :=
let n := if nbuckets = 0 then 8 else nbuckets
{ size := 0,
buckets :=
β¨ mkArray n [],
by rw [Array.size_mkArray]; cases nbuckets; decide; apply Nat.zeroLtSucc β© }
namespace HashSetImp
variable {Ξ± : Type u}
def mkIdx {n : Nat} (h : n > 0) (u : USize) : { u : USize // u.toNat < n } :=
β¨u % n, USize.modn_lt _ hβ©
@[inline] def reinsertAux (hashFn : Ξ± β UInt64) (data : HashSetBucket Ξ±) (a : Ξ±) : HashSetBucket Ξ± :=
let β¨i, hβ© := mkIdx data.property (hashFn a |>.toUSize)
data.update i (a :: data.val.uget i h) h
@[inline] def foldBucketsM {Ξ΄ : Type w} {m : Type w β Type w} [Monad m] (data : HashSetBucket Ξ±) (d : Ξ΄) (f : Ξ΄ β Ξ± β m Ξ΄) : m Ξ΄ :=
data.val.foldlM (init := d) fun d as => as.foldlM f d
@[inline] def foldBuckets {Ξ΄ : Type w} (data : HashSetBucket Ξ±) (d : Ξ΄) (f : Ξ΄ β Ξ± β Ξ΄) : Ξ΄ :=
Id.run $ foldBucketsM data d f
@[inline] def foldM {Ξ΄ : Type w} {m : Type w β Type w} [Monad m] (f : Ξ΄ β Ξ± β m Ξ΄) (d : Ξ΄) (h : HashSetImp Ξ±) : m Ξ΄ :=
foldBucketsM h.buckets d f
@[inline] def fold {Ξ΄ : Type w} (f : Ξ΄ β Ξ± β Ξ΄) (d : Ξ΄) (m : HashSetImp Ξ±) : Ξ΄ :=
foldBuckets m.buckets d f
def find? [BEq Ξ±] [Hashable Ξ±] (m : HashSetImp Ξ±) (a : Ξ±) : Option Ξ± :=
match m with
| β¨_, bucketsβ© =>
let β¨i, hβ© := mkIdx buckets.property (hash a |>.toUSize)
(buckets.val.uget i h).find? (fun a' => a == a')
def contains [BEq Ξ±] [Hashable Ξ±] (m : HashSetImp Ξ±) (a : Ξ±) : Bool :=
match m with
| β¨_, bucketsβ© =>
let β¨i, hβ© := mkIdx buckets.property (hash a |>.toUSize)
(buckets.val.uget i h).contains a
-- TODO: remove `partial` by using well-founded recursion
partial def moveEntries [Hashable Ξ±] (i : Nat) (source : Array (List Ξ±)) (target : HashSetBucket Ξ±) : HashSetBucket Ξ± :=
if h : i < source.size then
let idx : Fin source.size := β¨i, hβ©
let es : List Ξ± := source.get idx
-- We remove `es` from `source` to make sure we can reuse its memory cells when performing es.foldl
let source := source.set idx []
let target := es.foldl (reinsertAux hash) target
moveEntries (i+1) source target
else target
def expand [Hashable Ξ±] (size : Nat) (buckets : HashSetBucket Ξ±) : HashSetImp Ξ± :=
let nbuckets := buckets.val.size * 2
have : nbuckets > 0 := Nat.mulPos buckets.property (by decide)
let new_buckets : HashSetBucket Ξ± := β¨mkArray nbuckets [], by rw [Array.size_mkArray]; assumptionβ©
{ size := size,
buckets := moveEntries 0 buckets.val new_buckets }
def insert [BEq Ξ±] [Hashable Ξ±] (m : HashSetImp Ξ±) (a : Ξ±) : HashSetImp Ξ± :=
match m with
| β¨size, bucketsβ© =>
let β¨i, hβ© := mkIdx buckets.property (hash a |>.toUSize)
let bkt := buckets.val.uget i h
if bkt.contains a
then β¨size, buckets.update i (bkt.replace a a) hβ©
else
let size' := size + 1
let buckets' := buckets.update i (a :: bkt) h
if size' β€ buckets.val.size
then { size := size', buckets := buckets' }
else expand size' buckets'
def erase [BEq Ξ±] [Hashable Ξ±] (m : HashSetImp Ξ±) (a : Ξ±) : HashSetImp Ξ± :=
match m with
| β¨ size, buckets β© =>
let β¨i, hβ© := mkIdx buckets.property (hash a |>.toUSize)
let bkt := buckets.val.uget i h
if bkt.contains a then β¨size - 1, buckets.update i (bkt.erase a) hβ©
else m
inductive WellFormed [BEq Ξ±] [Hashable Ξ±] : HashSetImp Ξ± β Prop where
| mkWff : β n, WellFormed (mkHashSetImp n)
| insertWff : β m a, WellFormed m β WellFormed (insert m a)
| eraseWff : β m a, WellFormed m β WellFormed (erase m a)
end HashSetImp
def HashSet (Ξ± : Type u) [BEq Ξ±] [Hashable Ξ±] :=
{ m : HashSetImp Ξ± // m.WellFormed }
open HashSetImp
def mkHashSet {Ξ± : Type u} [BEq Ξ±] [Hashable Ξ±] (nbuckets := 8) : HashSet Ξ± :=
β¨ mkHashSetImp nbuckets, WellFormed.mkWff nbuckets β©
namespace HashSet
@[inline] def empty [BEq Ξ±] [Hashable Ξ±] : HashSet Ξ± :=
mkHashSet
instance [BEq Ξ±] [Hashable Ξ±] : Inhabited (HashSet Ξ±) where
default := mkHashSet
instance [BEq Ξ±] [Hashable Ξ±] : EmptyCollection (HashSet Ξ±) := β¨mkHashSetβ©
variable {Ξ± : Type u} {_ : BEq Ξ±} {_ : Hashable Ξ±}
@[inline] def insert (m : HashSet Ξ±) (a : Ξ±) : HashSet Ξ± :=
match m with
| β¨ m, hw β© => β¨ m.insert a, WellFormed.insertWff m a hw β©
@[inline] def erase (m : HashSet Ξ±) (a : Ξ±) : HashSet Ξ± :=
match m with
| β¨ m, hw β© => β¨ m.erase a, WellFormed.eraseWff m a hw β©
@[inline] def find? (m : HashSet Ξ±) (a : Ξ±) : Option Ξ± :=
match m with
| β¨ m, _ β© => m.find? a
@[inline] def contains (m : HashSet Ξ±) (a : Ξ±) : Bool :=
match m with
| β¨ m, _ β© => m.contains a
@[inline] def foldM {Ξ΄ : Type w} {m : Type w β Type w} [Monad m] (f : Ξ΄ β Ξ± β m Ξ΄) (init : Ξ΄) (h : HashSet Ξ±) : m Ξ΄ :=
match h with
| β¨ h, _ β© => h.foldM f init
@[inline] def fold {Ξ΄ : Type w} (f : Ξ΄ β Ξ± β Ξ΄) (init : Ξ΄) (m : HashSet Ξ±) : Ξ΄ :=
match m with
| β¨ m, _ β© => m.fold f init
@[inline] def size (m : HashSet Ξ±) : Nat :=
match m with
| β¨ {size := sz, ..}, _ β© => sz
@[inline] def isEmpty (m : HashSet Ξ±) : Bool :=
m.size = 0
def toList (m : HashSet Ξ±) : List Ξ± :=
m.fold (init := []) fun r a => a::r
def toArray (m : HashSet Ξ±) : Array Ξ± :=
m.fold (init := #[]) fun r a => r.push a
def numBuckets (m : HashSet Ξ±) : Nat :=
m.val.buckets.val.size
end HashSet
end Std
|
0e13b6edfa09138455a769f3e25a33699613e61a | af702bb100e4fe8a128e0e9a7e9475e590a0e051 | /8-kyu/multiply/solution-lean.lean | fe93fdd2ff5de6c10b3e81f8d2a51bfd89eab25c | [] | no_license | thaliaarchi/codewars | e6762c141a0f3375323cb377fc30357a46069ca9 | 66a3687f90de974acc5d770d7330e11f239a0e91 | refs/heads/master | 1,674,385,357,441 | 1,604,907,437,000 | 1,604,907,437,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 39 | lean | def multiply (a b : β) : β := a * b |
fde8e275f58164f40e9ff7aa8fc7be0460522020 | 9028d228ac200bbefe3a711342514dd4e4458bff | /src/category_theory/monoidal/category.lean | f1b33dab678c2f27d2926dbb8373cc0f9dea9b71 | [
"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 | 21,010 | lean | /-
Copyright (c) 2018 Michael Jendrusch. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Michael Jendrusch, Scott Morrison
-/
import category_theory.products.basic
/-!
# Monoidal categories
A monoidal category is a category equipped with a tensor product, unitors, and an associator.
In the definition, we provide the tensor product as a pair of functions
* `tensor_obj : C β C β C`
* `tensor_hom : (Xβ βΆ Yβ) β (Xβ βΆ Yβ) β ((Xβ β Xβ) βΆ (Yβ β Yβ))`
and allow use of the overloaded notation `β` for both.
The unitors and associator are provided componentwise.
The tensor product can be expressed as a functor via `tensor : C Γ C β₯€ C`.
The unitors and associator are gathered together as natural
isomorphisms in `left_unitor_nat_iso`, `right_unitor_nat_iso` and `associator_nat_iso`.
Some consequences of the definition are proved in other files,
e.g. `(Ξ»_ (π_ C)).hom = (Ο_ (π_ C)).hom` in `category_theory.monoidal.unitors_equal`.
## Implementation
Dealing with unitors and associators is painful, and at this stage we do not have a useful
implementation of coherence for monoidal categories.
In an effort to lessen the pain, we put some effort into choosing the right `simp` lemmas.
Generally, the rule is that the component index of a natural transformation "weighs more"
in considering the complexity of an expression than does a structural isomorphism (associator, etc).
As an example when we prove Proposition 2.2.4 of
<http://www-math.mit.edu/~etingof/egnobookfinal.pdf>
we state it as a `@[simp]` lemma as
```
(Ξ»_ (X β Y)).hom = (Ξ±_ (π_ C) X Y).inv β« (Ξ»_ X).hom β (π Y)
```
This is far from completely effective, but seems to prove a useful principle.
## References
* Tensor categories, Etingof, Gelaki, Nikshych, Ostrik,
http://www-math.mit.edu/~etingof/egnobookfinal.pdf
* https://stacks.math.columbia.edu/tag/0FFK.
-/
open category_theory
universes v u
open category_theory
open category_theory.category
open category_theory.iso
namespace category_theory
/--
In a monoidal category, we can take the tensor product of objects, `X β Y` and of morphisms `f β g`.
Tensor product does not need to be strictly associative on objects, but there is a
specified associator, `Ξ±_ X Y Z : (X β Y) β Z β
X β (Y β Z)`. There is a tensor unit `π_ C`,
with specified left and right unitor isomorphisms `Ξ»_ X : π_ C β X β
X` and `Ο_ X : X β π_ C β
X`.
These associators and unitors satisfy the pentagon and triangle equations.
See https://stacks.math.columbia.edu/tag/0FFK.
-/
class monoidal_category (C : Type u) [π : category.{v} C] :=
-- curried tensor product of objects:
(tensor_obj : C β C β C)
(infixr ` β `:70 := tensor_obj) -- This notation is only temporary
-- curried tensor product of morphisms:
(tensor_hom :
Ξ {Xβ Yβ Xβ Yβ : C}, (Xβ βΆ Yβ) β (Xβ βΆ Yβ) β ((Xβ β Xβ) βΆ (Yβ β Yβ)))
(infixr ` β' `:69 := tensor_hom) -- This notation is only temporary
-- tensor product laws:
(tensor_id' :
β (Xβ Xβ : C), (π Xβ) β' (π Xβ) = π (Xβ β Xβ) . obviously)
(tensor_comp' :
β {Xβ Yβ Zβ Xβ Yβ Zβ : C} (fβ : Xβ βΆ Yβ) (fβ : Xβ βΆ Yβ) (gβ : Yβ βΆ Zβ) (gβ : Yβ βΆ Zβ),
(fβ β« gβ) β' (fβ β« gβ) = (fβ β' fβ) β« (gβ β' gβ) . obviously)
-- tensor unit:
(tensor_unit [] : C)
(notation `π_` := tensor_unit)
-- associator:
(associator :
Ξ X Y Z : C, (X β Y) β Z β
X β (Y β Z))
(notation `Ξ±_` := associator)
(associator_naturality' :
β {Xβ Xβ Xβ Yβ Yβ Yβ : C} (fβ : Xβ βΆ Yβ) (fβ : Xβ βΆ Yβ) (fβ : Xβ βΆ Yβ),
((fβ β' fβ) β' fβ) β« (Ξ±_ Yβ Yβ Yβ).hom = (Ξ±_ Xβ Xβ Xβ).hom β« (fβ β' (fβ β' fβ)) . obviously)
-- left unitor:
(left_unitor : Ξ X : C, π_ β X β
X)
(notation `Ξ»_` := left_unitor)
(left_unitor_naturality' :
β {X Y : C} (f : X βΆ Y), ((π π_) β' f) β« (Ξ»_ Y).hom = (Ξ»_ X).hom β« f . obviously)
-- right unitor:
(right_unitor : Ξ X : C, X β π_ β
X)
(notation `Ο_` := right_unitor)
(right_unitor_naturality' :
β {X Y : C} (f : X βΆ Y), (f β' (π π_)) β« (Ο_ Y).hom = (Ο_ X).hom β« f . obviously)
-- pentagon identity:
(pentagon' : β W X Y Z : C,
((Ξ±_ W X Y).hom β' (π Z)) β« (Ξ±_ W (X β Y) Z).hom β« ((π W) β' (Ξ±_ X Y Z).hom)
= (Ξ±_ (W β X) Y Z).hom β« (Ξ±_ W X (Y β Z)).hom . obviously)
-- triangle identity:
(triangle' :
β X Y : C, (Ξ±_ X π_ Y).hom β« ((π X) β' (Ξ»_ Y).hom) = (Ο_ X).hom β' (π Y) . obviously)
restate_axiom monoidal_category.tensor_id'
attribute [simp] monoidal_category.tensor_id
restate_axiom monoidal_category.tensor_comp'
attribute [reassoc] monoidal_category.tensor_comp -- This would be redundant in the simp set.
attribute [simp] monoidal_category.tensor_comp
restate_axiom monoidal_category.associator_naturality'
attribute [reassoc] monoidal_category.associator_naturality
restate_axiom monoidal_category.left_unitor_naturality'
attribute [reassoc] monoidal_category.left_unitor_naturality
restate_axiom monoidal_category.right_unitor_naturality'
attribute [reassoc] monoidal_category.right_unitor_naturality
restate_axiom monoidal_category.pentagon'
restate_axiom monoidal_category.triangle'
attribute [simp, reassoc] monoidal_category.triangle
open monoidal_category
infixr ` β `:70 := tensor_obj
infixr ` β `:70 := tensor_hom
notation `π_` := tensor_unit
notation `Ξ±_` := associator
notation `Ξ»_` := left_unitor
notation `Ο_` := right_unitor
/-- The tensor product of two isomorphisms is an isomorphism. -/
@[simps]
def tensor_iso {C : Type u} {X Y X' Y' : C} [category.{v} C] [monoidal_category.{v} C] (f : X β
Y) (g : X' β
Y') :
X β X' β
Y β Y' :=
{ hom := f.hom β g.hom,
inv := f.inv β g.inv,
hom_inv_id' := by rw [βtensor_comp, iso.hom_inv_id, iso.hom_inv_id, βtensor_id],
inv_hom_id' := by rw [βtensor_comp, iso.inv_hom_id, iso.inv_hom_id, βtensor_id] }
infixr ` β `:70 := tensor_iso
namespace monoidal_category
section
variables {C : Type u} [category.{v} C] [monoidal_category.{v} C]
instance tensor_is_iso {W X Y Z : C} (f : W βΆ X) [is_iso f] (g : Y βΆ Z) [is_iso g] : is_iso (f β g) :=
{ ..(as_iso f β as_iso g) }
@[simp] lemma inv_tensor {W X Y Z : C} (f : W βΆ X) [is_iso f] (g : Y βΆ Z) [is_iso g] :
inv (f β g) = inv f β inv g := rfl
variables {U V W X Y Z : C}
-- When `rewrite_search` lands, add @[search] attributes to
-- monoidal_category.tensor_id monoidal_category.tensor_comp monoidal_category.associator_naturality
-- monoidal_category.left_unitor_naturality monoidal_category.right_unitor_naturality
-- monoidal_category.pentagon monoidal_category.triangle
-- tensor_comp_id tensor_id_comp comp_id_tensor_tensor_id
-- triangle_assoc_comp_left triangle_assoc_comp_right triangle_assoc_comp_left_inv triangle_assoc_comp_right_inv
-- left_unitor_tensor left_unitor_tensor_inv
-- right_unitor_tensor right_unitor_tensor_inv
-- pentagon_inv
-- associator_inv_naturality
-- left_unitor_inv_naturality
-- right_unitor_inv_naturality
@[simp] lemma comp_tensor_id (f : W βΆ X) (g : X βΆ Y) :
(f β« g) β (π Z) = (f β (π Z)) β« (g β (π Z)) :=
by { rw βtensor_comp, simp }
@[simp] lemma id_tensor_comp (f : W βΆ X) (g : X βΆ Y) :
(π Z) β (f β« g) = (π Z β f) β« (π Z β g) :=
by { rw βtensor_comp, simp }
@[simp, reassoc] lemma id_tensor_comp_tensor_id (f : W βΆ X) (g : Y βΆ Z) :
((π Y) β f) β« (g β (π X)) = g β f :=
by { rw [βtensor_comp], simp }
@[simp, reassoc] lemma tensor_id_comp_id_tensor (f : W βΆ X) (g : Y βΆ Z) :
(g β (π W)) β« ((π Z) β f) = g β f :=
by { rw [βtensor_comp], simp }
lemma left_unitor_inv_naturality {X X' : C} (f : X βΆ X') :
f β« (Ξ»_ X').inv = (Ξ»_ X).inv β« (π _ β f) :=
begin
apply (cancel_mono (Ξ»_ X').hom).1,
simp only [assoc, comp_id, iso.inv_hom_id],
rw [left_unitor_naturality, βcategory.assoc, iso.inv_hom_id, category.id_comp]
end
lemma right_unitor_inv_naturality {X X' : C} (f : X βΆ X') :
f β« (Ο_ X').inv = (Ο_ X).inv β« (f β π _) :=
begin
apply (cancel_mono (Ο_ X').hom).1,
simp only [assoc, comp_id, iso.inv_hom_id],
rw [right_unitor_naturality, βcategory.assoc, iso.inv_hom_id, category.id_comp]
end
@[simp]
lemma right_unitor_conjugation {X Y : C} (f : X βΆ Y) : (Ο_ X).inv β« (f β (π (π_ C))) β« (Ο_ Y).hom = f :=
by rw [right_unitor_naturality, βcategory.assoc, iso.inv_hom_id, category.id_comp]
@[simp]
lemma left_unitor_conjugation {X Y : C} (f : X βΆ Y) : (Ξ»_ X).inv β« ((π (π_ C)) β f) β« (Ξ»_ Y).hom = f :=
by rw [left_unitor_naturality, βcategory.assoc, iso.inv_hom_id, category.id_comp]
@[simp] lemma tensor_left_iff
{X Y : C} (f g : X βΆ Y) :
((π (π_ C)) β f = (π (π_ C)) β g) β (f = g) :=
begin
split,
{ intro h,
have h' := congr_arg (Ξ» k, (Ξ»_ _).inv β« k) h,
dsimp at h',
rw [βleft_unitor_inv_naturality, βleft_unitor_inv_naturality] at h',
exact (cancel_mono _).1 h', },
{ intro h, subst h, }
end
@[simp] lemma tensor_right_iff
{X Y : C} (f g : X βΆ Y) :
(f β (π (π_ C)) = g β (π (π_ C))) β (f = g) :=
begin
split,
{ intro h,
have h' := congr_arg (Ξ» k, (Ο_ _).inv β« k) h,
dsimp at h',
rw [βright_unitor_inv_naturality, βright_unitor_inv_naturality] at h',
exact (cancel_mono _).1 h' },
{ intro h, subst h, }
end
-- We now prove:
-- ((Ξ±_ (π_ C) X Y).hom) β«
-- ((Ξ»_ (X β Y)).hom)
-- = ((Ξ»_ X).hom β (π Y))
-- (and the corresponding fact for right unitors)
-- following the proof on nLab:
-- Lemma 2.2 at <https://ncatlab.org/nlab/revision/monoidal+category/115>
lemma left_unitor_product_aux_perimeter (X Y : C) :
((Ξ±_ (π_ C) (π_ C) X).hom β (π Y)) β«
(Ξ±_ (π_ C) ((π_ C) β X) Y).hom β«
((π (π_ C)) β (Ξ±_ (π_ C) X Y).hom) β«
((π (π_ C)) β (Ξ»_ (X β Y)).hom)
= (((Ο_ (π_ C)).hom β (π X)) β (π Y)) β«
(Ξ±_ (π_ C) X Y).hom :=
begin
conv_lhs { congr, skip, rw [βcategory.assoc] },
rw [βcategory.assoc, monoidal_category.pentagon, associator_naturality, tensor_id,
βmonoidal_category.triangle, βcategory.assoc]
end
lemma left_unitor_product_aux_triangle (X Y : C) :
((Ξ±_ (π_ C) (π_ C) X).hom β (π Y)) β«
(((π (π_ C)) β (Ξ»_ X).hom) β (π Y))
= ((Ο_ (π_ C)).hom β (π X)) β (π Y) :=
by rw [βcomp_tensor_id, βmonoidal_category.triangle]
lemma left_unitor_product_aux_square (X Y : C) :
(Ξ±_ (π_ C) ((π_ C) β X) Y).hom β«
((π (π_ C)) β (Ξ»_ X).hom β (π Y))
= (((π (π_ C)) β (Ξ»_ X).hom) β (π Y)) β«
(Ξ±_ (π_ C) X Y).hom :=
by rw associator_naturality
lemma left_unitor_product_aux (X Y : C) :
((π (π_ C)) β (Ξ±_ (π_ C) X Y).hom) β«
((π (π_ C)) β (Ξ»_ (X β Y)).hom)
= (π (π_ C)) β ((Ξ»_ X).hom β (π Y)) :=
begin
rw β(cancel_epi (Ξ±_ (π_ C) ((π_ C) β X) Y).hom),
rw left_unitor_product_aux_square,
rw β(cancel_epi ((Ξ±_ (π_ C) (π_ C) X).hom β (π Y))),
slice_rhs 1 2 { rw left_unitor_product_aux_triangle },
conv_lhs { rw [left_unitor_product_aux_perimeter] }
end
lemma right_unitor_product_aux_perimeter (X Y : C) :
((Ξ±_ X Y (π_ C)).hom β (π (π_ C))) β«
(Ξ±_ X (Y β (π_ C)) (π_ C)).hom β«
((π X) β (Ξ±_ Y (π_ C) (π_ C)).hom) β«
((π X) β (π Y) β (Ξ»_ (π_ C)).hom)
= ((Ο_ (X β Y)).hom β (π (π_ C))) β«
(Ξ±_ X Y (π_ C)).hom :=
begin
transitivity (((Ξ±_ X Y _).hom β π _) β« (Ξ±_ X _ _).hom β«
(π X β (Ξ±_ Y _ _).hom)) β«
(π X β π Y β (Ξ»_ _).hom),
{ conv_lhs { congr, skip, rw [βcategory.assoc] },
conv_rhs { rw [category.assoc] } },
{ conv_lhs { congr, rw [monoidal_category.pentagon] },
conv_rhs { congr, rw [βmonoidal_category.triangle] },
conv_rhs { rw [category.assoc] },
conv_rhs { congr, skip, congr, congr, rw [βtensor_id] },
conv_rhs { congr, skip, rw [associator_naturality] },
conv_rhs { rw [βcategory.assoc] } }
end
lemma right_unitor_product_aux_triangle (X Y : C) :
((π X) β (Ξ±_ Y (π_ C) (π_ C)).hom) β«
((π X) β (π Y) β (Ξ»_ (π_ C)).hom)
= (π X) β (Ο_ Y).hom β (π (π_ C)) :=
by rw [βid_tensor_comp, βmonoidal_category.triangle]
lemma right_unitor_product_aux_square (X Y : C) :
(Ξ±_ X (Y β (π_ C)) (π_ C)).hom β«
((π X) β (Ο_ Y).hom β (π (π_ C)))
= (((π X) β (Ο_ Y).hom) β (π (π_ C))) β«
(Ξ±_ X Y (π_ C)).hom :=
by rw [associator_naturality]
lemma right_unitor_product_aux (X Y : C) :
((Ξ±_ X Y (π_ C)).hom β (π (π_ C))) β«
(((π X) β (Ο_ Y).hom) β (π (π_ C)))
= ((Ο_ (X β Y)).hom β (π (π_ C))) :=
begin
rw β(cancel_mono (Ξ±_ X Y (π_ C)).hom),
slice_lhs 2 3 { rw βright_unitor_product_aux_square },
rw [βright_unitor_product_aux_triangle, βright_unitor_product_aux_perimeter],
end
-- See Proposition 2.2.4 of <http://www-math.mit.edu/~etingof/egnobookfinal.pdf>
lemma left_unitor_tensor' (X Y : C) :
((Ξ±_ (π_ C) X Y).hom) β« ((Ξ»_ (X β Y)).hom) = ((Ξ»_ X).hom β (π Y)) :=
by rw [βtensor_left_iff, id_tensor_comp, left_unitor_product_aux]
@[simp]
lemma left_unitor_tensor (X Y : C) :
((Ξ»_ (X β Y)).hom) = ((Ξ±_ (π_ C) X Y).inv) β« ((Ξ»_ X).hom β (π Y)) :=
by { rw [βleft_unitor_tensor'], simp }
lemma left_unitor_tensor_inv' (X Y : C) :
((Ξ»_ (X β Y)).inv) β« ((Ξ±_ (π_ C) X Y).inv) = ((Ξ»_ X).inv β (π Y)) :=
eq_of_inv_eq_inv (by simp)
@[simp]
lemma left_unitor_tensor_inv (X Y : C) :
((Ξ»_ (X β Y)).inv) = ((Ξ»_ X).inv β (π Y)) β« ((Ξ±_ (π_ C) X Y).hom) :=
by { rw [βleft_unitor_tensor_inv'], simp }
@[simp]
lemma right_unitor_tensor (X Y : C) :
((Ο_ (X β Y)).hom) = ((Ξ±_ X Y (π_ C)).hom) β« ((π X) β (Ο_ Y).hom) :=
by rw [βtensor_right_iff, comp_tensor_id, right_unitor_product_aux]
@[simp]
lemma right_unitor_tensor_inv (X Y : C) :
((Ο_ (X β Y)).inv) = ((π X) β (Ο_ Y).inv) β« ((Ξ±_ X Y (π_ C)).inv) :=
eq_of_inv_eq_inv (by simp)
lemma associator_inv_naturality {X Y Z X' Y' Z' : C} (f : X βΆ X') (g : Y βΆ Y') (h : Z βΆ Z') :
(f β (g β h)) β« (Ξ±_ X' Y' Z').inv = (Ξ±_ X Y Z).inv β« ((f β g) β h) :=
begin
apply (cancel_mono (Ξ±_ X' Y' Z').hom).1,
simp only [assoc, comp_id, iso.inv_hom_id],
rw [associator_naturality, βcategory.assoc, iso.inv_hom_id, category.id_comp]
end
lemma pentagon_inv (W X Y Z : C) :
((π W) β (Ξ±_ X Y Z).inv) β« (Ξ±_ W (X β Y) Z).inv β« ((Ξ±_ W X Y).inv β (π Z))
= (Ξ±_ W X (Y β Z)).inv β« (Ξ±_ (W β X) Y Z).inv :=
begin
apply category_theory.eq_of_inv_eq_inv,
dsimp,
rw [category.assoc, monoidal_category.pentagon]
end
lemma triangle_assoc_comp_left (X Y : C) :
(Ξ±_ X (π_ C) Y).hom β« ((π X) β (Ξ»_ Y).hom) = (Ο_ X).hom β π Y :=
monoidal_category.triangle X Y
@[simp] lemma triangle_assoc_comp_right (X Y : C) :
(Ξ±_ X (π_ C) Y).inv β« ((Ο_ X).hom β π Y) = ((π X) β (Ξ»_ Y).hom) :=
by rw [βtriangle_assoc_comp_left, βcategory.assoc, iso.inv_hom_id, category.id_comp]
@[simp] lemma triangle_assoc_comp_right_inv (X Y : C) :
((Ο_ X).inv β π Y) β« (Ξ±_ X (π_ C) Y).hom = ((π X) β (Ξ»_ Y).inv) :=
begin
apply (cancel_mono (π X β (Ξ»_ Y).hom)).1,
simp only [assoc, triangle_assoc_comp_left],
rw [βcomp_tensor_id, iso.inv_hom_id, βid_tensor_comp, iso.inv_hom_id]
end
@[simp] lemma triangle_assoc_comp_left_inv (X Y : C) :
((π X) β (Ξ»_ Y).inv) β« (Ξ±_ X (π_ C) Y).inv = ((Ο_ X).inv β π Y) :=
begin
apply (cancel_mono ((Ο_ X).hom β π Y)).1,
simp only [triangle_assoc_comp_right, assoc],
rw [βid_tensor_comp, iso.inv_hom_id, βcomp_tensor_id, iso.inv_hom_id]
end
end
section
variables (C : Type u) [category.{v} C] [monoidal_category.{v} C]
/-- The tensor product expressed as a functor. -/
def tensor : (C Γ C) β₯€ C :=
{ obj := Ξ» X, X.1 β X.2,
map := Ξ» {X Y : C Γ C} (f : X βΆ Y), f.1 β f.2 }
/-- The left-associated triple tensor product as a functor. -/
def left_assoc_tensor : (C Γ C Γ C) β₯€ C :=
{ obj := Ξ» X, (X.1 β X.2.1) β X.2.2,
map := Ξ» {X Y : C Γ C Γ C} (f : X βΆ Y), (f.1 β f.2.1) β f.2.2 }
@[simp] lemma left_assoc_tensor_obj (X) :
(left_assoc_tensor C).obj X = (X.1 β X.2.1) β X.2.2 := rfl
@[simp] lemma left_assoc_tensor_map {X Y} (f : X βΆ Y) :
(left_assoc_tensor C).map f = (f.1 β f.2.1) β f.2.2 := rfl
/-- The right-associated triple tensor product as a functor. -/
def right_assoc_tensor : (C Γ C Γ C) β₯€ C :=
{ obj := Ξ» X, X.1 β (X.2.1 β X.2.2),
map := Ξ» {X Y : C Γ C Γ C} (f : X βΆ Y), f.1 β (f.2.1 β f.2.2) }
@[simp] lemma right_assoc_tensor_obj (X) :
(right_assoc_tensor C).obj X = X.1 β (X.2.1 β X.2.2) := rfl
@[simp] lemma right_assoc_tensor_map {X Y} (f : X βΆ Y) :
(right_assoc_tensor C).map f = f.1 β (f.2.1 β f.2.2) := rfl
/-- The functor `Ξ» X, π_ C β X`. -/
def tensor_unit_left : C β₯€ C :=
{ obj := Ξ» X, π_ C β X,
map := Ξ» {X Y : C} (f : X βΆ Y), (π (π_ C)) β f }
/-- The functor `Ξ» X, X β π_ C`. -/
def tensor_unit_right : C β₯€ C :=
{ obj := Ξ» X, X β π_ C,
map := Ξ» {X Y : C} (f : X βΆ Y), f β (π (π_ C)) }
-- We can express the associator and the unitors, given componentwise above,
-- as natural isomorphisms.
/-- The associator as a natural isomorphism. -/
@[simps {rhs_md := semireducible}]
def associator_nat_iso :
left_assoc_tensor C β
right_assoc_tensor C :=
nat_iso.of_components
(by { intros, apply monoidal_category.associator })
(by { intros, apply monoidal_category.associator_naturality })
/-- The left unitor as a natural isomorphism. -/
@[simps {rhs_md := semireducible}]
def left_unitor_nat_iso :
tensor_unit_left C β
π C :=
nat_iso.of_components
(by { intros, apply monoidal_category.left_unitor })
(by { intros, apply monoidal_category.left_unitor_naturality })
/-- The right unitor as a natural isomorphism. -/
@[simps {rhs_md := semireducible}]
def right_unitor_nat_iso :
tensor_unit_right C β
π C :=
nat_iso.of_components
(by { intros, apply monoidal_category.right_unitor })
(by { intros, apply monoidal_category.right_unitor_naturality })
section
variables {C}
/-- Tensoring on the left with as fixed object, as a functor. -/
@[simps]
def tensor_left (X : C) : C β₯€ C :=
{ obj := Ξ» Y, X β Y,
map := Ξ» Y Y' f, (π X) β f, }
/--
Tensoring on the left with `X β Y` is naturally isomorphic to
tensoring on the left with `Y`, and then again with `X`.
-/
def tensor_left_tensor (X Y : C) : tensor_left (X β Y) β
tensor_left Y β tensor_left X :=
nat_iso.of_components
(associator _ _)
(Ξ» Z Z' f, by { dsimp, rw[βtensor_id], apply associator_naturality })
@[simp] lemma tensor_left_tensor_hom_app (X Y Z : C) :
(tensor_left_tensor X Y).hom.app Z = (associator X Y Z).hom :=
rfl
@[simp] lemma tensor_left_tensor_inv_app (X Y Z : C) :
(tensor_left_tensor X Y).inv.app Z = (associator X Y Z).inv :=
rfl
/-- Tensoring on the right with as fixed object, as a functor. -/
@[simps]
def tensor_right (X : C) : C β₯€ C :=
{ obj := Ξ» Y, Y β X,
map := Ξ» Y Y' f, f β (π X), }
variables (C)
/--
Tensoring on the right, as a functor from `C` into endofunctors of `C`.
We later show this is a monoidal functor.
-/
@[simps]
def tensoring_right : C β₯€ (C β₯€ C) :=
{ obj := tensor_right,
map := Ξ» X Y f,
{ app := Ξ» Z, (π Z) β f } }
instance : faithful (tensoring_right C) :=
{ map_injective' := Ξ» X Y f g h,
begin
injections with h,
replace h := congr_fun h (π_ C),
simpa using h,
end }
variables {C}
/--
Tensoring on the right with `X β Y` is naturally isomorphic to
tensoring on the right with `X`, and then again with `Y`.
-/
def tensor_right_tensor (X Y : C) : tensor_right (X β Y) β
tensor_right X β tensor_right Y :=
nat_iso.of_components
(Ξ» Z, (associator Z X Y).symm)
(Ξ» Z Z' f, by { dsimp, rw[βtensor_id], apply associator_inv_naturality })
@[simp] lemma tensor_right_tensor_hom_app (X Y Z : C) :
(tensor_right_tensor X Y).hom.app Z = (associator Z X Y).inv :=
rfl
@[simp] lemma tensor_right_tensor_inv_app (X Y Z : C) :
(tensor_right_tensor X Y).inv.app Z = (associator Z X Y).hom :=
rfl
end
end
end monoidal_category
end category_theory
|
766f445c1fd067f52b920af666b93710e300e67b | a9d0fb7b0e4f802bd3857b803e6c5c23d87fef91 | /tests/lean/print_reducible.lean | 06f1defc3c2d4512733b2bab27c57e86ccf7fd8e | [
"Apache-2.0"
] | permissive | soonhokong/lean-osx | 4a954262c780e404c1369d6c06516161d07fcb40 | 3670278342d2f4faa49d95b46d86642d7875b47c | refs/heads/master | 1,611,410,334,552 | 1,474,425,686,000 | 1,474,425,686,000 | 12,043,103 | 5 | 1 | null | null | null | null | UTF-8 | Lean | false | false | 445 | lean | prelude
attribute [reducible]
definition idβ {A : Type} (a : A) := a
attribute [reducible]
definition idβ {A : Type} (a : A) := a
attribute [irreducible]
definition idβ
{A : Type} (a : A) := a
attribute [irreducible]
definition idβ {A : Type} (a : A) := a
attribute [reducible]
definition pr {A B : Type} (a : A) (b : B) := a
definition pr2 {A B : Type} (a : A) (b : B) := a
print [reducible]
print "-----------"
print [irreducible]
|
e573569e5fa90549d8b55f026c74586a3db7689b | e953c38599905267210b87fb5d82dcc3e52a4214 | /library/init/nat.lean | 18e4f1dbc000f746d2b947828643bcaebdec1412 | [
"Apache-2.0"
] | permissive | c-cube/lean | 563c1020bff98441c4f8ba60111fef6f6b46e31b | 0fb52a9a139f720be418dafac35104468e293b66 | refs/heads/master | 1,610,753,294,113 | 1,440,451,356,000 | 1,440,499,588,000 | 41,748,334 | 0 | 0 | null | 1,441,122,656,000 | 1,441,122,656,000 | null | UTF-8 | Lean | false | false | 8,773 | lean | /-
Copyright (c) 2014 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn, Leonardo de Moura
-/
prelude
import init.wf init.tactic init.num
open eq.ops decidable or
namespace nat
notation `β` := nat
/- basic definitions on natural numbers -/
inductive le (a : β) : β β Prop :=
| refl : le a a
| step : Ξ {b}, le a b β le a (succ b)
infix `β€` := le
attribute le.refl [refl]
definition lt [reducible] (n m : β) := succ n β€ m
definition ge [reducible] (n m : β) := m β€ n
definition gt [reducible] (n m : β) := succ m β€ n
infix `<` := lt
infix `β₯` := ge
infix `>` := gt
definition pred [unfold 1] (a : nat) : nat :=
nat.cases_on a zero (Ξ» aβ, aβ)
-- add is defined in init.num
definition sub (a b : nat) : nat :=
nat.rec_on b a (Ξ» bβ, pred)
definition mul (a b : nat) : nat :=
nat.rec_on b zero (Ξ» bβ r, r + a)
notation a - b := sub a b
notation a * b := mul a b
/- properties of β -/
protected definition is_inhabited [instance] : inhabited nat :=
inhabited.mk zero
protected definition has_decidable_eq [instance] : β x y : nat, decidable (x = y)
| has_decidable_eq zero zero := inl rfl
| has_decidable_eq (succ x) zero := inr (by contradiction)
| has_decidable_eq zero (succ y) := inr (by contradiction)
| has_decidable_eq (succ x) (succ y) :=
match has_decidable_eq x y with
| inl xeqy := inl (by rewrite xeqy)
| inr xney := inr (Ξ» h : succ x = succ y, by injection h with xeqy; exact absurd xeqy xney)
end
/- properties of inequality -/
theorem le_of_eq {n m : β} (p : n = m) : n β€ m := p βΈ !le.refl
theorem le_succ (n : β) : n β€ succ n := le.step !le.refl
theorem pred_le (n : β) : pred n β€ n := by cases n;repeat constructor
theorem le_succ_iff_true [simp] (n : β) : n β€ succ n β true :=
iff_true_intro (le_succ n)
theorem pred_le_iff_true [simp] (n : β) : pred n β€ n β true :=
iff_true_intro (pred_le n)
theorem le.trans [trans] {n m k : β} (H1 : n β€ m) : m β€ k β n β€ k :=
le.rec H1 (Ξ»p H2, le.step)
theorem le_succ_of_le {n m : β} (H : n β€ m) : n β€ succ m := le.trans H !le_succ
theorem le_of_succ_le {n m : β} (H : succ n β€ m) : n β€ m := le.trans !le_succ H
theorem le_of_lt {n m : β} (H : n < m) : n β€ m := le_of_succ_le H
theorem succ_le_succ {n m : β} : n β€ m β succ n β€ succ m :=
le.rec !le.refl (Ξ»a b, le.step)
theorem pred_le_pred {n m : β} : n β€ m β pred n β€ pred m :=
le.rec !le.refl (nat.rec (Ξ»a b, b) (Ξ»a b c, le.step))
theorem le_of_succ_le_succ {n m : β} : succ n β€ succ m β n β€ m :=
pred_le_pred
theorem le_succ_of_pred_le {n m : β} : pred n β€ m β n β€ succ m :=
nat.cases_on n le.step (Ξ»a, succ_le_succ)
theorem not_succ_le_zero (n : β) : Β¬succ n β€ zero :=
by intro H; cases H
theorem succ_le_zero_iff_false (n : β) : succ n β€ zero β false :=
iff_false_intro !not_succ_le_zero
theorem not_succ_le_self : Ξ {n : β}, Β¬succ n β€ n :=
nat.rec !not_succ_le_zero (Ξ»a b c, b (le_of_succ_le_succ c))
theorem succ_le_self_iff_false [simp] (n : β) : succ n β€ n β false :=
iff_false_intro not_succ_le_self
theorem zero_le : β (n : β), 0 β€ n :=
nat.rec !le.refl (Ξ»a, le.step)
theorem zero_le_iff_true [simp] (n : β) : 0 β€ n β true :=
iff_true_intro !zero_le
theorem lt.step {n m : β} : n < m β n < succ m := le.step
theorem zero_lt_succ (n : β) : 0 < succ n :=
succ_le_succ !zero_le
theorem zero_lt_succ_iff_true [simp] (n : β) : 0 < succ n β true :=
iff_true_intro (zero_lt_succ n)
theorem lt.trans [trans] {n m k : β} (H1 : n < m) : m < k β n < k :=
le.trans (le.step H1)
theorem lt_of_le_of_lt [trans] {n m k : β} (H1 : n β€ m) : m < k β n < k :=
le.trans (succ_le_succ H1)
theorem lt_of_lt_of_le [trans] {n m k : β} : n < m β m β€ k β n < k := le.trans
theorem lt.irrefl (n : β) : Β¬n < n := not_succ_le_self
theorem lt_self_iff_false [simp] (n : β) : n < n β false :=
iff_false_intro (lt.irrefl n)
theorem self_lt_succ (n : β) : n < succ n := !le.refl
theorem self_lt_succ_iff_true [simp] (n : β) : n < succ n β true :=
iff_true_intro (self_lt_succ n)
theorem lt.base (n : β) : n < succ n := !le.refl
theorem le_lt_antisymm {n m : β} (H1 : n β€ m) (H2 : m < n) : false :=
!lt.irrefl (lt_of_le_of_lt H1 H2)
theorem le.antisymm {n m : β} (H1 : n β€ m) : m β€ n β n = m :=
le.cases_on H1 (Ξ»a, rfl) (Ξ»a b c, absurd (lt_of_le_of_lt b c) !lt.irrefl)
theorem lt_le_antisymm {n m : β} (H1 : n < m) (H2 : m β€ n) : false :=
le_lt_antisymm H2 H1
theorem lt.asymm {n m : β} (H1 : n < m) : Β¬ m < n :=
le_lt_antisymm (le_of_lt H1)
theorem not_lt_zero (a : β) : Β¬ a < zero := !not_succ_le_zero
theorem lt_zero_iff_false [simp] (a : β) : a < zero β false :=
iff_false_intro (not_lt_zero a)
theorem eq_or_lt_of_le {a b : β} (H : a β€ b) : a = b β¨ a < b :=
le.cases_on H (inl rfl) (Ξ»n h, inr (succ_le_succ h))
theorem le_of_eq_or_lt {a b : β} (H : a = b β¨ a < b) : a β€ b :=
or.elim H !le_of_eq !le_of_lt
-- less-than is well-founded
definition lt.wf [instance] : well_founded lt :=
well_founded.intro (nat.rec
(!acc.intro (Ξ»n H, absurd H (not_lt_zero n)))
(Ξ»n IH, !acc.intro (Ξ»m H,
elim (eq_or_lt_of_le (le_of_succ_le_succ H))
(Ξ»e, eq.substr e IH) (acc.inv IH))))
definition measure {A : Type} : (A β β) β A β A β Prop :=
inv_image lt
definition measure.wf {A : Type} (f : A β β) : well_founded (measure f) :=
inv_image.wf f lt.wf
theorem succ_lt_succ {a b : β} : a < b β succ a < succ b :=
succ_le_succ
theorem lt_of_succ_lt {a b : β} : succ a < b β a < b :=
le_of_succ_le
theorem lt_of_succ_lt_succ {a b : β} : succ a < succ b β a < b :=
le_of_succ_le_succ
definition decidable_le [instance] : decidable_rel le :=
nat.rec (Ξ»m, (decidable.inl !zero_le))
(Ξ»n IH m, !nat.cases_on (decidable.inr (not_succ_le_zero n))
(Ξ»m, decidable.rec (Ξ»H, inl (succ_le_succ H))
(Ξ»H, inr (Ξ»a, H (le_of_succ_le_succ a))) (IH m)))
definition decidable_lt [instance] : decidable_rel lt := _
definition decidable_gt [instance] : decidable_rel gt := _
definition decidable_ge [instance] : decidable_rel ge := _
theorem lt_or_ge (a b : β) : a < b β¨ a β₯ b :=
nat.rec (inr !zero_le) (Ξ»n, or.rec
(Ξ»h, inl (le_succ_of_le h))
(Ξ»h, elim (eq_or_lt_of_le h) (Ξ»e, inl (eq.subst e !le.refl)) inr)) b
definition lt_ge_by_cases {a b : β} {P : Type} (H1 : a < b β P) (H2 : a β₯ b β P) : P :=
by_cases H1 (Ξ»h, H2 (elim !lt_or_ge (Ξ»a, absurd a h) (Ξ»a, a)))
definition lt.by_cases {a b : β} {P : Type} (H1 : a < b β P) (H2 : a = b β P) (H3 : b < a β P) : P :=
lt_ge_by_cases H1 (Ξ»hβ,
lt_ge_by_cases H3 (Ξ»hβ, H2 (le.antisymm hβ hβ)))
theorem lt.trichotomy (a b : β) : a < b β¨ a = b β¨ b < a :=
lt.by_cases (Ξ»H, inl H) (Ξ»H, inr (inl H)) (Ξ»H, inr (inr H))
theorem eq_or_lt_of_not_lt {a b : β} (hnlt : Β¬ a < b) : a = b β¨ b < a :=
or.rec_on (lt.trichotomy a b)
(Ξ» hlt, absurd hlt hnlt)
(Ξ» h, h)
theorem lt_succ_of_le {a b : β} : a β€ b β a < succ b :=
succ_le_succ
theorem lt_of_succ_le {a b : β} (h : succ a β€ b) : a < b := h
theorem succ_le_of_lt {a b : β} (h : a < b) : succ a β€ b := h
theorem succ_sub_succ_eq_sub [simp] (a b : β) : succ a - succ b = a - b :=
nat.rec rfl (Ξ» b, congr_arg pred) b
theorem sub_eq_succ_sub_succ (a b : β) : a - b = succ a - succ b :=
eq.symm !succ_sub_succ_eq_sub
theorem zero_sub_eq_zero [simp] (a : β) : zero - a = zero :=
nat.rec rfl (Ξ» a, congr_arg pred) a
theorem zero_eq_zero_sub (a : β) : zero = zero - a :=
eq.symm !zero_sub_eq_zero
theorem sub_le (a b : β) : a - b β€ a :=
nat.rec_on b !le.refl (Ξ» bβ, le.trans !pred_le)
theorem sub_le_iff_true [simp] (a b : β) : a - b β€ a β true :=
iff_true_intro (sub_le a b)
theorem sub_lt {a b : β} (H1 : zero < a) (H2 : zero < b) : a - b < a :=
!nat.cases_on (Ξ»h, absurd h !lt.irrefl)
(Ξ»a h, succ_le_succ (!nat.cases_on (Ξ»h, absurd h !lt.irrefl)
(Ξ»b c, eq.substr !succ_sub_succ_eq_sub !sub_le) H2)) H1
theorem sub_lt_succ (a b : β) : a - b < succ a :=
lt_succ_of_le !sub_le
theorem sub_lt_succ_iff_true [simp] (a b : β) : a - b < succ a β true :=
iff_true_intro !sub_lt_succ
end nat
namespace nat_esimp
open nat
attribute add mul sub [unfold 2]
attribute of_num [unfold 1]
end nat_esimp
|
6462b0fa64ca26281adcef62b094210adaeb63d9 | 57c233acf9386e610d99ed20ef139c5f97504ba3 | /src/data/rat/floor.lean | f924c35b7c09fa4edb137801fd5a6e25ff137ee2 | [
"Apache-2.0"
] | permissive | robertylewis/mathlib | 3d16e3e6daf5ddde182473e03a1b601d2810952c | 1d13f5b932f5e40a8308e3840f96fc882fae01f0 | refs/heads/master | 1,651,379,945,369 | 1,644,276,960,000 | 1,644,276,960,000 | 98,875,504 | 0 | 0 | Apache-2.0 | 1,644,253,514,000 | 1,501,495,700,000 | Lean | UTF-8 | Lean | false | false | 6,441 | lean | /-
Copyright (c) 2019 Johannes HΓΆlzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes HΓΆlzl, Mario Carneiro, Kevin Kappelmann
-/
import algebra.order.floor
import tactic.field_simp
/-!
# Floor Function for Rational Numbers
## Summary
We define the `floor` function and the `floor_ring` instance on `β`. Some technical lemmas relating
`floor` to integer division and modulo arithmetic are derived as well as some simple inequalities.
## Tags
rat, rationals, β, floor
-/
open int
namespace rat
/-- `floor q` is the largest integer `z` such that `z β€ q` -/
protected def floor : β β β€
| β¨n, d, h, cβ© := n / d
protected theorem le_floor {z : β€} : β {r : β}, z β€ rat.floor r β (z : β) β€ r
| β¨n, d, h, cβ© := begin
simp [rat.floor],
rw [num_denom'],
have h' := int.coe_nat_lt.2 h,
conv { to_rhs,
rw [coe_int_eq_mk, rat.le_def zero_lt_one h', mul_one] },
exact int.le_div_iff_mul_le h'
end
instance : floor_ring β :=
floor_ring.of_floor β rat.floor $ Ξ» a z, rat.le_floor.symm
protected lemma floor_def {q : β} : βqβ = q.num / q.denom := by { cases q, refl }
lemma floor_int_div_nat_eq_div {n : β€} {d : β} : β(βn : β) / (βd : β)β = n / (βd : β€) :=
begin
rw [rat.floor_def],
cases decidable.em (d = 0) with d_eq_zero d_ne_zero,
{ simp [d_eq_zero] },
{ cases decidable.em (n = 0) with n_eq_zero n_ne_zero,
{ simp [n_eq_zero] },
{ set q := (n : β) / d with q_eq,
obtain β¨c, n_eq_c_mul_num, d_eq_c_mul_denomβ© : β c, n = c * q.num β§ (d : β€) = c * q.denom, by
{ rw q_eq,
exact_mod_cast (@rat.exists_eq_mul_div_num_and_eq_mul_div_denom n d n_ne_zero
(by exact_mod_cast d_ne_zero)) },
suffices : q.num / q.denom = c * q.num / (c * q.denom),
by rwa [n_eq_c_mul_num, d_eq_c_mul_denom],
suffices : c > 0, by solve_by_elim [int.mul_div_mul_of_pos],
have q_denom_mul_c_pos : (0 : β€) < q.denom * c, by
{ have : (d : β€) > 0, by exact_mod_cast (pos_iff_ne_zero.elim_right d_ne_zero),
rwa [d_eq_c_mul_denom, mul_comm] at this },
suffices : (0 : β€) β€ q.denom, from pos_of_mul_pos_left q_denom_mul_c_pos this,
exact_mod_cast (le_of_lt q.pos) } }
end
end rat
lemma int.mod_nat_eq_sub_mul_floor_rat_div {n : β€} {d : β} : n % d = n - d * β(n : β) / dβ :=
by rw [(eq_sub_of_add_eq $ int.mod_add_div n d), rat.floor_int_div_nat_eq_div]
lemma nat.coprime_sub_mul_floor_rat_div_of_coprime {n d : β} (n_coprime_d : n.coprime d) :
((n : β€) - d * β(n : β)/ dβ).nat_abs.coprime d :=
begin
have : (n : β€) % d = n - d * β(n : β)/ dβ, from int.mod_nat_eq_sub_mul_floor_rat_div,
rw βthis,
have : d.coprime n, from n_coprime_d.symm,
rwa [nat.coprime, nat.gcd_rec] at this
end
namespace rat
lemma num_lt_succ_floor_mul_denom (q : β) : q.num < (βqβ + 1) * q.denom :=
begin
suffices : (q.num : β) < (βqβ + 1) * q.denom, by exact_mod_cast this,
suffices : (q.num : β) < (q - fract q + 1) * q.denom, by
{ have : (βqβ : β) = q - fract q, from (eq_sub_of_add_eq $ floor_add_fract q),
rwa this },
suffices : (q.num : β) < q.num + (1 - fract q) * q.denom, by
{ have : (q - fract q + 1) * q.denom = q.num + (1 - fract q) * q.denom, calc
(q - fract q + 1) * q.denom = (q + (1 - fract q)) * q.denom : by ring
... = q * q.denom + (1 - fract q) * q.denom : by rw add_mul
... = q.num + (1 - fract q) * q.denom : by simp,
rwa this },
suffices : 0 < (1 - fract q) * q.denom, by { rw βsub_lt_iff_lt_add', simpa },
have : 0 < 1 - fract q, by
{ have : fract q < 1, from fract_lt_one q,
have : 0 + fract q < 1, by simp [this],
rwa lt_sub_iff_add_lt },
exact mul_pos this (by exact_mod_cast q.pos)
end
lemma fract_inv_num_lt_num_of_pos {q : β} (q_pos : 0 < q): (fract qβ»ΒΉ).num < q.num :=
begin
-- we know that the numerator must be positive
have q_num_pos : 0 < q.num, from rat.num_pos_iff_pos.elim_right q_pos,
-- we will work with the absolute value of the numerator, which is equal to the numerator
have q_num_abs_eq_q_num : (q.num.nat_abs : β€) = q.num, from
(int.nat_abs_of_nonneg q_num_pos.le),
set q_inv := (q.denom : β) / q.num with q_inv_def,
have q_inv_eq : qβ»ΒΉ = q_inv, from rat.inv_def',
suffices : (q_inv - βq_invβ).num < q.num, by rwa q_inv_eq,
suffices : ((q.denom - q.num * βq_invβ : β) / q.num).num < q.num, by
field_simp [this, (ne_of_gt q_num_pos)],
suffices : (q.denom : β€) - q.num * βq_invβ < q.num, by
{ -- use that `q.num` and `q.denom` are coprime to show that the numerator stays unreduced
have : ((q.denom - q.num * βq_invβ : β) / q.num).num = q.denom - q.num * βq_invβ, by
{ suffices : ((q.denom : β€) - q.num * βq_invβ).nat_abs.coprime q.num.nat_abs, by
exact_mod_cast (rat.num_div_eq_of_coprime q_num_pos this),
have : (q.num.nat_abs : β) = (q.num : β), by exact_mod_cast q_num_abs_eq_q_num,
have tmp := nat.coprime_sub_mul_floor_rat_div_of_coprime q.cop.symm,
simpa only [this, q_num_abs_eq_q_num] using tmp },
rwa this },
-- to show the claim, start with the following inequality
have q_inv_num_denom_ineq : qβ»ΒΉ.num - βqβ»ΒΉβ * qβ»ΒΉ.denom < qβ»ΒΉ.denom, by
{ have : qβ»ΒΉ.num < (βqβ»ΒΉβ + 1) * qβ»ΒΉ.denom, from rat.num_lt_succ_floor_mul_denom qβ»ΒΉ,
have : qβ»ΒΉ.num < βqβ»ΒΉβ * qβ»ΒΉ.denom + qβ»ΒΉ.denom, by rwa [right_distrib, one_mul] at this,
rwa [βsub_lt_iff_lt_add'] at this },
-- use that `q.num` and `q.denom` are coprime to show that q_inv is the unreduced reciprocal
-- of `q`
have : q_inv.num = q.denom β§ q_inv.denom = q.num.nat_abs, by
{ have coprime_q_denom_q_num : q.denom.coprime q.num.nat_abs, from q.cop.symm,
have : int.nat_abs q.denom = q.denom, by simp,
rw βthis at coprime_q_denom_q_num,
rw q_inv_def,
split,
{ exact_mod_cast (rat.num_div_eq_of_coprime q_num_pos coprime_q_denom_q_num) },
{ suffices : (((q.denom : β) / q.num).denom : β€) = q.num.nat_abs, by exact_mod_cast this,
rw q_num_abs_eq_q_num,
exact_mod_cast (rat.denom_div_eq_of_coprime q_num_pos coprime_q_denom_q_num) } },
rwa [q_inv_eq, this.left, this.right, q_num_abs_eq_q_num, mul_comm] at q_inv_num_denom_ineq
end
end rat
|
dd2a02003fbba331ac8c3ad9b7434518f80a7e42 | 2a70b774d16dbdf5a533432ee0ebab6838df0948 | /_target/deps/mathlib/src/topology/metric_space/emetric_space.lean | 4572a62ecd7f93752e5fcb1064cf962ff31440e6 | [
"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 | 37,665 | lean | /-
Copyright (c) 2015, 2017 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Robert Y. Lewis, Johannes HΓΆlzl, Mario Carneiro, SΓ©bastien GouΓ«zel
-/
import data.real.ennreal
import data.finset.intervals
import topology.uniform_space.uniform_embedding
import topology.uniform_space.pi
import topology.uniform_space.uniform_convergence
/-!
# Extended metric spaces
This file is devoted to the definition and study of `emetric_spaces`, i.e., metric
spaces in which the distance is allowed to take the value β. This extended distance is
called `edist`, and takes values in `ennreal`.
Many definitions and theorems expected on emetric spaces are already introduced on uniform spaces and
topological spaces. For example:
open and closed sets, compactness, completeness, continuity and uniform continuity
The class `emetric_space` therefore extends `uniform_space` (and `topological_space`).
-/
open set filter classical
noncomputable theory
open_locale uniformity topological_space big_operators filter nnreal
universes u v w
variables {Ξ± : Type u} {Ξ² : Type v} {Ξ³ : Type w}
/-- Characterizing uniformities associated to a (generalized) distance function `D`
in terms of the elements of the uniformity. -/
theorem uniformity_dist_of_mem_uniformity [linear_order Ξ²] {U : filter (Ξ± Γ Ξ±)} (z : Ξ²) (D : Ξ± β Ξ± β Ξ²)
(H : β s, s β U β βΞ΅>z, β{a b:Ξ±}, D a b < Ξ΅ β (a, b) β s) :
U = β¨
Ξ΅>z, π {p:Ξ±ΓΞ± | D p.1 p.2 < Ξ΅} :=
le_antisymm
(le_infi $ Ξ» Ξ΅, le_infi $ Ξ» Ξ΅0, le_principal_iff.2 $ (H _).2 β¨Ξ΅, Ξ΅0, Ξ» a b, idβ©)
(Ξ» r ur, let β¨Ξ΅, Ξ΅0, hβ© := (H _).1 ur in
mem_infi_sets Ξ΅ $ mem_infi_sets Ξ΅0 $ mem_principal_sets.2 $ Ξ» β¨a, bβ©, h)
class has_edist (Ξ± : Type*) := (edist : Ξ± β Ξ± β ennreal)
export has_edist (edist)
/-- Creating a uniform space from an extended distance. -/
def uniform_space_of_edist
(edist : Ξ± β Ξ± β ennreal)
(edist_self : β x : Ξ±, edist x x = 0)
(edist_comm : β x y : Ξ±, edist x y = edist y x)
(edist_triangle : β x y z : Ξ±, edist x z β€ edist x y + edist y z) : uniform_space Ξ± :=
uniform_space.of_core {
uniformity := (β¨
Ξ΅>0, π {p:Ξ±ΓΞ± | edist p.1 p.2 < Ξ΅}),
refl := le_infi $ assume Ξ΅, le_infi $
by simp [set.subset_def, id_rel, edist_self, (>)] {contextual := tt},
comp :=
le_infi $ assume Ξ΅, le_infi $ assume h,
have (2 : ennreal) = (2 : β) := by simp,
have A : 0 < Ξ΅ / 2 := ennreal.div_pos_iff.2
β¨ne_of_gt h, by { convert ennreal.nat_ne_top 2 }β©,
lift'_le
(mem_infi_sets (Ξ΅ / 2) $ mem_infi_sets A (subset.refl _)) $
have β (a b c : Ξ±), edist a c < Ξ΅ / 2 β edist c b < Ξ΅ / 2 β edist a b < Ξ΅,
from assume a b c hac hcb,
calc edist a b β€ edist a c + edist c b : edist_triangle _ _ _
... < Ξ΅ / 2 + Ξ΅ / 2 : ennreal.add_lt_add hac hcb
... = Ξ΅ : by rw [ennreal.add_halves],
by simpa [comp_rel],
symm := tendsto_infi.2 $ assume Ξ΅, tendsto_infi.2 $ assume h,
tendsto_infi' Ξ΅ $ tendsto_infi' h $ tendsto_principal_principal.2 $ by simp [edist_comm] }
-- the uniform structure is embedded in the emetric space structure
-- to avoid instance diamond issues. See Note [forgetful inheritance].
/-- Extended metric spaces, with an extended distance `edist` possibly taking the
value β
Each emetric space induces a canonical `uniform_space` and hence a canonical `topological_space`.
This is enforced in the type class definition, by extending the `uniform_space` structure. When
instantiating an `emetric_space` structure, the uniformity fields are not necessary, they will be
filled in by default. There is a default value for the uniformity, that can be substituted
in cases of interest, for instance when instantiating an `emetric_space` structure
on a product.
Continuity of `edist` is proved in `topology.instances.ennreal`
-/
class emetric_space (Ξ± : Type u) extends has_edist Ξ± : Type u :=
(edist_self : β x : Ξ±, edist x x = 0)
(eq_of_edist_eq_zero : β {x y : Ξ±}, edist x y = 0 β x = y)
(edist_comm : β x y : Ξ±, edist x y = edist y x)
(edist_triangle : β x y z : Ξ±, edist x z β€ edist x y + edist y z)
(to_uniform_space : uniform_space Ξ± := uniform_space_of_edist edist edist_self edist_comm edist_triangle)
(uniformity_edist : π€ Ξ± = β¨
Ξ΅>0, π {p:Ξ±ΓΞ± | edist p.1 p.2 < Ξ΅} . control_laws_tac)
/- emetric spaces are less common than metric spaces. Therefore, we work in a dedicated
namespace, while notions associated to metric spaces are mostly in the root namespace. -/
variables [emetric_space Ξ±]
@[priority 100] -- see Note [lower instance priority]
instance emetric_space.to_uniform_space' : uniform_space Ξ± :=
emetric_space.to_uniform_space
export emetric_space (edist_self eq_of_edist_eq_zero edist_comm edist_triangle)
attribute [simp] edist_self
/-- Characterize the equality of points by the vanishing of their extended distance -/
@[simp] theorem edist_eq_zero {x y : Ξ±} : edist x y = 0 β x = y :=
iff.intro eq_of_edist_eq_zero (assume : x = y, this βΈ edist_self _)
@[simp] theorem zero_eq_edist {x y : Ξ±} : 0 = edist x y β x = y :=
iff.intro (assume h, eq_of_edist_eq_zero (h.symm))
(assume : x = y, this βΈ (edist_self _).symm)
theorem edist_le_zero {x y : Ξ±} : (edist x y β€ 0) β x = y :=
nonpos_iff_eq_zero.trans edist_eq_zero
/-- Triangle inequality for the extended distance -/
theorem edist_triangle_left (x y z : Ξ±) : edist x y β€ edist z x + edist z y :=
by rw edist_comm z; apply edist_triangle
theorem edist_triangle_right (x y z : Ξ±) : edist x y β€ edist x z + edist y z :=
by rw edist_comm y; apply edist_triangle
lemma edist_triangle4 (x y z t : Ξ±) :
edist x t β€ edist x y + edist y z + edist z t :=
calc
edist x t β€ edist x z + edist z t : edist_triangle x z t
... β€ (edist x y + edist y z) + edist z t : add_le_add_right (edist_triangle x y z) _
/-- The triangle (polygon) inequality for sequences of points; `finset.Ico` version. -/
lemma edist_le_Ico_sum_edist (f : β β Ξ±) {m n} (h : m β€ n) :
edist (f m) (f n) β€ β i in finset.Ico m n, edist (f i) (f (i + 1)) :=
begin
revert n,
refine nat.le_induction _ _,
{ simp only [finset.sum_empty, finset.Ico.self_eq_empty, edist_self],
-- TODO: Why doesn't Lean close this goal automatically? `apply le_refl` fails too.
exact le_refl (0:ennreal) },
{ assume n hn hrec,
calc edist (f m) (f (n+1)) β€ edist (f m) (f n) + edist (f n) (f (n+1)) : edist_triangle _ _ _
... β€ β i in finset.Ico m n, _ + _ : add_le_add hrec (le_refl _)
... = β i in finset.Ico m (n+1), _ :
by rw [finset.Ico.succ_top hn, finset.sum_insert, add_comm]; simp }
end
/-- The triangle (polygon) inequality for sequences of points; `finset.range` version. -/
lemma edist_le_range_sum_edist (f : β β Ξ±) (n : β) :
edist (f 0) (f n) β€ β i in finset.range n, edist (f i) (f (i + 1)) :=
finset.Ico.zero_bot n βΈ edist_le_Ico_sum_edist f (nat.zero_le n)
/-- A version of `edist_le_Ico_sum_edist` with each intermediate distance replaced
with an upper estimate. -/
lemma edist_le_Ico_sum_of_edist_le {f : β β Ξ±} {m n} (hmn : m β€ n)
{d : β β ennreal} (hd : β {k}, m β€ k β k < n β edist (f k) (f (k + 1)) β€ d k) :
edist (f m) (f n) β€ β i in finset.Ico m n, d i :=
le_trans (edist_le_Ico_sum_edist f hmn) $
finset.sum_le_sum $ Ξ» k hk, hd (finset.Ico.mem.1 hk).1 (finset.Ico.mem.1 hk).2
/-- A version of `edist_le_range_sum_edist` with each intermediate distance replaced
with an upper estimate. -/
lemma edist_le_range_sum_of_edist_le {f : β β Ξ±} (n : β)
{d : β β ennreal} (hd : β {k}, k < n β edist (f k) (f (k + 1)) β€ d k) :
edist (f 0) (f n) β€ β i in finset.range n, d i :=
finset.Ico.zero_bot n βΈ edist_le_Ico_sum_of_edist_le (zero_le n) (Ξ» _ _, hd)
/-- Two points coincide if their distance is `< Ξ΅` for all positive Ξ΅ -/
theorem eq_of_forall_edist_le {x y : Ξ±} (h : βΞ΅ > 0, edist x y β€ Ξ΅) : x = y :=
eq_of_edist_eq_zero (eq_of_le_of_forall_le_of_dense bot_le h)
/-- Reformulation of the uniform structure in terms of the extended distance -/
theorem uniformity_edist :
π€ Ξ± = β¨
Ξ΅>0, π {p:Ξ±ΓΞ± | edist p.1 p.2 < Ξ΅} :=
emetric_space.uniformity_edist
theorem uniformity_basis_edist :
(π€ Ξ±).has_basis (Ξ» Ξ΅ : ennreal, 0 < Ξ΅) (Ξ» Ξ΅, {p:Ξ±ΓΞ± | edist p.1 p.2 < Ξ΅}) :=
(@uniformity_edist Ξ± _).symm βΈ has_basis_binfi_principal
(Ξ» r hr p hp, β¨min r p, lt_min hr hp,
Ξ» x hx, lt_of_lt_of_le hx (min_le_left _ _),
Ξ» x hx, lt_of_lt_of_le hx (min_le_right _ _)β©)
β¨1, ennreal.zero_lt_oneβ©
/-- Characterization of the elements of the uniformity in terms of the extended distance -/
theorem mem_uniformity_edist {s : set (Ξ±ΓΞ±)} :
s β π€ Ξ± β (βΞ΅>0, β{a b:Ξ±}, edist a b < Ξ΅ β (a, b) β s) :=
uniformity_basis_edist.mem_uniformity_iff
/-- Given `f : Ξ² β ennreal`, if `f` sends `{i | p i}` to a set of positive numbers
accumulating to zero, then `f i`-neighborhoods of the diagonal form a basis of `π€ Ξ±`.
For specific bases see `uniformity_basis_edist`, `uniformity_basis_edist'`,
`uniformity_basis_edist_nnreal`, and `uniformity_basis_edist_inv_nat`. -/
protected theorem emetric.mk_uniformity_basis {Ξ² : Type*} {p : Ξ² β Prop} {f : Ξ² β ennreal}
(hfβ : β x, p x β 0 < f x) (hf : β Ξ΅, 0 < Ξ΅ β β x (hx : p x), f x β€ Ξ΅) :
(π€ Ξ±).has_basis p (Ξ» x, {p:Ξ±ΓΞ± | edist p.1 p.2 < f x}) :=
begin
refine β¨Ξ» s, uniformity_basis_edist.mem_iff.trans _β©,
split,
{ rintros β¨Ξ΅, Ξ΅β, hΞ΅β©,
rcases hf Ξ΅ Ξ΅β with β¨i, hi, Hβ©,
exact β¨i, hi, Ξ» x hx, hΞ΅ $ lt_of_lt_of_le hx Hβ© },
{ exact Ξ» β¨i, hi, Hβ©, β¨f i, hfβ i hi, Hβ© }
end
/-- Given `f : Ξ² β ennreal`, if `f` sends `{i | p i}` to a set of positive numbers
accumulating to zero, then closed `f i`-neighborhoods of the diagonal form a basis of `π€ Ξ±`.
For specific bases see `uniformity_basis_edist_le` and `uniformity_basis_edist_le'`. -/
protected theorem emetric.mk_uniformity_basis_le {Ξ² : Type*} {p : Ξ² β Prop} {f : Ξ² β ennreal}
(hfβ : β x, p x β 0 < f x) (hf : β Ξ΅, 0 < Ξ΅ β β x (hx : p x), f x β€ Ξ΅) :
(π€ Ξ±).has_basis p (Ξ» x, {p:Ξ±ΓΞ± | edist p.1 p.2 β€ f x}) :=
begin
refine β¨Ξ» s, uniformity_basis_edist.mem_iff.trans _β©,
split,
{ rintros β¨Ξ΅, Ξ΅β, hΞ΅β©,
rcases exists_between Ξ΅β with β¨Ξ΅', hΞ΅'β©,
rcases hf Ξ΅' hΞ΅'.1 with β¨i, hi, Hβ©,
exact β¨i, hi, Ξ» x hx, hΞ΅ $ lt_of_le_of_lt (le_trans hx H) hΞ΅'.2β© },
{ exact Ξ» β¨i, hi, Hβ©, β¨f i, hfβ i hi, Ξ» x hx, H (le_of_lt hx)β© }
end
theorem uniformity_basis_edist_le :
(π€ Ξ±).has_basis (Ξ» Ξ΅ : ennreal, 0 < Ξ΅) (Ξ» Ξ΅, {p:Ξ±ΓΞ± | edist p.1 p.2 β€ Ξ΅}) :=
emetric.mk_uniformity_basis_le (Ξ» _, id) (Ξ» Ξ΅ Ξ΅β, β¨Ξ΅, Ξ΅β, le_refl Ξ΅β©)
theorem uniformity_basis_edist' (Ξ΅' : ennreal) (hΞ΅' : 0 < Ξ΅') :
(π€ Ξ±).has_basis (Ξ» Ξ΅ : ennreal, Ξ΅ β Ioo 0 Ξ΅') (Ξ» Ξ΅, {p:Ξ±ΓΞ± | edist p.1 p.2 < Ξ΅}) :=
emetric.mk_uniformity_basis (Ξ» _, and.left)
(Ξ» Ξ΅ Ξ΅β, let β¨Ξ΄, hΞ΄β© := exists_between hΞ΅' in
β¨min Ξ΅ Ξ΄, β¨lt_min Ξ΅β hΞ΄.1, lt_of_le_of_lt (min_le_right _ _) hΞ΄.2β©, min_le_left _ _β©)
theorem uniformity_basis_edist_le' (Ξ΅' : ennreal) (hΞ΅' : 0 < Ξ΅') :
(π€ Ξ±).has_basis (Ξ» Ξ΅ : ennreal, Ξ΅ β Ioo 0 Ξ΅') (Ξ» Ξ΅, {p:Ξ±ΓΞ± | edist p.1 p.2 β€ Ξ΅}) :=
emetric.mk_uniformity_basis_le (Ξ» _, and.left)
(Ξ» Ξ΅ Ξ΅β, let β¨Ξ΄, hΞ΄β© := exists_between hΞ΅' in
β¨min Ξ΅ Ξ΄, β¨lt_min Ξ΅β hΞ΄.1, lt_of_le_of_lt (min_le_right _ _) hΞ΄.2β©, min_le_left _ _β©)
theorem uniformity_basis_edist_nnreal :
(π€ Ξ±).has_basis (Ξ» Ξ΅ : ββ₯0, 0 < Ξ΅) (Ξ» Ξ΅, {p:Ξ±ΓΞ± | edist p.1 p.2 < Ξ΅}) :=
emetric.mk_uniformity_basis (Ξ» _, ennreal.coe_pos.2)
(Ξ» Ξ΅ Ξ΅β, let β¨Ξ΄, hΞ΄β© := ennreal.lt_iff_exists_nnreal_btwn.1 Ξ΅β in
β¨Ξ΄, ennreal.coe_pos.1 hΞ΄.1, le_of_lt hΞ΄.2β©)
theorem uniformity_basis_edist_inv_nat :
(π€ Ξ±).has_basis (Ξ» _, true) (Ξ» n:β, {p:Ξ±ΓΞ± | edist p.1 p.2 < (βn)β»ΒΉ}) :=
emetric.mk_uniformity_basis
(Ξ» n _, ennreal.inv_pos.2 $ ennreal.nat_ne_top n)
(Ξ» Ξ΅ Ξ΅β, let β¨n, hnβ© := ennreal.exists_inv_nat_lt (ne_of_gt Ξ΅β) in β¨n, trivial, le_of_lt hnβ©)
/-- Fixed size neighborhoods of the diagonal belong to the uniform structure -/
theorem edist_mem_uniformity {Ξ΅:ennreal} (Ξ΅0 : 0 < Ξ΅) :
{p:Ξ±ΓΞ± | edist p.1 p.2 < Ξ΅} β π€ Ξ± :=
mem_uniformity_edist.2 β¨Ξ΅, Ξ΅0, Ξ» a b, idβ©
namespace emetric
theorem uniformity_has_countable_basis : is_countably_generated (π€ Ξ±) :=
is_countably_generated_of_seq β¨_, uniformity_basis_edist_inv_nat.eq_infiβ©
/-- Ξ΅-Ξ΄ characterization of uniform continuity on a set for emetric spaces -/
theorem uniform_continuous_on_iff [emetric_space Ξ²] {f : Ξ± β Ξ²} {s : set Ξ±} :
uniform_continuous_on f s β β Ξ΅ > 0, β Ξ΄ > 0,
β{a b}, a β s β b β s β edist a b < Ξ΄ β edist (f a) (f b) < Ξ΅ :=
uniformity_basis_edist.uniform_continuous_on_iff uniformity_basis_edist
/-- Ξ΅-Ξ΄ characterization of uniform continuity on emetric spaces -/
theorem uniform_continuous_iff [emetric_space Ξ²] {f : Ξ± β Ξ²} :
uniform_continuous f β β Ξ΅ > 0, β Ξ΄ > 0,
β{a b:Ξ±}, edist a b < Ξ΄ β edist (f a) (f b) < Ξ΅ :=
uniformity_basis_edist.uniform_continuous_iff uniformity_basis_edist
/-- Ξ΅-Ξ΄ characterization of uniform embeddings on emetric spaces -/
theorem uniform_embedding_iff [emetric_space Ξ²] {f : Ξ± β Ξ²} :
uniform_embedding f β function.injective f β§ uniform_continuous f β§
β Ξ΄ > 0, β Ξ΅ > 0, β {a b : Ξ±}, edist (f a) (f b) < Ξ΅ β edist a b < Ξ΄ :=
uniform_embedding_def'.trans $ and_congr iff.rfl $ and_congr iff.rfl
β¨Ξ» H Ξ΄ Ξ΄0, let β¨t, tu, htβ© := H _ (edist_mem_uniformity Ξ΄0),
β¨Ξ΅, Ξ΅0, hΞ΅β© := mem_uniformity_edist.1 tu in
β¨Ξ΅, Ξ΅0, Ξ» a b h, ht _ _ (hΞ΅ h)β©,
Ξ» H s su, let β¨Ξ΄, Ξ΄0, hΞ΄β© := mem_uniformity_edist.1 su, β¨Ξ΅, Ξ΅0, hΞ΅β© := H _ Ξ΄0 in
β¨_, edist_mem_uniformity Ξ΅0, Ξ» a b h, hΞ΄ (hΞ΅ h)β©β©
/-- A map between emetric spaces is a uniform embedding if and only if the edistance between `f x`
and `f y` is controlled in terms of the distance between `x` and `y` and conversely. -/
theorem uniform_embedding_iff' [emetric_space Ξ²] {f : Ξ± β Ξ²} :
uniform_embedding f β
(β Ξ΅ > 0, β Ξ΄ > 0, β {a b : Ξ±}, edist a b < Ξ΄ β edist (f a) (f b) < Ξ΅) β§
(β Ξ΄ > 0, β Ξ΅ > 0, β {a b : Ξ±}, edist (f a) (f b) < Ξ΅ β edist a b < Ξ΄) :=
begin
split,
{ assume h,
exact β¨uniform_continuous_iff.1 (uniform_embedding_iff.1 h).2.1,
(uniform_embedding_iff.1 h).2.2β© },
{ rintros β¨hβ, hββ©,
refine uniform_embedding_iff.2 β¨_, uniform_continuous_iff.2 hβ, hββ©,
assume x y hxy,
have : edist x y β€ 0,
{ refine le_of_forall_lt' (λδ δpos, _),
rcases hβ Ξ΄ Ξ΄pos with β¨Ξ΅, Ξ΅pos, hΞ΅β©,
have : edist (f x) (f y) < Ξ΅, by simpa [hxy],
exact hΞ΅ this },
simpa using this }
end
/-- Ξ΅-Ξ΄ characterization of Cauchy sequences on emetric spaces -/
protected lemma cauchy_iff {f : filter Ξ±} :
cauchy f β f β β₯ β§ β Ξ΅ > 0, β t β f, β x y β t, edist x y < Ξ΅ :=
uniformity_basis_edist.cauchy_iff
/-- A very useful criterion to show that a space is complete is to show that all sequences
which satisfy a bound of the form `edist (u n) (u m) < B N` for all `n m β₯ N` are
converging. This is often applied for `B N = 2^{-N}`, i.e., with a very fast convergence to
`0`, which makes it possible to use arguments of converging series, while this is impossible
to do in general for arbitrary Cauchy sequences. -/
theorem complete_of_convergent_controlled_sequences (B : β β ennreal) (hB : βn, 0 < B n)
(H : βu : β β Ξ±, (βN n m : β, N β€ n β N β€ m β edist (u n) (u m) < B N) β βx, tendsto u at_top (π x)) :
complete_space Ξ± :=
uniform_space.complete_of_convergent_controlled_sequences
uniformity_has_countable_basis
(Ξ» n, {p:Ξ±ΓΞ± | edist p.1 p.2 < B n}) (Ξ» n, edist_mem_uniformity $ hB n) H
/-- A sequentially complete emetric space is complete. -/
theorem complete_of_cauchy_seq_tendsto :
(β u : β β Ξ±, cauchy_seq u β βa, tendsto u at_top (π a)) β complete_space Ξ± :=
uniform_space.complete_of_cauchy_seq_tendsto uniformity_has_countable_basis
/-- Expressing locally uniform convergence on a set using `edist`. -/
lemma tendsto_locally_uniformly_on_iff {ΞΉ : Type*} [topological_space Ξ²]
{F : ΞΉ β Ξ² β Ξ±} {f : Ξ² β Ξ±} {p : filter ΞΉ} {s : set Ξ²} :
tendsto_locally_uniformly_on F f p s β
β Ξ΅ > 0, β x β s, β t β π[s] x, βαΆ n in p, β y β t, edist (f y) (F n y) < Ξ΅ :=
begin
refine β¨Ξ» H Ξ΅ hΞ΅, H _ (edist_mem_uniformity hΞ΅), Ξ» H u hu x hx, _β©,
rcases mem_uniformity_edist.1 hu with β¨Ξ΅, Ξ΅pos, hΞ΅β©,
rcases H Ξ΅ Ξ΅pos x hx with β¨t, ht, Htβ©,
exact β¨t, ht, Ht.mono (Ξ» n hs x hx, hΞ΅ (hs x hx))β©
end
/-- Expressing uniform convergence on a set using `edist`. -/
lemma tendsto_uniformly_on_iff {ΞΉ : Type*}
{F : ΞΉ β Ξ² β Ξ±} {f : Ξ² β Ξ±} {p : filter ΞΉ} {s : set Ξ²} :
tendsto_uniformly_on F f p s β β Ξ΅ > 0, βαΆ n in p, β x β s, edist (f x) (F n x) < Ξ΅ :=
begin
refine β¨Ξ» H Ξ΅ hΞ΅, H _ (edist_mem_uniformity hΞ΅), Ξ» H u hu, _β©,
rcases mem_uniformity_edist.1 hu with β¨Ξ΅, Ξ΅pos, hΞ΅β©,
exact (H Ξ΅ Ξ΅pos).mono (Ξ» n hs x hx, hΞ΅ (hs x hx))
end
/-- Expressing locally uniform convergence using `edist`. -/
lemma tendsto_locally_uniformly_iff {ΞΉ : Type*} [topological_space Ξ²]
{F : ΞΉ β Ξ² β Ξ±} {f : Ξ² β Ξ±} {p : filter ΞΉ} :
tendsto_locally_uniformly F f p β
β Ξ΅ > 0, β (x : Ξ²), β t β π x, βαΆ n in p, β y β t, edist (f y) (F n y) < Ξ΅ :=
by simp only [β tendsto_locally_uniformly_on_univ, tendsto_locally_uniformly_on_iff,
mem_univ, forall_const, exists_prop, nhds_within_univ]
/-- Expressing uniform convergence using `edist`. -/
lemma tendsto_uniformly_iff {ΞΉ : Type*}
{F : ΞΉ β Ξ² β Ξ±} {f : Ξ² β Ξ±} {p : filter ΞΉ} :
tendsto_uniformly F f p β β Ξ΅ > 0, βαΆ n in p, β x, edist (f x) (F n x) < Ξ΅ :=
by simp only [β tendsto_uniformly_on_univ, tendsto_uniformly_on_iff, mem_univ, forall_const]
end emetric
open emetric
/-- An emetric space is separated -/
@[priority 100] -- see Note [lower instance priority]
instance to_separated : separated_space Ξ± :=
separated_def.2 $ Ξ» x y h, eq_of_forall_edist_le $
Ξ» Ξ΅ Ξ΅0, le_of_lt (h _ (edist_mem_uniformity Ξ΅0))
/-- Auxiliary function to replace the uniformity on an emetric space with
a uniformity which is equal to the original one, but maybe not defeq.
This is useful if one wants to construct an emetric space with a
specified uniformity. See Note [forgetful inheritance] explaining why having definitionally
the right uniformity is often important.
-/
def emetric_space.replace_uniformity {Ξ±} [U : uniform_space Ξ±] (m : emetric_space Ξ±)
(H : @uniformity _ U = @uniformity _ emetric_space.to_uniform_space) :
emetric_space Ξ± :=
{ edist := @edist _ m.to_has_edist,
edist_self := edist_self,
eq_of_edist_eq_zero := @eq_of_edist_eq_zero _ _,
edist_comm := edist_comm,
edist_triangle := edist_triangle,
to_uniform_space := U,
uniformity_edist := H.trans (@emetric_space.uniformity_edist Ξ± _) }
/-- The extended metric induced by an injective function taking values in an emetric space. -/
def emetric_space.induced {Ξ± Ξ²} (f : Ξ± β Ξ²) (hf : function.injective f)
(m : emetric_space Ξ²) : emetric_space Ξ± :=
{ edist := Ξ» x y, edist (f x) (f y),
edist_self := Ξ» x, edist_self _,
eq_of_edist_eq_zero := Ξ» x y h, hf (edist_eq_zero.1 h),
edist_comm := Ξ» x y, edist_comm _ _,
edist_triangle := Ξ» x y z, edist_triangle _ _ _,
to_uniform_space := uniform_space.comap f m.to_uniform_space,
uniformity_edist := begin
apply @uniformity_dist_of_mem_uniformity _ _ _ _ _ (Ξ» x y, edist (f x) (f y)),
refine Ξ» s, mem_comap_sets.trans _,
split; intro H,
{ rcases H with β¨r, ru, rsβ©,
rcases mem_uniformity_edist.1 ru with β¨Ξ΅, Ξ΅0, hΞ΅β©,
refine β¨Ξ΅, Ξ΅0, Ξ» a b h, rs (hΞ΅ _)β©, exact h },
{ rcases H with β¨Ξ΅, Ξ΅0, hΞ΅β©,
exact β¨_, edist_mem_uniformity Ξ΅0, Ξ» β¨a, bβ©, hΞ΅β© }
end }
/-- Emetric space instance on subsets of emetric spaces -/
instance {Ξ± : Type*} {p : Ξ± β Prop} [t : emetric_space Ξ±] : emetric_space (subtype p) :=
t.induced coe (Ξ» x y, subtype.ext_iff_val.2)
/-- The extended distance on a subset of an emetric space is the restriction of
the original distance, by definition -/
theorem subtype.edist_eq {p : Ξ± β Prop} (x y : subtype p) : edist x y = edist (x : Ξ±) y := rfl
/-- The product of two emetric spaces, with the max distance, is an extended
metric spaces. We make sure that the uniform structure thus constructed is the one
corresponding to the product of uniform spaces, to avoid diamond problems. -/
instance prod.emetric_space_max [emetric_space Ξ²] : emetric_space (Ξ± Γ Ξ²) :=
{ edist := Ξ» x y, max (edist x.1 y.1) (edist x.2 y.2),
edist_self := Ξ» x, by simp,
eq_of_edist_eq_zero := Ξ» x y h, begin
cases max_le_iff.1 (le_of_eq h) with hβ hβ,
have A : x.fst = y.fst := edist_le_zero.1 hβ,
have B : x.snd = y.snd := edist_le_zero.1 hβ,
exact prod.ext_iff.2 β¨A, Bβ©
end,
edist_comm := Ξ» x y, by simp [edist_comm],
edist_triangle := Ξ» x y z, max_le
(le_trans (edist_triangle _ _ _) (add_le_add (le_max_left _ _) (le_max_left _ _)))
(le_trans (edist_triangle _ _ _) (add_le_add (le_max_right _ _) (le_max_right _ _))),
uniformity_edist := begin
refine uniformity_prod.trans _,
simp [emetric_space.uniformity_edist, comap_infi],
rw β infi_inf_eq, congr, funext,
rw β infi_inf_eq, congr, funext,
simp [inf_principal, ext_iff, max_lt_iff]
end,
to_uniform_space := prod.uniform_space }
lemma prod.edist_eq [emetric_space Ξ²] (x y : Ξ± Γ Ξ²) :
edist x y = max (edist x.1 y.1) (edist x.2 y.2) :=
rfl
section pi
open finset
variables {Ο : Ξ² β Type*} [fintype Ξ²]
/-- The product of a finite number of emetric spaces, with the max distance, is still
an emetric space.
This construction would also work for infinite products, but it would not give rise
to the product topology. Hence, we only formalize it in the good situation of finitely many
spaces. -/
instance emetric_space_pi [βb, emetric_space (Ο b)] : emetric_space (Ξ b, Ο b) :=
{ edist := Ξ» f g, finset.sup univ (Ξ»b, edist (f b) (g b)),
edist_self := assume f, bot_unique $ finset.sup_le $ by simp,
edist_comm := assume f g, by unfold edist; congr; funext a; exact edist_comm _ _,
edist_triangle := assume f g h,
begin
simp only [finset.sup_le_iff],
assume b hb,
exact le_trans (edist_triangle _ (g b) _) (add_le_add (le_sup hb) (le_sup hb))
end,
eq_of_edist_eq_zero := assume f g eq0,
begin
have eq1 : sup univ (Ξ» (b : Ξ²), edist (f b) (g b)) β€ 0 := le_of_eq eq0,
simp only [finset.sup_le_iff] at eq1,
exact (funext $ assume b, edist_le_zero.1 $ eq1 b $ mem_univ b),
end,
to_uniform_space := Pi.uniform_space _,
uniformity_edist := begin
simp only [Pi.uniformity, emetric_space.uniformity_edist, comap_infi, gt_iff_lt,
preimage_set_of_eq, comap_principal],
rw infi_comm, congr, funext Ξ΅,
rw infi_comm, congr, funext Ξ΅pos,
change 0 < Ξ΅ at Ξ΅pos,
simp [set.ext_iff, Ξ΅pos]
end }
lemma edist_pi_def [Ξ b, emetric_space (Ο b)] (f g : Ξ b, Ο b) :
edist f g = finset.sup univ (Ξ»b, edist (f b) (g b)) := rfl
end pi
namespace emetric
variables {x y z : Ξ±} {Ξ΅ Ξ΅β Ξ΅β : ennreal} {s : set Ξ±}
/-- `emetric.ball x Ξ΅` is the set of all points `y` with `edist y x < Ξ΅` -/
def ball (x : Ξ±) (Ξ΅ : ennreal) : set Ξ± := {y | edist y x < Ξ΅}
@[simp] theorem mem_ball : y β ball x Ξ΅ β edist y x < Ξ΅ := iff.rfl
theorem mem_ball' : y β ball x Ξ΅ β edist x y < Ξ΅ := by rw edist_comm; refl
/-- `emetric.closed_ball x Ξ΅` is the set of all points `y` with `edist y x β€ Ξ΅` -/
def closed_ball (x : Ξ±) (Ξ΅ : ennreal) := {y | edist y x β€ Ξ΅}
@[simp] theorem mem_closed_ball : y β closed_ball x Ξ΅ β edist y x β€ Ξ΅ := iff.rfl
theorem ball_subset_closed_ball : ball x Ξ΅ β closed_ball x Ξ΅ :=
assume y, by simp; intros h; apply le_of_lt h
theorem pos_of_mem_ball (hy : y β ball x Ξ΅) : 0 < Ξ΅ :=
lt_of_le_of_lt (zero_le _) hy
theorem mem_ball_self (h : 0 < Ξ΅) : x β ball x Ξ΅ :=
show edist x x < Ξ΅, by rw edist_self; assumption
theorem mem_closed_ball_self : x β closed_ball x Ξ΅ :=
show edist x x β€ Ξ΅, by rw edist_self; exact bot_le
theorem mem_ball_comm : x β ball y Ξ΅ β y β ball x Ξ΅ :=
by simp [edist_comm]
theorem ball_subset_ball (h : Ξ΅β β€ Ξ΅β) : ball x Ξ΅β β ball x Ξ΅β :=
Ξ» y (yx : _ < Ξ΅β), lt_of_lt_of_le yx h
theorem closed_ball_subset_closed_ball (h : Ξ΅β β€ Ξ΅β) :
closed_ball x Ξ΅β β closed_ball x Ξ΅β :=
Ξ» y (yx : _ β€ Ξ΅β), le_trans yx h
theorem ball_disjoint (h : Ξ΅β + Ξ΅β β€ edist x y) : ball x Ξ΅β β© ball y Ξ΅β = β
:=
eq_empty_iff_forall_not_mem.2 $ Ξ» z β¨hβ, hββ©,
not_lt_of_le (edist_triangle_left x y z)
(lt_of_lt_of_le (ennreal.add_lt_add hβ hβ) h)
theorem ball_subset (h : edist x y + Ξ΅β β€ Ξ΅β) (h' : edist x y < β€) : ball x Ξ΅β β ball y Ξ΅β :=
Ξ» z zx, calc
edist z y β€ edist z x + edist x y : edist_triangle _ _ _
... = edist x y + edist z x : add_comm _ _
... < edist x y + Ξ΅β : (ennreal.add_lt_add_iff_left h').2 zx
... β€ Ξ΅β : h
theorem exists_ball_subset_ball (h : y β ball x Ξ΅) : β Ξ΅' > 0, ball y Ξ΅' β ball x Ξ΅ :=
begin
have : 0 < Ξ΅ - edist y x := by simpa using h,
refine β¨Ξ΅ - edist y x, this, ball_subset _ _β©,
{ rw ennreal.add_sub_cancel_of_le (le_of_lt h), apply le_refl _},
{ have : edist y x β β€ := ne_top_of_lt h, apply lt_top_iff_ne_top.2 this }
end
theorem ball_eq_empty_iff : ball x Ξ΅ = β
β Ξ΅ = 0 :=
eq_empty_iff_forall_not_mem.trans
β¨Ξ»h, le_bot_iff.1 (le_of_not_gt (Ξ» Ξ΅0, h _ (mem_ball_self Ξ΅0))),
λΡ0 y h, not_lt_of_le (le_of_eq Ξ΅0) (pos_of_mem_ball h)β©
/-- Relation βtwo points are at a finite edistanceβ is an equivalence relation. -/
def edist_lt_top_setoid : setoid Ξ± :=
{ r := Ξ» x y, edist x y < β€,
iseqv := β¨Ξ» x, by { rw edist_self, exact ennreal.coe_lt_top },
Ξ» x y h, by rwa edist_comm,
Ξ» x y z hxy hyz, lt_of_le_of_lt (edist_triangle x y z) (ennreal.add_lt_top.2 β¨hxy, hyzβ©)β© }
@[simp] lemma ball_zero : ball x 0 = β
:=
by rw [emetric.ball_eq_empty_iff]
theorem nhds_basis_eball : (π x).has_basis (Ξ» Ξ΅:ennreal, 0 < Ξ΅) (ball x) :=
nhds_basis_uniformity uniformity_basis_edist
theorem nhds_basis_closed_eball : (π x).has_basis (Ξ» Ξ΅:ennreal, 0 < Ξ΅) (closed_ball x) :=
nhds_basis_uniformity uniformity_basis_edist_le
theorem nhds_eq : π x = (β¨
Ξ΅>0, π (ball x Ξ΅)) :=
nhds_basis_eball.eq_binfi
theorem mem_nhds_iff : s β π x β βΞ΅>0, ball x Ξ΅ β s := nhds_basis_eball.mem_iff
theorem is_open_iff : is_open s β βxβs, βΞ΅>0, ball x Ξ΅ β s :=
by simp [is_open_iff_nhds, mem_nhds_iff]
theorem is_open_ball : is_open (ball x Ξ΅) :=
is_open_iff.2 $ Ξ» y, exists_ball_subset_ball
theorem is_closed_ball_top : is_closed (ball x β€) :=
is_open_iff.2 $ Ξ» y hy, β¨β€, ennreal.coe_lt_top, subset_compl_iff_disjoint.2 $
ball_disjoint $ by { rw ennreal.top_add, exact le_of_not_lt hy }β©
theorem ball_mem_nhds (x : Ξ±) {Ξ΅ : ennreal} (Ξ΅0 : 0 < Ξ΅) : ball x Ξ΅ β π x :=
mem_nhds_sets is_open_ball (mem_ball_self Ξ΅0)
/-- Ξ΅-characterization of the closure in emetric spaces -/
theorem mem_closure_iff :
x β closure s β βΞ΅>0, βy β s, edist x y < Ξ΅ :=
(mem_closure_iff_nhds_basis nhds_basis_eball).trans $
by simp only [mem_ball, edist_comm x]
theorem tendsto_nhds {f : filter Ξ²} {u : Ξ² β Ξ±} {a : Ξ±} :
tendsto u f (π a) β β Ξ΅ > 0, βαΆ x in f, edist (u x) a < Ξ΅ :=
nhds_basis_eball.tendsto_right_iff
theorem tendsto_at_top [nonempty Ξ²] [semilattice_sup Ξ²] {u : Ξ² β Ξ±} {a : Ξ±} :
tendsto u at_top (π a) β βΞ΅>0, βN, βnβ₯N, edist (u n) a < Ξ΅ :=
(at_top_basis.tendsto_iff nhds_basis_eball).trans $
by simp only [exists_prop, true_and, mem_Ici, mem_ball]
/-- In an emetric space, Cauchy sequences are characterized by the fact that, eventually,
the edistance between its elements is arbitrarily small -/
@[nolint ge_or_gt] -- see Note [nolint_ge]
theorem cauchy_seq_iff [nonempty Ξ²] [semilattice_sup Ξ²] {u : Ξ² β Ξ±} :
cauchy_seq u β βΞ΅>0, βN, βm nβ₯N, edist (u m) (u n) < Ξ΅ :=
uniformity_basis_edist.cauchy_seq_iff
/-- A variation around the emetric characterization of Cauchy sequences -/
theorem cauchy_seq_iff' [nonempty Ξ²] [semilattice_sup Ξ²] {u : Ξ² β Ξ±} :
cauchy_seq u β βΞ΅>(0 : ennreal), βN, βnβ₯N, edist (u n) (u N) < Ξ΅ :=
uniformity_basis_edist.cauchy_seq_iff'
/-- A variation of the emetric characterization of Cauchy sequences that deals with
`ββ₯0` upper bounds. -/
theorem cauchy_seq_iff_nnreal [nonempty Ξ²] [semilattice_sup Ξ²] {u : Ξ² β Ξ±} :
cauchy_seq u β β Ξ΅ : ββ₯0, 0 < Ξ΅ β β N, β n, N β€ n β edist (u n) (u N) < Ξ΅ :=
uniformity_basis_edist_nnreal.cauchy_seq_iff'
theorem totally_bounded_iff {s : set Ξ±} :
totally_bounded s β β Ξ΅ > 0, βt : set Ξ±, finite t β§ s β βyβt, ball y Ξ΅ :=
β¨Ξ» H Ξ΅ Ξ΅0, H _ (edist_mem_uniformity Ξ΅0),
Ξ» H r ru, let β¨Ξ΅, Ξ΅0, hΞ΅β© := mem_uniformity_edist.1 ru,
β¨t, ft, hβ© := H Ξ΅ Ξ΅0 in
β¨t, ft, subset.trans h $ Union_subset_Union $ Ξ» y, Union_subset_Union $ Ξ» yt z, hΞ΅β©β©
theorem totally_bounded_iff' {s : set Ξ±} :
totally_bounded s β β Ξ΅ > 0, βtβs, finite t β§ s β βyβt, ball y Ξ΅ :=
β¨Ξ» H Ξ΅ Ξ΅0, (totally_bounded_iff_subset.1 H) _ (edist_mem_uniformity Ξ΅0),
Ξ» H r ru, let β¨Ξ΅, Ξ΅0, hΞ΅β© := mem_uniformity_edist.1 ru,
β¨t, _, ft, hβ© := H Ξ΅ Ξ΅0 in
β¨t, ft, subset.trans h $ Union_subset_Union $ Ξ» y, Union_subset_Union $ Ξ» yt z, hΞ΅β©β©
section compact
/-- A compact set in an emetric space is separable, i.e., it is the closure of a countable set -/
lemma countable_closure_of_compact {Ξ± : Type u} [emetric_space Ξ±] {s : set Ξ±} (hs : is_compact s) :
β t β s, (countable t β§ s = closure t) :=
begin
have A : β (e:ennreal), e > 0 β β t β s, (finite t β§ s β (βxβt, ball x e)) :=
totally_bounded_iff'.1 (compact_iff_totally_bounded_complete.1 hs).1,
-- assume e, finite_cover_balls_of_compact hs,
have B : β (e:ennreal), β t β s, finite t β§ (e > 0 β s β (βxβt, ball x e)),
{ intro e,
cases le_or_gt e 0 with h,
{ exact β¨β
, by finishβ© },
{ rcases A e h with β¨s, β¨finite_s, closure_sβ©β©, existsi s, finish }},
/-The desired countable set is obtained by taking for each `n` the centers of a finite cover
by balls of radius `1/n`, and then the union over `n`. -/
choose T T_in_s finite_T using B,
let t := βn:β, T nβ»ΒΉ,
have Tβ : t β s := begin apply Union_subset, assume n, apply T_in_s end,
have Tβ : countable t := by finish [countable_Union, finite.countable],
have Tβ : s β closure t,
{ intros x x_in_s,
apply mem_closure_iff.2,
intros Ξ΅ Ξ΅pos,
rcases ennreal.exists_inv_nat_lt (bot_lt_iff_ne_bot.1 Ξ΅pos) with β¨n, hnβ©,
have inv_n_pos : (0 : ennreal) < (n : β)β»ΒΉ := by simp [ennreal.bot_lt_iff_ne_bot],
have C : x β (βyβ T (n : β)β»ΒΉ, ball y (n : β)β»ΒΉ) :=
mem_of_mem_of_subset x_in_s ((finite_T (n : β)β»ΒΉ).2 inv_n_pos),
rcases mem_Union.1 C with β¨y, _, β¨y_in_T, rflβ©, Dxyβ©,
simp at Dxy, -- Dxy : edist x y < 1 / βn
have : y β t := mem_of_mem_of_subset y_in_T (by apply subset_Union (Ξ» (n:β), T (n : β)β»ΒΉ)),
have : edist x y < Ξ΅ := lt_trans Dxy hn,
exact β¨y, βΉy β tβΊ, βΉedist x y < Ξ΅βΊβ© },
have Tβ : closure t β s := calc
closure t β closure s : closure_mono Tβ
... = s : hs.is_closed.closure_eq,
exact β¨t, β¨Tβ, Tβ, subset.antisymm Tβ Tββ©β©
end
end compact
section first_countable
@[priority 100] -- see Note [lower instance priority]
instance (Ξ± : Type u) [emetric_space Ξ±] :
topological_space.first_countable_topology Ξ± :=
uniform_space.first_countable_topology uniformity_has_countable_basis
end first_countable
section second_countable
open topological_space
/-- A separable emetric space is second countable: one obtains a countable basis by taking
the balls centered at points in a dense subset, and with rational radii. We do not register
this as an instance, as there is already an instance going in the other direction
from second countable spaces to separable spaces, and we want to avoid loops. -/
lemma second_countable_of_separable (Ξ± : Type u) [emetric_space Ξ±] [separable_space Ξ±] :
second_countable_topology Ξ± :=
uniform_space.second_countable_of_separable uniformity_has_countable_basis
end second_countable
section diam
/-- The diameter of a set in an emetric space, named `emetric.diam` -/
def diam (s : set Ξ±) := β¨ (x β s) (y β s), edist x y
lemma diam_le_iff_forall_edist_le {d : ennreal} :
diam s β€ d β β (x β s) (y β s), edist x y β€ d :=
by simp only [diam, supr_le_iff]
/-- If two points belong to some set, their edistance is bounded by the diameter of the set -/
lemma edist_le_diam_of_mem (hx : x β s) (hy : y β s) : edist x y β€ diam s :=
diam_le_iff_forall_edist_le.1 (le_refl _) x hx y hy
/-- If the distance between any two points in a set is bounded by some constant, this constant
bounds the diameter. -/
lemma diam_le_of_forall_edist_le {d : ennreal} (h : β (x β s) (y β s), edist x y β€ d) :
diam s β€ d :=
diam_le_iff_forall_edist_le.2 h
/-- The diameter of a subsingleton vanishes. -/
lemma diam_subsingleton (hs : s.subsingleton) : diam s = 0 :=
nonpos_iff_eq_zero.1 $ diam_le_of_forall_edist_le $
Ξ» x hx y hy, (hs hx hy).symm βΈ edist_self y βΈ le_refl _
/-- The diameter of the empty set vanishes -/
@[simp] lemma diam_empty : diam (β
: set Ξ±) = 0 :=
diam_subsingleton subsingleton_empty
/-- The diameter of a singleton vanishes -/
@[simp] lemma diam_singleton : diam ({x} : set Ξ±) = 0 :=
diam_subsingleton subsingleton_singleton
lemma diam_eq_zero_iff : diam s = 0 β s.subsingleton :=
β¨Ξ» h x hx y hy, edist_le_zero.1 $ h βΈ edist_le_diam_of_mem hx hy, diam_subsingletonβ©
lemma diam_pos_iff : 0 < diam s β β (x β s) (y β s), x β y :=
begin
have := not_congr (@diam_eq_zero_iff _ _ s),
dunfold set.subsingleton at this,
push_neg at this,
simpa only [pos_iff_ne_zero, exists_prop] using this
end
lemma diam_insert : diam (insert x s) = max (β¨ y β s, edist x y) (diam s) :=
eq_of_forall_ge_iff $ Ξ» d, by simp only [diam_le_iff_forall_edist_le, ball_insert_iff,
edist_self, edist_comm x, max_le_iff, supr_le_iff, zero_le, true_and,
forall_and_distrib, and_self, β and_assoc]
lemma diam_pair : diam ({x, y} : set Ξ±) = edist x y :=
by simp only [supr_singleton, diam_insert, diam_singleton, ennreal.max_zero_right]
lemma diam_triple :
diam ({x, y, z} : set Ξ±) = max (max (edist x y) (edist x z)) (edist y z) :=
by simp only [diam_insert, supr_insert, supr_singleton, diam_singleton,
ennreal.max_zero_right, ennreal.sup_eq_max]
/-- The diameter is monotonous with respect to inclusion -/
lemma diam_mono {s t : set Ξ±} (h : s β t) : diam s β€ diam t :=
diam_le_of_forall_edist_le $ Ξ» x hx y hy, edist_le_diam_of_mem (h hx) (h hy)
/-- The diameter of a union is controlled by the diameter of the sets, and the edistance
between two points in the sets. -/
lemma diam_union {t : set Ξ±} (xs : x β s) (yt : y β t) : diam (s βͺ t) β€ diam s + edist x y + diam t :=
begin
have A : βa β s, βb β t, edist a b β€ diam s + edist x y + diam t := Ξ»a ha b hb, calc
edist a b β€ edist a x + edist x y + edist y b : edist_triangle4 _ _ _ _
... β€ diam s + edist x y + diam t :
add_le_add (add_le_add (edist_le_diam_of_mem ha xs) (le_refl _)) (edist_le_diam_of_mem yt hb),
refine diam_le_of_forall_edist_le (Ξ»a ha b hb, _),
cases (mem_union _ _ _).1 ha with h'a h'a; cases (mem_union _ _ _).1 hb with h'b h'b,
{ calc edist a b β€ diam s : edist_le_diam_of_mem h'a h'b
... β€ diam s + (edist x y + diam t) : le_add_right (le_refl _)
... = diam s + edist x y + diam t : by simp only [add_comm, eq_self_iff_true, add_left_comm] },
{ exact A a h'a b h'b },
{ have Z := A b h'b a h'a, rwa [edist_comm] at Z },
{ calc edist a b β€ diam t : edist_le_diam_of_mem h'a h'b
... β€ (diam s + edist x y) + diam t : le_add_left (le_refl _) }
end
lemma diam_union' {t : set Ξ±} (h : (s β© t).nonempty) : diam (s βͺ t) β€ diam s + diam t :=
let β¨x, β¨xs, xtβ©β© := h in by simpa using diam_union xs xt
lemma diam_closed_ball {r : ennreal} : diam (closed_ball x r) β€ 2 * r :=
diam_le_of_forall_edist_le $ Ξ»a ha b hb, calc
edist a b β€ edist a x + edist b x : edist_triangle_right _ _ _
... β€ r + r : add_le_add ha hb
... = 2 * r : by simp [mul_two, mul_comm]
lemma diam_ball {r : ennreal} : diam (ball x r) β€ 2 * r :=
le_trans (diam_mono ball_subset_closed_ball) diam_closed_ball
end diam
end emetric --namespace
|
0b47fc2bc4615a396eaf3b591ab08074c1cd1130 | a7602958ab456501ff85db8cf5553f7bcab201d7 | /Notes/Logic_and_Proof/Chapter9/9.20.lean | bd77164f289c931729c7e609e9c314ecf13362fc | [] | no_license | enlauren/math-logic | 081e2e737c8afb28dbb337968df95ead47321ba0 | 086b6935543d1841f1db92d0e49add1124054c37 | refs/heads/master | 1,594,506,621,950 | 1,558,634,976,000 | 1,558,634,976,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 1,558 | lean | -- 9.2 Using the universal quantifier
import init.data.nat
open nat
constant A : β β Prop
constant B : β β Prop
#check β x, (A x β¨ B x) β§ Β¬ (A x β§ B x)
-- Remember, after β x, ___, the universal quantifier has the widest scope
-- possible. This means that:
#check β x, A x -> B x
-- Is the same as:
#check β x, (A x -> B x)
-- But we can tighten the bounds if we want:
#check β x, (A x) -> B x
-- β-Introduction.
-- In this case, our goal is to _prove_ some β statement. We do this with the
-- β-introduction.
example: β x, A x :=
show β x, A x, from
assume x, -- This just says "fix an arbitrary x of type β" (in this case).
-- We can also change the variable name here, since it is bound (I guess).
show A x, from sorry -- sorry should be some proof of |A x|.
-- β-Elimination.
-- In this case, our goal is to prove some |A x|, from an |β x, A x| assumption.
-- Setup a variable of type |β|, and |Type|
variable n: β
variable z: Type
-- Setup a |C|, analogous to |A|, but which accepts Type, instead of |β|.
-- constant A : β β Prop
variable C: Type -> Prop
-- Setup hypotheses that β x, we assume |A x| and |C x| are true. We are allowed
-- to "apply" this hypotheses to any variable whose type matches the formula
-- associated with the hypothesis.
variable h1: β x, A x -- Can apply this to arbitrary values of |β|.
variable h2: β x, C x -- Can | | | | | | |Type|.
example: A n :=
show A n, from h1 n
example: C z :=
show C z, from h2 z |
477511ac91de58d6ddcf55ad4dbb6122772fd373 | e21db629d2e37a833531fdcb0b37ce4d71825408 | /src/use_cases/parlang/if.lean | 2ddd3e6f1bc89c4b4e885f02f781ee209de775fe | [] | no_license | fischerman/GPU-transformation-verifier | 614a28cb4606a05a0eb27e8d4eab999f4f5ea60c | 75a5016f05382738ff93ce5859c4cfa47ccb63c1 | refs/heads/master | 1,586,985,789,300 | 1,579,290,514,000 | 1,579,290,514,000 | 165,031,073 | 1 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 5,175 | lean | import parlang
/- IDEA: try to remove the active map from the assertions -/
namespace parlang
open kernel
-- notation ac ` β ` c ` β ` x:(foldr ` β ` (h t, deactivate_threads c ac h) ac) := x
notation ac ` β ` c ` β ` s := deactivate_threads c ac s
example {Οβ ΞΉβ ΞΉβ : Type} {Οβ : ΞΉβ β Type} {Οβ : ΞΉβ β Type} [decidable_eq ΞΉβ] [decidable_eq ΞΉβ] :
{* Ξ» nβ sβ acβ nβ (sβ : state nβ (memory (Ξ» (n: string), β)) Οβ) acβ, 0 < nβ β§ all_threads_active acβ *}
@kernel.compute ΞΉβ Οβ Οβ id ~> kernel.ite (Ξ»m, m.get "tid" = 1) (kernel.compute (Ξ» m, m.update "x" 1)) (kernel.compute (Ξ»m, m.update "x" 0))
{* Ξ» nβ sβ acβ nβ sβ acβ, β (h : 0 < nβ), (sβ.threads.nth β¨0, hβ©).tlocal.get "x" = 1 *} := begin
suffices : {* Ξ» nβ sβ acβ nβ (sβ : state nβ (memory (Ξ» (n: string), β)) Οβ) acβ, 0 < nβ β§ (Ξ»acβ, all_threads_active acβ) acβ *}
@kernel.compute ΞΉβ Οβ Οβ id ~> kernel.ite (Ξ»m, m.get "tid" = 1) (kernel.compute (Ξ» m, m.update "x" 1)) (kernel.compute (Ξ»m, m.update "x" 0))
{* Ξ» nβ sβ acβ nβ sβ acβ, (β (h : 0 < nβ), (sβ.threads.nth β¨0, hβ©).tlocal.get "x" = 1) β§ (Ξ»acβ, all_threads_active acβ) acβ *},
{
apply consequence,
exact this,
simp,
intros,
exact β¨a, a_1β©,
intros,
exact (a.left) h,
},
apply ite_right,
swap 7,
exact (Ξ»nβ sβ acβ nβ sβ acβ, β (h : 0 < nβ), (sβ.threads.nth β¨0, hβ©).tlocal.get "x" = 1),
{
intros,
simp *,
}, {
intros,
exact a,
}, {
intros,
exact a,
}, {
intros,
exact a h,
}, {
apply consequence_pre,
apply compute_right,
intros _ _ _ _ _ _ hp _,
rw state.map_active_threads_nth_ac,
refl,
sorry,
}, {
apply consequence_pre,
apply compute_right,
intros _ _ _ _ _ _ hp _,
rw β state.map_active_threads_nth_inac,
exact hp.left h,
sorry,
}
end
section
parameters (k : kernel bool (Ξ» (s : string), β))
def pβ : program bool (Ξ» (s : string), β) :=
program.intro (Ξ»m, m.get "x") (
compute (Ξ»_, tt) ;;
ite id (
k
) (
store (Ξ»_, β¨"a", 5β©)
)
)
def pβ : program bool (Ξ» (s : string), β) :=
program.intro (Ξ»m, m.get "x") (
compute (Ξ»_, tt) ;;
k
)
example : rel_hoare_program (Ξ»_, ff) (Ξ»_, ff) (Ξ» mβ mβ, eq mβ mβ β§ 0 < mβ.get "x") pβ pβ eq := begin
apply rel_kernel_to_program,
apply single_step_left,
swap,
apply single_step_right,
swap,
{
apply known_branch_left,
swap,
{
apply consequence,
apply rhl_eq,
swap,
{intros,
cases a_1 with mβ,
use mβ,
use mβ,
split,
assumption,
cases a,
subst a_left,
specialize a_right rfl,
cases a_right,
subst a_right_left,
split,
exact a_1_h,
refl,},
intros,
have : (β (tid : fin nβ), id ((vector.nth (sβ.threads) tid).tlocal) = tt) β§ nβ = nβ β§ β h : nβ = nβ, sβ = (by rw h; exact sβ) β§ acβ = (by rw h; exact acβ) := a,
exact this.right,
},
intros,
exact a.left tid,
},
apply compute_right,
{
apply consequence_pre,
apply swap (compute_right _),
{
intros,
use sβ,
apply exec_skip,
}, {
intros _ _ _ _ _ _ h,
simp[assertion_swap_side],
cases h with mβ h,
cases h with mβ h,
cases h with hβ h,
cases h with hβ h,
cases h with hβ h,
cases h with hβ h,
cases h with hβ
h,
cases h with hβ h,
cases h with hβ h,
cases h with hβ hβ,
split,
{
intro tid,
rw state.map_active_threads_nth_ac,
refl,
apply all_threads_active_nth hβ,
},
split,
{
cases hβ,
subst hβ_left,
rw [hβ, β hβ],
},
intro h',
subst h',
split, {
rw eq.mpr.intro,
unfold state.map_active_threads,
simp,
apply vector.eq_element_wise,
intro i,
simp,
have : acβ = acβ := all_threads_active_eq hβ hβ,
subst this,
rw hβ,
rw hβ
,
cases hβ,
subst hβ_left,
}, {
have : acβ = acβ := all_threads_active_eq hβ hβ,
exact this,
}
}
}, {
intros,
exact a.right,
}
end
end
end parlang |
d43ab2cc066dd4aa83ac2ff559980c2f2ec2b939 | 57c233acf9386e610d99ed20ef139c5f97504ba3 | /src/topology/continuous_function/basic.lean | 3d681aeaacc74277c57b06bece6aa4c229bc1fea | [
"Apache-2.0"
] | permissive | robertylewis/mathlib | 3d16e3e6daf5ddde182473e03a1b601d2810952c | 1d13f5b932f5e40a8308e3840f96fc882fae01f0 | refs/heads/master | 1,651,379,945,369 | 1,644,276,960,000 | 1,644,276,960,000 | 98,875,504 | 0 | 0 | Apache-2.0 | 1,644,253,514,000 | 1,501,495,700,000 | Lean | UTF-8 | Lean | false | false | 7,855 | lean | /-
Copyright Β© 2020 NicolΓ² Cavalleri. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: NicolΓ² Cavalleri
-/
import data.set.Union_lift
import topology.homeomorph
/-!
# Continuous bundled map
In this file we define the type `continuous_map` of continuous bundled maps.
-/
/-- Bundled continuous maps. -/
@[protect_proj]
structure continuous_map (Ξ± : Type*) (Ξ² : Type*)
[topological_space Ξ±] [topological_space Ξ²] :=
(to_fun : Ξ± β Ξ²)
(continuous_to_fun : continuous to_fun . tactic.interactive.continuity')
notation `C(` Ξ± `, ` Ξ² `)` := continuous_map Ξ± Ξ²
namespace continuous_map
attribute [continuity] continuous_map.continuous_to_fun
variables {Ξ± : Type*} {Ξ² : Type*} {Ξ³ : Type*}
variables [topological_space Ξ±] [topological_space Ξ²] [topological_space Ξ³]
instance : has_coe_to_fun (C(Ξ±, Ξ²)) (Ξ» _, Ξ± β Ξ²) := β¨continuous_map.to_funβ©
@[simp] lemma to_fun_eq_coe {f : C(Ξ±, Ξ²)} : f.to_fun = (f : Ξ± β Ξ²) := rfl
variables {Ξ± Ξ²} {f g : continuous_map Ξ± Ξ²}
@[continuity] protected lemma continuous (f : C(Ξ±, Ξ²)) : continuous f := f.continuous_to_fun
@[continuity] lemma continuous_set_coe (s : set C(Ξ±, Ξ²)) (f : s) : continuous f :=
by { cases f, rw @coe_fn_coe_base', continuity }
protected lemma continuous_at (f : C(Ξ±, Ξ²)) (x : Ξ±) : continuous_at f x :=
f.continuous.continuous_at
protected lemma continuous_within_at (f : C(Ξ±, Ξ²)) (s : set Ξ±) (x : Ξ±) :
continuous_within_at f s x :=
f.continuous.continuous_within_at
protected lemma congr_fun {f g : C(Ξ±, Ξ²)} (H : f = g) (x : Ξ±) : f x = g x := H βΈ rfl
protected lemma congr_arg (f : C(Ξ±, Ξ²)) {x y : Ξ±} (h : x = y) : f x = f y := h βΈ rfl
@[ext] theorem ext (H : β x, f x = g x) : f = g :=
by cases f; cases g; congr'; exact funext H
lemma ext_iff : f = g β β x, f x = g x :=
β¨continuous_map.congr_fun, extβ©
instance [inhabited Ξ²] : inhabited C(Ξ±, Ξ²) :=
β¨{ to_fun := Ξ» _, default, }β©
lemma coe_inj β¦f g : C(Ξ±, Ξ²)β¦ (h : (f : Ξ± β Ξ²) = g) : f = g :=
by cases f; cases g; cases h; refl
@[simp] lemma coe_mk (f : Ξ± β Ξ²) (h : continuous f) :
β(β¨f, hβ© : continuous_map Ξ± Ξ²) = f := rfl
section
variables (Ξ± Ξ²)
/--
The continuous functions from `Ξ±` to `Ξ²` are the same as the plain functions when `Ξ±` is discrete.
-/
@[simps]
def equiv_fn_of_discrete [discrete_topology Ξ±] : C(Ξ±, Ξ²) β (Ξ± β Ξ²) :=
β¨(Ξ» f, f), (Ξ» f, β¨f, continuous_of_discrete_topologyβ©),
Ξ» f, by { ext, refl, }, Ξ» f, by { ext, refl, }β©
end
/-- The identity as a continuous map. -/
def id : C(Ξ±, Ξ±) := β¨idβ©
@[simp] lemma id_coe : (id : Ξ± β Ξ±) = _root_.id := rfl
lemma id_apply (a : Ξ±) : id a = a := rfl
/-- The composition of continuous maps, as a continuous map. -/
def comp (f : C(Ξ², Ξ³)) (g : C(Ξ±, Ξ²)) : C(Ξ±, Ξ³) := β¨f β gβ©
@[simp] lemma comp_coe (f : C(Ξ², Ξ³)) (g : C(Ξ±, Ξ²)) : (comp f g : Ξ± β Ξ³) = f β g := rfl
lemma comp_apply (f : C(Ξ², Ξ³)) (g : C(Ξ±, Ξ²)) (a : Ξ±) : comp f g a = f (g a) := rfl
@[simp] lemma id_comp (f : C(Ξ², Ξ³)) : id.comp f = f := by { ext, refl }
@[simp] lemma comp_id (f : C(Ξ±, Ξ²)) : f.comp id = f := by { ext, refl }
/-- Constant map as a continuous map -/
def const (b : Ξ²) : C(Ξ±, Ξ²) := β¨Ξ» x, bβ©
@[simp] lemma const_coe (b : Ξ²) : (const b : Ξ± β Ξ²) = (Ξ» x, b) := rfl
lemma const_apply (b : Ξ²) (a : Ξ±) : const b a = b := rfl
instance [h : nonempty Ξ±] [nontrivial Ξ²] : nontrivial C(Ξ±, Ξ²) :=
{ exists_pair_ne := begin
obtain β¨bβ, bβ, hbβ© := exists_pair_ne Ξ²,
refine β¨const bβ, const bβ, _β©,
contrapose! hb,
change const bβ h.some = const bβ h.some,
simp [hb]
end }
section prod
variables {Ξ±β Ξ±β Ξ²β Ξ²β : Type*}
[topological_space Ξ±β] [topological_space Ξ±β]
[topological_space Ξ²β] [topological_space Ξ²β]
/-- Given two continuous maps `f` and `g`, this is the continuous map `x β¦ (f x, g x)`. -/
def prod_mk (f : C(Ξ±, Ξ²β)) (g : C(Ξ±, Ξ²β)) :
C(Ξ±, Ξ²β Γ Ξ²β) :=
{ to_fun := (Ξ» x, (f x, g x)),
continuous_to_fun := continuous.prod_mk f.continuous g.continuous }
/-- Given two continuous maps `f` and `g`, this is the continuous map `(x, y) β¦ (f x, g y)`. -/
def prod_map (f : C(Ξ±β, Ξ±β)) (g : C(Ξ²β, Ξ²β)) :
C(Ξ±β Γ Ξ²β, Ξ±β Γ Ξ²β) :=
{ to_fun := prod.map f g,
continuous_to_fun := continuous.prod_map f.continuous g.continuous }
@[simp] lemma prod_eval (f : C(Ξ±, Ξ²β)) (g : C(Ξ±, Ξ²β)) (a : Ξ±) :
(prod_mk f g) a = (f a, g a) := rfl
end prod
section pi
variables {I A : Type*} {X : I β Type*}
[topological_space A] [β i, topological_space (X i)]
/-- Abbreviation for product of continuous maps, which is continuous -/
def pi (f : Ξ i, C(A, X i)) : C(A, Ξ i, X i) :=
{ to_fun := Ξ» (a : A) (i : I), f i a, }
@[simp] lemma pi_eval (f : Ξ i, C(A, X i)) (a : A) :
(pi f) a = Ξ» i : I, (f i) a := rfl
end pi
section restrict
variables (s : set Ξ±)
/-- The restriction of a continuous function `Ξ± β Ξ²` to a subset `s` of `Ξ±`. -/
def restrict (f : C(Ξ±, Ξ²)) : C(s, Ξ²) := β¨f β coeβ©
@[simp] lemma coe_restrict (f : C(Ξ±, Ξ²)) : β(f.restrict s) = f β coe := rfl
end restrict
section gluing
variables {ΞΉ : Type*}
(S : ΞΉ β set Ξ±)
(Ο : Ξ i : ΞΉ, C(S i, Ξ²))
(hΟ : β i j (x : Ξ±) (hxi : x β S i) (hxj : x β S j), Ο i β¨x, hxiβ© = Ο j β¨x, hxjβ©)
(hS : β x : Ξ±, β i, S i β nhds x)
include hΟ hS
/-- A family `Ο i` of continuous maps `C(S i, Ξ²)`, where the domains `S i` contain a neighbourhood
of each point in `Ξ±` and the functions `Ο i` agree pairwise on intersections, can be glued to
construct a continuous map in `C(Ξ±, Ξ²)`. -/
noncomputable def lift_cover : C(Ξ±, Ξ²) :=
begin
have H : (β i, S i) = set.univ,
{ rw set.eq_univ_iff_forall,
intros x,
rw set.mem_Union,
obtain β¨i, hiβ© := hS x,
exact β¨i, mem_of_mem_nhds hiβ© },
refine β¨set.lift_cover S (Ξ» i, Ο i) hΟ H, continuous_subtype_nhds_cover hS _β©,
intros i,
convert (Ο i).continuous,
ext x,
exact set.lift_cover_coe x,
end
variables {S Ο hΟ hS}
@[simp] lemma lift_cover_coe {i : ΞΉ} (x : S i) : lift_cover S Ο hΟ hS x = Ο i x :=
set.lift_cover_coe _
@[simp] lemma lift_cover_restrict {i : ΞΉ} : (lift_cover S Ο hΟ hS).restrict (S i) = Ο i :=
ext $ lift_cover_coe
omit hΟ hS
variables (A : set (set Ξ±))
(F : Ξ (s : set Ξ±) (hi : s β A), C(s, Ξ²))
(hF : β s (hs : s β A) t (ht : t β A) (x : Ξ±) (hxi : x β s) (hxj : x β t),
F s hs β¨x, hxiβ© = F t ht β¨x, hxjβ©)
(hA : β x : Ξ±, β i β A, i β nhds x)
include hF hA
/-- A family `F s` of continuous maps `C(s, Ξ²)`, where (1) the domains `s` are taken from a set `A`
of sets in `Ξ±` which contain a neighbourhood of each point in `Ξ±` and (2) the functions `F s` agree
pairwise on intersections, can be glued to construct a continuous map in `C(Ξ±, Ξ²)`. -/
noncomputable def lift_cover' : C(Ξ±, Ξ²) :=
begin
let S : A β set Ξ± := coe,
let F : Ξ i : A, C(i, Ξ²) := Ξ» i, F i i.prop,
refine lift_cover S F (Ξ» i j, hF i i.prop j j.prop) _,
intros x,
obtain β¨s, hs, hsxβ© := hA x,
exact β¨β¨s, hsβ©, hsxβ©
end
variables {A F hF hA}
@[simp] lemma lift_cover_coe' {s : set Ξ±} {hs : s β A} (x : s) :
lift_cover' A F hF hA x = F s hs x :=
let x' : (coe : A β set Ξ±) β¨s, hsβ© := x in lift_cover_coe x'
@[simp] lemma lift_cover_restrict' {s : set Ξ±} {hs : s β A} :
(lift_cover' A F hF hA).restrict s = F s hs :=
ext $ lift_cover_coe'
end gluing
end continuous_map
/--
The forward direction of a homeomorphism, as a bundled continuous map.
-/
@[simps]
def homeomorph.to_continuous_map {Ξ± Ξ² : Type*} [topological_space Ξ±] [topological_space Ξ²]
(e : Ξ± ββ Ξ²) : C(Ξ±, Ξ²) := β¨eβ©
|
1bc575b62f5d194e8ae8869059a385b8914e1fcf | 6df8d5ae3acf20ad0d7f0247d2cee1957ef96df1 | /notes/10.29.19.lean | eab58d59e8ac88c7ff9758c45a32765696e6585a | [] | 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 | 316 | lean | --Derek Johnson
/-
Propositional logic vs Predicate logic
*in prop logic, a variable can only be true or false
in Predicate, variables can have any range
*Propositions can have qualifiers
* Predicate can have quantifiers
Propositions and Proofs
Proofs of (not true) do not exist
-/ |
fc49f62fafca42905b25b79724b1ae4a11adca57 | 49ffcd4736fa3bdcc1cdbb546d4c855d67c0f28a | /library/tools/debugger/cli.lean | ece6579a75aa7bfb25bcedf3cfdca268c741d2d1 | [
"Apache-2.0"
] | permissive | black13/lean | 979e24d09e17b2fdf8ec74aac160583000086bc8 | 1a80ea9c8e28902cadbfb612896bcd45ba4ce697 | refs/heads/master | 1,626,839,620,164 | 1,509,113,016,000 | 1,509,122,889,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 8,237 | 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
Simple command line interface for debugging Lean programs and tactics.
-/
import tools.debugger.util
namespace debugger
@[derive decidable_eq]
inductive mode
| init | step | run | done
structure state :=
(md : mode)
(csz : nat)
(fn_bps : list name)
(active_bps : list (nat Γ name))
def init_state : state :=
{ md := mode.init, csz := 0,
fn_bps := [], active_bps := [] }
meta def show_help : vm unit :=
do
vm.put_str "exit - stop debugger\n",
vm.put_str "help - display this message\n",
vm.put_str "run - continue execution\n",
vm.put_str "step - execute until another function in on the top of the stack\n",
vm.put_str "stack trace\n",
vm.put_str " up - move up in the stack trace\n",
vm.put_str " down - move down in the stack trace\n",
vm.put_str " vars - display variables in the current stack frame\n",
vm.put_str " stack - display all functions on the call stack\n",
vm.put_str " print var - display the value of variable named 'var' in the current stack frame\n",
vm.put_str " pidx idx - display the value of variable at position #idx in the current stack frame\n",
vm.put_str "breakpoints\n",
vm.put_str " break fn - add breakpoint for fn\n",
vm.put_str " rbreak fn - remove breakpoint\n",
vm.put_str " bs - show breakpoints\n"
meta def add_breakpoint (s : state) (args : list string) : vm state :=
match args with
| [arg] := do
fn β return $ to_qualified_name arg,
ok β is_valid_fn_prefix fn,
if ok then
return {s with fn_bps := fn :: list.filter (Ξ» fn', fn β fn') s.fn_bps}
else
vm.put_str "invalid 'break' command, given name is not the prefix for any function\n" >>
return s
| _ :=
vm.put_str "invalid 'break <fn>' command, incorrect number of arguments\n" >>
return s
end
meta def remove_breakpoint (s : state) (args : list string) : vm state :=
match args with
| [arg] := do
fn β return $ to_qualified_name arg,
return {s with fn_bps := list.filter (Ξ» fn', fn β fn') s.fn_bps}
| _ :=
vm.put_str "invalid 'rbreak <fn>' command, incorrect number of arguments\n" >>
return s
end
meta def show_breakpoints : list name β vm unit
| [] := return ()
| (fn::fns) := do
vm.put_str " ",
vm.put_str fn.to_string,
vm.put_str "\n",
show_breakpoints fns
meta def up_cmd (frame : nat) : vm nat :=
if frame = 0 then return 0
else show_frame (frame - 1) >> return (frame - 1)
meta def down_cmd (frame : nat) : vm nat :=
do sz β vm.call_stack_size,
if frame >= sz - 1 then return frame
else show_frame (frame + 1) >> return (frame + 1)
meta def pidx_cmd : nat β list string β vm unit
| frame [arg] := do
idx β return $ arg.to_nat,
sz β vm.stack_size,
(bp, ep) β vm.call_stack_var_range frame,
if bp + idx >= ep then
vm.put_str "invalid 'pidx <idx>' command, index out of bounds\n"
else do
v β vm.pp_stack_obj (bp+idx),
(n, t) β vm.stack_obj_info (bp+idx),
opts β vm.get_options,
vm.put_str n.to_string,
vm.put_str " := ",
vm.put_str $ v.to_string opts,
vm.put_str "\n"
| _ _ :=
vm.put_str "invalid 'pidx <idx>' command, incorrect number of arguments\n"
meta def print_var : nat β nat β name β vm unit
| i ep v := do
if i = ep then vm.put_str "invalid 'print <var>', unknown variable\n"
else do
(n, t) β vm.stack_obj_info i,
if n = v then do
v β vm.pp_stack_obj i,
opts β vm.get_options,
vm.put_str n.to_string,
vm.put_str " := ",
vm.put_str $ v.to_string opts,
vm.put_str "\n"
else
print_var (i+1) ep v
meta def print_cmd : nat β list string β vm unit
| frame [arg] := do
(bp, ep) β vm.call_stack_var_range frame,
print_var bp ep (to_qualified_name arg)
| _ _ :=
vm.put_str "invalid 'print <var>' command, incorrect number of arguments\n"
meta def cmd_loop_core : state β nat β list string β vm state
| s frame default_cmd := do
is_eof β vm.eof,
if is_eof then do
vm.put_str "stopping debugger... 'end of file' has been found\n",
return {s with md := mode.done }
else do
vm.put_str "% ",
l β vm.get_line,
tks β return $ split l,
tks β return $ if tks = [] then default_cmd else tks,
match tks with
| [] := cmd_loop_core s frame default_cmd
| (cmd::args) :=
if cmd = "help" β¨ cmd = "h" then show_help >> cmd_loop_core s frame []
else if cmd = "exit" then return {s with md := mode.done }
else if cmd = "run" β¨ cmd = "r" then return {s with md := mode.run }
else if cmd = "step" β¨ cmd = "s" then return {s with md := mode.step }
else if cmd = "break" β¨ cmd = "b" then do new_s β add_breakpoint s args, cmd_loop_core new_s frame []
else if cmd = "rbreak" then do new_s β remove_breakpoint s args, cmd_loop_core new_s frame []
else if cmd = "bs" then do
vm.put_str "breakpoints\n",
show_breakpoints s.fn_bps,
cmd_loop_core s frame default_cmd
else if cmd = "up" β¨ cmd = "u" then do frame β up_cmd frame, cmd_loop_core s frame ["u"]
else if cmd = "down" β¨ cmd = "d" then do frame β down_cmd frame, cmd_loop_core s frame ["d"]
else if cmd = "vars" β¨ cmd = "v" then do show_vars frame, cmd_loop_core s frame []
else if cmd = "stack" then do show_stack, cmd_loop_core s frame []
else if cmd = "pidx" then do pidx_cmd frame args, cmd_loop_core s frame []
else if cmd = "print" β¨ cmd = "p" then do print_cmd frame args, cmd_loop_core s frame []
else do vm.put_str "unknown command, type 'help' for help\n", cmd_loop_core s frame default_cmd
end
meta def cmd_loop (s : state) (default_cmd : list string) : vm state :=
do csz β vm.call_stack_size,
cmd_loop_core s (csz - 1) default_cmd
def prune_active_bps_core (csz : nat) : list (nat Γ name) β list (nat Γ name)
| [] := []
| ((csz', n)::ls) := if csz < csz' then prune_active_bps_core ls else ((csz',n)::ls)
meta def prune_active_bps (s : state) : vm state :=
do sz β vm.call_stack_size,
return {s with active_bps := prune_active_bps_core sz s.active_bps}
meta def updt_csz (s : state) : vm state :=
do sz β vm.call_stack_size,
return {s with csz := sz}
meta def init_transition (s : state) : vm state :=
do opts β vm.get_options,
if opts.get_bool `server ff then return {s with md := mode.done}
else do
bps β vm.get_attribute `breakpoint,
new_s β return {s with fn_bps := bps},
if opts.get_bool `debugger.autorun ff then
return {new_s with md := mode.run}
else do
vm.put_str "Lean debugger\n",
show_curr_fn "debugging",
vm.put_str "type 'help' for help\n",
cmd_loop new_s []
meta def step_transition (s : state) : vm state :=
do
sz β vm.call_stack_size,
if sz = s.csz then return s
else do
show_curr_fn "step",
cmd_loop s ["s"]
meta def bp_reached (s : state) : vm bool :=
(do fn β vm.curr_fn,
return $ s.fn_bps.any (Ξ» p, p.is_prefix_of fn))
<|>
return ff
meta def in_active_bps (s : state) : vm bool :=
do sz β vm.call_stack_size,
match s.active_bps with
| [] := return ff
| (csz, _)::_ := return (sz = csz)
end
meta def run_transition (s : state) : vm state :=
do b1 β in_active_bps s,
b2 β bp_reached s,
if b1 β¨ not b2 then return s
else do
show_curr_fn "breakpoint",
fn β vm.curr_fn,
sz β vm.call_stack_size,
new_s β return $ {s with active_bps := (sz, fn) :: s.active_bps},
cmd_loop new_s ["r"]
meta def step_fn (s : state) : vm state :=
do s β prune_active_bps s,
if s.md = mode.init then do new_s β init_transition s, updt_csz new_s
else if s.md = mode.done then return s
else if s.md = mode.step then do new_s β step_transition s, updt_csz new_s
else if s.md = mode.run then do new_s β run_transition s, updt_csz new_s
else return s
@[vm_monitor]
meta def monitor : vm_monitor state :=
{ init := init_state, step := step_fn }
end debugger
|
6d67f82e2a59dd85044cd5d4221552da584b1177 | 63abd62053d479eae5abf4951554e1064a4c45b4 | /src/data/finset/intervals.lean | 7bf4f99e59324170391f997e82c21ca4bbe93937 | [
"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,439 | lean | /-
Copyright (c) 2019 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import data.finset.basic
import data.multiset.intervals
/-!
# Intervals in β as finsets
For now this only covers `Ico n m`, the "closed-open" interval containing `[n, ..., m-1]`.
-/
namespace finset
open multiset nat
/-! ### intervals -/
/- Ico (a closed open interval) -/
variables {n m l : β}
/-- `Ico n m` is the set of natural numbers `n β€ k < m`. -/
def Ico (n m : β) : finset β := β¨_, Ico.nodup n mβ©
namespace Ico
@[simp] theorem val (n m : β) : (Ico n m).1 = multiset.Ico n m := rfl
@[simp] theorem to_finset (n m : β) : (multiset.Ico n m).to_finset = Ico n m :=
(multiset.to_finset_eq _).symm
theorem image_add (n m k : β) : (Ico n m).image ((+) k) = Ico (n + k) (m + k) :=
by simp [image, multiset.Ico.map_add]
theorem image_sub (n m k : β) (h : k β€ n) : (Ico n m).image (Ξ» x, x - k) = Ico (n - k) (m - k) :=
begin
dsimp [image],
rw [multiset.Ico.map_sub _ _ _ h, βmultiset.to_finset_eq],
refl,
end
theorem zero_bot (n : β) : Ico 0 n = range n :=
eq_of_veq $ multiset.Ico.zero_bot _
@[simp] theorem card (n m : β) : (Ico n m).card = m - n :=
multiset.Ico.card _ _
@[simp] theorem mem {n m l : β} : l β Ico n m β n β€ l β§ l < m :=
multiset.Ico.mem
theorem eq_empty_of_le {n m : β} (h : m β€ n) : Ico n m = β
:=
eq_of_veq $ multiset.Ico.eq_zero_of_le h
@[simp] theorem self_eq_empty (n : β) : Ico n n = β
:=
eq_empty_of_le $ le_refl n
@[simp] theorem eq_empty_iff {n m : β} : Ico n m = β
β m β€ n :=
iff.trans val_eq_zero.symm multiset.Ico.eq_zero_iff
theorem subset_iff {mβ nβ mβ nβ : β} (hmn : mβ < nβ) :
Ico mβ nβ β Ico mβ nβ β (mβ β€ mβ β§ nβ β€ nβ) :=
begin
simp only [subset_iff, mem],
refine β¨Ξ» h, β¨_, _β©, _β©,
{ exact (h β¨le_refl _, hmnβ©).1 },
{ refine le_of_pred_lt (@h (pred nβ) β¨le_pred_of_lt hmn, pred_lt _β©).2,
exact ne_of_gt (lt_of_le_of_lt (nat.zero_le mβ) hmn) },
{ rintros β¨hm, hnβ© k β¨hmk, hknβ©,
exact β¨le_trans hm hmk, lt_of_lt_of_le hkn hnβ© }
end
protected theorem subset {mβ nβ mβ nβ : β} (hmm : mβ β€ mβ) (hnn : nβ β€ nβ) :
Ico mβ nβ β Ico mβ nβ :=
begin
simp only [finset.subset_iff, Ico.mem],
assume x hx,
exact β¨le_trans hmm hx.1, lt_of_lt_of_le hx.2 hnnβ©
end
lemma union_consecutive {n m l : β} (hnm : n β€ m) (hml : m β€ l) :
Ico n m βͺ Ico m l = Ico n l :=
by rw [β to_finset, β to_finset, β multiset.to_finset_add,
multiset.Ico.add_consecutive hnm hml, to_finset]
@[simp] lemma inter_consecutive (n m l : β) : Ico n m β© Ico m l = β
:=
begin
rw [β to_finset, β to_finset, β multiset.to_finset_inter, multiset.Ico.inter_consecutive],
simp,
end
lemma disjoint_consecutive (n m l : β) : disjoint (Ico n m) (Ico m l) :=
le_of_eq $ inter_consecutive n m l
@[simp] theorem succ_singleton (n : β) : Ico n (n+1) = {n} :=
eq_of_veq $ multiset.Ico.succ_singleton
theorem succ_top {n m : β} (h : n β€ m) : Ico n (m + 1) = insert m (Ico n m) :=
by rw [β to_finset, multiset.Ico.succ_top h, multiset.to_finset_cons, to_finset]
theorem succ_top' {n m : β} (h : n < m) : Ico n m = insert (m - 1) (Ico n (m - 1)) :=
begin
have w : m = m - 1 + 1 := (nat.sub_add_cancel (nat.one_le_of_lt h)).symm,
conv { to_lhs, rw w },
rw succ_top,
exact nat.le_pred_of_lt h
end
theorem insert_succ_bot {n m : β} (h : n < m) : insert n (Ico (n + 1) m) = Ico n m :=
by rw [eq_comm, β to_finset, multiset.Ico.eq_cons h, multiset.to_finset_cons, to_finset]
@[simp] theorem pred_singleton {m : β} (h : 0 < m) : Ico (m - 1) m = {m - 1} :=
eq_of_veq $ multiset.Ico.pred_singleton h
@[simp] theorem not_mem_top {n m : β} : m β Ico n m :=
multiset.Ico.not_mem_top
lemma filter_lt_of_top_le {n m l : β} (hml : m β€ l) : (Ico n m).filter (Ξ» x, x < l) = Ico n m :=
eq_of_veq $ multiset.Ico.filter_lt_of_top_le hml
lemma filter_lt_of_le_bot {n m l : β} (hln : l β€ n) : (Ico n m).filter (Ξ» x, x < l) = β
:=
eq_of_veq $ multiset.Ico.filter_lt_of_le_bot hln
lemma filter_Ico_bot {n m : β} (hnm : n < m) : (Ico n m).filter (Ξ» x, x β€ n) = {n} :=
eq_of_veq $ multiset.Ico.filter_le_of_bot hnm
lemma filter_lt_of_ge {n m l : β} (hlm : l β€ m) : (Ico n m).filter (Ξ» x, x < l) = Ico n l :=
eq_of_veq $ multiset.Ico.filter_lt_of_ge hlm
@[simp] lemma filter_lt (n m l : β) : (Ico n m).filter (Ξ» x, x < l) = Ico n (min m l) :=
eq_of_veq $ multiset.Ico.filter_lt n m l
lemma filter_le_of_le_bot {n m l : β} (hln : l β€ n) : (Ico n m).filter (Ξ» x, l β€ x) = Ico n m :=
eq_of_veq $ multiset.Ico.filter_le_of_le_bot hln
lemma filter_le_of_top_le {n m l : β} (hml : m β€ l) : (Ico n m).filter (Ξ» x, l β€ x) = β
:=
eq_of_veq $ multiset.Ico.filter_le_of_top_le hml
lemma filter_le_of_le {n m l : β} (hnl : n β€ l) : (Ico n m).filter (Ξ» x, l β€ x) = Ico l m :=
eq_of_veq $ multiset.Ico.filter_le_of_le hnl
@[simp] lemma filter_le (n m l : β) : (Ico n m).filter (Ξ» x, l β€ x) = Ico (max n l) m :=
eq_of_veq $ multiset.Ico.filter_le n m l
@[simp] lemma diff_left (l n m : β) : (Ico n m) \ (Ico n l) = Ico (max n l) m :=
by ext k; by_cases n β€ k; simp [h, and_comm]
@[simp] lemma diff_right (l n m : β) : (Ico n m) \ (Ico l m) = Ico n (min m l) :=
have βk, (k < m β§ (l β€ k β m β€ k)) β (k < m β§ k < l) :=
assume k, and_congr_right $ assume hk, by rw [β not_imp_not]; simp [hk],
by ext k; by_cases n β€ k; simp [h, this]
lemma image_const_sub {k m n : β} (hkn : k β€ n) :
(Ico k m).image (Ξ» j, n - j) = Ico (n + 1 - m) (n + 1 - k) :=
begin
rw [nat.sub_add_comm hkn],
ext j,
simp only [mem, mem_image, exists_prop, nat.lt_iff_add_one_le, add_le_add_iff_right],
split,
{ rintros β¨j, β¨hjk, hjmβ©, rflβ©,
split,
{ simp only [β nat.add_sub_add_right n 1 j, nat.sub_le_sub_left, hjm] },
{ exact nat.sub_le_sub_left _ hjk } },
{ rintros β¨hm, hkβ©,
have hj : j β€ n := le_trans hk (nat.sub_le_self _ _),
refine β¨n - j, β¨_, _β©, _β©,
{ apply nat.le_sub_right_of_add_le,
rwa nat.le_sub_left_iff_add_le hkn at hk },
{ rwa [β nat.sub_add_comm hj, nat.sub_le_iff] },
{ exact nat.sub_sub_self hj } }
end
end Ico
lemma range_eq_Ico (n : β) : finset.range n = finset.Ico 0 n :=
by { ext i, simp }
lemma range_image_pred_top_sub (n : β) :
(finset.range n).image (Ξ» j, n - 1 - j) = finset.range n :=
begin
cases n,
{ simp },
{ simp [range_eq_Ico, Ico.image_const_sub] }
end
-- TODO We don't yet attempt to reproduce the entire interface for `Ico` for `Ico_β€`.
/-- `Ico_β€ l u` is the set of integers `l β€ k < u`. -/
def Ico_β€ (l u : β€) : finset β€ :=
(finset.range (u - l).to_nat).map
{ to_fun := Ξ» n, n + l,
inj' := Ξ» n m h, by simpa using h }
@[simp] lemma Ico_β€.mem {n m l : β€} : l β Ico_β€ n m β n β€ l β§ l < m :=
begin
dsimp [Ico_β€],
simp only [int.lt_to_nat, exists_prop, mem_range, add_comm, function.embedding.coe_fn_mk,
mem_map],
split,
{ rintro β¨a, β¨h, rflβ©β©,
exact β¨int.le.intro rfl, lt_sub_iff_add_lt'.mp hβ© },
{ rintro β¨hβ, hββ©,
use (l - n).to_nat,
split; simp [hβ, hβ], }
end
@[simp] lemma Ico_β€.card (l u : β€) : (Ico_β€ l u).card = (u - l).to_nat := by simp [Ico_β€]
end finset
|
2451a309d2262990edd905d5ab8d18f315e8a7a6 | 1abd1ed12aa68b375cdef28959f39531c6e95b84 | /src/analysis/special_functions/complex/log.lean | 34f328cd867f0b42e4828195378596eeb52dfbe8 | [
"Apache-2.0"
] | permissive | jumpy4/mathlib | d3829e75173012833e9f15ac16e481e17596de0f | af36f1a35f279f0e5b3c2a77647c6bf2cfd51a13 | refs/heads/master | 1,693,508,842,818 | 1,636,203,271,000 | 1,636,203,271,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 13,633 | lean | /-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle SΓΆnne, Benjamin Davidson
-/
import analysis.special_functions.complex.arg
import analysis.special_functions.log
import analysis.special_functions.trigonometric.inverse_deriv
/-!
# The complex `log` function
Basic properties, relationship with `exp`, and differentiability.
-/
noncomputable theory
namespace complex
open set filter
open_locale real topological_space
/-- Inverse of the `exp` function. Returns values such that `(log x).im > - Ο` and `(log x).im β€ Ο`.
`log 0 = 0`-/
@[pp_nodot] noncomputable def log (x : β) : β := x.abs.log + arg x * I
lemma log_re (x : β) : x.log.re = x.abs.log := by simp [log]
lemma log_im (x : β) : x.log.im = x.arg := by simp [log]
lemma neg_pi_lt_log_im (x : β) : -Ο < (log x).im := by simp only [log_im, neg_pi_lt_arg]
lemma log_im_le_pi (x : β) : (log x).im β€ Ο := by simp only [log_im, arg_le_pi]
lemma exp_log {x : β} (hx : x β 0) : exp (log x) = x :=
by rw [log, exp_add_mul_I, β of_real_sin, sin_arg, β of_real_cos, cos_arg hx,
β of_real_exp, real.exp_log (abs_pos.2 hx), mul_add, of_real_div, of_real_div,
mul_div_cancel' _ (of_real_ne_zero.2 (mt abs_eq_zero.1 hx)), β mul_assoc,
mul_div_cancel' _ (of_real_ne_zero.2 (mt abs_eq_zero.1 hx)), re_add_im]
@[simp] lemma range_exp : range exp = {0}αΆ :=
set.ext $ Ξ» x, β¨by { rintro β¨x, rflβ©, exact exp_ne_zero x }, Ξ» hx, β¨log x, exp_log hxβ©β©
lemma exp_inj_of_neg_pi_lt_of_le_pi {x y : β} (hxβ : -Ο < x.im) (hxβ : x.im β€ Ο)
(hyβ : - Ο < y.im) (hyβ : y.im β€ Ο) (hxy : exp x = exp y) : x = y :=
by rw [exp_eq_exp_re_mul_sin_add_cos, exp_eq_exp_re_mul_sin_add_cos y] at hxy;
exact complex.ext
(real.exp_injective $
by simpa [abs_mul, abs_cos_add_sin_mul_I] using congr_arg complex.abs hxy)
(by simpa [(of_real_exp _).symm, - of_real_exp, arg_real_mul _ (real.exp_pos _),
arg_cos_add_sin_mul_I hxβ hxβ, arg_cos_add_sin_mul_I hyβ hyβ] using congr_arg arg hxy)
lemma log_exp {x : β} (hxβ : -Ο < x.im) (hxβ: x.im β€ Ο) : log (exp x) = x :=
exp_inj_of_neg_pi_lt_of_le_pi
(by rw log_im; exact neg_pi_lt_arg _)
(by rw log_im; exact arg_le_pi _)
hxβ hxβ (by rw [exp_log (exp_ne_zero _)])
lemma of_real_log {x : β} (hx : 0 β€ x) : (x.log : β) = log x :=
complex.ext
(by rw [log_re, of_real_re, abs_of_nonneg hx])
(by rw [of_real_im, log_im, arg_of_real_of_nonneg hx])
lemma log_of_real_re (x : β) : (log (x : β)).re = real.log x := by simp [log_re]
@[simp] lemma log_zero : log 0 = 0 := by simp [log]
@[simp] lemma log_one : log 1 = 0 := by simp [log]
lemma log_neg_one : log (-1) = Ο * I := by simp [log]
lemma log_I : log I = Ο / 2 * I := by simp [log]
lemma log_neg_I : log (-I) = -(Ο / 2) * I := by simp [log]
lemma two_pi_I_ne_zero : (2 * Ο * I : β) β 0 :=
by norm_num [real.pi_ne_zero, I_ne_zero]
lemma exp_eq_one_iff {x : β} : exp x = 1 β β n : β€, x = n * ((2 * Ο) * I) :=
have real.exp (x.re) * real.cos (x.im) = 1 β real.cos x.im β -1,
from Ξ» hβ hβ, begin
rw [hβ, mul_neg_eq_neg_mul_symm, mul_one, neg_eq_iff_neg_eq] at hβ,
have := real.exp_pos x.re,
rw β hβ at this,
exact absurd this (by norm_num)
end,
calc exp x = 1 β (exp x).re = 1 β§ (exp x).im = 0 : by simp [complex.ext_iff]
... β real.cos x.im = 1 β§ real.sin x.im = 0 β§ x.re = 0 :
begin
rw exp_eq_exp_re_mul_sin_add_cos,
simp [complex.ext_iff, cos_of_real_re, sin_of_real_re, exp_of_real_re,
real.exp_ne_zero],
split; finish [real.sin_eq_zero_iff_cos_eq]
end
... β (β n : β€, βn * (2 * Ο) = x.im) β§ (β n : β€, βn * Ο = x.im) β§ x.re = 0 :
by rw [real.sin_eq_zero_iff, real.cos_eq_one_iff]
... β β n : β€, x = n * ((2 * Ο) * I) :
β¨Ξ» β¨β¨n, hnβ©, β¨m, hmβ©, hβ©, β¨n, by simp [complex.ext_iff, hn.symm, h]β©,
Ξ» β¨n, hnβ©, β¨β¨n, by simp [hn]β©, β¨2 * n, by simp [hn, mul_comm, mul_assoc, mul_left_comm]β©,
by simp [hn]β©β©
lemma exp_eq_exp_iff_exp_sub_eq_one {x y : β} : exp x = exp y β exp (x - y) = 1 :=
by rw [exp_sub, div_eq_one_iff_eq (exp_ne_zero _)]
lemma exp_eq_exp_iff_exists_int {x y : β} : exp x = exp y β β n : β€, x = y + n * ((2 * Ο) * I) :=
by simp only [exp_eq_exp_iff_exp_sub_eq_one, exp_eq_one_iff, sub_eq_iff_eq_add']
@[simp] lemma countable_preimage_exp {s : set β} : countable (exp β»ΒΉ' s) β countable s :=
begin
refine β¨Ξ» hs, _, Ξ» hs, _β©,
{ refine ((hs.image exp).insert 0).mono _,
rw [image_preimage_eq_inter_range, range_exp, β diff_eq, β union_singleton, diff_union_self],
exact subset_union_left _ _ },
{ rw β bUnion_preimage_singleton,
refine hs.bUnion (Ξ» z hz, _),
rcases em (β w, exp w = z) with β¨w, rflβ©|hne,
{ simp only [preimage, mem_singleton_iff, exp_eq_exp_iff_exists_int, set_of_exists],
exact countable_Union (Ξ» m, countable_singleton _) },
{ push_neg at hne, simp [preimage, hne] } }
end
alias countable_preimage_exp β _ set.countable.preimage_cexp
/-- `complex.exp` as a `local_homeomorph` with `source = {z | -Ο < im z < Ο}` and
`target = {z | 0 < re z} βͺ {z | im z β 0}`. This definition is used to prove that `complex.log`
is complex differentiable at all points but the negative real semi-axis. -/
def exp_local_homeomorph : local_homeomorph β β :=
local_homeomorph.of_continuous_open
{ to_fun := exp,
inv_fun := log,
source := {z : β | z.im β Ioo (- Ο) Ο},
target := {z : β | 0 < z.re} βͺ {z : β | z.im β 0},
map_source' :=
begin
rintro β¨x, yβ© β¨hβ : -Ο < y, hβ : y < Οβ©,
refine (not_or_of_imp $ Ξ» hz, _).symm,
obtain rfl : y = 0,
{ rw exp_im at hz,
simpa [(real.exp_pos _).ne', real.sin_eq_zero_iff_of_lt_of_lt hβ hβ] using hz },
rw [mem_set_of_eq, β of_real_def, exp_of_real_re],
exact real.exp_pos x
end,
map_target' := Ξ» z h,
suffices 0 β€ z.re β¨ z.im β 0,
by simpa [log_im, neg_pi_lt_arg, (arg_le_pi _).lt_iff_ne, arg_eq_pi_iff, not_and_distrib],
h.imp (Ξ» h, le_of_lt h) id,
left_inv' := Ξ» x hx, log_exp hx.1 (le_of_lt hx.2),
right_inv' := Ξ» x hx, exp_log $ by { rintro rfl, simpa [lt_irrefl] using hx } }
continuous_exp.continuous_on is_open_map_exp (is_open_Ioo.preimage continuous_im)
lemma has_strict_deriv_at_log {x : β} (h : 0 < x.re β¨ x.im β 0) :
has_strict_deriv_at log xβ»ΒΉ x :=
have h0 : x β 0, by { rintro rfl, simpa [lt_irrefl] using h },
exp_local_homeomorph.has_strict_deriv_at_symm h h0 $
by simpa [exp_log h0] using has_strict_deriv_at_exp (log x)
lemma has_strict_fderiv_at_log_real {x : β} (h : 0 < x.re β¨ x.im β 0) :
has_strict_fderiv_at log (xβ»ΒΉ β’ (1 : β βL[β] β)) x :=
(has_strict_deriv_at_log h).complex_to_real_fderiv
lemma times_cont_diff_at_log {x : β} (h : 0 < x.re β¨ x.im β 0) {n : with_top β} :
times_cont_diff_at β n log x :=
exp_local_homeomorph.times_cont_diff_at_symm_deriv (exp_ne_zero $ log x) h
(has_deriv_at_exp _) times_cont_diff_exp.times_cont_diff_at
lemma tendsto_log_nhds_within_im_neg_of_re_neg_of_im_zero
{z : β} (hre : z.re < 0) (him : z.im = 0) :
tendsto log (π[{z : β | z.im < 0}] z) (π $ real.log (abs z) - Ο * I) :=
begin
have := (continuous_of_real.continuous_at.comp_continuous_within_at
(continuous_abs.continuous_within_at.log _)).tendsto.add
(((continuous_of_real.tendsto _).comp $
tendsto_arg_nhds_within_im_neg_of_re_neg_of_im_zero hre him).mul tendsto_const_nhds),
convert this,
{ simp [sub_eq_add_neg] },
{ lift z to β using him, simpa using hre.ne }
end
lemma continuous_within_at_log_of_re_neg_of_im_zero
{z : β} (hre : z.re < 0) (him : z.im = 0) :
continuous_within_at log {z : β | 0 β€ z.im} z :=
begin
have := (continuous_of_real.continuous_at.comp_continuous_within_at
(continuous_abs.continuous_within_at.log _)).tendsto.add
((continuous_of_real.continuous_at.comp_continuous_within_at $
continuous_within_at_arg_of_re_neg_of_im_zero hre him).mul tendsto_const_nhds),
convert this,
{ lift z to β using him, simpa using hre.ne }
end
lemma tendsto_log_nhds_within_im_nonneg_of_re_neg_of_im_zero
{z : β} (hre : z.re < 0) (him : z.im = 0) :
tendsto log (π[{z : β | 0 β€ z.im}] z) (π $ real.log (abs z) + Ο * I) :=
by simpa only [log, arg_eq_pi_iff.2 β¨hre, himβ©]
using (continuous_within_at_log_of_re_neg_of_im_zero hre him).tendsto
end complex
section log_deriv
open complex filter
open_locale topological_space
variables {Ξ± : Type*}
lemma filter.tendsto.clog {l : filter Ξ±} {f : Ξ± β β} {x : β} (h : tendsto f l (π x))
(hx : 0 < x.re β¨ x.im β 0) :
tendsto (Ξ» t, log (f t)) l (π $ log x) :=
(has_strict_deriv_at_log hx).continuous_at.tendsto.comp h
variables [topological_space Ξ±]
lemma continuous_at.clog {f : Ξ± β β} {x : Ξ±} (hβ : continuous_at f x)
(hβ : 0 < (f x).re β¨ (f x).im β 0) :
continuous_at (Ξ» t, log (f t)) x :=
hβ.clog hβ
lemma continuous_within_at.clog {f : Ξ± β β} {s : set Ξ±} {x : Ξ±} (hβ : continuous_within_at f s x)
(hβ : 0 < (f x).re β¨ (f x).im β 0) :
continuous_within_at (Ξ» t, log (f t)) s x :=
hβ.clog hβ
lemma continuous_on.clog {f : Ξ± β β} {s : set Ξ±} (hβ : continuous_on f s)
(hβ : β x β s, 0 < (f x).re β¨ (f x).im β 0) :
continuous_on (Ξ» t, log (f t)) s :=
Ξ» x hx, (hβ x hx).clog (hβ x hx)
lemma continuous.clog {f : Ξ± β β} (hβ : continuous f) (hβ : β x, 0 < (f x).re β¨ (f x).im β 0) :
continuous (Ξ» t, log (f t)) :=
continuous_iff_continuous_at.2 $ Ξ» x, hβ.continuous_at.clog (hβ x)
variables {E : Type*} [normed_group E] [normed_space β E]
lemma has_strict_fderiv_at.clog {f : E β β} {f' : E βL[β] β} {x : E}
(hβ : has_strict_fderiv_at f f' x) (hβ : 0 < (f x).re β¨ (f x).im β 0) :
has_strict_fderiv_at (Ξ» t, log (f t)) ((f x)β»ΒΉ β’ f') x :=
(has_strict_deriv_at_log hβ).comp_has_strict_fderiv_at x hβ
lemma has_strict_deriv_at.clog {f : β β β} {f' x : β} (hβ : has_strict_deriv_at f f' x)
(hβ : 0 < (f x).re β¨ (f x).im β 0) :
has_strict_deriv_at (Ξ» t, log (f t)) (f' / f x) x :=
by { rw div_eq_inv_mul, exact (has_strict_deriv_at_log hβ).comp x hβ }
lemma has_strict_deriv_at.clog_real {f : β β β} {x : β} {f' : β} (hβ : has_strict_deriv_at f f' x)
(hβ : 0 < (f x).re β¨ (f x).im β 0) :
has_strict_deriv_at (Ξ» t, log (f t)) (f' / f x) x :=
by simpa only [div_eq_inv_mul]
using (has_strict_fderiv_at_log_real hβ).comp_has_strict_deriv_at x hβ
lemma has_fderiv_at.clog {f : E β β} {f' : E βL[β] β} {x : E}
(hβ : has_fderiv_at f f' x) (hβ : 0 < (f x).re β¨ (f x).im β 0) :
has_fderiv_at (Ξ» t, log (f t)) ((f x)β»ΒΉ β’ f') x :=
(has_strict_deriv_at_log hβ).has_deriv_at.comp_has_fderiv_at x hβ
lemma has_deriv_at.clog {f : β β β} {f' x : β} (hβ : has_deriv_at f f' x)
(hβ : 0 < (f x).re β¨ (f x).im β 0) :
has_deriv_at (Ξ» t, log (f t)) (f' / f x) x :=
by { rw div_eq_inv_mul, exact (has_strict_deriv_at_log hβ).has_deriv_at.comp x hβ }
lemma has_deriv_at.clog_real {f : β β β} {x : β} {f' : β} (hβ : has_deriv_at f f' x)
(hβ : 0 < (f x).re β¨ (f x).im β 0) :
has_deriv_at (Ξ» t, log (f t)) (f' / f x) x :=
by simpa only [div_eq_inv_mul]
using (has_strict_fderiv_at_log_real hβ).has_fderiv_at.comp_has_deriv_at x hβ
lemma differentiable_at.clog {f : E β β} {x : E} (hβ : differentiable_at β f x)
(hβ : 0 < (f x).re β¨ (f x).im β 0) :
differentiable_at β (Ξ» t, log (f t)) x :=
(hβ.has_fderiv_at.clog hβ).differentiable_at
lemma has_fderiv_within_at.clog {f : E β β} {f' : E βL[β] β} {s : set E} {x : E}
(hβ : has_fderiv_within_at f f' s x) (hβ : 0 < (f x).re β¨ (f x).im β 0) :
has_fderiv_within_at (Ξ» t, log (f t)) ((f x)β»ΒΉ β’ f') s x :=
(has_strict_deriv_at_log hβ).has_deriv_at.comp_has_fderiv_within_at x hβ
lemma has_deriv_within_at.clog {f : β β β} {f' x : β} {s : set β}
(hβ : has_deriv_within_at f f' s x) (hβ : 0 < (f x).re β¨ (f x).im β 0) :
has_deriv_within_at (Ξ» t, log (f t)) (f' / f x) s x :=
by { rw div_eq_inv_mul,
exact (has_strict_deriv_at_log hβ).has_deriv_at.comp_has_deriv_within_at x hβ }
lemma has_deriv_within_at.clog_real {f : β β β} {s : set β} {x : β} {f' : β}
(hβ : has_deriv_within_at f f' s x) (hβ : 0 < (f x).re β¨ (f x).im β 0) :
has_deriv_within_at (Ξ» t, log (f t)) (f' / f x) s x :=
by simpa only [div_eq_inv_mul]
using (has_strict_fderiv_at_log_real hβ).has_fderiv_at.comp_has_deriv_within_at x hβ
lemma differentiable_within_at.clog {f : E β β} {s : set E} {x : E}
(hβ : differentiable_within_at β f s x) (hβ : 0 < (f x).re β¨ (f x).im β 0) :
differentiable_within_at β (Ξ» t, log (f t)) s x :=
(hβ.has_fderiv_within_at.clog hβ).differentiable_within_at
lemma differentiable_on.clog {f : E β β} {s : set E}
(hβ : differentiable_on β f s) (hβ : β x β s, 0 < (f x).re β¨ (f x).im β 0) :
differentiable_on β (Ξ» t, log (f t)) s :=
Ξ» x hx, (hβ x hx).clog (hβ x hx)
lemma differentiable.clog {f : E β β} (hβ : differentiable β f)
(hβ : β x, 0 < (f x).re β¨ (f x).im β 0) :
differentiable β (Ξ» t, log (f t)) :=
Ξ» x, (hβ x).clog (hβ x)
end log_deriv
|
910f063333650023649df4f30acf76093f0ecc8c | 88fb7558b0636ec6b181f2a548ac11ad3919f8a5 | /tests/lean/1207.lean | c7836765ec63a79c309b7fae2e693ee75d8bcdbb | [
"Apache-2.0"
] | permissive | moritayasuaki/lean | 9f666c323cb6fa1f31ac597d777914aed41e3b7a | ae96ebf6ee953088c235ff7ae0e8c95066ba8001 | refs/heads/master | 1,611,135,440,814 | 1,493,852,869,000 | 1,493,852,869,000 | 90,269,903 | 0 | 0 | null | 1,493,906,291,000 | 1,493,906,291,000 | null | UTF-8 | Lean | false | false | 480 | lean | example : true :=
begin
assertv H : true := (by trivial),
exact H
end
example : true :=
begin
assertv H : true := (by tactic.triv),
exact H
end
meta example (h : tactic unit) : true :=
begin
h, -- ERROR h should not be visible here
trivial
end
example : false :=
begin
assertv H : true := (by foo), -- ERROR
exact sorry
end
constant P : Prop
example (p : P) : true :=
begin
assertv H : P := by do { p β tactic.get_local `p, tactic.exact p },
trivial
end
|
7f3eae5ab8ad92a0fb6f00f16e194692ef852de6 | 74addaa0e41490cbaf2abd313a764c96df57b05d | /Mathlib/data/quaternion_auto.lean | a9d8d4699863ea3e084afff0d2d44f83c1c97164 | [] | 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 | 32,551 | lean | /-
Copyright (c) 2020 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.tactic.ring_exp
import Mathlib.algebra.algebra.basic
import Mathlib.algebra.opposites
import Mathlib.data.equiv.ring
import Mathlib.PostPort
universes u_1 l
namespace Mathlib
/-!
# Quaternions
In this file we define quaternions `β[R]` over a commutative ring `R`, and define some
algebraic structures on `β[R]`.
## Main definitions
* `quaternion_algebra R a b`, `β[R, a, b]` :
[quaternion algebra](https://en.wikipedia.org/wiki/Quaternion_algebra) with coefficients `a`, `b`
* `quaternion R`, `β[R]` : the space of quaternions, a.k.a. `quaternion_algebra R (-1) (-1)`;
* `quaternion.norm_sq` : square of the norm of a quaternion;
* `quaternion.conj` : conjugate of a quaternion;
We also define the following algebraic structures on `β[R]`:
* `ring β[R, a, b]` and `algebra R β[R, a, b]` : for any commutative ring `R`;
* `ring β[R]` and `algebra R β[R]` : for any commutative ring `R`;
* `domain β[R]` : for a linear ordered commutative ring `R`;
* `division_algebra β[R]` : for a linear ordered field `R`.
## Notation
The following notation is available with `open_locale quaternion`.
* `β[R, cβ, cβ]` : `quaternion_algebra R cβ cβ`
* `β[R]` : quaternions over `R`.
## Implementation notes
We define quaternions over any ring `R`, not just `β` to be able to deal with, e.g., integer
or rational quaternions without using real numbers. In particular, all definitions in this file
are computable.
## Tags
quaternion
-/
/-- Quaternion algebra over a type with fixed coefficients $a=i^2$ and $b=j^2$.
Implemented as a structure with four fields: `re`, `im_i`, `im_j`, and `im_k`. -/
structure quaternion_algebra (R : Type u_1) (a : R) (b : R) where
re : R
im_i : R
im_j : R
im_k : R
namespace quaternion_algebra
@[simp] theorem mk.eta {R : Type u_1} {cβ : R} {cβ : R} (a : quaternion_algebra R cβ cβ) :
mk (re a) (im_i a) (im_j a) (im_k a) = a :=
sorry
protected instance has_coe_t {R : Type u_1} [comm_ring R] {cβ : R} {cβ : R} :
has_coe_t R (quaternion_algebra R cβ cβ) :=
has_coe_t.mk fun (x : R) => mk x 0 0 0
@[simp] theorem coe_re {R : Type u_1} [comm_ring R] {cβ : R} {cβ : R} (x : R) : re βx = x := rfl
@[simp] theorem coe_im_i {R : Type u_1} [comm_ring R] {cβ : R} {cβ : R} (x : R) : im_i βx = 0 := rfl
@[simp] theorem coe_im_j {R : Type u_1} [comm_ring R] {cβ : R} {cβ : R} (x : R) : im_j βx = 0 := rfl
@[simp] theorem coe_im_k {R : Type u_1} [comm_ring R] {cβ : R} {cβ : R} (x : R) : im_k βx = 0 := rfl
theorem coe_injective {R : Type u_1} [comm_ring R] {cβ : R} {cβ : R} : function.injective coe :=
fun (x y : R) (h : βx = βy) => congr_arg re h
@[simp] theorem coe_inj {R : Type u_1} [comm_ring R] {cβ : R} {cβ : R} {x : R} {y : R} :
βx = βy β x = y :=
function.injective.eq_iff coe_injective
@[simp] theorem has_zero_zero_im_j {R : Type u_1} [comm_ring R] {cβ : R} {cβ : R} : im_j 0 = 0 :=
Eq.refl (im_j 0)
@[simp] theorem coe_zero {R : Type u_1} [comm_ring R] {cβ : R} {cβ : R} : β0 = 0 := rfl
protected instance inhabited {R : Type u_1} [comm_ring R] {cβ : R} {cβ : R} :
Inhabited (quaternion_algebra R cβ cβ) :=
{ default := 0 }
@[simp] theorem has_one_one_re {R : Type u_1} [comm_ring R] {cβ : R} {cβ : R} : re 1 = 1 :=
Eq.refl (re 1)
@[simp] theorem coe_one {R : Type u_1} [comm_ring R] {cβ : R} {cβ : R} : β1 = 1 := rfl
@[simp] theorem has_add_add_im_i {R : Type u_1} [comm_ring R] {cβ : R} {cβ : R}
(a : quaternion_algebra R cβ cβ) (b : quaternion_algebra R cβ cβ) :
im_i (a + b) = im_i a + im_i b :=
Eq.refl (im_i (a + b))
@[simp] theorem mk_add_mk {R : Type u_1} [comm_ring R] {cβ : R} {cβ : R} (aβ : R) (aβ : R) (aβ : R)
(aβ : R) (bβ : R) (bβ : R) (bβ : R) (bβ : R) :
mk aβ aβ aβ aβ + mk bβ bβ bβ bβ = mk (aβ + bβ) (aβ + bβ) (aβ + bβ) (aβ + bβ) :=
rfl
protected instance has_neg {R : Type u_1} [comm_ring R] {cβ : R} {cβ : R} :
Neg (quaternion_algebra R cβ cβ) :=
{ neg := fun (a : quaternion_algebra R cβ cβ) => mk (-re a) (-im_i a) (-im_j a) (-im_k a) }
@[simp] theorem neg_mk {R : Type u_1} [comm_ring R] {cβ : R} {cβ : R} (aβ : R) (aβ : R) (aβ : R)
(aβ : R) : -mk aβ aβ aβ aβ = mk (-aβ) (-aβ) (-aβ) (-aβ) :=
rfl
@[simp] theorem has_sub_sub_im_k {R : Type u_1} [comm_ring R] {cβ : R} {cβ : R}
(a : quaternion_algebra R cβ cβ) (b : quaternion_algebra R cβ cβ) :
im_k (a - b) = im_k a - im_k b :=
Eq.refl (im_k (a - b))
@[simp] theorem mk_sub_mk {R : Type u_1} [comm_ring R] {cβ : R} {cβ : R} (aβ : R) (aβ : R) (aβ : R)
(aβ : R) (bβ : R) (bβ : R) (bβ : R) (bβ : R) :
mk aβ aβ aβ aβ - mk bβ bβ bβ bβ = mk (aβ - bβ) (aβ - bβ) (aβ - bβ) (aβ - bβ) :=
rfl
/-- Multiplication is given by
* `1 * x = x * 1 = x`;
* `i * i = cβ`;
* `j * j = cβ`;
* `i * j = k`, `j * i = -k`;
* `k * k = -cβ * cβ`;
* `i * k = cβ * j`, `k * i = `-cβ * j`;
* `j * k = -cβ * i`, `k * j = cβ * i`. -/
@[simp] theorem has_mul_mul_im_i {R : Type u_1} [comm_ring R] {cβ : R} {cβ : R}
(a : quaternion_algebra R cβ cβ) (b : quaternion_algebra R cβ cβ) :
im_i (a * b) = re a * im_i b + im_i a * re b - cβ * im_j a * im_k b + cβ * im_k a * im_j b :=
Eq.refl (im_i (a * b))
@[simp] theorem mk_mul_mk {R : Type u_1} [comm_ring R] {cβ : R} {cβ : R} (aβ : R) (aβ : R) (aβ : R)
(aβ : R) (bβ : R) (bβ : R) (bβ : R) (bβ : R) :
mk aβ aβ aβ aβ * mk bβ bβ bβ bβ =
mk (aβ * bβ + cβ * aβ * bβ + cβ * aβ * bβ - cβ * cβ * aβ * bβ)
(aβ * bβ + aβ * bβ - cβ * aβ * bβ + cβ * aβ * bβ)
(aβ * bβ + cβ * aβ * bβ + aβ * bβ - cβ * aβ * bβ)
(aβ * bβ + aβ * bβ - aβ * bβ + aβ * bβ) :=
rfl
protected instance ring {R : Type u_1} [comm_ring R] {cβ : R} {cβ : R} :
ring (quaternion_algebra R cβ cβ) :=
ring.mk Add.add sorry 0 sorry sorry Neg.neg Sub.sub sorry sorry Mul.mul sorry 1 sorry sorry sorry
sorry
protected instance algebra {R : Type u_1} [comm_ring R] {cβ : R} {cβ : R} :
algebra R (quaternion_algebra R cβ cβ) :=
algebra.mk (ring_hom.mk coe sorry sorry sorry sorry) sorry sorry
@[simp] theorem smul_re {R : Type u_1} [comm_ring R] {cβ : R} {cβ : R} (r : R)
(a : quaternion_algebra R cβ cβ) : re (r β’ a) = r β’ re a :=
rfl
@[simp] theorem smul_im_i {R : Type u_1} [comm_ring R] {cβ : R} {cβ : R} (r : R)
(a : quaternion_algebra R cβ cβ) : im_i (r β’ a) = r β’ im_i a :=
rfl
@[simp] theorem smul_im_j {R : Type u_1} [comm_ring R] {cβ : R} {cβ : R} (r : R)
(a : quaternion_algebra R cβ cβ) : im_j (r β’ a) = r β’ im_j a :=
rfl
@[simp] theorem smul_im_k {R : Type u_1} [comm_ring R] {cβ : R} {cβ : R} (r : R)
(a : quaternion_algebra R cβ cβ) : im_k (r β’ a) = r β’ im_k a :=
rfl
@[simp] theorem coe_add {R : Type u_1} [comm_ring R] {cβ : R} {cβ : R} (x : R) (y : R) :
β(x + y) = βx + βy :=
ring_hom.map_add (algebra_map R (quaternion_algebra R cβ cβ)) x y
@[simp] theorem coe_sub {R : Type u_1} [comm_ring R] {cβ : R} {cβ : R} (x : R) (y : R) :
β(x - y) = βx - βy :=
ring_hom.map_sub (algebra_map R (quaternion_algebra R cβ cβ)) x y
@[simp] theorem coe_neg {R : Type u_1} [comm_ring R] {cβ : R} {cβ : R} (x : R) : β(-x) = -βx :=
ring_hom.map_neg (algebra_map R (quaternion_algebra R cβ cβ)) x
@[simp] theorem coe_mul {R : Type u_1} [comm_ring R] {cβ : R} {cβ : R} (x : R) (y : R) :
β(x * y) = βx * βy :=
ring_hom.map_mul (algebra_map R (quaternion_algebra R cβ cβ)) x y
theorem coe_commutes {R : Type u_1} [comm_ring R] {cβ : R} {cβ : R} (r : R)
(a : quaternion_algebra R cβ cβ) : βr * a = a * βr :=
algebra.commutes r a
theorem coe_commute {R : Type u_1} [comm_ring R] {cβ : R} {cβ : R} (r : R)
(a : quaternion_algebra R cβ cβ) : commute (βr) a :=
coe_commutes r a
theorem coe_mul_eq_smul {R : Type u_1} [comm_ring R] {cβ : R} {cβ : R} (r : R)
(a : quaternion_algebra R cβ cβ) : βr * a = r β’ a :=
Eq.symm (algebra.smul_def r a)
theorem mul_coe_eq_smul {R : Type u_1} [comm_ring R] {cβ : R} {cβ : R} (r : R)
(a : quaternion_algebra R cβ cβ) : a * βr = r β’ a :=
eq.mpr (id (Eq._oldrec (Eq.refl (a * βr = r β’ a)) (Eq.symm (coe_commutes r a))))
(eq.mpr (id (Eq._oldrec (Eq.refl (βr * a = r β’ a)) (coe_mul_eq_smul r a))) (Eq.refl (r β’ a)))
@[simp] theorem coe_algebra_map {R : Type u_1} [comm_ring R] {cβ : R} {cβ : R} :
β(algebra_map R (quaternion_algebra R cβ cβ)) = coe :=
rfl
theorem smul_coe {R : Type u_1} [comm_ring R] {cβ : R} {cβ : R} (x : R) (y : R) :
x β’ βy = β(x * y) :=
eq.mpr (id (Eq._oldrec (Eq.refl (x β’ βy = β(x * y))) (coe_mul x y)))
(eq.mpr (id (Eq._oldrec (Eq.refl (x β’ βy = βx * βy)) (coe_mul_eq_smul x βy)))
(Eq.refl (x β’ βy)))
/-- Quaternion conjugate. -/
def conj {R : Type u_1} [comm_ring R] {cβ : R} {cβ : R} :
linear_equiv R (quaternion_algebra R cβ cβ) (quaternion_algebra R cβ cβ) :=
linear_equiv.of_involutive
(linear_map.mk (fun (a : quaternion_algebra R cβ cβ) => mk (re a) (-im_i a) (-im_j a) (-im_k a))
sorry sorry)
sorry
@[simp] theorem re_conj {R : Type u_1} [comm_ring R] {cβ : R} {cβ : R}
(a : quaternion_algebra R cβ cβ) : re (coe_fn conj a) = re a :=
rfl
@[simp] theorem im_i_conj {R : Type u_1} [comm_ring R] {cβ : R} {cβ : R}
(a : quaternion_algebra R cβ cβ) : im_i (coe_fn conj a) = -im_i a :=
rfl
@[simp] theorem im_j_conj {R : Type u_1} [comm_ring R] {cβ : R} {cβ : R}
(a : quaternion_algebra R cβ cβ) : im_j (coe_fn conj a) = -im_j a :=
rfl
@[simp] theorem im_k_conj {R : Type u_1} [comm_ring R] {cβ : R} {cβ : R}
(a : quaternion_algebra R cβ cβ) : im_k (coe_fn conj a) = -im_k a :=
rfl
@[simp] theorem conj_conj {R : Type u_1} [comm_ring R] {cβ : R} {cβ : R}
(a : quaternion_algebra R cβ cβ) : coe_fn conj (coe_fn conj a) = a :=
ext (coe_fn conj (coe_fn conj a)) a rfl (neg_neg (im_i a)) (neg_neg (im_j a)) (neg_neg (im_k a))
theorem conj_add {R : Type u_1} [comm_ring R] {cβ : R} {cβ : R} (a : quaternion_algebra R cβ cβ)
(b : quaternion_algebra R cβ cβ) : coe_fn conj (a + b) = coe_fn conj a + coe_fn conj b :=
linear_equiv.map_add conj a b
@[simp] theorem conj_mul {R : Type u_1} [comm_ring R] {cβ : R} {cβ : R}
(a : quaternion_algebra R cβ cβ) (b : quaternion_algebra R cβ cβ) :
coe_fn conj (a * b) = coe_fn conj b * coe_fn conj a :=
sorry
theorem conj_conj_mul {R : Type u_1} [comm_ring R] {cβ : R} {cβ : R}
(a : quaternion_algebra R cβ cβ) (b : quaternion_algebra R cβ cβ) :
coe_fn conj (coe_fn conj a * b) = coe_fn conj b * a :=
eq.mpr
(id
(Eq._oldrec (Eq.refl (coe_fn conj (coe_fn conj a * b) = coe_fn conj b * a))
(conj_mul (coe_fn conj a) b)))
(eq.mpr
(id
(Eq._oldrec (Eq.refl (coe_fn conj b * coe_fn conj (coe_fn conj a) = coe_fn conj b * a))
(conj_conj a)))
(Eq.refl (coe_fn conj b * a)))
theorem conj_mul_conj {R : Type u_1} [comm_ring R] {cβ : R} {cβ : R}
(a : quaternion_algebra R cβ cβ) (b : quaternion_algebra R cβ cβ) :
coe_fn conj (a * coe_fn conj b) = b * coe_fn conj a :=
eq.mpr
(id
(Eq._oldrec (Eq.refl (coe_fn conj (a * coe_fn conj b) = b * coe_fn conj a))
(conj_mul a (coe_fn conj b))))
(eq.mpr
(id
(Eq._oldrec (Eq.refl (coe_fn conj (coe_fn conj b) * coe_fn conj a = b * coe_fn conj a))
(conj_conj b)))
(Eq.refl (b * coe_fn conj a)))
theorem self_add_conj' {R : Type u_1} [comm_ring R] {cβ : R} {cβ : R}
(a : quaternion_algebra R cβ cβ) : a + coe_fn conj a = β(bit0 1 * re a) :=
sorry
theorem self_add_conj {R : Type u_1} [comm_ring R] {cβ : R} {cβ : R}
(a : quaternion_algebra R cβ cβ) : a + coe_fn conj a = bit0 1 * β(re a) :=
sorry
theorem conj_add_self' {R : Type u_1} [comm_ring R] {cβ : R} {cβ : R}
(a : quaternion_algebra R cβ cβ) : coe_fn conj a + a = β(bit0 1 * re a) :=
eq.mpr
(id (Eq._oldrec (Eq.refl (coe_fn conj a + a = β(bit0 1 * re a))) (add_comm (coe_fn conj a) a)))
(eq.mpr (id (Eq._oldrec (Eq.refl (a + coe_fn conj a = β(bit0 1 * re a))) (self_add_conj' a)))
(Eq.refl β(bit0 1 * re a)))
theorem conj_add_self {R : Type u_1} [comm_ring R] {cβ : R} {cβ : R}
(a : quaternion_algebra R cβ cβ) : coe_fn conj a + a = bit0 1 * β(re a) :=
eq.mpr
(id (Eq._oldrec (Eq.refl (coe_fn conj a + a = bit0 1 * β(re a))) (add_comm (coe_fn conj a) a)))
(eq.mpr (id (Eq._oldrec (Eq.refl (a + coe_fn conj a = bit0 1 * β(re a))) (self_add_conj a)))
(Eq.refl (bit0 1 * β(re a))))
theorem conj_eq_two_re_sub {R : Type u_1} [comm_ring R] {cβ : R} {cβ : R}
(a : quaternion_algebra R cβ cβ) : coe_fn conj a = β(bit0 1 * re a) - a :=
iff.mpr eq_sub_iff_add_eq (conj_add_self' a)
theorem commute_conj_self {R : Type u_1} [comm_ring R] {cβ : R} {cβ : R}
(a : quaternion_algebra R cβ cβ) : commute (coe_fn conj a) a :=
eq.mpr (id (Eq._oldrec (Eq.refl (commute (coe_fn conj a) a)) (conj_eq_two_re_sub a)))
(commute.sub_left (coe_commute (bit0 1 * re a) a) (commute.refl a))
theorem commute_self_conj {R : Type u_1} [comm_ring R] {cβ : R} {cβ : R}
(a : quaternion_algebra R cβ cβ) : commute a (coe_fn conj a) :=
commute.symm (commute_conj_self a)
theorem commute_conj_conj {R : Type u_1} [comm_ring R] {cβ : R} {cβ : R}
{a : quaternion_algebra R cβ cβ} {b : quaternion_algebra R cβ cβ} (h : commute a b) :
commute (coe_fn conj a) (coe_fn conj b) :=
sorry
@[simp] theorem conj_coe {R : Type u_1} [comm_ring R] {cβ : R} {cβ : R} (x : R) :
coe_fn conj βx = βx :=
sorry
theorem conj_smul {R : Type u_1} [comm_ring R] {cβ : R} {cβ : R} (r : R)
(a : quaternion_algebra R cβ cβ) : coe_fn conj (r β’ a) = r β’ coe_fn conj a :=
linear_equiv.map_smul conj r a
@[simp] theorem conj_one {R : Type u_1} [comm_ring R] {cβ : R} {cβ : R} : coe_fn conj 1 = 1 :=
conj_coe 1
theorem eq_re_of_eq_coe {R : Type u_1} [comm_ring R] {cβ : R} {cβ : R}
{a : quaternion_algebra R cβ cβ} {x : R} (h : a = βx) : a = β(re a) :=
eq.mpr (id (Eq._oldrec (Eq.refl (a = β(re a))) h))
(eq.mpr (id (Eq._oldrec (Eq.refl (βx = β(re βx))) (coe_re x))) (Eq.refl βx))
theorem eq_re_iff_mem_range_coe {R : Type u_1} [comm_ring R] {cβ : R} {cβ : R}
{a : quaternion_algebra R cβ cβ} : a = β(re a) β a β set.range coe :=
sorry
@[simp] theorem conj_fixed {R : Type u_1} [comm_ring R] [no_zero_divisors R] [char_zero R] {cβ : R}
{cβ : R} {a : quaternion_algebra R cβ cβ} : coe_fn conj a = a β a = β(re a) :=
sorry
-- Can't use `rw β conj_fixed` in the proof without additional assumptions
theorem conj_mul_eq_coe {R : Type u_1} [comm_ring R] {cβ : R} {cβ : R}
(a : quaternion_algebra R cβ cβ) : coe_fn conj a * a = β(re (coe_fn conj a * a)) :=
sorry
theorem mul_conj_eq_coe {R : Type u_1} [comm_ring R] {cβ : R} {cβ : R}
(a : quaternion_algebra R cβ cβ) : a * coe_fn conj a = β(re (a * coe_fn conj a)) :=
eq.mpr
(id
(Eq._oldrec (Eq.refl (a * coe_fn conj a = β(re (a * coe_fn conj a))))
(commute.eq (commute_self_conj a))))
(conj_mul_eq_coe a)
theorem conj_zero {R : Type u_1} [comm_ring R] {cβ : R} {cβ : R} : coe_fn conj 0 = 0 :=
linear_equiv.map_zero conj
theorem conj_neg {R : Type u_1} [comm_ring R] {cβ : R} {cβ : R} (a : quaternion_algebra R cβ cβ) :
coe_fn conj (-a) = -coe_fn conj a :=
linear_equiv.map_neg conj a
theorem conj_sub {R : Type u_1} [comm_ring R] {cβ : R} {cβ : R} (a : quaternion_algebra R cβ cβ)
(b : quaternion_algebra R cβ cβ) : coe_fn conj (a - b) = coe_fn conj a - coe_fn conj b :=
linear_equiv.map_sub conj a b
protected instance star_ring {R : Type u_1} [comm_ring R] {cβ : R} {cβ : R} :
star_ring (quaternion_algebra R cβ cβ) :=
star_ring.mk conj_add
@[simp] theorem star_def {R : Type u_1} [comm_ring R] {cβ : R} {cβ : R}
(a : quaternion_algebra R cβ cβ) : star a = coe_fn conj a :=
rfl
/-- Quaternion conjugate as an `alg_equiv` to the opposite ring. -/
def conj_alg_equiv {R : Type u_1} [comm_ring R] {cβ : R} {cβ : R} :
alg_equiv R (quaternion_algebra R cβ cβ) (quaternion_algebra R cβ cβα΅α΅) :=
alg_equiv.mk (opposite.op β βconj) (βconj β opposite.unop) sorry sorry sorry sorry sorry
@[simp] theorem coe_conj_alg_equiv {R : Type u_1} [comm_ring R] {cβ : R} {cβ : R} :
βconj_alg_equiv = opposite.op β βconj :=
rfl
end quaternion_algebra
/-- Space of quaternions over a type. Implemented as a structure with four fields:
`re`, `im_i`, `im_j`, and `im_k`. -/
def quaternion (R : Type u_1) [HasOne R] [Neg R] := quaternion_algebra R (-1) (-1)
namespace quaternion
protected instance has_coe_t {R : Type u_1} [comm_ring R] : has_coe_t R (quaternion R) :=
quaternion_algebra.has_coe_t
protected instance ring {R : Type u_1} [comm_ring R] : ring (quaternion R) :=
quaternion_algebra.ring
protected instance inhabited {R : Type u_1} [comm_ring R] : Inhabited (quaternion R) :=
quaternion_algebra.inhabited
protected instance algebra {R : Type u_1} [comm_ring R] : algebra R (quaternion R) :=
quaternion_algebra.algebra
protected instance star_ring {R : Type u_1} [comm_ring R] : star_ring (quaternion R) :=
quaternion_algebra.star_ring
theorem ext {R : Type u_1} [comm_ring R] (a : quaternion R) (b : quaternion R) :
re a = re b β im_i a = im_i b β im_j a = im_j b β im_k a = im_k b β a = b :=
quaternion_algebra.ext a b
theorem ext_iff {R : Type u_1} [comm_ring R] {a : quaternion R} {b : quaternion R} :
a = b β re a = re b β§ im_i a = im_i b β§ im_j a = im_j b β§ im_k a = im_k b :=
quaternion_algebra.ext_iff a b
@[simp] theorem coe_re {R : Type u_1} [comm_ring R] (x : R) : re βx = x := rfl
@[simp] theorem coe_im_i {R : Type u_1} [comm_ring R] (x : R) : im_i βx = 0 := rfl
@[simp] theorem coe_im_j {R : Type u_1} [comm_ring R] (x : R) : im_j βx = 0 := rfl
@[simp] theorem coe_im_k {R : Type u_1} [comm_ring R] (x : R) : im_k βx = 0 := rfl
@[simp] theorem zero_re {R : Type u_1} [comm_ring R] : re 0 = 0 := rfl
@[simp] theorem zero_im_i {R : Type u_1} [comm_ring R] : im_i 0 = 0 := rfl
@[simp] theorem zero_im_j {R : Type u_1} [comm_ring R] : im_j 0 = 0 := rfl
@[simp] theorem zero_im_k {R : Type u_1} [comm_ring R] : im_k 0 = 0 := rfl
@[simp] theorem coe_zero {R : Type u_1} [comm_ring R] : β0 = 0 := rfl
@[simp] theorem one_re {R : Type u_1} [comm_ring R] : re 1 = 1 := rfl
@[simp] theorem one_im_i {R : Type u_1} [comm_ring R] : im_i 1 = 0 := rfl
@[simp] theorem one_im_j {R : Type u_1} [comm_ring R] : im_j 1 = 0 := rfl
@[simp] theorem one_im_k {R : Type u_1} [comm_ring R] : im_k 1 = 0 := rfl
@[simp] theorem coe_one {R : Type u_1} [comm_ring R] : β1 = 1 := rfl
@[simp] theorem add_re {R : Type u_1} [comm_ring R] (a : quaternion R) (b : quaternion R) :
re (a + b) = re a + re b :=
rfl
@[simp] theorem add_im_i {R : Type u_1} [comm_ring R] (a : quaternion R) (b : quaternion R) :
im_i (a + b) = im_i a + im_i b :=
rfl
@[simp] theorem add_im_j {R : Type u_1} [comm_ring R] (a : quaternion R) (b : quaternion R) :
im_j (a + b) = im_j a + im_j b :=
rfl
@[simp] theorem add_im_k {R : Type u_1} [comm_ring R] (a : quaternion R) (b : quaternion R) :
im_k (a + b) = im_k a + im_k b :=
rfl
@[simp] theorem coe_add {R : Type u_1} [comm_ring R] (x : R) (y : R) : β(x + y) = βx + βy :=
quaternion_algebra.coe_add x y
@[simp] theorem neg_re {R : Type u_1} [comm_ring R] (a : quaternion R) : re (-a) = -re a := rfl
@[simp] theorem neg_im_i {R : Type u_1} [comm_ring R] (a : quaternion R) : im_i (-a) = -im_i a :=
rfl
@[simp] theorem neg_im_j {R : Type u_1} [comm_ring R] (a : quaternion R) : im_j (-a) = -im_j a :=
rfl
@[simp] theorem neg_im_k {R : Type u_1} [comm_ring R] (a : quaternion R) : im_k (-a) = -im_k a :=
rfl
@[simp] theorem coe_neg {R : Type u_1} [comm_ring R] (x : R) : β(-x) = -βx :=
quaternion_algebra.coe_neg x
@[simp] theorem sub_re {R : Type u_1} [comm_ring R] (a : quaternion R) (b : quaternion R) :
re (a - b) = re a - re b :=
rfl
@[simp] theorem sub_im_i {R : Type u_1} [comm_ring R] (a : quaternion R) (b : quaternion R) :
im_i (a - b) = im_i a - im_i b :=
rfl
@[simp] theorem sub_im_j {R : Type u_1} [comm_ring R] (a : quaternion R) (b : quaternion R) :
im_j (a - b) = im_j a - im_j b :=
rfl
@[simp] theorem sub_im_k {R : Type u_1} [comm_ring R] (a : quaternion R) (b : quaternion R) :
im_k (a - b) = im_k a - im_k b :=
rfl
@[simp] theorem coe_sub {R : Type u_1} [comm_ring R] (x : R) (y : R) : β(x - y) = βx - βy :=
quaternion_algebra.coe_sub x y
@[simp] theorem mul_re {R : Type u_1} [comm_ring R] (a : quaternion R) (b : quaternion R) :
re (a * b) = re a * re b - im_i a * im_i b - im_j a * im_j b - im_k a * im_k b :=
sorry
@[simp] theorem mul_im_i {R : Type u_1} [comm_ring R] (a : quaternion R) (b : quaternion R) :
im_i (a * b) = re a * im_i b + im_i a * re b + im_j a * im_k b - im_k a * im_j b :=
sorry
@[simp] theorem mul_im_j {R : Type u_1} [comm_ring R] (a : quaternion R) (b : quaternion R) :
im_j (a * b) = re a * im_j b - im_i a * im_k b + im_j a * re b + im_k a * im_i b :=
sorry
@[simp] theorem mul_im_k {R : Type u_1} [comm_ring R] (a : quaternion R) (b : quaternion R) :
im_k (a * b) = re a * im_k b + im_i a * im_j b - im_j a * im_i b + im_k a * re b :=
sorry
@[simp] theorem coe_mul {R : Type u_1} [comm_ring R] (x : R) (y : R) : β(x * y) = βx * βy :=
quaternion_algebra.coe_mul x y
theorem coe_injective {R : Type u_1} [comm_ring R] : function.injective coe :=
quaternion_algebra.coe_injective
@[simp] theorem coe_inj {R : Type u_1} [comm_ring R] {x : R} {y : R} : βx = βy β x = y :=
function.injective.eq_iff coe_injective
@[simp] theorem smul_re {R : Type u_1} [comm_ring R] (r : R) (a : quaternion R) :
re (r β’ a) = r β’ re a :=
rfl
@[simp] theorem smul_im_i {R : Type u_1} [comm_ring R] (r : R) (a : quaternion R) :
im_i (r β’ a) = r β’ im_i a :=
rfl
@[simp] theorem smul_im_j {R : Type u_1} [comm_ring R] (r : R) (a : quaternion R) :
im_j (r β’ a) = r β’ im_j a :=
rfl
@[simp] theorem smul_im_k {R : Type u_1} [comm_ring R] (r : R) (a : quaternion R) :
im_k (r β’ a) = r β’ im_k a :=
rfl
theorem coe_commutes {R : Type u_1} [comm_ring R] (r : R) (a : quaternion R) : βr * a = a * βr :=
quaternion_algebra.coe_commutes r a
theorem coe_commute {R : Type u_1} [comm_ring R] (r : R) (a : quaternion R) : commute (βr) a :=
quaternion_algebra.coe_commute r a
theorem coe_mul_eq_smul {R : Type u_1} [comm_ring R] (r : R) (a : quaternion R) : βr * a = r β’ a :=
quaternion_algebra.coe_mul_eq_smul r a
theorem mul_coe_eq_smul {R : Type u_1} [comm_ring R] (r : R) (a : quaternion R) : a * βr = r β’ a :=
quaternion_algebra.mul_coe_eq_smul r a
@[simp] theorem algebra_map_def {R : Type u_1} [comm_ring R] :
β(algebra_map R (quaternion R)) = coe :=
rfl
theorem smul_coe {R : Type u_1} [comm_ring R] (x : R) (y : R) : x β’ βy = β(x * y) :=
quaternion_algebra.smul_coe x y
/-- Quaternion conjugate. -/
def conj {R : Type u_1} [comm_ring R] : linear_equiv R (quaternion R) (quaternion R) :=
quaternion_algebra.conj
@[simp] theorem conj_re {R : Type u_1} [comm_ring R] (a : quaternion R) :
re (coe_fn conj a) = re a :=
rfl
@[simp] theorem conj_im_i {R : Type u_1} [comm_ring R] (a : quaternion R) :
im_i (coe_fn conj a) = -im_i a :=
rfl
@[simp] theorem conj_im_j {R : Type u_1} [comm_ring R] (a : quaternion R) :
im_j (coe_fn conj a) = -im_j a :=
rfl
@[simp] theorem conj_im_k {R : Type u_1} [comm_ring R] (a : quaternion R) :
im_k (coe_fn conj a) = -im_k a :=
rfl
@[simp] theorem conj_conj {R : Type u_1} [comm_ring R] (a : quaternion R) :
coe_fn conj (coe_fn conj a) = a :=
quaternion_algebra.conj_conj a
@[simp] theorem conj_add {R : Type u_1} [comm_ring R] (a : quaternion R) (b : quaternion R) :
coe_fn conj (a + b) = coe_fn conj a + coe_fn conj b :=
quaternion_algebra.conj_add a b
@[simp] theorem conj_mul {R : Type u_1} [comm_ring R] (a : quaternion R) (b : quaternion R) :
coe_fn conj (a * b) = coe_fn conj b * coe_fn conj a :=
quaternion_algebra.conj_mul a b
theorem conj_conj_mul {R : Type u_1} [comm_ring R] (a : quaternion R) (b : quaternion R) :
coe_fn conj (coe_fn conj a * b) = coe_fn conj b * a :=
quaternion_algebra.conj_conj_mul a b
theorem conj_mul_conj {R : Type u_1} [comm_ring R] (a : quaternion R) (b : quaternion R) :
coe_fn conj (a * coe_fn conj b) = b * coe_fn conj a :=
quaternion_algebra.conj_mul_conj a b
theorem self_add_conj' {R : Type u_1} [comm_ring R] (a : quaternion R) :
a + coe_fn conj a = β(bit0 1 * re a) :=
quaternion_algebra.self_add_conj' a
theorem self_add_conj {R : Type u_1} [comm_ring R] (a : quaternion R) :
a + coe_fn conj a = bit0 1 * β(re a) :=
quaternion_algebra.self_add_conj a
theorem conj_add_self' {R : Type u_1} [comm_ring R] (a : quaternion R) :
coe_fn conj a + a = β(bit0 1 * re a) :=
quaternion_algebra.conj_add_self' a
theorem conj_add_self {R : Type u_1} [comm_ring R] (a : quaternion R) :
coe_fn conj a + a = bit0 1 * β(re a) :=
quaternion_algebra.conj_add_self a
theorem conj_eq_two_re_sub {R : Type u_1} [comm_ring R] (a : quaternion R) :
coe_fn conj a = β(bit0 1 * re a) - a :=
quaternion_algebra.conj_eq_two_re_sub a
theorem commute_conj_self {R : Type u_1} [comm_ring R] (a : quaternion R) :
commute (coe_fn conj a) a :=
quaternion_algebra.commute_conj_self a
theorem commute_self_conj {R : Type u_1} [comm_ring R] (a : quaternion R) :
commute a (coe_fn conj a) :=
quaternion_algebra.commute_self_conj a
theorem commute_conj_conj {R : Type u_1} [comm_ring R] {a : quaternion R} {b : quaternion R}
(h : commute a b) : commute (coe_fn conj a) (coe_fn conj b) :=
quaternion_algebra.commute_conj_conj h
theorem Mathlib.commute.quaternion_conj {R : Type u_1} [comm_ring R] {a : quaternion R}
{b : quaternion R} (h : commute a b) : commute (coe_fn conj a) (coe_fn conj b) :=
commute_conj_conj
@[simp] theorem conj_coe {R : Type u_1} [comm_ring R] (x : R) : coe_fn conj βx = βx :=
quaternion_algebra.conj_coe x
@[simp] theorem conj_smul {R : Type u_1} [comm_ring R] (r : R) (a : quaternion R) :
coe_fn conj (r β’ a) = r β’ coe_fn conj a :=
quaternion_algebra.conj_smul r a
@[simp] theorem conj_one {R : Type u_1} [comm_ring R] : coe_fn conj 1 = 1 := conj_coe 1
theorem eq_re_of_eq_coe {R : Type u_1} [comm_ring R] {a : quaternion R} {x : R} (h : a = βx) :
a = β(re a) :=
quaternion_algebra.eq_re_of_eq_coe h
theorem eq_re_iff_mem_range_coe {R : Type u_1} [comm_ring R] {a : quaternion R} :
a = β(re a) β a β set.range coe :=
quaternion_algebra.eq_re_iff_mem_range_coe
@[simp] theorem conj_fixed {R : Type u_1} [comm_ring R] [no_zero_divisors R] [char_zero R]
{a : quaternion R} : coe_fn conj a = a β a = β(re a) :=
quaternion_algebra.conj_fixed
theorem conj_mul_eq_coe {R : Type u_1} [comm_ring R] (a : quaternion R) :
coe_fn conj a * a = β(re (coe_fn conj a * a)) :=
quaternion_algebra.conj_mul_eq_coe a
theorem mul_conj_eq_coe {R : Type u_1} [comm_ring R] (a : quaternion R) :
a * coe_fn conj a = β(re (a * coe_fn conj a)) :=
quaternion_algebra.mul_conj_eq_coe a
@[simp] theorem conj_zero {R : Type u_1} [comm_ring R] : coe_fn conj 0 = 0 :=
quaternion_algebra.conj_zero
@[simp] theorem conj_neg {R : Type u_1} [comm_ring R] (a : quaternion R) :
coe_fn conj (-a) = -coe_fn conj a :=
quaternion_algebra.conj_neg a
@[simp] theorem conj_sub {R : Type u_1} [comm_ring R] (a : quaternion R) (b : quaternion R) :
coe_fn conj (a - b) = coe_fn conj a - coe_fn conj b :=
quaternion_algebra.conj_sub a b
/-- Quaternion conjugate as an `alg_equiv` to the opposite ring. -/
def conj_alg_equiv {R : Type u_1} [comm_ring R] : alg_equiv R (quaternion R) (quaternion Rα΅α΅) :=
quaternion_algebra.conj_alg_equiv
@[simp] theorem coe_conj_alg_equiv {R : Type u_1} [comm_ring R] :
βconj_alg_equiv = opposite.op β βconj :=
rfl
/-- Square of the norm. -/
def norm_sq {R : Type u_1} [comm_ring R] : monoid_with_zero_hom (quaternion R) R :=
monoid_with_zero_hom.mk (fun (a : quaternion R) => re (a * coe_fn conj a)) sorry sorry sorry
theorem norm_sq_def {R : Type u_1} [comm_ring R] (a : quaternion R) :
coe_fn norm_sq a = re (a * coe_fn conj a) :=
rfl
theorem norm_sq_def' {R : Type u_1} [comm_ring R] (a : quaternion R) :
coe_fn norm_sq a = re a ^ bit0 1 + im_i a ^ bit0 1 + im_j a ^ bit0 1 + im_k a ^ bit0 1 :=
sorry
theorem norm_sq_coe {R : Type u_1} [comm_ring R] (x : R) : coe_fn norm_sq βx = x ^ bit0 1 := sorry
@[simp] theorem norm_sq_neg {R : Type u_1} [comm_ring R] (a : quaternion R) :
coe_fn norm_sq (-a) = coe_fn norm_sq a :=
sorry
theorem self_mul_conj {R : Type u_1} [comm_ring R] (a : quaternion R) :
a * coe_fn conj a = β(coe_fn norm_sq a) :=
eq.mpr (id (Eq._oldrec (Eq.refl (a * coe_fn conj a = β(coe_fn norm_sq a))) (mul_conj_eq_coe a)))
(eq.mpr
(id (Eq._oldrec (Eq.refl (β(re (a * coe_fn conj a)) = β(coe_fn norm_sq a))) (norm_sq_def a)))
(Eq.refl β(re (a * coe_fn conj a))))
theorem conj_mul_self {R : Type u_1} [comm_ring R] (a : quaternion R) :
coe_fn conj a * a = β(coe_fn norm_sq a) :=
sorry
theorem coe_norm_sq_add {R : Type u_1} [comm_ring R] (a : quaternion R) (b : quaternion R) :
β(coe_fn norm_sq (a + b)) =
β(coe_fn norm_sq a) + a * coe_fn conj b + b * coe_fn conj a + β(coe_fn norm_sq b) :=
sorry
end quaternion
namespace quaternion
@[simp] theorem norm_sq_eq_zero {R : Type u_1} [linear_ordered_comm_ring R] {a : quaternion R} :
coe_fn norm_sq a = 0 β a = 0 :=
sorry
theorem norm_sq_ne_zero {R : Type u_1} [linear_ordered_comm_ring R] {a : quaternion R} :
coe_fn norm_sq a β 0 β a β 0 :=
not_congr norm_sq_eq_zero
@[simp] theorem norm_sq_nonneg {R : Type u_1} [linear_ordered_comm_ring R] {a : quaternion R} :
0 β€ coe_fn norm_sq a :=
eq.mpr (id (Eq._oldrec (Eq.refl (0 β€ coe_fn norm_sq a)) (norm_sq_def' a)))
(add_nonneg
(add_nonneg (add_nonneg (pow_two_nonneg (re a)) (pow_two_nonneg (im_i a)))
(pow_two_nonneg (im_j a)))
(pow_two_nonneg (im_k a)))
@[simp] theorem norm_sq_le_zero {R : Type u_1} [linear_ordered_comm_ring R] {a : quaternion R} :
coe_fn norm_sq a β€ 0 β a = 0 :=
sorry
protected instance domain {R : Type u_1} [linear_ordered_comm_ring R] : domain (quaternion R) :=
domain.mk ring.add sorry ring.zero sorry sorry ring.neg ring.sub sorry sorry ring.mul sorry
ring.one sorry sorry sorry sorry sorry sorry
theorem has_inv_inv {R : Type u_1} [linear_ordered_field R] (a : quaternion R) :
aβ»ΒΉ = coe_fn norm_sq aβ»ΒΉ β’ coe_fn conj a :=
Eq.refl (aβ»ΒΉ)
protected instance division_ring {R : Type u_1} [linear_ordered_field R] :
division_ring (quaternion R) :=
division_ring.mk domain.add sorry domain.zero sorry sorry domain.neg domain.sub sorry sorry
domain.mul sorry domain.one sorry sorry sorry sorry has_inv.inv
(div_inv_monoid.div._default domain.mul sorry domain.one sorry sorry has_inv.inv) sorry sorry
sorry
@[simp] theorem norm_sq_inv {R : Type u_1} [linear_ordered_field R] (a : quaternion R) :
coe_fn norm_sq (aβ»ΒΉ) = (coe_fn norm_sq aβ»ΒΉ) :=
monoid_with_zero_hom.map_inv' norm_sq a
@[simp] theorem norm_sq_div {R : Type u_1} [linear_ordered_field R] (a : quaternion R)
(b : quaternion R) : coe_fn norm_sq (a / b) = coe_fn norm_sq a / coe_fn norm_sq b :=
monoid_with_zero_hom.map_div norm_sq a b
end Mathlib |
5957b6d314dc70a1a2564894fc0495f20f06698a | a25cc44b447f2fbde61e4b848318762eb892f2bf | /src/sort_rank.lean | 6ea45abfd6afbddf1bc0e202029d64d8b7325d2e | [] | no_license | NeilStrickland/itloc | 20f9b9bcaa4d5840f7f32e84108174b294d84b1a | 5b13b5b418766d10926b983eb3dd2ac42abf63d8 | refs/heads/master | 1,592,747,030,159 | 1,578,138,004,000 | 1,578,138,004,000 | 197,470,135 | 2 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 21,374 | lean | /-
Copyright (c) 2019 Neil Strickland. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Neil Strickland
This file formalises the fact that any finite, linearly ordered
set of size n has a unique order-isomorphism with the set
fin n = {0,...,n-1}.
-/
import data.finset data.fintype
import fin_extra
open list
variables {Ξ± : Type*}
namespace list
/-
If we have a list l (of length n) and a natural number i, we might
want to refer to the i'th entry in the list, but then we have to
decide what to do about the possibility that i is too large so that
there is no i'th entry. We always use 0-based indexing so the
i'th entry is defined for i < n but not for i β₯ n.
The standard library defines (l.nth i) to be of type (option Ξ±),
and to have value (some x) if i < n and x is the i'th entry, but to
have value (none) if i β₯ n. The standard library also defines
(l.nth_le i h) to be x if h is a proof of i < n. Here we just
repackage this slightly: the pair β¨i,hβ© gives a term of type
(fin n), and we define l.fin_nth β¨i,hβ© to be x again.
-/
def fin_nth (l : list Ξ±) (i : fin l.length) : Ξ± :=
l.nth_le i.val i.is_lt
/- An obvious lemma about the behaviour of fin_nth. -/
lemma fin_nth_cons (a : Ξ±) (l : list Ξ±) (i : fin l.length) :
(list.cons a l).fin_nth i.succ = l.fin_nth i :=
begin
cases i,dsimp[fin.succ,fin_nth],refl,
end
/-
If R is a relation on Ξ± and l is a list, we define
(pairwise_nth R l) to be true if all entries in l are R-related
to all strictly later entries. For example, if R is an order
relation then this just means that the list is sorted, and if
R is the relation x β y then this just means that l has no
duplicates. Here we define pairwise_nth in the obvious way
using indices. We then prove that our pairwise_nth is
equivalent to the definition of pairwise in the standard
library, which is formulated by structural induction rather
than using indices.
-/
def pairwise_nthβ (R : Ξ± β Ξ± β Prop) (l : list Ξ±) :=
β (i j : fin l.length), i < j β R (l.fin_nth i) (l.fin_nth j)
def pairwise_nth (R : Ξ± β Ξ± β Prop) (l : list Ξ±) :=
β {i j : β} (hi : i < j) (hj : j < l.length),
R (l.nth_le i (lt_trans hi hj)) (l.nth_le j hj)
lemma pairwise_nth_mp {R : Ξ± β Ξ± β Prop} {l : list Ξ±}
(p : pairwise R l) : pairwise_nth R l :=
begin
induction p with a l0 R_a_l0 p0 ih,
{ intros i j hi hj, cases hj },
{ intros i j hi hj,
rcases j with j, { cases hi },
have hj0 : j < l0.length := nat.lt_of_succ_lt_succ hj,
cases i with i,
{ exact R_a_l0 _ (l0.nth_le_mem j hj0) },
{ exact ih (nat.lt_of_succ_lt_succ hi) hj0 } }
end
lemma pairwise_nth_mpr {R : Ξ± β Ξ± β Prop} {l : list Ξ±}
(hl : pairwise_nth R l) : (pairwise R l) :=
begin
induction l with a l ih,
{ exact @pairwise.nil _ R },
{ have R_a_l : β (b β l), (R a b) :=
begin
intros b b_in_l,
rcases nth_le_of_mem b_in_l with β¨j,β¨hj,eq_bβ©β©,
rw [β eq_b],
exact hl (nat.zero_lt_succ j) (nat.succ_lt_succ hj)
end,
have : l.pairwise R :=
begin
apply ih,
intros i j hi hj,
exact hl (nat.succ_lt_succ hi) (nat.succ_lt_succ hj),
end,
exact pairwise.cons R_a_l this }
end
lemma pairwise_nth_iff {R : Ξ± β Ξ± β Prop} {l : list Ξ±} :
(pairwise R l) β (pairwise_nth R l) :=
iff.intro (@pairwise_nth_mp _ R l) (@pairwise_nth_mpr _ R l)
/-
The standard library defines a list to be sorted if all entries are
less than or equal to all strictly later entries. Here we define
a list to be strongly sorted if the relevant inequalities hold
strictly. This is clearly equivalent to saying that the list is
sorted and has distinct entries; we also formalise this equivalence.
-/
variables [linear_order Ξ±] [decidable_rel (@has_le.le Ξ± _)]
def strongly_sorted (l : list Ξ±) : Prop :=
list.pairwise has_lt.lt l
lemma strongly_sorted_of_sorted_nodup (l : list Ξ±) :
l.sorted has_le.le β l.nodup β l.strongly_sorted :=
begin
intro l_sorted,
induction l_sorted with a l0 a_le_l0 l0_sorted ih,
{intro,exact pairwise.nil},
{intro l_nodup,
cases l_nodup with _ _ a_ne_l0 l0_nodup,
have l0_strongly_sorted := ih l0_nodup,
have a_lt_l0 : β (x : Ξ±) (x_in_l0 : x β l0), (a < x) :=
begin
intros x x_in_l0,
exact lt_of_le_of_ne (a_le_l0 x x_in_l0) (a_ne_l0 x x_in_l0),
end,
exact pairwise.cons a_lt_l0 l0_strongly_sorted,
}
end
lemma sorted_of_strongly_sorted (l : list Ξ±) :
l.strongly_sorted β l.sorted has_le.le :=
begin
intro l_strongly_sorted,
induction l_strongly_sorted with a l0 a_lt_l0 l0_strongly_sorted ih,
{exact pairwise.nil},
{have a_le_l0 : β x β l0, a β€ x :=
Ξ» x x_in_l0,le_of_lt (a_lt_l0 x x_in_l0),
have l0_sorted := ih,
exact pairwise.cons a_le_l0 l0_sorted
}
end
lemma nodup_of_strongly_sorted (l : list Ξ±) :
l.strongly_sorted β l.nodup :=
begin
intro l_strongly_sorted,
induction l_strongly_sorted with a l0 a_ne_l0 l0_strongly_sorted ih,
{exact pairwise.nil},
{have a_ne_l0 : β x β l0, a β x :=
Ξ» x x_in_l0,ne_of_lt (a_ne_l0 x x_in_l0),
have l0_nodup := ih,
exact pairwise.cons a_ne_l0 l0_nodup
}
end
/-
Sortedness is defined in the standard library by structural
induction. Here we reformulate it in terms of indices.
-/
lemma sorted_nth_lt_mp {l : list Ξ±}
(l_nodup : list.nodup l)
(l_sorted : list.sorted has_le.le l)
{i j : β} (hi : i < j) (hj : j < l.length) :
(l.nth_le i (lt_trans hi hj) < l.nth_le j hj) :=
begin
let x := l.nth_le i (lt_trans hi hj),
let y := l.nth_le j hj,
have x_ne_y : x β y := pairwise_nth_mp l_nodup hi hj,
have x_le_y : x β€ y := pairwise_nth_mp l_sorted hi hj,
exact lt_of_le_of_ne x_le_y x_ne_y,
end
lemma sorted_nth_le_mp {l : list Ξ±}
(l_nodup : list.nodup l)
(l_sorted : list.sorted has_le.le l)
{i j : β} (hi : i β€ j) (hj : j < l.length) :
(l.nth_le i (lt_of_le_of_lt hi hj) β€ l.nth_le j hj) :=
begin
by_cases h : i = j,
{ cases h, refl },
{ have hi' : i < j := lt_of_le_of_ne hi h,
exact (le_of_lt $ sorted_nth_lt_mp l_nodup l_sorted hi' hj) }
end
lemma sorted_nth_lt {l : list Ξ±}
(l_nodup : list.nodup l)
(l_sorted : list.sorted has_le.le l)
{ i j : β } (hi : i < l.length) (hj : j < l.length) :
(i < j) β (l.nth_le i hi < l.nth_le j hj) :=
begin
split,
{ intro hi',
exact sorted_nth_lt_mp l_nodup l_sorted hi' hj },
{ intro x_lt_y,
rcases lt_or_ge i j with i_lt_j | j_le_i,
{ assumption },
{ exfalso,
let y_le_x := sorted_nth_le_mp l_nodup l_sorted j_le_i hi,
exact not_lt_of_ge y_le_x x_lt_y } }
end
lemma sorted_nth_le {l : list Ξ±}
(l_nodup : list.nodup l)
(l_sorted : list.sorted has_le.le l)
{ i j : β } (hi : i < l.length) (hj : j < l.length) :
(i β€ j) β (l.nth_le i hi β€ l.nth_le j hj) :=
begin
split,
{ intro hi',
exact sorted_nth_le_mp l_nodup l_sorted hi' hj },
{ intro x_le_y,
rcases le_or_gt i j with i_le_j | j_lt_i,
{ assumption },
{ exfalso,
let y_lt_x := sorted_nth_lt_mp l_nodup l_sorted j_lt_i hi,
exact not_le_of_gt y_lt_x x_le_y } }
end
end list
namespace finset
variables [linear_order Ξ±] [decidable_rel (@has_le.le Ξ± _)]
/-
The standard library defines a function that accepts a finite set s
and returns the list of elements in sorted order. The next lemma
tells us how we can recognise that list if we have obtained it by
other means.
-/
theorem list.perm.eqv' (Ξ± : Type*) : equivalence (@perm Ξ±) :=
mk_equivalence (@perm Ξ±) (@perm.refl Ξ±) (@perm.symm Ξ±) (@perm.trans Ξ±)
instance list.is_setoid' (Ξ± : Type*) : setoid (list Ξ±) :=
setoid.mk (@perm Ξ±) (list.perm.eqv' Ξ±)
lemma sort_spec (s : finset Ξ±) (l : list Ξ±)
(l_nodup : l.nodup) (l_sorted : l.sorted has_le.le)
(s_eq_l : s = l.to_finset) : s.sort has_le.le = l :=
begin
let h0 := (congr_arg val
(eq.trans (eq.trans (to_finset_eq (sort_nodup has_le.le s)) (eq.trans (sort_to_finset has_le.le s) s_eq_l))
(eq.symm (to_finset_eq l_nodup)))),
let h1 := list.eq_of_sorted_of_perm (@quotient.exact (list Ξ±) (list.is_setoid' Ξ±) _ _ h0) (sort_sorted has_le.le s) l_sorted,
let ll : multiset Ξ± := quot.mk _ l,
have ll_nodup : ll.nodup := multiset.coe_nodup.mpr l_nodup,
have ll_eq : (β¨ll,ll_nodupβ© : finset Ξ±) = l.to_finset := list.to_finset_eq l_nodup,
let m := s.sort has_le.le,
have m_nodup : m.nodup := s.sort_nodup has_le.le,
have m_sorted : m.sorted has_le.le := s.sort_sorted has_le.le,
let mm : multiset Ξ± := quot.mk _ m,
have mm_nodup : mm.nodup := multiset.coe_nodup.mpr m_nodup,
have mm_eq : (β¨mm,mm_nodupβ© : finset Ξ±) = m.to_finset := list.to_finset_eq m_nodup,
have m_to_finset : m.to_finset = s :=
s.sort_to_finset has_le.le,
let mm_eq_ll :=
congr_arg finset.val ((mm_eq.trans (m_to_finset.trans s_eq_l)).trans ll_eq.symm),
dsimp[finset.val] at mm_eq_ll,
have perm_m_l : perm m l := quotient.exact mm_eq_ll,
exact list.eq_of_sorted_of_perm perm_m_l m_sorted l_sorted,
end
/-
The next lemma is equivalent to the previous one. However, as an
experiment we have written it as a single term rather than using
tactics. We used the command "#print sort_spec" to print the
proof term generated automatically be Lean from the tactic proof,
and then reorganised it a bit to eliminate some inefficiencies.
-/
lemma sort_spec_alt (s : finset Ξ±) (l : list Ξ±)
(l_nodup : l.nodup) (l_sorted : l.sorted has_le.le)
(s_eq_l : s = l.to_finset) : s.sort has_le.le = l :=
list.eq_of_sorted_of_perm
(@quotient.exact
(list Ξ±)
(list.is_setoid' Ξ±)
_
_
(@congr_arg
(finset Ξ±)
(multiset Ξ±)
_
_
finset.val
(eq.trans
(eq.trans (to_finset_eq (sort_nodup has_le.le s)) (eq.trans (sort_to_finset has_le.le s) s_eq_l))
(eq.symm (to_finset_eq l_nodup))
)
)
)
(sort_sorted has_le.le s)
l_sorted
section rank_equiv
/-
We now give our first version of the fact that any finite, linearly ordered
set of size n is order-isomorphic to (fin n). In this version, the type Ξ± has
a decidable linear order and s is a finite subset of Ξ± that need not contain
all elements of Ξ±. In order to talk about an order-equivalence we need to
convert s into a separate type by considering {a // a β s}. The definition
(rank_equiv s) gives an equivalence from this type to (fin n), but it is not
initially packaged with any information about order-preserving properties.
Instead, we prove those properties as four separate lemmas after the
definition of rank_equiv.
Note that we have arguments n and s_card : s.card = n, and we produce an
equivalence with (fin n). One might think that it would be more natural to
just produce an equivalence with (fin s.card), and then use eq.mp to convert
this to (fin n) if necessary. Unfortunately, this leads to a lot of tedious
troubles with heterogenous equality. As far as I can tell, the present
approach is the simplest way to avoid that.
-/
variables {s : finset Ξ±} {n : β} (s_card : s.card = n)
include s_card
def rank_equiv : { a // a β s } β fin n :=
begin
let l := s.sort has_le.le,
have l_nodup : list.nodup l := finset.sort_nodup has_le.le s,
have l_eq_s : l.to_finset = s := by simp[finset.sort_eq],
have l_len : l.length = n :=
((@eq.subst (finset Ξ±) (Ξ» t, t.card = l.length) _ _ l_eq_s
(list.to_finset_card_of_nodup l_nodup)).symm).trans s_card,
let mem_equiv : β a : Ξ±, a β s β a β l :=
Ξ» a, @eq.subst (finset Ξ±) (Ξ» t, a β t β a β l) _ _ l_eq_s
(@list.mem_to_finset Ξ± _ a l),
let to_fun : { a // a β s } β fin n :=
begin
intro a,
have a_in_l : a.val β l := (mem_equiv a.val).mp a.property,
let i : β := list.index_of a.val l,
have i_lt_n : i < n :=
l_len.subst (list.index_of_lt_length.mpr a_in_l),
exact β¨i,i_lt_nβ©
end,
let inv_fun : fin n β { a // a β s } :=
begin
intro i,
have i_is_lt : i.val < l.length := @eq.subst β (Ξ» m, i.val < m) _ _ l_len.symm i.is_lt,
let a := l.nth_le i.val i_is_lt,
have a_in_s : a β s := (mem_equiv a).mpr (l.nth_le_mem i.val i_is_lt),
exact β¨a,a_in_sβ©
end,
have left_inv : β a, inv_fun (to_fun a) = a :=
begin
intro a,
rcases a with β¨a_val,a_in_sβ©,
have a_in_l : a_val β l := (mem_equiv a_val).mp a_in_s,
let i := list.index_of a_val l,
have i_lt_len : i < l.length := list.index_of_lt_length.mpr a_in_l,
have i_lt_n : i < n := l_len.subst i_lt_len,
dsimp[inv_fun,to_fun],
apply subtype.eq,dsimp[subtype.val],
exact list.index_of_nth_le i_lt_len,
end,
have right_inv : β i, to_fun (inv_fun i) = i :=
begin
intro i,
rcases i with β¨i_val,i_lt_nβ©,
have i_lt_len : i_val < l.length := l_len.symm.subst i_lt_n,
dsimp[inv_fun,to_fun],
apply fin.eq_of_veq,dsimp[fin.val],
exact list.nth_le_index_of l_nodup i_val i_lt_len,
end,
exact β¨to_fun,inv_fun,left_inv,right_invβ©,
end
lemma seq_le (i1 i2 : fin n) :
i1 β€ i2 β (((rank_equiv s_card).inv_fun i1).val β€ ((rank_equiv s_card).inv_fun i2).val) :=
begin
dsimp [rank_equiv, nth_le, has_le.le, fin.le],
let l := s.sort has_le.le,
have l_nodup : list.nodup l := finset.sort_nodup has_le.le s,
have l_sorted : l.sorted has_le.le := sort_sorted has_le.le s,
have l_eq_s : l.to_finset = s := by simp[finset.sort_eq],
have l_len : l.length = n :=
((@eq.subst (finset Ξ±) (Ξ» t, t.card = l.length) _ _ l_eq_s
(list.to_finset_card_of_nodup l_nodup)).symm).trans s_card,
have i1p : i1.val < l.length := by { rw[l_len], exact i1.is_lt },
have i2p : i2.val < l.length := by { rw[l_len], exact i2.is_lt },
exact list.sorted_nth_le l_nodup l_sorted i1p i2p
end
lemma seq_lt (i1 i2 : fin n) :
i1 < i2 β (((rank_equiv s_card).inv_fun i1).val < ((rank_equiv s_card).inv_fun i2).val) :=
begin
dsimp [rank_equiv, nth_le, has_le.le, fin.le],
let l := s.sort has_le.le,
have l_nodup : list.nodup l := finset.sort_nodup has_le.le s,
have l_sorted : l.sorted has_le.le := sort_sorted has_le.le s,
have l_eq_s : l.to_finset = s := by simp[finset.sort_eq],
have l_len : l.length = n :=
((@eq.subst (finset Ξ±) (Ξ» t, t.card = l.length) _ _ l_eq_s
(list.to_finset_card_of_nodup l_nodup)).symm).trans s_card,
have i1p : i1.val < l.length := by { rw[l_len], exact i1.is_lt },
have i2p : i2.val < l.length := by { rw[l_len], exact i2.is_lt },
exact list.sorted_nth_lt l_nodup l_sorted i1p i2p
end
lemma rank_le (a1 a2 : {a // a β s }) :
a1.val β€ a2.val β (rank_equiv s_card).to_fun a1 β€ (rank_equiv s_card).to_fun a2 :=
begin
let f := rank_equiv s_card,
let i1 := f.to_fun a1,
let i2 := f.to_fun a2,
let a1a := f.inv_fun i1,
let a2a := f.inv_fun i2,
let h := ((seq_le s_card) (f.to_fun a1) (f.to_fun a2)).symm,
let e1 : (f.inv_fun i1).val = a1.val := congr_arg subtype.val (f.left_inv a1),
let e2 : (f.inv_fun i2).val = a2.val := congr_arg subtype.val (f.left_inv a2),
split,
{intro h1,rw[β e1,β e2] at h1,exact h.mp h1,},
{intro h2,let h3 := h.mpr h2,rw[e1,e2] at h3,exact h3}
end
lemma rank_lt (a1 a2 : {a // a β s }) :
a1.val < a2.val β ((rank_equiv s_card).to_fun a1) < ((rank_equiv s_card).to_fun a2) :=
begin
let f := rank_equiv s_card,
let i1 := f.to_fun a1,
let i2 := f.to_fun a2,
let a1a := f.inv_fun i1,
let a2a := f.inv_fun i2,
let h := ((seq_lt s_card) (f.to_fun a1) (f.to_fun a2)).symm,
let e1 : (f.inv_fun i1).val = a1.val := congr_arg subtype.val (f.left_inv a1),
let e2 : (f.inv_fun i2).val = a2.val := congr_arg subtype.val (f.left_inv a2),
split,
{intro h1,rw[β e1,β e2] at h1,exact h.mp h1,},
{intro h2,let h3 := h.mpr h2,rw[e1,e2] at h3,exact h3}
end
lemma rank_as_card (a : { x // x β s}) :
((rank_equiv s_card).to_fun a).val = card (s.filter (Ξ» x, x < a.val)) :=
begin
let f := rank_equiv s_card,
let u := s.filter (Ξ» x, x < a.val),
let ut := {x // x β u},
let k := f.to_fun a,
have fi_k : f.inv_fun k = a := f.left_inv a,
let g_to_fun : ut β fin k.val :=
begin
intro x,
let x0 : { x // x β s } := β¨x.val,(mem_filter.mp x.property).leftβ©,
let x_lt_a : x0.val < a.val := (mem_filter.mp x.property).right,
let i := f.to_fun x0,
let i_lt_k : i < k := ((rank_lt s_card) x0 a).mp x_lt_a,
let i_lt_k_val : i.val < k.val :=
begin
let h := i_lt_k,
dsimp[has_lt.lt,fin.lt] at h,
exact h,
end,
exact β¨i.val,i_lt_k_valβ©,
end,
let g_inv_fun : fin k.val β ut :=
begin
intro i,
let i0 : fin n := β¨i.val,lt_trans i.is_lt k.is_ltβ©,
have i0_lt_k : i0 < k := by { simp[has_lt.lt,fin.lt], exact i.is_lt,},
let x0 := f.inv_fun i0,
let x_lt_a := ((seq_lt s_card) i0 k).mp i0_lt_k,
rw[fi_k] at x_lt_a,
have x_in_u : x0.val β u :=
begin
apply mem_filter.mpr,
exact β¨x0.property,x_lt_aβ©,
end,
exact β¨x0.val,x_in_uβ©,
end,
have g_left_inv : β x, g_inv_fun (g_to_fun x) = x :=
begin
intro x,
dsimp[g_to_fun,g_inv_fun],
apply subtype.eq; simp[subtype.val],
exact congr_arg subtype.val (f.left_inv _),
end,
have g_right_inv : β i, g_to_fun (g_inv_fun i) = i :=
begin
intro i,
dsimp[g_to_fun,g_inv_fun],
apply fin.eq_of_veq; simp[fin.val],
exact congr_arg fin.val (f.right_inv _),
end,
let g : ut β fin k.val := β¨g_to_fun,g_inv_fun,g_left_inv,g_right_invβ©,
let h0 := fintype.card_congr g,
let h1 := @finset.card_attach Ξ± u,
let h2 := fintype.card_fin k.val,
exact (h1.symm.trans (h0.trans h2)).symm,
end
end rank_equiv
end finset
namespace fintype
open finset fintype
variables [linear_order Ξ±] [decidable_rel (@has_le.le Ξ± _)]
variables [fintype Ξ±] {n : β} (Ξ±_card : card Ξ± = n)
include Ξ±_card
/-
We now give our second version of the fact that any finite, linearly ordered
set of size n is order-isomorphic to (fin n). In this version we assume given
an instance of (fintype Ξ±), which is essentially a proof that the whole type
Ξ± is finite. From this we build an equivalence from Ξ± to (fin n), and again
we prove the order properties as separate lemmas.
-/
def rank_equiv : Ξ± β fin n :=
begin
have h0 : finset.card (@elems Ξ± _) = n := Ξ±_card,
let f := finset.rank_equiv h0,
let to_fun : Ξ± β fin n := Ξ» a, f.to_fun β¨a,mem_univ aβ©,
let inv_fun : fin n β Ξ± := Ξ» i, (f.inv_fun i).val,
have left_inv : β a : Ξ±, inv_fun (to_fun a) = a :=
Ξ» a, congr_arg subtype.val (f.left_inv β¨a,mem_univ aβ©),
have right_inv : β i : fin n, to_fun (inv_fun i) = i :=
begin
intro i,
have e : f.inv_fun i = β¨inv_fun i,mem_univ _β© :=
by {apply subtype.eq,simp[inv_fun]},
dsimp[inv_fun,to_fun],rw[β e],exact f.right_inv i,
end,
exact β¨to_fun,inv_fun,left_inv,right_invβ©,
end
lemma seq_le (i1 i2 : fin n) :
i1 β€ i2 β (rank_equiv Ξ±_card).inv_fun i1 β€ (rank_equiv Ξ±_card).inv_fun i2 :=
(seq_le Ξ±_card) i1 i2
lemma seq_lt (i1 i2 : fin n) :
i1 < i2 β (rank_equiv Ξ±_card).inv_fun i1 < (rank_equiv Ξ±_card).inv_fun i2 :=
(seq_lt Ξ±_card) i1 i2
lemma rank_le (a1 a2 : Ξ±) :
a1 β€ a2 β (rank_equiv Ξ±_card).to_fun a1 β€ (rank_equiv Ξ±_card).to_fun a2 :=
(rank_le Ξ±_card) β¨a1,mem_univ a1β© β¨a2,mem_univ a2β©
lemma rank_lt (a1 a2 : Ξ±) :
a1 < a2 β (rank_equiv Ξ±_card).to_fun a1 < (rank_equiv Ξ±_card).to_fun a2 :=
(rank_lt Ξ±_card) β¨a1,mem_univ a1β© β¨a2,mem_univ a2β©
end fintype
namespace fin
/-
The only strictly increasing self-map of (fin n) is the identity
-/
lemma rigid {n : β} {f : fin n β fin n}
(f_mono : β {i1 i2 : fin n}, i1 < i2 β (f i1) < (f i2)) :
β (i : fin n), f i = i :=
begin
induction n with n0 ih,
{intro i,exact fin.elim0 i},
{
let f0 : fin n0 β fin n0 :=
begin
intro i0,
let h0 := ne_of_lt (lt_of_le_of_lt (fin.zero_le (f 0)) (f_mono (@fin.zero_lt_succ n0 i0))),
exact fin.pred (f i0.succ) h0.symm,
end,
have succ_f0 : β (i0 : fin n0), (f0 i0).succ = f i0.succ :=
begin
intro i0,
let h0 := ne_of_lt (lt_of_le_of_lt (fin.zero_le (f 0)) (f_mono (@fin.zero_lt_succ n0 i0))),
exact fin.succ_pred (f i0.succ) h0.symm,
end,
have f0_mono : β {i1 i2 : fin n0}, i1 < i2 β (f0 i1) < (f0 i2) :=
begin
intros i1 i2 i1_lt_i2,
let h0 := f_mono (fin.succ_lt_succ i1_lt_i2),
rw[β (succ_f0 i1)] at h0,
rw[β (succ_f0 i2)] at h0,
exact fin.lt_of_succ_lt_succ h0,
end,
let f0_id := ih @f0_mono,
have f_zero_a : β (j : fin n0.succ), f 0 = j β j = 0 :=
begin
intros j e, cases j, cases j_val with j0_val,
{refl},
{
exfalso,
have j0_is_lt : j0_val < n0 := nat.lt_of_succ_lt_succ j_is_lt,
let j0 : fin n0 := β¨j0_val,j0_is_ltβ©,
let j := j0.succ,
have h0 : f j = j := (succ_f0 j0).symm.trans (congr_arg fin.succ (f0_id j0)),
have h1 : f 0 < f j := f_mono (@fin.zero_lt_succ n0 j0),
have h2 : j < f j := @eq.subst (fin n0.succ) (Ξ» k, k < f j) _ _ e h1,
exact (ne_of_lt h2) h0.symm,
}
end,
have f_zero : f 0 = 0 := f_zero_a (f 0) rfl,
intro i, cases i, cases i_val with i0_val,
{exact f_zero,},
{
have i0_is_lt : i0_val < n0 := nat.lt_of_succ_lt_succ i_is_lt,
let h0 := congr_arg fin.succ (f0_id β¨i0_val,i0_is_ltβ©),
let h1 := succ_f0 β¨i0_val,i0_is_ltβ©,
let h2 := h1.symm.trans h0,
exact h2,
}
}
end
end fin |
ec5d7de5caa90964dff441f9a5c6478e1fa6c209 | 302c785c90d40ad3d6be43d33bc6a558354cc2cf | /src/data/padics/padic_norm.lean | f64eb8224af26cf30d5987fec2f8e141e9b5881d | [
"Apache-2.0"
] | permissive | ilitzroth/mathlib | ea647e67f1fdfd19a0f7bdc5504e8acec6180011 | 5254ef14e3465f6504306132fe3ba9cec9ffff16 | refs/heads/master | 1,680,086,661,182 | 1,617,715,647,000 | 1,617,715,647,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 26,586 | lean | /-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis
-/
import ring_theory.int.basic
import algebra.field_power
import ring_theory.multiplicity
import data.real.cau_seq
import tactic.ring_exp
import tactic.basic
/-!
# p-adic norm
This file defines the p-adic valuation and the p-adic norm on β.
The p-adic valuation on β is the difference of the multiplicities of `p` in the numerator and
denominator of `q`. This function obeys the standard properties of a valuation, with the appropriate
assumptions on p.
The valuation induces a norm on β. This norm is a nonarchimedean absolute value.
It takes values in {0} βͺ {1/p^k | k β β€}.
## Notations
This file uses the local notation `/.` for `rat.mk`.
## Implementation notes
Much, but not all, of this file assumes that `p` is prime. This assumption is inferred automatically
by taking `[fact (prime p)]` as a type class argument.
## References
* [F. Q. GouΓͺva, *p-adic numbers*][gouvea1997]
* [R. Y. Lewis, *A formal proof of Hensel's lemma over the p-adic integers*][lewis2019]
* <https://en.wikipedia.org/wiki/P-adic_number>
## Tags
p-adic, p adic, padic, norm, valuation
-/
universe u
open nat
open_locale rat
open multiplicity
/--
For `p β 1`, the p-adic valuation of an integer `z β 0` is the largest natural number `n` such that
p^n divides z.
`padic_val_rat` defines the valuation of a rational `q` to be the valuation of `q.num` minus the
valuation of `q.denom`.
If `q = 0` or `p = 1`, then `padic_val_rat p q` defaults to 0.
-/
def padic_val_rat (p : β) (q : β) : β€ :=
if h : q β 0 β§ p β 1
then (multiplicity (p : β€) q.num).get
(multiplicity.finite_int_iff.2 β¨h.2, rat.num_ne_zero_of_ne_zero h.1β©) -
(multiplicity (p : β€) q.denom).get
(multiplicity.finite_int_iff.2 β¨h.2, by exact_mod_cast rat.denom_ne_zero _β©)
else 0
/--
A simplification of the definition of `padic_val_rat p q` when `q β 0` and `p` is prime.
-/
lemma padic_val_rat_def (p : β) [hp : fact p.prime] {q : β} (hq : q β 0) : padic_val_rat p q =
(multiplicity (p : β€) q.num).get (finite_int_iff.2 β¨hp.1.ne_one, rat.num_ne_zero_of_ne_zero hqβ©) -
(multiplicity (p : β€) q.denom).get
(finite_int_iff.2 β¨hp.1.ne_one, by exact_mod_cast rat.denom_ne_zero _β©) :=
dif_pos β¨hq, hp.1.ne_oneβ©
namespace padic_val_rat
open multiplicity
variables {p : β}
/--
`padic_val_rat p q` is symmetric in `q`.
-/
@[simp] protected lemma neg (q : β) : padic_val_rat p (-q) = padic_val_rat p q :=
begin
unfold padic_val_rat,
split_ifs,
{ simp [-add_comm]; refl },
{ exfalso, simp * at * },
{ exfalso, simp * at * },
{ refl }
end
/--
`padic_val_rat p 1` is 0 for any `p`.
-/
@[simp] protected lemma one : padic_val_rat p 1 = 0 :=
by unfold padic_val_rat; split_ifs; simp *
/--
For `p β 0, p β 1, `padic_val_rat p p` is 1.
-/
@[simp] lemma padic_val_rat_self (hp : 1 < p) : padic_val_rat p p = 1 :=
by unfold padic_val_rat; split_ifs; simp [*, nat.one_lt_iff_ne_zero_and_ne_one] at *
/--
The p-adic value of an integer `z β 0` is the multiplicity of `p` in `z`.
-/
lemma padic_val_rat_of_int (z : β€) (hp : p β 1) (hz : z β 0) :
padic_val_rat p (z : β) = (multiplicity (p : β€) z).get
(finite_int_iff.2 β¨hp, hzβ©) :=
by rw [padic_val_rat, dif_pos]; simp *; refl
end padic_val_rat
/--
A convenience function for the case of `padic_val_rat` when both inputs are natural numbers.
-/
def padic_val_nat (p : β) (n : β) : β :=
int.to_nat (padic_val_rat p n)
section padic_val_nat
/--
`padic_val_nat` is defined as an `int.to_nat` cast;
this lemma ensures that the cast is well-behaved.
-/
lemma zero_le_padic_val_rat_of_nat (p n : β) : 0 β€ padic_val_rat p n :=
begin
unfold padic_val_rat,
split_ifs,
{ simp, },
{ trivial, },
end
/--
`padic_val_rat` coincides with `padic_val_nat`.
-/
@[simp, norm_cast] lemma padic_val_rat_of_nat (p n : β) :
β(padic_val_nat p n) = padic_val_rat p n :=
begin
unfold padic_val_nat,
rw int.to_nat_of_nonneg (zero_le_padic_val_rat_of_nat p n),
end
/--
A simplification of `padic_val_nat` when one input is prime, by analogy with `padic_val_rat_def`.
-/
lemma padic_val_nat_def {p : β} [hp : fact p.prime] {n : β} (hn : n β 0) :
padic_val_nat p n =
(multiplicity p n).get
(multiplicity.finite_nat_iff.2 β¨nat.prime.ne_one hp.1, bot_lt_iff_ne_bot.mpr hnβ©) :=
begin
have n_nonzero : (n : β) β 0, by simpa only [cast_eq_zero, ne.def],
-- Infinite loop with @simp padic_val_rat_of_nat unless we restrict the available lemmas here,
-- hence the very long list
simpa only
[ int.coe_nat_multiplicity p n, rat.coe_nat_denom n, (padic_val_rat_of_nat p n).symm,
int.coe_nat_zero, int.coe_nat_inj', sub_zero, get_one_right, int.coe_nat_succ, zero_add,
rat.coe_nat_num ]
using padic_val_rat_def p n_nonzero,
end
lemma one_le_padic_val_nat_of_dvd
{n p : nat} [prime : fact p.prime] (nonzero : n β 0) (div : p β£ n) :
1 β€ padic_val_nat p n :=
begin
rw @padic_val_nat_def _ prime _ nonzero,
let one_le_mul : _ β€ multiplicity p n :=
@multiplicity.le_multiplicity_of_pow_dvd _ _ _ p n 1 (begin norm_num, exact div end),
simp only [enat.coe_one] at one_le_mul,
rcases one_le_mul with β¨_, qβ©,
dsimp at q,
solve_by_elim,
end
@[simp]
lemma padic_val_nat_zero (m : nat) : padic_val_nat m 0 = 0 := by simpa
@[simp]
lemma padic_val_nat_one (m : nat) : padic_val_nat m 1 = 0 := by simp [padic_val_nat]
end padic_val_nat
namespace padic_val_rat
open multiplicity
variables (p : β) [p_prime : fact p.prime]
include p_prime
/--
The multiplicity of `p : β` in `a : β€` is finite exactly when `a β 0`.
-/
lemma finite_int_prime_iff {p : β} [p_prime : fact p.prime] {a : β€} : finite (p : β€) a β a β 0 :=
by simp [finite_int_iff, ne.symm (ne_of_lt (p_prime.1.one_lt))]
/--
A rewrite lemma for `padic_val_rat p q` when `q` is expressed in terms of `rat.mk`.
-/
protected lemma defn {q : β} {n d : β€} (hqz : q β 0) (qdf : q = n /. d) :
padic_val_rat p q = (multiplicity (p : β€) n).get (finite_int_iff.2
β¨ne.symm $ ne_of_lt p_prime.1.one_lt, Ξ» hn, by simp * at *β©) -
(multiplicity (p : β€) d).get (finite_int_iff.2 β¨ne.symm $ ne_of_lt p_prime.1.one_lt,
Ξ» hd, by simp * at *β©) :=
have hn : n β 0, from rat.mk_num_ne_zero_of_ne_zero hqz qdf,
have hd : d β 0, from rat.mk_denom_ne_zero_of_ne_zero hqz qdf,
let β¨c, hc1, hc2β© := rat.num_denom_mk hn hd qdf in
by rw [padic_val_rat, dif_pos];
simp [hc1, hc2, multiplicity.mul' (nat.prime_iff_prime_int.1 p_prime.1),
(ne.symm (ne_of_lt p_prime.1.one_lt)), hqz]
/--
A rewrite lemma for `padic_val_rat p (q * r)` with conditions `q β 0`, `r β 0`.
-/
protected lemma mul {q r : β} (hq : q β 0) (hr : r β 0) :
padic_val_rat p (q * r) = padic_val_rat p q + padic_val_rat p r :=
have q*r = (q.num * r.num) /. (βq.denom * βr.denom), by rw_mod_cast rat.mul_num_denom,
have hq' : q.num /. q.denom β 0, by rw rat.num_denom; exact hq,
have hr' : r.num /. r.denom β 0, by rw rat.num_denom; exact hr,
have hp' : _root_.prime (p : β€), from nat.prime_iff_prime_int.1 p_prime.1,
begin
rw [padic_val_rat.defn p (mul_ne_zero hq hr) this],
conv_rhs { rw [β(@rat.num_denom q), padic_val_rat.defn p hq',
β(@rat.num_denom r), padic_val_rat.defn p hr'] },
rw [multiplicity.mul' hp', multiplicity.mul' hp']; simp [add_comm, add_left_comm, sub_eq_add_neg]
end
/--
A rewrite lemma for `padic_val_rat p (q^k) with condition `q β 0`.
-/
protected lemma pow {q : β} (hq : q β 0) {k : β} :
padic_val_rat p (q ^ k) = k * padic_val_rat p q :=
by induction k; simp [*, padic_val_rat.mul _ hq (pow_ne_zero _ hq),
pow_succ, add_mul, add_comm]
/--
A rewrite lemma for `padic_val_rat p (qβ»ΒΉ)` with condition `q β 0`.
-/
protected lemma inv {q : β} (hq : q β 0) :
padic_val_rat p (qβ»ΒΉ) = -padic_val_rat p q :=
by rw [eq_neg_iff_add_eq_zero, β padic_val_rat.mul p (inv_ne_zero hq) hq,
inv_mul_cancel hq, padic_val_rat.one]
/--
A rewrite lemma for `padic_val_rat p (q / r)` with conditions `q β 0`, `r β 0`.
-/
protected lemma div {q r : β} (hq : q β 0) (hr : r β 0) :
padic_val_rat p (q / r) = padic_val_rat p q - padic_val_rat p r :=
by rw [div_eq_mul_inv, padic_val_rat.mul p hq (inv_ne_zero hr),
padic_val_rat.inv p hr, sub_eq_add_neg]
/--
A condition for `padic_val_rat p (nβ / dβ) β€ padic_val_rat p (nβ / dβ),
in terms of divisibility by `p^n`.
-/
lemma padic_val_rat_le_padic_val_rat_iff {nβ nβ dβ dβ : β€}
(hnβ : nβ β 0) (hnβ : nβ β 0) (hdβ : dβ β 0) (hdβ : dβ β 0) :
padic_val_rat p (nβ /. dβ) β€ padic_val_rat p (nβ /. dβ) β
β (n : β), βp ^ n β£ nβ * dβ β βp ^ n β£ nβ * dβ :=
have hf1 : finite (p : β€) (nβ * dβ),
from finite_int_prime_iff.2 (mul_ne_zero hnβ hdβ),
have hf2 : finite (p : β€) (nβ * dβ),
from finite_int_prime_iff.2 (mul_ne_zero hnβ hdβ),
by conv {
to_lhs,
rw [padic_val_rat.defn p (rat.mk_ne_zero_of_ne_zero hnβ hdβ) rfl,
padic_val_rat.defn p (rat.mk_ne_zero_of_ne_zero hnβ hdβ) rfl,
sub_le_iff_le_add',
β add_sub_assoc,
le_sub_iff_add_le],
norm_cast,
rw [β multiplicity.mul' (nat.prime_iff_prime_int.1 p_prime.1) hf1, add_comm,
β multiplicity.mul' (nat.prime_iff_prime_int.1 p_prime.1) hf2,
enat.get_le_get, multiplicity_le_multiplicity_iff]
}
/--
Sufficient conditions to show that the p-adic valuation of `q` is less than or equal to the
p-adic vlauation of `q + r`.
-/
theorem le_padic_val_rat_add_of_le {q r : β}
(hq : q β 0) (hr : r β 0) (hqr : q + r β 0)
(h : padic_val_rat p q β€ padic_val_rat p r) :
padic_val_rat p q β€ padic_val_rat p (q + r) :=
have hqn : q.num β 0, from rat.num_ne_zero_of_ne_zero hq,
have hqd : (q.denom : β€) β 0, by exact_mod_cast rat.denom_ne_zero _,
have hrn : r.num β 0, from rat.num_ne_zero_of_ne_zero hr,
have hrd : (r.denom : β€) β 0, by exact_mod_cast rat.denom_ne_zero _,
have hqreq : q + r = (((q.num * r.denom + q.denom * r.num : β€)) /. (βq.denom * βr.denom : β€)),
from rat.add_num_denom _ _,
have hqrd : q.num * β(r.denom) + β(q.denom) * r.num β 0,
from rat.mk_num_ne_zero_of_ne_zero hqr hqreq,
begin
conv_lhs { rw β(@rat.num_denom q) },
rw [hqreq, padic_val_rat_le_padic_val_rat_iff p hqn hqrd hqd (mul_ne_zero hqd hrd),
β multiplicity_le_multiplicity_iff, mul_left_comm,
multiplicity.mul (nat.prime_iff_prime_int.1 p_prime.1), add_mul],
rw [β(@rat.num_denom q), β(@rat.num_denom r),
padic_val_rat_le_padic_val_rat_iff p hqn hrn hqd hrd, β multiplicity_le_multiplicity_iff] at h,
calc _ β€ min (multiplicity βp (q.num * β(r.denom) * β(q.denom)))
(multiplicity βp (β(q.denom) * r.num * β(q.denom))) : (le_min
(by rw [@multiplicity.mul _ _ _ _ (_ * _) _ (nat.prime_iff_prime_int.1 p_prime.1), add_comm])
(by rw [mul_assoc, @multiplicity.mul _ _ _ _ (q.denom : β€)
(_ * _) (nat.prime_iff_prime_int.1 p_prime.1)];
exact add_le_add_left h _))
... β€ _ : min_le_multiplicity_add
end
/--
The minimum of the valuations of `q` and `r` is less than or equal to the valuation of `q + r`.
-/
theorem min_le_padic_val_rat_add {q r : β}
(hq : q β 0) (hr : r β 0) (hqr : q + r β 0) :
min (padic_val_rat p q) (padic_val_rat p r) β€ padic_val_rat p (q + r) :=
(le_total (padic_val_rat p q) (padic_val_rat p r)).elim
(Ξ» h, by rw [min_eq_left h]; exact le_padic_val_rat_add_of_le _ hq hr hqr h)
(Ξ» h, by rw [min_eq_right h, add_comm]; exact le_padic_val_rat_add_of_le _ hr hq
(by rwa add_comm) h)
open_locale big_operators
/-- A finite sum of rationals with positive p-adic valuation has positive p-adic valuation
(if the sum is non-zero). -/
theorem sum_pos_of_pos {n : β} {F : β β β}
(hF : β i, i < n β 0 < padic_val_rat p (F i)) (hn0 : β i in finset.range n, F i β 0) :
0 < padic_val_rat p (β i in finset.range n, F i) :=
begin
induction n with d hd,
{ exact false.elim (hn0 rfl) },
{ rw finset.sum_range_succ at hn0 β’,
by_cases h : β (x : β) in finset.range d, F x = 0,
{ rw [h, add_zero],
exact hF d (lt_add_one _) },
{ refine lt_of_lt_of_le _ (min_le_padic_val_rat_add p (Ξ» h1, _) h hn0),
{ refine lt_min (hF d (lt_add_one _)) (hd (Ξ» i hi, _) h),
exact hF _ (lt_trans hi (lt_add_one _)) },
{ have h2 := hF d (lt_add_one _),
rw h1 at h2,
exact lt_irrefl _ h2 } } }
end
end padic_val_rat
namespace padic_val_nat
/--
A rewrite lemma for `padic_val_nat p (q * r)` with conditions `q β 0`, `r β 0`.
-/
protected lemma mul (p : β) [p_prime : fact p.prime] {q r : β} (hq : q β 0) (hr : r β 0) :
padic_val_nat p (q * r) = padic_val_nat p q + padic_val_nat p r :=
begin
apply int.coe_nat_inj,
simp only [padic_val_rat_of_nat, nat.cast_mul],
rw padic_val_rat.mul,
norm_cast,
exact cast_ne_zero.mpr hq,
exact cast_ne_zero.mpr hr,
end
/--
Dividing out by a prime factor reduces the padic_val_nat by 1.
-/
protected lemma div {p : β} [p_prime : fact p.prime] {b : β} (dvd : p β£ b) :
(padic_val_nat p (b / p)) = (padic_val_nat p b) - 1 :=
begin
by_cases b_split : (b = 0),
{ simp [b_split], },
{ have split_frac : padic_val_rat p (b / p) = padic_val_rat p b - padic_val_rat p p :=
padic_val_rat.div p (nat.cast_ne_zero.mpr b_split)
(nat.cast_ne_zero.mpr (nat.prime.ne_zero p_prime.1)),
rw padic_val_rat.padic_val_rat_self (nat.prime.one_lt p_prime.1) at split_frac,
have r : 1 β€ padic_val_nat p b := one_le_padic_val_nat_of_dvd b_split dvd,
exact_mod_cast split_frac, }
end
end padic_val_nat
section padic_val_nat
/--
If a prime doesn't appear in `n`, `padic_val_nat p n` is `0`.
-/
lemma padic_val_nat_of_not_dvd {p : β} [fact p.prime] {n : β} (not_dvd : Β¬(p β£ n)) :
padic_val_nat p n = 0 :=
begin
by_cases hn : n = 0,
{ subst hn, simp at not_dvd, trivial, },
{ rw padic_val_nat_def hn,
exact (@multiplicity.unique' _ _ _ p n 0 (by simp) (by simpa using not_dvd)).symm,
assumption, },
end
lemma dvd_of_one_le_padic_val_nat {n p : nat} [prime : fact p.prime] (hp : 1 β€ padic_val_nat p n) :
p β£ n :=
begin
by_contra h,
rw padic_val_nat_of_not_dvd h at hp,
exact lt_irrefl 0 (lt_of_lt_of_le zero_lt_one hp),
end
lemma padic_val_nat_primes {p q : β} [p_prime : fact p.prime] [q_prime : fact q.prime]
(neq : p β q) : padic_val_nat p q = 0 :=
@padic_val_nat_of_not_dvd p p_prime q $
(not_congr (iff.symm (prime_dvd_prime_iff_eq p_prime.1 q_prime.1))).mp neq
protected lemma padic_val_nat.div' {p : β} [p_prime : fact p.prime] :
β {m : β} (cpm : coprime p m) {b : β} (dvd : m β£ b), padic_val_nat p (b / m) = padic_val_nat p b
| 0 := Ξ» cpm b dvd, by { rw zero_dvd_iff at dvd, rw [dvd, nat.zero_div], }
| (n + 1) :=
Ξ» cpm b dvd,
begin
rcases dvd with β¨c, rflβ©,
rw [mul_div_right c (nat.succ_pos _)],by_cases hc : c = 0,
{ rw [hc, mul_zero] },
{ rw padic_val_nat.mul,
{ suffices : Β¬ p β£ (n+1),
{ rw [padic_val_nat_of_not_dvd this, zero_add] },
contrapose! cpm,
exact p_prime.1.dvd_iff_not_coprime.mp cpm },
{ exact nat.succ_ne_zero _ },
{ exact hc } },
end
lemma padic_val_nat_eq_factors_count (p : β) [hp : fact p.prime] :
β (n : β), padic_val_nat p n = (factors n).count p
| 0 := rfl
| 1 := by { rw padic_val_nat_one, refl }
| (m + 2) :=
let n := m + 2 in
let q := min_fac n in
have hq : fact q.prime := β¨min_fac_prime (show m + 2 β 1, by linarith)β©,
have wf : n / q < n := nat.div_lt_self (nat.succ_pos _) hq.1.one_lt,
begin
rw factors_add_two,
show padic_val_nat p n = list.count p (q :: (factors (n / q))),
rw [list.count_cons', β padic_val_nat_eq_factors_count],
split_ifs with h,
have p_dvd_n : p β£ n,
{ have: q β£ n := nat.min_fac_dvd n,
cc },
{ rw [βh, padic_val_nat.div],
{ have: 1 β€ padic_val_nat p n := one_le_padic_val_nat_of_dvd (by linarith) p_dvd_n,
exact (nat.sub_eq_iff_eq_add this).mp rfl, },
{ exact p_dvd_n, }, },
{ suffices : p.coprime q,
{ rw [padic_val_nat.div' this (min_fac_dvd n), add_zero], },
rwa nat.coprime_primes hp.1 hq.1, },
end
open_locale big_operators
lemma prod_pow_prime_padic_val_nat (n : nat) (hn : n β 0) (m : nat) (pr : n < m) :
β p in finset.filter nat.prime (finset.range m), p ^ (padic_val_nat p n) = n :=
begin
rw β pos_iff_ne_zero at hn,
have H : (factors n : multiset β).prod = n,
{ rw [multiset.coe_prod, prod_factors hn], },
rw finset.prod_multiset_count at H,
conv_rhs { rw β H, },
refine finset.prod_bij_ne_one (Ξ» p hp hp', p) _ _ _ _,
{ rintro p hp hpn,
rw [finset.mem_filter, finset.mem_range] at hp,
rw [multiset.mem_to_finset, multiset.mem_coe, mem_factors_iff_dvd hn hp.2],
contrapose! hpn,
haveI Hp : fact p.prime := β¨hp.2β©,
rw [padic_val_nat_of_not_dvd hpn, pow_zero], },
{ intros, assumption },
{ intros p hp hpn,
rw [multiset.mem_to_finset, multiset.mem_coe] at hp,
haveI Hp : fact p.prime := β¨mem_factors hpβ©,
simp only [exists_prop, ne.def, finset.mem_filter, finset.mem_range],
refine β¨p, β¨_, Hp.1β©, β¨_, rflβ©β©,
{ rw mem_factors_iff_dvd hn Hp.1 at hp, exact lt_of_le_of_lt (le_of_dvd hn hp) pr },
{ rw padic_val_nat_eq_factors_count,
simpa [ne.def, multiset.coe_count] using hpn } },
{ intros p hp hpn,
rw [finset.mem_filter, finset.mem_range] at hp,
haveI Hp : fact p.prime := β¨hp.2β©,
rw [padic_val_nat_eq_factors_count, multiset.coe_count] }
end
end padic_val_nat
/--
If `q β 0`, the p-adic norm of a rational `q` is `p ^ (-(padic_val_rat p q))`.
If `q = 0`, the p-adic norm of `q` is 0.
-/
def padic_norm (p : β) (q : β) : β :=
if q = 0 then 0 else (βp : β) ^ (-(padic_val_rat p q))
namespace padic_norm
section padic_norm
open padic_val_rat
variables (p : β)
/--
Unfolds the definition of the p-adic norm of `q` when `q β 0`.
-/
@[simp] protected lemma eq_fpow_of_nonzero {q : β} (hq : q β 0) :
padic_norm p q = p ^ (-(padic_val_rat p q)) :=
by simp [hq, padic_norm]
/--
The p-adic norm is nonnegative.
-/
protected lemma nonneg (q : β) : 0 β€ padic_norm p q :=
if hq : q = 0 then by simp [hq, padic_norm]
else
begin
unfold padic_norm; split_ifs,
apply fpow_nonneg,
exact_mod_cast nat.zero_le _
end
/--
The p-adic norm of 0 is 0.
-/
@[simp] protected lemma zero : padic_norm p 0 = 0 := by simp [padic_norm]
/--
The p-adic norm of 1 is 1.
-/
@[simp] protected lemma one : padic_norm p 1 = 1 := by simp [padic_norm]
/--
The p-adic norm of `p` is `1/p` if `p > 1`.
See also `padic_norm.padic_norm_p_of_prime` for a version that assumes `p` is prime.
-/
lemma padic_norm_p {p : β} (hp : 1 < p) : padic_norm p p = 1 / p :=
by simp [padic_norm, (show p β 0, by linarith), padic_val_rat.padic_val_rat_self hp]
/--
The p-adic norm of `p` is `1/p` if `p` is prime.
See also `padic_norm.padic_norm_p` for a version that assumes `1 < p`.
-/
@[simp] lemma padic_norm_p_of_prime (p : β) [fact p.prime] : padic_norm p p = 1 / p :=
padic_norm_p $ nat.prime.one_lt (fact.out _)
/-- The p-adic norm of `q` is `1` if `q` is prime and not equal to `p`. -/
lemma padic_norm_of_prime_of_ne {p q : β} [p_prime : fact p.prime] [q_prime : fact q.prime]
(neq : p β q) : padic_norm p q = 1 :=
begin
have p : padic_val_rat p q = 0,
{ exact_mod_cast @padic_val_nat_primes p q p_prime q_prime neq },
simp [padic_norm, p, q_prime.1.1, q_prime.1.ne_zero],
end
/--
The p-adic norm of `p` is less than 1 if `1 < p`.
See also `padic_norm.padic_norm_p_lt_one_of_prime` for a version assuming `prime p`.
-/
lemma padic_norm_p_lt_one {p : β} (hp : 1 < p) : padic_norm p p < 1 :=
begin
rw [padic_norm_p hp, div_lt_iff, one_mul],
{ exact_mod_cast hp },
{ exact_mod_cast zero_lt_one.trans hp },
end
/--
The p-adic norm of `p` is less than 1 if `p` is prime.
See also `padic_norm.padic_norm_p_lt_one` for a version assuming `1 < p`.
-/
lemma padic_norm_p_lt_one_of_prime (p : β) [fact p.prime] : padic_norm p p < 1 :=
padic_norm_p_lt_one $ nat.prime.one_lt (fact.out _)
/--
`padic_norm p q` takes discrete values `p ^ -z` for `z : β€`.
-/
protected theorem values_discrete {q : β} (hq : q β 0) : β z : β€, padic_norm p q = p ^ (-z) :=
β¨ (padic_val_rat p q), by simp [padic_norm, hq] β©
/--
`padic_norm p` is symmetric.
-/
@[simp] protected lemma neg (q : β) : padic_norm p (-q) = padic_norm p q :=
if hq : q = 0 then by simp [hq]
else by simp [padic_norm, hq]
variable [hp : fact p.prime]
include hp
/--
If `q β 0`, then `padic_norm p q β 0`.
-/
protected lemma nonzero {q : β} (hq : q β 0) : padic_norm p q β 0 :=
begin
rw padic_norm.eq_fpow_of_nonzero p hq,
apply fpow_ne_zero_of_ne_zero,
exact_mod_cast ne_of_gt hp.1.pos
end
/--
If the p-adic norm of `q` is 0, then `q` is 0.
-/
lemma zero_of_padic_norm_eq_zero {q : β} (h : padic_norm p q = 0) : q = 0 :=
begin
apply by_contradiction, intro hq,
unfold padic_norm at h, rw if_neg hq at h,
apply absurd h,
apply fpow_ne_zero_of_ne_zero,
exact_mod_cast hp.1.ne_zero
end
/--
The p-adic norm is multiplicative.
-/
@[simp] protected theorem mul (q r : β) : padic_norm p (q*r) = padic_norm p q * padic_norm p r :=
if hq : q = 0 then
by simp [hq]
else if hr : r = 0 then
by simp [hr]
else
have q*r β 0, from mul_ne_zero hq hr,
have (βp : β) β 0, by simp [hp.1.ne_zero],
by simp [padic_norm, *, padic_val_rat.mul, fpow_add this, mul_comm]
/--
The p-adic norm respects division.
-/
@[simp] protected theorem div (q r : β) : padic_norm p (q / r) = padic_norm p q / padic_norm p r :=
if hr : r = 0 then by simp [hr] else
eq_div_of_mul_eq (padic_norm.nonzero _ hr) (by rw [βpadic_norm.mul, div_mul_cancel _ hr])
/--
The p-adic norm of an integer is at most 1.
-/
protected theorem of_int (z : β€) : padic_norm p βz β€ 1 :=
if hz : z = 0 then by simp [hz, zero_le_one] else
begin
unfold padic_norm,
rw [if_neg _],
{ refine fpow_le_one_of_nonpos _ _,
{ exact_mod_cast le_of_lt hp.1.one_lt, },
{ rw [padic_val_rat_of_int _ hp.1.ne_one hz, neg_nonpos],
norm_cast, simp }},
exact_mod_cast hz
end
private lemma nonarchimedean_aux {q r : β} (h : padic_val_rat p q β€ padic_val_rat p r) :
padic_norm p (q + r) β€ max (padic_norm p q) (padic_norm p r) :=
have hnqp : padic_norm p q β₯ 0, from padic_norm.nonneg _ _,
have hnrp : padic_norm p r β₯ 0, from padic_norm.nonneg _ _,
if hq : q = 0 then
by simp [hq, max_eq_right hnrp, le_max_right]
else if hr : r = 0 then
by simp [hr, max_eq_left hnqp, le_max_left]
else if hqr : q + r = 0 then
le_trans (by simpa [hqr] using hnqp) (le_max_left _ _)
else
begin
unfold padic_norm, split_ifs,
apply le_max_iff.2,
left,
apply fpow_le_of_le,
{ exact_mod_cast le_of_lt hp.1.one_lt },
{ apply neg_le_neg,
have : padic_val_rat p q =
min (padic_val_rat p q) (padic_val_rat p r),
from (min_eq_left h).symm,
rw this,
apply min_le_padic_val_rat_add; assumption }
end
/--
The p-adic norm is nonarchimedean: the norm of `p + q` is at most the max of the norm of `p` and
the norm of `q`.
-/
protected theorem nonarchimedean {q r : β} :
padic_norm p (q + r) β€ max (padic_norm p q) (padic_norm p r) :=
begin
wlog hle := le_total (padic_val_rat p q) (padic_val_rat p r) using [q r],
exact nonarchimedean_aux p hle
end
/--
The p-adic norm respects the triangle inequality: the norm of `p + q` is at most the norm of `p`
plus the norm of `q`.
-/
theorem triangle_ineq (q r : β) : padic_norm p (q + r) β€ padic_norm p q + padic_norm p r :=
calc padic_norm p (q + r) β€ max (padic_norm p q) (padic_norm p r) : padic_norm.nonarchimedean p
... β€ padic_norm p q + padic_norm p r :
max_le_add_of_nonneg (padic_norm.nonneg p _) (padic_norm.nonneg p _)
/--
The p-adic norm of a difference is at most the max of each component. Restates the archimedean
property of the p-adic norm.
-/
protected theorem sub {q r : β} : padic_norm p (q - r) β€ max (padic_norm p q) (padic_norm p r) :=
by rw [sub_eq_add_neg, βpadic_norm.neg p r]; apply padic_norm.nonarchimedean
/--
If the p-adic norms of `q` and `r` are different, then the norm of `q + r` is equal to the max of
the norms of `q` and `r`.
-/
lemma add_eq_max_of_ne {q r : β} (hne : padic_norm p q β padic_norm p r) :
padic_norm p (q + r) = max (padic_norm p q) (padic_norm p r) :=
begin
wlog hle := le_total (padic_norm p r) (padic_norm p q) using [q r],
have hlt : padic_norm p r < padic_norm p q, from lt_of_le_of_ne hle hne.symm,
have : padic_norm p q β€ max (padic_norm p (q + r)) (padic_norm p r), from calc
padic_norm p q = padic_norm p (q + r - r) : by congr; ring
... β€ max (padic_norm p (q + r)) (padic_norm p (-r)) : padic_norm.nonarchimedean p
... = max (padic_norm p (q + r)) (padic_norm p r) : by simp,
have hnge : padic_norm p r β€ padic_norm p (q + r),
{ apply le_of_not_gt,
intro hgt,
rw max_eq_right_of_lt hgt at this,
apply not_lt_of_ge this,
assumption },
have : padic_norm p q β€ padic_norm p (q + r), by rwa [max_eq_left hnge] at this,
apply _root_.le_antisymm,
{ apply padic_norm.nonarchimedean p },
{ rw max_eq_left_of_lt hlt,
assumption }
end
/--
The p-adic norm is an absolute value: positive-definite and multiplicative, satisfying the triangle
inequality.
-/
instance : is_absolute_value (padic_norm p) :=
{ abv_nonneg := padic_norm.nonneg p,
abv_eq_zero :=
begin
intros,
constructor; intro,
{ apply zero_of_padic_norm_eq_zero p, assumption },
{ simp [*] }
end,
abv_add := padic_norm.triangle_ineq p,
abv_mul := padic_norm.mul p }
variable {p}
lemma dvd_iff_norm_le {n : β} {z : β€} : β(p^n) β£ z β padic_norm p z β€ βp ^ (-n : β€) :=
begin
unfold padic_norm, split_ifs with hz,
{ norm_cast at hz,
have : 0 β€ (p^n : β), {apply pow_nonneg, exact_mod_cast le_of_lt hp.1.pos },
simp [hz, this] },
{ rw [fpow_le_iff_le, neg_le_neg_iff, padic_val_rat_of_int _ hp.1.ne_one _],
{ norm_cast,
rw [β enat.coe_le_coe, enat.coe_get, β multiplicity.pow_dvd_iff_le_multiplicity],
simp },
{ exact_mod_cast hz },
{ exact_mod_cast hp.1.one_lt } }
end
end padic_norm
end padic_norm
|
0fa3bd22fa536471923368848e350fc400debc5c | 7cef822f3b952965621309e88eadf618da0c8ae9 | /src/analysis/asymptotics.lean | 1f4e54df699bd1c59f8abe87bf97f37f141315d8 | [
"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 | 30,725 | lean | /-
Copyright (c) 2019 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Jeremy Avigad
-/
import analysis.normed_space.basic
/-!
# Asymptotics
We introduce these relations:
`is_O f g l` : "f is big O of g along l"
`is_o f g l` : "f is little o of g along l"
Here `l` is any filter on the domain of `f` and `g`, which are assumed to be the same. The codomains
of `f` and `g` do not need to be the same; all that is needed that there is a norm associated with
these types, and it is the norm that is compared asymptotically.
Often the ranges of `f` and `g` will be the real numbers, in which case the norm is the absolute
value. In general, we have
`is_O f g l β is_O (Ξ» x, β₯f xβ₯) (Ξ» x, β₯g xβ₯) l`,
and similarly for `is_o`. But our setup allows us to use the notions e.g. with functions
to the integers, rationals, complex numbers, or any normed vector space without mentioning the
norm explicitly.
If `f` and `g` are functions to a normed field like the reals or complex numbers and `g` is always
nonzero, we have
`is_o f g l β tendsto (Ξ» x, f x / (g x)) (π 0) l`.
In fact, the right-to-left direction holds without the hypothesis on `g`, and in the other direction
it suffices to assume that `f` is zero wherever `g` is. (This generalization is useful in defining
the FrΓ©chet derivative.)
-/
open filter
open_locale topological_space
namespace asymptotics
variables {Ξ± : Type*} {Ξ² : Type*} {Ξ³ : Type*} {Ξ΄ : Type*} {π : Type*} {π' : Type*}
section
variables [has_norm Ξ²] [has_norm Ξ³] [has_norm Ξ΄]
/-- The Landau notation `is_O f g l` where `f` and `g` are two functions on a type `Ξ±` and `l` is
a filter on `Ξ±`, means that eventually for `l`, `β₯fβ₯` is bounded by a constant multiple of `β₯gβ₯`.
In other words, `β₯fβ₯ / β₯gβ₯` is eventually bounded, modulo division by zero issues that are avoided
by this definition. -/
def is_O (f : Ξ± β Ξ²) (g : Ξ± β Ξ³) (l : filter Ξ±) : Prop :=
β c > 0, { x | β₯ f x β₯ β€ c * β₯ g x β₯ } β l
/-- The Landau notation `is_o f g l` where `f` and `g` are two functions on a type `Ξ±` and `l` is
a filter on `Ξ±`, means that eventually for `l`, `β₯fβ₯` is bounded by an arbitrarily small constant
multiple of `β₯gβ₯`. In other words, `β₯fβ₯ / β₯gβ₯` tends to `0` along `l`, modulo division by zero
issues that are avoided by this definition. -/
def is_o (f : Ξ± β Ξ²) (g : Ξ± β Ξ³) (l : filter Ξ±) : Prop :=
β c > 0, { x | β₯ f x β₯ β€ c * β₯ g x β₯ } β l
theorem is_O_refl (f : Ξ± β Ξ²) (l : filter Ξ±) : is_O f f l :=
β¨1, zero_lt_one, by { filter_upwards [univ_mem_sets], intros x _, simp }β©
theorem is_O.comp {f : Ξ± β Ξ²} {g : Ξ± β Ξ³} {l : filter Ξ±} (hfg : is_O f g l)
{Ξ΄ : Type*} (k : Ξ΄ β Ξ±) :
is_O (f β k) (g β k) (l.comap k) :=
let β¨c, cpos, hfgcβ© := hfg in
β¨c, cpos, mem_comap_sets.mpr β¨_, hfgc, set.subset.refl _β©β©
theorem is_o.comp {f : Ξ± β Ξ²} {g : Ξ± β Ξ³} {l : filter Ξ±} (hfg : is_o f g l)
{Ξ΄ : Type*} (k : Ξ΄ β Ξ±) :
is_o (f β k) (g β k) (l.comap k) :=
Ξ» c cpos, mem_comap_sets.mpr β¨_, hfg c cpos, set.subset.refl _β©
theorem is_O.mono {f : Ξ± β Ξ²} {g : Ξ± β Ξ³} {lβ lβ : filter Ξ±} (h : lβ β€ lβ)
(h' : is_O f g lβ) : is_O f g lβ :=
let β¨c, cpos, h'cβ© := h' in β¨c, cpos, h (h'c)β©
theorem is_o.mono {f : Ξ± β Ξ²} {g : Ξ± β Ξ³} {lβ lβ : filter Ξ±} (h : lβ β€ lβ)
(h' : is_o f g lβ) : is_o f g lβ :=
Ξ» c cpos, h (h' c cpos)
theorem is_o.to_is_O {f : Ξ± β Ξ²} {g : Ξ± β Ξ³} {l : filter Ξ±} (hgf : is_o f g l) : is_O f g l :=
β¨1, zero_lt_one, hgf 1 zero_lt_oneβ©
theorem is_O.trans {f : Ξ± β Ξ²} {g : Ξ± β Ξ³} {k : Ξ± β Ξ΄} {l : filter Ξ±}
(hβ : is_O f g l) (hβ : is_O g k l) :
is_O f k l :=
let β¨c, cpos, hcβ© := hβ,
β¨c', c'pos, hc'β© := hβ in
begin
use [c * c', mul_pos cpos c'pos],
filter_upwards [hc, hc'], dsimp,
intros x hβx hβx, rw mul_assoc,
exact le_trans hβx (mul_le_mul_of_nonneg_left hβx (le_of_lt cpos))
end
theorem is_o.trans_is_O {f : Ξ± β Ξ²} {g : Ξ± β Ξ³} {k : Ξ± β Ξ΄} {l : filter Ξ±}
(hβ : is_o f g l) (hβ : is_O g k l) :
is_o f k l :=
begin
intros c cpos,
rcases hβ with β¨c', c'pos, hc'β©,
have cc'pos := div_pos cpos c'pos,
filter_upwards [hβ (c / c') cc'pos, hc'], dsimp,
intros x hβx hβx,
refine le_trans hβx (le_trans (mul_le_mul_of_nonneg_left hβx (le_of_lt cc'pos)) _),
rw [βmul_assoc, div_mul_cancel _ (ne_of_gt c'pos)]
end
theorem is_O.trans_is_o {f : Ξ± β Ξ²} {g : Ξ± β Ξ³} {k : Ξ± β Ξ΄} {l : filter Ξ±}
(hβ : is_O f g l) (hβ : is_o g k l) :
is_o f k l :=
begin
intros c cpos,
rcases hβ with β¨c', c'pos, hc'β©,
have cc'pos := div_pos cpos c'pos,
filter_upwards [hc', hβ (c / c') cc'pos], dsimp,
intros x hβx hβx,
refine le_trans hβx (le_trans (mul_le_mul_of_nonneg_left hβx (le_of_lt c'pos)) _),
rw [βmul_assoc, mul_div_cancel' _ (ne_of_gt c'pos)]
end
theorem is_o.trans {f : Ξ± β Ξ²} {g : Ξ± β Ξ³} {k : Ξ± β Ξ΄} {l : filter Ξ±}
(hβ : is_o f g l) (hβ : is_o g k l) :
is_o f k l :=
hβ.to_is_O.trans_is_o hβ
theorem is_o_join {f : Ξ± β Ξ²} {g : Ξ± β Ξ³} {lβ lβ : filter Ξ±}
(hβ : is_o f g lβ) (hβ : is_o f g lβ) :
is_o f g (lβ β lβ) :=
begin
intros c cpos,
rw mem_sup_sets,
exact β¨hβ c cpos, hβ c cposβ©
end
theorem is_O_congr {fβ fβ : Ξ± β Ξ²} {gβ gβ : Ξ± β Ξ³} {l : filter Ξ±}
(hf : {x | fβ x = fβ x} β l) (hg : {x | gβ x = gβ x} β l) :
is_O fβ gβ l β is_O fβ gβ l :=
bex_congr $ Ξ» c _, filter.congr_sets $
by filter_upwards [hf, hg] Ξ» x eβ eβ,
by dsimp at eβ eβ β’; rw [eβ, eβ]
theorem is_o_congr {fβ fβ : Ξ± β Ξ²} {gβ gβ : Ξ± β Ξ³} {l : filter Ξ±}
(hf : {x | fβ x = fβ x} β l) (hg : {x | gβ x = gβ x} β l) :
is_o fβ gβ l β is_o fβ gβ l :=
ball_congr $ Ξ» c _, filter.congr_sets $
by filter_upwards [hf, hg] Ξ» x eβ eβ,
by dsimp at eβ eβ β’; rw [eβ, eβ]
theorem is_O.congr {fβ fβ : Ξ± β Ξ²} {gβ gβ : Ξ± β Ξ³} {l : filter Ξ±}
(hf : β x, fβ x = fβ x) (hg : β x, gβ x = gβ x) :
is_O fβ gβ l β is_O fβ gβ l :=
(is_O_congr (univ_mem_sets' hf) (univ_mem_sets' hg)).1
theorem is_o.congr {fβ fβ : Ξ± β Ξ²} {gβ gβ : Ξ± β Ξ³} {l : filter Ξ±}
(hf : β x, fβ x = fβ x) (hg : β x, gβ x = gβ x) :
is_o fβ gβ l β is_o fβ gβ l :=
(is_o_congr (univ_mem_sets' hf) (univ_mem_sets' hg)).1
theorem is_O_congr_left {fβ fβ : Ξ± β Ξ²} {g : Ξ± β Ξ³} {l : filter Ξ±}
(h : {x | fβ x = fβ x} β l) :
is_O fβ g l β is_O fβ g l :=
is_O_congr h (univ_mem_sets' $ Ξ» _, rfl)
theorem is_o_congr_left {fβ fβ : Ξ± β Ξ²} {g : Ξ± β Ξ³} {l : filter Ξ±}
(h : {x | fβ x = fβ x} β l) :
is_o fβ g l β is_o fβ g l :=
is_o_congr h (univ_mem_sets' $ Ξ» _, rfl)
theorem is_O.congr_left {fβ fβ : Ξ± β Ξ²} {g : Ξ± β Ξ³} {l : filter Ξ±}
(hf : β x, fβ x = fβ x) : is_O fβ g l β is_O fβ g l :=
is_O.congr hf (Ξ» _, rfl)
theorem is_o.congr_left {fβ fβ : Ξ± β Ξ²} {g : Ξ± β Ξ³} {l : filter Ξ±}
(hf : β x, fβ x = fβ x) : is_o fβ g l β is_o fβ g l :=
is_o.congr hf (Ξ» _, rfl)
theorem is_O_congr_right {f : Ξ± β Ξ²} {gβ gβ : Ξ± β Ξ³} {l : filter Ξ±}
(h : {x | gβ x = gβ x} β l) :
is_O f gβ l β is_O f gβ l :=
is_O_congr (univ_mem_sets' $ Ξ» _, rfl) h
theorem is_o_congr_right {f : Ξ± β Ξ²} {gβ gβ : Ξ± β Ξ³} {l : filter Ξ±}
(h : {x | gβ x = gβ x} β l) :
is_o f gβ l β is_o f gβ l :=
is_o_congr (univ_mem_sets' $ Ξ» _, rfl) h
theorem is_O.congr_right {f : Ξ± β Ξ²} {gβ gβ : Ξ± β Ξ³} {l : filter Ξ±}
(hg : β x, gβ x = gβ x) : is_O f gβ l β is_O f gβ l :=
is_O.congr (Ξ» _, rfl) hg
theorem is_o.congr_right {f : Ξ± β Ξ²} {gβ gβ : Ξ± β Ξ³} {l : filter Ξ±}
(hg : β x, gβ x = gβ x) : is_o f gβ l β is_o f gβ l :=
is_o.congr (Ξ» _, rfl) hg
end
section
variables [has_norm Ξ²] [normed_group Ξ³] [normed_group Ξ΄]
@[simp]
theorem is_O_norm_right {f : Ξ± β Ξ²} {g : Ξ± β Ξ³} {l : filter Ξ±} :
is_O f (Ξ» x, β₯g xβ₯) l β is_O f g l :=
by simp only [is_O, norm_norm]
@[simp]
theorem is_o_norm_right {f : Ξ± β Ξ²} {g : Ξ± β Ξ³} {l : filter Ξ±} :
is_o f (Ξ» x, β₯g xβ₯) l β is_o f g l :=
by simp only [is_o, norm_norm]
@[simp]
theorem is_O_neg_right {f : Ξ± β Ξ²} {g : Ξ± β Ξ³} {l : filter Ξ±} :
is_O f (Ξ» x, -(g x)) l β is_O f g l :=
by { rw βis_O_norm_right, simp only [norm_neg], rw is_O_norm_right }
@[simp]
theorem is_o_neg_right {f : Ξ± β Ξ²} {g : Ξ± β Ξ³} {l : filter Ξ±} :
is_o f (Ξ» x, -(g x)) l β is_o f g l :=
by { rw βis_o_norm_right, simp only [norm_neg], rw is_o_norm_right }
theorem is_O_iff {f : Ξ± β Ξ²} {g : Ξ± β Ξ³} {l : filter Ξ±} :
is_O f g l β β c, { x | β₯f xβ₯ β€ c * β₯g xβ₯ } β l :=
suffices (β c, { x | β₯f xβ₯ β€ c * β₯g xβ₯ } β l) β is_O f g l,
from β¨Ξ» β¨c, cpos, hcβ©, β¨c, hcβ©, thisβ©,
assume β¨c, hcβ©,
or.elim (lt_or_ge 0 c)
(assume : c > 0, β¨c, this, hcβ©)
(assume h'c : c β€ 0,
have {x : Ξ± | β₯f xβ₯ β€ 1 * β₯g xβ₯} β l,
begin
filter_upwards [hc], intros x,
show β₯f xβ₯ β€ c * β₯g xβ₯ β β₯f xβ₯ β€ 1 * β₯g xβ₯,
{ intro hx, apply le_trans hx,
apply mul_le_mul_of_nonneg_right _ (norm_nonneg _),
show c β€ 1, from le_trans h'c zero_le_one }
end,
β¨1, zero_lt_one, thisβ©)
theorem is_O_join {f : Ξ± β Ξ²} {g : Ξ± β Ξ³} {lβ lβ : filter Ξ±}
(hβ : is_O f g lβ) (hβ : is_O f g lβ) :
is_O f g (lβ β lβ) :=
begin
rcases hβ with β¨cβ, cβpos, hcββ©,
rcases hβ with β¨cβ, cβpos, hcββ©,
have : 0 < max cβ cβ, by { rw lt_max_iff, left, exact cβpos },
use [max cβ cβ, this],
rw mem_sup_sets, split,
{ filter_upwards [hcβ], dsimp, intros x hx,
exact le_trans hx (mul_le_mul_of_nonneg_right (le_max_left _ _) (norm_nonneg _)) },
filter_upwards [hcβ], dsimp, intros x hx,
exact le_trans hx (mul_le_mul_of_nonneg_right (le_max_right _ _) (norm_nonneg _))
end
lemma is_O.prod_rightl {f : Ξ± β Ξ²} {gβ : Ξ± β Ξ³} {gβ : Ξ± β Ξ΄} {l : filter Ξ±}
(h : is_O f gβ l) : is_O f (Ξ»x, (gβ x, gβ x)) l :=
begin
have : is_O gβ (Ξ»x, (gβ x, gβ x)) l :=
β¨1, zero_lt_one, filter.univ_mem_sets' (Ξ»x, by simp [norm, le_refl])β©,
exact is_O.trans h this
end
lemma is_O.prod_rightr {f : Ξ± β Ξ²} {gβ : Ξ± β Ξ³} {gβ : Ξ± β Ξ΄} {l : filter Ξ±}
(h : is_O f gβ l) : is_O f (Ξ»x, (gβ x, gβ x)) l :=
begin
have : is_O gβ (Ξ»x, (gβ x, gβ x)) l :=
β¨1, zero_lt_one, filter.univ_mem_sets' (Ξ»x, by simp [norm, le_refl])β©,
exact is_O.trans h this
end
lemma is_o.prod_rightl {f : Ξ± β Ξ²} {gβ : Ξ± β Ξ³} {gβ : Ξ± β Ξ΄} {l : filter Ξ±}
(h : is_o f gβ l) : is_o f (Ξ»x, (gβ x, gβ x)) l :=
is_o.trans_is_O h (is_O.prod_rightl (is_O_refl gβ l))
lemma is_o.prod_rightr {f : Ξ± β Ξ²} {gβ : Ξ± β Ξ³} {gβ : Ξ± β Ξ΄} {l : filter Ξ±}
(h : is_o f gβ l) : is_o f (Ξ»x, (gβ x, gβ x)) l :=
is_o.trans_is_O h (is_O.prod_rightr (is_O_refl gβ l))
end
section
variables [normed_group Ξ²] [normed_group Ξ΄] [has_norm Ξ³]
@[simp] theorem is_O_norm_left {f : Ξ± β Ξ²} {g : Ξ± β Ξ³} {l : filter Ξ±} :
is_O (Ξ» x, β₯f xβ₯) g l β is_O f g l :=
by simp only [is_O, norm_norm]
@[simp] theorem is_o_norm_left {f : Ξ± β Ξ²} {g : Ξ± β Ξ³} {l : filter Ξ±} :
is_o (Ξ» x, β₯f xβ₯) g l β is_o f g l :=
by simp only [is_o, norm_norm]
@[simp] theorem is_O_neg_left {f : Ξ± β Ξ²} {g : Ξ± β Ξ³} {l : filter Ξ±} :
is_O (Ξ» x, -f x) g l β is_O f g l :=
by { rw βis_O_norm_left, simp only [norm_neg], rw is_O_norm_left }
@[simp] theorem is_o_neg_left {f : Ξ± β Ξ²} {g : Ξ± β Ξ³} {l : filter Ξ±} :
is_o (Ξ» x, -f x) g l β is_o f g l :=
by { rw βis_o_norm_left, simp only [norm_neg], rw is_o_norm_left }
theorem is_O.add {fβ fβ : Ξ± β Ξ²} {g : Ξ± β Ξ³} {l : filter Ξ±} (hβ : is_O fβ g l) (hβ : is_O fβ g l) :
is_O (Ξ» x, fβ x + fβ x) g l :=
let β¨cβ, cβpos, hcββ© := hβ,
β¨cβ, cβpos, hcββ© := hβ in
begin
use [cβ + cβ, add_pos cβpos cβpos],
filter_upwards [hcβ, hcβ],
intros x hxβ hxβ,
show β₯fβ x + fβ xβ₯ β€ (cβ + cβ) * β₯g xβ₯,
rw add_mul,
exact norm_add_le_of_le hxβ hxβ
end
theorem is_o.add {fβ fβ : Ξ± β Ξ²} {g : Ξ± β Ξ³} {l : filter Ξ±} (hβ : is_o fβ g l) (hβ : is_o fβ g l) :
is_o (Ξ» x, fβ x + fβ x) g l :=
begin
intros c cpos,
filter_upwards [hβ (c / 2) (half_pos cpos), hβ (c / 2) (half_pos cpos)],
intros x hxβ hxβ, dsimp at hxβ hxβ,
apply le_trans (norm_add_le_of_le hxβ hxβ),
rw [βmul_add, βtwo_mul, βmul_assoc, div_mul_cancel _ two_ne_zero]
end
theorem is_O.sub {fβ fβ : Ξ± β Ξ²} {g : Ξ± β Ξ³} {l : filter Ξ±} (hβ : is_O fβ g l) (hβ : is_O fβ g l) :
is_O (Ξ» x, fβ x - fβ x) g l :=
hβ.add (is_O_neg_left.mpr hβ)
theorem is_o.sub {fβ fβ : Ξ± β Ξ²} {g : Ξ± β Ξ³} {l : filter Ξ±} (hβ : is_o fβ g l) (hβ : is_o fβ g l) :
is_o (Ξ» x, fβ x - fβ x) g l :=
hβ.add (is_o_neg_left.mpr hβ)
theorem is_O_comm {fβ fβ : Ξ± β Ξ²} {g : Ξ± β Ξ³} {l : filter Ξ±} :
is_O (Ξ» x, fβ x - fβ x) g l β is_O (Ξ» x, fβ x - fβ x) g l :=
by simpa using @is_O_neg_left _ _ _ _ _ (Ξ» x, fβ x - fβ x) g l
theorem is_O.symm {fβ fβ : Ξ± β Ξ²} {g : Ξ± β Ξ³} {l : filter Ξ±} :
is_O (Ξ» x, fβ x - fβ x) g l β is_O (Ξ» x, fβ x - fβ x) g l :=
is_O_comm.1
theorem is_O.tri {fβ fβ fβ : Ξ± β Ξ²} {g : Ξ± β Ξ³} {l : filter Ξ±}
(hβ : is_O (Ξ» x, fβ x - fβ x) g l)
(hβ : is_O (Ξ» x, fβ x - fβ x) g l) :
is_O (Ξ» x, fβ x - fβ x) g l :=
(hβ.add hβ).congr_left (by simp)
theorem is_O.congr_of_sub {fβ fβ : Ξ± β Ξ²} {g : Ξ± β Ξ³} {l : filter Ξ±}
(h : is_O (Ξ» x, fβ x - fβ x) g l) :
is_O fβ g l β is_O fβ g l :=
β¨Ξ» h', (h'.sub h).congr_left (Ξ» x, sub_sub_cancel _ _),
Ξ» h', (h.add h').congr_left (Ξ» x, sub_add_cancel _ _)β©
theorem is_o_comm {fβ fβ : Ξ± β Ξ²} {g : Ξ± β Ξ³} {l : filter Ξ±} :
is_o (Ξ» x, fβ x - fβ x) g l β is_o (Ξ» x, fβ x - fβ x) g l :=
by simpa using @is_o_neg_left _ _ _ _ _ (Ξ» x, fβ x - fβ x) g l
theorem is_o.symm {fβ fβ : Ξ± β Ξ²} {g : Ξ± β Ξ³} {l : filter Ξ±} :
is_o (Ξ» x, fβ x - fβ x) g l β is_o (Ξ» x, fβ x - fβ x) g l :=
is_o_comm.1
theorem is_o.tri {fβ fβ fβ : Ξ± β Ξ²} {g : Ξ± β Ξ³} {l : filter Ξ±}
(hβ : is_o (Ξ» x, fβ x - fβ x) g l)
(hβ : is_o (Ξ» x, fβ x - fβ x) g l) :
is_o (Ξ» x, fβ x - fβ x) g l :=
(hβ.add hβ).congr_left (by simp)
theorem is_o.congr_of_sub {fβ fβ : Ξ± β Ξ²} {g : Ξ± β Ξ³} {l : filter Ξ±}
(h : is_o (Ξ» x, fβ x - fβ x) g l) :
is_o fβ g l β is_o fβ g l :=
β¨Ξ» h', (h'.sub h).congr_left (Ξ» x, sub_sub_cancel _ _),
Ξ» h', (h.add h').congr_left (Ξ» x, sub_add_cancel _ _)β©
@[simp] theorem is_O_prod_left {fβ : Ξ± β Ξ²} {fβ : Ξ± β Ξ΄} {g : Ξ± β Ξ³} {l : filter Ξ±} :
is_O (Ξ»x, (fβ x, fβ x)) g l β is_O fβ g l β§ is_O fβ g l :=
begin
split,
{ assume h,
split,
{ exact is_O.trans (is_O.prod_rightl (is_O_refl fβ l)) h },
{ exact is_O.trans (is_O.prod_rightr (is_O_refl fβ l)) h } },
{ rintros β¨hβ, hββ©,
have : is_O (Ξ»x, β₯fβ xβ₯ + β₯fβ xβ₯) g l :=
is_O.add (is_O_norm_left.2 hβ) (is_O_norm_left.2 hβ),
apply is_O.trans _ this,
refine β¨1, zero_lt_one, filter.univ_mem_sets' (Ξ»x, _)β©,
simp only [norm, max_le_iff, one_mul, set.mem_set_of_eq],
split; exact le_trans (by simp) (le_abs_self _) }
end
@[simp] theorem is_o_prod_left {fβ : Ξ± β Ξ²} {fβ : Ξ± β Ξ΄} {g : Ξ± β Ξ³} {l : filter Ξ±} :
is_o (Ξ»x, (fβ x, fβ x)) g l β is_o fβ g l β§ is_o fβ g l :=
begin
split,
{ assume h,
split,
{ exact is_O.trans_is_o (is_O.prod_rightl (is_O_refl fβ l)) h },
{ exact is_O.trans_is_o (is_O.prod_rightr (is_O_refl fβ l)) h } },
{ rintros β¨hβ, hββ©,
have : is_o (Ξ»x, β₯fβ xβ₯ + β₯fβ xβ₯) g l :=
is_o.add (is_o_norm_left.2 hβ) (is_o_norm_left.2 hβ),
apply is_O.trans_is_o _ this,
refine β¨1, zero_lt_one, filter.univ_mem_sets' (Ξ»x, _)β©,
simp only [norm, max_le_iff, one_mul, set.mem_set_of_eq],
split; exact le_trans (by simp) (le_abs_self _) }
end
end
section
variables [normed_group Ξ²] [normed_group Ξ³]
theorem is_O_zero (g : Ξ± β Ξ³) (l : filter Ξ±) :
is_O (Ξ» x, (0 : Ξ²)) g l :=
β¨1, zero_lt_one, by { filter_upwards [univ_mem_sets], intros x _, simp }β©
theorem is_O_refl_left {f : Ξ± β Ξ²} {g : Ξ± β Ξ³} {l : filter Ξ±} :
is_O (Ξ» x, f x - f x) g l :=
by simpa using is_O_zero g l
theorem is_O_zero_right_iff {f : Ξ± β Ξ²} {l : filter Ξ±} :
is_O f (Ξ» x, (0 : Ξ³)) l β {x | f x = 0} β l :=
begin
rw [is_O_iff], split,
{ rintros β¨c, hcβ©,
filter_upwards [hc], dsimp,
intro x, rw [norm_zero, mul_zero], intro hx,
rw βnorm_eq_zero,
exact le_antisymm hx (norm_nonneg _) },
intro h, use 0,
filter_upwards [h], dsimp,
intros x hx,
rw [hx, norm_zero, zero_mul]
end
theorem is_o_zero (g : Ξ± β Ξ³) (l : filter Ξ±) :
is_o (Ξ» x, (0 : Ξ²)) g l :=
Ξ» c cpos,
by { filter_upwards [univ_mem_sets], intros x _, simp,
exact mul_nonneg (le_of_lt cpos) (norm_nonneg _)}
theorem is_o_refl_left {f : Ξ± β Ξ²} {g : Ξ± β Ξ³} {l : filter Ξ±} :
is_o (Ξ» x, f x - f x) g l :=
by simpa using is_o_zero g l
theorem is_o_zero_right_iff {f : Ξ± β Ξ²} (l : filter Ξ±) :
is_o f (Ξ» x, (0 : Ξ³)) l β {x | f x = 0} β l :=
begin
split,
{ intro h, exact is_O_zero_right_iff.mp h.to_is_O },
intros h c cpos,
filter_upwards [h], dsimp,
intros x hx,
rw [hx, norm_zero, norm_zero, mul_zero]
end
end
section
variables [has_norm Ξ²] [normed_field π]
open normed_field
theorem is_O_const_one (c : Ξ²) (l : filter Ξ±) :
is_O (Ξ» x : Ξ±, c) (Ξ» x, (1 : π)) l :=
begin
rw is_O_iff,
refine β¨β₯cβ₯, _β©,
simp only [norm_one, mul_one],
apply univ_mem_sets',
simp [le_refl],
end
end
section
variables [normed_field π] [normed_group Ξ³]
theorem is_O_const_mul_left {f : Ξ± β π} {g : Ξ± β Ξ³} {l : filter Ξ±} (h : is_O f g l) (c : π) :
is_O (Ξ» x, c * f x) g l :=
begin
cases classical.em (c = 0) with h'' h'',
{ simp [h''], apply is_O_zero },
rcases h with β¨c', c'pos, h'β©,
have cne0 : β₯cβ₯ β 0, from mt (norm_eq_zero _).mp h'',
have cpos : β₯cβ₯ > 0, from lt_of_le_of_ne (norm_nonneg _) (ne.symm cne0),
refine β¨β₯cβ₯ * c', mul_pos cpos c'pos, _β©,
filter_upwards [h'], dsimp,
intros x hβ,
rw [normed_field.norm_mul, mul_assoc],
exact mul_le_mul_of_nonneg_left hβ (norm_nonneg _)
end
theorem is_O_const_mul_left_iff {f : Ξ± β π} {g : Ξ± β Ξ³} {l : filter Ξ±} {c : π} (hc : c β 0) :
is_O (Ξ» x, c * f x) g l β is_O f g l :=
begin
split,
{ intro h,
convert is_O_const_mul_left h cβ»ΒΉ, ext,
rw [βmul_assoc, inv_mul_cancel hc, one_mul] },
intro h, apply is_O_const_mul_left h
end
theorem is_o_const_mul_left {f : Ξ± β π} {g : Ξ± β Ξ³} {l : filter Ξ±} (h : is_o f g l) (c : π) :
is_o (Ξ» x, c * f x) g l :=
begin
cases classical.em (c = 0) with h'' h'',
{ simp [h''], apply is_o_zero },
have cne0 : β₯cβ₯ β 0, from mt (norm_eq_zero _).mp h'',
have cpos : β₯cβ₯ > 0, from lt_of_le_of_ne (norm_nonneg _) (ne.symm cne0),
intros c' c'pos, dsimp,
filter_upwards [h (c' / β₯cβ₯) (div_pos c'pos cpos)], dsimp,
intros x hx, rw [normed_field.norm_mul],
apply le_trans (mul_le_mul_of_nonneg_left hx (le_of_lt cpos)),
rw [βmul_assoc, mul_div_cancel' _ cne0]
end
theorem is_o_const_mul_left_iff {f : Ξ± β π} {g : Ξ± β Ξ³} {l : filter Ξ±} {c : π} (hc : c β 0) :
is_o (Ξ» x, c * f x) g l β is_o f g l :=
begin
split,
{ intro h,
convert is_o_const_mul_left h cβ»ΒΉ, ext,
rw [βmul_assoc, inv_mul_cancel hc, one_mul] },
intro h',
apply is_o_const_mul_left h'
end
end
section
variables [normed_group Ξ²] [normed_field π]
theorem is_O_of_is_O_const_mul_right {f : Ξ± β Ξ²} {g : Ξ± β π} {l : filter Ξ±} {c : π}
(h : is_O f (Ξ» x, c * g x) l) :
is_O f g l :=
begin
cases classical.em (c = 0) with h' h',
{ simp [h', is_O_zero_right_iff] at h, rw is_O_congr_left h, apply is_O_zero },
have cne0 : β₯cβ₯ β 0, from mt (norm_eq_zero _).mp h',
have cpos : β₯cβ₯ > 0, from lt_of_le_of_ne (norm_nonneg _) (ne.symm cne0),
rcases h with β¨c', c'pos, h''β©,
refine β¨c' * β₯cβ₯, mul_pos c'pos cpos, _β©,
convert h'', ext x, dsimp,
rw [normed_field.norm_mul, mul_assoc]
end
theorem is_O_const_mul_right_iff {f : Ξ± β Ξ²} {g : Ξ± β π} {l : filter Ξ±} {c : π} (hc : c β 0) :
is_O f (Ξ» x, c * g x) l β is_O f g l :=
begin
split,
{ intro h, exact is_O_of_is_O_const_mul_right h },
intro h,
apply is_O_of_is_O_const_mul_right,
show is_O f (Ξ» (x : Ξ±), cβ»ΒΉ * (c * g x)) l,
convert h, ext, rw [βmul_assoc, inv_mul_cancel hc, one_mul]
end
theorem is_o_of_is_o_const_mul_right {f : Ξ± β Ξ²} {g : Ξ± β π} {l : filter Ξ±} {c : π}
(h : is_o f (Ξ» x, c * g x) l) :
is_o f g l :=
begin
cases classical.em (c = 0) with h' h',
{ simp [h', is_o_zero_right_iff] at h, rw is_o_congr_left h, apply is_o_zero },
have cne0 : β₯cβ₯ β 0, from mt (norm_eq_zero _).mp h',
have cpos : β₯cβ₯ > 0, from lt_of_le_of_ne (norm_nonneg _) (ne.symm cne0),
intros c' c'pos,
convert h (c' / β₯cβ₯) (div_pos c'pos cpos), dsimp,
ext x, rw [normed_field.norm_mul, βmul_assoc, div_mul_cancel _ cne0]
end
theorem is_o_const_mul_right {f : Ξ± β Ξ²} {g : Ξ± β π} {l : filter Ξ±} {c : π} (hc : c β 0) :
is_o f (Ξ» x, c * g x) l β is_o f g l :=
begin
split,
{ intro h, exact is_o_of_is_o_const_mul_right h },
intro h,
apply is_o_of_is_o_const_mul_right,
show is_o f (Ξ» (x : Ξ±), cβ»ΒΉ * (c * g x)) l,
convert h, ext, rw [βmul_assoc, inv_mul_cancel hc, one_mul]
end
theorem is_o_one_iff {f : Ξ± β Ξ²} {l : filter Ξ±} :
is_o f (Ξ» x, (1 : π)) l β tendsto f l (π 0) :=
begin
rw [normed_group.tendsto_nhds_zero, is_o], split,
{ intros h e epos,
filter_upwards [h (e / 2) (half_pos epos)], simp,
intros x hx,
exact lt_of_le_of_lt hx (half_lt_self epos) },
intros h e epos,
filter_upwards [h e epos], simp,
intros x hx,
exact le_of_lt hx
end
theorem is_O_one_of_tendsto {f : Ξ± β Ξ²} {l : filter Ξ±} {y : Ξ²}
(h : tendsto f l (π y)) : is_O f (Ξ» x, (1 : π)) l :=
begin
have Iy : β₯yβ₯ < β₯yβ₯ + 1 := lt_add_one _,
refine β¨β₯yβ₯ + 1, lt_of_le_of_lt (norm_nonneg _) Iy, _β©,
simp only [mul_one, normed_field.norm_one],
have : tendsto (Ξ»x, β₯f xβ₯) l (π β₯yβ₯) :=
(continuous_norm.tendsto _).comp h,
exact this (ge_mem_nhds Iy)
end
end
section
variables [normed_group Ξ²] [normed_group Ξ³]
theorem is_O.trans_tendsto {f : Ξ± β Ξ²} {g : Ξ± β Ξ³} {l : filter Ξ±}
(hβ : is_O f g l) (hβ : tendsto g l (π 0)) :
tendsto f l (π 0) :=
(@is_o_one_iff _ _ β _ _ _ _).1 $ hβ.trans_is_o $ is_o_one_iff.2 hβ
theorem is_o.trans_tendsto {f : Ξ± β Ξ²} {g : Ξ± β Ξ³} {l : filter Ξ±}
(hβ : is_o f g l) : tendsto g l (π 0) β tendsto f l (π 0) :=
hβ.to_is_O.trans_tendsto
end
section
variables [normed_field π] [normed_field π']
theorem is_O_mul {fβ fβ : Ξ± β π} {gβ gβ : Ξ± β π'} {l : filter Ξ±}
(hβ : is_O fβ gβ l) (hβ : is_O fβ gβ l) :
is_O (Ξ» x, fβ x * fβ x) (Ξ» x, gβ x * gβ x) l :=
begin
rcases hβ with β¨cβ, cβpos, hcββ©,
rcases hβ with β¨cβ, cβpos, hcββ©,
refine β¨cβ * cβ, mul_pos cβpos cβpos, _β©,
filter_upwards [hcβ, hcβ], dsimp,
intros x hxβ hxβ,
rw [normed_field.norm_mul, normed_field.norm_mul, mul_assoc, mul_left_comm cβ, βmul_assoc],
exact mul_le_mul hxβ hxβ (norm_nonneg _) (mul_nonneg (le_of_lt cβpos) (norm_nonneg _))
end
theorem is_o_mul_left {fβ fβ : Ξ± β π} {gβ gβ : Ξ± β π'} {l : filter Ξ±}
(hβ : is_O fβ gβ l) (hβ : is_o fβ gβ l) :
is_o (Ξ» x, fβ x * fβ x) (Ξ» x, gβ x * gβ x) l :=
begin
intros c cpos,
rcases hβ with β¨cβ, cβpos, hcββ©,
filter_upwards [hcβ, hβ (c / cβ) (div_pos cpos cβpos)], dsimp,
intros x hxβ hxβ,
rw [normed_field.norm_mul, normed_field.norm_mul],
apply le_trans (mul_le_mul hxβ hxβ (norm_nonneg _) (mul_nonneg (le_of_lt cβpos) (norm_nonneg _))),
rw [mul_comm cβ, mul_assoc, mul_left_comm cβ, βmul_assoc _ cβ, div_mul_cancel _ (ne_of_gt cβpos)],
rw [mul_left_comm]
end
theorem is_o_mul_right {fβ fβ : Ξ± β π} {gβ gβ : Ξ± β π'} {l : filter Ξ±}
(hβ : is_o fβ gβ l) (hβ : is_O fβ gβ l) :
is_o (Ξ» x, fβ x * fβ x) (Ξ» x, gβ x * gβ x) l :=
by convert is_o_mul_left hβ hβ; simp only [mul_comm]
theorem is_o_mul {fβ fβ : Ξ± β π} {gβ gβ : Ξ± β π'} {l : filter Ξ±}
(hβ : is_o fβ gβ l) (hβ : is_o fβ gβ l) :
is_o (Ξ» x, fβ x * fβ x) (Ξ» x, gβ x * gβ x) l :=
is_o_mul_left hβ.to_is_O hβ
end
/-
Note: the theorems in the next two sections can also be used for the integers, since
scalar multiplication is multiplication.
-/
section
variables [normed_field π] [normed_group Ξ²] [normed_space π Ξ²] [normed_group Ξ³]
set_option class.instance_max_depth 43
theorem is_O_const_smul_left {f : Ξ± β Ξ²} {g : Ξ± β Ξ³} {l : filter Ξ±} (h : is_O f g l) (c : π) :
is_O (Ξ» x, c β’ f x) g l :=
begin
rw [βis_O_norm_left], simp only [norm_smul],
apply is_O_const_mul_left,
rw [is_O_norm_left],
apply h
end
theorem is_O_const_smul_left_iff {f : Ξ± β Ξ²} {g : Ξ± β Ξ³} {l : filter Ξ±} {c : π} (hc : c β 0) :
is_O (Ξ» x, c β’ f x) g l β is_O f g l :=
begin
have cne0 : β₯cβ₯ β 0, from mt (norm_eq_zero _).mp hc,
rw [βis_O_norm_left], simp only [norm_smul],
rw [is_O_const_mul_left_iff cne0, is_O_norm_left]
end
theorem is_o_const_smul_left {f : Ξ± β Ξ²} {g : Ξ± β Ξ³} {l : filter Ξ±} (h : is_o f g l) (c : π) :
is_o (Ξ» x, c β’ f x) g l :=
begin
rw [βis_o_norm_left], simp only [norm_smul],
apply is_o_const_mul_left,
rw [is_o_norm_left],
apply h
end
theorem is_o_const_smul_left_iff {f : Ξ± β Ξ²} {g : Ξ± β Ξ³} {l : filter Ξ±} {c : π} (hc : c β 0) :
is_o (Ξ» x, c β’ f x) g l β is_o f g l :=
begin
have cne0 : β₯cβ₯ β 0, from mt (norm_eq_zero _).mp hc,
rw [βis_o_norm_left], simp only [norm_smul],
rw [is_o_const_mul_left_iff cne0, is_o_norm_left]
end
end
section
variables [normed_group Ξ²] [normed_field π] [normed_group Ξ³] [normed_space π Ξ³]
set_option class.instance_max_depth 43
theorem is_O_const_smul_right {f : Ξ± β Ξ²} {g : Ξ± β Ξ³} {l : filter Ξ±} {c : π} (hc : c β 0) :
is_O f (Ξ» x, c β’ g x) l β is_O f g l :=
begin
have cne0 : β₯cβ₯ β 0, from mt (norm_eq_zero _).mp hc,
rw [βis_O_norm_right], simp only [norm_smul],
rw [is_O_const_mul_right_iff cne0, is_O_norm_right]
end
theorem is_o_const_smul_right {f : Ξ± β Ξ²} {g : Ξ± β Ξ³} {l : filter Ξ±} {c : π} (hc : c β 0) :
is_o f (Ξ» x, c β’ g x) l β is_o f g l :=
begin
have cne0 : β₯cβ₯ β 0, from mt (norm_eq_zero _).mp hc,
rw [βis_o_norm_right], simp only [norm_smul],
rw [is_o_const_mul_right cne0, is_o_norm_right]
end
end
section
variables [normed_field π] [normed_group Ξ²] [normed_space π Ξ²]
[normed_group Ξ³] [normed_space π Ξ³]
set_option class.instance_max_depth 43
theorem is_O_smul {k : Ξ± β π} {f : Ξ± β Ξ²} {g : Ξ± β Ξ³} {l : filter Ξ±} (h : is_O f g l) :
is_O (Ξ» x, k x β’ f x) (Ξ» x, k x β’ g x) l :=
begin
rw [βis_O_norm_left, βis_O_norm_right], simp only [norm_smul],
apply is_O_mul (is_O_refl _ _),
rw [is_O_norm_left, is_O_norm_right],
exact h
end
theorem is_o_smul {k : Ξ± β π} {f : Ξ± β Ξ²} {g : Ξ± β Ξ³} {l : filter Ξ±} (h : is_o f g l) :
is_o (Ξ» x, k x β’ f x) (Ξ» x, k x β’ g x) l :=
begin
rw [βis_o_norm_left, βis_o_norm_right], simp only [norm_smul],
apply is_o_mul_left (is_O_refl _ _),
rw [is_o_norm_left, is_o_norm_right],
exact h
end
end
section
variables [normed_field π]
theorem tendsto_nhds_zero_of_is_o {f g : Ξ± β π} {l : filter Ξ±} (h : is_o f g l) :
tendsto (Ξ» x, f x / (g x)) l (π 0) :=
have eqβ : is_o (Ξ» x, f x / g x) (Ξ» x, g x / g x) l,
from is_o_mul_right h (is_O_refl _ _),
have eqβ : is_O (Ξ» x, g x / g x) (Ξ» x, (1 : π)) l,
begin
use [1, zero_lt_one],
filter_upwards [univ_mem_sets], simp,
intro x,
cases classical.em (β₯g xβ₯ = 0) with h' h'; simp [h'],
exact zero_le_one
end,
is_o_one_iff.mp (eqβ.trans_is_O eqβ)
private theorem is_o_of_tendsto {f g : Ξ± β π} {l : filter Ξ±}
(hgf : β x, g x = 0 β f x = 0) (h : tendsto (Ξ» x, f x / (g x)) l (π 0)) :
is_o f g l :=
have eqβ : is_o (Ξ» x, f x / (g x)) (Ξ» x, (1 : π)) l,
from is_o_one_iff.mpr h,
have eqβ : is_o (Ξ» x, f x / g x * g x) g l,
by convert is_o_mul_right eqβ (is_O_refl _ _); simp,
have eqβ : is_O f (Ξ» x, f x / g x * g x) l,
begin
use [1, zero_lt_one],
refine filter.univ_mem_sets' (assume x, _),
suffices : β₯f xβ₯ β€ β₯f xβ₯ / β₯g xβ₯ * β₯g xβ₯, { simpa },
by_cases g x = 0,
{ simp only [h, hgf x h, norm_zero, mul_zero] },
{ rw [div_mul_cancel], exact mt (norm_eq_zero _).1 h }
end,
eqβ.trans_is_o eqβ
theorem is_o_iff_tendsto {f g : Ξ± β π} {l : filter Ξ±}
(hgf : β x, g x = 0 β f x = 0) :
is_o f g l β tendsto (Ξ» x, f x / (g x)) l (π 0) :=
iff.intro tendsto_nhds_zero_of_is_o (is_o_of_tendsto hgf)
theorem is_o_pow_pow {m n : β} (h : m < n) :
is_o (Ξ»(x : π), x^n) (Ξ»x, x^m) (π 0) :=
begin
let p := n - m,
have nmp : n = m + p := (nat.add_sub_cancel' (le_of_lt h)).symm,
have : (Ξ»(x : π), x^m) = (Ξ»x, x^m * 1), by simp,
simp only [this, pow_add, nmp],
refine is_o_mul_left (is_O_refl _ _) (is_o_one_iff.2 _),
convert (continuous_pow p).tendsto (0 : π),
exact (zero_pow (nat.sub_pos_of_lt h)).symm
end
theorem is_o_pow_id {n : β} (h : 1 < n) :
is_o (Ξ»(x : π), x^n) (Ξ»x, x) (π 0) :=
by { convert is_o_pow_pow h, simp }
end
end asymptotics
|
ef813cd47ba2e305c68a6d5ed44b1849c97d32e6 | d406927ab5617694ec9ea7001f101b7c9e3d9702 | /archive/imo/imo2005_q3.lean | 2c4acffbb7a1159802a96a67ebf6438efd7cfb2b | [
"Apache-2.0"
] | permissive | alreadydone/mathlib | dc0be621c6c8208c581f5170a8216c5ba6721927 | c982179ec21091d3e102d8a5d9f5fe06c8fafb73 | refs/heads/master | 1,685,523,275,196 | 1,670,184,141,000 | 1,670,184,141,000 | 287,574,545 | 0 | 0 | Apache-2.0 | 1,670,290,714,000 | 1,597,421,623,000 | Lean | UTF-8 | Lean | false | false | 2,806 | lean | /-
Copyright (c) 2021 Manuel Candales. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Manuel Candales
-/
import data.real.basic
import tactic.positivity
/-!
# IMO 2005 Q3
Let `x`, `y` and `z` be positive real numbers such that `xyz β₯ 1`. Prove that:
`(x^5 - x^2)/(x^5 + y^2 + z^2) + (y^5 - y^2)/(y^5 + z^2 + x^2) + (z^5 - z^2)/(z^5 + x^2 + y^2) β₯ 0`
# Solution
The solution by Iurie Boreico from Moldova is presented, which won a special prize during the exam.
The key insight is that `(x^5-x^2)/(x^5+y^2+z^2) β₯ (x^2-y*z)/(x^2+y^2+z^2)`, which is proven by
factoring `(x^5-x^2)/(x^5+y^2+z^2) - (x^5-x^2)/(x^3*(x^2+y^2+z^2))` into a non-negative expression
and then making use of `xyz β₯ 1` to show `(x^5-x^2)/(x^3*(x^2+y^2+z^2)) β₯ (x^2-y*z)/(x^2+y^2+z^2)`.
-/
lemma key_insight (x y z : β) (hx : x > 0) (hy : y > 0) (hz : z > 0) (h : x*y*z β₯ 1) :
(x^5-x^2)/(x^5+y^2+z^2) β₯ (x^2-y*z)/(x^2+y^2+z^2) :=
begin
have hβ : 0 < x^5+y^2+z^2 := by positivity,
have hβ : 0 < x^3 := by positivity,
have hβ : 0 < x^2+y^2+z^2 := by positivity,
have hβ : 0 < x^3*(x^2+y^2+z^2) := by positivity,
have key : (x^5-x^2)/(x^5+y^2+z^2) - (x^5-x^2)/(x^3*(x^2+y^2+z^2))
= ((x^3 - 1)^2*x^2*(y^2 + z^2))/((x^5+y^2+z^2)*(x^3*(x^2+y^2+z^2))),
{ field_simp [hβ.ne', hβ.ne'],
ring },
have hβ
: ((x^3 - 1)^2*x^2*(y^2 + z^2))/((x^5+y^2+z^2)*(x^3*(x^2+y^2+z^2))) β₯ 0 := by positivity,
calc (x^5-x^2)/(x^5+y^2+z^2)
β₯ (x^5-x^2)/(x^3*(x^2+y^2+z^2)) : by linarith [key, hβ
]
... β₯ (x^5-x^2*(x*y*z))/(x^3*(x^2+y^2+z^2)) :
by { refine (div_le_div_right hβ).mpr _, simp,
exact (le_mul_iff_one_le_right (pow_pos hx 2)).mpr h }
... = (x^2-y*z)/(x^2+y^2+z^2) :
by { field_simp [hβ.ne', hβ.ne'], ring },
end
theorem imo2005_q3 (x y z : β) (hx : x > 0) (hy : y > 0) (hz : z > 0) (h : x*y*z β₯ 1) :
(x^5-x^2)/(x^5+y^2+z^2) + (y^5-y^2)/(y^5+z^2+x^2) + (z^5-z^2)/(z^5+x^2+y^2) β₯ 0 :=
begin
calc (x^5-x^2)/(x^5+y^2+z^2) + (y^5-y^2)/(y^5+z^2+x^2) + (z^5-z^2)/(z^5+x^2+y^2)
β₯ (x^2-y*z)/(x^2+y^2+z^2) + (y^2-z*x)/(y^2+z^2+x^2) + (z^2-x*y)/(z^2+x^2+y^2) :
by { linarith [key_insight x y z hx hy hz h,
key_insight y z x hy hz hx (by linarith [h]),
key_insight z x y hz hx hy (by linarith [h])] }
... = 1/2*( (x-y)^2 + (y-z)^2 + (z-x)^2 ) / (x^2+y^2+z^2) :
by { have hβ : y^2+z^2+x^2 = x^2+y^2+z^2, ring,
have hβ : z^2+x^2+y^2 = x^2+y^2+z^2, ring,
rw [hβ, hβ], ring }
... β₯ 0 :
by { exact div_nonneg
(by linarith [sq_nonneg (x-y), sq_nonneg (y-z), sq_nonneg (z-x)])
(by linarith [sq_nonneg x, sq_nonneg y, sq_nonneg z]) },
end
|
e62e6139f0a1fcb1edc2e8bc964759c2e7369aba | 75db7e3219bba2fbf41bf5b905f34fcb3c6ca3f2 | /hott/types/int/hott.hlean | 073439408ef25e6ce7189e43aa99d4e8c376e34e | [
"Apache-2.0"
] | permissive | jroesch/lean | 30ef0860fa905d35b9ad6f76de1a4f65c9af6871 | 3de4ec1a6ce9a960feb2a48eeea8b53246fa34f2 | refs/heads/master | 1,586,090,835,348 | 1,455,142,203,000 | 1,455,142,277,000 | 51,536,958 | 1 | 0 | null | 1,455,215,811,000 | 1,455,215,811,000 | null | UTF-8 | Lean | false | false | 5,816 | 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 integers specific to HoTT
-/
import .basic types.eq arity algebra.bundled
open core eq is_equiv equiv equiv.ops algebra is_trunc
open nat (hiding pred)
namespace int
section
open algebra
definition group_integers : Group :=
Group.mk β€ (group_of_add_group _)
end
definition is_equiv_succ [instance] : is_equiv succ :=
adjointify succ pred (Ξ»a, !add_sub_cancel) (Ξ»a, !sub_add_cancel)
definition equiv_succ : β€ β β€ := equiv.mk succ _
definition is_equiv_neg [instance] : is_equiv (neg : β€ β β€) :=
adjointify neg neg (Ξ»x, !neg_neg) (Ξ»a, !neg_neg)
definition equiv_neg : β€ β β€ := equiv.mk neg _
definition iterate {A : Type} (f : A β A) (a : β€) : A β A :=
rec_nat_on a erfl
(Ξ»b g, f β¬e g)
(Ξ»b g, g β¬e fβ»ΒΉα΅)
-- definition iterate_trans {A : Type} (f : A β A) (a : β€)
-- : iterate f a β¬e f = iterate f (a + 1) :=
-- sorry
-- definition trans_iterate {A : Type} (f : A β A) (a : β€)
-- : f β¬e iterate f a = iterate f (a + 1) :=
-- sorry
-- definition iterate_trans_symm {A : Type} (f : A β A) (a : β€)
-- : iterate f a β¬e fβ»ΒΉe = iterate f (a - 1) :=
-- sorry
-- definition symm_trans_iterate {A : Type} (f : A β A) (a : β€)
-- : fβ»ΒΉe β¬e iterate f a = iterate f (a - 1) :=
-- sorry
-- definition iterate_neg {A : Type} (f : A β A) (a : β€)
-- : iterate f (-a) = (iterate f a)β»ΒΉe :=
-- rec_nat_on a idp
-- (Ξ»n p, calc
-- iterate f (-succ n) = iterate f (-n) β¬e fβ»ΒΉe : rec_nat_on_neg
-- ... = (iterate f n)β»ΒΉe β¬e fβ»ΒΉe : by rewrite p
-- ... = (f β¬e iterate f n)β»ΒΉe : sorry
-- ... = (iterate f (succ n))β»ΒΉe : idp)
-- sorry
-- definition iterate_add {A : Type} (f : A β A) (a b : β€)
-- : iterate f (a + b) = equiv.trans (iterate f a) (iterate f b) :=
-- sorry
-- definition iterate_sub {A : Type} (f : A β A) (a b : β€)
-- : iterate f (a - b) = equiv.trans (iterate f a) (equiv.symm (iterate f b)) :=
-- sorry
-- definition iterate_mul {A : Type} (f : A β A) (a b : β€)
-- : iterate f (a * b) = iterate (iterate f a) b :=
-- sorry
end int open int
namespace eq
variables {A : Type} {a : A} (p : a = a) (b c : β€) (n : β)
definition power : a = a :=
rec_nat_on b idp
(Ξ»c q, q β¬ p)
(Ξ»c q, q β¬ pβ»ΒΉ)
--iterate (equiv_eq_closed_right p a) b idp
-- definition power_neg_succ (n : β) : power p (-succ n) = power p (-n) β¬ pβ»ΒΉ :=
-- !rec_nat_on_neg
-- local attribute nat.add int.add int.of_num nat.of_num int.succ [constructor]
definition power_con : power p b β¬ p = power p (succ b) :=
rec_nat_on b
idp
(Ξ»n IH, idp)
(Ξ»n IH, calc
power p (-succ n) β¬ p
= (power p (-int.of_nat n) β¬ pβ»ΒΉ) β¬ p : by rewrite [βpower,-rec_nat_on_neg]
... = power p (-int.of_nat n) : inv_con_cancel_right
... = power p (succ (-succ n)) : by rewrite -succ_neg_succ)
definition power_con_inv : power p b β¬ pβ»ΒΉ = power p (pred b) :=
rec_nat_on b
idp
(Ξ»n IH, calc
power p (succ n) β¬ pβ»ΒΉ = power p n : by apply con_inv_cancel_right
... = power p (pred (succ n)) : by rewrite pred_nat_succ)
(Ξ»n IH, calc
power p (-int.of_nat (succ n)) β¬ pβ»ΒΉ
= power p (-int.of_nat (succ (succ n))) : by rewrite [βpower,-rec_nat_on_neg]
... = power p (pred (-succ n)) : by rewrite -neg_succ)
definition con_power : p β¬ power p b = power p (succ b) :=
rec_nat_on b
( by rewrite β[power];exact !idp_conβ»ΒΉ)
( Ξ»n IH, proof calc
p β¬ power p (succ n) = (p β¬ power p n) β¬ p : con.assoc p _ p
... = power p (succ (succ n)) : by rewrite IH qed)
( Ξ»n IH, calc
p β¬ power p (-int.of_nat (succ n))
= p β¬ (power p (-int.of_nat n) β¬ pβ»ΒΉ) : by rewrite [βpower, rec_nat_on_neg]
... = (p β¬ power p (-int.of_nat n)) β¬ pβ»ΒΉ : con.assoc
... = power p (succ (-int.of_nat n)) β¬ pβ»ΒΉ : by rewrite IH
... = power p (pred (succ (-int.of_nat n))) : power_con_inv
... = power p (succ (-int.of_nat (succ n))) : by rewrite [succ_neg_nat_succ,int.pred_succ])
definition inv_con_power : pβ»ΒΉ β¬ power p b = power p (pred b) :=
rec_nat_on b
( by rewrite β[power];exact !idp_conβ»ΒΉ)
(Ξ»n IH, calc
pβ»ΒΉ β¬ power p (succ n) = pβ»ΒΉ β¬ power p n β¬ p : con.assoc
... = power p (pred n) β¬ p : by rewrite IH
... = power p (succ (pred n)) : power_con
... = power p (pred (succ n)) : by rewrite [succ_pred,-int.pred_succ n])
( Ξ»n IH, calc
pβ»ΒΉ β¬ power p (-int.of_nat (succ n))
= pβ»ΒΉ β¬ (power p (-int.of_nat n) β¬ pβ»ΒΉ) : by rewrite [βpower,rec_nat_on_neg]
... = (pβ»ΒΉ β¬ power p (-int.of_nat n)) β¬ pβ»ΒΉ : con.assoc
... = power p (pred (-int.of_nat n)) β¬ pβ»ΒΉ : by rewrite IH
... = power p (-int.of_nat (succ n)) β¬ pβ»ΒΉ : by rewrite -neg_succ
... = power p (-succ (succ n)) : by rewrite [βpower,-rec_nat_on_neg]
... = power p (pred (-succ n)) : by rewrite -neg_succ)
definition power_con_power : Ξ (b : β€), power p b β¬ power p c = power p (b + c) :=
rec_nat_on c
(Ξ»b, by rewrite int.add_zero)
(Ξ»n IH b, by rewrite [-con_power,-con.assoc,power_con,IH,βsucc,add.assoc,
add.comm (int.of_nat n)])
(Ξ»n IH b, by rewrite [neg_nat_succ,-inv_con_power,-con.assoc,power_con_inv,IH,βpred,
+sub_eq_add_neg,add.assoc,add.comm (-n)])
end eq
|
1e7c5f86eeb2e64fb0b2837b414e0528dcc58c97 | 737dc4b96c97368cb66b925eeea3ab633ec3d702 | /src/Lean/Meta/Tactic/Simp/Rewrite.lean | 9e49b85c5e95f99dd85b07babc3c0f9a03fce0b9 | [
"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 | 6,275 | 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.SynthInstance
import Lean.Meta.Tactic.Simp.Types
namespace Lean.Meta.Simp
def synthesizeArgs (lemmaName : Name) (xs : Array Expr) (bis : Array BinderInfo) (discharge? : Expr β SimpM (Option Expr)) : SimpM Bool := do
for x in xs, bi in bis do
let type β inferType x
if bi.isInstImplicit then
unless (β synthesizeInstance x type) do
return false
else if (β instantiateMVars x).isMVar then
if (β isProp type) then
match (β discharge? type) with
| some proof =>
unless (β isDefEq x proof) do
trace[Meta.Tactic.simp.discharge] "{lemmaName}, failed to assign proof{indentExpr type}"
return false
| none =>
trace[Meta.Tactic.simp.discharge] "{lemmaName}, failed to discharge hypotheses{indentExpr type}"
return false
else if (β isClass? type).isSome then
unless (β synthesizeInstance x type) do
return false
return true
where
synthesizeInstance (x type : Expr) : SimpM Bool := do
match (β trySynthInstance type) with
| LOption.some val =>
if (β isDefEq x val) then
return true
else
trace[Meta.Tactic.simp.discharge] "{lemmaName}, failed to assign instance{indentExpr type}"
return false
| _ =>
trace[Meta.Tactic.simp.discharge] "{lemmaName}, failed to synthesize instance{indentExpr type}"
return false
def tryLemma? (e : Expr) (lemma : SimpLemma) (discharge? : Expr β SimpM (Option Expr)) : SimpM (Option Result) :=
withNewMCtxDepth do
let val β lemma.getValue
let type β inferType val
let (xs, bis, type) β forallMetaTelescopeReducing type
let type β whnf (β instantiateMVars type)
let lhs := type.appFn!.appArg!
if (β isDefEq lhs e) then
unless (β synthesizeArgs lemma.getName xs bis discharge?) do
return none
let proof β instantiateMVars (mkAppN val xs)
if β hasAssignableMVar proof then
trace[Meta.Tactic.simp.rewrite] "{lemma}, has unassigned metavariables after unification"
return none
let rhs β instantiateMVars type.appArg!
if e == rhs then
return none
if lemma.perm && !Expr.lt rhs e then
trace[Meta.Tactic.simp.rewrite] "{lemma}, perm rejected {e} ==> {rhs}"
return none
trace[Meta.Tactic.simp.rewrite] "{lemma}, {e} ==> {rhs}"
return some { expr := rhs, proof? := proof }
else
unless lhs.isMVar do
-- We do not report unification failures when `lhs` is a metavariable
-- Example: `x = ()`
-- TODO: reconsider if we want lemmas such as `(x : Unit) β x = ()`
trace[Meta.Tactic.simp.unify] "{lemma}, failed to unify {lhs} with {e}"
return none
/-
Remark: the parameter tag is used for creating trace messages. It is irrelevant otherwise.
-/
def rewrite (e : Expr) (s : DiscrTree SimpLemma) (erased : Std.PHashSet Name) (discharge? : Expr β SimpM (Option Expr)) (tag : String) : SimpM Result := do
let lemmas β s.getMatch e
if lemmas.isEmpty then
trace[Debug.Meta.Tactic.simp] "no theorems found for {tag}-rewriting {e}"
return { expr := e }
else
let lemmas := lemmas.insertionSort fun eβ eβ => eβ.priority < eβ.priority
for lemma in lemmas do
unless inErasedSet lemma do
if let some result β tryLemma? e lemma discharge? then
return result
return { expr := e }
where
inErasedSet (lemma : SimpLemma) : Bool :=
match lemma.name? with
| none => false
| some name => erased.contains name
def rewriteCtorEq? (e : Expr) : MetaM (Option Result) := withReducibleAndInstances do
match e.eq? with
| none => return none
| some (_, lhs, rhs) =>
let lhs β whnf lhs
let rhs β whnf rhs
let env β getEnv
match lhs.constructorApp? env, rhs.constructorApp? env with
| some (cβ, _), some (cβ, _) =>
if cβ.name != cβ.name then
withLocalDeclD `h e fun h =>
return some { expr := mkConst ``False, proof? := (β mkEqFalse' (β mkLambdaFVars #[h] (β mkNoConfusion (mkConst ``False) h))) }
else
return none
| _, _ => return none
@[inline] def tryRewriteCtorEq (e : Expr) (x : SimpM Step) : SimpM Step := do
match (β rewriteCtorEq? e) with
| some r => return Step.done r
| none => x
def rewriteUsingDecide? (e : Expr) : MetaM (Option Result) := withReducibleAndInstances do
if e.hasFVar || e.hasMVar || e.isConstOf ``True || e.isConstOf ``False then
return none
else
try
let d β mkDecide e
let r β withDefault <| whnf d
if r.isConstOf ``true then
return some { expr := mkConst ``True, proof? := mkAppN (mkConst ``eq_true_of_decide) #[e, d.appArg!, (β mkEqRefl (mkConst ``true))] }
else if r.isConstOf ``false then
let h β mkEqRefl d
return some { expr := mkConst ``False, proof? := mkAppN (mkConst ``eq_false_of_decide) #[e, d.appArg!, (β mkEqRefl (mkConst ``false))] }
else
return none
catch _ =>
return none
@[inline] def tryRewriteUsingDecide (e : Expr) (x : SimpM Step) : SimpM Step := do
if (β read).config.decide then
match (β rewriteUsingDecide? e) with
| some r => return Step.done r
| none => x
else
x
def rewritePre (e : Expr) (discharge? : Expr β SimpM (Option Expr)) : SimpM Step := do
let lemmas β (β read).simpLemmas
return Step.visit (β rewrite e lemmas.pre lemmas.erased discharge? (tag := "pre"))
def rewritePost (e : Expr) (discharge? : Expr β SimpM (Option Expr)) : SimpM Step := do
let lemmas β (β read).simpLemmas
return Step.visit (β rewrite e lemmas.post lemmas.erased discharge? (tag := "post"))
def preDefault (e : Expr) (discharge? : Expr β SimpM (Option Expr)) : SimpM Step :=
tryRewriteCtorEq e <| rewritePre e discharge?
def postDefault (e : Expr) (discharge? : Expr β SimpM (Option Expr)) : SimpM Step := do
-- TODO: try equation lemmas
tryRewriteCtorEq e <| tryRewriteUsingDecide e <| rewritePost e discharge?
end Lean.Meta.Simp
|
5af573c9725d5b11bfc1e615725a4a833c65608a | ad3e8f15221a986da27c99f371922c0b3f5792b6 | /src/week04/e01_groups.lean | 1bf6cf11a9a62ca4ad5fbefff9a8851585d243ac | [] | no_license | VArtem/lean-itmo | a0e1424c8cc4c2de2ac85ab6fd4a12d80e9b85f1 | dc44cd06f9f5b984d051831b3aaa7364e64c2dc4 | refs/heads/main | 1,683,761,214,467 | 1,622,821,295,000 | 1,622,821,295,000 | 357,236,048 | 12 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 8,184 | lean | import tactic
-- ΠΡΠΎΡ ΡΠ°ΠΉΠ» ΠΏΠ΅ΡΠ΅Π²Π΅Π΄Π΅Π½ ΠΈ Π°Π΄Π°ΠΏΡΠΈΡΠΎΠ²Π°Π½ ΠΈΠ· Π²ΡΠΎΡΠΎΠΉ Π½Π΅Π΄Π΅Π»ΠΈ ΠΊΡΡΡΠ° Formalising Mathematics: https://github.com/ImperialCollegeLondon/formalising-mathematics/tree/master/src/week_2
-- Π’Π°ΠΌ ΠΆΠ΅ Π΅ΡΡΡ ΠΏΡΠΎΠ΄ΠΎΠ»ΠΆΠ΅Π½ΠΈΠ΅ ΠΏΡΠΎ ΠΏΠΎΠ΄Π³ΡΡΠΏΠΏΡ, ΡΠΊΠ°ΡΠ°ΠΉΡΠ΅ ΡΠ΅ΠΏΠΎΠ·ΠΈΡΠΎΡΠΈΠΉ Ρ ΠΏΠΎΠΌΠΎΡΡΡ
-- `leanproject get ImperialCollegeLondon/formalising-mathematics`
-- Π ΡΠ°ΠΌΠΎΡΡΠΎΡΡΠ΅Π»ΡΠ½ΠΎ ΠΏΡΠΎΠΉΠ΄ΠΈΡΠ΅ ΡΠΎ, ΡΡΠΎ ΡΠ°ΠΌ Π΅ΡΡΡ
namespace itmo.lean
/-
ΠΠΏΡΠ΅Π΄Π΅Π»ΠΈΠΌ Π³ΡΡΠΏΠΏΡ ΠΊΠ°ΠΊ ΡΠ°ΠΉΠΏΠΊΠ»Π°ΡΡ (ΠΏΠΎΠ΄ΡΠΎΠ±Π½Π΅Π΅: https://leanprover.github.io/theorem_proving_in_lean/type_classes.html), ΡΠ°ΡΡΠΈΡΡΡΡΠΈΠΉ `has_mul`, `has_one` ΠΈ `has_inv`.
`has_mul G` ΠΎΠ·Π½Π°ΡΠ°Π΅Ρ, ΡΡΠΎ Π½Π° `G` ΠΎΠΏΡΠ΅Π΄Π΅Π»Π΅Π½ΠΎ ΡΠΌΠ½ΠΎΠΆΠ΅Π½ΠΈΠ΅ `* : G β G β G`
`has_one G` ΠΎΠ·Π½Π°ΡΠ°Π΅Ρ, ΡΡΠΎ Π² `G` Π΅ΡΡΡ Π΅Π΄ΠΈΠ½ΠΈΡΠ° `1 : G`
`has_inv G` ΠΎΠ·Π½Π°ΡΠ°Π΅Ρ, ΡΡΠΎ Π΅ΡΡΡ ΡΡΠ½ΠΊΡΠΈΡ, Π²ΡΠ΄Π°ΡΡΠ°Ρ ΠΎΠ±ΡΠ°ΡΠ½ΡΠΉ Π΄Π»Ρ ΡΠ»Π΅ΠΌΠ΅Π½ΡΠ° `G`: `β»ΒΉ : G β G`
ΠΡΠ΅ ΡΡΠΈ ΠΎΠΏΡΠ΅Π΄Π΅Π»Π΅Π½ΠΈΡ - ΠΏΡΠΎΡΡΠΎ Π½ΠΎΡΠ°ΡΠΈΡ, ΡΠ²ΠΎΠΉΡΡΠ²Π° ΠΈ Π²Π·Π°ΠΈΠΌΠΎΠ΄Π΅ΠΉΡΡΠ²ΠΈΠ΅ ΡΡΠΈΡ
ΡΡΠ½ΠΊΡΠΈΠΉ Π½Π°Π΄ΠΎ Π±ΡΠ΄Π΅Ρ Π΄ΠΎΠ±Π°Π²ΠΈΡΡ. ΠΠΏΡΠ΅Π΄Π΅Π»ΠΈΠΌ ΠΊΠ»Π°ΡΡ `group` Ρ Π°ΠΊΡΠΈΠΎΠΌΠ°ΠΌΠΈ Π³ΡΡΠΏΠΏ:
-/
class group (G : Type) extends has_mul G, has_one G, has_inv G :=
(mul_assoc : β (a b c : G), a * b * c = a * (b * c))
(one_mul : β (a : G), 1 * a = a)
(mul_left_inv : β (a : G), aβ»ΒΉ * a = 1)
/-
Π€ΠΎΡΠΌΠ°Π»ΡΠ½ΠΎ, `group G` ΡΡΠΎ ΡΡΡΡΠΊΡΡΡΠ°, Π² ΠΊΠΎΡΠΎΡΠΎΠΉ Π΅ΡΡΡ ΡΠΌΠ½ΠΎΠΆΠ΅Π½ΠΈΠ΅, 1, ΠΎΠ±ΡΠ°ΡΠ½ΡΠΉ ΡΠ»Π΅ΠΌΠ΅Π½Ρ, ΠΈ Π΄ΠΎΠΊΠ°Π·Π°ΡΠ΅Π»ΡΡΡΠ²Π° Π°ΠΊΡΠΈΠΎΠΌ Π³ΡΡΠΏΠΏ. ΠΠΎΡΠΊΠΎΠ»ΡΠΊΡ `group G` ΡΡΠΎ ΡΠ°ΠΉΠΏΠΊΠ»Π°ΡΡ, ΡΠΎ Π΄ΠΎΠ±Π°Π²ΠΈΡΡ Π² ΡΠΈΠ³Π½Π°ΡΡΡΡ ΡΡΠ½ΠΊΡΠΈΠΈ "ΠΏΡΡΡΡ `G` - Π³ΡΡΠΏΠΏΠ°" Π½ΡΠΆΠ½ΠΎ, ΠΊΠ°ΠΊ `(G : Type) [group G]`. ΠΠ²Π°Π΄ΡΠ°ΡΠ½ΡΠ΅ ΡΠΊΠΎΠ±ΠΊΠΈ ΠΈΡΠΏΠΎΠ»ΡΠ·ΡΡΡΡΡ Π΄Π»Ρ ΡΠ°ΠΉΠΏΠΊΠ»Π°ΡΡΠΎΠ² ΠΈ Π°Π²ΡΠΎΠΌΠ°ΡΠΈΡΠ΅ΡΠΊΠΈ (Π½Π°ΡΠΊΠΎΠ»ΡΠΊΠΎ ΠΏΠΎΠ»ΡΡΠΈΡΡΡ) Π½Π°Ρ
ΠΎΠ΄ΡΡΡΡ ΡΠΎΠΎΡΠ²Π΅ΡΡΡΠ²ΡΡΡΠΈΠ΅ ΠΈΠ½ΡΡΠ°Π½ΡΡ Π΄Π»Ρ `G`.
ΠΠ±ΡΠ°ΡΠΈΡΠ΅ Π²Π½ΠΈΠΌΠ°Π½ΠΈΠ΅, ΡΡΠΎ Π½Π°Π±ΠΎΡ ΠΈΡΠΏΠΎΠ»ΡΠ·ΠΎΠ²Π°Π½Π½ΡΡ
Π°ΠΊΡΠΈΠΎΠΌ ΠΌΠΈΠ½ΠΈΠΌΠ°Π»Π΅Π½, Π½Π°ΠΏΡΠΈΠΌΠ΅Ρ, Π½Π΅Ρ Π°ΠΊΡΠΈΠΎΠΌ
`mul_one : β (a : G), a * 1 = a` ΠΈ
`mul_right_inv : β (a : G), a * aβ»ΒΉ = 1`.
ΠΠ° ΡΠ°ΠΌΠΎΠΌ Π΄Π΅Π»Π΅, ΡΡΠΈ Π°ΠΊΡΠΈΠΎΠΌΡ ΡΠ»Π΅Π΄ΡΡΡ ΠΈΠ· ΠΎΡΠ½ΠΎΠ²Π½ΡΡ
, ΠΈ ΠΌΡ ΡΡΠΎ Π΄ΠΎΠΊΠ°ΠΆΠ΅ΠΌ.
-/
namespace group
variables {G : Type} [group G]
lemma mul_left_cancel (a b c : G) (Habac : a * b = a * c) : b = c :=
begin
sorry,
end
-- ΠΠΎΠΊΠ°Π·Π°ΡΠ΅Π»ΡΡΡΠ²Π° ΠΈΠ· Π΄Π»ΠΈΠ½Π½ΡΡ
ΡΠ΅ΠΏΠΎΡΠ΅ΠΊ ΡΠ°Π²Π΅Π½ΡΡΠ² ΠΈΠ»ΠΈ Π½Π΅ΡΠ°Π²Π΅Π½ΡΡΠ² ΡΠ°ΡΡΠΎ ΠΌΠΎΠΆΠ½ΠΎ Π·Π°ΠΌΠ΅Π½ΠΈΡΡ Π½Π° `calc` (ΡΠΏΡΠ°Π²ΠΊΠ° ΠΏΠΎ `calc`: https://leanprover-community.github.io/extras/calc.html)
-- ΠΡΠΈΠΌΠ΅Ρ ΡΠ΅ΡΠ΅Π½ΠΈΡ Π·Π°Π΄Π°ΡΠΈ Ρ IMO 2020 Ρ ΠΈΡΠΏΠΎΠ»ΡΠ·ΠΎΠ²Π°Π½ΠΈΠ΅ΠΌ `calc`: https://github.com/leanprover-community/mathlib/blob/master/archive/imo/imo2020_q2.lean
example (a b c : G) (Habac : a * b = a * c) : b = c :=
begin
calc b = 1 * b : by rw one_mul
... = (aβ»ΒΉ * a) * b : by rw β mul_left_inv a
... = aβ»ΒΉ * (a * b) : by rw β mul_assoc
... = aβ»ΒΉ * (a * c) : by rw Habac
... = (aβ»ΒΉ * a) * c : by rw β mul_assoc
... = 1 * c : by rw mul_left_inv a
... = c : by rw one_mul,
end
lemma mul_eq_of_eq_inv_mul {a x y : G} (h : x = aβ»ΒΉ * y) : a * x = y :=
begin
sorry,
end
variables (a b c x y : G)
/-
ΠΠΎΠΏΡΠΎΠ±ΡΠΉΡΠ΅ Π½Π°ΡΠ°ΡΡ Π΄ΠΎΠΊΠ°Π·Π°ΡΠ΅Π»ΡΡΡΠ²ΠΎ Ρ `apply mul_eq_of_eq_inv_mul`.
-/
@[simp] theorem mul_one : a * 1 = a :=
begin
sorry,
end
@[simp] theorem mul_right_inv : a * aβ»ΒΉ = 1 :=
begin
sorry,
end
/-
Π₯ΠΎΡΠΎΡΠ΅ΠΉ ΠΈΠ΄Π΅Π΅ΠΉ Π±ΡΠ»ΠΎ Π±Ρ Π½Π°ΡΡΠΈΡΡ `simp` ΡΠ°Π±ΠΎΡΠ°ΡΡ Ρ Π»Π΅ΠΌΠΌΠ°ΠΌΠΈ Π²ΠΈΠ΄Π° `A = B` ΠΈΠ»ΠΈ `A β B`, ΠΊΠΎΡΠΎΡΡΠ΅ ΠΌΡ ΠΎΠΏΠΈΡΠ°Π»ΠΈ Π²ΡΡΠ΅. ΠΠ»Ρ ΡΡΠΎΠ³ΠΎ ΠΌΡ Π½Π°ΠΏΠΈΡΠ°Π»ΠΈ Π°ΡΡΠΈΠ±ΡΡ `@[simp]` ΠΏΠ΅ΡΠ΅Π΄ Π»Π΅ΠΌΠΌΠΎΠΉ. Π ΠΈΠ΄Π΅Π°Π»Π΅, Ρ
ΠΎΡΠ΅ΡΡΡ, ΡΡΠΎΠ±Ρ ΡΠ°Π²Π΅Π½ΡΡΠ²Π° Π² Π³ΡΡΠΏΠΏΠ°Ρ
ΡΠ΅ΡΠ°Π»ΠΈΡΡ Π°Π²ΡΠΎΠΌΠ°ΡΠΈΡΠ΅ΡΠΊΠΈ:
`example : (a * b) * 1β»ΒΉβ»ΒΉ * bβ»ΒΉ * (aβ»ΒΉ * aβ»ΒΉβ»ΒΉβ»ΒΉ) * a = 1`
Π’Π°ΠΊΡΠΈΠΊΠ° `simp` Π±ΡΠ΄Π΅Ρ ΠΏΡΡΠ°ΡΡΡΡ "ΡΠΏΡΠΎΡΡΠΈΡΡ" ΡΠ΅Π»Ρ ΠΊΠ°ΠΊ ΠΌΠΎΠΆΠ½ΠΎ Π±ΠΎΠ»ΡΡΠ΅, Π² ΠΈΠ΄Π΅Π°Π»Π΅ Π·Π°ΠΊΡΡΡΡ ΡΠ΅Π»Ρ Ρ ΠΏΠΎΠΌΠΎΡΡΡ ΠΈΠ·Π²Π΅ΡΡΠ½ΡΡ
Π΅ΠΉ Π»Π΅ΠΌΠΌ. `simp` ΡΠ°Π±ΠΎΡΠ°Π΅Ρ ΠΏΠ΅ΡΠ΅ΠΏΠΈΡΡΠ²Π°Π½ΠΈΡΠΌΠΈ, ΡΠΎΠ»ΡΠΊΠΎ ΠΈΡΠΏΠΎΠ»ΡΠ·ΡΡ ΠΏΠ΅ΡΠ΅ΠΏΠΈΡΡΠ²Π°Π½ΠΈΡ ΡΠ»Π΅Π²Π° Π½Π°ΠΏΡΠ°Π²ΠΎ (Π΅ΡΠ»ΠΈ Ρ
ΠΎΡΠ΅ΡΡΡ ΠΈΠ·ΠΌΠ΅Π½ΠΈΡΡ Π½Π°ΠΏΡΠ°Π²Π»Π΅Π½ΠΈΠ΅, ΠΌΠΎΠΆΠ½ΠΎ Π΄Π°ΡΡ Π΄ΠΎΠΏΠΎΠ»Π½ΠΈΡΠ΅Π»ΡΠ½ΡΠΉ Π°ΡΠ³ΡΠΌΠ΅Π½Ρ `simp [β h] at ...`). ΠΠΎΡΡΠΎΠΌΡ, Π² ΡΠΎΠΆΠ΄Π΅ΡΡΠ²Π°Ρ
, ΠΏΠΎΠΌΠ΅ΡΠ΅Π½Π½ΡΡ
`simp`, ΠΏΡΠ°Π²Π°Ρ ΡΠ°ΡΡΡ Π΄ΠΎΠ»ΠΆΠ½Π° Π±ΡΡΡ "ΠΏΡΠΎΡΠ΅", ΡΠ΅ΠΌ Π»Π΅Π²Π°Ρ. Π ΡΠ°ΡΡΠ½ΠΎΡΡΠΈ, `add_comm (a b : β) : a + b = b + a` - ΠΏΠ»ΠΎΡ
Π°Ρ Π»Π΅ΠΌΠΌΠ° Π΄Π»Ρ `simp`. ΠΠ±ΡΠ°ΡΠΈΡΠ΅ Π²Π½ΠΈΠΌΠ°Π½ΠΈΠ΅, ΡΡΠΎ Π²ΠΎ Π²ΡΠ΅Ρ
Π»Π΅ΠΌΠΌΠ°Ρ
Π²ΡΡΠ΅, Π½Π°ΠΏΡΠΈΠΌΠ΅Ρ,
`@[simp] theorem mul_one (a : G) : a * 1 = a`
`@[simp] theorem mul_right_inv (a : G) : a * aβ»ΒΉ = 1`
ΠΏΡΠ°Π²Π°Ρ ΡΠ°ΡΡΡ ΠΏΡΠΎΡΠ΅ Π»Π΅Π²ΠΎΠΉ. ΠΠΎΠΌΠ΅ΡΠ°ΡΡ ΡΠ°Π²Π΅Π½ΡΡΠ²ΠΎ `a = a * 1` ΡΠ΅Π³ΠΎΠΌ `@[simp]` - ΠΏΠ»ΠΎΡ
Π°Ρ ΠΈΠ΄Π΅Ρ.
Π£ΠΆΠ΅ ΠΎΠΏΡΠ΅Π΄Π΅Π»Π΅Π½Π½ΡΠΌ ΡΡΠ½ΠΊΡΠΈΡΠΌ (ΠΈΠ»ΠΈ ΠΎΠΏΡΠ΅Π΄Π΅Π»Π΅Π½Π½ΡΠΌ Π² Π΄ΡΡΠ³ΠΎΠΌ ΡΠ°ΠΉΠ»Π΅) ΠΌΠΎΠΆΠ½ΠΎ ΡΠ΅ΡΡΠΎΡΠΏΠ΅ΠΊΡΠΈΠ²Π½ΠΎ ΠΏΡΠΎΡΡΠ°Π²ΠΈΡΡ Π°ΡΡΠΈΠ±ΡΡΡ Π²ΡΡΡΠ½ΡΡ.
-/
attribute [simp] one_mul mul_left_inv mul_assoc
/-
ΠΠ°ΡΡΠΈΠΌ `simp` ΠΈΡΠΏΠΎΠ»ΡΠ·ΠΎΠ²Π°ΡΡ ΡΠ»Π΅Π΄ΡΡΡΠΈΠ΅ ΠΏΡΡΡ Π»Π΅ΠΌΠΌ:
`inv_mul_cancel_left : aβ»ΒΉ * (a * b) = b`
`mul_inv_cancel_left : a * (aβ»ΒΉ * b) = b`
`inv_mul : (a * b)β»ΒΉ = bβ»ΒΉ * aβ»ΒΉ`
`one_inv : (1 : G)β»ΒΉ = 1`
`inv_inv : (aβ»ΒΉ)β»ΒΉ = a`
ΠΠ±ΡΠ°ΡΠΈΡΠ΅ Π²Π½ΠΈΠΌΠ°Π½ΠΈΠ΅, ΡΡΠΎ Π²Π΅Π·Π΄Π΅ ΠΏΡΠ°Π²Π°Ρ ΡΠ°ΡΡΡ "ΠΏΡΠΎΡΠ΅" Π»Π΅Π²ΠΎΠΉ.
-/
@[simp] lemma inv_mul_cancel_left : aβ»ΒΉ * (a * b) = b :=
begin
rw β mul_assoc,
-- ΠΠ΄Π΅ΡΡ ΡΠΆΠ΅ `simp` ΡΠΌΠΎΠΆΠ΅Ρ ΠΏΠ΅ΡΠ΅ΠΏΠΈΡΠ°ΡΡ `aβ»ΒΉ * a = 1` ΠΈ `1 * b = b`
simp,
end
@[simp] lemma mul_inv_cancel_left : a * (aβ»ΒΉ * b) = b :=
begin
sorry,
end
@[simp] lemma inv_mul : (a * b)β»ΒΉ = bβ»ΒΉ * aβ»ΒΉ :=
begin
sorry,
end
@[simp] lemma one_inv : (1 : G)β»ΒΉ = 1 :=
begin
sorry,
end
@[simp] lemma inv_inv : a β»ΒΉ β»ΒΉ = a :=
begin
sorry,
end
/-
ΠΡΠΈ 5 Π»Π΅ΠΌΠΌ Π²ΡΠ±ΡΠ°Π½Ρ Π½Π΅ΡΠΏΡΠΎΡΡΠ°: ΡΡΠΎ Π²ΡΠ²ΠΎΠ΄ Π°Π»Π³ΠΎΡΠΈΡΠΌΠ° ΠΠ½ΡΡΠ°-ΠΠ΅Π½Π΄ΠΈΠΊΡΠ° Π΄Π»Ρ ΠΏΠ΅ΡΠ΅ΠΏΠΈΡΡΠ²Π°Π½ΠΈΠΉ Π² Π³ΡΡΠΏΠΏΠ΅:
https://en.wikipedia.org/wiki/Word_problem_(mathematics)#Example:_A_term_rewriting_system_to_decide_the_word_problem_in_the_free_group
-/
-- Π‘Π»ΠΎΠΆΠ½ΡΠΉ ΠΏΡΠΈΠΌΠ΅Ρ ΡΠ΅ΠΏΠ΅ΡΡ ΡΠ΅ΡΠ°Π΅ΡΡΡ Π°Π²ΡΠΎΠΌΠ°ΡΠΈΡΠ΅ΡΠΊΠΈ
example : (a * b) * 1β»ΒΉβ»ΒΉ * bβ»ΒΉ * (aβ»ΒΉ * aβ»ΒΉβ»ΒΉβ»ΒΉ) * a = 1 := by simp
lemma eq_mul_inv_of_mul_eq {a b c : G} (h : a * c = b) : a = b * cβ»ΒΉ :=
begin
sorry,
end
lemma eq_inv_mul_of_mul_eq {a b c : G} (h : b * a = c) : a = bβ»ΒΉ * c :=
begin
sorry,
end
lemma mul_left_eq_self {a b : G} : a * b = b β a = 1 :=
begin
sorry,
end
lemma mul_right_eq_self {a b : G} : a * b = a β b = 1 :=
begin
sorry,
end
lemma eq_inv_of_mul_eq_one {a b : G} (h : a * b = 1) : a = bβ»ΒΉ :=
calc a = a * 1 : by rw mul_one
... = bβ»ΒΉ : by sorry
lemma inv_eq_of_mul_eq_one {a b : G} (h : a * b = 1) : aβ»ΒΉ = b :=
begin
sorry,
end
lemma unique_left_id {e : G} (h : β x : G, e * x = x) : e = 1 :=
begin
sorry,
end
lemma unique_right_inv {a b : G} (h : a * b = 1) : b = aβ»ΒΉ :=
begin
sorry,
end
lemma mul_left_cancel_iff (a x y : G) : a * x = a * y β x = y :=
begin
sorry,
end
lemma mul_right_cancel (a x y : G) (Habac : x * a = y * a) : x = y :=
calc x = x * 1 : by rw mul_one
... = y : by sorry
@[simp] theorem inv_inj_iff {a b : G}: aβ»ΒΉ = bβ»ΒΉ β a = b :=
begin
sorry,
end
theorem inv_eq {a b : G}: aβ»ΒΉ = b β bβ»ΒΉ = a :=
begin
sorry,
end
end group
end itmo.lean
|
a38bf96861259926ab30bf0f9abb44baeafa4dfe | aa5a655c05e5359a70646b7154e7cac59f0b4132 | /stage0/src/Init/Control/Except.lean | a5ca4ae4fd95b6497eba0a7aa6991df43a53a7c6 | [
"Apache-2.0"
] | permissive | lambdaxymox/lean4 | ae943c960a42247e06eff25c35338268d07454cb | 278d47c77270664ef29715faab467feac8a0f446 | refs/heads/master | 1,677,891,867,340 | 1,612,500,005,000 | 1,612,500,005,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 6,137 | lean | /-
Copyright (c) 2017 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jared Roesch, Sebastian Ullrich
The Except monad transformer.
-/
prelude
import Init.Control.Basic
import Init.Control.Id
universes u v w u'
namespace Except
variable {Ξ΅ : Type u}
@[inline] protected def pure {Ξ± : Type v} (a : Ξ±) : Except Ξ΅ Ξ± :=
Except.ok a
@[inline] protected def map {Ξ± Ξ² : Type v} (f : Ξ± β Ξ²) : Except Ξ΅ Ξ± β Except Ξ΅ Ξ²
| Except.error err => Except.error err
| Except.ok v => Except.ok <| f v
@[inline] protected def mapError {Ξ΅' : Type u} {Ξ± : Type v} (f : Ξ΅ β Ξ΅') : Except Ξ΅ Ξ± β Except Ξ΅' Ξ±
| Except.error err => Except.error <| f err
| Except.ok v => Except.ok v
@[inline] protected def bind {Ξ± Ξ² : Type v} (ma : Except Ξ΅ Ξ±) (f : Ξ± β Except Ξ΅ Ξ²) : Except Ξ΅ Ξ² :=
match ma with
| Except.error err => Except.error err
| Except.ok v => f v
@[inline] protected def toBool {Ξ± : Type v} : Except Ξ΅ Ξ± β Bool
| Except.ok _ => true
| Except.error _ => false
@[inline] protected def toOption {Ξ± : Type v} : Except Ξ΅ Ξ± β Option Ξ±
| Except.ok a => some a
| Except.error _ => none
@[inline] protected def tryCatch {Ξ± : Type u} (ma : Except Ξ΅ Ξ±) (handle : Ξ΅ β Except Ξ΅ Ξ±) : Except Ξ΅ Ξ± :=
match ma with
| Except.ok a => Except.ok a
| Except.error e => handle e
instance : Monad (Except Ξ΅) where
pure := Except.pure
bind := Except.bind
map := Except.map
end Except
def ExceptT (Ξ΅ : Type u) (m : Type u β Type v) (Ξ± : Type u) : Type v :=
m (Except Ξ΅ Ξ±)
@[inline] def ExceptT.mk {Ξ΅ : Type u} {m : Type u β Type v} {Ξ± : Type u} (x : m (Except Ξ΅ Ξ±)) : ExceptT Ξ΅ m Ξ± := x
@[inline] def ExceptT.run {Ξ΅ : Type u} {m : Type u β Type v} {Ξ± : Type u} (x : ExceptT Ξ΅ m Ξ±) : m (Except Ξ΅ Ξ±) := x
namespace ExceptT
variable {Ξ΅ : Type u} {m : Type u β Type v} [Monad m]
@[inline] protected def pure {Ξ± : Type u} (a : Ξ±) : ExceptT Ξ΅ m Ξ± :=
ExceptT.mk <| pure (Except.ok a)
@[inline] protected def bindCont {Ξ± Ξ² : Type u} (f : Ξ± β ExceptT Ξ΅ m Ξ²) : Except Ξ΅ Ξ± β m (Except Ξ΅ Ξ²)
| Except.ok a => f a
| Except.error e => pure (Except.error e)
@[inline] protected def bind {Ξ± Ξ² : Type u} (ma : ExceptT Ξ΅ m Ξ±) (f : Ξ± β ExceptT Ξ΅ m Ξ²) : ExceptT Ξ΅ m Ξ² :=
ExceptT.mk <| ma >>= ExceptT.bindCont f
@[inline] protected def map {Ξ± Ξ² : Type u} (f : Ξ± β Ξ²) (x : ExceptT Ξ΅ m Ξ±) : ExceptT Ξ΅ m Ξ² :=
ExceptT.mk <| x >>= fun a => match a with
| (Except.ok a) => pure <| Except.ok (f a)
| (Except.error e) => pure <| Except.error e
@[inline] protected def lift {Ξ± : Type u} (t : m Ξ±) : ExceptT Ξ΅ m Ξ± :=
ExceptT.mk <| Except.ok <$> t
instance : MonadLift (Except Ξ΅) (ExceptT Ξ΅ m) := β¨fun e => ExceptT.mk <| pure eβ©
instance : MonadLift m (ExceptT Ξ΅ m) := β¨ExceptT.liftβ©
@[inline] protected def tryCatch {Ξ± : Type u} (ma : ExceptT Ξ΅ m Ξ±) (handle : Ξ΅ β ExceptT Ξ΅ m Ξ±) : ExceptT Ξ΅ m Ξ± :=
ExceptT.mk <| ma >>= fun res => match res with
| Except.ok a => pure (Except.ok a)
| Except.error e => (handle e)
instance : MonadFunctor m (ExceptT Ξ΅ m) := β¨fun f x => f xβ©
instance : Monad (ExceptT Ξ΅ m) where
pure := ExceptT.pure
bind := ExceptT.bind
map := ExceptT.map
@[inline] protected def adapt {Ξ΅' Ξ± : Type u} (f : Ξ΅ β Ξ΅') : ExceptT Ξ΅ m Ξ± β ExceptT Ξ΅' m Ξ± := fun x =>
ExceptT.mk <| Except.mapError f <$> x
end ExceptT
instance (m : Type u β Type v) (Ξ΅β : Type u) (Ξ΅β : Type u) [Monad m] [MonadExceptOf Ξ΅β m] : MonadExceptOf Ξ΅β (ExceptT Ξ΅β m) where
throw e := ExceptT.mk <| throwThe Ξ΅β e
tryCatch x handle := ExceptT.mk <| tryCatchThe Ξ΅β x handle
instance (m : Type u β Type v) (Ξ΅ : Type u) [Monad m] : MonadExceptOf Ξ΅ (ExceptT Ξ΅ m) where
throw e := ExceptT.mk <| pure (Except.error e)
tryCatch := ExceptT.tryCatch
instance [Monad m] [Inhabited Ξ΅] : Inhabited (ExceptT Ξ΅ m Ξ±) where
default := throw arbitrary
instance (Ξ΅) : MonadExceptOf Ξ΅ (Except Ξ΅) where
throw := Except.error
tryCatch := Except.tryCatch
namespace MonadExcept
variable {Ξ΅ : Type u} {m : Type v β Type w}
/-- Alternative orelse operator that allows to select which exception should be used.
The default is to use the first exception since the standard `orelse` uses the second. -/
@[inline] def orelse' [MonadExcept Ξ΅ m] {Ξ± : Type v} (tβ tβ : m Ξ±) (useFirstEx := true) : m Ξ± :=
tryCatch tβ fun eβ => tryCatch tβ fun eβ => throw (if useFirstEx = true then eβ else eβ)
end MonadExcept
@[inline] def observing {Ξ΅ Ξ± : Type u} {m : Type u β Type v} [Monad m] [MonadExcept Ξ΅ m] (x : m Ξ±) : m (Except Ξ΅ Ξ±) :=
tryCatch (do let a β x; pure (Except.ok a)) (fun ex => pure (Except.error ex))
instance (Ξ΅ : Type u) (m : Type u β Type v) [Monad m] : MonadControl m (ExceptT Ξ΅ m) where
stM := Except Ξ΅
liftWith f := liftM <| f fun x => x.run
restoreM x := x
class MonadFinally (m : Type u β Type v) where
tryFinally' {Ξ± Ξ²} : m Ξ± β (Option Ξ± β m Ξ²) β m (Ξ± Γ Ξ²)
export MonadFinally (tryFinally')
/-- Execute `x` and then execute `finalizer` even if `x` threw an exception -/
@[inline] abbrev tryFinally {m : Type u β Type v} {Ξ± Ξ² : Type u} [MonadFinally m] [Functor m] (x : m Ξ±) (finalizer : m Ξ²) : m Ξ± :=
let y := tryFinally' x (fun _ => finalizer)
(Β·.1) <$> y
instance Id.finally : MonadFinally Id where
tryFinally' := fun x h =>
let a := x
let b := h (some x)
pure (a, b)
instance ExceptT.finally {m : Type u β Type v} {Ξ΅ : Type u} [MonadFinally m] [Monad m] : MonadFinally (ExceptT Ξ΅ m) where
tryFinally' := fun x h => ExceptT.mk do
let r β tryFinally' x fun e? => match e? with
| some (Except.ok a) => h (some a)
| _ => h none
match r with
| (Except.ok a, Except.ok b) => pure (Except.ok (a, b))
| (_, Except.error e) => pure (Except.error e) -- second error has precedence
| (Except.error e, _) => pure (Except.error e)
|
60f7f3dbe97fec7d133048e073fec14a47532b3e | 3618c6e11aa822fd542440674dfb9a7b9921dba0 | /src/exp_sum_eq_zero.lean | 9de7090921b99993d1a22e2301a0067dc3b6c914 | [] | no_license | ChrisHughes24/single_relation | 99ceedcc02d236ce46d6c65d72caa669857533c5 | 057e157a59de6d0e43b50fcb537d66792ec20450 | refs/heads/master | 1,683,652,062,698 | 1,683,360,089,000 | 1,683,360,089,000 | 279,346,432 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 1,693 | lean | import HNN_normalize
import cyclically_reduce
/-!
# Exp sum equal to zero
The case when there is a `t` in the relation with exponent sum equal to zero
## Main definitions
The main definition is `exp_sum_eq_zero`, which solves the word problem in the case
when there is a `t` with exponent_sum 0 in `r`.
-/
open free_group multiplicative P semidirect_product
variables {ΞΉ : Type} [decidable_eq ΞΉ] (T : set ΞΉ) [decidable_pred T]
/-- `exp_sum_eq_zero T t x hs cyc_r` solves the word problem for `cyc_r` and `T`
when `t` has exponent sum zero in `cyc_r`, `cyc_r` is cyclically reduced and
`t β T β x β T` and `x β t` -/
@[inline] meta def exp_sum_eq_zero (t x : ΞΉ)
(hs : Ξ (r : free_group (ΞΉ Γ Cβ)) (T : set (ΞΉ Γ Cβ)) [decidable_pred T], solver r T)
(cyc_r : free_group ΞΉ) : solver cyc_r T :=
Ξ» w,
let (cβ, conj_r) := cyclically_conjugate x cyc_r in
let r' := (add_subscript t conj_r).left in
let (a, b) := min_max_subscript x r' in
do (n, p) β HNN_normalize' t x r' a b hs w,
if t β T
then let T' : set (ΞΉ Γ Cβ) := { i : ΞΉ Γ Cβ | i.1 β T } in
do np β hs r' T' p.right,
return (change_r cβ
--(inr (of' t n) * P.map (remove_subscript t) undefined (P.trans p np)))
--The line for HNN_normalize
(P.map (remove_subscript t) undefined (P.trans p np)) * inr (of' t n))
--The line for HNN_normalize'
-- case t β T
else
-- Kind of silly. Could check if n = 1 before normalization.
guard (n = 1) >>
let T' : set (ΞΉ Γ Cβ) := { i : ΞΉ Γ Cβ | i.1 β T β§ i.2 = 1 } in
do np β hs r' T' p.right,
return (change_r cβ (P.map (remove_subscript t) undefined (P.trans p np)))
|
16127dab440e1d7e9021068e24880202ab25c1c3 | 9d2e3d5a2e2342a283affd97eead310c3b528a24 | /src/solutions/thursday/afternoon/category_theory/exercise7.lean | 8b01590b8a498a4ed38e1fce7e915949cee66af7 | [] | permissive | Vtec234/lftcm2020 | ad2610ab614beefe44acc5622bb4a7fff9a5ea46 | bbbd4c8162f8c2ef602300ab8fdeca231886375d | refs/heads/master | 1,668,808,098,623 | 1,594,989,081,000 | 1,594,990,079,000 | 280,423,039 | 0 | 0 | MIT | 1,594,990,209,000 | 1,594,990,209,000 | null | UTF-8 | Lean | false | false | 2,191 | lean | import category_theory.monoidal.category
import algebra.category.CommRing.basic
/-!
Let's define the category of monoid objects in a monoidal category.
-/
open category_theory
variables (C : Type*) [category C] [monoidal_category C]
structure Mon_in :=
(X : C)
(ΞΉ : π_ C βΆ X)
(ΞΌ : X β X βΆ X)
-- There are three missing axioms here!
-- Use `Ξ»_ X`, `Ο_ X` and `Ξ±_ X Y Z` for unitors and associators.
-- sorry
(ΞΌ_ΞΉ : (Ξ»_ X).inv β« (ΞΉ β π X) β« ΞΌ = π X)
(ΞΉ_ΞΌ : (Ο_ X).inv β« (π X β ΞΉ) β« ΞΌ = π X)
(ΞΌ_assoc : (Ξ±_ X X X).hom β« (π X β ΞΌ) β« ΞΌ = (ΞΌ β π X) β« ΞΌ)
-- sorry
namespace Mon_in
variables {C}
@[ext]
structure hom (M N : Mon_in C) :=
-- sorry
(hom : M.X βΆ N.X)
(ΞΉ_hom' : M.ΞΉ β« hom = N.ΞΉ . obviously)
(ΞΌ_hom' : M.ΞΌ β« hom = (hom β hom) β« N.ΞΌ . obviously)
-- sorry
-- omit
restate_axiom hom.ΞΉ_hom'
restate_axiom hom.ΞΌ_hom'
attribute [simp, reassoc] hom.ΞΉ_hom hom.ΞΌ_hom
@[simps]
def id (M : Mon_in C) : hom M M :=
{ hom := π M.X, }
@[simps]
def comp {M N O : Mon_in C} (f : hom M N) (g : hom N O) : hom M O :=
{ hom := f.hom β« g.hom, }
-- omit
instance : category (Mon_in C) :=
-- sorry
{ hom := Ξ» M N, hom M N,
id := id,
comp := Ξ» M N O f g, comp f g, }
-- sorry
end Mon_in
/-!
Bonus projects (all but the first will be non-trivial with today's mathlib):
* Construct the category of module objects for a fixed monoid object.
* Check that `Mon_in Type β Mon`.
* Check that `Mon_in Mon β CommMon`, via the Eckmann-Hilton argument.
(You'll have to hook up the cartesian monoidal structure on `Mon` first.)
* Check that `Mon_in AddCommGroup β Ring`.
(You'll have to hook up the monoidal structure on `AddCommGroup`.
Currently we have the monoidal structure on `Module R`; perhaps one could specialize to `R = β€`
and transport the monoidal structure across an equivalence? This sounds like some work!)
* Check that `Mon_in (Module R) β Algebra R`.
* Show that if `C` is braided (you'll have to define that first!)
then `Mon_in C` is naturally monoidal.
* Can you transport this monoidal structure to `Ring` or `Algebra R`?
How does it compare to the "native" one?
-/
|
3aa79133f3af17dffd41cbabf6e7e5bdcba67ea8 | 05b503addd423dd68145d68b8cde5cd595d74365 | /src/data/real/nnreal.lean | 1ee328fdeae0e02b84720b9ee7b1a5b41cf67d81 | [
"Apache-2.0"
] | permissive | aestriplex/mathlib | 77513ff2b176d74a3bec114f33b519069788811d | e2fa8b2b1b732d7c25119229e3cdfba8370cb00f | refs/heads/master | 1,621,969,960,692 | 1,586,279,279,000 | 1,586,279,279,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 25,011 | lean | /-
Copyright (c) 2018 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin
Nonnegative real numbers.
-/
import data.real.basic order.lattice algebra.field
noncomputable theory
open_locale classical
/-- Nonnegative real numbers. -/
def nnreal := {r : β // 0 β€ r}
localized "notation ` ββ₯0 ` := nnreal" in nnreal
namespace nnreal
instance : has_coe ββ₯0 β := β¨subtype.valβ©
/- Simp lemma to put back `n.val` into the normal form given by the coercion. -/
@[simp] lemma val_eq_coe (n : nnreal) : n.val = n := rfl
instance : can_lift β nnreal :=
{ coe := coe,
cond := Ξ» r, r β₯ 0,
prf := Ξ» x hx, β¨β¨x, hxβ©, rflβ© }
protected lemma eq {n m : ββ₯0} : (n : β) = (m : β) β n = m := subtype.eq
protected lemma eq_iff {n m : ββ₯0} : (n : β) = (m : β) β n = m :=
iff.intro nnreal.eq (congr_arg coe)
lemma ne_iff {x y : ββ₯0} : (x : β) β (y : β) β x β y :=
not_iff_not_of_iff $ nnreal.eq_iff
protected def of_real (r : β) : ββ₯0 := β¨max r 0, le_max_right _ _β©
lemma coe_of_real (r : β) (hr : 0 β€ r) : (nnreal.of_real r : β) = r :=
max_eq_left hr
lemma le_coe_of_real (r : β) : r β€ nnreal.of_real r :=
le_max_left r 0
lemma coe_nonneg (r : nnreal) : (0 : β) β€ r := r.2
@[elim_cast, simp, nolint simp_nf] -- takes a crazy amount of time simplify lhs
theorem coe_mk (a : β) (ha) : ((β¨a, haβ© : ββ₯0) : β) = a := rfl
instance : has_zero ββ₯0 := β¨β¨0, le_refl 0β©β©
instance : has_one ββ₯0 := β¨β¨1, zero_le_oneβ©β©
instance : has_add ββ₯0 := β¨Ξ»a b, β¨a + b, add_nonneg a.2 b.2β©β©
instance : has_sub ββ₯0 := β¨Ξ»a b, nnreal.of_real (a - b)β©
instance : has_mul ββ₯0 := β¨Ξ»a b, β¨a * b, mul_nonneg a.2 b.2β©β©
instance : has_inv ββ₯0 := β¨Ξ»a, β¨(a.1)β»ΒΉ, inv_nonneg.2 a.2β©β©
instance : has_div ββ₯0 := β¨Ξ»a b, β¨a.1 / b.1, div_nonneg' a.2 b.2β©β©
instance : has_le ββ₯0 := β¨Ξ» r s, (r:β) β€ sβ©
instance : has_bot ββ₯0 := β¨0β©
instance : inhabited ββ₯0 := β¨0β©
@[simp] protected lemma coe_zero : ((0 : ββ₯0) : β) = 0 := rfl
@[simp] protected lemma coe_one : ((1 : ββ₯0) : β) = 1 := rfl
@[simp, move_cast] protected lemma coe_add (rβ rβ : ββ₯0) : ((rβ + rβ : ββ₯0) : β) = rβ + rβ := rfl
@[simp, move_cast] protected lemma coe_mul (rβ rβ : ββ₯0) : ((rβ * rβ : ββ₯0) : β) = rβ * rβ := rfl
@[simp, move_cast] protected lemma coe_div (rβ rβ : ββ₯0) : ((rβ / rβ : ββ₯0) : β) = rβ / rβ := rfl
@[simp, move_cast] protected lemma coe_inv (r : ββ₯0) : ((rβ»ΒΉ : ββ₯0) : β) = rβ»ΒΉ := rfl
@[simp] protected lemma coe_sub {rβ rβ : ββ₯0} (h : rβ β€ rβ) : ((rβ - rβ : ββ₯0) : β) = rβ - rβ :=
max_eq_left $ le_sub.2 $ by simp [show (rβ : β) β€ rβ, from h]
-- TODO: setup semifield!
@[simp] protected lemma zero_div (r : ββ₯0) : 0 / r = 0 := nnreal.eq (zero_div _)
@[simp, elim_cast] protected lemma coe_eq_zero (r : ββ₯0) : βr = (0 : β) β r = 0 := @nnreal.eq_iff r 0
@[elim_cast] lemma coe_ne_zero {r : ββ₯0} : (r : β) β 0 β r β 0 := by simp
instance : comm_semiring ββ₯0 :=
begin
refine { zero := 0, add := (+), one := 1, mul := (*), ..};
{ intros;
apply nnreal.eq;
simp [mul_comm, mul_assoc, add_comm_monoid.add, left_distrib, right_distrib,
add_comm_monoid.zero, add_comm, add_left_comm] }
end
instance : is_semiring_hom (coe : ββ₯0 β β) := by refine_struct {..}; intros; refl
instance : comm_group_with_zero ββ₯0 :=
{ zero_ne_one := assume h, zero_ne_one $ nnreal.eq_iff.2 h,
inv_zero := nnreal.eq $ inv_zero,
mul_inv_cancel := assume x h, nnreal.eq $ mul_inv_cancel $ ne_iff.2 h,
.. (by apply_instance : has_inv ββ₯0),
.. (_ : comm_semiring ββ₯0) }
@[move_cast] lemma coe_pow (r : ββ₯0) (n : β) : ((r^n : ββ₯0) : β) = r^n :=
is_monoid_hom.map_pow coe r n
@[move_cast] lemma coe_list_sum (l : list ββ₯0) :
((l.sum : ββ₯0) : β) = (l.map coe).sum :=
eq.symm $ l.sum_hom coe
@[move_cast] lemma coe_list_prod (l : list ββ₯0) :
((l.prod : ββ₯0) : β) = (l.map coe).prod :=
eq.symm $ l.prod_hom coe
@[move_cast] lemma coe_multiset_sum (s : multiset ββ₯0) :
((s.sum : ββ₯0) : β) = (s.map coe).sum :=
eq.symm $ s.sum_hom coe
@[move_cast] lemma coe_multiset_prod (s : multiset ββ₯0) :
((s.prod : ββ₯0) : β) = (s.map coe).prod :=
eq.symm $ s.prod_hom coe
@[move_cast] lemma coe_sum {Ξ±} {s : finset Ξ±} {f : Ξ± β ββ₯0} :
β(s.sum f) = s.sum (Ξ»a, (f a : β)) :=
eq.symm $ s.sum_hom coe
@[move_cast] lemma coe_prod {Ξ±} {s : finset Ξ±} {f : Ξ± β ββ₯0} :
β(s.prod f) = s.prod (Ξ»a, (f a : β)) :=
eq.symm $ s.prod_hom coe
@[move_cast] lemma smul_coe (r : ββ₯0) (n : β) : β(add_monoid.smul n r) = add_monoid.smul n (r:β) :=
is_add_monoid_hom.map_smul coe r n
@[simp, squash_cast] protected lemma coe_nat_cast (n : β) : (β(βn : ββ₯0) : β) = n :=
(ring_hom.of (coe : ββ₯0 β β)).map_nat_cast n
instance : decidable_linear_order ββ₯0 :=
decidable_linear_order.lift (coe : ββ₯0 β β) subtype.val_injective (by apply_instance)
@[elim_cast] protected lemma coe_le_coe {rβ rβ : ββ₯0} : (rβ : β) β€ rβ β rβ β€ rβ := iff.rfl
@[elim_cast] protected lemma coe_lt_coe {rβ rβ : ββ₯0} : (rβ : β) < rβ β rβ < rβ := iff.rfl
@[elim_cast] protected lemma coe_pos {r : ββ₯0} : (0 : β) < r β 0 < r := iff.rfl
@[elim_cast] protected lemma coe_eq {rβ rβ : ββ₯0} : (rβ : β) = rβ β rβ = rβ := subtype.ext.symm
protected lemma coe_mono : monotone (coe : ββ₯0 β β) := Ξ» _ _, nnreal.coe_le_coe.2
protected lemma of_real_mono : monotone nnreal.of_real :=
Ξ» x y h, max_le_max h (le_refl 0)
@[simp] lemma of_real_coe {r : ββ₯0} : nnreal.of_real r = r :=
nnreal.eq $ max_eq_left r.2
/-- `nnreal.of_real` and `coe : ββ₯0 β β` form a Galois insertion. -/
protected def gi : galois_insertion nnreal.of_real coe :=
galois_insertion.monotone_intro nnreal.coe_mono nnreal.of_real_mono
le_coe_of_real (Ξ» _, of_real_coe)
instance : order_bot ββ₯0 :=
{ bot := β₯, bot_le := assume β¨a, hβ©, h, .. nnreal.decidable_linear_order }
instance : canonically_ordered_monoid ββ₯0 :=
{ add_le_add_left := assume a b h c, @add_le_add_left β _ a b h c,
lt_of_add_lt_add_left := assume a b c, @lt_of_add_lt_add_left β _ a b c,
le_iff_exists_add := assume β¨a, haβ© β¨b, hbβ©,
iff.intro
(assume h : a β€ b,
β¨β¨b - a, le_sub_iff_add_le.2 $ by simp [h]β©,
nnreal.eq $ show b = a + (b - a), by rw [add_sub_cancel'_right]β©)
(assume β¨β¨c, hcβ©, eqβ©, eq.symm βΈ show a β€ a + c, from (le_add_iff_nonneg_right a).2 hc),
..nnreal.comm_semiring,
..nnreal.order_bot,
..nnreal.decidable_linear_order }
instance : distrib_lattice ββ₯0 := by apply_instance
instance : semilattice_inf_bot ββ₯0 :=
{ .. nnreal.order_bot, .. nnreal.distrib_lattice }
instance : semilattice_sup_bot ββ₯0 :=
{ .. nnreal.order_bot, .. nnreal.distrib_lattice }
instance : linear_ordered_semiring ββ₯0 :=
{ add_left_cancel := assume a b c h, nnreal.eq $ @add_left_cancel β _ a b c (nnreal.eq_iff.2 h),
add_right_cancel := assume a b c h, nnreal.eq $ @add_right_cancel β _ a b c (nnreal.eq_iff.2 h),
le_of_add_le_add_left := assume a b c, @le_of_add_le_add_left β _ a b c,
mul_le_mul_of_nonneg_left := assume a b c, @mul_le_mul_of_nonneg_left β _ a b c,
mul_le_mul_of_nonneg_right := assume a b c, @mul_le_mul_of_nonneg_right β _ a b c,
mul_lt_mul_of_pos_left := assume a b c, @mul_lt_mul_of_pos_left β _ a b c,
mul_lt_mul_of_pos_right := assume a b c, @mul_lt_mul_of_pos_right β _ a b c,
zero_lt_one := @zero_lt_one β _,
.. nnreal.decidable_linear_order,
.. nnreal.canonically_ordered_monoid,
.. nnreal.comm_semiring }
instance : canonically_ordered_comm_semiring ββ₯0 :=
{ zero_ne_one := assume h, @zero_ne_one β _ $ congr_arg subtype.val $ h,
mul_eq_zero_iff := assume a b, nnreal.eq_iff.symm.trans $ mul_eq_zero.trans $ by simp,
.. nnreal.linear_ordered_semiring,
.. nnreal.canonically_ordered_monoid,
.. nnreal.comm_semiring }
instance : densely_ordered ββ₯0 :=
β¨assume a b (h : (a : β) < b), let β¨c, hac, hcbβ© := dense h in
β¨β¨c, le_trans a.property $ le_of_lt $ hacβ©, hac, hcbβ©β©
instance : no_top_order ββ₯0 :=
β¨assume a, let β¨b, hbβ© := no_top (a:β) in β¨β¨b, le_trans a.property $ le_of_lt $ hbβ©, hbβ©β©
lemma bdd_above_coe {s : set ββ₯0} : bdd_above ((coe : nnreal β β) '' s) β bdd_above s :=
iff.intro
(assume β¨b, hbβ©, β¨nnreal.of_real b, assume β¨y, hyβ© hys, show y β€ max b 0, from
le_max_left_of_le $ hb $ set.mem_image_of_mem _ hysβ©)
(assume β¨b, hbβ©, β¨b, assume y β¨x, hx, eqβ©, eq βΈ hb hxβ©)
lemma bdd_below_coe (s : set ββ₯0) : bdd_below ((coe : nnreal β β) '' s) :=
β¨0, assume r β¨q, _, eqβ©, eq βΈ q.2β©
instance : has_Sup ββ₯0 :=
β¨Ξ»s, β¨Sup ((coe : nnreal β β) '' s),
begin
cases s.eq_empty_or_nonempty with h h,
{ simp [h, set.image_empty, real.Sup_empty] },
rcases h with β¨β¨b, hbβ©, hbsβ©,
by_cases h' : bdd_above s,
{ exact le_cSup_of_le (bdd_above_coe.2 h') (set.mem_image_of_mem _ hbs) hb },
{ rw [real.Sup_of_not_bdd_above], rwa [bdd_above_coe] }
endβ©β©
instance : has_Inf ββ₯0 :=
β¨Ξ»s, β¨Inf ((coe : nnreal β β) '' s),
begin
cases s.eq_empty_or_nonempty with h h,
{ simp [h, set.image_empty, real.Inf_empty] },
exact le_cInf (h.image _) (assume r β¨q, _, eqβ©, eq βΈ q.2)
endβ©β©
lemma coe_Sup (s : set nnreal) : (β(Sup s) : β) = Sup ((coe : nnreal β β) '' s) := rfl
lemma coe_Inf (s : set nnreal) : (β(Inf s) : β) = Inf ((coe : nnreal β β) '' s) := rfl
instance : conditionally_complete_linear_order_bot ββ₯0 :=
{ Sup := Sup,
Inf := Inf,
le_cSup := assume s a hs ha, le_cSup (bdd_above_coe.2 hs) (set.mem_image_of_mem _ ha),
cSup_le := assume s a hs h,show Sup ((coe : nnreal β β) '' s) β€ a, from
cSup_le (by simp [hs]) $ assume r β¨b, hb, eqβ©, eq βΈ h hb,
cInf_le := assume s a _ has, cInf_le (bdd_below_coe s) (set.mem_image_of_mem _ has),
le_cInf := assume s a hs h, show (βa : β) β€ Inf ((coe : nnreal β β) '' s), from
le_cInf (by simp [hs]) $ assume r β¨b, hb, eqβ©, eq βΈ h hb,
cSup_empty := nnreal.eq $ by simp [coe_Sup, real.Sup_empty]; refl,
decidable_le := begin assume x y, apply classical.dec end,
.. nnreal.linear_ordered_semiring, .. lattice_of_decidable_linear_order,
.. nnreal.order_bot }
instance : archimedean nnreal :=
β¨ assume x y pos_y,
let β¨n, hrβ© := archimedean.arch (x:β) (pos_y : (0 : β) < y) in
β¨n, show (x:β) β€ (add_monoid.smul n y : nnreal), by simp [*, smul_coe]β© β©
lemma le_of_forall_epsilon_le {a b : nnreal} (h : βΞ΅, Ξ΅ > 0 β a β€ b + Ξ΅) : a β€ b :=
le_of_forall_le_of_dense $ assume x hxb,
begin
rcases le_iff_exists_add.1 (le_of_lt hxb) with β¨Ξ΅, rflβ©,
exact h _ ((lt_add_iff_pos_right b).1 hxb)
end
lemma lt_iff_exists_rat_btwn (a b : nnreal) :
a < b β (βq:β, 0 β€ q β§ a < nnreal.of_real q β§ nnreal.of_real q < b) :=
iff.intro
(assume (h : (βa:β) < (βb:β)),
let β¨q, haq, hqbβ© := exists_rat_btwn h in
have 0 β€ (q : β), from le_trans a.2 $ le_of_lt haq,
β¨q, rat.cast_nonneg.1 this, by simp [coe_of_real _ this, nnreal.coe_lt_coe.symm, haq, hqb]β©)
(assume β¨q, _, haq, hqbβ©, lt_trans haq hqb)
lemma bot_eq_zero : (β₯ : nnreal) = 0 := rfl
lemma mul_sup (a b c : ββ₯0) : a * (b β c) = (a * b) β (a * c) :=
begin
cases le_total b c with h h,
{ simp [sup_eq_max, max_eq_right h, max_eq_right (mul_le_mul_of_nonneg_left h (zero_le a))] },
{ simp [sup_eq_max, max_eq_left h, max_eq_left (mul_le_mul_of_nonneg_left h (zero_le a))] },
end
lemma mul_finset_sup {Ξ±} {f : Ξ± β ββ₯0} {s : finset Ξ±} (r : ββ₯0) :
r * s.sup f = s.sup (Ξ»a, r * f a) :=
begin
refine s.induction_on _ _,
{ simp [bot_eq_zero] },
{ assume a s has ih, simp [has, ih, mul_sup], }
end
@[simp, move_cast] lemma coe_max (x y : nnreal) :
((max x y : nnreal) : β) = max (x : β) (y : β) :=
by { delta max, split_ifs; refl }
@[simp, move_cast] lemma coe_min (x y : nnreal) :
((min x y : nnreal) : β) = min (x : β) (y : β) :=
by { delta min, split_ifs; refl }
section of_real
@[simp] lemma zero_le_coe {q : nnreal} : 0 β€ (q : β) := q.2
@[simp] lemma of_real_zero : nnreal.of_real 0 = 0 :=
by simp [nnreal.of_real]; refl
@[simp] lemma of_real_one : nnreal.of_real 1 = 1 :=
by simp [nnreal.of_real, max_eq_left (zero_le_one : (0 :β) β€ 1)]; refl
@[simp] lemma of_real_pos {r : β} : 0 < nnreal.of_real r β 0 < r :=
by simp [nnreal.of_real, nnreal.coe_lt_coe.symm, lt_irrefl]
@[simp] lemma of_real_eq_zero {r : β} : nnreal.of_real r = 0 β r β€ 0 :=
by simpa [-of_real_pos] using (not_iff_not.2 (@of_real_pos r))
lemma of_real_of_nonpos {r : β} : r β€ 0 β nnreal.of_real r = 0 :=
of_real_eq_zero.2
@[simp] lemma of_real_le_of_real_iff {r p : β} (hp : 0 β€ p) :
nnreal.of_real r β€ nnreal.of_real p β r β€ p :=
by simp [nnreal.coe_le_coe.symm, nnreal.of_real, hp]
@[simp] lemma of_real_lt_of_real_iff' {r p : β} :
nnreal.of_real r < nnreal.of_real p β r < p β§ 0 < p :=
by simp [nnreal.coe_lt_coe.symm, nnreal.of_real, lt_irrefl]
lemma of_real_lt_of_real_iff {r p : β} (h : 0 < p) :
nnreal.of_real r < nnreal.of_real p β r < p :=
of_real_lt_of_real_iff'.trans (and_iff_left h)
lemma of_real_lt_of_real_iff_of_nonneg {r p : β} (hr : 0 β€ r) :
nnreal.of_real r < nnreal.of_real p β r < p :=
of_real_lt_of_real_iff'.trans β¨and.left, Ξ» h, β¨h, lt_of_le_of_lt hr hβ©β©
@[simp] lemma of_real_add {r p : β} (hr : 0 β€ r) (hp : 0 β€ p) :
nnreal.of_real (r + p) = nnreal.of_real r + nnreal.of_real p :=
nnreal.eq $ by simp [nnreal.of_real, hr, hp, add_nonneg]
lemma of_real_add_of_real {r p : β} (hr : 0 β€ r) (hp : 0 β€ p) :
nnreal.of_real r + nnreal.of_real p = nnreal.of_real (r + p) :=
(of_real_add hr hp).symm
lemma of_real_le_of_real {r p : β} (h : r β€ p) : nnreal.of_real r β€ nnreal.of_real p :=
nnreal.of_real_mono h
lemma of_real_add_le {r p : β} : nnreal.of_real (r + p) β€ nnreal.of_real r + nnreal.of_real p :=
nnreal.coe_le_coe.1 $ max_le (add_le_add (le_max_left _ _) (le_max_left _ _)) nnreal.zero_le_coe
lemma of_real_le_iff_le_coe {r : β} {p : nnreal} : nnreal.of_real r β€ p β r β€ βp :=
nnreal.gi.gc r p
lemma le_of_real_iff_coe_le {r : nnreal} {p : β} (hp : p β₯ 0) : r β€ nnreal.of_real p β βr β€ p :=
by rw [β nnreal.coe_le_coe, nnreal.coe_of_real p hp]
lemma of_real_lt_iff_lt_coe {r : β} {p : nnreal} (ha : r β₯ 0) : nnreal.of_real r < p β r < βp :=
by rw [β nnreal.coe_lt_coe, nnreal.coe_of_real r ha]
lemma lt_of_real_iff_coe_lt {r : nnreal} {p : β} : r < nnreal.of_real p β βr < p :=
begin
cases le_total 0 p,
{ rw [β nnreal.coe_lt_coe, nnreal.coe_of_real p h] },
{ rw [of_real_eq_zero.2 h], split,
intro, have := not_lt_of_le (zero_le r), contradiction,
intro rp, have : Β¬(p β€ 0) := not_le_of_lt (lt_of_le_of_lt (coe_nonneg _) rp), contradiction }
end
end of_real
section mul
lemma mul_eq_mul_left {a b c : nnreal} (h : a β 0) : (a * b = a * c β b = c) :=
begin
rw [β nnreal.eq_iff, β nnreal.eq_iff, nnreal.coe_mul, nnreal.coe_mul], split,
{ exact eq_of_mul_eq_mul_left (mt (@nnreal.eq_iff a 0).1 h) },
{ assume h, rw [h] }
end
lemma of_real_mul {p q : β} (hp : 0 β€ p) :
nnreal.of_real (p * q) = nnreal.of_real p * nnreal.of_real q :=
begin
cases le_total 0 q with hq hq,
{ apply nnreal.eq,
have := max_eq_left (mul_nonneg hp hq),
simpa [nnreal.of_real, hp, hq, max_eq_left] },
{ have hpq := mul_nonpos_of_nonneg_of_nonpos hp hq,
rw [of_real_eq_zero.2 hq, of_real_eq_zero.2 hpq, mul_zero] }
end
@[field_simps] theorem mul_ne_zero' {a b : nnreal} (hβ : a β 0) (hβ : b β 0) : a * b β 0 :=
mul_ne_zero'' hβ hβ
end mul
section sub
lemma sub_def {r p : ββ₯0} : r - p = nnreal.of_real (r - p) := rfl
lemma sub_eq_zero {r p : ββ₯0} (h : r β€ p) : r - p = 0 :=
nnreal.eq $ max_eq_right $ sub_le_iff_le_add.2 $ by simpa [nnreal.coe_le_coe] using h
@[simp] lemma sub_self {r : ββ₯0} : r - r = 0 := sub_eq_zero $ le_refl r
@[simp] lemma sub_zero {r : ββ₯0} : r - 0 = r :=
by rw [sub_def, nnreal.coe_zero, sub_zero, nnreal.of_real_coe]
lemma sub_pos {r p : ββ₯0} : 0 < r - p β p < r :=
of_real_pos.trans $ sub_pos.trans $ nnreal.coe_lt_coe
protected lemma sub_lt_self {r p : nnreal} : 0 < r β 0 < p β r - p < r :=
assume hr hp,
begin
cases le_total r p,
{ rwa [sub_eq_zero h] },
{ rw [β nnreal.coe_lt_coe, nnreal.coe_sub h], exact sub_lt_self _ hp }
end
@[simp] lemma sub_le_iff_le_add {r p q : nnreal} : r - p β€ q β r β€ q + p :=
match le_total p r with
| or.inl h :=
by rw [β nnreal.coe_le_coe, β nnreal.coe_le_coe, nnreal.coe_sub h, nnreal.coe_add, sub_le_iff_le_add]
| or.inr h :=
have r β€ p + q, from le_add_right h,
by simpa [nnreal.coe_le_coe, nnreal.coe_le_coe, sub_eq_zero h, add_comm]
end
@[simp] lemma sub_le_self {r p : ββ₯0} : r - p β€ r :=
sub_le_iff_le_add.2 $ le_add_right $ le_refl r
lemma add_sub_cancel {r p : nnreal} : (p + r) - r = p :=
nnreal.eq $ by rw [nnreal.coe_sub, nnreal.coe_add, add_sub_cancel]; exact le_add_left (le_refl _)
lemma add_sub_cancel' {r p : nnreal} : (r + p) - r = p :=
by rw [add_comm, add_sub_cancel]
@[simp] lemma sub_add_cancel_of_le {a b : nnreal} (h : b β€ a) : (a - b) + b = a :=
nnreal.eq $ by rw [nnreal.coe_add, nnreal.coe_sub h, sub_add_cancel]
lemma sub_sub_cancel_of_le {r p : ββ₯0} (h : r β€ p) : p - (p - r) = r :=
by rw [nnreal.sub_def, nnreal.sub_def, nnreal.coe_of_real _ $ sub_nonneg.2 h,
sub_sub_cancel, nnreal.of_real_coe]
lemma lt_sub_iff_add_lt {p q r : nnreal} : p < q - r β p + r < q :=
begin
split,
{ assume H,
have : (((q - r) : nnreal) : β) = (q : β) - (r : β) :=
nnreal.coe_sub (le_of_lt (sub_pos.1 (lt_of_le_of_lt (zero_le _) H))),
rwa [β nnreal.coe_lt_coe, this, lt_sub_iff_add_lt, β nnreal.coe_add] at H },
{ assume H,
have : r β€ q := le_trans (le_add_left (le_refl _)) (le_of_lt H),
rwa [β nnreal.coe_lt_coe, nnreal.coe_sub this, lt_sub_iff_add_lt, β nnreal.coe_add] }
end
end sub
section inv
lemma div_def {r p : nnreal} : r / p = r * pβ»ΒΉ := rfl
@[simp] lemma inv_zero : (0 : nnreal)β»ΒΉ = 0 := nnreal.eq inv_zero
@[simp] lemma inv_eq_zero {r : nnreal} : (r : nnreal)β»ΒΉ = 0 β r = 0 :=
inv_eq_zero
@[simp] lemma inv_pos {r : nnreal} : 0 < rβ»ΒΉ β 0 < r :=
by simp [zero_lt_iff_ne_zero]
lemma div_pos {r p : ββ₯0} (hr : 0 < r) (hp : 0 < p) : 0 < r / p :=
mul_pos hr (inv_pos.2 hp)
@[simp] lemma inv_one : (1:ββ₯0)β»ΒΉ = 1 := nnreal.eq $ inv_one
@[simp] lemma div_one {r : ββ₯0} : r / 1 = r := by rw [div_def, inv_one, mul_one]
protected lemma mul_inv {r p : ββ₯0} : (r * p)β»ΒΉ = pβ»ΒΉ * rβ»ΒΉ := nnreal.eq $ mul_inv' _ _
protected lemma inv_pow {r : ββ₯0} {n : β} : (r^n)β»ΒΉ = (rβ»ΒΉ)^n :=
nnreal.eq $ by { push_cast, exact (inv_pow' _ _).symm }
@[simp] lemma inv_mul_cancel {r : ββ₯0} (h : r β 0) : rβ»ΒΉ * r = 1 :=
nnreal.eq $ inv_mul_cancel $ mt (@nnreal.eq_iff r 0).1 h
@[simp] lemma mul_inv_cancel {r : ββ₯0} (h : r β 0) : r * rβ»ΒΉ = 1 :=
by rw [mul_comm, inv_mul_cancel h]
@[simp] lemma div_self {r : ββ₯0} (h : r β 0) : r / r = 1 :=
mul_inv_cancel h
@[simp] lemma div_mul_cancel {r p : ββ₯0} (h : p β 0) : r / p * p = r :=
by rw [div_def, mul_assoc, inv_mul_cancel h, mul_one]
@[simp] lemma mul_div_cancel {r p : ββ₯0} (h : p β 0) : r * p / p = r :=
by rw [div_def, mul_assoc, mul_inv_cancel h, mul_one]
@[simp] lemma mul_div_cancel' {r p : ββ₯0} (h : r β 0) : r * (p / r) = p :=
by rw [mul_comm, div_mul_cancel h]
@[simp] lemma inv_inv {r : ββ₯0} : rβ»ΒΉβ»ΒΉ = r := nnreal.eq inv_inv'
@[simp] lemma inv_le {r p : ββ₯0} (h : r β 0) : rβ»ΒΉ β€ p β 1 β€ r * p :=
by rw [β mul_le_mul_left (zero_lt_iff_ne_zero.2 h), mul_inv_cancel h]
lemma inv_le_of_le_mul {r p : ββ₯0} (h : 1 β€ r * p) : rβ»ΒΉ β€ p :=
by by_cases r = 0; simp [*, inv_le]
@[simp] lemma le_inv_iff_mul_le {r p : ββ₯0} (h : p β 0) : (r β€ pβ»ΒΉ β r * p β€ 1) :=
by rw [β mul_le_mul_left (zero_lt_iff_ne_zero.2 h), mul_inv_cancel h, mul_comm]
@[simp] lemma lt_inv_iff_mul_lt {r p : ββ₯0} (h : p β 0) : (r < pβ»ΒΉ β r * p < 1) :=
by rw [β mul_lt_mul_left (zero_lt_iff_ne_zero.2 h), mul_inv_cancel h, mul_comm]
lemma mul_le_iff_le_inv {a b r : ββ₯0} (hr : r β 0) : r * a β€ b β a β€ rβ»ΒΉ * b :=
have 0 < r, from lt_of_le_of_ne (zero_le r) hr.symm,
by rw [β @mul_le_mul_left _ _ a _ r this, β mul_assoc, mul_inv_cancel hr, one_mul]
lemma le_div_iff_mul_le {a b r : ββ₯0} (hr : r β 0) : a β€ b / r β a * r β€ b :=
by rw [div_def, mul_comm, β mul_le_iff_le_inv hr, mul_comm]
lemma le_of_forall_lt_one_mul_lt {x y : ββ₯0} (h : βa<1, a * x β€ y) : x β€ y :=
le_of_forall_ge_of_dense $ assume a ha,
have hx : x β 0 := zero_lt_iff_ne_zero.1 (lt_of_le_of_lt (zero_le _) ha),
have hx' : xβ»ΒΉ β 0, by rwa [(β ), inv_eq_zero],
have a * xβ»ΒΉ < 1, by rwa [β lt_inv_iff_mul_lt hx', inv_inv],
have (a * xβ»ΒΉ) * x β€ y, from h _ this,
by rwa [mul_assoc, inv_mul_cancel hx, mul_one] at this
lemma div_add_div_same (a b c : ββ₯0) : a / c + b / c = (a + b) / c :=
eq.symm $ right_distrib a b (cβ»ΒΉ)
lemma half_pos {a : ββ₯0} (h : 0 < a) : 0 < a / 2 := div_pos h zero_lt_two
lemma add_halves (a : ββ₯0) : a / 2 + a / 2 = a := nnreal.eq (add_halves a)
lemma half_lt_self {a : ββ₯0} (h : a β 0) : a / 2 < a :=
by rw [β nnreal.coe_lt_coe, nnreal.coe_div]; exact
half_lt_self (bot_lt_iff_ne_bot.2 h)
lemma two_inv_lt_one : (2β»ΒΉ:ββ₯0) < 1 :=
by simpa [div_def] using half_lt_self zero_ne_one.symm
lemma div_lt_iff {a b c : ββ₯0} (hc : c β 0) : b / c < a β b < a * c :=
begin
rw [β nnreal.coe_lt_coe, β nnreal.coe_lt_coe, nnreal.coe_div, nnreal.coe_mul],
exact div_lt_iff (zero_lt_iff_ne_zero.mpr hc)
end
lemma div_lt_one_of_lt {a b : ββ₯0} (h : a < b) : a / b < 1 :=
begin
rwa [div_lt_iff, one_mul],
exact ne_of_gt (lt_of_le_of_lt (zero_le _) h)
end
@[field_simps] theorem div_pow {a b : ββ₯0} (n : β) : (a / b) ^ n = a ^ n / b ^ n :=
div_pow _ _ _
@[field_simps] lemma mul_div_assoc' (a b c : ββ₯0) : a * (b / c) = (a * b) / c :=
by rw [div_def, div_def, mul_assoc]
@[field_simps] lemma div_add_div (a : ββ₯0) {b : ββ₯0} (c : ββ₯0) {d : ββ₯0}
(hb : b β 0) (hd : d β 0) : a / b + c / d = (a * d + b * c) / (b * d) :=
begin
rw β nnreal.eq_iff,
simp only [nnreal.coe_add, nnreal.coe_div, nnreal.coe_mul],
exact div_add_div _ _ (coe_ne_zero.2 hb) (coe_ne_zero.2 hd)
end
@[field_simps] lemma inv_eq_one_div (a : ββ₯0) : aβ»ΒΉ = 1/a :=
by rw [div_def, one_mul]
@[field_simps] lemma div_mul_eq_mul_div (a b c : ββ₯0) : (a / b) * c = (a * c) / b :=
by { rw [div_def, div_def], ac_refl }
@[field_simps] lemma add_div' (a b c : ββ₯0) (hc : c β 0) :
b + a / c = (b * c + a) / c :=
by simpa using div_add_div b a one_ne_zero hc
@[field_simps] lemma div_add' (a b c : ββ₯0) (hc : c β 0) :
a / c + b = (a + b * c) / c :=
by rwa [add_comm, add_div', add_comm]
lemma one_div_eq_inv (a : ββ₯0) : 1 / a = aβ»ΒΉ :=
one_mul aβ»ΒΉ
lemma one_div_div (a b : ββ₯0) : 1 / (a / b) = b / a :=
by { rw β nnreal.eq_iff, simp [one_div_div] }
lemma div_eq_mul_one_div (a b : ββ₯0) : a / b = a * (1 / b) :=
by rw [div_def, div_def, one_mul]
@[field_simps] lemma div_div_eq_mul_div (a b c : ββ₯0) : a / (b / c) = (a * c) / b :=
by { rw β nnreal.eq_iff, simp [div_div_eq_mul_div] }
@[field_simps] lemma div_div_eq_div_mul (a b c : ββ₯0) : (a / b) / c = a / (b * c) :=
by { rw β nnreal.eq_iff, simp [div_div_eq_div_mul] }
@[field_simps] lemma div_eq_div_iff {a b c d : ββ₯0} (hb : b β 0) (hd : d β 0) :
a / b = c / d β a * d = c * b :=
div_eq_div_iff hb hd
@[field_simps] lemma div_eq_iff {a b c : ββ₯0} (hb : b β 0) : a / b = c β a = c * b :=
by simpa using @div_eq_div_iff a b c 1 hb one_ne_zero
@[field_simps] lemma eq_div_iff {a b c : ββ₯0} (hb : b β 0) : c = a / b β c * b = a :=
by simpa using @div_eq_div_iff c 1 a b one_ne_zero hb
end inv
section pow
theorem pow_eq_zero {a : ββ₯0} {n : β} (h : a^n = 0) : a = 0 :=
begin
rw β nnreal.eq_iff,
rw [β nnreal.eq_iff, coe_pow] at h,
exact pow_eq_zero h
end
@[field_simps] theorem pow_ne_zero {a : ββ₯0} (n : β) (h : a β 0) : a ^ n β 0 :=
mt pow_eq_zero h
end pow
end nnreal
|
7cdb15cf060cd2cc282b92947826d54a6567f32a | 9dc8cecdf3c4634764a18254e94d43da07142918 | /src/data/pfunctor/univariate/M.lean | 0d7980a33d14c57ef3779fde2b0c3e55b5c1ad7e | [
"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 | 21,952 | lean | /-
Copyright (c) 2017 Simon Hudon All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Simon Hudon
-/
import data.pfunctor.univariate.basic
/-!
# M-types
M types are potentially infinite tree-like structures. They are defined
as the greatest fixpoint of a polynomial functor.
-/
universes u v w
open nat function list (hiding head')
variables (F : pfunctor.{u})
local prefix `β―`:0 := cast (by simp [*] <|> cc <|> solve_by_elim)
namespace pfunctor
namespace approx
/-- `cofix_a F n` is an `n` level approximation of a M-type -/
inductive cofix_a : β β Type u
| continue : cofix_a 0
| intro {n} : β a, (F.B a β cofix_a n) β cofix_a (succ n)
/-- default inhabitant of `cofix_a` -/
protected def cofix_a.default [inhabited F.A] : Ξ n, cofix_a F n
| 0 := cofix_a.continue
| (succ n) := cofix_a.intro default $ Ξ» _, cofix_a.default n
instance [inhabited F.A] {n} : inhabited (cofix_a F n) := β¨ cofix_a.default F n β©
lemma cofix_a_eq_zero : β x y : cofix_a F 0, x = y
| cofix_a.continue cofix_a.continue := rfl
variables {F}
/--
The label of the root of the tree for a non-trivial
approximation of the cofix of a pfunctor.
-/
def head' : Ξ {n}, cofix_a F (succ n) β F.A
| n (cofix_a.intro i _) := i
/-- for a non-trivial approximation, return all the subtrees of the root -/
def children' : Ξ {n} (x : cofix_a F (succ n)), F.B (head' x) β cofix_a F n
| n (cofix_a.intro a f) := f
lemma approx_eta {n : β} (x : cofix_a F (n+1)) :
x = cofix_a.intro (head' x) (children' x) :=
by cases x; refl
/-- Relation between two approximations of the cofix of a pfunctor
that state they both contain the same data until one of them is truncated -/
inductive agree : β {n : β}, cofix_a F n β cofix_a F (n+1) β Prop
| continue (x : cofix_a F 0) (y : cofix_a F 1) : agree x y
| intro {n} {a} (x : F.B a β cofix_a F n) (x' : F.B a β cofix_a F (n+1)) :
(β i : F.B a, agree (x i) (x' i)) β
agree (cofix_a.intro a x) (cofix_a.intro a x')
/--
Given an infinite series of approximations `approx`,
`all_agree approx` states that they are all consistent with each other.
-/
def all_agree (x : Ξ n, cofix_a F n) :=
β n, agree (x n) (x (succ n))
@[simp]
lemma agree_trival {x : cofix_a F 0} {y : cofix_a F 1} :
agree x y :=
by { constructor }
lemma agree_children {n : β} (x : cofix_a F (succ n)) (y : cofix_a F (succ n+1))
{i j} (hβ : i == j) (hβ : agree x y) :
agree (children' x i) (children' y j) :=
begin
cases hβ with _ _ _ _ _ _ hagree, cases hβ,
apply hagree,
end
/-- `truncate a` turns `a` into a more limited approximation -/
def truncate : β {n : β}, cofix_a F (n+1) β cofix_a F n
| 0 (cofix_a.intro _ _) := cofix_a.continue
| (succ n) (cofix_a.intro i f) := cofix_a.intro i $ truncate β f
lemma truncate_eq_of_agree {n : β} (x : cofix_a F n) (y : cofix_a F (succ n)) (h : agree x y) :
truncate y = x :=
begin
induction n generalizing x y; cases x; cases y,
{ refl },
{ cases h with _ _ _ _ _ hβ hβ,
cases h,
simp only [truncate, function.comp, true_and, eq_self_iff_true, heq_iff_eq],
ext y, apply n_ih,
apply hβ }
end
variables {X : Type w}
variables (f : X β F.obj X)
/-- `s_corec f i n` creates an approximation of height `n`
of the final coalgebra of `f` -/
def s_corec : Ξ (i : X) n, cofix_a F n
| _ 0 := cofix_a.continue
| j (succ n) := cofix_a.intro (f j).1 (Ξ» i, s_corec ((f j).2 i) _)
lemma P_corec (i : X) (n : β) : agree (s_corec f i n) (s_corec f i (succ n)) :=
begin
induction n with n generalizing i,
constructor,
cases h : f i with y g,
constructor,
introv,
apply n_ih,
end
/-- `path F` provides indices to access internal nodes in `corec F` -/
def path (F : pfunctor.{u}) := list F.Idx
instance path.inhabited : inhabited (path F) := β¨ [] β©
open list nat
instance : subsingleton (cofix_a F 0) :=
β¨ by { intros, casesm* cofix_a F 0, refl } β©
lemma head_succ' (n m : β) (x : Ξ n, cofix_a F n) (Hconsistent : all_agree x) :
head' (x (succ n)) = head' (x (succ m)) :=
begin
suffices : β n, head' (x (succ n)) = head' (x 1),
{ simp [this] },
clear m n, intro,
cases hβ : x (succ n) with _ iβ fβ,
cases hβ : x 1 with _ iβ fβ,
dsimp only [head'],
induction n with n,
{ rw hβ at hβ, cases hβ, trivial },
{ have H := Hconsistent (succ n),
cases hβ : x (succ n) with _ iβ fβ,
rw [hβ,hβ] at H,
apply n_ih (truncate β fβ),
rw hβ,
cases H with _ _ _ _ _ _ hagree,
congr, funext j, dsimp only [comp_app],
rw truncate_eq_of_agree,
apply hagree }
end
end approx
open approx
/-- Internal definition for `M`. It is needed to avoid name clashes
between `M.mk` and `M.cases_on` and the declarations generated for
the structure -/
structure M_intl :=
(approx : β n, cofix_a F n)
(consistent : all_agree approx)
/-- For polynomial functor `F`, `M F` is its final coalgebra -/
def M := M_intl F
lemma M.default_consistent [inhabited F.A] :
Ξ n, agree (default : cofix_a F n) default
| 0 := agree.continue _ _
| (succ n) := agree.intro _ _ $ Ξ» _, M.default_consistent n
instance M.inhabited [inhabited F.A] : inhabited (M F) :=
β¨ { approx := default,
consistent := M.default_consistent _ } β©
instance M_intl.inhabited [inhabited F.A] : inhabited (M_intl F) :=
show inhabited (M F), by apply_instance
namespace M
lemma ext' (x y : M F) (H : β i : β, x.approx i = y.approx i) : x = y :=
by { cases x, cases y, congr' with n, apply H }
variables {X : Type*}
variables (f : X β F.obj X)
variables {F}
/-- Corecursor for the M-type defined by `F`. -/
protected def corec (i : X) : M F :=
{ approx := s_corec f i,
consistent := P_corec _ _ }
variables {F}
/-- given a tree generated by `F`, `head` gives us the first piece of data
it contains -/
def head (x : M F) :=
head' (x.1 1)
/-- return all the subtrees of the root of a tree `x : M F` -/
def children (x : M F) (i : F.B (head x)) : M F :=
let H := Ξ» n : β, @head_succ' _ n 0 x.1 x.2 in
{ approx := Ξ» n, children' (x.1 _) (cast (congr_arg _ $ by simp only [head,H]; refl) i),
consistent :=
begin
intro,
have P' := x.2 (succ n),
apply agree_children _ _ _ P',
transitivity i,
apply cast_heq,
symmetry,
apply cast_heq,
end }
/-- select a subtree using a `i : F.Idx` or return an arbitrary tree if
`i` designates no subtree of `x` -/
def ichildren [inhabited (M F)] [decidable_eq F.A] (i : F.Idx) (x : M F) : M F :=
if H' : i.1 = head x
then children x (cast (congr_arg _ $ by simp only [head,H']; refl) i.2)
else default
lemma head_succ (n m : β) (x : M F) :
head' (x.approx (succ n)) = head' (x.approx (succ m)) :=
head_succ' n m _ x.consistent
lemma head_eq_head' : Ξ (x : M F) (n : β),
head x = head' (x.approx $ n+1)
| β¨x,hβ© n := head_succ' _ _ _ h
lemma head'_eq_head : Ξ (x : M F) (n : β),
head' (x.approx $ n+1) = head x
| β¨x,hβ© n := head_succ' _ _ _ h
lemma truncate_approx (x : M F) (n : β) :
truncate (x.approx $ n+1) = x.approx n :=
truncate_eq_of_agree _ _ (x.consistent _)
/-- unfold an M-type -/
def dest : M F β F.obj (M F)
| x := β¨head x,Ξ» i, children x i β©
namespace approx
/-- generates the approximations needed for `M.mk` -/
protected def s_mk (x : F.obj $ M F) : Ξ n, cofix_a F n
| 0 := cofix_a.continue
| (succ n) := cofix_a.intro x.1 (Ξ» i, (x.2 i).approx n)
protected lemma P_mk (x : F.obj $ M F)
: all_agree (approx.s_mk x)
| 0 := by { constructor }
| (succ n) := by { constructor, introv,
apply (x.2 i).consistent }
end approx
/-- constructor for M-types -/
protected def mk (x : F.obj $ M F) : M F :=
{ approx := approx.s_mk x,
consistent := approx.P_mk x }
/-- `agree' n` relates two trees of type `M F` that
are the same up to dept `n` -/
inductive agree' : β β M F β M F β Prop
| trivial (x y : M F) : agree' 0 x y
| step {n : β} {a} (x y : F.B a β M F) {x' y'} :
x' = M.mk β¨a,xβ© β
y' = M.mk β¨a,yβ© β
(β i, agree' n (x i) (y i)) β
agree' (succ n) x' y'
@[simp]
lemma dest_mk (x : F.obj $ M F) :
dest (M.mk x) = x :=
begin
funext i,
dsimp only [M.mk,dest],
cases x with x ch, congr' with i,
cases h : ch i,
simp only [children,M.approx.s_mk,children',cast_eq],
dsimp only [M.approx.s_mk,children'],
congr, rw h,
end
@[simp] lemma mk_dest (x : M F) :
M.mk (dest x) = x :=
begin
apply ext', intro n,
dsimp only [M.mk],
induction n with n,
{ apply subsingleton.elim },
dsimp only [approx.s_mk,dest,head],
cases h : x.approx (succ n) with _ hd ch,
have h' : hd = head' (x.approx 1),
{ rw [β head_succ' n,h,head'], apply x.consistent },
revert ch, rw h', intros, congr,
{ ext a, dsimp only [children],
h_generalize! hh : a == a'',
rw h, intros, cases hh, refl },
end
lemma mk_inj {x y : F.obj $ M F}
(h : M.mk x = M.mk y) : x = y :=
by rw [β dest_mk x,h,dest_mk]
/-- destructor for M-types -/
protected def cases {r : M F β Sort w}
(f : β (x : F.obj $ M F), r (M.mk x)) (x : M F) : r x :=
suffices r (M.mk (dest x)),
by { haveI := classical.prop_decidable,
haveI := inhabited.mk x,
rw [β mk_dest x], exact this },
f _
/-- destructor for M-types -/
protected def cases_on {r : M F β Sort w}
(x : M F) (f : β (x : F.obj $ M F), r (M.mk x)) : r x :=
M.cases f x
/-- destructor for M-types, similar to `cases_on` but also
gives access directly to the root and subtrees on an M-type -/
protected def cases_on' {r : M F β Sort w}
(x : M F) (f : β a f, r (M.mk β¨a,fβ©)) : r x :=
M.cases_on x (Ξ» β¨a,gβ©, f a _)
lemma approx_mk (a : F.A) (f : F.B a β M F) (i : β) :
(M.mk β¨a, fβ©).approx (succ i) = cofix_a.intro a (Ξ» j, (f j).approx i) :=
rfl
@[simp] lemma agree'_refl {n : β} (x : M F) :
agree' n x x :=
by { induction n generalizing x; induction x using pfunctor.M.cases_on';
constructor; try { refl }, intros, apply n_ih }
lemma agree_iff_agree' {n : β} (x y : M F) :
agree (x.approx n) (y.approx $ n+1) β agree' n x y :=
begin
split; intros h,
{ induction n generalizing x y, constructor,
{ induction x using pfunctor.M.cases_on',
induction y using pfunctor.M.cases_on',
simp only [approx_mk] at h, cases h with _ _ _ _ _ _ hagree,
constructor; try { refl },
intro i, apply n_ih, apply hagree } },
{ induction n generalizing x y, constructor,
{ cases h,
induction x using pfunctor.M.cases_on',
induction y using pfunctor.M.cases_on',
simp only [approx_mk],
have h_a_1 := mk_inj βΉM.mk β¨x_a, x_fβ© = M.mk β¨h_a, h_xβ©βΊ, cases h_a_1,
replace h_a_2 := mk_inj βΉM.mk β¨y_a, y_fβ© = M.mk β¨h_a, h_yβ©βΊ, cases h_a_2,
constructor, intro i, apply n_ih, simp * } },
end
@[simp]
lemma cases_mk {r : M F β Sort*} (x : F.obj $ M F) (f : Ξ (x : F.obj $ M F), r (M.mk x)) :
pfunctor.M.cases f (M.mk x) = f x :=
begin
dsimp only [M.mk,pfunctor.M.cases,dest,head,approx.s_mk,head'],
cases x, dsimp only [approx.s_mk],
apply eq_of_heq,
apply rec_heq_of_heq, congr' with x,
dsimp only [children,approx.s_mk,children'],
cases h : x_snd x, dsimp only [head],
congr' with n, change (x_snd (x)).approx n = _, rw h
end
@[simp]
lemma cases_on_mk {r : M F β Sort*} (x : F.obj $ M F) (f : Ξ x : F.obj $ M F, r (M.mk x)) :
pfunctor.M.cases_on (M.mk x) f = f x :=
cases_mk x f
@[simp]
lemma cases_on_mk'
{r : M F β Sort*} {a} (x : F.B a β M F) (f : Ξ a (f : F.B a β M F), r (M.mk β¨a,fβ©)) :
pfunctor.M.cases_on' (M.mk β¨a,xβ©) f = f a x :=
cases_mk β¨_,xβ© _
/-- `is_path p x` tells us if `p` is a valid path through `x` -/
inductive is_path : path F β M F β Prop
| nil (x : M F) : is_path [] x
| cons (xs : path F) {a} (x : M F) (f : F.B a β M F) (i : F.B a) :
x = M.mk β¨a,fβ© β
is_path xs (f i) β
is_path (β¨a,iβ© :: xs) x
lemma is_path_cons {xs : path F} {a a'} {f : F.B a β M F} {i : F.B a'} :
is_path (β¨a',iβ© :: xs) (M.mk β¨a,fβ©) β a = a' :=
begin
generalize h : (M.mk β¨a,fβ©) = x,
rintro (_ | β¨_, _, _, _, _, rfl, _β©),
cases mk_inj h,
refl
end
lemma is_path_cons' {xs : path F} {a} {f : F.B a β M F} {i : F.B a} :
is_path (β¨a,iβ© :: xs) (M.mk β¨a,fβ©) β is_path xs (f i) :=
begin
generalize h : (M.mk β¨a,fβ©) = x,
rintro (_ | β¨_, _, _, _, _, rfl, hpβ©),
cases mk_inj h,
exact hp
end
/-- follow a path through a value of `M F` and return the subtree
found at the end of the path if it is a valid path for that value and
return a default tree -/
def isubtree [decidable_eq F.A] [inhabited (M F)] : path F β M F β M F
| [] x := x
| (β¨a, iβ© :: ps) x :=
pfunctor.M.cases_on' x (Ξ» a' f,
(if h : a = a' then isubtree ps (f $ cast (by rw h) i)
else default : (Ξ» x, M F) (M.mk β¨a',fβ©)))
/-- similar to `isubtree` but returns the data at the end of the path instead
of the whole subtree -/
def iselect [decidable_eq F.A] [inhabited (M F)] (ps : path F) : M F β F.A :=
Ξ» (x : M F), head $ isubtree ps x
lemma iselect_eq_default [decidable_eq F.A] [inhabited (M F)] (ps : path F) (x : M F)
(h : Β¬ is_path ps x) :
iselect ps x = head default :=
begin
induction ps generalizing x,
{ exfalso, apply h, constructor },
{ cases ps_hd with a i,
induction x using pfunctor.M.cases_on',
simp only [iselect,isubtree] at ps_ih β’,
by_cases h'' : a = x_a, subst x_a,
{ simp only [dif_pos, eq_self_iff_true, cases_on_mk'],
rw ps_ih, intro h', apply h,
constructor; try { refl }, apply h' },
{ simp * } }
end
@[simp] lemma head_mk (x : F.obj (M F)) :
head (M.mk x) = x.1 :=
eq.symm $
calc x.1
= (dest (M.mk x)).1 : by rw dest_mk
... = head (M.mk x) : by refl
lemma children_mk {a} (x : F.B a β (M F)) (i : F.B (head (M.mk β¨a,xβ©))) :
children (M.mk β¨a,xβ©) i = x (cast (by rw head_mk) i) :=
by apply ext'; intro n; refl
@[simp]
lemma ichildren_mk [decidable_eq F.A] [inhabited (M F)] (x : F.obj (M F)) (i : F.Idx) :
ichildren i (M.mk x) = x.iget i :=
by { dsimp only [ichildren,pfunctor.obj.iget],
congr' with h, apply ext',
dsimp only [children',M.mk,approx.s_mk],
intros, refl }
@[simp]
lemma isubtree_cons
[decidable_eq F.A] [inhabited (M F)] (ps : path F) {a} (f : F.B a β M F) {i : F.B a} :
isubtree (β¨_,iβ© :: ps) (M.mk β¨a,fβ©) = isubtree ps (f i) :=
by simp only [isubtree,ichildren_mk,pfunctor.obj.iget,dif_pos,isubtree,M.cases_on_mk']; refl
@[simp]
lemma iselect_nil [decidable_eq F.A] [inhabited (M F)] {a} (f : F.B a β M F) :
iselect nil (M.mk β¨a,fβ©) = a :=
by refl
@[simp]
lemma iselect_cons [decidable_eq F.A] [inhabited (M F)] (ps : path F) {a} (f : F.B a β M F) {i} :
iselect (β¨a,iβ© :: ps) (M.mk β¨a,fβ©) = iselect ps (f i) :=
by simp only [iselect,isubtree_cons]
lemma corec_def {X} (f : X β F.obj X) (xβ : X) :
M.corec f xβ = M.mk (M.corec f <$> f xβ) :=
begin
dsimp only [M.corec,M.mk],
congr' with n,
cases n with n,
{ dsimp only [s_corec,approx.s_mk], refl, },
{ dsimp only [s_corec,approx.s_mk], cases h : (f xβ),
dsimp only [(<$>),pfunctor.map],
congr, }
end
lemma ext_aux [inhabited (M F)] [decidable_eq F.A] {n : β} (x y z : M F)
(hx : agree' n z x)
(hy : agree' n z y)
(hrec : β (ps : path F),
n = ps.length β
iselect ps x = iselect ps y) :
x.approx (n+1) = y.approx (n+1) :=
begin
induction n with n generalizing x y z,
{ specialize hrec [] rfl,
induction x using pfunctor.M.cases_on', induction y using pfunctor.M.cases_on',
simp only [iselect_nil] at hrec, subst hrec,
simp only [approx_mk, true_and, eq_self_iff_true, heq_iff_eq],
apply subsingleton.elim },
{ cases hx, cases hy,
induction x using pfunctor.M.cases_on', induction y using pfunctor.M.cases_on',
subst z,
iterate 3 { have := mk_inj βΉ_βΊ, repeat { cases this } },
simp only [approx_mk, true_and, eq_self_iff_true, heq_iff_eq],
ext i, apply n_ih,
{ solve_by_elim },
{ solve_by_elim },
introv h, specialize hrec (β¨_,iβ© :: ps) (congr_arg _ h),
simp only [iselect_cons] at hrec, exact hrec }
end
open pfunctor.approx
variables {F}
local attribute [instance, priority 0] classical.prop_decidable
lemma ext [inhabited (M F)]
(x y : M F)
(H : β (ps : path F), iselect ps x = iselect ps y) :
x = y :=
begin
apply ext', intro i,
induction i with i,
{ cases x.approx 0, cases y.approx 0, constructor },
{ apply ext_aux x y x,
{ rw β agree_iff_agree', apply x.consistent },
{ rw [β agree_iff_agree',i_ih], apply y.consistent },
introv H',
dsimp only [iselect] at H,
cases H',
apply H ps }
end
section bisim
variable (R : M F β M F β Prop)
local infix ` ~ `:50 := R
/-- Bisimulation is the standard proof technique for equality between
infinite tree-like structures -/
structure is_bisimulation : Prop :=
(head : β {a a'} {f f'}, M.mk β¨a,fβ© ~ M.mk β¨a',f'β© β a = a')
(tail : β {a} {f f' : F.B a β M F},
M.mk β¨a,fβ© ~ M.mk β¨a,f'β© β
(β (i : F.B a), f i ~ f' i) )
theorem nth_of_bisim [inhabited (M F)] (bisim : is_bisimulation R) (sβ sβ) (ps : path F) :
sβ ~ sβ β
is_path ps sβ β¨ is_path ps sβ β
iselect ps sβ = iselect ps sβ β§
β a (f f' : F.B a β M F),
isubtree ps sβ = M.mk β¨a,fβ© β§
isubtree ps sβ = M.mk β¨a,f'β© β§
β (i : F.B a), f i ~ f' i :=
begin
intros hβ hh,
induction sβ using pfunctor.M.cases_on' with a f,
induction sβ using pfunctor.M.cases_on' with a' f',
obtain rfl : a = a' := bisim.head hβ,
induction ps with i ps generalizing a f f',
{ existsi [rfl,a,f,f',rfl,rfl],
apply bisim.tail hβ },
cases i with a' i,
obtain rfl : a = a',
{ cases hh; cases is_path_cons hh; refl },
dsimp only [iselect] at ps_ih β’,
have hβ := bisim.tail hβ i,
induction h : (f i) using pfunctor.M.cases_on' with aβ fβ,
induction h' : (f' i) using pfunctor.M.cases_on' with aβ fβ,
simp only [h,h',isubtree_cons] at ps_ih β’,
rw [h,h'] at hβ,
obtain rfl : aβ = aβ := bisim.head hβ,
apply (ps_ih _ _ _ hβ),
rw [β h,β h'], apply or_of_or_of_imp_of_imp hh is_path_cons' is_path_cons'
end
theorem eq_of_bisim [nonempty (M F)] (bisim : is_bisimulation R) : β sβ sβ, sβ ~ sβ β sβ = sβ :=
begin
inhabit (M F),
introv Hr, apply ext,
introv,
by_cases h : is_path ps sβ β¨ is_path ps sβ,
{ have H := nth_of_bisim R bisim _ _ ps Hr h,
exact H.left },
{ rw not_or_distrib at h, cases h with hβ hβ,
simp only [iselect_eq_default,*,not_false_iff] }
end
end bisim
universes u' v'
/-- corecursor for `M F` with swapped arguments -/
def corec_on {X : Type*} (xβ : X) (f : X β F.obj X) : M F :=
M.corec f xβ
variables {P : pfunctor.{u}} {Ξ± : Type u}
lemma dest_corec (g : Ξ± β P.obj Ξ±) (x : Ξ±) :
M.dest (M.corec g x) = M.corec g <$> g x :=
by rw [corec_def,dest_mk]
lemma bisim (R : M P β M P β Prop)
(h : β x y, R x y β β a f f',
M.dest x = β¨a, fβ© β§
M.dest y = β¨a, f'β© β§
β i, R (f i) (f' i)) :
β x y, R x y β x = y :=
begin
introv h',
haveI := inhabited.mk x.head,
apply eq_of_bisim R _ _ _ h', clear h' x y,
split; introv ih;
rcases h _ _ ih with β¨ a'', g, g', hβ, hβ, hβ β©; clear h,
{ replace hβ := congr_arg sigma.fst hβ,
replace hβ := congr_arg sigma.fst hβ,
simp only [dest_mk] at hβ hβ,
rw [hβ,hβ], },
{ simp only [dest_mk] at hβ hβ,
cases hβ, cases hβ,
apply hβ, },
end
theorem bisim' {Ξ± : Type*} (Q : Ξ± β Prop) (u v : Ξ± β M P)
(h : β x, Q x β β a f f',
M.dest (u x) = β¨a, fβ© β§
M.dest (v x) = β¨a, f'β© β§
β i, β x', Q x' β§ f i = u x' β§ f' i = v x') :
β x, Q x β u x = v x :=
Ξ» x Qx,
let R := Ξ» w z : M P, β x', Q x' β§ w = u x' β§ z = v x' in
@M.bisim P R
(Ξ» x y β¨x', Qx', xeq, yeqβ©,
let β¨a, f, f', ux'eq, vx'eq, h'β© := h x' Qx' in
β¨a, f, f', xeq.symm βΈ ux'eq, yeq.symm βΈ vx'eq, h'β©)
_ _ β¨x, Qx, rfl, rflβ©
-- for the record, show M_bisim follows from _bisim'
theorem bisim_equiv (R : M P β M P β Prop)
(h : β x y, R x y β β a f f',
M.dest x = β¨a, fβ© β§
M.dest y = β¨a, f'β© β§
β i, R (f i) (f' i)) :
β x y, R x y β x = y :=
Ξ» x y Rxy,
let Q : M P Γ M P β Prop := Ξ» p, R p.fst p.snd in
bisim' Q prod.fst prod.snd
(Ξ» p Qp,
let β¨a, f, f', hx, hy, h'β© := h p.fst p.snd Qp in
β¨a, f, f', hx, hy, Ξ» i, β¨β¨f i, f' iβ©, h' i, rfl, rflβ©β©)
β¨x, yβ© Rxy
theorem corec_unique (g : Ξ± β P.obj Ξ±) (f : Ξ± β M P)
(hyp : β x, M.dest (f x) = f <$> (g x)) :
f = M.corec g :=
begin
ext x,
apply bisim' (Ξ» x, true) _ _ _ _ trivial,
clear x,
intros x _,
cases gxeq : g x with a f',
have hβ : M.dest (f x) = β¨a, f β f'β©,
{ rw [hyp, gxeq, pfunctor.map_eq] },
have hβ : M.dest (M.corec g x) = β¨a, M.corec g β f'β©,
{ rw [dest_corec, gxeq, pfunctor.map_eq], },
refine β¨_, _, _, hβ, hβ, _β©,
intro i,
exact β¨f' i, trivial, rfl, rflβ©
end
/-- corecursor where the state of the computation can be sent downstream
in the form of a recursive call -/
def corecβ {Ξ± : Type u} (F : Ξ X, (Ξ± β X) β Ξ± β P.obj X) : Ξ± β M P :=
M.corec (F _ id)
/-- corecursor where it is possible to return a fully formed value at any point
of the computation -/
def corec' {Ξ± : Type u} (F : Ξ {X : Type u}, (Ξ± β X) β Ξ± β M P β P.obj X) (x : Ξ±) : M P :=
corecβ
(Ξ» X rec (a : M P β Ξ±),
let y := a >>= F (rec β sum.inr) in
match y with
| sum.inr y := y
| sum.inl y := (rec β sum.inl) <$> M.dest y
end )
(@sum.inr (M P) _ x)
end M
end pfunctor
|
d54ea38ba62efcfefa8299f164379529ac35643c | 5d166a16ae129621cb54ca9dde86c275d7d2b483 | /tests/lean/defeq_simp2.lean | bb1e03866a86936eb737080f20f54c1c80825e01 | [
"Apache-2.0"
] | permissive | jcarlson23/lean | b00098763291397e0ac76b37a2dd96bc013bd247 | 8de88701247f54d325edd46c0eed57aeacb64baf | refs/heads/master | 1,611,571,813,719 | 1,497,020,963,000 | 1,497,021,515,000 | 93,882,536 | 1 | 0 | null | 1,497,029,896,000 | 1,497,029,896,000 | null | UTF-8 | Lean | false | false | 1,136 | lean | open tactic
constant f (n : nat) : n β₯ 0 β nat
axiom foo1 (n : nat) : n β₯ 0
axiom foo2 (n : nat) : n β₯ 0
axiom foo3 (n : nat) : n β₯ 0
-- by default we dont canonize proofs
example (a b : nat) (H : f a (foo1 a) = f a (foo2 a)) : true :=
by do
s β simp_lemmas.mk_default,
get_local `H >>= infer_type >>= s^.dsimplify >>= trace,
constructor
constant x1 : nat -- update the environment to force defeq_canonize cache to be reset
example (a b : nat) (H : f a (foo1 a) = f a (foo2 a)) : true :=
by do
s β simp_lemmas.mk_default,
get_local `H >>= infer_type >>= s^.dsimplify >>= trace,
constructor
constant x2 : nat -- update the environment to force defeq_canonize cache to be reset
example (a b : nat) (H : f a (id (id (id (foo1 a)))) = f a (foo2 a)) : true :=
by do
s β simp_lemmas.mk_default,
get_local `H >>= infer_type >>= s^.dsimplify >>= trace,
constructor
-- Example that does not work
example (a b : nat) (H : (Ξ» x, f x (id (id (id (foo1 x))))) = (Ξ» x, f x (foo2 x))) : true :=
by do
s β simp_lemmas.mk_default,
get_local `H >>= infer_type >>= s^.dsimplify >>= trace,
constructor
|
cdd962190b369ae9c5a5c979a308d0e6f547577b | a4673261e60b025e2c8c825dfa4ab9108246c32e | /tests/lean/run/108.lean | f07d647b03ea2a869ff09eefae9d5a5dba97ca19 | [
"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 | 65 | lean |
macro m n:ident : command => `(def $n := 1)
m foo
#check foo
|
fb0a700952c00507464c8057e9d53b66dd543a4e | 55c7fc2bf55d496ace18cd6f3376e12bb14c8cc5 | /test/linarith.lean | 88523de91acfb1b4b9f7f94bc7e74d6b885f9810 | [
"Apache-2.0"
] | permissive | dupuisf/mathlib | 62de4ec6544bf3b79086afd27b6529acfaf2c1bb | 8582b06b0a5d06c33ee07d0bdf7c646cae22cf36 | refs/heads/master | 1,669,494,854,016 | 1,595,692,409,000 | 1,595,692,409,000 | 272,046,630 | 0 | 0 | Apache-2.0 | 1,592,066,143,000 | 1,592,066,142,000 | null | UTF-8 | Lean | false | false | 9,844 | lean | import tactic.linarith
example {Ξ± : Type} (_inst : Ξ (a : Prop), decidable a)
[linear_ordered_field Ξ±]
{a b c : Ξ±}
(ha : a < 0)
(hb : Β¬b = 0)
(hc' : c = 0)
(h : (1 - a) * (b * b) β€ 0)
(hc : 0 β€ 0)
(this : -(a * -b * -b + b * -b + 0) = (1 - a) * (b * b))
(h : (1 - a) * (b * b) β€ 0) :
0 < 1 - a :=
begin
linarith
end
example (e b c a v0 v1 : β) (h1 : v0 = 5*a) (h2 : v1 = 3*b) (h3 : v0 + v1 + c = 10) :
v0 + 5 + (v1 - 3) + (c - 2) = 10 :=
by linarith
example (u v r s t : β) (h : 0 < u*(t*v + t*r + s)) : 0 < (t*(r + v) + s)*3*u :=
by linarith
example (A B : β) (h : 0 < A * B) : 0 < 8*A*B :=
begin
linarith
end
example (A B : β) (h : 0 < A * B) : 0 < A*8*B :=
begin
linarith
end
example (A B : β) (h : 0 < A * B) : 0 < A*B/8 :=
begin
linarith
end
example (A B : β) (h : 0 < A * B) : 0 < A/8*B :=
begin
linarith
end
example (Ξ΅ : β) (h1 : Ξ΅ > 0) : Ξ΅ / 2 + Ξ΅ / 3 + Ξ΅ / 7 < Ξ΅ :=
by linarith
example (x y z : β) (h1 : 2*x < 3*y) (h2 : -4*x + z/2 < 0)
(h3 : 12*y - z < 0) : false :=
by linarith
example (Ξ΅ : β) (h1 : Ξ΅ > 0) : Ξ΅ / 2 < Ξ΅ :=
by linarith
example (Ξ΅ : β) (h1 : Ξ΅ > 0) : Ξ΅ / 3 + Ξ΅ / 3 + Ξ΅ / 3 = Ξ΅ :=
by linarith
example (a b c : β) (h2 : b + 2 > 3 + b) : false :=
by linarith {discharger := `[ring SOP]}
example (a b c : β) (h2 : b + 2 > 3 + b) : false :=
by linarith
example (a b c : β) (x y : β€) (h1 : x β€ 3*y) (h2 : b + 2 > 3 + b) : false :=
by linarith {restrict_type := β}
example (g v V c h : β) (h1 : h = 0) (h2 : v = V) (h3 : V > 0) (h4 : g > 0)
(h5 : 0 β€ c) (h6 : c < 1) :
v β€ V :=
by linarith
example (x y z : β) (h1 : 2*x + ((-3)*y) < 0) (h2 : (-4)*x + 2*z < 0)
(h3 : 12*y + (-4)* z < 0) (h4 : nat.prime 7) : false :=
by linarith
example (x y z : β) (h1 : 2*1*x + (3)*(y*(-1)) < 0) (h2 : (-2)*x*2 < -(z + z))
(h3 : 12*y + (-4)* z < 0) (h4 : nat.prime 7) : false :=
by linarith
example (x y z : β€) (h1 : 2*x < 3*y) (h2 : -4*x + 2*z < 0)
(h3 : 12*y - 4* z < 0) : false :=
by linarith
example (x y z : β€) (h1 : 2*x < 3*y) (h2 : -4*x + 2*z < 0) (h3 : x*y < 5)
(h3 : 12*y - 4* z < 0) : false :=
by linarith
example (x y z : β€) (h1 : 2*x < 3*y) (h2 : -4*x + 2*z < 0) (h3 : x*y < 5) :
Β¬ 12*y - 4* z < 0 :=
by linarith
example (w x y z : β€) (h1 : 4*x + (-3)*y + 6*w β€ 0) (h2 : (-1)*x < 0)
(h3 : y < 0) (h4 : w β₯ 0) (h5 : nat.prime x.nat_abs) : false :=
by linarith
example (a b c : β) (h1 : a > 0) (h2 : b > 5) (h3 : c < -10)
(h4 : a + b - c < 3) : false :=
by linarith
example (a b c : β) (h2 : b > 0) (h3 : Β¬ b β₯ 0) : false :=
by linarith
example (a b c : β) (h2 : (2 : β) > 3) : a + b - c β₯ 3 :=
by linarith {exfalso := ff}
example (x : β) (hx : x > 0) (h : x.num < 0) : false :=
by linarith [rat.num_pos_iff_pos.mpr hx, h]
example (x : β) (hx : x > 0) (h : x.num < 0) : false :=
by linarith only [rat.num_pos_iff_pos.mpr hx, h]
example (x y z : β) (hx : x β€ 3*y) (h2 : y β€ 2*z) (h3 : x β₯ 6*z) : x = 3*y :=
by linarith
example (x y z : β) (hx : x β€ 3*y) (h2 : y β€ 2*z) (h3 : x β₯ 6*z) : x = 3*y :=
by linarith
example (x y z : β) (hx : Β¬ x > 3*y) (h2 : Β¬ y > 2*z) (h3 : x β₯ 6*z) : x = 3*y :=
by linarith
example (h1 : (1 : β) < 1) : false :=
by linarith
example (a b c : β) (h2 : b > 0) (h3 : b < 0) : nat.prime 10 :=
by linarith
example (a b c : β) : a + b β₯ a :=
by linarith
example (a b c : β) : Β¬ a + b < a :=
by linarith
example (x y : β) (h : 6 + ((x + 4) * x + (6 + 3 * y) * y) = 3) (h' : (x + 4) * x β₯ 0)
(h'' : (6 + 3 * y) * y β₯ 0) : false :=
by linarith
example (x y : β)
(h : 6 + ((x + 4) * x + (6 + 3 * y) * y) = 3 β§ (x + 4) * x β₯ 0 β§ (6 + 3 * y) * y β₯ 0) : false :=
by linarith
example (a b i : β) (h1 : Β¬ a < i) (h2 : b < i) (h3 : a β€ b) : false :=
by linarith
example (n : β) (h1 : n β€ 3) (h2 : n > 2) : n = 3 := by linarith
example (z : β) (hz : Β¬ z β₯ 2) (h2 : Β¬ z + 1 β€ 2) : false :=
by linarith
example (z : β) (hz : Β¬ z β₯ 2) : z + 1 β€ 2 :=
by linarith
example (a b c : β) (h1 : 1 / a < b) (h2 : b < c) : 1 / a < c :=
by linarith
example
(N : β) (n : β) (Hirrelevant : n > N)
(A : β) (l : β) (h : A - l β€ -(A - l)) (h_1 : Β¬A β€ -A) (h_2 : Β¬l β€ -l)
(h_3 : -(A - l) < 1) : A < l + 1 := by linarith
example (d : β) (q n : β) (h1 : ((q : β) - 1)*n β₯ 0) (h2 : d = 2/3*(((q : β) - 1)*n)) :
d β€ ((q : β) - 1)*n :=
by linarith
example (d : β) (q n : β) (h1 : ((q : β) - 1)*n β₯ 0) (h2 : d = 2/3*(((q : β) - 1)*n)) :
((q : β) - 1)*n - d = 1/3 * (((q : β) - 1)*n) :=
by linarith
example (a : β) (ha : 0 β€ a) : 0 * 0 β€ 2 * a :=
by linarith
example (x : β) : id x β₯ x :=
by success_if_fail {linarith}; linarith!
example (x y z : β) (hx : x < 5) (hx2 : x > 5) (hy : y < 5000000000) (hz : z > 34*y) : false :=
by linarith only [hx, hx2]
example (x y z : β) (hx : x < 5) (hy : y < 5000000000) (hz : z > 34*y) : x β€ 5 :=
by linarith only [hx]
example (x y : β) (h : x < y) : x β y := by linarith
example (x y : β) (h : x < y) : Β¬ x = y := by linarith
example (u v x y A B : β)
(a : 0 < A)
(a_1 : 0 <= 1 - A)
(a_2 : 0 <= B - 1)
(a_3 : 0 <= B - x)
(a_4 : 0 <= B - y)
(a_5 : 0 <= u)
(a_6 : 0 <= v)
(a_7 : 0 < A - u)
(a_8 : 0 < A - v) :
u * y + v * x + u * v < 3 * A * B :=
by nlinarith
example (u v x y A B : β) : (0 < A) β (A β€ 1) β (1 β€ B)
β (x β€ B) β ( y β€ B)
β (0 β€ u ) β (0 β€ v )
β (u < A) β ( v < A)
β (u * y + v * x + u * v < 3 * A * B) :=
begin
intros,
nlinarith
end
example (u v x y A B : β)
(a : 0 < A)
(a_1 : 0 <= 1 - A)
(a_2 : 0 <= B - 1)
(a_3 : 0 <= B - x)
(a_4 : 0 <= B - y)
(a_5 : 0 <= u)
(a_6 : 0 <= v)
(a_7 : 0 < A - u)
(a_8 : 0 < A - v) :
(0 < A * A)
-> (0 <= A * (1 - A))
-> (0 <= A * (B - 1))
-> (0 <= A * (B - x))
-> (0 <= A * (B - y))
-> (0 <= A * u)
-> (0 <= A * v)
-> (0 < A * (A - u))
-> (0 < A * (A - v))
-> (0 <= (1 - A) * A)
-> (0 <= (1 - A) * (1 - A))
-> (0 <= (1 - A) * (B - 1))
-> (0 <= (1 - A) * (B - x))
-> (0 <= (1 - A) * (B - y))
-> (0 <= (1 - A) * u)
-> (0 <= (1 - A) * v)
-> (0 <= (1 - A) * (A - u))
-> (0 <= (1 - A) * (A - v))
-> (0 <= (B - 1) * A)
-> (0 <= (B - 1) * (1 - A))
-> (0 <= (B - 1) * (B - 1))
-> (0 <= (B - 1) * (B - x))
-> (0 <= (B - 1) * (B - y))
-> (0 <= (B - 1) * u)
-> (0 <= (B - 1) * v)
-> (0 <= (B - 1) * (A - u))
-> (0 <= (B - 1) * (A - v))
-> (0 <= (B - x) * A)
-> (0 <= (B - x) * (1 - A))
-> (0 <= (B - x) * (B - 1))
-> (0 <= (B - x) * (B - x))
-> (0 <= (B - x) * (B - y))
-> (0 <= (B - x) * u)
-> (0 <= (B - x) * v)
-> (0 <= (B - x) * (A - u))
-> (0 <= (B - x) * (A - v))
-> (0 <= (B - y) * A)
-> (0 <= (B - y) * (1 - A))
-> (0 <= (B - y) * (B - 1))
-> (0 <= (B - y) * (B - x))
-> (0 <= (B - y) * (B - y))
-> (0 <= (B - y) * u)
-> (0 <= (B - y) * v)
-> (0 <= (B - y) * (A - u))
-> (0 <= (B - y) * (A - v))
-> (0 <= u * A)
-> (0 <= u * (1 - A))
-> (0 <= u * (B - 1))
-> (0 <= u * (B - x))
-> (0 <= u * (B - y))
-> (0 <= u * u)
-> (0 <= u * v)
-> (0 <= u * (A - u))
-> (0 <= u * (A - v))
-> (0 <= v * A)
-> (0 <= v * (1 - A))
-> (0 <= v * (B - 1))
-> (0 <= v * (B - x))
-> (0 <= v * (B - y))
-> (0 <= v * u)
-> (0 <= v * v)
-> (0 <= v * (A - u))
-> (0 <= v * (A - v))
-> (0 < (A - u) * A)
-> (0 <= (A - u) * (1 - A))
-> (0 <= (A - u) * (B - 1))
-> (0 <= (A - u) * (B - x))
-> (0 <= (A - u) * (B - y))
-> (0 <= (A - u) * u)
-> (0 <= (A - u) * v)
-> (0 < (A - u) * (A - u))
-> (0 < (A - u) * (A - v))
-> (0 < (A - v) * A)
-> (0 <= (A - v) * (1 - A))
-> (0 <= (A - v) * (B - 1))
-> (0 <= (A - v) * (B - x))
-> (0 <= (A - v) * (B - y))
-> (0 <= (A - v) * u)
-> (0 <= (A - v) * v)
-> (0 < (A - v) * (A - u))
-> (0 < (A - v) * (A - v))
->
u * y + v * x + u * v < 3 * A * B :=
begin
intros,
linarith
end
example (A B : β) : (0 < A) β (1 β€ B) β (0 < A / 8 * B) :=
begin
intros, nlinarith
end
example (x y : β) : 0 β€ x ^2 + y ^2 :=
by nlinarith
example (x y : β) : 0 β€ x*x + y*y :=
by nlinarith
example (x y : β) : x = 0 β y = 0 β x*x + y*y = 0 :=
by intros; nlinarith
lemma norm_eq_zero_iff {x y : β} : x * x + y * y = 0 β x = 0 β§ y = 0 :=
begin
split,
{ intro, split; nlinarith },
{ intro, nlinarith }
end
lemma norm_nonpos_right {x y : β} (h1 : x * x + y * y β€ 0) : y = 0 :=
by nlinarith
lemma norm_nonpos_left (x y : β) (h1 : x * x + y * y β€ 0) : x = 0 :=
by nlinarith
variables {E : Type*} [add_group E]
example (f : β€ β E) (h : 0 = f 0) : 1 β€ 2 := by nlinarith
example (a : E) (h : a = a) : 1 β€ 2 := by nlinarith
-- test that the apply bug doesn't affect linarith preprocessing
constant Ξ± : Type
def leΞ± : Ξ± β Ξ± β Prop := Ξ» a b, β c : Ξ±, true
noncomputable instance : discrete_linear_ordered_field Ξ± :=
by refine_struct { le := leΞ± }; admit
example (a : Ξ±) (ha : a < 2) : a β€ a :=
by linarith
example (p q r s t u v w : β) (h1 : p + u = q + t) (h2 : r + w = s + v) :
p * r + q * s + (t * w + u * v) = p * s + q * r + (t * v + u * w) :=
by nlinarith
-- Tests involving a norm, including that squares in a type where `pow_two_nonneg` does not apply
-- do not cause an exception
variables {R : Type*} [ring R] (abs : R β β)
lemma abs_nonneg' : β r, 0 β€ abs r := sorry
example (t : R) (a b : β) (h : a β€ b) : abs (t^2) * a β€ abs (t^2) * b :=
by nlinarith [abs_nonneg' abs (t^2)]
example (t : R) (a b : β) (h : a β€ b) : a β€ abs (t^2) + b :=
by linarith [abs_nonneg' abs (t^2)]
example (t : R) (a b : β) (h : a β€ b) : abs t * a β€ abs t * b :=
by nlinarith [abs_nonneg' abs t]
constant T : Type
attribute [instance]
constant T_zero : ordered_ring T
namespace T
lemma zero_lt_one : (0 : T) < 1 := sorry
lemma works {a b : β} (hab : a β€ b) (h : b < a) : false :=
begin
linarith,
end
end T
|
a3810df4a3b0a04ac9b45010f5721c41d4872713 | 0c1546a496eccfb56620165cad015f88d56190c5 | /library/init/data/quot.lean | 3c69076391e5f3060ca6d1e680d3f0d01bac2c4b | [
"Apache-2.0"
] | permissive | Solertis/lean | 491e0939957486f664498fbfb02546e042699958 | 84188c5aa1673fdf37a082b2de8562dddf53df3f | refs/heads/master | 1,610,174,257,606 | 1,486,263,620,000 | 1,486,263,620,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 9,401 | 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
Quotient types.
-/
prelude
/- We import propext here, otherwise we would need a quot.lift for propositions. -/
import init.data.sigma.basic init.logic init.propext init.data.setoid
universe variables u v
-- iff can now be used to do substitutions in a calculation
attribute [subst]
lemma iff_subst {a b : Prop} {p : Prop β Prop} (hβ : a β b) (hβ : p a) : p b :=
eq.subst (propext hβ) hβ
namespace quot
constant sound : Ξ {Ξ± : Type u} {r : Ξ± β Ξ± β Prop} {a b : Ξ±}, r a b β quot.mk r a = quot.mk r b
attribute [elab_as_eliminator] lift ind
protected lemma lift_beta {Ξ± : Type u} {r : Ξ± β Ξ± β Prop} {Ξ² : Type v} (f : Ξ± β Ξ²) (c : β a b, r a b β f a = f b) (a : Ξ±) : lift f c (quot.mk r a) = f a :=
rfl
protected lemma ind_beta {Ξ± : Type u} {r : Ξ± β Ξ± β Prop} {Ξ² : quot r β Prop} (p : β a, Ξ² (quot.mk r a)) (a : Ξ±) : (ind p (quot.mk r a) : Ξ² (quot.mk r a)) = p a :=
rfl
attribute [reducible, elab_as_eliminator]
protected def lift_on {Ξ± : Type u} {Ξ² : Type v} {r : Ξ± β Ξ± β Prop} (q : quot r) (f : Ξ± β Ξ²) (c : β a b, r a b β f a = f b) : Ξ² :=
lift f c q
attribute [elab_as_eliminator]
protected lemma induction_on {Ξ± : Type u} {r : Ξ± β Ξ± β Prop} {Ξ² : quot r β Prop} (q : quot r) (h : β a, Ξ² (quot.mk r a)) : Ξ² q :=
ind h q
lemma exists_rep {Ξ± : Type u} {r : Ξ± β Ξ± β Prop} (q : quot r) : β a : Ξ±, (quot.mk r a) = q :=
quot.induction_on q (Ξ» a, β¨a, rflβ©)
section
variable {Ξ± : Type u}
variable {r : Ξ± β Ξ± β Prop}
variable {Ξ² : quot r β Type v}
local notation `β¦`:max a `β§` := quot.mk r a
attribute [reducible]
protected def indep (f : Ξ a, Ξ² β¦aβ§) (a : Ξ±) : Ξ£ q, Ξ² q :=
β¨β¦aβ§, f aβ©
protected lemma indep_coherent (f : Ξ a, Ξ² β¦aβ§)
(h : β (a b : Ξ±) (p : r a b), (eq.rec (f a) (sound p) : Ξ² β¦bβ§) = f b)
: β a b, r a b β quot.indep f a = quot.indep f b :=
Ξ» a b e, sigma.eq (sound e) (h a b e)
protected lemma lift_indep_pr1
(f : Ξ a, Ξ² β¦aβ§) (h : β (a b : Ξ±) (p : r a b), (eq.rec (f a) (sound p) : Ξ² β¦bβ§) = f b)
(q : quot r) : (lift (quot.indep f) (quot.indep_coherent f h) q).1 = q :=
quot.ind (Ξ» (a : Ξ±), eq.refl (quot.indep f a).1) q
attribute [reducible, elab_as_eliminator]
protected def rec
(f : Ξ a, Ξ² β¦aβ§) (h : β (a b : Ξ±) (p : r a b), (eq.rec (f a) (sound p) : Ξ² β¦bβ§) = f b)
(q : quot r) : Ξ² q :=
eq.rec_on (quot.lift_indep_pr1 f h q) ((lift (quot.indep f) (quot.indep_coherent f h) q).2)
attribute [reducible, elab_as_eliminator]
protected def rec_on
(q : quot r) (f : Ξ a, Ξ² β¦aβ§) (h : β (a b : Ξ±) (p : r a b), (eq.rec (f a) (sound p) : Ξ² β¦bβ§) = f b) : Ξ² q :=
quot.rec f h q
attribute [reducible, elab_as_eliminator]
protected def rec_on_subsingleton
[h : β a, subsingleton (Ξ² β¦aβ§)] (q : quot r) (f : Ξ a, Ξ² β¦aβ§) : Ξ² q :=
quot.rec f (Ξ» a b h, subsingleton.elim _ (f b)) q
attribute [reducible, elab_as_eliminator]
protected def hrec_on
(q : quot r) (f : Ξ a, Ξ² β¦aβ§) (c : β (a b : Ξ±) (p : r a b), f a == f b) : Ξ² q :=
quot.rec_on q f
(Ξ» a b p, eq_of_heq (calc
(eq.rec (f a) (sound p) : Ξ² β¦bβ§) == f a : eq_rec_heq (sound p) (f a)
... == f b : c a b p))
end
end quot
def quotient {Ξ± : Type u} (s : setoid Ξ±) :=
@quot Ξ± setoid.r
namespace quotient
protected def mk {Ξ± : Type u} [s : setoid Ξ±] (a : Ξ±) : quotient s :=
quot.mk setoid.r a
notation `β¦`:max a `β§`:0 := quotient.mk a
def sound {Ξ± : Type u} [s : setoid Ξ±] {a b : Ξ±} : a β b β β¦aβ§ = β¦bβ§ :=
quot.sound
attribute [reducible, elab_as_eliminator]
protected def lift {Ξ± : Type u} {Ξ² : Type v} [s : setoid Ξ±] (f : Ξ± β Ξ²) : (β a b, a β b β f a = f b) β quotient s β Ξ² :=
quot.lift f
attribute [elab_as_eliminator]
protected lemma ind {Ξ± : Type u} [s : setoid Ξ±] {Ξ² : quotient s β Prop} : (β a, Ξ² β¦aβ§) β β q, Ξ² q :=
quot.ind
attribute [reducible, elab_as_eliminator]
protected def lift_on {Ξ± : Type u} {Ξ² : Type v} [s : setoid Ξ±] (q : quotient s) (f : Ξ± β Ξ²) (c : β a b, a β b β f a = f b) : Ξ² :=
quot.lift_on q f c
attribute [elab_as_eliminator]
protected lemma induction_on {Ξ± : Type u} [s : setoid Ξ±] {Ξ² : quotient s β Prop} (q : quotient s) (h : β a, Ξ² β¦aβ§) : Ξ² q :=
quot.induction_on q h
lemma exists_rep {Ξ± : Type u} [s : setoid Ξ±] (q : quotient s) : β a : Ξ±, β¦aβ§ = q :=
quot.exists_rep q
section
variable {Ξ± : Type u}
variable [s : setoid Ξ±]
variable {Ξ² : quotient s β Type v}
protected def rec
(f : Ξ a, Ξ² β¦aβ§) (h : β (a b : Ξ±) (p : a β b), (eq.rec (f a) (quotient.sound p) : Ξ² β¦bβ§) = f b)
(q : quotient s) : Ξ² q :=
quot.rec f h q
attribute [reducible, elab_as_eliminator]
protected def rec_on
(q : quotient s) (f : Ξ a, Ξ² β¦aβ§) (h : β (a b : Ξ±) (p : a β b), (eq.rec (f a) (quotient.sound p) : Ξ² β¦bβ§) = f b) : Ξ² q :=
quot.rec_on q f h
attribute [reducible, elab_as_eliminator]
protected def rec_on_subsingleton
[h : β a, subsingleton (Ξ² β¦aβ§)] (q : quotient s) (f : Ξ a, Ξ² β¦aβ§) : Ξ² q :=
@quot.rec_on_subsingleton _ _ _ h q f
attribute [reducible, elab_as_eliminator]
protected def hrec_on
(q : quotient s) (f : Ξ a, Ξ² β¦aβ§) (c : β (a b : Ξ±) (p : a β b), f a == f b) : Ξ² q :=
quot.hrec_on q f c
end
section
universe variables u_a u_b u_c
variables {Ξ± : Type u_a} {Ξ² : Type u_b} {Ο : Type u_c}
variables [sβ : setoid Ξ±] [sβ : setoid Ξ²]
include sβ sβ
attribute [reducible, elab_as_eliminator]
protected def liftβ
(f : Ξ± β Ξ² β Ο)(c : β aβ aβ bβ bβ, aβ β bβ β aβ β bβ β f aβ aβ = f bβ bβ)
(qβ : quotient sβ) (qβ : quotient sβ) : Ο :=
quotient.lift
(Ξ» (aβ : Ξ±), quot.lift (f aβ) (Ξ» (a b : Ξ²), c aβ a aβ b (setoid.refl aβ)) qβ)
(Ξ» (a b : Ξ±) (h : a β b),
@quotient.ind Ξ² sβ
(Ξ» (a_1 : quotient sβ),
(quotient.lift (f a) (Ξ» (a_1 b : Ξ²), c a a_1 a b (setoid.refl a)) a_1)
=
(quotient.lift (f b) (Ξ» (a b_1 : Ξ²), c b a b b_1 (setoid.refl b)) a_1))
(Ξ» (a' : Ξ²), c a a' b a' h (setoid.refl a'))
qβ)
qβ
attribute [reducible, elab_as_eliminator]
protected def lift_onβ
(qβ : quotient sβ) (qβ : quotient sβ) (f : Ξ± β Ξ² β Ο) (c : β aβ aβ bβ bβ, aβ β bβ β aβ β bβ β f aβ aβ = f bβ bβ) : Ο :=
quotient.liftβ f c qβ qβ
attribute [elab_as_eliminator]
protected lemma indβ {Ο : quotient sβ β quotient sβ β Prop} (h : β a b, Ο β¦aβ§ β¦bβ§) (qβ : quotient sβ) (qβ : quotient sβ) : Ο qβ qβ :=
quotient.ind (Ξ» aβ, quotient.ind (Ξ» aβ, h aβ aβ) qβ) qβ
attribute [elab_as_eliminator]
protected lemma induction_onβ
{Ο : quotient sβ β quotient sβ β Prop} (qβ : quotient sβ) (qβ : quotient sβ) (h : β a b, Ο β¦aβ§ β¦bβ§) : Ο qβ qβ :=
quotient.ind (Ξ» aβ, quotient.ind (Ξ» aβ, h aβ aβ) qβ) qβ
attribute [elab_as_eliminator]
protected lemma induction_onβ
[sβ : setoid Ο]
{Ξ΄ : quotient sβ β quotient sβ β quotient sβ β Prop} (qβ : quotient sβ) (qβ : quotient sβ) (qβ : quotient sβ) (h : β a b c, Ξ΄ β¦aβ§ β¦bβ§ β¦cβ§)
: Ξ΄ qβ qβ qβ :=
quot.ind (Ξ» aβ, quot.ind (Ξ» aβ, quot.ind (Ξ» aβ, h aβ aβ aβ) qβ) qβ) qβ
end
section exact
variable {Ξ± : Type u}
variable [s : setoid Ξ±]
include s
private def rel (qβ qβ : quotient s) : Prop :=
quotient.lift_onβ qβ qβ
(Ξ» aβ aβ, aβ β aβ)
(Ξ» aβ aβ bβ bβ aβbβ aβbβ,
propext (iff.intro
(Ξ» aβaβ, setoid.trans (setoid.symm aβbβ) (setoid.trans aβaβ aβbβ))
(Ξ» bβbβ, setoid.trans aβbβ (setoid.trans bβbβ (setoid.symm aβbβ)))))
local infix `~` := rel
private lemma rel.refl : β q : quotient s, q ~ q :=
Ξ» q, quot.induction_on q (Ξ» a, setoid.refl a)
private lemma eq_imp_rel {qβ qβ : quotient s} : qβ = qβ β qβ ~ qβ :=
assume h, eq.rec_on h (rel.refl qβ)
lemma exact {a b : Ξ±} : β¦aβ§ = β¦bβ§ β a β b :=
assume h, eq_imp_rel h
end exact
section
universe variables u_a u_b u_c
variables {Ξ± : Type u_a} {Ξ² : Type u_b}
variables [sβ : setoid Ξ±] [sβ : setoid Ξ²]
include sβ sβ
attribute [reducible, elab_as_eliminator]
protected def rec_on_subsingletonβ
{Ο : quotient sβ β quotient sβ β Type u_c} [h : β a b, subsingleton (Ο β¦aβ§ β¦bβ§)]
(qβ : quotient sβ) (qβ : quotient sβ) (f : Ξ a b, Ο β¦aβ§ β¦bβ§) : Ο qβ qβ:=
@quotient.rec_on_subsingleton _ sβ (Ξ» q, Ο q qβ) (Ξ» a, quotient.ind (Ξ» b, h a b) qβ) qβ
(Ξ» a, quotient.rec_on_subsingleton qβ (Ξ» b, f a b))
end
end quotient
open decidable
instance {Ξ± : Type u} {s : setoid Ξ±} [d : β a b : Ξ±, decidable (a β b)] : decidable_eq (quotient s) :=
Ξ» qβ qβ : quotient s,
quotient.rec_on_subsingletonβ qβ qβ
(Ξ» aβ aβ,
match (d aβ aβ) with
| (is_true hβ) := is_true (quotient.sound hβ)
| (is_false hβ) := is_false (Ξ» h, absurd (quotient.exact h) hβ)
end)
|
0b635ead2eba1e5ee3557a7ef31d9f2cf3e0b314 | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/data/list/big_operators/basic.lean | 4e6925515baf0f182acdc81edd0d8b0ffda8e9e4 | [
"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 | 23,316 | 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, Floris van Doorn, SΓ©bastien GouΓ«zel, Alex J. Best
-/
import data.int.order.basic
import data.list.forall2
/-!
# Sums and products from lists
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
This file provides basic results about `list.prod`, `list.sum`, which calculate the product and sum
of elements of a list and `list.alternating_prod`, `list.alternating_sum`, their alternating
counterparts. These are defined in [`data.list.defs`](./defs).
-/
variables {ΞΉ Ξ± M N P Mβ G R : Type*}
namespace list
section monoid
variables [monoid M] [monoid N] [monoid P] {l lβ lβ : list M} {a : M}
@[simp, to_additive]
lemma prod_nil : ([] : list M).prod = 1 := rfl
@[to_additive]
lemma prod_singleton : [a].prod = a := one_mul a
@[simp, to_additive]
lemma prod_cons : (a :: l).prod = a * l.prod :=
calc (a :: l).prod = foldl (*) (a * 1) l : by simp only [list.prod, foldl_cons, one_mul, mul_one]
... = _ : foldl_assoc
@[simp, to_additive]
lemma prod_append : (lβ ++ lβ).prod = lβ.prod * lβ.prod :=
calc (lβ ++ lβ).prod = foldl (*) (foldl (*) 1 lβ * 1) lβ : by simp [list.prod]
... = lβ.prod * lβ.prod : foldl_assoc
@[to_additive]
lemma prod_concat : (l.concat a).prod = l.prod * a :=
by rw [concat_eq_append, prod_append, prod_singleton]
@[simp, to_additive]
lemma prod_join {l : list (list M)} : l.join.prod = (l.map list.prod).prod :=
by induction l; [refl, simp only [*, list.join, map, prod_append, prod_cons]]
@[to_additive]
lemma prod_eq_foldr : l.prod = foldr (*) 1 l :=
list.rec_on l rfl $ Ξ» a l ihl, by rw [prod_cons, foldr_cons, ihl]
@[simp, priority 500, to_additive]
theorem prod_replicate (n : β) (a : M) : (replicate n a).prod = a ^ n :=
begin
induction n with n ih,
{ rw pow_zero, refl },
{ rw [list.replicate_succ, list.prod_cons, ih, pow_succ] }
end
@[to_additive sum_eq_card_nsmul]
lemma prod_eq_pow_card (l : list M) (m : M) (h : β (x β l), x = m) :
l.prod = m ^ l.length :=
by rw [β prod_replicate, β eq_replicate_length.2 h]
@[to_additive]
lemma prod_hom_rel (l : list ΞΉ) {r : M β N β Prop} {f : ΞΉ β M} {g : ΞΉ β N} (hβ : r 1 1)
(hβ : β β¦i a bβ¦, r a b β r (f i * a) (g i * b)) :
r (l.map f).prod (l.map g).prod :=
list.rec_on l hβ (Ξ» a l hl, by simp only [map_cons, prod_cons, hβ hl])
@[to_additive]
lemma prod_hom (l : list M) {F : Type*} [monoid_hom_class F M N] (f : F) :
(l.map f).prod = f l.prod :=
by { simp only [prod, foldl_map, β map_one f],
exact l.foldl_hom _ _ _ 1 (map_mul f) }
@[to_additive]
lemma prod_homβ (l : list ΞΉ) (f : M β N β P)
(hf : β a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (fβ : ΞΉ β M) (fβ : ΞΉ β N) :
(l.map $ Ξ» i, f (fβ i) (fβ i)).prod = f (l.map fβ).prod (l.map fβ).prod :=
begin
simp only [prod, foldl_map],
convert l.foldl_homβ (Ξ» a b, f a b) _ _ _ _ _ (Ξ» a b i, _),
{ exact hf'.symm },
{ exact hf _ _ _ _ }
end
@[simp, to_additive]
lemma prod_map_mul {Ξ± : Type*} [comm_monoid Ξ±] {l : list ΞΉ} {f g : ΞΉ β Ξ±} :
(l.map $ Ξ» i, f i * g i).prod = (l.map f).prod * (l.map g).prod :=
l.prod_homβ (*) mul_mul_mul_comm (mul_one _) _ _
@[simp]
lemma prod_map_neg {Ξ±} [comm_monoid Ξ±] [has_distrib_neg Ξ±] (l : list Ξ±) :
(l.map has_neg.neg).prod = (-1) ^ l.length * l.prod :=
by simpa only [id, neg_mul, one_mul, map_const', prod_replicate, map_id]
using @prod_map_mul Ξ± Ξ± _ l (Ξ» _, -1) id
@[to_additive]
lemma prod_map_hom (L : list ΞΉ) (f : ΞΉ β M) {G : Type*} [monoid_hom_class G M N] (g : G) :
(L.map (g β f)).prod = g ((L.map f).prod) :=
by rw [β prod_hom, map_map]
@[to_additive]
lemma prod_is_unit : Ξ {L : list M} (u : β m β L, is_unit m), is_unit L.prod
| [] _ := by simp
| (h :: t) u :=
begin
simp only [list.prod_cons],
exact is_unit.mul (u h (mem_cons_self h t)) (prod_is_unit (Ξ» m mt, u m (mem_cons_of_mem h mt)))
end
@[to_additive]
lemma prod_is_unit_iff {Ξ± : Type*} [comm_monoid Ξ±] {L : list Ξ±} :
is_unit L.prod β β m β L, is_unit m :=
begin
refine β¨Ξ» h, _, prod_is_unitβ©,
induction L with m L ih,
{ exact Ξ» m' h', false.elim (not_mem_nil m' h'), },
rw [prod_cons, is_unit.mul_iff] at h,
exact Ξ» m' h', or.elim (eq_or_mem_of_mem_cons h') (Ξ» H, H.substr h.1) (Ξ» H, ih h.2 _ H),
end
@[simp, to_additive]
lemma prod_take_mul_prod_drop :
β (L : list M) (i : β), (L.take i).prod * (L.drop i).prod = L.prod
| [] i := by simp [nat.zero_le]
| L 0 := by simp
| (h :: t) (n+1) := by { dsimp, rw [prod_cons, prod_cons, mul_assoc, prod_take_mul_prod_drop] }
@[simp, to_additive]
lemma prod_take_succ :
β (L : list M) (i : β) (p), (L.take (i + 1)).prod = (L.take i).prod * L.nth_le i p
| [] i p := by cases p
| (h :: t) 0 _ := by simp
| (h :: t) (n+1) _ := by { dsimp, rw [prod_cons, prod_cons, prod_take_succ, mul_assoc] }
/-- A list with product not one must have positive length. -/
@[to_additive "A list with sum not zero must have positive length."]
lemma length_pos_of_prod_ne_one (L : list M) (h : L.prod β 1) : 0 < L.length :=
by { cases L, { contrapose h, simp }, { simp } }
/-- A list with product greater than one must have positive length. -/
@[to_additive length_pos_of_sum_pos "A list with positive sum must have positive length."]
lemma length_pos_of_one_lt_prod [preorder M] (L : list M) (h : 1 < L.prod) :
0 < L.length :=
length_pos_of_prod_ne_one L h.ne'
/-- A list with product less than one must have positive length. -/
@[to_additive "A list with negative sum must have positive length."]
lemma length_pos_of_prod_lt_one [preorder M] (L : list M) (h : L.prod < 1) :
0 < L.length :=
length_pos_of_prod_ne_one L h.ne
@[to_additive]
lemma prod_update_nth : β (L : list M) (n : β) (a : M),
(L.update_nth n a).prod =
(L.take n).prod * (if n < L.length then a else 1) * (L.drop (n + 1)).prod
| (x :: xs) 0 a := by simp [update_nth]
| (x :: xs) (i+1) a := by simp [update_nth, prod_update_nth xs i a, mul_assoc]
| [] _ _ := by simp [update_nth, (nat.zero_le _).not_lt, nat.zero_le]
open mul_opposite
/-- We'd like to state this as `L.head * L.tail.prod = L.prod`, but because `L.head` relies on an
inhabited instance to return a garbage value on the empty list, this is not possible.
Instead, we write the statement in terms of `(L.nth 0).get_or_else 1`.
-/
@[to_additive "We'd like to state this as `L.head + L.tail.sum = L.sum`, but because `L.head`
relies on an inhabited instance to return a garbage value on the empty list, this is not possible.
Instead, we write the statement in terms of `(L.nth 0).get_or_else 0`."]
lemma nth_zero_mul_tail_prod (l : list M) : (l.nth 0).get_or_else 1 * l.tail.prod = l.prod :=
by cases l; simp
/-- Same as `nth_zero_mul_tail_prod`, but avoiding the `list.head` garbage complication by requiring
the list to be nonempty. -/
@[to_additive "Same as `nth_zero_add_tail_sum`, but avoiding the `list.head` garbage complication
by requiring the list to be nonempty."]
lemma head_mul_tail_prod_of_ne_nil [inhabited M] (l : list M) (h : l β []) :
l.head * l.tail.prod = l.prod :=
by cases l; [contradiction, simp]
@[to_additive]
lemma _root_.commute.list_prod_right (l : list M) (y : M) (h : β (x β l), commute y x) :
commute y l.prod :=
begin
induction l with z l IH,
{ simp },
{ rw list.ball_cons at h,
rw list.prod_cons,
exact commute.mul_right h.1 (IH h.2), }
end
@[to_additive]
lemma _root_.commute.list_prod_left (l : list M) (y : M) (h : β (x β l), commute x y) :
commute l.prod y :=
(commute.list_prod_right _ _ $ Ξ» x hx, (h _ hx).symm).symm
@[to_additive sum_le_sum] lemma forallβ.prod_le_prod' [preorder M]
[covariant_class M M (function.swap (*)) (β€)] [covariant_class M M (*) (β€)]
{lβ lβ : list M} (h : forallβ (β€) lβ lβ) : lβ.prod β€ lβ.prod :=
begin
induction h with a b la lb hab ih ih',
{ refl },
{ simpa only [prod_cons] using mul_le_mul' hab ih' }
end
/-- If `lβ` is a sublist of `lβ` and all elements of `lβ` are greater than or equal to one, then
`lβ.prod β€ lβ.prod`. One can prove a stronger version assuming `β a β lβ.diff lβ, 1 β€ a` instead
of `β a β lβ, 1 β€ a` but this lemma is not yet in `mathlib`. -/
@[to_additive sum_le_sum "If `lβ` is a sublist of `lβ` and all elements of `lβ` are nonnegative,
then `lβ.sum β€ lβ.sum`. One can prove a stronger version assuming `β a β lβ.diff lβ, 0 β€ a` instead
of `β a β lβ, 0 β€ a` but this lemma is not yet in `mathlib`."]
lemma sublist.prod_le_prod' [preorder M] [covariant_class M M (function.swap (*)) (β€)]
[covariant_class M M (*) (β€)] {lβ lβ : list M} (h : lβ <+ lβ) (hβ : β a β lβ, (1 : M) β€ a) :
lβ.prod β€ lβ.prod :=
begin
induction h, { refl },
case cons : lβ lβ a ih ih'
{ simp only [prod_cons, forall_mem_cons] at hβ β’,
exact (ih' hβ.2).trans (le_mul_of_one_le_left' hβ.1) },
case cons2 : lβ lβ a ih ih'
{ simp only [prod_cons, forall_mem_cons] at hβ β’,
exact mul_le_mul_left' (ih' hβ.2) _ }
end
@[to_additive sum_le_sum] lemma sublist_forallβ.prod_le_prod' [preorder M]
[covariant_class M M (function.swap (*)) (β€)] [covariant_class M M (*) (β€)]
{lβ lβ : list M} (h : sublist_forallβ (β€) lβ lβ) (hβ : β a β lβ, (1 : M) β€ a) :
lβ.prod β€ lβ.prod :=
let β¨l, hall, hsubβ© := sublist_forallβ_iff.1 h
in hall.prod_le_prod'.trans $ hsub.prod_le_prod' hβ
@[to_additive sum_le_sum] lemma prod_le_prod' [preorder M]
[covariant_class M M (function.swap (*)) (β€)] [covariant_class M M (*) (β€)]
{l : list ΞΉ} {f g : ΞΉ β M} (h : β i β l, f i β€ g i) :
(l.map f).prod β€ (l.map g).prod :=
forallβ.prod_le_prod' $ by simpa
@[to_additive sum_lt_sum] lemma prod_lt_prod'
[preorder M] [covariant_class M M (*) (<)] [covariant_class M M (*) (β€)]
[covariant_class M M (function.swap (*)) (<)] [covariant_class M M (function.swap (*)) (β€)]
{l : list ΞΉ} (f g : ΞΉ β M) (hβ : β i β l, f i β€ g i) (hβ : β i β l, f i < g i) :
(l.map f).prod < (l.map g).prod :=
begin
induction l with i l ihl, { rcases hβ with β¨_, β¨β©, _β© },
simp only [ball_cons, bex_cons, map_cons, prod_cons] at hβ hβ β’,
cases hβ,
exacts [mul_lt_mul_of_lt_of_le hβ (prod_le_prod' hβ.2),
mul_lt_mul_of_le_of_lt hβ.1 $ ihl hβ.2 hβ]
end
@[to_additive] lemma prod_lt_prod_of_ne_nil
[preorder M] [covariant_class M M (*) (<)] [covariant_class M M (*) (β€)]
[covariant_class M M (function.swap (*)) (<)] [covariant_class M M (function.swap (*)) (β€)]
{l : list ΞΉ} (hl : l β []) (f g : ΞΉ β M) (hlt : β i β l, f i < g i) :
(l.map f).prod < (l.map g).prod :=
prod_lt_prod' f g (Ξ» i hi, (hlt i hi).le) $ (exists_mem_of_ne_nil l hl).imp $ Ξ» i hi, β¨hi, hlt i hiβ©
@[to_additive sum_le_card_nsmul]
lemma prod_le_pow_card [preorder M]
[covariant_class M M (function.swap (*)) (β€)] [covariant_class M M (*) (β€)]
(l : list M) (n : M) (h : β (x β l), x β€ n) :
l.prod β€ n ^ l.length :=
by simpa only [map_id'', map_const, prod_replicate] using prod_le_prod' h
@[to_additive exists_lt_of_sum_lt] lemma exists_lt_of_prod_lt' [linear_order M]
[covariant_class M M (function.swap (*)) (β€)] [covariant_class M M (*) (β€)] {l : list ΞΉ}
(f g : ΞΉ β M) (h : (l.map f).prod < (l.map g).prod) :
β i β l, f i < g i :=
by { contrapose! h, exact prod_le_prod' h }
@[to_additive exists_le_of_sum_le]
lemma exists_le_of_prod_le' [linear_order M] [covariant_class M M (*) (<)]
[covariant_class M M (*) (β€)] [covariant_class M M (function.swap (*)) (<)]
[covariant_class M M (function.swap (*)) (β€)] {l : list ΞΉ} (hl : l β [])
(f g : ΞΉ β M) (h : (l.map f).prod β€ (l.map g).prod) :
β x β l, f x β€ g x :=
by { contrapose! h, exact prod_lt_prod_of_ne_nil hl _ _ h }
@[to_additive sum_nonneg]
lemma one_le_prod_of_one_le [preorder M] [covariant_class M M (*) (β€)] {l : list M}
(hlβ : β x β l, (1 : M) β€ x) :
1 β€ l.prod :=
begin
-- We don't use `pow_card_le_prod` to avoid assumption
-- [covariant_class M M (function.swap (*)) (β€)]
induction l with hd tl ih, { refl },
rw prod_cons,
exact one_le_mul (hlβ hd (mem_cons_self hd tl)) (ih (Ξ» x h, hlβ x (mem_cons_of_mem hd h)))
end
end monoid
section monoid_with_zero
variables [monoid_with_zero Mβ]
/-- If zero is an element of a list `L`, then `list.prod L = 0`. If the domain is a nontrivial
monoid with zero with no divisors, then this implication becomes an `iff`, see
`list.prod_eq_zero_iff`. -/
lemma prod_eq_zero {L : list Mβ} (h : (0 : Mβ) β L) : L.prod = 0 :=
begin
induction L with a L ihL,
{ exact absurd h (not_mem_nil _) },
{ rw prod_cons,
cases (mem_cons_iff _ _ _).1 h with ha hL,
exacts [mul_eq_zero_of_left ha.symm _, mul_eq_zero_of_right _ (ihL hL)] }
end
/-- Product of elements of a list `L` equals zero if and only if `0 β L`. See also
`list.prod_eq_zero` for an implication that needs weaker typeclass assumptions. -/
@[simp] lemma prod_eq_zero_iff [nontrivial Mβ] [no_zero_divisors Mβ] {L : list Mβ} :
L.prod = 0 β (0 : Mβ) β L :=
begin
induction L with a L ihL,
{ simp },
{ rw [prod_cons, mul_eq_zero, ihL, mem_cons_iff, eq_comm] }
end
lemma prod_ne_zero [nontrivial Mβ] [no_zero_divisors Mβ] {L : list Mβ} (hL : (0 : Mβ) β L) :
L.prod β 0 :=
mt prod_eq_zero_iff.1 hL
end monoid_with_zero
section group
variables [group G]
/-- This is the `list.prod` version of `mul_inv_rev` -/
@[to_additive "This is the `list.sum` version of `add_neg_rev`"]
lemma prod_inv_reverse : β (L : list G), L.prodβ»ΒΉ = (L.map (Ξ» x, xβ»ΒΉ)).reverse.prod
| [] := by simp
| (x :: xs) := by simp [prod_inv_reverse xs]
/-- A non-commutative variant of `list.prod_reverse` -/
@[to_additive "A non-commutative variant of `list.sum_reverse`"]
lemma prod_reverse_noncomm : β (L : list G), L.reverse.prod = (L.map (Ξ» x, xβ»ΒΉ)).prodβ»ΒΉ :=
by simp [prod_inv_reverse]
/-- Counterpart to `list.prod_take_succ` when we have an inverse operation -/
@[simp, to_additive /-"Counterpart to `list.sum_take_succ` when we have an negation operation"-/]
lemma prod_drop_succ :
β (L : list G) (i : β) (p), (L.drop (i + 1)).prod = (L.nth_le i p)β»ΒΉ * (L.drop i).prod
| [] i p := false.elim (nat.not_lt_zero _ p)
| (x :: xs) 0 p := by simp
| (x :: xs) (i + 1) p := prod_drop_succ xs i _
end group
section comm_group
variables [comm_group G]
/-- This is the `list.prod` version of `mul_inv` -/
@[to_additive "This is the `list.sum` version of `add_neg`"]
lemma prod_inv : β (L : list G), L.prodβ»ΒΉ = (L.map (Ξ» x, xβ»ΒΉ)).prod
| [] := by simp
| (x :: xs) := by simp [mul_comm, prod_inv xs]
/-- Alternative version of `list.prod_update_nth` when the list is over a group -/
@[to_additive /-"Alternative version of `list.sum_update_nth` when the list is over a group"-/]
lemma prod_update_nth' (L : list G) (n : β) (a : G) :
(L.update_nth n a).prod =
L.prod * (if hn : n < L.length then (L.nth_le n hn)β»ΒΉ * a else 1) :=
begin
refine (prod_update_nth L n a).trans _,
split_ifs with hn hn,
{ rw [mul_comm _ a, mul_assoc a, prod_drop_succ L n hn, mul_comm _ (drop n L).prod,
β mul_assoc (take n L).prod, prod_take_mul_prod_drop, mul_comm a, mul_assoc] },
{ simp only [take_all_of_le (le_of_not_lt hn), prod_nil, mul_one,
drop_eq_nil_of_le ((le_of_not_lt hn).trans n.le_succ)] }
end
end comm_group
@[to_additive]
lemma eq_of_prod_take_eq [left_cancel_monoid M] {L L' : list M} (h : L.length = L'.length)
(h' : β i β€ L.length, (L.take i).prod = (L'.take i).prod) : L = L' :=
begin
apply ext_le h (Ξ» i hβ hβ, _),
have : (L.take (i + 1)).prod = (L'.take (i + 1)).prod := h' _ (nat.succ_le_of_lt hβ),
rw [prod_take_succ L i hβ, prod_take_succ L' i hβ, h' i (le_of_lt hβ)] at this,
convert mul_left_cancel this
end
@[to_additive]
lemma monotone_prod_take [canonically_ordered_monoid M] (L : list M) :
monotone (Ξ» i, (L.take i).prod) :=
begin
apply monotone_nat_of_le_succ (Ξ» n, _),
cases lt_or_le n L.length with h h,
{ rw prod_take_succ _ _ h,
exact le_self_mul },
{ simp [take_all_of_le h, take_all_of_le (le_trans h (nat.le_succ _))] }
end
@[to_additive sum_pos]
lemma one_lt_prod_of_one_lt [ordered_comm_monoid M] :
β (l : list M) (hl : β x β l, (1 : M) < x) (hlβ : l β []), 1 < l.prod
| [] _ h := (h rfl).elim
| [b] h _ := by simpa using h
| (a :: b :: l) hlβ hlβ :=
begin
simp only [forall_eq_or_imp, list.mem_cons_iff _ a] at hlβ,
rw list.prod_cons,
apply one_lt_mul_of_lt_of_le' hlβ.1,
apply le_of_lt ((b :: l).one_lt_prod_of_one_lt hlβ.2 (l.cons_ne_nil b)),
end
@[to_additive]
lemma single_le_prod [ordered_comm_monoid M] {l : list M} (hlβ : β x β l, (1 : M) β€ x) :
β x β l, x β€ l.prod :=
begin
induction l,
{ simp },
simp_rw [prod_cons, forall_mem_cons] at β’ hlβ,
split,
{ exact le_mul_of_one_le_right' (one_le_prod_of_one_le hlβ.2) },
{ exact Ξ» x H, le_mul_of_one_le_of_le hlβ.1 (l_ih hlβ.right x H) },
end
@[to_additive all_zero_of_le_zero_le_of_sum_eq_zero]
lemma all_one_of_le_one_le_of_prod_eq_one [ordered_comm_monoid M]
{l : list M} (hlβ : β x β l, (1 : M) β€ x) (hlβ : l.prod = 1) {x : M} (hx : x β l) :
x = 1 :=
le_antisymm (hlβ βΈ single_le_prod hlβ _ hx) (hlβ x hx)
/-- Slightly more general version of `list.prod_eq_one_iff` for a non-ordered `monoid` -/
@[to_additive "Slightly more general version of `list.sum_eq_zero_iff`
for a non-ordered `add_monoid`"]
lemma prod_eq_one [monoid M] {l : list M} (hl : β (x β l), x = (1 : M)) : l.prod = 1 :=
begin
induction l with i l hil,
{ refl },
rw [list.prod_cons, hil (Ξ» x hx, hl _ (mem_cons_of_mem i hx)), hl _ (mem_cons_self i l), one_mul]
end
@[to_additive]
lemma exists_mem_ne_one_of_prod_ne_one [monoid M] {l : list M} (h : l.prod β 1) :
β (x β l), x β (1 : M) :=
by simpa only [not_forall] using mt prod_eq_one h
-- TODO: develop theory of tropical rings
lemma sum_le_foldr_max [add_monoid M] [add_monoid N] [linear_order N] (f : M β N)
(h0 : f 0 β€ 0) (hadd : β x y, f (x + y) β€ max (f x) (f y)) (l : list M) :
f l.sum β€ (l.map f).foldr max 0 :=
begin
induction l with hd tl IH,
{ simpa using h0 },
simp only [list.sum_cons, list.foldr_map, list.foldr] at IH β’,
exact (hadd _ _).trans (max_le_max le_rfl IH)
end
@[simp, to_additive]
lemma prod_erase [decidable_eq M] [comm_monoid M] {a} :
β {l : list M}, a β l β a * (l.erase a).prod = l.prod
| (b :: l) h :=
begin
obtain rfl | β¨ne, hβ© := decidable.list.eq_or_ne_mem_of_mem h,
{ simp only [list.erase, if_pos, prod_cons] },
{ simp only [list.erase, if_neg (mt eq.symm ne), prod_cons, prod_erase h, mul_left_comm a b] }
end
@[simp, to_additive]
lemma prod_map_erase [decidable_eq ΞΉ] [comm_monoid M] (f : ΞΉ β M) {a} :
β {l : list ΞΉ}, a β l β f a * ((l.erase a).map f).prod = (l.map f).prod
| (b :: l) h :=
begin
obtain rfl | β¨ne, hβ© := decidable.list.eq_or_ne_mem_of_mem h,
{ simp only [map, erase_cons_head, prod_cons] },
{ simp only [map, erase_cons_tail _ ne.symm, prod_cons, prod_map_erase h,
mul_left_comm (f a) (f b)], }
end
lemma sum_const_nat (m n : β) : sum (replicate m n) = m * n :=
by rw [sum_replicate, smul_eq_mul]
/-- The product of a list of positive natural numbers is positive,
and likewise for any nontrivial ordered semiring. -/
lemma prod_pos [strict_ordered_semiring R] (l : list R) (h : β a β l, (0 : R) < a) : 0 < l.prod :=
begin
induction l with a l ih,
{ simp },
{ rw prod_cons,
exact mul_pos (h _ $ mem_cons_self _ _) (ih $ Ξ» a ha, h a $ mem_cons_of_mem _ ha) }
end
/-- A variant of `list.prod_pos` for `canonically_ordered_comm_semiring`. -/
@[simp]
lemma _root_.canonically_ordered_comm_semiring.list_prod_pos
{Ξ± : Type*} [canonically_ordered_comm_semiring Ξ±] [nontrivial Ξ±] :
Ξ {l : list Ξ±}, 0 < l.prod β (β x β l, (0 : Ξ±) < x)
| [] := β¨Ξ» h x hx, hx.elim, Ξ» _, zero_lt_oneβ©
| (x :: xs) := by simp_rw [prod_cons, mem_cons_iff, forall_eq_or_imp,
canonically_ordered_comm_semiring.mul_pos,
_root_.canonically_ordered_comm_semiring.list_prod_pos]
/-!
Several lemmas about sum/head/tail for `list β`.
These are hard to generalize well, as they rely on the fact that `default β = 0`.
If desired, we could add a class stating that `default = 0`.
-/
/-- This relies on `default β = 0`. -/
lemma head_add_tail_sum (L : list β) : L.head + L.tail.sum = L.sum :=
by { cases L, { simp, refl }, { simp } }
/-- This relies on `default β = 0`. -/
lemma head_le_sum (L : list β) : L.head β€ L.sum := nat.le.intro (head_add_tail_sum L)
/-- This relies on `default β = 0`. -/
lemma tail_sum (L : list β) : L.tail.sum = L.sum - L.head :=
by rw [β head_add_tail_sum L, add_comm, add_tsub_cancel_right]
section alternating
section
variables [has_one Ξ±] [has_mul Ξ±] [has_inv Ξ±]
@[simp, to_additive] lemma alternating_prod_nil : alternating_prod ([] : list Ξ±) = 1 := rfl
@[simp, to_additive] lemma alternating_prod_singleton (a : Ξ±) : alternating_prod [a] = a := rfl
@[to_additive] lemma alternating_prod_cons_cons' (a b : Ξ±) (l : list Ξ±) :
alternating_prod (a :: b :: l) = a * bβ»ΒΉ * alternating_prod l := rfl
end
@[to_additive] lemma alternating_prod_cons_cons [div_inv_monoid Ξ±] (a b : Ξ±) (l : list Ξ±) :
alternating_prod (a :: b :: l) = a / b * alternating_prod l :=
by rw [div_eq_mul_inv, alternating_prod_cons_cons']
variables [comm_group Ξ±]
@[to_additive] lemma alternating_prod_cons' :
β (a : Ξ±) (l : list Ξ±), alternating_prod (a :: l) = a * (alternating_prod l)β»ΒΉ
| a [] := by rw [alternating_prod_nil, inv_one, mul_one, alternating_prod_singleton]
| a (b :: l) :=
by rw [alternating_prod_cons_cons', alternating_prod_cons' b l, mul_inv, inv_inv, mul_assoc]
@[simp, to_additive] lemma alternating_prod_cons (a : Ξ±) (l : list Ξ±) :
alternating_prod (a :: l) = a / alternating_prod l :=
by rw [div_eq_mul_inv, alternating_prod_cons']
end alternating
lemma sum_nat_mod (l : list β) (n : β) : l.sum % n = (l.map (% n)).sum % n :=
by induction l; simp [nat.add_mod, *]
lemma prod_nat_mod (l : list β) (n : β) : l.prod % n = (l.map (% n)).prod % n :=
by induction l; simp [nat.mul_mod, *]
lemma sum_int_mod (l : list β€) (n : β€) : l.sum % n = (l.map (% n)).sum % n :=
by induction l; simp [int.add_mod, *]
lemma prod_int_mod (l : list β€) (n : β€) : l.prod % n = (l.map (% n)).prod % n :=
by induction l; simp [int.mul_mod, *]
end list
section monoid_hom
variables [monoid M] [monoid N]
@[to_additive]
lemma map_list_prod {F : Type*} [monoid_hom_class F M N] (f : F)
(l : list M) : f l.prod = (l.map f).prod :=
(l.prod_hom f).symm
namespace monoid_hom
/-- Deprecated, use `_root_.map_list_prod` instead. -/
@[to_additive "Deprecated, use `_root_.map_list_sum` instead."]
protected lemma map_list_prod (f : M β* N) (l : list M) :
f l.prod = (l.map f).prod :=
map_list_prod f l
end monoid_hom
end monoid_hom
|
18069cfcd13cc9588c38d825c335acad97008be8 | aa101d73b1a3173c7ec56de02b96baa8ca64c42e | /src/my_exercises/00_first_proofs.lean | cbadbcc71d9aca4908a9a44df4ba2929b225eb1b | [
"Apache-2.0"
] | permissive | gihanmarasingha/tutorials | b554d4d53866c493c4341dc13e914b01444e95a6 | 56617114ef0f9f7b808476faffd11e22e4380918 | refs/heads/master | 1,671,141,758,153 | 1,599,173,318,000 | 1,599,173,318,000 | 282,405,870 | 0 | 0 | Apache-2.0 | 1,595,666,751,000 | 1,595,666,750,000 | null | UTF-8 | Lean | false | false | 18,087 | lean | /-
This file is intended for Lean beginners. The goal is to demonstrate what it feels like to prove
things using Lean and mathlib. Complicated definitions and theory building are not covered.
Everything is covered again more slowly and with exercises in the next files.
-/
-- We want real numbers and their basic properties
import data.real.basic
-- We want to be able to use Lean's built-in "help" functionality
import tactic.suggest
-- We want to be able to define functions using the law of excluded middle
noncomputable theory
open_locale classical
/-
Our first goal is to define the set of upper bounds of a set of real numbers.
This is already defined in mathlib (in a more general context), but we repeat
it for the sake of exposition. Right-click "upper_bounds" below to get offered
to jump to mathlib's version
-/
#check upper_bounds
/-- The set of upper bounds of a set of real numbers β -/
def up_bounds (A : set β) := { x : β | β a β A, a β€ x}
/-- Predicate `is_max a A` means `a` is a maximum of `A` -/
def is_max (a : β) (A : set β) := a β A β§ a β up_bounds A
/-
In the above definition, the symbol `β§` means "and". We also see the most
visible difference between set theoretic foundations and type theoretic ones
(used by almost all proof assistants). In set theory, everything is a set, and the
only relation you get from foundations are `=` and `β`. In type theory, there is
a meta-theoretic relation of "typing": `a : β` reads "`a` is a real number" or,
more precisely, "the type of `a` is `β`". Here "meta-theoretic" means this is not a
statement you can prove or disprove inside the theory, it's a fact that is true or
not. Here we impose this fact, in other circumstances, it would be checked by the
Lean kernel.
By contrast, `a β A` is a statement inside the theory. Here it's part of the
definition, in other circumstances it could be something proven inside Lean.
-/
/- For illustrative purposes, we now define an infix version of the above predicate.
It will allow us to write `a is_a_max_of A`, which is closer to a sentence.
-/
infix ` is_a_max_of `:55 := is_max
/-
Let's prove something now! A set of real numbers has at most one maximum. Here
everything left of the final `:` is introducing the objects and assumption. The equality
`x = y` right of the colon is the conclusion.
-/
lemma unique_max (A : set β) (x y : β) (hx : x is_a_max_of A) (hy : y is_a_max_of A) : x = y :=
begin
-- We first break our assumptions in their two constituent pieces.
-- We are free to choose the name following `with`
cases hx with x_in x_up,
cases hy with y_in y_up,
-- Assumption `x_up` means x isn't less than elements of A, let's apply this to y
specialize x_up y,
-- Assumption `x_up` now needs the information that `y` is indeed in `A`.
specialize x_up y_in,
-- Let's do this quicker with roles swapped
specialize y_up x x_in,
-- We explained to Lean the idea of this proof.
-- Now we know `x β€ y` and `y β€ x`, and Lean shouldn't need more help.
-- `linarith` proves equalities and inequalities that follow linearly from
-- the assumption we have.
linarith,
end
/-
The above proof is too long, even if you remove comments. We don't really need the
unpacking steps at the beginning; we can access both parts of the assumption
`hx : x is_a_max_of A` using shortcuts `h.1` and `h.2`. We can also improve
readability without assistance from the tactic state display, clearly announcing
intermediate goals using `have`. This way we get to the following version of the
same proof.
-/
example (A : set β) (x y : β) (hx : x is_a_max_of A) (hy : y is_a_max_of A) : x = y :=
begin
have : x β€ y, from hy.2 x hx.1,
have : y β€ x, from hx.2 y hy.1,
linarith,
end
/-
Notice how mathematics based on type theory treats the assumption
`β a β A, a β€ y` as a function turning an element `a` of `A` into the statement
`a β€ y`. More precisely, this assumption is the abbreviation of
`β a : β, a β A β a β€ y`. The expression `hy.2 x` appearing in the above proof
is then the statement `x β A β x β€ y`, which itself is a function turning a
statement `x β A` into `x β€ y` so that the full expression `hy.2 x hx.1` is
indeed a proof of `x β€ y`.
One could argue a three-line-long proof of this lemma is still two lines too long.
This is debatable, but mathlib's style is to write very short proofs for trivial
lemmas. Those proofs are not easy to read but they are meant to indicate that the
proof is probably not worth reading.
In order to reach this stage, we need to know what `linarith` did for us. It invoked
the lemma `le_antisymm` which says: `x β€ y β y β€ x β x = y`. This arrow, which
is used both for function and implication, is right associative. So the statement is
`x β€ y β (y β€ x β x = y)` which reads: I will send a proof `p` of `x β€ y` to a function
sending a proof `q'` of `y β€ x` to a proof of `x = y`. Hence `le_antisymm p q'` is a
proof of `x = y`.
Using this we can get our one-line proof:
-/
example (A : set β) (x y : β) (hx : x is_a_max_of A) (hy : y is_a_max_of A) : x = y :=
le_antisymm (hy.2 x hx.1) (hx.2 y hy.1)
/-
Such a proof is called a proof term (or a "term mode" proof). Notice it has no `begin`
and `end`. It is directly the kind of low level proof that the Lean kernel is
consuming. Commands like `cases`, `specialize` or `linarith` are called tactics, they
help users constructing proof terms that could be very tedious to write directly.
The most efficient proof style combines tactics with proof terms like our previous
`have : x β€ y, from hy.2 x hx.1` where `hy.2 x hx.1` is a proof term embeded inside
a tactic mode proof.
In the remaining of this file, we'll be characterizing infima of sets of real numbers
in term of sequences.
-/
/-- The set of lower bounds of a set of real numbers β -/
def low_bounds (A : set β) := { x : β | β a β A, x β€ a}
/-
We now define `a` is an infimum of `A`. Again there is already a more general version
in mathlib.
-/
def is_inf (x : β) (A : set β) := x is_a_max_of (low_bounds A)
infix ` is_an_inf_of `:55 := is_inf
/-
We need to prove that any number which is greater than the infimum of A is greater
than some element of A.
-/
lemma inf_lt {A : set β} {x : β} (hx : x is_an_inf_of A) :
β y, x < y β β a β A, a < y :=
begin
-- Let `y` be any real number.
intro y,
-- Let's prove the contrapositive
contrapose,
-- The symbol `Β¬` means negation. Let's ask Lean to rewrite the goal without negation,
-- pushing negation through quantifiers and inequalities
push_neg,
-- Let's assume the premise, calling the assumption `h`
intro h,
-- `h` is exactly saying `y` is a lower bound of `A` so the second part of
-- the infimum assumption `hx` applied to `y` and `h` is exactly what we want.
exact hx.2 y h
end
/-
In the above proof, the sequence `contrapose, push_neg` is so common that it can be
abbreviated to `contrapose!`. With these commands, we enter the gray zone between
proof checking and proof finding. Practical computer proof checking crucially needs
the computer to handle tedious proof steps. In the next proof, we'll start using
`linarith` a bit more seriously, going one step further into automation.
Our next real goal is to prove inequalities for limits of sequences. We extract the
following lemma: if `y β€ x + Ξ΅` for all positive `Ξ΅` then `y β€ x`.
-/
lemma le_of_le_add_eps {x y : β} : (β Ξ΅ > 0, y β€ x + Ξ΅) β y β€ x :=
begin
-- Let's prove the contrapositive, asking Lean to push negations right away.
contrapose!,
-- Assume `h : x < y`.
intro h,
-- We need to find `Ξ΅` such that `Ξ΅` is positive and `x + Ξ΅ < y`.
-- Let's use `(y-x)/2`
use ((y-x)/2),
-- we now have two properties to prove. Let's do both in turn, using `linarith`
split,
linarith,
linarith,
end
/-
Note how `linarith` was used for both sub-goals at the end of the above proof.
We could have shortened that using the semi-colon combinator instead of comma,
writing `split ; linarith`.
Next we will study a compressed version of that proof:
-/
example {x y : β} : (β Ξ΅ > 0, y β€ x + Ξ΅) β y β€ x :=
begin
contrapose!,
exact assume h, β¨(y-x)/2, by linarith, by linarithβ©,
end
/-
The angle brackets `β¨` and `β©` introduce compound data or proofs. A proof
of a `β z, P z` statemement is composed of a witness `zβ` and a proof `h` of
`P zβ`. The compound is denoted by `β¨zβ, hβ©`. In the example above, the predicate is
itself compound, it is a conjunction `P z β§ Q z`. So the proof term should read
`β¨zβ, β¨hβ, hββ©β©` where `hβ` (resp. `hβ`) is a proof of `P zβ` (resp. `Q zβ`).
But these so-called "anonymous constructor" brackets are right-associative, so we can
get rid of the nested brackets.
The keyword `by` introduces tactic mode inside term mode, it is a shorter version
of the `begin`/`end` pair, which is more convenient for single tactic blocks.
In this example, `begin` enters tactic mode, `exact` leaves it, `by` re-enters it.
Going all the way to a proof term would make the proof much longer, because we
crucially use automation with `contrapose!` and `linarith`. We can still get a one-line
proof using curly braces to gather several tactic invocations, and the `by` abbreviation
instead of `begin`/`end`:
-/
example {x y : β} : (β Ξ΅ > 0, y β€ x + Ξ΅) β y β€ x :=
by { contrapose!, exact assume h, β¨(y-x)/2, by linarith, by linarithβ© }
/-
One could argue that the above proof is a bit too terse, and we are relying too much
on linarith. Let's have more `linarith` calls for smaller steps. For the sake
of (tiny) variation, we will also assume the premise and argue by contradiction
instead of contraposing.
-/
example {x y : β} : (β Ξ΅ > 0, y β€ x + Ξ΅) β y β€ x :=
begin
intro h,
-- Assume the conclusion is false, and call this assumption H.
by_contradiction H,
push_neg at H,
-- Now let's compute.
have key := calc
-- Each line must end with a colon followed by a proof term
-- We want to specialize our assumption `h` to `Ξ΅ = (y-x)/2` but this is long to
-- type, so let's put a hole `_` that Lean will fill in by comparing the
-- statement we want to prove and our proof term with a hole. As usual,
-- positivity of `(y-x)/2` is proved by `linarith`
y β€ x + (y-x)/2 : h _ (by linarith)
... = x/2 + y/2 : by ring
... < y : by linarith,
-- our key now says `y < y` (notice how the sequence `β€`, `=`, `<` was correctly
-- merged into a `<`). Let `linarith` find the desired contradiction now.
linarith,
-- alternatively, we could have provided the proof term
-- `exact lt_irrefl y key`
end
/-
Now we are ready for some analysis. Let's set up notation for absolute value
-/
local notation `|`x`|` := abs x
/-
And let's define convergence of sequences of real numbers (of course there is
a much more general definition in mathlib).
-/
/-- The sequence `u` tends to `l` -/
def limit (u : β β β) (l : β) := β Ξ΅ > 0, β N, β n β₯ N, |u n - l| β€ Ξ΅
/-
In the above definition, `u n` denotes the n-th term of the sequence. We can
add parentheses to get `u(n)` but we try to avoid parentheses because they pile up
very quickly
-/
-- If y β€ u n for all n and u n goes to x then y β€ x
lemma le_lim {x y : β} {u : β β β} (hu : limit u x) (ineq : β n, y β€ u n) : y β€ x :=
begin
-- Let's apply our previous lemma
apply le_of_le_add_eps,
-- We need to prove y β€ x + Ξ΅ for all positive Ξ΅.
-- Let Ξ΅ be any positive real
intros Ξ΅ Ξ΅_pos,
-- we now specialize our limit assumption to this `Ξ΅`, and immediately
-- fix a `N` as promised by the definition.
cases hu Ξ΅ Ξ΅_pos with N HN,
-- Now we only need to compute until reaching the conclusion
calc
y β€ u N : ineq N
... = x + (u N - x) : by linarith
-- We'll need `add_le_add` which says `a β€ b` and `c β€ d` implies `a + c β€ b + d`
-- We need a lemma saying `z β€ |z|`. Because we don't know the name of this lemma,
-- let's use `library_search`. Because searching thourgh the library is slow,
-- Lean will write what it found in the Lean message window when cursor is on
-- that line, so that we can replace it by the lemma. We see `le_max_left` which
-- says `a β€ max a b`. Actually there is a more specific lemma `le_abs_self`
... β€ x + |u N - x| : add_le_add (by linarith) (by library_search)
... β€ x + Ξ΅ : add_le_add (by linarith) (HN N (by linarith)),
end
/-
The next lemma has been extracted from the main proof in order to discuss numbers.
In ordinary maths, we know that β is *not* contained in `β`, whatever the
construction of real numbers that we use. For instance a natural number is not
an equivalence class of Cauchy sequences. But it's very easy to
pretend otherwise. Formal maths requires slightly more care. In the statement below,
the "type ascription" `(n + 1 : β)` forces Lean to convert the natural number
`n+1` into a real number. The "inclusion" map will be displayed in tactic state
as `β`. There are various lemmas asserting this map is compatible with addition and
monotone, but we don't want to bother writing their names. The `norm_cast`
tactic is designed to wisely apply those lemmas for us.
-/
lemma inv_succ_pos : β n : β, 1/(n+1 : β) > 0 :=
begin
-- Let `n` be any integer
intro n,
-- Since we don't know the name of the relevant lemma, asserting that the inverse of
-- a positive number is positive, let's state that is suffices
-- to prove that `n+1`, seen as a real number, is positive, and ask `library_search`
suffices : (n + 1 : β) > 0,
{ library_search },
-- Now we want to reduce to a statement about natural numbers, not real numbers
-- coming from natural numbers.
norm_cast,
-- and then get the usual help from `linarith`
linarith,
end
/-
That was a pretty long proof for an obvious fact. And stating it as a lemma feels
stupid, so let's find a way to write it on one line in case we want to include it
in some other proof without stating a lemma. First the `library_search` call
above displays the name of the relevant lemma: `one_div_pos_of_pos`. We can also
replace the `linarith` call on the last line by `library_search` to learn the name
of the lemma `nat.succ_pos` asserting that the successor of a natural number is
positive. There is also a variant on `norm_cast` that combines it with `exact`.
The term mode analogue of `intro` is `Ξ»`. We get down to:
-/
example : β n : β, 1/(n+1 : β) > 0 :=
Ξ» n, one_div_pos_of_pos (by exact_mod_cast nat.succ_pos n)
/-
The next proof uses mostly known things, so we will commment only new aspects.
-/
lemma limit_inv_succ : β Ξ΅ > 0, β N : β, β n β₯ N, 1/(n + 1 : β) β€ Ξ΅ :=
begin
intros Ξ΅ Ξ΅_pos,
suffices : β N : β, 1/Ξ΅ β€ N,
{ -- Because we didn't provide a name for the above statement, Lean called it `this`.
-- Let's fix an `N` that works.
cases this with N HN,
use N,
intros n Hn,
-- Now we want to rewrite the goal using lemmas
-- `div_le_iff' : 0 < b β (a / b β€ c β a β€ b * c)`
-- `div_le_iff : 0 < b β (a / b β€ c β a β€ c * b)`
-- the second one will be rewritten from right to left, as indicated by `β`.
-- Lean will create a side goal for the required positivity assumption that
-- we don't provide for `div_le_iff'`.
rw [div_le_iff', β div_le_iff Ξ΅_pos],
-- We want to replace assumption `Hn` by its real counter-part so that
-- linarith can find what it needs.
replace Hn : (N : β) β€ n, exact_mod_cast Hn,
linarith,
-- we are still left with the positivity assumption, but already discussed
-- how to prove it in the preceding lemma
exact_mod_cast nat.succ_pos n },
-- Now we need to prove that sufficient statement.
-- We want to use that `β` is archimedean. So we start typing
-- `exact archimedean_` and hit Ctrl-space to see what completion Lean proposes
-- the lemma `archimedean_iff_nat_le` sounds promising. We select the left to
-- right implication using `.1`. This a generic lemma for fields equiped with
-- a linear (ie total) order. We need to provide a proof that `β` is indeed
-- archimedean. This is done using the `apply_instance` tactic that will be
-- covered elsewhere.
exact archimedean_iff_nat_le.1 (by apply_instance) (1/Ξ΅),
end
/-
We can now put all pieces together, with almost no new things to explain.
-/
lemma inf_seq (A : set β) (x : β) :
(x is_an_inf_of A) β (x β low_bounds A β§ β u : β β β, limit u x β§ β n, u n β A ) :=
begin
split,
{ intro h,
split,
{ exact h.1 },
-- On the next line, we don't need to tell Lean to treat `n+1` as a real number because
-- we add `x` to it, so Lean knows there is only one way to make sense of this expression.
have key : β n : β, β a β A, a < x + 1/(n+1),
{ intro n,
-- we can use the lemma we proved above
apply inf_lt h,
-- and another one we proved!
have : 0 < 1/(n+1 : β), from inv_succ_pos n,
linarith },
-- Now we need to use axiom of (countable) choice
choose u hu using key,
use u,
split,
{ intros Ξ΅ Ξ΅_pos,
-- again we use a lemma we proved, specializing it to our fixed `Ξ΅`, and fixing a `N`
cases limit_inv_succ Ξ΅ Ξ΅_pos with N H,
use N,
intros n hn,
have : x β€ u n, from h.1 _ (hu n).1,
have := calc
u n < x + 1/(n + 1) : (hu n).2
... β€ x + Ξ΅ : add_le_add (le_refl x) (H n hn),
rw abs_of_nonneg ; linarith },
{ intro n,
exact (hu n).1 } },
{ intro h,
-- Assumption `h` is made of nested compound statements. We can use the
-- recursive version of `cases` to unpack it in one go.
rcases h with β¨x_min, u, lim, huAβ©,
split,
exact x_min,
intros y y_mino,
apply le_lim lim,
intro n,
exact y_mino (u n) (huA n) },
end
|
101bb9c5f19d2f5b030d5bb8e083275663699e84 | 0b3933727d99a2f351f5dbe6e24716bb786a6649 | /src/qtt/matrix.lean | be38bb091d4fc569f7e9f3b72085e216f2ecba6f | [] | no_license | Vtec234/lean-sesh | 1e770858215279f65aba92b4782b483ab4f09353 | d11d7bb0599406e27d3a4d26242aec13d639ecf7 | refs/heads/master | 1,587,497,515,696 | 1,558,362,223,000 | 1,558,362,223,000 | 169,809,439 | 2 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 3,148 | lean | /- Introduces matrices and horrifying linear algebra. -/
import qtt.context
open context
open debrujin_idx
/- This matrix defines the context in which every variable (given by a debrujin idx)
exists. In other words, it defines a substitution. Variables all exist in the same
precontext, but the type multiplicities might differ. -/
def matrix (Ο mult: Type) (Ξ³ Ξ΄: precontext Ο)
: Type := Ξ (T: Ο), Ξ³ β T β @context Ο mult Ξ΄
namespace matrix
variable {Ο: Type}
variables {mult: Type} [semiring mult]
def identity: Ξ Ξ³, @matrix Ο mult Ξ³ Ξ³
| (T::Ξ΄) _ ZVar := β¦1β¬Tβ§::0
| (T::Ξ΄) U (SVar x) := β¦0β¬Tβ§::(identity Ξ΄ U x)
@[unfold_] lemma identity_zvar {T: Ο} {Ξ³: precontext Ο}
: identity (T::Ξ³) T ZVar = β¦(1: mult)β¬Tβ§::(0: context Ξ³) := by refl
@[unfold_] lemma identity_svar {T U: Ο} {Ξ΄: precontext Ο} {x}
: identity (T::Ξ΄) U (SVar x) = β¦(0: mult)β¬Tβ§::(identity Ξ΄ U x) := by refl
def vmul: β {Ξ³ Ξ΄}, @context Ο mult Ξ³ β @matrix Ο mult Ξ³ Ξ΄ β @context Ο mult Ξ΄
| _ Ξ΄ context.nil _ := 0
| _ _ (β¦Οβ¬Tβ§::Ξ) Ξ := (Ο β’ Ξ T ZVar) + (vmul Ξ (Ξ» U x, Ξ U (SVar x)))
infix ` β `:70 := vmul
namespace vmul
@[simp] lemma vmul_nil {Ξ΄} {Ξ: @matrix Ο mult [] Ξ΄}
: context.nil β Ξ = 0 := by refl
@[unfold_] lemma vmul_cons {Ξ³ Ξ΄} {T: Ο} {Ξ: context Ξ³} {Ο: mult} {Ξ: @matrix Ο mult (T::Ξ³) Ξ΄}
: β¦Οβ¬Tβ§::Ξ β Ξ = (Ο β’ Ξ T ZVar) + (Ξ β (Ξ» U x, Ξ U (SVar x))) :=
by refl
@[simp] lemma zero_vmul
: β {Ξ³ Ξ΄: precontext Ο} (M: @matrix Ο mult Ξ³ Ξ΄),
0 β M = 0 :=
begin
intros,
induction Ξ³ with T Ξ³ ih,
{ refl },
{ unfold has_zero.zero zeros,
simp * with unfold_,
show (0: mult) β’ M T ZVar + 0 β (Ξ» (U: Ο) (x: Ξ³ β U), M U (SVar x)) = 0,
simp * },
end
@[simp] lemma vmul_ext_zero
: β {Ξ³ Ξ΄} {Ξ: context Ξ³} {Ξ: @matrix Ο mult Ξ³ Ξ΄} {T: Ο},
Ξ β (Ξ» U x, β¦0β¬Tβ§::(Ξ U x)) = β¦0β¬Tβ§::(Ξ β Ξ) :=
begin
intros,
induction Ξ with Ξ³' Ο T' Ξ ih,
{ refl },
{ simp * with unfold_ },
end
@[simp] lemma one_vmul
: β {Ξ³ Ξ΄} {Ξ: @matrix Ο mult Ξ³ Ξ΄} {T: Ο}
(x: Ξ³ β T),
-------------------------------
(identity Ξ³ T x) β Ξ = Ξ T x :=
begin
intros,
induction x with Ξ³' T' Ξ΄' T'' U x' ih;
{ simp * with unfold_ },
end
@[simp] lemma vmul_one
: β {Ξ³} (Ξ: @context Ο mult Ξ³),
Ξ β (identity Ξ³) = Ξ :=
begin
intros,
induction Ξ with Ξ³ Ο T Ξ ih,
{ refl },
{ simp [*, vmul_ext_zero] with unfold_ },
end
lemma smul_vmul
: β {Ξ³ Ξ΄} {Ξ: @context Ο mult Ξ³} {Ξ: @matrix Ο mult Ξ³ Ξ΄} {Ο: mult},
(Ο β’ Ξ) β Ξ = Ο β’ (Ξ β Ξ) :=
begin
intros,
induction Ξ with Ξ³' Ο' T Ξ ih;
{ simp [*, context.mul_smul]
with unfold_ sop_form },
end
@[sop_form] lemma vmul_right_distrib
: β {Ξ³ Ξ΄} {Ξβ Ξβ: @context Ο mult Ξ³} {Ξ: @matrix Ο mult Ξ³ Ξ΄},
(Ξβ + Ξβ) β Ξ = (Ξβ β Ξ) + (Ξβ β Ξ) :=
begin
intros,
induction Ξβ with Ξ³β Οβ Tβ Ξβ ihβ;
{ cases Ξβ,
simp * with unfold_ sop_form },
end
end vmul
end matrix
|
7529dce934f4ef2ce705d75d77760b3087a93ff8 | 77c5b91fae1b966ddd1db969ba37b6f0e4901e88 | /src/data/nat/prime.lean | a4fafc88cc00af4ec8058cc2cfb2df132abe94b4 | [
"Apache-2.0"
] | permissive | dexmagic/mathlib | ff48eefc56e2412429b31d4fddd41a976eb287ce | 7a5d15a955a92a90e1d398b2281916b9c41270b2 | refs/heads/master | 1,693,481,322,046 | 1,633,360,193,000 | 1,633,360,193,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 38,061 | lean | /-
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura, Jeremy Avigad, Mario Carneiro
-/
import algebra.group_power
import data.list.sort
import data.nat.gcd
import data.nat.sqrt
import tactic.norm_num
import tactic.wlog
/-!
# Prime numbers
This file deals with prime numbers: natural numbers `p β₯ 2` whose only divisors are `p` and `1`.
## Important declarations
All the following declarations exist in the namespace `nat`.
- `prime`: the predicate that expresses that a natural number `p` is prime
- `primes`: the subtype of natural numbers that are prime
- `min_fac n`: the minimal prime factor of a natural number `n β 1`
- `exists_infinite_primes`: Euclid's theorem that there exist infinitely many prime numbers
- `factors n`: the prime factorization of `n`
- `factors_unique`: uniqueness of the prime factorisation
-/
open bool subtype
open_locale nat
namespace nat
/-- `prime p` means that `p` is a prime number, that is, a natural number
at least 2 whose only divisors are `p` and `1`. -/
@[pp_nodot]
def prime (p : β) := 2 β€ p β§ β m β£ p, m = 1 β¨ m = p
theorem prime.two_le {p : β} : prime p β 2 β€ p := and.left
theorem prime.one_lt {p : β} : prime p β 1 < p := prime.two_le
instance prime.one_lt' (p : β) [hp : _root_.fact p.prime] : _root_.fact (1 < p) := β¨hp.1.one_ltβ©
lemma prime.ne_one {p : β} (hp : p.prime) : p β 1 :=
ne.symm $ ne_of_lt hp.one_lt
theorem prime_def_lt {p : β} : prime p β 2 β€ p β§ β m < p, m β£ p β m = 1 :=
and_congr_right $ Ξ» p2, forall_congr $ Ξ» m,
β¨Ξ» h l d, (h d).resolve_right (ne_of_lt l),
Ξ» h d, (le_of_dvd (le_of_succ_le p2) d).lt_or_eq_dec.imp_left (Ξ» l, h l d)β©
theorem prime_def_lt' {p : β} : prime p β 2 β€ p β§ β m, 2 β€ m β m < p β Β¬ m β£ p :=
prime_def_lt.trans $ and_congr_right $ Ξ» p2, forall_congr $ Ξ» m,
β¨Ξ» h m2 l d, not_lt_of_ge m2 ((h l d).symm βΈ dec_trivial),
Ξ» h l d, begin
rcases m with _|_|m,
{ rw eq_zero_of_zero_dvd d at p2, revert p2, exact dec_trivial },
{ refl },
{ exact (h dec_trivial l).elim d }
endβ©
theorem prime_def_le_sqrt {p : β} : prime p β 2 β€ p β§
β m, 2 β€ m β m β€ sqrt p β Β¬ m β£ p :=
prime_def_lt'.trans $ and_congr_right $ Ξ» p2,
β¨Ξ» a m m2 l, a m m2 $ lt_of_le_of_lt l $ sqrt_lt_self p2,
Ξ» a, have β {m k}, m β€ k β 1 < m β p β m * k, from
Ξ» m k mk m1 e, a m m1
(le_sqrt.2 (e.symm βΈ nat.mul_le_mul_left m mk)) β¨k, eβ©,
Ξ» m m2 l β¨k, eβ©, begin
cases (le_total m k) with mk km,
{ exact this mk m2 e },
{ rw [mul_comm] at e,
refine this km (lt_of_mul_lt_mul_right _ (zero_le m)) e,
rwa [one_mul, β e] }
endβ©
theorem prime_of_coprime (n : β) (h1 : 1 < n) (h : β m < n, m β 0 β n.coprime m) : prime n :=
begin
refine prime_def_lt.mpr β¨h1, Ξ» m mlt mdvd, _β©,
have hm : m β 0,
{ rintro rfl,
rw zero_dvd_iff at mdvd,
exact mlt.ne' mdvd },
exact (h m mlt hm).symm.eq_one_of_dvd mdvd,
end
section
/--
This instance is slower than the instance `decidable_prime` defined below,
but has the advantage that it works in the kernel for small values.
If you need to prove that a particular number is prime, in any case
you should not use `dec_trivial`, but rather `by norm_num`, which is
much faster.
-/
local attribute [instance]
def decidable_prime_1 (p : β) : decidable (prime p) :=
decidable_of_iff' _ prime_def_lt'
lemma prime.ne_zero {n : β} (h : prime n) : n β 0 :=
by { rintro rfl, revert h, dec_trivial }
theorem prime.pos {p : β} (pp : prime p) : 0 < p :=
lt_of_succ_lt pp.one_lt
theorem not_prime_zero : Β¬ prime 0 := by simp [prime]
theorem not_prime_one : Β¬ prime 1 := by simp [prime]
theorem prime_two : prime 2 := dec_trivial
end
theorem prime.pred_pos {p : β} (pp : prime p) : 0 < pred p :=
lt_pred_iff.2 pp.one_lt
theorem succ_pred_prime {p : β} (pp : prime p) : succ (pred p) = p :=
succ_pred_eq_of_pos pp.pos
theorem dvd_prime {p m : β} (pp : prime p) : m β£ p β m = 1 β¨ m = p :=
β¨Ξ» d, pp.2 m d, Ξ» h, h.elim (Ξ» e, e.symm βΈ one_dvd _) (Ξ» e, e.symm βΈ dvd_rfl)β©
theorem dvd_prime_two_le {p m : β} (pp : prime p) (H : 2 β€ m) : m β£ p β m = p :=
(dvd_prime pp).trans $ or_iff_right_of_imp $ not.elim $ ne_of_gt H
theorem prime_dvd_prime_iff_eq {p q : β} (pp : p.prime) (qp : q.prime) : p β£ q β p = q :=
dvd_prime_two_le qp (prime.two_le pp)
theorem prime.not_dvd_one {p : β} (pp : prime p) : Β¬ p β£ 1
| d := (not_le_of_gt pp.one_lt) $ le_of_dvd dec_trivial d
theorem not_prime_mul {a b : β} (a1 : 1 < a) (b1 : 1 < b) : Β¬ prime (a * b) :=
Ξ» h, ne_of_lt (nat.mul_lt_mul_of_pos_left b1 (lt_of_succ_lt a1)) $
by simpa using (dvd_prime_two_le h a1).1 (dvd_mul_right _ _)
lemma not_prime_mul' {a b n : β} (h : a * b = n) (hβ : 1 < a) (hβ : 1 < b) : Β¬ prime n :=
by { rw β h, exact not_prime_mul hβ hβ }
section min_fac
private lemma min_fac_lemma (n k : β) (h : Β¬ n < k * k) :
sqrt n - k < sqrt n + 2 - k :=
(nat.sub_lt_sub_right_iff $ le_sqrt.2 $ le_of_not_gt h).2 $
nat.lt_add_of_pos_right dec_trivial
/-- If `n < k * k`, then `min_fac_aux n k = n`, if `k | n`, then `min_fac_aux n k = k`.
Otherwise, `min_fac_aux n k = min_fac_aux n (k+2)` using well-founded recursion.
If `n` is odd and `1 < n`, then then `min_fac_aux n 3` is the smallest prime factor of `n`. -/
def min_fac_aux (n : β) : β β β | k :=
if h : n < k * k then n else
if k β£ n then k else
have _, from min_fac_lemma n k h,
min_fac_aux (k + 2)
using_well_founded {rel_tac :=
Ξ» _ _, `[exact β¨_, measure_wf (Ξ» k, sqrt n + 2 - k)β©]}
/-- Returns the smallest prime factor of `n β 1`. -/
def min_fac : β β β
| 0 := 2
| 1 := 1
| (n+2) := if 2 β£ n then 2 else min_fac_aux (n + 2) 3
@[simp] theorem min_fac_zero : min_fac 0 = 2 := rfl
@[simp] theorem min_fac_one : min_fac 1 = 1 := rfl
theorem min_fac_eq : β n, min_fac n = if 2 β£ n then 2 else min_fac_aux n 3
| 0 := by simp
| 1 := by simp [show 2β 1, from dec_trivial]; rw min_fac_aux; refl
| (n+2) :=
have 2 β£ n + 2 β 2 β£ n, from
(nat.dvd_add_iff_left (by refl)).symm,
by simp [min_fac, this]; congr
private def min_fac_prop (n k : β) :=
2 β€ k β§ k β£ n β§ β m, 2 β€ m β m β£ n β k β€ m
theorem min_fac_aux_has_prop {n : β} (n2 : 2 β€ n) (nd2 : Β¬ 2 β£ n) :
β k i, k = 2*i+3 β (β m, 2 β€ m β m β£ n β k β€ m) β min_fac_prop n (min_fac_aux n k)
| k := Ξ» i e a, begin
rw min_fac_aux,
by_cases h : n < k*k; simp [h],
{ have pp : prime n :=
prime_def_le_sqrt.2 β¨n2, Ξ» m m2 l d,
not_lt_of_ge l $ lt_of_lt_of_le (sqrt_lt.2 h) (a m m2 d)β©,
from β¨n2, dvd_rfl, Ξ» m m2 d, le_of_eq
((dvd_prime_two_le pp m2).1 d).symmβ© },
have k2 : 2 β€ k, { subst e, exact dec_trivial },
by_cases dk : k β£ n; simp [dk],
{ exact β¨k2, dk, aβ© },
{ refine have _, from min_fac_lemma n k h,
min_fac_aux_has_prop (k+2) (i+1)
(by simp [e, left_distrib]) (Ξ» m m2 d, _),
cases nat.eq_or_lt_of_le (a m m2 d) with me ml,
{ subst me, contradiction },
apply (nat.eq_or_lt_of_le ml).resolve_left, intro me,
rw [β me, e] at d, change 2 * (i + 2) β£ n at d,
have := dvd_of_mul_right_dvd d, contradiction }
end
using_well_founded {rel_tac :=
Ξ» _ _, `[exact β¨_, measure_wf (Ξ» k, sqrt n + 2 - k)β©]}
theorem min_fac_has_prop {n : β} (n1 : n β 1) :
min_fac_prop n (min_fac n) :=
begin
by_cases n0 : n = 0, {simp [n0, min_fac_prop, ge]},
have n2 : 2 β€ n, { revert n0 n1, rcases n with _|_|_; exact dec_trivial },
simp [min_fac_eq],
by_cases d2 : 2 β£ n; simp [d2],
{ exact β¨le_refl _, d2, Ξ» k k2 d, k2β© },
{ refine min_fac_aux_has_prop n2 d2 3 0 rfl
(Ξ» m m2 d, (nat.eq_or_lt_of_le m2).resolve_left (mt _ d2)),
exact Ξ» e, e.symm βΈ d }
end
theorem min_fac_dvd (n : β) : min_fac n β£ n :=
if n1 : n = 1 then by simp [n1] else (min_fac_has_prop n1).2.1
theorem min_fac_prime {n : β} (n1 : n β 1) : prime (min_fac n) :=
let β¨f2, fd, aβ© := min_fac_has_prop n1 in
prime_def_lt'.2 β¨f2, Ξ» m m2 l d, not_le_of_gt l (a m m2 (d.trans fd))β©
theorem min_fac_le_of_dvd {n : β} : β {m : β}, 2 β€ m β m β£ n β min_fac n β€ m :=
by by_cases n1 : n = 1;
[exact Ξ» m m2 d, n1.symm βΈ le_trans dec_trivial m2,
exact (min_fac_has_prop n1).2.2]
theorem min_fac_pos (n : β) : 0 < min_fac n :=
by by_cases n1 : n = 1;
[exact n1.symm βΈ dec_trivial, exact (min_fac_prime n1).pos]
theorem min_fac_le {n : β} (H : 0 < n) : min_fac n β€ n :=
le_of_dvd H (min_fac_dvd n)
theorem le_min_fac {m n : β} : n = 1 β¨ m β€ min_fac n β β p, prime p β p β£ n β m β€ p :=
β¨Ξ» h p pp d, h.elim
(by rintro rfl; cases pp.not_dvd_one d)
(Ξ» h, le_trans h $ min_fac_le_of_dvd pp.two_le d),
Ξ» H, or_iff_not_imp_left.2 $ Ξ» n1, H _ (min_fac_prime n1) (min_fac_dvd _)β©
theorem le_min_fac' {m n : β} : n = 1 β¨ m β€ min_fac n β β p, 2 β€ p β p β£ n β m β€ p :=
β¨Ξ» h p (pp:1<p) d, h.elim
(by rintro rfl; cases not_le_of_lt pp (le_of_dvd dec_trivial d))
(Ξ» h, le_trans h $ min_fac_le_of_dvd pp d),
Ξ» H, le_min_fac.2 (Ξ» p pp d, H p pp.two_le d)β©
theorem prime_def_min_fac {p : β} : prime p β 2 β€ p β§ min_fac p = p :=
β¨Ξ» pp, β¨pp.two_le,
let β¨f2, fd, aβ© := min_fac_has_prop $ ne_of_gt pp.one_lt in
((dvd_prime pp).1 fd).resolve_left (ne_of_gt f2)β©,
Ξ» β¨p2, eβ©, e βΈ min_fac_prime (ne_of_gt p2)β©
/--
This instance is faster in the virtual machine than `decidable_prime_1`,
but slower in the kernel.
If you need to prove that a particular number is prime, in any case
you should not use `dec_trivial`, but rather `by norm_num`, which is
much faster.
-/
instance decidable_prime (p : β) : decidable (prime p) :=
decidable_of_iff' _ prime_def_min_fac
theorem not_prime_iff_min_fac_lt {n : β} (n2 : 2 β€ n) : Β¬ prime n β min_fac n < n :=
(not_congr $ prime_def_min_fac.trans $ and_iff_right n2).trans $
(lt_iff_le_and_ne.trans $ and_iff_right $ min_fac_le $ le_of_succ_le n2).symm
lemma min_fac_le_div {n : β} (pos : 0 < n) (np : Β¬ prime n) : min_fac n β€ n / min_fac n :=
match min_fac_dvd n with
| β¨0, h0β© := absurd pos $ by rw [h0, mul_zero]; exact dec_trivial
| β¨1, h1β© :=
begin
rw mul_one at h1,
rw [prime_def_min_fac, not_and_distrib, β h1, eq_self_iff_true, not_true, or_false,
not_le] at np,
rw [le_antisymm (le_of_lt_succ np) (succ_le_of_lt pos), min_fac_one, nat.div_one]
end
| β¨(x+2), hxβ© :=
begin
conv_rhs { congr, rw hx },
rw [nat.mul_div_cancel_left _ (min_fac_pos _)],
exact min_fac_le_of_dvd dec_trivial β¨min_fac n, by rwa mul_commβ©
end
end
/--
The square of the smallest prime factor of a composite number `n` is at most `n`.
-/
lemma min_fac_sq_le_self {n : β} (w : 0 < n) (h : Β¬ prime n) : (min_fac n)^2 β€ n :=
have t : (min_fac n) β€ (n/min_fac n) := min_fac_le_div w h,
calc
(min_fac n)^2 = (min_fac n) * (min_fac n) : sq (min_fac n)
... β€ (n/min_fac n) * (min_fac n) : nat.mul_le_mul_right (min_fac n) t
... β€ n : div_mul_le_self n (min_fac n)
@[simp]
lemma min_fac_eq_one_iff {n : β} : min_fac n = 1 β n = 1 :=
begin
split,
{ intro h,
by_contradiction hn,
have := min_fac_prime hn,
rw h at this,
exact not_prime_one this, },
{ rintro rfl, refl, }
end
@[simp]
lemma min_fac_eq_two_iff (n : β) : min_fac n = 2 β 2 β£ n :=
begin
split,
{ intro h,
convert min_fac_dvd _,
rw h, },
{ intro h,
have ub := min_fac_le_of_dvd (le_refl 2) h,
have lb := min_fac_pos n,
-- If `interval_cases` and `norm_num` were already available here,
-- this would be easy and pleasant.
-- But they aren't, so it isn't.
cases h : n.min_fac with m,
{ rw h at lb, cases lb, },
{ cases m with m,
{ simp at h, subst h, cases h with n h, cases n; cases h, },
{ cases m with m,
{ refl, },
{ rw h at ub,
cases ub with _ ub, cases ub with _ ub, cases ub, } } } }
end
end min_fac
theorem exists_dvd_of_not_prime {n : β} (n2 : 2 β€ n) (np : Β¬ prime n) :
β m, m β£ n β§ m β 1 β§ m β n :=
β¨min_fac n, min_fac_dvd _, ne_of_gt (min_fac_prime (ne_of_gt n2)).one_lt,
ne_of_lt $ (not_prime_iff_min_fac_lt n2).1 npβ©
theorem exists_dvd_of_not_prime2 {n : β} (n2 : 2 β€ n) (np : Β¬ prime n) :
β m, m β£ n β§ 2 β€ m β§ m < n :=
β¨min_fac n, min_fac_dvd _, (min_fac_prime (ne_of_gt n2)).two_le,
(not_prime_iff_min_fac_lt n2).1 npβ©
theorem exists_prime_and_dvd {n : β} (n2 : 2 β€ n) : β p, prime p β§ p β£ n :=
β¨min_fac n, min_fac_prime (ne_of_gt n2), min_fac_dvd _β©
/-- Euclid's theorem on the **infinitude of primes**.
Here given in the form: for every `n`, there exists a prime number `p β₯ n`. -/
theorem exists_infinite_primes (n : β) : β p, n β€ p β§ prime p :=
let p := min_fac (n! + 1) in
have f1 : n! + 1 β 1, from ne_of_gt $ succ_lt_succ $ factorial_pos _,
have pp : prime p, from min_fac_prime f1,
have np : n β€ p, from le_of_not_ge $ Ξ» h,
have hβ : p β£ n!, from dvd_factorial (min_fac_pos _) h,
have hβ : p β£ 1, from (nat.dvd_add_iff_right hβ).2 (min_fac_dvd _),
pp.not_dvd_one hβ,
β¨p, np, ppβ©
lemma prime.eq_two_or_odd {p : β} (hp : prime p) : p = 2 β¨ p % 2 = 1 :=
(nat.mod_two_eq_zero_or_one p).elim
(Ξ» h, or.inl ((hp.2 2 (dvd_of_mod_eq_zero h)).resolve_left dec_trivial).symm)
or.inr
theorem coprime_of_dvd {m n : β} (H : β k, prime k β k β£ m β Β¬ k β£ n) : coprime m n :=
begin
cases nat.eq_zero_or_pos (gcd m n) with g0 g1,
{ rw [eq_zero_of_gcd_eq_zero_left g0, eq_zero_of_gcd_eq_zero_right g0] at H,
exfalso,
exact H 2 prime_two (dvd_zero _) (dvd_zero _) },
apply eq.symm,
change 1 β€ _ at g1,
apply (lt_or_eq_of_le g1).resolve_left,
intro g2,
obtain β¨p, hp, hpdvdβ© := exists_prime_and_dvd g2,
apply H p hp; apply dvd_trans hpdvd,
{ exact gcd_dvd_left _ _ },
{ exact gcd_dvd_right _ _ }
end
theorem coprime_of_dvd' {m n : β} (H : β k, prime k β k β£ m β k β£ n β k β£ 1) : coprime m n :=
coprime_of_dvd $ Ξ»k kp km kn, not_le_of_gt kp.one_lt $ le_of_dvd zero_lt_one $ H k kp km kn
theorem factors_lemma {k} : (k+2) / min_fac (k+2) < k+2 :=
div_lt_self dec_trivial (min_fac_prime dec_trivial).one_lt
/-- `factors n` is the prime factorization of `n`, listed in increasing order. -/
def factors : β β list β
| 0 := []
| 1 := []
| n@(k+2) :=
let m := min_fac n in have n / m < n := factors_lemma,
m :: factors (n / m)
@[simp] lemma factors_zero : factors 0 = [] := by rw factors
@[simp] lemma factors_one : factors 1 = [] := by rw factors
lemma prime_of_mem_factors : β {n p}, p β factors n β prime p
| 0 := by simp
| 1 := by simp
| n@(k+2) := Ξ» p h,
let m := min_fac n in have n / m < n := factors_lemma,
have hβ : p = m β¨ p β (factors (n / m)) :=
(list.mem_cons_iff _ _ _).1 (by rwa [factors] at h),
or.cases_on hβ (Ξ» hβ, hβ.symm βΈ min_fac_prime dec_trivial)
prime_of_mem_factors
lemma prod_factors : β {n}, 0 < n β list.prod (factors n) = n
| 0 := by simp
| 1 := by simp
| n@(k+2) := Ξ» h,
let m := min_fac n in have n / m < n := factors_lemma,
show (factors n).prod = n, from
have hβ : 0 < n / m :=
nat.pos_of_ne_zero $ Ξ» h,
have n = 0 * m := (nat.div_eq_iff_eq_mul_left (min_fac_pos _) (min_fac_dvd _)).1 h,
by rw zero_mul at this; exact (show k + 2 β 0, from dec_trivial) this,
by rw [factors, list.prod_cons, prod_factors hβ, nat.mul_div_cancel' (min_fac_dvd _)]
lemma factors_prime {p : β} (hp : nat.prime p) : p.factors = [p] :=
begin
have : p = (p - 2) + 2 := (nat.sub_eq_iff_eq_add hp.1).mp rfl,
rw [this, nat.factors],
simp only [eq.symm this],
have : nat.min_fac p = p := (nat.prime_def_min_fac.mp hp).2,
split,
{ exact this, },
{ simp only [this, nat.factors, nat.div_self (nat.prime.pos hp)], },
end
lemma factors_chain : β {n a}, (β p, prime p β p β£ n β a β€ p) β list.chain (β€) a (factors n)
| 0 := Ξ» a h, by simp
| 1 := Ξ» a h, by simp
| n@(k+2) := Ξ» a h,
let m := min_fac n in have n / m < n := factors_lemma,
begin
rw factors,
refine list.chain.cons ((le_min_fac.2 h).resolve_left dec_trivial) (factors_chain _),
exact Ξ» p pp d, min_fac_le_of_dvd pp.two_le (d.trans $ div_dvd_of_dvd $ min_fac_dvd _),
end
lemma factors_chain_2 (n) : list.chain (β€) 2 (factors n) := factors_chain $ Ξ» p pp _, pp.two_le
lemma factors_chain' (n) : list.chain' (β€) (factors n) :=
@list.chain'.tail _ _ (_::_) (factors_chain_2 _)
lemma factors_sorted (n : β) : list.sorted (β€) (factors n) :=
(list.chain'_iff_pairwise (@le_trans _ _)).1 (factors_chain' _)
/-- `factors` can be constructed inductively by extracting `min_fac`, for sufficiently large `n`. -/
lemma factors_add_two (n : β) :
factors (n+2) = min_fac (n+2) :: factors ((n+2) / min_fac (n+2)) :=
by rw factors
@[simp]
lemma factors_eq_nil (n : β) : n.factors = [] β n = 0 β¨ n = 1 :=
begin
split; intro h,
{ rcases n with (_ | _ | n),
{ exact or.inl rfl },
{ exact or.inr rfl },
{ rw factors at h, injection h }, },
{ rcases h with (rfl | rfl),
{ exact factors_zero },
{ exact factors_one }, }
end
theorem prime.coprime_iff_not_dvd {p n : β} (pp : prime p) : coprime p n β Β¬ p β£ n :=
β¨Ξ» co d, pp.not_dvd_one $ co.dvd_of_dvd_mul_left (by simp [d]),
Ξ» nd, coprime_of_dvd $ Ξ» m m2 mp, ((prime_dvd_prime_iff_eq m2 pp).1 mp).symm βΈ ndβ©
theorem prime.dvd_iff_not_coprime {p n : β} (pp : prime p) : p β£ n β Β¬ coprime p n :=
iff_not_comm.2 pp.coprime_iff_not_dvd
theorem prime.not_coprime_iff_dvd {m n : β} :
Β¬ coprime m n β βp, prime p β§ p β£ m β§ p β£ n :=
begin
apply iff.intro,
{ intro h,
exact β¨min_fac (gcd m n), min_fac_prime h,
((min_fac_dvd (gcd m n)).trans (gcd_dvd_left m n)),
((min_fac_dvd (gcd m n)).trans (gcd_dvd_right m n))β© },
{ intro h,
cases h with p hp,
apply nat.not_coprime_of_dvd_of_dvd (prime.one_lt hp.1) hp.2.1 hp.2.2 }
end
theorem prime.dvd_mul {p m n : β} (pp : prime p) : p β£ m * n β p β£ m β¨ p β£ n :=
β¨Ξ» H, or_iff_not_imp_left.2 $ Ξ» h,
(pp.coprime_iff_not_dvd.2 h).dvd_of_dvd_mul_left H,
or.rec (Ξ» h : p β£ m, h.mul_right _) (Ξ» h : p β£ n, h.mul_left _)β©
theorem prime.not_dvd_mul {p m n : β} (pp : prime p)
(Hm : Β¬ p β£ m) (Hn : Β¬ p β£ n) : Β¬ p β£ m * n :=
mt pp.dvd_mul.1 $ by simp [Hm, Hn]
theorem prime.dvd_of_dvd_pow {p m n : β} (pp : prime p) (h : p β£ m^n) : p β£ m :=
by induction n with n IH;
[exact pp.not_dvd_one.elim h,
by { rw pow_succ at h, exact (pp.dvd_mul.1 h).elim id IH } ]
lemma prime.pow_dvd_of_dvd_mul_right {p n a b : β} (hp : p.prime) (h : p ^ n β£ a * b)
(hpb : Β¬ p β£ b) : p ^ n β£ a :=
begin
induction n with n ih,
{ simp },
{ rw [pow_succ'] at *,
rcases ih ((dvd_mul_right _ _).trans h) with β¨c, rflβ©,
rw [mul_assoc] at h,
rcases hp.dvd_mul.1 (nat.dvd_of_mul_dvd_mul_left (pow_pos hp.pos _) h)
with β¨d, rflβ©|β¨d, rflβ©,
{ rw [β mul_assoc],
exact dvd_mul_right _ _ },
{ exact (hpb (dvd_mul_right _ _)).elim } }
end
lemma prime.pow_dvd_of_dvd_mul_left {p n a b : β} (hp : p.prime) (h : p ^ n β£ a * b)
(hpb : Β¬ p β£ a) : p ^ n β£ b :=
by rw [mul_comm] at h; exact hp.pow_dvd_of_dvd_mul_right h hpb
lemma prime.pow_not_prime {x n : β} (hn : 2 β€ n) : Β¬ (x ^ n).prime :=
Ξ» hp, (hp.2 x $ dvd_trans β¨x, sq _β© (pow_dvd_pow _ hn)).elim
(Ξ» hx1, hp.ne_one $ hx1.symm βΈ one_pow _)
(Ξ» hxn, lt_irrefl x $ calc x = x ^ 1 : (pow_one _).symm
... < x ^ n : nat.pow_right_strict_mono (hxn.symm βΈ hp.two_le) hn
... = x : hxn.symm)
lemma prime.pow_not_prime' {x : β} : β {n : β}, n β 1 β Β¬ (x ^ n).prime
| 0 := Ξ» _, not_prime_one
| 1 := Ξ» h, (h rfl).elim
| (n+2) := Ξ» _, prime.pow_not_prime le_add_self
lemma prime.eq_one_of_pow {x n : β} (h : (x ^ n).prime) : n = 1 :=
not_imp_not.mp prime.pow_not_prime' h
lemma prime.pow_eq_iff {p a k : β} (hp : p.prime) : a ^ k = p β a = p β§ k = 1 :=
begin
refine β¨_, Ξ» h, by rw [h.1, h.2, pow_one]β©,
rintro rfl,
rw [hp.eq_one_of_pow, eq_self_iff_true, and_true, pow_one],
end
lemma prime.mul_eq_prime_sq_iff {x y p : β} (hp : p.prime) (hx : x β 1) (hy : y β 1) :
x * y = p ^ 2 β x = p β§ y = p :=
β¨Ξ» h, have pdvdxy : p β£ x * y, by rw h; simp [sq],
begin
wlog := hp.dvd_mul.1 pdvdxy using x y,
cases case with a ha,
have hap : a β£ p, from β¨y, by rwa [ha, sq,
mul_assoc, nat.mul_right_inj hp.pos, eq_comm] at hβ©,
exact ((nat.dvd_prime hp).1 hap).elim
(Ξ» _, by clear_aux_decl; simp [*, sq, nat.mul_right_inj hp.pos] at *
{contextual := tt})
(Ξ» _, by clear_aux_decl; simp [*, sq, mul_comm, mul_assoc,
nat.mul_right_inj hp.pos, nat.mul_right_eq_self_iff hp.pos] at *
{contextual := tt})
end,
Ξ» β¨hβ, hββ©, hβ.symm βΈ hβ.symm βΈ (sq _).symmβ©
lemma prime.dvd_factorial : β {n p : β} (hp : prime p), p β£ n! β p β€ n
| 0 p hp := iff_of_false hp.not_dvd_one (not_le_of_lt hp.pos)
| (n+1) p hp := begin
rw [factorial_succ, hp.dvd_mul, prime.dvd_factorial hp],
exact β¨Ξ» h, h.elim (le_of_dvd (succ_pos _)) le_succ_of_le,
Ξ» h, (_root_.lt_or_eq_of_le h).elim (or.inr β le_of_lt_succ)
(Ξ» h, or.inl $ by rw h)β©
end
theorem prime.coprime_pow_of_not_dvd {p m a : β} (pp : prime p) (h : Β¬ p β£ a) : coprime a (p^m) :=
(pp.coprime_iff_not_dvd.2 h).symm.pow_right _
theorem coprime_primes {p q : β} (pp : prime p) (pq : prime q) : coprime p q β p β q :=
pp.coprime_iff_not_dvd.trans $ not_congr $ dvd_prime_two_le pq pp.two_le
theorem coprime_pow_primes {p q : β} (n m : β) (pp : prime p) (pq : prime q) (h : p β q) :
coprime (p^n) (q^m) :=
((coprime_primes pp pq).2 h).pow _ _
theorem coprime_or_dvd_of_prime {p} (pp : prime p) (i : β) : coprime p i β¨ p β£ i :=
by rw [pp.dvd_iff_not_coprime]; apply em
theorem dvd_prime_pow {p : β} (pp : prime p) {m i : β} : i β£ (p^m) β β k β€ m, i = p^k :=
begin
induction m with m IH generalizing i, {simp [pow_succ, le_zero_iff] at *},
by_cases p β£ i,
{ cases h with a e, subst e,
rw [pow_succ, nat.mul_dvd_mul_iff_left pp.pos, IH],
split; intro h; rcases h with β¨k, h, eβ©,
{ exact β¨succ k, succ_le_succ h, by rw [e, pow_succ]; reflβ© },
cases k with k,
{ apply pp.not_dvd_one.elim,
simp at e, rw β e, apply dvd_mul_right },
{ refine β¨k, le_of_succ_le_succ h, _β©,
rwa [mul_comm, pow_succ', nat.mul_left_inj pp.pos] at e } },
{ split; intro d,
{ rw (pp.coprime_pow_of_not_dvd h).eq_one_of_dvd d,
exact β¨0, zero_le _, rflβ© },
{ rcases d with β¨k, l, eβ©,
rw e, exact pow_dvd_pow _ l } }
end
/--
If `p` is prime,
and `a` doesn't divide `p^k`, but `a` does divide `p^(k+1)`
then `a = p^(k+1)`.
-/
lemma eq_prime_pow_of_dvd_least_prime_pow
{a p k : β} (pp : prime p) (hβ : Β¬(a β£ p^k)) (hβ : a β£ p^(k+1)) :
a = p^(k+1) :=
begin
obtain β¨l, β¨h, rflβ©β© := (dvd_prime_pow pp).1 hβ,
congr,
exact le_antisymm h (not_le.1 ((not_congr (pow_dvd_pow_iff_le_right (prime.one_lt pp))).1 hβ)),
end
section
open list
lemma mem_list_primes_of_dvd_prod {p : β} (hp : prime p) :
β {l : list β}, (β p β l, prime p) β p β£ prod l β p β l
| [] := Ξ» hβ hβ, absurd hβ (prime.not_dvd_one hp)
| (q :: l) := Ξ» hβ hβ,
have hβ : p β£ q * prod l := @prod_cons _ _ l q βΈ hβ,
have hq : prime q := hβ q (mem_cons_self _ _),
or.cases_on ((prime.dvd_mul hp).1 hβ)
(Ξ» h, by rw [prime.dvd_iff_not_coprime hp, coprime_primes hp hq, ne.def, not_not] at h;
exact h βΈ mem_cons_self _ _)
(Ξ» h, have hl : β p β l, prime p := Ξ» p hlp, hβ p ((mem_cons_iff _ _ _).2 (or.inr hlp)),
(mem_cons_iff _ _ _).2 (or.inr (mem_list_primes_of_dvd_prod hl h)))
lemma mem_factors_iff_dvd {n p : β} (hn : 0 < n) (hp : prime p) : p β factors n β p β£ n :=
β¨Ξ» h, prod_factors hn βΈ list.dvd_prod h,
Ξ» h, mem_list_primes_of_dvd_prod hp (@prime_of_mem_factors n) ((prod_factors hn).symm βΈ h)β©
lemma mem_factors {n p} (hn : 0 < n) : p β factors n β prime p β§ p β£ n :=
β¨Ξ» h, β¨prime_of_mem_factors h, (mem_factors_iff_dvd hn $ prime_of_mem_factors h).mp hβ©,
Ξ» β¨hprime, hdvdβ©, (mem_factors_iff_dvd hn hprime).mpr hdvdβ©
lemma factors_subset_right {n k : β} (h : k β 0) : n.factors β (n * k).factors :=
begin
cases n,
{ rw zero_mul, refl },
cases n,
{ rw factors_one, apply list.nil_subset },
intros p hp,
rw mem_factors succ_pos' at hp,
rw mem_factors (nat.mul_pos succ_pos' (nat.pos_of_ne_zero h)),
exact β¨hp.1, hp.2.mul_right kβ©,
end
lemma factors_subset_of_dvd {n k : β} (h : n β£ k) (h' : k β 0) : n.factors β k.factors :=
begin
obtain β¨a, rflβ© := h,
exact factors_subset_right (right_ne_zero_of_mul h'),
end
lemma perm_of_prod_eq_prod : β {lβ lβ : list β}, prod lβ = prod lβ β
(β p β lβ, prime p) β (β p β lβ, prime p) β lβ ~ lβ
| [] [] _ _ _ := perm.nil
| [] (a :: l) hβ hβ hβ :=
have ha : a β£ 1 := @prod_nil β _ βΈ hβ.symm βΈ (@prod_cons _ _ l a).symm βΈ dvd_mul_right _ _,
absurd ha (prime.not_dvd_one (hβ a (mem_cons_self _ _)))
| (a :: l) [] hβ hβ hβ :=
have ha : a β£ 1 := @prod_nil β _ βΈ hβ βΈ (@prod_cons _ _ l a).symm βΈ dvd_mul_right _ _,
absurd ha (prime.not_dvd_one (hβ a (mem_cons_self _ _)))
| (a :: lβ) (b :: lβ) h hlβ hlβ :=
have hlβ' : β p β lβ, prime p := Ξ» p hp, hlβ p (mem_cons_of_mem _ hp),
have hlβ' : β p β (b :: lβ).erase a, prime p := Ξ» p hp, hlβ p (mem_of_mem_erase hp),
have ha : a β (b :: lβ) := mem_list_primes_of_dvd_prod (hlβ a (mem_cons_self _ _)) hlβ
(h βΈ by rw prod_cons; exact dvd_mul_right _ _),
have hb : b :: lβ ~ a :: (b :: lβ).erase a := perm_cons_erase ha,
have hl : prod lβ = prod ((b :: lβ).erase a) :=
(nat.mul_right_inj (prime.pos (hlβ a (mem_cons_self _ _)))).1 $
by rwa [β prod_cons, β prod_cons, β hb.prod_eq],
perm.trans ((perm_of_prod_eq_prod hl hlβ' hlβ').cons _) hb.symm
/-- **Fundamental theorem of arithmetic**-/
lemma factors_unique {n : β} {l : list β} (hβ : prod l = n) (hβ : β p β l, prime p) :
l ~ factors n :=
have hn : 0 < n := nat.pos_of_ne_zero $ Ξ» h, begin
rw h at *, clear h,
induction l with a l hi,
{ exact absurd hβ dec_trivial },
{ rw prod_cons at hβ,
exact nat.mul_ne_zero (ne_of_lt (prime.pos (hβ a (mem_cons_self _ _)))).symm
(hi (Ξ» p hp, hβ p (mem_cons_of_mem _ hp))) hβ }
end,
perm_of_prod_eq_prod (by rwa prod_factors hn) hβ (@prime_of_mem_factors _)
lemma prime.factors_pow {p : β} (hp : p.prime) (n : β) :
(p ^ n).factors = list.repeat p n :=
begin
symmetry,
rw β list.repeat_perm,
apply nat.factors_unique (list.prod_repeat p n),
{ intros q hq,
rwa eq_of_mem_repeat hq },
end
end
lemma succ_dvd_or_succ_dvd_of_succ_sum_dvd_mul {p : β} (p_prime : prime p) {m n k l : β}
(hpm : p ^ k β£ m) (hpn : p ^ l β£ n) (hpmn : p ^ (k+l+1) β£ m*n) :
p ^ (k+1) β£ m β¨ p ^ (l+1) β£ n :=
have hpd : p^(k+l)*p β£ m*n, by rwa pow_succ' at hpmn,
have hpd2 : p β£ (m*n) / p ^ (k+l), from dvd_div_of_mul_dvd hpd,
have hpd3 : p β£ (m*n) / (p^k * p^l), by simpa [pow_add] using hpd2,
have hpd4 : p β£ (m / p^k) * (n / p^l), by simpa [nat.div_mul_div hpm hpn] using hpd3,
have hpd5 : p β£ (m / p^k) β¨ p β£ (n / p^l), from (prime.dvd_mul p_prime).1 hpd4,
suffices p^k*p β£ m β¨ p^l*p β£ n, by rwa [pow_succ', pow_succ'],
hpd5.elim
(assume : p β£ m / p ^ k, or.inl $ mul_dvd_of_dvd_div hpm this)
(assume : p β£ n / p ^ l, or.inr $ mul_dvd_of_dvd_div hpn this)
/-- The type of prime numbers -/
def primes := {p : β // p.prime}
namespace primes
instance : has_repr nat.primes := β¨Ξ» p, repr p.valβ©
instance inhabited_primes : inhabited primes := β¨β¨2, prime_twoβ©β©
instance coe_nat : has_coe nat.primes β := β¨subtype.valβ©
theorem coe_nat_inj (p q : nat.primes) : (p : β) = (q : β) β p = q :=
Ξ» h, subtype.eq h
end primes
instance monoid.prime_pow {Ξ± : Type*} [monoid Ξ±] : has_pow Ξ± primes := β¨Ξ» x p, x^p.valβ©
end nat
/-! ### Primality prover -/
namespace tactic
namespace norm_num
open norm_num
lemma is_prime_helper (n : β)
(hβ : 1 < n) (hβ : nat.min_fac n = n) : nat.prime n :=
nat.prime_def_min_fac.2 β¨hβ, hββ©
lemma min_fac_bit0 (n : β) : nat.min_fac (bit0 n) = 2 :=
by simp [nat.min_fac_eq, show 2 β£ bit0 n, by simp [bit0_eq_two_mul n]]
/-- A predicate representing partial progress in a proof of `min_fac`. -/
def min_fac_helper (n k : β) : Prop :=
0 < k β§ bit1 k β€ nat.min_fac (bit1 n)
theorem min_fac_helper.n_pos {n k : β} (h : min_fac_helper n k) : 0 < n :=
pos_iff_ne_zero.2 $ Ξ» e,
by rw e at h; exact not_le_of_lt (nat.bit1_lt h.1) h.2
lemma min_fac_ne_bit0 {n k : β} : nat.min_fac (bit1 n) β bit0 k :=
by rw bit0_eq_two_mul; exact Ξ» e, absurd
((nat.dvd_add_iff_right (by simp [bit0_eq_two_mul n])).2
(dvd_trans β¨_, eβ© (nat.min_fac_dvd _)))
(by norm_num)
lemma min_fac_helper_0 (n : β) (h : 0 < n) : min_fac_helper n 1 :=
begin
refine β¨zero_lt_one, lt_of_le_of_ne _ min_fac_ne_bit0.symmβ©,
refine @lt_of_le_of_ne β _ _ _ (nat.min_fac_pos _) _,
intro e,
have := nat.min_fac_prime _,
{ rw β e at this, exact nat.not_prime_one this },
{ exact ne_of_gt (nat.bit1_lt h) }
end
lemma min_fac_helper_1 {n k k' : β} (e : k + 1 = k')
(np : nat.min_fac (bit1 n) β bit1 k)
(h : min_fac_helper n k) : min_fac_helper n k' :=
begin
rw β e,
refine β¨nat.succ_pos _,
(lt_of_le_of_ne (lt_of_le_of_ne _ _ : k+1+k < _)
min_fac_ne_bit0.symm : bit0 (k+1) < _)β©,
{ rw add_right_comm, exact h.2 },
{ rw add_right_comm, exact np.symm }
end
lemma min_fac_helper_2 (n k k' : β) (e : k + 1 = k')
(np : Β¬ nat.prime (bit1 k)) (h : min_fac_helper n k) : min_fac_helper n k' :=
begin
refine min_fac_helper_1 e _ h,
intro eβ, rw β eβ at np,
exact np (nat.min_fac_prime $ ne_of_gt $ nat.bit1_lt h.n_pos)
end
lemma min_fac_helper_3 (n k k' c : β) (e : k + 1 = k')
(nc : bit1 n % bit1 k = c) (c0 : 0 < c)
(h : min_fac_helper n k) : min_fac_helper n k' :=
begin
refine min_fac_helper_1 e _ h,
refine mt _ (ne_of_gt c0), intro eβ,
rw [β nc, β nat.dvd_iff_mod_eq_zero, β eβ],
apply nat.min_fac_dvd
end
lemma min_fac_helper_4 (n k : β) (hd : bit1 n % bit1 k = 0)
(h : min_fac_helper n k) : nat.min_fac (bit1 n) = bit1 k :=
by rw β nat.dvd_iff_mod_eq_zero at hd; exact
le_antisymm (nat.min_fac_le_of_dvd (nat.bit1_lt h.1) hd) h.2
lemma min_fac_helper_5 (n k k' : β) (e : bit1 k * bit1 k = k')
(hd : bit1 n < k') (h : min_fac_helper n k) : nat.min_fac (bit1 n) = bit1 n :=
begin
refine (nat.prime_def_min_fac.1 (nat.prime_def_le_sqrt.2
β¨nat.bit1_lt h.n_pos, _β©)).2,
rw β e at hd,
intros m m2 hm md,
have := le_trans h.2 (le_trans (nat.min_fac_le_of_dvd m2 md) hm),
rw nat.le_sqrt at this,
exact not_le_of_lt hd this
end
/-- Given `e` a natural numeral and `d : nat` a factor of it, return `β’ Β¬ prime e`. -/
meta def prove_non_prime (e : expr) (n dβ : β) : tactic expr :=
do let eβ := reflect dβ,
c β mk_instance_cache `(nat),
(c, pβ) β prove_lt_nat c `(1) eβ,
let dβ := n / dβ, let eβ := reflect dβ,
(c, e', p) β prove_mul_nat c eβ eβ,
guard (e' =β e),
(c, pβ) β prove_lt_nat c `(1) eβ,
return $ `(@nat.not_prime_mul').mk_app [eβ, eβ, e, p, pβ, pβ]
/-- Given `a`,`a1 := bit1 a`, `n1` the value of `a1`, `b` and `p : min_fac_helper a b`,
returns `(c, β’ min_fac a1 = c)`. -/
meta def prove_min_fac_aux (a a1 : expr) (n1 : β) :
instance_cache β expr β expr β tactic (instance_cache Γ expr Γ expr)
| ic b p := do
k β b.to_nat,
let k1 := bit1 k,
let b1 := `(bit1:βββ).mk_app [b],
if n1 < k1*k1 then do
(ic, e', pβ) β prove_mul_nat ic b1 b1,
(ic, pβ) β prove_lt_nat ic a1 e',
return (ic, a1, `(min_fac_helper_5).mk_app [a, b, e', pβ, pβ, p])
else let d := k1.min_fac in
if to_bool (d < k1) then do
let k' := k+1, let e' := reflect k',
(ic, pβ) β prove_succ ic b e',
pβ β prove_non_prime b1 k1 d,
prove_min_fac_aux ic e' $ `(min_fac_helper_2).mk_app [a, b, e', pβ, pβ, p]
else do
let nc := n1 % k1,
(ic, c, pc) β prove_div_mod ic a1 b1 tt,
if nc = 0 then
return (ic, b1, `(min_fac_helper_4).mk_app [a, b, pc, p])
else do
(ic, pβ) β prove_pos ic c,
let k' := k+1, let e' := reflect k',
(ic, pβ) β prove_succ ic b e',
prove_min_fac_aux ic e' $ `(min_fac_helper_3).mk_app [a, b, e', c, pβ, pc, pβ, p]
/-- Given `a` a natural numeral, returns `(b, β’ min_fac a = b)`. -/
meta def prove_min_fac (ic : instance_cache) (e : expr) : tactic (instance_cache Γ expr Γ expr) :=
match match_numeral e with
| match_numeral_result.zero := return (ic, `(2:β), `(nat.min_fac_zero))
| match_numeral_result.one := return (ic, `(1:β), `(nat.min_fac_one))
| match_numeral_result.bit0 e := return (ic, `(2), `(min_fac_bit0).mk_app [e])
| match_numeral_result.bit1 e := do
n β e.to_nat,
c β mk_instance_cache `(nat),
(c, p) β prove_pos c e,
let a1 := `(bit1:βββ).mk_app [e],
prove_min_fac_aux e a1 (bit1 n) c `(1) (`(min_fac_helper_0).mk_app [e, p])
| _ := failed
end
/-- A partial proof of `factors`. Asserts that `l` is a sorted list of primes, lower bounded by a
prime `p`, which multiplies to `n`. -/
def factors_helper (n p : β) (l : list β) : Prop :=
p.prime β list.chain (β€) p l β§ (β a β l, nat.prime a) β§ list.prod l = n
lemma factors_helper_nil (a : β) : factors_helper 1 a [] :=
Ξ» pa, β¨list.chain.nil, by rintro _ β¨β©, list.prod_nilβ©
lemma factors_helper_cons' (n m a b : β) (l : list β)
(hβ : b * m = n) (hβ : a β€ b) (hβ : nat.min_fac b = b)
(H : factors_helper m b l) : factors_helper n a (b :: l) :=
Ξ» pa,
have pb : b.prime, from nat.prime_def_min_fac.2 β¨le_trans pa.two_le hβ, hββ©,
let β¨fβ, fβ, fββ© := H pb in
β¨list.chain.cons hβ fβ, Ξ» c h, h.elim (Ξ» e, e.symm βΈ pb) (fβ _),
by rw [list.prod_cons, fβ, hβ]β©
lemma factors_helper_cons (n m a b : β) (l : list β)
(hβ : b * m = n) (hβ : a < b) (hβ : nat.min_fac b = b)
(H : factors_helper m b l) : factors_helper n a (b :: l) :=
factors_helper_cons' _ _ _ _ _ hβ hβ.le hβ H
lemma factors_helper_sn (n a : β) (hβ : a < n) (hβ : nat.min_fac n = n) : factors_helper n a [n] :=
factors_helper_cons _ _ _ _ _ (mul_one _) hβ hβ (factors_helper_nil _)
lemma factors_helper_same (n m a : β) (l : list β) (h : a * m = n)
(H : factors_helper m a l) : factors_helper n a (a :: l) :=
Ξ» pa, factors_helper_cons' _ _ _ _ _ h (le_refl _) (nat.prime_def_min_fac.1 pa).2 H pa
lemma factors_helper_same_sn (a : β) : factors_helper a a [a] :=
factors_helper_same _ _ _ _ (mul_one _) (factors_helper_nil _)
lemma factors_helper_end (n : β) (l : list β) (H : factors_helper n 2 l) : nat.factors n = l :=
let β¨hβ, hβ, hββ© := H nat.prime_two in
have _, from (list.chain'_iff_pairwise (@le_trans _ _)).1 (@list.chain'.tail _ _ (_::_) hβ),
(list.eq_of_perm_of_sorted (nat.factors_unique hβ hβ) this (nat.factors_sorted _)).symm
/-- Given `n` and `a` natural numerals, returns `(l, β’ factors_helper n a l)`. -/
meta def prove_factors_aux :
instance_cache β expr β expr β β β β β tactic (instance_cache Γ expr Γ expr)
| c en ea n a :=
let b := n.min_fac in
if b < n then do
let m := n / b,
(c, em) β c.of_nat m,
if b = a then do
(c, _, pβ) β prove_mul_nat c ea em,
(c, l, pβ) β prove_factors_aux c em ea m a,
pure (c, `(%%ea::%%l:list β), `(factors_helper_same).mk_app [en, em, ea, l, pβ, pβ])
else do
(c, eb) β c.of_nat b,
(c, _, pβ) β prove_mul_nat c eb em,
(c, pβ) β prove_lt_nat c ea eb,
(c, _, pβ) β prove_min_fac c eb,
(c, l, pβ) β prove_factors_aux c em eb m b,
pure (c, `(%%eb::%%l : list β),
`(factors_helper_cons).mk_app [en, em, ea, eb, l, pβ, pβ, pβ, pβ])
else if b = a then
pure (c, `([%%ea] : list β), `(factors_helper_same_sn).mk_app [ea])
else do
(c, pβ) β prove_lt_nat c ea en,
(c, _, pβ) β prove_min_fac c en,
pure (c, `([%%en] : list β), `(factors_helper_sn).mk_app [en, ea, pβ, pβ])
/-- Evaluates the `prime` and `min_fac` functions. -/
@[norm_num] meta def eval_prime : expr β tactic (expr Γ expr)
| `(nat.prime %%e) := do
n β e.to_nat,
match n with
| 0 := false_intro `(nat.not_prime_zero)
| 1 := false_intro `(nat.not_prime_one)
| _ := let dβ := n.min_fac in
if dβ < n then prove_non_prime e n dβ >>= false_intro
else do
let eβ := reflect dβ,
c β mk_instance_cache `(β),
(c, pβ) β prove_lt_nat c `(1) eβ,
(c, eβ, p) β prove_min_fac c e,
true_intro $ `(is_prime_helper).mk_app [e, pβ, p]
end
| `(nat.min_fac %%e) := do
ic β mk_instance_cache `(β),
prod.snd <$> prove_min_fac ic e
| `(nat.factors %%e) := do
n β e.to_nat,
match n with
| 0 := pure (`(@list.nil β), `(nat.factors_zero))
| 1 := pure (`(@list.nil β), `(nat.factors_one))
| _ := do
c β mk_instance_cache `(β),
(c, l, p) β prove_factors_aux c e `(2) n 2,
pure (l, `(factors_helper_end).mk_app [e, l, p])
end
| _ := failed
end norm_num
end tactic
namespace nat
theorem prime_three : prime 3 := by norm_num
end nat
|
5c31fe4b0a57c23df9f153f35622b986ec760c19 | 42c01158c2730cc6ac3e058c1339c18cb90366e2 | /xenalib/square_root.lean | cfc7128e14594872f43184322438067e6ee1a4b7 | [] | no_license | ChrisHughes24/xena | c80d94355d0c2ae8deddda9d01e6d31bc21c30ae | 337a0d7c9f0e255e08d6d0a383e303c080c6ec0c | refs/heads/master | 1,631,059,898,392 | 1,511,200,551,000 | 1,511,200,551,000 | 111,468,589 | 1 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 13,700 | lean | /-
Copyright (c) 2017 Kevin Buzzard. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author : Kevin Buzzard
A square root function.
1) The non-computable function
square_root : Ξ (x : β), x β₯ 0 β β
returns the non-negative square root of x, defined as the sup of all
the reals whose square is at most x.
2) The non-computable function
sqrt_abs : β β β
sends a real number x to the non-negative square root of abs x (a.k.a. |x|).
-/
import analysis.real tactic.norm_num
-- analysis.real -- for reals
-- tactic.norm_num -- because I want to do proofs of things like 1/4 < 1 in β quickly
-- init.classical -- don't know why yet.
-- Can I just dump the below things into Lean within no namespace?
theorem pow_two_eq_mul_self {Ξ± : Type} [monoid Ξ±] {x : Ξ±} : x ^ 2 = x * x :=
by simp [pow_nat, has_pow_nat.pow_nat, monoid.pow]
theorem mul_self_eq_pow_two {Ξ± : Type} [monoid Ξ±] {x : Ξ±} : x * x = x ^ 2 :=
eq.symm pow_two_eq_mul_self
theorem imp_of_not_or {A B : Prop} : (A β¨ B) β (Β¬ A) β B :=
begin
intros Hor HnBofA,
cases Hor,
contradiction,
exact a
end
-- #check @abs_sub_square -- why is that even there?
/-
Possibly more useful:
#check @nonneg_le_nonneg_of_squares_le
nonneg_le_nonneg_of_squares_le :
β {Ξ± : Type u_1} [_inst_1 : linear_ordered_ring Ξ±] {a b : Ξ±}, b β₯ 0 β a * a β€ b * b β a β€ b
-/
namespace square_root -- I have no idea whether this is the right thing to do
open square_root
theorem square_inj_on_nonneg {x y : β} : (x β₯ 0) β (y β₯ 0) β (x^2 = y^2) β (x=y) :=
begin
assume H_x_ge_zero : x β₯ 0,
assume H_y_ge_zero : y β₯ 0,
assume H : x ^ 2 = y ^ 2,
rw [pow_two_eq_mul_self,pow_two_eq_mul_self,mul_self_eq_mul_self_iff] at H,
cases H with Heq Hneg,
exact Heq,
have H2 : x = 0 β§ y = 0,
exact (add_eq_zero_iff_eq_zero_of_nonneg H_x_ge_zero H_y_ge_zero).1 (add_eq_zero_iff_eq_neg.2 Hneg),
rw [H2.left,H2.right],
end
theorem square_cont_at_zero : β (r : β), r > 0 β
β (eps : β), (eps > 0) β§ eps ^ 2 < r :=
begin
intros r Hr_gt_0,
cases lt_or_ge r 1 with Hrl1 Hrge1,
have H : r^2<r,
unfold pow_nat has_pow_nat.pow_nat monoid.pow,
exact calc r*(r*1) = r*r : by simp
... < r*1 : mul_lt_mul_of_pos_left Hrl1 Hr_gt_0
... = r : mul_one r,
existsi r,
exact β¨Hr_gt_0,Hβ©,
cases le_iff_eq_or_lt.mp Hrge1 with r1 rg1,
rw [βr1],
exact β¨((1/2):β),by norm_numβ©,
existsi (1:β),
split,
exact zero_lt_one,
suffices : 1<r, by simpa,
exact rg1,
end
-- #check @nonneg_le_nonneg_of_squares_le
-- β {Ξ± : Type u_1} [_inst_1 : linear_ordered_ring Ξ±] {a b : Ξ±},
-- b β₯ 0 β a * a β€ b * b β a β€ b
theorem exists_square_root (r:β) (rnneg : r β₯ 0) : β (q : β), (q β₯ 0) β§ q^2=r :=
begin
cases le_iff_eq_or_lt.mp rnneg with r0 rpos,
rw [βr0],
exact β¨(0:β),by norm_numβ©,
clear rnneg,
let S := { x:β | x^2 β€ r},
-- S non-empty
have H0 : (0:β) β S,
suffices : 0 β€ r, by simpa [pow_two_eq_mul_self],
exact le_of_lt rpos,
-- S has upper bound
have H1 : max r 1 β upper_bounds S,
cases classical.em (r β€ 1) with rle1 rgt1,
intros t Ht,
suffices H : t β€ 1,
exact le_trans H (le_max_right r 1),
exact nonneg_le_nonneg_of_squares_le (zero_le_one) (by rw [mul_one,βpow_two_eq_mul_self];exact (le_trans Ht rle1)),
have H : 1<r,
exact lt_of_not_ge rgt1,
clear rgt1,
intros t Ht,
suffices H : t β€ r,
exact le_trans H (le_max_left r 1),
-- need to prove t^2<=r implies t<=r
apply imp_of_not_or (lt_or_ge r t),
assume H1 : r<t,
apply not_le_of_gt H1,
apply nonneg_le_nonneg_of_squares_le (le_of_lt rpos),
exact le_of_lt (calc t*t=t^2 : mul_self_eq_pow_two
... β€ r : Ht
... = r*1 : eq.symm (mul_one r)
... < r*r : mul_lt_mul_of_pos_left H rpos),
-- get LUB
have H : β (x : β), is_lub S x,
exact exists_supremum_real H0 H1,
cases H with q Hq,
existsi q,
have Hqge0 : 0 β€ q,
exact Hq.left 0 H0,
split,
exact Hqge0,
-- I tidied the code up, up to here; the rest is my original effort.
-- idea is to prove q^2=r by showing not < or >
-- first not <
have H2 : Β¬ (q^2<r),
intro Hq2r,
have H2 : q β upper_bounds S,
exact Hq.left,
clear Hq H0 H1,
unfold upper_bounds at H2,
have H3 : β qe, q<qe β Β¬(qe^2β€r),
intro qe,
intro qlqe,
intro H4,
have H5 : qe β€ q,
exact H2 qe H4,
exact not_lt_of_ge H5 qlqe,
have H4 : β eps > 0,(q+eps)^2>r,
intros eps Heps,
exact lt_of_not_ge (H3 (q+eps) ((lt_add_iff_pos_right q).mpr Heps)),
clear H3 H2 S,
cases le_iff_eq_or_lt.mp Hqge0 with Hq0 Hqg0,
cases (square_cont_at_zero r rpos) with eps Heps,
specialize H4 eps,
rw [βHq0] at H4,
simp at H4,
have H3 : eps^2>r,
exact H4 Heps.left,
exact (lt_iff_not_ge r (eps^2)).mp H3 (le_of_lt Heps.right),
clear Hqge0,
-- want eps such that 2*q*eps+eps^2 <= r-q^2
-- so eps=min((r-q^2)/4q,thing-produced-by-square-cts-function)
have H0 : (0:β)<2,
norm_num,
have H : 0<(r-q^2),
exact sub_pos_of_lt Hq2r,
have H2 : 0 < (r-q^2)/2,
exact div_pos_of_pos_of_pos H H0,
have H3 : 0 < (r-q^2)/2/(2*q),
exact div_pos_of_pos_of_pos H2 (mul_pos H0 Hqg0),
cases (square_cont_at_zero ((r-q^2)/2) H2) with e0 He0,
let e1 := min ((r-q^2)/2/(2*q)) e0,
have He1 : e1>0,
exact lt_min H3 He0.left,
specialize H4 e1, -- should be a contradiction
have H1 : (q+e1)^2 > r,
exact H4 He1,
have H5 : e1 β€ ((r-q^2)/2/(2*q)),
exact (min_le_left ((r-q^2)/2/(2*q)) e0),
have H6 : e1*e1<(r - q ^ 2) / 2,
exact calc e1*e1 β€ e0*e1 : mul_le_mul_of_nonneg_right (min_le_right ((r - q ^ 2) / 2 / (2 * q)) e0) (le_of_lt He1)
... β€ e0*e0 : mul_le_mul_of_nonneg_left (min_le_right ((r - q ^ 2) / 2 / (2 * q)) e0) (le_of_lt He0.left )
... = e0^2 : by {unfold pow_nat has_pow_nat.pow_nat monoid.pow,simp}
... < (r-q^2)/2 : He0.right,
have Hn1 : (q+e1)^2 < r,
exact calc (q+e1)^2 = (q+e1)*(q+e1) : by {unfold pow_nat has_pow_nat.pow_nat monoid.pow,simp}
... = q*q+2*q*e1+e1*e1 : by rw [mul_add,add_mul,add_mul,mul_comm e1 q,two_mul,add_mul,add_assoc,add_assoc,add_assoc]
... = q^2 + (2*q)*e1 + e1*e1 : by {unfold pow_nat has_pow_nat.pow_nat monoid.pow,simp}
... β€ q^2 + (2*q)*((r - q ^ 2) / 2 / (2 * q)) + e1*e1 : add_le_add_right (add_le_add_left ((mul_le_mul_left (mul_pos H0 Hqg0)).mpr H5) (q^2)) (e1*e1)
... < q^2 + (2*q)*((r - q ^ 2) / 2 / (2 * q)) + (r-q^2)/2 : add_lt_add_left H6 _
... = r : by rw [mul_comm,div_mul_eq_mul_div,mul_div_assoc,div_self (ne_of_gt (mul_pos H0 Hqg0)),mul_one,add_assoc,div_add_div_same,βtwo_mul,mul_comm,mul_div_assoc,div_self (ne_of_gt H0),mul_one,add_sub,add_comm,βadd_sub,sub_self,add_zero], -- rw [mul_div_cancel'], -- nearly there
exact not_lt_of_ge (le_of_lt H1) Hn1,
-- now not >
have H3 : Β¬ (q^2>r),
intro Hq2r,
have H3 : q β lower_bounds (upper_bounds S),
exact Hq.right,
clear Hq H0 H1 H2,
have Hqg0 : 0 < q,
cases le_iff_eq_or_lt.mp Hqge0 with Hq0 H,
tactic.swap,
exact H,
unfold pow_nat has_pow_nat.pow_nat monoid.pow at Hq2r,
rw [βHq0] at Hq2r,
simp at Hq2r,
exfalso,
exact not_lt_of_ge (le_of_lt rpos) Hq2r,
clear Hqge0,
have H : β (eps:β), (eps > 0 β§ eps < q) β (q-eps)^2 < r,
unfold lower_bounds at H3,
unfold set_of at H3,
unfold has_mem.mem set.mem has_mem.mem at H3,
intros eps Heps,
have H : Β¬ ((q-eps) β (upper_bounds S)),
intro H,
have H2 : q β€ q-eps,
exact H3 (q-eps) H,
rw [le_sub_iff_add_le] at H2,
have Hf : q<q,
exact calc
q < eps+q : lt_add_of_pos_left q Heps.left
... = q+eps : add_comm eps q
... β€ q : H2,
have Hf2 : Β¬ (q=q),
exact ne_of_lt Hf,
exact Hf2 (by simp),
unfold upper_bounds at H,
unfold has_mem.mem set.mem has_mem.mem set_of at H,
have H2 : β (b:β), Β¬ (S b β b β€ q-eps),
exact classical.not_forall.mp H,
cases H2 with b Hb,
clear H,
cases classical.em (S b) with Hsb Hsnb,
tactic.swap,
have Hnb : S b β b β€ q - eps,
intro Hsb,
exfalso,
exact Hsnb Hsb,
exfalso,
exact Hb Hnb,
cases classical.em (b β€ q - eps) with Hlt Hg,
exfalso,
exact Hb (Ξ» _,Hlt),
have Hh : q-eps < b,
exact lt_of_not_ge Hg,
clear Hg Hb,
-- todo: (q-eps)>0, (q-eps)^2<b^2<=r,
have H0 : 0<q-eps,
rw [lt_sub_iff,zero_add],exact Heps.right,
unfold pow_nat has_pow_nat.pow_nat monoid.pow,
exact calc (q-eps)*((q-eps)*1) = (q-eps)*(q-eps) : congr_arg (Ξ» t, (q-eps)*t) (mul_one (q-eps))
... < (q-eps) * b : mul_lt_mul_of_pos_left Hh H0
... < b * b : mul_lt_mul_of_pos_right Hh (lt_trans H0 Hh)
... = b^2 : by { unfold pow_nat has_pow_nat.pow_nat monoid.pow, simp}
... β€ r : Hsb,
-- We now know (q-eps)^2<r for all eps>0, and q^2>r. Need a contradiction.
-- Idea: (q^2-2*q*eps+eps^2)<r so 2q.eps-eps^2>q^2-r>0,
-- so we need to find eps such that 2q.eps-eps^2<(q^2-r)
-- so set eps=min((q^2-r)/2q,q)
have H0 : (0:β)<2,
norm_num,
have H1 : 0<(q^2-r),
exact sub_pos_of_lt Hq2r,
have H2 : 0 < (q/2),
exact div_pos_of_pos_of_pos Hqg0 H0,
have J1 : 0 < (q^2-r)/(2*q),
exact div_pos_of_pos_of_pos H1 (mul_pos H0 Hqg0),
let e1 := min ((q^2-r)/(2*q)) (q/2),
have He1 : e1>0,
exact lt_min J1 H2,
specialize H e1, -- should be a contradiction
have J0 : e1<q,
exact calc e1 β€ (q/2) : min_le_right ((q^2-r)/(2*q)) (q/2)
... = q*(1/2) : by rw [βmul_div_assoc,mul_one]
... < q*1 : mul_lt_mul_of_pos_left (by norm_num) Hqg0
... = q : by rw [mul_one],
have H4 : (q-e1)^2 < r,
exact H β¨He1,J0β©,
have H5 : e1 β€ ((q^2-r)/(2*q)),
exact (min_le_left ((q^2-r)/(2*q)) (q/2)),
have H6 : e1*e1>0,
exact mul_pos He1 He1,
have Hn1 : (q-e1)^2 > r,
exact calc (q-e1)^2 = (q-e1)*(q-e1) : by {unfold pow_nat has_pow_nat.pow_nat monoid.pow,simp}
... = q*q-2*q*e1+e1*e1 : by rw [mul_sub,sub_mul,sub_mul,mul_comm e1 q,two_mul,add_mul];simp
... = q^2 - (2*q)*e1 + e1*e1 : by {unfold pow_nat has_pow_nat.pow_nat monoid.pow,simp}
... > q^2 - (2*q)*e1 : lt_add_of_pos_right (q^2 -(2*q)*e1) H6
... β₯ q^2 - (2*q)*((q ^ 2 - r) / (2 * q)) : sub_le_sub (le_of_eq (eq.refl (q^2))) (mul_le_mul_of_nonneg_left H5 (le_of_lt (mul_pos H0 Hqg0))) -- lt_add_iff_pos_right -- (add_le_add_left ((mul_le_mul_left (mul_pos H0 Hqg0)).mpr H5) (q^2)) (e1*e1)
... = r : by rw [βdiv_mul_eq_mul_div_comm,div_self (ne_of_gt (mul_pos H0 Hqg0)),one_mul];simp, -- ... = r : by rw [mul_comm,div_mul_eq_mul_div,mul_div_assoc,div_self (ne_of_gt (mul_pos H0 Hqg0)),mul_one,add_assoc,div_add_div_same,βtwo_mul,mul_comm,mul_div_assoc,div_self (ne_of_gt H0),mul_one,add_sub,add_comm,βadd_sub,sub_self,add_zero], -- rw [mul_div_cancel'], -- nearly there
exact not_lt_of_ge (le_of_lt (H β¨He1,J0β©)) Hn1,
have H : q^2 β€ r,
exact le_of_not_lt H3,
cases lt_or_eq_of_le H with Hlt Heq,
exfalso,
exact H2 Hlt,
exact Heq
end
-- #check exists_square_root
-- exists_square_root : β (r : β), r β₯ 0 β (β (q : β), q β₯ 0 β§ q ^ 2 = r)
theorem exists_unique_square_root : β (r:β), (r β₯ 0) β β (q:β), (q β₯ 0 β§ q^2 = r β§ β (s:β), s β₯ 0 β§ s^2 = r β s=q) :=
begin
intro r,
assume H_r_ge_zero : r β₯ 0,
cases (exists_square_root r H_r_ge_zero) with q H_q_squared_is_r,
suffices H_unique : β (s:β), s β₯ 0 β§ s ^ 2 = r β s = q,
exact β¨q,β¨H_q_squared_is_r.left,β¨H_q_squared_is_r.right,H_uniqueβ©β©β©,
intro s,
assume H_s_ge_zero_and_square_is_r,
exact square_inj_on_nonneg H_s_ge_zero_and_square_is_r.left H_q_squared_is_r.left (eq.trans H_s_ge_zero_and_square_is_r.right (eq.symm H_q_squared_is_r.right))
end
noncomputable def square_root (x:β) (H_x_nonneg : x β₯ 0) : β := classical.some (exists_unique_square_root x H_x_nonneg)
-- #reduce (square_root 2 (by norm_num)) -- oops
-- Next is what Mario says I should do (at least in terms of where the proof that x>=0 goes)
noncomputable def sqrt_abs (x : β) : β := square_root (abs x) (abs_nonneg x)
def square_root_proof (x:β) (h : x β₯ 0) : (square_root x h) ^ 2 = x :=
(classical.some_spec (exists_unique_square_root x h)).right.left
def square_root_allinfo (x:β) (h : x β₯ 0) :=
classical.some_spec (exists_unique_square_root x h)
theorem sqrt_abs_ge_zero (x : β) : sqrt_abs x β₯ 0 :=
(classical.some_spec (exists_unique_square_root (abs x) (abs_nonneg x))).left
theorem sqrt_abs_unique (x : β) (Hx_nonneg : 0 β€ x) : β (s : β), s β₯ 0 β§ s ^ 2 = x β s = sqrt_abs x :=
begin
have H : β (s : β), s β₯ 0 β§ s ^ 2 = abs x β s = square_root (abs x) (abs_nonneg x),
exact (classical.some_spec (exists_unique_square_root (abs x) (abs_nonneg x))).right.right,
intro s,
intro Hs,
rw [eq.symm (abs_of_nonneg Hx_nonneg)] at Hs,
exact H s Hs,
end
theorem sqrt_abs_squared (x : β) (Hx_nonneg : 0 β€ x) : (sqrt_abs x) ^ 2 = x :=
begin
have H0 : sqrt_abs x ^ 2 = abs x,
exact square_root_proof (abs x) (abs_nonneg x),
rw [H0],
exact abs_of_nonneg Hx_nonneg,
end
theorem sqrt_abs_mul_self (x : β) (Hx_nonneg : 0 β€ x) : (sqrt_abs x) * (sqrt_abs x) = x :=
begin
rw [mul_self_eq_pow_two],
exact sqrt_abs_squared x Hx_nonneg,
end
meta def sqrt_tac : tactic unit := `[assumption <|> norm_num]
noncomputable def sqrt (r : β) (h : r β₯ 0 . sqrt_tac) : β :=
classical.some (exists_unique_square_root r h)
/- example of usage:
noncomputable def s2 : β := sqrt 2
example : s2^2=2 := sqrt_proof 2
-/
end square_root
|
9950745f0b34cb5a08138ea0e4cbe0649994b242 | 6432ea7a083ff6ba21ea17af9ee47b9c371760f7 | /tests/lean/run/discrRefinement.lean | 0b0af3b20cbf779e01bdfac24434544554d15614 | [
"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 | 521 | lean | inductive Vec (Ξ± : Type u) : Nat β Type u
| nil : Vec Ξ± 0
| cons : Ξ± β Vec Ξ± n β Vec Ξ± (n+1)
def Vec.map (xs : Vec Ξ± n) (f : Ξ± β Ξ²) : Vec Ξ² n :=
match xs with
| nil => nil
| cons a as => cons (f a) (map as f)
def Vec.map' (f : Ξ± β Ξ²) : Vec Ξ± n β Vec Ξ² n
| nil => nil
| cons a as => cons (f a) (map' f as)
def Vec.map2 (f : Ξ± β Ξ± β Ξ²) : Vec Ξ± n β Vec Ξ± n β Vec Ξ² n
| nil, nil => nil
| cons a as, cons b bs => cons (f a b) (map2 f as bs)
|
90467f9fbb61700c2478008936be57d6fe5c1801 | a537b538f2bea3181e24409d8a52590603d1ddd9 | /src/tidy/lib/list.lean | 3b190fdd2d172940241d18df5b849a3ce886f00e | [] | no_license | rwbarton/lean-tidy | 6134813ded72b275d19d4d32514dba80c21708e3 | fe1125d32adb60decda7a77d0f679614ba9f6fbb | refs/heads/master | 1,585,549,718,705 | 1,538,120,619,000 | 1,538,120,624,000 | 150,864,330 | 0 | 0 | null | 1,538,225,790,000 | 1,538,225,790,000 | null | UTF-8 | Lean | false | false | 2,353 | lean | import data.option
import data.buffer
universe u
namespace list
private def min_rel_aux {Ξ± : Type u} (r : Ξ± β Ξ± β Prop) [decidable_rel r] (curr : Ξ±) : list Ξ± β Ξ±
| [] := curr
| (a :: rest) := if r a curr then a else curr
def min_rel {Ξ± : Type u} (l : list Ξ±) (r : Ξ± β Ξ± β Prop) [decidable_rel r] : option Ξ± :=
match l with
| [] := none
| (a :: rest) := some $ min_rel_aux r a rest
end
def min {Ξ± : Type u} (l : list Ξ±) [has_lt Ξ±] [@decidable_rel Ξ± has_lt.lt] : option Ξ± :=
min_rel l has_lt.lt
def contains {Ξ± : Type u} [decidable_eq Ξ±] (a : Ξ±) : list Ξ± β bool
| [] := ff
| (h :: rest) := if a = h then tt else rest.contains
meta def erase_duplicates {Ξ± : Type u} [decidable_eq Ξ±] : list Ξ± β list Ξ±
| [] := []
| (x :: t) := (x :: erase_duplicates (t.filter $ Ξ» a, a β x))
def multiplex {Ξ± : Type u} : list Ξ± β list Ξ± β list Ξ±
| [] l := l
| l [] := l
| (aβ :: lβ) (aβ :: lβ) := [aβ, aβ].append $ lβ.multiplex lβ
private def set_at_aux {Ξ± : Type u} (val : Ξ±) : list Ξ± β list Ξ± β β β list Ξ±
| _ [] _ := []
| l (a :: rest) 0 := l.append (val :: rest)
| l (a :: rest) k := set_at_aux (l.append [a]) rest (k - 1)
def set_at {Ξ± : Type u} (l : list Ξ±) (idx : β) (val : Ξ±) : list Ξ± :=
set_at_aux val [] l idx
def split_on_aux {Ξ± : Type u} [decidable_eq Ξ±] (a : Ξ±) : list Ξ± β list Ξ± β list (list Ξ±)
| [] l := [l.reverse]
| (h :: t) l := if h = a then
l.reverse :: (split_on_aux t [])
else
split_on_aux t (h :: l)
def split_on {Ξ± : Type u} [decidable_eq Ξ±] (a : Ξ±) : list Ξ± β list (list Ξ±)
| l := split_on_aux a l []
def erase_first_such_that {Ξ± : Type u} (f : Ξ± β Prop) [decidable_pred f] : list Ξ± β list Ξ±
| [] := []
| (h :: t) := if f h then t else (h :: t.erase_first_such_that)
def erase_such_that {Ξ± : Type u} (f : Ξ± β Prop) [decidable_pred f] : list Ξ± β list Ξ± :=
filter (Ξ» x, Β¬ f x)
def strip {Ξ± : Type u} [decidable_eq Ξ±] (l : list Ξ±) (v : Ξ±) : list Ξ± :=
l.erase_such_that (Ξ» c, c = v)
def stripl {Ξ± : Type u} [decidable_eq Ξ±] (l : list Ξ±) (vs : list Ξ±) : list Ξ± :=
l.erase_such_that (Ξ» c, c β vs)
end list
def list.at {Ξ± : Type u} [inhabited Ξ±] (l : list Ξ±) (n : β) : Ξ± :=
list.head $ option.to_list $ list.nth l n
|
71c0bff6323aaa0a30bad1f4c478a162166fbe1f | cf39355caa609c0f33405126beee2739aa3cb77e | /tests/lean/1603.lean | cdf3759f918496f8b0eda12592483392968a7801 | [
"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 | 223 | lean | def some_lets : β β β β β
| 0 v := v
| (nat.succ n) v := let k := some_lets n v + v in k
def some_unfolded_lets (n : β) : β v : β , v = some_lets 5 n :=
begin
dunfold some_lets,
-- admit
end
|
5da7f1d99779b779689ae44534f0aa0b60f24838 | b7f22e51856f4989b970961f794f1c435f9b8f78 | /tests/lean/run/tactic30.lean | e2f76ad7483cd84d91725f6e90464cf042f7be67 | [
"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 | 276 | lean | import logic
open tactic
section
set_option pp.universes true
set_option pp.implicit true
variable {A : Type}
variables {a b : A}
variable H : a = b
include H
theorem test : a = b β§ a = a
:= by apply and.intro; assumption; apply eq.refl
end
check @test
|
763ac7c7506e5728e1b028da6ec6fbbf81c73f2a | 74addaa0e41490cbaf2abd313a764c96df57b05d | /Mathlib/data/multiset/finset_ops.lean | a8cfe66a1bad0b9364c323895451418469a2b62d | [] | 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 | 10,177 | 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 Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.data.multiset.erase_dup
import Mathlib.PostPort
universes u_1
namespace Mathlib
/-!
# Preparations for defining operations on `finset`.
The operations here ignore multiplicities,
and preparatory for defining the corresponding operations on `finset`.
-/
namespace multiset
/-! ### finset insert -/
/-- `ndinsert a s` is the lift of the list `insert` operation. This operation
does not respect multiplicities, unlike `cons`, but it is suitable as
an insert operation on `finset`. -/
def ndinsert {Ξ± : Type u_1} [DecidableEq Ξ±] (a : Ξ±) (s : multiset Ξ±) : multiset Ξ± :=
quot.lift_on s (fun (l : List Ξ±) => β(list.insert a l)) sorry
@[simp] theorem coe_ndinsert {Ξ± : Type u_1} [DecidableEq Ξ±] (a : Ξ±) (l : List Ξ±) : ndinsert a βl = β(insert a l) :=
rfl
@[simp] theorem ndinsert_zero {Ξ± : Type u_1} [DecidableEq Ξ±] (a : Ξ±) : ndinsert a 0 = a ::β 0 :=
rfl
@[simp] theorem ndinsert_of_mem {Ξ± : Type u_1} [DecidableEq Ξ±] {a : Ξ±} {s : multiset Ξ±} : a β s β ndinsert a s = s :=
quot.induction_on s fun (l : List Ξ±) (h : a β Quot.mk setoid.r l) => congr_arg coe (list.insert_of_mem h)
@[simp] theorem ndinsert_of_not_mem {Ξ± : Type u_1} [DecidableEq Ξ±] {a : Ξ±} {s : multiset Ξ±} : Β¬a β s β ndinsert a s = a ::β s :=
quot.induction_on s fun (l : List Ξ±) (h : Β¬a β Quot.mk setoid.r l) => congr_arg coe (list.insert_of_not_mem h)
@[simp] theorem mem_ndinsert {Ξ± : Type u_1} [DecidableEq Ξ±] {a : Ξ±} {b : Ξ±} {s : multiset Ξ±} : a β ndinsert b s β a = b β¨ a β s :=
quot.induction_on s fun (l : List Ξ±) => list.mem_insert_iff
@[simp] theorem le_ndinsert_self {Ξ± : Type u_1} [DecidableEq Ξ±] (a : Ξ±) (s : multiset Ξ±) : s β€ ndinsert a s :=
quot.induction_on s fun (l : List Ξ±) => list.sublist.subperm (list.sublist_of_suffix (list.suffix_insert a l))
@[simp] theorem mem_ndinsert_self {Ξ± : Type u_1} [DecidableEq Ξ±] (a : Ξ±) (s : multiset Ξ±) : a β ndinsert a s :=
iff.mpr mem_ndinsert (Or.inl rfl)
theorem mem_ndinsert_of_mem {Ξ± : Type u_1} [DecidableEq Ξ±] {a : Ξ±} {b : Ξ±} {s : multiset Ξ±} (h : a β s) : a β ndinsert b s :=
iff.mpr mem_ndinsert (Or.inr h)
@[simp] theorem length_ndinsert_of_mem {Ξ± : Type u_1} [DecidableEq Ξ±] {a : Ξ±} {s : multiset Ξ±} (h : a β s) : coe_fn card (ndinsert a s) = coe_fn card s := sorry
@[simp] theorem length_ndinsert_of_not_mem {Ξ± : Type u_1} [DecidableEq Ξ±] {a : Ξ±} {s : multiset Ξ±} (h : Β¬a β s) : coe_fn card (ndinsert a s) = coe_fn card s + 1 := sorry
theorem erase_dup_cons {Ξ± : Type u_1} [DecidableEq Ξ±] {a : Ξ±} {s : multiset Ξ±} : erase_dup (a ::β s) = ndinsert a (erase_dup s) := sorry
theorem nodup_ndinsert {Ξ± : Type u_1} [DecidableEq Ξ±] (a : Ξ±) {s : multiset Ξ±} : nodup s β nodup (ndinsert a s) :=
quot.induction_on s fun (l : List Ξ±) => list.nodup_insert
theorem ndinsert_le {Ξ± : Type u_1} [DecidableEq Ξ±] {a : Ξ±} {s : multiset Ξ±} {t : multiset Ξ±} : ndinsert a s β€ t β s β€ t β§ a β t := sorry
theorem attach_ndinsert {Ξ± : Type u_1} [DecidableEq Ξ±] (a : Ξ±) (s : multiset Ξ±) : attach (ndinsert a s) =
ndinsert { val := a, property := mem_ndinsert_self a s }
(map
(fun (p : Subtype fun (x : Ξ±) => x β s) =>
{ val := subtype.val p, property := mem_ndinsert_of_mem (subtype.property p) })
(attach s)) := sorry
@[simp] theorem disjoint_ndinsert_left {Ξ± : Type u_1} [DecidableEq Ξ±] {a : Ξ±} {s : multiset Ξ±} {t : multiset Ξ±} : disjoint (ndinsert a s) t β Β¬a β t β§ disjoint s t := sorry
@[simp] theorem disjoint_ndinsert_right {Ξ± : Type u_1} [DecidableEq Ξ±] {a : Ξ±} {s : multiset Ξ±} {t : multiset Ξ±} : disjoint s (ndinsert a t) β Β¬a β s β§ disjoint s t := sorry
/-! ### finset union -/
/-- `ndunion s t` is the lift of the list `union` operation. This operation
does not respect multiplicities, unlike `s βͺ t`, but it is suitable as
a union operation on `finset`. (`s βͺ t` would also work as a union operation
on finset, but this is more efficient.) -/
def ndunion {Ξ± : Type u_1} [DecidableEq Ξ±] (s : multiset Ξ±) (t : multiset Ξ±) : multiset Ξ± :=
quotient.lift_onβ s t (fun (lβ lβ : List Ξ±) => β(list.union lβ lβ)) sorry
@[simp] theorem coe_ndunion {Ξ± : Type u_1} [DecidableEq Ξ±] (lβ : List Ξ±) (lβ : List Ξ±) : ndunion βlβ βlβ = β(lβ βͺ lβ) :=
rfl
@[simp] theorem zero_ndunion {Ξ± : Type u_1} [DecidableEq Ξ±] (s : multiset Ξ±) : ndunion 0 s = s :=
quot.induction_on s fun (l : List Ξ±) => rfl
@[simp] theorem cons_ndunion {Ξ± : Type u_1} [DecidableEq Ξ±] (s : multiset Ξ±) (t : multiset Ξ±) (a : Ξ±) : ndunion (a ::β s) t = ndinsert a (ndunion s t) :=
quotient.induction_onβ s t fun (lβ lβ : List Ξ±) => rfl
@[simp] theorem mem_ndunion {Ξ± : Type u_1} [DecidableEq Ξ±] {s : multiset Ξ±} {t : multiset Ξ±} {a : Ξ±} : a β ndunion s t β a β s β¨ a β t :=
quotient.induction_onβ s t fun (lβ lβ : List Ξ±) => list.mem_union
theorem le_ndunion_right {Ξ± : Type u_1} [DecidableEq Ξ±] (s : multiset Ξ±) (t : multiset Ξ±) : t β€ ndunion s t :=
quotient.induction_onβ s t
fun (lβ lβ : List Ξ±) => list.sublist.subperm (list.sublist_of_suffix (list.suffix_union_right lβ lβ))
theorem subset_ndunion_right {Ξ± : Type u_1} [DecidableEq Ξ±] (s : multiset Ξ±) (t : multiset Ξ±) : t β ndunion s t :=
subset_of_le (le_ndunion_right s t)
theorem ndunion_le_add {Ξ± : Type u_1} [DecidableEq Ξ±] (s : multiset Ξ±) (t : multiset Ξ±) : ndunion s t β€ s + t :=
quotient.induction_onβ s t fun (lβ lβ : List Ξ±) => list.sublist.subperm (list.union_sublist_append lβ lβ)
theorem ndunion_le {Ξ± : Type u_1} [DecidableEq Ξ±] {s : multiset Ξ±} {t : multiset Ξ±} {u : multiset Ξ±} : ndunion s t β€ u β s β u β§ t β€ u := sorry
theorem subset_ndunion_left {Ξ± : Type u_1} [DecidableEq Ξ±] (s : multiset Ξ±) (t : multiset Ξ±) : s β ndunion s t :=
fun (a : Ξ±) (h : a β s) => iff.mpr mem_ndunion (Or.inl h)
theorem le_ndunion_left {Ξ± : Type u_1} [DecidableEq Ξ±] {s : multiset Ξ±} (t : multiset Ξ±) (d : nodup s) : s β€ ndunion s t :=
iff.mpr (le_iff_subset d) (subset_ndunion_left s t)
theorem ndunion_le_union {Ξ± : Type u_1} [DecidableEq Ξ±] (s : multiset Ξ±) (t : multiset Ξ±) : ndunion s t β€ s βͺ t :=
iff.mpr ndunion_le { left := subset_of_le (le_union_left s t), right := le_union_right s t }
theorem nodup_ndunion {Ξ± : Type u_1} [DecidableEq Ξ±] (s : multiset Ξ±) {t : multiset Ξ±} : nodup t β nodup (ndunion s t) :=
quotient.induction_onβ s t fun (lβ lβ : List Ξ±) => list.nodup_union lβ
@[simp] theorem ndunion_eq_union {Ξ± : Type u_1} [DecidableEq Ξ±] {s : multiset Ξ±} {t : multiset Ξ±} (d : nodup s) : ndunion s t = s βͺ t :=
le_antisymm (ndunion_le_union s t) (union_le (le_ndunion_left t d) (le_ndunion_right s t))
theorem erase_dup_add {Ξ± : Type u_1} [DecidableEq Ξ±] (s : multiset Ξ±) (t : multiset Ξ±) : erase_dup (s + t) = ndunion s (erase_dup t) :=
quotient.induction_onβ s t fun (lβ lβ : List Ξ±) => congr_arg coe (list.erase_dup_append lβ lβ)
/-! ### finset inter -/
/-- `ndinter s t` is the lift of the list `β©` operation. This operation
does not respect multiplicities, unlike `s β© t`, but it is suitable as
an intersection operation on `finset`. (`s β© t` would also work as a union operation
on finset, but this is more efficient.) -/
def ndinter {Ξ± : Type u_1} [DecidableEq Ξ±] (s : multiset Ξ±) (t : multiset Ξ±) : multiset Ξ± :=
filter (fun (_x : Ξ±) => _x β t) s
@[simp] theorem coe_ndinter {Ξ± : Type u_1} [DecidableEq Ξ±] (lβ : List Ξ±) (lβ : List Ξ±) : ndinter βlβ βlβ = β(lβ β© lβ) :=
rfl
@[simp] theorem zero_ndinter {Ξ± : Type u_1} [DecidableEq Ξ±] (s : multiset Ξ±) : ndinter 0 s = 0 :=
rfl
@[simp] theorem cons_ndinter_of_mem {Ξ± : Type u_1} [DecidableEq Ξ±] {a : Ξ±} (s : multiset Ξ±) {t : multiset Ξ±} (h : a β t) : ndinter (a ::β s) t = a ::β ndinter s t := sorry
@[simp] theorem ndinter_cons_of_not_mem {Ξ± : Type u_1} [DecidableEq Ξ±] {a : Ξ±} (s : multiset Ξ±) {t : multiset Ξ±} (h : Β¬a β t) : ndinter (a ::β s) t = ndinter s t := sorry
@[simp] theorem mem_ndinter {Ξ± : Type u_1} [DecidableEq Ξ±] {s : multiset Ξ±} {t : multiset Ξ±} {a : Ξ±} : a β ndinter s t β a β s β§ a β t :=
mem_filter
@[simp] theorem nodup_ndinter {Ξ± : Type u_1} [DecidableEq Ξ±] {s : multiset Ξ±} (t : multiset Ξ±) : nodup s β nodup (ndinter s t) :=
nodup_filter fun (_x : Ξ±) => _x β t
theorem le_ndinter {Ξ± : Type u_1} [DecidableEq Ξ±] {s : multiset Ξ±} {t : multiset Ξ±} {u : multiset Ξ±} : s β€ ndinter t u β s β€ t β§ s β u := sorry
theorem ndinter_le_left {Ξ± : Type u_1} [DecidableEq Ξ±] (s : multiset Ξ±) (t : multiset Ξ±) : ndinter s t β€ s :=
and.left (iff.mp le_ndinter (le_refl (ndinter s t)))
theorem ndinter_subset_left {Ξ± : Type u_1} [DecidableEq Ξ±] (s : multiset Ξ±) (t : multiset Ξ±) : ndinter s t β s :=
subset_of_le (ndinter_le_left s t)
theorem ndinter_subset_right {Ξ± : Type u_1} [DecidableEq Ξ±] (s : multiset Ξ±) (t : multiset Ξ±) : ndinter s t β t :=
and.right (iff.mp le_ndinter (le_refl (ndinter s t)))
theorem ndinter_le_right {Ξ± : Type u_1} [DecidableEq Ξ±] {s : multiset Ξ±} (t : multiset Ξ±) (d : nodup s) : ndinter s t β€ t :=
iff.mpr (le_iff_subset (nodup_ndinter t d)) (ndinter_subset_right s t)
theorem inter_le_ndinter {Ξ± : Type u_1} [DecidableEq Ξ±] (s : multiset Ξ±) (t : multiset Ξ±) : s β© t β€ ndinter s t :=
iff.mpr le_ndinter { left := inter_le_left s t, right := subset_of_le (inter_le_right s t) }
@[simp] theorem ndinter_eq_inter {Ξ± : Type u_1} [DecidableEq Ξ±] {s : multiset Ξ±} {t : multiset Ξ±} (d : nodup s) : ndinter s t = s β© t :=
le_antisymm (le_inter (ndinter_le_left s t) (ndinter_le_right t d)) (inter_le_ndinter s t)
theorem ndinter_eq_zero_iff_disjoint {Ξ± : Type u_1} [DecidableEq Ξ±] {s : multiset Ξ±} {t : multiset Ξ±} : ndinter s t = 0 β disjoint s t := sorry
|
a7ecca6622094192e83f909e2c00e84b8972c384 | 94e33a31faa76775069b071adea97e86e218a8ee | /src/topology/continuous_on.lean | 33faa2bdbcd2ec601fa65675e3c121ee44d6e65d | [
"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 | 54,388 | lean | /-
Copyright (c) 2019 Reid Barton. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: SΓ©bastien GouΓ«zel
-/
import topology.constructions
/-!
# Neighborhoods and continuity relative to a subset
This file defines relative versions
* `nhds_within` of `nhds`
* `continuous_on` of `continuous`
* `continuous_within_at` of `continuous_at`
and proves their basic properties, including the relationships between
these restricted notions and the corresponding notions for the subtype
equipped with the subspace topology.
## Notation
* `π x`: the filter of neighborhoods of a point `x`;
* `π s`: the principal filter of a set `s`;
* `π[s] x`: the filter `nhds_within x s` of neighborhoods of a point `x` within a set `s`.
-/
open set filter function
open_locale topological_space filter
variables {Ξ± : Type*} {Ξ² : Type*} {Ξ³ : Type*} {Ξ΄ : Type*}
variables [topological_space Ξ±]
@[simp] lemma nhds_bind_nhds_within {a : Ξ±} {s : set Ξ±} :
(π a).bind (Ξ» x, π[s] x) = π[s] a :=
bind_inf_principal.trans $ congr_arg2 _ nhds_bind_nhds rfl
@[simp] lemma eventually_nhds_nhds_within {a : Ξ±} {s : set Ξ±} {p : Ξ± β Prop} :
(βαΆ y in π a, βαΆ x in π[s] y, p x) β βαΆ x in π[s] a, p x :=
filter.ext_iff.1 nhds_bind_nhds_within {x | p x}
lemma eventually_nhds_within_iff {a : Ξ±} {s : set Ξ±} {p : Ξ± β Prop} :
(βαΆ x in π[s] a, p x) β βαΆ x in π a, x β s β p x :=
eventually_inf_principal
@[simp] lemma eventually_nhds_within_nhds_within {a : Ξ±} {s : set Ξ±} {p : Ξ± β Prop} :
(βαΆ y in π[s] a, βαΆ x in π[s] y, p x) β βαΆ x in π[s] a, p x :=
begin
refine β¨Ξ» h, _, Ξ» h, (eventually_nhds_nhds_within.2 h).filter_mono inf_le_leftβ©,
simp only [eventually_nhds_within_iff] at h β’,
exact h.mono (Ξ» x hx hxs, (hx hxs).self_of_nhds hxs)
end
theorem nhds_within_eq (a : Ξ±) (s : set Ξ±) :
π[s] a = β¨
t β {t : set Ξ± | a β t β§ is_open t}, π (t β© s) :=
((nhds_basis_opens a).inf_principal s).eq_binfi
theorem nhds_within_univ (a : Ξ±) : π[set.univ] a = π a :=
by rw [nhds_within, principal_univ, inf_top_eq]
lemma nhds_within_has_basis {p : Ξ² β Prop} {s : Ξ² β set Ξ±} {a : Ξ±} (h : (π a).has_basis p s)
(t : set Ξ±) :
(π[t] a).has_basis p (Ξ» i, s i β© t) :=
h.inf_principal t
lemma nhds_within_basis_open (a : Ξ±) (t : set Ξ±) :
(π[t] a).has_basis (Ξ» u, a β u β§ is_open u) (Ξ» u, u β© t) :=
nhds_within_has_basis (nhds_basis_opens a) t
theorem mem_nhds_within {t : set Ξ±} {a : Ξ±} {s : set Ξ±} :
t β π[s] a β β u, is_open u β§ a β u β§ u β© s β t :=
by simpa only [exists_prop, and_assoc, and_comm] using (nhds_within_basis_open a s).mem_iff
lemma mem_nhds_within_iff_exists_mem_nhds_inter {t : set Ξ±} {a : Ξ±} {s : set Ξ±} :
t β π[s] a β β u β π a, u β© s β t :=
(nhds_within_has_basis (π a).basis_sets s).mem_iff
lemma diff_mem_nhds_within_compl {x : Ξ±} {s : set Ξ±} (hs : s β π x) (t : set Ξ±) :
s \ t β π[tαΆ] x :=
diff_mem_inf_principal_compl hs t
lemma diff_mem_nhds_within_diff {x : Ξ±} {s t : set Ξ±} (hs : s β π[t] x) (t' : set Ξ±) :
s \ t' β π[t \ t'] x :=
begin
rw [nhds_within, diff_eq, diff_eq, β inf_principal, β inf_assoc],
exact inter_mem_inf hs (mem_principal_self _)
end
lemma nhds_of_nhds_within_of_nhds
{s t : set Ξ±} {a : Ξ±} (h1 : s β π a) (h2 : t β π[s] a) : (t β π a) :=
begin
rcases mem_nhds_within_iff_exists_mem_nhds_inter.mp h2 with β¨_, Hw, hwβ©,
exact (nhds a).sets_of_superset ((nhds a).inter_sets Hw h1) hw,
end
lemma mem_nhds_within_iff_eventually {s t : set Ξ±} {x : Ξ±} :
t β π[s] x β βαΆ y in π x, y β s β y β t :=
begin
rw [mem_nhds_within_iff_exists_mem_nhds_inter],
split,
{ rintro β¨u, hu, hutβ©, exact eventually_of_mem hu (Ξ» x hxu hxs, hut β¨hxu, hxsβ©) },
{ refine Ξ» h, β¨_, h, Ξ» y hy, hy.1 hy.2β© }
end
lemma mem_nhds_within_iff_eventually_eq {s t : set Ξ±} {x : Ξ±} :
t β π[s] x β s =αΆ [π x] (s β© t : set Ξ±) :=
by simp_rw [mem_nhds_within_iff_eventually, eventually_eq_set, mem_inter_iff, iff_self_and]
lemma nhds_within_eq_iff_eventually_eq {s t : set Ξ±} {x : Ξ±} : π[s] x = π[t] x β s =αΆ [π x] t :=
begin
simp_rw [filter.ext_iff, mem_nhds_within_iff_eventually, eventually_eq_set],
split,
{ intro h,
filter_upwards [(h t).mpr (eventually_of_forall $ Ξ» x, id),
(h s).mp (eventually_of_forall $ Ξ» x, id)],
exact Ξ» x, iff.intro, },
{ refine Ξ» h u, eventually_congr (h.mono $ Ξ» x h, _), rw [h] }
end
lemma nhds_within_le_iff {s t : set Ξ±} {x : Ξ±} : π[s] x β€ π[t] x β t β π[s] x :=
begin
simp_rw [filter.le_def, mem_nhds_within_iff_eventually],
split,
{ exact Ξ» h, (h t $ eventually_of_forall (Ξ» x, id)).mono (Ξ» x, id) },
{ exact Ξ» h u hu, (h.and hu).mono (Ξ» x hx h, hx.2 $ hx.1 h) }
end
lemma preimage_nhds_within_coinduced' {Ο : Ξ± β Ξ²} {s : set Ξ²} {t : set Ξ±} {a : Ξ±}
(h : a β t) (ht : is_open t)
(hs : s β @nhds Ξ² (topological_space.coinduced (Ξ» x : t, Ο x) subtype.topological_space) (Ο a)) :
Ο β»ΒΉ' s β π[t] a :=
begin
letI := topological_space.coinduced (Ξ» x : t, Ο x) subtype.topological_space,
rcases mem_nhds_iff.mp hs with β¨V, hVs, V_op, mem_Vβ©,
refine mem_nhds_within_iff_exists_mem_nhds_inter.mpr β¨Ο β»ΒΉ' V, mem_nhds_iff.mpr β¨t β© Ο β»ΒΉ' V,
inter_subset_right t (Ο β»ΒΉ' V), _, mem_sep h mem_Vβ©, subset.trans (inter_subset_left _ _)
(preimage_mono hVs)β©,
obtain β¨u, hu1, hu2β© := is_open_induced_iff.mp (is_open_coinduced.1 V_op),
rw [preimage_comp] at hu2,
rw [set.inter_comm, β(subtype.preimage_coe_eq_preimage_coe_iff.mp hu2)],
exact hu1.inter ht,
end
lemma mem_nhds_within_of_mem_nhds {s t : set Ξ±} {a : Ξ±} (h : s β π a) :
s β π[t] a :=
mem_inf_of_left h
theorem self_mem_nhds_within {a : Ξ±} {s : set Ξ±} : s β π[s] a :=
mem_inf_of_right (mem_principal_self s)
theorem eventually_mem_nhds_within {a : Ξ±} {s : set Ξ±} : βαΆ x in π[s] a, x β s :=
self_mem_nhds_within
theorem inter_mem_nhds_within (s : set Ξ±) {t : set Ξ±} {a : Ξ±} (h : t β π a) :
s β© t β π[s] a :=
inter_mem self_mem_nhds_within (mem_inf_of_left h)
theorem nhds_within_mono (a : Ξ±) {s t : set Ξ±} (h : s β t) : π[s] a β€ π[t] a :=
inf_le_inf_left _ (principal_mono.mpr h)
lemma pure_le_nhds_within {a : Ξ±} {s : set Ξ±} (ha : a β s) : pure a β€ π[s] a :=
le_inf (pure_le_nhds a) (le_principal_iff.2 ha)
lemma mem_of_mem_nhds_within {a : Ξ±} {s t : set Ξ±} (ha : a β s) (ht : t β π[s] a) :
a β t :=
pure_le_nhds_within ha ht
lemma filter.eventually.self_of_nhds_within {p : Ξ± β Prop} {s : set Ξ±} {x : Ξ±}
(h : βαΆ y in π[s] x, p y) (hx : x β s) : p x :=
mem_of_mem_nhds_within hx h
lemma tendsto_const_nhds_within {l : filter Ξ²} {s : set Ξ±} {a : Ξ±} (ha : a β s) :
tendsto (Ξ» x : Ξ², a) l (π[s] a) :=
tendsto_const_pure.mono_right $ pure_le_nhds_within ha
theorem nhds_within_restrict'' {a : Ξ±} (s : set Ξ±) {t : set Ξ±} (h : t β π[s] a) :
π[s] a = π[s β© t] a :=
le_antisymm
(le_inf inf_le_left (le_principal_iff.mpr (inter_mem self_mem_nhds_within h)))
(inf_le_inf_left _ (principal_mono.mpr (set.inter_subset_left _ _)))
theorem nhds_within_restrict' {a : Ξ±} (s : set Ξ±) {t : set Ξ±} (h : t β π a) :
π[s] a = π[s β© t] a :=
nhds_within_restrict'' s $ mem_inf_of_left h
theorem nhds_within_restrict {a : Ξ±} (s : set Ξ±) {t : set Ξ±} (hβ : a β t) (hβ : is_open t) :
π[s] a = π[s β© t] a :=
nhds_within_restrict' s (is_open.mem_nhds hβ hβ)
theorem nhds_within_le_of_mem {a : Ξ±} {s t : set Ξ±} (h : s β π[t] a) :
π[t] a β€ π[s] a :=
nhds_within_le_iff.mpr h
theorem nhds_within_le_nhds {a : Ξ±} {s : set Ξ±} : π[s] a β€ π a :=
by { rw β nhds_within_univ, apply nhds_within_le_of_mem, exact univ_mem }
lemma nhds_within_eq_nhds_within' {a : Ξ±} {s t u : set Ξ±}
(hs : s β π a) (hβ : t β© s = u β© s) : π[t] a = π[u] a :=
by rw [nhds_within_restrict' t hs, nhds_within_restrict' u hs, hβ]
theorem nhds_within_eq_nhds_within {a : Ξ±} {s t u : set Ξ±}
(hβ : a β s) (hβ : is_open s) (hβ : t β© s = u β© s) :
π[t] a = π[u] a :=
by rw [nhds_within_restrict t hβ hβ, nhds_within_restrict u hβ hβ, hβ]
theorem is_open.nhds_within_eq {a : Ξ±} {s : set Ξ±} (h : is_open s) (ha : a β s) :
π[s] a = π a :=
inf_eq_left.2 $ le_principal_iff.2 $ is_open.mem_nhds h ha
lemma preimage_nhds_within_coinduced {Ο : Ξ± β Ξ²} {s : set Ξ²} {t : set Ξ±} {a : Ξ±}
(h : a β t) (ht : is_open t)
(hs : s β @nhds Ξ² (topological_space.coinduced (Ξ» x : t, Ο x) subtype.topological_space) (Ο a)) :
Ο β»ΒΉ' s β π a :=
by { rw β ht.nhds_within_eq h, exact preimage_nhds_within_coinduced' h ht hs }
@[simp] theorem nhds_within_empty (a : Ξ±) : π[β
] a = β₯ :=
by rw [nhds_within, principal_empty, inf_bot_eq]
theorem nhds_within_union (a : Ξ±) (s t : set Ξ±) :
π[s βͺ t] a = π[s] a β π[t] a :=
by { delta nhds_within, rw [βinf_sup_left, sup_principal] }
theorem nhds_within_inter (a : Ξ±) (s t : set Ξ±) :
π[s β© t] a = π[s] a β π[t] a :=
by { delta nhds_within, rw [inf_left_comm, inf_assoc, inf_principal, βinf_assoc, inf_idem] }
theorem nhds_within_inter' (a : Ξ±) (s t : set Ξ±) :
π[s β© t] a = (π[s] a) β π t :=
by { delta nhds_within, rw [βinf_principal, inf_assoc] }
theorem nhds_within_inter_of_mem {a : Ξ±} {s t : set Ξ±} (h : s β π[t] a) :
π[s β© t] a = π[t] a :=
by { rw [nhds_within_inter, inf_eq_right], exact nhds_within_le_of_mem h }
@[simp] theorem nhds_within_singleton (a : Ξ±) : π[{a}] a = pure a :=
by rw [nhds_within, principal_singleton, inf_eq_right.2 (pure_le_nhds a)]
@[simp] theorem nhds_within_insert (a : Ξ±) (s : set Ξ±) :
π[insert a s] a = pure a β π[s] a :=
by rw [β singleton_union, nhds_within_union, nhds_within_singleton]
lemma mem_nhds_within_insert {a : Ξ±} {s t : set Ξ±} :
t β π[insert a s] a β a β t β§ t β π[s] a :=
by simp
lemma insert_mem_nhds_within_insert {a : Ξ±} {s t : set Ξ±} (h : t β π[s] a) :
insert a t β π[insert a s] a :=
by simp [mem_of_superset h]
lemma insert_mem_nhds_iff {a : Ξ±} {s : set Ξ±} : insert a s β π a β s β π[β ] a :=
by simp only [nhds_within, mem_inf_principal, mem_compl_iff, mem_singleton_iff,
or_iff_not_imp_left, insert_def]
@[simp] theorem nhds_within_compl_singleton_sup_pure (a : Ξ±) : π[β ] a β pure a = π a :=
by rw [β nhds_within_singleton, β nhds_within_union, compl_union_self, nhds_within_univ]
lemma nhds_within_prod_eq {Ξ± : Type*} [topological_space Ξ±] {Ξ² : Type*} [topological_space Ξ²]
(a : Ξ±) (b : Ξ²) (s : set Ξ±) (t : set Ξ²) :
π[s ΓΛ’ t] (a, b) = π[s] a ΓαΆ π[t] b :=
by { delta nhds_within, rw [nhds_prod_eq, βfilter.prod_inf_prod, filter.prod_principal_principal] }
lemma nhds_within_prod {Ξ± : Type*} [topological_space Ξ±] {Ξ² : Type*} [topological_space Ξ²]
{s u : set Ξ±} {t v : set Ξ²} {a : Ξ±} {b : Ξ²}
(hu : u β π[s] a) (hv : v β π[t] b) :
(u ΓΛ’ v) β π[s ΓΛ’ t] (a, b) :=
by { rw nhds_within_prod_eq, exact prod_mem_prod hu hv, }
lemma nhds_within_pi_eq' {ΞΉ : Type*} {Ξ± : ΞΉ β Type*} [Ξ i, topological_space (Ξ± i)]
{I : set ΞΉ} (hI : I.finite) (s : Ξ i, set (Ξ± i)) (x : Ξ i, Ξ± i) :
π[pi I s] x = β¨
i, comap (Ξ» x, x i) (π (x i) β β¨
(hi : i β I), π (s i)) :=
by simp only [nhds_within, nhds_pi, filter.pi, comap_inf, comap_infi, pi_def, comap_principal,
β infi_principal_finite hI, β infi_inf_eq]
lemma nhds_within_pi_eq {ΞΉ : Type*} {Ξ± : ΞΉ β Type*} [Ξ i, topological_space (Ξ± i)]
{I : set ΞΉ} (hI : I.finite) (s : Ξ i, set (Ξ± i)) (x : Ξ i, Ξ± i) :
π[pi I s] x = (β¨
i β I, comap (Ξ» x, x i) (π[s i] (x i))) β
β¨
(i β I), comap (Ξ» x, x i) (π (x i)) :=
begin
simp only [nhds_within, nhds_pi, filter.pi, pi_def, β infi_principal_finite hI, comap_inf,
comap_principal, eval],
rw [infi_split _ (Ξ» i, i β I), inf_right_comm],
simp only [infi_inf_eq]
end
lemma nhds_within_pi_univ_eq {ΞΉ : Type*} {Ξ± : ΞΉ β Type*} [fintype ΞΉ] [Ξ i, topological_space (Ξ± i)]
(s : Ξ i, set (Ξ± i)) (x : Ξ i, Ξ± i) :
π[pi univ s] x = β¨
i, comap (Ξ» x, x i) π[s i] (x i) :=
by simpa [nhds_within] using nhds_within_pi_eq finite_univ s x
lemma nhds_within_pi_eq_bot {ΞΉ : Type*} {Ξ± : ΞΉ β Type*} [Ξ i, topological_space (Ξ± i)]
{I : set ΞΉ} {s : Ξ i, set (Ξ± i)} {x : Ξ i, Ξ± i} :
π[pi I s] x = β₯ β β i β I, π[s i] (x i) = β₯ :=
by simp only [nhds_within, nhds_pi, pi_inf_principal_pi_eq_bot]
lemma nhds_within_pi_ne_bot {ΞΉ : Type*} {Ξ± : ΞΉ β Type*} [Ξ i, topological_space (Ξ± i)]
{I : set ΞΉ} {s : Ξ i, set (Ξ± i)} {x : Ξ i, Ξ± i} :
(π[pi I s] x).ne_bot β β i β I, (π[s i] (x i)).ne_bot :=
by simp [ne_bot_iff, nhds_within_pi_eq_bot]
theorem filter.tendsto.piecewise_nhds_within {f g : Ξ± β Ξ²} {t : set Ξ±} [β x, decidable (x β t)]
{a : Ξ±} {s : set Ξ±} {l : filter Ξ²}
(hβ : tendsto f (π[s β© t] a) l) (hβ : tendsto g (π[s β© tαΆ] a) l) :
tendsto (piecewise t f g) (π[s] a) l :=
by apply tendsto.piecewise; rwa β nhds_within_inter'
theorem filter.tendsto.if_nhds_within {f g : Ξ± β Ξ²} {p : Ξ± β Prop} [decidable_pred p]
{a : Ξ±} {s : set Ξ±} {l : filter Ξ²}
(hβ : tendsto f (π[s β© {x | p x}] a) l)
(hβ : tendsto g (π[s β© {x | Β¬ p x}] a) l) :
tendsto (Ξ» x, if p x then f x else g x) (π[s] a) l :=
hβ.piecewise_nhds_within hβ
lemma map_nhds_within (f : Ξ± β Ξ²) (a : Ξ±) (s : set Ξ±) :
map f (π[s] a) = β¨
t β {t : set Ξ± | a β t β§ is_open t}, π (f '' (t β© s)) :=
((nhds_within_basis_open a s).map f).eq_binfi
theorem tendsto_nhds_within_mono_left {f : Ξ± β Ξ²} {a : Ξ±}
{s t : set Ξ±} {l : filter Ξ²} (hst : s β t) (h : tendsto f (π[t] a) l) :
tendsto f (π[s] a) l :=
h.mono_left $ nhds_within_mono a hst
theorem tendsto_nhds_within_mono_right {f : Ξ² β Ξ±} {l : filter Ξ²}
{a : Ξ±} {s t : set Ξ±} (hst : s β t) (h : tendsto f l (π[s] a)) :
tendsto f l (π[t] a) :=
h.mono_right (nhds_within_mono a hst)
theorem tendsto_nhds_within_of_tendsto_nhds {f : Ξ± β Ξ²} {a : Ξ±}
{s : set Ξ±} {l : filter Ξ²} (h : tendsto f (π a) l) :
tendsto f (π[s] a) l :=
h.mono_left inf_le_left
theorem principal_subtype {Ξ± : Type*} (s : set Ξ±) (t : set {x // x β s}) :
π t = comap coe (π ((coe : s β Ξ±) '' t)) :=
by rw [comap_principal, set.preimage_image_eq _ subtype.coe_injective]
lemma nhds_within_ne_bot_of_mem {s : set Ξ±} {x : Ξ±} (hx : x β s) :
ne_bot (π[s] x) :=
mem_closure_iff_nhds_within_ne_bot.1 $ subset_closure hx
lemma is_closed.mem_of_nhds_within_ne_bot {s : set Ξ±} (hs : is_closed s)
{x : Ξ±} (hx : ne_bot $ π[s] x) : x β s :=
by simpa only [hs.closure_eq] using mem_closure_iff_nhds_within_ne_bot.2 hx
lemma dense_range.nhds_within_ne_bot {ΞΉ : Type*} {f : ΞΉ β Ξ±} (h : dense_range f) (x : Ξ±) :
ne_bot (π[range f] x) :=
mem_closure_iff_cluster_pt.1 (h x)
lemma mem_closure_pi {ΞΉ : Type*} {Ξ± : ΞΉ β Type*} [Ξ i, topological_space (Ξ± i)]
{I : set ΞΉ} {s : Ξ i, set (Ξ± i)} {x : Ξ i, Ξ± i} :
x β closure (pi I s) β β i β I, x i β closure (s i) :=
by simp only [mem_closure_iff_nhds_within_ne_bot, nhds_within_pi_ne_bot]
lemma closure_pi_set {ΞΉ : Type*} {Ξ± : ΞΉ β Type*} [Ξ i, topological_space (Ξ± i)]
(I : set ΞΉ) (s : Ξ i, set (Ξ± i)) :
closure (pi I s) = pi I (Ξ» i, closure (s i)) :=
set.ext $ Ξ» x, mem_closure_pi
lemma dense_pi {ΞΉ : Type*} {Ξ± : ΞΉ β Type*} [Ξ i, topological_space (Ξ± i)] {s : Ξ i, set (Ξ± i)}
(I : set ΞΉ) (hs : β i β I, dense (s i)) :
dense (pi I s) :=
by simp only [dense_iff_closure_eq, closure_pi_set,
pi_congr rfl (Ξ» i hi, (hs i hi).closure_eq), pi_univ]
lemma eventually_eq_nhds_within_iff {f g : Ξ± β Ξ²} {s : set Ξ±} {a : Ξ±} :
(f =αΆ [π[s] a] g) β βαΆ x in π a, x β s β f x = g x :=
mem_inf_principal
lemma eventually_eq_nhds_within_of_eq_on {f g : Ξ± β Ξ²} {s : set Ξ±} {a : Ξ±} (h : eq_on f g s) :
f =αΆ [π[s] a] g :=
mem_inf_of_right h
lemma set.eq_on.eventually_eq_nhds_within {f g : Ξ± β Ξ²} {s : set Ξ±} {a : Ξ±} (h : eq_on f g s) :
f =αΆ [π[s] a] g :=
eventually_eq_nhds_within_of_eq_on h
lemma tendsto_nhds_within_congr {f g : Ξ± β Ξ²} {s : set Ξ±} {a : Ξ±} {l : filter Ξ²}
(hfg : β x β s, f x = g x) (hf : tendsto f (π[s] a) l) : tendsto g (π[s] a) l :=
(tendsto_congr' $ eventually_eq_nhds_within_of_eq_on hfg).1 hf
lemma eventually_nhds_within_of_forall {s : set Ξ±} {a : Ξ±} {p : Ξ± β Prop} (h : β x β s, p x) :
βαΆ x in π[s] a, p x :=
mem_inf_of_right h
lemma tendsto_nhds_within_of_tendsto_nhds_of_eventually_within {a : Ξ±} {l : filter Ξ²}
{s : set Ξ±} (f : Ξ² β Ξ±) (h1 : tendsto f l (π a)) (h2 : βαΆ x in l, f x β s) :
tendsto f l (π[s] a) :=
tendsto_inf.2 β¨h1, tendsto_principal.2 h2β©
@[simp] lemma tendsto_nhds_within_range {a : Ξ±} {l : filter Ξ²} {f : Ξ² β Ξ±} :
tendsto f l (π[range f] a) β tendsto f l (π a) :=
β¨Ξ» h, h.mono_right inf_le_left, Ξ» h, tendsto_inf.2
β¨h, tendsto_principal.2 $ eventually_of_forall mem_range_selfβ©β©
lemma filter.eventually_eq.eq_of_nhds_within {s : set Ξ±} {f g : Ξ± β Ξ²} {a : Ξ±}
(h : f =αΆ [π[s] a] g) (hmem : a β s) : f a = g a :=
h.self_of_nhds_within hmem
lemma eventually_nhds_within_of_eventually_nhds {Ξ± : Type*} [topological_space Ξ±]
{s : set Ξ±} {a : Ξ±} {p : Ξ± β Prop} (h : βαΆ x in π a, p x) :
βαΆ x in π[s] a, p x :=
mem_nhds_within_of_mem_nhds h
/-!
### `nhds_within` and subtypes
-/
theorem mem_nhds_within_subtype {s : set Ξ±} {a : {x // x β s}} {t u : set {x // x β s}} :
t β π[u] a β t β comap (coe : s β Ξ±) (π[coe '' u] a) :=
by rw [nhds_within, nhds_subtype, principal_subtype, βcomap_inf, βnhds_within]
theorem nhds_within_subtype (s : set Ξ±) (a : {x // x β s}) (t : set {x // x β s}) :
π[t] a = comap (coe : s β Ξ±) (π[coe '' t] a) :=
filter.ext $ Ξ» u, mem_nhds_within_subtype
theorem nhds_within_eq_map_subtype_coe {s : set Ξ±} {a : Ξ±} (h : a β s) :
π[s] a = map (coe : s β Ξ±) (π β¨a, hβ©) :=
by simpa only [subtype.range_coe] using (embedding_subtype_coe.map_nhds_eq β¨a, hβ©).symm
theorem mem_nhds_subtype_iff_nhds_within {s : set Ξ±} {a : s} {t : set s} :
t β π a β coe '' t β π[s] (a : Ξ±) :=
by rw [nhds_within_eq_map_subtype_coe a.coe_prop, mem_map,
preimage_image_eq _ subtype.coe_injective, subtype.coe_eta]
theorem preimage_coe_mem_nhds_subtype {s t : set Ξ±} {a : s} :
coe β»ΒΉ' t β π a β t β π[s] βa :=
by simp only [mem_nhds_subtype_iff_nhds_within, subtype.image_preimage_coe, inter_mem_iff,
self_mem_nhds_within, and_true]
theorem tendsto_nhds_within_iff_subtype {s : set Ξ±} {a : Ξ±} (h : a β s) (f : Ξ± β Ξ²) (l : filter Ξ²) :
tendsto f (π[s] a) l β tendsto (s.restrict f) (π β¨a, hβ©) l :=
by simp only [tendsto, nhds_within_eq_map_subtype_coe h, filter.map_map, restrict]
variables [topological_space Ξ²] [topological_space Ξ³] [topological_space Ξ΄]
/-- A function between topological spaces is continuous at a point `xβ` within a subset `s`
if `f x` tends to `f xβ` when `x` tends to `xβ` while staying within `s`. -/
def continuous_within_at (f : Ξ± β Ξ²) (s : set Ξ±) (x : Ξ±) : Prop :=
tendsto f (π[s] x) (π (f x))
/-- If a function is continuous within `s` at `x`, then it tends to `f x` within `s` by definition.
We register this fact for use with the dot notation, especially to use `tendsto.comp` as
`continuous_within_at.comp` will have a different meaning. -/
lemma continuous_within_at.tendsto {f : Ξ± β Ξ²} {s : set Ξ±} {x : Ξ±}
(h : continuous_within_at f s x) :
tendsto f (π[s] x) (π (f x)) := h
/-- A function between topological spaces is continuous on a subset `s`
when it's continuous at every point of `s` within `s`. -/
def continuous_on (f : Ξ± β Ξ²) (s : set Ξ±) : Prop := β x β s, continuous_within_at f s x
lemma continuous_on.continuous_within_at {f : Ξ± β Ξ²} {s : set Ξ±} {x : Ξ±} (hf : continuous_on f s)
(hx : x β s) : continuous_within_at f s x :=
hf x hx
theorem continuous_within_at_univ (f : Ξ± β Ξ²) (x : Ξ±) :
continuous_within_at f set.univ x β continuous_at f x :=
by rw [continuous_at, continuous_within_at, nhds_within_univ]
theorem continuous_within_at_iff_continuous_at_restrict (f : Ξ± β Ξ²) {x : Ξ±} {s : set Ξ±}
(h : x β s) :
continuous_within_at f s x β continuous_at (s.restrict f) β¨x, hβ© :=
tendsto_nhds_within_iff_subtype h f _
theorem continuous_within_at.tendsto_nhds_within {f : Ξ± β Ξ²} {x : Ξ±} {s : set Ξ±} {t : set Ξ²}
(h : continuous_within_at f s x) (ht : maps_to f s t) :
tendsto f (π[s] x) (π[t] (f x)) :=
tendsto_inf.2 β¨h, tendsto_principal.2 $ mem_inf_of_right $ mem_principal.2 $ htβ©
theorem continuous_within_at.tendsto_nhds_within_image {f : Ξ± β Ξ²} {x : Ξ±} {s : set Ξ±}
(h : continuous_within_at f s x) :
tendsto f (π[s] x) (π[f '' s] (f x)) :=
h.tendsto_nhds_within (maps_to_image _ _)
lemma continuous_within_at.prod_map {f : Ξ± β Ξ³} {g : Ξ² β Ξ΄} {s : set Ξ±} {t : set Ξ²}
{x : Ξ±} {y : Ξ²}
(hf : continuous_within_at f s x) (hg : continuous_within_at g t y) :
continuous_within_at (prod.map f g) (s ΓΛ’ t) (x, y) :=
begin
unfold continuous_within_at at *,
rw [nhds_within_prod_eq, prod.map, nhds_prod_eq],
exact hf.prod_map hg,
end
lemma continuous_within_at_pi {ΞΉ : Type*} {Ο : ΞΉ β Type*} [β i, topological_space (Ο i)]
{f : Ξ± β Ξ i, Ο i} {s : set Ξ±} {x : Ξ±} :
continuous_within_at f s x β β i, continuous_within_at (Ξ» y, f y i) s x :=
tendsto_pi_nhds
lemma continuous_on_pi {ΞΉ : Type*} {Ο : ΞΉ β Type*} [β i, topological_space (Ο i)]
{f : Ξ± β Ξ i, Ο i} {s : set Ξ±} :
continuous_on f s β β i, continuous_on (Ξ» y, f y i) s :=
β¨Ξ» h i x hx, tendsto_pi_nhds.1 (h x hx) i, Ξ» h x hx, tendsto_pi_nhds.2 (Ξ» i, h i x hx)β©
lemma continuous_within_at.fin_insert_nth {n} {Ο : fin (n + 1) β Type*}
[Ξ i, topological_space (Ο i)] (i : fin (n + 1)) {f : Ξ± β Ο i} {a : Ξ±} {s : set Ξ±}
(hf : continuous_within_at f s a)
{g : Ξ± β Ξ j : fin n, Ο (i.succ_above j)} (hg : continuous_within_at g s a) :
continuous_within_at (Ξ» a, i.insert_nth (f a) (g a)) s a :=
hf.fin_insert_nth i hg
lemma continuous_on.fin_insert_nth {n} {Ο : fin (n + 1) β Type*} [Ξ i, topological_space (Ο i)]
(i : fin (n + 1)) {f : Ξ± β Ο i} {s : set Ξ±} (hf : continuous_on f s)
{g : Ξ± β Ξ j : fin n, Ο (i.succ_above j)} (hg : continuous_on g s) :
continuous_on (Ξ» a, i.insert_nth (f a) (g a)) s :=
Ξ» a ha, (hf a ha).fin_insert_nth i (hg a ha)
theorem continuous_on_iff {f : Ξ± β Ξ²} {s : set Ξ±} :
continuous_on f s β β x β s, β t : set Ξ², is_open t β f x β t β β u, is_open u β§ x β u β§
u β© s β f β»ΒΉ' t :=
by simp only [continuous_on, continuous_within_at, tendsto_nhds, mem_nhds_within]
theorem continuous_on_iff_continuous_restrict {f : Ξ± β Ξ²} {s : set Ξ±} :
continuous_on f s β continuous (s.restrict f) :=
begin
rw [continuous_on, continuous_iff_continuous_at], split,
{ rintros h β¨x, xsβ©,
exact (continuous_within_at_iff_continuous_at_restrict f xs).mp (h x xs) },
intros h x xs,
exact (continuous_within_at_iff_continuous_at_restrict f xs).mpr (h β¨x, xsβ©)
end
theorem continuous_on_iff' {f : Ξ± β Ξ²} {s : set Ξ±} :
continuous_on f s β β t : set Ξ², is_open t β β u, is_open u β§ f β»ΒΉ' t β© s = u β© s :=
have β t, is_open (s.restrict f β»ΒΉ' t) β β (u : set Ξ±), is_open u β§ f β»ΒΉ' t β© s = u β© s,
begin
intro t,
rw [is_open_induced_iff, set.restrict_eq, set.preimage_comp],
simp only [subtype.preimage_coe_eq_preimage_coe_iff],
split; { rintros β¨u, ou, useqβ©, exact β¨u, ou, useq.symmβ© }
end,
by rw [continuous_on_iff_continuous_restrict, continuous_def]; simp only [this]
/-- If a function is continuous on a set for some topologies, then it is
continuous on the same set with respect to any finer topology on the source space. -/
lemma continuous_on.mono_dom {Ξ± Ξ² : Type*} {tβ tβ : topological_space Ξ±} {tβ : topological_space Ξ²}
(hβ : tβ β€ tβ) {s : set Ξ±} {f : Ξ± β Ξ²} (hβ : @continuous_on Ξ± Ξ² tβ tβ f s) :
@continuous_on Ξ± Ξ² tβ tβ f s :=
begin
rw continuous_on_iff' at hβ β’,
assume t ht,
rcases hβ t ht with β¨u, hu, h'uβ©,
exact β¨u, hβ u hu, h'uβ©
end
/-- If a function is continuous on a set for some topologies, then it is
continuous on the same set with respect to any coarser topology on the target space. -/
lemma continuous_on.mono_rng {Ξ± Ξ² : Type*} {tβ : topological_space Ξ±} {tβ tβ : topological_space Ξ²}
(hβ : tβ β€ tβ) {s : set Ξ±} {f : Ξ± β Ξ²} (hβ : @continuous_on Ξ± Ξ² tβ tβ f s) :
@continuous_on Ξ± Ξ² tβ tβ f s :=
begin
rw continuous_on_iff' at hβ β’,
assume t ht,
exact hβ t (hβ t ht)
end
theorem continuous_on_iff_is_closed {f : Ξ± β Ξ²} {s : set Ξ±} :
continuous_on f s β β t : set Ξ², is_closed t β β u, is_closed u β§ f β»ΒΉ' t β© s = u β© s :=
have β t, is_closed (s.restrict f β»ΒΉ' t) β β (u : set Ξ±), is_closed u β§ f β»ΒΉ' t β© s = u β© s,
begin
intro t,
rw [is_closed_induced_iff, set.restrict_eq, set.preimage_comp],
simp only [subtype.preimage_coe_eq_preimage_coe_iff, eq_comm]
end,
by rw [continuous_on_iff_continuous_restrict, continuous_iff_is_closed]; simp only [this]
lemma continuous_on.prod_map {f : Ξ± β Ξ³} {g : Ξ² β Ξ΄} {s : set Ξ±} {t : set Ξ²}
(hf : continuous_on f s) (hg : continuous_on g t) :
continuous_on (prod.map f g) (s ΓΛ’ t) :=
Ξ» β¨x, yβ© β¨hx, hyβ©, continuous_within_at.prod_map (hf x hx) (hg y hy)
lemma continuous_on_empty (f : Ξ± β Ξ²) : continuous_on f β
:=
Ξ» x, false.elim
lemma continuous_on_singleton (f : Ξ± β Ξ²) (a : Ξ±) : continuous_on f {a} :=
forall_eq.2 $ by simpa only [continuous_within_at, nhds_within_singleton, tendsto_pure_left]
using Ξ» s, mem_of_mem_nhds
lemma set.subsingleton.continuous_on {s : set Ξ±} (hs : s.subsingleton) (f : Ξ± β Ξ²) :
continuous_on f s :=
hs.induction_on (continuous_on_empty f) (continuous_on_singleton f)
theorem nhds_within_le_comap {x : Ξ±} {s : set Ξ±} {f : Ξ± β Ξ²} (ctsf : continuous_within_at f s x) :
π[s] x β€ comap f (π[f '' s] (f x)) :=
ctsf.tendsto_nhds_within_image.le_comap
@[simp] lemma comap_nhds_within_range {Ξ±} (f : Ξ± β Ξ²) (y : Ξ²) :
comap f (π[range f] y) = comap f (π y) :=
comap_inf_principal_range
theorem continuous_within_at_iff_ptendsto_res (f : Ξ± β Ξ²) {x : Ξ±} {s : set Ξ±} :
continuous_within_at f s x β ptendsto (pfun.res f s) (π x) (π (f x)) :=
tendsto_iff_ptendsto _ _ _ _
lemma continuous_iff_continuous_on_univ {f : Ξ± β Ξ²} : continuous f β continuous_on f univ :=
by simp [continuous_iff_continuous_at, continuous_on, continuous_at, continuous_within_at,
nhds_within_univ]
lemma continuous_within_at.mono {f : Ξ± β Ξ²} {s t : set Ξ±} {x : Ξ±} (h : continuous_within_at f t x)
(hs : s β t) : continuous_within_at f s x :=
h.mono_left (nhds_within_mono x hs)
lemma continuous_within_at.mono_of_mem {f : Ξ± β Ξ²} {s t : set Ξ±} {x : Ξ±}
(h : continuous_within_at f t x) (hs : t β π[s] x) : continuous_within_at f s x :=
h.mono_left (nhds_within_le_of_mem hs)
lemma continuous_within_at_inter' {f : Ξ± β Ξ²} {s t : set Ξ±} {x : Ξ±} (h : t β π[s] x) :
continuous_within_at f (s β© t) x β continuous_within_at f s x :=
by simp [continuous_within_at, nhds_within_restrict'' s h]
lemma continuous_within_at_inter {f : Ξ± β Ξ²} {s t : set Ξ±} {x : Ξ±} (h : t β π x) :
continuous_within_at f (s β© t) x β continuous_within_at f s x :=
by simp [continuous_within_at, nhds_within_restrict' s h]
lemma continuous_within_at_union {f : Ξ± β Ξ²} {s t : set Ξ±} {x : Ξ±} :
continuous_within_at f (s βͺ t) x β continuous_within_at f s x β§ continuous_within_at f t x :=
by simp only [continuous_within_at, nhds_within_union, tendsto_sup]
lemma continuous_within_at.union {f : Ξ± β Ξ²} {s t : set Ξ±} {x : Ξ±}
(hs : continuous_within_at f s x) (ht : continuous_within_at f t x) :
continuous_within_at f (s βͺ t) x :=
continuous_within_at_union.2 β¨hs, htβ©
lemma continuous_within_at.mem_closure_image {f : Ξ± β Ξ²} {s : set Ξ±} {x : Ξ±}
(h : continuous_within_at f s x) (hx : x β closure s) : f x β closure (f '' s) :=
by haveI := (mem_closure_iff_nhds_within_ne_bot.1 hx);
exact (mem_closure_of_tendsto h $
mem_of_superset self_mem_nhds_within (subset_preimage_image f s))
lemma continuous_within_at.mem_closure {f : Ξ± β Ξ²} {s : set Ξ±} {x : Ξ±} {A : set Ξ²}
(h : continuous_within_at f s x) (hx : x β closure s) (hA : maps_to f s A) : f x β closure A :=
closure_mono (image_subset_iff.2 hA) (h.mem_closure_image hx)
lemma set.maps_to.closure_of_continuous_within_at {f : Ξ± β Ξ²} {s : set Ξ±} {t : set Ξ²}
(h : maps_to f s t) (hc : β x β closure s, continuous_within_at f s x) :
maps_to f (closure s) (closure t) :=
Ξ» x hx, (hc x hx).mem_closure hx h
lemma set.maps_to.closure_of_continuous_on {f : Ξ± β Ξ²} {s : set Ξ±} {t : set Ξ²}
(h : maps_to f s t) (hc : continuous_on f (closure s)) :
maps_to f (closure s) (closure t) :=
h.closure_of_continuous_within_at $ Ξ» x hx, (hc x hx).mono subset_closure
lemma continuous_within_at.image_closure {f : Ξ± β Ξ²} {s : set Ξ±}
(hf : β x β closure s, continuous_within_at f s x) :
f '' (closure s) β closure (f '' s) :=
maps_to'.1 $ (maps_to_image f s).closure_of_continuous_within_at hf
lemma continuous_on.image_closure {f : Ξ± β Ξ²} {s : set Ξ±} (hf : continuous_on f (closure s)) :
f '' (closure s) β closure (f '' s) :=
continuous_within_at.image_closure $ Ξ» x hx, (hf x hx).mono subset_closure
@[simp] lemma continuous_within_at_singleton {f : Ξ± β Ξ²} {x : Ξ±} : continuous_within_at f {x} x :=
by simp only [continuous_within_at, nhds_within_singleton, tendsto_pure_nhds]
@[simp] lemma continuous_within_at_insert_self {f : Ξ± β Ξ²} {x : Ξ±} {s : set Ξ±} :
continuous_within_at f (insert x s) x β continuous_within_at f s x :=
by simp only [β singleton_union, continuous_within_at_union, continuous_within_at_singleton,
true_and]
alias continuous_within_at_insert_self β _ continuous_within_at.insert_self
lemma continuous_within_at.diff_iff {f : Ξ± β Ξ²} {s t : set Ξ±} {x : Ξ±}
(ht : continuous_within_at f t x) :
continuous_within_at f (s \ t) x β continuous_within_at f s x :=
β¨Ξ» h, (h.union ht).mono $ by simp only [diff_union_self, subset_union_left],
Ξ» h, h.mono (diff_subset _ _)β©
@[simp] lemma continuous_within_at_diff_self {f : Ξ± β Ξ²} {s : set Ξ±} {x : Ξ±} :
continuous_within_at f (s \ {x}) x β continuous_within_at f s x :=
continuous_within_at_singleton.diff_iff
@[simp] lemma continuous_within_at_compl_self {f : Ξ± β Ξ²} {a : Ξ±} :
continuous_within_at f {a}αΆ a β continuous_at f a :=
by rw [compl_eq_univ_diff, continuous_within_at_diff_self, continuous_within_at_univ]
@[simp] lemma continuous_within_at_update_same [decidable_eq Ξ±] {f : Ξ± β Ξ²}
{s : set Ξ±} {x : Ξ±} {y : Ξ²} :
continuous_within_at (update f x y) s x β tendsto f (π[s \ {x}] x) (π y) :=
calc continuous_within_at (update f x y) s x β tendsto (update f x y) (π[s \ {x}] x) (π y) :
by rw [β continuous_within_at_diff_self, continuous_within_at, function.update_same]
... β tendsto f (π[s \ {x}] x) (π y) :
tendsto_congr' $ eventually_nhds_within_iff.2 $ eventually_of_forall $
Ξ» z hz, update_noteq hz.2 _ _
@[simp] lemma continuous_at_update_same [decidable_eq Ξ±] {f : Ξ± β Ξ²} {x : Ξ±} {y : Ξ²} :
continuous_at (function.update f x y) x β tendsto f (π[β ] x) (π y) :=
by rw [β continuous_within_at_univ, continuous_within_at_update_same, compl_eq_univ_diff]
theorem is_open_map.continuous_on_image_of_left_inv_on {f : Ξ± β Ξ²} {s : set Ξ±}
(h : is_open_map (s.restrict f)) {finv : Ξ² β Ξ±} (hleft : left_inv_on finv f s) :
continuous_on finv (f '' s) :=
begin
refine continuous_on_iff'.2 (Ξ» t ht, β¨f '' (t β© s), _, _β©),
{ rw β image_restrict, exact h _ (ht.preimage continuous_subtype_coe) },
{ rw [inter_eq_self_of_subset_left (image_subset f (inter_subset_right t s)),
hleft.image_inter'] },
end
theorem is_open_map.continuous_on_range_of_left_inverse {f : Ξ± β Ξ²} (hf : is_open_map f)
{finv : Ξ² β Ξ±} (hleft : function.left_inverse finv f) :
continuous_on finv (range f) :=
begin
rw [β image_univ],
exact (hf.restrict is_open_univ).continuous_on_image_of_left_inv_on (Ξ» x _, hleft x)
end
lemma continuous_on.congr_mono {f g : Ξ± β Ξ²} {s sβ : set Ξ±} (h : continuous_on f s)
(h' : eq_on g f sβ) (hβ : sβ β s) : continuous_on g sβ :=
begin
assume x hx,
unfold continuous_within_at,
have A := (h x (hβ hx)).mono hβ,
unfold continuous_within_at at A,
rw β h' hx at A,
exact A.congr' h'.eventually_eq_nhds_within.symm
end
lemma continuous_on.congr {f g : Ξ± β Ξ²} {s : set Ξ±} (h : continuous_on f s) (h' : eq_on g f s) :
continuous_on g s :=
h.congr_mono h' (subset.refl _)
lemma continuous_on_congr {f g : Ξ± β Ξ²} {s : set Ξ±} (h' : eq_on g f s) :
continuous_on g s β continuous_on f s :=
β¨Ξ» h, continuous_on.congr h h'.symm, Ξ» h, h.congr h'β©
lemma continuous_at.continuous_within_at {f : Ξ± β Ξ²} {s : set Ξ±} {x : Ξ±} (h : continuous_at f x) :
continuous_within_at f s x :=
continuous_within_at.mono ((continuous_within_at_univ f x).2 h) (subset_univ _)
lemma continuous_within_at_iff_continuous_at {f : Ξ± β Ξ²} {s : set Ξ±} {x : Ξ±} (h : s β π x) :
continuous_within_at f s x β continuous_at f x :=
by rw [β univ_inter s, continuous_within_at_inter h, continuous_within_at_univ]
lemma continuous_within_at.continuous_at {f : Ξ± β Ξ²} {s : set Ξ±} {x : Ξ±}
(h : continuous_within_at f s x) (hs : s β π x) : continuous_at f x :=
(continuous_within_at_iff_continuous_at hs).mp h
lemma continuous_on.continuous_at {f : Ξ± β Ξ²} {s : set Ξ±} {x : Ξ±}
(h : continuous_on f s) (hx : s β π x) : continuous_at f x :=
(h x (mem_of_mem_nhds hx)).continuous_at hx
lemma continuous_at.continuous_on {f : Ξ± β Ξ²} {s : set Ξ±} (hcont : β x β s, continuous_at f x) :
continuous_on f s :=
Ξ» x hx, (hcont x hx).continuous_within_at
lemma continuous_within_at.comp {g : Ξ² β Ξ³} {f : Ξ± β Ξ²} {s : set Ξ±} {t : set Ξ²} {x : Ξ±}
(hg : continuous_within_at g t (f x)) (hf : continuous_within_at f s x) (h : maps_to f s t) :
continuous_within_at (g β f) s x :=
hg.tendsto.comp (hf.tendsto_nhds_within h)
lemma continuous_within_at.comp' {g : Ξ² β Ξ³} {f : Ξ± β Ξ²} {s : set Ξ±} {t : set Ξ²} {x : Ξ±}
(hg : continuous_within_at g t (f x)) (hf : continuous_within_at f s x) :
continuous_within_at (g β f) (s β© fβ»ΒΉ' t) x :=
hg.comp (hf.mono (inter_subset_left _ _)) (inter_subset_right _ _)
lemma continuous_at.comp_continuous_within_at {g : Ξ² β Ξ³} {f : Ξ± β Ξ²} {s : set Ξ±} {x : Ξ±}
(hg : continuous_at g (f x)) (hf : continuous_within_at f s x) :
continuous_within_at (g β f) s x :=
hg.continuous_within_at.comp hf (maps_to_univ _ _)
lemma continuous_on.comp {g : Ξ² β Ξ³} {f : Ξ± β Ξ²} {s : set Ξ±} {t : set Ξ²}
(hg : continuous_on g t) (hf : continuous_on f s) (h : maps_to f s t) :
continuous_on (g β f) s :=
Ξ»x hx, continuous_within_at.comp (hg _ (h hx)) (hf x hx) h
lemma continuous_on.mono {f : Ξ± β Ξ²} {s t : set Ξ±} (hf : continuous_on f s) (h : t β s) :
continuous_on f t :=
Ξ»x hx, (hf x (h hx)).mono_left (nhds_within_mono _ h)
lemma antitone_continuous_on {f : Ξ± β Ξ²} : antitone (continuous_on f) :=
Ξ» s t hst hf, hf.mono hst
lemma continuous_on.comp' {g : Ξ² β Ξ³} {f : Ξ± β Ξ²} {s : set Ξ±} {t : set Ξ²}
(hg : continuous_on g t) (hf : continuous_on f s) :
continuous_on (g β f) (s β© fβ»ΒΉ' t) :=
hg.comp (hf.mono (inter_subset_left _ _)) (inter_subset_right _ _)
lemma continuous.continuous_on {f : Ξ± β Ξ²} {s : set Ξ±} (h : continuous f) :
continuous_on f s :=
begin
rw continuous_iff_continuous_on_univ at h,
exact h.mono (subset_univ _)
end
lemma continuous.continuous_within_at {f : Ξ± β Ξ²} {s : set Ξ±} {x : Ξ±} (h : continuous f) :
continuous_within_at f s x :=
h.continuous_at.continuous_within_at
lemma continuous.comp_continuous_on {g : Ξ² β Ξ³} {f : Ξ± β Ξ²} {s : set Ξ±}
(hg : continuous g) (hf : continuous_on f s) :
continuous_on (g β f) s :=
hg.continuous_on.comp hf (maps_to_univ _ _)
lemma continuous_on.comp_continuous {g : Ξ² β Ξ³} {f : Ξ± β Ξ²} {s : set Ξ²}
(hg : continuous_on g s) (hf : continuous f) (hs : β x, f x β s) : continuous (g β f) :=
begin
rw continuous_iff_continuous_on_univ at *,
exact hg.comp hf (Ξ» x _, hs x),
end
lemma continuous_within_at.preimage_mem_nhds_within {f : Ξ± β Ξ²} {x : Ξ±} {s : set Ξ±} {t : set Ξ²}
(h : continuous_within_at f s x) (ht : t β π (f x)) : f β»ΒΉ' t β π[s] x :=
h ht
lemma set.left_inv_on.map_nhds_within_eq {f : Ξ± β Ξ²} {g : Ξ² β Ξ±} {x : Ξ²} {s : set Ξ²}
(h : left_inv_on f g s) (hx : f (g x) = x) (hf : continuous_within_at f (g '' s) (g x))
(hg : continuous_within_at g s x) :
map g (π[s] x) = π[g '' s] (g x) :=
begin
apply le_antisymm,
{ exact hg.tendsto_nhds_within (maps_to_image _ _) },
{ have A : g β f =αΆ [π[g '' s] (g x)] id,
from h.right_inv_on_image.eq_on.eventually_eq_of_mem self_mem_nhds_within,
refine le_map_of_right_inverse A _,
simpa only [hx] using hf.tendsto_nhds_within (h.maps_to (surj_on_image _ _)) }
end
lemma function.left_inverse.map_nhds_eq {f : Ξ± β Ξ²} {g : Ξ² β Ξ±} {x : Ξ²}
(h : function.left_inverse f g) (hf : continuous_within_at f (range g) (g x))
(hg : continuous_at g x) :
map g (π x) = π[range g] (g x) :=
by simpa only [nhds_within_univ, image_univ]
using (h.left_inv_on univ).map_nhds_within_eq (h x) (by rwa image_univ) hg.continuous_within_at
lemma continuous_within_at.preimage_mem_nhds_within' {f : Ξ± β Ξ²} {x : Ξ±} {s : set Ξ±} {t : set Ξ²}
(h : continuous_within_at f s x) (ht : t β π[f '' s] (f x)) :
f β»ΒΉ' t β π[s] x :=
h.tendsto_nhds_within (maps_to_image _ _) ht
lemma filter.eventually_eq.congr_continuous_within_at {f g : Ξ± β Ξ²} {s : set Ξ±} {x : Ξ±}
(h : f =αΆ [π[s] x] g) (hx : f x = g x) :
continuous_within_at f s x β continuous_within_at g s x :=
by rw [continuous_within_at, hx, tendsto_congr' h, continuous_within_at]
lemma continuous_within_at.congr_of_eventually_eq {f fβ : Ξ± β Ξ²} {s : set Ξ±} {x : Ξ±}
(h : continuous_within_at f s x) (hβ : fβ =αΆ [π[s] x] f) (hx : fβ x = f x) :
continuous_within_at fβ s x :=
(hβ.congr_continuous_within_at hx).2 h
lemma continuous_within_at.congr {f fβ : Ξ± β Ξ²} {s : set Ξ±} {x : Ξ±}
(h : continuous_within_at f s x) (hβ : βyβs, fβ y = f y) (hx : fβ x = f x) :
continuous_within_at fβ s x :=
h.congr_of_eventually_eq (mem_of_superset self_mem_nhds_within hβ) hx
lemma continuous_within_at.congr_mono {f g : Ξ± β Ξ²} {s sβ : set Ξ±} {x : Ξ±}
(h : continuous_within_at f s x) (h' : eq_on g f sβ) (hβ : sβ β s) (hx : g x = f x):
continuous_within_at g sβ x :=
(h.mono hβ).congr h' hx
lemma continuous_on_const {s : set Ξ±} {c : Ξ²} : continuous_on (Ξ»x, c) s :=
continuous_const.continuous_on
lemma continuous_within_at_const {b : Ξ²} {s : set Ξ±} {x : Ξ±} :
continuous_within_at (Ξ» _:Ξ±, b) s x :=
continuous_const.continuous_within_at
lemma continuous_on_id {s : set Ξ±} : continuous_on id s :=
continuous_id.continuous_on
lemma continuous_within_at_id {s : set Ξ±} {x : Ξ±} : continuous_within_at id s x :=
continuous_id.continuous_within_at
lemma continuous_on_open_iff {f : Ξ± β Ξ²} {s : set Ξ±} (hs : is_open s) :
continuous_on f s β (βt, is_open t β is_open (s β© fβ»ΒΉ' t)) :=
begin
rw continuous_on_iff',
split,
{ assume h t ht,
rcases h t ht with β¨u, u_open, huβ©,
rw [inter_comm, hu],
apply is_open.inter u_open hs },
{ assume h t ht,
refine β¨s β© f β»ΒΉ' t, h t ht, _β©,
rw [@inter_comm _ s (f β»ΒΉ' t), inter_assoc, inter_self] }
end
lemma continuous_on.preimage_open_of_open {f : Ξ± β Ξ²} {s : set Ξ±} {t : set Ξ²}
(hf : continuous_on f s) (hs : is_open s) (ht : is_open t) : is_open (s β© fβ»ΒΉ' t) :=
(continuous_on_open_iff hs).1 hf t ht
lemma continuous_on.is_open_preimage {f : Ξ± β Ξ²} {s : set Ξ±} {t : set Ξ²} (h : continuous_on f s)
(hs : is_open s) (hp : f β»ΒΉ' t β s) (ht : is_open t) : is_open (f β»ΒΉ' t) :=
begin
convert (continuous_on_open_iff hs).mp h t ht,
rw [inter_comm, inter_eq_self_of_subset_left hp],
end
lemma continuous_on.preimage_closed_of_closed {f : Ξ± β Ξ²} {s : set Ξ±} {t : set Ξ²}
(hf : continuous_on f s) (hs : is_closed s) (ht : is_closed t) : is_closed (s β© fβ»ΒΉ' t) :=
begin
rcases continuous_on_iff_is_closed.1 hf t ht with β¨u, huβ©,
rw [inter_comm, hu.2],
apply is_closed.inter hu.1 hs
end
lemma continuous_on.preimage_interior_subset_interior_preimage {f : Ξ± β Ξ²} {s : set Ξ±} {t : set Ξ²}
(hf : continuous_on f s) (hs : is_open s) : s β© fβ»ΒΉ' (interior t) β s β© interior (fβ»ΒΉ' t) :=
calc s β© f β»ΒΉ' (interior t) β interior (s β© f β»ΒΉ' t) :
interior_maximal (inter_subset_inter (subset.refl _) (preimage_mono interior_subset))
(hf.preimage_open_of_open hs is_open_interior)
... = s β© interior (f β»ΒΉ' t) : by rw [interior_inter, hs.interior_eq]
lemma continuous_on_of_locally_continuous_on {f : Ξ± β Ξ²} {s : set Ξ±}
(h : βxβs, βt, is_open t β§ x β t β§ continuous_on f (s β© t)) : continuous_on f s :=
begin
assume x xs,
rcases h x xs with β¨t, open_t, xt, ctβ©,
have := ct x β¨xs, xtβ©,
rwa [continuous_within_at, β nhds_within_restrict _ xt open_t] at this
end
lemma continuous_on_open_of_generate_from {Ξ² : Type*} {s : set Ξ±} {T : set (set Ξ²)} {f : Ξ± β Ξ²}
(hs : is_open s) (h : βt β T, is_open (s β© fβ»ΒΉ' t)) :
@continuous_on Ξ± Ξ² _ (topological_space.generate_from T) f s :=
begin
rw continuous_on_open_iff,
assume t ht,
induction ht with u hu u v Tu Tv hu hv U hU hU',
{ exact h u hu },
{ simp only [preimage_univ, inter_univ], exact hs },
{ have : s β© f β»ΒΉ' (u β© v) = (s β© f β»ΒΉ' u) β© (s β© f β»ΒΉ' v),
by rw [preimage_inter, inter_assoc, inter_left_comm _ s, β inter_assoc s s, inter_self],
rw this,
exact hu.inter hv },
{ rw [preimage_sUnion, inter_Unionβ],
exact is_open_bUnion hU' },
{ exact hs }
end
lemma continuous_within_at.prod {f : Ξ± β Ξ²} {g : Ξ± β Ξ³} {s : set Ξ±} {x : Ξ±}
(hf : continuous_within_at f s x) (hg : continuous_within_at g s x) :
continuous_within_at (Ξ»x, (f x, g x)) s x :=
hf.prod_mk_nhds hg
lemma continuous_on.prod {f : Ξ± β Ξ²} {g : Ξ± β Ξ³} {s : set Ξ±}
(hf : continuous_on f s) (hg : continuous_on g s) : continuous_on (Ξ»x, (f x, g x)) s :=
Ξ»x hx, continuous_within_at.prod (hf x hx) (hg x hx)
lemma inducing.continuous_within_at_iff {f : Ξ± β Ξ²} {g : Ξ² β Ξ³} (hg : inducing g) {s : set Ξ±}
{x : Ξ±} : continuous_within_at f s x β continuous_within_at (g β f) s x :=
by simp_rw [continuous_within_at, inducing.tendsto_nhds_iff hg]
lemma inducing.continuous_on_iff {f : Ξ± β Ξ²} {g : Ξ² β Ξ³} (hg : inducing g) {s : set Ξ±} :
continuous_on f s β continuous_on (g β f) s :=
by simp_rw [continuous_on, hg.continuous_within_at_iff]
lemma embedding.continuous_on_iff {f : Ξ± β Ξ²} {g : Ξ² β Ξ³} (hg : embedding g) {s : set Ξ±} :
continuous_on f s β continuous_on (g β f) s :=
inducing.continuous_on_iff hg.1
lemma embedding.map_nhds_within_eq {f : Ξ± β Ξ²} (hf : embedding f) (s : set Ξ±) (x : Ξ±) :
map f (π[s] x) = π[f '' s] (f x) :=
by rw [nhds_within, map_inf hf.inj, hf.map_nhds_eq, map_principal, β nhds_within_inter',
inter_eq_self_of_subset_right (image_subset_range _ _)]
lemma open_embedding.map_nhds_within_preimage_eq {f : Ξ± β Ξ²} (hf : open_embedding f)
(s : set Ξ²) (x : Ξ±) :
map f (π[f β»ΒΉ' s] x) = π[s] (f x) :=
begin
rw [hf.to_embedding.map_nhds_within_eq, image_preimage_eq_inter_range],
apply nhds_within_eq_nhds_within (mem_range_self _) hf.open_range,
rw [inter_assoc, inter_self]
end
lemma continuous_within_at_of_not_mem_closure {f : Ξ± β Ξ²} {s : set Ξ±} {x : Ξ±} :
x β closure s β continuous_within_at f s x :=
begin
intros hx,
rw [mem_closure_iff_nhds_within_ne_bot, ne_bot_iff, not_not] at hx,
rw [continuous_within_at, hx],
exact tendsto_bot,
end
lemma continuous_on.piecewise' {s t : set Ξ±} {f g : Ξ± β Ξ²} [β a, decidable (a β t)]
(hpf : β a β s β© frontier t, tendsto f (π[s β© t] a) (π (piecewise t f g a)))
(hpg : β a β s β© frontier t, tendsto g (π[s β© tαΆ] a) (π (piecewise t f g a)))
(hf : continuous_on f $ s β© t) (hg : continuous_on g $ s β© tαΆ) :
continuous_on (piecewise t f g) s :=
begin
intros x hx,
by_cases hx' : x β frontier t,
{ exact (hpf x β¨hx, hx'β©).piecewise_nhds_within (hpg x β¨hx, hx'β©) },
{ rw [β inter_univ s, β union_compl_self t, inter_union_distrib_left] at hx β’,
cases hx,
{ apply continuous_within_at.union,
{ exact (hf x hx).congr (Ξ» y hy, piecewise_eq_of_mem _ _ _ hy.2)
(piecewise_eq_of_mem _ _ _ hx.2) },
{ have : x β closure tαΆ,
from Ξ» h, hx' β¨subset_closure hx.2, by rwa closure_compl at hβ©,
exact continuous_within_at_of_not_mem_closure
(Ξ» h, this (closure_inter_subset_inter_closure _ _ h).2) } },
{ apply continuous_within_at.union,
{ have : x β closure t,
from (Ξ» h, hx' β¨h, (Ξ» (h' : x β interior t), hx.2 (interior_subset h'))β©),
exact continuous_within_at_of_not_mem_closure
(Ξ» h, this (closure_inter_subset_inter_closure _ _ h).2) },
{ exact (hg x hx).congr
(Ξ» y hy, piecewise_eq_of_not_mem _ _ _ hy.2)
(piecewise_eq_of_not_mem _ _ _ hx.2) } } }
end
lemma continuous_on.if' {s : set Ξ±} {p : Ξ± β Prop} {f g : Ξ± β Ξ²} [β a, decidable (p a)]
(hpf : β a β s β© frontier {a | p a},
tendsto f (π[s β© {a | p a}] a) (π $ if p a then f a else g a))
(hpg : β a β s β© frontier {a | p a},
tendsto g (π[s β© {a | Β¬p a}] a) (π $ if p a then f a else g a))
(hf : continuous_on f $ s β© {a | p a}) (hg : continuous_on g $ s β© {a | Β¬p a}) :
continuous_on (Ξ» a, if p a then f a else g a) s :=
hf.piecewise' hpf hpg hg
lemma continuous_on.if {Ξ± Ξ² : Type*} [topological_space Ξ±] [topological_space Ξ²] {p : Ξ± β Prop}
[β a, decidable (p a)] {s : set Ξ±} {f g : Ξ± β Ξ²}
(hp : β a β s β© frontier {a | p a}, f a = g a) (hf : continuous_on f $ s β© closure {a | p a})
(hg : continuous_on g $ s β© closure {a | Β¬ p a}) :
continuous_on (Ξ»a, if p a then f a else g a) s :=
begin
apply continuous_on.if',
{ rintros a ha,
simp only [β hp a ha, if_t_t],
apply tendsto_nhds_within_mono_left (inter_subset_inter_right s subset_closure),
exact hf a β¨ha.1, ha.2.1β© },
{ rintros a ha,
simp only [hp a ha, if_t_t],
apply tendsto_nhds_within_mono_left (inter_subset_inter_right s subset_closure),
rcases ha with β¨has, β¨_, haβ©β©,
rw [β mem_compl_iff, β closure_compl] at ha,
apply hg a β¨has, haβ© },
{ exact hf.mono (inter_subset_inter_right s subset_closure) },
{ exact hg.mono (inter_subset_inter_right s subset_closure) }
end
lemma continuous_on.piecewise {s t : set Ξ±} {f g : Ξ± β Ξ²} [β a, decidable (a β t)]
(ht : β a β s β© frontier t, f a = g a) (hf : continuous_on f $ s β© closure t)
(hg : continuous_on g $ s β© closure tαΆ) :
continuous_on (piecewise t f g) s :=
hf.if ht hg
lemma continuous_if' {p : Ξ± β Prop} {f g : Ξ± β Ξ²} [β a, decidable (p a)]
(hpf : β a β frontier {x | p x}, tendsto f (π[{x | p x}] a) (π $ ite (p a) (f a) (g a)))
(hpg : β a β frontier {x | p x}, tendsto g (π[{x | Β¬p x}] a) (π $ ite (p a) (f a) (g a)))
(hf : continuous_on f {x | p x}) (hg : continuous_on g {x | Β¬p x}) :
continuous (Ξ» a, ite (p a) (f a) (g a)) :=
begin
rw continuous_iff_continuous_on_univ,
apply continuous_on.if'; simp *; assumption
end
lemma continuous_if {p : Ξ± β Prop} {f g : Ξ± β Ξ²} [β a, decidable (p a)]
(hp : β a β frontier {x | p x}, f a = g a) (hf : continuous_on f (closure {x | p x}))
(hg : continuous_on g (closure {x | Β¬p x})) :
continuous (Ξ» a, if p a then f a else g a) :=
begin
rw continuous_iff_continuous_on_univ,
apply continuous_on.if; simp; assumption
end
lemma continuous.if {p : Ξ± β Prop} {f g : Ξ± β Ξ²} [β a, decidable (p a)]
(hp : β a β frontier {x | p x}, f a = g a) (hf : continuous f) (hg : continuous g) :
continuous (Ξ» a, if p a then f a else g a) :=
continuous_if hp hf.continuous_on hg.continuous_on
lemma continuous_if_const (p : Prop) {f g : Ξ± β Ξ²} [decidable p]
(hf : p β continuous f) (hg : Β¬ p β continuous g) :
continuous (Ξ» a, if p then f a else g a) :=
by { split_ifs, exact hf h, exact hg h }
lemma continuous.if_const (p : Prop) {f g : Ξ± β Ξ²} [decidable p]
(hf : continuous f) (hg : continuous g) :
continuous (Ξ» a, if p then f a else g a) :=
continuous_if_const p (Ξ» _, hf) (Ξ» _, hg)
lemma continuous_piecewise {s : set Ξ±} {f g : Ξ± β Ξ²} [β a, decidable (a β s)]
(hs : β a β frontier s, f a = g a) (hf : continuous_on f (closure s))
(hg : continuous_on g (closure sαΆ)) :
continuous (piecewise s f g) :=
continuous_if hs hf hg
lemma continuous.piecewise {s : set Ξ±} {f g : Ξ± β Ξ²} [β a, decidable (a β s)]
(hs : β a β frontier s, f a = g a) (hf : continuous f) (hg : continuous g) :
continuous (piecewise s f g) :=
hf.if hs hg
lemma is_open.ite' {s s' t : set Ξ±}
(hs : is_open s) (hs' : is_open s') (ht : β x β frontier t, x β s β x β s') :
is_open (t.ite s s') :=
begin
classical,
simp only [is_open_iff_continuous_mem, set.ite] at *,
convert continuous_piecewise (Ξ» x hx, propext (ht x hx)) hs.continuous_on hs'.continuous_on,
ext x, by_cases hx : x β t; simp [hx]
end
lemma is_open.ite {s s' t : set Ξ±} (hs : is_open s) (hs' : is_open s')
(ht : s β© frontier t = s' β© frontier t) :
is_open (t.ite s s') :=
hs.ite' hs' $ Ξ» x hx, by simpa [hx] using ext_iff.1 ht x
lemma ite_inter_closure_eq_of_inter_frontier_eq {s s' t : set Ξ±}
(ht : s β© frontier t = s' β© frontier t) :
t.ite s s' β© closure t = s β© closure t :=
by rw [closure_eq_self_union_frontier, inter_union_distrib_left, inter_union_distrib_left,
ite_inter_self, ite_inter_of_inter_eq _ ht]
lemma ite_inter_closure_compl_eq_of_inter_frontier_eq {s s' t : set Ξ±}
(ht : s β© frontier t = s' β© frontier t) :
t.ite s s' β© closure tαΆ = s' β© closure tαΆ :=
by { rw [β ite_compl, ite_inter_closure_eq_of_inter_frontier_eq], rwa [frontier_compl, eq_comm] }
lemma continuous_on_piecewise_ite' {s s' t : set Ξ±} {f f' : Ξ± β Ξ²} [β x, decidable (x β t)]
(h : continuous_on f (s β© closure t)) (h' : continuous_on f' (s' β© closure tαΆ))
(H : s β© frontier t = s' β© frontier t) (Heq : eq_on f f' (s β© frontier t)) :
continuous_on (t.piecewise f f') (t.ite s s') :=
begin
apply continuous_on.piecewise,
{ rwa ite_inter_of_inter_eq _ H },
{ rwa ite_inter_closure_eq_of_inter_frontier_eq H },
{ rwa ite_inter_closure_compl_eq_of_inter_frontier_eq H }
end
lemma continuous_on_piecewise_ite {s s' t : set Ξ±} {f f' : Ξ± β Ξ²} [β x, decidable (x β t)]
(h : continuous_on f s) (h' : continuous_on f' s')
(H : s β© frontier t = s' β© frontier t) (Heq : eq_on f f' (s β© frontier t)) :
continuous_on (t.piecewise f f') (t.ite s s') :=
continuous_on_piecewise_ite' (h.mono (inter_subset_left _ _)) (h'.mono (inter_subset_left _ _))
H Heq
lemma frontier_inter_open_inter {s t : set Ξ±} (ht : is_open t) :
frontier (s β© t) β© t = frontier s β© t :=
by simp only [β subtype.preimage_coe_eq_preimage_coe_iff,
ht.is_open_map_subtype_coe.preimage_frontier_eq_frontier_preimage continuous_subtype_coe,
subtype.preimage_coe_inter_self]
lemma continuous_on_fst {s : set (Ξ± Γ Ξ²)} : continuous_on prod.fst s :=
continuous_fst.continuous_on
lemma continuous_within_at_fst {s : set (Ξ± Γ Ξ²)} {p : Ξ± Γ Ξ²} :
continuous_within_at prod.fst s p :=
continuous_fst.continuous_within_at
lemma continuous_on.fst {f : Ξ± β Ξ² Γ Ξ³} {s : set Ξ±} (hf : continuous_on f s) :
continuous_on (Ξ» x, (f x).1) s :=
continuous_fst.comp_continuous_on hf
lemma continuous_within_at.fst {f : Ξ± β Ξ² Γ Ξ³} {s : set Ξ±} {a : Ξ±}
(h : continuous_within_at f s a) : continuous_within_at (Ξ» x, (f x).fst) s a :=
continuous_at_fst.comp_continuous_within_at h
lemma continuous_on_snd {s : set (Ξ± Γ Ξ²)} : continuous_on prod.snd s :=
continuous_snd.continuous_on
lemma continuous_within_at_snd {s : set (Ξ± Γ Ξ²)} {p : Ξ± Γ Ξ²} :
continuous_within_at prod.snd s p :=
continuous_snd.continuous_within_at
lemma continuous_on.snd {f : Ξ± β Ξ² Γ Ξ³} {s : set Ξ±} (hf : continuous_on f s) :
continuous_on (Ξ» x, (f x).2) s :=
continuous_snd.comp_continuous_on hf
lemma continuous_within_at.snd {f : Ξ± β Ξ² Γ Ξ³} {s : set Ξ±} {a : Ξ±}
(h : continuous_within_at f s a) : continuous_within_at (Ξ» x, (f x).snd) s a :=
continuous_at_snd.comp_continuous_within_at h
lemma continuous_within_at_prod_iff {f : Ξ± β Ξ² Γ Ξ³} {s : set Ξ±} {x : Ξ±} :
continuous_within_at f s x β continuous_within_at (prod.fst β f) s x β§
continuous_within_at (prod.snd β f) s x :=
β¨Ξ» h, β¨h.fst, h.sndβ©, by { rintro β¨h1, h2β©, convert h1.prod h2, ext, refl, refl }β©
|
34b640ed6d8753dbf0e9402fd473990bbde02cbc | 9dc8cecdf3c4634764a18254e94d43da07142918 | /src/analysis/specific_limits/basic.lean | 0a964e07c6ab9e08586d27f2dd3e9481a32e9cc5 | [
"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 | 24,593 | lean | /-
Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: SΓ©bastien GouΓ«zel, Johannes HΓΆlzl, Yury G. Kudryashov, Patrick Massot
-/
import algebra.geom_sum
import order.filter.archimedean
import order.iterate
import topology.instances.ennreal
/-!
# A collection of specific limit computations
This file, by design, is independent of `normed_space` in the import hierarchy. It contains
important specific limit computations in metric spaces, in ordered rings/fields, and in specific
instances of these such as `β`, `ββ₯0` and `ββ₯0β`.
-/
noncomputable theory
open classical set function filter finset metric
open_locale classical topological_space nat big_operators uniformity nnreal ennreal
variables {Ξ± : Type*} {Ξ² : Type*} {ΞΉ : Type*}
lemma tendsto_inverse_at_top_nhds_0_nat : tendsto (Ξ» n : β, (n : β)β»ΒΉ) at_top (π 0) :=
tendsto_inv_at_top_zero.comp tendsto_coe_nat_at_top_at_top
lemma tendsto_const_div_at_top_nhds_0_nat (C : β) : tendsto (Ξ» n : β, C / n) at_top (π 0) :=
by simpa only [mul_zero] using tendsto_const_nhds.mul tendsto_inverse_at_top_nhds_0_nat
lemma nnreal.tendsto_inverse_at_top_nhds_0_nat : tendsto (Ξ» n : β, (n : ββ₯0)β»ΒΉ) at_top (π 0) :=
by { rw β nnreal.tendsto_coe, exact tendsto_inverse_at_top_nhds_0_nat }
lemma nnreal.tendsto_const_div_at_top_nhds_0_nat (C : ββ₯0) :
tendsto (Ξ» n : β, C / n) at_top (π 0) :=
by simpa using tendsto_const_nhds.mul nnreal.tendsto_inverse_at_top_nhds_0_nat
lemma tendsto_one_div_add_at_top_nhds_0_nat :
tendsto (Ξ» n : β, 1 / ((n : β) + 1)) at_top (π 0) :=
suffices tendsto (Ξ» n : β, 1 / (β(n + 1) : β)) at_top (π 0), by simpa,
(tendsto_add_at_top_iff_nat 1).2 (tendsto_const_div_at_top_nhds_0_nat 1)
/-! ### Powers -/
lemma tendsto_add_one_pow_at_top_at_top_of_pos [linear_ordered_semiring Ξ±] [archimedean Ξ±] {r : Ξ±}
(h : 0 < r) :
tendsto (Ξ» n:β, (r + 1)^n) at_top at_top :=
tendsto_at_top_at_top_of_monotone' (Ξ» n m, pow_le_pow (le_add_of_nonneg_left (le_of_lt h))) $
not_bdd_above_iff.2 $ Ξ» x, set.exists_range_iff.2 $ add_one_pow_unbounded_of_pos _ h
lemma tendsto_pow_at_top_at_top_of_one_lt [linear_ordered_ring Ξ±] [archimedean Ξ±]
{r : Ξ±} (h : 1 < r) :
tendsto (Ξ»n:β, r ^ n) at_top at_top :=
sub_add_cancel r 1 βΈ tendsto_add_one_pow_at_top_at_top_of_pos (sub_pos.2 h)
lemma nat.tendsto_pow_at_top_at_top_of_one_lt {m : β} (h : 1 < m) :
tendsto (Ξ»n:β, m ^ n) at_top at_top :=
tsub_add_cancel_of_le (le_of_lt h) βΈ
tendsto_add_one_pow_at_top_at_top_of_pos (tsub_pos_of_lt h)
lemma tendsto_pow_at_top_nhds_0_of_lt_1 {π : Type*} [linear_ordered_field π] [archimedean π]
[topological_space π] [order_topology π] {r : π} (hβ : 0 β€ r) (hβ : r < 1) :
tendsto (Ξ»n:β, r^n) at_top (π 0) :=
hβ.eq_or_lt.elim
(assume : 0 = r,
(tendsto_add_at_top_iff_nat 1).mp $ by simp [pow_succ, β this, tendsto_const_nhds])
(assume : 0 < r,
have tendsto (Ξ»n, (rβ»ΒΉ ^ n)β»ΒΉ) at_top (π 0),
from tendsto_inv_at_top_zero.comp
(tendsto_pow_at_top_at_top_of_one_lt $ one_lt_inv this hβ),
this.congr (Ξ» n, by simp))
lemma tendsto_pow_at_top_nhds_within_0_of_lt_1 {π : Type*} [linear_ordered_field π] [archimedean π]
[topological_space π] [order_topology π] {r : π} (hβ : 0 < r) (hβ : r < 1) :
tendsto (Ξ»n:β, r^n) at_top (π[>] 0) :=
tendsto_inf.2 β¨tendsto_pow_at_top_nhds_0_of_lt_1 hβ.le hβ,
tendsto_principal.2 $ eventually_of_forall $ Ξ» n, pow_pos hβ _β©
lemma uniformity_basis_dist_pow_of_lt_1 {Ξ± : Type*} [pseudo_metric_space Ξ±]
{r : β} (hβ : 0 < r) (hβ : r < 1) :
(π€ Ξ±).has_basis (Ξ» k : β, true) (Ξ» k, {p : Ξ± Γ Ξ± | dist p.1 p.2 < r ^ k}) :=
metric.mk_uniformity_basis (Ξ» i _, pow_pos hβ _) $ Ξ» Ξ΅ Ξ΅0,
(exists_pow_lt_of_lt_one Ξ΅0 hβ).imp $ Ξ» k hk, β¨trivial, hk.leβ©
lemma geom_lt {u : β β β} {c : β} (hc : 0 β€ c) {n : β} (hn : 0 < n)
(h : β k < n, c * u k < u (k + 1)) :
c ^ n * u 0 < u n :=
begin
refine (monotone_mul_left_of_nonneg hc).seq_pos_lt_seq_of_le_of_lt hn _ _ h,
{ simp },
{ simp [pow_succ, mul_assoc, le_refl] }
end
lemma geom_le {u : β β β} {c : β} (hc : 0 β€ c) (n : β) (h : β k < n, c * u k β€ u (k + 1)) :
c ^ n * u 0 β€ u n :=
by refine (monotone_mul_left_of_nonneg hc).seq_le_seq n _ _ h; simp [pow_succ, mul_assoc, le_refl]
lemma lt_geom {u : β β β} {c : β} (hc : 0 β€ c) {n : β} (hn : 0 < n)
(h : β k < n, u (k + 1) < c * u k) :
u n < c ^ n * u 0 :=
begin
refine (monotone_mul_left_of_nonneg hc).seq_pos_lt_seq_of_lt_of_le hn _ h _,
{ simp },
{ simp [pow_succ, mul_assoc, le_refl] }
end
lemma le_geom {u : β β β} {c : β} (hc : 0 β€ c) (n : β) (h : β k < n, u (k + 1) β€ c * u k) :
u n β€ (c ^ n) * u 0 :=
by refine (monotone_mul_left_of_nonneg hc).seq_le_seq n _ h _; simp [pow_succ, mul_assoc, le_refl]
/-- If a sequence `v` of real numbers satisfies `k * v n β€ v (n+1)` with `1 < k`,
then it goes to +β. -/
lemma tendsto_at_top_of_geom_le {v : β β β} {c : β} (hβ : 0 < v 0) (hc : 1 < c)
(hu : β n, c * v n β€ v (n + 1)) : tendsto v at_top at_top :=
tendsto_at_top_mono (Ξ» n, geom_le (zero_le_one.trans hc.le) n (Ξ» k hk, hu k)) $
(tendsto_pow_at_top_at_top_of_one_lt hc).at_top_mul_const hβ
lemma nnreal.tendsto_pow_at_top_nhds_0_of_lt_1 {r : ββ₯0} (hr : r < 1) :
tendsto (Ξ» n:β, r^n) at_top (π 0) :=
nnreal.tendsto_coe.1 $ by simp only [nnreal.coe_pow, nnreal.coe_zero,
tendsto_pow_at_top_nhds_0_of_lt_1 r.coe_nonneg hr]
lemma ennreal.tendsto_pow_at_top_nhds_0_of_lt_1 {r : ββ₯0β} (hr : r < 1) :
tendsto (Ξ» n:β, r^n) at_top (π 0) :=
begin
rcases ennreal.lt_iff_exists_coe.1 hr with β¨r, rfl, hr'β©,
rw [β ennreal.coe_zero],
norm_cast at *,
apply nnreal.tendsto_pow_at_top_nhds_0_of_lt_1 hr
end
/-! ### Geometric series-/
section geometric
lemma has_sum_geometric_of_lt_1 {r : β} (hβ : 0 β€ r) (hβ : r < 1) :
has_sum (Ξ»n:β, r ^ n) (1 - r)β»ΒΉ :=
have r β 1, from ne_of_lt hβ,
have tendsto (Ξ»n, (r ^ n - 1) * (r - 1)β»ΒΉ) at_top (π ((0 - 1) * (r - 1)β»ΒΉ)),
from ((tendsto_pow_at_top_nhds_0_of_lt_1 hβ hβ).sub tendsto_const_nhds).mul tendsto_const_nhds,
(has_sum_iff_tendsto_nat_of_nonneg (pow_nonneg hβ) _).mpr $
by simp [neg_inv, geom_sum_eq, div_eq_mul_inv, *] at *
lemma summable_geometric_of_lt_1 {r : β} (hβ : 0 β€ r) (hβ : r < 1) : summable (Ξ»n:β, r ^ n) :=
β¨_, has_sum_geometric_of_lt_1 hβ hββ©
lemma tsum_geometric_of_lt_1 {r : β} (hβ : 0 β€ r) (hβ : r < 1) : β'n:β, r ^ n = (1 - r)β»ΒΉ :=
(has_sum_geometric_of_lt_1 hβ hβ).tsum_eq
lemma has_sum_geometric_two : has_sum (Ξ»n:β, ((1:β)/2) ^ n) 2 :=
by convert has_sum_geometric_of_lt_1 _ _; norm_num
lemma summable_geometric_two : summable (Ξ»n:β, ((1:β)/2) ^ n) :=
β¨_, has_sum_geometric_twoβ©
lemma summable_geometric_two_encode {ΞΉ : Type*} [encodable ΞΉ] :
summable (Ξ» (i : ΞΉ), (1/2 : β)^(encodable.encode i)) :=
summable_geometric_two.comp_injective encodable.encode_injective
lemma tsum_geometric_two : β'n:β, ((1:β)/2) ^ n = 2 :=
has_sum_geometric_two.tsum_eq
lemma sum_geometric_two_le (n : β) : β (i : β) in range n, (1 / (2 : β)) ^ i β€ 2 :=
begin
have : β i, 0 β€ (1 / (2 : β)) ^ i,
{ intro i, apply pow_nonneg, norm_num },
convert sum_le_tsum (range n) (Ξ» i _, this i) summable_geometric_two,
exact tsum_geometric_two.symm
end
lemma tsum_geometric_inv_two : β' n : β, (2 : β)β»ΒΉ ^ n = 2 :=
(inv_eq_one_div (2 : β)).symm βΈ tsum_geometric_two
/-- The sum of `2β»ΒΉ ^ i` for `n β€ i` equals `2 * 2β»ΒΉ ^ n`. -/
lemma tsum_geometric_inv_two_ge (n : β) :
β' i, ite (n β€ i) ((2 : β)β»ΒΉ ^ i) 0 = 2 * 2β»ΒΉ ^ n :=
begin
have A : summable (Ξ» (i : β), ite (n β€ i) ((2β»ΒΉ : β) ^ i) 0),
{ apply summable_of_nonneg_of_le _ _ summable_geometric_two;
{ intro i, by_cases hi : n β€ i; simp [hi] } },
have B : (finset.range n).sum (Ξ» (i : β), ite (n β€ i) ((2β»ΒΉ : β)^i) 0) = 0 :=
finset.sum_eq_zero (Ξ» i hi, ite_eq_right_iff.2 $ Ξ» h,
(lt_irrefl _ ((finset.mem_range.1 hi).trans_le h)).elim),
simp only [β sum_add_tsum_nat_add n A, B, if_true, zero_add, zero_le',
le_add_iff_nonneg_left, pow_add, tsum_mul_right, tsum_geometric_inv_two],
end
lemma has_sum_geometric_two' (a : β) : has_sum (Ξ»n:β, (a / 2) / 2 ^ n) a :=
begin
convert has_sum.mul_left (a / 2) (has_sum_geometric_of_lt_1
(le_of_lt one_half_pos) one_half_lt_one),
{ funext n, simp, refl, },
{ norm_num }
end
lemma summable_geometric_two' (a : β) : summable (Ξ» n:β, (a / 2) / 2 ^ n) :=
β¨a, has_sum_geometric_two' aβ©
lemma tsum_geometric_two' (a : β) : β' n:β, (a / 2) / 2^n = a :=
(has_sum_geometric_two' a).tsum_eq
/-- **Sum of a Geometric Series** -/
lemma nnreal.has_sum_geometric {r : ββ₯0} (hr : r < 1) :
has_sum (Ξ» n : β, r ^ n) (1 - r)β»ΒΉ :=
begin
apply nnreal.has_sum_coe.1,
push_cast,
rw [nnreal.coe_sub (le_of_lt hr)],
exact has_sum_geometric_of_lt_1 r.coe_nonneg hr
end
lemma nnreal.summable_geometric {r : ββ₯0} (hr : r < 1) : summable (Ξ»n:β, r ^ n) :=
β¨_, nnreal.has_sum_geometric hrβ©
lemma tsum_geometric_nnreal {r : ββ₯0} (hr : r < 1) : β'n:β, r ^ n = (1 - r)β»ΒΉ :=
(nnreal.has_sum_geometric hr).tsum_eq
/-- The series `pow r` converges to `(1-r)β»ΒΉ`. For `r < 1` the RHS is a finite number,
and for `1 β€ r` the RHS equals `β`. -/
@[simp] lemma ennreal.tsum_geometric (r : ββ₯0β) : β'n:β, r ^ n = (1 - r)β»ΒΉ :=
begin
cases lt_or_le r 1 with hr hr,
{ rcases ennreal.lt_iff_exists_coe.1 hr with β¨r, rfl, hr'β©,
norm_cast at *,
convert ennreal.tsum_coe_eq (nnreal.has_sum_geometric hr),
rw [ennreal.coe_inv $ ne_of_gt $ tsub_pos_iff_lt.2 hr] },
{ rw [tsub_eq_zero_iff_le.mpr hr, ennreal.inv_zero, ennreal.tsum_eq_supr_nat, supr_eq_top],
refine Ξ» a ha, (ennreal.exists_nat_gt (lt_top_iff_ne_top.1 ha)).imp
(Ξ» n hn, lt_of_lt_of_le hn _),
calc (n:ββ₯0β) = β i in range n, 1 : by rw [sum_const, nsmul_one, card_range]
... β€ β i in range n, r ^ i : sum_le_sum (Ξ» k _, one_le_pow_of_one_le' hr k) }
end
end geometric
/-!
### Sequences with geometrically decaying distance in metric spaces
In this paragraph, we discuss sequences in metric spaces or emetric spaces for which the distance
between two consecutive terms decays geometrically. We show that such sequences are Cauchy
sequences, and bound their distances to the limit. We also discuss series with geometrically
decaying terms.
-/
section edist_le_geometric
variables [pseudo_emetric_space Ξ±] (r C : ββ₯0β) (hr : r < 1) (hC : C β β€) {f : β β Ξ±}
(hu : βn, edist (f n) (f (n+1)) β€ C * r^n)
include hr hC hu
/-- If `edist (f n) (f (n+1))` is bounded by `C * r^n`, `C β β`, `r < 1`,
then `f` is a Cauchy sequence.-/
lemma cauchy_seq_of_edist_le_geometric : cauchy_seq f :=
begin
refine cauchy_seq_of_edist_le_of_tsum_ne_top _ hu _,
rw [ennreal.tsum_mul_left, ennreal.tsum_geometric],
refine ennreal.mul_ne_top hC (ennreal.inv_ne_top.2 _),
exact (tsub_pos_iff_lt.2 hr).ne'
end
omit hr hC
/-- If `edist (f n) (f (n+1))` is bounded by `C * r^n`, then the distance from
`f n` to the limit of `f` is bounded above by `C * r^n / (1 - r)`. -/
lemma edist_le_of_edist_le_geometric_of_tendsto {a : Ξ±} (ha : tendsto f at_top (π a)) (n : β) :
edist (f n) a β€ (C * r^n) / (1 - r) :=
begin
convert edist_le_tsum_of_edist_le_of_tendsto _ hu ha _,
simp only [pow_add, ennreal.tsum_mul_left, ennreal.tsum_geometric, div_eq_mul_inv, mul_assoc]
end
/-- If `edist (f n) (f (n+1))` is bounded by `C * r^n`, then the distance from
`f 0` to the limit of `f` is bounded above by `C / (1 - r)`. -/
lemma edist_le_of_edist_le_geometric_of_tendstoβ {a : Ξ±} (ha : tendsto f at_top (π a)) :
edist (f 0) a β€ C / (1 - r) :=
by simpa only [pow_zero, mul_one] using edist_le_of_edist_le_geometric_of_tendsto r C hu ha 0
end edist_le_geometric
section edist_le_geometric_two
variables [pseudo_emetric_space Ξ±] (C : ββ₯0β) (hC : C β β€) {f : β β Ξ±}
(hu : βn, edist (f n) (f (n+1)) β€ C / 2^n) {a : Ξ±} (ha : tendsto f at_top (π a))
include hC hu
/-- If `edist (f n) (f (n+1))` is bounded by `C * 2^-n`, then `f` is a Cauchy sequence.-/
lemma cauchy_seq_of_edist_le_geometric_two : cauchy_seq f :=
begin
simp only [div_eq_mul_inv, ennreal.inv_pow] at hu,
refine cauchy_seq_of_edist_le_geometric 2β»ΒΉ C _ hC hu,
simp [ennreal.one_lt_two]
end
omit hC
include ha
/-- If `edist (f n) (f (n+1))` is bounded by `C * 2^-n`, then the distance from
`f n` to the limit of `f` is bounded above by `2 * C * 2^-n`. -/
lemma edist_le_of_edist_le_geometric_two_of_tendsto (n : β) :
edist (f n) a β€ 2 * C / 2^n :=
begin
simp only [div_eq_mul_inv, ennreal.inv_pow] at *,
rw [mul_assoc, mul_comm],
convert edist_le_of_edist_le_geometric_of_tendsto 2β»ΒΉ C hu ha n,
rw [ennreal.one_sub_inv_two, inv_inv]
end
/-- If `edist (f n) (f (n+1))` is bounded by `C * 2^-n`, then the distance from
`f 0` to the limit of `f` is bounded above by `2 * C`. -/
lemma edist_le_of_edist_le_geometric_two_of_tendstoβ: edist (f 0) a β€ 2 * C :=
by simpa only [pow_zero, div_eq_mul_inv, ennreal.inv_one, mul_one]
using edist_le_of_edist_le_geometric_two_of_tendsto C hu ha 0
end edist_le_geometric_two
section le_geometric
variables [pseudo_metric_space Ξ±] {r C : β} (hr : r < 1) {f : β β Ξ±}
(hu : βn, dist (f n) (f (n+1)) β€ C * r^n)
include hr hu
lemma aux_has_sum_of_le_geometric : has_sum (Ξ» n : β, C * r^n) (C / (1 - r)) :=
begin
rcases sign_cases_of_C_mul_pow_nonneg (Ξ» n, dist_nonneg.trans (hu n)) with rfl | β¨Cβ, rββ©,
{ simp [has_sum_zero] },
{ refine has_sum.mul_left C _,
simpa using has_sum_geometric_of_lt_1 rβ hr }
end
variables (r C)
/-- If `dist (f n) (f (n+1))` is bounded by `C * r^n`, `r < 1`, then `f` is a Cauchy sequence.
Note that this lemma does not assume `0 β€ C` or `0 β€ r`. -/
lemma cauchy_seq_of_le_geometric : cauchy_seq f :=
cauchy_seq_of_dist_le_of_summable _ hu β¨_, aux_has_sum_of_le_geometric hr huβ©
/-- If `dist (f n) (f (n+1))` is bounded by `C * r^n`, `r < 1`, then the distance from
`f n` to the limit of `f` is bounded above by `C * r^n / (1 - r)`. -/
lemma dist_le_of_le_geometric_of_tendstoβ {a : Ξ±} (ha : tendsto f at_top (π a)) :
dist (f 0) a β€ C / (1 - r) :=
(aux_has_sum_of_le_geometric hr hu).tsum_eq βΈ
dist_le_tsum_of_dist_le_of_tendstoβ _ hu β¨_, aux_has_sum_of_le_geometric hr huβ© ha
/-- If `dist (f n) (f (n+1))` is bounded by `C * r^n`, `r < 1`, then the distance from
`f 0` to the limit of `f` is bounded above by `C / (1 - r)`. -/
lemma dist_le_of_le_geometric_of_tendsto {a : Ξ±} (ha : tendsto f at_top (π a)) (n : β) :
dist (f n) a β€ (C * r^n) / (1 - r) :=
begin
have := aux_has_sum_of_le_geometric hr hu,
convert dist_le_tsum_of_dist_le_of_tendsto _ hu β¨_, thisβ© ha n,
simp only [pow_add, mul_left_comm C, mul_div_right_comm],
rw [mul_comm],
exact (this.mul_left _).tsum_eq.symm
end
omit hr hu
variable (huβ : β n, dist (f n) (f (n+1)) β€ (C / 2) / 2^n)
/-- If `dist (f n) (f (n+1))` is bounded by `(C / 2) / 2^n`, then `f` is a Cauchy sequence. -/
lemma cauchy_seq_of_le_geometric_two : cauchy_seq f :=
cauchy_seq_of_dist_le_of_summable _ huβ $ β¨_, has_sum_geometric_two' Cβ©
/-- If `dist (f n) (f (n+1))` is bounded by `(C / 2) / 2^n`, then the distance from
`f 0` to the limit of `f` is bounded above by `C`. -/
lemma dist_le_of_le_geometric_two_of_tendstoβ {a : Ξ±} (ha : tendsto f at_top (π a)) :
dist (f 0) a β€ C :=
(tsum_geometric_two' C) βΈ dist_le_tsum_of_dist_le_of_tendstoβ _ huβ (summable_geometric_two' C) ha
include huβ
/-- If `dist (f n) (f (n+1))` is bounded by `(C / 2) / 2^n`, then the distance from
`f n` to the limit of `f` is bounded above by `C / 2^n`. -/
lemma dist_le_of_le_geometric_two_of_tendsto {a : Ξ±} (ha : tendsto f at_top (π a)) (n : β) :
dist (f n) a β€ C / 2^n :=
begin
convert dist_le_tsum_of_dist_le_of_tendsto _ huβ (summable_geometric_two' C) ha n,
simp only [add_comm n, pow_add, β div_div],
symmetry,
exact ((has_sum_geometric_two' C).div_const _).tsum_eq
end
end le_geometric
/-! ### Summability tests based on comparison with geometric series -/
/-- A series whose terms are bounded by the terms of a converging geometric series converges. -/
lemma summable_one_div_pow_of_le {m : β} {f : β β β} (hm : 1 < m) (fi : β i, i β€ f i) :
summable (Ξ» i, 1 / m ^ f i) :=
begin
refine summable_of_nonneg_of_le
(Ξ» a, one_div_nonneg.mpr (pow_nonneg (zero_le_one.trans hm.le) _)) (Ξ» a, _)
(summable_geometric_of_lt_1 (one_div_nonneg.mpr (zero_le_one.trans hm.le))
((one_div_lt (zero_lt_one.trans hm) zero_lt_one).mpr (one_div_one.le.trans_lt hm))),
rw [div_pow, one_pow],
refine (one_div_le_one_div _ _).mpr (pow_le_pow hm.le (fi a));
exact pow_pos (zero_lt_one.trans hm) _
end
/-! ### Positive sequences with small sums on countable types -/
/-- For any positive `Ξ΅`, define on an encodable type a positive sequence with sum less than `Ξ΅` -/
def pos_sum_of_encodable {Ξ΅ : β} (hΞ΅ : 0 < Ξ΅)
(ΞΉ) [encodable ΞΉ] : {Ξ΅' : ΞΉ β β // (β i, 0 < Ξ΅' i) β§ β c, has_sum Ξ΅' c β§ c β€ Ξ΅} :=
begin
let f := Ξ» n, (Ξ΅ / 2) / 2 ^ n,
have hf : has_sum f Ξ΅ := has_sum_geometric_two' _,
have f0 : β n, 0 < f n := Ξ» n, div_pos (half_pos hΞ΅) (pow_pos zero_lt_two _),
refine β¨f β encodable.encode, Ξ» i, f0 _, _β©,
rcases hf.summable.comp_injective (@encodable.encode_injective ΞΉ _) with β¨c, hgβ©,
refine β¨c, hg, has_sum_le_inj _ (@encodable.encode_injective ΞΉ _) _ _ hg hfβ©,
{ assume i _, exact le_of_lt (f0 _) },
{ assume n, exact le_rfl }
end
lemma set.countable.exists_pos_has_sum_le {ΞΉ : Type*} {s : set ΞΉ} (hs : s.countable)
{Ξ΅ : β} (hΞ΅ : 0 < Ξ΅) :
β Ξ΅' : ΞΉ β β, (β i, 0 < Ξ΅' i) β§ β c, has_sum (Ξ» i : s, Ξ΅' i) c β§ c β€ Ξ΅ :=
begin
haveI := hs.to_encodable,
rcases pos_sum_of_encodable hΞ΅ s with β¨f, hf0, β¨c, hfc, hcΞ΅β©β©,
refine β¨Ξ» i, if h : i β s then f β¨i, hβ© else 1, Ξ» i, _, β¨c, _, hcΞ΅β©β©,
{ split_ifs, exacts [hf0 _, zero_lt_one] },
{ simpa only [subtype.coe_prop, dif_pos, subtype.coe_eta] }
end
lemma set.countable.exists_pos_forall_sum_le {ΞΉ : Type*} {s : set ΞΉ} (hs : s.countable)
{Ξ΅ : β} (hΞ΅ : 0 < Ξ΅) :
β Ξ΅' : ΞΉ β β, (β i, 0 < Ξ΅' i) β§ β t : finset ΞΉ, βt β s β β i in t, Ξ΅' i β€ Ξ΅ :=
begin
rcases hs.exists_pos_has_sum_le hΞ΅ with β¨Ξ΅', hpos, c, hΞ΅'c, hcΞ΅β©,
refine β¨Ξ΅', hpos, Ξ» t ht, _β©,
rw [β sum_subtype_of_mem _ ht],
refine (sum_le_has_sum _ _ hΞ΅'c).trans hcΞ΅,
exact Ξ» _ _, (hpos _).le
end
namespace nnreal
theorem exists_pos_sum_of_countable {Ξ΅ : ββ₯0} (hΞ΅ : Ξ΅ β 0) (ΞΉ) [countable ΞΉ] :
β Ξ΅' : ΞΉ β ββ₯0, (β i, 0 < Ξ΅' i) β§ βc, has_sum Ξ΅' c β§ c < Ξ΅ :=
begin
casesI nonempty_encodable ΞΉ,
obtain β¨a, a0, aΞ΅β© := exists_between (pos_iff_ne_zero.2 hΞ΅),
obtain β¨Ξ΅', hΞ΅', c, hc, hcΞ΅β© := pos_sum_of_encodable a0 ΞΉ,
exact β¨Ξ» i, β¨Ξ΅' i, (hΞ΅' i).leβ©, Ξ» i, nnreal.coe_lt_coe.1 $ hΞ΅' i, β¨c, has_sum_le (Ξ» i, (hΞ΅' i).le)
has_sum_zero hcβ©, nnreal.has_sum_coe.1 hc, aΞ΅.trans_le' $ nnreal.coe_le_coe.1 hcΞ΅β©,
end
end nnreal
namespace ennreal
theorem exists_pos_sum_of_countable {Ξ΅ : ββ₯0β} (hΞ΅ : Ξ΅ β 0) (ΞΉ) [countable ΞΉ] :
β Ξ΅' : ΞΉ β ββ₯0, (β i, 0 < Ξ΅' i) β§ β' i, (Ξ΅' i : ββ₯0β) < Ξ΅ :=
begin
rcases exists_between (pos_iff_ne_zero.2 hΞ΅) with β¨r, h0r, hrΞ΅β©,
rcases lt_iff_exists_coe.1 hrΞ΅ with β¨x, rfl, hxβ©,
rcases nnreal.exists_pos_sum_of_countable (coe_pos.1 h0r).ne' ΞΉ with β¨Ξ΅', hp, c, hc, hcrβ©,
exact β¨Ξ΅', hp, (ennreal.tsum_coe_eq hc).symm βΈ lt_trans (coe_lt_coe.2 hcr) hrΞ΅β©
end
theorem exists_pos_sum_of_countable' {Ξ΅ : ββ₯0β} (hΞ΅ : Ξ΅ β 0) (ΞΉ) [countable ΞΉ] :
β Ξ΅' : ΞΉ β ββ₯0β, (β i, 0 < Ξ΅' i) β§ (β' i, Ξ΅' i) < Ξ΅ :=
let β¨Ξ΄, Ξ΄pos, hΞ΄β© := exists_pos_sum_of_countable hΞ΅ ΞΉ in
β¨Ξ» i, Ξ΄ i, Ξ» i, ennreal.coe_pos.2 (Ξ΄pos i), hΞ΄β©
theorem exists_pos_tsum_mul_lt_of_countable {Ξ΅ : ββ₯0β} (hΞ΅ : Ξ΅ β 0) {ΞΉ} [countable ΞΉ]
(w : ΞΉ β ββ₯0β) (hw : β i, w i β β) :
β Ξ΄ : ΞΉ β ββ₯0, (β i, 0 < Ξ΄ i) β§ β' i, (w i * Ξ΄ i : ββ₯0β) < Ξ΅ :=
begin
lift w to ΞΉ β ββ₯0 using hw,
rcases exists_pos_sum_of_countable hΞ΅ ΞΉ with β¨Ξ΄', Hpos, Hsumβ©,
have : β i, 0 < max 1 (w i), from Ξ» i, zero_lt_one.trans_le (le_max_left _ _),
refine β¨Ξ» i, Ξ΄' i / max 1 (w i), Ξ» i, nnreal.div_pos (Hpos _) (this i), _β©,
refine lt_of_le_of_lt (ennreal.tsum_le_tsum $ Ξ» i, _) Hsum,
rw [coe_div (this i).ne'],
refine mul_le_of_le_div' (ennreal.mul_le_mul le_rfl $ ennreal.inv_le_inv.2 _),
exact coe_le_coe.2 (le_max_right _ _)
end
end ennreal
/-!
### Factorial
-/
lemma factorial_tendsto_at_top : tendsto nat.factorial at_top at_top :=
tendsto_at_top_at_top_of_monotone nat.monotone_factorial (Ξ» n, β¨n, n.self_le_factorialβ©)
lemma tendsto_factorial_div_pow_self_at_top : tendsto (Ξ» n, n! / n^n : β β β) at_top (π 0) :=
tendsto_of_tendsto_of_tendsto_of_le_of_le'
tendsto_const_nhds
(tendsto_const_div_at_top_nhds_0_nat 1)
(eventually_of_forall $ Ξ» n, div_nonneg (by exact_mod_cast n.factorial_pos.le)
(pow_nonneg (by exact_mod_cast n.zero_le) _))
begin
refine (eventually_gt_at_top 0).mono (Ξ» n hn, _),
rcases nat.exists_eq_succ_of_ne_zero hn.ne.symm with β¨k, rflβ©,
rw [β prod_range_add_one_eq_factorial, pow_eq_prod_const, div_eq_mul_inv, β inv_eq_one_div,
prod_nat_cast, nat.cast_succ, β prod_inv_distrib, β prod_mul_distrib,
finset.prod_range_succ'],
simp only [prod_range_succ', one_mul, nat.cast_add, zero_add, nat.cast_one],
refine mul_le_of_le_one_left (inv_nonneg.mpr $ by exact_mod_cast hn.le) (prod_le_one _ _);
intros x hx; rw finset.mem_range at hx,
{ refine mul_nonneg _ (inv_nonneg.mpr _); norm_cast; linarith },
{ refine (div_le_one $ by exact_mod_cast hn).mpr _, norm_cast, linarith }
end
/-!
### Ceil and floor
-/
section
lemma tendsto_nat_floor_at_top {Ξ± : Type*} [linear_ordered_semiring Ξ±] [floor_semiring Ξ±] :
tendsto (Ξ» (x : Ξ±), βxββ) at_top at_top :=
nat.floor_mono.tendsto_at_top_at_top (Ξ» x, β¨max 0 (x + 1), by simp [nat.le_floor_iff]β©)
variables {R : Type*} [topological_space R] [linear_ordered_field R] [order_topology R]
[floor_ring R]
lemma tendsto_nat_floor_mul_div_at_top {a : R} (ha : 0 β€ a) :
tendsto (Ξ» x, (βa * xββ : R) / x) at_top (π a) :=
begin
have A : tendsto (Ξ» (x : R), a - xβ»ΒΉ) at_top (π (a - 0)) :=
tendsto_const_nhds.sub tendsto_inv_at_top_zero,
rw sub_zero at A,
apply tendsto_of_tendsto_of_tendsto_of_le_of_le' A tendsto_const_nhds,
{ refine eventually_at_top.2 β¨1, Ξ» x hx, _β©,
simp only [le_div_iff (zero_lt_one.trans_le hx), sub_mul,
inv_mul_cancel (zero_lt_one.trans_le hx).ne'],
have := nat.lt_floor_add_one (a * x),
linarith },
{ refine eventually_at_top.2 β¨1, Ξ» x hx, _β©,
rw div_le_iff (zero_lt_one.trans_le hx),
simp [nat.floor_le (mul_nonneg ha (zero_le_one.trans hx))] }
end
lemma tendsto_nat_floor_div_at_top :
tendsto (Ξ» x, (βxββ : R) / x) at_top (π 1) :=
by simpa using tendsto_nat_floor_mul_div_at_top (zero_le_one' R)
lemma tendsto_nat_ceil_mul_div_at_top {a : R} (ha : 0 β€ a) :
tendsto (Ξ» x, (βa * xββ : R) / x) at_top (π a) :=
begin
have A : tendsto (Ξ» (x : R), a + xβ»ΒΉ) at_top (π (a + 0)) :=
tendsto_const_nhds.add tendsto_inv_at_top_zero,
rw add_zero at A,
apply tendsto_of_tendsto_of_tendsto_of_le_of_le' tendsto_const_nhds A,
{ refine eventually_at_top.2 β¨1, Ξ» x hx, _β©,
rw le_div_iff (zero_lt_one.trans_le hx),
exact nat.le_ceil _ },
{ refine eventually_at_top.2 β¨1, Ξ» x hx, _β©,
simp [div_le_iff (zero_lt_one.trans_le hx), inv_mul_cancel (zero_lt_one.trans_le hx).ne',
(nat.ceil_lt_add_one ((mul_nonneg ha (zero_le_one.trans hx)))).le, add_mul] }
end
lemma tendsto_nat_ceil_div_at_top :
tendsto (Ξ» x, (βxββ : R) / x) at_top (π 1) :=
by simpa using tendsto_nat_ceil_mul_div_at_top (zero_le_one' R)
end
|
d88d33da5144d80ff5a6ac88655f22b06cb86caa | e1da55f4222dac91b940ca052928eaace09762da | /src/finpartition.lean | a3ccf0bc7fd63d376b60472eb828f6bba98ca830 | [] | no_license | b-mehta/regularity-lemma | c5826e22c280d0b073a4e62dba731f4dd3d1b69f | cf26082b0c88fa54276e6fdc3338c15e607c52c6 | refs/heads/master | 1,658,209,524,267 | 1,644,406,456,000 | 1,644,406,456,000 | 457,327,371 | 1 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 18,248 | lean | /-
Copyright (c) 2022 YaΓ«l Dillies, Bhavik Mehta. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: YaΓ«l Dillies, Bhavik Mehta
-/
import algebra.big_operators.basic
import order.locally_finite
import order.atoms
import order.sup_indep
/-!
# Finite partitions
In this file, we define finite partitions. A finpartition of `a : Ξ±` is a finite set of pairwise
disjoint parts `parts : finset Ξ±` which does not contain `β₯` and whose supremum is `a`.
## Constructions
We provide many ways to build finpartitions:
* `finpartition.of_erase`: Builds a finpartition by erasing `β₯` for you.
* `finpartition.of_subset`: Builds a finpartition from a subset of the parts of a previous
finpartition.
* `finpartition.empty`: The empty finpartition of `β₯`.
* `finpartition.indiscrete`: The indiscrete, aka trivial, aka pure, finpartition made of a single
part.
* `finpartition.discrete`: The discrete finpartition of `s : finset Ξ±` made of singletons.
* `finpartition.bind`: Puts together the finpartitions of the parts of a finpartition into a new
finpartition.
* `finpartition.atomise`: Makes a finpartition of `s : finset Ξ±` by breaking `s` along all finsets
in `F : finset (finset Ξ±)`. Two elements of `s` belong to the same part iff they belong to the
same elements of `F`.
`finpartition.indiscrete` and `finpartition.bind` together form the monadic structure of
`finpartition`.
## Implementation notes
Forbidding `β₯` as a part follows mathematical tradition and is a pragmatic choice concerning
operations on `finpartition`. Not caring about `β₯` being a part or not breaks extensionality (it's
not because the parts of `P` and the parts of `Q` have the same elements that `P = Q`). Enforcing
`β₯` to be a part makes `finpartition.bind` uglier and doesn't rid us of the need of
`finpartition.of_erase`.
## TODO
Link `finpartition` and `setoid.is_partition`.
The order is the wrong way around to make `finpartition a` a graded order. Is it bad to depart from
the literature and turn the order around?
-/
lemma set.pairwise_disjoint.eq_of_le {Ξ± ΞΉ : Type*} [semilattice_inf Ξ±] [order_bot Ξ±] {s : set ΞΉ}
{f : ΞΉ β Ξ±} (hs : s.pairwise_disjoint f) {i j : ΞΉ} (hi : i β s) (hj : j β s)
(h : f i β β₯) (hf : f i β€ f j) :
i = j :=
begin
classical,
by_contra hij,
exact h ((hs hi hj hij).eq_bot_of_le hf),
end
instance {Ξ± ΞΉ : Type*} [lattice Ξ±] [order_bot Ξ±] {s t : finset ΞΉ} {f : ΞΉ β Ξ±} {i : ΞΉ}
[decidable_eq ΞΉ] [decidable_eq Ξ±] : decidable (s.sup_indep f) :=
begin
apply @finset.decidable_forall_of_decidable_subsets _ _ _ _,
intros t ht,
apply @finset.decidable_dforall_finset _ _ _ _,
exact Ξ» i hi, @implies.decidable _ _ _ (decidable_of_iff' (_ = β₯) disjoint_iff),
end
open finset function
open_locale big_operators
variables {Ξ± : Type*}
/-- A finite partition of `a : Ξ±` is a pairwise disjoint finite set of elements whose supremum is
`a`. We forbid `β₯` as a part. -/
@[ext, derive decidable_eq] structure finpartition [lattice Ξ±] [order_bot Ξ±] (a : Ξ±) :=
(parts : finset Ξ±)
(sup_indep : parts.sup_indep id)
(sup_parts : parts.sup id = a)
(not_bot_mem : β₯ β parts)
attribute [protected] finpartition.sup_indep
namespace finpartition
section lattice
variables [lattice Ξ±] [order_bot Ξ±]
/-- A `finpartition` constructor which does not insist on `β₯` not being a part. -/
@[simps] def of_erase [decidable_eq Ξ±] {a : Ξ±} (parts : finset Ξ±)
(sup_indep : parts.sup_indep id) (sup_parts : parts.sup id = a) :
finpartition a :=
{ parts := parts.erase β₯,
sup_indep := sup_indep.subset (erase_subset _ _),
sup_parts := (sup_erase_bot _).trans sup_parts,
not_bot_mem := not_mem_erase _ _ }
/-- A `finpartition` constructor from a bigger existing finpartition. -/
@[simps] def of_subset {a b : Ξ±} (P : finpartition a) {parts : finset Ξ±}
(subset : parts β P.parts) (sup_parts : parts.sup id = b) :
finpartition b :=
{ parts := parts,
sup_indep := P.sup_indep.subset subset,
sup_parts := sup_parts,
not_bot_mem := Ξ» h, P.not_bot_mem (subset h) }
/-- Changes the type of a finpartition to an equal one. -/
@[simps] def copy {a b : Ξ±} (P : finpartition a) (h : a = b) : finpartition b :=
{ parts := P.parts,
sup_indep := P.sup_indep,
sup_parts := h βΈ P.sup_parts,
not_bot_mem := P.not_bot_mem }
variables (Ξ±)
/-- The empty finpartition. -/
@[simps] protected def empty : finpartition (β₯ : Ξ±) :=
{ parts := β
,
sup_indep := sup_indep_empty _,
sup_parts := finset.sup_empty,
not_bot_mem := not_mem_empty β₯ }
instance : inhabited (finpartition (β₯ : Ξ±)) := β¨finpartition.empty Ξ±β©
@[simp] lemma default_eq_empty : (default : finpartition (β₯ : Ξ±)) = finpartition.empty Ξ± := rfl
variables {Ξ±} {a : Ξ±}
/-- The finpartition in one part, aka indiscrete finpartition. -/
@[simps] def indiscrete (ha : a β β₯) : finpartition a :=
{ parts := {a},
sup_indep := sup_indep_singleton _ _,
sup_parts := finset.sup_singleton,
not_bot_mem := Ξ» h, ha (mem_singleton.1 h).symm }
variables (P : finpartition a)
protected lemma le {b : Ξ±} (hb : b β P.parts) : b β€ a := (le_sup hb).trans P.sup_parts.le
lemma ne_bot {b : Ξ±} (hb : b β P.parts) : b β β₯ := Ξ» h, P.not_bot_mem $ h.subst hb
protected lemma disjoint : (P.parts : set Ξ±).pairwise_disjoint id := P.sup_indep.pairwise_disjoint
variables {P}
lemma parts_eq_empty_iff : P.parts = β
β a = β₯ :=
begin
simp_rw βP.sup_parts,
refine β¨Ξ» h, _, Ξ» h, eq_empty_iff_forall_not_mem.2 (Ξ» b hb, P.not_bot_mem _)β©,
{ rw h,
exact finset.sup_empty },
{ rwa βle_bot_iff.1 ((le_sup hb).trans h.le) }
end
lemma parts_nonempty_iff : P.parts.nonempty β a β β₯ :=
by rw [nonempty_iff_ne_empty, not_iff_not, parts_eq_empty_iff]
lemma parts_nonempty (P : finpartition a) (ha : a β β₯) : P.parts.nonempty := parts_nonempty_iff.2 ha
instance : unique (finpartition (β₯ : Ξ±)) :=
{ uniq := Ξ» P,
by { ext a, exact iff_of_false (Ξ» h, P.ne_bot h $ le_bot_iff.1 $ P.le h) (not_mem_empty a) },
..finpartition.inhabited Ξ± }
/-- There's a unique partition of an atom. -/
@[reducible] -- See note [reducible non instances]
def _root_.is_atom.unique_finpartition (ha : is_atom a) : unique (finpartition a) :=
{ default := indiscrete ha.1,
uniq := Ξ» P, begin
have h : β b β P.parts, b = a,
{ exact Ξ» b hb, (eq_bot_or_eq_of_le_atom ha $ P.le hb).resolve_left (P.ne_bot hb) },
ext b,
refine iff.trans β¨h b, _β© mem_singleton.symm,
rintro rfl,
obtain β¨c, hcβ© := P.parts_nonempty ha.1,
simp_rw βh c hc,
exact hc,
end }
/-! ### Refinement order -/
section order
/-- We say that `P β€ Q` if `P` refines `Q`: each part of `P` is less than some part of `Q`. -/
instance : has_le (finpartition a) := β¨Ξ» P Q, β β¦bβ¦, b β P.parts β β c β Q.parts, b β€ cβ©
instance : partial_order (finpartition a) :=
{ le_refl := Ξ» P b hb, β¨b, hb, le_rflβ©,
le_trans := Ξ» P Q R hPQ hQR b hb, begin
obtain β¨c, hc, hbcβ© := hPQ hb,
obtain β¨d, hd, hcdβ© := hQR hc,
exact β¨d, hd, hbc.trans hcdβ©,
end,
le_antisymm := Ξ» P Q hPQ hQP, begin
ext b,
refine β¨Ξ» hb, _, Ξ» hb, _β©,
{ obtain β¨c, hc, hbcβ© := hPQ hb,
obtain β¨d, hd, hcdβ© := hQP hc,
rwa hbc.antisymm,
rwa P.disjoint.eq_of_le hb hd (P.ne_bot hb) (hbc.trans hcd) },
{ obtain β¨c, hc, hbcβ© := hQP hb,
obtain β¨d, hd, hcdβ© := hPQ hc,
rwa hbc.antisymm,
rwa Q.disjoint.eq_of_le hb hd (Q.ne_bot hb) (hbc.trans hcd) }
end,
..finpartition.has_le }
instance [decidable (a = β₯)] : order_top (finpartition a) :=
{ top := if ha : a = β₯ then (finpartition.empty Ξ±).copy ha.symm else indiscrete ha,
le_top := Ξ» P,
begin
split_ifs,
{ intros x hx,
simpa [h, P.ne_bot hx] using P.le hx },
{ exact Ξ» b hb, β¨a, mem_singleton_self _, P.le hbβ© }
end }
end order
end lattice
section distrib_lattice
variables [distrib_lattice Ξ±] [order_bot Ξ±] [decidable_eq Ξ±] {a b c : Ξ±}
instance : has_inf (finpartition a) :=
β¨Ξ» P Q, of_erase ((P.parts.product Q.parts).image $ Ξ» bc, bc.1 β bc.2)
begin
rw sup_indep_iff_disjoint_erase,
simp only [mem_image, and_imp, exists_prop, forall_exists_index, id.def, prod.exists,
mem_product, finset.disjoint_sup_right, mem_erase, ne.def],
rintro _ xβ yβ hxβ hyβ rfl _ h xβ yβ hxβ hyβ rfl,
rcases eq_or_ne xβ xβ with rfl | xdiff,
{ refine disjoint.mono inf_le_right inf_le_right (Q.disjoint hyβ hyβ _),
intro t,
simpa [t] using h },
exact disjoint.mono inf_le_left inf_le_left (P.disjoint hxβ hxβ xdiff),
end
begin
rw [sup_image, comp.left_id, sup_product_left],
transitivity P.parts.sup id β Q.parts.sup id,
{ simp_rw [finset.sup_inf_distrib_right, finset.sup_inf_distrib_left],
refl },
{ rw [P.sup_parts, Q.sup_parts, inf_idem] }
endβ©
@[simp] lemma parts_inf (P Q : finpartition a) :
(P β Q).parts = ((P.parts.product Q.parts).image $ Ξ» bc : Ξ± Γ Ξ±, bc.1 β bc.2).erase β₯ := rfl
instance : semilattice_inf (finpartition a) :=
{ inf_le_left := Ξ» P Q b hb, begin
obtain β¨c, hc, rflβ© := mem_image.1 (mem_of_mem_erase hb),
rw mem_product at hc,
exact β¨c.1, hc.1, inf_le_leftβ©,
end,
inf_le_right := Ξ» P Q b hb, begin
obtain β¨c, hc, rflβ© := mem_image.1 (mem_of_mem_erase hb),
rw mem_product at hc,
exact β¨c.2, hc.2, inf_le_rightβ©,
end,
le_inf := Ξ» P Q R hPQ hPR b hb, begin
obtain β¨c, hc, hbcβ© := hPQ hb,
obtain β¨d, hd, hbdβ© := hPR hb,
have h := _root_.le_inf hbc hbd,
refine β¨c β d, mem_erase_of_ne_of_mem (ne_bot_of_le_ne_bot (P.ne_bot hb) h)
(mem_image.2 β¨(c, d), mem_product.2 β¨hc, hdβ©, rflβ©), hβ©,
end,
..finpartition.partial_order, ..finpartition.has_inf }
lemma exists_le_of_le {P Q : finpartition a} (h : P β€ Q) (hb : b β Q.parts) :
β c β P.parts, c β€ b :=
begin
by_contra' H,
refine Q.ne_bot hb (disjoint_self.1 $ disjoint.mono_right (Q.le hb) _),
rw [βP.sup_parts, finset.disjoint_sup_right],
rintro c hc,
obtain β¨d, hd, hcdβ© := h hc,
refine (Q.disjoint hb hd _).mono_right hcd,
rintro rfl,
exact H _ hc hcd,
end
lemma card_mono {P Q : finpartition a} (h : P β€ Q) : Q.parts.card β€ P.parts.card :=
begin
classical,
have : β b β Q.parts, β c β P.parts, c β€ b := Ξ» b, exists_le_of_le h,
choose f hP hf using this,
rw βcard_attach,
refine card_le_card_of_inj_on (Ξ» b, f _ b.2) (Ξ» b _, hP _ b.2) (Ξ» b hb c hc h, _),
exact subtype.coe_injective (Q.disjoint.elim b.2 c.2 $ Ξ» H, P.ne_bot (hP _ b.2) $
disjoint_self.1 $ H.mono (hf _ b.2) $ h.le.trans $ hf _ c.2),
end
section bind
variables {a} {P : finpartition a} {Q : Ξ i β P.parts, finpartition i}
/-- Given a finpartition `P` of `a` and finpartitions of each part of `P`, this yields the
finpartition of `a` obtained by juxtaposing all the subpartitions. -/
@[simps] def bind (P : finpartition a) (Q : Ξ i β P.parts, finpartition i) : finpartition a :=
{ parts := P.parts.attach.bUnion (Ξ» i, (Q i.1 i.2).parts),
sup_indep := begin
rw sup_indep_iff_pairwise_disjoint,
rintro a ha b hb h,
rw [finset.mem_coe, finset.mem_bUnion] at ha hb,
obtain β¨β¨A, hAβ©, -, haβ© := ha,
obtain β¨β¨B, hBβ©, -, hbβ© := hb,
obtain rfl | hAB := eq_or_ne A B,
{ exact (Q A hA).disjoint ha hb h },
{ exact (P.disjoint hA hB hAB).mono ((Q A hA).le ha) ((Q B hB).le hb) }
end,
sup_parts := begin
simp_rw [sup_bUnion, βP.sup_parts],
rw [eq_comm, βfinset.sup_attach],
exact sup_congr rfl (Ξ» b hb, (Q b.1 b.2).sup_parts.symm),
end,
not_bot_mem := Ξ» h, begin
rw finset.mem_bUnion at h,
obtain β¨β¨A, hAβ©, -, hβ© := h,
exact (Q A hA).not_bot_mem h,
end }
lemma mem_bind : b β (P.bind Q).parts β β A hA, b β (Q A hA).parts :=
begin
rw [bind, mem_bUnion],
split,
{ rintro β¨β¨A, hAβ©, -, hβ©,
exact β¨A, hA, hβ© },
{ rintro β¨A, hA, hβ©,
exact β¨β¨A, hAβ©, mem_attach _ β¨A, hAβ©, hβ© }
end
lemma card_bind (Q : Ξ i β P.parts, finpartition i) :
(P.bind Q).parts.card = β A in P.parts.attach, (Q _ A.2).parts.card :=
begin
apply card_bUnion,
rintro β¨b, hbβ© - β¨c, hcβ© - hbc d,
rw [inf_eq_inter, mem_inter],
rintro β¨hdb, hdcβ©,
rw [ne.def, subtype.mk_eq_mk] at hbc,
exact (Q b hb).ne_bot hdb (eq_bot_iff.2 $
(le_inf ((Q b hb).le hdb) $ (Q c hc).le hdc).trans $ P.disjoint hb hc hbc),
end
end bind
/-- Adds `b` to a finpartition of `a` to make a finpartition of `a β b`. -/
@[simps] def extend (P : finpartition a) (hb : b β β₯) (hab : disjoint a b) (hc : a β b = c) :
finpartition c :=
{ parts := insert b P.parts,
sup_indep :=
begin
rw [sup_indep_iff_pairwise_disjoint, coe_insert],
exact P.disjoint.insert (Ξ» d hd hbd, hab.symm.mono_right $ P.le hd),
end,
sup_parts := by rwa [sup_insert, P.sup_parts, id, _root_.sup_comm],
not_bot_mem := Ξ» h, (mem_insert.1 h).elim hb.symm P.not_bot_mem }
lemma card_extend (P : finpartition a) (b c : Ξ±) {hb : b β β₯} {hab : disjoint a b}
{hc : a β b = c} :
(P.extend hb hab hc).parts.card = P.parts.card + 1 :=
card_insert_of_not_mem $ Ξ» h, hb $ hab.symm.eq_bot_of_le $ P.le h
end distrib_lattice
section generalized_boolean_algebra
variables [generalized_boolean_algebra Ξ±] [decidable_eq Ξ±] {a : Ξ±} (P : finpartition a)
/-- Restricts a finpartition to avoid a given element. -/
@[simps] def avoid (b : Ξ±) : finpartition (a \ b) :=
of_erase
(P.parts.image (\ b))
(P.disjoint.image_finset_of_le $ Ξ» a, sdiff_le).sup_indep
(begin
rw [sup_image, comp.left_id, finset.sup_sdiff_right],
congr,
exact P.sup_parts,
end)
end generalized_boolean_algebra
end finpartition
/-! ### Finite partitions of finsets -/
namespace finpartition
variables [decidable_eq Ξ±] {s t : finset Ξ±} (P : finpartition s)
lemma nonempty_of_mem_parts {a : finset Ξ±} (ha : a β P.parts) : a.nonempty :=
nonempty_iff_ne_empty.2 $ P.ne_bot ha
lemma exists_mem {a : Ξ±} (ha : a β s) : β t β P.parts, a β t :=
by { simp_rw βP.sup_parts at ha, exact mem_sup.1 ha }
lemma bUnion_parts : P.parts.bUnion id = s := (sup_eq_bUnion _ _).symm.trans P.sup_parts
lemma sum_card_parts : β i in P.parts, i.card = s.card :=
begin
convert congr_arg finset.card P.bUnion_parts,
rw card_bUnion P.sup_indep.pairwise_disjoint,
refl,
end
/-- `β₯` is the partition in singletons, aka discrete partition. -/
instance (s : finset Ξ±) : has_bot (finpartition s) :=
β¨{ parts := s.map β¨singleton, singleton_injectiveβ©,
sup_indep := set.pairwise_disjoint.sup_indep begin
rw finset.coe_map,
exact finset.pairwise_disjoint_range_singleton.subset (set.image_subset_range _ _),
end,
sup_parts := by rw [sup_map, comp.left_id, embedding.coe_fn_mk, finset.sup_singleton'],
not_bot_mem := by simp }β©
@[simp] lemma parts_bot (s : finset Ξ±) :
(β₯ : finpartition s).parts = s.map β¨singleton, singleton_injectiveβ© := rfl
lemma card_bot (s : finset Ξ±) : (β₯ : finpartition s).parts.card = s.card := finset.card_map _
lemma mem_bot_iff : t β (β₯ : finpartition s).parts β β a β s, {a} = t := mem_map
instance (s : finset Ξ±) : order_bot (finpartition s) :=
{ bot_le := Ξ» P t ht, begin
rw mem_bot_iff at ht,
obtain β¨a, ha, rflβ© := ht,
obtain β¨t, ht, hatβ© := P.exists_mem ha,
exact β¨t, ht, singleton_subset_iff.2 hatβ©,
end,
..finpartition.has_bot s }
lemma card_parts_le_card (P : finpartition s) : P.parts.card β€ s.card :=
by { rw βcard_bot s, exact card_mono bot_le }
section atomise
/-- Cuts `s` along the finsets in `F`: Two elements of `s` will be in the same part if they are
in the same finsets of `F`. -/
def atomise (s : finset Ξ±) (F : finset (finset Ξ±)) : finpartition s :=
of_erase
(F.powerset.image $ Ξ» Q, s.filter (Ξ» i, β t β F, t β Q β i β t))
(set.pairwise_disjoint.sup_indep $ Ξ» x hx y hy h z hz, h begin
rw [mem_coe, mem_image] at hx hy,
obtain β¨Q, hQ, rflβ© := hx,
obtain β¨R, hR, rflβ© := hy,
suffices h : Q = R,
{ subst h },
rw [id, id, inf_eq_inter, mem_inter, mem_filter, mem_filter] at hz,
rw mem_powerset at hQ hR,
ext i,
refine β¨Ξ» hi, _, Ξ» hi, _β©,
{ rwa [hz.2.2 _ (hQ hi), βhz.1.2 _ (hQ hi)] },
{ rwa [hz.1.2 _ (hR hi), βhz.2.2 _ (hR hi)] }
end)
(begin
refine (finset.sup_le $ Ξ» t ht, _).antisymm (Ξ» a ha, _),
{ rw mem_image at ht,
obtain β¨A, hA, rflβ© := ht,
exact s.filter_subset _ },
{ rw [mem_sup],
refine β¨s.filter (Ξ» i, β t, t β F β (t β F.filter (Ξ» u, a β u) β i β t)),
mem_image_of_mem _ (mem_powerset.2 $ filter_subset _ _), mem_filter.2 β¨ha, Ξ» t ht, _β©β©,
rw mem_filter,
exact and_iff_right ht }
end)
variables {F : finset (finset Ξ±)}
lemma mem_atomise {t : finset Ξ±} :
t β (atomise s F).parts β t.nonempty β§ β (Q β F), s.filter (Ξ» i, β u β F, u β Q β i β u) = t :=
by simp only [atomise, of_erase, bot_eq_empty, mem_erase, mem_image, nonempty_iff_ne_empty,
mem_singleton, and_comm, mem_powerset, exists_prop]
lemma atomise_empty (hs : s.nonempty) : (atomise s β
).parts = {s} :=
begin
simp only [atomise, powerset_empty, image_singleton, not_mem_empty, forall_false_left,
implies_true_iff, filter_true],
exact erase_eq_of_not_mem (not_mem_singleton.2 hs.ne_empty.symm),
end
lemma card_atomise_le : (atomise s F).parts.card β€ 2^F.card :=
(card_le_of_subset $ erase_subset _ _).trans $ finset.card_image_le.trans (card_powerset _).le
lemma bUnion_filter_atomise (t : finset Ξ±) (ht : t β F) (hts : t β s) :
((atomise s F).parts.filter $ Ξ» u, u β t).bUnion id = t :=
begin
ext a,
rw mem_bUnion,
refine β¨Ξ» β¨u, hu, haβ©, (mem_filter.1 hu).2 ha, Ξ» ha, _β©,
obtain β¨u, hu, hauβ© := (atomise s F).exists_mem (hts ha),
refine β¨u, mem_filter.2 β¨hu, Ξ» b hb, _β©, hauβ©,
obtain β¨Q, hQ, rflβ© := (mem_atomise.1 hu).2,
rw mem_filter at hau hb,
rwa [βhb.2 _ ht, hau.2 _ ht]
end
end atomise
end finpartition
|
1545bf56211bc8c309392317ba8b23378c3df050 | 35677d2df3f081738fa6b08138e03ee36bc33cad | /src/algebra/category/Group/colimits.lean | c51ab395c1a886b1c9075631fe5169ce4f31ab2f | [
"Apache-2.0"
] | permissive | gebner/mathlib | eab0150cc4f79ec45d2016a8c21750244a2e7ff0 | cc6a6edc397c55118df62831e23bfbd6e6c6b4ab | refs/heads/master | 1,625,574,853,976 | 1,586,712,827,000 | 1,586,712,827,000 | 99,101,412 | 1 | 0 | Apache-2.0 | 1,586,716,389,000 | 1,501,667,958,000 | Lean | UTF-8 | Lean | false | false | 8,820 | lean | /-
Copyright (c) 2019 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import algebra.category.Group.basic
import category_theory.limits.limits
/-!
# The category of additive commutative groups has all colimits.
This file uses a "pre-automated" approach, just as for `Mon/colimits.lean`.
It is a very uniform approach, that conceivably could be synthesised directly
by a tactic that analyses the shape of `add_comm_group` and `monoid_hom`.
TODO:
In fact, in `AddCommGroup` there is a much nicer model of colimits as quotients
of finitely supported functions, and we really should implement this as well (or instead).
-/
universes u v
open category_theory
open category_theory.limits
-- [ROBOT VOICE]:
-- You should pretend for now that this file was automatically generated.
-- It follows the same template as colimits in Mon.
namespace AddCommGroup.colimits
/-!
We build the colimit of a diagram in `AddCommGroup` by constructing the
free group on the disjoint union of all the abelian groups in the diagram,
then taking the quotient by the abelian group laws within each abelian group,
and the identifications given by the morphisms in the diagram.
-/
variables {J : Type v} [small_category J] (F : J β₯€ AddCommGroup.{v})
/--
An inductive type representing all group expressions (without relations)
on a collection of types indexed by the objects of `J`.
-/
inductive prequotient
-- There's always `of`
| of : Ξ (j : J) (x : F.obj j), prequotient
-- Then one generator for each operation
| zero : prequotient
| neg : prequotient β prequotient
| add : prequotient β prequotient β prequotient
instance : inhabited (prequotient F) := β¨prequotient.zeroβ©
open prequotient
/--
The relation on `prequotient` saying when two expressions are equal
because of the abelian group laws, or
because one element is mapped to another by a morphism in the diagram.
-/
inductive relation : prequotient F β prequotient F β Prop
-- Make it an equivalence relation:
| refl : Ξ (x), relation x x
| symm : Ξ (x y) (h : relation x y), relation y x
| trans : Ξ (x y z) (h : relation x y) (k : relation y z), relation x z
-- There's always a `map` relation
| map : Ξ (j j' : J) (f : j βΆ j') (x : F.obj j), relation (of j' (F.map f x)) (of j x)
-- Then one relation per operation, describing the interaction with `of`
| zero : Ξ (j), relation (of j 0) zero
| neg : Ξ (j) (x : F.obj j), relation (of j (-x)) (neg (of j x))
| add : Ξ (j) (x y : F.obj j), relation (of j (x + y)) (add (of j x) (of j y))
-- Then one relation per argument of each operation
| neg_1 : Ξ (x x') (r : relation x x'), relation (neg x) (neg x')
| add_1 : Ξ (x x' y) (r : relation x x'), relation (add x y) (add x' y)
| add_2 : Ξ (x y y') (r : relation y y'), relation (add x y) (add x y')
-- And one relation per axiom
| zero_add : Ξ (x), relation (add zero x) x
| add_zero : Ξ (x), relation (add x zero) x
| add_left_neg : Ξ (x), relation (add (neg x) x) zero
| add_comm : Ξ (x y), relation (add x y) (add y x)
| add_assoc : Ξ (x y z), relation (add (add x y) z) (add x (add y z))
/--
The setoid corresponding to group expressions modulo abelian group relations and identifications.
-/
def colimit_setoid : setoid (prequotient F) :=
{ r := relation F, iseqv := β¨relation.refl, relation.symm, relation.transβ© }
attribute [instance] colimit_setoid
/--
The underlying type of the colimit of a diagram in `AddCommGroup`.
-/
@[derive inhabited]
def colimit_type : Type v := quotient (colimit_setoid F)
instance : add_comm_group (colimit_type F) :=
{ zero :=
begin
exact quot.mk _ zero
end,
neg :=
begin
fapply @quot.lift,
{ intro x,
exact quot.mk _ (neg x) },
{ intros x x' r,
apply quot.sound,
exact relation.neg_1 _ _ r },
end,
add :=
begin
fapply @quot.lift _ _ ((colimit_type F) β (colimit_type F)),
{ intro x,
fapply @quot.lift,
{ intro y,
exact quot.mk _ (add x y) },
{ intros y y' r,
apply quot.sound,
exact relation.add_2 _ _ _ r } },
{ intros x x' r,
funext y,
induction y,
dsimp,
apply quot.sound,
{ exact relation.add_1 _ _ _ r },
{ refl } },
end,
zero_add := Ξ» x,
begin
induction x,
dsimp,
apply quot.sound,
apply relation.zero_add,
refl,
end,
add_zero := Ξ» x,
begin
induction x,
dsimp,
apply quot.sound,
apply relation.add_zero,
refl,
end,
add_left_neg := Ξ» x,
begin
induction x,
dsimp,
apply quot.sound,
apply relation.add_left_neg,
refl,
end,
add_comm := Ξ» x y,
begin
induction x,
induction y,
dsimp,
apply quot.sound,
apply relation.add_comm,
refl,
refl,
end,
add_assoc := Ξ» x y z,
begin
induction x,
induction y,
induction z,
dsimp,
apply quot.sound,
apply relation.add_assoc,
refl,
refl,
refl,
end, }
@[simp] lemma quot_zero : quot.mk setoid.r zero = (0 : colimit_type F) := rfl
@[simp] lemma quot_neg (x) : quot.mk setoid.r (neg x) = (-(quot.mk setoid.r x) : colimit_type F) := rfl
@[simp] lemma quot_add (x y) : quot.mk setoid.r (add x y) = ((quot.mk setoid.r x) + (quot.mk setoid.r y) : colimit_type F) := rfl
/-- The bundled abelian group giving the colimit of a diagram. -/
def colimit : AddCommGroup := AddCommGroup.of (colimit_type F)
/-- The function from a given abelian group in the diagram to the colimit abelian group. -/
def cocone_fun (j : J) (x : F.obj j) : colimit_type F :=
quot.mk _ (of j x)
/-- The group homomorphism from a given abelian group in the diagram to the colimit abelian group. -/
def cocone_morphism (j : J) : F.obj j βΆ colimit F :=
{ to_fun := cocone_fun F j,
map_zero' := by apply quot.sound; apply relation.zero,
map_add' := by intros; apply quot.sound; apply relation.add }
@[simp] lemma cocone_naturality {j j' : J} (f : j βΆ j') :
F.map f β« (cocone_morphism F j') = cocone_morphism F j :=
begin
ext,
apply quot.sound,
apply relation.map,
end
@[simp] lemma cocone_naturality_components (j j' : J) (f : j βΆ j') (x : F.obj j):
(cocone_morphism F j') (F.map f x) = (cocone_morphism F j) x :=
by { rw βcocone_naturality F f, refl }
/-- The cocone over the proposed colimit abelian group. -/
def colimit_cocone : cocone F :=
{ X := colimit F,
ΞΉ :=
{ app := cocone_morphism F } }.
/-- The function from the free abelian group on the diagram to the cone point of any other cocone. -/
@[simp] def desc_fun_lift (s : cocone F) : prequotient F β s.X
| (of j x) := (s.ΞΉ.app j) x
| zero := 0
| (neg x) := -(desc_fun_lift x)
| (add x y) := desc_fun_lift x + desc_fun_lift y
/-- The function from the colimit abelian group to the cone point of any other cocone. -/
def desc_fun (s : cocone F) : colimit_type F β s.X :=
begin
fapply quot.lift,
{ exact desc_fun_lift F s },
{ intros x y r,
induction r; try { dsimp },
-- refl
{ refl },
-- symm
{ exact r_ih.symm },
-- trans
{ exact eq.trans r_ih_h r_ih_k },
-- map
{ rw cocone.naturality_concrete, },
-- zero
{ erw ((s.ΞΉ).app r).map_zero },
-- neg
{ rw ((s.ΞΉ).app r_j).map_neg },
-- add
{ rw ((s.ΞΉ).app r_j).map_add },
-- neg_1
{ rw r_ih, },
-- add_1
{ rw r_ih, },
-- add_2
{ rw r_ih, },
-- zero_add
{ rw zero_add, },
-- add_zero
{ rw add_zero, },
-- add_left_neg
{ rw add_left_neg, },
-- add_comm
{ rw add_comm, },
-- add_assoc
{ rw add_assoc, },
}
end
/-- The group homomorphism from the colimit abelian group to the cone point of any other cocone. -/
@[simps]
def desc_morphism (s : cocone F) : colimit F βΆ s.X :=
{ to_fun := desc_fun F s,
map_zero' := rfl,
map_add' := Ξ» x y, by { induction x; induction y; refl }, }
/-- Evidence that the proposed colimit is the colimit. -/
def colimit_is_colimit : is_colimit (colimit_cocone F) :=
{ desc := Ξ» s, desc_morphism F s,
uniq' := Ξ» s m w,
begin
ext,
induction x,
induction x,
{ have w' := congr_fun (congr_arg (Ξ» f : F.obj x_j βΆ s.X, (f : F.obj x_j β s.X)) (w x_j)) x_x,
erw w',
refl, },
{ simp only [desc_morphism, quot_zero],
erw m.map_zero,
refl, },
{ simp only [desc_morphism, quot_neg],
erw m.map_neg,
rw [x_ih],
refl, },
{ simp only [desc_morphism, quot_add],
erw m.map_add,
rw [x_ih_a, x_ih_a_1],
refl, },
refl
end }.
instance has_colimits_AddCommGroup : has_colimits.{v} AddCommGroup.{v} :=
{ has_colimits_of_shape := Ξ» J π₯,
{ has_colimit := Ξ» F, by exactI
{ cocone := colimit_cocone F,
is_colimit := colimit_is_colimit F } } }
end AddCommGroup.colimits
|
ba1c0ac4f2df705b750e9d43c770cb073473e7a7 | 957a80ea22c5abb4f4670b250d55534d9db99108 | /tests/lean/run/cc_ac1.lean | fcbef5aef0cb64184da2f06e79502905a9f44da7 | [
"Apache-2.0"
] | permissive | GaloisInc/lean | aa1e64d604051e602fcf4610061314b9a37ab8cd | f1ec117a24459b59c6ff9e56a1d09d9e9e60a6c0 | refs/heads/master | 1,592,202,909,807 | 1,504,624,387,000 | 1,504,624,387,000 | 75,319,626 | 2 | 1 | Apache-2.0 | 1,539,290,164,000 | 1,480,616,104,000 | C++ | UTF-8 | Lean | false | false | 186 | lean | open tactic
example (a b c : nat) (f : nat β nat) : f (a + b + c) = f (c + b + a) :=
by cc
example (a b c : nat) (f : nat β nat) : a + b = c β f (c + c) = f (a + b + c) :=
by cc
|
1769e7f03014e4bbf593f0096180d00e94d9fb40 | b7f22e51856f4989b970961f794f1c435f9b8f78 | /tests/lean/run/blast_ematch_uni_issue.lean | c70b42686ba88772a6fdffc80ae68ebe5c9f752b | [
"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 | 464 | lean | set_option blast.ematch true
variable {A : Type}
definition R : A β A β Prop := sorry
definition R_trans [forward] {a b c : A} : R a b β R b c β R a c := sorry
example (a b c : A) : R a b β R b c β R a c :=
by blast
example {A : Type} (a b c : A) : R a b β R b c β R a c :=
by blast
example {A : Type.{1}} (a b c : A) : R a b β R b c β R a c :=
by blast
universe u
example {A : Type.{u}} (a b c : A) : R a b β R b c β R a c :=
by blast
|
3d5cb8ee7c71300866a10248d87349fc2e612d8e | 7cef822f3b952965621309e88eadf618da0c8ae9 | /src/data/option/basic.lean | 4b38285e0e952564a60a1e1a4caec5077edfc44d | [
"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 | 6,623 | 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 logic.basic data.bool data.option.defs tactic.basic
namespace option
variables {Ξ± : Type*} {Ξ² : Type*} {Ξ³ : Type*}
lemma some_ne_none (x : Ξ±) : some x β none := Ξ» h, option.no_confusion h
@[simp] theorem get_mem : β {o : option Ξ±} (h : is_some o), option.get h β o
| (some a) _ := rfl
theorem get_of_mem {a : Ξ±} : β {o : option Ξ±} (h : is_some o), a β o β option.get h = a
| _ _ rfl := rfl
@[simp] lemma not_mem_none (a : Ξ±) : a β (none : option Ξ±) :=
Ξ» h, option.no_confusion h
@[simp] lemma some_get : β {x : option Ξ±} (h : is_some x), some (option.get h) = x
| (some x) hx := rfl
@[simp] lemma get_some (x : Ξ±) (h : is_some (some x)) : option.get h = x := rfl
theorem mem_unique {o : option Ξ±} {a b : Ξ±} (ha : a β o) (hb : b β o) : a = b :=
option.some.inj $ ha.symm.trans hb
theorem injective_some (Ξ± : Type*) : function.injective (@some Ξ±) :=
Ξ» _ _, some_inj.mp
/-- `option.map f` is injective if `f` is injective. -/
theorem injective_map {f : Ξ± β Ξ²} (Hf : function.injective f) : function.injective (option.map f)
| none none H := rfl
| (some aβ) (some aβ) H := by rw Hf (option.some.inj H)
@[ext] theorem ext : β {oβ oβ : option Ξ±}, (β a, a β oβ β a β oβ) β oβ = oβ
| none none H := rfl
| (some a) o H := ((H _).1 rfl).symm
| o (some b) H := (H _).2 rfl
theorem eq_none_iff_forall_not_mem {o : option Ξ±} :
o = none β (β a, a β o) :=
β¨Ξ» e a h, by rw e at h; cases h, Ξ» h, ext $ by simpaβ©
@[simp] theorem none_bind {Ξ± Ξ²} (f : Ξ± β option Ξ²) : none >>= f = none := rfl
@[simp] theorem some_bind {Ξ± Ξ²} (a : Ξ±) (f : Ξ± β option Ξ²) : some a >>= f = f a := rfl
@[simp] theorem none_bind' (f : Ξ± β option Ξ²) : none.bind f = none := rfl
@[simp] theorem some_bind' (a : Ξ±) (f : Ξ± β option Ξ²) : (some a).bind f = f a := rfl
@[simp] theorem bind_some : β x : option Ξ±, x >>= some = x :=
@bind_pure Ξ± option _ _
@[simp] theorem bind_eq_some {Ξ± Ξ²} {x : option Ξ±} {f : Ξ± β option Ξ²} {b : Ξ²} : x >>= f = some b β β a, x = some a β§ f a = some b :=
by cases x; simp
@[simp] theorem bind_eq_some' {x : option Ξ±} {f : Ξ± β option Ξ²} {b : Ξ²} : x.bind f = some b β β a, x = some a β§ f a = some b :=
by cases x; simp
@[simp] theorem bind_eq_none' {o : option Ξ±} {f : Ξ± β option Ξ²} :
o.bind f = none β (β b a, a β o β b β f a) :=
by simp only [eq_none_iff_forall_not_mem, not_exists, not_and, mem_def, bind_eq_some']
@[simp] theorem bind_eq_none {Ξ± Ξ²} {o : option Ξ±} {f : Ξ± β option Ξ²} :
o >>= f = none β (β b a, a β o β b β f a) :=
bind_eq_none'
lemma bind_comm {Ξ± Ξ² Ξ³} {f : Ξ± β Ξ² β option Ξ³} (a : option Ξ±) (b : option Ξ²) :
a.bind (Ξ»x, b.bind (f x)) = b.bind (Ξ»y, a.bind (Ξ»x, f x y)) :=
by cases a; cases b; refl
lemma bind_assoc (x : option Ξ±) (f : Ξ± β option Ξ²) (g : Ξ² β option Ξ³) :
(x.bind f).bind g = x.bind (Ξ» y, (f y).bind g) := by cases x; refl
@[simp] theorem map_none {Ξ± Ξ²} {f : Ξ± β Ξ²} : f <$> none = none := rfl
@[simp] theorem map_some {Ξ± Ξ²} {a : Ξ±} {f : Ξ± β Ξ²} : f <$> some a = some (f a) := rfl
@[simp] theorem map_none' {f : Ξ± β Ξ²} : option.map f none = none := rfl
@[simp] theorem map_some' {a : Ξ±} {f : Ξ± β Ξ²} : option.map f (some a) = some (f a) := rfl
@[simp] theorem map_eq_some {Ξ± Ξ²} {x : option Ξ±} {f : Ξ± β Ξ²} {b : Ξ²} : f <$> x = some b β β a, x = some a β§ f a = b :=
by cases x; simp
@[simp] theorem map_eq_some' {x : option Ξ±} {f : Ξ± β Ξ²} {b : Ξ²} : x.map f = some b β β a, x = some a β§ f a = b :=
by cases x; simp
@[simp] theorem map_id' : option.map (@id Ξ±) = id := map_id
@[simp] theorem seq_some {Ξ± Ξ²} {a : Ξ±} {f : Ξ± β Ξ²} : some f <*> some a = some (f a) := rfl
@[simp] theorem some_orelse' (a : Ξ±) (x : option Ξ±) : (some a).orelse x = some a := rfl
@[simp] theorem some_orelse (a : Ξ±) (x : option Ξ±) : (some a <|> x) = some a := rfl
@[simp] theorem none_orelse' (x : option Ξ±) : none.orelse x = x :=
by cases x; refl
@[simp] theorem none_orelse (x : option Ξ±) : (none <|> x) = x := none_orelse' x
@[simp] theorem orelse_none' (x : option Ξ±) : x.orelse none = x :=
by cases x; refl
@[simp] theorem orelse_none (x : option Ξ±) : (x <|> none) = x := orelse_none' x
@[simp] theorem is_some_none : @is_some Ξ± none = ff := rfl
@[simp] theorem is_some_some {a : Ξ±} : is_some (some a) = tt := rfl
theorem is_some_iff_exists {x : option Ξ±} : is_some x β β a, x = some a :=
by cases x; simp [is_some]; exact β¨_, rflβ©
@[simp] theorem is_none_none : @is_none Ξ± none = tt := rfl
@[simp] theorem is_none_some {a : Ξ±} : is_none (some a) = ff := rfl
@[simp] theorem not_is_some {a : option Ξ±} : is_some a = ff β a.is_none = tt :=
by cases a; simp
lemma eq_some_iff_get_eq {o : option Ξ±} {a : Ξ±} :
o = some a β β h : o.is_some, option.get h = a :=
by cases o; simp
lemma not_is_some_iff_eq_none {o : option Ξ±} : Β¬o.is_some β o = none :=
by cases o; simp
lemma ne_none_iff_is_some {o : option Ξ±} : o β none β o.is_some :=
by cases o; simp
lemma bex_ne_none {p : option Ξ± β Prop} :
(β x β none, p x) β β x, p (some x) :=
β¨Ξ» β¨x, hx, hpβ©, β¨get $ ne_none_iff_is_some.1 hx, by rwa [some_get]β©,
Ξ» β¨x, hxβ©, β¨some x, some_ne_none x, hxβ©β©
lemma ball_ne_none {p : option Ξ± β Prop} :
(β x β none, p x) β β x, p (some x) :=
β¨Ξ» h x, h (some x) (some_ne_none x),
Ξ» h x hx, by simpa only [some_get] using h (get $ ne_none_iff_is_some.1 hx)β©
theorem iget_mem [inhabited Ξ±] : β {o : option Ξ±}, is_some o β o.iget β o
| (some a) _ := rfl
theorem iget_of_mem [inhabited Ξ±] {a : Ξ±} : β {o : option Ξ±}, a β o β o.iget = a
| _ rfl := rfl
@[simp] theorem guard_eq_some {p : Ξ± β Prop} [decidable_pred p] {a b : Ξ±} :
guard p a = some b β a = b β§ p a :=
by by_cases p a; simp [option.guard, h]; intro; contradiction
@[simp] theorem guard_eq_some' {p : Prop} [decidable p] :
β u, _root_.guard p = some u β p
| () := by by_cases p; simp [guard, h, pure]; intro; contradiction
theorem lift_or_get_choice {f : Ξ± β Ξ± β Ξ±} (h : β a b, f a b = a β¨ f a b = b) :
β oβ oβ, lift_or_get f oβ oβ = oβ β¨ lift_or_get f oβ oβ = oβ
| none none := or.inl rfl
| (some a) none := or.inl rfl
| none (some b) := or.inr rfl
| (some a) (some b) := by simpa [lift_or_get] using h a b
end option
|
ebd6b4afd08b405815dcf60e04c523e439dbf01c | 65b579fba1b0b66add04cccd4529add645eff597 | /expression0.lean | 5689db00e161a2a8eb7356f22807008916a5f8d9 | [] | no_license | teodorov/sf_lean | ba637ca8ecc538aece4d02c8442d03ef713485db | cd4832d6bee9c606014c977951f6aebc4c8d611b | refs/heads/master | 1,632,890,232,054 | 1,543,005,745,000 | 1,543,005,745,000 | 108,566,115 | 1 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 1,827 | lean | -- inspired from https://github.com/UlfNorell/agda-summer-school/blob/OPLSS/lectures/Day1.agda
inductive Expr : Type
| elit (n : β) : Expr
| ett : Expr
| eff : Expr
| eless (a b : Expr) : Expr
| eplus (a b : Expr) : Expr
| eif (a b c : Expr) : Expr
.
inductive Value : Type
| nat : β β Value
| bool : bool β Value
.
def getNat : Value β option β
| (Value.nat n) := some n
| (Value.bool b) := none
def getBool : Value β option bool
| (Value.nat n) := none
| (Value.bool b) := some b
def lookup : list β β β β option β
| [] _ := none
| (x::xs) i := if (i = 0) then some x else lookup xs (i-1).
#eval lookup [10, 20, 30] 2
#eval lookup [10, 20, 30] 4
namespace Expr
def lless : option β β option β β option Value :=
Ξ» mx my, mx >>= (Ξ» x, my >>= Ξ» y, return (Value.bool (x < y)))
def pplus : option β β option β β option Value :=
Ξ» mx my, mx >>= (Ξ» x, my >>= Ξ» y, return (Value.nat (x + y)))
def eval : Expr β option Value
| (elit n) := some (Value.nat n)
| ett := some (Value.bool true)
| eff := some (Value.bool false)
| (eless eβ eβ) := lless ((eval eβ) >>= getNat) ((eval eβ) >>=getNat)
-- (Ξ» n m, Value.bool (n < m))
-- <$> (getNat =<< eval eβ)
-- <*> (getNat =<< eval eβ)
| (eplus eβ eβ) := pplus ((eval eβ) >>= getNat) ((eval eβ) >>=getNat)
-- (Ξ» n m, Value.nat (n + m))
-- <$> (getNat =<< eval eβ)
-- <*> (getNat =<< eval eβ)
| (eif eβ eβ eβ) := eval eβ >>= getBool >>= (Ξ» b, if (b) then (eval eβ) else (eval eβ))
-- (Ξ» b, if (b) then (eval eβ) else (eval eβ))
-- =<< (getBool =<< (eval eβ))
#reduce eval (eif (eff) (elit 3) (elit 4))
end Expr |
f347877f39eb456e152468ee5914a8a5f9ffdbd6 | 618003631150032a5676f229d13a079ac875ff77 | /src/category_theory/currying.lean | 2b0d3c0ef63d93f177c91a7bb19a507c4de69c0a | [
"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 | 3,228 | lean | /-
Copyright (c) 2017 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import category_theory.products.bifunctor
namespace category_theory
universes vβ vβ vβ uβ uβ uβ
variables {C : Type uβ} [category.{vβ} C]
{D : Type uβ} [category.{vβ} D]
{E : Type uβ} [category.{vβ} E]
def uncurry : (C β₯€ (D β₯€ E)) β₯€ ((C Γ D) β₯€ E) :=
{ obj := Ξ» F,
{ obj := Ξ» X, (F.obj X.1).obj X.2,
map := Ξ» X Y f, (F.map f.1).app X.2 β« (F.obj Y.1).map f.2,
map_comp' := Ξ» X Y Z f g,
begin
simp only [prod_comp_fst, prod_comp_snd, functor.map_comp,
nat_trans.comp_app, category.assoc],
slice_lhs 2 3 { rw β nat_trans.naturality },
rw category.assoc,
end },
map := Ξ» F G T,
{ app := Ξ» X, (T.app X.1).app X.2,
naturality' := Ξ» X Y f,
begin
simp only [prod_comp_fst, prod_comp_snd, category.comp_id, category.assoc,
functor.map_id, functor.map_comp, nat_trans.id_app, nat_trans.comp_app],
slice_lhs 2 3 { rw nat_trans.naturality },
slice_lhs 1 2 {
rw [βnat_trans.comp_app, nat_trans.naturality,
nat_trans.comp_app],
},
rw category.assoc,
end } }.
def curry_obj (F : (C Γ D) β₯€ E) : C β₯€ (D β₯€ E) :=
{ obj := Ξ» X,
{ obj := Ξ» Y, F.obj (X, Y),
map := Ξ» Y Y' g, F.map (π X, g) },
map := Ξ» X X' f, { app := Ξ» Y, F.map (f, π Y) } }
def curry : ((C Γ D) β₯€ E) β₯€ (C β₯€ (D β₯€ E)) :=
{ obj := Ξ» F, curry_obj F,
map := Ξ» F G T,
{ app := Ξ» X,
{ app := Ξ» Y, T.app (X, Y),
naturality' := Ξ» Y Y' g,
begin
dsimp [curry_obj],
rw nat_trans.naturality,
end },
naturality' := Ξ» X X' f,
begin
ext, dsimp [curry_obj],
rw nat_trans.naturality,
end } }.
@[simp] lemma uncurry.obj_obj {F : C β₯€ (D β₯€ E)} {X : C Γ D} :
(uncurry.obj F).obj X = (F.obj X.1).obj X.2 := rfl
@[simp] lemma uncurry.obj_map {F : C β₯€ (D β₯€ E)} {X Y : C Γ D} {f : X βΆ Y} :
(uncurry.obj F).map f = ((F.map f.1).app X.2) β« ((F.obj Y.1).map f.2) := rfl
@[simp] lemma uncurry.map_app {F G : C β₯€ (D β₯€ E)} {Ξ± : F βΆ G} {X : C Γ D} :
(uncurry.map Ξ±).app X = (Ξ±.app X.1).app X.2 := rfl
@[simp] lemma curry.obj_obj_obj
{F : (C Γ D) β₯€ E} {X : C} {Y : D} :
((curry.obj F).obj X).obj Y = F.obj (X, Y) := rfl
@[simp] lemma curry.obj_obj_map
{F : (C Γ D) β₯€ E} {X : C} {Y Y' : D} {g : Y βΆ Y'} :
((curry.obj F).obj X).map g = F.map (π X, g) := rfl
@[simp] lemma curry.obj_map_app {F : (C Γ D) β₯€ E} {X X' : C} {f : X βΆ X'} {Y} :
((curry.obj F).map f).app Y = F.map (f, π Y) := rfl
@[simp] lemma curry.map_app_app {F G : (C Γ D) β₯€ E} {Ξ± : F βΆ G} {X} {Y} :
((curry.map Ξ±).app X).app Y = Ξ±.app (X, Y) := rfl
def currying : (C β₯€ (D β₯€ E)) β ((C Γ D) β₯€ E) :=
equivalence.mk uncurry curry
(nat_iso.of_components (Ξ» F, nat_iso.of_components
(Ξ» X, nat_iso.of_components (Ξ» Y, as_iso (π _)) (by tidy)) (by tidy)) (by tidy))
(nat_iso.of_components (Ξ» F, nat_iso.of_components
(Ξ» X, eq_to_iso (by {dsimp, simp})) (by tidy)) (by tidy))
end category_theory
|
853cfaa9482bb5c21ddf836f0a313e23b464861b | bab2ace2b909818f20ac125499a8dd88ce812721 | /src/2020/relations/partition_challenge_solution2.lean | 16e3d9d362124cce46e55d4d39c346ca6f129e5d | [] | no_license | LaplaceKorea/M40001_lean | 8a3cd411fb821a7665132c09e436f02f674cc666 | 116e9ed1fadf59dc2e78376fca92026859a03bf2 | refs/heads/master | 1,693,347,195,820 | 1,635,517,507,000 | 1,635,517,507,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 5,578 | lean | import data.equiv.basic
import tactic
/-!
# Definition and basic API for partitions
-/
/-- The structure of a partition on a Type Ξ±. -/
-- Let Ξ± be a type. A *partition* on Ξ± is defined to
-- be the following data.
@[ext] structure partition (Ξ± : Type) :=
-- A set C of subsets of Ξ±, called "blocks".
(C : set (set Ξ±))
-- A hypothesis (a.k.a. a proof) that all the blocks are non-empty.
(Hnonempty : β X β C, (X : set Ξ±).nonempty)
-- A hypothesis that every term of type Ξ± is in one of the blocks.
(Hcover : β a, β X β C, a β X)
-- A hypothesis that two blocks with non-empty intersection are equal.
(Hdisjoint : β X Y β C, (X β© Y : set Ξ±).nonempty β X = Y)
namespace partition
-- let Ξ± be a type, and fix a partition P on Ξ±. Let X and Y be subsets of Ξ±.
variables {Ξ± : Type} {P : partition Ξ±} {X Y : set Ξ±}
-- a more convenient way of putting it.
theorem Hdisjoint' (hX : X β P.C) (hY : Y β P.C) : (X β© Y).nonempty β X = Y :=
P.Hdisjoint X Y hX hY
-- another way
theorem Hdisjoint'' (hX : X β P.C) (hY : Y β P.C) {a : Ξ±} (haX : a β X)
(haY : a β Y) : X = Y :=
P.Hdisjoint _ _ hX hY β¨a, haX, haYβ©
end partition
section equivalence_classes
/-!
# Definition and basic API for equivalence classes
We define equivalence classes and prove a few basic results about them.
-/
-- Notation and variables for this section:
-- let Ξ± be a type, and let R be an equivalence relation on R.
variables {Ξ± : Type} {R : Ξ± β Ξ± β Prop} (hR : equivalence R)
-- Always assume R is an equivalence relation, even when we don't need it.
include hR
/-- The equivalence class of `x` is all the `y` such that `y` is related to `x`. -/
def cl (x : Ξ±) :=
{y : Ξ± | R y x}
/-- Useful for rewriting -- `y` is in the equivalence class of `x` iff
`y` is related to `x`. True by definition. -/
theorem mem_cl_iff {x y : Ξ±} : x β cl hR y β R x y := iff.rfl
/-- x is in cl(x) -/
lemma mem_class_self (x : Ξ±) :
x β cl hR x :=
begin
rcases hR with β¨hrefl, hsymm, htransβ©,
exact hrefl x,
end
lemma class_sub {x y : Ξ±} :
x β cl hR y β
cl hR x β cl hR y :=
begin
rcases hR with β¨hrefl, hsymm, htransβ©,
intro hxy,
intro z,
intro hzx,
exact htrans hzx hxy,
end
lemma class_eq {x y : Ξ±} :
x β cl hR y β
cl hR x = cl hR y :=
begin
intro hxy,
apply set.subset.antisymm,
apply class_sub hR hxy,
apply class_sub hR,
rcases hR with β¨hrefl, hsymm, htransβ©,
exact hsymm hxy,
end
end equivalence_classes -- section
/-!
# Statement of the theorem
-/
open partition
-- There is a bijection between equivalence relations and partitions
example (Ξ± : Type) : {R : Ξ± β Ξ± β Prop // equivalence R} β partition Ξ± :=
{ -- Let R be an equivalence relation.
to_fun := Ξ» R, {
-- Let C be the set of equivalence classes for R.
C := { B : set Ξ± | β x : Ξ±, B = cl R.2 x},
-- I claim that C is a partition. We need to check three things.
Hnonempty := begin
-- If c is a block then c is nonempty.
rintros c β¨x, rflβ©,
use x,
apply mem_class_self R.2,
end,
Hcover := begin
intro x,
use (cl R.2 x),
split,
{ use x,
},
{ apply mem_class_self,
}
end,
Hdisjoint := begin
rintros c d β¨x, rflβ© β¨y, rflβ© β¨z, hzx, hzyβ©,
cases R with R hR,
erw β class_eq hR hzx,
erw β class_eq hR hzy,
end },
-- Conversely, say P is an partition.
inv_fun := Ξ» P,
-- Let's define a binary relation by x ~ y iff there's a block they're both in
β¨Ξ» a b, β X β P.C, a β X β b β X, begin
-- I claim this is an equivalence relation.
split,
{ -- It's reflexive
intros a C hC haC,
exact haC,
},
split,
{ -- it's symmetric
intros x y h C hC hyC,
rcases P.Hcover x with β¨D, hD, hxDβ©,
convert hxD,
apply P.Hdisjoint _ _ hC hD,
use [y, hyC],
exact h D hD hxD,
},
{ -- it's transitive
intros x y z hxy hyx C hC hxC,
apply hyx C hC,
apply hxy C hC,
exact hxC,
}
endβ©,
-- If you start with the equivalence relation, and then make the partition
-- and a new equivalence relation, you get back to where you started.
left_inv := begin
rintro β¨R, hRβ©,
simp,
ext a b,
rcases hR with β¨hRr,hRs,hRtβ©,
split,
{ intro f,
specialize f a (hRr a),
exact hRs f,
},
{ intros hab t hat,
refine hRt _ hat,
exact hRs hab,
},
end,
-- Similarly, if you start with the partition, and then make the
-- equivalence relation, and then construct the corresponding partition
-- into equivalence classes, you have the same partition you started with.
right_inv := begin
intro P,
ext W,
simp,
split,
{ rintro β¨a, rflβ©,
rcases P.Hcover a with β¨X, hX, haXβ©,
convert hX,
ext b,
rw mem_cl_iff,
split,
{ intro h,
rcases P.Hcover b with β¨Y, hY, hbYβ©,
specialize h Y hY hbY,
rwa Hdisjoint'' hX hY haX h,
},
{ intros hbX Y hY hbY,
rwa Hdisjoint'' hY hX hbY hbX,
}
},
{ intro hW,
cases P.Hnonempty W hW with a haW,
use a,
ext b,
rw mem_cl_iff,
split,
{ intro hbW,
intros X hX hbX,
rwa Hdisjoint'' hX hW hbX hbW
},
{ intro haX,
rcases P.Hcover b with β¨X, hX, hbXβ©,
specialize haX X hX hbX,
rwa Hdisjoint'' hW hX haW haX
}
}
end }
|
ae4cda0f9fa7a34e8e279dae1991685f1c2a0878 | 8b9f17008684d796c8022dab552e42f0cb6fb347 | /library/logic/axioms/prop_decidable.lean | 14daeeb835049d5cf0ae51d2f20c2d1a88f63e73 | [
"Apache-2.0"
] | permissive | chubbymaggie/lean | 0d06ae25f9dd396306fb02190e89422ea94afd7b | d2c7b5c31928c98f545b16420d37842c43b4ae9a | refs/heads/master | 1,611,313,622,901 | 1,430,266,839,000 | 1,430,267,083,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 648 | lean | /-
Copyright (c) 2014 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Module: logic.axioms.prop_decidable
Author: Leonardo de Moura
Excluded middle + Hilbert implies every proposition is decidable.
-/
import logic.axioms.prop_complete logic.axioms.hilbert
open decidable inhabited nonempty
theorem decidable_inhabited [instance] (a : Prop) : inhabited (decidable a) :=
inhabited_of_nonempty
(or.elim (em a)
(assume Ha, nonempty.intro (inl Ha))
(assume Hna, nonempty.intro (inr Hna)))
theorem prop_decidable [instance] (a : Prop) : decidable a :=
arbitrary (decidable a)
|
cde83449626bb05761e400ca4af81241de2ff629 | 64874bd1010548c7f5a6e3e8902efa63baaff785 | /library/logic/axioms/prop_decidable.lean | d3931aee0b29bbdc53a2773ef681ade1d2639c86 | [
"Apache-2.0"
] | permissive | tjiaqi/lean | 4634d729795c164664d10d093f3545287c76628f | d0ce4cf62f4246b0600c07e074d86e51f2195e30 | refs/heads/master | 1,622,323,796,480 | 1,422,643,069,000 | 1,422,643,069,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 883 | lean | /-
Copyright (c) 2014 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Module: logic.axioms.prop_decidable
Author: Leonardo de Moura
-/
import logic.axioms.classical logic.axioms.hilbert
open decidable inhabited nonempty
-- Excluded middle + Hilbert implies every proposition is decidable
-- First, we show that (decidable a) is inhabited for any 'a' using the excluded middle
theorem decidable_inhabited [instance] (a : Prop) : inhabited (decidable a) :=
inhabited_of_nonempty
(or.elim (em a)
(assume Ha, nonempty.intro (inl Ha))
(assume Hna, nonempty.intro (inr Hna)))
-- Note that decidable_inhabited is marked as an instance, and it is silently used
-- for synthesizing the implicit argument in the following 'epsilon'
theorem prop_decidable [instance] (a : Prop) : decidable a :=
epsilon (Ξ»d, true)
|
dd02e16905e340cba494f189b11eeb5f54148624 | 1a61aba1b67cddccce19532a9596efe44be4285f | /library/algebra/lattice.lean | b2ec2fb0ed13c7067a8ea711e1085a4311e65cf7 | [
"Apache-2.0"
] | permissive | eigengrau/lean | 07986a0f2548688c13ba36231f6cdbee82abf4c6 | f8a773be1112015e2d232661ce616d23f12874d0 | refs/heads/master | 1,610,939,198,566 | 1,441,352,386,000 | 1,441,352,494,000 | 41,903,576 | 0 | 0 | null | 1,441,352,210,000 | 1,441,352,210,000 | null | UTF-8 | Lean | false | false | 4,095 | lean | /-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Jeremy Avigad
-/
import .order
namespace algebra
variable {A : Type}
/- lattices (we could split this to upper- and lower-semilattices, if needed) -/
structure lattice [class] (A : Type) extends weak_order A :=
(inf : A β A β A)
(sup : A β A β A)
(inf_le_left : β a b, le (inf a b) a)
(inf_le_right : β a b, le (inf a b) b)
(le_inf : βa b c, le c a β le c b β le c (inf a b))
(le_sup_left : β a b, le a (sup a b))
(le_sup_right : β a b, le b (sup a b))
(sup_le : β a b c, le a c β le b c β le (sup a b) c)
definition inf := @lattice.inf
definition sup := @lattice.sup
infix `β`:70 := inf
infix `β`:65 := sup
section
variable [s : lattice A]
include s
theorem inf_le_left (a b : A) : a β b β€ a := !lattice.inf_le_left
theorem inf_le_right (a b : A) : a β b β€ b := !lattice.inf_le_right
theorem le_inf {a b c : A} (Hβ : c β€ a) (Hβ : c β€ b) : c β€ a β b := !lattice.le_inf Hβ Hβ
theorem le_sup_left (a b : A) : a β€ a β b := !lattice.le_sup_left
theorem le_sup_right (a b : A) : b β€ a β b := !lattice.le_sup_right
theorem sup_le {a b c : A} (Hβ : a β€ c) (Hβ : b β€ c) : a β b β€ c := !lattice.sup_le Hβ Hβ
/- inf -/
theorem eq_inf {a b c : A} (Hβ : c β€ a) (Hβ : c β€ b) (Hβ : β{d}, d β€ a β d β€ b β d β€ c) :
c = a β b :=
le.antisymm (le_inf Hβ Hβ) (Hβ !inf_le_left !inf_le_right)
theorem inf.comm (a b : A) : a β b = b β a :=
eq_inf !inf_le_right !inf_le_left (Ξ» c Hβ Hβ, le_inf Hβ Hβ)
theorem inf.assoc (a b c : A) : (a β b) β c = a β (b β c) :=
begin
apply eq_inf,
{ apply le.trans, apply inf_le_left, apply inf_le_left },
{ apply le_inf, apply le.trans, apply inf_le_left, apply inf_le_right, apply inf_le_right },
{ intros [d, Hβ, Hβ], apply le_inf, apply le_inf Hβ, apply le.trans Hβ, apply inf_le_left,
apply le.trans Hβ, apply inf_le_right }
end
theorem inf.left_comm (a b c : A) : a β (b β c) = b β (a β c) :=
binary.left_comm (@inf.comm A s) (@inf.assoc A s) a b c
theorem inf.right_comm (a b c : A) : (a β b) β c = (a β c) β b :=
binary.right_comm (@inf.comm A s) (@inf.assoc A s) a b c
theorem inf_self (a : A) : a β a = a :=
by apply eq.symm; apply eq_inf (le.refl a) !le.refl; intros; assumption
theorem inf_eq_left {a b : A} (H : a β€ b) : a β b = a :=
by apply eq.symm; apply eq_inf !le.refl H; intros; assumption
theorem inf_eq_right {a b : A} (H : b β€ a) : a β b = b :=
eq.subst !inf.comm (inf_eq_left H)
/- sup -/
theorem eq_sup {a b c : A} (Hβ : a β€ c) (Hβ : b β€ c) (Hβ : β{d}, a β€ d β b β€ d β c β€ d) :
c = a β b :=
le.antisymm (Hβ !le_sup_left !le_sup_right) (sup_le Hβ Hβ)
theorem sup.comm (a b : A) : a β b = b β a :=
eq_sup !le_sup_right !le_sup_left (Ξ» c Hβ Hβ, sup_le Hβ Hβ)
theorem sup.assoc (a b c : A) : (a β b) β c = a β (b β c) :=
begin
apply eq_sup,
{ apply le.trans, apply le_sup_left a b, apply le_sup_left },
{ apply sup_le, apply le.trans, apply le_sup_right a b, apply le_sup_left, apply le_sup_right },
{ intros [d, Hβ, Hβ], apply sup_le, apply sup_le Hβ, apply le.trans !le_sup_left Hβ,
apply le.trans !le_sup_right Hβ}
end
theorem sup.left_comm (a b c : A) : a β (b β c) = b β (a β c) :=
binary.left_comm (@sup.comm A s) (@sup.assoc A s) a b c
theorem sup.right_comm (a b c : A) : (a β b) β c = (a β c) β b :=
binary.right_comm (@sup.comm A s) (@sup.assoc A s) a b c
theorem sup_self (a : A) : a β a = a :=
by apply eq.symm; apply eq_sup (le.refl a) !le.refl; intros; assumption
theorem sup_eq_left {a b : A} (H : b β€ a) : a β b = a :=
by apply eq.symm; apply eq_sup !le.refl H; intros; assumption
theorem sup_eq_right {a b : A} (H : a β€ b) : a β b = b :=
eq.subst !sup.comm (sup_eq_left H)
end
end algebra
|
92c034fe1da8927101278cc6aae248dc313239ac | d1a52c3f208fa42c41df8278c3d280f075eb020c | /stage0/src/Lean/Compiler/Util.lean | c522e95f69274562dd97682686cf108f556bcec8 | [
"Apache-2.0",
"LLVM-exception",
"NCSA",
"LGPL-3.0-only",
"LicenseRef-scancode-inner-net-2.0",
"BSD-3-Clause",
"LGPL-2.0-or-later",
"Spencer-94",
"LGPL-2.1-or-later",
"HPND",
"LicenseRef-scancode-pcre",
"ISC",
"LGPL-2.1-only",
"LicenseRef-scancode-other-permissive",
"SunPro",
"CMU-Mach"... | permissive | cipher1024/lean4 | 6e1f98bb58e7a92b28f5364eb38a14c8d0aae393 | 69114d3b50806264ef35b57394391c3e738a9822 | refs/heads/master | 1,642,227,983,603 | 1,642,011,696,000 | 1,642,011,696,000 | 228,607,691 | 0 | 0 | Apache-2.0 | 1,576,584,269,000 | 1,576,584,268,000 | null | UTF-8 | Lean | false | false | 3,804 | 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.Environment
namespace Lean.Compiler
def neutralExpr : Expr := mkConst `_neutral
def unreachableExpr : Expr := mkConst `_unreachable
def objectType : Expr := mkConst `_obj
def voidType : Expr := mkConst `_void
def mkLcProof (pred : Expr) := mkApp (mkConst `lcProof []) pred
namespace atMostOnce
structure AtMostOnceData where
found : Bool
result : Bool
def Visitor := AtMostOnceData β AtMostOnceData
@[inline] def seq (f g : Visitor) : Visitor := fun d =>
match f d with
| β¨found, falseβ© => β¨found, falseβ©
| other => g other
instance : AndThen Visitor where
andThen a b := seq a (b ())
@[inline] def skip : Visitor := id
@[inline] def visitFVar (x y : FVarId) : Visitor
| d@{result := false, ..} => d
| {found := false, result := true} => {found := x == y, result := true}
| {found := true, result := true} => {found := true, result := x != y}
def visit (x : FVarId) : Expr β Visitor
| Expr.fvar y _ => visitFVar y x
| Expr.app f a _ => visit x a >> visit x f
| Expr.lam _ d b _ => visit x d >> visit x b
| Expr.forallE _ d b _ => visit x d >> visit x b
| Expr.letE _ t v b _ => visit x t >> visit x v >> visit x b
| Expr.mdata _ e _ => visit x e
| Expr.proj _ _ e _ => visit x e
| _ => skip
end atMostOnce
open atMostOnce (visit) in
/-- Return true iff the free variable with id `x` occurs at most once in `e` -/
@[export lean_at_most_once]
def atMostOnce (e : Expr) (x : FVarId) : Bool :=
let {result := result, ..} := visit x e {found := false, result := true}
result
/- Helper functions for creating auxiliary names used in compiler passes. -/
@[export lean_mk_eager_lambda_lifting_name]
def mkEagerLambdaLiftingName (n : Name) (idx : Nat) : Name :=
Name.mkStr n ("_elambda_" ++ toString idx)
@[export lean_is_eager_lambda_lifting_name]
def isEagerLambdaLiftingName : Name β Bool
| Name.str p s _ => "_elambda".isPrefixOf s || isEagerLambdaLiftingName p
| Name.num p _ _ => isEagerLambdaLiftingName p
| _ => false
/-- Return the name of new definitions in the a given declaration.
Here we consider only declarations we generate code for.
We use this definition to implement `add_and_compile`. -/
@[export lean_get_decl_names_for_code_gen]
private def getDeclNamesForCodeGen : Declaration β List Name
| Declaration.defnDecl { name := n, .. } => [n]
| Declaration.mutualDefnDecl defs => defs.map fun d => d.name
| Declaration.opaqueDecl { name := n, .. } => [n]
| Declaration.axiomDecl { name := n, .. } => [n] -- axiom may be tagged with `@[extern ...]`
| _ => []
def checkIsDefinition (env : Environment) (n : Name) : Except String Unit :=
match env.find? n with
| (some (ConstantInfo.defnInfo _)) => Except.ok ()
| (some (ConstantInfo.opaqueInfo _)) => Except.ok ()
| none => Except.error s!"unknow declaration '{n}'"
| _ => Except.error s!"declaration is not a definition '{n}'"
/--
We generate auxiliary unsafe definitions for regular recursive definitions.
The auxiliary unsafe definition has a clear runtime cost execution model.
This function returns the auxiliary unsafe definition name for the given name. -/
@[export lean_mk_unsafe_rec_name]
def mkUnsafeRecName (declName : Name) : Name :=
Name.mkStr declName "_unsafe_rec"
/-- Return `some _` if the given name was created using `mkUnsafeRecName` -/
@[export lean_is_unsafe_rec_name]
def isUnsafeRecName? : Name β Option Name
| Name.str n "_unsafe_rec" _ => some n
| _ => none
end Lean.Compiler
|
9d8253852ddb8e91ce09a55a1b1ac823153ca079 | f618aea02cb4104ad34ecf3b9713065cc0d06103 | /src/set_theory/ordinal_notation.lean | 0dc3172878ea8790d7a3681259998a5190eeacd8 | [
"Apache-2.0"
] | permissive | joehendrix/mathlib | 84b6603f6be88a7e4d62f5b1b0cbb523bb82b9a5 | c15eab34ad754f9ecd738525cb8b5a870e834ddc | refs/heads/master | 1,589,606,591,630 | 1,555,946,393,000 | 1,555,946,393,000 | 182,813,854 | 0 | 0 | null | 1,555,946,309,000 | 1,555,946,308,000 | null | UTF-8 | Lean | false | false | 35,791 | lean | /-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Mario Carneiro
Ordinal notations (constructive ordinal arithmetic for ordinals < Ξ΅β).
-/
import set_theory.ordinal data.pnat
open ordinal
local attribute [instance, priority 0] nat.cast_coe
local notation `Ο` := omega.{0}
/-- Recursive definition of an ordinal notation. `zero` denotes the
ordinal 0, and `oadd e n a` is intended to refer to `Ο^e * n + a`.
For this to be valid Cantor normal form, we must have the exponents
decrease to the right, but we can't state this condition until we've
defined `repr`, so it is a separate definition `NF`. -/
@[derive decidable_eq]
inductive onote : Type
| zero : onote
| oadd : onote β β+ β onote β onote
namespace onote
/-- Notation for 0 -/
instance : has_zero onote := β¨zeroβ©
@[simp] theorem zero_def : zero = 0 := rfl
/-- Notation for 1 -/
instance : has_one onote := β¨oadd 0 1 0β©
/-- Notation for Ο -/
def omega : onote := oadd 1 1 0
/-- The ordinal denoted by a notation -/
@[simp] noncomputable def repr : onote β ordinal.{0}
| 0 := 0
| (oadd e n a) := Ο ^ repr e * n + repr a
def to_string_aux1 (e : onote) (n : β) (s : string) : string :=
if e = 0 then _root_.to_string n else
(if e = 1 then "Ο" else "Ο^(" ++ s ++ ")") ++
if n = 1 then "" else "*" ++ _root_.to_string n
/-- Print an ordinal notation -/
def to_string : onote β string
| zero := "0"
| (oadd e n 0) := to_string_aux1 e n (to_string e)
| (oadd e n a) := to_string_aux1 e n (to_string e) ++ " + " ++ to_string a
/-- Print an ordinal notation -/
def repr' : onote β string
| zero := "0"
| (oadd e n a) := "(oadd " ++ repr' e ++ " " ++ _root_.to_string (n:β) ++ " " ++ repr' a ++ ")"
instance : has_to_string onote := β¨to_stringβ©
instance : has_repr onote := β¨repr'β©
instance : preorder onote :=
{ le := Ξ» x y, repr x β€ repr y,
lt := Ξ» x y, repr x < repr y,
le_refl := Ξ» a, @le_refl ordinal _ _,
le_trans := Ξ» a b c, @le_trans ordinal _ _ _ _,
lt_iff_le_not_le := Ξ» a b, @lt_iff_le_not_le ordinal _ _ _ }
theorem lt_def {x y : onote} : x < y β repr x < repr y := iff.rfl
theorem le_def {x y : onote} : x β€ y β repr x β€ repr y := iff.rfl
/-- Convert a `nat` into an ordinal -/
@[simp] def of_nat : β β onote
| 0 := 0
| (nat.succ n) := oadd 0 n.succ_pnat 0
@[simp] theorem of_nat_one : of_nat 1 = 1 := rfl
@[simp] theorem repr_of_nat (n : β) : repr (of_nat n) = n :=
by cases n; simp
@[simp] theorem repr_one : repr 1 = 1 :=
by simpa using repr_of_nat 1
theorem omega_le_oadd (e n a) : Ο ^ repr e β€ repr (oadd e n a) :=
begin
unfold repr,
refine le_trans _ (le_add_right _ _),
simpa using (mul_le_mul_iff_left $ power_pos (repr e) omega_pos).2 (nat_cast_le.2 n.2)
end
theorem oadd_pos (e n a) : 0 < oadd e n a :=
@lt_of_lt_of_le _ _ _ _ _ (power_pos _ omega_pos)
(omega_le_oadd _ _ _)
/-- Compare ordinal notations -/
def cmp : onote β onote β ordering
| 0 0 := ordering.eq
| _ 0 := ordering.gt
| 0 _ := ordering.lt
| oβ@(oadd eβ nβ aβ) oβ@(oadd eβ nβ aβ) :=
(cmp eβ eβ).or_else $ (_root_.cmp (nβ:β) nβ).or_else (cmp aβ aβ)
theorem eq_of_cmp_eq : β {oβ oβ}, cmp oβ oβ = ordering.eq β oβ = oβ
| 0 0 h := rfl
| (oadd e n a) 0 h := by injection h
| 0 (oadd e n a) h := by injection h
| oβ@(oadd eβ nβ aβ) oβ@(oadd eβ nβ aβ) h := begin
revert h, simp [cmp],
cases hβ : cmp eβ eβ; intro h; try {cases h},
have := eq_of_cmp_eq hβ, subst eβ,
revert h, cases hβ : _root_.cmp (nβ:β) nβ; intro h; try {cases h},
have := eq_of_cmp_eq h, subst aβ,
rw [_root_.cmp, cmp_using_eq_eq] at hβ,
have := subtype.eq (eq_of_incomp hβ), subst nβ, simp
end
theorem zero_lt_one : (0 : onote) < 1 :=
by rw [lt_def, repr, repr_one]; exact zero_lt_one
/-- `NF_below o b` says that `o` is a normal form ordinal notation
satisfying `repr o < Ο ^ b`. -/
inductive NF_below : onote β ordinal.{0} β Prop
| zero {b} : NF_below 0 b
| oadd' {e n a eb b} : NF_below e eb β
NF_below a (repr e) β repr e < b β NF_below (oadd e n a) b
/-- A normal form ordinal notation has the form
Ο ^ aβ * nβ + Ο ^ aβ * nβ + ... Ο ^ aβ * nβ
where `aβ > aβ > ... > aβ` and all the `aα΅’` are
also in normal form.
We will essentially only be interested in normal form
ordinal notations, but to avoid complicating the algorithms
we define everything over general ordinal notations and
only prove correctness with normal form as an invariant. -/
@[class] def NF (o : onote) := Exists (NF_below o)
instance NF.zero : NF 0 := β¨0, NF_below.zeroβ©
theorem NF_below.oadd {e n a b} : NF e β
NF_below a (repr e) β repr e < b β NF_below (oadd e n a) b
| β¨eb, hβ© := NF_below.oadd' h
theorem NF_below.fst {e n a b} (h : NF_below (oadd e n a) b) : NF e :=
by cases h with _ _ _ _ eb _ hβ hβ hβ; exact β¨_, hββ©
theorem NF.fst {e n a} : NF (oadd e n a) β NF e
| β¨b, hβ© := h.fst
theorem NF_below.snd {e n a b} (h : NF_below (oadd e n a) b) : NF_below a (repr e) :=
by cases h with _ _ _ _ eb _ hβ hβ hβ; exact hβ
theorem NF.snd' {e n a} : NF (oadd e n a) β NF_below a (repr e)
| β¨b, hβ© := h.snd
theorem NF.snd {e n a} (h : NF (oadd e n a)) : NF a :=
β¨_, h.snd'β©
theorem NF.oadd {e a} (hβ : NF e) (n)
(hβ : NF_below a (repr e)) : NF (oadd e n a) :=
β¨_, NF_below.oadd hβ hβ (ordinal.lt_succ_self _)β©
instance NF.oadd_zero (e n) [h : NF e] : NF (oadd e n 0) :=
h.oadd _ NF_below.zero
theorem NF_below.lt {e n a b} (h : NF_below (oadd e n a) b) : repr e < b :=
by cases h with _ _ _ _ eb _ hβ hβ hβ; exact hβ
theorem NF_below_zero : β {o}, NF_below o 0 β o = 0
| 0 := β¨Ξ» _, rfl, Ξ» _, NF_below.zeroβ©
| (oadd e n a) := β¨Ξ» h, (not_le_of_lt h.lt).elim (zero_le _),
Ξ» e, e.symm βΈ NF_below.zeroβ©
theorem NF.zero_of_zero {e n a} (h : NF (oadd e n a)) (e0 : e = 0) : a = 0 :=
by simpa [e0, NF_below_zero] using h.snd'
theorem NF_below.repr_lt {o b} (h : NF_below o b) : repr o < Ο ^ b :=
begin
induction h with _ e n a eb b hβ hβ hβ _ IH,
{ exact power_pos _ omega_pos },
{ rw repr,
refine lt_of_lt_of_le ((ordinal.add_lt_add_iff_left _).2 IH) _,
rw β mul_succ,
refine le_trans (mul_le_mul_left _ $ ordinal.succ_le.2 $ nat_lt_omega _) _,
rw β power_succ,
exact power_le_power_right omega_pos (ordinal.succ_le.2 hβ) }
end
theorem NF_below.mono {o bβ bβ} (bb : bβ β€ bβ) (h : NF_below o bβ) : NF_below o bβ :=
begin
induction h with _ e n a eb b hβ hβ hβ _ IH; constructor,
exacts [hβ, hβ, lt_of_lt_of_le hβ bb]
end
theorem NF.below_of_lt {e n a b} (H : repr e < b) : NF (oadd e n a) β NF_below (oadd e n a) b
| β¨b', hβ© := by cases h with _ _ _ _ eb _ hβ hβ hβ;
exact NF_below.oadd' hβ hβ H
theorem NF.below_of_lt' : β {o b}, repr o < Ο ^ b β NF o β NF_below o b
| 0 b H _ := NF_below.zero
| (oadd e n a) b H h := h.below_of_lt $ (power_lt_power_iff_right one_lt_omega).1 $
(lt_of_le_of_lt (omega_le_oadd _ _ _) H)
theorem NF_below_of_nat : β n, NF_below (of_nat n) 1
| 0 := NF_below.zero
| (nat.succ n) := NF_below.oadd NF.zero NF_below.zero ordinal.zero_lt_one
instance NF_of_nat (n) : NF (of_nat n) := β¨_, NF_below_of_nat nβ©
instance NF_one : NF 1 := by rw β of_nat_one; apply_instance
theorem oadd_lt_oadd_1 {eβ nβ oβ eβ nβ oβ}
(hβ : NF (oadd eβ nβ oβ)) (hβ : NF (oadd eβ nβ oβ))
(h : eβ < eβ) : oadd eβ nβ oβ < oadd eβ nβ oβ :=
@lt_of_lt_of_le _ _ _ _ _ ((hβ.below_of_lt h).repr_lt) (omega_le_oadd _ _ _)
theorem oadd_lt_oadd_2 {e nβ oβ nβ oβ}
(hβ : NF (oadd e nβ oβ)) (hβ : NF (oadd e nβ oβ))
(h : (nβ:β) < nβ) : oadd e nβ oβ < oadd e nβ oβ :=
begin
simp [lt_def],
refine lt_of_lt_of_le ((ordinal.add_lt_add_iff_left _).2 hβ.snd'.repr_lt)
(le_trans _ (le_add_right _ _)),
rwa [β mul_succ, mul_le_mul_iff_left (power_pos _ omega_pos),
ordinal.succ_le, nat_cast_lt]
end
theorem oadd_lt_oadd_3 {e n aβ aβ}
(hβ : NF (oadd e n aβ)) (hβ : NF (oadd e n aβ))
(h : aβ < aβ) : oadd e n aβ < oadd e n aβ :=
begin
rw lt_def, unfold repr,
exact (ordinal.add_lt_add_iff_left _).2 h
end
theorem cmp_compares : β (a b : onote) [NF a] [NF b], (cmp a b).compares a b
| 0 0 hβ hβ := rfl
| (oadd e n a) 0 hβ hβ := oadd_pos _ _ _
| 0 (oadd e n a) hβ hβ := oadd_pos _ _ _
| oβ@(oadd eβ nβ aβ) oβ@(oadd eβ nβ aβ) hβ hβ := begin
rw cmp,
have IHe := @cmp_compares _ _ hβ.fst hβ.fst,
cases cmp eβ eβ,
case ordering.lt { exact oadd_lt_oadd_1 hβ hβ IHe },
case ordering.gt { exact oadd_lt_oadd_1 hβ hβ IHe },
change eβ = eβ at IHe, subst IHe,
unfold _root_.cmp, cases nh : cmp_using (<) (nβ:β) nβ,
case ordering.lt {
rw cmp_using_eq_lt at nh, exact oadd_lt_oadd_2 hβ hβ nh },
case ordering.gt {
rw cmp_using_eq_gt at nh, exact oadd_lt_oadd_2 hβ hβ nh },
rw cmp_using_eq_eq at nh,
have := subtype.eq (eq_of_incomp nh), subst nβ,
have IHa := @cmp_compares _ _ hβ.snd hβ.snd,
cases cmp aβ aβ,
case ordering.lt { exact oadd_lt_oadd_3 hβ hβ IHa },
case ordering.gt { exact oadd_lt_oadd_3 hβ hβ IHa },
change aβ = aβ at IHa, subst IHa, exact rfl
end
theorem repr_inj {a b} [NF a] [NF b] : repr a = repr b β a = b :=
β¨match cmp a b, cmp_compares a b with
| ordering.lt, (h : repr a < repr b), e := (ne_of_lt h e).elim
| ordering.gt, (h : repr a > repr b), e := (ne_of_gt h e).elim
| ordering.eq, h, e := h
end, congr_arg _β©
theorem NF.of_dvd_omega_power {b e n a} (h : NF (oadd e n a)) (d : Ο ^ b β£ repr (oadd e n a)) :
b β€ repr e β§ Ο ^ b β£ repr a :=
begin
have := mt repr_inj.1 (Ξ» h, by injection h : oadd e n a β 0),
have L := le_of_not_lt (Ξ» l, not_le_of_lt (h.below_of_lt l).repr_lt (le_of_dvd this d)),
simp at d,
exact β¨L, (dvd_add_iff $ dvd_mul_of_dvd _ $ power_dvd_power _ L).1 dβ©
end
theorem NF.of_dvd_omega {e n a} (h : NF (oadd e n a)) :
Ο β£ repr (oadd e n a) β repr e β 0 β§ Ο β£ repr a :=
by rw [β power_one Ο, β one_le_iff_ne_zero]; exact h.of_dvd_omega_power
/-- `top_below b o` asserts that the largest exponent in `o`, if
it exists, is less than `b`. This is an auxiliary definition
for decidability of `NF`. -/
def top_below (b) : onote β Prop
| 0 := true
| (oadd e n a) := cmp e b = ordering.lt
instance decidable_top_below : decidable_rel top_below :=
by intros b o; cases o; delta top_below; apply_instance
theorem NF_below_iff_top_below {b} [NF b] : β {o},
NF_below o (repr b) β NF o β§ top_below b o
| 0 := β¨Ξ» h, β¨β¨_, hβ©, trivialβ©, Ξ» _, NF_below.zeroβ©
| (oadd e n a) :=
β¨Ξ» h, β¨β¨_, hβ©, (@cmp_compares _ b h.fst _).eq_lt.2 h.ltβ©,
Ξ» β¨hβ, hββ©, hβ.below_of_lt $ (@cmp_compares _ b hβ.fst _).eq_lt.1 hββ©
instance decidable_NF : decidable_pred NF
| 0 := is_true NF.zero
| (oadd e n a) := begin
have := decidable_NF e,
have := decidable_NF a, resetI,
apply decidable_of_iff (NF e β§ NF a β§ top_below e a),
abstract {
rw β and_congr_right (Ξ» h, @NF_below_iff_top_below _ h _),
exact β¨Ξ» β¨hβ, hββ©, NF.oadd hβ n hβ, Ξ» h, β¨h.fst, h.snd'β©β© },
end
/-- Addition of ordinal notations (correct only for normal input) -/
def add : onote β onote β onote
| 0 o := o
| (oadd e n a) o := match add a o with
| 0 := oadd e n 0
| o'@(oadd e' n' a') := match cmp e e' with
| ordering.lt := o'
| ordering.eq := oadd e (n + n') a'
| ordering.gt := oadd e n o'
end
end
instance : has_add onote := β¨addβ©
@[simp] theorem zero_add (o : onote) : 0 + o = o := rfl
theorem oadd_add (e n a o) : oadd e n a + o = add._match_1 e n (a + o) := rfl
/-- Subtraction of ordinal notations (correct only for normal input) -/
def sub : onote β onote β onote
| 0 o := 0
| o 0 := o
| oβ@(oadd eβ nβ aβ) (oadd eβ nβ aβ) := match cmp eβ eβ with
| ordering.lt := 0
| ordering.gt := oβ
| ordering.eq := match (nβ:β) - nβ with
| 0 := if nβ = nβ then sub aβ aβ else 0
| (nat.succ k) := oadd eβ k.succ_pnat aβ
end
end
instance : has_sub onote := β¨subβ©
theorem add_NF_below {b} : β {oβ oβ}, NF_below oβ b β NF_below oβ b β NF_below (oβ + oβ) b
| 0 o hβ hβ := hβ
| (oadd e n a) o hβ hβ := begin
have h' := add_NF_below (hβ.snd.mono $ le_of_lt hβ.lt) hβ,
simp [oadd_add], cases a + o with e' n' a',
{ exact NF_below.oadd hβ.fst NF_below.zero hβ.lt },
simp [add], have := @cmp_compares _ _ hβ.fst h'.fst,
cases cmp e e'; simp [add],
{ exact h' },
{ simp at this, subst e',
exact NF_below.oadd h'.fst h'.snd h'.lt },
{ exact NF_below.oadd hβ.fst (NF.below_of_lt this β¨_, h'β©) hβ.lt }
end
instance add_NF (oβ oβ) : β [NF oβ] [NF oβ], NF (oβ + oβ)
| β¨bβ, hββ© β¨bβ, hββ© := (bβ.le_total bβ).elim
(Ξ» h, β¨bβ, add_NF_below (hβ.mono h) hββ©)
(Ξ» h, β¨bβ, add_NF_below hβ (hβ.mono h)β©)
@[simp] theorem repr_add : β oβ oβ [NF oβ] [NF oβ], repr (oβ + oβ) = repr oβ + repr oβ
| 0 o hβ hβ := by simp
| (oadd e n a) o hβ hβ := begin
haveI := hβ.snd, have h' := repr_add a o,
conv at h' in (_+o) {simp [(+)]},
have nf := onote.add_NF a o,
conv at nf in (_+o) {simp [(+)]},
conv in (_+o) {simp [(+), add]},
cases add a o with e' n' a'; simp [add, h'.symm],
have := hβ.fst, have := nf.fst, have ee := cmp_compares e e',
cases cmp e e'; simp [add],
{ rw [β add_assoc, @add_absorp _ (repr e') (Ο ^ repr e' * (n':β))],
{ have := (hβ.below_of_lt ee).repr_lt, unfold repr at this,
exact lt_of_le_of_lt (le_add_right _ _) this },
{ simpa using (mul_le_mul_iff_left $
power_pos (repr e') omega_pos).2 (nat_cast_le.2 n'.pos) } },
{ change e = e' at ee, subst e',
rw [β add_assoc, β ordinal.mul_add, β nat.cast_add] }
end
theorem sub_NF_below : β {oβ oβ b}, NF_below oβ b β NF oβ β NF_below (oβ - oβ) b
| 0 o b hβ hβ := by cases o; exact NF_below.zero
| (oadd e n a) 0 b hβ hβ := hβ
| (oadd eβ nβ aβ) (oadd eβ nβ aβ) b hβ hβ := begin
have h' := sub_NF_below hβ.snd hβ.snd,
simp [has_sub.sub, sub] at h' β’,
have := @cmp_compares _ _ hβ.fst hβ.fst,
cases cmp eβ eβ; simp [sub],
{ apply NF_below.zero },
{ simp at this, subst eβ,
cases mn : (nβ:β) - nβ; simp [sub],
{ by_cases en : nβ = nβ; simp [en],
{ exact h'.mono (le_of_lt hβ.lt) },
{ exact NF_below.zero } },
{ exact NF_below.oadd hβ.fst hβ.snd hβ.lt } },
{ exact hβ }
end
instance sub_NF (oβ oβ) : β [NF oβ] [NF oβ], NF (oβ - oβ)
| β¨bβ, hββ© hβ := β¨bβ, sub_NF_below hβ hββ©
@[simp] theorem repr_sub : β oβ oβ [NF oβ] [NF oβ], repr (oβ - oβ) = repr oβ - repr oβ
| 0 o hβ hβ := by cases o; exact (ordinal.zero_sub _).symm
| (oadd e n a) 0 hβ hβ := (ordinal.sub_zero _).symm
| (oadd eβ nβ aβ) (oadd eβ nβ aβ) hβ hβ := begin
haveI := hβ.snd, haveI := hβ.snd, have h' := repr_sub aβ aβ,
conv at h' in (aβ-aβ) {simp [has_sub.sub]},
have nf := onote.sub_NF aβ aβ,
conv at nf in (aβ-aβ) {simp [has_sub.sub]},
conv in (_-oadd _ _ _) {simp [has_sub.sub, sub]},
have ee := @cmp_compares _ _ hβ.fst hβ.fst,
cases cmp eβ eβ,
{ rw [sub_eq_zero_iff_le.2], {refl},
exact le_of_lt (oadd_lt_oadd_1 hβ hβ ee) },
{ change eβ = eβ at ee, subst eβ, unfold sub._match_1,
cases mn : (nβ:β) - nβ; dsimp only [sub._match_2],
{ by_cases en : nβ = nβ,
{ simp [en], rwa [add_sub_add_cancel] },
{ simp [en, -repr],
exact (sub_eq_zero_iff_le.2 $ le_of_lt $ oadd_lt_oadd_2 hβ hβ $
lt_of_le_of_ne (nat.sub_eq_zero_iff_le.1 mn) (mt pnat.eq en)).symm } },
{ simp [nat.succ_pnat, -nat.cast_succ],
rw [(nat.sub_eq_iff_eq_add $ le_of_lt $ nat.lt_of_sub_eq_succ mn).1 mn,
add_comm, nat.cast_add, ordinal.mul_add, add_assoc, add_sub_add_cancel],
refine (ordinal.sub_eq_of_add_eq $ add_absorp hβ.snd'.repr_lt $
le_trans _ (le_add_right _ _)).symm,
simpa using mul_le_mul_left _ (nat_cast_le.2 $ nat.succ_pos _) } },
{ exact (ordinal.sub_eq_of_add_eq $ add_absorp (hβ.below_of_lt ee).repr_lt $
omega_le_oadd _ _ _).symm }
end
/-- Multiplication of ordinal notations (correct only for normal input) -/
def mul : onote β onote β onote
| 0 _ := 0
| _ 0 := 0
| oβ@(oadd eβ nβ aβ) (oadd eβ nβ aβ) :=
if eβ = 0 then oadd eβ (nβ * nβ) aβ else
oadd (eβ + eβ) nβ (mul oβ aβ)
instance : has_mul onote := β¨mulβ©
@[simp] theorem zero_mul (o : onote) : 0 * o = 0 := by cases o; refl
@[simp] theorem mul_zero (o : onote) : o * 0 = 0 := by cases o; refl
theorem oadd_mul (eβ nβ aβ eβ nβ aβ) : oadd eβ nβ aβ * oadd eβ nβ aβ =
if eβ = 0 then oadd eβ (nβ * nβ) aβ else
oadd (eβ + eβ) nβ (oadd eβ nβ aβ * aβ) := rfl
theorem oadd_mul_NF_below {eβ nβ aβ bβ} (hβ : NF_below (oadd eβ nβ aβ) bβ) :
β {oβ bβ}, NF_below oβ bβ β NF_below (oadd eβ nβ aβ * oβ) (repr eβ + bβ)
| 0 bβ hβ := NF_below.zero
| (oadd eβ nβ aβ) bβ hβ := begin
have IH := oadd_mul_NF_below hβ.snd,
by_cases e0 : eβ = 0; simp [e0, oadd_mul],
{ apply NF_below.oadd hβ.fst hβ.snd,
simpa using (add_lt_add_iff_left (repr eβ)).2
(lt_of_le_of_lt (ordinal.zero_le _) hβ.lt) },
{ haveI := hβ.fst, haveI := hβ.fst,
apply NF_below.oadd, apply_instance,
{ rwa repr_add },
{ rw [repr_add, ordinal.add_lt_add_iff_left], exact hβ.lt } }
end
instance mul_NF : β oβ oβ [NF oβ] [NF oβ], NF (oβ * oβ)
| 0 o hβ hβ := by cases o; exact NF.zero
| (oadd e n a) o β¨bβ, hbββ© β¨bβ, hbββ© :=
β¨_, oadd_mul_NF_below hbβ hbββ©
@[simp] theorem repr_mul : β oβ oβ [NF oβ] [NF oβ], repr (oβ * oβ) = repr oβ * repr oβ
| 0 o hβ hβ := by cases o; exact (ordinal.zero_mul _).symm
| (oadd eβ nβ aβ) 0 hβ hβ := (ordinal.mul_zero _).symm
| (oadd eβ nβ aβ) (oadd eβ nβ aβ) hβ hβ := begin
have IH : repr (mul _ _) = _ := @repr_mul _ _ hβ hβ.snd,
conv {to_lhs, simp [(*)]},
have ao : repr aβ + Ο ^ repr eβ * (nβ:β) = Ο ^ repr eβ * (nβ:β),
{ apply add_absorp hβ.snd'.repr_lt,
simpa using (mul_le_mul_iff_left $ power_pos _ omega_pos).2
(nat_cast_le.2 nβ.2) },
by_cases e0 : eβ = 0; simp [e0, mul],
{ cases nat.exists_eq_succ_of_ne_zero nβ.ne_zero with x xe,
simp [hβ.zero_of_zero e0, xe, -nat.cast_succ],
rw [β nat_cast_succ x, add_mul_succ _ ao, mul_assoc] },
{ haveI := hβ.fst, haveI := hβ.fst,
simp [IH, repr_add, power_add, ordinal.mul_add],
rw β mul_assoc, congr' 2,
have := mt repr_inj.1 e0,
rw [add_mul_limit ao (power_is_limit_left omega_is_limit this),
mul_assoc, mul_omega_dvd (nat_cast_pos.2 nβ.pos) (nat_lt_omega _)],
simpa using power_dvd_power Ο (one_le_iff_ne_zero.2 this) },
end
/-- Calculate division and remainder of `o` mod Ο.
`split' o = (a, n)` means `o = Ο * a + n`. -/
def split' : onote β onote Γ β
| 0 := (0, 0)
| (oadd e n a) := if e = 0 then (0, n) else
let (a', m) := split' a in (oadd (e - 1) n a', m)
/-- Calculate division and remainder of `o` mod Ο.
`split o = (a, n)` means `o = a + n`, where `Ο β£ a`. -/
def split : onote β onote Γ β
| 0 := (0, 0)
| (oadd e n a) := if e = 0 then (0, n) else
let (a', m) := split a in (oadd e n a', m)
/-- `scale x o` is the ordinal notation for `Ο ^ x * o`. -/
def scale (x : onote) : onote β onote
| 0 := 0
| (oadd e n a) := oadd (x + e) n (scale a)
/-- `mul_nat o n` is the ordinal notation for `o * n`. -/
def mul_nat : onote β β β onote
| 0 m := 0
| _ 0 := 0
| (oadd e n a) (m+1) := oadd e (n * m.succ_pnat) a
def power_aux (e a0 a : onote) : β β β β onote
| _ 0 := 0
| 0 (m+1) := oadd e m.succ_pnat 0
| (k+1) m := scale (e + mul_nat a0 k) a + power_aux k m
/-- `power oβ oβ` calculates the ordinal notation for
the ordinal exponential `oβ ^ oβ`. -/
def power (oβ oβ : onote) : onote :=
match split oβ with
| (0, 0) := if oβ = 0 then 1 else 0
| (0, 1) := 1
| (0, m+1) := let (b', k) := split' oβ in
oadd b' (@has_pow.pow β+ _ _ m.succ_pnat k) 0
| (a@(oadd a0 _ _), m) := match split oβ with
| (b, 0) := oadd (a0 * b) 1 0
| (b, k+1) := let eb := a0*b in
scale (eb + mul_nat a0 k) a + power_aux eb a0 (mul_nat a m) k m
end
end
instance : has_pow onote onote := β¨powerβ©
theorem power_def (oβ oβ : onote) : oβ ^ oβ = power._match_1 oβ (split oβ) := rfl
theorem split_eq_scale_split' : β {o o' m} [NF o], split' o = (o', m) β split o = (scale 1 o', m)
| 0 o' m h p := by injection p; substs o' m; refl
| (oadd e n a) o' m h p := begin
by_cases e0 : e = 0; simp [e0, split, split'] at p β’,
{ rcases p with β¨rfl, rflβ©, exact β¨rfl, rflβ© },
{ revert p, cases h' : split' a with a' m',
haveI := h.fst, haveI := h.snd,
simp [split_eq_scale_split' h', split, split'],
have : 1 + (e - 1) = e,
{ refine repr_inj.1 _, simp,
have := mt repr_inj.1 e0,
exact add_sub_cancel_of_le (one_le_iff_ne_zero.2 this) },
intros, substs o' m, simp [scale, this] }
end
theorem NF_repr_split' : β {o o' m} [NF o], split' o = (o', m) β NF o' β§ repr o = Ο * repr o' + m
| 0 o' m h p := by injection p; substs o' m; simp [NF.zero]
| (oadd e n a) o' m h p := begin
by_cases e0 : e = 0; simp [e0, split, split'] at p β’,
{ rcases p with β¨rfl, rflβ©,
simp [h.zero_of_zero e0, NF.zero] },
{ revert p, cases h' : split' a with a' m',
haveI := h.fst, haveI := h.snd,
cases NF_repr_split' h' with IHβ IHβ,
simp [IHβ, split'],
intros, substs o' m,
have : Ο ^ repr e = Ο ^ (1 : ordinal.{0}) * Ο ^ (repr e - 1),
{ have := mt repr_inj.1 e0,
rw [β power_add, add_sub_cancel_of_le (one_le_iff_ne_zero.2 this)] },
refine β¨NF.oadd (by apply_instance) _ _, _β©,
{ simp at this β’,
refine IHβ.below_of_lt' ((mul_lt_mul_iff_left omega_pos).1 $
lt_of_le_of_lt (le_add_right _ m') _),
rw [β this, β IHβ], exact h.snd'.repr_lt },
{ rw this, simp [ordinal.mul_add, mul_assoc] } }
end
theorem scale_eq_mul (x) [NF x] : β o [NF o], scale x o = oadd x 1 0 * o
| 0 h := rfl
| (oadd e n a) h := begin
simp [(*)], simp [mul, scale],
haveI := h.snd,
by_cases e0 : e = 0,
{ rw scale_eq_mul, simp [e0, h.zero_of_zero, show x + 0 = x, from repr_inj.1 (by simp)] },
{ simp [e0, scale_eq_mul, (*)] }
end
instance NF_scale (x) [NF x] (o) [NF o] : NF (scale x o) :=
by rw scale_eq_mul; apply_instance
@[simp] theorem repr_scale (x) [NF x] (o) [NF o] : repr (scale x o) = Ο ^ repr x * repr o :=
by simp [scale_eq_mul]
theorem NF_repr_split {o o' m} [NF o] (h : split o = (o', m)) : NF o' β§ repr o = repr o' + m :=
begin
cases e : split' o with a n,
cases NF_repr_split' e with sβ sβ, resetI,
rw split_eq_scale_split' e at h,
injection h, substs o' n,
simp [repr_scale, sβ.symm],
apply_instance
end
theorem split_dvd {o o' m} [NF o] (h : split o = (o', m)) : Ο β£ repr o' :=
begin
cases e : split' o with a n,
rw split_eq_scale_split' e at h,
injection h, subst o',
cases NF_repr_split' e, resetI, simp [dvd_mul]
end
theorem split_add_lt {o e n a m} [NF o] (h : split o = (oadd e n a, m)) : repr a + m < Ο ^ repr e :=
begin
cases NF_repr_split h with hβ hβ,
cases hβ.of_dvd_omega (split_dvd h) with e0 d,
have := hβ.fst, have := hβ.snd,
refine add_lt_omega_power hβ.snd'.repr_lt (lt_of_lt_of_le (nat_lt_omega _) _),
simpa using power_le_power_right omega_pos (one_le_iff_ne_zero.2 e0),
end
@[simp] theorem mul_nat_eq_mul (n o) : mul_nat o n = o * of_nat n :=
by cases o; cases n; refl
instance NF_mul_nat (o) [NF o] (n) : NF (mul_nat o n) :=
by simp; apply_instance
instance NF_power_aux (e a0 a) [NF e] [NF a0] [NF a] : β k m, NF (power_aux e a0 a k m)
| k 0 := by cases k; exact NF.zero
| 0 (m+1) := NF.oadd_zero _ _
| (k+1) (m+1) := by haveI := NF_power_aux k;
simp [power_aux, nat.succ_ne_zero]; apply_instance
instance NF_power (oβ oβ) [NF oβ] [NF oβ] : NF (oβ ^ oβ) :=
begin
cases eβ : split oβ with a m,
have na := (NF_repr_split eβ).1,
cases eβ : split' oβ with b' k,
haveI := (NF_repr_split' eβ).1,
cases a with a0 n a',
{ cases m with m,
{ by_cases oβ = 0; simp [pow, power, eβ, h]; apply_instance },
{ by_cases m = 0; simp [pow, power, eβ, eβ, h]; apply_instance } },
{ simp [pow, power, eβ, eβ, split_eq_scale_split' eβ],
have := na.fst,
cases k with k; simp [succ_eq_add_one, power]; apply_instance }
end
theorem scale_power_aux (e a0 a : onote) [NF e] [NF a0] [NF a] :
β k m, repr (power_aux e a0 a k m) = Ο ^ repr e * repr (power_aux 0 a0 a k m)
| 0 m := by cases m; simp [power_aux]
| (k+1) m := by by_cases m = 0; simp [h, power_aux,
ordinal.mul_add, power_add, mul_assoc, scale_power_aux]
theorem repr_power_auxβ {e a} [Ne : NF e] [Na : NF a] {a' : ordinal}
(e0 : repr e β 0) (h : a' < Ο ^ repr e) (aa : repr a = a') (n : β+) :
(Ο ^ repr e * (n:β) + a') ^ Ο = (Ο ^ repr e) ^ Ο :=
begin
subst aa,
have No := Ne.oadd n (Na.below_of_lt' h),
have := omega_le_oadd e n a, unfold repr at this,
refine le_antisymm _ (power_le_power_left _ this),
apply (power_le_of_limit
(ne_of_gt $ lt_of_lt_of_le (power_pos _ omega_pos) this) omega_is_limit).2,
intros b l,
have := (No.below_of_lt (lt_succ_self _)).repr_lt, unfold repr at this,
apply le_trans (power_le_power_left b $ le_of_lt this),
rw [β power_mul, β power_mul],
apply power_le_power_right omega_pos,
cases le_or_lt Ο (repr e) with h h,
{ apply le_trans (mul_le_mul_left _ $ le_of_lt $ lt_succ_self _),
rw [succ, add_mul_succ _ (one_add_of_omega_le h), β succ,
succ_le, mul_lt_mul_iff_left (pos_iff_ne_zero.2 e0)],
exact omega_is_limit.2 _ l },
{ refine le_trans (le_of_lt $ mul_lt_omega (omega_is_limit.2 _ h) l) _,
simpa using mul_le_mul_right Ο (one_le_iff_ne_zero.2 e0) }
end
section
local infixr ^ := @pow ordinal.{0} ordinal ordinal.has_pow
theorem repr_power_auxβ {a0 a'} [N0 : NF a0] [Na' : NF a'] (m : β)
(d : Ο β£ repr a')
(e0 : repr a0 β 0) (h : repr a' + m < Ο ^ repr a0) (n : β+) (k : β) :
let R := repr (power_aux 0 a0 (oadd a0 n a' * of_nat m) k m) in
(k β 0 β R < (Ο ^ repr a0) ^ succ k) β§
(Ο ^ repr a0) ^ k * (Ο ^ repr a0 * (n:β) + repr a') + R =
(Ο ^ repr a0 * (n:β) + repr a' + m) ^ succ k :=
begin
intro,
haveI No : NF (oadd a0 n a') :=
N0.oadd n (Na'.below_of_lt' $ lt_of_le_of_lt (le_add_right _ _) h),
induction k with k IH, {cases m; simp [power_aux, R]},
rename R R', let R := repr (power_aux 0 a0 (oadd a0 n a' * of_nat m) k m),
let Ο0 := Ο ^ repr a0, let Ξ±' := Ο0 * n + repr a',
change (k β 0 β R < Ο0 ^ succ k) β§ Ο0 ^ k * Ξ±' + R = (Ξ±' + m) ^ succ k at IH,
have RR : R' = Ο0 ^ k * (Ξ±' * m) + R,
{ by_cases m = 0; simp [h, R', power_aux, R, power_mul],
{ cases k; simp [power_aux] }, { refl } },
have Ξ±0 : 0 < Ξ±', {simpa [Ξ±', lt_def, repr] using oadd_pos a0 n a'},
have Ο00 : 0 < Ο0 ^ k := power_pos _ (power_pos _ omega_pos),
have Rl : R < Ο ^ (repr a0 * succ βk),
{ by_cases k0 : k = 0,
{ simp [k0],
refine lt_of_lt_of_le _ (power_le_power_right omega_pos (one_le_iff_ne_zero.2 e0)),
cases m with m; simp [k0, R, power_aux, omega_pos],
rw [β nat.cast_succ], apply nat_lt_omega },
{ rw power_mul, exact IH.1 k0 } },
refine β¨Ξ»_, _, _β©,
{ rw [RR, β power_mul _ _ (succ k.succ)],
have e0 := pos_iff_ne_zero.2 e0,
have rr0 := lt_of_lt_of_le e0 (le_add_left _ _),
apply add_lt_omega_power,
{ simp [power_mul, Ο0, power_add],
rw [mul_lt_mul_iff_left Ο00, β ordinal.power_add],
have := (No.below_of_lt _).repr_lt, unfold repr at this,
refine mul_lt_omega_power rr0 this (nat_lt_omega _),
simpa using (add_lt_add_iff_left (repr a0)).2 e0 },
{ refine lt_of_lt_of_le Rl (power_le_power_right omega_pos $
mul_le_mul_left _ $ succ_le_succ.2 $ nat_cast_le.2 $ le_of_lt k.lt_succ_self) } },
refine calc
Ο0 ^ k.succ * Ξ±' + R'
= Ο0 ^ succ k * Ξ±' + (Ο0 ^ k * Ξ±' * m + R) : by rw [nat_cast_succ, RR, β mul_assoc]
... = (Ο0 ^ k * Ξ±' + R) * Ξ±' + (Ο0 ^ k * Ξ±' + R) * m : _
... = (Ξ±' + m) ^ succ k.succ : by rw [β ordinal.mul_add, β nat_cast_succ, power_succ, IH.2],
congr' 1,
{ have Ξ±d : Ο β£ Ξ±' := dvd_add (dvd_mul_of_dvd _
(by simpa using power_dvd_power Ο (one_le_iff_ne_zero.2 e0))) d,
rw [ordinal.mul_add (Ο0 ^ k), add_assoc, β mul_assoc, β power_succ,
add_mul_limit _ (is_limit_iff_omega_dvd.2 β¨ne_of_gt Ξ±0, Ξ±dβ©), mul_assoc,
@mul_omega_dvd n (nat_cast_pos.2 n.pos) (nat_lt_omega _) _ Ξ±d],
apply @add_absorp _ (repr a0 * succ k),
{ refine add_lt_omega_power _ Rl,
rw [power_mul, power_succ, mul_lt_mul_iff_left Ο00],
exact No.snd'.repr_lt },
{ have := mul_le_mul_left (Ο0 ^ succ k) (one_le_iff_pos.2 $ nat_cast_pos.2 n.pos),
rw power_mul, simpa [-power_succ] } },
{ cases m,
{ have : R = 0, {cases k; simp [R, power_aux]}, simp [this] },
{ rw [β nat_cast_succ, add_mul_succ],
apply add_absorp Rl,
rw [power_mul, power_succ],
apply ordinal.mul_le_mul_left,
simpa [Ξ±', repr] using omega_le_oadd a0 n a' } }
end
end
theorem repr_power (oβ oβ) [NF oβ] [NF oβ] : repr (oβ ^ oβ) = repr oβ ^ repr oβ :=
begin
cases eβ : split oβ with a m,
cases NF_repr_split eβ with Nβ rβ,
cases a with a0 n a',
{ cases m with m,
{ by_cases oβ = 0; simp [power_def, power, eβ, h, rβ],
have := mt repr_inj.1 h, rw zero_power this },
{ cases eβ : split' oβ with b' k,
cases NF_repr_split' eβ with _ rβ,
by_cases m = 0; simp [power_def, power, eβ, h, rβ, eβ, rβ, -nat.cast_succ],
rw [power_add, power_mul, power_omega _ (nat_lt_omega _)],
simpa using nat_cast_lt.2 (nat.succ_lt_succ $ nat.pos_iff_ne_zero.2 h) } },
{ haveI := Nβ.fst, haveI := Nβ.snd,
cases Nβ.of_dvd_omega (split_dvd eβ) with a00 ad,
have al := split_add_lt eβ,
have aa : repr (a' + of_nat m) = repr a' + m, {simp},
cases eβ : split' oβ with b' k,
cases NF_repr_split' eβ with _ rβ,
simp [power_def, power, eβ, rβ, split_eq_scale_split' eβ],
cases k with k,
{ simp [power, rβ, power_mul, repr_power_auxβ a00 al aa] },
{ simp [succ_eq_add_one, power, rβ, power_add, power_mul, mul_assoc],
rw [repr_power_auxβ a00 al aa, scale_power_aux], simp [power_mul],
rw [β ordinal.mul_add, β add_assoc (Ο ^ repr a0 * (n:β))], congr' 1,
rw [β power_succ],
exact (repr_power_auxβ _ ad a00 al _ _).2 } }
end
end onote
/-- The type of normal ordinal notations. (It would have been
nicer to define this right in the inductive type, but `NF o`
requires `repr` which requires `onote`, so all these things
would have to be defined at once, which messes up the VM
representation.) -/
def nonote := {o : onote // o.NF}
instance : decidable_eq nonote := by unfold nonote; apply_instance
namespace nonote
open onote
instance NF (o : nonote) : NF o.1 := o.2
/-- Construct a `nonote` from an ordinal notation
(and infer normality) -/
def mk (o : onote) [h : NF o] : nonote := β¨o, hβ©
/-- The ordinal represented by an ordinal notation.
(This function is noncomputable because ordinal
arithmetic is noncomputable. In computational applications
`nonote` can be used exclusively without reference
to `ordinal`, but this function allows for correctness
results to be stated.) -/
noncomputable def repr (o : nonote) : ordinal := o.1.repr
instance : has_to_string nonote := β¨Ξ» x, x.1.to_stringβ©
instance : has_repr nonote := β¨Ξ» x, x.1.repr'β©
instance : preorder nonote :=
{ le := Ξ» x y, repr x β€ repr y,
lt := Ξ» x y, repr x < repr y,
le_refl := Ξ» a, @le_refl ordinal _ _,
le_trans := Ξ» a b c, @le_trans ordinal _ _ _ _,
lt_iff_le_not_le := Ξ» a b, @lt_iff_le_not_le ordinal _ _ _ }
instance : has_zero nonote := β¨β¨0, NF.zeroβ©β©
/-- Convert a natural number to an ordinal notation -/
def of_nat (n : β) : nonote := β¨of_nat n, _, NF_below_of_nat _β©
/-- Compare ordinal notations -/
def cmp (a b : nonote) : ordering :=
cmp a.1 b.1
theorem cmp_compares : β a b : nonote, (cmp a b).compares a b
| β¨a, haβ© β¨b, hbβ© := begin
resetI,
dsimp [cmp], have := onote.cmp_compares a b,
cases onote.cmp a b; try {exact this},
exact subtype.mk_eq_mk.2 this
end
instance : linear_order nonote :=
{ le_antisymm := Ξ» a b, match cmp a b, cmp_compares a b with
| ordering.lt, h, hβ, hβ := (not_lt_of_le hβ).elim h
| ordering.eq, h, hβ, hβ := h
| ordering.gt, h, hβ, hβ := (not_lt_of_le hβ).elim h
end,
le_total := Ξ» a b, match cmp a b, cmp_compares a b with
| ordering.lt, h := or.inl (le_of_lt h)
| ordering.eq, h := or.inl (le_of_eq h)
| ordering.gt, h := or.inr (le_of_lt h)
end,
..nonote.preorder }
instance decidable_lt : @decidable_rel nonote (<)
| a b := decidable_of_iff _ (cmp_compares a b).eq_lt
instance : decidable_linear_order nonote :=
{ decidable_le := Ξ» a b, decidable_of_iff _ not_lt,
decidable_lt := nonote.decidable_lt,
..nonote.linear_order }
/-- Asserts that `repr a < Ο ^ repr b`. Used in `nonote.rec_on` -/
def below (a b : nonote) : Prop := NF_below a.1 (repr b)
/-- The `oadd` pseudo-constructor for `nonote` -/
def oadd (e : nonote) (n : β+) (a : nonote) (h : below a e) : nonote := β¨_, NF.oadd e.2 n hβ©
/-- This is a recursor-like theorem for `nonote` suggesting an
inductive definition, which can't actually be defined this
way due to conflicting dependencies. -/
@[elab_as_eliminator] def rec_on {C : nonote β Sort*} (o : nonote)
(H0 : C 0)
(H1 : β e n a h, C e β C a β C (oadd e n a h)) : C o :=
begin
cases o with o h, induction o with e n a IHe IHa,
{ exact H0 },
{ exact H1 β¨e, h.fstβ© n β¨a, h.sndβ© h.snd' (IHe _) (IHa _) }
end
/-- Addition of ordinal notations -/
instance : has_add nonote := β¨Ξ» x y, mk (x.1 + y.1)β©
theorem repr_add (a b) : repr (a + b) = repr a + repr b :=
onote.repr_add a.1 b.1
/-- Subtraction of ordinal notations -/
instance : has_sub nonote := β¨Ξ» x y, mk (x.1 - y.1)β©
theorem repr_sub (a b) : repr (a - b) = repr a - repr b :=
onote.repr_sub a.1 b.1
/-- Multiplication of ordinal notations -/
instance : has_mul nonote := β¨Ξ» x y, mk (x.1 * y.1)β©
theorem repr_mul (a b) : repr (a * b) = repr a * repr b :=
onote.repr_mul a.1 b.1
/-- Exponentiation of ordinal notations -/
def power (x y : nonote) := mk (x.1.power y.1)
theorem repr_power (a b) : repr (power a b) = (repr a).power (repr b) :=
onote.repr_power a.1 b.1
end nonote
|
d74cc00d12a2acfcb8981a37cee9c0e47adbe8ef | f3849be5d845a1cb97680f0bbbe03b85518312f0 | /library/init/data/string/basic.lean | 23717a37c6fcdb5239ef9dd70ba8efc94226cf3d | [
"Apache-2.0"
] | permissive | bjoeris/lean | 0ed95125d762b17bfcb54dad1f9721f953f92eeb | 4e496b78d5e73545fa4f9a807155113d8e6b0561 | refs/heads/master | 1,611,251,218,281 | 1,495,337,658,000 | 1,495,337,658,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 1,497 | lean | /-
Copyright (c) 2016 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Leonardo de Moura
-/
prelude
import init.data.list.basic
import init.data.char.basic
def string := list char
namespace string
@[pattern] def empty : string := list.nil
instance : inhabited string :=
β¨emptyβ©
instance : has_sizeof string :=
β¨list.sizeofβ©
@[pattern] def str : char β string β string := list.cons
def concat (a b : string) : string :=
list.append b a
instance : has_append string :=
β¨string.concatβ©
end string
open list
private def utf8_length_aux : nat β nat β string β nat
| 0 r (c::s) :=
let n := char.to_nat c in
if n < 0x80 then utf8_length_aux 0 (r+1) s
else if 0xC0 β€ n β§ n < 0xE0 then utf8_length_aux 1 (r+1) s
else if 0xE0 β€ n β§ n < 0xF0 then utf8_length_aux 2 (r+1) s
else if 0xF0 β€ n β§ n < 0xF8 then utf8_length_aux 3 (r+1) s
else if 0xF8 β€ n β§ n < 0xFC then utf8_length_aux 4 (r+1) s
else if 0xFC β€ n β§ n < 0xFE then utf8_length_aux 5 (r+1) s
else utf8_length_aux 0 (r+1) s
| (n+1) r (c::s) := utf8_length_aux n r s
| n r [] := r
def utf8_length : string β nat
| s := utf8_length_aux 0 0 (reverse s)
private def to_nat_core : list char β nat β nat
| [] r := r
| (c::cs) r :=
to_nat_core cs (char.to_nat c - char.to_nat '0' + r*10)
def string.to_nat (s : string) : nat :=
to_nat_core s.reverse 0
|
1453721dd2002b087faa5f9af7535399b03e4935 | b561a44b48979a98df50ade0789a21c79ee31288 | /stage0/src/Lean/Elab/PreDefinition/WF/PackDomain.lean | d609761d73cddf4ad35b065359e6fb1ac18dc9c7 | [
"Apache-2.0"
] | permissive | 3401ijk/lean4 | 97659c475ebd33a034fed515cb83a85f75ccfb06 | a5b1b8de4f4b038ff752b9e607b721f15a9a4351 | refs/heads/master | 1,693,933,007,651 | 1,636,424,845,000 | 1,636,424,845,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 5,051 | lean | /-
Copyright (c) 2021 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
import Lean.Elab.PreDefinition.Basic
namespace Lean.Elab.WF
open Meta
/--
Given a (dependent) tuple `t` (using `PSigma`) of the given arity.
Return an array containing its "elements".
Example: `mkTupleElems a 4` returns `#[a.1, a.2.1, a.2.2.1, a.2.2.2]`.
-/
private def mkTupleElems (t : Expr) (arity : Nat) : Array Expr := do
let mut result := #[]
let mut t := t
for i in [:arity - 1] do
result := result.push (mkProj ``PSigma 0 t)
t := mkProj ``PSigma 1 t
result.push t
/-- Create a unary application by packing the given arguments using `PSigma.mk` -/
partial def mkUnaryArg (type : Expr) (args : Array Expr) : MetaM Expr := do
go 0 type
where
go (i : Nat) (type : Expr) : MetaM Expr := do
if i < args.size - 1 then
let arg := args[i]
assert! type.isAppOfArity ``PSigma 2
let us := type.getAppFn.constLevels!
let Ξ± := type.appFn!.appArg!
let Ξ² := type.appArg!
assert! Ξ².isLambda
let type := Ξ².bindingBody!.instantiate1 arg
let rest β go (i+1) type
return mkApp4 (mkConst ``PSigma.mk us) Ξ± Ξ² arg rest
else
return args[i]
private partial def mkPSigmaCasesOn (y : Expr) (codomain : Expr) (xs : Array Expr) (value : Expr) : MetaM Expr := do
let mvar β mkFreshExprSyntheticOpaqueMVar codomain
let rec go (mvarId : MVarId) (y : FVarId) (ys : Array Expr) : MetaM Unit := do
if ys.size < xs.size - 1 then
let #[s] β cases mvarId y | unreachable!
go s.mvarId s.fields[1].fvarId! (ys.push s.fields[0])
else
let ys := ys.push (mkFVar y)
assignExprMVar mvarId (value.replaceFVars xs ys)
go mvar.mvarId! y.fvarId! #[]
instantiateMVars mvar
/--
Convert the given pre-definitions into unary functions.
We "pack" the arguments using `PSigma`.
-/
def packDomain (preDefs : Array PreDefinition) : MetaM (Array PreDefinition) := do
let mut preDefsNew := #[]
let mut arities := #[]
let mut modified := false
for preDef in preDefs do
let (preDefNew, arity, modifiedCurr) β lambdaTelescope preDef.value fun xs body => do
if xs.size == 0 then
throwError "well-founded recursion cannot be used, '{preDef.declName}' does not take any arguments"
if xs.size > 1 then
let bodyType β instantiateForall preDef.type xs
let mut d β inferType xs.back
for x in xs.pop.reverse do
d β mkAppOptM ``PSigma #[some (β inferType x), some (β mkLambdaFVars #[x] d)]
withLocalDeclD (β mkFreshUserName `_x) d fun tuple => do
let elems := mkTupleElems tuple xs.size
let codomain := bodyType.replaceFVars xs elems
let preDefNew:= { preDef with
declName := preDef.declName ++ `_unary
type := (β mkForallFVars #[tuple] codomain)
}
addAsAxiom preDefNew
return (preDefNew, xs.size, true)
else
return (preDef, 1, false)
modified := modified || modifiedCurr
arities := arities.push arity
preDefsNew := preDefsNew.push preDefNew
if !modified then
return preDefs
/- Return `some i` if `e` is a `preDefs[i]` application -/
let isAppOfPreDef? (e : Expr) : OptionM Nat := do
let f := e.getAppFn
guard f.isConst
preDefs.findIdx? (Β·.declName == f.constName!)
/- Return `some i` if `e` is a `preDefs[i]` application with `arities[i]` arguments. -/
let isTargetApp? (e : Expr) : OptionM Nat := do
let i β isAppOfPreDef? e
guard (e.getAppNumArgs == arities[i])
return i
-- Update values
for i in [:preDefs.size] do
let preDef := preDefs[i]
let preDefNew := preDefsNew[i]
let arity := arities[i]
let valueNew β lambdaTelescope preDef.value fun xs body => do
forallBoundedTelescope preDefNew.type (some 1) fun y codomain => do
let y := y[0]
let newBody β mkPSigmaCasesOn y codomain xs body
let visit (e : Expr) : MetaM TransformStep := do
if let some idx := isTargetApp? e |>.run then
let f := e.getAppFn
let fNew := mkConst preDefsNew[idx].declName f.constLevels!
let Expr.forallE _ d .. β inferType fNew | unreachable!
let argNew β mkUnaryArg d e.getAppArgs
return TransformStep.done <| mkApp fNew argNew
else
return TransformStep.done e
mkLambdaFVars #[y] (β transform newBody (post := visit))
if let some bad := valueNew.find? fun e => (isAppOfPreDef? e).isSome && e.getAppNumArgs > 1 then
if let some i := isAppOfPreDef? bad then
throwErrorAt preDef.ref "well-founded recursion cannot be used, function '{preDef.declName}' contains application of function '{preDefs[i].declName}' with #{bad.getAppNumArgs} argument(s), but function has arity {arities[i]}"
preDefsNew := preDefsNew.set! i { preDefNew with value := valueNew }
return preDefsNew
end Lean.Elab.WF
|
aa827736e1a69978d60dd404cc9ad3312eb78f36 | 947b78d97130d56365ae2ec264df196ce769371a | /stage0/src/Lean/Data/Position.lean | bf46839a8bdc05b701c0a9d2f09f983ead8485c4 | [
"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 | 2,884 | lean | /-
Copyright (c) 2018 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura, Sebastian Ullrich
-/
import Lean.Data.Format
namespace Lean
structure Position :=
(line : Nat)
(column : Nat)
namespace Position
instance : DecidableEq Position :=
fun β¨lβ, cββ© β¨lβ, cββ© =>
if hβ : lβ = lβ then
if hβ : cβ = cβ then isTrue (Eq.recOn hβ (Eq.recOn hβ rfl))
else isFalse (fun contra => Position.noConfusion contra (fun eβ eβ => absurd eβ hβ))
else isFalse (fun contra => Position.noConfusion contra (fun eβ eβ => absurd eβ hβ))
protected def lt : Position β Position β Bool
| β¨lβ, cββ©, β¨lβ, cββ© => (lβ, cβ) < (lβ, cβ)
instance : HasFormat Position :=
β¨fun β¨l, cβ© => "β¨" ++ fmt l ++ ", " ++ fmt c ++ "β©"β©
instance : HasToString Position :=
β¨fun β¨l, cβ© => "β¨" ++ toString l ++ ", " ++ toString c ++ "β©"β©
instance : Inhabited Position := β¨β¨1, 0β©β©
end Position
structure FileMap :=
(source : String)
(positions : Array String.Pos)
(lines : Array Nat)
namespace FileMap
instance : Inhabited FileMap :=
β¨{ source := "", positions := #[], lines := #[] }β©
private partial def ofStringAux (s : String) : String.Pos β Nat β Array String.Pos β Array Nat β FileMap
| i, line, ps, lines =>
if s.atEnd i then { source := s, positions := ps.push i, lines := lines.push line }
else
let c := s.get i;
let i := s.next i;
if c == '\n' then ofStringAux i (line+1) (ps.push i) (lines.push (line+1))
else ofStringAux i line ps lines
def ofString (s : String) : FileMap :=
ofStringAux s 0 1 (#[0]) (#[1])
private partial def toColumnAux (str : String) (pos : String.Pos) : String.Pos β Nat β Nat
| i, c =>
if i == pos || str.atEnd i then c
else toColumnAux (str.next i) (c+1)
/- Remark: `pos` is in `[ps.get b, ps.get e]` and `b < e` -/
private partial def toPositionAux (str : String) (ps : Array Nat) (lines : Array Nat) (pos : String.Pos) : Nat β Nat β Position
| b, e =>
let posB := ps.get! b;
if e == b + 1 then { line := lines.get! b, column := toColumnAux str pos posB 0 }
else
let m := (b + e) / 2;
let posM := ps.get! m;
if pos == posM then { line := lines.get! m, column := 0 }
else if pos > posM then toPositionAux m e
else toPositionAux b m
def toPosition : FileMap β String.Pos β Position
| { source := str, positions := ps, lines := lines }, pos =>
if ps.size >= 2 && pos <= ps.back then
toPositionAux str ps lines pos 0 (ps.size-1)
else
-- Some systems like the delaborator use synthetic positions without an input file,
-- which would violate `toPositionAux`'s invariant
β¨1, posβ©
end FileMap
end Lean
def String.toFileMap (s : String) : Lean.FileMap :=
Lean.FileMap.ofString s
|
9af1998549733d172619a9582cbaac7fe2b4ce63 | e00ea76a720126cf9f6d732ad6216b5b824d20a7 | /src/data/equiv/basic.lean | cdff2f98b48da2eb069bc953f341338e944687b3 | [
"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 | 47,114 | lean | /-
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura, Mario Carneiro
In the standard library we cannot assume the univalence axiom.
We say two types are equivalent if they are isomorphic.
Two equivalent types have the same cardinality.
-/
import tactic.split_ifs logic.function logic.unique data.set.function data.bool data.quot
open function
universes u v w z
variables {Ξ± : Sort u} {Ξ² : Sort v} {Ξ³ : Sort w}
/-- `Ξ± β Ξ²` is the type of functions from `Ξ± β Ξ²` with a two-sided inverse. -/
structure equiv (Ξ± : Sort*) (Ξ² : Sort*) :=
(to_fun : Ξ± β Ξ²)
(inv_fun : Ξ² β Ξ±)
(left_inv : left_inverse inv_fun to_fun)
(right_inv : right_inverse inv_fun to_fun)
infix ` β `:25 := equiv
def function.involutive.to_equiv {f : Ξ± β Ξ±} (h : involutive f) : Ξ± β Ξ± :=
β¨f, f, h.left_inverse, h.right_inverseβ©
namespace equiv
/-- `perm Ξ±` is the type of bijections from `Ξ±` to itself. -/
@[reducible] def perm (Ξ± : Sort*) := equiv Ξ± Ξ±
instance : has_coe_to_fun (Ξ± β Ξ²) :=
β¨_, to_funβ©
@[simp] theorem coe_fn_mk (f : Ξ± β Ξ²) (g l r) : (equiv.mk f g l r : Ξ± β Ξ²) = f :=
rfl
theorem eq_of_to_fun_eq : β {eβ eβ : equiv Ξ± Ξ²}, (eβ : Ξ± β Ξ²) = eβ β eβ = eβ
| β¨fβ, gβ, lβ, rββ© β¨fβ, gβ, lβ, rββ© h :=
have fβ = fβ, from h,
have gβ = gβ, from funext $ assume x,
have fβ (gβ x) = fβ (gβ x), from (rβ x).trans (rβ x).symm,
have fβ (gβ x) = fβ (gβ x), by { subst fβ, exact this },
show gβ x = gβ x, from injective_of_left_inverse lβ this,
by simp *
@[ext] lemma ext (f g : equiv Ξ± Ξ²) (H : β x, f x = g x) : f = g :=
eq_of_to_fun_eq (funext H)
@[ext] lemma perm.ext (Ο Ο : equiv.perm Ξ±) (H : β x, Ο x = Ο x) : Ο = Ο :=
equiv.ext _ _ H
@[refl] protected def refl (Ξ± : Sort*) : Ξ± β Ξ± := β¨id, id, Ξ» x, rfl, Ξ» x, rflβ©
@[symm] protected def symm (e : Ξ± β Ξ²) : Ξ² β Ξ± := β¨e.inv_fun, e.to_fun, e.right_inv, e.left_invβ©
@[trans] protected def trans (eβ : Ξ± β Ξ²) (eβ : Ξ² β Ξ³) : Ξ± β Ξ³ :=
β¨eβ.to_fun β eβ.to_fun, eβ.inv_fun β eβ.inv_fun,
eβ.left_inv.comp eβ.left_inv, eβ.right_inv.comp eβ.right_invβ©
@[simp]
lemma to_fun_as_coe (e : Ξ± β Ξ²) (a : Ξ±) : e.to_fun a = e a := rfl
@[simp]
lemma inv_fun_as_coe (e : Ξ± β Ξ²) (b : Ξ²) : e.inv_fun b = e.symm b := rfl
protected theorem injective : β f : Ξ± β Ξ², injective f
| β¨f, g, hβ, hββ© := injective_of_left_inverse hβ
protected theorem surjective : β f : Ξ± β Ξ², surjective f
| β¨f, g, hβ, hββ© := surjective_of_has_right_inverse β¨_, hββ©
protected theorem bijective (f : Ξ± β Ξ²) : bijective f :=
β¨f.injective, f.surjectiveβ©
@[simp] lemma range_eq_univ {Ξ± : Type*} {Ξ² : Type*} (e : Ξ± β Ξ²) : set.range e = set.univ :=
set.eq_univ_of_forall e.surjective
protected theorem subsingleton (e : Ξ± β Ξ²) [subsingleton Ξ²] : subsingleton Ξ± :=
e.injective.comap_subsingleton
protected def decidable_eq (e : Ξ± β Ξ²) [H : decidable_eq Ξ²] : decidable_eq Ξ±
| a b := decidable_of_iff _ e.injective.eq_iff
lemma nonempty_iff_nonempty : Ξ± β Ξ² β (nonempty Ξ± β nonempty Ξ²)
| β¨f, g, _, _β© := nonempty.congr f g
protected def cast {Ξ± Ξ² : Sort*} (h : Ξ± = Ξ²) : Ξ± β Ξ² :=
β¨cast h, cast h.symm, Ξ» x, by { cases h, refl }, Ξ» x, by { cases h, refl }β©
@[simp] theorem coe_fn_symm_mk (f : Ξ± β Ξ²) (g l r) : ((equiv.mk f g l r).symm : Ξ² β Ξ±) = g :=
rfl
@[simp] theorem refl_apply (x : Ξ±) : equiv.refl Ξ± x = x := rfl
@[simp] theorem trans_apply (f : Ξ± β Ξ²) (g : Ξ² β Ξ³) (a : Ξ±) : (f.trans g) a = g (f a) := rfl
@[simp] theorem apply_symm_apply : β (e : Ξ± β Ξ²) (x : Ξ²), e (e.symm x) = x
| β¨fβ, gβ, lβ, rββ© x := by { simp [equiv.symm], rw rβ }
@[simp] theorem symm_apply_apply : β (e : Ξ± β Ξ²) (x : Ξ±), e.symm (e x) = x
| β¨fβ, gβ, lβ, rββ© x := by { simp [equiv.symm], rw lβ }
@[simp] lemma symm_trans_apply (f : Ξ± β Ξ²) (g : Ξ² β Ξ³) (a : Ξ³) :
(f.trans g).symm a = f.symm (g.symm a) := rfl
@[simp] theorem apply_eq_iff_eq : β (f : Ξ± β Ξ²) (x y : Ξ±), f x = f y β x = y
| β¨fβ, gβ, lβ, rββ© x y := (injective_of_left_inverse lβ).eq_iff
@[simp] theorem cast_apply {Ξ± Ξ²} (h : Ξ± = Ξ²) (x : Ξ±) : equiv.cast h x = cast h x := rfl
lemma symm_apply_eq {Ξ± Ξ²} (e : Ξ± β Ξ²) {x y} : e.symm x = y β x = e y :=
β¨Ξ» H, by simp [H.symm], Ξ» H, by simp [H]β©
lemma eq_symm_apply {Ξ± Ξ²} (e : Ξ± β Ξ²) {x y} : y = e.symm x β e y = x :=
(eq_comm.trans e.symm_apply_eq).trans eq_comm
@[simp] theorem symm_symm (e : Ξ± β Ξ²) : e.symm.symm = e := by { cases e, refl }
@[simp] theorem symm_symm_apply (e : Ξ± β Ξ²) (a : Ξ±) : e.symm.symm a = e a := by { cases e, refl }
@[simp] theorem trans_refl (e : Ξ± β Ξ²) : e.trans (equiv.refl Ξ²) = e := by { cases e, refl }
@[simp] theorem refl_symm : (equiv.refl Ξ±).symm = equiv.refl Ξ± := rfl
@[simp] theorem refl_trans (e : Ξ± β Ξ²) : (equiv.refl Ξ±).trans e = e := by { cases e, refl }
@[simp] theorem symm_trans (e : Ξ± β Ξ²) : e.symm.trans e = equiv.refl Ξ² := ext _ _ (by simp)
@[simp] theorem trans_symm (e : Ξ± β Ξ²) : e.trans e.symm = equiv.refl Ξ± := ext _ _ (by simp)
lemma trans_assoc {Ξ΄} (ab : Ξ± β Ξ²) (bc : Ξ² β Ξ³) (cd : Ξ³ β Ξ΄) :
(ab.trans bc).trans cd = ab.trans (bc.trans cd) :=
equiv.ext _ _ $ assume a, rfl
theorem left_inverse_symm (f : equiv Ξ± Ξ²) : left_inverse f.symm f := f.left_inv
theorem right_inverse_symm (f : equiv Ξ± Ξ²) : function.right_inverse f.symm f := f.right_inv
def equiv_congr {Ξ΄} (ab : Ξ± β Ξ²) (cd : Ξ³ β Ξ΄) : (Ξ± β Ξ³) β (Ξ² β Ξ΄) :=
β¨ Ξ»ac, (ab.symm.trans ac).trans cd, Ξ»bd, ab.trans $ bd.trans $ cd.symm,
assume ac, by { ext x, simp }, assume ac, by { ext x, simp } β©
def perm_congr {Ξ± : Type*} {Ξ² : Type*} (e : Ξ± β Ξ²) : perm Ξ± β perm Ξ² :=
equiv_congr e e
protected lemma image_eq_preimage {Ξ± Ξ²} (e : Ξ± β Ξ²) (s : set Ξ±) : e '' s = e.symm β»ΒΉ' s :=
set.ext $ assume x, set.mem_image_iff_of_inverse e.left_inv e.right_inv
protected lemma subset_image {Ξ± Ξ²} (e : Ξ± β Ξ²) (s : set Ξ±) (t : set Ξ²) : t β e '' s β e.symm '' t β s :=
by rw [set.image_subset_iff, e.image_eq_preimage]
lemma symm_image_image {Ξ± Ξ²} (f : equiv Ξ± Ξ²) (s : set Ξ±) : f.symm '' (f '' s) = s :=
by { rw [β set.image_comp], simp }
protected lemma image_compl {Ξ± Ξ²} (f : equiv Ξ± Ξ²) (s : set Ξ±) :
f '' -s = -(f '' s) :=
set.image_compl_eq f.bijective
/- The group of permutations (self-equivalences) of a type `Ξ±` -/
namespace perm
instance perm_group {Ξ± : Type u} : group (perm Ξ±) :=
begin
refine { mul := Ξ» f g, equiv.trans g f, one := equiv.refl Ξ±, inv:= equiv.symm, ..};
intros; apply equiv.ext; try { apply trans_apply },
apply symm_apply_apply
end
@[simp] theorem mul_apply {Ξ± : Type u} (f g : perm Ξ±) (x) : (f * g) x = f (g x) :=
equiv.trans_apply _ _ _
@[simp] theorem one_apply {Ξ± : Type u} (x) : (1 : perm Ξ±) x = x := rfl
@[simp] lemma inv_apply_self {Ξ± : Type u} (f : perm Ξ±) (x) :
fβ»ΒΉ (f x) = x := equiv.symm_apply_apply _ _
@[simp] lemma apply_inv_self {Ξ± : Type u} (f : perm Ξ±) (x) :
f (fβ»ΒΉ x) = x := equiv.apply_symm_apply _ _
lemma one_def {Ξ± : Type u} : (1 : perm Ξ±) = equiv.refl Ξ± := rfl
lemma mul_def {Ξ± : Type u} (f g : perm Ξ±) : f * g = g.trans f := rfl
lemma inv_def {Ξ± : Type u} (f : perm Ξ±) : fβ»ΒΉ = f.symm := rfl
end perm
def equiv_empty (h : Ξ± β false) : Ξ± β empty :=
β¨Ξ» x, (h x).elim, Ξ» e, e.rec _, Ξ» x, (h x).elim, Ξ» e, e.rec _β©
def false_equiv_empty : false β empty :=
equiv_empty _root_.id
def equiv_pempty (h : Ξ± β false) : Ξ± β pempty :=
β¨Ξ» x, (h x).elim, Ξ» e, e.rec _, Ξ» x, (h x).elim, Ξ» e, e.rec _β©
def false_equiv_pempty : false β pempty :=
equiv_pempty _root_.id
def empty_equiv_pempty : empty β pempty :=
equiv_pempty $ empty.rec _
def pempty_equiv_pempty : pempty.{v} β pempty.{w} :=
equiv_pempty pempty.elim
def empty_of_not_nonempty {Ξ± : Sort*} (h : Β¬ nonempty Ξ±) : Ξ± β empty :=
equiv_empty $ assume a, h β¨aβ©
def pempty_of_not_nonempty {Ξ± : Sort*} (h : Β¬ nonempty Ξ±) : Ξ± β pempty :=
equiv_pempty $ assume a, h β¨aβ©
def prop_equiv_punit {p : Prop} (h : p) : p β punit :=
β¨Ξ» x, (), Ξ» x, h, Ξ» _, rfl, Ξ» β¨β©, rflβ©
def true_equiv_punit : true β punit := prop_equiv_punit trivial
protected def ulift {Ξ± : Type u} : ulift Ξ± β Ξ± :=
β¨ulift.down, ulift.up, ulift.up_down, Ξ» a, rflβ©
protected def plift : plift Ξ± β Ξ± :=
β¨plift.down, plift.up, plift.up_down, plift.down_upβ©
@[congr] def arrow_congr {Ξ±β Ξ²β Ξ±β Ξ²β : Sort*} (eβ : Ξ±β β Ξ±β) (eβ : Ξ²β β Ξ²β) :
(Ξ±β β Ξ²β) β (Ξ±β β Ξ²β) :=
{ to_fun := Ξ» f, eβ.to_fun β f β eβ.inv_fun,
inv_fun := Ξ» f, eβ.inv_fun β f β eβ.to_fun,
left_inv := Ξ» f, funext $ Ξ» x, by { dsimp, simp },
right_inv := Ξ» f, funext $ Ξ» x, by { dsimp, simp } }
@[simp] lemma arrow_congr_apply {Ξ±β Ξ²β Ξ±β Ξ²β : Sort*} (eβ : Ξ±β β Ξ±β) (eβ : Ξ²β β Ξ²β)
(f : Ξ±β β Ξ²β) (x : Ξ±β) :
arrow_congr eβ eβ f x = (eβ $ f $ eβ.symm x) :=
rfl
lemma arrow_congr_comp {Ξ±β Ξ²β Ξ³β Ξ±β Ξ²β Ξ³β : Sort*}
(ea : Ξ±β β Ξ±β) (eb : Ξ²β β Ξ²β) (ec : Ξ³β β Ξ³β) (f : Ξ±β β Ξ²β) (g : Ξ²β β Ξ³β) :
arrow_congr ea ec (g β f) = (arrow_congr eb ec g) β (arrow_congr ea eb f) :=
by { ext, simp only [comp, arrow_congr_apply, eb.symm_apply_apply] }
@[simp] lemma arrow_congr_refl {Ξ± Ξ² : Sort*} :
arrow_congr (equiv.refl Ξ±) (equiv.refl Ξ²) = equiv.refl (Ξ± β Ξ²) := rfl
@[simp] lemma arrow_congr_trans {Ξ±β Ξ²β Ξ±β Ξ²β Ξ±β Ξ²β : Sort*}
(eβ : Ξ±β β Ξ±β) (eβ' : Ξ²β β Ξ²β) (eβ : Ξ±β β Ξ±β) (eβ' : Ξ²β β Ξ²β) :
arrow_congr (eβ.trans eβ) (eβ'.trans eβ') = (arrow_congr eβ eβ').trans (arrow_congr eβ eβ') :=
rfl
@[simp] lemma arrow_congr_symm {Ξ±β Ξ²β Ξ±β Ξ²β : Sort*} (eβ : Ξ±β β Ξ±β) (eβ : Ξ²β β Ξ²β) :
(arrow_congr eβ eβ).symm = arrow_congr eβ.symm eβ.symm :=
rfl
def conj (e : Ξ± β Ξ²) : (Ξ± β Ξ±) β (Ξ² β Ξ²) := arrow_congr e e
@[simp] lemma conj_apply (e : Ξ± β Ξ²) (f : Ξ± β Ξ±) (x : Ξ²) :
e.conj f x = (e $ f $ e.symm x) :=
rfl
@[simp] lemma conj_refl : conj (equiv.refl Ξ±) = equiv.refl (Ξ± β Ξ±) := rfl
@[simp] lemma conj_symm (e : Ξ± β Ξ²) : e.conj.symm = e.symm.conj := rfl
@[simp] lemma conj_trans (eβ : Ξ± β Ξ²) (eβ : Ξ² β Ξ³) :
(eβ.trans eβ).conj = eβ.conj.trans eβ.conj :=
rfl
-- This should not be a simp lemma as long as `(β)` is reducible:
-- when `(β)` is reducible, Lean can unify `fβ β fβ` with any `g` using
-- `fβ := g` and `fβ := Ξ» x, x`. This causes nontermination.
lemma conj_comp (e : Ξ± β Ξ²) (fβ fβ : Ξ± β Ξ±) :
e.conj (fβ β fβ) = (e.conj fβ) β (e.conj fβ) :=
by apply arrow_congr_comp
def punit_equiv_punit : punit.{v} β punit.{w} :=
β¨Ξ» _, punit.star, Ξ» _, punit.star, Ξ» u, by { cases u, refl }, Ξ» u, by { cases u, reflexivity }β©
section
@[simp] def arrow_punit_equiv_punit (Ξ± : Sort*) : (Ξ± β punit.{v}) β punit.{w} :=
β¨Ξ» f, punit.star, Ξ» u f, punit.star,
Ξ» f, by { funext x, cases f x, refl }, Ξ» u, by { cases u, reflexivity }β©
@[simp] def punit_arrow_equiv (Ξ± : Sort*) : (punit.{u} β Ξ±) β Ξ± :=
β¨Ξ» f, f punit.star, Ξ» a u, a, Ξ» f, by { funext x, cases x, refl }, Ξ» u, rflβ©
@[simp] def empty_arrow_equiv_punit (Ξ± : Sort*) : (empty β Ξ±) β punit.{u} :=
β¨Ξ» f, punit.star, Ξ» u e, e.rec _, Ξ» f, funext $ Ξ» x, x.rec _, Ξ» u, by { cases u, refl }β©
@[simp] def pempty_arrow_equiv_punit (Ξ± : Sort*) : (pempty β Ξ±) β punit.{u} :=
β¨Ξ» f, punit.star, Ξ» u e, e.rec _, Ξ» f, funext $ Ξ» x, x.rec _, Ξ» u, by { cases u, refl }β©
@[simp] def false_arrow_equiv_punit (Ξ± : Sort*) : (false β Ξ±) β punit.{u} :=
calc (false β Ξ±) β (empty β Ξ±) : arrow_congr false_equiv_empty (equiv.refl _)
... β punit : empty_arrow_equiv_punit _
end
@[congr] def prod_congr {Ξ±β Ξ²β Ξ±β Ξ²β : Sort*} (eβ : Ξ±β β Ξ±β) (eβ :Ξ²β β Ξ²β) : Ξ±β Γ Ξ²β β Ξ±β Γ Ξ²β :=
β¨Ξ»p, (eβ p.1, eβ p.2), Ξ»p, (eβ.symm p.1, eβ.symm p.2),
Ξ» β¨a, bβ©, show (eβ.symm (eβ a), eβ.symm (eβ b)) = (a, b), by rw [symm_apply_apply, symm_apply_apply],
Ξ» β¨a, bβ©, show (eβ (eβ.symm a), eβ (eβ.symm b)) = (a, b), by rw [apply_symm_apply, apply_symm_apply]β©
@[simp] theorem prod_congr_apply {Ξ±β Ξ²β Ξ±β Ξ²β : Sort*} (eβ : Ξ±β β Ξ±β) (eβ : Ξ²β β Ξ²β) (a : Ξ±β) (b : Ξ²β) :
prod_congr eβ eβ (a, b) = (eβ a, eβ b) :=
rfl
@[simp] def prod_comm (Ξ± Ξ² : Sort*) : Ξ± Γ Ξ² β Ξ² Γ Ξ± :=
β¨Ξ» p, (p.2, p.1), Ξ» p, (p.2, p.1), Ξ»β¨a, bβ©, rfl, Ξ»β¨a, bβ©, rflβ©
@[simp] def prod_assoc (Ξ± Ξ² Ξ³ : Sort*) : (Ξ± Γ Ξ²) Γ Ξ³ β Ξ± Γ (Ξ² Γ Ξ³) :=
β¨Ξ» p, β¨p.1.1, β¨p.1.2, p.2β©β©, Ξ»p, β¨β¨p.1, p.2.1β©, p.2.2β©, Ξ» β¨β¨a, bβ©, cβ©, rfl, Ξ» β¨a, β¨b, cβ©β©, rflβ©
@[simp] theorem prod_assoc_apply {Ξ± Ξ² Ξ³ : Sort*} (p : (Ξ± Γ Ξ²) Γ Ξ³) :
prod_assoc Ξ± Ξ² Ξ³ p = β¨p.1.1, β¨p.1.2, p.2β©β© := rfl
section
@[simp] def prod_punit (Ξ± : Sort*) : Ξ± Γ punit.{u+1} β Ξ± :=
β¨Ξ» p, p.1, Ξ» a, (a, punit.star), Ξ» β¨_, punit.starβ©, rfl, Ξ» a, rflβ©
@[simp] theorem prod_punit_apply {Ξ± : Sort*} (a : Ξ± Γ punit.{u+1}) : prod_punit Ξ± a = a.1 := rfl
@[simp] def punit_prod (Ξ± : Sort*) : punit.{u+1} Γ Ξ± β Ξ± :=
calc punit Γ Ξ± β Ξ± Γ punit : prod_comm _ _
... β Ξ± : prod_punit _
@[simp] theorem punit_prod_apply {Ξ± : Sort*} (a : punit.{u+1} Γ Ξ±) : punit_prod Ξ± a = a.2 := rfl
@[simp] def prod_empty (Ξ± : Sort*) : Ξ± Γ empty β empty :=
equiv_empty (Ξ» β¨_, eβ©, e.rec _)
@[simp] def empty_prod (Ξ± : Sort*) : empty Γ Ξ± β empty :=
equiv_empty (Ξ» β¨e, _β©, e.rec _)
@[simp] def prod_pempty (Ξ± : Sort*) : Ξ± Γ pempty β pempty :=
equiv_pempty (Ξ» β¨_, eβ©, e.rec _)
@[simp] def pempty_prod (Ξ± : Sort*) : pempty Γ Ξ± β pempty :=
equiv_pempty (Ξ» β¨e, _β©, e.rec _)
end
section
open sum
def psum_equiv_sum (Ξ± Ξ² : Sort*) : psum Ξ± Ξ² β Ξ± β Ξ² :=
β¨Ξ» s, psum.cases_on s inl inr,
Ξ» s, sum.cases_on s psum.inl psum.inr,
Ξ» s, by cases s; refl,
Ξ» s, by cases s; reflβ©
def sum_congr {Ξ±β Ξ²β Ξ±β Ξ²β : Sort*} : Ξ±β β Ξ±β β Ξ²β β Ξ²β β Ξ±β β Ξ²β β Ξ±β β Ξ²β
| β¨fβ, gβ, lβ, rββ© β¨fβ, gβ, lβ, rββ© :=
β¨Ξ» s, match s with inl aβ := inl (fβ aβ) | inr bβ := inr (fβ bβ) end,
Ξ» s, match s with inl aβ := inl (gβ aβ) | inr bβ := inr (gβ bβ) end,
Ξ» s, match s with inl a := congr_arg inl (lβ a) | inr a := congr_arg inr (lβ a) end,
Ξ» s, match s with inl a := congr_arg inl (rβ a) | inr a := congr_arg inr (rβ a) endβ©
@[simp] theorem sum_congr_apply_inl {Ξ±β Ξ²β Ξ±β Ξ²β : Sort*} (eβ : Ξ±β β Ξ±β) (eβ : Ξ²β β Ξ²β) (a : Ξ±β) :
sum_congr eβ eβ (inl a) = inl (eβ a) :=
by { cases eβ, cases eβ, refl }
@[simp] theorem sum_congr_apply_inr {Ξ±β Ξ²β Ξ±β Ξ²β : Sort*} (eβ : Ξ±β β Ξ±β) (eβ : Ξ²β β Ξ²β) (b : Ξ²β) :
sum_congr eβ eβ (inr b) = inr (eβ b) :=
by { cases eβ, cases eβ, refl }
@[simp] lemma sum_congr_symm {Ξ± Ξ² Ξ³ Ξ΄ : Type u} (e : Ξ± β Ξ²) (f : Ξ³ β Ξ΄) (x) :
(equiv.sum_congr e f).symm x = (equiv.sum_congr (e.symm) (f.symm)) x :=
by { cases e, cases f, cases x; refl }
def bool_equiv_punit_sum_punit : bool β punit.{u+1} β punit.{v+1} :=
β¨Ξ» b, cond b (inr punit.star) (inl punit.star),
Ξ» s, sum.rec_on s (Ξ»_, ff) (Ξ»_, tt),
Ξ» b, by cases b; refl,
Ξ» s, by rcases s with β¨β¨β©β© | β¨β¨β©β©; reflβ©
noncomputable def Prop_equiv_bool : Prop β bool :=
β¨Ξ» p, @to_bool p (classical.prop_decidable _),
Ξ» b, b, Ξ» p, by simp, Ξ» b, by simpβ©
@[simp] def sum_comm (Ξ± Ξ² : Sort*) : Ξ± β Ξ² β Ξ² β Ξ± :=
β¨Ξ» s, match s with inl a := inr a | inr b := inl b end,
Ξ» s, match s with inl b := inr b | inr a := inl a end,
Ξ» s, by cases s; refl,
Ξ» s, by cases s; reflβ©
@[simp] def sum_assoc (Ξ± Ξ² Ξ³ : Sort*) : (Ξ± β Ξ²) β Ξ³ β Ξ± β (Ξ² β Ξ³) :=
β¨Ξ» s, match s with inl (inl a) := inl a | inl (inr b) := inr (inl b) | inr c := inr (inr c) end,
Ξ» s, match s with inl a := inl (inl a) | inr (inl b) := inl (inr b) | inr (inr c) := inr c end,
Ξ» s, by rcases s with β¨_ | _β© | _; refl,
Ξ» s, by rcases s with _ | _ | _; reflβ©
@[simp] theorem sum_assoc_apply_in1 {Ξ± Ξ² Ξ³} (a) : sum_assoc Ξ± Ξ² Ξ³ (inl (inl a)) = inl a := rfl
@[simp] theorem sum_assoc_apply_in2 {Ξ± Ξ² Ξ³} (b) : sum_assoc Ξ± Ξ² Ξ³ (inl (inr b)) = inr (inl b) := rfl
@[simp] theorem sum_assoc_apply_in3 {Ξ± Ξ² Ξ³} (c) : sum_assoc Ξ± Ξ² Ξ³ (inr c) = inr (inr c) := rfl
@[simp] def sum_empty (Ξ± : Sort*) : Ξ± β empty β Ξ± :=
β¨Ξ» s, match s with inl a := a | inr e := empty.rec _ e end,
inl,
Ξ» s, by { rcases s with _ | β¨β¨β©β©, refl },
Ξ» a, rflβ©
@[simp] def empty_sum (Ξ± : Sort*) : empty β Ξ± β Ξ± :=
(sum_comm _ _).trans $ sum_empty _
@[simp] def sum_pempty (Ξ± : Sort*) : Ξ± β pempty β Ξ± :=
β¨Ξ» s, match s with inl a := a | inr e := pempty.rec _ e end,
inl,
Ξ» s, by { rcases s with _ | β¨β¨β©β©, refl },
Ξ» a, rflβ©
@[simp] def pempty_sum (Ξ± : Sort*) : pempty β Ξ± β Ξ± :=
(sum_comm _ _).trans $ sum_pempty _
@[simp] def option_equiv_sum_punit (Ξ± : Sort*) : option Ξ± β Ξ± β punit.{u+1} :=
β¨Ξ» o, match o with none := inr punit.star | some a := inl a end,
Ξ» s, match s with inr _ := none | inl a := some a end,
Ξ» o, by cases o; refl,
Ξ» s, by rcases s with _ | β¨β¨β©β©; reflβ©
def sum_equiv_sigma_bool (Ξ± Ξ² : Sort*) : Ξ± β Ξ² β (Ξ£ b: bool, cond b Ξ± Ξ²) :=
β¨Ξ» s, match s with inl a := β¨tt, aβ© | inr b := β¨ff, bβ© end,
Ξ» s, match s with β¨tt, aβ© := inl a | β¨ff, bβ© := inr b end,
Ξ» s, by cases s; refl,
Ξ» s, by rcases s with β¨_|_, _β©; reflβ©
def sigma_preimage_equiv {Ξ± Ξ² : Type*} (f : Ξ± β Ξ²) :
(Ξ£ y : Ξ², {x // f x = y}) β Ξ± :=
β¨Ξ» x, x.2.1, Ξ» x, β¨f x, x, rflβ©, Ξ» β¨y, x, rflβ©, rfl, Ξ» x, rflβ©
end
section
def Pi_congr_right {Ξ±} {Ξ²β Ξ²β : Ξ± β Sort*} (F : β a, Ξ²β a β Ξ²β a) : (Ξ a, Ξ²β a) β (Ξ a, Ξ²β a) :=
β¨Ξ» H a, F a (H a), Ξ» H a, (F a).symm (H a),
Ξ» H, funext $ by simp, Ξ» H, funext $ by simpβ©
def Pi_curry {Ξ±} {Ξ² : Ξ± β Sort*} (Ξ³ : Ξ a, Ξ² a β Sort*) : (Ξ x : sigma Ξ², Ξ³ x.1 x.2) β (Ξ a b, Ξ³ a b) :=
{ to_fun := Ξ» f x y, f β¨x,yβ©,
inv_fun := Ξ» f x, f x.1 x.2,
left_inv := Ξ» f, funext $ Ξ» β¨x,yβ©, rfl,
right_inv := Ξ» f, funext $ Ξ» x, funext $ Ξ» y, rfl }
end
section
def psigma_equiv_sigma {Ξ±} (Ξ² : Ξ± β Sort*) : psigma Ξ² β sigma Ξ² :=
β¨Ξ» β¨a, bβ©, β¨a, bβ©, Ξ» β¨a, bβ©, β¨a, bβ©, Ξ» β¨a, bβ©, rfl, Ξ» β¨a, bβ©, rflβ©
def sigma_congr_right {Ξ±} {Ξ²β Ξ²β : Ξ± β Sort*} (F : β a, Ξ²β a β Ξ²β a) : sigma Ξ²β β sigma Ξ²β :=
β¨Ξ» β¨a, bβ©, β¨a, F a bβ©, Ξ» β¨a, bβ©, β¨a, (F a).symm bβ©,
Ξ» β¨a, bβ©, congr_arg (sigma.mk a) $ symm_apply_apply (F a) b,
Ξ» β¨a, bβ©, congr_arg (sigma.mk a) $ apply_symm_apply (F a) bβ©
def sigma_congr_left {Ξ±β Ξ±β} {Ξ² : Ξ±β β Sort*} : β f : Ξ±β β Ξ±β, (Ξ£ a:Ξ±β, Ξ² (f a)) β (Ξ£ a:Ξ±β, Ξ² a)
| β¨f, g, l, rβ© :=
β¨Ξ» β¨a, bβ©, β¨f a, bβ©, Ξ» β¨a, bβ©, β¨g a, @@eq.rec Ξ² b (r a).symmβ©,
Ξ» β¨a, bβ©, match g (f a), l a : β a' (h : a' = a),
@sigma.mk _ (Ξ² β f) _ (@@eq.rec Ξ² b (congr_arg f h.symm)) = β¨a, bβ© with
| _, rfl := rfl end,
Ξ» β¨a, bβ©, match f (g a), _ : β a' (h : a' = a), sigma.mk a' (@@eq.rec Ξ² b h.symm) = β¨a, bβ© with
| _, rfl := rfl endβ©
/-- transporting a sigma type through an equivalence of the base -/
def sigma_congr_left' {Ξ±β Ξ±β} {Ξ² : Ξ±β β Sort*} : β f : Ξ±β β Ξ±β, (Ξ£ a:Ξ±β, Ξ² a) β (Ξ£ a:Ξ±β, Ξ² (f.symm a)) :=
Ξ» f, (sigma_congr_left f.symm).symm
/-- transporting a sigma type through an equivalence of the base and a family of equivalences of matching fibres -/
def sigma_congr {Ξ±β Ξ±β} {Ξ²β : Ξ±β β Sort*} {Ξ²β : Ξ±β β Sort*} (f : Ξ±β β Ξ±β) (F : β a, Ξ²β a β Ξ²β (f a)) :
sigma Ξ²β β sigma Ξ²β :=
(sigma_congr_right F).trans (sigma_congr_left f)
def sigma_equiv_prod (Ξ± Ξ² : Sort*) : (Ξ£_:Ξ±, Ξ²) β Ξ± Γ Ξ² :=
β¨Ξ» β¨a, bβ©, β¨a, bβ©, Ξ» β¨a, bβ©, β¨a, bβ©, Ξ» β¨a, bβ©, rfl, Ξ» β¨a, bβ©, rflβ©
def sigma_equiv_prod_of_equiv {Ξ± Ξ²} {Ξ²β : Ξ± β Sort*} (F : β a, Ξ²β a β Ξ²) : sigma Ξ²β β Ξ± Γ Ξ² :=
(sigma_congr_right F).trans (sigma_equiv_prod Ξ± Ξ²)
end
section
def arrow_prod_equiv_prod_arrow (Ξ± Ξ² Ξ³ : Type*) : (Ξ³ β Ξ± Γ Ξ²) β (Ξ³ β Ξ±) Γ (Ξ³ β Ξ²) :=
β¨Ξ» f, (Ξ» c, (f c).1, Ξ» c, (f c).2),
Ξ» p c, (p.1 c, p.2 c),
Ξ» f, funext $ Ξ» c, prod.mk.eta,
Ξ» p, by { cases p, refl }β©
def arrow_arrow_equiv_prod_arrow (Ξ± Ξ² Ξ³ : Sort*) : (Ξ± β Ξ² β Ξ³) β (Ξ± Γ Ξ² β Ξ³) :=
β¨Ξ» f, Ξ» p, f p.1 p.2,
Ξ» f, Ξ» a b, f (a, b),
Ξ» f, rfl,
Ξ» f, by { funext p, cases p, refl }β©
open sum
def sum_arrow_equiv_prod_arrow (Ξ± Ξ² Ξ³ : Type*) : ((Ξ± β Ξ²) β Ξ³) β (Ξ± β Ξ³) Γ (Ξ² β Ξ³) :=
β¨Ξ» f, (f β inl, f β inr),
Ξ» p s, sum.rec_on s p.1 p.2,
Ξ» f, by { funext s, cases s; refl },
Ξ» p, by { cases p, refl }β©
def sum_prod_distrib (Ξ± Ξ² Ξ³ : Sort*) : (Ξ± β Ξ²) Γ Ξ³ β (Ξ± Γ Ξ³) β (Ξ² Γ Ξ³) :=
β¨Ξ» p, match p with (inl a, c) := inl (a, c) | (inr b, c) := inr (b, c) end,
Ξ» s, match s with inl (a, c) := (inl a, c) | inr (b, c) := (inr b, c) end,
Ξ» p, by rcases p with β¨_ | _, _β©; refl,
Ξ» s, by rcases s with β¨_, _β© | β¨_, _β©; reflβ©
@[simp] theorem sum_prod_distrib_apply_left {Ξ± Ξ² Ξ³} (a : Ξ±) (c : Ξ³) :
sum_prod_distrib Ξ± Ξ² Ξ³ (sum.inl a, c) = sum.inl (a, c) := rfl
@[simp] theorem sum_prod_distrib_apply_right {Ξ± Ξ² Ξ³} (b : Ξ²) (c : Ξ³) :
sum_prod_distrib Ξ± Ξ² Ξ³ (sum.inr b, c) = sum.inr (b, c) := rfl
def prod_sum_distrib (Ξ± Ξ² Ξ³ : Sort*) : Ξ± Γ (Ξ² β Ξ³) β (Ξ± Γ Ξ²) β (Ξ± Γ Ξ³) :=
calc Ξ± Γ (Ξ² β Ξ³) β (Ξ² β Ξ³) Γ Ξ± : prod_comm _ _
... β (Ξ² Γ Ξ±) β (Ξ³ Γ Ξ±) : sum_prod_distrib _ _ _
... β (Ξ± Γ Ξ²) β (Ξ± Γ Ξ³) : sum_congr (prod_comm _ _) (prod_comm _ _)
@[simp] theorem prod_sum_distrib_apply_left {Ξ± Ξ² Ξ³} (a : Ξ±) (b : Ξ²) :
prod_sum_distrib Ξ± Ξ² Ξ³ (a, sum.inl b) = sum.inl (a, b) := rfl
@[simp] theorem prod_sum_distrib_apply_right {Ξ± Ξ² Ξ³} (a : Ξ±) (c : Ξ³) :
prod_sum_distrib Ξ± Ξ² Ξ³ (a, sum.inr c) = sum.inr (a, c) := rfl
def sigma_prod_distrib {ΞΉ : Type*} (Ξ± : ΞΉ β Type*) (Ξ² : Type*) :
((Ξ£ i, Ξ± i) Γ Ξ²) β (Ξ£ i, (Ξ± i Γ Ξ²)) :=
β¨Ξ» p, β¨p.1.1, (p.1.2, p.2)β©,
Ξ» p, (β¨p.1, p.2.1β©, p.2.2),
Ξ» p, by { rcases p with β¨β¨_, _β©, _β©, refl },
Ξ» p, by { rcases p with β¨_, β¨_, _β©β©, refl }β©
def bool_prod_equiv_sum (Ξ± : Type u) : bool Γ Ξ± β Ξ± β Ξ± :=
calc bool Γ Ξ± β (unit β unit) Γ Ξ± : prod_congr bool_equiv_punit_sum_punit (equiv.refl _)
... β Ξ± Γ (unit β unit) : prod_comm _ _
... β (Ξ± Γ unit) β (Ξ± Γ unit) : prod_sum_distrib _ _ _
... β Ξ± β Ξ± : sum_congr (prod_punit _) (prod_punit _)
end
section
open sum nat
def nat_equiv_nat_sum_punit : β β β β punit.{u+1} :=
β¨Ξ» n, match n with zero := inr punit.star | succ a := inl a end,
Ξ» s, match s with inl n := succ n | inr punit.star := zero end,
Ξ» n, begin cases n, repeat { refl } end,
Ξ» s, begin cases s with a u, { refl }, {cases u, { refl }} endβ©
@[simp] def nat_sum_punit_equiv_nat : β β punit.{u+1} β β :=
nat_equiv_nat_sum_punit.symm
def int_equiv_nat_sum_nat : β€ β β β β :=
by refine β¨_, _, _, _β©; intro z; {cases z; [left, right]; assumption} <|> {cases z; refl}
end
def list_equiv_of_equiv {Ξ± Ξ² : Type*} : Ξ± β Ξ² β list Ξ± β list Ξ²
| β¨f, g, l, rβ© :=
by refine β¨list.map f, list.map g, Ξ» x, _, Ξ» x, _β©;
simp [id_of_left_inverse l, id_of_right_inverse r]
def fin_equiv_subtype (n : β) : fin n β {m // m < n} :=
β¨Ξ» x, β¨x.1, x.2β©, Ξ» x, β¨x.1, x.2β©, Ξ» β¨a, bβ©, rfl,Ξ» β¨a, bβ©, rflβ©
def decidable_eq_of_equiv [decidable_eq Ξ²] (e : Ξ± β Ξ²) : decidable_eq Ξ±
| aβ aβ := decidable_of_iff (e aβ = e aβ) e.injective.eq_iff
def inhabited_of_equiv [inhabited Ξ²] (e : Ξ± β Ξ²) : inhabited Ξ± :=
β¨e.symm (default _)β©
def unique_of_equiv (e : Ξ± β Ξ²) (h : unique Ξ²) : unique Ξ± :=
e.symm.surjective.unique
def unique_congr (e : Ξ± β Ξ²) : unique Ξ± β unique Ξ² :=
{ to_fun := e.symm.unique_of_equiv,
inv_fun := e.unique_of_equiv,
left_inv := Ξ» _, subsingleton.elim _ _,
right_inv := Ξ» _, subsingleton.elim _ _ }
section
open subtype
def subtype_congr {p : Ξ± β Prop} {q : Ξ² β Prop}
(e : Ξ± β Ξ²) (h : β a, p a β q (e a)) : {a : Ξ± // p a} β {b : Ξ² // q b} :=
β¨Ξ» x, β¨e x.1, (h _).1 x.2β©,
Ξ» y, β¨e.symm y.1, (h _).2 (by { simp, exact y.2 })β©,
Ξ» β¨x, hβ©, subtype.eq' $ by simp,
Ξ» β¨y, hβ©, subtype.eq' $ by simpβ©
def subtype_congr_right {p q : Ξ± β Prop} (e : βx, p x β q x) : subtype p β subtype q :=
subtype_congr (equiv.refl _) e
@[simp] lemma subtype_congr_right_mk {p q : Ξ± β Prop} (e : βx, p x β q x)
{x : Ξ±} (h : p x) : subtype_congr_right e β¨x, hβ© = β¨x, (e x).1 hβ© := rfl
def subtype_equiv_of_subtype' {p : Ξ± β Prop} (e : Ξ± β Ξ²) :
{a : Ξ± // p a} β {b : Ξ² // p (e.symm b)} :=
subtype_congr e $ by simp
def subtype_congr_prop {Ξ± : Type*} {p q : Ξ± β Prop} (h : p = q) : subtype p β subtype q :=
subtype_congr (equiv.refl Ξ±) (assume a, h βΈ iff.rfl)
def set_congr {Ξ± : Type*} {s t : set Ξ±} (h : s = t) : s β t :=
subtype_congr_prop h
def subtype_subtype_equiv_subtype_exists {Ξ± : Type u} (p : Ξ± β Prop) (q : subtype p β Prop) :
subtype q β {a : Ξ± // βh:p a, q β¨a, hβ© } :=
β¨Ξ»β¨β¨a, haβ©, ha'β©, β¨a, ha, ha'β©,
Ξ»β¨a, haβ©, β¨β¨a, ha.cases_on $ assume h _, hβ©, by { cases ha, exact ha_h }β©,
assume β¨β¨a, haβ©, hβ©, rfl, assume β¨a, hβ, hββ©, rflβ©
def subtype_subtype_equiv_subtype_inter {Ξ± : Type u} (p q : Ξ± β Prop) :
{x : subtype p // q x.1} β subtype (Ξ» x, p x β§ q x) :=
(subtype_subtype_equiv_subtype_exists p _).trans $
subtype_congr_right $ Ξ» x, exists_prop
/-- If the outer subtype has more restrictive predicate than the inner one,
then we can drop the latter. -/
def subtype_subtype_equiv_subtype {Ξ± : Type u} {p q : Ξ± β Prop} (h : β {x}, q x β p x) :
{x : subtype p // q x.1} β subtype q :=
(subtype_subtype_equiv_subtype_inter p _).trans $
subtype_congr_right $
assume x,
β¨and.right, Ξ» hβ, β¨h hβ, hββ©β©
/-- If a proposition holds for all elements, then the subtype is
equivalent to the original type. -/
def subtype_univ_equiv {Ξ± : Type u} {p : Ξ± β Prop} (h : β x, p x) :
subtype p β Ξ± :=
β¨Ξ» x, x, Ξ» x, β¨x, h xβ©, Ξ» x, subtype.eq rfl, Ξ» x, rflβ©
/-- A subtype of a sigma-type is a sigma-type over a subtype. -/
def subtype_sigma_equiv {Ξ± : Type u} (p : Ξ± β Type v) (q : Ξ± β Prop) :
{ y : sigma p // q y.1 } β Ξ£(x : subtype q), p x.1 :=
β¨Ξ» x, β¨β¨x.1.1, x.2β©, x.1.2β©,
Ξ» x, β¨β¨x.1.1, x.2β©, x.1.2β©,
Ξ» β¨β¨x, hβ©, yβ©, rfl,
Ξ» β¨β¨x, yβ©, hβ©, rflβ©
/-- A sigma type over a subtype is equivalent to the sigma set over the original type,
if the fiber is empty outside of the subset -/
def sigma_subtype_equiv_of_subset {Ξ± : Type u} (p : Ξ± β Type v) (q : Ξ± β Prop)
(h : β x, p x β q x) :
(Ξ£ x : subtype q, p x) β Ξ£ x : Ξ±, p x :=
(subtype_sigma_equiv p q).symm.trans $ subtype_univ_equiv $ Ξ» x, h x.1 x.2
def sigma_subtype_preimage_equiv {Ξ± : Type u} {Ξ² : Type v} (f : Ξ± β Ξ²) (p : Ξ² β Prop)
(h : β x, p (f x)) :
(Ξ£ y : subtype p, {x : Ξ± // f x = y}) β Ξ± :=
calc _ β Ξ£ y : Ξ², {x : Ξ± // f x = y} : sigma_subtype_equiv_of_subset _ p (Ξ» y β¨x, h'β©, h' βΈ h x)
... β Ξ± : sigma_preimage_equiv f
def sigma_subtype_preimage_equiv_subtype {Ξ± : Type u} {Ξ² : Type v} (f : Ξ± β Ξ²)
{p : Ξ± β Prop} {q : Ξ² β Prop} (h : β x, p x β q (f x)) :
(Ξ£ y : subtype q, {x : Ξ± // f x = y}) β subtype p :=
calc (Ξ£ y : subtype q, {x : Ξ± // f x = y}) β
Ξ£ y : subtype q, {x : subtype p // subtype.mk (f x) ((h x).1 x.2) = y} :
begin
apply sigma_congr_right,
assume y,
symmetry,
refine (subtype_subtype_equiv_subtype_exists _ _).trans (subtype_congr_right _),
assume x,
exact β¨Ξ» β¨hp, h'β©, congr_arg subtype.val h', Ξ» h', β¨(h x).2 (h'.symm βΈ y.2), subtype.eq h'β©β©
end
... β subtype p : sigma_preimage_equiv (Ξ» x : subtype p, (β¨f x, (h x).1 x.propertyβ© : subtype q))
def pi_equiv_subtype_sigma (ΞΉ : Type*) (Ο : ΞΉ β Type*) :
(Ξ i, Ο i) β {f : ΞΉ β Ξ£i, Ο i | βi, (f i).1 = i } :=
β¨ Ξ»f, β¨Ξ»i, β¨i, f iβ©, assume i, rflβ©, Ξ»f i, begin rw β f.2 i, exact (f.1 i).2 end,
assume f, funext $ assume i, rfl,
assume β¨f, hfβ©, subtype.eq $ funext $ assume i, sigma.eq (hf i).symm $
eq_of_heq $ rec_heq_of_heq _ $ rec_heq_of_heq _ $ heq.refl _β©
def subtype_pi_equiv_pi {Ξ± : Sort u} {Ξ² : Ξ± β Sort v} {p : Ξ a, Ξ² a β Prop} :
{f : Ξ a, Ξ² a // βa, p a (f a) } β Ξ a, { b : Ξ² a // p a b } :=
β¨Ξ»f a, β¨f.1 a, f.2 aβ©, Ξ»f, β¨Ξ»a, (f a).1, Ξ»a, (f a).2β©,
by { rintro β¨f, hβ©, refl },
by { rintro f, funext a, exact subtype.eq' rfl }β©
end
namespace set
open set
protected def univ (Ξ±) : @univ Ξ± β Ξ± :=
β¨subtype.val, Ξ» a, β¨a, trivialβ©, Ξ» β¨a, _β©, rfl, Ξ» a, rflβ©
@[simp] lemma univ_apply {Ξ± : Type u} (x : @univ Ξ±) :
equiv.set.univ Ξ± x = x := rfl
@[simp] lemma univ_symm_apply {Ξ± : Type u} (x : Ξ±) :
(equiv.set.univ Ξ±).symm x = β¨x, trivialβ© := rfl
protected def empty (Ξ±) : (β
: set Ξ±) β empty :=
equiv_empty $ Ξ» β¨x, hβ©, not_mem_empty x h
protected def pempty (Ξ±) : (β
: set Ξ±) β pempty :=
equiv_pempty $ Ξ» β¨x, hβ©, not_mem_empty x h
protected def union' {Ξ±} {s t : set Ξ±}
(p : Ξ± β Prop) [decidable_pred p]
(hs : β x β s, p x)
(ht : β x β t, Β¬ p x) : (s βͺ t : set Ξ±) β s β t :=
{ to_fun := Ξ» x, if hp : p x.1
then sum.inl β¨_, x.2.resolve_right (Ξ» xt, ht _ xt hp)β©
else sum.inr β¨_, x.2.resolve_left (Ξ» xs, hp (hs _ xs))β©,
inv_fun := Ξ» o, match o with
| (sum.inl x) := β¨x.1, or.inl x.2β©
| (sum.inr x) := β¨x.1, or.inr x.2β©
end,
left_inv := Ξ» β¨x, h'β©, by by_cases p x; simp [union'._match_1, h]; congr,
right_inv := Ξ» o, begin
rcases o with β¨x, hβ© | β¨x, hβ©;
dsimp [union'._match_1];
[simp [hs _ h], simp [ht _ h]]
end }
protected def union {Ξ±} {s t : set Ξ±} [decidable_pred s] (H : s β© t = β
) :
(s βͺ t : set Ξ±) β s β t :=
set.union' s (Ξ» _, id) (Ξ» x xt xs, subset_empty_iff.2 H β¨xs, xtβ©)
lemma union_apply_left {Ξ±} {s t : set Ξ±} [decidable_pred s] (H : s β© t = β
)
{a : (s βͺ t : set Ξ±)} (ha : βa β s) : equiv.set.union H a = sum.inl β¨a, haβ© :=
dif_pos ha
lemma union_apply_right {Ξ±} {s t : set Ξ±} [decidable_pred s] (H : s β© t = β
)
{a : (s βͺ t : set Ξ±)} (ha : βa β t) : equiv.set.union H a = sum.inr β¨a, haβ© :=
dif_neg (show βa β s, by finish [set.ext_iff])
protected def singleton {Ξ±} (a : Ξ±) : ({a} : set Ξ±) β punit.{u} :=
β¨Ξ» _, punit.star, Ξ» _, β¨a, mem_singleton _β©,
Ξ» β¨x, hβ©, by { simp at h, subst x },
Ξ» β¨β©, rflβ©
protected def of_eq {Ξ± : Type u} {s t : set Ξ±} (h : s = t) : s β t :=
{ to_fun := Ξ» x, β¨x.1, h βΈ x.2β©,
inv_fun := Ξ» x, β¨x.1, h.symm βΈ x.2β©,
left_inv := Ξ» _, subtype.eq rfl,
right_inv := Ξ» _, subtype.eq rfl }
@[simp] lemma of_eq_apply {Ξ± : Type u} {s t : set Ξ±} (h : s = t) (a : s) :
equiv.set.of_eq h a = β¨a, h βΈ a.2β© := rfl
@[simp] lemma of_eq_symm_apply {Ξ± : Type u} {s t : set Ξ±} (h : s = t) (a : t) :
(equiv.set.of_eq h).symm a = β¨a, h.symm βΈ a.2β© := rfl
protected def insert {Ξ±} {s : set.{u} Ξ±} [decidable_pred s] {a : Ξ±} (H : a β s) :
(insert a s : set Ξ±) β s β punit.{u+1} :=
calc (insert a s : set Ξ±) β β₯(s βͺ {a}) : equiv.set.of_eq (by simp)
... β s β ({a} : set Ξ±) : equiv.set.union (by finish [set.ext_iff])
... β s β punit.{u+1} : sum_congr (equiv.refl _) (equiv.set.singleton _)
protected def sum_compl {Ξ±} (s : set Ξ±) [decidable_pred s] : s β (-s : set Ξ±) β Ξ± :=
calc s β (-s : set Ξ±) β β₯(s βͺ -s) : (equiv.set.union (by simp [set.ext_iff])).symm
... β @univ Ξ± : equiv.set.of_eq (by simp)
... β Ξ± : equiv.set.univ _
@[simp] lemma sum_compl_apply_inl {Ξ± : Type u} (s : set Ξ±) [decidable_pred s] (x : s) :
equiv.set.sum_compl s (sum.inl x) = x := rfl
@[simp] lemma sum_compl_apply_inr {Ξ± : Type u} (s : set Ξ±) [decidable_pred s] (x : -s) :
equiv.set.sum_compl s (sum.inr x) = x := rfl
lemma sum_compl_symm_apply_of_mem {Ξ± : Type u} {s : set Ξ±} [decidable_pred s] {x : Ξ±}
(hx : x β s) : (equiv.set.sum_compl s).symm x = sum.inl β¨x, hxβ© :=
have β(β¨x, or.inl hxβ© : (s βͺ -s : set Ξ±)) β s, from hx,
by { rw [equiv.set.sum_compl], simpa using set.union_apply_left _ this }
lemma sum_compl_symm_apply_of_not_mem {Ξ± : Type u} {s : set Ξ±} [decidable_pred s] {x : Ξ±}
(hx : x β s) : (equiv.set.sum_compl s).symm x = sum.inr β¨x, hxβ© :=
have β(β¨x, or.inr hxβ© : (s βͺ -s : set Ξ±)) β -s, from hx,
by { rw [equiv.set.sum_compl], simpa using set.union_apply_right _ this }
protected def union_sum_inter {Ξ± : Type u} (s t : set Ξ±) [decidable_pred s] :
(s βͺ t : set Ξ±) β (s β© t : set Ξ±) β s β t :=
calc (s βͺ t : set Ξ±) β (s β© t : set Ξ±)
β (s βͺ t \ s : set Ξ±) β (s β© t : set Ξ±) : by rw [union_diff_self]
... β (s β (t \ s : set Ξ±)) β (s β© t : set Ξ±) :
sum_congr (set.union (inter_diff_self _ _)) (equiv.refl _)
... β s β (t \ s : set Ξ±) β (s β© t : set Ξ±) : sum_assoc _ _ _
... β s β (t \ s βͺ s β© t : set Ξ±) : sum_congr (equiv.refl _) begin
refine (set.union' (β s) _ _).symm,
exacts [Ξ» x hx, hx.2, Ξ» x hx, not_not_intro hx.1]
end
... β s β t : by { rw (_ : t \ s βͺ s β© t = t), rw [union_comm, inter_comm, inter_union_diff] }
protected def prod {Ξ± Ξ²} (s : set Ξ±) (t : set Ξ²) :
s.prod t β s Γ t :=
β¨Ξ»p, β¨β¨p.1.1, p.2.1β©, β¨p.1.2, p.2.2β©β©,
Ξ»p, β¨β¨p.1.1, p.2.1β©, β¨p.1.2, p.2.2β©β©,
Ξ» β¨β¨x, yβ©, β¨hβ, hββ©β©, rfl,
Ξ» β¨β¨x, hββ©, β¨y, hββ©β©, rflβ©
protected noncomputable def image_of_inj_on {Ξ± Ξ²} (f : Ξ± β Ξ²) (s : set Ξ±) (H : inj_on f s) :
s β (f '' s) :=
β¨Ξ» β¨x, hβ©, β¨f x, mem_image_of_mem f hβ©,
Ξ» β¨y, hβ©, β¨classical.some h, (classical.some_spec h).1β©,
Ξ» β¨x, hβ©, subtype.eq (H (classical.some_spec (mem_image_of_mem f h)).1 h
(classical.some_spec (mem_image_of_mem f h)).2),
Ξ» β¨y, hβ©, subtype.eq (classical.some_spec h).2β©
protected noncomputable def image {Ξ± Ξ²} (f : Ξ± β Ξ²) (s : set Ξ±) (H : injective f) : s β (f '' s) :=
equiv.set.image_of_inj_on f s (Ξ» x y hx hy hxy, H hxy)
@[simp] theorem image_apply {Ξ± Ξ²} (f : Ξ± β Ξ²) (s : set Ξ±) (H : injective f) (a h) :
set.image f s H β¨a, hβ© = β¨f a, mem_image_of_mem _ hβ© := rfl
protected noncomputable def range {Ξ± Ξ²} (f : Ξ± β Ξ²) (H : injective f) :
Ξ± β range f :=
{ to_fun := Ξ» x, β¨f x, mem_range_self _β©,
inv_fun := Ξ» x, classical.some x.2,
left_inv := Ξ» x, H (classical.some_spec (show f x β range f, from mem_range_self _)),
right_inv := Ξ» x, subtype.eq $ classical.some_spec x.2 }
@[simp] theorem range_apply {Ξ± Ξ²} (f : Ξ± β Ξ²) (H : injective f) (a) :
set.range f H a = β¨f a, set.mem_range_self _β© := rfl
protected def congr {Ξ± Ξ² : Type*} (e : Ξ± β Ξ²) : set Ξ± β set Ξ² :=
β¨Ξ» s, e '' s, Ξ» t, e.symm '' t, symm_image_image e, symm_image_image e.symmβ©
protected def sep {Ξ± : Type u} (s : set Ξ±) (t : Ξ± β Prop) :
({ x β s | t x } : set Ξ±) β { x : s | t x.1 } :=
(equiv.subtype_subtype_equiv_subtype_inter s t).symm
end set
noncomputable def of_bijective {Ξ± Ξ²} {f : Ξ± β Ξ²} (hf : bijective f) : Ξ± β Ξ² :=
β¨f, Ξ» x, classical.some (hf.2 x), Ξ» x, hf.1 (classical.some_spec (hf.2 (f x))),
Ξ» x, classical.some_spec (hf.2 x)β©
@[simp] theorem of_bijective_to_fun {Ξ± Ξ²} {f : Ξ± β Ξ²} (hf : bijective f) : (of_bijective hf : Ξ± β Ξ²) = f := rfl
def subtype_quotient_equiv_quotient_subtype (pβ : Ξ± β Prop) [sβ : setoid Ξ±]
[sβ : setoid (subtype pβ)] (pβ : quotient sβ β Prop) (hpβ : β a, pβ a β pβ β¦aβ§)
(h : β x y : subtype pβ, @setoid.r _ sβ x y β (x : Ξ±) β y) :
{x // pβ x} β quotient sβ :=
{ to_fun := Ξ» a, quotient.hrec_on a.1 (Ξ» a h, β¦β¨a, (hpβ _).2 hβ©β§)
(Ξ» a b hab, hfunext (by rw quotient.sound hab)
(Ξ» hβ hβ _, heq_of_eq (quotient.sound ((h _ _).2 hab)))) a.2,
inv_fun := Ξ» a, quotient.lift_on a (Ξ» a, (β¨β¦a.1β§, (hpβ _).1 a.2β© : {x // pβ x}))
(Ξ» a b hab, subtype.eq' (quotient.sound ((h _ _).1 hab))),
left_inv := Ξ» β¨a, haβ©, quotient.induction_on a (Ξ» a ha, rfl) ha,
right_inv := Ξ» a, quotient.induction_on a (Ξ» β¨a, haβ©, rfl) }
section swap
variable [decidable_eq Ξ±]
open decidable
def swap_core (a b r : Ξ±) : Ξ± :=
if r = a then b
else if r = b then a
else r
theorem swap_core_self (r a : Ξ±) : swap_core a a r = r :=
by { unfold swap_core, split_ifs; cc }
theorem swap_core_swap_core (r a b : Ξ±) : swap_core a b (swap_core a b r) = r :=
by { unfold swap_core, split_ifs; cc }
theorem swap_core_comm (r a b : Ξ±) : swap_core a b r = swap_core b a r :=
by { unfold swap_core, split_ifs; cc }
/-- `swap a b` is the permutation that swaps `a` and `b` and
leaves other values as is. -/
def swap (a b : Ξ±) : perm Ξ± :=
β¨swap_core a b, swap_core a b, Ξ»r, swap_core_swap_core r a b, Ξ»r, swap_core_swap_core r a bβ©
theorem swap_self (a : Ξ±) : swap a a = equiv.refl _ :=
eq_of_to_fun_eq $ funext $ Ξ» r, swap_core_self r a
theorem swap_comm (a b : Ξ±) : swap a b = swap b a :=
eq_of_to_fun_eq $ funext $ Ξ» r, swap_core_comm r _ _
theorem swap_apply_def (a b x : Ξ±) : swap a b x = if x = a then b else if x = b then a else x :=
rfl
@[simp] theorem swap_apply_left (a b : Ξ±) : swap a b a = b :=
if_pos rfl
@[simp] theorem swap_apply_right (a b : Ξ±) : swap a b b = a :=
by { by_cases h : b = a; simp [swap_apply_def, h], }
theorem swap_apply_of_ne_of_ne {a b x : Ξ±} : x β a β x β b β swap a b x = x :=
by simp [swap_apply_def] {contextual := tt}
@[simp] theorem swap_swap (a b : Ξ±) : (swap a b).trans (swap a b) = equiv.refl _ :=
eq_of_to_fun_eq $ funext $ Ξ» x, swap_core_swap_core _ _ _
theorem swap_comp_apply {a b x : Ξ±} (Ο : perm Ξ±) :
Ο.trans (swap a b) x = if Ο x = a then b else if Ο x = b then a else Ο x :=
by { cases Ο, refl }
@[simp] lemma swap_inv {Ξ± : Type*} [decidable_eq Ξ±] (x y : Ξ±) :
(swap x y)β»ΒΉ = swap x y := rfl
@[simp] lemma symm_trans_swap_trans [decidable_eq Ξ²] (a b : Ξ±)
(e : Ξ± β Ξ²) : (e.symm.trans (swap a b)).trans e = swap (e a) (e b) :=
equiv.ext _ _ (Ξ» x, begin
have : β a, e.symm x = a β x = e a :=
Ξ» a, by { rw @eq_comm _ (e.symm x), split; intros; simp * at * },
simp [swap_apply_def, this],
split_ifs; simp
end)
@[simp] lemma swap_mul_self {Ξ± : Type*} [decidable_eq Ξ±] (i j : Ξ±) : swap i j * swap i j = 1 :=
equiv.swap_swap i j
@[simp] lemma swap_apply_self {Ξ± : Type*} [decidable_eq Ξ±] (i j a : Ξ±) : swap i j (swap i j a) = a :=
by rw [β perm.mul_apply, swap_mul_self, perm.one_apply]
/-- Augment an equivalence with a prescribed mapping `f a = b` -/
def set_value (f : Ξ± β Ξ²) (a : Ξ±) (b : Ξ²) : Ξ± β Ξ² :=
(swap a (f.symm b)).trans f
@[simp] theorem set_value_eq (f : Ξ± β Ξ²) (a : Ξ±) (b : Ξ²) : set_value f a b a = b :=
by { dsimp [set_value], simp [swap_apply_left] }
end swap
protected lemma forall_congr {p : Ξ± β Prop} {q : Ξ² β Prop} (f : Ξ± β Ξ²)
(h : β{x}, p x β q (f x)) : (βx, p x) β (βy, q y) :=
begin
split; intros hβ x,
{ rw [βf.right_inv x], apply h.mp, apply hβ },
apply h.mpr, apply hβ
end
protected lemma forall_congr_left' {p : Ξ± β Prop} (f : Ξ± β Ξ²) :
(βx, p x) β (βy, p (f.symm y)) :=
equiv.forall_congr f (Ξ»x, by simp)
protected lemma forall_congr_left {p : Ξ² β Prop} (f : Ξ± β Ξ²) :
(βx, p (f x)) β (βy, p y) :=
(equiv.forall_congr_left' f.symm).symm
section
variables (P : Ξ± β Sort w) (e : Ξ± β Ξ²)
/--
Transport dependent functions through an equivalence of the base space.
-/
def Pi_congr_left' : (Ξ a, P a) β (Ξ b, P (e.symm b)) :=
{ to_fun := Ξ» f x, f (e.symm x),
inv_fun := Ξ» f x, begin rw [β e.symm_apply_apply x], exact f (e x) end,
left_inv := Ξ» f, funext $ Ξ» x, eq_of_heq ((eq_rec_heq _ _).trans (by { dsimp, rw e.symm_apply_apply })),
right_inv := Ξ» f, funext $ Ξ» x, eq_of_heq ((eq_rec_heq _ _).trans (by { rw e.apply_symm_apply })) }
@[simp]
lemma Pi_congr_left'_apply (f : Ξ a, P a) (b : Ξ²) : ((Pi_congr_left' P e) f) b = f (e.symm b) :=
rfl
@[simp]
lemma Pi_congr_left'_symm_apply (g : Ξ b, P (e.symm b)) (a : Ξ±) :
((Pi_congr_left' P e).symm g) a = (by { convert g (e a), simp }) :=
rfl
end
section
variables (P : Ξ² β Sort w) (e : Ξ± β Ξ²)
/--
Transporting dependent functions through an equivalence of the base,
expressed as a "simplification".
-/
def Pi_congr_left : (Ξ a, P (e a)) β (Ξ b, P b) :=
(Pi_congr_left' P e.symm).symm
end
section
variables
{W : Ξ± β Sort w} {Z : Ξ² β Sort z} (hβ : Ξ± β Ξ²) (hβ : Ξ a : Ξ±, (W a β Z (hβ a)))
/--
Transport dependent functions through
an equivalence of the base spaces and a family
of equivalences of the matching fibres.
-/
def Pi_congr : (Ξ a, W a) β (Ξ b, Z b) :=
(equiv.Pi_congr_right hβ).trans (equiv.Pi_congr_left _ hβ)
end
end equiv
instance {Ξ±} [subsingleton Ξ±] : subsingleton (ulift Ξ±) := equiv.ulift.subsingleton
instance {Ξ±} [subsingleton Ξ±] : subsingleton (plift Ξ±) := equiv.plift.subsingleton
instance {Ξ±} [decidable_eq Ξ±] : decidable_eq (ulift Ξ±) := equiv.ulift.decidable_eq
instance {Ξ±} [decidable_eq Ξ±] : decidable_eq (plift Ξ±) := equiv.plift.decidable_eq
def unique_unique_equiv : unique (unique Ξ±) β unique Ξ± :=
{ to_fun := Ξ» h, h.default,
inv_fun := Ξ» h, { default := h, uniq := Ξ» _, subsingleton.elim _ _ },
left_inv := Ξ» _, subsingleton.elim _ _,
right_inv := Ξ» _, subsingleton.elim _ _ }
def equiv_of_unique_of_unique [unique Ξ±] [unique Ξ²] : Ξ± β Ξ² :=
{ to_fun := Ξ» _, default Ξ²,
inv_fun := Ξ» _, default Ξ±,
left_inv := Ξ» _, subsingleton.elim _ _,
right_inv := Ξ» _, subsingleton.elim _ _ }
def equiv_punit_of_unique [unique Ξ±] : Ξ± β punit.{v} :=
equiv_of_unique_of_unique
namespace quot
/-- An equivalence `e : Ξ± β Ξ²` generates an equivalence between quotient spaces,
if `ra aβ aβ β rb (e aβ) (e aβ). -/
protected def congr {ra : Ξ± β Ξ± β Prop} {rb : Ξ² β Ξ² β Prop} (e : Ξ± β Ξ²)
(eq : βaβ aβ, ra aβ aβ β rb (e aβ) (e aβ)) :
quot ra β quot rb :=
{ to_fun := quot.map e (assume aβ aβ, (eq aβ aβ).1),
inv_fun := quot.map e.symm
(assume bβ bβ h,
(eq (e.symm bβ) (e.symm bβ)).2
((e.apply_symm_apply bβ).symm βΈ (e.apply_symm_apply bβ).symm βΈ h)),
left_inv := by { rintros β¨aβ©, dunfold quot.map, simp only [equiv.symm_apply_apply] },
right_inv := by { rintros β¨aβ©, dunfold quot.map, simp only [equiv.apply_symm_apply] } }
/-- Quotients are congruent on equivalences under equality of their relation.
An alternative is just to use rewriting with `eq`, but then computational proofs get stuck. -/
protected def congr_right {r r' : Ξ± β Ξ± β Prop} (eq : βaβ aβ, r aβ aβ β r' aβ aβ) :
quot r β quot r' :=
quot.congr (equiv.refl Ξ±) eq
/-- An equivalence `e : Ξ± β Ξ²` generates an equivalence between the quotient space of `Ξ±`
by a relation `ra` and the quotient space of `Ξ²` by the image of this relation under `e`. -/
protected def congr_left {r : Ξ± β Ξ± β Prop} (e : Ξ± β Ξ²) :
quot r β quot (Ξ» b b', r (e.symm b) (e.symm b')) :=
@quot.congr Ξ± Ξ² r (Ξ» b b', r (e.symm b) (e.symm b')) e (Ξ» aβ aβ, by simp only [e.symm_apply_apply])
end quot
namespace quotient
/-- An equivalence `e : Ξ± β Ξ²` generates an equivalence between quotient spaces,
if `ra aβ aβ β rb (e aβ) (e aβ). -/
protected def congr {ra : setoid Ξ±} {rb : setoid Ξ²} (e : Ξ± β Ξ²)
(eq : βaβ aβ, @setoid.r Ξ± ra aβ aβ β @setoid.r Ξ² rb (e aβ) (e aβ)) :
quotient ra β quotient rb :=
quot.congr e eq
/-- Quotients are congruent on equivalences under equality of their relation.
An alternative is just to use rewriting with `eq`, but then computational proofs get stuck. -/
protected def congr_right {r r' : setoid Ξ±}
(eq : βaβ aβ, @setoid.r Ξ± r aβ aβ β @setoid.r Ξ± r' aβ aβ) : quotient r β quotient r' :=
quot.congr_right eq
end quotient
/-- If a function is a bijection between `univ` and a set `s` in the target type, it induces an
equivalence between the original type and the type `βs`. -/
noncomputable def set.bij_on.equiv {Ξ± : Type*} {Ξ² : Type*} {s : set Ξ²} (f : Ξ± β Ξ²)
(h : set.bij_on f set.univ s) : Ξ± β s :=
begin
have : function.bijective (Ξ» (x : Ξ±), (β¨f x, begin exact h.maps_to (set.mem_univ x) endβ© : s)),
{ split,
{ assume x y hxy,
apply h.inj_on (set.mem_univ x) (set.mem_univ y) (subtype.mk.inj hxy) },
{ assume x,
rcases h.surj_on x.2 with β¨y, hyβ©,
exact β¨y, subtype.eq hy.2β© } },
exact equiv.of_bijective this
end
/-- The composition of an updated function with an equiv on a subset can be expressed as an
updated function. -/
lemma dite_comp_equiv_update {Ξ± : Type*} {Ξ² : Type*} {Ξ³ : Type*} {s : set Ξ±} (e : Ξ² β s)
(v : Ξ² β Ξ³) (w : Ξ± β Ξ³) (j : Ξ²) (x : Ξ³) [decidable_eq Ξ²] [decidable_eq Ξ±]
[β j, decidable (j β s)] :
(Ξ» (i : Ξ±), if h : i β s then (function.update v j x) (e.symm β¨i, hβ©) else w i) =
function.update (Ξ» (i : Ξ±), if h : i β s then v (e.symm β¨i, hβ©) else w i) (e j) x :=
begin
ext i,
by_cases h : i β s,
{ simp only [h, dif_pos],
have A : e.symm β¨i, hβ© = j β i = e j,
by { rw equiv.symm_apply_eq, exact subtype.ext },
by_cases h' : i = e j,
{ rw [A.2 h', h'], simp },
{ have : Β¬ e.symm β¨i, hβ© = j, by simpa [β A] using h',
simp [h, h', this] } },
{ have : i β e j,
by { contrapose! h, have : (e j : Ξ±) β s := (e j).2, rwa β h at this },
simp [h, this] }
end
|
10921155943c10ef80ccab5667f979056f856f4c | 9dc8cecdf3c4634764a18254e94d43da07142918 | /src/linear_algebra/eigenspace.lean | 3d2bdd6d8c239ca7e7e0d75ed341447545df7ab3 | [
"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 | 29,281 | lean | /-
Copyright (c) 2020 Alexander Bentkamp. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Alexander Bentkamp
-/
import linear_algebra.charpoly.basic
import linear_algebra.finsupp
import linear_algebra.matrix.to_lin
import algebra.algebra.spectrum
import order.hom.basic
/-!
# Eigenvectors and eigenvalues
This file defines eigenspaces, eigenvalues, and eigenvalues, as well as their generalized
counterparts. We follow Axler's approach [axler2015] because it allows us to derive many properties
without choosing a basis and without using matrices.
An eigenspace of a linear map `f` for a scalar `ΞΌ` is the kernel of the map `(f - ΞΌ β’ id)`. The
nonzero elements of an eigenspace are eigenvectors `x`. They have the property `f x = ΞΌ β’ x`. If
there are eigenvectors for a scalar `ΞΌ`, the scalar `ΞΌ` is called an eigenvalue.
There is no consensus in the literature whether `0` is an eigenvector. Our definition of
`has_eigenvector` permits only nonzero vectors. For an eigenvector `x` that may also be `0`, we
write `x β f.eigenspace ΞΌ`.
A generalized eigenspace of a linear map `f` for a natural number `k` and a scalar `ΞΌ` is the kernel
of the map `(f - ΞΌ β’ id) ^ k`. The nonzero elements of a generalized eigenspace are generalized
eigenvectors `x`. If there are generalized eigenvectors for a natural number `k` and a scalar `ΞΌ`,
the scalar `ΞΌ` is called a generalized eigenvalue.
## References
* [Sheldon Axler, *Linear Algebra Done Right*][axler2015]
* https://en.wikipedia.org/wiki/Eigenvalues_and_eigenvectors
## Tags
eigenspace, eigenvector, eigenvalue, eigen
-/
universes u v w
namespace module
namespace End
open module principal_ideal_ring polynomial finite_dimensional
open_locale polynomial
variables {K R : Type v} {V M : Type w}
[comm_ring R] [add_comm_group M] [module R M] [field K] [add_comm_group V] [module K V]
/-- The submodule `eigenspace f ΞΌ` for a linear map `f` and a scalar `ΞΌ` consists of all vectors `x`
such that `f x = ΞΌ β’ x`. (Def 5.36 of [axler2015])-/
def eigenspace (f : End R M) (ΞΌ : R) : submodule R M :=
(f - algebra_map R (End R M) ΞΌ).ker
@[simp] lemma eigenspace_zero (f : End R M) : f.eigenspace 0 = f.ker :=
by simp [eigenspace]
/-- A nonzero element of an eigenspace is an eigenvector. (Def 5.7 of [axler2015]) -/
def has_eigenvector (f : End R M) (ΞΌ : R) (x : M) : Prop :=
x β eigenspace f ΞΌ β§ x β 0
/-- A scalar `ΞΌ` is an eigenvalue for a linear map `f` if there are nonzero vectors `x`
such that `f x = ΞΌ β’ x`. (Def 5.5 of [axler2015]) -/
def has_eigenvalue (f : End R M) (a : R) : Prop :=
eigenspace f a β β₯
/-- The eigenvalues of the endomorphism `f`, as a subtype of `R`. -/
def eigenvalues (f : End R M) : Type* := {ΞΌ : R // f.has_eigenvalue ΞΌ}
instance (f : End R M) : has_coe f.eigenvalues R := coe_subtype
lemma has_eigenvalue_of_has_eigenvector {f : End R M} {ΞΌ : R} {x : M} (h : has_eigenvector f ΞΌ x) :
has_eigenvalue f ΞΌ :=
begin
rw [has_eigenvalue, submodule.ne_bot_iff],
use x, exact h,
end
lemma mem_eigenspace_iff {f : End R M} {ΞΌ : R} {x : M} : x β eigenspace f ΞΌ β f x = ΞΌ β’ x :=
by rw [eigenspace, linear_map.mem_ker, linear_map.sub_apply, algebra_map_End_apply,
sub_eq_zero]
lemma has_eigenvector.apply_eq_smul {f : End R M} {ΞΌ : R} {x : M} (hx : f.has_eigenvector ΞΌ x) :
f x = ΞΌ β’ x :=
mem_eigenspace_iff.mp hx.1
lemma has_eigenvalue.exists_has_eigenvector {f : End R M} {ΞΌ : R} (hΞΌ : f.has_eigenvalue ΞΌ) :
β v, f.has_eigenvector ΞΌ v :=
submodule.exists_mem_ne_zero_of_ne_bot hΞΌ
lemma mem_spectrum_of_has_eigenvalue {f : End R M} {ΞΌ : R} (hΞΌ : has_eigenvalue f ΞΌ) :
ΞΌ β spectrum R f :=
begin
refine spectrum.mem_iff.mpr (Ξ» h_unit, _),
set f' := linear_map.general_linear_group.to_linear_equiv h_unit.unit,
rcases hΞΌ.exists_has_eigenvector with β¨v, hvβ©,
refine hv.2 ((linear_map.ker_eq_bot'.mp f'.ker) v (_ : ΞΌ β’ v - f v = 0)),
rw [hv.apply_eq_smul, sub_self]
end
lemma has_eigenvalue_iff_mem_spectrum [finite_dimensional K V] {f : End K V} {ΞΌ : K} :
f.has_eigenvalue ΞΌ β ΞΌ β spectrum K f :=
iff.intro mem_spectrum_of_has_eigenvalue
(Ξ» h, by rwa [spectrum.mem_iff, is_unit.sub_iff, linear_map.is_unit_iff_ker_eq_bot] at h)
lemma eigenspace_div (f : End K V) (a b : K) (hb : b β 0) :
eigenspace f (a / b) = (b β’ f - algebra_map K (End K V) a).ker :=
calc
eigenspace f (a / b) = eigenspace f (bβ»ΒΉ * a) : by { rw [div_eq_mul_inv, mul_comm] }
... = (f - (bβ»ΒΉ * a) β’ linear_map.id).ker : rfl
... = (f - bβ»ΒΉ β’ a β’ linear_map.id).ker : by rw smul_smul
... = (f - bβ»ΒΉ β’ algebra_map K (End K V) a).ker : rfl
... = (b β’ (f - bβ»ΒΉ β’ algebra_map K (End K V) a)).ker : by rw linear_map.ker_smul _ b hb
... = (b β’ f - algebra_map K (End K V) a).ker : by rw [smul_sub, smul_inv_smulβ hb]
lemma eigenspace_aeval_polynomial_degree_1
(f : End K V) (q : K[X]) (hq : degree q = 1) :
eigenspace f (- q.coeff 0 / q.leading_coeff) = (aeval f q).ker :=
calc
eigenspace f (- q.coeff 0 / q.leading_coeff)
= (q.leading_coeff β’ f - algebra_map K (End K V) (- q.coeff 0)).ker
: by { rw eigenspace_div, intro h, rw leading_coeff_eq_zero_iff_deg_eq_bot.1 h at hq, cases hq }
... = (aeval f (C q.leading_coeff * X + C (q.coeff 0))).ker
: by { rw [C_mul', aeval_def], simp [algebra_map, algebra.to_ring_hom], }
... = (aeval f q).ker
: by rwa β eq_X_add_C_of_degree_eq_one
lemma ker_aeval_ring_hom'_unit_polynomial
(f : End K V) (c : (K[X])Λ£) :
(aeval f (c : K[X])).ker = β₯ :=
begin
rw polynomial.eq_C_of_degree_eq_zero (degree_coe_units c),
simp only [aeval_def, evalβ_C],
apply ker_algebra_map_End,
apply coeff_coe_units_zero_ne_zero c
end
theorem aeval_apply_of_has_eigenvector {f : End K V}
{p : K[X]} {ΞΌ : K} {x : V} (h : f.has_eigenvector ΞΌ x) :
aeval f p x = (p.eval ΞΌ) β’ x :=
begin
apply p.induction_on,
{ intro a, simp [module.algebra_map_End_apply] },
{ intros p q hp hq, simp [hp, hq, add_smul] },
{ intros n a hna,
rw [mul_comm, pow_succ, mul_assoc, alg_hom.map_mul, linear_map.mul_apply, mul_comm, hna],
simp only [mem_eigenspace_iff.1 h.1, smul_smul, aeval_X, eval_mul, eval_C, eval_pow, eval_X,
linear_map.map_smulββ, ring_hom.id_apply, mul_comm] }
end
section minpoly
theorem is_root_of_has_eigenvalue {f : End K V} {ΞΌ : K} (h : f.has_eigenvalue ΞΌ) :
(minpoly K f).is_root ΞΌ :=
begin
rcases (submodule.ne_bot_iff _).1 h with β¨w, β¨H, ne0β©β©,
refine or.resolve_right (smul_eq_zero.1 _) ne0,
simp [β aeval_apply_of_has_eigenvector β¨H, ne0β©, minpoly.aeval K f],
end
variables [finite_dimensional K V] (f : End K V)
variables {f} {ΞΌ : K}
theorem has_eigenvalue_of_is_root (h : (minpoly K f).is_root ΞΌ) :
f.has_eigenvalue ΞΌ :=
begin
cases dvd_iff_is_root.2 h with p hp,
rw [has_eigenvalue, eigenspace],
intro con,
cases (linear_map.is_unit_iff_ker_eq_bot _).2 con with u hu,
have p_ne_0 : p β 0,
{ intro con,
apply minpoly.ne_zero f.is_integral,
rw [hp, con, mul_zero] },
have h_deg := minpoly.degree_le_of_ne_zero K f p_ne_0 _,
{ rw [hp, degree_mul, degree_X_sub_C, polynomial.degree_eq_nat_degree p_ne_0] at h_deg,
norm_cast at h_deg,
linarith, },
{ have h_aeval := minpoly.aeval K f,
revert h_aeval,
simp [hp, β hu] },
end
theorem has_eigenvalue_iff_is_root :
f.has_eigenvalue ΞΌ β (minpoly K f).is_root ΞΌ :=
β¨is_root_of_has_eigenvalue, has_eigenvalue_of_is_rootβ©
/-- An endomorphism of a finite-dimensional vector space has finitely many eigenvalues. -/
noncomputable instance (f : End K V) : fintype f.eigenvalues :=
set.finite.fintype
begin
have h : minpoly K f β 0 := minpoly.ne_zero f.is_integral,
convert (minpoly K f).root_set_finite K,
ext ΞΌ,
have : (ΞΌ β {ΞΌ : K | f.eigenspace ΞΌ = β₯ β false}) β Β¬f.eigenspace ΞΌ = β₯ := by tauto,
convert rfl.mpr this,
simp [polynomial.root_set_def, polynomial.mem_roots h, β has_eigenvalue_iff_is_root,
has_eigenvalue]
end
end minpoly
/-- Every linear operator on a vector space over an algebraically closed field has
an eigenvalue. -/
-- This is Lemma 5.21 of [axler2015], although we are no longer following that proof.
lemma exists_eigenvalue [is_alg_closed K] [finite_dimensional K V] [nontrivial V] (f : End K V) :
β (c : K), f.has_eigenvalue c :=
by { simp_rw has_eigenvalue_iff_mem_spectrum,
exact spectrum.nonempty_of_is_alg_closed_of_finite_dimensional K f }
noncomputable instance [is_alg_closed K] [finite_dimensional K V] [nontrivial V] (f : End K V) :
inhabited f.eigenvalues :=
β¨β¨f.exists_eigenvalue.some, f.exists_eigenvalue.some_specβ©β©
/-- The eigenspaces of a linear operator form an independent family of subspaces of `V`. That is,
any eigenspace has trivial intersection with the span of all the other eigenspaces. -/
lemma eigenspaces_independent (f : End K V) : complete_lattice.independent f.eigenspace :=
begin
classical,
-- Define an operation from `Ξ β ΞΌ : K, f.eigenspace ΞΌ`, the vector space of of finitely-supported
-- choices of an eigenvector from each eigenspace, to `V`, by sending a collection to its sum.
let S : @linear_map K K _ _ (ring_hom.id K) (Ξ β ΞΌ : K, f.eigenspace ΞΌ) V
(@dfinsupp.add_comm_monoid K (Ξ» ΞΌ, f.eigenspace ΞΌ) _) _
(@dfinsupp.module K _ (Ξ» ΞΌ, f.eigenspace ΞΌ) _ _ _) _ :=
@dfinsupp.lsum K K β _ V _ _ _ _ _ _ _ _ _
(Ξ» ΞΌ, (f.eigenspace ΞΌ).subtype),
-- We need to show that if a finitely-supported collection `l` of representatives of the
-- eigenspaces has sum `0`, then it itself is zero.
suffices : β l : Ξ β ΞΌ, f.eigenspace ΞΌ, S l = 0 β l = 0,
{ rw complete_lattice.independent_iff_dfinsupp_lsum_injective,
change function.injective S,
rw β @linear_map.ker_eq_bot K K (Ξ β ΞΌ, (f.eigenspace ΞΌ)) V _ _
(@dfinsupp.add_comm_group K (Ξ» ΞΌ, f.eigenspace ΞΌ) _),
rw eq_bot_iff,
exact this },
intros l hl,
-- We apply induction on the finite set of eigenvalues from which `l` selects a nonzero
-- eigenvector, i.e. on the support of `l`.
induction h_l_support : l.support using finset.induction with ΞΌβ l_support' hΞΌβ ih generalizing l,
-- If the support is empty, all coefficients are zero and we are done.
{ exact dfinsupp.support_eq_empty.1 h_l_support },
-- Now assume that the support of `l` contains at least one eigenvalue `ΞΌβ`. We define a new
-- collection of representatives `l'` to apply the induction hypothesis on later. The collection
-- of representatives `l'` is derived from `l` by multiplying the coefficient of the eigenvector
-- with eigenvalue `ΞΌ` by `ΞΌ - ΞΌβ`.
{ let l' := dfinsupp.map_range.linear_map
(Ξ» ΞΌ, (ΞΌ - ΞΌβ) β’ @linear_map.id K (f.eigenspace ΞΌ) _ _ _) l,
-- The support of `l'` is the support of `l` without `ΞΌβ`.
have h_l_support' : l'.support = l_support',
{ rw [β finset.erase_insert hΞΌβ, β h_l_support],
ext a,
have : Β¬(a = ΞΌβ β¨ l a = 0) β Β¬a = ΞΌβ β§ Β¬l a = 0 := not_or_distrib,
simp only [l', dfinsupp.map_range.linear_map_apply, dfinsupp.map_range_apply,
dfinsupp.mem_support_iff, finset.mem_erase, id.def, linear_map.id_coe,
linear_map.smul_apply, ne.def, smul_eq_zero, sub_eq_zero, this] },
-- The entries of `l'` add up to `0`.
have total_l' : S l' = 0,
{ let g := f - algebra_map K (End K V) ΞΌβ,
let a : Ξ β ΞΌ : K, V := dfinsupp.map_range.linear_map (Ξ» ΞΌ, (f.eigenspace ΞΌ).subtype) l,
calc S l'
= dfinsupp.lsum β (Ξ» ΞΌ, (f.eigenspace ΞΌ).subtype.comp ((ΞΌ - ΞΌβ) β’ linear_map.id)) l : _
... = dfinsupp.lsum β (Ξ» ΞΌ, g.comp (f.eigenspace ΞΌ).subtype) l : _
... = dfinsupp.lsum β (Ξ» ΞΌ, g) a : _
... = g (dfinsupp.lsum β (Ξ» ΞΌ, (linear_map.id : V ββ[K] V)) a) : _
... = g (S l) : _
... = 0 : by rw [hl, g.map_zero],
{ exact dfinsupp.sum_map_range_index.linear_map },
{ congr,
ext ΞΌ v,
simp only [g, eq_self_iff_true, function.comp_app, id.def, linear_map.coe_comp,
linear_map.id_coe, linear_map.smul_apply, linear_map.sub_apply,
module.algebra_map_End_apply, sub_left_inj, sub_smul, submodule.coe_smul_of_tower,
submodule.coe_sub, submodule.subtype_apply, mem_eigenspace_iff.1 v.prop], },
{ rw dfinsupp.sum_map_range_index.linear_map },
{ simp only [dfinsupp.sum_add_hom_apply, linear_map.id_coe, linear_map.map_dfinsupp_sum,
id.def, linear_map.to_add_monoid_hom_coe, dfinsupp.lsum_apply_apply], },
{ congr,
simp only [S, a, dfinsupp.sum_map_range_index.linear_map, linear_map.id_comp] } },
-- Therefore, by the induction hypothesis, all entries of `l'` are zero.
have l'_eq_0 := ih l' total_l' h_l_support',
-- By the definition of `l'`, this means that `(ΞΌ - ΞΌβ) β’ l ΞΌ = 0` for all `ΞΌ`.
have h_smul_eq_0 : β ΞΌ, (ΞΌ - ΞΌβ) β’ l ΞΌ = 0,
{ intro ΞΌ,
calc (ΞΌ - ΞΌβ) β’ l ΞΌ = l' ΞΌ : by simp only [l', linear_map.id_coe, id.def,
linear_map.smul_apply, dfinsupp.map_range_apply, dfinsupp.map_range.linear_map_apply]
... = 0 : by { rw [l'_eq_0], refl } },
-- Thus, the eigenspace-representatives in `l` for all `ΞΌ β ΞΌβ` are `0`.
have h_lΞΌ_eq_0 : β ΞΌ : K, ΞΌ β ΞΌβ β l ΞΌ = 0,
{ intros ΞΌ hΞΌ,
apply or_iff_not_imp_left.1 (smul_eq_zero.1 (h_smul_eq_0 ΞΌ)),
rwa [sub_eq_zero] },
-- So if we sum over all these representatives, we obtain `0`.
have h_sum_l_support'_eq_0 : finset.sum l_support' (Ξ» ΞΌ, (l ΞΌ : V)) = 0,
{ rw βfinset.sum_const_zero,
apply finset.sum_congr rfl,
intros ΞΌ hΞΌ,
rw [submodule.coe_eq_zero, h_lΞΌ_eq_0],
rintro rfl,
exact hΞΌβ hΞΌ },
-- The only potentially nonzero eigenspace-representative in `l` is the one corresponding to
-- `ΞΌβ`. But since the overall sum is `0` by assumption, this representative must also be `0`.
have : l ΞΌβ = 0,
{ simp only [S, dfinsupp.lsum_apply_apply, dfinsupp.sum_add_hom_apply,
linear_map.to_add_monoid_hom_coe, dfinsupp.sum, h_l_support, submodule.subtype_apply,
submodule.coe_eq_zero, finset.sum_insert hΞΌβ, h_sum_l_support'_eq_0, add_zero] at hl,
exact hl },
-- Thus, all coefficients in `l` are `0`.
show l = 0,
{ ext ΞΌ,
by_cases h_cases : ΞΌ = ΞΌβ,
{ rwa [h_cases, set_like.coe_eq_coe, dfinsupp.coe_zero, pi.zero_apply] },
exact congr_arg (coe : _ β V) (h_lΞΌ_eq_0 ΞΌ h_cases) }}
end
/-- Eigenvectors corresponding to distinct eigenvalues of a linear operator are linearly
independent. (Lemma 5.10 of [axler2015])
We use the eigenvalues as indexing set to ensure that there is only one eigenvector for each
eigenvalue in the image of `xs`. -/
lemma eigenvectors_linear_independent (f : End K V) (ΞΌs : set K) (xs : ΞΌs β V)
(h_eigenvec : β ΞΌ : ΞΌs, f.has_eigenvector ΞΌ (xs ΞΌ)) :
linear_independent K xs :=
complete_lattice.independent.linear_independent _
(f.eigenspaces_independent.comp subtype.coe_injective)
(Ξ» ΞΌ, (h_eigenvec ΞΌ).1) (Ξ» ΞΌ, (h_eigenvec ΞΌ).2)
/-- The generalized eigenspace for a linear map `f`, a scalar `ΞΌ`, and an exponent `k β β` is the
kernel of `(f - ΞΌ β’ id) ^ k`. (Def 8.10 of [axler2015]). Furthermore, a generalized eigenspace for
some exponent `k` is contained in the generalized eigenspace for exponents larger than `k`. -/
def generalized_eigenspace (f : End R M) (ΞΌ : R) : β βo submodule R M :=
{ to_fun := Ξ» k, ((f - algebra_map R (End R M) ΞΌ) ^ k).ker,
monotone' := Ξ» k m hm,
begin
simp only [β pow_sub_mul_pow _ hm],
exact linear_map.ker_le_ker_comp
((f - algebra_map R (End R M) ΞΌ) ^ k) ((f - algebra_map R (End R M) ΞΌ) ^ (m - k)),
end }
@[simp] lemma mem_generalized_eigenspace (f : End R M) (ΞΌ : R) (k : β) (m : M) :
m β f.generalized_eigenspace ΞΌ k β ((f - ΞΌ β’ 1)^k) m = 0 :=
iff.rfl
@[simp] lemma generalized_eigenspace_zero (f : End R M) (k : β) :
f.generalized_eigenspace 0 k = (f^k).ker :=
by simp [module.End.generalized_eigenspace]
/-- A nonzero element of a generalized eigenspace is a generalized eigenvector.
(Def 8.9 of [axler2015])-/
def has_generalized_eigenvector (f : End R M) (ΞΌ : R) (k : β) (x : M) : Prop :=
x β 0 β§ x β generalized_eigenspace f ΞΌ k
/-- A scalar `ΞΌ` is a generalized eigenvalue for a linear map `f` and an exponent `k β β` if there
are generalized eigenvectors for `f`, `k`, and `ΞΌ`. -/
def has_generalized_eigenvalue (f : End R M) (ΞΌ : R) (k : β) : Prop :=
generalized_eigenspace f ΞΌ k β β₯
/-- The generalized eigenrange for a linear map `f`, a scalar `ΞΌ`, and an exponent `k β β` is the
range of `(f - ΞΌ β’ id) ^ k`. -/
def generalized_eigenrange (f : End R M) (ΞΌ : R) (k : β) : submodule R M :=
((f - algebra_map R (End R M) ΞΌ) ^ k).range
/-- The exponent of a generalized eigenvalue is never 0. -/
lemma exp_ne_zero_of_has_generalized_eigenvalue {f : End R M} {ΞΌ : R} {k : β}
(h : f.has_generalized_eigenvalue ΞΌ k) : k β 0 :=
begin
rintro rfl,
exact h linear_map.ker_id
end
/-- The union of the kernels of `(f - ΞΌ β’ id) ^ k` over all `k`. -/
def maximal_generalized_eigenspace (f : End R M) (ΞΌ : R) : submodule R M :=
β¨ k, f.generalized_eigenspace ΞΌ k
lemma generalized_eigenspace_le_maximal (f : End R M) (ΞΌ : R) (k : β) :
f.generalized_eigenspace ΞΌ k β€ f.maximal_generalized_eigenspace ΞΌ :=
le_supr _ _
@[simp] lemma mem_maximal_generalized_eigenspace (f : End R M) (ΞΌ : R) (m : M) :
m β f.maximal_generalized_eigenspace ΞΌ β β (k : β), ((f - ΞΌ β’ 1)^k) m = 0 :=
by simp only [maximal_generalized_eigenspace, β mem_generalized_eigenspace,
submodule.mem_supr_of_chain]
/-- If there exists a natural number `k` such that the kernel of `(f - ΞΌ β’ id) ^ k` is the
maximal generalized eigenspace, then this value is the least such `k`. If not, this value is not
meaningful. -/
noncomputable def maximal_generalized_eigenspace_index (f : End R M) (ΞΌ : R) :=
monotonic_sequence_limit_index (f.generalized_eigenspace ΞΌ)
/-- For an endomorphism of a Noetherian module, the maximal eigenspace is always of the form kernel
`(f - ΞΌ β’ id) ^ k` for some `k`. -/
lemma maximal_generalized_eigenspace_eq [h : is_noetherian R M] (f : End R M) (ΞΌ : R) :
maximal_generalized_eigenspace f ΞΌ =
f.generalized_eigenspace ΞΌ (maximal_generalized_eigenspace_index f ΞΌ) :=
begin
rw is_noetherian_iff_well_founded at h,
exact (well_founded.supr_eq_monotonic_sequence_limit h (f.generalized_eigenspace ΞΌ) : _),
end
/-- A generalized eigenvalue for some exponent `k` is also
a generalized eigenvalue for exponents larger than `k`. -/
lemma has_generalized_eigenvalue_of_has_generalized_eigenvalue_of_le
{f : End R M} {ΞΌ : R} {k : β} {m : β} (hm : k β€ m) (hk : f.has_generalized_eigenvalue ΞΌ k) :
f.has_generalized_eigenvalue ΞΌ m :=
begin
unfold has_generalized_eigenvalue at *,
contrapose! hk,
rw [βle_bot_iff, βhk],
exact (f.generalized_eigenspace ΞΌ).monotone hm,
end
/-- The eigenspace is a subspace of the generalized eigenspace. -/
lemma eigenspace_le_generalized_eigenspace {f : End R M} {ΞΌ : R} {k : β} (hk : 0 < k) :
f.eigenspace ΞΌ β€ f.generalized_eigenspace ΞΌ k :=
(f.generalized_eigenspace ΞΌ).monotone (nat.succ_le_of_lt hk)
/-- All eigenvalues are generalized eigenvalues. -/
lemma has_generalized_eigenvalue_of_has_eigenvalue
{f : End R M} {ΞΌ : R} {k : β} (hk : 0 < k) (hΞΌ : f.has_eigenvalue ΞΌ) :
f.has_generalized_eigenvalue ΞΌ k :=
begin
apply has_generalized_eigenvalue_of_has_generalized_eigenvalue_of_le hk,
rw [has_generalized_eigenvalue, generalized_eigenspace, order_hom.coe_fun_mk, pow_one],
exact hΞΌ,
end
/-- All generalized eigenvalues are eigenvalues. -/
lemma has_eigenvalue_of_has_generalized_eigenvalue
{f : End R M} {ΞΌ : R} {k : β} (hΞΌ : f.has_generalized_eigenvalue ΞΌ k) :
f.has_eigenvalue ΞΌ :=
begin
intros contra, apply hΞΌ,
erw linear_map.ker_eq_bot at β’ contra, rw linear_map.coe_pow,
exact function.injective.iterate contra k,
end
/-- Generalized eigenvalues are actually just eigenvalues. -/
@[simp] lemma has_generalized_eigenvalue_iff_has_eigenvalue
{f : End R M} {ΞΌ : R} {k : β} (hk : 0 < k) :
f.has_generalized_eigenvalue ΞΌ k β f.has_eigenvalue ΞΌ :=
β¨has_eigenvalue_of_has_generalized_eigenvalue, has_generalized_eigenvalue_of_has_eigenvalue hkβ©
/-- Every generalized eigenvector is a generalized eigenvector for exponent `finrank K V`.
(Lemma 8.11 of [axler2015]) -/
lemma generalized_eigenspace_le_generalized_eigenspace_finrank
[finite_dimensional K V] (f : End K V) (ΞΌ : K) (k : β) :
f.generalized_eigenspace ΞΌ k β€ f.generalized_eigenspace ΞΌ (finrank K V) :=
ker_pow_le_ker_pow_finrank _ _
/-- Generalized eigenspaces for exponents at least `finrank K V` are equal to each other. -/
lemma generalized_eigenspace_eq_generalized_eigenspace_finrank_of_le [finite_dimensional K V]
(f : End K V) (ΞΌ : K) {k : β} (hk : finrank K V β€ k) :
f.generalized_eigenspace ΞΌ k = f.generalized_eigenspace ΞΌ (finrank K V) :=
ker_pow_eq_ker_pow_finrank_of_le hk
/-- If `f` maps a subspace `p` into itself, then the generalized eigenspace of the restriction
of `f` to `p` is the part of the generalized eigenspace of `f` that lies in `p`. -/
lemma generalized_eigenspace_restrict
(f : End R M) (p : submodule R M) (k : β) (ΞΌ : R) (hfp : β (x : M), x β p β f x β p) :
generalized_eigenspace (linear_map.restrict f hfp) ΞΌ k =
submodule.comap p.subtype (f.generalized_eigenspace ΞΌ k) :=
begin
simp only [generalized_eigenspace, order_hom.coe_fun_mk, β linear_map.ker_comp],
induction k with k ih,
{ rw [pow_zero, pow_zero, linear_map.one_eq_id],
apply (submodule.ker_subtype _).symm },
{ erw [pow_succ', pow_succ', linear_map.ker_comp, linear_map.ker_comp, ih,
β linear_map.ker_comp, linear_map.comp_assoc] },
end
/-- If `p` is an invariant submodule of an endomorphism `f`, then the `ΞΌ`-eigenspace of the
restriction of `f` to `p` is a submodule of the `ΞΌ`-eigenspace of `f`. -/
lemma eigenspace_restrict_le_eigenspace (f : End R M) {p : submodule R M}
(hfp : β x β p, f x β p) (ΞΌ : R) :
(eigenspace (f.restrict hfp) ΞΌ).map p.subtype β€ f.eigenspace ΞΌ :=
begin
rintros a β¨x, hx, rflβ©,
simp only [set_like.mem_coe, mem_eigenspace_iff, linear_map.restrict_apply] at hx β’,
exact congr_arg coe hx
end
/-- Generalized eigenrange and generalized eigenspace for exponent `finrank K V` are disjoint. -/
lemma generalized_eigenvec_disjoint_range_ker [finite_dimensional K V] (f : End K V) (ΞΌ : K) :
disjoint (f.generalized_eigenrange ΞΌ (finrank K V)) (f.generalized_eigenspace ΞΌ (finrank K V)) :=
begin
have h := calc
submodule.comap ((f - algebra_map _ _ ΞΌ) ^ finrank K V)
(f.generalized_eigenspace ΞΌ (finrank K V))
= ((f - algebra_map _ _ ΞΌ) ^ finrank K V *
(f - algebra_map K (End K V) ΞΌ) ^ finrank K V).ker :
by { simpa only [generalized_eigenspace, order_hom.coe_fun_mk, β linear_map.ker_comp] }
... = f.generalized_eigenspace ΞΌ (finrank K V + finrank K V) :
by { rw βpow_add, refl }
... = f.generalized_eigenspace ΞΌ (finrank K V) :
by { rw generalized_eigenspace_eq_generalized_eigenspace_finrank_of_le, linarith },
rw [disjoint, generalized_eigenrange, linear_map.range_eq_map, submodule.map_inf_eq_map_inf_comap,
top_inf_eq, h],
apply submodule.map_comap_le
end
/-- If an invariant subspace `p` of an endomorphism `f` is disjoint from the `ΞΌ`-eigenspace of `f`,
then the restriction of `f` to `p` has trivial `ΞΌ`-eigenspace. -/
lemma eigenspace_restrict_eq_bot {f : End R M} {p : submodule R M}
(hfp : β x β p, f x β p) {ΞΌ : R} (hΞΌp : disjoint (f.eigenspace ΞΌ) p) :
eigenspace (f.restrict hfp) ΞΌ = β₯ :=
begin
rw eq_bot_iff,
intros x hx,
simpa using hΞΌp β¨eigenspace_restrict_le_eigenspace f hfp ΞΌ β¨x, hx, rflβ©, x.propβ©,
end
/-- The generalized eigenspace of an eigenvalue has positive dimension for positive exponents. -/
lemma pos_finrank_generalized_eigenspace_of_has_eigenvalue [finite_dimensional K V]
{f : End K V} {k : β} {ΞΌ : K} (hx : f.has_eigenvalue ΞΌ) (hk : 0 < k):
0 < finrank K (f.generalized_eigenspace ΞΌ k) :=
calc
0 = finrank K (β₯ : submodule K V) : by rw finrank_bot
... < finrank K (f.eigenspace ΞΌ) : submodule.finrank_lt_finrank_of_lt (bot_lt_iff_ne_bot.2 hx)
... β€ finrank K (f.generalized_eigenspace ΞΌ k) :
submodule.finrank_mono ((f.generalized_eigenspace ΞΌ).monotone (nat.succ_le_of_lt hk))
/-- A linear map maps a generalized eigenrange into itself. -/
lemma map_generalized_eigenrange_le {f : End K V} {ΞΌ : K} {n : β} :
submodule.map f (f.generalized_eigenrange ΞΌ n) β€ f.generalized_eigenrange ΞΌ n :=
calc submodule.map f (f.generalized_eigenrange ΞΌ n)
= (f * ((f - algebra_map _ _ ΞΌ) ^ n)).range : (linear_map.range_comp _ _).symm
... = (((f - algebra_map _ _ ΞΌ) ^ n) * f).range : by rw algebra.mul_sub_algebra_map_pow_commutes
... = submodule.map ((f - algebra_map _ _ ΞΌ) ^ n) f.range : linear_map.range_comp _ _
... β€ f.generalized_eigenrange ΞΌ n : linear_map.map_le_range
/-- The generalized eigenvectors span the entire vector space (Lemma 8.21 of [axler2015]). -/
lemma supr_generalized_eigenspace_eq_top [is_alg_closed K] [finite_dimensional K V] (f : End K V) :
(β¨ (ΞΌ : K) (k : β), f.generalized_eigenspace ΞΌ k) = β€ :=
begin
-- We prove the claim by strong induction on the dimension of the vector space.
unfreezingI { induction h_dim : finrank K V using nat.strong_induction_on
with n ih generalizing V },
cases n,
-- If the vector space is 0-dimensional, the result is trivial.
{ rw βtop_le_iff,
simp only [finrank_eq_zero.1 (eq.trans finrank_top h_dim), bot_le] },
-- Otherwise the vector space is nontrivial.
{ haveI : nontrivial V := finrank_pos_iff.1 (by { rw h_dim, apply nat.zero_lt_succ }),
-- Hence, `f` has an eigenvalue `ΞΌβ`.
obtain β¨ΞΌβ, hΞΌββ© : β ΞΌβ, f.has_eigenvalue ΞΌβ := exists_eigenvalue f,
-- We define `ES` to be the generalized eigenspace
let ES := f.generalized_eigenspace ΞΌβ (finrank K V),
-- and `ER` to be the generalized eigenrange.
let ER := f.generalized_eigenrange ΞΌβ (finrank K V),
-- `f` maps `ER` into itself.
have h_f_ER : β (x : V), x β ER β f x β ER,
from Ξ» x hx, map_generalized_eigenrange_le (submodule.mem_map_of_mem hx),
-- Therefore, we can define the restriction `f'` of `f` to `ER`.
let f' : End K ER := f.restrict h_f_ER,
-- The dimension of `ES` is positive
have h_dim_ES_pos : 0 < finrank K ES,
{ dsimp only [ES],
rw h_dim,
apply pos_finrank_generalized_eigenspace_of_has_eigenvalue hΞΌβ (nat.zero_lt_succ n) },
-- and the dimensions of `ES` and `ER` add up to `finrank K V`.
have h_dim_add : finrank K ER + finrank K ES = finrank K V,
{ apply linear_map.finrank_range_add_finrank_ker },
-- Therefore the dimension `ER` mus be smaller than `finrank K V`.
have h_dim_ER : finrank K ER < n.succ, by linarith,
-- This allows us to apply the induction hypothesis on `ER`:
have ih_ER : (β¨ (ΞΌ : K) (k : β), f'.generalized_eigenspace ΞΌ k) = β€,
from ih (finrank K ER) h_dim_ER f' rfl,
-- The induction hypothesis gives us a statement about subspaces of `ER`. We can transfer this
-- to a statement about subspaces of `V` via `submodule.subtype`:
have ih_ER' : (β¨ (ΞΌ : K) (k : β), (f'.generalized_eigenspace ΞΌ k).map ER.subtype) = ER,
by simp only [(submodule.map_supr _ _).symm, ih_ER, submodule.map_subtype_top ER],
-- Moreover, every generalized eigenspace of `f'` is contained in the corresponding generalized
-- eigenspace of `f`.
have hff' : β ΞΌ k,
(f'.generalized_eigenspace ΞΌ k).map ER.subtype β€ f.generalized_eigenspace ΞΌ k,
{ intros,
rw generalized_eigenspace_restrict,
apply submodule.map_comap_le },
-- It follows that `ER` is contained in the span of all generalized eigenvectors.
have hER : ER β€ β¨ (ΞΌ : K) (k : β), f.generalized_eigenspace ΞΌ k,
{ rw β ih_ER',
exact suprβ_mono hff' },
-- `ES` is contained in this span by definition.
have hES : ES β€ β¨ (ΞΌ : K) (k : β), f.generalized_eigenspace ΞΌ k,
from le_trans
(le_supr (Ξ» k, f.generalized_eigenspace ΞΌβ k) (finrank K V))
(le_supr (Ξ» (ΞΌ : K), β¨ (k : β), f.generalized_eigenspace ΞΌ k) ΞΌβ),
-- Moreover, we know that `ER` and `ES` are disjoint.
have h_disjoint : disjoint ER ES,
from generalized_eigenvec_disjoint_range_ker f ΞΌβ,
-- Since the dimensions of `ER` and `ES` add up to the dimension of `V`, it follows that the
-- span of all generalized eigenvectors is all of `V`.
show (β¨ (ΞΌ : K) (k : β), f.generalized_eigenspace ΞΌ k) = β€,
{ rw [βtop_le_iff, βsubmodule.eq_top_of_disjoint ER ES h_dim_add h_disjoint],
apply sup_le hER hES } }
end
end End
end module
|
e768aea7842dc493cb5a0b599a9af8eca914e6fb | 26ac254ecb57ffcb886ff709cf018390161a9225 | /src/topology/algebra/polynomial.lean | 3ab115ad55ec5bcb9273939c004285910656dbb3 | [
"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 | 2,103 | lean | /-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Robert Y. Lewis
Analytic facts about polynomials.
-/
import topology.algebra.ring
import data.polynomial.div
import data.real.cau_seq
open polynomial is_absolute_value
@[nolint ge_or_gt] -- see Note [nolint_ge]
lemma polynomial.tendsto_infinity {Ξ± Ξ² : Type*} [comm_ring Ξ±] [discrete_linear_ordered_field Ξ²]
(abv : Ξ± β Ξ²) [is_absolute_value abv] {p : polynomial Ξ±} (h : 0 < degree p) :
β x : Ξ², β r > 0, β z : Ξ±, r < abv z β x < abv (p.eval z) :=
degree_pos_induction_on p h
(Ξ» a ha x, β¨max (x / abv a) 1, (lt_max_iff.2 (or.inr zero_lt_one)), Ξ» z hz,
by simp [max_lt_iff, div_lt_iff' ((abv_pos abv).2 ha), abv_mul abv] at *; tautoβ©)
(Ξ» p hp ih x, let β¨r, hr0, hrβ© := ih x in
β¨max r 1, lt_max_iff.2 (or.inr zero_lt_one), Ξ» z hz, by rw [eval_mul, eval_X, abv_mul abv];
calc x < abv (p.eval z) : hr _ (max_lt_iff.1 hz).1
... β€ abv (eval z p) * abv z : le_mul_of_ge_one_right
(abv_nonneg _ _) (max_le_iff.1 (le_of_lt hz)).2β©)
(Ξ» p a hp ih x, let β¨r, hr0, hrβ© := ih (x + abv a) in
β¨r, hr0, Ξ» z hz, by rw [eval_add, eval_C, β sub_neg_eq_add];
exact lt_of_lt_of_le (lt_sub_iff_add_lt.2
(by rw abv_neg abv; exact (hr z hz)))
(le_trans (le_abs_self _) (abs_abv_sub_le_abv_sub _ _ _))β©)
lemma polynomial.continuous_eval {Ξ±} [comm_semiring Ξ±] [topological_space Ξ±]
[topological_semiring Ξ±] (p : polynomial Ξ±) : continuous (Ξ» x, p.eval x) :=
begin
apply p.induction,
{ convert continuous_const,
ext, show polynomial.eval x 0 = 0, from rfl },
{ intros a b f haf hb hcts,
simp only [polynomial.eval_add],
refine continuous.add _ hcts,
have : β x, finsupp.sum (finsupp.single a b) (Ξ» (e : β) (a : Ξ±), a * x ^ e) = b * x ^a,
from Ξ» x, finsupp.sum_single_index (by simp),
convert continuous.mul _ _,
{ ext, apply this },
{ apply_instance },
{ apply continuous_const },
{ apply continuous_pow }}
end
|
91e82005781b2d19ce68476163cbce838b71aa4d | d9ed0fce1c218297bcba93e046cb4e79c83c3af8 | /library/tools/super/defs.lean | 0ef5caa3ee9013f1e82dc64e7be6721b2f0476c6 | [
"Apache-2.0"
] | permissive | leodemoura/lean_clone | 005c63aa892a6492f2d4741ee3c2cb07a6be9d7f | cc077554b584d39bab55c360bc12a6fe7957afe6 | refs/heads/master | 1,610,506,475,484 | 1,482,348,354,000 | 1,482,348,543,000 | 77,091,586 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 1,205 | lean | /-
Copyright (c) 2016 Gabriel Ebner. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Gabriel Ebner
-/
import .clause_ops .prover_state
open tactic expr monad
namespace super
-- FIXME: how to cleanly unfold one level of definitions?
-- what should one level even be? consider dvd->has_dvd->nat_has_dvd->...
meta def try_unfold_one_def (type : expr) : tactic expr := do
whnf type
meta def try_unfold_def_left (c : clause) (i : β) : tactic (list clause) :=
on_left_at c i $ Ξ»t, do
t' β try_unfold_one_def t,
ht' β mk_local_def `h t',
return [([ht'], ht')]
meta def try_unfold_def_right (c : clause) (i : β) : tactic (list clause) :=
on_right_at c i $ Ξ»h, do
t' β try_unfold_one_def h^.local_type,
hnt' β mk_local_def `h (imp t' c^.local_false),
return [([hnt'], app hnt' h)]
@[super.inf]
meta def unfold_def_inf : inf_decl := inf_decl.mk 40 $ take given, sequence' $ do
r β [try_unfold_def_right, try_unfold_def_left],
-- NOTE: we cannot restrict to selected literals here
-- as this might prevent factoring, e.g. _n>0_ β¨ is_pos(0)
i β list.range given^.c^.num_lits,
[inf_if_successful 3 given (r given^.c i)]
end super
|
2271421233234e80ee1626e5932fd5f69995ed8a | 510e96af568b060ed5858226ad954c258549f143 | /data/set/finite.lean | a8349438ab2067fc7a5203b4cafcbb65f795a7e8 | [] | 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 | 2,214 | 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
Finite sets -- assuming a classical logic.
-/
import .basic
noncomputable theory
universes u v w
variables {Ξ± : Type u} {Ξ² : Type v} {ΞΉ : Sort w}
open set lattice
namespace set
/-
local attribute [instance] classical.decidable_inhabited
local attribute [instance] classical.prop_decidable
-/
inductive finite : set Ξ± β Prop
| empty : finite β
| insert : βa s, a β s β finite s β finite (insert a s)
attribute [simp] finite.empty
@[simp]
lemma finite_insert {a : Ξ±} {s : set Ξ±} (h : finite s) : finite (insert a s) :=
classical.by_cases
(suppose a β s, by simp [*])
(suppose a β s, finite.insert a s this h)
@[simp]
lemma finite_singleton {a : Ξ±} : finite ({a} : set Ξ±) :=
finite_insert finite.empty
lemma finite_union {s t : set Ξ±} (hs : finite s) (ht : finite t) : finite (s βͺ t) :=
finite.drec_on ht (by simp [hs]) $ assume a t _ _, by simp; exact finite_insert
lemma finite_subset {s : set Ξ±} (hs : finite s) : β{t}, t β s β finite t :=
begin
induction hs with a t' ha ht' ih,
{ intros t ht, simp [(subset_empty_iff t)^.mp ht, finite.empty] },
{ intros t ht,
have tm : finite (t \ {a}) :=
(ih $ show t \ {a} β t',
from assume x β¨hxt, hnaβ©, or.resolve_left (ht hxt) (by simp at hna; assumption)),
cases (classical.em $ a β t) with ha hna,
{ exact have finite (insert a (t \ {a})), from finite_insert tm,
show finite t,
by simp [ha] at this; assumption },
{ simp [sdiff_singleton_eq_same, hna] at tm, exact tm } }
end
lemma finite_image {s : set Ξ±} {f : Ξ± β Ξ²} (h : finite s) : finite (f '' s) :=
begin
induction h with a s' hns' hs' hi,
simp [image_empty, finite.empty],
simp [image_insert_eq, finite_insert, hi]
end
lemma finite_sUnion {s : set (set Ξ±)} (h : finite s) : (βtβs, finite t) β finite (ββ s) :=
begin
induction h with a s' hns' hs' hi,
{ simp [finite.empty] },
{ intro h,
simp,
apply finite_union,
{ apply h, simp },
{ exact (hi $ assume t ht, h _ $ mem_insert_of_mem _ ht) } }
end
end set
|
ca45869d6bac7ac0e77ea2c1f1838d5d9a6ad998 | 26ac254ecb57ffcb886ff709cf018390161a9225 | /src/ring_theory/adjoin.lean | 342ff688de680f39f7bde59e531fec70378bee1b | [
"Apache-2.0"
] | permissive | eric-wieser/mathlib | 42842584f584359bbe1fc8b88b3ff937c8acd72d | d0df6b81cd0920ad569158c06a3fd5abb9e63301 | refs/heads/master | 1,669,546,404,255 | 1,595,254,668,000 | 1,595,254,668,000 | 281,173,504 | 0 | 0 | Apache-2.0 | 1,595,263,582,000 | 1,595,263,581,000 | null | UTF-8 | Lean | false | false | 8,707 | lean | /-
Copyright (c) 2019 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau
Adjoining elements to form subalgebras.
-/
import ring_theory.polynomial
import ring_theory.principal_ideal_domain
universes u v w
open submodule
namespace algebra
variables {R : Type u} {A : Type v}
section semiring
variables [comm_semiring R] [semiring A]
variables [algebra R A] {s t : set A}
open subsemiring
theorem subset_adjoin : s β adjoin R s :=
set.subset.trans (set.subset_union_right _ _) subset_closure
theorem adjoin_le {S : subalgebra R A} (H : s β S) : adjoin R s β€ S :=
closure_le.2 $ set.union_subset S.range_le H
theorem adjoin_le_iff {S : subalgebra R A} : adjoin R s β€ S β s β S:=
β¨set.subset.trans subset_adjoin, adjoin_leβ©
theorem adjoin_mono (H : s β t) : adjoin R s β€ adjoin R t :=
closure_le.2 (set.subset.trans (set.union_subset_union_right _ H) subset_closure)
variables (R A)
@[simp] theorem adjoin_empty : adjoin R (β
: set A) = β₯ :=
eq_bot_iff.2 $ adjoin_le $ set.empty_subset _
variables (R) {A} (s)
theorem adjoin_eq_span : (adjoin R s : submodule R A) = span R (monoid.closure s) :=
begin
apply le_antisymm,
{ intros r hr, rcases mem_closure_iff_exists_list.1 hr with β¨L, HL, rflβ©, clear hr,
induction L with hd tl ih, { exact zero_mem _ },
rw list.forall_mem_cons at HL,
rw [list.map_cons, list.sum_cons],
refine submodule.add_mem _ _ (ih HL.2),
replace HL := HL.1, clear ih tl,
suffices : β z r (hr : r β monoid.closure s), has_scalar.smul.{u v} z r = list.prod hd,
{ rcases this with β¨z, r, hr, hzrβ©, rw β hzr,
exact smul_mem _ _ (subset_span hr) },
induction hd with hd tl ih, { exact β¨1, 1, is_submonoid.one_mem, one_smul _ _β© },
rw list.forall_mem_cons at HL,
rcases (ih HL.2) with β¨z, r, hr, hzrβ©, rw [list.prod_cons, β hzr],
rcases HL.1 with β¨hd, rflβ© | hs,
{ refine β¨hd * z, r, hr, _β©,
rw [smul_def, smul_def, (algebra_map _ _).map_mul, _root_.mul_assoc] },
{ exact β¨z, hd * r, is_submonoid.mul_mem (monoid.subset_closure hs) hr,
(mul_smul_comm _ _ _).symmβ© } },
exact span_le.2 (show monoid.closure s β adjoin R s, from monoid.closure_subset subset_adjoin)
end
end semiring
section comm_semiring
variables [comm_semiring R] [comm_semiring A]
variables [algebra R A] {s t : set A}
open subsemiring
variables (R s t)
theorem adjoin_union : adjoin R (s βͺ t) = (adjoin R s).under (adjoin (adjoin R s) t) :=
le_antisymm
(closure_mono $ set.union_subset
(set.range_subset_iff.2 $ Ξ» r, or.inl β¨algebra_map R (adjoin R s) r, rflβ©)
(set.union_subset_union_left _ $ Ξ» x hxs, β¨β¨_, subset_adjoin hxsβ©, rflβ©))
(closure_le.2 $ set.union_subset
(set.range_subset_iff.2 $ Ξ» x, adjoin_mono (set.subset_union_left _ _) x.2)
(set.subset.trans (set.subset_union_right _ _) subset_adjoin))
theorem adjoin_eq_range :
adjoin R s = (mv_polynomial.aeval R A (coe : s β A)).range :=
le_antisymm
(adjoin_le $ Ξ» x hx, β¨mv_polynomial.X β¨x, hxβ©, mv_polynomial.evalβ_X _ _ _β©)
(Ξ» x β¨p, hpβ©, hp βΈ mv_polynomial.induction_on p
(Ξ» r, by rw [mv_polynomial.aeval_def, mv_polynomial.evalβ_C]; exact (adjoin R s).2 r)
(Ξ» p q hp hq, by rw alg_hom.map_add; exact is_add_submonoid.add_mem hp hq)
(Ξ» p β¨n, hnβ© hp, by rw [alg_hom.map_mul, mv_polynomial.aeval_def _ _ _ (mv_polynomial.X _),
mv_polynomial.evalβ_X]; exact is_submonoid.mul_mem hp (subset_adjoin hn)))
theorem adjoin_singleton_eq_range (x : A) : adjoin R {x} = (polynomial.aeval R A x).range :=
le_antisymm
(adjoin_le $ set.singleton_subset_iff.2 β¨polynomial.X, polynomial.evalβ_X _ _β©)
(Ξ» y β¨p, hpβ©, hp βΈ polynomial.induction_on p
(Ξ» r, by rw [polynomial.aeval_def, polynomial.evalβ_C]; exact (adjoin R _).2 r)
(Ξ» p q hp hq, by rw alg_hom.map_add; exact is_add_submonoid.add_mem hp hq)
(Ξ» n r ih, by { rw [pow_succ', β mul_assoc, alg_hom.map_mul,
polynomial.aeval_def _ polynomial.X, polynomial.evalβ_X],
exact is_submonoid.mul_mem ih (subset_adjoin rfl) }))
theorem adjoin_union_coe_submodule : (adjoin R (s βͺ t) : submodule R A) =
(adjoin R s) * (adjoin R t) :=
begin
rw [adjoin_eq_span, adjoin_eq_span, adjoin_eq_span, span_mul_span],
congr' 1, ext z, simp [monoid.mem_closure_union_iff, set.mem_mul],
end
end comm_semiring
section ring
variables [comm_ring R] [ring A]
variables [algebra R A] {s t : set A}
variables {R s t}
open ring
theorem adjoin_int (s : set R) : adjoin β€ s = subalgebra_of_subring (closure s) :=
le_antisymm (adjoin_le subset_closure) (closure_subset subset_adjoin)
theorem mem_adjoin_iff {s : set A} {x : A} :
x β adjoin R s β x β closure (set.range (algebra_map R A) βͺ s) :=
β¨Ξ» hx, subsemiring.closure_induction hx subset_closure is_add_submonoid.zero_mem
is_submonoid.one_mem (Ξ» _ _, is_add_submonoid.add_mem) (Ξ» _ _, is_submonoid.mul_mem),
suffices closure (set.range β(algebra_map R A) βͺ s) β adjoin R s, from @this x,
closure_subset subsemiring.subset_closureβ©
theorem adjoin_eq_ring_closure (s : set A) :
(adjoin R s : set A) = closure (set.range (algebra_map R A) βͺ s) :=
set.ext $ Ξ» x, mem_adjoin_iff
end ring
section comm_ring
variables [comm_ring R] [comm_ring A]
variables [algebra R A] {s t : set A}
variables {R s t}
open ring
theorem fg_trans (h1 : (adjoin R s : submodule R A).fg)
(h2 : (adjoin (adjoin R s) t : submodule (adjoin R s) A).fg) :
(adjoin R (s βͺ t) : submodule R A).fg :=
begin
rcases fg_def.1 h1 with β¨p, hp, hp'β©,
rcases fg_def.1 h2 with β¨q, hq, hq'β©,
refine fg_def.2 β¨p * q, hp.mul hq, le_antisymm _ _β©,
{ rw [span_le],
rintros _ β¨x, y, hx, hy, rflβ©,
change x * y β _,
refine is_submonoid.mul_mem _ _,
{ have : x β (adjoin R s : submodule R A),
{ rw β hp', exact subset_span hx },
exact adjoin_mono (set.subset_union_left _ _) this },
have : y β (adjoin (adjoin R s) t : submodule (adjoin R s) A),
{ rw β hq', exact subset_span hy },
change y β adjoin R (s βͺ t), rwa adjoin_union },
{ intros r hr,
change r β adjoin R (s βͺ t) at hr,
rw adjoin_union at hr,
change r β (adjoin (adjoin R s) t : submodule (adjoin R s) A) at hr,
haveI := classical.dec_eq A,
haveI := classical.dec_eq R,
rw [β hq', β set.image_id q, finsupp.mem_span_iff_total (adjoin R s)] at hr,
rcases hr with β¨l, hlq, rflβ©,
have := @finsupp.total_apply A A (adjoin R s),
rw [this, finsupp.sum],
refine sum_mem _ _,
intros z hz, change (l z).1 * _ β _,
have : (l z).1 β (adjoin R s : submodule R A) := (l z).2,
rw [β hp', β set.image_id p, finsupp.mem_span_iff_total R] at this,
rcases this with β¨l2, hlp, hlβ©,
have := @finsupp.total_apply A A R,
rw this at hl,
rw [βhl, finsupp.sum_mul],
refine sum_mem _ _,
intros t ht, change _ * _ β _, rw smul_mul_assoc, refine smul_mem _ _ _,
exact subset_span β¨t, z, hlp ht, hlq hz, rflβ© }
end
end comm_ring
end algebra
namespace subalgebra
variables {R : Type u} {A : Type v}
variables [comm_ring R] [comm_ring A] [algebra R A]
/-- A subalgebra `S` is finitely generated if there exists `t : finset A` such that
`algebra.adjoin R t = S`. -/
def fg (S : subalgebra R A) : Prop :=
β t : finset A, algebra.adjoin R βt = S
theorem fg_def {S : subalgebra R A} : S.fg β β t : set A, set.finite t β§ algebra.adjoin R t = S :=
β¨Ξ» β¨t, htβ©, β¨βt, set.finite_mem_finset t, htβ©,
Ξ» β¨t, ht1, ht2β©, β¨ht1.to_finset, by rwa set.finite.coe_to_finsetβ©β©
theorem fg_bot : (β₯ : subalgebra R A).fg :=
β¨β
, algebra.adjoin_empty R Aβ©
end subalgebra
variables {R : Type u} {A : Type v} {B : Type w}
variables [comm_ring R] [comm_ring A] [comm_ring B] [algebra R A] [algebra R B]
instance alg_hom.is_noetherian_ring_range (f : A ββ[R] B) [is_noetherian_ring A] :
is_noetherian_ring f.range :=
is_noetherian_ring_range f.to_ring_hom
theorem is_noetherian_ring_of_fg {S : subalgebra R A} (HS : S.fg)
[is_noetherian_ring R] : is_noetherian_ring S :=
let β¨t, htβ© := HS in ht βΈ (algebra.adjoin_eq_range R (βt : set A)).symm βΈ
by haveI : is_noetherian_ring (mv_polynomial (βt : set A) R) :=
mv_polynomial.is_noetherian_ring;
convert alg_hom.is_noetherian_ring_range _; apply_instance
theorem is_noetherian_ring_closure (s : set R) (hs : s.finite) :
is_noetherian_ring (ring.closure s) :=
show is_noetherian_ring (subalgebra_of_subring (ring.closure s)), from
algebra.adjoin_int s βΈ is_noetherian_ring_of_fg (subalgebra.fg_def.2 β¨s, hs, rflβ©)
|
93d49feb3893315257cfb86ab5b60309bc139e25 | 4727251e0cd73359b15b664c3170e5d754078599 | /src/data/rbmap/default.lean | c565e084d5c7497b4757ffed159211b573b15b70 | [
"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 | 15,086 | lean | /-
Copyright (c) 2017 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
import data.rbtree
import data.rbmap.basic
universes u v
namespace rbmap
variables {Ξ± : Type u} {Ξ² : Type v} {lt : Ξ± β Ξ± β Prop}
/- Auxiliary instances -/
private def rbmap_lt_is_swo {Ξ± : Type u} {Ξ² : Type v} {lt : Ξ± β Ξ± β Prop}
[is_strict_weak_order Ξ± lt] : is_strict_weak_order (Ξ± Γ Ξ²) (rbmap_lt lt) :=
{ irrefl := Ξ» _, irrefl_of lt _,
trans := Ξ» _ _ _ hβ hβ, trans_of lt hβ hβ,
incomp_trans := Ξ» _ _ _ hβ hβ, incomp_trans_of lt hβ hβ }
private def rbmap_lt_dec {Ξ± : Type u} {Ξ² : Type v} {lt : Ξ± β Ξ± β Prop} [h : decidable_rel lt] :
decidable_rel (@rbmap_lt Ξ± Ξ² lt) :=
Ξ» a b, h a.1 b.1
local attribute [instance] rbmap_lt_is_swo rbmap_lt_dec
/- Helper lemmas for reusing rbtree results. -/
private lemma to_rbtree_mem {k : Ξ±} {m : rbmap Ξ± Ξ² lt} : k β m β β v : Ξ², rbtree.mem (k, v) m :=
begin
cases m with n p; cases n; intros h,
{ exact false.elim h },
all_goals { existsi n_val.2, exact h }
end
private lemma eqv_entries_of_eqv_keys {kβ kβ : Ξ±} (vβ vβ : Ξ²) :
kβ β[lt] kβ β (kβ, vβ) β[rbmap_lt lt] (kβ, vβ) :=
id
private lemma eqv_keys_of_eqv_entries {kβ kβ : Ξ±} {vβ vβ : Ξ²} :
(kβ, vβ) β[rbmap_lt lt] (kβ, vβ) β kβ β[lt] kβ :=
id
private lemma eqv_entries [is_irrefl Ξ± lt] (k : Ξ±) (vβ vβ : Ξ²) : (k, vβ) β[rbmap_lt lt] (k, vβ) :=
and.intro (irrefl_of lt k) (irrefl_of lt k)
private lemma to_rbmap_mem [is_strict_weak_order Ξ± lt] {k : Ξ±} {v : Ξ²} {m : rbmap Ξ± Ξ² lt} :
rbtree.mem (k, v) m β k β m :=
begin
cases m with n p; cases n; intros h,
{ exact false.elim h },
{ simp [has_mem.mem, rbmap.mem],
exact @rbtree.mem_of_mem_of_eqv _ _ _ β¨rbnode.red_node n_lchild n_val n_rchild, pβ© _ _ h
(eqv_entries _ _ _) },
{ simp [has_mem.mem, rbmap.mem],
exact @rbtree.mem_of_mem_of_eqv _ _ _ β¨rbnode.black_node n_lchild n_val n_rchild, pβ© _ _ h
(eqv_entries _ _ _) }
end
private lemma to_rbtree_mem' [is_strict_weak_order Ξ± lt] {k : Ξ±} {m : rbmap Ξ± Ξ² lt} (v : Ξ²) :
k β m β rbtree.mem (k, v) m :=
begin
intro h,
cases to_rbtree_mem h with v' hm,
apply rbtree.mem_of_mem_of_eqv hm,
apply eqv_entries
end
lemma eq_some_of_to_value_eq_some {e : option (Ξ± Γ Ξ²)} {v : Ξ²} :
to_value e = some v β β k, e = some (k, v) :=
begin
cases e with val; simp [to_value, false_implies_iff],
{ cases val, simp, intro h, subst v, constructor, refl }
end
lemma eq_none_of_to_value_eq_none {e : option (Ξ± Γ Ξ²)} : to_value e = none β e = none :=
by cases e; simp [to_value, false_implies_iff]
/- Lemmas -/
lemma not_mem_mk_rbmap : β (k : Ξ±), k β mk_rbmap Ξ± Ξ² lt :=
by simp [has_mem.mem, mk_rbmap, mk_rbtree, rbmap.mem]
lemma not_mem_of_empty {m : rbmap Ξ± Ξ² lt} (k : Ξ±) : m.empty = tt β k β m :=
by cases m with n p; cases n;
simp [has_mem.mem, mk_rbmap, mk_rbtree, rbmap.mem, rbmap.empty, rbtree.empty, false_implies_iff]
lemma mem_of_mem_of_eqv [is_strict_weak_order Ξ± lt] {m : rbmap Ξ± Ξ² lt} {kβ kβ : Ξ±} :
kβ β m β kβ β[lt] kβ β kβ β m :=
begin
intros hβ hβ,
have hβ := to_rbtree_mem hβ, cases hβ with v hβ,
exact to_rbmap_mem (rbtree.mem_of_mem_of_eqv hβ (eqv_entries_of_eqv_keys v v hβ))
end
section decidable
variables [decidable_rel lt]
lemma not_mem_of_find_entry_none [is_strict_weak_order Ξ± lt] {k : Ξ±} {m : rbmap Ξ± Ξ² lt} :
m.find_entry k = none β k β m :=
begin
cases m with t p, cases t; simp [find_entry],
{ intros, simp [has_mem.mem, rbmap.mem] },
all_goals { intro h, exact rbtree.not_mem_of_find_none h, }
end
lemma not_mem_of_find_none [is_strict_weak_order Ξ± lt] {k : Ξ±} {m : rbmap Ξ± Ξ² lt} :
m.find k = none β k β m :=
begin
simp [find], intro h,
have := eq_none_of_to_value_eq_none h,
exact not_mem_of_find_entry_none this
end
lemma mem_of_find_entry_some [is_strict_weak_order Ξ± lt] {kβ : Ξ±} {e : Ξ± Γ Ξ²} {m : rbmap Ξ± Ξ² lt} :
m.find_entry kβ = some e β kβ β m :=
begin
cases m with t p, cases t; simp [find_entry, false_implies_iff],
all_goals { intro h, exact rbtree.mem_of_find_some h }
end
lemma mem_of_find_some [is_strict_weak_order Ξ± lt] {k : Ξ±} {v : Ξ²} {m : rbmap Ξ± Ξ² lt} :
m.find k = some v β k β m :=
begin
simp [find], intro h,
have := eq_some_of_to_value_eq_some h,
cases this with _ he,
exact mem_of_find_entry_some he
end
lemma find_entry_eq_find_entry_of_eqv [is_strict_weak_order Ξ± lt] {m : rbmap Ξ± Ξ² lt} {kβ kβ : Ξ±} :
kβ β[lt] kβ β m.find_entry kβ = m.find_entry kβ :=
begin
intro h, cases m with t p, cases t; simp [find_entry],
all_goals { apply rbtree.find_eq_find_of_eqv, apply eqv_entries_of_eqv_keys, assumption }
end
lemma find_eq_find_of_eqv [is_strict_weak_order Ξ± lt] {kβ kβ : Ξ±} (m : rbmap Ξ± Ξ² lt) :
kβ β[lt] kβ β m.find kβ = m.find kβ :=
begin intro h, simp [find], apply congr_arg, apply find_entry_eq_find_entry_of_eqv, assumption end
lemma find_entry_correct [is_strict_weak_order Ξ± lt] (k : Ξ±) (m : rbmap Ξ± Ξ² lt) :
k β m β (β e, m.find_entry k = some e β§ k β[lt] e.1) :=
begin
apply iff.intro; cases m with t p,
{ intro h,
have h := to_rbtree_mem h, cases h with v hβ,
have hex := iff.mp (rbtree.find_correct _ _) hβ, cases hex with e hβ,
existsi e, cases t; simp [find_entry] at β’ hβ,
{ simp [rbtree.find, rbnode.find] at hβ, cases hβ },
{ cases hβ with hββ hββ, split,
{ have := rbtree.find_eq_find_of_eqv β¨rbnode.red_node t_lchild t_val t_rchild, pβ©
(eqv_entries k v t_val.2),
rw [βthis], exact hββ },
{ cases e, apply eqv_keys_of_eqv_entries hββ } },
{ cases hβ with hββ hββ, split,
{ have := rbtree.find_eq_find_of_eqv β¨rbnode.black_node t_lchild t_val t_rchild, pβ©
(eqv_entries k v t_val.2),
rw [βthis], exact hββ },
{ cases e, apply eqv_keys_of_eqv_entries hββ } } },
{ intro h, cases h with e h,
cases h with hβ hβ, cases t; simp [find_entry] at hβ,
{ contradiction },
all_goals { exact to_rbmap_mem (rbtree.mem_of_find_some hβ) } }
end
lemma eqv_of_find_entry_some [is_strict_weak_order Ξ± lt] {kβ kβ : Ξ±} {v : Ξ²} {m : rbmap Ξ± Ξ² lt} :
m.find_entry kβ = some (kβ, v) β kβ β[lt] kβ :=
begin
cases m with t p, cases t; simp [find_entry, false_implies_iff],
all_goals { intro h, exact eqv_keys_of_eqv_entries (rbtree.eqv_of_find_some h) }
end
lemma eq_of_find_entry_some [is_strict_total_order Ξ± lt] {kβ kβ : Ξ±} {v : Ξ²} {m : rbmap Ξ± Ξ² lt} :
m.find_entry kβ = some (kβ, v) β kβ = kβ :=
Ξ» h, suffices kβ β[lt] kβ, from eq_of_eqv_lt this,
eqv_of_find_entry_some h
lemma find_correct [is_strict_weak_order Ξ± lt] (k : Ξ±) (m : rbmap Ξ± Ξ² lt) :
k β m β β v, m.find k = some v :=
begin
apply iff.intro,
{ intro h,
have := iff.mp (find_entry_correct k m) h,
cases this with e h, cases h with hβ hβ,
existsi e.2, simp [find, hβ, to_value] },
{ intro h,
cases h with v h,
simp [find] at h,
have h := eq_some_of_to_value_eq_some h,
cases h with k' h,
have heqv := eqv_of_find_entry_some h,
exact iff.mpr (find_entry_correct k m) β¨(k', v), β¨h, heqvβ©β© }
end
lemma constains_correct [is_strict_weak_order Ξ± lt] (k : Ξ±) (m : rbmap Ξ± Ξ² lt) :
k β m β m.contains k = tt :=
begin
apply iff.intro,
{ intro h,
have h := iff.mp (find_entry_correct k m) h,
cases h with e h, cases h with hβ hβ,
simp [contains, hβ, option.is_some] },
{ simp [contains],
intro h,
generalize he : find_entry m k = e,
cases e,
{ simp [he, option.is_some] at h, contradiction },
{ exact mem_of_find_entry_some he } }
end
lemma mem_insert_of_incomp [is_strict_weak_order Ξ± lt] {kβ kβ : Ξ±} (m : rbmap Ξ± Ξ² lt) (v : Ξ²) :
(Β¬ lt kβ kβ β§ Β¬ lt kβ kβ) β kβ β m.insert kβ v :=
Ξ» h, to_rbmap_mem (rbtree.mem_insert_of_incomp m (eqv_entries_of_eqv_keys v v h))
lemma mem_insert [is_strict_weak_order Ξ± lt] (k : Ξ±) (m : rbmap Ξ± Ξ² lt) (v : Ξ²) :
k β m.insert k v :=
to_rbmap_mem (rbtree.mem_insert (k, v) m)
lemma mem_insert_of_equiv [is_strict_weak_order Ξ± lt] {kβ kβ : Ξ±} (m : rbmap Ξ± Ξ² lt) (v : Ξ²) :
kβ β[lt] kβ β kβ β m.insert kβ v :=
mem_insert_of_incomp m v
lemma mem_insert_of_mem [is_strict_weak_order Ξ± lt] {kβ : Ξ±} {m : rbmap Ξ± Ξ² lt} (kβ : Ξ±) (v : Ξ²) :
kβ β m β kβ β m.insert kβ v :=
Ξ» h, to_rbmap_mem (rbtree.mem_insert_of_mem (kβ, v) (to_rbtree_mem' v h))
lemma equiv_or_mem_of_mem_insert [is_strict_weak_order Ξ± lt] {kβ kβ : Ξ±} {v : Ξ²}
{m : rbmap Ξ± Ξ² lt} : kβ β m.insert kβ v β kβ β[lt] kβ β¨ kβ β m :=
Ξ» h, or.elim (rbtree.equiv_or_mem_of_mem_insert (to_rbtree_mem' v h))
(Ξ» h, or.inl (eqv_keys_of_eqv_entries h))
(Ξ» h, or.inr (to_rbmap_mem h))
lemma incomp_or_mem_of_mem_ins [is_strict_weak_order Ξ± lt] {kβ kβ : Ξ±} {v : Ξ²} {m : rbmap Ξ± Ξ² lt} :
kβ β m.insert kβ v β (Β¬ lt kβ kβ β§ Β¬ lt kβ kβ) β¨ kβ β m :=
equiv_or_mem_of_mem_insert
lemma eq_or_mem_of_mem_ins [is_strict_total_order Ξ± lt] {kβ kβ : Ξ±} {v : Ξ²} {m : rbmap Ξ± Ξ² lt} :
kβ β m.insert kβ v β kβ = kβ β¨ kβ β m :=
Ξ» h, suffices kβ β[lt] kβ β¨ kβ β m, by simp [eqv_lt_iff_eq] at this; assumption,
incomp_or_mem_of_mem_ins h
lemma find_entry_insert_of_eqv [is_strict_weak_order Ξ± lt] (m : rbmap Ξ± Ξ² lt) {kβ kβ : Ξ±} (v : Ξ²) :
kβ β[lt] kβ β (m.insert kβ v).find_entry kβ = some (kβ, v) :=
begin
intro h,
generalize hβ : m.insert kβ v = m',
cases m' with t p, cases t,
{ have := mem_insert kβ m v, rw [hβ] at this, apply absurd this, apply not_mem_mk_rbmap },
all_goals { simp [find_entry], rw [βhβ, insert], apply rbtree.find_insert_of_eqv,
apply eqv_entries_of_eqv_keys _ _ h }
end
lemma find_entry_insert [is_strict_weak_order Ξ± lt] (m : rbmap Ξ± Ξ² lt) (k : Ξ±) (v : Ξ²) :
(m.insert k v).find_entry k = some (k, v) :=
find_entry_insert_of_eqv m v (refl k)
lemma find_insert_of_eqv [is_strict_weak_order Ξ± lt] (m : rbmap Ξ± Ξ² lt) {kβ kβ : Ξ±} (v : Ξ²) :
kβ β[lt] kβ β (m.insert kβ v).find kβ = some v :=
begin
intro h,
have := find_entry_insert_of_eqv m v h,
simp [find, this, to_value]
end
lemma find_insert [is_strict_weak_order Ξ± lt] (m : rbmap Ξ± Ξ² lt) (k : Ξ±) (v : Ξ²) :
(m.insert k v).find k = some v :=
find_insert_of_eqv m v (refl k)
lemma find_entry_insert_of_disj [is_strict_weak_order Ξ± lt] {kβ kβ : Ξ±} (m : rbmap Ξ± Ξ² lt) (v : Ξ²) :
lt kβ kβ β¨ lt kβ kβ β (m.insert kβ v).find_entry kβ = m.find_entry kβ :=
begin
intro h,
have h' : β {vβ vβ : Ξ²}, (rbmap_lt lt) (kβ, vβ) (kβ, vβ) β¨ (rbmap_lt lt) (kβ, vβ) (kβ, vβ) :=
Ξ» _ _, h,
generalize hβ : m = mβ,
generalize hβ : insert mβ kβ v = mβ,
rw [βhβ] at hβ β’, rw [βhβ],
cases mβ with tβ pβ; cases tβ; cases mβ with tβ pβ; cases tβ,
{ rw [hβ, hβ] },
iterate 2
{ rw [hβ],
conv { to_lhs, simp [find_entry] },
rw [βhβ, insert, rbtree.find_insert_of_disj _ h', hβ],
refl },
any_goals { simp [insert] at hβ,
exact absurd hβ (rbtree.insert_ne_mk_rbtree m (kβ, v)) },
any_goals
{ rw [hβ, hβ], simp [find_entry], rw [βhβ, βhβ, insert, rbtree.find_insert_of_disj _ h'],
apply rbtree.find_eq_find_of_eqv, apply eqv_entries }
end
lemma find_entry_insert_of_not_eqv [is_strict_weak_order Ξ± lt] {kβ kβ : Ξ±} (m : rbmap Ξ± Ξ² lt)
(v : Ξ²) : Β¬ kβ β[lt] kβ β (m.insert kβ v).find_entry kβ = m.find_entry kβ :=
begin
intro hn,
have he : lt kβ kβ β¨ lt kβ kβ,
{ simp [strict_weak_order.equiv, decidable.not_and_iff_or_not, decidable.not_not_iff] at hn,
assumption },
apply find_entry_insert_of_disj _ _ he
end
lemma find_entry_insert_of_ne [is_strict_total_order Ξ± lt] {kβ kβ : Ξ±} (m : rbmap Ξ± Ξ² lt) (v : Ξ²) :
kβ β kβ β (m.insert kβ v).find_entry kβ = m.find_entry kβ :=
begin
intro h,
have : Β¬ kβ β[lt] kβ := Ξ» h', h (eq_of_eqv_lt h'),
apply find_entry_insert_of_not_eqv _ _ this
end
lemma find_insert_of_disj [is_strict_weak_order Ξ± lt] {kβ kβ : Ξ±} (m : rbmap Ξ± Ξ² lt) (v : Ξ²) :
lt kβ kβ β¨ lt kβ kβ β (m.insert kβ v).find kβ = m.find kβ :=
begin intro h, have := find_entry_insert_of_disj m v h, simp [find, this] end
lemma find_insert_of_not_eqv [is_strict_weak_order Ξ± lt] {kβ kβ : Ξ±} (m : rbmap Ξ± Ξ² lt) (v : Ξ²) :
Β¬ kβ β[lt] kβ β (m.insert kβ v).find kβ = m.find kβ :=
begin intro h, have := find_entry_insert_of_not_eqv m v h, simp [find, this] end
lemma find_insert_of_ne [is_strict_total_order Ξ± lt] {kβ kβ : Ξ±} (m : rbmap Ξ± Ξ² lt) (v : Ξ²) :
kβ β kβ β (m.insert kβ v).find kβ = m.find kβ :=
begin intro h, have := find_entry_insert_of_ne m v h, simp [find, this] end
end decidable
lemma mem_of_min_eq [is_strict_total_order Ξ± lt] {k : Ξ±} {v : Ξ²} {m : rbmap Ξ± Ξ² lt} :
m.min = some (k, v) β k β m :=
Ξ» h, to_rbmap_mem (rbtree.mem_of_min_eq h)
lemma mem_of_max_eq [is_strict_total_order Ξ± lt] {k : Ξ±} {v : Ξ²} {m : rbmap Ξ± Ξ² lt} :
m.max = some (k, v) β k β m :=
Ξ» h, to_rbmap_mem (rbtree.mem_of_max_eq h)
lemma eq_leaf_of_min_eq_none {m : rbmap Ξ± Ξ² lt} :
m.min = none β m = mk_rbmap Ξ± Ξ² lt :=
rbtree.eq_leaf_of_min_eq_none
lemma eq_leaf_of_max_eq_none {m : rbmap Ξ± Ξ² lt} :
m.max = none β m = mk_rbmap Ξ± Ξ² lt :=
rbtree.eq_leaf_of_max_eq_none
lemma min_is_minimal [is_strict_weak_order Ξ± lt] {k : Ξ±} {v : Ξ²} {m : rbmap Ξ± Ξ² lt} :
m.min = some (k, v) β β {k'}, k' β m β k β[lt] k' β¨ lt k k' :=
Ξ» h k' hm, or.elim (rbtree.min_is_minimal h (to_rbtree_mem' v hm))
(Ξ» h, or.inl (eqv_keys_of_eqv_entries h))
(Ξ» h, or.inr h)
lemma max_is_maximal [is_strict_weak_order Ξ± lt] {k : Ξ±} {v : Ξ²} {m : rbmap Ξ± Ξ² lt} :
m.max = some (k, v) β β {k'}, k' β m β k β[lt] k' β¨ lt k' k :=
Ξ» h k' hm, or.elim (rbtree.max_is_maximal h (to_rbtree_mem' v hm))
(Ξ» h, or.inl (eqv_keys_of_eqv_entries h))
(Ξ» h, or.inr h)
lemma min_is_minimal_of_total [is_strict_total_order Ξ± lt] {k : Ξ±} {v : Ξ²} {m : rbmap Ξ± Ξ² lt} :
m.min = some (k, v) β β {k'}, k' β m β k = k' β¨ lt k k' :=
Ξ» h k' hm,
match min_is_minimal h hm with
| or.inl h := or.inl (eq_of_eqv_lt h)
| or.inr h := or.inr h
end
lemma max_is_maximal_of_total [is_strict_total_order Ξ± lt] {k : Ξ±} {v : Ξ²} {m : rbmap Ξ± Ξ² lt} :
m.max = some (k, v) β β {k'}, k' β m β k = k' β¨ lt k' k :=
Ξ» h k' hm,
match max_is_maximal h hm with
| or.inl h := or.inl (eq_of_eqv_lt h)
| or.inr h := or.inr h
end
end rbmap
|
b98e8d3f1a310a8eb7bbe15428cfcc99ea209407 | dd0f5513e11c52db157d2fcc8456d9401a6cd9da | /12_Axioms.org.12.lean | 7efda64ecc078f641fe0d47963994200626aec6e | [] | no_license | cjmazey/lean-tutorial | ba559a49f82aa6c5848b9bf17b7389bf7f4ba645 | 381f61c9fcac56d01d959ae0fa6e376f2c4e3b34 | refs/heads/master | 1,610,286,098,832 | 1,447,124,923,000 | 1,447,124,923,000 | 43,082,433 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 1,922 | lean | import standard
import data.prod
open prod prod.ops quot
private definition eqv {A : Type} (pβ pβ : A Γ A) : Prop :=
(pβ.1 = pβ.1 β§ pβ.2 = pβ.2) β¨ (pβ.1 = pβ.2 β§ pβ.2 = pβ.1)
infix `~` := eqv
open eq or
local notation `β¨` Hβ `,` Hβ `β©` := and.intro Hβ Hβ
private theorem eqv.refl {A : Type} : β p : A Γ A, p ~ p :=
take p, inl β¨rfl, rflβ©
private theorem eqv.symm {A : Type} : β pβ pβ : A Γ A, pβ ~ pβ β pβ ~ pβ
| (aβ, aβ) (bβ, bβ) (inl β¨aβbβ, aβbββ©) := inl β¨symm aβbβ, symm aβbββ©
| (aβ, aβ) (bβ, bβ) (inr β¨aβbβ, aβbββ©) := inr β¨symm aβbβ, symm aβbββ©
private theorem eqv.trans {A : Type} : β pβ pβ pβ : A Γ A, pβ ~ pβ β pβ ~ pβ β pβ ~ pβ
| (aβ, aβ) (bβ, bβ) (cβ, cβ) (inl β¨aβbβ, aβbββ©) (inl β¨bβcβ, bβcββ©) :=
inl β¨trans aβbβ bβcβ, trans aβbβ bβcββ©
| (aβ, aβ) (bβ, bβ) (cβ, cβ) (inl β¨aβbβ, aβbββ©) (inr β¨bβcβ, bβcββ©) :=
inr β¨trans aβbβ bβcβ, trans aβbβ bβcββ©
| (aβ, aβ) (bβ, bβ) (cβ, cβ) (inr β¨aβbβ, aβbββ©) (inl β¨bβcβ, bβcββ©) :=
inr β¨trans aβbβ bβcβ, trans aβbβ bβcββ©
| (aβ, aβ) (bβ, bβ) (cβ, cβ) (inr β¨aβbβ, aβbββ©) (inr β¨bβcβ, bβcββ©) :=
inl β¨trans aβbβ bβcβ, trans aβbβ bβcββ©
private theorem is_equivalence (A : Type) : equivalence (@eqv A) :=
mk_equivalence (@eqv A) (@eqv.refl A) (@eqv.symm A) (@eqv.trans A)
-- BEGIN
definition uprod.setoid [instance] (A : Type) : setoid (A Γ A) :=
setoid.mk (@eqv A) (is_equivalence A)
definition uprod (A : Type) : Type :=
quot (uprod.setoid A)
namespace uprod
definition mk {A : Type} (aβ aβ : A) : uprod A :=
β¦(aβ, aβ)β§
notation `{` aβ `,` aβ `}` := mk aβ aβ
end uprod
-- END
|
84514738ac7bb37a77ca15dc7dc5d7b11816e92d | 618003631150032a5676f229d13a079ac875ff77 | /src/topology/algebra/ordered.lean | c10a71d995c4595276d59fbdaf06c8f28cceb259 | [
"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 | 78,906 | 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, Yury Kudryashov
-/
import tactic.tfae
import order.liminf_limsup
import data.set.intervals
import topology.algebra.group
/-!
# Theory of topology on ordered spaces
## Main definitions
The order topology on an ordered space is the topology generated by all open intervals (or
equivalently by those of the form `(-β, a)` and `(b, +β)`). We define it as `preorder.topology Ξ±`.
However, we do *not* register it as an instance (as many existing ordered types already have
topologies, which would be equal but not definitionally equal to `preorder.topology Ξ±`). Instead,
we introduce a class `order_topology Ξ±`(which is a `Prop`, also known as a mixin) saying that on
the type `Ξ±` having already a topological space structure and a preorder structure, the topological
structure is equal to the order topology.
We also introduce another (mixin) class `order_closed_topology Ξ±` saying that the set of points
`(x, y)` with `x β€ y` is closed in the product space. This is automatically satisfied on a linear
order with the order topology.
We prove many basic properties of such topologies.
## Main statements
This file contains the proofs of the following facts. For exact requirements (`order_closed_topology`
vs `order_topology`, `preorder` vs `partial_order` vs `linear_order` etc) see their statements.
### Open / closed sets
* `is_open_lt` : if `f` and `g` are continuous functions, then `{x | f x < g x}` is open;
* `is_open_Iio`, `is_open_Ioi`, `is_open_Ioo` : open intervals are open;
* `is_closed_le` : if `f` and `g` are continuous functions, then `{x | f x β€ g x}` is closed;
* `is_closed_Iic`, `is_closed_Ici`, `is_closed_Icc` : closed intervals are closed;
* `frontier_le_subset_eq`, `frontier_lt_subset_eq` : frontiers of both `{x | f x β€ g x}`
and `{x | f x < g x}` are included by `{x | f x = g x}`;
* `exists_Ioc_subset_of_mem_nhds`, `exists_Ico_subset_of_mem_nhds` : if `x < y`, then any
neighborhood of `x` includes an interval `[x, z)` for some `z β (x, y]`, and any neighborhood
of `y` includes an interval `(z, y]` for some `z β [x, y)`.
### Convergence and inequalities
* `le_of_tendsto_of_tendsto` : if `f` converges to `a`, `g` converges to `b`, and eventually
`f x β€ g x`, then `a β€ b`
* `le_of_tendsto`, `ge_of_tendsto` : if `f` converges to `a` and eventually `f x β€ b`
(resp., `b β€ f x`), then `a β€ b` (resp., `b β€ a); we also provide primed versions
that assume the inequalities to hold for all `x`.
### Min, max, `Sup` and `Inf`
* `continuous.min`, `continuous.max`: pointwise `min`/`max` of two continuous functions is continuous.
* `tendsto.min`, `tendsto.max` : if `f` tends to `a` and `g` tends to `b`, then their pointwise
`min`/`max` tend to `min a b` and `max a b`, respectively.
* `tendsto_of_tendsto_of_tendsto_of_le_of_le` : theorem known as squeeze theorem,
sandwich theorem, theorem of Carabinieri, and two policemen (and a drunk) theorem; if `g` and `h`
both converge to `a`, and eventually `g x β€ f x β€ h x`, then `f` converges to `a`.
### Connected sets and Intermediate Value Theorem
* `is_connected_I??` : all intervals `I??` are connected,
* `is_connected.intermediate_value`, `intermediate_value_univ` : Intermediate Value Theorem for
connected sets and connected spaces, respectively;
* `intermediate_value_Icc`, `intermediate_value_Icc'`: Intermediate Value Theorem for functions
on closed intervals.
### Miscellaneous facts
* `compact.exists_forall_le`, `compact.exists_forall_ge` : extreme value theorem, a continuous
function on a compact set takes its minimum and maximum values.
* `is_closed.Icc_subset_of_forall_mem_nhds_within` : βContinuous inductionβ principle;
if `s β© [a, b]` is closed, `a β s`, and for each `x β [a, b) β© s` some of its right neighborhoods
is included `s`, then `[a, b] β s`.
* `is_closed.Icc_subset_of_forall_exists_gt`, `is_closed.mem_of_ge_of_forall_exists_gt` : two
other versions of the βcontinuous inductionβ principle.
## Implementation
We do _not_ register the order topology as an instance on a preorder (or even on a linear order).
Indeed, on many such spaces, a topology has already been constructed in a different way (think
of the discrete spaces `β` or `β€`, or `β` that could inherit a topology as the completion of `β`),
and is in general not defeq to the one generated by the intervals. We make it available as a
definition `preorder.topology Ξ±` though, that can be registered as an instance when necessary, or
for specific types.
-/
open classical set filter topological_space
open_locale topological_space classical
universes u v w
variables {Ξ± : Type u} {Ξ² : Type v} {Ξ³ : Type w}
/-- A topology on a set which is both a topological space and a preorder is _order-closed_ if the
set of points `(x, y)` with `x β€ y` is closed in the product space. We introduce this as a mixin.
This property is satisfied for the order topology on a linear order, but it can be satisfied more
generally, and suffices to derive many interesting properties relating order and topology. -/
class order_closed_topology (Ξ± : Type*) [topological_space Ξ±] [preorder Ξ±] : Prop :=
(is_closed_le' : is_closed (Ξ»p:Ξ±ΓΞ±, p.1 β€ p.2))
instance : Ξ [topological_space Ξ±], topological_space (order_dual Ξ±) := id
section order_closed_topology
section preorder
variables [topological_space Ξ±] [preorder Ξ±] [t : order_closed_topology Ξ±]
include t
lemma is_closed_le [topological_space Ξ²] {f g : Ξ² β Ξ±} (hf : continuous f) (hg : continuous g) :
is_closed {b | f b β€ g b} :=
continuous_iff_is_closed.mp (hf.prod_mk hg) _ t.is_closed_le'
lemma is_closed_le' (a : Ξ±) : is_closed {b | b β€ a} :=
is_closed_le continuous_id continuous_const
lemma is_closed_Iic {a : Ξ±} : is_closed (Iic a) :=
is_closed_le' a
lemma is_closed_ge' (a : Ξ±) : is_closed {b | a β€ b} :=
is_closed_le continuous_const continuous_id
lemma is_closed_Ici {a : Ξ±} : is_closed (Ici a) :=
is_closed_ge' a
instance : order_closed_topology (order_dual Ξ±) :=
β¨continuous_swap _ (@order_closed_topology.is_closed_le' Ξ± _ _ _)β©
lemma is_closed_Icc {a b : Ξ±} : is_closed (Icc a b) :=
is_closed_inter is_closed_Ici is_closed_Iic
lemma le_of_tendsto_of_tendsto {f g : Ξ² β Ξ±} {b : filter Ξ²} {aβ aβ : Ξ±} (hb : b β β₯)
(hf : tendsto f b (π aβ)) (hg : tendsto g b (π aβ)) (h : βαΆ x in b, f x β€ g x) :
aβ β€ aβ :=
have tendsto (Ξ»b, (f b, g b)) b (π (aβ, aβ)),
by rw [nhds_prod_eq]; exact hf.prod_mk hg,
show (aβ, aβ) β {p:Ξ±ΓΞ± | p.1 β€ p.2},
from mem_of_closed_of_tendsto hb this t.is_closed_le' h
lemma le_of_tendsto_of_tendsto' {f g : Ξ² β Ξ±} {b : filter Ξ²} {aβ aβ : Ξ±} (hb : b β β₯)
(hf : tendsto f b (π aβ)) (hg : tendsto g b (π aβ)) (h : β x, f x β€ g x) :
aβ β€ aβ :=
le_of_tendsto_of_tendsto hb hf hg (eventually_of_forall _ h)
lemma le_of_tendsto {f : Ξ² β Ξ±} {a b : Ξ±} {x : filter Ξ²}
(nt : x β β₯) (lim : tendsto f x (π a)) (h : βαΆ c in x, f c β€ b) : a β€ b :=
le_of_tendsto_of_tendsto nt lim tendsto_const_nhds h
lemma le_of_tendsto' {f : Ξ² β Ξ±} {a b : Ξ±} {x : filter Ξ²}
(nt : x β β₯) (lim : tendsto f x (π a)) (h : β c, f c β€ b) : a β€ b :=
le_of_tendsto nt lim (eventually_of_forall _ h)
lemma ge_of_tendsto {f : Ξ² β Ξ±} {a b : Ξ±} {x : filter Ξ²}
(nt : x β β₯) (lim : tendsto f x (π a)) (h : βαΆ c in x, b β€ f c) : b β€ a :=
le_of_tendsto_of_tendsto nt tendsto_const_nhds lim h
lemma ge_of_tendsto' {f : Ξ² β Ξ±} {a b : Ξ±} {x : filter Ξ²}
(nt : x β β₯) (lim : tendsto f x (π a)) (h : β c, b β€ f c) : b β€ a :=
ge_of_tendsto nt lim (eventually_of_forall _ h)
@[simp] lemma closure_le_eq [topological_space Ξ²] {f g : Ξ² β Ξ±} (hf : continuous f) (hg : continuous g) :
closure {b | f b β€ g b} = {b | f b β€ g b} :=
closure_eq_iff_is_closed.mpr $ is_closed_le hf hg
lemma closure_lt_subset_le [topological_space Ξ²] {f g : Ξ² β Ξ±} (hf : continuous f) (hg : continuous g) :
closure {b | f b < g b} β {b | f b β€ g b} :=
by { rw [βclosure_le_eq hf hg], exact closure_mono (Ξ» b, le_of_lt) }
lemma continuous_within_at.closure_le [topological_space Ξ²]
{f g : Ξ² β Ξ±} {s : set Ξ²} {x : Ξ²} (hx : x β closure s)
(hf : continuous_within_at f s x)
(hg : continuous_within_at g s x)
(h : β y β s, f y β€ g y) : f x β€ g x :=
begin
show (f x, g x) β {p : Ξ± Γ Ξ± | p.1 β€ p.2},
suffices : (f x, g x) β closure {p : Ξ± Γ Ξ± | p.1 β€ p.2},
begin
rwa closure_eq_iff_is_closed.2 at this,
exact order_closed_topology.is_closed_le'
end,
exact (continuous_within_at.prod hf hg).mem_closure hx h
end
end preorder
section partial_order
variables [topological_space Ξ±] [partial_order Ξ±] [t : order_closed_topology Ξ±]
include t
private lemma is_closed_eq : is_closed {p : Ξ± Γ Ξ± | p.1 = p.2} :=
by simp [le_antisymm_iff];
exact is_closed_inter t.is_closed_le' (is_closed_le continuous_snd continuous_fst)
@[priority 90] -- see Note [lower instance priority]
instance order_closed_topology.to_t2_space : t2_space Ξ± :=
{ t2 :=
have is_open {p : Ξ± Γ Ξ± | p.1 β p.2}, from is_closed_eq,
assume a b h,
let β¨u, v, hu, hv, ha, hb, hβ© := is_open_prod_iff.mp this a b h in
β¨u, v, hu, hv, ha, hb,
set.eq_empty_iff_forall_not_mem.2 $ assume a β¨hβ, hββ©,
have a β a, from @h (a, a) β¨hβ, hββ©,
this rflβ© }
end partial_order
section linear_order
variables [topological_space Ξ±] [linear_order Ξ±] [order_closed_topology Ξ±]
lemma is_open_lt [topological_space Ξ²] {f g : Ξ² β Ξ±} (hf : continuous f) (hg : continuous g) :
is_open {b | f b < g b} :=
by simp [lt_iff_not_ge, -not_le]; exact is_closed_le hg hf
variables {a b : Ξ±}
lemma is_open_Iio : is_open (Iio a) :=
is_open_lt continuous_id continuous_const
lemma is_open_Ioi : is_open (Ioi a) :=
is_open_lt continuous_const continuous_id
lemma is_open_Ioo : is_open (Ioo a b) :=
is_open_inter is_open_Ioi is_open_Iio
@[simp] lemma interior_Ioi : interior (Ioi a) = Ioi a :=
interior_eq_of_open is_open_Ioi
@[simp] lemma interior_Iio : interior (Iio a) = Iio a :=
interior_eq_of_open is_open_Iio
@[simp] lemma interior_Ioo : interior (Ioo a b) = Ioo a b :=
interior_eq_of_open is_open_Ioo
lemma is_preconnected.forall_Icc_subset {s : set Ξ±} (hs : is_preconnected s)
{a b : Ξ±} (ha : a β s) (hb : b β s) :
Icc a b β s :=
begin
assume x hx,
obtain β¨y, hy, hy'β© : (s β© ((Iic x) β© (Ici x))).nonempty,
from is_preconnected_closed_iff.1 hs (Iic x) (Ici x) is_closed_Iic is_closed_Ici
(Ξ» y _, le_total y x) β¨a, ha, hx.1β© β¨b, hb, hx.2β©,
exact le_antisymm hy'.1 hy'.2 βΈ hy
end
/-- Intermediate Value Theorem for continuous functions on connected sets. -/
lemma is_preconnected.intermediate_value {Ξ³ : Type*} [topological_space Ξ³] {s : set Ξ³}
(hs : is_preconnected s) {a b : Ξ³} (ha : a β s) (hb : b β s) {f : Ξ³ β Ξ±} (hf : continuous_on f s) :
Icc (f a) (f b) β f '' s :=
(hs.image f hf).forall_Icc_subset (mem_image_of_mem f ha) (mem_image_of_mem f hb)
/-- Intermediate Value Theorem for continuous functions on connected spaces. -/
lemma intermediate_value_univ {Ξ³ : Type*} [topological_space Ξ³] [H : preconnected_space Ξ³]
(a b : Ξ³) {f : Ξ³ β Ξ±} (hf : continuous f) :
Icc (f a) (f b) β range f :=
@image_univ _ _ f βΈ H.is_preconnected_univ.intermediate_value trivial trivial hf.continuous_on
end linear_order
section decidable_linear_order
variables [topological_space Ξ±] [decidable_linear_order Ξ±] [order_closed_topology Ξ±] {f g : Ξ² β Ξ±}
section
variables [topological_space Ξ²] (hf : continuous f) (hg : continuous g)
include hf hg
lemma frontier_le_subset_eq : frontier {b | f b β€ g b} β {b | f b = g b} :=
begin
rw [frontier_eq_closure_inter_closure, closure_le_eq hf hg],
rintros b β¨hbβ, hbββ©,
refine le_antisymm hbβ (closure_lt_subset_le hg hf _),
convert hbβ using 2, simp only [not_le.symm], refl
end
lemma frontier_lt_subset_eq : frontier {b | f b < g b} β {b | f b = g b} :=
by rw β frontier_compl;
convert frontier_le_subset_eq hg hf; simp [ext_iff, eq_comm]
lemma continuous.max : continuous (Ξ»b, max (f b) (g b)) :=
have βbβfrontier {b | f b β€ g b}, g b = f b, from assume b hb, (frontier_le_subset_eq hf hg hb).symm,
continuous_if this hg hf
lemma continuous.min : continuous (Ξ»b, min (f b) (g b)) :=
have βbβfrontier {b | f b β€ g b}, f b = g b, from assume b hb, frontier_le_subset_eq hf hg hb,
continuous_if this hf hg
end
lemma tendsto.max {b : filter Ξ²} {aβ aβ : Ξ±} (hf : tendsto f b (π aβ)) (hg : tendsto g b (π aβ)) :
tendsto (Ξ»b, max (f b) (g b)) b (π (max aβ aβ)) :=
show tendsto ((Ξ»p:Ξ±ΓΞ±, max p.1 p.2) β (Ξ»b, (f b, g b))) b (π (max aβ aβ)),
from tendsto.comp
begin
rw [βnhds_prod_eq],
from continuous_iff_continuous_at.mp (continuous_fst.max continuous_snd) _
end
(hf.prod_mk hg)
lemma tendsto.min {b : filter Ξ²} {aβ aβ : Ξ±} (hf : tendsto f b (π aβ)) (hg : tendsto g b (π aβ)) :
tendsto (Ξ»b, min (f b) (g b)) b (π (min aβ aβ)) :=
show tendsto ((Ξ»p:Ξ±ΓΞ±, min p.1 p.2) β (Ξ»b, (f b, g b))) b (π (min aβ aβ)),
from tendsto.comp
begin
rw [βnhds_prod_eq],
from continuous_iff_continuous_at.mp (continuous_fst.min continuous_snd) _
end
(hf.prod_mk hg)
end decidable_linear_order
end order_closed_topology
/-- The order topology on an ordered type is the topology generated by open intervals. We register
it on a preorder, but it is mostly interesting in linear orders, where it is also order-closed.
We define it as a mixin. If you want to introduce the order topology on a preorder, use
`preorder.topology`. -/
class order_topology (Ξ± : Type*) [t : topological_space Ξ±] [preorder Ξ±] : Prop :=
(topology_eq_generate_intervals : t = generate_from {s | βa, s = Ioi a β¨ s = Iio a})
/-- (Order) topology on a partial order `Ξ±` generated by the subbase of open intervals
`(a, β) = { x β£ a < x }, (-β , b) = {x β£ x < b}` for all `a, b` in `Ξ±`. We do not register it as an
instance as many ordered sets are already endowed with the same topology, most often in a non-defeq
way though. Register as a local instance when necessary. -/
def preorder.topology (Ξ± : Type*) [preorder Ξ±] : topological_space Ξ± :=
generate_from {s : set Ξ± | β (a : Ξ±), s = {b : Ξ± | a < b} β¨ s = {b : Ξ± | b < a}}
section order_topology
instance {Ξ± : Type*} [topological_space Ξ±] [partial_order Ξ±] [order_topology Ξ±] :
order_topology (order_dual Ξ±) :=
β¨by convert @order_topology.topology_eq_generate_intervals Ξ± _ _ _;
conv in (_ β¨ _) { rw or.comm }; reflβ©
section partial_order
variables [topological_space Ξ±] [partial_order Ξ±] [t : order_topology Ξ±]
include t
lemma is_open_iff_generate_intervals {s : set Ξ±} :
is_open s β generate_open {s | βa, s = Ioi a β¨ s = Iio a} s :=
by rw [t.topology_eq_generate_intervals]; refl
lemma is_open_lt' (a : Ξ±) : is_open {b:Ξ± | a < b} :=
by rw [@is_open_iff_generate_intervals Ξ± _ _ t]; exact generate_open.basic _ β¨a, or.inl rflβ©
lemma is_open_gt' (a : Ξ±) : is_open {b:Ξ± | b < a} :=
by rw [@is_open_iff_generate_intervals Ξ± _ _ t]; exact generate_open.basic _ β¨a, or.inr rflβ©
lemma lt_mem_nhds {a b : Ξ±} (h : a < b) : βαΆ x in π b, a < x :=
mem_nhds_sets (is_open_lt' _) h
lemma le_mem_nhds {a b : Ξ±} (h : a < b) : βαΆ x in π b, a β€ x :=
(π b).sets_of_superset (lt_mem_nhds h) $ assume b hb, le_of_lt hb
lemma gt_mem_nhds {a b : Ξ±} (h : a < b) : βαΆ x in π a, x < b :=
mem_nhds_sets (is_open_gt' _) h
lemma ge_mem_nhds {a b : Ξ±} (h : a < b) : βαΆ x in π a, x β€ b :=
(π a).sets_of_superset (gt_mem_nhds h) $ assume b hb, le_of_lt hb
lemma nhds_eq_order (a : Ξ±) :
π a = (β¨
b β Iio a, principal (Ioi b)) β (β¨
b β Ioi a, principal (Iio b)) :=
by rw [t.topology_eq_generate_intervals, nhds_generate_from];
from le_antisymm
(le_inf
(le_infi $ assume b, le_infi $ assume hb,
infi_le_of_le {c : Ξ± | b < c} $ infi_le _ β¨hb, b, or.inl rflβ©)
(le_infi $ assume b, le_infi $ assume hb,
infi_le_of_le {c : Ξ± | c < b} $ infi_le _ β¨hb, b, or.inr rflβ©))
(le_infi $ assume s, le_infi $ assume β¨ha, b, hsβ©,
match s, ha, hs with
| _, h, (or.inl rfl) := inf_le_left_of_le $ infi_le_of_le b $ infi_le _ h
| _, h, (or.inr rfl) := inf_le_right_of_le $ infi_le_of_le b $ infi_le _ h
end)
@[nolint ge_or_gt] -- see Note [nolint_ge]
lemma tendsto_order {f : Ξ² β Ξ±} {a : Ξ±} {x : filter Ξ²} :
tendsto f x (π a) β (β a' < a, βαΆ b in x, a' < f b) β§ (β a' > a, βαΆ b in x, f b < a') :=
by simp [nhds_eq_order a, tendsto_inf, tendsto_infi, tendsto_principal]
/-- Also known as squeeze or sandwich theorem. This version assumes that inequalities hold
eventually for the filter. -/
lemma tendsto_of_tendsto_of_tendsto_of_le_of_le' {f g h : Ξ² β Ξ±} {b : filter Ξ²} {a : Ξ±}
(hg : tendsto g b (π a)) (hh : tendsto h b (π a))
(hgf : βαΆ b in b, g b β€ f b) (hfh : βαΆ b in b, f b β€ h b) :
tendsto f b (π a) :=
tendsto_order.2
β¨assume a' h',
have βαΆ b in b, a' < g b, from (tendsto_order.1 hg).left a' h',
by filter_upwards [this, hgf] assume a, lt_of_lt_of_le,
assume a' h',
have βαΆ b in b, h b < a', from (tendsto_order.1 hh).right a' h',
by filter_upwards [this, hfh] assume a hβ hβ, lt_of_le_of_lt hβ hββ©
/-- Also known as squeeze or sandwich theorem. This version assumes that inequalities hold
everywhere. -/
lemma tendsto_of_tendsto_of_tendsto_of_le_of_le {f g h : Ξ² β Ξ±} {b : filter Ξ²} {a : Ξ±}
(hg : tendsto g b (π a)) (hh : tendsto h b (π a)) (hgf : g β€ f) (hfh : f β€ h) :
tendsto f b (π a) :=
tendsto_of_tendsto_of_tendsto_of_le_of_le' hg hh
(eventually_of_forall _ hgf) (eventually_of_forall _ hfh)
lemma nhds_order_unbounded {a : Ξ±} (hu : βu, a < u) (hl : βl, l < a) :
π a = (β¨
l (hβ : l < a) u (hβ : a < u), principal (Ioo l u)) :=
let β¨u, huβ© := hu, β¨l, hlβ© := hl in
calc π a = (β¨
b<a, principal {c | b < c}) β (β¨
b>a, principal {c | c < b}) : nhds_eq_order a
... = (β¨
b<a, principal {c | b < c} β (β¨
b>a, principal {c | c < b})) :
binfi_inf hl
... = (β¨
l<a, (β¨
u>a, principal {c | c < u} β principal {c | l < c})) :
begin
congr, funext x,
congr, funext hx,
rw [inf_comm],
apply binfi_inf hu
end
... = _ : by simp [inter_comm]; refl
lemma tendsto_order_unbounded {f : Ξ² β Ξ±} {a : Ξ±} {x : filter Ξ²}
(hu : βu, a < u) (hl : βl, l < a) (h : βl u, l < a β a < u β βαΆ b in x, l < f b β§ f b < u) :
tendsto f x (π a) :=
by rw [nhds_order_unbounded hu hl];
from (tendsto_infi.2 $ assume l, tendsto_infi.2 $ assume hl,
tendsto_infi.2 $ assume u, tendsto_infi.2 $ assume hu, tendsto_principal.2 $ h l u hl hu)
end partial_order
@[nolint ge_or_gt] -- see Note [nolint_ge]
theorem induced_order_topology' {Ξ± : Type u} {Ξ² : Type v}
[partial_order Ξ±] [ta : topological_space Ξ²] [partial_order Ξ²] [order_topology Ξ²]
(f : Ξ± β Ξ²) (hf : β {x y}, f x < f y β x < y)
(Hβ : β {a x}, x < f a β β b < a, x β€ f b)
(Hβ : β {a x}, f a < x β β b > a, f b β€ x) :
@order_topology _ (induced f ta) _ :=
begin
letI := induced f ta,
refine β¨eq_of_nhds_eq_nhds (Ξ» a, _)β©,
rw [nhds_induced, nhds_generate_from, nhds_eq_order (f a)],
apply le_antisymm,
{ refine le_infi (Ξ» s, le_infi $ Ξ» hs, le_principal_iff.2 _),
rcases hs with β¨ab, b, rfl|rflβ©,
{ exact mem_comap_sets.2 β¨{x | f b < x},
mem_inf_sets_of_left $ mem_infi_sets _ $ mem_infi_sets (hf.2 ab) $ mem_principal_self _,
Ξ» x, hf.1β© },
{ exact mem_comap_sets.2 β¨{x | x < f b},
mem_inf_sets_of_right $ mem_infi_sets _ $ mem_infi_sets (hf.2 ab) $ mem_principal_self _,
Ξ» x, hf.1β© } },
{ rw [β map_le_iff_le_comap],
refine le_inf _ _; refine le_infi (Ξ» x, le_infi $ Ξ» h, le_principal_iff.2 _); simp,
{ rcases Hβ h with β¨b, ab, xbβ©,
refine mem_infi_sets _ (mem_infi_sets β¨ab, b, or.inl rflβ© (mem_principal_sets.2 _)),
exact Ξ» c hc, lt_of_le_of_lt xb (hf.2 hc) },
{ rcases Hβ h with β¨b, ab, xbβ©,
refine mem_infi_sets _ (mem_infi_sets β¨ab, b, or.inr rflβ© (mem_principal_sets.2 _)),
exact Ξ» c hc, lt_of_lt_of_le (hf.2 hc) xb } },
end
theorem induced_order_topology {Ξ± : Type u} {Ξ² : Type v}
[partial_order Ξ±] [ta : topological_space Ξ²] [partial_order Ξ²] [order_topology Ξ²]
(f : Ξ± β Ξ²) (hf : β {x y}, f x < f y β x < y)
(H : β {x y}, x < y β β a, x < f a β§ f a < y) :
@order_topology _ (induced f ta) _ :=
induced_order_topology' f @hf
(Ξ» a x xa, let β¨b, xb, baβ© := H xa in β¨b, hf.1 ba, le_of_lt xbβ©)
(Ξ» a x ax, let β¨b, ab, bxβ© := H ax in β¨b, hf.1 ab, le_of_lt bxβ©)
lemma nhds_top_order [topological_space Ξ±] [order_top Ξ±] [order_topology Ξ±] :
π (β€:Ξ±) = (β¨
l (hβ : l < β€), principal (Ioi l)) :=
by simp [nhds_eq_order (β€:Ξ±)]
lemma nhds_bot_order [topological_space Ξ±] [order_bot Ξ±] [order_topology Ξ±] :
π (β₯:Ξ±) = (β¨
l (hβ : β₯ < l), principal (Iio l)) :=
by simp [nhds_eq_order (β₯:Ξ±)]
section linear_order
variables [topological_space Ξ±] [linear_order Ξ±] [order_topology Ξ±]
lemma exists_Ioc_subset_of_mem_nhds' {a : Ξ±} {s : set Ξ±} (hs : s β π a) {l : Ξ±} (hl : l < a) :
β l' β Ico l a, Ioc l' a β s :=
begin
rw [nhds_eq_order a] at hs,
rcases hs with β¨tβ, htβ, tβ, htβ, htsβ©,
-- First we show that `tβ` includes `(-β, a]`, so it suffices to show `(l', β) β tβ`
suffices : β l' β Ico l a, Ioi l' β tβ,
{ have A : principal (Iic a) β€ β¨
b β Ioi a, principal (Iio b),
from (le_infi $ Ξ» b, le_infi $ Ξ» hb, principal_mono.2 $ Iic_subset_Iio.2 hb),
have B : tβ β© Iic a β s,
from subset.trans (inter_subset_inter_right _ (A htβ)) hts,
from this.imp (Ξ» l', Exists.imp $ Ξ» hl' hl x hx, B β¨hl hx.1, hx.2β©) },
clear hts htβ tβ,
-- Now we find `l` such that `(l', β) β tβ`
letI := classical.DLO Ξ±,
rw [mem_binfi] at htβ,
{ rcases htβ with β¨b, hb, hb'β©,
exact β¨max b l, β¨le_max_right _ _, max_lt hb hlβ©,
Ξ» x hx, hb' $ Ioi_subset_Ioi (le_max_left _ _) hxβ© },
{ intros b hb b' hb', simp only [mem_Iio] at hb hb',
use [max b b', max_lt hb hb'],
simp [le_refl] },
exact β¨l, hlβ©
end
lemma exists_Ico_subset_of_mem_nhds' {a : Ξ±} {s : set Ξ±} (hs : s β π a) {u : Ξ±} (hu : a < u) :
β u' β Ioc a u, Ico a u' β s :=
begin
convert @exists_Ioc_subset_of_mem_nhds' (order_dual Ξ±) _ _ _ _ _ hs _ hu,
ext, rw [dual_Ico, dual_Ioc]
end
lemma exists_Ioc_subset_of_mem_nhds {a : Ξ±} {s : set Ξ±} (hs : s β π a) (h : β l, l < a) :
β l < a, Ioc l a β s :=
let β¨l', hl'β© := h in let β¨l, hlβ© := exists_Ioc_subset_of_mem_nhds' hs hl' in β¨l, hl.fst.2, hl.sndβ©
lemma exists_Ico_subset_of_mem_nhds {a : Ξ±} {s : set Ξ±} (hs : s β π a) (h : β u, a < u) :
β u (_ : a < u), Ico a u β s :=
let β¨l', hl'β© := h in let β¨l, hlβ© := exists_Ico_subset_of_mem_nhds' hs hl' in β¨l, hl.fst.1, hl.sndβ©
lemma mem_nhds_unbounded {a : Ξ±} {s : set Ξ±} (hu : βu, a < u) (hl : βl, l < a) :
s β π a β (βl u, l < a β§ a < u β§ βb, l < b β b < u β b β s) :=
let β¨l, hl'β© := hl, β¨u, hu'β© := hu in
have π a = (β¨
p : {l // l < a} Γ {u // a < u}, principal (Ioo p.1.val p.2.val)),
by simp [nhds_order_unbounded hu hl, infi_subtype, infi_prod],
iff.intro
(assume hs, by rw [this] at hs; from infi_sets_induct hs
β¨l, u, hl', hu', by simpβ©
begin
intro p, rcases p with β¨β¨l, hlβ©, β¨u, huβ©β©,
simp [set.subset_def],
intros sβ sβ hsβ l' hl' u' hu' hsβ,
letI := classical.DLO Ξ±,
refine β¨max l l', _, min u u', _β©;
simp [*, lt_min_iff, max_lt_iff] {contextual := tt}
end
(assume sβ sβ h β¨l, u, hβ, hβ, hββ©, β¨l, u, hβ, hβ, assume b hu hl, h $ hβ _ hu hlβ©))
(assume β¨l, u, hl, hu, hβ©,
by rw [this]; exact mem_infi_sets β¨β¨l, hlβ©, β¨u, huβ©β© (assume b β¨hβ, hββ©, h b hβ hβ))
lemma order_separated {aβ aβ : Ξ±} (h : aβ < aβ) :
βu v : set Ξ±, is_open u β§ is_open v β§ aβ β u β§ aβ β v β§ (βbββu, βbββv, bβ < bβ) :=
match dense_or_discrete aβ aβ with
| or.inl β¨a, haβ, haββ© := β¨{a' | a' < a}, {a' | a < a'}, is_open_gt' a, is_open_lt' a, haβ, haβ,
assume bβ hβ bβ hβ, lt_trans hβ hββ©
| or.inr β¨hβ, hββ© := β¨{a | a < aβ}, {a | aβ < a}, is_open_gt' aβ, is_open_lt' aβ, h, h,
assume bβ hbβ bβ hbβ,
calc bβ β€ aβ : hβ _ hbβ
... < aβ : h
... β€ bβ : hβ _ hbββ©
end
@[priority 100] -- see Note [lower instance priority]
instance order_topology.to_order_closed_topology : order_closed_topology Ξ± :=
{ is_closed_le' :=
is_open_prod_iff.mpr $ assume aβ aβ (h : Β¬ aβ β€ aβ),
have h : aβ < aβ, from lt_of_not_ge h,
let β¨u, v, hu, hv, haβ, haβ, hβ© := order_separated h in
β¨v, u, hv, hu, haβ, haβ, assume β¨bβ, bββ© β¨hβ, hββ©, not_le_of_gt $ h bβ hβ bβ hββ© }
lemma order_topology.t2_space : t2_space Ξ± := by apply_instance
@[priority 100] -- see Note [lower instance priority]
instance order_topology.regular_space : regular_space Ξ± :=
{ regular := assume s a hs ha,
have hs' : -s β π a, from mem_nhds_sets hs ha,
have βt:set Ξ±, is_open t β§ (βlβ s, l < a β l β t) β§ π a β principal t = β₯,
from by_cases
(assume h : βl, l < a,
let β¨l, hl, hβ© := exists_Ioc_subset_of_mem_nhds hs' h in
match dense_or_discrete l a with
| or.inl β¨b, hbβ, hbββ© := β¨{a | a < b}, is_open_gt' _,
assume c hcs hca, show c < b,
from lt_of_not_ge $ assume hbc, h β¨lt_of_lt_of_le hbβ hbc, le_of_lt hcaβ© hcs,
inf_principal_eq_bot $ (π a).sets_of_superset (mem_nhds_sets (is_open_lt' _) hbβ) $
assume x (hx : b < x), show Β¬ x < b, from not_lt.2 $ le_of_lt hxβ©
| or.inr β¨hβ, hββ© := β¨{a' | a' < a}, is_open_gt' _, assume b hbs hba, hba,
inf_principal_eq_bot $ (π a).sets_of_superset (mem_nhds_sets (is_open_lt' _) hl) $
assume x (hx : l < x), show Β¬ x < a, from not_lt.2 $ hβ _ hxβ©
end)
(assume : Β¬ βl, l < a, β¨β
, is_open_empty, assume l _ hl, (this β¨l, hlβ©).elim,
by rw [principal_empty, inf_bot_eq]β©),
let β¨tβ, htβo, htβs, htβaβ© := this in
have βt:set Ξ±, is_open t β§ (βuβ s, u>a β u β t) β§ π a β principal t = β₯,
from by_cases
(assume h : βu, u > a,
let β¨u, hu, hβ© := exists_Ico_subset_of_mem_nhds hs' h in
match dense_or_discrete a u with
| or.inl β¨b, hbβ, hbββ© := β¨{a | b < a}, is_open_lt' _,
assume c hcs hca, show c > b,
from lt_of_not_ge $ assume hbc, h β¨le_of_lt hca, lt_of_le_of_lt hbc hbββ© hcs,
inf_principal_eq_bot $ (π a).sets_of_superset (mem_nhds_sets (is_open_gt' _) hbβ) $
assume x (hx : b > x), show Β¬ x > b, from not_lt.2 $ le_of_lt hxβ©
| or.inr β¨hβ, hββ© := β¨{a' | a' > a}, is_open_lt' _, assume b hbs hba, hba,
inf_principal_eq_bot $ (π a).sets_of_superset (mem_nhds_sets (is_open_gt' _) hu) $
assume x (hx : u > x), show Β¬ x > a, from not_lt.2 $ hβ _ hxβ©
end)
(assume : Β¬ βu, u > a, β¨β
, is_open_empty, assume l _ hl, (this β¨l, hlβ©).elim,
by rw [principal_empty, inf_bot_eq]β©),
let β¨tβ, htβo, htβs, htβaβ© := this in
β¨tβ βͺ tβ, is_open_union htβo htβo,
assume x hx,
have x β a, from assume eq, ha $ eq βΈ hx,
(ne_iff_lt_or_gt.mp this).imp (htβs _ hx) (htβs _ hx),
by rw [βsup_principal, inf_sup_left, htβa, htβa, bot_sup_eq]β©,
..order_topology.t2_space }
/-- A set is a neighborhood of `a` if and only if it contains an interval `(l, u)` containing `a`,
provided `a` is neither a bottom element nor a top element. -/
lemma mem_nhds_iff_exists_Ioo_subset' {a l' u' : Ξ±} {s : set Ξ±}
(hl' : l' < a) (hu' : a < u') :
s β π a β βl u, a β Ioo l u β§ Ioo l u β s :=
begin
split,
{ assume h,
rcases exists_Ico_subset_of_mem_nhds' h hu' with β¨u, au, huβ©,
rcases exists_Ioc_subset_of_mem_nhds' h hl' with β¨l, la, hlβ©,
refine β¨l, u, β¨la.2, au.1β©, Ξ»x hx, _β©,
cases le_total a x with hax hax,
{ exact hu β¨hax, hx.2β© },
{ exact hl β¨hx.1, haxβ© } },
{ rintros β¨l, u, ha, hβ©,
apply mem_sets_of_superset (mem_nhds_sets is_open_Ioo ha) h }
end
/-- A set is a neighborhood of `a` if and only if it contains an interval `(l, u)` containing `a`. -/
lemma mem_nhds_iff_exists_Ioo_subset [no_top_order Ξ±] [no_bot_order Ξ±] {a : Ξ±} {s : set Ξ±} :
s β π a β βl u, a β Ioo l u β§ Ioo l u β s :=
let β¨l', hl'β© := no_bot a in let β¨u', hu'β© := no_top a in mem_nhds_iff_exists_Ioo_subset' hl' hu'
/-!
### Neighborhoods to the left and to the right
Limits to the left and to the right of real functions are defined in terms of neighborhoods to
the left and to the right, either open or closed, i.e., members of `nhds_within a (Ioi a)` and
`nhds_wihin a (Ici a)` on the right, and similarly on the left. Such neighborhoods can be
characterized as the sets containing suitable intervals to the right or to the left of `a`.
We give now these characterizations. -/
-- NB: If you extend the list, append to the end please to avoid breaking the API
/-- The following statements are equivalent:
0. `s` is a neighborhood of `a` within `(a, +β)`
1. `s` is a neighborhood of `a` within `(a, b]`
2. `s` is a neighborhood of `a` within `(a, b)`
3. `s` includes `(a, u)` for some `u β (a, b]`
4. `s` includes `(a, u)` for some `u > a` -/
lemma tfae_mem_nhds_within_Ioi {a b : Ξ±} (hab : a < b) (s : set Ξ±) :
tfae [s β nhds_within a (Ioi a), -- 0 : `s` is a neighborhood of `a` within `(a, +β)`
s β nhds_within a (Ioc a b), -- 1 : `s` is a neighborhood of `a` within `(a, b]`
s β nhds_within a (Ioo a b), -- 2 : `s` is a neighborhood of `a` within `(a, b)`
β u β Ioc a b, Ioo a u β s, -- 3 : `s` includes `(a, u)` for some `u β (a, b]`
β u β Ioi a, Ioo a u β s] := -- 4 : `s` includes `(a, u)` for some `u > a`
begin
tfae_have : 1 β 2, from Ξ» h, nhds_within_mono _ Ioc_subset_Ioi_self h,
tfae_have : 2 β 3, from Ξ» h, nhds_within_mono _ Ioo_subset_Ioc_self h,
tfae_have : 4 β 5, from Ξ» β¨u, umem, huβ©, β¨u, umem.1, huβ©,
tfae_have : 5 β 1,
{ rintros β¨u, hau, huβ©,
exact mem_nhds_within.2 β¨Iio u, is_open_Iio, hau, by rwa [inter_comm, Ioi_inter_Iio]β© },
tfae_have : 3 β 4,
{ assume h,
rcases mem_nhds_within_iff_exists_mem_nhds_inter.1 h with β¨v, va, hvβ©,
rcases exists_Ico_subset_of_mem_nhds' va hab with β¨u, au, huβ©,
refine β¨u, au, Ξ»x hx, _β©,
refine hv β¨hu β¨le_of_lt hx.1, hx.2β©, _β©,
exact Ioo_subset_Ioo_right au.2 hx },
tfae_finish
end
@[simp] lemma nhds_within_Ioc_eq_nhds_within_Ioi {a b : Ξ±} (h : a < b) :
nhds_within a (Ioc a b) = nhds_within a (Ioi a) :=
filter.ext $ Ξ» s, (tfae_mem_nhds_within_Ioi h s).out 1 0
@[simp] lemma nhds_within_Ioo_eq_nhds_within_Ioi {a b : Ξ±} (hu : a < b) :
nhds_within a (Ioo a b) = nhds_within a (Ioi a) :=
filter.ext $ Ξ» s, (tfae_mem_nhds_within_Ioi hu s).out 2 0
lemma mem_nhds_within_Ioi_iff_exists_mem_Ioc_Ioo_subset {a u' : Ξ±} {s : set Ξ±} (hu' : a < u') :
s β nhds_within a (Ioi a) β βu β Ioc a u', Ioo a u β s :=
(tfae_mem_nhds_within_Ioi hu' s).out 0 3
/-- A set is a neighborhood of `a` within `(a, +β)` if and only if it contains an interval `(a, u)`
with `a < u < u'`, provided `a` is not a top element. -/
lemma mem_nhds_within_Ioi_iff_exists_Ioo_subset' {a u' : Ξ±} {s : set Ξ±} (hu' : a < u') :
s β nhds_within a (Ioi a) β βu β Ioi a, Ioo a u β s :=
(tfae_mem_nhds_within_Ioi hu' s).out 0 4
/-- A set is a neighborhood of `a` within `(a, +β)` if and only if it contains an interval `(a, u)`
with `a < u`. -/
lemma mem_nhds_within_Ioi_iff_exists_Ioo_subset [no_top_order Ξ±] {a : Ξ±} {s : set Ξ±} :
s β nhds_within a (Ioi a) β βu β Ioi a, Ioo a u β s :=
let β¨u', hu'β© := no_top a in mem_nhds_within_Ioi_iff_exists_Ioo_subset' hu'
/-- A set is a neighborhood of `a` within `(a, +β)` if and only if it contains an interval `(a, u]`
with `a < u`. -/
lemma mem_nhds_within_Ioi_iff_exists_Ioc_subset [no_top_order Ξ±] [densely_ordered Ξ±]
{a : Ξ±} {s : set Ξ±} : s β nhds_within a (Ioi a) β βu β Ioi a, Ioc a u β s :=
begin
rw mem_nhds_within_Ioi_iff_exists_Ioo_subset,
split,
{ rintros β¨u, au, asβ©,
rcases dense au with β¨v, hvβ©,
exact β¨v, hv.1, Ξ»x hx, as β¨hx.1, lt_of_le_of_lt hx.2 hv.2β©β© },
{ rintros β¨u, au, asβ©,
exact β¨u, au, subset.trans Ioo_subset_Ioc_self asβ© }
end
lemma Ioo_mem_nhds_within_Ioi {a b c : Ξ±} (H : b β Ico a c) :
Ioo a c β nhds_within b (Ioi b) :=
(mem_nhds_within_Ioi_iff_exists_Ioo_subset' H.2).2 β¨c, H.2, Ioo_subset_Ioo_left H.1β©
lemma Ioc_mem_nhds_within_Ioi {a b c : Ξ±} (H : b β Ico a c) :
Ioc a c β nhds_within b (Ioi b) :=
mem_sets_of_superset (Ioo_mem_nhds_within_Ioi H) Ioo_subset_Ioc_self
lemma Ico_mem_nhds_within_Ioi {a b c : Ξ±} (H : b β Ico a c) :
Ico a c β nhds_within b (Ioi b) :=
mem_sets_of_superset (Ioo_mem_nhds_within_Ioi H) Ioo_subset_Ico_self
lemma Icc_mem_nhds_within_Ioi {a b c : Ξ±} (H : b β Ico a c) :
Icc a c β nhds_within b (Ioi b) :=
mem_sets_of_superset (Ioo_mem_nhds_within_Ioi H) Ioo_subset_Icc_self
/-- The following statements are equivalent:
0. `s` is a neighborhood of `b` within `(-β, b)`
1. `s` is a neighborhood of `b` within `[a, b)`
2. `s` is a neighborhood of `b` within `(a, b)`
3. `s` includes `(l, b)` for some `l β [a, b)`
4. `s` includes `(l, b)` for some `l < b` -/
lemma tfae_mem_nhds_within_Iio {a b : Ξ±} (h : a < b) (s : set Ξ±) :
tfae [s β nhds_within b (Iio b), -- 0 : `s` is a neighborhood of `b` within `(-β, b)`
s β nhds_within b (Ico a b), -- 1 : `s` is a neighborhood of `b` within `[a, b)`
s β nhds_within b (Ioo a b), -- 2 : `s` is a neighborhood of `b` within `(a, b)`
β l β Ico a b, Ioo l b β s, -- 3 : `s` includes `(l, b)` for some `l β [a, b)`
β l β Iio b, Ioo l b β s] := -- 4 : `s` includes `(l, b)` for some `l < b`
begin
have := @tfae_mem_nhds_within_Ioi (order_dual Ξ±) _ _ _ _ _ h s,
-- If we call `convert` here, it generates wrong equations, so we need to simplify first
simp only [exists_prop] at this β’,
rw [dual_Ioi, dual_Ioc, dual_Ioo] at this,
convert this; ext l; rw [dual_Ioo]
end
@[simp] lemma nhds_within_Ico_eq_nhds_within_Iio {a b : Ξ±} (h : a < b) :
nhds_within b (Ico a b) = nhds_within b (Iio b) :=
filter.ext $ Ξ» s, (tfae_mem_nhds_within_Iio h s).out 1 0
@[simp] lemma nhds_within_Ioo_eq_nhds_within_Iio {a b : Ξ±} (h : a < b) :
nhds_within b (Ioo a b) = nhds_within b (Iio b) :=
filter.ext $ Ξ» s, (tfae_mem_nhds_within_Iio h s).out 2 0
lemma mem_nhds_within_Iio_iff_exists_mem_Ico_Ioo_subset {a l' : Ξ±} {s : set Ξ±} (hl' : l' < a) :
s β nhds_within a (Iio a) β βl β Ico l' a, Ioo l a β s :=
(tfae_mem_nhds_within_Iio hl' s).out 0 3
/-- A set is a neighborhood of `a` within `(-β, a)` if and only if it contains an interval `(l, a)`
with `l < a`, provided `a` is not a bottom element. -/
lemma mem_nhds_within_Iio_iff_exists_Ioo_subset' {a l' : Ξ±} {s : set Ξ±} (hl' : l' < a) :
s β nhds_within a (Iio a) β βl β Iio a, Ioo l a β s :=
(tfae_mem_nhds_within_Iio hl' s).out 0 4
/-- A set is a neighborhood of `a` within `(-β, a)` if and only if it contains an interval `(l, a)`
with `l < a`. -/
lemma mem_nhds_within_Iio_iff_exists_Ioo_subset [no_bot_order Ξ±] {a : Ξ±} {s : set Ξ±} :
s β nhds_within a (Iio a) β βl β Iio a, Ioo l a β s :=
let β¨l', hl'β© := no_bot a in mem_nhds_within_Iio_iff_exists_Ioo_subset' hl'
/-- A set is a neighborhood of `a` within `(-β, a)` if and only if it contains an interval `[l, a)`
with `l < a`. -/
lemma mem_nhds_within_Iio_iff_exists_Ico_subset [no_bot_order Ξ±] [densely_ordered Ξ±]
{a : Ξ±} {s : set Ξ±} : s β nhds_within a (Iio a) β βl β Iio a, Ico l a β s :=
begin
convert @mem_nhds_within_Ioi_iff_exists_Ioc_subset (order_dual Ξ±) _ _ _ _ _ _ _,
simp only [dual_Ioc], refl
end
lemma Ioo_mem_nhds_within_Iio {a b c : Ξ±} (h : b β Ioc a c) :
Ioo a c β nhds_within b (Iio b) :=
(mem_nhds_within_Iio_iff_exists_Ioo_subset' h.1).2 β¨a, h.1, Ioo_subset_Ioo_right h.2β©
lemma Ioc_mem_nhds_within_Iio {a b c : Ξ±} (h : b β Ioc a c) :
Ioc a c β nhds_within b (Iio b) :=
mem_sets_of_superset (Ioo_mem_nhds_within_Iio h) Ioo_subset_Ioc_self
lemma Ico_mem_nhds_within_Iio {a b c : Ξ±} (h : b β Ioc a c) :
Ico a c β nhds_within b (Iio b) :=
mem_sets_of_superset (Ioo_mem_nhds_within_Iio h) Ioo_subset_Ico_self
lemma Icc_mem_nhds_within_Iio {a b c : Ξ±} (h : b β Ioc a c) :
Icc a c β nhds_within b (Iio b) :=
mem_sets_of_superset (Ioo_mem_nhds_within_Iio h) Ioo_subset_Icc_self
/-- A set is a neighborhood of `a` within `[a, +β)` if and only if it contains an interval `[a, u)`
with `a < u`, provided `a` is not a top element. -/
lemma mem_nhds_within_Ici_iff_exists_Ico_subset' {a u' : Ξ±} {s : set Ξ±} (hu' : a < u') :
s β nhds_within a (Ici a) β βu, a < u β§ Ico a u β s :=
begin
split,
{ assume h,
rcases mem_nhds_within_iff_exists_mem_nhds_inter.1 h with β¨v, va, hvβ©,
rcases exists_Ico_subset_of_mem_nhds va β¨u', hu'β© with β¨u, au, huβ©,
refine β¨u, au, Ξ»x hx, _β©,
refine hv β¨_, hx.1β©,
exact hu hx },
{ rintros β¨u, au, huβ©,
rw mem_nhds_within_iff_exists_mem_nhds_inter,
refine β¨Iio u, mem_nhds_sets is_open_Iio au, _β©,
rwa [inter_comm, Ici_inter_Iio] }
end
/-- A set is a neighborhood of `a` within `[a, +β)` if and only if it contains an interval `[a, u)`
with `a < u`. -/
lemma mem_nhds_within_Ici_iff_exists_Ico_subset [no_top_order Ξ±] {a : Ξ±} {s : set Ξ±} :
s β nhds_within a (Ici a) β βu, a < u β§ Ico a u β s :=
let β¨u', hu'β© := no_top a in mem_nhds_within_Ici_iff_exists_Ico_subset' hu'
/-- A set is a neighborhood of `a` within `[a, +β)` if and only if it contains an interval `[a, u]`
with `a < u`. -/
lemma mem_nhds_within_Ici_iff_exists_Icc_subset [no_top_order Ξ±] [densely_ordered Ξ±]
{a : Ξ±} {s : set Ξ±} : s β nhds_within a (Ici a) β βu, a < u β§ Icc a u β s :=
begin
rw mem_nhds_within_Ici_iff_exists_Ico_subset,
split,
{ rintros β¨u, au, asβ©,
rcases dense au with β¨v, hvβ©,
exact β¨v, hv.1, Ξ»x hx, as β¨hx.1, lt_of_le_of_lt hx.2 hv.2β©β© },
{ rintros β¨u, au, asβ©,
exact β¨u, au, subset.trans Ico_subset_Icc_self asβ© }
end
/-- A set is a neighborhood of `a` within `(-β, a]` if and only if it contains an interval `(l, a]`
with `l < a`, provided `a` is not a bottom element. -/
lemma mem_nhds_within_Iic_iff_exists_Ioc_subset' {a l' : Ξ±} {s : set Ξ±} (hl' : l' < a) :
s β nhds_within a (Iic a) β βl, l < a β§ Ioc l a β s :=
begin
split,
{ assume h,
rcases mem_nhds_within_iff_exists_mem_nhds_inter.1 h with β¨v, va, hvβ©,
rcases exists_Ioc_subset_of_mem_nhds va β¨l', hl'β© with β¨l, la, hlβ©,
refine β¨l, la, Ξ»x hx, _β©,
refine hv β¨_, hx.2β©,
exact hl hx },
{ rintros β¨l, la, haβ©,
rw mem_nhds_within_iff_exists_mem_nhds_inter,
refine β¨Ioi l, mem_nhds_sets is_open_Ioi la, _β©,
rwa [Ioi_inter_Iic] }
end
/-- A set is a neighborhood of `a` within `(-β, a]` if and only if it contains an interval `(l, a]`
with `l < a`. -/
lemma mem_nhds_within_Iic_iff_exists_Ioc_subset [no_bot_order Ξ±] {a : Ξ±} {s : set Ξ±} :
s β nhds_within a (Iic a) β βl, l < a β§ Ioc l a β s :=
let β¨l', hl'β© := no_bot a in mem_nhds_within_Iic_iff_exists_Ioc_subset' hl'
/-- A set is a neighborhood of `a` within `(-β, a]` if and only if it contains an interval `[l, a]`
with `l < a`. -/
lemma mem_nhds_within_Iic_iff_exists_Icc_subset [no_bot_order Ξ±] [densely_ordered Ξ±]
{a : Ξ±} {s : set Ξ±} : s β nhds_within a (Iic a) β βl, l < a β§ Icc l a β s :=
begin
rw mem_nhds_within_Iic_iff_exists_Ioc_subset,
split,
{ rintros β¨l, la, asβ©,
rcases dense la with β¨v, hvβ©,
refine β¨v, hv.2, Ξ»x hx, as β¨lt_of_lt_of_le hv.1 hx.1, hx.2β©β©, },
{ rintros β¨l, la, asβ©,
exact β¨l, la, subset.trans Ioc_subset_Icc_self asβ© }
end
end linear_order
lemma preimage_neg [add_group Ξ±] : preimage (has_neg.neg : Ξ± β Ξ±) = image (has_neg.neg : Ξ± β Ξ±) :=
(image_eq_preimage_of_inverse neg_neg neg_neg).symm
lemma filter.map_neg [add_group Ξ±] : map (has_neg.neg : Ξ± β Ξ±) = comap (has_neg.neg : Ξ± β Ξ±) :=
funext $ assume f, map_eq_comap_of_inverse (funext neg_neg) (funext neg_neg)
section topological_add_group
variables [topological_space Ξ±] [ordered_add_comm_group Ξ±] [topological_add_group Ξ±]
lemma neg_preimage_closure {s : set Ξ±} : (Ξ»r:Ξ±, -r) β»ΒΉ' closure s = closure ((Ξ»r:Ξ±, -r) '' s) :=
have (Ξ»r:Ξ±, -r) β (Ξ»r:Ξ±, -r) = id, from funext neg_neg,
by rw [preimage_neg]; exact
(subset.antisymm (image_closure_subset_closure_image continuous_neg) $
calc closure ((Ξ» (r : Ξ±), -r) '' s) = (Ξ»r, -r) '' ((Ξ»r, -r) '' closure ((Ξ» (r : Ξ±), -r) '' s)) :
by rw [βimage_comp, this, image_id]
... β (Ξ»r, -r) '' closure ((Ξ»r, -r) '' ((Ξ» (r : Ξ±), -r) '' s)) :
monotone_image $ image_closure_subset_closure_image continuous_neg
... = _ : by rw [βimage_comp, this, image_id])
end topological_add_group
section order_topology
variables [topological_space Ξ±] [topological_space Ξ²]
[linear_order Ξ±] [linear_order Ξ²] [order_topology Ξ±] [order_topology Ξ²]
lemma nhds_principal_ne_bot_of_is_lub {a : Ξ±} {s : set Ξ±} (ha : is_lub s a) (hs : s.nonempty) :
π a β principal s β β₯ :=
let β¨a', ha'β© := hs in
forall_sets_nonempty_iff_ne_bot.mp $ assume t ht,
let β¨tβ, htβ, tβ, htβ, htβ© := mem_inf_sets.mp ht in
by_cases
(assume h : a = a',
have a β tβ, from mem_of_nhds htβ,
have a β tβ, from htβ $ by rwa [h],
β¨a, ht β¨βΉa β tββΊ, βΉa β tββΊβ©β©)
(assume : a β a',
have a' < a, from lt_of_le_of_ne (ha.left βΉa' β sβΊ) this.symm,
let β¨l, hl, hltββ© := exists_Ioc_subset_of_mem_nhds htβ β¨a', thisβ© in
have βa'βs, l < a',
from classical.by_contradiction $ assume : Β¬ βa'βs, l < a',
have βa'βs, a' β€ l, from assume a ha, not_lt.1 $ assume ha', this β¨a, ha, ha'β©,
have Β¬ l < a, from not_lt.2 $ ha.right this,
this βΉl < aβΊ,
let β¨a', ha', ha'lβ© := this in
have a' β tβ, from hltβ β¨βΉl < a'βΊ, ha.left ha'β©,
β¨a', ht β¨βΉa' β tββΊ, htβ βΉa' β sβΊβ©β©)
lemma nhds_principal_ne_bot_of_is_glb : β {a : Ξ±} {s : set Ξ±}, is_glb s a β s.nonempty β
π a β principal s β β₯ :=
@nhds_principal_ne_bot_of_is_lub (order_dual Ξ±) _ _ _
lemma is_lub_of_mem_nhds {s : set Ξ±} {a : Ξ±} {f : filter Ξ±}
(hsa : a β upper_bounds s) (hsf : s β f) (hfa : f β π a β β₯) : is_lub s a :=
β¨hsa, assume b hb,
not_lt.1 $ assume hba,
have s β© {a | b < a} β f β π a,
from inter_mem_inf_sets hsf (mem_nhds_sets (is_open_lt' _) hba),
let β¨x, β¨hxs, hxbβ©β© := nonempty_of_mem_sets hfa this in
have b < b, from lt_of_lt_of_le hxb $ hb hxs,
lt_irrefl b thisβ©
lemma is_glb_of_mem_nhds : β {s : set Ξ±} {a : Ξ±} {f : filter Ξ±},
a β lower_bounds s β s β f β f β π a β β₯ β is_glb s a :=
@is_lub_of_mem_nhds (order_dual Ξ±) _ _ _
lemma is_lub_of_is_lub_of_tendsto {f : Ξ± β Ξ²} {s : set Ξ±} {a : Ξ±} {b : Ξ²}
(hf : βxβs, βyβs, x β€ y β f x β€ f y) (ha : is_lub s a) (hs : s.nonempty)
(hb : tendsto f (π a β principal s) (π b)) : is_lub (f '' s) b :=
have hnbot : (π a β principal s) β β₯, from nhds_principal_ne_bot_of_is_lub ha hs,
have βa'βs, Β¬ b < f a',
from assume a' ha' h,
have βαΆ x in π b, x < f a', from mem_nhds_sets (is_open_gt' _) h,
let β¨tβ, htβ, tβ, htβ, hsβ© := mem_inf_sets.mp (hb this) in
by_cases
(assume h : a = a',
have a β tβ β© tβ, from β¨mem_of_nhds htβ, htβ $ by rwa [h]β©,
have f a < f a', from hs this,
lt_irrefl (f a') $ by rwa [h] at this)
(assume h : a β a',
have a' < a, from lt_of_le_of_ne (ha.left ha') h.symm,
have {x | a' < x} β π a, from mem_nhds_sets (is_open_lt' _) this,
have {x | a' < x} β© tβ β π a, from inter_mem_sets this htβ,
have ({x | a' < x} β© tβ) β© s β π a β principal s,
from inter_mem_inf_sets this (subset.refl s),
let β¨x, β¨hxβ, hxββ©, hxββ© := nonempty_of_mem_sets hnbot this in
have hxa' : f x < f a', from hs β¨hxβ, htβ hxββ©,
have ha'x : f a' β€ f x, from hf _ ha' _ hxβ $ le_of_lt hxβ,
lt_irrefl _ (lt_of_le_of_lt ha'x hxa')),
and.intro
(assume b' β¨a', ha', h_eqβ©, h_eq βΈ not_lt.1 $ this _ ha')
(assume b' hb', le_of_tendsto hnbot hb $
mem_inf_sets_of_right $ assume x hx, hb' $ mem_image_of_mem _ hx)
lemma is_glb_of_is_glb_of_tendsto {f : Ξ± β Ξ²} {s : set Ξ±} {a : Ξ±} {b : Ξ²}
(hf : βxβs, βyβs, x β€ y β f x β€ f y) : is_glb s a β s.nonempty β
tendsto f (π a β principal s) (π b) β is_glb (f '' s) b :=
@is_lub_of_is_lub_of_tendsto (order_dual Ξ±) (order_dual Ξ²) _ _ _ _ _ _ f s a b
(Ξ» x hx y hy, hf y hy x hx)
lemma is_glb_of_is_lub_of_tendsto : β {f : Ξ± β Ξ²} {s : set Ξ±} {a : Ξ±} {b : Ξ²},
(βxβs, βyβs, x β€ y β f y β€ f x) β is_lub s a β s.nonempty β
tendsto f (π a β principal s) (π b) β is_glb (f '' s) b :=
@is_lub_of_is_lub_of_tendsto Ξ± (order_dual Ξ²) _ _ _ _ _ _
lemma is_lub_of_is_glb_of_tendsto : β {f : Ξ± β Ξ²} {s : set Ξ±} {a : Ξ±} {b : Ξ²},
(βxβs, βyβs, x β€ y β f y β€ f x) β is_glb s a β s.nonempty β
tendsto f (π a β principal s) (π b) β is_lub (f '' s) b :=
@is_glb_of_is_glb_of_tendsto Ξ± (order_dual Ξ²) _ _ _ _ _ _
lemma mem_closure_of_is_lub {a : Ξ±} {s : set Ξ±} (ha : is_lub s a) (hs : s.nonempty) : a β closure s :=
by rw closure_eq_nhds; exact nhds_principal_ne_bot_of_is_lub ha hs
lemma mem_of_is_lub_of_is_closed {a : Ξ±} {s : set Ξ±} (ha : is_lub s a) (hs : s.nonempty) (sc : is_closed s) : a β s :=
by rw βclosure_eq_of_is_closed sc; exact mem_closure_of_is_lub ha hs
lemma mem_closure_of_is_glb {a : Ξ±} {s : set Ξ±} (ha : is_glb s a) (hs : s.nonempty) : a β closure s :=
by rw closure_eq_nhds; exact nhds_principal_ne_bot_of_is_glb ha hs
lemma mem_of_is_glb_of_is_closed {a : Ξ±} {s : set Ξ±} (ha : is_glb s a) (hs : s.nonempty) (sc : is_closed s) : a β s :=
by rw βclosure_eq_of_is_closed sc; exact mem_closure_of_is_glb ha hs
/-- A compact set is bounded below -/
lemma bdd_below_of_compact {Ξ± : Type u} [topological_space Ξ±] [linear_order Ξ±]
[order_closed_topology Ξ±] [nonempty Ξ±] {s : set Ξ±} (hs : compact s) : bdd_below s :=
begin
by_contra H,
letI := classical.DLO Ξ±,
rcases hs.elim_finite_subcover_image (Ξ» x (_ : x β s), @is_open_Ioi _ _ _ _ x) _
with β¨t, st, ft, htβ©,
{ refine H ((bdd_below_finite ft).imp $ Ξ» C hC y hy, _),
rcases mem_bUnion_iff.1 (ht hy) with β¨x, hx, xyβ©,
exact le_trans (hC hx) (le_of_lt xy) },
{ refine Ξ» x hx, mem_bUnion_iff.2 (not_imp_comm.1 _ H),
exact Ξ» h, β¨x, Ξ» y hy, le_of_not_lt (h.imp $ Ξ» ys, β¨_, hy, ysβ©)β© }
end
/-- A compact set is bounded above -/
lemma bdd_above_of_compact {Ξ± : Type u} [topological_space Ξ±] [linear_order Ξ±]
[order_topology Ξ±] : Ξ [nonempty Ξ±] {s : set Ξ±}, compact s β bdd_above s :=
@bdd_below_of_compact (order_dual Ξ±) _ _ _
end order_topology
section linear_order
variables [topological_space Ξ±] [linear_order Ξ±] [order_topology Ξ±] [densely_ordered Ξ±]
/-- The closure of the interval `(a, +β)` is the closed interval `[a, +β)`, unless `a` is a top
element. -/
lemma closure_Ioi' {a b : Ξ±} (hab : a < b) :
closure (Ioi a) = Ici a :=
begin
apply subset.antisymm,
{ exact closure_minimal Ioi_subset_Ici_self is_closed_Ici },
{ assume x hx,
by_cases h : x = a,
{ rw h, exact mem_closure_of_is_glb is_glb_Ioi β¨_, habβ© },
{ exact subset_closure (lt_of_le_of_ne hx (ne.symm h)) } }
end
/-- The closure of the interval `(a, +β)` is the closed interval `[a, +β)`. -/
lemma closure_Ioi (a : Ξ±) [no_top_order Ξ±] :
closure (Ioi a) = Ici a :=
let β¨b, hbβ© := no_top a in closure_Ioi' hb
/-- The closure of the interval `(-β, a)` is the closed interval `(-β, a]`, unless `a` is a bottom
element. -/
lemma closure_Iio' {a b : Ξ±} (hab : b < a) :
closure (Iio a) = Iic a :=
begin
apply subset.antisymm,
{ exact closure_minimal Iio_subset_Iic_self is_closed_Iic },
{ assume x hx,
by_cases h : x = a,
{ rw h, exact mem_closure_of_is_lub is_lub_Iio β¨_, habβ© },
{ apply subset_closure, by simpa [h] using lt_or_eq_of_le hx } }
end
/-- The closure of the interval `(-β, a)` is the interval `(-β, a]`. -/
lemma closure_Iio (a : Ξ±) [no_bot_order Ξ±] :
closure (Iio a) = Iic a :=
let β¨b, hbβ© := no_bot a in closure_Iio' hb
/-- The closure of the open interval `(a, b)` is the closed interval `[a, b]`. -/
lemma closure_Ioo {a b : Ξ±} (hab : a < b) :
closure (Ioo a b) = Icc a b :=
begin
apply subset.antisymm,
{ exact closure_minimal Ioo_subset_Icc_self is_closed_Icc },
{ have hab' : (Ioo a b).nonempty, from nonempty_Ioo.2 hab,
assume x hx,
by_cases h : x = a,
{ rw h, exact mem_closure_of_is_glb (is_glb_Ioo hab) hab' },
by_cases h' : x = b,
{ rw h', refine mem_closure_of_is_lub (is_lub_Ioo hab) hab' },
exact subset_closure β¨lt_of_le_of_ne hx.1 (ne.symm h), by simpa [h'] using lt_or_eq_of_le hx.2β© }
end
/-- The closure of the interval `(a, b]` is the closed interval `[a, b]`. -/
lemma closure_Ioc {a b : Ξ±} (hab : a < b) :
closure (Ioc a b) = Icc a b :=
begin
apply subset.antisymm,
{ exact closure_minimal Ioc_subset_Icc_self is_closed_Icc },
{ apply subset.trans _ (closure_mono Ioo_subset_Ioc_self),
rw closure_Ioo hab }
end
/-- The closure of the interval `[a, b)` is the closed interval `[a, b]`. -/
lemma closure_Ico {a b : Ξ±} (hab : a < b) :
closure (Ico a b) = Icc a b :=
begin
apply subset.antisymm,
{ exact closure_minimal Ico_subset_Icc_self is_closed_Icc },
{ apply subset.trans _ (closure_mono Ioo_subset_Ico_self),
rw closure_Ioo hab }
end
@[simp] lemma interior_Ici [no_bot_order Ξ±] {a : Ξ±} : interior (Ici a) = Ioi a :=
by rw [β compl_Iio, interior_compl, closure_Iio, compl_Iic]
@[simp] lemma interior_Iic [no_top_order Ξ±] {a : Ξ±} : interior (Iic a) = Iio a :=
by rw [β compl_Ioi, interior_compl, closure_Ioi, compl_Ici]
@[simp] lemma interior_Icc [no_bot_order Ξ±] [no_top_order Ξ±] {a b : Ξ±}:
interior (Icc a b) = Ioo a b :=
by rw [β Ici_inter_Iic, interior_inter, interior_Ici, interior_Iic, Ioi_inter_Iio]
@[simp] lemma interior_Ico [no_bot_order Ξ±] {a b : Ξ±} : interior (Ico a b) = Ioo a b :=
by rw [β Ici_inter_Iio, interior_inter, interior_Ici, interior_Iio, Ioi_inter_Iio]
@[simp] lemma interior_Ioc [no_top_order Ξ±] {a b : Ξ±} : interior (Ioc a b) = Ioo a b :=
by rw [β Ioi_inter_Iic, interior_inter, interior_Ioi, interior_Iic, Ioi_inter_Iio]
lemma nhds_within_Ioi_ne_bot' {a b c : Ξ±} (Hβ : a < c) (Hβ : a β€ b) :
nhds_within b (Ioi a) β β₯ :=
mem_closure_iff_nhds_within_ne_bot.1 $ by { rw [closure_Ioi' Hβ], exact Hβ }
lemma nhds_within_Ioi_ne_bot [no_top_order Ξ±] {a b : Ξ±} (H : a β€ b) :
nhds_within b (Ioi a) β β₯ :=
let β¨c, hcβ© := no_top a in nhds_within_Ioi_ne_bot' hc H
lemma nhds_within_Ioi_self_ne_bot' {a b : Ξ±} (H : a < b) :
nhds_within a (Ioi a) β β₯ :=
nhds_within_Ioi_ne_bot' H (le_refl a)
lemma nhds_within_Ioi_self_ne_bot [no_top_order Ξ±] (a : Ξ±) :
nhds_within a (Ioi a) β β₯ :=
nhds_within_Ioi_ne_bot (le_refl a)
lemma nhds_within_Iio_ne_bot' {a b c : Ξ±} (Hβ : a < c) (Hβ : b β€ c) :
nhds_within b (Iio c) β β₯ :=
mem_closure_iff_nhds_within_ne_bot.1 $ by { rw [closure_Iio' Hβ], exact Hβ }
lemma nhds_within_Iio_ne_bot [no_bot_order Ξ±] {a b : Ξ±} (H : a β€ b) :
nhds_within a (Iio b) β β₯ :=
let β¨c, hcβ© := no_bot b in nhds_within_Iio_ne_bot' hc H
lemma nhds_within_Iio_self_ne_bot' {a b : Ξ±} (H : a < b) :
nhds_within b (Iio b) β β₯ :=
nhds_within_Iio_ne_bot' H (le_refl b)
lemma nhds_within_Iio_self_ne_bot [no_bot_order Ξ±] (a : Ξ±) :
nhds_within a (Iio a) β β₯ :=
nhds_within_Iio_ne_bot (le_refl a)
end linear_order
section complete_linear_order
variables [complete_linear_order Ξ±] [topological_space Ξ±] [order_topology Ξ±]
[complete_linear_order Ξ²] [topological_space Ξ²] [order_topology Ξ²] [nonempty Ξ³]
lemma Sup_mem_closure {Ξ± : Type u} [topological_space Ξ±] [complete_linear_order Ξ±] [order_topology Ξ±]
{s : set Ξ±} (hs : s.nonempty) : Sup s β closure s :=
mem_closure_of_is_lub (is_lub_Sup _) hs
lemma Inf_mem_closure {Ξ± : Type u} [topological_space Ξ±] [complete_linear_order Ξ±] [order_topology Ξ±]
{s : set Ξ±} (hs : s.nonempty) : Inf s β closure s :=
mem_closure_of_is_glb (is_glb_Inf _) hs
lemma Sup_mem_of_is_closed {Ξ± : Type u} [topological_space Ξ±] [complete_linear_order Ξ±] [order_topology Ξ±]
{s : set Ξ±} (hs : s.nonempty) (hc : is_closed s) : Sup s β s :=
mem_of_is_lub_of_is_closed (is_lub_Sup _) hs hc
lemma Inf_mem_of_is_closed {Ξ± : Type u} [topological_space Ξ±] [complete_linear_order Ξ±] [order_topology Ξ±]
{s : set Ξ±} (hs : s.nonempty) (hc : is_closed s) : Inf s β s :=
mem_of_is_glb_of_is_closed (is_glb_Inf _) hs hc
/-- A continuous monotone function sends supremum to supremum for nonempty sets. -/
lemma Sup_of_continuous' {f : Ξ± β Ξ²} (Mf : continuous f) (Cf : monotone f)
{s : set Ξ±} (hs : s.nonempty) : f (Sup s) = Sup (f '' s) :=
--This is a particular case of the more general is_lub_of_is_lub_of_tendsto
(is_lub_of_is_lub_of_tendsto (Ξ» x hx y hy xy, Cf xy) (is_lub_Sup _) hs $
tendsto_le_left inf_le_left (Mf.tendsto _)).Sup_eq.symm
/-- A continuous monotone function sending bot to bot sends supremum to supremum. -/
lemma Sup_of_continuous {f : Ξ± β Ξ²} (Mf : continuous f) (Cf : monotone f)
(fbot : f β₯ = β₯) {s : set Ξ±} : f (Sup s) = Sup (f '' s) :=
begin
cases s.eq_empty_or_nonempty with h h,
{ simp [h, fbot] },
{ exact Sup_of_continuous' Mf Cf h }
end
/-- A continuous monotone function sends indexed supremum to indexed supremum. -/
lemma supr_of_continuous' {ΞΉ : Sort*} [nonempty ΞΉ] {f : Ξ± β Ξ²} {g : ΞΉ β Ξ±}
(Mf : continuous f) (Cf : monotone f) : f (supr g) = supr (f β g) :=
by rw [supr, Sup_of_continuous' Mf Cf (range_nonempty g), β range_comp, supr]
/-- A continuous monotone function sends indexed supremum to indexed supremum. -/
lemma supr_of_continuous {ΞΉ : Sort*} {f : Ξ± β Ξ²} {g : ΞΉ β Ξ±}
(Mf : continuous f) (Cf : monotone f) (fbot : f β₯ = β₯) : f (supr g) = supr (f β g) :=
by rw [supr, Sup_of_continuous Mf Cf fbot, β range_comp, supr]
/-- A continuous monotone function sends infimum to infimum for nonempty sets. -/
lemma Inf_of_continuous' {f : Ξ± β Ξ²} (Mf : continuous f) (Cf : monotone f)
{s : set Ξ±} (hs : s.nonempty) : f (Inf s) = Inf (f '' s) :=
(is_glb_of_is_glb_of_tendsto (Ξ» x hx y hy xy, Cf xy) (is_glb_Inf _) hs $
tendsto_le_left inf_le_left (Mf.tendsto _)).Inf_eq.symm
/-- A continuous monotone function sending top to top sends infimum to infimum. -/
lemma Inf_of_continuous {f : Ξ± β Ξ²} (Mf : continuous f) (Cf : monotone f)
(ftop : f β€ = β€) {s : set Ξ±} : f (Inf s) = Inf (f '' s) :=
begin
cases s.eq_empty_or_nonempty with h h,
{ simpa [h] },
{ exact Inf_of_continuous' Mf Cf h }
end
/-- A continuous monotone function sends indexed infimum to indexed infimum. -/
lemma infi_of_continuous' {ΞΉ : Sort*} [nonempty ΞΉ] {f : Ξ± β Ξ²} {g : ΞΉ β Ξ±}
(Mf : continuous f) (Cf : monotone f) : f (infi g) = infi (f β g) :=
by rw [infi, Inf_of_continuous' Mf Cf (range_nonempty g), β range_comp, infi]
/-- A continuous monotone function sends indexed infimum to indexed infimum. -/
lemma infi_of_continuous {ΞΉ : Sort*} {f : Ξ± β Ξ²} {g : ΞΉ β Ξ±}
(Mf : continuous f) (Cf : monotone f) (ftop : f β€ = β€) : f (infi g) = infi (f β g) :=
by rw [infi, Inf_of_continuous Mf Cf ftop, β range_comp, infi]
end complete_linear_order
section conditionally_complete_linear_order
variables [conditionally_complete_linear_order Ξ±] [topological_space Ξ±] [order_topology Ξ±]
[conditionally_complete_linear_order Ξ²] [topological_space Ξ²] [order_topology Ξ²] [nonempty Ξ³]
lemma cSup_mem_closure {Ξ± : Type u} [topological_space Ξ±] [conditionally_complete_linear_order Ξ±] [order_topology Ξ±]
{s : set Ξ±} (hs : s.nonempty) (B : bdd_above s) : Sup s β closure s :=
mem_closure_of_is_lub (is_lub_cSup hs B) hs
lemma cInf_mem_closure {Ξ± : Type u} [topological_space Ξ±] [conditionally_complete_linear_order Ξ±] [order_topology Ξ±]
{s : set Ξ±} (hs : s.nonempty) (B : bdd_below s) : Inf s β closure s :=
mem_closure_of_is_glb (is_glb_cInf hs B) hs
lemma cSup_mem_of_is_closed {Ξ± : Type u} [topological_space Ξ±] [conditionally_complete_linear_order Ξ±] [order_topology Ξ±]
{s : set Ξ±} (hs : s.nonempty) (hc : is_closed s) (B : bdd_above s) : Sup s β s :=
mem_of_is_lub_of_is_closed (is_lub_cSup hs B) hs hc
lemma cInf_mem_of_is_closed {Ξ± : Type u} [topological_space Ξ±] [conditionally_complete_linear_order Ξ±] [order_topology Ξ±]
{s : set Ξ±} (hs : s.nonempty) (hc : is_closed s) (B : bdd_below s) : Inf s β s :=
mem_of_is_glb_of_is_closed (is_glb_cInf hs B) hs hc
/-- A continuous monotone function sends supremum to supremum in conditionally complete
lattices, under a boundedness assumption. -/
lemma cSup_of_cSup_of_monotone_of_continuous {f : Ξ± β Ξ²} (Mf : continuous f) (Cf : monotone f)
{s : set Ξ±} (ne : s.nonempty) (H : bdd_above s) : f (Sup s) = Sup (f '' s) :=
begin
refine ((is_lub_cSup (ne.image f) (Cf.map_bdd_above H)).unique _).symm,
refine is_lub_of_is_lub_of_tendsto (Ξ»x hx y hy xy, Cf xy) (is_lub_cSup ne H) ne _,
exact tendsto_le_left inf_le_left (Mf.tendsto _)
end
/-- A continuous monotone function sends indexed supremum to indexed supremum in conditionally complete
lattices, under a boundedness assumption. -/
lemma csupr_of_csupr_of_monotone_of_continuous {f : Ξ± β Ξ²} {g : Ξ³ β Ξ±}
(Mf : continuous f) (Cf : monotone f) (H : bdd_above (range g)) : f (supr g) = supr (f β g) :=
by rw [supr, cSup_of_cSup_of_monotone_of_continuous Mf Cf (range_nonempty _) H, β range_comp, supr]
/-- A continuous monotone function sends infimum to infimum in conditionally complete
lattices, under a boundedness assumption. -/
lemma cInf_of_cInf_of_monotone_of_continuous {f : Ξ± β Ξ²} (Mf : continuous f) (Cf : monotone f)
{s : set Ξ±} (ne : s.nonempty) (H : bdd_below s) : f (Inf s) = Inf (f '' s) :=
begin
refine ((is_glb_cInf (ne.image _) (Cf.map_bdd_below H)).unique _).symm,
refine is_glb_of_is_glb_of_tendsto (Ξ»x hx y hy xy, Cf xy) (is_glb_cInf ne H) ne _,
exact tendsto_le_left inf_le_left (Mf.tendsto _)
end
/-- A continuous monotone function sends indexed infimum to indexed infimum in conditionally complete
lattices, under a boundedness assumption. -/
lemma cinfi_of_cinfi_of_monotone_of_continuous {f : Ξ± β Ξ²} {g : Ξ³ β Ξ±}
(Mf : continuous f) (Cf : monotone f) (H : bdd_below (range g)) : f (infi g) = infi (f β g) :=
by rw [infi, cInf_of_cInf_of_monotone_of_continuous Mf Cf (range_nonempty _) H, β range_comp, infi]
/-- A "continuous induction principle" for a closed interval: if a set `s` meets `[a, b]`
on a closed subset, contains `a`, and the set `s β© [a, b)` has no maximal point, then `b β s`. -/
lemma is_closed.mem_of_ge_of_forall_exists_gt {a b : Ξ±} {s : set Ξ±} (hs : is_closed (s β© Icc a b))
(ha : a β s) (hab : a β€ b) (hgt : β x β s β© Ico a b, (s β© Ioc x b).nonempty) :
b β s :=
begin
let S := s β© Icc a b,
replace ha : a β S, from β¨ha, left_mem_Icc.2 habβ©,
have Sbd : bdd_above S, from β¨b, Ξ» z hz, hz.2.2β©,
let c := Sup (s β© Icc a b),
have c_mem : c β S, from cSup_mem_of_is_closed β¨_, haβ© hs Sbd,
have c_le : c β€ b, from cSup_le β¨_, haβ© (Ξ» x hx, hx.2.2),
cases eq_or_lt_of_le c_le with hc hc, from hc βΈ c_mem.1,
exfalso,
rcases hgt c β¨c_mem.1, c_mem.2.1, hcβ© with β¨x, xs, cx, xbβ©,
exact not_lt_of_le (le_cSup Sbd β¨xs, le_trans (le_cSup Sbd ha) (le_of_lt cx), xbβ©) cx
end
/-- A "continuous induction principle" for a closed interval: if a set `s` meets `[a, b]`
on a closed subset, contains `a`, and for any `a β€ x < y β€ b`, `x β s`, the set `s β© (x, y]`
is not empty, then `[a, b] β s`. -/
lemma is_closed.Icc_subset_of_forall_exists_gt {a b : Ξ±} {s : set Ξ±} (hs : is_closed (s β© Icc a b))
(ha : a β s) (hgt : β x β s β© Ico a b, β y β Ioi x, (s β© Ioc x y).nonempty) :
Icc a b β s :=
begin
assume y hy,
have : is_closed (s β© Icc a y),
{ suffices : s β© Icc a y = s β© Icc a b β© Icc a y,
{ rw this, exact is_closed_inter hs is_closed_Icc },
rw [inter_assoc],
congr,
exact (inter_eq_self_of_subset_right $ Icc_subset_Icc_right hy.2).symm },
exact is_closed.mem_of_ge_of_forall_exists_gt this ha hy.1
(Ξ» x hx, hgt x β¨hx.1, Ico_subset_Ico_right hy.2 hx.2β© y hx.2.2)
end
section densely_ordered
variables [densely_ordered Ξ±] {a b : Ξ±}
/-- A "continuous induction principle" for a closed interval: if a set `s` meets `[a, b]`
on a closed subset, contains `a`, and for any `x β s β© [a, b)` the set `s` includes some open
neighborhood of `x` within `(x, +β)`, then `[a, b] β s`. -/
lemma is_closed.Icc_subset_of_forall_mem_nhds_within {a b : Ξ±} {s : set Ξ±}
(hs : is_closed (s β© Icc a b)) (ha : a β s)
(hgt : β x β s β© Ico a b, s β nhds_within x (Ioi x)) :
Icc a b β s :=
begin
apply hs.Icc_subset_of_forall_exists_gt ha,
rintros x β¨hxs, hxabβ© y hyxb,
have : s β© Ioc x y β nhds_within x (Ioi x),
from inter_mem_sets (hgt x β¨hxs, hxabβ©) (Ioc_mem_nhds_within_Ioi β¨le_refl _, hyxbβ©),
exact nonempty_of_mem_sets (nhds_within_Ioi_self_ne_bot' hxab.2) this
end
/-- A closed interval is preconnected. -/
lemma is_connected_Icc : is_preconnected (Icc a b) :=
is_preconnected_closed_iff.2
begin
rintros s t hs ht hab β¨x, hxβ© β¨y, hyβ©,
wlog hxy : x β€ y := le_total x y using [x y s t, y x t s],
have xyab : Icc x y β Icc a b := Icc_subset_Icc hx.1.1 hy.1.2,
by_contradiction hst,
suffices : Icc x y β s,
from hst β¨y, xyab $ right_mem_Icc.2 hxy, this $ right_mem_Icc.2 hxy, hy.2β©,
apply (is_closed_inter hs is_closed_Icc).Icc_subset_of_forall_mem_nhds_within hx.2,
rintros z β¨zs, hzβ©,
have zt : z β -t, from Ξ» zt, hst β¨z, xyab $ Ico_subset_Icc_self hz, zs, ztβ©,
have : -t β© Ioc z y β nhds_within z (Ioi z),
{ rw [β nhds_within_Ioc_eq_nhds_within_Ioi hz.2],
exact mem_nhds_within.2 β¨-t, ht, zt, subset.refl _β©},
apply mem_sets_of_superset this,
have : Ioc z y β s βͺ t, from Ξ» w hw, hab (xyab β¨le_trans hz.1 (le_of_lt hw.1), hw.2β©),
exact Ξ» w β¨wt, wzyβ©, (this wzy).elim id (Ξ» h, (wt h).elim)
end
lemma is_preconnected_iff_forall_Icc_subset {s : set Ξ±} :
is_preconnected s β β x y β s, x β€ y β Icc x y β s :=
β¨Ξ» h x y hx hy hxy, h.forall_Icc_subset hx hy, Ξ» h, is_preconnected_of_forall_pair $ Ξ» x y hx hy,
β¨Icc (min x y) (max x y), h (min x y) (max x y)
((min_choice x y).elim (Ξ» h', by rwa h') (Ξ» h', by rwa h'))
((max_choice x y).elim (Ξ» h', by rwa h') (Ξ» h', by rwa h')) min_le_max,
β¨min_le_left x y, le_max_left x yβ©, β¨min_le_right x y, le_max_right x yβ©, is_connected_Iccβ©β©
lemma is_preconnected_Ici : is_preconnected (Ici a) :=
is_preconnected_iff_forall_Icc_subset.2 $ Ξ» x y hx hy hxy, (Icc_subset_Ici_iff hxy).2 hx
lemma is_preconnected_Iic : is_preconnected (Iic a) :=
is_preconnected_iff_forall_Icc_subset.2 $ Ξ» x y hx hy hxy, (Icc_subset_Iic_iff hxy).2 hy
lemma is_preconnected_Iio : is_preconnected (Iio a) :=
is_preconnected_iff_forall_Icc_subset.2 $ Ξ» x y hx hy hxy, (Icc_subset_Iio_iff hxy).2 hy
lemma is_preconnected_Ioi : is_preconnected (Ioi a) :=
is_preconnected_iff_forall_Icc_subset.2 $ Ξ» x y hx hy hxy, (Icc_subset_Ioi_iff hxy).2 hx
lemma is_connected_Ioo : is_preconnected (Ioo a b) :=
is_preconnected_iff_forall_Icc_subset.2 $ Ξ» x y hx hy hxy, (Icc_subset_Ioo_iff hxy).2 β¨hx.1, hy.2β©
lemma is_preconnected_Ioc : is_preconnected (Ioc a b) :=
is_preconnected_iff_forall_Icc_subset.2 $ Ξ» x y hx hy hxy, (Icc_subset_Ioc_iff hxy).2 β¨hx.1, hy.2β©
lemma is_preconnected_Ico : is_preconnected (Ico a b) :=
is_preconnected_iff_forall_Icc_subset.2 $ Ξ» x y hx hy hxy, (Icc_subset_Ico_iff hxy).2 β¨hx.1, hy.2β©
@[priority 100]
instance ordered_connected_space : preconnected_space Ξ± :=
β¨is_preconnected_iff_forall_Icc_subset.2 $ Ξ» x y hx hy hxy, subset_univ _β©
/--Intermediate Value Theorem for continuous functions on closed intervals, case `f a β€ t β€ f b`.-/
lemma intermediate_value_Icc {a b : Ξ±} (hab : a β€ b) {f : Ξ± β Ξ²} (hf : continuous_on f (Icc a b)) :
Icc (f a) (f b) β f '' (Icc a b) :=
is_connected_Icc.intermediate_value (left_mem_Icc.2 hab) (right_mem_Icc.2 hab) hf
/--Intermediate Value Theorem for continuous functions on closed intervals, case `f a β₯ t β₯ f b`.-/
lemma intermediate_value_Icc' {a b : Ξ±} (hab : a β€ b) {f : Ξ± β Ξ²} (hf : continuous_on f (Icc a b)) :
Icc (f b) (f a) β f '' (Icc a b) :=
is_connected_Icc.intermediate_value (right_mem_Icc.2 hab) (left_mem_Icc.2 hab) hf
end densely_ordered
/-- The extreme value theorem: a continuous function realizes its minimum on a compact set -/
lemma compact.exists_forall_le {Ξ± : Type u} [topological_space Ξ±]
{s : set Ξ±} (hs : compact s) (ne_s : s.nonempty) {f : Ξ± β Ξ²} (hf : continuous_on f s) :
βxβs, βyβs, f x β€ f y :=
begin
have C : compact (f '' s) := hs.image_of_continuous_on hf,
haveI := has_Inf_to_nonempty Ξ²,
have B : bdd_below (f '' s) := bdd_below_of_compact C,
have : Inf (f '' s) β f '' s :=
cInf_mem_of_is_closed (ne_s.image _) (closed_of_compact _ C) B,
rcases (mem_image _ _ _).1 this with β¨x, xs, hxβ©,
exact β¨x, xs, Ξ» y hy, hx.symm βΈ cInf_le B β¨_, hy, rflβ©β©
end
/-- The extreme value theorem: a continuous function realizes its maximum on a compact set -/
lemma compact.exists_forall_ge {Ξ± : Type u} [topological_space Ξ±]:
β {s : set Ξ±}, compact s β s.nonempty β β {f : Ξ± β Ξ²}, continuous_on f s β
βxβs, βyβs, f y β€ f x :=
@compact.exists_forall_le (order_dual Ξ²) _ _ _ _ _
end conditionally_complete_linear_order
section liminf_limsup
section order_closed_topology
variables [semilattice_sup Ξ±] [topological_space Ξ±] [order_topology Ξ±]
lemma is_bounded_le_nhds (a : Ξ±) : (π a).is_bounded (β€) :=
match forall_le_or_exists_lt_sup a with
| or.inl h := β¨a, eventually_of_forall _ hβ©
| or.inr β¨b, hbβ© := β¨b, ge_mem_nhds hbβ©
end
lemma is_bounded_under_le_of_tendsto {f : filter Ξ²} {u : Ξ² β Ξ±} {a : Ξ±}
(h : tendsto u f (π a)) : f.is_bounded_under (β€) u :=
is_bounded_of_le h (is_bounded_le_nhds a)
@[nolint ge_or_gt] -- see Note [nolint_ge]
lemma is_cobounded_ge_nhds (a : Ξ±) : (π a).is_cobounded (β₯) :=
is_cobounded_of_is_bounded nhds_ne_bot (is_bounded_le_nhds a)
@[nolint ge_or_gt] -- see Note [nolint_ge]
lemma is_cobounded_under_ge_of_tendsto {f : filter Ξ²} {u : Ξ² β Ξ±} {a : Ξ±}
(hf : f β β₯) (h : tendsto u f (π a)) : f.is_cobounded_under (β₯) u :=
is_cobounded_of_is_bounded (map_ne_bot hf) (is_bounded_under_le_of_tendsto h)
end order_closed_topology
section order_closed_topology
variables [semilattice_inf Ξ±] [topological_space Ξ±] [order_topology Ξ±]
@[nolint ge_or_gt] -- see Note [nolint_ge]
lemma is_bounded_ge_nhds (a : Ξ±) : (π a).is_bounded (β₯) :=
match forall_le_or_exists_lt_inf a with
| or.inl h := β¨a, eventually_of_forall _ hβ©
| or.inr β¨b, hbβ© := β¨b, le_mem_nhds hbβ©
end
@[nolint ge_or_gt] -- see Note [nolint_ge]
lemma is_bounded_under_ge_of_tendsto {f : filter Ξ²} {u : Ξ² β Ξ±} {a : Ξ±}
(h : tendsto u f (π a)) : f.is_bounded_under (β₯) u :=
is_bounded_of_le h (is_bounded_ge_nhds a)
lemma is_cobounded_le_nhds (a : Ξ±) : (π a).is_cobounded (β€) :=
is_cobounded_of_is_bounded nhds_ne_bot (is_bounded_ge_nhds a)
lemma is_cobounded_under_le_of_tendsto {f : filter Ξ²} {u : Ξ² β Ξ±} {a : Ξ±}
(hf : f β β₯) (h : tendsto u f (π a)) : f.is_cobounded_under (β€) u :=
is_cobounded_of_is_bounded (map_ne_bot hf) (is_bounded_under_ge_of_tendsto h)
end order_closed_topology
section conditionally_complete_linear_order
variables [conditionally_complete_linear_order Ξ±]
theorem lt_mem_sets_of_Limsup_lt {f : filter Ξ±} {b} (h : f.is_bounded (β€)) (l : f.Limsup < b) :
βαΆ a in f, a < b :=
let β¨c, (h : βαΆ a in f, a β€ c), hcbβ© := exists_lt_of_cInf_lt h l in
mem_sets_of_superset h $ assume a hac, lt_of_le_of_lt hac hcb
@[nolint ge_or_gt] -- see Note [nolint_ge]
theorem gt_mem_sets_of_Liminf_gt : β {f : filter Ξ±} {b}, f.is_bounded (β₯) β f.Liminf > b β
βαΆ a in f, a > b :=
@lt_mem_sets_of_Limsup_lt (order_dual Ξ±) _
variables [topological_space Ξ±] [order_topology Ξ±]
/-- If the liminf and the limsup of a filter coincide, then this filter converges to
their common value, at least if the filter is eventually bounded above and below. -/
@[nolint ge_or_gt] -- see Note [nolint_ge]
theorem le_nhds_of_Limsup_eq_Liminf {f : filter Ξ±} {a : Ξ±}
(hl : f.is_bounded (β€)) (hg : f.is_bounded (β₯)) (hs : f.Limsup = a) (hi : f.Liminf = a) :
f β€ π a :=
tendsto_order.2 $ and.intro
(assume b hb, gt_mem_sets_of_Liminf_gt hg $ hi.symm βΈ hb)
(assume b hb, lt_mem_sets_of_Limsup_lt hl $ hs.symm βΈ hb)
theorem Limsup_nhds (a : Ξ±) : Limsup (π a) = a :=
cInf_intro (is_bounded_le_nhds a)
(assume a' (h : {n : Ξ± | n β€ a'} β π a), show a β€ a', from @mem_of_nhds Ξ± _ a _ h)
(assume b (hba : a < b), show βc (h : {n : Ξ± | n β€ c} β π a), c < b, from
match dense_or_discrete a b with
| or.inl β¨c, hac, hcbβ© := β¨c, ge_mem_nhds hac, hcbβ©
| or.inr β¨_, hβ© := β¨a, (π a).sets_of_superset (gt_mem_nhds hba) h, hbaβ©
end)
theorem Liminf_nhds : β (a : Ξ±), Liminf (π a) = a :=
@Limsup_nhds (order_dual Ξ±) _ _ _
/-- If a filter is converging, its limsup coincides with its limit. -/
theorem Liminf_eq_of_le_nhds {f : filter Ξ±} {a : Ξ±} (hf : f β β₯) (h : f β€ π a) : f.Liminf = a :=
have hb_ge : is_bounded (β₯) f, from is_bounded_of_le h (is_bounded_ge_nhds a),
have hb_le : is_bounded (β€) f, from is_bounded_of_le h (is_bounded_le_nhds a),
le_antisymm
(calc f.Liminf β€ f.Limsup : Liminf_le_Limsup hf hb_le hb_ge
... β€ (π a).Limsup :
Limsup_le_Limsup_of_le h (is_cobounded_of_is_bounded hf hb_ge) (is_bounded_le_nhds a)
... = a : Limsup_nhds a)
(calc a = (π a).Liminf : (Liminf_nhds a).symm
... β€ f.Liminf :
Liminf_le_Liminf_of_le h (is_bounded_ge_nhds a) (is_cobounded_of_is_bounded hf hb_le))
/-- If a filter is converging, its liminf coincides with its limit. -/
theorem Limsup_eq_of_le_nhds : β {f : filter Ξ±} {a : Ξ±}, f β β₯ β f β€ π a β f.Limsup = a :=
@Liminf_eq_of_le_nhds (order_dual Ξ±) _ _ _
end conditionally_complete_linear_order
section complete_linear_order
variables [complete_linear_order Ξ±] [topological_space Ξ±] [order_topology Ξ±]
-- In complete_linear_order, the above theorems take a simpler form
/-- If the liminf and the limsup of a function coincide, then the limit of the function
exists and has the same value -/
theorem tendsto_of_liminf_eq_limsup {f : filter Ξ²} {u : Ξ² β Ξ±} {a : Ξ±}
(h : liminf f u = a β§ limsup f u = a) : tendsto u f (π a) :=
le_nhds_of_Limsup_eq_Liminf is_bounded_le_of_top is_bounded_ge_of_bot h.2 h.1
/-- If a function has a limit, then its limsup coincides with its limit-/
theorem limsup_eq_of_tendsto {f : filter Ξ²} {u : Ξ² β Ξ±} {a : Ξ±} (hf : f β β₯)
(h : tendsto u f (π a)) : limsup f u = a :=
Limsup_eq_of_le_nhds (map_ne_bot hf) h
/-- If a function has a limit, then its liminf coincides with its limit-/
theorem liminf_eq_of_tendsto {f : filter Ξ²} {u : Ξ² β Ξ±} {a : Ξ±} (hf : f β β₯)
(h : tendsto u f (π a)) : liminf f u = a :=
Liminf_eq_of_le_nhds (map_ne_bot hf) h
end complete_linear_order
end liminf_limsup
end order_topology
@[nolint ge_or_gt] -- see Note [nolint_ge]
lemma order_topology_of_nhds_abs
{Ξ± : Type*} [decidable_linear_ordered_add_comm_group Ξ±] [topological_space Ξ±]
(h_nhds : βa:Ξ±, π a = (β¨
r>0, principal {b | abs (a - b) < r})) : order_topology Ξ± :=
order_topology.mk $ eq_of_nhds_eq_nhds $ assume a:Ξ±, le_antisymm_iff.mpr
begin
simp [infi_and, topological_space.nhds_generate_from,
h_nhds, le_infi_iff, -le_principal_iff, and_comm],
refine β¨Ξ» s ha b hs, _, Ξ» r hr, _β©,
{ rcases hs with rfl | rfl,
{ refine infi_le_of_le (a - b)
(infi_le_of_le (lt_sub_left_of_add_lt $ by simpa using ha) $
principal_mono.mpr $ assume c (hc : abs (a - c) < a - b), _),
have : a - c < a - b := lt_of_le_of_lt (le_abs_self _) hc,
exact lt_of_neg_lt_neg (lt_of_add_lt_add_left this) },
{ refine infi_le_of_le (b - a)
(infi_le_of_le (lt_sub_left_of_add_lt $ by simpa using ha) $
principal_mono.mpr $ assume c (hc : abs (a - c) < b - a), _),
have : abs (c - a) < b - a, {rw abs_sub; simpa using hc},
have : c - a < b - a := lt_of_le_of_lt (le_abs_self _) this,
exact lt_of_add_lt_add_right this } },
{ have h : {b | abs (a - b) < r} = {b | a - r < b} β© {b | b < a + r},
from set.ext (assume b,
by simp [abs_lt, sub_lt, lt_sub_iff_add_lt, sub_lt_iff_lt_add']; cc),
rw [h, β inf_principal],
apply le_inf _ _,
{ exact infi_le_of_le {b : Ξ± | a - r < b} (infi_le_of_le (sub_lt_self a hr) $
infi_le_of_le (a - r) $ infi_le _ (or.inl rfl)) },
{ exact infi_le_of_le {b : Ξ± | b < a + r} (infi_le_of_le (lt_add_of_pos_right _ hr) $
infi_le_of_le (a + r) $ infi_le _ (or.inr rfl)) } }
end
lemma tendsto_at_top_supr_nat [topological_space Ξ±] [complete_linear_order Ξ±] [order_topology Ξ±]
(f : β β Ξ±) (hf : monotone f) : tendsto f at_top (π (β¨i, f i)) :=
tendsto_order.2 $ and.intro
(assume a ha, let β¨n, hnβ© := lt_supr_iff.1 ha in
mem_at_top_sets.2 β¨n, assume i hi, lt_of_lt_of_le hn (hf hi)β©)
(assume a ha, univ_mem_sets' (assume n, lt_of_le_of_lt (le_supr _ n) ha))
lemma tendsto_at_top_infi_nat [topological_space Ξ±] [complete_linear_order Ξ±] [order_topology Ξ±]
(f : β β Ξ±) (hf : β{n m}, n β€ m β f m β€ f n) : tendsto f at_top (π (β¨
i, f i)) :=
@tendsto_at_top_supr_nat (order_dual Ξ±) _ _ _ _ @hf
lemma supr_eq_of_tendsto {Ξ±} [topological_space Ξ±] [complete_linear_order Ξ±] [order_topology Ξ±]
{f : β β Ξ±} {a : Ξ±} (hf : monotone f) : tendsto f at_top (π a) β supr f = a :=
tendsto_nhds_unique at_top_ne_bot (tendsto_at_top_supr_nat f hf)
lemma infi_eq_of_tendsto {Ξ±} [topological_space Ξ±] [complete_linear_order Ξ±] [order_topology Ξ±]
{f : β β Ξ±} {a : Ξ±} (hf : βn m, n β€ m β f m β€ f n) : tendsto f at_top (π a) β infi f = a :=
tendsto_nhds_unique at_top_ne_bot (tendsto_at_top_infi_nat f hf)
lemma tendsto_abs_at_top_at_top [decidable_linear_ordered_add_comm_group Ξ±] : tendsto (abs : Ξ± β Ξ±) at_top at_top :=
tendsto_at_top_mono _ (Ξ» n, le_abs_self _) tendsto_id
local notation `|` x `|` := abs x
@[nolint ge_or_gt] -- see Note [nolint_ge]
lemma decidable_linear_ordered_add_comm_group.tendsto_nhds
[decidable_linear_ordered_add_comm_group Ξ±] [topological_space Ξ±] [order_topology Ξ±] {Ξ² : Type*}
(f : Ξ² β Ξ±) (x : filter Ξ²) (a : Ξ±) :
filter.tendsto f x (nhds a) β β Ξ΅ > (0 : Ξ±), βαΆ b in x, |f b - a| < Ξ΅ :=
begin
rw (show _, from @tendsto_order Ξ±), -- does not work without `show` for some reason
split,
{ rintros β¨hyp_lt_a, hyp_gt_aβ© Ξ΅ Ξ΅_pos,
suffices : {b : Ξ² | f b - a < Ξ΅ β§ a - f b < Ξ΅} β x, by simpa only [abs_sub_lt_iff],
have set1 : {b : Ξ² | a - f b < Ξ΅} β x,
{ have : {b : Ξ² | a - Ξ΅ < f b} β x, from hyp_lt_a (a - Ξ΅) (sub_lt_self a Ξ΅_pos),
have : β b, a - f b < Ξ΅ β a - Ξ΅ < f b, by { intro _, exact sub_lt },
simpa only [this] },
have set2 : {b : Ξ² | f b - a < Ξ΅} β x,
{ have : {b : Ξ² | a + Ξ΅ > f b} β x, from hyp_gt_a (a + Ξ΅) (lt_add_of_pos_right a Ξ΅_pos),
have : β b, f b - a < Ξ΅ β a + Ξ΅ > f b, by { intro _, exact sub_lt_iff_lt_add' },
simpa only [this] },
exact (x.inter_sets set2 set1) },
{ assume hyp_Ξ΅_pos,
split,
{ assume a' a'_lt_a,
let Ξ΅ := a - a',
have : {b : Ξ² | |f b - a| < Ξ΅} β x, from hyp_Ξ΅_pos Ξ΅ (sub_pos.elim_right a'_lt_a),
have : {b : Ξ² | f b - a < Ξ΅ β§ a - f b < Ξ΅} β x, by simpa only [abs_sub_lt_iff] using this,
have : {b : Ξ² | a - f b < Ξ΅} β x, from x.sets_of_superset this (set.inter_subset_right _ _),
have : β b, a' < f b β a - f b < Ξ΅, by {intro b, rw [sub_lt, sub_sub_self] },
simpa only [this] },
{ assume a' a'_gt_a,
let Ξ΅ := a' - a,
have : {b : Ξ² | |f b - a| < Ξ΅} β x, from hyp_Ξ΅_pos Ξ΅ (sub_pos.elim_right a'_gt_a),
have : {b : Ξ² | f b - a < Ξ΅ β§ a - f b < Ξ΅} β x, by simpa only [abs_sub_lt_iff] using this,
have : {b : Ξ² | f b - a < Ξ΅} β x, from x.sets_of_superset this (set.inter_subset_left _ _),
have : β b, f b < a' β f b - a < Ξ΅, by { intro b, simp [lt_sub_iff_add_lt] },
simpa only [this] }}
end
|
ff46a7b4d80544cf63d8a8bcd2c204f003b3c4c0 | 4efff1f47634ff19e2f786deadd394270a59ecd2 | /src/algebra/group/hom.lean | 24f8a2efae4f96ed90a9ddfc3200fffd4c9d3a7e | [
"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 | 13,868 | lean | /-
Copyright (c) 2018 Patrick Massot. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Massot, Kevin Buzzard, Scott Morrison, Johan Commelin, Chris Hughes,
Johannes HΓΆlzl, Yury Kudryashov
-/
import algebra.group.commute
/-!
# monoid and group homomorphisms
This file defines the bundled structures for monoid and group homomorphisms. Namely, we define
`monoid_hom` (resp., `add_monoid_hom`) to be bundled homomorphisms between multiplicative (resp.,
additive) monoids or groups.
We also define coercion to a function, and usual operations: composition, identity homomorphism,
pointwise multiplication and pointwise inversion.
## Notations
* `β*` for bundled monoid homs (also use for group homs)
* `β+` for bundled add_monoid homs (also use for add_group homs)
## implementation notes
There's a coercion from bundled homs to fun, and the canonical
notation is to use the bundled hom as a function via this coercion.
There is no `group_hom` -- the idea is that `monoid_hom` is used.
The constructor for `monoid_hom` needs a proof of `map_one` as well
as `map_mul`; a separate constructor `monoid_hom.mk'` will construct
group homs (i.e. monoid homs between groups) given only a proof
that multiplication is preserved,
Implicit `{}` brackets are often used instead of type class `[]` brackets. This is done when the
instances can be inferred because they are implicit arguments to the type `monoid_hom`. When they
can be inferred from the type it is faster to use this method than to use type class inference.
Historically this file also included definitions of unbundled homomorphism classes; they were
deprecated and moved to `deprecated/group`.
## Tags
monoid_hom, add_monoid_hom
-/
variables {M : Type*} {N : Type*} {P : Type*} -- monoids
{G : Type*} {H : Type*} -- groups
/-- Bundled add_monoid homomorphisms; use this for bundled add_group homomorphisms too. -/
structure add_monoid_hom (M : Type*) (N : Type*) [add_monoid M] [add_monoid N] :=
(to_fun : M β N)
(map_zero' : to_fun 0 = 0)
(map_add' : β x y, to_fun (x + y) = to_fun x + to_fun y)
infixr ` β+ `:25 := add_monoid_hom
/-- Bundled monoid homomorphisms; use this for bundled group homomorphisms too. -/
@[to_additive]
structure monoid_hom (M : Type*) (N : Type*) [monoid M] [monoid N] :=
(to_fun : M β N)
(map_one' : to_fun 1 = 1)
(map_mul' : β x y, to_fun (x * y) = to_fun x * to_fun y)
infixr ` β* `:25 := monoid_hom
@[to_additive]
instance {M : Type*} {N : Type*} {mM : monoid M} {mN : monoid N} : has_coe_to_fun (M β* N) :=
β¨_, monoid_hom.to_funβ©
namespace monoid_hom
variables {mM : monoid M} {mN : monoid N} {mP : monoid P}
variables [group G] [comm_group H]
include mM mN
@[simp, to_additive]
lemma to_fun_eq_coe (f : M β* N) : f.to_fun = f := rfl
@[simp, to_additive]
lemma coe_mk (f : M β N) (h1 hmul) : β(monoid_hom.mk f h1 hmul) = f := rfl
@[to_additive]
lemma coe_inj β¦f g : M β* Nβ¦ (h : (f : M β N) = g) : f = g :=
by cases f; cases g; cases h; refl
@[ext, to_additive]
lemma ext β¦f g : M β* Nβ¦ (h : β x, f x = g x) : f = g :=
coe_inj (funext h)
attribute [ext] _root_.add_monoid_hom.ext
@[to_additive]
lemma ext_iff {f g : M β* N} : f = g β β x, f x = g x :=
β¨Ξ» h x, h βΈ rfl, Ξ» h, ext hβ©
/-- If `f` is a monoid homomorphism then `f 1 = 1`. -/
@[simp, to_additive]
lemma map_one (f : M β* N) : f 1 = 1 := f.map_one'
/-- If `f` is an additive monoid homomorphism then `f 0 = 0`. -/
add_decl_doc add_monoid_hom.map_zero
/-- If `f` is a monoid homomorphism then `f (a * b) = f a * f b`. -/
@[simp, to_additive]
lemma map_mul (f : M β* N) (a b : M) : f (a * b) = f a * f b := f.map_mul' a b
/-- If `f` is an additive monoid homomorphism then `f (a + b) = f a + f b`. -/
add_decl_doc add_monoid_hom.map_add
@[to_additive]
lemma map_mul_eq_one (f : M β* N) {a b : M} (h : a * b = 1) : f a * f b = 1 :=
by rw [β f.map_mul, h, f.map_one]
/-- Given a monoid homomorphism `f : M β* N` and an element `x : M`, if `x` has a right inverse,
then `f x` has a right inverse too. For elements invertible on both sides see `is_unit.map`. -/
@[to_additive "Given an add_monoid homomorphism `f : M β+ N` and an element `x : M`, if `x` has
a right inverse, then `f x` has a right inverse too."]
lemma map_exists_right_inv (f : M β* N) {x : M} (hx : β y, x * y = 1) :
β y, f x * y = 1 :=
let β¨y, hyβ© := hx in β¨f y, f.map_mul_eq_one hyβ©
/-- Given a monoid homomorphism `f : M β* N` and an element `x : M`, if `x` has a left inverse,
then `f x` has a left inverse too. For elements invertible on both sides see `is_unit.map`. -/
@[to_additive "Given an add_monoid homomorphism `f : M β+ N` and an element `x : M`, if `x` has
a left inverse, then `f x` has a left inverse too. For elements invertible on both sides see
`is_add_unit.map`."]
lemma map_exists_left_inv (f : M β* N) {x : M} (hx : β y, y * x = 1) :
β y, y * f x = 1 :=
let β¨y, hyβ© := hx in β¨f y, f.map_mul_eq_one hyβ©
omit mN mM
/-- The identity map from a monoid to itself. -/
@[to_additive]
def id (M : Type*) [monoid M] : M β* M :=
{ to_fun := id,
map_one' := rfl,
map_mul' := Ξ» _ _, rfl }
/-- The identity map from an additive monoid to itself. -/
add_decl_doc add_monoid_hom.id
@[simp, to_additive] lemma id_apply {M : Type*} [monoid M] (x : M) :
id M x = x := rfl
include mM mN mP
/-- Composition of monoid morphisms as a monoid morphism. -/
@[to_additive]
def comp (hnp : N β* P) (hmn : M β* N) : M β* P :=
{ to_fun := hnp β hmn,
map_one' := by simp,
map_mul' := by simp }
/-- Composition of additive monoid morphisms as an additive monoid morphism. -/
add_decl_doc add_monoid_hom.comp
@[simp, to_additive] lemma comp_apply (g : N β* P) (f : M β* N) (x : M) :
g.comp f x = g (f x) := rfl
/-- Composition of monoid homomorphisms is associative. -/
@[to_additive] lemma comp_assoc {Q : Type*} [monoid Q] (f : M β* N) (g : N β* P) (h : P β* Q) :
(h.comp g).comp f = h.comp (g.comp f) := rfl
@[to_additive]
lemma cancel_right {gβ gβ : N β* P} {f : M β* N} (hf : function.surjective f) :
gβ.comp f = gβ.comp f β gβ = gβ :=
β¨Ξ» h, monoid_hom.ext $ (forall_iff_forall_surj hf).1 (ext_iff.1 h), Ξ» h, h βΈ rflβ©
@[to_additive]
lemma cancel_left {g : N β* P} {fβ fβ : M β* N} (hg : function.injective g) :
g.comp fβ = g.comp fβ β fβ = fβ :=
β¨Ξ» h, monoid_hom.ext $ Ξ» x, hg $ by rw [β comp_apply, h, comp_apply], Ξ» h, h βΈ rflβ©
omit mP
@[simp, to_additive] lemma comp_id (f : M β* N) : f.comp (id M) = f := ext $ Ξ» x, rfl
@[simp, to_additive] lemma id_comp (f : M β* N) : (id N).comp f = f := ext $ Ξ» x, rfl
end monoid_hom
section End
namespace monoid
variables (M) [monoid M]
/-- The monoid of endomorphisms. -/
protected def End := M β* M
namespace End
instance : monoid (monoid.End M) :=
{ mul := monoid_hom.comp,
one := monoid_hom.id M,
mul_assoc := Ξ» _ _ _, monoid_hom.comp_assoc _ _ _,
mul_one := monoid_hom.comp_id,
one_mul := monoid_hom.id_comp }
instance : inhabited (monoid.End M) := β¨1β©
instance : has_coe_to_fun (monoid.End M) := β¨_, monoid_hom.to_funβ©
end End
@[simp] lemma coe_one : ((1 : monoid.End M) : M β M) = id := rfl
@[simp] lemma coe_mul (f g) : ((f * g : monoid.End M) : M β M) = f β g := rfl
end monoid
namespace add_monoid
variables (A : Type*) [add_monoid A]
/-- The monoid of endomorphisms. -/
protected def End := A β+ A
namespace End
instance : monoid (add_monoid.End A) :=
{ mul := add_monoid_hom.comp,
one := add_monoid_hom.id A,
mul_assoc := Ξ» _ _ _, add_monoid_hom.comp_assoc _ _ _,
mul_one := add_monoid_hom.comp_id,
one_mul := add_monoid_hom.id_comp }
instance : inhabited (add_monoid.End A) := β¨1β©
instance : has_coe_to_fun (add_monoid.End A) := β¨_, add_monoid_hom.to_funβ©
end End
@[simp] lemma coe_one : ((1 : add_monoid.End A) : A β A) = id := rfl
@[simp] lemma coe_mul (f g) : ((f * g : add_monoid.End A) : A β A) = f β g := rfl
end add_monoid
end End
namespace monoid_hom
variables [mM : monoid M] [mN : monoid N] [mP : monoid P]
variables [group G] [comm_group H]
include mM mN
/-- `1` is the monoid homomorphism sending all elements to `1`. -/
@[to_additive]
instance : has_one (M β* N) := β¨β¨Ξ» _, 1, rfl, Ξ» _ _, (one_mul 1).symmβ©β©
/-- `0` is the additive monoid homomorphism sending all elements to `0`. -/
add_decl_doc add_monoid_hom.has_zero
@[simp, to_additive] lemma one_apply (x : M) : (1 : M β* N) x = 1 := rfl
@[to_additive]
instance : inhabited (M β* N) := β¨1β©
omit mM mN
/-- Given two monoid morphisms `f`, `g` to a commutative monoid, `f * g` is the monoid morphism
sending `x` to `f x * g x`. -/
@[to_additive]
instance {M N} {mM : monoid M} [comm_monoid N] : has_mul (M β* N) :=
β¨Ξ» f g,
{ to_fun := Ξ» m, f m * g m,
map_one' := show f 1 * g 1 = 1, by simp,
map_mul' := begin intros, show f (x * y) * g (x * y) = f x * g x * (f y * g y),
rw [f.map_mul, g.map_mul, βmul_assoc, βmul_assoc, mul_right_comm (f x)], end }β©
/-- Given two additive monoid morphisms `f`, `g` to an additive commutative monoid, `f + g` is the
additive monoid morphism sending `x` to `f x + g x`. -/
add_decl_doc add_monoid_hom.has_add
@[simp, to_additive] lemma mul_apply {M N} {mM : monoid M} {mN : comm_monoid N}
(f g : M β* N) (x : M) :
(f * g) x = f x * g x := rfl
/-- (M β* N) is a comm_monoid if N is commutative. -/
@[to_additive]
instance {M N} [monoid M] [comm_monoid N] : comm_monoid (M β* N) :=
{ mul := (*),
mul_assoc := by intros; ext; apply mul_assoc,
one := 1,
one_mul := by intros; ext; apply one_mul,
mul_one := by intros; ext; apply mul_one,
mul_comm := by intros; ext; apply mul_comm }
/-- `flip` arguments of `f : M β* N β* P` -/
@[to_additive "`flip` arguments of `f : M β+ N β+ P`"]
def flip {mM : monoid M} {mN : monoid N} {mP : comm_monoid P} (f : M β* N β* P) :
N β* M β* P :=
{ to_fun := Ξ» y, β¨Ξ» x, f x y, by rw [f.map_one, one_apply], Ξ» xβ xβ, by rw [f.map_mul, mul_apply]β©,
map_one' := ext $ Ξ» x, (f x).map_one,
map_mul' := Ξ» yβ yβ, ext $ Ξ» x, (f x).map_mul yβ yβ }
@[simp, to_additive] lemma flip_apply {mM : monoid M} {mN : monoid N} {mP : comm_monoid P}
(f : M β* N β* P) (x : M) (y : N) :
f.flip y x = f x y :=
rfl
/-- If two homomorphism from a group to a monoid are equal at `x`, then they are equal at `xβ»ΒΉ`. -/
@[to_additive "If two homomorphism from an additive group to an additive monoid are equal at `x`,
then they are equal at `-x`." ]
lemma eq_on_inv {G} [group G] [monoid M] {f g : G β* M} {x : G} (h : f x = g x) :
f xβ»ΒΉ = g xβ»ΒΉ :=
left_inv_eq_right_inv (f.map_mul_eq_one $ inv_mul_self x) $
h.symm βΈ g.map_mul_eq_one $ mul_inv_self x
/-- Group homomorphisms preserve inverse. -/
@[simp, to_additive]
theorem map_inv {G H} [group G] [group H] (f : G β* H) (g : G) : f gβ»ΒΉ = (f g)β»ΒΉ :=
eq_inv_of_mul_eq_one $ f.map_mul_eq_one $ inv_mul_self g
/-- Group homomorphisms preserve division. -/
@[simp, to_additive]
theorem map_mul_inv {G H} [group G] [group H] (f : G β* H) (g h : G) :
f (g * hβ»ΒΉ) = (f g) * (f h)β»ΒΉ := by rw [f.map_mul, f.map_inv]
/-- A homomorphism from a group to a monoid is injective iff its kernel is trivial. -/
@[to_additive]
lemma injective_iff {G H} [group G] [monoid H] (f : G β* H) :
function.injective f β (β a, f a = 1 β a = 1) :=
β¨Ξ» h x hfx, h $ hfx.trans f.map_one.symm,
Ξ» h x y hxy, mul_inv_eq_one.1 $ h _ $ by rw [f.map_mul, hxy, β f.map_mul, mul_inv_self, f.map_one]β©
include mM
/-- Makes a group homomomorphism from a proof that the map preserves multiplication. -/
@[to_additive]
def mk' (f : M β G) (map_mul : β a b : M, f (a * b) = f a * f b) : M β* G :=
{ to_fun := f,
map_mul' := map_mul,
map_one' := mul_self_iff_eq_one.1 $ by rw [βmap_mul, mul_one] }
/-- Makes an additive group homomomorphism from a proof that the map preserves multiplication. -/
add_decl_doc add_monoid_hom.mk'
@[simp, to_additive]
lemma coe_mk' {f : M β G} (map_mul : β a b : M, f (a * b) = f a * f b) :
β(mk' f map_mul) = f := rfl
omit mM
/-- If `f` is a monoid homomorphism to a commutative group, then `fβ»ΒΉ` is the homomorphism sending
`x` to `(f x)β»ΒΉ`. -/
@[to_additive]
instance {M G} [monoid M] [comm_group G] : has_inv (M β* G) :=
β¨Ξ» f, mk' (Ξ» g, (f g)β»ΒΉ) $ Ξ» a b, by rw [βmul_inv, f.map_mul]β©
/-- If `f` is an additive monoid homomorphism to an additive commutative group, then `-f` is the
homomorphism sending `x` to `-(f x)`. -/
add_decl_doc add_monoid_hom.has_neg
@[simp, to_additive] lemma inv_apply {M G} {mM : monoid M} {gG : comm_group G}
(f : M β* G) (x : M) :
fβ»ΒΉ x = (f x)β»ΒΉ := rfl
/-- If `G` is a commutative group, then `M β* G` a commutative group too. -/
@[to_additive]
instance {M G} [monoid M] [comm_group G] : comm_group (M β* G) :=
{ inv := has_inv.inv,
mul_left_inv := by intros; ext; apply mul_left_inv,
..monoid_hom.comm_monoid }
/-- If `G` is an additive commutative group, then `M β+ G` an additive commutative group too. -/
add_decl_doc add_monoid_hom.add_comm_group
end monoid_hom
namespace add_monoid_hom
/-- Additive group homomorphisms preserve subtraction. -/
@[simp] theorem map_sub {G H} [add_group G] [add_group H] (f : G β+ H) (g h : G) :
f (g - h) = (f g) - (f h) := f.map_add_neg g h
end add_monoid_hom
section commute
variables [monoid M] [monoid N] {a x y : M}
@[simp, to_additive]
protected lemma semiconj_by.map (h : semiconj_by a x y) (f : M β* N) :
semiconj_by (f a) (f x) (f y) :=
by simpa only [semiconj_by, f.map_mul] using congr_arg f h
@[simp, to_additive]
protected lemma commute.map (h : commute x y) (f : M β* N) : commute (f x) (f y) := h.map f
end commute
|
f10155085593d41c951fceb1fc88dc63847936f3 | 74addaa0e41490cbaf2abd313a764c96df57b05d | /Mathlib/Lean3Lib/init/data/subtype/instances_auto.lean | 9aa2f1880eac605d1664e9e89e7d6255d75087b4 | [] | 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 | 938 | 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.meta.mk_dec_eq_instance
import Mathlib.Lean3Lib.init.data.subtype.basic
universes u
namespace Mathlib
protected instance subtype.decidable_eq {Ξ± : Type u} {p : Ξ± β Prop} [DecidableEq Ξ±] :
DecidableEq (Subtype fun (x : Ξ±) => p x) :=
id
fun (_v : Subtype fun (x : Ξ±) => p x) =>
subtype.cases_on _v
fun (val : Ξ±) (property : p val) (w : Subtype fun (x : Ξ±) => p x) =>
subtype.cases_on w
fun (w_val : Ξ±) (w_property : p w_val) =>
decidable.by_cases
(fun (αΎ° : val = w_val) =>
Eq._oldrec (fun (w_property : p val) => is_true sorry) αΎ° w_property)
fun (αΎ° : Β¬val = w_val) => isFalse sorry
end Mathlib |
73feeb94040c240dcb76c4e9d007a88e2549c286 | 9dc8cecdf3c4634764a18254e94d43da07142918 | /src/algebra/hom/units.lean | 40746ceff609ee39361c9b0c16ddeb19f16b1185 | [
"Apache-2.0"
] | permissive | jcommelin/mathlib | d8456447c36c176e14d96d9e76f39841f69d2d9b | ee8279351a2e434c2852345c51b728d22af5a156 | refs/heads/master | 1,664,782,136,488 | 1,663,638,983,000 | 1,663,638,983,000 | 132,563,656 | 0 | 0 | Apache-2.0 | 1,663,599,929,000 | 1,525,760,539,000 | Lean | UTF-8 | Lean | false | false | 12,353 | lean | /-
Copyright (c) 2018 Johan Commelin All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin, Chris Hughes, Kevin Buzzard
-/
import algebra.hom.group
/-!
# Monoid homomorphisms and units
This file allows to lift monoid homomorphisms to group homomorphisms of their units subgroups. It
also contains unrelated results about `units` that depend on `monoid_hom`.
## Main declarations
* `units.map`: Turn an homomorphism from `Ξ±` to `Ξ²` monoids into an homomorphism from `Ξ±Λ£` to `Ξ²Λ£`.
* `monoid_hom.to_hom_units`: Turn an homomorphism from a group `Ξ±` to `Ξ²` into an homomorphism from
`Ξ±` to `Ξ²Λ£`.
## TODO
The results that don't mention homomorphisms should be proved (earlier?) in a different file and be
used to golf the basic `group` lemmas.
-/
open function
universes u v w
namespace units
variables {Ξ± : Type*} {M : Type u} {N : Type v} {P : Type w} [monoid M] [monoid N] [monoid P]
/-- The group homomorphism on units induced by a `monoid_hom`. -/
@[to_additive "The `add_group` homomorphism on `add_unit`s induced by an `add_monoid_hom`."]
def map (f : M β* N) : MΛ£ β* NΛ£ :=
monoid_hom.mk'
(Ξ» u, β¨f u.val, f u.inv,
by rw [β f.map_mul, u.val_inv, f.map_one],
by rw [β f.map_mul, u.inv_val, f.map_one]β©)
(Ξ» x y, ext (f.map_mul x y))
@[simp, to_additive] lemma coe_map (f : M β* N) (x : MΛ£) : β(map f x) = f x := rfl
@[simp, to_additive] lemma coe_map_inv (f : M β* N) (u : MΛ£) :
β(map f u)β»ΒΉ = f βuβ»ΒΉ :=
rfl
@[simp, to_additive]
lemma map_comp (f : M β* N) (g : N β* P) : map (g.comp f) = (map g).comp (map f) := rfl
variables (M)
@[simp, to_additive] lemma map_id : map (monoid_hom.id M) = monoid_hom.id MΛ£ :=
by ext; refl
/-- Coercion `MΛ£ β M` as a monoid homomorphism. -/
@[to_additive "Coercion `add_units M β M` as an add_monoid homomorphism."]
def coe_hom : MΛ£ β* M := β¨coe, coe_one, coe_mulβ©
variable {M}
@[simp, to_additive] lemma coe_hom_apply (x : MΛ£) : coe_hom M x = βx := rfl
@[simp, norm_cast, to_additive]
lemma coe_pow (u : MΛ£) (n : β) : ((u ^ n : MΛ£) : M) = u ^ n :=
(units.coe_hom M).map_pow u n
section division_monoid
variables [division_monoid Ξ±]
@[simp, norm_cast, to_additive] lemma coe_div : β uβ uβ : Ξ±Λ£, β(uβ / uβ) = (uβ / uβ : Ξ±) :=
(units.coe_hom Ξ±).map_div
@[simp, norm_cast, to_additive] lemma coe_zpow : β (u : Ξ±Λ£) (n : β€), ((u ^ n : Ξ±Λ£) : Ξ±) = u ^ n :=
(units.coe_hom Ξ±).map_zpow
@[field_simps] lemma _root_.divp_eq_div (a : Ξ±) (u : Ξ±Λ£) : a /β u = a / u :=
by rw [div_eq_mul_inv, divp, u.coe_inv]
@[simp, to_additive]
lemma _root_.map_units_inv {F : Type*} [monoid_hom_class F M Ξ±] (f : F) (u : units M) :
f βuβ»ΒΉ = (f u)β»ΒΉ :=
((f : M β* Ξ±).comp (units.coe_hom M)).map_inv u
end division_monoid
/-- If a map `g : M β NΛ£` agrees with a homomorphism `f : M β* N`, then
this map is a monoid homomorphism too. -/
@[to_additive "If a map `g : M β add_units N` agrees with a homomorphism `f : M β+ N`, then this map
is an add_monoid homomorphism too."]
def lift_right (f : M β* N) (g : M β NΛ£) (h : β x, β(g x) = f x) :
M β* NΛ£ :=
{ to_fun := g,
map_one' := units.ext $ (h 1).symm βΈ f.map_one,
map_mul' := Ξ» x y, units.ext $ by simp only [h, coe_mul, f.map_mul] }
@[simp, to_additive] lemma coe_lift_right {f : M β* N} {g : M β NΛ£}
(h : β x, β(g x) = f x) (x) : (lift_right f g h x : N) = f x := h x
@[simp, to_additive] lemma mul_lift_right_inv {f : M β* N} {g : M β NΛ£}
(h : β x, β(g x) = f x) (x) : f x * β(lift_right f g h x)β»ΒΉ = 1 :=
by rw [units.mul_inv_eq_iff_eq_mul, one_mul, coe_lift_right]
@[simp, to_additive] lemma lift_right_inv_mul {f : M β* N} {g : M β NΛ£}
(h : β x, β(g x) = f x) (x) : β(lift_right f g h x)β»ΒΉ * f x = 1 :=
by rw [units.inv_mul_eq_iff_eq_mul, mul_one, coe_lift_right]
end units
namespace monoid_hom
/-- If `f` is a homomorphism from a group `G` to a monoid `M`,
then its image lies in the units of `M`,
and `f.to_hom_units` is the corresponding monoid homomorphism from `G` to `MΛ£`. -/
@[to_additive "If `f` is a homomorphism from an additive group `G` to an additive monoid `M`,
then its image lies in the `add_units` of `M`,
and `f.to_hom_units` is the corresponding homomorphism from `G` to `add_units M`."]
def to_hom_units {G M : Type*} [group G] [monoid M] (f : G β* M) : G β* MΛ£ :=
units.lift_right f
(Ξ» g, β¨f g, f gβ»ΒΉ, map_mul_eq_one f (mul_inv_self _), map_mul_eq_one f (inv_mul_self _)β©)
(Ξ» g, rfl)
@[simp] lemma coe_to_hom_units {G M : Type*} [group G] [monoid M] (f : G β* M) (g : G):
(f.to_hom_units g : M) = f g := rfl
end monoid_hom
namespace is_unit
variables {F G Ξ± M N : Type*}
section monoid
variables [monoid M] [monoid N]
@[to_additive] lemma map [monoid_hom_class F M N] (f : F) {x : M} (h : is_unit x) : is_unit (f x) :=
by rcases h with β¨y, rflβ©; exact (units.map (f : M β* N) y).is_unit
@[to_additive] lemma of_left_inverse [monoid_hom_class F M N] [monoid_hom_class G N M]
{f : F} {x : M} (g : G) (hfg : function.left_inverse g f) (h : is_unit (f x)) :
is_unit x :=
by simpa only [hfg x] using h.map g
@[to_additive] lemma _root_.is_unit_map_of_left_inverse
[monoid_hom_class F M N] [monoid_hom_class G N M]
{f : F} {x : M} (g : G) (hfg : function.left_inverse g f) :
is_unit (f x) β is_unit x :=
β¨of_left_inverse g hfg, map _β©
/-- If a homomorphism `f : M β* N` sends each element to an `is_unit`, then it can be lifted
to `f : M β* NΛ£`. See also `units.lift_right` for a computable version. -/
@[to_additive "If a homomorphism `f : M β+ N` sends each element to an `is_add_unit`, then it can be
lifted to `f : M β+ add_units N`. See also `add_units.lift_right` for a computable version."]
noncomputable def lift_right (f : M β* N) (hf : β x, is_unit (f x)) : M β* NΛ£ :=
units.lift_right f (Ξ» x, (hf x).unit) $ Ξ» x, rfl
@[to_additive] lemma coe_lift_right (f : M β* N) (hf : β x, is_unit (f x)) (x) :
(is_unit.lift_right f hf x : N) = f x := rfl
@[simp, to_additive] lemma mul_lift_right_inv (f : M β* N) (h : β x, is_unit (f x)) (x) :
f x * β(is_unit.lift_right f h x)β»ΒΉ = 1 :=
units.mul_lift_right_inv (Ξ» y, rfl) x
@[simp, to_additive] lemma lift_right_inv_mul (f : M β* N) (h : β x, is_unit (f x)) (x) :
β(is_unit.lift_right f h x)β»ΒΉ * f x = 1 :=
units.lift_right_inv_mul (Ξ» y, rfl) x
end monoid
section division_monoid
variables [division_monoid Ξ±] {a b c : Ξ±}
/-- The element of the group of units, corresponding to an element of a monoid which is a unit. As
opposed to `is_unit.unit`, the inverse is computable and comes from the inversion on `Ξ±`. This is
useful to transfer properties of inversion in `units Ξ±` to `Ξ±`. See also `to_units`. -/
@[to_additive "The element of the additive group of additive units, corresponding to an element of
an additive monoid which is an additive unit. As opposed to `is_add_unit.add_unit`, the negation is
computable and comes from the negation on `Ξ±`. This is useful to transfer properties of negation in
`add_units Ξ±` to `Ξ±`. See also `to_add_units`.", simps]
def unit' (h : is_unit a) : Ξ±Λ£ := β¨a, aβ»ΒΉ, h.mul_inv_cancel, h.inv_mul_cancelβ©
@[simp, to_additive] protected lemma mul_inv_cancel_left (h : is_unit a) : β b, a * (aβ»ΒΉ * b) = b :=
h.unit'.mul_inv_cancel_left
@[simp, to_additive] protected lemma inv_mul_cancel_left (h : is_unit a) : β b, aβ»ΒΉ * (a * b) = b :=
h.unit'.inv_mul_cancel_left
@[simp, to_additive] protected lemma mul_inv_cancel_right (h : is_unit b) (a : Ξ±) :
a * b * bβ»ΒΉ = a :=
h.unit'.mul_inv_cancel_right _
@[simp, to_additive] protected lemma inv_mul_cancel_right (h : is_unit b) (a : Ξ±) :
a * bβ»ΒΉ * b = a :=
h.unit'.inv_mul_cancel_right _
@[to_additive] protected lemma div_self (h : is_unit a) : a / a = 1 :=
by rw [div_eq_mul_inv, h.mul_inv_cancel]
@[to_additive] protected lemma eq_mul_inv_iff_mul_eq (h : is_unit c) : a = b * cβ»ΒΉ β a * c = b :=
h.unit'.eq_mul_inv_iff_mul_eq
@[to_additive] protected lemma eq_inv_mul_iff_mul_eq (h : is_unit b) : a = bβ»ΒΉ * c β b * a = c :=
h.unit'.eq_inv_mul_iff_mul_eq
@[to_additive] protected lemma inv_mul_eq_iff_eq_mul (h : is_unit a) : aβ»ΒΉ * b = c β b = a * c :=
h.unit'.inv_mul_eq_iff_eq_mul
@[to_additive] protected lemma mul_inv_eq_iff_eq_mul (h : is_unit b) : a * bβ»ΒΉ = c β a = c * b :=
h.unit'.mul_inv_eq_iff_eq_mul
@[to_additive] protected lemma mul_inv_eq_one (h : is_unit b) : a * bβ»ΒΉ = 1 β a = b :=
@units.mul_inv_eq_one _ _ h.unit' _
@[to_additive] protected lemma inv_mul_eq_one (h : is_unit a) : aβ»ΒΉ * b = 1 β a = b :=
@units.inv_mul_eq_one _ _ h.unit' _
@[to_additive] protected lemma mul_eq_one_iff_eq_inv (h : is_unit b) : a * b = 1 β a = bβ»ΒΉ :=
@units.mul_eq_one_iff_eq_inv _ _ h.unit' _
@[to_additive] protected lemma mul_eq_one_iff_inv_eq (h : is_unit a) : a * b = 1 β aβ»ΒΉ = b :=
@units.mul_eq_one_iff_inv_eq _ _ h.unit' _
@[simp, to_additive] protected lemma div_mul_cancel (h : is_unit b) (a : Ξ±) : a / b * b = a :=
by rw [div_eq_mul_inv, h.inv_mul_cancel_right]
@[simp, to_additive] protected lemma mul_div_cancel (h : is_unit b) (a : Ξ±) : a * b / b = a :=
by rw [div_eq_mul_inv, h.mul_inv_cancel_right]
@[to_additive] protected lemma mul_one_div_cancel (h : is_unit a) : a * (1 / a) = 1 := by simp [h]
@[to_additive] protected lemma one_div_mul_cancel (h : is_unit a) : (1 / a) * a = 1 := by simp [h]
@[to_additive] lemma inv : is_unit a β is_unit aβ»ΒΉ :=
by { rintro β¨u, rflβ©, rw βunits.coe_inv, exact units.is_unit _ }
@[to_additive] lemma div (ha : is_unit a) (hb : is_unit b) : is_unit (a / b) :=
by { rw div_eq_mul_inv, exact ha.mul hb.inv }
@[to_additive] protected lemma div_left_inj (h : is_unit c) : a / c = b / c β a = b :=
by { simp_rw div_eq_mul_inv, exact units.mul_left_inj h.inv.unit' }
@[to_additive] protected lemma div_eq_iff (h : is_unit b) : a / b = c β a = c * b :=
by rw [div_eq_mul_inv, h.mul_inv_eq_iff_eq_mul]
@[to_additive] protected lemma eq_div_iff (h : is_unit c) : a = b / c β a * c = b :=
by rw [div_eq_mul_inv, h.eq_mul_inv_iff_mul_eq]
@[to_additive] protected lemma div_eq_of_eq_mul (h : is_unit b) : a = c * b β a / b = c :=
h.div_eq_iff.2
@[to_additive] protected lemma eq_div_of_mul_eq (h : is_unit c) : a * c = b β a = b / c :=
h.eq_div_iff.2
@[to_additive] protected lemma div_eq_one_iff_eq (h : is_unit b) : a / b = 1 β a = b :=
β¨eq_of_div_eq_one, Ξ» hab, hab.symm βΈ h.div_selfβ©
@[to_additive] protected lemma div_mul_left (h : is_unit b) : b / (a * b) = 1 / a :=
by rw [div_eq_mul_inv, mul_inv_rev, h.mul_inv_cancel_left, one_div]
@[to_additive] protected lemma mul_div_mul_right (h : is_unit c) (a b : Ξ±) :
(a * c) / (b * c) = a / b :=
by simp only [div_eq_mul_inv, mul_inv_rev, mul_assoc, h.mul_inv_cancel_left]
@[to_additive] protected lemma mul_mul_div (a : Ξ±) (h : is_unit b) : a * b * (1 / b) = a :=
by simp [h]
end division_monoid
section division_comm_monoid
variables [division_comm_monoid Ξ±] {a b c d : Ξ±}
@[to_additive] protected lemma div_mul_right (h : is_unit a) (b : Ξ±) : a / (a * b) = 1 / b :=
by rw [mul_comm, h.div_mul_left]
@[to_additive] protected lemma mul_div_cancel_left (h : is_unit a) (b : Ξ±) : a * b / a = b :=
by rw [mul_comm, h.mul_div_cancel]
@[to_additive] protected lemma mul_div_cancel' (h : is_unit a) (b : Ξ±) : a * (b / a) = b :=
by rw [mul_comm, h.div_mul_cancel]
@[to_additive] protected lemma mul_div_mul_left (h : is_unit c) (a b : Ξ±) :
(c * a) / (c * b) = a / b :=
by rw [mul_comm c, mul_comm c, h.mul_div_mul_right]
@[to_additive] protected lemma mul_eq_mul_of_div_eq_div (hb : is_unit b) (hd : is_unit d) (a c : Ξ±)
(h : a / b = c / d) : a * d = c * b :=
by rw [βmul_one a, βhb.div_self, βmul_comm_div, h, div_mul_eq_mul_div, hd.div_mul_cancel]
@[to_additive] protected lemma div_eq_div_iff (hb : is_unit b) (hd : is_unit d) :
a / b = c / d β a * d = c * b :=
by rw [β(hb.mul hd).mul_left_inj, βmul_assoc, hb.div_mul_cancel, βmul_assoc, mul_right_comm,
hd.div_mul_cancel]
@[to_additive] protected lemma div_div_cancel (h : is_unit a) : a / (a / b) = b :=
by rw [div_div_eq_mul_div, h.mul_div_cancel_left]
end division_comm_monoid
end is_unit
|
00d72716ab828024628f2446bb88db36fde72562 | 4727251e0cd73359b15b664c3170e5d754078599 | /src/group_theory/perm/list.lean | 72889079344dd4f7d4f7580ae438d67fefb58d13 | [
"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 | 16,095 | lean | /-
Copyright (c) 2021 Yakov Pechersky. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yakov Pechersky
-/
import data.list.rotate
import group_theory.perm.support
/-!
# Permutations from a list
A list `l : list Ξ±` can be interpreted as a `equiv.perm Ξ±` where each element in the list
is permuted to the next one, defined as `form_perm`. When we have that `nodup l`,
we prove that `equiv.perm.support (form_perm l) = l.to_finset`, and that
`form_perm l` is rotationally invariant, in `form_perm_rotate`.
When there are duplicate elements in `l`, how and in what arrangement with respect to the other
elements they appear in the list determines the formed permutation.
This is because `list.form_perm` is implemented as a product of `equiv.swap`s.
That means that presence of a sublist of two adjacent duplicates like `[..., x, x, ...]`
will produce the same permutation as if the adjacent duplicates were not present.
The `list.form_perm` definition is meant to primarily be used with `nodup l`, so that
the resulting permutation is cyclic (if `l` has at least two elements).
The presence of duplicates in a particular placement can lead `list.form_perm` to produce a
nontrivial permutation that is noncyclic.
-/
namespace list
variables {Ξ± Ξ² : Type*}
section form_perm
variables [decidable_eq Ξ±] (l : list Ξ±)
open equiv equiv.perm
/--
A list `l : list Ξ±` can be interpreted as a `equiv.perm Ξ±` where each element in the list
is permuted to the next one, defined as `form_perm`. When we have that `nodup l`,
we prove that `equiv.perm.support (form_perm l) = l.to_finset`, and that
`form_perm l` is rotationally invariant, in `form_perm_rotate`.
-/
def form_perm : equiv.perm Ξ± :=
(zip_with equiv.swap l l.tail).prod
@[simp] lemma form_perm_nil : form_perm ([] : list Ξ±) = 1 := rfl
@[simp] lemma form_perm_singleton (x : Ξ±) : form_perm [x] = 1 := rfl
@[simp] lemma form_perm_cons_cons (x y : Ξ±) (l : list Ξ±) :
form_perm (x :: y :: l) = swap x y * form_perm (y :: l) :=
prod_cons
lemma form_perm_pair (x y : Ξ±) : form_perm [x, y] = swap x y := rfl
lemma form_perm_apply_of_not_mem (x : Ξ±) (l : list Ξ±) (h : x β l) :
form_perm l x = x :=
begin
cases l with y l,
{ simp },
induction l with z l IH generalizing x y,
{ simp },
{ specialize IH x z (mt (mem_cons_of_mem y) h),
simp only [not_or_distrib, mem_cons_iff] at h,
simp [IH, swap_apply_of_ne_of_ne, h] }
end
lemma form_perm_apply_mem_of_mem (x : Ξ±) (l : list Ξ±) (h : x β l) :
form_perm l x β l :=
begin
cases l with y l,
{ simpa },
induction l with z l IH generalizing x y,
{ simpa using h },
{ by_cases hx : x β z :: l,
{ rw [form_perm_cons_cons, mul_apply, swap_apply_def],
split_ifs;
simp [IH _ _ hx] },
{ replace h : x = y := or.resolve_right h hx,
simp [form_perm_apply_of_not_mem _ _ hx, βh] } }
end
@[simp] lemma form_perm_cons_concat_apply_last (x y : Ξ±) (xs : list Ξ±) :
form_perm (x :: (xs ++ [y])) y = x :=
begin
induction xs with z xs IH generalizing x y,
{ simp },
{ simp [IH] }
end
@[simp] lemma form_perm_apply_last (x : Ξ±) (xs : list Ξ±) :
form_perm (x :: xs) ((x :: xs).last (cons_ne_nil x xs)) = x :=
begin
induction xs using list.reverse_rec_on with xs y IH generalizing x;
simp
end
@[simp] lemma form_perm_apply_nth_le_length (x : Ξ±) (xs : list Ξ±) :
form_perm (x :: xs) ((x :: xs).nth_le xs.length (by simp)) = x :=
by rw [nth_le_cons_length, form_perm_apply_last]
lemma form_perm_apply_head (x y : Ξ±) (xs : list Ξ±) (h : nodup (x :: y :: xs)) :
form_perm (x :: y :: xs) x = y :=
by simp [form_perm_apply_of_not_mem _ _ h.not_mem]
lemma form_perm_apply_nth_le_zero (l : list Ξ±) (h : nodup l) (hl : 1 < l.length) :
form_perm l (l.nth_le 0 (zero_lt_one.trans hl)) = l.nth_le 1 hl :=
begin
rcases l with (_|β¨x, _|β¨y, tlβ©β©),
{ simp },
{ simp },
{ simpa using form_perm_apply_head _ _ _ h }
end
lemma form_perm_eq_head_iff_eq_last (x y : Ξ±) :
form_perm (y :: l) x = y β x = last (y :: l) (cons_ne_nil _ _) :=
iff.trans (by rw form_perm_apply_last) (form_perm (y :: l)).injective.eq_iff
lemma zip_with_swap_prod_support' (l l' : list Ξ±) :
{x | (zip_with swap l l').prod x β x} β€ l.to_finset β l'.to_finset :=
begin
simp only [set.sup_eq_union, set.le_eq_subset],
induction l with y l hl generalizing l',
{ simp },
{ cases l' with z l',
{ simp },
{ intro x,
simp only [set.union_subset_iff, mem_cons_iff, zip_with_cons_cons, foldr, prod_cons,
mul_apply],
intro hx,
by_cases h : x β {x | (zip_with swap l l').prod x β x},
{ specialize hl l' h,
refine set.mem_union.elim hl (Ξ» hm, _) (Ξ» hm, _);
{ simp only [finset.coe_insert, set.mem_insert_iff, finset.mem_coe, to_finset_cons,
mem_to_finset] at hm β’,
simp [hm] } },
{ simp only [not_not, set.mem_set_of_eq] at h,
simp only [h, set.mem_set_of_eq] at hx,
rw swap_apply_ne_self_iff at hx,
rcases hx with β¨hyz, rfl|rflβ©;
simp } } }
end
lemma zip_with_swap_prod_support [fintype Ξ±] (l l' : list Ξ±) :
(zip_with swap l l').prod.support β€ l.to_finset β l'.to_finset :=
begin
intros x hx,
have hx' : x β {x | (zip_with swap l l').prod x β x} := by simpa using hx,
simpa using zip_with_swap_prod_support' _ _ hx'
end
lemma support_form_perm_le' : {x | form_perm l x β x} β€ l.to_finset :=
begin
refine (zip_with_swap_prod_support' l l.tail).trans _,
simpa [finset.subset_iff] using tail_subset l
end
lemma support_form_perm_le [fintype Ξ±] : support (form_perm l) β€ l.to_finset :=
begin
intros x hx,
have hx' : x β {x | form_perm l x β x} := by simpa using hx,
simpa using support_form_perm_le' _ hx'
end
lemma form_perm_apply_lt (xs : list Ξ±) (h : nodup xs) (n : β) (hn : n + 1 < xs.length) :
form_perm xs (xs.nth_le n ((nat.lt_succ_self n).trans hn)) = xs.nth_le (n + 1) hn :=
begin
induction n with n IH generalizing xs,
{ simpa using form_perm_apply_nth_le_zero _ h _ },
{ rcases xs with (_|β¨x, _|β¨y, lβ©β©),
{ simp },
{ simp },
{ specialize IH (y :: l) h.of_cons _,
{ simpa [nat.succ_lt_succ_iff] using hn },
simp only [swap_apply_eq_iff, coe_mul, form_perm_cons_cons, nth_le],
generalize_proofs at IH,
rw [IH, swap_apply_of_ne_of_ne, nth_le];
{ rintro rfl,
simpa [nth_le_mem _ _ _] using h } } }
end
lemma form_perm_apply_nth_le (xs : list Ξ±) (h : nodup xs) (n : β) (hn : n < xs.length) :
form_perm xs (xs.nth_le n hn) = xs.nth_le ((n + 1) % xs.length)
(nat.mod_lt _ (n.zero_le.trans_lt hn)) :=
begin
cases xs with x xs,
{ simp },
{ have : n β€ xs.length,
{ refine nat.le_of_lt_succ _,
simpa using hn },
rcases this.eq_or_lt with rfl|hn',
{ simp },
{ simp [form_perm_apply_lt, h, nat.mod_eq_of_lt, nat.succ_lt_succ hn'] } }
end
lemma support_form_perm_of_nodup' (l : list Ξ±) (h : nodup l) (h' : β (x : Ξ±), l β [x]) :
{x | form_perm l x β x} = l.to_finset :=
begin
apply le_antisymm,
{ exact support_form_perm_le' l },
{ intros x hx,
simp only [finset.mem_coe, mem_to_finset] at hx,
obtain β¨n, hn, rflβ© := nth_le_of_mem hx,
rw [set.mem_set_of_eq, form_perm_apply_nth_le _ h],
intro H,
rw nodup_iff_nth_le_inj at h,
specialize h _ _ _ _ H,
cases (nat.succ_le_of_lt hn).eq_or_lt with hn' hn',
{ simp only [βhn', nat.mod_self] at h,
refine not_exists.mpr h' _,
simpa [βh, eq_comm, length_eq_one] using hn' },
{ simpa [nat.mod_eq_of_lt hn'] using h } }
end
lemma support_form_perm_of_nodup [fintype Ξ±] (l : list Ξ±) (h : nodup l) (h' : β (x : Ξ±), l β [x]) :
support (form_perm l) = l.to_finset :=
begin
rw βfinset.coe_inj,
convert support_form_perm_of_nodup' _ h h',
simp [set.ext_iff]
end
lemma form_perm_rotate_one (l : list Ξ±) (h : nodup l) :
form_perm (l.rotate 1) = form_perm l :=
begin
have h' : nodup (l.rotate 1),
{ simpa using h },
ext x,
by_cases hx : x β l.rotate 1,
{ obtain β¨k, hk, rflβ© := nth_le_of_mem hx,
rw [form_perm_apply_nth_le _ h', nth_le_rotate l, nth_le_rotate l,
form_perm_apply_nth_le _ h],
simp },
{ rw [form_perm_apply_of_not_mem _ _ hx, form_perm_apply_of_not_mem],
simpa using hx }
end
lemma form_perm_rotate (l : list Ξ±) (h : nodup l) (n : β) :
form_perm (l.rotate n) = form_perm l :=
begin
induction n with n hn,
{ simp },
{ rw [nat.succ_eq_add_one, βrotate_rotate, form_perm_rotate_one, hn],
rwa is_rotated.nodup_iff,
exact is_rotated.forall l n }
end
lemma form_perm_eq_of_is_rotated {l l' : list Ξ±} (hd : nodup l) (h : l ~r l') :
form_perm l = form_perm l' :=
begin
obtain β¨n, rflβ© := h,
exact (form_perm_rotate l hd n).symm
end
lemma form_perm_reverse (l : list Ξ±) (h : nodup l) :
form_perm l.reverse = (form_perm l)β»ΒΉ :=
begin
-- Let's show `form_perm l` is an inverse to `form_perm l.reverse`.
rw [eq_comm, inv_eq_iff_mul_eq_one],
ext x,
-- We only have to check for `x β l` that `form_perm l (form_perm l.reverse x)`
rw [mul_apply, one_apply],
by_cases hx : x β l,
swap,
{ rw [form_perm_apply_of_not_mem x l.reverse, form_perm_apply_of_not_mem _ _ hx],
simpa using hx },
{ obtain β¨k, hk, rflβ© := nth_le_of_mem (mem_reverse.mpr hx),
rw [form_perm_apply_nth_le l.reverse (nodup_reverse.mpr h),
nth_le_reverse', form_perm_apply_nth_le _ h, nth_le_reverse'],
{ congr,
rw [length_reverse, βnat.succ_le_iff, nat.succ_eq_add_one] at hk,
cases hk.eq_or_lt with hk' hk',
{ simp [βhk'] },
{ rw [length_reverse, nat.mod_eq_of_lt hk', tsub_add_eq_add_tsub (nat.le_pred_of_lt hk'),
nat.mod_eq_of_lt],
{ simp },
{ rw tsub_add_cancel_of_le,
refine tsub_lt_self _ (nat.zero_lt_succ _),
all_goals { simpa using (nat.zero_le _).trans_lt hk' } } } },
all_goals { rw [β tsub_add_eq_tsub_tsub, βlength_reverse],
refine tsub_lt_self _ (zero_lt_one.trans_le (le_add_right le_rfl)),
exact k.zero_le.trans_lt hk } },
end
lemma form_perm_pow_apply_nth_le (l : list Ξ±) (h : nodup l) (n k : β) (hk : k < l.length) :
(form_perm l ^ n) (l.nth_le k hk) = l.nth_le ((k + n) % l.length)
(nat.mod_lt _ (k.zero_le.trans_lt hk)) :=
begin
induction n with n hn,
{ simp [nat.mod_eq_of_lt hk] },
{ simp [pow_succ, mul_apply, hn, form_perm_apply_nth_le _ h, nat.succ_eq_add_one,
βnat.add_assoc] }
end
lemma form_perm_pow_apply_head (x : Ξ±) (l : list Ξ±) (h : nodup (x :: l)) (n : β) :
(form_perm (x :: l) ^ n) x =
(x :: l).nth_le (n % (x :: l).length) (nat.mod_lt _ (nat.zero_lt_succ _)) :=
by { convert form_perm_pow_apply_nth_le _ h n 0 _; simp }
lemma form_perm_ext_iff {x y x' y' : Ξ±} {l l' : list Ξ±}
(hd : nodup (x :: y :: l)) (hd' : nodup (x' :: y' :: l')) :
form_perm (x :: y :: l) = form_perm (x' :: y' :: l') β (x :: y :: l) ~r (x' :: y' :: l') :=
begin
refine β¨Ξ» h, _, Ξ» hr, form_perm_eq_of_is_rotated hd hrβ©,
rw equiv.perm.ext_iff at h,
have hx : x' β (x :: y :: l),
{ have : x' β {z | form_perm (x :: y :: l) z β z},
{ rw [set.mem_set_of_eq, h x', form_perm_apply_head _ _ _ hd'],
simp only [mem_cons_iff, nodup_cons] at hd',
push_neg at hd',
exact hd'.left.left.symm },
simpa using support_form_perm_le' _ this },
obtain β¨n, hn, hx'β© := nth_le_of_mem hx,
have hl : (x :: y :: l).length = (x' :: y' :: l').length,
{ rw [βdedup_eq_self.mpr hd, βdedup_eq_self.mpr hd',
βcard_to_finset, βcard_to_finset],
refine congr_arg finset.card _,
rw [βfinset.coe_inj, βsupport_form_perm_of_nodup' _ hd (by simp),
βsupport_form_perm_of_nodup' _ hd' (by simp)],
simp only [h] },
use n,
apply list.ext_le,
{ rw [length_rotate, hl] },
{ intros k hk hk',
rw nth_le_rotate,
induction k with k IH,
{ simp_rw [nat.zero_add, nat.mod_eq_of_lt hn],
simpa },
{ have : k.succ = (k + 1) % (x' :: y' :: l').length,
{ rw [βnat.succ_eq_add_one, nat.mod_eq_of_lt hk'] },
simp_rw this,
rw [βform_perm_apply_nth_le _ hd' k (k.lt_succ_self.trans hk'),
βIH (k.lt_succ_self.trans hk), βh, form_perm_apply_nth_le _ hd],
congr' 1,
have h1 : 1 = 1 % (x' :: y' :: l').length := by simp,
rw [hl, nat.mod_eq_of_lt hk', h1, βnat.add_mod, nat.succ_add] } }
end
lemma form_perm_apply_mem_eq_self_iff (hl : nodup l) (x : Ξ±) (hx : x β l) :
form_perm l x = x β length l β€ 1 :=
begin
obtain β¨k, hk, rflβ© := nth_le_of_mem hx,
rw [form_perm_apply_nth_le _ hl, hl.nth_le_inj_iff],
cases hn : l.length,
{ exact absurd k.zero_le (hk.trans_le hn.le).not_le },
{ rw hn at hk,
cases (nat.le_of_lt_succ hk).eq_or_lt with hk' hk',
{ simp [βhk', nat.succ_le_succ_iff, eq_comm] },
{ simpa [nat.mod_eq_of_lt (nat.succ_lt_succ hk'), nat.succ_lt_succ_iff]
using k.zero_le.trans_lt hk' } }
end
lemma form_perm_apply_mem_ne_self_iff (hl : nodup l) (x : Ξ±) (hx : x β l) :
form_perm l x β x β 2 β€ l.length :=
begin
rw [ne.def, form_perm_apply_mem_eq_self_iff _ hl x hx, not_le],
exact β¨nat.succ_le_of_lt, nat.lt_of_succ_leβ©
end
lemma mem_of_form_perm_ne_self (l : list Ξ±) (x : Ξ±) (h : form_perm l x β x) :
x β l :=
begin
suffices : x β {y | form_perm l y β y},
{ rw βmem_to_finset,
exact support_form_perm_le' _ this },
simpa using h
end
lemma form_perm_eq_self_of_not_mem (l : list Ξ±) (x : Ξ±) (h : x β l) :
form_perm l x = x :=
by_contra (Ξ» H, h $ mem_of_form_perm_ne_self _ _ H)
lemma form_perm_eq_one_iff (hl : nodup l) :
form_perm l = 1 β l.length β€ 1 :=
begin
cases l with hd tl,
{ simp },
{ rw βform_perm_apply_mem_eq_self_iff _ hl hd (mem_cons_self _ _),
split,
{ simp {contextual := tt} },
{ intro h,
simp only [(hd :: tl).form_perm_apply_mem_eq_self_iff hl hd (mem_cons_self hd tl),
add_le_iff_nonpos_left, length, nonpos_iff_eq_zero, length_eq_zero] at h,
simp [h] } }
end
lemma form_perm_eq_form_perm_iff {l l' : list Ξ±} (hl : l.nodup) (hl' : l'.nodup) :
l.form_perm = l'.form_perm β l ~r l' β¨ l.length β€ 1 β§ l'.length β€ 1 :=
begin
rcases l with (_ | β¨x, _ | β¨y, lβ©β©),
{ suffices : l'.length β€ 1 β l' = nil β¨ l'.length β€ 1,
{ simpa [eq_comm, form_perm_eq_one_iff, hl, hl', length_eq_zero] },
refine β¨Ξ» h, or.inr h, _β©,
rintro (rfl | h),
{ simp },
{ exact h } },
{ suffices : l'.length β€ 1 β [x] ~r l' β¨ l'.length β€ 1,
{ simpa [eq_comm, form_perm_eq_one_iff, hl, hl', length_eq_zero, le_rfl] },
refine β¨Ξ» h, or.inr h, _β©,
rintro (h | h),
{ simp [βh.perm.length_eq] },
{ exact h } },
{ rcases l' with (_ | β¨x', _ | β¨y', l'β©β©),
{ simp [form_perm_eq_one_iff, hl, -form_perm_cons_cons] },
{ suffices : Β¬ (x :: y :: l) ~r [x'],
{ simp [form_perm_eq_one_iff, hl, -form_perm_cons_cons] },
intro h,
simpa using h.perm.length_eq },
{ simp [-form_perm_cons_cons, form_perm_ext_iff hl hl'] } }
end
lemma form_perm_zpow_apply_mem_imp_mem (l : list Ξ±) (x : Ξ±) (hx : x β l) (n : β€) :
((form_perm l) ^ n) x β l :=
begin
by_cases h : (l.form_perm ^ n) x = x,
{ simpa [h] using hx },
{ have : x β {x | (l.form_perm ^ n) x β x} := h,
rw βset_support_apply_mem at this,
replace this := set_support_zpow_subset _ _ this,
simpa using support_form_perm_le' _ this }
end
lemma form_perm_pow_length_eq_one_of_nodup (hl : nodup l) :
(form_perm l) ^ (length l) = 1 :=
begin
ext x,
by_cases hx : x β l,
{ obtain β¨k, hk, rflβ© := nth_le_of_mem hx,
simp [form_perm_pow_apply_nth_le _ hl, nat.mod_eq_of_lt hk] },
{ have : x β {x | (l.form_perm ^ l.length) x β x},
{ intros H,
refine hx _,
replace H := set_support_zpow_subset l.form_perm l.length H,
simpa using support_form_perm_le' _ H },
simpa }
end
end form_perm
end list
|
c76faa74f871e029105dcf602fb748b2a31064c2 | c777c32c8e484e195053731103c5e52af26a25d1 | /src/measure_theory/function/l2_space.lean | ee1620be1b073368d765d2bd855dcf320acce55f | [
"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 | 10,834 | lean | /-
Copyright (c) 2021 RΓ©my Degenne. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: RΓ©my Degenne
-/
import analysis.inner_product_space.basic
import measure_theory.integral.set_integral
/-! # `L^2` space
If `E` is an inner product space over `π` (`β` or `β`), then `Lp E 2 ΞΌ` (defined in `lp_space.lean`)
is also an inner product space, with inner product defined as `inner f g = β« a, βͺf a, g aβ« βΞΌ`.
### Main results
* `mem_L1_inner` : for `f` and `g` in `Lp E 2 ΞΌ`, the pointwise inner product `Ξ» x, βͺf x, g xβ«`
belongs to `Lp π 1 ΞΌ`.
* `integrable_inner` : for `f` and `g` in `Lp E 2 ΞΌ`, the pointwise inner product `Ξ» x, βͺf x, g xβ«`
is integrable.
* `L2.inner_product_space` : `Lp E 2 ΞΌ` is an inner product space.
-/
noncomputable theory
open topological_space measure_theory measure_theory.Lp
open_locale nnreal ennreal measure_theory
namespace measure_theory
section
variables {Ξ± F : Type*} {m : measurable_space Ξ±} {ΞΌ : measure Ξ±} [normed_add_comm_group F]
lemma mem_βp.integrable_sq {f : Ξ± β β} (h : mem_βp f 2 ΞΌ) :
integrable (Ξ» x, (f x)^2) ΞΌ :=
by simpa [β mem_βp_one_iff_integrable]
using h.norm_rpow two_ne_zero ennreal.two_ne_top
lemma mem_βp_two_iff_integrable_sq_norm {f : Ξ± β F} (hf : ae_strongly_measurable f ΞΌ) :
mem_βp f 2 ΞΌ β integrable (Ξ» x, βf xβ^2) ΞΌ :=
begin
rw β mem_βp_one_iff_integrable,
convert (mem_βp_norm_rpow_iff hf two_ne_zero ennreal.two_ne_top).symm,
{ simp },
{ rw [div_eq_mul_inv, ennreal.mul_inv_cancel two_ne_zero ennreal.two_ne_top] }
end
lemma mem_βp_two_iff_integrable_sq {f : Ξ± β β} (hf : ae_strongly_measurable f ΞΌ) :
mem_βp f 2 ΞΌ β integrable (Ξ» x, (f x)^2) ΞΌ :=
begin
convert mem_βp_two_iff_integrable_sq_norm hf,
ext x,
simp,
end
end
namespace L2
variables {Ξ± E F π : Type*} [is_R_or_C π] [measurable_space Ξ±] {ΞΌ : measure Ξ±}
[normed_add_comm_group E] [inner_product_space π E] [normed_add_comm_group F]
local notation `βͺ`x`, `y`β«` := @inner π _ _ x y
lemma snorm_rpow_two_norm_lt_top (f : Lp F 2 ΞΌ) : snorm (Ξ» x, βf xβ ^ (2 : β)) 1 ΞΌ < β :=
begin
have h_two : ennreal.of_real (2 : β) = 2, by simp [zero_le_one],
rw [snorm_norm_rpow f zero_lt_two, one_mul, h_two],
exact ennreal.rpow_lt_top_of_nonneg zero_le_two (Lp.snorm_ne_top f),
end
lemma snorm_inner_lt_top (f g : Ξ± ββ[ΞΌ] E) : snorm (Ξ» (x : Ξ±), βͺf x, g xβ«) 1 ΞΌ < β :=
begin
have h : β x, ββͺf x, g xβ«β β€ ββf xβ ^ (2 : β) + βg xβ ^ (2 : β)β,
{ intro x,
rw [β @nat.cast_two β, real.rpow_nat_cast, real.rpow_nat_cast],
calc ββͺf x, g xβ«β β€ βf xβ * βg xβ : norm_inner_le_norm _ _
... β€ 2 * βf xβ * βg xβ :
mul_le_mul_of_nonneg_right (le_mul_of_one_le_left (norm_nonneg _) one_le_two) (norm_nonneg _)
... β€ ββf xβ^2 + βg xβ^2β : (two_mul_le_add_sq _ _).trans (le_abs_self _) },
refine (snorm_mono_ae (ae_of_all _ h)).trans_lt ((snorm_add_le _ _ le_rfl).trans_lt _),
{ exact ((Lp.ae_strongly_measurable f).norm.ae_measurable.pow_const _).ae_strongly_measurable },
{ exact ((Lp.ae_strongly_measurable g).norm.ae_measurable.pow_const _).ae_strongly_measurable },
rw [ennreal.add_lt_top],
exact β¨snorm_rpow_two_norm_lt_top f, snorm_rpow_two_norm_lt_top gβ©,
end
section inner_product_space
open_locale complex_conjugate
include π
instance : has_inner π (Ξ± ββ[ΞΌ] E) := β¨Ξ» f g, β« a, βͺf a, g aβ« βΞΌβ©
lemma inner_def (f g : Ξ± ββ[ΞΌ] E) : βͺf, gβ« = β« a : Ξ±, βͺf a, g aβ« βΞΌ := rfl
lemma integral_inner_eq_sq_snorm (f : Ξ± ββ[ΞΌ] E) :
β« a, βͺf a, f aβ« βΞΌ = ennreal.to_real β«β» a, (βf aββ : ββ₯0β) ^ (2:β) βΞΌ :=
begin
simp_rw inner_self_eq_norm_sq_to_K,
norm_cast,
rw integral_eq_lintegral_of_nonneg_ae,
rotate,
{ exact filter.eventually_of_forall (Ξ» x, sq_nonneg _), },
{ exact ((Lp.ae_strongly_measurable f).norm.ae_measurable.pow_const _).ae_strongly_measurable },
congr,
ext1 x,
have h_two : (2 : β) = ((2 : β) : β), by simp,
rw [β real.rpow_nat_cast _ 2, β h_two,
β ennreal.of_real_rpow_of_nonneg (norm_nonneg _) zero_le_two, of_real_norm_eq_coe_nnnorm],
norm_cast,
end
private lemma norm_sq_eq_inner' (f : Ξ± ββ[ΞΌ] E) : βfβ ^ 2 = is_R_or_C.re βͺf, fβ« :=
begin
have h_two : (2 : ββ₯0β).to_real = 2 := by simp,
rw [inner_def, integral_inner_eq_sq_snorm, norm_def, β ennreal.to_real_pow, is_R_or_C.of_real_re,
ennreal.to_real_eq_to_real (ennreal.pow_ne_top (Lp.snorm_ne_top f)) _],
{ rw [βennreal.rpow_nat_cast, snorm_eq_snorm' two_ne_zero ennreal.two_ne_top, snorm',
β ennreal.rpow_mul, one_div, h_two],
simp, },
{ refine (lintegral_rpow_nnnorm_lt_top_of_snorm'_lt_top zero_lt_two _).ne,
rw [β h_two, β snorm_eq_snorm' two_ne_zero ennreal.two_ne_top],
exact Lp.snorm_lt_top f, },
end
lemma mem_L1_inner (f g : Ξ± ββ[ΞΌ] E) :
ae_eq_fun.mk (Ξ» x, βͺf x, g xβ«)
((Lp.ae_strongly_measurable f).inner (Lp.ae_strongly_measurable g)) β Lp π 1 ΞΌ :=
by { simp_rw [mem_Lp_iff_snorm_lt_top, snorm_ae_eq_fun], exact snorm_inner_lt_top f g, }
lemma integrable_inner (f g : Ξ± ββ[ΞΌ] E) : integrable (Ξ» x : Ξ±, βͺf x, g xβ«) ΞΌ :=
(integrable_congr (ae_eq_fun.coe_fn_mk (Ξ» x, βͺf x, g xβ«)
((Lp.ae_strongly_measurable f).inner (Lp.ae_strongly_measurable g)))).mp
(ae_eq_fun.integrable_iff_mem_L1.mpr (mem_L1_inner f g))
private lemma add_left' (f f' g : Ξ± ββ[ΞΌ] E) : βͺf + f', gβ« = inner f g + inner f' g :=
begin
simp_rw [inner_def, β integral_add (integrable_inner f g) (integrable_inner f' g),
βinner_add_left],
refine integral_congr_ae ((coe_fn_add f f').mono (Ξ» x hx, _)),
congr,
rwa pi.add_apply at hx,
end
private lemma smul_left' (f g : Ξ± ββ[ΞΌ] E) (r : π) :
βͺr β’ f, gβ« = conj r * inner f g :=
begin
rw [inner_def, inner_def, β smul_eq_mul, β integral_smul],
refine integral_congr_ae ((coe_fn_smul r f).mono (Ξ» x hx, _)),
rw [smul_eq_mul, β inner_smul_left],
congr,
rwa pi.smul_apply at hx,
end
instance inner_product_space : inner_product_space π (Ξ± ββ[ΞΌ] E) :=
{ norm_sq_eq_inner := norm_sq_eq_inner',
conj_symm := Ξ» _ _, by simp_rw [inner_def, β integral_conj, inner_conj_symm],
add_left := add_left',
smul_left := smul_left', }
end inner_product_space
section indicator_const_Lp
variables (π) {s : set Ξ±}
/-- The inner product in `L2` of the indicator of a set `indicator_const_Lp 2 hs hΞΌs c` and `f` is
equal to the integral of the inner product over `s`: `β« x in s, βͺc, f xβ« βΞΌ`. -/
lemma inner_indicator_const_Lp_eq_set_integral_inner (f : Lp E 2 ΞΌ) (hs : measurable_set s) (c : E)
(hΞΌs : ΞΌ s β β) :
(βͺindicator_const_Lp 2 hs hΞΌs c, fβ« : π) = β« x in s, βͺc, f xβ« βΞΌ :=
begin
rw [inner_def, β integral_add_compl hs (L2.integrable_inner _ f)],
have h_left : β« x in s, βͺ(indicator_const_Lp 2 hs hΞΌs c) x, f xβ« βΞΌ = β« x in s, βͺc, f xβ« βΞΌ,
{ suffices h_ae_eq : βα΅ x βΞΌ, x β s β βͺindicator_const_Lp 2 hs hΞΌs c x, f xβ« = βͺc, f xβ«,
from set_integral_congr_ae hs h_ae_eq,
have h_indicator : βα΅ (x : Ξ±) βΞΌ, x β s β (indicator_const_Lp 2 hs hΞΌs c x) = c,
from indicator_const_Lp_coe_fn_mem,
refine h_indicator.mono (Ξ» x hx hxs, _),
congr,
exact hx hxs, },
have h_right : β« x in sαΆ, βͺ(indicator_const_Lp 2 hs hΞΌs c) x, f xβ« βΞΌ = 0,
{ suffices h_ae_eq : βα΅ x βΞΌ, x β s β βͺindicator_const_Lp 2 hs hΞΌs c x, f xβ« = 0,
{ simp_rw β set.mem_compl_iff at h_ae_eq,
suffices h_int_zero : β« x in sαΆ, inner (indicator_const_Lp 2 hs hΞΌs c x) (f x) βΞΌ
= β« x in sαΆ, (0 : π) βΞΌ,
{ rw h_int_zero,
simp, },
exact set_integral_congr_ae hs.compl h_ae_eq, },
have h_indicator : βα΅ (x : Ξ±) βΞΌ, x β s β (indicator_const_Lp 2 hs hΞΌs c x) = 0,
from indicator_const_Lp_coe_fn_nmem,
refine h_indicator.mono (Ξ» x hx hxs, _),
rw hx hxs,
exact inner_zero_left _, },
rw [h_left, h_right, add_zero],
end
/-- The inner product in `L2` of the indicator of a set `indicator_const_Lp 2 hs hΞΌs c` and `f` is
equal to the inner product of the constant `c` and the integral of `f` over `s`. -/
lemma inner_indicator_const_Lp_eq_inner_set_integral [complete_space E] [normed_space β E]
(hs : measurable_set s) (hΞΌs : ΞΌ s β β) (c : E) (f : Lp E 2 ΞΌ) :
(βͺindicator_const_Lp 2 hs hΞΌs c, fβ« : π) = βͺc, β« x in s, f x βΞΌβ« :=
by rw [β integral_inner (integrable_on_Lp_of_measure_ne_top f fact_one_le_two_ennreal.elim hΞΌs),
L2.inner_indicator_const_Lp_eq_set_integral_inner]
variables {π}
/-- The inner product in `L2` of the indicator of a set `indicator_const_Lp 2 hs hΞΌs (1 : π)` and
a real or complex function `f` is equal to the integral of `f` over `s`. -/
lemma inner_indicator_const_Lp_one (hs : measurable_set s) (hΞΌs : ΞΌ s β β) (f : Lp π 2 ΞΌ) :
βͺindicator_const_Lp 2 hs hΞΌs (1 : π), fβ« = β« x in s, f x βΞΌ :=
by { rw L2.inner_indicator_const_Lp_eq_inner_set_integral π hs hΞΌs (1 : π) f, simp, }
end indicator_const_Lp
end L2
section inner_continuous
variables {Ξ± : Type*} [topological_space Ξ±] [measure_space Ξ±] [borel_space Ξ±] {π : Type*}
[is_R_or_C π]
variables (ΞΌ : measure Ξ±) [is_finite_measure ΞΌ]
open_locale bounded_continuous_function complex_conjugate
local notation `βͺ`x`, `y`β«` := @inner π (Ξ± ββ[ΞΌ] π) _ x y
/-- For bounded continuous functions `f`, `g` on a finite-measure topological space `Ξ±`, the L^2
inner product is the integral of their pointwise inner product. -/
lemma bounded_continuous_function.inner_to_Lp (f g : Ξ± βα΅ π) :
βͺbounded_continuous_function.to_Lp 2 ΞΌ π f, bounded_continuous_function.to_Lp 2 ΞΌ π gβ«
= β« x, conj (f x) * g x βΞΌ :=
begin
apply integral_congr_ae,
have hf_ae := f.coe_fn_to_Lp 2 ΞΌ π,
have hg_ae := g.coe_fn_to_Lp 2 ΞΌ π,
filter_upwards [hf_ae, hg_ae] with _ hf hg,
rw [hf, hg],
simp
end
variables [compact_space Ξ±]
/-- For continuous functions `f`, `g` on a compact, finite-measure topological space `Ξ±`, the L^2
inner product is the integral of their pointwise inner product. -/
lemma continuous_map.inner_to_Lp (f g : C(Ξ±, π)) :
βͺcontinuous_map.to_Lp 2 ΞΌ π f, continuous_map.to_Lp 2 ΞΌ π gβ«
= β« x, conj (f x) * g x βΞΌ :=
begin
apply integral_congr_ae,
have hf_ae := f.coe_fn_to_Lp ΞΌ,
have hg_ae := g.coe_fn_to_Lp ΞΌ,
filter_upwards [hf_ae, hg_ae] with _ hf hg,
rw [hf, hg],
simp
end
end inner_continuous
end measure_theory
|
2b1a27a4f7ed503bc04f193e21e05b045c6bbb1a | 63abd62053d479eae5abf4951554e1064a4c45b4 | /src/data/equiv/local_equiv.lean | 401ae4a4fe1852f9db09f988ddbb66369dc1c343 | [
"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 | 24,965 | 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.basic
/-!
# Local equivalences
This files defines equivalences between subsets of given types.
An element `e` of `local_equiv Ξ± Ξ²` is made of two maps `e.to_fun` and `e.inv_fun` respectively
from Ξ± to Ξ² and from Ξ² to Ξ± (just like equivs), which are inverse to each other on the subsets
`e.source` and `e.target` of respectively Ξ± and Ξ².
They are designed in particular to define charts on manifolds.
The main functionality is `e.trans f`, which composes the two local equivalences by restricting
the source and target to the maximal set where the composition makes sense.
As for equivs, we register a coercion to functions and use it in our simp normal form: we write
`e x` and `e.symm y` instead of `e.to_fun x` and `e.inv_fun y`.
## Main definitions
`equiv.to_local_equiv`: associating a local equiv to an equiv, with source = target = univ
`local_equiv.symm` : the inverse of a local equiv
`local_equiv.trans` : the composition of two local equivs
`local_equiv.refl` : the identity local equiv
`local_equiv.of_set` : the identity on a set `s`
`eq_on_source` : equivalence relation describing the "right" notion of equality for local
equivs (see below in implementation notes)
## Implementation notes
There are at least three possible implementations of local equivalences:
* equivs on subtypes
* pairs of functions taking values in `option Ξ±` and `option Ξ²`, equal to none where the local
equivalence is not defined
* pairs of functions defined everywhere, keeping the source and target as additional data
Each of these implementations has pros and cons.
* When dealing with subtypes, one still need to define additional API for composition and
restriction of domains. Checking that one always belongs to the right subtype makes things very
tedious, and leads quickly to DTT hell (as the subtype `u β© v` is not the "same" as `v β© u`, for
instance).
* With option-valued functions, the composition is very neat (it is just the usual composition, and
the domain is restricted automatically). These are implemented in `pequiv.lean`. For manifolds,
where one wants to discuss thoroughly the smoothness of the maps, this creates however a lot of
overhead as one would need to extend all classes of smoothness to option-valued maps.
* The local_equiv version as explained above is easier to use for manifolds. The drawback is that
there is extra useless data (the values of `to_fun` and `inv_fun` outside of `source` and `target`).
In particular, the equality notion between local equivs is not "the right one", i.e., coinciding
source and target and equality there. Moreover, there are no local equivs in this sense between
an empty type and a nonempty type. Since empty types are not that useful, and since one almost never
needs to talk about equal local equivs, this is not an issue in practice.
Still, we introduce an equivalence relation `eq_on_source` that captures this right notion of
equality, and show that many properties are invariant under this equivalence relation.
-/
mk_simp_attribute mfld_simps "The simpset `mfld_simps` records several simp lemmas that are
especially useful in manifolds. It is a subset of the whole set of simp lemmas, but it makes it
possible to have quicker proofs (when used with `squeeze_simp` or `simp only`) while retaining
readability.
The typical use case is the following, in a file on manifolds:
If `simp [foo, bar]` is slow, replace it with `squeeze_simp [foo, bar] with mfld_simps` and paste
its output. The list of lemmas should be reasonable (contrary to the output of
`squeeze_simp [foo, bar]` which might contain tens of lemmas), and the outcome should be quick
enough.
"
-- register in the simpset `mfld_simps` several lemmas that are often useful when dealing
-- with manifolds
attribute [mfld_simps] id.def function.comp.left_id set.mem_set_of_eq set.image_eq_empty
set.univ_inter set.preimage_univ set.prod_mk_mem_set_prod_eq and_true set.mem_univ
set.mem_image_of_mem true_and set.mem_inter_eq set.mem_preimage function.comp_app
set.inter_subset_left set.mem_prod set.range_id and_self set.mem_range_self
eq_self_iff_true forall_const forall_true_iff set.inter_univ set.preimage_id function.comp.right_id
not_false_iff and_imp set.prod_inter_prod set.univ_prod_univ true_or or_true prod.map_mk
set.preimage_inter heq_iff_eq equiv.sigma_equiv_prod_apply equiv.sigma_equiv_prod_symm_apply
subtype.coe_mk equiv.to_fun_as_coe equiv.inv_fun_as_coe
namespace tactic.interactive
/-- A very basic tactic to show that sets showing up in manifolds coincide or are included in
one another. -/
meta def mfld_set_tac : tactic unit := do
goal β tactic.target,
match goal with
| `(%%eβ = %%eβ) :=
`[ext my_y,
split;
{ assume h_my_y,
try { simp only [*, -h_my_y] with mfld_simps at h_my_y },
simp only [*] with mfld_simps }]
| `(%%eβ β %%eβ) :=
`[assume my_y h_my_y,
try { simp only [*, -h_my_y] with mfld_simps at h_my_y },
simp only [*] with mfld_simps]
| _ := tactic.fail "goal should be an equality or an inclusion"
end
end tactic.interactive
open function set
variables {Ξ± : Type*} {Ξ² : Type*} {Ξ³ : Type*} {Ξ΄ : Type*}
/-- Local equivalence between subsets `source` and `target` of Ξ± and Ξ² respectively. The (global)
maps `to_fun : Ξ± β Ξ²` and `inv_fun : Ξ² β Ξ±` map `source` to `target` and conversely, and are inverse
to each other there. The values of `to_fun` outside of `source` and of `inv_fun` outside of `target`
are irrelevant. -/
@[nolint has_inhabited_instance]
structure local_equiv (Ξ± : Type*) (Ξ² : Type*) :=
(to_fun : Ξ± β Ξ²)
(inv_fun : Ξ² β Ξ±)
(source : set Ξ±)
(target : set Ξ²)
(map_source' : β{x}, x β source β to_fun x β target)
(map_target' : β{x}, x β target β inv_fun x β source)
(left_inv' : β{x}, x β source β inv_fun (to_fun x) = x)
(right_inv' : β{x}, x β target β to_fun (inv_fun x) = x)
/-- Associating a local_equiv to an equiv-/
def equiv.to_local_equiv (e : equiv Ξ± Ξ²) : local_equiv Ξ± Ξ² :=
{ to_fun := e.to_fun,
inv_fun := e.inv_fun,
source := univ,
target := univ,
map_source' := Ξ»x hx, mem_univ _,
map_target' := Ξ»y hy, mem_univ _,
left_inv' := Ξ»x hx, e.left_inv x,
right_inv' := Ξ»x hx, e.right_inv x }
namespace local_equiv
variables (e : local_equiv Ξ± Ξ²) (e' : local_equiv Ξ² Ξ³)
/-- The inverse of a local equiv -/
protected def symm : local_equiv Ξ² Ξ± :=
{ to_fun := e.inv_fun,
inv_fun := e.to_fun,
source := e.target,
target := e.source,
map_source' := e.map_target',
map_target' := e.map_source',
left_inv' := e.right_inv',
right_inv' := e.left_inv' }
instance : has_coe_to_fun (local_equiv Ξ± Ξ²) := β¨_, local_equiv.to_funβ©
@[simp, mfld_simps] theorem coe_mk (f : Ξ± β Ξ²) (g s t ml mr il ir) :
(local_equiv.mk f g s t ml mr il ir : Ξ± β Ξ²) = f := rfl
@[simp, mfld_simps] theorem coe_symm_mk (f : Ξ± β Ξ²) (g s t ml mr il ir) :
((local_equiv.mk f g s t ml mr il ir).symm : Ξ² β Ξ±) = g := rfl
@[simp, mfld_simps] lemma to_fun_as_coe : e.to_fun = e := rfl
@[simp, mfld_simps] lemma inv_fun_as_coe : e.inv_fun = e.symm := rfl
@[simp, mfld_simps] lemma map_source {x : Ξ±} (h : x β e.source) : e x β e.target :=
e.map_source' h
protected lemma maps_to : maps_to e e.source e.target := Ξ» _, e.map_source
@[simp, mfld_simps] lemma map_target {x : Ξ²} (h : x β e.target) : e.symm x β e.source :=
e.map_target' h
lemma symm_maps_to : maps_to e.symm e.target e.source := e.symm.maps_to
@[simp, mfld_simps] lemma left_inv {x : Ξ±} (h : x β e.source) : e.symm (e x) = x :=
e.left_inv' h
protected lemma left_inv_on : left_inv_on e.symm e e.source := Ξ» _, e.left_inv
@[simp, mfld_simps] lemma right_inv {x : Ξ²} (h : x β e.target) : e (e.symm x) = x :=
e.right_inv' h
protected lemma right_inv_on : right_inv_on e.symm e e.target := Ξ» _, e.right_inv
/-- Associating to a local_equiv an equiv between the source and the target -/
protected def to_equiv : equiv (e.source) (e.target) :=
{ to_fun := Ξ» x, β¨e x, e.map_source x.memβ©,
inv_fun := Ξ» y, β¨e.symm y, e.map_target y.memβ©,
left_inv := Ξ»β¨x, hxβ©, subtype.eq $ e.left_inv hx,
right_inv := Ξ»β¨y, hyβ©, subtype.eq $ e.right_inv hy }
@[simp, mfld_simps] lemma symm_source : e.symm.source = e.target := rfl
@[simp, mfld_simps] lemma symm_target : e.symm.target = e.source := rfl
@[simp, mfld_simps] lemma symm_symm : e.symm.symm = e := by { cases e, refl }
/-- A local equiv induces a bijection between its source and target -/
lemma bij_on_source : bij_on e e.source e.target :=
inv_on.bij_on β¨e.left_inv_on, e.right_inv_onβ© e.maps_to e.symm_maps_to
lemma image_eq_target_inter_inv_preimage {s : set Ξ±} (h : s β e.source) :
e '' s = e.target β© e.symm β»ΒΉ' s :=
begin
refine subset.antisymm (Ξ»x hx, _) (Ξ»x hx, _),
{ rcases (mem_image _ _ _).1 hx with β¨y, ys, hyβ©,
rw β hy,
split,
{ apply e.map_source,
exact h ys },
{ rwa [mem_preimage, e.left_inv (h ys)] } },
{ rw β e.right_inv hx.1,
exact mem_image_of_mem _ hx.2 }
end
lemma image_inter_source_eq (s : set Ξ±) :
e '' (s β© e.source) = e.target β© e.symm β»ΒΉ' (s β© e.source) :=
e.image_eq_target_inter_inv_preimage (inter_subset_right _ _)
lemma image_inter_source_eq' (s : set Ξ±) :
e '' (s β© e.source) = e.target β© e.symm β»ΒΉ' s :=
begin
rw e.image_eq_target_inter_inv_preimage (inter_subset_right _ _),
ext x, split; { assume hx, simp at hx, simp [hx] }
end
lemma symm_image_eq_source_inter_preimage {s : set Ξ²} (h : s β e.target) :
e.symm '' s = e.source β© e β»ΒΉ' s :=
e.symm.image_eq_target_inter_inv_preimage h
lemma symm_image_inter_target_eq (s : set Ξ²) :
e.symm '' (s β© e.target) = e.source β© e β»ΒΉ' (s β© e.target) :=
e.symm.image_inter_source_eq _
lemma symm_image_inter_target_eq' (s : set Ξ²) :
e.symm '' (s β© e.target) = e.source β© e β»ΒΉ' s :=
e.symm.image_inter_source_eq' _
lemma source_inter_preimage_inv_preimage (s : set Ξ±) :
e.source β© e β»ΒΉ' (e.symm β»ΒΉ' s) = e.source β© s :=
begin
ext x, split,
{ rintros β¨hx, xsβ©,
simp only [mem_preimage, hx, e.left_inv, mem_preimage] at xs,
exact β¨hx, xsβ© },
{ rintros β¨hx, xsβ©,
simp [hx, xs] }
end
lemma target_inter_inv_preimage_preimage (s : set Ξ²) :
e.target β© e.symm β»ΒΉ' (e β»ΒΉ' s) = e.target β© s :=
e.symm.source_inter_preimage_inv_preimage _
lemma image_source_eq_target : e '' e.source = e.target :=
e.bij_on_source.image_eq
lemma source_subset_preimage_target : e.source β e β»ΒΉ' e.target :=
Ξ»x hx, e.map_source hx
lemma inv_image_target_eq_source : e.symm '' e.target = e.source :=
e.symm.bij_on_source.image_eq
lemma target_subset_preimage_source : e.target β e.symm β»ΒΉ' e.source :=
Ξ»x hx, e.map_target hx
/-- Two local equivs that have the same `source`, same `to_fun` and same `inv_fun`, coincide. -/
@[ext]
protected lemma ext {e e' : local_equiv Ξ± Ξ²} (h : βx, e x = e' x)
(hsymm : βx, e.symm x = e'.symm x) (hs : e.source = e'.source) : e = e' :=
begin
have A : (e : Ξ± β Ξ²) = e', by { ext x, exact h x },
have B : (e.symm : Ξ² β Ξ±) = e'.symm, by { ext x, exact hsymm x },
have I : e '' e.source = e.target := e.image_source_eq_target,
have I' : e' '' e'.source = e'.target := e'.image_source_eq_target,
rw [A, hs, I'] at I,
cases e; cases e',
simp * at *
end
/-- Restricting a local equivalence to e.source β© s -/
protected def restr (s : set Ξ±) : local_equiv Ξ± Ξ² :=
{ to_fun := e,
inv_fun := e.symm,
source := e.source β© s,
target := e.target β© e.symmβ»ΒΉ' s,
map_source' := Ξ»x hx, begin
simp only with mfld_simps at hx,
simp only [hx] with mfld_simps,
end,
map_target' := Ξ»y hy, begin
simp only with mfld_simps at hy,
simp only [hy] with mfld_simps,
end,
left_inv' := Ξ»x hx, e.left_inv hx.1,
right_inv' := Ξ»y hy, e.right_inv hy.1 }
@[simp, mfld_simps] lemma restr_coe (s : set Ξ±) : (e.restr s : Ξ± β Ξ²) = e := rfl
@[simp, mfld_simps] lemma restr_coe_symm (s : set Ξ±) : ((e.restr s).symm : Ξ² β Ξ±) = e.symm := rfl
@[simp, mfld_simps] lemma restr_source (s : set Ξ±) : (e.restr s).source = e.source β© s := rfl
@[simp, mfld_simps] lemma restr_target (s : set Ξ±) : (e.restr s).target = e.target β© e.symm β»ΒΉ' s := rfl
lemma restr_eq_of_source_subset {e : local_equiv Ξ± Ξ²} {s : set Ξ±} (h : e.source β s) :
e.restr s = e :=
local_equiv.ext (Ξ»_, rfl) (Ξ»_, rfl) (by simp [inter_eq_self_of_subset_left h])
@[simp, mfld_simps] lemma restr_univ {e : local_equiv Ξ± Ξ²} : e.restr univ = e :=
restr_eq_of_source_subset (subset_univ _)
/-- The identity local equiv -/
protected def refl (Ξ± : Type*) : local_equiv Ξ± Ξ± := (equiv.refl Ξ±).to_local_equiv
@[simp, mfld_simps] lemma refl_source : (local_equiv.refl Ξ±).source = univ := rfl
@[simp, mfld_simps] lemma refl_target : (local_equiv.refl Ξ±).target = univ := rfl
@[simp, mfld_simps] lemma refl_coe : (local_equiv.refl Ξ± : Ξ± β Ξ±) = id := rfl
@[simp, mfld_simps] lemma refl_symm : (local_equiv.refl Ξ±).symm = local_equiv.refl Ξ± := rfl
@[simp, mfld_simps] lemma refl_restr_source (s : set Ξ±) : ((local_equiv.refl Ξ±).restr s).source = s :=
by simp
@[simp, mfld_simps] lemma refl_restr_target (s : set Ξ±) : ((local_equiv.refl Ξ±).restr s).target = s :=
by { change univ β© idβ»ΒΉ' s = s, simp }
/-- The identity local equiv on a set `s` -/
def of_set (s : set Ξ±) : local_equiv Ξ± Ξ± :=
{ to_fun := id,
inv_fun := id,
source := s,
target := s,
map_source' := Ξ»x hx, hx,
map_target' := Ξ»x hx, hx,
left_inv' := Ξ»x hx, rfl,
right_inv' := Ξ»x hx, rfl }
@[simp, mfld_simps] lemma of_set_source (s : set Ξ±) : (local_equiv.of_set s).source = s := rfl
@[simp, mfld_simps] lemma of_set_target (s : set Ξ±) : (local_equiv.of_set s).target = s := rfl
@[simp, mfld_simps] lemma of_set_coe (s : set Ξ±) : (local_equiv.of_set s : Ξ± β Ξ±) = id := rfl
@[simp, mfld_simps] lemma of_set_symm (s : set Ξ±) : (local_equiv.of_set s).symm = local_equiv.of_set s := rfl
/-- Composing two local equivs if the target of the first coincides with the source of the
second. -/
protected def trans' (e' : local_equiv Ξ² Ξ³) (h : e.target = e'.source) :
local_equiv Ξ± Ξ³ :=
{ to_fun := e' β e,
inv_fun := e.symm β e'.symm,
source := e.source,
target := e'.target,
map_source' := Ξ»x hx, by simp [h.symm, hx],
map_target' := Ξ»y hy, by simp [h, hy],
left_inv' := Ξ»x hx, by simp [hx, h.symm],
right_inv' := Ξ»y hy, by simp [hy, h] }
/-- Composing two local equivs, by restricting to the maximal domain where their composition
is well defined. -/
protected def trans : local_equiv Ξ± Ξ³ :=
local_equiv.trans' (e.symm.restr (e'.source)).symm (e'.restr (e.target)) (inter_comm _ _)
@[simp, mfld_simps] lemma coe_trans : (e.trans e' : Ξ± β Ξ³) = e' β e := rfl
@[simp, mfld_simps] lemma coe_trans_symm : ((e.trans e').symm : Ξ³ β Ξ±) = e.symm β e'.symm := rfl
lemma trans_symm_eq_symm_trans_symm : (e.trans e').symm = e'.symm.trans e.symm :=
by cases e; cases e'; refl
@[simp, mfld_simps] lemma trans_source : (e.trans e').source = e.source β© e β»ΒΉ' e'.source := rfl
lemma trans_source' : (e.trans e').source = e.source β© e β»ΒΉ' (e.target β© e'.source) :=
by mfld_set_tac
lemma trans_source'' : (e.trans e').source = e.symm '' (e.target β© e'.source) :=
by rw [e.trans_source', inter_comm e.target, e.symm_image_inter_target_eq]
lemma image_trans_source : e '' (e.trans e').source = e.target β© e'.source :=
image_source_eq_target (local_equiv.symm (local_equiv.restr (local_equiv.symm e) (e'.source)))
@[simp, mfld_simps] lemma trans_target : (e.trans e').target = e'.target β© e'.symm β»ΒΉ' e.target := rfl
lemma trans_target' : (e.trans e').target = e'.target β© e'.symm β»ΒΉ' (e'.source β© e.target) :=
trans_source' e'.symm e.symm
lemma trans_target'' : (e.trans e').target = e' '' (e'.source β© e.target) :=
trans_source'' e'.symm e.symm
lemma inv_image_trans_target : e'.symm '' (e.trans e').target = e'.source β© e.target :=
image_trans_source e'.symm e.symm
lemma trans_assoc (e'' : local_equiv Ξ³ Ξ΄) : (e.trans e').trans e'' = e.trans (e'.trans e'') :=
local_equiv.ext (Ξ»x, rfl) (Ξ»x, rfl) (by simp [trans_source, @preimage_comp Ξ± Ξ² Ξ³, inter_assoc])
@[simp, mfld_simps] lemma trans_refl : e.trans (local_equiv.refl Ξ²) = e :=
local_equiv.ext (Ξ»x, rfl) (Ξ»x, rfl) (by simp [trans_source])
@[simp, mfld_simps] lemma refl_trans : (local_equiv.refl Ξ±).trans e = e :=
local_equiv.ext (Ξ»x, rfl) (Ξ»x, rfl) (by simp [trans_source, preimage_id])
lemma trans_refl_restr (s : set Ξ²) :
e.trans ((local_equiv.refl Ξ²).restr s) = e.restr (e β»ΒΉ' s) :=
local_equiv.ext (Ξ»x, rfl) (Ξ»x, rfl) (by simp [trans_source])
lemma trans_refl_restr' (s : set Ξ²) :
e.trans ((local_equiv.refl Ξ²).restr s) = e.restr (e.source β© e β»ΒΉ' s) :=
local_equiv.ext (Ξ»x, rfl) (Ξ»x, rfl) $ by { simp [trans_source], rw [β inter_assoc, inter_self] }
lemma restr_trans (s : set Ξ±) :
(e.restr s).trans e' = (e.trans e').restr s :=
local_equiv.ext (Ξ»x, rfl) (Ξ»x, rfl) $ by { simp [trans_source, inter_comm], rwa inter_assoc }
/-- `eq_on_source e e'` means that `e` and `e'` have the same source, and coincide there. Then `e`
and `e'` should really be considered the same local equiv. -/
def eq_on_source (e e' : local_equiv Ξ± Ξ²) : Prop :=
e.source = e'.source β§ (e.source.eq_on e e')
/-- `eq_on_source` is an equivalence relation -/
instance eq_on_source_setoid : setoid (local_equiv Ξ± Ξ²) :=
{ r := eq_on_source,
iseqv := β¨
Ξ»e, by simp [eq_on_source],
Ξ»e e' h, by { simp [eq_on_source, h.1.symm], exact Ξ»x hx, (h.2 hx).symm },
Ξ»e e' e'' h h', β¨by rwa [β h'.1, β h.1], Ξ»x hx, by { rw [β h'.2, h.2 hx], rwa β h.1 }β©β© }
lemma eq_on_source_refl : e β e := setoid.refl _
/-- Two equivalent local equivs have the same source -/
lemma eq_on_source.source_eq {e e' : local_equiv Ξ± Ξ²} (h : e β e') : e.source = e'.source :=
h.1
/-- Two equivalent local equivs coincide on the source -/
lemma eq_on_source.eq_on {e e' : local_equiv Ξ± Ξ²} (h : e β e') : e.source.eq_on e e' :=
h.2
/-- Two equivalent local equivs have the same target -/
lemma eq_on_source.target_eq {e e' : local_equiv Ξ± Ξ²} (h : e β e') : e.target = e'.target :=
by simp only [β image_source_eq_target, β h.source_eq, h.2.image_eq]
/-- If two local equivs are equivalent, so are their inverses. -/
lemma eq_on_source.symm' {e e' : local_equiv Ξ± Ξ²} (h : e β e') : e.symm β e'.symm :=
begin
refine β¨h.target_eq, eq_on_of_left_inv_on_of_right_inv_on e.left_inv_on _ _β©;
simp only [symm_source, h.target_eq, h.source_eq, e'.symm_maps_to],
exact e'.right_inv_on.congr_right e'.symm_maps_to (h.source_eq βΈ h.eq_on.symm),
end
/-- Two equivalent local equivs have coinciding inverses on the target -/
lemma eq_on_source.symm_eq_on {e e' : local_equiv Ξ± Ξ²} (h : e β e') :
eq_on e.symm e'.symm e.target :=
h.symm'.eq_on
/-- Composition of local equivs respects equivalence -/
lemma eq_on_source.trans' {e e' : local_equiv Ξ± Ξ²} {f f' : local_equiv Ξ² Ξ³}
(he : e β e') (hf : f β f') : e.trans f β e'.trans f' :=
begin
split,
{ rw [trans_source'', trans_source'', β he.target_eq, β hf.1],
exact (he.symm'.eq_on.mono $ inter_subset_left _ _).image_eq },
{ assume x hx,
rw trans_source at hx,
simp [(he.2 hx.1).symm, hf.2 hx.2] }
end
/-- Restriction of local equivs respects equivalence -/
lemma eq_on_source.restr {e e' : local_equiv Ξ± Ξ²} (he : e β e') (s : set Ξ±) :
e.restr s β e'.restr s :=
begin
split,
{ simp [he.1] },
{ assume x hx,
simp only [mem_inter_eq, restr_source] at hx,
exact he.2 hx.1 }
end
/-- Preimages are respected by equivalence -/
lemma eq_on_source.source_inter_preimage_eq {e e' : local_equiv Ξ± Ξ²} (he : e β e') (s : set Ξ²) :
e.source β© e β»ΒΉ' s = e'.source β© e' β»ΒΉ' s :=
begin
ext x,
simp only [mem_inter_eq, mem_preimage],
split,
{ assume hx,
rwa [β he.2 hx.1, β he.source_eq] },
{ assume hx,
rwa [β (setoid.symm he).2 hx.1, he.source_eq] }
end
/-- Composition of a local equiv and its inverse is equivalent to the restriction of the identity
to the source -/
lemma trans_self_symm :
e.trans e.symm β local_equiv.of_set e.source :=
begin
have A : (e.trans e.symm).source = e.source, by mfld_set_tac,
refine β¨by simp [A], Ξ»x hx, _β©,
rw A at hx,
simp only [hx] with mfld_simps
end
/-- Composition of the inverse of a local equiv and this local equiv is equivalent to the
restriction of the identity to the target -/
lemma trans_symm_self :
e.symm.trans e β local_equiv.of_set e.target :=
trans_self_symm (e.symm)
/-- Two equivalent local equivs are equal when the source and target are univ -/
lemma eq_of_eq_on_source_univ (e e' : local_equiv Ξ± Ξ²) (h : e β e')
(s : e.source = univ) (t : e.target = univ) : e = e' :=
begin
apply local_equiv.ext (Ξ»x, _) (Ξ»x, _) h.1,
{ apply h.2,
rw s,
exact mem_univ _ },
{ apply h.symm'.2,
rw [symm_source, t],
exact mem_univ _ }
end
section prod
/-- The product of two local equivs, as a local equiv on the product. -/
def prod (e : local_equiv Ξ± Ξ²) (e' : local_equiv Ξ³ Ξ΄) : local_equiv (Ξ± Γ Ξ³) (Ξ² Γ Ξ΄) :=
{ source := set.prod e.source e'.source,
target := set.prod e.target e'.target,
to_fun := Ξ»p, (e p.1, e' p.2),
inv_fun := Ξ»p, (e.symm p.1, e'.symm p.2),
map_source' := Ξ»p hp, by { simp at hp, simp [hp] },
map_target' := Ξ»p hp, by { simp at hp, simp [map_target, hp] },
left_inv' := Ξ»p hp, by { simp at hp, simp [hp] },
right_inv' := Ξ»p hp, by { simp at hp, simp [hp] } }
@[simp, mfld_simps] lemma prod_source (e : local_equiv Ξ± Ξ²) (e' : local_equiv Ξ³ Ξ΄) :
(e.prod e').source = set.prod e.source e'.source := rfl
@[simp, mfld_simps] lemma prod_target (e : local_equiv Ξ± Ξ²) (e' : local_equiv Ξ³ Ξ΄) :
(e.prod e').target = set.prod e.target e'.target := rfl
@[simp, mfld_simps] lemma prod_coe (e : local_equiv Ξ± Ξ²) (e' : local_equiv Ξ³ Ξ΄) :
((e.prod e') : Ξ± Γ Ξ³ β Ξ² Γ Ξ΄) = (Ξ»p, (e p.1, e' p.2)) := rfl
lemma prod_coe_symm (e : local_equiv Ξ± Ξ²) (e' : local_equiv Ξ³ Ξ΄) :
((e.prod e').symm : Ξ² Γ Ξ΄ β Ξ± Γ Ξ³) = (Ξ»p, (e.symm p.1, e'.symm p.2)) := rfl
@[simp, mfld_simps] lemma prod_symm (e : local_equiv Ξ± Ξ²) (e' : local_equiv Ξ³ Ξ΄) :
(e.prod e').symm = (e.symm.prod e'.symm) :=
by ext x; simp [prod_coe_symm]
@[simp, mfld_simps] lemma prod_trans {Ξ· : Type*} {Ξ΅ : Type*}
(e : local_equiv Ξ± Ξ²) (f : local_equiv Ξ² Ξ³) (e' : local_equiv Ξ΄ Ξ·) (f' : local_equiv Ξ· Ξ΅) :
(e.prod e').trans (f.prod f') = (e.trans f).prod (e'.trans f') :=
by ext x; simp [ext_iff]; tauto
end prod
end local_equiv
namespace set
-- All arguments are explicit to avoid missing information in the pretty printer output
/-- A bijection between two sets `s : set Ξ±` and `t : set Ξ²` provides a local equivalence
between `Ξ±` and `Ξ²`. -/
@[simps] noncomputable def bij_on.to_local_equiv [nonempty Ξ±] (f : Ξ± β Ξ²) (s : set Ξ±) (t : set Ξ²)
(hf : bij_on f s t) :
local_equiv Ξ± Ξ² :=
{ to_fun := f,
inv_fun := inv_fun_on f s,
source := s,
target := t,
map_source' := hf.maps_to,
map_target' := hf.surj_on.maps_to_inv_fun_on,
left_inv' := hf.inv_on_inv_fun_on.1,
right_inv' := hf.inv_on_inv_fun_on.2 }
/-- A map injective on a subset of its domain provides a local equivalence. -/
@[simp, mfld_simps] noncomputable def inj_on.to_local_equiv [nonempty Ξ±] (f : Ξ± β Ξ²) (s : set Ξ±)
(hf : inj_on f s) :
local_equiv Ξ± Ξ² :=
hf.bij_on_image.to_local_equiv f s (f '' s)
end set
namespace equiv
/- equivs give rise to local_equiv. We set up simp lemmas to reduce most properties of the local
equiv to that of the equiv. -/
variables (e : equiv Ξ± Ξ²) (e' : equiv Ξ² Ξ³)
@[simp, mfld_simps] lemma to_local_equiv_coe : (e.to_local_equiv : Ξ± β Ξ²) = e := rfl
@[simp, mfld_simps] lemma to_local_equiv_symm_coe : (e.to_local_equiv.symm : Ξ² β Ξ±) = e.symm := rfl
@[simp, mfld_simps] lemma to_local_equiv_source : e.to_local_equiv.source = univ := rfl
@[simp, mfld_simps] lemma to_local_equiv_target : e.to_local_equiv.target = univ := rfl
@[simp, mfld_simps] lemma refl_to_local_equiv : (equiv.refl Ξ±).to_local_equiv = local_equiv.refl Ξ± := rfl
@[simp, mfld_simps] lemma symm_to_local_equiv : e.symm.to_local_equiv = e.to_local_equiv.symm := rfl
@[simp, mfld_simps] lemma trans_to_local_equiv :
(e.trans e').to_local_equiv = e.to_local_equiv.trans e'.to_local_equiv :=
local_equiv.ext (Ξ»x, rfl) (Ξ»x, rfl) (by simp [local_equiv.trans_source, equiv.to_local_equiv])
end equiv
|
79cb9438d13b7a26bf6a7da3dd79909860fc19fc | be30445afb85fcb2041b437059d21f9a84dff894 | /reflexive_graphs.hlean | ec8fb8d1b90e311237b676d9c3c4e219e83badde | [
"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 | 368 | hlean | import graphmodel
namespace rgraph
structure ctx extends graph.ctx :=
( rfx : Ξ (i : pts), edg i i)
structure fam (Ξ : ctx) extends graph.fam Ξ :=
( rfx : Ξ (i : ctx.pts Ξ) (x : pts i), edg (ctx.rfx Ξ i) x x)
structure tm {Ξ : ctx} (A : fam Ξ) extends graph.tm A :=
( rfx : Ξ (i : ctx.pts Ξ), fam.edg A (ctx.rfx Ξ i) (pts i) (pts i))
end rgraph
|
3c4cb4932492375cf3279dbbab22efa93da1ea9d | 2731214ea32f2a1a985300e281fb3117640a16c3 | /portmanteau_topological_lemmas.lean | 90c057f79b2dad5bf9c9c4474306bc81f9962cd3 | [
"Apache-2.0"
] | permissive | kkytola/lean_portmanteau | 5d6a156db959974ebc4f5bed9118a7a2438a33fa | ac55eb4e24be43032cbc082e2b68d8fb8bd63f22 | refs/heads/main | 1,686,107,117,334 | 1,625,177,052,000 | 1,625,177,052,000 | 381,514,032 | 1 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 3,403 | lean | /-
Copyright (c) 2021 Kalle KytΓΆlΓ€. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kalle KytΓΆlΓ€
-/
import tactic
import measure_theory.measurable_space
import measure_theory.borel_space
noncomputable theory
open set
open measure_theory
open measurable_space
open borel_space
namespace portmanteau
section portmanteau_topological_lemmas
variables {Ξ± : Type*} [topological_space Ξ±]
lemma meas_eq_various_of_null_bdry (ΞΌ : @measure_theory.measure Ξ± (borel Ξ±)) (E : set Ξ±) :
(ΞΌ(frontier E) = 0) β (ΞΌ(interior E) = ΞΌ(E)) β§ (ΞΌ(closure E) = ΞΌ(E)) :=
begin
intro hEnullbdry ,
have ineq_E_le_Ecl := @measure_mono Ξ± (borel(Ξ±)) ΞΌ E (closure E) subset_closure ,
have ineq_Eint_le_E := @measure_mono Ξ± (borel(Ξ±)) ΞΌ (interior E) E interior_subset ,
have surpr := @measure_union_le Ξ± (borel(Ξ±)) ΞΌ (interior E) (frontier E) ,
rw β closure_eq_interior_union_frontier at surpr ,
simp [hEnullbdry] at surpr ,
have mono := @measure_mono Ξ± (borel(Ξ±)) ΞΌ (interior E) (closure E) interior_subset_closure ,
have key := le_antisymm mono surpr ,
split ,
{ apply le_antisymm ,
{ assumption , } ,
rw key ,
assumption , } ,
{ apply le_antisymm ,
{ rw β key ,
assumption , } ,
assumption , } ,
end
lemma open_imp_borel {Ξ³ : Type*} [top_Ξ³ : topological_space Ξ³]
{G : set Ξ³} : is_open G β (borel Ξ³).measurable_set' G
:= measurable_set_generate_from
lemma closed_imp_borel {Ξ³ : Type*} [top_Ξ³ : topological_space Ξ³]
{F : set Ξ³} : is_closed F β (borel Ξ³).measurable_set' F :=
begin
set G := FαΆ with hG ,
have FeqGc := compl_compl F ,
rw β hG at FeqGc ,
intro hFclosed ,
have Gmble := open_imp_borel (is_open_compl_iff.mpr hFclosed) ,
rw β FeqGc ,
exact (borel Ξ³).measurable_set_compl G Gmble ,
end
lemma compl_frontier {Ξ³ : Type*} [topological_space Ξ³] (A : set Ξ³) :
(frontier A)αΆ = (interior A) βͺ (interior (AαΆ)) :=
begin
have fact := @closure_eq_compl_interior_compl Ξ³ _ AαΆ ,
rw compl_compl at fact ,
suffices : frontier A = (interior A)αΆ β© (interior (AαΆ))αΆ ,
{ rw this ,
rw compl_inter (interior A)αΆ (interior (AαΆ))αΆ ,
repeat {rw compl_compl ,} , } ,
rw [βfrontier_compl A , βfact] ,
exact diff_eq (closure (AαΆ)) (interior (AαΆ)) ,
end
lemma interior_preimage {Ξ² Ξ³ : Type*}
[topological_space Ξ²] [topological_space Ξ³]
(G : set Ξ³) (f : Ξ² β Ξ³) (hf : continuous f) :
fβ»ΒΉ' (interior G) β interior (fβ»ΒΉ'(G)) :=
begin
apply interior_maximal ,
{ have Gint_ss_G : (interior G) β G := interior_subset ,
exact preimage_mono Gint_ss_G , } ,
{ have interior_open : is_open (interior G) := is_open_interior ,
exact continuous_def.mp hf (interior G) interior_open , } ,
end
lemma frontier_preimage {Ξ² Ξ³ : Type*}
[topological_space Ξ²] [topological_space Ξ³]
(A : set Ξ³) (f : Ξ² β Ξ³) (hf : continuous f) :
frontier (fβ»ΒΉ'(A)) β fβ»ΒΉ'(frontier A) :=
begin
apply (@compl_subset_compl Ξ² (fβ»ΒΉ'(frontier A)) (frontier (fβ»ΒΉ'(A)))).mp,
rw [compl_frontier _ , βpreimage_compl , compl_frontier _ , preimage_union ] ,
have one := @interior_preimage Ξ² Ξ³ _ _ A f hf ,
have two := @interior_preimage Ξ² Ξ³ _ _ (AαΆ) f hf ,
exact union_subset_union one two ,
end
end portmanteau_topological_lemmas
end portmanteau
|
0d3458b0517ae0c91508a6c9fa9a5d7a3e38d76c | 4d2583807a5ac6caaffd3d7a5f646d61ca85d532 | /src/data/nat/with_bot.lean | c33918ac8ada0a80bcfc8f3ef5472fa7ead1c24f | [
"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 | 2,185 | lean | /-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes
-/
import data.nat.basic
import algebra.order.group
/-!
# `with_bot β`
Lemmas about the type of natural numbers with a bottom element adjoined.
-/
namespace nat
lemma with_bot.add_eq_zero_iff : β {n m : with_bot β}, n + m = 0 β n = 0 β§ m = 0
| none m := iff_of_false dec_trivial (Ξ» h, absurd h.1 dec_trivial)
| n none := iff_of_false (by cases n; exact dec_trivial)
(Ξ» h, absurd h.2 dec_trivial)
| (some n) (some m) := show (n + m : with_bot β) = (0 : β) β (n : with_bot β) = (0 : β) β§
(m : with_bot β) = (0 : β),
by rw [β with_bot.coe_add, with_bot.coe_eq_coe, with_bot.coe_eq_coe,
with_bot.coe_eq_coe, add_eq_zero_iff' (nat.zero_le _) (nat.zero_le _)]
lemma with_bot.add_eq_one_iff : β {n m : with_bot β}, n + m = 1 β (n = 0 β§ m = 1) β¨ (n = 1 β§ m = 0)
| none none := dec_trivial
| none (some m) := dec_trivial
| (some n) none := iff_of_false dec_trivial (Ξ» h, h.elim (Ξ» h, absurd h.2 dec_trivial)
(Ξ» h, absurd h.2 dec_trivial))
| (some n) (some 0) := by erw [with_bot.coe_eq_coe, with_bot.coe_eq_coe, with_bot.coe_eq_coe,
with_bot.coe_eq_coe]; simp
| (some n) (some (m + 1)) := by erw [with_bot.coe_eq_coe, with_bot.coe_eq_coe, with_bot.coe_eq_coe,
with_bot.coe_eq_coe, with_bot.coe_eq_coe]; simp [nat.add_succ, nat.succ_inj', nat.succ_ne_zero]
@[simp] lemma with_bot.coe_nonneg {n : β} : 0 β€ (n : with_bot β) :=
by rw [β with_bot.coe_zero, with_bot.coe_le_coe]; exact nat.zero_le _
@[simp] lemma with_bot.lt_zero_iff (n : with_bot β) : n < 0 β n = β₯ :=
option.cases_on n dec_trivial (Ξ» n, iff_of_false
(by simp [with_bot.some_eq_coe]) (Ξ» h, option.no_confusion h))
lemma with_bot.one_le_iff_zero_lt {x : with_bot β} : 1 β€ x β 0 < x :=
begin
refine β¨Ξ» h, lt_of_lt_of_le (with_bot.coe_lt_coe.mpr zero_lt_one) h, Ξ» h, _β©,
induction x using with_bot.rec_bot_coe,
{ exact (not_lt_bot h).elim },
{ exact with_bot.coe_le_coe.mpr (nat.succ_le_iff.mpr (with_bot.coe_lt_coe.mp h)) }
end
end nat
|
e94c45f5aa42d0162a06c5882cad6fd1eecf038c | 1b8f093752ba748c5ca0083afef2959aaa7dace5 | /src/category_theory/universal/continuous.lean | fab59ab7c80b5552d47b8ddd68411979bc5c8b54 | [] | no_license | khoek/lean-category-theory | 7ec4cda9cc64a5a4ffeb84712ac7d020dbbba386 | 63dcb598e9270a3e8b56d1769eb4f825a177cd95 | refs/heads/master | 1,585,251,725,759 | 1,539,344,445,000 | 1,539,344,445,000 | 145,281,070 | 0 | 0 | null | 1,534,662,376,000 | 1,534,662,376,000 | null | UTF-8 | Lean | false | false | 1,442 | lean | -- Copyright (c) 2017 Scott Morrison. All rights reserved.
-- Released under Apache 2.0 license as described in the file LICENSE.
-- Authors: Scott Morrison
import category_theory.limits.limits
open category_theory.limits
namespace category_theory
universes u v
variables {C : Type u} [π : category.{u v} C] {D : Type u} [π : category.{u v} D]
section
include π π
class continuous (F : C β₯€ D) :=
(preserves_limits : β {J : Type v} [small_category J] (G : J β₯€ C) (c : cone G) (L : is_limit c), is_limit ((cones.functoriality G F) c))
class cocontinuous (F : C β₯€ D) :=
(preserves_colimits : β {J : Type v} [small_category J] (G : J β₯€ C) (c : cocone G) (L : is_colimit c), is_colimit ((cocones.functoriality G F) c))
end
section
include π
instance : continuous (functor.id C) :=
{ preserves_limits := Ξ» J π₯ G c L,
begin resetI, exact
{ lift := Ξ» s, @is_limit.lift _ _ _ _ _ c L { X := s.X, Ο := s.Ο }, -- We need to do a little work here because `G β (functor.id _) β G`.
uniq' := Ξ» s m w, @is_limit.uniq _ _ _ _ _ c L { X := s.X, Ο := s.Ο } m w, }
end }
end
-- instance HomFunctorPreservesLimits (a : A) : preserves_limits ((coyoneda A) a) := {
-- preserves := Ξ» I D q, sorry
-- }
-- instance RepresentableFunctorPreservesLimits (F : A β₯€ (Type u)) [representable F] : preserves_limits F := sorry
-- PROJECT right adjoints are continuous
end category_theory
|
853de1b0a11f3a1701b5fd7af2d16030be32a8ac | b561a44b48979a98df50ade0789a21c79ee31288 | /stage0/src/Lean/Elab/Util.lean | d3be2bbbda83e40611ce3f378a245af790caa82b | [
"Apache-2.0"
] | permissive | 3401ijk/lean4 | 97659c475ebd33a034fed515cb83a85f75ccfb06 | a5b1b8de4f4b038ff752b9e607b721f15a9a4351 | refs/heads/master | 1,693,933,007,651 | 1,636,424,845,000 | 1,636,424,845,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 7,766 | lean | /-
Copyright (c) 2019 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
import Lean.Util.Trace
import Lean.Parser.Syntax
import Lean.Parser.Extension
import Lean.KeyedDeclsAttribute
import Lean.Elab.Exception
namespace Lean
def Syntax.prettyPrint (stx : Syntax) : Format :=
match stx.unsetTrailing.reprint with -- TODO use syntax pretty printer
| some str => format str.toFormat
| none => format stx
def MacroScopesView.format (view : MacroScopesView) (mainModule : Name) : Format :=
Std.format $
if view.scopes.isEmpty then
view.name
else if view.mainModule == mainModule then
view.scopes.foldl Name.mkNum (view.name ++ view.imported)
else
view.scopes.foldl Name.mkNum (view.name ++ view.imported ++ view.mainModule)
namespace Elab
def expandOptNamedPrio (stx : Syntax) : MacroM Nat :=
if stx.isNone then
return eval_prio default
else match stx[0] with
| `(Parser.Command.namedPrio| (priority := $prio)) => evalPrio prio
| _ => Macro.throwUnsupported
structure MacroStackElem where
before : Syntax
after : Syntax
abbrev MacroStack := List MacroStackElem
/- If `ref` does not have position information, then try to use macroStack -/
def getBetterRef (ref : Syntax) (macroStack : MacroStack) : Syntax :=
match ref.getPos? with
| some _ => ref
| none =>
match macroStack.find? (Β·.before.getPos? != none) with
| some elem => elem.before
| none => ref
register_builtin_option pp.macroStack : Bool := {
defValue := false
group := "pp"
descr := "dispaly macro expansion stack"
}
def addMacroStack {m} [Monad m] [MonadOptions m] (msgData : MessageData) (macroStack : MacroStack) : m MessageData := do
if !pp.macroStack.get (β getOptions) then pure msgData else
match macroStack with
| [] => pure msgData
| stack@(top::_) =>
let msgData := msgData ++ Format.line ++ "with resulting expansion" ++ indentD top.after
pure $ stack.foldl
(fun (msgData : MessageData) (elem : MacroStackElem) =>
msgData ++ Format.line ++ "while expanding" ++ indentD elem.before)
msgData
def checkSyntaxNodeKind [Monad m] [MonadEnv m] [MonadError m] (k : Name) : m Name := do
if Parser.isValidSyntaxNodeKind (β getEnv) k then pure k
else throwError "failed"
def checkSyntaxNodeKindAtNamespaces [Monad m] [MonadEnv m] [MonadError m] (k : Name) : Name β m Name
| n@(Name.str p _ _) => checkSyntaxNodeKind (n ++ k) <|> checkSyntaxNodeKindAtNamespaces k p
| Name.anonymous => checkSyntaxNodeKind k
| _ => throwError "failed"
def checkSyntaxNodeKindAtCurrentNamespaces (k : Name) : AttrM Name := do
let ctx β read
checkSyntaxNodeKindAtNamespaces k ctx.currNamespace
def syntaxNodeKindOfAttrParam (defaultParserNamespace : Name) (stx : Syntax) : AttrM SyntaxNodeKind := do
let k β Attribute.Builtin.getId stx
checkSyntaxNodeKindAtCurrentNamespaces k
<|>
checkSyntaxNodeKind (defaultParserNamespace ++ k)
<|>
throwError "invalid syntax node kind '{k}'"
private unsafe def evalSyntaxConstantUnsafe (env : Environment) (opts : Options) (constName : Name) : ExceptT String Id Syntax :=
env.evalConstCheck Syntax opts `Lean.Syntax constName
@[implementedBy evalSyntaxConstantUnsafe]
constant evalSyntaxConstant (env : Environment) (opts : Options) (constName : Name) : ExceptT String Id Syntax := throw ""
unsafe def mkElabAttribute (Ξ³) (attrDeclName attrBuiltinName attrName : Name) (parserNamespace : Name) (typeName : Name) (kind : String)
: IO (KeyedDeclsAttribute Ξ³) :=
KeyedDeclsAttribute.init {
builtinName := attrBuiltinName
name := attrName
descr := kind ++ " elaborator"
valueTypeName := typeName
evalKey := fun _ stx => syntaxNodeKindOfAttrParam parserNamespace stx
} attrDeclName
unsafe def mkMacroAttributeUnsafe : IO (KeyedDeclsAttribute Macro) :=
mkElabAttribute Macro `Lean.Elab.macroAttribute `builtinMacro `macro Name.anonymous `Lean.Macro "macro"
@[implementedBy mkMacroAttributeUnsafe]
constant mkMacroAttribute : IO (KeyedDeclsAttribute Macro)
builtin_initialize macroAttribute : KeyedDeclsAttribute Macro β mkMacroAttribute
/--
Try to expand macro at syntax tree root and return macro declaration name and new syntax if successful.
Return none if all macros threw `Macro.Exception.unsupportedSyntax`.
-/
def expandMacroImpl? (env : Environment) : Syntax β MacroM (Option (Name Γ Syntax)) := fun stx => do
for e in macroAttribute.getEntries env stx.getKind do
try
let stx' β withFreshMacroScope (e.value stx)
return (e.declName, stx')
catch
| Macro.Exception.unsupportedSyntax => pure ()
| ex => throw ex
return none
class MonadMacroAdapter (m : Type β Type) where
getCurrMacroScope : m MacroScope
getNextMacroScope : m MacroScope
setNextMacroScope : MacroScope β m Unit
instance (m n) [MonadLift m n] [MonadMacroAdapter m] : MonadMacroAdapter n := {
getCurrMacroScope := liftM (MonadMacroAdapter.getCurrMacroScope : m _),
getNextMacroScope := liftM (MonadMacroAdapter.getNextMacroScope : m _),
setNextMacroScope := fun s => liftM (MonadMacroAdapter.setNextMacroScope s : m _)
}
def liftMacroM {Ξ±} {m : Type β Type} [Monad m] [MonadMacroAdapter m] [MonadEnv m] [MonadRecDepth m] [MonadError m] [MonadResolveName m] [MonadTrace m] [MonadOptions m] [AddMessageContext m] (x : MacroM Ξ±) : m Ξ± := do
let env β getEnv
let currNamespace β getCurrNamespace
let openDecls β getOpenDecls
let methods := Macro.mkMethods {
-- TODO: record recursive expansions in info tree?
expandMacro? := fun stx => do
match (β expandMacroImpl? env stx) with
| some (_, stx) => some stx
| none => none
hasDecl := fun declName => return env.contains declName
getCurrNamespace := return currNamespace
resolveNamespace? := fun n => return ResolveName.resolveNamespace? env currNamespace openDecls n
resolveGlobalName := fun n => return ResolveName.resolveGlobalName env currNamespace openDecls n
}
match x { methods := methods
ref := β getRef
currMacroScope := β MonadMacroAdapter.getCurrMacroScope
mainModule := env.mainModule
currRecDepth := β MonadRecDepth.getRecDepth
maxRecDepth := β MonadRecDepth.getMaxRecDepth
} { macroScope := (β MonadMacroAdapter.getNextMacroScope) } with
| EStateM.Result.error Macro.Exception.unsupportedSyntax _ => throwUnsupportedSyntax
| EStateM.Result.error (Macro.Exception.error ref msg) _ => throwErrorAt ref msg
| EStateM.Result.ok a s =>
MonadMacroAdapter.setNextMacroScope s.macroScope
s.traceMsgs.reverse.forM fun (clsName, msg) => trace clsName fun _ => msg
pure a
@[inline] def adaptMacro {m : Type β Type} [Monad m] [MonadMacroAdapter m] [MonadEnv m] [MonadRecDepth m] [MonadError m] [MonadResolveName m] [MonadTrace m] [MonadOptions m] [AddMessageContext m] (x : Macro) (stx : Syntax) : m Syntax :=
liftMacroM (x stx)
partial def mkUnusedBaseName (baseName : Name) : MacroM Name := do
let currNamespace β Macro.getCurrNamespace
if β Macro.hasDecl (currNamespace ++ baseName) then
let rec loop (idx : Nat) := do
let name := baseName.appendIndexAfter idx
if β Macro.hasDecl (currNamespace ++ name) then
loop (idx+1)
else
name
loop 1
else
return baseName
builtin_initialize
registerTraceClass `Elab
registerTraceClass `Elab.step
end Lean.Elab
|
6ab75c0e62b771b22ec06196f222c8500a91a125 | e151e9053bfd6d71740066474fc500a087837323 | /src/hott/types/prod.lean | 10e11e876c74181f0862f7cdde92586542b8878f | [
"Apache-2.0"
] | permissive | daniel-carranza/hott3 | 15bac2d90589dbb952ef15e74b2837722491963d | 913811e8a1371d3a5751d7d32ff9dec8aa6815d9 | refs/heads/master | 1,610,091,349,670 | 1,596,222,336,000 | 1,596,222,336,000 | 241,957,822 | 0 | 0 | Apache-2.0 | 1,582,222,839,000 | 1,582,222,838,000 | null | UTF-8 | Lean | false | false | 12,647 | 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, Jakob von Raumer
Ported from Coq HoTT
Theorems about products
-/
import ..init
universes u v w
hott_theory
namespace hott
open hott.eq hott.equiv hott.is_equiv hott.is_trunc prod unit
variables {A : Type _}
{A': Type _}
{B : Type _}
{B' : Type _}
{C : Type _}
{D : Type _}
{P : A β Type _} {Q : A β Type _}
{a a' a'' : A} {b bβ bβ b' b'' : B} {u v w : A Γ B}
namespace prod
/- Paths in a product space -/
@[hott] protected def eta (u : A Γ B) : (fst u, snd u) = u :=
by cases u; reflexivity
@[hott] def pair_eq (pa : a = a') (pb : b = b') : (a, b) = (a', b') :=
ap011 prod.mk pa pb
@[hott] def prod_eq (Hβ : u.1 = v.1) (Hβ : u.2 = v.2) : u = v :=
by cases u; cases v; exact pair_eq Hβ Hβ
@[hott] def eq_fst (p : u = v) : u.1 = v.1 :=
ap fst p
@[hott] def eq_snd (p : u = v) : u.2 = v.2 :=
ap snd p
postfix `..1`:(max+1) := eq_fst
postfix `..2`:(max+1) := eq_snd
@[hott] protected def ap_fst (p : u = v) : ap fst p = p..1 := idp
@[hott] protected def ap_snd (p : u = v) : ap snd p = p..2 := idp
@[hott] def pair_prod_eq (p : u.1 = v.1) (q : u.2 = v.2)
: ((prod_eq p q)..1, (prod_eq p q)..2) = (p, q) :=
by induction u; induction v; dsimp at *; induction p; induction q; reflexivity
@[hott] def prod_eq_fst (p : u.1 = v.1) (q : u.2 = v.2) : (prod_eq p q)..1 = p :=
(pair_prod_eq p q)..1
@[hott] def prod_eq_snd (p : u.1 = v.1) (q : u.2 = v.2) : (prod_eq p q)..2 = q :=
(pair_prod_eq p q)..2
@[hott] def prod_eq_eta (p : u = v) : prod_eq (p..1) (p..2) = p :=
by induction p; induction u; reflexivity
-- the uncurried version of prod_eq. We will prove that this is an equivalence
@[hott] def prod_eq_unc (H : u.1 = v.1 Γ u.2 = v.2) : u = v :=
by cases H with Hβ Hβ; exact prod_eq Hβ Hβ
@[hott] def pair_prod_eq_unc : Ξ (pq : u.1 = v.1 Γ u.2 = v.2),
((prod_eq_unc pq)..1, (prod_eq_unc pq)..2) = pq
| (pqβ, pqβ) := pair_prod_eq pqβ pqβ
@[hott] def prod_eq_unc_fst (pq : u.1 = v.1 Γ u.2 = v.2) : (prod_eq_unc pq)..1 = pq.1 :=
(pair_prod_eq_unc pq)..1
@[hott] def prod_eq_unc_snd (pq : u.1 = v.1 Γ u.2 = v.2) : (prod_eq_unc pq)..2 = pq.2 :=
(pair_prod_eq_unc pq)..2
@[hott] def prod_eq_unc_eta (p : u = v) : prod_eq_unc (p..1, p..2) = p :=
prod_eq_eta p
@[hott, instance] def is_equiv_prod_eq (u v : A Γ B)
: is_equiv (prod_eq_unc : u.1 = v.1 Γ u.2 = v.2 β u = v) :=
adjointify prod_eq_unc
(Ξ»p, (p..1, p..2))
prod_eq_unc_eta
pair_prod_eq_unc
@[hott] def prod_eq_equiv (u v : A Γ B) : (u = v) β (u.1 = v.1 Γ u.2 = v.2) :=
(equiv.mk prod_eq_unc (by apply_instance))β»ΒΉα΅
@[hott] def pair_eq_pair_equiv (a a' : A) (b b' : B) :
((a, b) = (a', b')) β (a = a' Γ b = b') :=
prod_eq_equiv (a, b) (a', b')
@[hott] def ap_prod_mk_left (p : a = a') : ap (Ξ»a, prod.mk a b) p = prod_eq p idp :=
ap_eq_ap011_left prod.mk p b
@[hott] def ap_prod_mk_right (p : b = b') : ap (Ξ»b, prod.mk a b) p = prod_eq idp p :=
ap_eq_ap011_right prod.mk a p
@[hott] def pair_eq_eta {A B : Type _} {u v : A Γ B}
(p : u = v) : pair_eq (p..1) (p..2) = prod.eta u β¬ p β¬ (prod.eta v)β»ΒΉ :=
by induction p; induction u; reflexivity
@[hott] def prod_eq_eq {A B : Type _} {u v : A Γ B}
{pβ qβ : u.1 = v.1} {pβ qβ : u.2 = v.2} (Ξ±β : pβ = qβ) (Ξ±β : pβ = qβ)
: prod_eq pβ pβ = prod_eq qβ qβ :=
by induction Ξ±β; induction Ξ±β; reflexivity
@[hott] def prod_eq_assemble {A B : Type _} {u v : A Γ B}
{p q : u = v} (Ξ±β : p..1 = q..1) (Ξ±β : p..2 = q..2) : p = q :=
(prod_eq_eta p)β»ΒΉ β¬ prod.prod_eq_eq Ξ±β Ξ±β β¬ prod_eq_eta q
@[hott] def eq_fst_concat {A B : Type _} {u v w : A Γ B}
(p : u = v) (q : v = w)
: (p β¬ q)..1 = p..1 β¬ q..1 :=
by induction q; reflexivity
@[hott] def eq_snd_concat {A B : Type _} {u v w : A Γ B}
(p : u = v) (q : v = w)
: (p β¬ q)..2 = p..2 β¬ q..2 :=
by induction q; reflexivity
/- Groupoid structure -/
@[hott] def prod_eq_inv (p : a = a') (q : b = b') :
(@prod_eq _ _ (a,b) (a',b') p q)β»ΒΉ = prod_eq pβ»ΒΉ qβ»ΒΉ :=
by induction p; induction q; reflexivity
@[hott] def prod_eq_concat (p : a = a') (p' : a' = a'') (q : b = b') (q' : b' = b'')
: @prod_eq _ _ (a,b) (a',b') p q β¬ @prod_eq _ _ (a',b') (a'',b'') p' q' = prod_eq (p β¬ p') (q β¬ q') :=
by induction p; induction q; induction p'; induction q'; reflexivity
@[hott] def prod_eq_concat_idp (p : a = a') (q : b = b')
: @prod_eq _ _ (a,b) (a',b) p idp β¬ @prod_eq _ _ (a',b) (a',b') idp q = prod_eq p q :=
by induction p; induction q; reflexivity
/- Transport -/
@[hott] def prod_transport (p : a = a') (u : P a Γ Q a)
: p βΈ u = (p βΈ u.1, p βΈ u.2) :=
by induction p; induction u; reflexivity
@[hott] def prod_eq_transport (p : a = a') (q : b = b') {R : A Γ B β Type _} (r : R (a, b))
: @prod_eq _ _ (a,b) (a',b') p q βΈ r = p βΈ (q βΈ r) :=
by induction p; induction q; reflexivity
/- Pathovers -/
@[hott] def etao (p : a = a') (bc : P a Γ Q a) : bc =[p; Ξ» a, P a Γ Q a] (p βΈ bc.1, p βΈ bc.2) :=
by induction p; induction bc; apply idpo
@[hott] def prod_pathover (p : a = a') (u : P a Γ Q a) (v : P a' Γ Q a')
(r : u.1 =[p] v.1) (s : u.2 =[p] v.2) : u =[p; Ξ» a, P a Γ Q a] v :=
begin
induction u, induction v, dsimp at *, induction r,
refine idp_rec_on s _,
apply idpo
end
@[hott] def prod_pathover_equiv {A : Type _} {B C : A β Type _} {a a' : A} (p : a = a')
(x : B a Γ C a) (x' : B a' Γ C a') : x =[p; Ξ» a, B a Γ C a] x' β x.1 =[p] x'.1 Γ x.2 =[p] x'.2 :=
begin
fapply equiv.MK,
{ intro q, induction q, constructor; constructor },
{ intro v, induction v with q r, exact prod_pathover _ _ _ q r },
{ intro v, induction v with q r, induction x with b c, induction x' with b' c',
dsimp at *, induction q, refine idp_rec_on r _, reflexivity },
{ intro q, induction q, induction x with b c, reflexivity }
end
/-
TODO:
* define the projections from the type u =[p] v
* show that the uncurried version of prod_pathover is an equivalence
-/
/- Functorial action -/
variables (f : A β A') (g : B β B')
@[hott] def prod_functor (u : A Γ B) : A' Γ B' :=
(f u.1, g u.2)
@[hott] def ap_prod_functor (p : u.1 = v.1) (q : u.2 = v.2)
: ap (prod_functor f g) (prod_eq p q) = prod_eq (ap f p) (ap g q) :=
by induction u; induction v; dsimp at *; induction p; induction q; reflexivity
/- Helpers for functions of two arguments -/
@[hott] def ap_diagonal {a a' : A} (p : a = a')
: ap (Ξ»x : A, (x,x)) p = prod_eq p p :=
by induction p; constructor
@[hott] def ap_binary (m : A β B β C) (p : a = a') (q : b = b')
: ap (Ξ»z : A Γ B, m z.1 z.2) (@prod_eq _ _ (a,b) (a',b') p q)
= ap (m a) q β¬ ap (Ξ»x : A, m x b') p :=
by induction p; induction q; constructor
@[hott] def ap_prod_elim {A B C : Type _} {a a' : A} {b b' : B} (m : A β B β C)
(p : a = a') (q : b = b') : @ap (A Γ B) C (Ξ» ab, prod.rec m ab) (a,b) (a',b') (prod_eq p q)
= ap (m a) q β¬ ap (Ξ»x : A, m x b') p :=
by induction p; induction q; constructor
@[hott] def ap_prod_elim_idp {A B C : Type _} {a a' : A} (m : A β B β C)
(p : a = a') (b : B) : @ap (A Γ B) C (Ξ» ab, prod.rec m ab) (a,b) (a',b) (prod_eq p idp) = ap (Ξ»x : A, m x b) p :=
ap_prod_elim m p idp β¬ idp_con _
/- Equivalences -/
@[hott, instance] def is_equiv_prod_functor [H : is_equiv f] [H : is_equiv g]
: is_equiv (prod_functor f g) :=
begin
apply adjointify _ (prod_functor fβ»ΒΉαΆ gβ»ΒΉαΆ );
intro u; induction u; dsimp [prod_functor],
{rwr [right_inv f, right_inv g]},
{rwr [left_inv f, left_inv g]},
end
@[hott] def prod_equiv_prod_of_is_equiv [H : is_equiv f] [H : is_equiv g]
: A Γ B β A' Γ B' :=
equiv.mk (prod_functor f g) (by apply_instance)
@[hott] def prod_equiv_prod (f : A β A') (g : B β B') : A Γ B β A' Γ B' :=
equiv.mk (prod_functor f g) (by apply_instance)
-- rename
@[hott] def prod_equiv_prod_left (g : B β B') : A Γ B β A Γ B' :=
prod_equiv_prod equiv.rfl g
-- rename
@[hott] def prod_equiv_prod_right (f : A β A') : A Γ B β A' Γ B :=
prod_equiv_prod f equiv.rfl
/- Symmetry -/
@[hott, instance] def is_equiv_flip (A B : Type _)
: is_equiv (flip : A Γ B β B Γ A) :=
adjointify flip flip (Ξ» β¨b,aβ©, idp) (Ξ» β¨a,bβ©, idp)
@[hott] def prod_comm_equiv (A B : Type _) : A Γ B β B Γ A :=
equiv.mk flip (by apply_instance)
/- Associativity -/
@[hott] def prod_assoc_equiv (A B C : Type _) : A Γ (B Γ C) β (A Γ B) Γ C :=
begin
fapply equiv.MK,
{ intro z, induction z with a z, induction z with b c, exact β¨β¨a, bβ©, cβ©},
{ intro z, induction z with z c, induction z with a b, exact β¨a, β¨b, cβ©β©},
{ intro z, induction z with z c, induction z with a b, reflexivity},
{ intro z, induction z with a z, induction z with b c, reflexivity},
end
@[hott] def prod_contr_equiv (A : Type u) (B : Type v) [H : is_contr B] : A Γ B β A :=
equiv.MK fst
(Ξ»x, (x, by apply center))
(Ξ»x, idp)
(Ξ» β¨a,bβ©, pair_eq idp (center_eq _))
@[hott] def prod_unit_equiv (A : Type _) : A Γ unit β A :=
by apply prod_contr_equiv
@[hott] def prod_empty_equiv (A : Type _) : A Γ empty β empty :=
begin
fapply equiv.MK,
{ intro x, cases x with a e, cases e },
{ intro e, cases e },
{ intro e, cases e },
{ intro x, cases x with a e, cases e }
end
/- Universal mapping properties -/
@[hott, instance] def is_equiv_prod_rec (P : A Γ B β Type _)
: is_equiv (prod.rec : (Ξ a b, P (a, b)) β Ξ u, P u) :=
adjointify _
(Ξ»g a b, g (a, b))
(Ξ»g, eq_of_homotopy (Ξ»u, by induction u;reflexivity))
(Ξ»f, idp)
@[hott] def equiv_prod_rec (P : A Γ B β Type _) : (Ξ a b, P (a, b)) β (Ξ u, P u) :=
equiv.mk prod.rec (by apply_instance)
@[hott] def imp_imp_equiv_prod_imp (A B C : Type _) : (A β B β C) β (A Γ B β C) :=
equiv_prod_rec (Ξ» _, C)
@[hott] def prod_corec_unc {P Q : A β Type _} (u : (Ξ a, P a) Γ (Ξ a, Q a)) (a : A)
: P a Γ Q a :=
(u.1 a, u.2 a)
@[hott] def is_equiv_prod_corec (P Q : A β Type _)
: is_equiv (prod_corec_unc : (Ξ a, P a) Γ (Ξ a, Q a) β Ξ a, P a Γ Q a) :=
adjointify _
(Ξ»g, (Ξ»a, (g a).1, Ξ»a, (g a).2))
(by intro g; apply eq_of_homotopy; intro a; dsimp [prod_corec_unc]; induction g a; reflexivity)
(by intro h; induction h with f g; reflexivity)
@[hott] def equiv_prod_corec (P Q : A β Type _)
: ((Ξ a, P a) Γ (Ξ a, Q a)) β (Ξ a, P a Γ Q a) :=
equiv.mk _ (by apply is_equiv_prod_corec)
@[hott] def imp_prod_imp_equiv_imp_prod (A B C : Type _)
: (A β B) Γ (A β C) β (A β (B Γ C)) :=
by apply equiv_prod_corec
@[hott] def is_trunc_prod (A B : Type _) (n : trunc_index) [HA : is_trunc n A] [HB : is_trunc n B]
: is_trunc n (A Γ B) :=
begin
unfreezeI, induction n with n IH generalizing A B HA HB; resetI,
{ fapply is_contr.mk,
constructor; apply center,
intro u, apply prod_eq; apply center_eq},
{ apply @is_trunc_succ_intro _ _ _, intros u v,
apply @is_trunc_equiv_closed_rev (u=v) ((u.fst = v.fst) Γ (u.snd = v.snd)) _ _ _,
apply prod_eq_equiv,
exact @IH _ _ _ _}
end
end prod
attribute [instance] prod.is_trunc_prod
namespace prod
/- pointed products -/
open pointed
@[hott, instance] def pointed_prod (A B : Type _) [H1 : pointed A] [H2 : pointed B]
: pointed (A Γ B) :=
pointed.mk (pt,pt)
@[hott] def pprod (A B : Type*) : Type* :=
pointed.mk' (A Γ B)
infixr ` Γ* `:35 := pprod
@[hott] def pfst {A B : Type*} : A Γ* B β* A :=
pmap.mk fst idp
@[hott] def psnd {A B : Type*} : A Γ* B β* B :=
pmap.mk snd idp
@[hott] def tprod {n : trunc_index} (A B : n-Type) : n-Type :=
trunctype.mk (A Γ B) (by apply_instance)
infixr `Γt`:30 := tprod
@[hott] def ptprod {n : βββ} (A B : n-Type*) : n-Type* :=
ptrunctype.mk' n (A Γ B)
@[hott] def pprod_functor {A B C D : Type*} (f : A β* C) (g : B β* D) : A Γ* B β* C Γ* D :=
pmap.mk (prod_functor f g) (prod_eq (respect_pt f) (respect_pt g))
end prod
end hott |
00c5ea60a09b94318da0444e5094de511c47f410 | 60bf3fa4185ec5075eaea4384181bfbc7e1dc319 | /src/game/order/level09.lean | 2d46e6587003afe6062c03f230688cab3db051ad | [
"Apache-2.0"
] | permissive | anrddh/real-number-game | 660f1127d03a78fd35986c771d65c3132c5f4025 | c708c4e02ec306c657e1ea67862177490db041b0 | refs/heads/master | 1,668,214,277,092 | 1,593,105,075,000 | 1,593,105,075,000 | 264,269,218 | 0 | 0 | null | 1,589,567,264,000 | 1,589,567,264,000 | null | UTF-8 | Lean | false | false | 2,803 | lean | import data.real.basic
open real
namespace xena -- hide
/-
# Chapter 2 : Order
## Level 9
This level invites you to work out a property of the absolute value.
In Lean the absolute value of $x$ is denoted by `abs x`.
For ease of use, a notation can be used around that definition as below.
Feel free to use the triangle inequality on the real numbers,
`abs_add : β (a b : ?M_1), |a + b| β€ |a| + |b|`
together with the `linarith` and `norm_num` tactics.
-/
notation `|` x `|` := abs x
-- begin hide
-- this to go in the side bar
lemma eq_sqr_to_eq (a b : β) (ha : 0 β€ a) (hb : 0 β€ b) : a^2 = b^2 β a = b :=
begin
intro H,
have A : sqrt (a ^ 2) = sqrt (a ^ 2), refl,
rw H at A {occs := occurrences.pos [2]},
have G := sqrt_sqr ha, rw G at A,
have F := sqrt_sqr hb, rw F at A,
exact A, done
end
-- end hide
/- Lemma
For any two real numbers $a$ and $b$, we have that
$$|a + b| = |a| + |b|$$ if and only if $ab \ge 0$ .
-/
theorem abs_sub_eq_sum_abs (a b : β) : |a + b| = |a| + |b| β a * b β₯ 0 :=
begin
have H0 : (a+b)^2 = |a+b|^2,
have h01 := abs_mul_abs_self (a+b),
rw pow_two _, rw pow_two _, symmetry, exact h01,
have H1 : 0 β€ (a + b) ^ 2, exact pow_two_nonneg (a+b),
have H2 : (a+b) ^ 2 = a ^2 + 2 * a * b + b^2, ring,
have H3 : ( |a| + |b| )^2 = |a|^2 + 2*|a|*|b| + |b|^2, ring,
rw H0 at H2,
have Ha : a^2 = |a|^2,
have h01 := abs_mul_abs_self a,
rw pow_two _, rw pow_two _, symmetry, exact h01,
have Hb : b^2 = |b|^2,
have h01 := abs_mul_abs_self b,
rw pow_two _, rw pow_two _, symmetry, exact h01,
rw [Ha, Hb] at H2,
split,
intro h,
rw h at H2, rw H3 at H2, simp at H2,
rw mul_assoc at H2, rw mul_assoc at H2,
have g1 : ( |a| * |b| ) = (a * b), linarith,
have g2 : |a * b| = ( |a| * |b| ), exact abs_mul _ _,
rw β g2 at g1,
by_contradiction hn, push_neg at hn,
have g3 : | a * b | = - (a *b), exact abs_of_neg hn,
rw g1 at g3, linarith,
-- the right-left direction
intro h,
have g1 : |a * b| = a * b, exact abs_of_nonneg h,
have g2 : |a * b| = ( |a| * |b| ), exact abs_mul _ _,
rw g2 at g1, rw mul_assoc 2 a b at H2,
rw β g1 at H2,
have g3 : |a| ^ 2 + 2 * ( |a| * |b| ) + |b| ^ 2 = ( |a| + |b| )^2, ring,
rw g3 at H2,
have g4 : sqrt ( |a + b| ^ 2 ) = sqrt ( |a + b| ^ 2), refl,
rw H2 at g4 {occs := occurrences.pos [2]},
have hab : 0 β€ |a + b|, exact is_absolute_value.abv_nonneg abs (a+b),
have ha : 0 β€ |a|, exact is_absolute_value.abv_nonneg abs a,
have hb : 0 β€ |b|, exact is_absolute_value.abv_nonneg abs b,
have hc : 0 β€ |a| + |b|, linarith,
have G := eq_sqr_to_eq ( |a + b| ) ( |a| + |b| ) hab hc H2, exact G, done
end
end xena -- hide
|
79f7108f8ad50c2dd377c2223121c5e0de12798c | 4727251e0cd73359b15b664c3170e5d754078599 | /src/combinatorics/simple_graph/matching.lean | 7fc17adc471d2b25269f4ed096552eb0125406cf | [
"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 | 4,592 | lean | /-
Copyright (c) 2020 Alena Gusakov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Alena Gusakov, Arthur Paulino, Kyle Miller
-/
import combinatorics.simple_graph.degree_sum
import combinatorics.simple_graph.subgraph
/-!
# Matchings
A *matching* for a simple graph is a set of disjoint pairs of adjacent vertices, and the set of all
the vertices in a matching is called its *support* (and sometimes the vertices in the support are
said to be *saturated* by the matching). A *perfect matching* is a matching whose support contains
every vertex of the graph.
In this module, we represent a matching as a subgraph whose vertices are each incident to at most
one edge, and the edges of the subgraph represent the paired vertices.
## Main definitions
* `simple_graph.subgraph.is_matching`: `M.is_matching` means that `M` is a matching of its
underlying graph.
denoted `M.is_matching`.
* `simple_graph.subgraph.is_perfect_matching` defines when a subgraph `M` of a simple graph is a
perfect matching, denoted `M.is_perfect_matching`.
## TODO
* Define an `other` function and prove useful results about it (https://leanprover.zulipchat.com/#narrow/stream/252551-graph-theory/topic/matchings/near/266205863)
* Provide a bicoloring for matchings (https://leanprover.zulipchat.com/#narrow/stream/252551-graph-theory/topic/matchings/near/265495120)
* Tutte's Theorem
* Hall's Marriage Theorem (see combinatorics.hall)
-/
universe u
namespace simple_graph
variables {V : Type u} {G : simple_graph V} (M : subgraph G)
namespace subgraph
/--
The subgraph `M` of `G` is a matching if every vertex of `M` is incident to exactly one edge in `M`.
We say that the vertices in `M.support` are *matched* or *saturated*.
-/
def is_matching : Prop := β β¦vβ¦, v β M.verts β β! w, M.adj v w
/-- Given a vertex, returns the unique edge of the matching it is incident to. -/
noncomputable def is_matching.to_edge {M : subgraph G} (h : M.is_matching)
(v : M.verts) : M.edge_set :=
β¨β¦(v, (h v.property).some)β§, (h v.property).some_spec.1β©
lemma is_matching.to_edge_eq_of_adj {M : subgraph G} (h : M.is_matching) {v w : V}
(hv : v β M.verts) (hvw : M.adj v w) : h.to_edge β¨v, hvβ© = β¨β¦(v, w)β§, hvwβ© :=
begin
simp only [is_matching.to_edge, subtype.mk_eq_mk],
congr,
exact ((h (M.edge_vert hvw)).some_spec.2 w hvw).symm,
end
lemma is_matching.to_edge.surjective {M : subgraph G} (h : M.is_matching) :
function.surjective h.to_edge :=
begin
rintro β¨e, heβ©,
refine sym2.ind (Ξ» x y he, _) e he,
exact β¨β¨x, M.edge_vert heβ©, h.to_edge_eq_of_adj _ heβ©,
end
lemma is_matching.to_edge_eq_to_edge_of_adj {M : subgraph G} {v w : V}
(h : M.is_matching) (hv : v β M.verts) (hw : w β M.verts) (ha : M.adj v w) :
h.to_edge β¨v, hvβ© = h.to_edge β¨w, hwβ© :=
by rw [h.to_edge_eq_of_adj hv ha, h.to_edge_eq_of_adj hw (M.symm ha),
subtype.mk_eq_mk, sym2.eq_swap]
/--
The subgraph `M` of `G` is a perfect matching on `G` if it's a matching and every vertex `G` is
matched.
-/
def is_perfect_matching : Prop := M.is_matching β§ M.is_spanning
lemma is_matching.support_eq_verts {M : subgraph G} (h : M.is_matching) : M.support = M.verts :=
begin
refine M.support_subset_verts.antisymm (Ξ» v hv, _),
obtain β¨w, hvw, -β© := h hv,
exact β¨_, hvwβ©,
end
lemma is_matching_iff_forall_degree {M : subgraph G} [Ξ (v : V), fintype (M.neighbor_set v)] :
M.is_matching β β (v : V), v β M.verts β M.degree v = 1 :=
by simpa [degree_eq_one_iff_unique_adj]
lemma is_matching.even_card {M : subgraph G} [fintype M.verts] (h : M.is_matching) :
even M.verts.to_finset.card :=
begin
classical,
rw is_matching_iff_forall_degree at h,
use M.coe.edge_finset.card,
rw [β two_mul, β M.coe.sum_degrees_eq_twice_card_edges],
simp [h, finset.card_univ],
end
lemma is_perfect_matching_iff : M.is_perfect_matching β β v, β! w, M.adj v w :=
begin
refine β¨_, Ξ» hm, β¨Ξ» v hv, hm v, Ξ» v, _β©β©,
{ rintro β¨hm, hsβ© v,
exact hm (hs v) },
{ obtain β¨w, hw, -β© := hm v,
exact M.edge_vert hw }
end
lemma is_perfect_matching_iff_forall_degree {M : subgraph G} [Ξ v, fintype (M.neighbor_set v)] :
M.is_perfect_matching β β v, M.degree v = 1 :=
by simp [degree_eq_one_iff_unique_adj, is_perfect_matching_iff]
lemma is_perfect_matching.even_card {M : subgraph G} [fintype V] (h : M.is_perfect_matching) :
even (fintype.card V) :=
by { classical, simpa [h.2.card_verts] using is_matching.even_card h.1 }
end subgraph
end simple_graph
|
9680778bf43ed5f159c1675092696542e69b960f | 7a76361040c55ae1eba5856c1a637593117a6556 | /src/lovelib.lean | 241a3e4cf21add516f1a16497165953364a49522 | [] | 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 | 6,942 | lean | import algebra
import data.real.basic
import data.vector
import tactic.explode
import tactic.find
import tactic.induction
import tactic.linarith
import tactic.rcases
import tactic.rewrite
import tactic.ring_exp
import tactic.tidy
import tactic.where
/-! # LoVe Library
This files contains a few extensions on top of Lean's core libraries and
`mathlib`. -/
namespace LoVe
/-! ## Structured Proofs -/
notation `fix ` binders `, ` r:(scoped f, f) := r
/-! ## Logical Connectives -/
meta def tactic.dec_trivial := `[exact dec_trivial]
lemma not_def (a : Prop) :
Β¬ a β a β false :=
by refl
@[simp] lemma not_not_iff (a : Prop) [decidable a] :
¬¬ a β a :=
by by_cases a; simp [h]
@[simp] lemma and_imp_distrib (a b c : Prop) :
(a β§ b β c) β (a β b β c) :=
iff.intro
(assume h ha hb, h β¨ha, hbβ©)
(assume h β¨ha, hbβ©, h ha hb)
@[simp] lemma or_imp_distrib {a b c : Prop} :
a β¨ b β c β (a β c) β§ (b β c) :=
iff.intro
(assume h,
β¨assume ha, h (or.intro_left _ ha), assume hb, h (or.intro_right _ hb)β©)
(assume β¨ha, hbβ© h, match h with or.inl h := ha h | or.inr h := hb h end)
@[simp] lemma exists_imp_distrib {Ξ± : Sort*} {p : Ξ± β Prop} {a : Prop} :
((βx, p x) β a) β (βx, p x β a) :=
iff.intro
(assume h hp ha, h β¨hp, haβ©)
(assume h β¨hp, haβ©, h hp ha)
lemma and_exists {Ξ± : Sort*} {p : Ξ± β Prop} {a : Prop} :
(a β§ (βx, p x)) β (βx, a β§ p x) :=
iff.intro
(assume β¨ha, x, hpβ©, β¨x, ha, hpβ©)
(assume β¨x, ha, hpβ©, β¨ha, x, hpβ©)
@[simp] lemma exists_false {Ξ± : Sort*} :
(βx : Ξ±, false) β false :=
iff.intro (assume β¨a, fβ©, f) (assume h, h.elim)
/-! ## Natural Numbers -/
attribute [simp] nat.add
/-! ## Integers -/
@[simp] lemma int.neg_comp_neg :
int.neg β int.neg = id :=
begin
apply funext,
apply neg_neg
end
/-! ## Reflexive Transitive Closure -/
namespace rtc
inductive star {Ξ± : Sort*} (r : Ξ± β Ξ± β Prop) (a : Ξ±) : Ξ± β Prop
| refl {} : star a
| tail {b c} : star b β r b c β star c
attribute [refl] star.refl
namespace star
variables {Ξ± : Sort*} {r : Ξ± β Ξ± β Prop} {a b c d : Ξ±}
@[trans] lemma trans (hab : star r a b) (hbc : star r b c) :
star r a c :=
begin
induction' hbc,
case refl {
assumption },
case tail : c d hbc hcd hac {
exact (tail (hac hab)) hcd }
end
lemma single (hab : r a b) :
star r a b :=
refl.tail hab
lemma head (hab : r a b) (hbc : star r b c) :
star r a c :=
begin
induction' hbc,
case refl {
exact (tail refl) hab },
case tail : c d hbc hcd hac {
exact (tail (hac hab)) hcd }
end
lemma head_induction_on {Ξ± : Sort*} {r : Ξ± β Ξ± β Prop} {b : Ξ±}
{P : βa : Ξ±, star r a b β Prop} {a : Ξ±} (h : star r a b)
(refl : P b refl)
(head : β{a c} (h' : r a c) (h : star r c b), P c h β P a (h.head h')) :
P a h :=
begin
induction' h,
case refl {
exact refl },
case tail : b c hab hbc ih {
apply ih,
show P b _, from
head hbc _ refl,
show βa a', r a a' β star r a' b β P a' _ β P a _, from
assume a a' hab hbc, head hab _ }
end
lemma trans_induction_on {Ξ± : Sort*} {r : Ξ± β Ξ± β Prop}
{p : β{a b : Ξ±}, star r a b β Prop} {a b : Ξ±} (h : star r a b)
(ihβ : βa, @p a a refl) (ihβ : β{a b} (h : r a b), p (single h))
(ihβ : β{a b c} (hβ : star r a b) (hβ : star r b c), p hβ β
p hβ β p (hβ.trans hβ)) :
p h :=
begin
induction' h,
case refl {
exact ihβ a },
case tail : b c hab hbc ih {
exact ihβ hab (single hbc) (ih ihβ @ihβ @ihβ) (ihβ hbc) }
end
lemma lift {Ξ² : Sort*} {s : Ξ² β Ξ² β Prop} (f : Ξ± β Ξ²)
(h : βa b, r a b β s (f a) (f b)) (hab : star r a b) :
star s (f a) (f b) :=
hab.trans_induction_on
(assume a, refl)
(assume a b, single β h _ _)
(assume a b c _ _, trans)
lemma mono {p : Ξ± β Ξ± β Prop} :
(βa b, r a b β p a b) β star r a b β star p a b :=
lift id
lemma star_star_eq :
star (star r) = star r :=
funext
(assume a,
funext
(assume b,
propext (iff.intro
(assume h,
begin
induction' h,
{ refl },
{ transitivity;
assumption }
end)
(star.mono (assume a b,
single)))))
end star
end rtc
export rtc
/-! ## States -/
def state : Type :=
string β β
def state.update (name : string) (val : β) (s : state) : state :=
Ξ»name', if name' = name then val else s name'
notation s `{` name ` β¦ ` val `}` := state.update name val s
instance : has_emptyc state :=
{ emptyc := Ξ»_, 0 }
@[simp] lemma update_apply (name : string) (val : β) (s : state) :
s{name β¦ val} name = val :=
if_pos rfl
@[simp] lemma update_apply_ne (name name' : string) (val : β) (s : state)
(h : name' β name . tactic.dec_trivial) :
s{name β¦ val} name' = s name' :=
if_neg h
@[simp] lemma update_override (name : string) (valβ valβ : β) (s : state) :
s{name β¦ valβ}{name β¦ valβ} = s{name β¦ valβ} :=
begin
apply funext,
intro name',
by_cases name' = name;
simp [h]
end
@[simp] lemma update_swap (nameβ nameβ : string) (valβ valβ : β) (s : state)
(h : nameβ β nameβ . tactic.dec_trivial) :
s{nameβ β¦ valβ}{nameβ β¦ valβ} = s{nameβ β¦ valβ}{nameβ β¦ valβ} :=
begin
apply funext,
intro name',
by_cases name' = nameβ;
by_cases name' = nameβ;
simp * at *
end
@[simp] lemma update_id (name : string) (s : state) :
s{name β¦ s name} = s :=
begin
apply funext,
intro name',
by_cases name' = name;
simp * at *
end
@[simp] lemma update_same_const (name : string) (val : β) :
(Ξ»_, val){name β¦ val} = (Ξ»_, val) :=
by apply funext; simp
example (s : state) :
s{"a" β¦ 0}{"a" β¦ 2} = s{"a" β¦ 2} :=
by simp
example (s : state) :
s{"a" β¦ 0}{"b" β¦ 2} = s{"b" β¦ 2}{"a" β¦ 0} :=
by simp
example (s : state) :
s{"a" β¦ s "a"}{"b" β¦ 0} = s{"b" β¦ 0} :=
by simp
/-! ## Relations -/
def Id {Ξ± : Type} : set (Ξ± Γ Ξ±) :=
{ab | prod.snd ab = prod.fst ab}
@[simp] lemma mem_Id {Ξ± : Type} (a b : Ξ±) :
(a, b) β @Id Ξ± β b = a :=
by refl
def comp {Ξ± : Type} (rβ rβ : set (Ξ± Γ Ξ±)) : set (Ξ± Γ Ξ±) :=
{ac | βb, (prod.fst ac, b) β rβ β§ (b, prod.snd ac) β rβ}
infixl ` β― ` : 90 := comp
@[simp] lemma mem_comp {Ξ± : Type} (rβ rβ : set (Ξ± Γ Ξ±))
(a b : Ξ±) :
(a, b) β rβ β― rβ β (βc, (a, c) β rβ β§ (c, b) β rβ) :=
by refl
def restrict {Ξ± : Type} (r : set (Ξ± Γ Ξ±)) (p : Ξ± β Prop) :
set (Ξ± Γ Ξ±) :=
{ab | ab β r β§ p (prod.fst ab)}
infixl ` β ` : 90 := restrict
@[simp] lemma mem_restrict {Ξ± : Type} (r : set (Ξ± Γ Ξ±))
(p : Ξ± β Prop) (a b : Ξ±) :
(a, b) β r β p β (a, b) β r β§ p a :=
by refl
/-! ## Setoids -/
def equivalence_rel : Type β Type :=
setoid
end LoVe
|
d10873b3a74ab6b6637b6013946e7ee30bb76245 | 4727251e0cd73359b15b664c3170e5d754078599 | /src/dynamics/flow.lean | 5103f6a58c727e029568db91c2e51f0489840c9f | [
"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 | 6,165 | lean | /-
Copyright (c) 2020 Jean Lo. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jean Lo
-/
import topology.algebra.group
import logic.function.iterate
/-!
# Flows and invariant sets
This file defines a flow on a topological space `Ξ±` by a topological
monoid `Ο` as a continuous monoid-act of `Ο` on `Ξ±`. Anticipating the
cases where `Ο` is one of `β`, `β€`, `ββΊ`, or `β`, we use additive
notation for the monoids, though the definition does not require
commutativity.
A subset `s` of `Ξ±` is invariant under a family of maps `Οβ : Ξ± β Ξ±`
if `Οβ s β s` for all `t`. In many cases `Ο` will be a flow on
`Ξ±`. For the cases where `Ο` is a flow by an ordered (additive,
commutative) monoid, we additionally define forward invariance, where
`t` ranges over those elements which are nonnegative.
Additionally, we define such constructions as the restriction of a
flow onto an invariant subset, and the time-reveral of a flow by a
group.
-/
open set function filter
/-!
### Invariant sets
-/
section invariant
variables {Ο : Type*} {Ξ± : Type*}
/-- A set `s β Ξ±` is invariant under `Ο : Ο β Ξ± β Ξ±` if
`Ο t s β s` for all `t` in `Ο`. -/
def is_invariant (Ο : Ο β Ξ± β Ξ±) (s : set Ξ±): Prop := β t, maps_to (Ο t) s s
variables (Ο : Ο β Ξ± β Ξ±) (s : set Ξ±)
lemma is_invariant_iff_image : is_invariant Ο s β β t, Ο t '' s β s :=
by simp_rw [is_invariant, maps_to']
/-- A set `s β Ξ±` is forward-invariant under `Ο : Ο β Ξ± β Ξ±` if
`Ο t s β s` for all `t β₯ 0`. -/
def is_fw_invariant [preorder Ο] [has_zero Ο] (Ο : Ο β Ξ± β Ξ±) (s : set Ξ±): Prop :=
β β¦tβ¦, 0 β€ t β maps_to (Ο t) s s
lemma is_invariant.is_fw_invariant [preorder Ο] [has_zero Ο] {Ο : Ο β Ξ± β Ξ±} {s : set Ξ±}
(h : is_invariant Ο s) : is_fw_invariant Ο s :=
Ξ» t ht, h t
/-- If `Ο` is a `canonically_ordered_add_monoid` (e.g., `β` or `ββ₯0`), then the notions
`is_fw_invariant` and `is_invariant` are equivalent. -/
lemma is_fw_invariant.is_invariant [canonically_ordered_add_monoid Ο] {Ο : Ο β Ξ± β Ξ±} {s : set Ξ±}
(h : is_fw_invariant Ο s) : is_invariant Ο s :=
Ξ» t, h (zero_le t)
/-- If `Ο` is a `canonically_ordered_add_monoid` (e.g., `β` or `ββ₯0`), then the notions
`is_fw_invariant` and `is_invariant` are equivalent. -/
lemma is_fw_invariant_iff_is_invariant [canonically_ordered_add_monoid Ο]
{Ο : Ο β Ξ± β Ξ±} {s : set Ξ±} :
is_fw_invariant Ο s β is_invariant Ο s :=
β¨is_fw_invariant.is_invariant, is_invariant.is_fw_invariantβ©
end invariant
/-!
### Flows
-/
/-- A flow on a topological space `Ξ±` by an a additive topological
monoid `Ο` is a continuous monoid action of `Ο` on `Ξ±`.-/
structure flow
(Ο : Type*) [topological_space Ο] [add_monoid Ο] [has_continuous_add Ο]
(Ξ± : Type*) [topological_space Ξ±] :=
(to_fun : Ο β Ξ± β Ξ±)
(cont' : continuous (uncurry to_fun))
(map_add' : β tβ tβ x, to_fun (tβ + tβ) x = to_fun tβ (to_fun tβ x))
(map_zero' : β x, to_fun 0 x = x)
namespace flow
variables
{Ο : Type*} [add_monoid Ο] [topological_space Ο] [has_continuous_add Ο]
{Ξ± : Type*} [topological_space Ξ±]
(Ο : flow Ο Ξ±)
instance : inhabited (flow Ο Ξ±) :=
β¨{ to_fun := Ξ» _ x, x,
cont' := continuous_snd,
map_add' := Ξ» _ _ _, rfl,
map_zero' := Ξ» _, rfl }β©
instance : has_coe_to_fun (flow Ο Ξ±) (Ξ» _, Ο β Ξ± β Ξ±) := β¨flow.to_funβ©
@[ext]
lemma ext : β {Οβ Οβ : flow Ο Ξ±}, (β t x, Οβ t x = Οβ t x) β Οβ = Οβ
| β¨fβ, _, _, _β© β¨fβ, _, _, _β© h := by { congr, funext, exact h _ _ }
@[continuity]
protected lemma continuous {Ξ² : Type*} [topological_space Ξ²]
{t : Ξ² β Ο} (ht : continuous t) {f : Ξ² β Ξ±} (hf : continuous f) :
continuous (Ξ» x, Ο (t x) (f x)) :=
Ο.cont'.comp (ht.prod_mk hf)
alias flow.continuous β continuous.flow
lemma map_add (tβ tβ : Ο) (x : Ξ±) : Ο (tβ + tβ) x = Ο tβ (Ο tβ x) :=
Ο.map_add' _ _ _
@[simp] lemma map_zero : Ο 0 = id := funext Ο.map_zero'
lemma map_zero_apply (x : Ξ±) : Ο 0 x = x := Ο.map_zero' x
/-- Iterations of a continuous function from a topological space `Ξ±`
to itself defines a semiflow by `β` on `Ξ±`. -/
def from_iter {g : Ξ± β Ξ±} (h : continuous g) : flow β Ξ± :=
{ to_fun := Ξ» n x, g^[n] x,
cont' := continuous_uncurry_of_discrete_topology_left (continuous.iterate h),
map_add' := iterate_add_apply _,
map_zero' := Ξ» x, rfl }
/-- Restriction of a flow onto an invariant set. -/
def restrict {s : set Ξ±} (h : is_invariant Ο s) : flow Ο β₯s :=
{ to_fun := Ξ» t, (h t).restrict _ _ _,
cont' := continuous_subtype_mk _ (Ο.continuous continuous_fst
(continuous_subtype_coe.comp continuous_snd)),
map_add' := Ξ» _ _ _, subtype.ext (map_add _ _ _ _),
map_zero' := Ξ» _, subtype.ext (map_zero_apply _ _)}
end flow
namespace flow
variables
{Ο : Type*} [add_comm_group Ο] [topological_space Ο] [topological_add_group Ο]
{Ξ± : Type*} [topological_space Ξ±]
(Ο : flow Ο Ξ±)
lemma is_invariant_iff_image_eq (s : set Ξ±) :
is_invariant Ο s β β t, Ο t '' s = s :=
(is_invariant_iff_image _ _).trans (iff.intro
(Ξ» h t, subset.antisymm (h t) (Ξ» _ hx, β¨_, h (-t) β¨_, hx, rflβ©, by simp [β map_add]β©))
(Ξ» h t, by rw h t))
/-- The time-reversal of a flow `Ο` by a (commutative, additive) group
is defined `Ο.reverse t x = Ο (-t) x`. -/
def reverse : flow Ο Ξ± :=
{ to_fun := Ξ» t, Ο (-t),
cont' := Ο.continuous continuous_fst.neg continuous_snd,
map_add' := Ξ» _ _ _, by rw [neg_add, map_add],
map_zero' := Ξ» _, by rw [neg_zero, map_zero_apply] }
/-- The map `Ο t` as a homeomorphism. -/
def to_homeomorph (t : Ο) : Ξ± ββ Ξ± :=
{ to_fun := Ο t,
inv_fun := Ο (-t),
left_inv := Ξ» x, by rw [β map_add, neg_add_self, map_zero_apply],
right_inv := Ξ» x, by rw [β map_add, add_neg_self, map_zero_apply] }
lemma image_eq_preimage (t : Ο) (s : set Ξ±) : Ο t '' s = Ο (-t) β»ΒΉ' s :=
(Ο.to_homeomorph t).to_equiv.image_eq_preimage s
end flow
|
17b770fae4b84c126379d6cb6ecd3493ab26107c | a3db153d66921f9d5a199b60b52ab3c21cf0e023 | /src/sia.lean | 383a2a04f7a7630e862175c8c21033467b6077be | [
"MIT"
] | permissive | metalogical/sia-lean | 3bd87a76b3ee6d910cbf182eb2a0e6d9eca3c056 | f8e354dd2ff6c09c4e001c1f80f6112c62da8592 | refs/heads/master | 1,629,775,811,523 | 1,512,684,874,000 | 1,512,684,874,000 | 106,763,566 | 4 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 1,337 | lean | import .ordered_field
import .util
universe u
variable {R : Type u}
section -- define Delta in terms of ring to avoid circularity in the definition of sia
variable [ring R]
@[reducible] private def DeltaT := { x:R // x * x = 0 }
@[reducible] private def zDeltaT : DeltaT := { val := (0 : R), property := ring.mul_zero (0 : R) }
end
-- Smooth Infinitesimal Analysis
class sia R extends st_ordered_field R :=
(exists_unique_sqrt : forall a : { r: R // r > 0 }, exists! b, b * b = a.val) -- we have at least the real numbers (? is this equivalent to LUB)
(kock_lawvere : forall f: DeltaT -> R, exists! a: R, forall d: DeltaT, f d = f zDeltaT + a * d.val)
namespace sia -- intervals
variable [sia R]
@[reducible]
def microstable (A : set R) : Prop := forall a : subtype A, forall d : DeltaT, set.mem (a.val + d.val) A
end sia
namespace sia
-- export Delta in terms of sia; type parameter R is explicit because Lean cannot typically infer it
@[reducible] def Delta (R: Type u) [sia R] := fun r : R, r * r = 0
@[reducible] def DeltaT (R: Type u) [sia R] := subtype (Delta R)
instance {R : Type u} [sia R] : has_zero (DeltaT R) := (| zDeltaT |)
-- instance {R : Type u} [sia R] : has_neg (DeltaT R) := { neg := fun (a : DeltaT R), { val := -a.val, property := sorry } }
end sia
|
a2abd0310b7d49e5d50c227e61a2e97afbb5c3f2 | 8b9f17008684d796c8022dab552e42f0cb6fb347 | /tests/lean/run/tactic14.lean | e0defea4e5d248da97819bf465b858c25c377e13 | [
"Apache-2.0"
] | permissive | chubbymaggie/lean | 0d06ae25f9dd396306fb02190e89422ea94afd7b | d2c7b5c31928c98f545b16420d37842c43b4ae9a | refs/heads/master | 1,611,313,622,901 | 1,430,266,839,000 | 1,430,267,083,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 462 | lean | import logic
open tactic
notation `(` h `|` r:(foldl `|` (e r, tactic.or_else r e) h) `)` := r
definition basic_tac : tactic
:= repeat (apply @and.intro | assumption)
set_begin_end_tactic basic_tac -- basic_tac is automatically applied to each element of a proof-qed block
theorem tst (a b : Prop) (H : Β¬ a β¨ Β¬ b) (Hb : b) : Β¬ a β§ b :=
begin
assume Ha, or.elim H
(assume Hna, @absurd _ false Ha Hna)
(assume Hnb, @absurd _ false Hb Hnb)
end
|
9fcea9540fdbf493361ede1d09811295571d8683 | a4673261e60b025e2c8c825dfa4ab9108246c32e | /tests/lean/run/sharecommon.lean | 5d93d5b3e94660ad9131228d72b3d2a9d641fdb7 | [
"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 | 3,901 | lean | import Std.ShareCommon
open Std
def check (b : Bool) : ShareCommonT IO Unit := do
unless b do throw $ IO.userError "check failed"
unsafe def tst1 : ShareCommonT IO Unit := do
let x := [1]
let y := [0].map (fun x => x + 1)
check $ ptrAddrUnsafe x != ptrAddrUnsafe y
let x β shareCommonM x
let y β shareCommonM y
check $ ptrAddrUnsafe x == ptrAddrUnsafe y
let z β shareCommonM [2]
let x β shareCommonM x
check $ ptrAddrUnsafe x == ptrAddrUnsafe y
check $ ptrAddrUnsafe x != ptrAddrUnsafe z
IO.println x
IO.println y
IO.println z
#eval tst1.run
unsafe def tst2 : ShareCommonT IO Unit := do
let x := [1, 2]
let y := [0, 1].map (fun x => x + 1)
check $ ptrAddrUnsafe x != ptrAddrUnsafe y
let x β shareCommonM x
let y β shareCommonM y
check $ ptrAddrUnsafe x == ptrAddrUnsafe y
let z β shareCommonM [2]
let x β shareCommonM x
check $ ptrAddrUnsafe x == ptrAddrUnsafe y
check $ ptrAddrUnsafe x != ptrAddrUnsafe z
IO.println x
IO.println y
IO.println z
#eval tst2.run
structure Foo :=
(x : Nat)
(y : Bool)
(z : Bool)
@[noinline] def mkFoo1 (x : Nat) (z : Bool) : Foo := { x := x, y := true, z := z }
@[noinline] def mkFoo2 (x : Nat) (z : Bool) : Foo := { x := x, y := true, z := z }
unsafe def tst3 : ShareCommonT IO Unit := do
let o1 := mkFoo1 10 true
let o2 := mkFoo2 10 true
let o3 := mkFoo2 10 false
check $ ptrAddrUnsafe o1 != ptrAddrUnsafe o2
check $ ptrAddrUnsafe o1 != ptrAddrUnsafe o3
let o1 β shareCommonM o1
let o2 β shareCommonM o2
let o3 β shareCommonM o3
check $
o1.x == 10 && o1.y == true &&
o1.z == true && o3.z == false &&
ptrAddrUnsafe o1 == ptrAddrUnsafe o2 &&
ptrAddrUnsafe o1 != ptrAddrUnsafe o3
IO.println o1.x
pure ()
#eval tst3.run
unsafe def tst4 : ShareCommonT IO Unit := do
let x := ["hello"]
let y := ["ello"].map (fun x => "h" ++ x)
check $ ptrAddrUnsafe x != ptrAddrUnsafe y
let x β shareCommonM x
let y β shareCommonM y
check $ ptrAddrUnsafe x == ptrAddrUnsafe y
let z β shareCommonM ["world"]
let x β shareCommonM x
check $
ptrAddrUnsafe x == ptrAddrUnsafe y &&
ptrAddrUnsafe x != ptrAddrUnsafe z
IO.println x
IO.println y
IO.println z
#eval tst4.run
@[noinline] def mkList1 (x : Nat) : List Nat := List.replicate x x
@[noinline] def mkList2 (x : Nat) : List Nat := List.replicate x x
@[noinline] def mkArray1 (x : Nat) : Array (List Nat) :=
#[ mkList1 x, mkList2 x, mkList2 (x+1) ]
@[noinline] def mkArray2 (x : Nat) : Array (List Nat) :=
mkArray1 x
unsafe def tst5 : ShareCommonT IO Unit := do
let a := mkArray1 3
let b := mkArray2 3
let c := mkArray2 4
IO.println a
IO.println b
IO.println c
check $
ptrAddrUnsafe a != ptrAddrUnsafe b &&
ptrAddrUnsafe a != ptrAddrUnsafe c &&
ptrAddrUnsafe a[0] != ptrAddrUnsafe a[1] &&
ptrAddrUnsafe a[0] != ptrAddrUnsafe a[2] &&
ptrAddrUnsafe b[0] != ptrAddrUnsafe b[1] &&
ptrAddrUnsafe c[0] != ptrAddrUnsafe c[1]
let a β shareCommonM a
let b β shareCommonM b
let c β shareCommonM c
check $
ptrAddrUnsafe a == ptrAddrUnsafe b &&
ptrAddrUnsafe a != ptrAddrUnsafe c &&
ptrAddrUnsafe a[0] == ptrAddrUnsafe a[1] &&
ptrAddrUnsafe a[0] != ptrAddrUnsafe a[2] &&
ptrAddrUnsafe b[0] == ptrAddrUnsafe b[1] &&
ptrAddrUnsafe c[0] == ptrAddrUnsafe c[1]
pure ()
#eval tst5.run
@[noinline] def mkByteArray1 (x : Nat) : ByteArray :=
let r := ByteArray.empty
let r := r.push x.toUInt8
let r := r.push (x+1).toUInt8
let r := r.push (x+2).toUInt8
r
@[noinline] def mkByteArray2 (x : Nat) : ByteArray :=
mkByteArray1 x
unsafe def tst6 (x : Nat) : ShareCommonT IO Unit := do
let a := [mkByteArray1 x]
let b := [mkByteArray2 x]
let c := [mkByteArray2 (x+1)]
IO.println a
IO.println b
IO.println c
check $ ptrAddrUnsafe a != ptrAddrUnsafe b
check $ ptrAddrUnsafe a != ptrAddrUnsafe c
let a β shareCommonM a
let b β shareCommonM b
let c β shareCommonM c
check $ ptrAddrUnsafe a == ptrAddrUnsafe b
check $ ptrAddrUnsafe a != ptrAddrUnsafe c
pure ()
#eval (tst6 2).run
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.