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
|
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
7f1eb27c9295bc42b3b14038a498a56890b058c2
|
77c5b91fae1b966ddd1db969ba37b6f0e4901e88
|
/src/data/nat/choose/basic.lean
|
17a7051e63454fe5b0942153ddc4e2c09394f9af
|
[
"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
| 11,496
|
lean
|
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Bhavik Mehta
-/
import data.nat.factorial.basic
/-!
# Binomial coefficients
This file defines binomial coefficients and proves simple lemmas (i.e. those not
requiring more imports).
## Main definition and results
* `nat.choose`: binomial coefficients, defined inductively
* `nat.choose_eq_factorial_div_factorial`: a proof that `choose n k = n! / (k! * (n - k)!)`
* `nat.choose_symm`: symmetry of binomial coefficients
* `nat.choose_le_succ_of_lt_half_left`: `choose n k` is increasing for small values of `k`
* `nat.choose_le_middle`: `choose n r` is maximised when `r` is `n/2`
* `nat.desc_factorial_eq_factorial_mul_choose`: Relates binomial coefficients to the descending
factorial. This is used to prove `nat.choose_le_pow` and variants. We provide similar statements
for the ascending factorial.
-/
open_locale nat
namespace nat
/-- `choose n k` is the number of `k`-element subsets in an `n`-element set. Also known as binomial
coefficients. -/
def choose : ℕ → ℕ → ℕ
| _ 0 := 1
| 0 (k + 1) := 0
| (n + 1) (k + 1) := choose n k + choose n (k + 1)
@[simp] lemma choose_zero_right (n : ℕ) : choose n 0 = 1 := by cases n; refl
@[simp] lemma choose_zero_succ (k : ℕ) : choose 0 (succ k) = 0 := rfl
lemma choose_succ_succ (n k : ℕ) : choose (succ n) (succ k) = choose n k + choose n (succ k) := rfl
lemma choose_eq_zero_of_lt : ∀ {n k}, n < k → choose n k = 0
| _ 0 hk := absurd hk dec_trivial
| 0 (k + 1) hk := choose_zero_succ _
| (n + 1) (k + 1) hk :=
have hnk : n < k, from lt_of_succ_lt_succ hk,
have hnk1 : n < k + 1, from lt_of_succ_lt hk,
by rw [choose_succ_succ, choose_eq_zero_of_lt hnk, choose_eq_zero_of_lt hnk1]
@[simp] lemma choose_self (n : ℕ) : choose n n = 1 :=
by induction n; simp [*, choose, choose_eq_zero_of_lt (lt_succ_self _)]
@[simp] lemma choose_succ_self (n : ℕ) : choose n (succ n) = 0 :=
choose_eq_zero_of_lt (lt_succ_self _)
@[simp] lemma choose_one_right (n : ℕ) : choose n 1 = n :=
by induction n; simp [*, choose, add_comm]
/- The `n+1`-st triangle number is `n` more than the `n`-th triangle number -/
lemma triangle_succ (n : ℕ) : (n + 1) * ((n + 1) - 1) / 2 = n * (n - 1) / 2 + n :=
begin
rw [← add_mul_div_left, mul_comm 2 n, ← mul_add, nat.add_sub_cancel, mul_comm],
cases n; refl, apply zero_lt_succ
end
/-- `choose n 2` is the `n`-th triangle number. -/
lemma choose_two_right (n : ℕ) : choose n 2 = n * (n - 1) / 2 :=
begin
induction n with n ih,
simp,
{rw triangle_succ n, simp [choose, ih], rw add_comm},
end
lemma choose_pos : ∀ {n k}, k ≤ n → 0 < choose n k
| 0 _ hk := by rw [nat.eq_zero_of_le_zero hk]; exact dec_trivial
| (n + 1) 0 hk := by simp; exact dec_trivial
| (n + 1) (k + 1) hk := by rw choose_succ_succ;
exact add_pos_of_pos_of_nonneg (choose_pos (le_of_succ_le_succ hk)) (nat.zero_le _)
lemma succ_mul_choose_eq : ∀ n k, succ n * choose n k = choose (succ n) (succ k) * succ k
| 0 0 := dec_trivial
| 0 (k + 1) := by simp [choose]
| (n + 1) 0 := by simp
| (n + 1) (k + 1) :=
by rw [choose_succ_succ (succ n) (succ k), add_mul, ←succ_mul_choose_eq, mul_succ,
←succ_mul_choose_eq, add_right_comm, ←mul_add, ←choose_succ_succ, ←succ_mul]
lemma choose_mul_factorial_mul_factorial : ∀ {n k}, k ≤ n → choose n k * k! * (n - k)! = n!
| 0 _ hk := by simp [nat.eq_zero_of_le_zero hk]
| (n + 1) 0 hk := by simp
| (n + 1) (succ k) hk :=
begin
cases lt_or_eq_of_le hk with hk₁ hk₁,
{ have h : choose n k * k.succ! * (n-k)! = k.succ * n! :=
by rw ← choose_mul_factorial_mul_factorial (le_of_succ_le_succ hk);
simp [factorial_succ, mul_comm, mul_left_comm],
have h₁ : (n - k)! = (n - k) * (n - k.succ)! :=
by rw [← succ_sub_succ, succ_sub (le_of_lt_succ hk₁), factorial_succ],
have h₂ : choose n (succ k) * k.succ! * ((n - k) * (n - k.succ)!) = (n - k) * n! :=
by rw ← choose_mul_factorial_mul_factorial (le_of_lt_succ hk₁);
simp [factorial_succ, mul_comm, mul_left_comm, mul_assoc],
have h₃ : k * n! ≤ n * n! := nat.mul_le_mul_right _ (le_of_succ_le_succ hk),
rw [choose_succ_succ, add_mul, add_mul, succ_sub_succ, h, h₁, h₂, ← add_one, add_mul,
nat.mul_sub_right_distrib, factorial_succ, ← nat.add_sub_assoc h₃, add_assoc, ← add_mul,
nat.add_sub_cancel_left, add_comm] },
{ simp [hk₁, mul_comm, choose, nat.sub_self] }
end
lemma choose_mul {n k s : ℕ} (hkn : k ≤ n) (hsk : s ≤ k) :
n.choose k * k.choose s = n.choose s * (n - s).choose (k - s) :=
begin
have h : 0 < (n - k)! * (k - s)! * s! :=
mul_pos (mul_pos (factorial_pos _) (factorial_pos _)) (factorial_pos _),
refine eq_of_mul_eq_mul_right h _,
calc
n.choose k * k.choose s * ((n - k)! * (k - s)! * s!)
= n.choose k * (k.choose s * s! * (k - s)!) * (n - k)!
: by rw [mul_assoc, mul_assoc, mul_assoc, mul_assoc _ s!, mul_assoc, mul_comm (n - k)!,
mul_comm s!]
... = n!
: by rw [choose_mul_factorial_mul_factorial hsk, choose_mul_factorial_mul_factorial hkn]
... = n.choose s * s! * ((n - s).choose (k - s) * (k - s)! * (n - s - (k - s))!)
: by rw [choose_mul_factorial_mul_factorial (nat.sub_le_sub_right hkn _),
choose_mul_factorial_mul_factorial (hsk.trans hkn)]
... = n.choose s * (n - s).choose (k - s) * ((n - k)! * (k - s)! * s!)
: by rw [sub_sub_sub_cancel_right hsk, mul_assoc, mul_left_comm s!, mul_assoc,
mul_comm (k - s)!, mul_comm s!, mul_right_comm, ←mul_assoc]
end
theorem choose_eq_factorial_div_factorial {n k : ℕ} (hk : k ≤ n) :
choose n k = n! / (k! * (n - k)!) :=
begin
rw [← choose_mul_factorial_mul_factorial hk, mul_assoc],
exact (mul_div_left _ (mul_pos (factorial_pos _) (factorial_pos _))).symm
end
lemma add_choose (i j : ℕ) : (i + j).choose j = (i + j)! / (i! * j!) :=
by rw [choose_eq_factorial_div_factorial (nat.le_add_left j i), nat.add_sub_cancel, mul_comm]
lemma add_choose_mul_factorial_mul_factorial (i j : ℕ) : (i + j).choose j * i! * j! = (i + j)! :=
by rw [← choose_mul_factorial_mul_factorial (nat.le_add_left _ _),
nat.add_sub_cancel, mul_right_comm]
theorem factorial_mul_factorial_dvd_factorial {n k : ℕ} (hk : k ≤ n) : k! * (n - k)! ∣ n! :=
by rw [←choose_mul_factorial_mul_factorial hk, mul_assoc]; exact dvd_mul_left _ _
lemma factorial_mul_factorial_dvd_factorial_add (i j : ℕ) :
i! * j! ∣ (i + j)! :=
begin
convert factorial_mul_factorial_dvd_factorial (le.intro rfl),
rw nat.add_sub_cancel_left
end
@[simp] lemma choose_symm {n k : ℕ} (hk : k ≤ n) : choose n (n-k) = choose n k :=
by rw [choose_eq_factorial_div_factorial hk, choose_eq_factorial_div_factorial (nat.sub_le _ _),
nat.sub_sub_self hk, mul_comm]
lemma choose_symm_of_eq_add {n a b : ℕ} (h : n = a + b) : nat.choose n a = nat.choose n b :=
by { convert nat.choose_symm (nat.le_add_left _ _), rw nat.add_sub_cancel}
lemma choose_symm_add {a b : ℕ} : choose (a+b) a = choose (a+b) b :=
choose_symm_of_eq_add rfl
lemma choose_symm_half (m : ℕ) : choose (2 * m + 1) (m + 1) = choose (2 * m + 1) m :=
by { apply choose_symm_of_eq_add,
rw [add_comm m 1, add_assoc 1 m m, add_comm (2 * m) 1, two_mul m] }
lemma choose_succ_right_eq (n k : ℕ) : choose n (k + 1) * (k + 1) = choose n k * (n - k) :=
begin
have e : (n+1) * choose n k = choose n k * (k+1) + choose n (k+1) * (k+1),
rw [← right_distrib, ← choose_succ_succ, succ_mul_choose_eq],
rw [← nat.sub_eq_of_eq_add e, mul_comm, ← nat.mul_sub_left_distrib, nat.add_sub_add_right]
end
@[simp] lemma choose_succ_self_right : ∀ (n:ℕ), (n+1).choose n = n+1
| 0 := rfl
| (n+1) := by rw [choose_succ_succ, choose_succ_self_right, choose_self]
lemma choose_mul_succ_eq (n k : ℕ) :
(n.choose k) * (n + 1) = ((n+1).choose k) * (n + 1 - k) :=
begin
induction k with k ih, { simp },
obtain hk | hk := le_or_lt (k + 1) (n + 1),
{ rw [choose_succ_succ, add_mul, succ_sub_succ, ←choose_succ_right_eq, ←succ_sub_succ,
nat.mul_sub_left_distrib, nat.add_sub_cancel' (nat.mul_le_mul_left _ hk)] },
rw [choose_eq_zero_of_lt hk, choose_eq_zero_of_lt (n.lt_succ_self.trans hk), zero_mul, zero_mul],
end
lemma asc_factorial_eq_factorial_mul_choose (n k : ℕ) :
n.asc_factorial k = k! * (n + k).choose k :=
begin
rw mul_comm,
apply mul_right_cancel₀ (factorial_ne_zero (n + k - k)),
rw [choose_mul_factorial_mul_factorial, nat.add_sub_cancel, ←factorial_mul_asc_factorial,
mul_comm],
exact nat.le_add_left k n,
end
lemma factorial_dvd_asc_factorial (n k : ℕ) : k! ∣ n.asc_factorial k :=
⟨(n+k).choose k, asc_factorial_eq_factorial_mul_choose _ _⟩
lemma choose_eq_asc_factorial_div_factorial (n k : ℕ) :
(n + k).choose k = n.asc_factorial k / k! :=
begin
apply mul_left_cancel₀ (factorial_ne_zero k),
rw ←asc_factorial_eq_factorial_mul_choose,
exact (nat.mul_div_cancel' $ factorial_dvd_asc_factorial _ _).symm,
end
lemma desc_factorial_eq_factorial_mul_choose (n k : ℕ) : n.desc_factorial k = k! * n.choose k :=
begin
obtain h | h := nat.lt_or_ge n k,
{ rw [desc_factorial_eq_zero_iff_lt.2 h, choose_eq_zero_of_lt h, mul_zero] },
rw mul_comm,
apply mul_right_cancel₀ (factorial_ne_zero (n - k)),
rw [choose_mul_factorial_mul_factorial h, ←factorial_mul_desc_factorial h, mul_comm],
end
lemma factorial_dvd_desc_factorial (n k : ℕ) : k! ∣ n.desc_factorial k :=
⟨n.choose k, desc_factorial_eq_factorial_mul_choose _ _⟩
lemma choose_eq_desc_factorial_div_factorial (n k : ℕ) : n.choose k = n.desc_factorial k / k! :=
begin
apply mul_left_cancel₀ (factorial_ne_zero k),
rw ←desc_factorial_eq_factorial_mul_choose,
exact (nat.mul_div_cancel' $ factorial_dvd_desc_factorial _ _).symm,
end
/-! ### Inequalities -/
/-- Show that `nat.choose` is increasing for small values of the right argument. -/
lemma choose_le_succ_of_lt_half_left {r n : ℕ} (h : r < n/2) :
choose n r ≤ choose n (r+1) :=
begin
refine le_of_mul_le_mul_right _ (nat.lt_sub_left_of_add_lt (lt_of_lt_of_le h (n.div_le_self 2))),
rw ← choose_succ_right_eq,
apply nat.mul_le_mul_left,
rw [← nat.lt_iff_add_one_le, nat.lt_sub_left_iff_add_lt, ← mul_two],
exact lt_of_lt_of_le (mul_lt_mul_of_pos_right h zero_lt_two) (n.div_mul_le_self 2),
end
/-- Show that for small values of the right argument, the middle value is largest. -/
private lemma choose_le_middle_of_le_half_left {n r : ℕ} (hr : r ≤ n/2) :
choose n r ≤ choose n (n/2) :=
decreasing_induction
(λ _ k a,
(eq_or_lt_of_le a).elim
(λ t, t.symm ▸ le_refl _)
(λ h, (choose_le_succ_of_lt_half_left h).trans (k h)))
hr (λ _, le_rfl) hr
/-- `choose n r` is maximised when `r` is `n/2`. -/
lemma choose_le_middle (r n : ℕ) : choose n r ≤ choose n (n/2) :=
begin
cases le_or_gt r n with b b,
{ cases le_or_lt r (n/2) with a h,
{ apply choose_le_middle_of_le_half_left a },
{ rw ← choose_symm b,
apply choose_le_middle_of_le_half_left,
rw [div_lt_iff_lt_mul' zero_lt_two] at h,
rw [le_div_iff_mul_le' zero_lt_two, nat.mul_sub_right_distrib, nat.sub_le_iff,
mul_two, nat.add_sub_cancel],
exact le_of_lt h } },
{ rw choose_eq_zero_of_lt b,
apply zero_le }
end
end nat
|
c8cbc2be2d3251c0170145d88290bf5910fb6a09
|
fa02ed5a3c9c0adee3c26887a16855e7841c668b
|
/src/group_theory/congruence.lean
|
bf450ce3ba6aea600f39d7e68f685eec9dea9e3b
|
[
"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
| 44,950
|
lean
|
/-
Copyright (c) 2019 Amelia Livingston. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Amelia Livingston
-/
import data.setoid.basic
import algebra.group.pi
import algebra.group.prod
import data.equiv.mul_add
import group_theory.submonoid.operations
/-!
# Congruence relations
This file defines congruence relations: equivalence relations that preserve a binary operation,
which in this case is multiplication or addition. The principal definition is a `structure`
extending a `setoid` (an equivalence relation), and the inductive definition of the smallest
congruence relation containing a binary relation is also given (see `con_gen`).
The file also proves basic properties of the quotient of a type by a congruence relation, and the
complete lattice of congruence relations on a type. We then establish an order-preserving bijection
between the set of congruence relations containing a congruence relation `c` and the set of
congruence relations on the quotient by `c`.
The second half of the file concerns congruence relations on monoids, in which case the
quotient by the congruence relation is also a monoid. There are results about the universal
property of quotients of monoids, and the isomorphism theorems for monoids.
## Implementation notes
The inductive definition of a congruence relation could be a nested inductive type, defined using
the equivalence closure of a binary relation `eqv_gen`, but the recursor generated does not work.
A nested inductive definition could conceivably shorten proofs, because they would allow invocation
of the corresponding lemmas about `eqv_gen`.
The lemmas `refl`, `symm` and `trans` are not tagged with `@[refl]`, `@[symm]`, and `@[trans]`
respectively as these tags do not work on a structure coerced to a binary relation.
There is a coercion from elements of a type to the element's equivalence class under a
congruence relation.
A congruence relation on a monoid `M` can be thought of as a submonoid of `M × M` for which
membership is an equivalence relation, but whilst this fact is established in the file, it is not
used, since this perspective adds more layers of definitional unfolding.
## Tags
congruence, congruence relation, quotient, quotient by congruence relation, monoid,
quotient monoid, isomorphism theorems
-/
variables (M : Type*) {N : Type*} {P : Type*}
set_option old_structure_cmd true
open function setoid
/-- A congruence relation on a type with an addition is an equivalence relation which
preserves addition. -/
structure add_con [has_add M] extends setoid M :=
(add' : ∀ {w x y z}, r w x → r y z → r (w + y) (x + z))
/-- A congruence relation on a type with a multiplication is an equivalence relation which
preserves multiplication. -/
@[to_additive add_con] structure con [has_mul M] extends setoid M :=
(mul' : ∀ {w x y z}, r w x → r y z → r (w * y) (x * z))
/-- The equivalence relation underlying an additive congruence relation. -/
add_decl_doc add_con.to_setoid
/-- The equivalence relation underlying a multiplicative congruence relation. -/
add_decl_doc con.to_setoid
variables {M}
/-- The inductively defined smallest additive congruence relation containing a given binary
relation. -/
inductive add_con_gen.rel [has_add M] (r : M → M → Prop) : M → M → Prop
| of : Π x y, r x y → add_con_gen.rel x y
| refl : Π x, add_con_gen.rel x x
| symm : Π x y, add_con_gen.rel x y → add_con_gen.rel y x
| trans : Π x y z, add_con_gen.rel x y → add_con_gen.rel y z → add_con_gen.rel x z
| add : Π w x y z, add_con_gen.rel w x → add_con_gen.rel y z → add_con_gen.rel (w + y) (x + z)
/-- The inductively defined smallest multiplicative congruence relation containing a given binary
relation. -/
@[to_additive add_con_gen.rel]
inductive con_gen.rel [has_mul M] (r : M → M → Prop) : M → M → Prop
| of : Π x y, r x y → con_gen.rel x y
| refl : Π x, con_gen.rel x x
| symm : Π x y, con_gen.rel x y → con_gen.rel y x
| trans : Π x y z, con_gen.rel x y → con_gen.rel y z → con_gen.rel x z
| mul : Π w x y z, con_gen.rel w x → con_gen.rel y z → con_gen.rel (w * y) (x * z)
/-- The inductively defined smallest multiplicative congruence relation containing a given binary
relation. -/
@[to_additive add_con_gen "The inductively defined smallest additive congruence relation containing
a given binary relation."]
def con_gen [has_mul M] (r : M → M → Prop) : con M :=
⟨con_gen.rel r, ⟨con_gen.rel.refl, con_gen.rel.symm, con_gen.rel.trans⟩, con_gen.rel.mul⟩
namespace con
section
variables [has_mul M] [has_mul N] [has_mul P] (c : con M)
@[to_additive]
instance : inhabited (con M) :=
⟨con_gen empty_relation⟩
/-- A coercion from a congruence relation to its underlying binary relation. -/
@[to_additive "A coercion from an additive congruence relation to its underlying binary relation."]
instance : has_coe_to_fun (con M) := ⟨_, λ c, λ x y, c.r x y⟩
@[simp, to_additive] lemma rel_eq_coe (c : con M) : c.r = c := rfl
/-- Congruence relations are reflexive. -/
@[to_additive "Additive congruence relations are reflexive."]
protected lemma refl (x) : c x x := c.2.1 x
/-- Congruence relations are symmetric. -/
@[to_additive "Additive congruence relations are symmetric."]
protected lemma symm : ∀ {x y}, c x y → c y x := λ _ _ h, c.2.2.1 h
/-- Congruence relations are transitive. -/
@[to_additive "Additive congruence relations are transitive."]
protected lemma trans : ∀ {x y z}, c x y → c y z → c x z :=
λ _ _ _ h, c.2.2.2 h
/-- Multiplicative congruence relations preserve multiplication. -/
@[to_additive "Additive congruence relations preserve addition."]
protected lemma mul : ∀ {w x y z}, c w x → c y z → c (w * y) (x * z) :=
λ _ _ _ _ h1 h2, c.3 h1 h2
/-- Given a type `M` with a multiplication, a congruence relation `c` on `M`, and elements of `M`
`x, y`, `(x, y) ∈ M × M` iff `x` is related to `y` by `c`. -/
@[to_additive "Given a type `M` with an addition, `x, y ∈ M`, and an additive congruence relation
`c` on `M`, `(x, y) ∈ M × M` iff `x` is related to `y` by `c`."]
instance : has_mem (M × M) (con M) := ⟨λ x c, c x.1 x.2⟩
variables {c}
/-- The map sending a congruence relation to its underlying binary relation is injective. -/
@[to_additive "The map sending an additive congruence relation to its underlying binary relation
is injective."]
lemma ext' {c d : con M} (H : c.r = d.r) : c = d :=
by cases c; cases d; simpa using H
/-- Extensionality rule for congruence relations. -/
@[ext, to_additive "Extensionality rule for additive congruence relations."]
lemma ext {c d : con M} (H : ∀ x y, c x y ↔ d x y) : c = d :=
ext' $ by ext; apply H
attribute [ext] add_con.ext
/-- The map sending a congruence relation to its underlying equivalence relation is injective. -/
@[to_additive "The map sending an additive congruence relation to its underlying equivalence
relation is injective."]
lemma to_setoid_inj {c d : con M} (H : c.to_setoid = d.to_setoid) : c = d :=
ext $ ext_iff.1 H
/-- Iff version of extensionality rule for congruence relations. -/
@[to_additive "Iff version of extensionality rule for additive congruence relations."]
lemma ext_iff {c d : con M} : (∀ x y, c x y ↔ d x y) ↔ c = d :=
⟨ext, λ h _ _, h ▸ iff.rfl⟩
/-- Two congruence relations are equal iff their underlying binary relations are equal. -/
@[to_additive "Two additive congruence relations are equal iff their underlying binary relations
are equal."]
lemma ext'_iff {c d : con M} : c.r = d.r ↔ c = d :=
⟨ext', λ h, h ▸ rfl⟩
/-- The kernel of a multiplication-preserving function as a congruence relation. -/
@[to_additive "The kernel of an addition-preserving function as an additive congruence relation."]
def mul_ker (f : M → P) (h : ∀ x y, f (x * y) = f x * f y) : con M :=
{ r := λ x y, f x = f y,
iseqv := ⟨λ _, rfl, λ _ _, eq.symm, λ _ _ _, eq.trans⟩,
mul' := λ _ _ _ _ h1 h2, by rw [h, h1, h2, h] }
/-- Given types with multiplications `M, N`, the product of two congruence relations `c` on `M` and
`d` on `N`: `(x₁, x₂), (y₁, y₂) ∈ M × N` are related by `c.prod d` iff `x₁` is related to `y₁`
by `c` and `x₂` is related to `y₂` by `d`. -/
@[to_additive prod "Given types with additions `M, N`, the product of two congruence relations
`c` on `M` and `d` on `N`: `(x₁, x₂), (y₁, y₂) ∈ M × N` are related by `c.prod d` iff `x₁`
is related to `y₁` by `c` and `x₂` is related to `y₂` by `d`."]
protected def prod (c : con M) (d : con N) : con (M × N) :=
{ mul' := λ _ _ _ _ h1 h2, ⟨c.mul h1.1 h2.1, d.mul h1.2 h2.2⟩, ..c.to_setoid.prod d.to_setoid }
/-- The product of an indexed collection of congruence relations. -/
@[to_additive "The product of an indexed collection of additive congruence relations."]
def pi {ι : Type*} {f : ι → Type*} [Π i, has_mul (f i)]
(C : Π i, con (f i)) : con (Π i, f i) :=
{ mul' := λ _ _ _ _ h1 h2 i, (C i).mul (h1 i) (h2 i), ..@pi_setoid _ _ $ λ i, (C i).to_setoid }
variables (c)
@[simp, to_additive] lemma coe_eq : c.to_setoid.r = c := rfl
-- Quotients
/-- Defining the quotient by a congruence relation of a type with a multiplication. -/
@[to_additive "Defining the quotient by an additive congruence relation of a type with
an addition."]
protected def quotient := quotient $ c.to_setoid
/-- Coercion from a type with a multiplication to its quotient by a congruence relation.
See Note [use has_coe_t]. -/
@[to_additive "Coercion from a type with an addition to its quotient by an additive congruence
relation", priority 0]
instance : has_coe_t M c.quotient := ⟨@quotient.mk _ c.to_setoid⟩
/-- The quotient of a type with decidable equality by a congruence relation also has
decidable equality. -/
@[to_additive "The quotient of a type with decidable equality by an additive congruence relation
also has decidable equality."]
instance [d : ∀ a b, decidable (c a b)] : decidable_eq c.quotient :=
@quotient.decidable_eq M c.to_setoid d
/-- The function on the quotient by a congruence relation `c` induced by a function that is
constant on `c`'s equivalence classes. -/
@[elab_as_eliminator, to_additive "The function on the quotient by a congruence relation `c`
induced by a function that is constant on `c`'s equivalence classes."]
protected def lift_on {β} {c : con M} (q : c.quotient) (f : M → β)
(h : ∀ a b, c a b → f a = f b) : β := quotient.lift_on' q f h
/-- The binary function on the quotient by a congruence relation `c` induced by a binary function
that is constant on `c`'s equivalence classes. -/
@[elab_as_eliminator, to_additive "The binary function on the quotient by a congruence relation `c`
induced by a binary function that is constant on `c`'s equivalence classes."]
protected def lift_on₂ {β} {c : con M} (q r : c.quotient) (f : M → M → β)
(h : ∀ a₁ a₂ b₁ b₂, c a₁ b₁ → c a₂ b₂ → f a₁ a₂ = f b₁ b₂) : β := quotient.lift_on₂' q r f h
variables {c}
/-- The inductive principle used to prove propositions about the elements of a quotient by a
congruence relation. -/
@[elab_as_eliminator, to_additive "The inductive principle used to prove propositions about
the elements of a quotient by an additive congruence relation."]
protected lemma induction_on {C : c.quotient → Prop} (q : c.quotient) (H : ∀ x : M, C x) : C q :=
quotient.induction_on' q H
/-- A version of `con.induction_on` for predicates which take two arguments. -/
@[elab_as_eliminator, to_additive "A version of `add_con.induction_on` for predicates which take
two arguments."]
protected lemma induction_on₂ {d : con N} {C : c.quotient → d.quotient → Prop}
(p : c.quotient) (q : d.quotient) (H : ∀ (x : M) (y : N), C x y) : C p q :=
quotient.induction_on₂' p q H
variables (c)
/-- Two elements are related by a congruence relation `c` iff they are represented by the same
element of the quotient by `c`. -/
@[simp, to_additive "Two elements are related by an additive congruence relation `c` iff they
are represented by the same element of the quotient by `c`."]
protected lemma eq {a b : M} : (a : c.quotient) = b ↔ c a b :=
quotient.eq'
/-- The multiplication induced on the quotient by a congruence relation on a type with a
multiplication. -/
@[to_additive "The addition induced on the quotient by an additive congruence relation on a type
with an addition."]
instance has_mul : has_mul c.quotient :=
⟨λ x y, quotient.lift_on₂' x y (λ w z, ((w * z : M) : c.quotient))
$ λ _ _ _ _ h1 h2, c.eq.2 $ c.mul h1 h2⟩
/-- The kernel of the quotient map induced by a congruence relation `c` equals `c`. -/
@[simp, to_additive "The kernel of the quotient map induced by an additive congruence relation
`c` equals `c`."]
lemma mul_ker_mk_eq : mul_ker (coe : M → c.quotient) (λ x y, rfl) = c :=
ext $ λ x y, quotient.eq'
variables {c}
/-- The coercion to the quotient of a congruence relation commutes with multiplication (by
definition). -/
@[simp, to_additive "The coercion to the quotient of an additive congruence relation commutes with
addition (by definition)."]
lemma coe_mul (x y : M) : (↑(x * y) : c.quotient) = ↑x * ↑y := rfl
/-- Definition of the function on the quotient by a congruence relation `c` induced by a function
that is constant on `c`'s equivalence classes. -/
@[simp, to_additive "Definition of the function on the quotient by an additive congruence
relation `c` induced by a function that is constant on `c`'s equivalence classes."]
protected lemma lift_on_coe {β} (c : con M) (f : M → β)
(h : ∀ a b, c a b → f a = f b) (x : M) :
con.lift_on (x : c.quotient) f h = f x := rfl
/-- Makes an isomorphism of quotients by two congruence relations, given that the relations are
equal. -/
@[to_additive "Makes an additive isomorphism of quotients by two additive congruence relations,
given that the relations are equal."]
protected def congr {c d : con M} (h : c = d) : c.quotient ≃* d.quotient :=
{ map_mul' := λ x y, by rcases x; rcases y; refl,
..quotient.congr (equiv.refl M) $ by apply ext_iff.2 h }
-- The complete lattice of congruence relations on a type
/-- For congruence relations `c, d` on a type `M` with a multiplication, `c ≤ d` iff `∀ x y ∈ M`,
`x` is related to `y` by `d` if `x` is related to `y` by `c`. -/
@[to_additive "For additive congruence relations `c, d` on a type `M` with an addition, `c ≤ d` iff
`∀ x y ∈ M`, `x` is related to `y` by `d` if `x` is related to `y` by `c`."]
instance : has_le (con M) := ⟨λ c d, ∀ ⦃x y⦄, c x y → d x y⟩
/-- Definition of `≤` for congruence relations. -/
@[to_additive "Definition of `≤` for additive congruence relations."]
theorem le_def {c d : con M} : c ≤ d ↔ ∀ {x y}, c x y → d x y := iff.rfl
/-- The infimum of a set of congruence relations on a given type with a multiplication. -/
@[to_additive "The infimum of a set of additive congruence relations on a given type with
an addition."]
instance : has_Inf (con M) :=
⟨λ S, ⟨λ x y, ∀ c : con M, c ∈ S → c x y,
⟨λ x c hc, c.refl x, λ _ _ h c hc, c.symm $ h c hc,
λ _ _ _ h1 h2 c hc, c.trans (h1 c hc) $ h2 c hc⟩,
λ _ _ _ _ h1 h2 c hc, c.mul (h1 c hc) $ h2 c hc⟩⟩
/-- The infimum of a set of congruence relations is the same as the infimum of the set's image
under the map to the underlying equivalence relation. -/
@[to_additive "The infimum of a set of additive congruence relations is the same as the infimum of
the set's image under the map to the underlying equivalence relation."]
lemma Inf_to_setoid (S : set (con M)) : (Inf S).to_setoid = Inf (to_setoid '' S) :=
setoid.ext' $ λ x y, ⟨λ h r ⟨c, hS, hr⟩, by rw ←hr; exact h c hS,
λ h c hS, h c.to_setoid ⟨c, hS, rfl⟩⟩
/-- The infimum of a set of congruence relations is the same as the infimum of the set's image
under the map to the underlying binary relation. -/
@[to_additive "The infimum of a set of additive congruence relations is the same as the infimum
of the set's image under the map to the underlying binary relation."]
lemma Inf_def (S : set (con M)) : (Inf S).r = Inf (r '' S) :=
by { ext, simp only [Inf_image, infi_apply, infi_Prop_eq], refl }
@[to_additive]
instance : partial_order (con M) :=
{ le := (≤),
lt := λ c d, c ≤ d ∧ ¬d ≤ c,
le_refl := λ c _ _, id,
le_trans := λ c1 c2 c3 h1 h2 x y h, h2 $ h1 h,
lt_iff_le_not_le := λ _ _, iff.rfl,
le_antisymm := λ c d hc hd, ext $ λ x y, ⟨λ h, hc h, λ h, hd h⟩ }
/-- The complete lattice of congruence relations on a given type with a multiplication. -/
@[to_additive "The complete lattice of additive congruence relations on a given type with
an addition."]
instance : complete_lattice (con M) :=
{ inf := λ c d, ⟨(c.to_setoid ⊓ d.to_setoid).1, (c.to_setoid ⊓ d.to_setoid).2,
λ _ _ _ _ h1 h2, ⟨c.mul h1.1 h2.1, d.mul h1.2 h2.2⟩⟩,
inf_le_left := λ _ _ _ _ h, h.1,
inf_le_right := λ _ _ _ _ h, h.2,
le_inf := λ _ _ _ hb hc _ _ h, ⟨hb h, hc h⟩,
top := { mul' := by tauto, ..setoid.complete_lattice.top},
le_top := λ _ _ _ h, trivial,
bot := { mul' := λ _ _ _ _ h1 h2, h1 ▸ h2 ▸ rfl, ..setoid.complete_lattice.bot},
bot_le := λ c x y h, h ▸ c.refl x,
.. complete_lattice_of_Inf (con M) $ assume s,
⟨λ r hr x y h, (h : ∀ r ∈ s, (r : con M) x y) r hr, λ r hr x y h r' hr', hr hr' h⟩ }
/-- The infimum of two congruence relations equals the infimum of the underlying binary
operations. -/
@[to_additive "The infimum of two additive congruence relations equals the infimum of the
underlying binary operations."]
lemma inf_def {c d : con M} : (c ⊓ d).r = c.r ⊓ d.r := rfl
/-- Definition of the infimum of two congruence relations. -/
@[to_additive "Definition of the infimum of two additive congruence relations."]
theorem inf_iff_and {c d : con M} {x y} : (c ⊓ d) x y ↔ c x y ∧ d x y := iff.rfl
/-- The inductively defined smallest congruence relation containing a binary relation `r` equals
the infimum of the set of congruence relations containing `r`. -/
@[to_additive add_con_gen_eq "The inductively defined smallest additive congruence relation
containing a binary relation `r` equals the infimum of the set of additive congruence relations
containing `r`."]
theorem con_gen_eq (r : M → M → Prop) :
con_gen r = Inf {s : con M | ∀ x y, r x y → s x y} :=
le_antisymm
(λ x y H, con_gen.rel.rec_on H (λ _ _ h _ hs, hs _ _ h) (con.refl _) (λ _ _ _, con.symm _)
(λ _ _ _ _ _, con.trans _)
$ λ w x y z _ _ h1 h2 c hc, c.mul (h1 c hc) $ h2 c hc)
(Inf_le (λ _ _, con_gen.rel.of _ _))
/-- The smallest congruence relation containing a binary relation `r` is contained in any
congruence relation containing `r`. -/
@[to_additive add_con_gen_le "The smallest additive congruence relation containing a binary
relation `r` is contained in any additive congruence relation containing `r`."]
theorem con_gen_le {r : M → M → Prop} {c : con M} (h : ∀ x y, r x y → c.r x y) :
con_gen r ≤ c :=
by rw con_gen_eq; exact Inf_le h
/-- Given binary relations `r, s` with `r` contained in `s`, the smallest congruence relation
containing `s` contains the smallest congruence relation containing `r`. -/
@[to_additive add_con_gen_mono "Given binary relations `r, s` with `r` contained in `s`, the
smallest additive congruence relation containing `s` contains the smallest additive congruence
relation containing `r`."]
theorem con_gen_mono {r s : M → M → Prop} (h : ∀ x y, r x y → s x y) :
con_gen r ≤ con_gen s :=
con_gen_le $ λ x y hr, con_gen.rel.of _ _ $ h x y hr
/-- Congruence relations equal the smallest congruence relation in which they are contained. -/
@[simp, to_additive add_con_gen_of_add_con "Additive congruence relations equal the smallest
additive congruence relation in which they are contained."]
lemma con_gen_of_con (c : con M) : con_gen c = c :=
le_antisymm (by rw con_gen_eq; exact Inf_le (λ _ _, id)) con_gen.rel.of
/-- The map sending a binary relation to the smallest congruence relation in which it is
contained is idempotent. -/
@[simp, to_additive add_con_gen_idem "The map sending a binary relation to the smallest additive
congruence relation in which it is contained is idempotent."]
lemma con_gen_idem (r : M → M → Prop) :
con_gen (con_gen r) = con_gen r :=
con_gen_of_con _
/-- The supremum of congruence relations `c, d` equals the smallest congruence relation containing
the binary relation '`x` is related to `y` by `c` or `d`'. -/
@[to_additive sup_eq_add_con_gen "The supremum of additive congruence relations `c, d` equals the
smallest additive congruence relation containing the binary relation '`x` is related to `y`
by `c` or `d`'."]
lemma sup_eq_con_gen (c d : con M) :
c ⊔ d = con_gen (λ x y, c x y ∨ d x y) :=
begin
rw con_gen_eq,
apply congr_arg Inf,
simp only [le_def, or_imp_distrib, ← forall_and_distrib]
end
/-- The supremum of two congruence relations equals the smallest congruence relation containing
the supremum of the underlying binary operations. -/
@[to_additive "The supremum of two additive congruence relations equals the smallest additive
congruence relation containing the supremum of the underlying binary operations."]
lemma sup_def {c d : con M} : c ⊔ d = con_gen (c.r ⊔ d.r) :=
by rw sup_eq_con_gen; refl
/-- The supremum of a set of congruence relations `S` equals the smallest congruence relation
containing the binary relation 'there exists `c ∈ S` such that `x` is related to `y` by
`c`'. -/
@[to_additive Sup_eq_add_con_gen "The supremum of a set of additive congruence relations `S` equals
the smallest additive congruence relation containing the binary relation 'there exists `c ∈ S`
such that `x` is related to `y` by `c`'."]
lemma Sup_eq_con_gen (S : set (con M)) :
Sup S = con_gen (λ x y, ∃ c : con M, c ∈ S ∧ c x y) :=
begin
rw con_gen_eq,
apply congr_arg Inf,
ext,
exact ⟨λ h _ _ ⟨r, hr⟩, h hr.1 hr.2,
λ h r hS _ _ hr, h _ _ ⟨r, hS, hr⟩⟩,
end
/-- The supremum of a set of congruence relations is the same as the smallest congruence relation
containing the supremum of the set's image under the map to the underlying binary relation. -/
@[to_additive "The supremum of a set of additive congruence relations is the same as the smallest
additive congruence relation containing the supremum of the set's image under the map to the
underlying binary relation."]
lemma Sup_def {S : set (con M)} : Sup S = con_gen (Sup (r '' S)) :=
begin
rw [Sup_eq_con_gen, Sup_image],
congr' with x y,
simp only [Sup_image, supr_apply, supr_Prop_eq, exists_prop, rel_eq_coe]
end
variables (M)
/-- There is a Galois insertion of congruence relations on a type with a multiplication `M` into
binary relations on `M`. -/
@[to_additive "There is a Galois insertion of additive congruence relations on a type with
an addition `M` into binary relations on `M`."]
protected noncomputable def gi : @galois_insertion (M → M → Prop) (con M) _ _ con_gen r :=
{ choice := λ r h, con_gen r,
gc := λ r c, ⟨λ H _ _ h, H $ con_gen.rel.of _ _ h, λ H, con_gen_of_con c ▸ con_gen_mono H⟩,
le_l_u := λ x, (con_gen_of_con x).symm ▸ le_refl x,
choice_eq := λ _ _, rfl }
variables {M} (c)
/-- Given a function `f`, the smallest congruence relation containing the binary relation on `f`'s
image defined by '`x ≈ y` iff the elements of `f⁻¹(x)` are related to the elements of `f⁻¹(y)`
by a congruence relation `c`.' -/
@[to_additive "Given a function `f`, the smallest additive congruence relation containing the
binary relation on `f`'s image defined by '`x ≈ y` iff the elements of `f⁻¹(x)` are related to the
elements of `f⁻¹(y)` by an additive congruence relation `c`.'"]
def map_gen (f : M → N) : con N :=
con_gen $ λ x y, ∃ a b, f a = x ∧ f b = y ∧ c a b
/-- Given a surjective multiplicative-preserving function `f` whose kernel is contained in a
congruence relation `c`, the congruence relation on `f`'s codomain defined by '`x ≈ y` iff the
elements of `f⁻¹(x)` are related to the elements of `f⁻¹(y)` by `c`.' -/
@[to_additive "Given a surjective addition-preserving function `f` whose kernel is contained in
an additive congruence relation `c`, the additive congruence relation on `f`'s codomain defined
by '`x ≈ y` iff the elements of `f⁻¹(x)` are related to the elements of `f⁻¹(y)` by `c`.'"]
def map_of_surjective (f : M → N) (H : ∀ x y, f (x * y) = f x * f y) (h : mul_ker f H ≤ c)
(hf : surjective f) : con N :=
{ mul' := λ w x y z ⟨a, b, hw, hx, h1⟩ ⟨p, q, hy, hz, h2⟩,
⟨a * p, b * q, by rw [H, hw, hy], by rw [H, hx, hz], c.mul h1 h2⟩,
..c.to_setoid.map_of_surjective f h hf }
/-- A specialization of 'the smallest congruence relation containing a congruence relation `c`
equals `c`'. -/
@[to_additive "A specialization of 'the smallest additive congruence relation containing
an additive congruence relation `c` equals `c`'."]
lemma map_of_surjective_eq_map_gen {c : con M} {f : M → N} (H : ∀ x y, f (x * y) = f x * f y)
(h : mul_ker f H ≤ c) (hf : surjective f) :
c.map_gen f = c.map_of_surjective f H h hf :=
by rw ←con_gen_of_con (c.map_of_surjective f H h hf); refl
/-- Given types with multiplications `M, N` and a congruence relation `c` on `N`, a
multiplication-preserving map `f : M → N` induces a congruence relation on `f`'s domain
defined by '`x ≈ y` iff `f(x)` is related to `f(y)` by `c`.' -/
@[to_additive "Given types with additions `M, N` and an additive congruence relation `c` on `N`,
an addition-preserving map `f : M → N` induces an additive congruence relation on `f`'s domain
defined by '`x ≈ y` iff `f(x)` is related to `f(y)` by `c`.' "]
def comap (f : M → N) (H : ∀ x y, f (x * y) = f x * f y) (c : con N) : con M :=
{ mul' := λ w x y z h1 h2, show c (f (w * y)) (f (x * z)), by rw [H, H]; exact c.mul h1 h2,
..c.to_setoid.comap f }
section
open quotient
/-- Given a congruence relation `c` on a type `M` with a multiplication, the order-preserving
bijection between the set of congruence relations containing `c` and the congruence relations
on the quotient of `M` by `c`. -/
@[to_additive "Given an additive congruence relation `c` on a type `M` with an addition,
the order-preserving bijection between the set of additive congruence relations containing `c` and
the additive congruence relations on the quotient of `M` by `c`."]
def correspondence : {d // c ≤ d} ≃o (con c.quotient) :=
{ to_fun := λ d, d.1.map_of_surjective coe _
(by rw mul_ker_mk_eq; exact d.2) $ @exists_rep _ c.to_setoid,
inv_fun := λ d, ⟨comap (coe : M → c.quotient) (λ x y, rfl) d, λ _ _ h,
show d _ _, by rw c.eq.2 h; exact d.refl _ ⟩,
left_inv := λ d, subtype.ext_iff_val.2 $ ext $ λ _ _,
⟨λ h, let ⟨a, b, hx, hy, H⟩ := h in
d.1.trans (d.1.symm $ d.2 $ c.eq.1 hx) $ d.1.trans H $ d.2 $ c.eq.1 hy,
λ h, ⟨_, _, rfl, rfl, h⟩⟩,
right_inv := λ d, let Hm : mul_ker (coe : M → c.quotient) (λ x y, rfl) ≤
comap (coe : M → c.quotient) (λ x y, rfl) d :=
λ x y h, show d _ _, by rw mul_ker_mk_eq at h; exact c.eq.2 h ▸ d.refl _ in
ext $ λ x y, ⟨λ h, let ⟨a, b, hx, hy, H⟩ := h in hx ▸ hy ▸ H,
con.induction_on₂ x y $ λ w z h, ⟨w, z, rfl, rfl, h⟩⟩,
map_rel_iff' := λ s t, ⟨λ h _ _ hs, let ⟨a, b, hx, hy, ht⟩ := h ⟨_, _, rfl, rfl, hs⟩ in
t.1.trans (t.1.symm $ t.2 $ eq_rel.1 hx) $ t.1.trans ht $ t.2 $ eq_rel.1 hy,
λ h _ _ hs, let ⟨a, b, hx, hy, Hs⟩ := hs in ⟨a, b, hx, hy, h Hs⟩⟩ }
end
end
section mul_one_class
variables {M} [mul_one_class M] [mul_one_class N] [mul_one_class P] (c : con M)
/-- The quotient of a monoid by a congruence relation is a monoid. -/
@[to_additive "The quotient of an `add_monoid` by an additive congruence relation is
an `add_monoid`."]
instance mul_one_class : mul_one_class c.quotient :=
{ one := ((1 : M) : c.quotient),
mul := (*),
mul_one := λ x, quotient.induction_on' x $ λ _, congr_arg coe $ mul_one _,
one_mul := λ x, quotient.induction_on' x $ λ _, congr_arg coe $ one_mul _ }
variables {c}
/-- The 1 of the quotient of a monoid by a congruence relation is the equivalence class of the
monoid's 1. -/
@[simp, to_additive "The 0 of the quotient of an `add_monoid` by an additive congruence relation
is the equivalence class of the `add_monoid`'s 0."]
lemma coe_one : ((1 : M) : c.quotient) = 1 := rfl
variables (M c)
/-- The submonoid of `M × M` defined by a congruence relation on a monoid `M`. -/
@[to_additive "The `add_submonoid` of `M × M` defined by an additive congruence
relation on an `add_monoid` `M`."]
protected def submonoid : submonoid (M × M) :=
{ carrier := { x | c x.1 x.2 },
one_mem' := c.iseqv.1 1,
mul_mem' := λ _ _, c.mul }
variables {M c}
/-- The congruence relation on a monoid `M` from a submonoid of `M × M` for which membership
is an equivalence relation. -/
@[to_additive "The additive congruence relation on an `add_monoid` `M` from
an `add_submonoid` of `M × M` for which membership is an equivalence relation."]
def of_submonoid (N : submonoid (M × M)) (H : equivalence (λ x y, (x, y) ∈ N)) : con M :=
{ r := λ x y, (x, y) ∈ N,
iseqv := H,
mul' := λ _ _ _ _, N.mul_mem }
/-- Coercion from a congruence relation `c` on a monoid `M` to the submonoid of `M × M` whose
elements are `(x, y)` such that `x` is related to `y` by `c`. -/
@[to_additive "Coercion from a congruence relation `c` on an `add_monoid` `M`
to the `add_submonoid` of `M × M` whose elements are `(x, y)` such that `x`
is related to `y` by `c`."]
instance to_submonoid : has_coe (con M) (submonoid (M × M)) := ⟨λ c, c.submonoid M⟩
@[to_additive] lemma mem_coe {c : con M} {x y} :
(x, y) ∈ (↑c : submonoid (M × M)) ↔ (x, y) ∈ c := iff.rfl
@[to_additive]
theorem to_submonoid_inj (c d : con M) (H : (c : submonoid (M × M)) = d) : c = d :=
ext $ λ x y, show (x, y) ∈ (c : submonoid (M × M)) ↔ (x, y) ∈ ↑d, by rw H
@[to_additive]
lemma le_iff {c d : con M} : c ≤ d ↔ (c : submonoid (M × M)) ≤ d :=
⟨λ h x H, h H, λ h x y hc, h $ show (x, y) ∈ c, from hc⟩
/-- The kernel of a monoid homomorphism as a congruence relation. -/
@[to_additive "The kernel of an `add_monoid` homomorphism as an additive congruence relation."]
def ker (f : M →* P) : con M := mul_ker f f.3
/-- The definition of the congruence relation defined by a monoid homomorphism's kernel. -/
@[to_additive "The definition of the additive congruence relation defined by an `add_monoid`
homomorphism's kernel."]
lemma ker_rel (f : M →* P) {x y} : ker f x y ↔ f x = f y := iff.rfl
/-- There exists an element of the quotient of a monoid by a congruence relation (namely 1). -/
@[to_additive "There exists an element of the quotient of an `add_monoid` by a congruence relation
(namely 0)."]
instance quotient.inhabited : inhabited c.quotient := ⟨((1 : M) : c.quotient)⟩
variables (c)
/-- The natural homomorphism from a monoid to its quotient by a congruence relation. -/
@[to_additive "The natural homomorphism from an `add_monoid` to its quotient by an additive
congruence relation."]
def mk' : M →* c.quotient := ⟨coe, rfl, λ _ _, rfl⟩
variables (x y : M)
/-- The kernel of the natural homomorphism from a monoid to its quotient by a congruence
relation `c` equals `c`. -/
@[simp, to_additive "The kernel of the natural homomorphism from an `add_monoid` to its quotient by
an additive congruence relation `c` equals `c`."]
lemma mk'_ker : ker c.mk' = c := ext $ λ _ _, c.eq
variables {c}
/-- The natural homomorphism from a monoid to its quotient by a congruence relation is
surjective. -/
@[to_additive "The natural homomorphism from an `add_monoid` to its quotient by a congruence
relation is surjective."]
lemma mk'_surjective : surjective c.mk' :=
λ x, by rcases x; exact ⟨x, rfl⟩
@[simp, to_additive] lemma comp_mk'_apply (g : c.quotient →* P) {x} :
g.comp c.mk' x = g x := rfl
/-- The elements related to `x ∈ M`, `M` a monoid, by the kernel of a monoid homomorphism are
those in the preimage of `f(x)` under `f`. -/
@[to_additive "The elements related to `x ∈ M`, `M` an `add_monoid`, by the kernel of
an `add_monoid` homomorphism are those in the preimage of `f(x)` under `f`. "]
lemma ker_apply_eq_preimage {f : M →* P} (x) : (ker f) x = f ⁻¹' {f x} :=
set.ext $ λ x,
⟨λ h, set.mem_preimage.2 $ set.mem_singleton_iff.2 h.symm,
λ h, (set.mem_singleton_iff.1 $ set.mem_preimage.1 h).symm⟩
/-- Given a monoid homomorphism `f : N → M` and a congruence relation `c` on `M`, the congruence
relation induced on `N` by `f` equals the kernel of `c`'s quotient homomorphism composed with
`f`. -/
@[to_additive "Given an `add_monoid` homomorphism `f : N → M` and an additive congruence relation
`c` on `M`, the additive congruence relation induced on `N` by `f` equals the kernel of `c`'s
quotient homomorphism composed with `f`."]
lemma comap_eq {f : N →* M} : comap f f.map_mul c = ker (c.mk'.comp f) :=
ext $ λ x y, show c _ _ ↔ c.mk' _ = c.mk' _, by rw ←c.eq; refl
variables (c) (f : M →* P)
/-- The homomorphism on the quotient of a monoid by a congruence relation `c` induced by a
homomorphism constant on `c`'s equivalence classes. -/
@[to_additive "The homomorphism on the quotient of an `add_monoid` by an additive congruence
relation `c` induced by a homomorphism constant on `c`'s equivalence classes."]
def lift (H : c ≤ ker f) : c.quotient →* P :=
{ to_fun := λ x, con.lift_on x f $ λ _ _ h, H h,
map_one' := by rw ←f.map_one; refl,
map_mul' := λ x y, con.induction_on₂ x y $ λ m n, f.map_mul m n ▸ rfl }
variables {c f}
/-- The diagram describing the universal property for quotients of monoids commutes. -/
@[simp, to_additive "The diagram describing the universal property for quotients of `add_monoid`s
commutes."]
lemma lift_mk' (H : c ≤ ker f) (x) :
c.lift f H (c.mk' x) = f x := rfl
/-- The diagram describing the universal property for quotients of monoids commutes. -/
@[simp, to_additive "The diagram describing the universal property for quotients of `add_monoid`s
commutes."]
lemma lift_coe (H : c ≤ ker f) (x : M) :
c.lift f H x = f x := rfl
/-- The diagram describing the universal property for quotients of monoids commutes. -/
@[simp, to_additive "The diagram describing the universal property for quotients of `add_monoid`s
commutes."]
theorem lift_comp_mk' (H : c ≤ ker f) :
(c.lift f H).comp c.mk' = f := by ext; refl
/-- Given a homomorphism `f` from the quotient of a monoid by a congruence relation, `f` equals the
homomorphism on the quotient induced by `f` composed with the natural map from the monoid to
the quotient. -/
@[simp, to_additive "Given a homomorphism `f` from the quotient of an `add_monoid` by an additive
congruence relation, `f` equals the homomorphism on the quotient induced by `f` composed with the
natural map from the `add_monoid` to the quotient."]
lemma lift_apply_mk' (f : c.quotient →* P) :
c.lift (f.comp c.mk') (λ x y h, show f ↑x = f ↑y, by rw c.eq.2 h) = f :=
by ext; rcases x; refl
/-- Homomorphisms on the quotient of a monoid by a congruence relation are equal if they
are equal on elements that are coercions from the monoid. -/
@[to_additive "Homomorphisms on the quotient of an `add_monoid` by an additive congruence relation
are equal if they are equal on elements that are coercions from the `add_monoid`."]
lemma lift_funext (f g : c.quotient →* P) (h : ∀ a : M, f a = g a) : f = g :=
begin
rw [←lift_apply_mk' f, ←lift_apply_mk' g],
congr' 1,
exact monoid_hom.ext_iff.2 h,
end
/-- The uniqueness part of the universal property for quotients of monoids. -/
@[to_additive "The uniqueness part of the universal property for quotients of `add_monoid`s."]
theorem lift_unique (H : c ≤ ker f) (g : c.quotient →* P)
(Hg : g.comp c.mk' = f) : g = c.lift f H :=
lift_funext g (c.lift f H) $ λ x, by rw [lift_coe H, ←comp_mk'_apply, Hg]
/-- Given a congruence relation `c` on a monoid and a homomorphism `f` constant on `c`'s
equivalence classes, `f` has the same image as the homomorphism that `f` induces on the
quotient. -/
@[to_additive "Given an additive congruence relation `c` on an `add_monoid` and a homomorphism `f`
constant on `c`'s equivalence classes, `f` has the same image as the homomorphism that `f` induces
on the quotient."]
theorem lift_range (H : c ≤ ker f) : (c.lift f H).mrange = f.mrange :=
submonoid.ext $ λ x, ⟨by rintros ⟨⟨y⟩, hy⟩; exact ⟨y, hy⟩, λ ⟨y, hy⟩, ⟨↑y, hy⟩⟩
/-- Surjective monoid homomorphisms constant on a congruence relation `c`'s equivalence classes
induce a surjective homomorphism on `c`'s quotient. -/
@[to_additive "Surjective `add_monoid` homomorphisms constant on an additive congruence
relation `c`'s equivalence classes induce a surjective homomorphism on `c`'s quotient."]
lemma lift_surjective_of_surjective (h : c ≤ ker f) (hf : surjective f) :
surjective (c.lift f h) :=
λ y, exists.elim (hf y) $ λ w hw, ⟨w, (lift_mk' h w).symm ▸ hw⟩
variables (c f)
/-- Given a monoid homomorphism `f` from `M` to `P`, the kernel of `f` is the unique congruence
relation on `M` whose induced map from the quotient of `M` to `P` is injective. -/
@[to_additive "Given an `add_monoid` homomorphism `f` from `M` to `P`, the kernel of `f`
is the unique additive congruence relation on `M` whose induced map from the quotient of `M`
to `P` is injective."]
lemma ker_eq_lift_of_injective (H : c ≤ ker f) (h : injective (c.lift f H)) :
ker f = c :=
to_setoid_inj $ ker_eq_lift_of_injective f H h
variables {c}
/-- The homomorphism induced on the quotient of a monoid by the kernel of a monoid homomorphism. -/
@[to_additive "The homomorphism induced on the quotient of an `add_monoid` by the kernel
of an `add_monoid` homomorphism."]
def ker_lift : (ker f).quotient →* P :=
(ker f).lift f $ λ _ _, id
variables {f}
/-- The diagram described by the universal property for quotients of monoids, when the congruence
relation is the kernel of the homomorphism, commutes. -/
@[simp, to_additive "The diagram described by the universal property for quotients
of `add_monoid`s, when the additive congruence relation is the kernel of the homomorphism,
commutes."]
lemma ker_lift_mk (x : M) : ker_lift f x = f x := rfl
/-- Given a monoid homomorphism `f`, the induced homomorphism on the quotient by `f`'s kernel has
the same image as `f`. -/
@[simp, to_additive "Given an `add_monoid` homomorphism `f`, the induced homomorphism
on the quotient by `f`'s kernel has the same image as `f`."]
lemma ker_lift_range_eq : (ker_lift f).mrange = f.mrange :=
lift_range $ λ _ _, id
/-- A monoid homomorphism `f` induces an injective homomorphism on the quotient by `f`'s kernel. -/
@[to_additive "An `add_monoid` homomorphism `f` induces an injective homomorphism on the quotient
by `f`'s kernel."]
lemma ker_lift_injective (f : M →* P) : injective (ker_lift f) :=
λ x y, quotient.induction_on₂' x y $ λ _ _, (ker f).eq.2
/-- Given congruence relations `c, d` on a monoid such that `d` contains `c`, `d`'s quotient
map induces a homomorphism from the quotient by `c` to the quotient by `d`. -/
@[to_additive "Given additive congruence relations `c, d` on an `add_monoid` such that `d`
contains `c`, `d`'s quotient map induces a homomorphism from the quotient by `c` to the quotient
by `d`."]
def map (c d : con M) (h : c ≤ d) : c.quotient →* d.quotient :=
c.lift d.mk' $ λ x y hc, show (ker d.mk') x y, from
(mk'_ker d).symm ▸ h hc
/-- Given congruence relations `c, d` on a monoid such that `d` contains `c`, the definition of
the homomorphism from the quotient by `c` to the quotient by `d` induced by `d`'s quotient
map. -/
@[to_additive "Given additive congruence relations `c, d` on an `add_monoid` such that `d`
contains `c`, the definition of the homomorphism from the quotient by `c` to the quotient by `d`
induced by `d`'s quotient map."]
lemma map_apply {c d : con M} (h : c ≤ d) (x) :
c.map d h x = c.lift d.mk' (λ x y hc, d.eq.2 $ h hc) x := rfl
variables (c)
/-- The first isomorphism theorem for monoids. -/
@[to_additive "The first isomorphism theorem for `add_monoid`s."]
noncomputable def quotient_ker_equiv_range (f : M →* P) : (ker f).quotient ≃* f.mrange :=
{ map_mul' := monoid_hom.map_mul _,
..equiv.of_bijective
((@mul_equiv.to_monoid_hom (ker_lift f).mrange _ _ _
$ mul_equiv.submonoid_congr ker_lift_range_eq).comp (ker_lift f).mrange_restrict) $
(equiv.bijective _).comp
⟨λ x y h, ker_lift_injective f $ by rcases x; rcases y; injections,
λ ⟨w, z, hz⟩, ⟨z, by rcases hz; rcases _x; refl⟩⟩ }
/-- The first isomorphism theorem for monoids in the case of a homomorphism with right inverse. -/
@[to_additive "The first isomorphism theorem for `add_monoid`s in the case of a homomorphism
with right inverse.", simps]
def quotient_ker_equiv_of_right_inverse (f : M →* P) (g : P → M)
(hf : function.right_inverse g f) :
(ker f).quotient ≃* P :=
{ to_fun := ker_lift f,
inv_fun := coe ∘ g,
left_inv := λ x, ker_lift_injective _ (by rw [function.comp_app, ker_lift_mk, hf]),
right_inv := hf,
.. ker_lift f }
/-- The first isomorphism theorem for monoids in the case of a surjective homomorphism.
For a `computable` version, see `con.quotient_ker_equiv_of_right_inverse`.
-/
@[to_additive "The first isomorphism theorem for `add_monoid`s in the case of a surjective
homomorphism.
For a `computable` version, see `add_con.quotient_ker_equiv_of_right_inverse`.
"]
noncomputable def quotient_ker_equiv_of_surjective (f : M →* P) (hf : surjective f) :
(ker f).quotient ≃* P :=
quotient_ker_equiv_of_right_inverse _ _ hf.has_right_inverse.some_spec
/-- The second isomorphism theorem for monoids. -/
@[to_additive "The second isomorphism theorem for `add_monoid`s."]
noncomputable def comap_quotient_equiv (f : N →* M) :
(comap f f.map_mul c).quotient ≃* (c.mk'.comp f).mrange :=
(con.congr comap_eq).trans $ quotient_ker_equiv_range $ c.mk'.comp f
/-- The third isomorphism theorem for monoids. -/
@[to_additive "The third isomorphism theorem for `add_monoid`s."]
def quotient_quotient_equiv_quotient (c d : con M) (h : c ≤ d) :
(ker (c.map d h)).quotient ≃* d.quotient :=
{ map_mul' := λ x y, con.induction_on₂ x y $ λ w z, con.induction_on₂ w z $ λ a b,
show _ = d.mk' a * d.mk' b, by rw ←d.mk'.map_mul; refl,
..quotient_quotient_equiv_quotient c.to_setoid d.to_setoid h }
end mul_one_class
section monoids
/-- The quotient of a monoid by a congruence relation is a monoid. -/
@[to_additive "The quotient of an `add_monoid` by an additive congruence relation is
an `add_monoid`."]
instance monoid {M : Type*} [monoid M] (c : con M): monoid c.quotient :=
{ one := ((1 : M) : c.quotient),
mul := (*),
mul_assoc := λ x y z, quotient.induction_on₃' x y z
$ λ _ _ _, congr_arg coe $ mul_assoc _ _ _,
.. c.mul_one_class }
/-- The quotient of a `comm_monoid` by a congruence relation is a `comm_monoid`. -/
@[to_additive "The quotient of an `add_comm_monoid` by an additive congruence
relation is an `add_comm_monoid`."]
instance comm_monoid {M : Type*} [comm_monoid M] (c : con M) :
comm_monoid c.quotient :=
{ mul_comm := λ x y, con.induction_on₂ x y $ λ w z, by rw [←coe_mul, ←coe_mul, mul_comm],
..c.monoid}
end monoids
section groups
variables {M} [group M] [group N] [group P] (c : con M)
/-- Multiplicative congruence relations preserve inversion. -/
@[to_additive "Additive congruence relations preserve negation."]
protected lemma inv : ∀ {w x}, c w x → c w⁻¹ x⁻¹ :=
λ x y h, by simpa using c.symm (c.mul (c.mul (c.refl x⁻¹) h) (c.refl y⁻¹))
/-- The inversion induced on the quotient by a congruence relation on a type with a
inversion. -/
@[to_additive "The negation induced on the quotient by an additive congruence relation on a type
with an negation."]
instance has_inv : has_inv c.quotient :=
⟨λ x, quotient.lift_on' x (λ w, ((w⁻¹ : M) : c.quotient))
$ λ x y h, c.eq.2 $ c.inv h⟩
/-- The quotient of a group by a congruence relation is a group. -/
@[to_additive "The quotient of an `add_group` by an additive congruence relation is
an `add_group`."]
instance group : group c.quotient :=
{ inv := λ x, x⁻¹,
mul_left_inv := λ x, show x⁻¹ * x = 1,
from quotient.induction_on' x $ λ _, congr_arg coe $ mul_left_inv _,
.. con.monoid c}
end groups
end con
|
1417b6a2ead032b4670c53af25a6b4f9e531e5b7
|
8c95816d6379a6864848d68ce735a5700c1cbbc3
|
/src/smt2/builder.lean
|
35cf7eadbeb6334f5db46060f658bdc429e3975b
|
[
"Apache-2.0"
] |
permissive
|
aqjune/smt2_interface
|
f00ed0a4317d7c9112deb0806c8e89e6512a901e
|
598848a7a6fa47520fadcfe1b16891053a296084
|
refs/heads/master
| 1,631,518,664,718
| 1,524,489,340,000
| 1,524,489,340,000
| 115,204,811
| 0
| 0
| null | 1,514,043,428,000
| 1,514,043,427,000
| null |
UTF-8
|
Lean
| false
| false
| 4,850
|
lean
|
import .syntax
@[reducible] def smt2.builder :=
except_t string (state (list smt2.cmd))
instance smt2.builder.monad : monad smt2.builder :=
by apply_instance
meta def smt2.builder.to_format {α : Type} (build : smt2.builder α) : format :=
format.join $ list.intersperse "\n" $ (list.map to_fmt $ (build.run.run []).snd).reverse
meta def smt2.builder.run {α : Type} (build : smt2.builder α) : (except string α × list smt2.cmd) :=
state_t.run (except_t.run build) []
def smt2.builder.fail {α : Type} : string → smt2.builder α :=
fun msg, except_t.mk (state_t.mk (fun s, (except.error msg, s)))
meta instance (α : Type) : has_to_format (smt2.builder α) :=
⟨ smt2.builder.to_format ⟩
namespace smt2
namespace builder
def equals (t u : term) : term :=
term.apply "=" [t, u]
def not (t : term) : term :=
term.apply "not" [t]
def implies (t u : term) : term :=
term.apply "implies" [t, u]
def forallq (sym : symbol) (s : sort) (t : term) : term :=
term.forallq [(sym, s)] t
def and (ts : list term) : term :=
term.apply "and" ts
def and2 (t u : term) : term :=
and [t, u]
def or (ts : list term) : term :=
term.apply "or" ts
def or2 (t u : term) : term :=
or [t, u]
def xor (ts : list term) : term :=
term.apply "xor" ts
def xor2 (t u : term) : term :=
xor [t, u]
def iff (t u : term) : term :=
term.apply "iff" [t, u]
def lt (t u : term) : term :=
term.apply "<" [t, u]
def lte (t u : term) : term :=
term.apply "<=" [t, u]
def gt (t u : term) : term :=
term.apply ">" [t, u]
def gte (t u : term) : term :=
term.apply ">=" [t, u]
def add (t u : term) : term :=
term.apply "+" [t, u]
def sub (t u : term) : term :=
term.apply "-" [t, u]
def mul (t u : term) : term :=
term.apply "*" [t, u]
def div (t u : term) : term :=
term.apply "div" [t, u]
def mod (t u : term) : term :=
term.apply "mod" [t, u]
def neg (t : term) : term :=
term.apply "-" [t]
def ite (c t f : term) : term :=
term.apply "ite" [c, t, f]
def int_const (i : int) : term :=
term.const $ special_constant.number i
-- Begin bitvec operations
def bv_const (bitwidth:nat) (i : int) : term :=
term.const $ special_constant.bitvec bitwidth i
def bv_add (t u : term) : term :=
term.apply "bvadd" [t, u]
def bv_sub (t u : term) : term :=
term.apply "bvsub" [t, u]
def bv_mul (t u : term) : term :=
term.apply "bvmul" [t, u]
def bv_udiv (t u : term) : term :=
term.apply "bvudiv" [t, u]
def bv_sdiv (t u : term) : term :=
term.apply "bvsdiv" [t, u]
def bv_urem (t u : term) : term :=
term.apply "bvurem" [t, u]
def bv_smod (t u : term) : term :=
term.apply "bvsmod" [t, u]
def bv_srem (t u : term) : term :=
term.apply "bvsrem" [t, u]
def bv_or (t u : term) : term :=
term.apply "bvor" [t, u]
def bv_and (t u : term) : term :=
term.apply "bvand" [t, u]
def bv_xor (t u : term) : term :=
term.apply "bvxor" [t, u]
def bv_shl (t u : term) : term :=
term.apply "bvshl" [t, u]
def bv_lshr (t u : term) : term :=
term.apply "bvlshr" [t, u]
def bv_ashr (t u : term) : term :=
term.apply "bvashr" [t, u]
def bv_sle (t u : term) : term :=
term.apply "bvsle" [t, u]
def bv_slt (t u : term) : term :=
term.apply "bvslt" [t, u]
def bv_ule (t u : term) : term :=
term.apply "bvule" [t, u]
def bv_ult (t u : term) : term :=
term.apply "bvult" [t, u]
def bv_zext (bitsz : nat) (t : term) : term :=
term.apply2 (term.apply "_"
[term.qual_id "zero_extend", term.const bitsz])
[t]
def bv_sext (bitsz : nat) (t : term) : term :=
term.apply2 (term.apply "_"
[term.qual_id "sign_extend", term.const bitsz])
[t]
def bv_extract (upper lower : nat) (t : term) : term :=
term.apply2 (term.apply "_" [term.qual_id "extract",
term.const ↑upper, term.const ↑lower])
[t]
-- End bitvec operations
def put {σ:Type} {m:Type → Type} [monad m] : σ → state_t σ m unit :=
λ s', ⟨λ s, return (unit.star, s')⟩
def add_command (c : cmd) : builder unit := do
cs ← except_t.lift get,
except_t.lift $ put (c :: cs)
def echo (msg : string) : builder unit :=
add_command (cmd.echo msg)
def check_sat : builder unit :=
add_command cmd.check_sat
def pop (n : nat) : builder unit :=
add_command $ cmd.pop n
def push (n : nat) : builder unit :=
add_command $ cmd.push n
def scope {α} (level : nat) (action : builder α) : builder α :=
do push level,
res ← action,
pop level,
return res
def assert (t : term) : builder unit :=
add_command $ cmd.assert_cmd t
def reset : builder unit :=
add_command cmd.reset
def exit' : builder unit :=
add_command cmd.exit_cmd
def declare_const (sym : string) (s : sort) : builder unit :=
add_command $ cmd.declare_const sym s
def declare_fun (sym : string) (ps : list sort) (ret : sort) : builder unit :=
add_command $ cmd.declare_fun sym ps ret
def declare_sort (sym : string) (arity : nat) : builder unit :=
add_command $ cmd.declare_sort sym arity
end builder
end smt2
|
8db321321ba66d834b3bdc9d9d28bb1430f3b73b
|
74addaa0e41490cbaf2abd313a764c96df57b05d
|
/Mathlib/data/mv_polynomial/comap.lean
|
d7e2f2437108584231d8a239e1458b5481c81c00
|
[] |
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
| 3,594
|
lean
|
/-
Copyright (c) 2020 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.data.mv_polynomial.rename
import Mathlib.PostPort
universes u_1 u_2 u_4 u_3
namespace Mathlib
/-!
# `comap` operation on `mv_polynomial`
This file defines the `comap` function on `mv_polynomial`.
`mv_polynomial.comap` is a low-tech example of a map of "algebraic varieties," modulo the fact that
`mathlib` does not yet define varieties.
## Notation
As in other polynomial files, we typically use the notation:
+ `σ : Type*` (indexing the variables)
+ `R : Type*` `[comm_semiring R]` (the coefficients)
-/
namespace mv_polynomial
/--
Given an algebra hom `f : mv_polynomial σ R →ₐ[R] mv_polynomial τ R`
and a variable evaluation `v : τ → R`,
`comap f v` produces a variable evaluation `σ → R`.
-/
def comap {σ : Type u_1} {τ : Type u_2} {R : Type u_4} [comm_semiring R] (f : alg_hom R (mv_polynomial σ R) (mv_polynomial τ R)) : (τ → R) → σ → R :=
fun (x : τ → R) (i : σ) => coe_fn (aeval x) (coe_fn f (X i))
@[simp] theorem comap_apply {σ : Type u_1} {τ : Type u_2} {R : Type u_4} [comm_semiring R] (f : alg_hom R (mv_polynomial σ R) (mv_polynomial τ R)) (x : τ → R) (i : σ) : comap f x i = coe_fn (aeval x) (coe_fn f (X i)) :=
rfl
@[simp] theorem comap_id_apply {σ : Type u_1} {R : Type u_4} [comm_semiring R] (x : σ → R) : comap (alg_hom.id R (mv_polynomial σ R)) x = x := sorry
theorem comap_id (σ : Type u_1) (R : Type u_4) [comm_semiring R] : comap (alg_hom.id R (mv_polynomial σ R)) = id :=
funext fun (x : σ → R) => comap_id_apply x
theorem comap_comp_apply {σ : Type u_1} {τ : Type u_2} {υ : Type u_3} {R : Type u_4} [comm_semiring R] (f : alg_hom R (mv_polynomial σ R) (mv_polynomial τ R)) (g : alg_hom R (mv_polynomial τ R) (mv_polynomial υ R)) (x : υ → R) : comap (alg_hom.comp g f) x = comap f (comap g x) := sorry
theorem comap_comp {σ : Type u_1} {τ : Type u_2} {υ : Type u_3} {R : Type u_4} [comm_semiring R] (f : alg_hom R (mv_polynomial σ R) (mv_polynomial τ R)) (g : alg_hom R (mv_polynomial τ R) (mv_polynomial υ R)) : comap (alg_hom.comp g f) = comap f ∘ comap g :=
funext fun (x : υ → R) => comap_comp_apply f g x
theorem comap_eq_id_of_eq_id {σ : Type u_1} {R : Type u_4} [comm_semiring R] (f : alg_hom R (mv_polynomial σ R) (mv_polynomial σ R)) (hf : ∀ (φ : mv_polynomial σ R), coe_fn f φ = φ) (x : σ → R) : comap f x = x := sorry
theorem comap_rename {σ : Type u_1} {τ : Type u_2} {R : Type u_4} [comm_semiring R] (f : σ → τ) (x : τ → R) : comap (rename f) x = x ∘ f := sorry
/--
If two polynomial types over the same coefficient ring `R` are equivalent,
there is a bijection between the types of functions from their variable types to `R`.
-/
def comap_equiv {σ : Type u_1} {τ : Type u_2} {R : Type u_4} [comm_semiring R] (f : alg_equiv R (mv_polynomial σ R) (mv_polynomial τ R)) : (τ → R) ≃ (σ → R) :=
equiv.mk (comap ↑f) (comap ↑(alg_equiv.symm f)) sorry sorry
@[simp] theorem comap_equiv_coe {σ : Type u_1} {τ : Type u_2} {R : Type u_4} [comm_semiring R] (f : alg_equiv R (mv_polynomial σ R) (mv_polynomial τ R)) : ⇑(comap_equiv f) = comap ↑f :=
rfl
@[simp] theorem comap_equiv_symm_coe {σ : Type u_1} {τ : Type u_2} {R : Type u_4} [comm_semiring R] (f : alg_equiv R (mv_polynomial σ R) (mv_polynomial τ R)) : ⇑(equiv.symm (comap_equiv f)) = comap ↑(alg_equiv.symm f) :=
rfl
|
f0c3ef413abd1f2e6baa9b70d9e401768168e10b
|
b2fe74b11b57d362c13326bc5651244f111fa6f4
|
/src/data/real/nnreal.lean
|
827598b3225bf1a3f8ee89d44917133de238a90d
|
[
"Apache-2.0"
] |
permissive
|
midfield/mathlib
|
c4db5fa898b5ac8f2f80ae0d00c95eb6f745f4c7
|
775edc615ecec631d65b6180dbcc7bc26c3abc26
|
refs/heads/master
| 1,675,330,551,921
| 1,608,304,514,000
| 1,608,304,514,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 29,177
|
lean
|
/-
Copyright (c) 2018 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin
-/
import algebra.linear_ordered_comm_group_with_zero
import algebra.big_operators.ring
import data.real.basic
import data.indicator_function
/-!
# Nonnegative real numbers
In this file we define `nnreal` (notation: `ℝ≥0`) to be the type of non-negative real numbers,
a.k.a. the interval `[0, ∞)`. We also define the following operations and structures on `ℝ≥0`:
* the order on `ℝ≥0` is the restriction of the order on `ℝ`; these relations define a conditionally
complete linear order with a bottom element, `conditionally_complete_linear_order_bot`;
* `a + b` and `a * b` are the restrictions of addition and multiplication of real numbers to `ℝ≥0`;
these operations together with `0 = ⟨0, _⟩` and `1 = ⟨1, _⟩` turn `ℝ≥0` into a linear ordered
archimedean commutative semifield; we have no typeclass for this in `mathlib` yet, so we define
the following instances instead:
- `linear_ordered_semiring ℝ≥0`;
- `comm_semiring ℝ≥0`;
- `canonically_ordered_comm_semiring ℝ≥0`;
- `linear_ordered_comm_group_with_zero ℝ≥0`;
- `archimedean ℝ≥0`.
* `nnreal.of_real x` is defined as `⟨max x 0, _⟩`, i.e. `↑(nnreal.of_real x) = x` when `0 ≤ x` and
`↑(nnreal.of_real x) = 0` otherwise.
We also define an instance `can_lift ℝ ℝ≥0`. This instance can be used by the `lift` tactic to
replace `x : ℝ` and `hx : 0 ≤ x` in the proof context with `x : ℝ≥0` while replacing all occurences
of `x` with `↑x`. This tactic also works for a function `f : α → ℝ` with a hypothesis
`hf : ∀ x, 0 ≤ f x`.
## Notations
This file defines `ℝ≥0` as a localized notation for `nnreal`.
-/
noncomputable theory
open_locale classical big_operators
/-- 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 : ℝ≥0) : n.val = n := rfl
instance : can_lift ℝ ℝ≥0 :=
{ coe := coe,
cond := λ r, 0 ≤ r,
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
/-- Reinterpret a real number `r` as a non-negative real number. Returns `0` if `r < 0`. -/
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 : ℝ≥0) : (0 : ℝ) ≤ r := r.2
@[norm_cast]
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_le ℝ≥0 := ⟨λ r s, (r:ℝ) ≤ s⟩
instance : has_bot ℝ≥0 := ⟨0⟩
instance : inhabited ℝ≥0 := ⟨0⟩
protected lemma injective_coe : function.injective (coe : ℝ≥0 → ℝ) := subtype.coe_injective
@[simp, norm_cast] protected lemma coe_eq {r₁ r₂ : ℝ≥0} : (r₁ : ℝ) = r₂ ↔ r₁ = r₂ :=
nnreal.injective_coe.eq_iff
@[simp, norm_cast] protected lemma coe_zero : ((0 : ℝ≥0) : ℝ) = 0 := rfl
@[simp, norm_cast] protected lemma coe_one : ((1 : ℝ≥0) : ℝ) = 1 := rfl
@[simp, norm_cast] protected lemma coe_add (r₁ r₂ : ℝ≥0) : ((r₁ + r₂ : ℝ≥0) : ℝ) = r₁ + r₂ := rfl
@[simp, norm_cast] protected lemma coe_mul (r₁ r₂ : ℝ≥0) : ((r₁ * r₂ : ℝ≥0) : ℝ) = r₁ * r₂ := rfl
@[simp, norm_cast] protected lemma coe_inv (r : ℝ≥0) : ((r⁻¹ : ℝ≥0) : ℝ) = r⁻¹ := rfl
@[simp, norm_cast] protected lemma coe_bit0 (r : ℝ≥0) : ((bit0 r : ℝ≥0) : ℝ) = bit0 r := rfl
@[simp, norm_cast] protected lemma coe_bit1 (r : ℝ≥0) : ((bit1 r : ℝ≥0) : ℝ) = bit1 r := rfl
@[simp, norm_cast] 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 coe_eq_zero (r : ℝ≥0) : ↑r = (0 : ℝ) ↔ r = 0 := by norm_cast
lemma coe_ne_zero {r : ℝ≥0} : (r : ℝ) ≠ 0 ↔ r ≠ 0 := by norm_cast
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
/-- Coercion `ℝ≥0 → ℝ` as a `ring_hom`. -/
def to_real_hom : ℝ≥0 →+* ℝ :=
⟨coe, nnreal.coe_one, nnreal.coe_mul, nnreal.coe_zero, nnreal.coe_add⟩
@[simp] lemma coe_to_real_hom : ⇑to_real_hom = coe := rfl
instance : comm_group_with_zero ℝ≥0 :=
{ exists_pair_ne := ⟨0, 1, assume h, zero_ne_one $ nnreal.eq_iff.2 h⟩,
inv_zero := nnreal.eq $ show (0⁻¹ : ℝ) = 0, from 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),
.. (_ : semiring ℝ≥0) }
@[simp, norm_cast] lemma coe_indicator {α} (s : set α) (f : α → ℝ≥0) (a : α) :
((s.indicator f a : ℝ≥0) : ℝ) = s.indicator (λ x, f x) a :=
(to_real_hom : ℝ≥0 →+ ℝ).map_indicator _ _ _
@[simp, norm_cast] protected lemma coe_div (r₁ r₂ : ℝ≥0) : ((r₁ / r₂ : ℝ≥0) : ℝ) = r₁ / r₂ := rfl
@[norm_cast] lemma coe_pow (r : ℝ≥0) (n : ℕ) : ((r^n : ℝ≥0) : ℝ) = r^n :=
to_real_hom.map_pow r n
@[norm_cast] lemma coe_list_sum (l : list ℝ≥0) :
((l.sum : ℝ≥0) : ℝ) = (l.map coe).sum :=
to_real_hom.map_list_sum l
@[norm_cast] lemma coe_list_prod (l : list ℝ≥0) :
((l.prod : ℝ≥0) : ℝ) = (l.map coe).prod :=
to_real_hom.map_list_prod l
@[norm_cast] lemma coe_multiset_sum (s : multiset ℝ≥0) :
((s.sum : ℝ≥0) : ℝ) = (s.map coe).sum :=
to_real_hom.map_multiset_sum s
@[norm_cast] lemma coe_multiset_prod (s : multiset ℝ≥0) :
((s.prod : ℝ≥0) : ℝ) = (s.map coe).prod :=
to_real_hom.map_multiset_prod s
@[norm_cast] lemma coe_sum {α} {s : finset α} {f : α → ℝ≥0} :
↑(∑ a in s, f a) = ∑ a in s, (f a : ℝ) :=
to_real_hom.map_sum _ _
@[norm_cast] lemma coe_prod {α} {s : finset α} {f : α → ℝ≥0} :
↑(∏ a in s, f a) = ∏ a in s, (f a : ℝ) :=
to_real_hom.map_prod _ _
@[norm_cast] lemma nsmul_coe (r : ℝ≥0) (n : ℕ) : ↑(n •ℕ r) = n •ℕ (r:ℝ) :=
to_real_hom.to_add_monoid_hom.map_nsmul _ _
@[simp, norm_cast] protected lemma coe_nat_cast (n : ℕ) : (↑(↑n : ℝ≥0) : ℝ) = n :=
to_real_hom.map_nat_cast n
instance : linear_order ℝ≥0 :=
linear_order.lift (coe : ℝ≥0 → ℝ) nnreal.injective_coe
@[simp, norm_cast] protected lemma coe_le_coe {r₁ r₂ : ℝ≥0} : (r₁ : ℝ) ≤ r₂ ↔ r₁ ≤ r₂ := iff.rfl
@[simp, norm_cast] protected lemma coe_lt_coe {r₁ r₂ : ℝ≥0} : (r₁ : ℝ) < r₂ ↔ r₁ < r₂ := iff.rfl
@[simp, norm_cast] protected lemma coe_pos {r : ℝ≥0} : (0 : ℝ) < r ↔ 0 < r := iff.rfl
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.linear_order }
instance : canonically_ordered_add_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.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_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_le_one := @zero_le_one ℝ _,
exists_pair_ne := ⟨0, 1, ne_of_lt (@zero_lt_one ℝ _ _)⟩,
.. nnreal.linear_order,
.. nnreal.canonically_ordered_add_monoid,
.. nnreal.comm_semiring, }
instance : linear_ordered_comm_group_with_zero ℝ≥0 :=
{ mul_le_mul_left := assume a b h c, mul_le_mul (le_refl c) h (zero_le a) (zero_le c),
zero_le_one := zero_le 1,
.. nnreal.linear_ordered_semiring,
.. nnreal.comm_group_with_zero }
instance : canonically_ordered_comm_semiring ℝ≥0 :=
{ .. nnreal.canonically_ordered_add_monoid,
.. nnreal.comm_semiring,
.. (show no_zero_divisors ℝ≥0, by apply_instance),
.. nnreal.comm_group_with_zero }
instance : densely_ordered ℝ≥0 :=
⟨assume a b (h : (a : ℝ) < b), let ⟨c, hac, hcb⟩ := exists_between 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 : ℝ≥0 → ℝ) '' 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 : ℝ≥0 → ℝ) '' s) :=
⟨0, assume r ⟨q, _, eq⟩, eq ▸ q.2⟩
instance : has_Sup ℝ≥0 :=
⟨λs, ⟨Sup ((coe : ℝ≥0 → ℝ) '' 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 : ℝ≥0 → ℝ) '' 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 ℝ≥0) : (↑(Sup s) : ℝ) = Sup ((coe : ℝ≥0 → ℝ) '' s) := rfl
lemma coe_Inf (s : set ℝ≥0) : (↑(Inf s) : ℝ) = Inf ((coe : ℝ≥0 → ℝ) '' 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 : ℝ≥0 → ℝ) '' 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 : ℝ≥0 → ℝ) '' 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_linear_order,
.. nnreal.order_bot }
instance : archimedean ℝ≥0 :=
⟨ assume x y pos_y,
let ⟨n, hr⟩ := archimedean.arch (x:ℝ) (pos_y : (0 : ℝ) < y) in
⟨n, show (x:ℝ) ≤ (n •ℕ y : ℝ≥0), by simp [*, -nsmul_eq_mul, nsmul_coe]⟩ ⟩
lemma le_of_forall_epsilon_le {a b : ℝ≥0} (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 : ℝ≥0) :
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 : (⊥ : ℝ≥0) = 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, norm_cast] lemma coe_max (x y : ℝ≥0) :
((max x y : ℝ≥0) : ℝ) = max (x : ℝ) (y : ℝ) :=
by { delta max, split_ifs; refl }
@[simp, norm_cast] lemma coe_min (x y : ℝ≥0) :
((min x y : ℝ≥0) : ℝ) = min (x : ℝ) (y : ℝ) :=
by { delta min, split_ifs; refl }
section of_real
@[simp] lemma zero_le_coe {q : ℝ≥0} : 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 : ℝ≥0} : nnreal.of_real r ≤ p ↔ r ≤ ↑p :=
nnreal.gi.gc r p
lemma le_of_real_iff_coe_le {r : ℝ≥0} {p : ℝ} (hp : 0 ≤ p) : r ≤ nnreal.of_real p ↔ ↑r ≤ p :=
by rw [← nnreal.coe_le_coe, nnreal.coe_of_real p hp]
lemma le_of_real_iff_coe_le' {r : ℝ≥0} {p : ℝ} (hr : 0 < r) : r ≤ nnreal.of_real p ↔ ↑r ≤ p :=
(le_or_lt 0 p).elim le_of_real_iff_coe_le $ λ hp,
by simp only [(hp.trans_le r.coe_nonneg).not_le, of_real_eq_zero.2 hp.le, hr.not_le]
lemma of_real_lt_iff_lt_coe {r : ℝ} {p : ℝ≥0} (ha : 0 ≤ r) : 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 : ℝ≥0} {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 : ℝ≥0} (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 mul_left_cancel' (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,
simp [nnreal.of_real, hp, hq, max_eq_left, mul_nonneg] },
{ 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 : ℝ≥0} (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 : ℝ≥0} : 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 : ℝ≥0} : 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 : ℝ≥0} : (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 : ℝ≥0} : (r + p) - r = p :=
by rw [add_comm, add_sub_cancel]
@[simp] lemma sub_add_cancel_of_le {a b : ℝ≥0} (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 : ℝ≥0} : p < q - r ↔ p + r < q :=
begin
split,
{ assume H,
have : (((q - r) : ℝ≥0) : ℝ) = (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
lemma sub_lt_iff_lt_add {a b c : ℝ≥0} (h : b ≤ a) : a - b < c ↔ a < b + c :=
by simp only [←nnreal.coe_lt_coe, nnreal.coe_sub h, nnreal.coe_add, sub_lt_iff_lt_add']
lemma sub_eq_iff_eq_add {a b c : ℝ≥0} (h : b ≤ a) : a - b = c ↔ a = c + b :=
by rw [←nnreal.eq_iff, nnreal.coe_sub h, ←nnreal.eq_iff, nnreal.coe_add, sub_eq_iff_eq_add]
end sub
section inv
lemma div_def {r p : ℝ≥0} : r / p = r * p⁻¹ := rfl
lemma sum_div {ι} (s : finset ι) (f : ι → ℝ≥0) (b : ℝ≥0) :
(∑ i in s, f i) / b = ∑ i in s, (f i / b) :=
by simp only [nnreal.div_def, finset.sum_mul]
@[simp] lemma inv_zero : (0 : ℝ≥0)⁻¹ = 0 := nnreal.eq inv_zero
@[simp] lemma inv_eq_zero {r : ℝ≥0} : (r : ℝ≥0)⁻¹ = 0 ↔ r = 0 :=
inv_eq_zero
@[simp] lemma inv_pos {r : ℝ≥0} : 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_rev' _ _
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
lemma div_self_le (r : ℝ≥0) : r / r ≤ 1 :=
if h : r = 0 then by simp [h] else by rw [div_self h]
@[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 div_le_iff {a b r : ℝ≥0} (hr : r ≠ 0) : a / r ≤ b ↔ a ≤ b * r :=
@div_le_iff ℝ _ a r b $ zero_lt_iff_ne_zero.2 hr
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 (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
lemma of_real_inv {x : ℝ} :
nnreal.of_real x⁻¹ = (nnreal.of_real x)⁻¹ :=
begin
by_cases hx : 0 ≤ x,
{ nth_rewrite 0 ← coe_of_real x hx,
rw [←nnreal.coe_inv, of_real_coe], },
{ have hx' := le_of_not_ge hx,
rw [of_real_eq_zero.mpr hx', inv_zero, of_real_eq_zero.mpr (inv_nonpos.mpr hx')], },
end
lemma of_real_div {x y : ℝ} (hx : 0 ≤ x) :
nnreal.of_real (x / y) = nnreal.of_real x / nnreal.of_real y :=
by rw [div_def, ←of_real_inv, ←of_real_mul hx, div_eq_mul_inv]
lemma of_real_div' {x y : ℝ} (hy : 0 ≤ y) :
nnreal.of_real (x / y) = nnreal.of_real x / nnreal.of_real y :=
by rw [div_def, ←of_real_inv, mul_comm, ←@of_real_mul y⁻¹ _ (by simp [hy]), mul_comm,
div_eq_mul_inv]
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
@[simp] lemma abs_eq (x : ℝ≥0) : abs (x : ℝ) = x :=
abs_of_nonneg x.property
end nnreal
/-- The absolute value on `ℝ` as a map to `ℝ≥0`. -/
@[pp_nodot] def real.nnabs (x : ℝ) : ℝ≥0 := ⟨abs x, abs_nonneg x⟩
@[norm_cast, simp] lemma nnreal.coe_nnabs (x : ℝ) : (real.nnabs x : ℝ) = abs x :=
by simp [real.nnabs]
|
269b79f0b381fc0adaec0d93a6264faea8be24bc
|
ac2987d8c7832fb4a87edb6bee26141facbb6fa0
|
/Mathlib/Algebra/Group/Basic.lean
|
435990243a3d75111ef216c0f83864a32928770f
|
[
"Apache-2.0"
] |
permissive
|
AurelienSaue/mathlib4
|
52204b9bd9d207c922fe0cf3397166728bb6c2e2
|
84271fe0875bafdaa88ac41f1b5a7c18151bd0d5
|
refs/heads/master
| 1,689,156,096,545
| 1,629,378,840,000
| 1,629,378,840,000
| 389,648,603
| 0
| 0
|
Apache-2.0
| 1,627,307,284,000
| 1,627,307,284,000
| null |
UTF-8
|
Lean
| false
| false
| 1,397
|
lean
|
import Mathlib.Algebra.Group.Defs
import Mathlib.Logic.Basic
section AddCommSemigroup_lemmas
variable {A : Type u} [AddCommSemigroup A]
lemma add_left_comm (a b c : A) : a + (b + c) = b + (a + c) :=
by rw [← add_assoc, add_comm a, add_assoc]
lemma add_right_comm (a b c : A) : a + b + c = a + c + b :=
by rw [add_assoc, add_comm b, add_assoc]
theorem add_add_add_comm (a b c d : A) : (a + b) +(c + d) = (a + c) + (b + d) :=
by simp [add_left_comm, add_assoc]
end AddCommSemigroup_lemmas
section CommSemigroup_lemmas
variable {M : Type u} [CommSemigroup M]
lemma mul_left_comm (a b c : M) : a * (b * c) = b * (a * c) :=
by rw [← mul_assoc, mul_comm a, mul_assoc]
-- Funky Lean 3 proof of the above:
--left_comm has_mul.mul mul_comm mul_assoc
lemma mul_right_comm (a b c : M) : a * b * c = a * c * b :=
by rw [mul_assoc, mul_comm b c, mul_assoc]
theorem mul_mul_mul_comm (a b c d : M) : (a * b) * (c * d) = (a * c) * (b * d) :=
by simp [mul_assoc, mul_left_comm]
end CommSemigroup_lemmas
section AddLeftCancelMonoid_lemmas
-- too lazy to do mul versions and right versions
variable {A : Type u} [AddMonoid A] [IsAddLeftCancel A] {a b : A}
lemma add_right_eq_self : a + b = a ↔ b = 0 :=
by rw [←add_left_cancel_iff (c := 0), add_zero]
lemma self_eq_add_right : a = a + b ↔ b = 0 :=
by rw [←add_left_cancel_iff (c := 0), add_zero, eq_comm]
end AddLeftCancelMonoid_lemmas
|
00bc2c5713353dbee573747e55bc66db742e9705
|
bd30ef9a38da5172e55165b5cf19d92706763afa
|
/src/array_perm_group.lean
|
ffbb8132ae9efbe31b7c0c550874bf1a0b15cc9a
|
[] |
no_license
|
kendfrey/rubiks-cube-group
|
8838ce34704d8d150e5feba6f1e536b3d228dd37
|
3baebd73972384294931c75d584a491eb0fbc15c
|
refs/heads/master
| 1,671,557,772,358
| 1,601,554,362,000
| 1,601,554,362,000
| 285,715,961
| 21
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 2,549
|
lean
|
import algebra.group
import data.equiv.basic
import array_group
open equiv
section perm_array
parameters {n : ℕ} {α : Type*}
@[simp] private lemma array.read_def {f : fin n → α} {i : fin n} : array.read { data := f } i = f i := rfl
def perm_array (a : array n α) (p : perm (fin n)) : array n α := ⟨a.read ∘ p.inv_fun⟩
lemma perm_array_def (a : array n α) (p : perm (fin n)) : perm_array a p = ⟨a.read ∘ p.inv_fun⟩ := rfl
@[simp] lemma perm_array_array_one {p : perm (fin n)} [group α] : perm_array 1 p = 1 :=
begin
apply array.ext,
intros i,
refl,
end
@[simp] lemma perm_array_perm_one {a : array n α} : perm_array a 1 = a :=
begin
apply array.ext,
intros i,
refl,
end
@[simp] lemma perm_array_comp {a : array n α} {p₁ p₂ : perm (fin n)} : perm_array (perm_array a p₁) p₂ = perm_array a (p₂ * p₁) :=
begin
apply array.ext,
simp [perm_array_def, perm.mul_def],
end
end perm_array
section
parameters {n : ℕ} {α : Type*} [group α]
def array_perm (n : ℕ) (α : Type*) := array n α × perm (fin n)
@[reducible] private def ap := array_perm n α
variables (a b c : ap)
private def mul : ap := (perm_array a.fst b.snd * b.fst, b.snd * a.snd)
private def inv : ap := (perm_array a.fst⁻¹ a.snd⁻¹, a.snd⁻¹)
instance array_perm.has_mul : has_mul ap := ⟨mul⟩
instance array_perm.has_one : has_one ap := ⟨(mk_array n 1, 1)⟩
instance array_perm.has_inv : has_inv ap := ⟨inv⟩
@[simp] private lemma mul_def : a * b = (perm_array a.fst b.snd * b.fst, b.snd * a.snd) := rfl
@[simp] private lemma one_def : (1 : ap) = (mk_array n 1, 1) := rfl
@[simp] private lemma inv_def : a⁻¹ = (perm_array a.fst⁻¹ a.snd⁻¹, a.snd⁻¹) := rfl
private lemma mul_assoc : a * b * c = a * (b * c) :=
begin
dsimp,
congr' 1,
apply array.ext,
intros i,
simp only [perm_array_def, function.comp, array.read_mul, array.read_def, mul_assoc],
refl,
end
private lemma one_mul : 1 * a = a :=
begin
dsimp,
change (perm_array 1 a.snd * a.fst, a.snd * 1) = a,
rw perm_array_array_one,
simp,
end
private lemma mul_one : a * 1 = a :=
begin
dsimp,
rw perm_array_perm_one,
change (a.fst * 1, 1 * a.snd) = a,
simp,
end
private lemma mul_left_inv : a⁻¹ * a = 1 :=
begin
dsimp,
rw perm_array_comp,
simp,
refl,
end
instance array_perm_group : group ap :=
{
mul := (*),
mul_assoc := mul_assoc,
one := 1,
one_mul := one_mul,
mul_one := mul_one,
inv := has_inv.inv,
mul_left_inv := mul_left_inv,
}
end
|
97f1327d2a386b48e0dd81d8a55266ec6f790e72
|
9be442d9ec2fcf442516ed6e9e1660aa9071b7bd
|
/tests/lean/run/1308.lean
|
86f28e6f18505d767c6e92fc78d63a736c6b0a6e
|
[
"Apache-2.0",
"LLVM-exception",
"NCSA",
"LGPL-3.0-only",
"LicenseRef-scancode-inner-net-2.0",
"BSD-3-Clause",
"LGPL-2.0-or-later",
"Spencer-94",
"LGPL-2.1-or-later",
"HPND",
"LicenseRef-scancode-pcre",
"ISC",
"LGPL-2.1-only",
"LicenseRef-scancode-other-permissive",
"SunPro",
"CMU-Mach"
] |
permissive
|
EdAyers/lean4
|
57ac632d6b0789cb91fab2170e8c9e40441221bd
|
37ba0df5841bde51dbc2329da81ac23d4f6a4de4
|
refs/heads/master
| 1,676,463,245,298
| 1,660,619,433,000
| 1,660,619,433,000
| 183,433,437
| 1
| 0
|
Apache-2.0
| 1,657,612,672,000
| 1,556,196,574,000
|
Lean
|
UTF-8
|
Lean
| false
| false
| 157
|
lean
|
@[defaultInstance high] instance : HPow R Nat R where hPow a _ := a
example (x y : Nat) : (x + y) ^ 3 = x ^ 3 + y ^ 3 + 3 * (x * y ^ 2 + x ^ 2 * y) := sorry
|
bb02b3ad25e947a320d957dd98801c93e3e26d92
|
82b86ba2ae0d5aed0f01f49c46db5afec0eb2bd7
|
/stage0/src/Std/ShareCommon.lean
|
bf35e1f5a9dafde73b708c53d07db4024c27f377
|
[
"Apache-2.0"
] |
permissive
|
banksonian/lean4
|
3a2e6b0f1eb63aa56ff95b8d07b2f851072d54dc
|
78da6b3aa2840693eea354a41e89fc5b212a5011
|
refs/heads/master
| 1,673,703,624,165
| 1,605,123,551,000
| 1,605,123,551,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 6,648
|
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 Std.Data.HashSet
import Std.Data.HashMap
import Std.Data.PersistentHashMap
import Std.Data.PersistentHashSet
namespace Std
universes u v
namespace ShareCommon
/-
The max sharing primitives are implemented internally.
They use maps and sets of Lean objects. We have two versions:
one using `HashMap` and `HashSet`, and another using
`PersistentHashMap` and `PersistentHashSet`.
These maps and sets are "instantiated here using the "unsafe"
primitives `Object.eq`, `Object.hash`, and `ptrAddrUnsafe`. -/
abbrev Object : Type := NonScalar
unsafe def Object.ptrEq (a b : Object) : Bool :=
ptrAddrUnsafe a == ptrAddrUnsafe b
unsafe def Object.ptrHash (a : Object) : USize :=
ptrAddrUnsafe a
@[extern "lean_sharecommon_eq"]
unsafe constant Object.eq (a b : @& Object) : Bool := arbitrary _
@[extern "lean_sharecommon_hash"]
unsafe constant Object.hash (a : @& Object) : USize := arbitrary _
unsafe def ObjectMap : Type := @HashMap Object Object ⟨Object.ptrEq⟩ ⟨Object.ptrHash⟩
unsafe def ObjectSet : Type := @HashSet Object ⟨Object.eq⟩ ⟨Object.hash⟩
unsafe def ObjectPersistentMap : Type := @PersistentHashMap Object Object ⟨Object.ptrEq⟩ ⟨Object.ptrHash⟩
unsafe def ObjectPersistentSet : Type := @PersistentHashSet Object ⟨Object.eq⟩ ⟨Object.hash⟩
@[export lean_mk_object_map]
unsafe def mkObjectMap : Unit → ObjectMap :=
fun _ => @mkHashMap Object Object ⟨Object.ptrEq⟩ ⟨Object.ptrHash⟩ 1024
@[export lean_object_map_find]
unsafe def ObjectMap.find? (m : ObjectMap) (k : Object) : Option Object :=
@HashMap.find? Object Object ⟨Object.ptrEq⟩ ⟨Object.ptrHash⟩ m k
@[export lean_object_map_insert]
unsafe def ObjectMap.insert (m : ObjectMap) (k v : Object) : ObjectMap :=
@HashMap.insert Object Object ⟨Object.ptrEq⟩ ⟨Object.ptrHash⟩ m k v
@[export lean_mk_object_set]
unsafe def mkObjectSet : Unit → ObjectSet :=
fun _ => @mkHashSet Object ⟨Object.eq⟩ ⟨Object.hash⟩ 1024
@[export lean_object_set_find]
unsafe def ObjectSet.find? (s : ObjectSet) (o : Object) : Option Object :=
@HashSet.find? Object ⟨Object.eq⟩ ⟨Object.hash⟩ s o
@[export lean_object_set_insert]
unsafe def ObjectSet.insert (s : ObjectSet) (o : Object) : ObjectSet :=
@HashSet.insert Object ⟨Object.eq⟩ ⟨Object.hash⟩ s o
@[export lean_mk_object_pmap]
unsafe def mkObjectPersistentMap : Unit → ObjectPersistentMap :=
fun _ => @PersistentHashMap.empty Object Object ⟨Object.ptrEq⟩ ⟨Object.ptrHash⟩
@[export lean_object_pmap_find]
unsafe def ObjectPersistentMap.find? (m : ObjectPersistentMap) (k : Object) : Option Object :=
@PersistentHashMap.find? Object Object ⟨Object.ptrEq⟩ ⟨Object.ptrHash⟩ m k
@[export lean_object_pmap_insert]
unsafe def ObjectPersistentMap.insert (m : ObjectPersistentMap) (k v : Object) : ObjectPersistentMap :=
@PersistentHashMap.insert Object Object ⟨Object.ptrEq⟩ ⟨Object.ptrHash⟩ m k v
@[export lean_mk_object_pset]
unsafe def mkObjectPersistentSet : Unit → ObjectPersistentSet :=
fun _ => @PersistentHashSet.empty Object ⟨Object.eq⟩ ⟨Object.hash⟩
@[export lean_object_pset_find]
unsafe def ObjectPersistentSet.find? (s : ObjectPersistentSet) (o : Object) : Option Object :=
@PersistentHashSet.find? Object ⟨Object.eq⟩ ⟨Object.hash⟩ s o
@[export lean_object_pset_insert]
unsafe def ObjectPersistentSet.insert (s : ObjectPersistentSet) (o : Object) : ObjectPersistentSet :=
@PersistentHashSet.insert Object ⟨Object.eq⟩ ⟨Object.hash⟩ s o
/- Internally `State` is implemented as a pair `ObjectMap` and `ObjectSet` -/
constant StatePointed : PointedType := arbitrary _
abbrev State : Type u := StatePointed.type
@[extern "lean_sharecommon_mk_state"]
constant mkState : Unit → State := fun _ => StatePointed.val
def State.empty : State := mkState ()
instance State.inhabited : Inhabited State := ⟨State.empty⟩
/- Internally `PersistentState` is implemented as a pair `ObjectPersistentMap` and `ObjectPersistentSet` -/
constant PersistentStatePointed : PointedType := arbitrary _
abbrev PersistentState : Type u := PersistentStatePointed.type
@[extern "lean_sharecommon_mk_pstate"]
constant mkPersistentState : Unit → PersistentState := fun _ => PersistentStatePointed.val
def PersistentState.empty : PersistentState := mkPersistentState ()
instance PersistentState.inhabited : Inhabited PersistentState := ⟨PersistentState.empty⟩
abbrev PState : Type u := PersistentState
@[extern "lean_state_sharecommon"]
def State.shareCommon {α} (s : State) (a : α) : α × State :=
(a, s)
@[extern "lean_persistent_state_sharecommon"]
def PersistentState.shareCommon {α} (s : PersistentState) (a : α) : α × PersistentState :=
(a, s)
end ShareCommon
class MonadShareCommon (m : Type u → Type v) :=
(withShareCommon {α : Type u} : α → m α)
abbrev withShareCommon := @MonadShareCommon.withShareCommon
abbrev shareCommonM {α : Type u} {m : Type u → Type v} [MonadShareCommon m] (a : α) : m α :=
withShareCommon a
abbrev ShareCommonT (m : Type u → Type v) := StateT ShareCommon.State m
abbrev PShareCommonT (m : Type u → Type v) := StateT ShareCommon.PState m
abbrev ShareCommonM := ShareCommonT Id
abbrev PShareCommonM := PShareCommonT Id
@[specialize] def ShareCommonT.withShareCommon {m : Type u → Type v} [Monad m] {α : Type u} (a : α) : ShareCommonT m α :=
modifyGet $ fun s => s.shareCommon a
@[specialize] def PShareCommonT.withShareCommon {m : Type u → Type v} [Monad m] {α : Type u} (a : α) : PShareCommonT m α :=
modifyGet $ fun s => s.shareCommon a
instance ShareCommonT.monadShareCommon {m : Type u → Type v} [Monad m] : MonadShareCommon (ShareCommonT m) :=
{ withShareCommon := @ShareCommonT.withShareCommon _ _ }
instance PShareCommonT.monadShareCommon {m : Type u → Type v} [Monad m] : MonadShareCommon (PShareCommonT m) :=
{ withShareCommon := @PShareCommonT.withShareCommon _ _ }
@[inline] def ShareCommonT.run {m : Type u → Type v} [Monad m] {α : Type u} (x : ShareCommonT m α) : m α :=
x.run' ShareCommon.State.empty
@[inline] def PShareCommonT.run {m : Type u → Type v} [Monad m] {α : Type u} (x : PShareCommonT m α) : m α :=
x.run' ShareCommon.PersistentState.empty
@[inline] def ShareCommonM.run {α : Type u} (x : ShareCommonM α) : α :=
ShareCommonT.run x
@[inline] def PShareCommonM.run {α : Type u} (x : PShareCommonM α) : α :=
PShareCommonT.run x
def shareCommon {α} (a : α) : α :=
(withShareCommon a : ShareCommonM α).run
end Std
|
9e7a6fa3fbade05f4b31c9f827e37800047239ce
|
acc85b4be2c618b11fc7cb3005521ae6858a8d07
|
/data/seq/seq.lean
|
a46f0f982ec1b8f92f09c91ba5b6a4e6fdac8864
|
[
"Apache-2.0"
] |
permissive
|
linpingchuan/mathlib
|
d49990b236574df2a45d9919ba43c923f693d341
|
5ad8020f67eb13896a41cc7691d072c9331b1f76
|
refs/heads/master
| 1,626,019,377,808
| 1,508,048,784,000
| 1,508,048,784,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 21,998
|
lean
|
import data.stream data.lazy_list data.seq.computation logic.basic
universes u v w
/-
coinductive seq (α : Type u) : Type u
| nil : seq α
| cons : α → seq α → seq α
-/
def seq (α : Type u) : Type u := { f : stream (option α) // ∀ {n}, f n = none → f (n+1) = none }
def seq1 (α) := α × seq α
namespace seq
variables {α : Type u} {β : Type v} {γ : Type w}
def nil : seq α := ⟨stream.const none, λn h, rfl⟩
def cons (a : α) : seq α → seq α
| ⟨f, al⟩ := ⟨some a :: f, λn h, by {cases n with n, contradiction, exact al h}⟩
def nth : seq α → ℕ → option α := subtype.val
def omap (f : β → γ) : option (α × β) → option (α × γ)
| none := none
| (some (a, b)) := some (a, f b)
attribute [simp] omap
def head (s : seq α) : option α := nth s 0
def tail : seq α → seq α
| ⟨f, al⟩ := ⟨f.tail, λ n, al⟩
protected def mem (a : α) (s : seq α) := some a ∈ s.1
instance : has_mem α (seq α) :=
⟨seq.mem⟩
theorem le_stable (s : seq α) {m n} (h : m ≤ n) :
s.1 m = none → s.1 n = none :=
by {cases s with f al, induction h with n h IH, exacts [id, λ h2, al (IH h2)]}
theorem not_mem_nil (a : α) : a ∉ @nil α :=
λ ⟨n, (h : some a = none)⟩, by injection h
theorem mem_cons (a : α) : ∀ (s : seq α), a ∈ cons a s
| ⟨f, al⟩ := stream.mem_cons (some a) _
theorem mem_cons_of_mem (y : α) {a : α} : ∀ {s : seq α}, a ∈ s → a ∈ cons y s
| ⟨f, al⟩ := stream.mem_cons_of_mem (some y)
theorem eq_or_mem_of_mem_cons {a b : α} : ∀ {s : seq α}, a ∈ cons b s → a = b ∨ a ∈ s
| ⟨f, al⟩ h := (stream.eq_or_mem_of_mem_cons h).imp_left (λh, by injection h)
@[simp] theorem mem_cons_iff {a b : α} {s : seq α} : a ∈ cons b s ↔ a = b ∨ a ∈ s :=
⟨eq_or_mem_of_mem_cons, λo, by cases o with e m;
[{rw e, apply mem_cons}, exact mem_cons_of_mem _ m]⟩
def destruct (s : seq α) : option (seq1 α) :=
(λa', (a', s.tail)) <$> nth s 0
theorem destruct_eq_nil {s : seq α} : destruct s = none → s = nil :=
begin
dsimp [destruct],
ginduction nth s 0 with f0; intro h,
{ apply subtype.eq, apply funext,
dsimp [nil], intro n,
induction n with n IH, exacts [f0, s.2 IH] },
{ contradiction }
end
theorem destruct_eq_cons {s : seq α} {a s'} : destruct s = some (a, s') → s = cons a s' :=
begin
dsimp [destruct],
ginduction nth s 0 with f0 a'; intro h,
{ contradiction },
{ unfold has_map.map at h, dsimp [option.map, option.bind] at h,
cases s with f al,
injections with _ h1 h2,
rw ←h2, apply subtype.eq, dsimp [tail, cons],
rw h1 at f0, rw ←f0,
exact (stream.eta f).symm }
end
@[simp] theorem destruct_nil : destruct (nil : seq α) = none := rfl
@[simp] theorem destruct_cons (a : α) : ∀ s, destruct (cons a s) = some (a, s)
| ⟨f, al⟩ := begin
unfold cons destruct has_map.map,
apply congr_arg (λ s, some (a, s)),
apply subtype.eq, dsimp [tail], rw [stream.tail_cons]
end
theorem head_eq_destruct (s : seq α) : head s = prod.fst <$> destruct s :=
by unfold destruct head; cases nth s 0; refl
@[simp] theorem head_nil : head (nil : seq α) = none := rfl
@[simp] theorem head_cons (a : α) (s) : head (cons a s) = some a :=
by rw [head_eq_destruct, destruct_cons]; refl
@[simp] theorem tail_nil : tail (nil : seq α) = nil := rfl
@[simp] theorem tail_cons (a : α) (s) : tail (cons a s) = s :=
by cases s with f al; apply subtype.eq; dsimp [tail, cons]; rw [stream.tail_cons]
def cases_on {C : seq α → Sort v} (s : seq α)
(h1 : C nil) (h2 : ∀ x s, C (cons x s)) : C s := begin
ginduction destruct s with H,
{ rw destruct_eq_nil H, apply h1 },
{ cases a with a s', rw destruct_eq_cons H, apply h2 }
end
theorem mem_rec_on {C : seq α → Prop} {a s} (M : a ∈ s)
(h1 : ∀ b s', (a = b ∨ C s') → C (cons b s')) : C s :=
begin
cases M with k e, unfold stream.nth at e,
induction k with k IH generalizing s,
{ have TH : s = cons a (tail s),
{ apply destruct_eq_cons,
unfold destruct nth has_map.map, rw ←e, refl },
rw TH, apply h1 _ _ (or.inl rfl) },
revert e, apply s.cases_on _ (λ b s', _); intro e,
{ injection e },
{ have h_eq : (cons b s').val (nat.succ k) = s'.val k, { cases s'; refl },
rw [h_eq] at e,
apply h1 _ _ (or.inr (IH e)) }
end
def corec.F (f : β → option (α × β)) : option β → option α × option β
| none := (none, none)
| (some b) := match f b with none := (none, none) | some (a, b') := (some a, some b') end
def corec (f : β → option (α × β)) (b : β) : seq α :=
begin
refine ⟨stream.corec' (corec.F f) (some b), λn h, _⟩,
rw stream.corec'_eq,
change stream.corec' (corec.F f) (corec.F f (some b)).2 n = none,
revert h, generalize : some b = o, revert o,
induction n with n IH; intro o,
{ change (corec.F f o).1 = none → (corec.F f (corec.F f o).2).1 = none,
cases o with b; intro h, { refl },
dsimp [corec.F] at h, dsimp [corec.F],
cases f b with s, { refl },
{ cases s with a b', contradiction } },
{ rw [stream.corec'_eq (corec.F f) (corec.F f o).2,
stream.corec'_eq (corec.F f) o],
exact IH (corec.F f o).2 }
end
@[simp] def corec_eq (f : β → option (α × β)) (b : β) :
destruct (corec f b) = omap (corec f) (f b) :=
begin
dsimp [corec, destruct, nth],
change stream.corec' (corec.F f) (some b) 0 with (corec.F f (some b)).1,
unfold has_map.map, dsimp [corec.F],
ginduction f b with h s, { refl },
cases s with a b', dsimp [corec.F, option.bind],
apply congr_arg (λ b', some (a, b')),
apply subtype.eq,
dsimp [corec, tail],
rw [stream.corec'_eq, stream.tail_cons],
dsimp [corec.F], rw h, refl
end
def of_list (l : list α) : seq α :=
⟨list.nth l, λn h, begin
induction l with a l IH generalizing n, refl,
dsimp [list.nth], cases n with n; dsimp [list.nth] at h,
{ contradiction },
{ apply IH _ h }
end⟩
instance coe_list : has_coe (list α) (seq α) := ⟨of_list⟩
section bisim
variable (R : seq α → seq α → Prop)
local infix ~ := R
def bisim_o : option (seq1 α) → option (seq1 α) → Prop
| none none := true
| (some (a, s)) (some (a', s')) := a = a' ∧ R s s'
| _ _ := false
attribute [simp] bisim_o
def is_bisimulation := ∀ ⦃s₁ s₂⦄, s₁ ~ s₂ → bisim_o R (destruct s₁) (destruct s₂)
-- If two streams are bisimilar, then they are equal
theorem eq_of_bisim (bisim : is_bisimulation R) {s₁ s₂} (r : s₁ ~ s₂) : s₁ = s₂ :=
begin
apply subtype.eq,
apply stream.eq_of_bisim (λx y, ∃ s s' : seq α, s.1 = x ∧ s'.1 = y ∧ R s s'),
dsimp [stream.is_bisimulation],
intros t₁ t₂ e,
exact match t₁, t₂, e with ._, ._, ⟨s, s', rfl, rfl, r⟩ :=
suffices head s = head s' ∧ R (tail s) (tail s'), from
and.imp id (λr, ⟨tail s, tail s',
by cases s; refl, by cases s'; refl, r⟩) this,
begin
have := bisim r, revert r this,
apply cases_on s _ _; intros; apply cases_on s' _ _; intros; intros r this,
{ constructor, refl, assumption },
{ rw [destruct_nil, destruct_cons] at this,
exact false.elim this },
{ rw [destruct_nil, destruct_cons] at this,
exact false.elim this },
{ rw [destruct_cons, destruct_cons] at this,
rw [head_cons, head_cons, tail_cons, tail_cons],
cases this with h1 h2,
constructor, rw h1, exact h2 }
end
end,
exact ⟨s₁, s₂, rfl, rfl, r⟩
end
end bisim
theorem coinduction : ∀ {s₁ s₂ : seq α}, head s₁ = head s₂ →
(∀ (β : Type u) (fr : seq α → β),
fr s₁ = fr s₂ → fr (tail s₁) = fr (tail s₂)) → s₁ = s₂
| ⟨f₁, a₁⟩ ⟨f₂, a₂⟩ hh ht :=
subtype.eq (stream.coinduction hh (λ β fr, ht β (λs, fr s.1)))
theorem coinduction2 (s) (f g : seq α → seq β)
(H : ∀ s, bisim_o (λ (s1 s2 : seq β), ∃ (s : seq α), s1 = f s ∧ s2 = g s)
(destruct (f s)) (destruct (g s)))
: f s = g s :=
begin
refine eq_of_bisim (λ s1 s2, ∃ s, s1 = f s ∧ s2 = g s) _ ⟨s, rfl, rfl⟩,
intros s1 s2 h, cases h with s h, cases h with h1 h2,
rw [h1, h2], apply H
end
def of_stream (s : stream α) : seq α :=
⟨s.map some, λn h, by contradiction⟩
instance coe_stream : has_coe (stream α) (seq α) := ⟨of_stream⟩
def of_lazy_list : lazy_list α → seq α :=
corec (λl, match l with
| lazy_list.nil := none
| lazy_list.cons a l' := some (a, l' ())
end)
instance coe_lazy_list : has_coe (lazy_list α) (seq α) := ⟨of_lazy_list⟩
meta def to_lazy_list : seq α → lazy_list α | s :=
match destruct s with
| none := lazy_list.nil
| some (a, s') := lazy_list.cons a (to_lazy_list s')
end
meta def force_to_list (s : seq α) : list α := (to_lazy_list s).to_list
def append (s₁ s₂ : seq α) : seq α :=
@corec α (seq α × seq α) (λ⟨s₁, s₂⟩,
match destruct s₁ with
| none := omap (λs₂, (nil, s₂)) (destruct s₂)
| some (a, s₁') := some (a, s₁', s₂)
end) (s₁, s₂)
def map (f : α → β) : seq α → seq β | ⟨s, al⟩ :=
⟨s.map (option.map f),
λn, begin
dsimp [stream.map, stream.nth],
ginduction s n with e; intro,
{ rw al e, assumption }, { contradiction }
end⟩
def join : seq (seq1 α) → seq α :=
corec (λS, match destruct S with
| none := none
| some ((a, s), S') := some (a, match destruct s with
| none := S'
| some s' := cons s' S'
end)
end)
def drop (s : seq α) : ℕ → seq α
| 0 := s
| (n+1) := tail (drop n)
attribute [simp] drop
def take : ℕ → seq α → list α
| 0 s := []
| (n+1) s := match destruct s with
| none := []
| some (x, r) := list.cons x (take n r)
end
def split_at : ℕ → seq α → list α × seq α
| 0 s := ([], s)
| (n+1) s := match destruct s with
| none := ([], nil)
| some (x, s') := let (l, r) := split_at n s' in (list.cons x l, r)
end
def zip_with (f : α → β → γ) : seq α → seq β → seq γ
| ⟨f₁, a₁⟩ ⟨f₂, a₂⟩ := ⟨λn,
match f₁ n, f₂ n with
| some a, some b := some (f a b)
| _, _ := none
end,
λn, begin
ginduction f₁ n with h1,
{ intro H, rw a₁ h1, refl },
ginduction f₂ n with h2; dsimp [seq.zip_with._match_1]; intro H,
{ rw a₂ h2, cases f₁ (n + 1); refl },
{ contradiction }
end⟩
def zip : seq α → seq β → seq (α × β) := zip_with prod.mk
def unzip (s : seq (α × β)) : seq α × seq β := (map prod.fst s, map prod.snd s)
def to_list (s : seq α) (h : ∃ n, ¬ (nth s n).is_some) : list α :=
take (nat.find h) s
def to_stream (s : seq α) (h : ∀ n, (nth s n).is_some) : stream α :=
λn, option.get (h n)
def to_list_or_stream (s : seq α) [decidable (∃ n, ¬ (nth s n).is_some)] :
list α ⊕ stream α :=
if h : ∃ n, ¬ (nth s n).is_some
then sum.inl (to_list s h)
else sum.inr (to_stream s (λn, decidable.by_contradiction (λ hn, h ⟨n, hn⟩)))
@[simp] theorem nil_append (s : seq α) : append nil s = s :=
begin
apply coinduction2, intro s,
dsimp [append], rw [corec_eq],
dsimp [append], apply cases_on s _ _,
{ trivial },
{ intros x s,
rw [destruct_cons], dsimp,
exact ⟨rfl, s, rfl, rfl⟩ }
end
@[simp] theorem cons_append (a : α) (s t) : append (cons a s) t = cons a (append s t) :=
destruct_eq_cons $ begin
dsimp [append], rw [corec_eq],
dsimp [append], rw [destruct_cons],
dsimp [append], refl
end
@[simp] theorem append_nil (s : seq α) : append s nil = s :=
begin
apply coinduction2 s, intro s,
apply cases_on s _ _,
{ trivial },
{ intros x s,
rw [cons_append, destruct_cons, destruct_cons], dsimp,
exact ⟨rfl, s, rfl, rfl⟩ }
end
@[simp] theorem append_assoc (s t u : seq α) :
append (append s t) u = append s (append t u) :=
begin
apply eq_of_bisim (λs1 s2, ∃ s t u,
s1 = append (append s t) u ∧ s2 = append s (append t u)),
{ intros s1 s2 h, exact match s1, s2, h with ._, ._, ⟨s, t, u, rfl, rfl⟩ := begin
apply cases_on s; simp,
{ apply cases_on t; simp,
{ apply cases_on u; simp,
{ intros x u, refine ⟨nil, nil, u, _, _⟩; simp } },
{ intros x t, refine ⟨nil, t, u, _, _⟩; simp } },
{ intros x s, exact ⟨s, t, u, rfl, rfl⟩ }
end end },
{ exact ⟨s, t, u, rfl, rfl⟩ }
end
@[simp] theorem map_nil (f : α → β) : map f nil = nil := rfl
@[simp] theorem map_cons (f : α → β) (a) : ∀ s, map f (cons a s) = cons (f a) (map f s)
| ⟨s, al⟩ := by apply subtype.eq; dsimp [cons, map]; rw stream.map_cons; refl
@[simp] theorem map_id : ∀ (s : seq α), map id s = s
| ⟨s, al⟩ := begin
apply subtype.eq; dsimp [map],
rw [option.map_id, stream.map_id]; refl
end
@[simp] theorem map_tail (f : α → β) : ∀ s, map f (tail s) = tail (map f s)
| ⟨s, al⟩ := by apply subtype.eq; dsimp [tail, map]; rw stream.map_tail; refl
theorem map_comp (f : α → β) (g : β → γ) : ∀ (s : seq α), map (g ∘ f) s = map g (map f s)
| ⟨s, al⟩ := begin
apply subtype.eq; dsimp [map],
rw stream.map_map,
apply congr_arg (λ f : _ → option γ, stream.map f s),
apply funext, intro, cases x with x; refl
end
@[simp] theorem map_append (f : α → β) (s t) : map f (append s t) = append (map f s) (map f t) :=
begin
apply eq_of_bisim (λs1 s2, ∃ s t,
s1 = map f (append s t) ∧ s2 = append (map f s) (map f t)) _ ⟨s, t, rfl, rfl⟩,
intros s1 s2 h, exact match s1, s2, h with ._, ._, ⟨s, t, rfl, rfl⟩ := begin
apply cases_on s; simp,
{ apply cases_on t; simp,
{ intros x t, refine ⟨nil, t, _, _⟩; simp } },
{ intros x s, refine ⟨s, t, rfl, rfl⟩ }
end end
end
@[simp] theorem map_nth (f : α → β) : ∀ s n, nth (map f s) n = (nth s n).map f
| ⟨s, al⟩ n := rfl
instance : functor seq :=
{ map := @map, id_map := @map_id, map_comp := @map_comp }
@[simp] theorem join_nil : join nil = (nil : seq α) := destruct_eq_nil rfl
@[simp] theorem join_cons_nil (a : α) (S) :
join (cons (a, nil) S) = cons a (join S) :=
destruct_eq_cons $ by simp [join]
@[simp] theorem join_cons_cons (a b : α) (s S) :
join (cons (a, cons b s) S) = cons a (join (cons (b, s) S)) :=
destruct_eq_cons $ by simp [join]
@[simp] theorem join_cons (a : α) (s S) :
join (cons (a, s) S) = cons a (append s (join S)) :=
begin
apply eq_of_bisim (λs1 s2, s1 = s2 ∨
∃ a s S, s1 = join (cons (a, s) S) ∧
s2 = cons a (append s (join S))) _ (or.inr ⟨a, s, S, rfl, rfl⟩),
intros s1 s2 h,
exact match s1, s2, h with
| _, _, (or.inl $ eq.refl s) := begin
apply cases_on s, { trivial },
{ intros x s, rw [destruct_cons], exact ⟨rfl, or.inl rfl⟩ }
end
| ._, ._, (or.inr ⟨a, s, S, rfl, rfl⟩) := begin
apply cases_on s,
{ simp },
{ intros x s, simp, refine or.inr ⟨x, s, S, rfl, rfl⟩ }
end
end
end
@[simp] theorem join_append (S T : seq (seq1 α)) :
join (append S T) = append (join S) (join T) :=
begin
apply eq_of_bisim (λs1 s2, ∃ s S T,
s1 = append s (join (append S T)) ∧
s2 = append s (append (join S) (join T))),
{ intros s1 s2 h, exact match s1, s2, h with ._, ._, ⟨s, S, T, rfl, rfl⟩ := begin
apply cases_on s; simp,
{ apply cases_on S; simp,
{ apply cases_on T, { simp },
{ intros s T, cases s with a s; simp,
refine ⟨s, nil, T, _, _⟩; simp } },
{ intros s S, cases s with a s; simp,
exact ⟨s, S, T, rfl, rfl⟩ } },
{ intros x s, exact ⟨s, S, T, rfl, rfl⟩ }
end end },
{ refine ⟨nil, S, T, _, _⟩; simp }
end
@[simp] def of_list_nil : of_list [] = (nil : seq α) := rfl
@[simp] def of_list_cons (a : α) (l) :
of_list (a :: l) = cons a (of_list l) :=
begin
apply subtype.eq, simp [of_list, cons],
apply funext, intro n, cases n; simp [list.nth, stream.cons]
end
@[simp] def of_stream_cons (a : α) (s) :
of_stream (a :: s) = cons a (of_stream s) :=
by apply subtype.eq; simp [of_stream, cons]; rw stream.map_cons
@[simp] def of_list_append (l l' : list α) :
of_list (l ++ l') = append (of_list l) (of_list l') :=
by induction l; simp [*]
@[simp] def of_stream_append (l : list α) (s : stream α) :
of_stream (l ++ₛ s) = append (of_list l) (of_stream s) :=
by induction l; simp [*, stream.nil_append_stream, stream.cons_append_stream]
def to_list' {α} (s : seq α) : computation (list α) :=
@computation.corec (list α) (list α × seq α) (λ⟨l, s⟩,
match destruct s with
| none := sum.inl l.reverse
| some (a, s') := sum.inr (a::l, s')
end) ([], s)
theorem dropn_add (s : seq α) (m) : ∀ n, drop s (m + n) = drop (drop s m) n
| 0 := rfl
| (n+1) := congr_arg tail (dropn_add n)
theorem dropn_tail (s : seq α) (n) : drop (tail s) n = drop s (n + 1) :=
by rw add_comm; symmetry; apply dropn_add
theorem nth_tail : ∀ (s : seq α) n, nth (tail s) n = nth s (n + 1)
| ⟨f, al⟩ n := rfl
@[simp] theorem head_dropn (s : seq α) (n) : head (drop s n) = nth s n :=
begin
induction n with n IH generalizing s, { refl },
rw [nat.succ_eq_add_one, ←nth_tail, ←dropn_tail], apply IH
end
theorem mem_map (f : α → β) {a : α} : ∀ {s : seq α}, a ∈ s → f a ∈ map f s
| ⟨g, al⟩ := stream.mem_map (option.map f)
theorem exists_of_mem_map {f} {b : β} : ∀ {s : seq α}, b ∈ map f s → ∃ a, a ∈ s ∧ f a = b
| ⟨g, al⟩ h := let ⟨o, om, oe⟩ := stream.exists_of_mem_map h in
by cases o; injection oe with h'; exact ⟨a, om, h'⟩
def of_mem_append {s₁ s₂ : seq α} {a : α} (h : a ∈ append s₁ s₂) : a ∈ s₁ ∨ a ∈ s₂ :=
begin
have := h, revert this,
generalize e : append s₁ s₂ = ss, intro h, revert s₁,
apply mem_rec_on h _,
intros b s' o s₁,
apply s₁.cases_on _ (λ c t₁, _); intros m e;
have := congr_arg destruct e; simp at this; injections with i1 i2 i3,
{ simp at m, exact or.inr m },
{ simp at m, cases m with e' m,
{ rw e', exact or.inl (mem_cons _ _) },
{ rw i2, cases o with e' IH,
{ rw e', exact or.inl (mem_cons _ _) },
{ exact or.imp_left (mem_cons_of_mem _) (IH m i3) } } }
end
def mem_append_left {s₁ s₂ : seq α} {a : α} (h : a ∈ s₁) : a ∈ append s₁ s₂ :=
by apply mem_rec_on h; intros; simp [*]
end seq
namespace seq1
variables {α : Type u} {β : Type v} {γ : Type w}
open seq
def to_seq : seq1 α → seq α
| (a, s) := cons a s
instance coe_seq : has_coe (seq1 α) (seq α) := ⟨to_seq⟩
def map (f : α → β) : seq1 α → seq1 β
| (a, s) := (f a, seq.map f s)
theorem map_id : ∀ (s : seq1 α), map id s = s | ⟨a, s⟩ := by simp [map]
def join : seq1 (seq1 α) → seq1 α
| ((a, s), S) := match destruct s with
| none := (a, seq.join S)
| some s' := (a, seq.join (cons s' S))
end
@[simp] theorem join_nil (a : α) (S) : join ((a, nil), S) = (a, seq.join S) := rfl
@[simp] theorem join_cons (a b : α) (s S) :
join ((a, cons b s), S) = (a, seq.join (cons (b, s) S)) :=
by dsimp [join]; rw [destruct_cons]; refl
def ret (a : α) : seq1 α := (a, nil)
def bind (s : seq1 α) (f : α → seq1 β) : seq1 β :=
join (map f s)
@[simp] theorem join_map_ret (s : seq α) : seq.join (seq.map ret s) = s :=
by apply coinduction2 s; intro s; apply cases_on s; simp [ret]
@[simp] theorem bind_ret (f : α → β) : ∀ s, bind s (ret ∘ f) = map f s
| ⟨a, s⟩ := begin
dsimp [bind, map], change (λx, ret (f x)) with (ret ∘ f),
rw [map_comp], simp [function.comp, ret]
end
@[simp] theorem ret_bind (a : α) (f : α → seq1 β) : bind (ret a) f = f a :=
begin
simp [ret, bind, map],
cases f a with a s,
apply cases_on s; intros; simp
end
@[simp] theorem map_join' (f : α → β) (S) :
seq.map f (seq.join S) = seq.join (seq.map (map f) S) :=
begin
apply eq_of_bisim (λs1 s2,
∃ s S, s1 = append s (seq.map f (seq.join S)) ∧
s2 = append s (seq.join (seq.map (map f) S))),
{ intros s1 s2 h, exact match s1, s2, h with ._, ._, ⟨s, S, rfl, rfl⟩ := begin
apply cases_on s; simp,
{ apply cases_on S; simp,
{ intros x S, cases x with a s; simp [map],
exact ⟨_, _, rfl, rfl⟩ } },
{ intros x s, refine ⟨s, S, rfl, rfl⟩ }
end end },
{ refine ⟨nil, S, _, _⟩; simp }
end
@[simp] theorem map_join (f : α → β) : ∀ S, map f (join S) = join (map (map f) S)
| ((a, s), S) := by apply cases_on s; intros; simp [map]
@[simp] theorem join_join (SS : seq (seq1 (seq1 α))) :
seq.join (seq.join SS) = seq.join (seq.map join SS) :=
begin
apply eq_of_bisim (λs1 s2,
∃ s SS, s1 = seq.append s (seq.join (seq.join SS)) ∧
s2 = seq.append s (seq.join (seq.map join SS))),
{ intros s1 s2 h, exact match s1, s2, h with ._, ._, ⟨s, SS, rfl, rfl⟩ := begin
apply cases_on s; simp,
{ apply cases_on SS; simp,
{ intros S SS, cases S with s S; cases s with x s; simp [map],
apply cases_on s; simp,
{ exact ⟨_, _, rfl, rfl⟩ },
{ intros x s,
refine ⟨cons x (append s (seq.join S)), SS, _, _⟩; simp } } },
{ intros x s, exact ⟨s, SS, rfl, rfl⟩ }
end end },
{ refine ⟨nil, SS, _, _⟩; simp }
end
@[simp] theorem bind_assoc (s : seq1 α) (f : α → seq1 β) (g : β → seq1 γ) :
bind (bind s f) g = bind s (λ (x : α), bind (f x) g) :=
begin
cases s with a s,
simp [bind, map],
rw [←map_comp],
change (λ x, join (map g (f x))) with (join ∘ ((map g) ∘ f)),
rw [map_comp _ join],
generalize : seq.map (map g ∘ f) s = SS,
cases map g (f a) with s S,
cases s with a s,
apply cases_on s; intros; apply cases_on S; intros; simp,
{ cases x with x t, apply cases_on t; intros; simp },
{ cases x_1 with y t; simp }
end
instance : monad seq1 :=
{ map := @map,
pure := @ret,
bind := @bind,
id_map := @map_id,
bind_pure_comp_eq_map := @bind_ret,
pure_bind := @ret_bind,
bind_assoc := @bind_assoc }
end seq1
|
5729d8b02408c250b1dda13484df9341a9a99ec6
|
958488bc7f3c2044206e0358e56d7690b6ae696c
|
/lean/tacticComb.lean
|
4d6ceb81016d740ee2257038646db424d5074522
|
[] |
no_license
|
possientis/Prog
|
a08eec1c1b121c2fd6c70a8ae89e2fbef952adb4
|
d4b3debc37610a88e0dac3ac5914903604fd1d1f
|
refs/heads/master
| 1,692,263,717,723
| 1,691,757,179,000
| 1,691,757,179,000
| 40,361,602
| 3
| 0
| null | 1,679,896,438,000
| 1,438,953,859,000
|
Coq
|
UTF-8
|
Lean
| false
| false
| 2,326
|
lean
|
lemma L1 : ∀ (p q:Prop), p → p ∨ q :=
begin intros p q H, left, assumption end
--#check L1
lemma L2 : ∀ (p q:Prop), p → p ∨ q :=
assume p q (H : p), by {left, assumption}
--#check L2
lemma L3 : ∀ (p q:Prop), p → q → p ∧ q :=
assume p q Hp Hq, by {split; assumption}
--#check L3
lemma L4 : ∀ (p q:Prop), p → p ∨ q :=
assume p q Hp, by {left, assumption} <|> {right, assumption}
--#check L4
lemma L5 : ∀ (p q:Prop), q → p ∨ q :=
assume p q Hq, by {left, assumption} <|> {right, assumption}
--#check L5
lemma L6 : ∀ (p q r:Prop), p → p ∨ q ∨ r :=
assume p q r H, by repeat {{left, assumption} <|> right <|> assumption}
--#check L6
lemma L7 : ∀ (p q r:Prop), q → p ∨ q ∨ r :=
assume p q r H, by repeat {{left, assumption} <|> right <|> assumption}
--#check L7
lemma L8 : ∀ (p q r:Prop), r → p ∨ q ∨ r :=
assume p q r H, by repeat {{left, assumption} <|> right <|> assumption}
--#check L8
meta def my_tac : tactic unit :=
`[ repeat { {left, assumption} <|> right <|> assumption}]
--#check my_tac
lemma L9 : ∀ (p q r:Prop), p → p ∨ q ∨ r :=
assume p q r H, by my_tac
--#check L9
lemma L10 : ∀ (p q r:Prop), q → p ∨ q ∨ r :=
assume p q r H, by my_tac
--#check L10
lemma L11 : ∀ (p q r:Prop), r → p ∨ q ∨ r :=
assume p q r H, by my_tac
--#check L11
lemma L12 : ∀ (p q r:Prop), p → q → r → p ∧ q ∧ r :=
assume p q r Hp Hq Hr, by split; try {split}; assumption
--#check L12
lemma L13 : ∀ (p q r:Prop), p → q → r → p ∧ q ∧ r :=
assume p q r Hp Hq Hr, by
begin
split,
all_goals {try {split}},
all_goals {assumption}
end
--#check L13
lemma L14 : ∀ (p q r:Prop), p → q → r → p ∧ q ∧ r :=
assume p q r Hp Hq Hr, by
begin
split,
any_goals {split},
any_goals {assumption}
end
--#check L14
lemma L15 : ∀ (p q r:Prop), p → q → r → p ∧ ((p ∧ q) ∧ r) ∧ (q ∧ r ∧ p) :=
assume p q r Hp Hq Hr,
begin
repeat {any_goals {split}},
all_goals {assumption}
end
--#check L15
lemma L16 : ∀ (p q r:Prop), p → q → r → p ∧ ((p ∧ q) ∧ r) ∧ (q ∧ r ∧ p) :=
assume p q r Hp Hq Hr,
begin
repeat {any_goals {split <|> assumption}}
end
--#check L16
|
17dbb7d4181b55bc9fba8e18a67fe7cdb1d54600
|
3ed5a65c1ab3ce5d1a094edce8fa3287980f197b
|
/src/herstein/ex1_1/Q_08.lean
|
0d22421211c20a5a5f79afe57d10ff11470639a8
|
[] |
no_license
|
group-study-group/herstein
|
35d32e77158efa2cc303c84e1ee5e3bc80831137
|
f5a1a72eb56fa19c19ece0cb3ab6cf7ffd161f66
|
refs/heads/master
| 1,586,202,191,519
| 1,548,969,759,000
| 1,548,969,759,000
| 157,746,953
| 0
| 0
| null | 1,542,412,901,000
| 1,542,302,366,000
|
Lean
|
UTF-8
|
Lean
| false
| false
| 565
|
lean
|
import data.set.basic data.finset
variable α: Type*
variables A B C: set α
open set
-- requires classical logic?
theorem Q8: (A - B) ∪ (B - A) = (A ∪ B) - (A ∩ B) :=
ext $ λ x,
⟨λ hl,
⟨or.elim hl
(λ hab, or.inl hab.1)
(λ hba, or.inr hba.1),
λ ⟨ha, hb⟩, or.elim hl
(λ hab, hab.2 hb)
(λ hba, hba.2 ha)⟩,
λ hr, classical.by_cases
(λ ha, or.inl ⟨ha, λ hb, hr.2 ⟨ha, hb⟩⟩)
(λ hn, or.inr
⟨or.elim hr.1
(λ ha, false.elim (hn ha))
(λ hb, hb),
hn⟩)⟩
|
6c2e248cfcb05f2a754e03ace11c1244d6c261b5
|
8cae430f0a71442d02dbb1cbb14073b31048e4b0
|
/src/data/list/palindrome.lean
|
74d22c24122dda21b5ae1458a7ec095abf1d97ca
|
[
"Apache-2.0"
] |
permissive
|
leanprover-community/mathlib
|
56a2cadd17ac88caf4ece0a775932fa26327ba0e
|
442a83d738cb208d3600056c489be16900ba701d
|
refs/heads/master
| 1,693,584,102,358
| 1,693,471,902,000
| 1,693,471,902,000
| 97,922,418
| 1,595
| 352
|
Apache-2.0
| 1,694,693,445,000
| 1,500,624,130,000
|
Lean
|
UTF-8
|
Lean
| false
| false
| 2,296
|
lean
|
/-
Copyright (c) 2020 Google LLC. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Wong
-/
import data.list.basic
/-!
# Palindromes
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
This module defines *palindromes*, lists which are equal to their reverse.
The main result is the `palindrome` inductive type, and its associated `palindrome.rec_on` induction
principle. Also provided are conversions to and from other equivalent definitions.
## References
* [Pierre Castéran, *On palindromes*][casteran]
[casteran]: https://www.labri.fr/perso/casteran/CoqArt/inductive-prop-chap/palindrome.html
## Tags
palindrome, reverse, induction
-/
variables {α β : Type*}
namespace list
/--
`palindrome l` asserts that `l` is a palindrome. This is defined inductively:
* The empty list is a palindrome;
* A list with one element is a palindrome;
* Adding the same element to both ends of a palindrome results in a bigger palindrome.
-/
inductive palindrome : list α → Prop
| nil : palindrome []
| singleton : ∀ x, palindrome [x]
| cons_concat : ∀ x {l}, palindrome l → palindrome (x :: (l ++ [x]))
namespace palindrome
variables {l : list α}
lemma reverse_eq {l : list α} (p : palindrome l) : reverse l = l :=
palindrome.rec_on p rfl (λ _, rfl) (λ x l p h, by simp [h])
lemma of_reverse_eq {l : list α} : reverse l = l → palindrome l :=
begin
refine bidirectional_rec_on l (λ _, palindrome.nil) (λ a _, palindrome.singleton a) _,
intros x l y hp hr,
rw [reverse_cons, reverse_append] at hr,
rw head_eq_of_cons_eq hr,
have : palindrome l, from hp (append_inj_left' (tail_eq_of_cons_eq hr) rfl),
exact palindrome.cons_concat x this
end
lemma iff_reverse_eq {l : list α} : palindrome l ↔ reverse l = l :=
iff.intro reverse_eq of_reverse_eq
lemma append_reverse (l : list α) : palindrome (l ++ reverse l) :=
by { apply of_reverse_eq, rw [reverse_append, reverse_reverse] }
protected lemma map (f : α → β) (p : palindrome l) : palindrome (map f l) :=
of_reverse_eq $ by rw [← map_reverse, p.reverse_eq]
instance [decidable_eq α] (l : list α) : decidable (palindrome l) :=
decidable_of_iff' _ iff_reverse_eq
end palindrome
end list
|
3a81e6186d044b7a172e1ccde8f171f0729b5efd
|
4727251e0cd73359b15b664c3170e5d754078599
|
/src/control/fix.lean
|
839187dc350dff95fd9e1243f2b00c9c24f6f360
|
[
"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
| 3,244
|
lean
|
/-
Copyright (c) 2020 Simon Hudon. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Simon Hudon
-/
import data.stream.init
import data.part
import data.nat.upto
/-!
# Fixed point
This module defines a generic `fix` operator for defining recursive
computations that are not necessarily well-founded or productive.
An instance is defined for `part`.
## Main definition
* class `has_fix`
* `part.fix`
-/
universes u v
open_locale classical
variables {α : Type*} {β : α → Type*}
/-- `has_fix α` gives us a way to calculate the fixed point
of function of type `α → α`. -/
class has_fix (α : Type*) :=
(fix : (α → α) → α)
namespace part
open part nat nat.upto
section basic
variables (f : (Π a, part $ β a) → (Π a, part $ β a))
/-- A series of successive, finite approximation of the fixed point of `f`, defined by
`approx f n = f^[n] ⊥`. The limit of this chain is the fixed point of `f`. -/
def fix.approx : stream $ Π a, part $ β a
| 0 := ⊥
| (nat.succ i) := f (fix.approx i)
/-- loop body for finding the fixed point of `f` -/
def fix_aux {p : ℕ → Prop} (i : nat.upto p)
(g : Π j : nat.upto p, i < j → Π a, part $ β a) : Π a, part $ β a :=
f $ λ x : α,
assert (¬p (i.val)) $ λ h : ¬ p (i.val),
g (i.succ h) (nat.lt_succ_self _) x
/-- The least fixed point of `f`.
If `f` is a continuous function (according to complete partial orders),
it satisfies the equations:
1. `fix f = f (fix f)` (is a fixed point)
2. `∀ X, f X ≤ X → fix f ≤ X` (least fixed point)
-/
protected def fix (x : α) : part $ β x :=
part.assert (∃ i, (fix.approx f i x).dom) $ λ h,
well_founded.fix.{1} (nat.upto.wf h) (fix_aux f) nat.upto.zero x
protected lemma fix_def {x : α} (h' : ∃ i, (fix.approx f i x).dom) :
part.fix f x = fix.approx f (nat.succ $ nat.find h') x :=
begin
let p := λ (i : ℕ), (fix.approx f i x).dom,
have : p (nat.find h') := nat.find_spec h',
generalize hk : nat.find h' = k,
replace hk : nat.find h' = k + (@upto.zero p).val := hk,
rw hk at this,
revert hk,
dsimp [part.fix], rw assert_pos h', revert this,
generalize : upto.zero = z, intros,
suffices : ∀ x',
well_founded.fix (fix._proof_1 f x h') (fix_aux f) z x' = fix.approx f (succ k) x',
from this _,
induction k generalizing z; intro,
{ rw [fix.approx,well_founded.fix_eq,fix_aux],
congr, ext : 1, rw assert_neg, refl,
rw nat.zero_add at this,
simpa only [not_not, subtype.val_eq_coe] },
{ rw [fix.approx,well_founded.fix_eq,fix_aux],
congr, ext : 1,
have hh : ¬(fix.approx f (z.val) x).dom,
{ apply nat.find_min h',
rw [hk,nat.succ_add,← nat.add_succ],
apply nat.lt_of_succ_le,
apply nat.le_add_left },
rw succ_add_eq_succ_add at this hk,
rw [assert_pos hh, k_ih (upto.succ z hh) this hk] }
end
lemma fix_def' {x : α} (h' : ¬ ∃ i, (fix.approx f i x).dom) :
part.fix f x = none :=
by dsimp [part.fix]; rw assert_neg h'
end basic
end part
namespace part
instance : has_fix (part α) :=
⟨λ f, part.fix (λ x u, f (x u)) ()⟩
end part
open sigma
namespace pi
instance part.has_fix {β} : has_fix (α → part β) := ⟨part.fix⟩
end pi
|
3ccc1564ab8429861a03a35e70b51e17bec3d59a
|
9dc8cecdf3c4634764a18254e94d43da07142918
|
/src/probability/martingale/upcrossing.lean
|
473fa98d7aa0c2f73c8a1fbd7046e6599276a6e6
|
[
"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
| 41,414
|
lean
|
/-
Copyright (c) 2022 Kexing Ying. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kexing Ying
-/
import probability.hitting_time
import probability.martingale.basic
/-!
# Doob's upcrossing estimate
Given a discrete real-valued submartingale $(f_n)_{n \in \mathbb{N}}$, denoting $U_N(a, b)$ the
number of times $f_n$ crossed from below $a$ to above $b$ before time $N$, Doob's upcrossing
estimate (also known as Doob's inequality) states that
$$(b - a) \mathbb{E}[U_N(a, b)] \le \mathbb{E}[(f_N - a)^+].$$
Doob's upcrossing estimate is an important inequality and is central in proving the martingale
convergence theorems.
## Main definitions
* `measure_theory.upper_crossing_time a b f N n`: is the stopping time corresponding to `f`
crossing above `b` the `n`-th time before time `N` (if this does not occur then the value is
taken to be `N`).
* `measure_theory.lower_crossing_time a b f N n`: is the stopping time corresponding to `f`
crossing below `a` the `n`-th time before time `N` (if this does not occur then the value is
taken to be `N`).
* `measure_theory.upcrossing_strat a b f N`: is the predictable process which is 1 if `n` is
between a consecutive pair of lower and upper crossing and is 0 otherwise. Intuitively
one might think of the `upcrossing_strat` as the strategy of buying 1 share whenever the process
crosses below `a` for the first time after selling and selling 1 share whenever the process
crosses above `b` for the first time after buying.
* `measure_theory.upcrossings_before a b f N`: is the number of times `f` crosses from below `a` to
above `b` before time `N`.
* `measure_theory.upcrossings a b f`: is the number of times `f` crosses from below `a` to above
`b`. This takes value in `ℝ≥0∞` and so is allowed to be `∞`.
## Main results
* `measure_theory.adapted.is_stopping_time_upper_crossing_time`: `upper_crossing_time` is a
stopping time whenever the process it is associated to is adapted.
* `measure_theory.adapted.is_stopping_time_lower_crossing_time`: `lower_crossing_time` is a
stopping time whenever the process it is associated to is adapted.
* `measure_theory.submartingale.mul_integral_upcrossings_before_le_integral_pos_part`: Doob's
upcrossing estimate.
* `measure_theory.submartingale.mul_lintegral_upcrossings_le_lintegral_pos_part`: the inequality
obtained by taking the supremum on both sides of Doob's upcrossing estimate.
### References
We mostly follow the proof from [Kallenberg, *Foundations of modern probability*][kallenberg2021]
-/
open topological_space filter
open_locale nnreal ennreal measure_theory probability_theory big_operators topological_space
namespace measure_theory
variables {Ω ι : Type*} {m0 : measurable_space Ω} {μ : measure Ω}
/-!
## Proof outline
In this section, we will denote $U_N(a, b)$ the number of upcrossings of $(f_n)$ from below $a$ to
above $b$ before time $N$.
To define $U_N(a, b)$, we will construct two stopping times corresponding to when $(f_n)$ crosses
below $a$ and above $b$. Namely, we define
$$
\sigma_n := \inf \{n \ge \tau_n \mid f_n \le a\} \wedge N;
$$
$$
\tau_{n + 1} := \inf \{n \ge \sigma_n \mid f_n \ge b\} \wedge N.
$$
These are `lower_crossing_time` and `upper_crossing_time` in our formalization which are defined
using `measure_theory.hitting` allowing us to specify a starting and ending time.
Then, we may simply define $U_N(a, b) := \sup \{n \mid \tau_n < N\}$.
Fixing $a < b \in \mathbb{R}$, we will first prove the theorem in the special case that
$0 \le f_0$ and $a \le f_N$. In particular, we will show
$$
(b - a) \mathbb{E}[U_N(a, b)] \le \mathbb{E}[f_N].
$$
This is `measure_theory.integral_mul_upcrossings_before_le_integral` in our formalization.
To prove this, we use the fact that given a non-negative, bounded, predictable process $(C_n)$
(i.e. $(C_{n + 1})$ is adapted), $(C \bullet f)_n := \sum_{k \le n} C_{k + 1}(f_{k + 1} - f_k)$ is
a submartingale if $(f_n)$ is.
Define $C_n := \sum_{k \le n} \mathbf{1}_{[\sigma_k, \tau_{k + 1})}(n)$. It is easy to see that
$(1 - C_n)$ is non-negative, bounded and predictable, and hence, given a submartingale $(f_n)$,
$(1 - C) \bullet f$ is also a submartingale. Thus, by the submartingale property,
$0 \le \mathbb{E}[((1 - C) \bullet f)_0] \le \mathbb{E}[((1 - C) \bullet f)_N]$ implying
$$
\mathbb{E}[(C \bullet f)_N] \le \mathbb{E}[(1 \bullet f)_N] = \mathbb{E}[f_N] - \mathbb{E}[f_0].
$$
Furthermore,
\begin{align}
(C \bullet f)_N & =
\sum_{n \le N} \sum_{k \le N} \mathbf{1}_{[\sigma_k, \tau_{k + 1})}(n)(f_{n + 1} - f_n)\\
& = \sum_{k \le N} \sum_{n \le N} \mathbf{1}_{[\sigma_k, \tau_{k + 1})}(n)(f_{n + 1} - f_n)\\
& = \sum_{k \le N} (f_{\sigma_k + 1} - f_{\sigma_k} + f_{\sigma_k + 2} - f_{\sigma_k + 1}
+ \cdots + f_{\tau_{k + 1}} - f_{\tau_{k + 1} - 1})\\
& = \sum_{k \le N} (f_{\tau_{k + 1}} - f_{\sigma_k})
\ge \sum_{k < U_N(a, b)} (b - a) = (b - a) U_N(a, b)
\end{align}
where the inequality follows since for all $k < U_N(a, b)$,
$f_{\tau_{k + 1}} - f_{\sigma_k} \ge b - a$ while for all $k > U_N(a, b)$,
$f_{\tau_{k + 1}} = f_{\sigma_k} = f_N$ and
$f_{\tau_{U_N(a, b) + 1}} - f_{\sigma_{U_N(a, b)}} = f_N - a \ge 0$. Hence, we have
$$
(b - a) \mathbb{E}[U_N(a, b)] \le \mathbb{E}[(C \bullet f)_N]
\le \mathbb{E}[f_N] - \mathbb{E}[f_0] \le \mathbb{E}[f_N],
$$
as required.
To obtain the general case, we simply apply the above to $((f_n - a)^+)_n$.
-/
/-- `lower_crossing_time_aux a f c N` is the first time `f` reached below `a` after time `c` before
time `N`. -/
noncomputable
def lower_crossing_time_aux [preorder ι] [has_Inf ι] (a : ℝ) (f : ι → Ω → ℝ) (c N : ι) : Ω → ι :=
hitting f (set.Iic a) c N
/-- `upper_crossing_time a b f N n` is the first time before time `N`, `f` reaches
above `b` after `f` reached below `a` for the `n - 1`-th time. -/
noncomputable
def upper_crossing_time [preorder ι] [order_bot ι] [has_Inf ι]
(a b : ℝ) (f : ι → Ω → ℝ) (N : ι) : ℕ → Ω → ι
| 0 := ⊥
| (n + 1) := λ ω, hitting f (set.Ici b)
(lower_crossing_time_aux a f (upper_crossing_time n ω) N ω) N ω
/-- `lower_crossing_time a b f N n` is the first time before time `N`, `f` reaches
below `a` after `f` reached above `b` for the `n`-th time. -/
noncomputable
def lower_crossing_time [preorder ι] [order_bot ι] [has_Inf ι]
(a b : ℝ) (f : ι → Ω → ℝ) (N : ι) (n : ℕ) : Ω → ι :=
λ ω, hitting f (set.Iic a) (upper_crossing_time a b f N n ω) N ω
section
variables [preorder ι] [order_bot ι] [has_Inf ι]
variables {a b : ℝ} {f : ι → Ω → ℝ} {N : ι} {n m : ℕ} {ω : Ω}
@[simp]
lemma upper_crossing_time_zero : upper_crossing_time a b f N 0 = ⊥ := rfl
@[simp]
lemma lower_crossing_time_zero : lower_crossing_time a b f N 0 = hitting f (set.Iic a) ⊥ N := rfl
lemma upper_crossing_time_succ :
upper_crossing_time a b f N (n + 1) ω =
hitting f (set.Ici b) (lower_crossing_time_aux a f (upper_crossing_time a b f N n ω) N ω) N ω :=
by rw upper_crossing_time
lemma upper_crossing_time_succ_eq (ω : Ω) :
upper_crossing_time a b f N (n + 1) ω =
hitting f (set.Ici b) (lower_crossing_time a b f N n ω) N ω :=
begin
simp only [upper_crossing_time_succ],
refl,
end
end
section conditionally_complete_linear_order_bot
variables [conditionally_complete_linear_order_bot ι]
variables {a b : ℝ} {f : ι → Ω → ℝ} {N : ι} {n m : ℕ} {ω : Ω}
lemma upper_crossing_time_le : upper_crossing_time a b f N n ω ≤ N :=
begin
cases n,
{ simp only [upper_crossing_time_zero, pi.bot_apply, bot_le] },
{ simp only [upper_crossing_time_succ, hitting_le] },
end
@[simp]
lemma upper_crossing_time_zero' : upper_crossing_time a b f ⊥ n ω = ⊥ :=
eq_bot_iff.2 upper_crossing_time_le
lemma lower_crossing_time_le : lower_crossing_time a b f N n ω ≤ N :=
by simp only [lower_crossing_time, hitting_le ω]
lemma upper_crossing_time_le_lower_crossing_time :
upper_crossing_time a b f N n ω ≤ lower_crossing_time a b f N n ω :=
by simp only [lower_crossing_time, le_hitting upper_crossing_time_le ω]
lemma lower_crossing_time_le_upper_crossing_time_succ :
lower_crossing_time a b f N n ω ≤ upper_crossing_time a b f N (n + 1) ω :=
begin
rw upper_crossing_time_succ,
exact le_hitting lower_crossing_time_le ω,
end
lemma lower_crossing_time_mono (hnm : n ≤ m) :
lower_crossing_time a b f N n ω ≤ lower_crossing_time a b f N m ω :=
begin
suffices : monotone (λ n, lower_crossing_time a b f N n ω),
{ exact this hnm },
exact monotone_nat_of_le_succ
(λ n, le_trans lower_crossing_time_le_upper_crossing_time_succ
upper_crossing_time_le_lower_crossing_time)
end
lemma upper_crossing_time_mono (hnm : n ≤ m) :
upper_crossing_time a b f N n ω ≤ upper_crossing_time a b f N m ω :=
begin
suffices : monotone (λ n, upper_crossing_time a b f N n ω),
{ exact this hnm },
exact monotone_nat_of_le_succ
(λ n, le_trans upper_crossing_time_le_lower_crossing_time
lower_crossing_time_le_upper_crossing_time_succ),
end
end conditionally_complete_linear_order_bot
variables {a b : ℝ} {f : ℕ → Ω → ℝ} {N : ℕ} {n m : ℕ} {ω : Ω}
lemma stopped_value_lower_crossing_time (h : lower_crossing_time a b f N n ω ≠ N) :
stopped_value f (lower_crossing_time a b f N n) ω ≤ a :=
begin
obtain ⟨j, hj₁, hj₂⟩ :=
(hitting_le_iff_of_lt _ (lt_of_le_of_ne lower_crossing_time_le h)).1 le_rfl,
exact stopped_value_hitting_mem ⟨j, ⟨hj₁.1, le_trans hj₁.2 lower_crossing_time_le⟩, hj₂⟩,
end
lemma stopped_value_upper_crossing_time (h : upper_crossing_time a b f N (n + 1) ω ≠ N) :
b ≤ stopped_value f (upper_crossing_time a b f N (n + 1)) ω :=
begin
obtain ⟨j, hj₁, hj₂⟩ :=
(hitting_le_iff_of_lt _ (lt_of_le_of_ne upper_crossing_time_le h)).1 le_rfl,
exact stopped_value_hitting_mem ⟨j, ⟨hj₁.1, le_trans hj₁.2 (hitting_le _)⟩, hj₂⟩,
end
lemma upper_crossing_time_lt_lower_crossing_time
(hab : a < b) (hn : lower_crossing_time a b f N (n + 1) ω ≠ N) :
upper_crossing_time a b f N (n + 1) ω < lower_crossing_time a b f N (n + 1) ω :=
begin
refine lt_of_le_of_ne upper_crossing_time_le_lower_crossing_time
(λ h, not_le.2 hab $ le_trans _ (stopped_value_lower_crossing_time hn)),
simp only [stopped_value],
rw ← h,
exact stopped_value_upper_crossing_time (h.symm ▸ hn),
end
lemma lower_crossing_time_lt_upper_crossing_time
(hab : a < b) (hn : upper_crossing_time a b f N (n + 1) ω ≠ N) :
lower_crossing_time a b f N n ω < upper_crossing_time a b f N (n + 1) ω :=
begin
refine lt_of_le_of_ne lower_crossing_time_le_upper_crossing_time_succ
(λ h, not_le.2 hab $ le_trans (stopped_value_upper_crossing_time hn) _),
simp only [stopped_value],
rw ← h,
exact stopped_value_lower_crossing_time (h.symm ▸ hn),
end
lemma upper_crossing_time_lt_succ (hab : a < b) (hn : upper_crossing_time a b f N (n + 1) ω ≠ N) :
upper_crossing_time a b f N n ω < upper_crossing_time a b f N (n + 1) ω :=
lt_of_le_of_lt upper_crossing_time_le_lower_crossing_time
(lower_crossing_time_lt_upper_crossing_time hab hn)
lemma lower_crossing_time_stabilize (hnm : n ≤ m) (hn : lower_crossing_time a b f N n ω = N) :
lower_crossing_time a b f N m ω = N :=
le_antisymm lower_crossing_time_le (le_trans (le_of_eq hn.symm) (lower_crossing_time_mono hnm))
lemma upper_crossing_time_stabilize (hnm : n ≤ m) (hn : upper_crossing_time a b f N n ω = N) :
upper_crossing_time a b f N m ω = N :=
le_antisymm upper_crossing_time_le (le_trans (le_of_eq hn.symm) (upper_crossing_time_mono hnm))
lemma lower_crossing_time_stabilize' (hnm : n ≤ m) (hn : N ≤ lower_crossing_time a b f N n ω) :
lower_crossing_time a b f N m ω = N :=
lower_crossing_time_stabilize hnm (le_antisymm lower_crossing_time_le hn)
lemma upper_crossing_time_stabilize' (hnm : n ≤ m) (hn : N ≤ upper_crossing_time a b f N n ω) :
upper_crossing_time a b f N m ω = N :=
upper_crossing_time_stabilize hnm (le_antisymm upper_crossing_time_le hn)
-- `upper_crossing_time_bound_eq` provides an explicit bound
lemma exists_upper_crossing_time_eq (f : ℕ → Ω → ℝ) (N : ℕ) (ω : Ω) (hab : a < b) :
∃ n, upper_crossing_time a b f N n ω = N :=
begin
by_contra h, push_neg at h,
have : strict_mono (λ n, upper_crossing_time a b f N n ω) :=
strict_mono_nat_of_lt_succ (λ n, upper_crossing_time_lt_succ hab (h _)),
obtain ⟨_, ⟨k, rfl⟩, hk⟩ :
∃ m (hm : m ∈ set.range (λ n, upper_crossing_time a b f N n ω)), N < m :=
⟨upper_crossing_time a b f N (N + 1) ω, ⟨N + 1, rfl⟩,
lt_of_lt_of_le (N.lt_succ_self) (strict_mono.id_le this (N + 1))⟩,
exact not_le.2 hk upper_crossing_time_le
end
lemma upper_crossing_time_lt_bdd_above (hab : a < b) :
bdd_above {n | upper_crossing_time a b f N n ω < N} :=
begin
obtain ⟨k, hk⟩ := exists_upper_crossing_time_eq f N ω hab,
refine ⟨k, λ n (hn : upper_crossing_time a b f N n ω < N), _⟩,
by_contra hn',
exact hn.ne (upper_crossing_time_stabilize (not_le.1 hn').le hk)
end
lemma upper_crossing_time_lt_nonempty (hN : 0 < N) :
{n | upper_crossing_time a b f N n ω < N}.nonempty :=
⟨0, hN⟩
lemma upper_crossing_time_bound_eq (f : ℕ → Ω → ℝ) (N : ℕ) (ω : Ω) (hab : a < b) :
upper_crossing_time a b f N N ω = N :=
begin
by_cases hN' : N < nat.find (exists_upper_crossing_time_eq f N ω hab),
{ refine le_antisymm upper_crossing_time_le _,
have hmono : strict_mono_on (λ n, upper_crossing_time a b f N n ω)
(set.Iic (nat.find (exists_upper_crossing_time_eq f N ω hab)).pred),
{ refine strict_mono_on_Iic_of_lt_succ (λ m hm, upper_crossing_time_lt_succ hab _),
rw nat.lt_pred_iff at hm,
convert nat.find_min _ hm },
convert strict_mono_on.Iic_id_le hmono N (nat.le_pred_of_lt hN') },
{ rw not_lt at hN',
exact upper_crossing_time_stabilize hN'
(nat.find_spec (exists_upper_crossing_time_eq f N ω hab)) }
end
lemma upper_crossing_time_eq_of_bound_le (hab : a < b) (hn : N ≤ n) :
upper_crossing_time a b f N n ω = N :=
le_antisymm upper_crossing_time_le
((le_trans (upper_crossing_time_bound_eq f N ω hab).symm.le (upper_crossing_time_mono hn)))
variables {ℱ : filtration ℕ m0}
lemma adapted.is_stopping_time_crossing (hf : adapted ℱ f) :
is_stopping_time ℱ (upper_crossing_time a b f N n) ∧
is_stopping_time ℱ (lower_crossing_time a b f N n) :=
begin
induction n with k ih,
{ refine ⟨is_stopping_time_const _ 0, _⟩,
simp [hitting_is_stopping_time hf measurable_set_Iic] },
{ obtain ⟨ih₁, ih₂⟩ := ih,
have : is_stopping_time ℱ (upper_crossing_time a b f N (k + 1)),
{ intro n,
simp_rw upper_crossing_time_succ_eq,
exact is_stopping_time_hitting_is_stopping_time ih₂ (λ _, lower_crossing_time_le)
measurable_set_Ici hf _ },
refine ⟨this, _⟩,
{ intro n,
exact is_stopping_time_hitting_is_stopping_time this (λ _, upper_crossing_time_le)
measurable_set_Iic hf _ } }
end
lemma adapted.is_stopping_time_upper_crossing_time (hf : adapted ℱ f) :
is_stopping_time ℱ (upper_crossing_time a b f N n) :=
hf.is_stopping_time_crossing.1
lemma adapted.is_stopping_time_lower_crossing_time (hf : adapted ℱ f) :
is_stopping_time ℱ (lower_crossing_time a b f N n) :=
hf.is_stopping_time_crossing.2
/-- `upcrossing_strat a b f N n` is 1 if `n` is between a consecutive pair of lower and upper
crossings and is 0 otherwise. `upcrossing_strat` is shifted by one index so that it is adapted
rather than predictable. -/
noncomputable
def upcrossing_strat (a b : ℝ) (f : ℕ → Ω → ℝ) (N n : ℕ) (ω : Ω) : ℝ :=
∑ k in finset.range N,
(set.Ico (lower_crossing_time a b f N k ω) (upper_crossing_time a b f N (k + 1) ω)).indicator 1 n
lemma upcrossing_strat_nonneg : 0 ≤ upcrossing_strat a b f N n ω :=
finset.sum_nonneg (λ i hi, set.indicator_nonneg (λ ω hω, zero_le_one) _)
lemma upcrossing_strat_le_one : upcrossing_strat a b f N n ω ≤ 1 :=
begin
rw [upcrossing_strat, ← set.indicator_finset_bUnion_apply],
{ exact set.indicator_le_self' (λ _ _, zero_le_one) _ },
{ intros i hi j hj hij,
rw set.Ico_disjoint_Ico,
obtain (hij' | hij') := lt_or_gt_of_ne hij,
{ rw [min_eq_left ((upper_crossing_time_mono (nat.succ_le_succ hij'.le)) :
upper_crossing_time a b f N _ ω ≤ upper_crossing_time a b f N _ ω),
max_eq_right (lower_crossing_time_mono hij'.le :
lower_crossing_time a b f N _ _ ≤ lower_crossing_time _ _ _ _ _ _)],
refine le_trans upper_crossing_time_le_lower_crossing_time (lower_crossing_time_mono
(nat.succ_le_of_lt hij')) },
{ rw gt_iff_lt at hij',
rw [min_eq_right ((upper_crossing_time_mono (nat.succ_le_succ hij'.le)) :
upper_crossing_time a b f N _ ω ≤ upper_crossing_time a b f N _ ω),
max_eq_left (lower_crossing_time_mono hij'.le :
lower_crossing_time a b f N _ _ ≤ lower_crossing_time _ _ _ _ _ _)],
refine le_trans upper_crossing_time_le_lower_crossing_time
(lower_crossing_time_mono (nat.succ_le_of_lt hij')) } }
end
lemma adapted.upcrossing_strat_adapted (hf : adapted ℱ f) :
adapted ℱ (upcrossing_strat a b f N) :=
begin
intro n,
change strongly_measurable[ℱ n] (λ ω, ∑ k in finset.range N,
({n | lower_crossing_time a b f N k ω ≤ n} ∩
{n | n < upper_crossing_time a b f N (k + 1) ω}).indicator 1 n),
refine finset.strongly_measurable_sum _ (λ i hi,
strongly_measurable_const.indicator ((hf.is_stopping_time_lower_crossing_time n).inter _)),
simp_rw ← not_le,
exact (hf.is_stopping_time_upper_crossing_time n).compl,
end
lemma submartingale.sum_upcrossing_strat_mul [is_finite_measure μ] (hf : submartingale f ℱ μ)
(a b : ℝ) (N : ℕ) :
submartingale
(λ n : ℕ, ∑ k in finset.range n, upcrossing_strat a b f N k * (f (k + 1) - f k)) ℱ μ :=
hf.sum_mul_sub hf.adapted.upcrossing_strat_adapted
(λ _ _, upcrossing_strat_le_one) (λ _ _, upcrossing_strat_nonneg)
lemma submartingale.sum_sub_upcrossing_strat_mul [is_finite_measure μ] (hf : submartingale f ℱ μ)
(a b : ℝ) (N : ℕ) :
submartingale
(λ n : ℕ, ∑ k in finset.range n, (1 - upcrossing_strat a b f N k) * (f (k + 1) - f k)) ℱ μ :=
begin
refine hf.sum_mul_sub (λ n, (adapted_const ℱ 1 n).sub (hf.adapted.upcrossing_strat_adapted n))
(_ : ∀ n ω, (1 - upcrossing_strat a b f N n) ω ≤ 1) _,
{ refine λ n ω, sub_le.1 _,
simp [upcrossing_strat_nonneg] },
{ intros n ω,
simp [upcrossing_strat_le_one] }
end
lemma submartingale.sum_mul_upcrossing_strat_le [is_finite_measure μ] (hf : submartingale f ℱ μ) :
μ[∑ k in finset.range n, upcrossing_strat a b f N k * (f (k + 1) - f k)] ≤
μ[f n] - μ[f 0] :=
begin
have h₁ : (0 : ℝ) ≤
μ[∑ k in finset.range n, (1 - upcrossing_strat a b f N k) * (f (k + 1) - f k)],
{ have := (hf.sum_sub_upcrossing_strat_mul a b N).set_integral_le (zero_le n) measurable_set.univ,
rw [integral_univ, integral_univ] at this,
refine le_trans _ this,
simp only [finset.range_zero, finset.sum_empty, integral_zero'] },
have h₂ : μ[∑ k in finset.range n, (1 - upcrossing_strat a b f N k) * (f (k + 1) - f k)] =
μ[∑ k in finset.range n, (f (k + 1) - f k)] -
μ[∑ k in finset.range n, upcrossing_strat a b f N k * (f (k + 1) - f k)],
{ simp only [sub_mul, one_mul, finset.sum_sub_distrib, pi.sub_apply,
finset.sum_apply, pi.mul_apply],
refine integral_sub (integrable.sub (integrable_finset_sum _ (λ i hi, hf.integrable _))
(integrable_finset_sum _ (λ i hi, hf.integrable _))) _,
convert (hf.sum_upcrossing_strat_mul a b N).integrable n,
ext, simp },
rw [h₂, sub_nonneg] at h₁,
refine le_trans h₁ _,
simp_rw [finset.sum_range_sub, integral_sub' (hf.integrable _) (hf.integrable _)],
end
/-- The number of upcrossings (strictly) before time `N`. -/
noncomputable
def upcrossings_before [preorder ι] [order_bot ι] [has_Inf ι]
(a b : ℝ) (f : ι → Ω → ℝ) (N : ι) (ω : Ω) : ℕ :=
Sup {n | upper_crossing_time a b f N n ω < N}
@[simp]
lemma upcrossings_before_bot [preorder ι] [order_bot ι] [has_Inf ι]
{a b : ℝ} {f : ι → Ω → ℝ} {ω : Ω} :
upcrossings_before a b f ⊥ ω = ⊥ :=
by simp [upcrossings_before]
lemma upcrossings_before_zero :
upcrossings_before a b f 0 ω = 0 :=
by simp [upcrossings_before]
@[simp] lemma upcrossings_before_zero' :
upcrossings_before a b f 0 = 0 :=
by { ext ω, exact upcrossings_before_zero }
lemma upper_crossing_time_lt_of_le_upcrossings_before
(hN : 0 < N) (hab : a < b) (hn : n ≤ upcrossings_before a b f N ω) :
upper_crossing_time a b f N n ω < N :=
begin
have : upper_crossing_time a b f N (upcrossings_before a b f N ω) ω < N :=
(upper_crossing_time_lt_nonempty hN).cSup_mem
((order_bot.bdd_below _).finite_of_bdd_above (upper_crossing_time_lt_bdd_above hab)),
exact lt_of_le_of_lt (upper_crossing_time_mono hn) this,
end
lemma upper_crossing_time_eq_of_upcrossings_before_lt
(hab : a < b) (hn : upcrossings_before a b f N ω < n) :
upper_crossing_time a b f N n ω = N :=
begin
refine le_antisymm upper_crossing_time_le (not_lt.1 _),
convert not_mem_of_cSup_lt hn (upper_crossing_time_lt_bdd_above hab),
end
lemma upcrossings_before_le (f : ℕ → Ω → ℝ) (ω : Ω) (hab : a < b) :
upcrossings_before a b f N ω ≤ N :=
begin
by_cases hN : N = 0,
{ subst hN,
rw upcrossings_before_zero },
{ refine cSup_le ⟨0, zero_lt_iff.2 hN⟩ (λ n (hn : _ < _), _),
by_contra hnN,
exact hn.ne (upper_crossing_time_eq_of_bound_le hab (not_le.1 hnN).le) },
end
lemma crossing_eq_crossing_of_lower_crossing_time_lt {M : ℕ} (hNM : N ≤ M)
(h : lower_crossing_time a b f N n ω < N) :
upper_crossing_time a b f M n ω = upper_crossing_time a b f N n ω ∧
lower_crossing_time a b f M n ω = lower_crossing_time a b f N n ω :=
begin
have h' : upper_crossing_time a b f N n ω < N :=
lt_of_le_of_lt upper_crossing_time_le_lower_crossing_time h,
induction n with k ih,
{ simp only [nat.nat_zero_eq_zero, upper_crossing_time_zero, bot_eq_zero', eq_self_iff_true,
lower_crossing_time_zero, true_and, eq_comm],
refine hitting_eq_hitting_of_exists hNM _,
simp only [lower_crossing_time, hitting_lt_iff] at h,
obtain ⟨j, hj₁, hj₂⟩ := h,
exact ⟨j, ⟨hj₁.1, hj₁.2.le⟩, hj₂⟩ },
{ specialize ih (lt_of_le_of_lt (lower_crossing_time_mono (nat.le_succ _)) h)
(lt_of_le_of_lt (upper_crossing_time_mono (nat.le_succ _)) h'),
have : upper_crossing_time a b f M k.succ ω = upper_crossing_time a b f N k.succ ω,
{ simp only [upper_crossing_time_succ_eq, hitting_lt_iff] at h' ⊢,
obtain ⟨j, hj₁, hj₂⟩ := h',
rw [eq_comm, ih.2],
exact hitting_eq_hitting_of_exists hNM ⟨j, ⟨hj₁.1, hj₁.2.le⟩, hj₂⟩ },
refine ⟨this, _⟩,
simp only [lower_crossing_time, eq_comm, this],
refine hitting_eq_hitting_of_exists hNM _,
rw [lower_crossing_time, hitting_lt_iff _ le_rfl] at h,
swap, { apply_instance },
obtain ⟨j, hj₁, hj₂⟩ := h,
exact ⟨j, ⟨hj₁.1, hj₁.2.le⟩, hj₂⟩ }
end
lemma crossing_eq_crossing_of_upper_crossing_time_lt {M : ℕ} (hNM : N ≤ M)
(h : upper_crossing_time a b f N (n + 1) ω < N) :
upper_crossing_time a b f M (n + 1) ω = upper_crossing_time a b f N (n + 1) ω ∧
lower_crossing_time a b f M n ω = lower_crossing_time a b f N n ω :=
begin
have := (crossing_eq_crossing_of_lower_crossing_time_lt hNM
(lt_of_le_of_lt lower_crossing_time_le_upper_crossing_time_succ h)).2,
refine ⟨_, this⟩,
rw [upper_crossing_time_succ_eq, upper_crossing_time_succ_eq, eq_comm, this],
refine hitting_eq_hitting_of_exists hNM _,
simp only [upper_crossing_time_succ_eq, hitting_lt_iff] at h,
obtain ⟨j, hj₁, hj₂⟩ := h,
exact ⟨j, ⟨hj₁.1, hj₁.2.le⟩, hj₂⟩
end
lemma upper_crossing_time_eq_upper_crossing_time_of_lt {M : ℕ} (hNM : N ≤ M)
(h : upper_crossing_time a b f N n ω < N) :
upper_crossing_time a b f M n ω = upper_crossing_time a b f N n ω :=
begin
cases n,
{ simp },
{ exact (crossing_eq_crossing_of_upper_crossing_time_lt hNM h).1 }
end
lemma upcrossings_before_mono (hab : a < b) :
monotone (λ N ω, upcrossings_before a b f N ω) :=
begin
intros N M hNM ω,
simp only [upcrossings_before],
by_cases hemp : {n : ℕ | upper_crossing_time a b f N n ω < N}.nonempty,
{ refine cSup_le_cSup (upper_crossing_time_lt_bdd_above hab) hemp (λ n hn, _),
rw [set.mem_set_of_eq, upper_crossing_time_eq_upper_crossing_time_of_lt hNM hn],
exact lt_of_lt_of_le hn hNM },
{ rw set.not_nonempty_iff_eq_empty at hemp,
simp [hemp, cSup_empty, bot_eq_zero', zero_le'] }
end
lemma upcrossings_before_lt_of_exists_upcrossing (hab : a < b) {N₁ N₂ : ℕ}
(hN₁: N ≤ N₁) (hN₁': f N₁ ω < a) (hN₂: N₁ ≤ N₂) (hN₂': b < f N₂ ω) :
upcrossings_before a b f N ω < upcrossings_before a b f (N₂ + 1) ω :=
begin
refine lt_of_lt_of_le (nat.lt_succ_self _) (le_cSup (upper_crossing_time_lt_bdd_above hab) _),
rw [set.mem_set_of_eq, upper_crossing_time_succ_eq, hitting_lt_iff _ le_rfl],
swap,
{ apply_instance },
{ refine ⟨N₂, ⟨_, nat.lt_succ_self _⟩, hN₂'.le⟩,
rw [lower_crossing_time, hitting_le_iff_of_lt _ (nat.lt_succ_self _)],
refine ⟨N₁, ⟨le_trans _ hN₁, hN₂⟩, hN₁'.le⟩,
by_cases hN : 0 < N,
{ have : upper_crossing_time a b f N (upcrossings_before a b f N ω) ω < N :=
nat.Sup_mem (upper_crossing_time_lt_nonempty hN) (upper_crossing_time_lt_bdd_above hab),
rw upper_crossing_time_eq_upper_crossing_time_of_lt
(hN₁.trans (hN₂.trans $ nat.le_succ _)) this,
exact this.le },
{ rw [not_lt, le_zero_iff] at hN,
rw [hN, upcrossings_before_zero, upper_crossing_time_zero],
refl } },
end
lemma lower_crossing_time_lt_of_lt_upcrossings_before
(hN : 0 < N) (hab : a < b) (hn : n < upcrossings_before a b f N ω) :
lower_crossing_time a b f N n ω < N :=
lt_of_le_of_lt lower_crossing_time_le_upper_crossing_time_succ
(upper_crossing_time_lt_of_le_upcrossings_before hN hab hn)
lemma le_sub_of_le_upcrossings_before
(hN : 0 < N) (hab : a < b) (hn : n < upcrossings_before a b f N ω) :
b - a ≤
stopped_value f (upper_crossing_time a b f N (n + 1)) ω -
stopped_value f (lower_crossing_time a b f N n) ω :=
sub_le_sub (stopped_value_upper_crossing_time
(upper_crossing_time_lt_of_le_upcrossings_before hN hab hn).ne)
(stopped_value_lower_crossing_time (lower_crossing_time_lt_of_lt_upcrossings_before hN hab hn).ne)
lemma sub_eq_zero_of_upcrossings_before_lt (hab : a < b) (hn : upcrossings_before a b f N ω < n) :
stopped_value f (upper_crossing_time a b f N (n + 1)) ω -
stopped_value f (lower_crossing_time a b f N n) ω = 0 :=
begin
have : N ≤ upper_crossing_time a b f N n ω,
{ rw upcrossings_before at hn,
rw ← not_lt,
exact λ h, not_le.2 hn (le_cSup (upper_crossing_time_lt_bdd_above hab) h) },
simp [stopped_value, upper_crossing_time_stabilize' (nat.le_succ n) this,
lower_crossing_time_stabilize' le_rfl
(le_trans this upper_crossing_time_le_lower_crossing_time)]
end
lemma mul_upcrossings_before_le (hf : a ≤ f N ω) (hab : a < b) :
(b - a) * upcrossings_before a b f N ω ≤
∑ k in finset.range N, upcrossing_strat a b f N k ω * (f (k + 1) - f k) ω :=
begin
classical,
by_cases hN : N = 0,
{ simp [hN] },
simp_rw [upcrossing_strat, finset.sum_mul, ← set.indicator_mul_left, pi.one_apply,
pi.sub_apply, one_mul],
rw finset.sum_comm,
have h₁ : ∀ k, ∑ n in finset.range N,
(set.Ico (lower_crossing_time a b f N k ω) (upper_crossing_time a b f N (k + 1) ω)).indicator
(λ m, f (m + 1) ω - f m ω) n =
stopped_value f (upper_crossing_time a b f N (k + 1)) ω -
stopped_value f (lower_crossing_time a b f N k) ω,
{ intro k,
rw [finset.sum_indicator_eq_sum_filter, (_ : (finset.filter
(λ i, i ∈ set.Ico (lower_crossing_time a b f N k ω) (upper_crossing_time a b f N (k + 1) ω))
(finset.range N)) =
finset.Ico (lower_crossing_time a b f N k ω) (upper_crossing_time a b f N (k + 1) ω)),
finset.sum_Ico_eq_add_neg _ lower_crossing_time_le_upper_crossing_time_succ,
finset.sum_range_sub (λ n, f n ω), finset.sum_range_sub (λ n, f n ω), neg_sub,
sub_add_sub_cancel],
{ refl },
{ ext i,
simp only [set.mem_Ico, finset.mem_filter, finset.mem_range, finset.mem_Ico,
and_iff_right_iff_imp, and_imp],
exact λ _ h, lt_of_lt_of_le h upper_crossing_time_le } },
simp_rw [h₁],
have h₂ : ∑ k in finset.range (upcrossings_before a b f N ω), (b - a) ≤
∑ k in finset.range N,
(stopped_value f (upper_crossing_time a b f N (k + 1)) ω -
stopped_value f (lower_crossing_time a b f N k) ω),
{ calc ∑ k in finset.range (upcrossings_before a b f N ω), (b - a)
≤ ∑ k in finset.range (upcrossings_before a b f N ω),
(stopped_value f (upper_crossing_time a b f N (k + 1)) ω -
stopped_value f (lower_crossing_time a b f N k) ω) :
begin
refine finset.sum_le_sum (λ i hi, le_sub_of_le_upcrossings_before (zero_lt_iff.2 hN) hab _),
rwa finset.mem_range at hi,
end
...≤ ∑ k in finset.range N,
(stopped_value f (upper_crossing_time a b f N (k + 1)) ω -
stopped_value f (lower_crossing_time a b f N k) ω) :
begin
refine finset.sum_le_sum_of_subset_of_nonneg
(finset.range_subset.2 (upcrossings_before_le f ω hab)) (λ i _ hi, _),
by_cases hi' : i = upcrossings_before a b f N ω,
{ subst hi',
simp only [stopped_value],
rw upper_crossing_time_eq_of_upcrossings_before_lt hab (nat.lt_succ_self _),
by_cases heq : lower_crossing_time a b f N (upcrossings_before a b f N ω) ω = N,
{ rw [heq, sub_self] },
{ rw sub_nonneg,
exact le_trans (stopped_value_lower_crossing_time heq) hf } },
{ rw sub_eq_zero_of_upcrossings_before_lt hab,
rw [finset.mem_range, not_lt] at hi,
exact lt_of_le_of_ne hi (ne.symm hi') },
end },
refine le_trans _ h₂,
rw [finset.sum_const, finset.card_range, nsmul_eq_mul, mul_comm],
end
lemma integral_mul_upcrossings_before_le_integral [is_finite_measure μ]
(hf : submartingale f ℱ μ) (hfN : ∀ ω, a ≤ f N ω) (hfzero : 0 ≤ f 0) (hab : a < b) :
(b - a) * μ[upcrossings_before a b f N] ≤ μ[f N] :=
calc (b - a) * μ[upcrossings_before a b f N]
≤ μ[∑ k in finset.range N, upcrossing_strat a b f N k * (f (k + 1) - f k)] :
begin
rw ← integral_mul_left,
refine integral_mono_of_nonneg _ ((hf.sum_upcrossing_strat_mul a b N).integrable N) _,
{ exact eventually_of_forall (λ ω, mul_nonneg (sub_nonneg.2 hab.le) (nat.cast_nonneg _)) },
{ refine eventually_of_forall (λ ω, _),
simpa using mul_upcrossings_before_le (hfN ω) hab },
end
...≤ μ[f N] - μ[f 0] : hf.sum_mul_upcrossing_strat_le
...≤ μ[f N] : (sub_le_self_iff _).2 (integral_nonneg hfzero)
lemma crossing_pos_eq (hab : a < b) :
upper_crossing_time 0 (b - a) (λ n ω, (f n ω - a)⁺) N n = upper_crossing_time a b f N n ∧
lower_crossing_time 0 (b - a) (λ n ω, (f n ω - a)⁺) N n = lower_crossing_time a b f N n :=
begin
have hab' : 0 < b - a := sub_pos.2 hab,
have hf : ∀ ω i, b - a ≤ (f i ω - a)⁺ ↔ b ≤ f i ω,
{ intros i ω,
refine ⟨λ h, _, λ h, _⟩,
{ rwa [← sub_le_sub_iff_right a,
← lattice_ordered_comm_group.pos_eq_self_of_pos_pos (lt_of_lt_of_le hab' h)] },
{ rw ← sub_le_sub_iff_right a at h,
rwa lattice_ordered_comm_group.pos_of_nonneg _ (le_trans hab'.le h) } },
have hf' : ∀ ω i, (f i ω - a)⁺ ≤ 0 ↔ f i ω ≤ a,
{ intros ω i,
rw [lattice_ordered_comm_group.pos_nonpos_iff, sub_nonpos] },
induction n with k ih,
{ refine ⟨rfl, _⟩,
simp only [lower_crossing_time_zero, hitting, set.mem_Icc, set.mem_Iic],
ext ω,
split_ifs with h₁ h₂ h₂,
{ simp_rw [hf'] },
{ simp_rw [set.mem_Iic, ← hf' _ _] at h₂,
exact false.elim (h₂ h₁) },
{ simp_rw [set.mem_Iic, hf' _ _] at h₁,
exact false.elim (h₁ h₂) },
{ refl } },
{ have : upper_crossing_time 0 (b - a) (λ n ω, (f n ω - a)⁺) N (k + 1) =
upper_crossing_time a b f N (k + 1),
{ ext ω,
simp only [upper_crossing_time_succ_eq, ← ih.2, hitting, set.mem_Ici, tsub_le_iff_right],
split_ifs with h₁ h₂ h₂,
{ simp_rw [← sub_le_iff_le_add, hf ω] },
{ simp_rw [set.mem_Ici, ← hf _ _] at h₂,
exact false.elim (h₂ h₁) },
{ simp_rw [set.mem_Ici, hf _ _] at h₁,
exact false.elim (h₁ h₂) },
{ refl } },
refine ⟨this, _⟩,
ext ω,
simp only [lower_crossing_time, this, hitting, set.mem_Iic],
split_ifs with h₁ h₂ h₂,
{ simp_rw [hf' ω] },
{ simp_rw [set.mem_Iic, ← hf' _ _] at h₂,
exact false.elim (h₂ h₁) },
{ simp_rw [set.mem_Iic, hf' _ _] at h₁,
exact false.elim (h₁ h₂) },
{ refl } }
end
lemma upcrossings_before_pos_eq (hab : a < b) :
upcrossings_before 0 (b - a) (λ n ω, (f n ω - a)⁺) N ω = upcrossings_before a b f N ω :=
by simp_rw [upcrossings_before, (crossing_pos_eq hab).1]
lemma mul_integral_upcrossings_before_le_integral_pos_part_aux [is_finite_measure μ]
(hf : submartingale f ℱ μ) (hab : a < b) :
(b - a) * μ[upcrossings_before a b f N] ≤ μ[λ ω, (f N ω - a)⁺] :=
begin
refine le_trans (le_of_eq _) (integral_mul_upcrossings_before_le_integral
(hf.sub_martingale (martingale_const _ _ _)).pos
(λ ω, lattice_ordered_comm_group.pos_nonneg _)
(λ ω, lattice_ordered_comm_group.pos_nonneg _) (sub_pos.2 hab)),
simp_rw [sub_zero, ← upcrossings_before_pos_eq hab],
refl,
end
/-- **Doob's upcrossing estimate**: given a real valued discrete submartingale `f` and real
values `a` and `b`, we have `(b - a) * 𝔼[upcrossings_before a b f N] ≤ 𝔼[(f N - a)⁺]` where
`upcrossings_before a b f N` is the number of times the process `f` crossed from below `a` to above
`b` before the time `N`. -/
theorem submartingale.mul_integral_upcrossings_before_le_integral_pos_part [is_finite_measure μ]
(a b : ℝ) (hf : submartingale f ℱ μ) (N : ℕ) :
(b - a) * μ[upcrossings_before a b f N] ≤ μ[λ ω, (f N ω - a)⁺] :=
begin
by_cases hab : a < b,
{ exact mul_integral_upcrossings_before_le_integral_pos_part_aux hf hab },
{ rw [not_lt, ← sub_nonpos] at hab,
exact le_trans (mul_nonpos_of_nonpos_of_nonneg hab (integral_nonneg (λ ω, nat.cast_nonneg _)))
(integral_nonneg (λ ω, lattice_ordered_comm_group.pos_nonneg _)) }
end
/-!
### Variant of the upcrossing estimate
Now, we would like to prove a variant of the upcrossing estimate obtained by taking the supremum
over $N$ of the original upcrossing estimate. Namely, we want the inequality
$$
(b - a) \sup_N \mathbb{E}[U_N(a, b)] \le \sup_N \mathbb{E}[f_N].
$$
This inequality is central for the martingale convergence theorem as it provides a uniform bound
for the upcrossings.
We note that on top of taking the supremum on both sides of the inequality, we had also used
the monotone convergence theorem on the left hand side to take the supremum outside of the
integral. To do this, we need to make sure $U_N(a, b)$ is measurable and integrable. Integrability
is easy to check as $U_N(a, b) ≤ N$ and so it suffices to show measurability. Indeed, by
noting that
$$
U_N(a, b) = \sum_{i = 1}^N \mathbf{1}_{\{U_N(a, b) < N\}}
$$
$U_N(a, b)$ is measurable as $\{U_N(a, b) < N\}$ is a measurable set since $U_N(a, b)$ is a
stopping time.
-/
lemma upcrossings_before_eq_sum (hab : a < b) :
upcrossings_before a b f N ω =
∑ i in finset.Ico 1 (N + 1), {n | upper_crossing_time a b f N n ω < N}.indicator 1 i :=
begin
by_cases hN : N = 0,
{ simp [hN] },
rw ← finset.sum_Ico_consecutive _ (nat.succ_le_succ zero_le')
(nat.succ_le_succ (upcrossings_before_le f ω hab)),
have h₁ : ∀ k ∈ finset.Ico 1 (upcrossings_before a b f N ω + 1),
{n : ℕ | upper_crossing_time a b f N n ω < N}.indicator 1 k = 1,
{ rintro k hk,
rw finset.mem_Ico at hk,
rw set.indicator_of_mem,
{ refl },
{ exact upper_crossing_time_lt_of_le_upcrossings_before (zero_lt_iff.2 hN) hab
(nat.lt_succ_iff.1 hk.2) } },
have h₂ : ∀ k ∈ finset.Ico (upcrossings_before a b f N ω + 1) (N + 1),
{n : ℕ | upper_crossing_time a b f N n ω < N}.indicator 1 k = 0,
{ rintro k hk,
rw [finset.mem_Ico, nat.succ_le_iff] at hk,
rw set.indicator_of_not_mem,
simp only [set.mem_set_of_eq, not_lt],
exact (upper_crossing_time_eq_of_upcrossings_before_lt hab hk.1).symm.le },
rw [finset.sum_congr rfl h₁, finset.sum_congr rfl h₂, finset.sum_const, finset.sum_const,
smul_eq_mul, mul_one, smul_eq_mul, mul_zero, nat.card_Ico, nat.add_succ_sub_one,
add_zero, add_zero],
end
lemma adapted.measurable_upcrossings_before (hf : adapted ℱ f) (hab : a < b) :
measurable (upcrossings_before a b f N) :=
begin
have : upcrossings_before a b f N =
λ ω, ∑ i in finset.Ico 1 (N + 1), {n | upper_crossing_time a b f N n ω < N}.indicator 1 i,
{ ext ω,
exact upcrossings_before_eq_sum hab },
rw this,
exact finset.measurable_sum _ (λ i hi, measurable.indicator measurable_const $
ℱ.le N _ (hf.is_stopping_time_upper_crossing_time.measurable_set_lt_of_pred N))
end
lemma adapted.integrable_upcrossings_before [is_finite_measure μ]
(hf : adapted ℱ f) (hab : a < b) :
integrable (λ ω, (upcrossings_before a b f N ω : ℝ)) μ :=
begin
have : ∀ᵐ ω ∂μ, ∥(upcrossings_before a b f N ω : ℝ)∥ ≤ N,
{ refine eventually_of_forall (λ ω, _),
rw [real.norm_eq_abs, nat.abs_cast, nat.cast_le],
refine upcrossings_before_le _ _ hab },
exact ⟨measurable.ae_strongly_measurable
(measurable_from_top.comp (hf.measurable_upcrossings_before hab)),
has_finite_integral_of_bounded this⟩
end
/-- The number of upcrossings of a realization of a stochastic process (`upcrossing` takes value
in `ℝ≥0∞` and so is allowed to be `∞`). -/
noncomputable def upcrossings [preorder ι] [order_bot ι] [has_Inf ι]
(a b : ℝ) (f : ι → Ω → ℝ) (ω : Ω) : ℝ≥0∞ :=
⨆ N, (upcrossings_before a b f N ω : ℝ≥0∞)
lemma adapted.measurable_upcrossings (hf : adapted ℱ f) (hab : a < b) :
measurable (upcrossings a b f) :=
measurable_supr (λ N, measurable_from_top.comp (hf.measurable_upcrossings_before hab))
lemma upcrossings_lt_top_iff :
upcrossings a b f ω < ∞ ↔ ∃ k, ∀ N, upcrossings_before a b f N ω ≤ k :=
begin
have : upcrossings a b f ω < ∞ ↔ ∃ k : ℝ≥0, upcrossings a b f ω ≤ k,
{ split,
{ intro h,
lift upcrossings a b f ω to ℝ≥0 using h.ne with r hr,
exact ⟨r, le_rfl⟩ },
{ rintro ⟨k, hk⟩,
exact lt_of_le_of_lt hk ennreal.coe_lt_top } },
simp_rw [this, upcrossings, supr_le_iff],
split; rintro ⟨k, hk⟩,
{ obtain ⟨m, hm⟩ := exists_nat_ge k,
refine ⟨m, λ N, ennreal.coe_nat_le_coe_nat.1 ((hk N).trans _)⟩,
rwa [← ennreal.coe_nat, ennreal.coe_le_coe] },
{ refine ⟨k, λ N, _⟩,
simp only [ennreal.coe_nat, ennreal.coe_nat_le_coe_nat, hk N] }
end
/-- A variant of Doob's upcrossing estimate obtained by taking the supremum on both sides. -/
lemma submartingale.mul_lintegral_upcrossings_le_lintegral_pos_part [is_finite_measure μ]
(a b : ℝ) (hf : submartingale f ℱ μ) :
ennreal.of_real (b - a) * ∫⁻ ω, upcrossings a b f ω ∂μ ≤
⨆ N, ∫⁻ ω, ennreal.of_real ((f N ω - a)⁺) ∂μ :=
begin
by_cases hab : a < b,
{ simp_rw [upcrossings],
have : ∀ N, ∫⁻ ω, ennreal.of_real ((f N ω - a)⁺) ∂μ = ennreal.of_real (∫ ω, (f N ω - a)⁺ ∂μ),
{ intro N,
rw of_real_integral_eq_lintegral_of_real,
{ exact (hf.sub_martingale (martingale_const _ _ _)).pos.integrable _ },
{ exact eventually_of_forall (λ ω, lattice_ordered_comm_group.pos_nonneg _) } },
rw lintegral_supr',
{ simp_rw [this, ennreal.mul_supr, supr_le_iff],
intro N,
rw [(by simp : ∫⁻ ω, upcrossings_before a b f N ω ∂μ =
∫⁻ ω, ↑(upcrossings_before a b f N ω : ℝ≥0) ∂μ), lintegral_coe_eq_integral,
← ennreal.of_real_mul (sub_pos.2 hab).le],
{ simp_rw [nnreal.coe_nat_cast],
exact (ennreal.of_real_le_of_real
(hf.mul_integral_upcrossings_before_le_integral_pos_part a b N)).trans (le_supr _ N) },
{ simp only [nnreal.coe_nat_cast, hf.adapted.integrable_upcrossings_before hab] } },
{ exact λ n, measurable_from_top.comp_ae_measurable
(hf.adapted.measurable_upcrossings_before hab).ae_measurable },
{ refine eventually_of_forall (λ ω N M hNM, _),
rw ennreal.coe_nat_le_coe_nat,
exact upcrossings_before_mono hab hNM ω } },
{ rw [not_lt, ← sub_nonpos] at hab,
rw [ennreal.of_real_of_nonpos hab, zero_mul],
exact zero_le _ }
end
end measure_theory
|
79f4eeb00e25d0e91a27f79e864fb04ea703159e
|
29cc89d6158dd3b90acbdbcab4d2c7eb9a7dbf0f
|
/Exercises week 6/23_homework_sheet.lean
|
71063c69e9defa1d94c7a636b295a0245938c8c6
|
[] |
no_license
|
KjellZijlemaker/Logical_Verification_VU
|
ced0ba95316a30e3c94ba8eebd58ea004fa6f53b
|
4578b93bf1615466996157bb333c84122b201d99
|
refs/heads/master
| 1,585,966,086,108
| 1,549,187,704,000
| 1,549,187,704,000
| 155,690,284
| 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 3,144
|
lean
|
/- Homework 2.3: Functional Programming — Monads -/
namespace homework
/- Question 1: `map` for monads
Define `map` for monads. This is the generalization of `map` on lists. Use the monad operations to
define `map`. The _functorial properties_ (`map_id` and `map_map`) are derived from the monad laws.
This time, we use Lean's monad definition. In combination, `monad` and `is_lawful_monad` include the
same constants, laws, and syntactic sugar as the `monad` type class from the lecture. -/
section map
variables {M : Type → Type} [monad M] [is_lawful_monad M]
/- 1.1. Define `map` on `M`.
**Hint:** The challenge is to find a way to create `M β`. Follow the types. -/
def map {α β} (f : α → β) (m : M α) : M β:=
do a <- m,
return (f a)
/- 1.2. Prove the identity law for `map`. -/
lemma map_id {α} (m : M α) : map id m = m := by simp[map]
/- 1.3. Prove the composition law for `map`. -/
lemma map_map {α β γ} (f : α → β) (g : β → γ) (m : M α) :
map g (map f m) = map (g ∘ f) m :=
begin
simp[map, return],
end
end map
/- Question 2: Monadic structure on lists -/
/- `list` can be seen as a monad, similar to `option` but with several possible outcomes. It is also
similar to `set`, but the results are ordered and finite. The code below sets `list` up as a
monad. -/
namespace list
protected def bind {α β : Type} : list α → (α → list β) → list β
| [] f := []
| (a :: l) f := f a ++ bind l f
protected def pure {α : Type} (a : α) : list α := [a]
lemma pure_eq_singleton {α} (a : α) : pure a = [a] :=
by refl
instance : monad list :=
{ pure := @list.pure,
bind := @list.bind }
/- 2.1. Prove the following properties of `bind` under the empty list (`[]`), the list constructor
(`::`), and `++`. -/
@[simp] lemma bind_nil {α β} (f : α → list β) : [] >>= f = [] := by refl
@[simp] lemma bind_cons {α β} (f : α → list β) (a : α) (l : list α) :
(a :: l) >>= f = f a ++ (l >>= f) := by simp[bind]
@[simp] lemma bind_append {α β} (f : α → list β) :
∀l l':list α, (l ++ l') >>= f = (l >>= f) ++ (l' >>= f):=
begin
intros a b,
simp[bind]
end
/- 2.2. Prove the monadic laws for `list`.
**Hint:** The simplifier cannot see through the type class definition of `pure`. You can use
`pure_eq_singleton` to unfold the definition or `show` to state the lemma statement using `bind` and
`[...]`. -/
lemma pure_bind {α β} (a : α) (f : α → list β) : (pure a >>= f) = f a := by simp[pure_eq_singleton]
lemma bind_pure {α} : ∀l : list α, l >>= pure = l := by simp[pure_eq_singleton]
lemma bind_assoc {α β γ} (f : α → list β) (g : β → list γ) :
∀l : list α, (l >>= f) >>= g = l >>= (λa, f a >>= g)
| [] := by refl
| (x :: xs) := by simp[bind_assoc xs]
lemma bind_pure_comp_eq_map {α β} {f : α → β} :
∀l : list α, l >>= (pure ∘ f) = list.map f l
| [] := by refl
| (x :: xs) := begin simp[bind_pure_comp_eq_map xs], simp[pure], simp[list.ret] end
/- 2.3 **optional**. Register `list` as a lawful monad. This may be a challenge. -/
instance : is_lawful_monad list :=
sorry
end list
end homework
|
edb3d19734821c32495e2af707196f43cfbe1bfe
|
6b45072eb2b3db3ecaace2a7a0241ce81f815787
|
/data/num/lemmas.lean
|
783cbd70f230df4006ffb62a9b8d9b336e13c3fe
|
[] |
no_license
|
avigad/library_dev
|
27b47257382667b5eb7e6476c4f5b0d685dd3ddc
|
9d8ac7c7798ca550874e90fed585caad030bbfac
|
refs/heads/master
| 1,610,452,468,791
| 1,500,712,839,000
| 1,500,713,478,000
| 69,311,142
| 1
| 0
| null | 1,474,942,903,000
| 1,474,942,902,000
| null |
UTF-8
|
Lean
| false
| false
| 20,204
|
lean
|
/-
Copyright (c) 2014 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Mario Carneiro
Properties of the binary representation of integers.
-/
import .basic .bitwise pending
meta def unfold_coe : tactic unit :=
`[unfold coe lift_t has_lift_t.lift coe_t has_coe_t.coe coe_b has_coe.coe]
namespace pos_num
theorem one_to_nat : ((1 : pos_num) : ℕ) = 1 := rfl
theorem bit_to_nat (b n) : (bit b n : ℕ) = nat.bit b n :=
by cases b; refl
theorem succ_to_nat : ∀ n, (succ n : ℕ) = n + 1
| 1 := rfl
| (bit0 p) := rfl
| (bit1 p) := (congr_arg _root_.bit0 (succ_to_nat p)).trans $
show ↑p + 1 + ↑p + 1 = ↑p + ↑p + 1 + 1, by simp
theorem add_one (n : pos_num) : n + 1 = succ n := by cases n; refl
theorem one_add (n : pos_num) : 1 + n = succ n := by cases n; refl
theorem add_to_nat : ∀ m n, ((m + n : pos_num) : ℕ) = m + n
| 1 b := by rw [one_add b, succ_to_nat, add_comm]; refl
| a 1 := by rw [add_one a, succ_to_nat]; refl
| (bit0 a) (bit0 b) := (congr_arg _root_.bit0 (add_to_nat a b)).trans $
show ((a + b) + (a + b) : ℕ) = (a + a) + (b + b), by simp
| (bit0 a) (bit1 b) := (congr_arg _root_.bit1 (add_to_nat a b)).trans $
show ((a + b) + (a + b) + 1 : ℕ) = (a + a) + (b + b + 1), by simp
| (bit1 a) (bit0 b) := (congr_arg _root_.bit1 (add_to_nat a b)).trans $
show ((a + b) + (a + b) + 1 : ℕ) = (a + a + 1) + (b + b), by simp
| (bit1 a) (bit1 b) :=
show (succ (a + b) + succ (a + b) : ℕ) = (a + a + 1) + (b + b + 1),
by rw [succ_to_nat, add_to_nat]; simp
theorem add_succ : ∀ (m n : pos_num), m + succ n = succ (m + n)
| 1 b := by simp [one_add]
| (bit0 a) 1 := congr_arg bit0 (add_one a)
| (bit1 a) 1 := congr_arg bit1 (add_one a)
| (bit0 a) (bit0 b) := rfl
| (bit0 a) (bit1 b) := congr_arg bit0 (add_succ a b)
| (bit1 a) (bit0 b) := rfl
| (bit1 a) (bit1 b) := congr_arg bit1 (add_succ a b)
theorem bit0_of_bit0 : Π n, _root_.bit0 n = bit0 n
| 1 := rfl
| (bit0 p) := congr_arg bit0 (bit0_of_bit0 p)
| (bit1 p) := show bit0 (succ (_root_.bit0 p)) = _, by rw bit0_of_bit0; refl
theorem bit1_of_bit1 (n : pos_num) : _root_.bit1 n = bit1 n :=
show _root_.bit0 n + 1 = bit1 n, by rw [add_one, bit0_of_bit0]; refl
theorem to_nat_pos : ∀ n : pos_num, (n : ℕ) > 0
| 1 := dec_trivial
| (bit0 p) := let h := to_nat_pos p in add_pos h h
| (bit1 p) := nat.succ_pos _
theorem pred'_to_nat : ∀ n, (option.cases_on (pred' n) ((n : ℕ) = 1) (λm, (m : ℕ) = nat.pred n) : Prop)
| 1 := rfl
| (pos_num.bit1 q) := rfl
| (pos_num.bit0 q) :=
suffices _ → ((option.cases_on (pred' q) 1 bit1 : pos_num) : ℕ) = nat.pred (bit0 q),
from this (pred'_to_nat q),
match pred' q with
| none, (IH : (q : ℕ) = 1) := show 1 = nat.pred (q + q), by rw IH; refl
| some p, (IH : ↑p = nat.pred q) :=
show _root_.bit1 ↑p = nat.pred (q + q), begin
rw [←nat.succ_pred_eq_of_pos (to_nat_pos q), IH],
generalize : nat.pred q = n,
simp [_root_.bit1, _root_.bit0]
end
end
theorem mul_to_nat (m) : ∀ n, ((m * n : pos_num) : ℕ) = m * n
| 1 := (mul_one _).symm
| (bit0 p) := show (↑(m * p) + ↑(m * p) : ℕ) = ↑m * (p + p), by rw [mul_to_nat, left_distrib]
| (bit1 p) := (add_to_nat (bit0 (m * p)) m).trans $
show (↑(m * p) + ↑(m * p) + ↑m : ℕ) = ↑m * (p + p) + m, by rw [mul_to_nat, left_distrib]
end pos_num
namespace num
open pos_num
theorem zero_to_nat : ((0 : num) : ℕ) = 0 := rfl
theorem one_to_nat : ((1 : num) : ℕ) = 1 := rfl
theorem bit_to_nat (b n) : (bit b n : ℕ) = nat.bit b n :=
by cases b; cases n; refl
theorem add_to_nat : ∀ m n, ((m + n : num) : ℕ) = m + n
| 0 0 := rfl
| 0 (pos q) := (zero_add _).symm
| (pos p) 0 := rfl
| (pos p) (pos q) := pos_num.add_to_nat _ _
theorem add_zero (n : num) : n + 0 = n := by cases n; refl
theorem zero_add (n : num) : 0 + n = n := by cases n; refl
theorem add_succ : ∀ (m n : num), m + succ n = succ (m + n)
| 0 n := by simp [zero_add]
| (pos p) 0 := show pos (p + 1) = succ (pos p + 0), by rw [add_one, add_zero]; refl
| (pos p) (pos q) := congr_arg pos (pos_num.add_succ _ _)
theorem succ'_to_nat : ∀ n, (succ' n : ℕ) = n + 1
| 0 := rfl
| (pos p) := pos_num.succ_to_nat _
theorem succ_to_nat (n) : (succ n : ℕ) = n + 1 := succ'_to_nat n
@[simp] theorem to_of_nat : Π (n : ℕ), ((n : num) : ℕ) = n
| 0 := rfl
| (n+1) := (succ_to_nat (num.of_nat n)).trans (congr_arg nat.succ (to_of_nat n))
theorem of_nat_inj : ∀ {m n : ℕ}, (m : num) = n → m = n :=
function.injective_of_left_inverse to_of_nat
theorem add_of_nat (m) : ∀ n, ((m + n : ℕ) : num) = m + n
| 0 := (add_zero _).symm
| (n+1) := show succ (m + n : ℕ) = m + succ n,
by rw [add_succ, add_of_nat]
theorem mul_to_nat : ∀ m n, ((m * n : num) : ℕ) = m * n
| 0 0 := rfl
| 0 (pos q) := (zero_mul _).symm
| (pos p) 0 := rfl
| (pos p) (pos q) := pos_num.mul_to_nat _ _
end num
namespace pos_num
open num
@[simp] theorem of_to_nat : Π (n : pos_num), ((n : ℕ) : num) = pos n
| 1 := rfl
| (bit0 p) :=
show ↑(p + p : ℕ) = pos (bit0 p),
by rw [add_of_nat, of_to_nat]; exact congr_arg pos p.bit0_of_bit0
| (bit1 p) :=
show num.succ (p + p : ℕ) = pos (bit1 p),
by rw [add_of_nat, of_to_nat]; exact congr_arg (num.pos ∘ succ) p.bit0_of_bit0
theorem to_nat_inj {m n : pos_num} (h : (m : ℕ) = n) : m = n :=
by have := congr_arg (coe : ℕ → num) h; simp at this; injection this
theorem pred_to_nat {n : pos_num} (h : n > 1) : (pred n : ℕ) = nat.pred n :=
begin
unfold pred,
have := pred'_to_nat n, revert this,
cases pred' n; dsimp [option.get_or_else],
{ intro this, rw @to_nat_inj n 1 this at h,
exact absurd h dec_trivial },
{ exact id }
end
theorem cmp_swap (m) : ∀n, (cmp m n).swap = cmp n m :=
by induction m with m IH m IH; intro n;
cases n with n n; try {unfold cmp}; try {refl}; rw ←IH; cases cmp m n; refl
lemma cmp_dec_lemma {m n} : m < n → bit1 m < bit0 n :=
show (m:ℕ) < n → (m + m + 1 + 1 : ℕ) ≤ n + n,
by intro h; rw [nat.add_right_comm m m 1, add_assoc]; exact add_le_add h h
theorem cmp_dec : ∀ (m n), (ordering.cases_on (cmp m n) (m < n) (m = n) (m > n) : Prop)
| 1 1 := rfl
| (bit0 a) 1 := let h : (1:ℕ) ≤ a := to_nat_pos a in add_le_add h h
| (bit1 a) 1 := nat.succ_lt_succ $ to_nat_pos $ bit0 a
| 1 (bit0 b) := let h : (1:ℕ) ≤ b := to_nat_pos b in add_le_add h h
| 1 (bit1 b) := nat.succ_lt_succ $ to_nat_pos $ bit0 b
| (bit0 a) (bit0 b) := begin
have := cmp_dec a b, revert this, cases cmp a b; dsimp; intro,
{ exact @add_lt_add nat _ _ _ _ _ this this },
{ rw this },
{ exact @add_lt_add nat _ _ _ _ _ this this }
end
| (bit0 a) (bit1 b) := begin dsimp [cmp],
have := cmp_dec a b, revert this, cases cmp a b; dsimp; intro,
{ exact nat.le_succ_of_le (@add_lt_add nat _ _ _ _ _ this this) },
{ rw this, apply nat.lt_succ_self },
{ exact cmp_dec_lemma this }
end
| (bit1 a) (bit0 b) := begin dsimp [cmp],
have := cmp_dec a b, revert this, cases cmp a b; dsimp; intro,
{ exact cmp_dec_lemma this },
{ rw this, apply nat.lt_succ_self },
{ exact nat.le_succ_of_le (@add_lt_add nat _ _ _ _ _ this this) },
end
| (bit1 a) (bit1 b) := begin
have := cmp_dec a b, revert this, cases cmp a b; dsimp; intro,
{ exact nat.succ_lt_succ (add_lt_add this this) },
{ rw this },
{ exact nat.succ_lt_succ (add_lt_add this this) }
end
theorem lt_iff_cmp {m n} : m < n ↔ cmp m n = ordering.lt :=
match cmp m n, cmp_dec m n with
| ordering.lt, (h : m < n) := ⟨λ_, rfl, λ_, h⟩
| ordering.eq, (h : m = n) :=
⟨λh', absurd h' $ by rw h; apply @lt_irrefl nat, dec_trivial⟩
| ordering.gt, (h : m > n) :=
⟨λh', absurd h' $ @not_lt_of_gt nat _ _ _ h, dec_trivial⟩
end
theorem le_iff_cmp {m n} : m ≤ n ↔ cmp m n ≠ ordering.gt :=
iff.trans ⟨@not_lt_of_ge nat _ _ _, le_of_not_gt⟩ $ not_congr $
lt_iff_cmp.trans $ by rw ←cmp_swap; cases cmp m n; exact dec_trivial
instance decidable_lt : @decidable_rel pos_num (<) := λ m n,
decidable_of_decidable_of_iff (by apply_instance) lt_iff_cmp.symm
instance decidable_le : @decidable_rel pos_num (≤) := λ m n,
decidable_of_decidable_of_iff (by apply_instance) le_iff_cmp.symm
meta def transfer_rw : tactic unit :=
`[repeat {rw add_to_nat <|> rw mul_to_nat <|> rw one_to_nat <|> rw zero_to_nat}]
meta def transfer : tactic unit := `[intros, apply to_nat_inj, transfer_rw, try {simp}]
instance : add_comm_semigroup pos_num :=
{ add := (+),
add_assoc := by transfer,
add_comm := by transfer }
instance : comm_monoid pos_num :=
{ mul := (*),
mul_assoc := by transfer,
one := 1,
one_mul := by transfer,
mul_one := by transfer,
mul_comm := by transfer }
instance : distrib pos_num :=
{ add := (+),
mul := (*),
left_distrib := by {transfer, simp [left_distrib]},
right_distrib := by {transfer, simp [left_distrib]} }
-- TODO(Mario): Prove these using transfer tactic
instance : decidable_linear_order pos_num :=
{ lt := (<),
le := (≤),
le_refl := λa, @le_refl nat _ _,
le_trans := λa b c, @le_trans nat _ _ _ _,
le_antisymm := λa b h1 h2, to_nat_inj $ @le_antisymm nat _ _ _ h1 h2,
le_total := λa b, @le_total nat _ _ _,
le_iff_lt_or_eq := λa b, le_iff_lt_or_eq.trans $ or_congr iff.rfl ⟨to_nat_inj, congr_arg _⟩,
lt_irrefl := λ a, @lt_irrefl nat _ _,
decidable_lt := by apply_instance,
decidable_le := by apply_instance,
decidable_eq := by apply_instance }
end pos_num
namespace num
open pos_num
@[simp] theorem of_to_nat : Π (n : num), ((n : ℕ) : num) = n
| 0 := rfl
| (pos p) := p.of_to_nat
theorem to_nat_inj : ∀ {m n : num}, (m : ℕ) = n → m = n :=
function.injective_of_left_inverse of_to_nat
theorem pred_to_nat : ∀ (n : num), (pred n : ℕ) = nat.pred n
| 0 := rfl
| (pos p) :=
suffices _ → ↑(option.cases_on (pred' p) 0 pos : num) = nat.pred p,
from this (pred'_to_nat p),
by { cases pred' p; dsimp [option.get_or_else]; intro h, rw h; refl, exact h }
theorem cmp_swap (m n) : (cmp m n).swap = cmp n m :=
by cases m; cases n; try {unfold cmp}; try {refl}; apply pos_num.cmp_swap
theorem cmp_dec : ∀ (m n), (ordering.cases_on (cmp m n) (m < n) (m = n) (m > n) : Prop)
| 0 0 := rfl
| 0 (pos b) := to_nat_pos _
| (pos a) 0 := to_nat_pos _
| (pos a) (pos b) :=
by { have := pos_num.cmp_dec a b; revert this; dsimp [cmp];
cases pos_num.cmp a b, exacts [id, congr_arg pos, id] }
theorem lt_iff_cmp {m n} : m < n ↔ cmp m n = ordering.lt :=
match cmp m n, cmp_dec m n with
| ordering.lt, (h : m < n) := ⟨λ_, rfl, λ_, h⟩
| ordering.eq, (h : m = n) :=
⟨λh', absurd h' $ by rw h; apply @lt_irrefl nat, dec_trivial⟩
| ordering.gt, (h : m > n) :=
⟨λh', absurd h' $ @not_lt_of_gt nat _ _ _ h, dec_trivial⟩
end
theorem le_iff_cmp {m n} : m ≤ n ↔ cmp m n ≠ ordering.gt :=
iff.trans ⟨@not_lt_of_ge nat _ _ _, le_of_not_gt⟩ $ not_congr $
lt_iff_cmp.trans $ by rw ←cmp_swap; cases cmp m n; exact dec_trivial
instance decidable_lt : @decidable_rel num (<) := λ m n,
decidable_of_decidable_of_iff (by apply_instance) lt_iff_cmp.symm
instance decidable_le : @decidable_rel num (≤) := λ m n,
decidable_of_decidable_of_iff (by apply_instance) le_iff_cmp.symm
meta def transfer_rw : tactic unit :=
`[repeat {rw add_to_nat <|> rw mul_to_nat <|> rw one_to_nat <|> rw zero_to_nat}]
meta def transfer : tactic unit := `[intros, apply to_nat_inj, transfer_rw, try {simp}]
instance : comm_semiring num :=
{ add := (+),
add_assoc := by transfer,
zero := 0,
zero_add := zero_add,
add_zero := add_zero,
add_comm := by transfer,
mul := (*),
mul_assoc := by transfer,
one := 1,
one_mul := by transfer,
mul_one := by transfer,
left_distrib := by {transfer, simp [left_distrib]},
right_distrib := by {transfer, simp [left_distrib]},
zero_mul := by transfer,
mul_zero := by transfer,
mul_comm := by transfer }
instance : decidable_linear_ordered_semiring num :=
{ num.comm_semiring with
add_left_cancel := λ a b c h, by { apply to_nat_inj,
have := congr_arg (coe : num → nat) h, revert this,
transfer_rw, apply add_left_cancel },
add_right_cancel := λ a b c h, by { apply to_nat_inj,
have := congr_arg (coe : num → nat) h, revert this,
transfer_rw, apply add_right_cancel },
lt := (<),
le := (≤),
le_refl := λa, @le_refl nat _ _,
le_trans := λa b c, @le_trans nat _ _ _ _,
le_antisymm := λa b h1 h2, to_nat_inj $ @le_antisymm nat _ _ _ h1 h2,
le_total := λa b, @le_total nat _ _ _,
le_iff_lt_or_eq := λa b, le_iff_lt_or_eq.trans $ or_congr iff.rfl ⟨to_nat_inj, congr_arg _⟩,
le_of_lt := λa b, @le_of_lt nat _ _ _,
lt_irrefl := λa, @lt_irrefl nat _ _,
lt_of_lt_of_le := λa b c, @lt_of_lt_of_le nat _ _ _ _,
lt_of_le_of_lt := λa b c, @lt_of_le_of_lt nat _ _ _ _,
lt_of_add_lt_add_left := λa b c, show (_:ℕ)<_→(_:ℕ)<_, by {transfer_rw, apply lt_of_add_lt_add_left},
add_lt_add_left := λa b h c, show (_:ℕ)<_, by {transfer_rw, apply @add_lt_add_left nat _ _ _ h},
add_le_add_left := λa b h c, show (_:ℕ)≤_, by {transfer_rw, apply @add_le_add_left nat _ _ _ h},
le_of_add_le_add_left := λa b c, show (_:ℕ)≤_→(_:ℕ)≤_, by {transfer_rw, apply le_of_add_le_add_left},
zero_lt_one := dec_trivial,
mul_le_mul_of_nonneg_left := λa b c h _, show (_:ℕ)≤_, by {transfer_rw, apply nat.mul_le_mul_left _ h},
mul_le_mul_of_nonneg_right := λa b c h _, show (_:ℕ)≤_, by {transfer_rw, apply nat.mul_le_mul_right _ h},
mul_lt_mul_of_pos_left := λa b c h₁ h₂, show (_:ℕ)<_, by {transfer_rw, apply nat.mul_lt_mul_of_pos_left h₁ h₂},
mul_lt_mul_of_pos_right := λa b c h₁ h₂, show (_:ℕ)<_, by {transfer_rw, apply nat.mul_lt_mul_of_pos_right h₁ h₂},
decidable_lt := num.decidable_lt,
decidable_le := num.decidable_le,
decidable_eq := num.decidable_eq }
lemma bitwise_to_nat {f : num → num → num} {g : bool → bool → bool}
(p : pos_num → pos_num → num)
(gff : g ff ff = ff)
(f00 : f 0 0 = 0)
(f0n : ∀ n, f 0 (pos n) = cond (g ff tt) (pos n) 0)
(fn0 : ∀ n, f (pos n) 0 = cond (g tt ff) (pos n) 0)
(fnn : ∀ m n, f (pos m) (pos n) = p m n)
(p11 : p 1 1 = cond (g tt tt) 1 0)
(p1b : ∀ b n, p 1 (pos_num.bit b n) = bit (g tt b) (cond (g ff tt) ↑n 0))
(pb1 : ∀ a m, p (pos_num.bit a m) 1 = bit (g a tt) (cond (g tt ff) ↑m 0))
(pbb : ∀ a b m n, p (pos_num.bit a m) (pos_num.bit b n) = bit (g a b) (p m n))
: ∀ m n : num, (f m n : ℕ) = nat.bitwise g m n :=
begin
intros, cases m with m; cases n with n;
try {rw show zero = 0, from rfl};
try {rw show ((0:num):ℕ) = 0, from rfl},
{ rw [f00, nat.bitwise_zero]; refl },
{ unfold nat.bitwise, rw [f0n, nat.binary_rec_zero],
cases g ff tt; refl },
{ unfold nat.bitwise,
generalize h : (pos m : ℕ) = m', revert h,
apply nat.bit_cases_on m' _, intros b m' h,
rw [fn0, nat.binary_rec_eq, nat.binary_rec_zero, ←h],
cases g tt ff; refl,
apply nat.bitwise_bit_aux gff },
{ rw fnn, revert n,
have : ∀b (n : pos_num), cond b ↑n 0 = ↑(cond b n 0 : num) :=
by intros; cases b; refl,
induction m with m IH m IH; intro n; cases n with n n,
any_goals { change one with 1 },
any_goals { change pos 1 with 1 },
any_goals { change pos_num.bit0 with pos_num.bit ff },
any_goals { change pos_num.bit1 with pos_num.bit tt },
any_goals { change ((1:num):ℕ) with nat.bit tt 0 },
all_goals {
repeat {
rw show ∀ b n, (pos (pos_num.bit b n) : ℕ) = nat.bit b ↑n,
by intros; cases b; refl },
rw nat.bitwise_bit },
any_goals { assumption },
any_goals { rw [nat.bitwise_zero, p11], cases g tt tt; refl },
any_goals { rw [nat.bitwise_zero_left, this, ←bit_to_nat, p1b] },
any_goals { rw [nat.bitwise_zero_right _ gff, this, ←bit_to_nat, pb1] },
all_goals { rw [←show ∀ n, ↑(p m n) = nat.bitwise g ↑m ↑n, from IH],
rw [←bit_to_nat, pbb] } }
end
@[simp] lemma lor_to_nat : ∀ m n, (lor m n : ℕ) = nat.lor m n :=
by apply bitwise_to_nat (λx y, ↑(pos_num.lor x y)); intros; try {cases a}; try {cases b}; refl
@[simp] lemma land_to_nat : ∀ m n, (land m n : ℕ) = nat.land m n :=
by apply bitwise_to_nat pos_num.land; intros; try {cases a}; try {cases b}; refl
@[simp] lemma ldiff_to_nat : ∀ m n, (ldiff m n : ℕ) = nat.ldiff m n :=
by apply bitwise_to_nat pos_num.ldiff; intros; try {cases a}; try {cases b}; refl
@[simp] lemma lxor_to_nat : ∀ m n, (lxor m n : ℕ) = nat.lxor m n :=
by apply bitwise_to_nat pos_num.lxor; intros; try {cases a}; try {cases b}; refl
@[simp] lemma shiftl_to_nat (m n) : (shiftl m n : ℕ) = nat.shiftl m n :=
begin
cases m; dunfold shiftl, {symmetry, apply nat.zero_shiftl},
induction n with n IH, {refl},
simp [pos_num.shiftl, nat.shiftl_succ], rw ←IH, refl
end
@[simp] lemma shiftr_to_nat (m n) : (shiftr m n : ℕ) = nat.shiftr m n :=
begin
cases m with m; dunfold shiftr, {symmetry, apply nat.zero_shiftr},
revert m; induction n with n IH; intro m, {cases m; refl},
cases m with m m; dunfold pos_num.shiftr,
{ rw [nat.shiftr_eq_div_pow], symmetry, apply nat.div_eq_of_lt,
exact @nat.pow_lt_pow_of_lt_right 2 dec_trivial 0 (n+1) (nat.succ_pos _) },
{ transitivity, apply IH,
change nat.shiftr m n = nat.shiftr (bit1 m) (n+1),
rw [add_comm n 1, nat.shiftr_add],
apply congr_arg (λx, nat.shiftr x n), unfold nat.shiftr,
change (bit1 ↑m : ℕ) with nat.bit tt m,
rw nat.div2_bit },
{ transitivity, apply IH,
change nat.shiftr m n = nat.shiftr (bit0 m) (n + 1),
rw [add_comm n 1, nat.shiftr_add],
apply congr_arg (λx, nat.shiftr x n), unfold nat.shiftr,
change (bit0 ↑m : ℕ) with nat.bit ff m,
rw nat.div2_bit }
end
@[simp] lemma test_bit_to_nat (m n) : test_bit m n = nat.test_bit m n :=
begin
cases m with m; unfold test_bit nat.test_bit,
{ change (zero : nat) with 0, rw nat.zero_shiftr, refl },
revert m; induction n with n IH; intro m;
cases m; dunfold pos_num.test_bit, {refl},
{ exact (nat.bodd_bit _ _).symm },
{ exact (nat.bodd_bit _ _).symm },
{ change ff = nat.bodd (nat.shiftr 1 (n + 1)),
rw [add_comm, nat.shiftr_add], change nat.shiftr 1 1 with 0,
rw nat.zero_shiftr; refl },
{ change pos_num.test_bit a n = nat.bodd (nat.shiftr (nat.bit tt a) (n + 1)),
rw [add_comm, nat.shiftr_add], unfold nat.shiftr,
rw nat.div2_bit, apply IH },
{ change pos_num.test_bit a n = nat.bodd (nat.shiftr (nat.bit ff a) (n + 1)),
rw [add_comm, nat.shiftr_add], unfold nat.shiftr,
rw nat.div2_bit, apply IH },
end
end num
|
0aa4272510e9417c9cda3dcb187bce7db8074a0c
|
8cae430f0a71442d02dbb1cbb14073b31048e4b0
|
/src/algebra/direct_sum/internal.lean
|
dc481b292617336b5cb809ccff3e378361fe40c7
|
[
"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
| 14,309
|
lean
|
/-
Copyright (c) 2021 Eric Wieser. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Wieser, Kevin Buzzard, Jujian Zhang
-/
import algebra.algebra.operations
import algebra.algebra.subalgebra.basic
import algebra.direct_sum.algebra
/-!
# Internally graded rings and algebras
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
This module provides `gsemiring` and `gcomm_semiring` instances for a collection of subobjects `A`
when a `set_like.graded_monoid` instance is available:
* `set_like.gnon_unital_non_assoc_semiring`
* `set_like.gsemiring`
* `set_like.gcomm_semiring`
With these instances in place, it provides the bundled canonical maps out of a direct sum of
subobjects into their carrier type:
* `direct_sum.coe_ring_hom` (a `ring_hom` version of `direct_sum.coe_add_monoid_hom`)
* `direct_sum.coe_alg_hom` (an `alg_hom` version of `direct_sum.submodule_coe`)
Strictly the definitions in this file are not sufficient to fully define an "internal" direct sum;
to represent this case, `(h : direct_sum.is_internal A) [set_like.graded_monoid A]` is
needed. In the future there will likely be a data-carrying, constructive, typeclass version of
`direct_sum.is_internal` for providing an explicit decomposition function.
When `complete_lattice.independent (set.range A)` (a weaker condition than
`direct_sum.is_internal A`), these provide a grading of `⨆ i, A i`, and the
mapping `⨁ i, A i →+ ⨆ i, A i` can be obtained as
`direct_sum.to_monoid (λ i, add_submonoid.inclusion $ le_supr A i)`.
## tags
internally graded ring
-/
open_locale direct_sum big_operators
variables {ι : Type*} {σ S R : Type*}
instance add_comm_monoid.of_submonoid_on_semiring [semiring R] [set_like σ R]
[add_submonoid_class σ R] (A : ι → σ) : ∀ i, add_comm_monoid (A i) :=
λ i, by apply_instance
instance add_comm_group.of_subgroup_on_ring [ring R] [set_like σ R]
[add_subgroup_class σ R] (A : ι → σ) : ∀ i, add_comm_group (A i) :=
λ i, by apply_instance
lemma set_like.algebra_map_mem_graded [has_zero ι]
[comm_semiring S] [semiring R] [algebra S R]
(A : ι → submodule S R) [set_like.has_graded_one A] (s : S) : algebra_map S R s ∈ A 0 :=
begin
rw algebra.algebra_map_eq_smul_one,
exact ((A 0).smul_mem s $ set_like.one_mem_graded _),
end
lemma set_like.nat_cast_mem_graded [has_zero ι] [add_monoid_with_one R]
[set_like σ R] [add_submonoid_class σ R] (A : ι → σ) [set_like.has_graded_one A] (n : ℕ) :
(n : R) ∈ A 0 :=
begin
induction n,
{ rw nat.cast_zero,
exact zero_mem (A 0), },
{ rw nat.cast_succ,
exact add_mem n_ih (set_like.one_mem_graded _), },
end
lemma set_like.int_cast_mem_graded [has_zero ι] [add_group_with_one R]
[set_like σ R] [add_subgroup_class σ R] (A : ι → σ) [set_like.has_graded_one A] (z : ℤ) :
(z : R) ∈ A 0:=
begin
induction z,
{ rw int.cast_of_nat,
exact set_like.nat_cast_mem_graded _ _, },
{ rw int.cast_neg_succ_of_nat,
exact neg_mem (set_like.nat_cast_mem_graded _ _), },
end
section direct_sum
variables [decidable_eq ι]
/-! #### From `add_submonoid`s and `add_subgroup`s -/
namespace set_like
/-- Build a `gnon_unital_non_assoc_semiring` instance for a collection of additive submonoids. -/
instance gnon_unital_non_assoc_semiring [has_add ι] [non_unital_non_assoc_semiring R]
[set_like σ R] [add_submonoid_class σ R]
(A : ι → σ) [set_like.has_graded_mul A] :
direct_sum.gnon_unital_non_assoc_semiring (λ i, A i) :=
{ mul_zero := λ i j _, subtype.ext (mul_zero _),
zero_mul := λ i j _, subtype.ext (zero_mul _),
mul_add := λ i j _ _ _, subtype.ext (mul_add _ _ _),
add_mul := λ i j _ _ _, subtype.ext (add_mul _ _ _),
..set_like.ghas_mul A }
/-- Build a `gsemiring` instance for a collection of additive submonoids. -/
instance gsemiring [add_monoid ι] [semiring R] [set_like σ R] [add_submonoid_class σ R]
(A : ι → σ) [set_like.graded_monoid A] :
direct_sum.gsemiring (λ i, A i) :=
{ mul_zero := λ i j _, subtype.ext (mul_zero _),
zero_mul := λ i j _, subtype.ext (zero_mul _),
mul_add := λ i j _ _ _, subtype.ext (mul_add _ _ _),
add_mul := λ i j _ _ _, subtype.ext (add_mul _ _ _),
nat_cast := λ n, ⟨n, set_like.nat_cast_mem_graded _ _⟩,
nat_cast_zero := subtype.ext nat.cast_zero,
nat_cast_succ := λ n, subtype.ext (nat.cast_succ n),
..set_like.gmonoid A }
/-- Build a `gcomm_semiring` instance for a collection of additive submonoids. -/
instance gcomm_semiring [add_comm_monoid ι] [comm_semiring R] [set_like σ R]
[add_submonoid_class σ R] (A : ι → σ) [set_like.graded_monoid A] :
direct_sum.gcomm_semiring (λ i, A i) :=
{ ..set_like.gcomm_monoid A,
..set_like.gsemiring A, }
/-- Build a `gring` instance for a collection of additive subgroups. -/
instance gring [add_monoid ι] [ring R] [set_like σ R] [add_subgroup_class σ R]
(A : ι → σ) [set_like.graded_monoid A] :
direct_sum.gring (λ i, A i) :=
{ int_cast := λ z, ⟨z, set_like.int_cast_mem_graded _ _⟩,
int_cast_of_nat := λ n, subtype.ext $ int.cast_of_nat _,
int_cast_neg_succ_of_nat := λ n, subtype.ext $ int.cast_neg_succ_of_nat n,
..set_like.gsemiring A }
/-- Build a `gcomm_semiring` instance for a collection of additive submonoids. -/
instance gcomm_ring [add_comm_monoid ι] [comm_ring R] [set_like σ R]
[add_subgroup_class σ R] (A : ι → σ) [set_like.graded_monoid A] :
direct_sum.gcomm_ring (λ i, A i) :=
{ ..set_like.gcomm_monoid A,
..set_like.gring A, }
end set_like
namespace direct_sum
section coe
variables [semiring R] [set_like σ R] [add_submonoid_class σ R] (A : ι → σ)
/-- The canonical ring isomorphism between `⨁ i, A i` and `R`-/
def coe_ring_hom [add_monoid ι] [set_like.graded_monoid A] : (⨁ i, A i) →+* R :=
direct_sum.to_semiring (λ i, add_submonoid_class.subtype (A i)) rfl (λ _ _ _ _, rfl)
/-- The canonical ring isomorphism between `⨁ i, A i` and `R`-/
@[simp] lemma coe_ring_hom_of [add_monoid ι] [set_like.graded_monoid A] (i : ι)
(x : A i) : (coe_ring_hom A : _ →+* R) (of (λ i, A i) i x) = x :=
direct_sum.to_semiring_of _ _ _ _ _
lemma coe_mul_apply [add_monoid ι] [set_like.graded_monoid A]
[Π (i : ι) (x : A i), decidable (x ≠ 0)] (r r' : ⨁ i, A i) (n : ι) :
((r * r') n : R) =
∑ ij in (r.support ×ˢ r'.support).filter (λ ij : ι × ι, ij.1 + ij.2 = n), r ij.1 * r' ij.2 :=
begin
rw [mul_eq_sum_support_ghas_mul, dfinsupp.finset_sum_apply, add_submonoid_class.coe_finset_sum],
simp_rw [coe_of_apply, ←finset.sum_filter, set_like.coe_ghas_mul],
end
lemma coe_mul_apply_eq_dfinsupp_sum [add_monoid ι] [set_like.graded_monoid A]
[Π (i : ι) (x : A i), decidable (x ≠ 0)] (r r' : ⨁ i, A i) (n : ι) :
((r * r') n : R) = r.sum (λ i ri, r'.sum (λ j rj, if i + j = n then ri * rj else 0)) :=
begin
simp only [mul_eq_dfinsupp_sum, dfinsupp.sum_apply],
iterate 2 { rw [dfinsupp.sum, add_submonoid_class.coe_finset_sum], congr, ext },
dsimp only, split_ifs,
{ subst h, rw of_eq_same, refl },
{ rw of_eq_of_ne _ _ _ _ h, refl },
end
lemma coe_of_mul_apply_aux [add_monoid ι] [set_like.graded_monoid A] {i : ι}
(r : A i) (r' : ⨁ i, A i) {j n : ι} (H : ∀ (x : ι), i + x = n ↔ x = j) :
((of _ i r * r') n : R) = r * r' j :=
begin
classical,
rw coe_mul_apply_eq_dfinsupp_sum,
apply (dfinsupp.sum_single_index _).trans, swap,
{ simp_rw [zero_mem_class.coe_zero, zero_mul, if_t_t], exact dfinsupp.sum_zero },
simp_rw [dfinsupp.sum, H, finset.sum_ite_eq'],
split_ifs, refl,
rw [dfinsupp.not_mem_support_iff.mp h, zero_mem_class.coe_zero, mul_zero],
end
lemma coe_mul_of_apply_aux [add_monoid ι] [set_like.graded_monoid A]
(r : ⨁ i, A i) {i : ι} (r' : A i) {j n : ι} (H : ∀ (x : ι), x + i = n ↔ x = j) :
((r * of _ i r') n : R) = r j * r' :=
begin
classical,
rw [coe_mul_apply_eq_dfinsupp_sum, dfinsupp.sum_comm],
apply (dfinsupp.sum_single_index _).trans, swap,
{ simp_rw [zero_mem_class.coe_zero, mul_zero, if_t_t], exact dfinsupp.sum_zero },
simp_rw [dfinsupp.sum, H, finset.sum_ite_eq'],
split_ifs, refl,
rw [dfinsupp.not_mem_support_iff.mp h, zero_mem_class.coe_zero, zero_mul],
end
lemma coe_of_mul_apply_add [add_left_cancel_monoid ι] [set_like.graded_monoid A]
{i : ι} (r : A i) (r' : ⨁ i, A i) (j : ι) :
((of _ i r * r') (i + j) : R) = r * r' j :=
coe_of_mul_apply_aux _ _ _ (λ x, ⟨λ h, add_left_cancel h, λ h, h ▸ rfl⟩)
lemma coe_mul_of_apply_add [add_right_cancel_monoid ι] [set_like.graded_monoid A]
(r : ⨁ i, A i) {i : ι} (r' : A i) (j : ι) :
((r * of _ i r') (j + i) : R) = r j * r' :=
coe_mul_of_apply_aux _ _ _ (λ x, ⟨λ h, add_right_cancel h, λ h, h ▸ rfl⟩)
end coe
section canonically_ordered_add_monoid
variables [semiring R] [set_like σ R] [add_submonoid_class σ R] (A : ι → σ)
variables [canonically_ordered_add_monoid ι] [set_like.graded_monoid A]
lemma coe_of_mul_apply_of_not_le
{i : ι} (r : A i) (r' : ⨁ i, A i) (n : ι)
(h : ¬ i ≤ n) : ((of _ i r * r') n : R) = 0 :=
begin
classical,
rw coe_mul_apply_eq_dfinsupp_sum,
apply (dfinsupp.sum_single_index _).trans, swap,
{ simp_rw [zero_mem_class.coe_zero, zero_mul, if_t_t], exact dfinsupp.sum_zero },
{ rw [dfinsupp.sum, finset.sum_ite_of_false _ _ (λ x _ H, _), finset.sum_const_zero],
exact h ((self_le_add_right i x).trans_eq H) },
end
lemma coe_mul_of_apply_of_not_le
(r : ⨁ i, A i) {i : ι} (r' : A i) (n : ι)
(h : ¬ i ≤ n) : ((r * of _ i r') n : R) = 0 :=
begin
classical,
rw [coe_mul_apply_eq_dfinsupp_sum, dfinsupp.sum_comm],
apply (dfinsupp.sum_single_index _).trans, swap,
{ simp_rw [zero_mem_class.coe_zero, mul_zero, if_t_t], exact dfinsupp.sum_zero },
{ rw [dfinsupp.sum, finset.sum_ite_of_false _ _ (λ x _ H, _), finset.sum_const_zero],
exact h ((self_le_add_left i x).trans_eq H) },
end
variables [has_sub ι] [has_ordered_sub ι] [contravariant_class ι ι (+) (≤)]
/- The following two lemmas only require the same hypotheses as `eq_tsub_iff_add_eq_of_le`, but we
state them for `canonically_ordered_add_monoid` + the above three typeclasses for convenience. -/
lemma coe_mul_of_apply_of_le (r : ⨁ i, A i) {i : ι} (r' : A i) (n : ι)
(h : i ≤ n) : ((r * of _ i r') n : R) = r (n - i) * r' :=
coe_mul_of_apply_aux _ _ _ (λ x, (eq_tsub_iff_add_eq_of_le h).symm)
lemma coe_of_mul_apply_of_le {i : ι} (r : A i) (r' : ⨁ i, A i) (n : ι)
(h : i ≤ n) : ((of _ i r * r') n : R) = r * r' (n - i) :=
coe_of_mul_apply_aux _ _ _ (λ x, by rw [eq_tsub_iff_add_eq_of_le h, add_comm])
lemma coe_mul_of_apply (r : ⨁ i, A i) {i : ι} (r' : A i) (n : ι) [decidable (i ≤ n)] :
((r * of _ i r') n : R) = if i ≤ n then r (n - i) * r' else 0 :=
by { split_ifs, exacts [coe_mul_of_apply_of_le _ _ _ n h, coe_mul_of_apply_of_not_le _ _ _ n h] }
lemma coe_of_mul_apply {i : ι} (r : A i) (r' : ⨁ i, A i) (n : ι) [decidable (i ≤ n)] :
((of _ i r * r') n : R) = if i ≤ n then r * r' (n - i) else 0 :=
by { split_ifs, exacts [coe_of_mul_apply_of_le _ _ _ n h, coe_of_mul_apply_of_not_le _ _ _ n h] }
end canonically_ordered_add_monoid
end direct_sum
/-! #### From `submodule`s -/
namespace submodule
/-- Build a `galgebra` instance for a collection of `submodule`s. -/
instance galgebra [add_monoid ι]
[comm_semiring S] [semiring R] [algebra S R]
(A : ι → submodule S R) [set_like.graded_monoid A] :
direct_sum.galgebra S (λ i, A i) :=
{ to_fun := ((algebra.linear_map S R).cod_restrict (A 0) $
set_like.algebra_map_mem_graded A).to_add_monoid_hom,
map_one := subtype.ext $ by exact (algebra_map S R).map_one,
map_mul := λ x y, sigma.subtype_ext (add_zero 0).symm $ (algebra_map S R).map_mul _ _,
commutes := λ r ⟨i, xi⟩,
sigma.subtype_ext ((zero_add i).trans (add_zero i).symm) $ algebra.commutes _ _,
smul_def := λ r ⟨i, xi⟩, sigma.subtype_ext (zero_add i).symm $ algebra.smul_def _ _ }
@[simp] lemma set_like.coe_galgebra_to_fun [add_monoid ι]
[comm_semiring S] [semiring R] [algebra S R]
(A : ι → submodule S R) [set_like.graded_monoid A] (s : S) :
↑(@direct_sum.galgebra.to_fun _ S (λ i, A i) _ _ _ _ _ _ _ s) = (algebra_map S R s : R) := rfl
/-- A direct sum of powers of a submodule of an algebra has a multiplicative structure. -/
instance nat_power_graded_monoid
[comm_semiring S] [semiring R] [algebra S R] (p : submodule S R) :
set_like.graded_monoid (λ i : ℕ, p ^ i) :=
{ one_mem := by { rw [←one_le, pow_zero], exact le_rfl },
mul_mem := λ i j p q hp hq, by { rw pow_add, exact submodule.mul_mem_mul hp hq } }
end submodule
/-- The canonical algebra isomorphism between `⨁ i, A i` and `R`. -/
def direct_sum.coe_alg_hom [add_monoid ι]
[comm_semiring S] [semiring R] [algebra S R]
(A : ι → submodule S R) [set_like.graded_monoid A] : (⨁ i, A i) →ₐ[S] R :=
direct_sum.to_algebra S _ (λ i, (A i).subtype) rfl (λ _ _ _ _, rfl) (λ _, rfl)
/-- The supremum of submodules that form a graded monoid is a subalgebra, and equal to the range of
`direct_sum.coe_alg_hom`. -/
lemma submodule.supr_eq_to_submodule_range [add_monoid ι]
[comm_semiring S] [semiring R] [algebra S R] (A : ι → submodule S R) [set_like.graded_monoid A] :
(⨆ i, A i) = (direct_sum.coe_alg_hom A).range.to_submodule :=
(submodule.supr_eq_range_dfinsupp_lsum A).trans $ set_like.coe_injective rfl
@[simp] lemma direct_sum.coe_alg_hom_of [add_monoid ι]
[comm_semiring S] [semiring R] [algebra S R]
(A : ι → submodule S R) [set_like.graded_monoid A] (i : ι) (x : A i) :
direct_sum.coe_alg_hom A (direct_sum.of (λ i, A i) i x) = x :=
direct_sum.to_semiring_of _ rfl (λ _ _ _ _, rfl) _ _
end direct_sum
section homogeneous_element
lemma set_like.is_homogeneous_zero_submodule [has_zero ι]
[semiring S] [add_comm_monoid R] [module S R]
(A : ι → submodule S R) : set_like.is_homogeneous A (0 : R) :=
⟨0, submodule.zero_mem _⟩
lemma set_like.is_homogeneous.smul [comm_semiring S] [semiring R] [algebra S R]
{A : ι → submodule S R} {s : S}
{r : R} (hr : set_like.is_homogeneous A r) : set_like.is_homogeneous A (s • r) :=
let ⟨i, hi⟩ := hr in ⟨i, submodule.smul_mem _ _ hi⟩
end homogeneous_element
|
656a760dd08676be6a091e826336239ec212eff1
|
bbecf0f1968d1fba4124103e4f6b55251d08e9c4
|
/src/measure_theory/measure/measure_space.lean
|
800a0da32ee4a4b1373faef46e654d299a66b37f
|
[
"Apache-2.0"
] |
permissive
|
waynemunro/mathlib
|
e3fd4ff49f4cb43d4a8ded59d17be407bc5ee552
|
065a70810b5480d584033f7bbf8e0409480c2118
|
refs/heads/master
| 1,693,417,182,397
| 1,634,644,781,000
| 1,634,644,781,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 134,427
|
lean
|
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro
-/
import measure_theory.measure.measure_space_def
import measure_theory.measurable_space
/-!
# Measure spaces
The definition of a measure and a measure space are in `measure_theory.measure_space_def`, with
only a few basic properties. This file provides many more properties of these objects.
This separation allows the measurability tactic to import only the file `measure_space_def`, and to
be available in `measure_space` (through `measurable_space`).
Given a measurable space `α`, a measure on `α` is a function that sends measurable sets to the
extended nonnegative reals that satisfies the following conditions:
1. `μ ∅ = 0`;
2. `μ` is countably additive. This means that the measure of a countable union of pairwise disjoint
sets is equal to the measure of the individual sets.
Every measure can be canonically extended to an outer measure, so that it assigns values to
all subsets, not just the measurable subsets. On the other hand, a measure that is countably
additive on measurable sets can be restricted to measurable sets to obtain a measure.
In this file a measure is defined to be an outer measure that is countably additive on
measurable sets, with the additional assumption that the outer measure is the canonical
extension of the restricted measure.
Measures on `α` form a complete lattice, and are closed under scalar multiplication with `ℝ≥0∞`.
We introduce the following typeclasses for measures:
* `is_probability_measure μ`: `μ univ = 1`;
* `is_finite_measure μ`: `μ univ < ∞`;
* `sigma_finite μ`: there exists a countable collection of sets that cover `univ`
where `μ` is finite;
* `is_locally_finite_measure μ` : `∀ x, ∃ s ∈ 𝓝 x, μ s < ∞`;
* `has_no_atoms μ` : `∀ x, μ {x} = 0`; possibly should be redefined as
`∀ s, 0 < μ s → ∃ t ⊆ s, 0 < μ t ∧ μ t < μ s`.
Given a measure, the null sets are the sets where `μ s = 0`, where `μ` denotes the corresponding
outer measure (so `s` might not be measurable). We can then define the completion of `μ` as the
measure on the least `σ`-algebra that also contains all null sets, by defining the measure to be `0`
on the null sets.
## Main statements
* `completion` is the completion of a measure to all null measurable sets.
* `measure.of_measurable` and `outer_measure.to_measure` are two important ways to define a measure.
## Implementation notes
Given `μ : measure α`, `μ s` is the value of the *outer measure* applied to `s`.
This conveniently allows us to apply the measure to sets without proving that they are measurable.
We get countable subadditivity for all sets, but only countable additivity for measurable sets.
You often don't want to define a measure via its constructor.
Two ways that are sometimes more convenient:
* `measure.of_measurable` is a way to define a measure by only giving its value on measurable sets
and proving the properties (1) and (2) mentioned above.
* `outer_measure.to_measure` is a way of obtaining a measure from an outer measure by showing that
all measurable sets in the measurable space are Carathéodory measurable.
To prove that two measures are equal, there are multiple options:
* `ext`: two measures are equal if they are equal on all measurable sets.
* `ext_of_generate_from_of_Union`: two measures are equal if they are equal on a π-system generating
the measurable sets, if the π-system contains a spanning increasing sequence of sets where the
measures take finite value (in particular the measures are σ-finite). This is a special case of
the more general `ext_of_generate_from_of_cover`
* `ext_of_generate_finite`: two finite measures are equal if they are equal on a π-system
generating the measurable sets. This is a special case of `ext_of_generate_from_of_Union` using
`C ∪ {univ}`, but is easier to work with.
A `measure_space` is a class that is a measurable space with a canonical measure.
The measure is denoted `volume`.
## References
* <https://en.wikipedia.org/wiki/Measure_(mathematics)>
* <https://en.wikipedia.org/wiki/Complete_measure>
* <https://en.wikipedia.org/wiki/Almost_everywhere>
## Tags
measure, almost everywhere, measure space, completion, null set, null measurable set
-/
noncomputable theory
open classical set filter (hiding map) function measurable_space
open_locale classical topological_space big_operators filter ennreal nnreal
variables {α β γ δ ι : Type*}
namespace measure_theory
section
variables {m : measurable_space α} {μ μ₁ μ₂ : measure α} {s s₁ s₂ t : set α}
instance ae_is_measurably_generated : is_measurably_generated μ.ae :=
⟨λ s hs, let ⟨t, hst, htm, htμ⟩ := exists_measurable_superset_of_null hs in
⟨tᶜ, compl_mem_ae_iff.2 htμ, htm.compl, compl_subset_comm.1 hst⟩⟩
lemma measure_Union [encodable β] {f : β → set α}
(hn : pairwise (disjoint on f)) (h : ∀ i, measurable_set (f i)) :
μ (⋃ i, f i) = ∑' i, μ (f i) :=
begin
rw [measure_eq_extend (measurable_set.Union h),
extend_Union measurable_set.empty _ measurable_set.Union _ hn h],
{ simp [measure_eq_extend, h] },
{ exact μ.empty },
{ exact μ.m_Union }
end
lemma measure_union (hd : disjoint s₁ s₂) (h₁ : measurable_set s₁) (h₂ : measurable_set s₂) :
μ (s₁ ∪ s₂) = μ s₁ + μ s₂ :=
begin
rw [union_eq_Union, measure_Union, tsum_fintype, fintype.sum_bool, cond, cond],
exacts [pairwise_disjoint_on_bool.2 hd, λ b, bool.cases_on b h₂ h₁]
end
lemma measure_add_measure_compl (h : measurable_set s) :
μ s + μ sᶜ = μ univ :=
by { rw [← union_compl_self s, measure_union _ h h.compl], exact disjoint_compl_right }
lemma measure_bUnion {s : set β} {f : β → set α} (hs : countable s)
(hd : pairwise_on s (disjoint on f)) (h : ∀ b ∈ s, measurable_set (f b)) :
μ (⋃ b ∈ s, f b) = ∑' p : s, μ (f p) :=
begin
haveI := hs.to_encodable,
rw bUnion_eq_Union,
exact measure_Union (hd.on_injective subtype.coe_injective $ λ x, x.2) (λ x, h x x.2)
end
lemma measure_sUnion {S : set (set α)} (hs : countable S)
(hd : pairwise_on S disjoint) (h : ∀ s ∈ S, measurable_set s) :
μ (⋃₀ S) = ∑' s : S, μ s :=
by rw [sUnion_eq_bUnion, measure_bUnion hs hd h]
lemma measure_bUnion_finset {s : finset ι} {f : ι → set α} (hd : pairwise_on ↑s (disjoint on f))
(hm : ∀ b ∈ s, measurable_set (f b)) :
μ (⋃ b ∈ s, f b) = ∑ p in s, μ (f p) :=
begin
rw [← finset.sum_attach, finset.attach_eq_univ, ← tsum_fintype],
exact measure_bUnion s.countable_to_set hd hm
end
/-- If `s` is a countable set, then the measure of its preimage can be found as the sum of measures
of the fibers `f ⁻¹' {y}`. -/
lemma tsum_measure_preimage_singleton {s : set β} (hs : countable s) {f : α → β}
(hf : ∀ y ∈ s, measurable_set (f ⁻¹' {y})) :
∑' b : s, μ (f ⁻¹' {↑b}) = μ (f ⁻¹' s) :=
by rw [← set.bUnion_preimage_singleton, measure_bUnion hs (pairwise_on_disjoint_fiber _ _) hf]
/-- If `s` is a `finset`, then the measure of its preimage can be found as the sum of measures
of the fibers `f ⁻¹' {y}`. -/
lemma sum_measure_preimage_singleton (s : finset β) {f : α → β}
(hf : ∀ y ∈ s, measurable_set (f ⁻¹' {y})) :
∑ b in s, μ (f ⁻¹' {b}) = μ (f ⁻¹' ↑s) :=
by simp only [← measure_bUnion_finset (pairwise_on_disjoint_fiber _ _) hf,
finset.set_bUnion_preimage_singleton]
lemma measure_diff_null' (h : μ (s₁ ∩ s₂) = 0) : μ (s₁ \ s₂) = μ s₁ :=
measure_congr $ diff_ae_eq_self.2 h
lemma measure_diff_null (h : μ s₂ = 0) : μ (s₁ \ s₂) = μ s₁ :=
measure_diff_null' $ measure_mono_null (inter_subset_right _ _) h
lemma measure_diff (h : s₂ ⊆ s₁) (h₁ : measurable_set s₁) (h₂ : measurable_set 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 le_measure_diff : μ s₁ - μ s₂ ≤ μ (s₁ \ s₂) :=
ennreal.sub_le_iff_le_add'.2 $
calc μ s₁ ≤ μ (s₂ ∪ s₁) : measure_mono (subset_union_right _ _)
... = μ (s₂ ∪ s₁ \ s₂) : congr_arg μ union_diff_self.symm
... ≤ μ s₂ + μ (s₁ \ s₂) : measure_union_le _ _
lemma measure_diff_lt_of_lt_add (hs : measurable_set s) (ht : measurable_set t) (hst : s ⊆ t)
(hs' : μ s ≠ ∞) {ε : ℝ≥0∞} (h : μ t < μ s + ε) : μ (t \ s) < ε :=
begin
rw [measure_diff hst ht hs hs'], rw add_comm at h,
exact ennreal.sub_lt_of_lt_add (measure_mono hst) h
end
lemma measure_diff_le_iff_le_add (hs : measurable_set s) (ht : measurable_set t) (hst : s ⊆ t)
(hs' : μ s ≠ ∞) {ε : ℝ≥0∞} : μ (t \ s) ≤ ε ↔ μ t ≤ μ s + ε :=
by rwa [measure_diff hst ht hs hs', ennreal.sub_le_iff_le_add']
lemma measure_eq_measure_of_null_diff {s t : set α}
(hst : s ⊆ t) (h_nulldiff : μ (t.diff s) = 0) : μ s = μ t :=
by { rw [←diff_diff_cancel_left hst, ←@measure_diff_null _ _ _ t _ h_nulldiff], refl, }
lemma measure_eq_measure_of_between_null_diff {s₁ s₂ s₃ : set α}
(h12 : s₁ ⊆ s₂) (h23 : s₂ ⊆ s₃) (h_nulldiff : μ (s₃ \ s₁) = 0) :
(μ s₁ = μ s₂) ∧ (μ s₂ = μ s₃) :=
begin
have le12 : μ s₁ ≤ μ s₂ := measure_mono h12,
have le23 : μ s₂ ≤ μ s₃ := measure_mono h23,
have key : μ s₃ ≤ μ s₁ := calc
μ s₃ = μ ((s₃ \ s₁) ∪ s₁) : by rw (diff_union_of_subset (h12.trans h23))
... ≤ μ (s₃ \ s₁) + μ s₁ : measure_union_le _ _
... = μ s₁ : by simp only [h_nulldiff, zero_add],
exact ⟨le12.antisymm (le23.trans key), le23.antisymm (key.trans le12)⟩,
end
lemma measure_eq_measure_smaller_of_between_null_diff {s₁ s₂ s₃ : set α}
(h12 : s₁ ⊆ s₂) (h23 : s₂ ⊆ s₃) (h_nulldiff : μ (s₃.diff s₁) = 0) : μ s₁ = μ s₂ :=
(measure_eq_measure_of_between_null_diff h12 h23 h_nulldiff).1
lemma measure_eq_measure_larger_of_between_null_diff {s₁ s₂ s₃ : set α}
(h12 : s₁ ⊆ s₂) (h23 : s₂ ⊆ s₃) (h_nulldiff : μ (s₃.diff s₁) = 0) : μ s₂ = μ s₃ :=
(measure_eq_measure_of_between_null_diff h12 h23 h_nulldiff).2
lemma measure_compl (h₁ : measurable_set s) (h_fin : μ s ≠ ∞) : μ (sᶜ) = μ univ - μ s :=
by { rw compl_eq_univ_diff, exact measure_diff (subset_univ s) measurable_set.univ h₁ h_fin }
lemma sum_measure_le_measure_univ {s : finset ι} {t : ι → set α} (h : ∀ i ∈ s, measurable_set (t i))
(H : pairwise_on ↑s (disjoint on t)) :
∑ i in s, μ (t i) ≤ μ (univ : set α) :=
by { rw ← measure_bUnion_finset H h, exact measure_mono (subset_univ _) }
lemma tsum_measure_le_measure_univ {s : ι → set α} (hs : ∀ i, measurable_set (s i))
(H : pairwise (disjoint on s)) :
∑' i, μ (s i) ≤ μ (univ : set α) :=
begin
rw [ennreal.tsum_eq_supr_sum],
exact supr_le (λ s, sum_measure_le_measure_univ (λ i hi, hs i) (λ i hi j hj hij, H i j hij))
end
lemma measure_Union_of_null_inter [encodable ι] {f : ι → set α} (h : ∀ i, measurable_set (f i))
(hn : pairwise ((λ S T, μ (S ∩ T) = 0) on f)) : μ (⋃ i, f i) = ∑' i, μ (f i) :=
begin
have h_null : μ (⋃ (ij : ι × ι) (hij : ij.fst ≠ ij.snd), f ij.fst ∩ f ij.snd) = 0,
{ rw measure_Union_null_iff,
rintro ⟨i, j⟩,
by_cases hij : i = j,
{ simp [hij], },
{ suffices : μ (f i ∩ f j) = 0,
{ simpa [hij], },
apply hn i j hij, }, },
have h_pair : pairwise (disjoint on
(λ i, f i \ (⋃ (ij : ι × ι) (hij : ij.fst ≠ ij.snd), f ij.fst ∩ f ij.snd))),
{ intros i j hij x hx,
simp only [not_exists, exists_prop, mem_Union, mem_inter_eq, not_and,
inf_eq_inter, ne.def, mem_diff, prod.exists] at hx,
simp only [mem_empty_eq, bot_eq_empty],
rcases hx with ⟨⟨hx_left_left, hx_left_right⟩, hx_right_left, hx_right_right⟩,
exact hx_left_right _ _ hij hx_left_left hx_right_left, },
have h_meas :
∀ i, measurable_set (f i \ (⋃ (ij : ι × ι) (hij : ij.fst ≠ ij.snd), f ij.fst ∩ f ij.snd)),
{ intro w,
apply (h w).diff,
apply measurable_set.Union,
rintro ⟨i, j⟩,
by_cases hij : i = j,
{ simp [hij], },
{ simp [hij, measurable_set.inter (h i) (h j)], }, },
have : μ _ = _ := measure_Union h_pair h_meas,
rw ← Union_diff at this,
simp_rw measure_diff_null h_null at this,
exact this,
end
/-- Pigeonhole principle for measure spaces: if `∑' i, μ (s i) > μ univ`, then
one of the intersections `s i ∩ s j` is not empty. -/
lemma exists_nonempty_inter_of_measure_univ_lt_tsum_measure {m : measurable_space α} (μ : measure α)
{s : ι → set α} (hs : ∀ i, measurable_set (s i)) (H : μ (univ : set α) < ∑' i, μ (s i)) :
∃ i j (h : i ≠ j), (s i ∩ s j).nonempty :=
begin
contrapose! H,
apply tsum_measure_le_measure_univ hs,
exact λ i j hij x hx, H i j hij ⟨x, hx⟩
end
/-- Pigeonhole principle for measure spaces: if `s` is a `finset` and
`∑ i in s, μ (t i) > μ univ`, then one of the intersections `t i ∩ t j` is not empty. -/
lemma exists_nonempty_inter_of_measure_univ_lt_sum_measure {m : measurable_space α} (μ : measure α)
{s : finset ι} {t : ι → set α} (h : ∀ i ∈ s, measurable_set (t i))
(H : μ (univ : set α) < ∑ i in s, μ (t i)) :
∃ (i ∈ s) (j ∈ s) (h : i ≠ j), (t i ∩ t j).nonempty :=
begin
contrapose! H,
apply sum_measure_le_measure_univ h,
exact λ i hi j hj hij x hx, H i hi j hj hij ⟨x, hx⟩
end
/-- Continuity from below: the measure of the union of a directed sequence of measurable sets
is the supremum of the measures. -/
lemma measure_Union_eq_supr [encodable ι] {s : ι → set α} (h : ∀ i, measurable_set (s i))
(hd : directed (⊆) s) : μ (⋃ i, s i) = ⨆ i, μ (s i) :=
begin
casesI is_empty_or_nonempty ι,
{ simp only [supr_of_empty, Union], exact measure_empty },
refine le_antisymm _ (supr_le $ λ i, measure_mono $ subset_Union _ _),
have : ∀ n, measurable_set (disjointed (λ n, ⋃ b ∈ encodable.decode₂ ι n, s b) n) :=
measurable_set.disjointed (measurable_set.bUnion_decode₂ h),
rw [← encodable.Union_decode₂, ← Union_disjointed, measure_Union (disjoint_disjointed _) this,
ennreal.tsum_eq_supr_nat],
simp only [← measure_bUnion_finset ((disjoint_disjointed _).pairwise_on _) (λ n _, this n)],
refine supr_le (λ n, _),
refine le_trans (_ : _ ≤ μ (⋃ (k ∈ finset.range n) (i ∈ encodable.decode₂ ι k), s i)) _,
exact measure_mono (bUnion_mono (λ k hk, disjointed_subset _ _)),
simp only [← finset.set_bUnion_option_to_finset, ← finset.set_bUnion_bUnion],
generalize : (finset.range n).bUnion (λ k, (encodable.decode₂ ι k).to_finset) = t,
rcases hd.finset_le t with ⟨i, hi⟩,
exact le_supr_of_le i (measure_mono $ bUnion_subset hi)
end
lemma measure_bUnion_eq_supr {s : ι → set α} {t : set ι} (ht : countable t)
(h : ∀ i ∈ t, measurable_set (s i)) (hd : directed_on ((⊆) on s) t) :
μ (⋃ i ∈ t, s i) = ⨆ i ∈ t, μ (s i) :=
begin
haveI := ht.to_encodable,
rw [bUnion_eq_Union, measure_Union_eq_supr (set_coe.forall'.1 h) hd.directed_coe,
supr_subtype'],
refl
end
/-- Continuity from above: the measure of the intersection of a decreasing sequence of measurable
sets is the infimum of the measures. -/
lemma measure_Inter_eq_infi [encodable ι] {s : ι → set α}
(h : ∀ i, measurable_set (s i)) (hd : directed (⊇) s) (hfin : ∃ i, μ (s i) ≠ ∞) :
μ (⋂ i, s i) = (⨅ i, μ (s i)) :=
begin
rcases hfin with ⟨k, hk⟩,
have : ∀ t ⊆ s k, μ t ≠ ∞, from λ t ht, ne_top_of_le_ne_top hk (measure_mono ht),
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) (measurable_set.Inter h) (this _ (Inter_subset _ k)),
diff_Inter, measure_Union_eq_supr],
{ congr' 1,
refine le_antisymm (supr_le_supr2 $ λ i, _) (supr_le_supr $ λ i, _),
{ rcases hd i k with ⟨j, hji, hjk⟩,
use j,
rw [← measure_diff hjk (h _) (h _) (this _ hjk)],
exact measure_mono (diff_subset_diff_right hji) },
{ rw [ennreal.sub_le_iff_le_add, ← measure_union disjoint_diff.symm ((h k).diff (h i)) (h i),
set.union_comm],
exact measure_mono (diff_subset_iff.1 $ subset.refl _) } },
{ exact λ i, (h k).diff (h i) },
{ exact hd.mono_comp _ (λ _ _, diff_subset_diff_right) }
end
lemma measure_eq_inter_diff (hs : measurable_set s) (ht : measurable_set 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 measure_union_add_inter (hs : measurable_set s) (ht : measurable_set t) :
μ (s ∪ t) + μ (s ∩ t) = μ s + μ t :=
by { rw [measure_eq_inter_diff (hs.union ht) ht, set.union_inter_cancel_right,
union_diff_right, measure_eq_inter_diff hs ht], ac_refl }
/-- Continuity from below: the measure of the union of an increasing sequence of measurable sets
is the limit of the measures. -/
lemma tendsto_measure_Union [semilattice_sup ι] [encodable ι] {s : ι → set α}
(hs : ∀ n, measurable_set (s n)) (hm : monotone s) :
tendsto (μ ∘ s) at_top (𝓝 (μ (⋃ n, s n))) :=
begin
rw measure_Union_eq_supr hs (directed_of_sup hm),
exact tendsto_at_top_supr (assume n m hnm, measure_mono $ hm hnm)
end
/-- Continuity from above: the measure of the intersection of a decreasing sequence of measurable
sets is the limit of the measures. -/
lemma tendsto_measure_Inter [encodable ι] [semilattice_sup ι] {s : ι → set α}
(hs : ∀ n, measurable_set (s n)) (hm : antitone s) (hf : ∃ i, μ (s i) ≠ ∞) :
tendsto (μ ∘ s) at_top (𝓝 (μ (⋂ n, s n))) :=
begin
rw measure_Inter_eq_infi hs (directed_of_sup hm) hf,
exact tendsto_at_top_infi (assume n m hnm, measure_mono $ hm hnm),
end
/-- One direction of the **Borel-Cantelli lemma**: if (sᵢ) is a sequence of sets such
that `∑ μ sᵢ` is finite, then the limit superior of the `sᵢ` is a null set. -/
lemma measure_limsup_eq_zero {s : ℕ → set α} (hs : ∑' i, μ (s i) ≠ ∞) : μ (limsup at_top s) = 0 :=
begin
-- First we replace the sequence `sₙ` with a sequence of measurable sets `tₙ ⊇ sₙ` of the same
-- measure.
set t : ℕ → set α := λ n, to_measurable μ (s n),
have ht : ∑' i, μ (t i) ≠ ∞, by simpa only [t, measure_to_measurable] using hs,
suffices : μ (limsup at_top t) = 0,
{ have A : s ≤ t := λ n, subset_to_measurable μ (s n),
-- TODO default args fail
exact measure_mono_null (limsup_le_limsup (eventually_of_forall A) is_cobounded_le_of_bot
is_bounded_le_of_top) this },
-- Next we unfold `limsup` for sets and replace equality with an inequality
simp only [limsup_eq_infi_supr_of_nat', set.infi_eq_Inter, set.supr_eq_Union,
← nonpos_iff_eq_zero],
-- Finally, we estimate `μ (⋃ i, t (i + n))` by `∑ i', μ (t (i + n))`
refine le_of_tendsto_of_tendsto'
(tendsto_measure_Inter (λ i, measurable_set.Union (λ b, measurable_set_to_measurable _ _)) _
⟨0, ne_top_of_le_ne_top ht (measure_Union_le t)⟩)
(ennreal.tendsto_sum_nat_add (μ ∘ t) ht) (λ n, measure_Union_le _),
intros n m hnm x,
simp only [set.mem_Union],
exact λ ⟨i, hi⟩, ⟨i + (m - n), by simpa only [add_assoc, nat.sub_add_cancel hnm] using hi⟩
end
lemma measure_if {x : β} {t : set β} {s : set α} :
μ (if x ∈ t then s else ∅) = indicator t (λ _, μ s) x :=
by { split_ifs; simp [h] }
end
section outer_measure
variables [ms : measurable_space α] {s t : set α}
include ms
/-- Obtain a measure by giving an outer measure where all sets in the σ-algebra are
Carathéodory measurable. -/
def outer_measure.to_measure (m : outer_measure α) (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 (μ : measure α) : ms ≤ μ.to_outer_measure.caratheodory :=
begin
assume s hs,
rw to_outer_measure_eq_induced_outer_measure,
refine outer_measure.of_function_caratheodory (λ t, le_infi $ λ ht, _),
rw [← measure_eq_extend (ht.inter hs),
← measure_eq_extend (ht.diff hs),
← measure_union _ (ht.inter hs) (ht.diff hs),
inter_union_diff],
exact le_refl _,
exact λ x ⟨⟨_, h₁⟩, _, h₂⟩, h₂ h₁
end
@[simp] lemma to_measure_to_outer_measure (m : outer_measure α) (h : ms ≤ m.caratheodory) :
(m.to_measure h).to_outer_measure = m.trim := rfl
@[simp] lemma to_measure_apply (m : outer_measure α) (h : ms ≤ m.caratheodory)
{s : set α} (hs : measurable_set s) : m.to_measure h s = m s :=
m.trim_eq hs
lemma le_to_measure_apply (m : outer_measure α) (h : ms ≤ m.caratheodory) (s : set α) :
m s ≤ m.to_measure h s :=
m.le_trim s
@[simp] lemma to_outer_measure_to_measure {μ : measure α} :
μ.to_outer_measure.to_measure (le_to_outer_measure_caratheodory _) = μ :=
measure.ext $ λ s, μ.to_outer_measure.trim_eq
@[simp] lemma bounded_by_measure (μ : measure α) :
outer_measure.bounded_by μ = μ.to_outer_measure :=
μ.to_outer_measure.bounded_by_eq_self
end outer_measure
variables {m0 : measurable_space α} [measurable_space β] [measurable_space γ]
variables {μ μ₁ μ₂ μ₃ ν ν' ν₁ ν₂ : measure α} {s s' t : set α}
namespace measure
protected lemma caratheodory {m : measurable_space α} (μ : measure α) (hs : measurable_set s) :
μ (t ∩ s) + μ (t \ s) = μ t :=
(le_to_outer_measure_caratheodory μ s hs t).symm
/-! ### The `ℝ≥0∞`-module of measures -/
instance [measurable_space α] : 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 {m : measurable_space α} :
(0 : measure α).to_outer_measure = 0 := rfl
@[simp, norm_cast] theorem coe_zero {m : measurable_space α} : ⇑(0 : measure α) = 0 := rfl
lemma eq_zero_of_is_empty [is_empty α] {m : measurable_space α} (μ : measure α) : μ = 0 :=
ext $ λ s hs, by simp only [eq_empty_of_is_empty s, measure_empty]
instance [measurable_space α] : inhabited (measure α) := ⟨0⟩
instance [measurable_space α] : 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 {m : measurable_space α} (μ₁ μ₂ : measure α) :
(μ₁ + μ₂).to_outer_measure = μ₁.to_outer_measure + μ₂.to_outer_measure := rfl
@[simp, norm_cast] theorem coe_add {m : measurable_space α} (μ₁ μ₂ : measure α) :
⇑(μ₁ + μ₂) = μ₁ + μ₂ := rfl
theorem add_apply {m : measurable_space α} (μ₁ μ₂ : measure α) (s : set α) :
(μ₁ + μ₂) s = μ₁ s + μ₂ s := rfl
instance add_comm_monoid [measurable_space α] : add_comm_monoid (measure α) :=
to_outer_measure_injective.add_comm_monoid to_outer_measure zero_to_outer_measure
add_to_outer_measure
instance [measurable_space α] : has_scalar ℝ≥0∞ (measure α) :=
⟨λ c μ,
{ to_outer_measure := c • μ.to_outer_measure,
m_Union := λ s hs hd, by simp [measure_Union, *, ennreal.tsum_mul_left],
trimmed := by rw [outer_measure.trim_smul, μ.trimmed] }⟩
@[simp] theorem smul_to_outer_measure {m : measurable_space α} (c : ℝ≥0∞) (μ : measure α) :
(c • μ).to_outer_measure = c • μ.to_outer_measure :=
rfl
@[simp, norm_cast] theorem coe_smul {m : measurable_space α} (c : ℝ≥0∞) (μ : measure α) :
⇑(c • μ) = c • μ :=
rfl
theorem smul_apply {m : measurable_space α} (c : ℝ≥0∞) (μ : measure α) (s : set α) :
(c • μ) s = c * μ s :=
rfl
instance [measurable_space α] : module ℝ≥0∞ (measure α) :=
injective.module ℝ≥0∞ ⟨to_outer_measure, zero_to_outer_measure, add_to_outer_measure⟩
to_outer_measure_injective smul_to_outer_measure
@[simp, norm_cast] theorem coe_nnreal_smul {m : measurable_space α} (c : ℝ≥0) (μ : measure α) :
⇑(c • μ) = c • μ :=
rfl
/-! ### The complete lattice of measures -/
/-- Measures are partially ordered.
The definition of less equal here is equivalent to the definition without the
measurable set condition, and this is shown by `measure.le_iff'`. It is defined
this way since, to prove `μ ≤ ν`, we may simply `intros s hs` instead of rewriting followed
by `intros s hs`. -/
instance [measurable_space α] : partial_order (measure α) :=
{ le := λ m₁ m₂, ∀ s, measurable_set 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 : μ₁ ≤ μ₂ ↔ ∀ s, measurable_set s → μ₁ s ≤ μ₂ s := iff.rfl
theorem to_outer_measure_le : μ₁.to_outer_measure ≤ μ₂.to_outer_measure ↔ μ₁ ≤ μ₂ :=
by rw [← μ₂.trimmed, outer_measure.le_trim_iff]; refl
theorem le_iff' : μ₁ ≤ μ₂ ↔ ∀ s, μ₁ s ≤ μ₂ s :=
to_outer_measure_le.symm
theorem lt_iff : μ < ν ↔ μ ≤ ν ∧ ∃ s, measurable_set s ∧ μ s < ν s :=
lt_iff_le_not_le.trans $ and_congr iff.rfl $ by simp only [le_iff, not_forall, not_le, exists_prop]
theorem lt_iff' : μ < ν ↔ μ ≤ ν ∧ ∃ s, μ s < ν s :=
lt_iff_le_not_le.trans $ and_congr iff.rfl $ by simp only [le_iff', not_forall, not_le]
instance covariant_add_le [measurable_space α] : covariant_class (measure α) (measure α) (+) (≤) :=
⟨λ ν μ₁ μ₂ hμ s hs, add_le_add_left (hμ s hs) _⟩
protected lemma le_add_left (h : μ ≤ ν) : μ ≤ ν' + ν :=
λ s hs, le_add_left (h s hs)
protected lemma le_add_right (h : μ ≤ ν) : μ ≤ ν + ν' :=
λ s hs, le_add_right (h s hs)
section Inf
variables {m : set (measure α)}
lemma Inf_caratheodory (s : set α) (hs : measurable_set s) :
(Inf (to_outer_measure '' m)).caratheodory.measurable_set' s :=
begin
rw [outer_measure.Inf_eq_bounded_by_Inf_gen],
refine outer_measure.bounded_by_caratheodory (λ t, _),
simp only [outer_measure.Inf_gen, le_infi_iff, ball_image_iff, coe_to_outer_measure,
measure_eq_infi t],
intros μ hμ u htu hu,
have hm : ∀ {s t}, s ⊆ t → outer_measure.Inf_gen (to_outer_measure '' m) s ≤ μ t,
{ intros s t hst,
rw [outer_measure.Inf_gen_def],
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 [measurable_space α] : has_Inf (measure α) :=
⟨λ m, (Inf (to_outer_measure '' m)).to_measure $ Inf_caratheodory⟩
lemma Inf_apply (hs : measurable_set s) : Inf m s = Inf (to_outer_measure '' m) s :=
to_measure_apply _ _ hs
private lemma measure_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 measure_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 [measurable_space α] : complete_semilattice_Inf (measure α) :=
{ Inf_le := λ s a, measure_Inf_le,
le_Inf := λ s a, measure_le_Inf,
..(by apply_instance : partial_order (measure α)),
..(by apply_instance : has_Inf (measure α)), }
instance [measurable_space α] : complete_lattice (measure α) :=
{ bot := 0,
bot_le := assume a s hs, by exact bot_le,
/- Adding an explicit `top` makes `leanchecker` fail, see lean#364, disable for now
top := (⊤ : outer_measure α).to_measure (by rw [outer_measure.top_caratheodory]; exact le_top),
le_top := assume a s hs,
by cases s.eq_empty_or_nonempty with h h;
simp [h, to_measure_apply ⊤ _ hs, outer_measure.top_apply],
-/
.. complete_lattice_of_complete_semilattice_Inf (measure α) }
end Inf
protected lemma zero_le {m0 : measurable_space α} (μ : measure α) : 0 ≤ μ := bot_le
lemma nonpos_iff_eq_zero' : μ ≤ 0 ↔ μ = 0 :=
μ.zero_le.le_iff_eq
@[simp] lemma measure_univ_eq_zero : μ univ = 0 ↔ μ = 0 :=
⟨λ h, bot_unique $ λ s hs, trans_rel_left (≤) (measure_mono (subset_univ s)) h, λ h, h.symm ▸ rfl⟩
/-! ### Pushforward and pullback -/
/-- Lift a linear map between `outer_measure` spaces such that for each measure `μ` every measurable
set is caratheodory-measurable w.r.t. `f μ` to a linear map between `measure` spaces. -/
def lift_linear {m0 : measurable_space α} (f : outer_measure α →ₗ[ℝ≥0∞] outer_measure β)
(hf : ∀ μ : measure α, ‹_› ≤ (f μ.to_outer_measure).caratheodory) :
measure α →ₗ[ℝ≥0∞] measure β :=
{ to_fun := λ μ, (f μ.to_outer_measure).to_measure (hf μ),
map_add' := λ μ₁ μ₂, ext $ λ s hs, by simp [hs],
map_smul' := λ c μ, ext $ λ s hs, by simp [hs] }
@[simp] lemma lift_linear_apply {f : outer_measure α →ₗ[ℝ≥0∞] outer_measure β} (hf)
{s : set β} (hs : measurable_set s) : lift_linear f hf μ s = f μ.to_outer_measure s :=
to_measure_apply _ _ hs
lemma le_lift_linear_apply {f : outer_measure α →ₗ[ℝ≥0∞] outer_measure β} (hf) (s : set β) :
f μ.to_outer_measure s ≤ lift_linear f hf μ s :=
le_to_measure_apply _ _ s
/-- The pushforward of a measure. It is defined to be `0` if `f` is not a measurable function. -/
def map [measurable_space α] (f : α → β) : measure α →ₗ[ℝ≥0∞] measure β :=
if hf : measurable f then
lift_linear (outer_measure.map f) $ λ μ s hs t,
le_to_outer_measure_caratheodory μ _ (hf hs) (f ⁻¹' t)
else 0
/-- We can evaluate the pushforward on measurable sets. For non-measurable sets, see
`measure_theory.measure.le_map_apply` and `measurable_equiv.map_apply`. -/
@[simp] theorem map_apply {f : α → β} (hf : measurable f) {s : set β} (hs : measurable_set s) :
map f μ s = μ (f ⁻¹' s) :=
by simp [map, dif_pos hf, hs]
lemma map_to_outer_measure {f : α → β} (hf : measurable f) :
(map f μ).to_outer_measure = (outer_measure.map f μ.to_outer_measure).trim :=
begin
rw [← trimmed, outer_measure.trim_eq_trim_iff],
intros s hs,
rw [coe_to_outer_measure, map_apply hf hs, outer_measure.map_apply, coe_to_outer_measure]
end
theorem map_of_not_measurable {f : α → β} (hf : ¬measurable f) :
map f μ = 0 :=
by rw [map, dif_neg hf, linear_map.zero_apply]
@[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 hs, hg.comp hf, ← preimage_comp]
@[mono] lemma map_mono (f : α → β) (h : μ ≤ ν) : map f μ ≤ map f ν :=
if hf : measurable f then λ s hs, by simp only [map_apply hf hs, h _ (hf hs)]
else by simp only [map_of_not_measurable hf, le_rfl]
/-- Even if `s` is not measurable, we can bound `map f μ s` from below.
See also `measurable_equiv.map_apply`. -/
theorem le_map_apply {f : α → β} (hf : measurable f) (s : set β) : μ (f ⁻¹' s) ≤ map f μ s :=
begin
rw [measure_eq_infi' (map f μ)], refine le_infi _, rintro ⟨t, hst, ht⟩,
convert measure_mono (preimage_mono hst),
exact map_apply hf ht
end
/-- Even if `s` is not measurable, `map f μ s = 0` implies that `μ (f ⁻¹' s) = 0`. -/
lemma preimage_null_of_map_null {f : α → β} (hf : measurable f) {s : set β}
(hs : map f μ s = 0) : μ (f ⁻¹' s) = 0 :=
nonpos_iff_eq_zero.mp $ (le_map_apply hf s).trans_eq hs
lemma tendsto_ae_map {f : α → β} (hf : measurable f) : tendsto f μ.ae (map f μ).ae :=
λ s hs, preimage_null_of_map_null hf hs
/-- Pullback of a `measure`. If `f` sends each `measurable` set to a `measurable` set, then for each
measurable set `s` we have `comap f μ s = μ (f '' s)`. -/
def comap [measurable_space α] (f : α → β) : measure β →ₗ[ℝ≥0∞] measure α :=
if hf : injective f ∧ ∀ s, measurable_set s → measurable_set (f '' s) then
lift_linear (outer_measure.comap f) $ λ μ s hs t,
begin
simp only [coe_to_outer_measure, outer_measure.comap_apply, ← image_inter hf.1,
image_diff hf.1],
apply le_to_outer_measure_caratheodory,
exact hf.2 s hs
end
else 0
lemma comap_apply {β} [measurable_space α] {mβ : measurable_space β} (f : α → β) (hfi : injective f)
(hf : ∀ s, measurable_set s → measurable_set (f '' s)) (μ : measure β) (hs : measurable_set s) :
comap f μ s = μ (f '' s) :=
begin
rw [comap, dif_pos, lift_linear_apply _ hs, outer_measure.comap_apply, coe_to_outer_measure],
exact ⟨hfi, hf⟩
end
/-! ### Restricting a measure -/
/-- Restrict a measure `μ` to a set `s` as an `ℝ≥0∞`-linear map. -/
def restrictₗ {m0 : measurable_space α} (s : set α) : measure α →ₗ[ℝ≥0∞] measure α :=
lift_linear (outer_measure.restrict s) $ λ μ s' hs' t,
begin
suffices : μ (s ∩ t) = μ (s ∩ t ∩ s') + μ (s ∩ t \ s'),
{ simpa [← set.inter_assoc, set.inter_comm _ s, ← inter_diff_assoc] },
exact le_to_outer_measure_caratheodory _ _ hs' _,
end
/-- Restrict a measure `μ` to a set `s`. -/
def restrict {m0 : measurable_space α} (μ : measure α) (s : set α) : measure α := restrictₗ s μ
@[simp] lemma restrictₗ_apply {m0 : measurable_space α} (s : set α) (μ : measure α) :
restrictₗ s μ = μ.restrict s :=
rfl
/-- If `t` is a measurable set, then the measure of `t` with respect to the restriction of
the measure to `s` equals the outer measure of `t ∩ s`. An alternate version requiring that `s`
be measurable instead of `t` exists as `measure.restrict_apply'`. -/
@[simp] lemma restrict_apply (ht : measurable_set t) : μ.restrict s t = μ (t ∩ s) :=
by simp [← restrictₗ_apply, restrictₗ, ht]
lemma restrict_eq_self (h_meas_t : measurable_set t) (h : t ⊆ s) : μ.restrict s t = μ t :=
by rw [restrict_apply h_meas_t, inter_eq_left_iff_subset.mpr h]
lemma restrict_apply_self {m0 : measurable_space α} (μ : measure α) (h_meas_s : measurable_set s) :
(μ.restrict s) s = μ s := (restrict_eq_self h_meas_s (set.subset.refl _))
lemma restrict_apply_univ (s : set α) : μ.restrict s univ = μ s :=
by rw [restrict_apply measurable_set.univ, set.univ_inter]
lemma le_restrict_apply (s t : set α) :
μ (t ∩ s) ≤ μ.restrict s t :=
by { rw [restrict, restrictₗ], convert le_lift_linear_apply _ t, simp }
@[simp] lemma restrict_add {m0 : measurable_space α} (μ ν : measure α) (s : set α) :
(μ + ν).restrict s = μ.restrict s + ν.restrict s :=
(restrictₗ s).map_add μ ν
@[simp] lemma restrict_zero {m0 : measurable_space α} (s : set α) :
(0 : measure α).restrict s = 0 :=
(restrictₗ s).map_zero
@[simp] lemma restrict_smul {m0 : measurable_space α} (c : ℝ≥0∞) (μ : measure α) (s : set α) :
(c • μ).restrict s = c • μ.restrict s :=
(restrictₗ s).map_smul c μ
@[simp] lemma restrict_restrict (hs : measurable_set s) :
(μ.restrict t).restrict s = μ.restrict (s ∩ t) :=
ext $ λ u hu, by simp [*, set.inter_assoc]
lemma restrict_comm (hs : measurable_set s) (ht : measurable_set t) :
(μ.restrict t).restrict s = (μ.restrict s).restrict t :=
by rw [restrict_restrict hs, restrict_restrict ht, inter_comm]
lemma restrict_apply_eq_zero (ht : measurable_set t) : μ.restrict s t = 0 ↔ μ (t ∩ s) = 0 :=
by rw [restrict_apply ht]
lemma measure_inter_eq_zero_of_restrict (h : μ.restrict s t = 0) : μ (t ∩ s) = 0 :=
nonpos_iff_eq_zero.1 (h ▸ le_restrict_apply _ _)
lemma restrict_apply_eq_zero' (hs : measurable_set s) : μ.restrict s t = 0 ↔ μ (t ∩ s) = 0 :=
begin
refine ⟨measure_inter_eq_zero_of_restrict, λ h, _⟩,
rcases exists_measurable_superset_of_null h with ⟨t', htt', ht', ht'0⟩,
apply measure_mono_null ((inter_subset _ _ _).1 htt'),
rw [restrict_apply (hs.compl.union ht'), union_inter_distrib_right, compl_inter_self,
set.empty_union],
exact measure_mono_null (inter_subset_left _ _) ht'0
end
@[simp] lemma restrict_eq_zero : μ.restrict s = 0 ↔ μ s = 0 :=
by rw [← measure_univ_eq_zero, restrict_apply_univ]
lemma restrict_zero_set {s : set α} (h : μ s = 0) :
μ.restrict s = 0 :=
by simp only [measure.restrict_eq_zero, h]
@[simp] lemma restrict_empty : μ.restrict ∅ = 0 := ext $ λ s hs, by simp [hs]
@[simp] lemma restrict_univ : μ.restrict univ = μ := ext $ λ s hs, by simp [hs]
lemma restrict_eq_self_of_measurable_subset (ht : measurable_set t) (t_subset : t ⊆ s) :
μ.restrict s t = μ t :=
by rw [measure.restrict_apply ht, set.inter_eq_self_of_subset_left t_subset]
lemma restrict_union_apply (h : disjoint (t ∩ s) (t ∩ s')) (hs : measurable_set s)
(hs' : measurable_set s') (ht : measurable_set t) :
μ.restrict (s ∪ s') t = μ.restrict s t + μ.restrict s' t :=
begin
simp only [restrict_apply, ht, set.inter_union_distrib_left],
exact measure_union h (ht.inter hs) (ht.inter hs'),
end
lemma restrict_union (h : disjoint s t) (hs : measurable_set s) (ht : measurable_set t) :
μ.restrict (s ∪ t) = μ.restrict s + μ.restrict t :=
ext $ λ t' ht', restrict_union_apply (h.mono inf_le_right inf_le_right) hs ht ht'
lemma restrict_union_add_inter (hs : measurable_set s) (ht : measurable_set t) :
μ.restrict (s ∪ t) + μ.restrict (s ∩ t) = μ.restrict s + μ.restrict t :=
begin
ext1 u hu,
simp only [add_apply, restrict_apply hu, inter_union_distrib_left],
convert measure_union_add_inter (hu.inter hs) (hu.inter ht) using 3,
rw [set.inter_left_comm (u ∩ s), set.inter_assoc, ← set.inter_assoc u u, set.inter_self]
end
@[simp] lemma restrict_add_restrict_compl (hs : measurable_set s) :
μ.restrict s + μ.restrict sᶜ = μ :=
by rw [← restrict_union (@disjoint_compl_right (set α) _ _) hs hs.compl,
union_compl_self, restrict_univ]
@[simp] lemma restrict_compl_add_restrict (hs : measurable_set s) :
μ.restrict sᶜ + μ.restrict s = μ :=
by rw [add_comm, restrict_add_restrict_compl hs]
lemma restrict_union_le (s s' : set α) : μ.restrict (s ∪ s') ≤ μ.restrict s + μ.restrict s' :=
begin
intros t ht,
suffices : μ (t ∩ s ∪ t ∩ s') ≤ μ (t ∩ s) + μ (t ∩ s'),
by simpa [ht, inter_union_distrib_left],
apply measure_union_le
end
lemma restrict_Union_apply [encodable ι] {s : ι → set α} (hd : pairwise (disjoint on s))
(hm : ∀ i, measurable_set (s i)) {t : set α} (ht : measurable_set t) :
μ.restrict (⋃ i, s i) t = ∑' i, μ.restrict (s i) t :=
begin
simp only [restrict_apply, ht, inter_Union],
exact measure_Union (λ i j hij, (hd i j hij).mono inf_le_right inf_le_right)
(λ i, ht.inter (hm i))
end
lemma restrict_Union_apply_eq_supr [encodable ι] {s : ι → set α}
(hm : ∀ i, measurable_set (s i)) (hd : directed (⊆) s) {t : set α} (ht : measurable_set t) :
μ.restrict (⋃ i, s i) t = ⨆ i, μ.restrict (s i) t :=
begin
simp only [restrict_apply ht, inter_Union],
rw [measure_Union_eq_supr],
exacts [λ i, ht.inter (hm i), hd.mono_comp _ (λ s₁ s₂, inter_subset_inter_right _)]
end
lemma restrict_map {f : α → β} (hf : measurable f) {s : set β} (hs : measurable_set s) :
(map f μ).restrict s = map f (μ.restrict $ f ⁻¹' s) :=
ext $ λ t ht, by simp [*, hf ht]
lemma map_comap_subtype_coe {m0 : measurable_space α} (hs : measurable_set s) :
(map (coe : s → α)).comp (comap coe) = restrictₗ s :=
linear_map.ext $ λ μ, ext $ λ t ht,
by rw [restrictₗ_apply, restrict_apply ht, linear_map.comp_apply,
map_apply measurable_subtype_coe ht,
comap_apply (coe : s → α) subtype.val_injective (λ _, hs.subtype_image) _
(measurable_subtype_coe ht), subtype.image_preimage_coe]
/-- Restriction of a measure to a subset is monotone both in set and in measure. -/
lemma restrict_mono' {m0 : measurable_space α} ⦃s s' : set α⦄ ⦃μ ν : measure α⦄
(hs : s ≤ᵐ[μ] s') (hμν : μ ≤ ν) :
μ.restrict s ≤ ν.restrict s' :=
assume t ht,
calc μ.restrict s t = μ (t ∩ s) : restrict_apply ht
... ≤ μ (t ∩ s') : measure_mono_ae $ hs.mono $ λ x hx ⟨hxt, hxs⟩, ⟨hxt, hx hxs⟩
... ≤ ν (t ∩ s') : le_iff'.1 hμν (t ∩ s')
... = ν.restrict s' t : (restrict_apply ht).symm
/-- Restriction of a measure to a subset is monotone both in set and in measure. -/
@[mono] lemma restrict_mono {m0 : measurable_space α} ⦃s s' : set α⦄ (hs : s ⊆ s') ⦃μ ν : measure α⦄
(hμν : μ ≤ ν) :
μ.restrict s ≤ ν.restrict s' :=
restrict_mono' (ae_of_all _ hs) hμν
lemma restrict_le_self : μ.restrict s ≤ μ :=
assume t ht,
calc μ.restrict s t = μ (t ∩ s) : restrict_apply ht
... ≤ μ t : measure_mono $ inter_subset_left t s
lemma restrict_congr_meas (hs : measurable_set s) :
μ.restrict s = ν.restrict s ↔ ∀ t ⊆ s, measurable_set t → μ t = ν t :=
⟨λ H t hts ht,
by rw [← inter_eq_self_of_subset_left hts, ← restrict_apply ht, H, restrict_apply ht],
λ H, ext $ λ t ht,
by rw [restrict_apply ht, restrict_apply ht, H _ (inter_subset_right _ _) (ht.inter hs)]⟩
lemma restrict_congr_mono (hs : s ⊆ t) (hm : measurable_set s) (h : μ.restrict t = ν.restrict t) :
μ.restrict s = ν.restrict s :=
by rw [← inter_eq_self_of_subset_left hs, ← restrict_restrict hm, h, restrict_restrict hm]
/-- If two measures agree on all measurable subsets of `s` and `t`, then they agree on all
measurable subsets of `s ∪ t`. -/
lemma restrict_union_congr (hsm : measurable_set s) (htm : measurable_set t) :
μ.restrict (s ∪ t) = ν.restrict (s ∪ t) ↔
μ.restrict s = ν.restrict s ∧ μ.restrict t = ν.restrict t :=
begin
refine ⟨λ h, ⟨restrict_congr_mono (subset_union_left _ _) hsm h,
restrict_congr_mono (subset_union_right _ _) htm h⟩, _⟩,
simp only [restrict_congr_meas, hsm, htm, hsm.union htm],
rintros ⟨hs, ht⟩ u hu hum,
rw [measure_eq_inter_diff hum hsm, measure_eq_inter_diff hum hsm,
hs _ (inter_subset_right _ _) (hum.inter hsm),
ht _ (diff_subset_iff.2 hu) (hum.diff hsm)]
end
lemma restrict_finset_bUnion_congr {s : finset ι} {t : ι → set α}
(htm : ∀ i ∈ s, measurable_set (t i)) :
μ.restrict (⋃ i ∈ s, t i) = ν.restrict (⋃ i ∈ s, t i) ↔
∀ i ∈ s, μ.restrict (t i) = ν.restrict (t i) :=
begin
induction s using finset.induction_on with i s hi hs, { simp },
simp only [finset.mem_insert, or_imp_distrib, forall_and_distrib, forall_eq] at htm ⊢,
simp only [finset.set_bUnion_insert, ← hs htm.2],
exact restrict_union_congr htm.1 (s.measurable_set_bUnion htm.2)
end
lemma restrict_Union_congr [encodable ι] {s : ι → set α} (hm : ∀ i, measurable_set (s i)) :
μ.restrict (⋃ i, s i) = ν.restrict (⋃ i, s i) ↔
∀ i, μ.restrict (s i) = ν.restrict (s i) :=
begin
refine ⟨λ h i, restrict_congr_mono (subset_Union _ _) (hm i) h, λ h, _⟩,
ext1 t ht,
have M : ∀ t : finset ι, measurable_set (⋃ i ∈ t, s i) :=
λ t, t.measurable_set_bUnion (λ i _, hm i),
have D : directed (⊆) (λ t : finset ι, ⋃ i ∈ t, s i) :=
directed_of_sup (λ t₁ t₂ ht, bUnion_subset_bUnion_left ht),
rw [Union_eq_Union_finset],
simp only [restrict_Union_apply_eq_supr M D ht,
(restrict_finset_bUnion_congr (λ i hi, hm i)).2 (λ i hi, h i)],
end
lemma restrict_bUnion_congr {s : set ι} {t : ι → set α} (hc : countable s)
(htm : ∀ i ∈ s, measurable_set (t i)) :
μ.restrict (⋃ i ∈ s, t i) = ν.restrict (⋃ i ∈ s, t i) ↔
∀ i ∈ s, μ.restrict (t i) = ν.restrict (t i) :=
begin
simp only [bUnion_eq_Union, set_coe.forall'] at htm ⊢,
haveI := hc.to_encodable,
exact restrict_Union_congr htm
end
lemma restrict_sUnion_congr {S : set (set α)} (hc : countable S) (hm : ∀ s ∈ S, measurable_set s) :
μ.restrict (⋃₀ S) = ν.restrict (⋃₀ S) ↔ ∀ s ∈ S, μ.restrict s = ν.restrict s :=
by rw [sUnion_eq_bUnion, restrict_bUnion_congr hc hm]
/-- This lemma shows that `restrict` and `to_outer_measure` commute. Note that the LHS has a
restrict on measures and the RHS has a restrict on outer measures. -/
lemma restrict_to_outer_measure_eq_to_outer_measure_restrict (h : measurable_set s) :
(μ.restrict s).to_outer_measure = outer_measure.restrict s μ.to_outer_measure :=
by simp_rw [restrict, restrictₗ, lift_linear, linear_map.coe_mk, to_measure_to_outer_measure,
outer_measure.restrict_trim h, μ.trimmed]
/-- This lemma shows that `Inf` and `restrict` commute for measures. -/
lemma restrict_Inf_eq_Inf_restrict {m0 : measurable_space α} {m : set (measure α)}
(hm : m.nonempty) (ht : measurable_set t) :
(Inf m).restrict t = Inf ((λ μ : measure α, μ.restrict t) '' m) :=
begin
ext1 s hs,
simp_rw [Inf_apply hs, restrict_apply hs, Inf_apply (measurable_set.inter hs ht), set.image_image,
restrict_to_outer_measure_eq_to_outer_measure_restrict ht, ← set.image_image _ to_outer_measure,
← outer_measure.restrict_Inf_eq_Inf_restrict _ (hm.image _),
outer_measure.restrict_apply]
end
/-- If `s` is a measurable set, then the outer measure of `t` with respect to the restriction of
the measure to `s` equals the outer measure of `t ∩ s`. This is an alternate version of
`measure.restrict_apply`, requiring that `s` is measurable instead of `t`. -/
lemma restrict_apply' (hs : measurable_set s) : μ.restrict s t = μ (t ∩ s) :=
by rw [← coe_to_outer_measure, measure.restrict_to_outer_measure_eq_to_outer_measure_restrict hs,
outer_measure.restrict_apply s t _, coe_to_outer_measure]
lemma restrict_eq_self_of_subset_of_measurable (hs : measurable_set s) (t_subset : t ⊆ s) :
μ.restrict s t = μ t :=
by rw [restrict_apply' hs, set.inter_eq_self_of_subset_left t_subset]
/-! ### Extensionality results -/
/-- Two measures are equal if they have equal restrictions on a spanning collection of sets
(formulated using `Union`). -/
lemma ext_iff_of_Union_eq_univ [encodable ι] {s : ι → set α}
(hm : ∀ i, measurable_set (s i)) (hs : (⋃ i, s i) = univ) :
μ = ν ↔ ∀ i, μ.restrict (s i) = ν.restrict (s i) :=
by rw [← restrict_Union_congr hm, hs, restrict_univ, restrict_univ]
alias ext_iff_of_Union_eq_univ ↔ _ measure_theory.measure.ext_of_Union_eq_univ
/-- Two measures are equal if they have equal restrictions on a spanning collection of sets
(formulated using `bUnion`). -/
lemma ext_iff_of_bUnion_eq_univ {S : set ι} {s : ι → set α} (hc : countable S)
(hm : ∀ i ∈ S, measurable_set (s i)) (hs : (⋃ i ∈ S, s i) = univ) :
μ = ν ↔ ∀ i ∈ S, μ.restrict (s i) = ν.restrict (s i) :=
by rw [← restrict_bUnion_congr hc hm, hs, restrict_univ, restrict_univ]
alias ext_iff_of_bUnion_eq_univ ↔ _ measure_theory.measure.ext_of_bUnion_eq_univ
/-- Two measures are equal if they have equal restrictions on a spanning collection of sets
(formulated using `sUnion`). -/
lemma ext_iff_of_sUnion_eq_univ {S : set (set α)} (hc : countable S)
(hm : ∀ s ∈ S, measurable_set s) (hs : (⋃₀ S) = univ) :
μ = ν ↔ ∀ s ∈ S, μ.restrict s = ν.restrict s :=
ext_iff_of_bUnion_eq_univ hc hm $ by rwa ← sUnion_eq_bUnion
alias ext_iff_of_sUnion_eq_univ ↔ _ measure_theory.measure.ext_of_sUnion_eq_univ
lemma ext_of_generate_from_of_cover {S T : set (set α)}
(h_gen : ‹_› = generate_from S) (hc : countable T)
(h_inter : is_pi_system S)
(hm : ∀ t ∈ T, measurable_set t) (hU : ⋃₀ T = univ) (htop : ∀ t ∈ T, μ t ≠ ∞)
(ST_eq : ∀ (t ∈ T) (s ∈ S), μ (s ∩ t) = ν (s ∩ t)) (T_eq : ∀ t ∈ T, μ t = ν t) :
μ = ν :=
begin
refine ext_of_sUnion_eq_univ hc hm hU (λ t ht, _),
ext1 u hu,
simp only [restrict_apply hu],
refine induction_on_inter h_gen h_inter _ (ST_eq t ht) _ _ hu,
{ simp only [set.empty_inter, measure_empty] },
{ intros v hv hvt,
have := T_eq t ht,
rw [set.inter_comm] at hvt ⊢,
rwa [measure_eq_inter_diff (hm _ ht) hv, measure_eq_inter_diff (hm _ ht) hv, ← hvt,
ennreal.add_right_inj] at this,
exact ne_top_of_le_ne_top (htop t ht) (measure_mono $ set.inter_subset_left _ _) },
{ intros f hfd hfm h_eq,
have : pairwise (disjoint on λ n, f n ∩ t) :=
λ m n hmn, (hfd m n hmn).mono (inter_subset_left _ _) (inter_subset_left _ _),
simp only [Union_inter, measure_Union this (λ n, (hfm n).inter (hm t ht)), h_eq] }
end
/-- Two measures are equal if they are equal on the π-system generating the σ-algebra,
and they are both finite on a increasing spanning sequence of sets in the π-system.
This lemma is formulated using `sUnion`. -/
lemma ext_of_generate_from_of_cover_subset {S T : set (set α)}
(h_gen : ‹_› = generate_from S)
(h_inter : is_pi_system S)
(h_sub : T ⊆ S) (hc : countable T) (hU : ⋃₀ T = univ) (htop : ∀ s ∈ T, μ s ≠ ∞)
(h_eq : ∀ s ∈ S, μ s = ν s) :
μ = ν :=
begin
refine ext_of_generate_from_of_cover h_gen hc h_inter _ hU htop _ (λ t ht, h_eq t (h_sub ht)),
{ intros t ht, rw [h_gen], exact generate_measurable.basic _ (h_sub ht) },
{ intros t ht s hs, cases (s ∩ t).eq_empty_or_nonempty with H H,
{ simp only [H, measure_empty] },
{ exact h_eq _ (h_inter _ _ hs (h_sub ht) H) } }
end
/-- Two measures are equal if they are equal on the π-system generating the σ-algebra,
and they are both finite on a increasing spanning sequence of sets in the π-system.
This lemma is formulated using `Union`.
`finite_spanning_sets_in.ext` is a reformulation of this lemma. -/
lemma ext_of_generate_from_of_Union (C : set (set α)) (B : ℕ → set α)
(hA : ‹_› = generate_from C) (hC : is_pi_system C) (h1B : (⋃ i, B i) = univ)
(h2B : ∀ i, B i ∈ C) (hμB : ∀ i, μ (B i) ≠ ∞) (h_eq : ∀ s ∈ C, μ s = ν s) : μ = ν :=
begin
refine ext_of_generate_from_of_cover_subset hA hC _ (countable_range B) h1B _ h_eq,
{ rintro _ ⟨i, rfl⟩, apply h2B },
{ rintro _ ⟨i, rfl⟩, apply hμB }
end
section dirac
variable [measurable_space α]
/-- The dirac measure. -/
def dirac (a : α) : measure α :=
(outer_measure.dirac a).to_measure (by simp)
lemma le_dirac_apply {a} : s.indicator 1 a ≤ dirac a s :=
outer_measure.dirac_apply a s ▸ le_to_measure_apply _ _ _
@[simp] lemma dirac_apply' (a : α) (hs : measurable_set s) :
dirac a s = s.indicator 1 a :=
to_measure_apply _ _ hs
@[simp] lemma dirac_apply_of_mem {a : α} (h : a ∈ s) :
dirac a s = 1 :=
begin
have : ∀ t : set α, a ∈ t → t.indicator (1 : α → ℝ≥0∞) a = 1,
from λ t ht, indicator_of_mem ht 1,
refine le_antisymm (this univ trivial ▸ _) (this s h ▸ le_dirac_apply),
rw [← dirac_apply' a measurable_set.univ],
exact measure_mono (subset_univ s)
end
@[simp] lemma dirac_apply [measurable_singleton_class α] (a : α) (s : set α) :
dirac a s = s.indicator 1 a :=
begin
by_cases h : a ∈ s, by rw [dirac_apply_of_mem h, indicator_of_mem h, pi.one_apply],
rw [indicator_of_not_mem h, ← nonpos_iff_eq_zero],
calc dirac a s ≤ dirac a {a}ᶜ : measure_mono (subset_compl_comm.1 $ singleton_subset_iff.2 h)
... = 0 : by simp [dirac_apply' _ (measurable_set_singleton _).compl]
end
lemma map_dirac {f : α → β} (hf : measurable f) (a : α) :
map f (dirac a) = dirac (f a) :=
ext $ assume s hs, by simp [hs, map_apply hf hs, hf hs, indicator_apply]
end dirac
section sum
include m0
/-- Sum of an indexed family of measures. -/
def sum (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 _)
lemma le_sum_apply (f : ι → measure α) (s : set α) : (∑' i, f i s) ≤ sum f s :=
le_to_measure_apply _ _ _
@[simp] lemma sum_apply (f : ι → measure α) {s : set α} (hs : measurable_set s) :
sum f s = ∑' i, f i s :=
to_measure_apply _ _ hs
lemma le_sum (μ : ι → measure α) (i : ι) : μ i ≤ sum μ :=
λ s hs, by simp only [sum_apply μ hs, ennreal.le_tsum i]
@[simp] lemma sum_bool (f : bool → measure α) : sum f = f tt + f ff :=
ext $ λ s hs, by simp [hs, tsum_fintype]
@[simp] lemma sum_cond (μ ν : measure α) : sum (λ b, cond b μ ν) = μ + ν := sum_bool _
@[simp] lemma restrict_sum (μ : ι → measure α) {s : set α} (hs : measurable_set s) :
(sum μ).restrict s = sum (λ i, (μ i).restrict s) :=
ext $ λ t ht, by simp only [sum_apply, restrict_apply, ht, ht.inter hs]
lemma sum_congr {μ ν : ℕ → measure α} (h : ∀ n, μ n = ν n) : sum μ = sum ν :=
by { congr, ext1 n, exact h n }
lemma sum_add_sum (μ ν : ℕ → measure α) : sum μ + sum ν = sum (λ n, μ n + ν n) :=
begin
ext1 s hs,
simp only [add_apply, sum_apply _ hs, pi.add_apply, coe_add,
tsum_add ennreal.summable ennreal.summable],
end
/-- If `f` is a map with encodable codomain, then `map f μ` is the sum of Dirac measures -/
lemma map_eq_sum [encodable β] [measurable_singleton_class β]
(μ : measure α) (f : α → β) (hf : measurable f) :
map f μ = sum (λ b : β, μ (f ⁻¹' {b}) • dirac b) :=
begin
ext1 s hs,
have : ∀ y ∈ s, measurable_set (f ⁻¹' {y}), from λ y _, hf (measurable_set_singleton _),
simp [← tsum_measure_preimage_singleton (countable_encodable s) this, *,
tsum_subtype s (λ b, μ (f ⁻¹' {b})), ← indicator_mul_right s (λ b, μ (f ⁻¹' {b}))]
end
/-- A measure on an encodable type is a sum of dirac measures. -/
@[simp] lemma sum_smul_dirac [encodable α] [measurable_singleton_class α] (μ : measure α) :
sum (λ a, μ {a} • dirac a) = μ :=
by simpa using (map_eq_sum μ id measurable_id).symm
omit m0
end sum
lemma restrict_Union [encodable ι] {s : ι → set α} (hd : pairwise (disjoint on s))
(hm : ∀ i, measurable_set (s i)) :
μ.restrict (⋃ i, s i) = sum (λ i, μ.restrict (s i)) :=
ext $ λ t ht, by simp only [sum_apply _ ht, restrict_Union_apply hd hm ht]
lemma restrict_Union_le [encodable ι] {s : ι → set α} :
μ.restrict (⋃ i, s i) ≤ sum (λ i, μ.restrict (s i)) :=
begin
intros t ht,
suffices : μ (⋃ i, t ∩ s i) ≤ ∑' i, μ (t ∩ s i), by simpa [ht, inter_Union],
apply measure_Union_le
end
section count
variable [measurable_space α]
/-- Counting measure on any measurable space. -/
def count : measure α := sum dirac
lemma le_count_apply : (∑' i : s, 1 : ℝ≥0∞) ≤ count s :=
calc (∑' i : s, 1 : ℝ≥0∞) = ∑' i, indicator s 1 i : tsum_subtype s 1
... ≤ ∑' i, dirac i s : ennreal.tsum_le_tsum $ λ x, le_dirac_apply
... ≤ count s : le_sum_apply _ _
lemma count_apply (hs : measurable_set s) : count s = ∑' i : s, 1 :=
by simp only [count, sum_apply, hs, dirac_apply', ← tsum_subtype s 1, pi.one_apply]
@[simp] lemma count_apply_finset [measurable_singleton_class α] (s : finset α) :
count (↑s : set α) = s.card :=
calc count (↑s : set α) = ∑' i : (↑s : set α), 1 : count_apply s.measurable_set
... = ∑ i in s, 1 : s.tsum_subtype 1
... = s.card : by simp
lemma count_apply_finite [measurable_singleton_class α] (s : set α) (hs : finite s) :
count s = hs.to_finset.card :=
by rw [← count_apply_finset, finite.coe_to_finset]
/-- `count` measure evaluates to infinity at infinite sets. -/
lemma count_apply_infinite (hs : s.infinite) : count s = ∞ :=
begin
refine top_unique (le_of_tendsto' ennreal.tendsto_nat_nhds_top $ λ n, _),
rcases hs.exists_subset_card_eq n with ⟨t, ht, rfl⟩,
calc (t.card : ℝ≥0∞) = ∑ i in t, 1 : by simp
... = ∑' i : (t : set α), 1 : (t.tsum_subtype 1).symm
... ≤ count (t : set α) : le_count_apply
... ≤ count s : measure_mono ht
end
@[simp] lemma count_apply_eq_top [measurable_singleton_class α] : count s = ∞ ↔ s.infinite :=
begin
by_cases hs : s.finite,
{ simp [set.infinite, hs, count_apply_finite] },
{ change s.infinite at hs,
simp [hs, count_apply_infinite] }
end
@[simp] lemma count_apply_lt_top [measurable_singleton_class α] : count s < ∞ ↔ s.finite :=
calc count s < ∞ ↔ count s ≠ ∞ : lt_top_iff_ne_top
... ↔ ¬s.infinite : not_congr count_apply_eq_top
... ↔ s.finite : not_not
end count
/-! ### Absolute continuity -/
/-- We say that `μ` is absolutely continuous with respect to `ν`, or that `μ` is dominated by `ν`,
if `ν(A) = 0` implies that `μ(A) = 0`. -/
def absolutely_continuous {m0 : measurable_space α} (μ ν : measure α) : Prop :=
∀ ⦃s : set α⦄, ν s = 0 → μ s = 0
localized "infix ` ≪ `:50 := measure_theory.measure.absolutely_continuous" in measure_theory
lemma absolutely_continuous_of_le (h : μ ≤ ν) : μ ≪ ν :=
λ s hs, nonpos_iff_eq_zero.1 $ hs ▸ le_iff'.1 h s
alias absolutely_continuous_of_le ← has_le.le.absolutely_continuous
lemma absolutely_continuous_of_eq (h : μ = ν) : μ ≪ ν :=
h.le.absolutely_continuous
alias absolutely_continuous_of_eq ← eq.absolutely_continuous
namespace absolutely_continuous
lemma mk (h : ∀ ⦃s : set α⦄, measurable_set s → ν s = 0 → μ s = 0) : μ ≪ ν :=
begin
intros s hs,
rcases exists_measurable_superset_of_null hs with ⟨t, h1t, h2t, h3t⟩,
exact measure_mono_null h1t (h h2t h3t),
end
@[refl] protected lemma refl {m0 : measurable_space α} (μ : measure α) : μ ≪ μ :=
rfl.absolutely_continuous
protected lemma rfl : μ ≪ μ := λ s hs, hs
@[trans] protected lemma trans (h1 : μ₁ ≪ μ₂) (h2 : μ₂ ≪ μ₃) : μ₁ ≪ μ₃ :=
λ s hs, h1 $ h2 hs
@[mono] protected lemma map (h : μ ≪ ν) (f : α → β) : map f μ ≪ map f ν :=
if hf : measurable f then absolutely_continuous.mk $ λ s hs, by simpa [hf, hs] using @h _
else by simp only [map_of_not_measurable hf]
end absolutely_continuous
lemma ae_le_iff_absolutely_continuous : μ.ae ≤ ν.ae ↔ μ ≪ ν :=
⟨λ h s, by { rw [measure_zero_iff_ae_nmem, measure_zero_iff_ae_nmem], exact λ hs, h hs },
λ h s hs, h hs⟩
alias ae_le_iff_absolutely_continuous ↔ has_le.le.absolutely_continuous_of_ae
measure_theory.measure.absolutely_continuous.ae_le
alias absolutely_continuous.ae_le ← ae_mono'
lemma absolutely_continuous.ae_eq (h : μ ≪ ν) {f g : α → δ} (h' : f =ᵐ[ν] g) : f =ᵐ[μ] g :=
h.ae_le h'
/-! ### Quasi measure preserving maps (a.k.a. non-singular maps) -/
/-- A map `f : α → β` is said to be *quasi measure preserving* (a.k.a. non-singular) w.r.t. measures
`μa` and `μb` if it is measurable and `μb s = 0` implies `μa (f ⁻¹' s) = 0`. -/
@[protect_proj]
structure quasi_measure_preserving {m0 : measurable_space α} (f : α → β)
(μa : measure α . volume_tac) (μb : measure β . volume_tac) : Prop :=
(measurable : measurable f)
(absolutely_continuous : map f μa ≪ μb)
namespace quasi_measure_preserving
protected lemma id {m0 : measurable_space α} (μ : measure α) : quasi_measure_preserving id μ μ :=
⟨measurable_id, map_id.absolutely_continuous⟩
variables {μa μa' : measure α} {μb μb' : measure β} {μc : measure γ} {f : α → β}
lemma mono_left (h : quasi_measure_preserving f μa μb)
(ha : μa' ≪ μa) : quasi_measure_preserving f μa' μb :=
⟨h.1, (ha.map f).trans h.2⟩
lemma mono_right (h : quasi_measure_preserving f μa μb)
(ha : μb ≪ μb') : quasi_measure_preserving f μa μb' :=
⟨h.1, h.2.trans ha⟩
@[mono] lemma mono (ha : μa' ≪ μa) (hb : μb ≪ μb') (h : quasi_measure_preserving f μa μb) :
quasi_measure_preserving f μa' μb' :=
(h.mono_left ha).mono_right hb
protected lemma comp {g : β → γ} {f : α → β} (hg : quasi_measure_preserving g μb μc)
(hf : quasi_measure_preserving f μa μb) :
quasi_measure_preserving (g ∘ f) μa μc :=
⟨hg.measurable.comp hf.measurable, by { rw ← map_map hg.1 hf.1, exact (hf.2.map g).trans hg.2 }⟩
protected lemma iterate {f : α → α} (hf : quasi_measure_preserving f μa μa) :
∀ n, quasi_measure_preserving (f^[n]) μa μa
| 0 := quasi_measure_preserving.id μa
| (n + 1) := (iterate n).comp hf
lemma ae_map_le (h : quasi_measure_preserving f μa μb) : (map f μa).ae ≤ μb.ae :=
h.2.ae_le
lemma tendsto_ae (h : quasi_measure_preserving f μa μb) : tendsto f μa.ae μb.ae :=
(tendsto_ae_map h.1).mono_right h.ae_map_le
lemma ae (h : quasi_measure_preserving f μa μb) {p : β → Prop} (hg : ∀ᵐ x ∂μb, p x) :
∀ᵐ x ∂μa, p (f x) :=
h.tendsto_ae hg
lemma ae_eq (h : quasi_measure_preserving f μa μb) {g₁ g₂ : β → δ} (hg : g₁ =ᵐ[μb] g₂) :
g₁ ∘ f =ᵐ[μa] g₂ ∘ f :=
h.ae hg
end quasi_measure_preserving
/-! ### The `cofinite` filter -/
/-- The filter of sets `s` such that `sᶜ` has finite measure. -/
def cofinite {m0 : measurable_space α} (μ : measure α) : filter α :=
{ sets := {s | μ sᶜ < ∞},
univ_sets := by simp,
inter_sets := λ s t hs ht, by { simp only [compl_inter, mem_set_of_eq],
calc μ (sᶜ ∪ tᶜ) ≤ μ sᶜ + μ tᶜ : measure_union_le _ _
... < ∞ : ennreal.add_lt_top.2 ⟨hs, ht⟩ },
sets_of_superset := λ s t hs hst, lt_of_le_of_lt (measure_mono $ compl_subset_compl.2 hst) hs }
lemma mem_cofinite : s ∈ μ.cofinite ↔ μ sᶜ < ∞ := iff.rfl
lemma compl_mem_cofinite : sᶜ ∈ μ.cofinite ↔ μ s < ∞ :=
by rw [mem_cofinite, compl_compl]
lemma eventually_cofinite {p : α → Prop} : (∀ᶠ x in μ.cofinite, p x) ↔ μ {x | ¬p x} < ∞ := iff.rfl
/-! ### Mutually singular measures -/
/-- Two measures `μ`, `ν` are said to be mutually singular if there exists a measurable set `s`
such that `μ s = 0` and `ν sᶜ = 0`. -/
def mutually_singular {m0 : measurable_space α} (μ ν : measure α) : Prop :=
∃ (s : set α), measurable_set s ∧ μ s = 0 ∧ ν sᶜ = 0
localized "infix ` ⊥ₘ `:60 := measure_theory.measure.mutually_singular" in measure_theory
namespace mutually_singular
lemma zero : μ ⊥ₘ 0 :=
⟨∅, measurable_set.empty, measure_empty, rfl⟩
lemma symm (h : ν ⊥ₘ μ) : μ ⊥ₘ ν :=
let ⟨i, hi, his, hit⟩ := h in
⟨iᶜ, measurable_set.compl hi, hit, (compl_compl i).symm ▸ his⟩
lemma add (h₁ : ν₁ ⊥ₘ μ) (h₂ : ν₂ ⊥ₘ μ) : ν₁ + ν₂ ⊥ₘ μ :=
begin
obtain ⟨s, hs, hs0, hs0'⟩ := h₁,
obtain ⟨t, ht, ht0, ht0'⟩ := h₂,
refine ⟨s ∩ t, hs.inter ht, _, _⟩,
{ simp only [pi.add_apply, add_eq_zero_iff, coe_add],
exact ⟨measure_mono_null (inter_subset_left s t) hs0,
measure_mono_null (inter_subset_right s t) ht0⟩ },
{ rw [compl_inter, ← nonpos_iff_eq_zero],
refine le_trans (measure_union_le _ _) _,
rw [hs0', ht0', zero_add],
exact le_refl _ }
end
lemma add_iff : ν₁ + ν₂ ⊥ₘ μ ↔ ν₁ ⊥ₘ μ ∧ ν₂ ⊥ₘ μ :=
begin
split,
{ rintro ⟨u, hmeas, hu₁, hu₂⟩,
rw [measure.add_apply, add_eq_zero_iff] at hu₁,
exact ⟨⟨u, hmeas, hu₁.1, hu₂⟩, u, hmeas, hu₁.2, hu₂⟩ },
{ exact λ ⟨h₁, h₂⟩, h₁.add h₂ }
end
lemma smul (r : ℝ≥0) (h : ν ⊥ₘ μ) : r • ν ⊥ₘ μ :=
let ⟨s, hs, hs0, hs0'⟩ := h in
⟨s, hs, by simp only [coe_nnreal_smul, pi.smul_apply, hs0, smul_zero], hs0'⟩
lemma of_absolutely_continuous (hms : ν₂ ⊥ₘ μ) (hac : ν₁ ≪ ν₂) : ν₁ ⊥ₘ μ :=
let ⟨u, hmeas, hu₁, hu₂⟩ := hms in ⟨u, hmeas, hac hu₁, hu₂⟩
end mutually_singular
end measure
open measure
open_locale measure_theory
@[simp] lemma ae_eq_bot : μ.ae = ⊥ ↔ μ = 0 :=
by rw [← empty_mem_iff_bot, mem_ae_iff, compl_empty, measure_univ_eq_zero]
@[simp] lemma ae_ne_bot : μ.ae.ne_bot ↔ μ ≠ 0 :=
ne_bot_iff.trans (not_congr ae_eq_bot)
@[simp] lemma ae_zero {m0 : measurable_space α} : (0 : measure α).ae = ⊥ := ae_eq_bot.2 rfl
@[mono] lemma ae_mono (h : μ ≤ ν) : μ.ae ≤ ν.ae := h.absolutely_continuous.ae_le
lemma mem_ae_map_iff {f : α → β} (hf : measurable f) {s : set β} (hs : measurable_set s) :
s ∈ (map f μ).ae ↔ (f ⁻¹' s) ∈ μ.ae :=
by simp only [mem_ae_iff, map_apply hf hs.compl, preimage_compl]
lemma mem_ae_of_mem_ae_map {f : α → β} (hf : measurable f) {s : set β} (hs : s ∈ (map f μ).ae) :
f ⁻¹' s ∈ μ.ae :=
begin
apply le_antisymm _ bot_le,
calc μ (f ⁻¹' sᶜ) ≤ (map f μ) sᶜ : le_map_apply hf sᶜ
... = 0 : hs
end
lemma ae_map_iff {f : α → β} (hf : measurable f) {p : β → Prop} (hp : measurable_set {x | p x}) :
(∀ᵐ y ∂ (map f μ), p y) ↔ ∀ᵐ x ∂ μ, p (f x) :=
mem_ae_map_iff hf hp
lemma ae_of_ae_map {f : α → β} (hf : measurable f) {p : β → Prop} (h : ∀ᵐ y ∂ (map f μ), p y) :
∀ᵐ x ∂ μ, p (f x) :=
mem_ae_of_mem_ae_map hf h
lemma ae_map_mem_range {m0 : measurable_space α} (f : α → β) (hf : measurable_set (range f))
(μ : measure α) :
∀ᵐ x ∂(map f μ), x ∈ range f :=
begin
by_cases h : measurable f,
{ change range f ∈ (map f μ).ae,
rw mem_ae_map_iff h hf,
apply eventually_of_forall,
exact mem_range_self },
{ simp [map_of_not_measurable h] }
end
lemma ae_restrict_iff {p : α → Prop} (hp : measurable_set {x | p x}) :
(∀ᵐ x ∂(μ.restrict s), p x) ↔ ∀ᵐ x ∂μ, x ∈ s → p x :=
begin
simp only [ae_iff, ← compl_set_of, restrict_apply hp.compl],
congr' with x, simp [and_comm]
end
lemma ae_imp_of_ae_restrict {s : set α} {p : α → Prop} (h : ∀ᵐ x ∂(μ.restrict s), p x) :
∀ᵐ x ∂μ, x ∈ s → p x :=
begin
simp only [ae_iff] at h ⊢,
simpa [set_of_and, inter_comm] using measure_inter_eq_zero_of_restrict h
end
lemma ae_restrict_iff' {s : set α} {p : α → Prop} (hs : measurable_set s) :
(∀ᵐ x ∂(μ.restrict s), p x) ↔ ∀ᵐ x ∂μ, x ∈ s → p x :=
begin
simp only [ae_iff, ← compl_set_of, restrict_apply_eq_zero' hs],
congr' with x, simp [and_comm]
end
lemma ae_restrict_mem {s : set α} (hs : measurable_set s) :
∀ᵐ x ∂(μ.restrict s), x ∈ s :=
(ae_restrict_iff' hs).2 (filter.eventually_of_forall (λ x, id))
lemma ae_restrict_of_ae {s : set α} {p : α → Prop} (h : ∀ᵐ x ∂μ, p x) :
(∀ᵐ x ∂(μ.restrict s), p x) :=
eventually.filter_mono (ae_mono measure.restrict_le_self) h
lemma ae_restrict_of_ae_restrict_of_subset {s t : set α} {p : α → Prop} (hst : s ⊆ t)
(h : ∀ᵐ x ∂(μ.restrict t), p x) :
(∀ᵐ x ∂(μ.restrict s), p x) :=
h.filter_mono (ae_mono $ measure.restrict_mono hst (le_refl μ))
lemma ae_of_ae_restrict_of_ae_restrict_compl {t : set α} (ht_meas : measurable_set t) {p : α → Prop}
(ht : ∀ᵐ x ∂(μ.restrict t), p x) (htc : ∀ᵐ x ∂(μ.restrict tᶜ), p x) :
∀ᵐ x ∂μ, p x :=
begin
rw ae_restrict_iff' ht_meas at ht,
rw ae_restrict_iff' ht_meas.compl at htc,
refine ht.mp (htc.mono (λ x hx1 hx2, _)),
by_cases hxt : x ∈ t,
{ exact hx2 hxt, },
{ exact hx1 hxt, },
end
lemma mem_map_restrict_ae_iff {β} {s : set α} {t : set β} {f : α → β} (hs : measurable_set s) :
t ∈ filter.map f (μ.restrict s).ae ↔ μ ((f ⁻¹' t)ᶜ ∩ s) = 0 :=
by rw [mem_map, mem_ae_iff, measure.restrict_apply' hs]
lemma ae_smul_measure {p : α → Prop} (h : ∀ᵐ x ∂μ, p x) (c : ℝ≥0∞) : ∀ᵐ x ∂(c • μ), p x :=
ae_iff.2 $ by rw [smul_apply, ae_iff.1 h, mul_zero]
lemma ae_smul_measure_iff {p : α → Prop} {c : ℝ≥0∞} (hc : c ≠ 0) :
(∀ᵐ x ∂(c • μ), p x) ↔ ∀ᵐ x ∂μ, p x :=
by simp [ae_iff, hc]
lemma ae_add_measure_iff {p : α → Prop} {ν} : (∀ᵐ x ∂μ + ν, p x) ↔ (∀ᵐ x ∂μ, p x) ∧ ∀ᵐ x ∂ν, p x :=
add_eq_zero_iff
lemma ae_eq_comp' {ν : measure β} {f : α → β} {g g' : β → δ} (hf : measurable f)
(h : g =ᵐ[ν] g') (h2 : map f μ ≪ ν) : g ∘ f =ᵐ[μ] g' ∘ f :=
(quasi_measure_preserving.mk hf h2).ae_eq h
lemma ae_eq_comp {f : α → β} {g g' : β → δ} (hf : measurable f)
(h : g =ᵐ[measure.map f μ] g') : g ∘ f =ᵐ[μ] g' ∘ f :=
ae_eq_comp' hf h absolutely_continuous.rfl
lemma sub_ae_eq_zero {β} [add_group β] (f g : α → β) : f - g =ᵐ[μ] 0 ↔ f =ᵐ[μ] g :=
begin
refine ⟨λ h, h.mono (λ x hx, _), λ h, h.mono (λ x hx, _)⟩,
{ rwa [pi.sub_apply, pi.zero_apply, sub_eq_zero] at hx, },
{ rwa [pi.sub_apply, pi.zero_apply, sub_eq_zero], },
end
lemma le_ae_restrict : μ.ae ⊓ 𝓟 s ≤ (μ.restrict s).ae :=
λ s hs, eventually_inf_principal.2 (ae_imp_of_ae_restrict hs)
@[simp] lemma ae_restrict_eq (hs : measurable_set s) : (μ.restrict s).ae = μ.ae ⊓ 𝓟 s :=
begin
ext t,
simp only [mem_inf_principal, mem_ae_iff, restrict_apply_eq_zero' hs, compl_set_of,
not_imp, and_comm (_ ∈ s)],
refl
end
@[simp] lemma ae_restrict_eq_bot {s} : (μ.restrict s).ae = ⊥ ↔ μ s = 0 :=
ae_eq_bot.trans restrict_eq_zero
@[simp] lemma ae_restrict_ne_bot {s} : (μ.restrict s).ae.ne_bot ↔ 0 < μ s :=
ne_bot_iff.trans $ (not_congr ae_restrict_eq_bot).trans pos_iff_ne_zero.symm
lemma self_mem_ae_restrict {s} (hs : measurable_set s) : s ∈ (μ.restrict s).ae :=
by simp only [ae_restrict_eq hs, exists_prop, mem_principal, mem_inf_iff];
exact ⟨_, univ_mem, s, subset.rfl, (univ_inter s).symm⟩
/-- A version of the **Borel-Cantelli lemma**: if `pᵢ` is a sequence of predicates such that
`∑ μ {x | pᵢ x}` is finite, then the measure of `x` such that `pᵢ x` holds frequently as `i → ∞` (or
equivalently, `pᵢ x` holds for infinitely many `i`) is equal to zero. -/
lemma measure_set_of_frequently_eq_zero {p : ℕ → α → Prop} (hp : ∑' i, μ {x | p i x} ≠ ∞) :
μ {x | ∃ᶠ n in at_top, p n x} = 0 :=
by simpa only [limsup_eq_infi_supr_of_nat, frequently_at_top, set_of_forall, set_of_exists]
using measure_limsup_eq_zero hp
/-- A version of the **Borel-Cantelli lemma**: if `sᵢ` is a sequence of sets such that
`∑ μ sᵢ` exists, then for almost all `x`, `x` does not belong to almost all `sᵢ`. -/
lemma ae_eventually_not_mem {s : ℕ → set α} (hs : ∑' i, μ (s i) ≠ ∞) :
∀ᵐ x ∂ μ, ∀ᶠ n in at_top, x ∉ s n :=
measure_set_of_frequently_eq_zero hs
section dirac
variable [measurable_space α]
lemma mem_ae_dirac_iff {a : α} (hs : measurable_set s) : s ∈ (dirac a).ae ↔ a ∈ s :=
by by_cases a ∈ s; simp [mem_ae_iff, dirac_apply', hs.compl, indicator_apply, *]
lemma ae_dirac_iff {a : α} {p : α → Prop} (hp : measurable_set {x | p x}) :
(∀ᵐ x ∂(dirac a), p x) ↔ p a :=
mem_ae_dirac_iff hp
@[simp] lemma ae_dirac_eq [measurable_singleton_class α] (a : α) : (dirac a).ae = pure a :=
by { ext s, simp [mem_ae_iff, imp_false] }
lemma ae_eq_dirac' [measurable_singleton_class β] {a : α} {f : α → β} (hf : measurable f) :
f =ᵐ[dirac a] const α (f a) :=
(ae_dirac_iff $ show measurable_set (f ⁻¹' {f a}), from hf $ measurable_set_singleton _).2 rfl
lemma ae_eq_dirac [measurable_singleton_class α] {a : α} (f : α → δ) :
f =ᵐ[dirac a] const α (f a) :=
by simp [filter.eventually_eq]
end dirac
lemma restrict_mono_ae (h : s ≤ᵐ[μ] t) : μ.restrict s ≤ μ.restrict t :=
begin
intros u hu,
simp only [restrict_apply hu],
exact measure_mono_ae (h.mono $ λ x hx, and.imp id hx)
end
lemma restrict_congr_set (H : s =ᵐ[μ] t) : μ.restrict s = μ.restrict t :=
le_antisymm (restrict_mono_ae H.le) (restrict_mono_ae H.symm.le)
section is_finite_measure
include m0
/-- A measure `μ` is called finite if `μ univ < ∞`. -/
class is_finite_measure (μ : measure α) : Prop := (measure_univ_lt_top : μ univ < ∞)
instance restrict.is_finite_measure (μ : measure α) [hs : fact (μ s < ∞)] :
is_finite_measure (μ.restrict s) :=
⟨by simp [hs.elim]⟩
lemma measure_lt_top (μ : measure α) [is_finite_measure μ] (s : set α) : μ s < ∞ :=
(measure_mono (subset_univ s)).trans_lt is_finite_measure.measure_univ_lt_top
lemma measure_ne_top (μ : measure α) [is_finite_measure μ] (s : set α) : μ s ≠ ∞ :=
ne_of_lt (measure_lt_top μ s)
lemma measure_compl_le_add_of_le_add [is_finite_measure μ] (hs : measurable_set s)
(ht : measurable_set t) {ε : ℝ≥0∞} (h : μ s ≤ μ t + ε) :
μ tᶜ ≤ μ sᶜ + ε :=
begin
rw [measure_compl ht (measure_ne_top μ _), measure_compl hs (measure_ne_top μ _),
ennreal.sub_le_iff_le_add],
calc μ univ = μ univ - μ s + μ s :
(ennreal.sub_add_cancel_of_le $ measure_mono s.subset_univ).symm
... ≤ μ univ - μ s + (μ t + ε) : add_le_add_left h _
... = _ : by rw [add_right_comm, add_assoc]
end
lemma measure_compl_le_add_iff [is_finite_measure μ] (hs : measurable_set s)
(ht : measurable_set t) {ε : ℝ≥0∞} :
μ sᶜ ≤ μ tᶜ + ε ↔ μ t ≤ μ s + ε :=
⟨λ h, compl_compl s ▸ compl_compl t ▸ measure_compl_le_add_of_le_add hs.compl ht.compl h,
measure_compl_le_add_of_le_add ht hs⟩
/-- The measure of the whole space with respect to a finite measure, considered as `ℝ≥0`. -/
def measure_univ_nnreal (μ : measure α) : ℝ≥0 := (μ univ).to_nnreal
@[simp] lemma coe_measure_univ_nnreal (μ : measure α) [is_finite_measure μ] :
↑(measure_univ_nnreal μ) = μ univ :=
ennreal.coe_to_nnreal (measure_ne_top μ univ)
instance is_finite_measure_zero : is_finite_measure (0 : measure α) := ⟨by simp⟩
@[priority 100]
instance is_finite_measure_of_is_empty [is_empty α] : is_finite_measure μ :=
by { rw eq_zero_of_is_empty μ, apply_instance }
@[simp] lemma measure_univ_nnreal_zero : measure_univ_nnreal (0 : measure α) = 0 := rfl
omit m0
instance is_finite_measure_add [is_finite_measure μ] [is_finite_measure ν] :
is_finite_measure (μ + ν) :=
{ measure_univ_lt_top :=
begin
rw [measure.coe_add, pi.add_apply, ennreal.add_lt_top],
exact ⟨measure_lt_top _ _, measure_lt_top _ _⟩,
end }
instance is_finite_measure_smul_nnreal [is_finite_measure μ] {r : ℝ≥0} :
is_finite_measure (r • μ) :=
{ measure_univ_lt_top := ennreal.mul_lt_top ennreal.coe_ne_top (measure_ne_top _ _) }
lemma is_finite_measure_of_le (μ : measure α) [is_finite_measure μ] (h : ν ≤ μ) :
is_finite_measure ν :=
{ measure_univ_lt_top := lt_of_le_of_lt (h set.univ measurable_set.univ) (measure_lt_top _ _) }
lemma measure.is_finite_measure_map {m : measurable_space α}
(μ : measure α) [is_finite_measure μ] {f : α → β} (hf : measurable f) :
is_finite_measure (map f μ) :=
⟨by { rw map_apply hf measurable_set.univ, exact measure_lt_top μ _ }⟩
@[simp] lemma measure_univ_nnreal_eq_zero [is_finite_measure μ] :
measure_univ_nnreal μ = 0 ↔ μ = 0 :=
begin
rw [← measure_theory.measure.measure_univ_eq_zero, ← coe_measure_univ_nnreal],
norm_cast
end
lemma measure_univ_nnreal_pos [is_finite_measure μ] (hμ : μ ≠ 0) : 0 < measure_univ_nnreal μ :=
begin
contrapose! hμ,
simpa [measure_univ_nnreal_eq_zero, le_zero_iff] using hμ
end
/-- `le_of_add_le_add_left` is normally applicable to `ordered_cancel_add_comm_monoid`,
but it holds for measures with the additional assumption that μ is finite. -/
lemma measure.le_of_add_le_add_left [is_finite_measure μ] (A2 : μ + ν₁ ≤ μ + ν₂) : ν₁ ≤ ν₂ :=
λ S B1, ennreal.le_of_add_le_add_left (measure_theory.measure_ne_top μ S) (A2 S B1)
lemma summable_measure_to_real [hμ : is_finite_measure μ]
{f : ℕ → set α} (hf₁ : ∀ (i : ℕ), measurable_set (f i)) (hf₂ : pairwise (disjoint on f)) :
summable (λ x, (μ (f x)).to_real) :=
begin
apply ennreal.summable_to_real,
rw ← measure_theory.measure_Union hf₂ hf₁,
exact ne_of_lt (measure_lt_top _ _)
end
end is_finite_measure
section is_probability_measure
include m0
/-- A measure `μ` is called a probability measure if `μ univ = 1`. -/
class is_probability_measure (μ : measure α) : Prop := (measure_univ : μ univ = 1)
export is_probability_measure (measure_univ)
@[priority 100]
instance is_probability_measure.to_is_finite_measure (μ : measure α) [is_probability_measure μ] :
is_finite_measure μ :=
⟨by simp only [measure_univ, ennreal.one_lt_top]⟩
lemma is_probability_measure.ne_zero (μ : measure α) [is_probability_measure μ] : μ ≠ 0 :=
mt measure_univ_eq_zero.2 $ by simp [measure_univ]
omit m0
instance measure.dirac.is_probability_measure [measurable_space α] {x : α} :
is_probability_measure (dirac x) :=
⟨dirac_apply_of_mem $ mem_univ x⟩
lemma prob_add_prob_compl [is_probability_measure μ]
(h : measurable_set s) : μ s + μ sᶜ = 1 :=
(measure_add_measure_compl h).trans measure_univ
lemma prob_le_one [is_probability_measure μ] : μ s ≤ 1 :=
(measure_mono $ set.subset_univ _).trans_eq measure_univ
end is_probability_measure
section no_atoms
/-- Measure `μ` *has no atoms* if the measure of each singleton is zero.
NB: Wikipedia assumes that for any measurable set `s` with positive `μ`-measure,
there exists a measurable `t ⊆ s` such that `0 < μ t < μ s`. While this implies `μ {x} = 0`,
the converse is not true. -/
class has_no_atoms {m0 : measurable_space α} (μ : measure α) : Prop :=
(measure_singleton : ∀ x, μ {x} = 0)
export has_no_atoms (measure_singleton)
attribute [simp] measure_singleton
variables [has_no_atoms μ]
lemma _root_.set.subsingleton.measure_zero {α : Type*} {m : measurable_space α} {s : set α}
(hs : s.subsingleton) (μ : measure α) [has_no_atoms μ] :
μ s = 0 :=
hs.induction_on measure_empty measure_singleton
@[simp] lemma measure.restrict_singleton' {a : α} :
μ.restrict {a} = 0 :=
by simp only [measure_singleton, measure.restrict_eq_zero]
instance (s : set α) : has_no_atoms (μ.restrict s) :=
begin
refine ⟨λ x, _⟩,
obtain ⟨t, hxt, ht1, ht2⟩ := exists_measurable_superset_of_null (measure_singleton x : μ {x} = 0),
apply measure_mono_null hxt,
rw measure.restrict_apply ht1,
apply measure_mono_null (inter_subset_left t s) ht2
end
lemma _root_.set.countable.measure_zero {α : Type*} {m : measurable_space α} {s : set α}
(h : countable s) (μ : measure α) [has_no_atoms μ] :
μ s = 0 :=
begin
rw [← bUnion_of_singleton s, ← nonpos_iff_eq_zero],
refine le_trans (measure_bUnion_le h _) _,
simp
end
lemma _root_.set.finite.measure_zero {α : Type*} {m : measurable_space α} {s : set α}
(h : s.finite) (μ : measure α) [has_no_atoms μ] : μ s = 0 :=
h.countable.measure_zero μ
lemma _root_.finset.measure_zero {α : Type*} {m : measurable_space α}
(s : finset α) (μ : measure α) [has_no_atoms μ] : μ s = 0 :=
s.finite_to_set.measure_zero μ
lemma insert_ae_eq_self (a : α) (s : set α) :
(insert a s : set α) =ᵐ[μ] s :=
union_ae_eq_right.2 $ measure_mono_null (diff_subset _ _) (measure_singleton _)
variables [partial_order α] {a b : α}
lemma Iio_ae_eq_Iic : Iio a =ᵐ[μ] Iic a :=
by simp only [← Iic_diff_right, diff_ae_eq_self,
measure_mono_null (set.inter_subset_right _ _) (measure_singleton a)]
lemma Ioi_ae_eq_Ici : Ioi a =ᵐ[μ] Ici a :=
@Iio_ae_eq_Iic (order_dual α) ‹_› ‹_› _ _ _
lemma Ioo_ae_eq_Ioc : Ioo a b =ᵐ[μ] Ioc a b :=
(ae_eq_refl _).inter Iio_ae_eq_Iic
lemma Ioc_ae_eq_Icc : Ioc a b =ᵐ[μ] Icc a b :=
Ioi_ae_eq_Ici.inter (ae_eq_refl _)
lemma Ioo_ae_eq_Ico : Ioo a b =ᵐ[μ] Ico a b :=
Ioi_ae_eq_Ici.inter (ae_eq_refl _)
lemma Ioo_ae_eq_Icc : Ioo a b =ᵐ[μ] Icc a b :=
Ioi_ae_eq_Ici.inter Iio_ae_eq_Iic
lemma Ico_ae_eq_Icc : Ico a b =ᵐ[μ] Icc a b :=
(ae_eq_refl _).inter Iio_ae_eq_Iic
lemma Ico_ae_eq_Ioc : Ico a b =ᵐ[μ] Ioc a b :=
Ioo_ae_eq_Ico.symm.trans Ioo_ae_eq_Ioc
end no_atoms
lemma ite_ae_eq_of_measure_zero {γ} (f : α → γ) (g : α → γ) (s : set α) (hs_zero : μ s = 0) :
(λ x, ite (x ∈ s) (f x) (g x)) =ᵐ[μ] g :=
begin
have h_ss : sᶜ ⊆ {a : α | ite (a ∈ s) (f a) (g a) = g a},
from λ x hx, by simp [(set.mem_compl_iff _ _).mp hx],
refine measure_mono_null _ hs_zero,
nth_rewrite 0 ←compl_compl s,
rwa set.compl_subset_compl,
end
lemma ite_ae_eq_of_measure_compl_zero {γ} (f : α → γ) (g : α → γ) (s : set α) (hs_zero : μ sᶜ = 0) :
(λ x, ite (x ∈ s) (f x) (g x)) =ᵐ[μ] f :=
by { filter_upwards [hs_zero], intros, split_ifs, refl }
namespace measure
/-- A measure is called finite at filter `f` if it is finite at some set `s ∈ f`.
Equivalently, it is eventually finite at `s` in `f.lift' powerset`. -/
def finite_at_filter {m0 : measurable_space α} (μ : measure α) (f : filter α) : Prop :=
∃ s ∈ f, μ s < ∞
lemma finite_at_filter_of_finite {m0 : measurable_space α} (μ : measure α) [is_finite_measure μ]
(f : filter α) :
μ.finite_at_filter f :=
⟨univ, univ_mem, measure_lt_top μ univ⟩
lemma finite_at_filter.exists_mem_basis {f : filter α} (hμ : finite_at_filter μ f)
{p : ι → Prop} {s : ι → set α} (hf : f.has_basis p s) :
∃ i (hi : p i), μ (s i) < ∞ :=
(hf.exists_iff (λ s t hst ht, (measure_mono hst).trans_lt ht)).1 hμ
lemma finite_at_bot {m0 : measurable_space α} (μ : measure α) : μ.finite_at_filter ⊥ :=
⟨∅, mem_bot, by simp only [measure_empty, with_top.zero_lt_top]⟩
/-- `μ` has finite spanning sets in `C` if there is a countable sequence of sets in `C` that have
finite measures. This structure is a type, which is useful if we want to record extra properties
about the sets, such as that they are monotone.
`sigma_finite` is defined in terms of this: `μ` is σ-finite if there exists a sequence of
finite spanning sets in the collection of all measurable sets. -/
@[protect_proj, nolint has_inhabited_instance]
structure finite_spanning_sets_in {m0 : measurable_space α} (μ : measure α) (C : set (set α)) :=
(set : ℕ → set α)
(set_mem : ∀ i, set i ∈ C)
(finite : ∀ i, μ (set i) < ∞)
(spanning : (⋃ i, set i) = univ)
end measure
open measure
/-- A measure `μ` is called σ-finite if there is a countable collection of sets
`{ A i | i ∈ ℕ }` such that `μ (A i) < ∞` and `⋃ i, A i = s`. -/
class sigma_finite {m0 : measurable_space α} (μ : measure α) : Prop :=
(out' : nonempty (μ.finite_spanning_sets_in univ))
theorem sigma_finite_iff :
sigma_finite μ ↔ nonempty (μ.finite_spanning_sets_in univ) :=
⟨λ h, h.1, λ h, ⟨h⟩⟩
theorem sigma_finite.out (h : sigma_finite μ) :
nonempty (μ.finite_spanning_sets_in univ) := h.1
include m0
/-- If `μ` is σ-finite it has finite spanning sets in the collection of all measurable sets. -/
def measure.to_finite_spanning_sets_in (μ : measure α) [h : sigma_finite μ] :
μ.finite_spanning_sets_in {s | measurable_set s} :=
{ set := λ n, to_measurable μ (h.out.some.set n),
set_mem := λ n, measurable_set_to_measurable _ _,
finite := λ n, by { rw measure_to_measurable, exact h.out.some.finite n },
spanning := eq_univ_of_subset (Union_subset_Union $ λ n, subset_to_measurable _ _)
h.out.some.spanning }
/-- A noncomputable way to get a monotone collection of sets that span `univ` and have finite
measure using `classical.some`. This definition satisfies monotonicity in addition to all other
properties in `sigma_finite`. -/
def spanning_sets (μ : measure α) [sigma_finite μ] (i : ℕ) : set α :=
accumulate μ.to_finite_spanning_sets_in.set i
lemma monotone_spanning_sets (μ : measure α) [sigma_finite μ] :
monotone (spanning_sets μ) :=
monotone_accumulate
lemma measurable_spanning_sets (μ : measure α) [sigma_finite μ] (i : ℕ) :
measurable_set (spanning_sets μ i) :=
measurable_set.Union $ λ j, measurable_set.Union_Prop $
λ hij, μ.to_finite_spanning_sets_in.set_mem j
lemma measure_spanning_sets_lt_top (μ : measure α) [sigma_finite μ] (i : ℕ) :
μ (spanning_sets μ i) < ∞ :=
measure_bUnion_lt_top (finite_le_nat i) $ λ j _, (μ.to_finite_spanning_sets_in.finite j).ne
lemma Union_spanning_sets (μ : measure α) [sigma_finite μ] :
(⋃ i : ℕ, spanning_sets μ i) = univ :=
by simp_rw [spanning_sets, Union_accumulate, μ.to_finite_spanning_sets_in.spanning]
lemma is_countably_spanning_spanning_sets (μ : measure α) [sigma_finite μ] :
is_countably_spanning (range (spanning_sets μ)) :=
⟨spanning_sets μ, mem_range_self, Union_spanning_sets μ⟩
/-- `spanning_sets_index μ x` is the least `n : ℕ` such that `x ∈ spanning_sets μ n`. -/
def spanning_sets_index (μ : measure α) [sigma_finite μ] (x : α) : ℕ :=
nat.find $ Union_eq_univ_iff.1 (Union_spanning_sets μ) x
lemma measurable_spanning_sets_index (μ : measure α) [sigma_finite μ] :
measurable (spanning_sets_index μ) :=
measurable_find _ $ measurable_spanning_sets μ
lemma preimage_spanning_sets_index_singleton (μ : measure α) [sigma_finite μ] (n : ℕ) :
spanning_sets_index μ ⁻¹' {n} = disjointed (spanning_sets μ) n :=
preimage_find_eq_disjointed _ _ _
lemma spanning_sets_index_eq_iff (μ : measure α) [sigma_finite μ] {x : α} {n : ℕ} :
spanning_sets_index μ x = n ↔ x ∈ disjointed (spanning_sets μ) n :=
by convert set.ext_iff.1 (preimage_spanning_sets_index_singleton μ n) x
lemma mem_disjointed_spanning_sets_index (μ : measure α) [sigma_finite μ] (x : α) :
x ∈ disjointed (spanning_sets μ) (spanning_sets_index μ x) :=
(spanning_sets_index_eq_iff μ).1 rfl
lemma mem_spanning_sets_index (μ : measure α) [sigma_finite μ] (x : α) :
x ∈ spanning_sets μ (spanning_sets_index μ x) :=
disjointed_subset _ _ (mem_disjointed_spanning_sets_index μ x)
omit m0
namespace measure
lemma supr_restrict_spanning_sets [sigma_finite μ] (hs : measurable_set s) :
(⨆ i, μ.restrict (spanning_sets μ i) s) = μ s :=
begin
convert (restrict_Union_apply_eq_supr (measurable_spanning_sets μ) _ hs).symm,
{ simp [Union_spanning_sets] },
{ exact directed_of_sup (monotone_spanning_sets μ) }
end
namespace finite_spanning_sets_in
variables {C D : set (set α)}
/-- If `μ` has finite spanning sets in `C` and `C ∩ {s | μ s < ∞} ⊆ D` then `μ` has finite spanning
sets in `D`. -/
protected def mono' (h : μ.finite_spanning_sets_in C) (hC : C ∩ {s | μ s < ∞} ⊆ D) :
μ.finite_spanning_sets_in D :=
⟨h.set, λ i, hC ⟨h.set_mem i, h.finite i⟩, h.finite, h.spanning⟩
/-- If `μ` has finite spanning sets in `C` and `C ⊆ D` then `μ` has finite spanning sets in `D`. -/
protected def mono (h : μ.finite_spanning_sets_in C) (hC : C ⊆ D) : μ.finite_spanning_sets_in D :=
h.mono' (λ s hs, hC hs.1)
/-- If `μ` has finite spanning sets in the collection of measurable sets `C`, then `μ` is σ-finite.
-/
protected lemma sigma_finite (h : μ.finite_spanning_sets_in C) :
sigma_finite μ :=
⟨⟨h.mono $ subset_univ C⟩⟩
/-- An extensionality for measures. It is `ext_of_generate_from_of_Union` formulated in terms of
`finite_spanning_sets_in`. -/
protected lemma ext {ν : measure α} {C : set (set α)} (hA : ‹_› = generate_from C)
(hC : is_pi_system C) (h : μ.finite_spanning_sets_in C) (h_eq : ∀ s ∈ C, μ s = ν s) : μ = ν :=
ext_of_generate_from_of_Union C _ hA hC h.spanning h.set_mem (λ i, (h.finite i).ne) h_eq
protected lemma is_countably_spanning (h : μ.finite_spanning_sets_in C) : is_countably_spanning C :=
⟨h.set, h.set_mem, h.spanning⟩
end finite_spanning_sets_in
lemma sigma_finite_of_countable {S : set (set α)} (hc : countable S)
(hμ : ∀ s ∈ S, μ s < ∞) (hU : ⋃₀ S = univ) :
sigma_finite μ :=
begin
obtain ⟨s, hμ, hs⟩ : ∃ s : ℕ → set α, (∀ n, μ (s n) < ∞) ∧ (⋃ n, s n) = univ,
from (exists_seq_cover_iff_countable ⟨∅, by simp⟩).2 ⟨S, hc, hμ, hU⟩,
exact ⟨⟨⟨λ n, s n, λ n, trivial, hμ, hs⟩⟩⟩,
end
/-- Given measures `μ`, `ν` where `ν ≤ μ`, `finite_spanning_sets_in.of_le` provides the induced
`finite_spanning_set` with respect to `ν` from a `finite_spanning_set` with respect to `μ`. -/
def finite_spanning_sets_in.of_le (h : ν ≤ μ) {C : set (set α)}
(S : μ.finite_spanning_sets_in C) : ν.finite_spanning_sets_in C :=
{ set := S.set,
set_mem := S.set_mem,
finite := λ n, lt_of_le_of_lt (le_iff'.1 h _) (S.finite n),
spanning := S.spanning }
lemma sigma_finite_of_le (μ : measure α) [hs : sigma_finite μ]
(h : ν ≤ μ) : sigma_finite ν :=
⟨hs.out.map $ finite_spanning_sets_in.of_le h⟩
end measure
include m0
/-- Every finite measure is σ-finite. -/
@[priority 100]
instance is_finite_measure.to_sigma_finite (μ : measure α) [is_finite_measure μ] :
sigma_finite μ :=
⟨⟨⟨λ _, univ, λ _, trivial, λ _, measure_lt_top μ _, Union_const _⟩⟩⟩
instance restrict.sigma_finite (μ : measure α) [sigma_finite μ] (s : set α) :
sigma_finite (μ.restrict s) :=
begin
refine ⟨⟨⟨spanning_sets μ, λ _, trivial, λ i, _, Union_spanning_sets μ⟩⟩⟩,
rw [restrict_apply (measurable_spanning_sets μ i)],
exact (measure_mono $ inter_subset_left _ _).trans_lt (measure_spanning_sets_lt_top μ i)
end
instance sum.sigma_finite {ι} [fintype ι] (μ : ι → measure α) [∀ i, sigma_finite (μ i)] :
sigma_finite (sum μ) :=
begin
haveI : encodable ι := fintype.encodable ι,
have : ∀ n, measurable_set (⋂ (i : ι), spanning_sets (μ i) n) :=
λ n, measurable_set.Inter (λ i, measurable_spanning_sets (μ i) n),
refine ⟨⟨⟨λ n, ⋂ i, spanning_sets (μ i) n, λ _, trivial, λ n, _, _⟩⟩⟩,
{ rw [sum_apply _ (this n), tsum_fintype, ennreal.sum_lt_top_iff],
rintro i -,
exact (measure_mono $ Inter_subset _ i).trans_lt (measure_spanning_sets_lt_top (μ i) n) },
{ rw [Union_Inter_of_monotone], simp_rw [Union_spanning_sets, Inter_univ],
exact λ i, monotone_spanning_sets (μ i), }
end
instance add.sigma_finite (μ ν : measure α) [sigma_finite μ] [sigma_finite ν] :
sigma_finite (μ + ν) :=
by { rw [← sum_cond], refine @sum.sigma_finite _ _ _ _ _ (bool.rec _ _); simpa }
lemma sigma_finite.of_map (μ : measure α) {f : α → β} (hf : measurable f)
(h : sigma_finite (map f μ)) :
sigma_finite μ :=
⟨⟨⟨λ n, f ⁻¹' (spanning_sets (map f μ) n),
λ n, trivial,
λ n, by simp only [← map_apply hf, measurable_spanning_sets, measure_spanning_sets_lt_top],
by rw [← preimage_Union, Union_spanning_sets, preimage_univ]⟩⟩⟩
/-- A measure is called locally finite if it is finite in some neighborhood of each point. -/
class is_locally_finite_measure [topological_space α] (μ : measure α) : Prop :=
(finite_at_nhds : ∀ x, μ.finite_at_filter (𝓝 x))
@[priority 100] -- see Note [lower instance priority]
instance is_finite_measure.to_is_locally_finite_measure [topological_space α] (μ : measure α)
[is_finite_measure μ] :
is_locally_finite_measure μ :=
⟨λ x, finite_at_filter_of_finite _ _⟩
lemma measure.finite_at_nhds [topological_space α] (μ : measure α)
[is_locally_finite_measure μ] (x : α) :
μ.finite_at_filter (𝓝 x) :=
is_locally_finite_measure.finite_at_nhds x
lemma measure.smul_finite (μ : measure α) [is_finite_measure μ] {c : ℝ≥0∞} (hc : c ≠ ∞) :
is_finite_measure (c • μ) :=
begin
lift c to ℝ≥0 using hc,
exact measure_theory.is_finite_measure_smul_nnreal,
end
lemma measure.exists_is_open_measure_lt_top [topological_space α] (μ : measure α)
[is_locally_finite_measure μ] (x : α) :
∃ s : set α, x ∈ s ∧ is_open s ∧ μ s < ∞ :=
by simpa only [exists_prop, and.assoc]
using (μ.finite_at_nhds x).exists_mem_basis (nhds_basis_opens x)
omit m0
@[priority 100] -- see Note [lower instance priority]
instance sigma_finite_of_locally_finite [topological_space α]
[topological_space.second_countable_topology α] [is_locally_finite_measure μ] :
sigma_finite μ :=
begin
choose s hsx hsμ using μ.finite_at_nhds,
rcases topological_space.countable_cover_nhds hsx with ⟨t, htc, htU⟩,
refine measure.sigma_finite_of_countable (htc.image s) (ball_image_iff.2 $ λ x hx, hsμ x) _,
rwa sUnion_image
end
/-- If a set has zero measure in a neighborhood of each of its points, then it has zero measure
in a second-countable space. -/
lemma null_of_locally_null [topological_space α] [topological_space.second_countable_topology α]
(s : set α) (hs : ∀ x ∈ s, ∃ u ∈ 𝓝[s] x, μ (s ∩ u) = 0) :
μ s = 0 :=
begin
choose! u hu using hs,
obtain ⟨t, ts, t_count, ht⟩ : ∃ t ⊆ s, t.countable ∧ s ⊆ ⋃ x ∈ t, u x :=
topological_space.countable_cover_nhds_within (λ x hx, (hu x hx).1),
replace ht : s ⊆ ⋃ x ∈ t, s ∩ u x,
by { rw ← inter_bUnion, exact subset_inter (subset.refl _) ht },
apply measure_mono_null ht,
exact (measure_bUnion_null_iff t_count).2 (λ x hx, (hu x (ts hx)).2),
end
/-- If two finite measures give the same mass to the whole space and coincide on a π-system made
of measurable sets, then they coincide on all sets in the σ-algebra generated by the π-system. -/
lemma ext_on_measurable_space_of_generate_finite {α} (m₀ : measurable_space α)
{μ ν : measure α} [is_finite_measure μ]
(C : set (set α)) (hμν : ∀ s ∈ C, μ s = ν s) {m : measurable_space α}
(h : m ≤ m₀) (hA : m = measurable_space.generate_from C) (hC : is_pi_system C)
(h_univ : μ set.univ = ν set.univ) {s : set α} (hs : m.measurable_set' s) :
μ s = ν s :=
begin
haveI : is_finite_measure ν := begin
constructor,
rw ← h_univ,
apply is_finite_measure.measure_univ_lt_top,
end,
refine induction_on_inter hA hC (by simp) hμν _ _ hs,
{ intros t h1t h2t,
have h1t_ : @measurable_set α m₀ t, from h _ h1t,
rw [@measure_compl α m₀ μ t h1t_ (@measure_ne_top α m₀ μ _ t),
@measure_compl α m₀ ν t h1t_ (@measure_ne_top α m₀ ν _ t), h_univ, h2t], },
{ intros f h1f h2f h3f,
have h2f_ : ∀ (i : ℕ), @measurable_set α m₀ (f i), from (λ i, h _ (h2f i)),
have h_Union : @measurable_set α m₀ (⋃ (i : ℕ), f i),from @measurable_set.Union α ℕ m₀ _ f h2f_,
simp [measure_Union, h_Union, h1f, h3f, h2f_], },
end
/-- Two finite measures are equal if they are equal on the π-system generating the σ-algebra
(and `univ`). -/
lemma ext_of_generate_finite (C : set (set α)) (hA : m0 = generate_from C) (hC : is_pi_system C)
[is_finite_measure μ] (hμν : ∀ s ∈ C, μ s = ν s) (h_univ : μ univ = ν univ) :
μ = ν :=
measure.ext (λ s hs, ext_on_measurable_space_of_generate_finite m0 C hμν le_rfl hA hC h_univ hs)
namespace measure
section disjointed
include m0
/-- Given `S : μ.finite_spanning_sets_in {s | measurable_set s}`,
`finite_spanning_sets_in.disjointed` provides a `finite_spanning_sets_in {s | measurable_set s}`
such that its underlying sets are pairwise disjoint. -/
protected def finite_spanning_sets_in.disjointed {μ : measure α}
(S : μ.finite_spanning_sets_in {s | measurable_set s}) :
μ.finite_spanning_sets_in {s | measurable_set s} :=
⟨disjointed S.set, measurable_set.disjointed S.set_mem,
λ n, lt_of_le_of_lt (measure_mono (disjointed_subset S.set n)) (S.finite _),
S.spanning ▸ Union_disjointed⟩
lemma finite_spanning_sets_in.disjointed_set_eq {μ : measure α}
(S : μ.finite_spanning_sets_in {s | measurable_set s}) :
S.disjointed.set = disjointed S.set :=
rfl
lemma exists_eq_disjoint_finite_spanning_sets_in
(μ ν : measure α) [sigma_finite μ] [sigma_finite ν] :
∃ (S : μ.finite_spanning_sets_in {s | measurable_set s})
(T : ν.finite_spanning_sets_in {s | measurable_set s}),
S.set = T.set ∧ pairwise (disjoint on S.set) :=
let S := (μ + ν).to_finite_spanning_sets_in.disjointed in
⟨S.of_le (measure.le_add_right le_rfl), S.of_le (measure.le_add_left le_rfl),
rfl, disjoint_disjointed _⟩
end disjointed
namespace finite_at_filter
variables {f g : filter α}
lemma filter_mono (h : f ≤ g) : μ.finite_at_filter g → μ.finite_at_filter f :=
λ ⟨s, hs, hμ⟩, ⟨s, h hs, hμ⟩
lemma inf_of_left (h : μ.finite_at_filter f) : μ.finite_at_filter (f ⊓ g) :=
h.filter_mono inf_le_left
lemma inf_of_right (h : μ.finite_at_filter g) : μ.finite_at_filter (f ⊓ g) :=
h.filter_mono inf_le_right
@[simp] lemma inf_ae_iff : μ.finite_at_filter (f ⊓ μ.ae) ↔ μ.finite_at_filter f :=
begin
refine ⟨_, λ h, h.filter_mono inf_le_left⟩,
rintros ⟨s, ⟨t, ht, u, hu, rfl⟩, hμ⟩,
suffices : μ t ≤ μ (t ∩ u), from ⟨t, ht, this.trans_lt hμ⟩,
exact measure_mono_ae (mem_of_superset hu (λ x hu ht, ⟨ht, hu⟩))
end
alias inf_ae_iff ↔ measure_theory.measure.finite_at_filter.of_inf_ae _
lemma filter_mono_ae (h : f ⊓ μ.ae ≤ g) (hg : μ.finite_at_filter g) : μ.finite_at_filter f :=
inf_ae_iff.1 (hg.filter_mono h)
protected lemma measure_mono (h : μ ≤ ν) : ν.finite_at_filter f → μ.finite_at_filter f :=
λ ⟨s, hs, hν⟩, ⟨s, hs, (measure.le_iff'.1 h s).trans_lt hν⟩
@[mono] protected lemma mono (hf : f ≤ g) (hμ : μ ≤ ν) :
ν.finite_at_filter g → μ.finite_at_filter f :=
λ h, (h.filter_mono hf).measure_mono hμ
protected lemma eventually (h : μ.finite_at_filter f) : ∀ᶠ s in f.lift' powerset, μ s < ∞ :=
(eventually_lift'_powerset' $ λ s t hst ht, (measure_mono hst).trans_lt ht).2 h
lemma filter_sup : μ.finite_at_filter f → μ.finite_at_filter g → μ.finite_at_filter (f ⊔ g) :=
λ ⟨s, hsf, hsμ⟩ ⟨t, htg, htμ⟩,
⟨s ∪ t, union_mem_sup hsf htg, (measure_union_le s t).trans_lt (ennreal.add_lt_top.2 ⟨hsμ, htμ⟩)⟩
end finite_at_filter
lemma finite_at_nhds_within [topological_space α] {m0 : measurable_space α} (μ : measure α)
[is_locally_finite_measure μ] (x : α) (s : set α) :
μ.finite_at_filter (𝓝[s] x) :=
(finite_at_nhds μ x).inf_of_left
@[simp] lemma finite_at_principal : μ.finite_at_filter (𝓟 s) ↔ μ s < ∞ :=
⟨λ ⟨t, ht, hμ⟩, (measure_mono ht).trans_lt hμ, λ h, ⟨s, mem_principal_self s, h⟩⟩
/-! ### Subtraction of measures -/
/-- The measure `μ - ν` is defined to be the least measure `τ` such that `μ ≤ τ + ν`.
It is the equivalent of `(μ - ν) ⊔ 0` if `μ` and `ν` were signed measures.
Compare with `ennreal.has_sub`.
Specifically, note that if you have `α = {1,2}`, and `μ {1} = 2`, `μ {2} = 0`, and
`ν {2} = 2`, `ν {1} = 0`, then `(μ - ν) {1, 2} = 2`. However, if `μ ≤ ν`, and
`ν univ ≠ ∞`, then `(μ - ν) + ν = μ`. -/
noncomputable instance has_sub {α : Type*} [measurable_space α] : has_sub (measure α) :=
⟨λ μ ν, Inf {τ | μ ≤ τ + ν} ⟩
section measure_sub
lemma sub_def : μ - ν = Inf {d | μ ≤ d + ν} := rfl
lemma sub_eq_zero_of_le (h : μ ≤ ν) : μ - ν = 0 :=
begin
rw [← nonpos_iff_eq_zero', measure.sub_def],
apply @Inf_le (measure α) _ _,
simp [h],
end
/-- This application lemma only works in special circumstances. Given knowledge of
when `μ ≤ ν` and `ν ≤ μ`, a more general application lemma can be written. -/
lemma sub_apply [is_finite_measure ν] (h₁ : measurable_set s) (h₂ : ν ≤ μ) :
(μ - ν) s = μ s - ν s :=
begin
-- We begin by defining `measure_sub`, which will be equal to `(μ - ν)`.
let measure_sub : measure α := @measure_theory.measure.of_measurable α _
(λ (t : set α) (h_t_measurable_set : measurable_set t), (μ t - ν t))
begin
simp
end
begin
intros g h_meas h_disj, simp only, rw ennreal.tsum_sub,
repeat { rw ← measure_theory.measure_Union h_disj h_meas },
exacts [measure_theory.measure_ne_top _ _, λ i, h₂ _ (h_meas _)]
end,
-- Now, we demonstrate `μ - ν = measure_sub`, and apply it.
begin
have h_measure_sub_add : (ν + measure_sub = μ),
{ ext t h_t_measurable_set,
simp only [pi.add_apply, coe_add],
rw [measure_theory.measure.of_measurable_apply _ h_t_measurable_set, add_comm,
ennreal.sub_add_cancel_of_le (h₂ t h_t_measurable_set)] },
have h_measure_sub_eq : (μ - ν) = measure_sub,
{ rw measure_theory.measure.sub_def, apply le_antisymm,
{ apply @Inf_le (measure α) measure.complete_semilattice_Inf,
simp [le_refl, add_comm, h_measure_sub_add] },
apply @le_Inf (measure α) measure.complete_semilattice_Inf,
intros d h_d, rw [← h_measure_sub_add, mem_set_of_eq, add_comm d] at h_d,
apply measure.le_of_add_le_add_left h_d },
rw h_measure_sub_eq,
apply measure.of_measurable_apply _ h₁,
end
end
lemma sub_add_cancel_of_le [is_finite_measure ν] (h₁ : ν ≤ μ) : μ - ν + ν = μ :=
begin
ext s h_s_meas,
rw [add_apply, sub_apply h_s_meas h₁, ennreal.sub_add_cancel_of_le (h₁ s h_s_meas)],
end
lemma sub_le : μ - ν ≤ μ :=
Inf_le (measure.le_add_right (le_refl _))
end measure_sub
lemma restrict_sub_eq_restrict_sub_restrict (h_meas_s : measurable_set s) :
(μ - ν).restrict s = (μ.restrict s) - (ν.restrict s) :=
begin
repeat {rw sub_def},
have h_nonempty : {d | μ ≤ d + ν}.nonempty,
{ apply @set.nonempty_of_mem _ _ μ, rw mem_set_of_eq, intros t h_meas,
exact le_self_add },
rw restrict_Inf_eq_Inf_restrict h_nonempty h_meas_s,
apply le_antisymm,
{ apply @Inf_le_Inf_of_forall_exists_le (measure α) _,
intros ν' h_ν'_in, rw mem_set_of_eq at h_ν'_in, apply exists.intro (ν'.restrict s),
split,
{ rw mem_image, apply exists.intro (ν' + (⊤ : measure_theory.measure α).restrict sᶜ),
rw mem_set_of_eq,
split,
{ rw [add_assoc, add_comm _ ν, ← add_assoc, measure_theory.measure.le_iff],
intros t h_meas_t,
have h_inter_inter_eq_inter : ∀ t' : set α , t ∩ t' ∩ t' = t ∩ t',
{ intro t', rw set.inter_eq_self_of_subset_left, apply set.inter_subset_right t t' },
have h_meas_t_inter_s : measurable_set (t ∩ s) :=
h_meas_t.inter h_meas_s,
repeat {rw measure_eq_inter_diff h_meas_t h_meas_s, rw set.diff_eq},
refine add_le_add _ _,
{ rw add_apply,
apply le_add_right _,
rw add_apply,
rw ← @restrict_eq_self _ _ μ s _ h_meas_t_inter_s (set.inter_subset_right _ _),
rw ← @restrict_eq_self _ _ ν s _ h_meas_t_inter_s (set.inter_subset_right _ _),
apply h_ν'_in _ h_meas_t_inter_s },
cases (@set.eq_empty_or_nonempty _ (t ∩ sᶜ)) with h_inter_empty h_inter_nonempty,
{ simp [h_inter_empty] },
{ rw add_apply,
have h_meas_inter_compl :=
h_meas_t.inter (measurable_set.compl h_meas_s),
rw [restrict_apply h_meas_inter_compl, h_inter_inter_eq_inter sᶜ],
have h_mu_le_add_top : μ ≤ ν' + ν + ⊤,
{ rw add_comm,
have h_le_top : μ ≤ ⊤ := le_top,
apply (λ t₂ h_meas, le_add_right (h_le_top t₂ h_meas)) },
apply h_mu_le_add_top _ h_meas_inter_compl } },
{ ext1 t h_meas_t,
simp [restrict_apply h_meas_t,
restrict_apply (h_meas_t.inter h_meas_s),
set.inter_assoc] } },
{ apply restrict_le_self } },
{ apply @Inf_le_Inf_of_forall_exists_le (measure α) _,
intros s h_s_in, cases h_s_in with t h_t, cases h_t with h_t_in h_t_eq, subst s,
apply exists.intro (t.restrict s), split,
{ rw [set.mem_set_of_eq, ← restrict_add],
apply restrict_mono (set.subset.refl _) h_t_in },
{ apply le_refl _ } },
end
lemma sub_apply_eq_zero_of_restrict_le_restrict
(h_le : μ.restrict s ≤ ν.restrict s) (h_meas_s : measurable_set s) :
(μ - ν) s = 0 :=
begin
rw [← restrict_apply_self _ h_meas_s, restrict_sub_eq_restrict_sub_restrict,
sub_eq_zero_of_le],
repeat {simp [*]},
end
instance is_finite_measure_sub [is_finite_measure μ] : is_finite_measure (μ - ν) :=
{ measure_univ_lt_top := lt_of_le_of_lt
(measure.sub_le set.univ measurable_set.univ) (measure_lt_top _ _) }
end measure
end measure_theory
open measure_theory measure_theory.measure
namespace measurable_equiv
/-! Interactions of measurable equivalences and measures -/
open equiv measure_theory.measure
variables [measurable_space α] [measurable_space β] {μ : measure α} {ν : measure β}
/-- If we map a measure along a measurable equivalence, we can compute the measure on all sets
(not just the measurable ones). -/
protected theorem map_apply (f : α ≃ᵐ β) (s : set β) : map f μ s = μ (f ⁻¹' s) :=
begin
refine le_antisymm _ (le_map_apply f.measurable s),
rw [measure_eq_infi' μ],
refine le_infi _, rintro ⟨t, hst, ht⟩,
rw [subtype.coe_mk],
have : f.symm '' s = f ⁻¹' s := f.symm.to_equiv.image_eq_preimage s,
rw [← this, image_subset_iff] at hst,
convert measure_mono hst,
rw [map_apply, preimage_preimage],
{ refine congr_arg μ (eq.symm _), convert preimage_id, exact funext f.left_inv },
exacts [f.measurable, f.measurable_inv_fun ht]
end
@[simp] lemma map_symm_map (e : α ≃ᵐ β) : map e.symm (map e μ) = μ :=
by simp [map_map e.symm.measurable e.measurable]
@[simp] lemma map_map_symm (e : α ≃ᵐ β) : map e (map e.symm ν) = ν :=
by simp [map_map e.measurable e.symm.measurable]
lemma map_measurable_equiv_injective (e : α ≃ᵐ β) : injective (map e) :=
by { intros μ₁ μ₂ hμ, apply_fun map e.symm at hμ, simpa [map_symm_map e] using hμ }
lemma map_apply_eq_iff_map_symm_apply_eq (e : α ≃ᵐ β) : map e μ = ν ↔ map e.symm ν = μ :=
by rw [← (map_measurable_equiv_injective e).eq_iff, map_map_symm, eq_comm]
lemma restrict_map (e : α ≃ᵐ β) (s : set β) : (map e μ).restrict s = map e (μ.restrict $ e ⁻¹' s) :=
measure.ext $ λ t ht, by simp [e.map_apply, ht, e.measurable ht]
end measurable_equiv
section is_complete
/-- A measure is complete if every null set is also measurable.
A null set is a subset of a measurable set with measure `0`.
Since every measure is defined as a special case of an outer measure, we can more simply state
that a set `s` is null if `μ s = 0`. -/
class measure_theory.measure.is_complete {_ : measurable_space α} (μ : measure α) : Prop :=
(out' : ∀ s, μ s = 0 → measurable_set s)
theorem measure_theory.measure.is_complete_iff {_ : measurable_space α} {μ : measure α} :
μ.is_complete ↔ ∀ s, μ s = 0 → measurable_set s := ⟨λ h, h.1, λ h, ⟨h⟩⟩
theorem measure_theory.measure.is_complete.out {_ : measurable_space α} {μ : measure α}
(h : μ.is_complete) : ∀ s, μ s = 0 → measurable_set s := h.1
variables [measurable_space α] {μ : measure α} {s t z : set α}
/-- A set is null measurable if it is the union of a null set and a measurable set. -/
def null_measurable_set (μ : measure α) (s : set α) : Prop :=
∃ t z, s = t ∪ z ∧ measurable_set t ∧ μ z = 0
theorem null_measurable_set_iff : null_measurable_set μ s ↔
∃ t, t ⊆ s ∧ measurable_set 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 null_measurable_set_measure_eq (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 measurable_set.null_measurable_set (μ : measure α) (hs : measurable_set s) :
null_measurable_set μ s :=
⟨s, ∅, by simp, hs, μ.empty⟩
theorem null_measurable_set_of_complete (μ : measure α) [c : μ.is_complete] :
null_measurable_set μ s ↔ measurable_set s :=
⟨by rintro ⟨t, z, rfl, ht, hz⟩; exact
measurable_set.union ht (c.out _ hz),
λ h, h.null_measurable_set _⟩
theorem null_measurable_set.union_null (hs : null_measurable_set μ s) (hz : μ z = 0) :
null_measurable_set μ (s ∪ z) :=
begin
rcases hs with ⟨t, z', rfl, ht, hz'⟩,
exact ⟨t, z' ∪ z, set.union_assoc _ _ _, ht, nonpos_iff_eq_zero.1
(le_trans (measure_union_le _ _) $ by simp [hz, hz'])⟩
end
theorem null_null_measurable_set (hz : μ z = 0) : null_measurable_set μ z :=
by simpa using (measurable_set.empty.null_measurable_set _).union_null hz
theorem null_measurable_set.Union_nat {s : ℕ → set α} (hs : ∀ i, null_measurable_set μ (s i)) :
null_measurable_set μ (Union s) :=
begin
choose t ht using assume i, null_measurable_set_iff.1 (hs i),
simp [forall_and_distrib] at ht,
rcases ht with ⟨st, ht, hz⟩,
refine null_measurable_set_iff.2
⟨Union t, Union_subset_Union st, measurable_set.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 measurable_set.diff_null (hs : measurable_set s) (hz : μ z = 0) :
null_measurable_set μ (s \ z) :=
begin
rw measure_eq_infi at hz,
choose f hf using show ∀ q : {q : ℚ // q > 0}, ∃ t : set α,
z ⊆ t ∧ measurable_set t ∧ μ t < (real.to_nnreal q.1 : ℝ≥0∞),
{ rintro ⟨ε, ε0⟩,
have : 0 < (real.to_nnreal ε : ℝ≥0∞), { simpa using ε0 },
rw ← hz at this, simpa [infi_lt_iff] },
refine null_measurable_set_iff.2 ⟨s \ Inter f,
diff_subset_diff_right (subset_Inter (λ i, (hf i).1)),
hs.diff (measurable_set.Inter (λ i, (hf i).2.1)),
measure_mono_null _ (nonpos_iff_eq_zero.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 null_measurable_set.diff_null (hs : null_measurable_set μ s) (hz : μ z = 0) :
null_measurable_set μ (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 null_measurable_set.compl (hs : null_measurable_set μ s) : null_measurable_set μ sᶜ :=
begin
rcases hs with ⟨t, z, rfl, ht, hz⟩,
rw compl_union,
exact ht.compl.diff_null hz
end
theorem null_measurable_set_iff_ae {s : set α} :
null_measurable_set μ s ↔ ∃ t, measurable_set t ∧ s =ᵐ[μ] t :=
begin
simp only [ae_eq_set],
split,
{ assume h,
rcases null_measurable_set_iff.1 h with ⟨t, ts, tmeas, ht⟩,
refine ⟨t, tmeas, ht, _⟩,
rw [diff_eq_empty.2 ts, measure_empty] },
{ rintros ⟨t, tmeas, h₁, h₂⟩,
have : null_measurable_set μ (t ∪ (s \ t)) :=
null_measurable_set.union_null (tmeas.null_measurable_set _) h₁,
have A : null_measurable_set μ ((t ∪ (s \ t)) \ (t \ s)) :=
null_measurable_set.diff_null this h₂,
have : (t ∪ (s \ t)) \ (t \ s) = s,
{ apply subset.antisymm,
{ assume x hx,
simp only [mem_union_eq, not_and, mem_diff, not_not_mem] at hx,
cases hx.1, { exact hx.2 h }, { exact h.1 } },
{ assume x hx,
simp [hx, classical.em (x ∈ t)] } },
rwa this at A }
end
theorem null_measurable_set_iff_sandwich {s : set α} :
null_measurable_set μ s ↔
∃ (t u : set α), measurable_set t ∧ measurable_set u ∧ t ⊆ s ∧ s ⊆ u ∧ μ (u \ t) = 0 :=
begin
split,
{ assume h,
rcases null_measurable_set_iff.1 h with ⟨t, ts, tmeas, ht⟩,
rcases null_measurable_set_iff.1 h.compl with ⟨u', u's, u'meas, hu'⟩,
have A : s ⊆ u'ᶜ := subset_compl_comm.mp u's,
refine ⟨t, u'ᶜ, tmeas, u'meas.compl, ts, A, _⟩,
have : sᶜ \ u' = u'ᶜ \ s, by simp [compl_eq_univ_diff, diff_diff, union_comm],
rw this at hu',
apply le_antisymm _ bot_le,
calc μ (u'ᶜ \ t) ≤ μ ((u'ᶜ \ s) ∪ (s \ t)) :
begin
apply measure_mono,
assume x hx,
simp at hx,
simp [hx, or_comm, classical.em],
end
... ≤ μ (u'ᶜ \ s) + μ (s \ t) : measure_union_le _ _
... = 0 : by rw [ht, hu', zero_add] },
{ rintros ⟨t, u, tmeas, umeas, ts, su, hμ⟩,
refine null_measurable_set_iff.2 ⟨t, ts, tmeas, _⟩,
apply le_antisymm _ bot_le,
calc μ (s \ t) ≤ μ (u \ t) : measure_mono (diff_subset_diff_left su)
... = 0 : hμ }
end
lemma restrict_apply_of_null_measurable_set {s t : set α}
(ht : null_measurable_set (μ.restrict s) t) : μ.restrict s t = μ (t ∩ s) :=
begin
rcases null_measurable_set_iff_sandwich.1 ht with ⟨u, v, umeas, vmeas, ut, tv, huv⟩,
apply le_antisymm _ (le_restrict_apply _ _),
calc μ.restrict s t ≤ μ.restrict s v : measure_mono tv
... = μ (v ∩ s) : restrict_apply vmeas
... ≤ μ ((u ∩ s) ∪ ((v \ u) ∩ s)) : measure_mono $
by { assume x hx, simp at hx, simp [hx, classical.em] }
... ≤ μ (u ∩ s) + μ ((v \ u) ∩ s) : measure_union_le _ _
... = μ (u ∩ s) + μ.restrict s (v \ u) : by rw measure.restrict_apply (vmeas.diff umeas)
... = μ (u ∩ s) : by rw [huv, add_zero]
... ≤ μ (t ∩ s) : measure_mono $ inter_subset_inter_left s ut
end
/-- The measurable space of all null measurable sets. -/
def null_measurable (μ : measure α) : measurable_space α :=
{ measurable_set' := null_measurable_set μ,
measurable_set_empty := measurable_set.empty.null_measurable_set _,
measurable_set_compl := λ s hs, hs.compl,
measurable_set_Union := λ f, null_measurable_set.Union_nat }
/-- Given a measure we can complete it to a (complete) measure on all null measurable sets. -/
def completion (μ : 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, null_measurable_set_iff.1 (hs i),
simp [forall_and_distrib] at ht, rcases ht with ⟨st, ht, hz⟩,
rw null_measurable_set_measure_eq (Union_subset_Union st),
{ rw measure_Union _ ht,
{ congr, funext i,
exact (null_measurable_set_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.le_trim _),
rw outer_measure.trim_eq_infi,
dsimp,
clear _inst,
resetI,
rw measure_eq_infi s,
exact infi_le_infi (λ t, infi_le_infi $ λ st,
infi_le_infi2 $ λ ht, ⟨ht.null_measurable_set _, le_refl _⟩)
end }
instance completion.is_complete (μ : measure α) : (completion μ).is_complete :=
⟨λ z hz, null_null_measurable_set hz⟩
lemma measurable.ae_eq {α β} [measurable_space α] [measurable_space β] {μ : measure α}
[hμ : μ.is_complete] {f g : α → β} (hf : measurable f) (hfg : f =ᵐ[μ] g) :
measurable g :=
begin
intros s hs,
let t := {x | f x = g x},
have ht_compl : μ tᶜ = 0, by rwa [filter.eventually_eq, ae_iff] at hfg,
rw (set.inter_union_compl (g ⁻¹' s) t).symm,
refine measurable_set.union _ _,
{ have h_g_to_f : (g ⁻¹' s) ∩ t = (f ⁻¹' s) ∩ t,
{ ext,
simp only [set.mem_inter_iff, set.mem_preimage, and.congr_left_iff, set.mem_set_of_eq],
exact λ hx, by rw hx, },
rw h_g_to_f,
exact measurable_set.inter (hf hs) (measurable_set.compl_iff.mp (hμ.out tᶜ ht_compl)), },
{ exact hμ.out (g ⁻¹' s ∩ tᶜ) (measure_mono_null (set.inter_subset_right _ _) ht_compl), },
end
end is_complete
namespace measure_theory
lemma outer_measure.to_measure_zero [measurable_space α] : (0 : outer_measure α).to_measure
((le_top).trans outer_measure.zero_caratheodory.symm.le) = 0 :=
by rw [← measure.measure_univ_eq_zero, to_measure_apply _ _ measurable_set.univ,
outer_measure.coe_zero, pi.zero_apply]
section trim
/-- Restriction of a measure to a sub-sigma algebra.
It is common to see a measure `μ` on a measurable space structure `m0` as being also a measure on
any `m ≤ m0`. Since measures in mathlib have to be trimmed to the measurable space, `μ` itself
cannot be a measure on `m`, hence the definition of `μ.trim hm`.
This notion is related to `outer_measure.trim`, see the lemma
`to_outer_measure_trim_eq_trim_to_outer_measure`. -/
def measure.trim {m m0 : measurable_space α} (μ : @measure α m0) (hm : m ≤ m0) : @measure α m :=
@outer_measure.to_measure α m μ.to_outer_measure (hm.trans (le_to_outer_measure_caratheodory μ))
@[simp] lemma trim_eq_self [measurable_space α] {μ : measure α} : μ.trim le_rfl = μ :=
by simp [measure.trim]
variables {m m0 : measurable_space α} {μ : measure α} {s : set α}
lemma to_outer_measure_trim_eq_trim_to_outer_measure (μ : measure α) (hm : m ≤ m0) :
@measure.to_outer_measure _ m (μ.trim hm) = @outer_measure.trim _ m μ.to_outer_measure :=
by rw [measure.trim, to_measure_to_outer_measure]
@[simp] lemma zero_trim (hm : m ≤ m0) : (0 : measure α).trim hm = (0 : @measure α m) :=
by simp [measure.trim, outer_measure.to_measure_zero]
lemma trim_measurable_set_eq (hm : m ≤ m0) (hs : @measurable_set α m s) : μ.trim hm s = μ s :=
by simp [measure.trim, hs]
lemma le_trim (hm : m ≤ m0) : μ s ≤ μ.trim hm s :=
by { simp_rw [measure.trim], exact (@le_to_measure_apply _ m _ _ _), }
lemma measure_eq_zero_of_trim_eq_zero (hm : m ≤ m0) (h : μ.trim hm s = 0) : μ s = 0 :=
le_antisymm ((le_trim hm).trans (le_of_eq h)) (zero_le _)
lemma measure_trim_to_measurable_eq_zero {hm : m ≤ m0} (hs : μ.trim hm s = 0) :
μ (@to_measurable α m (μ.trim hm) s) = 0 :=
measure_eq_zero_of_trim_eq_zero hm (by rwa measure_to_measurable)
lemma ae_eq_of_ae_eq_trim {E} {hm : m ≤ m0} {f₁ f₂ : α → E}
(h12 : f₁ =ᶠ[@measure.ae α m (μ.trim hm)] f₂) :
f₁ =ᵐ[μ] f₂ :=
measure_eq_zero_of_trim_eq_zero hm h12
lemma restrict_trim (hm : m ≤ m0) (μ : measure α) (hs : @measurable_set α m s) :
@measure.restrict α m (μ.trim hm) s = (μ.restrict s).trim hm :=
begin
ext1 t ht,
rw [@measure.restrict_apply α m _ _ _ ht, trim_measurable_set_eq hm ht,
measure.restrict_apply (hm t ht),
trim_measurable_set_eq hm (@measurable_set.inter α m t s ht hs)],
end
instance is_finite_measure_trim (hm : m ≤ m0) [is_finite_measure μ] :
is_finite_measure (μ.trim hm) :=
{ measure_univ_lt_top :=
by { rw trim_measurable_set_eq hm (@measurable_set.univ _ m), exact measure_lt_top _ _, } }
end trim
end measure_theory
open_locale measure_theory
/-!
# Almost everywhere measurable functions
A function is almost everywhere measurable if it coincides almost everywhere with a measurable
function. This property, called `ae_measurable f μ`, is defined in the file `measure_space_def`.
We discuss several of its properties that are analogous to properties of measurable functions.
-/
section
open measure_theory
variables [measurable_space α] [measurable_space β]
{f g : α → β} {μ ν : measure α}
@[nontriviality, measurability]
lemma subsingleton.ae_measurable [subsingleton α] : ae_measurable f μ :=
subsingleton.measurable.ae_measurable
@[simp, measurability] lemma ae_measurable_zero_measure : ae_measurable f (0 : measure α) :=
begin
nontriviality α, inhabit α,
exact ⟨λ x, f (default α), measurable_const, rfl⟩
end
lemma ae_measurable_iff_measurable [μ.is_complete] :
ae_measurable f μ ↔ measurable f :=
begin
split; intro h,
{ rcases h with ⟨g, hg_meas, hfg⟩,
exact hg_meas.ae_eq hfg.symm, },
{ exact h.ae_measurable, },
end
namespace ae_measurable
lemma mono_measure (h : ae_measurable f μ) (h' : ν ≤ μ) : ae_measurable f ν :=
⟨h.mk f, h.measurable_mk, eventually.filter_mono (ae_mono h') h.ae_eq_mk⟩
lemma mono_set {s t} (h : s ⊆ t) (ht : ae_measurable f (μ.restrict t)) :
ae_measurable f (μ.restrict s) :=
ht.mono_measure (restrict_mono h le_rfl)
protected lemma mono' (h : ae_measurable f μ) (h' : ν ≪ μ) : ae_measurable f ν :=
⟨h.mk f, h.measurable_mk, h' h.ae_eq_mk⟩
lemma ae_mem_imp_eq_mk {s} (h : ae_measurable f (μ.restrict s)) :
∀ᵐ x ∂μ, x ∈ s → f x = h.mk f x :=
ae_imp_of_ae_restrict h.ae_eq_mk
lemma ae_inf_principal_eq_mk {s} (h : ae_measurable f (μ.restrict s)) :
f =ᶠ[μ.ae ⊓ 𝓟 s] h.mk f :=
le_ae_restrict h.ae_eq_mk
@[measurability]
lemma add_measure {f : α → β} (hμ : ae_measurable f μ) (hν : ae_measurable f ν) :
ae_measurable f (μ + ν) :=
begin
let s := {x | f x ≠ hμ.mk f x},
have : μ s = 0 := hμ.ae_eq_mk,
obtain ⟨t, st, t_meas, μt⟩ : ∃ t, s ⊆ t ∧ measurable_set t ∧ μ t = 0 :=
exists_measurable_superset_of_null this,
let g : α → β := t.piecewise (hν.mk f) (hμ.mk f),
refine ⟨g, measurable.piecewise t_meas hν.measurable_mk hμ.measurable_mk, _⟩,
change μ {x | f x ≠ g x} + ν {x | f x ≠ g x} = 0,
suffices : μ {x | f x ≠ g x} = 0 ∧ ν {x | f x ≠ g x} = 0, by simp [this.1, this.2],
have ht : {x | f x ≠ g x} ⊆ t,
{ assume x hx,
by_contra h,
simp only [g, h, mem_set_of_eq, ne.def, not_false_iff, piecewise_eq_of_not_mem] at hx,
exact h (st hx) },
split,
{ have : μ {x | f x ≠ g x} ≤ μ t := measure_mono ht,
rw μt at this,
exact le_antisymm this bot_le },
{ have : {x | f x ≠ g x} ⊆ {x | f x ≠ hν.mk f x},
{ assume x hx,
simpa [ht hx, g] using hx },
apply le_antisymm _ bot_le,
calc ν {x | f x ≠ g x} ≤ ν {x | f x ≠ hν.mk f x} : measure_mono this
... = 0 : hν.ae_eq_mk }
end
@[measurability]
lemma smul_measure (h : ae_measurable f μ) (c : ℝ≥0∞) :
ae_measurable f (c • μ) :=
⟨h.mk f, h.measurable_mk, ae_smul_measure h.ae_eq_mk c⟩
lemma comp_measurable [measurable_space δ] {f : α → δ} {g : δ → β}
(hg : ae_measurable g (map f μ)) (hf : measurable f) : ae_measurable (g ∘ f) μ :=
⟨hg.mk g ∘ f, hg.measurable_mk.comp hf, ae_eq_comp hf hg.ae_eq_mk⟩
lemma comp_measurable' {δ} [measurable_space δ] {ν : measure δ} {f : α → δ} {g : δ → β}
(hg : ae_measurable g ν) (hf : measurable f) (h : map f μ ≪ ν) : ae_measurable (g ∘ f) μ :=
(hg.mono' h).comp_measurable hf
@[measurability]
lemma prod_mk {γ : Type*} [measurable_space γ] {f : α → β} {g : α → γ}
(hf : ae_measurable f μ) (hg : ae_measurable g μ) : ae_measurable (λ x, (f x, g x)) μ :=
⟨λ a, (hf.mk f a, hg.mk g a), hf.measurable_mk.prod_mk hg.measurable_mk,
eventually_eq.prod_mk hf.ae_eq_mk hg.ae_eq_mk⟩
protected lemma null_measurable_set (h : ae_measurable f μ) {s : set β} (hs : measurable_set s) :
null_measurable_set μ (f ⁻¹' s) :=
begin
apply null_measurable_set_iff_ae.2,
refine ⟨(h.mk f) ⁻¹' s, h.measurable_mk hs, _⟩,
filter_upwards [h.ae_eq_mk],
assume x hx,
change (f x ∈ s) = ((h.mk f) x ∈ s),
rwa hx
end
end ae_measurable
@[simp] lemma ae_measurable_add_measure_iff :
ae_measurable f (μ + ν) ↔ ae_measurable f μ ∧ ae_measurable f ν :=
⟨λ h, ⟨h.mono_measure (measure.le_add_right (le_refl _)),
h.mono_measure (measure.le_add_left (le_refl _))⟩,
λ h, h.1.add_measure h.2⟩
@[simp, to_additive] lemma ae_measurable_one [has_one β] : ae_measurable (λ a : α, (1 : β)) μ :=
measurable_one.ae_measurable
@[simp] lemma ae_measurable_smul_measure_iff {c : ℝ≥0∞} (hc : c ≠ 0) :
ae_measurable f (c • μ) ↔ ae_measurable f μ :=
⟨λ h, ⟨h.mk f, h.measurable_mk, (ae_smul_measure_iff hc).1 h.ae_eq_mk⟩,
λ h, ⟨h.mk f, h.measurable_mk, (ae_smul_measure_iff hc).2 h.ae_eq_mk⟩⟩
lemma ae_measurable_of_ae_measurable_trim {α} {m m0 : measurable_space α}
{μ : measure α} (hm : m ≤ m0) {f : α → β} (hf : ae_measurable f (μ.trim hm)) :
ae_measurable f μ :=
⟨hf.mk f, measurable.mono hf.measurable_mk hm le_rfl, ae_eq_of_ae_eq_trim hf.ae_eq_mk⟩
lemma ae_measurable_restrict_of_measurable_subtype {s : set α}
(hs : measurable_set s) (hf : measurable (λ x : s, f x)) : ae_measurable f (μ.restrict s) :=
begin
casesI is_empty_or_nonempty β,
{ exact (measurable_of_empty_codomain f).ae_measurable },
refine ⟨s.piecewise f (λ x, classical.choice h), _, (ae_restrict_iff' hs).mpr $ ae_of_all _
(λ x hx, (piecewise_eq_of_mem s _ _ hx).symm)⟩,
intros t ht,
rw piecewise_preimage,
refine measurable_set.union _ ((measurable_const ht).diff hs),
rw [← subtype.image_preimage_coe, ← preimage_comp],
exact hs.subtype_image (hf ht)
end
lemma ae_measurable_map_equiv_iff [measurable_space γ] (e : α ≃ᵐ β) {f : β → γ} :
ae_measurable f (map e μ) ↔ ae_measurable (f ∘ e) μ :=
begin
refine ⟨λ h, h.comp_measurable e.measurable, λ h, _⟩,
rw [← (e.map_symm_map : _ = μ)] at h,
convert h.comp_measurable e.symm.measurable,
simp [(∘)]
end
end
namespace is_compact
variables [topological_space α] [measurable_space α] {μ : measure α} {s : set α}
/-- If `s` is a compact set and `μ` is finite at `𝓝 x` for every `x ∈ s`, then `s` admits an open
superset of finite measure. -/
lemma exists_open_superset_measure_lt_top' (h : is_compact s)
(hμ : ∀ x ∈ s, μ.finite_at_filter (𝓝 x)) :
∃ U ⊇ s, is_open U ∧ μ U < ∞ :=
begin
refine is_compact.induction_on h _ _ _ _,
{ use ∅, simp [superset] },
{ rintro s t hst ⟨U, htU, hUo, hU⟩, exact ⟨U, hst.trans htU, hUo, hU⟩ },
{ rintro s t ⟨U, hsU, hUo, hU⟩ ⟨V, htV, hVo, hV⟩,
refine ⟨U ∪ V, union_subset_union hsU htV, hUo.union hVo,
(measure_union_le _ _).trans_lt $ ennreal.add_lt_top.2 ⟨hU, hV⟩⟩ },
{ intros x hx,
rcases (hμ x hx).exists_mem_basis (nhds_basis_opens _) with ⟨U, ⟨hx, hUo⟩, hU⟩,
exact ⟨U, nhds_within_le_nhds (hUo.mem_nhds hx), U, subset.rfl, hUo, hU⟩ }
end
/-- If `s` is a compact set and `μ` is a locally finite measure, then `s` admits an open superset of
finite measure. -/
lemma exists_open_superset_measure_lt_top (h : is_compact s)
(μ : measure α) [is_locally_finite_measure μ] :
∃ U ⊇ s, is_open U ∧ μ U < ∞ :=
h.exists_open_superset_measure_lt_top' $ λ x hx, μ.finite_at_nhds x
lemma measure_lt_top_of_nhds_within (h : is_compact s) (hμ : ∀ x ∈ s, μ.finite_at_filter (𝓝[s] x)) :
μ s < ∞ :=
is_compact.induction_on h (by simp) (λ s t hst ht, (measure_mono hst).trans_lt ht)
(λ s t hs ht, (measure_union_le s t).trans_lt (ennreal.add_lt_top.2 ⟨hs, ht⟩)) hμ
lemma measure_lt_top (h : is_compact s) {μ : measure α} [is_locally_finite_measure μ] :
μ s < ∞ :=
h.measure_lt_top_of_nhds_within $ λ x hx, μ.finite_at_nhds_within _ _
lemma measure_zero_of_nhds_within (hs : is_compact s) :
(∀ a ∈ s, ∃ t ∈ 𝓝[s] a, μ t = 0) → μ s = 0 :=
by simpa only [← compl_mem_ae_iff] using hs.compl_mem_sets_of_nhds_within
end is_compact
/-- Compact covering of a `σ`-compact topological space as
`measure_theory.measure.finite_spanning_sets_in`. -/
def measure_theory.measure.finite_spanning_sets_in_compact [topological_space α]
[sigma_compact_space α] {m : measurable_space α} (μ : measure α) [is_locally_finite_measure μ] :
μ.finite_spanning_sets_in {K | is_compact K} :=
{ set := compact_covering α,
set_mem := is_compact_compact_covering α,
finite := λ n, (is_compact_compact_covering α n).measure_lt_top,
spanning := Union_compact_covering α }
/-- A locally finite measure on a `σ`-compact topological space admits a finite spanning sequence
of open sets. -/
def measure_theory.measure.finite_spanning_sets_in_open [topological_space α]
[sigma_compact_space α] {m : measurable_space α} (μ : measure α) [is_locally_finite_measure μ] :
μ.finite_spanning_sets_in {K | is_open K} :=
{ set := λ n, ((is_compact_compact_covering α n).exists_open_superset_measure_lt_top μ).some,
set_mem := λ n,
((is_compact_compact_covering α n).exists_open_superset_measure_lt_top μ).some_spec.snd.1,
finite := λ n,
((is_compact_compact_covering α n).exists_open_superset_measure_lt_top μ).some_spec.snd.2,
spanning := eq_univ_of_subset (Union_subset_Union $ λ n,
((is_compact_compact_covering α n).exists_open_superset_measure_lt_top μ).some_spec.fst)
(Union_compact_covering α) }
section measure_Ixx
variables [conditionally_complete_linear_order α] [topological_space α] [order_topology α]
{m : measurable_space α} {μ : measure α} [is_locally_finite_measure μ] {a b : α}
lemma measure_Icc_lt_top : μ (Icc a b) < ∞ := is_compact_Icc.measure_lt_top
lemma measure_Ico_lt_top : μ (Ico a b) < ∞ :=
(measure_mono Ico_subset_Icc_self).trans_lt measure_Icc_lt_top
lemma measure_Ioc_lt_top : μ (Ioc a b) < ∞ :=
(measure_mono Ioc_subset_Icc_self).trans_lt measure_Icc_lt_top
lemma measure_Ioo_lt_top : μ (Ioo a b) < ∞ :=
(measure_mono Ioo_subset_Icc_self).trans_lt measure_Icc_lt_top
end measure_Ixx
lemma metric.bounded.measure_lt_top [metric_space α] [proper_space α]
[measurable_space α] {μ : measure α} [is_locally_finite_measure μ] {s : set α}
(hs : metric.bounded s) :
μ s < ∞ :=
(measure_mono subset_closure).trans_lt (metric.compact_iff_closed_bounded.2
⟨is_closed_closure, metric.bounded_closure_of_bounded hs⟩).measure_lt_top
section piecewise
variables [measurable_space α] {μ : measure α} {s t : set α} {f g : α → β}
lemma piecewise_ae_eq_restrict (hs : measurable_set s) : piecewise s f g =ᵐ[μ.restrict s] f :=
begin
rw [ae_restrict_eq hs],
exact (piecewise_eq_on s f g).eventually_eq.filter_mono inf_le_right
end
lemma piecewise_ae_eq_restrict_compl (hs : measurable_set s) :
piecewise s f g =ᵐ[μ.restrict sᶜ] g :=
begin
rw [ae_restrict_eq hs.compl],
exact (piecewise_eq_on_compl s f g).eventually_eq.filter_mono inf_le_right
end
lemma piecewise_ae_eq_of_ae_eq_set (hst : s =ᵐ[μ] t) : s.piecewise f g =ᵐ[μ] t.piecewise f g :=
begin
filter_upwards [hst],
intros x hx,
replace hx : x ∈ s ↔ x ∈ t := iff_of_eq hx,
by_cases h : x ∈ s; have h' := h; rw hx at h'; simp [h, h']
end
end piecewise
section indicator_function
variables [measurable_space α] {μ : measure α} {s t : set α} {f : α → β}
lemma mem_map_indicator_ae_iff_mem_map_restrict_ae_of_zero_mem [has_zero β] {t : set β}
(ht : (0 : β) ∈ t) (hs : measurable_set s) :
t ∈ filter.map (s.indicator f) μ.ae ↔ t ∈ filter.map f (μ.restrict s).ae :=
begin
simp_rw [mem_map, mem_ae_iff],
rw [measure.restrict_apply' hs, set.indicator_preimage, set.ite],
simp_rw [set.compl_union, set.compl_inter],
change μ (((f ⁻¹' t)ᶜ ∪ sᶜ) ∩ ((λ x, (0 : β)) ⁻¹' t \ s)ᶜ) = 0 ↔ μ ((f ⁻¹' t)ᶜ ∩ s) = 0,
simp only [ht, ← set.compl_eq_univ_diff, compl_compl, set.compl_union, if_true,
set.preimage_const],
simp_rw [set.union_inter_distrib_right, set.compl_inter_self s, set.union_empty],
end
lemma mem_map_indicator_ae_iff_of_zero_nmem [has_zero β] {t : set β} (ht : (0 : β) ∉ t) :
t ∈ filter.map (s.indicator f) μ.ae ↔ μ ((f ⁻¹' t)ᶜ ∪ sᶜ) = 0 :=
begin
rw [mem_map, mem_ae_iff, set.indicator_preimage, set.ite, set.compl_union, set.compl_inter],
change μ (((f ⁻¹' t)ᶜ ∪ sᶜ) ∩ ((λ x, (0 : β)) ⁻¹' t \ s)ᶜ) = 0 ↔ μ ((f ⁻¹' t)ᶜ ∪ sᶜ) = 0,
simp only [ht, if_false, set.compl_empty, set.empty_diff, set.inter_univ, set.preimage_const],
end
lemma map_restrict_ae_le_map_indicator_ae [has_zero β] (hs : measurable_set s) :
filter.map f (μ.restrict s).ae ≤ filter.map (s.indicator f) μ.ae :=
begin
intro t,
by_cases ht : (0 : β) ∈ t,
{ rw mem_map_indicator_ae_iff_mem_map_restrict_ae_of_zero_mem ht hs, exact id, },
rw [mem_map_indicator_ae_iff_of_zero_nmem ht, mem_map_restrict_ae_iff hs],
exact λ h, measure_mono_null ((set.inter_subset_left _ _).trans (set.subset_union_left _ _)) h,
end
lemma ae_measurable.restrict [measurable_space β] (hfm : ae_measurable f μ) {s} :
ae_measurable f (μ.restrict s) :=
⟨ae_measurable.mk f hfm, hfm.measurable_mk, ae_restrict_of_ae hfm.ae_eq_mk⟩
variables [has_zero β]
lemma indicator_ae_eq_restrict (hs : measurable_set s) : indicator s f =ᵐ[μ.restrict s] f :=
piecewise_ae_eq_restrict hs
lemma indicator_ae_eq_restrict_compl (hs : measurable_set s) : indicator s f =ᵐ[μ.restrict sᶜ] 0 :=
piecewise_ae_eq_restrict_compl hs
lemma indicator_ae_eq_of_ae_eq_set (hst : s =ᵐ[μ] t) : s.indicator f =ᵐ[μ] t.indicator f :=
piecewise_ae_eq_of_ae_eq_set hst
variables [measurable_space β]
lemma ae_measurable_indicator_iff {s} (hs : measurable_set s) :
ae_measurable (indicator s f) μ ↔ ae_measurable f (μ.restrict s) :=
begin
split,
{ assume h,
exact (h.mono_measure measure.restrict_le_self).congr (indicator_ae_eq_restrict hs) },
{ assume h,
refine ⟨indicator s (h.mk f), h.measurable_mk.indicator hs, _⟩,
have A : s.indicator f =ᵐ[μ.restrict s] s.indicator (ae_measurable.mk f h) :=
(indicator_ae_eq_restrict hs).trans (h.ae_eq_mk.trans $ (indicator_ae_eq_restrict hs).symm),
have B : s.indicator f =ᵐ[μ.restrict sᶜ] s.indicator (ae_measurable.mk f h) :=
(indicator_ae_eq_restrict_compl hs).trans (indicator_ae_eq_restrict_compl hs).symm,
have : s.indicator f =ᵐ[μ.restrict s + μ.restrict sᶜ] s.indicator (ae_measurable.mk f h) :=
ae_add_measure_iff.2 ⟨A, B⟩,
simpa only [hs, measure.restrict_add_restrict_compl] using this },
end
@[measurability]
lemma ae_measurable.indicator (hfm : ae_measurable f μ) {s} (hs : measurable_set s) :
ae_measurable (s.indicator f) μ :=
(ae_measurable_indicator_iff hs).mpr hfm.restrict
end indicator_function
|
063f796dfd65c58e37f1888b7b800fe04af2651b
|
b7f22e51856f4989b970961f794f1c435f9b8f78
|
/tests/lean/run/blast_ematch_ss1.lean
|
7bbd92380835f55db926632b4fa7e1776e8ebb14
|
[
"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
| 329
|
lean
|
constant q (a : Prop) (h : decidable a) : Prop
constant r : nat → Prop
constant rdec : ∀ a, decidable (r a)
constant s : nat → nat
axiom qax : ∀ a h, (: q (r (s a)) h :)
attribute qax [forward]
set_option blast.strategy "ematch"
definition ex1 (a : nat) (b : nat) : b = s a → q (r b) (rdec b) :=
by blast
print ex1
|
cf6dfadb6516364e5204f6b805454cca75534279
|
d9d511f37a523cd7659d6f573f990e2a0af93c6f
|
/src/measure_theory/measure/with_density_vector_measure.lean
|
0c3e962978718f4c4de5784d875636392d788284
|
[
"Apache-2.0"
] |
permissive
|
hikari0108/mathlib
|
b7ea2b7350497ab1a0b87a09d093ecc025a50dfa
|
a9e7d333b0cfd45f13a20f7b96b7d52e19fa2901
|
refs/heads/master
| 1,690,483,608,260
| 1,631,541,580,000
| 1,631,541,580,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 5,647
|
lean
|
/-
Copyright (c) 2021 Kexing Ying. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kexing Ying
-/
import measure_theory.measure.vector_measure
import measure_theory.function.ae_eq_of_integral
/-!
# Vector measure defined by an integral
Given a measure `μ` and an integrable function `f : α → E`, we can define a vector measure `v` such
that for all measurable set `s`, `v i = ∫ x in s, f x ∂μ`. This definition is useful for
the Radon-Nikodym theorem for signed measures.
## Main definitions
* `measure_theory.measure.with_densityᵥ`: the vector measure formed by integrating a function `f`
with respect to a measure `μ` on some set if `f` is integrable, and `0` otherwise.
-/
noncomputable theory
open_locale classical measure_theory nnreal ennreal
variables {α β : Type*} {m : measurable_space α}
namespace measure_theory
open topological_space
variables {μ ν : measure α}
variables {E : Type*} [normed_group E] [measurable_space E] [second_countable_topology E]
[normed_space ℝ E] [complete_space E] [borel_space E]
/-- Given a measure `μ` and an integrable function `f`, `μ.with_densityᵥ f` is
the vector measure which maps the set `s` to `∫ₛ f ∂μ`. -/
def measure.with_densityᵥ {m : measurable_space α} (μ : measure α) (f : α → E) :
vector_measure α E :=
if hf : integrable f μ then
{ measure_of' := λ s, if measurable_set s then ∫ x in s, f x ∂μ else 0,
empty' := by simp,
not_measurable' := λ s hs, if_neg hs,
m_Union' := λ s hs₁ hs₂,
begin
convert has_sum_integral_Union hs₁ hs₂ hf,
{ ext n, rw if_pos (hs₁ n) },
{ rw if_pos (measurable_set.Union hs₁) }
end }
else 0
open measure
include m
variables {f g : α → E}
lemma with_densityᵥ_apply (hf : integrable f μ) {s : set α} (hs : measurable_set s) :
μ.with_densityᵥ f s = ∫ x in s, f x ∂μ :=
by { rw [with_densityᵥ, dif_pos hf], exact dif_pos hs }
@[simp] lemma with_densityᵥ_zero : μ.with_densityᵥ (0 : α → E) = 0 :=
by { ext1 s hs, erw [with_densityᵥ_apply (integrable_zero α E μ) hs], simp, }
@[simp] lemma with_densityᵥ_neg : μ.with_densityᵥ (-f) = -μ.with_densityᵥ f :=
begin
by_cases hf : integrable f μ,
{ ext1 i hi,
rw [vector_measure.neg_apply, with_densityᵥ_apply hf hi,
← integral_neg, with_densityᵥ_apply hf.neg hi],
refl },
{ rw [with_densityᵥ, with_densityᵥ, dif_neg hf, dif_neg, neg_zero],
rwa integrable_neg_iff }
end
@[simp] lemma with_densityᵥ_add (hf : integrable f μ) (hg : integrable g μ) :
μ.with_densityᵥ (f + g) = μ.with_densityᵥ f + μ.with_densityᵥ g :=
begin
ext1 i hi,
rw [with_densityᵥ_apply (hf.add hg) hi, vector_measure.add_apply,
with_densityᵥ_apply hf hi, with_densityᵥ_apply hg hi],
simp_rw [pi.add_apply],
rw integral_add; rw ← integrable_on_univ,
{ exact hf.integrable_on.restrict measurable_set.univ },
{ exact hg.integrable_on.restrict measurable_set.univ }
end
@[simp] lemma with_densityᵥ_sub (hf : integrable f μ) (hg : integrable g μ) :
μ.with_densityᵥ (f - g) = μ.with_densityᵥ f - μ.with_densityᵥ g :=
by rw [sub_eq_add_neg, sub_eq_add_neg, with_densityᵥ_add hf hg.neg, with_densityᵥ_neg]
@[simp] lemma with_densityᵥ_smul {𝕜 : Type*} [nondiscrete_normed_field 𝕜] [normed_space 𝕜 E]
[smul_comm_class ℝ 𝕜 E] [measurable_space 𝕜] [opens_measurable_space 𝕜] (r : 𝕜) :
μ.with_densityᵥ (r • f) = r • μ.with_densityᵥ f :=
begin
by_cases hf : integrable f μ,
{ ext1 i hi,
rw [with_densityᵥ_apply (hf.smul r) hi, vector_measure.smul_apply,
with_densityᵥ_apply hf hi, ← integral_smul r f],
refl },
{ by_cases hr : r = 0,
{ rw [hr, zero_smul, zero_smul, with_densityᵥ_zero] },
{ rw [with_densityᵥ, with_densityᵥ, dif_neg hf, dif_neg, smul_zero],
rwa integrable_smul_iff hr f } }
end
lemma measure.with_densityᵥ_absolutely_continuous (μ : measure α) (f : α → ℝ) :
μ.with_densityᵥ f ≪ μ.to_ennreal_vector_measure :=
begin
by_cases hf : integrable f μ,
{ refine vector_measure.absolutely_continuous.mk (λ i hi₁ hi₂, _),
rw to_ennreal_vector_measure_apply_measurable hi₁ at hi₂,
rw [with_densityᵥ_apply hf hi₁, measure.restrict_zero_set hi₂, integral_zero_measure] },
{ rw [with_densityᵥ, dif_neg hf],
exact vector_measure.absolutely_continuous.zero _ }
end
/-- Having the same density implies the underlying functions are equal almost everywhere. -/
lemma integrable.ae_eq_of_with_densityᵥ_eq {f g : α → E} (hf : integrable f μ) (hg : integrable g μ)
(hfg : μ.with_densityᵥ f = μ.with_densityᵥ g) :
f =ᵐ[μ] g :=
begin
refine hf.ae_eq_of_forall_set_integral_eq f g hg (λ i hi _, _),
rw [← with_densityᵥ_apply hf hi, hfg, with_densityᵥ_apply hg hi]
end
lemma with_densityᵥ_eq.congr_ae {f g : α → E} (h : f =ᵐ[μ] g) :
μ.with_densityᵥ f = μ.with_densityᵥ g :=
begin
by_cases hf : integrable f μ,
{ ext i hi,
rw [with_densityᵥ_apply hf hi, with_densityᵥ_apply (hf.congr h) hi],
exact integral_congr_ae (ae_restrict_of_ae h) },
{ have hg : ¬ integrable g μ,
{ intro hg, exact hf (hg.congr h.symm) },
rw [with_densityᵥ, with_densityᵥ, dif_neg hf, dif_neg hg] }
end
lemma integrable.with_densityᵥ_eq_iff {f g : α → E}
(hf : integrable f μ) (hg : integrable g μ) :
μ.with_densityᵥ f = μ.with_densityᵥ g ↔ f =ᵐ[μ] g :=
⟨λ hfg, hf.ae_eq_of_with_densityᵥ_eq hg hfg, λ h, with_densityᵥ_eq.congr_ae h⟩
end measure_theory
|
ff1257d472c82f5ee0b456f03baf4f208664b505
|
8aabfc0cb7ee877354be18461793fa0a16e8c624
|
/src/first_proofs.lean
|
78d3284ac04bc1d67b8a8413d4f323b505a90cc1
|
[
"Apache-2.0"
] |
permissive
|
dwrensha/tutorials
|
f2596cf6f4a408d553bb4947f37b7960f8141b29
|
e6f872936c222b06bf13d4fb7e3a41d43da9c338
|
refs/heads/master
| 1,600,265,863,399
| 1,573,904,974,000
| 1,573,904,974,000
| 223,796,679
| 0
| 0
| null | 1,574,623,038,000
| 1,574,623,037,000
| null |
UTF-8
|
Lean
| false
| false
| 17,965
|
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.
-/
-- We want real numbers and their basic properties
import data.real.basic
-- We want to be able to define functions using the law of excluded middle
local attribute [instance, priority 0] classical.prop_decidable
/-
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 wite `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 number 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 swaped
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
-- 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 `p'` of `y ≤ x` to a proof of `x = y`. Hence `le_antisymm p p'` 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 neagtion. 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 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 `z` 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 invocation, 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 linarith
... < 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 setup 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 precedining 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
|
67a4b5f68eb524a5aba2dcf0dc05149d29e270dd
|
02005f45e00c7ecf2c8ca5db60251bd1e9c860b5
|
/src/data/fintype/card.lean
|
ab992f6a0af9fe4faf9a56ad38ee41760aa2226d
|
[
"Apache-2.0"
] |
permissive
|
anthony2698/mathlib
|
03cd69fe5c280b0916f6df2d07c614c8e1efe890
|
407615e05814e98b24b2ff322b14e8e3eb5e5d67
|
refs/heads/master
| 1,678,792,774,873
| 1,614,371,563,000
| 1,614,371,563,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 17,200
|
lean
|
/-
Copyright (c) 2017 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Mario Carneiro
-/
import data.fintype.basic
import algebra.big_operators.ring
/-!
Results about "big operations" over a `fintype`, and consequent
results about cardinalities of certain types.
## Implementation note
This content had previously been in `data.fintype`, but was moved here to avoid
requiring `algebra.big_operators` (and hence many other imports) as a
dependency of `fintype`.
-/
universes u v
variables {α : Type*} {β : Type*} {γ : Type*}
open_locale big_operators
namespace fintype
@[to_additive]
lemma prod_bool [comm_monoid α] (f : bool → α) : ∏ b, f b = f tt * f ff := by simp
lemma card_eq_sum_ones {α} [fintype α] : fintype.card α = ∑ a : α, 1 :=
finset.card_eq_sum_ones _
section
open finset
variables {ι : Type*} [decidable_eq ι] [fintype ι]
@[to_additive]
lemma prod_extend_by_one [comm_monoid α] (s : finset ι) (f : ι → α) :
∏ i, (if i ∈ s then f i else 1) = ∏ i in s, f i :=
by rw [← prod_filter, filter_mem_eq_inter, univ_inter]
end
section
variables {M : Type*} [fintype α] [comm_monoid M]
@[to_additive]
lemma prod_eq_one (f : α → M) (h : ∀ a, f a = 1) :
(∏ a, f a) = 1 :=
finset.prod_eq_one $ λ a ha, h a
@[to_additive]
lemma prod_congr (f g : α → M) (h : ∀ a, f a = g a) :
(∏ a, f a) = ∏ a, g a :=
finset.prod_congr rfl $ λ a ha, h a
@[to_additive]
lemma prod_eq_single {f : α → M} (a : α) (h : ∀ x ≠ a, f x = 1) :
(∏ x, f x) = f a :=
finset.prod_eq_single a (λ x _ hx, h x hx) $ λ ha, (ha (finset.mem_univ a)).elim
@[to_additive]
lemma prod_unique [unique β] (f : β → M) :
(∏ x, f x) = f (default β) :=
by simp only [finset.prod_singleton, univ_unique]
/-- If a product of a `finset` of a subsingleton type has a given
value, so do the terms in that product. -/
@[to_additive "If a sum of a `finset` of a subsingleton type has a given
value, so do the terms in that sum."]
lemma eq_of_subsingleton_of_prod_eq {ι : Type*} [subsingleton ι] {s : finset ι}
{f : ι → M} {b : M} (h : ∏ i in s, f i = b) : ∀ i ∈ s, f i = b :=
finset.eq_of_card_le_one_of_prod_eq (finset.card_le_one_of_subsingleton s) h
end
end fintype
open finset
section
variables {M : Type*} [fintype α] [decidable_eq α] [comm_monoid M]
@[to_additive]
lemma is_compl.prod_mul_prod {s t : finset α} (h : is_compl s t) (f : α → M) :
(∏ i in s, f i) * (∏ i in t, f i) = ∏ i, f i :=
(finset.prod_union h.disjoint).symm.trans $ by rw [← finset.sup_eq_union, h.sup_eq_top]; refl
@[to_additive]
lemma finset.prod_mul_prod_compl (s : finset α) (f : α → M) :
(∏ i in s, f i) * (∏ i in sᶜ, f i) = ∏ i, f i :=
is_compl_compl.prod_mul_prod f
@[to_additive]
lemma finset.prod_compl_mul_prod (s : finset α) (f : α → M) :
(∏ i in sᶜ, f i) * (∏ i in s, f i) = ∏ i, f i :=
is_compl_compl.symm.prod_mul_prod f
end
@[to_additive]
theorem fin.prod_univ_def [comm_monoid β] {n : ℕ} (f : fin n → β) :
∏ i, f i = ((list.fin_range n).map f).prod :=
by simp [fin.univ_def, finset.fin_range]
@[to_additive]
theorem fin.prod_of_fn [comm_monoid β] {n : ℕ} (f : fin n → β) :
(list.of_fn f).prod = ∏ i, f i :=
by rw [list.of_fn_eq_map, fin.prod_univ_def]
/-- A product of a function `f : fin 0 → β` is `1` because `fin 0` is empty -/
@[simp, to_additive "A sum of a function `f : fin 0 → β` is `0` because `fin 0` is empty"]
theorem fin.prod_univ_zero [comm_monoid β] (f : fin 0 → β) : ∏ i, f i = 1 := rfl
/-- A product of a function `f : fin (n + 1) → β` over all `fin (n + 1)`
is the product of `f x`, for some `x : fin (n + 1)` times the remaining product -/
theorem fin.prod_univ_succ_above [comm_monoid β] {n : ℕ} (f : fin (n + 1) → β) (x : fin (n + 1)) :
∏ i, f i = f x * ∏ i : fin n, f (x.succ_above i) :=
begin
rw [fin.univ_succ_above, finset.prod_insert, finset.prod_image],
{ intros x _ y _ hxy, exact fin.succ_above_right_inj.mp hxy },
{ simp [fin.succ_above_ne] }
end
/-- A sum of a function `f : fin (n + 1) → β` over all `fin (n + 1)`
is the sum of `f x`, for some `x : fin (n + 1)` plus the remaining product -/
theorem fin.sum_univ_succ_above [add_comm_monoid β] {n : ℕ} (f : fin (n + 1) → β)
(x : fin (n + 1)) :
∑ i, f i = f x + ∑ i : fin n, f (x.succ_above i) :=
by apply @fin.prod_univ_succ_above (multiplicative β)
attribute [to_additive] fin.prod_univ_succ_above
/-- A product of a function `f : fin (n + 1) → β` over all `fin (n + 1)`
is the product of `f 0` plus the remaining product -/
theorem fin.prod_univ_succ [comm_monoid β] {n : ℕ} (f : fin (n + 1) → β) :
∏ i, f i = f 0 * ∏ i : fin n, f i.succ :=
fin.prod_univ_succ_above f 0
/-- A sum of a function `f : fin (n + 1) → β` over all `fin (n + 1)`
is the sum of `f 0` plus the remaining product -/
theorem fin.sum_univ_succ [add_comm_monoid β] {n : ℕ} (f : fin (n + 1) → β) :
∑ i, f i = f 0 + ∑ i : fin n, f i.succ :=
fin.sum_univ_succ_above f 0
attribute [to_additive] fin.prod_univ_succ
/-- A product of a function `f : fin (n + 1) → β` over all `fin (n + 1)`
is the product of `f (fin.last n)` plus the remaining product -/
theorem fin.prod_univ_cast_succ [comm_monoid β] {n : ℕ} (f : fin (n + 1) → β) :
∏ i, f i = (∏ i : fin n, f i.cast_succ) * f (fin.last n) :=
by simpa [mul_comm] using fin.prod_univ_succ_above f (fin.last n)
/-- A sum of a function `f : fin (n + 1) → β` over all `fin (n + 1)`
is the sum of `f (fin.last n)` plus the remaining sum -/
theorem fin.sum_univ_cast_succ [add_comm_monoid β] {n : ℕ} (f : fin (n + 1) → β) :
∑ i, f i = ∑ i : fin n, f i.cast_succ + f (fin.last n) :=
by apply @fin.prod_univ_cast_succ (multiplicative β)
attribute [to_additive] fin.prod_univ_cast_succ
@[simp] theorem fintype.card_sigma {α : Type*} (β : α → Type*)
[fintype α] [∀ a, fintype (β a)] :
fintype.card (sigma β) = ∑ a, fintype.card (β a) :=
card_sigma _ _
-- FIXME ouch, this should be in the main file.
@[simp] theorem fintype.card_sum (α β : Type*) [fintype α] [fintype β] :
fintype.card (α ⊕ β) = fintype.card α + fintype.card β :=
by simp [sum.fintype, fintype.of_equiv_card]
@[simp] lemma finset.card_pi [decidable_eq α] {δ : α → Type*}
(s : finset α) (t : Π a, finset (δ a)) :
(s.pi t).card = ∏ a in s, card (t a) :=
multiset.card_pi _ _
@[simp] lemma fintype.card_pi_finset [decidable_eq α] [fintype α]
{δ : α → Type*} (t : Π a, finset (δ a)) :
(fintype.pi_finset t).card = ∏ a, card (t a) :=
by simp [fintype.pi_finset, card_map]
@[simp] lemma fintype.card_pi {β : α → Type*} [decidable_eq α] [fintype α]
[f : Π a, fintype (β a)] : fintype.card (Π a, β a) = ∏ a, fintype.card (β a) :=
fintype.card_pi_finset _
-- FIXME ouch, this should be in the main file.
@[simp] lemma fintype.card_fun [decidable_eq α] [fintype α] [fintype β] :
fintype.card (α → β) = fintype.card β ^ fintype.card α :=
by rw [fintype.card_pi, finset.prod_const]; refl
@[simp] lemma card_vector [fintype α] (n : ℕ) :
fintype.card (vector α n) = fintype.card α ^ n :=
by rw fintype.of_equiv_card; simp
@[simp, to_additive]
lemma finset.prod_attach_univ [fintype α] [comm_monoid β] (f : {a : α // a ∈ @univ α _} → β) :
∏ x in univ.attach, f x = ∏ x, f ⟨x, (mem_univ _)⟩ :=
prod_bij (λ x _, x.1) (λ _ _, mem_univ _) (λ _ _ , by simp) (by simp)
(λ b _, ⟨⟨b, mem_univ _⟩, by simp⟩)
/-- Taking a product over `univ.pi t` is the same as taking the product over `fintype.pi_finset t`.
`univ.pi t` and `fintype.pi_finset t` are essentially the same `finset`, but differ
in the type of their element, `univ.pi t` is a `finset (Π a ∈ univ, t a)` and
`fintype.pi_finset t` is a `finset (Π a, t a)`. -/
@[to_additive "Taking a sum over `univ.pi t` is the same as taking the sum over
`fintype.pi_finset t`. `univ.pi t` and `fintype.pi_finset t` are essentially the same `finset`,
but differ in the type of their element, `univ.pi t` is a `finset (Π a ∈ univ, t a)` and
`fintype.pi_finset t` is a `finset (Π a, t a)`."]
lemma finset.prod_univ_pi [decidable_eq α] [fintype α] [comm_monoid β]
{δ : α → Type*} {t : Π (a : α), finset (δ a)}
(f : (Π (a : α), a ∈ (univ : finset α) → δ a) → β) :
∏ x in univ.pi t, f x = ∏ x in fintype.pi_finset t, f (λ a _, x a) :=
prod_bij (λ x _ a, x a (mem_univ _))
(by simp)
(by simp)
(by simp [function.funext_iff] {contextual := tt})
(λ x hx, ⟨λ a _, x a, by simp * at *⟩)
/-- The product over `univ` of a sum can be written as a sum over the product of sets,
`fintype.pi_finset`. `finset.prod_sum` is an alternative statement when the product is not
over `univ` -/
lemma finset.prod_univ_sum [decidable_eq α] [fintype α] [comm_semiring β] {δ : α → Type u_1}
[Π (a : α), decidable_eq (δ a)] {t : Π (a : α), finset (δ a)}
{f : Π (a : α), δ a → β} :
∏ a, ∑ b in t a, f a b = ∑ p in fintype.pi_finset t, ∏ x, f x (p x) :=
by simp only [finset.prod_attach_univ, prod_sum, finset.sum_univ_pi]
/-- Summing `a^s.card * b^(n-s.card)` over all finite subsets `s` of a fintype of cardinality `n`
gives `(a + b)^n`. The "good" proof involves expanding along all coordinates using the fact that
`x^n` is multilinear, but multilinear maps are only available now over rings, so we give instead
a proof reducing to the usual binomial theorem to have a result over semirings. -/
lemma fintype.sum_pow_mul_eq_add_pow
(α : Type*) [fintype α] {R : Type*} [comm_semiring R] (a b : R) :
∑ s : finset α, a ^ s.card * b ^ (fintype.card α - s.card) =
(a + b) ^ (fintype.card α) :=
finset.sum_pow_mul_eq_add_pow _ _ _
lemma fin.sum_pow_mul_eq_add_pow {n : ℕ} {R : Type*} [comm_semiring R] (a b : R) :
∑ s : finset (fin n), a ^ s.card * b ^ (n - s.card) =
(a + b) ^ n :=
by simpa using fintype.sum_pow_mul_eq_add_pow (fin n) a b
@[to_additive]
lemma function.bijective.prod_comp [fintype α] [fintype β] [comm_monoid γ] {f : α → β}
(hf : function.bijective f) (g : β → γ) :
∏ i, g (f i) = ∏ i, g i :=
prod_bij (λ i hi, f i) (λ i hi, mem_univ _) (λ i hi, rfl) (λ i j _ _ h, hf.1 h) $
λ i hi, (hf.2 i).imp $ λ j hj, ⟨mem_univ _, hj.symm⟩
@[to_additive]
lemma equiv.prod_comp [fintype α] [fintype β] [comm_monoid γ] (e : α ≃ β) (f : β → γ) :
∏ i, f (e i) = ∏ i, f i :=
e.bijective.prod_comp f
/-- It is equivalent to sum a function over `fin n` or `finset.range n`. -/
@[to_additive]
lemma fin.prod_univ_eq_prod_range [comm_monoid α] (f : ℕ → α) (n : ℕ) :
∏ i : fin n, f i = ∏ i in range n, f i :=
calc (∏ i : fin n, f i) = ∏ i : {x // x ∈ range n}, f i :
((equiv.fin_equiv_subtype n).trans
(equiv.subtype_equiv_right (λ _, mem_range.symm))).prod_comp (f ∘ coe)
... = ∏ i in range n, f i : by rw [← attach_eq_univ, prod_attach]
@[to_additive]
lemma finset.prod_fin_eq_prod_range [comm_monoid β] {n : ℕ} (c : fin n → β) :
∏ i, c i = ∏ i in finset.range n, if h : i < n then c ⟨i, h⟩ else 1 :=
begin
rw [← fin.prod_univ_eq_prod_range, finset.prod_congr rfl],
rintros ⟨i, hi⟩ _,
simp only [fin.coe_eq_val, hi, dif_pos]
end
@[to_additive]
lemma finset.prod_subtype {M : Type*} [comm_monoid M]
{p : α → Prop} {F : fintype (subtype p)} (s : finset α) (h : ∀ x, x ∈ s ↔ p x) (f : α → M) :
∏ a in s, f a = ∏ a : subtype p, f a :=
have (∈ s) = p, from set.ext h,
begin
rw [← prod_attach, attach_eq_univ],
substI p,
congr
end
@[to_additive]
lemma finset.prod_to_finset_eq_subtype {M : Type*} [comm_monoid M] [fintype α]
(p : α → Prop) [decidable_pred p] (f : α → M) :
∏ a in {x | p x}.to_finset, f a = ∏ a : subtype p, f a :=
by { rw ← finset.prod_subtype, simp }
@[to_additive] lemma finset.prod_fiberwise [decidable_eq β] [fintype β] [comm_monoid γ]
(s : finset α) (f : α → β) (g : α → γ) :
∏ b : β, ∏ a in s.filter (λ a, f a = b), g a = ∏ a in s, g a :=
finset.prod_fiberwise_of_maps_to (λ x _, mem_univ _) _
@[to_additive]
lemma fintype.prod_fiberwise [fintype α] [decidable_eq β] [fintype β] [comm_monoid γ]
(f : α → β) (g : α → γ) :
(∏ b : β, ∏ a : {a // f a = b}, g (a : α)) = ∏ a, g a :=
begin
rw [← (equiv.sigma_preimage_equiv f).prod_comp, ← univ_sigma_univ, prod_sigma],
refl
end
lemma fintype.prod_dite [fintype α] {p : α → Prop} [decidable_pred p]
[comm_monoid β] (f : Π (a : α) (ha : p a), β) (g : Π (a : α) (ha : ¬p a), β) :
(∏ a, dite (p a) (f a) (g a)) = (∏ a : {a // p a}, f a a.2) * (∏ a : {a // ¬p a}, g a a.2) :=
begin
simp only [prod_dite, attach_eq_univ],
congr' 1,
{ convert (equiv.subtype_equiv_right _).prod_comp (λ x : {x // p x}, f x x.2),
simp },
{ convert (equiv.subtype_equiv_right _).prod_comp (λ x : {x // ¬p x}, g x x.2),
simp }
end
section
open finset
variables {α₁ : Type*} {α₂ : Type*} {M : Type*} [fintype α₁] [fintype α₂] [comm_monoid M]
@[to_additive]
lemma fintype.prod_sum_elim (f : α₁ → M) (g : α₂ → M) :
(∏ x, sum.elim f g x) = (∏ a₁, f a₁) * (∏ a₂, g a₂) :=
by { classical, rw [univ_sum_type, prod_sum_elim] }
@[to_additive]
lemma fintype.prod_sum_type (f : α₁ ⊕ α₂ → M) :
(∏ x, f x) = (∏ a₁, f (sum.inl a₁)) * (∏ a₂, f (sum.inr a₂)) :=
by simp only [← fintype.prod_sum_elim, sum.elim_comp_inl_inr]
end
namespace list
lemma prod_take_of_fn [comm_monoid α] {n : ℕ} (f : fin n → α) (i : ℕ) :
((of_fn f).take i).prod = ∏ j in finset.univ.filter (λ (j : fin n), j.val < i), f j :=
begin
have A : ∀ (j : fin n), ¬ ((j : ℕ) < 0) := λ j, not_lt_bot,
induction i with i IH, { simp [A] },
by_cases h : i < n,
{ have : i < length (of_fn f), by rwa [length_of_fn f],
rw prod_take_succ _ _ this,
have A : ((finset.univ : finset (fin n)).filter (λ j, j.val < i + 1))
= ((finset.univ : finset (fin n)).filter (λ j, j.val < i)) ∪ {(⟨i, h⟩ : fin n)},
by { ext j, simp [nat.lt_succ_iff_lt_or_eq, fin.ext_iff, - add_comm] },
have B : _root_.disjoint (finset.filter (λ (j : fin n), j.val < i) finset.univ)
(singleton (⟨i, h⟩ : fin n)), by simp,
rw [A, finset.prod_union B, IH],
simp },
{ have A : (of_fn f).take i = (of_fn f).take i.succ,
{ rw ← length_of_fn f at h,
have : length (of_fn f) ≤ i := not_lt.mp h,
rw [take_all_of_le this, take_all_of_le (le_trans this (nat.le_succ _))] },
have B : ∀ (j : fin n), ((j : ℕ) < i.succ) = ((j : ℕ) < i),
{ assume j,
have : (j : ℕ) < i := lt_of_lt_of_le j.2 (not_lt.mp h),
simp [this, lt_trans this (nat.lt_succ_self _)] },
simp [← A, B, IH] }
end
-- `to_additive` does not work on `prod_take_of_fn` because of `0 : ℕ` in the proof.
-- Use `multiplicative` instead.
lemma sum_take_of_fn [add_comm_monoid α] {n : ℕ} (f : fin n → α) (i : ℕ) :
((of_fn f).take i).sum = ∑ j in finset.univ.filter (λ (j : fin n), j.val < i), f j :=
@prod_take_of_fn (multiplicative α) _ n f i
attribute [to_additive] prod_take_of_fn
@[to_additive]
lemma prod_of_fn [comm_monoid α] {n : ℕ} {f : fin n → α} :
(of_fn f).prod = ∏ i, f i :=
begin
convert prod_take_of_fn f n,
{ rw [take_all_of_le (le_of_eq (length_of_fn f))] },
{ have : ∀ (j : fin n), (j : ℕ) < n := λ j, j.is_lt,
simp [this] }
end
lemma alternating_sum_eq_finset_sum {G : Type*} [add_comm_group G] :
∀ (L : list G), alternating_sum L = ∑ i : fin L.length, (-1 : ℤ) ^ (i : ℕ) •ℤ L.nth_le i i.is_lt
| [] := by { rw [alternating_sum, finset.sum_eq_zero], rintro ⟨i, ⟨⟩⟩ }
| (g :: []) :=
begin
show g = ∑ i : fin 1, (-1 : ℤ) ^ (i : ℕ) •ℤ [g].nth_le i i.2,
rw [fin.sum_univ_succ], simp,
end
| (g :: h :: L) :=
calc g + -h + L.alternating_sum
= g + -h + ∑ i : fin L.length, (-1 : ℤ) ^ (i : ℕ) •ℤ L.nth_le i i.2 :
congr_arg _ (alternating_sum_eq_finset_sum _)
... = ∑ i : fin (L.length + 2), (-1 : ℤ) ^ (i : ℕ) •ℤ list.nth_le (g :: h :: L) i _ :
begin
rw [fin.sum_univ_succ, fin.sum_univ_succ, add_assoc],
unfold_coes,
simp [nat.succ_eq_add_one, pow_add],
refl,
end
@[to_additive]
lemma alternating_prod_eq_finset_prod {G : Type*} [comm_group G] :
∀ (L : list G), alternating_prod L = ∏ i : fin L.length, (L.nth_le i i.2) ^ ((-1 : ℤ) ^ (i : ℕ))
| [] := by { rw [alternating_prod, finset.prod_eq_one], rintro ⟨i, ⟨⟩⟩ }
| (g :: []) :=
begin
show g = ∏ i : fin 1, [g].nth_le i i.2 ^ (-1 : ℤ) ^ (i : ℕ),
rw [fin.prod_univ_succ], simp,
end
| (g :: h :: L) :=
calc g * h⁻¹ * L.alternating_prod
= g * h⁻¹ * ∏ i : fin L.length, L.nth_le i i.2 ^ (-1 : ℤ) ^ (i : ℕ) :
congr_arg _ (alternating_prod_eq_finset_prod _)
... = ∏ i : fin (L.length + 2), list.nth_le (g :: h :: L) i _ ^ (-1 : ℤ) ^ (i : ℕ) :
begin
rw [fin.prod_univ_succ, fin.prod_univ_succ, mul_assoc],
unfold_coes,
simp [nat.succ_eq_add_one, pow_add],
refl,
end
end list
|
1a0d4058278bc3d12de46bda30ae78166b23bfd5
|
8c9f90127b78cbeb5bb17fd6b5db1db2ffa3cbc4
|
/succ_over_eq.lean
|
162f73a007861aa03075a723eba3b82e619ec726
|
[] |
no_license
|
picrin/lean
|
420f4d08bb3796b911d56d0938e4410e1da0e072
|
3d10c509c79704aa3a88ebfb24d08b30ce1137cc
|
refs/heads/master
| 1,611,166,610,726
| 1,536,671,438,000
| 1,536,671,438,000
| 60,029,899
| 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 418
|
lean
|
inductive natural : Type
| zero : natural
| succ : natural -> natural
lemma succ_over_equality (a b : natural) (H : a = b) : (natural.succ a) = (natural.succ b) :=
eq.rec_on H (eq.refl (natural.succ a))
--eq.rec_on H rfl
--eq.subst H rfl
--eq.subst H (eq.refl (natural.succ a))
--congr_arg (λ (n : natural), (natural.succ n)) H
variables a b : natural
variable H : (a = b)
#check eq a b
--eq H
|
6a8bad30c3fd139a052c0a4d732702f20fcceea9
|
35677d2df3f081738fa6b08138e03ee36bc33cad
|
/src/algebra/associated.lean
|
3d32871c7b471a1735d18d3c718146f1155e0124
|
[
"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
| 25,440
|
lean
|
/-
Copyright (c) 2018 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Jens Wagemaker
-/
import algebra.group.is_unit data.multiset
/-!
# Associated, prime, and irreducible elements.
-/
variables {α : Type*} {β : Type*} {γ : Type*} {δ : Type*}
theorem is_unit.mk0 [division_ring α] (x : α) (hx : x ≠ 0) : is_unit x := is_unit_unit (units.mk0 x hx)
theorem is_unit_iff_ne_zero [division_ring α] {x : α} :
is_unit x ↔ x ≠ 0 :=
⟨λ ⟨u, hu⟩, hu.symm ▸ λ h : u.1 = 0, by simpa [h, zero_ne_one] using u.3, is_unit.mk0 x⟩
@[simp] theorem is_unit_zero_iff [semiring α] : is_unit (0 : α) ↔ (0:α) = 1 :=
⟨λ ⟨⟨_, a, (a0 : 0 * a = 1), _⟩, rfl⟩, by rwa zero_mul at a0,
λ h, begin
haveI := subsingleton_of_zero_eq_one _ h,
refine ⟨⟨0, 0, _, _⟩, rfl⟩; apply subsingleton.elim
end⟩
@[simp] theorem not_is_unit_zero [nonzero_comm_ring α] : ¬ is_unit (0 : α) :=
mt is_unit_zero_iff.1 zero_ne_one
lemma is_unit_pow [monoid α] {a : α} (n : ℕ) : is_unit a → is_unit (a ^ n) :=
λ ⟨u, hu⟩, ⟨u ^ n, by simp *⟩
theorem is_unit_iff_dvd_one [comm_semiring α] {x : α} : is_unit x ↔ x ∣ 1 :=
⟨by rintro ⟨u, rfl⟩; exact ⟨_, u.mul_inv.symm⟩,
λ ⟨y, h⟩, ⟨⟨x, y, h.symm, by rw [h, mul_comm]⟩, rfl⟩⟩
theorem is_unit_iff_forall_dvd [comm_semiring α] {x : α} :
is_unit x ↔ ∀ y, x ∣ y :=
is_unit_iff_dvd_one.trans ⟨λ h y, dvd.trans h (one_dvd _), λ h, h _⟩
theorem mul_dvd_of_is_unit_left [comm_semiring α] {x y z : α} (h : is_unit x) : x * y ∣ z ↔ y ∣ z :=
⟨dvd_trans (dvd_mul_left _ _),
dvd_trans $ by simpa using mul_dvd_mul_right (is_unit_iff_dvd_one.1 h) y⟩
theorem mul_dvd_of_is_unit_right [comm_semiring α] {x y z : α} (h : is_unit y) : x * y ∣ z ↔ x ∣ z :=
by rw [mul_comm, mul_dvd_of_is_unit_left h]
@[simp] lemma unit_mul_dvd_iff [comm_semiring α] {a b : α} {u : units α} : (u : α) * a ∣ b ↔ a ∣ b :=
mul_dvd_of_is_unit_left (is_unit_unit _)
lemma mul_unit_dvd_iff [comm_semiring α] {a b : α} {u : units α} : a * u ∣ b ↔ a ∣ b :=
units.coe_mul_dvd _ _ _
theorem is_unit_of_dvd_unit {α} [comm_semiring α] {x y : α}
(xy : x ∣ y) (hu : is_unit y) : is_unit x :=
is_unit_iff_dvd_one.2 $ dvd_trans xy $ is_unit_iff_dvd_one.1 hu
theorem is_unit_int {n : ℤ} : is_unit n ↔ n.nat_abs = 1 :=
⟨λ ⟨u, hu⟩, (int.units_eq_one_or u).elim (by simp *) (by simp *),
λ h, is_unit_iff_dvd_one.2 ⟨n, by rw [← int.nat_abs_mul_self, h]; refl⟩⟩
lemma is_unit_of_dvd_one [comm_semiring α] : ∀a ∣ 1, is_unit (a:α)
| a ⟨b, eq⟩ := ⟨units.mk_of_mul_eq_one a b eq.symm, rfl⟩
lemma dvd_and_not_dvd_iff [integral_domain α] {x y : α} :
x ∣ y ∧ ¬y ∣ x ↔ x ≠ 0 ∧ ∃ d : α, ¬ is_unit d ∧ y = x * d :=
⟨λ ⟨⟨d, hd⟩, hyx⟩, ⟨λ hx0, by simpa [hx0] using hyx, ⟨d,
mt is_unit_iff_dvd_one.1 (λ ⟨e, he⟩, hyx ⟨e, by rw [hd, mul_assoc, ← he, mul_one]⟩), hd⟩⟩,
λ ⟨hx0, d, hdu, hdx⟩, ⟨⟨d, hdx⟩, λ ⟨e, he⟩, hdu (is_unit_of_dvd_one _
⟨e, (domain.mul_left_inj hx0).1 $ by conv {to_lhs, rw [he, hdx]};simp [mul_assoc]⟩)⟩⟩
lemma pow_dvd_pow_iff [integral_domain α] {x : α} {n m : ℕ} (h0 : x ≠ 0) (h1 : ¬ is_unit x) :
x ^ n ∣ x ^ m ↔ n ≤ m :=
begin
split,
{ intro h, rw [← not_lt], intro hmn, apply h1,
have : x * x ^ m ∣ 1 * x ^ m,
{ rw [← pow_succ, one_mul], exact dvd_trans (pow_dvd_pow _ (nat.succ_le_of_lt hmn)) h },
rwa [mul_dvd_mul_iff_right, ← is_unit_iff_dvd_one] at this, apply pow_ne_zero m h0 },
{ apply pow_dvd_pow }
end
/-- prime element of a semiring -/
def prime [comm_semiring α] (p : α) : Prop :=
p ≠ 0 ∧ ¬ is_unit p ∧ (∀a b, p ∣ a * b → p ∣ a ∨ p ∣ b)
namespace prime
lemma ne_zero [comm_semiring α] {p : α} (hp : prime p) : p ≠ 0 :=
hp.1
lemma not_unit [comm_semiring α] {p : α} (hp : prime p) : ¬ is_unit p :=
hp.2.1
lemma div_or_div [comm_semiring α] {p : α} (hp : prime p) {a b : α} (h : p ∣ a * b) :
p ∣ a ∨ p ∣ b :=
hp.2.2 a b h
end prime
@[simp] lemma not_prime_zero [comm_semiring α] : ¬ prime (0 : α) :=
λ h, h.ne_zero rfl
@[simp] lemma not_prime_one [comm_semiring α] : ¬ prime (1 : α) :=
λ h, h.not_unit is_unit_one
lemma exists_mem_multiset_dvd_of_prime [comm_semiring α] {s : multiset α} {p : α} (hp : prime p) :
p ∣ s.prod → ∃a∈s, p ∣ a :=
multiset.induction_on s (assume h, (hp.not_unit $ is_unit_of_dvd_one _ h).elim) $
assume a s ih h,
have p ∣ a * s.prod, by simpa using h,
match hp.div_or_div this with
| or.inl h := ⟨a, multiset.mem_cons_self a s, h⟩
| or.inr h := let ⟨a, has, h⟩ := ih h in ⟨a, multiset.mem_cons_of_mem has, h⟩
end
/-- `irreducible p` states that `p` is non-unit and only factors into units.
We explicitly avoid stating that `p` is non-zero, this would require a semiring. Assuming only a
monoid allows us to reuse irreducible for associated elements.
-/
@[class] def irreducible [monoid α] (p : α) : Prop :=
¬ is_unit p ∧ ∀a b, p = a * b → is_unit a ∨ is_unit b
namespace irreducible
lemma not_unit [monoid α] {p : α} (hp : irreducible p) : ¬ is_unit p :=
hp.1
lemma is_unit_or_is_unit [monoid α] {p : α} (hp : irreducible p) {a b : α} (h : p = a * b) :
is_unit a ∨ is_unit b :=
hp.2 a b h
end irreducible
@[simp] theorem not_irreducible_one [monoid α] : ¬ irreducible (1 : α) :=
by simp [irreducible]
@[simp] theorem not_irreducible_zero [semiring α] : ¬ irreducible (0 : α)
| ⟨hn0, h⟩ := have is_unit (0:α) ∨ is_unit (0:α), from h 0 0 ((mul_zero 0).symm),
this.elim hn0 hn0
theorem irreducible.ne_zero [semiring α] : ∀ {p:α}, irreducible p → p ≠ 0
| _ hp rfl := not_irreducible_zero hp
theorem of_irreducible_mul {α} [monoid α] {x y : α} :
irreducible (x * y) → is_unit x ∨ is_unit y
| ⟨_, h⟩ := h _ _ rfl
theorem irreducible_or_factor {α} [monoid α] (x : α) (h : ¬ is_unit x) :
irreducible x ∨ ∃ a b, ¬ is_unit a ∧ ¬ is_unit b ∧ a * b = x :=
begin
haveI := classical.dec,
refine or_iff_not_imp_right.2 (λ H, _),
simp [h, irreducible] at H ⊢,
refine λ a b h, classical.by_contradiction $ λ o, _,
simp [not_or_distrib] at o,
exact H _ o.1 _ o.2 h.symm
end
lemma irreducible_of_prime [integral_domain α] {p : α} (hp : prime p) : irreducible p :=
⟨hp.not_unit, λ a b hab,
(show a * b ∣ a ∨ a * b ∣ b, from hab ▸ hp.div_or_div (hab ▸ (dvd_refl _))).elim
(λ ⟨x, hx⟩, or.inr (is_unit_iff_dvd_one.2
⟨x, (domain.mul_left_inj (show a ≠ 0, from λ h, by simp [*, prime] at *)).1
$ by conv {to_lhs, rw hx}; simp [mul_comm, mul_assoc, mul_left_comm]⟩))
(λ ⟨x, hx⟩, or.inl (is_unit_iff_dvd_one.2
⟨x, (domain.mul_left_inj (show b ≠ 0, from λ h, by simp [*, prime] at *)).1
$ by conv {to_lhs, rw hx}; simp [mul_comm, mul_assoc, mul_left_comm]⟩))⟩
lemma succ_dvd_or_succ_dvd_of_succ_sum_dvd_mul [integral_domain α] {p : α} (hp : prime p) {a b : α}
{k l : ℕ} : p ^ k ∣ a → p ^ l ∣ b → p ^ ((k + l) + 1) ∣ a * b →
p ^ (k + 1) ∣ a ∨ p ^ (l + 1) ∣ b :=
λ ⟨x, hx⟩ ⟨y, hy⟩ ⟨z, hz⟩,
have h : p ^ (k + l) * (x * y) = p ^ (k + l) * (p * z),
by simpa [mul_comm, _root_.pow_add, hx, hy, mul_assoc, mul_left_comm] using hz,
have hp0: p ^ (k + l) ≠ 0, from pow_ne_zero _ hp.ne_zero,
have hpd : p ∣ x * y, from ⟨z, by rwa [domain.mul_left_inj hp0] at h⟩,
(hp.div_or_div hpd).elim
(λ ⟨d, hd⟩, or.inl ⟨d, by simp [*, _root_.pow_succ, mul_comm, mul_left_comm, mul_assoc]⟩)
(λ ⟨d, hd⟩, or.inr ⟨d, by simp [*, _root_.pow_succ, mul_comm, mul_left_comm, mul_assoc]⟩)
/-- Two elements of a `monoid` are `associated` if one of them is another one
multiplied by a unit on the right. -/
def associated [monoid α] (x y : α) : Prop := ∃u:units α, x * u = y
local infix ` ~ᵤ ` : 50 := associated
namespace associated
@[refl] protected theorem refl [monoid α] (x : α) : x ~ᵤ x := ⟨1, by simp⟩
@[symm] protected theorem symm [monoid α] : ∀{x y : α}, x ~ᵤ y → y ~ᵤ x
| x _ ⟨u, rfl⟩ := ⟨u⁻¹, by rw [mul_assoc, units.mul_inv, mul_one]⟩
@[trans] protected theorem trans [monoid α] : ∀{x y z : α}, x ~ᵤ y → y ~ᵤ z → x ~ᵤ z
| x _ _ ⟨u, rfl⟩ ⟨v, rfl⟩ := ⟨u * v, by rw [units.coe_mul, mul_assoc]⟩
protected def setoid (α : Type*) [monoid α] : setoid α :=
{ r := associated, iseqv := ⟨associated.refl, λa b, associated.symm, λa b c, associated.trans⟩ }
end associated
local attribute [instance] associated.setoid
theorem unit_associated_one [monoid α] {u : units α} : (u : α) ~ᵤ 1 := ⟨u⁻¹, units.mul_inv u⟩
theorem associated_one_iff_is_unit [monoid α] {a : α} : (a : α) ~ᵤ 1 ↔ is_unit a :=
iff.intro
(assume h, let ⟨c, h⟩ := h.symm in h ▸ ⟨c, one_mul _⟩)
(assume ⟨c, h⟩, associated.symm ⟨c, by simp [h]⟩)
theorem associated_zero_iff_eq_zero [comm_semiring α] (a : α) : a ~ᵤ 0 ↔ a = 0 :=
iff.intro
(assume h, let ⟨u, h⟩ := h.symm in by simpa using h.symm)
(assume h, h ▸ associated.refl a)
theorem associated_one_of_mul_eq_one [comm_monoid α] {a : α} (b : α) (hab : a * b = 1) : a ~ᵤ 1 :=
show (units.mk_of_mul_eq_one a b hab : α) ~ᵤ 1, from unit_associated_one
theorem associated_one_of_associated_mul_one [comm_monoid α] {a b : α} :
a * b ~ᵤ 1 → a ~ᵤ 1
| ⟨u, h⟩ := associated_one_of_mul_eq_one (b * u) $ by simpa [mul_assoc] using h
lemma associated_mul_mul [comm_monoid α] {a₁ a₂ b₁ b₂ : α} :
a₁ ~ᵤ b₁ → a₂ ~ᵤ b₂ → (a₁ * a₂) ~ᵤ (b₁ * b₂)
| ⟨c₁, h₁⟩ ⟨c₂, h₂⟩ := ⟨c₁ * c₂, by simp [h₁.symm, h₂.symm, mul_assoc, mul_comm, mul_left_comm]⟩
theorem associated_of_dvd_dvd [integral_domain α] {a b : α} (hab : a ∣ b) (hba : b ∣ a) : a ~ᵤ b :=
begin
haveI := classical.dec_eq α,
rcases hab with ⟨c, rfl⟩,
rcases hba with ⟨d, a_eq⟩,
by_cases ha0 : a = 0,
{ simp [*] at * },
have : a * 1 = a * (c * d),
{ simpa [mul_assoc] using a_eq },
have : 1 = (c * d), from eq_of_mul_eq_mul_left ha0 this,
exact ⟨units.mk_of_mul_eq_one c d (this.symm), by rw [units.mk_of_mul_eq_one, units.val_coe]⟩
end
lemma exists_associated_mem_of_dvd_prod [integral_domain α] {p : α}
(hp : prime p) {s : multiset α} : (∀ r ∈ s, prime r) → p ∣ s.prod → ∃ q ∈ s, p ~ᵤ q :=
multiset.induction_on s (by simp [mt is_unit_iff_dvd_one.2 hp.not_unit])
(λ a s ih hs hps, begin
rw [multiset.prod_cons] at hps,
cases hp.div_or_div hps with h h,
{ use [a, by simp],
cases h with u hu,
cases ((irreducible_of_prime (hs a (multiset.mem_cons.2
(or.inl rfl)))).2 p u hu).resolve_left hp.not_unit with v hv,
exact ⟨v, by simp [hu, hv]⟩ },
{ rcases ih (λ r hr, hs _ (multiset.mem_cons.2 (or.inr hr))) h with ⟨q, hq₁, hq₂⟩,
exact ⟨q, multiset.mem_cons.2 (or.inr hq₁), hq₂⟩ }
end)
lemma dvd_iff_dvd_of_rel_left [comm_semiring α] {a b c : α} (h : a ~ᵤ b) : a ∣ c ↔ b ∣ c :=
let ⟨u, hu⟩ := h in hu ▸ mul_unit_dvd_iff.symm
lemma dvd_mul_unit_iff [comm_semiring α] {a b : α} {u : units α} : a ∣ b * u ↔ a ∣ b :=
units.dvd_coe_mul _ _ _
lemma dvd_iff_dvd_of_rel_right [comm_semiring α] {a b c : α} (h : b ~ᵤ c) : a ∣ b ↔ a ∣ c :=
let ⟨u, hu⟩ := h in hu ▸ dvd_mul_unit_iff.symm
lemma eq_zero_iff_of_associated [comm_semiring α] {a b : α} (h : a ~ᵤ b) : a = 0 ↔ b = 0 :=
⟨λ ha, let ⟨u, hu⟩ := h in by simp [hu.symm, ha],
λ hb, let ⟨u, hu⟩ := h.symm in by simp [hu.symm, hb]⟩
lemma ne_zero_iff_of_associated [comm_semiring α] {a b : α} (h : a ~ᵤ b) : a ≠ 0 ↔ b ≠ 0 :=
by haveI := classical.dec; exact not_iff_not.2 (eq_zero_iff_of_associated h)
lemma prime_of_associated [comm_semiring α] {p q : α} (h : p ~ᵤ q) (hp : prime p) : prime q :=
⟨(ne_zero_iff_of_associated h).1 hp.ne_zero,
let ⟨u, hu⟩ := h in
⟨λ ⟨v, hv⟩, hp.not_unit ⟨v * u⁻¹, by simp [hv.symm, hu.symm]⟩,
hu ▸ by { simp [mul_unit_dvd_iff], intros a b, exact hp.div_or_div }⟩⟩
lemma prime_iff_of_associated [comm_semiring α] {p q : α}
(h : p ~ᵤ q) : prime p ↔ prime q :=
⟨prime_of_associated h, prime_of_associated h.symm⟩
lemma is_unit_iff_of_associated [monoid α] {a b : α} (h : a ~ᵤ b) : is_unit a ↔ is_unit b :=
⟨let ⟨u, hu⟩ := h in λ ⟨v, hv⟩, ⟨v * u, by simp [hv, hu.symm]⟩,
let ⟨u, hu⟩ := h.symm in λ ⟨v, hv⟩, ⟨v * u, by simp [hv, hu.symm]⟩⟩
lemma irreducible_of_associated [comm_semiring α] {p q : α} (h : p ~ᵤ q)
(hp : irreducible p) : irreducible q :=
⟨mt (is_unit_iff_of_associated h).2 hp.1,
let ⟨u, hu⟩ := h in λ a b hab,
have hpab : p = a * (b * (u⁻¹ : units α)),
from calc p = (p * u) * (u ⁻¹ : units α) : by simp
... = _ : by rw hu; simp [hab, mul_assoc],
(hp.2 _ _ hpab).elim or.inl (λ ⟨v, hv⟩, or.inr ⟨v * u, by simp [hv.symm]⟩)⟩
lemma irreducible_iff_of_associated [comm_semiring α] {p q : α} (h : p ~ᵤ q) :
irreducible p ↔ irreducible q :=
⟨irreducible_of_associated h, irreducible_of_associated h.symm⟩
lemma associated_mul_left_cancel [integral_domain α] {a b c d : α}
(h : a * b ~ᵤ c * d) (h₁ : a ~ᵤ c) (ha : a ≠ 0) : b ~ᵤ d :=
let ⟨u, hu⟩ := h in let ⟨v, hv⟩ := associated.symm h₁ in
⟨u * (v : units α), (domain.mul_left_inj ha).1
begin
rw [← hv, mul_assoc c (v : α) d, mul_left_comm c, ← hu],
simp [hv.symm, mul_assoc, mul_comm, mul_left_comm]
end⟩
lemma associated_mul_right_cancel [integral_domain α] {a b c d : α} :
a * b ~ᵤ c * d → b ~ᵤ d → b ≠ 0 → a ~ᵤ c :=
by rw [mul_comm a, mul_comm c]; exact associated_mul_left_cancel
def associates (α : Type*) [monoid α] : Type* :=
quotient (associated.setoid α)
namespace associates
open associated
protected def mk {α : Type*} [monoid α] (a : α) : associates α :=
⟦ a ⟧
instance [monoid α] : inhabited (associates α) := ⟨⟦1⟧⟩
theorem mk_eq_mk_iff_associated [monoid α] {a b : α} :
associates.mk a = associates.mk b ↔ a ~ᵤ b :=
iff.intro quotient.exact quot.sound
theorem quotient_mk_eq_mk [monoid α] (a : α) : ⟦ a ⟧ = associates.mk a := rfl
theorem quot_mk_eq_mk [monoid α] (a : α) : quot.mk setoid.r a = associates.mk a := rfl
theorem forall_associated [monoid α] {p : associates α → Prop} :
(∀a, p a) ↔ (∀a, p (associates.mk a)) :=
iff.intro
(assume h a, h _)
(assume h a, quotient.induction_on a h)
instance [monoid α] : has_one (associates α) := ⟨⟦ 1 ⟧⟩
theorem one_eq_mk_one [monoid α] : (1 : associates α) = associates.mk 1 := rfl
instance [monoid α] : has_bot (associates α) := ⟨1⟩
section comm_monoid
variable [comm_monoid α]
instance : has_mul (associates α) :=
⟨λa' b', quotient.lift_on₂ a' b' (λa b, ⟦ a * b ⟧) $
assume a₁ a₂ b₁ b₂ ⟨c₁, h₁⟩ ⟨c₂, h₂⟩,
quotient.sound $ ⟨c₁ * c₂, by simp [h₁.symm, h₂.symm, mul_assoc, mul_comm, mul_left_comm]⟩⟩
theorem mk_mul_mk {x y : α} : associates.mk x * associates.mk y = associates.mk (x * y) :=
rfl
instance : comm_monoid (associates α) :=
{ one := 1,
mul := (*),
mul_one := assume a', quotient.induction_on a' $
assume a, show ⟦a * 1⟧ = ⟦ a ⟧, by simp,
one_mul := assume a', quotient.induction_on a' $
assume a, show ⟦1 * a⟧ = ⟦ a ⟧, by simp,
mul_assoc := assume a' b' c', quotient.induction_on₃ a' b' c' $
assume a b c, show ⟦a * b * c⟧ = ⟦a * (b * c)⟧, by rw [mul_assoc],
mul_comm := assume a' b', quotient.induction_on₂ a' b' $
assume a b, show ⟦a * b⟧ = ⟦b * a⟧, by rw [mul_comm] }
instance : preorder (associates α) :=
{ le := λa b, ∃c, a * c = b,
le_refl := assume a, ⟨1, by simp⟩,
le_trans := assume a b c ⟨f₁, h₁⟩ ⟨f₂, h₂⟩, ⟨f₁ * f₂, h₂ ▸ h₁ ▸ (mul_assoc _ _ _).symm⟩}
instance : has_dvd (associates α) := ⟨(≤)⟩
@[simp] lemma mk_one : associates.mk (1 : α) = 1 := rfl
lemma mk_pow (a : α) (n : ℕ) : associates.mk (a ^ n) = (associates.mk a) ^ n :=
by induction n; simp [*, pow_succ, associates.mk_mul_mk.symm]
lemma dvd_eq_le : ((∣) : associates α → associates α → Prop) = (≤) := rfl
theorem prod_mk {p : multiset α} : (p.map associates.mk).prod = associates.mk p.prod :=
multiset.induction_on p (by simp; refl) $ assume a s ih, by simp [ih]; refl
theorem rel_associated_iff_map_eq_map {p q : multiset α} :
multiset.rel associated p q ↔ p.map associates.mk = q.map associates.mk :=
by rw [← multiset.rel_eq];
simp [multiset.rel_map_left, multiset.rel_map_right, mk_eq_mk_iff_associated]
theorem mul_eq_one_iff {x y : associates α} : x * y = 1 ↔ (x = 1 ∧ y = 1) :=
iff.intro
(quotient.induction_on₂ x y $ assume a b h,
have a * b ~ᵤ 1, from quotient.exact h,
⟨quotient.sound $ associated_one_of_associated_mul_one this,
quotient.sound $ associated_one_of_associated_mul_one $ by rwa [mul_comm] at this⟩)
(by simp {contextual := tt})
theorem prod_eq_one_iff {p : multiset (associates α)} :
p.prod = 1 ↔ (∀a ∈ p, (a:associates α) = 1) :=
multiset.induction_on p
(by simp)
(by simp [mul_eq_one_iff, or_imp_distrib, forall_and_distrib] {contextual := tt})
theorem coe_unit_eq_one : ∀u:units (associates α), (u : associates α) = 1
| ⟨u, v, huv, hvu⟩ := by rw [mul_eq_one_iff] at huv; exact huv.1
theorem is_unit_iff_eq_one (a : associates α) : is_unit a ↔ a = 1 :=
iff.intro
(assume ⟨u, h⟩, h.symm ▸ coe_unit_eq_one _)
(assume h, h.symm ▸ is_unit_one)
theorem is_unit_mk {a : α} : is_unit (associates.mk a) ↔ is_unit a :=
calc is_unit (associates.mk a) ↔ a ~ᵤ 1 :
by rw [is_unit_iff_eq_one, one_eq_mk_one, mk_eq_mk_iff_associated]
... ↔ is_unit a : associated_one_iff_is_unit
section order
theorem mul_mono {a b c d : associates α} (h₁ : a ≤ b) (h₂ : c ≤ d) :
a * c ≤ b * d :=
let ⟨x, hx⟩ := h₁, ⟨y, hy⟩ := h₂ in
⟨x * y, by simp [hx.symm, hy.symm, mul_comm, mul_assoc, mul_left_comm]⟩
theorem one_le {a : associates α} : 1 ≤ a :=
⟨a, one_mul a⟩
theorem prod_le_prod {p q : multiset (associates α)} (h : p ≤ q) : p.prod ≤ q.prod :=
begin
haveI := classical.dec_eq (associates α),
haveI := classical.dec_eq α,
suffices : p.prod ≤ (p + (q - p)).prod, { rwa [multiset.add_sub_of_le h] at this },
suffices : p.prod * 1 ≤ p.prod * (q - p).prod, { simpa },
exact mul_mono (le_refl p.prod) one_le
end
theorem le_mul_right {a b : associates α} : a ≤ a * b := ⟨b, rfl⟩
theorem le_mul_left {a b : associates α} : a ≤ b * a :=
by rw [mul_comm]; exact le_mul_right
end order
end comm_monoid
instance [has_zero α] [monoid α] : has_zero (associates α) := ⟨⟦ 0 ⟧⟩
instance [has_zero α] [monoid α] : has_top (associates α) := ⟨0⟩
section comm_semiring
variables [comm_semiring α]
@[simp] theorem mk_zero_eq (a : α) : associates.mk a = 0 ↔ a = 0 :=
⟨assume h, (associated_zero_iff_eq_zero a).1 $ quotient.exact h, assume h, h.symm ▸ rfl⟩
@[simp] theorem mul_zero : ∀(a : associates α), a * 0 = 0 :=
by rintros ⟨a⟩; show associates.mk (a * 0) = associates.mk 0; rw [mul_zero]
@[simp] protected theorem zero_mul : ∀(a : associates α), 0 * a = 0 :=
by rintros ⟨a⟩; show associates.mk (0 * a) = associates.mk 0; rw [zero_mul]
theorem mk_eq_zero_iff_eq_zero {a : α} : associates.mk a = 0 ↔ a = 0 :=
calc associates.mk a = 0 ↔ (a ~ᵤ 0) : mk_eq_mk_iff_associated
... ↔ a = 0 : associated_zero_iff_eq_zero a
theorem dvd_of_mk_le_mk {a b : α} : associates.mk a ≤ associates.mk b → a ∣ b
| ⟨c', hc'⟩ := (quotient.induction_on c' $ assume c hc,
let ⟨d, hd⟩ := (quotient.exact hc).symm in
⟨(↑d⁻¹) * c,
calc b = (a * c) * ↑d⁻¹ : by rw [← hd, mul_assoc, units.mul_inv, mul_one]
... = a * (↑d⁻¹ * c) : by ac_refl⟩) hc'
theorem mk_le_mk_of_dvd {a b : α} : a ∣ b → associates.mk a ≤ associates.mk b :=
assume ⟨c, hc⟩, ⟨associates.mk c, by simp [hc]; refl⟩
theorem mk_le_mk_iff_dvd_iff {a b : α} : associates.mk a ≤ associates.mk b ↔ a ∣ b :=
iff.intro dvd_of_mk_le_mk mk_le_mk_of_dvd
def prime (p : associates α) : Prop := p ≠ 0 ∧ p ≠ 1 ∧ (∀a b, p ≤ a * b → p ≤ a ∨ p ≤ b)
lemma prime.ne_zero {p : associates α} (hp : prime p) : p ≠ 0 :=
hp.1
lemma prime.ne_one {p : associates α} (hp : prime p) : p ≠ 1 :=
hp.2.1
lemma prime.le_or_le {p : associates α} (hp : prime p) {a b : associates α} (h : p ≤ a * b) :
p ≤ a ∨ p ≤ b :=
hp.2.2 a b h
lemma exists_mem_multiset_le_of_prime {s : multiset (associates α)} {p : associates α}
(hp : prime p) :
p ≤ s.prod → ∃a∈s, p ≤ a :=
multiset.induction_on s (assume ⟨d, eq⟩, (hp.ne_one (mul_eq_one_iff.1 eq).1).elim) $
assume a s ih h,
have p ≤ a * s.prod, by simpa using h,
match hp.le_or_le this with
| or.inl h := ⟨a, multiset.mem_cons_self a s, h⟩
| or.inr h := let ⟨a, has, h⟩ := ih h in ⟨a, multiset.mem_cons_of_mem has, h⟩
end
lemma prime_mk (p : α) : prime (associates.mk p) ↔ _root_.prime p :=
begin
rw [associates.prime, _root_.prime, forall_associated],
transitivity,
{ apply and_congr, refl,
apply and_congr, refl,
apply forall_congr, assume a,
exact forall_associated },
apply and_congr,
{ rw [(≠), mk_zero_eq] },
apply and_congr,
{ rw [(≠), ← is_unit_iff_eq_one, is_unit_mk], },
apply forall_congr, assume a,
apply forall_congr, assume b,
rw [mk_mul_mk, mk_le_mk_iff_dvd_iff, mk_le_mk_iff_dvd_iff, mk_le_mk_iff_dvd_iff]
end
end comm_semiring
section integral_domain
variable [integral_domain α]
instance : partial_order (associates α) :=
{ le_antisymm := assume a' b',
quotient.induction_on₂ a' b' $ assume a b ⟨f₁', h₁⟩ ⟨f₂', h₂⟩,
(quotient.induction_on₂ f₁' f₂' $ assume f₁ f₂ h₁ h₂,
let ⟨c₁, h₁⟩ := quotient.exact h₁, ⟨c₂, h₂⟩ := quotient.exact h₂ in
quotient.sound $ associated_of_dvd_dvd
(h₁ ▸ dvd_mul_of_dvd_left (dvd_mul_right _ _) _)
(h₂ ▸ dvd_mul_of_dvd_left (dvd_mul_right _ _) _)) h₁ h₂
.. associates.preorder }
instance : order_bot (associates α) :=
{ bot := 1,
bot_le := assume a, one_le,
.. associates.partial_order }
instance : order_top (associates α) :=
{ top := 0,
le_top := assume a, ⟨0, mul_zero a⟩,
.. associates.partial_order }
theorem zero_ne_one : (0 : associates α) ≠ 1 :=
assume h,
have (0 : α) ~ᵤ 1, from quotient.exact h,
have (0 : α) = 1, from ((associated_zero_iff_eq_zero 1).1 this.symm).symm,
zero_ne_one this
theorem mul_eq_zero_iff {x y : associates α} : x * y = 0 ↔ x = 0 ∨ y = 0 :=
iff.intro
(quotient.induction_on₂ x y $ assume a b h,
have a * b = 0, from (associated_zero_iff_eq_zero _).1 (quotient.exact h),
have a = 0 ∨ b = 0, from mul_eq_zero_iff_eq_zero_or_eq_zero.1 this,
this.imp (assume h, h.symm ▸ rfl) (assume h, h.symm ▸ rfl))
(by simp [or_imp_distrib] {contextual := tt})
theorem prod_eq_zero_iff {s : multiset (associates α)} :
s.prod = 0 ↔ (0 : associates α) ∈ s :=
multiset.induction_on s (by simp; exact zero_ne_one.symm) $
assume a s, by simp [mul_eq_zero_iff, @eq_comm _ 0 a] {contextual := tt}
theorem irreducible_mk_iff (a : α) : irreducible (associates.mk a) ↔ irreducible a :=
begin
simp [irreducible, is_unit_mk],
apply and_congr iff.rfl,
split,
{ assume h x y eq,
have : is_unit (associates.mk x) ∨ is_unit (associates.mk y),
from h _ _ (by rw [eq]; refl),
simpa [is_unit_mk] },
{ refine assume h x y, quotient.induction_on₂ x y (assume x y eq, _),
rcases quotient.exact eq.symm with ⟨u, eq⟩,
have : a = x * (y * u), by rwa [mul_assoc, eq_comm] at eq,
show is_unit (associates.mk x) ∨ is_unit (associates.mk y),
simpa [is_unit_mk] using h _ _ this }
end
lemma eq_of_mul_eq_mul_left :
∀(a b c : associates α), a ≠ 0 → a * b = a * c → b = c :=
begin
rintros ⟨a⟩ ⟨b⟩ ⟨c⟩ ha h,
rcases quotient.exact' h with ⟨u, hu⟩,
have hu : a * (b * ↑u) = a * c, { rwa [← mul_assoc] },
exact quotient.sound' ⟨u, eq_of_mul_eq_mul_left (mt (mk_zero_eq a).2 ha) hu⟩
end
lemma le_of_mul_le_mul_left (a b c : associates α) (ha : a ≠ 0) :
a * b ≤ a * c → b ≤ c
| ⟨d, hd⟩ := ⟨d, eq_of_mul_eq_mul_left a _ _ ha $ by rwa ← mul_assoc⟩
lemma one_or_eq_of_le_of_prime :
∀(p m : associates α), prime p → m ≤ p → (m = 1 ∨ m = p)
| _ m ⟨hp0, hp1, h⟩ ⟨d, rfl⟩ :=
match h m d (le_refl _) with
| or.inl h := classical.by_cases (assume : m = 0, by simp [this]) $
assume : m ≠ 0,
have m * d ≤ m * 1, by simpa using h,
have d ≤ 1, from associates.le_of_mul_le_mul_left m d 1 ‹m ≠ 0› this,
have d = 1, from bot_unique this,
by simp [this]
| or.inr h := classical.by_cases (assume : d = 0, by simp [this] at hp0; contradiction) $
assume : d ≠ 0,
have d * m ≤ d * 1, by simpa [mul_comm] using h,
or.inl $ bot_unique $ associates.le_of_mul_le_mul_left d m 1 ‹d ≠ 0› this
end
end integral_domain
end associates
|
983427f055fa9bc69150d3e7d2d9c403c75e7a08
|
2bafba05c98c1107866b39609d15e849a4ca2bb8
|
/src/week_8/ideas/Part_D_boundary_map.lean
|
393368d1a95a52b6bfc8e41d0c019e498ac62be0
|
[
"Apache-2.0"
] |
permissive
|
ImperialCollegeLondon/formalising-mathematics
|
b54c83c94b5c315024ff09997fcd6b303892a749
|
7cf1d51c27e2038d2804561d63c74711924044a1
|
refs/heads/master
| 1,651,267,046,302
| 1,638,888,459,000
| 1,638,888,459,000
| 331,592,375
| 284
| 24
|
Apache-2.0
| 1,669,593,705,000
| 1,611,224,849,000
|
Lean
|
UTF-8
|
Lean
| false
| false
| 3,180
|
lean
|
import week_8.ideas.Part_C_H1
/-
# Boundary maps
If 0 → A → B → C → 0 is exact, we want
a boundary map `H0 G C →+ H1 G A`
We're going to use the axiom of choice in our definition.
Whenever we invoke the axiom of choice we are using something
noncomputable, so it's important that we make a proper API
for the object we construct.
-/
-- missing?
section missing
variables {A B : Type*} [group A] [group B]
(f : A →* B) (a1 a2 : A)
@[to_additive] lemma monoid_hom.map_div (a1 a2 : A) :
f (a1 / a2) = f a1 / f a2 :=
by simp [div_eq_mul_inv]
@[simp, to_additive] lemma group.div_self (a : A) : a / a = 1 :=
by simp [div_eq_mul_inv]
@[simp, to_additive] lemma group.div_eq_one_iff (a1 a2 : A) : a1 / a2 = 1 ↔ a1 = a2 :=
⟨by simp [div_eq_mul_inv, mul_eq_one_iff_eq_inv], by {rintro rfl, simp}⟩
@[to_additive] lemma monoid_hom.div_mem_ker (f : A →* B) (a1 a2 : A) :
a1 / a2 ∈ f.ker ↔ f a1 = f a2 :=
begin
rw monoid_hom.mem_ker,
rw f.map_div,
rw group.div_eq_one_iff,
end
end missing
namespace boundary_map
variables {G M N P : Type} [monoid G]
[add_comm_group M] [distrib_mul_action G M]
[add_comm_group N] [distrib_mul_action G N]
[add_comm_group P] [distrib_mul_action G P]
{φ : M →+[G] N} {ψ : N →+[G] P} (hse : is_short_exact φ ψ)
include hse
noncomputable def raw_boundary_function : H0 G P → (G → M) :=
λ p g, hse.inverse_φ (g • (hse.inverse_ψ p) - hse.inverse_ψ p)
begin
rw hse.exact_set,
simp [hse.inverse_ψ_spec, p.spec],
end
lemma raw_boundary_function.is_cocycle
{p : H0 G P} : is_cocycle (raw_boundary_function hse p) :=
begin
intros g h,
unfold raw_boundary_function,
apply hse.injective,
-- should `smul_sub` be a `simp` lemma?
simp [mul_smul, smul_sub],
end
noncomputable def delta : H0 G P →+ H1 G M :=
{ to_fun := λ p, Z1.quotient
{ to_fun := raw_boundary_function hse p,
is_cocycle' := raw_boundary_function.is_cocycle hse },
map_zero' := begin
rw ← add_monoid_hom.mem_ker,
rw H1.ker_quotient,
simp [raw_boundary_function],
refine ⟨hse.inverse_φ (hse.inverse_ψ 0) _, _⟩,
{ rw hse.exact_set,
rw hse.inverse_ψ_spec },
ext g,
simp,
apply hse.injective,
simp [hse.inverse_φ_spec],
end,
map_add' := begin
intros p q,
rw ← add_monoid_hom.map_add,
rw ← add_monoid_hom.sub_mem_ker,
rw H1.ker_quotient,
have crucial :
∃ m : M, φ m = hse.inverse_ψ (↑p + ↑q) - hse.inverse_ψ p - hse.inverse_ψ q,
{ simp [hse.exact_set] },
refine ⟨hse.inverse_φ _ crucial, _⟩,
ext g,
simp [cochain_map, Z1.coe_add, raw_boundary_function],
apply hse.injective,
simp [smul_sub],
abel,
end }
/-
todo
In Part D of this week's workshop we will define
a boundary map `H0 G C →+ H1 H A` coming from a short
exact sequence of `G`-modules. In this definition we make
a choice of sign ("do we use `g b - b` or `b - g b`?").
The final boss of this course
is verifying the first seven terms of the long exact sequence
of group cohomology associated to a short exact sequence of
G-modules.
TODO
boundary map API
7 term exact sequnce
inf-res
-/
end boundary_map
|
a18f0c4baae2e916767741c1cc82c3f3c0f79fa4
|
fa02ed5a3c9c0adee3c26887a16855e7841c668b
|
/counterexamples/cyclotomic_105.lean
|
1bddc4c4f722470beee6db627355c3acbcbfbd4a
|
[
"Apache-2.0"
] |
permissive
|
jjgarzella/mathlib
|
96a345378c4e0bf26cf604aed84f90329e4896a2
|
395d8716c3ad03747059d482090e2bb97db612c8
|
refs/heads/master
| 1,686,480,124,379
| 1,625,163,323,000
| 1,625,163,323,000
| 281,190,421
| 2
| 0
|
Apache-2.0
| 1,595,268,170,000
| 1,595,268,169,000
| null |
UTF-8
|
Lean
| false
| false
| 3,956
|
lean
|
/-
Copyright (c) 2021 Riccardo Brasca. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Riccardo Brasca
-/
import ring_theory.polynomial.cyclotomic
/-!
# Not all coefficients of cyclotomic polynomials are -1, 0, or 1
We show that not all coefficients of cyclotomic polynomials are equal to `0`, `-1` or `1`, in the
theorem `not_forall_coeff_cyclotomic_neg_one_zero_one`. We prove this with the counterexample
`coeff_cyclotomic_105 : coeff (cyclotomic 105 ℤ) 7 = -2`.
-/
section computation
lemma prime_3 : nat.prime 3 := by norm_num
lemma prime_5 : nat.prime 5 := by norm_num
lemma prime_7 : nat.prime 7 := by norm_num
lemma proper_divisors_15 : nat.proper_divisors 15 = {1, 3, 5} := rfl
lemma proper_divisors_21 : nat.proper_divisors 21 = {1, 3, 7} := rfl
lemma proper_divisors_35 : nat.proper_divisors 35 = {1, 5, 7} := rfl
lemma proper_divisors_105 : nat.proper_divisors 105 = {1, 3, 5, 7, 15, 21, 35} := rfl
end computation
open polynomial
lemma cyclotomic_3 : cyclotomic 3 ℤ = 1 + X + X ^ 2 :=
begin
refine ((eq_cyclotomic_iff (show 0 < 3, by norm_num) _).2 _).symm,
rw nat.prime.proper_divisors prime_3,
simp only [finset.prod_singleton, cyclotomic_one],
ring
end
lemma cyclotomic_5 : cyclotomic 5 ℤ = 1 + X + X ^ 2 + X ^ 3 + X ^ 4 :=
begin
refine ((eq_cyclotomic_iff (nat.prime.pos prime_5) _).2 _).symm,
rw nat.prime.proper_divisors prime_5,
simp only [finset.prod_singleton, cyclotomic_one],
ring
end
lemma cyclotomic_7 : cyclotomic 7 ℤ = 1 + X + X ^ 2 + X ^ 3 + X ^ 4 + X ^ 5 + X ^ 6 :=
begin
refine ((eq_cyclotomic_iff (nat.prime.pos prime_7) _).2 _).symm,
rw nat.prime.proper_divisors prime_7,
simp only [finset.prod_singleton, cyclotomic_one],
ring
end
lemma cyclotomic_15 : cyclotomic 15 ℤ = 1 - X + X ^ 3 - X ^ 4 + X ^ 5 - X ^ 7 + X ^ 8 :=
begin
refine ((eq_cyclotomic_iff (show 0 < 15, by norm_num) _).2 _).symm,
rw [proper_divisors_15, finset.prod_insert _, finset.prod_insert _, finset.prod_singleton,
cyclotomic_one, cyclotomic_3, cyclotomic_5],
ring,
repeat { norm_num }
end
lemma cyclotomic_21 : cyclotomic 21 ℤ =
1 - X + X ^ 3 - X ^ 4 + X ^ 6 - X ^ 8 + X ^ 9 - X ^ 11 + X ^ 12 :=
begin
refine ((eq_cyclotomic_iff (show 0 < 21, by norm_num) _).2 _).symm,
rw [proper_divisors_21, finset.prod_insert _, finset.prod_insert _, finset.prod_singleton,
cyclotomic_one, cyclotomic_3, cyclotomic_7],
ring,
repeat { norm_num }
end
lemma cyclotomic_35 : cyclotomic 35 ℤ =
1 - X + X ^ 5 - X ^ 6 + X ^ 7 - X ^ 8 + X ^ 10 - X ^ 11 + X ^ 12 - X ^ 13 + X ^ 14 - X ^ 16 +
X ^ 17 - X ^ 18 + X ^ 19 - X ^ 23 + X ^ 24 :=
begin
refine ((eq_cyclotomic_iff (show 0 < 35, by norm_num) _).2 _).symm,
rw [proper_divisors_35, finset.prod_insert _, finset.prod_insert _, finset.prod_singleton,
cyclotomic_one, cyclotomic_5, cyclotomic_7],
ring,
repeat { norm_num }
end
lemma cyclotomic_105 : cyclotomic 105 ℤ =
1 + X + X ^ 2 - X ^ 5 - X ^ 6 - 2 * X ^ 7 - X ^ 8 - X ^ 9 + X ^ 12 + X ^ 13 + X ^ 14 + X ^ 15
+ X ^ 16 + X ^ 17 - X ^ 20 - X ^ 22 - X ^ 24 - X ^ 26 - X ^ 28 + X ^ 31 + X ^ 32 + X ^ 33 +
X ^ 34 + X ^ 35 + X ^ 36 - X ^ 39 - X ^ 40 - 2 * X ^ 41 - X ^ 42 - X ^ 43 + X ^ 46 + X ^ 47 +
X ^ 48 :=
begin
refine ((eq_cyclotomic_iff (show 0 < 105, by norm_num) _).2 _).symm,
rw proper_divisors_105,
repeat {rw finset.prod_insert _},
rw [finset.prod_singleton, cyclotomic_one, cyclotomic_3, cyclotomic_5, cyclotomic_7,
cyclotomic_15, cyclotomic_21, cyclotomic_35],
ring,
repeat { norm_num }
end
lemma coeff_cyclotomic_105 : coeff (cyclotomic 105 ℤ) 7 = -2 :=
begin
simp [cyclotomic_105, coeff_X_pow, coeff_one, coeff_X_of_ne_one, coeff_bit0_mul, coeff_bit1_mul]
end
lemma not_forall_coeff_cyclotomic_neg_one_zero_one :
¬∀ n i, coeff (cyclotomic n ℤ) i ∈ ({-1, 0, 1} : set ℤ) :=
begin
intro h,
replace h := h 105 7,
rw coeff_cyclotomic_105 at h,
norm_num at h
end
|
530701fb81490a16b8b2637de3fb7bfd4a2cb1a7
|
b3fced0f3ff82d577384fe81653e47df68bb2fa1
|
/src/topology/algebra/open_subgroup.lean
|
acbb437fc2664bd6bbaa41db99d14849a5ae3de0
|
[
"Apache-2.0"
] |
permissive
|
ratmice/mathlib
|
93b251ef5df08b6fd55074650ff47fdcc41a4c75
|
3a948a6a4cd5968d60e15ed914b1ad2f4423af8d
|
refs/heads/master
| 1,599,240,104,318
| 1,572,981,183,000
| 1,572,981,183,000
| 219,830,178
| 0
| 0
|
Apache-2.0
| 1,572,980,897,000
| 1,572,980,896,000
| null |
UTF-8
|
Lean
| false
| false
| 5,928
|
lean
|
import order.filter.lift
import linear_algebra.basic
import topology.opens topology.algebra.ring
section
open topological_space
variables (G : Type*) [group G] [topological_space G]
/-- The type of open subgroups of a topological group. -/
@[to_additive open_add_subgroup]
def open_subgroup := { U : set G // is_open U ∧ is_subgroup U }
@[to_additive]
instance open_subgroup.has_coe :
has_coe (open_subgroup G) (opens G) := ⟨λ U, ⟨U.1, U.2.1⟩⟩
end
-- Tell Lean that `open_add_subgroup` is a namespace
namespace open_add_subgroup
end open_add_subgroup
namespace open_subgroup
open function lattice topological_space
variables {G : Type*} [group G] [topological_space G]
variables {U V : open_subgroup G}
@[to_additive]
instance : has_mem G (open_subgroup G) := ⟨λ g U, g ∈ (U : set G)⟩
@[to_additive]
lemma ext : (U = V) ↔ ((U : set G) = V) :=
by cases U; cases V; split; intro h; try {congr}; assumption
@[extensionality, to_additive]
lemma ext' (h : (U : set G) = V) : (U = V) :=
ext.mpr h
@[to_additive]
lemma coe_injective : injective (λ U : open_subgroup G, (U : set G)) :=
λ U V h, ext' h
@[to_additive is_add_subgroup]
instance : is_subgroup (U : set G) := U.2.2
variable (U)
@[to_additive]
protected lemma is_open : is_open (U : set G) := U.2.1
@[to_additive]
protected lemma one_mem : (1 : G) ∈ U := is_submonoid.one_mem (U : set G)
@[to_additive]
protected lemma inv_mem {g : G} (h : g ∈ U) : g⁻¹ ∈ U :=
@is_subgroup.inv_mem G _ U _ g h
@[to_additive]
protected lemma mul_mem {g₁ g₂ : G} (h₁ : g₁ ∈ U) (h₂ : g₂ ∈ U) : g₁ * g₂ ∈ U :=
@is_submonoid.mul_mem G _ U _ g₁ g₂ h₁ h₂
@[to_additive]
lemma mem_nhds_one : (U : set G) ∈ nhds (1 : G) :=
mem_nhds_sets U.is_open U.one_mem
variable {U}
@[to_additive]
instance : inhabited (open_subgroup G) :=
{ default := ⟨set.univ, ⟨is_open_univ, by apply_instance⟩⟩ }
@[to_additive]
lemma is_open_of_nonempty_open_subset [topological_monoid G] {s : set G} [is_subgroup s]
(h : ∃ U : opens G, nonempty U ∧ (U : set G) ⊆ s) :
is_open s :=
begin
rw is_open_iff_forall_mem_open,
intros x hx,
rcases h with ⟨U, ⟨g, hg⟩, hU⟩,
use (λ y, y * (x⁻¹ * g)) ⁻¹' U,
split,
{ intros u hu,
erw set.mem_preimage at hu,
replace hu := hU hu,
replace hg := hU hg,
have : (x⁻¹ * g)⁻¹ ∈ s,
{ simp [*, is_subgroup.inv_mem, is_submonoid.mul_mem], },
convert is_submonoid.mul_mem hu this, simp [mul_assoc] },
split,
{ apply continuous_mul continuous_id continuous_const,
{ exact U.property },
{ apply_instance } },
{ erw set.mem_preimage,
convert hg,
rw [← mul_assoc, mul_right_inv, one_mul] }
end
@[to_additive is_open_of_open_add_subgroup]
lemma is_open_of_open_subgroup [topological_monoid G] {s : set G} [is_subgroup s]
(h : ∃ U : open_subgroup G, (U : set G) ⊆ s) : is_open s :=
is_open_of_nonempty_open_subset $ let ⟨U, hU⟩ := h in ⟨U, ⟨⟨1, U.one_mem⟩⟩, hU⟩
@[to_additive]
lemma is_closed [topological_monoid G] (U : open_subgroup G) : is_closed (U : set G) :=
begin
show is_open (-(U : set G)),
rw is_open_iff_forall_mem_open,
intros x hx,
use (λ y, y * x⁻¹) ⁻¹' U,
split,
{ intros u hux,
erw set.mem_preimage at hux,
rw set.mem_compl_iff at hx ⊢,
intro hu, apply hx,
convert is_submonoid.mul_mem (is_subgroup.inv_mem hux) hu,
simp },
split,
{ exact (continuous_mul_right _) _ U.is_open },
{ simpa using is_submonoid.one_mem (U : set G) }
end
section
variables {H : Type*} [group H] [topological_space H]
@[to_additive]
def prod (U : open_subgroup G) (V : open_subgroup H) : open_subgroup (G × H) :=
⟨(U : set G).prod (V : set H), is_open_prod U.is_open V.is_open, by apply_instance⟩
end
@[to_additive]
instance : partial_order (open_subgroup G) := partial_order.lift _ coe_injective (by apply_instance)
@[to_additive]
instance : semilattice_inf_top (open_subgroup G) :=
{ inf := λ U V, ⟨(U : set G) ∩ V, is_open_inter U.is_open V.is_open, by apply_instance⟩,
inf_le_left := λ U V, set.inter_subset_left _ _,
inf_le_right := λ U V, set.inter_subset_right _ _,
le_inf := λ U V W hV hW, set.subset_inter hV hW,
top := default _,
le_top := λ U, set.subset_univ _,
..open_subgroup.partial_order }
@[to_additive]
instance [topological_monoid G] : semilattice_sup_top (open_subgroup G) :=
{ sup := λ U V,
{ val := group.closure ((U : set G) ∪ V),
property :=
begin
haveI subgrp := _, refine ⟨_, subgrp⟩,
{ refine is_open_of_open_subgroup _,
exact ⟨U, set.subset.trans (set.subset_union_left _ _) group.subset_closure⟩ },
{ apply_instance }
end },
le_sup_left := λ U V, set.subset.trans (set.subset_union_left _ _) group.subset_closure,
le_sup_right := λ U V, set.subset.trans (set.subset_union_right _ _) group.subset_closure,
sup_le := λ U V W hU hV, group.closure_subset $ set.union_subset hU hV,
..open_subgroup.lattice.semilattice_inf_top }
@[simp, to_additive] lemma coe_inf : (↑(U ⊓ V) : set G) = (U : set G) ∩ V := rfl
@[to_additive] lemma le_iff : U ≤ V ↔ (U : set G) ⊆ V := iff.rfl
end open_subgroup
namespace submodule
open open_add_subgroup
variables {R : Type*} {M : Type*} [comm_ring R]
variables [add_comm_group M] [topological_space M] [topological_add_group M] [module R M]
lemma is_open_of_open_submodule {P : submodule R M}
(h : ∃ U : submodule R M, is_open (U : set M) ∧ U ≤ P) : is_open (P : set M) :=
let ⟨U, h₁, h₂⟩ := h in is_open_of_open_add_subgroup ⟨⟨U, h₁, by apply_instance⟩, h₂⟩
end submodule
namespace ideal
variables {R : Type*} [comm_ring R]
variables [topological_space R] [topological_ring R]
lemma is_open_of_open_subideal {I : ideal R}
(h : ∃ U : ideal R, is_open (U : set R) ∧ U ≤ I) : is_open (I : set R) :=
submodule.is_open_of_open_submodule h
end ideal
|
1fa59f766b1fc066fbd043a19743b939328c08be
|
9dc8cecdf3c4634764a18254e94d43da07142918
|
/src/group_theory/perm/basic.lean
|
02f99f3bce4249a4ebdb865d4b0645edd62ebdee
|
[
"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
| 15,762
|
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
-/
import algebra.group.pi
import algebra.group_power.lemmas
import logic.function.iterate
/-!
# The group of permutations (self-equivalences) of a type `α`
This file defines the `group` structure on `equiv.perm α`.
-/
universes u v
namespace equiv
variables {α : Type u} {β : Type v}
namespace perm
instance perm_group : group (perm α) :=
{ mul := λ f g, equiv.trans g f,
one := equiv.refl α,
inv := equiv.symm,
mul_assoc := λ f g h, (trans_assoc _ _ _).symm,
one_mul := trans_refl,
mul_one := refl_trans,
mul_left_inv := self_trans_symm }
theorem mul_apply (f g : perm α) (x) : (f * g) x = f (g x) :=
equiv.trans_apply _ _ _
theorem one_apply (x) : (1 : perm α) x = x := rfl
@[simp] lemma inv_apply_self (f : perm α) (x) : f⁻¹ (f x) = x := f.symm_apply_apply x
@[simp] lemma apply_inv_self (f : perm α) (x) : f (f⁻¹ x) = x := f.apply_symm_apply x
lemma one_def : (1 : perm α) = equiv.refl α := rfl
lemma mul_def (f g : perm α) : f * g = g.trans f := rfl
lemma inv_def (f : perm α) : f⁻¹ = f.symm := rfl
@[simp] lemma coe_mul (f g : perm α) : ⇑(f * g) = f ∘ g := rfl
@[simp] lemma coe_one : ⇑(1 : perm α) = id := rfl
lemma eq_inv_iff_eq {f : perm α} {x y : α} : x = f⁻¹ y ↔ f x = y := f.eq_symm_apply
lemma inv_eq_iff_eq {f : perm α} {x y : α} : f⁻¹ x = y ↔ x = f y := f.symm_apply_eq
lemma zpow_apply_comm {α : Type*} (σ : perm α) (m n : ℤ) {x : α} :
(σ ^ m) ((σ ^ n) x) = (σ ^ n) ((σ ^ m) x) :=
by rw [←equiv.perm.mul_apply, ←equiv.perm.mul_apply, zpow_mul_comm]
@[simp] lemma iterate_eq_pow (f : perm α) : ∀ n, f^[n] = ⇑(f ^ n)
| 0 := rfl
| (n + 1) := by { rw [function.iterate_succ, pow_add, iterate_eq_pow], refl }
/-! Lemmas about mixing `perm` with `equiv`. Because we have multiple ways to express
`equiv.refl`, `equiv.symm`, and `equiv.trans`, we want simp lemmas for every combination.
The assumption made here is that if you're using the group structure, you want to preserve it after
simp. -/
@[simp] lemma trans_one {α : Sort*} {β : Type*} (e : α ≃ β) : e.trans (1 : perm β) = e :=
equiv.trans_refl e
@[simp] lemma mul_refl (e : perm α) : e * equiv.refl α = e := equiv.trans_refl e
@[simp] lemma one_symm : (1 : perm α).symm = 1 := equiv.refl_symm
@[simp] lemma refl_inv : (equiv.refl α : perm α)⁻¹ = 1 := equiv.refl_symm
@[simp] lemma one_trans {α : Type*} {β : Sort*} (e : α ≃ β) : (1 : perm α).trans e = e :=
equiv.refl_trans e
@[simp] lemma refl_mul (e : perm α) : equiv.refl α * e = e := equiv.refl_trans e
@[simp] lemma inv_trans_self (e : perm α) : e⁻¹.trans e = 1 := equiv.symm_trans_self e
@[simp] lemma mul_symm (e : perm α) : e * e.symm = 1 := equiv.symm_trans_self e
@[simp] lemma self_trans_inv (e : perm α) : e.trans e⁻¹ = 1 := equiv.self_trans_symm e
@[simp] lemma symm_mul (e : perm α) : e.symm * e = 1 := equiv.self_trans_symm e
/-! Lemmas about `equiv.perm.sum_congr` re-expressed via the group structure. -/
@[simp] lemma sum_congr_mul {α β : Type*} (e : perm α) (f : perm β) (g : perm α) (h : perm β) :
sum_congr e f * sum_congr g h = sum_congr (e * g) (f * h) :=
sum_congr_trans g h e f
@[simp] lemma sum_congr_inv {α β : Type*} (e : perm α) (f : perm β) :
(sum_congr e f)⁻¹ = sum_congr e⁻¹ f⁻¹ :=
sum_congr_symm e f
@[simp] lemma sum_congr_one {α β : Type*} :
sum_congr (1 : perm α) (1 : perm β) = 1 :=
sum_congr_refl
/-- `equiv.perm.sum_congr` as a `monoid_hom`, with its two arguments bundled into a single `prod`.
This is particularly useful for its `monoid_hom.range` projection, which is the subgroup of
permutations which do not exchange elements between `α` and `β`. -/
@[simps]
def sum_congr_hom (α β : Type*) :
perm α × perm β →* perm (α ⊕ β) :=
{ to_fun := λ a, sum_congr a.1 a.2,
map_one' := sum_congr_one,
map_mul' := λ a b, (sum_congr_mul _ _ _ _).symm}
lemma sum_congr_hom_injective {α β : Type*} :
function.injective (sum_congr_hom α β) :=
begin
rintros ⟨⟩ ⟨⟩ h,
rw prod.mk.inj_iff,
split; ext i,
{ simpa using equiv.congr_fun h (sum.inl i), },
{ simpa using equiv.congr_fun h (sum.inr i), },
end
@[simp] lemma sum_congr_swap_one {α β : Type*} [decidable_eq α] [decidable_eq β] (i j : α) :
sum_congr (equiv.swap i j) (1 : perm β) = equiv.swap (sum.inl i) (sum.inl j) :=
sum_congr_swap_refl i j
@[simp] lemma sum_congr_one_swap {α β : Type*} [decidable_eq α] [decidable_eq β] (i j : β) :
sum_congr (1 : perm α) (equiv.swap i j) = equiv.swap (sum.inr i) (sum.inr j) :=
sum_congr_refl_swap i j
/-! Lemmas about `equiv.perm.sigma_congr_right` re-expressed via the group structure. -/
@[simp] lemma sigma_congr_right_mul {α : Type*} {β : α → Type*}
(F : Π a, perm (β a)) (G : Π a, perm (β a)) :
sigma_congr_right F * sigma_congr_right G = sigma_congr_right (F * G) :=
sigma_congr_right_trans G F
@[simp] lemma sigma_congr_right_inv {α : Type*} {β : α → Type*} (F : Π a, perm (β a)) :
(sigma_congr_right F)⁻¹ = sigma_congr_right (λ a, (F a)⁻¹) :=
sigma_congr_right_symm F
@[simp] lemma sigma_congr_right_one {α : Type*} {β : α → Type*} :
(sigma_congr_right (1 : Π a, equiv.perm $ β a)) = 1 :=
sigma_congr_right_refl
/-- `equiv.perm.sigma_congr_right` as a `monoid_hom`.
This is particularly useful for its `monoid_hom.range` projection, which is the subgroup of
permutations which do not exchange elements between fibers. -/
@[simps]
def sigma_congr_right_hom {α : Type*} (β : α → Type*) :
(Π a, perm (β a)) →* perm (Σ a, β a) :=
{ to_fun := sigma_congr_right,
map_one' := sigma_congr_right_one,
map_mul' := λ a b, (sigma_congr_right_mul _ _).symm }
lemma sigma_congr_right_hom_injective {α : Type*} {β : α → Type*} :
function.injective (sigma_congr_right_hom β) :=
begin
intros x y h,
ext a b,
simpa using equiv.congr_fun h ⟨a, b⟩,
end
/-- `equiv.perm.subtype_congr` as a `monoid_hom`. -/
@[simps] def subtype_congr_hom (p : α → Prop) [decidable_pred p] :
(perm {a // p a}) × (perm {a // ¬ p a}) →* perm α :=
{ to_fun := λ pair, perm.subtype_congr pair.fst pair.snd,
map_one' := perm.subtype_congr.refl,
map_mul' := λ _ _, (perm.subtype_congr.trans _ _ _ _).symm }
lemma subtype_congr_hom_injective (p : α → Prop) [decidable_pred p] :
function.injective (subtype_congr_hom p) :=
begin
rintros ⟨⟩ ⟨⟩ h,
rw prod.mk.inj_iff,
split;
ext i;
simpa using equiv.congr_fun h i
end
/-- If `e` is also a permutation, we can write `perm_congr`
completely in terms of the group structure. -/
@[simp] lemma perm_congr_eq_mul (e p : perm α) :
e.perm_congr p = e * p * e⁻¹ := rfl
section extend_domain
/-! Lemmas about `equiv.perm.extend_domain` re-expressed via the group structure. -/
variables (e : perm α) {p : β → Prop} [decidable_pred p] (f : α ≃ subtype p)
@[simp] lemma extend_domain_one : extend_domain 1 f = 1 :=
extend_domain_refl f
@[simp] lemma extend_domain_inv : (e.extend_domain f)⁻¹ = e⁻¹.extend_domain f := rfl
@[simp] lemma extend_domain_mul (e e' : perm α) :
(e.extend_domain f) * (e'.extend_domain f) = (e * e').extend_domain f :=
extend_domain_trans _ _ _
/-- `extend_domain` as a group homomorphism -/
@[simps] def extend_domain_hom : perm α →* perm β :=
{ to_fun := λ e, extend_domain e f,
map_one' := extend_domain_one f,
map_mul' := λ e e', (extend_domain_mul f e e').symm }
lemma extend_domain_hom_injective : function.injective (extend_domain_hom f) :=
(injective_iff_map_eq_one (extend_domain_hom f)).mpr (λ e he, ext (λ x, f.injective (subtype.ext
((extend_domain_apply_image e f x).symm.trans (ext_iff.mp he (f x))))))
@[simp] lemma extend_domain_eq_one_iff {e : perm α} {f : α ≃ subtype p} :
e.extend_domain f = 1 ↔ e = 1 :=
(injective_iff_map_eq_one' (extend_domain_hom f)).mp (extend_domain_hom_injective f) e
end extend_domain
/-- If the permutation `f` fixes the subtype `{x // p x}`, then this returns the permutation
on `{x // p x}` induced by `f`. -/
def subtype_perm (f : perm α) {p : α → Prop} (h : ∀ x, p x ↔ p (f x)) : perm {x // p x} :=
⟨λ x, ⟨f x, (h _).1 x.2⟩, λ x, ⟨f⁻¹ x, (h (f⁻¹ x)).2 $ by simpa using x.2⟩,
λ _, by simp only [perm.inv_apply_self, subtype.coe_eta, subtype.coe_mk],
λ _, by simp only [perm.apply_inv_self, subtype.coe_eta, subtype.coe_mk]⟩
@[simp] lemma subtype_perm_apply (f : perm α) {p : α → Prop} (h : ∀ x, p x ↔ p (f x))
(x : {x // p x}) : subtype_perm f h x = ⟨f x, (h _).1 x.2⟩ := rfl
@[simp] lemma subtype_perm_one (p : α → Prop) (h : ∀ x, p x ↔ p ((1 : perm α) x)) :
@subtype_perm α 1 p h = 1 :=
equiv.ext $ λ ⟨_, _⟩, rfl
/-- The inclusion map of permutations on a subtype of `α` into permutations of `α`,
fixing the other points. -/
def of_subtype {p : α → Prop} [decidable_pred p] : perm (subtype p) →* perm α :=
{ to_fun := λ f, extend_domain f (equiv.refl (subtype p)),
map_one' := equiv.perm.extend_domain_one _,
map_mul' := λ f g, (equiv.perm.extend_domain_mul _ f g).symm, }
lemma of_subtype_subtype_perm {f : perm α} {p : α → Prop} [decidable_pred p]
(h₁ : ∀ x, p x ↔ p (f x)) (h₂ : ∀ x, f x ≠ x → p x) :
of_subtype (subtype_perm f h₁) = f :=
equiv.ext $ λ x, begin
by_cases hx : p x,
{ exact (subtype_perm f h₁).extend_domain_apply_subtype _ hx, },
{ rw [of_subtype, monoid_hom.coe_mk, equiv.perm.extend_domain_apply_not_subtype],
{ exact not_not.mp (λ h, hx (h₂ x (ne.symm h))), },
{ exact hx, }, }
end
lemma of_subtype_apply_of_mem {p : α → Prop} [decidable_pred p]
(f : perm (subtype p)) {x : α} (hx : p x) :
of_subtype f x = f ⟨x, hx⟩ := extend_domain_apply_subtype f _ hx
@[simp] lemma of_subtype_apply_coe {p : α → Prop} [decidable_pred p]
(f : perm (subtype p)) (x : subtype p) :
of_subtype f x = f x :=
subtype.cases_on x $ λ _, of_subtype_apply_of_mem f
lemma of_subtype_apply_of_not_mem {p : α → Prop} [decidable_pred p]
(f : perm (subtype p)) {x : α} (hx : ¬ p x) :
of_subtype f x = x := extend_domain_apply_not_subtype f (equiv.refl (subtype p)) hx
lemma mem_iff_of_subtype_apply_mem {p : α → Prop} [decidable_pred p]
(f : perm (subtype p)) (x : α) :
p x ↔ p ((of_subtype f : α → α) x) :=
if h : p x then
by simpa only [h, true_iff, monoid_hom.coe_mk, of_subtype_apply_of_mem f h] using (f ⟨x, h⟩).2
else by simp [h, of_subtype_apply_of_not_mem f h]
@[simp] lemma subtype_perm_of_subtype {p : α → Prop} [decidable_pred p] (f : perm (subtype p)) :
subtype_perm (of_subtype f) (mem_iff_of_subtype_apply_mem f) = f :=
equiv.ext $ λ ⟨x, hx⟩,
subtype.coe_injective (of_subtype_apply_of_mem f hx)
@[simp] lemma default_perm {n : Type*} : (default : perm n) = 1 := rfl
/-- Permutations on a subtype are equivalent to permutations on the original type that fix pointwise
the rest. -/
@[simps] protected def subtype_equiv_subtype_perm (p : α → Prop) [decidable_pred p] :
perm (subtype p) ≃ {f : perm α // ∀ a, ¬p a → f a = a} :=
{ to_fun := λ f, ⟨f.of_subtype, λ a, f.of_subtype_apply_of_not_mem⟩,
inv_fun := λ f, (f : perm α).subtype_perm
(λ a, ⟨decidable.not_imp_not.1 $ λ hfa, (f.val.injective (f.prop _ hfa) ▸ hfa),
decidable.not_imp_not.1 $ λ ha hfa, ha $ f.prop a ha ▸ hfa⟩),
left_inv := equiv.perm.subtype_perm_of_subtype,
right_inv := λ f,
subtype.ext (equiv.perm.of_subtype_subtype_perm _ $ λ a, not.decidable_imp_symm $ f.prop a) }
lemma subtype_equiv_subtype_perm_apply_of_mem {α : Type*} {p : α → Prop}
[decidable_pred p] (f : perm (subtype p)) {a : α} (h : p a) :
perm.subtype_equiv_subtype_perm p f a = f ⟨a, h⟩ :=
f.of_subtype_apply_of_mem h
lemma subtype_equiv_subtype_perm_apply_of_not_mem {α : Type*} {p : α → Prop}
[decidable_pred p] (f : perm (subtype p)) {a : α} (h : ¬ p a) :
perm.subtype_equiv_subtype_perm p f a = a :=
f.of_subtype_apply_of_not_mem h
variables (e : perm α) (ι : α ↪ β)
open_locale classical
/-- Noncomputable version of `equiv.perm.via_fintype_embedding` that does not assume `fintype` -/
noncomputable def via_embedding : perm β :=
extend_domain e (of_injective ι.1 ι.2)
lemma via_embedding_apply (x : α) : e.via_embedding ι (ι x) = ι (e x) :=
extend_domain_apply_image e (of_injective ι.1 ι.2) x
lemma via_embedding_apply_of_not_mem (x : β) (hx : x ∉ _root_.set.range ι) :
e.via_embedding ι x = x :=
extend_domain_apply_not_subtype e (of_injective ι.1 ι.2) hx
/-- `via_embedding` as a group homomorphism -/
noncomputable def via_embedding_hom : perm α →* perm β:=
extend_domain_hom (of_injective ι.1 ι.2)
lemma via_embedding_hom_apply : via_embedding_hom ι e = via_embedding e ι := rfl
lemma via_embedding_hom_injective : function.injective (via_embedding_hom ι) :=
extend_domain_hom_injective (of_injective ι.1 ι.2)
end perm
section swap
variables [decidable_eq α]
@[simp] lemma swap_inv (x y : α) : (swap x y)⁻¹ = swap x y := rfl
@[simp] lemma swap_mul_self (i j : α) : swap i j * swap i j = 1 := swap_swap i j
lemma swap_mul_eq_mul_swap (f : perm α) (x y : α) : swap x y * f = f * swap (f⁻¹ x) (f⁻¹ y) :=
equiv.ext $ λ z, begin
simp only [perm.mul_apply, swap_apply_def],
split_ifs;
simp only [perm.apply_inv_self, *, perm.eq_inv_iff_eq, eq_self_iff_true, not_true] at *
end
lemma mul_swap_eq_swap_mul (f : perm α) (x y : α) : f * swap x y = swap (f x) (f y) * f :=
by rw [swap_mul_eq_mul_swap, perm.inv_apply_self, perm.inv_apply_self]
lemma swap_apply_apply (f : perm α) (x y : α) : swap (f x) (f y) = f * swap x y * f⁻¹ :=
by rw [mul_swap_eq_swap_mul, mul_inv_cancel_right]
/-- Left-multiplying a permutation with `swap i j` twice gives the original permutation.
This specialization of `swap_mul_self` is useful when using cosets of permutations.
-/
@[simp]
lemma swap_mul_self_mul (i j : α) (σ : perm α) : equiv.swap i j * (equiv.swap i j * σ) = σ :=
by rw [←mul_assoc, swap_mul_self, one_mul]
/-- Right-multiplying a permutation with `swap i j` twice gives the original permutation.
This specialization of `swap_mul_self` is useful when using cosets of permutations.
-/
@[simp]
lemma mul_swap_mul_self (i j : α) (σ : perm α) : (σ * equiv.swap i j) * equiv.swap i j = σ :=
by rw [mul_assoc, swap_mul_self, mul_one]
/-- A stronger version of `mul_right_injective` -/
@[simp]
lemma swap_mul_involutive (i j : α) : function.involutive ((*) (equiv.swap i j)) :=
swap_mul_self_mul i j
/-- A stronger version of `mul_left_injective` -/
@[simp]
lemma mul_swap_involutive (i j : α) : function.involutive (* (equiv.swap i j)) :=
mul_swap_mul_self i j
@[simp] lemma swap_eq_one_iff {i j : α} : swap i j = (1 : perm α) ↔ i = j :=
swap_eq_refl_iff
lemma swap_mul_eq_iff {i j : α} {σ : perm α} : swap i j * σ = σ ↔ i = j :=
⟨(assume h, have swap_id : swap i j = 1 := mul_right_cancel (trans h (one_mul σ).symm),
by {rw [←swap_apply_right i j, swap_id], refl}),
(assume h, by erw [h, swap_self, one_mul])⟩
lemma mul_swap_eq_iff {i j : α} {σ : perm α} : σ * swap i j = σ ↔ i = j :=
⟨(assume h, have swap_id : swap i j = 1 := mul_left_cancel (trans h (one_mul σ).symm),
by {rw [←swap_apply_right i j, swap_id], refl}),
(assume h, by erw [h, swap_self, mul_one])⟩
lemma swap_mul_swap_mul_swap {x y z : α} (hwz: x ≠ y) (hxz : x ≠ z) :
swap y z * swap x y * swap y z = swap z x :=
equiv.ext $ λ n, by { simp only [swap_apply_def, perm.mul_apply], split_ifs; cc }
end swap
end equiv
|
a9e8738357979e9c5136012e398e73da4e166fbd
|
432d948a4d3d242fdfb44b81c9e1b1baacd58617
|
/src/order/boolean_algebra.lean
|
9dfb8e92afd8f92d2977b243715832f26b1da533
|
[
"Apache-2.0"
] |
permissive
|
JLimperg/aesop3
|
306cc6570c556568897ed2e508c8869667252e8a
|
a4a116f650cc7403428e72bd2e2c4cda300fe03f
|
refs/heads/master
| 1,682,884,916,368
| 1,620,320,033,000
| 1,620,320,033,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 31,567
|
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, Bryan Gin-ge Chen
-/
import order.bounded_lattice
/-!
# (Generalized) Boolean algebras
A Boolean algebra is a bounded distributive lattice with a complement operator. Boolean algebras
generalize the (classical) logic of propositions and the lattice of subsets of a set.
Generalized Boolean algebras may be less familiar, but they are essentially Boolean algebras which
do not necessarily have a top element (`⊤`) (and hence not all elements may have complements). One
example in mathlib is `finset α`, the type of all finite subsets of an arbitrary
(not-necessarily-finite) type `α`.
`generalized_boolean_algebra α` is defined to be a distributive lattice with bottom (`⊥`) admitting
a *relative* complement operator, written using "set difference" notation as `x \ y` (`sdiff x y`).
For convenience, the `boolean_algebra` type class is defined to extend `generalized_boolean_algebra`
so that it is also bundled with a `\` operator.
(A terminological point: `x \ y` is the complement of `y` relative to the interval `[⊥, x]`. We do
not yet have relative complements for arbitrary intervals, as we do not even have lattice
intervals.)
## Main declarations
* `has_compl`: a type class for the complement operator
* `generalized_boolean_algebra`: a type class for generalized Boolean algebras
* `boolean_algebra.core`: a type class with the minimal assumptions for a Boolean algebras
* `boolean_algebra`: the main type class for Boolean algebras; it extends both
`generalized_boolean_algebra` and `boolean_algebra.core`. An instance of `boolean_algebra` can be
obtained from one of `boolean_algebra.core` using `boolean_algebra.of_core`.
* `boolean_algebra_Prop`: the Boolean algebra instance on `Prop`
## Implementation notes
The `sup_inf_sdiff` and `inf_inf_sdiff` axioms for the relative complement operator in
`generalized_boolean_algebra` are taken from
[Wikipedia](https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations).
[Stone's paper introducing generalized Boolean algebras][Stone1935] does not define a relative
complement operator `a \ b` for all `a`, `b`. Instead, the postulates there amount to an assumption
that for all `a, b : α` where `a ≤ b`, the equations `x ⊔ a = b` and `x ⊓ a = ⊥` have a solution
`x`. `disjoint.sdiff_unique` proves that this `x` is in fact `b \ a`.
## Notations
* `xᶜ` is notation for `compl x`
* `x \ y` is notation for `sdiff x y`.
## References
* <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations>
* [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935]
* [*Lattice Theory: Foundation*, George Grätzer][Gratzer2011]
## Tags
generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl
-/
set_option old_structure_cmd true
universes u v
variables {α : Type u} {w x y z : α}
/-!
### Generalized Boolean algebras
Some of the lemmas in this section are from:
* [*Lattice Theory: Foundation*, George Grätzer][Gratzer2011]
* <https://ncatlab.org/nlab/show/relative+complement>
* <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf>
-/
export has_sdiff (sdiff)
/-- A generalized Boolean algebra is a distributive lattice with `⊥` and a relative complement
operation `\` (called `sdiff`, after "set difference") satisfying `(a ⊓ b) ⊔ (a \ b) = a` and
`(a ⊓ b) ⊓ (a \ b) = b`, i.e. `a \ b` is the complement of `b` in `a`.
This is a generalization of Boolean algebras which applies to `finset α` for arbitrary
(not-necessarily-`fintype`) `α`. -/
class generalized_boolean_algebra (α : Type u) extends semilattice_sup_bot α, semilattice_inf_bot α,
distrib_lattice α, has_sdiff α :=
(sup_inf_sdiff : ∀a b:α, (a ⊓ b) ⊔ (a \ b) = a)
(inf_inf_sdiff : ∀a b:α, (a ⊓ b) ⊓ (a \ b) = ⊥)
-- We might want a `is_compl_of` predicate generalizing `is_compl`,
-- however we'd need another type class for lattices with bot, and all the API for that.
section generalized_boolean_algebra
variables [generalized_boolean_algebra α]
@[simp] theorem sup_inf_sdiff (x y : α) : (x ⊓ y) ⊔ (x \ y) = x :=
generalized_boolean_algebra.sup_inf_sdiff _ _
@[simp] theorem inf_inf_sdiff (x y : α) : (x ⊓ y) ⊓ (x \ y) = ⊥ :=
generalized_boolean_algebra.inf_inf_sdiff _ _
@[simp] theorem sup_sdiff_inf (x y : α) : (x \ y) ⊔ (x ⊓ y) = x :=
by rw [sup_comm, sup_inf_sdiff]
@[simp] theorem inf_sdiff_inf (x y : α) : (x \ y) ⊓ (x ⊓ y) = ⊥ :=
by rw [inf_comm, inf_inf_sdiff]
theorem disjoint_inf_sdiff : disjoint (x ⊓ y) (x \ y) := (inf_inf_sdiff x y).le
-- TODO: in distributive lattices, relative complements are unique when they exist
theorem sdiff_unique (s : (x ⊓ y) ⊔ z = x) (i : (x ⊓ y) ⊓ z = ⊥) : x \ y = z :=
begin
conv_rhs at s { rw [←sup_inf_sdiff x y, sup_comm] },
rw sup_comm at s,
conv_rhs at i { rw [←inf_inf_sdiff x y, inf_comm] },
rw inf_comm at i,
exact (eq_of_inf_eq_sup_eq i s).symm,
end
theorem sdiff_symm (hy : y ≤ x) (hz : z ≤ x) (H : x \ y = z) : x \ z = y :=
have hyi : x ⊓ y = y := inf_eq_right.2 hy,
have hzi : x ⊓ z = z := inf_eq_right.2 hz,
eq_of_inf_eq_sup_eq
(begin
have ixy := inf_inf_sdiff x y,
rw [H, hyi] at ixy,
have ixz := inf_inf_sdiff x z,
rwa [hzi, inf_comm, ←ixy] at ixz,
end)
(begin
have sxz := sup_inf_sdiff x z,
rw [hzi, sup_comm] at sxz,
rw sxz,
symmetry,
have sxy := sup_inf_sdiff x y,
rwa [H, hyi] at sxy,
end)
lemma sdiff_le : x \ y ≤ x :=
calc x \ y ≤ (x ⊓ y) ⊔ (x \ y) : le_sup_right
... = x : sup_inf_sdiff x y
@[simp] lemma bot_sdiff : ⊥ \ x = ⊥ := le_bot_iff.1 sdiff_le
lemma inf_sdiff_right : x ⊓ (x \ y) = x \ y := by rw [inf_of_le_right (@sdiff_le _ x y _)]
lemma inf_sdiff_left : (x \ y) ⊓ x = x \ y := by rw [inf_comm, inf_sdiff_right]
-- cf. `is_compl_top_bot`
@[simp] lemma sdiff_self : x \ x = ⊥ :=
by rw [←inf_inf_sdiff, inf_idem, inf_of_le_right (@sdiff_le _ x x _)]
@[simp] theorem sup_sdiff_self_right : x ⊔ (y \ x) = x ⊔ y :=
calc x ⊔ (y \ x) = (x ⊔ (x ⊓ y)) ⊔ (y \ x) : by rw sup_inf_self
... = x ⊔ ((y ⊓ x) ⊔ (y \ x)) : by ac_refl
... = x ⊔ y : by rw sup_inf_sdiff
@[simp] theorem sup_sdiff_self_left : (y \ x) ⊔ x = y ⊔ x :=
by rw [sup_comm, sup_sdiff_self_right, sup_comm]
lemma sup_sdiff_symm : x ⊔ (y \ x) = y ⊔ (x \ y) :=
by rw [sup_sdiff_self_right, sup_sdiff_self_right, sup_comm]
lemma sup_sdiff_of_le (h : x ≤ y) : x ⊔ (y \ x) = y :=
by conv_rhs { rw [←sup_inf_sdiff y x, inf_eq_right.2 h] }
@[simp] lemma sup_sdiff_left : x ⊔ (x \ y) = x := by { rw sup_eq_left, exact sdiff_le }
lemma sup_sdiff_right : (x \ y) ⊔ x = x := by rw [sup_comm, sup_sdiff_left]
@[simp] lemma sdiff_inf_sdiff : x \ y ⊓ (y \ x) = ⊥ :=
eq.symm $
calc ⊥ = (x ⊓ y) ⊓ (x \ y) : by rw inf_inf_sdiff
... = (x ⊓ (y ⊓ x ⊔ y \ x)) ⊓ (x \ y) : by rw sup_inf_sdiff
... = (x ⊓ (y ⊓ x) ⊔ x ⊓ (y \ x)) ⊓ (x \ y) : by rw inf_sup_left
... = (y ⊓ (x ⊓ x) ⊔ x ⊓ (y \ x)) ⊓ (x \ y) : by ac_refl
... = (y ⊓ x ⊔ x ⊓ (y \ x)) ⊓ (x \ y) : by rw inf_idem
... = (x ⊓ y ⊓ (x \ y)) ⊔ (x ⊓ (y \ x) ⊓ (x \ y)) : by rw [inf_sup_right, @inf_comm _ _ x y]
... = x ⊓ (y \ x) ⊓ (x \ y) : by rw [inf_inf_sdiff, bot_sup_eq]
... = x ⊓ (x \ y) ⊓ (y \ x) : by ac_refl
... = (x \ y) ⊓ (y \ x) : by rw inf_sdiff_right
lemma disjoint_sdiff_sdiff : disjoint (x \ y) (y \ x) := sdiff_inf_sdiff.le
theorem le_sup_sdiff : y ≤ x ⊔ (y \ x) :=
by { rw [sup_sdiff_self_right], exact le_sup_right }
theorem le_sdiff_sup : y ≤ (y \ x) ⊔ x :=
by { rw [sup_comm], exact le_sup_sdiff }
@[simp] theorem inf_sdiff_self_right : x ⊓ (y \ x) = ⊥ :=
calc x ⊓ (y \ x) = ((x ⊓ y) ⊔ (x \ y)) ⊓ (y \ x) : by rw sup_inf_sdiff
... = (x ⊓ y) ⊓ (y \ x) ⊔ (x \ y) ⊓ (y \ x) : by rw inf_sup_right
... = ⊥ : by rw [@inf_comm _ _ x y, inf_inf_sdiff, sdiff_inf_sdiff, bot_sup_eq]
@[simp] theorem inf_sdiff_self_left : (y \ x) ⊓ x = ⊥ := by rw [inf_comm, inf_sdiff_self_right]
theorem disjoint_sdiff : disjoint x (y \ x) := inf_sdiff_self_right.le
/- TODO: if we had a typeclass for distributive lattices with `⊥`, we could make an alternative
constructor for `generalized_boolean_algebra` using `disjoint x (y \ x)` and `x ⊔ (y \ x) = y` as
axioms. -/
theorem disjoint.sdiff_eq_of_sup_eq (hi : disjoint x z) (hs : x ⊔ z = y) : y \ x = z :=
have h : y ⊓ x = x := inf_eq_right.2 $ le_sup_left.trans hs.le,
sdiff_unique (by rw [h, hs]) (by rw [h, hi.eq_bot])
lemma disjoint.sup_sdiff_cancel_left (h : disjoint x y) : (x ⊔ y) \ x = y :=
h.sdiff_eq_of_sup_eq rfl
lemma disjoint.sup_sdiff_cancel_right (h : disjoint x y) : (x ⊔ y) \ y = x :=
h.symm.sdiff_eq_of_sup_eq sup_comm
protected theorem disjoint.sdiff_unique (hd : disjoint x z) (hz : z ≤ y) (hs : y ≤ x ⊔ z) :
y \ x = z :=
sdiff_unique
(begin
rw ←inf_eq_right at hs,
rwa [sup_inf_right, inf_sup_right, @sup_comm _ _ x, inf_sup_self, inf_comm, @sup_comm _ _ z,
hs, sup_eq_left],
end)
(by rw [inf_assoc, hd.eq_bot, inf_bot_eq])
-- cf. `is_compl.disjoint_left_iff` and `is_compl.disjoint_right_iff`
lemma disjoint_sdiff_iff_le (hz : z ≤ y) (hx : x ≤ y) : disjoint z (y \ x) ↔ z ≤ x :=
⟨λ H, le_of_inf_le_sup_le
(le_trans H bot_le)
(begin
rw sup_sdiff_of_le hx,
refine le_trans (sup_le_sup_left sdiff_le z) _,
rw sup_eq_right.2 hz,
end),
λ H, disjoint_sdiff.mono_left H⟩
-- cf. `is_compl.le_left_iff` and `is_compl.le_right_iff`
lemma le_iff_disjoint_sdiff (hz : z ≤ y) (hx : x ≤ y) : z ≤ x ↔ disjoint z (y \ x) :=
(disjoint_sdiff_iff_le hz hx).symm
-- cf. `is_compl.inf_left_eq_bot_iff` and `is_compl.inf_right_eq_bot_iff`
lemma inf_sdiff_eq_bot_iff (hz : z ≤ y) (hx : x ≤ y) : z ⊓ (y \ x) = ⊥ ↔ z ≤ x :=
by { rw ←disjoint_iff, exact disjoint_sdiff_iff_le hz hx }
-- cf. `is_compl.left_le_iff` and `is_compl.right_le_iff`
lemma le_iff_eq_sup_sdiff (hz : z ≤ y) (hx : x ≤ y) : x ≤ z ↔ y = z ⊔ (y \ x) :=
⟨λ H,
begin
apply le_antisymm,
{ conv_lhs { rw ←sup_inf_sdiff y x, },
apply sup_le_sup_right,
rwa inf_eq_right.2 hx, },
{ apply le_trans,
{ apply sup_le_sup_right hz, },
{ rw sup_sdiff_left, } }
end,
λ H,
begin
conv_lhs at H { rw ←sup_sdiff_of_le hx, },
refine le_of_inf_le_sup_le _ H.le,
rw inf_sdiff_self_right,
exact bot_le,
end⟩
-- cf. `set.union_diff_cancel'`
lemma sup_sdiff_cancel' (hx : x ≤ z) (hz : z ≤ y) : z ⊔ (y \ x) = y :=
((le_iff_eq_sup_sdiff hz (hx.trans hz)).1 hx).symm
-- cf. `is_compl.sup_inf`
lemma sdiff_sup : y \ (x ⊔ z) = (y \ x) ⊓ (y \ z) :=
sdiff_unique
(calc y ⊓ (x ⊔ z) ⊔ y \ x ⊓ (y \ z) =
(y ⊓ (x ⊔ z) ⊔ y \ x) ⊓ (y ⊓ (x ⊔ z) ⊔ (y \ z)) : by rw sup_inf_left
... = (y ⊓ x ⊔ y ⊓ z ⊔ y \ x) ⊓ (y ⊓ x ⊔ y ⊓ z ⊔ (y \ z)) : by rw @inf_sup_left _ _ y
... = (y ⊓ z ⊔ (y ⊓ x ⊔ y \ x)) ⊓ (y ⊓ x ⊔ (y ⊓ z ⊔ (y \ z))) : by ac_refl
... = (y ⊓ z ⊔ y) ⊓ (y ⊓ x ⊔ y) : by rw [sup_inf_sdiff, sup_inf_sdiff]
... = (y ⊔ y ⊓ z) ⊓ (y ⊔ y ⊓ x) : by ac_refl
... = y : by rw [sup_inf_self, sup_inf_self, inf_idem])
(calc y ⊓ (x ⊔ z) ⊓ ((y \ x) ⊓ (y \ z)) =
(y ⊓ x ⊔ y ⊓ z) ⊓ ((y \ x) ⊓ (y \ z)) : by rw inf_sup_left
... = ((y ⊓ x) ⊓ ((y \ x) ⊓ (y \ z))) ⊔ ((y ⊓ z) ⊓ ((y \ x) ⊓ (y \ z))) : by rw inf_sup_right
... = ((y ⊓ x) ⊓ (y \ x) ⊓ (y \ z)) ⊔ ((y \ x) ⊓ ((y \ z) ⊓ (y ⊓ z))) : by ac_refl
... = ⊥ : by rw [inf_inf_sdiff, bot_inf_eq, bot_sup_eq, @inf_comm _ _ (y \ z), inf_inf_sdiff,
inf_bot_eq])
-- cf. `is_compl.inf_sup`
lemma sdiff_inf : y \ (x ⊓ z) = y \ x ⊔ y \ z :=
sdiff_unique
(calc y ⊓ (x ⊓ z) ⊔ (y \ x ⊔ y \ z) =
(z ⊓ (y ⊓ x)) ⊔ (y \ x ⊔ y \ z) : by ac_refl
... = (z ⊔ (y \ x ⊔ y \ z)) ⊓ ((y ⊓ x) ⊔ (y \ x ⊔ y \ z)) : by rw sup_inf_right
... = (y \ x ⊔ (y \ z ⊔ z)) ⊓ (y ⊓ x ⊔ (y \ x ⊔ y \ z)) : by ac_refl
... = (y ⊔ z) ⊓ ((y ⊓ x) ⊔ (y \ x ⊔ y \ z)) :
by rw [sup_sdiff_self_left, ←sup_assoc, sup_sdiff_right]
... = (y ⊔ z) ⊓ y : by rw [←sup_assoc, sup_inf_sdiff, sup_sdiff_left]
... = y : by rw [inf_comm, inf_sup_self])
(calc y ⊓ (x ⊓ z) ⊓ ((y \ x) ⊔ (y \ z)) =
(y ⊓ (x ⊓ z) ⊓ (y \ x)) ⊔ (y ⊓ (x ⊓ z) ⊓ (y \ z)) : by rw inf_sup_left
... = z ⊓ (y ⊓ x ⊓ (y \ x)) ⊔ z ⊓ (y ⊓ x) ⊓ (y \ z) : by ac_refl
... = z ⊓ (y ⊓ x) ⊓ (y \ z) : by rw [inf_inf_sdiff, inf_bot_eq, bot_sup_eq]
... = x ⊓ ((y ⊓ z) ⊓ (y \ z)) : by ac_refl
... = ⊥ : by rw [inf_inf_sdiff, inf_bot_eq])
@[simp] lemma sdiff_inf_self_right : y \ (x ⊓ y) = y \ x :=
by rw [sdiff_inf, sdiff_self, sup_bot_eq]
@[simp] lemma sdiff_inf_self_left : y \ (y ⊓ x) = y \ x := by rw [inf_comm, sdiff_inf_self_right]
lemma sdiff_eq_sdiff_iff_inf_eq_inf : y \ x = y \ z ↔ y ⊓ x = y ⊓ z :=
⟨λ h, eq_of_inf_eq_sup_eq
(by rw [inf_inf_sdiff, h, inf_inf_sdiff])
(by rw [sup_inf_sdiff, h, sup_inf_sdiff]),
λ h, by rw [←sdiff_inf_self_right, ←@sdiff_inf_self_right _ z y, inf_comm, h, inf_comm]⟩
theorem disjoint.sdiff_eq_left (h : disjoint x y) : x \ y = x :=
by conv_rhs { rw [←sup_inf_sdiff x y, h.eq_bot, bot_sup_eq] }
theorem disjoint.sdiff_eq_right (h : disjoint x y) : y \ x = y := h.symm.sdiff_eq_left
-- cf. `is_compl_bot_top`
@[simp] theorem sdiff_bot : x \ ⊥ = x := disjoint_bot_right.sdiff_eq_left
theorem sdiff_eq_self_iff_disjoint : x \ y = x ↔ disjoint y x :=
calc x \ y = x ↔ x \ y = x \ ⊥ : by rw sdiff_bot
... ↔ x ⊓ y = x ⊓ ⊥ : sdiff_eq_sdiff_iff_inf_eq_inf
... ↔ disjoint y x : by rw [inf_bot_eq, inf_comm, disjoint_iff]
theorem sdiff_eq_self_iff_disjoint' : x \ y = x ↔ disjoint x y :=
by rw [sdiff_eq_self_iff_disjoint, disjoint.comm]
-- cf. `is_compl.antimono`
lemma sdiff_le_sdiff_self (h : z ≤ x) : w \ x ≤ w \ z :=
le_of_inf_le_sup_le
(calc (w \ x) ⊓ (w ⊓ z) ≤ (w \ x) ⊓ (w ⊓ x) : inf_le_inf le_rfl (inf_le_inf le_rfl h)
... = ⊥ : by rw [inf_comm, inf_inf_sdiff]
... ≤ (w \ z) ⊓ (w ⊓ z) : bot_le)
(calc w \ x ⊔ (w ⊓ z) ≤ w \ x ⊔ (w ⊓ x) : sup_le_sup le_rfl (inf_le_inf le_rfl h)
... ≤ w : by rw [sup_comm, sup_inf_sdiff]
... = (w \ z) ⊔ (w ⊓ z) : by rw [sup_comm, sup_inf_sdiff])
lemma sdiff_le_iff : y \ x ≤ z ↔ y ≤ x ⊔ z :=
⟨λ h, le_of_inf_le_sup_le
(le_of_eq
(calc y ⊓ (y \ x) = y \ x : inf_sdiff_right
... = (x ⊓ (y \ x)) ⊔ (z ⊓ (y \ x)) :
by rw [inf_eq_right.2 h, inf_sdiff_self_right, bot_sup_eq]
... = (x ⊔ z) ⊓ (y \ x) : inf_sup_right.symm))
(calc y ⊔ y \ x = y : sup_sdiff_left
... ≤ y ⊔ (x ⊔ z) : le_sup_left
... = ((y \ x) ⊔ x) ⊔ z : by rw [←sup_assoc, ←@sup_sdiff_self_left _ x y]
... = x ⊔ z ⊔ y \ x : by ac_refl),
λ h, le_of_inf_le_sup_le
(calc y \ x ⊓ x = ⊥ : inf_sdiff_self_left
... ≤ z ⊓ x : bot_le)
(calc y \ x ⊔ x = y ⊔ x : sup_sdiff_self_left
... ≤ (x ⊔ z) ⊔ x : sup_le_sup_right h x
... ≤ z ⊔ x : by rw [sup_assoc, sup_comm, sup_assoc, sup_idem])⟩
lemma sdiff_eq_bot_iff : y \ x = ⊥ ↔ y ≤ x :=
by rw [←le_bot_iff, sdiff_le_iff, sup_bot_eq]
lemma sdiff_le_comm : x \ y ≤ z ↔ x \ z ≤ y :=
by rw [sdiff_le_iff, sup_comm, sdiff_le_iff]
lemma sdiff_le_self_sdiff (h : w ≤ y) : w \ x ≤ y \ x :=
le_of_inf_le_sup_le
(calc (w \ x) ⊓ (w ⊓ x) = ⊥ : by rw [inf_comm, inf_inf_sdiff]
... ≤ (y \ x) ⊓ (w ⊓ x) : bot_le)
(calc w \ x ⊔ (w ⊓ x) = w : by rw [sup_comm, sup_inf_sdiff]
... ≤ (y ⊓ (y \ x)) ⊔ w : le_sup_right
... = (y ⊓ (y \ x)) ⊔ (y ⊓ w) : by rw inf_eq_right.2 h
... = y ⊓ ((y \ x) ⊔ w) : by rw inf_sup_left
... = ((y \ x) ⊔ (y ⊓ x)) ⊓ ((y \ x) ⊔ w) :
by rw [@sup_comm _ _ (y \ x) (y ⊓ x), sup_inf_sdiff]
... = (y \ x) ⊔ ((y ⊓ x) ⊓ w) : by rw ←sup_inf_left
... = (y \ x) ⊔ ((w ⊓ y) ⊓ x) : by ac_refl
... = (y \ x) ⊔ (w ⊓ x) : by rw inf_eq_left.2 h)
theorem sdiff_le_sdiff (h₁ : w ≤ y) (h₂ : z ≤ x) : w \ x ≤ y \ z :=
calc w \ x ≤ w \ z : sdiff_le_sdiff_self h₂
... ≤ y \ z : sdiff_le_self_sdiff h₁
lemma sup_inf_inf_sdiff : (x ⊓ y) ⊓ z ⊔ (y \ z) = (x ⊓ y) ⊔ (y \ z) :=
calc (x ⊓ y) ⊓ z ⊔ (y \ z) = x ⊓ (y ⊓ z) ⊔ (y \ z) : by rw inf_assoc
... = (x ⊔ (y \ z)) ⊓ y : by rw [sup_inf_right, sup_inf_sdiff]
... = (x ⊓ y) ⊔ (y \ z) : by rw [inf_sup_right, inf_sdiff_left]
@[simp] lemma inf_sdiff_sup_left : (x \ z) ⊓ (x ⊔ y) = x \ z :=
by rw [inf_sup_left, inf_sdiff_left, sup_inf_self]
@[simp] lemma inf_sdiff_sup_right : (x \ z) ⊓ (y ⊔ x) = x \ z :=
by rw [sup_comm, inf_sdiff_sup_left]
lemma sdiff_sdiff_right : x \ (y \ z) = (x \ y) ⊔ (x ⊓ y ⊓ z) :=
begin
rw [sup_comm, inf_comm, ←inf_assoc, sup_inf_inf_sdiff],
apply sdiff_unique,
{ calc x ⊓ (y \ z) ⊔ (z ⊓ x ⊔ x \ y) =
(x ⊔ (z ⊓ x ⊔ x \ y)) ⊓ (y \ z ⊔ (z ⊓ x ⊔ x \ y)) : by rw sup_inf_right
... = (x ⊔ x ⊓ z ⊔ x \ y) ⊓ (y \ z ⊔ (x ⊓ z ⊔ x \ y)) : by ac_refl
... = x ⊓ (y \ z ⊔ x ⊓ z ⊔ x \ y) : by rw [sup_inf_self, sup_sdiff_left, ←sup_assoc]
... = x ⊓ (y \ z ⊓ (z ⊔ y) ⊔ x ⊓ (z ⊔ y) ⊔ x \ y) :
by rw [sup_inf_left, sup_sdiff_self_left, inf_sup_right, @sup_comm _ _ y]
... = x ⊓ (y \ z ⊔ (x ⊓ z ⊔ x ⊓ y) ⊔ x \ y) :
by rw [inf_sdiff_sup_right, @inf_sup_left _ _ x z y]
... = x ⊓ (y \ z ⊔ (x ⊓ z ⊔ (x ⊓ y ⊔ x \ y))) : by ac_refl
... = x ⊓ (y \ z ⊔ (x ⊔ x ⊓ z)) : by rw [sup_inf_sdiff, @sup_comm _ _ (x ⊓ z)]
... = x : by rw [sup_inf_self, sup_comm, inf_sup_self] },
{ calc x ⊓ (y \ z) ⊓ (z ⊓ x ⊔ x \ y) =
x ⊓ (y \ z) ⊓ (z ⊓ x) ⊔ x ⊓ (y \ z) ⊓ (x \ y) : by rw inf_sup_left
... = x ⊓ (y \ z ⊓ z ⊓ x) ⊔ x ⊓ (y \ z) ⊓ (x \ y) : by ac_refl
... = x ⊓ (y \ z) ⊓ (x \ y) : by rw [inf_sdiff_self_left, bot_inf_eq, inf_bot_eq, bot_sup_eq]
... = x ⊓ (y \ z ⊓ y) ⊓ (x \ y) : by conv_lhs { rw ←inf_sdiff_left }
... = x ⊓ (y \ z ⊓ (y ⊓ (x \ y))) : by ac_refl
... = ⊥ : by rw [inf_sdiff_self_right, inf_bot_eq, inf_bot_eq] }
end
lemma sdiff_sdiff_right' : x \ (y \ z) = (x \ y) ⊔ (x ⊓ z) :=
calc x \ (y \ z) = (x \ y) ⊔ (x ⊓ y ⊓ z) : sdiff_sdiff_right
... = z ⊓ x ⊓ y ⊔ (x \ y) : by ac_refl
... = (x \ y) ⊔ (x ⊓ z) : by rw [sup_inf_inf_sdiff, sup_comm, inf_comm]
@[simp] lemma sdiff_sdiff_right_self : x \ (x \ y) = x ⊓ y :=
by rw [sdiff_sdiff_right, inf_idem, sdiff_self, bot_sup_eq]
lemma sdiff_sdiff_eq_self (h : y ≤ x) : x \ (x \ y) = y :=
by rw [sdiff_sdiff_right_self, inf_of_le_right h]
lemma sdiff_sdiff_left : (x \ y) \ z = x \ (y ⊔ z) :=
begin
rw sdiff_sup,
apply sdiff_unique,
{ rw [←inf_sup_left, sup_sdiff_self_right, inf_sdiff_sup_right] },
{ rw [inf_assoc, @inf_comm _ _ z, inf_assoc, inf_sdiff_self_left, inf_bot_eq, inf_bot_eq] }
end
lemma sdiff_sdiff_left' : (x \ y) \ z = (x \ y) ⊓ (x \ z) :=
by rw [sdiff_sdiff_left, sdiff_sup]
lemma sdiff_sdiff_comm : (x \ y) \ z = (x \ z) \ y :=
by rw [sdiff_sdiff_left, sup_comm, sdiff_sdiff_left]
@[simp] lemma sdiff_idem : x \ y \ y = x \ y := by rw [sdiff_sdiff_left, sup_idem]
lemma sdiff_sdiff_sup_sdiff : z \ (x \ y ⊔ y \ x) = z ⊓ (z \ x ⊔ y) ⊓ (z \ y ⊔ x) :=
calc z \ (x \ y ⊔ y \ x) = (z \ x ⊔ z ⊓ x ⊓ y) ⊓ (z \ y ⊔ z ⊓ y ⊓ x) :
by rw [sdiff_sup, sdiff_sdiff_right, sdiff_sdiff_right]
... = z ⊓ (z \ x ⊔ y) ⊓ (z \ y ⊔ z ⊓ y ⊓ x) : by rw [sup_inf_left, sup_comm, sup_inf_sdiff]
... = z ⊓ (z \ x ⊔ y) ⊓ (z ⊓ (z \ y ⊔ x)) :
by rw [sup_inf_left, @sup_comm _ _ (z \ y), sup_inf_sdiff]
... = z ⊓ z ⊓ (z \ x ⊔ y) ⊓ (z \ y ⊔ x) : by ac_refl
... = z ⊓ (z \ x ⊔ y) ⊓ (z \ y ⊔ x) : by rw inf_idem
lemma sdiff_sdiff_sup_sdiff' : z \ (x \ y ⊔ y \ x) = z ⊓ x ⊓ y ⊔ ((z \ x) ⊓ (z \ y)) :=
calc z \ (x \ y ⊔ y \ x) =
z \ (x \ y) ⊓ (z \ (y \ x)) : sdiff_sup
... = (z \ x ⊔ z ⊓ x ⊓ y) ⊓ (z \ y ⊔ z ⊓ y ⊓ x) : by rw [sdiff_sdiff_right, sdiff_sdiff_right]
... = (z \ x ⊔ z ⊓ y ⊓ x) ⊓ (z \ y ⊔ z ⊓ y ⊓ x) : by ac_refl
... = (z \ x) ⊓ (z \ y) ⊔ z ⊓ y ⊓ x : sup_inf_right.symm
... = z ⊓ x ⊓ y ⊔ ((z \ x) ⊓ (z \ y)) : by ac_refl
lemma sup_sdiff : (x ⊔ y) \ z = (x \ z) ⊔ (y \ z) :=
sdiff_unique
(calc (x ⊔ y) ⊓ z ⊔ (x \ z ⊔ y \ z) =
(x ⊓ z ⊔ y ⊓ z) ⊔ (x \ z ⊔ y \ z) : by rw inf_sup_right
... = x ⊓ z ⊔ x \ z ⊔ y \ z ⊔ y ⊓ z : by ac_refl
... = x ⊔ (y ⊓ z ⊔ y \ z) : by rw [sup_inf_sdiff, sup_assoc, @sup_comm _ _ (y \ z)]
... = x ⊔ y : by rw sup_inf_sdiff)
(calc (x ⊔ y) ⊓ z ⊓ (x \ z ⊔ y \ z) =
(x ⊓ z ⊔ y ⊓ z) ⊓ (x \ z ⊔ y \ z) : by rw inf_sup_right
... = (x ⊓ z ⊔ y ⊓ z) ⊓ (x \ z) ⊔ ((x ⊓ z ⊔ y ⊓ z) ⊓ (y \ z)) :
by rw [@inf_sup_left _ _ (x ⊓ z ⊔ y ⊓ z)]
... = (y ⊓ z ⊓ (x \ z)) ⊔ ((x ⊓ z ⊔ y ⊓ z) ⊓ (y \ z)) :
by rw [inf_sup_right, inf_inf_sdiff, bot_sup_eq]
... = (x ⊓ z ⊔ y ⊓ z) ⊓ (y \ z) : by rw [inf_assoc, inf_sdiff_self_right, inf_bot_eq, bot_sup_eq]
... = x ⊓ z ⊓ (y \ z) : by rw [inf_sup_right, inf_inf_sdiff, sup_bot_eq]
... = ⊥ : by rw [inf_assoc, inf_sdiff_self_right, inf_bot_eq])
lemma sup_sdiff_right_self : (x ⊔ y) \ y = x \ y :=
by rw [sup_sdiff, sdiff_self, sup_bot_eq]
lemma sup_sdiff_left_self : (x ⊔ y) \ x = y \ x :=
by rw [sup_comm, sup_sdiff_right_self]
lemma inf_sdiff : (x ⊓ y) \ z = (x \ z) ⊓ (y \ z) :=
sdiff_unique
(calc (x ⊓ y) ⊓ z ⊔ ((x \ z) ⊓ (y \ z)) =
((x ⊓ y) ⊓ z ⊔ (x \ z)) ⊓ ((x ⊓ y) ⊓ z ⊔ (y \ z)) : by rw [sup_inf_left]
... = (x ⊓ y ⊓ (z ⊔ x) ⊔ x \ z) ⊓ (x ⊓ y ⊓ z ⊔ y \ z) :
by rw [sup_inf_right, sup_sdiff_self_right, inf_sup_right, inf_sdiff_sup_right]
... = (y ⊓ (x ⊓ (x ⊔ z)) ⊔ x \ z) ⊓ (x ⊓ y ⊓ z ⊔ y \ z) : by ac_refl
... = ((y ⊓ x) ⊔ (x \ z)) ⊓ ((x ⊓ y) ⊔ (y \ z)) : by rw [inf_sup_self, sup_inf_inf_sdiff]
... = (x ⊓ y) ⊔ ((x \ z) ⊓ (y \ z)) : by rw [@inf_comm _ _ y, sup_inf_left]
... = x ⊓ y : sup_eq_left.2 (inf_le_inf sdiff_le sdiff_le))
(calc (x ⊓ y) ⊓ z ⊓ ((x \ z) ⊓ (y \ z)) =
x ⊓ y ⊓ (z ⊓ (x \ z)) ⊓ (y \ z) : by ac_refl
... = ⊥ : by rw [inf_sdiff_self_right, inf_bot_eq, bot_inf_eq])
lemma inf_sdiff_assoc : (x ⊓ y) \ z = x ⊓ (y \ z) :=
sdiff_unique
(calc x ⊓ y ⊓ z ⊔ x ⊓ (y \ z) = x ⊓ (y ⊓ z) ⊔ x ⊓ (y \ z) : by rw inf_assoc
... = x ⊓ ((y ⊓ z) ⊔ y \ z) : inf_sup_left.symm
... = x ⊓ y : by rw sup_inf_sdiff)
(calc x ⊓ y ⊓ z ⊓ (x ⊓ (y \ z)) = x ⊓ x ⊓ ((y ⊓ z) ⊓ (y \ z)) : by ac_refl
... = ⊥ : by rw [inf_inf_sdiff, inf_bot_eq])
lemma sup_eq_sdiff_sup_sdiff_sup_inf : x ⊔ y = (x \ y) ⊔ (y \ x) ⊔ (x ⊓ y) :=
eq.symm $
calc (x \ y) ⊔ (y \ x) ⊔ (x ⊓ y) =
((x \ y) ⊔ (y \ x) ⊔ x) ⊓ ((x \ y) ⊔ (y \ x) ⊔ y) : by rw sup_inf_left
... = ((x \ y) ⊔ x ⊔ (y \ x)) ⊓ ((x \ y) ⊔ ((y \ x) ⊔ y)) : by ac_refl
... = (x ⊔ (y \ x)) ⊓ ((x \ y) ⊔ y) : by rw [sup_sdiff_right, sup_sdiff_right]
... = x ⊔ y : by rw [sup_sdiff_self_right, sup_sdiff_self_left, inf_idem]
instance pi.generalized_boolean_algebra {α : Type u} {β : Type v} [generalized_boolean_algebra β] :
generalized_boolean_algebra (α → β) :=
by pi_instance
end generalized_boolean_algebra
/-!
### Boolean algebras
-/
/-- Set / lattice complement -/
class has_compl (α : Type*) := (compl : α → α)
export has_compl (compl)
postfix `ᶜ`:(max+1) := compl
/-- This class contains the core axioms of a Boolean algebra. The `boolean_algebra` class extends
both this class and `generalized_boolean_algebra`, see Note [forgetful inheritance]. -/
class boolean_algebra.core (α : Type u) extends bounded_distrib_lattice α, has_compl α :=
(inf_compl_le_bot : ∀x:α, x ⊓ xᶜ ≤ ⊥)
(top_le_sup_compl : ∀x:α, ⊤ ≤ x ⊔ xᶜ)
section boolean_algebra_core
variables [boolean_algebra.core α]
@[simp] theorem inf_compl_eq_bot : x ⊓ xᶜ = ⊥ :=
bot_unique $ boolean_algebra.core.inf_compl_le_bot x
@[simp] theorem compl_inf_eq_bot : xᶜ ⊓ x = ⊥ :=
eq.trans inf_comm inf_compl_eq_bot
@[simp] theorem sup_compl_eq_top : x ⊔ xᶜ = ⊤ :=
top_unique $ boolean_algebra.core.top_le_sup_compl x
@[simp] theorem compl_sup_eq_top : xᶜ ⊔ x = ⊤ :=
eq.trans sup_comm sup_compl_eq_top
theorem is_compl_compl : is_compl x xᶜ :=
is_compl.of_eq inf_compl_eq_bot sup_compl_eq_top
theorem is_compl.eq_compl (h : is_compl x y) : x = yᶜ :=
h.left_unique is_compl_compl.symm
theorem is_compl.compl_eq (h : is_compl x y) : xᶜ = y :=
(h.right_unique is_compl_compl).symm
theorem disjoint_compl_right : disjoint x xᶜ := is_compl_compl.disjoint
theorem disjoint_compl_left : disjoint xᶜ x := disjoint_compl_right.symm
theorem compl_unique (i : x ⊓ y = ⊥) (s : x ⊔ y = ⊤) : xᶜ = y :=
(is_compl.of_eq i s).compl_eq
@[simp] theorem compl_top : ⊤ᶜ = (⊥:α) :=
is_compl_top_bot.compl_eq
@[simp] theorem compl_bot : ⊥ᶜ = (⊤:α) :=
is_compl_bot_top.compl_eq
@[simp] theorem compl_compl (x : α) : xᶜᶜ = x :=
is_compl_compl.symm.compl_eq
theorem compl_injective : function.injective (compl : α → α) :=
function.involutive.injective compl_compl
@[simp] theorem compl_inj_iff : xᶜ = yᶜ ↔ x = y :=
compl_injective.eq_iff
theorem is_compl.compl_eq_iff (h : is_compl x y) : zᶜ = y ↔ z = x :=
h.compl_eq ▸ compl_inj_iff
@[simp] theorem compl_eq_top : xᶜ = ⊤ ↔ x = ⊥ :=
is_compl_bot_top.compl_eq_iff
@[simp] theorem compl_eq_bot : xᶜ = ⊥ ↔ x = ⊤ :=
is_compl_top_bot.compl_eq_iff
@[simp] theorem compl_inf : (x ⊓ y)ᶜ = xᶜ ⊔ yᶜ :=
(is_compl_compl.inf_sup is_compl_compl).compl_eq
@[simp] theorem compl_sup : (x ⊔ y)ᶜ = xᶜ ⊓ yᶜ :=
(is_compl_compl.sup_inf is_compl_compl).compl_eq
theorem compl_le_compl (h : y ≤ x) : xᶜ ≤ yᶜ :=
is_compl_compl.antimono is_compl_compl h
@[simp] theorem compl_le_compl_iff_le : yᶜ ≤ xᶜ ↔ x ≤ y :=
⟨assume h, by have h := compl_le_compl h; simp at h; assumption,
compl_le_compl⟩
theorem le_compl_of_le_compl (h : y ≤ xᶜ) : x ≤ yᶜ :=
by simpa only [compl_compl] using compl_le_compl h
theorem compl_le_of_compl_le (h : yᶜ ≤ x) : xᶜ ≤ y :=
by simpa only [compl_compl] using compl_le_compl h
theorem le_compl_iff_le_compl : y ≤ xᶜ ↔ x ≤ yᶜ :=
⟨le_compl_of_le_compl, le_compl_of_le_compl⟩
theorem compl_le_iff_compl_le : xᶜ ≤ y ↔ yᶜ ≤ x :=
⟨compl_le_of_compl_le, compl_le_of_compl_le⟩
namespace boolean_algebra
@[priority 100]
instance : is_complemented α := ⟨λ x, ⟨xᶜ, is_compl_compl⟩⟩
end boolean_algebra
end boolean_algebra_core
/-- A Boolean algebra is a bounded distributive lattice with
a complement operator `ᶜ` such that `x ⊓ xᶜ = ⊥` and `x ⊔ xᶜ = ⊤`.
For convenience, it must also provide a set difference operation `\`
satisfying `x \ y = x ⊓ yᶜ`.
This is a generalization of (classical) logic of propositions, or
the powerset lattice. -/
-- Lean complains about metavariables in the type if the universe is not specified
class boolean_algebra (α : Type u) extends generalized_boolean_algebra α, boolean_algebra.core α :=
(sdiff_eq : ∀x y:α, x \ y = x ⊓ yᶜ)
-- TODO: is there a way to automatically fill in the proofs of sup_inf_sdiff and inf_inf_sdiff given
-- everything in `boolean_algebra.core` and `sdiff_eq`? The following doesn't work:
-- (sup_inf_sdiff := λ a b, by rw [sdiff_eq, ←inf_sup_left, sup_compl_eq_top, inf_top_eq])
/-- Create a `boolean_algebra` instance from a `boolean_algebra.core` instance, defining `x \ y` to
be `x ⊓ yᶜ`.
For some types, it may be more convenient to create the `boolean_algebra` instance by hand in order
to have a simpler `sdiff` operation. -/
def boolean_algebra.of_core (B : boolean_algebra.core α) :
boolean_algebra α :=
{ sdiff := λ x y, x ⊓ yᶜ,
sdiff_eq := λ _ _, rfl,
sup_inf_sdiff := λ a b, by rw [←inf_sup_left, sup_compl_eq_top, inf_top_eq],
inf_inf_sdiff := λ a b, by rw [inf_left_right_swap, @inf_assoc _ _ a, compl_inf_eq_bot,
inf_bot_eq, bot_inf_eq],
..B }
section boolean_algebra
variables [boolean_algebra α]
theorem sdiff_eq : x \ y = x ⊓ yᶜ := boolean_algebra.sdiff_eq x y
theorem sdiff_compl : x \ yᶜ = x ⊓ y := by rw [sdiff_eq, compl_compl]
theorem top_sdiff : ⊤ \ x = xᶜ := by rw [sdiff_eq, top_inf_eq]
@[simp] theorem sdiff_top : x \ ⊤ = ⊥ := by rw [sdiff_eq, compl_top, inf_bot_eq]
end boolean_algebra
instance boolean_algebra_Prop : boolean_algebra Prop :=
boolean_algebra.of_core
{ compl := not,
inf_compl_le_bot := λ p ⟨Hp, Hpc⟩, Hpc Hp,
top_le_sup_compl := λ p H, classical.em p,
.. bounded_distrib_lattice_Prop }
instance pi.boolean_algebra {α : Type u} {β : Type v} [boolean_algebra β] :
boolean_algebra (α → β) :=
by pi_instance
|
301e5c00855731e4ec1fb65678facc3ca0492bc5
|
2eab05920d6eeb06665e1a6df77b3157354316ad
|
/src/measure_theory/function/special_functions.lean
|
2b27694345231fede6b3a415aace4d0ab9dc472c
|
[
"Apache-2.0"
] |
permissive
|
ayush1801/mathlib
|
78949b9f789f488148142221606bf15c02b960d2
|
ce164e28f262acbb3de6281b3b03660a9f744e3c
|
refs/heads/master
| 1,692,886,907,941
| 1,635,270,866,000
| 1,635,270,866,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 9,537
|
lean
|
/-
Copyright (c) 2020 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import analysis.special_functions.pow
import analysis.special_functions.trigonometric.arctan
import analysis.inner_product_space.calculus
import measure_theory.constructions.borel_space
/-!
# Measurability of real and complex functions
We show that most standard real and complex functions are measurable, notably `exp`, `cos`, `sin`,
`cosh`, `sinh`, `log`, `pow`, `arcsin`, `arccos`, `arctan`, and scalar products.
-/
noncomputable theory
open_locale nnreal ennreal
namespace real
@[measurability] lemma measurable_exp : measurable exp := continuous_exp.measurable
@[measurability] lemma measurable_log : measurable log :=
measurable_of_measurable_on_compl_singleton 0 $ continuous.measurable $
continuous_on_iff_continuous_restrict.1 continuous_on_log
@[measurability] lemma measurable_sin : measurable sin := continuous_sin.measurable
@[measurability] lemma measurable_cos : measurable cos := continuous_cos.measurable
@[measurability] lemma measurable_sinh : measurable sinh := continuous_sinh.measurable
@[measurability] lemma measurable_cosh : measurable cosh := continuous_cosh.measurable
@[measurability] lemma measurable_arcsin : measurable arcsin := continuous_arcsin.measurable
@[measurability] lemma measurable_arccos : measurable arccos := continuous_arccos.measurable
@[measurability] lemma measurable_arctan : measurable arctan := continuous_arctan.measurable
end real
namespace complex
@[measurability] lemma measurable_re : measurable re := continuous_re.measurable
@[measurability] lemma measurable_im : measurable im := continuous_im.measurable
@[measurability] lemma measurable_of_real : measurable (coe : ℝ → ℂ) :=
continuous_of_real.measurable
@[measurability] lemma measurable_exp : measurable exp := continuous_exp.measurable
@[measurability] lemma measurable_sin : measurable sin := continuous_sin.measurable
@[measurability] lemma measurable_cos : measurable cos := continuous_cos.measurable
@[measurability] lemma measurable_sinh : measurable sinh := continuous_sinh.measurable
@[measurability] lemma measurable_cosh : measurable cosh := continuous_cosh.measurable
@[measurability] lemma measurable_arg : measurable arg :=
have A : measurable (λ x : ℂ, real.arcsin (x.im / x.abs)),
from real.measurable_arcsin.comp (measurable_im.div measurable_norm),
have B : measurable (λ x : ℂ, real.arcsin ((-x).im / x.abs)),
from real.measurable_arcsin.comp ((measurable_im.comp measurable_neg).div measurable_norm),
measurable.ite (is_closed_le continuous_const continuous_re).measurable_set A $
measurable.ite (is_closed_le continuous_const continuous_im).measurable_set
(B.add_const _) (B.sub_const _)
@[measurability] lemma measurable_log : measurable log :=
(measurable_of_real.comp $ real.measurable_log.comp measurable_norm).add $
(measurable_of_real.comp measurable_arg).mul_const I
end complex
namespace is_R_or_C
variables {𝕜 : Type*} [is_R_or_C 𝕜] [measurable_space 𝕜] [opens_measurable_space 𝕜]
@[measurability] lemma measurable_re : measurable (re : 𝕜 → ℝ) := continuous_re.measurable
@[measurability] lemma measurable_im : measurable (im : 𝕜 → ℝ) := continuous_im.measurable
end is_R_or_C
section real_composition
open real
variables {α : Type*} [measurable_space α] {f : α → ℝ} (hf : measurable f)
@[measurability] lemma measurable.exp : measurable (λ x, real.exp (f x)) :=
real.measurable_exp.comp hf
@[measurability] lemma measurable.log : measurable (λ x, log (f x)) :=
measurable_log.comp hf
@[measurability] lemma measurable.cos : measurable (λ x, real.cos (f x)) :=
real.measurable_cos.comp hf
@[measurability] lemma measurable.sin : measurable (λ x, real.sin (f x)) :=
real.measurable_sin.comp hf
@[measurability] lemma measurable.cosh : measurable (λ x, real.cosh (f x)) :=
real.measurable_cosh.comp hf
@[measurability] lemma measurable.sinh : measurable (λ x, real.sinh (f x)) :=
real.measurable_sinh.comp hf
@[measurability] lemma measurable.arctan : measurable (λ x, arctan (f x)) :=
measurable_arctan.comp hf
@[measurability] lemma measurable.sqrt : measurable (λ x, sqrt (f x)) :=
continuous_sqrt.measurable.comp hf
end real_composition
section complex_composition
open complex
variables {α : Type*} [measurable_space α] {f : α → ℂ} (hf : measurable f)
@[measurability] lemma measurable.cexp : measurable (λ x, complex.exp (f x)) :=
complex.measurable_exp.comp hf
@[measurability] lemma measurable.ccos : measurable (λ x, complex.cos (f x)) :=
complex.measurable_cos.comp hf
@[measurability] lemma measurable.csin : measurable (λ x, complex.sin (f x)) :=
complex.measurable_sin.comp hf
@[measurability] lemma measurable.ccosh : measurable (λ x, complex.cosh (f x)) :=
complex.measurable_cosh.comp hf
@[measurability] lemma measurable.csinh : measurable (λ x, complex.sinh (f x)) :=
complex.measurable_sinh.comp hf
@[measurability] lemma measurable.carg : measurable (λ x, arg (f x)) :=
measurable_arg.comp hf
@[measurability] lemma measurable.clog : measurable (λ x, log (f x)) :=
measurable_log.comp hf
end complex_composition
section is_R_or_C_composition
variables {α 𝕜 : Type*} [is_R_or_C 𝕜] [measurable_space α] [measurable_space 𝕜]
[opens_measurable_space 𝕜] {f : α → 𝕜} {μ : measure_theory.measure α}
@[measurability] lemma measurable.re (hf : measurable f) : measurable (λ x, is_R_or_C.re (f x)) :=
is_R_or_C.measurable_re.comp hf
@[measurability] lemma ae_measurable.re (hf : ae_measurable f μ) :
ae_measurable (λ x, is_R_or_C.re (f x)) μ :=
is_R_or_C.measurable_re.comp_ae_measurable hf
@[measurability] lemma measurable.im (hf : measurable f) : measurable (λ x, is_R_or_C.im (f x)) :=
is_R_or_C.measurable_im.comp hf
@[measurability] lemma ae_measurable.im (hf : ae_measurable f μ) :
ae_measurable (λ x, is_R_or_C.im (f x)) μ :=
is_R_or_C.measurable_im.comp_ae_measurable hf
end is_R_or_C_composition
section
variables {α 𝕜 : Type*} [is_R_or_C 𝕜] [measurable_space α] [measurable_space 𝕜]
[borel_space 𝕜] {f : α → 𝕜} {μ : measure_theory.measure α}
@[measurability] lemma is_R_or_C.measurable_of_real : measurable (coe : ℝ → 𝕜) :=
is_R_or_C.continuous_of_real.measurable
lemma measurable_of_re_im
(hre : measurable (λ x, is_R_or_C.re (f x)))
(him : measurable (λ x, is_R_or_C.im (f x))) : measurable f :=
begin
convert (is_R_or_C.measurable_of_real.comp hre).add
((is_R_or_C.measurable_of_real.comp him).mul_const is_R_or_C.I),
{ ext1 x,
exact (is_R_or_C.re_add_im _).symm },
all_goals { apply_instance },
end
lemma ae_measurable_of_re_im
(hre : ae_measurable (λ x, is_R_or_C.re (f x)) μ)
(him : ae_measurable (λ x, is_R_or_C.im (f x)) μ) : ae_measurable f μ :=
begin
convert (is_R_or_C.measurable_of_real.comp_ae_measurable hre).add
((is_R_or_C.measurable_of_real.comp_ae_measurable him).mul_const is_R_or_C.I),
{ ext1 x,
exact (is_R_or_C.re_add_im _).symm },
all_goals { apply_instance },
end
end
section pow_instances
instance complex.has_measurable_pow : has_measurable_pow ℂ ℂ :=
⟨measurable.ite (measurable_fst (measurable_set_singleton 0))
(measurable.ite (measurable_snd (measurable_set_singleton 0)) measurable_one measurable_zero)
(measurable_fst.clog.mul measurable_snd).cexp⟩
instance real.has_measurable_pow : has_measurable_pow ℝ ℝ :=
⟨complex.measurable_re.comp $ ((complex.measurable_of_real.comp measurable_fst).pow
(complex.measurable_of_real.comp measurable_snd))⟩
instance nnreal.has_measurable_pow : has_measurable_pow ℝ≥0 ℝ :=
⟨(measurable_fst.coe_nnreal_real.pow measurable_snd).subtype_mk⟩
instance ennreal.has_measurable_pow : has_measurable_pow ℝ≥0∞ ℝ :=
begin
refine ⟨ennreal.measurable_of_measurable_nnreal_prod _ _⟩,
{ simp_rw ennreal.coe_rpow_def,
refine measurable.ite _ measurable_const
(measurable_fst.pow measurable_snd).coe_nnreal_ennreal,
exact measurable_set.inter (measurable_fst (measurable_set_singleton 0))
(measurable_snd measurable_set_Iio), },
{ simp_rw ennreal.top_rpow_def,
refine measurable.ite measurable_set_Ioi measurable_const _,
exact measurable.ite (measurable_set_singleton 0) measurable_const measurable_const, },
end
end pow_instances
section
variables {α : Type*} {𝕜 : Type*} {E : Type*} [is_R_or_C 𝕜] [inner_product_space 𝕜 E]
local notation `⟪`x`, `y`⟫` := @inner 𝕜 _ _ x y
@[measurability]
lemma measurable.inner [measurable_space α] [measurable_space E] [opens_measurable_space E]
[topological_space.second_countable_topology E] [measurable_space 𝕜] [borel_space 𝕜]
{f g : α → E} (hf : measurable f) (hg : measurable g) :
measurable (λ t, ⟪f t, g t⟫) :=
continuous.measurable2 continuous_inner hf hg
@[measurability]
lemma ae_measurable.inner [measurable_space α] [measurable_space E] [opens_measurable_space E]
[topological_space.second_countable_topology E] [measurable_space 𝕜] [borel_space 𝕜]
{μ : measure_theory.measure α} {f g : α → E} (hf : ae_measurable f μ) (hg : ae_measurable g μ) :
ae_measurable (λ x, ⟪f x, g x⟫) μ :=
begin
refine ⟨λ x, ⟪hf.mk f x, hg.mk g x⟫, hf.measurable_mk.inner hg.measurable_mk, _⟩,
refine hf.ae_eq_mk.mp (hg.ae_eq_mk.mono (λ x hxg hxf, _)),
dsimp only,
congr,
{ exact hxf, },
{ exact hxg, },
end
end
|
6994482205c274ece97cd1bb88797f15815b8a0a
|
05f637fa14ac28031cb1ea92086a0f4eb23ff2b1
|
/tests/lean/stackoverflow/tactic2.lean
|
c17fef84114579ea65e2dd28a9abc45a0f145b3b
|
[
"Apache-2.0"
] |
permissive
|
codyroux/lean0.1
|
1ce92751d664aacff0529e139083304a7bbc8a71
|
0dc6fb974aa85ed6f305a2f4b10a53a44ee5f0ef
|
refs/heads/master
| 1,610,830,535,062
| 1,402,150,480,000
| 1,402,150,480,000
| 19,588,851
| 2
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 70
|
lean
|
Theorem T (a : Bool) : a.
apply (** REPEAT(id_tac) **).
done.
|
d914029da59bb8b91ad33b1c2997ea4d1a56cc97
|
f3a5af2927397cf346ec0e24312bfff077f00425
|
/src/game/world3/level9.lean
|
d9bb2fdd23ea5e70086a907de24b82093f96da9b
|
[
"Apache-2.0"
] |
permissive
|
ImperialCollegeLondon/natural_number_game
|
05c39e1586408cfb563d1a12e1085a90726ab655
|
f29b6c2884299fc63fdfc81ae5d7daaa3219f9fd
|
refs/heads/master
| 1,688,570,964,990
| 1,636,908,242,000
| 1,636,908,242,000
| 195,403,790
| 277
| 84
|
Apache-2.0
| 1,694,547,955,000
| 1,562,328,792,000
|
Lean
|
UTF-8
|
Lean
| false
| false
| 1,219
|
lean
|
import game.world3.level8 -- hide
import mynat.mul -- hide
namespace mynat -- hide
/-
# Multiplication World
## Level 9: `mul_left_comm`
You are equipped with
* `mul_assoc (a b c : mynat) : (a * b) * c = a * (b * c)`
* `mul_comm (a b : mynat) : a * b = b * a`
Re-read the docs for `rw` so you know all the tricks.
You can see them in the "tactics" drop-down menu on the left.
-/
/- Lemma
For all natural numbers $a$ $b$ and $c$, we have
$$a(bc)=b(ac)$$
-/
lemma mul_left_comm (a b c : mynat) : a * (b * c) = b * (a * c) :=
begin [nat_num_game]
rw ←mul_assoc,
rw mul_comm a,
rw mul_assoc,
refl,
end
/-
And now I whisper a magic incantation
-/
attribute [simp] mul_assoc mul_comm mul_left_comm
/-
and all of a sudden Lean can automatically do levels which are
very boring for a human, for example
-/
example (a b c d e : mynat) :
(((a*b)*c)*d)*e=(c*((b*e)*a))*d :=
begin
simp,
end
/-
If you feel like attempting Advanced Multiplication world
you'll have to do Function World and the Proposition Worlds first.
These worlds assume a certain amount of mathematical maturity
(perhaps 1st year undergraduate level).
Your other possibility is Power World, with the "final boss".
-/
end mynat -- hide
|
b1298d660771cdc01b735f46ac31448da6b76713
|
8cae430f0a71442d02dbb1cbb14073b31048e4b0
|
/src/tactic/transform_decl.lean
|
8f1296bf7d948d18144fd332bb9105a92f6d69a3
|
[
"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
| 7,910
|
lean
|
/-
Copyright (c) 2017 Mario Carneiro All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Floris van Doorn
-/
import tactic.core
namespace tactic
/-- `copy_attribute' attr_name src tgt p d_name` copy (user) attribute `attr_name` from
`src` to `tgt` if it is defined for `src`; unlike `copy_attribute` the primed version also copies
the parameter of the user attribute, in the user attribute case. Make it persistent if `p` is
`tt`; if `p` is `none`, the copied attribute is made persistent iff it is persistent on `src` -/
meta def copy_attribute' (attr_name : name) (src : name) (tgt : name) (p : option bool := none) :
tactic unit := do
get_decl tgt <|> fail!"unknown declaration {tgt}",
-- if the source doesn't have the attribute we do not error and simply return
mwhen (succeeds (has_attribute attr_name src)) $
do (p', prio) ← has_attribute attr_name src,
let p := p.get_or_else p',
s ← try_or_report_error (set_basic_attribute attr_name tgt p prio),
sum.inr msg ← return s | skip,
if msg =
(format!("set_basic_attribute tactic failed, '{attr_name}' " ++
"is not a basic attribute")).to_string
then do
user_attr_const ← (get_user_attribute_name attr_name >>= mk_const),
tac ← eval_pexpr (tactic unit)
``(user_attribute.get_param_untyped %%user_attr_const %%`(src) >>=
λ x, user_attribute.set_untyped %%user_attr_const %%`(tgt) x %%`(p) %%`(prio)),
tac
else fail msg
open expr
/-- Auxilliary function for `additive_test`. The bool argument *only* matters when applied
to exactly a constant. -/
meta def additive_test_aux (f : name → option name) (ignore : name_map $ list ℕ) :
bool → expr → bool
| b (var n) := tt
| b (sort l) := tt
| b (const n ls) := b || (f n).is_some
| b (mvar n m t) := tt
| b (local_const n m bi t) := tt
| b (app e f) := additive_test_aux tt e &&
-- this might be inefficient.
-- If it becomes a performance problem: we can give this info for the recursive call to `e`.
match ignore.find e.get_app_fn.const_name with
| some l := if e.get_app_num_args + 1 ∈ l then tt else additive_test_aux ff f
| none := additive_test_aux ff f
end
| b (lam n bi e t) := additive_test_aux ff t
| b (pi n bi e t) := additive_test_aux ff t
| b (elet n g e f) := additive_test_aux ff e && additive_test_aux ff f
| b (macro d args) := tt
/--
`additive_test f replace_all ignore e` tests whether the expression `e` contains no constant
`nm` that is not applied to any arguments, and such that `f nm = none`.
This is used in `@[to_additive]` for deciding which subexpressions to transform: we only transform
constants if `additive_test` applied to their first argument returns `tt`.
This means we will replace expression applied to e.g. `α` or `α × β`, but not when applied to
e.g. `ℕ` or `ℝ × α`.
`f` is the dictionary of declarations that are in the `to_additive` dictionary.
We ignore all arguments specified in the `name_map` `ignore`.
If `replace_all` is `tt` the test always return `tt`.
-/
meta def additive_test (f : name → option name) (replace_all : bool) (ignore : name_map $ list ℕ)
(e : expr) : bool :=
if replace_all then tt else additive_test_aux f ignore ff e
/-- transform the declaration `src` and all declarations `pre._proof_i` occurring in `src`
using the dictionary `f`.
`replace_all`, `trace`, `ignore` and `reorder` are configuration options.
`pre` is the declaration that got the `@[to_additive]` attribute and `tgt_pre` is the target of this
declaration. -/
meta def transform_decl_with_prefix_fun_aux (f : name → option name)
(replace_all trace : bool) (relevant : name_map ℕ) (ignore reorder : name_map $ list ℕ)
(pre tgt_pre : name) : name → command :=
λ src,
do
-- if this declaration is not `pre` or an internal declaration, we do nothing.
tt ← return (src = pre ∨ src.is_internal : bool) |
if (f src).is_some then skip else fail!("@[to_additive] failed.
The declaration {pre} depends on the declaration {src} which is in the namespace {pre}, but " ++
"does not have the `@[to_additive]` attribute. This is not supported. Workaround: move {src} to " ++
"a different namespace."),
env ← get_env,
-- we find the additive name of `src`
let tgt := src.map_prefix (λ n, if n = pre then some tgt_pre else none),
-- we skip if we already transformed this declaration before
ff ← return $ env.contains tgt | skip,
decl ← get_decl src,
-- we first transform all the declarations of the form `pre._proof_i`
(decl.type.list_names_with_prefix pre).mfold () (λ n _, transform_decl_with_prefix_fun_aux n),
(decl.value.list_names_with_prefix pre).mfold () (λ n _, transform_decl_with_prefix_fun_aux n),
-- we transform `decl` using `f` and the configuration options.
let decl :=
decl.update_with_fun env (name.map_prefix f) (additive_test f replace_all ignore)
relevant reorder tgt,
-- o ← get_options, set_options $ o.set_bool `pp.all tt, -- print with pp.all (for debugging)
pp_decl ← pp decl,
when trace $ trace!"[to_additive] > generating\n{pp_decl}",
decorate_error (format!"@[to_additive] failed. Type mismatch in additive declaration.
For help, see the docstring of `to_additive.attr`, section `Troubleshooting`.
Failed to add declaration\n{pp_decl}
Nested error message:\n").to_string $ do
{ if env.is_protected src then add_protected_decl decl else add_decl decl,
-- we test that the declaration value type-checks, so that we get the decorated error message
-- without this line, the type-checking might fail outside the `decorate_error`.
decorate_error "proof doesn't type-check. " $ type_check decl.value }
/--
Make a new copy of a declaration,
replacing fragments of the names of identifiers in the type and the body using the function `f`.
This is used to implement `@[to_additive]`.
-/
meta def transform_decl_with_prefix_fun (f : name → option name) (replace_all trace : bool)
(relevant : name_map ℕ) (ignore reorder : name_map $ list ℕ) (src tgt : name) (attrs : list name)
: command :=
do -- In order to ensure that attributes are copied correctly we must transform declarations and
-- attributes in the right order:
-- first generate the transformed main declaration
transform_decl_with_prefix_fun_aux f replace_all trace relevant ignore reorder src tgt src,
ls ← get_eqn_lemmas_for tt src,
-- now transform all of the equational lemmas
ls.mmap' $
transform_decl_with_prefix_fun_aux f replace_all trace relevant ignore reorder src tgt,
-- copy attributes for the equational lemmas so that they know if they are refl lemmas
ls.mmap' (λ src_eqn, do
let tgt_eqn := src_eqn.map_prefix (λ n, if n = src then some tgt else none),
attrs.mmap' (λ n, copy_attribute' n src_eqn tgt_eqn)),
-- set the transformed equation lemmas as equation lemmas for the new declaration
ls.mmap' (λ src_eqn, do
e ← get_env,
let tgt_eqn := src_eqn.map_prefix (λ n, if n = src then some tgt else none),
set_env (e.add_eqn_lemma tgt_eqn)),
-- copy attributes for the main declaration, this needs the equational lemmas to exist already
attrs.mmap' (λ n, copy_attribute' n src tgt)
/--
Make a new copy of a declaration, replacing fragments of the names of identifiers in the type and
the body using the dictionary `dict`.
This is used to implement `@[to_additive]`.
-/
meta def transform_decl_with_prefix_dict (dict : name_map name) (replace_all trace : bool)
(relevant : name_map ℕ) (ignore reorder : name_map $ list ℕ) (src tgt : name) (attrs : list name)
: command :=
transform_decl_with_prefix_fun dict.find replace_all trace relevant ignore reorder src tgt attrs
end tactic
|
fa349a208f85502897791cc17507e09904cbcaf8
|
4bcaca5dc83d49803f72b7b5920b75b6e7d9de2d
|
/stage0/src/Lean/Parser/Do.lean
|
94c60efe3152ea7ee47c9be9db68afa7cef77464
|
[
"Apache-2.0"
] |
permissive
|
subfish-zhou/leanprover-zh_CN.github.io
|
30b9fba9bd790720bd95764e61ae796697d2f603
|
8b2985d4a3d458ceda9361ac454c28168d920d3f
|
refs/heads/master
| 1,689,709,967,820
| 1,632,503,056,000
| 1,632,503,056,000
| 409,962,097
| 1
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 7,260
|
lean
|
/-
Copyright (c) 2020 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
import Lean.Parser.Term
namespace Lean
namespace Parser
builtin_initialize registerBuiltinParserAttribute `builtinDoElemParser `doElem
builtin_initialize registerBuiltinDynamicParserAttribute `doElemParser `doElem
@[inline] def doElemParser (rbp : Nat := 0) : Parser :=
categoryParser `doElem rbp
namespace Term
def leftArrow : Parser := unicodeSymbol " ← " " <- "
@[builtinTermParser] def liftMethod := leading_parser:minPrec leftArrow >> termParser
def doSeqItem := leading_parser ppLine >> doElemParser >> optional "; "
def doSeqIndent := leading_parser many1Indent doSeqItem
def doSeqBracketed := leading_parser "{" >> withoutPosition (many1 doSeqItem) >> ppLine >> "}"
def doSeq := doSeqBracketed <|> doSeqIndent
def termBeforeDo := withForbidden "do" termParser
attribute [runBuiltinParserAttributeHooks] doSeq termBeforeDo
builtin_initialize
register_parser_alias doSeq
register_parser_alias termBeforeDo
def notFollowedByRedefinedTermToken :=
-- Remark: we don't currently support `open` and `set_option` in `do`-blocks, but we include them in the following list to fix the ambiguity
-- "open" command following `do`-block. If we don't add `do`, then users would have to indent `do` blocks or use `{ ... }`.
notFollowedBy ("set_option" <|> "open" <|> "if" <|> "match" <|> "let" <|> "have" <|> "do" <|> "dbg_trace" <|> "assert!" <|> "for" <|> "unless" <|> "return" <|> symbol "try") "token at 'do' element"
@[builtinDoElemParser] def doLet := leading_parser "let " >> optional "mut " >> letDecl
@[builtinDoElemParser] def doLetRec := leading_parser group ("let " >> nonReservedSymbol "rec ") >> letRecDecls
def doIdDecl := leading_parser atomic (ident >> optType >> leftArrow) >> doElemParser
def doPatDecl := leading_parser atomic (termParser >> leftArrow) >> doElemParser >> optional (checkColGt >> " | " >> doElemParser)
@[builtinDoElemParser] def doLetArrow := leading_parser withPosition ("let " >> optional "mut " >> (doIdDecl <|> doPatDecl))
-- We use `letIdDeclNoBinders` to define `doReassign`.
-- Motivation: we do not reassign functions, and avoid parser conflict
def letIdDeclNoBinders := node `Lean.Parser.Term.letIdDecl $ atomic (ident >> pushNone >> optType >> " := ") >> termParser
@[builtinDoElemParser] def doReassign := leading_parser notFollowedByRedefinedTermToken >> (letIdDeclNoBinders <|> letPatDecl)
@[builtinDoElemParser] def doReassignArrow := leading_parser notFollowedByRedefinedTermToken >> withPosition (doIdDecl <|> doPatDecl)
@[builtinDoElemParser] def doHave := leading_parser "have " >> Term.haveDecl
/-
In `do` blocks, we support `if` without an `else`. Thus, we use indentation to prevent examples such as
```
if c_1 then
if c_2 then
action_1
else
action_2
```
from being parsed as
```
if c_1 then {
if c_2 then {
action_1
} else {
action_2
}
}
```
We also have special support for `else if` because we don't want to write
```
if c_1 then
action_1
else if c_2 then
action_2
else
action_3
```
-/
def elseIf := atomic (group (withPosition (" else " >> checkLineEq >> " if ")))
-- ensure `if $e then ...` still binds to `e:term`
def doIfLetPure := leading_parser " := " >> termParser
def doIfLetBind := leading_parser " ← " >> termParser
def doIfLet := nodeWithAntiquot "doIfLet" `Lean.Parser.Term.doIfLet <| "let " >> termParser >> (doIfLetPure <|> doIfLetBind)
def doIfProp := nodeWithAntiquot "doIfProp" `Lean.Parser.Term.doIfProp <| optIdent >> termParser
def doIfCond := withAntiquot (mkAntiquot "doIfCond" none (anonymous := false)) <| doIfLet <|> doIfProp
@[builtinDoElemParser] def doIf := leading_parser withPosition $
"if " >> doIfCond >> " then " >> doSeq
>> many (checkColGe "'else if' in 'do' must be indented" >> group (elseIf >> doIfCond >> " then " >> doSeq))
>> optional (checkColGe "'else' in 'do' must be indented" >> " else " >> doSeq)
@[builtinDoElemParser] def doUnless := leading_parser "unless " >> withForbidden "do" termParser >> "do " >> doSeq
def doForDecl := leading_parser termParser >> " in " >> withForbidden "do" termParser
@[builtinDoElemParser] def doFor := leading_parser "for " >> sepBy1 doForDecl ", " >> "do " >> doSeq
def doMatchAlts := matchAlts (rhsParser := doSeq)
@[builtinDoElemParser] def doMatch := leading_parser:leadPrec "match " >> optional Term.generalizingParam >> sepBy1 matchDiscr ", " >> optType >> " with " >> doMatchAlts
def doCatch := leading_parser atomic ("catch " >> binderIdent) >> optional (" : " >> termParser) >> darrow >> doSeq
def doCatchMatch := leading_parser "catch " >> doMatchAlts
def doFinally := leading_parser "finally " >> doSeq
@[builtinDoElemParser] def doTry := leading_parser "try " >> doSeq >> many (doCatch <|> doCatchMatch) >> optional doFinally
@[builtinDoElemParser] def doBreak := leading_parser "break"
@[builtinDoElemParser] def doContinue := leading_parser "continue"
@[builtinDoElemParser] def doReturn := leading_parser:leadPrec withPosition ("return " >> optional (checkLineEq >> termParser))
@[builtinDoElemParser] def doDbgTrace := leading_parser:leadPrec "dbg_trace " >> ((interpolatedStr termParser) <|> termParser)
@[builtinDoElemParser] def doAssert := leading_parser:leadPrec "assert! " >> termParser
/-
We use `notFollowedBy` to avoid counterintuitive behavior.
For example, the `if`-term parser
doesn't enforce indentation restrictions, but we don't want it to be used when `doIf` fails.
Note that parser priorities would not solve this problem since the `doIf` parser is failing while the `if`
parser is succeeding. The first `notFollowedBy` prevents this problem.
Consider the `doElem` `x := (a, b⟩` it contains an error since we are using `⟩` instead of `)`. Thus, `doReassign` parser fails.
However, `doExpr` would succeed consuming just `x`, and cryptic error message is generated after that.
The second `notFollowedBy` prevents this problem.
-/
@[builtinDoElemParser] def doExpr := leading_parser notFollowedByRedefinedTermToken >> termParser >> notFollowedBy (symbol ":=" <|> symbol "←" <|> symbol "<-") "unexpected token after 'expr' in 'do' block"
@[builtinDoElemParser] def doNested := leading_parser "do " >> doSeq
@[builtinTermParser] def «do» := leading_parser:argPrec "do " >> doSeq
@[builtinTermParser] def doElem.quot : Parser := leading_parser "`(doElem|" >> incQuotDepth doElemParser >> ")"
/- macros for using `unless`, `for`, `try`, `return` as terms. They expand into `do unless ...`, `do for ...`, `do try ...`, and `do return ...` -/
@[builtinTermParser] def termUnless := leading_parser "unless " >> withForbidden "do" termParser >> "do " >> doSeq
@[builtinTermParser] def termFor := leading_parser "for " >> sepBy1 doForDecl ", " >> "do " >> doSeq
@[builtinTermParser] def termTry := leading_parser "try " >> doSeq >> many (doCatch <|> doCatchMatch) >> optional doFinally
@[builtinTermParser] def termReturn := leading_parser:leadPrec withPosition ("return " >> optional (checkLineEq >> termParser))
end Term
end Parser
end Lean
|
0b0d4eab2c719df07dfc429769d4057b69b44ec0
|
6fca17f8d5025f89be1b2d9d15c9e0c4b4900cbf
|
/src/game/world1/level1.lean
|
e9f9595f2248130bb62ffd878ae5ad0d5f489594
|
[
"Apache-2.0"
] |
permissive
|
arolihas/natural_number_game
|
4f0c93feefec93b8824b2b96adff8b702b8b43ce
|
8e4f7b4b42888a3b77429f90cce16292bd288138
|
refs/heads/master
| 1,621,872,426,808
| 1,586,270,467,000
| 1,586,270,467,000
| 253,648,466
| 0
| 0
| null | 1,586,219,694,000
| 1,586,219,694,000
| null |
UTF-8
|
Lean
| false
| false
| 3,781
|
lean
|
import mynat.definition -- imports the natural numbers {0,1,2,3,4,...}.
import mynat.add -- imports definition of addition on the natural numbers.
import mynat.mul -- imports definition of multiplication on the natural numbers.
namespace mynat -- hide
-- World name : Tutorial world
/-
# Tutorial World
## Level 1: the `refl` tactic.
Let's learn some tactics! Let's start with the `refl` tactic. `refl` stands for "reflexivity", which is a fancy
way of saying that it will prove any goal of the form `A = A`. It doesn't matter how
complicated `A` is, all that matters is that the left hand side is *exactly equal* to the
right hand side (a computer scientist would say "definitionally equal"). I really mean
"press the same buttons on your computer in the same order" equal.
For example, `x * y + z = x * y + z` can be proved by `refl`, but `x + y = y + x` cannot.
Each level in this game involves proving a theorem or a lemma (a lemma is just a baby theorem).
The goal of the thereom will be a mathematical statement with a `⊢` just before it.
We will use tactics to manipulate and ultimately close (i.e. prove) these goals.
Let's see `refl` in action! At the bottom of the text in this box, there's a lemma,
which says that if $x$, $y$ and $z$ are natural numbers then $xy + z = xy + z$.
Locate this lemma (if you can't see the lemma and these instructions at the same time, make this box wider
by dragging the sides). Let's supply the proof. Click on the word `sorry` and then delete it.
When the system finishes being busy, you'll be able to see your goal -- the objective
of this level -- in the box on the top right. [NB if your system never finishes being busy, then
your computer is not running the javascript Lean which powers everything behind the scenes.
Try Chrome? Try not using private browsing?]
Remember that the goal is
the thing with the weird `⊢` thing just before it. The goal in this case is `x * y + z = x * y + z`,
where `x`, `y` and `z` are some of your very own natural numbers.
That's a pretty easy goal to prove -- you can just prove it with the `refl` tactic.
Where it used to say `sorry`, write
`refl,`
**and don't forget the comma**. Then hit enter to go onto the next line.
If all is well, Lean should tell you "Proof complete!" in the top right box, and there
should be no errors in the bottom right box. You just did the first
level of the tutorial! And you also learnt how to avoid by *far* the most
common mistake that beginner users make -- **every line must end with a comma**.
If things go weird and you don't understand why the top right box is empty,
check for missing commas. Also check you've spelt `refl` correctly: it's REFL
for "reflexivity".
For each level, the idea is to get Lean into this state: with the top right
box saying "Proof complete!" and the bottom right box empty (i.e. with no errors in).
If you want to be reminded about the `refl` tactic, you can click on the "Tactics" drop
down menu on the left. Resize the window if it's too small.
Now click on "next level" in the top right of your browser to go onto the second level of
tutorial world, where we'll learn about the `rw` tactic.
-/
/- Lemma : no-side-bar
For all natural numbers $x$, $y$ and $z$, we have $xy + z = xy + z$.
-/
lemma example1 (x y z : mynat) : x * y + z = x * y + z :=
begin [nat_num_game]
refl,
end
/- Tactic : refl
## Summary
`refl` proves goals of the form `X = X`.
## Details
The `refl` tactic will close any goal of the form `A = B`
where `A` and `B` are *exactly the same thing*.
### Example:
If it looks like this in the top right hand box:
```
a b c d : mynat
⊢ (a + b) * (c + d) = (a + b) * (c + d)
```
then
`refl,`
will close the goal and solve the level. Don't forget the comma.
-/
end mynat -- hide
|
db712d3f9da79727971e4df09e3e83886d80a0e7
|
a9d0fb7b0e4f802bd3857b803e6c5c23d87fef91
|
/tests/lean/run/match_expr.lean
|
c86e784aea8f2702179bf47c711a48190a493c91
|
[
"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
| 407
|
lean
|
open tactic
axiom Sorry : ∀ {A:Type*}, A
example (a b c : nat) (h₀ : c > 0) (h₁ : a > 1) (h₂ : b > 0) : a + b + c = 0 :=
by do
[x, y] ← match_target_subexpr `(λ x y : nat, x + y) | failed,
trace "------ subterms -------",
trace x, trace y,
(h, [z]) ← match_hypothesis `(λ x : nat, x > 1) | failed,
trace "--- hypothesis of the form x > 1 ---",
trace h, trace z,
refine `(Sorry)
|
97064f172c52b29acf51336884f416090c026d30
|
36c7a18fd72e5b57229bd8ba36493daf536a19ce
|
/hott/types/univ.hlean
|
720e37fada740d37d23e7bb87a5d3f802f088824
|
[
"Apache-2.0"
] |
permissive
|
YHVHvx/lean
|
732bf0fb7a298cd7fe0f15d82f8e248c11db49e9
|
038369533e0136dd395dc252084d3c1853accbf2
|
refs/heads/master
| 1,610,701,080,210
| 1,449,128,595,000
| 1,449,128,595,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 4,894
|
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 universe
-/
-- see also init.ua
import .bool .trunc .lift .pullback
open is_trunc bool lift unit eq pi equiv equiv.ops sum sigma fiber prod pullback is_equiv sigma.ops
pointed
namespace univ
universe variables u v
variables {A B : Type.{u}} {a : A} {b : B}
/- Pathovers -/
definition eq_of_pathover_ua {f : A ≃ B} (p : a =[ua f] b) : f a = b :=
!cast_ua⁻¹ ⬝ tr_eq_of_pathover p
definition pathover_ua {f : A ≃ B} (p : f a = b) : a =[ua f] b :=
pathover_of_tr_eq (!cast_ua ⬝ p)
definition pathover_ua_equiv (f : A ≃ B) : (a =[ua f] b) ≃ (f a = b) :=
equiv.MK eq_of_pathover_ua
pathover_ua
abstract begin
intro p, unfold [pathover_ua,eq_of_pathover_ua],
rewrite [to_right_inv !pathover_equiv_tr_eq, inv_con_cancel_left]
end end
abstract begin
intro p, unfold [pathover_ua,eq_of_pathover_ua],
rewrite [con_inv_cancel_left, to_left_inv !pathover_equiv_tr_eq]
end end
/- Properties which can be disproven for the universe -/
definition not_is_hset_type0 : ¬is_hset Type₀ :=
assume H : is_hset Type₀,
absurd !is_hset.elim eq_bnot_ne_idp
definition not_is_hset_type : ¬is_hset Type.{u} :=
assume H : is_hset Type,
absurd (is_trunc_is_embedding_closed lift star) not_is_hset_type0
definition not_double_negation_elimination0 : ¬Π(A : Type₀), ¬¬A → A :=
begin
intro f,
have u : ¬¬bool, by exact (λg, g tt),
let H1 := apdo f eq_bnot,
let H2 := apo10 H1 u,
have p : eq_bnot ▸ u = u, from !is_hprop.elim,
rewrite p at H2,
let H3 := eq_of_pathover_ua H2, esimp at H3, --TODO: use apply ... at after #700
exact absurd H3 (bnot_ne (f bool u)),
end
definition not_double_negation_elimination : ¬Π(A : Type), ¬¬A → A :=
begin
intro f,
apply not_double_negation_elimination0,
intro A nna, refine down (f _ _),
intro na,
have ¬A, begin intro a, exact absurd (up a) na end,
exact absurd this nna
end
definition not_excluded_middle : ¬Π(A : Type), A + ¬A :=
begin
intro f,
apply not_double_negation_elimination,
intro A nna,
induction (f A) with a na,
exact a,
exact absurd na nna
end
definition characteristic_map [unfold 2] {B : Type.{u}} (p : Σ(A : Type.{max u v}), A → B)
(b : B) : Type.{max u v} :=
by induction p with A f; exact fiber f b
definition characteristic_map_inv [unfold 2] {B : Type.{u}} (P : B → Type.{max u v}) :
Σ(A : Type.{max u v}), A → B :=
⟨(Σb, P b), pr1⟩
definition sigma_arrow_equiv_arrow_univ [constructor] (B : Type.{u}) :
(Σ(A : Type.{max u v}), A → B) ≃ (B → Type.{max u v}) :=
begin
fapply equiv.MK,
{ exact characteristic_map},
{ exact characteristic_map_inv},
{ intro P, apply eq_of_homotopy, intro b, esimp, apply ua, apply fiber_pr1},
{ intro p, induction p with A f, fapply sigma_eq: esimp,
{ apply ua, apply sigma_fiber_equiv },
{ apply arrow_pathover_constant_right, intro v,
rewrite [-cast_def _ v, cast_ua_fn],
esimp [sigma_fiber_equiv,equiv.trans,equiv.symm,sigma_comm_equiv,comm_equiv_unc],
induction v with b w, induction w with a p, esimp, exact p⁻¹}}
end
definition is_object_classifier (f : A → B)
: pullback_square (pointed_fiber f) (fiber f) f Pointed.carrier :=
pullback_square.mk
(λa, idp)
(is_equiv_of_equiv_of_homotopy
(calc
A ≃ Σb, fiber f b : sigma_fiber_equiv
... ≃ Σb (v : ΣX, X = fiber f b), v.1 : sigma_equiv_sigma_id
(λb, !sigma_equiv_of_is_contr_left)
... ≃ Σb X (p : X = fiber f b), X : sigma_equiv_sigma_id
(λb, !sigma_assoc_equiv)
... ≃ Σb X (x : X), X = fiber f b : sigma_equiv_sigma_id
(λb, sigma_equiv_sigma_id
(λX, !comm_equiv_nondep))
... ≃ Σb (v : ΣX, X), v.1 = fiber f b : sigma_equiv_sigma_id
(λb, !sigma_assoc_equiv⁻¹)
... ≃ Σb (Y : Type*), Y = fiber f b : sigma_equiv_sigma_id
(λb, sigma_equiv_sigma (Pointed.sigma_char)⁻¹
(λv, sigma.rec_on v (λx y, equiv.refl)))
... ≃ Σ(Y : Type*) b, Y = fiber f b : sigma_comm_equiv
... ≃ pullback Pointed.carrier (fiber f) : !pullback.sigma_char⁻¹ᵉ
)
proof λb, idp qed)
end univ
|
489b80d1b5ce77011b969ce0914c22423b4e3be1
|
4efff1f47634ff19e2f786deadd394270a59ecd2
|
/src/algebra/category/Mon/limits.lean
|
d373283921bdea2f01e06eaff96c9a8facc84e3b
|
[
"Apache-2.0"
] |
permissive
|
agjftucker/mathlib
|
d634cd0d5256b6325e3c55bb7fb2403548371707
|
87fe50de17b00af533f72a102d0adefe4a2285e8
|
refs/heads/master
| 1,625,378,131,941
| 1,599,166,526,000
| 1,599,166,526,000
| 160,748,509
| 0
| 0
|
Apache-2.0
| 1,544,141,789,000
| 1,544,141,789,000
| null |
UTF-8
|
Lean
| false
| false
| 6,594
|
lean
|
/-
Copyright (c) 2020 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import algebra.group.pi
import algebra.category.Mon.basic
import category_theory.limits.types
import category_theory.limits.creates
/-!
# The category of (commutative) (additive) monoids has all limits
Further, these limits are preserved by the forgetful functor --- that is,
the underlying types are just the limits in the category of types.
-/
open category_theory
open category_theory.limits
universe u
namespace Mon
variables {J : Type u} [small_category J]
@[to_additive]
instance monoid_obj (F : J ⥤ Mon) (j) :
monoid ((F ⋙ forget Mon).obj j) :=
by { change monoid (F.obj j), apply_instance }
/--
The flat sections of a functor into `Mon` form a submonoid of all sections.
-/
@[to_additive
"The flat sections of a functor into `AddMon` form an additive submonoid of all sections."]
def sections_submonoid (F : J ⥤ Mon) :
submonoid (Π j, F.obj j) :=
{ carrier := (F ⋙ forget Mon).sections,
one_mem' := λ j j' f, by simp,
mul_mem' := λ a b ah bh j j' f,
begin
simp only [forget_map_eq_coe, functor.comp_map, monoid_hom.map_mul, pi.mul_apply],
dsimp [functor.sections] at ah bh,
rw [ah f, bh f],
end }
@[to_additive]
instance limit_monoid (F : J ⥤ Mon) :
monoid (types.limit_cone (F ⋙ forget Mon.{u})).X :=
(sections_submonoid F).to_monoid
/-- `limit.π (F ⋙ forget Mon) j` as a `monoid_hom`. -/
@[to_additive "`limit.π (F ⋙ forget AddMon) j` as an `add_monoid_hom`."]
def limit_π_monoid_hom (F : J ⥤ Mon.{u}) (j) :
(types.limit_cone (F ⋙ forget Mon)).X →* (F ⋙ forget Mon).obj j :=
{ to_fun := (types.limit_cone (F ⋙ forget Mon)).π.app j,
map_one' := rfl,
map_mul' := λ x y, rfl }
namespace has_limits
-- The next two definitions are used in the construction of `has_limits Mon`.
-- After that, the limits should be constructed using the generic limits API,
-- e.g. `limit F`, `limit.cone F`, and `limit.is_limit F`.
/--
Construction of a limit cone in `Mon`.
(Internal use only; use the limits API.)
-/
@[to_additive "(Internal use only; use the limits API.)"]
def limit_cone (F : J ⥤ Mon) : cone F :=
{ X := Mon.of (types.limit_cone (F ⋙ forget _)).X,
π :=
{ app := limit_π_monoid_hom F,
naturality' := λ j j' f,
monoid_hom.coe_inj ((types.limit_cone (F ⋙ forget _)).π.naturality f) } }
/--
Witness that the limit cone in `Mon` is a limit cone.
(Internal use only; use the limits API.)
-/
@[to_additive "(Internal use only; use the limits API.)"]
def limit_cone_is_limit (F : J ⥤ Mon) : is_limit (limit_cone F) :=
begin
refine is_limit.of_faithful
(forget Mon) (types.limit_cone_is_limit _)
(λ s, ⟨_, _, _⟩) (λ s, rfl); tidy,
end
end has_limits
open has_limits
/-- The category of monoids has all limits. -/
@[irreducible, to_additive]
instance has_limits : has_limits Mon :=
{ has_limits_of_shape := λ J 𝒥, by exactI
{ has_limit := λ F,
{ cone := limit_cone F,
is_limit := limit_cone_is_limit F } } }
/--
The forgetful functor from monoids to types preserves all limits. (That is, the underlying
types could have been computed instead as limits in the category of types.)
-/
@[to_additive]
instance forget_preserves_limits : preserves_limits (forget Mon) :=
{ preserves_limits_of_shape := λ J 𝒥, by exactI
{ preserves_limit := λ F, preserves_limit_of_preserves_limit_cone
(limit_cone_is_limit F) (types.limit_cone_is_limit (F ⋙ forget _)) } }
end Mon
namespace CommMon
variables {J : Type u} [small_category J]
@[to_additive]
instance comm_monoid_obj (F : J ⥤ CommMon) (j) :
comm_monoid ((F ⋙ forget CommMon).obj j) :=
by { change comm_monoid (F.obj j), apply_instance }
@[to_additive]
instance limit_comm_monoid (F : J ⥤ CommMon) :
comm_monoid (types.limit_cone (F ⋙ forget CommMon.{u})).X :=
@submonoid.to_comm_monoid (Π j, F.obj j) _
(Mon.sections_submonoid (F ⋙ forget₂ CommMon Mon.{u}))
/--
We show that the forgetful functor `CommMon ⥤ Mon` creates limits.
All we need to do is notice that the limit point has a `comm_monoid` instance available,
and then reuse the existing limit.
-/
@[to_additive]
instance (F : J ⥤ CommMon) : creates_limit F (forget₂ CommMon Mon.{u}) :=
creates_limit_of_reflects_iso (λ c' t,
{ lifted_cone :=
{ X := CommMon.of (types.limit_cone (F ⋙ forget CommMon)).X,
π :=
{ app := Mon.limit_π_monoid_hom (F ⋙ forget₂ CommMon Mon),
naturality' := (Mon.has_limits.limit_cone (F ⋙ forget₂ _ _)).π.naturality, } },
valid_lift := is_limit.unique_up_to_iso (Mon.has_limits.limit_cone_is_limit _) t,
makes_limit := is_limit.of_faithful (forget₂ CommMon Mon.{u}) (Mon.has_limits.limit_cone_is_limit _)
(λ s, _) (λ s, rfl) })
/--
A choice of limit cone for a functor into `CommMon`.
(Generally, you'll just want to use `limit F`.)
-/
@[to_additive "A choice of limit cone for a functor into `CommMon`. (Generally, you'll just want to use `limit F`.)"]
def limit_cone (F : J ⥤ CommMon) : cone F :=
lift_limit (limit.is_limit (F ⋙ (forget₂ CommMon Mon.{u})))
/--
The chosen cone is a limit cone.
(Generally, you'll just want to use `limit.cone F`.)
-/
@[to_additive "The chosen cone is a limit cone. (Generally, you'll just want to use `limit.cone F`.)"]
def limit_cone_is_limit (F : J ⥤ CommMon) : is_limit (limit_cone F) :=
lifted_limit_is_limit _
/-- The category of commutative monoids has all limits. -/
@[irreducible, to_additive]
instance has_limits : has_limits CommMon :=
{ has_limits_of_shape := λ J 𝒥, by exactI
{ has_limit := λ F, has_limit_of_created F (forget₂ CommMon Mon) } }
/--
The forgetful functor from commutative monoids to monoids preserves all limits.
(That is, the underlying monoid could have been computed instead as limits in the category of monoids.)
-/
@[to_additive AddCommMon.forget₂_AddMon_preserves_limits]
instance forget₂_Mon_preserves_limits : preserves_limits (forget₂ CommMon Mon) :=
{ preserves_limits_of_shape := λ J 𝒥,
{ preserves_limit := λ F, by apply_instance } }
/--
The forgetful functor from commutative monoids to types preserves all limits. (That is, the underlying
types could have been computed instead as limits in the category of types.)
-/
@[to_additive]
instance forget_preserves_limits : preserves_limits (forget CommMon) :=
{ preserves_limits_of_shape := λ J 𝒥, by exactI
{ preserves_limit := λ F, limits.comp_preserves_limit (forget₂ CommMon Mon) (forget Mon) } }
end CommMon
|
945337e9d2722832121dbc2992c4e38ab835e605
|
9db059bff49b1090a86ec0050ac6c577eb16ac67
|
/src/meetings/topology.lean
|
d8a2570f410fa01a83f282418c24b6c982671348
|
[] |
no_license
|
fpvandoorn/Harvard-tutoring
|
d64cd75c4c529009ee562c30e9cb245fe237e760
|
a8846c08e32cdc7b91a7e28adfa5d9b2810088b0
|
refs/heads/master
| 1,680,870,428,641
| 1,617,022,194,000
| 1,617,022,194,000
| 330,297,467
| 1
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 6,938
|
lean
|
import tactic
import analysis.special_functions.trigonometric
/-
# Topology in Lean
In this and the next meetings we will discuss how to do various areas of math in mathlib.
We will start with topology.
-/
noncomputable theory
open set topological_space filter
open_locale topological_space filter big_operators classical
#check @topological_space
example {X} {g : set (set X)} : topological_space X :=
{ is_open :=
⋂ (t : topological_space X) (h : ∀ s ∈ g, t.is_open s),
{ s | t.is_open s },
is_open_univ := _,
is_open_inter := _,
is_open_sUnion := _ }
#check @topological_space.generate_open
/-
There is a Galois insertion between sets and topological spaces.
As in last week, this gives topological spaces the structure of a complete lattice.
However, in mathlib the order is given by *reverse* inclusion.
So e.g. `⊥` is the discrete topology and `⊤` is the indiscrete topology.
-/
#check @topological_space.complete_lattice
/-- The topology on `X × Y` is the coarsest topology
that makes both projections continuous. -/
example {X Y : Type*} [t₁ : topological_space X]
[t₂ : topological_space Y] : topological_space (X × Y) :=
induced prod.fst t₁ ⊓ induced prod.snd t₂
#check @continuous
#check @is_open_compl_iff
example {X Y : Type*} [topological_space X] [topological_space Y] (f : X → Y) :
continuous f ↔ ∀ C : set Y, is_closed C → is_closed (f ⁻¹' C) :=
begin
rw [continuous_def],
split,
{
intros h C hC, rw [← is_open_compl_iff] at hC ⊢, rw [← preimage_compl], apply h, assumption,
},
sorry
end
example {f : ℝ → ℝ} (hf : continuous f) :
continuous (λ x, x * f (x ^ 2 + 37)) :=
by continuity
class my_metric_space (α : Type*) :=
(dist : α → α → ℝ)
(dist_self : ∀ x : α, dist x x = 0)
(eq_of_dist_eq_zero : ∀ {x y : α}, dist x y = 0 → x = y)
(dist_comm : ∀ x y : α, dist x y = dist y x)
(dist_triangle : ∀ x y z : α, dist x z ≤ dist x y + dist y z)
/- Every metric space (as defined in mathlib) is a topological space. -/
example {X : Type} [metric_space X] (U : set X) :
is_open U ↔ ∀ x ∈ U, ∃ ε > 0, metric.ball x ε ⊆ U :=
metric.is_open_iff
/-
The above is not quite the definition in Lean.
Suppose that `X` and `Y` are metric spaces,
we can define the topology on `X × Y` in two ways:
* the product topology of `X` and `Y`
* the topology given by the metric space `X × Y`.
These are provably the same, but not exactly the same.
To avoid this distinction,
we add the correct topological space as a field
-/
class my_metric_space2 (α : Type*) :=
(dist : α → α → ℝ)
(dist_self : ∀ x : α, dist x x = 0)
(eq_of_dist_eq_zero : ∀ {x y : α}, dist x y = 0 → x = y)
(dist_comm : ∀ x y : α, dist x y = dist y x)
(dist_triangle : ∀ x y z : α, dist x z ≤ dist x y + dist y z)
(topology : topological_space α)
(topology_opens : ∀ U : set α, is_open U ↔ ∀ x ∈ U, ∃ ε > 0, { y | dist x y < ε } ⊆ U)
instance my_metric_space2.topological_space {X : Type*}
[my_metric_space2 X] : topological_space X :=
my_metric_space2.topology
example {X Y : Type*} [my_metric_space2 X] [my_metric_space2 Y] :
my_metric_space2 (X × Y) :=
{ dist := sorry,
dist_self := sorry,
eq_of_dist_eq_zero := sorry,
dist_comm := sorry,
dist_triangle := sorry,
topology := prod.topological_space,
topology_opens := sorry }
#print uniform_space
/- You can now define the product metric space
where the `topology` field is the product topology. -/
/- This is still not quite the definition of metric space in mathlib,
which is defined in terms of *uniform spaces*,
but I won't get into that now -/
/-! ## Limits -/
/-
We want to define multiple limits:
* As x ⟶ a, then f(x) ⟶ b
* As n ⟶ ∞, then a(n) ⟶ b⁻
* As x ⟶ a⁺ (x ≠ a), then f(x) ⟶ - ∞
If we want all combinations of a, a⁺, a⁻, ± ∞,
possibly with the added condition that x ≠ a.
We could even take some crazier limits, like constraining `x` to be rational.
Even worse is the composition of limits:
* If
- as x ⟶ a, then f(x) ⟶ b
- as y ⟶ b, then g(y) ⟶ c
then
- as x ⟶ a, then g(f(x)) ⟶ c
For a uniform way of dealing with limits we use filters.
-/
#print filter
/- The neighborhood filter `𝓝 a` -/
#check @mem_nhds_sets_iff
/- The filter `at_top` (at ∞) -/
#check @mem_at_top_sets
/- The principal filter `𝓟 A = { B | A ⊆ B } `-/
#check @mem_principal_sets
/-
Now we can define the limit
* As x ⟶ a, then f(x) ⟶ b
as follows
-/
definition simple_limit {X Y} [topological_space X]
[topological_space Y] (f : X → Y) (a : X) (b : Y) : Prop :=
∀ V ∈ 𝓝 b, f ⁻¹' V ∈ 𝓝 a
/- In full generality, the limit is defined as follows.
Filters are ordered by *reverse* inclusion. -/
def my_tendsto {X Y} (f : X → Y) (l₁ : filter X) (l₂ : filter Y) :=
l₁.map f ≤ l₂
lemma tendsto.comp {X Y Z} {f : X → Y} {g : Y → Z}
{x : filter X} {y : filter Y} {z : filter Z}
(hg : tendsto g y z) (hf : tendsto f x y) :
tendsto (g ∘ f) x z :=
calc map (g ∘ f) x = map g (map f x) : by rw [map_map]
... ≤ map g y : map_mono hf
... ≤ z : hg
/-
Here are some propositions:
* For `N` large enough, `P(N)`
* For `y` close enough to `z`, `P(y)`
* For almost every `y`, `P(y)`
These are all examples of `{x | P(x)} ∈ F`
for some filter `F`. Notation: `∀ᶠ x in F, P(x)`
-/
example {X} [topological_space X] (P : X → Prop) (y : X) :
(∀ᶠ x in 𝓝 y, P x) ↔
∃ (U : set X), (∀ x ∈ U, P x) ∧ is_open U ∧ y ∈ U :=
eventually_nhds_iff
/- We can formulate topological properties
in terms of filters -/
#check @t2_iff_nhds
#print t2_space
#check @ne_bot_iff
#check @empty_in_sets_eq_bot
#print is_compact
#check @cluster_pt_iff
#check @compact_iff_finite_subcover
#check @complete_space
#print instances locally_compact_space
/- Heine-Borel -/
#check @metric.compact_iff_closed_bounded
/- ℝⁿ is "proper" -/
example (n : ℕ) : proper_space (fin n → ℝ) :=
by apply_instance
/- We can use limits to define infinite sums.
Note: the default sum for mathlib only exists for
absolutely convergent sequences, but has some nice properties,
like invariance under reordering. -/
variables {I X : Type*} [topological_space X] [add_comm_group X]
[topological_add_group X]
def my_has_sum (f : I → X) (a : X) : Prop :=
tendsto (λ A : finset I, ∑ b in A, f b) at_top (𝓝 a)
/- We can pick a value for the sum.
This is only well-behaved if X is a T₂-space. -/
def my_tsum (f : I → X) :=
if h : ∃ a, my_has_sum f a then classical.some h else 0
example [t2_space X] (f : I → X) {a₁ a₂ : X} :
my_has_sum f a₁ → my_has_sum f a₂ → a₁ = a₂ :=
tendsto_nhds_unique
example [t2_space X] (f : ℕ → X) :
tendsto (λ i, ∑' k, f (k + i)) at_top (𝓝 0) :=
tendsto_sum_nat_add f
|
9a05ebb9de36c14fedff903871173eb9ff16178a
|
856e2e1615a12f95b551ed48fa5b03b245abba44
|
/src/algebra/pointwise.lean
|
996ff9a035279cb4e1f63daf06406adc6d6fa1b2
|
[
"Apache-2.0"
] |
permissive
|
pimsp/mathlib
|
8b77e1ccfab21703ba8fbe65988c7de7765aa0e5
|
913318ca9d6979686996e8d9b5ebf7e74aae1c63
|
refs/heads/master
| 1,669,812,465,182
| 1,597,133,610,000
| 1,597,133,610,000
| 281,890,685
| 1
| 0
| null | 1,595,491,577,000
| 1,595,491,576,000
| null |
UTF-8
|
Lean
| false
| false
| 13,538
|
lean
|
/-
Copyright (c) 2019 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin, Floris van Doorn
-/
import algebra.module
import data.set.finite
/-!
# Pointwise addition, multiplication, and scalar multiplication of sets.
This file defines pointwise algebraic operations on sets.
* For a type `α` with multiplication, multiplication is defined on `set α` by taking
`s * t` to be the set of all `x * y` where `x ∈ s` and `y ∈ t`. Similarly for addition.
* For `α` a semigroup, `set α` is a semigroup.
* If `α` is a (commutative) monoid, we define an alias `set_semiring α` for `set α`, which then
becomes a (commutative) semiring with union as addition and pointwise multiplication as
multiplication.
* For a type `β` with scalar multiplication by another type `α`, this
file defines a scalar multiplication of `set β` by `set α` and a separate scalar
multiplication of `set β` by `α`.
Appropriate definitions and results are also transported to the additive theory via `to_additive`.
## Implementation notes
* The following expressions are considered in simp-normal form in a group:
`(λ h, h * g) ⁻¹' s`, `(λ h, g * h) ⁻¹' s`, `(λ h, h * g⁻¹) ⁻¹' s`, `(λ h, g⁻¹ * h) ⁻¹' s`,
`s * t`, `s⁻¹`, `(1 : set _)` (and similarly for additive variants).
Expressions equal to one of these will be simplified.
## Tags
set multiplication, set addition, pointwise addition, pointwise multiplication
-/
namespace set
open function
variables {α : Type*} {β : Type*} {s s₁ s₂ t t₁ t₂ u : set α} {a b : α} {x y : β}
/-! Properties about 1 -/
@[to_additive]
instance [has_one α] : has_one (set α) := ⟨{1}⟩
@[simp, to_additive]
lemma singleton_one [has_one α] : ({1} : set α) = 1 := rfl
@[simp, to_additive]
lemma mem_one [has_one α] : a ∈ (1 : set α) ↔ a = 1 := iff.rfl
@[to_additive]
lemma one_mem_one [has_one α] : (1 : α) ∈ (1 : set α) := eq.refl _
@[simp, to_additive]
theorem one_subset [has_one α] : 1 ⊆ s ↔ (1 : α) ∈ s := singleton_subset_iff
@[to_additive]
theorem one_nonempty [has_one α] : (1 : set α).nonempty := ⟨1, rfl⟩
@[simp, to_additive]
theorem image_one [has_one α] {f : α → β} : f '' 1 = {f 1} := image_singleton
/-! Properties about multiplication -/
@[to_additive]
instance [has_mul α] : has_mul (set α) := ⟨image2 has_mul.mul⟩
@[simp, to_additive]
lemma image2_mul [has_mul α] : image2 has_mul.mul s t = s * t := rfl
@[to_additive]
lemma mem_mul [has_mul α] : a ∈ s * t ↔ ∃ x y, x ∈ s ∧ y ∈ t ∧ x * y = a := iff.rfl
@[to_additive]
lemma mul_mem_mul [has_mul α] (ha : a ∈ s) (hb : b ∈ t) : a * b ∈ s * t := mem_image2_of_mem ha hb
@[to_additive add_image_prod]
lemma image_mul_prod [has_mul α] : (λ x : α × α, x.fst * x.snd) '' s.prod t = s * t := image_prod _
@[simp, to_additive]
lemma image_mul_left [group α] : (λ b, a * b) '' t = (λ b, a⁻¹ * b) ⁻¹' t :=
by { rw image_eq_preimage_of_inverse; intro c; simp }
@[simp, to_additive]
lemma image_mul_right [group α] : (λ a, a * b) '' t = (λ a, a * b⁻¹) ⁻¹' t :=
by { rw image_eq_preimage_of_inverse; intro c; simp }
@[to_additive]
lemma image_mul_left' [group α] : (λ b, a⁻¹ * b) '' t = (λ b, a * b) ⁻¹' t := by simp
@[to_additive]
lemma image_mul_right' [group α] : (λ a, a * b⁻¹) '' t = (λ a, a * b) ⁻¹' t := by simp
@[simp, to_additive]
lemma preimage_mul_left_one [group α] : (λ b, a * b) ⁻¹' 1 = {a⁻¹} :=
by rw [← image_mul_left', image_one, mul_one]
@[simp, to_additive]
lemma preimage_mul_right_one [group α] : (λ a, a * b) ⁻¹' 1 = {b⁻¹} :=
by rw [← image_mul_right', image_one, one_mul]
@[to_additive]
lemma preimage_mul_left_one' [group α] : (λ b, a⁻¹ * b) ⁻¹' 1 = {a} := by simp
@[to_additive]
lemma preimage_mul_right_one' [group α] : (λ a, a * b) ⁻¹' 1 = {b⁻¹} := by simp
@[simp, to_additive]
lemma mul_singleton [has_mul α] : s * {b} = (λ a, a * b) '' s := image2_singleton_right
@[simp, to_additive]
lemma singleton_mul [has_mul α] : {a} * t = (λ b, a * b) '' t := image2_singleton_left
@[simp, to_additive]
lemma singleton_mul_singleton [has_mul α] : ({a} : set α) * {b} = {a * b} := image2_singleton
@[to_additive set.add_semigroup]
instance [semigroup α] : semigroup (set α) :=
{ mul_assoc :=
by { intros, simp only [← image2_mul, image2_image2_left, image2_image2_right, mul_assoc] },
..set.has_mul }
@[to_additive set.add_monoid]
instance [monoid α] : monoid (set α) :=
{ mul_one := λ s, by { simp only [← singleton_one, mul_singleton, mul_one, image_id'] },
one_mul := λ s, by { simp only [← singleton_one, singleton_mul, one_mul, image_id'] },
..set.semigroup,
..set.has_one }
@[to_additive]
protected lemma mul_comm [comm_semigroup α] : s * t = t * s :=
by simp only [← image2_mul, image2_swap _ s, mul_comm]
@[to_additive set.add_comm_monoid]
instance [comm_monoid α] : comm_monoid (set α) :=
{ mul_comm := λ _ _, set.mul_comm, ..set.monoid }
@[to_additive]
lemma singleton.is_mul_hom [has_mul α] : is_mul_hom (singleton : α → set α) :=
{ map_mul := λ a b, singleton_mul_singleton.symm }
@[simp, to_additive]
lemma empty_mul [has_mul α] : ∅ * s = ∅ := image2_empty_left
@[simp, to_additive]
lemma mul_empty [has_mul α] : s * ∅ = ∅ := image2_empty_right
@[to_additive]
lemma mul_subset_mul [has_mul α] (h₁ : s₁ ⊆ t₁) (h₂ : s₂ ⊆ t₂) : s₁ * s₂ ⊆ t₁ * t₂ :=
image2_subset h₁ h₂
@[to_additive]
lemma union_mul [has_mul α] : (s ∪ t) * u = (s * u) ∪ (t * u) := image2_union_left
@[to_additive]
lemma mul_union [has_mul α] : s * (t ∪ u) = (s * t) ∪ (s * u) := image2_union_right
@[to_additive]
lemma Union_mul_left_image [has_mul α] : (⋃ a ∈ s, (λ x, a * x) '' t) = s * t :=
Union_image_left _
@[to_additive]
lemma Union_mul_right_image [has_mul α] : (⋃ a ∈ t, (λ x, x * a) '' s) = s * t :=
Union_image_right _
@[simp, to_additive]
lemma univ_mul_univ [monoid α] : (univ : set α) * univ = univ :=
begin
have : ∀x, ∃a b : α, a * b = x := λx, ⟨x, ⟨1, mul_one x⟩⟩,
simpa only [mem_mul, eq_univ_iff_forall, mem_univ, true_and]
end
/-- `singleton` is a monoid hom. -/
@[to_additive singleton_add_hom "singleton is an add monoid hom"]
def singleton_hom [monoid α] : α →* set α :=
{ to_fun := singleton, map_one' := rfl, map_mul' := λ a b, singleton_mul_singleton.symm }
@[to_additive]
lemma nonempty.mul [has_mul α] : s.nonempty → t.nonempty → (s * t).nonempty := nonempty.image2
@[to_additive]
lemma finite.mul [has_mul α] (hs : finite s) (ht : finite t) : finite (s * t) :=
hs.image2 _ ht
/-- multiplication preserves finiteness -/
@[to_additive "addition preserves finiteness"]
def fintype_mul [has_mul α] [decidable_eq α] (s t : set α) [hs : fintype s] [ht : fintype t] :
fintype (s * t : set α) :=
set.fintype_image2 _ s t
/-! Properties about inversion -/
@[to_additive set.has_neg'] -- todo: remove prime once name becomes available
instance [has_inv α] : has_inv (set α) :=
⟨preimage has_inv.inv⟩
@[simp, to_additive]
lemma mem_inv [has_inv α] : a ∈ s⁻¹ ↔ a⁻¹ ∈ s := iff.rfl
@[to_additive]
lemma inv_mem_inv [group α] : a⁻¹ ∈ s⁻¹ ↔ a ∈ s :=
by simp only [mem_inv, inv_inv]
@[simp, to_additive]
lemma inv_preimage [has_inv α] : has_inv.inv ⁻¹' s = s⁻¹ := rfl
@[simp, to_additive]
lemma image_inv [group α] : has_inv.inv '' s = s⁻¹ :=
by { simp only [← inv_preimage], rw [image_eq_preimage_of_inverse]; intro; simp only [inv_inv] }
@[simp, to_additive]
lemma inter_inv [has_inv α] : (s ∩ t)⁻¹ = s⁻¹ ∩ t⁻¹ := preimage_inter
@[simp, to_additive]
lemma union_inv [has_inv α] : (s ∪ t)⁻¹ = s⁻¹ ∪ t⁻¹ := preimage_union
@[simp, to_additive]
lemma compl_inv [has_inv α] : (sᶜ)⁻¹ = (s⁻¹)ᶜ := preimage_compl
@[simp, to_additive]
protected lemma inv_inv [group α] : s⁻¹⁻¹ = s :=
by { simp only [← inv_preimage, preimage_preimage, inv_inv, preimage_id'] }
@[simp, to_additive]
protected lemma univ_inv [group α] : (univ : set α)⁻¹ = univ := preimage_univ
/-! Properties about scalar multiplication -/
/-- Scaling a set: multiplying every element by a scalar. -/
instance has_scalar_set [has_scalar α β] : has_scalar α (set β) :=
⟨λ a, image (has_scalar.smul a)⟩
@[simp]
lemma image_smul [has_scalar α β] {t : set β} : (λ x, a • x) '' t = a • t := rfl
lemma mem_smul_set [has_scalar α β] {t : set β} : x ∈ a • t ↔ ∃ y, y ∈ t ∧ a • y = x := iff.rfl
lemma smul_mem_smul_set [has_scalar α β] {t : set β} (hy : y ∈ t) : a • y ∈ a • t :=
⟨y, hy, rfl⟩
lemma smul_set_union [has_scalar α β] {s t : set β} : a • (s ∪ t) = a • s ∪ a • t :=
by simp only [← image_smul, image_union]
@[simp]
lemma smul_set_empty [has_scalar α β] (a : α) : a • (∅ : set β) = ∅ :=
by rw [← image_smul, image_empty]
lemma smul_set_mono [has_scalar α β] {s t : set β} (h : s ⊆ t) : a • s ⊆ a • t :=
by { simp only [← image_smul, image_subset, h] }
/-- Pointwise scalar multiplication by a set of scalars. -/
instance [has_scalar α β] : has_scalar (set α) (set β) := ⟨image2 has_scalar.smul⟩
@[simp]
lemma image2_smul [has_scalar α β] {t : set β} : image2 has_scalar.smul s t = s • t := rfl
lemma mem_smul [has_scalar α β] {t : set β} : x ∈ s • t ↔ ∃ a y, a ∈ s ∧ y ∈ t ∧ a • y = x :=
iff.rfl
lemma image_smul_prod [has_scalar α β] {t : set β} :
(λ x : α × β, x.fst • x.snd) '' s.prod t = s • t :=
image_prod _
theorem range_smul_range [has_scalar α β] {ι κ : Type*} (b : ι → α) (c : κ → β) :
range b • range c = range (λ p : ι × κ, b p.1 • c p.2) :=
ext $ λ x, ⟨λ hx, let ⟨p, q, ⟨i, hi⟩, ⟨j, hj⟩, hpq⟩ := set.mem_smul.1 hx in
⟨(i, j), hpq ▸ hi ▸ hj ▸ rfl⟩,
λ ⟨⟨i, j⟩, h⟩, set.mem_smul.2 ⟨b i, c j, ⟨i, rfl⟩, ⟨j, rfl⟩, h⟩⟩
lemma singleton_smul [has_scalar α β] {t : set β} : ({a} : set α) • t = a • t :=
image2_singleton_left
section monoid
/-! `set α` as a `(∪,*)`-semiring -/
/-- An alias for `set α`, which has a semiring structure given by `∪` as "addition" and pointwise
multiplication `*` as "multiplication". -/
@[derive inhabited] def set_semiring (α : Type*) : Type* := set α
/-- The identitiy function `set α → set_semiring α`. -/
protected def up (s : set α) : set_semiring α := s
/-- The identitiy function `set_semiring α → set α`. -/
protected def set_semiring.down (s : set_semiring α) : set α := s
@[simp] protected lemma down_up {s : set α} : s.up.down = s := rfl
@[simp] protected lemma up_down {s : set_semiring α} : s.down.up = s := rfl
instance set_semiring.semiring [monoid α] : semiring (set_semiring α) :=
{ add := λ s t, (s ∪ t : set α),
zero := (∅ : set α),
add_assoc := union_assoc,
zero_add := empty_union,
add_zero := union_empty,
add_comm := union_comm,
zero_mul := λ s, empty_mul,
mul_zero := λ s, mul_empty,
left_distrib := λ _ _ _, mul_union,
right_distrib := λ _ _ _, union_mul,
..set.monoid }
instance set_semiring.comm_semiring [comm_monoid α] : comm_semiring (set_semiring α) :=
{ ..set.comm_monoid, ..set_semiring.semiring }
/-- A multiplicative action of a monoid on a type β gives also a
multiplicative action on the subsets of β. -/
instance mul_action_set [monoid α] [mul_action α β] : mul_action α (set β) :=
{ mul_smul := by { intros, simp only [← image_smul, image_image, ← mul_smul] },
one_smul := by { intros, simp only [← image_smul, image_eta, one_smul, image_id'] },
..set.has_scalar_set }
section is_mul_hom
open is_mul_hom
variables [has_mul α] [has_mul β] (m : α → β) [is_mul_hom m]
@[to_additive]
lemma image_mul : m '' (s * t) = m '' s * m '' t :=
by { simp only [← image2_mul, image_image2, image2_image_left, image2_image_right, map_mul m] }
@[to_additive]
lemma preimage_mul_preimage_subset {s t : set β} : m ⁻¹' s * m ⁻¹' t ⊆ m ⁻¹' (s * t) :=
by { rintros _ ⟨_, _, _, _, rfl⟩, exact ⟨_, _, ‹_›, ‹_›, (map_mul _ _ _).symm ⟩ }
end is_mul_hom
/-- The image of a set under function is a ring homomorphism
with respect to the pointwise operations on sets. -/
def image_hom [monoid α] [monoid β] (f : α →* β) : set_semiring α →+* set_semiring β :=
{ to_fun := image f,
map_zero' := image_empty _,
map_one' := by simp only [← singleton_one, image_singleton, is_monoid_hom.map_one f],
map_add' := image_union _,
map_mul' := λ _ _, image_mul _ }
end monoid
end set
section
open set
variables {α : Type*} {β : Type*}
/-- A nonempty set in a semimodule is scaled by zero to the singleton
containing 0 in the semimodule. -/
lemma zero_smul_set [semiring α] [add_comm_monoid β] [semimodule α β] {s : set β} (h : s.nonempty) :
(0 : α) • s = (0 : set β) :=
by simp only [← image_smul, image_eta, zero_smul, h.image_const, singleton_zero]
lemma mem_inv_smul_set_iff [field α] [mul_action α β] {a : α} (ha : a ≠ 0) (A : set β) (x : β) :
x ∈ a⁻¹ • A ↔ a • x ∈ A :=
by simp only [← image_smul, mem_image, inv_smul_eq_iff ha, exists_eq_right]
lemma mem_smul_set_iff_inv_smul_mem [field α] [mul_action α β] {a : α} (ha : a ≠ 0) (A : set β)
(x : β) : x ∈ a • A ↔ a⁻¹ • x ∈ A :=
by rw [← mem_inv_smul_set_iff $ inv_ne_zero ha, inv_inv']
end
|
41ef53ac0fe603786715045fb521c8f44e6881cd
|
8cae430f0a71442d02dbb1cbb14073b31048e4b0
|
/src/ring_theory/filtration.lean
|
b037c0da93ecb179629f5bbab546d1766e85b0e5
|
[
"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
| 17,167
|
lean
|
/-
Copyright (c) 2022 Andrew Yang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Andrew Yang
-/
import ring_theory.ideal.local_ring
import ring_theory.noetherian
import ring_theory.rees_algebra
import ring_theory.finiteness
import data.polynomial.module
import order.hom.lattice
/-!
# `I`-filtrations of modules
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
This file contains the definitions and basic results around (stable) `I`-filtrations of modules.
## Main results
- `ideal.filtration`: An `I`-filtration on the module `M` is a sequence of decreasing submodules
`N i` such that `I • N ≤ I (i + 1)`. Note that we do not require the filtration to start from `⊤`.
- `ideal.filtration.stable`: An `I`-filtration is stable if `I • (N i) = N (i + 1)` for large
enough `i`.
- `ideal.filtration.submodule`: The associated module `⨁ Nᵢ` of a filtration, implemented as a
submodule of `M[X]`.
- `ideal.filtration.submodule_fg_iff_stable`: If `F.N i` are all finitely generated, then
`F.stable` iff `F.submodule.fg`.
- `ideal.filtration.stable.of_le`: In a finite module over a noetherian ring,
if `F' ≤ F`, then `F.stable → F'.stable`.
- `ideal.exists_pow_inf_eq_pow_smul`: **Artin-Rees lemma**.
given `N ≤ M`, there exists a `k` such that `IⁿM ⊓ N = Iⁿ⁻ᵏ(IᵏM ⊓ N)` for all `n ≥ k`.
- `ideal.infi_pow_eq_bot_of_local_ring`:
**Krull's intersection theorem** (`⨅ i, I ^ i = ⊥`) for noetherian local rings.
- `ideal.infi_pow_eq_bot_of_is_domain`:
**Krull's intersection theorem** (`⨅ i, I ^ i = ⊥`) for noetherian domains.
-/
universes u v
variables {R M : Type u} [comm_ring R] [add_comm_group M] [module R M] (I : ideal R)
open polynomial
open_locale polynomial big_operators
/-- An `I`-filtration on the module `M` is a sequence of decreasing submodules `N i` such that
`I • (N i) ≤ N (i + 1)`. Note that we do not require the filtration to start from `⊤`. -/
@[ext]
structure ideal.filtration (M : Type u) [add_comm_group M] [module R M] :=
(N : ℕ → submodule R M)
(mono : ∀ i, N (i + 1) ≤ N i)
(smul_le : ∀ i, I • N i ≤ N (i + 1))
variables (F F' : I.filtration M) {I}
namespace ideal.filtration
lemma pow_smul_le (i j : ℕ) : I ^ i • F.N j ≤ F.N (i + j) :=
begin
induction i,
{ simp },
{ rw [pow_succ, mul_smul, nat.succ_eq_add_one, add_assoc, add_comm 1, ← add_assoc],
exact (submodule.smul_mono_right i_ih).trans (F.smul_le _) }
end
lemma pow_smul_le_pow_smul (i j k : ℕ) : I ^ (i + k) • F.N j ≤ I ^ k • F.N (i + j) :=
by { rw [add_comm, pow_add, mul_smul], exact submodule.smul_mono_right (F.pow_smul_le i j) }
protected
lemma antitone : antitone F.N :=
antitone_nat_of_succ_le F.mono
/-- The trivial `I`-filtration of `N`. -/
@[simps]
def _root_.ideal.trivial_filtration (I : ideal R) (N : submodule R M) : I.filtration M :=
{ N := λ i, N,
mono := λ i, le_of_eq rfl,
smul_le := λ i, submodule.smul_le_right }
/-- The `sup` of two `I.filtration`s is an `I.filtration`. -/
instance : has_sup (I.filtration M) :=
⟨λ F F', ⟨F.N ⊔ F'.N, λ i, sup_le_sup (F.mono i) (F'.mono i),
λ i, (le_of_eq (submodule.smul_sup _ _ _)).trans $ sup_le_sup (F.smul_le i) (F'.smul_le i)⟩⟩
/-- The `Sup` of a family of `I.filtration`s is an `I.filtration`. -/
instance : has_Sup (I.filtration M) := ⟨λ S,
{ N := Sup (ideal.filtration.N '' S),
mono := λ i, begin
apply Sup_le_Sup_of_forall_exists_le _,
rintros _ ⟨⟨_, F, hF, rfl⟩, rfl⟩,
exact ⟨_, ⟨⟨_, F, hF, rfl⟩, rfl⟩, F.mono i⟩,
end,
smul_le := λ i, begin
rw [Sup_eq_supr', supr_apply, submodule.smul_supr, supr_apply],
apply supr_mono _,
rintro ⟨_, F, hF, rfl⟩,
exact F.smul_le i,
end }⟩
/-- The `inf` of two `I.filtration`s is an `I.filtration`. -/
instance : has_inf (I.filtration M) :=
⟨λ F F', ⟨F.N ⊓ F'.N, λ i, inf_le_inf (F.mono i) (F'.mono i),
λ i, (submodule.smul_inf_le _ _ _).trans $ inf_le_inf (F.smul_le i) (F'.smul_le i)⟩⟩
/-- The `Inf` of a family of `I.filtration`s is an `I.filtration`. -/
instance : has_Inf (I.filtration M) := ⟨λ S,
{ N := Inf (ideal.filtration.N '' S),
mono := λ i, begin
apply Inf_le_Inf_of_forall_exists_le _,
rintros _ ⟨⟨_, F, hF, rfl⟩, rfl⟩,
exact ⟨_, ⟨⟨_, F, hF, rfl⟩, rfl⟩, F.mono i⟩,
end,
smul_le := λ i, begin
rw [Inf_eq_infi', infi_apply, infi_apply],
refine submodule.smul_infi_le.trans _,
apply infi_mono _,
rintro ⟨_, F, hF, rfl⟩,
exact F.smul_le i,
end }⟩
instance : has_top (I.filtration M) := ⟨I.trivial_filtration ⊤⟩
instance : has_bot (I.filtration M) := ⟨I.trivial_filtration ⊥⟩
@[simp] lemma sup_N : (F ⊔ F').N = F.N ⊔ F'.N := rfl
@[simp] lemma Sup_N (S : set (I.filtration M)) : (Sup S).N = Sup (ideal.filtration.N '' S) := rfl
@[simp] lemma inf_N : (F ⊓ F').N = F.N ⊓ F'.N := rfl
@[simp] lemma Inf_N (S : set (I.filtration M)) : (Inf S).N = Inf (ideal.filtration.N '' S) := rfl
@[simp] lemma top_N : (⊤ : I.filtration M).N = ⊤ := rfl
@[simp] lemma bot_N : (⊥ : I.filtration M).N = ⊥ := rfl
@[simp] lemma supr_N {ι : Sort*} (f : ι → I.filtration M) : (supr f).N = ⨆ i, (f i).N :=
congr_arg Sup (set.range_comp _ _).symm
@[simp] lemma infi_N {ι : Sort*} (f : ι → I.filtration M) : (infi f).N = ⨅ i, (f i).N :=
congr_arg Inf (set.range_comp _ _).symm
instance : complete_lattice (I.filtration M) :=
function.injective.complete_lattice ideal.filtration.N ideal.filtration.ext
sup_N inf_N (λ _, Sup_image) (λ _, Inf_image) top_N bot_N
instance : inhabited (I.filtration M) := ⟨⊥⟩
/-- An `I` filtration is stable if `I • F.N n = F.N (n+1)` for large enough `n`. -/
def stable : Prop :=
∃ n₀, ∀ n ≥ n₀, I • F.N n = F.N (n + 1)
/-- The trivial stable `I`-filtration of `N`. -/
@[simps]
def _root_.ideal.stable_filtration (I : ideal R) (N : submodule R M) :
I.filtration M :=
{ N := λ i, I ^ i • N,
mono := λ i, by { rw [add_comm, pow_add, mul_smul], exact submodule.smul_le_right },
smul_le := λ i, by { rw [add_comm, pow_add, mul_smul, pow_one], exact le_refl _ } }
lemma _root_.ideal.stable_filtration_stable (I : ideal R) (N : submodule R M) :
(I.stable_filtration N).stable :=
by { use 0, intros n _, dsimp, rw [add_comm, pow_add, mul_smul, pow_one] }
variables {F F'} (h : F.stable)
include h
lemma stable.exists_pow_smul_eq :
∃ n₀, ∀ k, F.N (n₀ + k) = I ^ k • F.N n₀ :=
begin
obtain ⟨n₀, hn⟩ := h,
use n₀,
intro k,
induction k,
{ simp },
{ rw [nat.succ_eq_add_one, ← add_assoc, ← hn, k_ih, add_comm, pow_add, mul_smul, pow_one],
linarith }
end
lemma stable.exists_pow_smul_eq_of_ge :
∃ n₀, ∀ n ≥ n₀, F.N n = I ^ (n - n₀) • F.N n₀ :=
begin
obtain ⟨n₀, hn₀⟩ := h.exists_pow_smul_eq,
use n₀,
intros n hn,
convert hn₀ (n - n₀),
rw [add_comm, tsub_add_cancel_of_le hn],
end
omit h
lemma stable_iff_exists_pow_smul_eq_of_ge :
F.stable ↔ ∃ n₀, ∀ n ≥ n₀, F.N n = I ^ (n - n₀) • F.N n₀ :=
begin
refine ⟨stable.exists_pow_smul_eq_of_ge, λ h, ⟨h.some, λ n hn, _⟩⟩,
rw [h.some_spec n hn, h.some_spec (n+1) (by linarith), smul_smul, ← pow_succ,
tsub_add_eq_add_tsub hn],
end
lemma stable.exists_forall_le (h : F.stable) (e : F.N 0 ≤ F'.N 0) :
∃ n₀, ∀ n, F.N (n + n₀) ≤ F'.N n :=
begin
obtain ⟨n₀, hF⟩ := h,
use n₀,
intro n,
induction n with n hn,
{ refine (F.antitone _).trans e, simp },
{ rw [nat.succ_eq_one_add, add_assoc, add_comm, add_comm 1 n, ← hF],
exact (submodule.smul_mono_right hn).trans (F'.smul_le _),
simp },
end
lemma stable.bounded_difference (h : F.stable) (h' : F'.stable) (e : F.N 0 = F'.N 0) :
∃ n₀, ∀ n, F.N (n + n₀) ≤ F'.N n ∧ F'.N (n + n₀) ≤ F.N n :=
begin
obtain ⟨n₁, h₁⟩ := h.exists_forall_le (le_of_eq e),
obtain ⟨n₂, h₂⟩ := h'.exists_forall_le (le_of_eq e.symm),
use max n₁ n₂,
intro n,
refine ⟨(F.antitone _).trans (h₁ n), (F'.antitone _).trans (h₂ n)⟩; simp
end
open polynomial_module
variables (F F')
/-- The `R[IX]`-submodule of `M[X]` associated with an `I`-filtration. -/
protected
def submodule : submodule (rees_algebra I) (polynomial_module R M) :=
{ carrier := { f | ∀ i, f i ∈ F.N i },
add_mem' := λ f g hf hg i, submodule.add_mem _ (hf i) (hg i),
zero_mem' := λ i, submodule.zero_mem _,
smul_mem' := λ r f hf i, begin
rw [subalgebra.smul_def, polynomial_module.smul_apply],
apply submodule.sum_mem,
rintro ⟨j, k⟩ e,
rw finset.nat.mem_antidiagonal at e,
subst e,
exact F.pow_smul_le j k (submodule.smul_mem_smul (r.2 j) (hf k))
end }
@[simp]
lemma mem_submodule (f : polynomial_module R M) : f ∈ F.submodule ↔ ∀ i, f i ∈ F.N i := iff.rfl
lemma inf_submodule : (F ⊓ F').submodule = F.submodule ⊓ F'.submodule :=
by { ext, exact forall_and_distrib }
variables (I M)
/-- `ideal.filtration.submodule` as an `inf_hom` -/
def submodule_inf_hom :
inf_hom (I.filtration M) (submodule (rees_algebra I) (polynomial_module R M)) :=
{ to_fun := ideal.filtration.submodule, map_inf' := inf_submodule }
variables {I M}
lemma submodule_closure_single :
add_submonoid.closure (⋃ i, single R i '' (F.N i : set M)) = F.submodule.to_add_submonoid :=
begin
apply le_antisymm,
{ rw [add_submonoid.closure_le, set.Union_subset_iff],
rintro i _ ⟨m, hm, rfl⟩ j,
rw single_apply,
split_ifs,
{ rwa ← h },
{ exact (F.N j).zero_mem } },
{ intros f hf,
rw [← f.sum_single],
apply add_submonoid.sum_mem _ _,
rintros c -,
exact add_submonoid.subset_closure (set.subset_Union _ c $ set.mem_image_of_mem _ (hf c)) }
end
lemma submodule_span_single :
submodule.span (rees_algebra I) (⋃ i, single R i '' (F.N i : set M)) = F.submodule :=
begin
rw [← submodule.span_closure, submodule_closure_single],
simp,
end
lemma submodule_eq_span_le_iff_stable_ge (n₀ : ℕ) :
F.submodule = submodule.span _ (⋃ i ≤ n₀, single R i '' (F.N i : set M)) ↔
∀ n ≥ n₀, I • F.N n = F.N (n + 1) :=
begin
rw [← submodule_span_single, ← has_le.le.le_iff_eq, submodule.span_le,
set.Union_subset_iff],
swap, { exact submodule.span_mono (set.Union₂_subset_Union _ _) },
split,
{ intros H n hn,
refine (F.smul_le n).antisymm _,
intros x hx,
obtain ⟨l, hl⟩ := (finsupp.mem_span_iff_total _ _ _).mp (H _ ⟨x, hx, rfl⟩),
replace hl := congr_arg (λ f : ℕ →₀ M, f (n + 1)) hl,
dsimp only at hl,
erw finsupp.single_eq_same at hl,
rw [← hl, finsupp.total_apply, finsupp.sum_apply],
apply submodule.sum_mem _ _,
rintros ⟨_, _, ⟨n', rfl⟩, _, ⟨hn', rfl⟩, m, hm, rfl⟩ -,
dsimp only [subtype.coe_mk],
rw [subalgebra.smul_def, smul_single_apply, if_pos (show n' ≤ n + 1, by linarith)],
have e : n' ≤ n := by linarith,
have := F.pow_smul_le_pow_smul (n - n') n' 1,
rw [tsub_add_cancel_of_le e, pow_one, add_comm _ 1, ← add_tsub_assoc_of_le e, add_comm] at this,
exact this (submodule.smul_mem_smul ((l _).2 $ n + 1 - n') hm) },
{ let F' := submodule.span (rees_algebra I) (⋃ i ≤ n₀, single R i '' (F.N i : set M)),
intros hF i,
have : ∀ i ≤ n₀, single R i '' (F.N i : set M) ⊆ F' :=
λ i hi, set.subset.trans (set.subset_Union₂ i hi) submodule.subset_span,
induction i with j hj,
{ exact this _ (zero_le _) },
by_cases hj' : j.succ ≤ n₀,
{ exact this _ hj' },
simp only [not_le, nat.lt_succ_iff] at hj',
rw [nat.succ_eq_add_one, ← hF _ hj'],
rintro _ ⟨m, hm, rfl⟩,
apply submodule.smul_induction_on hm,
{ intros r hr m' hm',
rw [add_comm, ← monomial_smul_single],
exact F'.smul_mem ⟨_, rees_algebra.monomial_mem.mpr (by rwa pow_one)⟩
(hj $ set.mem_image_of_mem _ hm') },
{ intros x y hx hy, rw map_add, exact F'.add_mem hx hy } }
end
/-- If the components of a filtration are finitely generated, then the filtration is stable iff
its associated submodule of is finitely generated. -/
lemma submodule_fg_iff_stable (hF' : ∀ i, (F.N i).fg) :
F.submodule.fg ↔ F.stable :=
begin
classical,
delta ideal.filtration.stable,
simp_rw ← F.submodule_eq_span_le_iff_stable_ge,
split,
{ rintro H,
apply H.stablizes_of_supr_eq
⟨λ n₀, submodule.span _ (⋃ (i : ℕ) (H : i ≤ n₀), single R i '' ↑(F.N i)), _⟩,
{ dsimp,
rw [← submodule.span_Union, ← submodule_span_single],
congr' 1,
ext,
simp only [set.mem_Union, set.mem_image, set_like.mem_coe, exists_prop],
split,
{ rintro ⟨-, i, -, e⟩, exact ⟨i, e⟩ },
{ rintro ⟨i, e⟩, exact ⟨i, i, le_refl i, e⟩ } },
{ intros n m e,
rw [submodule.span_le, set.Union₂_subset_iff],
intros i hi,
refine (set.subset.trans _ (set.subset_Union₂ i (hi.trans e : _))).trans
submodule.subset_span,
refl } },
{ rintros ⟨n, hn⟩,
rw hn,
simp_rw [submodule.span_Union₂, ← finset.mem_range_succ_iff, supr_subtype'],
apply submodule.fg_supr,
rintro ⟨i, hi⟩,
obtain ⟨s, hs⟩ := hF' i,
have : submodule.span (rees_algebra I) (s.image (lsingle R i) : set (polynomial_module R M))
= submodule.span _ (single R i '' (F.N i : set M)),
{ rw [finset.coe_image, ← submodule.span_span_of_tower R, ← submodule.map_span, hs], refl },
rw [subtype.coe_mk, ← this],
exact ⟨_, rfl⟩ }
end
.
variables {F}
lemma stable.of_le [is_noetherian_ring R] [h : module.finite R M] (hF : F.stable)
{F' : I.filtration M} (hf : F' ≤ F) : F'.stable :=
begin
haveI := is_noetherian_of_fg_of_noetherian' h.1,
rw ← submodule_fg_iff_stable at hF ⊢,
any_goals { intro i, exact is_noetherian.noetherian _ },
have := is_noetherian_of_fg_of_noetherian _ hF,
rw is_noetherian_submodule at this,
exact this _ (order_hom_class.mono (submodule_inf_hom M I) hf),
end
lemma stable.inter_right [is_noetherian_ring R] [h : module.finite R M] (hF : F.stable) :
(F ⊓ F').stable :=
hF.of_le inf_le_left
lemma stable.inter_left [is_noetherian_ring R] [h : module.finite R M] (hF : F.stable) :
(F' ⊓ F).stable :=
hF.of_le inf_le_right
end ideal.filtration
variable (I)
/-- **Artin-Rees lemma** -/
lemma ideal.exists_pow_inf_eq_pow_smul [is_noetherian_ring R] [h : module.finite R M]
(N : submodule R M) : ∃ k : ℕ, ∀ n ≥ k, I ^ n • ⊤ ⊓ N = I ^ (n - k) • (I ^ k • ⊤ ⊓ N) :=
((I.stable_filtration_stable ⊤).inter_right (I.trivial_filtration N)).exists_pow_smul_eq_of_ge
lemma ideal.mem_infi_smul_pow_eq_bot_iff [is_noetherian_ring R] [hM : module.finite R M] (x : M) :
x ∈ (⨅ i : ℕ, I ^ i • ⊤ : submodule R M) ↔ ∃ r : I, (r : R) • x = x :=
begin
let N := (⨅ i : ℕ, I ^ i • ⊤ : submodule R M),
have hN : ∀ k, (I.stable_filtration ⊤ ⊓ I.trivial_filtration N).N k = N,
{ intro k, exact inf_eq_right.mpr ((infi_le _ k).trans $ le_of_eq $ by simp) },
split,
{ haveI := is_noetherian_of_fg_of_noetherian' hM.out,
obtain ⟨r, hr₁, hr₂⟩ := submodule.exists_mem_and_smul_eq_self_of_fg_of_le_smul I N
(is_noetherian.noetherian N) _,
{ intro H, exact ⟨⟨r, hr₁⟩, hr₂ _ H⟩ },
obtain ⟨k, hk⟩ := (I.stable_filtration_stable ⊤).inter_right (I.trivial_filtration N),
have := hk k (le_refl _),
rw [hN, hN] at this,
exact le_of_eq this.symm },
{ rintro ⟨r, eq⟩,
rw submodule.mem_infi,
intro i,
induction i with i hi,
{ simp },
{ rw [nat.succ_eq_one_add, pow_add, ← smul_smul, pow_one, ← eq],
exact submodule.smul_mem_smul r.prop hi } }
end
lemma ideal.infi_pow_smul_eq_bot_of_local_ring [is_noetherian_ring R] [local_ring R]
[module.finite R M] (h : I ≠ ⊤) :
(⨅ i : ℕ, I ^ i • ⊤ : submodule R M) = ⊥ :=
begin
rw eq_bot_iff,
intros x hx,
obtain ⟨r, hr⟩ := (I.mem_infi_smul_pow_eq_bot_iff x).mp hx,
have := local_ring.is_unit_one_sub_self_of_mem_nonunits _ (local_ring.le_maximal_ideal h r.prop),
apply this.smul_left_cancel.mp,
swap, { apply_instance },
simp [sub_smul, hr],
end
/-- **Krull's intersection theorem** for noetherian local rings. -/
lemma ideal.infi_pow_eq_bot_of_local_ring [is_noetherian_ring R] [local_ring R] (h : I ≠ ⊤) :
(⨅ i : ℕ, I ^ i) = ⊥ :=
begin
convert I.infi_pow_smul_eq_bot_of_local_ring h,
ext i,
rw [smul_eq_mul, ← ideal.one_eq_top, mul_one],
apply_instance,
end
/-- **Krull's intersection theorem** for noetherian domains. -/
lemma ideal.infi_pow_eq_bot_of_is_domain [is_noetherian_ring R] [is_domain R] (h : I ≠ ⊤) :
(⨅ i : ℕ, I ^ i) = ⊥ :=
begin
rw eq_bot_iff,
intros x hx,
by_contra hx',
have := ideal.mem_infi_smul_pow_eq_bot_iff I x,
simp_rw [smul_eq_mul, ← ideal.one_eq_top, mul_one] at this,
obtain ⟨r, hr⟩ := this.mp hx,
have := mul_right_cancel₀ hx' (hr.trans (one_mul x).symm),
exact I.eq_top_iff_one.not.mp h (this ▸ r.prop),
end
|
234f574d359effc224273e430a8ff0adfe080a7a
|
50b3917f95cf9fe84639812ea0461b38f8f0dbe1
|
/Examples/well_founded_lists.lean
|
5733dec0d9cc7f747e4efe44625dde7129a2e284
|
[] |
no_license
|
roro47/xena
|
6389bcd7dcf395656a2c85cfc90a4366e9b825bb
|
237910190de38d6ff43694ffe3a9b68f79363e6c
|
refs/heads/master
| 1,598,570,061,948
| 1,570,052,567,000
| 1,570,052,567,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 543
|
lean
|
import data.equiv.basic
namespace xena
inductive W (L : Type) (A : L → Type) : Type
| Node : ∀ (lbl : L), (A lbl → W) → W
def nat := W bool (λ b, bool.rec empty unit b)
def list (L : Type) :=
W (option L) (λ l, option.rec_on l empty (λ _, unit))
end xena
example : equiv nat xena.nat :=
{ to_fun := λ n, nat.rec_on n (xena.W.Node ff empty.elim) (λ d w, xena.W.Node tt $ λ _, w),
inv_fun := λ w, xena.W.rec_on w $ λ b H1 H2, begin cases b, exact 0, exact nat.succ (H2 unit.star) end,
left_inv := _,
right_inv := _ }
|
5f5a345b4b66e88c1a86c7707b1f8c3bbb5faf16
|
ac2987d8c7832fb4a87edb6bee26141facbb6fa0
|
/Mathlib/Data/ByteArray.lean
|
d784e7c7c3a05127f79cb32d5ab881db24add9cc
|
[
"Apache-2.0"
] |
permissive
|
AurelienSaue/mathlib4
|
52204b9bd9d207c922fe0cf3397166728bb6c2e2
|
84271fe0875bafdaa88ac41f1b5a7c18151bd0d5
|
refs/heads/master
| 1,689,156,096,545
| 1,629,378,840,000
| 1,629,378,840,000
| 389,648,603
| 0
| 0
|
Apache-2.0
| 1,627,307,284,000
| 1,627,307,284,000
| null |
UTF-8
|
Lean
| false
| false
| 4,165
|
lean
|
import Mathlib.Data.Nat.Basic
import Mathlib.Data.Char
import Mathlib.Data.UInt
/-- A terminal byte slice, a suffix of a byte array. -/
structure ByteSliceT := (arr : ByteArray) (off : Nat)
namespace ByteSliceT
/-- The number of elements in the byte slice. -/
@[inline] def size (self : ByteSliceT) : Nat := self.arr.size - self.off
/-- Index into a byte slice. The `getOp` function allows the use of the `buf[i]` notation. -/
@[inline] def getOp (self : ByteSliceT) (idx : Nat) : UInt8 := self.arr.get! (self.off + idx)
end ByteSliceT
/-- Convert a byte array into a terminal slice. -/
def ByteArray.toSliceT (arr : ByteArray) : ByteSliceT := ⟨arr, 0⟩
/-- A byte slice, given by a backing byte array, and an offset and length. -/
structure ByteSlice := (arr : ByteArray) (off len : Nat)
namespace ByteSlice
/-- Convert a byte slice into an array, by copying the data if necessary. -/
def toArray : ByteSlice → ByteArray
| ⟨arr, off, len⟩ => arr.extract off len
/-- Index into a byte slice. The `getOp` function allows the use of the `buf[i]` notation. -/
@[inline] def getOp (self : ByteSlice) (idx : Nat) : UInt8 := self.arr.get! (self.off + idx)
/-- Implementation of `forIn.loop`. -/
partial def forIn.loop.impl [Monad m] (f : UInt8 → β → m (ForInStep β))
(arr : ByteArray) (off _end : Nat) (i : Nat) (b : β) : m β :=
if i < _end then do
match ← f (arr.get! i) b with
| ForInStep.done b => pure b
| ForInStep.yield b => impl f arr off _end (i+1) b
else b
set_option codegen false in
/-- The inner loop of the `forIn` implementation for byte slices. It is defined twice:
this version is the model, while `forIn.loop.impl` is the version used for code generation. -/
@[implementedBy forIn.loop.impl]
def forIn.loop [Monad m] (f : UInt8 → β → m (ForInStep β))
(arr : ByteArray) (off _end : Nat) (i : Nat) (b : β) : m β := do
(Nat.Up.WF _end).fix (x := i) (C := fun _ => ∀ b, m β) (b := b)
fun i IH b =>
if h : i < _end then do
let b ← f (arr.get! i) b
match b with
| ForInStep.done b => pure b
| ForInStep.yield b => IH (i+1) (Nat.Up.next h) b
else b
instance : ForIn m ByteSlice UInt8 :=
⟨fun ⟨arr, off, len⟩ b f => forIn.loop f arr off (off + len) off b⟩
end ByteSlice
/-- Convert a terminal byte slice into a regular byte slice. -/
def ByteSliceT.toSlice : ByteSliceT → ByteSlice
| ⟨arr, off⟩ => ⟨arr, off, arr.size - off⟩
/-- Convert a byte array into a byte slice. -/
def ByteArray.toSlice (arr : ByteArray) : ByteSlice := ⟨arr, 0, arr.size⟩
/-- Implementation of `String.toAsciiByteArray.loop`. -/
partial def String.toAsciiByteArray.loop.impl
(s : String) (out : ByteArray) (p : Pos) : ByteArray :=
if s.atEnd p then out else
let c := s.get p
impl s (out.push c.toUInt8) (s.next p)
set_option codegen false in
/-- The inner loop of `String.toAsciiByteArray`. Because it uses well founded recursion, we have
to write the compiler version of the implementation separately from the version used for
reasoning inside lean. -/
@[implementedBy String.toAsciiByteArray.loop.impl]
def String.toAsciiByteArray.loop (s : String) (out : ByteArray) (p : Pos) : ByteArray :=
(Nat.Up.WF (utf8ByteSize s)).fix (x := p) (C := fun _ => ∀ out, ByteArray) (out := out)
fun p IH i =>
if h : s.atEnd p then out else
let c := s.get p
IH (s.next p) (out := out.push c.toUInt8)
⟨Nat.lt_add_of_pos_right (String.csize_pos _),
Nat.lt_of_not_le (mt decide_eq_true h)⟩
/-- Convert a string of assumed-ASCII characters into a byte array.
(If any characters are non-ASCII they will be reduced modulo 256.) -/
def String.toAsciiByteArray (s : String) : ByteArray :=
String.toAsciiByteArray.loop s ByteArray.empty 0
/-- Convert a byte slice into a string. This does not handle non-ASCII characters correctly:
every byte will become a unicode character with codepoint < 256. -/
def ByteSlice.toString (bs : ByteSlice) : String := do
let mut s := ""
for c in bs do s := s.push c.toChar
s
instance : ToString ByteSlice where
toString bs := do
let mut s := ""
for c in bs do s := s.push c.toChar
s
|
4fc305e1d83674f8d02dac0d6abd67c785346578
|
9be442d9ec2fcf442516ed6e9e1660aa9071b7bd
|
/tests/lean/warningAsError.lean
|
cd35d1f68806d8c53d7c5d7fb7e2dfd64da9cb4c
|
[
"Apache-2.0",
"LLVM-exception",
"NCSA",
"LGPL-3.0-only",
"LicenseRef-scancode-inner-net-2.0",
"BSD-3-Clause",
"LGPL-2.0-or-later",
"Spencer-94",
"LGPL-2.1-or-later",
"HPND",
"LicenseRef-scancode-pcre",
"ISC",
"LGPL-2.1-only",
"LicenseRef-scancode-other-permissive",
"SunPro",
"CMU-Mach"
] |
permissive
|
EdAyers/lean4
|
57ac632d6b0789cb91fab2170e8c9e40441221bd
|
37ba0df5841bde51dbc2329da81ac23d4f6a4de4
|
refs/heads/master
| 1,676,463,245,298
| 1,660,619,433,000
| 1,660,619,433,000
| 183,433,437
| 1
| 0
|
Apache-2.0
| 1,657,612,672,000
| 1,556,196,574,000
|
Lean
|
UTF-8
|
Lean
| false
| false
| 217
|
lean
|
def f (x : Nat) := x + 1
@[deprecated f]
def g (x : Nat) := x + 1
#eval g 0 -- warning
set_option warningAsError true
#eval g 0 -- error
set_option linter.unusedVariables true
def h (unused : Nat) := 0 -- error
|
babf2a4bd62ad11ce89dbdf1cb4517a1d8efaae1
|
63abd62053d479eae5abf4951554e1064a4c45b4
|
/src/ring_theory/int/basic.lean
|
c09fd91e8fc6727178c0a9e0f165360177fac971
|
[
"Apache-2.0"
] |
permissive
|
Lix0120/mathlib
|
0020745240315ed0e517cbf32e738d8f9811dd80
|
e14c37827456fc6707f31b4d1d16f1f3a3205e91
|
refs/heads/master
| 1,673,102,855,024
| 1,604,151,044,000
| 1,604,151,044,000
| 308,930,245
| 0
| 0
|
Apache-2.0
| 1,604,164,710,000
| 1,604,163,547,000
| null |
UTF-8
|
Lean
| false
| false
| 11,961
|
lean
|
/-
Copyright (c) 2018 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Jens Wagemaker, Aaron Anderson
-/
import data.int.gcd
import ring_theory.multiplicity
import ring_theory.principal_ideal_domain
/-!
# Divisibility over ℕ and ℤ
This file collects results for the integers and natural numbers that use abstract algebra in
their proofs or cases of ℕ and ℤ being examples of structures in abstract algebra.
## Main statements
* `nat.prime_iff`: `nat.prime` coincides with the general definition of `prime`
* `nat.irreducible_iff_prime`: a non-unit natural number is only divisible by `1` iff it is prime
* `nat.factors_eq`: the multiset of elements of `nat.factors` is equal to the factors
given by the `unique_factorization_monoid` instance
* ℤ is a `normalization_monoid`
* ℤ is a `gcd_monoid`
## Tags
prime, irreducible, natural numbers, integers, normalization monoid, gcd monoid,
greatest common divisor, prime factorization, prime factors, unique factorization,
unique factors
-/
theorem nat.prime_iff {p : ℕ} : p.prime ↔ prime p :=
begin
split; intro h,
{ refine ⟨h.ne_zero, ⟨_, λ a b, _⟩⟩,
{ rw nat.is_unit_iff, apply h.ne_one },
{ apply h.dvd_mul.1 } },
{ refine ⟨_, λ m hm, _⟩,
{ cases p, { exfalso, apply h.ne_zero rfl },
cases p, { exfalso, apply h.ne_one rfl },
omega },
{ cases hm with n hn,
cases h.2.2 m n (hn ▸ dvd_refl _) with hpm hpn,
{ right, apply nat.dvd_antisymm (dvd.intro _ hn.symm) hpm },
{ left,
cases n, { exfalso, rw [hn, mul_zero] at h, apply h.ne_zero rfl },
apply nat.eq_of_mul_eq_mul_right (nat.succ_pos _),
rw [← hn, one_mul],
apply nat.dvd_antisymm hpn (dvd.intro m _),
rw [mul_comm, hn], }, } }
end
theorem nat.irreducible_iff_prime {p : ℕ} : irreducible p ↔ prime p :=
begin
refine ⟨λ h, _, irreducible_of_prime⟩,
rw ← nat.prime_iff,
refine ⟨_, λ m hm, _⟩,
{ cases p, { exfalso, apply h.ne_zero rfl },
cases p, { exfalso, apply h.1 is_unit_one, },
omega },
{ cases hm with n hn,
cases h.2 m n hn with um un,
{ left, rw nat.is_unit_iff.1 um, },
{ right, rw [hn, nat.is_unit_iff.1 un, mul_one], } }
end
namespace nat
instance : wf_dvd_monoid ℕ :=
⟨begin
apply rel_hom.well_founded _ (with_top.well_founded_lt nat.lt_wf),
refine ⟨λ x, if x = 0 then ⊤ else x, _⟩,
intros a b h,
cases a,
{ exfalso, revert h, simp [dvd_not_unit] },
cases b,
{simp [succ_ne_zero, with_top.coe_lt_top]},
cases dvd_and_not_dvd_iff.2 h with h1 h2,
simp only [succ_ne_zero, with_top.coe_lt_coe, if_false],
apply lt_of_le_of_ne (nat.le_of_dvd (nat.succ_pos _) h1) (λ con, h2 _),
rw con,
end⟩
instance : unique_factorization_monoid ℕ :=
⟨λ _, nat.irreducible_iff_prime⟩
end nat
namespace int
section normalization_monoid
instance : normalization_monoid ℤ :=
{ norm_unit := λa:ℤ, if 0 ≤ a then 1 else -1,
norm_unit_zero := if_pos (le_refl _),
norm_unit_mul := assume a b hna hnb,
begin
cases hna.lt_or_lt with ha ha; cases hnb.lt_or_lt with hb hb;
simp [mul_nonneg_iff, ha.le, ha.not_le, hb.le, hb.not_le]
end,
norm_unit_coe_units := assume u, (units_eq_one_or u).elim
(assume eq, eq.symm ▸ if_pos zero_le_one)
(assume eq, eq.symm ▸ if_neg (not_le_of_gt $ show (-1:ℤ) < 0, by dec_trivial)), }
lemma normalize_of_nonneg {z : ℤ} (h : 0 ≤ z) : normalize z = z :=
show z * ↑(ite _ _ _) = z, by rw [if_pos h, units.coe_one, mul_one]
lemma normalize_of_neg {z : ℤ} (h : z < 0) : normalize z = -z :=
show z * ↑(ite _ _ _) = -z,
by rw [if_neg (not_le_of_gt h), units.coe_neg, units.coe_one, mul_neg_one]
lemma normalize_coe_nat (n : ℕ) : normalize (n : ℤ) = n :=
normalize_of_nonneg (coe_nat_le_coe_nat_of_le $ nat.zero_le n)
theorem coe_nat_abs_eq_normalize (z : ℤ) : (z.nat_abs : ℤ) = normalize z :=
begin
by_cases 0 ≤ z,
{ simp [nat_abs_of_nonneg h, normalize_of_nonneg h] },
{ simp [of_nat_nat_abs_of_nonpos (le_of_not_ge h), normalize_of_neg (lt_of_not_ge h)] }
end
end normalization_monoid
section gcd_monoid
instance : gcd_monoid ℤ :=
{ gcd := λa b, int.gcd a b,
lcm := λa b, int.lcm a b,
gcd_dvd_left := assume a b, int.gcd_dvd_left _ _,
gcd_dvd_right := assume a b, int.gcd_dvd_right _ _,
dvd_gcd := assume a b c, dvd_gcd,
normalize_gcd := assume a b, normalize_coe_nat _,
gcd_mul_lcm := by intros; rw [← int.coe_nat_mul, gcd_mul_lcm, coe_nat_abs_eq_normalize],
lcm_zero_left := assume a, coe_nat_eq_zero.2 $ nat.lcm_zero_left _,
lcm_zero_right := assume a, coe_nat_eq_zero.2 $ nat.lcm_zero_right _,
.. int.normalization_monoid }
lemma coe_gcd (i j : ℤ) : ↑(int.gcd i j) = gcd_monoid.gcd i j := rfl
lemma coe_lcm (i j : ℤ) : ↑(int.lcm i j) = gcd_monoid.lcm i j := rfl
lemma nat_abs_gcd (i j : ℤ) : nat_abs (gcd_monoid.gcd i j) = int.gcd i j := rfl
lemma nat_abs_lcm (i j : ℤ) : nat_abs (gcd_monoid.lcm i j) = int.lcm i j := rfl
end gcd_monoid
lemma exists_unit_of_abs (a : ℤ) : ∃ (u : ℤ) (h : is_unit u), (int.nat_abs a : ℤ) = u * a :=
begin
cases (nat_abs_eq a) with h,
{ use [1, is_unit_one], rw [← h, one_mul], },
{ use [-1, is_unit_int.mpr rfl], rw [ ← neg_eq_iff_neg_eq.mp (eq.symm h)],
simp only [neg_mul_eq_neg_mul_symm, one_mul] }
end
lemma gcd_eq_one_iff_coprime {a b : ℤ} : int.gcd a b = 1 ↔ is_coprime a b :=
begin
split,
{ intro hg,
obtain ⟨ua, hua, ha⟩ := exists_unit_of_abs a,
obtain ⟨ub, hub, hb⟩ := exists_unit_of_abs b,
use [(nat.gcd_a (int.nat_abs a) (int.nat_abs b)) * ua,
(nat.gcd_b (int.nat_abs a) (int.nat_abs b)) * ub],
rw [mul_assoc, ← ha, mul_assoc, ← hb, mul_comm, mul_comm _ (int.nat_abs b : ℤ),
← nat.gcd_eq_gcd_ab],
norm_cast,
exact hg },
{ rintro ⟨r, s, h⟩,
by_contradiction hg,
obtain ⟨p, ⟨hp, ha, hb⟩⟩ := nat.prime.not_coprime_iff_dvd.mp hg,
apply nat.prime.not_dvd_one hp,
apply coe_nat_dvd.mp,
change (p : ℤ) ∣ 1,
rw [← h],
exact dvd_add (dvd_mul_of_dvd_right (coe_nat_dvd_left.mpr ha) _)
(dvd_mul_of_dvd_right (coe_nat_dvd_left.mpr hb) _),
}
end
lemma sqr_of_gcd_eq_one {a b c : ℤ} (h : int.gcd a b = 1) (heq : a * b = c ^ 2) :
∃ (a0 : ℤ), a = a0 ^ 2 ∨ a = - (a0 ^ 2) :=
begin
have h' : gcd_monoid.gcd a b = 1, { rw [← coe_gcd, h], dec_trivial },
obtain ⟨d, ⟨u, hu⟩⟩ := exists_associated_pow_of_mul_eq_pow h' heq,
use d,
rw ← hu,
cases int.units_eq_one_or u with hu' hu'; { rw hu', simp }
end
lemma sqr_of_coprime {a b c : ℤ} (h : is_coprime a b) (heq : a * b = c ^ 2) :
∃ (a0 : ℤ), a = a0 ^ 2 ∨ a = - (a0 ^ 2) := sqr_of_gcd_eq_one (gcd_eq_one_iff_coprime.mpr h) heq
end int
theorem irreducible_iff_nat_prime : ∀(a : ℕ), irreducible a ↔ nat.prime a
| 0 := by simp [nat.not_prime_zero]
| 1 := by simp [nat.prime, one_lt_two]
| (n + 2) :=
have h₁ : ¬n + 2 = 1, from dec_trivial,
begin
simp [h₁, nat.prime, irreducible, (≥), nat.le_add_left 2 n, (∣)],
refine forall_congr (assume a, forall_congr $ assume b, forall_congr $ assume hab, _),
by_cases a = 1; simp [h],
split,
{ assume hb, simpa [hb] using hab.symm },
{ assume ha, subst ha,
have : n + 2 > 0, from dec_trivial,
refine nat.eq_of_mul_eq_mul_left this _,
rw [← hab, mul_one] }
end
lemma nat.prime_iff_prime {p : ℕ} : p.prime ↔ _root_.prime (p : ℕ) :=
⟨λ hp, ⟨nat.pos_iff_ne_zero.1 hp.pos, mt is_unit_iff_dvd_one.1 hp.not_dvd_one,
λ a b, hp.dvd_mul.1⟩,
λ hp, ⟨nat.one_lt_iff_ne_zero_and_ne_one.2 ⟨hp.1, λ h1, hp.2.1 $ h1.symm ▸ is_unit_one⟩,
λ a h, let ⟨b, hab⟩ := h in
(hp.2.2 a b (hab ▸ dvd_refl _)).elim
(λ ha, or.inr (nat.dvd_antisymm h ha))
(λ hb, or.inl (have hpb : p = b, from nat.dvd_antisymm hb
(hab.symm ▸ dvd_mul_left _ _),
(nat.mul_right_inj (show 0 < p, from
nat.pos_of_ne_zero hp.1)).1 $
by rw [hpb, mul_comm, ← hab, hpb, mul_one]))⟩⟩
lemma nat.prime_iff_prime_int {p : ℕ} : p.prime ↔ _root_.prime (p : ℤ) :=
⟨λ hp, ⟨int.coe_nat_ne_zero_iff_pos.2 hp.pos, mt is_unit_int.1 hp.ne_one,
λ a b h, by rw [← int.dvd_nat_abs, int.coe_nat_dvd, int.nat_abs_mul, hp.dvd_mul] at h;
rwa [← int.dvd_nat_abs, int.coe_nat_dvd, ← int.dvd_nat_abs, int.coe_nat_dvd]⟩,
λ hp, nat.prime_iff_prime.2 ⟨int.coe_nat_ne_zero.1 hp.1,
mt nat.is_unit_iff.1 $ λ h, by simpa [h, not_prime_one] using hp,
λ a b, by simpa only [int.coe_nat_dvd, (int.coe_nat_mul _ _).symm] using hp.2.2 a b⟩⟩
/-- Maps an associate class of integers consisting of `-n, n` to `n : ℕ` -/
def associates_int_equiv_nat : associates ℤ ≃ ℕ :=
begin
refine ⟨λz, z.out.nat_abs, λn, associates.mk n, _, _⟩,
{ refine (assume a, quotient.induction_on' a $ assume a,
associates.mk_eq_mk_iff_associated.2 $ associated.symm $ ⟨norm_unit a, _⟩),
show normalize a = int.nat_abs (normalize a),
rw [int.coe_nat_abs_eq_normalize, normalize_idem] },
{ intro n, dsimp, rw [associates.out_mk ↑n,
← int.coe_nat_abs_eq_normalize, int.nat_abs_of_nat, int.nat_abs_of_nat] }
end
lemma int.prime.dvd_mul {m n : ℤ} {p : ℕ}
(hp : nat.prime p) (h : (p : ℤ) ∣ m * n) : p ∣ m.nat_abs ∨ p ∣ n.nat_abs :=
begin
apply (nat.prime.dvd_mul hp).mp,
rw ← int.nat_abs_mul,
exact int.coe_nat_dvd_left.mp h
end
lemma int.prime.dvd_mul' {m n : ℤ} {p : ℕ}
(hp : nat.prime p) (h : (p : ℤ) ∣ m * n) : (p : ℤ) ∣ m ∨ (p : ℤ) ∣ n :=
begin
rw [int.coe_nat_dvd_left, int.coe_nat_dvd_left],
exact int.prime.dvd_mul hp h
end
lemma int.prime.dvd_pow {n : ℤ} {k p : ℕ}
(hp : nat.prime p) (h : (p : ℤ) ∣ n ^ k) : p ∣ n.nat_abs :=
begin
apply @nat.prime.dvd_of_dvd_pow _ _ k hp,
rw ← int.nat_abs_pow,
exact int.coe_nat_dvd_left.mp h
end
lemma int.prime.dvd_pow' {n : ℤ} {k p : ℕ}
(hp : nat.prime p) (h : (p : ℤ) ∣ n ^ k) : (p : ℤ) ∣ n :=
begin
rw int.coe_nat_dvd_left,
exact int.prime.dvd_pow hp h
end
lemma prime_two_or_dvd_of_dvd_two_mul_pow_self_two {m : ℤ} {p : ℕ}
(hp : nat.prime p) (h : (p : ℤ) ∣ 2 * m ^ 2) : p = 2 ∨ p ∣ int.nat_abs m :=
begin
cases int.prime.dvd_mul hp h with hp2 hpp,
{ apply or.intro_left,
exact le_antisymm (nat.le_of_dvd zero_lt_two hp2) (nat.prime.two_le hp) },
{ apply or.intro_right,
rw [pow_two, int.nat_abs_mul] at hpp,
exact (or_self _).mp ((nat.prime.dvd_mul hp).mp hpp)}
end
instance nat.unique_units : unique (units ℕ) :=
{ default := 1, uniq := nat.units_eq_one }
open unique_factorization_monoid
theorem nat.factors_eq {n : ℕ} : factors n = n.factors :=
begin
cases n, {refl},
rw [← multiset.rel_eq, ← associated_eq_eq],
apply factors_unique (irreducible_of_factor) _,
{ rw [multiset.coe_prod, nat.prod_factors (nat.succ_pos _)],
apply factors_prod (nat.succ_ne_zero _) },
{ apply_instance },
{ intros x hx,
rw [nat.irreducible_iff_prime, ← nat.prime_iff],
apply nat.mem_factors hx, }
end
namespace multiplicity
lemma finite_int_iff_nat_abs_finite {a b : ℤ} : finite a b ↔ finite a.nat_abs b.nat_abs :=
by simp only [finite_def, ← int.nat_abs_dvd_abs_iff, int.nat_abs_pow]
lemma finite_int_iff {a b : ℤ} : finite a b ↔ (a.nat_abs ≠ 1 ∧ b ≠ 0) :=
begin
have := int.nat_abs_eq a,
have := @int.nat_abs_ne_zero_of_ne_zero b,
rw [finite_int_iff_nat_abs_finite, finite_nat_iff, nat.pos_iff_ne_zero],
split; finish
end
instance decidable_nat : decidable_rel (λ a b : ℕ, (multiplicity a b).dom) :=
λ a b, decidable_of_iff _ finite_nat_iff.symm
instance decidable_int : decidable_rel (λ a b : ℤ, (multiplicity a b).dom) :=
λ a b, decidable_of_iff _ finite_int_iff.symm
end multiplicity
|
3840ddcce19ff71c52506186ce464648ce5d6006
|
a0e23cfdd129a671bf3154ee1a8a3a72bf4c7940
|
/stage0/src/Lean/Meta/SortLocalDecls.lean
|
df39bf5ede64a4329477ff6be00eff3c8e635f50
|
[
"Apache-2.0"
] |
permissive
|
WojciechKarpiel/lean4
|
7f89706b8e3c1f942b83a2c91a3a00b05da0e65b
|
f6e1314fa08293dea66a329e05b6c196a0189163
|
refs/heads/master
| 1,686,633,402,214
| 1,625,821,189,000
| 1,625,821,258,000
| 384,640,886
| 0
| 0
|
Apache-2.0
| 1,625,903,617,000
| 1,625,903,026,000
| null |
UTF-8
|
Lean
| false
| false
| 1,785
|
lean
|
/-
Copyright (c) 2021 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
import Lean.Meta.Basic
namespace Lean.Meta
namespace SortLocalDecls
structure Context where
localDecls : NameMap LocalDecl := {}
structure State where
visited : NameSet := {}
result : Array LocalDecl := #[]
abbrev M := ReaderT Context $ StateRefT State MetaM
mutual
partial def visitExpr (e : Expr) : M Unit := do
match e with
| Expr.proj _ _ e _ => visitExpr e
| Expr.forallE _ d b _ => visitExpr d; visitExpr b
| Expr.lam _ d b _ => visitExpr d; visitExpr b
| Expr.letE _ t v b _ => visitExpr t; visitExpr v; visitExpr b
| Expr.app f a _ => visitExpr f; visitExpr a
| Expr.mdata _ b _ => visitExpr b
| Expr.mvar _ _ => let v ← instantiateMVars e; unless v.isMVar do visitExpr v
| Expr.fvar fvarId _ => if let some localDecl := (← read).localDecls.find? fvarId then visitLocalDecl localDecl
| _ => return ()
partial def visitLocalDecl (localDecl : LocalDecl) : M Unit := do
unless (← get).visited.contains localDecl.fvarId do
modify fun s => { s with visited := s.visited.insert localDecl.fvarId }
visitExpr localDecl.type
if let some val := localDecl.value? then
visitExpr val
modify fun s => { s with result := s.result.push localDecl }
end
end SortLocalDecls
open SortLocalDecls in
def sortLocalDecls (localDecls : Array LocalDecl) : MetaM (Array LocalDecl) :=
let aux : M (Array LocalDecl) := do localDecls.forM visitLocalDecl; return (← get).result
aux.run { localDecls := localDecls.foldl (init := {}) fun s d => s.insert d.fvarId d } |>.run' {}
end Lean.Meta
|
8f5fb310d81fea46af6e194418871f46ceac55ae
|
63abd62053d479eae5abf4951554e1064a4c45b4
|
/src/measure_theory/giry_monad.lean
|
b20c52f9866cdc8576fcbe40f0b7e0cd089a606c
|
[
"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
| 8,188
|
lean
|
/-
Copyright (c) 2019 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl
-/
import measure_theory.integration
/-!
# The Giry monad
Let X be a measurable space. The collection of all measures on X again
forms a measurable space. This construction forms a monad on
measurable spaces and measurable functions, called the Giry monad.
Note that most sources use the term "Giry monad" for the restriction
to *probability* measures. Here we include all measures on X.
See also `measure_theory/category/Meas.lean`, containing an upgrade of the type-level
monad to an honest monad of the functor `Measure : Meas ⥤ Meas`.
## References
* <https://ncatlab.org/nlab/show/Giry+monad>
## Tags
giry monad
-/
noncomputable theory
open_locale classical big_operators
open classical set filter
variables {α β γ δ ε : Type*}
namespace measure_theory
namespace measure
variables [measurable_space α] [measurable_space β]
/-- Measurability structure on `measure`: Measures are measurable w.r.t. all projections -/
instance : measurable_space (measure α) :=
⨆ (s : set α) (hs : is_measurable s), (borel ennreal).comap (λμ, μ s)
lemma measurable_coe {s : set α} (hs : is_measurable s) : measurable (λμ : measure α, μ s) :=
measurable.of_comap_le $ le_supr_of_le s $ le_supr_of_le hs $ le_refl _
lemma measurable_of_measurable_coe (f : β → measure α)
(h : ∀(s : set α) (hs : is_measurable s), measurable (λb, f b s)) :
measurable f :=
measurable.of_le_map $ bsupr_le $ assume s hs, measurable_space.comap_le_iff_le_map.2 $
by rw [measurable_space.map_comp]; exact h s hs
lemma measurable_measure {μ : α → measure β} :
measurable μ ↔ ∀(s : set β) (hs : is_measurable s), measurable (λb, μ b s) :=
⟨λ hμ s hs, (measurable_coe hs).comp hμ, measurable_of_measurable_coe μ⟩
lemma measurable_map (f : α → β) (hf : measurable f) :
measurable (λμ : measure α, map f μ) :=
measurable_of_measurable_coe _ $ assume s hs,
suffices measurable (λ (μ : measure α), μ (f ⁻¹' s)),
by simpa [map_apply, hs, hf],
measurable_coe (hf hs)
lemma measurable_dirac :
measurable (measure.dirac : α → measure α) :=
measurable_of_measurable_coe _ $ assume s hs,
begin
simp only [dirac_apply, hs],
exact measurable_one.indicator hs
end
lemma measurable_lintegral {f : α → ennreal} (hf : measurable f) :
measurable (λμ : measure α, ∫⁻ x, f x ∂μ) :=
begin
simp only [lintegral_eq_supr_eapprox_lintegral, hf, simple_func.lintegral],
refine measurable_supr (λ n, finset.measurable_sum _ (λ i, _)),
refine measurable_const.ennreal_mul _,
exact measurable_coe ((simple_func.eapprox f n).is_measurable_preimage _)
end
/-- Monadic join on `measure` in the category of measurable spaces and measurable
functions. -/
def join (m : measure (measure α)) : measure α :=
measure.of_measurable
(λs hs, ∫⁻ μ, μ s ∂m)
(by simp)
begin
assume f hf h,
simp [measure_Union h hf],
apply lintegral_tsum,
assume i, exact measurable_coe (hf i)
end
@[simp] lemma join_apply {m : measure (measure α)} :
∀{s : set α}, is_measurable s → join m s = ∫⁻ μ, μ s ∂m :=
measure.of_measurable_apply
lemma measurable_join : measurable (join : measure (measure α) → measure α) :=
measurable_of_measurable_coe _ $ assume s hs,
by simp only [join_apply hs]; exact measurable_lintegral (measurable_coe hs)
lemma lintegral_join {m : measure (measure α)} {f : α → ennreal} (hf : measurable f) :
∫⁻ x, f x ∂(join m) = ∫⁻ μ, ∫⁻ x, f x ∂μ ∂m :=
begin
rw [lintegral_eq_supr_eapprox_lintegral hf],
have : ∀n x,
join m (⇑(simple_func.eapprox (λ (a : α), f a) n) ⁻¹' {x}) =
∫⁻ μ, μ ((⇑(simple_func.eapprox (λ (a : α), f a) n) ⁻¹' {x})) ∂m :=
assume n x, join_apply (simple_func.is_measurable_preimage _ _),
simp only [simple_func.lintegral, this],
transitivity,
have : ∀(s : ℕ → finset ennreal) (f : ℕ → ennreal → measure α → ennreal)
(hf : ∀n r, measurable (f n r)) (hm : monotone (λn μ, ∑ r in s n, r * f n r μ)),
(⨆n:ℕ, ∑ r in s n, r * ∫⁻ μ, f n r μ ∂m) =
∫⁻ μ, ⨆n:ℕ, ∑ r in s n, r * f n r μ ∂m,
{ assume s f hf hm,
symmetry,
transitivity,
apply lintegral_supr,
{ assume n,
exact finset.measurable_sum _ (assume r, measurable_const.ennreal_mul (hf _ _)) },
{ exact hm },
congr, funext n,
transitivity,
apply lintegral_finset_sum,
{ assume r, exact measurable_const.ennreal_mul (hf _ _) },
congr, funext r,
apply lintegral_const_mul,
exact hf _ _ },
specialize this (λn, simple_func.range (simple_func.eapprox f n)),
specialize this
(λn r μ, μ (⇑(simple_func.eapprox (λ (a : α), f a) n) ⁻¹' {r})),
refine this _ _; clear this,
{ assume n r,
apply measurable_coe,
exact simple_func.is_measurable_preimage _ _ },
{ change monotone (λn μ, (simple_func.eapprox f n).lintegral μ),
assume n m h μ,
refine simple_func.lintegral_mono _ (le_refl _),
apply simple_func.monotone_eapprox,
assumption },
congr, funext μ,
symmetry,
apply lintegral_eq_supr_eapprox_lintegral,
exact hf
end
/-- Monadic bind on `measure`, only works in the category of measurable spaces and measurable
functions. When the function `f` is not measurable the result is not well defined. -/
def bind (m : measure α) (f : α → measure β) : measure β := join (map f m)
@[simp] lemma bind_apply {m : measure α} {f : α → measure β} {s : set β}
(hs : is_measurable s) (hf : measurable f) :
bind m f s = ∫⁻ a, f a s ∂m :=
by rw [bind, join_apply hs, lintegral_map (measurable_coe hs) hf]
lemma measurable_bind' {g : α → measure β} (hg : measurable g) : measurable (λm, bind m g) :=
measurable_join.comp (measurable_map _ hg)
lemma lintegral_bind {m : measure α} {μ : α → measure β} {f : β → ennreal}
(hμ : measurable μ) (hf : measurable f) :
∫⁻ x, f x ∂ (bind m μ) = ∫⁻ a, ∫⁻ x, f x ∂(μ a) ∂m:=
(lintegral_join hf).trans (lintegral_map (measurable_lintegral hf) hμ)
lemma bind_bind {γ} [measurable_space γ] {m : measure α} {f : α → measure β} {g : β → measure γ}
(hf : measurable f) (hg : measurable g) :
bind (bind m f) g = bind m (λa, bind (f a) g) :=
measure.ext $ assume s hs,
begin
rw [bind_apply hs hg, bind_apply hs ((measurable_bind' hg).comp hf), lintegral_bind hf],
{ congr, funext a,
exact (bind_apply hs hg).symm },
exact (measurable_coe hs).comp hg
end
lemma bind_dirac {f : α → measure β} (hf : measurable f) (a : α) : bind (dirac a) f = f a :=
measure.ext $ assume s hs, by rw [bind_apply hs hf, lintegral_dirac a ((measurable_coe hs).comp hf)]
lemma dirac_bind {m : measure α} : bind m dirac = m :=
measure.ext $ assume s hs,
by simp [bind_apply hs measurable_dirac, dirac_apply _ hs, lintegral_indicator 1 hs]
lemma map_dirac {f : α → β} (hf : measurable f) (a : α) :
map f (dirac a) = dirac (f a) :=
measure.ext $ assume s hs, by simp [hs, map_apply hf hs, hf hs, indicator_apply]
lemma join_eq_bind (μ : measure (measure α)) : join μ = bind μ id :=
by rw [bind, map_id]
lemma join_map_map {f : α → β} (hf : measurable f) (μ : measure (measure α)) :
join (map (map f) μ) = map f (join μ) :=
measure.ext $ assume s hs,
begin
rw [join_apply hs, map_apply hf hs, join_apply,
lintegral_map (measurable_coe hs) (measurable_map f hf)],
{ congr, funext ν, exact map_apply hf hs },
exact hf hs
end
lemma join_map_join (μ : measure (measure (measure α))) :
join (map join μ) = join (join μ) :=
begin
show bind μ join = join (join μ),
rw [join_eq_bind, join_eq_bind, bind_bind measurable_id measurable_id],
apply congr_arg (bind μ),
funext ν,
exact join_eq_bind ν
end
lemma join_map_dirac (μ : measure α) : join (map dirac μ) = μ :=
dirac_bind
lemma join_dirac (μ : measure α) : join (dirac μ) = μ :=
eq.trans (join_eq_bind (dirac μ)) (bind_dirac measurable_id _)
end measure
end measure_theory
|
69dc3b034aa55a67b1f78b53aa35b6da702a01ec
|
8cae430f0a71442d02dbb1cbb14073b31048e4b0
|
/src/topology/algebra/infinite_sum/real.lean
|
3db37b9ec67705c975185ae8a483721576ce46c9
|
[
"Apache-2.0"
] |
permissive
|
leanprover-community/mathlib
|
56a2cadd17ac88caf4ece0a775932fa26327ba0e
|
442a83d738cb208d3600056c489be16900ba701d
|
refs/heads/master
| 1,693,584,102,358
| 1,693,471,902,000
| 1,693,471,902,000
| 97,922,418
| 1,595
| 352
|
Apache-2.0
| 1,694,693,445,000
| 1,500,624,130,000
|
Lean
|
UTF-8
|
Lean
| false
| false
| 4,256
|
lean
|
/-
Copyright (c) 2019 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel, Yury Kudryashov
-/
import algebra.big_operators.intervals
import topology.algebra.infinite_sum.order
import topology.instances.real
/-!
# Infinite sum in the reals
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
This file provides lemmas about Cauchy sequences in terms of infinite sums.
-/
open filter finset
open_locale big_operators nnreal topology
variables {α : Type*}
/-- If the extended distance between consecutive points of a sequence is estimated
by a summable series of `nnreal`s, then the original sequence is a Cauchy sequence. -/
lemma cauchy_seq_of_edist_le_of_summable [pseudo_emetric_space α] {f : ℕ → α} (d : ℕ → ℝ≥0)
(hf : ∀ n, edist (f n) (f n.succ) ≤ d n) (hd : summable d) : cauchy_seq f :=
begin
refine emetric.cauchy_seq_iff_nnreal.2 (λ ε εpos, _),
-- Actually we need partial sums of `d` to be a Cauchy sequence
replace hd : cauchy_seq (λ (n : ℕ), ∑ x in range n, d x) :=
let ⟨_, H⟩ := hd in H.tendsto_sum_nat.cauchy_seq,
-- Now we take the same `N` as in one of the definitions of a Cauchy sequence
refine (metric.cauchy_seq_iff'.1 hd ε (nnreal.coe_pos.2 εpos)).imp (λ N hN n hn, _),
have hsum := hN n hn,
-- We simplify the known inequality
rw [dist_nndist, nnreal.nndist_eq, ← sum_range_add_sum_Ico _ hn, add_tsub_cancel_left] at hsum,
norm_cast at hsum,
replace hsum := lt_of_le_of_lt (le_max_left _ _) hsum,
rw edist_comm,
-- Then use `hf` to simplify the goal to the same form
apply lt_of_le_of_lt (edist_le_Ico_sum_of_edist_le hn (λ k _ _, hf k)),
assumption_mod_cast
end
variables [pseudo_metric_space α] {f : ℕ → α} {a : α}
/-- If the distance between consecutive points of a sequence is estimated by a summable series,
then the original sequence is a Cauchy sequence. -/
lemma cauchy_seq_of_dist_le_of_summable (d : ℕ → ℝ) (hf : ∀ n, dist (f n) (f n.succ) ≤ d n)
(hd : summable d) : cauchy_seq f :=
begin
refine metric.cauchy_seq_iff'.2 (λε εpos, _),
replace hd : cauchy_seq (λ (n : ℕ), ∑ x in range n, d x) :=
let ⟨_, H⟩ := hd in H.tendsto_sum_nat.cauchy_seq,
refine (metric.cauchy_seq_iff'.1 hd ε εpos).imp (λ N hN n hn, _),
have hsum := hN n hn,
rw [real.dist_eq, ← sum_Ico_eq_sub _ hn] at hsum,
calc dist (f n) (f N) = dist (f N) (f n) : dist_comm _ _
... ≤ ∑ x in Ico N n, d x : dist_le_Ico_sum_of_dist_le hn (λ k _ _, hf k)
... ≤ |∑ x in Ico N n, d x| : le_abs_self _
... < ε : hsum
end
lemma cauchy_seq_of_summable_dist (h : summable (λ n, dist (f n) (f n.succ))) : cauchy_seq f :=
cauchy_seq_of_dist_le_of_summable _ (λ _, le_rfl) h
lemma dist_le_tsum_of_dist_le_of_tendsto (d : ℕ → ℝ) (hf : ∀ n, dist (f n) (f n.succ) ≤ d n)
(hd : summable d) {a : α} (ha : tendsto f at_top (𝓝 a)) (n : ℕ) :
dist (f n) a ≤ ∑' m, d (n + m) :=
begin
refine le_of_tendsto (tendsto_const_nhds.dist ha)
(eventually_at_top.2 ⟨n, λ m hnm, _⟩),
refine le_trans (dist_le_Ico_sum_of_dist_le hnm (λ k _ _, hf k)) _,
rw [sum_Ico_eq_sum_range],
refine sum_le_tsum (range _) (λ _ _, le_trans dist_nonneg (hf _)) _,
exact hd.comp_injective (add_right_injective n)
end
lemma dist_le_tsum_of_dist_le_of_tendsto₀ (d : ℕ → ℝ) (hf : ∀ n, dist (f n) (f n.succ) ≤ d n)
(hd : summable d) (ha : tendsto f at_top (𝓝 a)) :
dist (f 0) a ≤ tsum d :=
by simpa only [zero_add] using dist_le_tsum_of_dist_le_of_tendsto d hf hd ha 0
lemma dist_le_tsum_dist_of_tendsto (h : summable (λ n, dist (f n) (f n.succ)))
(ha : tendsto f at_top (𝓝 a)) (n) :
dist (f n) a ≤ ∑' m, dist (f (n + m)) (f (n + m).succ) :=
show dist (f n) a ≤ ∑' m, (λx, dist (f x) (f x.succ)) (n + m), from
dist_le_tsum_of_dist_le_of_tendsto (λ n, dist (f n) (f n.succ)) (λ _, le_rfl) h ha n
lemma dist_le_tsum_dist_of_tendsto₀ (h : summable (λ n, dist (f n) (f n.succ)))
(ha : tendsto f at_top (𝓝 a)) :
dist (f 0) a ≤ ∑' n, dist (f n) (f n.succ) :=
by simpa only [zero_add] using dist_le_tsum_dist_of_tendsto h ha 0
|
20285250856b6758c0eb2a892f9062f486cb80fe
|
d406927ab5617694ec9ea7001f101b7c9e3d9702
|
/src/data/int/order/lemmas.lean
|
658dd4abab57b1f3c50d3dac536e280bea47d2c8
|
[
"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,044
|
lean
|
/-
Copyright (c) 2016 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad
-/
import data.int.order.basic
import algebra.group_with_zero.divisibility
import algebra.order.ring.abs
/-!
# Further lemmas about the integers
The distinction between this file and `data.int.order.basic` is not particularly clear.
They are separated by now to minimize the porting requirements for tactics during the transition to
mathlib4. After `data.rat.order` has been ported, please feel free to reorganize these two files.
-/
open nat
namespace int
/-! ### nat abs -/
variables {a b : ℤ} {n : ℕ}
lemma nat_abs_eq_iff_mul_self_eq {a b : ℤ} : a.nat_abs = b.nat_abs ↔ a * a = b * b :=
begin
rw [← abs_eq_iff_mul_self_eq, abs_eq_nat_abs, abs_eq_nat_abs],
exact int.coe_nat_inj'.symm
end
lemma eq_nat_abs_iff_mul_eq_zero : a.nat_abs = n ↔ (a - n) * (a + n) = 0 :=
by rw [nat_abs_eq_iff, mul_eq_zero, sub_eq_zero, add_eq_zero_iff_eq_neg]
lemma nat_abs_lt_iff_mul_self_lt {a b : ℤ} : a.nat_abs < b.nat_abs ↔ a * a < b * b :=
begin
rw [← abs_lt_iff_mul_self_lt, abs_eq_nat_abs, abs_eq_nat_abs],
exact int.coe_nat_lt.symm
end
lemma nat_abs_le_iff_mul_self_le {a b : ℤ} : a.nat_abs ≤ b.nat_abs ↔ a * a ≤ b * b :=
begin
rw [← abs_le_iff_mul_self_le, abs_eq_nat_abs, abs_eq_nat_abs],
exact int.coe_nat_le.symm
end
lemma dvd_div_of_mul_dvd {a b c : ℤ} (h : a * b ∣ c) : b ∣ c / a :=
begin
rcases eq_or_ne a 0 with rfl | ha,
{ simp only [int.div_zero, dvd_zero] },
rcases h with ⟨d, rfl⟩,
refine ⟨d, _⟩,
rw [mul_assoc, int.mul_div_cancel_left _ ha],
end
/-! ### units -/
lemma eq_zero_of_abs_lt_dvd {m x : ℤ} (h1 : m ∣ x) (h2 : | x | < m) : x = 0 :=
begin
by_cases hm : m = 0, { subst m, exact zero_dvd_iff.mp h1, },
rcases h1 with ⟨d, rfl⟩,
apply mul_eq_zero_of_right,
rw [←abs_lt_one_iff, ←mul_lt_iff_lt_one_right (abs_pos.mpr hm), ←abs_mul],
exact lt_of_lt_of_le h2 (le_abs_self m),
end
end int
|
0495ed8f5038793cb318eb0b85853c7b8d6712bf
|
4fa118f6209450d4e8d058790e2967337811b2b5
|
/src/sheaves/opens.lean
|
f0be9ad22acbdbec08ec8a5ba00859a59fd35432
|
[
"Apache-2.0"
] |
permissive
|
leanprover-community/lean-perfectoid-spaces
|
16ab697a220ed3669bf76311daa8c466382207f7
|
95a6520ce578b30a80b4c36e36ab2d559a842690
|
refs/heads/master
| 1,639,557,829,139
| 1,638,797,866,000
| 1,638,797,866,000
| 135,769,296
| 96
| 10
|
Apache-2.0
| 1,638,797,866,000
| 1,527,892,754,000
|
Lean
|
UTF-8
|
Lean
| false
| false
| 1,936
|
lean
|
/-
Basic definitions and lemmas about opens.
TODO : Not use opens as sets when possible.
Author: Ramon Fernandez Mir
-/
import topology.basic
import topology.opens
universes u v
open topological_space lattice lattice.lattice
section opens
variables {α : Type u} [topological_space α]
-- A couple of useful tricks to work avoid using the lattice jargon when
-- dealing with opens.
@[simp] lemma opens.inter (U V : opens α) :
U ∩ V = ⟨U.1 ∩ V.1, is_open_inter U.2 V.2⟩ := rfl
lemma opens.inter_comm (U V : opens α) :
U ∩ V = V ∩ U := subtype.ext.2 $ set.inter_comm U.1 V.1
prefix `⋃` := supr
-- Opens constants.
def opens.univ : opens α := ⟨set.univ, is_open_univ⟩
def opens.empty : opens α := ⟨∅, is_open_empty⟩
-- Some useful lemmas. Maybe versions of them are already somewhere.
lemma opens_supr_mem {γ : Type*} (X : γ → opens α)
: ∀ i x, x ∈ (X i).val → x ∈ (⋃ X).val :=
λ i x Hx, let Xi := X i in
begin
unfold supr; simp,
exact ⟨Xi.1, ⟨⟨Xi.2, i, by simp⟩, Hx⟩⟩,
end
lemma opens_supr_subset {γ : Type*} (X : γ → opens α)
: ∀ i, X i ⊆ ⋃ X :=
λ i x, opens_supr_mem X i x
-- Opens comap.
section opens_comap
variables {β : Type v} [topological_space β]
variables {f : α → β} (Hf : continuous f)
@[reducible] def opens.comap : opens β → opens α :=
λ U, ⟨f ⁻¹' U.1, Hf U.1 U.2⟩
def opens.comap_mono (U V : opens β) (HUV : U ≤ V) : opens.comap Hf U ≤ opens.comap Hf V :=
set.preimage_mono HUV
end opens_comap
-- Opens map (assuming that f is an open immersion).
section opens_map
variables {β : Type v} [topological_space β]
variables {f : α → β} (Hf : ∀ (U : opens α), is_open (f '' U))
def opens.map : opens α → opens β :=
λ U, ⟨f '' U, Hf U⟩
lemma opens.map_mono (U V : opens α) (HUV : U ≤ V) : opens.map Hf U ≤ opens.map Hf V :=
set.image_subset f HUV
end opens_map
end opens
|
2ac716820e79ba15b03f5d855cb58ac43e0a66c1
|
432d948a4d3d242fdfb44b81c9e1b1baacd58617
|
/src/algebra/group_ring_action.lean
|
d1cdf3676f663b064e122a81205525768b3c691f
|
[
"Apache-2.0"
] |
permissive
|
JLimperg/aesop3
|
306cc6570c556568897ed2e508c8869667252e8a
|
a4a116f650cc7403428e72bd2e2c4cda300fe03f
|
refs/heads/master
| 1,682,884,916,368
| 1,620,320,033,000
| 1,620,320,033,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 5,544
|
lean
|
/-
Copyright (c) 2020 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau
-/
import group_theory.group_action.group
import data.equiv.ring
import deprecated.subring
/-!
# Group action on rings
This file defines the typeclass of monoid acting on semirings `mul_semiring_action M R`,
and the corresponding typeclass of invariant subrings.
Note that `algebra` does not satisfy the axioms of `mul_semiring_action`.
## Implementation notes
There is no separate typeclass for group acting on rings, group acting on fields, etc.
They are all grouped under `mul_semiring_action`.
## Tags
group action, invariant subring
-/
universes u v
open_locale big_operators
/-- Typeclass for multiplicative actions by monoids on semirings. -/
class mul_semiring_action (M : Type u) [monoid M] (R : Type v) [semiring R]
extends distrib_mul_action M R :=
(smul_one : ∀ (g : M), (g • 1 : R) = 1)
(smul_mul : ∀ (g : M) (x y : R), g • (x * y) = (g • x) * (g • y))
export mul_semiring_action (smul_one)
/-- Typeclass for faithful multiplicative actions by monoids on semirings. -/
class faithful_mul_semiring_action (M : Type u) [monoid M] (R : Type v) [semiring R]
extends mul_semiring_action M R :=
(eq_of_smul_eq_smul' : ∀ {m₁ m₂ : M}, (∀ r : R, m₁ • r = m₂ • r) → m₁ = m₂)
section semiring
variables (M G : Type u) [monoid M] [group G]
variables (A R S F : Type v) [add_monoid A] [semiring R] [comm_semiring S] [field F]
variables {M R}
lemma smul_mul' [mul_semiring_action M R] (g : M) (x y : R) :
g • (x * y) = (g • x) * (g • y) :=
mul_semiring_action.smul_mul g x y
variables {M} (R)
theorem eq_of_smul_eq_smul [faithful_mul_semiring_action M R] {m₁ m₂ : M} :
(∀ r : R, m₁ • r = m₂ • r) → m₁ = m₂ :=
faithful_mul_semiring_action.eq_of_smul_eq_smul'
variables (M R)
/-- Each element of the monoid defines a additive monoid homomorphism. -/
def distrib_mul_action.to_add_monoid_hom [distrib_mul_action M A] (x : M) : A →+ A :=
{ to_fun := (•) x,
map_zero' := smul_zero x,
map_add' := smul_add x }
/-- Each element of the group defines an additive monoid isomorphism. -/
def distrib_mul_action.to_add_equiv [distrib_mul_action G A] (x : G) : A ≃+ A :=
{ .. distrib_mul_action.to_add_monoid_hom G A x,
.. mul_action.to_perm G A x }
/-- Each element of the group defines an additive monoid homomorphism. -/
def distrib_mul_action.hom_add_monoid_hom [distrib_mul_action M A] : M →* add_monoid.End A :=
{ to_fun := distrib_mul_action.to_add_monoid_hom M A,
map_one' := add_monoid_hom.ext $ λ x, one_smul M x,
map_mul' := λ x y, add_monoid_hom.ext $ λ z, mul_smul x y z }
/-- Each element of the monoid defines a semiring homomorphism. -/
def mul_semiring_action.to_semiring_hom [mul_semiring_action M R] (x : M) : R →+* R :=
{ map_one' := smul_one x,
map_mul' := smul_mul' x,
.. distrib_mul_action.to_add_monoid_hom M R x }
theorem to_semiring_hom_injective [faithful_mul_semiring_action M R] :
function.injective (mul_semiring_action.to_semiring_hom M R) :=
λ m₁ m₂ h, eq_of_smul_eq_smul R $ λ r, ring_hom.ext_iff.1 h r
/-- Each element of the group defines a semiring isomorphism. -/
def mul_semiring_action.to_semiring_equiv [mul_semiring_action G R] (x : G) : R ≃+* R :=
{ .. distrib_mul_action.to_add_equiv G R x,
.. mul_semiring_action.to_semiring_hom G R x }
section prod
variables [mul_semiring_action M R] [mul_semiring_action M S]
lemma list.smul_prod (g : M) (L : list R) : g • L.prod = (L.map $ (•) g).prod :=
monoid_hom.map_list_prod (mul_semiring_action.to_semiring_hom M R g : R →* R) L
lemma multiset.smul_prod (g : M) (m : multiset S) : g • m.prod = (m.map $ (•) g).prod :=
monoid_hom.map_multiset_prod (mul_semiring_action.to_semiring_hom M S g : S →* S) m
lemma smul_prod (g : M) {ι : Type*} (f : ι → S) (s : finset ι) :
g • ∏ i in s, f i = ∏ i in s, g • f i :=
monoid_hom.map_prod (mul_semiring_action.to_semiring_hom M S g : S →* S) f s
end prod
section simp_lemmas
variables {M G A R}
attribute [simp] smul_one smul_mul' smul_zero smul_add
@[simp] lemma smul_inv [mul_semiring_action M F] (x : M) (m : F) : x • m⁻¹ = (x • m)⁻¹ :=
(mul_semiring_action.to_semiring_hom M F x).map_inv _
@[simp] lemma smul_pow [mul_semiring_action M R] (x : M) (m : R) (n : ℕ) :
x • m ^ n = (x • m) ^ n :=
begin
induction n with n ih,
{ rw [pow_zero, pow_zero], exact smul_one x },
{ rw [pow_succ, pow_succ], exact (smul_mul' x m (m ^ n)).trans (congr_arg _ ih) }
end
end simp_lemmas
end semiring
section ring
variables (M : Type u) [monoid M] {R : Type v} [ring R] [mul_semiring_action M R]
variables (S : set R) [is_subring S]
open mul_action
set_option old_structure_cmd false
/-- A subring invariant under the action. -/
class is_invariant_subring : Prop :=
(smul_mem : ∀ (m : M) {x : R}, x ∈ S → m • x ∈ S)
variables [is_invariant_subring M S]
local attribute [instance] subset.ring
instance is_invariant_subring.to_mul_semiring_action : mul_semiring_action M S :=
{ smul := λ m x, ⟨m • x, is_invariant_subring.smul_mem m x.2⟩,
one_smul := λ s, subtype.eq $ one_smul M s,
mul_smul := λ m₁ m₂ s, subtype.eq $ mul_smul m₁ m₂ s,
smul_add := λ m s₁ s₂, subtype.eq $ smul_add m s₁ s₂,
smul_zero := λ m, subtype.eq $ smul_zero m,
smul_one := λ m, subtype.eq $ smul_one m,
smul_mul := λ m s₁ s₂, subtype.eq $ smul_mul' m s₁ s₂ }
end ring
|
70b4083e55110c9395e30febd61b80ce16e43c82
|
d406927ab5617694ec9ea7001f101b7c9e3d9702
|
/src/analysis/analytic/inverse.lean
|
91a9a365f5f3a0dbdf1b7ff79db9ad94d4fce07c
|
[
"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
| 27,270
|
lean
|
/-
Copyright (c) 2021 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel
-/
import analysis.analytic.composition
import tactic.congrm
/-!
# Inverse of analytic functions
We construct the left and right inverse of a formal multilinear series with invertible linear term,
we prove that they coincide and study their properties (notably convergence).
## Main statements
* `p.left_inv i`: the formal left inverse of the formal multilinear series `p`,
for `i : E ≃L[𝕜] F` which coincides with `p₁`.
* `p.right_inv i`: the formal right inverse of the formal multilinear series `p`,
for `i : E ≃L[𝕜] F` which coincides with `p₁`.
* `p.left_inv_comp` says that `p.left_inv i` is indeed a left inverse to `p` when `p₁ = i`.
* `p.right_inv_comp` says that `p.right_inv i` is indeed a right inverse to `p` when `p₁ = i`.
* `p.left_inv_eq_right_inv`: the two inverses coincide.
* `p.radius_right_inv_pos_of_radius_pos`: if a power series has a positive radius of convergence,
then so does its inverse.
-/
open_locale big_operators classical topological_space
open finset filter
namespace formal_multilinear_series
variables {𝕜 : Type*} [nontrivially_normed_field 𝕜]
{E : Type*} [normed_add_comm_group E] [normed_space 𝕜 E]
{F : Type*} [normed_add_comm_group F] [normed_space 𝕜 F]
/-! ### The left inverse of a formal multilinear series -/
/-- The left inverse of a formal multilinear series, where the `n`-th term is defined inductively
in terms of the previous ones to make sure that `(left_inv p i) ∘ p = id`. For this, the linear term
`p₁` in `p` should be invertible. In the definition, `i` is a linear isomorphism that should
coincide with `p₁`, so that one can use its inverse in the construction. The definition does not
use that `i = p₁`, but proofs that the definition is well-behaved do.
The `n`-th term in `q ∘ p` is `∑ qₖ (p_{j₁}, ..., p_{jₖ})` over `j₁ + ... + jₖ = n`. In this
expression, `qₙ` appears only once, in `qₙ (p₁, ..., p₁)`. We adjust the definition so that this
term compensates the rest of the sum, using `i⁻¹` as an inverse to `p₁`.
These formulas only make sense when the constant term `p₀` vanishes. The definition we give is
general, but it ignores the value of `p₀`.
-/
noncomputable def left_inv (p : formal_multilinear_series 𝕜 E F) (i : E ≃L[𝕜] F) :
formal_multilinear_series 𝕜 F E
| 0 := 0
| 1 := (continuous_multilinear_curry_fin1 𝕜 F E).symm i.symm
| (n+2) := - ∑ c : {c : composition (n+2) // c.length < n + 2},
have (c : composition (n+2)).length < n+2 := c.2,
(left_inv (c : composition (n+2)).length).comp_along_composition
(p.comp_continuous_linear_map i.symm) c
@[simp] lemma left_inv_coeff_zero (p : formal_multilinear_series 𝕜 E F) (i : E ≃L[𝕜] F) :
p.left_inv i 0 = 0 := by rw left_inv
@[simp] lemma left_inv_coeff_one (p : formal_multilinear_series 𝕜 E F) (i : E ≃L[𝕜] F) :
p.left_inv i 1 = (continuous_multilinear_curry_fin1 𝕜 F E).symm i.symm := by rw left_inv
/-- The left inverse does not depend on the zeroth coefficient of a formal multilinear
series. -/
lemma left_inv_remove_zero (p : formal_multilinear_series 𝕜 E F) (i : E ≃L[𝕜] F) :
p.remove_zero.left_inv i = p.left_inv i :=
begin
ext1 n,
induction n using nat.strong_rec' with n IH,
cases n, { simp }, -- if one replaces `simp` with `refl`, the proof times out in the kernel.
cases n, { simp }, -- TODO: why?
simp only [left_inv, neg_inj],
refine finset.sum_congr rfl (λ c cuniv, _),
rcases c with ⟨c, hc⟩,
ext v,
dsimp,
simp [IH _ hc],
end
/-- The left inverse to a formal multilinear series is indeed a left inverse, provided its linear
term is invertible. -/
lemma left_inv_comp (p : formal_multilinear_series 𝕜 E F) (i : E ≃L[𝕜] F)
(h : p 1 = (continuous_multilinear_curry_fin1 𝕜 E F).symm i) :
(left_inv p i).comp p = id 𝕜 E :=
begin
ext n v,
cases n,
{ simp only [left_inv, continuous_multilinear_map.zero_apply, id_apply_ne_one, ne.def,
not_false_iff, zero_ne_one, comp_coeff_zero']},
cases n,
{ simp only [left_inv, comp_coeff_one, h, id_apply_one, continuous_linear_equiv.coe_apply,
continuous_linear_equiv.symm_apply_apply, continuous_multilinear_curry_fin1_symm_apply] },
have A : (finset.univ : finset (composition (n+2)))
= {c | composition.length c < n + 2}.to_finset ∪ {composition.ones (n+2)},
{ refine subset.antisymm (λ c hc, _) (subset_univ _),
by_cases h : c.length < n + 2,
{ simp [h] },
{ simp [composition.eq_ones_iff_le_length.2 (not_lt.1 h)] } },
have B : disjoint ({c | composition.length c < n + 2} : set (composition (n + 2))).to_finset
{composition.ones (n+2)}, by simp,
have C : (p.left_inv i (composition.ones (n + 2)).length)
(λ (j : fin (composition.ones n.succ.succ).length), p 1 (λ k,
v ((fin.cast_le (composition.length_le _)) j)))
= p.left_inv i (n+2) (λ (j : fin (n+2)), p 1 (λ k, v j)),
{ apply formal_multilinear_series.congr _ (composition.ones_length _) (λ j hj1 hj2, _),
exact formal_multilinear_series.congr _ rfl (λ k hk1 hk2, by congr) },
have D : p.left_inv i (n+2) (λ (j : fin (n+2)), p 1 (λ k, v j)) =
- ∑ (c : composition (n + 2)) in {c : composition (n + 2) | c.length < n + 2}.to_finset,
(p.left_inv i c.length) (p.apply_composition c v),
{ simp only [left_inv, continuous_multilinear_map.neg_apply, neg_inj,
continuous_multilinear_map.sum_apply],
convert (sum_to_finset_eq_subtype (λ (c : composition (n+2)), c.length < n+2)
(λ (c : composition (n+2)), (continuous_multilinear_map.comp_along_composition
(p.comp_continuous_linear_map ↑(i.symm)) c (p.left_inv i c.length))
(λ (j : fin (n + 2)), p 1 (λ (k : fin 1), v j)))).symm.trans _,
simp only [comp_continuous_linear_map_apply_composition,
continuous_multilinear_map.comp_along_composition_apply],
congr,
ext c,
congr,
ext k,
simp [h] },
simp [formal_multilinear_series.comp, show n + 2 ≠ 1, by dec_trivial, A, finset.sum_union B,
apply_composition_ones, C, D],
end
/-! ### The right inverse of a formal multilinear series -/
/-- The right inverse of a formal multilinear series, where the `n`-th term is defined inductively
in terms of the previous ones to make sure that `p ∘ (right_inv p i) = id`. For this, the linear
term `p₁` in `p` should be invertible. In the definition, `i` is a linear isomorphism that should
coincide with `p₁`, so that one can use its inverse in the construction. The definition does not
use that `i = p₁`, but proofs that the definition is well-behaved do.
The `n`-th term in `p ∘ q` is `∑ pₖ (q_{j₁}, ..., q_{jₖ})` over `j₁ + ... + jₖ = n`. In this
expression, `qₙ` appears only once, in `p₁ (qₙ)`. We adjust the definition of `qₙ` so that this
term compensates the rest of the sum, using `i⁻¹` as an inverse to `p₁`.
These formulas only make sense when the constant term `p₀` vanishes. The definition we give is
general, but it ignores the value of `p₀`.
-/
noncomputable def right_inv (p : formal_multilinear_series 𝕜 E F) (i : E ≃L[𝕜] F) :
formal_multilinear_series 𝕜 F E
| 0 := 0
| 1 := (continuous_multilinear_curry_fin1 𝕜 F E).symm i.symm
| (n+2) :=
let q : formal_multilinear_series 𝕜 F E := λ k, if h : k < n + 2 then right_inv k else 0 in
- (i.symm : F →L[𝕜] E).comp_continuous_multilinear_map ((p.comp q) (n+2))
@[simp] lemma right_inv_coeff_zero (p : formal_multilinear_series 𝕜 E F) (i : E ≃L[𝕜] F) :
p.right_inv i 0 = 0 := by rw right_inv
@[simp] lemma right_inv_coeff_one (p : formal_multilinear_series 𝕜 E F) (i : E ≃L[𝕜] F) :
p.right_inv i 1 = (continuous_multilinear_curry_fin1 𝕜 F E).symm i.symm := by rw right_inv
/-- The right inverse does not depend on the zeroth coefficient of a formal multilinear
series. -/
lemma right_inv_remove_zero (p : formal_multilinear_series 𝕜 E F) (i : E ≃L[𝕜] F) :
p.remove_zero.right_inv i = p.right_inv i :=
begin
ext1 n,
induction n using nat.strong_rec' with n IH,
rcases n with _|_|n,
{ simp only [right_inv_coeff_zero] },
{ simp only [right_inv_coeff_one] },
simp only [right_inv, neg_inj],
rw remove_zero_comp_of_pos _ _ (add_pos_of_nonneg_of_pos (n.zero_le) zero_lt_two),
congrm i.symm.to_continuous_linear_map.comp_continuous_multilinear_map (p.comp (λ k, _) _),
by_cases hk : k < n+2; simp [hk, IH]
end
lemma comp_right_inv_aux1 {n : ℕ} (hn : 0 < n)
(p : formal_multilinear_series 𝕜 E F) (q : formal_multilinear_series 𝕜 F E) (v : fin n → F) :
p.comp q n v =
(∑ (c : composition n) in {c : composition n | 1 < c.length}.to_finset,
p c.length (q.apply_composition c v)) + p 1 (λ i, q n v) :=
begin
have A : (finset.univ : finset (composition n))
= {c | 1 < composition.length c}.to_finset ∪ {composition.single n hn},
{ refine subset.antisymm (λ c hc, _) (subset_univ _),
by_cases h : 1 < c.length,
{ simp [h] },
{ have : c.length = 1,
by { refine (eq_iff_le_not_lt.2 ⟨ _, h⟩).symm, exact c.length_pos_of_pos hn },
rw ← composition.eq_single_iff_length hn at this,
simp [this] } },
have B : disjoint ({c | 1 < composition.length c} : set (composition n)).to_finset
{composition.single n hn}, by simp,
have C : p (composition.single n hn).length
(q.apply_composition (composition.single n hn) v)
= p 1 (λ (i : fin 1), q n v),
{ apply p.congr (composition.single_length hn) (λ j hj1 hj2, _),
simp [apply_composition_single] },
simp [formal_multilinear_series.comp, A, finset.sum_union B, C],
end
lemma comp_right_inv_aux2
(p : formal_multilinear_series 𝕜 E F) (i : E ≃L[𝕜] F) (n : ℕ) (v : fin (n + 2) → F) :
∑ (c : composition (n + 2)) in {c : composition (n + 2) | 1 < c.length}.to_finset,
p c.length (apply_composition (λ (k : ℕ), ite (k < n + 2) (p.right_inv i k) 0) c v) =
∑ (c : composition (n + 2)) in {c : composition (n + 2) | 1 < c.length}.to_finset,
p c.length ((p.right_inv i).apply_composition c v) :=
begin
have N : 0 < n + 2, by dec_trivial,
refine sum_congr rfl (λ c hc, p.congr rfl (λ j hj1 hj2, _)),
have : ∀ k, c.blocks_fun k < n + 2,
{ simp only [set.mem_to_finset, set.mem_set_of_eq] at hc,
simp [← composition.ne_single_iff N, composition.eq_single_iff_length, ne_of_gt hc] },
simp [apply_composition, this],
end
/-- The right inverse to a formal multilinear series is indeed a right inverse, provided its linear
term is invertible and its constant term vanishes. -/
lemma comp_right_inv (p : formal_multilinear_series 𝕜 E F) (i : E ≃L[𝕜] F)
(h : p 1 = (continuous_multilinear_curry_fin1 𝕜 E F).symm i) (h0 : p 0 = 0) :
p.comp (right_inv p i) = id 𝕜 F :=
begin
ext n v,
cases n,
{ simp only [h0, continuous_multilinear_map.zero_apply, id_apply_ne_one, ne.def, not_false_iff,
zero_ne_one, comp_coeff_zero']},
cases n,
{ simp only [comp_coeff_one, h, right_inv, continuous_linear_equiv.apply_symm_apply, id_apply_one,
continuous_linear_equiv.coe_apply, continuous_multilinear_curry_fin1_symm_apply] },
have N : 0 < n+2, by dec_trivial,
simp [comp_right_inv_aux1 N, h, right_inv, lt_irrefl n, show n + 2 ≠ 1, by dec_trivial,
← sub_eq_add_neg, sub_eq_zero, comp_right_inv_aux2],
end
lemma right_inv_coeff (p : formal_multilinear_series 𝕜 E F) (i : E ≃L[𝕜] F) (n : ℕ) (hn : 2 ≤ n) :
p.right_inv i n = - (i.symm : F →L[𝕜] E).comp_continuous_multilinear_map
(∑ c in ({c | 1 < composition.length c}.to_finset : finset (composition n)),
p.comp_along_composition (p.right_inv i) c) :=
begin
cases n, { exact false.elim (zero_lt_two.not_le hn) },
cases n, { exact false.elim (one_lt_two.not_le hn) },
simp only [right_inv, neg_inj],
congr' 1,
ext v,
have N : 0 < n + 2, by dec_trivial,
have : (p 1) (λ (i : fin 1), 0) = 0 := continuous_multilinear_map.map_zero _,
simp [comp_right_inv_aux1 N, lt_irrefl n, this, comp_right_inv_aux2]
end
/-! ### Coincidence of the left and the right inverse -/
private lemma left_inv_eq_right_inv_aux (p : formal_multilinear_series 𝕜 E F) (i : E ≃L[𝕜] F)
(h : p 1 = (continuous_multilinear_curry_fin1 𝕜 E F).symm i) (h0 : p 0 = 0) :
left_inv p i = right_inv p i := calc
left_inv p i = (left_inv p i).comp (id 𝕜 F) : by simp
... = (left_inv p i).comp (p.comp (right_inv p i)) : by rw comp_right_inv p i h h0
... = ((left_inv p i).comp p).comp (right_inv p i) : by rw comp_assoc
... = (id 𝕜 E).comp (right_inv p i) : by rw left_inv_comp p i h
... = right_inv p i : by simp
/-- The left inverse and the right inverse of a formal multilinear series coincide. This is not at
all obvious from their definition, but it follows from uniqueness of inverses (which comes from the
fact that composition is associative on formal multilinear series). -/
theorem left_inv_eq_right_inv (p : formal_multilinear_series 𝕜 E F) (i : E ≃L[𝕜] F)
(h : p 1 = (continuous_multilinear_curry_fin1 𝕜 E F).symm i) :
left_inv p i = right_inv p i := calc
left_inv p i = left_inv p.remove_zero i : by rw left_inv_remove_zero
... = right_inv p.remove_zero i : by { apply left_inv_eq_right_inv_aux; simp [h] }
... = right_inv p i : by rw right_inv_remove_zero
/-!
### Convergence of the inverse of a power series
Assume that `p` is a convergent multilinear series, and let `q` be its (left or right) inverse.
Using the left-inverse formula gives
$$
q_n = - (p_1)^{-n} \sum_{k=0}^{n-1} \sum_{i_1 + \dotsc + i_k = n} q_k (p_{i_1}, \dotsc, p_{i_k}).
$$
Assume for simplicity that we are in dimension `1` and `p₁ = 1`. In the formula for `qₙ`, the term
`q_{n-1}` appears with a multiplicity of `n-1` (choosing the index `i_j` for which `i_j = 2` while
all the other indices are equal to `1`), which indicates that `qₙ` might grow like `n!`. This is
bad for summability properties.
It turns out that the right-inverse formula is better behaved, and should instead be used for this
kind of estimate. It reads
$$
q_n = - (p_1)^{-1} \sum_{k=2}^n \sum_{i_1 + \dotsc + i_k = n} p_k (q_{i_1}, \dotsc, q_{i_k}).
$$
Here, `q_{n-1}` can only appear in the term with `k = 2`, and it only appears twice, so there is
hope this formula can lead to an at most geometric behavior.
Let `Qₙ = ‖qₙ‖`. Bounding `‖pₖ‖` with `C r^k` gives an inequality
$$
Q_n ≤ C' \sum_{k=2}^n r^k \sum_{i_1 + \dotsc + i_k = n} Q_{i_1} \dotsm Q_{i_k}.
$$
This formula is not enough to prove by naive induction on `n` a bound of the form `Qₙ ≤ D R^n`.
However, assuming that the inequality above were an equality, one could get a formula for the
generating series of the `Qₙ`:
$$
\begin{align}
Q(z) & := \sum Q_n z^n = Q_1 z + C' \sum_{2 \leq k \leq n} \sum_{i_1 + \dotsc + i_k = n}
(r z^{i_1} Q_{i_1}) \dotsm (r z^{i_k} Q_{i_k})
\\ & = Q_1 z + C' \sum_{k = 2}^\infty (\sum_{i_1 \geq 1} r z^{i_1} Q_{i_1})
\dotsm (\sum_{i_k \geq 1} r z^{i_k} Q_{i_k})
\\ & = Q_1 z + C' \sum_{k = 2}^\infty (r Q(z))^k
= Q_1 z + C' (r Q(z))^2 / (1 - r Q(z)).
\end{align}
$$
One can solve this formula explicitly. The solution is analytic in a neighborhood of `0` in `ℂ`,
hence its coefficients grow at most geometrically (by a contour integral argument), and therefore
the original `Qₙ`, which are bounded by these ones, are also at most geometric.
This classical argument is not really satisfactory, as it requires an a priori bound on a complex
analytic function. Another option would be to compute explicitly its terms (with binomial
coefficients) to obtain an explicit geometric bound, but this would be very painful.
Instead, we will use the above intuition, but in a slightly different form, with finite sums and an
induction. I learnt this trick in [pöschel2017siegelsternberg]. Let
$S_n = \sum_{k=1}^n Q_k a^k$ (where `a` is a positive real parameter to be chosen suitably small).
The above computation but with finite sums shows that
$$
S_n \leq Q_1 a + C' \sum_{k=2}^n (r S_{n-1})^k.
$$
In particular, $S_n \leq Q_1 a + C' (r S_{n-1})^2 / (1- r S_{n-1})$.
Assume that $S_{n-1} \leq K a$, where `K > Q₁` is fixed and `a` is small enough so that
`r K a ≤ 1/2` (to control the denominator). Then this equation gives a bound
$S_n \leq Q_1 a + 2 C' r^2 K^2 a^2$.
If `a` is small enough, this is bounded by `K a` as the second term is quadratic in `a`, and
therefore negligible.
By induction, we deduce `Sₙ ≤ K a` for all `n`, which gives in particular the fact that `aⁿ Qₙ`
remains bounded.
-/
/-- First technical lemma to control the growth of coefficients of the inverse. Bound the explicit
expression for `∑_{k<n+1} aᵏ Qₖ` in terms of a sum of powers of the same sum one step before,
in a general abstract setup. -/
lemma radius_right_inv_pos_of_radius_pos_aux1
(n : ℕ) (p : ℕ → ℝ) (hp : ∀ k, 0 ≤ p k) {r a : ℝ} (hr : 0 ≤ r) (ha : 0 ≤ a) :
∑ k in Ico 2 (n + 1), a ^ k *
(∑ c in ({c | 1 < composition.length c}.to_finset : finset (composition k)),
r ^ c.length * ∏ j, p (c.blocks_fun j))
≤ ∑ j in Ico 2 (n + 1), r ^ j * (∑ k in Ico 1 n, a ^ k * p k) ^ j :=
calc
∑ k in Ico 2 (n + 1), a ^ k *
(∑ c in ({c | 1 < composition.length c}.to_finset : finset (composition k)),
r ^ c.length * ∏ j, p (c.blocks_fun j))
= ∑ k in Ico 2 (n + 1),
(∑ c in ({c | 1 < composition.length c}.to_finset : finset (composition k)),
∏ j, r * (a ^ (c.blocks_fun j) * p (c.blocks_fun j))) :
begin
simp_rw [mul_sum],
apply sum_congr rfl (λ k hk, _),
apply sum_congr rfl (λ c hc, _),
rw [prod_mul_distrib, prod_mul_distrib, prod_pow_eq_pow_sum, composition.sum_blocks_fun,
prod_const, card_fin],
ring,
end
... ≤ ∑ d in comp_partial_sum_target 2 (n + 1) n,
∏ (j : fin d.2.length), r * (a ^ d.2.blocks_fun j * p (d.2.blocks_fun j)) :
begin
rw sum_sigma',
refine sum_le_sum_of_subset_of_nonneg _ (λ x hx1 hx2,
prod_nonneg (λ j hj, mul_nonneg hr (mul_nonneg (pow_nonneg ha _) (hp _)))),
rintros ⟨k, c⟩ hd,
simp only [set.mem_to_finset, mem_Ico, mem_sigma, set.mem_set_of_eq] at hd,
simp only [mem_comp_partial_sum_target_iff],
refine ⟨hd.2, c.length_le.trans_lt hd.1.2, λ j, _⟩,
have : c ≠ composition.single k (zero_lt_two.trans_le hd.1.1),
by simp [composition.eq_single_iff_length, ne_of_gt hd.2],
rw composition.ne_single_iff at this,
exact (this j).trans_le (nat.lt_succ_iff.mp hd.1.2)
end
... = ∑ e in comp_partial_sum_source 2 (n+1) n, ∏ (j : fin e.1), r * (a ^ e.2 j * p (e.2 j)) :
begin
symmetry,
apply comp_change_of_variables_sum,
rintros ⟨k, blocks_fun⟩ H,
have K : (comp_change_of_variables 2 (n + 1) n ⟨k, blocks_fun⟩ H).snd.length = k, by simp,
congr' 2; try { rw K },
rw fin.heq_fun_iff K.symm,
assume j,
rw comp_change_of_variables_blocks_fun,
end
... = ∑ j in Ico 2 (n+1), r ^ j * (∑ k in Ico 1 n, a ^ k * p k) ^ j :
begin
rw [comp_partial_sum_source, ← sum_sigma' (Ico 2 (n + 1))
(λ (k : ℕ), (fintype.pi_finset (λ (i : fin k), Ico 1 n) : finset (fin k → ℕ)))
(λ n e, ∏ (j : fin n), r * (a ^ e j * p (e j)))],
apply sum_congr rfl (λ j hj, _),
simp only [← @multilinear_map.mk_pi_algebra_apply ℝ (fin j) _ _ ℝ],
simp only [← multilinear_map.map_sum_finset (multilinear_map.mk_pi_algebra ℝ (fin j) ℝ)
(λ k (m : ℕ), r * (a ^ m * p m))],
simp only [multilinear_map.mk_pi_algebra_apply],
dsimp,
simp [prod_const, ← mul_sum, mul_pow],
end
/-- Second technical lemma to control the growth of coefficients of the inverse. Bound the explicit
expression for `∑_{k<n+1} aᵏ Qₖ` in terms of a sum of powers of the same sum one step before,
in the specific setup we are interesting in, by reducing to the general bound in
`radius_right_inv_pos_of_radius_pos_aux1`. -/
lemma radius_right_inv_pos_of_radius_pos_aux2
{n : ℕ} (hn : 2 ≤ n + 1) (p : formal_multilinear_series 𝕜 E F) (i : E ≃L[𝕜] F)
{r a C : ℝ} (hr : 0 ≤ r) (ha : 0 ≤ a) (hC : 0 ≤ C) (hp : ∀ n, ‖p n‖ ≤ C * r ^ n) :
(∑ k in Ico 1 (n + 1), a ^ k * ‖p.right_inv i k‖) ≤
‖(i.symm : F →L[𝕜] E)‖ * a + ‖(i.symm : F →L[𝕜] E)‖ * C * ∑ k in Ico 2 (n + 1),
(r * ((∑ j in Ico 1 n, a ^ j * ‖p.right_inv i j‖))) ^ k :=
let I := ‖(i.symm : F →L[𝕜] E)‖ in calc
∑ k in Ico 1 (n + 1), a ^ k * ‖p.right_inv i k‖
= a * I + ∑ k in Ico 2 (n + 1), a ^ k * ‖p.right_inv i k‖ :
by simp only [linear_isometry_equiv.norm_map, pow_one, right_inv_coeff_one,
nat.Ico_succ_singleton, sum_singleton, ← sum_Ico_consecutive _ one_le_two hn]
... = a * I + ∑ k in Ico 2 (n + 1), a ^ k *
‖(i.symm : F →L[𝕜] E).comp_continuous_multilinear_map
(∑ c in ({c | 1 < composition.length c}.to_finset : finset (composition k)),
p.comp_along_composition (p.right_inv i) c)‖ :
begin
congr' 1,
apply sum_congr rfl (λ j hj, _),
rw [right_inv_coeff _ _ _ (mem_Ico.1 hj).1, norm_neg],
end
... ≤ a * ‖(i.symm : F →L[𝕜] E)‖ + ∑ k in Ico 2 (n + 1), a ^ k * (I *
(∑ c in ({c | 1 < composition.length c}.to_finset : finset (composition k)),
C * r ^ c.length * ∏ j, ‖p.right_inv i (c.blocks_fun j)‖)) :
begin
apply_rules [add_le_add, le_refl, sum_le_sum (λ j hj, _), mul_le_mul_of_nonneg_left,
pow_nonneg, ha],
apply (continuous_linear_map.norm_comp_continuous_multilinear_map_le _ _).trans,
apply mul_le_mul_of_nonneg_left _ (norm_nonneg _),
apply (norm_sum_le _ _).trans,
apply sum_le_sum (λ c hc, _),
apply (comp_along_composition_norm _ _ _).trans,
apply mul_le_mul_of_nonneg_right (hp _),
exact prod_nonneg (λ j hj, norm_nonneg _),
end
... = I * a + I * C * ∑ k in Ico 2 (n + 1), a ^ k *
(∑ c in ({c | 1 < composition.length c}.to_finset : finset (composition k)),
r ^ c.length * ∏ j, ‖p.right_inv i (c.blocks_fun j)‖) :
begin
simp_rw [mul_assoc C, ← mul_sum, ← mul_assoc, mul_comm _ (‖↑i.symm‖), mul_assoc, ← mul_sum,
← mul_assoc, mul_comm _ C, mul_assoc, ← mul_sum],
ring,
end
... ≤ I * a + I * C * ∑ k in Ico 2 (n+1), (r * ((∑ j in Ico 1 n, a ^ j * ‖p.right_inv i j‖))) ^ k :
begin
apply_rules [add_le_add, le_refl, mul_le_mul_of_nonneg_left, norm_nonneg, hC, mul_nonneg],
simp_rw [mul_pow],
apply radius_right_inv_pos_of_radius_pos_aux1 n (λ k, ‖p.right_inv i k‖)
(λ k, norm_nonneg _) hr ha,
end
/-- If a a formal multilinear series has a positive radius of convergence, then its right inverse
also has a positive radius of convergence. -/
theorem radius_right_inv_pos_of_radius_pos (p : formal_multilinear_series 𝕜 E F) (i : E ≃L[𝕜] F)
(hp : 0 < p.radius) : 0 < (p.right_inv i).radius :=
begin
obtain ⟨C, r, Cpos, rpos, ple⟩ : ∃ C r (hC : 0 < C) (hr : 0 < r), ∀ (n : ℕ), ‖p n‖ ≤ C * r ^ n :=
le_mul_pow_of_radius_pos p hp,
let I := ‖(i.symm : F →L[𝕜] E)‖,
-- choose `a` small enough to make sure that `∑_{k ≤ n} aᵏ Qₖ` will be controllable by
-- induction
obtain ⟨a, apos, ha1, ha2⟩ : ∃ a (apos : 0 < a),
(2 * I * C * r^2 * (I + 1) ^ 2 * a ≤ 1) ∧ (r * (I + 1) * a ≤ 1/2),
{ have : tendsto (λ a, 2 * I * C * r^2 * (I + 1) ^ 2 * a) (𝓝 0)
(𝓝 (2 * I * C * r^2 * (I + 1) ^ 2 * 0)) := tendsto_const_nhds.mul tendsto_id,
have A : ∀ᶠ a in 𝓝 0, 2 * I * C * r^2 * (I + 1) ^ 2 * a < 1,
by { apply (tendsto_order.1 this).2, simp [zero_lt_one] },
have : tendsto (λ a, r * (I + 1) * a) (𝓝 0)
(𝓝 (r * (I + 1) * 0)) := tendsto_const_nhds.mul tendsto_id,
have B : ∀ᶠ a in 𝓝 0, r * (I + 1) * a < 1/2,
by { apply (tendsto_order.1 this).2, simp [zero_lt_one] },
have C : ∀ᶠ a in 𝓝[>] (0 : ℝ), (0 : ℝ) < a,
by { filter_upwards [self_mem_nhds_within] with _ ha using ha },
rcases (C.and ((A.and B).filter_mono inf_le_left)).exists with ⟨a, ha⟩,
exact ⟨a, ha.1, ha.2.1.le, ha.2.2.le⟩ },
-- check by induction that the partial sums are suitably bounded, using the choice of `a` and the
-- inductive control from Lemma `radius_right_inv_pos_of_radius_pos_aux2`.
let S := λ n, ∑ k in Ico 1 n, a ^ k * ‖p.right_inv i k‖,
have IRec : ∀ n, 1 ≤ n → S n ≤ (I + 1) * a,
{ apply nat.le_induction,
{ simp only [S],
rw [Ico_eq_empty_of_le (le_refl 1), sum_empty],
exact mul_nonneg (add_nonneg (norm_nonneg _) zero_le_one) apos.le },
{ assume n one_le_n hn,
have In : 2 ≤ n + 1, by linarith,
have Snonneg : 0 ≤ S n :=
sum_nonneg (λ x hx, mul_nonneg (pow_nonneg apos.le _) (norm_nonneg _)),
have rSn : r * S n ≤ 1/2 := calc
r * S n ≤ r * ((I+1) * a) : mul_le_mul_of_nonneg_left hn rpos.le
... ≤ 1/2 : by rwa [← mul_assoc],
calc S (n + 1) ≤ I * a + I * C * ∑ k in Ico 2 (n + 1), (r * S n)^k :
radius_right_inv_pos_of_radius_pos_aux2 In p i rpos.le apos.le Cpos.le ple
... = I * a + I * C * (((r * S n) ^ 2 - (r * S n) ^ (n + 1)) / (1 - r * S n)) :
by { rw geom_sum_Ico' _ In, exact ne_of_lt (rSn.trans_lt (by norm_num)) }
... ≤ I * a + I * C * ((r * S n) ^ 2 / (1/2)) :
begin
apply_rules [add_le_add, le_refl, mul_le_mul_of_nonneg_left, mul_nonneg, norm_nonneg,
Cpos.le],
refine div_le_div (sq_nonneg _) _ (by norm_num) (by linarith),
simp only [sub_le_self_iff],
apply pow_nonneg (mul_nonneg rpos.le Snonneg),
end
... = I * a + 2 * I * C * (r * S n) ^ 2 : by ring
... ≤ I * a + 2 * I * C * (r * ((I + 1) * a)) ^ 2 :
by apply_rules [add_le_add, le_refl, mul_le_mul_of_nonneg_left, mul_nonneg, norm_nonneg,
Cpos.le, zero_le_two, pow_le_pow_of_le_left, rpos.le]
... = (I + 2 * I * C * r^2 * (I + 1) ^ 2 * a) * a : by ring
... ≤ (I + 1) * a :
by apply_rules [mul_le_mul_of_nonneg_right, apos.le, add_le_add, le_refl] } },
-- conclude that all coefficients satisfy `aⁿ Qₙ ≤ (I + 1) a`.
let a' : nnreal := ⟨a, apos.le⟩,
suffices H : (a' : ennreal) ≤ (p.right_inv i).radius,
by { apply lt_of_lt_of_le _ H, exact_mod_cast apos },
apply le_radius_of_bound _ ((I + 1) * a) (λ n, _),
by_cases hn : n = 0,
{ have : ‖p.right_inv i n‖ = ‖p.right_inv i 0‖, by congr; try { rw hn },
simp only [this, norm_zero, zero_mul, right_inv_coeff_zero],
apply_rules [mul_nonneg, add_nonneg, norm_nonneg, zero_le_one, apos.le] },
{ have one_le_n : 1 ≤ n := bot_lt_iff_ne_bot.2 hn,
calc ‖p.right_inv i n‖ * ↑a' ^ n = a ^ n * ‖p.right_inv i n‖ : mul_comm _ _
... ≤ ∑ k in Ico 1 (n + 1), a ^ k * ‖p.right_inv i k‖ :
begin
have : ∀ k ∈ Ico 1 (n + 1), 0 ≤ a ^ k * ‖p.right_inv i k‖ :=
λ k hk, mul_nonneg (pow_nonneg apos.le _) (norm_nonneg _),
exact single_le_sum this (by simp [one_le_n]),
end
... ≤ (I + 1) * a : IRec (n + 1) (by dec_trivial) }
end
end formal_multilinear_series
|
8609d80d28c0cb0ec128bcc1439ea0e6fe62d492
|
432d948a4d3d242fdfb44b81c9e1b1baacd58617
|
/src/tactic/aesop/default.lean
|
930f687b7fb4d579929ddf4dad16d77f1d535418
|
[
"Apache-2.0"
] |
permissive
|
JLimperg/aesop3
|
306cc6570c556568897ed2e508c8869667252e8a
|
a4a116f650cc7403428e72bd2e2c4cda300fe03f
|
refs/heads/master
| 1,682,884,916,368
| 1,620,320,033,000
| 1,620,320,033,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 436
|
lean
|
/-
Copyright (c) 2021 Jannis Limperg. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jannis Limperg
-/
import tactic.aesop.search
/-!
# Aesop, a general-purpose proof search tactic
-/
namespace tactic
export aesop (aesop)
namespace interactive
open interactive (parse)
meta def aesop : parse aesop.config.parser → tactic unit :=
tactic.aesop.aesop
end interactive
end tactic
|
d8be4faa7ad448694fea535b390e17ee96645ef0
|
36c7a18fd72e5b57229bd8ba36493daf536a19ce
|
/tests/lean/run/blast_simp1.lean
|
cb290d523fd1fdc8c9ecee7599c20f893aca00db
|
[
"Apache-2.0"
] |
permissive
|
YHVHvx/lean
|
732bf0fb7a298cd7fe0f15d82f8e248c11db49e9
|
038369533e0136dd395dc252084d3c1853accbf2
|
refs/heads/master
| 1,610,701,080,210
| 1,449,128,595,000
| 1,449,128,595,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 416
|
lean
|
example (a b c : Prop) : a ∧ b ∧ c ↔ c ∧ b ∧ a :=
by blast
example (a b c : Prop) : a ∧ false ∧ c ↔ false :=
by blast
example (a b c : Prop) : a ∨ false ∨ b ↔ b ∨ a :=
by blast
example (a b c : Prop) : ¬ true ∨ false ∨ b ↔ b :=
by blast
example (a b c : Prop) : if true then a else b ↔ if false then b else a :=
by blast
example (a b : Prop) : a ∧ not a ↔ false :=
by blast
|
a38b1de91cec37a315cc3d957f669332bf27015e
|
4f065978c49388d188224610d9984673079f7d91
|
/zorn.lean
|
988ae425d3e5e108f7e0b4fad4672e4e40160474
|
[] |
no_license
|
kckennylau/Lean
|
b323103f52706304907adcfaee6f5cb8095d4a33
|
907d0a4d2bd8f23785abd6142ad53d308c54fdcb
|
refs/heads/master
| 1,624,623,720,653
| 1,563,901,820,000
| 1,563,901,820,000
| 109,506,702
| 3
| 1
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 8,343
|
lean
|
-- https://proofwiki.org/wiki/Axiom_of_Choice_Implies_Zorn%27s_Lemma/Proof_1
universe u
instance set.partial_order {α} : partial_order (set α) :=
{ le := (⊆),
le_refl := λ A z, id,
le_trans := λ A B C hab hbc z hz, hbc (hab hz),
le_antisymm := λ A B hab hba, funext $ λ z, propext ⟨@hab z, @hba z⟩ }
local attribute [instance] classical.prop_decidable
namespace zorn
variables {α : Type u} (r : α → α → Prop)
inductive trichotomy (A B) : Prop
| inl (H : r A B) : trichotomy
| eq (H : A = B) : trichotomy
| inr (H : r B A) : trichotomy
theorem trichotomy.symm {r : α → α → Prop} {A B}
(H : trichotomy r A B) :
trichotomy r B A :=
trichotomy.cases_on H trichotomy.inr (λ H, trichotomy.eq r H.symm) trichotomy.inl
def chains : set (set α) :=
{ C | ∀ A ∈ C, ∀ B ∈ C, trichotomy r A B }
theorem chains.empty : ∅ ∈ chains r :=
λ _, false.elim
theorem chains.insert {C x} (H1 : C ∈ chains r) (H2 : ∀ y ∈ C, trichotomy r x y) :
insert x C ∈ chains r :=
λ A HA B HB, or.cases_on HA
(assume HA : A = x, or.cases_on HB
(assume HB : B = x, trichotomy.eq r $ HA.trans HB.symm)
(assume HB : B ∈ C, HA.symm ▸ H2 B HB))
(assume HA : A ∈ C, or.cases_on HB
(assume HB : B = x, trichotomy.symm $ HB.symm ▸ H2 A HA)
(assume HB : B ∈ C, H1 A HA B HB))
theorem chains.union {C} (H1 : C ⊆ chains r) (H2 : C ∈ @chains (set α) (⊆)) :
{ A | ∃ t ∈ C, A ∈ t } ∈ chains r :=
λ A ⟨t, ht1, ht2⟩ B ⟨u, hu1, hu2⟩, trichotomy.cases_on (H2 t ht1 u hu1)
(λ H3, (H1 hu1) _ (H3 ht2) _ hu2)
(λ H3, (H1 ht1) A ht2 B (H3.symm ▸ hu2))
(λ H3, (H1 ht1) _ ht2 _ (H3 hu2))
def extensions (A) : set α :=
{ x | insert x A ∈ chains r }
noncomputable def succ (A : set α) : set α :=
if H : ∃ x, x ∈ extensions r A \ A then insert (classical.some H) A else A
@[elab_as_eliminator] noncomputable def succ.rec {C : set α → set α → Sort*}
(H1 : ∀ A, ∀ x ∈ extensions r A \ A, C A (insert x A))
(H2 : ∀ A, extensions r A ⊆ A → C A A)
(A : set α) : C A (succ r A) :=
if H : ∃ x, x ∈ extensions r A \ A then
have succ r A = insert (classical.some H) A, from dif_pos H,
eq.drec_on this.symm $ H1 _ (classical.some H) (classical.some_spec H)
else
have succ r A = A, from dif_neg H,
eq.drec_on this.symm $ H2 A $ λ z hz1,
classical.by_contradiction $ λ hz2, H ⟨z, hz1, hz2⟩
@[elab_as_eliminator] noncomputable def succ.rec_on {C : set α → set α → Sort*}
(A : set α)
(H1 : ∀ A, ∀ x ∈ extensions r A \ A, C A (insert x A))
(H2 : ∀ A, extensions r A ⊆ A → C A A) :
C A (succ r A) :=
succ.rec r H1 H2 A
theorem succ.mem (A : set α) (x) (H1 : insert x A ∈ chains r) (H2 : x ∉ A) :
∃ x, x ∈ extensions r A ∧ x ∉ A ∧ succ r A = insert x A :=
have H : ∃ x, x ∈ extensions r A \ A := ⟨x, H1, H2⟩,
⟨_, and.assoc.1 ⟨classical.some_spec H, dif_pos H⟩⟩
theorem succ.cases (A : set α) :
(∃ x, x ∉ A ∧ x ∈ extensions r A ∧ succ r A = insert x A) ∨ succ r A = A :=
@succ.rec_on α _ (λ t u, (∃ x, x ∉ t ∧ x ∈ extensions r t ∧ u = insert x t) ∨ u = t) A
(λ A x hx, or.inl ⟨x, hx.2, hx.1, rfl⟩) (λ _ _, or.inr rfl)
theorem succ.subset {A : set α} : A ⊆ succ r A :=
succ.rec_on r A
(λ t A H, show t ⊆ insert A t, from λ z, or.inr)
(λ t H z, id)
theorem chains.succ {A : set α} : A ∈ chains r → succ r A ∈ chains r :=
@succ.rec_on α _ (λ t u, t ∈ chains r → u ∈ chains r) A
(λ t X HX H, HX.1) (λ _ _, id)
theorem succ.eq_or_eq_of_subset_of_subset (A : set α) :
∀ B, A ⊆ B → B ⊆ succ r A → A = B ∨ B = succ r A :=
@succ.rec_on α _ (λ t u, ∀ B, t ⊆ B → B ⊆ u → t = B ∨ B = u) A
(λ A x hx B HAB HBA, classical.by_cases
(assume h : x ∈ B, or.inr $ le_antisymm HBA $ λ z hz, or.cases_on hz
(λ hz1, hz1.symm ▸ h) (@HAB z))
(assume h : x ∉ B, or.inl $ le_antisymm HAB $ λ z hz, or.cases_on (HBA hz)
(λ hz1, false.elim $ h $ hz1 ▸ hz) id))
(λ _ _ _ HBC HCB, or.inl $ le_antisymm HBC HCB)
inductive tower : set (set α)
| succ : ∀ {A}, tower A → tower (succ r A)
| chain : ∀ {C}, C ⊆ chains r → C ∈ @chains (set α) (⊆) →
(∀ A ∈ C, tower A) → tower { A | ∃ t ∈ C, A ∈ t }
theorem tower.empty : ∅ ∈ tower r :=
have H : { A | ∃ t ∈ (∅ : set (set α)), A ∈ t } = ∅,
from le_antisymm (λ _ ⟨_, H, _⟩, H) (λ _, false.elim),
H ▸ tower.chain (λ _, false.elim) (λ _, false.elim) (λ _, false.elim)
theorem tower.subset_chains : tower r ⊆ chains r :=
λ A HA, tower.rec_on HA
(λ A HA, chains.succ r)
(λ C HC1 HC2 HC3 ih, chains.union r HC1 HC2)
/-- TLDR: proof by heavy induction -/
theorem tower.chains : tower r ∈ @chains (set α) (⊆) :=
λ A HA, tower.rec_on HA
(λ C HC ih1 A HA, suffices A ⊆ C ∨ succ r C ⊆ A,
from or.cases_on this (λ h, trichotomy.inr $ λ z hz, succ.subset r $ h hz) trichotomy.inl,
tower.rec_on HA
(λ A HA ih2, or.cases_on ih2
(assume h1 : A ⊆ C, trichotomy.cases_on (ih1 (succ r A) (tower.succ HA))
(assume h2 : C ⊆ succ r A, or.cases_on (succ.eq_or_eq_of_subset_of_subset r A C h1 h2)
(assume h3 : A = C, or.inr $ λ _, h3 ▸ id)
(assume h3 : C = succ r A, or.inl $ λ _, h3 ▸ id))
(assume h2 : C = succ r A, or.inl $ λ _, h2 ▸ id)
or.inl)
(assume h1 : succ r C ⊆ A, or.inr $ λ z hz, succ.subset r $ h1 hz))
(λ D HD1 HD2 HD3 ih2, trichotomy.cases_on (ih1 _ (tower.chain HD1 HD2 HD3))
(λ h1, have H1 : C ⊆ {A : α | ∃ (t : set α) (H : t ∈ D), A ∈ t} ∩ succ r C,
from λ z hz, ⟨h1 hz, succ.subset r hz⟩,
have H2 : {A : α | ∃ (t : set α) (H : t ∈ D), A ∈ t} ∩ succ r C ⊆ succ r C,
from λ _, and.right,
or.cases_on (succ.eq_or_eq_of_subset_of_subset r _ _ H1 H2)
(λ h2, or.cases_on (succ.cases r C)
(λ ⟨x, hx1, hx2, hx3⟩, or.inl $ λ z ⟨t, ht1, ht2⟩,
or.cases_on (ih2 t ht1) (λ h3, h3 ht2)
(λ h3, have H3 : x ∈ succ r C, from hx3.symm ▸ or.inl rfl,
false.elim $ hx1 $ h2.symm ▸ ⟨⟨t, ht1, h3 H3⟩, H3⟩))
(λ h3, h3.symm ▸ or.inr h1))
(λ h2, or.inr $ h2 ▸ λ _, and.left))
(λ h1, or.inl $ λ _, h1 ▸ id)
or.inl))
(λ C HC1 HC2 HC3 ih B HB, classical.by_cases
(assume h : ∃ A ∈ C, B ⊆ A, let ⟨A, HA1, HA2⟩ := h in
trichotomy.inr $ λ z hz, ⟨A, HA1, HA2 hz⟩)
(assume h : ¬∃ A ∈ C, B ⊆ A, trichotomy.inl $ λ z ⟨t, ht1, ht2⟩,
trichotomy.cases_on (ih t ht1 B HB)
(assume H : t ⊆ B, H ht2)
(assume H : t = B, H ▸ ht2)
(assume H : B ⊆ t, false.elim $ h ⟨t, ht1, H⟩)))
def fixed : set α :=
{A : α | ∃ t ∈ tower r, A ∈ t}
theorem fixed.tower : fixed r ∈ tower r :=
tower.chain (tower.subset_chains r) (tower.chains r) (λ A, id)
theorem fixed.succ_tower : succ r (fixed r) ∈ tower r :=
tower.succ (fixed.tower r)
theorem fixed.fixed : succ r (fixed r) = fixed r :=
le_antisymm (λ z hz, ⟨succ r (fixed r), fixed.succ_tower r, hz⟩) $
λ z hz, succ.subset r hz
theorem fixed.chains : fixed r ∈ chains r :=
chains.union r (tower.subset_chains r) (tower.chains r)
theorem zorn.aux {M} (HM : ∀ x ∈ fixed r, r x M)
(trans : ∀ {a b c}, r a b → r b c → r a c) :
∀ A, r M A → r A M :=
λ A HA, HM A (classical.by_contradiction $ λ H,
let ⟨y, hy1, hy2, hy3⟩ := succ.mem r (fixed r) A
(chains.insert r (fixed.chains r) $ λ y hy,
trichotomy.inr $ trans (HM y hy) HA) H in
hy2 $ (fixed.fixed r) ▸ hy3.symm ▸ or.inl rfl)
theorem zorn [HN : nonempty α] [partial_order α]
(H : ∀ C ∈ @chains α (≤), ∀ y ∈ C, ∃ M, ∀ x ∈ C, x ≤ M) :
∃ M : α, ∀ A, M ≤ A → M = A :=
nonempty.elim HN $ λ X,
let ⟨x, hx1, hx2, hx3⟩ := succ.mem (≤) ∅ X
(chains.insert (≤) (chains.empty (≤)) (λ _, false.elim)) id in
let ⟨M, HM⟩ := H (fixed (≤)) (fixed.chains (≤)) x
⟨insert x ∅, hx3 ▸ tower.succ (tower.empty (≤)), or.inl rfl⟩ in
⟨M, λ A HA, le_antisymm HA $
zorn.aux (≤) HM (λ _ _ _, le_trans) A HA⟩
end zorn
|
10cdad3babf399d27be4b3909cd7b8b0584a5531
|
92b50235facfbc08dfe7f334827d47281471333b
|
/library/algebra/field.lean
|
64a130ca5ae0b8e23b828b34bcfe1ef1d7d7da35
|
[
"Apache-2.0"
] |
permissive
|
htzh/lean
|
24f6ed7510ab637379ec31af406d12584d31792c
|
d70c79f4e30aafecdfc4a60b5d3512199200ab6e
|
refs/heads/master
| 1,607,677,731,270
| 1,437,089,952,000
| 1,437,089,952,000
| 37,078,816
| 0
| 0
| null | 1,433,780,956,000
| 1,433,780,955,000
| null |
UTF-8
|
Lean
| false
| false
| 18,926
|
lean
|
/-
Copyright (c) 2014 Robert Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Lewis
Structures with multiplicative and additive components, including division rings and fields.
The development is modeled after Isabelle's library.
-/
----------------------------------------------------------------------------------------------------
import logic.eq logic.connectives data.unit data.sigma data.prod
import algebra.binary algebra.group algebra.ring
open eq eq.ops
namespace algebra
variable {A : Type}
-- in division rings, 1 / 0 = 0
structure division_ring [class] (A : Type) extends ring A, has_inv A, zero_ne_one_class A :=
(mul_inv_cancel : ∀{a}, a ≠ zero → mul a (inv a) = one)
(inv_mul_cancel : ∀{a}, a ≠ zero → mul (inv a) a = one)
--(inv_zero : inv zero = zero)
section division_ring
variables [s : division_ring A] {a b c : A}
include s
definition divide (a b : A) : A := a * b⁻¹
infix [priority algebra.prio] `/` := divide
-- only in this file
local attribute divide [reducible]
theorem mul_inv_cancel (H : a ≠ 0) : a * a⁻¹ = 1 :=
division_ring.mul_inv_cancel H
theorem inv_mul_cancel (H : a ≠ 0) : a⁻¹ * a = 1 :=
division_ring.inv_mul_cancel H
theorem inv_eq_one_div : a⁻¹ = 1 / a := !one_mul⁻¹
-- the following are only theorems if we assume inv_zero here
/- theorem inv_zero : 0⁻¹ = 0 := !division_ring.inv_zero
theorem one_div_zero : 1 / 0 = 0 :=
calc
1 / 0 = 1 * 0⁻¹ : refl
... = 1 * 0 : division_ring.inv_zero A
... = 0 : mul_zero
-/
theorem div_eq_mul_one_div : a / b = a * (1 / b) :=
by rewrite [↑divide, one_mul]
-- theorem div_zero : a / 0 = 0 := by rewrite [div_eq_mul_one_div, one_div_zero, mul_zero]
theorem mul_one_div_cancel (H : a ≠ 0) : a * (1 / a) = 1 :=
by rewrite [-inv_eq_one_div, (mul_inv_cancel H)]
theorem one_div_mul_cancel (H : a ≠ 0) : (1 / a) * a = 1 :=
by rewrite [-inv_eq_one_div, (inv_mul_cancel H)]
theorem div_self (H : a ≠ 0) : a / a = 1 := mul_inv_cancel H
theorem one_div_one : 1 / 1 = (1:A) := div_self (ne.symm zero_ne_one)
theorem mul_div_assoc : (a * b) / c = a * (b / c) := !mul.assoc
theorem one_div_ne_zero (H : a ≠ 0) : 1 / a ≠ 0 :=
assume H2 : 1 / a = 0,
have C1 : 0 = (1:A), from symm (by rewrite [-(mul_one_div_cancel H), H2, mul_zero]),
absurd C1 zero_ne_one
-- theorem ne_zero_of_one_div_ne_zero (H : 1 / a ≠ 0) : a ≠ 0 :=
-- assume Ha : a = 0, absurd (Ha⁻¹ ▸ one_div_zero) H
theorem one_inv_eq : 1⁻¹ = (1:A) :=
by rewrite [-mul_one, inv_mul_cancel (ne.symm (@zero_ne_one A _))]
theorem div_one : a / 1 = a :=
by rewrite [↑divide, one_inv_eq, mul_one]
theorem zero_div : 0 / a = 0 := !zero_mul
-- note: integral domain has a "mul_ne_zero". Discrete fields are int domains.
theorem mul_ne_zero' (Ha : a ≠ 0) (Hb : b ≠ 0) : a * b ≠ 0 :=
assume H : a * b = 0,
have C1 : a = 0, by rewrite [-mul_one, -(mul_one_div_cancel Hb), -mul.assoc, H, zero_mul],
absurd C1 Ha
theorem mul_ne_zero_comm (H : a * b ≠ 0) : b * a ≠ 0 :=
have H2 : a ≠ 0 ∧ b ≠ 0, from ne_zero_and_ne_zero_of_mul_ne_zero H,
mul_ne_zero' (and.right H2) (and.left H2)
-- make "left" and "right" versions?
theorem eq_one_div_of_mul_eq_one (H : a * b = 1) : b = 1 / a :=
have H2 : a ≠ 0, from
(assume aeq0 : a = 0,
have B : 0 = (1:A), by rewrite [-(zero_mul b), -aeq0, H],
absurd B zero_ne_one),
show b = 1 / a, from symm (calc
1 / a = (1 / a) * 1 : mul_one
... = (1 / a) * (a * b) : H
... = (1 / a) * a * b : mul.assoc
... = 1 * b : one_div_mul_cancel H2
... = b : one_mul)
-- which one is left and which is right?
theorem eq_one_div_of_mul_eq_one_left (H : b * a = 1) : b = 1 / a :=
have H2 : a ≠ 0, from
(assume A : a = 0,
have B : 0 = 1, from symm (calc
1 = b * a : symm H
... = b * 0 : A
... = 0 : mul_zero),
absurd B zero_ne_one),
show b = 1 / a, from symm (calc
1 / a = 1 * (1 / a) : one_mul
... = b * a * (1 / a) : H
... = b * (a * (1 / a)) : mul.assoc
... = b * 1 : mul_one_div_cancel H2
... = b : mul_one)
theorem one_div_mul_one_div (Ha : a ≠ 0) (Hb : b ≠ 0) : (1 / a) * (1 / b) = 1 / (b * a) :=
have H : (b * a) * ((1 / a) * (1 / b)) = 1, by
rewrite [mul.assoc, -(mul.assoc a), (mul_one_div_cancel Ha), one_mul, (mul_one_div_cancel Hb)],
eq_one_div_of_mul_eq_one H
theorem one_div_neg_one_eq_neg_one : (1:A) / (-1) = -1 :=
have H : (-1) * (-1) = (1:A), by rewrite [-neg_eq_neg_one_mul, neg_neg],
symm (eq_one_div_of_mul_eq_one H)
theorem one_div_neg_eq_neg_one_div (H : a ≠ 0) : 1 / (- a) = - (1 / a) :=
have H1 : -1 ≠ 0, from
(assume H2 : -1 = 0, absurd (symm (calc
1 = -(-1) : neg_neg
... = -0 : H2
... = (0:A) : neg_zero)) zero_ne_one),
calc
1 / (- a) = 1 / ((-1) * a) : neg_eq_neg_one_mul
... = (1 / a) * (1 / (- 1)) : one_div_mul_one_div H H1
... = (1 / a) * (-1) : one_div_neg_one_eq_neg_one
... = - (1 / a) : mul_neg_one_eq_neg
theorem div_neg_eq_neg_div (Ha : a ≠ 0) : b / (- a) = - (b / a) :=
calc
b / (- a) = b * (1 / (- a)) : inv_eq_one_div
... = b * -(1 / a) : one_div_neg_eq_neg_one_div Ha
... = -(b * (1 / a)) : neg_mul_eq_mul_neg
... = - (b * a⁻¹) : inv_eq_one_div
theorem neg_div (Ha : a ≠ 0) : (-b) / a = - (b / a) :=
by rewrite [neg_eq_neg_one_mul, mul_div_assoc, -neg_eq_neg_one_mul]
theorem neg_div_neg_eq_div (Hb : b ≠ 0) : (-a) / (-b) = a / b :=
by rewrite [(div_neg_eq_neg_div Hb), (neg_div Hb), neg_neg]
theorem div_div (H : a ≠ 0) : 1 / (1 / a) = a :=
symm (eq_one_div_of_mul_eq_one_left (mul_one_div_cancel H))
theorem eq_of_invs_eq (Ha : a ≠ 0) (Hb : b ≠ 0) (H : 1 / a = 1 / b) : a = b :=
by rewrite [-(div_div Ha), H, (div_div Hb)]
theorem mul_inv_eq (Ha : a ≠ 0) (Hb : b ≠ 0) : (b * a)⁻¹ = a⁻¹ * b⁻¹ :=
have H1 : b * a ≠ 0, from mul_ne_zero' Hb Ha,
eq.symm (calc
a⁻¹ * b⁻¹ = (1 / a) * b⁻¹ : inv_eq_one_div
... = (1 / a) * (1 / b) : inv_eq_one_div
... = (1 / (b * a)) : one_div_mul_one_div Ha Hb
... = (b * a)⁻¹ : inv_eq_one_div)
theorem mul_div_cancel (Hb : b ≠ 0) : a * b / b = a :=
by rewrite [↑divide, mul.assoc, (mul_inv_cancel Hb), mul_one]
theorem div_mul_cancel (Hb : b ≠ 0) : a / b * b = a :=
by rewrite [↑divide, mul.assoc, (inv_mul_cancel Hb), mul_one]
theorem div_add_div_same : a / c + b / c = (a + b) / c := !right_distrib⁻¹
theorem inv_mul_add_mul_inv_eq_inv_add_inv (Ha : a ≠ 0) (Hb : b ≠ 0) :
(1 / a) * (a + b) * (1 / b) = 1 / a + 1 / b :=
by rewrite [(left_distrib (1 / a)), (one_div_mul_cancel Ha), right_distrib, one_mul,
mul.assoc, (mul_one_div_cancel Hb), mul_one, add.comm]
theorem inv_mul_sub_mul_inv_eq_inv_add_inv (Ha : a ≠ 0) (Hb : b ≠ 0) :
(1 / a) * (b - a) * (1 / b) = 1 / a - 1 / b :=
by rewrite [(mul_sub_left_distrib (1 / a)), (one_div_mul_cancel Ha), mul_sub_right_distrib,
one_mul, mul.assoc, (mul_one_div_cancel Hb), mul_one, one_mul]
theorem div_eq_one_iff_eq (Hb : b ≠ 0) : a / b = 1 ↔ a = b :=
iff.intro
(assume H1 : a / b = 1, symm (calc
b = 1 * b : one_mul
... = a / b * b : H1
... = a : div_mul_cancel Hb))
(assume H2 : a = b, calc
a / b = b / b : H2
... = 1 : div_self Hb)
theorem eq_div_iff_mul_eq (Hc : c ≠ 0) : a = b / c ↔ a * c = b :=
iff.intro
(assume H : a = b / c, by rewrite [H, (div_mul_cancel Hc)])
(assume H : a * c = b, by rewrite [-(mul_div_cancel Hc), H])
theorem add_div_eq_mul_add_div (Hc : c ≠ 0) : a + b / c = (a * c + b) / c :=
have H : (a + b / c) * c = a * c + b, by rewrite [right_distrib, (div_mul_cancel Hc)],
(iff.elim_right (eq_div_iff_mul_eq Hc)) H
theorem mul_mul_div (Hc : c ≠ 0) : a = a * c * (1 / c) :=
calc
a = a * 1 : mul_one
... = a * (c * (1 / c)) : mul_one_div_cancel Hc
... = a * c * (1 / c) : mul.assoc
-- There are many similar rules to these last two in the Isabelle library
-- that haven't been ported yet. Do as necessary.
end division_ring
structure field [class] (A : Type) extends division_ring A, comm_ring A
section field
variables [s : field A] {a b c d: A}
include s
local attribute divide [reducible]
theorem one_div_mul_one_div' (Ha : a ≠ 0) (Hb : b ≠ 0) : (1 / a) * (1 / b) = 1 / (a * b) :=
by rewrite [(one_div_mul_one_div Ha Hb), mul.comm b]
theorem div_mul_right (Hb : b ≠ 0) (H : a * b ≠ 0) : a / (a * b) = 1 / b :=
let Ha : a ≠ 0 := and.left (ne_zero_and_ne_zero_of_mul_ne_zero H) in
symm (calc
1 / b = 1 * (1 / b) : one_mul
... = (a * a⁻¹) * (1 / b) : mul_inv_cancel Ha
... = a * (a⁻¹ * (1 / b)) : mul.assoc
... = a * ((1 / a) * (1 / b)) :inv_eq_one_div
... = a * (1 / (b * a)) : one_div_mul_one_div Ha Hb
... = a * (1 / (a * b)) : mul.comm
... = a * (a * b)⁻¹ : inv_eq_one_div)
theorem div_mul_left (Ha : a ≠ 0) (H : a * b ≠ 0) : b / (a * b) = 1 / a :=
let H1 : b * a ≠ 0 := mul_ne_zero_comm H in
by rewrite [mul.comm a, (div_mul_right Ha H1)]
theorem mul_div_cancel_left (Ha : a ≠ 0) : a * b / a = b :=
by rewrite [mul.comm a, (mul_div_cancel Ha)]
theorem mul_div_cancel' (Hb : b ≠ 0) : b * (a / b) = a :=
by rewrite [mul.comm, (div_mul_cancel Hb)]
theorem one_div_add_one_div (Ha : a ≠ 0) (Hb : b ≠ 0) : 1 / a + 1 / b = (a + b) / (a * b) :=
have H [visible] : a * b ≠ 0, from (mul_ne_zero' Ha Hb),
by rewrite [add.comm, -(div_mul_left Ha H), -(div_mul_right Hb H), ↑divide, -right_distrib]
theorem div_mul_div (Hb : b ≠ 0) (Hd : d ≠ 0) : (a / b) * (c / d) = (a * c) / (b * d) :=
by rewrite [↑divide, 2 mul.assoc, (mul.comm b⁻¹), mul.assoc, (mul_inv_eq Hd Hb)]
theorem mul_div_mul_left (Hb : b ≠ 0) (Hc : c ≠ 0) : (c * a) / (c * b) = a / b :=
have H [visible] : c * b ≠ 0, from mul_ne_zero' Hc Hb,
by rewrite [-(div_mul_div Hc Hb), (div_self Hc), one_mul]
theorem mul_div_mul_right (Hb : b ≠ 0) (Hc : c ≠ 0) : (a * c) / (b * c) = a / b :=
by rewrite [(mul.comm a), (mul.comm b), (mul_div_mul_left Hb Hc)]
theorem div_mul_eq_mul_div : (b / c) * a = (b * a) / c :=
by rewrite [↑divide, mul.assoc, (mul.comm c⁻¹), -mul.assoc]
-- this one is odd -- I am not sure what to call it, but again, the prefix is right
theorem div_mul_eq_mul_div_comm (Hc : c ≠ 0) : (b / c) * a = b * (a / c) :=
by rewrite [(div_mul_eq_mul_div), -(one_mul c), -(div_mul_div (ne.symm zero_ne_one) Hc), div_one, one_mul]
theorem div_add_div (Hb : b ≠ 0) (Hd : d ≠ 0) :
(a / b) + (c / d) = ((a * d) + (b * c)) / (b * d) :=
have H [visible] : b * d ≠ 0, from mul_ne_zero' Hb Hd,
by rewrite [-(mul_div_mul_right Hb Hd), -(mul_div_mul_left Hd Hb), div_add_div_same]
theorem div_sub_div (Hb : b ≠ 0) (Hd : d ≠ 0) :
(a / b) - (c / d) = ((a * d) - (b * c)) / (b * d) :=
by rewrite [↑sub, neg_eq_neg_one_mul, -mul_div_assoc, (div_add_div Hb Hd),
-mul.assoc, (mul.comm b), mul.assoc, -neg_eq_neg_one_mul]
theorem mul_eq_mul_of_div_eq_div (Hb : b ≠ 0) (Hd : d ≠ 0) (H : a / b = c / d) : a * d = c * b :=
by rewrite [-mul_one, mul.assoc, (mul.comm d), -mul.assoc, -(div_self Hb),
-(div_mul_eq_mul_div_comm Hb), H, (div_mul_eq_mul_div), (div_mul_cancel Hd)]
theorem one_div_div (Ha : a ≠ 0) (Hb : b ≠ 0) : 1 / (a / b) = b / a :=
have H : (a / b) * (b / a) = 1, from calc
(a / b) * (b / a) = (a * b) / (b * a) : div_mul_div Hb Ha
... = (a * b) / (a * b) : mul.comm
... = 1 : div_self (mul_ne_zero' Ha Hb),
symm (eq_one_div_of_mul_eq_one H)
theorem div_div_eq_mul_div (Hb : b ≠ 0) (Hc : c ≠ 0) : a / (b / c) = (a * c) / b :=
by rewrite [div_eq_mul_one_div, (one_div_div Hb Hc), -mul_div_assoc]
theorem div_div_eq_div_mul (Hb : b ≠ 0) (Hc : c ≠ 0) : (a / b) / c = a / (b * c) :=
by rewrite [div_eq_mul_one_div, (div_mul_div Hb Hc), mul_one]
theorem div_div_div_div (Hb : b ≠ 0) (Hc : c ≠ 0) (Hd : d ≠ 0) : (a / b) / (c / d) = (a * d) / (b * c) :=
by rewrite [(div_div_eq_mul_div Hc Hd), (div_mul_eq_mul_div), (div_div_eq_div_mul Hb Hc)]
-- remaining to transfer from Isabelle fields: ordered fields
end field
structure discrete_field [class] (A : Type) extends field A :=
(has_decidable_eq : decidable_eq A)
(inv_zero : inv zero = zero)
attribute discrete_field.has_decidable_eq [instance]
section discrete_field
variable [s : discrete_field A]
include s
variables {a b c d : A}
-- many of the theorems in discrete_field are the same as theorems in field or division ring,
-- but with fewer hypotheses since 0⁻¹ = 0 and equality is decidable.
-- they are named with '. Is there a better convention?
theorem discrete_field.eq_zero_or_eq_zero_of_mul_eq_zero
(x y : A) (H : x * y = 0) : x = 0 ∨ y = 0 :=
decidable.by_cases
(assume H : x = 0, or.inl H)
(assume H1 : x ≠ 0,
or.inr (by rewrite [-one_mul, -(inv_mul_cancel H1), mul.assoc, H, mul_zero]))
definition discrete_field.to_integral_domain [trans-instance] [reducible] [coercion] :
integral_domain A :=
⦃ integral_domain, s,
eq_zero_or_eq_zero_of_mul_eq_zero := discrete_field.eq_zero_or_eq_zero_of_mul_eq_zero⦄
theorem inv_zero : 0⁻¹ = (0:A) := !discrete_field.inv_zero
theorem one_div_zero : 1 / 0 = (0:A) :=
calc
1 / 0 = 1 * 0⁻¹ : refl
... = 1 * 0 : discrete_field.inv_zero A
... = 0 : mul_zero
theorem div_zero : a / 0 = 0 := by rewrite [div_eq_mul_one_div, one_div_zero, mul_zero]
theorem ne_zero_of_one_div_ne_zero (H : 1 / a ≠ 0) : a ≠ 0 :=
assume Ha : a = 0, absurd (Ha⁻¹ ▸ one_div_zero) H
theorem inv_zero_imp_zero (H : 1 / a = 0) : a = 0 :=
decidable.by_cases
(assume Ha, Ha)
(assume Ha, false.elim ((one_div_ne_zero Ha) H))
-- the following could all go in "discrete_division_ring"
theorem one_div_mul_one_div'' : (1 / a) * (1 / b) = 1 / (b * a) :=
decidable.by_cases
(assume Ha : a = 0,
by rewrite [Ha, div_zero, zero_mul, -(@div_zero A s 1), mul_zero b])
(assume Ha : a ≠ 0,
decidable.by_cases
(assume Hb : b = 0,
by rewrite [Hb, div_zero, mul_zero, -(@div_zero A s 1), zero_mul a])
(assume Hb : b ≠ 0, one_div_mul_one_div Ha Hb))
theorem one_div_neg_eq_neg_one_div' : 1 / (- a) = - (1 / a) :=
decidable.by_cases
(assume Ha : a = 0, by rewrite [Ha, neg_zero, 2 div_zero, neg_zero])
(assume Ha : a ≠ 0, one_div_neg_eq_neg_one_div Ha)
theorem neg_div' : (-b) / a = - (b / a) :=
decidable.by_cases
(assume Ha : a = 0, by rewrite [Ha, 2 div_zero, neg_zero])
(assume Ha : a ≠ 0, neg_div Ha)
theorem neg_div_neg_eq_div' : (-a) / (-b) = a / b :=
decidable.by_cases
(assume Hb : b = 0, by rewrite [Hb, neg_zero, 2 div_zero])
(assume Hb : b ≠ 0, neg_div_neg_eq_div Hb)
theorem div_div' : 1 / (1 / a) = a :=
decidable.by_cases
(assume Ha : a = 0, by rewrite [Ha, 2 div_zero])
(assume Ha : a ≠ 0, div_div Ha)
theorem eq_of_invs_eq' (H : 1 / a = 1 / b) : a = b :=
decidable.by_cases
(assume Ha : a = 0,
have Hb : b = 0, from inv_zero_imp_zero (by rewrite [-H, Ha, div_zero]),
Hb⁻¹ ▸ Ha)
(assume Ha : a ≠ 0,
have Hb : b ≠ 0, from ne_zero_of_one_div_ne_zero (H ▸ (one_div_ne_zero Ha)),
eq_of_invs_eq Ha Hb H)
theorem mul_inv' : (b * a)⁻¹ = a⁻¹ * b⁻¹ :=
decidable.by_cases
(assume Ha : a = 0, by rewrite [Ha, mul_zero, 2 inv_zero, zero_mul])
(assume Ha : a ≠ 0,
decidable.by_cases
(assume Hb : b = 0, by rewrite [Hb, zero_mul, 2 inv_zero, mul_zero])
(assume Hb : b ≠ 0, mul_inv_eq Ha Hb))
-- the following are specifically for fields
theorem one_div_mul_one_div''' : (1 / a) * (1 / b) = 1 / (a * b) :=
by rewrite [(one_div_mul_one_div''), mul.comm b]
theorem div_mul_right' (Ha : a ≠ 0) : a / (a * b) = 1 / b :=
decidable.by_cases
(assume Hb : b = 0, by rewrite [Hb, mul_zero, 2 div_zero])
(assume Hb : b ≠ 0, div_mul_right Hb (mul_ne_zero Ha Hb))
theorem div_mul_left' (Hb : b ≠ 0) : b / (a * b) = 1 / a :=
by rewrite [mul.comm a, div_mul_right' Hb]
theorem div_mul_div' : (a / b) * (c / d) = (a * c) / (b * d) :=
decidable.by_cases
(assume Hb : b = 0, by rewrite [Hb, div_zero, zero_mul, -(@div_zero A s (a * c)), zero_mul])
(assume Hb : b ≠ 0,
decidable.by_cases
(assume Hd : d = 0, by rewrite [Hd, div_zero, mul_zero, -(@div_zero A s (a * c)), mul_zero])
(assume Hd : d ≠ 0, div_mul_div Hb Hd))
theorem mul_div_mul_left' (Hc : c ≠ 0) : (c * a) / (c * b) = a / b :=
decidable.by_cases
(assume Hb : b = 0, by rewrite [Hb, mul_zero, 2 div_zero])
(assume Hb : b ≠ 0, mul_div_mul_left Hb Hc)
theorem mul_div_mul_right' (Hc : c ≠ 0) : (a * c) / (b * c) = a / b :=
by rewrite [(mul.comm a), (mul.comm b), (mul_div_mul_left' Hc)]
-- this one is odd -- I am not sure what to call it, but again, the prefix is right
theorem div_mul_eq_mul_div_comm' : (b / c) * a = b * (a / c) :=
decidable.by_cases
(assume Hc : c = 0, by rewrite [Hc, div_zero, zero_mul, -(mul_zero b), -(@div_zero A s a)])
(assume Hc : c ≠ 0, div_mul_eq_mul_div_comm Hc)
theorem one_div_div' : 1 / (a / b) = b / a :=
decidable.by_cases
(assume Ha : a = 0, by rewrite [Ha, zero_div, 2 div_zero])
(assume Ha : a ≠ 0,
decidable.by_cases
(assume Hb : b = 0, by rewrite [Hb, 2 div_zero, zero_div])
(assume Hb : b ≠ 0, one_div_div Ha Hb))
theorem div_div_eq_mul_div' : a / (b / c) = (a * c) / b :=
by rewrite [div_eq_mul_one_div, one_div_div', -mul_div_assoc]
theorem div_div_eq_div_mul' : (a / b) / c = a / (b * c) :=
by rewrite [div_eq_mul_one_div, div_mul_div', mul_one]
theorem div_div_div_div' : (a / b) / (c / d) = (a * d) / (b * c) :=
by rewrite [div_div_eq_mul_div', div_mul_eq_mul_div, div_div_eq_div_mul']
theorem div_helper (H : a ≠ 0) : (1 / (a * b)) * a = 1 / b :=
by rewrite [div_mul_eq_mul_div, one_mul, (div_mul_right' H)]
end discrete_field
end algebra
/-
decidable.by_cases
(assume Ha : a = 0, sorry)
(assume Ha : a ≠ 0, sorry)
-/
|
9f7265761f9ba22d0de28ddc095bbbff103d5cac
|
6432ea7a083ff6ba21ea17af9ee47b9c371760f7
|
/tests/lean/run/haveDestruct.lean
|
bef657029eee5ca497b546e42c3e1445c3ac3b47
|
[
"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
| 316
|
lean
|
def f (x : Nat) :=
have y := x+1
y+y
def g (x : Nat × Nat) :=
have (y, z) := x
y + y
theorem ex1 (h : p ∧ q ∧ r) : p := by
have ⟨h', _, _⟩ := h
exact h'
theorem ex2 (h : p ∧ q ∧ r) : p :=
have ⟨h, _, _⟩ := h
h
theorem ex3 (h : p ∧ q ∧ r) : r :=
have ⟨_, _, h⟩ := h
h
|
bd0ccaa5a3cbd0ca943942aea44df0ad7f23dc5a
|
302c785c90d40ad3d6be43d33bc6a558354cc2cf
|
/src/algebraic_geometry/presheafed_space.lean
|
2a922611555fe8e6f9af29aeec6d3b6dcf725c75
|
[
"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
| 10,845
|
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 topology.sheaves.presheaf
/-!
# Presheafed spaces
Introduces the category of topological spaces equipped with a presheaf (taking values in an
arbitrary target category `C`.)
We further describe how to apply functors and natural transformations to the values of the
presheaves.
-/
universes v u
open category_theory
open Top
open topological_space
open opposite
open category_theory.category category_theory.functor
variables (C : Type u) [category.{v} C]
local attribute [tidy] tactic.op_induction'
namespace algebraic_geometry
/-- A `PresheafedSpace C` is a topological space equipped with a presheaf of `C`s. -/
structure PresheafedSpace :=
(carrier : Top)
(presheaf : carrier.presheaf C)
variables {C}
namespace PresheafedSpace
attribute [protected] presheaf
instance coe_carrier : has_coe (PresheafedSpace C) Top :=
{ coe := λ X, X.carrier }
@[simp] lemma as_coe (X : PresheafedSpace C) : X.carrier = (X : Top.{v}) := rfl
@[simp] lemma mk_coe (carrier) (presheaf) : (({ carrier := carrier, presheaf := presheaf } :
PresheafedSpace.{v} C) : Top.{v}) = carrier := rfl
instance (X : PresheafedSpace.{v} C) : topological_space X := X.carrier.str
/-- The constant presheaf on `X` with value `Z`. -/
def const (X : Top) (Z : C) : PresheafedSpace C :=
{ carrier := X,
presheaf :=
{ obj := λ U, Z,
map := λ U V f, 𝟙 Z, } }
instance [inhabited C] : inhabited (PresheafedSpace C) := ⟨const (Top.of pempty) (default C)⟩
/-- A morphism between presheafed spaces `X` and `Y` consists of a continuous map
`f` between the underlying topological spaces, and a (notice contravariant!) map
from the presheaf on `Y` to the pushforward of the presheaf on `X` via `f`. -/
structure hom (X Y : PresheafedSpace C) :=
(base : (X : Top.{v}) ⟶ (Y : Top.{v}))
(c : Y.presheaf ⟶ base _* X.presheaf)
@[ext] lemma ext {X Y : PresheafedSpace C} (α β : hom X Y)
(w : α.base = β.base)
(h : α.c ≫ (whisker_right (nat_trans.op (opens.map_iso _ _ w).inv) X.presheaf) = β.c) :
α = β :=
begin
cases α, cases β,
dsimp [presheaf.pushforward_obj] at *,
tidy, -- TODO including `injections` would make tidy work earlier.
end
.
/-- The identity morphism of a `PresheafedSpace`. -/
def id (X : PresheafedSpace C) : hom X X :=
{ base := 𝟙 (X : Top.{v}),
c := (functor.left_unitor _).inv ≫ whisker_right (nat_trans.op (opens.map_id X.carrier).hom) _ }
instance hom_inhabited (X : PresheafedSpace C) : inhabited (hom X X) := ⟨id X⟩
/-- Composition of morphisms of `PresheafedSpace`s. -/
def comp {X Y Z : PresheafedSpace C} (α : hom X Y) (β : hom Y Z) : hom X Z :=
{ base := α.base ≫ β.base,
c := β.c ≫ (whisker_left (opens.map β.base).op α.c) ≫ (Top.presheaf.pushforward.comp _ _ _).inv }
variables (C)
section
local attribute [simp] id comp
/- The proofs below can be done by `tidy`, but it is too slow,
and we don't have a tactic caching mechanism. -/
/-- The category of PresheafedSpaces. Morphisms are pairs, a continuous map and a presheaf map
from the presheaf on the target to the pushforward of the presheaf on the source. -/
instance category_of_PresheafedSpaces : category (PresheafedSpace C) :=
{ hom := hom,
id := id,
comp := λ X Y Z f g, comp f g,
id_comp' := λ X Y f,
begin
ext1, swap,
{ dsimp, simp only [id_comp] }, -- See note [dsimp, simp].
{ ext U, op_induction, cases U,
dsimp,
simp only [presheaf.pushforward.comp_inv_app, opens.map_iso_inv_app],
dsimp,
simp only [comp_id, comp_id, map_id], },
end,
comp_id' := λ X Y f,
begin
ext1, swap,
{ dsimp, simp only [comp_id] },
{ ext U, op_induction, cases U,
dsimp,
simp only [presheaf.pushforward.comp_inv_app, opens.map_iso_inv_app],
dsimp,
simp only [id_comp, comp_id, map_id], }
end,
assoc' := λ W X Y Z f g h,
begin
ext1, swap,
refl,
{ ext U, op_induction, cases U,
dsimp,
simp only [assoc, presheaf.pushforward.comp_inv_app, opens.map_iso_inv_app],
dsimp,
simp only [comp_id, id_comp, map_id], }
end }
end
variables {C}
@[simp] lemma id_base (X : PresheafedSpace C) :
((𝟙 X) : X ⟶ X).base = (𝟙 (X : Top.{v})) := rfl
lemma id_c (X : PresheafedSpace C) :
((𝟙 X) : X ⟶ X).c =
(functor.left_unitor _).inv ≫ whisker_right (nat_trans.op (opens.map_id X.carrier).hom) _ := rfl
@[simp] lemma id_c_app (X : PresheafedSpace C) (U) :
((𝟙 X) : X ⟶ X).c.app U = eq_to_hom (by { op_induction U, cases U, refl }) :=
by { op_induction U, cases U, simp only [id_c], dsimp, simp, }
@[simp] lemma comp_base {X Y Z : PresheafedSpace C} (f : X ⟶ Y) (g : Y ⟶ Z) :
(f ≫ g).base = f.base ≫ g.base := rfl
@[simp] lemma comp_c_app {X Y Z : PresheafedSpace C} (α : X ⟶ Y) (β : Y ⟶ Z) (U) :
(α ≫ β).c.app U = (β.c).app U ≫ (α.c).app (op ((opens.map (β.base)).obj (unop U))) ≫
(Top.presheaf.pushforward.comp _ _ _).inv.app U := rfl
lemma congr_app {X Y : PresheafedSpace C} {α β : X ⟶ Y} (h : α = β) (U) :
α.c.app U = β.c.app U ≫ X.presheaf.map (eq_to_hom (by subst h)) :=
by { subst h, dsimp, simp, }
section
variables (C)
/-- The forgetful functor from `PresheafedSpace` to `Top`. -/
@[simps]
def forget : PresheafedSpace C ⥤ Top :=
{ obj := λ X, (X : Top.{v}),
map := λ X Y f, f.base }
end
/--
The restriction of a presheafed space along an open embedding into the space.
-/
@[simps]
def restrict {U : Top} (X : PresheafedSpace C)
(f : U ⟶ (X : Top.{v})) (h : open_embedding f) : PresheafedSpace C :=
{ carrier := U,
presheaf := h.is_open_map.functor.op ⋙ X.presheaf }
/--
The map from the restriction of a presheafed space.
-/
@[simps]
def of_restrict (U : Top) (X : PresheafedSpace C)
(f : U ⟶ (X : Top.{v})) (h : open_embedding f) :
X.restrict f h ⟶ X :=
{ base := f,
c := { app := λ V, X.presheaf.map $
((h.is_open_map.adjunction.hom_equiv _ _).symm (𝟙 $ (opens.map f).obj $ unop V)).op,
naturality':= λ U V f, show _ = _ ≫ X.presheaf.map _,
by { rw [← map_comp, ← map_comp], refl } } }
/--
The map to the restriction of a presheafed space along the canonical inclusion from the top
subspace.
-/
@[simps]
def to_restrict_top (X : PresheafedSpace C) :
X ⟶ X.restrict (opens.inclusion ⊤) (opens.inclusion_open_embedding ⊤) :=
{ base := ⟨λ x, ⟨x, trivial⟩, continuous_def.2 $ λ U ⟨S, hS, hSU⟩, hSU ▸ hS⟩,
c := { app := λ U, X.presheaf.map $ (hom_of_le $ λ x hxU, ⟨⟨x, trivial⟩, hxU, rfl⟩ :
(opens.map (⟨λ x, ⟨x, trivial⟩, continuous_def.2 $ λ U ⟨S, hS, hSU⟩, hSU ▸ hS⟩ :
X.1 ⟶ (opens.to_Top X.1).obj ⊤)).obj (unop U) ⟶
(opens.inclusion_open_embedding ⊤).is_open_map.functor.obj (unop U)).op,
naturality':= λ U V f, show X.presheaf.map _ ≫ _ = _ ≫ X.presheaf.map _,
by { rw [← map_comp, ← map_comp], refl } } }
/--
The isomorphism from the restriction to the top subspace.
-/
@[simps]
def restrict_top_iso (X : PresheafedSpace C) :
X.restrict (opens.inclusion ⊤) (opens.inclusion_open_embedding ⊤) ≅ X :=
{ hom := X.of_restrict _ _ _,
inv := X.to_restrict_top,
hom_inv_id' := ext _ _ (concrete_category.hom_ext _ _ $ λ ⟨x, _⟩, rfl) $
nat_trans.ext _ _ $ funext $ λ U, by { op_induction U,
dsimp only [nat_trans.comp_app, comp_c_app, to_restrict_top, of_restrict,
whisker_right_app, comp_base, nat_trans.op_app, opens.map_iso_inv_app],
erw [presheaf.pushforward.comp_inv_app, comp_id, ← X.presheaf.map_comp,
← X.presheaf.map_comp, id_c_app],
exact X.presheaf.map_id _ },
inv_hom_id' := ext _ _ rfl $ nat_trans.ext _ _ $ funext $ λ U, by { op_induction U,
dsimp only [nat_trans.comp_app, comp_c_app, of_restrict, to_restrict_top,
whisker_right_app, comp_base, nat_trans.op_app, opens.map_iso_inv_app],
erw [← X.presheaf.map_comp, ← X.presheaf.map_comp, ← X.presheaf.map_comp, id_c_app],
convert eq_to_hom_map X.presheaf _,
erw [op_obj, id_base, opens.map_id_obj], refl } }
/--
The global sections, notated Gamma.
-/
@[simps]
def Γ : (PresheafedSpace C)ᵒᵖ ⥤ C :=
{ obj := λ X, (unop X).presheaf.obj (op ⊤),
map := λ X Y f, f.unop.c.app (op ⊤) ≫ (unop Y).presheaf.map (opens.le_map_top _ _).op,
map_id' := λ X, begin
op_induction X,
erw [unop_id_op, id_c_app, eq_to_hom_refl, id_comp],
exact X.presheaf.map_id _
end,
map_comp' := λ X Y Z f g, begin
rw [unop_comp, comp_c_app],
simp_rw category.assoc,
erw [nat_trans.naturality_assoc, presheaf.pushforward.comp_inv_app, id_comp,
category_theory.functor.comp_map, ← map_comp],
refl
end }
lemma Γ_obj_op (X : PresheafedSpace C) : Γ.obj (op X) = X.presheaf.obj (op ⊤) := rfl
lemma Γ_map_op {X Y : PresheafedSpace C} (f : X ⟶ Y) :
Γ.map f.op = f.c.app (op ⊤) ≫ X.presheaf.map (opens.le_map_top _ _).op := rfl
end PresheafedSpace
end algebraic_geometry
open algebraic_geometry algebraic_geometry.PresheafedSpace
variables {C}
namespace category_theory
variables {D : Type u} [category.{v} D]
local attribute [simp] presheaf.pushforward_obj
namespace functor
/-- We can apply a functor `F : C ⥤ D` to the values of the presheaf in any `PresheafedSpace C`,
giving a functor `PresheafedSpace C ⥤ PresheafedSpace D` -/
def map_presheaf (F : C ⥤ D) : PresheafedSpace C ⥤ PresheafedSpace D :=
{ obj := λ X, { carrier := X.carrier, presheaf := X.presheaf ⋙ F },
map := λ X Y f, { base := f.base, c := whisker_right f.c F }, }
@[simp] lemma map_presheaf_obj_X (F : C ⥤ D) (X : PresheafedSpace C) :
((F.map_presheaf.obj X) : Top.{v}) = (X : Top.{v}) := rfl
@[simp] lemma map_presheaf_obj_presheaf (F : C ⥤ D) (X : PresheafedSpace C) :
(F.map_presheaf.obj X).presheaf = X.presheaf ⋙ F := rfl
@[simp] lemma map_presheaf_map_f (F : C ⥤ D) {X Y : PresheafedSpace C} (f : X ⟶ Y) :
(F.map_presheaf.map f).base = f.base := rfl
@[simp] lemma map_presheaf_map_c (F : C ⥤ D) {X Y : PresheafedSpace C} (f : X ⟶ Y) :
(F.map_presheaf.map f).c = whisker_right f.c F := rfl
end functor
namespace nat_trans
/--
A natural transformation induces a natural transformation between the `map_presheaf` functors.
-/
def on_presheaf {F G : C ⥤ D} (α : F ⟶ G) : G.map_presheaf ⟶ F.map_presheaf :=
{ app := λ X,
{ base := 𝟙 _,
c := whisker_left X.presheaf α ≫ (functor.left_unitor _).inv ≫
whisker_right (nat_trans.op (opens.map_id X.carrier).hom) _ }, }
-- TODO Assemble the last two constructions into a functor
-- `(C ⥤ D) ⥤ (PresheafedSpace C ⥤ PresheafedSpace D)`
end nat_trans
end category_theory
|
f1f3bcc8fcc8cba95d84f55338ab3cc666d0cbe4
|
bf532e3e865883a676110e756f800e0ddeb465be
|
/data/real/basic.lean
|
d224b69ef770f0ea10f79eed55ee820b2b666a39
|
[
"Apache-2.0"
] |
permissive
|
aqjune/mathlib
|
da42a97d9e6670d2efaa7d2aa53ed3585dafc289
|
f7977ff5a6bcf7e5c54eec908364ceb40dafc795
|
refs/heads/master
| 1,631,213,225,595
| 1,521,089,840,000
| 1,521,089,840,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 24,458
|
lean
|
/-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
The (classical) real numbers ℝ. This is a direct construction
from Cauchy sequences.
-/
import order.conditionally_complete_lattice data.real.cau_seq algebra.big_operators algebra.archimedean
def real := quotient (@cau_seq.equiv ℚ _ _ _ abs _)
notation `ℝ` := real
namespace real
open rat cau_seq
def mk : cau_seq ℚ abs → ℝ := quotient.mk
@[simp] theorem mk_eq_mk (f) : @eq ℝ ⟦f⟧ (mk f) := rfl
theorem mk_eq {f g} : mk f = mk g ↔ f ≈ g := quotient.eq
def of_rat (x : ℚ) : ℝ := mk (const abs x)
instance : has_zero ℝ := ⟨of_rat 0⟩
instance : has_one ℝ := ⟨of_rat 1⟩
instance : inhabited ℝ := ⟨0⟩
theorem of_rat_zero : of_rat 0 = 0 := rfl
theorem of_rat_one : of_rat 1 = 1 := rfl
@[simp] theorem mk_eq_zero {f} : mk f = 0 ↔ lim_zero f :=
by have : mk f = 0 ↔ lim_zero (f - 0) := quotient.eq;
rwa sub_zero at this
instance : has_add ℝ :=
⟨λ x y, quotient.lift_on₂ x y (λ f g, mk (f + g)) $
λ f₁ g₁ f₂ g₂ hf hg, quotient.sound $
by simpa [(≈), setoid.r] using add_lim_zero hf hg⟩
@[simp] theorem mk_add (f g : cau_seq ℚ abs) : mk f + mk g = mk (f + g) := rfl
instance : has_neg ℝ :=
⟨λ x, quotient.lift_on x (λ f, mk (-f)) $
λ f₁ f₂ hf, quotient.sound $
by simpa [(≈), setoid.r] using neg_lim_zero hf⟩
@[simp] theorem mk_neg (f : cau_seq ℚ abs) : -mk f = mk (-f) := rfl
instance : has_mul ℝ :=
⟨λ x y, quotient.lift_on₂ x y (λ f g, mk (f * g)) $
λ f₁ g₁ f₂ g₂ hf hg, quotient.sound $
by simpa [(≈), setoid.r, mul_add, mul_comm] using
add_lim_zero (mul_lim_zero g₁ hf) (mul_lim_zero f₂ hg)⟩
@[simp] theorem mk_mul (f g : cau_seq ℚ abs) : mk f * mk g = mk (f * g) := rfl
theorem of_rat_add (x y : ℚ) : of_rat (x + y) = of_rat x + of_rat y :=
congr_arg mk (const_add _ _)
theorem of_rat_neg (x : ℚ) : of_rat (-x) = -of_rat x :=
congr_arg mk (const_neg _)
theorem of_rat_mul (x y : ℚ) : of_rat (x * y) = of_rat x * of_rat y :=
congr_arg mk (const_mul _ _)
instance : comm_ring ℝ :=
by refine { neg := has_neg.neg,
add := (+), zero := 0, mul := (*), one := 1, .. };
{ repeat {refine λ a, quotient.induction_on a (λ _, _)},
simp [show 0 = mk 0, from rfl, show 1 = mk 1, from rfl,
mul_left_comm, mul_comm, mul_add] }
/- Extra instances to short-circuit type class resolution -/
instance : semigroup ℝ := by apply_instance
instance : monoid ℝ := by apply_instance
instance : comm_semigroup ℝ := by apply_instance
instance : comm_monoid ℝ := by apply_instance
instance : add_monoid ℝ := by apply_instance
instance : add_group ℝ := by apply_instance
instance : add_comm_group ℝ := by apply_instance
instance : ring ℝ := by apply_instance
theorem of_rat_sub (x y : ℚ) : of_rat (x - y) = of_rat x - of_rat y :=
congr_arg mk (const_sub _ _)
instance : has_lt ℝ :=
⟨λ x y, quotient.lift_on₂ x y (<) $
λ f₁ g₁ f₂ g₂ hf hg, propext $
⟨λ h, lt_of_eq_of_lt (setoid.symm hf) (lt_of_lt_of_eq h hg),
λ h, lt_of_eq_of_lt hf (lt_of_lt_of_eq h (setoid.symm hg))⟩⟩
@[simp] theorem mk_lt {f g : cau_seq ℚ abs} : mk f < mk g ↔ f < g := iff.rfl
@[simp] theorem mk_pos {f : cau_seq ℚ abs} : 0 < mk f ↔ pos f :=
iff_of_eq (congr_arg pos (sub_zero f))
instance : has_le ℝ := ⟨λ x y, x < y ∨ x = y⟩
@[simp] theorem mk_le {f 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 :=
quotient.induction_on₃ a b c (λ f g h,
iff_of_eq (congr_arg pos $ by rw add_sub_add_left_eq_sub))
instance : linear_order ℝ :=
{ le := (≤), lt := (<),
le_refl := λ a, or.inr rfl,
le_trans := λ a b c, quotient.induction_on₃ a b c $
λ f g h, by simpa using le_trans,
lt_iff_le_not_le := λ a b, quotient.induction_on₂ a b $
λ f g, by simpa using lt_iff_le_not_le,
le_antisymm := λ a b, quotient.induction_on₂ a b $
λ f g, by simpa [mk_eq] using @cau_seq.le_antisymm _ _ f g,
le_total := λ a b, quotient.induction_on₂ a b $
λ f g, by simpa using le_total f g }
instance : partial_order ℝ := by apply_instance
instance : preorder ℝ := by apply_instance
theorem of_rat_lt {x y : ℚ} : of_rat x < of_rat y ↔ x < y := const_lt
protected theorem zero_lt_one : (0 : ℝ) < 1 := of_rat_lt.2 zero_lt_one
protected theorem mul_pos {a b : ℝ} : 0 < a → 0 < b → 0 < a * b :=
quotient.induction_on₂ a b $ λ f g, by simpa using cau_seq.mul_pos
instance : linear_ordered_comm_ring ℝ :=
{ add_le_add_left := λ a b h c,
(le_iff_le_iff_lt_iff_lt.2 $ real.add_lt_add_iff_left c).2 h,
zero_ne_one := ne_of_lt real.zero_lt_one,
mul_nonneg := λ a b a0 b0,
match a0, b0 with
| or.inl a0, or.inl b0 := le_of_lt (real.mul_pos a0 b0)
| or.inr a0, _ := by simp [a0.symm]
| _, or.inr b0 := by simp [b0.symm]
end,
mul_pos := @real.mul_pos,
zero_lt_one := real.zero_lt_one,
add_lt_add_left := λ a b h c, (real.add_lt_add_iff_left c).2 h,
..real.comm_ring, ..real.linear_order }
/- Extra instances to short-circuit type class resolution -/
instance : linear_ordered_ring ℝ := by apply_instance
instance : ordered_ring ℝ := by apply_instance
instance : ordered_comm_group ℝ := by apply_instance
instance : ordered_cancel_comm_monoid ℝ := by apply_instance
instance : integral_domain ℝ := by apply_instance
instance : domain ℝ := by apply_instance
local attribute [instance] classical.prop_decidable
noncomputable instance : has_inv ℝ :=
⟨λ x, quotient.lift_on x
(λ f, mk $ if h : lim_zero f then 0 else inv f h) $
λ f g fg, begin
have := lim_zero_congr fg,
by_cases hf : lim_zero f,
{ simp [hf, this.1 hf, setoid.refl] },
{ have hg := mt this.2 hf, simp [hf, hg],
have If : mk (inv f hf) * mk f = 1 := mk_eq.2 (inv_mul_cancel hf),
have Ig : mk (inv g hg) * mk g = 1 := mk_eq.2 (inv_mul_cancel hg),
rw [mk_eq.2 fg, ← Ig] at If,
rw mul_comm at Ig,
rw [← mul_one (mk (inv f hf)), ← Ig, ← mul_assoc, If,
mul_assoc, Ig, mul_one] }
end⟩
@[simp] theorem inv_zero : (0 : ℝ)⁻¹ = 0 :=
congr_arg mk $ by rw dif_pos; [refl, exact zero_lim_zero]
@[simp] theorem inv_mk {f} (hf) : (mk f)⁻¹ = mk (inv f hf) :=
congr_arg mk $ by rw dif_neg
protected theorem inv_mul_cancel {x : ℝ} : x ≠ 0 → x⁻¹ * x = 1 :=
quotient.induction_on x $ λ f hf, begin
simp at hf, simp [hf],
exact quotient.sound (cau_seq.inv_mul_cancel hf)
end
noncomputable instance : discrete_linear_ordered_field ℝ :=
{ inv := has_inv.inv,
inv_mul_cancel := @real.inv_mul_cancel,
mul_inv_cancel := λ x x0, by rw [mul_comm, real.inv_mul_cancel x0],
inv_zero := inv_zero,
decidable_le := by apply_instance,
..real.linear_ordered_comm_ring }
/- Extra instances to short-circuit type class resolution -/
noncomputable instance : linear_ordered_field ℝ := by apply_instance
noncomputable instance : decidable_linear_ordered_comm_ring ℝ := by apply_instance
noncomputable instance : decidable_linear_ordered_comm_group ℝ := by apply_instance
noncomputable instance : decidable_linear_order ℝ := by apply_instance
noncomputable instance : discrete_field ℝ := by apply_instance
noncomputable instance : field ℝ := by apply_instance
noncomputable instance : division_ring ℝ := by apply_instance
@[simp] theorem of_rat_eq_cast : ∀ x : ℚ, of_rat x = x :=
eq_cast of_rat rfl of_rat_add of_rat_mul
theorem le_mk_of_forall_le {x : ℝ} {f : cau_seq ℚ abs} :
(∃ i, ∀ j ≥ i, x ≤ f j) → x ≤ mk f :=
quotient.induction_on x $ λ g h, le_of_not_lt $
λ ⟨K, K0, hK⟩,
let ⟨i, H⟩ := exists_forall_ge_and h $
exists_forall_ge_and hK (f.cauchy₃ $ half_pos K0) in
begin
apply not_lt_of_le (H _ (le_refl _)).1,
rw ← of_rat_eq_cast,
refine ⟨_, half_pos K0, i, λ j ij, _⟩,
have := add_le_add (H _ ij).2.1
(le_of_lt (abs_lt.1 $ (H _ (le_refl _)).2.2 _ ij).1),
rwa [← sub_eq_add_neg, sub_self_div_two, sub_apply, sub_add_sub_cancel] at this
end
theorem mk_le_of_forall_le {f : cau_seq ℚ abs} {x : ℝ} :
(∃ i, ∀ j ≥ i, (f j : ℝ) ≤ x) → mk f ≤ x
| ⟨i, H⟩ := by rw [← neg_le_neg_iff, mk_neg]; exact
le_mk_of_forall_le ⟨i, λ j ij, by simp [H _ ij]⟩
theorem mk_near_of_forall_near {f : cau_seq ℚ abs} {x : ℝ} {ε : ℝ}
(H : ∃ i, ∀ j ≥ i, abs ((f j : ℝ) - x) ≤ ε) : abs (mk f - x) ≤ ε :=
abs_sub_le_iff.2
⟨sub_le_iff_le_add'.2 $ mk_le_of_forall_le $
H.imp $ λ i h j ij, sub_le_iff_le_add'.1 (abs_sub_le_iff.1 $ h j ij).1,
sub_le.1 $ le_mk_of_forall_le $
H.imp $ λ i h j ij, sub_le.1 (abs_sub_le_iff.1 $ h j ij).2⟩
instance : archimedean ℝ :=
archimedean_iff_rat_le.2 $ λ x, quotient.induction_on x $ λ f,
let ⟨M, M0, H⟩ := f.bounded' 0 in
⟨M, mk_le_of_forall_le ⟨0, λ i _,
rat.cast_le.2 $ le_of_lt (abs_lt.1 (H i)).2⟩⟩
noncomputable instance : floor_ring ℝ := archimedean.floor_ring _
theorem is_cau_seq_iff_lift {f : ℕ → ℚ} : is_cau_seq abs f ↔ is_cau_seq abs (λ i, (f i : ℝ)) :=
⟨λ H ε ε0,
let ⟨δ, δ0, δε⟩ := exists_pos_rat_lt ε0 in
(H _ δ0).imp $ λ i hi j ij, lt_trans
(by simpa using (@rat.cast_lt ℝ _ _ _).2 (hi _ ij)) δε,
λ H ε ε0, (H _ (rat.cast_pos.2 ε0)).imp $
λ i hi j ij, (@rat.cast_lt ℝ _ _ _).1 $ by simpa using hi _ ij⟩
theorem of_near (f : ℕ → ℚ) (x : ℝ)
(h : ∀ ε > 0, ∃ i, ∀ j ≥ i, abs ((f j : ℝ) - x) < ε) :
∃ h', mk ⟨f, h'⟩ = x :=
⟨is_cau_seq_iff_lift.2 (of_near _ (const abs x) h),
sub_eq_zero.1 $ abs_eq_zero.1 $
eq_of_le_of_forall_le_of_dense (abs_nonneg _) $ λ ε ε0,
mk_near_of_forall_near $
(h _ ε0).imp (λ i h j ij, le_of_lt (h j ij))⟩
theorem exists_floor (x : ℝ) : ∃ (ub : ℤ), (ub:ℝ) ≤ x ∧
∀ (z : ℤ), (z:ℝ) ≤ x → z ≤ ub :=
int.exists_greatest_of_bdd
(let ⟨n, hn⟩ := exists_int_gt x in ⟨n, λ z h',
int.cast_le.1 $ le_trans h' $ le_of_lt hn⟩)
(let ⟨n, hn⟩ := exists_int_lt x in ⟨n, le_of_lt hn⟩)
theorem exists_sup (S : set ℝ) : (∃ x, x ∈ S) → (∃ x, ∀ y ∈ S, y ≤ x) →
∃ x, ∀ y, x ≤ y ↔ ∀ z ∈ S, z ≤ y
| ⟨L, hL⟩ ⟨U, hU⟩ := begin
have,
{ refine λ d : ℕ, @int.exists_greatest_of_bdd
(λ n, ∃ y ∈ S, (n:ℝ) ≤ y * d) _ _ _,
{ cases exists_int_gt U with k hk,
refine ⟨k * d, λ z h, _⟩,
rcases h with ⟨y, yS, hy⟩,
refine int.cast_le.1 (le_trans hy _),
simp,
exact mul_le_mul_of_nonneg_right
(le_trans (hU _ yS) (le_of_lt hk)) (nat.cast_nonneg _) },
{ exact ⟨⌊L * d⌋, L, hL, floor_le _⟩ } },
cases classical.axiom_of_choice this with f hf,
dsimp at f hf,
have hf₁ : ∀ n > 0, ∃ y ∈ S, ((f n / n:ℚ):ℝ) ≤ y := λ n n0,
let ⟨y, yS, hy⟩ := (hf n).1 in
⟨y, yS, by simpa using (div_le_iff (nat.cast_pos.2 n0)).2 hy⟩,
have hf₂ : ∀ (n > 0) (y ∈ S), (y - (n:ℕ)⁻¹ : ℝ) < (f n / n:ℚ),
{ intros n n0 y yS,
have := lt_of_lt_of_le (sub_one_lt_floor _)
(int.cast_le.2 $ (hf n).2 _ ⟨y, yS, floor_le _⟩),
simp [-sub_eq_add_neg],
rwa [lt_div_iff (nat.cast_pos.2 n0), sub_mul, _root_.inv_mul_cancel],
exact ne_of_gt (nat.cast_pos.2 n0) },
suffices hg, let g : cau_seq ℚ abs := ⟨λ n, f n / n, hg⟩,
refine ⟨mk g, λ y, ⟨λ h x xS, le_trans _ h, λ h, _⟩⟩,
{ refine le_of_forall_ge_of_dense (λ z xz, _),
cases exists_nat_gt (x - z)⁻¹ with K hK,
refine le_mk_of_forall_le ⟨K, λ n nK, _⟩,
replace xz := sub_pos.2 xz,
replace hK := le_trans (le_of_lt hK) (nat.cast_le.2 nK),
have n0 : 0 < n := nat.cast_pos.1 (lt_of_lt_of_le (inv_pos xz) hK),
refine le_trans _ (le_of_lt $ hf₂ _ n0 _ xS),
rwa [le_sub, inv_le (nat.cast_pos.2 n0) xz] },
{ exact mk_le_of_forall_le ⟨1, λ n n1,
let ⟨x, xS, hx⟩ := hf₁ _ n1 in le_trans hx (h _ xS)⟩ },
intros ε ε0,
suffices : ∀ j k ≥ nat_ceil ε⁻¹, (f j / j - f k / k : ℚ) < ε,
{ refine ⟨_, λ j ij, abs_lt.2 ⟨_, this _ _ ij (le_refl _)⟩⟩,
rw [neg_lt, neg_sub], exact this _ _ (le_refl _) ij },
intros j k ij ik,
replace ij := le_trans (le_nat_ceil _) (nat.cast_le.2 ij),
replace ik := le_trans (le_nat_ceil _) (nat.cast_le.2 ik),
have j0 := nat.cast_pos.1 (lt_of_lt_of_le (inv_pos ε0) ij),
have k0 := nat.cast_pos.1 (lt_of_lt_of_le (inv_pos ε0) ik),
rcases hf₁ _ j0 with ⟨y, yS, hy⟩,
refine lt_of_lt_of_le ((@rat.cast_lt ℝ _ _ _).1 _)
((inv_le ε0 (nat.cast_pos.2 k0)).1 ik),
simpa using sub_lt_iff_lt_add'.2
(lt_of_le_of_lt hy $ sub_lt_iff_lt_add.1 $ hf₂ _ k0 _ yS)
end
noncomputable def Sup (S : set ℝ) : ℝ :=
if h : (∃ x, x ∈ S) ∧ (∃ x, ∀ y ∈ S, y ≤ x)
then classical.some (exists_sup S h.1 h.2) else 0
theorem Sup_le (S : set ℝ) (h₁ : ∃ x, x ∈ S) (h₂ : ∃ x, ∀ y ∈ S, y ≤ x)
{y} : Sup S ≤ y ↔ ∀ z ∈ S, z ≤ y :=
by simp [Sup, h₁, h₂]; exact
classical.some_spec (exists_sup S h₁ h₂) y
theorem lt_Sup (S : set ℝ) (h₁ : ∃ x, x ∈ S) (h₂ : ∃ x, ∀ y ∈ S, y ≤ x)
{y} : y < Sup S ↔ ∃ z ∈ S, y < z :=
by simpa [not_forall] using not_congr (@Sup_le S h₁ h₂ y)
theorem le_Sup (S : set ℝ) (h₂ : ∃ x, ∀ y ∈ S, y ≤ x) {x} (xS : x ∈ S) : x ≤ Sup S :=
(Sup_le S ⟨_, xS⟩ h₂).1 (le_refl _) _ xS
theorem Sup_le_ub (S : set ℝ) (h₁ : ∃ x, x ∈ S) {ub} (h₂ : ∀ y ∈ S, y ≤ ub) : Sup S ≤ ub :=
(Sup_le S h₁ ⟨_, h₂⟩).2 h₂
noncomputable def Inf (S : set ℝ) : ℝ := -Sup {x | -x ∈ S}
theorem le_Inf (S : set ℝ) (h₁ : ∃ x, x ∈ S) (h₂ : ∃ x, ∀ y ∈ S, x ≤ y)
{y} : y ≤ Inf S ↔ ∀ z ∈ S, y ≤ z :=
begin
refine le_neg.trans ((Sup_le _ _ _).trans _),
{ cases h₁ with x xS, exact ⟨-x, by simp [xS]⟩ },
{ cases h₂ with ub h, exact ⟨-ub, λ y hy, le_neg.1 $ h _ hy⟩ },
split; intros H z hz,
{ exact neg_le_neg_iff.1 (H _ $ by simp [hz]) },
{ exact le_neg.2 (H _ hz) }
end
theorem Inf_lt (S : set ℝ) (h₁ : ∃ x, x ∈ S) (h₂ : ∃ x, ∀ y ∈ S, x ≤ y)
{y} : Inf S < y ↔ ∃ z ∈ S, z < y :=
by simpa [not_forall] using not_congr (@le_Inf S h₁ h₂ y)
theorem Inf_le (S : set ℝ) (h₂ : ∃ x, ∀ y ∈ S, x ≤ y) {x} (xS : x ∈ S) : Inf S ≤ x :=
(le_Inf S ⟨_, xS⟩ h₂).1 (le_refl _) _ xS
theorem lb_le_Inf (S : set ℝ) (h₁ : ∃ x, x ∈ S) {lb} (h₂ : ∀ y ∈ S, lb ≤ y) : lb ≤ Inf S :=
(le_Inf S h₁ ⟨_, h₂⟩).2 h₂
open lattice
noncomputable instance lattice : lattice ℝ := by apply_instance
noncomputable instance : conditionally_complete_linear_order ℝ :=
{ Sup := real.Sup,
Inf := real.Inf,
le_cSup :=
assume (s : set ℝ) (a : ℝ) (_ : bdd_above s) (_ : a ∈ s),
show a ≤ Sup s,
from le_Sup s ‹bdd_above s› ‹a ∈ s›,
cSup_le :=
assume (s : set ℝ) (a : ℝ) (_ : s ≠ ∅) (H : ∀b∈s, b ≤ a),
show Sup s ≤ a,
from Sup_le_ub s (set.exists_mem_of_ne_empty ‹s ≠ ∅›) H,
cInf_le :=
assume (s : set ℝ) (a : ℝ) (_ : bdd_below s) (_ : a ∈ s),
show Inf s ≤ a,
from Inf_le s ‹bdd_below s› ‹a ∈ s›,
le_cInf :=
assume (s : set ℝ) (a : ℝ) (_ : s ≠ ∅) (H : ∀b∈s, a ≤ b),
show a ≤ Inf s,
from lb_le_Inf s (set.exists_mem_of_ne_empty ‹s ≠ ∅›) H,
..real.linear_order, ..real.lattice}
theorem cau_seq_converges (f : cau_seq ℝ abs) : ∃ x, f ≈ const abs x :=
begin
let S := {x : ℝ | const abs x < f},
have lb : ∃ x, x ∈ S := exists_lt f,
have ub' : ∀ x, f < const abs x → ∀ y ∈ S, y ≤ x :=
λ x h y yS, le_of_lt $ const_lt.1 $ cau_seq.lt_trans yS h,
have ub : ∃ x, ∀ y ∈ S, y ≤ x := (exists_gt f).imp ub',
refine ⟨Sup S,
((lt_total _ _).resolve_left (λ h, _)).resolve_right (λ h, _)⟩,
{ rcases h with ⟨ε, ε0, i, ih⟩,
refine not_lt_of_le (Sup_le_ub S lb (ub' _ _))
((sub_lt_self_iff _).2 (half_pos ε0)),
refine ⟨_, half_pos ε0, i, λ j ij, _⟩,
rw [sub_apply, const_apply, sub_right_comm,
le_sub_iff_add_le, add_halves],
exact ih _ ij },
{ rcases h with ⟨ε, ε0, i, ih⟩,
refine not_lt_of_le (le_Sup S ub _)
((lt_add_iff_pos_left _).2 (half_pos ε0)),
refine ⟨_, half_pos ε0, i, λ j ij, _⟩,
rw [sub_apply, const_apply, add_comm, ← sub_sub,
le_sub_iff_add_le, add_halves],
exact ih _ ij }
end
noncomputable def lim (f : ℕ → ℝ) : ℝ :=
if hf : is_cau_seq abs f then
classical.some (cau_seq_converges ⟨f, hf⟩)
else 0
theorem equiv_lim (f : cau_seq ℝ abs) : f ≈ const abs (lim f) :=
by simp [lim, f.is_cau]; cases f with f hf;
exact classical.some_spec (cau_seq_converges ⟨f, hf⟩)
theorem sqrt_exists : ∀ {x : ℝ}, 0 ≤ x → ∃ y, 0 ≤ y ∧ y * y = x :=
suffices H : ∀ {x : ℝ}, 0 < x → x ≤ 1 → ∃ y, 0 < y ∧ y * y = x, begin
intros x x0, cases x0,
cases le_total x 1 with x1 x1,
{ rcases H x0 x1 with ⟨y, y0, hy⟩,
exact ⟨y, le_of_lt y0, hy⟩ },
{ have := (inv_le_inv x0 zero_lt_one).2 x1,
rw inv_one at this,
rcases H (inv_pos x0) this with ⟨y, y0, hy⟩,
refine ⟨y⁻¹, le_of_lt (inv_pos y0), _⟩, rw [← mul_inv', hy, inv_inv'] },
{ exact ⟨0, by simp [x0.symm]⟩ }
end,
λ x x0 x1, begin
let S := {y | 0 < y ∧ y * y ≤ x},
have lb : x ∈ S := ⟨x0, by simpa using (mul_le_mul_right x0).2 x1⟩,
have ub : ∀ y ∈ S, (y:ℝ) ≤ 1,
{ intros y yS, cases yS with y0 yx,
refine (mul_self_le_mul_self_iff (le_of_lt y0) zero_le_one).2 _,
simpa using le_trans yx x1 },
have S0 : 0 < Sup S := lt_of_lt_of_le x0 (le_Sup _ ⟨_, ub⟩ lb),
refine ⟨Sup S, S0, le_antisymm (not_lt.1 $ λ h, _) (not_lt.1 $ λ h, _)⟩,
{ rw [← div_lt_iff S0, lt_Sup S ⟨_, lb⟩ ⟨_, ub⟩] at h,
rcases h with ⟨y, yS, hy⟩, rcases yS with ⟨y0, yx⟩,
rw [div_lt_iff S0, ← div_lt_iff' y0, lt_Sup S ⟨_, lb⟩ ⟨_, ub⟩] at hy,
rcases hy with ⟨z, zS, hz⟩, rcases zS with ⟨z0, zx⟩,
rw [div_lt_iff y0] at hz,
exact not_lt_of_lt
((mul_lt_mul_right y0).1 (lt_of_le_of_lt yx hz))
((mul_lt_mul_left z0).1 (lt_of_le_of_lt zx hz)) },
{ let s := Sup S, let y := s + (x - s * s) / 3,
replace h : 0 < x - s * s := sub_pos.2 h,
have _30 := bit1_pos zero_le_one,
have : s < y := (lt_add_iff_pos_right _).2 (div_pos h _30),
refine not_le_of_lt this (le_Sup S ⟨_, ub⟩ ⟨lt_trans S0 this, _⟩),
rw [add_mul_self_eq, add_assoc, ← le_sub_iff_add_le', ← add_mul,
← le_div_iff (div_pos h _30), div_div_cancel (ne_of_gt h)],
apply add_le_add,
{ simpa using (mul_le_mul_left (@two_pos ℝ _)).2 (Sup_le_ub _ ⟨_, lb⟩ ub) },
{ rw [div_le_one_iff_le _30],
refine le_trans (sub_le_self _ (mul_self_nonneg _)) (le_trans x1 _),
exact (le_add_iff_nonneg_left _).2 (le_of_lt two_pos) } }
end
def sqrt_aux (f : cau_seq ℚ abs) : ℕ → ℚ
| 0 := rat.mk_nat (f 0).num.to_nat.sqrt (f 0).denom.sqrt
| (n + 1) := let s := sqrt_aux n in max 0 $ (s + f (n+1) / s) / 2
theorem sqrt_aux_nonneg (f : cau_seq ℚ abs) : ∀ i : ℕ, 0 ≤ sqrt_aux f i
| 0 := by rw [sqrt_aux, mk_nat_eq, mk_eq_div];
apply div_nonneg'; exact int.cast_nonneg.2 (int.of_nat_nonneg _)
| (n + 1) := le_max_left _ _
/- TODO(Mario): finish the proof
theorem sqrt_aux_converges (f : cau_seq ℚ abs) : ∃ h x, 0 ≤ x ∧ x * x = max 0 (mk f) ∧
mk ⟨sqrt_aux f, h⟩ = x :=
begin
rcases sqrt_exists (le_max_left 0 (mk f)) with ⟨x, x0, hx⟩,
suffices : ∃ h, mk ⟨sqrt_aux f, h⟩ = x,
{ exact this.imp (λ h e, ⟨x, x0, hx, e⟩) },
apply of_near,
suffices : ∃ δ > 0, ∀ i, abs (↑(sqrt_aux f i) - x) < δ / 2 ^ i,
{ rcases this with ⟨δ, δ0, hδ⟩,
intros,
}
end -/
noncomputable def sqrt (x : ℝ) : ℝ :=
classical.some (sqrt_exists (le_max_left 0 x))
/-quotient.lift_on x
(λ f, mk ⟨sqrt_aux f, (sqrt_aux_converges f).fst⟩)
(λ f g e, begin
rcases sqrt_aux_converges f with ⟨hf, x, x0, xf, xs⟩,
rcases sqrt_aux_converges g with ⟨hg, y, y0, yg, ys⟩,
refine xs.trans (eq.trans _ ys.symm),
rw [← @mul_self_inj_of_nonneg ℝ _ x y x0 y0, xf, yg],
congr_n 1, exact quotient.sound e
end)-/
theorem sqrt_prop (x : ℝ) : 0 ≤ sqrt x ∧ sqrt x * sqrt x = max 0 x :=
classical.some_spec (sqrt_exists (le_max_left 0 x))
/-quotient.induction_on x $ λ f,
by rcases sqrt_aux_converges f with ⟨hf, _, x0, xf, rfl⟩; exact ⟨x0, xf⟩-/
theorem sqrt_eq_zero_of_nonpos {x : ℝ} (h : x ≤ 0) : sqrt x = 0 :=
eq_zero_of_mul_self_eq_zero $ (sqrt_prop x).2.trans $ max_eq_left h
theorem sqrt_nonneg (x : ℝ) : 0 ≤ sqrt x := (sqrt_prop x).1
@[simp] theorem mul_self_sqrt {x : ℝ} (h : 0 ≤ x) : sqrt x * sqrt x = x :=
(sqrt_prop x).2.trans (max_eq_right h)
@[simp] theorem sqrt_mul_self {x : ℝ} (h : 0 ≤ x) : sqrt (x * x) = x :=
(mul_self_inj_of_nonneg (sqrt_nonneg _) h).1 (mul_self_sqrt (mul_self_nonneg _))
theorem sqrt_eq_iff_mul_self_eq {x y : ℝ} (hx : 0 ≤ x) (hy : 0 ≤ y) :
sqrt x = y ↔ y * y = x :=
⟨λ h, by rw [← h, mul_self_sqrt hx],
λ h, by rw [← h, sqrt_mul_self hy]⟩
local infix ` ^ ` := monoid.pow
@[simp] theorem sqr_sqrt {x : ℝ} (h : 0 ≤ x) : sqrt x ^ 2 = x :=
by rw [pow_two, mul_self_sqrt h]
@[simp] theorem sqrt_sqr {x : ℝ} (h : 0 ≤ x) : sqrt (x ^ 2) = x :=
by rw [pow_two, sqrt_mul_self h]
theorem sqrt_eq_iff_sqr_eq {x y : ℝ} (hx : 0 ≤ x) (hy : 0 ≤ y) :
sqrt x = y ↔ y ^ 2 = x :=
by rw [pow_two, sqrt_eq_iff_mul_self_eq hx hy]
theorem sqrt_mul_self_eq_abs (x : ℝ) : sqrt (x * x) = abs x :=
(le_total 0 x).elim
(λ h, (sqrt_mul_self h).trans (abs_of_nonneg h).symm)
(λ h, by rw [← neg_mul_neg,
sqrt_mul_self (neg_nonneg.2 h), abs_of_nonpos h])
theorem sqrt_sqr_eq_abs (x : ℝ) : sqrt (x ^ 2) = abs x :=
by rw [pow_two, sqrt_mul_self_eq_abs]
@[simp] theorem sqrt_zero : sqrt 0 = 0 :=
by simpa using sqrt_mul_self (le_refl _)
@[simp] theorem sqrt_one : sqrt 1 = 1 :=
by simpa using sqrt_mul_self zero_le_one
@[simp] theorem sqrt_le {x y : ℝ} (hx : 0 ≤ x) (hy : 0 ≤ y) : sqrt x ≤ sqrt y ↔ x ≤ y :=
by rw [mul_self_le_mul_self_iff (sqrt_nonneg _) (sqrt_nonneg _),
mul_self_sqrt hx, mul_self_sqrt hy]
@[simp] theorem sqrt_lt {x y : ℝ} (hx : 0 ≤ x) (hy : 0 ≤ y) : sqrt x < sqrt y ↔ x < y :=
le_iff_le_iff_lt_iff_lt.1 (sqrt_le hy hx)
@[simp] theorem sqrt_inj {x y : ℝ} (hx : 0 ≤ x) (hy : 0 ≤ y) : sqrt x = sqrt y ↔ x = y :=
by simp [le_antisymm_iff, hx, hy]
@[simp] theorem sqrt_eq_zero {x : ℝ} (h : 0 ≤ x) : sqrt x = 0 ↔ x = 0 :=
by simpa using sqrt_inj h (le_refl _)
theorem sqrt_eq_zero' {x : ℝ} : sqrt x = 0 ↔ x ≤ 0 :=
(le_total x 0).elim
(λ h, by simp [h, sqrt_eq_zero_of_nonpos])
(λ h, by simp [h]; simp [le_antisymm_iff, h])
@[simp] theorem sqrt_pos {x : ℝ} : 0 < sqrt x ↔ 0 < x :=
le_iff_le_iff_lt_iff_lt.1 (iff.trans
(by simp [le_antisymm_iff, sqrt_nonneg]) sqrt_eq_zero')
@[simp] theorem sqrt_mul' (x) {y : ℝ} (hy : 0 ≤ y) : sqrt (x * y) = sqrt x * sqrt y :=
begin
cases le_total 0 x with hx hx,
{ refine (mul_self_inj_of_nonneg _ (mul_nonneg _ _)).1 _; try {apply sqrt_nonneg},
rw [mul_self_sqrt (mul_nonneg hx hy), mul_assoc,
mul_left_comm (sqrt y), mul_self_sqrt hy, ← mul_assoc, mul_self_sqrt hx] },
{ rw [sqrt_eq_zero'.2 (mul_nonpos_of_nonpos_of_nonneg hx hy),
sqrt_eq_zero'.2 hx, zero_mul] }
end
@[simp] theorem sqrt_mul {x : ℝ} (hx : 0 ≤ x) (y : ℝ) : sqrt (x * y) = sqrt x * sqrt y :=
by rw [mul_comm, sqrt_mul' _ hx, mul_comm]
@[simp] theorem sqrt_inv (x : ℝ) : sqrt x⁻¹ = (sqrt x)⁻¹ :=
(le_or_lt x 0).elim
(λ h, by simp [sqrt_eq_zero'.2, inv_nonpos, h])
(λ h, by rw [
← mul_self_inj_of_nonneg (sqrt_nonneg _) (le_of_lt $ inv_pos $ sqrt_pos.2 h),
mul_self_sqrt (le_of_lt $ inv_pos h), ← mul_inv', mul_self_sqrt (le_of_lt h)])
@[simp] theorem sqrt_div {x : ℝ} (hx : 0 ≤ x) (y : ℝ) : sqrt (x / y) = sqrt x / sqrt y :=
by rw [division_def, sqrt_mul hx, sqrt_inv]; refl
end real
|
e3597c9b3119a44dfec806f62aa48b8acf925ce2
|
6432ea7a083ff6ba21ea17af9ee47b9c371760f7
|
/tests/lean/interactive/completionIStr.lean
|
49c205940cba3cbd7b20a422e15fe61472b711fa
|
[
"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
| 153
|
lean
|
structure C where
f1 : Nat
f2 : Bool
b1 : String
#check fun c : C => s!"testing {c. "
--^ textDocument/completion
|
f81b86d1d70f2f66d890f0547c729945343c79a9
|
367134ba5a65885e863bdc4507601606690974c1
|
/src/data/set/intervals/surj_on.lean
|
926a9847064a757a8ccd1ca8c0bcc05b60df217d
|
[
"Apache-2.0"
] |
permissive
|
kodyvajjha/mathlib
|
9bead00e90f68269a313f45f5561766cfd8d5cad
|
b98af5dd79e13a38d84438b850a2e8858ec21284
|
refs/heads/master
| 1,624,350,366,310
| 1,615,563,062,000
| 1,615,563,062,000
| 162,666,963
| 0
| 0
|
Apache-2.0
| 1,545,367,651,000
| 1,545,367,651,000
| null |
UTF-8
|
Lean
| false
| false
| 3,984
|
lean
|
/-
Copyright (c) 2020 Heather Macbeth. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Heather Macbeth
-/
import data.set.intervals.basic
import data.set.function
/-!
# Monotone surjective functions are surjective on intervals
A monotone surjective function sends any interval in the domain onto the interval with corresponding
endpoints in the range. This is expressed in this file using `set.surj_on`, and provided for all
permutations of interval endpoints.
-/
variables {α : Type*} {β : Type*} [linear_order α] [partial_order β] {f : α → β}
open set function
lemma surj_on_Ioo_of_monotone_surjective
(h_mono : monotone f) (h_surj : function.surjective f) (a b : α) :
surj_on f (Ioo a b) (Ioo (f a) (f b)) :=
begin
classical,
intros p hp,
rcases h_surj p with ⟨x, rfl⟩,
refine ⟨x, _, rfl⟩,
simp only [mem_Ioo],
by_contra h,
cases not_and_distrib.mp h with ha hb,
{ exact has_lt.lt.false (lt_of_lt_of_le hp.1 (h_mono (not_lt.mp ha))) },
{ exact has_lt.lt.false (lt_of_le_of_lt (h_mono (not_lt.mp hb)) hp.2) }
end
lemma surj_on_Ico_of_monotone_surjective
(h_mono : monotone f) (h_surj : function.surjective f) (a b : α) :
surj_on f (Ico a b) (Ico (f a) (f b)) :=
begin
rcases lt_or_ge a b with hab|hab,
{ intros p hp,
rcases mem_Ioo_or_eq_left_of_mem_Ico hp with hp'|hp',
{ rw hp',
refine ⟨a, left_mem_Ico.mpr hab, rfl⟩ },
{ have := surj_on_Ioo_of_monotone_surjective h_mono h_surj a b hp',
cases this with x hx,
exact ⟨x, Ioo_subset_Ico_self hx.1, hx.2⟩ } },
{ rw Ico_eq_empty (h_mono hab),
exact surj_on_empty f _ },
end
lemma surj_on_Ioc_of_monotone_surjective
(h_mono : monotone f) (h_surj : function.surjective f) (a b : α) :
surj_on f (Ioc a b) (Ioc (f a) (f b)) :=
begin
convert @surj_on_Ico_of_monotone_surjective _ _ _ _ _ h_mono.order_dual h_surj b a;
simp
end
-- to see that the hypothesis `a ≤ b` is necessary, consider a constant function
lemma surj_on_Icc_of_monotone_surjective
(h_mono : monotone f) (h_surj : function.surjective f) {a b : α} (hab : a ≤ b) :
surj_on f (Icc a b) (Icc (f a) (f b)) :=
begin
rcases lt_or_eq_of_le hab with hab|hab,
{ intros p hp,
rcases mem_Ioo_or_eq_endpoints_of_mem_Icc hp with hp'|⟨hp'|hp'⟩,
{ rw hp',
refine ⟨a, left_mem_Icc.mpr (le_of_lt hab), rfl⟩ },
{ rw hp',
refine ⟨b, right_mem_Icc.mpr (le_of_lt hab), rfl⟩ },
{ have := surj_on_Ioo_of_monotone_surjective h_mono h_surj a b hp',
cases this with x hx,
exact ⟨x, Ioo_subset_Icc_self hx.1, hx.2⟩ } },
{ simp only [hab, Icc_self],
intros _ hp,
exact ⟨b, mem_singleton _, (mem_singleton_iff.mp hp).symm⟩ }
end
lemma surj_on_Ioi_of_monotone_surjective
(h_mono : monotone f) (h_surj : function.surjective f) (a : α) :
surj_on f (Ioi a) (Ioi (f a)) :=
begin
classical,
intros p hp,
rcases h_surj p with ⟨x, rfl⟩,
refine ⟨x, _, rfl⟩,
simp only [mem_Ioi],
by_contra h,
exact has_lt.lt.false (lt_of_lt_of_le hp (h_mono (not_lt.mp h)))
end
lemma surj_on_Iio_of_monotone_surjective
(h_mono : monotone f) (h_surj : function.surjective f) (a : α) :
surj_on f (Iio a) (Iio (f a)) :=
@surj_on_Ioi_of_monotone_surjective _ _ _ _ _ (monotone.order_dual h_mono) h_surj a
lemma surj_on_Ici_of_monotone_surjective
(h_mono : monotone f) (h_surj : function.surjective f) (a : α) :
surj_on f (Ici a) (Ici (f a)) :=
begin
intros p hp,
rw [mem_Ici, le_iff_lt_or_eq] at hp,
rcases hp with hp'|hp',
{ cases (surj_on_Ioi_of_monotone_surjective h_mono h_surj a hp') with x hx,
exact ⟨x, Ioi_subset_Ici_self hx.1, hx.2⟩ },
{ rw ← hp',
refine ⟨a, left_mem_Ici, rfl⟩ }
end
lemma surj_on_Iic_of_monotone_surjective
(h_mono : monotone f) (h_surj : function.surjective f) (a : α) :
surj_on f (Iic a) (Iic (f a)) :=
@surj_on_Ici_of_monotone_surjective _ _ _ _ _ (monotone.order_dual h_mono) h_surj a
|
4715a457eec41383db7f9fea34370a90579e588c
|
4727251e0cd73359b15b664c3170e5d754078599
|
/src/data/polynomial/hasse_deriv.lean
|
5f3aa05c42f83a2aa9642dad03da396ce1b855e8
|
[
"Apache-2.0"
] |
permissive
|
Vierkantor/mathlib
|
0ea59ac32a3a43c93c44d70f441c4ee810ccceca
|
83bc3b9ce9b13910b57bda6b56222495ebd31c2f
|
refs/heads/master
| 1,658,323,012,449
| 1,652,256,003,000
| 1,652,256,003,000
| 209,296,341
| 0
| 1
|
Apache-2.0
| 1,568,807,655,000
| 1,568,807,655,000
| null |
UTF-8
|
Lean
| false
| false
| 10,395
|
lean
|
/-
Copyright (c) 2021 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin
-/
import algebra.polynomial.big_operators
import data.nat.choose.cast
import data.nat.choose.vandermonde
import data.polynomial.degree.lemmas
import data.polynomial.derivative
/-!
# Hasse derivative of polynomials
The `k`th Hasse derivative of a polynomial `∑ a_i X^i` is `∑ (i.choose k) a_i X^(i-k)`.
It is a variant of the usual derivative, and satisfies `k! * (hasse_deriv k f) = derivative^[k] f`.
The main benefit is that is gives an atomic way of talking about expressions such as
`(derivative^[k] f).eval r / k!`, that occur in Taylor expansions, for example.
## Main declarations
In the following, we write `D k` for the `k`-th Hasse derivative `hasse_deriv k`.
* `polynomial.hasse_deriv`: the `k`-th Hasse derivative of a polynomial
* `polynomial.hasse_deriv_zero`: the `0`th Hasse derivative is the identity
* `polynomial.hasse_deriv_one`: the `1`st Hasse derivative is the usual derivative
* `polynomial.factorial_smul_hasse_deriv`: the identity `k! • (D k f) = derivative^[k] f`
* `polynomial.hasse_deriv_comp`: the identity `(D k).comp (D l) = (k+l).choose k • D (k+l)`
* `polynomial.hasse_deriv_mul`:
the "Leibniz rule" `D k (f * g) = ∑ ij in antidiagonal k, D ij.1 f * D ij.2 g`
For the identity principle, see `polynomial.eq_zero_of_hasse_deriv_eq_zero`
in `data/polynomial/taylor.lean`.
## Reference
https://math.fontein.de/2009/08/12/the-hasse-derivative/
-/
noncomputable theory
namespace polynomial
open_locale nat big_operators polynomial
open function nat (hiding nsmul_eq_mul)
variables {R : Type*} [semiring R] (k : ℕ) (f : R[X])
/-- The `k`th Hasse derivative of a polynomial `∑ a_i X^i` is `∑ (i.choose k) a_i X^(i-k)`.
It satisfies `k! * (hasse_deriv k f) = derivative^[k] f`. -/
def hasse_deriv (k : ℕ) : R[X] →ₗ[R] R[X] :=
lsum (λ i, (monomial (i-k)) ∘ₗ distrib_mul_action.to_linear_map R R (i.choose k))
lemma hasse_deriv_apply :
hasse_deriv k f = f.sum (λ i r, monomial (i - k) (↑(i.choose k) * r)) :=
by simpa only [← nsmul_eq_mul]
lemma hasse_deriv_coeff (n : ℕ) :
(hasse_deriv k f).coeff n = (n + k).choose k * f.coeff (n + k) :=
begin
rw [hasse_deriv_apply, coeff_sum, sum_def, finset.sum_eq_single (n + k), coeff_monomial],
{ simp only [if_true, add_tsub_cancel_right, eq_self_iff_true], },
{ intros i hi hink,
rw [coeff_monomial],
by_cases hik : i < k,
{ simp only [nat.choose_eq_zero_of_lt hik, if_t_t, nat.cast_zero, zero_mul], },
{ push_neg at hik, rw if_neg, contrapose! hink,
exact (tsub_eq_iff_eq_add_of_le hik).mp hink, } },
{ intro h, simp only [not_mem_support_iff.mp h, monomial_zero_right, mul_zero, coeff_zero] }
end
lemma hasse_deriv_zero' : hasse_deriv 0 f = f :=
by simp only [hasse_deriv_apply, tsub_zero, nat.choose_zero_right,
nat.cast_one, one_mul, sum_monomial_eq]
@[simp] lemma hasse_deriv_zero : @hasse_deriv R _ 0 = linear_map.id :=
linear_map.ext $ hasse_deriv_zero'
lemma hasse_deriv_eq_zero_of_lt_nat_degree (p : R[X]) (n : ℕ)
(h : p.nat_degree < n) : hasse_deriv n p = 0 :=
begin
rw [hasse_deriv_apply, sum_def],
refine finset.sum_eq_zero (λ x hx, _),
simp [nat.choose_eq_zero_of_lt ((le_nat_degree_of_mem_supp _ hx).trans_lt h)]
end
lemma hasse_deriv_one' : hasse_deriv 1 f = derivative f :=
by simp only [hasse_deriv_apply, derivative_apply, monomial_eq_C_mul_X, nat.choose_one_right,
(nat.cast_commute _ _).eq]
@[simp] lemma hasse_deriv_one : @hasse_deriv R _ 1 = derivative :=
linear_map.ext $ hasse_deriv_one'
@[simp] lemma hasse_deriv_monomial (n : ℕ) (r : R) :
hasse_deriv k (monomial n r) = monomial (n - k) (↑(n.choose k) * r) :=
begin
ext i,
simp only [hasse_deriv_coeff, coeff_monomial],
by_cases hnik : n = i + k,
{ rw [if_pos hnik, if_pos, ← hnik], apply tsub_eq_of_eq_add_rev, rwa add_comm },
{ rw [if_neg hnik, mul_zero],
by_cases hkn : k ≤ n,
{ rw [← tsub_eq_iff_eq_add_of_le hkn] at hnik, rw [if_neg hnik] },
{ push_neg at hkn, rw [nat.choose_eq_zero_of_lt hkn, nat.cast_zero, zero_mul, if_t_t] } }
end
lemma hasse_deriv_C (r : R) (hk : 0 < k) : hasse_deriv k (C r) = 0 :=
by rw [← monomial_zero_left, hasse_deriv_monomial, nat.choose_eq_zero_of_lt hk,
nat.cast_zero, zero_mul, monomial_zero_right]
lemma hasse_deriv_apply_one (hk : 0 < k) : hasse_deriv k (1 : R[X]) = 0 :=
by rw [← C_1, hasse_deriv_C k _ hk]
lemma hasse_deriv_X (hk : 1 < k) : hasse_deriv k (X : R[X]) = 0 :=
by rw [← monomial_one_one_eq_X, hasse_deriv_monomial, nat.choose_eq_zero_of_lt hk,
nat.cast_zero, zero_mul, monomial_zero_right]
lemma factorial_smul_hasse_deriv :
⇑(k! • @hasse_deriv R _ k) = ((@derivative R _)^[k]) :=
begin
induction k with k ih,
{ rw [hasse_deriv_zero, factorial_zero, iterate_zero, one_smul, linear_map.id_coe], },
ext f n : 2,
rw [iterate_succ_apply', ← ih],
simp only [linear_map.smul_apply, coeff_smul, linear_map.map_smul_of_tower, coeff_derivative,
hasse_deriv_coeff, ← @choose_symm_add _ k],
simp only [nsmul_eq_mul, factorial_succ, mul_assoc, succ_eq_add_one, ← add_assoc,
add_right_comm n 1 k, ← cast_succ],
rw ← (cast_commute (n+1) (f.coeff (n + k + 1))).eq,
simp only [← mul_assoc], norm_cast, congr' 2,
apply @cast_injective ℚ,
have h1 : n + 1 ≤ n + k + 1 := succ_le_succ le_self_add,
have h2 : k + 1 ≤ n + k + 1 := succ_le_succ le_add_self,
have H : ∀ (n : ℕ), (n! : ℚ) ≠ 0, { exact_mod_cast factorial_ne_zero },
-- why can't `field_simp` help me here?
simp only [cast_mul, cast_choose ℚ, h1, h2, -one_div, -mul_eq_zero,
succ_sub_succ_eq_sub, add_tsub_cancel_right, add_tsub_cancel_left] with field_simps,
rw [eq_div_iff_mul_eq (mul_ne_zero (H _) (H _)), eq_comm, div_mul_eq_mul_div,
eq_div_iff_mul_eq (mul_ne_zero (H _) (H _))],
norm_cast,
simp only [factorial_succ, succ_eq_add_one], ring,
end
lemma hasse_deriv_comp (k l : ℕ) :
(@hasse_deriv R _ k).comp (hasse_deriv l) = (k+l).choose k • hasse_deriv (k+l) :=
begin
ext i : 2,
simp only [linear_map.smul_apply, comp_app, linear_map.coe_comp, smul_monomial,
hasse_deriv_apply, mul_one, monomial_eq_zero_iff, sum_monomial_index, mul_zero,
← tsub_add_eq_tsub_tsub, add_comm l k],
rw_mod_cast nsmul_eq_mul,
congr' 2,
by_cases hikl : i < k + l,
{ rw [choose_eq_zero_of_lt hikl, mul_zero],
by_cases hil : i < l,
{ rw [choose_eq_zero_of_lt hil, mul_zero] },
{ push_neg at hil, rw [← tsub_lt_iff_right hil] at hikl,
rw [choose_eq_zero_of_lt hikl , zero_mul], }, },
push_neg at hikl, apply @cast_injective ℚ,
have h1 : l ≤ i := nat.le_of_add_le_right hikl,
have h2 : k ≤ i - l := le_tsub_of_add_le_right hikl,
have h3 : k ≤ k + l := le_self_add,
have H : ∀ (n : ℕ), (n! : ℚ) ≠ 0, { exact_mod_cast factorial_ne_zero },
-- why can't `field_simp` help me here?
simp only [cast_mul, cast_choose ℚ, h1, h2, h3, hikl, -one_div, -mul_eq_zero,
succ_sub_succ_eq_sub, add_tsub_cancel_right, add_tsub_cancel_left] with field_simps,
rw [eq_div_iff_mul_eq, eq_comm, div_mul_eq_mul_div, eq_div_iff_mul_eq, ← tsub_add_eq_tsub_tsub,
add_comm l k],
{ ring, },
all_goals { apply_rules [mul_ne_zero, H] }
end
lemma nat_degree_hasse_deriv_le (p : R[X]) (n : ℕ) :
nat_degree (hasse_deriv n p) ≤ nat_degree p - n :=
begin
classical,
rw [hasse_deriv_apply, sum_def],
refine (nat_degree_sum_le _ _).trans _,
simp_rw [function.comp, nat_degree_monomial],
rw [finset.fold_ite, finset.fold_const],
{ simp only [if_t_t, max_eq_right, zero_le', finset.fold_max_le, true_and, and_imp,
tsub_le_iff_right, mem_support_iff, ne.def, finset.mem_filter],
intros x hx hx',
have hxp : x ≤ p.nat_degree := le_nat_degree_of_ne_zero hx,
have hxn : n ≤ x,
{ contrapose! hx',
simp [nat.choose_eq_zero_of_lt hx'] },
rwa [tsub_add_cancel_of_le (hxn.trans hxp)] },
{ simp }
end
lemma nat_degree_hasse_deriv [no_zero_smul_divisors ℕ R] (p : R[X]) (n : ℕ) :
nat_degree (hasse_deriv n p) = nat_degree p - n :=
begin
cases lt_or_le p.nat_degree n with hn hn,
{ simpa [hasse_deriv_eq_zero_of_lt_nat_degree, hn] using (tsub_eq_zero_of_le hn.le).symm },
{ refine map_nat_degree_eq_sub _ _,
{ exact λ h, hasse_deriv_eq_zero_of_lt_nat_degree _ _ },
{ classical,
simp only [ite_eq_right_iff, ne.def, nat_degree_monomial, hasse_deriv_monomial],
intros k c c0 hh,
-- this is where we use the `smul_eq_zero` from `no_zero_smul_divisors`
rw [←nsmul_eq_mul, smul_eq_zero, nat.choose_eq_zero_iff] at hh,
exact (tsub_eq_zero_of_le (or.resolve_right hh c0).le).symm } }
end
section
open add_monoid_hom finset.nat
lemma hasse_deriv_mul (f g : R[X]) :
hasse_deriv k (f * g) = ∑ ij in antidiagonal k, hasse_deriv ij.1 f * hasse_deriv ij.2 g :=
begin
let D := λ k, (@hasse_deriv R _ k).to_add_monoid_hom,
let Φ := @add_monoid_hom.mul R[X] _,
show (comp_hom (D k)).comp Φ f g =
∑ (ij : ℕ × ℕ) in antidiagonal k, ((comp_hom.comp ((comp_hom Φ) (D ij.1))).flip (D ij.2) f) g,
simp only [← finset_sum_apply],
congr' 2, clear f g,
ext m r n s : 4,
simp only [finset_sum_apply, coe_mul_left, coe_comp, flip_apply, comp_app,
hasse_deriv_monomial, linear_map.to_add_monoid_hom_coe, comp_hom_apply_apply, coe_mul,
monomial_mul_monomial],
have aux : ∀ (x : ℕ × ℕ), x ∈ antidiagonal k →
monomial (m - x.1 + (n - x.2)) (↑(m.choose x.1) * r * (↑(n.choose x.2) * s)) =
monomial (m + n - k) (↑(m.choose x.1) * ↑(n.choose x.2) * (r * s)),
{ intros x hx, rw [finset.nat.mem_antidiagonal] at hx, subst hx,
by_cases hm : m < x.1,
{ simp only [nat.choose_eq_zero_of_lt hm, nat.cast_zero, zero_mul, monomial_zero_right], },
by_cases hn : n < x.2,
{ simp only [nat.choose_eq_zero_of_lt hn, nat.cast_zero,
zero_mul, mul_zero, monomial_zero_right], },
push_neg at hm hn,
rw [tsub_add_eq_add_tsub hm, ← add_tsub_assoc_of_le hn, ← tsub_add_eq_tsub_tsub,
add_comm x.2 x.1, mul_assoc, ← mul_assoc r, ← (nat.cast_commute _ r).eq, mul_assoc,
mul_assoc], },
conv_rhs { apply_congr, skip, rw aux _ H, },
rw_mod_cast [← linear_map.map_sum, ← finset.sum_mul, ← nat.add_choose_eq],
end
end
end polynomial
|
cc8073cddc007f37ccd6f72ecca8c8640650fc0c
|
fa02ed5a3c9c0adee3c26887a16855e7841c668b
|
/src/topology/sheaves/sheaf_condition/opens_le_cover.lean
|
2a982b84618e885d4e3481c35d97305cb41e3272
|
[
"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
| 9,602
|
lean
|
/-
Copyright (c) 2020 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import topology.sheaves.presheaf
import category_theory.limits.cofinal
import topology.sheaves.sheaf_condition.pairwise_intersections
/-!
# Another version of the sheaf condition.
Given a family of open sets `U : ι → opens X` we can form the subcategory
`{ V : opens X // ∃ i, V ≤ U i }`, which has `supr U` as a cocone.
The sheaf condition on a presheaf `F` is equivalent to
`F` sending the opposite of this cocone to a limit cone in `C`, for every `U`.
This condition is particularly nice when checking the sheaf condition
because we don't need to do any case bashing
(depending on whether we're looking at single or double intersections,
or equivalently whether we're looking at the first or second object in an equalizer diagram).
## References
* This is the definition Lurie uses in [Spectral Algebraic Geometry][LurieSAG].
-/
universes v u
noncomputable theory
open category_theory
open category_theory.limits
open topological_space
open opposite
open topological_space.opens
namespace Top
variables {C : Type u} [category.{v} C]
variables {X : Top.{v}} (F : presheaf C X) {ι : Type v} (U : ι → opens X)
namespace presheaf
namespace sheaf_condition
/--
The category of open sets contained in some element of the cover.
-/
def opens_le_cover : Type v := { V : opens X // ∃ i, V ≤ U i }
instance [inhabited ι] : inhabited (opens_le_cover U) :=
⟨⟨⊥, default ι, bot_le⟩⟩
instance : category (opens_le_cover U) := category_theory.full_subcategory _
namespace opens_le_cover
variables {U}
/--
An arbitrarily chosen index such that `V ≤ U i`.
-/
def index (V : opens_le_cover U) : ι := V.property.some
/--
The morphism from `V` to `U i` for some `i`.
-/
def hom_to_index (V : opens_le_cover U) : V.val ⟶ U (index V) :=
(V.property.some_spec).hom
end opens_le_cover
/--
`supr U` as a cocone over the opens sets contained in some element of the cover.
(In fact this is a colimit cocone.)
-/
def opens_le_cover_cocone : cocone (full_subcategory_inclusion _ : opens_le_cover U ⥤ opens X) :=
{ X := supr U,
ι := { app := λ V : opens_le_cover U, V.hom_to_index ≫ opens.le_supr U _, } }
end sheaf_condition
open sheaf_condition
/--
An equivalent formulation of the sheaf condition
(which we prove equivalent to the usual one below as
`sheaf_condition_equiv_sheaf_condition_opens_le_cover`).
A presheaf is a sheaf if `F` sends the cone `(opens_le_cover_cocone U).op` to a limit cone.
(Recall `opens_le_cover_cocone U`, has cone point `supr U`,
mapping down to any `V` which is contained in some `U i`.)
-/
@[derive subsingleton, nolint has_inhabited_instance]
def sheaf_condition_opens_le_cover : Type (max u (v+1)) :=
Π ⦃ι : Type v⦄ (U : ι → opens X), is_limit (F.map_cone (opens_le_cover_cocone U).op)
namespace sheaf_condition
open category_theory.pairwise
/--
Implementation detail:
the object level of `pairwise_to_opens_le_cover : pairwise ι ⥤ opens_le_cover U`
-/
@[simp]
def pairwise_to_opens_le_cover_obj : pairwise ι → opens_le_cover U
| (single i) := ⟨U i, ⟨i, le_refl _⟩⟩
| (pair i j) := ⟨U i ⊓ U j, ⟨i, inf_le_left⟩⟩
open category_theory.pairwise.hom
/--
Implementation detail:
the morphism level of `pairwise_to_opens_le_cover : pairwise ι ⥤ opens_le_cover U`
-/
def pairwise_to_opens_le_cover_map :
Π {V W : pairwise ι},
(V ⟶ W) → (pairwise_to_opens_le_cover_obj U V ⟶ pairwise_to_opens_le_cover_obj U W)
| _ _ (id_single i) := 𝟙 _
| _ _ (id_pair i j) := 𝟙 _
| _ _ (left i j) := hom_of_le inf_le_left
| _ _ (right i j) := hom_of_le inf_le_right
/--
The category of single and double intersections of the `U i` maps into the category
of open sets below some `U i`.
-/
@[simps]
def pairwise_to_opens_le_cover : pairwise ι ⥤ opens_le_cover U :=
{ obj := pairwise_to_opens_le_cover_obj U,
map := λ V W i, pairwise_to_opens_le_cover_map U i, }
instance (V : opens_le_cover U) :
nonempty (structured_arrow V (pairwise_to_opens_le_cover U)) :=
⟨{ right := single (V.index), hom := V.hom_to_index }⟩
/--
The diagram consisting of the `U i` and `U i ⊓ U j` is cofinal in the diagram
of all opens contained in some `U i`.
-/
-- This is a case bash: for each pair of types of objects in `pairwise ι`,
-- we have to explicitly construct a zigzag.
instance : cofinal (pairwise_to_opens_le_cover U) :=
⟨λ V, is_connected_of_zigzag $ λ A B, begin
rcases A with ⟨⟨⟩, ⟨i⟩|⟨i,j⟩, a⟩;
rcases B with ⟨⟨⟩, ⟨i'⟩|⟨i',j'⟩, b⟩;
dsimp at *,
{ refine ⟨[
{ left := punit.star, right := pair i i',
hom := (le_inf a.le b.le).hom, }, _], _, rfl⟩,
exact
list.chain.cons (or.inr ⟨{ left := 𝟙 _, right := left i i', }⟩)
(list.chain.cons (or.inl ⟨{ left := 𝟙 _, right := right i i', }⟩) list.chain.nil) },
{ refine ⟨[
{ left := punit.star, right := pair i' i,
hom := (le_inf (b.le.trans inf_le_left) a.le).hom, },
{ left := punit.star, right := single i',
hom := (b.le.trans inf_le_left).hom, }, _], _, rfl⟩,
exact
list.chain.cons (or.inr ⟨{ left := 𝟙 _, right := right i' i, }⟩)
(list.chain.cons (or.inl ⟨{ left := 𝟙 _, right := left i' i, }⟩)
(list.chain.cons (or.inr ⟨{ left := 𝟙 _, right := left i' j', }⟩) list.chain.nil)) },
{ refine ⟨[
{ left := punit.star, right := single i,
hom := (a.le.trans inf_le_left).hom, },
{ left := punit.star, right := pair i i', hom :=
(le_inf (a.le.trans inf_le_left) b.le).hom, }, _], _, rfl⟩,
exact
list.chain.cons (or.inl ⟨{ left := 𝟙 _, right := left i j, }⟩)
(list.chain.cons (or.inr ⟨{ left := 𝟙 _, right := left i i', }⟩)
(list.chain.cons (or.inl ⟨{ left := 𝟙 _, right := right i i', }⟩) list.chain.nil)) },
{ refine ⟨[
{ left := punit.star, right := single i,
hom := (a.le.trans inf_le_left).hom, },
{ left := punit.star, right := pair i i',
hom := (le_inf (a.le.trans inf_le_left) (b.le.trans inf_le_left)).hom, },
{ left := punit.star, right := single i',
hom := (b.le.trans inf_le_left).hom, }, _], _, rfl⟩,
exact
list.chain.cons (or.inl ⟨{ left := 𝟙 _, right := left i j, }⟩)
(list.chain.cons (or.inr ⟨{ left := 𝟙 _, right := left i i', }⟩)
(list.chain.cons (or.inl ⟨{ left := 𝟙 _, right := right i i', }⟩)
(list.chain.cons (or.inr ⟨{ left := 𝟙 _, right := left i' j', }⟩) list.chain.nil))), },
end⟩
/--
The diagram in `opens X` indexed by pairwise intersections from `U` is isomorphic
(in fact, equal) to the diagram factored through `opens_le_cover U`.
-/
def pairwise_diagram_iso :
pairwise.diagram U ≅
pairwise_to_opens_le_cover U ⋙ full_subcategory_inclusion _ :=
{ hom := { app := begin rintro (i|⟨i,j⟩); exact 𝟙 _, end, },
inv := { app := begin rintro (i|⟨i,j⟩); exact 𝟙 _, end, }, }
/--
The cocone `pairwise.cocone U` with cocone point `supr U` over `pairwise.diagram U` is isomorphic
to the cocone `opens_le_cover_cocone U` (with the same cocone point)
after appropriate whiskering and postcomposition.
-/
def pairwise_cocone_iso :
(pairwise.cocone U).op ≅
(cones.postcompose_equivalence (nat_iso.op (pairwise_diagram_iso U : _) : _)).functor.obj
((opens_le_cover_cocone U).op.whisker (pairwise_to_opens_le_cover U).op) :=
cones.ext (iso.refl _) (by tidy)
end sheaf_condition
open sheaf_condition
/--
The sheaf condition
in terms of a limit diagram over all `{ V : opens X // ∃ i, V ≤ U i }`
is equivalent to the reformulation
in terms of a limit diagram over `U i` and `U i ⊓ U j`.
-/
def sheaf_condition_opens_le_cover_equiv_sheaf_condition_pairwise_intersections (F : presheaf C X) :
F.sheaf_condition_opens_le_cover ≃ F.sheaf_condition_pairwise_intersections :=
equiv.Pi_congr_right $ λ ι, equiv.Pi_congr_right $ λ U,
calc is_limit (F.map_cone (opens_le_cover_cocone U).op)
≃ is_limit ((F.map_cone (opens_le_cover_cocone U).op).whisker (pairwise_to_opens_le_cover U).op)
: (cofinal.is_limit_whisker_equiv (pairwise_to_opens_le_cover U) _).symm
... ≃ is_limit (F.map_cone ((opens_le_cover_cocone U).op.whisker (pairwise_to_opens_le_cover U).op))
: is_limit.equiv_iso_limit F.map_cone_whisker.symm
... ≃ is_limit ((cones.postcompose_equivalence _).functor.obj
(F.map_cone ((opens_le_cover_cocone U).op.whisker (pairwise_to_opens_le_cover U).op)))
: (is_limit.postcompose_hom_equiv _ _).symm
... ≃ is_limit (F.map_cone ((cones.postcompose_equivalence _).functor.obj
((opens_le_cover_cocone U).op.whisker (pairwise_to_opens_le_cover U).op)))
: is_limit.equiv_iso_limit (functor.map_cone_postcompose_equivalence_functor _).symm
... ≃ is_limit (F.map_cone (pairwise.cocone U).op)
: is_limit.equiv_iso_limit
((cones.functoriality _ _).map_iso (pairwise_cocone_iso U : _).symm)
variables [has_products C]
/--
The sheaf condition in terms of an equalizer diagram is equivalent
to the reformulation in terms of a limit diagram over all `{ V : opens X // ∃ i, V ≤ U i }`.
-/
def sheaf_condition_equiv_sheaf_condition_opens_le_cover (F : presheaf C X) :
F.sheaf_condition ≃ F.sheaf_condition_opens_le_cover :=
equiv.trans
(sheaf_condition_equiv_sheaf_condition_pairwise_intersections F)
(sheaf_condition_opens_le_cover_equiv_sheaf_condition_pairwise_intersections F).symm
end presheaf
end Top
|
6d6b13086467737fbad7321549ab19b2a76aff00
|
cf39355caa609c0f33405126beee2739aa3cb77e
|
/tests/lean/red.lean
|
db62a23c8845da5d04d1c4510ed5115e938c151c
|
[
"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
| 486
|
lean
|
constant g : nat → nat
noncomputable definition f := g
example : f = g := rfl
attribute [irreducible] f
example : f = g := rfl -- Error
example (a : nat) (H : a = g a) : f a = a :=
eq.subst H rfl -- Error
attribute [semireducible] f
example (a : nat) (H : a = g a) : f a = a :=
eq.subst H rfl -- Error
example : f = g := rfl
attribute [reducible] f
example : f = g := rfl
example (a : nat) (H : a = g a) : f a = a :=
@@eq.subst (λ x, f a = x) (eq.symm H) (eq.refl (f a))
|
3f2523a98587749e2fd90efb3b63f5f2edf3646f
|
64874bd1010548c7f5a6e3e8902efa63baaff785
|
/tests/lean/shadow.lean
|
dc54137f3e93a2be851a1f230d508c26280b9202
|
[
"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
| 202
|
lean
|
open nat
variable a : nat
-- The variable 'a' in the following definition is not the variable 'a' above
definition tadd : nat → nat → nat,
tadd zero b := b,
tadd (succ a) b := succ (tadd a b)
|
f664d6573a772cca96e34cf9c02ebc4fa6b5462f
|
95dcf8dea2baf2b4b0a60d438f27c35ae3dd3990
|
/src/category_theory/opposites.lean
|
c09fadbca9c0e073585f9e411b4ae67a16769c04
|
[
"Apache-2.0"
] |
permissive
|
uniformity1/mathlib
|
829341bad9dfa6d6be9adaacb8086a8a492e85a4
|
dd0e9bd8f2e5ec267f68e72336f6973311909105
|
refs/heads/master
| 1,588,592,015,670
| 1,554,219,842,000
| 1,554,219,842,000
| 179,110,702
| 0
| 0
|
Apache-2.0
| 1,554,220,076,000
| 1,554,220,076,000
| null |
UTF-8
|
Lean
| false
| false
| 7,369
|
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
import category_theory.types
namespace category_theory
universes v₁ v₂ u₁ u₂ -- declare the `v`'s first; see `category_theory.category` for an explanation
/-- The type of objects of the opposite of C (which should be a category).
In order to avoid confusion between C and its opposite category, we
set up the type of objects `opposite C` using the following pattern,
which will be repeated later for the morphisms.
1. Define `opposite C := C`.
2. Define the isomorphisms `op : C → opposite C`, `unop : opposite C → C`.
3. Make the definition `opposite` irreducible.
This has the following consequences.
* `opposite C` and `C` are distinct types in the elaborator, so you
must use `op` and `unop` explicitly to convert between them.
* Both `unop (op X) = X` and `op (unop X) = X` are definitional
equalities. Notably, every object of the opposite category is
definitionally of the form `op X`, which greatly simplifies the
definition of the structure of the opposite category, for example.
(If Lean supported definitional eta equality for records, we could
achieve the same goals using a structure with one field.)
-/
def opposite (C : Sort u₁) : Sort u₁ := C
-- Use a high right binding power (like that of postfix ⁻¹) so that, for example,
-- `presheaf Cᵒᵖ` parses as `presheaf (Cᵒᵖ)` and not `(presheaf C)ᵒᵖ`.
notation C `ᵒᵖ`:std.prec.max_plus := opposite C
variables {C : Sort u₁}
def op (X : C) : Cᵒᵖ := X
def unop (X : Cᵒᵖ) : C := X
attribute [irreducible] opposite
@[simp] lemma unop_op (X : C) : unop (op X) = X := rfl
@[simp] lemma op_unop (X : Cᵒᵖ) : op (unop X) = X := rfl
lemma op_inj : function.injective (@op C) :=
by { rintros _ _ ⟨ ⟩, refl }
lemma unop_inj : function.injective (@unop C) :=
by { rintros _ _ ⟨ ⟩, refl }
section has_hom
variables [𝒞 : has_hom.{v₁} C]
include 𝒞
/-- The hom types of the opposite of a category (or graph).
As with the objects, we'll make this irreducible below.
Use `f.op` and `f.unop` to convert between morphisms of C
and morphisms of Cᵒᵖ.
-/
instance has_hom.opposite : has_hom Cᵒᵖ :=
{ hom := λ X Y, unop Y ⟶ unop X }
def has_hom.hom.op {X Y : C} (f : X ⟶ Y) : op Y ⟶ op X := f
def has_hom.hom.unop {X Y : Cᵒᵖ} (f : X ⟶ Y) : unop Y ⟶ unop X := f
attribute [irreducible] has_hom.opposite
lemma has_hom.hom.op_inj {X Y : C} :
function.injective (has_hom.hom.op : (X ⟶ Y) → (op Y ⟶ op X)) :=
λ _ _ H, congr_arg has_hom.hom.unop H
lemma has_hom.hom.unop_inj {X Y : Cᵒᵖ} :
function.injective (has_hom.hom.unop : (X ⟶ Y) → (unop Y ⟶ unop X)) :=
λ _ _ H, congr_arg has_hom.hom.op H
@[simp] lemma has_hom.hom.unop_op {X Y : C} {f : X ⟶ Y} : f.op.unop = f := rfl
@[simp] lemma has_hom.hom.op_unop {X Y : Cᵒᵖ} {f : X ⟶ Y} : f.unop.op = f := rfl
end has_hom
variables [𝒞 : category.{v₁} C]
include 𝒞
instance category.opposite : category.{v₁} Cᵒᵖ :=
{ comp := λ _ _ _ f g, (g.unop ≫ f.unop).op,
id := λ X, (𝟙 (unop X)).op }
@[simp] lemma op_comp {X Y Z : C} {f : X ⟶ Y} {g : Y ⟶ Z} :
(f ≫ g).op = g.op ≫ f.op := rfl
@[simp] lemma op_id {X : C} : (𝟙 X).op = 𝟙 (op X) := rfl
@[simp] lemma unop_comp {X Y Z : Cᵒᵖ} {f : X ⟶ Y} {g : Y ⟶ Z} :
(f ≫ g).unop = g.unop ≫ f.unop := rfl
@[simp] lemma unop_id {X : Cᵒᵖ} : (𝟙 X).unop = 𝟙 (unop X) := rfl
def op_op : (Cᵒᵖ)ᵒᵖ ⥤ C :=
{ obj := λ X, unop (unop X),
map := λ X Y f, f.unop.unop }
-- TODO this is an equivalence
namespace functor
section
variables {D : Sort u₂} [𝒟 : category.{v₂} D]
include 𝒟
variables {C D}
protected definition op (F : C ⥤ D) : Cᵒᵖ ⥤ Dᵒᵖ :=
{ obj := λ X, op (F.obj (unop X)),
map := λ X Y f, (F.map f.unop).op }
@[simp] lemma op_obj (F : C ⥤ D) (X : Cᵒᵖ) : (F.op).obj X = op (F.obj (unop X)) := rfl
@[simp] lemma op_map (F : C ⥤ D) {X Y : Cᵒᵖ} (f : X ⟶ Y) : (F.op).map f = (F.map f.unop).op := rfl
protected definition unop (F : Cᵒᵖ ⥤ Dᵒᵖ) : C ⥤ D :=
{ obj := λ X, unop (F.obj (op X)),
map := λ X Y f, (F.map f.op).unop }
@[simp] lemma unop_obj (F : Cᵒᵖ ⥤ Dᵒᵖ) (X : C) : (F.unop).obj X = unop (F.obj (op X)) := rfl
@[simp] lemma unop_map (F : Cᵒᵖ ⥤ Dᵒᵖ) {X Y : C} (f : X ⟶ Y) : (F.unop).map f = (F.map f.op).unop := rfl
variables (C D)
definition op_hom : (C ⥤ D)ᵒᵖ ⥤ (Cᵒᵖ ⥤ Dᵒᵖ) :=
{ obj := λ F, (unop F).op,
map := λ F G α,
{ app := λ X, (α.unop.app (unop X)).op,
naturality' := λ X Y f, has_hom.hom.unop_inj $ eq.symm (α.unop.naturality f.unop) } }
@[simp] lemma op_hom.obj (F : (C ⥤ D)ᵒᵖ) : (op_hom C D).obj F = (unop F).op := rfl
@[simp] lemma op_hom.map_app {F G : (C ⥤ D)ᵒᵖ} (α : F ⟶ G) (X : Cᵒᵖ) :
((op_hom C D).map α).app X = (α.unop.app (unop X)).op := rfl
definition op_inv : (Cᵒᵖ ⥤ Dᵒᵖ) ⥤ (C ⥤ D)ᵒᵖ :=
{ obj := λ F, op F.unop,
map := λ F G α, has_hom.hom.op
{ app := λ X, (α.app (op X)).unop,
naturality' := λ X Y f, has_hom.hom.op_inj $ eq.symm (α.naturality f.op) } }
@[simp] lemma op_inv.obj (F : Cᵒᵖ ⥤ Dᵒᵖ) : (op_inv C D).obj F = op F.unop := rfl
@[simp] lemma op_inv.map_app {F G : Cᵒᵖ ⥤ Dᵒᵖ} (α : F ⟶ G) (X : C) :
(((op_inv C D).map α).unop).app X = (α.app (op X)).unop := rfl
-- TODO show these form an equivalence
instance {F : C ⥤ D} [full F] : full F.op :=
{ preimage := λ X Y f, (F.preimage f.unop).op }
instance {F : C ⥤ D} [faithful F] : faithful F.op :=
{ injectivity' := λ X Y f g h,
has_hom.hom.unop_inj $ by simpa using injectivity F (has_hom.hom.op_inj h) }
end
section
omit 𝒞
variables (E : Type u₁) [ℰ : category.{v₁+1} E]
include ℰ
/-- `functor.hom` is the hom-pairing, sending (X,Y) to X → Y, contravariant in X and covariant in Y. -/
definition hom : Eᵒᵖ × E ⥤ Type v₁ :=
{ obj := λ p, unop p.1 ⟶ p.2,
map := λ X Y f, λ h, f.1.unop ≫ h ≫ f.2 }
@[simp] lemma hom_obj (X : Eᵒᵖ × E) : (functor.hom E).obj X = (unop X.1 ⟶ X.2) := rfl
@[simp] lemma hom_pairing_map {X Y : Eᵒᵖ × E} (f : X ⟶ Y) :
(functor.hom E).map f = λ h, f.1.unop ≫ h ≫ f.2 := rfl
end
end functor
-- TODO the following definitions do not belong here
omit 𝒞
variables (E : Type u₁)
instance opposite.has_one [has_one E] : has_one (Eᵒᵖ) :=
{ one := op 1 }
instance opposite.has_mul [has_mul E] : has_mul (Eᵒᵖ) :=
{ mul := λ x y, op $ unop y * unop x }
@[simp] lemma opposite.unop_one [has_one E] : unop (1 : Eᵒᵖ) = (1 : E) := rfl
@[simp] lemma opposite.unop_mul [has_mul E] (xs ys : Eᵒᵖ) : unop (xs * ys) = (unop ys * unop xs : E) := rfl
@[simp] lemma opposite.op_one [has_one E] : op (1 : E) = 1 := rfl
@[simp] lemma opposite.op_mul [has_mul E] (xs ys : E) : op (xs * ys) = (op ys * op xs) := rfl
instance opposite.monoid [monoid E] : monoid (Eᵒᵖ) :=
{ one := op 1,
mul := λ x y, op $ unop y * unop x,
mul_one := by { intros, apply unop_inj, simp },
one_mul := by { intros, simp },
mul_assoc := by { intros, simp [mul_assoc], } }
end category_theory
|
075af6f67a1d2adfb0e175da7eb771a6940be8b8
|
947fa6c38e48771ae886239b4edce6db6e18d0fb
|
/src/field_theory/intermediate_field.lean
|
37afbfec245a71d74f99ca7792009bf8166c5b8d
|
[
"Apache-2.0"
] |
permissive
|
ramonfmir/mathlib
|
c5dc8b33155473fab97c38bd3aa6723dc289beaa
|
14c52e990c17f5a00c0cc9e09847af16fabbed25
|
refs/heads/master
| 1,661,979,343,526
| 1,660,830,384,000
| 1,660,830,384,000
| 182,072,989
| 0
| 0
| null | 1,555,585,876,000
| 1,555,585,876,000
| null |
UTF-8
|
Lean
| false
| false
| 21,913
|
lean
|
/-
Copyright (c) 2020 Anne Baanen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anne Baanen
-/
import field_theory.minpoly
import field_theory.subfield
import field_theory.tower
/-!
# Intermediate fields
Let `L / K` be a field extension, given as an instance `algebra K L`.
This file defines the type of fields in between `K` and `L`, `intermediate_field K L`.
An `intermediate_field K L` is a subfield of `L` which contains (the image of) `K`,
i.e. it is a `subfield L` and a `subalgebra K L`.
## Main definitions
* `intermediate_field K L` : the type of intermediate fields between `K` and `L`.
* `subalgebra.to_intermediate_field`: turns a subalgebra closed under `⁻¹`
into an intermediate field
* `subfield.to_intermediate_field`: turns a subfield containing the image of `K`
into an intermediate field
* `intermediate_field.map`: map an intermediate field along an `alg_hom`
* `intermediate_field.restrict_scalars`: restrict the scalars of an intermediate field to a smaller
field in a tower of fields.
## Implementation notes
Intermediate fields are defined with a structure extending `subfield` and `subalgebra`.
A `subalgebra` is closed under all operations except `⁻¹`,
## Tags
intermediate field, field extension
-/
open finite_dimensional polynomial
open_locale big_operators polynomial
variables (K L L' : Type*) [field K] [field L] [field L'] [algebra K L] [algebra K L']
/-- `S : intermediate_field K L` is a subset of `L` such that there is a field
tower `L / S / K`. -/
structure intermediate_field extends subalgebra K L :=
(neg_mem' : ∀ x ∈ carrier, -x ∈ carrier)
(inv_mem' : ∀ x ∈ carrier, x⁻¹ ∈ carrier)
/-- Reinterpret an `intermediate_field` as a `subalgebra`. -/
add_decl_doc intermediate_field.to_subalgebra
variables {K L L'} (S : intermediate_field K L)
namespace intermediate_field
/-- Reinterpret an `intermediate_field` as a `subfield`. -/
def to_subfield : subfield L := { ..S.to_subalgebra, ..S }
instance : set_like (intermediate_field K L) L :=
⟨λ S, S.to_subalgebra.carrier, by { rintros ⟨⟨⟩⟩ ⟨⟨⟩⟩ ⟨h⟩, congr, }⟩
instance : subfield_class (intermediate_field K L) L :=
{ add_mem := λ s, s.add_mem',
zero_mem := λ s, s.zero_mem',
neg_mem := neg_mem',
mul_mem := λ s, s.mul_mem',
one_mem := λ s, s.one_mem',
inv_mem := inv_mem' }
@[simp]
lemma mem_carrier {s : intermediate_field K L} {x : L} : x ∈ s.carrier ↔ x ∈ s := iff.rfl
/-- Two intermediate fields are equal if they have the same elements. -/
@[ext] theorem ext {S T : intermediate_field K L} (h : ∀ x, x ∈ S ↔ x ∈ T) : S = T :=
set_like.ext h
@[simp] lemma coe_to_subalgebra : (S.to_subalgebra : set L) = S := rfl
@[simp] lemma coe_to_subfield : (S.to_subfield : set L) = S := rfl
@[simp] lemma mem_mk (s : set L) (hK : ∀ x, algebra_map K L x ∈ s)
(ho hm hz ha hn hi) (x : L) :
x ∈ intermediate_field.mk (subalgebra.mk s ho hm hz ha hK) hn hi ↔ x ∈ s := iff.rfl
@[simp] lemma mem_to_subalgebra (s : intermediate_field K L) (x : L) :
x ∈ s.to_subalgebra ↔ x ∈ s := iff.rfl
@[simp] lemma mem_to_subfield (s : intermediate_field K L) (x : L) :
x ∈ s.to_subfield ↔ x ∈ s := iff.rfl
/-- Copy of an intermediate field with a new `carrier` equal to the old one. Useful to fix
definitional equalities. -/
protected def copy (S : intermediate_field K L) (s : set L) (hs : s = ↑S) :
intermediate_field K L :=
{ to_subalgebra := S.to_subalgebra.copy s (hs : s = (S.to_subalgebra).carrier),
neg_mem' :=
have hs' : (S.to_subalgebra.copy s hs).carrier = (S.to_subalgebra).carrier := hs,
hs'.symm ▸ S.neg_mem',
inv_mem' :=
have hs' : (S.to_subalgebra.copy s hs).carrier = (S.to_subalgebra).carrier := hs,
hs'.symm ▸ S.inv_mem' }
@[simp] lemma coe_copy (S : intermediate_field K L) (s : set L) (hs : s = ↑S) :
(S.copy s hs : set L) = s := rfl
lemma copy_eq (S : intermediate_field K L) (s : set L) (hs : s = ↑S) : S.copy s hs = S :=
set_like.coe_injective hs
section inherited_lemmas
/-! ### Lemmas inherited from more general structures
The declarations in this section derive from the fact that an `intermediate_field` is also a
subalgebra or subfield. Their use should be replaceable with the corresponding lemma from a
subobject class.
-/
/-- An intermediate field contains the image of the smaller field. -/
theorem algebra_map_mem (x : K) : algebra_map K L x ∈ S :=
S.algebra_map_mem' x
/-- An intermediate field is closed under scalar multiplication. -/
theorem smul_mem {y : L} : y ∈ S → ∀ {x : K}, x • y ∈ S := S.to_subalgebra.smul_mem
/-- An intermediate field contains the ring's 1. -/
protected theorem one_mem : (1 : L) ∈ S := one_mem S
/-- An intermediate field contains the ring's 0. -/
protected theorem zero_mem : (0 : L) ∈ S := zero_mem S
/-- An intermediate field is closed under multiplication. -/
protected theorem mul_mem {x y : L} : x ∈ S → y ∈ S → x * y ∈ S := mul_mem
/-- An intermediate field is closed under addition. -/
protected theorem add_mem {x y : L} : x ∈ S → y ∈ S → x + y ∈ S := add_mem
/-- An intermediate field is closed under subtraction -/
protected theorem sub_mem {x y : L} : x ∈ S → y ∈ S → x - y ∈ S := sub_mem
/-- An intermediate field is closed under negation. -/
protected theorem neg_mem {x : L} : x ∈ S → -x ∈ S := neg_mem
/-- An intermediate field is closed under inverses. -/
protected theorem inv_mem {x : L} : x ∈ S → x⁻¹ ∈ S := inv_mem
/-- An intermediate field is closed under division. -/
protected theorem div_mem {x y : L} : x ∈ S → y ∈ S → x / y ∈ S := div_mem
/-- Product of a list of elements in an intermediate_field is in the intermediate_field. -/
protected lemma list_prod_mem {l : list L} : (∀ x ∈ l, x ∈ S) → l.prod ∈ S := list_prod_mem
/-- Sum of a list of elements in an intermediate field is in the intermediate_field. -/
protected lemma list_sum_mem {l : list L} : (∀ x ∈ l, x ∈ S) → l.sum ∈ S := list_sum_mem
/-- Product of a multiset of elements in an intermediate field is in the intermediate_field. -/
protected lemma multiset_prod_mem (m : multiset L) : (∀ a ∈ m, a ∈ S) → m.prod ∈ S :=
multiset_prod_mem m
/-- Sum of a multiset of elements in a `intermediate_field` is in the `intermediate_field`. -/
protected lemma multiset_sum_mem (m : multiset L) : (∀ a ∈ m, a ∈ S) → m.sum ∈ S :=
multiset_sum_mem m
/-- Product of elements of an intermediate field indexed by a `finset` is in the intermediate_field.
-/
protected lemma prod_mem {ι : Type*} {t : finset ι} {f : ι → L} (h : ∀ c ∈ t, f c ∈ S) :
∏ i in t, f i ∈ S := prod_mem h
/-- Sum of elements in a `intermediate_field` indexed by a `finset` is in the `intermediate_field`.
-/
protected lemma sum_mem {ι : Type*} {t : finset ι} {f : ι → L} (h : ∀ c ∈ t, f c ∈ S) :
∑ i in t, f i ∈ S := sum_mem h
protected lemma pow_mem {x : L} (hx : x ∈ S) (n : ℤ) : x^n ∈ S := zpow_mem hx n
protected lemma zsmul_mem {x : L} (hx : x ∈ S) (n : ℤ) : n • x ∈ S := zsmul_mem hx n
protected lemma coe_int_mem (n : ℤ) : (n : L) ∈ S := coe_int_mem S n
protected lemma coe_add (x y : S) : (↑(x + y) : L) = ↑x + ↑y := rfl
protected lemma coe_neg (x : S) : (↑(-x) : L) = -↑x := rfl
protected lemma coe_mul (x y : S) : (↑(x * y) : L) = ↑x * ↑y := rfl
protected lemma coe_inv (x : S) : (↑(x⁻¹) : L) = (↑x)⁻¹ := rfl
protected lemma coe_zero : ((0 : S) : L) = 0 := rfl
protected lemma coe_one : ((1 : S) : L) = 1 := rfl
protected lemma coe_pow (x : S) (n : ℕ) : (↑(x ^ n) : L) = ↑x ^ n := submonoid_class.coe_pow x n
end inherited_lemmas
lemma coe_nat_mem (n : ℕ) : (n : L) ∈ S :=
by simpa using coe_int_mem S n
end intermediate_field
/-- Turn a subalgebra closed under inverses into an intermediate field -/
def subalgebra.to_intermediate_field (S : subalgebra K L) (inv_mem : ∀ x ∈ S, x⁻¹ ∈ S) :
intermediate_field K L :=
{ neg_mem' := λ x, S.neg_mem,
inv_mem' := inv_mem,
.. S }
@[simp] lemma to_subalgebra_to_intermediate_field
(S : subalgebra K L) (inv_mem : ∀ x ∈ S, x⁻¹ ∈ S) :
(S.to_intermediate_field inv_mem).to_subalgebra = S :=
by { ext, refl }
@[simp] lemma to_intermediate_field_to_subalgebra (S : intermediate_field K L) :
S.to_subalgebra.to_intermediate_field (λ x, S.inv_mem) = S :=
by { ext, refl }
/-- Turn a subalgebra satisfying `is_field` into an intermediate_field -/
def subalgebra.to_intermediate_field' (S : subalgebra K L) (hS : is_field S) :
intermediate_field K L :=
S.to_intermediate_field $ λ x hx, begin
by_cases hx0 : x = 0,
{ rw [hx0, inv_zero],
exact S.zero_mem },
letI hS' := hS.to_field,
obtain ⟨y, hy⟩ := hS.mul_inv_cancel (show (⟨x, hx⟩ : S) ≠ 0, from subtype.ne_of_val_ne hx0),
rw [subtype.ext_iff, S.coe_mul, S.coe_one, subtype.coe_mk, mul_eq_one_iff_inv_eq₀ hx0] at hy,
exact hy.symm ▸ y.2,
end
@[simp] lemma to_subalgebra_to_intermediate_field' (S : subalgebra K L) (hS : is_field S) :
(S.to_intermediate_field' hS).to_subalgebra = S :=
by { ext, refl }
@[simp] lemma to_intermediate_field'_to_subalgebra (S : intermediate_field K L) :
S.to_subalgebra.to_intermediate_field' (field.to_is_field S) = S :=
by { ext, refl }
/-- Turn a subfield of `L` containing the image of `K` into an intermediate field -/
def subfield.to_intermediate_field (S : subfield L)
(algebra_map_mem : ∀ x, algebra_map K L x ∈ S) :
intermediate_field K L :=
{ algebra_map_mem' := algebra_map_mem,
.. S }
namespace intermediate_field
/-- An intermediate field inherits a field structure -/
instance to_field : field S :=
S.to_subfield.to_field
@[simp, norm_cast]
lemma coe_sum {ι : Type*} [fintype ι] (f : ι → S) : (↑∑ i, f i : L) = ∑ i, (f i : L) :=
begin
classical,
induction finset.univ using finset.induction_on with i s hi H,
{ simp },
{ rw [finset.sum_insert hi, add_mem_class.coe_add, H, finset.sum_insert hi] }
end
@[simp, norm_cast]
lemma coe_prod {ι : Type*} [fintype ι] (f : ι → S) : (↑∏ i, f i : L) = ∏ i, (f i : L) :=
begin
classical,
induction finset.univ using finset.induction_on with i s hi H,
{ simp },
{ rw [finset.prod_insert hi, mul_mem_class.coe_mul, H, finset.prod_insert hi] }
end
/-! `intermediate_field`s inherit structure from their `subalgebra` coercions. -/
instance module' {R} [semiring R] [has_smul R K] [module R L] [is_scalar_tower R K L] :
module R S :=
S.to_subalgebra.module'
instance module : module K S := S.to_subalgebra.module
instance is_scalar_tower {R} [semiring R] [has_smul R K] [module R L]
[is_scalar_tower R K L] :
is_scalar_tower R K S :=
S.to_subalgebra.is_scalar_tower
@[simp] lemma coe_smul {R} [semiring R] [has_smul R K] [module R L] [is_scalar_tower R K L]
(r : R) (x : S) :
↑(r • x) = (r • x : L) := rfl
instance algebra' {K'} [comm_semiring K'] [has_smul K' K] [algebra K' L]
[is_scalar_tower K' K L] :
algebra K' S :=
S.to_subalgebra.algebra'
instance algebra : algebra K S := S.to_subalgebra.algebra
instance to_algebra {R : Type*} [semiring R] [algebra L R] : algebra S R :=
S.to_subalgebra.to_algebra
instance is_scalar_tower_bot {R : Type*} [semiring R] [algebra L R] :
is_scalar_tower S L R :=
is_scalar_tower.subalgebra _ _ _ S.to_subalgebra
instance is_scalar_tower_mid {R : Type*} [semiring R] [algebra L R] [algebra K R]
[is_scalar_tower K L R] : is_scalar_tower K S R :=
is_scalar_tower.subalgebra' _ _ _ S.to_subalgebra
/-- Specialize `is_scalar_tower_mid` to the common case where the top field is `L` -/
instance is_scalar_tower_mid' : is_scalar_tower K S L :=
S.is_scalar_tower_mid
/-- If `f : L →+* L'` fixes `K`, `S.map f` is the intermediate field between `L'` and `K`
such that `x ∈ S ↔ f x ∈ S.map f`. -/
def map (f : L →ₐ[K] L') (S : intermediate_field K L) : intermediate_field K L' :=
{ inv_mem' := by { rintros _ ⟨x, hx, rfl⟩, exact ⟨x⁻¹, S.inv_mem hx, map_inv₀ f x⟩ },
neg_mem' := λ x hx, (S.to_subalgebra.map f).neg_mem hx,
.. S.to_subalgebra.map f}
@[simp] lemma coe_map (f : L →ₐ[K] L') : (S.map f : set L') = f '' S := rfl
lemma map_map {K L₁ L₂ L₃ : Type*} [field K] [field L₁] [algebra K L₁]
[field L₂] [algebra K L₂] [field L₃] [algebra K L₃]
(E : intermediate_field K L₁) (f : L₁ →ₐ[K] L₂) (g : L₂ →ₐ[K] L₃) :
(E.map f).map g = E.map (g.comp f) :=
set_like.coe_injective $ set.image_image _ _ _
/-- Given an equivalence `e : L ≃ₐ[K] L'` of `K`-field extensions and an intermediate
field `E` of `L/K`, `intermediate_field_equiv_map e E` is the induced equivalence
between `E` and `E.map e` -/
def intermediate_field_map (e : L ≃ₐ[K] L') (E : intermediate_field K L) :
E ≃ₐ[K] (E.map e.to_alg_hom) :=
e.subalgebra_map E.to_subalgebra
/- We manually add these two simp lemmas because `@[simps]` before `intermediate_field_map`
led to a timeout. -/
@[simp] lemma intermediate_field_map_apply_coe (e : L ≃ₐ[K] L') (E : intermediate_field K L)
(a : E) : ↑(intermediate_field_map e E a) = e a := rfl
@[simp] lemma intermediate_field_map_symm_apply_coe (e : L ≃ₐ[K] L') (E : intermediate_field K L)
(a : E.map e.to_alg_hom) : ↑((intermediate_field_map e E).symm a) = e.symm a := rfl
end intermediate_field
namespace alg_hom
variables (f : L →ₐ[K] L')
/-- The range of an algebra homomorphism, as an intermediate field. -/
@[simps to_subalgebra]
def field_range : intermediate_field K L' :=
{ .. f.range,
.. (f : L →+* L').field_range }
@[simp] lemma coe_field_range : ↑f.field_range = set.range f := rfl
@[simp] lemma field_range_to_subfield :
f.field_range.to_subfield = (f : L →+* L').field_range := rfl
variables {f}
@[simp] lemma mem_field_range {y : L'} : y ∈ f.field_range ↔ ∃ x, f x = y := iff.rfl
end alg_hom
namespace intermediate_field
/-- The embedding from an intermediate field of `L / K` to `L`. -/
def val : S →ₐ[K] L :=
S.to_subalgebra.val
@[simp] theorem coe_val : ⇑S.val = coe := rfl
@[simp] lemma val_mk {x : L} (hx : x ∈ S) : S.val ⟨x, hx⟩ = x := rfl
lemma range_val : S.val.range = S.to_subalgebra :=
S.to_subalgebra.range_val
lemma aeval_coe {R : Type*} [comm_ring R] [algebra R K] [algebra R L]
[is_scalar_tower R K L] (x : S) (P : R[X]) : aeval (x : L) P = aeval x P :=
begin
refine polynomial.induction_on' P (λ f g hf hg, _) (λ n r, _),
{ rw [aeval_add, aeval_add, add_mem_class.coe_add, hf, hg] },
{ simp only [mul_mem_class.coe_mul, aeval_monomial, submonoid_class.coe_pow,
mul_eq_mul_right_iff],
left, refl }
end
lemma coe_is_integral_iff {R : Type*} [comm_ring R] [algebra R K] [algebra R L]
[is_scalar_tower R K L] {x : S} : is_integral R (x : L) ↔ _root_.is_integral R x :=
begin
refine ⟨λ h, _, λ h, _⟩,
{ obtain ⟨P, hPmo, hProot⟩ := h,
refine ⟨P, hPmo, (injective_iff_map_eq_zero _).1 (algebra_map ↥S L).injective _ _⟩,
letI : is_scalar_tower R S L := is_scalar_tower.of_algebra_map_eq (congr_fun rfl),
rwa [eval₂_eq_eval_map, ← eval₂_at_apply, eval₂_eq_eval_map, polynomial.map_map,
← is_scalar_tower.algebra_map_eq, ← eval₂_eq_eval_map] },
{ obtain ⟨P, hPmo, hProot⟩ := h,
refine ⟨P, hPmo, _⟩,
rw [← aeval_def, aeval_coe, aeval_def, hProot, add_submonoid_class.coe_zero] },
end
/-- The map `E → F` when `E` is an intermediate field contained in the intermediate field `F`.
This is the intermediate field version of `subalgebra.inclusion`. -/
def inclusion {E F : intermediate_field K L} (hEF : E ≤ F) : E →ₐ[K] F :=
subalgebra.inclusion hEF
lemma inclusion_injective {E F : intermediate_field K L} (hEF : E ≤ F) :
function.injective (inclusion hEF) :=
subalgebra.inclusion_injective hEF
@[simp] lemma inclusion_self {E : intermediate_field K L}:
inclusion (le_refl E) = alg_hom.id K E :=
subalgebra.inclusion_self
@[simp] lemma inclusion_inclusion {E F G : intermediate_field K L} (hEF : E ≤ F) (hFG : F ≤ G)
(x : E) : inclusion hFG (inclusion hEF x) = inclusion (le_trans hEF hFG) x :=
subalgebra.inclusion_inclusion hEF hFG x
@[simp] lemma coe_inclusion {E F : intermediate_field K L} (hEF : E ≤ F) (e : E) :
(inclusion hEF e : L) = e := rfl
variables {S}
lemma to_subalgebra_injective {S S' : intermediate_field K L}
(h : S.to_subalgebra = S'.to_subalgebra) : S = S' :=
by { ext, rw [← mem_to_subalgebra, ← mem_to_subalgebra, h] }
variables (S)
lemma set_range_subset : set.range (algebra_map K L) ⊆ S :=
S.to_subalgebra.range_subset
lemma field_range_le : (algebra_map K L).field_range ≤ S.to_subfield :=
λ x hx, S.to_subalgebra.range_subset (by rwa [set.mem_range, ← ring_hom.mem_field_range])
@[simp] lemma to_subalgebra_le_to_subalgebra {S S' : intermediate_field K L} :
S.to_subalgebra ≤ S'.to_subalgebra ↔ S ≤ S' := iff.rfl
@[simp] lemma to_subalgebra_lt_to_subalgebra {S S' : intermediate_field K L} :
S.to_subalgebra < S'.to_subalgebra ↔ S < S' := iff.rfl
variables {S}
section tower
/-- Lift an intermediate_field of an intermediate_field -/
def lift {F : intermediate_field K L} (E : intermediate_field K F) : intermediate_field K L :=
E.map (val F)
instance has_lift {F : intermediate_field K L} :
has_lift_t (intermediate_field K F) (intermediate_field K L) := ⟨lift⟩
section restrict_scalars
variables (K) [algebra L' L] [is_scalar_tower K L' L]
/-- Given a tower `L / ↥E / L' / K` of field extensions, where `E` is an `L'`-intermediate field of
`L`, reinterpret `E` as a `K`-intermediate field of `L`. -/
def restrict_scalars (E : intermediate_field L' L) :
intermediate_field K L :=
{ carrier := E.carrier,
..E.to_subfield,
..E.to_subalgebra.restrict_scalars K }
@[simp] lemma coe_restrict_scalars {E : intermediate_field L' L} :
(restrict_scalars K E : set L) = (E : set L) := rfl
@[simp] lemma restrict_scalars_to_subalgebra {E : intermediate_field L' L} :
(E.restrict_scalars K).to_subalgebra = E.to_subalgebra.restrict_scalars K :=
set_like.coe_injective rfl
@[simp] lemma restrict_scalars_to_subfield {E : intermediate_field L' L} :
(E.restrict_scalars K).to_subfield = E.to_subfield :=
set_like.coe_injective rfl
@[simp] lemma mem_restrict_scalars {E : intermediate_field L' L} {x : L} :
x ∈ restrict_scalars K E ↔ x ∈ E := iff.rfl
lemma restrict_scalars_injective :
function.injective (restrict_scalars K : intermediate_field L' L → intermediate_field K L) :=
λ U V H, ext $ λ x, by rw [← mem_restrict_scalars K, H, mem_restrict_scalars]
end restrict_scalars
/-- This was formerly an instance called `lift2_alg`, but an instance above already provides it. -/
example {F : intermediate_field K L} {E : intermediate_field F L} : algebra K E :=
by apply_instance
end tower
section finite_dimensional
variables (F E : intermediate_field K L)
instance finite_dimensional_left [finite_dimensional K L] : finite_dimensional K F :=
left K F L
instance finite_dimensional_right [finite_dimensional K L] : finite_dimensional F L :=
right K F L
@[simp] lemma dim_eq_dim_subalgebra :
module.rank K F.to_subalgebra = module.rank K F := rfl
@[simp] lemma finrank_eq_finrank_subalgebra :
finrank K F.to_subalgebra = finrank K F := rfl
variables {F} {E}
@[simp] lemma to_subalgebra_eq_iff : F.to_subalgebra = E.to_subalgebra ↔ F = E :=
by { rw [set_like.ext_iff, set_like.ext'_iff, set.ext_iff], refl }
lemma eq_of_le_of_finrank_le [finite_dimensional K L] (h_le : F ≤ E)
(h_finrank : finrank K E ≤ finrank K F) : F = E :=
to_subalgebra_injective $ subalgebra.to_submodule_injective $ eq_of_le_of_finrank_le h_le h_finrank
lemma eq_of_le_of_finrank_eq [finite_dimensional K L] (h_le : F ≤ E)
(h_finrank : finrank K F = finrank K E) : F = E :=
eq_of_le_of_finrank_le h_le h_finrank.ge
lemma eq_of_le_of_finrank_le' [finite_dimensional K L] (h_le : F ≤ E)
(h_finrank : finrank F L ≤ finrank E L) : F = E :=
begin
apply eq_of_le_of_finrank_le h_le,
have h1 := finrank_mul_finrank K F L,
have h2 := finrank_mul_finrank K E L,
have h3 : 0 < finrank E L := finrank_pos,
nlinarith,
end
lemma eq_of_le_of_finrank_eq' [finite_dimensional K L] (h_le : F ≤ E)
(h_finrank : finrank F L = finrank E L) : F = E :=
eq_of_le_of_finrank_le' h_le h_finrank.le
end finite_dimensional
lemma is_algebraic_iff {x : S} : is_algebraic K x ↔ is_algebraic K (x : L) :=
(is_algebraic_algebra_map_iff (algebra_map S L).injective).symm
lemma is_integral_iff {x : S} : is_integral K x ↔ is_integral K (x : L) :=
by rw [←is_algebraic_iff_is_integral, is_algebraic_iff, is_algebraic_iff_is_integral]
lemma minpoly_eq (x : S) : minpoly K x = minpoly K (x : L) :=
begin
by_cases hx : is_integral K x,
{ exact minpoly.eq_of_algebra_map_eq (algebra_map S L).injective hx rfl },
{ exact (minpoly.eq_zero hx).trans (minpoly.eq_zero (mt is_integral_iff.mpr hx)).symm },
end
end intermediate_field
/-- If `L/K` is algebraic, the `K`-subalgebras of `L` are all fields. -/
def subalgebra_equiv_intermediate_field (alg : algebra.is_algebraic K L) :
subalgebra K L ≃o intermediate_field K L :=
{ to_fun := λ S, S.to_intermediate_field (λ x hx, S.inv_mem_of_algebraic (alg (⟨x, hx⟩ : S))),
inv_fun := λ S, S.to_subalgebra,
left_inv := λ S, to_subalgebra_to_intermediate_field _ _,
right_inv := to_intermediate_field_to_subalgebra,
map_rel_iff' := λ S S', iff.rfl }
@[simp] lemma mem_subalgebra_equiv_intermediate_field (alg : algebra.is_algebraic K L)
{S : subalgebra K L} {x : L} :
x ∈ subalgebra_equiv_intermediate_field alg S ↔ x ∈ S :=
iff.rfl
@[simp] lemma mem_subalgebra_equiv_intermediate_field_symm (alg : algebra.is_algebraic K L)
{S : intermediate_field K L} {x : L} :
x ∈ (subalgebra_equiv_intermediate_field alg).symm S ↔ x ∈ S :=
iff.rfl
|
78cc2564f1e0b020cbca58577be1d952457470d1
|
6f1049e897f569e5c47237de40321e62f0181948
|
/src/solutions/07_first_negations.lean
|
1caf59291b61283f9edc93c37fa0964a4b3127b2
|
[
"Apache-2.0"
] |
permissive
|
anrddh/tutorials
|
f654a0807b9523608544836d9a81939f8e1dceb8
|
3ba43804e7b632201c494cdaa8da5406f1a255f9
|
refs/heads/master
| 1,655,542,921,827
| 1,588,846,595,000
| 1,588,846,595,000
| 262,330,134
| 0
| 0
| null | 1,588,944,346,000
| 1,588,944,345,000
| null |
UTF-8
|
Lean
| false
| false
| 8,309
|
lean
|
import tuto_lib
import data.int.parity
/-
Negations, proof by contradiction and contraposition
This file introduces the logical rules and tactics related to negation:
exfalso, by_contradiction, contrapose, by_cases and push_neg.
There is a special statement denoted by false which, by definition,
has no proof.
So false implies everything. Indeed `false → P` means any proof of
false could be turned into a proof of P.
This fact is known by its latin name
"ex falso quod libet" (from false follows whatever you want).
Hence Lean's tactic to invoke this is called `exfalso`.
-/
example : false → 0 = 1 :=
begin
intro h,
exfalso,
exact h,
end
/-
The preceding example suggest the definition of false isn't very useful.
But actually it allows to define the negation of a statement P as
"P implies False" that we can read as "if P were true, we would get
a contradiction". Lean denote this by `¬ P`.
One can prove that (¬ P) ↔ (P ↔ false). But in practice we directly
use the definition of ¬ P.
-/
example {x : ℝ} : ¬ x < x :=
begin
intro hyp,
rw lt_iff_le_and_ne at hyp,
cases hyp with hyp_inf hyp_non,
clear hyp_inf, -- we won't use that one, so let's discard it
change x = x → false at hyp_non, -- Lean doesn't need this psychological line
apply hyp_non,
refl,
end
open int
-- 0045
example (n : ℤ) (h_pair : even n) (h_non_pair : ¬ even n) : 0 = 1 :=
begin
-- sorry
exfalso,
exact h_non_pair h_pair,
-- sorry
end
-- 0046
example (P Q : Prop) (h₁ : P ∨ Q) (h₂ : ¬ (P ∧ Q)) : ¬ P ↔ Q :=
begin
-- sorry
split,
{ intro hnP,
cases h₁ with hP hQ,
{ exfalso,
exact hnP hP, },
{ exact hQ }, },
{ intros hQ hP,
exact h₂ ⟨hP, hQ⟩ },
-- sorry
end
/-
The definition of negation easily implies that, for every statement P,
P → ¬ ¬ P
The excluded middle axiom, which asserts P ∨ ¬ P allows to
prove the converse implication.
Together those implications form the principle of double negation elimination.
not_not {P : Prop} : (¬ ¬ P) ↔ P
The implication ¬ ¬ P → P is the basic for proofs by contradiction:
in order to prove P, it suffices to prove ¬¬ P, ie ¬ P → false.
Of course there is no need to keep explaining all this. The tactic
by_contradiction Hyp,
transform any goal P into false and adds Hyp : ¬ P to the local context.
Let's return to a proof of the 5th file: uniqueness of limits for a sequence.
This cannot be proved without using some version of the excluded middle
axiom. We used it secretely in
eq_of_abs_sub_le_all (x y : ℝ) : (∀ ε > 0, |x - y| ≤ ε) → x = y
(we'll prove a variation on this lemma below).
-/
example (u : ℕ → ℝ) (l l' : ℝ) : seq_limit u l → seq_limit u l' → l = l' :=
begin
intros hl hl',
by_contradiction H,
change l ≠ l' at H, -- Lean does not need this line
have ineg : |l-l'| > 0,
exact abs_pos_of_ne_zero (sub_ne_zero_of_ne H),
cases hl ( |l-l'|/4 ) (by linarith) with N hN,
cases hl' ( |l-l'|/4 ) (by linarith) with N' hN',
let N₀ := max N N', -- this is a new tactic, whose effect should be clear
specialize hN N₀ (le_max_left _ _),
specialize hN' N₀ (le_max_right _ _),
have clef : |l-l'| < |l-l'|,
calc
|l - l'| = |(l-u N₀) + (u N₀ -l')| : by ring
... ≤ |l - u N₀| + |u N₀ - l'| : by apply abs_add
... = |u N₀ - l| + |u N₀ - l'| : by rw abs_sub
... < |l-l'| : by linarith,
linarith, -- linarith can also found easy numerical contradictions
end
/-
Another incarnation of the excluded middle axiom is the principle of
contraposition: in order to prove P ⇒ Q, it suffices to prove
non Q ⇒ non P.
-/
-- Using a proof by contradiction, let's prove the contraposition principle
-- 0047
example (P Q : Prop) (h : ¬ Q → ¬ P) : P → Q :=
begin
-- sorry
intro hP,
by_contradiction hnQ,
exact h hnQ hP,
-- sorry
end
/-
Again Lean doesn't need to be explained this principle, we can use the
contrapose tactic.
-/
example (P Q : Prop) (h : ¬ Q → ¬ P) : P → Q :=
begin
contrapose,
exact h,
end
/-
In the next exercise, we'll use
odd n : ∃ k, n = 2*k + 1
not_even_iff_odd : ¬ even n ↔ odd n,
-/
-- 0048
example (n : ℤ) : even (n^2) ↔ even n :=
begin
-- sorry
split,
{ contrapose,
rw not_even_iff_odd,
rw not_even_iff_odd,
rintro ⟨k, rfl⟩,
use 2*k*(k+1),
ring },
{ rintro ⟨k, rfl⟩,
use 2*k^2,
ring },
-- sorry
end
/-
As a last step of our excluded middle tour, let's notice that, especially
in pure logic exercises, it can sometimes be useful to use the
excluded middle axiom in its original form:
classical.em : ∀ P, P ∨ ¬ P
Instead of applying this lemma and then using the cases tactic, we
have the shortcut
by_cases h : P,
combining both steps to create two proof branches: one assuming
h : P, and the other assuming h : ¬ P
For instance, let's prove a reformulation of this implication relation,
which is sometimes used as a definition in other logical foundations,
especially those based on truth tables (hence very strongly using
excluded middle from the very beginning).
-/
variables (P Q : Prop)
example : (P → Q) ↔ (¬ P ∨ Q) :=
begin
split,
{ intro h,
by_cases hP : P,
{ right,
exact h hP },
{ left,
exact hP } },
{ intros h hP,
cases h with hnP hQ,
{ exfalso,
exact hnP hP },
{ exact hQ } },
end
-- 0049
example : ¬ (P ∧ Q) ↔ ¬ P ∨ ¬ Q :=
begin
-- sorry
split,
{ intro h,
by_cases hP : P,
{ right,
intro hQ,
exact h ⟨hP, hQ⟩ },
{ left,
exact hP } },
{ rintros h ⟨hP, hQ⟩,
cases h with hnP hnQ,
{ exact hnP hP },
{ exact hnQ hQ } },
-- sorry
end
/-
It is crucial to understand negation of quantifiers.
Let's do it by hand for a little while.
In the first exercise, only the definition of negation is needed.
-/
-- 0050
example (n : ℤ) : ¬ (∃ k, n = 2*k) ↔ ∀ k, n ≠ 2*k :=
begin
-- sorry
split,
{ intros hyp k hk,
exact hyp ⟨k, hk⟩ },
{ rintros hyp ⟨k, rfl⟩,
exact hyp k rfl },
-- sorry
end
/-
Contrary to begation of the existential quantifier, negation of the
universal quantifier requires excluded middle for the first implication.
In order to prove this, we can use either
* a double proof by contradiction
* a contraposition, not_not : (¬ ¬ P) ↔ P) and a proof by contradiction.
-/
def even_fun (f : ℝ → ℝ) := ∀ x, f (-x) = f x
-- 0051
example (f : ℝ → ℝ) : ¬ even_fun f ↔ ∃ x, f (-x) ≠ f x :=
begin
-- sorry
split,
{ contrapose,
intro h,
rw not_not,
intro x,
by_contradiction H,
apply h,
use x,
/- Alternative version
intro h,
by_contradiction H,
apply h,
intro x,
by_contradiction H',
apply H,
use x, -/ },
{ rintros ⟨x, hx⟩ h',
exact hx (h' x) },
-- sorry
end
/-
Of course we can't keep repeating the above proofs, especially the second one.
So we use the `push_neg` tactic.
-/
example : ¬ even_fun (λ x, 2*x) :=
begin
unfold even_fun, -- Here unfolding is important because push_neg won't do it.
push_neg,
use 42,
linarith,
end
-- 0052
example (f : ℝ → ℝ) : ¬ even_fun f ↔ ∃ x, f (-x) ≠ f x :=
begin
-- sorry
unfold even_fun,
push_neg,
-- sorry
end
def bounded_above (f : ℝ → ℝ) := ∃ M, ∀ x, f x ≤ M
example : ¬ bounded_above (λ x, x) :=
begin
unfold bounded_above,
push_neg,
intro M,
use M + 1,
linarith,
end
-- Let's contrapose
-- 0053
example (x : ℝ) : (∀ ε > 0, x ≤ ε) → x ≤ 0 :=
begin
-- sorry
contrapose,
push_neg,
intro h,
use x/2,
split ; linarith,
-- sorry
end
/-
The "contrapose, push_neg" combo is so common that we can abreviate it to
`contrapose!`
Let's use this trick, together with:
eq_or_lt_of_le : a ≤ b → a = b ∨ a < b
-/
-- 0054
example (f : ℝ → ℝ) : (∀ x y, x < y → f x < f y) ↔ (∀ x y, (x ≤ y ↔ f x ≤ f y)) :=
begin
-- sorry
split,
{ intros hf x y,
split,
{ intros hxy,
cases eq_or_lt_of_le hxy with hxy hxy,
{ rw hxy },
{ linarith [hf x y hxy]} },
{ contrapose!,
apply hf } },
{ intros hf x y,
contrapose!,
intro h,
rwa hf, }
-- sorry
end
|
d31e1792390668ca80e958026e80f60c0f07159d
|
2eab05920d6eeb06665e1a6df77b3157354316ad
|
/test/simp_command.lean
|
8fd6f17401bd0018c34d22d83e327aaf8f74a17f
|
[
"Apache-2.0"
] |
permissive
|
ayush1801/mathlib
|
78949b9f789f488148142221606bf15c02b960d2
|
ce164e28f262acbb3de6281b3b03660a9f744e3c
|
refs/heads/master
| 1,692,886,907,941
| 1,635,270,866,000
| 1,635,270,866,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 2,489
|
lean
|
import tactic.simp_command
import analysis.special_functions.trigonometric.basic
/- Turn off trace messages only if the statements are simplified to true: -/
set_option trace.silence_simp_if_true true
/-!
Tests for the #simp command.
-/
#simp 5 - 5 = 0
section arith
def f (x : ℤ) := x + (x - x)
#simp [f] f 3 = 3
mk_simp_attribute test ""
attribute [test] f
-- You can use the optional `:` to separate
-- the simp lemmas and attributes from the expression to simplify.
#simp with test : (f 3) = 3
attribute [simp] f
#simp f 3 = 3
#simp only [f, eq_self_iff_true] f 3 = 3 + (3 - 3)
local attribute [simp] sub_self
variables (x : ℤ)
#simp with test : (f x) = x
#simp f x = x
#simp only [f, eq_self_iff_true] f x = x + (x - x)
#simp only [f, sub_self, eq_self_iff_true] f x = x + 0
end arith
section real
open real
#simp [exp_ne_zero] : (λ x, deriv (λ x, (sin x) / (exp x)) x) =
(λ (x : ℝ), (cos x * exp x - sin x * exp x) / exp x ^ 2)
variables (x : ℝ)
-- You can refer to local variables, rather than having to use lambdas.
open real
#simp [exp_ne_zero] : deriv (λ x, (sin x) / (exp x)) x = (cos x * exp x - sin x * exp x) / exp x ^ 2
end real
section func_hyp
variables (f : ℕ → ℕ) (hf : f 3 = 0) (hg : 9 = 55)
#simp only [hg, eq_self_iff_true] : 9 = 55
#simp only [hf, add_zero, eq_self_iff_true] : 1 + f 3 = 1
end func_hyp
namespace inst
class magic_data (n : ℕ) :=
(dummy : ℕ)
axiom spell (t : ℤ) (k : ℕ) [magic_data k] : (k = 3) ↔ (k = 77)
variables (t : ℤ) (k : ℕ) [magic_data k] [ii : magic_data k] (h : k = 77 ↔ k = 8)
-- We want to be able to emulate this:
example : (t = t) ∧ (h = h) ∧ ((k = 3) ↔ (k = 8)) :=
begin
simp [spell t, h]
end
-- Check that we can:
#simp [spell t, h, ii] : (k = 3) ↔ (k = 8)
#simp [spell t, h] : (k = 3) ↔ (k = 8)
theorem spell' (k : ℕ) [magic_data k] : (k = 3) ↔ (k = 77) := spell 1 k
attribute [simp] spell'
#simp [h, ii] : (k = 3) ↔ (k = 8)
#simp [h] : (k = 3) ↔ (k = 8)
-- Check that the `#simp` resolver can handle depth > 2 recursive inclusions
class doubly_magic_data (n : ℕ) [magic_data n] :=
(dummy : ℕ)
variables (n : ℕ) [magic_data n] [doubly_magic_data n] (h₂ : n = 77 ↔ n = 8)
@[simp] axiom spell2 (n : ℕ) [magic_data n] [doubly_magic_data n] : (n = 4) ↔ (n = 77)
example : (h₂ = h₂) ∧ ((n = 4) ↔ (n = 8)) :=
begin
simp [h₂],
end
#simp [h₂, ii] : (n = 4) ↔ (n = 8)
#simp [h₂] : (n = 4) ↔ (n = 8)
end inst
|
c8e0d5e66f772c85cc01d0b26c66c22af79897e3
|
6432ea7a083ff6ba21ea17af9ee47b9c371760f7
|
/src/Lean/Compiler/ClosedTermCache.lean
|
69f5b9b30271f5186ddb4afcfdbb74f668d2fda0
|
[
"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
| 959
|
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
structure ClosedTermCache where
map : PHashMap Expr Name := {}
constNames : NameSet := {}
deriving Inhabited
builtin_initialize closedTermCacheExt : EnvExtension ClosedTermCache ← registerEnvExtension (pure {})
@[export lean_cache_closed_term_name]
def cacheClosedTermName (env : Environment) (e : Expr) (n : Name) : Environment :=
closedTermCacheExt.modifyState env fun s => { s with map := s.map.insert e n, constNames := s.constNames.insert n }
@[export lean_get_closed_term_name]
def getClosedTermName? (env : Environment) (e : Expr) : Option Name :=
(closedTermCacheExt.getState env).map.find? e
def isClosedTermName (env : Environment) (n : Name) : Bool :=
(closedTermCacheExt.getState env).constNames.contains n
end Lean
|
c3f82163e8fc524c1e21659a4e0f75e101b8afe3
|
618003631150032a5676f229d13a079ac875ff77
|
/src/linear_algebra/dimension.lean
|
4aaf452f2bc396254258a97967eb11e02b975268
|
[
"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
| 16,677
|
lean
|
/-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Mario Carneiro, Johannes Hölzl, Sander Dahmen
-/
import linear_algebra.basis
import set_theory.ordinal
/-!
# Dimension of modules and vector spaces
## Main definitions
* The dimension of a vector space is defined as `vector_space.dim : cardinal`.
## Main statements
* `mk_eq_mk_of_basis`: the dimension theorem, any two bases of the same vector space have the same
cardinality.
* `dim_quotient_add_dim`: if V' is a submodule of V, then dim (V/V') + dim V' = dim V.
* `dim_range_add_dim_ker`: the rank-nullity theorem.
-/
noncomputable theory
universes u u' u'' v v' w w'
variables {K : Type u} {V V₂ V₃ V₄ : Type v}
variables {ι : Type w} {ι' : Type w'} {η : Type u''} {φ : η → Type u'}
-- TODO: relax these universe constraints
open_locale classical
section vector_space
variables [field K] [add_comm_group V] [vector_space K V]
include K
open submodule function set
variables (K V)
/-- the dimension of a vector space, defined as a term of type `cardinal` -/
def vector_space.dim : cardinal :=
cardinal.min
(nonempty_subtype.2 (@exists_is_basis K V _ _ _))
(λ b, cardinal.mk b.1)
variables {K V}
open vector_space
section
theorem is_basis.le_span (zero_ne_one : (0 : K) ≠ 1) {v : ι → V} {J : set V} (hv : is_basis K v)
(hJ : span K J = ⊤) : cardinal.mk (range v) ≤ cardinal.mk J :=
begin
cases le_or_lt cardinal.omega (cardinal.mk J) with oJ oJ,
{ have := cardinal.mk_range_eq_of_inj (linear_independent.injective zero_ne_one hv.1),
let S : J → set ι := λ j, ↑(is_basis.repr hv j).support,
let S' : J → set V := λ j, v '' S j,
have hs : range v ⊆ ⋃ j, S' j,
{ intros b hb,
rcases mem_range.1 hb with ⟨i, hi⟩,
have : span K J ≤ comap hv.repr (finsupp.supported K K (⋃ j, S j)) :=
span_le.2 (λ j hj x hx, ⟨_, ⟨⟨j, hj⟩, rfl⟩, hx⟩),
rw hJ at this,
replace : hv.repr (v i) ∈ (finsupp.supported K K (⋃ j, S j)) := this trivial,
rw [hv.repr_eq_single, finsupp.mem_supported,
finsupp.support_single_ne_zero zero_ne_one.symm] at this,
subst b,
rcases mem_Union.1 (this (finset.mem_singleton_self _)) with ⟨j, hj⟩,
exact mem_Union.2 ⟨j, (mem_image _ _ _).2 ⟨i, hj, rfl⟩⟩ },
refine le_of_not_lt (λ IJ, _),
suffices : cardinal.mk (⋃ j, S' j) < cardinal.mk (range v),
{ exact not_le_of_lt this ⟨set.embedding_of_subset _ _ hs⟩ },
refine lt_of_le_of_lt (le_trans cardinal.mk_Union_le_sum_mk
(cardinal.sum_le_sum _ (λ _, cardinal.omega) _)) _,
{ exact λ j, le_of_lt (cardinal.lt_omega_iff_finite.2 $ finite_image _ (finset.finite_to_set _)) },
{ rwa [cardinal.sum_const, cardinal.mul_eq_max oJ (le_refl _), max_eq_left oJ] } },
{ rcases exists_finite_card_le_of_finite_of_linear_independent_of_span
(cardinal.lt_omega_iff_finite.1 oJ) hv.1.to_subtype_range _ with ⟨fI, hi⟩,
{ rwa [← cardinal.nat_cast_le, cardinal.finset_card, set.finite.coe_to_finset,
cardinal.finset_card, set.finite.coe_to_finset] at hi, },
{ rw hJ, apply set.subset_univ } },
end
end
/-- dimension theorem -/
theorem mk_eq_mk_of_basis {v : ι → V} {v' : ι' → V}
(hv : is_basis K v) (hv' : is_basis K v') :
cardinal.lift.{w w'} (cardinal.mk ι) = cardinal.lift.{w' w} (cardinal.mk ι') :=
begin
rw ←cardinal.lift_inj.{(max w w') v},
rw [cardinal.lift_lift, cardinal.lift_lift],
apply le_antisymm,
{ convert cardinal.lift_le.{v (max w w')}.2 (hv.le_span zero_ne_one hv'.2),
{ rw cardinal.lift_max.{w v w'},
apply (cardinal.mk_range_eq_of_inj (hv.injective zero_ne_one)).symm, },
{ rw cardinal.lift_max.{w' v w},
apply (cardinal.mk_range_eq_of_inj (hv'.injective zero_ne_one)).symm, }, },
{ convert cardinal.lift_le.{v (max w w')}.2 (hv'.le_span zero_ne_one hv.2),
{ rw cardinal.lift_max.{w' v w},
apply (cardinal.mk_range_eq_of_inj (hv'.injective zero_ne_one)).symm, },
{ rw cardinal.lift_max.{w v w'},
apply (cardinal.mk_range_eq_of_inj (hv.injective zero_ne_one)).symm, }, }
end
theorem is_basis.mk_range_eq_dim {v : ι → V} (h : is_basis K v) :
cardinal.mk (range v) = dim K V :=
begin
have := show ∃ v', dim K V = _, from cardinal.min_eq _ _,
rcases this with ⟨v', e⟩,
rw e,
apply cardinal.lift_inj.1,
rw cardinal.mk_range_eq_of_inj (h.injective zero_ne_one),
convert @mk_eq_mk_of_basis _ _ _ _ _ _ _ _ _ h v'.property
end
theorem is_basis.mk_eq_dim {v : ι → V} (h : is_basis K v) :
cardinal.lift.{w v} (cardinal.mk ι) = cardinal.lift.{v w} (dim K V) :=
by rw [←h.mk_range_eq_dim, cardinal.mk_range_eq_of_inj (h.injective zero_ne_one)]
variables [add_comm_group V₂] [vector_space K V₂]
/-- Two linearly equivalent vector spaces have the same dimension. -/
theorem linear_equiv.dim_eq (f : V ≃ₗ[K] V₂) :
dim K V = dim K V₂ :=
by letI := classical.dec_eq V;
letI := classical.dec_eq V₂; exact
let ⟨b, hb⟩ := exists_is_basis K V in
cardinal.lift_inj.1 $ hb.mk_eq_dim.symm.trans (f.is_basis hb).mk_eq_dim
@[simp] lemma dim_bot : dim K (⊥ : submodule K V) = 0 :=
by letI := classical.dec_eq V;
rw [← cardinal.lift_inj, ← (@is_basis_empty_bot pempty K V _ _ _ not_nonempty_pempty).mk_eq_dim,
cardinal.mk_pempty]
@[simp] lemma dim_top : dim K (⊤ : submodule K V) = dim K V :=
linear_equiv.dim_eq (linear_equiv.of_top _ rfl)
lemma dim_of_field (K : Type*) [field K] : dim K K = 1 :=
by rw [←cardinal.lift_inj, ← (@is_basis_singleton_one punit K _ _).mk_eq_dim, cardinal.mk_punit]
lemma dim_span {v : ι → V} (hv : linear_independent K v) :
dim K ↥(span K (range v)) = cardinal.mk (range v) :=
by rw [←cardinal.lift_inj, ← (is_basis_span hv).mk_eq_dim,
cardinal.mk_range_eq_of_inj (@linear_independent.injective ι K V v _ _ _ zero_ne_one hv)]
lemma dim_span_set {s : set V} (hs : linear_independent K (λ x, x : s → V)) :
dim K ↥(span K s) = cardinal.mk s :=
by rw [← @set_of_mem_eq _ s, ← subtype.val_range]; exact dim_span hs
lemma dim_span_le (s : set V) : dim K (span K s) ≤ cardinal.mk s :=
begin
classical,
rcases
exists_linear_independent (linear_independent_empty K V) (set.empty_subset s)
with ⟨b, hb, _, hsb, hlib⟩,
have hsab : span K s = span K b,
from span_eq_of_le _ hsb (span_le.2 (λ x hx, subset_span (hb hx))),
convert cardinal.mk_le_mk_of_subset hb,
rw [hsab, dim_span_set hlib]
end
lemma dim_span_of_finset (s : finset V) :
dim K (span K (↑s : set V)) < cardinal.omega :=
calc dim K (span K (↑s : set V)) ≤ cardinal.mk (↑s : set V) : dim_span_le ↑s
... = s.card : by rw ←cardinal.finset_card
... < cardinal.omega : cardinal.nat_lt_omega _
theorem dim_prod : dim K (V × V₂) = dim K V + dim K V₂ :=
begin
letI := classical.dec_eq V,
letI := classical.dec_eq V₂,
rcases exists_is_basis K V with ⟨b, hb⟩,
rcases exists_is_basis K V₂ with ⟨c, hc⟩,
rw [← cardinal.lift_inj,
← @is_basis.mk_eq_dim K (V × V₂) _ _ _ _ _ (is_basis_inl_union_inr hb hc),
cardinal.lift_add, cardinal.lift_mk,
← hb.mk_eq_dim, ← hc.mk_eq_dim,
cardinal.lift_mk, cardinal.lift_mk,
cardinal.add_def (ulift b) (ulift c)],
exact cardinal.lift_inj.1 (cardinal.lift_mk_eq.2
⟨equiv.ulift.trans (equiv.sum_congr (@equiv.ulift b) (@equiv.ulift c)).symm ⟩),
end
theorem dim_quotient_add_dim (p : submodule K V) :
dim K p.quotient + dim K p = dim K V :=
by classical; exact let ⟨f⟩ := quotient_prod_linear_equiv p in dim_prod.symm.trans f.dim_eq
theorem dim_quotient_le (p : submodule K V) :
dim K p.quotient ≤ dim K V :=
by { rw ← dim_quotient_add_dim p, exact cardinal.le_add_right _ _ }
/-- rank-nullity theorem -/
theorem dim_range_add_dim_ker (f : V →ₗ[K] V₂) : dim K f.range + dim K f.ker = dim K V :=
begin
haveI := λ (p : submodule K V), classical.dec_eq p.quotient,
rw [← f.quot_ker_equiv_range.dim_eq, dim_quotient_add_dim]
end
lemma dim_range_le (f : V →ₗ[K] V₂) : dim K f.range ≤ dim K V :=
by rw ← dim_range_add_dim_ker f; exact le_add_right (le_refl _)
lemma dim_map_le (f : V →ₗ V₂) (p : submodule K V) : dim K (p.map f) ≤ dim K p :=
begin
have h := dim_range_le (f.comp (submodule.subtype p)),
rwa [linear_map.range_comp, range_subtype] at h,
end
lemma dim_range_of_surjective (f : V →ₗ[K] V₂) (h : surjective f) : dim K f.range = dim K V₂ :=
begin
refine linear_equiv.dim_eq (linear_equiv.of_bijective (submodule.subtype _) _ _),
exact linear_map.ker_eq_bot.2 subtype.val_injective,
rwa [range_subtype, linear_map.range_eq_top]
end
lemma dim_eq_surjective (f : V →ₗ[K] V₂) (h : surjective f) : dim K V = dim K V₂ + dim K f.ker :=
by rw [← dim_range_add_dim_ker f, ← dim_range_of_surjective f h]
lemma dim_le_surjective (f : V →ₗ[K] V₂) (h : surjective f) : dim K V₂ ≤ dim K V :=
by rw [dim_eq_surjective f h]; refine le_add_right (le_refl _)
lemma dim_eq_injective (f : V →ₗ[K] V₂) (h : injective f) : dim K V = dim K f.range :=
by rw [← dim_range_add_dim_ker f, linear_map.ker_eq_bot.2 h]; simp [dim_bot]
lemma dim_submodule_le (s : submodule K V) : dim K s ≤ dim K V :=
by { rw ← dim_quotient_add_dim s, exact cardinal.le_add_left _ _ }
lemma dim_le_injective (f : V →ₗ[K] V₂) (h : injective f) :
dim K V ≤ dim K V₂ :=
by { rw [dim_eq_injective f h], exact dim_submodule_le _ }
lemma dim_le_of_submodule (s t : submodule K V) (h : s ≤ t) : dim K s ≤ dim K t :=
dim_le_injective (of_le h) $ assume ⟨x, hx⟩ ⟨y, hy⟩ eq,
subtype.eq $ show x = y, from subtype.ext.1 eq
section
variables [add_comm_group V₃] [vector_space K V₃]
variables [add_comm_group V₄] [vector_space K V₄]
open linear_map
/-- This is mostly an auxiliary lemma for `dim_sup_add_dim_inf_eq`. -/
lemma dim_add_dim_split
(db : V₃ →ₗ[K] V) (eb : V₄ →ₗ[K] V) (cd : V₂ →ₗ[K] V₃) (ce : V₂ →ₗ[K] V₄)
(hde : ⊤ ≤ db.range ⊔ eb.range)
(hgd : ker cd = ⊥)
(eq : db.comp cd = eb.comp ce)
(eq₂ : ∀d e, db d = eb e → (∃c, cd c = d ∧ ce c = e)) :
dim K V + dim K V₂ = dim K V₃ + dim K V₄ :=
have hf : surjective (coprod db eb),
begin
refine (range_eq_top.1 $ top_unique $ _),
rwa [← map_top, ← prod_top, map_coprod_prod]
end,
begin
conv {to_rhs, rw [← dim_prod, dim_eq_surjective _ hf] },
congr' 1,
apply linear_equiv.dim_eq,
refine linear_equiv.of_bijective _ _ _,
{ refine cod_restrict _ (prod cd (- ce)) _,
{ assume c,
simp only [add_eq_zero_iff_eq_neg, prod_apply, mem_ker,
coprod_apply, neg_neg, map_neg, neg_apply],
exact linear_map.ext_iff.1 eq c } },
{ rw [ker_cod_restrict, ker_prod, hgd, bot_inf_eq] },
{ rw [eq_top_iff, range_cod_restrict, ← map_le_iff_le_comap, map_top, range_subtype],
rintros ⟨d, e⟩,
have h := eq₂ d (-e),
simp only [add_eq_zero_iff_eq_neg, prod_apply, mem_ker, mem_coe, prod.mk.inj_iff,
coprod_apply, map_neg, neg_apply, linear_map.mem_range] at ⊢ h,
assume hde,
rcases h hde with ⟨c, h₁, h₂⟩,
refine ⟨c, h₁, _⟩,
rw [h₂, _root_.neg_neg] }
end
lemma dim_sup_add_dim_inf_eq (s t : submodule K V) :
dim K (s ⊔ t : submodule K V) + dim K (s ⊓ t : submodule K V) = dim K s + dim K t :=
dim_add_dim_split (of_le le_sup_left) (of_le le_sup_right) (of_le inf_le_left) (of_le inf_le_right)
begin
rw [← map_le_map_iff' (ker_subtype $ s ⊔ t), map_sup, map_top,
← linear_map.range_comp, ← linear_map.range_comp, subtype_comp_of_le, subtype_comp_of_le,
range_subtype, range_subtype, range_subtype],
exact le_refl _
end
(ker_of_le _ _ _)
begin ext ⟨x, hx⟩, refl end
begin
rintros ⟨b₁, hb₁⟩ ⟨b₂, hb₂⟩ eq,
have : b₁ = b₂ := congr_arg subtype.val eq,
subst this,
exact ⟨⟨b₁, hb₁, hb₂⟩, rfl, rfl⟩
end
lemma dim_add_le_dim_add_dim (s t : submodule K V) :
dim K (s ⊔ t : submodule K V) ≤ dim K s + dim K t :=
by rw [← dim_sup_add_dim_inf_eq]; exact le_add_right (le_refl _)
end
section fintype
variable [fintype η]
variables [∀i, add_comm_group (φ i)] [∀i, vector_space K (φ i)]
open linear_map
lemma dim_pi : vector_space.dim K (Πi, φ i) = cardinal.sum (λi, vector_space.dim K (φ i)) :=
begin
choose b hb using assume i, exists_is_basis K (φ i),
have : is_basis K (λ (ji : Σ j, b j), std_basis K (λ j, φ j) ji.fst ji.snd.val),
by apply pi.is_basis_std_basis _ hb,
rw [←cardinal.lift_inj, ← this.mk_eq_dim],
simp [λ i, (hb i).mk_range_eq_dim.symm, cardinal.sum_mk]
end
lemma dim_fun {V η : Type u} [fintype η] [add_comm_group V] [vector_space K V] :
vector_space.dim K (η → V) = fintype.card η * vector_space.dim K V :=
by rw [dim_pi, cardinal.sum_const, cardinal.fintype_card]
lemma dim_fun_eq_lift_mul :
vector_space.dim K (η → V) = (fintype.card η : cardinal.{max u'' v}) *
cardinal.lift.{v u''} (vector_space.dim K V) :=
by rw [dim_pi, cardinal.sum_const_eq_lift_mul, cardinal.fintype_card, cardinal.lift_nat_cast]
lemma dim_fun' : vector_space.dim K (η → K) = fintype.card η :=
by rw [dim_fun_eq_lift_mul, dim_of_field K, cardinal.lift_one, mul_one, cardinal.nat_cast_inj]
lemma dim_fin_fun (n : ℕ) : dim K (fin n → K) = n :=
by simp [dim_fun']
end fintype
lemma exists_mem_ne_zero_of_ne_bot {s : submodule K V} (h : s ≠ ⊥) : ∃ b : V, b ∈ s ∧ b ≠ 0 :=
begin
classical,
by_contradiction hex,
have : ∀x∈s, (x:V) = 0, { simpa only [not_exists, not_and, not_not, ne.def] using hex },
exact (h $ bot_unique $ assume s hs, (submodule.mem_bot K).2 $ this s hs)
end
lemma exists_mem_ne_zero_of_dim_pos {s : submodule K V} (h : vector_space.dim K s > 0) :
∃ b : V, b ∈ s ∧ b ≠ 0 :=
exists_mem_ne_zero_of_ne_bot $ assume eq, by rw [(>), eq, dim_bot] at h; exact lt_irrefl _ h
lemma exists_is_basis_fintype (h : dim K V < cardinal.omega) :
∃ s : (set V), (is_basis K (subtype.val : s → V)) ∧ nonempty (fintype s) :=
begin
cases exists_is_basis K V with s hs,
rw [←cardinal.lift_lt, ← is_basis.mk_eq_dim hs, cardinal.lift_lt,
cardinal.lt_omega_iff_fintype] at h,
exact ⟨s, hs, h⟩
end
section rank
/-- `rank f` is the rank of a `linear_map f`, defined as the dimension of `f.range`. -/
def rank (f : V →ₗ[K] V₂) : cardinal := dim K f.range
lemma rank_le_domain (f : V →ₗ[K] V₂) : rank f ≤ dim K V :=
by rw [← dim_range_add_dim_ker f]; exact le_add_right (le_refl _)
lemma rank_le_range (f : V →ₗ[K] V₂) : rank f ≤ dim K V₂ :=
dim_submodule_le _
lemma rank_add_le (f g : V →ₗ[K] V₂) : rank (f + g) ≤ rank f + rank g :=
calc rank (f + g) ≤ dim K (f.range ⊔ g.range : submodule K V₂) :
begin
refine dim_le_of_submodule _ _ _,
exact (linear_map.range_le_iff_comap.2 $ eq_top_iff'.2 $
assume x, show f x + g x ∈ (f.range ⊔ g.range : submodule K V₂), from
mem_sup.2 ⟨_, mem_image_of_mem _ (mem_univ _), _, mem_image_of_mem _ (mem_univ _), rfl⟩)
end
... ≤ rank f + rank g : dim_add_le_dim_add_dim _ _
@[simp] lemma rank_zero : rank (0 : V →ₗ[K] V₂) = 0 :=
by rw [rank, linear_map.range_zero, dim_bot]
lemma rank_finset_sum_le {η} (s : finset η) (f : η → V →ₗ[K] V₂) :
rank (s.sum f) ≤ s.sum (λ d, rank (f d)) :=
@finset.sum_hom_rel _ _ _ _ _ (λa b, rank a ≤ b) f (λ d, rank (f d)) s (le_of_eq rank_zero)
(λ i g c h, le_trans (rank_add_le _ _) (add_le_add_left' h))
variables [add_comm_group V₃] [vector_space K V₃]
lemma rank_comp_le1 (g : V →ₗ[K] V₂) (f : V₂ →ₗ[K] V₃) : rank (f.comp g) ≤ rank f :=
begin
refine dim_le_of_submodule _ _ _,
rw [linear_map.range_comp],
exact image_subset _ (subset_univ _)
end
lemma rank_comp_le2 (g : V →ₗ[K] V₂) (f : V₂ →ₗ V₃) : rank (f.comp g) ≤ rank g :=
by rw [rank, rank, linear_map.range_comp]; exact dim_map_le _ _
end rank
end vector_space
section unconstrained_universes
variables {E : Type v'}
variables [field K] [add_comm_group V] [vector_space K V]
[add_comm_group E] [vector_space K E]
open vector_space
/-- Version of linear_equiv.dim_eq without universe constraints. -/
theorem linear_equiv.dim_eq_lift (f : V ≃ₗ[K] E) :
cardinal.lift.{v v'} (dim K V) = cardinal.lift.{v' v} (dim K E) :=
begin
cases exists_is_basis K V with b hb,
rw [← cardinal.lift_inj.1 hb.mk_eq_dim, ← (f.is_basis hb).mk_eq_dim, cardinal.lift_mk],
end
end unconstrained_universes
|
20d36df6ce7c6cdd59d0bfdcf2469bc76e8b91eb
|
624f6f2ae8b3b1adc5f8f67a365c51d5126be45a
|
/stage0/src/Init/Data/Nat/Bitwise.lean
|
52a89b7a89ccaab3e7af58a16ee009063ae40615
|
[
"Apache-2.0"
] |
permissive
|
mhuisi/lean4
|
28d35a4febc2e251c7f05492e13f3b05d6f9b7af
|
dda44bc47f3e5d024508060dac2bcb59fd12e4c0
|
refs/heads/master
| 1,621,225,489,283
| 1,585,142,689,000
| 1,585,142,689,000
| 250,590,438
| 0
| 2
|
Apache-2.0
| 1,602,443,220,000
| 1,585,327,814,000
|
C
|
UTF-8
|
Lean
| false
| false
| 752
|
lean
|
/-
Copyright (c) 2019 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
prelude
import Init.Data.Nat.Basic
import Init.Data.Nat.Div
import Init.Coe
namespace Nat
partial def bitwise (f : Bool → Bool → Bool) : Nat → Nat → Nat | n, m =>
if n = 0 then (if f false true then m else 0)
else if m = 0 then (if f true false then n else 0)
else
let n' := n / 2;
let m' := m / 2;
let b₁ := n % 2 = 1;
let b₂ := m % 2 = 1;
let r := bitwise n' m';
if f b₁ b₂ then bit1 r else bit0 r
@[extern "lean_nat_land"]
def land : Nat → Nat → Nat := bitwise and
@[extern "lean_nat_lor"]
def lor : Nat → Nat → Nat := bitwise or
end Nat
|
a7e1b85c5bb092f1868d3fe09a0853ee16af9048
|
d406927ab5617694ec9ea7001f101b7c9e3d9702
|
/src/category_theory/abelian/injective_resolution.lean
|
b72be7a1ac788dc387caa7922cc9e3291e3abfa5
|
[
"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
| 12,728
|
lean
|
/-
Copyright (c) 2022 Jujian Zhang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jujian Zhang, Scott Morrison
-/
import algebra.homology.quasi_iso
import category_theory.preadditive.injective_resolution
import category_theory.abelian.homology
import algebra.homology.homotopy_category
/-!
# Main result
When the underlying category is abelian:
* `category_theory.InjectiveResolution.desc`: Given `I : InjectiveResolution X` and
`J : InjectiveResolution Y`, any morphism `X ⟶ Y` admits a descent to a chain map
`J.cocomplex ⟶ I.cocomplex`. It is a descent in the sense that `I.ι` intertwines the descent and
the original morphism, see `category_theory.InjectiveResolution.desc_commutes`.
* `category_theory.InjectiveResolution.desc_homotopy`: Any two such descents are homotopic.
* `category_theory.InjectiveResolution.homotopy_equiv`: Any two injective resolutions of the same
object are homotopy equivalent.
* `category_theory.injective_resolutions`: If every object admits an injective resolution, we can
construct a functor `injective_resolutions C : C ⥤ homotopy_category C`.
* `category_theory.exact_f_d`: `f` and `injective.d f` are exact.
* `category_theory.InjectiveResolution.of`: Hence, starting from a monomorphism `X ⟶ J`, where `J`
is injective, we can apply `injective.d` repeatedly to obtain an injective resolution of `X`.
-/
noncomputable theory
open category_theory
open category_theory.limits
universes v u
namespace category_theory
variables {C : Type u} [category.{v} C]
open injective
namespace InjectiveResolution
section
variables [has_zero_morphisms C] [has_zero_object C] [has_equalizers C] [has_images C]
/-- Auxiliary construction for `desc`. -/
def desc_f_zero {Y Z : C} (f : Z ⟶ Y) (I : InjectiveResolution Y) (J : InjectiveResolution Z) :
J.cocomplex.X 0 ⟶ I.cocomplex.X 0 :=
factor_thru (f ≫ I.ι.f 0) (J.ι.f 0)
end
section abelian
variables [abelian C]
/-- Auxiliary construction for `desc`. -/
def desc_f_one {Y Z : C}
(f : Z ⟶ Y) (I : InjectiveResolution Y) (J : InjectiveResolution Z) :
J.cocomplex.X 1 ⟶ I.cocomplex.X 1 :=
exact.desc (desc_f_zero f I J ≫ I.cocomplex.d 0 1) (J.ι.f 0) (J.cocomplex.d 0 1)
(abelian.exact.op _ _ J.exact₀) (by simp [←category.assoc, desc_f_zero])
@[simp] lemma desc_f_one_zero_comm {Y Z : C}
(f : Z ⟶ Y) (I : InjectiveResolution Y) (J : InjectiveResolution Z) :
J.cocomplex.d 0 1 ≫ desc_f_one f I J = desc_f_zero f I J ≫ I.cocomplex.d 0 1 :=
by simp [desc_f_zero, desc_f_one]
/-- Auxiliary construction for `desc`. -/
def desc_f_succ {Y Z : C}
(I : InjectiveResolution Y) (J : InjectiveResolution Z)
(n : ℕ) (g : J.cocomplex.X n ⟶ I.cocomplex.X n) (g' : J.cocomplex.X (n+1) ⟶ I.cocomplex.X (n+1))
(w : J.cocomplex.d n (n+1) ≫ g' = g ≫ I.cocomplex.d n (n+1)) :
Σ' g'' : J.cocomplex.X (n+2) ⟶ I.cocomplex.X (n+2),
J.cocomplex.d (n+1) (n+2) ≫ g'' = g' ≫ I.cocomplex.d (n+1) (n+2) :=
⟨@exact.desc C _ _ _ _ _ _ _ _ _
(g' ≫ I.cocomplex.d (n+1) (n+2))
(J.cocomplex.d n (n+1))
(J.cocomplex.d (n+1) (n+2)) (abelian.exact.op _ _ (J.exact _))
(by simp [←category.assoc, w]), (by simp)⟩
/-- A morphism in `C` descends to a chain map between injective resolutions. -/
def desc {Y Z : C}
(f : Z ⟶ Y) (I : InjectiveResolution Y) (J : InjectiveResolution Z) :
J.cocomplex ⟶ I.cocomplex :=
cochain_complex.mk_hom _ _ (desc_f_zero f _ _) (desc_f_one f _ _)
(desc_f_one_zero_comm f I J).symm
(λ n ⟨g, g', w⟩, ⟨(desc_f_succ I J n g g' w.symm).1, (desc_f_succ I J n g g' w.symm).2.symm⟩)
/-- The resolution maps intertwine the descent of a morphism and that morphism. -/
@[simp, reassoc]
lemma desc_commutes {Y Z : C}
(f : Z ⟶ Y) (I : InjectiveResolution Y) (J : InjectiveResolution Z) :
J.ι ≫ desc f I J = (cochain_complex.single₀ C).map f ≫ I.ι :=
begin
ext n,
rcases n with (_|_|n);
{ dsimp [desc, desc_f_one, desc_f_zero], simp, },
end
-- Now that we've checked this property of the descent,
-- we can seal away the actual definition.
attribute [irreducible] desc
/-- An auxiliary definition for `desc_homotopy_zero`. -/
def desc_homotopy_zero_zero {Y Z : C} {I : InjectiveResolution Y} {J : InjectiveResolution Z}
(f : I.cocomplex ⟶ J.cocomplex)
(comm : I.ι ≫ f = 0) : I.cocomplex.X 1 ⟶ J.cocomplex.X 0 :=
exact.desc (f.f 0) (I.ι.f 0) (I.cocomplex.d 0 1) (abelian.exact.op _ _ I.exact₀)
(congr_fun (congr_arg homological_complex.hom.f comm) 0)
/-- An auxiliary definition for `desc_homotopy_zero`. -/
def desc_homotopy_zero_one {Y Z : C} {I : InjectiveResolution Y} {J : InjectiveResolution Z}
(f : I.cocomplex ⟶ J.cocomplex)
(comm : I.ι ≫ f = (0 : _ ⟶ J.cocomplex)) : I.cocomplex.X 2 ⟶ J.cocomplex.X 1 :=
exact.desc (f.f 1 - desc_homotopy_zero_zero f comm ≫ J.cocomplex.d 0 1)
(I.cocomplex.d 0 1) (I.cocomplex.d 1 2) (abelian.exact.op _ _ (I.exact _))
(by simp [desc_homotopy_zero_zero, ←category.assoc])
/-- An auxiliary definition for `desc_homotopy_zero`. -/
def desc_homotopy_zero_succ {Y Z : C} {I : InjectiveResolution Y} {J : InjectiveResolution Z}
(f : I.cocomplex ⟶ J.cocomplex) (n : ℕ)
(g : I.cocomplex.X (n + 1) ⟶ J.cocomplex.X n)
(g' : I.cocomplex.X (n + 2) ⟶ J.cocomplex.X (n + 1))
(w : f.f (n + 1) = I.cocomplex.d (n+1) (n+2) ≫ g' + g ≫ J.cocomplex.d n (n+1)) :
I.cocomplex.X (n + 3) ⟶ J.cocomplex.X (n + 2) :=
exact.desc (f.f (n+2) - g' ≫ J.cocomplex.d _ _) (I.cocomplex.d (n+1) (n+2))
(I.cocomplex.d (n+2) (n+3)) (abelian.exact.op _ _ (I.exact _))
(by simp [preadditive.comp_sub, ←category.assoc, preadditive.sub_comp,
show I.cocomplex.d (n+1) (n+2) ≫ g' = f.f (n + 1) - g ≫ J.cocomplex.d n (n+1),
by {rw w, simp only [add_sub_cancel] } ])
/-- Any descent of the zero morphism is homotopic to zero. -/
def desc_homotopy_zero {Y Z : C} {I : InjectiveResolution Y} {J : InjectiveResolution Z}
(f : I.cocomplex ⟶ J.cocomplex)
(comm : I.ι ≫ f = 0) :
homotopy f 0 :=
homotopy.mk_coinductive _ (desc_homotopy_zero_zero f comm) (by simp [desc_homotopy_zero_zero])
(desc_homotopy_zero_one f comm) (by simp [desc_homotopy_zero_one])
(λ n ⟨g, g', w⟩, ⟨desc_homotopy_zero_succ f n g g' (by simp only [w, add_comm]),
by simp [desc_homotopy_zero_succ, w]⟩)
/-- Two descents of the same morphism are homotopic. -/
def desc_homotopy {Y Z : C} (f : Y ⟶ Z) {I : InjectiveResolution Y} {J : InjectiveResolution Z}
(g h : I.cocomplex ⟶ J.cocomplex)
(g_comm : I.ι ≫ g = (cochain_complex.single₀ C).map f ≫ J.ι)
(h_comm : I.ι ≫ h = (cochain_complex.single₀ C).map f ≫ J.ι) :
homotopy g h :=
homotopy.equiv_sub_zero.inv_fun (desc_homotopy_zero _ (by simp [g_comm, h_comm]))
/-- The descent of the identity morphism is homotopic to the identity cochain map. -/
def desc_id_homotopy (X : C) (I : InjectiveResolution X) :
homotopy (desc (𝟙 X) I I) (𝟙 I.cocomplex) :=
by apply desc_homotopy (𝟙 X); simp
/-- The descent of a composition is homotopic to the composition of the descents. -/
def desc_comp_homotopy {X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z)
(I : InjectiveResolution X) (J : InjectiveResolution Y) (K : InjectiveResolution Z) :
homotopy (desc (f ≫ g) K I) (desc f J I ≫ desc g K J) :=
by apply desc_homotopy (f ≫ g); simp
-- We don't care about the actual definitions of these homotopies.
attribute [irreducible] desc_homotopy_zero desc_homotopy desc_id_homotopy desc_comp_homotopy
/-- Any two injective resolutions are homotopy equivalent. -/
def homotopy_equiv {X : C} (I J : InjectiveResolution X) :
homotopy_equiv I.cocomplex J.cocomplex :=
{ hom := desc (𝟙 X) J I,
inv := desc (𝟙 X) I J,
homotopy_hom_inv_id := (desc_comp_homotopy (𝟙 X) (𝟙 X) I J I).symm.trans $
by simpa [category.id_comp] using desc_id_homotopy _ _,
homotopy_inv_hom_id := (desc_comp_homotopy (𝟙 X) (𝟙 X) J I J).symm.trans $
by simpa [category.id_comp] using desc_id_homotopy _ _ }
@[simp, reassoc] lemma homotopy_equiv_hom_ι {X : C} (I J : InjectiveResolution X) :
I.ι ≫ (homotopy_equiv I J).hom = J.ι :=
by simp [homotopy_equiv]
@[simp, reassoc] lemma homotopy_equiv_inv_ι {X : C} (I J : InjectiveResolution X) :
J.ι ≫ (homotopy_equiv I J).inv = I.ι :=
by simp [homotopy_equiv]
end abelian
end InjectiveResolution
section
variables [abelian C]
/-- An arbitrarily chosen injective resolution of an object. -/
abbreviation injective_resolution (Z : C) [has_injective_resolution Z] : cochain_complex C ℕ :=
(has_injective_resolution.out Z).some.cocomplex
/-- The cochain map from cochain complex consisting of `Z` supported in degree `0`
back to the arbitrarily chosen injective resolution `injective_resolution Z`. -/
abbreviation injective_resolution.ι (Z : C) [has_injective_resolution Z] :
(cochain_complex.single₀ C).obj Z ⟶ injective_resolution Z :=
(has_injective_resolution.out Z).some.ι
/-- The descent of a morphism to a cochain map between the arbitrarily chosen injective resolutions.
-/
abbreviation injective_resolution.desc {X Y : C} (f : X ⟶ Y)
[has_injective_resolution X] [has_injective_resolution Y] :
injective_resolution X ⟶ injective_resolution Y :=
InjectiveResolution.desc f _ _
variables (C) [has_injective_resolutions C]
/--
Taking injective resolutions is functorial,
if considered with target the homotopy category
(`ℕ`-indexed cochain complexes and chain maps up to homotopy).
-/
def injective_resolutions : C ⥤ homotopy_category C (complex_shape.up ℕ) :=
{ obj := λ X, (homotopy_category.quotient _ _).obj (injective_resolution X),
map := λ X Y f, (homotopy_category.quotient _ _).map (injective_resolution.desc f),
map_id' := λ X, begin
rw ←(homotopy_category.quotient _ _).map_id,
apply homotopy_category.eq_of_homotopy,
apply InjectiveResolution.desc_id_homotopy,
end,
map_comp' := λ X Y Z f g, begin
rw ←(homotopy_category.quotient _ _).map_comp,
apply homotopy_category.eq_of_homotopy,
apply InjectiveResolution.desc_comp_homotopy,
end, }
end
section
variables [abelian C] [enough_injectives C]
lemma exact_f_d {X Y : C} (f : X ⟶ Y) : exact f (d f) :=
(abelian.exact_iff _ _).2 $
⟨by simp, zero_of_comp_mono (ι _) $ by rw [category.assoc, kernel.condition]⟩
end
namespace InjectiveResolution
/-!
Our goal is to define `InjectiveResolution.of Z : InjectiveResolution Z`.
The `0`-th object in this resolution will just be `injective.under Z`,
i.e. an arbitrarily chosen injective object with a map from `Z`.
After that, we build the `n+1`-st object as `injective.syzygies`
applied to the previously constructed morphism,
and the map from the `n`-th object as `injective.d`.
-/
variables [abelian C] [enough_injectives C]
/-- Auxiliary definition for `InjectiveResolution.of`. -/
@[simps]
def of_cocomplex (Z : C) : cochain_complex C ℕ :=
cochain_complex.mk'
(injective.under Z) (injective.syzygies (injective.ι Z)) (injective.d (injective.ι Z))
(λ ⟨X, Y, f⟩, ⟨injective.syzygies f, injective.d f, (exact_f_d f).w⟩)
/--
In any abelian category with enough injectives,
`InjectiveResolution.of Z` constructs an injective resolution of the object `Z`.
-/
@[irreducible] def of (Z : C) : InjectiveResolution Z :=
{ cocomplex := of_cocomplex Z,
ι := cochain_complex.mk_hom _ _ (injective.ι Z) 0
(by { simp only [of_cocomplex_d, eq_self_iff_true, eq_to_hom_refl, category.comp_id,
dite_eq_ite, if_true, comp_zero],
exact (exact_f_d (injective.ι Z)).w, } ) (λ n _, ⟨0, by ext⟩),
injective := by { rintros (_|_|_|n); { apply injective.injective_under, } },
exact₀ := by simpa using exact_f_d (injective.ι Z),
exact := by { rintros (_|n); { simp, apply exact_f_d } },
mono := injective.ι_mono Z }
@[priority 100]
instance (Z : C) : has_injective_resolution Z :=
{ out := ⟨of Z⟩ }
@[priority 100]
instance : has_injective_resolutions C :=
{ out := λ _, infer_instance }
end InjectiveResolution
end category_theory
namespace homological_complex.hom
variables {C : Type u} [category.{v} C] [abelian C]
/-- If `X` is a cochain complex of injective objects and we have a quasi-isomorphism
`f : Y[0] ⟶ X`, then `X` is an injective resolution of `Y.` -/
def homological_complex.hom.from_single₀_InjectiveResolution (X : cochain_complex C ℕ) (Y : C)
(f : (cochain_complex.single₀ C).obj Y ⟶ X) [quasi_iso f]
(H : ∀ n, injective (X.X n)) :
InjectiveResolution Y :=
{ cocomplex := X,
ι := f,
injective := H,
exact₀ := f.from_single₀_exact_f_d_at_zero,
exact := f.from_single₀_exact_at_succ,
mono := f.from_single₀_mono_at_zero }
end homological_complex.hom
|
39533bc58d96fa050007cf11bda60e82c327074a
|
297c4ceafbbaed2a59b6215504d09e6bf201a2ee
|
/theorem.lean
|
aec17ccd4cdb0949f968d177c29445253dfd7992
|
[] |
no_license
|
minchaowu/Kruskal.lean3
|
559c91b82033ce44ea61593adcec9cfff725c88d
|
a14516f47b21e636e9df914fc6ebe64cbe5cd38d
|
refs/heads/master
| 1,611,010,001,429
| 1,497,935,421,000
| 1,497,935,421,000
| 82,000,982
| 1
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 20,857
|
lean
|
import .kruskal .higman data.list
open classical fin set nat subtype finite_tree kruskal function prod
noncomputable theory
theorem dne {p : Prop} (H : ¬¬p) : p := or.elim (em p) (assume Hp : p, Hp) (assume Hnp : ¬p, absurd Hnp H)
lemma tag_eq_of_eq {A : Type} {P : A → Prop} {a b : subtype P} (H : a = b) :a.1 = b.1 := by rw H
section
variables {A B : Type}
variable x : A × B
theorem prod_eta : (x.1,x.2) = x := prod.rec_on x (λ a b, rfl)
theorem eq_of_prod {A B : Type} {p q : A × B} (H1 : p.1 = q.1) (H2 : p.2 = q.2) : p = q :=
begin
cases p with p1 p2,
dsimp at H1, dsimp at H2,
rw [H1,H2,prod_eta]
end
end
theorem ne_empty_of_image_on_univ {A B : Type} (f : A → B) [inhabited A] : image f univ ≠ ∅ :=
have (∅ : set A) ≠ univ, from empty_ne_univ,
have ∃ a, a ∈ (univ : set A), from exists_mem_of_ne_empty (ne.symm this),
let ⟨a,h⟩ := this in
have f a ∈ image f univ, from exists.intro a (and.intro h rfl),
set.ne_empty_of_mem this
theorem val_mapsto (n : ℕ) : maps_to fin.val (@univ (fin n)) {i : ℕ | i < n} :=
take x, assume Ha, is_lt x
theorem injective_val_on_univ (n : ℕ): inj_on fin.val (@univ (fin n)) :=
take x₁ x₂, assume H1, assume H2, assume eq, eq_of_veq eq
instance finite_univ_of_fin (n : ℕ) : finite (@univ (fin n)) :=
finite_of_inj_on (val_mapsto n) (injective_val_on_univ n)
theorem refl_of_image_on_univ {A B: Type} (f : A → B) : set.image f (@set.univ A) = {b : B | ∃ x, f x = b} :=
have Hl : set.image f (@set.univ A) ⊆ {b : B | ∃ x, f x = b}, from
take x, assume Hx,
let ⟨i,h⟩ := Hx in exists.intro i (and.right h),
have {b : B | ∃ x, f x = b} ⊆ set.image f (@set.univ A), from
take x, assume Hx,
let ⟨i,h⟩ := Hx in exists.intro i (and.intro trivial h),
set.subset.antisymm Hl this
theorem finite_image_of_fin {A : Type} {n : ℕ} (f : fin n → A) : finite {a : A | ∃ x, f x = a} :=
have image f (@univ (fin n)) = {a : A | ∃ x, f x = a}, from refl_of_image_on_univ f,
have finite (image f (@univ (fin n))), from finite_image f (@univ (fin n)),
by super
-- need this to handle trees of the form (f n) where f : ℕ → finite_tree
theorem finite_tree_destruct {t : finite_tree} :
∃ n (ss : fin n → finite_tree), t = cons ss :=
finite_tree.cases_on t (λ n a, ⟨n,a,rfl⟩)
definition num_of_branches_at_root : finite_tree → ℕ
| (@cons n ts) := n
-- definition num_of_branches_at_root (t : finite_tree) (H : t ≠ node) : ℕ :=
-- some (exists_eq_cons_of_ne_node H)
-- definition branches_at_root : finite_tree → Π {n : ℕ}, fin n → finite_tree
-- | (@cons n ts) := ts
-- some (some_spec (exists_eq_cons_of_ne_node H))
-- definition set_of_branches' {n : ℕ} : finite_tree → set (finite_tree × ℕ)
-- | (@cons n ts) := {x : finite_tree × ℕ | ∃ a : fin n, ts a = x.1 ∧ val a = x.2}
-- {x : finite_tree × ℕ | ∃ a : fin n, ts a = x.1 ∧ val a = x.2}
def branches_aux {n : ℕ} (ts : fin n → finite_tree) : set (finite_tree × ℕ) :=
{x : finite_tree × ℕ | ∃ a : fin n, ts a = x.1 ∧ val a = x.2}
theorem empty_branches (ts : fin 0 → finite_tree) : branches_aux ts = ∅ :=
have ∀ x, x ∉ branches_aux ts, from λ x h, let ⟨a,ha⟩ := h in fin_zero_absurd a,
set.eq_empty_of_forall_not_mem this
definition branches : finite_tree → set (finite_tree × ℕ)
| (@cons n ts) := branches_aux ts
theorem embeds_of_branches {t : finite_tree × ℕ} {T : finite_tree} : t ∈ (branches T) → t.1 ≼ T :=
begin
cases T with n ts,
intro H, cases H with a h,
cases t.1 with t1a t1s,
dsimp [embeds],apply or.inl,
fapply exists.intro,
exact a, rw h^.left, apply embeds_refl
end
theorem lt_of_size_of_branches {t : finite_tree × ℕ} {T : finite_tree} : t ∈ branches T → size t.1 < size T :=
begin
cases T with n ts,
intro h,
assert h' : ∃ i, ts i = t.1, cases h with b hb,
{exact exists.intro b hb^.left},
cases h' with c hc, rw -hc, apply lt_of_size_branches_aux
end
theorem finite_set_of_branches {n : ℕ} (ts : fin n → finite_tree) : finite (branches_aux ts) :=
let f (a : fin n) : finite_tree × ℕ := (ts a, val a) in
let S : set (finite_tree × ℕ) := {x : finite_tree × ℕ | ∃ a : fin n, f a = x} in
have finS : finite S, from finite_image_of_fin f,
have H1 : S ⊆ branches_aux ts, from
λ x ⟨a,h⟩, ⟨a,⟨by rw -h,by rw -h⟩⟩,
have H2 : branches_aux ts ⊆ S, from
λ x ⟨a,h⟩, ⟨a,begin dsimp,rw [h^.left, h^.right], apply prod_eta end⟩,
begin rw -(subset.antisymm H1 H2), exact finS end
theorem finite_branches (t : finite_tree) : finite (branches t) :=
by induction t; apply finite_set_of_branches
#check @minimal_bad_seq
section
parameter H : ∃ f, ¬ is_good f embeds
definition mbs_of_finite_tree := minimal_bad_seq size H
theorem bad_mbs_finite_tree : ¬ is_good mbs_of_finite_tree embeds := badness_of_mbs size H
theorem ne_node_of_elt_of_mbs_finite_tree (n : ℕ) {ts : fin 0 → finite_tree} : mbs_of_finite_tree n ≠ cons ts :=
assume Hneg,
have cons ts ≼ mbs_of_finite_tree (succ n), by apply node_embeds,
have Hr : mbs_of_finite_tree n ≼ mbs_of_finite_tree (succ n), by simph,
have n < succ n, from lt_succ_self n,
have is_good mbs_of_finite_tree embeds, from exists.intro n (exists.intro (succ n) (and.intro this Hr)),
show _, from bad_mbs_finite_tree this
theorem minimality_of_mbs_finite_tree0 (f : ℕ → finite_tree) (Hf : ¬ is_good f embeds) : size (mbs_of_finite_tree 0) ≤ size (f 0) := minimality_of_mbs_0 size H f Hf
theorem minimality_of_mbs_finite_tree (n : ℕ) (f : ℕ → finite_tree) (H1 : extends_at n mbs_of_finite_tree f ∧ ¬ is_good f embeds) : size (mbs_of_finite_tree (succ n)) ≤ size (f (succ n)) := minimality_of_mbs size H n f H1
definition seq_branches_of_mbs_tree (n : ℕ) : set (finite_tree × ℕ) := branches (mbs_of_finite_tree n)
theorem mem_of_seq_branches {n i : ℕ} (ts : fin n → finite_tree) (k : fin n) (Heq : mbs_of_finite_tree i = cons ts) : (ts k, val k) ∈ seq_branches_of_mbs_tree i :=
have ts k = (ts k, val k).1 ∧ val k = (ts k, val k).2, from and.intro rfl rfl,
have ∃ a, ts a = (ts k, val k).1 ∧ val a = (ts k, val k).2, from exists.intro k this,
have (ts k, val k) ∈ branches (cons ts), from this,
by rw -Heq at this;exact this
definition mbs_tree : Type := {t : finite_tree × ℕ // ∃ i, t ∈ seq_branches_of_mbs_tree i}
definition embeds' (t : mbs_tree) (s : mbs_tree) : Prop := t.val.1 ≼ s.val.1
theorem embeds'_refl (t : mbs_tree) : embeds' t t := embeds_refl t.val.1
theorem embeds'_trans (a b c : mbs_tree) : embeds' a b → embeds' b c → embeds' a c :=
assume H₁, assume H₂, embeds_trans H₁ H₂
section
parameter H' : ∃ f, ¬ is_good f embeds'
definition R : ℕ → mbs_tree := some H'
definition family_index (n : ℕ) : ℕ := some ((R n).2)
definition index_set_of_mbs_tree : set ℕ := image family_index univ
lemma index_ne_empty : index_set_of_mbs_tree ≠ ∅ := ne_empty_of_image_on_univ family_index
definition least_family_index := least index_set_of_mbs_tree index_ne_empty
lemma exists_least : ∃ i, family_index i = least_family_index :=
have least_family_index ∈ index_set_of_mbs_tree, from least_is_mem index_set_of_mbs_tree index_ne_empty,
let ⟨i,h⟩ := this in
⟨i, h^.right⟩
definition least_index : ℕ := some exists_least
definition Kruskal's_g (n : ℕ) : mbs_tree := R (least_index + n)
definition Kruskal's_h (n : ℕ) : ℕ := family_index (least_index + n)
theorem bad_Kruskal's_g : ¬ is_good Kruskal's_g embeds' :=
suppose is_good Kruskal's_g embeds',
let ⟨i,j,hij⟩ := this in
have Hr : embeds' (Kruskal's_g i) (Kruskal's_g j), from hij^.right,
have least_index + i < least_index + j, from add_lt_add_left hij^.left _,
have is_good R embeds', from ⟨least_index + i, ⟨least_index + j,⟨this, Hr⟩⟩⟩,
(some_spec H') this
theorem Kruskal's_Hg : ¬ is_good (fst ∘ (val ∘ Kruskal's_g)) embeds := bad_Kruskal's_g
theorem trans_of_Kruskal's_g {i j : ℕ} (H1 : mbs_of_finite_tree i ≼ (Kruskal's_g j).val.1) :
mbs_of_finite_tree i ≼ mbs_of_finite_tree (Kruskal's_h j) :=
have (Kruskal's_g j).val ∈ branches (mbs_of_finite_tree (Kruskal's_h j)), from some_spec (Kruskal's_g j).2,
have (Kruskal's_g j).val.1 ≼ mbs_of_finite_tree (Kruskal's_h j), from embeds_of_branches this,
embeds_trans H1 this
theorem size_elt_Kruskal's_g_lt_mbs_finite_tree (n : ℕ) : size (Kruskal's_g n).val.1 < size (mbs_of_finite_tree (Kruskal's_h n)) :=
lt_of_size_of_branches (some_spec (Kruskal's_g n).2)
theorem Kruskal's_Hbp : size (Kruskal's_g 0).val.1 < size (mbs_of_finite_tree (Kruskal's_h 0)) := size_elt_Kruskal's_g_lt_mbs_finite_tree 0
lemma family_index_in_index_of_mbs_tree (n : ℕ) : Kruskal's_h n ∈ index_set_of_mbs_tree :=
have Kruskal's_h n = family_index (least_index + n), from rfl,
⟨(least_index + n),⟨trivial,rfl⟩⟩
theorem Kruskal's_Hh (n : ℕ) : Kruskal's_h 0 ≤ Kruskal's_h n :=
-- have Kruskal's_h 0 = family_index (least_index + 0), from rfl,
have Kruskal's_h 0 = family_index least_index, from rfl,--by simph,
have family_index least_index = least_family_index, from some_spec exists_least,
have Kruskal's_h 0 = least_family_index, by simph,
begin rw this, apply minimality, apply family_index_in_index_of_mbs_tree end
theorem Kruskal's_H : ∀ i j, mbs_of_finite_tree i ≼ (Kruskal's_g (j - Kruskal's_h 0)).val.1 → mbs_of_finite_tree i ≼ mbs_of_finite_tree (Kruskal's_h (j - Kruskal's_h 0)) := λ i j, λ H1, trans_of_Kruskal's_g H1
definition Kruskal's_comb_seq (n : ℕ) : finite_tree := @comb_seq_with_mbs _ embeds (fst ∘ (val ∘ Kruskal's_g)) Kruskal's_h size H n
theorem Kruskal's_local_contradiction : false := local_contra_of_comb_seq_with_mbs Kruskal's_h size Kruskal's_Hh H Kruskal's_Hg Kruskal's_H Kruskal's_Hbp
end
#check Kruskal's_local_contradiction
theorem embeds'_is_good : ∀ f, is_good f embeds' :=
by_contradiction
(suppose ¬ ∀ f, is_good f embeds',
have ∃ f, ¬ is_good f embeds', from classical.exists_not_of_not_forall this,
Kruskal's_local_contradiction this)
instance wqo_mbs_tree : wqo mbs_tree :=
⟨⟨⟨embeds'⟩,embeds'_refl,embeds'_trans⟩,embeds'_is_good⟩
definition wqo_finite_subsets_of_mbs_tree : wqo (finite_subsets mbs_tree) := wqo_finite_subsets
definition os : finite_subsets mbs_tree → finite_subsets mbs_tree → Prop := wqo_finite_subsets_of_mbs_tree.le
-- type mbs_tree is the collection of all branches at roots appearing in the mbs_of_finite_tree
-- hence, mbs_of_finite_tree can be viewed as a sequence on finite_subsets mbs_tree. We call this sequence a copy (or a mirror) of mbs_of_finite_tree.
-- the following theorem says given any sequence f : ℕ → finite_subsets mbs_tree, there exists i j such that there exists a f' : mbs_tree → mbs_tree which is injective and nondescending from (f i) to (f j).
theorem good_finite_subsets_of_mbs_tree : ∀ f, is_good f os := wqo_finite_subsets_of_mbs_tree.is_good
-- Intuitively, the above f' is already a witness of the goodness of mbs_of_finite_tree, as it maps each branch of mbs_of_finite_tree i to a branch of mbs_of_finite_tree j. (Also note that there is no node in the mbs_of_finite_tree.)
-- However, according to the definition of embeds, f' has to be of type fin n → fin m for some n,m ∈ ℕ, representing a permutation on the labels of the branches. The following construction recovers the desired function from f'.
-- branches at root of mbs_of_finite_tree form a set of mbs_tree
definition elt_mirror (n : ℕ) : set mbs_tree := {x : mbs_tree | x.1 ∈ seq_branches_of_mbs_tree n}
theorem mirror_refl_left (x : mbs_tree) (n : ℕ) : x ∈ elt_mirror n → x.1 ∈ seq_branches_of_mbs_tree n := λ Hx, Hx
theorem mirror_refl_right (x : mbs_tree) (n : ℕ) : x.1 ∈ seq_branches_of_mbs_tree n → x ∈ elt_mirror n := λ Hx, Hx
instance finite_seq_branches (n : ℕ) : finite (seq_branches_of_mbs_tree n) := finite_branches (mbs_of_finite_tree n)
theorem finite_elt (n : ℕ) : finite (elt_mirror n) :=
have mapsto : maps_to subtype.val (elt_mirror n) (seq_branches_of_mbs_tree n), from λ x Hx, mirror_refl_left x n Hx,
have inj_on subtype.val (elt_mirror n), from λ x₁ x₂ H₁ H₂, subtype.eq,
finite_of_inj_on mapsto this
-- this gives a sequence of finite_subsets of mbs_tree.
-- mirror_of_seq_branches 0 is the branches at the root of the first element of the minimal bad sequence of finite_tree.
definition mirror (n : ℕ) : finite_subsets mbs_tree := ⟨elt_mirror n, finite_elt n⟩
-- (mirror i) is the collection of branches at the root of (mbs_of_finite_tree i)
theorem good_mirror : ∃ i j, i < j ∧ os (mirror i) (mirror j) := good_finite_subsets_of_mbs_tree mirror
section
-- destruct the statement: os (mirror i) (mirror j)
-- we want to show that there exists some i j such that (mbs_of_finite_tree i ≼ mbs_of_finite_tree j)
-- fortunately, i and j from good_mirror suffice
-- this section tries to get an injection "recover" : fin ni → fin nj such that tsi ti ≼ tsj (recover ti) assuming that (mbs_of_finite_tree i = cons tsi) and (mbs_of_finite_tree j = cons tsj). Note that both are not nodes.
parameters {i j : ℕ}
-- -- since finite_subsets_of_mbs_tree is good, we have an injection f' from some set of branches to some set of branches. This is because each set of branches is a subset of mbs_tree.
parameter f' : mbs_tree → mbs_tree
parameter inj : inj_from_to f' (elt_mirror i) (elt_mirror j)
-- -- of course, it is also nondescending by definition.
parameter nond : ∀ a : mbs_tree, a.val ∈ seq_branches_of_mbs_tree i → a.val.1 ≼ (f' a).val.1 ∧ (f' a).val ∈ seq_branches_of_mbs_tree j
-- suppose (mbs_of_finite_tree i) is of the form (cons tsi)
parameters ni nj : ℕ
parameters (tsi : fin ni → finite_tree) (tsj : fin nj → finite_tree)
-- suppose we know that they are destructed
parameter eqi : mbs_of_finite_tree i = cons tsi
parameter eqj : mbs_of_finite_tree j = cons tsj
-- this reminds us that each branch at the root of (mbs_of_finite_tree i) is in (seq_branches_of_mbs_tree i)
parameter Htsi : ∀ a, (tsi a, val a) ∈ seq_branches_of_mbs_tree i
-- lemma eltini (ti : fin ni) : (tsi ti, val ti) ∈ seq_branches_of_mbs_tree i := Htsi ti
-- every ti corresponds to some seq_branches_of_mbs_tree i
lemma foo (ti : fin ni) : ∃ i, (tsi ti, val ti) ∈ seq_branches_of_mbs_tree i := ⟨i,Htsi ti⟩
-- given a ti, find the corresponding mbs_tree of (tsi ti). The intuition is that this mbs_tree is itself, but of a different type.
definition mbst_form (ti : fin ni) : mbs_tree := ⟨(tsi ti, val ti),(foo ti)⟩
theorem mem_mbst_form (a : fin ni) : mbst_form a ∈ elt_mirror i := Htsi a
theorem eq_of_mbst_form {a₁ a₂ : fin ni} (Heq : mbst_form a₁ = mbst_form a₂) : a₁ = a₂ :=
by apply eq_of_veq;super
-- lemma mem (ti : fin ni) : (f' (mbst_form ti)).val ∈ branches (mbs_of_finite_tree j) :=
-- (nond _ (begin dsimp [mbst_form], apply Htsi end))^.right
include eqj
-- recover :
-- 1. find the mbst_form of ti, say x.
-- 2. By nond, we know that (f' x) is in (seq_branches_of_mbs_tree j).
-- 3. (seq_branches_of_mbs_tree j) is just branches (mbs_of_finite_tree j).
-- 4. The latter is just (set_of_branches tsj).
-- 5. This means that some a : fin nj corresponds to ti. 6. By choice, take such a fin nj.
definition recover (ti : fin ni) : fin nj :=
have (f' (mbst_form ti)).val ∈ seq_branches_of_mbs_tree j, from (nond _ (begin dsimp [mbst_form], apply Htsi end))^.right,
have mem : (f' (mbst_form ti)).val ∈ branches (mbs_of_finite_tree j), from this, -- this line is redundant
have branches (mbs_of_finite_tree j) = branches (cons tsj), by rw eqj, -- by rw eqj at this{2};exact this,
-- have branches (mbs_of_finite_tree j) = branches_aux tsj, from this,
have (f' (mbst_form ti)).val ∈ branches_aux tsj, by rw this at mem;exact mem,
-- have ∃ a : fin nj, tsj a = (f' (mbst_form ti)).val.1 ∧ val a = (f' (mbst_form ti)).val.2, from this,
some this
theorem perm_recover (ti : fin ni) : tsi ti ≼ tsj (recover ti) :=
have (f' (mbst_form ti)).val ∈ seq_branches_of_mbs_tree j, from (nond _ (begin dsimp [mbst_form], apply Htsi end))^.right,
have mem : (f' (mbst_form ti)).val ∈ branches (mbs_of_finite_tree j), from this,
-- have branches (mbs_of_finite_tree j) = branches (mbs_of_finite_tree j), from rfl,
have branches (mbs_of_finite_tree j) = branches (cons tsj), by rw eqj, -- by rw eqj at this{2};exact this,
-- have branches (mbs_of_finite_tree j) = branches_aux tsj, from this,
have (f' (mbst_form ti)).val ∈ branches_aux tsj, by rw this at mem;exact mem,
-- have ∃ a : fin nj, tsj a = (f' (mbst_form ti)).val.1 ∧ val a = (f' (mbst_form ti)).val.2, from this,
have tsj (recover ti) = (f' (mbst_form ti)).val.1, from let ⟨a,b⟩ := some_spec this in a,
have tsi ti ≼ (f' (mbst_form ti)).val.1, from (nond _ (begin dsimp [mbst_form], apply Htsi end))^.left,
by simph
theorem inj_recover : injective recover :=
λ a₁ a₂ Heq,
have (f' (mbst_form a₁)).val ∈ seq_branches_of_mbs_tree j, from (nond _ (begin dsimp [mbst_form], apply Htsi end))^.right,
have mem : (f' (mbst_form a₁)).val ∈ branches (mbs_of_finite_tree j), from this,
-- have branches (mbs_of_finite_tree j) = branches (mbs_of_finite_tree j), from rfl,
have branches (mbs_of_finite_tree j) = branches (cons tsj), by rw eqj, -- by rw eqj at this{2};exact this,
-- have branches (mbs_of_finite_tree j) = branches_aux tsj, from this,
have (f' (mbst_form a₁)).val ∈ branches_aux tsj, by rw this at mem;exact mem,
have eeq1 : ∃ a : fin nj, tsj a = (f' (mbst_form a₁)).val.1 ∧ val a = (f' (mbst_form a₁)).val.2, from this,
have pr11 : tsj (recover a₁) = (f' (mbst_form a₁)).val.1, from let ⟨a,b⟩ := some_spec eeq1 in a,-- proof and.left (some_spec eeq1) qed,
have pr21 : val (recover a₁) = (f' (mbst_form a₁)).val.2, from let ⟨a,b⟩ := some_spec eeq1 in b, -- proof and.right (some_spec eeq1) qed,
have (f' (mbst_form a₂)).val ∈ seq_branches_of_mbs_tree j, from (nond _ (begin dsimp [mbst_form], apply Htsi end))^.right,-- proof and.right (nond _ (eltini a₂)) qed,
have mem : (f' (mbst_form a₂)).val ∈ branches (mbs_of_finite_tree j), from this,
-- have branches (mbs_of_finite_tree j) = branches (mbs_of_finite_tree j), from rfl,
have branches (mbs_of_finite_tree j) = branches (cons tsj), by rw eqj, -- by+ rw eqj at this{2};exact this,
-- have branches (mbs_of_finite_tree j) = branches_aux tsj, from this,
have (f' (mbst_form a₂)).val ∈ branches_aux tsj, by rw this at mem;exact mem,
have eeq2 : ∃ a : fin nj, tsj a = (f' (mbst_form a₂)).val.1 ∧ val a = (f' (mbst_form a₂)).val.2, from this,
have pr12 : tsj (recover a₂) = (f' (mbst_form a₂)).val.1, from let ⟨a,b⟩ := some_spec eeq2 in a,-- proof and.left (some_spec eeq2) qed,
have pr22 : val (recover a₂) = (f' (mbst_form a₂)).val.2, from let ⟨a,b⟩ := some_spec eeq2 in b,-- proof and.right (some_spec eeq2) qed,
have eq1 : (f' (mbst_form a₁)).val.1 = (f' (mbst_form a₂)).val.1, by rw [-pr12, -pr11, Heq],
have (f' (mbst_form a₁)).val.2 = (f' (mbst_form a₂)).val.2, by rw [-pr22,-pr21,Heq],
have (f' (mbst_form a₁)).val = (f' (mbst_form a₂)).val, from eq_of_prod eq1 this,
have f'eq : f' (mbst_form a₁) = f' (mbst_form a₂), from subtype.eq this,
have ∀ x₁ x₂ : mbs_tree, x₁ ∈ elt_mirror i → x₂ ∈ elt_mirror i → f' x₁ = f' x₂ → x₁ = x₂, from and.right inj,
have mbst_form a₁ = mbst_form a₂, from this (mbst_form a₁) (mbst_form a₂) (mem_mbst_form a₁) (mem_mbst_form a₂) f'eq,
show _, from eq_of_mbst_form this
end
#check @recover
#check inj_recover
theorem good_mbs_of_finite_tree : ∃ i j, i < j ∧ mbs_of_finite_tree i ≼ mbs_of_finite_tree j :=
let ⟨i,j,⟨iltj,⟨f',⟨inj,nond⟩⟩⟩⟩ := good_mirror in
let ⟨ni,tsi,htsi⟩ := @finite_tree_destruct (mbs_of_finite_tree i) in
let ⟨nj,tsj,htsj⟩ := @finite_tree_destruct (mbs_of_finite_tree j) in
have Htsi : ∀ a, (tsi a, val a) ∈ seq_branches_of_mbs_tree i, from take a, mem_of_seq_branches tsi a htsi,
let f (a : fin ni) : fin nj := recover f' nond ni _ tsi tsj htsj Htsi a in
have injf : injective f, from inj_recover _ inj _ _ _ _ _ _ _,
have ∀ z : fin ni, tsi z ≼ tsj (f z), from λ z, perm_recover _ _ _ _ _ _ _ _ _,
have cons tsi ≼ cons tsj, from or.inr ⟨f,⟨injf,this⟩⟩,
have mbs_of_finite_tree i ≼ mbs_of_finite_tree j, by simph,
⟨i,j,⟨iltj,this⟩⟩
theorem Kruskal's_contradiction : false := bad_mbs_finite_tree good_mbs_of_finite_tree
end
theorem embeds_is_good : ∀ f, is_good f embeds :=
by_contradiction
(suppose ¬ ∀ f, is_good f embeds,
have ∃ f, ¬ is_good f embeds, from classical.exists_not_of_not_forall this,
Kruskal's_contradiction this)
def wqo_finite_tree : wqo finite_tree :=
⟨⟨⟨embeds⟩,embeds_refl,@embeds_trans⟩,embeds_is_good⟩
|
3dac7c6c80da661ec5e33c575b260e4e06671dd5
|
d406927ab5617694ec9ea7001f101b7c9e3d9702
|
/src/algebra/category/fgModule/limits.lean
|
f4c114b7dccdb066fe35070e086343d8fa03d47f
|
[
"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,920
|
lean
|
/-
Copyright (c) 2022 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import algebra.category.fgModule.basic
import algebra.category.Module.limits
import algebra.category.Module.products
import algebra.category.Module.epi_mono
import category_theory.limits.creates
import category_theory.limits.shapes.finite_limits
import category_theory.limits.constructions.limits_of_products_and_equalizers
/-!
# `forget₂ (fgModule K) (Module K)` creates all finite limits.
And hence `fgModule K` has all finite limits.
## Future work
After generalising `fgModule` to allow the ring and the module to live in different universes,
generalize this construction so we can take limits over smaller diagrams,
as is done for the other algebraic categories.
Analogous constructions for Noetherian modules.
-/
noncomputable theory
universes v u
open category_theory
open category_theory.limits
namespace fgModule
variables {J : Type} [small_category J] [fin_category J]
variables {k : Type v} [field k]
instance {J : Type} [fintype J] (Z : J → Module.{v} k) [∀ j, finite_dimensional k (Z j)] :
finite_dimensional k (∏ λ j, Z j : Module.{v} k) :=
begin
haveI : finite_dimensional k (Module.of k (Π j, Z j)), { dsimp, apply_instance, },
exact finite_dimensional.of_injective
(Module.pi_iso_pi _).hom
((Module.mono_iff_injective _).1 (by apply_instance)),
end
/-- Finite limits of finite dimensional vectors spaces are finite dimensional,
because we can realise them as subobjects of a finite product. -/
instance (F : J ⥤ fgModule k) :
finite_dimensional k (limit (F ⋙ forget₂ (fgModule k) (Module.{v} k)) : Module.{v} k) :=
begin
haveI : ∀ j, finite_dimensional k ((F ⋙ forget₂ (fgModule k) (Module.{v} k)).obj j),
{ intro j, change finite_dimensional k (F.obj j).obj, apply_instance, },
exact finite_dimensional.of_injective
(limit_subobject_product (F ⋙ forget₂ (fgModule k) (Module.{v} k)))
((Module.mono_iff_injective _).1 (by apply_instance)),
end
/-- The forgetful functor from `fgModule k` to `Module k` creates all finite limits. -/
def forget₂_creates_limit (F : J ⥤ fgModule k) :
creates_limit F (forget₂ (fgModule k) (Module.{v} k)) :=
creates_limit_of_fully_faithful_of_iso
⟨(limit (F ⋙ forget₂ (fgModule k) (Module.{v} k)) : Module.{v} k), by apply_instance⟩
(iso.refl _)
instance : creates_limits_of_shape J (forget₂ (fgModule k) (Module.{v} k)) :=
{ creates_limit := λ F, forget₂_creates_limit F, }
instance : has_finite_limits (fgModule k) :=
{ out := λ J _ _, by exactI
has_limits_of_shape_of_has_limits_of_shape_creates_limits_of_shape
(forget₂ (fgModule k) (Module.{v} k)), }
instance : preserves_finite_limits (forget₂ (fgModule k) (Module.{v} k)) :=
{ preserves_finite_limits := λ J _ _, by exactI infer_instance, }
end fgModule
|
735f476f8520def11fdffcb342a66344f63bcb81
|
4e3bf8e2b29061457a887ac8889e88fa5aa0e34c
|
/lean/love10_denotational_semantics_demo.lean
|
1fbe2d2741771ef212344a3257bbc45d7515d1ab
|
[] |
no_license
|
mukeshtiwari/logical_verification_2019
|
9f964c067a71f65eb8884743273fbeef99e6503d
|
16f62717f55ed5b7b87e03ae0134791a9bef9b9a
|
refs/heads/master
| 1,619,158,844,208
| 1,585,139,500,000
| 1,585,139,500,000
| 249,906,380
| 0
| 0
| null | 1,585,118,728,000
| 1,585,118,727,000
| null |
UTF-8
|
Lean
| false
| false
| 6,470
|
lean
|
/- LoVe Demo 10: Denotational Semantics -/
import .love08_operational_semantics_demo
namespace LoVe
/- Complete Lattices -/
class complete_lattice (α : Type)
extends partial_order α :=
(Inf : set α → α)
(Inf_le : ∀s a, a ∈ s → Inf s ≤ a)
(le_Inf : ∀s a, (∀a', a' ∈ s → a ≤ a') → a ≤ Inf s)
/- Instance for Complete Lattices: `set α` -/
namespace set
instance (α : Type) : complete_lattice (set α) :=
{ le := (⊆),
le_refl :=
assume s a h,
h,
le_trans :=
assume s t u hst htu a has,
htu (hst has),
le_antisymm :=
begin
intros s t hst hts,
apply set.ext,
intro a,
apply iff.intro,
apply hst,
apply hts
end,
Inf := λf, {a | ∀s, s ∈ f → a ∈ s},
Inf_le :=
begin
intros f s hsf a h,
simp at h,
exact h s hsf
end,
le_Inf :=
assume f s h a has t htf,
h t htf has }
end set
/- Monotonicity of Functions -/
def monotone {α β : Type} [partial_order α] [partial_order β]
(f : α → β) : Prop :=
∀a₁ a₂, a₁ ≤ a₂ → f a₁ ≤ f a₂
namespace monotone
lemma id {α : Type} [partial_order α] :
monotone (λa : α, a) :=
assume a₁ a₂ ha,
ha
lemma const {α β : Type} [partial_order α] [partial_order β]
(b : β) :
monotone (λa : α, b) :=
assume a₁ a₂ ha,
le_refl b
lemma union {α β : Type} [partial_order α] (f g : α → set β)
(hf : monotone f) (hg : monotone g) :
monotone (λa, f a ∪ g a) :=
begin
intros a₁ a₂ ha b hb,
cases hb,
{ exact or.intro_left _ (hf a₁ a₂ ha hb) },
{ exact or.intro_right _ (hg a₁ a₂ ha hb) }
end
end monotone
/- Least Fixpoint -/
namespace complete_lattice
variables {α : Type} [complete_lattice α]
def lfp (f : α → α) : α :=
Inf {x | f x ≤ x}
lemma lfp_le (f : α → α) (a : α) (h : f a ≤ a) :
lfp f ≤ a :=
Inf_le _ _ h
lemma le_lfp (f : α → α) (a : α) (h : ∀a', f a' ≤ a' → a ≤ a') :
a ≤ lfp f :=
le_Inf _ _ h
lemma lfp_eq (f : α → α) (hf : monotone f) :
lfp f = f (lfp f) :=
begin
have h : f (lfp f) ≤ lfp f :=
begin
apply le_lfp,
intros a' ha',
apply @le_trans _ _ _ (f a'),
{ apply hf,
apply lfp_le,
assumption },
{ assumption }
end,
apply le_antisymm,
{ apply lfp_le,
apply hf,
assumption },
{ assumption }
end
end complete_lattice
/- Relations -/
def Id (α : Type) : set (α × α) :=
{x | x.2 = x.1}
@[simp] lemma mem_Id {α : Type} (a b : α) :
(a, b) ∈ Id α ↔ b = a :=
iff.rfl
def comp {α : Type} (r₁ r₂ : set (α × α)) : set (α × α) :=
{x | ∃y, (x.1, y) ∈ r₁ ∧ (y, x.2) ∈ 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₂) :=
iff.rfl
def restrict {α : Type} (r : set (α × α)) (b : α → Prop) :
set (α × α) :=
{x | b x.1 ∧ x ∈ r}
infixl ` ⇃ ` : 90 := restrict
@[simp] lemma mem_restrict {α : Type} (r : set (α × α))
(p : α → Prop) (a b : α) :
(a, b) ∈ r ⇃ p ↔ p a ∧ (a, b) ∈ r :=
by refl
/- We will prove the following two lemmas in the exercise. -/
namespace sorry_lemmas
lemma monotone_comp {α β : Type} [partial_order α]
(f g : α → set (β × β)) (hf : monotone f)
(hg : monotone g) :
monotone (λa, f a ◯ g a) :=
sorry
lemma monotone_restrict {α β : Type} [partial_order α]
(f : α → set (β × β)) (p : β → Prop) (hf : monotone f) :
monotone (λa, f a ⇃ p) :=
sorry
end sorry_lemmas
/- A Relational Denotational Semantics -/
def den : program → set (state × state)
| skip := Id state
| (assign n a) := {x | x.2 = x.1{n ↦ a x.1}}
| (seq S₁ S₂) := den S₁ ◯ den S₂
| (ite b S₁ S₂) := (den S₁ ⇃ b) ∪ (den S₂ ⇃ λs, ¬ b s)
| (while b S) :=
complete_lattice.lfp
(λX, ((den S ◯ X) ⇃ b) ∪ (Id state ⇃ λs, ¬ b s))
notation `⟦` S `⟧`:= den S
lemma den_while (S : program) (b : state → Prop) :
⟦while b S⟧ = ⟦ite b (S ;; while b S) skip⟧ :=
begin
apply complete_lattice.lfp_eq,
apply monotone.union,
{ apply sorry_lemmas.monotone_restrict,
apply sorry_lemmas.monotone_comp,
{ exact monotone.const _ },
{ exact monotone.id } },
{ exact monotone.const _ }
end
/- (**optional**) Equivalence of the Denotational and the
Big-Step Semantics -/
lemma den_of_big_step (S : program) (s t : state) :
(S, s) ⟹ t → (s, t) ∈ ⟦S⟧ :=
begin
generalize eq : (S, s) = Ss,
intro h,
induction h generalizing eq S s;
cases eq;
-- simplify only if `simp` solves the goal completely
try { simp [den, *], done },
{ use h_t,
exact and.intro (h_ih_h₁ _ _ rfl) (h_ih_h₂ _ _ rfl) },
{ rw [den_while, den],
simp [*],
use h_t,
exact and.intro (h_ih_hbody _ _ rfl) (h_ih_hrest _ _ rfl) },
{ rw [den_while],
simp [den, *] }
end
lemma big_step_of_den :
∀(S : program) (s t : state), (s, t) ∈ ⟦S⟧ → (S, s) ⟹ t
| skip s t :=
by simp [den] { contextual := tt };
exact _
| (assign n a) s t :=
by simp [den] { contextual := tt }
| (seq S₁ S₂) s t :=
begin
intro h,
cases h with u hu,
exact big_step.seq
(big_step_of_den S₁ _ _ (and.elim_left hu))
(big_step_of_den S₂ _ _ (and.elim_right hu))
end
| (ite b S₁ S₂) s t :=
assume h,
match h with
| or.intro_left _ (and.intro hs hst) :=
big_step.ite_true hs (big_step_of_den S₁ _ _ hst)
| or.intro_right _ (and.intro hs hst) :=
big_step.ite_false hs (big_step_of_den S₂ _ _ hst)
end
| (while b S) s t :=
begin
have hw : ⟦while b S⟧ ≤ {x | (while b S, x.1) ⟹ x.2} :=
begin
apply complete_lattice.lfp_le _ _ _,
intros x hx,
cases x with s t,
simp at hx,
cases hx,
{ cases hx with hs hst,
cases hst with u hu,
apply big_step.while_true hs,
{ exact big_step_of_den S _ _ (and.elim_left hu) },
{ exact and.elim_right hu } },
{ cases hx,
cases hx_right,
apply big_step.while_false hx_left }
end,
apply hw
end
lemma den_eq_bigstep (S : program) (s t : state) :
(s, t) ∈ ⟦S⟧ ↔ (S, s) ⟹ t :=
iff.intro (big_step_of_den S s t) (den_of_big_step S s t)
end LoVe
|
4a4be09636cbe608c1b5137a3da82ed7990097b6
|
64874bd1010548c7f5a6e3e8902efa63baaff785
|
/library/logic/subsingleton.lean
|
0fe2e0ddc13761c6c1afd67d734d3e2ac0300d29
|
[
"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
| 1,419
|
lean
|
/-
Copyright (c) 2014 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Module: logic.subsingleton
Author: Floris van Doorn
-/
import logic.eq
inductive subsingleton [class] (A : Type) : Prop :=
intro : (∀ a b : A, a = b) → subsingleton A
namespace subsingleton
definition elim {A : Type} {H : subsingleton A} : ∀(a b : A), a = b := rec (fun p, p) H
end subsingleton
protected definition prop.subsingleton [instance] (P : Prop) : subsingleton P :=
subsingleton.intro (λa b, !proof_irrel)
theorem irrelevant [instance] (p : Prop) : subsingleton (decidable p) :=
subsingleton.intro (fun d1 d2,
decidable.rec
(assume Hp1 : p, decidable.rec
(assume Hp2 : p, congr_arg decidable.inl (eq.refl Hp1)) -- using proof irrelevance for Prop
(assume Hnp2 : ¬p, absurd Hp1 Hnp2)
d2)
(assume Hnp1 : ¬p, decidable.rec
(assume Hp2 : p, absurd Hp2 Hnp1)
(assume Hnp2 : ¬p, congr_arg decidable.inr (eq.refl Hnp1)) -- using proof irrelevance for Prop
d2)
d1)
protected theorem rec_subsingleton [instance] {p : Prop} [H : decidable p]
{H1 : p → Type} {H2 : ¬p → Type}
(H3 : Π(h : p), subsingleton (H1 h)) (H4 : Π(h : ¬p), subsingleton (H2 h))
: subsingleton (decidable.rec_on H H1 H2) :=
decidable.rec_on H (λh, H3 h) (λh, H4 h) --this can be proven using dependent version of "by_cases"
|
32436da9ce9ad3fb2bf268dd093ecac3d55fb089
|
a9d0fb7b0e4f802bd3857b803e6c5c23d87fef91
|
/library/data/squash.lean
|
33370c5ff1c73ec015d169bf19c5d1b4a2784253
|
[
"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
| 1,839
|
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
Define squash type (aka propositional truncation) using quotients.
This definition is slightly better than defining the squash type ∥A∥ as (nonempty A).
If we define it using (nonempty A), then we can only lift functions A → B to ∥A∥ → B
when B is a proposition. With quotients, we can lift to any B type that is a subsingleton
(i.e., has at most one element).
-/
open quot
private definition eqv {A : Type} (a b : A) : Prop := true
local infix ~ := eqv
private lemma eqv_refl {A : Type} : ∀ a : A, a ~ a :=
λ a, trivial
private lemma eqv_symm {A : Type} : ∀ a b : A, a ~ b → b ~ a :=
λ a b h, trivial
private lemma eqv_trans {A : Type} : ∀ a b c : A, a ~ b → b ~ c → a ~ c :=
λ a b c h₁ h₂, trivial
definition squash_setoid (A : Type) : setoid A :=
setoid.mk (@eqv A) (mk_equivalence (@eqv A) (@eqv_refl A) (@eqv_symm A) (@eqv_trans A))
definition squash (A : Type) : Type :=
quot (squash_setoid A)
namespace squash
local attribute squash_setoid [instance]
notation `∥`:0 A `∥` := squash A
definition mk {A : Type} (a : A) : ∥A∥ :=
⟦a⟧
protected definition irrelevant {A : Type} : ∀ a b : ∥A∥, a = b :=
λ a b, quot.induction_on₂ a b (λ a b, quot.sound trivial)
definition lift {A B : Type} [h : subsingleton B] (f : A → B) : ∥A∥ → B :=
λ s, quot.lift_on s f (λ a₁ a₂ r, subsingleton.elim (f a₁) (f a₂))
end squash
open squash decidable
attribute [instance]
definition decidable_eq_squash (A : Type) : decidable_eq ∥A∥ :=
λ a b, inl (squash.irrelevant a b)
attribute [instance]
definition subsingleton_squash (A : Type) : subsingleton ∥A∥ :=
subsingleton.intro (@squash.irrelevant A)
|
8200378868ceed05fb3990c97bf29080b3c39c83
|
82e44445c70db0f03e30d7be725775f122d72f3e
|
/src/ring_theory/polynomial/chebyshev.lean
|
eaeb9496d582e171eeba989a92e11d707e31fa4c
|
[
"Apache-2.0"
] |
permissive
|
stjordanis/mathlib
|
51e286d19140e3788ef2c470bc7b953e4991f0c9
|
2568d41bca08f5d6bf39d915434c8447e21f42ee
|
refs/heads/master
| 1,631,748,053,501
| 1,627,938,886,000
| 1,627,938,886,000
| 228,728,358
| 0
| 0
|
Apache-2.0
| 1,576,630,588,000
| 1,576,630,587,000
| null |
UTF-8
|
Lean
| false
| false
| 11,066
|
lean
|
/-
Copyright (c) 2020 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin, Julian Kuelshammer, Heather Macbeth
-/
import data.polynomial.derivative
import tactic.ring
/-!
# Chebyshev polynomials
The Chebyshev polynomials are two families of polynomials indexed by `ℕ`,
with integral coefficients.
## Main definitions
* `polynomial.chebyshev.T`: the Chebyshev polynomials of the first kind.
* `polynomial.chebyshev.U`: the Chebyshev polynomials of the second kind.
## Main statements
* The formal derivative of the Chebyshev polynomials of the first kind is a scalar multiple of the
Chebyshev polynomials of the second kind.
* `polynomial.chebyshev.mul_T`, the product of the `m`-th and `(m + k)`-th Chebyshev polynomials of
the first kind is the sum of the `(2 * m + k)`-th and `k`-th Chebyshev polynomials of the first
kind.
* `polynomial.chebyshev.T_mul`, the `(m * n)`-th Chebyshev polynomial of the first kind is the
composition of the `m`-th and `n`-th Chebyshev polynomials of the first kind.
## Implementation details
Since Chebyshev polynomials have interesting behaviour over the complex numbers and modulo `p`,
we define them to have coefficients in an arbitrary commutative ring, even though
technically `ℤ` would suffice.
The benefit of allowing arbitrary coefficient rings, is that the statements afterwards are clean,
and do not have `map (int.cast_ring_hom R)` interfering all the time.
## References
[Lionel Ponton, _Roots of the Chebyshev polynomials: A purely algebraic approach_]
[ponton2020chebyshev]
## TODO
* Redefine and/or relate the definition of Chebyshev polynomials to `linear_recurrence`.
* Add explicit formula involving square roots for Chebyshev polynomials
* Compute zeroes and extrema of Chebyshev polynomials.
* Prove that the roots of the Chebyshev polynomials (except 0) are irrational.
* Prove minimax properties of Chebyshev polynomials.
-/
noncomputable theory
namespace polynomial.chebyshev
open polynomial
variables (R S : Type*) [comm_ring R] [comm_ring S]
/-- `T n` is the `n`-th Chebyshev polynomial of the first kind -/
noncomputable def T : ℕ → polynomial R
| 0 := 1
| 1 := X
| (n + 2) := 2 * X * T (n + 1) - T n
@[simp] lemma T_zero : T R 0 = 1 := rfl
@[simp] lemma T_one : T R 1 = X := rfl
lemma T_two : T R 2 = 2 * X ^ 2 - 1 :=
by simp only [T, sub_left_inj, sq, mul_assoc]
@[simp] lemma T_add_two (n : ℕ) :
T R (n + 2) = 2 * X * T R (n + 1) - T R n :=
by rw T
lemma T_of_two_le (n : ℕ) (h : 2 ≤ n) :
T R n = 2 * X * T R (n - 1) - T R (n - 2) :=
begin
obtain ⟨n, rfl⟩ := nat.exists_eq_add_of_le h,
rw add_comm,
exact T_add_two R n
end
variables {R S}
lemma map_T (f : R →+* S) :
∀ (n : ℕ), map f (T R n) = T S n
| 0 := by simp only [T_zero, map_one]
| 1 := by simp only [T_one, map_X]
| (n + 2) :=
begin
simp only [T_add_two, map_mul, map_sub, map_X, bit0, map_add, map_one],
rw [map_T (n + 1), map_T n],
end
variables (R S)
/-- `U n` is the `n`-th Chebyshev polynomial of the second kind -/
noncomputable def U : ℕ → polynomial R
| 0 := 1
| 1 := 2 * X
| (n + 2) := 2 * X * U (n + 1) - U n
@[simp] lemma U_zero : U R 0 = 1 := rfl
@[simp] lemma U_one : U R 1 = 2 * X := rfl
lemma U_two : U R 2 = 4 * X ^ 2 - 1 :=
by { simp only [U], ring, }
@[simp] lemma U_add_two (n : ℕ) :
U R (n + 2) = 2 * X * U R (n + 1) - U R n :=
by rw U
lemma U_of_two_le (n : ℕ) (h : 2 ≤ n) :
U R n = 2 * X * U R (n - 1) - U R (n - 2) :=
begin
obtain ⟨n, rfl⟩ := nat.exists_eq_add_of_le h,
rw add_comm,
exact U_add_two R n
end
lemma U_eq_X_mul_U_add_T :
∀ (n : ℕ), U R (n+1) = X * U R n + T R (n+1)
| 0 := by { simp only [U_zero, U_one, T_one], ring }
| 1 := by { simp only [U_one, T_two, U_two], ring }
| (n + 2) :=
calc U R (n + 2 + 1) = 2 * X * (X * U R (n + 1) + T R (n + 2)) - (X * U R n + T R (n + 1)) :
by simp only [U_add_two, U_eq_X_mul_U_add_T n, U_eq_X_mul_U_add_T (n + 1)]
... = X * (2 * X * U R (n + 1) - U R n) + (2 * X * T R (n + 2) - T R (n + 1)) : by ring
... = X * U R (n + 2) + T R (n + 2 + 1) : by simp only [U_add_two, T_add_two]
lemma T_eq_U_sub_X_mul_U (n : ℕ) :
T R (n+1) = U R (n+1) - X * U R n :=
by rw [U_eq_X_mul_U_add_T, add_comm (X * U R n), add_sub_cancel]
lemma T_eq_X_mul_T_sub_pol_U :
∀ (n : ℕ), T R (n+2) = X * T R (n+1) - (1 - X ^ 2) * U R n
| 0 := by { simp only [T_one, T_two, U_zero], ring }
| 1 := by { simp only [T_add_two, T_zero, T_add_two,
U_one, T_one], ring }
| (n + 2) :=
calc T R (n + 2 + 2)
= 2 * X * T R (n + 2 + 1) - T R (n + 2) : T_add_two _ _
... = 2 * X * (X * T R (n + 2) - (1 - X ^ 2) * U R (n + 1))
- (X * T R (n + 1) - (1 - X ^ 2) * U R n) : by simp only [T_eq_X_mul_T_sub_pol_U]
... = X * (2 * X * T R (n + 2) - T R (n + 1)) - (1 - X ^ 2) * (2 * X * U R (n + 1) - U R n) :
by ring
... = X * T R (n + 2 + 1) - (1 - X ^ 2) * U R (n + 2) : by rw [T_add_two _ (n + 1), U_add_two]
lemma one_sub_X_sq_mul_U_eq_pol_in_T (n : ℕ) :
(1 - X ^ 2) * U R n = X * T R (n + 1) - T R (n + 2) :=
by rw [T_eq_X_mul_T_sub_pol_U, ←sub_add, sub_self, zero_add]
variables {R S}
@[simp] lemma map_U (f : R →+* S) :
∀ (n : ℕ), map f (U R n) = U S n
| 0 := by simp only [U_zero, map_one]
| 1 :=
begin
simp only [U_one, map_X, map_mul, map_add, map_one],
change map f (1+1) * X = 2 * X,
simpa only [map_add, map_one]
end
| (n + 2) :=
begin
simp only [U_add_two, map_mul, map_sub, map_X, bit0, map_add, map_one],
rw [map_U (n + 1), map_U n],
end
lemma T_derivative_eq_U :
∀ (n : ℕ), derivative (T R (n + 1)) = (n + 1) * U R n
| 0 := by simp only [T_one, U_zero, derivative_X, nat.cast_zero, zero_add, mul_one]
| 1 := by { simp only [T_two, U_one, derivative_sub, derivative_one, derivative_mul,
derivative_X_pow, nat.cast_one, nat.cast_two],
norm_num }
| (n + 2) :=
calc derivative (T R (n + 2 + 1))
= 2 * T R (n + 2) + 2 * X * derivative (T R (n + 1 + 1)) - derivative (T R (n + 1)) :
by simp only [T_add_two _ (n + 1), derivative_sub, derivative_mul, derivative_X,
derivative_bit0, derivative_one, bit0_zero, zero_mul, zero_add, mul_one]
... = 2 * (U R (n + 1 + 1) - X * U R (n + 1)) + 2 * X * ((n + 1 + 1) * U R (n + 1))
- (n + 1) * U R n : by rw_mod_cast [T_derivative_eq_U, T_derivative_eq_U,
T_eq_U_sub_X_mul_U]
... = (n + 1) * (2 * X * U R (n + 1) - U R n) + 2 * U R (n + 2) : by ring
... = (n + 1) * U R (n + 2) + 2 * U R (n + 2) : by rw U_add_two
... = (n + 2 + 1) * U R (n + 2) : by ring
... = (↑(n + 2) + 1) * U R (n + 2) : by norm_cast
lemma one_sub_X_sq_mul_derivative_T_eq_poly_in_T (n : ℕ) :
(1 - X ^ 2) * (derivative (T R (n+1))) =
(n + 1) * (T R n - X * T R (n+1)) :=
calc
(1 - X ^ 2) * (derivative (T R (n+1))) = (1 - X ^ 2 ) * ((n + 1) * U R n) :
by rw T_derivative_eq_U
... = (n + 1) * ((1 - X ^ 2) * U R n) : by ring
... = (n + 1) * (X * T R (n + 1) - (2 * X * T R (n + 1) - T R n)) :
by rw [one_sub_X_sq_mul_U_eq_pol_in_T, T_add_two]
... = (n + 1) * (T R n - X * T R (n+1)) : by ring
lemma add_one_mul_T_eq_poly_in_U (n : ℕ) :
((n : polynomial R) + 1) * T R (n+1) =
X * U R n - (1 - X ^ 2) * derivative ( U R n) :=
begin
have h : derivative (T R (n + 2)) = (U R (n + 1) - X * U R n) + X * derivative (T R (n + 1))
+ 2 * X * U R n - (1 - X ^ 2) * derivative (U R n),
{ conv_lhs { rw T_eq_X_mul_T_sub_pol_U },
simp only [derivative_sub, derivative_mul, derivative_X, derivative_one, derivative_X_pow,
one_mul, T_derivative_eq_U],
rw [T_eq_U_sub_X_mul_U, nat.cast_bit0, nat.cast_one],
ring },
calc ((n : polynomial R) + 1) * T R (n + 1)
= ((n : polynomial R) + 1 + 1) * (X * U R n + T R (n + 1))
- X * ((n + 1) * U R n) - (X * U R n + T R (n + 1)) : by ring
... = derivative (T R (n + 2)) - X * derivative (T R (n + 1)) - U R (n + 1) :
by rw [←U_eq_X_mul_U_add_T, ←T_derivative_eq_U, ←nat.cast_one, ←nat.cast_add,
nat.cast_one, ←T_derivative_eq_U (n + 1)]
... = (U R (n + 1) - X * U R n) + X * derivative (T R (n + 1))
+ 2 * X * U R n - (1 - X ^ 2) * derivative (U R n)
- X * derivative (T R (n + 1)) - U R (n + 1) : by rw h
... = X * U R n - (1 - X ^ 2) * derivative (U R n) : by ring,
end
variables (R)
/-- The product of two Chebyshev polynomials is the sum of two other Chebyshev polynomials. -/
lemma mul_T :
∀ m : ℕ, ∀ k,
2 * T R m * T R (m + k) = T R (2 * m + k) + T R k
| 0 := by simp [two_mul, add_mul]
| 1 := by simp [add_comm]
| (m + 2) := begin
intros k,
-- clean up the `T` nat indices in the goal
suffices : 2 * T R (m + 2) * T R (m + k + 2) = T R (2 * m + k + 4) + T R k,
{ have h_nat₁ : 2 * (m + 2) + k = 2 * m + k + 4 := by ring,
have h_nat₂ : m + 2 + k = m + k + 2 := by simp [add_comm, add_assoc],
simpa [h_nat₁, h_nat₂] using this },
-- clean up the `T` nat indices in the inductive hypothesis applied to `m + 1` and
-- `k + 1`
have H₁ : 2 * T R (m + 1) * T R (m + k + 2) = T R (2 * m + k + 3) + T R (k + 1),
{ have h_nat₁ : m + 1 + (k + 1) = m + k + 2 := by ring,
have h_nat₂ : 2 * (m + 1) + (k + 1) = 2 * m + k + 3 := by ring,
simpa [h_nat₁, h_nat₂] using mul_T (m + 1) (k + 1) },
-- clean up the `T` nat indices in the inductive hypothesis applied to `m` and `k + 2`
have H₂ : 2 * T R m * T R (m + k + 2) = T R (2 * m + k + 2) + T R (k + 2),
{ have h_nat₁ : 2 * m + (k + 2) = 2 * m + k + 2 := by simp [add_assoc],
have h_nat₂ : m + (k + 2) = m + k + 2 := by simp [add_assoc],
simpa [h_nat₁, h_nat₂] using mul_T m (k + 2) },
-- state the `T` recurrence relation for a few useful indices
have h₁ := T_add_two R m,
have h₂ := T_add_two R (2 * m + k + 2),
have h₃ := T_add_two R k,
-- the desired identity is an appropriate linear combination of H₁, H₂, h₁, h₂, h₃
-- it would be really nice here to have a linear algebra tactic!!
apply_fun (λ p, 2 * X * p) at H₁,
apply_fun (λ p, 2 * T R (m + k + 2) * p) at h₁,
have e₁ := congr (congr_arg has_add.add H₁) h₁,
have e₂ := congr (congr_arg has_sub.sub e₁) H₂,
have e₃ := congr (congr_arg has_sub.sub e₂) h₂,
have e₄ := congr (congr_arg has_sub.sub e₃) h₃,
rw ← sub_eq_zero at e₄ ⊢,
rw ← e₄,
ring,
end
/-- The `(m * n)`-th Chebyshev polynomial is the composition of the `m`-th and `n`-th -/
lemma T_mul :
∀ m : ℕ, ∀ n : ℕ, T R (m * n) = (T R m).comp (T R n)
| 0 := by simp
| 1 := by simp
| (m + 2) := begin
intros n,
have : 2 * T R n * T R ((m + 1) * n) = T R ((m + 2) * n) + T R (m * n),
{ convert mul_T R n (m * n); ring },
simp [this, T_mul m, ← T_mul (m + 1)]
end
end polynomial.chebyshev
|
5f8e06107de4666b0a5957d0a83972f404aa4853
|
4727251e0cd73359b15b664c3170e5d754078599
|
/src/data/qpf/multivariate/constructions/cofix.lean
|
b82c606ffc2319f9930e4fd2dc9b74e58aa26616
|
[
"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
| 19,004
|
lean
|
/-
Copyright (c) 2018 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Simon Hudon
-/
import control.functor.multivariate
import data.pfunctor.multivariate.basic
import data.pfunctor.multivariate.M
import data.qpf.multivariate.basic
/-!
# The final co-algebra of a multivariate qpf is again a qpf.
For a `(n+1)`-ary QPF `F (α₀,..,αₙ)`, we take the least fixed point of `F` with
regards to its last argument `αₙ`. The result is a `n`-ary functor: `fix F (α₀,..,αₙ₋₁)`.
Making `fix F` into a functor allows us to take the fixed point, compose with other functors
and take a fixed point again.
## Main definitions
* `cofix.mk` - constructor
* `cofix.dest - destructor
* `cofix.corec` - corecursor: useful for formulating infinite, productive computations
* `cofix.bisim` - bisimulation: proof technique to show the equality of possibly infinite values
of `cofix F α`
## Implementation notes
For `F` a QPF`, we define `cofix F α` in terms of the M-type of the polynomial functor `P` of `F`.
We define the relation `Mcongr` and take its quotient as the definition of `cofix F α`.
`Mcongr` is taken as the weakest bisimulation on M-type. See
[avigad-carneiro-hudon2019] for more details.
## Reference
* Jeremy Avigad, Mario M. Carneiro and Simon Hudon.
[*Data Types as Quotients of Polynomial Functors*][avigad-carneiro-hudon2019]
-/
universe u
open_locale mvfunctor
namespace mvqpf
open typevec mvpfunctor
open mvfunctor (liftp liftr)
variables {n : ℕ} {F : typevec.{u} (n+1) → Type u} [mvfunctor F] [q : mvqpf F]
include q
/-- `corecF` is used as a basis for defining the corecursor of `cofix F α`. `corecF`
uses corecursion to construct the M-type generated by `q.P` and uses function on `F`
as a corecursive step -/
def corecF {α : typevec n} {β : Type*} (g : β → F (α.append1 β)) : β → q.P.M α :=
M.corec _ (λ x, repr (g x))
theorem corecF_eq {α : typevec n} {β : Type*} (g : β → F (α.append1 β)) (x : β) :
M.dest q.P (corecF g x) = append_fun id (corecF g) <$$> repr (g x) :=
by rw [corecF, M.dest_corec]
/-- Characterization of desirable equivalence relations on M-types -/
def is_precongr {α : typevec n} (r : q.P.M α → q.P.M α → Prop) : Prop :=
∀ ⦃x y⦄, r x y →
abs (append_fun id (quot.mk r) <$$> M.dest q.P x) =
abs (append_fun id (quot.mk r) <$$> M.dest q.P y)
/-- Equivalence relation on M-types representing a value of type `cofix F` -/
def Mcongr {α : typevec n} (x y : q.P.M α) : Prop :=
∃ r, is_precongr r ∧ r x y
/-- Greatest fixed point of functor F. The result is a functor with one fewer parameters
than the input. For `F a b c` a ternary functor, fix F is a binary functor such that
```lean
cofix F a b = F a b (cofix F a b)
```
-/
def cofix (F : typevec (n + 1) → Type u) [mvfunctor F] [q : mvqpf F] (α : typevec n) :=
quot (@Mcongr _ F _ q α)
instance {α : typevec n} [inhabited q.P.A] [Π (i : fin2 n), inhabited (α i)] :
inhabited (cofix F α) := ⟨ quot.mk _ default ⟩
/-- maps every element of the W type to a canonical representative -/
def Mrepr {α : typevec n} : q.P.M α → q.P.M α := corecF (abs ∘ M.dest q.P)
/-- the map function for the functor `cofix F` -/
def cofix.map {α β : typevec n} (g : α ⟹ β) : cofix F α → cofix F β :=
quot.lift (λ x : q.P.M α, quot.mk Mcongr (g <$$> x))
begin
rintros aa₁ aa₂ ⟨r, pr, ra₁a₂⟩, apply quot.sound,
let r' := λ b₁ b₂, ∃ a₁ a₂ : q.P.M α, r a₁ a₂ ∧ b₁ = g <$$> a₁ ∧ b₂ = g <$$> a₂,
use r', split,
{ show is_precongr r',
rintros b₁ b₂ ⟨a₁, a₂, ra₁a₂, b₁eq, b₂eq⟩,
let u : quot r → quot r' := quot.lift (λ x : q.P.M α, quot.mk r' (g <$$> x))
(by { intros a₁ a₂ ra₁a₂, apply quot.sound, exact ⟨a₁, a₂, ra₁a₂, rfl, rfl⟩ }),
have hu : (quot.mk r' ∘ λ x : q.P.M α, g <$$> x) = u ∘ quot.mk r,
{ ext x, refl },
rw [b₁eq, b₂eq, M.dest_map, M.dest_map, ←q.P.comp_map, ←q.P.comp_map],
rw [←append_fun_comp, id_comp, hu, hu, ←comp_id g, append_fun_comp],
rw [q.P.comp_map, q.P.comp_map, abs_map, pr ra₁a₂, ←abs_map] },
show r' (g <$$> aa₁) (g <$$> aa₂), from ⟨aa₁, aa₂, ra₁a₂, rfl, rfl⟩
end
instance cofix.mvfunctor : mvfunctor (cofix F) :=
{ map := @cofix.map _ _ _ _}
/-- Corecursor for `cofix F` -/
def cofix.corec {α : typevec n} {β : Type u} (g : β → F (α.append1 β)) : β → cofix F α :=
λ x, quot.mk _ (corecF g x)
/-- Destructor for `cofix F` -/
def cofix.dest {α : typevec n} : cofix F α → F (α.append1 (cofix F α)) :=
quot.lift
(λ x, append_fun id (quot.mk Mcongr) <$$> (abs (M.dest q.P x)))
begin
rintros x y ⟨r, pr, rxy⟩, dsimp,
have : ∀ x y, r x y → Mcongr x y,
{ intros x y h, exact ⟨r, pr, h⟩ },
rw [←quot.factor_mk_eq _ _ this], dsimp,
conv { to_lhs,
rw [append_fun_comp_id, comp_map, ←abs_map, pr rxy, abs_map, ←comp_map,
←append_fun_comp_id] }
end
/-- Abstraction function for `cofix F α` -/
def cofix.abs {α} : q.P.M α → cofix F α :=
quot.mk _
/-- Representation function for `cofix F α` -/
def cofix.repr {α} : cofix F α → q.P.M α :=
M.corec _ $ repr ∘ cofix.dest
/-- Corecursor for `cofix F` -/
def cofix.corec'₁ {α : typevec n} {β : Type u}
(g : Π {X}, (β → X) → F (α.append1 X)) (x : β) : cofix F α :=
cofix.corec (λ x, g id) x
/-- More flexible corecursor for `cofix F`. Allows the return of a fully formed
value instead of making a recursive call -/
def cofix.corec' {α : typevec n} {β : Type u} (g : β → F (α.append1 (cofix F α ⊕ β))) (x : β) :
cofix F α :=
let f : α ::: cofix F α ⟹ α ::: (cofix F α ⊕ β) := id ::: sum.inl in
cofix.corec
(sum.elim (mvfunctor.map f ∘ cofix.dest) g)
(sum.inr x : cofix F α ⊕ β)
/-- Corecursor for `cofix F`. The shape allows recursive calls to
look like recursive calls. -/
def cofix.corec₁ {α : typevec n} {β : Type u}
(g : Π {X}, (cofix F α → X) → (β → X) → β → F (α ::: X)) (x : β) : cofix F α :=
cofix.corec' (λ x, g sum.inl sum.inr x) x
theorem cofix.dest_corec {α : typevec n} {β : Type u} (g : β → F (α.append1 β)) (x : β) :
cofix.dest (cofix.corec g x) = append_fun id (cofix.corec g) <$$> g x :=
begin
conv { to_lhs, rw [cofix.dest, cofix.corec] }, dsimp,
rw [corecF_eq, abs_map, abs_repr, ←comp_map, ←append_fun_comp], reflexivity
end
/-- constructor for `cofix F` -/
def cofix.mk {α : typevec n} : F (α.append1 $ cofix F α) → cofix F α :=
cofix.corec (λ x, append_fun id (λ i : cofix F α, cofix.dest.{u} i) <$$> x)
/-!
## Bisimulation principles for `cofix F`
The following theorems are bisimulation principles. The general idea
is to use a bisimulation relation to prove the equality between
specific values of type `cofix F α`.
A bisimulation relation `R` for values `x y : cofix F α`:
* holds for `x y`: `R x y`
* for any values `x y` that satisfy `R`, their root has the same shape
and their children can be paired in such a way that they satisfy `R`.
-/
private theorem cofix.bisim_aux {α : typevec n}
(r : cofix F α → cofix F α → Prop)
(h' : ∀ x, r x x)
(h : ∀ x y, r x y →
append_fun id (quot.mk r) <$$> cofix.dest x = append_fun id (quot.mk r) <$$> cofix.dest y) :
∀ x y, r x y → x = y :=
begin
intro x, apply quot.induction_on x, clear x,
intros x y, apply quot.induction_on y, clear y,
intros y rxy,
apply quot.sound,
let r' := λ x y, r (quot.mk _ x) (quot.mk _ y),
have : is_precongr r',
{ intros a b r'ab,
have h₀ :
append_fun id (quot.mk r ∘ quot.mk Mcongr) <$$> abs (M.dest q.P a) =
append_fun id (quot.mk r ∘ quot.mk Mcongr) <$$> abs (M.dest q.P b) :=
by rw [append_fun_comp_id, comp_map, comp_map]; exact h _ _ r'ab,
have h₁ : ∀ u v : q.P.M α, Mcongr u v → quot.mk r' u = quot.mk r' v,
{ intros u v cuv, apply quot.sound, dsimp [r'], rw quot.sound cuv, apply h' },
let f : quot r → quot r' := quot.lift (quot.lift (quot.mk r') h₁)
begin
intro c, apply quot.induction_on c, clear c,
intros c d, apply quot.induction_on d, clear d,
intros d rcd, apply quot.sound, apply rcd
end,
have : f ∘ quot.mk r ∘ quot.mk Mcongr = quot.mk r' := rfl,
rw [←this, append_fun_comp_id, q.P.comp_map, q.P.comp_map, abs_map, abs_map, abs_map,
abs_map, h₀] },
refine ⟨r', this, rxy⟩
end
/-- Bisimulation principle using `map` and `quot.mk` to match and relate children of two trees. -/
theorem cofix.bisim_rel {α : typevec n}
(r : cofix F α → cofix F α → Prop)
(h : ∀ x y, r x y →
append_fun id (quot.mk r) <$$> cofix.dest x = append_fun id (quot.mk r) <$$> cofix.dest y) :
∀ x y, r x y → x = y :=
let r' x y := x = y ∨ r x y in
begin
intros x y rxy,
apply cofix.bisim_aux r',
{ intro x, left, reflexivity },
{ intros x y r'xy,
cases r'xy, { rw r'xy },
have : ∀ x y, r x y → r' x y := λ x y h, or.inr h,
rw ←quot.factor_mk_eq _ _ this, dsimp,
rw [append_fun_comp_id, append_fun_comp_id],
rw [@comp_map _ _ _ q _ _ _ (append_fun id (quot.mk r)),
@comp_map _ _ _ q _ _ _ (append_fun id (quot.mk r))],
rw h _ _ r'xy },
right, exact rxy
end
/-- Bisimulation principle using `liftr` to match and relate children of two trees. -/
theorem cofix.bisim {α : typevec n}
(r : cofix F α → cofix F α → Prop)
(h : ∀ x y, r x y → liftr (rel_last α r) (cofix.dest x) (cofix.dest y)) :
∀ x y, r x y → x = y :=
begin
apply cofix.bisim_rel,
intros x y rxy,
rcases (liftr_iff (rel_last α r) _ _).mp (h x y rxy) with ⟨a, f₀, f₁, dxeq, dyeq, h'⟩,
rw [dxeq, dyeq, ←abs_map, ←abs_map, mvpfunctor.map_eq, mvpfunctor.map_eq],
rw [←split_drop_fun_last_fun f₀, ←split_drop_fun_last_fun f₁],
rw [append_fun_comp_split_fun, append_fun_comp_split_fun],
rw [id_comp, id_comp],
congr' 2 with i j, cases i with _ i; dsimp,
{ apply quot.sound, apply h' _ j },
{ change f₀ _ j = f₁ _ j, apply h' _ j },
end
open mvfunctor
/-- Bisimulation principle using `liftr'` to match and relate children of two trees. -/
theorem cofix.bisim₂ {α : typevec n}
(r : cofix F α → cofix F α → Prop)
(h : ∀ x y, r x y → liftr' (rel_last' α r) (cofix.dest x) (cofix.dest y)) :
∀ x y, r x y → x = y :=
cofix.bisim _ $ by intros; rw ← liftr_last_rel_iff; apply h; assumption
/-- Bisimulation principle the values `⟨a,f⟩` of the polynomial functor representing
`cofix F α` as well as an invariant `Q : β → Prop` and a state `β` generating the
left-hand side and right-hand side of the equality through functions `u v : β → cofix F α` -/
theorem cofix.bisim' {α : typevec n} {β : Type*} (Q : β → Prop)
(u v : β → cofix F α)
(h : ∀ x, Q x → ∃ a f' f₀ f₁,
cofix.dest (u x) = abs ⟨a, q.P.append_contents f' f₀⟩ ∧
cofix.dest (v x) = abs ⟨a, q.P.append_contents f' 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 : cofix F α, ∃ x', Q x' ∧ w = u x' ∧ z = v x' in
cofix.bisim R
(λ x y ⟨x', Qx', xeq, yeq⟩,
begin
rcases h x' Qx' with ⟨a, f', f₀, f₁, ux'eq, vx'eq, h'⟩,
rw liftr_iff,
refine ⟨a, q.P.append_contents f' f₀, q.P.append_contents f' f₁,
xeq.symm ▸ ux'eq, yeq.symm ▸ vx'eq, _⟩,
intro i, cases i,
{ apply h' },
{ intro j, apply eq.refl },
end)
_ _ ⟨x, Qx, rfl, rfl⟩
lemma cofix.mk_dest {α : typevec n} (x : cofix F α) : cofix.mk (cofix.dest x) = x :=
begin
apply cofix.bisim_rel (λ x y : cofix F α, x = cofix.mk (cofix.dest y)) _ _ _ rfl, dsimp,
intros x y h, rw h,
conv { to_lhs, congr, skip, rw [cofix.mk], rw cofix.dest_corec},
rw [←comp_map, ←append_fun_comp, id_comp],
rw [←comp_map, ←append_fun_comp, id_comp, ←cofix.mk],
congr' 2 with u, apply quot.sound, refl
end
lemma cofix.dest_mk {α : typevec n} (x : F (α.append1 $ cofix F α)) : cofix.dest (cofix.mk x) = x :=
begin
have : cofix.mk ∘ cofix.dest = @_root_.id (cofix F α) := funext cofix.mk_dest,
rw [cofix.mk, cofix.dest_corec, ←comp_map, ←cofix.mk, ← append_fun_comp, this, id_comp,
append_fun_id_id, mvfunctor.id_map]
end
lemma cofix.ext {α : typevec n} (x y : cofix F α) (h : x.dest = y.dest) : x = y :=
by rw [← cofix.mk_dest x,h,cofix.mk_dest]
lemma cofix.ext_mk {α : typevec n} (x y : F (α ::: cofix F α)) (h : cofix.mk x = cofix.mk y) :
x = y :=
by rw [← cofix.dest_mk x,h,cofix.dest_mk]
/-!
`liftr_map`, `liftr_map_last` and `liftr_map_last'` are useful for reasoning about
the induction step in bisimulation proofs.
-/
section liftr_map
omit q
theorem liftr_map {α β : typevec n} {F' : typevec n → Type u} [mvfunctor F']
[is_lawful_mvfunctor F']
(R : β ⊗ β ⟹ repeat n Prop) (x : F' α) (f g : α ⟹ β)
(h : α ⟹ subtype_ R)
(hh : subtype_val _ ⊚ h = (f ⊗' g) ⊚ prod.diag) :
liftr' R (f <$$> x) (g <$$> x) :=
begin
rw liftr_def,
existsi h <$$> x,
rw [mvfunctor.map_map,comp_assoc,hh,← comp_assoc,fst_prod_mk,comp_assoc,fst_diag],
rw [mvfunctor.map_map,comp_assoc,hh,← comp_assoc,snd_prod_mk,comp_assoc,snd_diag],
dsimp [liftr'], split; refl,
end
open function
theorem liftr_map_last [is_lawful_mvfunctor F] {α : typevec n} {ι ι'}
(R : ι' → ι' → Prop) (x : F (α ::: ι)) (f g : ι → ι')
(hh : ∀ x : ι, R (f x) (g x)) :
liftr' (rel_last' _ R) ((id ::: f) <$$> x) ((id ::: g) <$$> x) :=
let h : ι → { x : ι' × ι' // uncurry R x } := λ x, ⟨ (f x,g x), hh x ⟩ in
let b : α ::: ι ⟹ _ := @diag_sub n α ::: h,
c : subtype_ α.repeat_eq ::: {x // uncurry R x} ⟹
(λ (i : fin2 (n)), {x // of_repeat (α.rel_last' R i.fs x)}) ::: subtype (uncurry R) :=
of_subtype _ ::: id
in
have hh : subtype_val _ ⊚ to_subtype _ ⊚ from_append1_drop_last ⊚ c ⊚ b =
(id ::: f ⊗' id ::: g) ⊚ prod.diag,
by { dsimp [c,b],
apply eq_of_drop_last_eq,
{ dsimp,
simp only [prod_map_id, drop_fun_prod, drop_fun_append_fun, drop_fun_diag, id_comp,
drop_fun_to_subtype],
erw [to_subtype_of_subtype_assoc,id_comp],
clear_except,
ext i x : 2, induction i,
refl, apply i_ih, },
simp only [h, last_fun_from_append1_drop_last, last_fun_to_subtype, last_fun_append_fun,
last_fun_subtype_val, comp.left_id, last_fun_comp, last_fun_prod],
dsimp, ext1, refl },
liftr_map _ _ _ _ (to_subtype _ ⊚ from_append1_drop_last ⊚ c ⊚ b) hh
theorem liftr_map_last' [is_lawful_mvfunctor F] {α : typevec n} {ι}
(R : ι → ι → Prop) (x : F (α ::: ι)) (f : ι → ι)
(hh : ∀ x : ι, R (f x) x) :
liftr' (rel_last' _ R) ((id ::: f) <$$> x) x :=
begin
have := liftr_map_last R x f id hh,
rwa [append_fun_id_id,mvfunctor.id_map] at this,
end
end liftr_map
lemma cofix.abs_repr {α} (x : cofix F α) :
quot.mk _ (cofix.repr x) = x :=
begin
let R := λ x y : cofix F α,
cofix.abs (cofix.repr y) = x,
refine cofix.bisim₂ R _ _ _ rfl,
clear x, rintros x y h, dsimp [R] at h, subst h,
dsimp [cofix.dest,cofix.abs],
induction y using quot.ind,
simp only [cofix.repr, M.dest_corec, abs_map, abs_repr],
conv { congr, skip, rw cofix.dest },
dsimp, rw [mvfunctor.map_map,mvfunctor.map_map,← append_fun_comp_id,← append_fun_comp_id],
let f : α ::: (P F).M α ⟹ subtype_ (α.rel_last' R) :=
split_fun diag_sub (λ x, ⟨(cofix.abs (cofix.abs x).repr, cofix.abs x),_⟩),
refine liftr_map _ _ _ _ f _,
{ simp only [←append_prod_append_fun, prod_map_id],
apply eq_of_drop_last_eq,
{ dsimp, simp only [drop_fun_diag],
erw subtype_val_diag_sub },
ext1,
simp only [cofix.abs, prod.mk.inj_iff, prod_map, function.comp_app, last_fun_append_fun,
last_fun_subtype_val, last_fun_comp, last_fun_split_fun],
dsimp [drop_fun_rel_last,last_fun,prod.diag],
split; refl, },
dsimp [rel_last',split_fun,function.uncurry,R],
refl,
end
section tactic
setup_tactic_parser
open tactic
omit q
/-- tactic for proof by bisimulation -/
meta def mv_bisim (e : parse texpr) (ids : parse with_ident_list) : tactic unit :=
do e ← to_expr e,
(expr.pi n bi d b) ← retrieve $ do
{ generalize e,
target },
`(@eq %%t %%l %%r) ← pure b,
x ← mk_local_def `n d,
v₀ ← mk_local_def `a t,
v₁ ← mk_local_def `b t,
x₀ ← mk_app ``eq [v₀,l.instantiate_var x],
x₁ ← mk_app ``eq [v₁,r.instantiate_var x],
xx ← mk_app ``and [x₀,x₁],
ex ← lambdas [x] xx,
ex ← mk_app ``Exists [ex] >>= lambdas [v₀,v₁],
R ← pose `R none ex,
refine ``(cofix.bisim₂ %%R _ _ _ ⟨_,rfl,rfl⟩),
let f (a b : name) : name := if a = `_ then b else a,
let ids := (ids ++ list.repeat `_ 5).zip_with f [`a,`b,`x,`Ha,`Hb],
(ids₀,w::ids₁) ← pure $ list.split_at 2 ids,
intro_lst ids₀,
h ← intro1,
[(_,[w,h],_)] ← cases_core h [w],
cases h ids₁,
pure ()
run_cmd add_interactive [``mv_bisim]
end tactic
theorem corec_roll {α : typevec n} {X Y} {x₀ : X}
(f : X → Y) (g : Y → F (α ::: X)) :
cofix.corec (g ∘ f) x₀ = cofix.corec (mvfunctor.map (id ::: f) ∘ g) (f x₀) :=
begin
mv_bisim x₀,
rw [Ha,Hb,cofix.dest_corec,cofix.dest_corec],
rw [mvfunctor.map_map,← append_fun_comp_id],
refine liftr_map_last _ _ _ _ _,
intros a, refine ⟨a,rfl,rfl⟩
end
theorem cofix.dest_corec' {α : typevec n} {β : Type u}
(g : β → F (α.append1 (cofix F α ⊕ β))) (x : β) :
cofix.dest (cofix.corec' g x) = append_fun id (sum.elim id (cofix.corec' g)) <$$> g x :=
begin
rw [cofix.corec',cofix.dest_corec], dsimp,
congr' with (i|i); rw corec_roll; dsimp [cofix.corec'],
{ mv_bisim i,
rw [Ha,Hb,cofix.dest_corec], dsimp [(∘)],
repeat { rw [mvfunctor.map_map,← append_fun_comp_id] },
apply liftr_map_last', dsimp [(∘),R], intros, exact ⟨_,rfl,rfl⟩ },
{ congr' with y, erw [append_fun_id_id], simp [mvfunctor.id_map] },
end
theorem cofix.dest_corec₁ {α : typevec n} {β : Type u}
(g : Π {X}, (cofix F α → X) → (β → X) → β → F (α.append1 X)) (x : β)
(h : ∀ X Y (f : cofix F α → X) (f' : β → X) (k : X → Y),
g (k ∘ f) (k ∘ f') x = (id ::: k) <$$> g f f' x) :
cofix.dest (cofix.corec₁ @g x) = g id (cofix.corec₁ @g) x :=
by rw [cofix.corec₁,cofix.dest_corec',← h]; refl
instance mvqpf_cofix : mvqpf (cofix F) :=
{ P := q.P.Mp,
abs := λ α, quot.mk Mcongr,
repr := λ α, cofix.repr,
abs_repr := λ α, cofix.abs_repr,
abs_map := λ α β g x, rfl }
end mvqpf
|
94fd7112dfe6de366795fa4ad24486c878defbe7
|
2d34dfb0a1cc250584282618dc10ea03d3fa858e
|
/src/for_mathlib/discrete_topology.lean
|
82b93fa3e94a706755e14eac9e40cbc42f1d7372
|
[] |
no_license
|
zeta1999/lean-liquid
|
61e294ec5adae959d8ee1b65d015775484ff58c2
|
96bb0fa3afc3b451bcd1fb7d974348de2f290541
|
refs/heads/master
| 1,676,579,150,248
| 1,610,771,445,000
| 1,610,771,445,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 552
|
lean
|
import topology.subset_properties
variables {ι : Type*} (X : ι → Type*)
variables [fintype ι] [∀ i, topological_space (X i)] [∀ i, discrete_topology (X i)]
instance Pi.discrete_topology : discrete_topology (Π i, X i) :=
begin
rw ← singletons_open_iff_discrete,
intro x,
rw show {x} = ⋂ i, {y : Π i, X i | y i = x i},
{ ext, simp only [function.funext_iff, set.mem_singleton_iff, set.mem_Inter, set.mem_set_of_eq] },
apply is_open_Inter,
intro i,
exact (continuous_apply i).is_open_preimage _ (is_open_discrete {x i})
end
|
b24e7606e4ab47eb72f2e256d8259d47340db290
|
74addaa0e41490cbaf2abd313a764c96df57b05d
|
/Mathlib/algebraic_geometry/structure_sheaf_auto.lean
|
9b682e7043727cc84ffd34d71638cd0e21e09239
|
[] |
no_license
|
AurelienSaue/Mathlib4_auto
|
f538cfd0980f65a6361eadea39e6fc639e9dae14
|
590df64109b08190abe22358fabc3eae000943f2
|
refs/heads/master
| 1,683,906,849,776
| 1,622,564,669,000
| 1,622,564,669,000
| 371,723,747
| 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 4,120
|
lean
|
/-
Copyright (c) 2020 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin, Scott Morrison
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.algebraic_geometry.prime_spectrum
import Mathlib.algebra.category.CommRing.colimits
import Mathlib.algebra.category.CommRing.limits
import Mathlib.topology.sheaves.local_predicate
import Mathlib.topology.sheaves.forget
import Mathlib.ring_theory.localization
import Mathlib.ring_theory.subring
import Mathlib.PostPort
universes u
namespace Mathlib
/-!
# The structure sheaf on `prime_spectrum R`.
We define the structure sheaf on `Top.of (prime_spectrum R)`, for a commutative ring `R`.
We define this as a subsheaf of the sheaf of dependent functions into the localizations,
cut out by the condition that the function must be locally equal to a ratio of elements of `R`.
Because the condition "is equal to a fraction" passes to smaller open subsets,
the subset of functions satisfying this condition is automatically a subpresheaf.
Because the condition "is locally equal to a fraction" is local,
it is also a subsheaf.
(It may be helpful to refer back to `topology.sheaves.sheaf_of_functions`,
where we show that dependent functions into any type family form a sheaf,
and also `topology.sheaves.local_predicate`, where we characterise the predicates
which pick out sub-presheaves and sub-sheaves of these sheaves.)
We also set up the ring structure, obtaining
`structure_sheaf R : sheaf CommRing (Top.of (prime_spectrum R))`.
-/
namespace algebraic_geometry
/--
$Spec R$, just as a topological space.
-/
def Spec.Top (R : Type u) [comm_ring R] : Top := Top.of (prime_spectrum R)
namespace structure_sheaf
/--
The type family over `prime_spectrum R` consisting of the localization over each point.
-/
def localizations (R : Type u) [comm_ring R] (P : ↥(Spec.Top R)) :=
localization.at_prime (prime_spectrum.as_ideal P)
protected instance localizations.inhabited (R : Type u) [comm_ring R] (P : ↥(Spec.Top R)) :
Inhabited (localizations R P) :=
{ default :=
coe_fn
(localization_map.to_map (localization.of (ideal.prime_compl (prime_spectrum.as_ideal P))))
1 }
/--
The predicate saying that a dependent function on an open `U` is realised as a fixed fraction
`r / s` in each of the stalks (which are localizations at various prime ideals).
-/
def is_fraction {R : Type u} [comm_ring R] {U : topological_space.opens ↥(Spec.Top R)}
(f : (x : ↥U) → localizations R ↑x) :=
∃ (r : R),
∃ (s : R),
∀ (x : ↥U),
¬s ∈ prime_spectrum.as_ideal (subtype.val x) ∧
f x *
coe_fn
(localization_map.to_map
(localization.of (ideal.prime_compl (prime_spectrum.as_ideal ↑x))))
s =
coe_fn
(localization_map.to_map
(localization.of (ideal.prime_compl (prime_spectrum.as_ideal ↑x))))
r
/--
The predicate `is_fraction` is "prelocal",
in the sense that if it holds on `U` it holds on any open subset `V` of `U`.
-/
def is_fraction_prelocal (R : Type u) [comm_ring R] : Top.prelocal_predicate (localizations R) :=
Top.prelocal_predicate.mk
(fun (U : topological_space.opens ↥(Spec.Top R)) (f : (x : ↥U) → localizations R ↑x) =>
is_fraction f)
sorry
/--
We will define the structure sheaf as
the subsheaf of all dependent functions in `Π x : U, localizations R x`
consisting of those functions which can locally be expressed as a ratio of
(the images in the localization of) elements of `R`.
Quoting Hartshorne:
For an open set $$U ⊆ Spec A$$, we define $$𝒪(U)$$ to be the set of functions
$$s : U → ⨆_{𝔭 ∈ U} A_𝔭$$, such that $s(𝔭) ∈ A_𝔭$$ for each $$𝔭$$,
and such that $$s$$ is locally a quotient of elements of $$A$$:
to be precise, we require that for each $$𝔭 ∈ U$$, there is a neighborhood $$V$$ of $$𝔭$$,
contained in $$U$$, and elements $$a, f ∈ A$$, such that for each $$𝔮 ∈ V, f ∉ 𝔮$$,
a
|
4ee8ef63660b8594a96851ad285af07a3ccfbe05
|
94e33a31faa76775069b071adea97e86e218a8ee
|
/src/set_theory/game/pgame.lean
|
60714d56fe29591246ecfead47ca8b35ee20e04d
|
[
"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
| 58,114
|
lean
|
/-
Copyright (c) 2019 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Reid Barton, Mario Carneiro, Isabel Longbottom, Scott Morrison
-/
import data.fin.basic
import data.list.basic
import logic.relation
/-!
# Combinatorial (pre-)games.
The basic theory of combinatorial games, following Conway's book `On Numbers and Games`. We
construct "pregames", define an ordering and arithmetic operations on them, then show that the
operations descend to "games", defined via the equivalence relation `p ≈ q ↔ p ≤ q ∧ q ≤ p`.
The surreal numbers will be built as a quotient of a subtype of pregames.
A pregame (`pgame` below) is axiomatised via an inductive type, whose sole constructor takes two
types (thought of as indexing the possible moves for the players Left and Right), and a pair of
functions out of these types to `pgame` (thought of as describing the resulting game after making a
move).
Combinatorial games themselves, as a quotient of pregames, are constructed in `game.lean`.
## Conway induction
By construction, the induction principle for pregames is exactly "Conway induction". That is, to
prove some predicate `pgame → Prop` holds for all pregames, it suffices to prove that for every
pregame `g`, if the predicate holds for every game resulting from making a move, then it also holds
for `g`.
While it is often convenient to work "by induction" on pregames, in some situations this becomes
awkward, so we also define accessor functions `pgame.left_moves`, `pgame.right_moves`,
`pgame.move_left` and `pgame.move_right`. There is a relation `pgame.subsequent p q`, saying that
`p` can be reached by playing some non-empty sequence of moves starting from `q`, an instance
`well_founded subsequent`, and a local tactic `pgame_wf_tac` which is helpful for discharging proof
obligations in inductive proofs relying on this relation.
## Order properties
Pregames have both a `≤` and a `<` relation, satisfying the usual properties of a `preorder`. The
relation `0 < x` means that `x` can always be won by Left, while `0 ≤ x` means that `x` can be won
by Left as the second player.
It turns out to be quite convenient to define various relations on top of these. We define the "less
or fuzzy" relation `x ⧏ y` as `¬ y ≤ x`, the equivalence relation `x ≈ y` as `x ≤ y ∧ y ≤ x`, and
the fuzzy relation `x ∥ y` as `x ⧏ y ∧ y ⧏ x`. If `0 ⧏ x`, then `x` can be won by Left as the
first player. If `x ≈ 0`, then `x` can be won by the second player. If `x ∥ 0`, then `x` can be won
by the first player.
Statements like `zero_le_lf`, `zero_lf_le`, etc. unfold these definitions. The theorems `le_def` and
`lf_def` give a recursive characterisation of each relation in terms of themselves two moves later.
The theorems `zero_le`, `zero_lf`, etc. also take into account that `0` has no moves.
Later, games will be defined as the quotient by the `≈` relation; that is to say, the
`antisymmetrization` of `pgame`.
## Algebraic structures
We next turn to defining the operations necessary to make games into a commutative additive group.
Addition is defined for $x = \{xL | xR\}$ and $y = \{yL | yR\}$ by $x + y = \{xL + y, x + yL | xR +
y, x + yR\}$. Negation is defined by $\{xL | xR\} = \{-xR | -xL\}$.
The order structures interact in the expected way with addition, so we have
```
theorem le_iff_sub_nonneg {x y : pgame} : x ≤ y ↔ 0 ≤ y - x := sorry
theorem lt_iff_sub_pos {x y : pgame} : x < y ↔ 0 < y - x := sorry
```
We show that these operations respect the equivalence relation, and hence descend to games. At the
level of games, these operations satisfy all the laws of a commutative group. To prove the necessary
equivalence relations at the level of pregames, we introduce the notion of a `relabelling` of a
game, and show, for example, that there is a relabelling between `x + (y + z)` and `(x + y) + z`.
## Future work
* The theory of dominated and reversible positions, and unique normal form for short games.
* Analysis of basic domineering positions.
* Hex.
* Temperature.
* The development of surreal numbers, based on this development of combinatorial games, is still
quite incomplete.
## References
The material here is all drawn from
* [Conway, *On numbers and games*][conway2001]
An interested reader may like to formalise some of the material from
* [Andreas Blass, *A game semantics for linear logic*][MR1167694]
* [André Joyal, *Remarques sur la théorie des jeux à deux personnes*][joyal1997]
-/
open function relation
universes u
/-! ### Pre-game moves -/
/-- The type of pre-games, before we have quotiented
by equivalence (`pgame.setoid`). In ZFC, a combinatorial game is constructed from
two sets of combinatorial games that have been constructed at an earlier
stage. To do this in type theory, we say that a pre-game is built
inductively from two families of pre-games indexed over any type
in Type u. The resulting type `pgame.{u}` lives in `Type (u+1)`,
reflecting that it is a proper class in ZFC. -/
inductive pgame : Type (u+1)
| mk : ∀ α β : Type u, (α → pgame) → (β → pgame) → pgame
namespace pgame
/-- The indexing type for allowable moves by Left. -/
def left_moves : pgame → Type u
| (mk l _ _ _) := l
/-- The indexing type for allowable moves by Right. -/
def right_moves : pgame → Type u
| (mk _ r _ _) := r
/-- The new game after Left makes an allowed move. -/
def move_left : Π (g : pgame), left_moves g → pgame
| (mk l _ L _) := L
/-- The new game after Right makes an allowed move. -/
def move_right : Π (g : pgame), right_moves g → pgame
| (mk _ r _ R) := R
@[simp] lemma left_moves_mk {xl xr xL xR} : (⟨xl, xr, xL, xR⟩ : pgame).left_moves = xl := rfl
@[simp] lemma move_left_mk {xl xr xL xR} : (⟨xl, xr, xL, xR⟩ : pgame).move_left = xL := rfl
@[simp] lemma right_moves_mk {xl xr xL xR} : (⟨xl, xr, xL, xR⟩ : pgame).right_moves = xr := rfl
@[simp] lemma move_right_mk {xl xr xL xR} : (⟨xl, xr, xL, xR⟩ : pgame).move_right = xR := rfl
/--
Construct a pre-game from list of pre-games describing the available moves for Left and Right.
-/
-- TODO define this at the level of games, as well, and perhaps also for finsets of games.
def of_lists (L R : list pgame.{u}) : pgame.{u} :=
mk (ulift (fin L.length)) (ulift (fin R.length))
(λ i, L.nth_le i.down i.down.is_lt) (λ j, R.nth_le j.down j.down.prop)
lemma left_moves_of_lists (L R : list pgame) : (of_lists L R).left_moves = ulift (fin L.length) :=
rfl
lemma right_moves_of_lists (L R : list pgame) : (of_lists L R).right_moves = ulift (fin R.length) :=
rfl
/-- Converts a number into a left move for `of_lists`. -/
def to_of_lists_left_moves {L R : list pgame} : fin L.length ≃ (of_lists L R).left_moves :=
((equiv.cast (left_moves_of_lists L R).symm).trans equiv.ulift).symm
/-- Converts a number into a right move for `of_lists`. -/
def to_of_lists_right_moves {L R : list pgame} : fin R.length ≃ (of_lists L R).right_moves :=
((equiv.cast (right_moves_of_lists L R).symm).trans equiv.ulift).symm
theorem of_lists_move_left {L R : list pgame} (i : fin L.length) :
(of_lists L R).move_left (to_of_lists_left_moves i) = L.nth_le i i.is_lt :=
rfl
@[simp] theorem of_lists_move_left' {L R : list pgame} (i : (of_lists L R).left_moves) :
(of_lists L R).move_left i =
L.nth_le (to_of_lists_left_moves.symm i) (to_of_lists_left_moves.symm i).is_lt :=
rfl
theorem of_lists_move_right {L R : list pgame} (i : fin R.length) :
(of_lists L R).move_right (to_of_lists_right_moves i) = R.nth_le i i.is_lt :=
rfl
@[simp] theorem of_lists_move_right' {L R : list pgame} (i : (of_lists L R).right_moves) :
(of_lists L R).move_right i =
R.nth_le (to_of_lists_right_moves.symm i) (to_of_lists_right_moves.symm i).is_lt :=
rfl
/-- A variant of `pgame.rec_on` expressed in terms of `pgame.move_left` and `pgame.move_right`.
Both this and `pgame.rec_on` describe Conway induction on games. -/
@[elab_as_eliminator] def move_rec_on {C : pgame → Sort*} (x : pgame)
(IH : ∀ (y : pgame), (∀ i, C (y.move_left i)) → (∀ j, C (y.move_right j)) → C y) : C x :=
x.rec_on $ λ yl yr yL yR, IH (mk yl yr yL yR)
/-- `is_option x y` means that `x` is either a left or right option for `y`. -/
@[mk_iff] inductive is_option : pgame → pgame → Prop
| move_left {x : pgame} (i : x.left_moves) : is_option (x.move_left i) x
| move_right {x : pgame} (i : x.right_moves) : is_option (x.move_right i) x
theorem is_option.mk_left {xl xr : Type u} (xL : xl → pgame) (xR : xr → pgame) (i : xl) :
(xL i).is_option (mk xl xr xL xR) :=
@is_option.move_left (mk _ _ _ _) i
theorem is_option.mk_right {xl xr : Type u} (xL : xl → pgame) (xR : xr → pgame) (i : xr) :
(xR i).is_option (mk xl xr xL xR) :=
@is_option.move_right (mk _ _ _ _) i
theorem wf_is_option : well_founded is_option :=
⟨λ x, move_rec_on x $ λ x IHl IHr, acc.intro x $ λ y h, begin
induction h with _ i _ j,
{ exact IHl i },
{ exact IHr j }
end⟩
/-- `subsequent x y` says that `x` can be obtained by playing some nonempty sequence of moves from
`y`. It is the transitive closure of `is_option`. -/
def subsequent : pgame → pgame → Prop :=
trans_gen is_option
instance : is_trans _ subsequent := trans_gen.is_trans
@[trans] theorem subsequent.trans {x y z} : subsequent x y → subsequent y z → subsequent x z :=
trans_gen.trans
theorem wf_subsequent : well_founded subsequent := wf_is_option.trans_gen
instance : has_well_founded pgame := ⟨_, wf_subsequent⟩
lemma subsequent.move_left {x : pgame} (i : x.left_moves) : subsequent (x.move_left i) x :=
trans_gen.single (is_option.move_left i)
lemma subsequent.move_right {x : pgame} (j : x.right_moves) : subsequent (x.move_right j) x :=
trans_gen.single (is_option.move_right j)
lemma subsequent.mk_left {xl xr} (xL : xl → pgame) (xR : xr → pgame) (i : xl) :
subsequent (xL i) (mk xl xr xL xR) :=
@subsequent.move_left (mk _ _ _ _) i
lemma subsequent.mk_right {xl xr} (xL : xl → pgame) (xR : xr → pgame) (j : xr) :
subsequent (xR j) (mk xl xr xL xR) :=
@subsequent.move_right (mk _ _ _ _) j
/-- A local tactic for proving well-foundedness of recursive definitions involving pregames. -/
meta def pgame_wf_tac :=
`[solve_by_elim
[psigma.lex.left, psigma.lex.right, subsequent.move_left, subsequent.move_right,
subsequent.mk_left, subsequent.mk_right, subsequent.trans]
{ max_depth := 6 }]
/-! ### Basic pre-games -/
/-- The pre-game `zero` is defined by `0 = { | }`. -/
instance : has_zero pgame := ⟨⟨pempty, pempty, pempty.elim, pempty.elim⟩⟩
@[simp] lemma zero_left_moves : left_moves 0 = pempty := rfl
@[simp] lemma zero_right_moves : right_moves 0 = pempty := rfl
instance is_empty_zero_left_moves : is_empty (left_moves 0) := pempty.is_empty
instance is_empty_zero_right_moves : is_empty (right_moves 0) := pempty.is_empty
instance : inhabited pgame := ⟨0⟩
/-- The pre-game `one` is defined by `1 = { 0 | }`. -/
instance : has_one pgame := ⟨⟨punit, pempty, λ _, 0, pempty.elim⟩⟩
@[simp] lemma one_left_moves : left_moves 1 = punit := rfl
@[simp] lemma one_move_left (x) : move_left 1 x = 0 := rfl
@[simp] lemma one_right_moves : right_moves 1 = pempty := rfl
instance unique_one_left_moves : unique (left_moves 1) := punit.unique
instance is_empty_one_right_moves : is_empty (right_moves 1) := pempty.is_empty
/-! ### Pre-game order relations -/
/-- Define simultaneously by mutual induction the `≤` relation and its swapped converse `⧏` on
pre-games.
The ZFC definition says that `x = {xL | xR}` is less or equal to `y = {yL | yR}` if
`∀ x₁ ∈ xL, x₁ ⧏ y` and `∀ y₂ ∈ yR, x ⧏ y₂`, where `x ⧏ y` means `¬ y ≤ x`. This is a tricky
induction because it only decreases one side at a time, and it also swaps the arguments in the
definition of `≤`. The solution is to define `x ≤ y` and `x ⧏ y` simultaneously. -/
def le_lf : Π (x y : pgame.{u}), Prop × Prop
| (mk xl xr xL xR) (mk yl yr yL yR) :=
-- the orderings of the clauses here are carefully chosen so that
-- and.left/or.inl refer to moves by Left, and
-- and.right/or.inr refer to moves by Right.
((∀ i, (le_lf (xL i) ⟨yl, yr, yL, yR⟩).2) ∧ ∀ j, (le_lf ⟨xl, xr, xL, xR⟩ (yR j)).2,
(∃ i, (le_lf ⟨xl, xr, xL, xR⟩ (yL i)).1) ∨ ∃ j, (le_lf (xR j) ⟨yl, yr, yL, yR⟩).1)
using_well_founded { dec_tac := pgame_wf_tac }
/-- The less or equal relation on pre-games.
If `0 ≤ x`, then Left can win `x` as the second player. -/
instance : has_le pgame := ⟨λ x y, (le_lf x y).1⟩
/-- The less or fuzzy relation on pre-games.
If `0 ⧏ x`, then Left can win `x` as the first player. -/
def lf (x y : pgame) : Prop := (le_lf x y).2
localized "infix ` ⧏ `:50 := pgame.lf" in pgame
/-- Definition of `x ≤ y` on pre-games built using the constructor. -/
@[simp] theorem mk_le_mk {xl xr xL xR yl yr yL yR} :
mk xl xr xL xR ≤ mk yl yr yL yR ↔
(∀ i, xL i ⧏ mk yl yr yL yR) ∧ ∀ j, mk xl xr xL xR ⧏ yR j :=
show (le_lf _ _).1 ↔ _, by { rw le_lf, refl }
/-- Definition of `x ≤ y` on pre-games, in terms of `⧏` -/
theorem le_iff_forall_lf {x y : pgame} :
x ≤ y ↔ (∀ i, x.move_left i ⧏ y) ∧ ∀ j, x ⧏ y.move_right j :=
by { cases x, cases y, exact mk_le_mk }
theorem le_of_forall_lf {x y : pgame} (h₁ : ∀ i, x.move_left i ⧏ y) (h₂ : ∀ j, x ⧏ y.move_right j) :
x ≤ y :=
le_iff_forall_lf.2 ⟨h₁, h₂⟩
/-- Definition of `x ⧏ y` on pre-games built using the constructor. -/
@[simp] theorem mk_lf_mk {xl xr xL xR yl yr yL yR} :
mk xl xr xL xR ⧏ mk yl yr yL yR ↔
(∃ i, mk xl xr xL xR ≤ yL i) ∨ ∃ j, xR j ≤ mk yl yr yL yR :=
show (le_lf _ _).2 ↔ _, by { rw le_lf, refl }
/-- Definition of `x ⧏ y` on pre-games, in terms of `≤` -/
theorem lf_iff_exists_le {x y : pgame} :
x ⧏ y ↔ (∃ i, x ≤ y.move_left i) ∨ ∃ j, x.move_right j ≤ y :=
by { cases x, cases y, exact mk_lf_mk }
private theorem not_le_lf {x y : pgame} : (¬ x ≤ y ↔ y ⧏ x) ∧ (¬ x ⧏ y ↔ y ≤ x) :=
begin
induction x with xl xr xL xR IHxl IHxr generalizing y,
induction y with yl yr yL yR IHyl IHyr,
simp only [mk_le_mk, mk_lf_mk, IHxl, IHxr, IHyl, IHyr,
not_and_distrib, not_or_distrib, not_forall, not_exists,
and_comm, or_comm, iff_self, and_self]
end
@[simp] protected theorem not_le {x y : pgame} : ¬ x ≤ y ↔ y ⧏ x := not_le_lf.1
@[simp] theorem not_lf {x y : pgame} : ¬ x ⧏ y ↔ y ≤ x := not_le_lf.2
theorem _root_.has_le.le.not_gf {x y : pgame} : x ≤ y → ¬ y ⧏ x := not_lf.2
theorem lf.not_ge {x y : pgame} : x ⧏ y → ¬ y ≤ x := pgame.not_le.2
theorem le_or_gf (x y : pgame) : x ≤ y ∨ y ⧏ x :=
by { rw ←pgame.not_le, apply em }
theorem move_left_lf_of_le {x y : pgame} (h : x ≤ y) (i) : x.move_left i ⧏ y :=
(le_iff_forall_lf.1 h).1 i
alias move_left_lf_of_le ← _root_.has_le.le.move_left_lf
theorem lf_move_right_of_le {x y : pgame} (h : x ≤ y) (j) : x ⧏ y.move_right j :=
(le_iff_forall_lf.1 h).2 j
alias lf_move_right_of_le ← _root_.has_le.le.lf_move_right
theorem lf_of_move_right_le {x y : pgame} {j} (h : x.move_right j ≤ y) : x ⧏ y :=
lf_iff_exists_le.2 $ or.inr ⟨j, h⟩
theorem lf_of_le_move_left {x y : pgame} {i} (h : x ≤ y.move_left i) : x ⧏ y :=
lf_iff_exists_le.2 $ or.inl ⟨i, h⟩
theorem lf_of_le_mk {xl xr xL xR y} : mk xl xr xL xR ≤ y → ∀ i, xL i ⧏ y :=
move_left_lf_of_le
theorem lf_of_mk_le {x yl yr yL yR} : x ≤ mk yl yr yL yR → ∀ j, x ⧏ yR j :=
lf_move_right_of_le
theorem mk_lf_of_le {xl xr y j} (xL) {xR : xr → pgame} : xR j ≤ y → mk xl xr xL xR ⧏ y :=
@lf_of_move_right_le (mk _ _ _ _) y j
theorem lf_mk_of_le {x yl yr} {yL : yl → pgame} (yR) {i} : x ≤ yL i → x ⧏ mk yl yr yL yR :=
@lf_of_le_move_left x (mk _ _ _ _) i
/- We prove that `x ≤ y → y ≤ z ← x ≤ z` inductively, by also simultaneously proving its cyclic
reorderings. This auxiliary lemma is used during said induction. -/
private theorem le_trans_aux {x y z : pgame}
(h₁ : ∀ {i}, y ≤ z → z ≤ x.move_left i → y ≤ x.move_left i)
(h₂ : ∀ {j}, z.move_right j ≤ x → x ≤ y → z.move_right j ≤ y)
(hxy : x ≤ y) (hyz : y ≤ z) : x ≤ z :=
le_of_forall_lf
(λ i, pgame.not_le.1 $ λ h, (h₁ hyz h).not_gf $ hxy.move_left_lf i)
(λ j, pgame.not_le.1 $ λ h, (h₂ h hxy).not_gf $ hyz.lf_move_right j)
instance : has_lt pgame := ⟨λ x y, x ≤ y ∧ x ⧏ y⟩
instance : preorder pgame :=
{ le_refl := λ x, begin
induction x with _ _ _ _ IHl IHr,
exact le_of_forall_lf (λ i, lf_of_le_move_left (IHl i)) (λ i, lf_of_move_right_le (IHr i))
end,
le_trans := begin
suffices : ∀ {x y z : pgame},
(x ≤ y → y ≤ z → x ≤ z) ∧ (y ≤ z → z ≤ x → y ≤ x) ∧ (z ≤ x → x ≤ y → z ≤ y),
from λ x y z, this.1,
intros x y z,
induction x with xl xr xL xR IHxl IHxr generalizing y z,
induction y with yl yr yL yR IHyl IHyr generalizing z,
induction z with zl zr zL zR IHzl IHzr,
exact ⟨le_trans_aux (λ i, (IHxl i).2.1) (λ j, (IHzr j).2.2),
le_trans_aux (λ i, (IHyl i).2.2) (λ j, (IHxr j).1),
le_trans_aux (λ i, (IHzl i).1) (λ j, (IHyr j).2.1)⟩
end,
lt_iff_le_not_le := λ x y, by { rw pgame.not_le, refl },
..pgame.has_le, ..pgame.has_lt }
theorem lt_iff_le_and_lf {x y : pgame} : x < y ↔ x ≤ y ∧ x ⧏ y := iff.rfl
theorem lt_of_le_of_lf {x y : pgame} (h₁ : x ≤ y) (h₂ : x ⧏ y) : x < y := ⟨h₁, h₂⟩
theorem lf_of_lt {x y : pgame} (h : x < y) : x ⧏ y := h.2
alias lf_of_lt ← _root_.has_lt.lt.lf
theorem lf_irrefl (x : pgame) : ¬ x ⧏ x := le_rfl.not_gf
instance : is_irrefl _ (⧏) := ⟨lf_irrefl⟩
@[trans] theorem lf_of_le_of_lf {x y z : pgame} (h₁ : x ≤ y) (h₂ : y ⧏ z) : x ⧏ z :=
by { rw ←pgame.not_le at h₂ ⊢, exact λ h₃, h₂ (h₃.trans h₁) }
@[trans] theorem lf_of_lf_of_le {x y z : pgame} (h₁ : x ⧏ y) (h₂ : y ≤ z) : x ⧏ z :=
by { rw ←pgame.not_le at h₁ ⊢, exact λ h₃, h₁ (h₂.trans h₃) }
alias lf_of_le_of_lf ← _root_.has_le.le.trans_lf
alias lf_of_lf_of_le ← lf.trans_le
@[trans] theorem lf_of_lt_of_lf {x y z : pgame} (h₁ : x < y) (h₂ : y ⧏ z) : x ⧏ z :=
h₁.le.trans_lf h₂
@[trans] theorem lf_of_lf_of_lt {x y z : pgame} (h₁ : x ⧏ y) (h₂ : y < z) : x ⧏ z :=
h₁.trans_le h₂.le
alias lf_of_lt_of_lf ← _root_.has_lt.lt.trans_lf
alias lf_of_lf_of_lt ← lf.trans_lt
theorem move_left_lf {x : pgame} : ∀ i, x.move_left i ⧏ x :=
le_rfl.move_left_lf
theorem lf_move_right {x : pgame} : ∀ j, x ⧏ x.move_right j :=
le_rfl.lf_move_right
theorem lf_mk {xl xr} (xL : xl → pgame) (xR : xr → pgame) (i) : xL i ⧏ mk xl xr xL xR :=
@move_left_lf (mk _ _ _ _) i
theorem mk_lf {xl xr} (xL : xl → pgame) (xR : xr → pgame) (j) : mk xl xr xL xR ⧏ xR j :=
@lf_move_right (mk _ _ _ _) j
/-- This special case of `pgame.le_of_forall_lf` is useful when dealing with surreals, where `<` is
preferred over `⧏`. -/
theorem le_of_forall_lt {x y : pgame} (h₁ : ∀ i, x.move_left i < y) (h₂ : ∀ j, x < y.move_right j) :
x ≤ y :=
le_of_forall_lf (λ i, (h₁ i).lf) (λ i, (h₂ i).lf)
/-- The definition of `x ≤ y` on pre-games, in terms of `≤` two moves later. -/
theorem le_def {x y : pgame} : x ≤ y ↔
(∀ i, (∃ i', x.move_left i ≤ y.move_left i') ∨ ∃ j, (x.move_left i).move_right j ≤ y) ∧
∀ j, (∃ i, x ≤ (y.move_right j).move_left i) ∨ ∃ j', x.move_right j' ≤ y.move_right j :=
by { rw le_iff_forall_lf, conv { to_lhs, simp only [lf_iff_exists_le] } }
/-- The definition of `x ⧏ y` on pre-games, in terms of `⧏` two moves later. -/
theorem lf_def {x y : pgame} : x ⧏ y ↔
(∃ i, (∀ i', x.move_left i' ⧏ y.move_left i) ∧ ∀ j, x ⧏ (y.move_left i).move_right j) ∨
∃ j, (∀ i, (x.move_right j).move_left i ⧏ y) ∧ ∀ j', x.move_right j ⧏ y.move_right j' :=
by { rw lf_iff_exists_le, conv { to_lhs, simp only [le_iff_forall_lf] } }
/-- The definition of `0 ≤ x` on pre-games, in terms of `0 ⧏`. -/
theorem zero_le_lf {x : pgame} : 0 ≤ x ↔ ∀ j, 0 ⧏ x.move_right j :=
by { rw le_iff_forall_lf, simp }
/-- The definition of `x ≤ 0` on pre-games, in terms of `⧏ 0`. -/
theorem le_zero_lf {x : pgame} : x ≤ 0 ↔ ∀ i, x.move_left i ⧏ 0 :=
by { rw le_iff_forall_lf, simp }
/-- The definition of `0 ⧏ x` on pre-games, in terms of `0 ≤`. -/
theorem zero_lf_le {x : pgame} : 0 ⧏ x ↔ ∃ i, 0 ≤ x.move_left i :=
by { rw lf_iff_exists_le, simp }
/-- The definition of `x ⧏ 0` on pre-games, in terms of `≤ 0`. -/
theorem lf_zero_le {x : pgame} : x ⧏ 0 ↔ ∃ j, x.move_right j ≤ 0 :=
by { rw lf_iff_exists_le, simp }
/-- The definition of `0 ≤ x` on pre-games, in terms of `0 ≤` two moves later. -/
theorem zero_le {x : pgame} : 0 ≤ x ↔ ∀ j, ∃ i, 0 ≤ (x.move_right j).move_left i :=
by { rw le_def, simp }
/-- The definition of `x ≤ 0` on pre-games, in terms of `≤ 0` two moves later. -/
theorem le_zero {x : pgame} : x ≤ 0 ↔ ∀ i, ∃ j, (x.move_left i).move_right j ≤ 0 :=
by { rw le_def, simp }
/-- The definition of `0 ⧏ x` on pre-games, in terms of `0 ⧏` two moves later. -/
theorem zero_lf {x : pgame} : 0 ⧏ x ↔ ∃ i, ∀ j, 0 ⧏ (x.move_left i).move_right j :=
by { rw lf_def, simp }
/-- The definition of `x ⧏ 0` on pre-games, in terms of `⧏ 0` two moves later. -/
theorem lf_zero {x : pgame} : x ⧏ 0 ↔ ∃ j, ∀ i, (x.move_right j).move_left i ⧏ 0 :=
by { rw lf_def, simp }
@[simp] theorem zero_le_of_is_empty_right_moves (x : pgame) [is_empty x.right_moves] : 0 ≤ x :=
zero_le.2 is_empty_elim
@[simp] theorem le_zero_of_is_empty_left_moves (x : pgame) [is_empty x.left_moves] : x ≤ 0 :=
le_zero.2 is_empty_elim
/-- Given a game won by the right player when they play second, provide a response to any move by
left. -/
noncomputable def right_response {x : pgame} (h : x ≤ 0) (i : x.left_moves) :
(x.move_left i).right_moves :=
classical.some $ (le_zero.1 h) i
/-- Show that the response for right provided by `right_response` preserves the right-player-wins
condition. -/
lemma right_response_spec {x : pgame} (h : x ≤ 0) (i : x.left_moves) :
(x.move_left i).move_right (right_response h i) ≤ 0 :=
classical.some_spec $ (le_zero.1 h) i
/-- Given a game won by the left player when they play second, provide a response to any move by
right. -/
noncomputable def left_response {x : pgame} (h : 0 ≤ x) (j : x.right_moves) :
(x.move_right j).left_moves :=
classical.some $ (zero_le.1 h) j
/-- Show that the response for left provided by `left_response` preserves the left-player-wins
condition. -/
lemma left_response_spec {x : pgame} (h : 0 ≤ x) (j : x.right_moves) :
0 ≤ (x.move_right j).move_left (left_response h j) :=
classical.some_spec $ (zero_le.1 h) j
/-- The equivalence relation on pre-games. Two pre-games `x`, `y` are equivalent if `x ≤ y` and
`y ≤ x`.
If `x ≈ 0`, then the second player can always win `x`. -/
def equiv (x y : pgame) : Prop := x ≤ y ∧ y ≤ x
localized "infix ` ≈ ` := pgame.equiv" in pgame
instance : is_equiv _ (≈) :=
{ refl := λ x, ⟨le_rfl, le_rfl⟩,
trans := λ x y z ⟨xy, yx⟩ ⟨yz, zy⟩, ⟨xy.trans yz, zy.trans yx⟩,
symm := λ x y, and.symm }
theorem equiv.le {x y : pgame} (h : x ≈ y) : x ≤ y := h.1
theorem equiv.ge {x y : pgame} (h : x ≈ y) : y ≤ x := h.2
@[refl, simp] theorem equiv_rfl {x} : x ≈ x := refl x
theorem equiv_refl (x) : x ≈ x := refl x
@[symm] protected theorem equiv.symm {x y} : x ≈ y → y ≈ x := symm
@[trans] protected theorem equiv.trans {x y z} : x ≈ y → y ≈ z → x ≈ z := trans
protected theorem equiv_comm {x y} : x ≈ y ↔ y ≈ x := comm
theorem equiv_of_eq {x y} (h : x = y) : x ≈ y := by subst h
@[trans] theorem le_of_le_of_equiv {x y z} (h₁ : x ≤ y) (h₂ : y ≈ z) : x ≤ z := h₁.trans h₂.1
@[trans] theorem le_of_equiv_of_le {x y z} (h₁ : x ≈ y) : y ≤ z → x ≤ z := h₁.1.trans
theorem lf.not_equiv {x y} (h : x ⧏ y) : ¬ x ≈ y := λ h', h.not_ge h'.2
theorem lf.not_equiv' {x y} (h : x ⧏ y) : ¬ y ≈ x := λ h', h.not_ge h'.1
theorem lf.not_gt {x y} (h : x ⧏ y) : ¬ y < x := λ h', h.not_ge h'.le
theorem le_congr_imp {x₁ y₁ x₂ y₂} (hx : x₁ ≈ x₂) (hy : y₁ ≈ y₂) (h : x₁ ≤ y₁) : x₂ ≤ y₂ :=
hx.2.trans (h.trans hy.1)
theorem le_congr {x₁ y₁ x₂ y₂} (hx : x₁ ≈ x₂) (hy : y₁ ≈ y₂) : x₁ ≤ y₁ ↔ x₂ ≤ y₂ :=
⟨le_congr_imp hx hy, le_congr_imp hx.symm hy.symm⟩
theorem le_congr_left {x₁ x₂ y} (hx : x₁ ≈ x₂) : x₁ ≤ y ↔ x₂ ≤ y :=
le_congr hx equiv_rfl
theorem le_congr_right {x y₁ y₂} (hy : y₁ ≈ y₂) : x ≤ y₁ ↔ x ≤ y₂ :=
le_congr equiv_rfl hy
theorem lf_congr {x₁ y₁ x₂ y₂} (hx : x₁ ≈ x₂) (hy : y₁ ≈ y₂) : x₁ ⧏ y₁ ↔ x₂ ⧏ y₂ :=
pgame.not_le.symm.trans $ (not_congr (le_congr hy hx)).trans pgame.not_le
theorem lf_congr_imp {x₁ y₁ x₂ y₂} (hx : x₁ ≈ x₂) (hy : y₁ ≈ y₂) : x₁ ⧏ y₁ → x₂ ⧏ y₂ :=
(lf_congr hx hy).1
theorem lf_congr_left {x₁ x₂ y} (hx : x₁ ≈ x₂) : x₁ ⧏ y ↔ x₂ ⧏ y :=
lf_congr hx equiv_rfl
theorem lf_congr_right {x y₁ y₂} (hy : y₁ ≈ y₂) : x ⧏ y₁ ↔ x ⧏ y₂ :=
lf_congr equiv_rfl hy
@[trans] theorem lf_of_lf_of_equiv {x y z} (h₁ : x ⧏ y) (h₂ : y ≈ z) : x ⧏ z :=
lf_congr_imp equiv_rfl h₂ h₁
@[trans] theorem lf_of_equiv_of_lf {x y z} (h₁ : x ≈ y) : y ⧏ z → x ⧏ z :=
lf_congr_imp h₁.symm equiv_rfl
@[trans] theorem lt_of_lt_of_equiv {x y z} (h₁ : x < y) (h₂ : y ≈ z) : x < z := h₁.trans_le h₂.1
@[trans] theorem lt_of_equiv_of_lt {x y z} (h₁ : x ≈ y) : y < z → x < z := h₁.1.trans_lt
theorem lt_congr_imp {x₁ y₁ x₂ y₂} (hx : x₁ ≈ x₂) (hy : y₁ ≈ y₂) (h : x₁ < y₁) : x₂ < y₂ :=
hx.2.trans_lt (h.trans_le hy.1)
theorem lt_congr {x₁ y₁ x₂ y₂} (hx : x₁ ≈ x₂) (hy : y₁ ≈ y₂) : x₁ < y₁ ↔ x₂ < y₂ :=
⟨lt_congr_imp hx hy, lt_congr_imp hx.symm hy.symm⟩
theorem lt_congr_left {x₁ x₂ y} (hx : x₁ ≈ x₂) : x₁ < y ↔ x₂ < y :=
lt_congr hx equiv_rfl
theorem lt_congr_right {x y₁ y₂} (hy : y₁ ≈ y₂) : x < y₁ ↔ x < y₂ :=
lt_congr equiv_rfl hy
theorem lt_or_equiv_of_le {x y : pgame} (h : x ≤ y) : x < y ∨ x ≈ y :=
and_or_distrib_left.mp ⟨h, (em $ y ≤ x).swap.imp_left pgame.not_le.1⟩
theorem lf_or_equiv_or_gf (x y : pgame) : x ⧏ y ∨ x ≈ y ∨ y ⧏ x :=
begin
by_cases h : x ⧏ y,
{ exact or.inl h },
{ right,
cases (lt_or_equiv_of_le (pgame.not_lf.1 h)) with h' h',
{ exact or.inr h'.lf },
{ exact or.inl h'.symm } }
end
theorem equiv_congr_left {y₁ y₂} : y₁ ≈ y₂ ↔ ∀ x₁, x₁ ≈ y₁ ↔ x₁ ≈ y₂ :=
⟨λ h x₁, ⟨λ h', h'.trans h, λ h', h'.trans h.symm⟩,
λ h, (h y₁).1 $ equiv_rfl⟩
theorem equiv_congr_right {x₁ x₂} : x₁ ≈ x₂ ↔ ∀ y₁, x₁ ≈ y₁ ↔ x₂ ≈ y₁ :=
⟨λ h y₁, ⟨λ h', h.symm.trans h', λ h', h.trans h'⟩,
λ h, (h x₂).2 $ equiv_rfl⟩
theorem equiv_of_mk_equiv {x y : pgame}
(L : x.left_moves ≃ y.left_moves) (R : x.right_moves ≃ y.right_moves)
(hl : ∀ (i : x.left_moves), x.move_left i ≈ y.move_left (L i))
(hr : ∀ (j : y.right_moves), x.move_right (R.symm j) ≈ y.move_right j) :
x ≈ y :=
begin
fsplit; rw le_def,
{ exact ⟨λ i, or.inl ⟨L i, (hl i).1⟩, λ j, or.inr ⟨R.symm j, (hr j).1⟩⟩ },
{ fsplit,
{ intro i,
left,
specialize hl (L.symm i),
simp only [move_left_mk, equiv.apply_symm_apply] at hl,
use ⟨L.symm i, hl.2⟩ },
{ intro j,
right,
specialize hr (R j),
simp only [move_right_mk, equiv.symm_apply_apply] at hr,
use ⟨R j, hr.2⟩ } }
end
/-- The fuzzy, confused, or incomparable relation on pre-games.
If `x ∥ 0`, then the first player can always win `x`. -/
def fuzzy (x y : pgame) : Prop := x ⧏ y ∧ y ⧏ x
localized "infix ` ∥ `:50 := pgame.fuzzy" in pgame
@[symm] theorem fuzzy.swap {x y : pgame} : x ∥ y → y ∥ x := and.swap
instance : is_symm _ (∥) := ⟨λ x y, fuzzy.swap⟩
theorem fuzzy.swap_iff {x y : pgame} : x ∥ y ↔ y ∥ x := ⟨fuzzy.swap, fuzzy.swap⟩
theorem fuzzy_irrefl (x : pgame) : ¬ x ∥ x := λ h, lf_irrefl x h.1
instance : is_irrefl _ (∥) := ⟨fuzzy_irrefl⟩
theorem lf_iff_lt_or_fuzzy {x y : pgame} : x ⧏ y ↔ x < y ∨ x ∥ y :=
by { simp only [lt_iff_le_and_lf, fuzzy, ←pgame.not_le], tauto! }
theorem lf_of_fuzzy {x y : pgame} (h : x ∥ y) : x ⧏ y := lf_iff_lt_or_fuzzy.2 (or.inr h)
alias lf_of_fuzzy ← fuzzy.lf
theorem lt_or_fuzzy_of_lf {x y : pgame} : x ⧏ y → x < y ∨ x ∥ y :=
lf_iff_lt_or_fuzzy.1
theorem fuzzy.not_equiv {x y : pgame} (h : x ∥ y) : ¬ x ≈ y :=
λ h', h'.1.not_gf h.2
theorem fuzzy.not_equiv' {x y : pgame} (h : x ∥ y) : ¬ y ≈ x :=
λ h', h'.2.not_gf h.2
theorem not_fuzzy_of_le {x y : pgame} (h : x ≤ y) : ¬ x ∥ y :=
λ h', h'.2.not_ge h
theorem not_fuzzy_of_ge {x y : pgame} (h : y ≤ x) : ¬ x ∥ y :=
λ h', h'.1.not_ge h
theorem equiv.not_fuzzy {x y : pgame} (h : x ≈ y) : ¬ x ∥ y :=
not_fuzzy_of_le h.1
theorem equiv.not_fuzzy' {x y : pgame} (h : x ≈ y) : ¬ y ∥ x :=
not_fuzzy_of_le h.2
theorem fuzzy_congr {x₁ y₁ x₂ y₂ : pgame} (hx : x₁ ≈ x₂) (hy : y₁ ≈ y₂) : x₁ ∥ y₁ ↔ x₂ ∥ y₂ :=
show _ ∧ _ ↔ _ ∧ _, by rw [lf_congr hx hy, lf_congr hy hx]
theorem fuzzy_congr_imp {x₁ y₁ x₂ y₂ : pgame} (hx : x₁ ≈ x₂) (hy : y₁ ≈ y₂) : x₁ ∥ y₁ → x₂ ∥ y₂ :=
(fuzzy_congr hx hy).1
theorem fuzzy_congr_left {x₁ x₂ y} (hx : x₁ ≈ x₂) : x₁ ∥ y ↔ x₂ ∥ y :=
fuzzy_congr hx equiv_rfl
theorem fuzzy_congr_right {x y₁ y₂} (hy : y₁ ≈ y₂) : x ∥ y₁ ↔ x ∥ y₂ :=
fuzzy_congr equiv_rfl hy
@[trans] theorem fuzzy_of_fuzzy_of_equiv {x y z} (h₁ : x ∥ y) (h₂ : y ≈ z) : x ∥ z :=
(fuzzy_congr_right h₂).1 h₁
@[trans] theorem fuzzy_of_equiv_of_fuzzy {x y z} (h₁ : x ≈ y) (h₂ : y ∥ z) : x ∥ z :=
(fuzzy_congr_left h₁).2 h₂
/-- Exactly one of the following is true (although we don't prove this here). -/
theorem lt_or_equiv_or_gt_or_fuzzy (x y : pgame) : x < y ∨ x ≈ y ∨ y < x ∨ x ∥ y :=
begin
cases le_or_gf x y with h₁ h₁;
cases le_or_gf y x with h₂ h₂,
{ right, left, exact ⟨h₁, h₂⟩ },
{ left, exact ⟨h₁, h₂⟩ },
{ right, right, left, exact ⟨h₂, h₁⟩ },
{ right, right, right, exact ⟨h₂, h₁⟩ }
end
theorem lt_or_equiv_or_gf (x y : pgame) : x < y ∨ x ≈ y ∨ y ⧏ x :=
begin
rw [lf_iff_lt_or_fuzzy, fuzzy.swap_iff],
exact lt_or_equiv_or_gt_or_fuzzy x y
end
/-! ### Relabellings -/
/-- `restricted x y` says that Left always has no more moves in `x` than in `y`,
and Right always has no more moves in `y` than in `x` -/
inductive restricted : pgame.{u} → pgame.{u} → Type (u+1)
| mk : Π {x y : pgame} (L : x.left_moves → y.left_moves) (R : y.right_moves → x.right_moves),
(∀ i, restricted (x.move_left i) (y.move_left (L i))) →
(∀ j, restricted (x.move_right (R j)) (y.move_right j)) → restricted x y
/-- The identity restriction. -/
@[refl] def restricted.refl : Π (x : pgame), restricted x x
| x := ⟨_, _, λ i, restricted.refl _, λ j, restricted.refl _⟩
using_well_founded { dec_tac := pgame_wf_tac }
instance (x : pgame) : inhabited (restricted x x) := ⟨restricted.refl _⟩
/-- Transitivity of restriction. -/
def restricted.trans : Π {x y z : pgame} (r : restricted x y) (s : restricted y z), restricted x z
| x y z ⟨L₁, R₁, hL₁, hR₁⟩ ⟨L₂, R₂, hL₂, hR₂⟩ :=
⟨_, _, λ i, (hL₁ i).trans (hL₂ _), λ j, (hR₁ _).trans (hR₂ j)⟩
theorem restricted.le : Π {x y : pgame} (r : restricted x y), x ≤ y
| x y ⟨L, R, hL, hR⟩ :=
le_def.2 ⟨λ i, or.inl ⟨L i, (hL i).le⟩, λ i, or.inr ⟨R i, (hR i).le⟩⟩
/--
`relabelling x y` says that `x` and `y` are really the same game, just dressed up differently.
Specifically, there is a bijection between the moves for Left in `x` and in `y`, and similarly
for Right, and under these bijections we inductively have `relabelling`s for the consequent games.
-/
inductive relabelling : pgame.{u} → pgame.{u} → Type (u+1)
| mk : Π {x y : pgame} (L : x.left_moves ≃ y.left_moves) (R : x.right_moves ≃ y.right_moves),
(∀ i, relabelling (x.move_left i) (y.move_left (L i))) →
(∀ j, relabelling (x.move_right (R.symm j)) (y.move_right j)) →
relabelling x y
localized "infix ` ≡r `:50 := pgame.relabelling" in pgame
namespace relabelling
variables {x y : pgame.{u}}
/-- If `x` is a relabelling of `y`, then `x` is a restriction of `y`. -/
def restricted : Π {x y : pgame} (r : x ≡r y), restricted x y
| x y ⟨L, R, hL, hR⟩ :=
⟨L, R.symm, λ i, (hL i).restricted, λ j, (hR j).restricted⟩
-- It's not the case that `restricted x y → restricted y x → relabelling x y`,
-- but if we insisted that the maps in a restriction were injective, then one
-- could use Schröder-Bernstein for do this.
/-- The identity relabelling. -/
@[refl] def refl : Π (x : pgame), x ≡r x
| x := ⟨equiv.refl _, equiv.refl _, λ i, refl _, λ j, refl _⟩
using_well_founded { dec_tac := pgame_wf_tac }
instance (x : pgame) : inhabited (x ≡r x) := ⟨refl _⟩
/-- Flip a relabelling. -/
@[symm] def symm : Π {x y : pgame}, x ≡r y → y ≡r x
| x y ⟨L, R, hL, hR⟩ :=
⟨L.symm, R.symm, λ i, by simpa using (hL (L.symm i)).symm, λ j, by simpa using (hR (R j)).symm⟩
theorem le (r : x ≡r y) : x ≤ y := r.restricted.le
theorem ge (r : x ≡r y) : y ≤ x := r.symm.restricted.le
/-- A relabelling lets us prove equivalence of games. -/
theorem equiv (r : x ≡r y) : x ≈ y := ⟨r.le, r.ge⟩
/-- Transitivity of relabelling. -/
@[trans] def trans : Π {x y z : pgame}, x ≡r y → y ≡r z → x ≡r z
| x y z ⟨L₁, R₁, hL₁, hR₁⟩ ⟨L₂, R₂, hL₂, hR₂⟩ :=
⟨L₁.trans L₂, R₁.trans R₂,
λ i, by simpa using (hL₁ i).trans (hL₂ _), λ j, by simpa using (hR₁ _).trans (hR₂ j)⟩
/-- Any game without left or right moves is a relabelling of 0. -/
def is_empty (x : pgame) [is_empty x.left_moves] [is_empty x.right_moves] : x ≡r 0 :=
⟨equiv.equiv_pempty _, equiv.equiv_pempty _, is_empty_elim, is_empty_elim⟩
end relabelling
theorem equiv.is_empty (x : pgame) [is_empty x.left_moves] [is_empty x.right_moves] : x ≈ 0 :=
(relabelling.is_empty x).equiv
instance {x y : pgame} : has_coe (x ≡r y) (x ≈ y) := ⟨relabelling.equiv⟩
/-- Replace the types indexing the next moves for Left and Right by equivalent types. -/
def relabel {x : pgame} {xl' xr'} (el : x.left_moves ≃ xl') (er : x.right_moves ≃ xr') : pgame :=
⟨xl', xr', λ i, x.move_left (el.symm i), λ j, x.move_right (er.symm j)⟩
@[simp] lemma relabel_move_left' {x : pgame} {xl' xr'}
(el : x.left_moves ≃ xl') (er : x.right_moves ≃ xr') (i : xl') :
move_left (relabel el er) i = x.move_left (el.symm i) :=
rfl
@[simp] lemma relabel_move_left {x : pgame} {xl' xr'}
(el : x.left_moves ≃ xl') (er : x.right_moves ≃ xr') (i : x.left_moves) :
move_left (relabel el er) (el i) = x.move_left i :=
by simp
@[simp] lemma relabel_move_right' {x : pgame} {xl' xr'}
(el : x.left_moves ≃ xl') (er : x.right_moves ≃ xr') (j : xr') :
move_right (relabel el er) j = x.move_right (er.symm j) :=
rfl
@[simp] lemma relabel_move_right {x : pgame} {xl' xr'}
(el : x.left_moves ≃ xl') (er : x.right_moves ≃ xr') (j : x.right_moves) :
move_right (relabel el er) (er j) = x.move_right j :=
by simp
/-- The game obtained by relabelling the next moves is a relabelling of the original game. -/
def relabel_relabelling {x : pgame} {xl' xr'} (el : x.left_moves ≃ xl') (er : x.right_moves ≃ xr') :
x ≡r relabel el er :=
relabelling.mk el er (λ i, by simp) (λ j, by simp)
/-! ### Negation -/
/-- The negation of `{L | R}` is `{-R | -L}`. -/
def neg : pgame → pgame
| ⟨l, r, L, R⟩ := ⟨r, l, λ i, neg (R i), λ i, neg (L i)⟩
instance : has_neg pgame := ⟨neg⟩
@[simp] lemma neg_def {xl xr xL xR} : -(mk xl xr xL xR) = mk xr xl (λ j, -(xR j)) (λ i, -(xL i)) :=
rfl
instance : has_involutive_neg pgame :=
{ neg_neg := λ x, begin
induction x with xl xr xL xR ihL ihR,
simp_rw [neg_def, ihL, ihR],
exact ⟨rfl, rfl, heq.rfl, heq.rfl⟩,
end,
..pgame.has_neg }
@[simp] protected lemma neg_zero : -(0 : pgame) = 0 :=
begin
dsimp [has_zero.zero, has_neg.neg, neg],
congr; funext i; cases i
end
@[simp] lemma neg_of_lists (L R : list pgame) :
-of_lists L R = of_lists (R.map (λ x, -x)) (L.map (λ x, -x)) :=
begin
simp only [of_lists, neg_def, list.length_map, list.nth_le_map', eq_self_iff_true, true_and],
split, all_goals
{ apply hfunext,
{ simp },
{ intros a a' ha,
congr' 2,
have : ∀ {m n} (h₁ : m = n) {b : ulift (fin m)} {c : ulift (fin n)} (h₂ : b == c),
(b.down : ℕ) = ↑c.down,
{ rintros m n rfl b c rfl, refl },
exact this (list.length_map _ _).symm ha } }
end
theorem is_option_neg {x y : pgame} : is_option x (-y) ↔ is_option (-x) y :=
begin
rw [is_option_iff, is_option_iff, or_comm],
cases y, apply or_congr;
{ apply exists_congr, intro, rw ← neg_eq_iff_neg_eq, exact eq_comm },
end
@[simp] theorem is_option_neg_neg {x y : pgame} : is_option (-x) (-y) ↔ is_option x y :=
by rw [is_option_neg, neg_neg]
theorem left_moves_neg : ∀ x : pgame, (-x).left_moves = x.right_moves
| ⟨_, _, _, _⟩ := rfl
theorem right_moves_neg : ∀ x : pgame, (-x).right_moves = x.left_moves
| ⟨_, _, _, _⟩ := rfl
/-- Turns a right move for `x` into a left move for `-x` and vice versa.
Even though these types are the same (not definitionally so), this is the preferred way to convert
between them. -/
def to_left_moves_neg {x : pgame} : x.right_moves ≃ (-x).left_moves :=
equiv.cast (left_moves_neg x).symm
/-- Turns a left move for `x` into a right move for `-x` and vice versa.
Even though these types are the same (not definitionally so), this is the preferred way to convert
between them. -/
def to_right_moves_neg {x : pgame} : x.left_moves ≃ (-x).right_moves :=
equiv.cast (right_moves_neg x).symm
lemma move_left_neg {x : pgame} (i) :
(-x).move_left (to_left_moves_neg i) = -x.move_right i :=
by { cases x, refl }
@[simp] lemma move_left_neg' {x : pgame} (i) :
(-x).move_left i = -x.move_right (to_left_moves_neg.symm i) :=
by { cases x, refl }
lemma move_right_neg {x : pgame} (i) :
(-x).move_right (to_right_moves_neg i) = -(x.move_left i) :=
by { cases x, refl }
@[simp] lemma move_right_neg' {x : pgame} (i) :
(-x).move_right i = -x.move_left (to_right_moves_neg.symm i) :=
by { cases x, refl }
lemma move_left_neg_symm {x : pgame} (i) :
x.move_left (to_right_moves_neg.symm i) = -(-x).move_right i :=
by simp
lemma move_left_neg_symm' {x : pgame} (i) :
x.move_left i = -(-x).move_right (to_right_moves_neg i) :=
by simp
lemma move_right_neg_symm {x : pgame} (i) :
x.move_right (to_left_moves_neg.symm i) = -(-x).move_left i :=
by simp
lemma move_right_neg_symm' {x : pgame} (i) :
x.move_right i = -(-x).move_left (to_left_moves_neg i) :=
by simp
/-- If `x` has the same moves as `y`, then `-x` has the sames moves as `-y`. -/
def relabelling.neg_congr : ∀ {x y : pgame}, x ≡r y → -x ≡r -y
| ⟨xl, xr, xL, xR⟩ ⟨yl, yr, yL, yR⟩ ⟨L, R, hL, hR⟩ :=
⟨R, L,
λ i, relabelling.neg_congr (by simpa using hR (R i)),
λ i, relabelling.neg_congr (by simpa using hL (L.symm i))⟩
private theorem neg_le_lf_neg_iff :
Π {x y : pgame.{u}}, (-y ≤ -x ↔ x ≤ y) ∧ (-y ⧏ -x ↔ x ⧏ y)
| (mk xl xr xL xR) (mk yl yr yL yR) :=
begin
simp_rw [neg_def, mk_le_mk, mk_lf_mk, ← neg_def],
split,
{ rw and_comm, apply and_congr; exact forall_congr (λ _, neg_le_lf_neg_iff.2) },
{ rw or_comm, apply or_congr; exact exists_congr (λ _, neg_le_lf_neg_iff.1) },
end
using_well_founded { dec_tac := pgame_wf_tac }
@[simp] theorem neg_le_neg_iff {x y : pgame} : -y ≤ -x ↔ x ≤ y := neg_le_lf_neg_iff.1
@[simp] theorem neg_lf_neg_iff {x y : pgame} : -y ⧏ -x ↔ x ⧏ y := neg_le_lf_neg_iff.2
@[simp] theorem neg_lt_neg_iff {x y : pgame} : -y < -x ↔ x < y :=
by rw [lt_iff_le_and_lf, lt_iff_le_and_lf, neg_le_neg_iff, neg_lf_neg_iff]
@[simp] theorem neg_equiv_neg_iff {x y : pgame} : -x ≈ -y ↔ x ≈ y :=
by rw [equiv, equiv, neg_le_neg_iff, neg_le_neg_iff, and.comm]
@[simp] theorem neg_fuzzy_neg_iff {x y : pgame} : -x ∥ -y ↔ x ∥ y :=
by rw [fuzzy, fuzzy, neg_lf_neg_iff, neg_lf_neg_iff, and.comm]
theorem neg_le_iff {x y : pgame} : -y ≤ x ↔ -x ≤ y :=
by rw [←neg_neg x, neg_le_neg_iff, neg_neg]
theorem neg_lf_iff {x y : pgame} : -y ⧏ x ↔ -x ⧏ y :=
by rw [←neg_neg x, neg_lf_neg_iff, neg_neg]
theorem neg_lt_iff {x y : pgame} : -y < x ↔ -x < y :=
by rw [←neg_neg x, neg_lt_neg_iff, neg_neg]
theorem neg_equiv_iff {x y : pgame} : -x ≈ y ↔ x ≈ -y :=
by rw [←neg_neg y, neg_equiv_neg_iff, neg_neg]
theorem neg_fuzzy_iff {x y : pgame} : -x ∥ y ↔ x ∥ -y :=
by rw [←neg_neg y, neg_fuzzy_neg_iff, neg_neg]
theorem le_neg_iff {x y : pgame} : y ≤ -x ↔ x ≤ -y :=
by rw [←neg_neg x, neg_le_neg_iff, neg_neg]
theorem lf_neg_iff {x y : pgame} : y ⧏ -x ↔ x ⧏ -y :=
by rw [←neg_neg x, neg_lf_neg_iff, neg_neg]
theorem lt_neg_iff {x y : pgame} : y < -x ↔ x < -y :=
by rw [←neg_neg x, neg_lt_neg_iff, neg_neg]
@[simp] theorem neg_le_zero_iff {x : pgame} : -x ≤ 0 ↔ 0 ≤ x :=
by rw [neg_le_iff, pgame.neg_zero]
@[simp] theorem zero_le_neg_iff {x : pgame} : 0 ≤ -x ↔ x ≤ 0 :=
by rw [le_neg_iff, pgame.neg_zero]
@[simp] theorem neg_lf_zero_iff {x : pgame} : -x ⧏ 0 ↔ 0 ⧏ x :=
by rw [neg_lf_iff, pgame.neg_zero]
@[simp] theorem zero_lf_neg_iff {x : pgame} : 0 ⧏ -x ↔ x ⧏ 0 :=
by rw [lf_neg_iff, pgame.neg_zero]
@[simp] theorem neg_lt_zero_iff {x : pgame} : -x < 0 ↔ 0 < x :=
by rw [neg_lt_iff, pgame.neg_zero]
@[simp] theorem zero_lt_neg_iff {x : pgame} : 0 < -x ↔ x < 0 :=
by rw [lt_neg_iff, pgame.neg_zero]
@[simp] theorem neg_equiv_zero_iff {x : pgame} : -x ≈ 0 ↔ x ≈ 0 :=
by rw [neg_equiv_iff, pgame.neg_zero]
@[simp] theorem neg_fuzzy_zero_iff {x : pgame} : -x ∥ 0 ↔ x ∥ 0 :=
by rw [neg_fuzzy_iff, pgame.neg_zero]
@[simp] theorem zero_equiv_neg_iff {x : pgame} : 0 ≈ -x ↔ 0 ≈ x :=
by rw [←neg_equiv_iff, pgame.neg_zero]
@[simp] theorem zero_fuzzy_neg_iff {x : pgame} : 0 ∥ -x ↔ 0 ∥ x :=
by rw [←neg_fuzzy_iff, pgame.neg_zero]
/-! ### Addition and subtraction -/
/-- The sum of `x = {xL | xR}` and `y = {yL | yR}` is `{xL + y, x + yL | xR + y, x + yR}`. -/
instance : has_add pgame.{u} := ⟨λ x y, begin
induction x with xl xr xL xR IHxl IHxr generalizing y,
induction y with yl yr yL yR IHyl IHyr,
have y := mk yl yr yL yR,
refine ⟨xl ⊕ yl, xr ⊕ yr, sum.rec _ _, sum.rec _ _⟩,
{ exact λ i, IHxl i y },
{ exact IHyl },
{ exact λ i, IHxr i y },
{ exact IHyr }
end⟩
/-- The pre-game `((0+1)+⋯)+1`. -/
instance : has_nat_cast pgame := ⟨nat.unary_cast⟩
@[simp] protected theorem nat_succ (n : ℕ) : ((n + 1 : ℕ) : pgame) = n + 1 := rfl
instance is_empty_left_moves_add (x y : pgame.{u})
[is_empty x.left_moves] [is_empty y.left_moves] : is_empty (x + y).left_moves :=
begin
unfreezingI { cases x, cases y },
apply is_empty_sum.2 ⟨_, _⟩,
assumption'
end
instance is_empty_right_moves_add (x y : pgame.{u})
[is_empty x.right_moves] [is_empty y.right_moves] : is_empty (x + y).right_moves :=
begin
unfreezingI { cases x, cases y },
apply is_empty_sum.2 ⟨_, _⟩,
assumption'
end
/-- `x + 0` has exactly the same moves as `x`. -/
def add_zero_relabelling : Π (x : pgame.{u}), x + 0 ≡r x
| (mk xl xr xL xR) :=
begin
refine ⟨equiv.sum_empty xl pempty, equiv.sum_empty xr pempty, _, _⟩,
{ rintro (⟨i⟩|⟨⟨⟩⟩),
apply add_zero_relabelling, },
{ rintro j,
apply add_zero_relabelling, }
end
/-- `x + 0` is equivalent to `x`. -/
lemma add_zero_equiv (x : pgame.{u}) : x + 0 ≈ x :=
(add_zero_relabelling x).equiv
/-- `0 + x` has exactly the same moves as `x`. -/
def zero_add_relabelling : Π (x : pgame.{u}), 0 + x ≡r x
| (mk xl xr xL xR) :=
begin
refine ⟨equiv.empty_sum pempty xl, equiv.empty_sum pempty xr, _, _⟩,
{ rintro (⟨⟨⟩⟩|⟨i⟩),
apply zero_add_relabelling, },
{ rintro j,
apply zero_add_relabelling, }
end
/-- `0 + x` is equivalent to `x`. -/
lemma zero_add_equiv (x : pgame.{u}) : 0 + x ≈ x :=
(zero_add_relabelling x).equiv
theorem left_moves_add : ∀ (x y : pgame.{u}),
(x + y).left_moves = (x.left_moves ⊕ y.left_moves)
| ⟨_, _, _, _⟩ ⟨_, _, _, _⟩ := rfl
theorem right_moves_add : ∀ (x y : pgame.{u}),
(x + y).right_moves = (x.right_moves ⊕ y.right_moves)
| ⟨_, _, _, _⟩ ⟨_, _, _, _⟩ := rfl
/-- Converts a left move for `x` or `y` into a left move for `x + y` and vice versa.
Even though these types are the same (not definitionally so), this is the preferred way to convert
between them. -/
def to_left_moves_add {x y : pgame} :
x.left_moves ⊕ y.left_moves ≃ (x + y).left_moves :=
equiv.cast (left_moves_add x y).symm
/-- Converts a right move for `x` or `y` into a right move for `x + y` and vice versa.
Even though these types are the same (not definitionally so), this is the preferred way to convert
between them. -/
def to_right_moves_add {x y : pgame} :
x.right_moves ⊕ y.right_moves ≃ (x + y).right_moves :=
equiv.cast (right_moves_add x y).symm
@[simp] lemma mk_add_move_left_inl {xl xr yl yr} {xL xR yL yR} {i} :
(mk xl xr xL xR + mk yl yr yL yR).move_left (sum.inl i) =
(mk xl xr xL xR).move_left i + (mk yl yr yL yR) :=
rfl
@[simp] lemma add_move_left_inl {x : pgame} (y : pgame) (i) :
(x + y).move_left (to_left_moves_add (sum.inl i)) = x.move_left i + y :=
by { cases x, cases y, refl }
@[simp] lemma mk_add_move_right_inl {xl xr yl yr} {xL xR yL yR} {i} :
(mk xl xr xL xR + mk yl yr yL yR).move_right (sum.inl i) =
(mk xl xr xL xR).move_right i + (mk yl yr yL yR) :=
rfl
@[simp] lemma add_move_right_inl {x : pgame} (y : pgame) (i) :
(x + y).move_right (to_right_moves_add (sum.inl i)) = x.move_right i + y :=
by { cases x, cases y, refl }
@[simp] lemma mk_add_move_left_inr {xl xr yl yr} {xL xR yL yR} {i} :
(mk xl xr xL xR + mk yl yr yL yR).move_left (sum.inr i) =
(mk xl xr xL xR) + (mk yl yr yL yR).move_left i :=
rfl
@[simp] lemma add_move_left_inr (x : pgame) {y : pgame} (i) :
(x + y).move_left (to_left_moves_add (sum.inr i)) = x + y.move_left i :=
by { cases x, cases y, refl }
@[simp] lemma mk_add_move_right_inr {xl xr yl yr} {xL xR yL yR} {i} :
(mk xl xr xL xR + mk yl yr yL yR).move_right (sum.inr i) =
(mk xl xr xL xR) + (mk yl yr yL yR).move_right i :=
rfl
@[simp] lemma add_move_right_inr (x : pgame) {y : pgame} (i) :
(x + y).move_right (to_right_moves_add (sum.inr i)) = x + y.move_right i :=
by { cases x, cases y, refl }
lemma left_moves_add_cases {x y : pgame} (k) {P : (x + y).left_moves → Prop}
(hl : ∀ i, P $ to_left_moves_add (sum.inl i))
(hr : ∀ i, P $ to_left_moves_add (sum.inr i)) : P k :=
begin
rw ←to_left_moves_add.apply_symm_apply k,
cases to_left_moves_add.symm k with i i,
{ exact hl i },
{ exact hr i }
end
lemma right_moves_add_cases {x y : pgame} (k) {P : (x + y).right_moves → Prop}
(hl : ∀ j, P $ to_right_moves_add (sum.inl j))
(hr : ∀ j, P $ to_right_moves_add (sum.inr j)) : P k :=
begin
rw ←to_right_moves_add.apply_symm_apply k,
cases to_right_moves_add.symm k with i i,
{ exact hl i },
{ exact hr i }
end
instance is_empty_nat_right_moves : ∀ n : ℕ, is_empty (right_moves n)
| 0 := pempty.is_empty
| (n + 1) := begin
haveI := is_empty_nat_right_moves n,
rw [pgame.nat_succ, right_moves_add],
apply_instance
end
/-- If `w` has the same moves as `x` and `y` has the same moves as `z`,
then `w + y` has the same moves as `x + z`. -/
def relabelling.add_congr : ∀ {w x y z : pgame.{u}}, w ≡r x → y ≡r z → w + y ≡r x + z
| ⟨wl, wr, wL, wR⟩ ⟨xl, xr, xL, xR⟩ ⟨yl, yr, yL, yR⟩ ⟨zl, zr, zL, zR⟩
⟨L₁, R₁, hL₁, hR₁⟩ ⟨L₂, R₂, hL₂, hR₂⟩ :=
begin
let Hwx : ⟨wl, wr, wL, wR⟩ ≡r ⟨xl, xr, xL, xR⟩ := ⟨L₁, R₁, hL₁, hR₁⟩,
let Hyz : ⟨yl, yr, yL, yR⟩ ≡r ⟨zl, zr, zL, zR⟩ := ⟨L₂, R₂, hL₂, hR₂⟩,
refine ⟨equiv.sum_congr L₁ L₂, equiv.sum_congr R₁ R₂, _, _⟩;
rintro (i|j),
{ exact (hL₁ i).add_congr Hyz },
{ exact Hwx.add_congr (hL₂ j) },
{ exact (hR₁ i).add_congr Hyz },
{ exact Hwx.add_congr (hR₂ j) }
end
using_well_founded { dec_tac := pgame_wf_tac }
instance : has_sub pgame := ⟨λ x y, x + -y⟩
@[simp] theorem sub_zero (x : pgame) : x - 0 = x + 0 :=
show x + -0 = x + 0, by rw pgame.neg_zero
/-- If `w` has the same moves as `x` and `y` has the same moves as `z`,
then `w - y` has the same moves as `x - z`. -/
def relabelling.sub_congr {w x y z : pgame} (h₁ : w ≡r x) (h₂ : y ≡r z) : w - y ≡r x - z :=
h₁.add_congr h₂.neg_congr
/-- `-(x + y)` has exactly the same moves as `-x + -y`. -/
def neg_add_relabelling : Π (x y : pgame), -(x + y) ≡r -x + -y
| ⟨xl, xr, xL, xR⟩ ⟨yl, yr, yL, yR⟩ :=
begin
refine ⟨equiv.refl _, equiv.refl _, _, _⟩,
all_goals {
exact λ j, sum.cases_on j
(λ j, neg_add_relabelling _ _)
(λ j, neg_add_relabelling ⟨xl, xr, xL, xR⟩ _) }
end
using_well_founded { dec_tac := pgame_wf_tac }
theorem neg_add_le {x y : pgame} : -(x + y) ≤ -x + -y :=
(neg_add_relabelling x y).le
/-- `x + y` has exactly the same moves as `y + x`. -/
def add_comm_relabelling : Π (x y : pgame.{u}), x + y ≡r y + x
| (mk xl xr xL xR) (mk yl yr yL yR) :=
begin
refine ⟨equiv.sum_comm _ _, equiv.sum_comm _ _, _, _⟩;
rintros (_|_);
{ dsimp [left_moves_add, right_moves_add], apply add_comm_relabelling }
end
using_well_founded { dec_tac := pgame_wf_tac }
theorem add_comm_le {x y : pgame} : x + y ≤ y + x :=
(add_comm_relabelling x y).le
theorem add_comm_equiv {x y : pgame} : x + y ≈ y + x :=
(add_comm_relabelling x y).equiv
/-- `(x + y) + z` has exactly the same moves as `x + (y + z)`. -/
def add_assoc_relabelling : Π (x y z : pgame.{u}), x + y + z ≡r x + (y + z)
| ⟨xl, xr, xL, xR⟩ ⟨yl, yr, yL, yR⟩ ⟨zl, zr, zL, zR⟩ :=
begin
refine ⟨equiv.sum_assoc _ _ _, equiv.sum_assoc _ _ _, _, _⟩,
all_goals
{ rintro (⟨i|i⟩|i) <|> rintro (j|⟨j|j⟩),
{ apply add_assoc_relabelling },
{ apply add_assoc_relabelling ⟨xl, xr, xL, xR⟩ },
{ apply add_assoc_relabelling ⟨xl, xr, xL, xR⟩ ⟨yl, yr, yL, yR⟩ } }
end
using_well_founded { dec_tac := pgame_wf_tac }
theorem add_assoc_equiv {x y z : pgame} : (x + y) + z ≈ x + (y + z) :=
(add_assoc_relabelling x y z).equiv
theorem add_left_neg_le_zero : ∀ (x : pgame), -x + x ≤ 0
| ⟨xl, xr, xL, xR⟩ :=
le_zero.2 $ λ i, begin
cases i,
{ -- If Left played in -x, Right responds with the same move in x.
refine ⟨@to_right_moves_add _ ⟨_, _, _, _⟩ (sum.inr i), _⟩,
convert @add_left_neg_le_zero (xR i),
apply add_move_right_inr },
{ -- If Left in x, Right responds with the same move in -x.
dsimp,
refine ⟨@to_right_moves_add ⟨_, _, _, _⟩ _ (sum.inl i), _⟩,
convert @add_left_neg_le_zero (xL i),
apply add_move_right_inl }
end
theorem zero_le_add_left_neg (x : pgame) : 0 ≤ -x + x :=
begin
rw [←neg_le_neg_iff, pgame.neg_zero],
exact neg_add_le.trans (add_left_neg_le_zero _)
end
theorem add_left_neg_equiv (x : pgame) : -x + x ≈ 0 :=
⟨add_left_neg_le_zero x, zero_le_add_left_neg x⟩
theorem add_right_neg_le_zero (x : pgame) : x + -x ≤ 0 :=
add_comm_le.trans (add_left_neg_le_zero x)
theorem zero_le_add_right_neg (x : pgame) : 0 ≤ x + -x :=
(zero_le_add_left_neg x).trans add_comm_le
theorem add_right_neg_equiv (x : pgame) : x + -x ≈ 0 :=
⟨add_right_neg_le_zero x, zero_le_add_right_neg x⟩
theorem sub_self_equiv : ∀ x, x - x ≈ 0 :=
add_right_neg_equiv
private lemma add_le_add_right' : ∀ {x y z : pgame} (h : x ≤ y), x + z ≤ y + z
| (mk xl xr xL xR) (mk yl yr yL yR) (mk zl zr zL zR) :=
λ h, begin
refine le_def.2 ⟨λ i, _, λ i, _⟩;
cases i,
{ rw le_def at h,
cases h,
rcases h_left i with ⟨i', ih⟩ | ⟨j, jh⟩,
{ exact or.inl ⟨to_left_moves_add (sum.inl i'), add_le_add_right' ih⟩ },
{ refine or.inr ⟨to_right_moves_add (sum.inl j), _⟩,
convert add_le_add_right' jh,
apply add_move_right_inl } },
{ exact or.inl ⟨@to_left_moves_add _ ⟨_, _, _, _⟩ (sum.inr i), add_le_add_right' h⟩ },
{ rw le_def at h,
cases h,
rcases h_right i with ⟨i, ih⟩ | ⟨j', jh⟩,
{ refine or.inl ⟨to_left_moves_add (sum.inl i), _⟩,
convert add_le_add_right' ih,
apply add_move_left_inl },
{ exact or.inr ⟨to_right_moves_add (sum.inl j'), add_le_add_right' jh⟩ } },
{ exact or.inr ⟨@to_right_moves_add _ ⟨_, _, _, _⟩ (sum.inr i), add_le_add_right' h⟩ }
end
using_well_founded { dec_tac := pgame_wf_tac }
instance covariant_class_swap_add_le : covariant_class pgame pgame (swap (+)) (≤) :=
⟨λ x y z, add_le_add_right'⟩
instance covariant_class_add_le : covariant_class pgame pgame (+) (≤) :=
⟨λ x y z h, (add_comm_le.trans (add_le_add_right h x)).trans add_comm_le⟩
theorem add_lf_add_right {y z : pgame} (h : y ⧏ z) (x) : y + x ⧏ z + x :=
suffices z + x ≤ y + x → z ≤ y, by { rw ←pgame.not_le at ⊢ h, exact mt this h }, λ w,
calc z ≤ z + 0 : (add_zero_relabelling _).symm.le
... ≤ z + (x + -x) : add_le_add_left (zero_le_add_right_neg x) _
... ≤ z + x + -x : (add_assoc_relabelling _ _ _).symm.le
... ≤ y + x + -x : add_le_add_right w _
... ≤ y + (x + -x) : (add_assoc_relabelling _ _ _).le
... ≤ y + 0 : add_le_add_left (add_right_neg_le_zero x) _
... ≤ y : (add_zero_relabelling _).le
theorem add_lf_add_left {y z : pgame} (h : y ⧏ z) (x) : x + y ⧏ x + z :=
by { rw lf_congr add_comm_equiv add_comm_equiv, apply add_lf_add_right h }
instance covariant_class_swap_add_lt : covariant_class pgame pgame (swap (+)) (<) :=
⟨λ x y z h, ⟨add_le_add_right h.1 x, add_lf_add_right h.2 x⟩⟩
instance covariant_class_add_lt : covariant_class pgame pgame (+) (<) :=
⟨λ x y z h, ⟨add_le_add_left h.1 x, add_lf_add_left h.2 x⟩⟩
theorem add_lf_add_of_lf_of_le {w x y z : pgame} (hwx : w ⧏ x) (hyz : y ≤ z) : w + y ⧏ x + z :=
lf_of_lf_of_le (add_lf_add_right hwx y) (add_le_add_left hyz x)
theorem add_lf_add_of_le_of_lf {w x y z : pgame} (hwx : w ≤ x) (hyz : y ⧏ z) : w + y ⧏ x + z :=
lf_of_le_of_lf (add_le_add_right hwx y) (add_lf_add_left hyz x)
theorem add_congr {w x y z : pgame} (h₁ : w ≈ x) (h₂ : y ≈ z) : w + y ≈ x + z :=
⟨(add_le_add_left h₂.1 w).trans (add_le_add_right h₁.1 z),
(add_le_add_left h₂.2 x).trans (add_le_add_right h₁.2 y)⟩
theorem add_congr_left {x y z : pgame} (h : x ≈ y) : x + z ≈ y + z :=
add_congr h equiv_rfl
theorem add_congr_right {x y z : pgame} : y ≈ z → x + y ≈ x + z :=
add_congr equiv_rfl
theorem sub_congr {w x y z : pgame} (h₁ : w ≈ x) (h₂ : y ≈ z) : w - y ≈ x - z :=
add_congr h₁ (neg_equiv_neg_iff.2 h₂)
theorem sub_congr_left {x y z : pgame} (h : x ≈ y) : x - z ≈ y - z :=
sub_congr h equiv_rfl
theorem sub_congr_right {x y z : pgame} : y ≈ z → x - y ≈ x - z :=
sub_congr equiv_rfl
theorem le_iff_sub_nonneg {x y : pgame} : x ≤ y ↔ 0 ≤ y - x :=
⟨λ h, (zero_le_add_right_neg x).trans (add_le_add_right h _),
λ h,
calc x ≤ 0 + x : (zero_add_relabelling x).symm.le
... ≤ y - x + x : add_le_add_right h _
... ≤ y + (-x + x) : (add_assoc_relabelling _ _ _).le
... ≤ y + 0 : add_le_add_left (add_left_neg_le_zero x) _
... ≤ y : (add_zero_relabelling y).le⟩
theorem lf_iff_sub_zero_lf {x y : pgame} : x ⧏ y ↔ 0 ⧏ y - x :=
⟨λ h, (zero_le_add_right_neg x).trans_lf (add_lf_add_right h _),
λ h,
calc x ≤ 0 + x : (zero_add_relabelling x).symm.le
... ⧏ y - x + x : add_lf_add_right h _
... ≤ y + (-x + x) : (add_assoc_relabelling _ _ _).le
... ≤ y + 0 : add_le_add_left (add_left_neg_le_zero x) _
... ≤ y : (add_zero_relabelling y).le⟩
theorem lt_iff_sub_pos {x y : pgame} : x < y ↔ 0 < y - x :=
⟨λ h, lt_of_le_of_lt (zero_le_add_right_neg x) (add_lt_add_right h _),
λ h,
calc x ≤ 0 + x : (zero_add_relabelling x).symm.le
... < y - x + x : add_lt_add_right h _
... ≤ y + (-x + x) : (add_assoc_relabelling _ _ _).le
... ≤ y + 0 : add_le_add_left (add_left_neg_le_zero x) _
... ≤ y : (add_zero_relabelling y).le⟩
/-! ### Special pre-games -/
/-- The pre-game `star`, which is fuzzy with zero. -/
def star : pgame.{u} := ⟨punit, punit, λ _, 0, λ _, 0⟩
@[simp] theorem star_left_moves : star.left_moves = punit := rfl
@[simp] theorem star_right_moves : star.right_moves = punit := rfl
@[simp] theorem star_move_left (x) : star.move_left x = 0 := rfl
@[simp] theorem star_move_right (x) : star.move_right x = 0 := rfl
instance unique_star_left_moves : unique star.left_moves := punit.unique
instance unique_star_right_moves : unique star.right_moves := punit.unique
theorem star_fuzzy_zero : star ∥ 0 :=
⟨by { rw lf_zero, use default, rintros ⟨⟩ }, by { rw zero_lf, use default, rintros ⟨⟩ }⟩
@[simp] theorem neg_star : -star = star :=
by simp [star]
@[simp] theorem zero_lt_one : (0 : pgame) < 1 :=
lt_of_le_of_lf (zero_le_of_is_empty_right_moves 1) (zero_lf_le.2 ⟨default, le_rfl⟩)
instance : zero_le_one_class pgame := ⟨zero_lt_one.le⟩
@[simp] theorem zero_lf_one : (0 : pgame) ⧏ 1 :=
zero_lt_one.lf
end pgame
|
c251269f193dc22eb0e98183d84cbb33911361d2
|
c777c32c8e484e195053731103c5e52af26a25d1
|
/src/category_theory/monoidal/Mod_.lean
|
e88e0ba3371710ca6023365bb7c7b3be15b382fa
|
[
"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
| 3,646
|
lean
|
/-
Copyright (c) 2020 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import category_theory.monoidal.Mon_
/-!
# The category of module objects over a monoid object.
-/
universes v₁ v₂ u₁ u₂
open category_theory
open category_theory.monoidal_category
variables (C : Type u₁) [category.{v₁} C] [monoidal_category.{v₁} C]
variables {C}
/-- A module object for a monoid object, all internal to some monoidal category. -/
structure Mod_ (A : Mon_ C) :=
(X : C)
(act : A.X ⊗ X ⟶ X)
(one_act' : (A.one ⊗ 𝟙 X) ≫ act = (λ_ X).hom . obviously)
(assoc' : (A.mul ⊗ 𝟙 X) ≫ act = (α_ A.X A.X X).hom ≫ (𝟙 A.X ⊗ act) ≫ act . obviously)
restate_axiom Mod_.one_act'
restate_axiom Mod_.assoc'
attribute [simp, reassoc] Mod_.one_act Mod_.assoc
namespace Mod_
variables {A : Mon_ C} (M : Mod_ A)
lemma assoc_flip : (𝟙 A.X ⊗ M.act) ≫ M.act = (α_ A.X A.X M.X).inv ≫ (A.mul ⊗ 𝟙 M.X) ≫ M.act :=
by simp
/-- A morphism of module objects. -/
@[ext]
structure hom (M N : Mod_ A) :=
(hom : M.X ⟶ N.X)
(act_hom' : M.act ≫ hom = (𝟙 A.X ⊗ hom) ≫ N.act . obviously)
restate_axiom hom.act_hom'
attribute [simp, reassoc] hom.act_hom
/-- The identity morphism on a module object. -/
@[simps]
def id (M : Mod_ A) : hom M M :=
{ hom := 𝟙 M.X, }
instance hom_inhabited (M : Mod_ A) : inhabited (hom M M) := ⟨id M⟩
/-- Composition of module object morphisms. -/
@[simps]
def comp {M N O : Mod_ A} (f : hom M N) (g : hom N O) : hom M O :=
{ hom := f.hom ≫ g.hom, }
instance : category (Mod_ A) :=
{ hom := λ M N, hom M N,
id := id,
comp := λ M N O f g, comp f g, }
@[simp] lemma id_hom' (M : Mod_ A) : (𝟙 M : hom M M).hom = 𝟙 M.X := rfl
@[simp] lemma comp_hom' {M N K : Mod_ A} (f : M ⟶ N) (g : N ⟶ K) :
(f ≫ g : hom M K).hom = f.hom ≫ g.hom := rfl
variables (A)
/-- A monoid object as a module over itself. -/
@[simps]
def regular : Mod_ A :=
{ X := A.X,
act := A.mul, }
instance : inhabited (Mod_ A) := ⟨regular A⟩
/-- The forgetful functor from module objects to the ambient category. -/
def forget : Mod_ A ⥤ C :=
{ obj := λ A, A.X,
map := λ A B f, f.hom, }
open category_theory.monoidal_category
/--
A morphism of monoid objects induces a "restriction" or "comap" functor
between the categories of module objects.
-/
@[simps]
def comap {A B : Mon_ C} (f : A ⟶ B) : Mod_ B ⥤ Mod_ A :=
{ obj := λ M,
{ X := M.X,
act := (f.hom ⊗ 𝟙 M.X) ≫ M.act,
one_act' :=
begin
slice_lhs 1 2 { rw [←comp_tensor_id], },
rw [f.one_hom, one_act],
end,
assoc' :=
begin
-- oh, for homotopy.io in a widget!
slice_rhs 2 3 { rw [id_tensor_comp_tensor_id, ←tensor_id_comp_id_tensor], },
rw id_tensor_comp,
slice_rhs 4 5 { rw Mod_.assoc_flip, },
slice_rhs 3 4 { rw associator_inv_naturality, },
slice_rhs 2 3 { rw [←tensor_id, associator_inv_naturality], },
slice_rhs 1 3 { rw [iso.hom_inv_id_assoc], },
slice_rhs 1 2 { rw [←comp_tensor_id, tensor_id_comp_id_tensor], },
slice_rhs 1 2 { rw [←comp_tensor_id, ←f.mul_hom], },
rw [comp_tensor_id, category.assoc],
end, },
map := λ M N g,
{ hom := g.hom,
act_hom' :=
begin
dsimp,
slice_rhs 1 2 { rw [id_tensor_comp_tensor_id, ←tensor_id_comp_id_tensor], },
slice_rhs 2 3 { rw ←g.act_hom, },
rw category.assoc,
end }, }
-- Lots more could be said about `comap`, e.g. how it interacts with
-- identities, compositions, and equalities of monoid object morphisms.
end Mod_
|
a8c6b76ddf4e06757cf437a28ec84321098fc46e
|
ba4794a0deca1d2aaa68914cd285d77880907b5c
|
/src/game/world2/level2.lean
|
0dcc6217e0c3be1e26ac3b7056292d9d99a1bb5d
|
[
"Apache-2.0"
] |
permissive
|
ChrisHughes24/natural_number_game
|
c7c00aa1f6a95004286fd456ed13cf6e113159ce
|
9d09925424da9f6275e6cfe427c8bcf12bb0944f
|
refs/heads/master
| 1,600,715,773,528
| 1,573,910,462,000
| 1,573,910,462,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 1,797
|
lean
|
import mynat.definition -- hide
import mynat.add -- hide
import game.world2.level1 -- hide
namespace mynat -- hide
/-
# Addition world
Don't forget to use the drop down boxes on the left to see your tactics and
what you have proved so far.
## Level 2: `add_assoc` -- associativity of addition.
It's well-known that (1 + 2) + 3 = 1 + (2 + 3) -- if we have three numbers
to add up, it doesn't matter which of the additions we do first. This fact
is called *associativity of addition* by mathematicians, and it is *not*
obvious. For example, subtraction really is not associative: $(6 - 2) - 1$
is really not equal to $6 - (2 - 1)$. We are going to have to prove
that addition, as defined the way we've defined it, is associative.
See if you can prove associativity of addition. Hint: because addition was defined
by recursion on the right-most variable, use induction on the right-most
variable (try other variables at your peril!). Note that when Lean writes `a + b + c`,
it means `(a + b) + c`. If it wants to talk about `a + (b + c)` it will put the brackets
in explictly.
Reminder: you are done when you see "Proof complete!" in the top right, and an empty
box (no errors) in the bottom right.
-/
/- Lemma
On the set of natural numbers, addition is associative.
In other words, for all natural numbers $a, b$ and $c$, we have
$$ (a + b) + c = a + (b + c). $$
-/
lemma add_assoc (a b c : mynat) : (a + b) + c = a + (b + c) :=
begin [less_leaky]
induction c with d hd,
{ -- ⊢ a + b + 0 = a + (b + 0)
rw add_zero,
rw add_zero,
refl
},
{ -- ⊢ (a + b) + succ d = a + (b + succ d)
rw add_succ,
rw add_succ,
rw add_succ,
rw hd,
refl,
}
end
/-
Once you have associativity (sub-boss), let's move on to commutativity (boss).
-/
end mynat -- hide
|
f53b98e47cb022458976db7432d9494240e4973c
|
302c785c90d40ad3d6be43d33bc6a558354cc2cf
|
/src/algebra/group/inj_surj.lean
|
d7b787ceb5faa438a846e071ccb1f589179aa02c
|
[
"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
| 12,702
|
lean
|
/-
Copyright (c) 2020 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin
-/
import algebra.group.defs
import logic.function.basic
/-!
# Lifting algebraic data classes along injective/surjective maps
This file provides definitions that are meant to deal with
situations such as the following:
Suppose that `G` is a group, and `H` is a type endowed with
`has_one H`, `has_mul H`, and `has_inv H`.
Suppose furthermore, that `f : G → H` is a surjective map
that respects the multiplication, and the unit elements.
Then `H` satisfies the group axioms.
The relevant definition in this case is `function.surjective.group`.
Dually, there is also `function.injective.group`.
And there are versions for (additive) (commutative) semigroups/monoids.
-/
namespace function
/-!
### Injective
-/
namespace injective
variables {M₁ : Type*} {M₂ : Type*} [has_mul M₁]
/-- A type endowed with `*` is a semigroup,
if it admits an injective map that preserves `*` to a semigroup. -/
@[to_additive
"A type endowed with `+` is an additive semigroup,
if it admits an injective map that preserves `+` to an additive semigroup."]
protected def semigroup [semigroup M₂] (f : M₁ → M₂) (hf : injective f)
(mul : ∀ x y, f (x * y) = f x * f y) :
semigroup M₁ :=
{ mul_assoc := λ x y z, hf $ by erw [mul, mul, mul, mul, mul_assoc],
..‹has_mul M₁› }
/-- A type endowed with `*` is a commutative semigroup,
if it admits an injective map that preserves `*` to a commutative semigroup. -/
@[to_additive
"A type endowed with `+` is an additive commutative semigroup,
if it admits an injective map that preserves `+` to an additive commutative semigroup."]
protected def comm_semigroup [comm_semigroup M₂] (f : M₁ → M₂) (hf : injective f)
(mul : ∀ x y, f (x * y) = f x * f y) :
comm_semigroup M₁ :=
{ mul_comm := λ x y, hf $ by erw [mul, mul, mul_comm],
.. hf.semigroup f mul }
/-- A type endowed with `*` is a left cancel semigroup,
if it admits an injective map that preserves `*` to a left cancel semigroup. -/
@[to_additive add_left_cancel_semigroup
"A type endowed with `+` is an additive left cancel semigroup,
if it admits an injective map that preserves `+` to an additive left cancel semigroup."]
protected def left_cancel_semigroup [left_cancel_semigroup M₂] (f : M₁ → M₂) (hf : injective f)
(mul : ∀ x y, f (x * y) = f x * f y) :
left_cancel_semigroup M₁ :=
{ mul := (*),
mul_left_cancel := λ x y z H, hf $ (mul_right_inj (f x)).1 $ by erw [← mul, ← mul, H]; refl,
.. hf.semigroup f mul }
/-- A type endowed with `*` is a right cancel semigroup,
if it admits an injective map that preserves `*` to a right cancel semigroup. -/
@[to_additive add_right_cancel_semigroup
"A type endowed with `+` is an additive right cancel semigroup,
if it admits an injective map that preserves `+` to an additive right cancel semigroup."]
protected def right_cancel_semigroup [right_cancel_semigroup M₂] (f : M₁ → M₂) (hf : injective f)
(mul : ∀ x y, f (x * y) = f x * f y) :
right_cancel_semigroup M₁ :=
{ mul := (*),
mul_right_cancel := λ x y z H, hf $ (mul_left_inj (f y)).1 $ by erw [← mul, ← mul, H]; refl,
.. hf.semigroup f mul }
variables [has_one M₁]
/-- A type endowed with `1` and `*` is a mul_one_class,
if it admits an injective map that preserves `1` and `*` to a mul_one_class. -/
@[to_additive
"A type endowed with `0` and `+` is an add_zero_class,
if it admits an injective map that preserves `0` and `+` to an add_zero_class."]
protected def mul_one_class [mul_one_class M₂] (f : M₁ → M₂) (hf : injective f)
(one : f 1 = 1) (mul : ∀ x y, f (x * y) = f x * f y) :
mul_one_class M₁ :=
{ one_mul := λ x, hf $ by erw [mul, one, one_mul],
mul_one := λ x, hf $ by erw [mul, one, mul_one],
..‹has_one M₁›, ..‹has_mul M₁› }
/-- A type endowed with `1` and `*` is a monoid,
if it admits an injective map that preserves `1` and `*` to a monoid. -/
@[to_additive
"A type endowed with `0` and `+` is an additive monoid,
if it admits an injective map that preserves `0` and `+` to an additive monoid."]
protected def monoid [monoid M₂] (f : M₁ → M₂) (hf : injective f)
(one : f 1 = 1) (mul : ∀ x y, f (x * y) = f x * f y) :
monoid M₁ :=
{ .. hf.semigroup f mul, .. hf.mul_one_class f one mul }
/-- A type endowed with `1` and `*` is a left cancel monoid,
if it admits an injective map that preserves `1` and `*` to a left cancel monoid. -/
@[to_additive add_left_cancel_monoid
"A type endowed with `0` and `+` is an additive left cancel monoid,
if it admits an injective map that preserves `0` and `+` to an additive left cancel monoid."]
protected def left_cancel_monoid [left_cancel_monoid M₂] (f : M₁ → M₂) (hf : injective f)
(one : f 1 = 1) (mul : ∀ x y, f (x * y) = f x * f y) :
left_cancel_monoid M₁ :=
{ .. hf.left_cancel_semigroup f mul, .. hf.monoid f one mul }
/-- A type endowed with `1` and `*` is a commutative monoid,
if it admits an injective map that preserves `1` and `*` to a commutative monoid. -/
@[to_additive
"A type endowed with `0` and `+` is an additive commutative monoid,
if it admits an injective map that preserves `0` and `+` to an additive commutative monoid."]
protected def comm_monoid [comm_monoid M₂] (f : M₁ → M₂) (hf : injective f)
(one : f 1 = 1) (mul : ∀ x y, f (x * y) = f x * f y) :
comm_monoid M₁ :=
{ .. hf.comm_semigroup f mul, .. hf.monoid f one mul }
variables [has_inv M₁] [has_div M₁]
/-- A type endowed with `1`, `*`, `⁻¹`, and `/` is a `div_inv_monoid`
if it admits an injective map that preserves `1`, `*`, `⁻¹`, and `/` to a `div_inv_monoid`. -/
@[to_additive
"A type endowed with `0`, `+`, unary `-`, and binary `-` is a `sub_neg_monoid`
if it admits an injective map that preserves `0`, `+`, unary `-`, and binary `-` to
a `sub_neg_monoid`."]
protected def div_inv_monoid [div_inv_monoid M₂] (f : M₁ → M₂) (hf : injective f)
(one : f 1 = 1) (mul : ∀ x y, f (x * y) = f x * f y) (inv : ∀ x, f x⁻¹ = (f x)⁻¹)
(div : ∀ x y, f (x / y) = f x / f y) :
div_inv_monoid M₁ :=
{ div_eq_mul_inv := λ x y, hf $ by erw [div, mul, inv, div_eq_mul_inv],
.. hf.monoid f one mul, .. ‹has_inv M₁›, .. ‹has_div M₁› }
/-- A type endowed with `1`, `*` and `⁻¹` is a group,
if it admits an injective map that preserves `1`, `*` and `⁻¹` to a group. -/
@[to_additive
"A type endowed with `0` and `+` is an additive group,
if it admits an injective map that preserves `0` and `+` to an additive group."]
protected def group [group M₂] (f : M₁ → M₂) (hf : injective f)
(one : f 1 = 1) (mul : ∀ x y, f (x * y) = f x * f y) (inv : ∀ x, f (x⁻¹) = (f x)⁻¹)
(div : ∀ x y, f (x / y) = f x / f y) :
group M₁ :=
{ mul_left_inv := λ x, hf $ by erw [mul, inv, mul_left_inv, one],
.. hf.div_inv_monoid f one mul inv div }
/-- A type endowed with `1`, `*` and `⁻¹` is a commutative group,
if it admits an injective map that preserves `1`, `*` and `⁻¹` to a commutative group. -/
@[to_additive
"A type endowed with `0` and `+` is an additive commutative group,
if it admits an injective map that preserves `0` and `+` to an additive commutative group."]
protected def comm_group [comm_group M₂] (f : M₁ → M₂) (hf : injective f)
(one : f 1 = 1) (mul : ∀ x y, f (x * y) = f x * f y) (inv : ∀ x, f (x⁻¹) = (f x)⁻¹)
(div : ∀ x y, f (x / y) = f x / f y) :
comm_group M₁ :=
{ .. hf.comm_monoid f one mul, .. hf.group f one mul inv div }
end injective
/-!
### Surjective
-/
namespace surjective
variables {M₁ : Type*} {M₂ : Type*} [has_mul M₂]
/-- A type endowed with `*` is a semigroup,
if it admits a surjective map that preserves `*` from a semigroup. -/
@[to_additive
"A type endowed with `+` is an additive semigroup,
if it admits a surjective map that preserves `+` from an additive semigroup."]
protected def semigroup [semigroup M₁] (f : M₁ → M₂) (hf : surjective f)
(mul : ∀ x y, f (x * y) = f x * f y) :
semigroup M₂ :=
{ mul_assoc := hf.forall₃.2 $ λ x y z, by simp only [← mul, mul_assoc],
..‹has_mul M₂› }
/-- A type endowed with `*` is a commutative semigroup,
if it admits a surjective map that preserves `*` from a commutative semigroup. -/
@[to_additive
"A type endowed with `+` is an additive commutative semigroup,
if it admits a surjective map that preserves `+` from an additive commutative semigroup."]
protected def comm_semigroup [comm_semigroup M₁] (f : M₁ → M₂) (hf : surjective f)
(mul : ∀ x y, f (x * y) = f x * f y) :
comm_semigroup M₂ :=
{ mul_comm := hf.forall₂.2 $ λ x y, by erw [← mul, ← mul, mul_comm],
.. hf.semigroup f mul }
variables [has_one M₂]
/-- A type endowed with `1` and `*` is a mul_one_class,
if it admits a surjective map that preserves `1` and `*` from a mul_one_class. -/
@[to_additive
"A type endowed with `0` and `+` is an add_zero_class,
if it admits a surjective map that preserves `0` and `+` to an add_zero_class."]
protected def mul_one_class [mul_one_class M₁] (f : M₁ → M₂) (hf : surjective f)
(one : f 1 = 1) (mul : ∀ x y, f (x * y) = f x * f y) :
mul_one_class M₂ :=
{ one_mul := hf.forall.2 $ λ x, by erw [← one, ← mul, one_mul],
mul_one := hf.forall.2 $ λ x, by erw [← one, ← mul, mul_one],
..‹has_one M₂›, ..‹has_mul M₂› }
/-- A type endowed with `1` and `*` is a monoid,
if it admits a surjective map that preserves `1` and `*` from a monoid. -/
@[to_additive
"A type endowed with `0` and `+` is an additive monoid,
if it admits a surjective map that preserves `0` and `+` to an additive monoid."]
protected def monoid [monoid M₁] (f : M₁ → M₂) (hf : surjective f)
(one : f 1 = 1) (mul : ∀ x y, f (x * y) = f x * f y) :
monoid M₂ :=
{ .. hf.semigroup f mul, .. hf.mul_one_class f one mul }
/-- A type endowed with `1` and `*` is a commutative monoid,
if it admits a surjective map that preserves `1` and `*` from a commutative monoid. -/
@[to_additive
"A type endowed with `0` and `+` is an additive commutative monoid,
if it admits a surjective map that preserves `0` and `+` to an additive commutative monoid."]
protected def comm_monoid [comm_monoid M₁] (f : M₁ → M₂) (hf : surjective f)
(one : f 1 = 1) (mul : ∀ x y, f (x * y) = f x * f y) :
comm_monoid M₂ :=
{ .. hf.comm_semigroup f mul, .. hf.monoid f one mul }
variables [has_inv M₂] [has_div M₂]
/-- A type endowed with `1`, `*`, `⁻¹`, and `/` is a `div_inv_monoid`,
if it admits a surjective map that preserves `1`, `*`, `⁻¹`, and `/` from a `div_inv_monoid` -/
@[to_additive
"A type endowed with `0`, `+`, and `-` (unary and binary) is an additive group,
if it admits a surjective map that preserves `0`, `+`, and `-` from a `sub_neg_monoid`"]
protected def div_inv_monoid [div_inv_monoid M₁] (f : M₁ → M₂) (hf : surjective f)
(one : f 1 = 1) (mul : ∀ x y, f (x * y) = f x * f y) (inv : ∀ x, f (x⁻¹) = (f x)⁻¹)
(div : ∀ x y, f (x / y) = f x / f y) :
div_inv_monoid M₂ :=
{ div_eq_mul_inv := hf.forall₂.2 $ λ x y, by erw [← inv, ← mul, ← div, div_eq_mul_inv],
.. hf.monoid f one mul, .. ‹has_div M₂›, .. ‹has_inv M₂› }
/-- A type endowed with `1`, `*`, `⁻¹`, and `/` is a group,
if it admits a surjective map that preserves `1`, `*`, `⁻¹`, and `/` from a group. -/
@[to_additive
"A type endowed with `0`, `+`, and unary `-` is an additive group,
if it admits a surjective map that preserves `0`, `+`, and `-` from an additive group."]
protected def group [group M₁] (f : M₁ → M₂) (hf : surjective f)
(one : f 1 = 1) (mul : ∀ x y, f (x * y) = f x * f y) (inv : ∀ x, f (x⁻¹) = (f x)⁻¹)
(div : ∀ x y, f (x / y) = f x / f y) :
group M₂ :=
{ mul_left_inv := hf.forall.2 $ λ x, by erw [← inv, ← mul, mul_left_inv, one]; refl,
.. hf.div_inv_monoid f one mul inv div }
/-- A type endowed with `1`, `*`, `⁻¹`, and `/` is a commutative group,
if it admits a surjective map that preserves `1`, `*`, `⁻¹`, and `/` from a commutative group. -/
@[to_additive
"A type endowed with `0` and `+` is an additive commutative group,
if it admits a surjective map that preserves `0` and `+` to an additive commutative group."]
protected def comm_group [comm_group M₁] (f : M₁ → M₂) (hf : surjective f)
(one : f 1 = 1) (mul : ∀ x y, f (x * y) = f x * f y) (inv : ∀ x, f (x⁻¹) = (f x)⁻¹)
(div : ∀ x y, f (x / y) = f x / f y) :
comm_group M₂ :=
{ .. hf.comm_monoid f one mul, .. hf.group f one mul inv div }
end surjective
end function
|
a8a252459f74f95f873a0f3c6664d423aaf791a6
|
737dc4b96c97368cb66b925eeea3ab633ec3d702
|
/stage0/src/Lean/Parser/Extra.lean
|
52d76fd089a6fe3a91dd0e33fb5d276d174c7fa2
|
[
"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
| 5,116
|
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, Sebastian Ullrich
-/
import Lean.Parser.Extension
-- necessary for auto-generation
import Lean.PrettyPrinter.Parenthesizer
import Lean.PrettyPrinter.Formatter
namespace Lean
namespace Parser
-- synthesize pretty printers for parsers declared prior to `Lean.PrettyPrinter`
-- (because `Parser.Extension` depends on them)
attribute [runBuiltinParserAttributeHooks]
leadingNode termParser commandParser mkAntiquot nodeWithAntiquot sepBy sepBy1
unicodeSymbol nonReservedSymbol
@[runBuiltinParserAttributeHooks] def optional (p : Parser) : Parser :=
optionalNoAntiquot (withAntiquotSpliceAndSuffix `optional p (symbol "?"))
@[runBuiltinParserAttributeHooks] def many (p : Parser) : Parser :=
manyNoAntiquot (withAntiquotSpliceAndSuffix `many p (symbol "*"))
@[runBuiltinParserAttributeHooks] def many1 (p : Parser) : Parser :=
many1NoAntiquot (withAntiquotSpliceAndSuffix `many p (symbol "*"))
@[runBuiltinParserAttributeHooks] def ident : Parser :=
withAntiquot (mkAntiquot "ident" identKind) identNoAntiquot
-- `ident` and `rawIdent` produce the same syntax tree, so we reuse the antiquotation kind name
@[runBuiltinParserAttributeHooks] def rawIdent : Parser :=
withAntiquot (mkAntiquot "ident" identKind) rawIdentNoAntiquot
@[runBuiltinParserAttributeHooks] def numLit : Parser :=
withAntiquot (mkAntiquot "numLit" numLitKind) numLitNoAntiquot
@[runBuiltinParserAttributeHooks] def scientificLit : Parser :=
withAntiquot (mkAntiquot "scientificLit" scientificLitKind) scientificLitNoAntiquot
@[runBuiltinParserAttributeHooks] def strLit : Parser :=
withAntiquot (mkAntiquot "strLit" strLitKind) strLitNoAntiquot
@[runBuiltinParserAttributeHooks] def charLit : Parser :=
withAntiquot (mkAntiquot "charLit" charLitKind) charLitNoAntiquot
@[runBuiltinParserAttributeHooks] def nameLit : Parser :=
withAntiquot (mkAntiquot "nameLit" nameLitKind) nameLitNoAntiquot
@[runBuiltinParserAttributeHooks, inline] def group (p : Parser) : Parser :=
node groupKind p
@[runBuiltinParserAttributeHooks, inline] def many1Indent (p : Parser) : Parser :=
withPosition $ many1 (checkColGe "irrelevant" >> p)
@[runBuiltinParserAttributeHooks, inline] def manyIndent (p : Parser) : Parser :=
withPosition $ many (checkColGe "irrelevant" >> p)
@[runBuiltinParserAttributeHooks] abbrev notSymbol (s : String) : Parser :=
notFollowedBy (symbol s) s
/-- No-op parser that advises the pretty printer to emit a non-breaking space. -/
@[inline] def ppHardSpace : Parser := skip
/-- No-op parser that advises the pretty printer to emit a space/soft line break. -/
@[inline] def ppSpace : Parser := skip
/-- No-op parser that advises the pretty printer to emit a hard line break. -/
@[inline] def ppLine : Parser := skip
/--
No-op parser combinator that advises the pretty printer to group and indent the given syntax.
By default, only syntax categories are grouped. -/
@[inline] def ppGroup : Parser → Parser := id
/-- No-op parser combinator that advises the pretty printer to indent the given syntax without grouping it. -/
@[inline] def ppIndent : Parser → Parser := id
/--
No-op parser combinator that advises the pretty printer to dedent the given syntax.
Dedenting can in particular be used to counteract automatic indentation. -/
@[inline] def ppDedent : Parser → Parser := id
end Parser
section
open PrettyPrinter
@[combinatorFormatter Lean.Parser.ppHardSpace] def ppHardSpace.formatter : Formatter := Formatter.push " "
@[combinatorFormatter Lean.Parser.ppSpace] def ppSpace.formatter : Formatter := Formatter.pushLine
@[combinatorFormatter Lean.Parser.ppLine] def ppLine.formatter : Formatter := Formatter.push "\n"
@[combinatorFormatter Lean.Parser.ppGroup] def ppGroup.formatter (p : Formatter) : Formatter := Formatter.group $ Formatter.indent p
@[combinatorFormatter Lean.Parser.ppIndent] def ppIndent.formatter (p : Formatter) : Formatter := Formatter.indent p
@[combinatorFormatter Lean.Parser.ppDedent] def ppDedent.formatter (p : Formatter) : Formatter := do
let opts ← getOptions
Formatter.indent p (some ((0:Int) - Std.Format.getIndent opts))
end
namespace Parser
-- now synthesize parenthesizers
attribute [runBuiltinParserAttributeHooks]
ppHardSpace ppSpace ppLine ppGroup ppIndent ppDedent
macro "register_parser_alias" aliasName:strLit declName:ident : term =>
`(do Parser.registerAlias $aliasName $declName
PrettyPrinter.Formatter.registerAlias $aliasName $(mkIdentFrom declName (declName.getId ++ `formatter))
PrettyPrinter.Parenthesizer.registerAlias $aliasName $(mkIdentFrom declName (declName.getId ++ `parenthesizer)))
builtin_initialize
register_parser_alias "group" group
register_parser_alias "ppHardSpace" ppHardSpace
register_parser_alias "ppSpace" ppSpace
register_parser_alias "ppLine" ppLine
register_parser_alias "ppGroup" ppGroup
register_parser_alias "ppIndent" ppIndent
register_parser_alias "ppDedent" ppDedent
end Parser
end Lean
|
39c2e7ceb3c24a0a8e61f84352d1cf4a87539727
|
4d2583807a5ac6caaffd3d7a5f646d61ca85d532
|
/src/topology/tactic.lean
|
4af4fea8429af2af40d1a8644b5b7fa80d1accf8
|
[
"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
| 4,068
|
lean
|
/-
Copyright (c) 2020 Reid Barton. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Reid Barton
-/
import tactic.auto_cases
import tactic.tidy
import tactic.with_local_reducibility
import tactic.show_term
import topology.basic
/-!
# Tactics for topology
Currently we have one domain-specific tactic for topology: `continuity`.
-/
/-!
### `continuity` tactic
Automatically solve goals of the form `continuous f`.
Mark lemmas with `@[continuity]` to add them to the set of lemmas
used by `continuity`.
-/
/-- User attribute used to mark tactics used by `continuity`. -/
@[user_attribute]
meta def continuity : user_attribute :=
{ name := `continuity,
descr := "lemmas usable to prove continuity" }
-- Mark some continuity lemmas already defined in `topology.basic`
attribute [continuity]
continuous_id
continuous_const
-- As we will be using `apply_rules` with `md := semireducible`,
-- we need another version of `continuous_id`.
@[continuity] lemma continuous_id' {α : Type*} [topological_space α] : continuous (λ a : α, a) :=
continuous_id
namespace tactic
/--
Tactic to apply `continuous.comp` when appropriate.
Applying `continuous.comp` is not always a good idea, so we have some
extra logic here to try to avoid bad cases.
* If the function we're trying to prove continuous is actually
constant, and that constant is a function application `f z`, then
continuous.comp would produce new goals `continuous f`, `continuous
(λ _, z)`, which is silly. We avoid this by failing if we could
apply continuous_const.
* continuous.comp will always succeed on `continuous (λ x, f x)` and
produce new goals `continuous (λ x, x)`, `continuous f`. We detect
this by failing if a new goal can be closed by applying
continuous_id.
-/
meta def apply_continuous.comp : tactic unit :=
`[fail_if_success { exact continuous_const };
refine continuous.comp _ _;
fail_if_success { exact continuous_id }]
/-- List of tactics used by `continuity` internally. -/
meta def continuity_tactics (md : transparency := reducible) : list (tactic string) :=
[
intros1 >>= λ ns, pure ("intros " ++ (" ".intercalate (ns.map (λ e, e.to_string)))),
apply_rules [``(continuity)] 50 { md := md }
>> pure "apply_rules continuity",
apply_continuous.comp >> pure "refine continuous.comp _ _"
]
namespace interactive
setup_tactic_parser
/--
Solve goals of the form `continuous f`. `continuity?` reports back the proof term it found.
-/
meta def continuity
(bang : parse $ optional (tk "!")) (trace : parse $ optional (tk "?")) (cfg : tidy.cfg := {}) :
tactic unit :=
let md := if bang.is_some then semireducible else reducible,
continuity_core := tactic.tidy { tactics := continuity_tactics md, ..cfg },
trace_fn := if trace.is_some then show_term else id in
trace_fn continuity_core
/-- Version of `continuity` for use with auto_param. -/
meta def continuity' : tactic unit := continuity none none {}
/--
`continuity` solves goals of the form `continuous f` by applying lemmas tagged with the
`continuity` user attribute.
```
example {X Y : Type*} [topological_space X] [topological_space Y]
(f₁ f₂ : X → Y) (hf₁ : continuous f₁) (hf₂ : continuous f₂)
(g : Y → ℝ) (hg : continuous g) : continuous (λ x, (max (g (f₁ x)) (g (f₂ x))) + 1) :=
by continuity
```
will discharge the goal, generating a proof term like
`((continuous.comp hg hf₁).max (continuous.comp hg hf₂)).add continuous_const`
You can also use `continuity!`, which applies lemmas with `{ md := semireducible }`.
The default behaviour is more conservative, and only unfolds `reducible` definitions
when attempting to match lemmas with the goal.
`continuity?` reports back the proof term it found.
-/
add_tactic_doc
{ name := "continuity / continuity'",
category := doc_category.tactic,
decl_names := [`tactic.interactive.continuity, `tactic.interactive.continuity'],
tags := ["lemma application"]
}
end interactive
end tactic
|
e48b42654dbb06c553dff37c0b551a51c8759380
|
05f637fa14ac28031cb1ea92086a0f4eb23ff2b1
|
/tests/lean/coercion1.lean
|
e03ca901412d6fad21bb4505c5776a801af18095
|
[
"Apache-2.0"
] |
permissive
|
codyroux/lean0.1
|
1ce92751d664aacff0529e139083304a7bbc8a71
|
0dc6fb974aa85ed6f305a2f4b10a53a44ee5f0ef
|
refs/heads/master
| 1,610,830,535,062
| 1,402,150,480,000
| 1,402,150,480,000
| 19,588,851
| 2
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 283
|
lean
|
variable T : Type
variable R : Type
variable f : T -> R
coercion f
print environment 2
variable g : T -> R
coercion g
variable h : forall (x : Type), x
coercion h
definition T2 : Type := T
definition R2 : Type := R
variable f2 : T2 -> R2
coercion f2
variable id : T -> T
coercion id
|
c0ba7acf9d4a829f45727073b2118c3a41ccb69e
|
8cae430f0a71442d02dbb1cbb14073b31048e4b0
|
/src/algebra/order/monoid/basic.lean
|
f2a9adb01108a805128a58b37e38254956de244b
|
[
"Apache-2.0"
] |
permissive
|
leanprover-community/mathlib
|
56a2cadd17ac88caf4ece0a775932fa26327ba0e
|
442a83d738cb208d3600056c489be16900ba701d
|
refs/heads/master
| 1,693,584,102,358
| 1,693,471,902,000
| 1,693,471,902,000
| 97,922,418
| 1,595
| 352
|
Apache-2.0
| 1,694,693,445,000
| 1,500,624,130,000
|
Lean
|
UTF-8
|
Lean
| false
| false
| 3,190
|
lean
|
/-
Copyright (c) 2016 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura, Mario Carneiro, Johannes Hölzl
-/
import algebra.order.monoid.defs
import algebra.group.inj_surj
import order.hom.basic
/-!
# Ordered monoids
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
This file develops some additional material on ordered monoids.
-/
set_option old_structure_cmd true
open function
universe u
variables {α : Type u} {β : Type*}
/-- Pullback an `ordered_comm_monoid` under an injective map.
See note [reducible non-instances]. -/
@[reducible, to_additive function.injective.ordered_add_comm_monoid
"Pullback an `ordered_add_comm_monoid` under an injective map."]
def function.injective.ordered_comm_monoid [ordered_comm_monoid α] {β : Type*}
[has_one β] [has_mul β] [has_pow β ℕ]
(f : β → α) (hf : function.injective f) (one : f 1 = 1)
(mul : ∀ x y, f (x * y) = f x * f y) (npow : ∀ x (n : ℕ), f (x ^ n) = f x ^ n) :
ordered_comm_monoid β :=
{ mul_le_mul_left := λ a b ab c, show f (c * a) ≤ f (c * b), by
{ rw [mul, mul], apply mul_le_mul_left', exact ab },
..partial_order.lift f hf,
..hf.comm_monoid f one mul npow }
/-- Pullback a `linear_ordered_comm_monoid` under an injective map.
See note [reducible non-instances]. -/
@[reducible, to_additive function.injective.linear_ordered_add_comm_monoid
"Pullback an `ordered_add_comm_monoid` under an injective map."]
def function.injective.linear_ordered_comm_monoid [linear_ordered_comm_monoid α] {β : Type*}
[has_one β] [has_mul β] [has_pow β ℕ] [has_sup β] [has_inf β]
(f : β → α) (hf : function.injective f) (one : f 1 = 1)
(mul : ∀ x y, f (x * y) = f x * f y) (npow : ∀ x (n : ℕ), f (x ^ n) = f x ^ n)
(hsup : ∀ x y, f (x ⊔ y) = max (f x) (f y)) (hinf : ∀ x y, f (x ⊓ y) = min (f x) (f y)) :
linear_ordered_comm_monoid β :=
{ .. hf.ordered_comm_monoid f one mul npow,
.. linear_order.lift f hf hsup hinf }
-- TODO find a better home for the next two constructions.
/-- The order embedding sending `b` to `a * b`, for some fixed `a`.
See also `order_iso.mul_left` when working in an ordered group. -/
@[to_additive "The order embedding sending `b` to `a + b`, for some fixed `a`.
See also `order_iso.add_left` when working in an additive ordered group.", simps]
def order_embedding.mul_left
{α : Type*} [has_mul α] [linear_order α] [covariant_class α α (*) (<)] (m : α) : α ↪o α :=
order_embedding.of_strict_mono (λ n, m * n) (λ a b w, mul_lt_mul_left' w m)
/-- The order embedding sending `b` to `b * a`, for some fixed `a`.
See also `order_iso.mul_right` when working in an ordered group. -/
@[to_additive "The order embedding sending `b` to `b + a`, for some fixed `a`.
See also `order_iso.add_right` when working in an additive ordered group.", simps]
def order_embedding.mul_right
{α : Type*} [has_mul α] [linear_order α] [covariant_class α α (swap (*)) (<)] (m : α) :
α ↪o α :=
order_embedding.of_strict_mono (λ n, n * m) (λ a b w, mul_lt_mul_right' w m)
|
c87739b8dbb6ae123b3ab7d4150a4693140382f2
|
74addaa0e41490cbaf2abd313a764c96df57b05d
|
/Mathlib/topology/separation.lean
|
a73d404eee26b28219bc893831b9b1f60641b7ee
|
[] |
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
| 21,788
|
lean
|
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro
Separation properties of topological spaces.
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.topology.subset_properties
import Mathlib.PostPort
universes u l u_1 u_2 v
namespace Mathlib
/--
`separated` is a predicate on pairs of sub`set`s of a topological space. It holds if the two
sub`set`s are contained in disjoint open sets.
-/
def separated {α : Type u} [topological_space α] : set α → set α → Prop :=
fun (s t : set α) => ∃ (U : set α), ∃ (V : set α), is_open U ∧ is_open V ∧ s ⊆ U ∧ t ⊆ V ∧ disjoint U V
namespace separated
theorem symm {α : Type u} [topological_space α] {s : set α} {t : set α} : separated s t → separated t s := sorry
theorem comm {α : Type u} [topological_space α] (s : set α) (t : set α) : separated s t ↔ separated t s :=
{ mp := symm, mpr := symm }
theorem empty_right {α : Type u} [topological_space α] (a : set α) : separated a ∅ := sorry
theorem empty_left {α : Type u} [topological_space α] (a : set α) : separated ∅ a :=
symm (empty_right a)
theorem union_left {α : Type u} [topological_space α] {a : set α} {b : set α} {c : set α} : separated a c → separated b c → separated (a ∪ b) c := sorry
theorem union_right {α : Type u} [topological_space α] {a : set α} {b : set α} {c : set α} (ab : separated a b) (ac : separated a c) : separated a (b ∪ c) :=
symm (union_left (symm ab) (symm ac))
end separated
/-- A T₀ space, also known as a Kolmogorov space, is a topological space
where for every pair `x ≠ y`, there is an open set containing one but not the other. -/
class t0_space (α : Type u) [topological_space α]
where
t0 : ∀ (x y : α), x ≠ y → ∃ (U : set α), is_open U ∧ xor (x ∈ U) (y ∈ U)
theorem exists_open_singleton_of_open_finset {α : Type u} [topological_space α] [t0_space α] (s : finset α) (sne : finset.nonempty s) (hso : is_open ↑s) : ∃ (x : α), ∃ (H : x ∈ s), is_open (singleton x) := sorry
theorem exists_open_singleton_of_fintype {α : Type u} [topological_space α] [t0_space α] [f : fintype α] [ha : Nonempty α] : ∃ (x : α), is_open (singleton x) := sorry
protected instance subtype.t0_space {α : Type u} [topological_space α] [t0_space α] {p : α → Prop} : t0_space (Subtype p) :=
t0_space.mk fun (x y : Subtype p) (hxy : x ≠ y) => sorry
/-- A T₁ space, also known as a Fréchet space, is a topological space
where every singleton set is closed. Equivalently, for every pair
`x ≠ y`, there is an open set containing `x` and not `y`. -/
class t1_space (α : Type u) [topological_space α]
where
t1 : ∀ (x : α), is_closed (singleton x)
theorem is_closed_singleton {α : Type u} [topological_space α] [t1_space α] {x : α} : is_closed (singleton x) :=
t1_space.t1 x
theorem is_open_compl_singleton {α : Type u} [topological_space α] [t1_space α] {x : α} : is_open (singleton xᶜ) :=
is_closed_singleton
theorem is_open_ne {α : Type u} [topological_space α] [t1_space α] {x : α} : is_open (set_of fun (y : α) => y ≠ x) :=
is_open_compl_singleton
protected instance subtype.t1_space {α : Type u} [topological_space α] [t1_space α] {p : α → Prop} : t1_space (Subtype p) :=
t1_space.mk fun (_x : Subtype p) => sorry
protected instance t1_space.t0_space {α : Type u} [topological_space α] [t1_space α] : t0_space α :=
t0_space.mk
fun (x y : α) (h : x ≠ y) =>
Exists.intro (set_of fun (z : α) => z ≠ y)
{ left := is_open_ne, right := Or.inl { left := h, right := not_not_intro rfl } }
theorem compl_singleton_mem_nhds {α : Type u} [topological_space α] [t1_space α] {x : α} {y : α} (h : y ≠ x) : singleton xᶜ ∈ nhds y :=
mem_nhds_sets is_closed_singleton
(eq.mpr (id (Eq._oldrec (Eq.refl (y ∈ (singleton xᶜ))) (set.mem_compl_eq (singleton x) y)))
(eq.mpr (id (Eq._oldrec (Eq.refl (¬y ∈ singleton x)) (propext set.mem_singleton_iff))) h))
@[simp] theorem closure_singleton {α : Type u} [topological_space α] [t1_space α] {a : α} : closure (singleton a) = singleton a :=
is_closed.closure_eq is_closed_singleton
theorem is_closed_map_const {α : Type u_1} {β : Type u_2} [topological_space α] [topological_space β] [t1_space β] {y : β} : is_closed_map (function.const α y) := sorry
theorem discrete_of_t1_of_finite {X : Type u_1} [topological_space X] [t1_space X] [fintype X] : discrete_topology X := sorry
theorem singleton_mem_nhds_within_of_mem_discrete {α : Type u} [topological_space α] {s : set α} [discrete_topology ↥s] {x : α} (hx : x ∈ s) : singleton x ∈ nhds_within x s := sorry
theorem nhds_within_of_mem_discrete {α : Type u} [topological_space α] {s : set α} [discrete_topology ↥s] {x : α} (hx : x ∈ s) : nhds_within x s = pure x :=
le_antisymm (iff.mpr filter.le_pure_iff (singleton_mem_nhds_within_of_mem_discrete hx)) (pure_le_nhds_within hx)
theorem filter.has_basis.exists_inter_eq_singleton_of_mem_discrete {α : Type u} [topological_space α] {ι : Type u_1} {p : ι → Prop} {t : ι → set α} {s : set α} [discrete_topology ↥s] {x : α} (hb : filter.has_basis (nhds x) p t) (hx : x ∈ s) : ∃ (i : ι), ∃ (hi : p i), t i ∩ s = singleton x := sorry
/-- A point `x` in a discrete subset `s` of a topological space admits a neighbourhood
that only meets `s` at `x`. -/
theorem nhds_inter_eq_singleton_of_mem_discrete {α : Type u} [topological_space α] {s : set α} [discrete_topology ↥s] {x : α} (hx : x ∈ s) : ∃ (U : set α), ∃ (H : U ∈ nhds x), U ∩ s = singleton x := sorry
/-- For point `x` in a discrete subset `s` of a topological space, there is a set `U`
such that
1. `U` is a punctured neighborhood of `x` (ie. `U ∪ {x}` is a neighbourhood of `x`),
2. `U` is disjoint from `s`.
-/
theorem disjoint_nhds_within_of_mem_discrete {α : Type u} [topological_space α] {s : set α} [discrete_topology ↥s] {x : α} (hx : x ∈ s) : ∃ (U : set α), ∃ (H : U ∈ nhds_within x (singleton xᶜ)), disjoint U s := sorry
/-- A T₂ space, also known as a Hausdorff space, is one in which for every
`x ≠ y` there exists disjoint open sets around `x` and `y`. This is
the most widely used of the separation axioms. -/
class t2_space (α : Type u) [topological_space α]
where
t2 : ∀ (x y : α), x ≠ y → ∃ (u : set α), ∃ (v : set α), is_open u ∧ is_open v ∧ x ∈ u ∧ y ∈ v ∧ u ∩ v = ∅
theorem t2_separation {α : Type u} [topological_space α] [t2_space α] {x : α} {y : α} (h : x ≠ y) : ∃ (u : set α), ∃ (v : set α), is_open u ∧ is_open v ∧ x ∈ u ∧ y ∈ v ∧ u ∩ v = ∅ :=
t2_space.t2 x y h
protected instance t2_space.t1_space {α : Type u} [topological_space α] [t2_space α] : t1_space α :=
t1_space.mk fun (x : α) => iff.mpr is_open_iff_forall_mem_open fun (y : α) (hxy : y ∈ (singleton xᶜ)) => sorry
theorem eq_of_nhds_ne_bot {α : Type u} [topological_space α] [ht : t2_space α] {x : α} {y : α} (h : filter.ne_bot (nhds x ⊓ nhds y)) : x = y := sorry
theorem t2_iff_nhds {α : Type u} [topological_space α] : t2_space α ↔ ∀ {x y : α}, filter.ne_bot (nhds x ⊓ nhds y) → x = y := sorry
theorem t2_iff_ultrafilter {α : Type u} [topological_space α] : t2_space α ↔ ∀ {x y : α} (f : ultrafilter α), ↑f ≤ nhds x → ↑f ≤ nhds y → x = y := sorry
theorem is_closed_diagonal {α : Type u} [topological_space α] [t2_space α] : is_closed (set.diagonal α) := sorry
theorem t2_iff_is_closed_diagonal {α : Type u} [topological_space α] : t2_space α ↔ is_closed (set.diagonal α) := sorry
theorem finset_disjoint_finset_opens_of_t2 {α : Type u} [topological_space α] [t2_space α] (s : finset α) (t : finset α) : disjoint s t → separated ↑s ↑t := sorry
theorem point_disjoint_finset_opens_of_t2 {α : Type u} [topological_space α] [t2_space α] {x : α} {s : finset α} (h : ¬x ∈ s) : separated (singleton x) ↑s := sorry
@[simp] theorem nhds_eq_nhds_iff {α : Type u} [topological_space α] {a : α} {b : α} [t2_space α] : nhds a = nhds b ↔ a = b := sorry
@[simp] theorem nhds_le_nhds_iff {α : Type u} [topological_space α] {a : α} {b : α} [t2_space α] : nhds a ≤ nhds b ↔ a = b := sorry
theorem tendsto_nhds_unique {α : Type u} {β : Type v} [topological_space α] [t2_space α] {f : β → α} {l : filter β} {a : α} {b : α} [filter.ne_bot l] (ha : filter.tendsto f l (nhds a)) (hb : filter.tendsto f l (nhds b)) : a = b :=
eq_of_nhds_ne_bot (filter.ne_bot_of_le (le_inf ha hb))
theorem tendsto_nhds_unique' {α : Type u} {β : Type v} [topological_space α] [t2_space α] {f : β → α} {l : filter β} {a : α} {b : α} (hl : filter.ne_bot l) (ha : filter.tendsto f l (nhds a)) (hb : filter.tendsto f l (nhds b)) : a = b :=
eq_of_nhds_ne_bot (filter.ne_bot_of_le (le_inf ha hb))
/-!
### Properties of `Lim` and `lim`
In this section we use explicit `nonempty α` instances for `Lim` and `lim`. This way the lemmas
are useful without a `nonempty α` instance.
-/
theorem Lim_eq {α : Type u} [topological_space α] [t2_space α] {f : filter α} {a : α} [filter.ne_bot f] (h : f ≤ nhds a) : Lim f = a :=
tendsto_nhds_unique (le_nhds_Lim (Exists.intro a h)) h
theorem Lim_eq_iff {α : Type u} [topological_space α] [t2_space α] {f : filter α} [filter.ne_bot f] (h : ∃ (a : α), f ≤ nhds a) {a : α} : Lim f = a ↔ f ≤ nhds a :=
{ mp := fun (c : Lim f = a) => c ▸ le_nhds_Lim h, mpr := Lim_eq }
theorem ultrafilter.Lim_eq_iff_le_nhds {α : Type u} [topological_space α] [t2_space α] [compact_space α] {x : α} {F : ultrafilter α} : ultrafilter.Lim F = x ↔ ↑F ≤ nhds x :=
{ mp := fun (h : ultrafilter.Lim F = x) => h ▸ ultrafilter.le_nhds_Lim F, mpr := Lim_eq }
theorem is_open_iff_ultrafilter' {α : Type u} [topological_space α] [t2_space α] [compact_space α] (U : set α) : is_open U ↔ ∀ (F : ultrafilter α), ultrafilter.Lim F ∈ U → U ∈ ultrafilter.to_filter F := sorry
theorem filter.tendsto.lim_eq {α : Type u} {β : Type v} [topological_space α] [t2_space α] {a : α} {f : filter β} [filter.ne_bot f] {g : β → α} (h : filter.tendsto g f (nhds a)) : lim f g = a :=
Lim_eq h
theorem filter.lim_eq_iff {α : Type u} {β : Type v} [topological_space α] [t2_space α] {f : filter β} [filter.ne_bot f] {g : β → α} (h : ∃ (a : α), filter.tendsto g f (nhds a)) {a : α} : lim f g = a ↔ filter.tendsto g f (nhds a) :=
{ mp := fun (c : lim f g = a) => c ▸ tendsto_nhds_lim h, mpr := filter.tendsto.lim_eq }
theorem continuous.lim_eq {α : Type u} {β : Type v} [topological_space α] [t2_space α] [topological_space β] {f : β → α} (h : continuous f) (a : β) : lim (nhds a) f = f a :=
filter.tendsto.lim_eq (continuous.tendsto h a)
@[simp] theorem Lim_nhds {α : Type u} [topological_space α] [t2_space α] (a : α) : Lim (nhds a) = a :=
Lim_eq (le_refl (nhds a))
@[simp] theorem lim_nhds_id {α : Type u} [topological_space α] [t2_space α] (a : α) : lim (nhds a) id = a :=
Lim_nhds a
@[simp] theorem Lim_nhds_within {α : Type u} [topological_space α] [t2_space α] {a : α} {s : set α} (h : a ∈ closure s) : Lim (nhds_within a s) = a :=
Lim_eq inf_le_left
@[simp] theorem lim_nhds_within_id {α : Type u} [topological_space α] [t2_space α] {a : α} {s : set α} (h : a ∈ closure s) : lim (nhds_within a s) id = a :=
Lim_nhds_within h
/-!
### Instances of `t2_space` typeclass
We use two lemmas to prove that various standard constructions generate Hausdorff spaces from
Hausdorff spaces:
* `separated_by_continuous` says that two points `x y : α` can be separated by open neighborhoods
provided that there exists a continuous map `f`: α → β` with a Hausdorff codomain such that
`f x ≠ f y`. We use this lemma to prove that topological spaces defined using `induced` are
Hausdorff spaces.
* `separated_by_open_embedding` says that for an open embedding `f : α → β` of a Hausdorff space
`α`, the images of two distinct points `x y : α`, `x ≠ y` can be separated by open neighborhoods.
We use this lemma to prove that topological spaces defined using `coinduced` are Hausdorff spaces.
-/
protected instance t2_space_discrete {α : Type u_1} [topological_space α] [discrete_topology α] : t2_space α := sorry
theorem separated_by_continuous {α : Type u_1} {β : Type u_2} [topological_space α] [topological_space β] [t2_space β] {f : α → β} (hf : continuous f) {x : α} {y : α} (h : f x ≠ f y) : ∃ (u : set α), ∃ (v : set α), is_open u ∧ is_open v ∧ x ∈ u ∧ y ∈ v ∧ u ∩ v = ∅ := sorry
theorem separated_by_open_embedding {α : Type u_1} {β : Type u_2} [topological_space α] [topological_space β] [t2_space α] {f : α → β} (hf : open_embedding f) {x : α} {y : α} (h : x ≠ y) : ∃ (u : set β), ∃ (v : set β), is_open u ∧ is_open v ∧ f x ∈ u ∧ f y ∈ v ∧ u ∩ v = ∅ := sorry
protected instance subtype.t2_space {α : Type u_1} {p : α → Prop} [t : topological_space α] [t2_space α] : t2_space (Subtype p) :=
t2_space.mk fun (x y : Subtype p) (h : x ≠ y) => separated_by_continuous continuous_subtype_val (mt subtype.eq h)
protected instance prod.t2_space {α : Type u_1} {β : Type u_2} [t₁ : topological_space α] [t2_space α] [t₂ : topological_space β] [t2_space β] : t2_space (α × β) :=
t2_space.mk fun (_x : α × β) => sorry
protected instance sum.t2_space {α : Type u_1} {β : Type u_2} [t₁ : topological_space α] [t2_space α] [t₂ : topological_space β] [t2_space β] : t2_space (α ⊕ β) := sorry
protected instance Pi.t2_space {α : Type u_1} {β : α → Type v} [t₂ : (a : α) → topological_space (β a)] [∀ (a : α), t2_space (β a)] : t2_space ((a : α) → β a) :=
t2_space.mk fun (x y : (a : α) → β a) (h : x ≠ y) => sorry
protected instance sigma.t2_space {ι : Type u_1} {α : ι → Type u_2} [(i : ι) → topological_space (α i)] [∀ (a : ι), t2_space (α a)] : t2_space (sigma fun (i : ι) => α i) := sorry
theorem is_closed_eq {α : Type u} {β : Type v} [topological_space α] [topological_space β] [t2_space α] {f : β → α} {g : β → α} (hf : continuous f) (hg : continuous g) : is_closed (set_of fun (x : β) => f x = g x) :=
iff.mp continuous_iff_is_closed (continuous.prod_mk hf hg) (set.diagonal α) is_closed_diagonal
/-- If two continuous maps are equal on `s`, then they are equal on the closure of `s`. -/
theorem set.eq_on.closure {α : Type u} {β : Type v} [topological_space α] [topological_space β] [t2_space α] {s : set β} {f : β → α} {g : β → α} (h : set.eq_on f g s) (hf : continuous f) (hg : continuous g) : set.eq_on f g (closure s) :=
closure_minimal h (is_closed_eq hf hg)
/-- If two continuous functions are equal on a dense set, then they are equal. -/
theorem continuous.ext_on {α : Type u} {β : Type v} [topological_space α] [topological_space β] [t2_space α] {s : set β} (hs : dense s) {f : β → α} {g : β → α} (hf : continuous f) (hg : continuous g) (h : set.eq_on f g s) : f = g :=
funext fun (x : β) => set.eq_on.closure h hf hg (hs x)
theorem diagonal_eq_range_diagonal_map {α : Type u_1} : (set_of fun (p : α × α) => prod.fst p = prod.snd p) = set.range fun (x : α) => (x, x) := sorry
theorem prod_subset_compl_diagonal_iff_disjoint {α : Type u_1} {s : set α} {t : set α} : set.prod s t ⊆ ((set_of fun (p : α × α) => prod.fst p = prod.snd p)ᶜ) ↔ s ∩ t = ∅ := sorry
theorem compact_compact_separated {α : Type u} [topological_space α] [t2_space α] {s : set α} {t : set α} (hs : is_compact s) (ht : is_compact t) (hst : s ∩ t = ∅) : ∃ (u : set α), ∃ (v : set α), is_open u ∧ is_open v ∧ s ⊆ u ∧ t ⊆ v ∧ u ∩ v = ∅ := sorry
/-- In a `t2_space`, every compact set is closed. -/
theorem is_compact.is_closed {α : Type u} [topological_space α] [t2_space α] {s : set α} (hs : is_compact s) : is_closed s := sorry
theorem is_compact.inter {α : Type u} [topological_space α] [t2_space α] {s : set α} {t : set α} (hs : is_compact s) (ht : is_compact t) : is_compact (s ∩ t) :=
is_compact.inter_right hs (is_compact.is_closed ht)
/-- If a compact set is covered by two open sets, then we can cover it by two compact subsets. -/
theorem is_compact.binary_compact_cover {α : Type u} [topological_space α] [t2_space α] {K : set α} {U : set α} {V : set α} (hK : is_compact K) (hU : is_open U) (hV : is_open V) (h2K : K ⊆ U ∪ V) : ∃ (K₁ : set α), ∃ (K₂ : set α), is_compact K₁ ∧ is_compact K₂ ∧ K₁ ⊆ U ∧ K₂ ⊆ V ∧ K = K₁ ∪ K₂ := sorry
/-- For every finite open cover `Uᵢ` of a compact set, there exists a compact cover `Kᵢ ⊆ Uᵢ`. -/
theorem is_compact.finite_compact_cover {α : Type u} [topological_space α] [t2_space α] {s : set α} (hs : is_compact s) {ι : Type u_1} (t : finset ι) (U : ι → set α) (hU : ∀ (i : ι), i ∈ t → is_open (U i)) (hsC : s ⊆ set.Union fun (i : ι) => set.Union fun (H : i ∈ t) => U i) : ∃ (K : ι → set α),
(∀ (i : ι), is_compact (K i)) ∧ (∀ (i : ι), K i ⊆ U i) ∧ s = set.Union fun (i : ι) => set.Union fun (H : i ∈ t) => K i := sorry
theorem locally_compact_of_compact_nhds {α : Type u} [topological_space α] [t2_space α] (h : ∀ (x : α), ∃ (s : set α), s ∈ nhds x ∧ is_compact s) : locally_compact_space α := sorry
protected instance locally_compact_of_compact {α : Type u} [topological_space α] [t2_space α] [compact_space α] : locally_compact_space α :=
locally_compact_of_compact_nhds
fun (x : α) => Exists.intro set.univ { left := mem_nhds_sets is_open_univ trivial, right := compact_univ }
/-- In a locally compact T₂ space, every point has an open neighborhood with compact closure -/
theorem exists_open_with_compact_closure {α : Type u} [topological_space α] [locally_compact_space α] [t2_space α] (x : α) : ∃ (U : set α), is_open U ∧ x ∈ U ∧ is_compact (closure U) := sorry
/-- In a locally compact T₂ space, every compact set is contained in the interior of a compact
set. -/
theorem exists_compact_superset {α : Type u} [topological_space α] [locally_compact_space α] [t2_space α] {K : set α} (hK : is_compact K) : ∃ (K' : set α), is_compact K' ∧ K ⊆ interior K' := sorry
/-- A T₃ space, also known as a regular space (although this condition sometimes
omits T₂), is one in which for every closed `C` and `x ∉ C`, there exist
disjoint open sets containing `x` and `C` respectively. -/
class regular_space (α : Type u) [topological_space α]
extends t1_space α
where
regular : ∀ {s : set α} {a : α}, is_closed s → ¬a ∈ s → ∃ (t : set α), is_open t ∧ s ⊆ t ∧ nhds_within a t = ⊥
theorem nhds_is_closed {α : Type u} [topological_space α] [regular_space α] {a : α} {s : set α} (h : s ∈ nhds a) : ∃ (t : set α), ∃ (H : t ∈ nhds a), t ⊆ s ∧ is_closed t := sorry
theorem closed_nhds_basis {α : Type u} [topological_space α] [regular_space α] (a : α) : filter.has_basis (nhds a) (fun (s : set α) => s ∈ nhds a ∧ is_closed s) id := sorry
protected instance subtype.regular_space {α : Type u} [topological_space α] [regular_space α] {p : α → Prop} : regular_space (Subtype p) := sorry
protected instance regular_space.t2_space (α : Type u) [topological_space α] [regular_space α] : t2_space α :=
t2_space.mk fun (x y : α) (hxy : x ≠ y) => sorry
theorem disjoint_nested_nhds {α : Type u} [topological_space α] [regular_space α] {x : α} {y : α} (h : x ≠ y) : ∃ (U₁ : set α),
∃ (V₁ : set α),
∃ (H : U₁ ∈ nhds x),
∃ (H : V₁ ∈ nhds x),
∃ (U₂ : set α),
∃ (V₂ : set α),
∃ (H : U₂ ∈ nhds y),
∃ (H : V₂ ∈ nhds y),
is_closed V₁ ∧ is_closed V₂ ∧ is_open U₁ ∧ is_open U₂ ∧ V₁ ⊆ U₁ ∧ V₂ ⊆ U₂ ∧ U₁ ∩ U₂ = ∅ := sorry
/-- A T₄ space, also known as a normal space (although this condition sometimes
omits T₂), is one in which for every pair of disjoint closed sets `C` and `D`,
there exist disjoint open sets containing `C` and `D` respectively. -/
class normal_space (α : Type u) [topological_space α]
extends t1_space α
where
normal : ∀ (s t : set α),
is_closed s →
is_closed t → disjoint s t → ∃ (u : set α), ∃ (v : set α), is_open u ∧ is_open v ∧ s ⊆ u ∧ t ⊆ v ∧ disjoint u v
theorem normal_separation {α : Type u} [topological_space α] [normal_space α] (s : set α) (t : set α) (H1 : is_closed s) (H2 : is_closed t) (H3 : disjoint s t) : ∃ (u : set α), ∃ (v : set α), is_open u ∧ is_open v ∧ s ⊆ u ∧ t ⊆ v ∧ disjoint u v :=
normal_space.normal s t H1 H2 H3
protected instance normal_space.regular_space {α : Type u} [topological_space α] [normal_space α] : regular_space α :=
regular_space.mk fun (s : set α) (x : α) (hs : is_closed s) (hxs : ¬x ∈ s) => sorry
-- We can't make this an instance because it could cause an instance loop.
theorem normal_of_compact_t2 {α : Type u} [topological_space α] [compact_space α] [t2_space α] : normal_space α := sorry
/-- In a compact t2 space, the connected component of a point equals the intersection of all
its clopen neighbourhoods. -/
theorem connected_component_eq_Inter_clopen {α : Type u} [topological_space α] [t2_space α] [compact_space α] {x : α} : connected_component x = set.Inter fun (Z : Subtype fun (Z : set α) => is_clopen Z ∧ x ∈ Z) => ↑Z := sorry
|
a95f90db55c5d0e867a99d617a4fbe8cd1870117
|
4fa161becb8ce7378a709f5992a594764699e268
|
/src/linear_algebra/nonsingular_inverse.lean
|
0f72630729ff29e7f8b55e3a80eb7afad1fa6f7b
|
[
"Apache-2.0"
] |
permissive
|
laughinggas/mathlib
|
e4aa4565ae34e46e834434284cb26bd9d67bc373
|
86dcd5cda7a5017c8b3c8876c89a510a19d49aad
|
refs/heads/master
| 1,669,496,232,688
| 1,592,831,995,000
| 1,592,831,995,000
| 274,155,979
| 0
| 0
|
Apache-2.0
| 1,592,835,190,000
| 1,592,835,189,000
| null |
UTF-8
|
Lean
| false
| false
| 15,486
|
lean
|
/-
Copyright (c) 2019 Tim Baanen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Tim Baanen.
-/
import algebra.associated
import linear_algebra.determinant
import tactic.linarith
import tactic.ring_exp
/-!
# Nonsingular inverses
In this file, we define an inverse for square matrices of invertible
determinant. For matrices that are not square or not of full rank, there is a
more general notion of pseudoinverses. Unfortunately, the definition of
pseudoinverses is typically in terms of inverses of nonsingular matrices, so we
need to define those first. The file also doesn't define a `has_inv` instance
for `matrix` so that can be used for the pseudoinverse instead.
The definition of inverse used in this file is the adjugate divided by the determinant.
The adjugate is calculated with Cramer's rule, which we introduce first.
The vectors returned by Cramer's rule are given by the linear map `cramer`,
which sends a matrix `A` and vector `b` to the vector consisting of the
determinant of replacing the `i`th column of `A` with `b` at index `i`
(written as `(A.update_column i b).det`).
Using Cramer's rule, we can compute for each matrix `A` the matrix `adjugate A`.
The entries of the adjugate are the determinants of each minor of `A`.
Instead of defining a minor to be `A` with column `i` and row `j` deleted, we
replace the `i`th column of `A` with the `j`th basis vector; this has the same
determinant as the minor but more importantly equals Cramer's rule applied
to `A` and the `j`th basis vector, simplifying the subsequent proofs.
We prove the adjugate behaves like `det A • A⁻¹`. Finally, we show that dividing
the adjugate by `det A` (if possible), giving a matrix `nonsing_inv A`, will
result in a multiplicative inverse to `A`.
## References
* https://en.wikipedia.org/wiki/Cramer's_rule#Finding_inverse_matrix
## Tags
matrix inverse, cramer, cramer's rule, adjugate
-/
namespace matrix
universes u v
variables {n : Type u} [fintype n] [decidable_eq n] {α : Type v}
open_locale matrix big_operators
open equiv equiv.perm finset
section update
/-- Update, i.e. replace the `i`th column of matrix `A` with the values in `b`. -/
def update_column (A : matrix n n α) (i : n) (b : n → α) : matrix n n α :=
function.update A i b
/-- Update, i.e. replace the `i`th row of matrix `A` with the values in `b`. -/
def update_row (A : matrix n n α) (j : n) (b : n → α) : matrix n n α :=
λ i, function.update (A i) j (b i)
variables {A : matrix n n α} {i j : n} {b : n → α}
@[simp] lemma update_column_self : update_column A i b i = b := function.update_same i b A
@[simp] lemma update_row_self : update_row A j b i j = b i := function.update_same j (b i) (A i)
@[simp] lemma update_column_ne {i' : n} (i_ne : i' ≠ i) : update_column A i b i' = A i' :=
function.update_noteq i_ne b A
@[simp] lemma update_row_ne {j' : n} (j_ne : j' ≠ j) : update_row A j b i j' = A i j' :=
function.update_noteq j_ne (b i) (A i)
lemma update_column_val {i' : n} : update_column A i b i' j = if i' = i then b j else A i' j :=
begin
by_cases i' = i,
{ rw [h, update_column_self, if_pos rfl] },
{ rw [update_column_ne h, if_neg h] }
end
lemma update_row_val {j' : n} : update_row A j b i j' = if j' = j then b i else A i j' :=
begin
by_cases j' = j,
{ rw [h, update_row_self, if_pos rfl] },
{ rw [update_row_ne h, if_neg h] }
end
lemma update_column_transpose : update_column Aᵀ i b = (update_row A i b)ᵀ :=
begin
ext i' j,
rw [transpose_val, update_column_val, update_row_val],
refl
end
end update
section cramer
/-!
### `cramer` section
Introduce the linear map `cramer` with values defined by `cramer_map`.
After defining `cramer_map` and showing it is linear,
we will restrict our proofs to using `cramer`.
-/
variables [comm_ring α] (A : matrix n n α) (b : n → α)
/--
`cramer_map A b i` is the determinant of the matrix `A` with column `i` replaced with `b`,
and thus `cramer_map A b` is the vector output by Cramer's rule on `A` and `b`.
If `A ⬝ x = b` has a unique solution in `x`, `cramer_map` sends a square matrix `A`
and vector `b` to the vector `x` such that `A ⬝ x = b`.
Otherwise, the outcome of `cramer_map` is well-defined but not necessarily useful.
-/
def cramer_map (i : n) : α := (A.update_column i b).det
lemma cramer_map_is_linear (i : n) : is_linear_map α (λ b, cramer_map A b i) :=
begin
have : Π {f : n → n} {i : n} (x : n → α),
(∏ i' : n, (update_column A i x)ᵀ (f i') i')
= (∏ i' : n, if i' = i then x (f i') else A i' (f i')),
{ intros, congr, ext i', rw [transpose_val, update_column_val] },
split,
{ intros x y,
repeat { rw [cramer_map, ←det_transpose, det] },
rw [←sum_add_distrib],
congr, ext σ,
rw [←mul_add ↑↑(sign σ)],
congr,
repeat { erw [this, finset.prod_ite] },
erw [finset.filter_eq', if_pos (mem_univ i), prod_singleton, prod_singleton,
prod_singleton, ←add_mul],
refl },
{ intros c x,
repeat { rw [cramer_map, ←det_transpose, det] },
rw [smul_eq_mul, mul_sum],
congr, ext σ,
rw [←mul_assoc, mul_comm c, mul_assoc], congr,
repeat { erw [this, finset.prod_ite] },
erw [finset.filter_eq', if_pos (mem_univ i),
prod_singleton, prod_singleton, mul_assoc], }
end
lemma cramer_is_linear : is_linear_map α (cramer_map A) :=
begin
split; intros; ext i,
{ apply (cramer_map_is_linear A i).1 },
{ apply (cramer_map_is_linear A i).2 }
end
/-- The linear map of vectors associated to Cramer's rule.
To help the elaborator, we need to make the type `α` an explicit argument to
`cramer`. Otherwise, the coercion `⇑(cramer A) : (n → α) → (n → α)` gives an
error because it fails to infer the type (even though `α` can be inferred from
`A : matrix n n α`).
-/
def cramer (α : Type v) [comm_ring α] (A : matrix n n α) : (n → α) →ₗ[α] (n → α) :=
is_linear_map.mk' (cramer_map A) (cramer_is_linear A)
lemma cramer_apply (i : n) : cramer α A b i = (A.update_column i b).det := rfl
/-- Applying Cramer's rule to a column of the matrix gives a scaled basis vector. -/
lemma cramer_column_self (i : n) :
cramer α A (A i) = (λ j, if i = j then A.det else 0) :=
begin
ext j,
rw cramer_apply,
by_cases i = j,
{ -- i = j: this entry should be `A.det`
rw [if_pos h, ←h],
congr, ext i',
by_cases h : i' = i, { rw [h, update_column_self] }, { rw [update_column_ne h]} },
{ -- i ≠ j: this entry should be 0
rw [if_neg h],
apply det_zero_of_column_eq h,
rw [update_column_self, update_column_ne],
apply h }
end
/-- Use linearity of `cramer` to take it out of a summation. -/
lemma sum_cramer {β} (s : finset β) (f : β → n → α) :
∑ x in s, cramer α A (f x) = cramer α A (∑ x in s, f x) :=
(linear_map.map_sum (cramer α A)).symm
/-- Use linearity of `cramer` and vector evaluation to take `cramer A _ i` out of a summation. -/
lemma sum_cramer_apply {β} (s : finset β) (f : n → β → α) (i : n) :
∑ x in s, cramer α A (λ j, f j x) i = cramer α A (λ (j : n), ∑ x in s, f j x) i :=
calc ∑ x in s, cramer α A (λ j, f j x) i
= (∑ x in s, cramer α A (λ j, f j x)) i : (pi.finset_sum_apply i s _).symm
... = cramer α A (λ (j : n), ∑ x in s, f j x) i :
by { rw [sum_cramer, cramer_apply], congr, ext j, apply pi.finset_sum_apply }
end cramer
section adjugate
/-!
### `adjugate` section
Define the `adjugate` matrix and a few equations.
These will hold for any matrix over a commutative ring,
while the `inv` section is specifically for invertible matrices.
-/
variable [comm_ring α]
/-- The adjugate matrix is the transpose of the cofactor matrix.
Typically, the cofactor matrix is defined by taking the determinant of minors,
i.e. the matrix with a row and column removed.
However, the proof of `mul_adjugate` becomes a lot easier if we define the
minor as replacing a column with a basis vector, since it allows us to use
facts about the `cramer` map.
-/
def adjugate (A : matrix n n α) : matrix n n α := λ i, cramer α A (λ j, if i = j then 1 else 0)
lemma adjugate_def (A : matrix n n α) :
adjugate A = λ i, cramer α A (λ j, if i = j then 1 else 0) := rfl
lemma adjugate_val (A : matrix n n α) (i j : n) :
adjugate A i j = (A.update_column j (λ j, if i = j then 1 else 0)).det := rfl
lemma adjugate_transpose (A : matrix n n α) : (adjugate A)ᵀ = adjugate (Aᵀ) :=
begin
ext i j,
rw [transpose_val, adjugate_val, adjugate_val, update_column_transpose, det_transpose],
apply finset.sum_congr rfl,
intros σ _,
congr' 1,
by_cases i = σ j,
{ -- Everything except `(i , j)` (= `(σ j , j)`) is given by A, and the rest is a single `1`.
congr; ext j',
have := (@equiv.injective _ _ σ j j' : σ j = σ j' → j = j'),
rw [update_column_val, update_row_val],
finish },
{ -- Otherwise, we need to show that there is a `0` somewhere in the product.
have : (∏ j' : n, update_row A j (λ (i' : n), ite (i = i') 1 0) (σ j') j') = 0,
{ apply prod_eq_zero (mem_univ j),
rw [update_row_self],
exact if_neg h },
rw this,
apply prod_eq_zero (mem_univ (σ⁻¹ i)),
erw [apply_symm_apply σ i, update_column_self],
apply if_neg,
intro h',
exact h ((symm_apply_eq σ).mp h'.symm) }
end
lemma mul_adjugate_val (A : matrix n n α) (i j k) :
A i k * adjugate A k j = cramer α A (λ j, if k = j then A i k else 0) j :=
begin
erw [←smul_eq_mul, ←pi.smul_apply, ←linear_map.map_smul],
congr, ext,
rw [pi.smul_apply, smul_eq_mul, mul_boole],
end
lemma mul_adjugate (A : matrix n n α) : A ⬝ adjugate A = A.det • 1 :=
begin
ext i j,
rw [mul_val, smul_val, one_val, mul_boole],
calc
∑ k : n, A i k * adjugate A k j
= ∑ k : n, cramer α A (λ j, if k = j then A i k else 0) j
: by {congr, ext k, apply mul_adjugate_val A i j k}
... = cramer α A (λ j, ∑ k : n, if k = j then A i k else 0) j
: sum_cramer_apply A univ (λ (j k : n), if k = j then A i k else 0) j
... = cramer α A (A i) j : by { rw [cramer_apply], congr, ext,
rw [sum_ite_eq' univ x (A i), if_pos (mem_univ _)] }
... = if i = j then det A else 0 : by rw [cramer_column_self]
end
lemma adjugate_mul (A : matrix n n α) : adjugate A ⬝ A = A.det • 1 :=
calc adjugate A ⬝ A = (Aᵀ ⬝ (adjugate Aᵀ))ᵀ :
by rw [←adjugate_transpose, ←transpose_mul, transpose_transpose]
... = A.det • 1 : by rw [mul_adjugate (Aᵀ), det_transpose, transpose_smul, transpose_one]
/-- `det_adjugate_of_cancel` is an auxiliary lemma for computing `(adjugate A).det`,
used in `det_adjugate_eq_one` and `det_adjugate_of_is_unit`.
The formula for the determinant of the adjugate of an `n` by `n` matrix `A`
is in general `(adjugate A).det = A.det ^ (n - 1)`, but the proof differs in several cases.
This lemma `det_adjugate_of_cancel` covers the case that `det A` cancels
on the left of the equation `A.det * b = A.det ^ n`.
-/
lemma det_adjugate_of_cancel {A : matrix n n α}
(h : ∀ b, A.det * b = A.det ^ fintype.card n → b = A.det ^ (fintype.card n - 1)) :
(adjugate A).det = A.det ^ (fintype.card n - 1) :=
h (adjugate A).det (calc A.det * (adjugate A).det = (A ⬝ adjugate A).det : (det_mul _ _).symm
... = A.det ^ fintype.card n : by simp [mul_adjugate])
lemma adjugate_eq_one_of_card_eq_one {A : matrix n n α} (h : fintype.card n = 1) : adjugate A = 1 :=
begin
ext i j,
have univ_eq_i := univ_eq_singleton_of_card_one i h,
have univ_eq_j := univ_eq_singleton_of_card_one j h,
have i_eq_j : i = j := singleton_inj.mp (by rw [←univ_eq_i, univ_eq_j]),
have perm_eq : (univ : finset (perm n)) = {1} :=
univ_eq_singleton_of_card_one (1 : perm n) (by simp [card_univ, fintype.card_perm, h]),
simp [adjugate_val, det, univ_eq_i, perm_eq, i_eq_j]
end
@[simp] lemma adjugate_zero (h : 1 < fintype.card n) : adjugate (0 : matrix n n α) = 0 :=
begin
ext i j,
obtain ⟨j', hj'⟩ : ∃ j', j' ≠ j := fintype.exists_ne_of_one_lt_card h j,
apply det_eq_zero_of_column_eq_zero j',
intro j'',
simp [update_column_ne hj']
end
lemma det_adjugate_eq_one {A : matrix n n α} (h : A.det = 1) : (adjugate A).det = 1 :=
calc (adjugate A).det
= A.det ^ (fintype.card n - 1) : det_adjugate_of_cancel (λ b hb, by simpa [h] using hb)
... = 1 : by rw [h, one_pow]
/-- `det_adjugate_of_is_unit` gives the formula for `(adjugate A).det` if `A.det` has an inverse.
The formula for the determinant of the adjugate of an `n` by `n` matrix `A`
is in general `(adjugate A).det = A.det ^ (n - 1)`, but the proof differs in several cases.
This lemma `det_adjugate_of_is_unit` covers the case that `det A` has an inverse.
-/
lemma det_adjugate_of_is_unit {A : matrix n n α} (h : is_unit A.det) :
(adjugate A).det = A.det ^ (fintype.card n - 1) :=
begin
rcases is_unit_iff_exists_inv'.mp h with ⟨a, ha⟩,
by_cases card_lt_zero : fintype.card n ≤ 0,
{ have h : fintype.card n = 0 := by linarith,
simp [det_eq_one_of_card_eq_zero h] },
have zero_lt_card : 0 < fintype.card n := by linarith,
have n_nonempty : nonempty n := fintype.card_pos_iff.mp zero_lt_card,
by_cases card_lt_one : fintype.card n ≤ 1,
{ have h : fintype.card n = 1 := by linarith,
simp [h, adjugate_eq_one_of_card_eq_one h] },
have one_lt_card : 1 < fintype.card n := by linarith,
have zero_lt_card_sub_one : 0 < fintype.card n - 1 :=
(nat.sub_lt_sub_right_iff (refl 1)).mpr one_lt_card,
apply det_adjugate_of_cancel,
intros b hb,
calc b = a * (det A ^ (fintype.card n - 1 + 1)) :
by rw [←one_mul b, ←ha, mul_assoc, hb, nat.sub_add_cancel zero_lt_card]
... = a * det A * det A ^ (fintype.card n - 1) : by ring_exp
... = det A ^ (fintype.card n - 1) : by rw [ha, one_mul]
end
end adjugate
section inv
/-!
### `inv` section
Defines the matrix `nonsing_inv A` and proves it is the inverse matrix
of a square matrix `A` as long as `det A` has a multiplicative inverse.
-/
variables [comm_ring α] [has_inv α]
/-- The inverse of a nonsingular matrix.
This is not the most general possible definition, so we don't instantiate `has_inv` (yet).
-/
def nonsing_inv (A : matrix n n α) : matrix n n α := (A.det)⁻¹ • adjugate A
lemma nonsing_inv_val (A : matrix n n α) (i j : n) :
A.nonsing_inv i j = (A.det)⁻¹ * adjugate A i j := rfl
lemma transpose_nonsing_inv (A : matrix n n α) : (A.nonsing_inv)ᵀ = (Aᵀ).nonsing_inv :=
by {ext, simp [transpose_val, nonsing_inv_val, det_transpose, (adjugate_transpose A).symm]}
/-- The `nonsing_inv` of `A` is a right inverse. -/
theorem mul_nonsing_inv (A : matrix n n α) (inv_mul_cancel : A.det⁻¹ * A.det = 1) :
A ⬝ nonsing_inv A = 1 :=
by erw [mul_smul, mul_adjugate, smul_smul, inv_mul_cancel, one_smul]
/-- The `nonsing_inv` of `A` is a left inverse. -/
theorem nonsing_inv_mul (A : matrix n n α) (inv_mul_cancel : A.det⁻¹ * A.det = 1) :
nonsing_inv A ⬝ A = 1 :=
have inv_mul_cancel' : (det Aᵀ)⁻¹ * det Aᵀ = 1 := by {rw det_transpose, assumption},
calc nonsing_inv A ⬝ A
= (Aᵀ ⬝ nonsing_inv (Aᵀ))ᵀ : by rw [transpose_mul, transpose_nonsing_inv, transpose_transpose]
... = 1ᵀ : by rw [mul_nonsing_inv Aᵀ inv_mul_cancel']
... = 1 : transpose_one
end inv
end matrix
|
e3f77bf62e5f65dae1335b3e57c67f5ed4535616
|
7565ffb53cc64430691ce89265da0f944ee43051
|
/hott/init/funext.hlean
|
64e7b0d3555a7db5b1a455ca4dfbac141c1fb373
|
[
"Apache-2.0"
] |
permissive
|
EgbertRijke/lean2
|
cacddba3d150f8b38688e044960a208bf851f90e
|
519dcee739fbca5a4ab77d66db7652097b4604cd
|
refs/heads/master
| 1,606,936,954,854
| 1,498,836,083,000
| 1,498,910,882,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 12,041
|
hlean
|
/-
Copyright (c) 2014 Jakob von Raumer. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jakob von Raumer, Floris van Doorn
Ported from Coq HoTT
-/
prelude
import .trunc .equiv .ua
open eq is_trunc sigma function is_equiv equiv prod unit prod.ops lift
/-
We now prove that funext follows from a couple of weaker-looking forms
of function extensionality.
This proof is originally due to Voevodsky; it has since been simplified
by Peter Lumsdaine and Michael Shulman.
-/
definition funext.{l k} :=
Π ⦃A : Type.{l}⦄ {P : A → Type.{k}} (f g : Π x, P x), is_equiv (@apd10 A P f g)
-- Naive funext is the simple assertion that pointwise equal functions are equal.
definition naive_funext :=
Π ⦃A : Type⦄ {P : A → Type} (f g : Πx, P x), (f ~ g) → f = g
-- Weak funext says that a product of contractible types is contractible.
definition weak_funext :=
Π ⦃A : Type⦄ (P : A → Type) [H: Πx, is_contr (P x)], is_contr (Πx, P x)
definition weak_funext_of_naive_funext : naive_funext → weak_funext :=
(λ nf A P (Pc : Πx, is_contr (P x)),
let c := λx, center (P x) in
is_contr.mk c (λ f,
have eq' : (λx, center (P x)) ~ f,
from (λx, center_eq (f x)),
have eq : (λx, center (P x)) = f,
from nf A P (λx, center (P x)) f eq',
eq
)
)
/-
The less obvious direction is that weak_funext implies funext
(and hence all three are logically equivalent). The point is that under weak
funext, the space of "pointwise homotopies" has the same universal property as
the space of paths.
-/
section
universe variables l k
parameters [wf : weak_funext.{l k}] {A : Type.{l}} {B : A → Type.{k}} (f : Π x, B x)
definition is_contr_sigma_homotopy : is_contr (Σ (g : Π x, B x), f ~ g) :=
is_contr.mk (sigma.mk f (homotopy.refl f))
(λ dp, sigma.rec_on dp
(λ (g : Π x, B x) (h : f ~ g),
let r := λ (k : Π x, Σ y, f x = y),
@sigma.mk _ (λg, f ~ g)
(λx, pr1 (k x)) (λx, pr2 (k x)) in
let s := λ g h x, @sigma.mk _ (λy, f x = y) (g x) (h x) in
have t1 : Πx, is_contr (Σ y, f x = y),
from (λx, !is_contr_sigma_eq),
have t2 : is_contr (Πx, Σ y, f x = y),
from !wf,
have t3 : (λ x, @sigma.mk _ (λ y, f x = y) (f x) idp) = s g h,
from @eq_of_is_contr (Π x, Σ y, f x = y) t2 _ _,
have t4 : r (λ x, sigma.mk (f x) idp) = r (s g h),
from ap r t3,
have endt : sigma.mk f (homotopy.refl f) = sigma.mk g h,
from t4,
endt
)
)
local attribute is_contr_sigma_homotopy [instance]
parameters (Q : Π g (h : f ~ g), Type) (d : Q f (homotopy.refl f))
definition homotopy_ind (g : Πx, B x) (h : f ~ g) : Q g h :=
@transport _ (λ gh, Q (pr1 gh) (pr2 gh)) (sigma.mk f (homotopy.refl f)) (sigma.mk g h)
(@eq_of_is_contr _ is_contr_sigma_homotopy _ _) d
local attribute weak_funext [reducible]
local attribute homotopy_ind [reducible]
definition homotopy_ind_comp : homotopy_ind f (homotopy.refl f) = d :=
(@prop_eq_of_is_contr _ _ _ _ !eq_of_is_contr idp)⁻¹ ▸ idp
end
/- Now the proof is fairly easy; we can just use the same induction principle on both sides. -/
section
universe variables l k
local attribute weak_funext [reducible]
theorem funext_of_weak_funext (wf : weak_funext.{l k}) : funext.{l k} :=
λ A B f g,
let eq_to_f := (λ g' x, f = g') in
let sim2path := homotopy_ind f eq_to_f idp in
have t1 : sim2path f (homotopy.refl f) = idp,
proof homotopy_ind_comp f eq_to_f idp qed,
have t2 : apd10 (sim2path f (homotopy.refl f)) = (homotopy.refl f),
proof ap apd10 t1 qed,
have left_inv : apd10 ∘ (sim2path g) ~ id,
proof (homotopy_ind f (λ g' x, apd10 (sim2path g' x) = x) t2) g qed,
have right_inv : (sim2path g) ∘ apd10 ~ id,
from (λ h, eq.rec_on h (homotopy_ind_comp f _ idp)),
is_equiv.adjointify apd10 (sim2path g) left_inv right_inv
definition funext_from_naive_funext : naive_funext → funext :=
compose funext_of_weak_funext weak_funext_of_naive_funext
end
section
universe variables l
private theorem ua_isequiv_postcompose {A B : Type.{l}} {C : Type}
{w : A → B} [H0 : is_equiv w] : is_equiv (@compose C A B w) :=
let w' := equiv.mk w H0 in
let eqinv : A = B := ((@is_equiv.inv _ _ _ (univalence A B)) w') in
let eq' := equiv_of_eq eqinv in
is_equiv.adjointify (@compose C A B w)
(@compose C B A (is_equiv.inv w))
(λ (x : C → B),
have eqretr : eq' = w',
from (@right_inv _ _ (@equiv_of_eq A B) (univalence A B) w'),
have invs_eq : (to_fun eq')⁻¹ = (to_fun w')⁻¹,
from inv_eq eq' w' eqretr,
have eqfin1 : Π(p : A = B), (to_fun (equiv_of_eq p)) ∘ ((to_fun (equiv_of_eq p))⁻¹ ∘ x) = x,
by intro p; induction p; reflexivity,
have eqfin : (to_fun eq') ∘ ((to_fun eq')⁻¹ ∘ x) = x,
from eqfin1 eqinv,
have eqfin' : (to_fun w') ∘ ((to_fun eq')⁻¹ ∘ x) = x,
from ap (λu, u ∘ _) eqretr⁻¹ ⬝ eqfin,
show (to_fun w') ∘ ((to_fun w')⁻¹ ∘ x) = x,
from ap (λu, _ ∘ (u ∘ _)) invs_eq⁻¹ ⬝ eqfin'
)
(λ (x : C → A),
have eqretr : eq' = w',
from (@right_inv _ _ (@equiv_of_eq A B) (univalence A B) w'),
have invs_eq : (to_fun eq')⁻¹ = (to_fun w')⁻¹,
from inv_eq eq' w' eqretr,
have eqfin1 : Π(p : A = B), (to_fun (equiv_of_eq p))⁻¹ ∘ ((to_fun (equiv_of_eq p)) ∘ x) = x,
by intro p; induction p; reflexivity,
have eqfin : (to_fun eq')⁻¹ ∘ ((to_fun eq') ∘ x) = x,
from eqfin1 eqinv,
have eqfin' : (to_fun eq')⁻¹ ∘ ((to_fun w') ∘ x) = x,
from ap (λu, _ ∘ (u ∘ _)) eqretr⁻¹ ⬝ eqfin,
show (to_fun w')⁻¹ ∘ ((to_fun w') ∘ x) = x,
from ap (λu, u ∘ _) invs_eq⁻¹ ⬝ eqfin'
)
-- We are ready to prove functional extensionality,
-- starting with the naive non-dependent version.
private definition diagonal [reducible] (B : Type) : Type
:= Σ xy : B × B, pr₁ xy = pr₂ xy
private definition isequiv_src_compose {A B : Type}
: @is_equiv (A → diagonal B)
(A → B)
(compose (pr₁ ∘ pr1)) :=
@ua_isequiv_postcompose _ _ _ (pr₁ ∘ pr1)
(is_equiv.adjointify (pr₁ ∘ pr1)
(λ x, sigma.mk (x , x) idp) (λx, idp)
(λ x, sigma.rec_on x
(λ xy, prod.rec_on xy
(λ b c p, eq.rec_on p idp))))
private definition isequiv_tgt_compose {A B : Type}
: is_equiv (compose (pr₂ ∘ pr1) : (A → diagonal B) → (A → B)) :=
begin
refine @ua_isequiv_postcompose _ _ _ (pr2 ∘ pr1) _,
fapply adjointify,
{ intro b, exact ⟨(b, b), idp⟩},
{ intro b, reflexivity},
{ intro a, induction a with q p, induction q, esimp at *, induction p, reflexivity}
end
theorem nondep_funext_from_ua {A : Type} {B : Type}
: Π {f g : A → B}, f ~ g → f = g :=
(λ (f g : A → B) (p : f ~ g),
let d := λ (x : A), @sigma.mk (B × B) (λ (xy : B × B), xy.1 = xy.2) (f x , f x) (eq.refl (f x, f x).1) in
let e := λ (x : A), @sigma.mk (B × B) (λ (xy : B × B), xy.1 = xy.2) (f x , g x) (p x) in
let precomp1 := compose (pr₁ ∘ sigma.pr1) in
have equiv1 : is_equiv precomp1,
from @isequiv_src_compose A B,
have equiv2 : Π (x y : A → diagonal B), is_equiv (ap precomp1),
from is_equiv.is_equiv_ap precomp1,
have H' : Π (x y : A → diagonal B), pr₁ ∘ pr1 ∘ x = pr₁ ∘ pr1 ∘ y → x = y,
from (λ x y, is_equiv.inv (ap precomp1)),
have eq2 : pr₁ ∘ pr1 ∘ d = pr₁ ∘ pr1 ∘ e,
from idp,
have eq0 : d = e,
from H' d e eq2,
have eq1 : (pr₂ ∘ pr1) ∘ d = (pr₂ ∘ pr1) ∘ e,
from ap _ eq0,
eq1
)
end
-- Now we use this to prove weak funext, which as we know
-- implies (with dependent eta) also the strong dependent funext.
theorem weak_funext_of_ua : weak_funext :=
(λ (A : Type) (P : A → Type) allcontr,
let U := (λ (x : A), lift unit) in
have pequiv : Π (x : A), P x ≃ unit,
from (λ x, @equiv_unit_of_is_contr (P x) (allcontr x)),
have psim : Π (x : A), P x = U x,
from (λ x, eq_of_equiv_lift (pequiv x)),
have p : P = U,
from @nondep_funext_from_ua A Type P U psim,
have tU' : is_contr (A → lift unit),
from is_contr.mk (λ x, up ⋆)
(λ f, nondep_funext_from_ua (λa, by induction (f a) with u;induction u;reflexivity)),
have tU : is_contr (Π x, U x),
from tU',
have tlast : is_contr (Πx, P x),
from p⁻¹ ▸ tU,
tlast)
-- we have proven function extensionality from the univalence axiom
definition funext_of_ua : funext :=
funext_of_weak_funext (@weak_funext_of_ua)
/-
We still take funext as an axiom, so that when you write "print axioms foo", you can see whether
it uses only function extensionality, and not also univalence.
-/
axiom function_extensionality : funext
variables {A : Type} {P : A → Type} {f g : Π x, P x}
namespace funext
theorem is_equiv_apdt [instance] (f g : Π x, P x) : is_equiv (@apd10 A P f g) :=
function_extensionality f g
end funext
open funext
namespace eq
definition eq_equiv_homotopy : (f = g) ≃ (f ~ g) :=
equiv.mk apd10 _
definition eq_of_homotopy [reducible] : f ~ g → f = g :=
(@apd10 A P f g)⁻¹
definition apd10_eq_of_homotopy (p : f ~ g) : apd10 (eq_of_homotopy p) = p :=
right_inv apd10 p
definition eq_of_homotopy_apd10 (p : f = g) : eq_of_homotopy (apd10 p) = p :=
left_inv apd10 p
definition eq_of_homotopy_idp (f : Π x, P x) : eq_of_homotopy (λx : A, idpath (f x)) = idpath f :=
is_equiv.left_inv apd10 idp
definition naive_funext_of_ua : naive_funext :=
λ A P f g h, eq_of_homotopy h
protected definition homotopy.rec_on [recursor] {Q : (f ~ g) → Type} (p : f ~ g)
(H : Π(q : f = g), Q (apd10 q)) : Q p :=
right_inv apd10 p ▸ H (eq_of_homotopy p)
protected definition homotopy.rec_on_idp [recursor] {Q : Π{g}, (f ~ g) → Type} {g : Π x, P x}
(p : f ~ g) (H : Q (homotopy.refl f)) : Q p :=
homotopy.rec_on p (λq, eq.rec_on q H)
protected definition homotopy.rec_on' {f f' : Πa, P a} {Q : (f ~ f') → (f = f') → Type}
(p : f ~ f') (H : Π(q : f = f'), Q (apd10 q) q) : Q p (eq_of_homotopy p) :=
begin
refine homotopy.rec_on p _,
intro q, exact (left_inv (apd10) q)⁻¹ ▸ H q
end
protected definition homotopy.rec_on_idp' {f : Πa, P a} {Q : Π{g}, (f ~ g) → (f = g) → Type}
{g : Πa, P a} (p : f ~ g) (H : Q (homotopy.refl f) idp) : Q p (eq_of_homotopy p) :=
begin
refine homotopy.rec_on' p _, intro q, induction q, exact H
end
protected definition homotopy.rec_on_idp_left {A : Type} {P : A → Type} {g : Πa, P a}
{Q : Πf, (f ~ g) → Type} {f : Π x, P x}
(p : f ~ g) (H : Q g (homotopy.refl g)) : Q f p :=
begin
induction p using homotopy.rec_on, induction q, exact H
end
definition eq_of_homotopy_inv {f g : Π x, P x} (H : f ~ g)
: eq_of_homotopy (λx, (H x)⁻¹) = (eq_of_homotopy H)⁻¹ :=
begin
apply homotopy.rec_on_idp H,
rewrite [+eq_of_homotopy_idp]
end
definition eq_of_homotopy_con {f g h : Π x, P x} (H1 : f ~ g) (H2 : g ~ h)
: eq_of_homotopy (λx, H1 x ⬝ H2 x) = eq_of_homotopy H1 ⬝ eq_of_homotopy H2 :=
begin
apply homotopy.rec_on_idp H1,
apply homotopy.rec_on_idp H2,
rewrite [+eq_of_homotopy_idp]
end
definition compose_eq_of_homotopy {A B C : Type} (g : B → C) {f f' : A → B} (H : f ~ f') :
ap (λf, g ∘ f) (eq_of_homotopy H) = eq_of_homotopy (hwhisker_left g H) :=
begin
refine homotopy.rec_on_idp' H _, exact !eq_of_homotopy_idp⁻¹
end
end eq
|
75fdec59ccb64ff9a20160688352f4b3f115f236
|
6b45072eb2b3db3ecaace2a7a0241ce81f815787
|
/pending/default.lean
|
b2dc55c88a8ba710a2f780e918d800cd8b435ef5
|
[] |
no_license
|
avigad/library_dev
|
27b47257382667b5eb7e6476c4f5b0d685dd3ddc
|
9d8ac7c7798ca550874e90fed585caad030bbfac
|
refs/heads/master
| 1,610,452,468,791
| 1,500,712,839,000
| 1,500,713,478,000
| 69,311,142
| 1
| 0
| null | 1,474,942,903,000
| 1,474,942,902,000
| null |
UTF-8
|
Lean
| false
| false
| 529
|
lean
|
/- Temporary space for definitions pending merges to the lean repository -/
open tactic
-- PR #1761
meta def transport_multiplicative_to_additive' (ls : list (name × name)) : command :=
let dict := rb_map.of_list ls in
ls.foldl (λ t ⟨src, tgt⟩, do
env ← get_env,
if (env.get tgt).to_bool = ff
then t >> transport_with_dict dict src tgt
else t)
skip
namespace nat
@[simp] theorem shiftl_zero (m) : shiftl m 0 = m := rfl
@[simp] theorem shiftl_succ (m n) : shiftl m (n + 1) = bit0 (shiftl m n) := rfl
end nat
|
25ab559afc2d1bd513d4769fa41224761e534d09
|
0942a74cc0b397d09bcd1059762fa076b1a5d308
|
/src/lean5.lean
|
15b5cff927a41af9f6e86bb4e96a7f8f44abd4bb
|
[
"Unlicense"
] |
permissive
|
sguzman/lean-examples
|
81df2010e204be1a9fde6ae18295e299e69cebca
|
c7428b2982d0468d0adb4453766a27e1550a72e8
|
refs/heads/master
| 1,668,438,655,034
| 1,594,156,605,000
| 1,594,156,605,000
| 277,626,098
| 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 304
|
lean
|
theorem and_swap (p q : Prop) : p ∧ q → q ∧ p :=
begin
assume h : (p ∧ q), -- assume p ∧ q is true
cases h, -- extract the individual propositions from the conjunction
split, -- split the goal conjunction into two cases: prove p and prove q separately
repeat { assumption }
end
|
2cb689a0b109b899388deb4e47986988fffe8aa6
|
8b0adce7bd4e8e06a22dbf65d3ef29169133227b
|
/inClassNotes/04_type_library/list.lean
|
6f967778e5848568c16bdb7025d3e3719c2502a7
|
[] |
no_license
|
parvahujauva/complogic-s21
|
5420bce9c456cd9dafcb4965719d2e45fb53437a
|
ba8d38bfb9000420e0051bc07195026b0e39a29c
|
refs/heads/master
| 1,677,682,663,658
| 1,613,232,309,000
| 1,613,232,309,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 1,242
|
lean
|
#print nat
namespace hidden
/-
The list α type represents the
set of lists of values of type
α. So "list nat", for example, is
the type of lists that contain
natural numbers. It explains that
such a list is either empty (nil)
or is constructed (cons) from a
single element of type α and a
smaller list (possibly empty) of
the same type.
This is an inductive definition
in which "larger" objects of a
given type are constructed from
smaller objects of the same type.
The induction starts with the
base case, nil, representing
the empty list of values of type
α. A list with one element, h
of type α, is represented as a
term (cons h nil). And given a
list (t : list α) a list that
comprises a new element (h : α)
followed by the "old" list, t,
represented as (cons h t). We
often refer to the element, h,
first in a list as the "head" of
the list, and the one-smaller
list, t, that follows as the
"tail".
We will interpret these terms
as mathematical sequences of values
represented by terms of type α.
Here's Lean's definition of the
list type builder. We'll use it
instead of our own version.
universe u
inductive list (α : Type u) : Type u
| nil : list
| cons : α → list → list
-/
#print list
end hidden
|
86f1a659aac96d73bc781789f83401d1a694f056
|
8cae430f0a71442d02dbb1cbb14073b31048e4b0
|
/src/data/finset/sym.lean
|
9b6246c51e858b8a4360e8192603b6068635dac8
|
[
"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
| 7,221
|
lean
|
/-
Copyright (c) 2021 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import data.finset.lattice
import data.fintype.prod
import data.fintype.vector
import data.sym.sym2
/-!
# Symmetric powers of a finset
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
This file defines the symmetric powers of a finset as `finset (sym α n)` and `finset (sym2 α)`.
## Main declarations
* `finset.sym`: The symmetric power of a finset. `s.sym n` is all the multisets of cardinality `n`
whose elements are in `s`.
* `finset.sym2`: The symmetric square of a finset. `s.sym2` is all the pairs whose elements are in
`s`.
## TODO
`finset.sym` forms a Galois connection between `finset α` and `finset (sym α n)`. Similar for
`finset.sym2`.
-/
namespace finset
variables {α : Type*} [decidable_eq α] {s t : finset α} {a b : α}
lemma is_diag_mk_of_mem_diag {a : α × α} (h : a ∈ s.diag) : sym2.is_diag ⟦a⟧ :=
(sym2.is_diag_iff_proj_eq _).2 (mem_diag.1 h).2
lemma not_is_diag_mk_of_mem_off_diag {a : α × α} (h : a ∈ s.off_diag) : ¬ sym2.is_diag ⟦a⟧ :=
by { rw sym2.is_diag_iff_proj_eq, exact (mem_off_diag.1 h).2.2 }
section sym2
variables {m : sym2 α}
/-- Lifts a finset to `sym2 α`. `s.sym2` is the finset of all pairs with elements in `s`. -/
protected def sym2 (s : finset α) : finset (sym2 α) := (s ×ˢ s).image quotient.mk
@[simp] lemma mem_sym2_iff : m ∈ s.sym2 ↔ ∀ a ∈ m, a ∈ s :=
begin
refine mem_image.trans
⟨_, λ h, ⟨m.out, mem_product.2 ⟨h _ m.out_fst_mem, h _ m.out_snd_mem⟩, m.out_eq⟩⟩,
rintro ⟨⟨a, b⟩, h, rfl⟩,
rw sym2.ball,
rwa mem_product at h,
end
lemma mk_mem_sym2_iff : ⟦(a, b)⟧ ∈ s.sym2 ↔ a ∈ s ∧ b ∈ s := by rw [mem_sym2_iff, sym2.ball]
@[simp] lemma sym2_empty : (∅ : finset α).sym2 = ∅ := rfl
@[simp] lemma sym2_eq_empty : s.sym2 = ∅ ↔ s = ∅ :=
by rw [finset.sym2, image_eq_empty, product_eq_empty, or_self]
@[simp] lemma sym2_nonempty : s.sym2.nonempty ↔ s.nonempty :=
by rw [finset.sym2, nonempty.image_iff, nonempty_product, and_self]
alias sym2_nonempty ↔ _ nonempty.sym2
attribute [protected] nonempty.sym2
@[simp] lemma sym2_univ [fintype α] : (univ : finset α).sym2 = univ := rfl
@[simp] lemma sym2_singleton (a : α) : ({a} : finset α).sym2 = {sym2.diag a} :=
by rw [finset.sym2, singleton_product_singleton, image_singleton, sym2.diag]
@[simp] lemma diag_mem_sym2_iff : sym2.diag a ∈ s.sym2 ↔ a ∈ s := mk_mem_sym2_iff.trans $ and_self _
@[simp] lemma sym2_mono (h : s ⊆ t) : s.sym2 ⊆ t.sym2 :=
λ m he, mem_sym2_iff.2 $ λ a ha, h $ mem_sym2_iff.1 he _ ha
lemma image_diag_union_image_off_diag :
s.diag.image quotient.mk ∪ s.off_diag.image quotient.mk = s.sym2 :=
by { rw [←image_union, diag_union_off_diag], refl }
end sym2
section sym
variables {n : ℕ} {m : sym α n}
/-- Lifts a finset to `sym α n`. `s.sym n` is the finset of all unordered tuples of cardinality `n`
with elements in `s`. -/
protected def sym (s : finset α) : Π n, finset (sym α n)
| 0 := {∅}
| (n + 1) := s.sup $ λ a, (sym n).image $ _root_.sym.cons a
@[simp] lemma sym_zero : s.sym 0 = {∅} := rfl
@[simp] lemma sym_succ : s.sym (n + 1) = s.sup (λ a, (s.sym n).image $ sym.cons a) := rfl
@[simp] lemma mem_sym_iff : m ∈ s.sym n ↔ ∀ a ∈ m, a ∈ s :=
begin
induction n with n ih,
{ refine mem_singleton.trans ⟨_, λ _, sym.eq_nil_of_card_zero _⟩,
rintro rfl,
exact λ a ha, ha.elim },
refine mem_sup.trans ⟨_, λ h, _⟩,
{ rintro ⟨a, ha, he⟩ b hb,
rw mem_image at he,
obtain ⟨m, he, rfl⟩ := he,
rw sym.mem_cons at hb,
obtain rfl | hb := hb,
{ exact ha },
{ exact ih.1 he _ hb } },
{ obtain ⟨a, m, rfl⟩ := m.exists_eq_cons_of_succ,
exact ⟨a, h _ $ sym.mem_cons_self _ _,
mem_image_of_mem _ $ ih.2 $ λ b hb, h _ $ sym.mem_cons_of_mem hb⟩ }
end
@[simp] lemma sym_empty (n : ℕ) : (∅ : finset α).sym (n + 1) = ∅ := rfl
lemma replicate_mem_sym (ha : a ∈ s) (n : ℕ) : sym.replicate n a ∈ s.sym n :=
mem_sym_iff.2 $ λ b hb, by rwa (sym.mem_replicate.1 hb).2
protected lemma nonempty.sym (h : s.nonempty) (n : ℕ) : (s.sym n).nonempty :=
let ⟨a, ha⟩ := h in ⟨_, replicate_mem_sym ha n⟩
@[simp] lemma sym_singleton (a : α) (n : ℕ) : ({a} : finset α).sym n = {sym.replicate n a} :=
eq_singleton_iff_unique_mem.2 ⟨replicate_mem_sym (mem_singleton.2 rfl) _,
λ s hs, sym.eq_replicate_iff.2 $ λ b hb, eq_of_mem_singleton $ mem_sym_iff.1 hs _ hb⟩
lemma eq_empty_of_sym_eq_empty (h : s.sym n = ∅) : s = ∅ :=
begin
rw ←not_nonempty_iff_eq_empty at ⊢ h,
exact λ hs, h (hs.sym _),
end
@[simp] lemma sym_eq_empty : s.sym n = ∅ ↔ n ≠ 0 ∧ s = ∅ :=
begin
cases n,
{ exact iff_of_false (singleton_ne_empty _) (λ h, (h.1 rfl).elim) },
{ refine ⟨λ h, ⟨n.succ_ne_zero, eq_empty_of_sym_eq_empty h⟩, _⟩,
rintro ⟨_, rfl⟩,
exact sym_empty _ }
end
@[simp] lemma sym_nonempty : (s.sym n).nonempty ↔ n = 0 ∨ s.nonempty :=
by simp_rw [nonempty_iff_ne_empty, ne.def, sym_eq_empty, not_and_distrib, not_ne_iff]
@[simp] lemma sym_univ [fintype α] (n : ℕ) : (univ : finset α).sym n = univ :=
eq_univ_iff_forall.2 $ λ s, mem_sym_iff.2 $ λ a _, mem_univ _
@[simp] lemma sym_mono (h : s ⊆ t) (n : ℕ): s.sym n ⊆ t.sym n :=
λ m hm, mem_sym_iff.2 $ λ a ha, h $ mem_sym_iff.1 hm _ ha
@[simp] lemma sym_inter (s t : finset α) (n : ℕ) : (s ∩ t).sym n = s.sym n ∩ t.sym n :=
by { ext m, simp only [mem_inter, mem_sym_iff, imp_and_distrib, forall_and_distrib] }
@[simp] lemma sym_union (s t : finset α) (n : ℕ) : s.sym n ∪ t.sym n ⊆ (s ∪ t).sym n :=
union_subset (sym_mono (subset_union_left s t) n) (sym_mono (subset_union_right s t) n)
lemma sym_fill_mem (a : α) {i : fin (n + 1)} {m : sym α (n - i)} (h : m ∈ s.sym (n - i)) :
m.fill a i ∈ (insert a s).sym n :=
mem_sym_iff.2 $ λ b hb, mem_insert.2 $ (sym.mem_fill_iff.1 hb).imp and.right $ mem_sym_iff.1 h b
lemma sym_filter_ne_mem (a : α) (h : m ∈ s.sym n) :
(m.filter_ne a).2 ∈ (s.erase a).sym (n - (m.filter_ne a).1) :=
mem_sym_iff.2 $ λ b H, mem_erase.2 $ (multiset.mem_filter.1 H).symm.imp ne.symm $ mem_sym_iff.1 h b
/-- If `a` does not belong to the finset `s`, then the `n`th symmetric power of `{a} ∪ s` is
in 1-1 correspondence with the disjoint union of the `n - i`th symmetric powers of `s`,
for `0 ≤ i ≤ n`. -/
@[simps] def sym_insert_equiv (h : a ∉ s) : (insert a s).sym n ≃ Σ i : fin (n + 1), s.sym (n - i) :=
{ to_fun := λ m, ⟨_, (m.1.filter_ne a).2, by convert sym_filter_ne_mem a m.2; rw erase_insert h⟩,
inv_fun := λ m, ⟨m.2.1.fill a m.1, sym_fill_mem a m.2.2⟩,
left_inv := λ m, subtype.ext $ m.1.fill_filter_ne a,
right_inv := λ ⟨i, m, hm⟩, begin
refine (_ : id.injective).sigma_map (λ i, _) _,
{ exact λ i, sym α (n - i) },
swap, { exact λ _ _, id },
swap, { exact subtype.coe_injective },
refine eq.trans _ (sym.filter_ne_fill a _ _),
exacts [rfl, h ∘ mem_sym_iff.1 hm a],
end }
end sym
end finset
|
c4a32599b638be8ff275b9572cc435ff9304a645
|
cf39355caa609c0f33405126beee2739aa3cb77e
|
/tests/lean/heuristic_name_field_anonymous.lean
|
dc7b79a7d68e8a872c8c47cd138a73b33d215f82
|
[
"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
| 236
|
lean
|
class A {α : Type*} (x : α)
instance {α : Type*} {p : α → Prop} (x : subtype p) : A x.1 := A.mk
example := @subtype.field_1.A
instance {α : Type*} {p : α → Prop} (x : subtype p) : A x.val := A.mk
example := @subtype.val.A
|
d10e005b6840f69d0575995f51dbc1cea6fabb5f
|
ae1e94c332e17c7dc7051ce976d5a9eebe7ab8a5
|
/src/Std/Data/RBTree.lean
|
e2bd9a4dc8c73c76af1d8b2bc6223c9f6c0a2313
|
[
"Apache-2.0"
] |
permissive
|
dupuisf/lean4
|
d082d13b01243e1de29ae680eefb476961221eef
|
6a39c65bd28eb0e28c3870188f348c8914502718
|
refs/heads/master
| 1,676,948,755,391
| 1,610,665,114,000
| 1,610,665,114,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 3,216
|
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 Std.Data.RBMap
namespace Std
universes u v w
def RBTree (α : Type u) (lt : α → α → Bool) : Type u :=
RBMap α Unit lt
instance : Inhabited (RBTree α p) where
default := RBMap.empty
@[inline] def mkRBTree (α : Type u) (lt : α → α → Bool) : RBTree α lt :=
mkRBMap α Unit lt
instance (α : Type u) (lt : α → α → Bool) : EmptyCollection (RBTree α lt) :=
⟨mkRBTree α lt⟩
namespace RBTree
variables {α : Type u} {β : Type v} {lt : α → α → Bool}
@[inline] def empty : RBTree α lt :=
RBMap.empty
@[inline] def depth (f : Nat → Nat → Nat) (t : RBTree α lt) : Nat :=
RBMap.depth f t
@[inline] def fold (f : β → α → β) (init : β) (t : RBTree α lt) : β :=
RBMap.fold (fun r a _ => f r a) init t
@[inline] def revFold (f : β → α → β) (init : β) (t : RBTree α lt) : β :=
RBMap.revFold (fun r a _ => f r a) init t
@[inline] def foldM {m : Type v → Type w} [Monad m] (f : β → α → m β) (init : β) (t : RBTree α lt) : m β :=
RBMap.foldM (fun r a _ => f r a) init t
@[inline] def forM {m : Type v → Type w} [Monad m] (f : α → m PUnit) (t : RBTree α lt) : m PUnit :=
t.foldM (fun _ a => f a) ⟨⟩
@[inline] def forIn [Monad m] (t : RBTree α lt) (init : σ) (f : α → σ → m (ForInStep σ)) : m σ :=
t.val.forIn init (fun a _ acc => f a acc)
@[inline] def isEmpty (t : RBTree α lt) : Bool :=
RBMap.isEmpty t
@[specialize] def toList (t : RBTree α lt) : List α :=
t.revFold (fun as a => a::as) []
@[inline] protected def min (t : RBTree α lt) : Option α :=
match RBMap.min t with
| some ⟨a, _⟩ => some a
| none => none
@[inline] protected def max (t : RBTree α lt) : Option α :=
match RBMap.max t with
| some ⟨a, _⟩ => some a
| none => none
instance [Repr α] : Repr (RBTree α lt) where
reprPrec t prec := Repr.addAppParen ("Std.rbtreeOf " ++ repr t.toList) prec
@[inline] def insert (t : RBTree α lt) (a : α) : RBTree α lt :=
RBMap.insert t a ()
@[inline] def erase (t : RBTree α lt) (a : α) : RBTree α lt :=
RBMap.erase t a
@[specialize] def ofList : List α → RBTree α lt
| [] => mkRBTree ..
| x::xs => (ofList xs).insert x
@[inline] def find? (t : RBTree α lt) (a : α) : Option α :=
match RBMap.findCore? t a with
| some ⟨a, _⟩ => some a
| none => none
@[inline] def contains (t : RBTree α lt) (a : α) : Bool :=
(t.find? a).isSome
def fromList (l : List α) (lt : α → α → Bool) : RBTree α lt :=
l.foldl insert (mkRBTree α lt)
@[inline] def all (t : RBTree α lt) (p : α → Bool) : Bool :=
RBMap.all t (fun a _ => p a)
@[inline] def any (t : RBTree α lt) (p : α → Bool) : Bool :=
RBMap.any t (fun a _ => p a)
def subset (t₁ t₂ : RBTree α lt) : Bool :=
t₁.all fun a => (t₂.find? a).toBool
def seteq (t₁ t₂ : RBTree α lt) : Bool :=
subset t₁ t₂ && subset t₂ t₁
end RBTree
def rbtreeOf {α : Type u} (l : List α) (lt : α → α → Bool) : RBTree α lt :=
RBTree.fromList l lt
end Std
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.