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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
923f6c7e7ef99229fc1490850b83a3d78a5f6029 | 32025d5c2d6e33ad3b6dd8a3c91e1e838066a7f7 | /stage0/src/Lean/ParserCompiler.lean | 84dbcda4bc7b515c659162e2261d6be72b8cfc53 | [
"Apache-2.0"
] | permissive | walterhu1015/lean4 | b2c71b688975177402758924eaa513475ed6ce72 | 2214d81e84646a905d0b20b032c89caf89c737ad | refs/heads/master | 1,671,342,096,906 | 1,599,695,985,000 | 1,599,695,985,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 6,092 | lean | /-
Copyright (c) 2020 Sebastian Ullrich. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sebastian Ullrich
-/
/-!
Gadgets for compiling parser declarations into other programs, such as pretty printers.
-/
import Lean.Util.ReplaceExpr
import Lean.Meta.Basic
import Lean.Meta.WHNF
import Lean.ParserCompiler.Attribute
import Lean.Parser.Extension
namespace Lean
namespace ParserCompiler
structure Context (α : Type) :=
(varName : Name)
(runtimeAttr : KeyedDeclsAttribute α)
(combinatorAttr : CombinatorAttribute)
(interpretParserDescr : ParserDescr → CoreM α)
def Context.tyName {α} (ctx : Context α) : Name := ctx.runtimeAttr.defn.valueTypeName
-- replace all references of `Parser` with `tyName` as a first approximation
def preprocessParserBody {α} (ctx : Context α) (e : Expr) : Expr :=
e.replace fun e => if e.isConstOf `Lean.Parser.Parser then mkConst ctx.tyName else none
section
open Meta
-- translate an expression of type `Parser` into one of type `tyName`
partial def compileParserBody {α} (ctx : Context α) : Expr → MetaM Expr | e => do
e ← whnfCore e;
match e with
| e@(Expr.lam _ _ _ _) => lambdaLetTelescope e fun xs b => compileParserBody b >>= mkLambdaFVars xs
| e@(Expr.fvar _ _) => pure e
| _ => do
let fn := e.getAppFn;
Expr.const c _ _ ← pure fn
| throwError $ "call of unknown parser at '" ++ toString e ++ "'";
let args := e.getAppArgs;
-- call the translated `p` with (a prefix of) the arguments of `e`, recursing for arguments
-- of type `ty` (i.e. formerly `Parser`)
let mkCall (p : Name) := do {
ty ← inferType (mkConst p);
forallTelescope ty fun params _ =>
params.foldlM₂ (fun p param arg => do
paramTy ← inferType param;
resultTy ← forallTelescope paramTy fun _ b => pure b;
arg ← if resultTy.isConstOf ctx.tyName then compileParserBody arg
else pure arg;
pure $ mkApp p arg)
(mkConst p)
e.getAppArgs
};
env ← getEnv;
match ctx.combinatorAttr.getDeclFor env c with
| some p => mkCall p
| none => do
let c' := c ++ ctx.varName;
cinfo ← getConstInfo c;
resultTy ← forallTelescope cinfo.type fun _ b => pure b;
if resultTy.isConstOf `Lean.Parser.TrailingParser || resultTy.isConstOf `Lean.Parser.Parser then do
-- synthesize a new `[combinatorAttr c]`
some value ← pure cinfo.value?
| throwError $ "don't know how to generate " ++ ctx.varName ++ " for non-definition '" ++ toString e ++ "'";
value ← compileParserBody $ preprocessParserBody ctx value;
ty ← forallTelescope cinfo.type fun params _ =>
params.foldrM (fun param ty => do
paramTy ← inferType param;
paramTy ← forallTelescope paramTy fun _ b => pure $
if b.isConstOf `Lean.Parser.Parser then mkConst ctx.tyName
else b;
pure $ mkForall `_ BinderInfo.default paramTy ty)
(mkConst ctx.tyName);
let decl := Declaration.defnDecl { name := c', lparams := [],
type := ty, value := value, hints := ReducibilityHints.opaque, isUnsafe := false };
env ← getEnv;
env ← match env.addAndCompile {} decl with
| Except.ok env => pure env
| Except.error kex => throwError $ toString $ fmt $ kex.toMessageData {};
setEnv $ ctx.combinatorAttr.setDeclFor env c c';
mkCall c'
else do
-- if this is a generic function, e.g. `HasAndthen.andthen`, it's easier to just unfold it until we are
-- back to parser combinators
some e' ← unfoldDefinition? e
| throwError $ "don't know how to generate " ++ ctx.varName ++ " for non-parser combinator '" ++ toString e ++ "'";
compileParserBody e'
end
open Core
/-- Compile the given declaration into a `[(builtin)runtimeAttr declName]` -/
def compileParser {α} (ctx : Context α) (declName : Name) (builtin : Bool) : CoreM Unit := do
-- This will also tag the declaration as a `[combinatorParenthesizer declName]` in case the parser is used by other parsers.
-- Note that simply having `[(builtin)Parenthesizer]` imply `[combinatorParenthesizer]` is not ideal since builtin
-- attributes are active only in the next stage, while `[combinatorParenthesizer]` is active immediately (since we never
-- call them at compile time but only reference them).
(Expr.const c' _ _) ← (compileParserBody ctx (mkConst declName)).run'
| unreachable!;
-- We assume that for tagged parsers, the kind is equal to the declaration name. This is automatically true for parsers
-- using `parser!` or `syntax`.
let kind := declName;
env ← getEnv;
liftIO (env.addAttribute c' (if builtin then ctx.runtimeAttr.defn.builtinName else ctx.runtimeAttr.defn.name) (mkNullNode #[mkIdent kind])) >>= setEnv
-- When called from `interpretParserDescr`, `declName` might not be a tagged parser, so ignore "not a valid syntax kind" failures
<|> pure ()
unsafe def interpretParser {α} (ctx : Context α) (constName : Name) : CoreM α := do
info ← getConstInfo constName;
env ← getEnv;
if info.type.isConstOf `Lean.Parser.TrailingParser || info.type.isConstOf `Lean.Parser.Parser then
match ctx.runtimeAttr.getValues env constName with
| p::_ => pure p
| _ => do
compileParser ctx constName /- builtin -/ false;
env ← getEnv;
ofExcept $ env.evalConst α (constName ++ ctx.varName)
else do
d ← ofExcept $ env.evalConst TrailingParserDescr constName;
ctx.interpretParserDescr d
unsafe def registerParserCompiler {α} (ctx : Context α) : IO Unit := do
Parser.registerParserAttributeHook {
postAdd := fun catName declName builtin =>
if builtin then
compileParser ctx declName builtin
else do
p ← interpretParser ctx declName;
-- Register `p` without exporting it to the .olean file. It will be re-interpreted and registered
-- when the parser is imported.
env ← getEnv;
setEnv $ ctx.runtimeAttr.ext.modifyState env fun st => { st with table := st.table.insert declName p }
}
end ParserCompiler
end Lean
|
35a13cf6e74e021d9e95cd9b8bd9f60cffd0245e | 10c7c971a1902d76057c52ce0529ebb491a69c44 | /NatDeduction.lean | f76f9f54230f741be5c28e992e8e08d3336f5b84 | [] | no_license | SzymonKubica/Lean | 5f6122e8dd9171239b36a9ce0515f6acbc49781a | 627bff2f001ba3f009c112c9332093e8de84863c | refs/heads/main | 1,675,563,490,768 | 1,608,538,609,000 | 1,608,538,609,000 | 307,184,347 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 2,696 | lean | import tactic
-- Exercise 1
-- (a)
variables p q : Prop
variable given1 : (p ∧ q)
example : p :=
show p, from and.left given1
-- (b)
--example : (p ∧ q → p) :=
--assume h1 : (p ∧ q),
--show p, from and.left h1
-- (c)
example : p → (q → p) :=
begin
assume h1,
assume h2,
exact h1,
end
-- (d)
example: p → (q → p ∧ q) :=
begin
assume h1,
assume h2,
split,
exact h1,
exact h2,
end
-- (f)
variable r : Prop
example : (p → (q → r)) → ((p → q) → (p → r)) :=
begin
assume h1: p → (q → r),
assume h2: p → q,
assume h3: p,
apply h1,
exact h3,
apply h2,
exact h3,
end
-- (e)
example : (p → (q → r)) → (p ∧ q → r) :=
begin
assume h1,
assume h2: p ∧ q,
cases h2 with h3 h4,
apply h1,
exact h3,
exact h4,
end
-- (g)
example : ((p ∧ q) → r) → (p → (q → r)) :=
begin
intro h1,
intro h2,
intro h3,
apply h1,
split,
exact h2,
exact h3,
end
-- (h)
example : (p ∧ q) → (p ∨ q) :=
begin
intro h1,
cases h1 with h2 h3,
left,
exact h2,
end
-- (i)
example : p → (q → p) :=
begin
intro h1,
intro h2,
exact h1,
end
-- (j)
example : p ∧ (q ∨ (p → q)) → p ∧ q :=
begin
intro h1,
cases h1 with h2 h3,
split,
exact h2,
cases h3 with h4 h5,
exact h4,
apply h5,
exact h2,
end
-- 2.
-- (a)
example : p ∧ (p → q) → p ∧ q :=
begin
intro h1,
cases h1 with h1 h2,
split,
exact h1,
apply h2,
exact h1,
end
-- (b)
example : (q → r) → ((p → q) → (p → r)) :=
begin
intro h1,
intro h2,
intro h3,
apply h1,
apply h2,
exact h3,
end
-- (c)
example : (p ∧ (q ∨ r)) → (p ∧ q) ∨ (p ∧ r) :=
begin
intro h1,
cases h1 with h1 h2,
cases h2 with h2 h3,
left,
split,
exact h1,
exact h2,
right,
split,
exact h1,
exact h3,
end
-- (d)
example : (¬ p ∧ (p ∨ q)) → q :=
begin
intro h1,
cases h1 with h1 h2,
cases h2 with h2 h3,
exfalso,
show false, from h1 h2,
exact h3,
end
-- (f)
example : (¬ (p ∨ q)) → (¬ p ∧ ¬ q) :=
begin
intro h1,
split,
push_neg at h1,
show ¬ p, from and.left h1,
push_neg at h1,
show ¬ q, from and.right h1,
end
axiom lawOfExcludedMiddle : p ∨ ¬ p → true
axiom pAndNotPImpF : q ∧ ¬ q -> false
-- (g)
example : (p → q) → (¬ q → ¬ p) :=
begin
intro h1,
intro h2,
assume (hp : p),
have hq : q, from h1 hp,
have hf : q ∧ ¬ q, from and.intro hq h2,
show false, from pAndNotPImpF hf,
end
-- The following code defines useful tools that we defined in Nat. deduction.
example (hp : p) (hq : q) : p ∧ q := and.intro hp hq
#check assume (hp : p) (hq : q), and.intro hp hq
|
79c5b06c336e1c30a24a0b55ca4c985a7813b0b0 | b82c5bb4c3b618c23ba67764bc3e93f4999a1a39 | /src/formal_ml/real_random_variable.lean | 0128cf01e46f638b1028c15b319f70968900e5c2 | [
"Apache-2.0"
] | permissive | nouretienne/formal-ml | 83c4261016955bf9bcb55bd32b4f2621b44163e0 | 40b6da3b6e875f47412d50c7cd97936cb5091a2b | refs/heads/master | 1,671,216,448,724 | 1,600,472,285,000 | 1,600,472,285,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 93,169 | lean | /-
Copyright 2020 Google LLC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-/
import measure_theory.measurable_space
import measure_theory.measure_space
import measure_theory.outer_measure
import measure_theory.lebesgue_measure
import measure_theory.integration
import measure_theory.borel_space
import data.set.countable
import formal_ml.measurable_space
import formal_ml.probability_space
import formal_ml.real_measurable_space
import formal_ml.nnreal
import formal_ml.semiring
import topology.instances.real
import formal_ml.integral
import formal_ml.classical
/-
This file should be vetted for results in borel_space.lean.
borel_space also has a wealth of results about ennreal, including
a proof that multiplication is measurable. This completes the story
of ennreal measurable functions being a commutative semiring.
-/
------------- A measurable linear order ------------------------------------------------------------
/-
Similar to topological semirings, a measurable linear order adds measurability onto a linear
order.
-/
class measurable_linear_order (α:Type*) [M:measurable_space α]
extends linear_order α :=
(is_measurable_le:is_measurable {p:α × α|p.fst ≤ p.snd})
(is_measurable_eq:is_measurable {p:α × α|p.fst = p.snd})
def measurable_linear_order_t2_sc {α:Type*} [T:topological_space α]
[SC:topological_space.second_countable_topology α] [P:linear_order α]
[OT:order_topology α] [T2:t2_space α]:@measurable_linear_order α (borel α) :=
{
is_measurable_le:=is_measurable_of_le,
is_measurable_eq:=is_measurable_of_eq,
}
noncomputable instance measurable_linear_order_nnreal:measurable_linear_order nnreal :=
measurable_linear_order_t2_sc
noncomputable instance measurable_linear_order_real:measurable_linear_order real :=
measurable_linear_order_t2_sc
noncomputable instance measurable_linear_order_ennreal:measurable_linear_order ennreal :=
measurable_linear_order_t2_sc
lemma lt_iff_le_not_eq {α:Type*} [linear_order α] (a b:α):a < b ↔ a ≤ b ∧ (a ≠ b) :=
begin
apply iff.trans,
apply linear_order.lt_iff_le_not_le,
split; intro A1,
{
split,
apply A1.left,
intro A2,
apply A1.right,
rw A2,
},
{
split,
apply A1.left,
intro A2,
apply A1.right,
apply linear_order.le_antisymm,
apply A1.left,
apply A2,
}
end
lemma measurable_linear_order.is_measurable_lt (α:Type*) [M:measurable_space α]
[c:measurable_linear_order α]:measurable_space.is_measurable (@prod.measurable_space α α M M) {p:α × α|p.fst < p.snd} :=
begin
have A1:{p:α × α|p.fst < p.snd} = {p:α × α|p.fst ≤ p.snd} \ {p:α × α|p.fst = p.snd},
{
ext,
simp,
apply lt_iff_le_not_eq,
},
rw A1,
apply is_measurable.diff,
{
apply measurable_linear_order.is_measurable_le,
},
{
apply measurable_linear_order.is_measurable_eq
}
end
lemma measurable_linear_order.is_measurable_le' (α:Type*) [M:measurable_space α]
[MLO:measurable_linear_order α]:is_measurable {p:α × α|p.snd ≤ p.fst} :=
begin
have A1:{p:α × α|p.snd ≤ p.fst} = {p:α × α|p.fst < p.snd}ᶜ,
{
ext p,
split;intros A1A;simp;simp at A1A;apply A1A,
},
rw A1,
apply is_measurable.compl,
apply measurable_linear_order.is_measurable_lt,
end
---------------------------------------------------------------------------------------------------
section is_sub_semiring
universes u v
--def semiring.to_add_monoid {α:Type u} (semiring α):add_monoid α :=
def SC_sum_measurable_add_monoid
{Ω:Type*} [MΩ:measurable_space Ω]
{β:Type*} {T:topological_space β} {SC:topological_space.second_countable_topology β}
{CSR:add_monoid β} {TA:has_continuous_add β}:
add_monoid (measurable_fun MΩ (borel β)) :=
@subtype.add_monoid (Ω → β) _ (@measurable Ω β MΩ (borel β))
(@SC_sum_measurable_is_add_submonoid Ω MΩ β T SC CSR TA)
def SC_sum_measurable_add_comm_monoid
{Ω:Type*} [MΩ:measurable_space Ω]
{β:Type*} {T:topological_space β} {SC:topological_space.second_countable_topology β}
{CSR:add_comm_monoid β} {TA:has_continuous_add β}:
add_comm_monoid (measurable_fun MΩ (borel β)) :=
@subtype.add_comm_monoid (Ω → β) _ (@measurable Ω β MΩ (borel β))
(@SC_sum_measurable_is_add_submonoid Ω MΩ β T SC (add_comm_monoid.to_add_monoid β) TA)
def SC_sum_measurable_is_add_submonoid_from_semiring
{Ω:Type*} [MΩ:measurable_space Ω]
{β:Type*} {T:topological_space β} {SC:topological_space.second_countable_topology β}
{CSR:semiring β} {TA:topological_semiring β}:
is_add_submonoid (@measurable Ω β MΩ (borel β)) :=
(@SC_sum_measurable_is_add_submonoid Ω MΩ β T SC (add_comm_monoid.to_add_monoid β)
(topological_semiring.to_has_continuous_add))
def SC_sum_measurable_is_add_subgroup_from_ring
{Ω:Type*} [MΩ:measurable_space Ω]
{β:Type*} {T:topological_space β} {SC:topological_space.second_countable_topology β}
{CSR:ring β} {TA:topological_ring β}:
is_add_subgroup (@measurable Ω β MΩ (borel β)) :=
(@SC_sum_measurable_is_add_subgroup Ω MΩ β T SC (add_comm_group.to_add_group β)
(topological_ring.to_topological_add_group β))
def SC_mul_measurable_is_submonoid_from_semiring
{Ω:Type*} [MΩ:measurable_space Ω]
{β:Type*} {T:topological_space β} {SC:topological_space.second_countable_topology β}
{CSR:semiring β} {TA:topological_semiring β}:
is_submonoid (@measurable Ω β MΩ (borel β)) :=
(@SC_mul_measurable_is_submonoid Ω MΩ β T SC (monoid_with_zero.to_monoid β)
(topological_semiring.to_has_continuous_mul))
def SC_measurable_semiring_is_sub_semiring
{Ω:Type u} [MΩ:measurable_space Ω]
{β:Type v} {T:topological_space β} {SC:topological_space.second_countable_topology β}
{CSR:semiring β} {TA:topological_semiring β}:
is_sub_semiring (@measurable Ω β MΩ (borel β)) := {
..(@SC_sum_measurable_is_add_submonoid_from_semiring Ω MΩ β T SC _ TA),
..(@SC_mul_measurable_is_submonoid_from_semiring Ω MΩ β T SC _ TA),
}
def SC_measurable_ring_is_subring
{Ω:Type u} [MΩ:measurable_space Ω]
{β:Type v} {T:topological_space β} {SC:topological_space.second_countable_topology β}
{CSR:ring β} {TA:topological_ring β}:
is_subring (@measurable Ω β MΩ (borel β)) := {
..(@SC_sum_measurable_is_add_subgroup_from_ring Ω MΩ β T SC _ TA),
..(@SC_mul_measurable_is_submonoid_from_semiring Ω MΩ β T SC _ (topological_ring.to_topological_semiring β)),
}
def SC_measurable_semiring
{Ω:Type u} [MΩ:measurable_space Ω]
{β:Type v} {T:topological_space β} {SC:topological_space.second_countable_topology β}
{CSR:semiring β} {TA:topological_semiring β}:
semiring (measurable_fun MΩ (borel β)):=
@subtype.semiring (Ω → β) _ (@measurable Ω β MΩ (borel β))
(@SC_measurable_semiring_is_sub_semiring Ω MΩ β T SC CSR TA)
def SC_measurable_comm_semiring
{Ω:Type u} [MΩ:measurable_space Ω]
{β:Type v} {T:topological_space β} {SC:topological_space.second_countable_topology β}
{CSR:comm_semiring β} {TA:topological_semiring β}:
comm_semiring (measurable_fun MΩ (borel β)):=
@subtype.comm_semiring (Ω → β) _ (@measurable Ω β MΩ (borel β))
(@SC_measurable_semiring_is_sub_semiring Ω MΩ β T SC (comm_semiring.to_semiring β) TA)
def SC_measurable_comm_ring
{Ω:Type u} [MΩ:measurable_space Ω]
{β:Type v} {T:topological_space β} {SC:topological_space.second_countable_topology β}
{CSR:comm_ring β} {TA:topological_ring β}:
comm_ring (measurable_fun MΩ (borel β)):=
@subtype.comm_ring (Ω → β) _ (@measurable Ω β MΩ (borel β))
(@SC_measurable_ring_is_subring Ω MΩ β T SC (comm_ring.to_ring β) TA)
end is_sub_semiring
noncomputable instance nnreal_measurable_fun_comm_semiring {Ω:Type*} [MΩ:measurable_space Ω]:
comm_semiring (measurable_fun MΩ (borel nnreal)):=
@SC_measurable_comm_semiring Ω MΩ nnreal nnreal.topological_space
nnreal.topological_space.second_countable_topology nnreal.comm_semiring
nnreal.topological_semiring
noncomputable def real.topological_space:topological_space ℝ := infer_instance
noncomputable instance real_measurable_fun_comm_ring {Ω:Type*} [MΩ:measurable_space Ω]:
comm_ring (measurable_fun MΩ (borel real)):=
@SC_measurable_comm_ring Ω MΩ real real.topological_space
real.topological_space.second_countable_topology real.comm_ring
real.topological_ring
lemma nnreal_measurable_fun_zero_val_def {Ω:Type*} [MΩ:measurable_space Ω]:
(0:MΩ →m (borel nnreal)).val = 0 := rfl
lemma real_measurable_fun_zero_val_def {Ω:Type*} [MΩ:measurable_space Ω]:
(0:MΩ →m (borel real)).val = 0 := rfl
lemma nnreal_measurable_fun_add_val_def {Ω:Type*} [MΩ:measurable_space Ω] {a b:MΩ →m (borel nnreal)}:
(a + b).val = (a.val + b.val) := rfl
lemma real_measurable_fun_add_val_def {Ω:Type*} [MΩ:measurable_space Ω] {a b:MΩ →m (borel real)}:
(a + b).val = (a.val + b.val) := rfl
lemma nnreal_measurable_fun_one_val_def {Ω:Type*} [MΩ:measurable_space Ω]:
(1:MΩ →m (borel nnreal)).val = 1 := rfl
lemma real_measurable_fun_one_val_def {Ω:Type*} [MΩ:measurable_space Ω]:
(1:MΩ →m (borel real)).val = 1 := rfl
lemma nnreal_measurable_fun_mul_val_def {Ω:Type*} [MΩ:measurable_space Ω] {a b:MΩ →m (borel nnreal)}:
(a * b).val = (a.val * b.val) := rfl
lemma real_measurable_fun_mul_val_def {Ω:Type*} [MΩ:measurable_space Ω] {a b:MΩ →m (borel real)}:
(a * b).val = (a.val * b.val) := rfl
noncomputable instance nnreal_random_variable_comm_semiring {Ω:Type*}
{p:probability_space Ω}:
comm_semiring (random_variable p (borel nnreal)):=
nnreal_measurable_fun_comm_semiring
noncomputable instance real_random_variable_comm_ring {Ω:Type*}
{p:probability_space Ω}:
comm_ring (random_variable p (borel real)):=
real_measurable_fun_comm_ring
lemma nnreal_random_variable_add_val_def {Ω:Type*}
{P:probability_space Ω} {a b:P →r (borel nnreal)}:
(a + b).val = (a.val + b.val) := rfl
lemma real_random_variable_add_val_def {Ω:Type*}
{P:probability_space Ω} {a b:P →r (borel real)}:
(a + b).val = (a.val + b.val) := rfl
lemma nnreal_random_variable_mul_val_def {Ω:Type*}
{P:probability_space Ω} {a b:P →r (borel nnreal)}:
(a * b).val = (a.val * b.val) := rfl
lemma real_random_variable_mul_val_def {Ω:Type*}
{P:probability_space Ω} {a b:P →r (borel nnreal)}:
(a * b).val = (a.val * b.val) := rfl
lemma real_random_variable_neg_val_def {Ω:Type*}
{P:probability_space Ω} {a:P →r (borel real)}:
(-a).val = -(a.val) := rfl
--ennreal is not a topological semiring, because multiplication is not continuous,
--but it is measurable. Therefore, we must prove it is a submonoid directly.
def ennreal_measurable_is_submonoid
{Ω:Type*} [MΩ:measurable_space Ω]:
is_submonoid (@measurable Ω ennreal MΩ (borel ennreal)) := {
one_mem :=@measurable_const ennreal Ω (borel ennreal) MΩ 1,
mul_mem :=
begin
intros x y A1 A2,
apply measurable.ennreal_mul A1 A2,
end
}
--Should be able to use SC_sum_measurable_is_add_submonoid,
--but results in definitional inequalities in ennreal_measurable_is_sub_semiring.
def ennreal_measurable_is_add_submonoid
{Ω:Type*} [MΩ:measurable_space Ω]:
is_add_submonoid (@measurable Ω ennreal MΩ (borel ennreal)) := {
zero_mem :=@measurable_const ennreal Ω (borel ennreal) MΩ 0,
add_mem :=
begin
intros x y A1 A2,
apply measurable.ennreal_add A1 A2,
end
}
def ennreal_measurable_is_sub_semiring
{Ω:Type*} [MΩ:measurable_space Ω]:
is_sub_semiring (@measurable Ω ennreal MΩ (borel ennreal)) := {
..(@ennreal_measurable_is_add_submonoid Ω MΩ),
..(@ennreal_measurable_is_submonoid Ω MΩ),
}
noncomputable instance ennreal_measurable_fun_comm_semiring {Ω:Type*} [MΩ:measurable_space Ω]:
comm_semiring (measurable_fun MΩ (borel ennreal)):=
@subtype.comm_semiring (Ω → ennreal) _ (@measurable Ω ennreal MΩ (borel ennreal))
(@ennreal_measurable_is_sub_semiring Ω MΩ)
noncomputable instance ennreal_random_variable_comm_semiring {Ω:Type*}
{p:probability_space Ω}:
comm_semiring (random_variable p (borel ennreal)):=
ennreal_measurable_fun_comm_semiring
lemma ennreal_measurable_fun_zero_val_def {Ω:Type*} [MΩ:measurable_space Ω]:
(0:MΩ →m (borel ennreal)).val = 0 := rfl
lemma ennreal_measurable_fun_add_val_def {Ω:Type*} [MΩ:measurable_space Ω] {a b:MΩ →m (borel ennreal)}:
(a + b).val = (a.val + b.val) := rfl
--A test to see if + works.
lemma nnreal_commutes {Ω:Type*}
{P:probability_space Ω} (A B:P →r (borel nnreal)):A + B = B + A :=
begin
rw add_comm,
end
def measurable_set_le {β : Type*} [Mβ:measurable_space β] [L:measurable_linear_order β]
:measurable_set (Mβ ×m Mβ) := {
val:={p:β × β|p.fst ≤ p.snd},
property:=L.is_measurable_le,
}
lemma measurable_set_le_val_def {β : Type*} [Mβ:measurable_space β] [L:measurable_linear_order β]:(@measurable_set_le β Mβ L).val = {p:β × β|p.fst ≤ p.snd} := rfl
def measurable_set_eq {β : Type*} [Mβ:measurable_space β] [L:measurable_linear_order β]
:measurable_set (Mβ ×m Mβ) := {
val:={p:β × β|p.fst = p.snd},
property:=L.is_measurable_eq,
}
lemma measurable_set_eq_val_def {β : Type*} [Mβ:measurable_space β] [L:measurable_linear_order β]
:(@measurable_set_eq β Mβ L).val={p:β × β|p.fst = p.snd} :=
begin
refl,
end
lemma measurable_linear_order.is_measurable_lt' (α:Type*) [M:measurable_space α]
[c:measurable_linear_order α]:measurable_space.is_measurable (M ×m M) {p:α × α|p.fst < p.snd} :=
begin
apply measurable_linear_order.is_measurable_lt,
end
def measurable_set_lt {β : Type*} [Mβ:measurable_space β] [L:measurable_linear_order β]
:measurable_set (Mβ ×m Mβ) := {
val:={p:β × β|p.fst < p.snd},
property:=@measurable_linear_order.is_measurable_lt _ _ L,
}
/-TODO:Define a class measurable_eq, and make an instance of top_measurable-/
def event_eq
{Ω : Type*} {P:probability_space Ω}
{β : Type*} [Mβ:measurable_space β] [L:measurable_linear_order β]
(X Y:P →r Mβ):event P := rv_event (X ×r Y) (measurable_set_eq)
infixr ` =ᵣ `:80 := event_eq
lemma event_eq_val_def {Ω : Type*} {P:probability_space Ω}
{β : Type*} [Mβ:measurable_space β] [L:measurable_linear_order β]
(X Y:P →r Mβ):(X =ᵣ Y).val = {a : Ω | X.val a = Y.val a} :=
begin
unfold event_eq,
rw rv_event_val_def,
rw measurable_set_eq_val_def,
rw prod_random_variable_val_def,
simp,
end
def event_lt
{Ω : Type*} {P:probability_space Ω}
{β : Type*} [Mβ:measurable_space β] [L:measurable_linear_order β]
(X Y:P →r Mβ):event P := rv_event (X ×r Y) (measurable_set_lt)
/-
Now, Pr[X <ᵣ Y] is just what it looks like: the probability that X is less than Y.
-/
infixr ` <ᵣ `:80 := event_lt
def event_le
{Ω : Type*} {P:probability_space Ω}
{β : Type*} [Mβ:measurable_space β] [L:measurable_linear_order β]
(X Y:P →r Mβ):event P := rv_event (X ×r Y) (measurable_set_le)
infixr ` ≤ᵣ `:80 := event_le
lemma event_le_def
{Ω : Type*} {P:probability_space Ω}
{β : Type*} [Mβ:measurable_space β] [L:measurable_linear_order β]
(X Y:P →r Mβ):(X ≤ᵣ Y) = rv_event (X ×r Y) (measurable_set_le) := rfl
lemma event_le_val_def
{Ω : Type*} {P:probability_space Ω}
{β : Type*} [Mβ:measurable_space β] [L:measurable_linear_order β]
(X Y:P →r Mβ):(X ≤ᵣ Y).val = {ω : Ω | X.val ω ≤ Y.val ω} :=
begin
rw event_le_def,
rw rv_event_val_def,
rw prod_random_variable_val_def,
rw measurable_set_le_val_def,
simp,
end
noncomputable instance coe_measurable_fun_of_nnreal
{Ω : Type*} {P:measurable_space Ω}
:has_coe nnreal (measurable_fun P (borel nnreal)) := {
coe := const_measurable_fun
}
noncomputable instance coe_measurable_fun_of_real
{Ω : Type*} {P:measurable_space Ω}
:has_coe real (measurable_fun P (borel real)) := {
coe := const_measurable_fun
}
noncomputable instance coe_random_variable_of_nnreal
{Ω : Type*} {P:probability_space Ω}
:has_coe nnreal (P →r borel nnreal) := {
coe := const_random_variable
}
noncomputable instance coe_random_variable_of_real
{Ω : Type*} {P:probability_space Ω}
:has_coe real (P →r borel real) := {
coe := const_random_variable
}
lemma coe_random_variable_of_real_def {Ω : Type*} {P:probability_space Ω} {x:ℝ}:
(x:P →r (borel ℝ)) = const_random_variable x := rfl
lemma coe_random_variable_of_real_val_def {Ω : Type*} {P:probability_space Ω} {x:ℝ}:
(x:P →r (borel ℝ)).val = λ (ω:Ω), x := rfl
noncomputable def to_nnreal_rv {Ω : Type*}
{P:probability_space Ω} (x:nnreal):(P →r borel nnreal) := x
lemma to_nnreal_rv_val_def {Ω : Type*}
{P:probability_space Ω} (x:nnreal):(@to_nnreal_rv Ω P x).val = λ ω:Ω, x := rfl
noncomputable instance coe_measurable_fun_of_ennreal
{Ω : Type*} [MΩ:measurable_space Ω]
:has_coe ennreal (measurable_fun MΩ (borel ennreal)) := {
coe := const_measurable_fun
}
noncomputable instance coe_random_variable_of_ennreal
{Ω : Type*} {P:probability_space Ω}
:has_coe ennreal (P →r borel ennreal) := {
coe := const_random_variable
}
noncomputable def to_ennreal_rv {Ω : Type*}
{P:probability_space Ω} (x:ennreal):(P →r borel ennreal) := x
def to_ennreal_rv_val_def {Ω : Type*}
{P:probability_space Ω} (x:ennreal):
(@to_ennreal_rv Ω P x).val = λ ω:Ω, x :=
begin
rw to_ennreal_rv,
refl,
end
noncomputable def expected_value_ennreal {α:Type*} {p:probability_space α}
(X:p →r borel ennreal):ennreal :=
measure_theory.measure.integral p.volume X.val
lemma nnreal_to_ennreal_measurable:measurable (λ x:nnreal, (x:ennreal)) :=
begin
apply is_ennreal_measurable_intro_Iio,
intro x,
cases x,
{
simp,
},
{
simp,
apply is_nnreal_is_measurable_intro_Iio,
}
end
def measurable2 {α β γ:Type*} [measurable_space α] [measurable_space β]
[measurable_space γ] (f:α → β → γ):Prop :=
measurable (λ p:α × β, f (p.fst) (p.snd))
lemma measurable2_def {α β γ:Type*} [measurable_space α] [measurable_space β]
[measurable_space γ] (f:α → β → γ):measurable2 f =
measurable (λ p:α × β, f (p.fst) (p.snd)) := rfl
lemma measurable2_composition {Ω:Type*} [MΩ:measurable_space Ω]
{β:Type*} [Mβ:measurable_space β]
(f:Ω → β) (g:Ω → β) (h:β → β → β):
(measurable f) →
(measurable g) →
(measurable2 h) →
measurable (λ ω:Ω, h (f ω) (g ω)) :=
begin
intros A1 A2 A3,
have A4:measurable (λ ω:Ω, prod.mk (f ω) (g ω)),
{
apply measurable_fun_product_measurable;assumption,
},
rw measurable2_def at A3,
have A6:(λ ω:Ω, h (f ω) (g ω))=(λ p: (β × β), h (p.fst) (p.snd)) ∘ (λ ω:Ω, prod.mk (f ω) (g ω)),
{
simp,
},
rw A6,
apply compose_measurable_fun_measurable (λ p: (β × β), h (p.fst) (p.snd)) (λ ω:Ω, prod.mk (f ω) (g ω)) A3 A4,
end
lemma measurable2_max:measurable2 (@max ℝ _) :=
begin
rw measurable2_def,
apply measurable.if,
apply @measurable_linear_order.is_measurable_le' ℝ,
apply fst_measurable,
apply snd_measurable,
end
lemma abs_eq_max (x:ℝ):abs x = max x (-x) := rfl
lemma abs_eq_max_fn :(@abs ℝ _) = (λ x, max x (-x)) :=
begin
ext,
rw abs_eq_max,
end
lemma measurable_abs:measurable (@abs ℝ _) :=
begin
rw abs_eq_max_fn,
apply measurable2_composition (@id ℝ) (@has_neg.neg ℝ _) (@max ℝ _),
{
apply measurable_id,
},
{
apply continuous_measurable,
apply @topological_ring.continuous_neg ℝ _ _,
},
{
apply measurable2_max,
},
end
lemma of_real_of_nonpos {a:ℝ}:a ≤ 0 → (nnreal.of_real a = 0) :=
begin
intro A1,
apply subtype.eq,
simp,
apply A1,
end
lemma nnreal_lt {a:ℝ} {b:nnreal}:(b ≠ 0) → (nnreal.of_real a < b ↔ a < b.val) :=
begin
intro A1,
split;intro A2,
{
have A3:0 ≤ a ∨ a < 0 := decidable.le_or_lt 0 a,
cases A3,
{
rw ← nnreal.coe_lt_coe at A2,
rw nnreal.coe_of_real _ A3 at A2,
apply A2,
},
{
apply lt_of_lt_of_le,
apply A3,
apply b.2,
},
},
{
have A3:0 ≤ a ∨ a < 0 := decidable.le_or_lt 0 a,
cases A3,
{
rw ← nnreal.coe_lt_coe,
rw nnreal.coe_of_real _ A3,
apply A2,
},
{
rw of_real_of_nonpos (le_of_lt A3),
--apply lt_of_lt_of_le,
--apply A3,
--apply b.2,
apply lt_of_le_of_ne,
{
apply bot_le,
},
{
symmetry,
apply A1,
},
},
},
end
lemma nnreal_lt_set {b:nnreal}:(b ≠ 0) → {a:ℝ|nnreal.of_real a < b} = {a:ℝ|a < b.val} :=
begin
intro A1,
ext,
simp,
apply nnreal_lt A1,
end
lemma nnreal_lt_zero_set:{a : ℝ | nnreal.of_real a < 0} = ∅ :=
begin
ext,
simp,
end
lemma measurable_nnreal_of_real:measurable nnreal.of_real :=
begin
apply is_nnreal_measurable_intro_Iio,
intro x,
simp,
have A1:(x=0) ∨ (x≠ 0) := eq_or_ne,
cases A1,
{
rw A1,
rw nnreal_lt_zero_set,
apply is_measurable.empty,
},
{
rw nnreal_lt_set A1,
apply is_real_is_measurable_intro_Iio,
},
end
noncomputable def nnreal_of_real_fun:measurable_fun (borel real) (borel nnreal) := {
val := nnreal.of_real,
property := measurable_nnreal_of_real,
}
lemma nnreal_of_real_fun_val_def:nnreal_of_real_fun.val = nnreal.of_real := rfl
noncomputable def real_abs_fun:measurable_fun (borel real) (borel real) := {
val := (@abs ℝ _),
property := measurable_abs,
}
lemma real_abs_fun_val_def:real_abs_fun.val = (@abs ℝ _) := rfl
noncomputable def measurable_fun_nnreal_of_measurable_fun_real {α:Type*} {Mα:measurable_space α}
(X:measurable_fun Mα (borel real)):measurable_fun Mα (borel nnreal) :=
compose_measurable_fun nnreal_of_real_fun X
lemma measurable_fun_nnreal_of_measurable_fun_real_val_def {α:Type*} {Mα:measurable_space α}
(X:measurable_fun Mα (borel real)):
(measurable_fun_nnreal_of_measurable_fun_real X).val =
(nnreal.of_real ∘ X.val) :=
begin
unfold measurable_fun_nnreal_of_measurable_fun_real,
rw compose_measurable_fun_val_def,
rw nnreal_of_real_fun_val_def
end
def nnreal_to_ennreal_measurable_fun:measurable_fun (borel nnreal) (borel ennreal) := {
val := (λ x:nnreal, (x:ennreal)),
property := nnreal_to_ennreal_measurable,
}
noncomputable def nnreal_to_ennreal_random_variable {Ω:Type*}
{p:probability_space Ω} (X:p →r borel nnreal):p →r borel ennreal :=
nnreal_to_ennreal_measurable_fun ∘r X
lemma nnreal_to_ennreal_random_variable_val_def {Ω:Type*}
{p:probability_space Ω} (X:p →r borel nnreal):
(nnreal_to_ennreal_random_variable X).val = (λ (ω:Ω), ((X.val ω):ennreal)) :=
begin
unfold nnreal_to_ennreal_random_variable,
rw rv_compose_val_def,
unfold nnreal_to_ennreal_measurable_fun,
end
noncomputable def expected_value_nnreal {Ω:Type*} {p:probability_space Ω}
(X:p →r borel nnreal):ennreal :=
@expected_value_ennreal Ω p (nnreal_to_ennreal_random_variable X)
class has_expectation (Ω α: Type*) (P:probability_space Ω) (M:measurable_space α) := (expectation : (P →r M) → ennreal)
notation `E[` X `]`:= has_expectation.expectation X
noncomputable instance has_expectation_nnreal {Ω:Type*} {P:probability_space Ω}:has_expectation Ω nnreal P (borel nnreal) := {
expectation := @expected_value_nnreal Ω P
}
noncomputable instance has_expectation_ennreal {Ω:Type*} {P:probability_space Ω}:has_expectation Ω ennreal P (borel ennreal) := {
expectation := @expected_value_ennreal Ω P
}
/-
I haven't wrapped my head around measure_space yet.
-/
def to_measure_space {Ω:Type*} (p:probability_space Ω):
measure_theory.measure_space Ω := probability_space.to_measure_space
lemma expected_value_ennreal_def {Ω:Type*} {P:probability_space Ω}
(X:P →r borel ennreal):E[X] = measure_theory.measure.integral (P.volume) (X.val) := rfl
lemma expected_value_ennreal_def2 {Ω:Type*} {P:probability_space Ω}
(X:P →r borel ennreal):E[X] = measure_theory.lintegral P.volume(X.val) := rfl
lemma expected_value_nnreal_def {Ω:Type*} {P:probability_space Ω}
(X:P →r borel nnreal):E[X] = @expected_value_ennreal Ω P (nnreal_to_ennreal_random_variable X) := rfl
lemma expected_value_nnreal_def2 {Ω:Type*} {P:probability_space Ω}
(X:P →r borel nnreal):E[X] = measure_theory.lintegral P.volume
(λ (ω:Ω), ((X.val ω):ennreal)) := rfl
lemma expected_value_nnreal_def3 {Ω:Type*} {P:probability_space Ω}
(X:P →r borel nnreal):E[X] = E[(nnreal_to_ennreal_random_variable X)] := rfl
lemma expected_value_nnreal_def4 {Ω:Type*} {P:probability_space Ω}
(X:P →r borel nnreal):E[X] = @expected_value_nnreal Ω P X := rfl
lemma expectation_add_ennreal {Ω:Type*} {p:probability_space Ω}
(X Y:p →r borel ennreal):E[X + Y] = E[X] + E[Y] :=
begin
repeat {rw expected_value_ennreal_def2},
rw ennreal_measurable_fun_add_val_def,
have A1:@measure_theory.lintegral Ω _ p.volume (X.val + Y.val)=
(@measure_theory.lintegral Ω _ p.volume (λ a, X.val a + Y.val a)),
{
refl,
},
rw A1,
rw @measure_theory.lintegral_add Ω (probability_space.to_measurable_space Ω) p.volume X.val Y.val,
apply X.property,
apply Y.property,
end
lemma decidable_subst (P Q:Prop):(P↔ Q) → decidable P → decidable Q :=
begin
intros A1 A2,
rw ← A1,
apply A2,
end
lemma decidable_subst2 (P Q:Prop):(Q↔ P) → decidable P → decidable Q :=
begin
intros A1 A2,
rw A1,
apply A2,
end
noncomputable def max_rv
{α β:Type*}
{P:probability_space α} {Mβ:measurable_space β}
[L:measurable_linear_order β] [D:decidable_linear_order β]
(X Y:random_variable P Mβ):random_variable P Mβ :=
if_random_variable (X ≤ᵣ Y) (classical.decidable_pred (X ≤ᵣ Y).val) Y X
noncomputable def min_rv
{α β:Type*}
{P:probability_space α} {Mβ:measurable_space β}
[L:measurable_linear_order β] [D:decidable_linear_order β]
(X Y:random_variable P Mβ):random_variable P Mβ :=
if_random_variable (X ≤ᵣ Y) (classical.decidable_pred (X ≤ᵣ Y).val) X Y
noncomputable def absolute_nnreal {Ω:Type*} {P:probability_space Ω} (X:random_variable P (borel ℝ)):random_variable P (borel nnreal) :=
@measurable_fun_nnreal_of_measurable_fun_real Ω (probability_space.to_measurable_space Ω) (real_abs_fun ∘r X)
lemma absolute_nnreal_val_def {Ω:Type*} {P:probability_space Ω} (X:random_variable P (borel ℝ)):
(absolute_nnreal X).val = nnreal.of_real ∘ (@abs ℝ _) ∘ X.val :=
begin
unfold absolute_nnreal,
rw measurable_fun_nnreal_of_measurable_fun_real_val_def,
rw rv_compose_val_def,
rw real_abs_fun_val_def,
end
noncomputable def pos_nnreal {Ω:Type*} {P:probability_space Ω} (X:random_variable P (borel ℝ)):random_variable P (borel nnreal) :=
@measurable_fun_nnreal_of_measurable_fun_real Ω (probability_space.to_measurable_space Ω) X
lemma pos_nnreal_val_def {Ω:Type*} {P:probability_space Ω} (X:random_variable P (borel ℝ)):
(pos_nnreal X).val = nnreal.of_real ∘ X.val :=
begin
unfold pos_nnreal,
rw measurable_fun_nnreal_of_measurable_fun_real_val_def,
end
noncomputable def neg_nnreal {Ω:Type*} {P:probability_space Ω} (X:random_variable P (borel ℝ)):random_variable P (borel nnreal) :=
@measurable_fun_nnreal_of_measurable_fun_real Ω (probability_space.to_measurable_space Ω) (-X)
lemma neg_nnreal_val_def {Ω:Type*} {P:probability_space Ω} (X:random_variable P (borel ℝ)):
(neg_nnreal X).val = nnreal.of_real ∘ (- X.val) :=
begin
unfold neg_nnreal,
rw measurable_fun_nnreal_of_measurable_fun_real_val_def,
rw real_random_variable_neg_val_def,
end
noncomputable def absolute_expected_value_real {Ω:Type*} {P:probability_space Ω} (X:random_variable P (borel ℝ)):ennreal :=
expected_value_nnreal (absolute_nnreal X)
def expected_value_exists {Ω:Type*} {p:probability_space Ω} (X:p →r borel real):Prop := (absolute_expected_value_real X) < ⊤
/- Calculate the expected value of a real random variable.
If the absolute expected value is infinite, the result is undefined. -/
noncomputable def expected_value_real_raw {Ω:Type*} {P:probability_space Ω} (X:random_variable P (borel ℝ)):real :=
ennreal.to_real (expected_value_nnreal (pos_nnreal X)) -
(ennreal.to_real (expected_value_nnreal (neg_nnreal X)))
lemma absolute_nnreal_pos_nnreal_plus_neg_nnreal {Ω:Type*} {P:probability_space Ω} (X:random_variable P (borel ℝ)):
(absolute_nnreal X) = (pos_nnreal X) + (neg_nnreal X) :=
begin
apply subtype.eq,
rw absolute_nnreal_val_def,
rw nnreal_measurable_fun_add_val_def,
-- unfold absolute_nnreal pos_nnreal neg_nnreal,
rw pos_nnreal_val_def,
rw neg_nnreal_val_def,
ext ω,
simp,
let x:ℝ := X.val ω,
begin
have A1:x = X.val ω:=rfl,
rw ← random_variable_val_eq_coe,
rw ← A1,
have A2:x ≤ 0 ∨ (0 < x) := le_or_lt x 0,
cases A2,
{
rw abs_of_nonpos,
have A3:nnreal.of_real x = 0,
{
apply nnreal.of_real_of_nonpos A2,
},
rw A3,
simp,
apply A2,
},
{
rw abs_of_pos A2,
have A3:nnreal.of_real (-x) = 0,
{
apply nnreal.of_real_of_nonpos,
apply le_of_lt,
apply neg_lt_of_pos,
apply A2,
},
{
rw A3,
simp,
},
},
end
end
noncomputable def expected_value_real {Ω:Type*} {P:probability_space Ω} (X:random_variable P (borel ℝ)):real :=
@ite (expected_value_exists X) (classical.prop_decidable (expected_value_exists X)) _ (expected_value_real_raw X) 0
/- Note that random variables do not necessarily have means or variances. In particular,
the mean (or variance) may be infinite.
TODO: make the calculation of the variance more explicit. Explicitly show that for any real
or nnreal random variable, 0≤ (X ω - E[X]) * (X ω - E[x]) (on the extended real number line). -/
def has_mean {Ω:Type*} {p:probability_space Ω} (X:p →r borel nnreal)
(μ:nnreal):Prop := E[X] = μ
noncomputable def finite_mean {Ω:Type*} {p:probability_space Ω} (X:p →r borel nnreal):nnreal
:= ennreal.to_nnreal ( E[X] )
def has_variance {Ω:Type*} {p:probability_space Ω} (X:p →r borel nnreal)
{μ:nnreal} {H:has_mean X μ} {V:nnreal}:Prop := E[X * X] - μ * μ = V
lemma indicator_measurable {Ω:Type*} [measurable_space Ω]
(E:set Ω) [D:decidable_pred E]: (is_measurable E) → measurable (λ ω:Ω, if (ω ∈ E) then (1:nnreal) else (0:nnreal)) :=
begin
intros A1,
have A2:(λ ω:Ω, if (ω ∈ E) then (1:nnreal) else (0:nnreal)) = (λ ω:Ω, if (ω ∈ E) then ((λ x:Ω, (1:nnreal)) ω) else ((λ x:Ω, (0:nnreal)) ω)),
{
refl,
},
rw A2,
apply measurable.if,
{
exact A1,
},
{
apply const_measurable,
},
{
apply const_measurable,
}
end
def indicatorh {Ω : Type*} [MΩ:measurable_space Ω]
(E:set Ω) [D:decidable_pred E] (H:is_measurable E):measurable_fun MΩ (borel nnreal) := {
val := (λ ω:Ω, if (ω ∈ E) then (1:nnreal) else (0:nnreal)),
property := @indicator_measurable Ω MΩ E D H,
}
noncomputable def indicator {Ω : Type*} {MΩ:measurable_space Ω}
(E:measurable_set MΩ):measurable_fun MΩ (borel nnreal) :=
@indicatorh Ω MΩ E.val (classical.decidable_pred E.val) E.property
lemma indicator_val_def {Ω : Type*} {MΩ:measurable_space Ω}
(E:measurable_set MΩ):(indicator E).val =
(λ ω:Ω, @ite (ω ∈ E.val) (@classical.decidable_pred Ω E.val ω) nnreal (1:nnreal) (0:nnreal)) :=
begin
refl,
end
noncomputable def indicator_rv {Ω : Type*} {P:probability_space Ω}
(E:event P):random_variable P (borel nnreal) := indicator E
def finset_sum_measurable2 {Ω β:Type*} {MΩ:measurable_space Ω}
{γ:Type*} {T:topological_space γ} {SC:topological_space.second_countable_topology γ}
{CSR:add_comm_monoid γ} {TA:has_continuous_add γ}
(S:finset β) (X:β → (measurable_fun MΩ (borel γ))):@measurable _ _ _ (borel γ) (λ ω:Ω, S.sum (λ b:β, ((X b).val ω))) :=
begin
apply finset_sum_measurable_classical,
{
apply SC,
},
{
apply TA,
},
{
intro b,
apply (X b).property,
}
end
def finset_sum_measurable_fun {Ω β:Type*} {MΩ:measurable_space Ω}
{γ:Type*} [T:topological_space γ] [SC:topological_space.second_countable_topology γ]
[CSR:add_comm_monoid γ] [TA:has_continuous_add γ]
(S:finset β) (X:β → (measurable_fun MΩ (borel γ))):measurable_fun MΩ (borel γ) := {
val := (λ ω:Ω, S.sum (λ b:β, ((X b).val ω))),
property := @finset_sum_measurable2 Ω β MΩ γ T SC CSR TA S X,
}
lemma finset_sum_measurable_fun_val_def {Ω β:Type*} {MΩ:measurable_space Ω}
{γ:Type*} [T:topological_space γ] [SC:topological_space.second_countable_topology γ]
[CSR:add_comm_monoid γ] [TA:has_continuous_add γ]
(S:finset β) (X:β → (measurable_fun MΩ (borel γ))):
(finset_sum_measurable_fun S X).val = (λ ω:Ω, S.sum (λ b:β, ((X b).val ω))) :=
begin
unfold finset_sum_measurable_fun,
end
noncomputable def count_finset {Ω β:Type*} {MΩ:measurable_space Ω}
(S:finset β) (X:β → measurable_set MΩ):MΩ →m borel nnreal :=
finset_sum_measurable_fun S (λ b:β, indicator (X b))
lemma count_finset_val_def {Ω β:Type*} {MΩ:measurable_space Ω}
(S:finset β) (X:β → measurable_set MΩ):(count_finset S X).val =
λ ω:Ω, S.sum (λ (b : β), @ite (ω ∈ (X b).val) (@classical.decidable_pred Ω (X b).val ω) nnreal 1 0) :=
begin
unfold count_finset,
rw finset_sum_measurable_fun_val_def,
ext ω,
have A1:(λ (b : β), (indicator (X b)).val ω) =
(λ b, @ite (ω ∈ (X b).val) (@classical.decidable_pred Ω (X b).val ω) nnreal 1 0),
{
ext,
rw indicator_val_def,
},
rw A1,
end
noncomputable def count_finset_rv {Ω β:Type*} {P:probability_space Ω}
(S:finset β) (X:β → event P):P →r borel nnreal :=
count_finset S X
noncomputable def count {Ω β:Type*} {MΩ:measurable_space Ω}
[F:fintype β] (X:β → measurable_set MΩ):MΩ →m borel nnreal :=
count_finset F.elems X
--Before going on, we need linearity of expectation.
--We have to either prove that the ennreal random variables are a commutative semiring, or
--just a commutative additive monoid.
---------- Lemmas that need a home -----------------------------------------------------------------
lemma supr_eq_max {α β:Type*} [complete_lattice α] {x:β} {f:β → α}:
(∀ y:β, f y ≤ f x)→ f x = supr f :=
begin
intro A1,
apply le_antisymm,
{
apply complete_lattice.le_Sup,
simp,
},
{
apply complete_lattice.Sup_le,
intros b A2,
simp at A2,
cases A2 with y A3,
rw ← A3,
apply A1,
}
end
lemma measure_theory_volume_def {Ω:Type*} {P:probability_space Ω} {S:set Ω}:@measure_theory.measure_space.volume Ω (to_measure_space P) S =
@measure_theory.measure_space.volume Ω (to_measure_space P) S := rfl
lemma measure_theory_volume_def2 {Ω:Type*}
{P:probability_space Ω} {S:set Ω}:@measure_theory.measure_space.volume Ω (to_measure_space P) S =
P.volume.measure_of S := rfl
lemma measure_theory_volume_def3 {Ω:Type*} {MΩ:measure_theory.measure_space Ω}
{S:set Ω}:@measure_theory.measure_space.volume Ω MΩ S =
@measure_theory.measure_space.volume Ω MΩ S := rfl
lemma measure_theory_volume_def4 {Ω:Type*} {MΩ:measure_theory.measure_space Ω}
{S:set Ω}:@measure_theory.measure_space.volume Ω MΩ S =
measure_theory.outer_measure.measure_of
(@measure_theory.measure_space.volume Ω MΩ).to_outer_measure S := rfl
lemma univ_eq_empty_of_not_inhabited {Ω:Type*}:(¬(∃ x:Ω,true)) →
(@set.univ Ω=∅) :=
begin
intro A1,
ext,split;intro A2,
{
exfalso,
apply A1,
apply exists.intro x,
exact true.intro,
},
{
exfalso,
apply A2,
}
end
lemma simple_func_const_cast_def {Ω:Type*} {MΩ:measurable_space Ω} (x:ennreal):
⇑(@measure_theory.simple_func.const Ω ennreal MΩ x)=λ ω:Ω, x := rfl
lemma simple_func_const_to_fun_def {Ω:Type*} {MΩ:measurable_space Ω} (x:ennreal):
(@measure_theory.simple_func.const Ω ennreal MΩ x).to_fun=λ ω:Ω, x := rfl
lemma simple_func_to_fun_eq_cast_def {Ω:Type*} {MΩ:measurable_space Ω}
(s:@measure_theory.simple_func Ω MΩ ennreal):s.to_fun = s := rfl
lemma outcome_space_inhabited {Ω:Type*}
(P:probability_space Ω):(∃ x:Ω,true) :=
begin
have A1:¬(∃ x:Ω,true) → false,
{
intro A1A,
have A1B:(@set.univ Ω=∅),
{
apply univ_eq_empty_of_not_inhabited A1A,
},
have A1C:P.volume.measure_of (@set.univ Ω)=
P.volume.measure_of (@has_emptyc.emptyc (set Ω) _),
{
rw A1B,
},
rw measure_theory.outer_measure.empty at A1C,
rw probability_space.univ_one at A1C,
simp at A1C,
exact A1C,
},
apply classical.by_contradiction A1,
end
lemma outcome_space_nonempty {Ω:Type*}
(P:probability_space Ω):nonempty Ω :=
begin
have A1:(∃ x:Ω, true) := outcome_space_inhabited P,
cases A1 with x A2,
apply nonempty.intro x,
end
lemma integral_simple_func_const {Ω:Type*}
{P:probability_space Ω}
(x:ennreal):
@measure_theory.simple_func.lintegral Ω
(P.to_measurable_space)
(@measure_theory.simple_func.const Ω ennreal (probability_space.to_measurable_space Ω) x) (P.to_measure_space.volume) = x :=
begin
unfold measure_theory.simple_func.lintegral,
have A1:(λ (x_1 : ennreal), x_1 *
@measure_theory.measure_space.volume Ω (to_measure_space P) (⇑(measure_theory.simple_func.const Ω x) ⁻¹' {x_1}))
= λ x_1:ennreal, if (x_1 = x) then x else 0,
{
ext x_1,
rw measure_theory_volume_def2,
rw simple_func_const_cast_def,
have A1A:decidable (x_1 = x),
{
apply classical.decidable_eq ennreal x_1 x,
},
cases A1A,
{
rw if_neg A1A,
have A1C:((λ (ω : Ω), x) ⁻¹' {x_1}) =∅,
{
ext ω,split;intros A1CA,
{
simp at A1CA,
exfalso,
apply A1A,
rw A1CA,
},
{
exfalso,
apply A1CA,
}
},
rw A1C,
rw measure_theory.outer_measure.empty,
simp,
},
{
rw if_pos A1A,
rw A1A,
have A1C:((λ (ω : Ω), x) ⁻¹' {x}) =set.univ,
{
ext ω,split;intros A1CA;simp,
},
rw A1C,
rw probability_space.univ_one,
simp,
},
},
rw A1,
have A3:(@measure_theory.simple_func.range Ω ennreal
(@measure_theory.measure_space.to_measurable_space Ω
(@to_measure_space Ω P))
(@measure_theory.simple_func.const Ω ennreal
(probability_space.to_measurable_space Ω) x)) = {x},
{
have A3X:nonempty Ω := outcome_space_nonempty P,
apply @measure_theory.simple_func.range_const ennreal Ω
(probability_space.to_measurable_space Ω) A3X x,
},
rw A3,
simp,
end
lemma ge_refl {α : Type*} [preorder α] (a : α): a ≥ a :=
begin
simp,
end
lemma simple_func_le_def {Ω:Type*} {MΩ:measurable_space Ω} {β:Type*}
[preorder β] (a b:(@measure_theory.simple_func Ω MΩ β)):
(a ≤ b) ↔ a.to_fun ≤ b.to_fun :=
begin
refl,
end
lemma integral_simple_func_to_fun {Ω:Type*} {MΩ:measure_theory.measure_space Ω}
(s:@measure_theory.simple_func Ω MΩ.to_measurable_space ennreal):
@measure_theory.lintegral Ω MΩ.to_measurable_space MΩ.volume
(@measure_theory.simple_func.to_fun Ω MΩ.to_measurable_space ennreal s) =
s.lintegral MΩ.volume :=
begin
rw simple_func_to_fun_eq_cast_def,
rw measure_theory.simple_func.lintegral_eq_lintegral,
end
lemma to_ennreal_rv_val_eq_simple_func {Ω:Type*} {P:probability_space Ω}
{x:ennreal}:(@to_ennreal_rv Ω P x).val =
(@measure_theory.simple_func.const Ω ennreal (probability_space.to_measurable_space Ω) x).to_fun :=
begin
rw to_ennreal_rv_val_def,
rw simple_func_const_to_fun_def,
end
lemma ennreal_expectation_const {Ω:Type*} {P:probability_space Ω}
{x:ennreal}:
E[(@to_ennreal_rv Ω P x)] = (x:ennreal) :=
begin
rw expected_value_ennreal_def2,
rw to_ennreal_rv_val_eq_simple_func,
rw integral_simple_func_to_fun,
rw integral_simple_func_const,
end
lemma ennreal_expectation_zero {Ω:Type*} {P:probability_space Ω}:
E[(0:P→r (borel ennreal))] = (0:ennreal) :=
begin
--apply ennreal_expectation_const,
rw expected_value_ennreal_def,
have A1:(0:P→r (borel ennreal)).val=λ ω:Ω, 0,
{
apply @ennreal_measurable_fun_zero_val_def Ω (probability_space.to_measurable_space Ω),
},
rw A1,
unfold measure_theory.measure.integral,
rw measure_theory.lintegral_const,
rw zero_mul,
end
lemma nnreal_zero_eq_ennreal_zero {Ω:Type*} {P:probability_space Ω}:
(@nnreal_to_ennreal_random_variable Ω P (0:P→r (borel nnreal))) =
(0:P→r (borel ennreal)) :=
begin
apply subtype.eq,
rw nnreal_to_ennreal_random_variable_val_def,
refl,
end
lemma expectation_zero {Ω:Type*} {P:probability_space Ω}:
E[(0:P→r (borel nnreal))] = (0:ennreal) :=
begin
rw expected_value_nnreal_def3,
rw nnreal_zero_eq_ennreal_zero,
apply ennreal_expectation_zero,
end
lemma to_nnreal_rv_eq_to_ennreal_rv {Ω:Type*} {P:probability_space Ω}
{x:nnreal}:
(@nnreal_to_ennreal_random_variable Ω P (to_nnreal_rv x)) =
(to_ennreal_rv (x:ennreal)) :=
begin
apply subtype.eq,
rw nnreal_to_ennreal_random_variable_val_def,
refl,
end
lemma nnreal_expectation_const {Ω:Type*} {P:probability_space Ω}
(x:nnreal):
E[(@to_nnreal_rv Ω P x)] = (x:ennreal) :=
begin
rw expected_value_nnreal_def3,
rw to_nnreal_rv_eq_to_ennreal_rv,
rw ennreal_expectation_const,
end
/-
lemma ennreal_expectation_prod {Ω:Type*} {P:probability_space Ω}
(X Y:P →r (borel ennreal)):E[X * Y] = E[X] * E[Y]
-/
lemma finset_sum_measurable_fun_zero {Ω β:Type*} {P:probability_space Ω}
(X:β → P →r (borel nnreal)):
(finset_sum_measurable_fun ∅ (λ (b : β), (X b))) = (0:P→r (borel nnreal)) :=
begin
unfold finset_sum_measurable_fun,
simp,
refl,
end
lemma finset_sum_measurable_fun_insert {Ω β:Type*} [decidable_eq β]
{P:probability_space Ω}
{a:β} {S:finset β} (X:β → P →r (borel nnreal)):(a∉ S) →
(finset_sum_measurable_fun (insert a S) (λ (b : β), (X b))) =
(X a) + (finset_sum_measurable_fun S (λ (b : β), (X b))) :=
begin
intros A1,
apply subtype.eq,
rw finset_sum_measurable_fun_val_def,
rw nnreal_measurable_fun_add_val_def,
rw finset_sum_measurable_fun_val_def,
ext ω,
rw finset.sum_insert,
refl,
exact A1,
end
lemma lift_add_nnreal_random_variable {Ω:Type*} {p:probability_space Ω}
(X Y:p →r borel nnreal):
nnreal_to_ennreal_random_variable (X + Y) = (nnreal_to_ennreal_random_variable X) +
(nnreal_to_ennreal_random_variable Y) :=
begin
apply subtype.eq,
rw ennreal_measurable_fun_add_val_def,
rw nnreal_to_ennreal_random_variable_val_def,
rw nnreal_to_ennreal_random_variable_val_def,
rw nnreal_to_ennreal_random_variable_val_def,
rw nnreal_measurable_fun_add_val_def,
have A1:(λ (ω : Ω), (((X.val + Y.val) ω):ennreal))=(λ (ω : Ω), ((X.val ω):ennreal) + ((Y.val ω):ennreal)),
{
ext ω,
simp,
},
rw A1,
refl,
end
lemma expectation_add_nnreal {Ω:Type*} {p:probability_space Ω}
(X Y:p →r borel nnreal):E[X + Y] = E[X] + E[Y] :=
begin
rw expected_value_nnreal_def,
rw lift_add_nnreal_random_variable,
apply expectation_add_ennreal,
end
lemma finset_sum_measurable_fun_linear {Ω β:Type*} {P:probability_space Ω}
(S:finset β) [D:decidable_eq β] (X:β → P →r (borel nnreal)):
E[(finset_sum_measurable_fun S (λ (b : β), (X b)))] =
finset.sum S (λ (k : β), E[X k]) :=
begin
apply finset.induction_on S,
{
rw finset_sum_measurable_fun_zero,
simp,
rw expectation_zero,
},
{
intros a s A1 A2,
rw finset_sum_measurable_fun_insert,
rw finset.sum_insert,
rw expectation_add_nnreal,
rw A2,
exact A1,
exact A1,
}
end
noncomputable def ennreal.has_zero:has_zero ennreal := infer_instance
lemma indicator_eq_simple_func {Ω:Type*} {P:probability_space Ω}
{S:event P}:
(@nnreal_to_ennreal_random_variable Ω P (@indicator Ω (probability_space.to_measurable_space Ω) S)).val =
(@measure_theory.simple_func.restrict Ω ennreal (probability_space.to_measurable_space Ω) ennreal.has_zero
(@measure_theory.simple_func.const Ω ennreal (probability_space.to_measurable_space Ω) 1) S.val) :=
begin
ext ω,
rw nnreal_to_ennreal_random_variable_val_def,
rw indicator_val_def,
rw measure_theory.simple_func.restrict_apply,
rw measure_theory.simple_func.const_apply,
simp,
apply S.property,
end
lemma restrict_univ {Ω:Type*} {MΩ:measurable_space Ω}
(s:@measure_theory.simple_func Ω MΩ ennreal):
(@measure_theory.simple_func.restrict Ω ennreal MΩ ennreal.has_zero
s
(@set.univ Ω))=s :=
begin
ext ω,
simp,
end
lemma simple_func_preimage_empty_of_notin_range {Ω:Type*} {MΩ:measurable_space Ω}
{f:@measure_theory.simple_func Ω MΩ ennreal}
{x:ennreal}:(x∉ f.range) → ⇑f ⁻¹' {x}=∅ :=
begin
intro A1,
unfold measure_theory.simple_func.range at A1,
ext ω,split;intro A2,
{
exfalso,
apply A1,
rw ← simple_func_to_fun_eq_cast_def at A2,
simp,
apply exists.intro ω,
simp at A2,
exact A2,
},
{
exfalso,
apply A2,
}
end
lemma simple_func_integral_superset {Ω:Type*} {MΩ:measure_theory.measure_space Ω}
{f:@measure_theory.simple_func Ω MΩ.to_measurable_space ennreal}
{S:finset ennreal}:f.range ⊆ S →
f.lintegral MΩ.volume = S.sum (λ x, x * measure_theory.measure_space.volume (f ⁻¹' {x})) :=
begin
intro A1,
unfold measure_theory.simple_func.lintegral,
apply finset.sum_subset A1,
intros x A2 A3,
have A4:⇑f ⁻¹' {x}=∅,
{
apply simple_func_preimage_empty_of_notin_range A3,
},
rw A4,
rw measure_theory_volume_def4,
rw measure_theory.outer_measure.empty,
simp,
end
lemma restrict_range_subseteq {Ω:Type*} {MΩ:measurable_space Ω}
(s:@measure_theory.simple_func Ω MΩ ennreal)
(S:measurable_set MΩ):
(@measure_theory.simple_func.range Ω ennreal
MΩ
(@measure_theory.simple_func.restrict Ω ennreal MΩ ennreal.has_zero
s
(@subtype.val (set Ω) (@measurable_space.is_measurable Ω MΩ) (S)))) ⊆
{0} ∪ (s.range) :=
begin
simp,
rw finset.subset_iff,
intros x A1,
simp,
simp at A1,
cases A1 with ω A2,
rw ← measurable_set_val_eq_coe at A2,
rw @measure_theory.simple_func.restrict_apply Ω ennreal MΩ ennreal.has_zero s S.val
S.property at A2,
cases classical.em (ω ∈ S.val) with A3 A3,
{
right,
apply exists.intro ω,
rw if_pos at A2,
exact A2,
exact A3,
},
{
left,
rw if_neg at A2,
rw A2,
exact A3,
}
end
lemma integral_simple_func_restrict_const {Ω:Type*}
{P:probability_space Ω} {S:event P}
(x:ennreal):
(x≠ 0) →
(@measure_theory.simple_func.lintegral Ω
(probability_space.to_measurable_space Ω)
(@measure_theory.simple_func.restrict Ω ennreal (probability_space.to_measurable_space Ω) ennreal.has_zero
(@measure_theory.simple_func.const Ω ennreal (probability_space.to_measurable_space Ω) x) S.val)
P.volume)
= x * (P.volume.measure_of (S.val)) :=
begin
intro AX,
have A1:(λ (x_1 : ennreal), x_1 *
@measure_theory.measure_space.volume Ω (to_measure_space P)
(⇑(@measure_theory.simple_func.restrict Ω ennreal (probability_space.to_measurable_space Ω) ennreal.has_zero
(@measure_theory.simple_func.const Ω ennreal (probability_space.to_measurable_space Ω) x) S.val) ⁻¹' {x_1}))
= λ x_1:ennreal, if (x_1 = x) then x * (P.volume.measure_of S.val) else 0,
{
ext x_1,
rw measure_theory_volume_def2,
have A1X:decidable (x_1 = 0),
{
apply classical.decidable_eq ennreal x_1 0,
},
cases A1X,
{
rw measure_theory.simple_func.restrict_preimage,
have A1A:decidable (x_1 = x),
{
apply classical.decidable_eq ennreal x_1 x,
},
cases A1A,
{
rw if_neg A1A,
have A1C:⇑(@measure_theory.simple_func.const Ω ennreal (probability_space.to_measurable_space Ω) x) ⁻¹' {x_1} =∅,
{
ext ω,split;intros A1CA,
{
simp at A1CA,
exfalso,
apply A1A,
rw A1CA,
},
{
exfalso,
apply A1CA,
}
},
rw A1C,
simp,
},
{
rw if_pos A1A,
rw A1A,
have A1C:⇑(@measure_theory.simple_func.const Ω ennreal (probability_space.to_measurable_space Ω) x) ⁻¹' {x} =set.univ,
{
ext ω,split;intros A1CA;simp,
},
rw A1C,
simp,
},
apply S.property,
simp,
intro A1D,
apply A1X,
rw A1D,
},
{
rw A1X,
simp,
have A1E:¬ (0 = x),
{
intro A1E1,
apply AX,
rw A1E1,
},
rw if_neg,
simp,
intro A1E1,
apply AX,
rw A1E1,
},
},
have B1:(@measure_theory.simple_func.range Ω ennreal
(@measure_theory.measure_space.to_measurable_space Ω (@to_measure_space Ω P))
(@measure_theory.simple_func.restrict Ω ennreal (probability_space.to_measurable_space Ω) ennreal.has_zero
(@measure_theory.simple_func.const Ω ennreal (probability_space.to_measurable_space Ω) x)
(@subtype.val (set Ω) (@measurable_space.is_measurable Ω (probability_space.to_measurable_space Ω)) (S)))) ⊆
{0,x},
{
apply set.subset.trans,
apply restrict_range_subseteq,
have B1A:nonempty Ω := outcome_space_nonempty P,
rw @measure_theory.simple_func.range_const ennreal Ω (probability_space.to_measurable_space Ω) B1A x,
simp,
},
rw @simple_func_integral_superset Ω (@to_measure_space Ω P)
(@measure_theory.simple_func.restrict Ω ennreal (probability_space.to_measurable_space Ω) ennreal.has_zero
(@measure_theory.simple_func.const Ω ennreal (probability_space.to_measurable_space Ω) x)
(@subtype.val (set Ω) (@measurable_space.is_measurable Ω (probability_space.to_measurable_space Ω)) (S)))
{0,x} B1,
rw A1,
simp,
end
lemma indicator_expectation_set {Ω:Type*} {P:probability_space Ω}
{S:event P}:E[(indicator S)] = (@event_prob Ω P S) :=
begin
rw expected_value_nnreal_def3,
rw expected_value_ennreal_def2,
rw @indicator_eq_simple_func Ω P S,
rw measure_theory.simple_func.lintegral_eq_lintegral,
rw integral_simple_func_restrict_const,
{
simp,
rw event_prob_def,
rw ← event_val_eq_coe,
refl,
},
apply one_ne_zero,
end
lemma indicator_expectation_event {Ω:Type*} {P:probability_space Ω}
{S:event P}:E[(indicator S)] = Pr[S] :=
begin
rw indicator_expectation_set,
end
---------- Unproven lemmas, all focusing on trying to get the PAC bound. ---------------------------
lemma ennreal_generate_from:(borel ennreal) = measurable_space.generate_from
{s | ∃a, s = {b | a < b} ∨ s = {b | b < a}} :=
begin
apply borel_eq_generate_from_of_subbasis,
refl,
end
lemma generate_measurable_iff_is_measurable {Ω:Type*} (B:set (set Ω))
(U:set Ω):
measurable_space.generate_measurable B
U ↔ @is_measurable Ω (measurable_space.generate_from B) U :=
begin
unfold is_measurable,
unfold measurable_space.generate_from,
end
lemma ennreal_is_measurable_of_generate_measurable (U:set ennreal):
measurable_space.generate_measurable {s:set ennreal | ∃a, s = {b | a < b} ∨ s = {b | b < a}}
U ↔ is_measurable U :=
begin
have A1:is_measurable U =
@is_measurable ennreal (borel ennreal) U := rfl,
rw A1,
rw ennreal_generate_from,
rw generate_measurable_iff_is_measurable,
end
lemma Iio_empty:@set.Iio ennreal _ 0 = ∅ :=
begin
unfold set.Iio,
simp,
end
lemma Ioi_empty:@set.Ioi ennreal _ ⊤ = ∅ :=
begin
unfold set.Ioi,
simp,
end
lemma Iio_in_ennreal_subbasis {t:ennreal}:
(set.Iio t) ∈ {s:set ennreal| ∃a, s = {b | a < b} ∨ s = {b | b < a}} :=
begin
simp,
apply exists.intro t,
right,
refl,
end
lemma Ioi_in_ennreal_subbasis {t:ennreal}:
(set.Ioi t) ∈ {s:set ennreal| ∃a, s = {b | a < b} ∨ s = {b | b < a}} :=
begin
simp,
apply exists.intro t,
left,
refl,
end
lemma Iic_compl_Ioi {α : Type*} [linear_order α] {a:α}:
(set.Iic a)=(set.Ioi a)ᶜ :=
begin
unfold set.Iic,
unfold set.Ioi,
ext,split;intro A1;simp;simp at A1;apply A1,
end
lemma Ici_compl_Iio {α : Type*} [linear_order α] {a:α}:
(set.Ici a)=(set.Iio a)ᶜ :=
begin
unfold set.Ici,
unfold set.Iio,
ext,split;intro A1;simp;simp at A1;apply A1,
end
lemma ennreal_is_measurable_Iic {a:ennreal}:is_measurable (set.Iic a) :=
begin
rw ← ennreal_is_measurable_of_generate_measurable,
have A1:(set.Iic a)=(set.Ioi a)ᶜ := Iic_compl_Ioi,
rw A1,
apply measurable_space.generate_measurable.compl,
apply measurable_space.generate_measurable.basic,
apply Ioi_in_ennreal_subbasis,
end
lemma ennreal_is_measurable_Iio {a:ennreal}:is_measurable (set.Iio a) :=
begin
rw ← ennreal_is_measurable_of_generate_measurable,
apply measurable_space.generate_measurable.basic,
apply Iio_in_ennreal_subbasis,
end
lemma ennreal_is_measurable_Ici {a:ennreal}:is_measurable (set.Ici a) :=
begin
rw ← ennreal_is_measurable_of_generate_measurable,
have A1:(set.Ici a)=(set.Iio a)ᶜ := Ici_compl_Iio,
rw A1,
apply measurable_space.generate_measurable.compl,
apply measurable_space.generate_measurable.basic,
apply Iio_in_ennreal_subbasis,
end
lemma ennreal_is_measurable_Ioi {a:ennreal}:is_measurable (set.Ioi a) :=
begin
rw ← ennreal_is_measurable_of_generate_measurable,
apply measurable_space.generate_measurable.basic,
apply Ioi_in_ennreal_subbasis,
end
lemma ennreal_measurable_introh (f:ennreal → ennreal):
(∀ (y:ennreal),is_measurable (f ⁻¹' (set.Iio y))) →
(∀ (y:ennreal),is_measurable (f ⁻¹' (set.Ioi y))) →
measurable f :=
begin
intros A1 A2,
apply generate_from_measurable,
symmetry,
apply ennreal_generate_from,
intros B A3,
cases A3 with s A4,
cases A4,
{
rw A4,
apply A2,
},
{
rw A4,
apply A1,
},
end
lemma ennreal_measurable_intro (f:ennreal → ennreal):
(∀ (y:ennreal),y≠ 0 → is_measurable (f ⁻¹' (set.Iio y))) →
(∀ (y:ennreal),y≠ ⊤ → is_measurable (f ⁻¹' (set.Ioi y))) →
measurable f :=
begin
intros A1 A2,
apply ennreal_measurable_introh,
{
intro y,
have A3:(y = 0) ∨ (y ≠ 0) := classical.em (y=0),
cases A3,
{
rw A3,
rw Iio_empty,
simp,
},
{
apply A1,
apply A3,
}
},
{
intro y,
have A3:(y = ⊤) ∨ (y ≠ ⊤) := classical.em (y=⊤),
cases A3,
{
rw A3,
rw Ioi_empty,
simp,
},
{
apply A2,
apply A3,
}
},
end
lemma classical.double_negation_elimination {P:Prop}:¬ ¬ P → P :=
begin
intro A1,
have A2:P ∨ ¬ P := classical.em P,
cases A2,
{
exact A2,
},
{
exfalso,
apply A1,
exact A2,
}
end
lemma subset_of_not_exists_in_diff {α:Type*} {S T:set α}:(¬ (∃ a:α, a∈ T \ S))
→ (T⊆ S) :=
begin
intro A1,
rw set.subset_def,
have A2:∀ a:α, ¬ (a∈ T \ S) := forall_not_of_not_exists A1,
intros x A3,
have A4:x∉ T \ S := A2 x,
simp at A4,
apply A4 A3,
end
lemma in_notin_or_notin_in_or_eq {α:Type*} {S T:set α}:
(∃ a:α, a∈ S \ T) ∨ (∃ a:α, a∈ T \ S) ∨ S = T :=
begin
have A1:(∃ a:α, a∈ S \ T) ∨ ¬ (∃ a:α, a∈ S \ T),
{
apply classical.em,
},
have A2:(∃ a:α, a∈ T \ S) ∨ ¬ (∃ a:α, a∈ T \ S),
{
apply classical.em,
},
cases A1,
{
left,
apply A1,
},
{
cases A2,
{
right,left,
apply A2,
},
right,right,
apply set.subset.antisymm,
{
apply subset_of_not_exists_in_diff A1,
},
{
apply subset_of_not_exists_in_diff A2,
}
},
end
lemma in_notin_or_notin_in_of_ne {α:Type*} {S T:set α}:S≠ T →
((∃ a:α, a∈ S \ T) ∨ (∃ a:α, a∈ T \ S)) :=
begin
intros A1,
have A2:((∃ a:α, a∈ S \ T) ∨
(∃ a:α, a∈ T \ S) ∨ S = T )
:= in_notin_or_notin_in_or_eq,
cases A2,
{
left,
apply A2,
},
cases A2,
{
right,
apply A2,
},
{
exfalso,
apply A1,
apply A2,
}
end
--Classical.
lemma exists_notin_of_ne_set_univ {α:Type*} {S:set α}:S ≠ set.univ → (∃ x, x∉ S) :=
begin
intro A1,
have A2:((∃ a:α, a∈ S \ set.univ) ∨ (∃ a:α, a∈ set.univ \ S)) :=in_notin_or_notin_in_of_ne A1,
cases A2;cases A2 with a A3;simp at A3,
{
exfalso,
apply A3,
},
{
apply exists.intro a,
exact A3,
}
end
lemma false_of_le_of_lt {α:Type*} [linear_order α] {x y:α}:(x < y) → (y ≤ x) → false :=
begin
intros A1 A2,
apply not_le_of_lt A1,
apply A2,
end
lemma ennreal_monotone_inv (f:ennreal → ennreal) (x y:ennreal):
monotone f →
f x < f y →
x < y :=
begin
intros A1 A2,
apply classical.by_contradiction,
intro A3,
have A4:f y ≤ f x,
{
apply A1,
apply le_of_not_lt A3,
},
apply false_of_le_of_lt A2 A4,
end
lemma ennreal_monotone_bound_le_Sup (f:ennreal → ennreal) (x' y:ennreal):
monotone f →
{x:ennreal|f x < y} ≠ set.univ →
x'∈ {x:ennreal|f x < y} →
x' ≤ Sup {x:ennreal|f x < y} :=
begin
intros AX A1 A2,
have A4:(bdd_above {x:ennreal|f x < y}),
{
unfold bdd_above,
unfold upper_bounds,
have A4A:(∃ z, z∉ {x:ennreal|f x < y}),
{
apply exists_notin_of_ne_set_univ,
apply A1,
},
cases A4A with z A4B,
apply exists.intro z,
simp,
simp at A4B,
intros a A4C,
apply @le_of_lt ennreal _ a z,
apply ennreal_monotone_inv,
unfold monotone at AX,
apply AX,
apply lt_of_lt_of_le,
apply A4C,
apply A4B,
},
apply le_cSup A4,
exact A2,
end
lemma ennreal_monotone_bound_Inf_le (f:ennreal → ennreal) (x' y:ennreal):
monotone f →
{x:ennreal|y < f x} ≠ set.univ →
x'∈ {x:ennreal|y < f x} →
Inf {x:ennreal|y < f x} ≤ x' :=
begin
intros AX A1 A2,
have A4:(bdd_below {x:ennreal|y < f x}),
{
unfold bdd_below,
unfold lower_bounds,
have A4A:(∃ z, z∉ {x:ennreal|y < f x}),
{
apply exists_notin_of_ne_set_univ,
apply A1,
},
cases A4A with z A4B,
apply exists.intro z,
simp,
simp at A4B,
intros a A4C,
apply @le_of_lt ennreal _ z a,
apply ennreal_monotone_inv,
unfold monotone at AX,
apply AX,
apply lt_of_le_of_lt,
apply A4B,
apply A4C,
},
apply @cInf_le ennreal _ {x:ennreal|y < f x},
apply A4,
exact A2,
end
lemma lt_of_not_le {α:Type*} [linear_order α] {x y:α}:¬ (y≤ x) → (x < y) :=
begin
intro A1,
have A2:x≤ y,
{
apply le_of_not_le A1,
},
{
rw lt_iff_le_not_le,
apply and.intro A2 A1,
}
end
/-
Given an order topology (which is also ???), a monotone function f is
borel measurable.
First, find the image of f.
Given [0,y), find all x such that f x < y. If this is all x or none of x, then
we are done. Otherwise, since the ennreal are a
conditionally complete lattice, there exists a supremum on such x, we'll call x'.
If f x' < y, then [0,x'] is the measurable set. If f x' = y, then for any x < x',
f x < y, otherwise x' would be the supremum. Thus, [0,x') would be the open set.
A similar proof works for the preimage of (y,∞].
-/
lemma ennreal_monotone_measurable (f:ennreal → ennreal):
monotone f → measurable f :=
begin
intro A1,
apply ennreal_measurable_intro;intros y A2,
{
let S := {x:ennreal|f x < y},
begin
have B1:S = {x:ennreal|f x < y} := rfl,
have C1:f ⁻¹' (set.Iio y) = S := rfl,
rw C1,
have B2:decidable (S=set.univ),
{
apply classical.prop_decidable,
},
have B3:S.nonempty ∨ (S=∅),
{
rw or.comm,
apply set.eq_empty_or_nonempty,
},
have B4:decidable (y ≤ f (Sup S)),
{
apply classical.prop_decidable,
},
cases B2,
cases B3,
{ -- ¬S = set.univ, ¬S = ∅ ⊢ is_measurable (f ⁻¹' set.Iio y)
cases B4,
{
have B4A:f (Sup S) < y,
begin
apply lt_of_not_le,
apply B4,
end,
have B4B:S = set.Iic (Sup S),
{
rw B1,
ext z,simp;split;intros B4BA,
{
apply ennreal_monotone_bound_le_Sup,
exact A1,
apply B2,
apply B4BA,
},
{
rw ← B1 at B4BA,
have B4BB:f z ≤ f (Sup S),
{
apply A1,
apply B4BA,
},
apply lt_of_le_of_lt,
apply B4BB,
apply B4A,
}
},
rw B4B,
apply ennreal_is_measurable_Iic,
},
{
have B4A:S = set.Iio (Sup S),
{
ext,split;intro B4AB,
{
simp,
apply lt_of_le_of_ne,
{
apply ennreal_monotone_bound_le_Sup,
exact A1,
apply B2,
apply B4AB,
},
{
intro B4AD,
rw ← B4AD at B4,
simp at B4AB,
apply false_of_le_of_lt B4AB B4,
},
},
{
simp,
simp at B4AB,
apply classical.by_contradiction,
intro D1,
have D2:y≤ f x,
{
apply le_of_not_lt D1,
},
have D3:Sup S ≤ x,
{
apply cSup_le B3,
intros b D3A,
simp at D3A,
have D3B:b < x,
{
apply ennreal_monotone_inv,
apply A1,
apply lt_of_lt_of_le,
apply D3A,
apply D2,
},
apply le_of_lt D3B,
},
apply false_of_le_of_lt B4AB D3,
}
},
rw B4A,
apply ennreal_is_measurable_Iio,
}
},
{ -- S = ∅ ⊢ is_measurable (f ⁻¹' set.Iio y)
rw B3,
apply is_measurable.empty,
},
{ -- S = set.univ ⊢ is_measurable (f ⁻¹' set.Iio y)
rw B2,
apply is_measurable.univ,
},
end
},
{
let S := {x:ennreal|y < f x},
begin
have B1:S = {x:ennreal|y < f x} := rfl,
have C1:f ⁻¹' (set.Ioi y) = S := rfl,
rw C1,
have B2:decidable (S=set.univ),
{
apply classical.prop_decidable,
},
have B3:S.nonempty ∨ (S=∅),
{
rw or.comm,
apply set.eq_empty_or_nonempty,
},
have B4:decidable (f (Inf S)≤ y),
{
apply classical.prop_decidable,
},
cases B2,
cases B3,
{ -- ¬S = set.univ,¬S = ∅ ⊢ is_measurable (f ⁻¹' set.Iio y)
cases B4,
{
have B4A:y < f (Inf S),
begin
apply lt_of_not_le,
apply B4,
end,
have B4B:S = set.Ici (Inf S),
{
rw B1,
ext z,simp;split;intros B4BA,
{
apply ennreal_monotone_bound_Inf_le,
exact A1,
apply B2,
apply B4BA,
},
{
rw ← B1 at B4BA,
have B4BB:f (Inf S) ≤ f z,
{
apply A1,
apply B4BA,
},
apply lt_of_lt_of_le,
apply B4A,
apply B4BB,
}
},
rw B4B,
apply ennreal_is_measurable_Ici,
},
{
have B4A:S = set.Ioi (Inf S),
{
ext,split;intro B4AB,
{
simp,
apply lt_of_le_of_ne,
{
apply ennreal_monotone_bound_Inf_le,
exact A1,
apply B2,
apply B4AB,
},
{
intro B4AD,
rw B4AD at B4,
simp at B4AB,
apply false_of_le_of_lt B4AB B4,
},
},
{
simp,
simp at B4AB,
apply classical.by_contradiction,
intro D1,
have D2:f x ≤ y,
{
apply le_of_not_lt D1,
},
have D3:x ≤ Inf S,
{
apply le_cInf B3,
intros b D3A,
simp at D3A,
have D3B:x < b,
{
apply ennreal_monotone_inv,
apply A1,
apply lt_of_le_of_lt,
apply D2,
apply D3A,
},
apply le_of_lt D3B,
},
apply false_of_le_of_lt B4AB D3,
}
},
rw B4A,
apply ennreal_is_measurable_Ioi,
}
},
{ -- S = ∅ ⊢ is_measurable (f ⁻¹' set.Iio y)
rw B3,
apply is_measurable.empty,
},
{ -- S = set.univ ⊢ is_measurable (f ⁻¹' set.Iio y)
rw B2,
apply is_measurable.univ,
},
end
}
end
lemma ennreal_scalar_mul_monotone (k:ennreal):monotone (λ x, k * x) :=
begin
apply ennreal.mul_left_mono,
end
/-
WAIT: alternative proof. Scalar multiplication is monotone.
Given an order topology (which is also ???), a monotone function f is
borel measurable.
First, find the image of f.
Given [0,y), find all x such that f x < y. If this is all x or none of x, then
we are done. Otherwise, since the ennreal are a
conditionally complete lattice, there exists a supremum on such x, we'll call x'.
If f x' < y, then [0,x'] is the measurable set. If f x' = y, then for any x < x',
f x < y, otherwise x' would be the supremum. Thus, [0,x') would be the open set.
A similar proof works for the preimage of (y,∞].
This is the simplest way to prove that scalar multiplication is measurable.
Basically, we can consider the preimage of sets of the form
(x,∞] and [0,x), and prove that they are measurable.
The preimage of [0,0) and (∞,∞] is ∅.
1. If k = 0, then the preimage of [0,x) is set.univ. The preimage of (x,∞] is ∅.
2. If k = ∞, then the preimage of [0,x) is {0}. The preimage of (x,∞] is (0,∞].
3. Otherwise, the preimage of [0,x) is [0,x/k). The preimage of (x,∞] is (x/k,∞].
-/
lemma ennreal_scalar_mul_measurable (k:ennreal):measurable (λ x, k * x) :=
begin
apply ennreal_monotone_measurable,
apply ennreal.mul_left_mono,
end
noncomputable def ennreal_scalar_measurable_fun (k:ennreal):(borel ennreal) →m (borel ennreal) := {
val := λ x, k * x,
property := ennreal_scalar_mul_measurable k,
}
noncomputable def scalar_mul_measurable_fun {Ω:Type*} {MΩ:measurable_space Ω} (k:ennreal)
(X:MΩ →m (borel ennreal)):(MΩ →m (borel ennreal)) :=
(ennreal_scalar_measurable_fun k) ∘m X
noncomputable def scalar_mul_rv {Ω:Type*} {P:probability_space Ω}
(k:ennreal) (X:P →r (borel ennreal)):(P →r (borel ennreal)) :=
(ennreal_scalar_measurable_fun k) ∘r X
def scalar_mul_rv_val_def {Ω:Type*} {P:probability_space Ω}
(k:ennreal) (X:P →r (borel ennreal)):
(scalar_mul_rv k X).val = λ ω:Ω, k * (X.val ω) := rfl
lemma nnreal_scalar_mul_to_ennreal {Ω:Type*} (p:probability_space Ω)
(k:nnreal) (X:random_variable p (borel nnreal)):
nnreal_to_ennreal_random_variable ((to_nnreal_rv (k)) * X) = scalar_mul_rv (k:ennreal)
(nnreal_to_ennreal_random_variable X) :=
begin
apply subtype.eq,
rw scalar_mul_rv_val_def,
rw nnreal_to_ennreal_random_variable_val_def,
rw nnreal_to_ennreal_random_variable_val_def,
rw nnreal_random_variable_mul_val_def,
rw to_nnreal_rv_val_def,
simp,
end
lemma ennreal_scalar_expected_value {Ω:Type*} (p:probability_space Ω)
(k:ennreal) (X:random_variable p (borel ennreal)):
E[scalar_mul_rv k X] = k * E[X] :=
begin
rw expected_value_ennreal_def,
unfold measure_theory.measure.integral,
rw scalar_mul_rv_val_def,
rw measure_theory.lintegral_const_mul,
rw expected_value_ennreal_def,
unfold measure_theory.measure.integral,
apply X.property
end
-----Our TWO TARGET LEMMAS--------------------------------------------------------------------------
/-
Okay, here is the plan for this one, because solving this one the "right" way will take
forever.
1. First of all, we define a scalar multiplier on ennreal measurable functions and ennreal
random variables.
2. Then, we show how the cast to ennreal results in such a random variable.
3. Then, we show how such the scalar multiplier yields a scalar multiplier on the
expectation using measure_theory.lintegral_const_mul
-/
lemma scalar_expected_value {Ω:Type*} (p:probability_space Ω)
(X:random_variable p (borel nnreal)) (k:nnreal):E[X * (to_nnreal_rv (k))] = E[X] * (k:ennreal) :=
begin
rw mul_comm,
rw mul_comm _ (k:ennreal),
rw expected_value_nnreal_def,
rw nnreal_scalar_mul_to_ennreal,
apply ennreal_scalar_expected_value,
end
lemma linear_count_finset_rv {Ω β:Type*} {P:probability_space Ω}
(S:finset β) (X:β → event P):E[count_finset_rv S X] = S.sum (λ k, (Pr[X k]:ennreal)) :=
begin
unfold count_finset_rv,
unfold count_finset,
have A1:decidable_eq β := classical.decidable_eq β,
rw @finset_sum_measurable_fun_linear Ω β P S A1,
have A2:(λ (k : β), E[indicator (X k)])=(λ (k : β), ↑Pr[X k]),
{
ext k,
rw indicator_expectation_event,
},
rw A2,
end
lemma pos_nnreal_and_neg_nnreal_of_expected_value_exists {Ω:Type*} {p:probability_space Ω}
(X:p →r borel real):(expected_value_exists X) →
E[pos_nnreal X] < ⊤ ∧ E[neg_nnreal X] < ⊤:=
begin
unfold expected_value_exists,
unfold absolute_expected_value_real,
rw absolute_nnreal_pos_nnreal_plus_neg_nnreal,
rw ← expected_value_nnreal_def4,
rw expectation_add_nnreal,
intro A1,
rw with_top.add_lt_top at A1,
apply A1,
end
lemma pos_nnreal_of_expected_value_exists {Ω:Type*} {p:probability_space Ω}
(X:p →r borel real):(expected_value_exists X) →
E[pos_nnreal X] < ⊤ :=
begin
intro A1,
have A2:E[pos_nnreal X] < ⊤ ∧ E[neg_nnreal X] < ⊤,
{
apply pos_nnreal_and_neg_nnreal_of_expected_value_exists,
apply A1,
},
apply A2.left,
end
lemma neg_nnreal_of_expected_value_exists {Ω:Type*} {p:probability_space Ω}
(X:p →r borel real):(expected_value_exists X) →
E[neg_nnreal X] < ⊤ :=
begin
intro A1,
have A2:E[pos_nnreal X] < ⊤ ∧ E[neg_nnreal X] < ⊤,
{
apply pos_nnreal_and_neg_nnreal_of_expected_value_exists,
apply A1,
},
apply A2.right,
end
noncomputable def real_CDF {Ω:Type*} {p:probability_space Ω} (X:p →r borel real) (x:ℝ):nnreal :=
Pr[X ≤ᵣ x]
-------------------------------Find a home for these theorems.--------------------------------
lemma pr_empty_zero {Ω α:Type*} {p:probability_space Ω} [M:measurable_space α] {X:p →r M}
{E:@measurable_set α M}:E.val = ∅ → (X ∈r E ) = @event_empty Ω p :=
begin
intro A1,
apply event.eq,
rw rv_event_val_def,
ext ω,
rw A1,
split;intros A2,
{
simp at A2,
exfalso,
apply A2,
},
{
exfalso,
apply A2,
}
end
lemma pr_empty_zero2 {Ω α:Type*} {p:probability_space Ω} [M:measurable_space α]
{E:event p}:E = @event_empty Ω p → Pr[E] = 0 :=
begin
intro A1,
rw A1,
rw Pr_event_empty,
end
lemma pr_empty_zero3 {Ω α:Type*} {p:probability_space Ω} [M:measurable_space α] {X:p →r M}
{E:@measurable_set α M}:E.val = ∅ → Pr[X ∈r E ] = 0 :=
begin
intro A1,
apply @pr_empty_zero2 Ω α p M,
apply pr_empty_zero,
apply A1,
end
lemma random_variable_identical_ennreal
{Ω α:Type*} {p:probability_space Ω} [M:measurable_space α] {X Y:p →r M}:
(∀ E:@measurable_set α M, (Pr[X ∈r E]:ennreal) = (Pr[Y∈r E]:ennreal) ) → random_variable_identical X Y :=
begin
intro A1,
intro E,
rw ← with_top.coe_eq_coe,
apply A1,
end
/-
lemma random_variable_identical_generate_from
{Ω:Type*} {p:probability_space Ω}
{X Y:p →r (measurable_space.generate_from (set.range set.Iic))}:
real_CDF X = real_CDF Y →
(∀ E:(set ℝ), E ∈ (set.range (@set.Iic ℝ _)) →
p.μ.measure_of (set.preimage X.val E) =
p.μ.measure_of (set.preimage Y.val E)) →
@random_variable_identical Ω p ℝ (measurable_space.generate_from
(set.range (@set.Iic ℝ _))) X Y :=
begin
intros E A1,
repeat {rw ← with_top.coe_eq_coe,rw event_prob_def},
rw rv_event_val_def,
end-/
/-
In order to prove this, we need to know that S is nonempty
and closed under intersection. Then, we can use Dynkin's
theorem.
https://en.wikipedia.org/wiki/Dynkin_system
-/
lemma disjoint_preimage
{Ω α:Type*}
{X:Ω → α}
{A B:set α}
:
(A ∩ B ⊆ ∅ ) →
((set.preimage X (A)) ∩ (set.preimage X (B)) ⊆ ∅ )
:=
begin
intros A1,
rw set.subset_def,
intros ω A2,
exfalso,
simp at A2,
rw set.subset_def at A1,
have A3 := A1 (X ω),
apply A3,
simp,
apply A2,
end
lemma pairwise_disjoint_preimage
{Ω α β:Type*}
[decidable_eq β]
{X:Ω → α}
{f:β → set α}
:
(∀ (i j : β), i ≠ j → f i ∩ f j ⊆ ∅ ) →
(∀ (i j : β), i ≠ j → (set.preimage X (f i)) ∩ (set.preimage X (f j)) ⊆ ∅ )
:=
begin
intros A1 i j A2,
apply disjoint_preimage (A1 i j A2),
end
lemma measure_Union2
{Ω α:Type*} {p:probability_space Ω}
{M:measurable_space α}
{X:Ω → α}
{f:ℕ → set α}
:
(measurable X) →
(∀ (i j : ℕ), i ≠ j → f i ∩ f j ⊆ ∅ ) →
(∀ n, is_measurable (f n)) →
p.volume.measure_of (X ⁻¹' ⋃ (i : ℕ), f i)
=∑' n:ℕ, p.volume.measure_of (X ⁻¹' f n)
:=
begin
intros A1 A2 A3,
rw set.preimage_Union,
apply @measure_theory.measure_Union Ω _ measure_theory.measure_space.volume ℕ _ (λ n:ℕ, (set.preimage X (f n))),
apply pairwise_disjoint_preimage A2,
intro i,
apply measurable.preimage A1 (A3 i),
end
lemma induction_on_inter2
{α:Type*} {M:measurable_space α}
{S:set (set α)}
{P:measurable_set M → Prop}:
(M = measurable_space.generate_from S) →
(∀ t₁ t₂:(set α), t₁ ∈ S → t₂ ∈ S →
set.nonempty (t₁ ∩ t₂) →
t₁ ∩ t₂ ∈ S) →
(P ∅) →
(∀ E:measurable_set M, P E → P (Eᶜ)) →
(∀ (f : ℕ → measurable_set M),
(∀ (i j : ℕ), i ≠ j → (measurable_inter (f i) (f j)).val ⊆ ∅) →
(∀ (i : ℕ), P (f i)) → P (measurable_Union f)) →
(∀ E:measurable_set M, E.val ∈ S → P E ) →
(∀ E:measurable_set M, P E) :=
begin
intros A1 A2 B1 B2 B3 A3,
let P2 := λ T:set α, ∃ H:is_measurable T, P ⟨T, H⟩,
begin
have A4:P2 = λ T:set α, ∃ H:is_measurable T, P ⟨T, H⟩ := rfl,
have A5:(∀ T:set α, is_measurable T → P2 T),
{
apply measurable_space.induction_on_inter,
apply A1,
apply A2,
{
rw A4,
apply exists.intro is_measurable.empty,
apply B1,
},
{
intros T A5A,
rw A4,
have A5B:is_measurable T,
{
rw A1,
apply measurable_space.generate_measurable.basic,
apply A5A,
},
apply exists.intro A5B,
apply A3,
simp,
apply A5A,
},
{
intros T A5C,
rw A4,
intro A5D,
cases A5D with A5E A5F,
have A5G:= (is_measurable.compl A5E),
apply exists.intro A5G,
have A5H:(measurable_set.mk A5G)=(measurable_set.mk A5E)ᶜ,
{
unfold measurable_set.mk,
apply subtype.eq,
rw measurable_set_neg_def,
},
unfold measurable_set.mk at A5H,
rw A5H,
apply B2,
apply A5F,
},
{
intros f A5J A5K A5L,
have A5M:is_measurable (⋃ (i:ℕ), f i),
{
apply is_measurable.Union,
intro b,
apply A5K,
},
rw A4,
apply exists.intro A5M,
let g := λ (i:ℕ), @measurable_set.mk α M (f i) (A5K i),
let V := measurable_Union g,
begin
have A5N:g = λ (i:ℕ), @measurable_set.mk α M (f i) (A5K i) := rfl,
have A5O:V = measurable_Union g := rfl,
have A5P:@measurable_set.mk α M (⋃ (i:ℕ), f i) A5M = V,
{
apply subtype.eq,
rw A5O,
unfold measurable_set.mk,
simp,
rw ← measurable_set_val_eq_coe,
rw measurable_Union_val_def,
ext ω,split;intro A5PA;simp at A5PA;cases A5PA with i A5PA;simp;
apply exists.intro i;have A5PB:f i = (g i).val := rfl,
{
rw ← measurable_set_val_eq_coe,
rw ← A5PB,
apply A5PA,
},
{
rw A5PB,
apply A5PA,
},
},
unfold measurable_set.mk at A5P,
rw A5P,
rw A5O,
apply B3,
{
intros i j A5Q,
rw measurable_inter_val_def,
have A5R:(g i).val = f i := rfl,
have A5S:(g j).val = f j := rfl,
rw A5R,
rw A5S,
apply A5J,
apply A5Q,
},
{
intro i,
have A5T:=A5L i,
rw A4 at A5T,
cases A5T with A5U A5V,
have A5W:g i = ⟨f i, A5U⟩ := rfl,
rw A5W,
apply A5V,
},
end
},
},
intro E,
cases E,
have A6 := A5 E_val E_property,
rw A4 at A6,
cases A6 with A7 A8,
have A9:(⟨E_val, E_property⟩:measurable_set M) = (⟨E_val, A7⟩:measurable_set M),
{
apply subtype.eq,
refl,
},
rw A9,
apply A8,
end
end
lemma nnreal.sum_subst {β:Type*} [encodable β] {f g:β → nnreal}:(f = g) →
(∑' (b:β), f b) = (∑' (b:β), g b) :=
begin
intro A1,
rw A1,
end
lemma random_variable_identical_generate_from
{Ω α:Type*} {p:probability_space Ω}
{M:measurable_space α}
{S:set (set α)}
{X Y:p →r M}:
(M = measurable_space.generate_from S) →
(∀ (t₁ t₂ : set α), t₁ ∈ S → t₂ ∈ S → set.nonempty (t₁ ∩ t₂) → t₁ ∩ t₂ ∈ S) →
(∀ E:measurable_set M, E.val ∈ S →
Pr[X ∈r E] = Pr[Y ∈r E]) →
(∀ E:measurable_set M,
Pr[X ∈r E] = Pr[Y ∈r E]) :=
begin
intros A1 A2,
apply induction_on_inter2,
{
apply A1,
},
{
apply A2,
},
{
repeat {rw rv_event_empty},
},
{
intros E A1,
repeat {rw rv_event_compl},
repeat {rw neg_eq_not},
repeat {rw ← Pr_one_minus_eq_not},
rw A1,
},
{
intros f A3 A4,
repeat {rw rv_event_measurable_Union},
repeat {rw measurable_Union_eq_any},
repeat {rw Pr_eany_sum},
rw nnreal.sum_subst,
--rw @sum_subst ℕ _ (λ b:ℕ, Pr[X ∈r f b]),
--sorry
{
ext i,
rw A4 i,
},
apply pairwise_disjoint_preimage,
{
intros i j A5,
have A6 := A3 i j A5,
rw measurable_inter_val_def at A6,
apply A6,
},
apply pairwise_disjoint_preimage,
{
intros i j A5,
have A6 := A3 i j A5,
rw measurable_inter_val_def at A6,
apply A6,
},
},
end
-- Could rewrite this lemma using Pr instead of measure_of.
/-(∀ E:(set α), E ∈ S →
p.μ.measure_of (set.preimage X.val E) =
p.μ.measure_of (set.preimage Y.val E)) →-/
lemma random_variable_identical_generate_from2
{Ω α:Type*} {p:probability_space Ω}
{M:measurable_space α}
{S:set (set α)}
{X Y:p →r M}:
(M = measurable_space.generate_from S) →
(∀ (t₁ t₂ : set α), t₁ ∈ S → t₂ ∈ S → set.nonempty (t₁ ∩ t₂) → t₁ ∩ t₂ ∈ S) →
(∀ E:measurable_set M, E.val ∈ S →
Pr[X ∈r E] = Pr[Y ∈r E]) →
/-(∀ E:(set α), E ∈ S →
p.μ.measure_of (set.preimage X.val E) =
p.μ.measure_of (set.preimage Y.val E)) →-/
@random_variable_identical Ω p α M X Y :=
begin
intros AX A1 A2,
unfold random_variable_identical,
apply @random_variable_identical_generate_from Ω α p M S X Y AX A1 A2,
/-{
intros E A3,
have A4 := A2 (E.val) A3,
rw ← ennreal.coe_eq_coe,
repeat {rw event_prob_def},
repeat {rw rv_event_val_def},
--simp,
apply A4,
},-/
end
/-
There is no way to solve this problem. We still need unrestricted union.
However, we also need to show that unrestricted union can be broken down
into a pairwise disjoint union.
-/
lemma generate_measurable_finite_union {α:Type*} {s:set (set α)} {f:ℕ → set α} {n:ℕ}:
(∀ n:ℕ, (measurable_space.generate_measurable s (f n))) →
measurable_space.generate_measurable s (set.sUnion (set.image f {i:ℕ|i < n})) :=
begin
let g:= λ i:ℕ, if (i < n) then (f i) else ∅,
begin
intro A1,
have A2:g = λ i:ℕ, if (i < n) then (f i) else ∅ := rfl,
have A3:(⋃ j:ℕ, g j) = (set.sUnion (set.image f {i:ℕ|i < n})),
{
ext ω,split;intro A4,
{
simp at A4,
cases A4 with i A4,
rw A2 at A4,
simp at A4,
have A4A:i < n,
{
apply decidable.by_contradiction,
intro A4A1,
rw if_neg at A4,
apply A4,
apply A4A1,
},
rw if_pos at A4,
simp,
apply exists.intro i,
split,
{
apply A4A,
},
{
apply A4,
},
apply A4A,
},
{
simp at A4,
cases A4 with i A4,
simp,
apply exists.intro i,
rw A2,
simp,
rw if_pos,
apply A4.right,
apply A4.left,
},
},
rw ← A3,
apply measurable_space.generate_measurable.union,
intro i,
rw A2,
simp,
have A5:(i < n) ∨ ¬(i < n) := decidable.em (i < n),
cases A5,
{
rw if_pos A5,
apply A1,
},
{
rw if_neg A5,
apply measurable_space.generate_measurable.empty,
},
end
end
lemma set_range_Iic_closed {t₁ t₂ : set ℝ}:
t₁ ∈ set.range (@set.Iic ℝ _)→
t₂ ∈ set.range (@set.Iic ℝ _) →
set.nonempty (t₁ ∩ t₂) → t₁ ∩ t₂ ∈ set.range (@set.Iic ℝ _):=
begin
intros A1 A2 A3,
simp at A1,
cases A1 with y1 A1,
simp at A2,
cases A2 with y2 A2,
subst t₁,
subst t₂,
rw set.Iic_inter_Iic,
simp,
end
lemma set_Iic_eq_CDF {Ω:Type*} {p:probability_space Ω} {X:p →r borel real} {y:ℝ}
{E:measurable_set (borel ℝ)}:E.val = set.Iic y →
(Pr[X ∈r E] = (real_CDF X y)) :=
begin
intro A1,
unfold real_CDF,
rw ← ennreal.coe_eq_coe,
repeat {
rw event_prob_def
},
rw event_le_val_def,
rw coe_random_variable_of_real_val_def,
rw rv_event_val_def,
rw A1,
unfold set.Iic,
simp,
end
--set_option pp.implicit true
lemma real.is_measurable_Iic (x:ℝ):is_measurable (set.Iic x) :=
begin
rw real_measurable_space_def,
apply is_measurable_Iic,
end
lemma real.is_measurable_Ioc (x y:ℝ):is_measurable (set.Ioc x y) :=
begin
rw real_measurable_space_def,
apply is_measurable_Ioc,
end
lemma real_CDF_identical {Ω:Type*} {p:probability_space Ω}
{X Y:p →r borel real}:
((real_CDF X) = (real_CDF Y)) → random_variable_identical X Y :=
begin
intro A1,
have A2:borel ℝ = measurable_space.generate_from (set.range set.Iic),
{
apply borel_eq_generate_Iic,
},
apply random_variable_identical_generate_from2 A2,
apply set_range_Iic_closed,
intros E A3,
simp at A3,
cases A3 with y A3,
have A4:E.val = set.Iic y,
{
rw A3,
rw measurable_set_val_eq_coe,
},
repeat {rw set_Iic_eq_CDF A4},
rw A1,
end
noncomputable def real_joint_CDF {Ω:Type*} {p:probability_space Ω} (X:p →r borel real) (Y:p →r borel real) (x y:ℝ):nnreal :=
Pr[(X ≤ᵣ x) ∧ₑ (Y ≤ᵣ y)]
def measurable_set.Iic (x:ℝ):measurable_set (borel ℝ) := {
val := set.Iic x,
property := real.is_measurable_Iic x,
}
def measurable_set.Ioc (x y:ℝ):measurable_set (borel ℝ) := {
val := set.Ioc x y,
property := real.is_measurable_Ioc x y,
}
lemma measurable_set.Iic_val_def {x:ℝ}:
(measurable_set.Iic x).val = set.Iic x := rfl
lemma measurable_set.Ioc_val_def {x y:ℝ}:
(measurable_set.Ioc x y).val = set.Ioc x y := rfl
noncomputable def real_joint_set (x y:ℝ):
measurable_set ((borel real) ×m (borel real)) :=
prod_measurable_set (measurable_set.Iic x)
(measurable_set.Iic y)
lemma mem_real_measurable_set_Iic_def {Ω:Type*} {p:probability_space Ω} (X:p →r borel real) (x:ℝ):X ∈r (measurable_set.Iic x) = X ≤ᵣ x :=
begin
apply event.eq,
rw rv_event_val_def,
rw measurable_set.Iic_val_def,
rw event_le_val_def,
unfold set.Iic,
simp,
rw ← random_variable_val_eq_coe,
rw ← random_variable_val_eq_coe,
rw coe_random_variable_of_real_val_def,
end
lemma real_joint_CDF_alt {Ω:Type*} {p:probability_space Ω} (X:p →r borel real) (Y:p →r borel real) (x y:ℝ):
real_joint_CDF X Y x y =
Pr[(X ×r Y) ∈r real_joint_set x y] :=
begin
unfold real_joint_set,
rw mem_prod_random_variable_prod_measurable_set,
unfold real_joint_CDF,
repeat {rw mem_real_measurable_set_Iic_def},
end
lemma prod_set_Iic_eq_CDF {Ω:Type*} {p:probability_space Ω}
{X:p →r borel real} {x:ℝ}
{Y:p →r borel real} {y:ℝ}
{E:measurable_set (borel ℝ ×m borel ℝ)}:
E.val = set.prod (set.Iic x) (set.Iic y) →
(Pr[(X ×r Y) ∈r E] = (real_joint_CDF X Y x y)) :=
begin
intro A1,
rw real_joint_CDF_alt,
rw ← ennreal.coe_eq_coe,
unfold real_joint_set,
repeat {
rw event_prob_def,
rw rv_event_val_def
},
rw A1,
rw prod_measurable_set_val_def,
repeat {rw measurable_set.Iic_val_def},
end
lemma real.Iic_covers:set.sUnion (set.range (λ n:ℕ,set.Iic (n:ℝ))) = set.univ :=
begin
ext x,split;intro A1,
{
apply set.mem_univ,
},
{
simp,
have A2 := exists_nat_gt x,
cases A2 with i A2,
apply exists.intro i,
apply le_of_lt,
apply A2,
},
end
lemma set.mem_range_elim {α β:Type*} {f:α → β} {b:β}:
b∈ set.range f →
∃ a:α, f a = b :=
begin
intro A1,
simp at A1,
apply A1,
end
lemma prod_borel_R_eq_Iic:
(borel ℝ) ×m (borel ℝ) = measurable_space.generate_from
{S|∃ x y:ℝ, S = set.prod (set.Iic x) (set.Iic y)} :=
begin
repeat {rw borel_eq_generate_Iic},
unfold prod_space,
have A1:set.countable (set.range (λ n:ℕ,set.Iic (n:ℝ))),
{
apply set.countable_range,
},
have A2:(set.range (λ n:ℕ,set.Iic (n:ℝ))) ⊆ set.range set.Iic,
{
rw set.subset_def,
intros S A2A,
simp at A2A,
simp,
cases A2A with y A2A,
apply exists.intro (y:ℝ),
apply A2A,
},
have A3:set.sUnion (set.range (λ n:ℕ,set.Iic (n:ℝ))) = set.univ :=
real.Iic_covers,
rw @prod_measurable_space_def2 _ _ _ _ (set.range (λ n:ℕ,set.Iic (n:ℝ)))
(set.range (λ n:ℕ,set.Iic (n:ℝ))) A1 A1 A2 A2 A3 A3,
have A4:
{U : set (ℝ × ℝ) | ∃ (A ∈ set.range (@set.Iic ℝ _)),
∃ (B ∈ set.range (@set.Iic ℝ _)),
U = set.prod A B} =
{S : set (ℝ × ℝ) | ∃ (x y : ℝ), S =
set.prod (@set.Iic ℝ _ x) (@set.Iic ℝ _ y)},
{
ext p;split;intro A4A;simp,
{
cases A4A with A A4A,
cases A4A with A4A A4B,
cases A4B with B A4B,
cases A4B with A4B A4C,
subst p,
--cases A4A with x A4A,
--unfold set.range at A4A,
have A4D := @set.mem_range_elim (ℝ) (set ℝ) (set.Iic) A A4A,
cases A4D with x A4D,
apply exists.intro x,
have A4E := @set.mem_range_elim (ℝ) (set ℝ) (set.Iic) B A4B,
cases A4E with y A4E,
apply exists.intro y,
rw A4D,
rw A4E,
},
{
simp at A4A,
apply A4A,
},
},
rw A4,
end
lemma prod_set_range_Iic_closed {t₁ t₂ : set (ℝ × ℝ)}:
t₁ ∈ {S : set (ℝ × ℝ) | ∃ (x y : ℝ), S = set.prod (set.Iic x) (set.Iic y)} →
t₂ ∈ {S : set (ℝ × ℝ) | ∃ (x y : ℝ), S = set.prod (set.Iic x) (set.Iic y)} →
set.nonempty (t₁ ∩ t₂) →
t₁ ∩ t₂ ∈ {S : set (ℝ × ℝ) | ∃ (x y : ℝ), S = set.prod (set.Iic x) (set.Iic y)} :=
begin
intros A1 A2 A3,
cases A1 with x1 A1,
cases A1 with y1 A1,
subst t₁,
cases A2 with x2 A2,
cases A2 with y2 A2,
subst t₂,
rw set.prod_inter_prod,
repeat {rw set.Iic_inter_Iic},
simp,
apply exists.intro (x1 ⊓ x2),
apply exists.intro (y1 ⊓ y2),
refl,
end
lemma real_joint_CDF_identical {Ω:Type*} {p:probability_space Ω}
{X1 X2 Y1 Y2:p →r borel real}:
((real_joint_CDF X1 X2) = (real_joint_CDF Y1 Y2)) →
random_variable_identical (X1 ×r X2) (Y1 ×r Y2) :=
begin
intro A1,
have A2:= prod_borel_R_eq_Iic,
apply random_variable_identical_generate_from2 A2,
apply prod_set_range_Iic_closed,
intros E A3,
simp at A3,
cases A3 with x A3,
cases A3 with y A3,
repeat {rw prod_set_Iic_eq_CDF A3},
rw A1,
end
lemma is_measurable.countable {S:set ℝ}:set.countable S → is_measurable S :=
begin
intro A1,
have A2:S = (set.sUnion (set.image singleton S)),
{
simp,
},
rw A2,
apply is_measurable.sUnion,
apply set.countable.image,
apply A1,
intro t,
intro A3,
simp at A3,
cases A3 with x A3,
cases A3 with A3 A4,
subst t,
apply is_measurable_singleton,
end
def measurable_set.of_countable (S:set ℝ) (H:set.countable S):measurable_set (borel ℝ) := {
val := S,
property := is_measurable.countable H,
}
--The concept of a countable support for a probability mass function is unclear. There are two interpretations.
--For instance, one could consider the concept of a support in a borel space.
--One can construct a distribution over all decimal numbers between 0 and 1, such that the support is the range
--[0,1]. However, there exists a countable set with measure 1 for this distribution as well.
--Thus, we focus on the question of whether a set is countable and has probability 1.
def is_countable_support {Ω:Type*} {p:probability_space Ω} (X:p →r borel ℝ) (S:set ℝ):Prop :=
∃ (H:set.countable S), Pr[X ∈r (measurable_set.of_countable S H)] = 1
def is_discrete_random_variable {Ω:Type*} {p:probability_space Ω} (X:p →r borel ℝ):Prop := ∃ (S:set ℝ), is_countable_support X S
def is_probability_mass_function {Ω:Type*} {p:probability_space Ω} (X:p →r borel ℝ) {S:set ℝ} (f:{x // x ∈ S} → nnreal):Prop :=
(set.countable S) ∧
(∀ E:measurable_set (borel ℝ), has_sum f (Pr[X∈r E]))
def is_absolutely_continuous_wrt
{Ω:Type*} {M:measurable_space Ω} (μ ν:measure_theory.measure Ω):Prop :=
∀ A:set Ω, is_measurable A → (ν A = 0) → (μ A = 0)
def measure_zero_of_is_absolutely_continuous_wrt
{Ω:Type*} {M:measurable_space Ω} (μ ν:measure_theory.measure Ω) (A:set Ω):
is_absolutely_continuous_wrt μ ν →
is_measurable A → (ν A = 0) → (μ A = 0) :=
begin
intros A1 A2 A3,
unfold is_absolutely_continuous_wrt at A1,
apply A1 A A2 A3,
end
--#check random_variable_independent_pair
/-
Proving this will make a lot of stuff a lot easier. The nnreals can follow directly.
lemma ennreal.expectation_mul_independent {Ω:Type*} {P:probability_space Ω} {X Y:P →r (borel ennreal)}:
random_variable_independent_pair X Y → E[X * Y] = E[X] * E[Y] :=
begin
end
-/
|
11b984b418d4abac540bd08dbd8e903f92ee7d80 | 9b9a16fa2cb737daee6b2785474678b6fa91d6d4 | /src/linear_algebra/basis.lean | 9af256c5f145119b962fc061edfa8b2f21ec662d | [
"Apache-2.0"
] | permissive | johoelzl/mathlib | 253f46daa30b644d011e8e119025b01ad69735c4 | 592e3c7a2dfbd5826919b4605559d35d4d75938f | refs/heads/master | 1,625,657,216,488 | 1,551,374,946,000 | 1,551,374,946,000 | 98,915,829 | 0 | 0 | Apache-2.0 | 1,522,917,267,000 | 1,501,524,499,000 | Lean | UTF-8 | Lean | false | false | 28,447 | 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
Linear independence and basis sets in a module or vector space.
This file is inspired by Isabelle/HOL's linear algebra, and hence indirectly by HOL Light.
We define the following concepts:
* `linear_independent α s`: states that `s` are linear independent
* `linear_independent.repr s b`: choose the linear combination representing `b` on the linear
independent vectors `s`. `b` should be in `span α b` (uses classical choice)
* `is_basis α s`: if `s` is a basis, i.e. linear independent and spans the entire space
* `is_basis.repr s b`: like `linear_independent.repr` but as a `linear_map`
* `is_basis.constr s g`: constructs a `linear_map` by extending `g` from the basis `s`
-/
import linear_algebra.linear_combination order.zorn
noncomputable theory
open function lattice set submodule
local attribute [instance] classical.prop_decidable
variables {α : Type*} {β : Type*} {γ : Type*} {δ : Type*}
section module
variables [ring α] [add_comm_group β] [add_comm_group γ] [add_comm_group δ]
variables [module α β] [module α γ] [module α δ]
variables {a b : α} {s t : set β} {x y : β}
include α
variables (α)
/-- Linearly independent set of vectors -/
def linear_independent (s : set β) : Prop :=
disjoint (lc.supported α s) (lc.total α β).ker
variables {α}
theorem linear_independent_iff : linear_independent α s ↔
∀l ∈ lc.supported α s, lc.total α β l = 0 → l = 0 :=
by simp [linear_independent, linear_map.disjoint_ker]
theorem linear_independent_iff_total_on : linear_independent α s ↔ (lc.total_on α s).ker = ⊥ :=
by rw [lc.total_on, linear_map.ker, linear_map.comap_cod_restrict, map_bot, comap_bot,
linear_map.ker_comp, linear_independent, disjoint, ← map_comap_subtype, map_le_iff_le_comap,
comap_bot, ker_subtype, le_bot_iff]
lemma linear_independent_empty : linear_independent α (∅ : set β) :=
by simp [linear_independent]
lemma linear_independent.mono (h : t ⊆ s) : linear_independent α s → linear_independent α t :=
disjoint_mono_left (lc.supported_mono h)
lemma linear_independent.unique (hs : linear_independent α s) {l₁ l₂ : lc α β} :
l₁ ∈ lc.supported α s → l₂ ∈ lc.supported α s →
lc.total α β l₁ = lc.total α β l₂ → l₁ = l₂ :=
linear_map.disjoint_ker'.1 hs _ _
lemma zero_not_mem_of_linear_independent (ne : 0 ≠ (1:α)) (hs : linear_independent α s) : (0:β) ∉ s :=
λ h, ne $ eq.symm begin
suffices : (finsupp.single 0 1 : lc α β) 0 = 0, {simpa},
rw disjoint_def.1 hs _ (lc.single_mem_supported 1 h),
{refl}, {simp}
end
lemma linear_independent_union {s t : set β}
(hs : linear_independent α s) (ht : linear_independent α t)
(hst : disjoint (span α s) (span α t)) : linear_independent α (s ∪ t) :=
begin
rw [linear_independent, disjoint_def, lc.supported_union],
intros l h₁ h₂, rw mem_sup at h₁,
rcases h₁ with ⟨ls, hls, lt, hlt, rfl⟩,
rw [span_eq_map_lc, span_eq_map_lc] at hst,
have : lc.total α β ls ∈ map (lc.total α β) (lc.supported α t),
{ apply (add_mem_iff_left (map _ _) (mem_image_of_mem _ hlt)).1,
rw [← linear_map.map_add, linear_map.mem_ker.1 h₂],
apply zero_mem },
have ls0 := disjoint_def.1 hs _ hls (linear_map.mem_ker.2 $
disjoint_def.1 hst _ (mem_image_of_mem _ hls) this),
subst ls0, simp [-linear_map.mem_ker] at this h₂ ⊢,
exact disjoint_def.1 ht _ hlt h₂
end
lemma linear_independent_of_finite
(H : ∀ t ⊆ s, finite t → linear_independent α t) :
linear_independent α s :=
linear_independent_iff.2 $ λ l hl,
linear_independent_iff.1 (H _ hl (finset.finite_to_set _)) l (subset.refl _)
lemma linear_independent_Union_of_directed {ι : Type*}
{s : ι → set β} (hs : directed (⊆) s)
(h : ∀ i, linear_independent α (s i)) : linear_independent α (⋃ i, s i) :=
begin
by_cases hι : nonempty ι,
{ refine linear_independent_of_finite (λ t ht ft, _),
rcases finite_subset_Union ft ht with ⟨I, fi, hI⟩,
rcases hs.finset_le hι fi.to_finset with ⟨i, hi⟩,
exact (h i).mono (subset.trans hI $ bUnion_subset $
λ j hj, hi j (finite.mem_to_finset.2 hj)) },
{ refine linear_independent_empty.mono _,
rintro _ ⟨_, ⟨i, _⟩, _⟩, exact hι ⟨i⟩ }
end
lemma linear_independent_sUnion_of_directed {s : set (set β)}
(hs : directed_on (⊆) s)
(h : ∀ a ∈ s, linear_independent α a) : linear_independent α (⋃₀ s) :=
by rw sUnion_eq_Union; exact
linear_independent_Union_of_directed
((directed_on_iff_directed _).1 hs) (by simpa using h)
lemma linear_independent_bUnion_of_directed {ι} {s : set ι} {t : ι → set β}
(hs : directed_on (t ⁻¹'o (⊆)) s) (h : ∀a∈s, linear_independent α (t a)) :
linear_independent α (⋃a∈s, t a) :=
by rw bUnion_eq_Union; exact
linear_independent_Union_of_directed
((directed_comp _ _ _).2 $ (directed_on_iff_directed _).1 hs)
(by simpa using h)
lemma linear_independent_Union_finite {ι : Type*} {f : ι → set β}
(hl : ∀i, linear_independent α (f i))
(hd : ∀i, ∀t:set ι, finite t → i ∉ t → disjoint (span α (f i)) (⨆i∈t, span α (f i))) :
linear_independent α (⋃i, f i) :=
begin
classical,
rw [Union_eq_Union_finset f],
refine linear_independent_Union_of_directed (directed_of_sup _) _,
exact (assume t₁ t₂ ht, Union_subset_Union $ assume i, Union_subset_Union_const $ assume h, ht h),
assume t, rw [set.Union, ← finset.sup_eq_supr],
refine t.induction_on _ _,
{ exact linear_independent_empty },
{ rintros ⟨i⟩ s his ih,
rw [finset.sup_insert],
refine linear_independent_union (hl _) ih _,
rw [finset.sup_eq_supr],
refine disjoint_mono (le_refl _) _ (hd i _ _ his),
{ simp only [(span_Union _).symm],
refine span_mono (@supr_le_supr2 (set β) _ _ _ _ _ _),
rintros ⟨i⟩, exact ⟨i, le_refl _⟩ },
{ change finite (plift.up ⁻¹' s.to_set),
exact finite_preimage (assume i j, plift.up.inj) s.finite_to_set } }
end
section repr
variables (hs : linear_independent α s)
def linear_independent.total_equiv : lc.supported α s ≃ₗ span α s :=
linear_equiv.of_bijective (lc.total_on α s)
(linear_independent_iff_total_on.1 hs) (lc.total_on_range _)
def linear_independent.repr : span α s →ₗ[α] lc α β :=
(submodule.subtype _).comp (hs.total_equiv.symm : span α s →ₗ[α] lc.supported α s)
lemma linear_independent.total_repr (x) : lc.total α β (hs.repr x) = x :=
subtype.ext.1 $ hs.total_equiv.right_inv x
lemma linear_independent.total_comp_repr : (lc.total α β).comp hs.repr = submodule.subtype _ :=
linear_map.ext $ hs.total_repr
lemma linear_independent.repr_ker : hs.repr.ker = ⊥ :=
by rw [linear_independent.repr, linear_map.ker_comp, ker_subtype, comap_bot,
linear_equiv.ker]
lemma linear_independent.repr_range : hs.repr.range = lc.supported α s :=
by rw [linear_independent.repr, linear_map.range_comp,
linear_equiv.range, map_top, range_subtype]
lemma linear_independent.repr_eq {l : lc α β} (h : l ∈ lc.supported α s) {x} (eq : lc.total α β l = ↑x) : hs.repr x = l :=
by rw ← (subtype.eq' eq : (lc.total_on α s : lc.supported α s →ₗ span α s) ⟨l, h⟩ = x);
exact subtype.ext.1 (hs.total_equiv.left_inv ⟨l, h⟩)
lemma linear_independent.repr_eq_single (x) (hx : ↑x ∈ s) : hs.repr x = finsupp.single x 1 :=
hs.repr_eq (lc.single_mem_supported _ hx) (by simp)
lemma linear_independent.repr_supported (x) : hs.repr x ∈ lc.supported α s :=
((hs.total_equiv.symm : span α s →ₗ[α] lc.supported α s) x).2
lemma linear_independent.repr_eq_repr_of_subset
(h : t ⊆ s) (x y) (e : (↑x:β) = ↑y) :
(hs.mono h).repr x = hs.repr y :=
eq.symm $ hs.repr_eq (lc.supported_mono h $ (hs.mono h).repr_supported _)
(by rw [← e, (hs.mono h).total_repr]).
lemma linear_independent_iff_not_smul_mem_span :
linear_independent α s ↔ (∀ (x ∈ s) (a : α), a • x ∈ span α (s \ {x}) → a = 0) :=
⟨λ hs x hx a ha, begin
rw [span_eq_map_lc, mem_map] at ha,
rcases ha with ⟨l, hl, e⟩,
have := (lc.supported α s).sub_mem
(lc.supported_mono (diff_subset _ _) hl) (lc.single_mem_supported a hx),
rw [sub_eq_zero.1 (linear_independent_iff.1 hs _ this $ by simp [e])] at hl,
by_contra hn,
exact (not_mem_of_mem_diff (hl $ by simp [hn])) (mem_singleton _)
end, λ H, linear_independent_iff.2 $ λ l ls l0, begin
ext x, simp,
by_contra hn,
have xs : x ∈ s := ls (finsupp.mem_support_iff.2 hn),
refine hn (H _ xs _ _),
refine mem_span_iff_lc.2 ⟨finsupp.single x (l x) - l, _, _⟩,
{ have : finsupp.single x (l x) - l ∈ lc.supported α s :=
sub_mem _ (lc.single_mem_supported _ xs) ls,
refine λ y hy, ⟨this hy, λ e, _⟩,
simp at e hy, apply hy, simp [e] },
{ simp [l0] }
end⟩
end repr
lemma eq_of_linear_independent_of_span (nz : (1 : α) ≠ 0)
(hs : linear_independent α s) (h : t ⊆ s) (hst : s ⊆ span α t) : s = t :=
begin
refine subset.antisymm (λ b hb, _) h,
have : (hs.mono h).repr ⟨b, hst hb⟩ = finsupp.single b 1 :=
(hs.repr_eq_repr_of_subset h ⟨b, hst hb⟩ ⟨b, subset_span hb⟩ rfl).trans
(hs.repr_eq_single ⟨b, _⟩ hb),
have ss := (hs.mono h).repr_supported _,
rw this at ss, exact ss (by simp [nz]),
end
section
variables {f : β →ₗ[α] γ}
(hs : linear_independent α (f '' s))
(hf_inj : ∀ a b ∈ s, f a = f b → a = b)
include hs hf_inj
open linear_map
lemma linear_independent.supported_disjoint_ker :
disjoint (lc.supported α s) (ker (f.comp (lc.total α β))) :=
begin
refine le_trans (le_inf inf_le_left _) (lc.map_disjoint_ker f hf_inj),
rw [linear_independent, disjoint_iff, ← lc.map_supported f] at hs,
rw [← lc.map_total, le_ker_iff_map],
refine eq_bot_mono (le_inf (map_mono inf_le_left) _) hs,
rw [map_le_iff_le_comap, ← ker_comp], exact inf_le_right
end
lemma linear_independent.of_image : linear_independent α s :=
disjoint_mono_right (ker_le_ker_comp _ _) (hs.supported_disjoint_ker hf_inj)
lemma linear_independent.disjoint_ker : disjoint (span α s) f.ker :=
by rw [span_eq_map_lc, disjoint_iff, map_inf_eq_map_inf_comap,
← ker_comp, disjoint_iff.1 (hs.supported_disjoint_ker hf_inj), map_bot]
end
lemma linear_independent.inj_span_iff_inj {s : set β} {f : β →ₗ[α] γ}
(hfs : linear_independent α (f '' s)) :
disjoint (span α s) f.ker ↔ (∀a b ∈ s, f a = f b → a = b) :=
⟨linear_map.inj_of_disjoint_ker subset_span, hfs.disjoint_ker⟩
open linear_map
lemma linear_independent.image {s : set β} {f : β →ₗ γ} (hs : linear_independent α s)
(hf_inj : disjoint (span α s) f.ker) : linear_independent α (f '' s) :=
by rw [disjoint, span_eq_map_lc, map_inf_eq_map_inf_comap,
map_le_iff_le_comap, comap_bot] at hf_inj;
rw [linear_independent, disjoint, ← lc.map_supported f, map_inf_eq_map_inf_comap,
map_le_iff_le_comap, ← ker_comp, lc.map_total, ker_comp];
exact le_trans (le_inf inf_le_left hf_inj) (le_trans hs bot_le)
lemma linear_map.linear_independent_image_iff {s : set β} {f : β →ₗ γ}
(hf_inj : disjoint (span α s) f.ker) :
linear_independent α (f '' s) ↔ linear_independent α s :=
⟨λ hs, hs.of_image (linear_map.inj_of_disjoint_ker subset_span hf_inj),
λ hs, hs.image hf_inj⟩
lemma linear_independent_inl_union_inr {s : set β} {t : set γ}
(hs : linear_independent α s) (ht : linear_independent α t) :
linear_independent α (inl α β γ '' s ∪ inr α β γ '' t) :=
linear_independent_union (hs.image $ by simp) (ht.image $ by simp) $
by rw [span_image, span_image]; simp [disjoint_iff, prod_inf_prod]
variables (α)
/-- A set of vectors is a basis if it is linearly independent and all vectors are in the span α -/
def is_basis (s : set β) := linear_independent α s ∧ span α s = ⊤
variables {α}
section is_basis
variables (hs : is_basis α s)
lemma is_basis.mem_span (hs : is_basis α s) : ∀ x, x ∈ span α s := eq_top_iff'.1 hs.2
def is_basis.repr : β →ₗ lc α β :=
(hs.1.repr).comp (linear_map.id.cod_restrict _ hs.mem_span)
lemma is_basis.total_repr (x) : lc.total α β (hs.repr x) = x :=
hs.1.total_repr ⟨x, _⟩
lemma is_basis.total_comp_repr : (lc.total α β).comp hs.repr = linear_map.id :=
linear_map.ext hs.total_repr
lemma is_basis.repr_ker : hs.repr.ker = ⊥ :=
linear_map.ker_eq_bot.2 $ injective_of_left_inverse hs.total_repr
lemma is_basis.repr_range : hs.repr.range = lc.supported α s :=
by rw [is_basis.repr, linear_map.range, submodule.map_comp,
linear_map.map_cod_restrict, submodule.map_id, comap_top, map_top, hs.1.repr_range]
lemma is_basis.repr_supported (x) : hs.repr x ∈ lc.supported α s :=
hs.1.repr_supported ⟨x, _⟩
lemma is_basis.repr_eq_single {x} : x ∈ s → hs.repr x = finsupp.single x 1 :=
hs.1.repr_eq_single ⟨x, _⟩
/-- Construct a linear map given the value at the basis. -/
def is_basis.constr (f : β → γ) : β →ₗ γ :=
(lc.total α γ).comp $ (lc.map α f).comp hs.repr
theorem is_basis.constr_apply (f : β → γ) (x : β) :
(hs.constr f : β → γ) x = (hs.repr x).sum (λb a, a • f b) :=
by dsimp [is_basis.constr];
rw [lc.total_apply, finsupp.sum_map_domain_index]; simp [add_smul]
lemma is_basis.ext {f g : β →ₗ[α] γ} (hs : is_basis α s) (h : ∀x∈s, f x = g x) : f = g :=
linear_map.ext $ λ x, linear_eq_on h (hs.mem_span x)
lemma constr_congr {f g : β → γ} {x : β} (hs : is_basis α s) (h : ∀x∈s, f x = g x) :
hs.constr f = hs.constr g :=
by ext y; simp [is_basis.constr_apply]; exact
finset.sum_congr rfl (λ x hx, by simp [h x (hs.repr_supported _ hx)])
lemma constr_basis {f : β → γ} {b : β} (hs : is_basis α s) (hb : b ∈ s) :
(hs.constr f : β → γ) b = f b :=
by simp [is_basis.constr_apply, hs.repr_eq_single hb, finsupp.sum_single_index]
lemma constr_eq {g : β → γ} {f : β →ₗ[α] γ} (hs : is_basis α s)
(h : ∀x∈s, g x = f x) : hs.constr g = f :=
hs.ext $ λ x hx, (constr_basis hs hx).trans (h _ hx)
lemma constr_self (f : β →ₗ[α] γ) : hs.constr f = f :=
constr_eq hs $ λ x hx, rfl
lemma constr_zero (hs : is_basis α s) : hs.constr (λb, (0 : γ)) = 0 :=
constr_eq hs $ λ x hx, rfl
lemma constr_add {g f : β → γ} (hs : is_basis α s) :
hs.constr (λb, f b + g b) = hs.constr f + hs.constr g :=
constr_eq hs $ by simp [constr_basis hs] {contextual := tt}
lemma constr_neg {f : β → γ} (hs : is_basis α s) : hs.constr (λb, - f b) = - hs.constr f :=
constr_eq hs $ by simp [constr_basis hs] {contextual := tt}
lemma constr_sub {g f : β → γ} (hs : is_basis α s) :
hs.constr (λb, f b - g b) = hs.constr f - hs.constr g :=
by simp [constr_add, constr_neg]
-- this only works on functions if `α` is a commutative ring
lemma constr_smul {α β γ} [comm_ring α]
[add_comm_group β] [add_comm_group γ] [module α β] [module α γ]
{f : β → γ} {a : α} {s : set β} (hs : is_basis α s) {b : β} :
hs.constr (λb, a • f b) = a • hs.constr f :=
constr_eq hs $ by simp [constr_basis hs] {contextual := tt}
lemma constr_range (hs : is_basis α s) {f : β → γ} : (hs.constr f).range = span α (f '' s) :=
by rw [is_basis.constr, linear_map.range_comp, linear_map.range_comp,
is_basis.repr_range, lc.map_supported, span_eq_map_lc]
def module_equiv_lc (hs : is_basis α s) : β ≃ₗ lc.supported α s :=
(hs.1.total_equiv.trans (linear_equiv.of_top _ hs.2)).symm
def equiv_of_is_basis {s : set β} {t : set γ} {f : β → γ} {g : γ → β}
(hs : is_basis α s) (ht : is_basis α t) (hf : ∀b∈s, f b ∈ t) (hg : ∀c∈t, g c ∈ s)
(hgf : ∀b∈s, g (f b) = b) (hfg : ∀c∈t, f (g c) = c) :
β ≃ₗ γ :=
{ inv_fun := ht.constr g,
left_inv :=
have (ht.constr g).comp (hs.constr f) = linear_map.id,
from hs.ext $ by simp [constr_basis, hs, ht, hf, hgf, (∘)] {contextual := tt},
λ x, congr_arg (λ h:β →ₗ[α] β, h x) this,
right_inv :=
have (hs.constr f).comp (ht.constr g) = linear_map.id,
from ht.ext $ by simp [constr_basis, hs, ht, hg, hfg, (∘)] {contextual := tt},
λ y, congr_arg (λ h:γ →ₗ[α] γ, h y) this,
..hs.constr f }
lemma is_basis_inl_union_inr {s : set β} {t : set γ}
(hs : is_basis α s) (ht : is_basis α t) : is_basis α (inl α β γ '' s ∪ inr α β γ '' t) :=
⟨linear_independent_inl_union_inr hs.1 ht.1,
by rw [span_union, span_image, span_image]; simp [hs.2, ht.2]⟩
end is_basis
lemma is_basis_singleton_one (α : Type*) [ring α] : is_basis α ({1} : set α) :=
⟨ by simp [linear_independent_iff_not_smul_mem_span],
top_unique $ assume a h, by simp [submodule.mem_span_singleton]⟩
lemma linear_equiv.is_basis {s : set β} (hs : is_basis α s)
(f : β ≃ₗ[α] γ) : is_basis α (f '' s) :=
show is_basis α ((f : β →ₗ[α] γ) '' s), from
⟨hs.1.image $ by simp, by rw [span_image, hs.2, map_top, f.range]⟩
lemma is_basis_injective {s : set γ} {f : β →ₗ[α] γ}
(hs : linear_independent α s) (h : function.injective f) (hfs : span α s = f.range) :
is_basis α (f ⁻¹' s) :=
have s_eq : f '' (f ⁻¹' s) = s :=
image_preimage_eq_of_subset $ by rw [← linear_map.range_coe, ← hfs]; exact subset_span,
have linear_independent α (f '' (f ⁻¹' s)), from hs.mono (image_preimage_subset _ _),
begin
split,
exact (this.of_image $ assume a ha b hb eq, h eq),
refine (top_unique $ (linear_map.map_le_map_iff $ linear_map.ker_eq_bot.2 h).1 _),
rw [← span_image f,s_eq, hfs, linear_map.range],
exact le_refl _
end
lemma is_basis_span {s : set β} (hs : linear_independent α s) : is_basis α ((span α s).subtype ⁻¹' s) :=
is_basis_injective hs subtype.val_injective (range_subtype _).symm
lemma is_basis_empty (h : ∀x:β, x = 0) : is_basis α (∅ : set β) :=
⟨linear_independent_empty, eq_top_iff'.2 $ assume x, (h x).symm ▸ submodule.zero_mem _⟩
lemma is_basis_empty_bot : is_basis α ({x | false } : set (⊥ : submodule α β)) :=
is_basis_empty $ assume ⟨x, hx⟩,
by change x ∈ (⊥ : submodule α β) at hx; simpa [subtype.ext] using hx
end module
section vector_space
variables [discrete_field α] [add_comm_group β] [add_comm_group γ]
[vector_space α β] [vector_space α γ] {s t : set β} {x y z : β}
include α
open submodule
/- TODO: some of the following proofs can generalized with a zero_ne_one predicate type class
(instead of a data containing type classs) -/
lemma mem_span_insert_exchange : x ∈ span α (insert y s) → x ∉ span α s → y ∈ span α (insert x s) :=
begin
simp [mem_span_insert],
rintro a z hz rfl h,
refine ⟨a⁻¹, -a⁻¹ • z, smul_mem _ _ hz, _⟩,
have a0 : a ≠ 0, {rintro rfl, simp * at *},
simp [a0, smul_add, smul_smul]
end
lemma linear_independent_iff_not_mem_span : linear_independent α s ↔ (∀x∈s, x ∉ span α (s \ {x})) :=
linear_independent_iff_not_smul_mem_span.trans
⟨λ H x xs hx, one_ne_zero (H x xs 1 $ by simpa),
λ H x xs a hx, classical.by_contradiction $ λ a0,
H x xs ((smul_mem_iff _ a0).1 hx)⟩
lemma linear_independent_singleton {x : β} (hx : x ≠ 0) : linear_independent α ({x} : set β) :=
linear_independent_iff_not_mem_span.mpr $ by simp [hx] {contextual := tt}
lemma disjoint_span_singleton {p : submodule α β} {x : β} (x0 : x ≠ 0) :
disjoint p (span α {x}) ↔ x ∉ p :=
⟨λ H xp, x0 (disjoint_def.1 H _ xp (singleton_subset_iff.1 subset_span:_)),
begin
simp [disjoint_def, mem_span_singleton],
rintro xp y yp a rfl,
by_cases a0 : a = 0, {simp [a0]},
exact xp.elim ((smul_mem_iff p a0).1 yp),
end⟩
lemma linear_independent.insert (hs : linear_independent α s) (hx : x ∉ span α s) :
linear_independent α (insert x s) :=
begin
rw ← union_singleton,
have x0 : x ≠ 0 := mt (by rintro rfl; apply zero_mem _) hx,
exact linear_independent_union hs (linear_independent_singleton x0)
((disjoint_span_singleton x0).2 hx)
end
lemma exists_linear_independent (hs : linear_independent α s) (hst : s ⊆ t) :
∃b⊆t, s ⊆ b ∧ t ⊆ span α b ∧ linear_independent α b :=
begin
rcases zorn.zorn_subset₀ {b | b ⊆ t ∧ linear_independent α b} _ _
⟨hst, hs⟩ with ⟨b, ⟨bt, bi⟩, sb, h⟩,
{ refine ⟨b, bt, sb, λ x xt, _, bi⟩,
by_contra hn,
apply hn,
rw ← h _ ⟨insert_subset.2 ⟨xt, bt⟩, bi.insert hn⟩ (subset_insert _ _),
exact subset_span (mem_insert _ _) },
{ refine λ c hc cc c0, ⟨⋃₀ c, ⟨_, _⟩, λ x, _⟩,
{ exact sUnion_subset (λ x xc, (hc xc).1) },
{ exact linear_independent_sUnion_of_directed cc.directed_on (λ x xc, (hc xc).2) },
{ exact subset_sUnion_of_mem } }
end
lemma exists_subset_is_basis (hs : linear_independent α s) : ∃b, s ⊆ b ∧ is_basis α b :=
let ⟨b, hb₀, hx, hb₂, hb₃⟩ := exists_linear_independent hs (@subset_univ _ _) in
⟨b, hx, hb₃, eq_top_iff.2 hb₂⟩
variables (α β)
lemma exists_is_basis : ∃b : set β, is_basis α b :=
let ⟨b, _, hb⟩ := exists_subset_is_basis linear_independent_empty in ⟨b, hb⟩
variables {α β}
-- TODO(Mario): rewrite?
lemma exists_of_linear_independent_of_finite_span {t : finset β}
(hs : linear_independent α s) (hst : s ⊆ (span α ↑t : submodule α β)) :
∃t':finset β, ↑t' ⊆ s ∪ ↑t ∧ s ⊆ ↑t' ∧ t'.card = t.card :=
have ∀t, ∀(s' : finset β), ↑s' ⊆ s → s ∩ ↑t = ∅ → s ⊆ (span α ↑(s' ∪ t) : submodule α β) →
∃t':finset β, ↑t' ⊆ s ∪ ↑t ∧ s ⊆ ↑t' ∧ t'.card = (s' ∪ t).card :=
assume t, finset.induction_on t
(assume s' hs' _ hss',
have s = ↑s', from eq_of_linear_independent_of_span (@one_ne_zero α _) hs hs' $ by simpa using hss',
⟨s', by simp [this]⟩)
(assume b₁ t hb₁t ih s' hs' hst hss',
have hb₁s : b₁ ∉ s,
from assume h,
have b₁ ∈ s ∩ ↑(insert b₁ t), from ⟨h, finset.mem_insert_self _ _⟩,
by rwa [hst] at this,
have hb₁s' : b₁ ∉ s', from assume h, hb₁s $ hs' h,
have hst : s ∩ ↑t = ∅,
from eq_empty_of_subset_empty $ subset.trans
(by simp [inter_subset_inter, subset.refl]) (le_of_eq hst),
classical.by_cases
(assume : s ⊆ (span α ↑(s' ∪ t) : submodule α β),
let ⟨u, hust, hsu, eq⟩ := ih _ hs' hst this in
have hb₁u : b₁ ∉ u, from assume h, (hust h).elim hb₁s hb₁t,
⟨insert b₁ u, by simp [insert_subset_insert hust],
subset.trans hsu (by simp), by simp [eq, hb₁t, hb₁s', hb₁u]⟩)
(assume : ¬ s ⊆ (span α ↑(s' ∪ t) : submodule α β),
let ⟨b₂, hb₂s, hb₂t⟩ := not_subset.mp this in
have hb₂t' : b₂ ∉ s' ∪ t, from assume h, hb₂t $ subset_span h,
have s ⊆ (span α ↑(insert b₂ s' ∪ t) : submodule α β), from
assume b₃ hb₃,
have ↑(s' ∪ insert b₁ t) ⊆ insert b₁ (insert b₂ ↑(s' ∪ t) : set β),
by simp [insert_eq, -singleton_union, -union_singleton, union_subset_union, subset.refl, subset_union_right],
have hb₃ : b₃ ∈ span α (insert b₁ (insert b₂ ↑(s' ∪ t) : set β)),
from span_mono this (hss' hb₃),
have s ⊆ (span α (insert b₁ ↑(s' ∪ t)) : submodule α β),
by simpa [insert_eq, -singleton_union, -union_singleton] using hss',
have hb₁ : b₁ ∈ span α (insert b₂ ↑(s' ∪ t)),
from mem_span_insert_exchange (this hb₂s) hb₂t,
by rw [span_insert_eq_span hb₁] at hb₃; simpa using hb₃,
let ⟨u, hust, hsu, eq⟩ := ih _ (by simp [insert_subset, hb₂s, hs']) hst this in
⟨u, subset.trans hust $ union_subset_union (subset.refl _) (by simp [subset_insert]),
hsu, by rw [finset.union_comm] at hb₂t'; simp [eq, hb₂t', hb₁t, hb₁s']⟩)),
have eq : t.filter (λx, x ∈ s) ∪ t.filter (λx, x ∉ s) = t,
from finset.ext.mpr $ assume x, by by_cases x ∈ s; simp *,
let ⟨u, h₁, h₂, h⟩ := this (t.filter (λx, x ∉ s)) (t.filter (λx, x ∈ s))
(by simp [set.subset_def]) (by simp [set.ext_iff] {contextual := tt}) (by rwa [eq]) in
⟨u, subset.trans h₁ (by simp [subset_def, and_imp, or_imp_distrib] {contextual:=tt}),
h₂, by rwa [eq] at h⟩
lemma exists_finite_card_le_of_finite_of_linear_independent_of_span
(ht : finite t) (hs : linear_independent α s) (hst : s ⊆ span α t) :
∃h : finite s, h.to_finset.card ≤ ht.to_finset.card :=
have s ⊆ (span α ↑(ht.to_finset) : submodule α β), by simp; assumption,
let ⟨u, hust, hsu, eq⟩ := exists_of_linear_independent_of_finite_span hs this in
have finite s, from finite_subset u.finite_to_set hsu,
⟨this, by rw [←eq]; exact (finset.card_le_of_subset $ finset.coe_subset.mp $ by simp [hsu])⟩
lemma exists_left_inverse_linear_map_of_injective {f : β →ₗ[α] γ}
(hf_inj : f.ker = ⊥) : ∃g:γ →ₗ β, g.comp f = linear_map.id :=
begin
rcases exists_is_basis α β with ⟨B, hB⟩,
have : linear_independent α (f '' B) :=
hB.1.image (by simp [hf_inj]),
rcases exists_subset_is_basis this with ⟨C, BC, hC⟩,
haveI : inhabited β := ⟨0⟩,
refine ⟨hC.constr (inv_fun f), hB.ext $ λ b bB, _⟩,
rw image_subset_iff at BC,
simp [constr_basis hC (BC bB)],
exact left_inverse_inv_fun (linear_map.ker_eq_bot.1 hf_inj) _
end
lemma exists_right_inverse_linear_map_of_surjective {f : β →ₗ[α] γ}
(hf_surj : f.range = ⊤) : ∃g:γ →ₗ β, f.comp g = linear_map.id :=
begin
rcases exists_is_basis α γ with ⟨C, hC⟩,
haveI : inhabited β := ⟨0⟩,
refine ⟨hC.constr (inv_fun f), hC.ext $ λ c cC, _⟩,
simp [constr_basis hC cC],
exact right_inverse_inv_fun (linear_map.range_eq_top.1 hf_surj) _
end
set_option class.instance_max_depth 49
open submodule linear_map
theorem quotient_prod_linear_equiv (p : submodule α β) :
nonempty ((p.quotient × p) ≃ₗ[α] β) :=
begin
rcases exists_right_inverse_linear_map_of_surjective p.range_mkq with ⟨f, hf⟩,
have mkf : ∀ x, submodule.quotient.mk (f x) = x := linear_map.ext_iff.1 hf,
have fp : ∀ x, x - f (p.mkq x) ∈ p :=
λ x, (submodule.quotient.eq p).1 (mkf (p.mkq x)).symm,
refine ⟨linear_equiv.of_linear (f.copair p.subtype)
(p.mkq.pair (cod_restrict p (linear_map.id - f.comp p.mkq) fp))
(by ext; simp) _⟩,
ext ⟨⟨x⟩, y, hy⟩; simp,
{ apply (submodule.quotient.eq p).2,
simpa using sub_mem p hy (fp x) },
{ refine subtype.coe_ext.2 _,
simp [mkf, (submodule.quotient.mk_eq_zero p).2 hy] }
end.
end vector_space
namespace pi
open set linear_map
section module
variables {ι : Type*} {φ : ι → Type*}
variables [ring α] [∀i, add_comm_group (φ i)] [∀i, module α (φ i)] [fintype ι] [decidable_eq ι]
lemma linear_independent_std_basis (s : Πi, set (φ i)) (hs : ∀i, linear_independent α (s i)) :
linear_independent α (⋃i, std_basis α φ i '' s i) :=
begin
refine linear_independent_Union_finite _ _,
{ assume i,
refine (linear_independent_image_iff _).2 (hs i),
simp only [ker_std_basis, disjoint_bot_right] },
{ assume i J _ hiJ,
simp [(set.Union.equations._eqn_1 _).symm, submodule.span_image, submodule.span_Union],
have h₁ : map (std_basis α φ i) (span α (s i)) ≤ (⨆j∈({i} : set ι), range (std_basis α φ j)),
{ exact (le_supr_of_le i $ le_supr_of_le (set.mem_singleton _) $ map_mono $ le_top) },
have h₂ : (⨆j∈J, map (std_basis α φ j) (span α (s j))) ≤ (⨆j∈J, range (std_basis α φ j)),
{ exact supr_le_supr (assume i, supr_le_supr $ assume hi, map_mono $ le_top) },
exact disjoint_mono h₁ h₂
(disjoint_std_basis_std_basis _ _ _ _ $ set.disjoint_singleton_left.2 hiJ) }
end
lemma is_basis_std_basis [fintype ι] (s : Πi, set (φ i)) (hs : ∀i, is_basis α (s i)) :
is_basis α (⋃i, std_basis α φ i '' s i) :=
begin
refine ⟨linear_independent_std_basis _ (assume i, (hs i).1), _⟩,
simp only [submodule.span_Union, submodule.span_image, (assume i, (hs i).2), submodule.map_top,
supr_range_std_basis]
end
section
variables (α ι)
lemma is_basis_fun [fintype ι] : is_basis α (⋃i, std_basis α (λi:ι, α) i '' {1}) :=
is_basis_std_basis _ (assume i, is_basis_singleton_one _)
end
end module
end pi
|
55397996958bfa4ef41db7bddbd9e587c8ef4834 | 94e33a31faa76775069b071adea97e86e218a8ee | /src/analysis/convex/krein_milman.lean | 9069f54d51ec030cf31063264e0b943682d09627 | [
"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 | 5,429 | lean | /-
Copyright (c) 2022 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import analysis.convex.exposed
import analysis.normed_space.hahn_banach.separation
/-!
# The Krein-Milman theorem
This file proves the Krein-Milman lemma and the Krein-Milman theorem.
## The lemma
The lemma states that a nonempty compact set `s` has an extreme point. The proof goes:
1. Using Zorn's lemma, find a minimal nonempty closed `t` that is an extreme subset of `s`. We will
show that `t` is a singleton, thus corresponding to an extreme point.
2. By contradiction, `t` contains two distinct points `x` and `y`.
3. With the (geometric) Hahn-Banach theorem, find an hyperplane that separates `x` and `y`.
4. Look at the extreme (actually exposed) subset of `t` obtained by going the furthest away from
the separating hyperplane in the direction of `x`. It is nonempty, closed and an extreme subset
of `s`.
5. It is a strict subset of `t` (`y` isn't in it), so `t` isn't minimal. Absurd.
## The theorem
The theorem states that a compact convex set `s` is the closure of the convex hull of its extreme
points. It is an almost immediate strengthening of the lemma. The proof goes:
1. By contradiction, `s \ closure (convex_hull ℝ (extreme_points ℝ s))` is nonempty, say with `x`.
2. With the (geometric) Hahn-Banach theorem, find an hyperplane that separates `x` from
`closure (convex_hull ℝ (extreme_points ℝ s))`.
3. Look at the extreme (actually exposed) subset of
`s \ closure (convex_hull ℝ (extreme_points ℝ s))` obtained by going the furthest away from the
separating hyperplane. It is nonempty by assumption of nonemptiness and compactness, so by the
lemma it has an extreme point.
4. This point is also an extreme point of `s`. Absurd.
## Related theorems
When the space is finite dimensional, the `closure` can be dropped to strengthen the result of the
Krein-Milman theorem. This leads to the Minkowski-Carathéodory theorem (currently not in mathlib).
Birkhoff's theorem is the Minkowski-Carathéodory theorem applied to the set of bistochastic
matrices, permutation matrices being the extreme points.
## References
See chapter 8 of [Barry Simon, *Convexity*][simon2011]
## TODO
* Both theorems are currently stated for normed `ℝ`-spaces due to our version of geometric
Hahn-Banach. They are more generally true in a LCTVS without changes to the proofs.
-/
open set
open_locale classical
variables {E : Type*} [normed_group E] [normed_space ℝ E] {s : set E}
/-- **Krein-Milman lemma**: In a LCTVS (currently only in normed `ℝ`-spaces), any nonempty compact
set has an extreme point. -/
lemma is_compact.has_extreme_point (hscomp : is_compact s) (hsnemp : s.nonempty) :
(s.extreme_points ℝ).nonempty :=
begin
let S : set (set E) := {t | t.nonempty ∧ is_closed t ∧ is_extreme ℝ s t},
suffices h : ∃ t ∈ S, ∀ u ∈ S, u ⊆ t → u = t,
{ obtain ⟨t, ⟨⟨x, hxt⟩, htclos, hst⟩, hBmin⟩ := h,
refine ⟨x, mem_extreme_points_iff_extreme_singleton.2 _⟩,
rwa ←eq_singleton_iff_unique_mem.2 ⟨hxt, λ y hyB, _⟩,
by_contra hyx,
obtain ⟨l, hl⟩ := geometric_hahn_banach_point_point hyx,
obtain ⟨z, hzt, hz⟩ := (compact_of_is_closed_subset hscomp htclos hst.1).exists_forall_ge
⟨x, hxt⟩ l.continuous.continuous_on,
have h : is_exposed ℝ t {z ∈ t | ∀ w ∈ t, l w ≤ l z} := λ h, ⟨l, rfl⟩,
rw ←hBmin {z ∈ t | ∀ w ∈ t, l w ≤ l z} ⟨⟨z, hzt, hz⟩, h.is_closed htclos, hst.trans
h.is_extreme⟩ (t.sep_subset _) at hyB,
exact hl.not_le (hyB.2 x hxt) },
refine zorn_superset _ (λ F hFS hF, _),
obtain rfl | hFnemp := F.eq_empty_or_nonempty,
{ exact ⟨s, ⟨hsnemp, hscomp.is_closed, is_extreme.rfl⟩, λ _, false.elim⟩ },
refine ⟨⋂₀ F, ⟨_, is_closed_sInter $ λ t ht, (hFS ht).2.1, is_extreme_sInter hFnemp $
λ t ht, (hFS ht).2.2⟩, λ t ht, sInter_subset_of_mem ht⟩,
haveI : nonempty ↥F := hFnemp.to_subtype,
rw sInter_eq_Inter,
refine is_compact.nonempty_Inter_of_directed_nonempty_compact_closed _ (λ t u, _)
(λ t, (hFS t.mem).1) (λ t, compact_of_is_closed_subset hscomp (hFS t.mem).2.1 (hFS t.mem).2.2.1)
(λ t, (hFS t.mem).2.1),
obtain htu | hut := hF.total t.mem u.mem,
exacts [⟨t, subset.rfl, htu⟩, ⟨u, hut, subset.rfl⟩],
end
/-- **Krein-Milman theorem**: In a LCTVS (currently only in normed `ℝ`-spaces), any compact convex
set is the closure of the convex hull of its extreme points. -/
lemma closure_convex_hull_extreme_points (hscomp : is_compact s) (hAconv : convex ℝ s) :
closure (convex_hull ℝ $ s.extreme_points ℝ) = s :=
begin
apply (closure_minimal (convex_hull_min extreme_points_subset hAconv) hscomp.is_closed).antisymm,
by_contra hs,
obtain ⟨x, hxA, hxt⟩ := not_subset.1 hs,
obtain ⟨l, r, hlr, hrx⟩ := geometric_hahn_banach_closed_point (convex_convex_hull _ _).closure
is_closed_closure hxt,
have h : is_exposed ℝ s {y ∈ s | ∀ z ∈ s, l z ≤ l y} := λ _, ⟨l, rfl⟩,
obtain ⟨z, hzA, hz⟩ := hscomp.exists_forall_ge ⟨x, hxA⟩ l.continuous.continuous_on,
obtain ⟨y, hy⟩ := (h.is_compact hscomp).has_extreme_point ⟨z, hzA, hz⟩,
linarith [hlr _ (subset_closure $ subset_convex_hull _ _ $
h.is_extreme.extreme_points_subset_extreme_points hy), hy.1.2 x hxA],
end
|
727dfd9ee1ea29a8c780a45bf46b948412f2f5fc | 48f4f349e1bb919d14ab7e5921d0cfe825f4c423 | /fabstract/Birkhoff_G_ErgodicTheorem/fabstract.lean | 1a88054eac77f2c7ccd21c92116d3c692c7f8846 | [] | no_license | thalesant/formalabstracts-2017 | fdf4ff90d30ab1dcb6d4cf16a068a997ea5ecc80 | c47181342c9e41954aa8d41f5049965b5f332bca | refs/heads/master | 1,584,610,453,925 | 1,528,277,508,000 | 1,528,277,508,000 | 136,299,625 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 3,107 | lean | import folklore.measure_theory
noncomputable theory
open set real_axiom.extended_real
namespace Birkhoff_G_ErgodicTheorem
variables {X : Type} (σ : set (set X)) [sigma_algebra σ] (μ : set X → ℝ∞) [hms : measure_space σ μ]
@[meta_data {description := "A transformation is measure preserving if the measure of the image of every set is equal to the measure of the set."}]
def measure_preserving (T : X → X) := ∀ s ∈ σ, μ (image T s) = μ s
def {u} function.pow {α : Type u} (f : α → α) : ℕ → (α → α)
| 0 := id
| (n+1) := f ∘ (function.pow n)
def {u} nth_preimage {α : Type u} (f : α → α) : ℕ → (set α → set α)
| 0 := id
| (n+1) := λ s, {a | f a ∈ nth_preimage n s}
variable (T : X → X)
@[meta_data {description := "A transformation is ergodic if the only sets that map to themselves are null or conull."}]
def ergodic [finite_measure_space σ μ] := ∀ E ∈ σ, nth_preimage T 1 E = E → μ E = 0 ∨ μ E = of_real (univ_measure σ μ)
variables (f : X → ℝ) [lebesgue_integrable σ μ f]
include hms
def time_average_partial (x : X) : ℕ → ℝ :=
(λ n, (1/n)*((((list.iota n).map (λ k, f (function.pow T k x)))).foldr (+) 0))
def time_average_exists (x : X) : Prop :=
nat_limit_at_infinity_exists (time_average_partial σ μ T f x)
@[meta_data {description := "The time average of f under T at x is the limit of (1/n)*Σ{k=1...n} f(T^k(x)) as n→∞"}]
def time_average (x : X) : ℝ :=
nat_limit_at_infinity (time_average_partial σ μ T f x)
omit hms
@[meta_data {description := "The space average of f is (1/μ(univ))*∫f dμ"}]
def space_average [finite_measure_space σ μ] [lebesgue_integrable σ μ f] := (1/univ_measure σ μ)*lebesgue_integral σ μ f
unfinished Birkhoffs_ergodic_theorem :
∀ {X} {σ : set (set X)} {μ} [sigma_algebra σ] [finite_measure_space σ μ],
∀ (f : X → ℝ) [lebesgue_integrable σ μ f],
∀ {T : X → X} (t_mp : measure_preserving σ μ T) (t_erg : ergodic σ μ T),
almost_everywhere σ μ (λ x : X, time_average_exists σ μ T f x ∧ time_average σ μ T f x = space_average σ μ f) :=
{description := "Birkhoff's ergodic theorem."}
def furstenberg_source : document :=
{ authors := [{name := "Harry Furstenberg"}],
title := "Recurrence in Ergodic Theory",
year := ↑1981,
doi := "10.1515/9781400855162.59"}
def fabstract : fabstract :=
{ description := "Birkhoff's ergodic theorem states that, under appropriate conditions, the space average of an integrable function f is equal to the time average of f wrt a measure preserting transformation T. This result was proved in a slightly different form by Birkhoff (1931), and stated and proved in this form by many others, including Halmos (1960) and Furstenberg (1981).",
contributors := [{name := "Robert Y. Lewis", homepage := "https://andrew.cmu.edu/user/rlewis1"}],
sources := [cite.Document furstenberg_source],
results := [result.Proof @Birkhoffs_ergodic_theorem] }
end Birkhoff_G_ErgodicTheorem
|
cb62d806f1251103cee12b51649a2b59f528b0b8 | 94e33a31faa76775069b071adea97e86e218a8ee | /src/geometry/manifold/instances/sphere.lean | 06624e839af3c0588fe16a9ad923f6c7963fa14e | [
"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 | 20,604 | lean | /-
Copyright (c) 2021 Heather Macbeth. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Heather Macbeth
-/
import analysis.complex.circle
import analysis.normed_space.ball_action
import analysis.inner_product_space.calculus
import analysis.inner_product_space.pi_L2
import geometry.manifold.algebra.lie_group
import geometry.manifold.instances.real
/-!
# Manifold structure on the sphere
This file defines stereographic projection from the sphere in an inner product space `E`, and uses
it to put a smooth manifold structure on the sphere.
## Main results
For a unit vector `v` in `E`, the definition `stereographic` gives the stereographic projection
centred at `v`, a local homeomorphism from the sphere to `(ℝ ∙ v)ᗮ` (the orthogonal complement of
`v`).
For finite-dimensional `E`, we then construct a smooth manifold instance on the sphere; the charts
here are obtained by composing the local homeomorphisms `stereographic` with arbitrary isometries
from `(ℝ ∙ v)ᗮ` to Euclidean space.
We prove two lemmas about smooth maps:
* `cont_mdiff_coe_sphere` states that the coercion map from the sphere into `E` is smooth;
this is a useful tool for constructing smooth maps *from* the sphere.
* `cont_mdiff.cod_restrict_sphere` states that a map from a manifold into the sphere is
smooth if its lift to a map to `E` is smooth; this is a useful tool for constructing smooth maps
*to* the sphere.
As an application we prove `cont_mdiff_neg_sphere`, that the antipodal map is smooth.
Finally, we equip the `circle` (defined in `analysis.complex.circle` to be the sphere in `ℂ`
centred at `0` of radius `1`) with the following structure:
* a charted space with model space `euclidean_space ℝ (fin 1)` (inherited from `metric.sphere`)
* a Lie group with model with corners `𝓡 1`
We furthermore show that `exp_map_circle` (defined in `analysis.complex.circle` to be the natural
map `λ t, exp (t * I)` from `ℝ` to `circle`) is smooth.
## Implementation notes
The model space for the charted space instance is `euclidean_space ℝ (fin n)`, where `n` is a
natural number satisfying the typeclass assumption `[fact (finrank ℝ E = n + 1)]`. This may seem a
little awkward, but it is designed to circumvent the problem that the literal expression for the
dimension of the model space (up to definitional equality) determines the type. If one used the
naive expression `euclidean_space ℝ (fin (finrank ℝ E - 1))` for the model space, then the sphere in
`ℂ` would be a manifold with model space `euclidean_space ℝ (fin (2 - 1))` but not with model space
`euclidean_space ℝ (fin 1)`.
-/
variables {E : Type*} [inner_product_space ℝ E]
noncomputable theory
open metric finite_dimensional
open_locale manifold
local attribute [instance] fact_finite_dimensional_of_finrank_eq_succ
section stereographic_projection
variables (v : E)
/-! ### Construction of the stereographic projection -/
/-- Stereographic projection, forward direction. This is a map from an inner product space `E` to
the orthogonal complement of an element `v` of `E`. It is smooth away from the affine hyperplane
through `v` parallel to the orthogonal complement. It restricts on the sphere to the stereographic
projection. -/
def stereo_to_fun [complete_space E] (x : E) : (ℝ ∙ v)ᗮ :=
(2 / ((1:ℝ) - innerSL v x)) • orthogonal_projection (ℝ ∙ v)ᗮ x
variables {v}
@[simp] lemma stereo_to_fun_apply [complete_space E] (x : E) :
stereo_to_fun v x = (2 / ((1:ℝ) - innerSL v x)) • orthogonal_projection (ℝ ∙ v)ᗮ x :=
rfl
lemma cont_diff_on_stereo_to_fun [complete_space E] :
cont_diff_on ℝ ⊤ (stereo_to_fun v) {x : E | innerSL v x ≠ (1:ℝ)} :=
begin
refine cont_diff_on.smul _
(orthogonal_projection ((ℝ ∙ v)ᗮ)).cont_diff.cont_diff_on,
refine cont_diff_const.cont_diff_on.div _ _,
{ exact (cont_diff_const.sub (innerSL v).cont_diff).cont_diff_on },
{ intros x h h',
exact h (sub_eq_zero.mp h').symm }
end
lemma continuous_on_stereo_to_fun [complete_space E] :
continuous_on (stereo_to_fun v) {x : E | innerSL v x ≠ (1:ℝ)} :=
(@cont_diff_on_stereo_to_fun E _ v _).continuous_on
variables (v)
/-- Auxiliary function for the construction of the reverse direction of the stereographic
projection. This is a map from the orthogonal complement of a unit vector `v` in an inner product
space `E` to `E`; we will later prove that it takes values in the unit sphere.
For most purposes, use `stereo_inv_fun`, not `stereo_inv_fun_aux`. -/
def stereo_inv_fun_aux (w : E) : E := (∥w∥ ^ 2 + 4)⁻¹ • ((4:ℝ) • w + (∥w∥ ^ 2 - 4) • v)
variables {v}
@[simp] lemma stereo_inv_fun_aux_apply (w : E) :
stereo_inv_fun_aux v w = (∥w∥ ^ 2 + 4)⁻¹ • ((4:ℝ) • w + (∥w∥ ^ 2 - 4) • v) :=
rfl
lemma stereo_inv_fun_aux_mem (hv : ∥v∥ = 1) {w : E} (hw : w ∈ (ℝ ∙ v)ᗮ) :
stereo_inv_fun_aux v w ∈ (sphere (0:E) 1) :=
begin
have h₁ : 0 ≤ ∥w∥ ^ 2 + 4 := by nlinarith,
suffices : ∥(4:ℝ) • w + (∥w∥ ^ 2 - 4) • v∥ = ∥w∥ ^ 2 + 4,
{ have h₂ : ∥w∥ ^ 2 + 4 ≠ 0 := by nlinarith,
simp only [mem_sphere_zero_iff_norm, norm_smul, real.norm_eq_abs, abs_inv, this,
abs_of_nonneg h₁, stereo_inv_fun_aux_apply],
field_simp },
suffices : ∥(4:ℝ) • w + (∥w∥ ^ 2 - 4) • v∥ ^ 2 = (∥w∥ ^ 2 + 4) ^ 2,
{ have h₃ : 0 ≤ ∥stereo_inv_fun_aux v w∥ := norm_nonneg _,
simpa [h₁, h₃, -one_pow] using this },
simp [norm_add_sq_real, norm_smul, inner_smul_left, inner_smul_right,
inner_left_of_mem_orthogonal_singleton _ hw, mul_pow, real.norm_eq_abs, hv],
ring
end
lemma cont_diff_stereo_inv_fun_aux : cont_diff ℝ ⊤ (stereo_inv_fun_aux v) :=
begin
have h₀ : cont_diff ℝ ⊤ (λ w : E, ∥w∥ ^ 2) := cont_diff_norm_sq,
have h₁ : cont_diff ℝ ⊤ (λ w : E, (∥w∥ ^ 2 + 4)⁻¹),
{ refine (h₀.add cont_diff_const).inv _,
intros x,
nlinarith },
have h₂ : cont_diff ℝ ⊤ (λ w, (4:ℝ) • w + (∥w∥ ^ 2 - 4) • v),
{ refine (cont_diff_const.smul cont_diff_id).add _,
refine (h₀.sub cont_diff_const).smul cont_diff_const },
exact h₁.smul h₂
end
/-- Stereographic projection, reverse direction. This is a map from the orthogonal complement of a
unit vector `v` in an inner product space `E` to the unit sphere in `E`. -/
def stereo_inv_fun (hv : ∥v∥ = 1) (w : (ℝ ∙ v)ᗮ) : sphere (0:E) 1 :=
⟨stereo_inv_fun_aux v (w:E), stereo_inv_fun_aux_mem hv w.2⟩
@[simp] lemma stereo_inv_fun_apply (hv : ∥v∥ = 1) (w : (ℝ ∙ v)ᗮ) :
(stereo_inv_fun hv w : E) = (∥w∥ ^ 2 + 4)⁻¹ • ((4:ℝ) • w + (∥w∥ ^ 2 - 4) • v) :=
rfl
lemma stereo_inv_fun_ne_north_pole (hv : ∥v∥ = 1) (w : (ℝ ∙ v)ᗮ) :
stereo_inv_fun hv w ≠ (⟨v, by simp [hv]⟩ : sphere (0:E) 1) :=
begin
refine subtype.ne_of_val_ne _,
rw ← inner_lt_one_iff_real_of_norm_one _ hv,
{ have hw : ⟪v, w⟫_ℝ = 0 := inner_right_of_mem_orthogonal_singleton v w.2,
have hw' : (∥(w:E)∥ ^ 2 + 4)⁻¹ * (∥(w:E)∥ ^ 2 - 4) < 1,
{ refine (inv_mul_lt_iff' _).mpr _,
{ nlinarith },
linarith },
simpa [real_inner_comm, inner_add_right, inner_smul_right, real_inner_self_eq_norm_mul_norm, hw,
hv] using hw' },
{ simpa using stereo_inv_fun_aux_mem hv w.2 }
end
lemma continuous_stereo_inv_fun (hv : ∥v∥ = 1) : continuous (stereo_inv_fun hv) :=
continuous_induced_rng (cont_diff_stereo_inv_fun_aux.continuous.comp continuous_subtype_coe)
variables [complete_space E]
lemma stereo_left_inv (hv : ∥v∥ = 1) {x : sphere (0:E) 1} (hx : (x:E) ≠ v) :
stereo_inv_fun hv (stereo_to_fun v x) = x :=
begin
ext,
simp only [stereo_to_fun_apply, stereo_inv_fun_apply, smul_add],
-- name two frequently-occuring quantities and write down their basic properties
set a : ℝ := innerSL v x,
set y := orthogonal_projection (ℝ ∙ v)ᗮ x,
have split : ↑x = a • v + ↑y,
{ convert eq_sum_orthogonal_projection_self_orthogonal_complement (ℝ ∙ v) x,
exact (orthogonal_projection_unit_singleton ℝ hv x).symm },
have hvy : ⟪v, y⟫_ℝ = 0 := inner_right_of_mem_orthogonal_singleton v y.2,
have pythag : 1 = a ^ 2 + ∥y∥ ^ 2,
{ have hvy' : ⟪a • v, y⟫_ℝ = 0 := by simp [inner_smul_left, hvy],
convert norm_add_sq_eq_norm_sq_add_norm_sq_of_inner_eq_zero _ _ hvy' using 2,
{ simp [← split] },
{ simp [norm_smul, hv, ← sq, sq_abs] },
{ exact sq _ } },
-- two facts which will be helpful for clearing denominators in the main calculation
have ha : 1 - a ≠ 0,
{ have : a < 1 := (inner_lt_one_iff_real_of_norm_one hv (by simp)).mpr hx.symm,
linarith },
have : 2 ^ 2 * ∥y∥ ^ 2 + 4 * (1 - a) ^ 2 ≠ 0,
{ refine ne_of_gt _,
have := norm_nonneg (y:E),
have : 0 < (1 - a) ^ 2 := sq_pos_of_ne_zero (1 - a) ha,
nlinarith },
-- the core of the problem is these two algebraic identities:
have h₁ : (2 ^ 2 / (1 - a) ^ 2 * ∥y∥ ^ 2 + 4)⁻¹ * 4 * (2 / (1 - a)) = 1,
{ field_simp,
simp only [submodule.coe_norm] at *,
nlinarith },
have h₂ : (2 ^ 2 / (1 - a) ^ 2 * ∥y∥ ^ 2 + 4)⁻¹ * (2 ^ 2 / (1 - a) ^ 2 * ∥y∥ ^ 2 - 4) = a,
{ field_simp,
transitivity (1 - a) ^ 2 * (a * (2 ^ 2 * ∥y∥ ^ 2 + 4 * (1 - a) ^ 2)),
{ congr,
simp only [submodule.coe_norm] at *,
nlinarith },
ring },
-- deduce the result
convert congr_arg2 has_add.add (congr_arg (λ t, t • (y:E)) h₁) (congr_arg (λ t, t • v) h₂)
using 1,
{ simp [inner_add_right, inner_smul_right, hvy, real_inner_self_eq_norm_mul_norm, hv, mul_smul,
mul_pow, real.norm_eq_abs, sq_abs, norm_smul] },
{ simp [split, add_comm] }
end
lemma stereo_right_inv (hv : ∥v∥ = 1) (w : (ℝ ∙ v)ᗮ) :
stereo_to_fun v (stereo_inv_fun hv w) = w :=
begin
have : 2 / (1 - (∥(w:E)∥ ^ 2 + 4)⁻¹ * (∥(w:E)∥ ^ 2 - 4)) * (∥(w:E)∥ ^ 2 + 4)⁻¹ * 4 = 1,
{ have : ∥(w:E)∥ ^ 2 + 4 ≠ 0 := by nlinarith,
have : (4:ℝ) + 4 ≠ 0 := by nlinarith,
field_simp,
ring },
convert congr_arg (λ c, c • w) this,
{ have h₁ : orthogonal_projection (ℝ ∙ v)ᗮ v = 0 :=
orthogonal_projection_orthogonal_complement_singleton_eq_zero v,
have h₂ : orthogonal_projection (ℝ ∙ v)ᗮ w = w :=
orthogonal_projection_mem_subspace_eq_self w,
have h₃ : innerSL v w = (0:ℝ) := inner_right_of_mem_orthogonal_singleton v w.2,
have h₄ : innerSL v v = (1:ℝ) := by simp [real_inner_self_eq_norm_mul_norm, hv],
simp [h₁, h₂, h₃, h₄, continuous_linear_map.map_add, continuous_linear_map.map_smul,
mul_smul] },
{ simp }
end
/-- Stereographic projection from the unit sphere in `E`, centred at a unit vector `v` in `E`; this
is the version as a local homeomorphism. -/
def stereographic (hv : ∥v∥ = 1) : local_homeomorph (sphere (0:E) 1) (ℝ ∙ v)ᗮ :=
{ to_fun := (stereo_to_fun v) ∘ coe,
inv_fun := stereo_inv_fun hv,
source := {⟨v, by simp [hv]⟩}ᶜ,
target := set.univ,
map_source' := by simp,
map_target' := λ w _, stereo_inv_fun_ne_north_pole hv w,
left_inv' := λ _ hx, stereo_left_inv hv (λ h, hx (subtype.ext h)),
right_inv' := λ w _, stereo_right_inv hv w,
open_source := is_open_compl_singleton,
open_target := is_open_univ,
continuous_to_fun := continuous_on_stereo_to_fun.comp continuous_subtype_coe.continuous_on
(λ w h, h ∘ subtype.ext ∘ eq.symm ∘ (inner_eq_norm_mul_iff_of_norm_one hv (by simp)).mp),
continuous_inv_fun := (continuous_stereo_inv_fun hv).continuous_on }
lemma stereographic_apply (hv : ∥v∥ = 1) (x : sphere (0 : E) 1) :
stereographic hv x = (2 / ((1:ℝ) - inner v x)) • orthogonal_projection (ℝ ∙ v)ᗮ x :=
rfl
@[simp] lemma stereographic_source (hv : ∥v∥ = 1) :
(stereographic hv).source = {⟨v, by simp [hv]⟩}ᶜ :=
rfl
@[simp] lemma stereographic_target (hv : ∥v∥ = 1) : (stereographic hv).target = set.univ := rfl
end stereographic_projection
section charted_space
/-!
### Charted space structure on the sphere
In this section we construct a charted space structure on the unit sphere in a finite-dimensional
real inner product space `E`; that is, we show that it is locally homeomorphic to the Euclidean
space of dimension one less than `E`.
The restriction to finite dimension is for convenience. The most natural `charted_space`
structure for the sphere uses the stereographic projection from the antipodes of a point as the
canonical chart at this point. However, the codomain of the stereographic projection constructed
in the previous section is `(ℝ ∙ v)ᗮ`, the orthogonal complement of the vector `v` in `E` which is
the "north pole" of the projection, so a priori these charts all have different codomains.
So it is necessary to prove that these codomains are all continuously linearly equivalent to a
fixed normed space. This could be proved in general by a simple case of Gram-Schmidt
orthogonalization, but in the finite-dimensional case it follows more easily by dimension-counting.
-/
/-- Variant of the stereographic projection, for the sphere in an `n + 1`-dimensional inner product
space `E`. This version has codomain the Euclidean space of dimension `n`, and is obtained by
composing the original sterographic projection (`stereographic`) with an arbitrary linear isometry
from `(ℝ ∙ v)ᗮ` to the Euclidean space. -/
def stereographic' (n : ℕ) [fact (finrank ℝ E = n + 1)] (v : sphere (0:E) 1) :
local_homeomorph (sphere (0:E) 1) (euclidean_space ℝ (fin n)) :=
(stereographic (norm_eq_of_mem_sphere v)) ≫ₕ
(linear_isometry_equiv.from_orthogonal_span_singleton n
(ne_zero_of_mem_unit_sphere v)).to_homeomorph.to_local_homeomorph
@[simp] lemma stereographic'_source {n : ℕ} [fact (finrank ℝ E = n + 1)] (v : sphere (0:E) 1) :
(stereographic' n v).source = {v}ᶜ :=
by simp [stereographic']
@[simp] lemma stereographic'_target {n : ℕ} [fact (finrank ℝ E = n + 1)] (v : sphere (0:E) 1) :
(stereographic' n v).target = set.univ :=
by simp [stereographic']
/-- The unit sphere in an `n + 1`-dimensional inner product space `E` is a charted space
modelled on the Euclidean space of dimension `n`. -/
instance {n : ℕ} [fact (finrank ℝ E = n + 1)] :
charted_space (euclidean_space ℝ (fin n)) (sphere (0:E) 1) :=
{ atlas := {f | ∃ v : (sphere (0:E) 1), f = stereographic' n v},
chart_at := λ v, stereographic' n (-v),
mem_chart_source := λ v, by simpa using ne_neg_of_mem_unit_sphere ℝ v,
chart_mem_atlas := λ v, ⟨-v, rfl⟩ }
end charted_space
section smooth_manifold
lemma sphere_ext_iff (u v : sphere (0:E) 1) :
u = v ↔ ⟪(u:E), v⟫_ℝ = 1 :=
by simp [subtype.ext_iff, inner_eq_norm_mul_iff_of_norm_one]
lemma stereographic'_symm_apply {n : ℕ} [fact (finrank ℝ E = n + 1)]
(v : sphere (0:E) 1) (x : euclidean_space ℝ (fin n)) :
((stereographic' n v).symm x : E) =
let U : (ℝ ∙ (v:E))ᗮ ≃ₗᵢ[ℝ] euclidean_space ℝ (fin n) :=
linear_isometry_equiv.from_orthogonal_span_singleton n
(ne_zero_of_mem_unit_sphere v) in
((∥(U.symm x : E)∥ ^ 2 + 4)⁻¹ • (4 : ℝ) • (U.symm x : E) +
(∥(U.symm x : E)∥ ^ 2 + 4)⁻¹ • (∥(U.symm x : E)∥ ^ 2 - 4) • v) :=
by simp [real_inner_comm, stereographic, stereographic', ← submodule.coe_norm]
/-! ### Smooth manifold structure on the sphere -/
/-- The unit sphere in an `n + 1`-dimensional inner product space `E` is a smooth manifold,
modelled on the Euclidean space of dimension `n`. -/
instance {n : ℕ} [fact (finrank ℝ E = n + 1)] :
smooth_manifold_with_corners (𝓡 n) (sphere (0:E) 1) :=
smooth_manifold_with_corners_of_cont_diff_on (𝓡 n) (sphere (0:E) 1)
begin
rintros _ _ ⟨v, rfl⟩ ⟨v', rfl⟩,
let U : (ℝ ∙ (v:E))ᗮ ≃ₗᵢ[ℝ] euclidean_space ℝ (fin n) :=
linear_isometry_equiv.from_orthogonal_span_singleton n
(ne_zero_of_mem_unit_sphere v),
let U' : (ℝ ∙ (v':E))ᗮ ≃ₗᵢ[ℝ] euclidean_space ℝ (fin n) :=
linear_isometry_equiv.from_orthogonal_span_singleton n
(ne_zero_of_mem_unit_sphere v'),
have H₁ := U'.cont_diff.comp_cont_diff_on cont_diff_on_stereo_to_fun,
have H₂ := (cont_diff_stereo_inv_fun_aux.comp
(ℝ ∙ (v:E))ᗮ.subtypeL.cont_diff).comp U.symm.cont_diff,
convert H₁.comp' (H₂.cont_diff_on : cont_diff_on ℝ ⊤ _ set.univ) using 1,
ext,
simp [sphere_ext_iff, stereographic'_symm_apply, real_inner_comm]
end
/-- The inclusion map (i.e., `coe`) from the sphere in `E` to `E` is smooth. -/
lemma cont_mdiff_coe_sphere {n : ℕ} [fact (finrank ℝ E = n + 1)] :
cont_mdiff (𝓡 n) 𝓘(ℝ, E) ∞ (coe : (sphere (0:E) 1) → E) :=
begin
rw cont_mdiff_iff,
split,
{ exact continuous_subtype_coe },
{ intros v _,
let U : (ℝ ∙ ((-v):E))ᗮ ≃ₗᵢ[ℝ] euclidean_space ℝ (fin n) :=
linear_isometry_equiv.from_orthogonal_span_singleton n (ne_zero_of_mem_unit_sphere (-v)),
exact ((cont_diff_stereo_inv_fun_aux.comp
(ℝ ∙ ((-v):E))ᗮ.subtypeL.cont_diff).comp U.symm.cont_diff).cont_diff_on }
end
variables {F : Type*} [normed_group F] [normed_space ℝ F]
variables {H : Type*} [topological_space H] {I : model_with_corners ℝ F H}
variables {M : Type*} [topological_space M] [charted_space H M] [smooth_manifold_with_corners I M]
/-- If a `cont_mdiff` function `f : M → E`, where `M` is some manifold, takes values in the
sphere, then it restricts to a `cont_mdiff` function from `M` to the sphere. -/
lemma cont_mdiff.cod_restrict_sphere {n : ℕ} [fact (finrank ℝ E = n + 1)]
{m : with_top ℕ} {f : M → E} (hf : cont_mdiff I 𝓘(ℝ, E) m f)
(hf' : ∀ x, f x ∈ sphere (0:E) 1) :
cont_mdiff I (𝓡 n) m (set.cod_restrict _ _ hf' : M → (sphere (0:E) 1)) :=
begin
rw cont_mdiff_iff_target,
refine ⟨continuous_induced_rng hf.continuous, _⟩,
intros v,
let U : (ℝ ∙ ((-v):E))ᗮ ≃ₗᵢ[ℝ] euclidean_space ℝ (fin n) :=
(linear_isometry_equiv.from_orthogonal_span_singleton n (ne_zero_of_mem_unit_sphere (-v))),
have h : cont_diff_on ℝ ⊤ _ set.univ :=
U.cont_diff.cont_diff_on,
have H₁ := (h.comp' cont_diff_on_stereo_to_fun).cont_mdiff_on,
have H₂ : cont_mdiff_on _ _ _ _ set.univ := hf.cont_mdiff_on,
convert (H₁.of_le le_top).comp' H₂ using 1,
ext x,
have hfxv : f x = -↑v ↔ ⟪f x, -↑v⟫_ℝ = 1,
{ have hfx : ∥f x∥ = 1 := by simpa using hf' x,
rw inner_eq_norm_mul_iff_of_norm_one hfx,
exact norm_eq_of_mem_sphere (-v) },
dsimp [chart_at],
simp [not_iff_not, subtype.ext_iff, hfxv, real_inner_comm]
end
/-- The antipodal map is smooth. -/
lemma cont_mdiff_neg_sphere {n : ℕ} [fact (finrank ℝ E = n + 1)] :
cont_mdiff (𝓡 n) (𝓡 n) ∞ (λ x : sphere (0:E) 1, -x) :=
begin
-- this doesn't elaborate well in term mode
apply cont_mdiff.cod_restrict_sphere,
apply cont_diff_neg.cont_mdiff.comp _,
exact cont_mdiff_coe_sphere,
end
end smooth_manifold
section circle
open complex
local attribute [instance] finrank_real_complex_fact
/-- The unit circle in `ℂ` is a charted space modelled on `euclidean_space ℝ (fin 1)`. This
follows by definition from the corresponding result for `metric.sphere`. -/
instance : charted_space (euclidean_space ℝ (fin 1)) circle := metric.sphere.charted_space
instance : smooth_manifold_with_corners (𝓡 1) circle :=
metric.sphere.smooth_manifold_with_corners
/-- The unit circle in `ℂ` is a Lie group. -/
instance : lie_group (𝓡 1) circle :=
{ smooth_mul := begin
apply cont_mdiff.cod_restrict_sphere,
let c : circle → ℂ := coe,
have h₂ : cont_mdiff (𝓘(ℝ, ℂ).prod 𝓘(ℝ, ℂ)) 𝓘(ℝ, ℂ) ∞ (λ (z : ℂ × ℂ), z.fst * z.snd),
{ rw cont_mdiff_iff,
exact ⟨continuous_mul, λ x y, (cont_diff_mul.restrict_scalars ℝ).cont_diff_on⟩ },
suffices h₁ : cont_mdiff _ _ _ (prod.map c c),
{ apply h₂.comp h₁ },
-- this elaborates much faster with `apply`
apply cont_mdiff.prod_map; exact cont_mdiff_coe_sphere,
end,
smooth_inv := begin
apply cont_mdiff.cod_restrict_sphere,
simp only [← coe_inv_circle, coe_inv_circle_eq_conj],
exact complex.conj_cle.cont_diff.cont_mdiff.comp cont_mdiff_coe_sphere
end }
/-- The map `λ t, exp (t * I)` from `ℝ` to the unit circle in `ℂ` is smooth. -/
lemma cont_mdiff_exp_map_circle : cont_mdiff 𝓘(ℝ, ℝ) (𝓡 1) ∞ exp_map_circle :=
((cont_diff_exp.comp (cont_diff_id.smul cont_diff_const)).cont_mdiff).cod_restrict_sphere _
end circle
|
5079e3455d47aada9ca6475aa7b9c03b40b26124 | 4d2583807a5ac6caaffd3d7a5f646d61ca85d532 | /src/category_theory/limits/cone_category.lean | 13620deff44cc974a2578ff70ca5bbbedc4c3922 | [
"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,220 | lean | /-
Copyright (c) 2021 Andrew Yang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Andrew Yang
-/
import category_theory.limits.preserves.shapes.terminal
/-!
# Limits and the category of (co)cones
This files contains results that stem from the limit API. For the definition and the category
instance of `cone`, please refer to `category_theory/limits/cones.lean`.
A cone is limiting iff it is terminal in the category of cones. As a corollary, an equivalence of
categories of cones preserves limiting properties. We also provide the dual.
-/
namespace category_theory.limits
open category_theory
universes v u
variables {J : Type v} [category.{v} J] {J' : Type v} [category.{v} J']
variables {C : Type u} [category.{v} C] {C' : Type u} [category.{v} C']
/-- A cone is a limit cone iff it is terminal. -/
def cone.is_limit_equiv_is_terminal {F : J ⥤ C} (c : cone F) : is_limit c ≃ is_terminal c :=
is_limit.iso_unique_cone_morphism.to_equiv.trans
{ to_fun := λ h, by exactI is_terminal.of_unique _,
inv_fun := λ h s, ⟨⟨is_terminal.from h s⟩, λ a, is_terminal.hom_ext h a _⟩,
left_inv := by tidy,
right_inv := by tidy }
lemma is_limit.lift_cone_morphism_eq_is_terminal_from {F : J ⥤ C} {c : cone F} (hc : is_limit c)
(s : cone F) : hc.lift_cone_morphism s =
is_terminal.from (cone.is_limit_equiv_is_terminal _ hc) _ := rfl
lemma is_terminal.from_eq_lift_cone_morphism {F : J ⥤ C} {c : cone F} (hc : is_terminal c)
(s : cone F) : is_terminal.from hc s =
((cone.is_limit_equiv_is_terminal _).symm hc).lift_cone_morphism s :=
by convert (is_limit.lift_cone_morphism_eq_is_terminal_from _ s).symm
/-- If `G : cone F ⥤ cone F'` preserves terminal objects, it preserves limit cones. -/
def is_limit.of_preserves_cone_terminal {F : J ⥤ C} {F' : J' ⥤ C'} (G : cone F ⥤ cone F')
[preserves_limit (functor.empty _) G] {c : cone F} (hc : is_limit c) :
is_limit (G.obj c) :=
(cone.is_limit_equiv_is_terminal _).symm $
(cone.is_limit_equiv_is_terminal _ hc).is_terminal_obj _ _
/-- If `G : cone F ⥤ cone F'` reflects terminal objects, it reflects limit cones. -/
def is_limit.of_reflects_cone_terminal {F : J ⥤ C} {F' : J' ⥤ C'} (G : cone F ⥤ cone F')
[reflects_limit (functor.empty _) G] {c : cone F} (hc : is_limit (G.obj c)) :
is_limit c :=
(cone.is_limit_equiv_is_terminal _).symm $
(cone.is_limit_equiv_is_terminal _ hc).is_terminal_of_obj _ _
/-- A cocone is a colimit cocone iff it is initial. -/
def cocone.is_colimit_equiv_is_initial {F : J ⥤ C} (c : cocone F) : is_colimit c ≃ is_initial c :=
is_colimit.iso_unique_cocone_morphism.to_equiv.trans
{ to_fun := λ h, by exactI is_initial.of_unique _,
inv_fun := λ h s, ⟨⟨is_initial.to h s⟩, λ a, is_initial.hom_ext h a _⟩,
left_inv := by tidy,
right_inv := by tidy }
lemma is_colimit.desc_cocone_morphism_eq_is_initial_to {F : J ⥤ C} {c : cocone F}
(hc : is_colimit c) (s : cocone F) :
hc.desc_cocone_morphism s =
is_initial.to (cocone.is_colimit_equiv_is_initial _ hc) _ := rfl
lemma is_initial.to_eq_desc_cocone_morphism {F : J ⥤ C} {c : cocone F}
(hc : is_initial c) (s : cocone F) :
is_initial.to hc s = ((cocone.is_colimit_equiv_is_initial _).symm hc).desc_cocone_morphism s :=
by convert (is_colimit.desc_cocone_morphism_eq_is_initial_to _ s).symm
/-- If `G : cocone F ⥤ cocone F'` preserves initial objects, it preserves colimit cocones. -/
def is_colimit.of_preserves_cocone_initial {F : J ⥤ C} {F' : J' ⥤ C'} (G : cocone F ⥤ cocone F')
[preserves_colimit (functor.empty _) G] {c : cocone F} (hc : is_colimit c) :
is_colimit (G.obj c) :=
(cocone.is_colimit_equiv_is_initial _).symm $
(cocone.is_colimit_equiv_is_initial _ hc).is_initial_obj _ _
/-- If `G : cocone F ⥤ cocone F'` reflects initial objects, it reflects colimit cocones. -/
def is_colimit.of_reflects_cocone_initial {F : J ⥤ C} {F' : J' ⥤ C'} (G : cocone F ⥤ cocone F')
[reflects_colimit (functor.empty _) G] {c : cocone F} (hc : is_colimit (G.obj c)) :
is_colimit c :=
(cocone.is_colimit_equiv_is_initial _).symm $
(cocone.is_colimit_equiv_is_initial _ hc).is_initial_of_obj _ _
end category_theory.limits
|
730240fcf607baf1ae83227903ba536f8abc84c1 | 8b9f17008684d796c8022dab552e42f0cb6fb347 | /hott/init/types/sigma.hlean | 53d2600ab46d492013aa588957b4fec7c8fc537d | [
"Apache-2.0"
] | permissive | chubbymaggie/lean | 0d06ae25f9dd396306fb02190e89422ea94afd7b | d2c7b5c31928c98f545b16420d37842c43b4ae9a | refs/heads/master | 1,611,313,622,901 | 1,430,266,839,000 | 1,430,267,083,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 639 | hlean | /-
Copyright (c) 2014 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Module: init.types.sigma
Authors: Leonardo de Moura, Jeremy Avigad, Floris van Doorn
-/
prelude
import init.num
structure sigma {A : Type} (B : A → Type) :=
mk :: (pr1 : A) (pr2 : B pr1)
notation `Σ` binders `,` r:(scoped P, sigma P) := r
namespace sigma
notation `⟨`:max t:(foldr `,` (e r, mk e r)) `⟩`:0 := t --input ⟨ ⟩ as \< \>
namespace ops
postfix `.1`:(max+1) := pr1
postfix `.2`:(max+1) := pr2
abbreviation pr₁ := @pr1
abbreviation pr₂ := @pr2
end ops
end sigma
|
74780a365635365ea7db43fdbb8a45254a3d0009 | bbecf0f1968d1fba4124103e4f6b55251d08e9c4 | /src/ring_theory/jacobson.lean | 16bbe3704494c3e8a0115746a07dc08a57d3f306 | [
"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 | 34,433 | lean | /-
Copyright (c) 2020 Devon Tuma. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Devon Tuma
-/
import data.mv_polynomial
import ring_theory.ideal.over
import ring_theory.jacobson_ideal
import ring_theory.localization
/-!
# Jacobson Rings
The following conditions are equivalent for a ring `R`:
1. Every radical ideal `I` is equal to its Jacobson radical
2. Every radical ideal `I` can be written as an intersection of maximal ideals
3. Every prime ideal `I` is equal to its Jacobson radical
Any ring satisfying any of these equivalent conditions is said to be Jacobson.
Some particular examples of Jacobson rings are also proven.
`is_jacobson_quotient` says that the quotient of a Jacobson ring is Jacobson.
`is_jacobson_localization` says the localization of a Jacobson ring to a single element is Jacobson.
`is_jacobson_polynomial_iff_is_jacobson` says polynomials over a Jacobson ring form a Jacobson ring.
## Main definitions
Let `R` be a commutative ring. Jacobson Rings are defined using the first of the above conditions
* `is_jacobson R` is the proposition that `R` is a Jacobson ring. It is a class,
implemented as the predicate that for any ideal, `I.radical = I` implies `I.jacobson = I`.
## Main statements
* `is_jacobson_iff_prime_eq` is the equivalence between conditions 1 and 3 above.
* `is_jacobson_iff_Inf_maximal` is the equivalence between conditions 1 and 2 above.
* `is_jacobson_of_surjective` says that if `R` is a Jacobson ring and `f : R →+* S` is surjective,
then `S` is also a Jacobson ring
* `is_jacobson_mv_polynomial` says that multi-variate polynomials over a Jacobson ring are Jacobson.
## Tags
Jacobson, Jacobson Ring
-/
namespace ideal
open polynomial
section is_jacobson
variables {R S : Type*} [comm_ring R] [comm_ring S] {I : ideal R}
/-- A ring is a Jacobson ring if for every radical ideal `I`,
the Jacobson radical of `I` is equal to `I`.
See `is_jacobson_iff_prime_eq` and `is_jacobson_iff_Inf_maximal` for equivalent definitions. -/
class is_jacobson (R : Type*) [comm_ring R] : Prop :=
(out' : ∀ (I : ideal R), I.radical = I → I.jacobson = I)
theorem is_jacobson_iff {R} [comm_ring R] :
is_jacobson R ↔ ∀ (I : ideal R), I.radical = I → I.jacobson = I :=
⟨λ h, h.1, λ h, ⟨h⟩⟩
theorem is_jacobson.out {R} [comm_ring R] :
is_jacobson R → ∀ {I : ideal R}, I.radical = I → I.jacobson = I := is_jacobson_iff.1
/-- A ring is a Jacobson ring if and only if for all prime ideals `P`,
the Jacobson radical of `P` is equal to `P`. -/
lemma is_jacobson_iff_prime_eq : is_jacobson R ↔ ∀ P : ideal R, is_prime P → P.jacobson = P :=
begin
refine is_jacobson_iff.trans ⟨λ h I hI, h I (is_prime.radical hI), _⟩,
refine λ h I hI, le_antisymm (λ x hx, _) (λ x hx, mem_Inf.mpr (λ _ hJ, hJ.left hx)),
rw [← hI, radical_eq_Inf I, mem_Inf],
intros P hP,
rw set.mem_set_of_eq at hP,
erw mem_Inf at hx,
erw [← h P hP.right, mem_Inf],
exact λ J hJ, hx ⟨le_trans hP.left hJ.left, hJ.right⟩
end
/-- A ring `R` is Jacobson if and only if for every prime ideal `I`,
`I` can be written as the infimum of some collection of maximal ideals.
Allowing ⊤ in the set `M` of maximal ideals is equivalent, but makes some proofs cleaner. -/
lemma is_jacobson_iff_Inf_maximal : is_jacobson R ↔
∀ {I : ideal R}, I.is_prime → ∃ M : set (ideal R), (∀ J ∈ M, is_maximal J ∨ J = ⊤) ∧ I = Inf M :=
⟨λ H I h, eq_jacobson_iff_Inf_maximal.1 (H.out (is_prime.radical h)),
λ H, is_jacobson_iff_prime_eq.2 (λ P hP, eq_jacobson_iff_Inf_maximal.2 (H hP))⟩
lemma is_jacobson_iff_Inf_maximal' : is_jacobson R ↔
∀ {I : ideal R}, I.is_prime → ∃ M : set (ideal R),
(∀ (J ∈ M) (K : ideal R), J < K → K = ⊤) ∧ I = Inf M :=
⟨λ H I h, eq_jacobson_iff_Inf_maximal'.1 (H.out (is_prime.radical h)),
λ H, is_jacobson_iff_prime_eq.2 (λ P hP, eq_jacobson_iff_Inf_maximal'.2 (H hP))⟩
lemma radical_eq_jacobson [H : is_jacobson R] (I : ideal R) : I.radical = I.jacobson :=
le_antisymm (le_Inf (λ J ⟨hJ, hJ_max⟩, (is_prime.radical_le_iff hJ_max.is_prime).mpr hJ))
((H.out (radical_idem I)) ▸ (jacobson_mono le_radical))
/-- Fields have only two ideals, and the condition holds for both of them. -/
@[priority 100]
instance is_jacobson_field {K : Type*} [field K] : is_jacobson K :=
⟨λ I hI, or.rec_on (eq_bot_or_top I)
(λ h, le_antisymm
(Inf_le ⟨le_of_eq rfl, (eq.symm h) ▸ bot_is_maximal⟩)
((eq.symm h) ▸ bot_le))
(λ h, by rw [h, jacobson_eq_top_iff])⟩
theorem is_jacobson_of_surjective [H : is_jacobson R] :
(∃ (f : R →+* S), function.surjective f) → is_jacobson S :=
begin
rintros ⟨f, hf⟩,
rw is_jacobson_iff_Inf_maximal,
intros p hp,
use map f '' {J : ideal R | comap f p ≤ J ∧ J.is_maximal },
use λ j ⟨J, hJ, hmap⟩, hmap ▸ or.symm (map_eq_top_or_is_maximal_of_surjective f hf hJ.right),
have : p = map f ((comap f p).jacobson),
from (is_jacobson.out' (comap f p) (by rw [← comap_radical, is_prime.radical hp])).symm
▸ (map_comap_of_surjective f hf p).symm,
exact eq.trans this (map_Inf hf (λ J ⟨hJ, _⟩, le_trans (ideal.ker_le_comap f) hJ)),
end
@[priority 100]
instance is_jacobson_quotient [is_jacobson R] : is_jacobson (quotient I) :=
is_jacobson_of_surjective ⟨quotient.mk I, (by rintro ⟨x⟩; use x; refl)⟩
lemma is_jacobson_iso (e : R ≃+* S) : is_jacobson R ↔ is_jacobson S :=
⟨λ h, @is_jacobson_of_surjective _ _ _ _ h ⟨(e : R →+* S), e.surjective⟩,
λ h, @is_jacobson_of_surjective _ _ _ _ h ⟨(e.symm : S →+* R), e.symm.surjective⟩⟩
lemma is_jacobson_of_is_integral [algebra R S] (hRS : algebra.is_integral R S)
(hR : is_jacobson R) : is_jacobson S :=
begin
rw is_jacobson_iff_prime_eq,
introsI P hP,
by_cases hP_top : comap (algebra_map R S) P = ⊤,
{ simp [comap_eq_top_iff.1 hP_top] },
{ haveI : nontrivial (comap (algebra_map R S) P).quotient := quotient.nontrivial hP_top,
rw jacobson_eq_iff_jacobson_quotient_eq_bot,
refine eq_bot_of_comap_eq_bot (is_integral_quotient_of_is_integral hRS) _,
rw [eq_bot_iff, ← jacobson_eq_iff_jacobson_quotient_eq_bot.1 ((is_jacobson_iff_prime_eq.1 hR)
(comap (algebra_map R S) P) (comap_is_prime _ _)), comap_jacobson],
refine Inf_le_Inf (λ J hJ, _),
simp only [true_and, set.mem_image, bot_le, set.mem_set_of_eq],
haveI : J.is_maximal, { simpa using hJ },
exact exists_ideal_over_maximal_of_is_integral (is_integral_quotient_of_is_integral hRS) J
(comap_bot_le_of_injective _ algebra_map_quotient_injective) }
end
lemma is_jacobson_of_is_integral' (f : R →+* S) (hf : f.is_integral)
(hR : is_jacobson R) : is_jacobson S :=
@is_jacobson_of_is_integral _ _ _ _ f.to_algebra hf hR
end is_jacobson
section localization
open is_localization submonoid
variables {R S : Type*} [comm_ring R] [comm_ring S] {I : ideal R}
variables (y : R) [algebra R S] [is_localization.away y S]
lemma disjoint_powers_iff_not_mem (hI : I.radical = I) :
disjoint ((submonoid.powers y) : set R) ↑I ↔ y ∉ I.1 :=
begin
refine ⟨λ h, set.disjoint_left.1 h (mem_powers _), λ h, (disjoint_iff).mpr (eq_bot_iff.mpr _)⟩,
rintros x ⟨⟨n, rfl⟩, hx'⟩,
rw [← hI] at hx',
exact absurd (hI ▸ mem_radical_of_pow_mem hx' : y ∈ I.carrier) h
end
variables (S)
/-- If `R` is a Jacobson ring, then maximal ideals in the localization at `y`
correspond to maximal ideals in the original ring `R` that don't contain `y`.
This lemma gives the correspondence in the particular case of an ideal and its comap.
See `le_rel_iso_of_maximal` for the more general relation isomorphism -/
lemma is_maximal_iff_is_maximal_disjoint [H : is_jacobson R] (J : ideal S) :
J.is_maximal ↔ (comap (algebra_map R S) J).is_maximal ∧ y ∉ ideal.comap (algebra_map R S) J :=
begin
split,
{ refine λ h, ⟨_, λ hy, h.ne_top (ideal.eq_top_of_is_unit_mem _ hy
(map_units _ ⟨y, submonoid.mem_powers _⟩))⟩,
have hJ : J.is_prime := is_maximal.is_prime h,
rw is_prime_iff_is_prime_disjoint (submonoid.powers y) at hJ,
have : y ∉ (comap (algebra_map R S) J).1 :=
set.disjoint_left.1 hJ.right (submonoid.mem_powers _),
erw [← H.out (is_prime.radical hJ.left), mem_Inf] at this,
push_neg at this,
rcases this with ⟨I, hI, hI'⟩,
convert hI.right,
by_cases hJ : J = map (algebra_map R S) I,
{ rw [hJ, comap_map_of_is_prime_disjoint (powers y) S I (is_maximal.is_prime hI.right)],
rwa disjoint_powers_iff_not_mem y (is_maximal.is_prime hI.right).radical },
{ have hI_p : (map (algebra_map R S) I).is_prime,
{ refine is_prime_of_is_prime_disjoint (powers y) _ I hI.right.is_prime _,
rwa disjoint_powers_iff_not_mem y (is_maximal.is_prime hI.right).radical },
have : J ≤ map (algebra_map R S) I :=
(map_comap (submonoid.powers y) S J) ▸ (map_mono hI.left),
exact absurd (h.1.2 _ (lt_of_le_of_ne this hJ)) hI_p.1 } },
{ refine λ h, ⟨⟨λ hJ, h.1.ne_top (eq_top_iff.2 _), λ I hI, _⟩⟩,
{ rwa [eq_top_iff, ← (is_localization.order_embedding (powers y) S).le_iff_le] at hJ },
{ have := congr_arg (map (algebra_map R S)) (h.1.1.2 _ ⟨comap_mono (le_of_lt hI), _⟩),
rwa [map_comap (powers y) S I, map_top] at this,
refine λ hI', hI.right _,
rw [← map_comap (powers y) S I, ← map_comap (powers y) S J],
exact map_mono hI' } }
end
variables {S}
/-- If `R` is a Jacobson ring, then maximal ideals in the localization at `y`
correspond to maximal ideals in the original ring `R` that don't contain `y`.
This lemma gives the correspondence in the particular case of an ideal and its map.
See `le_rel_iso_of_maximal` for the more general statement, and the reverse of this implication -/
lemma is_maximal_of_is_maximal_disjoint [is_jacobson R] (I : ideal R) (hI : I.is_maximal)
(hy : y ∉ I) : (map (algebra_map R S) I).is_maximal :=
begin
rw [is_maximal_iff_is_maximal_disjoint S y,
comap_map_of_is_prime_disjoint (powers y) S I (is_maximal.is_prime hI)
((disjoint_powers_iff_not_mem y (is_maximal.is_prime hI).radical).2 hy)],
exact ⟨hI, hy⟩
end
/-- If `R` is a Jacobson ring, then maximal ideals in the localization at `y`
correspond to maximal ideals in the original ring `R` that don't contain `y` -/
def order_iso_of_maximal [is_jacobson R] :
{p : ideal S // p.is_maximal} ≃o {p : ideal R // p.is_maximal ∧ y ∉ p} :=
{ to_fun := λ p,
⟨ideal.comap (algebra_map R S) p.1, (is_maximal_iff_is_maximal_disjoint S y p.1).1 p.2⟩,
inv_fun := λ p,
⟨ideal.map (algebra_map R S) p.1, is_maximal_of_is_maximal_disjoint y p.1 p.2.1 p.2.2⟩,
left_inv := λ J, subtype.eq (map_comap (powers y) S J),
right_inv := λ I, subtype.eq (comap_map_of_is_prime_disjoint _ _ I.1 (is_maximal.is_prime I.2.1)
((disjoint_powers_iff_not_mem y I.2.1.is_prime.radical).2 I.2.2)),
map_rel_iff' := λ I I', ⟨λ h, (show I.val ≤ I'.val,
from (map_comap (powers y) S I.val) ▸ (map_comap (powers y) S I'.val) ▸ (ideal.map_mono h)),
λ h x hx, h hx⟩ }
include y
/-- If `S` is the localization of the Jacobson ring `R` at the submonoid generated by `y : R`, then
`S` is Jacobson. -/
lemma is_jacobson_localization [H : is_jacobson R] : is_jacobson S :=
begin
rw is_jacobson_iff_prime_eq,
refine λ P' hP', le_antisymm _ le_jacobson,
obtain ⟨hP', hPM⟩ := (is_localization.is_prime_iff_is_prime_disjoint (powers y) S P').mp hP',
have hP := H.out (is_prime.radical hP'),
refine (le_of_eq (is_localization.map_comap (powers y) S P'.jacobson).symm).trans
((map_mono _).trans (le_of_eq (is_localization.map_comap (powers y) S P'))),
have : Inf { I : ideal R | comap (algebra_map R S) P' ≤ I ∧ I.is_maximal ∧ y ∉ I } ≤
comap (algebra_map R S) P',
{ intros x hx,
have hxy : x * y ∈ (comap (algebra_map R S) P').jacobson,
{ rw [ideal.jacobson, mem_Inf],
intros J hJ,
by_cases y ∈ J,
{ exact J.smul_mem x h },
{ exact (mul_comm y x) ▸ J.smul_mem y ((mem_Inf.1 hx) ⟨hJ.left, ⟨hJ.right, h⟩⟩) } },
rw hP at hxy,
cases hP'.mem_or_mem hxy with hxy hxy,
{ exact hxy },
{ exact (hPM ⟨submonoid.mem_powers _, hxy⟩).elim } },
refine le_trans _ this,
rw [ideal.jacobson, comap_Inf', Inf_eq_infi],
refine infi_le_infi_of_subset (λ I hI, ⟨map (algebra_map R S) I, ⟨_, _⟩⟩),
{ exact ⟨le_trans (le_of_eq ((is_localization.map_comap (powers y) S P').symm)) (map_mono hI.1),
is_maximal_of_is_maximal_disjoint y _ hI.2.1 hI.2.2⟩ },
{ exact is_localization.comap_map_of_is_prime_disjoint _ S I (is_maximal.is_prime hI.2.1)
((disjoint_powers_iff_not_mem y hI.2.1.is_prime.radical).2 hI.2.2) }
end
end localization
namespace polynomial
open polynomial
section comm_ring
variables {R S : Type*} [comm_ring R] [comm_ring S] [integral_domain S]
variables {Rₘ Sₘ : Type*} [comm_ring Rₘ] [comm_ring Sₘ]
/-- If `I` is a prime ideal of `polynomial R` and `pX ∈ I` is a non-constant polynomial,
then the map `R →+* R[x]/I` descends to an integral map when localizing at `pX.leading_coeff`.
In particular `X` is integral because it satisfies `pX`, and constants are trivially integral,
so integrality of the entire extension follows by closure under addition and multiplication. -/
lemma is_integral_is_localization_polynomial_quotient
(P : ideal (polynomial R)) (pX : polynomial R) (hpX : pX ∈ P)
[algebra (P.comap (C : R →+* _)).quotient Rₘ]
[is_localization.away (pX.map (quotient.mk (P.comap C))).leading_coeff Rₘ]
[algebra P.quotient Sₘ]
[is_localization ((submonoid.powers (pX.map (quotient.mk (P.comap C))).leading_coeff).map
(quotient_map P C le_rfl) : submonoid P.quotient) Sₘ] :
(is_localization.map Sₘ (quotient_map P C le_rfl)
((submonoid.powers (pX.map (quotient.mk (P.comap C))).leading_coeff).le_comap_map) : Rₘ →+* _)
.is_integral :=
begin
let P' : ideal R := P.comap C,
let M : submonoid P'.quotient :=
submonoid.powers (pX.map (quotient.mk (P.comap C))).leading_coeff,
let M' : submonoid P.quotient :=
(submonoid.powers (pX.map (quotient.mk (P.comap C))).leading_coeff).map (quotient_map P C le_rfl),
let φ : P'.quotient →+* P.quotient := quotient_map P C le_rfl,
let φ' := is_localization.map Sₘ φ M.le_comap_map,
have hφ' : φ.comp (quotient.mk P') = (quotient.mk P).comp C := rfl,
intro p,
obtain ⟨⟨p', ⟨q, hq⟩⟩, hp⟩ := is_localization.surj M' p,
suffices : φ'.is_integral_elem (algebra_map _ _ p'),
{ obtain ⟨q', hq', rfl⟩ := hq,
obtain ⟨q'', hq''⟩ := is_unit_iff_exists_inv'.1 (is_localization.map_units Rₘ (⟨q', hq'⟩ : M)),
refine φ'.is_integral_of_is_integral_mul_unit p (algebra_map _ _ (φ q')) q'' _ (hp.symm ▸ this),
convert trans (trans (φ'.map_mul _ _).symm (congr_arg φ' hq'')) φ'.map_one using 2,
rw [← φ'.comp_apply, is_localization.map_comp, ring_hom.comp_apply, subtype.coe_mk] },
refine is_integral_of_mem_closure''
(((algebra_map _ Sₘ).comp (quotient.mk P)) '' (insert X {p | p.degree ≤ 0})) _ _ _,
{ rintros x ⟨p, hp, rfl⟩,
refine hp.rec_on (λ hy, _) (λ hy, _),
{ refine hy.symm ▸ (φ.is_integral_elem_localization_at_leading_coeff ((quotient.mk P) X)
(pX.map (quotient.mk P')) _ M ⟨1, pow_one _⟩),
rwa [eval₂_map, hφ', ← hom_eval₂, quotient.eq_zero_iff_mem, eval₂_C_X] },
{ rw [set.mem_set_of_eq, degree_le_zero_iff] at hy,
refine hy.symm ▸ ⟨X - C (algebra_map _ _ ((quotient.mk P') (p.coeff 0))), monic_X_sub_C _, _⟩,
simp only [eval₂_sub, eval₂_C, eval₂_X],
rw [sub_eq_zero, ← φ'.comp_apply, is_localization.map_comp],
refl } },
{ obtain ⟨p, rfl⟩ := quotient.mk_surjective p',
refine polynomial.induction_on p
(λ r, subring.subset_closure $ set.mem_image_of_mem _ (or.inr degree_C_le))
(λ _ _ h1 h2, _) (λ n _ hr, _),
{ convert subring.add_mem _ h1 h2,
rw [ring_hom.map_add, ring_hom.map_add] },
{ rw [pow_succ X n, mul_comm X, ← mul_assoc, ring_hom.map_mul, ring_hom.map_mul],
exact subring.mul_mem _ hr (subring.subset_closure (set.mem_image_of_mem _ (or.inl rfl))) } },
end
/-- If `f : R → S` descends to an integral map in the localization at `x`,
and `R` is a Jacobson ring, then the intersection of all maximal ideals in `S` is trivial -/
lemma jacobson_bot_of_integral_localization
{R : Type*} [comm_ring R] [integral_domain R] [is_jacobson R]
(Rₘ Sₘ : Type*) [comm_ring Rₘ] [comm_ring Sₘ]
(φ : R →+* S) (hφ : function.injective φ) (x : R) (hx : x ≠ 0)
[algebra R Rₘ] [is_localization.away x Rₘ]
[algebra S Sₘ] [is_localization ((submonoid.powers x).map φ : submonoid S) Sₘ]
(hφ' : ring_hom.is_integral
(is_localization.map Sₘ φ (submonoid.powers x).le_comap_map : Rₘ →+* Sₘ)) :
(⊥ : ideal S).jacobson = (⊥ : ideal S) :=
begin
have hM : ((submonoid.powers x).map φ : submonoid S) ≤ non_zero_divisors S :=
φ.map_le_non_zero_divisors_of_injective hφ (powers_le_non_zero_divisors_of_no_zero_divisors hx),
letI : integral_domain Sₘ := is_localization.integral_domain_of_le_non_zero_divisors _ hM,
let φ' : Rₘ →+* Sₘ := is_localization.map _ φ (submonoid.powers x).le_comap_map,
suffices : ∀ I : ideal Sₘ, I.is_maximal → (I.comap (algebra_map S Sₘ)).is_maximal,
{ have hϕ' : comap (algebra_map S Sₘ) (⊥ : ideal Sₘ) = (⊥ : ideal S),
{ rw [← ring_hom.ker_eq_comap_bot, ← ring_hom.injective_iff_ker_eq_bot],
exact is_localization.injective Sₘ hM },
have hSₘ : is_jacobson Sₘ := is_jacobson_of_is_integral' φ' hφ' (is_jacobson_localization x),
refine eq_bot_iff.mpr (le_trans _ (le_of_eq hϕ')),
rw [← hSₘ.out radical_bot_of_integral_domain, comap_jacobson],
exact Inf_le_Inf (λ j hj, ⟨bot_le, let ⟨J, hJ⟩ := hj in hJ.2 ▸ this J hJ.1.2⟩) },
introsI I hI,
-- Remainder of the proof is pulling and pushing ideals around the square and the quotient square
haveI : (I.comap (algebra_map S Sₘ)).is_prime := comap_is_prime _ I,
haveI : (I.comap φ').is_prime := comap_is_prime φ' I,
haveI : (⊥ : ideal (I.comap (algebra_map S Sₘ)).quotient).is_prime := bot_prime,
have hcomm: φ'.comp (algebra_map R Rₘ) = (algebra_map S Sₘ).comp φ := is_localization.map_comp _,
let f := quotient_map (I.comap (algebra_map S Sₘ)) φ le_rfl,
let g := quotient_map I (algebra_map S Sₘ) le_rfl,
have := is_maximal_comap_of_is_integral_of_is_maximal' φ' hφ' I
(by convert hI; casesI _inst_4; refl),
have := ((is_maximal_iff_is_maximal_disjoint Rₘ x _).1 this).left,
have : ((I.comap (algebra_map S Sₘ)).comap φ).is_maximal,
{ rwa [comap_comap, hcomm, ← comap_comap] at this },
rw ← bot_quotient_is_maximal_iff at this ⊢,
refine is_maximal_of_is_integral_of_is_maximal_comap' f _ ⊥
((eq_bot_iff.2 (comap_bot_le_of_injective f quotient_map_injective)).symm ▸ this),
exact f.is_integral_tower_bot_of_is_integral g quotient_map_injective
((comp_quotient_map_eq_of_comp_eq hcomm I).symm ▸
(ring_hom.is_integral_trans _ _ (ring_hom.is_integral_of_surjective _
(is_localization.surjective_quotient_map_of_maximal_of_localization (submonoid.powers x) Rₘ
(by rwa [comap_comap, hcomm, ← bot_quotient_is_maximal_iff])))
(ring_hom.is_integral_quotient_of_is_integral _ hφ'))),
end
/-- Used to bootstrap the proof of `is_jacobson_polynomial_iff_is_jacobson`.
That theorem is more general and should be used instead of this one. -/
private lemma is_jacobson_polynomial_of_domain
(R : Type*) [comm_ring R] [integral_domain R] [hR : is_jacobson R]
(P : ideal (polynomial R)) [is_prime P] (hP : ∀ (x : R), C x ∈ P → x = 0) :
P.jacobson = P :=
begin
by_cases Pb : P = ⊥,
{ exact Pb.symm ▸ jacobson_bot_polynomial_of_jacobson_bot
(hR.out radical_bot_of_integral_domain) },
{ rw jacobson_eq_iff_jacobson_quotient_eq_bot,
haveI : (P.comap (C : R →+* polynomial R)).is_prime := comap_is_prime C P,
obtain ⟨p, pP, p0⟩ := exists_nonzero_mem_of_ne_bot Pb hP,
let x := (polynomial.map (quotient.mk (comap (C : R →+* _) P)) p).leading_coeff,
have hx : x ≠ 0 := by rwa [ne.def, leading_coeff_eq_zero],
refine jacobson_bot_of_integral_localization
(localization.away x)
(localization ((submonoid.powers x).map (P.quotient_map C le_rfl) : submonoid P.quotient))
(quotient_map P C le_rfl) quotient_map_injective
x hx
_,
-- `convert` is noticeably faster than `exact` here:
convert is_integral_is_localization_polynomial_quotient P p pP }
end
lemma is_jacobson_polynomial_of_is_jacobson (hR : is_jacobson R) :
is_jacobson (polynomial R) :=
begin
refine is_jacobson_iff_prime_eq.mpr (λ I, _),
introI hI,
let R' : subring I.quotient := ((quotient.mk I).comp C).range,
let i : R →+* R' := ((quotient.mk I).comp C).range_restrict,
have hi : function.surjective (i : R → R') := ((quotient.mk I).comp C).range_restrict_surjective,
have hi' : (polynomial.map_ring_hom i : polynomial R →+* polynomial R').ker ≤ I,
{ refine λ f hf, polynomial_mem_ideal_of_coeff_mem_ideal I f (λ n, _),
replace hf := congr_arg (λ (g : polynomial (((quotient.mk I).comp C).range)), g.coeff n) hf,
change (polynomial.map ((quotient.mk I).comp C).range_restrict f).coeff n = 0 at hf,
rw [coeff_map, subtype.ext_iff] at hf,
rwa [mem_comap, ← quotient.eq_zero_iff_mem, ← ring_hom.comp_apply], },
haveI : (ideal.map (map_ring_hom i) I).is_prime :=
map_is_prime_of_surjective (map_surjective i hi) hi',
suffices : (I.map (polynomial.map_ring_hom i)).jacobson = (I.map (polynomial.map_ring_hom i)),
{ replace this := congr_arg (comap (polynomial.map_ring_hom i)) this,
rw [← map_jacobson_of_surjective _ hi',
comap_map_of_surjective _ _, comap_map_of_surjective _ _] at this,
refine le_antisymm (le_trans (le_sup_of_le_left le_rfl)
(le_trans (le_of_eq this) (sup_le le_rfl hi'))) le_jacobson,
all_goals {exact polynomial.map_surjective i hi} },
exact @is_jacobson_polynomial_of_domain R' _ _ (is_jacobson_of_surjective ⟨i, hi⟩)
(map (map_ring_hom i) I) _ (eq_zero_of_polynomial_mem_map_range I),
end
theorem is_jacobson_polynomial_iff_is_jacobson :
is_jacobson (polynomial R) ↔ is_jacobson R :=
begin
refine ⟨_, is_jacobson_polynomial_of_is_jacobson⟩,
introI H,
exact is_jacobson_of_surjective ⟨eval₂_ring_hom (ring_hom.id _) 1, λ x,
⟨C x, by simp only [coe_eval₂_ring_hom, ring_hom.id_apply, eval₂_C]⟩⟩,
end
instance [is_jacobson R] : is_jacobson (polynomial R) :=
is_jacobson_polynomial_iff_is_jacobson.mpr ‹is_jacobson R›
end comm_ring
section integral_domain
variables {R : Type*} [comm_ring R] [is_jacobson R]
variables (P : ideal (polynomial R)) [hP : P.is_maximal]
include P hP
lemma is_maximal_comap_C_of_is_maximal [nontrivial R] (hP' : ∀ (x : R), C x ∈ P → x = 0) :
is_maximal (comap C P : ideal R) :=
begin
haveI hp'_prime : (P.comap C : ideal R).is_prime := comap_is_prime C P,
obtain ⟨m, hm⟩ := submodule.nonzero_mem_of_bot_lt (bot_lt_of_maximal P polynomial_not_is_field),
have : (m : polynomial R) ≠ 0, rwa [ne.def, submodule.coe_eq_zero],
let φ : (P.comap C : ideal R).quotient →+* P.quotient := quotient_map P C le_rfl,
let M : submonoid (P.comap C : ideal R).quotient :=
submonoid.powers ((m : polynomial R).map (quotient.mk (P.comap C : ideal R))).leading_coeff,
rw ← bot_quotient_is_maximal_iff,
have hp0 : ((m : polynomial R).map (quotient.mk (P.comap C : ideal R))).leading_coeff ≠ 0 :=
λ hp0', this $ map_injective (quotient.mk (P.comap C : ideal R))
((quotient.mk (P.comap C : ideal R)).injective_iff.2 (λ x hx,
by rwa [quotient.eq_zero_iff_mem, (by rwa eq_bot_iff : (P.comap C : ideal R) = ⊥)] at hx))
(by simpa only [leading_coeff_eq_zero, map_zero] using hp0'),
have hM : (0 : ((P.comap C : ideal R)).quotient) ∉ M := λ ⟨n, hn⟩, hp0 (pow_eq_zero hn),
suffices : (⊥ : ideal (localization M)).is_maximal,
{ rw ← is_localization.comap_map_of_is_prime_disjoint M (localization M) ⊥ bot_prime
(λ x hx, hM (hx.2 ▸ hx.1)),
refine ((is_maximal_iff_is_maximal_disjoint (localization M) _ _).mp (by rwa map_bot)).1,
swap, exact localization.is_localization },
let M' : submonoid P.quotient := M.map φ,
have hM' : (0 : P.quotient) ∉ M' :=
λ ⟨z, hz⟩, hM (quotient_map_injective (trans hz.2 φ.map_zero.symm) ▸ hz.1),
haveI : integral_domain (localization M') :=
is_localization.integral_domain_localization (le_non_zero_divisors_of_no_zero_divisors hM'),
suffices : (⊥ : ideal (localization M')).is_maximal,
{ rw le_antisymm bot_le (comap_bot_le_of_injective _ (is_localization.map_injective_of_injective
M (localization M) (localization M')
quotient_map_injective (le_non_zero_divisors_of_no_zero_divisors hM'))),
refine is_maximal_comap_of_is_integral_of_is_maximal' _ _ ⊥ this,
apply is_integral_is_localization_polynomial_quotient P _ (submodule.coe_mem m) },
rw (map_bot.symm : (⊥ : ideal (localization M')) =
map (algebra_map P.quotient (localization M')) ⊥),
let bot_maximal := ((bot_quotient_is_maximal_iff _).mpr hP),
refine map.is_maximal (algebra_map _ _) (localization_map_bijective_of_field hM' _) bot_maximal,
rwa [← quotient.maximal_ideal_iff_is_field_quotient, ← bot_quotient_is_maximal_iff],
end
/-- Used to bootstrap the more general `quotient_mk_comp_C_is_integral_of_jacobson` -/
private lemma quotient_mk_comp_C_is_integral_of_jacobson' [nontrivial R] (hR : is_jacobson R)
(hP' : ∀ (x : R), C x ∈ P → x = 0) :
((quotient.mk P).comp C : R →+* P.quotient).is_integral :=
begin
refine (is_integral_quotient_map_iff _).mp _,
let P' : ideal R := P.comap C,
obtain ⟨pX, hpX, hp0⟩ :=
exists_nonzero_mem_of_ne_bot (ne_of_lt (bot_lt_of_maximal P polynomial_not_is_field)).symm hP',
let M : submonoid P'.quotient := submonoid.powers (pX.map (quotient.mk P')).leading_coeff,
let φ : P'.quotient →+* P.quotient := quotient_map P C le_rfl,
haveI hp'_prime : P'.is_prime := comap_is_prime C P,
have hM : (0 : P'.quotient) ∉ M := λ ⟨n, hn⟩, hp0 $ leading_coeff_eq_zero.mp (pow_eq_zero hn),
let M' : submonoid P.quotient := M.map (quotient_map P C le_rfl),
refine ((quotient_map P C le_rfl).is_integral_tower_bot_of_is_integral
(algebra_map _ (localization M')) _ _),
{ refine is_localization.injective (localization M')
(show M' ≤ _, from le_non_zero_divisors_of_no_zero_divisors (λ hM', hM _)),
exact (let ⟨z, zM, z0⟩ := hM' in (quotient_map_injective (trans z0 φ.map_zero.symm)) ▸ zM) },
{ rw ← is_localization.map_comp M.le_comap_map,
refine ring_hom.is_integral_trans (algebra_map P'.quotient (localization M))
(is_localization.map _ _ M.le_comap_map) _ _,
{ exact (algebra_map P'.quotient (localization M)).is_integral_of_surjective
(localization_map_bijective_of_field hM
((quotient.maximal_ideal_iff_is_field_quotient _).mp
(is_maximal_comap_C_of_is_maximal P hP'))).2 },
{ -- `convert` here is faster than `exact`, and this proof is near the time limit.
convert is_integral_is_localization_polynomial_quotient P pX hpX } }
end
/-- If `R` is a Jacobson ring, and `P` is a maximal ideal of `polynomial R`,
then `R → (polynomial R)/P` is an integral map. -/
lemma quotient_mk_comp_C_is_integral_of_jacobson :
((quotient.mk P).comp C : R →+* P.quotient).is_integral :=
begin
let P' : ideal R := P.comap C,
haveI : P'.is_prime := comap_is_prime C P,
let f : polynomial R →+* polynomial P'.quotient := polynomial.map_ring_hom (quotient.mk P'),
have hf : function.surjective f := map_surjective (quotient.mk P') quotient.mk_surjective,
have hPJ : P = (P.map f).comap f,
{ rw comap_map_of_surjective _ hf,
refine le_antisymm (le_sup_of_le_left le_rfl) (sup_le le_rfl _),
refine λ p hp, polynomial_mem_ideal_of_coeff_mem_ideal P p (λ n, quotient.eq_zero_iff_mem.mp _),
simpa only [coeff_map, coe_map_ring_hom] using (polynomial.ext_iff.mp hp) n },
refine ring_hom.is_integral_tower_bot_of_is_integral _ _ (injective_quotient_le_comap_map P) _,
rw ← quotient_mk_maps_eq,
refine ring_hom.is_integral_trans _ _
((quotient.mk P').is_integral_of_surjective quotient.mk_surjective) _,
apply quotient_mk_comp_C_is_integral_of_jacobson' _ _ (λ x hx, _),
any_goals { exact ideal.is_jacobson_quotient },
{ exact or.rec_on (map_eq_top_or_is_maximal_of_surjective f hf hP)
(λ h, absurd (trans (h ▸ hPJ : P = comap f ⊤) comap_top : P = ⊤) hP.ne_top) id },
{ apply_instance, },
{ obtain ⟨z, rfl⟩ := quotient.mk_surjective x,
rwa [quotient.eq_zero_iff_mem, mem_comap, hPJ, mem_comap, coe_map_ring_hom, map_C] }
end
lemma is_maximal_comap_C_of_is_jacobson :
(P.comap (C : R →+* polynomial R)).is_maximal :=
begin
rw [← @mk_ker _ _ P, ring_hom.ker_eq_comap_bot, comap_comap],
exact is_maximal_comap_of_is_integral_of_is_maximal' _
(quotient_mk_comp_C_is_integral_of_jacobson P) ⊥ ((bot_quotient_is_maximal_iff _).mpr hP),
end
omit P hP
lemma comp_C_integral_of_surjective_of_jacobson
{S : Type*} [field S] (f : (polynomial R) →+* S) (hf : function.surjective f) :
(f.comp C).is_integral :=
begin
haveI : (f.ker).is_maximal := f.ker_is_maximal_of_surjective hf,
let g : f.ker.quotient →+* S := ideal.quotient.lift f.ker f (λ _ h, h),
have hfg : (g.comp (quotient.mk f.ker)) = f := ring_hom_ext' rfl rfl,
rw [← hfg, ring_hom.comp_assoc],
refine ring_hom.is_integral_trans _ g (quotient_mk_comp_C_is_integral_of_jacobson f.ker)
(g.is_integral_of_surjective _), --(quotient.lift_surjective f.ker f _ hf)),
rw [← hfg] at hf,
exact function.surjective.of_comp hf,
end
end integral_domain
end polynomial
namespace mv_polynomial
open mv_polynomial ring_hom
lemma is_jacobson_mv_polynomial_fin {R : Type*} [comm_ring R] [H : is_jacobson R] :
∀ (n : ℕ), is_jacobson (mv_polynomial (fin n) R)
| 0 := ((is_jacobson_iso ((rename_equiv R
(equiv.equiv_pempty (fin 0))).to_ring_equiv.trans (is_empty_ring_equiv R pempty))).mpr H)
| (n+1) := (is_jacobson_iso (fin_succ_equiv R n).to_ring_equiv).2
(polynomial.is_jacobson_polynomial_iff_is_jacobson.2 (is_jacobson_mv_polynomial_fin n))
/-- General form of the nullstellensatz for Jacobson rings, since in a Jacobson ring we have
`Inf {P maximal | P ≥ I} = Inf {P prime | P ≥ I} = I.radical`. Fields are always Jacobson,
and in that special case this is (most of) the classical Nullstellensatz,
since `I(V(I))` is the intersection of maximal ideals containing `I`, which is then `I.radical` -/
instance {R : Type*} [comm_ring R] {ι : Type*} [fintype ι] [is_jacobson R] :
is_jacobson (mv_polynomial ι R) :=
begin
haveI := classical.dec_eq ι,
let e := fintype.equiv_fin ι,
rw is_jacobson_iso (rename_equiv R e).to_ring_equiv,
exact is_jacobson_mv_polynomial_fin _
end
variables {n : ℕ}
lemma quotient_mk_comp_C_is_integral_of_jacobson
{R : Type*} [comm_ring R] [is_jacobson R]
(P : ideal (mv_polynomial (fin n) R)) [P.is_maximal] :
((quotient.mk P).comp mv_polynomial.C : R →+* P.quotient).is_integral :=
begin
unfreezingI {induction n with n IH},
{ refine ring_hom.is_integral_of_surjective _ (function.surjective.comp quotient.mk_surjective _),
exact C_surjective (fin 0) },
{ rw [← fin_succ_equiv_comp_C_eq_C, ← ring_hom.comp_assoc, ← ring_hom.comp_assoc,
← quotient_map_comp_mk le_rfl, ring_hom.comp_assoc (polynomial.C),
← quotient_map_comp_mk le_rfl, ring_hom.comp_assoc, ring_hom.comp_assoc,
← quotient_map_comp_mk le_rfl, ← ring_hom.comp_assoc (quotient.mk _)],
refine ring_hom.is_integral_trans _ _ _ _,
{ refine ring_hom.is_integral_trans _ _ (is_integral_of_surjective _ quotient.mk_surjective) _,
refine ring_hom.is_integral_trans _ _ _ _,
{ apply (is_integral_quotient_map_iff _).mpr (IH _),
apply polynomial.is_maximal_comap_C_of_is_jacobson _,
{ exact mv_polynomial.is_jacobson_mv_polynomial_fin n },
{ apply comap_is_maximal_of_surjective,
exact (fin_succ_equiv R n).symm.surjective } },
{ refine (is_integral_quotient_map_iff _).mpr _,
rw ← quotient_map_comp_mk le_rfl,
refine ring_hom.is_integral_trans _ _ _ ((is_integral_quotient_map_iff _).mpr _),
{ exact ring_hom.is_integral_of_surjective _ quotient.mk_surjective },
{ apply polynomial.quotient_mk_comp_C_is_integral_of_jacobson _,
{ exact mv_polynomial.is_jacobson_mv_polynomial_fin n },
{ exact comap_is_maximal_of_surjective _ (fin_succ_equiv R n).symm.surjective } } } },
{ refine (is_integral_quotient_map_iff _).mpr _,
refine ring_hom.is_integral_trans _ _ _ (is_integral_of_surjective _ quotient.mk_surjective),
exact ring_hom.is_integral_of_surjective _ (fin_succ_equiv R n).symm.surjective } }
end
lemma comp_C_integral_of_surjective_of_jacobson
{R : Type*} [comm_ring R] [is_jacobson R]
{σ : Type*} [fintype σ] {S : Type*} [field S] (f : mv_polynomial σ R →+* S)
(hf : function.surjective f) : (f.comp C).is_integral :=
begin
haveI := classical.dec_eq σ,
obtain ⟨e⟩ := fintype.trunc_equiv_fin σ,
let f' : mv_polynomial (fin _) R →+* S :=
f.comp (rename_equiv R e.symm).to_ring_equiv.to_ring_hom,
have hf' : function.surjective f' :=
((function.surjective.comp hf (rename_equiv R e.symm).surjective)),
have : (f'.comp C).is_integral,
{ haveI : (f'.ker).is_maximal := f'.ker_is_maximal_of_surjective hf',
let g : f'.ker.quotient →+* S := ideal.quotient.lift f'.ker f' (λ _ h, h),
have hfg : (g.comp (quotient.mk f'.ker)) = f' := ring_hom_ext (λ r, rfl) (λ i, rfl),
rw [← hfg, ring_hom.comp_assoc],
refine ring_hom.is_integral_trans _ g (quotient_mk_comp_C_is_integral_of_jacobson f'.ker)
(g.is_integral_of_surjective _),
rw ← hfg at hf',
exact function.surjective.of_comp hf' },
rw ring_hom.comp_assoc at this,
convert this,
refine ring_hom.ext (λ x, _),
exact ((rename_equiv R e.symm).commutes' x).symm,
end
end mv_polynomial
end ideal
|
06b93c8b908d157fa8b9c9732272edbcebd02b16 | cf39355caa609c0f33405126beee2739aa3cb77e | /tests/lean/run/simp_norm.lean | 2566a458c7e00f7820dc33aa3ae4ce81c69ab0d4 | [
"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 | 456 | lean | universes u v
axiom map_bind_lemma : ∀ {α β : Type u} {m : Type u → Type v} [monad m] (f : α → β) (x : m α), f <$> x = x >>= pure ∘ f
attribute [norm] function.comp map_bind_lemma
example : nat.succ <$> [1, 2] = [2, 3] :=
begin
simp with norm,
guard_target
@eq (list nat)
(@bind (λ (α : Type), list α) _ _ _
[1, 2]
(λ x, pure (nat.succ x)))
[2, 3],
simp [has_bind.bind, pure, has_pure.pure, list.ret]
end
|
12f27d8346b28e5559979f872ee2d08c44faac29 | d406927ab5617694ec9ea7001f101b7c9e3d9702 | /src/order/conditionally_complete_lattice/finset.lean | 182242ff9b5c6086aa86dfc34856e77bbfdca0ab | [
"Apache-2.0"
] | permissive | alreadydone/mathlib | dc0be621c6c8208c581f5170a8216c5ba6721927 | c982179ec21091d3e102d8a5d9f5fe06c8fafb73 | refs/heads/master | 1,685,523,275,196 | 1,670,184,141,000 | 1,670,184,141,000 | 287,574,545 | 0 | 0 | Apache-2.0 | 1,670,290,714,000 | 1,597,421,623,000 | Lean | UTF-8 | Lean | false | false | 3,382 | lean | /-
Copyright (c) 2018 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 order.conditionally_complete_lattice.basic
import data.set.finite
/-!
# Conditionally complete lattices and finite sets.
-/
open set
variables {α β γ : Type*}
section conditionally_complete_lattice
variables [conditionally_complete_lattice α] {s t : set α} {a b : α}
lemma finset.nonempty.sup'_eq_cSup_image {s : finset β} (hs : s.nonempty) (f : β → α) :
s.sup' hs f = Sup (f '' s) :=
eq_of_forall_ge_iff $ λ a,
by simp [cSup_le_iff (s.finite_to_set.image f).bdd_above (hs.to_set.image f)]
lemma finset.nonempty.sup'_id_eq_cSup {s : finset α} (hs : s.nonempty) :
s.sup' hs id = Sup s :=
by rw [hs.sup'_eq_cSup_image, image_id]
end conditionally_complete_lattice
section conditionally_complete_linear_order
variables [conditionally_complete_linear_order α] {s t : set α} {a b : α}
lemma finset.nonempty.cSup_eq_max' {s : finset α} (h : s.nonempty) : Sup ↑s = s.max' h :=
eq_of_forall_ge_iff $ λ a, (cSup_le_iff s.bdd_above h.to_set).trans (s.max'_le_iff h).symm
lemma finset.nonempty.cInf_eq_min' {s : finset α} (h : s.nonempty) : Inf ↑s = s.min' h :=
@finset.nonempty.cSup_eq_max' αᵒᵈ _ s h
lemma finset.nonempty.cSup_mem {s : finset α} (h : s.nonempty) : Sup (s : set α) ∈ s :=
by { rw h.cSup_eq_max', exact s.max'_mem _ }
lemma finset.nonempty.cInf_mem {s : finset α} (h : s.nonempty) : Inf (s : set α) ∈ s :=
@finset.nonempty.cSup_mem αᵒᵈ _ _ h
lemma set.nonempty.cSup_mem (h : s.nonempty) (hs : s.finite) : Sup s ∈ s :=
by { lift s to finset α using hs, exact finset.nonempty.cSup_mem h }
lemma set.nonempty.cInf_mem (h : s.nonempty) (hs : s.finite) : Inf s ∈ s :=
@set.nonempty.cSup_mem αᵒᵈ _ _ h hs
lemma set.finite.cSup_lt_iff (hs : s.finite) (h : s.nonempty) : Sup s < a ↔ ∀ x ∈ s, x < a :=
⟨λ h x hx, (le_cSup hs.bdd_above hx).trans_lt h, λ H, H _ $ h.cSup_mem hs⟩
lemma set.finite.lt_cInf_iff (hs : s.finite) (h : s.nonempty) : a < Inf s ↔ ∀ x ∈ s, a < x :=
@set.finite.cSup_lt_iff αᵒᵈ _ _ _ hs h
end conditionally_complete_linear_order
/-!
### Relation between `Sup` / `Inf` and `finset.sup'` / `finset.inf'`
Like the `Sup` of a `conditionally_complete_lattice`, `finset.sup'` also requires the set to be
non-empty. As a result, we can translate between the two.
-/
namespace finset
lemma sup'_eq_cSup_image [conditionally_complete_lattice β] (s : finset α) (H) (f : α → β) :
s.sup' H f = Sup (f '' s) :=
begin
apply le_antisymm,
{ refine (finset.sup'_le _ _ $ λ a ha, _),
refine le_cSup ⟨s.sup' H f, _⟩ ⟨a, ha, rfl⟩,
rintros i ⟨j, hj, rfl⟩,
exact finset.le_sup' _ hj },
{ apply cSup_le ((coe_nonempty.mpr H).image _),
rintros _ ⟨a, ha, rfl⟩,
exact finset.le_sup' _ ha, }
end
lemma inf'_eq_cInf_image [conditionally_complete_lattice β] (s : finset α) (H) (f : α → β) :
s.inf' H f = Inf (f '' s) :=
@sup'_eq_cSup_image _ βᵒᵈ _ _ H _
lemma sup'_id_eq_cSup [conditionally_complete_lattice α] (s : finset α) (H) :
s.sup' H id = Sup s :=
by rw [sup'_eq_cSup_image s H, set.image_id]
lemma inf'_id_eq_cInf [conditionally_complete_lattice α] (s : finset α) (H) :
s.inf' H id = Inf s :=
@sup'_id_eq_cSup αᵒᵈ _ _ H
end finset
|
da695201296f66169f55acede9bd9dec5a199c0b | 0c1546a496eccfb56620165cad015f88d56190c5 | /library/tools/super/prover.lean | d1f2610715b95efb5ac53c72532cacfc0809d24a | [
"Apache-2.0"
] | permissive | Solertis/lean | 491e0939957486f664498fbfb02546e042699958 | 84188c5aa1673fdf37a082b2de8562dddf53df3f | refs/heads/master | 1,610,174,257,606 | 1,486,263,620,000 | 1,486,263,620,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 3,642 | lean | /-
Copyright (c) 2016 Gabriel Ebner. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Gabriel Ebner
-/
import .clause .prover_state
import .misc_preprocessing
import .selection
import .trim
-- default inferences
-- 0
import .clausifier
-- 10
import .demod
import .inhabited
import .datatypes
-- 20
import .subsumption
-- 30
import .splitting
-- 40
import .factoring
import .resolution
import .superposition
import .equality
import .simp
import .defs
open monad tactic expr
declare_trace super
namespace super
meta def trace_clauses : prover unit :=
do state ← state_t.read, trace state
meta def run_prover_loop
(literal_selection : selection_strategy)
(clause_selection : clause_selection_strategy)
(preprocessing_rules : list (prover unit))
(inference_rules : list inference)
: ℕ → prover (option expr) | i := do
sequence' preprocessing_rules,
new ← take_newly_derived, for' new register_as_passive,
when (is_trace_enabled_for `super) $ for' new $ λn,
tactic.trace { n with c := { (n^.c) with proof := const (mk_simple_name "derived") [] } },
needs_sat_run ← flip monad.lift state_t.read (λst, st^.needs_sat_run),
if needs_sat_run then do
res ← do_sat_run,
match res with
| some proof := return (some proof)
| none := do
model ← flip monad.lift state_t.read (λst, st^.current_model),
when (is_trace_enabled_for `super) (do
pp_model ← pp (model^.to_list^.for (λlit, if lit.2 = tt then lit.1 else not_ lit.1)),
trace $ to_fmt "sat model: " ++ pp_model),
run_prover_loop i
end
else do
passive ← get_passive,
if rb_map.size passive = 0 then return none else do
given_name ← clause_selection i,
given ← option.to_monad (rb_map.find passive given_name),
-- trace_clauses,
remove_passive given_name,
given ← literal_selection given,
when (is_trace_enabled_for `super) (do
fmt ← pp given, trace (to_fmt "given: " ++ fmt)),
add_active given,
seq_inferences inference_rules given,
run_prover_loop (i+1)
meta def default_preprocessing : list (prover unit) :=
[
clausify_pre,
clause_normalize_pre,
factor_dup_lits_pre,
remove_duplicates_pre,
refl_r_pre,
diff_constr_eq_l_pre,
tautology_removal_pre,
subsumption_interreduction_pre,
forward_subsumption_pre,
return ()
]
end super
open super
meta def super (sos_lemmas : list expr) : tactic unit := with_trim $ do
as_refutation, local_false ← target,
clauses ← clauses_of_context,
sos_clauses ← monad.for sos_lemmas (clause.of_proof local_false),
initial_state ← prover_state.initial local_false (clauses ++ sos_clauses),
inf_names ← attribute.get_instances `super.inf,
infs ← for inf_names $ λn, eval_expr inf_decl (const n []),
infs ← return $ list.map inf_decl.inf $ list.sort_on inf_decl.prio infs,
res ← run_prover_loop selection21 (age_weight_clause_selection 3 4)
default_preprocessing infs
0 initial_state,
match res with
| (some empty_clause, st) := apply empty_clause
| (none, saturation) := do sat_fmt ← pp saturation,
fail $ to_fmt "saturation:" ++ format.line ++ sat_fmt
end
namespace tactic.interactive
open interactive
meta def with_lemmas (ls : types.raw_ident_list) : tactic unit := monad.for' ls $ λl, do
p ← mk_const l,
t ← infer_type p,
n ← get_unused_name p^.get_app_fn^.const_name none,
tactic.assertv n t p
meta def super (extra_clause_names : types.raw_ident_list)
(extra_lemma_names : types.with_ident_list) : tactic unit := do
with_lemmas extra_clause_names,
extra_lemmas ← monad.for extra_lemma_names mk_const,
_root_.super extra_lemmas
end tactic.interactive
|
2811a35fb6d7302817b276be7d5050ca451429f4 | 302c785c90d40ad3d6be43d33bc6a558354cc2cf | /src/order/order_iso_nat.lean | d4822422c62f8ca900f312d31f357d4ab8c89cd7 | [
"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 | 6,000 | lean | /-
Copyright (c) 2017 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import data.nat.basic
import data.equiv.denumerable
import data.set.finite
import order.rel_iso
import logic.function.iterate
namespace rel_embedding
variables {α : Type*} {r : α → α → Prop} [is_strict_order α r]
/-- If `f` is a strictly `r`-increasing sequence, then this returns `f` as an order embedding. -/
def nat_lt (f : ℕ → α) (H : ∀ n:ℕ, r (f n) (f (n+1))) :
((<) : ℕ → ℕ → Prop) ↪r r :=
of_monotone f $ λ a b h, begin
induction b with b IH, {exact (nat.not_lt_zero _ h).elim},
cases nat.lt_succ_iff_lt_or_eq.1 h with h e,
{ exact trans (IH h) (H _) },
{ subst b, apply H }
end
@[simp]
lemma nat_lt_apply {f : ℕ → α} {H : ∀ n:ℕ, r (f n) (f (n+1))} {n : ℕ} : nat_lt f H n = f n := rfl
/-- If `f` is a strictly `r`-decreasing sequence, then this returns `f` as an order embedding. -/
def nat_gt (f : ℕ → α) (H : ∀ n:ℕ, r (f (n+1)) (f n)) :
((>) : ℕ → ℕ → Prop) ↪r r :=
by haveI := is_strict_order.swap r; exact rel_embedding.swap (nat_lt f H)
theorem well_founded_iff_no_descending_seq :
well_founded r ↔ ¬ nonempty (((>) : ℕ → ℕ → Prop) ↪r r) :=
⟨λ ⟨h⟩ ⟨⟨f, o⟩⟩,
suffices ∀ a, acc r a → ∀ n, a ≠ f n, from this (f 0) (h _) 0 rfl,
λ a ac, begin
induction ac with a _ IH, intros n h, subst a,
exact IH (f (n+1)) (o.2 (nat.lt_succ_self _)) _ rfl
end,
λ N, ⟨λ a, classical.by_contradiction $ λ na,
let ⟨f, h⟩ := classical.axiom_of_choice $
show ∀ x : {a // ¬ acc r a}, ∃ y : {a // ¬ acc r a}, r y.1 x.1,
from λ ⟨x, h⟩, classical.by_contradiction $ λ hn, h $
⟨_, λ y h, classical.by_contradiction $ λ na, hn ⟨⟨y, na⟩, h⟩⟩ in
N ⟨nat_gt (λ n, (f^[n] ⟨a, na⟩).1) $ λ n,
by { rw [function.iterate_succ'], apply h }⟩⟩⟩
end rel_embedding
namespace nat
variables (s : set ℕ) [decidable_pred s] [infinite s]
/-- An order embedding from `ℕ` to itself with a specified range -/
def order_embedding_of_set : ℕ ↪o ℕ :=
(rel_embedding.order_embedding_of_lt_embedding
(rel_embedding.nat_lt (nat.subtype.of_nat s) (λ n, nat.subtype.lt_succ_self _))).trans
(order_embedding.subtype s)
/-- `nat.subtype.of_nat` as an order isomorphism between `ℕ` and an infinite decidable subset. -/
noncomputable def subtype.order_iso_of_nat :
ℕ ≃o s :=
rel_iso.of_surjective (rel_embedding.order_embedding_of_lt_embedding
(rel_embedding.nat_lt (nat.subtype.of_nat s) (λ n, nat.subtype.lt_succ_self _)))
nat.subtype.of_nat_surjective
variable {s}
@[simp]
lemma order_embedding_of_set_apply {n : ℕ} : order_embedding_of_set s n = subtype.of_nat s n :=
rfl
@[simp]
lemma subtype.order_iso_of_nat_apply {n : ℕ} :
subtype.order_iso_of_nat s n = subtype.of_nat s n :=
by { simp [subtype.order_iso_of_nat] }
variable (s)
@[simp]
lemma order_embedding_of_set_range : set.range (nat.order_embedding_of_set s) = s :=
begin
ext x,
rw [set.mem_range, nat.order_embedding_of_set],
split; intro h,
{ rcases h with ⟨y, rfl⟩,
simp },
{ refine ⟨(nat.subtype.order_iso_of_nat s).symm ⟨x, h⟩, _⟩,
simp only [rel_embedding.coe_trans, rel_embedding.order_embedding_of_lt_embedding_apply,
rel_embedding.nat_lt_apply, function.comp_app, order_embedding.coe_subtype],
rw [← subtype.order_iso_of_nat_apply, order_iso.apply_symm_apply, subtype.coe_mk] }
end
end nat
theorem exists_increasing_or_nonincreasing_subseq' {α : Type*} (r : α → α → Prop) (f : ℕ → α) :
∃ (g : ℕ ↪o ℕ), (∀ n : ℕ, r (f (g n)) (f (g (n + 1)))) ∨
(∀ m n : ℕ, m < n → ¬ r (f (g m)) (f (g n))) :=
begin
classical,
let bad : set ℕ := { m | ∀ n, m < n → ¬ r (f m) (f n) },
by_cases hbad : infinite bad,
{ haveI := hbad,
refine ⟨nat.order_embedding_of_set bad, or.intro_right _ (λ m n mn, _)⟩,
have h := set.mem_range_self m,
rw nat.order_embedding_of_set_range bad at h,
exact h _ ((order_embedding.lt_iff_lt _).2 mn) },
{ rw [set.infinite_coe_iff, set.infinite, not_not] at hbad,
obtain ⟨m, hm⟩ : ∃ m, ∀ n, m ≤ n → ¬ n ∈ bad,
{ by_cases he : hbad.to_finset.nonempty,
{ refine ⟨(hbad.to_finset.max' he).succ, λ n hn nbad, nat.not_succ_le_self _
(hn.trans (hbad.to_finset.le_max' n (hbad.mem_to_finset.2 nbad)))⟩ },
{ exact ⟨0, λ n hn nbad, he ⟨n, hbad.mem_to_finset.2 nbad⟩⟩ } },
have h : ∀ (n : ℕ), ∃ (n' : ℕ), n < n' ∧ r (f (n + m)) (f (n' + m)),
{ intro n,
have h := hm _ (le_add_of_nonneg_left n.zero_le),
simp only [exists_prop, not_not, set.mem_set_of_eq, not_forall] at h,
obtain ⟨n', hn1, hn2⟩ := h,
obtain ⟨x, hpos, rfl⟩ := exists_pos_add_of_lt hn1,
refine ⟨n + x, add_lt_add_left hpos n, _⟩,
rw [add_assoc, add_comm x m, ← add_assoc],
exact hn2 },
let g' : ℕ → ℕ := @nat.rec (λ _, ℕ) m (λ n gn, nat.find (h gn)),
exact ⟨(rel_embedding.nat_lt (λ n, g' n + m)
(λ n, nat.add_lt_add_right (nat.find_spec (h (g' n))).1 m)).order_embedding_of_lt_embedding,
or.intro_left _ (λ n, (nat.find_spec (h (g' n))).2)⟩ }
end
theorem exists_increasing_or_nonincreasing_subseq
{α : Type*} (r : α → α → Prop) [is_trans α r] (f : ℕ → α) :
∃ (g : ℕ ↪o ℕ), (∀ m n : ℕ, m < n → r (f (g m)) (f (g n))) ∨
(∀ m n : ℕ, m < n → ¬ r (f (g m)) (f (g n))) :=
begin
obtain ⟨g, hr | hnr⟩ := exists_increasing_or_nonincreasing_subseq' r f,
{ refine ⟨g, or.intro_left _ (λ m n mn, _)⟩,
obtain ⟨x, rfl⟩ := le_iff_exists_add.1 (nat.succ_le_iff.2 mn),
induction x with x ih,
{ apply hr },
{ apply is_trans.trans _ _ _ _ (hr _),
exact ih (lt_of_lt_of_le m.lt_succ_self (nat.le_add_right _ _)) } },
{ exact ⟨g, or.intro_right _ hnr⟩ }
end
|
7e0b64598bb8793865da8a7d3cb40db807e00eff | 130c49f47783503e462c16b2eff31933442be6ff | /stage0/src/Lean/Meta.lean | 6bd4425b84ada10d57d5d5d45520f286a7e65af5 | [
"Apache-2.0"
] | permissive | Hazel-Brown/lean4 | 8aa5860e282435ffc30dcdfccd34006c59d1d39c | 79e6732fc6bbf5af831b76f310f9c488d44e7a16 | refs/heads/master | 1,689,218,208,951 | 1,629,736,869,000 | 1,629,736,896,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 1,079 | 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.Meta.Basic
import Lean.Meta.LevelDefEq
import Lean.Meta.WHNF
import Lean.Meta.InferType
import Lean.Meta.FunInfo
import Lean.Meta.ExprDefEq
import Lean.Meta.DiscrTree
import Lean.Meta.Reduce
import Lean.Meta.Instances
import Lean.Meta.AbstractMVars
import Lean.Meta.SynthInstance
import Lean.Meta.AppBuilder
import Lean.Meta.Tactic
import Lean.Meta.KAbstract
import Lean.Meta.RecursorInfo
import Lean.Meta.GeneralizeTelescope
import Lean.Meta.Match
import Lean.Meta.ReduceEval
import Lean.Meta.Closure
import Lean.Meta.AbstractNestedProofs
import Lean.Meta.ForEachExpr
import Lean.Meta.Transform
import Lean.Meta.PPGoal
import Lean.Meta.UnificationHint
import Lean.Meta.Inductive
import Lean.Meta.SizeOf
import Lean.Meta.IndPredBelow
import Lean.Meta.Coe
import Lean.Meta.SortLocalDecls
import Lean.Meta.CollectFVars
import Lean.Meta.GeneralizeVars
import Lean.Meta.Injective
import Lean.Meta.Structure
|
570e56dbde799ef1a28439861956fb70abd6b746 | 8d65764a9e5f0923a67fc435eb1a5a1d02fd80e3 | /src/algebra/module/prod.lean | 644e88c8c7aab730c84f82bcced3cd3d7421f129 | [
"Apache-2.0"
] | permissive | troyjlee/mathlib | e18d4b8026e32062ab9e89bc3b003a5d1cfec3f5 | 45e7eb8447555247246e3fe91c87066506c14875 | refs/heads/master | 1,689,248,035,046 | 1,629,470,528,000 | 1,629,470,528,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 1,146 | lean | /-
Copyright (c) 2018 Simon Hudon. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Simon Hudon, Patrick Massot, Eric Wieser
-/
import algebra.module.basic
import group_theory.group_action.prod
/-!
# Prod instances for module and multiplicative actions
This file defines instances for binary product of modules
-/
variables {R : Type*} {S : Type*} {M : Type*} {N : Type*}
namespace prod
instance {r : semiring R} [add_comm_monoid M] [add_comm_monoid N]
[module R M] [module R N] : module R (M × N) :=
{ add_smul := λ a p₁ p₂, mk.inj_iff.mpr ⟨add_smul _ _ _, add_smul _ _ _⟩,
zero_smul := λ ⟨b, c⟩, mk.inj_iff.mpr ⟨zero_smul _ _, zero_smul _ _⟩,
.. prod.distrib_mul_action }
instance {r : semiring R} [add_comm_monoid M] [add_comm_monoid N]
[module R M] [module R N]
[no_zero_smul_divisors R M] [no_zero_smul_divisors R N] :
no_zero_smul_divisors R (M × N) :=
⟨λ c ⟨x, y⟩ h, or_iff_not_imp_left.mpr (λ hc, mk.inj_iff.mpr
⟨(smul_eq_zero.mp (congr_arg fst h)).resolve_left hc,
(smul_eq_zero.mp (congr_arg snd h)).resolve_left hc⟩)⟩
end prod
|
158e746ef368c7131894048773a1363a023b3cf0 | dd0f5513e11c52db157d2fcc8456d9401a6cd9da | /05_Interacting_with_Lean.org.9.lean | a690f68dab0c6d02bc3c9c095e808e41335d7db5 | [] | no_license | cjmazey/lean-tutorial | ba559a49f82aa6c5848b9bf17b7389bf7f4ba645 | 381f61c9fcac56d01d959ae0fa6e376f2c4e3b34 | refs/heads/master | 1,610,286,098,832 | 1,447,124,923,000 | 1,447,124,923,000 | 43,082,433 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 194 | lean | /- page 67 -/
import standard
import standard algebra.ordered_ring
open nat algebra
-- BEGIN
check lt_of_succ_le
check @lt_of_not_ge
check @lt_of_le_of_ne
check @add_lt_add_of_lt_of_le
-- END
|
2ee49a65de65512be6dcce39968f7ddd3313650c | 6432ea7a083ff6ba21ea17af9ee47b9c371760f7 | /tests/lean/macroscopes.lean | 1e0cb6a19e8f746e2c3bdeeba4e507dc155c70b5 | [
"Apache-2.0",
"LLVM-exception",
"NCSA",
"LGPL-3.0-only",
"LicenseRef-scancode-inner-net-2.0",
"BSD-3-Clause",
"LGPL-2.0-or-later",
"Spencer-94",
"LGPL-2.1-or-later",
"HPND",
"LicenseRef-scancode-pcre",
"ISC",
"LGPL-2.1-only",
"LicenseRef-scancode-other-permissive",
"SunPro",
"CMU-Mach"... | permissive | leanprover/lean4 | 4bdf9790294964627eb9be79f5e8f6157780b4cc | f1f9dc0f2f531af3312398999d8b8303fa5f096b | refs/heads/master | 1,693,360,665,786 | 1,693,350,868,000 | 1,693,350,868,000 | 129,571,436 | 2,827 | 311 | Apache-2.0 | 1,694,716,156,000 | 1,523,760,560,000 | Lean | UTF-8 | Lean | false | false | 1,123 | lean | --
open Lean
def check (b : Bool) : IO Unit :=
unless b do throw $ IO.userError "check failed"
def test1 : IO Unit := do
let x := `x;
let x := addMacroScope `main x 1;
IO.println $ x;
let v := extractMacroScopes x;
let x := { v with name := `y }.review;
IO.println $ x;
let v := extractMacroScopes x;
let x := { v with name := `x }.review;
IO.println $ x;
let x := addMacroScope `main x 2;
IO.println $ x;
let v := extractMacroScopes x;
let x := { v with name := `y }.review;
IO.println $ x;
let v := extractMacroScopes x;
let x := { v with name := `x }.review;
IO.println $ x;
let x := addMacroScope `main x 3;
IO.println $ x;
let x := addMacroScope `foo x 4;
IO.println $ x;
let x := addMacroScope `foo x 5;
let v := extractMacroScopes x;
check (v.mainModule == `foo);
IO.println $ x;
let x := addMacroScope `bla.bla x 6;
IO.println $ x;
let v := extractMacroScopes x;
check (v.mainModule == `bla.bla);
let x := addMacroScope `bla.bla x 7;
IO.println $ x;
let v := extractMacroScopes x;
let x := { v with name := `y }.review;
IO.println $ x;
let x := { v with name := `z.w }.review;
IO.println $ x;
pure ()
#eval test1
|
40d4e62ccf5aed4c784aa6808bdf0dd2f25d1dbb | abd85493667895c57a7507870867b28124b3998f | /src/data/polynomial.lean | 605cb1a2ddc0db41e30c5a3f38d0b67ec29b9f61 | [
"Apache-2.0"
] | permissive | pechersky/mathlib | d56eef16bddb0bfc8bc552b05b7270aff5944393 | f1df14c2214ee114c9738e733efd5de174deb95d | refs/heads/master | 1,666,714,392,571 | 1,591,747,567,000 | 1,591,747,567,000 | 270,557,274 | 0 | 0 | Apache-2.0 | 1,591,597,975,000 | 1,591,597,974,000 | null | UTF-8 | Lean | false | false | 108,349 | lean | /-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Johannes Hölzl, Scott Morrison, Jens Wagemaker
-/
import data.monoid_algebra
import algebra.gcd_domain
import ring_theory.euclidean_domain
import ring_theory.multiplicity
import tactic.ring_exp
import deprecated.field
/-!
# Theory of univariate polynomials
Polynomials are represented as `add_monoid_algebra R ℕ`, where `R` is a commutative semiring.
-/
noncomputable theory
local attribute [instance, priority 100] classical.prop_decidable
local attribute [instance, priority 10] is_semiring_hom.comp is_ring_hom.comp
/-- `polynomial R` is the type of univariate polynomials over `R`.
Polynomials should be seen as (semi-)rings with the additional constructor `X`.
The embedding from `R` is called `C`. -/
def polynomial (R : Type*) [comm_semiring R] := add_monoid_algebra R ℕ
open finsupp finset add_monoid_algebra
namespace polynomial
universes u v w x y z
variables {R : Type u} {S : Type v} {T : Type w} {ι : Type x} {k : Type y} {A : Type z}
{a b : R} {m n : ℕ}
section comm_semiring
variables [comm_semiring R] {p q r : polynomial R}
instance : inhabited (polynomial R) := finsupp.inhabited
instance : comm_semiring (polynomial R) := add_monoid_algebra.comm_semiring
instance : has_scalar R (polynomial R) := add_monoid_algebra.has_scalar
instance : semimodule R (polynomial R) := add_monoid_algebra.semimodule
instance : algebra R (polynomial R) := add_monoid_algebra.algebra
/-- The coercion turning a `polynomial` into the function which reports the coefficient of a given
monomial `X^n` -/
def coeff_coe_to_fun : has_coe_to_fun (polynomial R) :=
finsupp.has_coe_to_fun
local attribute [instance] coeff_coe_to_fun
@[simp] lemma support_zero : (0 : polynomial R).support = ∅ := rfl
/-- `monomial s a` is the monomial `a * X^s` -/
@[reducible]
def monomial (n : ℕ) (a : R) : polynomial R := finsupp.single n a
/-- `C a` is the constant polynomial `a`. -/
def C : R →ₐ[R] polynomial R := algebra.of_id R (polynomial R)
lemma C_def (a : R) : C a = single 0 a := rfl
/-- `X` is the polynomial variable (aka indeterminant). -/
def X : polynomial R := monomial 1 1
/-- coeff p n is the coefficient of X^n in p -/
def coeff (p : polynomial R) := p.to_fun
@[simp] lemma coeff_mk (s) (f) (h) : coeff (finsupp.mk s f h : polynomial R) = f := rfl
instance [has_repr R] : has_repr (polynomial R) :=
⟨λ p, if p = 0 then "0"
else (p.support.sort (≤)).foldr
(λ n a, a ++ (if a = "" then "" else " + ") ++
if n = 0
then "C (" ++ repr (coeff p n) ++ ")"
else if n = 1
then if (coeff p n) = 1 then "X" else "C (" ++ repr (coeff p n) ++ ") * X"
else if (coeff p n) = 1 then "X ^ " ++ repr n
else "C (" ++ repr (coeff p n) ++ ") * X ^ " ++ repr n) ""⟩
theorem ext_iff {p q : polynomial R} : p = q ↔ ∀ n, coeff p n = coeff q n :=
⟨λ h n, h ▸ rfl, finsupp.ext⟩
@[ext] lemma ext {p q : polynomial R} : (∀ n, coeff p n = coeff q n) → p = q :=
(@ext_iff _ _ p q).2
/-- `degree p` is the degree of the polynomial `p`, i.e. the largest `X`-exponent in `p`.
`degree p = some n` when `p ≠ 0` and `n` is the highest power of `X` that appears in `p`, otherwise
`degree 0 = ⊥`. -/
def degree (p : polynomial R) : with_bot ℕ := p.support.sup some
lemma degree_lt_wf : well_founded (λp q : polynomial R, degree p < degree q) :=
inv_image.wf degree (with_bot.well_founded_lt nat.lt_wf)
instance : has_well_founded (polynomial R) := ⟨_, degree_lt_wf⟩
/-- `nat_degree p` forces `degree p` to ℕ, by defining nat_degree 0 = 0. -/
def nat_degree (p : polynomial R) : ℕ := (degree p).get_or_else 0
lemma single_eq_C_mul_X : ∀{n}, monomial n a = C a * X^n
| 0 := (mul_one _).symm
| (n+1) :=
calc monomial (n + 1) a = monomial n a * X : by rw [X, single_mul_single, mul_one]
... = (C a * X^n) * X : by rw [single_eq_C_mul_X]
... = C a * X^(n+1) : by simp only [pow_add, mul_assoc, pow_one]
lemma sum_C_mul_X_eq (p : polynomial R) : p.sum (λn a, C a * X^n) = p :=
eq.trans (sum_congr rfl $ assume n hn, single_eq_C_mul_X.symm) (finsupp.sum_single _)
@[elab_as_eliminator] protected lemma induction_on {M : polynomial R → Prop} (p : polynomial R)
(h_C : ∀a, M (C a))
(h_add : ∀p q, M p → M q → M (p + q))
(h_monomial : ∀(n : ℕ) (a : R), M (C a * X^n) → M (C a * X^(n+1))) :
M p :=
have ∀{n:ℕ} {a}, M (C a * X^n),
begin
assume n a,
induction n with n ih,
{ simp only [pow_zero, mul_one, h_C] },
{ exact h_monomial _ _ ih }
end,
finsupp.induction p
(suffices M (C 0), by { convert this, exact single_zero.symm, },
h_C 0)
(assume n a p _ _ hp, suffices M (C a * X^n + p), by { convert this, exact single_eq_C_mul_X },
h_add _ _ this hp)
lemma C_0 : C (0 : R) = 0 := single_zero
lemma C_1 : C (1 : R) = 1 := rfl
lemma C_mul : C (a * b) = C a * C b := C.map_mul a b
lemma C_add : C (a + b) = C a + C b := C.map_add a b
instance C.is_semiring_hom : is_semiring_hom (C : R → polynomial R) :=
C.to_ring_hom.is_semiring_hom
lemma C_pow : C (a ^ n) = C a ^ n := C.map_pow a n
lemma nat_cast_eq_C (n : ℕ) : (n : polynomial R) = C (n : R) :=
(C.to_ring_hom.map_nat_cast n).symm
section coeff
lemma apply_eq_coeff : p n = coeff p n := rfl
@[simp] lemma coeff_zero (n : ℕ) : coeff (0 : polynomial R) n = 0 := rfl
lemma coeff_single : coeff (single n a) m = if n = m then a else 0 :=
by { dsimp [single, finsupp.single], congr }
@[simp] lemma coeff_one_zero : coeff (1 : polynomial R) 0 = 1 :=
coeff_single
@[simp]
lemma coeff_add (p q : polynomial R) (n : ℕ) : coeff (p + q) n = coeff p n + coeff q n := rfl
instance coeff.is_add_monoid_hom {n : ℕ} : is_add_monoid_hom (λ p : polynomial R, p.coeff n) :=
{ map_add := λ p q, coeff_add p q n,
map_zero := coeff_zero _ }
lemma coeff_C : coeff (C a) n = ite (n = 0) a 0 :=
by simp [coeff, eq_comm, C_def, monomial, single]; congr
@[simp] lemma coeff_C_zero : coeff (C a) 0 = a := coeff_single
@[simp] lemma coeff_X_one : coeff (X : polynomial R) 1 = 1 := coeff_single
@[simp] lemma coeff_X_zero : coeff (X : polynomial R) 0 = 0 := coeff_single
lemma coeff_X : coeff (X : polynomial R) n = if 1 = n then 1 else 0 := coeff_single
lemma coeff_C_mul_X (x : R) (k n : ℕ) :
coeff (C x * X^k : polynomial R) n = if n = k then x else 0 :=
by rw [← single_eq_C_mul_X]; simp [monomial, single, eq_comm, coeff]; congr
lemma coeff_sum [comm_semiring S] (n : ℕ) (f : ℕ → R → polynomial S) :
coeff (p.sum f) n = p.sum (λ a b, coeff (f a b) n) := finsupp.sum_apply
@[simp] lemma coeff_C_mul (p : polynomial R) : coeff (C a * p) n = a * coeff p n :=
begin
conv in (a * _) { rw [← @sum_single _ _ _ p, coeff_sum] },
rw [mul_def, C_def, sum_single_index],
{ simp [coeff_single, finsupp.mul_sum, coeff_sum],
apply sum_congr rfl,
assume i hi, by_cases i = n; simp [h] },
{ simp [finsupp.sum] }
end
@[simp] lemma coeff_smul (p : polynomial R) (r : R) (n : ℕ) :
coeff (r • p) n = r * coeff p n := finsupp.smul_apply
lemma C_mul' (a : R) (f : polynomial R) : C a * f = a • f :=
ext $ λ n, coeff_C_mul f
@[simp, priority 990]
lemma coeff_one (n : ℕ) : coeff (1 : polynomial R) n = if 0 = n then 1 else 0 :=
coeff_single
@[simp] lemma coeff_X_pow (k n : ℕ) :
coeff (X^k : polynomial R) n = if n = k then 1 else 0 :=
by simpa only [C_1, one_mul] using coeff_C_mul_X (1:R) k n
lemma coeff_mul (p q : polynomial R) (n : ℕ) :
coeff (p * q) n = (nat.antidiagonal n).sum (λ x, coeff p x.1 * coeff q x.2) :=
have hite : ∀ a : ℕ × ℕ, ite (a.1 + a.2 = n) (coeff p (a.fst) * coeff q (a.snd)) 0 ≠ 0
→ a.1 + a.2 = n, from λ a ha, by_contradiction
(λ h, absurd (eq.refl (0 : R)) (by rwa if_neg h at ha)),
calc coeff (p * q) n = p.support.sum (λ a, q.support.sum
(λ b, ite (a + b = n) (coeff p a * coeff q b) 0)) :
by simp only [mul_def, coeff_sum, coeff_single]; refl
... = (p.support.product q.support).sum
(λ v : ℕ × ℕ, ite (v.1 + v.2 = n) (coeff p v.1 * coeff q v.2) 0) :
by rw sum_product
... = (nat.antidiagonal n).sum (λ x, coeff p x.1 * coeff q x.2) :
begin
refine sum_bij_ne_zero (λ x _ _, x)
(λ x _ hx, nat.mem_antidiagonal.2 (hite x hx)) (λ _ _ _ _ _ _ h, h)
(λ x h₁ h₂, ⟨x, _, _, rfl⟩) _,
{ rw [mem_product, mem_support_iff, mem_support_iff],
exact ⟨ne_zero_of_mul_ne_zero_right h₂, ne_zero_of_mul_ne_zero_left h₂⟩ },
{ rw nat.mem_antidiagonal at h₁, rwa [if_pos h₁] },
{ intros x h hx, rw [if_pos (hite x hx)] }
end
theorem coeff_mul_X_pow (p : polynomial R) (n d : ℕ) :
coeff (p * polynomial.X ^ n) (d + n) = coeff p d :=
begin
rw [coeff_mul, sum_eq_single (d,n), coeff_X_pow, if_pos rfl, mul_one],
{ rintros ⟨i,j⟩ h1 h2, rw [coeff_X_pow, if_neg, mul_zero], rintro rfl, apply h2,
rw [nat.mem_antidiagonal, add_right_cancel_iff] at h1, subst h1 },
{ exact λ h1, (h1 (nat.mem_antidiagonal.2 rfl)).elim }
end
theorem coeff_mul_X (p : polynomial R) (n : ℕ) :
coeff (p * X) (n + 1) = coeff p n :=
by simpa only [pow_one] using coeff_mul_X_pow p 1 n
theorem mul_X_pow_eq_zero {p : polynomial R} {n : ℕ}
(H : p * X ^ n = 0) : p = 0 :=
ext $ λ k, (coeff_mul_X_pow p n k).symm.trans $ ext_iff.1 H (k+n)
end coeff
lemma C_inj : C a = C b ↔ a = b :=
⟨λ h, coeff_C_zero.symm.trans (h.symm ▸ coeff_C_zero), congr_arg C⟩
section eval₂
variables [semiring S]
variables (f : R → S) (x : S)
open is_semiring_hom
/-- Evaluate a polynomial `p` given a ring hom `f` from the scalar ring
to the target and a value `x` for the variable in the target -/
def eval₂ (p : polynomial R) : S :=
p.sum (λ e a, f a * x ^ e)
variables [is_semiring_hom f]
@[simp] lemma eval₂_C : (C a).eval₂ f x = f a :=
(sum_single_index $ by rw [map_zero f, zero_mul]).trans $ by rw [pow_zero, mul_one]
@[simp] lemma eval₂_X : X.eval₂ f x = x :=
(sum_single_index $ by rw [map_zero f, zero_mul]).trans $ by rw [map_one f, one_mul, pow_one]
@[simp] lemma eval₂_zero : (0 : polynomial R).eval₂ f x = 0 :=
finsupp.sum_zero_index
@[simp] lemma eval₂_add : (p + q).eval₂ f x = p.eval₂ f x + q.eval₂ f x :=
finsupp.sum_add_index
(λ _, by rw [map_zero f, zero_mul])
(λ _ _ _, by rw [map_add f, add_mul])
@[simp] lemma eval₂_one : (1 : polynomial R).eval₂ f x = 1 :=
by rw [← C_1, eval₂_C, map_one f]
instance eval₂.is_add_monoid_hom : is_add_monoid_hom (eval₂ f x) :=
{ map_zero := eval₂_zero _ _, map_add := λ _ _, eval₂_add _ _ }
end eval₂
section eval₂
variables [comm_semiring S]
variables (f : R → S) [is_semiring_hom f] (x : S)
open is_semiring_hom
@[simp] lemma eval₂_mul : (p * q).eval₂ f x = p.eval₂ f x * q.eval₂ f x :=
begin
dunfold eval₂,
rw [mul_def, finsupp.sum_mul _ p], simp only [finsupp.mul_sum _ q], rw [sum_sum_index],
{ apply sum_congr rfl, assume i hi, dsimp only, rw [sum_sum_index],
{ apply sum_congr rfl, assume j hj, dsimp only,
rw [sum_single_index, map_mul f, pow_add],
{ simp only [mul_assoc, mul_left_comm] },
{ rw [map_zero f, zero_mul] } },
{ intro, rw [map_zero f, zero_mul] },
{ intros, rw [map_add f, add_mul] } },
{ intro, rw [map_zero f, zero_mul] },
{ intros, rw [map_add f, add_mul] }
end
instance eval₂.is_semiring_hom : is_semiring_hom (eval₂ f x) :=
⟨eval₂_zero _ _, eval₂_one _ _, λ _ _, eval₂_add _ _, λ _ _, eval₂_mul _ _⟩
/-- `eval₂` as a `ring_hom` -/
def eval₂_ring_hom (f : R →+* S) (x) : polynomial R →+* S :=
ring_hom.of (eval₂ f x)
@[simp] lemma coe_eval₂_ring_hom (f : R →+* S) (x) : ⇑(eval₂_ring_hom f x) = eval₂ f x := rfl
lemma eval₂_pow (n : ℕ) : (p ^ n).eval₂ f x = p.eval₂ f x ^ n := map_pow _ _ _
lemma eval₂_sum (p : polynomial R) (g : ℕ → R → polynomial R) (x : S) :
(p.sum g).eval₂ f x = p.sum (λ n a, (g n a).eval₂ f x) :=
finsupp.sum_sum_index (by simp [is_add_monoid_hom.map_zero f])
(by intros; simp [right_distrib, is_add_monoid_hom.map_add f])
end eval₂
section eval
variable {x : R}
/-- `eval x p` is the evaluation of the polynomial `p` at `x` -/
def eval : R → polynomial R → R := eval₂ id
@[simp] lemma eval_C : (C a).eval x = a := eval₂_C _ _
@[simp] lemma eval_X : X.eval x = x := eval₂_X _ _
@[simp] lemma eval_zero : (0 : polynomial R).eval x = 0 := eval₂_zero _ _
@[simp] lemma eval_add : (p + q).eval x = p.eval x + q.eval x := eval₂_add _ _
@[simp] lemma eval_one : (1 : polynomial R).eval x = 1 := eval₂_one _ _
@[simp] lemma eval_mul : (p * q).eval x = p.eval x * q.eval x := eval₂_mul _ _
instance eval.is_semiring_hom : is_semiring_hom (eval x) := eval₂.is_semiring_hom _ _
@[simp] lemma eval_pow (n : ℕ) : (p ^ n).eval x = p.eval x ^ n := eval₂_pow _ _ _
lemma eval_sum (p : polynomial R) (f : ℕ → R → polynomial R) (x : R) :
(p.sum f).eval x = p.sum (λ n a, (f n a).eval x) :=
eval₂_sum _ _ _ _
lemma eval₂_hom [comm_semiring S] (f : R → S) [is_semiring_hom f] (x : R) :
p.eval₂ f (f x) = f (p.eval x) :=
polynomial.induction_on p
(by simp)
(by simp [is_semiring_hom.map_add f] {contextual := tt})
(by simp [is_semiring_hom.map_mul f, eval_pow,
is_semiring_hom.map_pow f, pow_succ', (mul_assoc _ _ _).symm] {contextual := tt})
/-- `is_root p x` implies `x` is a root of `p`. The evaluation of `p` at `x` is zero -/
def is_root (p : polynomial R) (a : R) : Prop := p.eval a = 0
instance [decidable_eq R] : decidable (is_root p a) := by unfold is_root; apply_instance
@[simp] lemma is_root.def : is_root p a ↔ p.eval a = 0 := iff.rfl
lemma root_mul_left_of_is_root (p : polynomial R) {q : polynomial R} :
is_root q a → is_root (p * q) a :=
λ H, by rw [is_root, eval_mul, is_root.def.1 H, mul_zero]
lemma root_mul_right_of_is_root {p : polynomial R} (q : polynomial R) :
is_root p a → is_root (p * q) a :=
λ H, by rw [is_root, eval_mul, is_root.def.1 H, zero_mul]
lemma coeff_zero_eq_eval_zero (p : polynomial R) :
coeff p 0 = p.eval 0 :=
calc coeff p 0 = coeff p 0 * 0 ^ 0 : by simp
... = p.eval 0 : eq.symm $
finset.sum_eq_single _ (λ b _ hb, by simp [zero_pow (nat.pos_of_ne_zero hb)]) (by simp)
lemma zero_is_root_of_coeff_zero_eq_zero {p : polynomial R} (hp : p.coeff 0 = 0) :
is_root p 0 :=
by rwa coeff_zero_eq_eval_zero at hp
end eval
section comp
def comp (p q : polynomial R) : polynomial R := p.eval₂ C q
lemma eval₂_comp [comm_semiring S] (f : R → S) [is_semiring_hom f] {x : S} :
(p.comp q).eval₂ f x = p.eval₂ f (q.eval₂ f x) :=
show (p.sum (λ e a, C a * q ^ e)).eval₂ f x = p.eval₂ f (eval₂ f x q),
by simp only [eval₂_mul, eval₂_C, eval₂_pow, eval₂_sum]; refl
lemma eval_comp : (p.comp q).eval a = p.eval (q.eval a) := eval₂_comp _
@[simp] lemma comp_X : p.comp X = p :=
begin
refine ext (λ n, _),
rw [comp, eval₂],
conv in (C _ * _) { rw ← single_eq_C_mul_X },
rw finsupp.sum_single
end
@[simp] lemma X_comp : X.comp p = p := eval₂_X _ _
@[simp] lemma comp_C : p.comp (C a) = C (p.eval a) :=
begin
dsimp [comp, eval₂, eval, finsupp.sum],
rw [← p.support.sum_hom (@C R _)],
apply finset.sum_congr rfl; simp
end
@[simp] lemma C_comp : (C a).comp p = C a := eval₂_C _ _
@[simp] lemma comp_zero : p.comp (0 : polynomial R) = C (p.eval 0) :=
by rw [← C_0, comp_C]
@[simp] lemma zero_comp : comp (0 : polynomial R) p = 0 :=
by rw [← C_0, C_comp]
@[simp] lemma comp_one : p.comp 1 = C (p.eval 1) :=
by rw [← C_1, comp_C]
@[simp] lemma one_comp : comp (1 : polynomial R) p = 1 :=
by rw [← C_1, C_comp]
instance : is_semiring_hom (λ q : polynomial R, q.comp p) :=
by unfold comp; apply_instance
@[simp] lemma add_comp : (p + q).comp r = p.comp r + q.comp r := eval₂_add _ _
@[simp] lemma mul_comp : (p * q).comp r = p.comp r * q.comp r := eval₂_mul _ _
end comp
/-- `leading_coeff p` gives the coefficient of the highest power of `X` in `p`-/
def leading_coeff (p : polynomial R) : R := coeff p (nat_degree p)
/-- a polynomial is `monic` if its leading coefficient is 1 -/
def monic (p : polynomial R) := leading_coeff p = (1 : R)
lemma monic.def : monic p ↔ leading_coeff p = 1 := iff.rfl
instance monic.decidable [decidable_eq R] : decidable (monic p) :=
by unfold monic; apply_instance
@[simp] lemma monic.leading_coeff {p : polynomial R} (hp : p.monic) :
leading_coeff p = 1 := hp
@[simp] lemma degree_zero : degree (0 : polynomial R) = ⊥ := rfl
@[simp] lemma nat_degree_zero : nat_degree (0 : polynomial R) = 0 := rfl
@[simp] lemma degree_C (ha : a ≠ 0) : degree (C a) = (0 : with_bot ℕ) :=
show sup (ite (a = 0) ∅ {0}) some = 0, by rw if_neg ha; refl
lemma degree_C_le : degree (C a) ≤ (0 : with_bot ℕ) :=
by by_cases h : a = 0; [rw [h, C_0], rw [degree_C h]]; [exact bot_le, exact le_refl _]
lemma degree_one_le : degree (1 : polynomial R) ≤ (0 : with_bot ℕ) :=
by rw [← C_1]; exact degree_C_le
lemma degree_eq_bot : degree p = ⊥ ↔ p = 0 :=
⟨λ h, by rw [degree, ← max_eq_sup_with_bot] at h;
exact support_eq_empty.1 (max_eq_none.1 h),
λ h, h.symm ▸ rfl⟩
lemma degree_eq_nat_degree (hp : p ≠ 0) : degree p = (nat_degree p : with_bot ℕ) :=
let ⟨n, hn⟩ :=
classical.not_forall.1 (mt option.eq_none_iff_forall_not_mem.2 (mt degree_eq_bot.1 hp)) in
have hn : degree p = some n := not_not.1 hn,
by rw [nat_degree, hn]; refl
lemma degree_eq_iff_nat_degree_eq {p : polynomial R} {n : ℕ} (hp : p ≠ 0) :
p.degree = n ↔ p.nat_degree = n :=
by rw [degree_eq_nat_degree hp, with_bot.coe_eq_coe]
lemma degree_eq_iff_nat_degree_eq_of_pos {p : polynomial R} {n : ℕ} (hn : n > 0) :
p.degree = n ↔ p.nat_degree = n :=
begin
split,
{ intro H, rwa ← degree_eq_iff_nat_degree_eq, rintro rfl,
rw degree_zero at H, exact option.no_confusion H },
{ intro H, rwa degree_eq_iff_nat_degree_eq, rintro rfl,
rw nat_degree_zero at H, rw H at hn, exact lt_irrefl _ hn }
end
lemma nat_degree_eq_of_degree_eq_some {p : polynomial R} {n : ℕ}
(h : degree p = n) : nat_degree p = n :=
have hp0 : p ≠ 0, from λ hp0, by rw hp0 at h; exact option.no_confusion h,
option.some_inj.1 $ show (nat_degree p : with_bot ℕ) = n,
by rwa [← degree_eq_nat_degree hp0]
@[simp] lemma degree_le_nat_degree : degree p ≤ nat_degree p :=
begin
by_cases hp : p = 0, { rw hp, exact bot_le },
rw [degree_eq_nat_degree hp],
exact le_refl _
end
lemma nat_degree_eq_of_degree_eq [comm_semiring S] {q : polynomial S}
(h : degree p = degree q) : nat_degree p = nat_degree q :=
by unfold nat_degree; rw h
lemma le_degree_of_ne_zero (h : coeff p n ≠ 0) : (n : with_bot ℕ) ≤ degree p :=
show @has_le.le (with_bot ℕ) _ (some n : with_bot ℕ) (p.support.sup some : with_bot ℕ),
from finset.le_sup (finsupp.mem_support_iff.2 h)
lemma le_nat_degree_of_ne_zero (h : coeff p n ≠ 0) : n ≤ nat_degree p :=
begin
rw [← with_bot.coe_le_coe, ← degree_eq_nat_degree],
exact le_degree_of_ne_zero h,
{ assume h, subst h, exact h rfl }
end
lemma degree_le_degree (h : coeff q (nat_degree p) ≠ 0) : degree p ≤ degree q :=
begin
by_cases hp : p = 0,
{ rw hp, exact bot_le },
{ rw degree_eq_nat_degree hp, exact le_degree_of_ne_zero h }
end
@[simp] lemma nat_degree_C (a : R) : nat_degree (C a) = 0 :=
begin
by_cases ha : a = 0,
{ have : C a = 0, { rw [ha, C_0] },
rw [nat_degree, degree_eq_bot.2 this],
refl },
{ rw [nat_degree, degree_C ha], refl }
end
@[simp] lemma nat_degree_one : nat_degree (1 : polynomial R) = 0 := nat_degree_C 1
@[simp] lemma nat_degree_nat_cast (n : ℕ) : nat_degree (n : polynomial R) = 0 :=
by simp [nat_cast_eq_C]
@[simp] lemma degree_monomial (n : ℕ) (ha : a ≠ 0) : degree (C a * X ^ n) = n :=
by rw [← single_eq_C_mul_X, degree, support_single_ne_zero ha]; refl
lemma degree_monomial_le (n : ℕ) (a : R) : degree (C a * X ^ n) ≤ n :=
if h : a = 0 then by rw [h, C_0, zero_mul]; exact bot_le else le_of_eq (degree_monomial n h)
lemma coeff_eq_zero_of_degree_lt (h : degree p < n) : coeff p n = 0 :=
not_not.1 (mt le_degree_of_ne_zero (not_le_of_gt h))
lemma coeff_eq_zero_of_nat_degree_lt {p : polynomial R} {n : ℕ} (h : p.nat_degree < n) :
p.coeff n = 0 :=
begin
apply coeff_eq_zero_of_degree_lt,
by_cases hp : p = 0,
{ subst hp, exact with_bot.bot_lt_coe n },
{ rwa [degree_eq_nat_degree hp, with_bot.coe_lt_coe] }
end
-- TODO find a home (this file)
@[simp] lemma finset_sum_coeff (s : finset ι) (f : ι → polynomial R) (n : ℕ) :
coeff (s.sum f) n = s.sum (λ b, coeff (f b) n) :=
(s.sum_hom (λ q : polynomial R, q.coeff n)).symm
-- We need the explicit `decidable` argument here because an exotic one shows up in a moment!
lemma ite_le_nat_degree_coeff (p : polynomial R) (n : ℕ) (I : decidable (n < 1 + nat_degree p)) :
@ite (n < 1 + nat_degree p) I _ (coeff p n) 0 = coeff p n :=
begin
split_ifs,
{ refl },
{ exact (coeff_eq_zero_of_nat_degree_lt (not_le.1 (λ w, h (nat.lt_one_add_iff.2 w)))).symm, }
end
lemma as_sum (p : polynomial R) :
p = (range (p.nat_degree + 1)).sum (λ i, C (p.coeff i) * X^i) :=
begin
ext n,
simp only [add_comm, coeff_X_pow, coeff_C_mul, finset.mem_range,
finset.sum_mul_boole, finset_sum_coeff, ite_le_nat_degree_coeff],
end
lemma monic.as_sum {p : polynomial R} (hp : p.monic) :
p = X^(p.nat_degree) + ((finset.range p.nat_degree).sum $ λ i, C (p.coeff i) * X^i) :=
begin
conv_lhs { rw [p.as_sum, finset.sum_range_succ] },
suffices : C (p.coeff p.nat_degree) = 1,
{ rw [this, one_mul] },
exact congr_arg C hp
end
section map
variables [comm_semiring S]
variables (f : R →+* S)
/-- `map f p` maps a polynomial `p` across a ring hom `f` -/
def map : polynomial R → polynomial S := eval₂ (C ∘ f) X
instance is_semiring_hom_C_f : is_semiring_hom (C ∘ f) :=
is_semiring_hom.comp _ _
@[simp] lemma map_C : (C a).map f = C (f a) := eval₂_C _ _
@[simp] lemma map_X : X.map f = X := eval₂_X _ _
@[simp] lemma map_zero : (0 : polynomial R).map f = 0 := eval₂_zero _ _
@[simp] lemma map_add : (p + q).map f = p.map f + q.map f := eval₂_add _ _
@[simp] lemma map_one : (1 : polynomial R).map f = 1 := eval₂_one _ _
@[simp] lemma map_mul : (p * q).map f = p.map f * q.map f := eval₂_mul _ _
instance map.is_semiring_hom : is_semiring_hom (map f) := eval₂.is_semiring_hom _ _
@[simp] lemma map_pow (n : ℕ) : (p ^ n).map f = p.map f ^ n := eval₂_pow _ _ _
lemma coeff_map (n : ℕ) : coeff (p.map f) n = f (coeff p n) :=
begin
rw [map, eval₂, coeff_sum],
conv_rhs { rw [← sum_C_mul_X_eq p, coeff_sum, finsupp.sum,
← p.support.sum_hom f], },
refine finset.sum_congr rfl (λ x hx, _),
simp [function.comp, coeff_C_mul_X, is_semiring_hom.map_mul f],
split_ifs; simp [is_semiring_hom.map_zero f],
end
lemma map_map [comm_semiring T] (g : S →+* T)
(p : polynomial R) : (p.map f).map g = p.map (g.comp f) :=
ext (by simp [coeff_map])
lemma eval₂_map [comm_semiring T] (g : S → T) [is_semiring_hom g] (x : T) :
(p.map f).eval₂ g x = p.eval₂ (λ y, g (f y)) x :=
polynomial.induction_on p
(by simp)
(by simp [is_semiring_hom.map_add f] {contextual := tt})
(by simp [is_semiring_hom.map_mul f,
is_semiring_hom.map_pow f, pow_succ', (mul_assoc _ _ _).symm] {contextual := tt})
lemma eval_map (x : S) : (p.map f).eval x = p.eval₂ f x := eval₂_map _ _ _
@[simp] lemma map_id : p.map (ring_hom.id _) = p := by simp [polynomial.ext_iff, coeff_map]
lemma mem_map_range {p : polynomial S} :
p ∈ set.range (map f) ↔ ∀ n, p.coeff n ∈ (set.range f) :=
begin
split,
{ rintro ⟨p, rfl⟩ n, rw coeff_map, exact set.mem_range_self _ },
{ intro h, rw p.as_sum,
apply is_add_submonoid.finset_sum_mem,
intros i hi,
rcases h i with ⟨c, hc⟩,
use [C c * X^i],
rw [map_mul, map_C, hc, map_pow, map_X] }
end
end map
section
variables [comm_semiring S] [comm_semiring T]
variables (f : R →+* S) (g : S →+* T) (p)
lemma hom_eval₂ (x : S) : g (p.eval₂ f x) = p.eval₂ (g ∘ f) (g x) :=
begin
apply polynomial.induction_on p; clear p,
{ intros a, rw [eval₂_C, eval₂_C] },
{ intros p q hp hq, simp only [hp, hq, eval₂_add, is_semiring_hom.map_add g] },
{ intros n a ih,
replace ih := congr_arg (λ y, y * g x) ih,
simpa [pow_succ', is_semiring_hom.map_mul g, (mul_assoc _ _ _).symm,
eval₂_C, eval₂_mul, eval₂_X] using ih }
end
end
lemma coeff_nat_degree_eq_zero_of_degree_lt (h : degree p < degree q) :
coeff p (nat_degree q) = 0 :=
coeff_eq_zero_of_degree_lt (lt_of_lt_of_le h degree_le_nat_degree)
lemma ne_zero_of_degree_gt {n : with_bot ℕ} (h : n < degree p) : p ≠ 0 :=
mt degree_eq_bot.2 (ne.symm (ne_of_lt (lt_of_le_of_lt bot_le h)))
lemma eq_C_of_degree_le_zero (h : degree p ≤ 0) : p = C (coeff p 0) :=
begin
refine ext (λ n, _),
cases n,
{ simp },
{ have : degree p < ↑(nat.succ n) := lt_of_le_of_lt h (with_bot.some_lt_some.2 (nat.succ_pos _)),
rw [coeff_C, if_neg (nat.succ_ne_zero _), coeff_eq_zero_of_degree_lt this] }
end
lemma eq_C_of_degree_eq_zero (h : degree p = 0) : p = C (coeff p 0) :=
eq_C_of_degree_le_zero (h ▸ le_refl _)
lemma degree_le_zero_iff : degree p ≤ 0 ↔ p = C (coeff p 0) :=
⟨eq_C_of_degree_le_zero, λ h, h.symm ▸ degree_C_le⟩
lemma degree_add_le (p q : polynomial R) : degree (p + q) ≤ max (degree p) (degree q) :=
calc degree (p + q) = ((p + q).support).sup some : rfl
... ≤ (p.support ∪ q.support).sup some : by convert sup_mono support_add
... = p.support.sup some ⊔ q.support.sup some : by convert sup_union
... = _ : with_bot.sup_eq_max _ _
@[simp] lemma leading_coeff_zero : leading_coeff (0 : polynomial R) = 0 := rfl
@[simp] lemma leading_coeff_eq_zero : leading_coeff p = 0 ↔ p = 0 :=
⟨λ h, by_contradiction $ λ hp, mt mem_support_iff.1
(not_not.2 h) (mem_of_max (degree_eq_nat_degree hp)),
λ h, h.symm ▸ leading_coeff_zero⟩
lemma leading_coeff_eq_zero_iff_deg_eq_bot : leading_coeff p = 0 ↔ degree p = ⊥ :=
by rw [leading_coeff_eq_zero, degree_eq_bot]
lemma degree_add_eq_of_degree_lt (h : degree p < degree q) : degree (p + q) = degree q :=
le_antisymm (max_eq_right_of_lt h ▸ degree_add_le _ _) $ degree_le_degree $
begin
rw [coeff_add, coeff_nat_degree_eq_zero_of_degree_lt h, zero_add],
exact mt leading_coeff_eq_zero.1 (ne_zero_of_degree_gt h)
end
lemma degree_add_C (hp : 0 < degree p) : degree (p + C a) = degree p :=
add_comm (C a) p ▸ degree_add_eq_of_degree_lt $ lt_of_le_of_lt degree_C_le hp
lemma degree_add_eq_of_leading_coeff_add_ne_zero (h : leading_coeff p + leading_coeff q ≠ 0) :
degree (p + q) = max p.degree q.degree :=
le_antisymm (degree_add_le _ _) $
match lt_trichotomy (degree p) (degree q) with
| or.inl hlt :=
by rw [degree_add_eq_of_degree_lt hlt, max_eq_right_of_lt hlt]; exact le_refl _
| or.inr (or.inl heq) :=
le_of_not_gt $
assume hlt : max (degree p) (degree q) > degree (p + q),
h $ show leading_coeff p + leading_coeff q = 0,
begin
rw [heq, max_self] at hlt,
rw [leading_coeff, leading_coeff, nat_degree_eq_of_degree_eq heq, ← coeff_add],
exact coeff_nat_degree_eq_zero_of_degree_lt hlt
end
| or.inr (or.inr hlt) :=
by rw [add_comm, degree_add_eq_of_degree_lt hlt, max_eq_left_of_lt hlt]; exact le_refl _
end
lemma degree_erase_le (p : polynomial R) (n : ℕ) : degree (p.erase n) ≤ degree p :=
by convert sup_mono (erase_subset _ _)
lemma degree_erase_lt (hp : p ≠ 0) : degree (p.erase (nat_degree p)) < degree p :=
lt_of_le_of_ne (degree_erase_le _ _) $
(degree_eq_nat_degree hp).symm ▸ (by convert λ h, not_mem_erase _ _ (mem_of_max h))
lemma degree_sum_le (s : finset ι) (f : ι → polynomial R) :
degree (s.sum f) ≤ s.sup (λ b, degree (f b)) :=
finset.induction_on s (by simp only [sum_empty, sup_empty, degree_zero, le_refl]) $
assume a s has ih,
calc degree ((insert a s).sum f) ≤ max (degree (f a)) (degree (s.sum f)) :
by rw sum_insert has; exact degree_add_le _ _
... ≤ _ : by rw [sup_insert, with_bot.sup_eq_max]; exact max_le_max (le_refl _) ih
lemma degree_mul_le (p q : polynomial R) : degree (p * q) ≤ degree p + degree q :=
calc degree (p * q) ≤ (p.support).sup (λi, degree (sum q (λj a, C (coeff p i * a) * X ^ (i + j)))) :
by simp only [single_eq_C_mul_X.symm]; exact degree_sum_le _ _
... ≤ p.support.sup (λi, q.support.sup (λj, degree (C (coeff p i * coeff q j) * X ^ (i + j)))) :
finset.sup_mono_fun (assume i hi, degree_sum_le _ _)
... ≤ degree p + degree q :
begin
refine finset.sup_le (λ a ha, finset.sup_le (λ b hb, le_trans (degree_monomial_le _ _) _)),
rw [with_bot.coe_add],
rw mem_support_iff at ha hb,
exact add_le_add' (le_degree_of_ne_zero ha) (le_degree_of_ne_zero hb)
end
lemma degree_pow_le (p : polynomial R) : ∀ n, degree (p ^ n) ≤ n •ℕ (degree p)
| 0 := by rw [pow_zero, zero_nsmul]; exact degree_one_le
| (n+1) := calc degree (p ^ (n + 1)) ≤ degree p + degree (p ^ n) :
by rw pow_succ; exact degree_mul_le _ _
... ≤ _ : by rw succ_nsmul; exact add_le_add' (le_refl _) (degree_pow_le _)
@[simp] lemma leading_coeff_monomial (a : R) (n : ℕ) : leading_coeff (C a * X ^ n) = a :=
begin
by_cases ha : a = 0,
{ simp only [ha, C_0, zero_mul, leading_coeff_zero] },
{ rw [leading_coeff, nat_degree, degree_monomial _ ha, ← single_eq_C_mul_X],
exact @finsupp.single_eq_same _ _ _ n a }
end
@[simp] lemma leading_coeff_C (a : R) : leading_coeff (C a) = a :=
suffices leading_coeff (C a * X^0) = a, by rwa [pow_zero, mul_one] at this,
leading_coeff_monomial a 0
@[simp] lemma leading_coeff_X : leading_coeff (X : polynomial R) = 1 :=
suffices leading_coeff (C (1:R) * X^1) = 1, by rwa [C_1, pow_one, one_mul] at this,
leading_coeff_monomial 1 1
@[simp] lemma monic_X : monic (X : polynomial R) := leading_coeff_X
@[simp] lemma leading_coeff_one : leading_coeff (1 : polynomial R) = 1 :=
suffices leading_coeff (C (1:R) * X^0) = 1, by rwa [C_1, pow_zero, mul_one] at this,
leading_coeff_monomial 1 0
@[simp] lemma monic_one : monic (1 : polynomial R) := leading_coeff_C _
lemma monic.ne_zero_of_zero_ne_one (h : (0:R) ≠ 1) {p : polynomial R} (hp : p.monic) :
p ≠ 0 :=
by { contrapose! h, rwa [h] at hp }
lemma monic.ne_zero {R : Type*} [comm_semiring R] [nonzero R] {p : polynomial R} (hp : p.monic) :
p ≠ 0 :=
hp.ne_zero_of_zero_ne_one zero_ne_one
lemma leading_coeff_add_of_degree_lt (h : degree p < degree q) :
leading_coeff (p + q) = leading_coeff q :=
have coeff p (nat_degree q) = 0, from coeff_nat_degree_eq_zero_of_degree_lt h,
by simp only [leading_coeff, nat_degree_eq_of_degree_eq (degree_add_eq_of_degree_lt h),
this, coeff_add, zero_add]
lemma leading_coeff_add_of_degree_eq (h : degree p = degree q)
(hlc : leading_coeff p + leading_coeff q ≠ 0) :
leading_coeff (p + q) = leading_coeff p + leading_coeff q :=
have nat_degree (p + q) = nat_degree p,
by apply nat_degree_eq_of_degree_eq;
rw [degree_add_eq_of_leading_coeff_add_ne_zero hlc, h, max_self],
by simp only [leading_coeff, this, nat_degree_eq_of_degree_eq h, coeff_add]
@[simp] lemma coeff_mul_degree_add_degree (p q : polynomial R) :
coeff (p * q) (nat_degree p + nat_degree q) = leading_coeff p * leading_coeff q :=
calc coeff (p * q) (nat_degree p + nat_degree q) =
(nat.antidiagonal (nat_degree p + nat_degree q)).sum
(λ x, coeff p x.1 * coeff q x.2) : coeff_mul _ _ _
... = coeff p (nat_degree p) * coeff q (nat_degree q) :
begin
refine finset.sum_eq_single (nat_degree p, nat_degree q) _ _,
{ rintro ⟨i,j⟩ h₁ h₂, rw nat.mem_antidiagonal at h₁,
by_cases H : nat_degree p < i,
{ rw [coeff_eq_zero_of_degree_lt
(lt_of_le_of_lt degree_le_nat_degree (with_bot.coe_lt_coe.2 H)), zero_mul] },
{ rw not_lt_iff_eq_or_lt at H, cases H,
{ subst H, rw add_left_cancel_iff at h₁, dsimp at h₁, subst h₁, exfalso, exact h₂ rfl },
{ suffices : nat_degree q < j,
{ rw [coeff_eq_zero_of_degree_lt
(lt_of_le_of_lt degree_le_nat_degree (with_bot.coe_lt_coe.2 this)), mul_zero] },
{ by_contra H', rw not_lt at H',
exact ne_of_lt (nat.lt_of_lt_of_le
(nat.add_lt_add_right H j) (nat.add_le_add_left H' _)) h₁ } } } },
{ intro H, exfalso, apply H, rw nat.mem_antidiagonal }
end
lemma degree_mul_eq' (h : leading_coeff p * leading_coeff q ≠ 0) :
degree (p * q) = degree p + degree q :=
have hp : p ≠ 0 := by refine mt _ h; exact λ hp, by rw [hp, leading_coeff_zero, zero_mul],
have hq : q ≠ 0 := by refine mt _ h; exact λ hq, by rw [hq, leading_coeff_zero, mul_zero],
le_antisymm (degree_mul_le _ _)
begin
rw [degree_eq_nat_degree hp, degree_eq_nat_degree hq],
refine le_degree_of_ne_zero _,
rwa coeff_mul_degree_add_degree
end
lemma nat_degree_mul_eq' (h : leading_coeff p * leading_coeff q ≠ 0) :
nat_degree (p * q) = nat_degree p + nat_degree q :=
have hp : p ≠ 0 := mt leading_coeff_eq_zero.2 (λ h₁, h $ by rw [h₁, zero_mul]),
have hq : q ≠ 0 := mt leading_coeff_eq_zero.2 (λ h₁, h $ by rw [h₁, mul_zero]),
have hpq : p * q ≠ 0 := λ hpq, by rw [← coeff_mul_degree_add_degree, hpq, coeff_zero] at h;
exact h rfl,
option.some_inj.1 (show (nat_degree (p * q) : with_bot ℕ) = nat_degree p + nat_degree q,
by rw [← degree_eq_nat_degree hpq, degree_mul_eq' h, degree_eq_nat_degree hp,
degree_eq_nat_degree hq])
lemma leading_coeff_mul' (h : leading_coeff p * leading_coeff q ≠ 0) :
leading_coeff (p * q) = leading_coeff p * leading_coeff q :=
begin
unfold leading_coeff,
rw [nat_degree_mul_eq' h, coeff_mul_degree_add_degree],
refl
end
lemma leading_coeff_pow' : leading_coeff p ^ n ≠ 0 →
leading_coeff (p ^ n) = leading_coeff p ^ n :=
nat.rec_on n (by simp) $
λ n ih h,
have h₁ : leading_coeff p ^ n ≠ 0 :=
λ h₁, h $ by rw [pow_succ, h₁, mul_zero],
have h₂ : leading_coeff p * leading_coeff (p ^ n) ≠ 0 :=
by rwa [pow_succ, ← ih h₁] at h,
by rw [pow_succ, pow_succ, leading_coeff_mul' h₂, ih h₁]
lemma degree_pow_eq' : ∀ {n}, leading_coeff p ^ n ≠ 0 →
degree (p ^ n) = n •ℕ (degree p)
| 0 := λ h, by rw [pow_zero, ← C_1] at *;
rw [degree_C h, zero_nsmul]
| (n+1) := λ h,
have h₁ : leading_coeff p ^ n ≠ 0 := λ h₁, h $
by rw [pow_succ, h₁, mul_zero],
have h₂ : leading_coeff p * leading_coeff (p ^ n) ≠ 0 :=
by rwa [pow_succ, ← leading_coeff_pow' h₁] at h,
by rw [pow_succ, degree_mul_eq' h₂, succ_nsmul, degree_pow_eq' h₁]
lemma nat_degree_pow_eq' {n : ℕ} (h : leading_coeff p ^ n ≠ 0) :
nat_degree (p ^ n) = n * nat_degree p :=
if hp0 : p = 0 then
if hn0 : n = 0 then by simp *
else by rw [hp0, zero_pow (nat.pos_of_ne_zero hn0)]; simp
else
have hpn : p ^ n ≠ 0, from λ hpn0, have h1 : _ := h,
by rw [← leading_coeff_pow' h1, hpn0, leading_coeff_zero] at h;
exact h rfl,
option.some_inj.1 $ show (nat_degree (p ^ n) : with_bot ℕ) = (n * nat_degree p : ℕ),
by rw [← degree_eq_nat_degree hpn, degree_pow_eq' h, degree_eq_nat_degree hp0,
← with_bot.coe_nsmul]; simp
@[simp] lemma leading_coeff_X_pow : ∀ n : ℕ, leading_coeff ((X : polynomial R) ^ n) = 1
| 0 := by simp
| (n+1) :=
if h10 : (1 : R) = 0
then by rw [pow_succ, ← one_mul X, ← C_1, h10]; simp
else
have h : leading_coeff (X : polynomial R) * leading_coeff (X ^ n) ≠ 0,
by rw [leading_coeff_X, leading_coeff_X_pow n, one_mul];
exact h10,
by rw [pow_succ, leading_coeff_mul' h, leading_coeff_X, leading_coeff_X_pow, one_mul]
lemma nat_degree_comp_le : nat_degree (p.comp q) ≤ nat_degree p * nat_degree q :=
if h0 : p.comp q = 0 then by rw [h0, nat_degree_zero]; exact nat.zero_le _
else with_bot.coe_le_coe.1 $
calc ↑(nat_degree (p.comp q)) = degree (p.comp q) : (degree_eq_nat_degree h0).symm
... ≤ _ : degree_sum_le _ _
... ≤ _ : sup_le (λ n hn,
calc degree (C (coeff p n) * q ^ n)
≤ degree (C (coeff p n)) + degree (q ^ n) : degree_mul_le _ _
... ≤ nat_degree (C (coeff p n)) + n •ℕ (degree q) :
add_le_add' degree_le_nat_degree (degree_pow_le _ _)
... ≤ nat_degree (C (coeff p n)) + n •ℕ (nat_degree q) :
add_le_add_left' (nsmul_le_nsmul_of_le_right (@degree_le_nat_degree _ _ q) n)
... = (n * nat_degree q : ℕ) :
by rw [nat_degree_C, with_bot.coe_zero, zero_add, ← with_bot.coe_nsmul,
nsmul_eq_mul]; simp
... ≤ (nat_degree p * nat_degree q : ℕ) : with_bot.coe_le_coe.2 $
mul_le_mul_of_nonneg_right
(le_nat_degree_of_ne_zero (finsupp.mem_support_iff.1 hn))
(nat.zero_le _))
lemma degree_map_le [comm_semiring S] (f : R →+* S) :
degree (p.map f) ≤ degree p :=
if h : p.map f = 0 then by simp [h]
else begin
rw [degree_eq_nat_degree h],
refine le_degree_of_ne_zero (mt (congr_arg f) _),
rw [← coeff_map f, is_semiring_hom.map_zero f],
exact mt leading_coeff_eq_zero.1 h
end
lemma subsingleton_of_monic_zero (h : monic (0 : polynomial R)) :
(∀ p q : polynomial R, p = q) ∧ (∀ a b : R, a = b) :=
by rw [monic.def, leading_coeff_zero] at h;
exact ⟨λ p q, by rw [← mul_one p, ← mul_one q, ← C_1, ← h, C_0, mul_zero, mul_zero],
λ a b, by rw [← mul_one a, ← mul_one b, ← h, mul_zero, mul_zero]⟩
lemma degree_map_eq_of_leading_coeff_ne_zero [comm_semiring S] (f : R →+* S)
(hf : f (leading_coeff p) ≠ 0) : degree (p.map f) = degree p :=
le_antisymm (degree_map_le f) $
have hp0 : p ≠ 0, from λ hp0, by simpa [hp0, is_semiring_hom.map_zero f] using hf,
begin
rw [degree_eq_nat_degree hp0],
refine le_degree_of_ne_zero _,
rw [coeff_map], exact hf
end
lemma monic_map [comm_semiring S] (f : R →+* S) (hp : monic p) : monic (p.map f) :=
if h : (0 : S) = 1 then
by haveI := subsingleton_of_zero_eq_one S h;
exact subsingleton.elim _ _
else
have f (leading_coeff p) ≠ 0,
by rwa [show _ = _, from hp, is_semiring_hom.map_one f, ne.def, eq_comm],
by erw [monic, leading_coeff, nat_degree_eq_of_degree_eq
(degree_map_eq_of_leading_coeff_ne_zero f this), coeff_map,
← leading_coeff, show _ = _, from hp, is_semiring_hom.map_one f]
lemma zero_le_degree_iff {p : polynomial R} : 0 ≤ degree p ↔ p ≠ 0 :=
by rw [ne.def, ← degree_eq_bot];
cases degree p; exact dec_trivial
@[simp] lemma coeff_mul_X_zero (p : polynomial R) : coeff (p * X) 0 = 0 :=
by rw [coeff_mul, nat.antidiagonal_zero];
simp only [polynomial.coeff_X_zero, finset.sum_singleton, mul_zero]
lemma is_unit_C {x : R} : is_unit (C x) ↔ is_unit x :=
begin
rw [is_unit_iff_dvd_one, is_unit_iff_dvd_one],
split,
{ rintros ⟨g, hg⟩,
replace hg := congr_arg (eval 0) hg,
rw [eval_one, eval_mul, eval_C] at hg,
exact ⟨g.eval 0, hg⟩ },
{ rintros ⟨y, hy⟩,
exact ⟨C y, by rw [← C_mul, ← hy, C_1]⟩ }
end
lemma degree_nonneg_iff_ne_zero : 0 ≤ degree p ↔ p ≠ 0 :=
⟨λ h0p hp0, absurd h0p (by rw [hp0, degree_zero]; exact dec_trivial),
λ hp0, le_of_not_gt (λ h, by simp [gt, degree_eq_bot, *] at *)⟩
lemma nat_degree_eq_zero_iff_degree_le_zero : p.nat_degree = 0 ↔ p.degree ≤ 0 :=
if hp0 : p = 0 then by simp [hp0]
else by rw [degree_eq_nat_degree hp0, ← with_bot.coe_zero, with_bot.coe_le_coe,
nat.le_zero_iff]
lemma eq_one_of_is_unit_of_monic (hm : monic p) (hpu : is_unit p) : p = 1 :=
have degree p ≤ 0,
from calc degree p ≤ degree (1 : polynomial R) :
let ⟨u, hu⟩ := is_unit_iff_dvd_one.1 hpu in
if hu0 : u = 0
then begin
rw [hu0, mul_zero] at hu,
rw [← mul_one p, hu, mul_zero],
simp
end
else have p.leading_coeff * u.leading_coeff ≠ 0,
by rw [hm.leading_coeff, one_mul, ne.def, leading_coeff_eq_zero];
exact hu0,
by rw [hu, degree_mul_eq' this];
exact le_add_of_nonneg_right' (degree_nonneg_iff_ne_zero.2 hu0)
... ≤ 0 : degree_one_le,
by rw [eq_C_of_degree_le_zero this, ← nat_degree_eq_zero_iff_degree_le_zero.2 this,
← leading_coeff, hm.leading_coeff, C_1]
end comm_semiring
instance subsingleton [subsingleton R] [comm_semiring R] : subsingleton (polynomial R) :=
⟨λ _ _, ext (λ _, subsingleton.elim _ _)⟩
section comm_semiring
variables [comm_semiring R] {p q r : polynomial R}
lemma ne_zero_of_monic_of_zero_ne_one (hp : monic p) (h : (0 : R) ≠ 1) :
p ≠ 0 := mt (congr_arg leading_coeff) $ by rw [monic.def.1 hp, leading_coeff_zero]; cc
lemma eq_X_add_C_of_degree_le_one (h : degree p ≤ 1) :
p = C (p.coeff 1) * X + C (p.coeff 0) :=
ext (λ n, nat.cases_on n (by simp)
(λ n, nat.cases_on n (by simp [coeff_C])
(λ m, have degree p < m.succ.succ, from lt_of_le_of_lt h dec_trivial,
by simp [coeff_eq_zero_of_degree_lt this, coeff_C, nat.succ_ne_zero, coeff_X,
nat.succ_inj', @eq_comm ℕ 0])))
lemma eq_X_add_C_of_degree_eq_one (h : degree p = 1) :
p = C (p.leading_coeff) * X + C (p.coeff 0) :=
(eq_X_add_C_of_degree_le_one (show degree p ≤ 1, from h ▸ le_refl _)).trans
(by simp [leading_coeff, nat_degree_eq_of_degree_eq_some h])
theorem degree_C_mul_X_pow_le (r : R) (n : ℕ) : degree (C r * X^n) ≤ n :=
begin
rw [← single_eq_C_mul_X],
refine finset.sup_le (λ b hb, _),
rw list.eq_of_mem_singleton (finsupp.support_single_subset hb),
exact le_refl _
end
theorem degree_X_pow_le (n : ℕ) : degree (X^n : polynomial R) ≤ n :=
by simpa only [C_1, one_mul] using degree_C_mul_X_pow_le (1:R) n
theorem degree_X_le : degree (X : polynomial R) ≤ 1 :=
by simpa only [C_1, one_mul, pow_one] using degree_C_mul_X_pow_le (1:R) 1
section injective
open function
variables [comm_semiring S] {f : R →+* S} (hf : function.injective f)
include hf
lemma degree_map_eq_of_injective (p : polynomial R) : degree (p.map f) = degree p :=
if h : p = 0 then by simp [h]
else degree_map_eq_of_leading_coeff_ne_zero _
(by rw [← is_semiring_hom.map_zero f]; exact mt hf.eq_iff.1
(mt leading_coeff_eq_zero.1 h))
lemma degree_map' (p : polynomial R) :
degree (p.map f) = degree p :=
p.degree_map_eq_of_injective hf
lemma nat_degree_map' (p : polynomial R) :
nat_degree (p.map f) = nat_degree p :=
nat_degree_eq_of_degree_eq (degree_map' hf p)
lemma map_injective : injective (map f) :=
λ p q h, ext $ λ m, hf $
begin
rw ext_iff at h,
specialize h m,
rw [coeff_map f, coeff_map f] at h,
exact h
end
lemma leading_coeff_of_injective (p : polynomial R) :
leading_coeff (p.map f) = f (leading_coeff p) :=
begin
delta leading_coeff,
rw [coeff_map f, nat_degree_map' hf p]
end
lemma monic_of_injective {p : polynomial R} (hp : (p.map f).monic) : p.monic :=
begin
apply hf,
rw [← leading_coeff_of_injective hf, hp.leading_coeff, is_semiring_hom.map_one f]
end
end injective
theorem monic_of_degree_le (n : ℕ) (H1 : degree p ≤ n) (H2 : coeff p n = 1) : monic p :=
decidable.by_cases
(assume H : degree p < n, @subsingleton.elim _ (subsingleton_of_zero_eq_one R $
H2 ▸ (coeff_eq_zero_of_degree_lt H).symm) _ _)
(assume H : ¬degree p < n,
by rwa [monic, leading_coeff, nat_degree, (lt_or_eq_of_le H1).resolve_left H])
theorem monic_X_pow_add {n : ℕ} (H : degree p ≤ n) : monic (X ^ (n+1) + p) :=
have H1 : degree p < n+1, from lt_of_le_of_lt H (with_bot.coe_lt_coe.2 (nat.lt_succ_self n)),
monic_of_degree_le (n+1)
(le_trans (degree_add_le _ _) (max_le (degree_X_pow_le _) (le_of_lt H1)))
(by rw [coeff_add, coeff_X_pow, if_pos rfl, coeff_eq_zero_of_degree_lt H1, add_zero])
theorem monic_X_add_C (x : R) : monic (X + C x) :=
pow_one (X : polynomial R) ▸ monic_X_pow_add degree_C_le
theorem degree_le_iff_coeff_zero (f : polynomial R) (n : with_bot ℕ) :
degree f ≤ n ↔ ∀ m : ℕ, n < m → coeff f m = 0 :=
⟨λ (H : finset.sup (f.support) some ≤ n) m (Hm : n < (m : with_bot ℕ)), decidable.of_not_not $ λ H4,
have H1 : m ∉ f.support,
from λ H2, not_lt_of_ge ((finset.sup_le_iff.1 H) m H2 : ((m : with_bot ℕ) ≤ n)) Hm,
H1 $ (finsupp.mem_support_to_fun f m).2 H4,
λ H, finset.sup_le $ λ b Hb, decidable.of_not_not $ λ Hn,
(finsupp.mem_support_to_fun f b).1 Hb $ H b $ lt_of_not_ge Hn⟩
theorem nat_degree_le_of_degree_le {p : polynomial R} {n : ℕ}
(H : degree p ≤ n) : nat_degree p ≤ n :=
show option.get_or_else (degree p) 0 ≤ n, from match degree p, H with
| none, H := zero_le _
| (some d), H := with_bot.coe_le_coe.1 H
end
theorem leading_coeff_mul_X_pow {p : polynomial R} {n : ℕ} :
leading_coeff (p * X ^ n) = leading_coeff p :=
decidable.by_cases
(λ H : leading_coeff p = 0, by rw [H, leading_coeff_eq_zero.1 H, zero_mul, leading_coeff_zero])
(λ H : leading_coeff p ≠ 0,
by rw [leading_coeff_mul', leading_coeff_X_pow, mul_one];
rwa [leading_coeff_X_pow, mul_one])
lemma monic_mul (hp : monic p) (hq : monic q) : monic (p * q) :=
if h0 : (0 : R) = 1 then by haveI := subsingleton_of_zero_eq_one _ h0;
exact subsingleton.elim _ _
else
have leading_coeff p * leading_coeff q ≠ 0, by simp [monic.def.1 hp, monic.def.1 hq, ne.symm h0],
by rw [monic.def, leading_coeff_mul' this, monic.def.1 hp, monic.def.1 hq, one_mul]
lemma monic_pow (hp : monic p) : ∀ (n : ℕ), monic (p ^ n)
| 0 := monic_one
| (n+1) := monic_mul hp (monic_pow n)
lemma multiplicity_finite_of_degree_pos_of_monic (hp : (0 : with_bot ℕ) < degree p)
(hmp : monic p) (hq : q ≠ 0) : multiplicity.finite p q :=
have zn0 : (0 : R) ≠ 1, from λ h, by haveI := subsingleton_of_zero_eq_one _ h;
exact hq (subsingleton.elim _ _),
⟨nat_degree q, λ ⟨r, hr⟩,
have hp0 : p ≠ 0, from λ hp0, by simp [hp0] at hp; contradiction,
have hr0 : r ≠ 0, from λ hr0, by simp * at *,
have hpn1 : leading_coeff p ^ (nat_degree q + 1) = 1,
by simp [show _ = _, from hmp],
have hpn0' : leading_coeff p ^ (nat_degree q + 1) ≠ 0,
from hpn1.symm ▸ zn0.symm,
have hpnr0 : leading_coeff (p ^ (nat_degree q + 1)) * leading_coeff r ≠ 0,
by simp only [leading_coeff_pow' hpn0', leading_coeff_eq_zero, hpn1,
one_pow, one_mul, ne.def, hr0]; simp,
have hpn0 : p ^ (nat_degree q + 1) ≠ 0,
from mt leading_coeff_eq_zero.2 $
by rw [leading_coeff_pow' hpn0', show _ = _, from hmp, one_pow]; exact zn0.symm,
have hnp : 0 < nat_degree p,
by rw [← with_bot.coe_lt_coe, ← degree_eq_nat_degree hp0];
exact hp,
begin
have := congr_arg nat_degree hr,
rw [nat_degree_mul_eq' hpnr0, nat_degree_pow_eq' hpn0', add_mul, add_assoc] at this,
exact ne_of_lt (lt_add_of_le_of_pos (le_mul_of_one_le_right' (nat.zero_le _) hnp)
(add_pos_of_pos_of_nonneg (by rwa one_mul) (nat.zero_le _))) this
end⟩
end comm_semiring
section nonzero_comm_semiring
variables [comm_semiring R] [nonzero R] {p q : polynomial R}
instance : nonzero (polynomial R) :=
{ zero_ne_one := λ (h : (0 : polynomial R) = 1), zero_ne_one $
calc (0 : R) = eval 0 0 : eval_zero.symm
... = eval 0 1 : congr_arg _ h
... = 1 : eval_C }
@[simp] lemma degree_one : degree (1 : polynomial R) = (0 : with_bot ℕ) :=
degree_C (show (1 : R) ≠ 0, from zero_ne_one.symm)
@[simp] lemma degree_X : degree (X : polynomial R) = 1 :=
begin
unfold X degree monomial single finsupp.support,
rw if_neg (one_ne_zero : (1 : R) ≠ 0),
refl
end
lemma X_ne_zero : (X : polynomial R) ≠ 0 :=
mt (congr_arg (λ p, coeff p 1)) (by simp)
@[simp] lemma degree_X_pow : ∀ (n : ℕ), degree ((X : polynomial R) ^ n) = n
| 0 := by simp only [pow_zero, degree_one]; refl
| (n+1) :=
have h : leading_coeff (X : polynomial R) * leading_coeff (X ^ n) ≠ 0,
by rw [leading_coeff_X, leading_coeff_X_pow n, one_mul];
exact zero_ne_one.symm,
by rw [pow_succ, degree_mul_eq' h, degree_X, degree_X_pow, add_comm]; refl
@[simp] lemma not_monic_zero : ¬monic (0 : polynomial R) :=
by simpa only [monic, leading_coeff_zero] using (zero_ne_one : (0 : R) ≠ 1)
lemma ne_zero_of_monic (h : monic p) : p ≠ 0 :=
λ h₁, @not_monic_zero R _ _ (h₁ ▸ h)
end nonzero_comm_semiring
section comm_semiring
variables [comm_semiring R] {p q : polynomial R}
/-- `dix_X p` return a polynomial `q` such that `q * X + C (p.coeff 0) = p`.
It can be used in a semiring where the usual division algorithm is not possible -/
def div_X (p : polynomial R) : polynomial R :=
{ to_fun := λ n, p.coeff (n + 1),
support := ⟨(p.support.filter (> 0)).1.map (λ n, n - 1),
multiset.nodup_map_on begin
simp only [finset.mem_def.symm, finset.mem_erase, finset.mem_filter],
assume x hx y hy hxy,
rwa [← @add_right_cancel_iff _ _ 1, nat.sub_add_cancel hx.2,
nat.sub_add_cancel hy.2] at hxy
end
(p.support.filter (> 0)).2⟩,
mem_support_to_fun := λ n,
suffices (∃ (a : ℕ), (¬coeff p a = 0 ∧ a > 0) ∧ a - 1 = n) ↔
¬coeff p (n + 1) = 0,
by simpa [finset.mem_def.symm, apply_eq_coeff],
⟨λ ⟨a, ha⟩, by rw [← ha.2, nat.sub_add_cancel ha.1.2]; exact ha.1.1,
λ h, ⟨n + 1, ⟨h, nat.succ_pos _⟩, nat.succ_sub_one _⟩⟩ }
lemma div_X_mul_X_add (p : polynomial R) : div_X p * X + C (p.coeff 0) = p :=
ext $ λ n,
nat.cases_on n
(by simp)
(by simp [coeff_C, nat.succ_ne_zero, coeff_mul_X, div_X])
@[simp] lemma div_X_C (a : R) : div_X (C a) = 0 :=
ext $ λ n, by cases n; simp [div_X, coeff_C]; simp [coeff]
lemma div_X_eq_zero_iff : div_X p = 0 ↔ p = C (p.coeff 0) :=
⟨λ h, by simpa [eq_comm, h] using div_X_mul_X_add p,
λ h, by rw [h, div_X_C]⟩
lemma div_X_add : div_X (p + q) = div_X p + div_X q :=
ext $ by simp [div_X]
theorem nonzero.of_polynomial_ne (h : p ≠ q) : nonzero R :=
{ zero_ne_one := λ h01 : 0 = 1, h $
by rw [← mul_one p, ← mul_one q, ← C_1, ← h01, C_0, mul_zero, mul_zero] }
lemma degree_lt_degree_mul_X (hp : p ≠ 0) : p.degree < (p * X).degree :=
by haveI := nonzero.of_polynomial_ne hp; exact
have leading_coeff p * leading_coeff X ≠ 0, by simpa,
by erw [degree_mul_eq' this, degree_eq_nat_degree hp,
degree_X, ← with_bot.coe_one, ← with_bot.coe_add, with_bot.coe_lt_coe];
exact nat.lt_succ_self _
lemma degree_div_X_lt (hp0 : p ≠ 0) : (div_X p).degree < p.degree :=
by haveI := nonzero.of_polynomial_ne hp0; exact
calc (div_X p).degree < (div_X p * X + C (p.coeff 0)).degree :
if h : degree p ≤ 0
then begin
have h' : C (p.coeff 0) ≠ 0, by rwa [← eq_C_of_degree_le_zero h],
rw [eq_C_of_degree_le_zero h, div_X_C, degree_zero, zero_mul, zero_add],
exact lt_of_le_of_ne bot_le (ne.symm (mt degree_eq_bot.1 $
by simp [h'])),
end
else
have hXp0 : div_X p ≠ 0,
by simpa [div_X_eq_zero_iff, -not_le, degree_le_zero_iff] using h,
have leading_coeff (div_X p) * leading_coeff X ≠ 0, by simpa,
have degree (C (p.coeff 0)) < degree (div_X p * X),
from calc degree (C (p.coeff 0)) ≤ 0 : degree_C_le
... < 1 : dec_trivial
... = degree (X : polynomial R) : degree_X.symm
... ≤ degree (div_X p * X) :
by rw [← zero_add (degree X), degree_mul_eq' this];
exact add_le_add'
(by rw [zero_le_degree_iff, ne.def, div_X_eq_zero_iff];
exact λ h0, h (h0.symm ▸ degree_C_le))
(le_refl _),
by rw [add_comm, degree_add_eq_of_degree_lt this];
exact degree_lt_degree_mul_X hXp0
... = p.degree : by rw div_X_mul_X_add
@[elab_as_eliminator] noncomputable def rec_on_horner
{M : polynomial R → Sort*} : Π (p : polynomial R),
M 0 →
(Π p a, coeff p 0 = 0 → a ≠ 0 → M p → M (p + C a)) →
(Π p, p ≠ 0 → M p → M (p * X)) →
M p
| p := λ M0 MC MX,
if hp : p = 0 then eq.rec_on hp.symm M0
else
have wf : degree (div_X p) < degree p,
from degree_div_X_lt hp,
by rw [← div_X_mul_X_add p] at *;
exact
if hcp0 : coeff p 0 = 0
then by rw [hcp0, C_0, add_zero];
exact MX _ (λ h : div_X p = 0, by simpa [h, hcp0] using hp)
(rec_on_horner _ M0 MC MX)
else MC _ _ (coeff_mul_X_zero _) hcp0 (if hpX0 : div_X p = 0
then show M (div_X p * X), by rw [hpX0, zero_mul]; exact M0
else MX (div_X p) hpX0 (rec_on_horner _ M0 MC MX))
using_well_founded {dec_tac := tactic.assumption}
@[elab_as_eliminator] lemma degree_pos_induction_on
{P : polynomial R → Prop} (p : polynomial R) (h0 : 0 < degree p)
(hC : ∀ {a}, a ≠ 0 → P (C a * X))
(hX : ∀ {p}, 0 < degree p → P p → P (p * X))
(hadd : ∀ {p} {a}, 0 < degree p → P p → P (p + C a)) : P p :=
rec_on_horner p
(λ h, by rw degree_zero at h; exact absurd h dec_trivial)
(λ p a _ _ ih h0,
have 0 < degree p,
from lt_of_not_ge (λ h, (not_lt_of_ge degree_C_le) $
by rwa [eq_C_of_degree_le_zero h, ← C_add] at h0),
hadd this (ih this))
(λ p _ ih h0',
if h0 : 0 < degree p
then hX h0 (ih h0)
else by rw [eq_C_of_degree_le_zero (le_of_not_gt h0)] at *;
exact hC (λ h : coeff p 0 = 0,
by simpa [h, nat.not_lt_zero] using h0'))
h0
end comm_semiring
section comm_ring
variables [comm_ring R] {p q : polynomial R}
instance : comm_ring (polynomial R) := add_monoid_algebra.comm_ring
instance : module R (polynomial R) := add_monoid_algebra.module
variable (R)
def lcoeff (n : ℕ) : polynomial R →ₗ[R] R :=
{ to_fun := λ f, coeff f n,
add := λ f g, coeff_add f g n,
smul := λ r p, coeff_smul p r n }
variable {R}
@[simp] lemma lcoeff_apply (n : ℕ) (f : polynomial R) : lcoeff R n f = coeff f n := rfl
instance : is_ring_hom (C : R → polynomial R) := (C : R →ₐ[R] polynomial R).to_ring_hom.is_ring_hom
lemma int_cast_eq_C (n : ℤ) : (n : polynomial R) = C ↑n :=
((C : R →ₐ[R] _).to_ring_hom.map_int_cast n).symm
lemma C_neg : C (-a) = -C a := alg_hom.map_neg C a
lemma C_sub : C (a - b) = C a - C b := alg_hom.map_sub C a b
instance eval₂.is_ring_hom {S} [comm_ring S]
(f : R → S) [is_ring_hom f] {x : S} : is_ring_hom (eval₂ f x) :=
by apply is_ring_hom.of_semiring
instance eval.is_ring_hom {x : R} : is_ring_hom (eval x) := eval₂.is_ring_hom _
instance map.is_ring_hom {S} [comm_ring S] (f : R →+* S) : is_ring_hom (map f) :=
eval₂.is_ring_hom (C ∘ f)
@[simp] lemma map_sub {S} [comm_ring S] (f : R →+* S) :
(p - q).map f = p.map f - q.map f :=
is_ring_hom.map_sub _
@[simp] lemma map_neg {S} [comm_ring S] (f : R →+* S) :
(-p).map f = -(p.map f) :=
is_ring_hom.map_neg _
@[simp] lemma degree_neg (p : polynomial R) : degree (-p) = degree p :=
by unfold degree; rw support_neg
lemma degree_sub_le (p q : polynomial R) : degree (p - q) ≤ max (degree p) (degree q) :=
degree_neg q ▸ degree_add_le p (-q)
@[simp] lemma nat_degree_neg (p : polynomial R) : nat_degree (-p) = nat_degree p :=
by simp [nat_degree]
@[simp] lemma nat_degree_int_cast (n : ℤ) : nat_degree (n : polynomial R) = 0 :=
by simp [int_cast_eq_C]
@[simp] lemma coeff_neg (p : polynomial R) (n : ℕ) : coeff (-p) n = -coeff p n := rfl
@[simp]
lemma coeff_sub (p q : polynomial R) (n : ℕ) : coeff (p - q) n = coeff p n - coeff q n := rfl
@[simp] lemma eval₂_neg {S} [comm_ring S] (f : R → S) [is_ring_hom f] {x : S} :
(-p).eval₂ f x = -p.eval₂ f x :=
is_ring_hom.map_neg _
@[simp] lemma eval₂_sub {S} [comm_ring S] (f : R → S) [is_ring_hom f] {x : S} :
(p - q).eval₂ f x = p.eval₂ f x - q.eval₂ f x :=
is_ring_hom.map_sub _
@[simp] lemma eval_neg (p : polynomial R) (x : R) : (-p).eval x = -p.eval x :=
is_ring_hom.map_neg _
@[simp] lemma eval_sub (p q : polynomial R) (x : R) : (p - q).eval x = p.eval x - q.eval x :=
is_ring_hom.map_sub _
section aeval
/-- `R[X]` is the generator of the category `R-Alg`. -/
instance polynomial (R : Type u) [comm_semiring R] : algebra R (polynomial R) :=
{ commutes' := λ _ _, mul_comm _ _,
smul_def' := λ c p, (polynomial.C_mul' c p).symm,
.. polynomial.semimodule, .. ring_hom.of polynomial.C }
variables (R) (A)
variables [comm_ring A] [algebra R A]
variables (x : A)
/-- Given a valuation `x` of the variable in an `R`-algebra `A`, `aeval R A x` is
the unique `R`-algebra homomorphism from `R[X]` to `A` sending `X` to `x`. -/
def aeval : polynomial R →ₐ[R] A :=
{ commutes' := λ r, eval₂_C _ _,
..eval₂_ring_hom (algebra_map R A) x }
variables {R A}
theorem aeval_def (p : polynomial R) : aeval R A x p = eval₂ (algebra_map R A) x p := rfl
@[simp] lemma aeval_X : aeval R A x X = x := eval₂_X _ x
@[simp] lemma aeval_C (r : R) : aeval R A x (C r) = algebra_map R A r := eval₂_C _ x
theorem eval_unique (φ : polynomial R →ₐ[R] A) (p) :
φ p = eval₂ (algebra_map R A) (φ X) p :=
begin
apply polynomial.induction_on p,
{ intro r, rw eval₂_C, exact φ.commutes r },
{ intros f g ih1 ih2,
rw [φ.map_add, ih1, ih2, eval₂_add] },
{ intros n r ih,
rw [pow_succ', ← mul_assoc, φ.map_mul, eval₂_mul (algebra_map R A), eval₂_X, ih] }
end
end aeval
lemma degree_sub_lt (hd : degree p = degree q)
(hp0 : p ≠ 0) (hlc : leading_coeff p = leading_coeff q) :
degree (p - q) < degree p :=
have hp : single (nat_degree p) (leading_coeff p) + p.erase (nat_degree p) = p :=
finsupp.single_add_erase,
have hq : single (nat_degree q) (leading_coeff q) + q.erase (nat_degree q) = q :=
finsupp.single_add_erase,
have hd' : nat_degree p = nat_degree q := by unfold nat_degree; rw hd,
have hq0 : q ≠ 0 := mt degree_eq_bot.2 (hd ▸ mt degree_eq_bot.1 hp0),
calc degree (p - q) = degree (erase (nat_degree q) p + -erase (nat_degree q) q) :
by conv {to_lhs, rw [← hp, ← hq, hlc, hd', add_sub_add_left_eq_sub, sub_eq_add_neg]}
... ≤ max (degree (erase (nat_degree q) p)) (degree (erase (nat_degree q) q))
: degree_neg (erase (nat_degree q) q) ▸ degree_add_le _ _
... < degree p : max_lt_iff.2 ⟨hd' ▸ degree_erase_lt hp0, hd.symm ▸ degree_erase_lt hq0⟩
lemma ne_zero_of_ne_zero_of_monic (hp : p ≠ 0) (hq : monic q) : q ≠ 0
| h := begin
rw [h, monic.def, leading_coeff_zero] at hq,
rw [← mul_one p, ← C_1, ← hq, C_0, mul_zero] at hp,
exact hp rfl
end
lemma div_wf_lemma (h : degree q ≤ degree p ∧ p ≠ 0) (hq : monic q) :
degree (p - C (leading_coeff p) * X ^ (nat_degree p - nat_degree q) * q) < degree p :=
have hp : leading_coeff p ≠ 0 := mt leading_coeff_eq_zero.1 h.2,
have hpq : leading_coeff (C (leading_coeff p) * X ^ (nat_degree p - nat_degree q)) *
leading_coeff q ≠ 0,
by rwa [leading_coeff_monomial, monic.def.1 hq, mul_one],
if h0 : p - C (leading_coeff p) * X ^ (nat_degree p - nat_degree q) * q = 0
then h0.symm ▸ (lt_of_not_ge $ mt le_bot_iff.1 (mt degree_eq_bot.1 h.2))
else
have hq0 : q ≠ 0 := ne_zero_of_ne_zero_of_monic h.2 hq,
have hlt : nat_degree q ≤ nat_degree p := with_bot.coe_le_coe.1
(by rw [← degree_eq_nat_degree h.2, ← degree_eq_nat_degree hq0];
exact h.1),
degree_sub_lt
(by rw [degree_mul_eq' hpq, degree_monomial _ hp, degree_eq_nat_degree h.2,
degree_eq_nat_degree hq0, ← with_bot.coe_add, nat.sub_add_cancel hlt])
h.2
(by rw [leading_coeff_mul' hpq, leading_coeff_monomial, monic.def.1 hq, mul_one])
noncomputable def div_mod_by_monic_aux : Π (p : polynomial R) {q : polynomial R},
monic q → polynomial R × polynomial R
| p := λ q hq, if h : degree q ≤ degree p ∧ p ≠ 0 then
let z := C (leading_coeff p) * X^(nat_degree p - nat_degree q) in
have wf : _ := div_wf_lemma h hq,
let dm := div_mod_by_monic_aux (p - z * q) hq in
⟨z + dm.1, dm.2⟩
else ⟨0, p⟩
using_well_founded {dec_tac := tactic.assumption}
/-- `div_by_monic` gives the quotient of `p` by a monic polynomial `q`. -/
def div_by_monic (p q : polynomial R) : polynomial R :=
if hq : monic q then (div_mod_by_monic_aux p hq).1 else 0
/-- `mod_by_monic` gives the remainder of `p` by a monic polynomial `q`. -/
def mod_by_monic (p q : polynomial R) : polynomial R :=
if hq : monic q then (div_mod_by_monic_aux p hq).2 else p
infixl ` /ₘ ` : 70 := div_by_monic
infixl ` %ₘ ` : 70 := mod_by_monic
lemma degree_mod_by_monic_lt : ∀ (p : polynomial R) {q : polynomial R} (hq : monic q)
(hq0 : q ≠ 0), degree (p %ₘ q) < degree q
| p := λ q hq hq0,
if h : degree q ≤ degree p ∧ p ≠ 0 then
have wf : _ := div_wf_lemma ⟨h.1, h.2⟩ hq,
have degree ((p - C (leading_coeff p) * X ^ (nat_degree p - nat_degree q) * q) %ₘ q) < degree q :=
degree_mod_by_monic_lt (p - C (leading_coeff p) * X ^ (nat_degree p - nat_degree q) * q)
hq hq0,
begin
unfold mod_by_monic at this ⊢,
unfold div_mod_by_monic_aux,
rw dif_pos hq at this ⊢,
rw if_pos h,
exact this
end
else
or.cases_on (not_and_distrib.1 h) begin
unfold mod_by_monic div_mod_by_monic_aux,
rw [dif_pos hq, if_neg h],
exact lt_of_not_ge,
end
begin
assume hp,
unfold mod_by_monic div_mod_by_monic_aux,
rw [dif_pos hq, if_neg h, not_not.1 hp],
exact lt_of_le_of_ne bot_le
(ne.symm (mt degree_eq_bot.1 hq0)),
end
using_well_founded {dec_tac := tactic.assumption}
lemma mod_by_monic_eq_sub_mul_div : ∀ (p : polynomial R) {q : polynomial R} (hq : monic q),
p %ₘ q = p - q * (p /ₘ q)
| p := λ q hq,
if h : degree q ≤ degree p ∧ p ≠ 0 then
have wf : _ := div_wf_lemma h hq,
have ih : _ := mod_by_monic_eq_sub_mul_div
(p - C (leading_coeff p) * X ^ (nat_degree p - nat_degree q) * q) hq,
begin
unfold mod_by_monic div_by_monic div_mod_by_monic_aux,
rw [dif_pos hq, if_pos h],
rw [mod_by_monic, dif_pos hq] at ih,
refine ih.trans _,
unfold div_by_monic,
rw [dif_pos hq, dif_pos hq, if_pos h, mul_add, sub_add_eq_sub_sub, mul_comm]
end
else
begin
unfold mod_by_monic div_by_monic div_mod_by_monic_aux,
rw [dif_pos hq, if_neg h, dif_pos hq, if_neg h, mul_zero, sub_zero]
end
using_well_founded {dec_tac := tactic.assumption}
lemma mod_by_monic_add_div (p : polynomial R) {q : polynomial R} (hq : monic q) :
p %ₘ q + q * (p /ₘ q) = p := eq_sub_iff_add_eq.1 (mod_by_monic_eq_sub_mul_div p hq)
@[simp] lemma zero_mod_by_monic (p : polynomial R) : 0 %ₘ p = 0 :=
begin
unfold mod_by_monic div_mod_by_monic_aux,
by_cases hp : monic p,
{ rw [dif_pos hp, if_neg (mt and.right (not_not_intro rfl))] },
{ rw [dif_neg hp] }
end
@[simp] lemma zero_div_by_monic (p : polynomial R) : 0 /ₘ p = 0 :=
begin
unfold div_by_monic div_mod_by_monic_aux,
by_cases hp : monic p,
{ rw [dif_pos hp, if_neg (mt and.right (not_not_intro rfl))] },
{ rw [dif_neg hp] }
end
@[simp] lemma mod_by_monic_zero (p : polynomial R) : p %ₘ 0 = p :=
if h : monic (0 : polynomial R) then (subsingleton_of_monic_zero h).1 _ _ else
by unfold mod_by_monic div_mod_by_monic_aux; rw dif_neg h
@[simp] lemma div_by_monic_zero (p : polynomial R) : p /ₘ 0 = 0 :=
if h : monic (0 : polynomial R) then (subsingleton_of_monic_zero h).1 _ _ else
by unfold div_by_monic div_mod_by_monic_aux; rw dif_neg h
lemma div_by_monic_eq_of_not_monic (p : polynomial R) (hq : ¬monic q) : p /ₘ q = 0 := dif_neg hq
lemma mod_by_monic_eq_of_not_monic (p : polynomial R) (hq : ¬monic q) : p %ₘ q = p := dif_neg hq
lemma mod_by_monic_eq_self_iff (hq : monic q) (hq0 : q ≠ 0) : p %ₘ q = p ↔ degree p < degree q :=
⟨λ h, h ▸ degree_mod_by_monic_lt _ hq hq0,
λ h, have ¬ degree q ≤ degree p := not_le_of_gt h,
by unfold mod_by_monic div_mod_by_monic_aux; rw [dif_pos hq, if_neg (mt and.left this)]⟩
lemma div_by_monic_eq_zero_iff (hq : monic q) (hq0 : q ≠ 0) : p /ₘ q = 0 ↔ degree p < degree q :=
⟨λ h, by have := mod_by_monic_add_div p hq;
rwa [h, mul_zero, add_zero, mod_by_monic_eq_self_iff hq hq0] at this,
λ h, have ¬ degree q ≤ degree p := not_le_of_gt h,
by unfold div_by_monic div_mod_by_monic_aux; rw [dif_pos hq, if_neg (mt and.left this)]⟩
lemma degree_add_div_by_monic (hq : monic q) (h : degree q ≤ degree p) :
degree q + degree (p /ₘ q) = degree p :=
if hq0 : q = 0 then
have ∀ (p : polynomial R), p = 0,
from λ p, (@subsingleton_of_monic_zero R _ (hq0 ▸ hq)).1 _ _,
by rw [this (p /ₘ q), this p, this q]; refl
else
have hdiv0 : p /ₘ q ≠ 0 := by rwa [(≠), div_by_monic_eq_zero_iff hq hq0, not_lt],
have hlc : leading_coeff q * leading_coeff (p /ₘ q) ≠ 0 :=
by rwa [monic.def.1 hq, one_mul, (≠), leading_coeff_eq_zero],
have hmod : degree (p %ₘ q) < degree (q * (p /ₘ q)) :=
calc degree (p %ₘ q) < degree q : degree_mod_by_monic_lt _ hq hq0
... ≤ _ : by rw [degree_mul_eq' hlc, degree_eq_nat_degree hq0,
degree_eq_nat_degree hdiv0, ← with_bot.coe_add, with_bot.coe_le_coe];
exact nat.le_add_right _ _,
calc degree q + degree (p /ₘ q) = degree (q * (p /ₘ q)) : eq.symm (degree_mul_eq' hlc)
... = degree (p %ₘ q + q * (p /ₘ q)) : (degree_add_eq_of_degree_lt hmod).symm
... = _ : congr_arg _ (mod_by_monic_add_div _ hq)
lemma degree_div_by_monic_le (p q : polynomial R) : degree (p /ₘ q) ≤ degree p :=
if hp0 : p = 0 then by simp only [hp0, zero_div_by_monic, le_refl]
else if hq : monic q then
have hq0 : q ≠ 0 := ne_zero_of_ne_zero_of_monic hp0 hq,
if h : degree q ≤ degree p
then by rw [← degree_add_div_by_monic hq h, degree_eq_nat_degree hq0,
degree_eq_nat_degree (mt (div_by_monic_eq_zero_iff hq hq0).1 (not_lt.2 h))];
exact with_bot.coe_le_coe.2 (nat.le_add_left _ _)
else
by unfold div_by_monic div_mod_by_monic_aux;
simp only [dif_pos hq, h, false_and, if_false, degree_zero, bot_le]
else (div_by_monic_eq_of_not_monic p hq).symm ▸ bot_le
lemma degree_div_by_monic_lt (p : polynomial R) {q : polynomial R} (hq : monic q)
(hp0 : p ≠ 0) (h0q : 0 < degree q) : degree (p /ₘ q) < degree p :=
have hq0 : q ≠ 0 := ne_zero_of_ne_zero_of_monic hp0 hq,
if hpq : degree p < degree q
then begin
rw [(div_by_monic_eq_zero_iff hq hq0).2 hpq, degree_eq_nat_degree hp0],
exact with_bot.bot_lt_some _
end
else begin
rw [← degree_add_div_by_monic hq (not_lt.1 hpq), degree_eq_nat_degree hq0,
degree_eq_nat_degree (mt (div_by_monic_eq_zero_iff hq hq0).1 hpq)],
exact with_bot.coe_lt_coe.2 (nat.lt_add_of_pos_left
(with_bot.coe_lt_coe.1 $ (degree_eq_nat_degree hq0) ▸ h0q))
end
lemma div_mod_by_monic_unique {f g} (q r : polynomial R) (hg : monic g)
(h : r + g * q = f ∧ degree r < degree g) : f /ₘ g = q ∧ f %ₘ g = r :=
if hg0 : g = 0 then by split; exact (subsingleton_of_monic_zero
(hg0 ▸ hg : monic (0 : polynomial R))).1 _ _
else
have h₁ : r - f %ₘ g = -g * (q - f /ₘ g),
from eq_of_sub_eq_zero
(by rw [← sub_eq_zero_of_eq (h.1.trans (mod_by_monic_add_div f hg).symm)];
simp [mul_add, mul_comm, sub_eq_add_neg, add_comm, add_left_comm, add_assoc]),
have h₂ : degree (r - f %ₘ g) = degree (g * (q - f /ₘ g)),
by simp [h₁],
have h₄ : degree (r - f %ₘ g) < degree g,
from calc degree (r - f %ₘ g) ≤ max (degree r) (degree (-(f %ₘ g))) :
degree_add_le _ _
... < degree g : max_lt_iff.2 ⟨h.2, by rw degree_neg; exact degree_mod_by_monic_lt _ hg hg0⟩,
have h₅ : q - (f /ₘ g) = 0,
from by_contradiction
(λ hqf, not_le_of_gt h₄ $
calc degree g ≤ degree g + degree (q - f /ₘ g) :
by erw [degree_eq_nat_degree hg0, degree_eq_nat_degree hqf,
with_bot.coe_le_coe];
exact nat.le_add_right _ _
... = degree (r - f %ₘ g) :
by rw [h₂, degree_mul_eq']; simpa [monic.def.1 hg]),
⟨eq.symm $ eq_of_sub_eq_zero h₅,
eq.symm $ eq_of_sub_eq_zero $ by simpa [h₅] using h₁⟩
lemma map_mod_div_by_monic [comm_ring S] (f : R →+* S) (hq : monic q) :
(p /ₘ q).map f = p.map f /ₘ q.map f ∧ (p %ₘ q).map f = p.map f %ₘ q.map f :=
if h01 : (0 : S) = 1 then by haveI := subsingleton_of_zero_eq_one S h01;
exact ⟨subsingleton.elim _ _, subsingleton.elim _ _⟩
else
have h01R : (0 : R) ≠ 1, from mt (congr_arg f)
(by rwa [is_semiring_hom.map_one f, is_semiring_hom.map_zero f]),
have map f p /ₘ map f q = map f (p /ₘ q) ∧ map f p %ₘ map f q = map f (p %ₘ q),
from (div_mod_by_monic_unique ((p /ₘ q).map f) _ (monic_map f hq)
⟨eq.symm $ by rw [← map_mul, ← map_add, mod_by_monic_add_div _ hq],
calc _ ≤ degree (p %ₘ q) : degree_map_le _
... < degree q : degree_mod_by_monic_lt _ hq
$ (ne_zero_of_monic_of_zero_ne_one hq h01R)
... = _ : eq.symm $ degree_map_eq_of_leading_coeff_ne_zero _
(by rw [monic.def.1 hq, is_semiring_hom.map_one f]; exact ne.symm h01)⟩),
⟨this.1.symm, this.2.symm⟩
lemma map_div_by_monic [comm_ring S] (f : R →+* S) (hq : monic q) :
(p /ₘ q).map f = p.map f /ₘ q.map f :=
(map_mod_div_by_monic f hq).1
lemma map_mod_by_monic [comm_ring S] (f : R →+* S) (hq : monic q) :
(p %ₘ q).map f = p.map f %ₘ q.map f :=
(map_mod_div_by_monic f hq).2
lemma dvd_iff_mod_by_monic_eq_zero (hq : monic q) : p %ₘ q = 0 ↔ q ∣ p :=
⟨λ h, by rw [← mod_by_monic_add_div p hq, h, zero_add];
exact dvd_mul_right _ _,
λ h, if hq0 : q = 0 then by rw hq0 at hq;
exact (subsingleton_of_monic_zero hq).1 _ _
else
let ⟨r, hr⟩ := exists_eq_mul_right_of_dvd h in
by_contradiction (λ hpq0,
have hmod : p %ₘ q = q * (r - p /ₘ q) :=
by rw [mod_by_monic_eq_sub_mul_div _ hq, mul_sub, ← hr],
have degree (q * (r - p /ₘ q)) < degree q :=
hmod ▸ degree_mod_by_monic_lt _ hq hq0,
have hrpq0 : leading_coeff (r - p /ₘ q) ≠ 0 :=
λ h, hpq0 $ leading_coeff_eq_zero.1
(by rw [hmod, leading_coeff_eq_zero.1 h, mul_zero, leading_coeff_zero]),
have hlc : leading_coeff q * leading_coeff (r - p /ₘ q) ≠ 0 :=
by rwa [monic.def.1 hq, one_mul],
by rw [degree_mul_eq' hlc, degree_eq_nat_degree hq0,
degree_eq_nat_degree (mt leading_coeff_eq_zero.2 hrpq0)] at this;
exact not_lt_of_ge (nat.le_add_right _ _) (with_bot.some_lt_some.1 this))⟩
@[simp] lemma mod_by_monic_one (p : polynomial R) : p %ₘ 1 = 0 :=
(dvd_iff_mod_by_monic_eq_zero monic_one).2 (one_dvd _)
@[simp] lemma div_by_monic_one (p : polynomial R) : p /ₘ 1 = p :=
by conv_rhs { rw [← mod_by_monic_add_div p monic_one] }; simp
lemma degree_pos_of_root (hp : p ≠ 0) (h : is_root p a) : 0 < degree p :=
lt_of_not_ge $ λ hlt, begin
have := eq_C_of_degree_le_zero hlt,
rw [is_root, this, eval_C] at h,
exact hp (finsupp.ext (λ n, show coeff p n = 0, from
nat.cases_on n h (λ _, coeff_eq_zero_of_degree_lt (lt_of_le_of_lt hlt
(with_bot.coe_lt_coe.2 (nat.succ_pos _)))))),
end
theorem monic_X_sub_C (x : R) : monic (X - C x) :=
by simpa only [C_neg] using monic_X_add_C (-x)
theorem monic_X_pow_sub {n : ℕ} (H : degree p ≤ n) : monic (X ^ (n+1) - p) :=
monic_X_pow_add ((degree_neg p).symm ▸ H)
theorem degree_mod_by_monic_le (p : polynomial R) {q : polynomial R}
(hq : monic q) : degree (p %ₘ q) ≤ degree q :=
decidable.by_cases
(assume H : q = 0, by rw [monic, H, leading_coeff_zero] at hq;
have : (0:polynomial R) = 1 := (by rw [← C_0, ← C_1, hq]);
rw [eq_zero_of_zero_eq_one _ this (p %ₘ q), eq_zero_of_zero_eq_one _ this q]; exact le_refl _)
(assume H : q ≠ 0, le_of_lt $ degree_mod_by_monic_lt _ hq H)
lemma root_X_sub_C : is_root (X - C a) b ↔ a = b :=
by rw [is_root.def, eval_sub, eval_X, eval_C, sub_eq_zero_iff_eq, eq_comm]
end comm_ring
section nonzero_comm_ring
variables [comm_ring R] [nonzero R] {p q : polynomial R}
@[simp] lemma degree_X_sub_C (a : R) : degree (X - C a) = 1 :=
begin
rw [sub_eq_add_neg, add_comm, ← @degree_X R],
by_cases ha : a = 0,
{ simp only [ha, C_0, neg_zero, zero_add] },
exact degree_add_eq_of_degree_lt (by rw [degree_X, degree_neg, degree_C ha]; exact dec_trivial)
end
lemma degree_X_pow_sub_C {n : ℕ} (hn : 0 < n) (a : R) :
degree ((X : polynomial R) ^ n - C a) = n :=
have degree (-C a) < degree ((X : polynomial R) ^ n),
from calc degree (-C a) ≤ 0 : by rw degree_neg; exact degree_C_le
... < degree ((X : polynomial R) ^ n) : by rwa [degree_X_pow];
exact with_bot.coe_lt_coe.2 hn,
by rw [sub_eq_add_neg, add_comm, degree_add_eq_of_degree_lt this, degree_X_pow]
lemma X_pow_sub_C_ne_zero {n : ℕ} (hn : 0 < n) (a : R) :
(X : polynomial R) ^ n - C a ≠ 0 :=
mt degree_eq_bot.2 (show degree ((X : polynomial R) ^ n - C a) ≠ ⊥,
by rw degree_X_pow_sub_C hn a; exact dec_trivial)
end nonzero_comm_ring
section comm_ring
variables [comm_ring R] {p q : polynomial R}
@[simp] lemma mod_by_monic_X_sub_C_eq_C_eval (p : polynomial R) (a : R) :
p %ₘ (X - C a) = C (p.eval a) :=
if h0 : (0 : R) = 1 then by letI := subsingleton_of_zero_eq_one R h0; exact subsingleton.elim _ _
else
by letI : nonzero R := nonzero.of_ne h0; exact
have h : (p %ₘ (X - C a)).eval a = p.eval a :=
by rw [mod_by_monic_eq_sub_mul_div _ (monic_X_sub_C a), eval_sub, eval_mul,
eval_sub, eval_X, eval_C, sub_self, zero_mul, sub_zero],
have degree (p %ₘ (X - C a)) < 1 :=
degree_X_sub_C a ▸ degree_mod_by_monic_lt p (monic_X_sub_C a) ((degree_X_sub_C a).symm ▸
ne_zero_of_monic (monic_X_sub_C _)),
have degree (p %ₘ (X - C a)) ≤ 0 :=
begin
cases (degree (p %ₘ (X - C a))),
{ exact bot_le },
{ exact with_bot.some_le_some.2 (nat.le_of_lt_succ (with_bot.some_lt_some.1 this)) }
end,
begin
rw [eq_C_of_degree_le_zero this, eval_C] at h,
rw [eq_C_of_degree_le_zero this, h]
end
lemma mul_div_by_monic_eq_iff_is_root : (X - C a) * (p /ₘ (X - C a)) = p ↔ is_root p a :=
⟨λ h, by rw [← h, is_root.def, eval_mul, eval_sub, eval_X, eval_C, sub_self, zero_mul],
λ h : p.eval a = 0,
by conv {to_rhs, rw ← mod_by_monic_add_div p (monic_X_sub_C a)};
rw [mod_by_monic_X_sub_C_eq_C_eval, h, C_0, zero_add]⟩
lemma dvd_iff_is_root : (X - C a) ∣ p ↔ is_root p a :=
⟨λ h, by rwa [← dvd_iff_mod_by_monic_eq_zero (monic_X_sub_C _),
mod_by_monic_X_sub_C_eq_C_eval, ← C_0, C_inj] at h,
λ h, ⟨(p /ₘ (X - C a)), by rw mul_div_by_monic_eq_iff_is_root.2 h⟩⟩
lemma mod_by_monic_X (p : polynomial R) : p %ₘ X = C (p.eval 0) :=
by rw [← mod_by_monic_X_sub_C_eq_C_eval, C_0, sub_zero]
section multiplicity
def decidable_dvd_monic (p : polynomial R) (hq : monic q) : decidable (q ∣ p) :=
decidable_of_iff (p %ₘ q = 0) (dvd_iff_mod_by_monic_eq_zero hq)
open_locale classical
lemma multiplicity_X_sub_C_finite (a : R) (h0 : p ≠ 0) :
multiplicity.finite (X - C a) p :=
multiplicity_finite_of_degree_pos_of_monic
(have (0 : R) ≠ 1, from (λ h, by haveI := subsingleton_of_zero_eq_one _ h;
exact h0 (subsingleton.elim _ _)),
by haveI : nonzero R := ⟨this⟩; rw degree_X_sub_C; exact dec_trivial)
(monic_X_sub_C _) h0
def root_multiplicity (a : R) (p : polynomial R) : ℕ :=
if h0 : p = 0 then 0
else let I : decidable_pred (λ n : ℕ, ¬(X - C a) ^ (n + 1) ∣ p) :=
λ n, @not.decidable _ (decidable_dvd_monic p (monic_pow (monic_X_sub_C a) (n + 1))) in
by exactI nat.find (multiplicity_X_sub_C_finite a h0)
lemma root_multiplicity_eq_multiplicity (p : polynomial R) (a : R) :
root_multiplicity a p = if h0 : p = 0 then 0 else
(multiplicity (X - C a) p).get (multiplicity_X_sub_C_finite a h0) :=
by simp [multiplicity, root_multiplicity, roption.dom];
congr; funext; congr
lemma pow_root_multiplicity_dvd (p : polynomial R) (a : R) :
(X - C a) ^ root_multiplicity a p ∣ p :=
if h : p = 0 then by simp [h]
else by rw [root_multiplicity_eq_multiplicity, dif_neg h];
exact multiplicity.pow_multiplicity_dvd _
lemma div_by_monic_mul_pow_root_multiplicity_eq
(p : polynomial R) (a : R) :
p /ₘ ((X - C a) ^ root_multiplicity a p) *
(X - C a) ^ root_multiplicity a p = p :=
have monic ((X - C a) ^ root_multiplicity a p),
from monic_pow (monic_X_sub_C _) _,
by conv_rhs { rw [← mod_by_monic_add_div p this,
(dvd_iff_mod_by_monic_eq_zero this).2 (pow_root_multiplicity_dvd _ _)] };
simp [mul_comm]
lemma eval_div_by_monic_pow_root_multiplicity_ne_zero
{p : polynomial R} (a : R) (hp : p ≠ 0) :
(p /ₘ ((X - C a) ^ root_multiplicity a p)).eval a ≠ 0 :=
begin
haveI : nonzero R := nonzero.of_polynomial_ne hp,
rw [ne.def, ← is_root.def, ← dvd_iff_is_root],
rintros ⟨q, hq⟩,
have := div_by_monic_mul_pow_root_multiplicity_eq p a,
rw [mul_comm, hq, ← mul_assoc, ← pow_succ',
root_multiplicity_eq_multiplicity, dif_neg hp] at this,
exact multiplicity.is_greatest'
(multiplicity_finite_of_degree_pos_of_monic
(show (0 : with_bot ℕ) < degree (X - C a),
by rw degree_X_sub_C; exact dec_trivial) (monic_X_sub_C _) hp)
(nat.lt_succ_self _) (dvd_of_mul_right_eq _ this)
end
end multiplicity
end comm_ring
section integral_domain
variables [integral_domain R] {p q : polynomial R}
@[simp] lemma degree_mul_eq : degree (p * q) = degree p + degree q :=
if hp0 : p = 0 then by simp only [hp0, degree_zero, zero_mul, with_bot.bot_add]
else if hq0 : q = 0 then by simp only [hq0, degree_zero, mul_zero, with_bot.add_bot]
else degree_mul_eq' $ mul_ne_zero (mt leading_coeff_eq_zero.1 hp0)
(mt leading_coeff_eq_zero.1 hq0)
@[simp] lemma degree_pow_eq (p : polynomial R) (n : ℕ) :
degree (p ^ n) = n •ℕ (degree p) :=
by induction n; [simp only [pow_zero, degree_one, zero_nsmul],
simp only [*, pow_succ, succ_nsmul, degree_mul_eq]]
@[simp] lemma leading_coeff_mul (p q : polynomial R) : leading_coeff (p * q) =
leading_coeff p * leading_coeff q :=
begin
by_cases hp : p = 0,
{ simp only [hp, zero_mul, leading_coeff_zero] },
{ by_cases hq : q = 0,
{ simp only [hq, mul_zero, leading_coeff_zero] },
{ rw [leading_coeff_mul'],
exact mul_ne_zero (mt leading_coeff_eq_zero.1 hp) (mt leading_coeff_eq_zero.1 hq) } }
end
@[simp] lemma leading_coeff_pow (p : polynomial R) (n : ℕ) :
leading_coeff (p ^ n) = leading_coeff p ^ n :=
by induction n; [simp only [pow_zero, leading_coeff_one],
simp only [*, pow_succ, leading_coeff_mul]]
instance : integral_domain (polynomial R) :=
{ eq_zero_or_eq_zero_of_mul_eq_zero := λ a b h, begin
have : leading_coeff 0 = leading_coeff a * leading_coeff b := h ▸ leading_coeff_mul a b,
rw [leading_coeff_zero, eq_comm] at this,
erw [← leading_coeff_eq_zero, ← leading_coeff_eq_zero],
exact eq_zero_or_eq_zero_of_mul_eq_zero this
end,
..polynomial.nonzero,
..polynomial.comm_ring }
lemma nat_degree_mul_eq (hp : p ≠ 0) (hq : q ≠ 0) : nat_degree (p * q) =
nat_degree p + nat_degree q :=
by rw [← with_bot.coe_eq_coe, ← degree_eq_nat_degree (mul_ne_zero hp hq),
with_bot.coe_add, ← degree_eq_nat_degree hp,
← degree_eq_nat_degree hq, degree_mul_eq]
@[simp] lemma nat_degree_pow_eq (p : polynomial R) (n : ℕ) :
nat_degree (p ^ n) = n * nat_degree p :=
if hp0 : p = 0
then if hn0 : n = 0 then by simp [hp0, hn0]
else by rw [hp0, zero_pow (nat.pos_of_ne_zero hn0)]; simp
else nat_degree_pow_eq'
(by rw [← leading_coeff_pow, ne.def, leading_coeff_eq_zero]; exact pow_ne_zero _ hp0)
lemma root_or_root_of_root_mul (h : is_root (p * q) a) : is_root p a ∨ is_root q a :=
by rw [is_root, eval_mul] at h;
exact eq_zero_or_eq_zero_of_mul_eq_zero h
lemma degree_le_mul_left (p : polynomial R) (hq : q ≠ 0) : degree p ≤ degree (p * q) :=
if hp : p = 0 then by simp only [hp, zero_mul, le_refl]
else by rw [degree_mul_eq, degree_eq_nat_degree hp,
degree_eq_nat_degree hq];
exact with_bot.coe_le_coe.2 (nat.le_add_right _ _)
lemma exists_finset_roots : ∀ {p : polynomial R} (hp : p ≠ 0),
∃ s : finset R, (s.card : with_bot ℕ) ≤ degree p ∧ ∀ x, x ∈ s ↔ is_root p x
| p := λ hp, by haveI := classical.prop_decidable (∃ x, is_root p x); exact
if h : ∃ x, is_root p x
then
let ⟨x, hx⟩ := h in
have hpd : 0 < degree p := degree_pos_of_root hp hx,
have hd0 : p /ₘ (X - C x) ≠ 0 :=
λ h, by rw [← mul_div_by_monic_eq_iff_is_root.2 hx, h, mul_zero] at hp; exact hp rfl,
have wf : degree (p /ₘ _) < degree p :=
degree_div_by_monic_lt _ (monic_X_sub_C x) hp
((degree_X_sub_C x).symm ▸ dec_trivial),
let ⟨t, htd, htr⟩ := @exists_finset_roots (p /ₘ (X - C x)) hd0 in
have hdeg : degree (X - C x) ≤ degree p := begin
rw [degree_X_sub_C, degree_eq_nat_degree hp],
rw degree_eq_nat_degree hp at hpd,
exact with_bot.coe_le_coe.2 (with_bot.coe_lt_coe.1 hpd)
end,
have hdiv0 : p /ₘ (X - C x) ≠ 0 := mt (div_by_monic_eq_zero_iff (monic_X_sub_C x)
(ne_zero_of_monic (monic_X_sub_C x))).1 $ not_lt.2 hdeg,
⟨insert x t, calc (card (insert x t) : with_bot ℕ) ≤ card t + 1 :
with_bot.coe_le_coe.2 $ finset.card_insert_le _ _
... ≤ degree p :
by rw [← degree_add_div_by_monic (monic_X_sub_C x) hdeg,
degree_X_sub_C, add_comm];
exact add_le_add' (le_refl (1 : with_bot ℕ)) htd,
begin
assume y,
rw [mem_insert, htr, eq_comm, ← root_X_sub_C],
conv {to_rhs, rw ← mul_div_by_monic_eq_iff_is_root.2 hx},
exact ⟨λ h, or.cases_on h (root_mul_right_of_is_root _) (root_mul_left_of_is_root _),
root_or_root_of_root_mul⟩
end⟩
else
⟨∅, (degree_eq_nat_degree hp).symm ▸ with_bot.coe_le_coe.2 (nat.zero_le _),
by simpa only [not_mem_empty, false_iff, not_exists] using h⟩
using_well_founded {dec_tac := tactic.assumption}
/-- `roots p` noncomputably gives a finset containing all the roots of `p` -/
noncomputable def roots (p : polynomial R) : finset R :=
if h : p = 0 then ∅ else classical.some (exists_finset_roots h)
lemma card_roots (hp0 : p ≠ 0) : ((roots p).card : with_bot ℕ) ≤ degree p :=
begin
unfold roots,
rw dif_neg hp0,
exact (classical.some_spec (exists_finset_roots hp0)).1
end
lemma card_roots' {p : polynomial R} (hp0 : p ≠ 0) : p.roots.card ≤ nat_degree p :=
with_bot.coe_le_coe.1 (le_trans (card_roots hp0) (le_of_eq $ degree_eq_nat_degree hp0))
lemma card_roots_sub_C {p : polynomial R} {a : R} (hp0 : 0 < degree p) :
((p - C a).roots.card : with_bot ℕ) ≤ degree p :=
calc ((p - C a).roots.card : with_bot ℕ) ≤ degree (p - C a) :
card_roots $ mt sub_eq_zero.1 $ λ h, not_le_of_gt hp0 $ h.symm ▸ degree_C_le
... = degree p : by rw [sub_eq_add_neg, ← C_neg]; exact degree_add_C hp0
lemma card_roots_sub_C' {p : polynomial R} {a : R} (hp0 : 0 < degree p) :
(p - C a).roots.card ≤ nat_degree p :=
with_bot.coe_le_coe.1 (le_trans (card_roots_sub_C hp0) (le_of_eq $ degree_eq_nat_degree
(λ h, by simp [*, lt_irrefl] at *)))
@[simp] lemma mem_roots (hp : p ≠ 0) : a ∈ p.roots ↔ is_root p a :=
by unfold roots; rw dif_neg hp; exact (classical.some_spec (exists_finset_roots hp)).2 _
@[simp] lemma mem_roots_sub_C {p : polynomial R} {a x : R} (hp0 : 0 < degree p) :
x ∈ (p - C a).roots ↔ p.eval x = a :=
(mem_roots (show p - C a ≠ 0, from mt sub_eq_zero.1 $ λ h,
not_le_of_gt hp0 $ h.symm ▸ degree_C_le)).trans
(by rw [is_root.def, eval_sub, eval_C, sub_eq_zero])
lemma card_roots_X_pow_sub_C {n : ℕ} (hn : 0 < n) (a : R) :
(roots ((X : polynomial R) ^ n - C a)).card ≤ n :=
with_bot.coe_le_coe.1 $
calc ((roots ((X : polynomial R) ^ n - C a)).card : with_bot ℕ)
≤ degree ((X : polynomial R) ^ n - C a) : card_roots (X_pow_sub_C_ne_zero hn a)
... = n : degree_X_pow_sub_C hn a
/-- `nth_roots n a` noncomputably returns the solutions to `x ^ n = a`-/
def nth_roots {R : Type*} [integral_domain R] (n : ℕ) (a : R) : finset R :=
roots ((X : polynomial R) ^ n - C a)
@[simp] lemma mem_nth_roots {R : Type*} [integral_domain R] {n : ℕ} (hn : 0 < n) {a x : R} :
x ∈ nth_roots n a ↔ x ^ n = a :=
by rw [nth_roots, mem_roots (X_pow_sub_C_ne_zero hn a),
is_root.def, eval_sub, eval_C, eval_pow, eval_X, sub_eq_zero_iff_eq]
lemma card_nth_roots {R : Type*} [integral_domain R] (n : ℕ) (a : R) :
(nth_roots n a).card ≤ n :=
if hn : n = 0
then if h : (X : polynomial R) ^ n - C a = 0
then by simp only [nat.zero_le, nth_roots, roots, h, dif_pos rfl, card_empty]
else with_bot.coe_le_coe.1 (le_trans (card_roots h)
(by rw [hn, pow_zero, ← C_1, ← @is_ring_hom.map_sub _ _ _ _ (@C R _)];
exact degree_C_le))
else by rw [← with_bot.coe_le_coe, ← degree_X_pow_sub_C (nat.pos_of_ne_zero hn) a];
exact card_roots (X_pow_sub_C_ne_zero (nat.pos_of_ne_zero hn) a)
lemma coeff_comp_degree_mul_degree (hqd0 : nat_degree q ≠ 0) :
coeff (p.comp q) (nat_degree p * nat_degree q) =
leading_coeff p * leading_coeff q ^ nat_degree p :=
if hp0 : p = 0 then by simp [hp0] else
calc coeff (p.comp q) (nat_degree p * nat_degree q)
= p.sum (λ n a, coeff (C a * q ^ n) (nat_degree p * nat_degree q)) :
by rw [comp, eval₂, coeff_sum]
... = coeff (C (leading_coeff p) * q ^ nat_degree p) (nat_degree p * nat_degree q) :
finset.sum_eq_single _
begin
assume b hbs hbp,
have hq0 : q ≠ 0, from λ hq0, hqd0 (by rw [hq0, nat_degree_zero]),
have : coeff p b ≠ 0, rwa [← apply_eq_coeff, ← finsupp.mem_support_iff],
dsimp [apply_eq_coeff],
refine coeff_eq_zero_of_degree_lt _,
rw [degree_mul_eq, degree_C this, degree_pow_eq, zero_add, degree_eq_nat_degree hq0,
← with_bot.coe_nsmul, nsmul_eq_mul, with_bot.coe_lt_coe, nat.cast_id],
exact (mul_lt_mul_right (nat.pos_of_ne_zero hqd0)).2
(lt_of_le_of_ne (with_bot.coe_le_coe.1 (by rw ← degree_eq_nat_degree hp0; exact le_sup hbs))
hbp)
end
(by rw [finsupp.mem_support_iff, apply_eq_coeff, ← leading_coeff, ne.def, leading_coeff_eq_zero,
classical.not_not]; simp {contextual := tt})
... = _ :
have coeff (q ^ nat_degree p) (nat_degree p * nat_degree q) = leading_coeff (q ^ nat_degree p),
by rw [leading_coeff, nat_degree_pow_eq],
by rw [coeff_C_mul, this, leading_coeff_pow]
lemma nat_degree_comp : nat_degree (p.comp q) = nat_degree p * nat_degree q :=
le_antisymm nat_degree_comp_le
(if hp0 : p = 0 then by rw [hp0, zero_comp, nat_degree_zero, zero_mul]
else if hqd0 : nat_degree q = 0
then have degree q ≤ 0, by rw [← with_bot.coe_zero, ← hqd0]; exact degree_le_nat_degree,
by rw [eq_C_of_degree_le_zero this]; simp
else le_nat_degree_of_ne_zero $
have hq0 : q ≠ 0, from λ hq0, hqd0 $ by rw [hq0, nat_degree_zero],
calc coeff (p.comp q) (nat_degree p * nat_degree q)
= leading_coeff p * leading_coeff q ^ nat_degree p :
coeff_comp_degree_mul_degree hqd0
... ≠ 0 : mul_ne_zero (mt leading_coeff_eq_zero.1 hp0)
(pow_ne_zero _ (mt leading_coeff_eq_zero.1 hq0)))
lemma leading_coeff_comp (hq : nat_degree q ≠ 0) : leading_coeff (p.comp q) =
leading_coeff p * leading_coeff q ^ nat_degree p :=
by rw [← coeff_comp_degree_mul_degree hq, ← nat_degree_comp]; refl
lemma degree_eq_zero_of_is_unit (h : is_unit p) : degree p = 0 :=
let ⟨q, hq⟩ := is_unit_iff_dvd_one.1 h in
have hp0 : p ≠ 0, from λ hp0, by simpa [hp0] using hq,
have hq0 : q ≠ 0, from λ hp0, by simpa [hp0] using hq,
have nat_degree (1 : polynomial R) = nat_degree (p * q),
from congr_arg _ hq,
by rw [nat_degree_one, nat_degree_mul_eq hp0 hq0, eq_comm,
_root_.add_eq_zero_iff, ← with_bot.coe_eq_coe,
← degree_eq_nat_degree hp0] at this;
exact this.1
@[simp] lemma degree_coe_units (u : units (polynomial R)) :
degree (u : polynomial R) = 0 :=
degree_eq_zero_of_is_unit ⟨u, rfl⟩
@[simp] lemma nat_degree_coe_units (u : units (polynomial R)) :
nat_degree (u : polynomial R) = 0 :=
nat_degree_eq_of_degree_eq_some (degree_coe_units u)
lemma coeff_coe_units_zero_ne_zero (u : units (polynomial R)) :
coeff (u : polynomial R) 0 ≠ 0 :=
begin
conv in (0) {rw [← nat_degree_coe_units u]},
rw [← leading_coeff, ne.def, leading_coeff_eq_zero],
exact units.coe_ne_zero _
end
lemma degree_eq_degree_of_associated (h : associated p q) : degree p = degree q :=
let ⟨u, hu⟩ := h in by simp [hu.symm]
lemma degree_eq_one_of_irreducible_of_root (hi : irreducible p) {x : R} (hx : is_root p x) :
degree p = 1 :=
let ⟨g, hg⟩ := dvd_iff_is_root.2 hx in
have is_unit (X - C x) ∨ is_unit g, from hi.2 _ _ hg,
this.elim
(λ h, have h₁ : degree (X - C x) = 1, from degree_X_sub_C x,
have h₂ : degree (X - C x) = 0, from degree_eq_zero_of_is_unit h,
by rw h₁ at h₂; exact absurd h₂ dec_trivial)
(λ hgu, by rw [hg, degree_mul_eq, degree_X_sub_C, degree_eq_zero_of_is_unit hgu, add_zero])
lemma prime_of_degree_eq_one_of_monic (hp1 : degree p = 1)
(hm : monic p) : prime p :=
have p = X - C (- p.coeff 0),
by simpa [hm.leading_coeff] using eq_X_add_C_of_degree_eq_one hp1,
⟨mt degree_eq_bot.2 $ hp1.symm ▸ dec_trivial,
mt degree_eq_zero_of_is_unit (by simp [hp1]; exact dec_trivial),
λ _ _, begin
rw [this, dvd_iff_is_root, dvd_iff_is_root, dvd_iff_is_root,
is_root, is_root, is_root, eval_mul, mul_eq_zero],
exact id
end⟩
lemma irreducible_of_degree_eq_one_of_monic (hp1 : degree p = 1)
(hm : monic p) : irreducible p :=
irreducible_of_prime (prime_of_degree_eq_one_of_monic hp1 hm)
end integral_domain
section field
variables [field R] {p q : polynomial R}
instance : vector_space R (polynomial R) := finsupp.vector_space _ _
lemma is_unit_iff_degree_eq_zero : is_unit p ↔ degree p = 0 :=
⟨degree_eq_zero_of_is_unit,
λ h, have degree p ≤ 0, by simp [*, le_refl],
have hc : coeff p 0 ≠ 0, from λ hc,
by rw [eq_C_of_degree_le_zero this, hc] at h;
simpa using h,
is_unit_iff_dvd_one.2 ⟨C (coeff p 0)⁻¹, begin
conv in p { rw eq_C_of_degree_le_zero this },
rw [← C_mul, _root_.mul_inv_cancel hc, C_1]
end⟩⟩
lemma degree_pos_of_ne_zero_of_nonunit (hp0 : p ≠ 0) (hp : ¬is_unit p) :
0 < degree p :=
lt_of_not_ge (λ h, by rw [eq_C_of_degree_le_zero h] at hp0 hp;
exact (hp $ is_unit.map' C $
is_unit.mk0 (coeff p 0) (mt C_inj.2 (by simpa using hp0))))
lemma monic_mul_leading_coeff_inv (h : p ≠ 0) :
monic (p * C (leading_coeff p)⁻¹) :=
by rw [monic, leading_coeff_mul, leading_coeff_C,
mul_inv_cancel (show leading_coeff p ≠ 0, from mt leading_coeff_eq_zero.1 h)]
lemma degree_mul_leading_coeff_inv (p : polynomial R) (h : q ≠ 0) :
degree (p * C (leading_coeff q)⁻¹) = degree p :=
have h₁ : (leading_coeff q)⁻¹ ≠ 0 :=
inv_ne_zero (mt leading_coeff_eq_zero.1 h),
by rw [degree_mul_eq, degree_C h₁, add_zero]
def div (p q : polynomial R) :=
C (leading_coeff q)⁻¹ * (p /ₘ (q * C (leading_coeff q)⁻¹))
def mod (p q : polynomial R) :=
p %ₘ (q * C (leading_coeff q)⁻¹)
private lemma quotient_mul_add_remainder_eq_aux (p q : polynomial R) :
q * div p q + mod p q = p :=
if h : q = 0 then by simp only [h, zero_mul, mod, mod_by_monic_zero, zero_add]
else begin
conv {to_rhs, rw ← mod_by_monic_add_div p (monic_mul_leading_coeff_inv h)},
rw [div, mod, add_comm, mul_assoc]
end
private lemma remainder_lt_aux (p : polynomial R) (hq : q ≠ 0) :
degree (mod p q) < degree q :=
by rw ← degree_mul_leading_coeff_inv q hq; exact
degree_mod_by_monic_lt p (monic_mul_leading_coeff_inv hq)
(mul_ne_zero hq (mt leading_coeff_eq_zero.2 (by rw leading_coeff_C;
exact inv_ne_zero (mt leading_coeff_eq_zero.1 hq))))
instance : has_div (polynomial R) := ⟨div⟩
instance : has_mod (polynomial R) := ⟨mod⟩
lemma div_def : p / q = C (leading_coeff q)⁻¹ * (p /ₘ (q * C (leading_coeff q)⁻¹)) := rfl
lemma mod_def : p % q = p %ₘ (q * C (leading_coeff q)⁻¹) := rfl
lemma mod_by_monic_eq_mod (p : polynomial R) (hq : monic q) : p %ₘ q = p % q :=
show p %ₘ q = p %ₘ (q * C (leading_coeff q)⁻¹), by simp only [monic.def.1 hq, inv_one, mul_one, C_1]
lemma div_by_monic_eq_div (p : polynomial R) (hq : monic q) : p /ₘ q = p / q :=
show p /ₘ q = C (leading_coeff q)⁻¹ * (p /ₘ (q * C (leading_coeff q)⁻¹)),
by simp only [monic.def.1 hq, inv_one, C_1, one_mul, mul_one]
lemma mod_X_sub_C_eq_C_eval (p : polynomial R) (a : R) : p % (X - C a) = C (p.eval a) :=
mod_by_monic_eq_mod p (monic_X_sub_C a) ▸ mod_by_monic_X_sub_C_eq_C_eval _ _
lemma mul_div_eq_iff_is_root : (X - C a) * (p / (X - C a)) = p ↔ is_root p a :=
div_by_monic_eq_div p (monic_X_sub_C a) ▸ mul_div_by_monic_eq_iff_is_root
instance : euclidean_domain (polynomial R) :=
{ quotient := (/),
quotient_zero := by simp [div_def],
remainder := (%),
r := _,
r_well_founded := degree_lt_wf,
quotient_mul_add_remainder_eq := quotient_mul_add_remainder_eq_aux,
remainder_lt := λ p q hq, remainder_lt_aux _ hq,
mul_left_not_lt := λ p q hq, not_lt_of_ge (degree_le_mul_left _ hq),
.. polynomial.comm_ring,
.. polynomial.nonzero }
lemma mod_eq_self_iff (hq0 : q ≠ 0) : p % q = p ↔ degree p < degree q :=
⟨λ h, h ▸ euclidean_domain.mod_lt _ hq0,
λ h, have ¬degree (q * C (leading_coeff q)⁻¹) ≤ degree p :=
not_le_of_gt $ by rwa degree_mul_leading_coeff_inv q hq0,
begin
rw [mod_def, mod_by_monic, dif_pos (monic_mul_leading_coeff_inv hq0)],
unfold div_mod_by_monic_aux,
simp only [this, false_and, if_false]
end⟩
lemma div_eq_zero_iff (hq0 : q ≠ 0) : p / q = 0 ↔ degree p < degree q :=
⟨λ h, by have := euclidean_domain.div_add_mod p q;
rwa [h, mul_zero, zero_add, mod_eq_self_iff hq0] at this,
λ h, have hlt : degree p < degree (q * C (leading_coeff q)⁻¹),
by rwa degree_mul_leading_coeff_inv q hq0,
have hm : monic (q * C (leading_coeff q)⁻¹) := monic_mul_leading_coeff_inv hq0,
by rw [div_def, (div_by_monic_eq_zero_iff hm (ne_zero_of_monic hm)).2 hlt, mul_zero]⟩
lemma degree_add_div (hq0 : q ≠ 0) (hpq : degree q ≤ degree p) :
degree q + degree (p / q) = degree p :=
have degree (p % q) < degree (q * (p / q)) :=
calc degree (p % q) < degree q : euclidean_domain.mod_lt _ hq0
... ≤ _ : degree_le_mul_left _ (mt (div_eq_zero_iff hq0).1 (not_lt_of_ge hpq)),
by conv {to_rhs, rw [← euclidean_domain.div_add_mod p q, add_comm,
degree_add_eq_of_degree_lt this, degree_mul_eq]}
lemma degree_div_le (p q : polynomial R) : degree (p / q) ≤ degree p :=
if hq : q = 0 then by simp [hq]
else by rw [div_def, mul_comm, degree_mul_leading_coeff_inv _ hq];
exact degree_div_by_monic_le _ _
lemma degree_div_lt (hp : p ≠ 0) (hq : 0 < degree q) : degree (p / q) < degree p :=
have hq0 : q ≠ 0, from λ hq0, by simpa [hq0] using hq,
by rw [div_def, mul_comm, degree_mul_leading_coeff_inv _ hq0];
exact degree_div_by_monic_lt _ (monic_mul_leading_coeff_inv hq0) hp
(by rw degree_mul_leading_coeff_inv _ hq0; exact hq)
@[simp] lemma degree_map [field k] (p : polynomial R) (f : R →+* k) :
degree (p.map f) = degree p :=
p.degree_map_eq_of_injective (is_ring_hom.injective f)
@[simp] lemma nat_degree_map [field k] (f : R →+* k) :
nat_degree (p.map f) = nat_degree p :=
nat_degree_eq_of_degree_eq (degree_map _ f)
@[simp] lemma leading_coeff_map [field k] (f : R →+* k) :
leading_coeff (p.map f) = f (leading_coeff p) :=
by simp [leading_coeff, coeff_map f]
lemma map_div [field k] (f : R →+* k) :
(p / q).map f = p.map f / q.map f :=
if hq0 : q = 0 then by simp [hq0]
else
by rw [div_def, div_def, map_mul, map_div_by_monic f (monic_mul_leading_coeff_inv hq0)];
simp [is_ring_hom.map_inv f, leading_coeff, coeff_map f]
lemma map_mod [field k] (f : R →+* k) :
(p % q).map f = p.map f % q.map f :=
if hq0 : q = 0 then by simp [hq0]
else by rw [mod_def, mod_def, leading_coeff_map f, ← is_ring_hom.map_inv f, ← map_C f,
← map_mul f, map_mod_by_monic f (monic_mul_leading_coeff_inv hq0)]
@[simp] lemma map_eq_zero [field k] (f : R →+* k) :
p.map f = 0 ↔ p = 0 :=
by simp [polynomial.ext_iff, is_ring_hom.map_eq_zero f, coeff_map]
lemma exists_root_of_degree_eq_one (h : degree p = 1) : ∃ x, is_root p x :=
⟨-(p.coeff 0 / p.coeff 1),
have p.coeff 1 ≠ 0,
by rw ← nat_degree_eq_of_degree_eq_some h;
exact mt leading_coeff_eq_zero.1 (λ h0, by simpa [h0] using h),
by conv in p { rw [eq_X_add_C_of_degree_le_one (show degree p ≤ 1, by rw h; exact le_refl _)] };
simp [is_root, mul_div_cancel' _ this]⟩
lemma coeff_inv_units (u : units (polynomial R)) (n : ℕ) :
((↑u : polynomial R).coeff n)⁻¹ = ((↑u⁻¹ : polynomial R).coeff n) :=
begin
rw [eq_C_of_degree_eq_zero (degree_coe_units u), eq_C_of_degree_eq_zero (degree_coe_units u⁻¹),
coeff_C, coeff_C, inv_eq_one_div],
split_ifs,
{ rw [div_eq_iff_mul_eq (coeff_coe_units_zero_ne_zero u), coeff_zero_eq_eval_zero,
coeff_zero_eq_eval_zero, ← eval_mul, ← units.coe_mul, inv_mul_self];
simp },
{ simp }
end
instance : normalization_domain (polynomial R) :=
{ norm_unit := λ p, if hp0 : p = 0 then 1
else ⟨C p.leading_coeff⁻¹, C p.leading_coeff,
by rw [← C_mul, inv_mul_cancel, C_1];
exact mt leading_coeff_eq_zero.1 hp0,
by rw [← C_mul, mul_inv_cancel, C_1];
exact mt leading_coeff_eq_zero.1 hp0,⟩,
norm_unit_zero := dif_pos rfl,
norm_unit_mul := λ p q hp0 hq0, begin
rw [dif_neg hp0, dif_neg hq0, dif_neg (mul_ne_zero hp0 hq0)],
apply units.ext,
show C (leading_coeff (p * q))⁻¹ = C (leading_coeff p)⁻¹ * C (leading_coeff q)⁻¹,
rw [leading_coeff_mul, mul_inv', C_mul, mul_comm]
end,
norm_unit_coe_units := λ u,
have hu : degree ↑u⁻¹ = 0, from degree_eq_zero_of_is_unit ⟨u⁻¹, rfl⟩,
begin
apply units.ext,
rw [dif_neg (units.coe_ne_zero u)],
conv_rhs {rw eq_C_of_degree_eq_zero hu},
refine C_inj.2 _,
rw [← nat_degree_eq_of_degree_eq_some hu, leading_coeff,
coeff_inv_units],
simp
end,
..polynomial.integral_domain }
lemma monic_normalize (hp0 : p ≠ 0) : monic (normalize p) :=
show leading_coeff (p * ↑(dite _ _ _)) = 1,
by rw dif_neg hp0; exact monic_mul_leading_coeff_inv hp0
lemma coe_norm_unit (hp : p ≠ 0) : (norm_unit p : polynomial R) = C p.leading_coeff⁻¹ :=
show ↑(dite _ _ _) = C p.leading_coeff⁻¹, by rw dif_neg hp; refl
@[simp] lemma degree_normalize : degree (normalize p) = degree p :=
if hp0 : p = 0 then by simp [hp0]
else by rw [normalize, degree_mul_eq, degree_eq_zero_of_is_unit (is_unit_unit _), add_zero]
lemma prime_of_degree_eq_one (hp1 : degree p = 1) : prime p :=
have prime (normalize p),
from prime_of_degree_eq_one_of_monic (hp1 ▸ degree_normalize)
(monic_normalize (λ hp0, absurd hp1 (hp0.symm ▸ by simp; exact dec_trivial))),
prime_of_associated normalize_associated this
lemma irreducible_of_degree_eq_one (hp1 : degree p = 1) : irreducible p :=
irreducible_of_prime (prime_of_degree_eq_one hp1)
end field
section derivative
variables [comm_semiring R]
/-- `derivative p` is the formal derivative of the polynomial `p` -/
def derivative (p : polynomial R) : polynomial R := p.sum (λn a, C (a * n) * X^(n - 1))
lemma coeff_derivative (p : polynomial R) (n : ℕ) :
coeff (derivative p) n = coeff p (n + 1) * (n + 1) :=
begin
rw [derivative],
simp only [coeff_X_pow, coeff_sum, coeff_C_mul],
rw [finsupp.sum, finset.sum_eq_single (n + 1), apply_eq_coeff],
{ rw [if_pos (nat.add_sub_cancel _ _).symm, mul_one, nat.cast_add, nat.cast_one] },
{ assume b, cases b,
{ intros, rw [nat.cast_zero, mul_zero, zero_mul] },
{ intros _ H, rw [nat.succ_sub_one b, if_neg (mt (congr_arg nat.succ) H.symm), mul_zero] } },
{ intro H, rw [not_mem_support_iff.1 H, zero_mul, zero_mul] }
end
@[simp] lemma derivative_zero : derivative (0 : polynomial R) = 0 :=
finsupp.sum_zero_index
lemma derivative_monomial (a : R) (n : ℕ) : derivative (C a * X ^ n) = C (a * n) * X^(n - 1) :=
by rw [← single_eq_C_mul_X, ← single_eq_C_mul_X, derivative, sum_single_index, single_eq_C_mul_X];
simp only [zero_mul, C_0]; refl
@[simp] lemma derivative_C {a : R} : derivative (C a) = 0 :=
suffices derivative (C a * X^0) = C (a * 0:R) * X ^ 0,
by simpa only [mul_one, zero_mul, C_0, mul_zero, pow_zero],
derivative_monomial a 0
@[simp] lemma derivative_X : derivative (X : polynomial R) = 1 :=
by simpa only [mul_one, one_mul, C_1, pow_one, nat.cast_one, pow_zero]
using derivative_monomial (1:R) 1
@[simp] lemma derivative_one : derivative (1 : polynomial R) = 0 :=
derivative_C
@[simp] lemma derivative_add {f g : polynomial R} :
derivative (f + g) = derivative f + derivative g :=
by refine finsupp.sum_add_index _ _; intros;
simp only [add_mul, zero_mul, C_0, C_add, C_mul]
/-- The formal derivative of polynomials, as additive homomorphism. -/
def derivative_hom (R : Type*) [comm_semiring R] : polynomial R →+ polynomial R :=
{ to_fun := derivative,
map_zero' := derivative_zero,
map_add' := λ p q, derivative_add }
@[simp] lemma derivative_neg {R : Type*} [comm_ring R] (f : polynomial R) :
derivative (-f) = -derivative f :=
(derivative_hom R).map_neg f
@[simp] lemma derivative_sub {R : Type*} [comm_ring R] (f g : polynomial R) :
derivative (f - g) = derivative f - derivative g :=
(derivative_hom R).map_sub f g
instance : is_add_monoid_hom (derivative : polynomial R → polynomial R) :=
(derivative_hom R).is_add_monoid_hom
@[simp] lemma derivative_sum {s : finset ι} {f : ι → polynomial R} :
derivative (s.sum f) = s.sum (λb, derivative (f b)) :=
(derivative_hom R).map_sum f s
@[simp] lemma derivative_mul {f g : polynomial R} :
derivative (f * g) = derivative f * g + f * derivative g :=
calc derivative (f * g) = f.sum (λn a, g.sum (λm b, C ((a * b) * (n + m : ℕ)) * X^((n + m) - 1))) :
begin
transitivity, exact derivative_sum,
transitivity, { apply finset.sum_congr rfl, assume x hx, exact derivative_sum },
apply finset.sum_congr rfl, assume n hn, apply finset.sum_congr rfl, assume m hm,
transitivity,
{ apply congr_arg, exact single_eq_C_mul_X },
exact derivative_monomial _ _
end
... = f.sum (λn a, g.sum (λm b,
(C (a * n) * X^(n - 1)) * (C b * X^m) + (C a * X^n) * (C (b * m) * X^(m - 1)))) :
sum_congr rfl $ assume n hn, sum_congr rfl $ assume m hm,
by simp only [nat.cast_add, mul_add, add_mul, C_add, C_mul];
cases n; simp only [nat.succ_sub_succ, pow_zero];
cases m; simp only [nat.cast_zero, C_0, nat.succ_sub_succ, zero_mul, mul_zero,
nat.sub_zero, pow_zero, pow_add, one_mul, pow_succ, mul_comm, mul_left_comm]
... = derivative f * g + f * derivative g :
begin
conv { to_rhs, congr,
{ rw [← sum_C_mul_X_eq g] },
{ rw [← sum_C_mul_X_eq f] } },
unfold derivative finsupp.sum,
simp only [sum_add_distrib, finset.mul_sum, finset.sum_mul]
end
lemma derivative_eval (p : polynomial R) (x : R) :
p.derivative.eval x = p.sum (λ n a, (a * n)*x^(n-1)) :=
by simp [derivative, eval_sum, eval_pow]
@[simp] lemma derivative_smul (r : R) (p : polynomial R) : derivative (r • p) = r • derivative p :=
by { ext, simp only [coeff_derivative, mul_assoc, coeff_smul], }
/-- The formal derivative of polynomials, as linear homomorphism. -/
def derivative_lhom (R : Type*) [comm_ring R] : polynomial R →ₗ[R] polynomial R :=
{ to_fun := derivative,
add := λ p q, derivative_add,
smul := λ r p, derivative_smul r p }
/-- If `f` is a polynomial over a field, and `a : K` satisfies `f' a ≠ 0`,
then `f / (X - a)` is coprime with `X - a`.
Note that we do not assume `f a = 0`, because `f / (X - a) = (f - f a) / (X - a)`. -/
lemma is_coprime_of_is_root_of_eval_derivative_ne_zero {K : Type*} [field K]
(f : polynomial K) (a : K) (hf' : f.derivative.eval a ≠ 0) :
ideal.is_coprime (X - C a : polynomial K) (f /ₘ (X - C a)) :=
begin
refine or.resolve_left (dvd_or_coprime (X - C a) (f /ₘ (X - C a))
(irreducible_of_degree_eq_one (polynomial.degree_X_sub_C a))) _,
contrapose! hf' with h,
have key : (X - C a) * (f /ₘ (X - C a)) = f - (f %ₘ (X - C a)),
{ rw [eq_sub_iff_add_eq, ← eq_sub_iff_add_eq', mod_by_monic_eq_sub_mul_div],
exact monic_X_sub_C a },
replace key := congr_arg derivative key,
simp only [derivative_X, derivative_mul, one_mul, sub_zero, derivative_sub,
mod_by_monic_X_sub_C_eq_C_eval, derivative_C] at key,
have : (X - C a) ∣ derivative f := key ▸ (dvd_add h (dvd_mul_right _ _)),
rw [← dvd_iff_mod_by_monic_eq_zero (monic_X_sub_C _), mod_by_monic_X_sub_C_eq_C_eval] at this,
rw [← C_inj, this, C_0],
end
end derivative
section domain
variables [integral_domain R]
lemma mem_support_derivative [char_zero R] (p : polynomial R) (n : ℕ) :
n ∈ (derivative p).support ↔ n + 1 ∈ p.support :=
suffices (¬(coeff p (n + 1) = 0 ∨ ((n + 1:ℕ) : R) = 0)) ↔ coeff p (n + 1) ≠ 0,
by simpa only [coeff_derivative, apply_eq_coeff, mem_support_iff, ne.def, mul_eq_zero],
by rw [nat.cast_eq_zero]; simp only [nat.succ_ne_zero, or_false]
@[simp] lemma degree_derivative_eq [char_zero R] (p : polynomial R) (hp : 0 < nat_degree p) :
degree (derivative p) = (nat_degree p - 1 : ℕ) :=
le_antisymm
(le_trans (degree_sum_le _ _) $ sup_le $ assume n hn,
have n ≤ nat_degree p, begin
rw [← with_bot.coe_le_coe, ← degree_eq_nat_degree],
{ refine le_degree_of_ne_zero _, simpa only [mem_support_iff] using hn },
{ assume h, simpa only [h, support_zero] using hn }
end,
le_trans (degree_monomial_le _ _) $ with_bot.coe_le_coe.2 $ nat.sub_le_sub_right this _)
begin
refine le_sup _,
rw [mem_support_derivative, nat.sub_add_cancel, mem_support_iff],
{ show ¬ leading_coeff p = 0,
rw [leading_coeff_eq_zero],
assume h, rw [h, nat_degree_zero] at hp,
exact lt_irrefl 0 (lt_of_le_of_lt (zero_le _) hp), },
exact hp
end
end domain
section identities
/- @TODO: pow_add_expansion and pow_sub_pow_factor are not specific to polynomials.
These belong somewhere else. But not in group_power because they depend on tactic.ring
Maybe use data.nat.choose to prove it.
-/
def pow_add_expansion {R : Type*} [comm_semiring R] (x y : R) : ∀ (n : ℕ),
{k // (x + y)^n = x^n + n*x^(n-1)*y + k * y^2}
| 0 := ⟨0, by simp⟩
| 1 := ⟨0, by simp⟩
| (n+2) :=
begin
cases pow_add_expansion (n+1) with z hz,
existsi x*z + (n+1)*x^n+z*y,
calc (x + y) ^ (n + 2) = (x + y) * (x + y) ^ (n + 1) : by ring_exp
... = (x + y) * (x ^ (n + 1) + ↑(n + 1) * x ^ (n + 1 - 1) * y + z * y ^ 2) : by rw hz
... = x ^ (n + 2) + ↑(n + 2) * x ^ (n + 1) * y + (x*z + (n+1)*x^n+z*y) * y ^ 2 :
by { push_cast, ring_exp! }
end
variables [comm_ring R]
private def poly_binom_aux1 (x y : R) (e : ℕ) (a : R) :
{k : R // a * (x + y)^e = a * (x^e + e*x^(e-1)*y + k*y^2)} :=
begin
existsi (pow_add_expansion x y e).val,
congr,
apply (pow_add_expansion _ _ _).property
end
private lemma poly_binom_aux2 (f : polynomial R) (x y : R) :
f.eval (x + y) = f.sum (λ e a, a * (x^e + e*x^(e-1)*y + (poly_binom_aux1 x y e a).val*y^2)) :=
begin
unfold eval eval₂, congr, ext,
apply (poly_binom_aux1 x y _ _).property
end
private lemma poly_binom_aux3 (f : polynomial R) (x y : R) : f.eval (x + y) =
f.sum (λ e a, a * x^e) +
f.sum (λ e a, (a * e * x^(e-1)) * y) +
f.sum (λ e a, (a *(poly_binom_aux1 x y e a).val)*y^2) :=
by rw poly_binom_aux2; simp [left_distrib, finsupp.sum_add, mul_assoc]
def binom_expansion (f : polynomial R) (x y : R) :
{k : R // f.eval (x + y) = f.eval x + (f.derivative.eval x) * y + k * y^2} :=
begin
existsi f.sum (λ e a, a *((poly_binom_aux1 x y e a).val)),
rw poly_binom_aux3,
congr,
{ rw derivative_eval, symmetry,
apply finsupp.sum_mul },
{ symmetry, apply finsupp.sum_mul }
end
def pow_sub_pow_factor (x y : R) : Π (i : ℕ), {z : R // x^i - y^i = z * (x - y)}
| 0 := ⟨0, by simp⟩
| 1 := ⟨1, by simp⟩
| (k+2) :=
begin
cases @pow_sub_pow_factor (k+1) with z hz,
existsi z*x + y^(k+1),
calc x ^ (k + 2) - y ^ (k + 2)
= x * (x ^ (k + 1) - y ^ (k + 1)) + (x * y ^ (k + 1) - y ^ (k + 2)) : by ring_exp
... = x * (z * (x - y)) + (x * y ^ (k + 1) - y ^ (k + 2)) : by rw hz
... = (z * x + y ^ (k + 1)) * (x - y) : by ring_exp
end
def eval_sub_factor (f : polynomial R) (x y : R) :
{z : R // f.eval x - f.eval y = z * (x - y)} :=
begin
refine ⟨f.sum (λ i r, r * (pow_sub_pow_factor x y i).val), _⟩,
delta eval eval₂,
rw ← finsupp.sum_sub,
rw finsupp.sum_mul,
delta finsupp.sum,
congr, ext i r, dsimp,
rw [mul_assoc, ←(pow_sub_pow_factor x y _).property, mul_sub],
end
end identities
end polynomial
namespace is_integral_domain
variables {R : Type*} [comm_ring R]
/-- Lift evidence that `is_integral_domain R` to `is_integral_domain (polynomial R)`. -/
lemma polynomial (h : is_integral_domain R) : is_integral_domain (polynomial R) :=
@integral_domain.to_is_integral_domain _ (@polynomial.integral_domain _ (h.to_integral_domain _))
end is_integral_domain
|
bc80209bf61b3789e25edb3181562c9ae841024e | 9dc8cecdf3c4634764a18254e94d43da07142918 | /src/topology/homotopy/basic.lean | ed41f986392f3d6113cc889817901dff55088c6b | [
"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 | 20,418 | lean | /-
Copyright (c) 2021 Shing Tak Lam. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Shing Tak Lam
-/
import topology.algebra.order.proj_Icc
import topology.continuous_function.ordered
import topology.compact_open
import topology.unit_interval
/-!
# Homotopy between functions
In this file, we define a homotopy between two functions `f₀` and `f₁`. First we define
`continuous_map.homotopy` between the two functions, with no restrictions on the intermediate
maps. Then, as in the formalisation in HOL-Analysis, we define
`continuous_map.homotopy_with f₀ f₁ P`, for homotopies between `f₀` and `f₁`, where the
intermediate maps satisfy the predicate `P`. Finally, we define
`continuous_map.homotopy_rel f₀ f₁ S`, for homotopies between `f₀` and `f₁` which are fixed
on `S`.
## Definitions
* `continuous_map.homotopy f₀ f₁` is the type of homotopies between `f₀` and `f₁`.
* `continuous_map.homotopy_with f₀ f₁ P` is the type of homotopies between `f₀` and `f₁`, where
the intermediate maps satisfy the predicate `P`.
* `continuous_map.homotopy_rel f₀ f₁ S` is the type of homotopies between `f₀` and `f₁` which
are fixed on `S`.
For each of the above, we have
* `refl f`, which is the constant homotopy from `f` to `f`.
* `symm F`, which reverses the homotopy `F`. For example, if `F : continuous_map.homotopy f₀ f₁`,
then `F.symm : continuous_map.homotopy f₁ f₀`.
* `trans F G`, which concatenates the homotopies `F` and `G`. For example, if
`F : continuous_map.homotopy f₀ f₁` and `G : continuous_map.homotopy f₁ f₂`, then
`F.trans G : continuous_map.homotopy f₀ f₂`.
We also define the relations
* `continuous_map.homotopic f₀ f₁` is defined to be `nonempty (continuous_map.homotopy f₀ f₁)`
* `continuous_map.homotopic_with f₀ f₁ P` is defined to be
`nonempty (continuous_map.homotopy_with f₀ f₁ P)`
* `continuous_map.homotopic_rel f₀ f₁ P` is defined to be
`nonempty (continuous_map.homotopy_rel f₀ f₁ P)`
and for `continuous_map.homotopic` and `continuous_map.homotopic_rel`, we also define the
`setoid` and `quotient` in `C(X, Y)` by these relations.
## References
- [HOL-Analysis formalisation](https://isabelle.in.tum.de/library/HOL/HOL-Analysis/Homotopy.html)
-/
noncomputable theory
universes u v w
variables {F : Type*} {X : Type u} {Y : Type v} {Z : Type w}
variables [topological_space X] [topological_space Y] [topological_space Z]
open_locale unit_interval
namespace continuous_map
/-- `continuous_map.homotopy f₀ f₁` is the type of homotopies from `f₀` to `f₁`.
When possible, instead of parametrizing results over `(f : homotopy f₀ f₁)`,
you should parametrize over `{F : Type*} [homotopy_like F f₀ f₁] (f : F)`.
When you extend this structure, make sure to extend `continuous_map.homotopy_like`. -/
structure homotopy (f₀ f₁ : C(X, Y)) extends C(I × X, Y) :=
(map_zero_left' : ∀ x, to_fun (0, x) = f₀ x)
(map_one_left' : ∀ x, to_fun (1, x) = f₁ x)
/-- `continuous_map.homotopy_like F f₀ f₁` states that `F` is a type of homotopies between `f₀` and
`f₁`.
You should extend this class when you extend `continuous_map.homotopy`. -/
class homotopy_like (F : Type*) (f₀ f₁ : out_param $ C(X, Y))
extends continuous_map_class F (I × X) Y :=
(map_zero_left (f : F) : ∀ x, f (0, x) = f₀ x)
(map_one_left (f : F) : ∀ x, f (1, x) = f₁ x)
-- `f₀` and `f₁` are `out_param` so this is not dangerous
attribute [nolint dangerous_instance] homotopy_like.to_continuous_map_class
namespace homotopy
section
variables {f₀ f₁ : C(X, Y)}
instance : homotopy_like (homotopy f₀ f₁) f₀ f₁ :=
{ coe := λ f, f.to_fun,
coe_injective' := λ f g h, by { obtain ⟨⟨_, _⟩, _⟩ := f, obtain ⟨⟨_, _⟩, _⟩ := g, congr' },
map_continuous := λ f, f.continuous_to_fun,
map_zero_left := λ f, f.map_zero_left',
map_one_left := λ f, f.map_one_left' }
/-- Helper instance for when there's too many metavariables to apply `fun_like.has_coe_to_fun`
directly. -/
instance : has_coe_to_fun (homotopy f₀ f₁) (λ _, I × X → Y) := fun_like.has_coe_to_fun
@[ext]
lemma ext {F G : homotopy f₀ f₁} (h : ∀ x, F x = G x) : F = G := fun_like.ext _ _ h
/-- See Note [custom simps projection]. We need to specify this projection explicitly in this case,
because it is a composition of multiple projections. -/
def simps.apply (F : homotopy f₀ f₁) : I × X → Y := F
initialize_simps_projections homotopy (to_continuous_map_to_fun -> apply, -to_continuous_map)
/-- Deprecated. Use `map_continuous` instead. -/
protected lemma continuous (F : homotopy f₀ f₁) : continuous F := F.continuous_to_fun
@[simp]
lemma apply_zero (F : homotopy f₀ f₁) (x : X) : F (0, x) = f₀ x := F.map_zero_left' x
@[simp]
lemma apply_one (F : homotopy f₀ f₁) (x : X) : F (1, x) = f₁ x := F.map_one_left' x
@[simp]
lemma coe_to_continuous_map (F : homotopy f₀ f₁) : ⇑F.to_continuous_map = F := rfl
/--
Currying a homotopy to a continuous function fron `I` to `C(X, Y)`.
-/
def curry (F : homotopy f₀ f₁) : C(I, C(X, Y)) := F.to_continuous_map.curry
@[simp]
lemma curry_apply (F : homotopy f₀ f₁) (t : I) (x : X) : F.curry t x = F (t, x) := rfl
/--
Continuously extending a curried homotopy to a function from `ℝ` to `C(X, Y)`.
-/
def extend (F : homotopy f₀ f₁) : C(ℝ, C(X, Y)) := F.curry.Icc_extend zero_le_one
lemma extend_apply_of_le_zero (F : homotopy f₀ f₁) {t : ℝ} (ht : t ≤ 0) (x : X) :
F.extend t x = f₀ x :=
begin
rw [←F.apply_zero],
exact continuous_map.congr_fun (set.Icc_extend_of_le_left (zero_le_one' ℝ) F.curry ht) x,
end
lemma extend_apply_of_one_le (F : homotopy f₀ f₁) {t : ℝ} (ht : 1 ≤ t) (x : X) :
F.extend t x = f₁ x :=
begin
rw [←F.apply_one],
exact continuous_map.congr_fun (set.Icc_extend_of_right_le (zero_le_one' ℝ) F.curry ht) x,
end
@[simp]
lemma extend_apply_coe (F : homotopy f₀ f₁) (t : I) (x : X) : F.extend t x = F (t, x) :=
continuous_map.congr_fun (set.Icc_extend_coe (zero_le_one' ℝ) F.curry t) x
@[simp]
lemma extend_apply_of_mem_I (F : homotopy f₀ f₁) {t : ℝ} (ht : t ∈ I) (x : X) :
F.extend t x = F (⟨t, ht⟩, x) :=
continuous_map.congr_fun (set.Icc_extend_of_mem (zero_le_one' ℝ) F.curry ht) x
lemma congr_fun {F G : homotopy f₀ f₁} (h : F = G) (x : I × X) : F x = G x :=
continuous_map.congr_fun (congr_arg _ h) x
lemma congr_arg (F : homotopy f₀ f₁) {x y : I × X} (h : x = y) : F x = F y :=
F.to_continuous_map.congr_arg h
end
/--
Given a continuous function `f`, we can define a `homotopy f f` by `F (t, x) = f x`
-/
@[simps]
def refl (f : C(X, Y)) : homotopy f f :=
{ to_fun := λ x, f x.2,
map_zero_left' := λ _, rfl,
map_one_left' := λ _, rfl }
instance : inhabited (homotopy (continuous_map.id X) (continuous_map.id X)) := ⟨homotopy.refl _⟩
/--
Given a `homotopy f₀ f₁`, we can define a `homotopy f₁ f₀` by reversing the homotopy.
-/
@[simps]
def symm {f₀ f₁ : C(X, Y)} (F : homotopy f₀ f₁) : homotopy f₁ f₀ :=
{ to_fun := λ x, F (σ x.1, x.2),
map_zero_left' := by norm_num,
map_one_left' := by norm_num }
@[simp]
lemma symm_symm {f₀ f₁ : C(X, Y)} (F : homotopy f₀ f₁) : F.symm.symm = F :=
by { ext, simp }
/--
Given `homotopy f₀ f₁` and `homotopy f₁ f₂`, we can define a `homotopy f₀ f₂` by putting the first
homotopy on `[0, 1/2]` and the second on `[1/2, 1]`.
-/
def trans {f₀ f₁ f₂ : C(X, Y)} (F : homotopy f₀ f₁) (G : homotopy f₁ f₂) :
homotopy f₀ f₂ :=
{ to_fun := λ x, if (x.1 : ℝ) ≤ 1/2 then F.extend (2 * x.1) x.2 else G.extend (2 * x.1 - 1) x.2,
continuous_to_fun := begin
refine continuous_if_le (continuous_induced_dom.comp continuous_fst) continuous_const
(F.continuous.comp (by continuity)).continuous_on
(G.continuous.comp (by continuity)).continuous_on _,
rintros x hx,
norm_num [hx],
end,
map_zero_left' := λ x, by norm_num,
map_one_left' := λ x, by norm_num }
lemma trans_apply {f₀ f₁ f₂ : C(X, Y)} (F : homotopy f₀ f₁) (G : homotopy f₁ f₂)
(x : I × X) : (F.trans G) x =
if h : (x.1 : ℝ) ≤ 1/2 then
F (⟨2 * x.1, (unit_interval.mul_pos_mem_iff zero_lt_two).2 ⟨x.1.2.1, h⟩⟩, x.2)
else
G (⟨2 * x.1 - 1, unit_interval.two_mul_sub_one_mem_iff.2 ⟨(not_le.1 h).le, x.1.2.2⟩⟩, x.2) :=
show ite _ _ _ = _,
by split_ifs; { rw [extend, continuous_map.coe_Icc_extend, set.Icc_extend_of_mem], refl }
lemma symm_trans {f₀ f₁ f₂ : C(X, Y)} (F : homotopy f₀ f₁) (G : homotopy f₁ f₂) :
(F.trans G).symm = G.symm.trans F.symm :=
begin
ext x,
simp only [symm_apply, trans_apply],
split_ifs with h₁ h₂,
{ change (x.1 : ℝ) ≤ _ at h₂,
change (1 : ℝ) - x.1 ≤ _ at h₁,
have ht : (x.1 : ℝ) = 1/2,
{ linarith },
norm_num [ht] },
{ congr' 2,
apply subtype.ext,
simp only [unit_interval.coe_symm_eq, subtype.coe_mk],
linarith },
{ congr' 2,
apply subtype.ext,
simp only [unit_interval.coe_symm_eq, subtype.coe_mk],
linarith },
{ change ¬ (x.1 : ℝ) ≤ _ at h,
change ¬ (1 : ℝ) - x.1 ≤ _ at h₁,
exfalso, linarith }
end
/--
Casting a `homotopy f₀ f₁` to a `homotopy g₀ g₁` where `f₀ = g₀` and `f₁ = g₁`.
-/
@[simps]
def cast {f₀ f₁ g₀ g₁ : C(X, Y)} (F : homotopy f₀ f₁) (h₀ : f₀ = g₀) (h₁ : f₁ = g₁) :
homotopy g₀ g₁ :=
{ to_fun := F,
map_zero_left' := by simp [←h₀],
map_one_left' := by simp [←h₁] }
/--
If we have a `homotopy f₀ f₁` and a `homotopy g₀ g₁`, then we can compose them and get a
`homotopy (g₀.comp f₀) (g₁.comp f₁)`.
-/
@[simps]
def hcomp {f₀ f₁ : C(X, Y)} {g₀ g₁ : C(Y, Z)} (F : homotopy f₀ f₁) (G : homotopy g₀ g₁) :
homotopy (g₀.comp f₀) (g₁.comp f₁) :=
{ to_fun := λ x, G (x.1, F x),
map_zero_left' := by simp,
map_one_left' := by simp }
end homotopy
/--
Given continuous maps `f₀` and `f₁`, we say `f₀` and `f₁` are homotopic if there exists a
`homotopy f₀ f₁`.
-/
def homotopic (f₀ f₁ : C(X, Y)) : Prop :=
nonempty (homotopy f₀ f₁)
namespace homotopic
@[refl]
lemma refl (f : C(X, Y)) : homotopic f f := ⟨homotopy.refl f⟩
@[symm]
lemma symm ⦃f g : C(X, Y)⦄ (h : homotopic f g) : homotopic g f := h.map homotopy.symm
@[trans]
lemma trans ⦃f g h : C(X, Y)⦄ (h₀ : homotopic f g) (h₁ : homotopic g h) : homotopic f h :=
h₀.map2 homotopy.trans h₁
lemma hcomp {f₀ f₁ : C(X, Y)} {g₀ g₁ : C(Y, Z)} (h₀ : homotopic f₀ f₁) (h₁ : homotopic g₀ g₁) :
homotopic (g₀.comp f₀) (g₁.comp f₁) :=
h₀.map2 homotopy.hcomp h₁
lemma equivalence : equivalence (@homotopic X Y _ _) := ⟨refl, symm, trans⟩
end homotopic
/--
The type of homotopies between `f₀ f₁ : C(X, Y)`, where the intermediate maps satisfy the predicate
`P : C(X, Y) → Prop`
-/
structure homotopy_with (f₀ f₁ : C(X, Y)) (P : C(X, Y) → Prop) extends homotopy f₀ f₁ :=
(prop' : ∀ t, P ⟨λ x, to_fun (t, x),
continuous.comp continuous_to_fun (continuous_const.prod_mk continuous_id')⟩)
namespace homotopy_with
section
variables {f₀ f₁ : C(X, Y)} {P : C(X, Y) → Prop}
instance : has_coe_to_fun (homotopy_with f₀ f₁ P) (λ _, I × X → Y) := ⟨λ F, F.to_fun⟩
lemma coe_fn_injective : @function.injective (homotopy_with f₀ f₁ P) (I × X → Y) coe_fn :=
begin
rintros ⟨⟨⟨F, _⟩, _⟩, _⟩ ⟨⟨⟨G, _⟩, _⟩, _⟩ h,
congr' 3,
end
@[ext]
lemma ext {F G : homotopy_with f₀ f₁ P} (h : ∀ x, F x = G x) : F = G :=
coe_fn_injective $ funext h
/-- See Note [custom simps projection]. We need to specify this projection explicitly in this case,
because it is a composition of multiple projections. -/
def simps.apply (F : homotopy_with f₀ f₁ P) : I × X → Y := F
initialize_simps_projections homotopy_with
(to_homotopy_to_continuous_map_to_fun -> apply, -to_homotopy_to_continuous_map)
@[continuity]
protected lemma continuous (F : homotopy_with f₀ f₁ P) : continuous F := F.continuous_to_fun
@[simp]
lemma apply_zero (F : homotopy_with f₀ f₁ P) (x : X) : F (0, x) = f₀ x := F.map_zero_left' x
@[simp]
lemma apply_one (F : homotopy_with f₀ f₁ P) (x : X) : F (1, x) = f₁ x := F.map_one_left' x
@[simp]
lemma coe_to_continuous_map (F : homotopy_with f₀ f₁ P) : ⇑F.to_continuous_map = F := rfl
@[simp]
lemma coe_to_homotopy (F : homotopy_with f₀ f₁ P) : ⇑F.to_homotopy = F := rfl
lemma prop (F : homotopy_with f₀ f₁ P) (t : I) : P (F.to_homotopy.curry t) := F.prop' t
lemma extend_prop (F : homotopy_with f₀ f₁ P) (t : ℝ) : P (F.to_homotopy.extend t) :=
begin
by_cases ht₀ : 0 ≤ t,
{ by_cases ht₁ : t ≤ 1,
{ convert F.prop ⟨t, ht₀, ht₁⟩,
ext,
rw [F.to_homotopy.extend_apply_of_mem_I ⟨ht₀, ht₁⟩, F.to_homotopy.curry_apply] },
{ convert F.prop 1,
ext,
rw [F.to_homotopy.extend_apply_of_one_le (le_of_not_le ht₁), F.to_homotopy.curry_apply,
F.to_homotopy.apply_one] } },
{ convert F.prop 0,
ext,
rw [F.to_homotopy.extend_apply_of_le_zero (le_of_not_le ht₀), F.to_homotopy.curry_apply,
F.to_homotopy.apply_zero] }
end
end
variable {P : C(X, Y) → Prop}
/--
Given a continuous function `f`, and a proof `h : P f`, we can define a `homotopy_with f f P` by
`F (t, x) = f x`
-/
@[simps]
def refl (f : C(X, Y)) (hf : P f) : homotopy_with f f P :=
{ prop' := λ t, by { convert hf, cases f, refl },
..homotopy.refl f }
instance : inhabited (homotopy_with (continuous_map.id X) (continuous_map.id X) (λ f, true)) :=
⟨homotopy_with.refl _ trivial⟩
/--
Given a `homotopy_with f₀ f₁ P`, we can define a `homotopy_with f₁ f₀ P` by reversing the homotopy.
-/
@[simps]
def symm {f₀ f₁ : C(X, Y)} (F : homotopy_with f₀ f₁ P) : homotopy_with f₁ f₀ P :=
{ prop' := λ t, by simpa using F.prop (σ t),
..F.to_homotopy.symm }
@[simp]
lemma symm_symm {f₀ f₁ : C(X, Y)} (F : homotopy_with f₀ f₁ P) : F.symm.symm = F :=
ext $ homotopy.congr_fun $ homotopy.symm_symm _
/--
Given `homotopy_with f₀ f₁ P` and `homotopy_with f₁ f₂ P`, we can define a `homotopy_with f₀ f₂ P`
by putting the first homotopy on `[0, 1/2]` and the second on `[1/2, 1]`.
-/
def trans {f₀ f₁ f₂ : C(X, Y)} (F : homotopy_with f₀ f₁ P) (G : homotopy_with f₁ f₂ P) :
homotopy_with f₀ f₂ P :=
{ prop' := λ t, begin
simp only [homotopy.trans],
change P ⟨λ _, ite ((t : ℝ) ≤ _) _ _, _⟩,
split_ifs,
{ exact F.extend_prop _ },
{ exact G.extend_prop _ }
end,
..F.to_homotopy.trans G.to_homotopy }
lemma trans_apply {f₀ f₁ f₂ : C(X, Y)} (F : homotopy_with f₀ f₁ P) (G : homotopy_with f₁ f₂ P)
(x : I × X) : (F.trans G) x =
if h : (x.1 : ℝ) ≤ 1/2 then
F (⟨2 * x.1, (unit_interval.mul_pos_mem_iff zero_lt_two).2 ⟨x.1.2.1, h⟩⟩, x.2)
else
G (⟨2 * x.1 - 1, unit_interval.two_mul_sub_one_mem_iff.2 ⟨(not_le.1 h).le, x.1.2.2⟩⟩, x.2) :=
homotopy.trans_apply _ _ _
lemma symm_trans {f₀ f₁ f₂ : C(X, Y)} (F : homotopy_with f₀ f₁ P) (G : homotopy_with f₁ f₂ P) :
(F.trans G).symm = G.symm.trans F.symm :=
ext $ homotopy.congr_fun $ homotopy.symm_trans _ _
/--
Casting a `homotopy_with f₀ f₁ P` to a `homotopy_with g₀ g₁ P` where `f₀ = g₀` and `f₁ = g₁`.
-/
@[simps]
def cast {f₀ f₁ g₀ g₁ : C(X, Y)} (F : homotopy_with f₀ f₁ P) (h₀ : f₀ = g₀) (h₁ : f₁ = g₁) :
homotopy_with g₀ g₁ P :=
{ prop' := F.prop,
..F.to_homotopy.cast h₀ h₁ }
end homotopy_with
/--
Given continuous maps `f₀` and `f₁`, we say `f₀` and `f₁` are homotopic with respect to the
predicate `P` if there exists a `homotopy_with f₀ f₁ P`.
-/
def homotopic_with (f₀ f₁ : C(X, Y)) (P : C(X, Y) → Prop) : Prop :=
nonempty (homotopy_with f₀ f₁ P)
namespace homotopic_with
variable {P : C(X, Y) → Prop}
@[refl]
lemma refl (f : C(X, Y)) (hf : P f) : homotopic_with f f P :=
⟨homotopy_with.refl f hf⟩
@[symm]
lemma symm ⦃f g : C(X, Y)⦄ (h : homotopic_with f g P) : homotopic_with g f P := ⟨h.some.symm⟩
@[trans]
lemma trans ⦃f g h : C(X, Y)⦄ (h₀ : homotopic_with f g P) (h₁ : homotopic_with g h P) :
homotopic_with f h P :=
⟨h₀.some.trans h₁.some⟩
end homotopic_with
/--
A `homotopy_rel f₀ f₁ S` is a homotopy between `f₀` and `f₁` which is fixed on the points in `S`.
-/
abbreviation homotopy_rel (f₀ f₁ : C(X, Y)) (S : set X) :=
homotopy_with f₀ f₁ (λ f, ∀ x ∈ S, f x = f₀ x ∧ f x = f₁ x)
namespace homotopy_rel
section
variables {f₀ f₁ : C(X, Y)} {S : set X}
lemma eq_fst (F : homotopy_rel f₀ f₁ S) (t : I) {x : X} (hx : x ∈ S) :
F (t, x) = f₀ x := (F.prop t x hx).1
lemma eq_snd (F : homotopy_rel f₀ f₁ S) (t : I) {x : X} (hx : x ∈ S) :
F (t, x) = f₁ x := (F.prop t x hx).2
lemma fst_eq_snd (F : homotopy_rel f₀ f₁ S) {x : X} (hx : x ∈ S) :
f₀ x = f₁ x := F.eq_fst 0 hx ▸ F.eq_snd 0 hx
end
variables {f₀ f₁ f₂ : C(X, Y)} {S : set X}
/--
Given a map `f : C(X, Y)` and a set `S`, we can define a `homotopy_rel f f S` by setting
`F (t, x) = f x` for all `t`. This is defined using `homotopy_with.refl`, but with the proof
filled in.
-/
@[simps]
def refl (f : C(X, Y)) (S : set X) : homotopy_rel f f S :=
homotopy_with.refl f (λ x hx, ⟨rfl, rfl⟩)
/--
Given a `homotopy_rel f₀ f₁ S`, we can define a `homotopy_rel f₁ f₀ S` by reversing the homotopy.
-/
@[simps]
def symm (F : homotopy_rel f₀ f₁ S) : homotopy_rel f₁ f₀ S :=
{ prop' := λ t x hx, by simp [F.eq_snd _ hx, F.fst_eq_snd hx],
..homotopy_with.symm F }
@[simp]
lemma symm_symm (F : homotopy_rel f₀ f₁ S) : F.symm.symm = F :=
homotopy_with.symm_symm F
/--
Given `homotopy_rel f₀ f₁ S` and `homotopy_rel f₁ f₂ S`, we can define a `homotopy_rel f₀ f₂ S`
by putting the first homotopy on `[0, 1/2]` and the second on `[1/2, 1]`.
-/
def trans (F : homotopy_rel f₀ f₁ S) (G : homotopy_rel f₁ f₂ S) : homotopy_rel f₀ f₂ S :=
{ prop' := λ t, begin
intros x hx,
simp only [homotopy.trans],
change (⟨λ _, ite ((t : ℝ) ≤ _) _ _, _⟩ : C(X, Y)) _ = _ ∧ _ = _,
split_ifs,
{ simp [(homotopy_with.extend_prop F (2 * t) x hx).1, F.fst_eq_snd hx, G.fst_eq_snd hx] },
{ simp [(homotopy_with.extend_prop G (2 * t - 1) x hx).1, F.fst_eq_snd hx, G.fst_eq_snd hx] },
end,
..homotopy.trans F.to_homotopy G.to_homotopy }
lemma trans_apply (F : homotopy_rel f₀ f₁ S) (G : homotopy_rel f₁ f₂ S)
(x : I × X) : (F.trans G) x =
if h : (x.1 : ℝ) ≤ 1/2 then
F (⟨2 * x.1, (unit_interval.mul_pos_mem_iff zero_lt_two).2 ⟨x.1.2.1, h⟩⟩, x.2)
else
G (⟨2 * x.1 - 1, unit_interval.two_mul_sub_one_mem_iff.2 ⟨(not_le.1 h).le, x.1.2.2⟩⟩, x.2) :=
homotopy.trans_apply _ _ _
lemma symm_trans (F : homotopy_rel f₀ f₁ S) (G : homotopy_rel f₁ f₂ S) :
(F.trans G).symm = G.symm.trans F.symm :=
homotopy_with.ext $ homotopy.congr_fun $ homotopy.symm_trans _ _
/--
Casting a `homotopy_rel f₀ f₁ S` to a `homotopy_rel g₀ g₁ S` where `f₀ = g₀` and `f₁ = g₁`.
-/
@[simps]
def cast {f₀ f₁ g₀ g₁ : C(X, Y)} (F : homotopy_rel f₀ f₁ S) (h₀ : f₀ = g₀) (h₁ : f₁ = g₁) :
homotopy_rel g₀ g₁ S :=
{ prop' := λ t x hx, by { simpa [←h₀, ←h₁] using F.prop t x hx },
..homotopy.cast F.to_homotopy h₀ h₁ }
end homotopy_rel
/--
Given continuous maps `f₀` and `f₁`, we say `f₀` and `f₁` are homotopic relative to a set `S` if
there exists a `homotopy_rel f₀ f₁ S`.
-/
def homotopic_rel (f₀ f₁ : C(X, Y)) (S : set X) : Prop :=
nonempty (homotopy_rel f₀ f₁ S)
namespace homotopic_rel
variable {S : set X}
@[refl]
lemma refl (f : C(X, Y)) : homotopic_rel f f S := ⟨homotopy_rel.refl f S⟩
@[symm]
lemma symm ⦃f g : C(X, Y)⦄ (h : homotopic_rel f g S) : homotopic_rel g f S :=
h.map homotopy_rel.symm
@[trans]
lemma trans ⦃f g h : C(X, Y)⦄ (h₀ : homotopic_rel f g S) (h₁ : homotopic_rel g h S) :
homotopic_rel f h S :=
h₀.map2 homotopy_rel.trans h₁
lemma equivalence : equivalence (λ f g : C(X, Y), homotopic_rel f g S) :=
⟨refl, symm, trans⟩
end homotopic_rel
end continuous_map
|
247fc3ad0449be0eb6de48e13af2cb7fc4c43277 | 69d4931b605e11ca61881fc4f66db50a0a875e39 | /src/topology/locally_constant/algebra.lean | 02e0cdde737bce750ac21f861e1b220da1fd1b8a | [
"Apache-2.0"
] | permissive | abentkamp/mathlib | d9a75d291ec09f4637b0f30cc3880ffb07549ee5 | 5360e476391508e092b5a1e5210bd0ed22dc0755 | refs/heads/master | 1,682,382,954,948 | 1,622,106,077,000 | 1,622,106,077,000 | 149,285,665 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 4,361 | 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 topology.locally_constant.basic
/-!
# Algebraic structure on locally constant functions
This file puts algebraic structure (`add_group`, etc)
on the type of locally constant functions.
-/
namespace locally_constant
variables {X Y : Type*} [topological_space X]
@[to_additive] instance [has_one Y] : has_one (locally_constant X Y) :=
{ one := const X 1 }
@[simp, to_additive] lemma one_apply [has_one Y] (x : X) : (1 : locally_constant X Y) x = 1 := rfl
@[to_additive] instance [has_inv Y] : has_inv (locally_constant X Y) :=
{ inv := λ f, ⟨f⁻¹ , f.is_locally_constant.inv⟩ }
@[simp, to_additive] lemma inv_apply [has_inv Y] (f : locally_constant X Y) (x : X) :
f⁻¹ x = (f x)⁻¹ := rfl
@[to_additive] instance [has_mul Y] : has_mul (locally_constant X Y) :=
{ mul := λ f g, ⟨f * g, f.is_locally_constant.mul g.is_locally_constant⟩ }
@[simp, to_additive] lemma mul_apply [has_mul Y] (f g : locally_constant X Y) (x : X) :
(f * g) x = f x * g x := rfl
@[to_additive] instance [mul_one_class Y] : mul_one_class (locally_constant X Y) :=
{ one_mul := by { intros, ext, simp only [mul_apply, one_apply, one_mul] },
mul_one := by { intros, ext, simp only [mul_apply, one_apply, mul_one] },
.. locally_constant.has_one,
.. locally_constant.has_mul }
instance [mul_zero_class Y] : mul_zero_class (locally_constant X Y) :=
{ zero_mul := by { intros, ext, simp only [mul_apply, zero_apply, zero_mul] },
mul_zero := by { intros, ext, simp only [mul_apply, zero_apply, mul_zero] },
.. locally_constant.has_zero,
.. locally_constant.has_mul }
instance [mul_zero_one_class Y] : mul_zero_one_class (locally_constant X Y) :=
{ .. locally_constant.mul_zero_class, .. locally_constant.mul_one_class }
@[to_additive] instance [has_div Y] : has_div (locally_constant X Y) :=
{ div := λ f g, ⟨f / g, f.is_locally_constant.div g.is_locally_constant⟩ }
@[to_additive] lemma div_apply [has_div Y] (f g : locally_constant X Y) (x : X) :
(f / g) x = f x / g x := rfl
@[to_additive] instance [semigroup Y] : semigroup (locally_constant X Y) :=
{ mul_assoc := by { intros, ext, simp only [mul_apply, mul_assoc] },
.. locally_constant.has_mul }
instance [semigroup_with_zero Y] : semigroup_with_zero (locally_constant X Y) :=
{ .. locally_constant.mul_zero_class,
.. locally_constant.semigroup }
@[to_additive] instance [comm_semigroup Y] : comm_semigroup (locally_constant X Y) :=
{ mul_comm := by { intros, ext, simp only [mul_apply, mul_comm] },
.. locally_constant.semigroup }
@[to_additive] instance [monoid Y] : monoid (locally_constant X Y) :=
{ mul := (*),
.. locally_constant.semigroup, .. locally_constant.mul_one_class }
@[to_additive] instance [comm_monoid Y] : comm_monoid (locally_constant X Y) :=
{ .. locally_constant.comm_semigroup, .. locally_constant.monoid }
@[to_additive] instance [group Y] : group (locally_constant X Y) :=
{ mul_left_inv := by { intros, ext, simp only [mul_apply, inv_apply, one_apply, mul_left_inv] },
div_eq_mul_inv := by { intros, ext, simp only [mul_apply, inv_apply, div_apply, div_eq_mul_inv] },
.. locally_constant.monoid, .. locally_constant.has_inv, .. locally_constant.has_div }
@[to_additive] instance [comm_group Y] : comm_group (locally_constant X Y) :=
{ .. locally_constant.comm_monoid, .. locally_constant.group }
instance [distrib Y] : distrib (locally_constant X Y) :=
{ left_distrib := by { intros, ext, simp only [mul_apply, add_apply, mul_add] },
right_distrib := by { intros, ext, simp only [mul_apply, add_apply, add_mul] },
.. locally_constant.has_add, .. locally_constant.has_mul }
instance [semiring Y] : semiring (locally_constant X Y) :=
{ .. locally_constant.add_comm_monoid, .. locally_constant.monoid,
.. locally_constant.distrib, .. locally_constant.mul_zero_class }
instance [comm_semiring Y] : comm_semiring (locally_constant X Y) :=
{ .. locally_constant.semiring, .. locally_constant.comm_monoid }
instance [ring Y] : ring (locally_constant X Y) :=
{ .. locally_constant.semiring, .. locally_constant.add_comm_group }
instance [comm_ring Y] : comm_ring (locally_constant X Y) :=
{ .. locally_constant.comm_semiring, .. locally_constant.ring }
end locally_constant
|
a910f569629f2c5f0c60bb60291994c386886cd0 | 9dc8cecdf3c4634764a18254e94d43da07142918 | /src/category_theory/limits/shapes/pullbacks.lean | dfd1089f8fbf15d149af9ad3e7782f4b3271a9fe | [
"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 | 92,095 | lean | /-
Copyright (c) 2018 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison, Markus Himmel, Bhavik Mehta, Andrew Yang
-/
import category_theory.limits.shapes.wide_pullbacks
import category_theory.limits.shapes.binary_products
/-!
# Pullbacks
We define a category `walking_cospan` (resp. `walking_span`), which is the index category
for the given data for a pullback (resp. pushout) diagram. Convenience methods `cospan f g`
and `span f g` construct functors from the walking (co)span, hitting the given morphisms.
We define `pullback f g` and `pushout f g` as limits and colimits of such functors.
## References
* [Stacks: Fibre products](https://stacks.math.columbia.edu/tag/001U)
* [Stacks: Pushouts](https://stacks.math.columbia.edu/tag/0025)
-/
noncomputable theory
open category_theory
namespace category_theory.limits
universes w v₁ v₂ v u u₂
local attribute [tidy] tactic.case_bash
/--
The type of objects for the diagram indexing a pullback, defined as a special case of
`wide_pullback_shape`.
-/
abbreviation walking_cospan : Type := wide_pullback_shape walking_pair
/-- The left point of the walking cospan. -/
@[pattern] abbreviation walking_cospan.left : walking_cospan := some walking_pair.left
/-- The right point of the walking cospan. -/
@[pattern] abbreviation walking_cospan.right : walking_cospan := some walking_pair.right
/-- The central point of the walking cospan. -/
@[pattern] abbreviation walking_cospan.one : walking_cospan := none
/--
The type of objects for the diagram indexing a pushout, defined as a special case of
`wide_pushout_shape`.
-/
abbreviation walking_span : Type := wide_pushout_shape walking_pair
/-- The left point of the walking span. -/
@[pattern] abbreviation walking_span.left : walking_span := some walking_pair.left
/-- The right point of the walking span. -/
@[pattern] abbreviation walking_span.right : walking_span := some walking_pair.right
/-- The central point of the walking span. -/
@[pattern] abbreviation walking_span.zero : walking_span := none
namespace walking_cospan
/-- The type of arrows for the diagram indexing a pullback. -/
abbreviation hom : walking_cospan → walking_cospan → Type := wide_pullback_shape.hom
/-- The left arrow of the walking cospan. -/
@[pattern] abbreviation hom.inl : left ⟶ one := wide_pullback_shape.hom.term _
/-- The right arrow of the walking cospan. -/
@[pattern] abbreviation hom.inr : right ⟶ one := wide_pullback_shape.hom.term _
/-- The identity arrows of the walking cospan. -/
@[pattern] abbreviation hom.id (X : walking_cospan) : X ⟶ X := wide_pullback_shape.hom.id X
instance (X Y : walking_cospan) : subsingleton (X ⟶ Y) := by tidy
end walking_cospan
namespace walking_span
/-- The type of arrows for the diagram indexing a pushout. -/
abbreviation hom : walking_span → walking_span → Type := wide_pushout_shape.hom
/-- The left arrow of the walking span. -/
@[pattern] abbreviation hom.fst : zero ⟶ left := wide_pushout_shape.hom.init _
/-- The right arrow of the walking span. -/
@[pattern] abbreviation hom.snd : zero ⟶ right := wide_pushout_shape.hom.init _
/-- The identity arrows of the walking span. -/
@[pattern] abbreviation hom.id (X : walking_span) : X ⟶ X := wide_pushout_shape.hom.id X
instance (X Y : walking_span) : subsingleton (X ⟶ Y) := by tidy
end walking_span
open walking_span.hom walking_cospan.hom wide_pullback_shape.hom wide_pushout_shape.hom
variables {C : Type u} [category.{v} C]
/-- To construct an isomorphism of cones over the walking cospan,
it suffices to construct an isomorphism
of the cone points and check it commutes with the legs to `left` and `right`. -/
def walking_cospan.ext {F : walking_cospan ⥤ C} {s t : cone F} (i : s.X ≅ t.X)
(w₁ : s.π.app walking_cospan.left = i.hom ≫ t.π.app walking_cospan.left)
(w₂ : s.π.app walking_cospan.right = i.hom ≫ t.π.app walking_cospan.right) :
s ≅ t :=
begin
apply cones.ext i,
rintro (⟨⟩|⟨⟨⟩⟩),
{ have h₁ := s.π.naturality walking_cospan.hom.inl,
dsimp at h₁, simp only [category.id_comp] at h₁,
have h₂ := t.π.naturality walking_cospan.hom.inl,
dsimp at h₂, simp only [category.id_comp] at h₂,
simp_rw [h₂, ←category.assoc, ←w₁, ←h₁], },
{ exact w₁, },
{ exact w₂, },
end
/-- To construct an isomorphism of cocones over the walking span,
it suffices to construct an isomorphism
of the cocone points and check it commutes with the legs from `left` and `right`. -/
def walking_span.ext {F : walking_span ⥤ C} {s t : cocone F} (i : s.X ≅ t.X)
(w₁ : s.ι.app walking_cospan.left ≫ i.hom = t.ι.app walking_cospan.left)
(w₂ : s.ι.app walking_cospan.right ≫ i.hom = t.ι.app walking_cospan.right) :
s ≅ t :=
begin
apply cocones.ext i,
rintro (⟨⟩|⟨⟨⟩⟩),
{ have h₁ := s.ι.naturality walking_span.hom.fst,
dsimp at h₁, simp only [category.comp_id] at h₁,
have h₂ := t.ι.naturality walking_span.hom.fst,
dsimp at h₂, simp only [category.comp_id] at h₂,
simp_rw [←h₁, category.assoc, w₁, h₂], },
{ exact w₁, },
{ exact w₂, },
end
/-- `cospan f g` is the functor from the walking cospan hitting `f` and `g`. -/
def cospan {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) : walking_cospan ⥤ C :=
wide_pullback_shape.wide_cospan Z
(λ j, walking_pair.cases_on j X Y) (λ j, walking_pair.cases_on j f g)
/-- `span f g` is the functor from the walking span hitting `f` and `g`. -/
def span {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) : walking_span ⥤ C :=
wide_pushout_shape.wide_span X
(λ j, walking_pair.cases_on j Y Z) (λ j, walking_pair.cases_on j f g)
@[simp] lemma cospan_left {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) :
(cospan f g).obj walking_cospan.left = X := rfl
@[simp] lemma span_left {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) :
(span f g).obj walking_span.left = Y := rfl
@[simp] lemma cospan_right {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) :
(cospan f g).obj walking_cospan.right = Y := rfl
@[simp] lemma span_right {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) :
(span f g).obj walking_span.right = Z := rfl
@[simp] lemma cospan_one {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) :
(cospan f g).obj walking_cospan.one = Z := rfl
@[simp] lemma span_zero {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) :
(span f g).obj walking_span.zero = X := rfl
@[simp] lemma cospan_map_inl {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) :
(cospan f g).map walking_cospan.hom.inl = f := rfl
@[simp] lemma span_map_fst {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) :
(span f g).map walking_span.hom.fst = f := rfl
@[simp] lemma cospan_map_inr {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) :
(cospan f g).map walking_cospan.hom.inr = g := rfl
@[simp] lemma span_map_snd {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) :
(span f g).map walking_span.hom.snd = g := rfl
lemma cospan_map_id {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) (w : walking_cospan) :
(cospan f g).map (walking_cospan.hom.id w) = 𝟙 _ := rfl
lemma span_map_id {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) (w : walking_span) :
(span f g).map (walking_span.hom.id w) = 𝟙 _ := rfl
/-- Every diagram indexing an pullback is naturally isomorphic (actually, equal) to a `cospan` -/
@[simps {rhs_md := semireducible}]
def diagram_iso_cospan (F : walking_cospan ⥤ C) :
F ≅ cospan (F.map inl) (F.map inr) :=
nat_iso.of_components (λ j, eq_to_iso (by tidy)) (by tidy)
/-- Every diagram indexing a pushout is naturally isomorphic (actually, equal) to a `span` -/
@[simps {rhs_md := semireducible}]
def diagram_iso_span (F : walking_span ⥤ C) :
F ≅ span (F.map fst) (F.map snd) :=
nat_iso.of_components (λ j, eq_to_iso (by tidy)) (by tidy)
variables {D : Type u₂} [category.{v₂} D]
/-- A functor applied to a cospan is a cospan. -/
def cospan_comp_iso (F : C ⥤ D) {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) :
cospan f g ⋙ F ≅ cospan (F.map f) (F.map g) :=
nat_iso.of_components (by rintros (⟨⟩|⟨⟨⟩⟩); exact iso.refl _)
(by rintros (⟨⟩|⟨⟨⟩⟩) (⟨⟩|⟨⟨⟩⟩) ⟨⟩; repeat { dsimp, simp, })
section
variables (F : C ⥤ D) {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z)
@[simp] lemma cospan_comp_iso_app_left :
(cospan_comp_iso F f g).app walking_cospan.left = iso.refl _ :=
rfl
@[simp] lemma cospan_comp_iso_app_right :
(cospan_comp_iso F f g).app walking_cospan.right = iso.refl _ :=
rfl
@[simp] lemma cospan_comp_iso_app_one :
(cospan_comp_iso F f g).app walking_cospan.one = iso.refl _ :=
rfl
@[simp] lemma cospan_comp_iso_hom_app_left :
(cospan_comp_iso F f g).hom.app walking_cospan.left = 𝟙 _ :=
rfl
@[simp] lemma cospan_comp_iso_hom_app_right :
(cospan_comp_iso F f g).hom.app walking_cospan.right = 𝟙 _ :=
rfl
@[simp] lemma cospan_comp_iso_hom_app_one :
(cospan_comp_iso F f g).hom.app walking_cospan.one = 𝟙 _ :=
rfl
@[simp] lemma cospan_comp_iso_inv_app_left :
(cospan_comp_iso F f g).inv.app walking_cospan.left = 𝟙 _ :=
rfl
@[simp] lemma cospan_comp_iso_inv_app_right :
(cospan_comp_iso F f g).inv.app walking_cospan.right = 𝟙 _ :=
rfl
@[simp] lemma cospan_comp_iso_inv_app_one :
(cospan_comp_iso F f g).inv.app walking_cospan.one = 𝟙 _ :=
rfl
end
/-- A functor applied to a span is a span. -/
def span_comp_iso (F : C ⥤ D) {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) :
span f g ⋙ F ≅ span (F.map f) (F.map g) :=
nat_iso.of_components (by rintros (⟨⟩|⟨⟨⟩⟩); exact iso.refl _)
(by rintros (⟨⟩|⟨⟨⟩⟩) (⟨⟩|⟨⟨⟩⟩) ⟨⟩; repeat { dsimp, simp, })
section
variables (F : C ⥤ D) {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z)
@[simp] lemma span_comp_iso_app_left : (span_comp_iso F f g).app walking_span.left = iso.refl _ :=
rfl
@[simp] lemma span_comp_iso_app_right : (span_comp_iso F f g).app walking_span.right = iso.refl _ :=
rfl
@[simp] lemma span_comp_iso_app_zero : (span_comp_iso F f g).app walking_span.zero = iso.refl _ :=
rfl
@[simp] lemma span_comp_iso_hom_app_left : (span_comp_iso F f g).hom.app walking_span.left = 𝟙 _ :=
rfl
@[simp] lemma span_comp_iso_hom_app_right :
(span_comp_iso F f g).hom.app walking_span.right = 𝟙 _ :=
rfl
@[simp] lemma span_comp_iso_hom_app_zero : (span_comp_iso F f g).hom.app walking_span.zero = 𝟙 _ :=
rfl
@[simp] lemma span_comp_iso_inv_app_left : (span_comp_iso F f g).inv.app walking_span.left = 𝟙 _ :=
rfl
@[simp] lemma span_comp_iso_inv_app_right :
(span_comp_iso F f g).inv.app walking_span.right = 𝟙 _ :=
rfl
@[simp] lemma span_comp_iso_inv_app_zero : (span_comp_iso F f g).inv.app walking_span.zero = 𝟙 _ :=
rfl
end
section
variables {X Y Z X' Y' Z' : C} (iX : X ≅ X') (iY : Y ≅ Y') (iZ : Z ≅ Z')
section
variables {f : X ⟶ Z} {g : Y ⟶ Z} {f' : X' ⟶ Z'} {g' : Y' ⟶ Z'}
/-- Construct an isomorphism of cospans from components. -/
def cospan_ext (wf : iX.hom ≫ f' = f ≫ iZ.hom) (wg : iY.hom ≫ g' = g ≫ iZ.hom) :
cospan f g ≅ cospan f' g' :=
nat_iso.of_components (by { rintros (⟨⟩|⟨⟨⟩⟩), exacts [iZ, iX, iY], })
(by rintros (⟨⟩|⟨⟨⟩⟩) (⟨⟩|⟨⟨⟩⟩) ⟨⟩; repeat { dsimp, simp [wf, wg], })
variables (wf : iX.hom ≫ f' = f ≫ iZ.hom) (wg : iY.hom ≫ g' = g ≫ iZ.hom)
@[simp] lemma cospan_ext_app_left : (cospan_ext iX iY iZ wf wg).app walking_cospan.left = iX :=
by { dsimp [cospan_ext], simp, }
@[simp] lemma cospan_ext_app_right : (cospan_ext iX iY iZ wf wg).app walking_cospan.right = iY :=
by { dsimp [cospan_ext], simp, }
@[simp] lemma cospan_ext_app_one : (cospan_ext iX iY iZ wf wg).app walking_cospan.one = iZ :=
by { dsimp [cospan_ext], simp, }
@[simp] lemma cospan_ext_hom_app_left :
(cospan_ext iX iY iZ wf wg).hom.app walking_cospan.left = iX.hom :=
by { dsimp [cospan_ext], simp, }
@[simp] lemma cospan_ext_hom_app_right :
(cospan_ext iX iY iZ wf wg).hom.app walking_cospan.right = iY.hom :=
by { dsimp [cospan_ext], simp, }
@[simp] lemma cospan_ext_hom_app_one :
(cospan_ext iX iY iZ wf wg).hom.app walking_cospan.one = iZ.hom :=
by { dsimp [cospan_ext], simp, }
@[simp] lemma cospan_ext_inv_app_left :
(cospan_ext iX iY iZ wf wg).inv.app walking_cospan.left = iX.inv :=
by { dsimp [cospan_ext], simp, }
@[simp] lemma cospan_ext_inv_app_right :
(cospan_ext iX iY iZ wf wg).inv.app walking_cospan.right = iY.inv :=
by { dsimp [cospan_ext], simp, }
@[simp] lemma cospan_ext_inv_app_one :
(cospan_ext iX iY iZ wf wg).inv.app walking_cospan.one = iZ.inv :=
by { dsimp [cospan_ext], simp, }
end
section
variables {f : X ⟶ Y} {g : X ⟶ Z} {f' : X' ⟶ Y'} {g' : X' ⟶ Z'}
/-- Construct an isomorphism of spans from components. -/
def span_ext (wf : iX.hom ≫ f' = f ≫ iY.hom) (wg : iX.hom ≫ g' = g ≫ iZ.hom) :
span f g ≅ span f' g' :=
nat_iso.of_components (by { rintros (⟨⟩|⟨⟨⟩⟩), exacts [iX, iY, iZ], })
(by rintros (⟨⟩|⟨⟨⟩⟩) (⟨⟩|⟨⟨⟩⟩) ⟨⟩; repeat { dsimp, simp [wf, wg], })
variables (wf : iX.hom ≫ f' = f ≫ iY.hom) (wg : iX.hom ≫ g' = g ≫ iZ.hom)
@[simp] lemma span_ext_app_left : (span_ext iX iY iZ wf wg).app walking_span.left = iY :=
by { dsimp [span_ext], simp, }
@[simp] lemma span_ext_app_right : (span_ext iX iY iZ wf wg).app walking_span.right = iZ :=
by { dsimp [span_ext], simp, }
@[simp] lemma span_ext_app_one : (span_ext iX iY iZ wf wg).app walking_span.zero = iX :=
by { dsimp [span_ext], simp, }
@[simp] lemma span_ext_hom_app_left :
(span_ext iX iY iZ wf wg).hom.app walking_span.left = iY.hom :=
by { dsimp [span_ext], simp, }
@[simp] lemma span_ext_hom_app_right :
(span_ext iX iY iZ wf wg).hom.app walking_span.right = iZ.hom :=
by { dsimp [span_ext], simp, }
@[simp] lemma span_ext_hom_app_zero :
(span_ext iX iY iZ wf wg).hom.app walking_span.zero = iX.hom :=
by { dsimp [span_ext], simp, }
@[simp] lemma span_ext_inv_app_left :
(span_ext iX iY iZ wf wg).inv.app walking_span.left = iY.inv :=
by { dsimp [span_ext], simp, }
@[simp] lemma span_ext_inv_app_right :
(span_ext iX iY iZ wf wg).inv.app walking_span.right = iZ.inv :=
by { dsimp [span_ext], simp, }
@[simp] lemma span_ext_inv_app_zero :
(span_ext iX iY iZ wf wg).inv.app walking_span.zero = iX.inv :=
by { dsimp [span_ext], simp, }
end
end
variables {W X Y Z : C}
/-- A pullback cone is just a cone on the cospan formed by two morphisms `f : X ⟶ Z` and
`g : Y ⟶ Z`.-/
abbreviation pullback_cone (f : X ⟶ Z) (g : Y ⟶ Z) := cone (cospan f g)
namespace pullback_cone
variables {f : X ⟶ Z} {g : Y ⟶ Z}
/-- The first projection of a pullback cone. -/
abbreviation fst (t : pullback_cone f g) : t.X ⟶ X := t.π.app walking_cospan.left
/-- The second projection of a pullback cone. -/
abbreviation snd (t : pullback_cone f g) : t.X ⟶ Y := t.π.app walking_cospan.right
@[simp] lemma π_app_left (c : pullback_cone f g) : c.π.app walking_cospan.left = c.fst := rfl
@[simp] lemma π_app_right (c : pullback_cone f g) : c.π.app walking_cospan.right = c.snd := rfl
@[simp] lemma condition_one (t : pullback_cone f g) : t.π.app walking_cospan.one = t.fst ≫ f :=
begin
have w := t.π.naturality walking_cospan.hom.inl,
dsimp at w, simpa using w,
end
/-- This is a slightly more convenient method to verify that a pullback cone is a limit cone. It
only asks for a proof of facts that carry any mathematical content -/
def is_limit_aux (t : pullback_cone f g) (lift : Π (s : pullback_cone f g), s.X ⟶ t.X)
(fac_left : ∀ (s : pullback_cone f g), lift s ≫ t.fst = s.fst)
(fac_right : ∀ (s : pullback_cone f g), lift s ≫ t.snd = s.snd)
(uniq : ∀ (s : pullback_cone f g) (m : s.X ⟶ t.X)
(w : ∀ j : walking_cospan, m ≫ t.π.app j = s.π.app j), m = lift s) :
is_limit t :=
{ lift := lift,
fac' := λ s j, option.cases_on j
(by { rw [← s.w inl, ← t.w inl, ←category.assoc], congr, exact fac_left s, } )
(λ j', walking_pair.cases_on j' (fac_left s) (fac_right s)),
uniq' := uniq }
/-- This is another convenient method to verify that a pullback cone is a limit cone. It
only asks for a proof of facts that carry any mathematical content, and allows access to the
same `s` for all parts. -/
def is_limit_aux' (t : pullback_cone f g)
(create : Π (s : pullback_cone f g),
{l // l ≫ t.fst = s.fst ∧ l ≫ t.snd = s.snd ∧
∀ {m}, m ≫ t.fst = s.fst → m ≫ t.snd = s.snd → m = l}) :
limits.is_limit t :=
pullback_cone.is_limit_aux t
(λ s, (create s).1)
(λ s, (create s).2.1)
(λ s, (create s).2.2.1)
(λ s m w, (create s).2.2.2 (w walking_cospan.left) (w walking_cospan.right))
/-- A pullback cone on `f` and `g` is determined by morphisms `fst : W ⟶ X` and `snd : W ⟶ Y`
such that `fst ≫ f = snd ≫ g`. -/
@[simps]
def mk {W : C} (fst : W ⟶ X) (snd : W ⟶ Y) (eq : fst ≫ f = snd ≫ g) : pullback_cone f g :=
{ X := W,
π := { app := λ j, option.cases_on j (fst ≫ f) (λ j', walking_pair.cases_on j' fst snd) } }
@[simp] lemma mk_π_app_left {W : C} (fst : W ⟶ X) (snd : W ⟶ Y) (eq : fst ≫ f = snd ≫ g) :
(mk fst snd eq).π.app walking_cospan.left = fst := rfl
@[simp] lemma mk_π_app_right {W : C} (fst : W ⟶ X) (snd : W ⟶ Y) (eq : fst ≫ f = snd ≫ g) :
(mk fst snd eq).π.app walking_cospan.right = snd := rfl
@[simp] lemma mk_π_app_one {W : C} (fst : W ⟶ X) (snd : W ⟶ Y) (eq : fst ≫ f = snd ≫ g) :
(mk fst snd eq).π.app walking_cospan.one = fst ≫ f := rfl
@[simp] lemma mk_fst {W : C} (fst : W ⟶ X) (snd : W ⟶ Y) (eq : fst ≫ f = snd ≫ g) :
(mk fst snd eq).fst = fst := rfl
@[simp] lemma mk_snd {W : C} (fst : W ⟶ X) (snd : W ⟶ Y) (eq : fst ≫ f = snd ≫ g) :
(mk fst snd eq).snd = snd := rfl
@[reassoc] lemma condition (t : pullback_cone f g) : fst t ≫ f = snd t ≫ g :=
(t.w inl).trans (t.w inr).symm
/-- To check whether a morphism is equalized by the maps of a pullback cone, it suffices to check
it for `fst t` and `snd t` -/
lemma equalizer_ext (t : pullback_cone f g) {W : C} {k l : W ⟶ t.X}
(h₀ : k ≫ fst t = l ≫ fst t) (h₁ : k ≫ snd t = l ≫ snd t) :
∀ (j : walking_cospan), k ≫ t.π.app j = l ≫ t.π.app j
| (some walking_pair.left) := h₀
| (some walking_pair.right) := h₁
| none := by rw [← t.w inl, reassoc_of h₀]
lemma is_limit.hom_ext {t : pullback_cone f g} (ht : is_limit t) {W : C} {k l : W ⟶ t.X}
(h₀ : k ≫ fst t = l ≫ fst t) (h₁ : k ≫ snd t = l ≫ snd t) : k = l :=
ht.hom_ext $ equalizer_ext _ h₀ h₁
lemma mono_snd_of_is_pullback_of_mono {t : pullback_cone f g} (ht : is_limit t) [mono f] :
mono t.snd :=
⟨λ W h k i, is_limit.hom_ext ht (by simp [←cancel_mono f, t.condition, reassoc_of i]) i⟩
lemma mono_fst_of_is_pullback_of_mono {t : pullback_cone f g} (ht : is_limit t) [mono g] :
mono t.fst :=
⟨λ W h k i, is_limit.hom_ext ht i (by simp [←cancel_mono g, ←t.condition, reassoc_of i])⟩
/-- To construct an isomorphism of pullback cones, it suffices to construct an isomorphism
of the cone points and check it commutes with `fst` and `snd`. -/
def ext {s t : pullback_cone f g} (i : s.X ≅ t.X)
(w₁ : s.fst = i.hom ≫ t.fst) (w₂ : s.snd = i.hom ≫ t.snd) :
s ≅ t :=
walking_cospan.ext i w₁ w₂
/-- If `t` is a limit pullback cone over `f` and `g` and `h : W ⟶ X` and `k : W ⟶ Y` are such that
`h ≫ f = k ≫ g`, then we have `l : W ⟶ t.X` satisfying `l ≫ fst t = h` and `l ≫ snd t = k`.
-/
def is_limit.lift' {t : pullback_cone f g} (ht : is_limit t) {W : C} (h : W ⟶ X) (k : W ⟶ Y)
(w : h ≫ f = k ≫ g) : {l : W ⟶ t.X // l ≫ fst t = h ∧ l ≫ snd t = k} :=
⟨ht.lift $ pullback_cone.mk _ _ w, ht.fac _ _, ht.fac _ _⟩
/--
This is a more convenient formulation to show that a `pullback_cone` constructed using
`pullback_cone.mk` is a limit cone.
-/
def is_limit.mk {W : C} {fst : W ⟶ X} {snd : W ⟶ Y} (eq : fst ≫ f = snd ≫ g)
(lift : Π (s : pullback_cone f g), s.X ⟶ W)
(fac_left : ∀ (s : pullback_cone f g), lift s ≫ fst = s.fst)
(fac_right : ∀ (s : pullback_cone f g), lift s ≫ snd = s.snd)
(uniq : ∀ (s : pullback_cone f g) (m : s.X ⟶ W)
(w_fst : m ≫ fst = s.fst) (w_snd : m ≫ snd = s.snd), m = lift s) :
is_limit (mk fst snd eq) :=
is_limit_aux _ lift fac_left fac_right
(λ s m w, uniq s m (w walking_cospan.left) (w walking_cospan.right))
/-- The flip of a pullback square is a pullback square. -/
def flip_is_limit {W : C} {h : W ⟶ X} {k : W ⟶ Y}
{comm : h ≫ f = k ≫ g} (t : is_limit (mk _ _ comm.symm)) :
is_limit (mk _ _ comm) :=
is_limit_aux' _ $ λ s,
begin
refine ⟨(is_limit.lift' t _ _ s.condition.symm).1,
(is_limit.lift' t _ _ _).2.2,
(is_limit.lift' t _ _ _).2.1, λ m m₁ m₂, t.hom_ext _⟩,
apply (mk k h _).equalizer_ext,
{ rwa (is_limit.lift' t _ _ _).2.1 },
{ rwa (is_limit.lift' t _ _ _).2.2 },
end
/--
The pullback cone `(𝟙 X, 𝟙 X)` for the pair `(f, f)` is a limit if `f` is a mono. The converse is
shown in `mono_of_pullback_is_id`.
-/
def is_limit_mk_id_id (f : X ⟶ Y) [mono f] :
is_limit (mk (𝟙 X) (𝟙 X) rfl : pullback_cone f f) :=
is_limit.mk _
(λ s, s.fst)
(λ s, category.comp_id _)
(λ s, by rw [←cancel_mono f, category.comp_id, s.condition])
(λ s m m₁ m₂, by simpa using m₁)
/--
`f` is a mono if the pullback cone `(𝟙 X, 𝟙 X)` is a limit for the pair `(f, f)`. The converse is
given in `pullback_cone.is_id_of_mono`.
-/
lemma mono_of_is_limit_mk_id_id (f : X ⟶ Y)
(t : is_limit (mk (𝟙 X) (𝟙 X) rfl : pullback_cone f f)) :
mono f :=
⟨λ Z g h eq, by { rcases pullback_cone.is_limit.lift' t _ _ eq with ⟨_, rfl, rfl⟩, refl } ⟩
/-- Suppose `f` and `g` are two morphisms with a common codomain and `s` is a limit cone over the
diagram formed by `f` and `g`. Suppose `f` and `g` both factor through a monomorphism `h` via
`x` and `y`, respectively. Then `s` is also a limit cone over the diagram formed by `x` and
`y`. -/
def is_limit_of_factors (f : X ⟶ Z) (g : Y ⟶ Z) (h : W ⟶ Z) [mono h]
(x : X ⟶ W) (y : Y ⟶ W) (hxh : x ≫ h = f) (hyh : y ≫ h = g) (s : pullback_cone f g)
(hs : is_limit s) : is_limit (pullback_cone.mk _ _ (show s.fst ≫ x = s.snd ≫ y,
from (cancel_mono h).1 $ by simp only [category.assoc, hxh, hyh, s.condition])) :=
pullback_cone.is_limit_aux' _ $ λ t,
⟨hs.lift (pullback_cone.mk t.fst t.snd $ by rw [←hxh, ←hyh, reassoc_of t.condition]),
⟨hs.fac _ walking_cospan.left, hs.fac _ walking_cospan.right, λ r hr hr',
begin
apply pullback_cone.is_limit.hom_ext hs;
simp only [pullback_cone.mk_fst, pullback_cone.mk_snd] at ⊢ hr hr';
simp only [hr, hr'];
symmetry,
exacts [hs.fac _ walking_cospan.left, hs.fac _ walking_cospan.right]
end⟩⟩
/-- If `W` is the pullback of `f, g`,
it is also the pullback of `f ≫ i, g ≫ i` for any mono `i`. -/
def is_limit_of_comp_mono (f : X ⟶ W) (g : Y ⟶ W) (i : W ⟶ Z) [mono i]
(s : pullback_cone f g) (H : is_limit s) :
is_limit (pullback_cone.mk _ _ (show s.fst ≫ f ≫ i = s.snd ≫ g ≫ i,
by rw [← category.assoc, ← category.assoc, s.condition])) :=
begin
apply pullback_cone.is_limit_aux',
intro s,
rcases pullback_cone.is_limit.lift' H s.fst s.snd
((cancel_mono i).mp (by simpa using s.condition)) with ⟨l, h₁, h₂⟩,
refine ⟨l,h₁,h₂,_⟩,
intros m hm₁ hm₂,
exact (pullback_cone.is_limit.hom_ext H (hm₁.trans h₁.symm) (hm₂.trans h₂.symm) : _)
end
end pullback_cone
/-- A pushout cocone is just a cocone on the span formed by two morphisms `f : X ⟶ Y` and
`g : X ⟶ Z`.-/
abbreviation pushout_cocone (f : X ⟶ Y) (g : X ⟶ Z) := cocone (span f g)
namespace pushout_cocone
variables {f : X ⟶ Y} {g : X ⟶ Z}
/-- The first inclusion of a pushout cocone. -/
abbreviation inl (t : pushout_cocone f g) : Y ⟶ t.X := t.ι.app walking_span.left
/-- The second inclusion of a pushout cocone. -/
abbreviation inr (t : pushout_cocone f g) : Z ⟶ t.X := t.ι.app walking_span.right
@[simp] lemma ι_app_left (c : pushout_cocone f g) : c.ι.app walking_span.left = c.inl := rfl
@[simp] lemma ι_app_right (c : pushout_cocone f g) : c.ι.app walking_span.right = c.inr := rfl
@[simp] lemma condition_zero (t : pushout_cocone f g) : t.ι.app walking_span.zero = f ≫ t.inl :=
begin
have w := t.ι.naturality walking_span.hom.fst,
dsimp at w, simpa using w.symm,
end
/-- This is a slightly more convenient method to verify that a pushout cocone is a colimit cocone.
It only asks for a proof of facts that carry any mathematical content -/
def is_colimit_aux (t : pushout_cocone f g) (desc : Π (s : pushout_cocone f g), t.X ⟶ s.X)
(fac_left : ∀ (s : pushout_cocone f g), t.inl ≫ desc s = s.inl)
(fac_right : ∀ (s : pushout_cocone f g), t.inr ≫ desc s = s.inr)
(uniq : ∀ (s : pushout_cocone f g) (m : t.X ⟶ s.X)
(w : ∀ j : walking_span, t.ι.app j ≫ m = s.ι.app j), m = desc s) :
is_colimit t :=
{ desc := desc,
fac' := λ s j, option.cases_on j (by { simp [← s.w fst, ← t.w fst, fac_left s] } )
(λ j', walking_pair.cases_on j' (fac_left s) (fac_right s)),
uniq' := uniq }
/-- This is another convenient method to verify that a pushout cocone is a colimit cocone. It
only asks for a proof of facts that carry any mathematical content, and allows access to the
same `s` for all parts. -/
def is_colimit_aux' (t : pushout_cocone f g)
(create : Π (s : pushout_cocone f g),
{l // t.inl ≫ l = s.inl ∧ t.inr ≫ l = s.inr ∧
∀ {m}, t.inl ≫ m = s.inl → t.inr ≫ m = s.inr → m = l}) :
is_colimit t :=
is_colimit_aux t
(λ s, (create s).1)
(λ s, (create s).2.1)
(λ s, (create s).2.2.1)
(λ s m w, (create s).2.2.2 (w walking_cospan.left) (w walking_cospan.right))
/-- A pushout cocone on `f` and `g` is determined by morphisms `inl : Y ⟶ W` and `inr : Z ⟶ W` such
that `f ≫ inl = g ↠ inr`. -/
@[simps]
def mk {W : C} (inl : Y ⟶ W) (inr : Z ⟶ W) (eq : f ≫ inl = g ≫ inr) : pushout_cocone f g :=
{ X := W,
ι := { app := λ j, option.cases_on j (f ≫ inl) (λ j', walking_pair.cases_on j' inl inr) } }
@[simp] lemma mk_ι_app_left {W : C} (inl : Y ⟶ W) (inr : Z ⟶ W) (eq : f ≫ inl = g ≫ inr) :
(mk inl inr eq).ι.app walking_span.left = inl := rfl
@[simp] lemma mk_ι_app_right {W : C} (inl : Y ⟶ W) (inr : Z ⟶ W) (eq : f ≫ inl = g ≫ inr) :
(mk inl inr eq).ι.app walking_span.right = inr := rfl
@[simp] lemma mk_ι_app_zero {W : C} (inl : Y ⟶ W) (inr : Z ⟶ W) (eq : f ≫ inl = g ≫ inr) :
(mk inl inr eq).ι.app walking_span.zero = f ≫ inl := rfl
@[simp] lemma mk_inl {W : C} (inl : Y ⟶ W) (inr : Z ⟶ W) (eq : f ≫ inl = g ≫ inr) :
(mk inl inr eq).inl = inl := rfl
@[simp] lemma mk_inr {W : C} (inl : Y ⟶ W) (inr : Z ⟶ W) (eq : f ≫ inl = g ≫ inr) :
(mk inl inr eq).inr = inr := rfl
@[reassoc] lemma condition (t : pushout_cocone f g) : f ≫ (inl t) = g ≫ (inr t) :=
(t.w fst).trans (t.w snd).symm
/-- To check whether a morphism is coequalized by the maps of a pushout cocone, it suffices to check
it for `inl t` and `inr t` -/
lemma coequalizer_ext (t : pushout_cocone f g) {W : C} {k l : t.X ⟶ W}
(h₀ : inl t ≫ k = inl t ≫ l) (h₁ : inr t ≫ k = inr t ≫ l) :
∀ (j : walking_span), t.ι.app j ≫ k = t.ι.app j ≫ l
| (some walking_pair.left) := h₀
| (some walking_pair.right) := h₁
| none := by rw [← t.w fst, category.assoc, category.assoc, h₀]
lemma is_colimit.hom_ext {t : pushout_cocone f g} (ht : is_colimit t) {W : C} {k l : t.X ⟶ W}
(h₀ : inl t ≫ k = inl t ≫ l) (h₁ : inr t ≫ k = inr t ≫ l) : k = l :=
ht.hom_ext $ coequalizer_ext _ h₀ h₁
/-- If `t` is a colimit pushout cocone over `f` and `g` and `h : Y ⟶ W` and `k : Z ⟶ W` are
morphisms satisfying `f ≫ h = g ≫ k`, then we have a factorization `l : t.X ⟶ W` such that
`inl t ≫ l = h` and `inr t ≫ l = k`. -/
def is_colimit.desc' {t : pushout_cocone f g} (ht : is_colimit t) {W : C} (h : Y ⟶ W) (k : Z ⟶ W)
(w : f ≫ h = g ≫ k) : {l : t.X ⟶ W // inl t ≫ l = h ∧ inr t ≫ l = k } :=
⟨ht.desc $ pushout_cocone.mk _ _ w, ht.fac _ _, ht.fac _ _⟩
lemma epi_inr_of_is_pushout_of_epi {t : pushout_cocone f g} (ht : is_colimit t) [epi f] :
epi t.inr :=
⟨λ W h k i, is_colimit.hom_ext ht (by simp [←cancel_epi f, t.condition_assoc, i]) i⟩
lemma epi_inl_of_is_pushout_of_epi {t : pushout_cocone f g} (ht : is_colimit t) [epi g] :
epi t.inl :=
⟨λ W h k i, is_colimit.hom_ext ht i (by simp [←cancel_epi g, ←t.condition_assoc, i])⟩
/-- To construct an isomorphism of pushout cocones, it suffices to construct an isomorphism
of the cocone points and check it commutes with `inl` and `inr`. -/
def ext {s t : pushout_cocone f g} (i : s.X ≅ t.X)
(w₁ : s.inl ≫ i.hom = t.inl) (w₂ : s.inr ≫ i.hom = t.inr) :
s ≅ t :=
walking_span.ext i w₁ w₂
/--
This is a more convenient formulation to show that a `pushout_cocone` constructed using
`pushout_cocone.mk` is a colimit cocone.
-/
def is_colimit.mk {W : C} {inl : Y ⟶ W} {inr : Z ⟶ W} (eq : f ≫ inl = g ≫ inr)
(desc : Π (s : pushout_cocone f g), W ⟶ s.X)
(fac_left : ∀ (s : pushout_cocone f g), inl ≫ desc s = s.inl)
(fac_right : ∀ (s : pushout_cocone f g), inr ≫ desc s = s.inr)
(uniq : ∀ (s : pushout_cocone f g) (m : W ⟶ s.X)
(w_inl : inl ≫ m = s.inl) (w_inr : inr ≫ m = s.inr), m = desc s) :
is_colimit (mk inl inr eq) :=
is_colimit_aux _ desc fac_left fac_right
(λ s m w, uniq s m (w walking_cospan.left) (w walking_cospan.right))
/-- The flip of a pushout square is a pushout square. -/
def flip_is_colimit {W : C} {h : Y ⟶ W} {k : Z ⟶ W}
{comm : f ≫ h = g ≫ k} (t : is_colimit (mk _ _ comm.symm)) :
is_colimit (mk _ _ comm) :=
is_colimit_aux' _ $ λ s,
begin
refine ⟨(is_colimit.desc' t _ _ s.condition.symm).1,
(is_colimit.desc' t _ _ _).2.2,
(is_colimit.desc' t _ _ _).2.1, λ m m₁ m₂, t.hom_ext _⟩,
apply (mk k h _).coequalizer_ext,
{ rwa (is_colimit.desc' t _ _ _).2.1 },
{ rwa (is_colimit.desc' t _ _ _).2.2 },
end
/--
The pushout cocone `(𝟙 X, 𝟙 X)` for the pair `(f, f)` is a colimit if `f` is an epi. The converse is
shown in `epi_of_is_colimit_mk_id_id`.
-/
def is_colimit_mk_id_id (f : X ⟶ Y) [epi f] :
is_colimit (mk (𝟙 Y) (𝟙 Y) rfl : pushout_cocone f f) :=
is_colimit.mk _
(λ s, s.inl)
(λ s, category.id_comp _)
(λ s, by rw [←cancel_epi f, category.id_comp, s.condition])
(λ s m m₁ m₂, by simpa using m₁)
/--
`f` is an epi if the pushout cocone `(𝟙 X, 𝟙 X)` is a colimit for the pair `(f, f)`.
The converse is given in `pushout_cocone.is_colimit_mk_id_id`.
-/
lemma epi_of_is_colimit_mk_id_id (f : X ⟶ Y)
(t : is_colimit (mk (𝟙 Y) (𝟙 Y) rfl : pushout_cocone f f)) :
epi f :=
⟨λ Z g h eq, by { rcases pushout_cocone.is_colimit.desc' t _ _ eq with ⟨_, rfl, rfl⟩, refl }⟩
/-- Suppose `f` and `g` are two morphisms with a common domain and `s` is a colimit cocone over the
diagram formed by `f` and `g`. Suppose `f` and `g` both factor through an epimorphism `h` via
`x` and `y`, respectively. Then `s` is also a colimit cocone over the diagram formed by `x` and
`y`. -/
def is_colimit_of_factors (f : X ⟶ Y) (g : X ⟶ Z) (h : X ⟶ W) [epi h]
(x : W ⟶ Y) (y : W ⟶ Z) (hhx : h ≫ x = f) (hhy : h ≫ y = g) (s : pushout_cocone f g)
(hs : is_colimit s) : is_colimit (pushout_cocone.mk _ _ (show x ≫ s.inl = y ≫ s.inr,
from (cancel_epi h).1 $ by rw [reassoc_of hhx, reassoc_of hhy, s.condition])) :=
pushout_cocone.is_colimit_aux' _ $ λ t,
⟨hs.desc (pushout_cocone.mk t.inl t.inr $
by rw [←hhx, ←hhy, category.assoc, category.assoc, t.condition]),
⟨hs.fac _ walking_span.left, hs.fac _ walking_span.right, λ r hr hr',
begin
apply pushout_cocone.is_colimit.hom_ext hs;
simp only [pushout_cocone.mk_inl, pushout_cocone.mk_inr] at ⊢ hr hr';
simp only [hr, hr'];
symmetry,
exacts [hs.fac _ walking_span.left, hs.fac _ walking_span.right]
end⟩⟩
/-- If `W` is the pushout of `f, g`,
it is also the pushout of `h ≫ f, h ≫ g` for any epi `h`. -/
def is_colimit_of_epi_comp (f : X ⟶ Y) (g : X ⟶ Z) (h : W ⟶ X) [epi h]
(s : pushout_cocone f g) (H : is_colimit s) :
is_colimit (pushout_cocone.mk _ _ (show (h ≫ f) ≫ s.inl = (h ≫ g) ≫ s.inr,
by rw [category.assoc, category.assoc, s.condition])) :=
begin
apply pushout_cocone.is_colimit_aux',
intro s,
rcases pushout_cocone.is_colimit.desc' H s.inl s.inr
((cancel_epi h).mp (by simpa using s.condition)) with ⟨l, h₁, h₂⟩,
refine ⟨l,h₁,h₂,_⟩,
intros m hm₁ hm₂,
exact (pushout_cocone.is_colimit.hom_ext H (hm₁.trans h₁.symm) (hm₂.trans h₂.symm) : _)
end
end pushout_cocone
/-- This is a helper construction that can be useful when verifying that a category has all
pullbacks. Given `F : walking_cospan ⥤ C`, which is really the same as
`cospan (F.map inl) (F.map inr)`, and a pullback cone on `F.map inl` and `F.map inr`, we
get a cone on `F`.
If you're thinking about using this, have a look at `has_pullbacks_of_has_limit_cospan`,
which you may find to be an easier way of achieving your goal. -/
@[simps]
def cone.of_pullback_cone
{F : walking_cospan ⥤ C} (t : pullback_cone (F.map inl) (F.map inr)) : cone F :=
{ X := t.X,
π := t.π ≫ (diagram_iso_cospan F).inv }
/-- This is a helper construction that can be useful when verifying that a category has all
pushout. Given `F : walking_span ⥤ C`, which is really the same as
`span (F.map fst) (F.mal snd)`, and a pushout cocone on `F.map fst` and `F.map snd`,
we get a cocone on `F`.
If you're thinking about using this, have a look at `has_pushouts_of_has_colimit_span`, which
you may find to be an easiery way of achieving your goal. -/
@[simps]
def cocone.of_pushout_cocone
{F : walking_span ⥤ C} (t : pushout_cocone (F.map fst) (F.map snd)) : cocone F :=
{ X := t.X,
ι := (diagram_iso_span F).hom ≫ t.ι }
/-- Given `F : walking_cospan ⥤ C`, which is really the same as `cospan (F.map inl) (F.map inr)`,
and a cone on `F`, we get a pullback cone on `F.map inl` and `F.map inr`. -/
@[simps]
def pullback_cone.of_cone
{F : walking_cospan ⥤ C} (t : cone F) : pullback_cone (F.map inl) (F.map inr) :=
{ X := t.X,
π := t.π ≫ (diagram_iso_cospan F).hom }
/-- A diagram `walking_cospan ⥤ C` is isomorphic to some `pullback_cone.mk` after
composing with `diagram_iso_cospan`. -/
@[simps] def pullback_cone.iso_mk {F : walking_cospan ⥤ C} (t : cone F) :
(cones.postcompose (diagram_iso_cospan.{v} _).hom).obj t ≅
pullback_cone.mk (t.π.app walking_cospan.left) (t.π.app walking_cospan.right)
((t.π.naturality inl).symm.trans (t.π.naturality inr : _)) :=
cones.ext (iso.refl _) $ by rintro (_|(_|_)); { dsimp, simp }
/-- Given `F : walking_span ⥤ C`, which is really the same as `span (F.map fst) (F.map snd)`,
and a cocone on `F`, we get a pushout cocone on `F.map fst` and `F.map snd`. -/
@[simps]
def pushout_cocone.of_cocone
{F : walking_span ⥤ C} (t : cocone F) : pushout_cocone (F.map fst) (F.map snd) :=
{ X := t.X,
ι := (diagram_iso_span F).inv ≫ t.ι }
/-- A diagram `walking_span ⥤ C` is isomorphic to some `pushout_cocone.mk` after composing with
`diagram_iso_span`. -/
@[simps] def pushout_cocone.iso_mk {F : walking_span ⥤ C} (t : cocone F) :
(cocones.precompose (diagram_iso_span.{v} _).inv).obj t ≅
pushout_cocone.mk (t.ι.app walking_span.left) (t.ι.app walking_span.right)
((t.ι.naturality fst).trans (t.ι.naturality snd).symm) :=
cocones.ext (iso.refl _) $ by rintro (_|(_|_)); { dsimp, simp }
/--
`has_pullback f g` represents a particular choice of limiting cone
for the pair of morphisms `f : X ⟶ Z` and `g : Y ⟶ Z`.
-/
abbreviation has_pullback {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) := has_limit (cospan f g)
/--
`has_pushout f g` represents a particular choice of colimiting cocone
for the pair of morphisms `f : X ⟶ Y` and `g : X ⟶ Z`.
-/
abbreviation has_pushout {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) := has_colimit (span f g)
/-- `pullback f g` computes the pullback of a pair of morphisms with the same target. -/
abbreviation pullback {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) [has_pullback f g] :=
limit (cospan f g)
/-- `pushout f g` computes the pushout of a pair of morphisms with the same source. -/
abbreviation pushout {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) [has_pushout f g] :=
colimit (span f g)
/-- The first projection of the pullback of `f` and `g`. -/
abbreviation pullback.fst {X Y Z : C} {f : X ⟶ Z} {g : Y ⟶ Z} [has_pullback f g] :
pullback f g ⟶ X :=
limit.π (cospan f g) walking_cospan.left
/-- The second projection of the pullback of `f` and `g`. -/
abbreviation pullback.snd {X Y Z : C} {f : X ⟶ Z} {g : Y ⟶ Z} [has_pullback f g] :
pullback f g ⟶ Y :=
limit.π (cospan f g) walking_cospan.right
/-- The first inclusion into the pushout of `f` and `g`. -/
abbreviation pushout.inl {X Y Z : C} {f : X ⟶ Y} {g : X ⟶ Z} [has_pushout f g] :
Y ⟶ pushout f g :=
colimit.ι (span f g) walking_span.left
/-- The second inclusion into the pushout of `f` and `g`. -/
abbreviation pushout.inr {X Y Z : C} {f : X ⟶ Y} {g : X ⟶ Z} [has_pushout f g] :
Z ⟶ pushout f g :=
colimit.ι (span f g) walking_span.right
/-- A pair of morphisms `h : W ⟶ X` and `k : W ⟶ Y` satisfying `h ≫ f = k ≫ g` induces a morphism
`pullback.lift : W ⟶ pullback f g`. -/
abbreviation pullback.lift {W X Y Z : C} {f : X ⟶ Z} {g : Y ⟶ Z} [has_pullback f g]
(h : W ⟶ X) (k : W ⟶ Y) (w : h ≫ f = k ≫ g) : W ⟶ pullback f g :=
limit.lift _ (pullback_cone.mk h k w)
/-- A pair of morphisms `h : Y ⟶ W` and `k : Z ⟶ W` satisfying `f ≫ h = g ≫ k` induces a morphism
`pushout.desc : pushout f g ⟶ W`. -/
abbreviation pushout.desc {W X Y Z : C} {f : X ⟶ Y} {g : X ⟶ Z} [has_pushout f g]
(h : Y ⟶ W) (k : Z ⟶ W) (w : f ≫ h = g ≫ k) : pushout f g ⟶ W :=
colimit.desc _ (pushout_cocone.mk h k w)
@[simp]
lemma pullback_cone.fst_colimit_cocone {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z)
[has_limit (cospan f g)] : pullback_cone.fst (limit.cone (cospan f g)) = pullback.fst :=
rfl
@[simp]
lemma pullback_cone.snd_colimit_cocone {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z)
[has_limit (cospan f g)] : pullback_cone.snd (limit.cone (cospan f g)) = pullback.snd :=
rfl
@[simp]
lemma pushout_cocone.inl_colimit_cocone {X Y Z : C} (f : Z ⟶ X) (g : Z ⟶ Y)
[has_colimit (span f g)] : pushout_cocone.inl (colimit.cocone (span f g)) = pushout.inl :=
rfl
@[simp]
lemma pushout_cocone.inr_colimit_cocone {X Y Z : C} (f : Z ⟶ X) (g : Z ⟶ Y)
[has_colimit (span f g)] : pushout_cocone.inr (colimit.cocone (span f g)) = pushout.inr :=
rfl
@[simp, reassoc]
lemma pullback.lift_fst {W X Y Z : C} {f : X ⟶ Z} {g : Y ⟶ Z} [has_pullback f g]
(h : W ⟶ X) (k : W ⟶ Y) (w : h ≫ f = k ≫ g) : pullback.lift h k w ≫ pullback.fst = h :=
limit.lift_π _ _
@[simp, reassoc]
lemma pullback.lift_snd {W X Y Z : C} {f : X ⟶ Z} {g : Y ⟶ Z} [has_pullback f g]
(h : W ⟶ X) (k : W ⟶ Y) (w : h ≫ f = k ≫ g) : pullback.lift h k w ≫ pullback.snd = k :=
limit.lift_π _ _
@[simp, reassoc]
lemma pushout.inl_desc {W X Y Z : C} {f : X ⟶ Y} {g : X ⟶ Z} [has_pushout f g]
(h : Y ⟶ W) (k : Z ⟶ W) (w : f ≫ h = g ≫ k) : pushout.inl ≫ pushout.desc h k w = h :=
colimit.ι_desc _ _
@[simp, reassoc]
lemma pushout.inr_desc {W X Y Z : C} {f : X ⟶ Y} {g : X ⟶ Z} [has_pushout f g]
(h : Y ⟶ W) (k : Z ⟶ W) (w : f ≫ h = g ≫ k) : pushout.inr ≫ pushout.desc h k w = k :=
colimit.ι_desc _ _
/-- A pair of morphisms `h : W ⟶ X` and `k : W ⟶ Y` satisfying `h ≫ f = k ≫ g` induces a morphism
`l : W ⟶ pullback f g` such that `l ≫ pullback.fst = h` and `l ≫ pullback.snd = k`. -/
def pullback.lift' {W X Y Z : C} {f : X ⟶ Z} {g : Y ⟶ Z} [has_pullback f g]
(h : W ⟶ X) (k : W ⟶ Y) (w : h ≫ f = k ≫ g) :
{l : W ⟶ pullback f g // l ≫ pullback.fst = h ∧ l ≫ pullback.snd = k} :=
⟨pullback.lift h k w, pullback.lift_fst _ _ _, pullback.lift_snd _ _ _⟩
/-- A pair of morphisms `h : Y ⟶ W` and `k : Z ⟶ W` satisfying `f ≫ h = g ≫ k` induces a morphism
`l : pushout f g ⟶ W` such that `pushout.inl ≫ l = h` and `pushout.inr ≫ l = k`. -/
def pullback.desc' {W X Y Z : C} {f : X ⟶ Y} {g : X ⟶ Z} [has_pushout f g]
(h : Y ⟶ W) (k : Z ⟶ W) (w : f ≫ h = g ≫ k) :
{l : pushout f g ⟶ W // pushout.inl ≫ l = h ∧ pushout.inr ≫ l = k} :=
⟨pushout.desc h k w, pushout.inl_desc _ _ _, pushout.inr_desc _ _ _⟩
@[reassoc]
lemma pullback.condition {X Y Z : C} {f : X ⟶ Z} {g : Y ⟶ Z} [has_pullback f g] :
(pullback.fst : pullback f g ⟶ X) ≫ f = pullback.snd ≫ g :=
pullback_cone.condition _
@[reassoc]
lemma pushout.condition {X Y Z : C} {f : X ⟶ Y} {g : X ⟶ Z} [has_pushout f g] :
f ≫ (pushout.inl : Y ⟶ pushout f g) = g ≫ pushout.inr :=
pushout_cocone.condition _
/--
Given such a diagram, then there is a natural morphism `W ×ₛ X ⟶ Y ×ₜ Z`.
W ⟶ Y
↘ ↘
S ⟶ T
↗ ↗
X ⟶ Z
-/
abbreviation pullback.map {W X Y Z S T : C} (f₁ : W ⟶ S) (f₂ : X ⟶ S) [has_pullback f₁ f₂]
(g₁ : Y ⟶ T) (g₂ : Z ⟶ T) [has_pullback g₁ g₂] (i₁ : W ⟶ Y) (i₂ : X ⟶ Z) (i₃ : S ⟶ T)
(eq₁ : f₁ ≫ i₃ = i₁ ≫ g₁) (eq₂ : f₂ ≫ i₃ = i₂ ≫ g₂) : pullback f₁ f₂ ⟶ pullback g₁ g₂ :=
pullback.lift (pullback.fst ≫ i₁) (pullback.snd ≫ i₂)
(by simp [← eq₁, ← eq₂, pullback.condition_assoc])
/--
Given such a diagram, then there is a natural morphism `W ⨿ₛ X ⟶ Y ⨿ₜ Z`.
W ⟶ Y
↗ ↗
S ⟶ T
↘ ↘
X ⟶ Z
-/
abbreviation pushout.map {W X Y Z S T : C} (f₁ : S ⟶ W) (f₂ : S ⟶ X) [has_pushout f₁ f₂]
(g₁ : T ⟶ Y) (g₂ : T ⟶ Z) [has_pushout g₁ g₂] (i₁ : W ⟶ Y) (i₂ : X ⟶ Z) (i₃ : S ⟶ T)
(eq₁ : f₁ ≫ i₁ = i₃ ≫ g₁) (eq₂ : f₂ ≫ i₂ = i₃ ≫ g₂) : pushout f₁ f₂ ⟶ pushout g₁ g₂ :=
pushout.desc (i₁ ≫ pushout.inl) (i₂ ≫ pushout.inr)
(by { simp only [← category.assoc, eq₁, eq₂], simp [pushout.condition] })
/-- Two morphisms into a pullback are equal if their compositions with the pullback morphisms are
equal -/
@[ext] lemma pullback.hom_ext {X Y Z : C} {f : X ⟶ Z} {g : Y ⟶ Z} [has_pullback f g]
{W : C} {k l : W ⟶ pullback f g} (h₀ : k ≫ pullback.fst = l ≫ pullback.fst)
(h₁ : k ≫ pullback.snd = l ≫ pullback.snd) : k = l :=
limit.hom_ext $ pullback_cone.equalizer_ext _ h₀ h₁
/-- The pullback cone built from the pullback projections is a pullback. -/
def pullback_is_pullback {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) [has_pullback f g] :
is_limit (pullback_cone.mk (pullback.fst : pullback f g ⟶ _) pullback.snd pullback.condition) :=
pullback_cone.is_limit.mk _ (λ s, pullback.lift s.fst s.snd s.condition)
(by simp) (by simp) (by tidy)
/-- The pullback of a monomorphism is a monomorphism -/
instance pullback.fst_of_mono {X Y Z : C} {f : X ⟶ Z} {g : Y ⟶ Z} [has_pullback f g]
[mono g] : mono (pullback.fst : pullback f g ⟶ X) :=
pullback_cone.mono_fst_of_is_pullback_of_mono (limit.is_limit _)
/-- The pullback of a monomorphism is a monomorphism -/
instance pullback.snd_of_mono {X Y Z : C} {f : X ⟶ Z} {g : Y ⟶ Z} [has_pullback f g]
[mono f] : mono (pullback.snd : pullback f g ⟶ Y) :=
pullback_cone.mono_snd_of_is_pullback_of_mono (limit.is_limit _)
/-- The map `X ×[Z] Y ⟶ X × Y` is mono. -/
instance mono_pullback_to_prod {C : Type*} [category C] {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z)
[has_pullback f g] [has_binary_product X Y] :
mono (prod.lift pullback.fst pullback.snd : pullback f g ⟶ _) :=
⟨λ W i₁ i₂ h, begin
ext,
{ simpa using congr_arg (λ f, f ≫ prod.fst) h },
{ simpa using congr_arg (λ f, f ≫ prod.snd) h }
end⟩
/-- Two morphisms out of a pushout are equal if their compositions with the pushout morphisms are
equal -/
@[ext] lemma pushout.hom_ext {X Y Z : C} {f : X ⟶ Y} {g : X ⟶ Z} [has_pushout f g]
{W : C} {k l : pushout f g ⟶ W} (h₀ : pushout.inl ≫ k = pushout.inl ≫ l)
(h₁ : pushout.inr ≫ k = pushout.inr ≫ l) : k = l :=
colimit.hom_ext $ pushout_cocone.coequalizer_ext _ h₀ h₁
/-- The pushout cocone built from the pushout coprojections is a pushout. -/
def pushout_is_pushout {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) [has_pushout f g] :
is_colimit (pushout_cocone.mk (pushout.inl : _ ⟶ pushout f g) pushout.inr pushout.condition) :=
pushout_cocone.is_colimit.mk _ (λ s, pushout.desc s.inl s.inr s.condition)
(by simp) (by simp) (by tidy)
/-- The pushout of an epimorphism is an epimorphism -/
instance pushout.inl_of_epi {X Y Z : C} {f : X ⟶ Y} {g : X ⟶ Z} [has_pushout f g] [epi g] :
epi (pushout.inl : Y ⟶ pushout f g) :=
pushout_cocone.epi_inl_of_is_pushout_of_epi (colimit.is_colimit _)
/-- The pushout of an epimorphism is an epimorphism -/
instance pushout.inr_of_epi {X Y Z : C} {f : X ⟶ Y} {g : X ⟶ Z} [has_pushout f g] [epi f] :
epi (pushout.inr : Z ⟶ pushout f g) :=
pushout_cocone.epi_inr_of_is_pushout_of_epi (colimit.is_colimit _)
/-- The map ` X ⨿ Y ⟶ X ⨿[Z] Y` is epi. -/
instance epi_coprod_to_pushout {C : Type*} [category C] {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z)
[has_pushout f g] [has_binary_coproduct Y Z] :
epi (coprod.desc pushout.inl pushout.inr : _ ⟶ pushout f g) :=
⟨λ W i₁ i₂ h, begin
ext,
{ simpa using congr_arg (λ f, coprod.inl ≫ f) h },
{ simpa using congr_arg (λ f, coprod.inr ≫ f) h }
end⟩
instance pullback.map_is_iso {W X Y Z S T : C} (f₁ : W ⟶ S) (f₂ : X ⟶ S) [has_pullback f₁ f₂]
(g₁ : Y ⟶ T) (g₂ : Z ⟶ T) [has_pullback g₁ g₂] (i₁ : W ⟶ Y) (i₂ : X ⟶ Z) (i₃ : S ⟶ T)
(eq₁ : f₁ ≫ i₃ = i₁ ≫ g₁) (eq₂ : f₂ ≫ i₃ = i₂ ≫ g₂) [is_iso i₁] [is_iso i₂] [is_iso i₃] :
is_iso (pullback.map f₁ f₂ g₁ g₂ i₁ i₂ i₃ eq₁ eq₂) :=
begin
refine ⟨⟨pullback.map _ _ _ _ (inv i₁) (inv i₂) (inv i₃) _ _, _, _⟩⟩,
{ rw [is_iso.comp_inv_eq, category.assoc, eq₁, is_iso.inv_hom_id_assoc] },
{ rw [is_iso.comp_inv_eq, category.assoc, eq₂, is_iso.inv_hom_id_assoc] },
tidy
end
/-- If `f₁ = f₂` and `g₁ = g₂`, we may construct a canonical
isomorphism `pullback f₁ g₁ ≅ pullback f₂ g₂` -/
@[simps hom]
def pullback.congr_hom {X Y Z : C} {f₁ f₂ : X ⟶ Z} {g₁ g₂ : Y ⟶ Z}
(h₁ : f₁ = f₂) (h₂ : g₁ = g₂) [has_pullback f₁ g₁] [has_pullback f₂ g₂] :
pullback f₁ g₁ ≅ pullback f₂ g₂ :=
as_iso $ pullback.map _ _ _ _ (𝟙 _) (𝟙 _) (𝟙 _) (by simp [h₁]) (by simp [h₂])
@[simp]
lemma pullback.congr_hom_inv {X Y Z : C} {f₁ f₂ : X ⟶ Z} {g₁ g₂ : Y ⟶ Z}
(h₁ : f₁ = f₂) (h₂ : g₁ = g₂) [has_pullback f₁ g₁] [has_pullback f₂ g₂] :
(pullback.congr_hom h₁ h₂).inv =
pullback.map _ _ _ _ (𝟙 _) (𝟙 _) (𝟙 _) (by simp [h₁]) (by simp [h₂]) :=
begin
apply pullback.hom_ext,
{ erw pullback.lift_fst,
rw iso.inv_comp_eq,
erw pullback.lift_fst_assoc,
rw [category.comp_id, category.comp_id] },
{ erw pullback.lift_snd,
rw iso.inv_comp_eq,
erw pullback.lift_snd_assoc,
rw [category.comp_id, category.comp_id] },
end
instance pushout.map_is_iso {W X Y Z S T : C} (f₁ : S ⟶ W) (f₂ : S ⟶ X) [has_pushout f₁ f₂]
(g₁ : T ⟶ Y) (g₂ : T ⟶ Z) [has_pushout g₁ g₂] (i₁ : W ⟶ Y) (i₂ : X ⟶ Z) (i₃ : S ⟶ T)
(eq₁ : f₁ ≫ i₁ = i₃ ≫ g₁) (eq₂ : f₂ ≫ i₂ = i₃ ≫ g₂) [is_iso i₁] [is_iso i₂] [is_iso i₃] :
is_iso (pushout.map f₁ f₂ g₁ g₂ i₁ i₂ i₃ eq₁ eq₂) :=
begin
refine ⟨⟨pushout.map _ _ _ _ (inv i₁) (inv i₂) (inv i₃) _ _, _, _⟩⟩,
{ rw [is_iso.comp_inv_eq, category.assoc, eq₁, is_iso.inv_hom_id_assoc] },
{ rw [is_iso.comp_inv_eq, category.assoc, eq₂, is_iso.inv_hom_id_assoc] },
tidy
end
/-- If `f₁ = f₂` and `g₁ = g₂`, we may construct a canonical
isomorphism `pushout f₁ g₁ ≅ pullback f₂ g₂` -/
@[simps hom]
def pushout.congr_hom {X Y Z : C} {f₁ f₂ : X ⟶ Y} {g₁ g₂ : X ⟶ Z}
(h₁ : f₁ = f₂) (h₂ : g₁ = g₂) [has_pushout f₁ g₁] [has_pushout f₂ g₂] :
pushout f₁ g₁ ≅ pushout f₂ g₂ :=
as_iso $ pushout.map _ _ _ _ (𝟙 _) (𝟙 _) (𝟙 _) (by simp [h₁]) (by simp [h₂])
@[simp]
lemma pushout.congr_hom_inv {X Y Z : C} {f₁ f₂ : X ⟶ Y} {g₁ g₂ : X ⟶ Z}
(h₁ : f₁ = f₂) (h₂ : g₁ = g₂) [has_pushout f₁ g₁] [has_pushout f₂ g₂] :
(pushout.congr_hom h₁ h₂).inv =
pushout.map _ _ _ _ (𝟙 _) (𝟙 _) (𝟙 _) (by simp [h₁]) (by simp [h₂]) :=
begin
apply pushout.hom_ext,
{ erw pushout.inl_desc,
rw [iso.comp_inv_eq, category.id_comp],
erw pushout.inl_desc,
rw category.id_comp },
{ erw pushout.inr_desc,
rw [iso.comp_inv_eq, category.id_comp],
erw pushout.inr_desc,
rw category.id_comp }
end
section
variables (G : C ⥤ D)
/--
The comparison morphism for the pullback of `f,g`.
This is an isomorphism iff `G` preserves the pullback of `f,g`; see
`category_theory/limits/preserves/shapes/pullbacks.lean`
-/
def pullback_comparison (f : X ⟶ Z) (g : Y ⟶ Z)
[has_pullback f g] [has_pullback (G.map f) (G.map g)] :
G.obj (pullback f g) ⟶ pullback (G.map f) (G.map g) :=
pullback.lift (G.map pullback.fst) (G.map pullback.snd)
(by simp only [←G.map_comp, pullback.condition])
@[simp, reassoc]
lemma pullback_comparison_comp_fst (f : X ⟶ Z) (g : Y ⟶ Z)
[has_pullback f g] [has_pullback (G.map f) (G.map g)] :
pullback_comparison G f g ≫ pullback.fst = G.map pullback.fst :=
pullback.lift_fst _ _ _
@[simp, reassoc]
lemma pullback_comparison_comp_snd (f : X ⟶ Z) (g : Y ⟶ Z)
[has_pullback f g] [has_pullback (G.map f) (G.map g)] :
pullback_comparison G f g ≫ pullback.snd = G.map pullback.snd :=
pullback.lift_snd _ _ _
@[simp, reassoc]
lemma map_lift_pullback_comparison (f : X ⟶ Z) (g : Y ⟶ Z)
[has_pullback f g] [has_pullback (G.map f) (G.map g)]
{W : C} {h : W ⟶ X} {k : W ⟶ Y} (w : h ≫ f = k ≫ g) :
G.map (pullback.lift _ _ w) ≫ pullback_comparison G f g =
pullback.lift (G.map h) (G.map k) (by simp only [←G.map_comp, w]) :=
by { ext; simp [← G.map_comp] }
/--
The comparison morphism for the pushout of `f,g`.
This is an isomorphism iff `G` preserves the pushout of `f,g`; see
`category_theory/limits/preserves/shapes/pullbacks.lean`
-/
def pushout_comparison (f : X ⟶ Y) (g : X ⟶ Z)
[has_pushout f g] [has_pushout (G.map f) (G.map g)] :
pushout (G.map f) (G.map g) ⟶ G.obj (pushout f g) :=
pushout.desc (G.map pushout.inl) (G.map pushout.inr)
(by simp only [←G.map_comp, pushout.condition])
@[simp, reassoc]
lemma inl_comp_pushout_comparison (f : X ⟶ Y) (g : X ⟶ Z)
[has_pushout f g] [has_pushout (G.map f) (G.map g)] :
pushout.inl ≫ pushout_comparison G f g = G.map pushout.inl :=
pushout.inl_desc _ _ _
@[simp, reassoc]
lemma inr_comp_pushout_comparison (f : X ⟶ Y) (g : X ⟶ Z)
[has_pushout f g] [has_pushout (G.map f) (G.map g)] :
pushout.inr ≫ pushout_comparison G f g = G.map pushout.inr :=
pushout.inr_desc _ _ _
@[simp, reassoc]
lemma pushout_comparison_map_desc (f : X ⟶ Y) (g : X ⟶ Z)
[has_pushout f g] [has_pushout (G.map f) (G.map g)]
{W : C} {h : Y ⟶ W} {k : Z ⟶ W} (w : f ≫ h = g ≫ k) :
pushout_comparison G f g ≫ G.map (pushout.desc _ _ w) =
pushout.desc (G.map h) (G.map k) (by simp only [←G.map_comp, w]) :=
by { ext; simp [← G.map_comp] }
end
section pullback_symmetry
open walking_cospan
variables (f : X ⟶ Z) (g : Y ⟶ Z)
/-- Making this a global instance would make the typeclass seach go in an infinite loop. -/
lemma has_pullback_symmetry [has_pullback f g] : has_pullback g f :=
⟨⟨⟨pullback_cone.mk _ _ pullback.condition.symm,
pullback_cone.flip_is_limit (pullback_is_pullback _ _)⟩⟩⟩
local attribute [instance] has_pullback_symmetry
/-- The isomorphism `X ×[Z] Y ≅ Y ×[Z] X`. -/
def pullback_symmetry [has_pullback f g] :
pullback f g ≅ pullback g f :=
is_limit.cone_point_unique_up_to_iso
(pullback_cone.flip_is_limit (pullback_is_pullback f g) :
is_limit (pullback_cone.mk _ _ pullback.condition.symm))
(limit.is_limit _)
@[simp, reassoc] lemma pullback_symmetry_hom_comp_fst [has_pullback f g] :
(pullback_symmetry f g).hom ≫ pullback.fst = pullback.snd := by simp [pullback_symmetry]
@[simp, reassoc] lemma pullback_symmetry_hom_comp_snd [has_pullback f g] :
(pullback_symmetry f g).hom ≫ pullback.snd = pullback.fst := by simp [pullback_symmetry]
@[simp, reassoc] lemma pullback_symmetry_inv_comp_fst [has_pullback f g] :
(pullback_symmetry f g).inv ≫ pullback.fst = pullback.snd := by simp [iso.inv_comp_eq]
@[simp, reassoc] lemma pullback_symmetry_inv_comp_snd [has_pullback f g] :
(pullback_symmetry f g).inv ≫ pullback.snd = pullback.fst := by simp [iso.inv_comp_eq]
end pullback_symmetry
section pushout_symmetry
open walking_cospan
variables (f : X ⟶ Y) (g : X ⟶ Z)
/-- Making this a global instance would make the typeclass seach go in an infinite loop. -/
lemma has_pushout_symmetry [has_pushout f g] : has_pushout g f :=
⟨⟨⟨pushout_cocone.mk _ _ pushout.condition.symm,
pushout_cocone.flip_is_colimit (pushout_is_pushout _ _)⟩⟩⟩
local attribute [instance] has_pushout_symmetry
/-- The isomorphism `Y ⨿[X] Z ≅ Z ⨿[X] Y`. -/
def pushout_symmetry [has_pushout f g] :
pushout f g ≅ pushout g f :=
is_colimit.cocone_point_unique_up_to_iso
(pushout_cocone.flip_is_colimit (pushout_is_pushout f g) :
is_colimit (pushout_cocone.mk _ _ pushout.condition.symm))
(colimit.is_colimit _)
@[simp, reassoc] lemma inl_comp_pushout_symmetry_hom [has_pushout f g] :
pushout.inl ≫ (pushout_symmetry f g).hom = pushout.inr :=
(colimit.is_colimit (span f g)).comp_cocone_point_unique_up_to_iso_hom
(pushout_cocone.flip_is_colimit (pushout_is_pushout g f)) _
@[simp, reassoc] lemma inr_comp_pushout_symmetry_hom [has_pushout f g] :
pushout.inr ≫ (pushout_symmetry f g).hom = pushout.inl :=
(colimit.is_colimit (span f g)).comp_cocone_point_unique_up_to_iso_hom
(pushout_cocone.flip_is_colimit (pushout_is_pushout g f)) _
@[simp, reassoc] lemma inl_comp_pushout_symmetry_inv [has_pushout f g] :
pushout.inl ≫ (pushout_symmetry f g).inv = pushout.inr := by simp [iso.comp_inv_eq]
@[simp, reassoc] lemma inr_comp_pushout_symmetry_inv [has_pushout f g] :
pushout.inr ≫ (pushout_symmetry f g).inv = pushout.inl := by simp [iso.comp_inv_eq]
end pushout_symmetry
section pullback_left_iso
open walking_cospan
/-- The pullback of `f, g` is also the pullback of `f ≫ i, g ≫ i` for any mono `i`. -/
noncomputable
def pullback_is_pullback_of_comp_mono (f : X ⟶ W) (g : Y ⟶ W) (i : W ⟶ Z)
[mono i] [has_pullback f g] :
is_limit (pullback_cone.mk pullback.fst pullback.snd _) :=
pullback_cone.is_limit_of_comp_mono f g i _ (limit.is_limit (cospan f g))
instance has_pullback_of_comp_mono (f : X ⟶ W) (g : Y ⟶ W) (i : W ⟶ Z)
[mono i] [has_pullback f g] : has_pullback (f ≫ i) (g ≫ i) :=
⟨⟨⟨_,pullback_is_pullback_of_comp_mono f g i⟩⟩⟩
variables (f : X ⟶ Z) (g : Y ⟶ Z) [is_iso f]
/-- If `f : X ⟶ Z` is iso, then `X ×[Z] Y ≅ Y`. This is the explicit limit cone. -/
def pullback_cone_of_left_iso : pullback_cone f g :=
pullback_cone.mk (g ≫ inv f) (𝟙 _) $ by simp
@[simp] lemma pullback_cone_of_left_iso_X :
(pullback_cone_of_left_iso f g).X = Y := rfl
@[simp] lemma pullback_cone_of_left_iso_fst :
(pullback_cone_of_left_iso f g).fst = g ≫ inv f := rfl
@[simp] lemma pullback_cone_of_left_iso_snd :
(pullback_cone_of_left_iso f g).snd = 𝟙 _ := rfl
@[simp] lemma pullback_cone_of_left_iso_π_app_none :
(pullback_cone_of_left_iso f g).π.app none = g := by { delta pullback_cone_of_left_iso, simp }
@[simp] lemma pullback_cone_of_left_iso_π_app_left :
(pullback_cone_of_left_iso f g).π.app left = g ≫ inv f := rfl
@[simp] lemma pullback_cone_of_left_iso_π_app_right :
(pullback_cone_of_left_iso f g).π.app right = 𝟙 _ := rfl
/-- Verify that the constructed limit cone is indeed a limit. -/
def pullback_cone_of_left_iso_is_limit :
is_limit (pullback_cone_of_left_iso f g) :=
pullback_cone.is_limit_aux' _ (λ s, ⟨s.snd, by simp [← s.condition_assoc]⟩)
lemma has_pullback_of_left_iso : has_pullback f g :=
⟨⟨⟨_, pullback_cone_of_left_iso_is_limit f g⟩⟩⟩
local attribute [instance] has_pullback_of_left_iso
instance pullback_snd_iso_of_left_iso : is_iso (pullback.snd : pullback f g ⟶ _) :=
begin
refine ⟨⟨pullback.lift (g ≫ inv f) (𝟙 _) (by simp), _, by simp⟩⟩,
ext,
{ simp [← pullback.condition_assoc] },
{ simp [pullback.condition_assoc] },
end
variables (i : Z ⟶ W) [mono i]
instance has_pullback_of_right_factors_mono (f : X ⟶ Z) : has_pullback i (f ≫ i) :=
by { conv { congr, rw ←category.id_comp i, }, apply_instance }
instance pullback_snd_iso_of_right_factors_mono (f : X ⟶ Z) :
is_iso (pullback.snd : pullback i (f ≫ i) ⟶ _) :=
begin
convert (congr_arg is_iso (show _ ≫ pullback.snd = _,
from limit.iso_limit_cone_hom_π ⟨_,pullback_is_pullback_of_comp_mono (𝟙 _) f i⟩
walking_cospan.right)).mp infer_instance;
exact (category.id_comp _).symm
end
end pullback_left_iso
section pullback_right_iso
open walking_cospan
variables (f : X ⟶ Z) (g : Y ⟶ Z) [is_iso g]
/-- If `g : Y ⟶ Z` is iso, then `X ×[Z] Y ≅ X`. This is the explicit limit cone. -/
def pullback_cone_of_right_iso : pullback_cone f g :=
pullback_cone.mk (𝟙 _) (f ≫ inv g) $ by simp
@[simp] lemma pullback_cone_of_right_iso_X :
(pullback_cone_of_right_iso f g).X = X := rfl
@[simp] lemma pullback_cone_of_right_iso_fst :
(pullback_cone_of_right_iso f g).fst = 𝟙 _ := rfl
@[simp] lemma pullback_cone_of_right_iso_snd :
(pullback_cone_of_right_iso f g).snd = f ≫ inv g := rfl
@[simp] lemma pullback_cone_of_right_iso_π_app_none :
(pullback_cone_of_right_iso f g).π.app none = f := category.id_comp _
@[simp] lemma pullback_cone_of_right_iso_π_app_left :
(pullback_cone_of_right_iso f g).π.app left = 𝟙 _ := rfl
@[simp] lemma pullback_cone_of_right_iso_π_app_right :
(pullback_cone_of_right_iso f g).π.app right = f ≫ inv g := rfl
/-- Verify that the constructed limit cone is indeed a limit. -/
def pullback_cone_of_right_iso_is_limit :
is_limit (pullback_cone_of_right_iso f g) :=
pullback_cone.is_limit_aux' _ (λ s, ⟨s.fst, by simp [s.condition_assoc]⟩)
lemma has_pullback_of_right_iso : has_pullback f g :=
⟨⟨⟨_, pullback_cone_of_right_iso_is_limit f g⟩⟩⟩
local attribute [instance] has_pullback_of_right_iso
instance pullback_snd_iso_of_right_iso : is_iso (pullback.fst : pullback f g ⟶ _) :=
begin
refine ⟨⟨pullback.lift (𝟙 _) (f ≫ inv g) (by simp), _, by simp⟩⟩,
ext,
{ simp },
{ simp [pullback.condition_assoc] },
end
variables (i : Z ⟶ W) [mono i]
instance has_pullback_of_left_factors_mono (f : X ⟶ Z) : has_pullback (f ≫ i) i :=
by { conv { congr, skip, rw ←category.id_comp i, }, apply_instance }
instance pullback_snd_iso_of_left_factors_mono (f : X ⟶ Z) :
is_iso (pullback.fst : pullback (f ≫ i) i ⟶ _) :=
begin
convert (congr_arg is_iso (show _ ≫ pullback.fst = _,
from limit.iso_limit_cone_hom_π ⟨_,pullback_is_pullback_of_comp_mono f (𝟙 _) i⟩
walking_cospan.left)).mp infer_instance;
exact (category.id_comp _).symm
end
end pullback_right_iso
section pushout_left_iso
open walking_span
/-- The pushout of `f, g` is also the pullback of `h ≫ f, h ≫ g` for any epi `h`. -/
noncomputable
def pushout_is_pushout_of_epi_comp (f : X ⟶ Y) (g : X ⟶ Z) (h : W ⟶ X)
[epi h] [has_pushout f g] :
is_colimit (pushout_cocone.mk pushout.inl pushout.inr _) :=
pushout_cocone.is_colimit_of_epi_comp f g h _ (colimit.is_colimit (span f g))
instance has_pushout_of_epi_comp (f : X ⟶ Y) (g : X ⟶ Z) (h : W ⟶ X)
[epi h] [has_pushout f g] : has_pushout (h ≫ f) (h ≫ g) :=
⟨⟨⟨_,pushout_is_pushout_of_epi_comp f g h⟩⟩⟩
variables (f : X ⟶ Y) (g : X ⟶ Z) [is_iso f]
/-- If `f : X ⟶ Y` is iso, then `Y ⨿[X] Z ≅ Z`. This is the explicit colimit cocone. -/
def pushout_cocone_of_left_iso : pushout_cocone f g :=
pushout_cocone.mk (inv f ≫ g) (𝟙 _) $ by simp
@[simp] lemma pushout_cocone_of_left_iso_X :
(pushout_cocone_of_left_iso f g).X = Z := rfl
@[simp] lemma pushout_cocone_of_left_iso_inl :
(pushout_cocone_of_left_iso f g).inl = inv f ≫ g := rfl
@[simp] lemma pushout_cocone_of_left_iso_inr :
(pushout_cocone_of_left_iso f g).inr = 𝟙 _ := rfl
@[simp] lemma pushout_cocone_of_left_iso_ι_app_none :
(pushout_cocone_of_left_iso f g).ι.app none = g := by { delta pushout_cocone_of_left_iso, simp }
@[simp] lemma pushout_cocone_of_left_iso_ι_app_left :
(pushout_cocone_of_left_iso f g).ι.app left = inv f ≫ g := rfl
@[simp] lemma pushout_cocone_of_left_iso_ι_app_right :
(pushout_cocone_of_left_iso f g).ι.app right = 𝟙 _ := rfl
/-- Verify that the constructed cocone is indeed a colimit. -/
def pushout_cocone_of_left_iso_is_limit :
is_colimit (pushout_cocone_of_left_iso f g) :=
pushout_cocone.is_colimit_aux' _ (λ s, ⟨s.inr, by simp [← s.condition]⟩)
lemma has_pushout_of_left_iso : has_pushout f g :=
⟨⟨⟨_, pushout_cocone_of_left_iso_is_limit f g⟩⟩⟩
local attribute [instance] has_pushout_of_left_iso
instance pushout_inr_iso_of_left_iso : is_iso (pushout.inr : _ ⟶ pushout f g) :=
begin
refine ⟨⟨pushout.desc (inv f ≫ g) (𝟙 _) (by simp), (by simp), _⟩⟩,
ext,
{ simp [← pushout.condition] },
{ simp [pushout.condition_assoc] },
end
variables (h : W ⟶ X) [epi h]
instance has_pushout_of_right_factors_epi (f : X ⟶ Y) : has_pushout h (h ≫ f) :=
by { conv { congr, rw ←category.comp_id h, }, apply_instance }
instance pushout_inr_iso_of_right_factors_epi (f : X ⟶ Y) :
is_iso (pushout.inr : _ ⟶ pushout h (h ≫ f)) :=
begin
convert (congr_arg is_iso (show pushout.inr ≫ _ = _,
from colimit.iso_colimit_cocone_ι_inv ⟨_, pushout_is_pushout_of_epi_comp (𝟙 _) f h⟩
walking_span.right)).mp infer_instance;
exact (category.comp_id _).symm
end
end pushout_left_iso
section pushout_right_iso
open walking_span
variables (f : X ⟶ Y) (g : X ⟶ Z) [is_iso g]
/-- If `f : X ⟶ Z` is iso, then `Y ⨿[X] Z ≅ Y`. This is the explicit colimit cocone. -/
def pushout_cocone_of_right_iso : pushout_cocone f g :=
pushout_cocone.mk (𝟙 _) (inv g ≫ f) $ by simp
@[simp] lemma pushout_cocone_of_right_iso_X :
(pushout_cocone_of_right_iso f g).X = Y := rfl
@[simp] lemma pushout_cocone_of_right_iso_inl :
(pushout_cocone_of_right_iso f g).inl = 𝟙 _ := rfl
@[simp] lemma pushout_cocone_of_right_iso_inr :
(pushout_cocone_of_right_iso f g).inr = inv g ≫ f := rfl
@[simp] lemma pushout_cocone_of_right_iso_ι_app_none :
(pushout_cocone_of_right_iso f g).ι.app none = f := by { delta pushout_cocone_of_right_iso, simp }
@[simp] lemma pushout_cocone_of_right_iso_ι_app_left :
(pushout_cocone_of_right_iso f g).ι.app left = 𝟙 _ := rfl
@[simp] lemma pushout_cocone_of_right_iso_ι_app_right :
(pushout_cocone_of_right_iso f g).ι.app right = inv g ≫ f := rfl
/-- Verify that the constructed cocone is indeed a colimit. -/
def pushout_cocone_of_right_iso_is_limit :
is_colimit (pushout_cocone_of_right_iso f g) :=
pushout_cocone.is_colimit_aux' _ (λ s, ⟨s.inl, by simp [←s.condition]⟩)
lemma has_pushout_of_right_iso : has_pushout f g :=
⟨⟨⟨_, pushout_cocone_of_right_iso_is_limit f g⟩⟩⟩
local attribute [instance] has_pushout_of_right_iso
instance pushout_inl_iso_of_right_iso : is_iso (pushout.inl : _ ⟶ pushout f g) :=
begin
refine ⟨⟨pushout.desc (𝟙 _) (inv g ≫ f) (by simp), (by simp), _⟩⟩,
ext,
{ simp [←pushout.condition] },
{ simp [pushout.condition] },
end
variables (h : W ⟶ X) [epi h]
instance has_pushout_of_left_factors_epi (f : X ⟶ Y) : has_pushout (h ≫ f) h :=
by { conv { congr, skip, rw ←category.comp_id h, }, apply_instance }
instance pushout_inl_iso_of_left_factors_epi (f : X ⟶ Y) :
is_iso (pushout.inl : _ ⟶ pushout (h ≫ f) h) :=
begin
convert (congr_arg is_iso (show pushout.inl ≫ _ = _,
from colimit.iso_colimit_cocone_ι_inv ⟨_, pushout_is_pushout_of_epi_comp f (𝟙 _) h⟩
walking_span.left)).mp infer_instance;
exact (category.comp_id _).symm
end
end pushout_right_iso
section
open walking_cospan
variable (f : X ⟶ Y)
instance has_kernel_pair_of_mono [mono f] : has_pullback f f :=
⟨⟨⟨_, pullback_cone.is_limit_mk_id_id f⟩⟩⟩
lemma fst_eq_snd_of_mono_eq [mono f] : (pullback.fst : pullback f f ⟶ _) = pullback.snd :=
((pullback_cone.is_limit_mk_id_id f).fac (get_limit_cone (cospan f f)).cone left).symm.trans
((pullback_cone.is_limit_mk_id_id f).fac (get_limit_cone (cospan f f)).cone right : _)
@[simp] lemma pullback_symmetry_hom_of_mono_eq [mono f] :
(pullback_symmetry f f).hom = 𝟙 _ := by ext; simp [fst_eq_snd_of_mono_eq]
instance fst_iso_of_mono_eq [mono f] : is_iso (pullback.fst : pullback f f ⟶ _) :=
begin
refine ⟨⟨pullback.lift (𝟙 _) (𝟙 _) (by simp), _, by simp⟩⟩,
ext,
{ simp },
{ simp [fst_eq_snd_of_mono_eq] }
end
instance snd_iso_of_mono_eq [mono f] : is_iso (pullback.snd : pullback f f ⟶ _) :=
by { rw ← fst_eq_snd_of_mono_eq, apply_instance }
end
section
open walking_span
variable (f : X ⟶ Y)
instance has_cokernel_pair_of_epi [epi f] : has_pushout f f :=
⟨⟨⟨_, pushout_cocone.is_colimit_mk_id_id f⟩⟩⟩
lemma inl_eq_inr_of_epi_eq [epi f] : (pushout.inl : _ ⟶ pushout f f) = pushout.inr :=
((pushout_cocone.is_colimit_mk_id_id f).fac
(get_colimit_cocone (span f f)).cocone left).symm.trans
((pushout_cocone.is_colimit_mk_id_id f).fac
(get_colimit_cocone (span f f)).cocone right : _)
@[simp] lemma pullback_symmetry_hom_of_epi_eq [epi f] :
(pushout_symmetry f f).hom = 𝟙 _ := by ext; simp [inl_eq_inr_of_epi_eq]
instance inl_iso_of_epi_eq [epi f] : is_iso (pushout.inl : _ ⟶ pushout f f) :=
begin
refine ⟨⟨pushout.desc (𝟙 _) (𝟙 _) (by simp), by simp, _⟩⟩,
ext,
{ simp },
{ simp [inl_eq_inr_of_epi_eq] }
end
instance inr_iso_of_epi_eq [epi f] : is_iso (pushout.inr : _ ⟶ pushout f f) :=
by { rw ← inl_eq_inr_of_epi_eq, apply_instance }
end
section paste_lemma
variables {X₁ X₂ X₃ Y₁ Y₂ Y₃ : C} (f₁ : X₁ ⟶ X₂) (f₂ : X₂ ⟶ X₃) (g₁ : Y₁ ⟶ Y₂) (g₂ : Y₂ ⟶ Y₃)
variables (i₁ : X₁ ⟶ Y₁) (i₂ : X₂ ⟶ Y₂) (i₃ : X₃ ⟶ Y₃)
variables (h₁ : i₁ ≫ g₁ = f₁ ≫ i₂) (h₂ : i₂ ≫ g₂ = f₂ ≫ i₃)
/--
Given
X₁ - f₁ -> X₂ - f₂ -> X₃
| | |
i₁ i₂ i₃
∨ ∨ ∨
Y₁ - g₁ -> Y₂ - g₂ -> Y₃
Then the big square is a pullback if both the small squares are.
-/
def big_square_is_pullback (H : is_limit (pullback_cone.mk _ _ h₂))
(H' : is_limit (pullback_cone.mk _ _ h₁)) :
is_limit (pullback_cone.mk _ _ (show i₁ ≫ g₁ ≫ g₂ = (f₁ ≫ f₂) ≫ i₃,
by rw [← category.assoc, h₁, category.assoc, h₂, category.assoc])) :=
begin
fapply pullback_cone.is_limit_aux',
intro s,
have : (s.fst ≫ g₁) ≫ g₂ = s.snd ≫ i₃ := by rw [← s.condition, category.assoc],
rcases pullback_cone.is_limit.lift' H (s.fst ≫ g₁) s.snd this with ⟨l₁, hl₁, hl₁'⟩,
rcases pullback_cone.is_limit.lift' H' s.fst l₁ hl₁.symm with ⟨l₂, hl₂, hl₂'⟩,
use l₂,
use hl₂,
use show l₂ ≫ f₁ ≫ f₂ = s.snd, by { rw [← hl₁', ← hl₂', category.assoc], refl },
intros m hm₁ hm₂,
apply pullback_cone.is_limit.hom_ext H',
{ erw [hm₁, hl₂] },
{ apply pullback_cone.is_limit.hom_ext H,
{ erw [category.assoc, ← h₁, ← category.assoc, hm₁, ← hl₂,
category.assoc, category.assoc, h₁], refl },
{ erw [category.assoc, hm₂, ← hl₁', ← hl₂'] } }
end
/--
Given
X₁ - f₁ -> X₂ - f₂ -> X₃
| | |
i₁ i₂ i₃
∨ ∨ ∨
Y₁ - g₁ -> Y₂ - g₂ -> Y₃
Then the big square is a pushout if both the small squares are.
-/
def big_square_is_pushout (H : is_colimit (pushout_cocone.mk _ _ h₂))
(H' : is_colimit (pushout_cocone.mk _ _ h₁)) :
is_colimit (pushout_cocone.mk _ _ (show i₁ ≫ g₁ ≫ g₂ = (f₁ ≫ f₂) ≫ i₃,
by rw [← category.assoc, h₁, category.assoc, h₂, category.assoc])) :=
begin
fapply pushout_cocone.is_colimit_aux',
intro s,
have : i₁ ≫ s.inl = f₁ ≫ (f₂ ≫ s.inr) := by rw [s.condition, category.assoc],
rcases pushout_cocone.is_colimit.desc' H' s.inl (f₂ ≫ s.inr) this with ⟨l₁, hl₁, hl₁'⟩,
rcases pushout_cocone.is_colimit.desc' H l₁ s.inr hl₁' with ⟨l₂, hl₂, hl₂'⟩,
use l₂,
use show (g₁ ≫ g₂) ≫ l₂ = s.inl, by { rw [← hl₁, ← hl₂, category.assoc], refl },
use hl₂',
intros m hm₁ hm₂,
apply pushout_cocone.is_colimit.hom_ext H,
{ apply pushout_cocone.is_colimit.hom_ext H',
{ erw [← category.assoc, hm₁, hl₂, hl₁] },
{ erw [← category.assoc, h₂, category.assoc, hm₂, ← hl₂',
← category.assoc, ← category.assoc, ← h₂], refl } },
{ erw [hm₂, hl₂'] }
end
/--
Given
X₁ - f₁ -> X₂ - f₂ -> X₃
| | |
i₁ i₂ i₃
∨ ∨ ∨
Y₁ - g₁ -> Y₂ - g₂ -> Y₃
Then the left square is a pullback if the right square and the big square are.
-/
def left_square_is_pullback (H : is_limit (pullback_cone.mk _ _ h₂))
(H' : is_limit (pullback_cone.mk _ _ (show i₁ ≫ g₁ ≫ g₂ = (f₁ ≫ f₂) ≫ i₃,
by rw [← category.assoc, h₁, category.assoc, h₂, category.assoc]))) :
is_limit (pullback_cone.mk _ _ h₁) :=
begin
fapply pullback_cone.is_limit_aux',
intro s,
have : s.fst ≫ g₁ ≫ g₂ = (s.snd ≫ f₂) ≫ i₃ :=
by { rw [← category.assoc, s.condition, category.assoc, category.assoc, h₂] },
rcases pullback_cone.is_limit.lift' H' s.fst (s.snd ≫ f₂) this with ⟨l₁, hl₁, hl₁'⟩,
use l₁,
use hl₁,
split,
{ apply pullback_cone.is_limit.hom_ext H,
{ erw [category.assoc, ← h₁, ← category.assoc, hl₁, s.condition], refl },
{ erw [category.assoc, hl₁'], refl } },
{ intros m hm₁ hm₂,
apply pullback_cone.is_limit.hom_ext H',
{ erw [hm₁, hl₁] },
{ erw [hl₁', ← hm₂], exact (category.assoc _ _ _).symm } }
end
/--
Given
X₁ - f₁ -> X₂ - f₂ -> X₃
| | |
i₁ i₂ i₃
∨ ∨ ∨
Y₁ - g₁ -> Y₂ - g₂ -> Y₃
Then the right square is a pushout if the left square and the big square are.
-/
def right_square_is_pushout (H : is_colimit (pushout_cocone.mk _ _ h₁))
(H' : is_colimit (pushout_cocone.mk _ _ (show i₁ ≫ g₁ ≫ g₂ = (f₁ ≫ f₂) ≫ i₃,
by rw [← category.assoc, h₁, category.assoc, h₂, category.assoc]))) :
is_colimit (pushout_cocone.mk _ _ h₂) :=
begin
fapply pushout_cocone.is_colimit_aux',
intro s,
have : i₁ ≫ g₁ ≫ s.inl = (f₁ ≫ f₂) ≫ s.inr :=
by { rw [category.assoc, ← s.condition, ← category.assoc, ← category.assoc, h₁] },
rcases pushout_cocone.is_colimit.desc' H' (g₁ ≫ s.inl) s.inr this with ⟨l₁, hl₁, hl₁'⟩,
dsimp at *,
use l₁,
refine ⟨_,_,_⟩,
{ apply pushout_cocone.is_colimit.hom_ext H,
{ erw [← category.assoc, hl₁], refl },
{ erw [← category.assoc, h₂, category.assoc, hl₁', s.condition] } },
{ exact hl₁' },
{ intros m hm₁ hm₂,
apply pushout_cocone.is_colimit.hom_ext H',
{ erw [hl₁, category.assoc, hm₁] },
{ erw [hm₂, hl₁'] } }
end
end paste_lemma
section
variables (f : X ⟶ Z) (g : Y ⟶ Z) (f' : W ⟶ X)
variables [has_pullback f g] [has_pullback f' (pullback.fst : pullback f g ⟶ _)]
variables [has_pullback (f' ≫ f) g]
/-- The canonical isomorphism `W ×[X] (X ×[Z] Y) ≅ W ×[Z] Y` -/
noncomputable
def pullback_right_pullback_fst_iso :
pullback f' (pullback.fst : pullback f g ⟶ _) ≅ pullback (f' ≫ f) g :=
begin
let := big_square_is_pullback
(pullback.snd : pullback f' (pullback.fst : pullback f g ⟶ _) ⟶ _) pullback.snd
f' f pullback.fst pullback.fst g pullback.condition pullback.condition
(pullback_is_pullback _ _) (pullback_is_pullback _ _),
exact (this.cone_point_unique_up_to_iso (pullback_is_pullback _ _) : _)
end
@[simp, reassoc]
lemma pullback_right_pullback_fst_iso_hom_fst :
(pullback_right_pullback_fst_iso f g f').hom ≫ pullback.fst = pullback.fst :=
is_limit.cone_point_unique_up_to_iso_hom_comp _ _ walking_cospan.left
@[simp, reassoc]
lemma pullback_right_pullback_fst_iso_hom_snd :
(pullback_right_pullback_fst_iso f g f').hom ≫ pullback.snd = pullback.snd ≫ pullback.snd :=
is_limit.cone_point_unique_up_to_iso_hom_comp _ _ walking_cospan.right
@[simp, reassoc]
lemma pullback_right_pullback_fst_iso_inv_fst :
(pullback_right_pullback_fst_iso f g f').inv ≫ pullback.fst = pullback.fst :=
is_limit.cone_point_unique_up_to_iso_inv_comp _ _ walking_cospan.left
@[simp, reassoc]
lemma pullback_right_pullback_fst_iso_inv_snd_snd :
(pullback_right_pullback_fst_iso f g f').inv ≫ pullback.snd ≫ pullback.snd = pullback.snd :=
is_limit.cone_point_unique_up_to_iso_inv_comp _ _ walking_cospan.right
@[simp, reassoc]
lemma pullback_right_pullback_fst_iso_inv_snd_fst :
(pullback_right_pullback_fst_iso f g f').inv ≫ pullback.snd ≫ pullback.fst = pullback.fst ≫ f' :=
begin
rw ← pullback.condition,
exact pullback_right_pullback_fst_iso_inv_fst_assoc _ _ _ _
end
end
section
variables (f : X ⟶ Y) (g : X ⟶ Z) (g' : Z ⟶ W)
variables [has_pushout f g] [has_pushout (pushout.inr : _ ⟶ pushout f g) g']
variables [has_pushout f (g ≫ g')]
/-- The canonical isomorphism `(Y ⨿[X] Z) ⨿[Z] W ≅ Y ×[X] W` -/
noncomputable
def pushout_left_pushout_inr_iso :
pushout (pushout.inr : _ ⟶ pushout f g) g' ≅ pushout f (g ≫ g') :=
((big_square_is_pushout g g' _ _ f _ _ pushout.condition pushout.condition
(pushout_is_pushout _ _) (pushout_is_pushout _ _))
.cocone_point_unique_up_to_iso (pushout_is_pushout _ _) : _)
@[simp, reassoc]
lemma inl_pushout_left_pushout_inr_iso_inv :
pushout.inl ≫ (pushout_left_pushout_inr_iso f g g').inv = pushout.inl ≫ pushout.inl :=
((big_square_is_pushout g g' _ _ f _ _ pushout.condition pushout.condition
(pushout_is_pushout _ _) (pushout_is_pushout _ _))
.comp_cocone_point_unique_up_to_iso_inv (pushout_is_pushout _ _) walking_span.left : _)
@[simp, reassoc]
lemma inr_pushout_left_pushout_inr_iso_hom :
pushout.inr ≫ (pushout_left_pushout_inr_iso f g g').hom = pushout.inr :=
((big_square_is_pushout g g' _ _ f _ _ pushout.condition pushout.condition
(pushout_is_pushout _ _) (pushout_is_pushout _ _))
.comp_cocone_point_unique_up_to_iso_hom (pushout_is_pushout _ _) walking_span.right : _)
@[simp, reassoc]
lemma inr_pushout_left_pushout_inr_iso_inv :
pushout.inr ≫ (pushout_left_pushout_inr_iso f g g').inv = pushout.inr :=
by rw [iso.comp_inv_eq, inr_pushout_left_pushout_inr_iso_hom]
@[simp, reassoc]
lemma inl_inl_pushout_left_pushout_inr_iso_hom :
pushout.inl ≫ pushout.inl ≫ (pushout_left_pushout_inr_iso f g g').hom = pushout.inl :=
by rw [← category.assoc, ← iso.eq_comp_inv, inl_pushout_left_pushout_inr_iso_inv]
@[simp, reassoc]
lemma inr_inl_pushout_left_pushout_inr_iso_hom :
pushout.inr ≫ pushout.inl ≫ (pushout_left_pushout_inr_iso f g g').hom = g' ≫ pushout.inr :=
by rw [← category.assoc, ← iso.eq_comp_inv, category.assoc,
inr_pushout_left_pushout_inr_iso_inv, pushout.condition]
end
section pullback_assoc
/-
The objects and morphisms are as follows:
Z₂ - g₄ -> X₃
| |
g₃ f₄
∨ ∨
Z₁ - g₂ -> X₂ - f₃ -> Y₂
| |
g₁ f₂
∨ ∨
X₁ - f₁ -> Y₁
where the two squares are pullbacks.
We can then construct the pullback squares
W - l₂ -> Z₂ - g₄ -> X₃
| |
l₁ f₄
∨ ∨
Z₁ - g₂ -> X₂ - f₃ -> Y₂
and
W' - l₂' -> Z₂
| |
l₁' g₃
∨ ∨
Z₁ X₂
| |
g₁ f₂
∨ ∨
X₁ - f₁ -> Y₁
We will show that both `W` and `W'` are pullbacks over `g₁, g₂`, and thus we may construct a
canonical isomorphism between them. -/
variables {X₁ X₂ X₃ Y₁ Y₂ : C} (f₁ : X₁ ⟶ Y₁) (f₂ : X₂ ⟶ Y₁) (f₃ : X₂ ⟶ Y₂)
variables (f₄ : X₃ ⟶ Y₂) [has_pullback f₁ f₂] [has_pullback f₃ f₄]
include f₁ f₂ f₃ f₄
local notation `Z₁` := pullback f₁ f₂
local notation `Z₂` := pullback f₃ f₄
local notation `g₁` := (pullback.fst : Z₁ ⟶ X₁)
local notation `g₂` := (pullback.snd : Z₁ ⟶ X₂)
local notation `g₃` := (pullback.fst : Z₂ ⟶ X₂)
local notation `g₄` := (pullback.snd : Z₂ ⟶ X₃)
local notation `W` := pullback (g₂ ≫ f₃) f₄
local notation `W'` := pullback f₁ (g₃ ≫ f₂)
local notation `l₁` := (pullback.fst : W ⟶ Z₁)
local notation `l₂` := (pullback.lift (pullback.fst ≫ g₂) pullback.snd
((category.assoc _ _ _).trans pullback.condition) : W ⟶ Z₂)
local notation `l₁'`:= (pullback.lift pullback.fst (pullback.snd ≫ g₃)
(pullback.condition.trans (category.assoc _ _ _).symm) : W' ⟶ Z₁)
local notation `l₂'`:= (pullback.snd : W' ⟶ Z₂)
/-- `(X₁ ×[Y₁] X₂) ×[Y₂] X₃` is the pullback `(X₁ ×[Y₁] X₂) ×[X₂] (X₂ ×[Y₂] X₃)`. -/
def pullback_pullback_left_is_pullback [has_pullback (g₂ ≫ f₃) f₄] :
is_limit (pullback_cone.mk l₁ l₂ (show l₁ ≫ g₂ = l₂ ≫ g₃, from (pullback.lift_fst _ _ _).symm)) :=
begin
apply left_square_is_pullback,
exact pullback_is_pullback f₃ f₄,
convert pullback_is_pullback (g₂ ≫ f₃) f₄,
rw pullback.lift_snd
end
/-- `(X₁ ×[Y₁] X₂) ×[Y₂] X₃` is the pullback `X₁ ×[Y₁] (X₂ ×[Y₂] X₃)`. -/
def pullback_assoc_is_pullback [has_pullback (g₂ ≫ f₃) f₄] :
is_limit (pullback_cone.mk (l₁ ≫ g₁) l₂ (show (l₁ ≫ g₁) ≫ f₁ = l₂ ≫ (g₃ ≫ f₂),
by rw [pullback.lift_fst_assoc, category.assoc, category.assoc, pullback.condition])) :=
begin
apply pullback_cone.flip_is_limit,
apply big_square_is_pullback,
{ apply pullback_cone.flip_is_limit,
exact pullback_is_pullback f₁ f₂ },
{ apply pullback_cone.flip_is_limit,
apply pullback_pullback_left_is_pullback },
{ exact pullback.lift_fst _ _ _ },
{ exact pullback.condition.symm }
end
lemma has_pullback_assoc [has_pullback (g₂ ≫ f₃) f₄] :
has_pullback f₁ (g₃ ≫ f₂) :=
⟨⟨⟨_, pullback_assoc_is_pullback f₁ f₂ f₃ f₄⟩⟩⟩
/-- `X₁ ×[Y₁] (X₂ ×[Y₂] X₃)` is the pullback `(X₁ ×[Y₁] X₂) ×[X₂] (X₂ ×[Y₂] X₃)`. -/
def pullback_pullback_right_is_pullback [has_pullback f₁ (g₃ ≫ f₂)] :
is_limit (pullback_cone.mk l₁' l₂' (show l₁' ≫ g₂ = l₂' ≫ g₃, from pullback.lift_snd _ _ _)) :=
begin
apply pullback_cone.flip_is_limit,
apply left_square_is_pullback,
{ apply pullback_cone.flip_is_limit,
exact pullback_is_pullback f₁ f₂ },
{ apply pullback_cone.flip_is_limit,
convert pullback_is_pullback f₁ (g₃ ≫ f₂),
rw pullback.lift_fst },
{ exact pullback.condition.symm }
end
/-- `X₁ ×[Y₁] (X₂ ×[Y₂] X₃)` is the pullback `(X₁ ×[Y₁] X₂) ×[Y₂] X₃`. -/
def pullback_assoc_symm_is_pullback [has_pullback f₁ (g₃ ≫ f₂)] :
is_limit (pullback_cone.mk l₁' (l₂' ≫ g₄) (show l₁' ≫ (g₂ ≫ f₃) = (l₂' ≫ g₄) ≫ f₄,
by rw [pullback.lift_snd_assoc, category.assoc, category.assoc, pullback.condition])) :=
begin
apply big_square_is_pullback,
exact pullback_is_pullback f₃ f₄,
apply pullback_pullback_right_is_pullback
end
lemma has_pullback_assoc_symm [has_pullback f₁ (g₃ ≫ f₂)] :
has_pullback (g₂ ≫ f₃) f₄ :=
⟨⟨⟨_, pullback_assoc_symm_is_pullback f₁ f₂ f₃ f₄⟩⟩⟩
variables [has_pullback (g₂ ≫ f₃) f₄] [has_pullback f₁ (g₃ ≫ f₂)]
/-- The canonical isomorphism `(X₁ ×[Y₁] X₂) ×[Y₂] X₃ ≅ X₁ ×[Y₁] (X₂ ×[Y₂] X₃)`. -/
noncomputable
def pullback_assoc :
pullback (pullback.snd ≫ f₃ : pullback f₁ f₂ ⟶ _) f₄ ≅
pullback f₁ (pullback.fst ≫ f₂ : pullback f₃ f₄ ⟶ _) :=
(pullback_pullback_left_is_pullback f₁ f₂ f₃ f₄).cone_point_unique_up_to_iso
(pullback_pullback_right_is_pullback f₁ f₂ f₃ f₄)
@[simp, reassoc]
lemma pullback_assoc_inv_fst_fst :
(pullback_assoc f₁ f₂ f₃ f₄).inv ≫ pullback.fst ≫ pullback.fst = pullback.fst :=
begin
transitivity l₁' ≫ pullback.fst,
rw ← category.assoc,
congr' 1,
exact is_limit.cone_point_unique_up_to_iso_inv_comp _ _ walking_cospan.left,
exact pullback.lift_fst _ _ _,
end
@[simp, reassoc]
lemma pullback_assoc_hom_fst :
(pullback_assoc f₁ f₂ f₃ f₄).hom ≫ pullback.fst = pullback.fst ≫ pullback.fst :=
by rw [← iso.eq_inv_comp, pullback_assoc_inv_fst_fst]
@[simp, reassoc]
lemma pullback_assoc_hom_snd_fst :
(pullback_assoc f₁ f₂ f₃ f₄).hom ≫ pullback.snd ≫ pullback.fst = pullback.fst ≫ pullback.snd :=
begin
transitivity l₂ ≫ pullback.fst,
rw ← category.assoc,
congr' 1,
exact is_limit.cone_point_unique_up_to_iso_hom_comp _ _ walking_cospan.right,
exact pullback.lift_fst _ _ _,
end
@[simp, reassoc]
lemma pullback_assoc_hom_snd_snd :
(pullback_assoc f₁ f₂ f₃ f₄).hom ≫ pullback.snd ≫ pullback.snd = pullback.snd :=
begin
transitivity l₂ ≫ pullback.snd,
rw ← category.assoc,
congr' 1,
exact is_limit.cone_point_unique_up_to_iso_hom_comp _ _ walking_cospan.right,
exact pullback.lift_snd _ _ _,
end
@[simp, reassoc]
lemma pullback_assoc_inv_fst_snd :
(pullback_assoc f₁ f₂ f₃ f₄).inv ≫ pullback.fst ≫ pullback.snd = pullback.snd ≫ pullback.fst :=
by rw [iso.inv_comp_eq, pullback_assoc_hom_snd_fst]
@[simp, reassoc]
lemma pullback_assoc_inv_snd :
(pullback_assoc f₁ f₂ f₃ f₄).inv ≫ pullback.snd = pullback.snd ≫ pullback.snd :=
by rw [iso.inv_comp_eq, pullback_assoc_hom_snd_snd]
end pullback_assoc
section pushout_assoc
/-
The objects and morphisms are as follows:
Z₂ - g₄ -> X₃
| |
g₃ f₄
∨ ∨
Z₁ - g₂ -> X₂ - f₃ -> Y₂
| |
g₁ f₂
∨ ∨
X₁ - f₁ -> Y₁
where the two squares are pushouts.
We can then construct the pushout squares
Z₁ - g₂ -> X₂ - f₃ -> Y₂
| |
g₁ l₂
∨ ∨
X₁ - f₁ -> Y₁ - l₁ -> W
and
Z₂ - g₄ -> X₃
| |
g₃ f₄
∨ ∨
X₂ Y₂
| |
f₂ l₂'
∨ ∨
Y₁ - l₁' -> W'
We will show that both `W` and `W'` are pushouts over `f₂, f₃`, and thus we may construct a
canonical isomorphism between them. -/
variables {X₁ X₂ X₃ Z₁ Z₂ : C} (g₁ : Z₁ ⟶ X₁) (g₂ : Z₁ ⟶ X₂) (g₃ : Z₂ ⟶ X₂)
variables (g₄ : Z₂ ⟶ X₃) [has_pushout g₁ g₂] [has_pushout g₃ g₄]
include g₁ g₂ g₃ g₄
local notation `Y₁` := pushout g₁ g₂
local notation `Y₂` := pushout g₃ g₄
local notation `f₁` := (pushout.inl : X₁ ⟶ Y₁)
local notation `f₂` := (pushout.inr : X₂ ⟶ Y₁)
local notation `f₃` := (pushout.inl : X₂ ⟶ Y₂)
local notation `f₄` := (pushout.inr : X₃ ⟶ Y₂)
local notation `W` := pushout g₁ (g₂ ≫ f₃)
local notation `W'` := pushout (g₃ ≫ f₂) g₄
local notation `l₁` := (pushout.desc pushout.inl (f₃ ≫ pushout.inr)
(pushout.condition.trans (category.assoc _ _ _)) : Y₁ ⟶ W)
local notation `l₂` := (pushout.inr : Y₂ ⟶ W)
local notation `l₁'`:= (pushout.inl : Y₁ ⟶ W')
local notation `l₂'`:= (pushout.desc (f₂ ≫ pushout.inl) pushout.inr
((category.assoc _ _ _).symm.trans pushout.condition) : Y₂ ⟶ W')
/-- `(X₁ ⨿[Z₁] X₂) ⨿[Z₂] X₃` is the pushout `(X₁ ⨿[Z₁] X₂) ×[X₂] (X₂ ⨿[Z₂] X₃)`. -/
def pushout_pushout_left_is_pushout [has_pushout (g₃ ≫ f₂) g₄] :
is_colimit (pushout_cocone.mk l₁' l₂'
(show f₂ ≫ l₁' = f₃ ≫ l₂', from (pushout.inl_desc _ _ _).symm)) :=
begin
apply pushout_cocone.flip_is_colimit,
apply right_square_is_pushout,
{ apply pushout_cocone.flip_is_colimit,
exact pushout_is_pushout _ _ },
{ apply pushout_cocone.flip_is_colimit,
convert pushout_is_pushout (g₃ ≫ f₂) g₄,
exact pushout.inr_desc _ _ _ },
{ exact pushout.condition.symm }
end
/-- `(X₁ ⨿[Z₁] X₂) ⨿[Z₂] X₃` is the pushout `X₁ ⨿[Z₁] (X₂ ⨿[Z₂] X₃)`. -/
def pushout_assoc_is_pushout [has_pushout (g₃ ≫ f₂) g₄] :
is_colimit (pushout_cocone.mk (f₁ ≫ l₁') l₂' (show g₁ ≫ (f₁ ≫ l₁') = (g₂ ≫ f₃) ≫ l₂',
by rw [category.assoc, pushout.inl_desc, pushout.condition_assoc])) :=
begin
apply big_square_is_pushout,
{ apply pushout_pushout_left_is_pushout },
{ exact pushout_is_pushout _ _ }
end
lemma has_pushout_assoc [has_pushout (g₃ ≫ f₂) g₄] :
has_pushout g₁ (g₂ ≫ f₃) :=
⟨⟨⟨_, pushout_assoc_is_pushout g₁ g₂ g₃ g₄⟩⟩⟩
/-- `X₁ ⨿[Z₁] (X₂ ⨿[Z₂] X₃)` is the pushout `(X₁ ⨿[Z₁] X₂) ×[X₂] (X₂ ⨿[Z₂] X₃)`. -/
def pushout_pushout_right_is_pushout [has_pushout g₁ (g₂ ≫ f₃)] :
is_colimit (pushout_cocone.mk l₁ l₂ (show f₂ ≫ l₁ = f₃ ≫ l₂, from pushout.inr_desc _ _ _)) :=
begin
apply right_square_is_pushout,
{ exact pushout_is_pushout _ _ },
{ convert pushout_is_pushout g₁ (g₂ ≫ f₃),
rw pushout.inl_desc }
end
/-- `X₁ ⨿[Z₁] (X₂ ⨿[Z₂] X₃)` is the pushout `(X₁ ⨿[Z₁] X₂) ⨿[Z₂] X₃`. -/
def pushout_assoc_symm_is_pushout [has_pushout g₁ (g₂ ≫ f₃)] :
is_colimit (pushout_cocone.mk l₁ (f₄ ≫ l₂) ((show (g₃ ≫ f₂) ≫ l₁ = g₄ ≫ (f₄ ≫ l₂),
by rw [category.assoc, pushout.inr_desc, pushout.condition_assoc]))) :=
begin
apply pushout_cocone.flip_is_colimit,
apply big_square_is_pushout,
{ apply pushout_cocone.flip_is_colimit,
apply pushout_pushout_right_is_pushout },
{ apply pushout_cocone.flip_is_colimit,
exact pushout_is_pushout _ _ },
{ exact pushout.condition.symm },
{ exact (pushout.inr_desc _ _ _).symm }
end
lemma has_pushout_assoc_symm [has_pushout g₁ (g₂ ≫ f₃)] :
has_pushout (g₃ ≫ f₂) g₄ :=
⟨⟨⟨_, pushout_assoc_symm_is_pushout g₁ g₂ g₃ g₄⟩⟩⟩
variables [has_pushout (g₃ ≫ f₂) g₄] [has_pushout g₁ (g₂ ≫ f₃)]
/-- The canonical isomorphism `(X₁ ⨿[Z₁] X₂) ⨿[Z₂] X₃ ≅ X₁ ⨿[Z₁] (X₂ ⨿[Z₂] X₃)`. -/
noncomputable
def pushout_assoc :
pushout (g₃ ≫ pushout.inr : _ ⟶ pushout g₁ g₂) g₄ ≅
pushout g₁ (g₂ ≫ pushout.inl : _ ⟶ pushout g₃ g₄) :=
(pushout_pushout_left_is_pushout g₁ g₂ g₃ g₄).cocone_point_unique_up_to_iso
(pushout_pushout_right_is_pushout g₁ g₂ g₃ g₄)
@[simp, reassoc]
lemma inl_inl_pushout_assoc_hom :
pushout.inl ≫ pushout.inl ≫ (pushout_assoc g₁ g₂ g₃ g₄).hom = pushout.inl :=
begin
transitivity f₁ ≫ l₁,
{ congr' 1,
exact (pushout_pushout_left_is_pushout g₁ g₂ g₃ g₄)
.comp_cocone_point_unique_up_to_iso_hom _ walking_cospan.left },
{ exact pushout.inl_desc _ _ _ }
end
@[simp, reassoc]
lemma inr_inl_pushout_assoc_hom :
pushout.inr ≫ pushout.inl ≫ (pushout_assoc g₁ g₂ g₃ g₄).hom = pushout.inl ≫ pushout.inr :=
begin
transitivity f₂ ≫ l₁,
{ congr' 1,
exact (pushout_pushout_left_is_pushout g₁ g₂ g₃ g₄)
.comp_cocone_point_unique_up_to_iso_hom _ walking_cospan.left },
{ exact pushout.inr_desc _ _ _ }
end
@[simp, reassoc]
lemma inr_inr_pushout_assoc_inv :
pushout.inr ≫ pushout.inr ≫ (pushout_assoc g₁ g₂ g₃ g₄).inv = pushout.inr :=
begin
transitivity f₄ ≫ l₂',
{ congr' 1,
exact (pushout_pushout_left_is_pushout g₁ g₂ g₃ g₄).comp_cocone_point_unique_up_to_iso_inv
(pushout_pushout_right_is_pushout g₁ g₂ g₃ g₄) walking_cospan.right },
{ exact pushout.inr_desc _ _ _ }
end
@[simp, reassoc]
lemma inl_pushout_assoc_inv :
pushout.inl ≫ (pushout_assoc g₁ g₂ g₃ g₄).inv = pushout.inl ≫ pushout.inl :=
by rw [iso.comp_inv_eq, category.assoc, inl_inl_pushout_assoc_hom]
@[simp, reassoc]
lemma inl_inr_pushout_assoc_inv :
pushout.inl ≫ pushout.inr ≫ (pushout_assoc g₁ g₂ g₃ g₄).inv = pushout.inr ≫ pushout.inl :=
by rw [← category.assoc, iso.comp_inv_eq, category.assoc, inr_inl_pushout_assoc_hom]
@[simp, reassoc]
lemma inr_pushout_assoc_hom :
pushout.inr ≫ (pushout_assoc g₁ g₂ g₃ g₄).hom = pushout.inr ≫ pushout.inr :=
by rw [← iso.eq_comp_inv, category.assoc, inr_inr_pushout_assoc_inv]
end pushout_assoc
variables (C)
/--
`has_pullbacks` represents a choice of pullback for every pair of morphisms
See <https://stacks.math.columbia.edu/tag/001W>
-/
abbreviation has_pullbacks := has_limits_of_shape walking_cospan C
/-- `has_pushouts` represents a choice of pushout for every pair of morphisms -/
abbreviation has_pushouts := has_colimits_of_shape walking_span C
/-- If `C` has all limits of diagrams `cospan f g`, then it has all pullbacks -/
lemma has_pullbacks_of_has_limit_cospan
[Π {X Y Z : C} {f : X ⟶ Z} {g : Y ⟶ Z}, has_limit (cospan f g)] :
has_pullbacks C :=
{ has_limit := λ F, has_limit_of_iso (diagram_iso_cospan F).symm }
/-- If `C` has all colimits of diagrams `span f g`, then it has all pushouts -/
lemma has_pushouts_of_has_colimit_span
[Π {X Y Z : C} {f : X ⟶ Y} {g : X ⟶ Z}, has_colimit (span f g)] :
has_pushouts C :=
{ has_colimit := λ F, has_colimit_of_iso (diagram_iso_span F) }
/-- The duality equivalence `walking_spanᵒᵖ ≌ walking_cospan` -/
@[simps]
def walking_span_op_equiv : walking_spanᵒᵖ ≌ walking_cospan :=
wide_pushout_shape_op_equiv _
/-- The duality equivalence `walking_cospanᵒᵖ ≌ walking_span` -/
@[simps]
def walking_cospan_op_equiv : walking_cospanᵒᵖ ≌ walking_span :=
wide_pullback_shape_op_equiv _
/-- Having wide pullback at any universe level implies having binary pullbacks. -/
@[priority 100] -- see Note [lower instance priority]
instance has_pullbacks_of_has_wide_pullbacks [has_wide_pullbacks.{w} C] : has_pullbacks C :=
begin
haveI := has_wide_pullbacks_shrink.{0 w} C,
apply_instance
end
variable {C}
/-- Given a morphism `f : X ⟶ Y`, we can take morphisms over `Y` to morphisms over `X` via
pullbacks. This is right adjoint to `over.map` (TODO) -/
@[simps obj_left obj_hom map_left {rhs_md := semireducible, simp_rhs := tt}]
def base_change [has_pullbacks C] {X Y : C} (f : X ⟶ Y) : over Y ⥤ over X :=
{ obj := λ g, over.mk (pullback.snd : pullback g.hom f ⟶ _),
map := λ g₁ g₂ i, over.hom_mk (pullback.map _ _ _ _ i.left (𝟙 _) (𝟙 _) (by simp) (by simp))
(by simp) }
end category_theory.limits
|
84e587e6117676e0c3fe9055320a723fda48e187 | 43390109ab88557e6090f3245c47479c123ee500 | /src/Geometry/tarski_6.lean | 7bb9cfee7b50fadc99a08c3b5eefbb6083dbdcbd | [
"Apache-2.0"
] | permissive | Ja1941/xena-UROP-2018 | 41f0956519f94d56b8bf6834a8d39473f4923200 | b111fb87f343cf79eca3b886f99ee15c1dd9884b | refs/heads/master | 1,662,355,955,139 | 1,590,577,325,000 | 1,590,577,325,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 45,614 | lean | import geometry.tarski_5
open classical set
namespace Euclidean_plane
variables {point : Type} [Euclidean_plane point]
local attribute [instance, priority 0] prop_decidable
theorem eleven22a {a b c p a' b' c' p' : point} : Bl a (l b p) c → Bl a' (l b' p') c' → eqa a b p a' b' p' →
eqa p b c p' b' c' → eqa a b c a' b' c' :=
begin
intros h h1 h2 h3,
cases h.2.2.2 with d h4,
cases exists_of_exists_unique (six11 h2.2.2.1 h2.1.symm) with a₁ ha,
suffices : ∃ d₁, col b' p' d₁ ∧ (B p' b' d₁ ↔ B p b d) ∧ eqd b' d₁ b d,
cases this with d₁ hd,
cases seg_cons d₁ d c a₁ with c₁ hc,
have h5 : eqd a d a₁ d₁,
by_cases h_1 : d = b,
subst d,
have h_1 : b' = d₁,
exact id_eqd hd.2.2,
subst d₁,
exact ha.2.symm.flip,
have h_2 : d₁ ≠ b',
intro h_2,
subst d₁,
exact h_1 (id_eqd hd.2.2.symm.flip),
suffices : eqa a b d a' b' d₁,
rw eleven4 at this,
apply this.2.2.2.2 (six5 h2.1) (six5 h_1) ha.1 (six5 h_2) ha.2.symm hd.2.2.symm,
by_cases h_3 : B p b d,
exact (eleven13 h2.flip h_1 h_3 h_2 (hd.2.1.2 h_3)).flip,
have h4 := six4.2 ⟨(four11 h4.1).2.1, h_3⟩,
have h5 : ¬B p' b' d₁,
intro h_4,
exact h_3 (hd.2.1.1 h_4),
have h6 := six4.2 ⟨(four11 hd.1).2.1, h5⟩,
exact eleven10 h2 (six5 h2.1) h4.symm (six5 ha.1.2.1) h6.symm,
have h6 : eqd b c b' c₁,
apply (afive_seg ⟨h4.2, hc.1, h5, hc.2.symm, ha.2.symm.flip, hd.2.2.symm.flip⟩ _).flip,
intro h_1,
subst d,
exact h.2.1 h4.1,
have h7 : eqa a b c a₁ b' c₁,
apply eleven3.2 ⟨a, c, a₁, c₁, six5 h2.1, six5 h3.2.1, six5 ha.1.1, _⟩,
split,
apply six5 (two7 h6.flip h3.2.1),
refine ⟨ha.2.symm.flip, h6, _⟩,
exact two11 h4.2 hc.1 h5 hc.2.symm,
apply eleven10 h7 (six5 h2.1) (six5 h3.2.1) ha.1.symm,
have h8 : eqa p b c p' b' c₁,
by_cases h_1 : d = b,
subst d,
have h_1 : b' = d₁,
exact id_eqd hd.2.2,
subst d₁,
apply (eleven13 _ h3.2.1 h4.2 (two7 hc.2.symm.flip h3.2.1) hc.1).flip,
exact eleven10 h2 (six5 h2.1) (six5 h2.2.1) ha.1 (six5 h3.2.2.1),
have h_2 : d₁ ≠ b',
intro h_2,
subst d₁,
exact h_1 (id_eqd hd.2.2.symm.flip),
suffices : eqa d b c d₁ b' c₁,
by_cases h_3 : B p b d,
exact (eleven13 this h2.2.1 h_3.symm h2.2.2.2.1 (hd.2.1.2 h_3).symm),
have h8 := six4.2 ⟨(four11 h4.1).2.1, h_3⟩,
have h9 : ¬B p' b' d₁,
intro h_4,
exact h_3 (hd.2.1.1 h_4),
have h10 := six4.2 ⟨(four11 hd.1).2.1, h9⟩,
exact eleven10 this h8 (six5 this.2.1) h10 (six5 this.2.2.2.1),
apply eleven3.2 ⟨d, c, d₁, c₁, six5 h_1, six5 h3.2.1, six5 h_2, (six5 h7.2.2.2.1), _⟩,
exact ⟨hd.2.2.symm.flip, h6, hc.2.symm⟩,
have h9 : a₁ ∉ l b' p',
intro h_1,
apply h1.2.1,
exact six20 h1.1 (six17a b' p') h_1 ha.1.1.symm (four11 (six4.1 ha.1).1).2.1,
have h10 : c₁ ∉ l b' p',
intro h_1,
apply h9,
apply six20 h1.1 h_1 hd.1 _ (or.inl hc.1.symm),
apply two7 hc.2.symm.flip,
intro h_2,
subst d,
exact h.2.2.1 h4.1,
have h11 : side (l b' p') c' c₁,
refine ⟨a₁, (nine5 h1 (six17a b' p') ha.1.symm).symm, _⟩,
split,
exact h1.1,
refine ⟨h10, h9, _⟩,
exact ⟨d₁, hd.1, hc.1.symm⟩,
rw six17 at h,
rw six17 at h10,
rw six17 at h11,
apply eleven15b h.2.2.1 h10 h3 h11 h8,
rw six17 b' p' at *,
exact side.refl h1.1 h10,
by_cases h_1 : B p b d,
simp [h_1],
cases seg_cons b' b d p' with d₁ hd,
exact ⟨d₁, or.inr (or.inr hd.1.symm), hd.1, hd.2⟩,
simp [h_1],
have h5 : sided b p d,
exact six4.2 ⟨(four11 h4.1).2.1, h_1⟩,
cases exists_of_exists_unique (six11 h3.2.2.1 h5.2.1.symm) with d₁ hd,
exact ⟨d₁, (four11 (six4.1 hd.1).1).2.2.1, (six4.1 hd.1.symm).2, hd.2⟩
end
theorem eleven22b {a b c p a' b' c' p' : point} : side (l b p) a c → side (l b' p') a' c' → eqa a b p a' b' p' →
eqa p b c p' b' c' → eqa a b c a' b' c' :=
begin
intros h h1 h2 h3,
apply eleven13 _ h2.1 (seven5 b a).1.symm h2.2.2.1 (seven5 b' a').1.symm,
have h4 : Bl a (l b p) (S b a),
refine ⟨(nine11 h).1, (nine11 h).2.1, _, b, (six17a b p), (seven5 b a).1⟩,
intro h_1,
exact (nine11 h).2.1 ((seven24 (nine11 h).1 (six17a b p)).2 h_1),
have h5 : Bl a' (l b' p') (S b' a'),
refine ⟨(nine11 h1).1, (nine11 h1).2.1, _, b', (six17a b' p'), (seven5 b' a').1⟩,
intro h_1,
exact (nine11 h1).2.1 ((seven24 (nine11 h1).1 (six17a b' p')).2 h_1),
apply (eleven22a _ _ (eleven13 h2 (seven12a h2.1) ((seven5 b a).1) (seven12a h2.2.2.1) (seven5 b' a').1) h3),
exact ((nine8 h4).2 h).symm,
exact ((nine8 h5).2 h1).symm
end
def I (p a b c : point) : Prop := a ≠ b ∧ c ≠ b ∧ p ≠ b ∧ (B a b c ∨ ∃ x, B a x c ∧ sided b x p)
theorem eleven23a {a b c p : point} : I p a b c → B a b c ∨ ∃ q, a ≠ b ∧ c ≠ b ∧ q ≠ b ∧ B a q c ∧ sided b q p :=
begin
intro h,
cases h.2.2.2,
exact or.inl h_1,
cases h_1 with q hq,
exact or.inr ⟨q, h.1, h.2.1, hq.2.1, hq.1, hq.2⟩
end
theorem eleven23b {p a b c : point} : ¬B a b c → I p a b c → a ≠ b ∧ c ≠ b ∧ p ≠ b ∧ ∃ x, B a x c ∧ sided b x p :=
begin
intros h h1,
unfold I at h1,
simpa [h] using h1
end
theorem I.symm {p a b c : point} : I p a b c → I p c b a :=
begin
intro h,
refine ⟨h.2.1, h.1, h.2.2.1, _⟩,
cases h.2.2.2,
exact or.inl h_1.symm,
right,
cases h_1 with x hx,
exact ⟨x, hx.1.symm, hx.2⟩
end
theorem eleven25 {p a b c a' c' p' : point} : I p a b c → sided b a' a → sided b c' c → sided b p' p → I p' a' b c' :=
begin
intros h h1 h2 h3,
by_cases h_1 : B a b c,
exact ⟨h1.1, h2.1, h3.1, or.inl (six8 h1 h2 h_1)⟩,
replace h := eleven23b h_1 h,
cases h.2.2.2 with x hx,
have h4 : ∃ x', B c x' a' ∧ sided b x' x,
cases h1.2.2,
cases pasch h_2 hx.1.symm with x' hx',
refine ⟨x', hx'.1.symm, _⟩,
apply six7 hx'.2.symm,
intro h_3,
subst x',
exact h_1 (six6 hx'.1.symm h1).symm,
cases nine6 h_2.symm hx.1.symm with x' hx',
exact ⟨x', hx'.1.symm, (six7 hx'.2 hx.2.1).symm⟩,
cases h4 with x' hx',
have h5 : ∃ y, B a' y c' ∧ sided b x' y,
cases h2.2.2,
cases pasch h_2 hx'.1.symm with y hy,
refine ⟨y, hy.1.symm, _⟩,
apply (six7 hy.2.symm _).symm,
intro h_3,
subst y,
exact h_1 (six8 h1.symm h2.symm hy.1.symm),
cases nine6 h_2.symm hx'.1.symm with y hy,
exact ⟨y, hy.1.symm, (six7 hy.2 hx'.2.1)⟩,
cases h5 with y hy,
refine ⟨h1.1, h2.1, h3.1, or.inr ⟨y, hy.1,_⟩⟩,
exact hy.2.symm.trans (hx'.2.trans (hx.2.trans h3.symm))
end
theorem eleven26a {a b c : point} : a ≠ b → c ≠ b → I a a b c :=
λ h h1, ⟨h, h1, h, or.inr ⟨a, three3 a c, six5 h⟩⟩
theorem eleven26b {a b c : point} : a ≠ b → c ≠ b → I c a b c :=
λ h h1, ⟨h, h1, h1, or.inr ⟨c, three1 a c, six5 h1⟩⟩
lemma eleven28 {a b c d a' b' c' : point} : cong a b c a' b' c' → col a c d →
∃ d', eqd a d a' d' ∧ eqd b d b' d' ∧ eqd c d c' d' :=
begin
intros h h1,
by_cases h_1 : a = c,
subst c,
have h_1 : a' = c',
exact id_eqd h.2.2.symm,
subst c',
by_cases h_1 : col a b d,
cases four14 h_1 h.1 with d' hd,
exact ⟨d', hd.2.2, hd.2.1, hd.2.2⟩,
have h_2 : a' ≠ b',
intro h_2,
subst b',
exact (six26 h_1).1 (id_eqd h.1),
cases six25 h_2 with p' hp,
cases exists_of_exists_unique (ten16 h_1 hp h.1) with d' hd,
exact ⟨d', hd.1.2.2, hd.1.2.1, hd.1.2.2⟩,
cases four14 h1 h.2.2 with d' hd,
exact ⟨d', hd.2.2, (four16 ⟨h1, hd, h.1, h.2.1.flip ⟩ h_1).flip, hd.2.1⟩
end
def ang_le (a b c d e f : point) : Prop := ∃ p, I p d e f ∧ eqa a b c d e p
theorem eleven31a {a b c d e f : point} : sided b a c → d ≠ e → f ≠ e → ang_le a b c d e f :=
λ h h1 h2, ⟨d, ⟨h1, h2, h1, or.inr ⟨d, three3 d f, six5 h1⟩⟩, (eleven21a h).2 (six5 h1)⟩
theorem eleven31b {a b c d e f : point} : a ≠ b → c ≠ b → d ≠ e → f ≠ e → B d e f → ang_le a b c d e f :=
begin
intros h h1 h2 h3 h4,
by_cases h_1 : col a b c,
cases six1 h_1,
exact ⟨f, ⟨h2, h3, h3, or.inl h4⟩, eleven21c h h1 h2 h3 h_2 h4⟩,
exact eleven31a h_2 h2 h3,
cases exists_of_exists_unique (six11 h h2.symm) with a' ha,
cases six25 h2 with x hx,
suffices : ¬col a' b c,
cases (exists_of_exists_unique (ten16 this hx ha.2.flip)) with p hp,
refine ⟨p, ⟨h2, h3, two7 hp.1.2.1.flip h1, or.inl h4⟩, _⟩,
exact (eleven9 ha.1 (six5 h1)).trans (eleven11 ha.1.1 h1 hp.1),
intro h_2,
exact h_1 (four11 (five4 ha.1.1.symm (four11 h_2).2.1 (four11 (six4.1 ha.1).1).2.1)).2.2.2.1
end
theorem eleven32a {a b c d e f : point} : ¬B a b c → ang_le d e f a b c → ∃ p, B a p c ∧ eqa d e f a b p :=
begin
rintro h ⟨x, h1, h2⟩,
cases (eleven23b h h1).2.2.2 with p hp,
refine ⟨p, hp.1, _⟩,
exact eleven10 h2 (six5 h2.1) (six5 h2.2.1) (six5 h2.2.2.1) hp.2
end
theorem eleven32b {a b c p : point} : a ≠ b → c ≠ b → p ≠ b → B a p c → ang_le a b p a b c :=
begin
intros h h1 h2 h3,
exact ⟨p, ⟨h, h1, h2, or.inr ⟨p, h3, six5 h2⟩⟩, eqa.refl h h2⟩
end
theorem eleven30 {a b c d e f a' b' c' d' e' f' : point} : ang_le a b c d e f → eqa a b c a' b' c' →
eqa d e f d' e' f' → ang_le a' b' c' d' e' f' :=
begin
rintro ⟨p, hp⟩ h1 h2,
rcases eleven5.1 h2 with ⟨d₁, f₁, hd, hf, h⟩,
cases hp.1.2.2.2,
exact eleven31b h1.2.2.1 h1.2.2.2.1 h2.2.2.1 h2.2.2.2.1 (eleven21b h_1 h2),
cases h_1 with x hx,
cases four5 hx.1 h.2.2 with y hy,
have h3 : eqd e x e' y,
apply (four2 ⟨hx.1, hy.1, h.2.2, hy.2.2.1, h.1, h.2.1.flip⟩).flip,
suffices : ang_le a b c d₁ e' f₁,
unfold ang_le at *,
cases this with r hr,
refine ⟨r, eleven25 hr.1 hd.symm hf.symm (six5 hr.1.2.2.1), _⟩,
exact h1.symm.trans (hr.2.trans (eleven9 hd.symm (six5 hr.1.2.2.1))),
refine ⟨y, ⟨hd.1, hf.1, two7 h3.flip hx.2.1, or.inr ⟨y, hy.1, six5 (two7 h3.flip hx.2.1)⟩⟩, _⟩,
apply hp.2.trans ((eleven9 (six5 h2.1) hx.2).trans (eleven11 h2.1 hx.2.1 ⟨h.1, h3, hy.2.1⟩))
end
theorem eleven29 {a b c d e f : point} : ang_le a b c d e f ↔ ∃ q, I c a b q ∧ eqa a b q d e f :=
begin
split,
rintro ⟨p, hp, h⟩,
by_cases h_1 : B d e f,
refine ⟨S b a, ⟨h.1, (seven12a h.1), h.2.1, or.inl (seven5 b a).1⟩, _⟩,
exact eleven21c h.1 (seven12a h.1) hp.1 hp.2.1 (seven5 b a).1 h_1,
unfold I at hp,
simp [h_1, - ne.def] at hp,
cases hp.2.2.2 with x hx,
have h1 : eqa a b c d e x,
exact eleven10 h (six5 h.1) (six5 h.2.1) (six5 h.2.2.1) hx.2,
rcases eleven5.1 h1.symm with ⟨a', c', h2, h3, h4⟩,
cases eleven28 h4 (or.inl hx.1) with q hq,
existsi q,
suffices : I c' a' b q ∧ eqa a' b q d e f,
refine ⟨eleven25 this.1 h2.symm (six5 this.1.2.1).symm h3.symm, _⟩,
exact eleven10 this.2 h2.symm (six5 this.2.2.1) (six5 this.2.2.2.1) (six5 this.2.2.2.2.1),
have h5 : B a' c' q,
exact four6 hx.1 ⟨h4.2.2, hq.2.2, hq.1⟩,
refine ⟨⟨h2.1, (two7 hq.2.1.flip hp.2.1), h3.1, or.inr ⟨c', h5, six5 h3.1⟩⟩, _⟩,
have h6 : eqa c' b q x e f,
exact eleven11 h3.1 (two7 hq.2.1.flip hp.2.1) ⟨h4.2.1.symm.flip, hq.2.1.symm, hq.2.2.symm⟩,
by_cases h_2 : col d e x,
have h7 : sided e d x,
apply six4.2 ⟨h_2, _⟩,
intro h_3,
exact h_1 (three6b h_3 hx.1),
apply eleven10 h6 _ (six5 h6.2.1) h7 (six5 h6.2.2.2.1),
exact six10a h7 ⟨h4.1.flip, h4.2.2, h4.2.1⟩,
by_cases h_3 : col x e f,
have h7 : sided e x f,
apply six4.2 ⟨h_3, _⟩,
intro h_4,
exact h_1 (three5b hx.1 h_4),
apply eleven10 (eleven11 h2.1 h3.1 h4.symm) (six5 h2.1) _ (six5 h.2.2.1) h7.symm,
exact six10a h7.symm ⟨hq.2.1, hq.2.2.flip, h4.2.1⟩,
apply eleven22a _ _ (eleven11 h2.1 h3.1 h4.symm) h6,
unfold Bl,
refine ⟨six14 h3.1.symm, _, _, c', six17b b c', h5⟩,
intro h_4,
exact h_2 (four13 (four11 h_4).2.2.2.1 h4.symm),
intro h_4,
exact h_3 (eleven21d (four11 h_4).2.1 h6),
refine ⟨six14 hx.2.1.symm, (four10 h_2).2.2.1, (four10 h_3).2.1, x, six17b e x, hx.1⟩,
rintro ⟨q, h, h1⟩,
apply eleven30 _ (eqa.refl h.1 h.2.2.1) h1,
exact ⟨c, h, (eqa.refl h.1 h.2.2.1)⟩
end
theorem eleven33 {a b c d e f : point} : ang_le a b c d e f → a ≠ b ∧ c ≠ b ∧ d ≠ e ∧ f ≠ e :=
λ ⟨p, hp⟩, ⟨hp.2.1, hp.2.2.1, hp.1.1, hp.1.2.1⟩
theorem eleven33a {a b c d e f : point} : ang_le a b c d e f → ang_le c b a d e f :=
λ h, have h1 : _ := eleven33 h, eleven30 h (eleven6 h1.1 h1.2.1) (eqa.refl h1.2.2.1 h1.2.2.2)
theorem eleven33b {a b c d e f : point} : ang_le a b c d e f → ang_le a b c f e d :=
λ h, have h1 : _ := eleven33 h, eleven30 h (eqa.refl h1.1 h1.2.1) (eleven6 h1.2.2.1 h1.2.2.2)
theorem ang_le.refl {a b c : point} : a ≠ b → c ≠ b → ang_le a b c a b c :=
λ h h1, ⟨c, eleven26b h h1, eqa.refl h h1⟩
theorem ang_le.trans {a b c d e f x y z : point} : ang_le a b c d e f → ang_le d e f x y z →
ang_le a b c x y z :=
begin
intros h h1,
rcases h1 with ⟨q, h2, h3⟩,
cases h2.2.2.2,
exact eleven31b (eleven33 h).1 (eleven33 h).2.1 h2.1 h2.2.1 h_1,
cases h_1 with r hr,
replace h3 := eleven10 h3 (six5 h3.1) (six5 h3.2.1) (six5 h3.2.2.1) hr.2,
replace h := eleven30 h (eqa.refl (eleven33 h).1 (eleven33 h).2.1) h3,
rcases h with ⟨s, hs, h4⟩,
cases hs.2.2.2,
exact eleven31b h4.1 h4.2.1 h2.1 h2.2.1 (three6b h hr.1),
cases h with p hp,
refine ⟨p, ⟨h2.1, h2.2.1, hp.2.1, or.inr ⟨p, three6b hp.1 hr.1, six5 hp.2.1⟩⟩, _⟩,
exact eleven10 h4 (six5 h4.1) (six5 h4.2.1) (six5 h4.2.2.1) hp.2
end
theorem ang_le.flip {a b c d e f : point} : ang_le a b c d e f → ang_le c b a f e d :=
λ h, eleven33b (eleven33a h)
theorem eleven34 {a b c d e f : point} : ang_le a b c d e f → ang_le d e f a b c → eqa a b c d e f :=
begin
rintro ⟨p, h, h1⟩ h2,
by_cases h_1 : B d e f,
apply eleven21c h1.1 h1.2.1 h.1 h.2.1 _ h_1,
rcases h2 with ⟨q, h2, h3⟩,
cases eleven23a h2,
exact h_2,
cases h_2 with r hr,
apply three6b (eleven21b h_1 _) hr.2.2.2.1,
exact eleven10 h3 (six5 h3.1) (six5 h3.2.1) (six5 h3.2.2.1) hr.2.2.2.2,
rcases eleven29.1 h2 with ⟨q, h4, h3⟩,
replace h2 := eleven23a h4,
clear h4,
cases h2,
exfalso,
cases (eleven23b h_1 h).2.2.2 with r hr,
exact h_1 (three6b (six6 (eleven21b h2 (h3.trans h1)) hr.2.symm) hr.1),
cases h2 with t ht,
have h4 : ¬B d e t,
intro h_2,
exact h_1 (six6 h_2 ht.2.2.2.2),
cases (eleven23b h4 (eleven25 h (six5 h.1) ht.2.2.2.2 (six5 h.2.2.1))).2.2.2 with r hr,
replace h1 := eleven10 h1 (six5 h1.1) (six5 h1.2.1) (six5 h1.2.2.1) hr.2,
apply eleven10 _ (six5 h3.2.2.1) (six5 h3.2.2.2.1) (six5 h3.1) ht.2.2.2.2.symm,
by_cases h_2 : col a b c,
cases six1 h_2,
apply eleven21c h1.1 h1.2.1 ht.1 ht.2.2.2.2.1 h_3,
exact three6b (eleven21b h_3 h1) hr.1,
exact (eleven21a h_3).2 (six6a ((eleven21a h_3).1 h3.symm) ht.2.2.2.1),
suffices : sided e r q,
apply eleven10 h1 (six5 h1.1) (six5 h1.2.1) (six5 h1.2.2.1) _,
exact (six6a this (three6a hr.1 ht.2.2.2.1)).symm,
have h5 : ¬col d e r,
intro h_3,
exact h_2 (eleven21d h_3 h1.symm),
apply eleven15b h_2 h5 h1 (side.refl (six14 ht.1) h5) h3.symm,
apply nine12 (six14 ht.1) (six17a d e) ((six7 (three6b hr.1 ht.2.2.2.1) (six26 h5).2.2.symm).symm),
intro h_3,
exact h5 (eleven21d h_3 (h3.trans h1))
end
theorem eleven35 {a b c d e f : point} : a ≠ b → c ≠ b → d ≠ e → f ≠ e → ang_le a b c d e f ∨ ang_le d e f a b c :=
begin
intros h h1 h2 h3,
by_cases h4 : col a b c,
cases six1 h4,
exact or.inr (eleven31b h2 h3 h h1 h_1),
exact or.inl (eleven31a h_1 h2 h3),
by_cases h5 : col d e f,
cases six1 h5,
exact or.inl (eleven31b h h1 h2 h3 h_1),
exact or.inr (eleven31a h_1 h h1),
rcases eleven15a h5 h4 with ⟨c', h6, hc⟩,
rw six17 at hc,
have h7 : c' ∈ pl (l b c) a,
suffices : pl (l b a) c = pl (l b c) a,
exact this ▸ (or.inl hc),
exact (nine24 (four10 h4).2.1).1,
cases h7,
cases (nine31 hc h7).2.2.2 with x hx,
refine or.inr ⟨c', ⟨h, h1, h6.2.2.2.1, or.inr ⟨x, hx.2, _⟩⟩, h6⟩,
apply (nine19 (six14 h.symm) (six17a b a) (four11 hx.1).2.2.2.2 _).1,
apply (nine19a hc (six17b b a) (six7 hx.2 _).symm).symm,
intro h_1,
subst x,
exact (nine11 hc).2.1 (four11 hx.1).1,
suffices : ∃ x, col b c x ∧ B c' x a,
cases this with x hx,
refine or.inl (eleven29.2 ⟨c', ⟨h, h6.2.2.2.1, h1, or.inr ⟨x, hx.2.symm, _⟩⟩, h6.symm⟩),
apply (nine19 (six14 h.symm) (six17a b a) (four11 hx.1).2.2.2.2 _).1,
apply (nine19a hc.symm (six17b b a) (six7 hx.2.symm _).symm).symm,
intro h_1,
subst x,
exact (nine11 hc).2.2 (four11 hx.1).1,
cases h7,
exact ⟨c', h7, three3 c' a⟩,
exact h7.symm.2.2.2
end
lemma eleven36a {a b c d e f a' d' : point} : a' ≠ b → d' ≠ e → B a b a' → B d e d' →
ang_le a b c d e f → ang_le d' e f a' b c :=
begin
intros h h1 h2 h3 h4,
by_cases h_1 : col a b c,
cases six1 h_1,
suffices : B d e f,
apply eleven31a _ h (eleven33 h4).2.1,
exact ⟨h1, (eleven33 h4).2.2.2, five2 (eleven33 h4).2.2.1 h3 this⟩,
exact eleven21b h_2 (eleven34 h4 (eleven31b (eleven33 h4).2.2.1 (eleven33 h4).2.2.2 (eleven33 h4).1 (eleven33 h4).2.1 h_2)),
apply eleven31b h1 (eleven33 h4).2.2.2 h (eleven33 h4).2.1 _,
exact six6 h2.symm h_2,
cases eleven29.1 h4 with p hp,
cases hp.1.2.2.2,
suffices : B d e f,
apply eleven31a _ h (eleven33 h4).2.1,
exact ⟨h1, (eleven33 h4).2.2.2, five2 (eleven33 h4).2.2.1 h3 this⟩,
exact eleven21b h_2 hp.2,
cases h_2 with y hy,
by_cases h_2 : y = p,
subst y,
apply eleven30 (ang_le.refl h (eleven33 h4).2.1) _ (eqa.refl h (eleven33 h4).2.1),
exact eleven13 (eleven10 hp.2 (six5 hp.2.1) hy.2.symm (six5 hp.2.2.2.1) (six5 hp.2.2.2.2.1)) h h2 h1 h3,
refine ⟨p, ⟨h, hp.1.2.2.1, hp.1.2.1, or.inr _⟩, (eleven13 hp.2 h h2 h1 h3).symm⟩,
have h5 : side (l b p) a c,
apply (nine19a _ (six17a b p) hy.2),
apply (nine12 (six14 hp.2.2.1.symm) (six17b b p) (six7 hy.1.symm h_2) _).symm,
intro h_3,
apply h_1 (six23.2 ⟨l b p, (six14 hp.2.2.1.symm), _, (six17a b p), _⟩),
rw (six18 (six14 hp.2.2.1.symm) h_2 h_3 (six17b b p)),
exact or.inr (or.inr hy.1),
rw (six18 (six14 hp.2.2.1.symm) hy.2.1 h_3 (six17a b p)),
exact (six4.1 hy.2).1,
have h6 : Bl c (l b p) a',
apply (nine8 ⟨(nine11 h5).1, (nine11 h5).2.1, _, ⟨b, (six17a b p), h2⟩⟩).2 h5,
intro h_3,
apply (nine11 h5).2.1,
rw (six18 ((nine11 h5).1) h h_3 (six17a b p)),
exact or.inl h2.symm,
cases h6.2.2.2 with x hx,
refine ⟨x, hx.2.symm, six4.2 ⟨(four11 hx.1).2.2.2.1, _⟩⟩,
intro h_3,
suffices : side (l a b) p c,
have h6 : side (l a b) p x,
apply nine19a this (or.inl h2) (six7 hx.2.symm _).symm,
intro h_4,
subst x,
exact h6.2.2.1 (or.inr (or.inr h_3)),
apply (nine9 _) h6,
exact ⟨(nine11 h6).1, (nine11 h6).2.1, (nine11 h6).2.2, ⟨b, (six17b a b), h_3.symm⟩⟩,
have h7 : side (l a b) c y,
exact nine12 (six14 (six26 h_1).1) (six17b a b) hy.2.symm h_1,
apply (nine19a h7 (six17a a b) _).symm,
apply (six7 hy.1 _),
intro h_4,
subst y,
exact (nine11 h7).2.2 (six17a a b)
end
theorem eleven36 {a b c d e f a' d' : point} : a ≠ b → a' ≠ b → d ≠ e → d' ≠ e → B a b a' → B d e d' →
(ang_le a b c d e f ↔ ang_le d' e f a' b c) :=
begin
intros h h1 h2 h3 h4 h5,
split,
intro h6,
exact eleven36a h1 h3 h4 h5 h6,
intro h6,
exact eleven36a h2 h h5.symm h4.symm h6
end
def ang_lt (a b c d e f : point) : Prop := ang_le a b c d e f ∧ ¬eqa a b c d e f
theorem ang_lt_or_eq_of_le {a b c d e f : point} : ang_le a b c d e f → (ang_lt a b c d e f ∨ eqa a b c d e f) :=
begin
intro h,
by_cases h1 : eqa a b c d e f,
exact or.inr h1,
exact or.inl ⟨h, h1⟩,
end
theorem ang_lt.flip {a b c d e f : point} : ang_lt a b c d e f → ang_lt c b a f e d :=
λ h, ⟨h.1.flip, λ h_1, h.2 h_1.flip⟩
theorem eleven32c {a b c d e f : point} : ¬B a b c → ang_lt d e f a b c → ∃ p, p ≠ c ∧ B a p c ∧ eqa d e f a b p :=
begin
rintro h ⟨h1, h2⟩,
cases eleven32a h h1 with p hp,
refine ⟨p, _, hp.1, hp.2⟩,
intro h_1,
subst p,
exact h2 hp.2
end
theorem eleven32d {a b c p : point} : ¬col a b c → p ≠ c → B a p c → ang_lt a b p a b c :=
begin
intros h h1 h2,
refine ⟨eleven32b (six26 h).1 (six26 h).2.1.symm _ h2, _⟩,
intro h_1,
subst p,
exact h (or.inl h2),
intro h_1,
by_cases h_2 : p = a,
subst p,
exact h (six4.1 ((eleven21a (six5 (six26 h).1)).1 h_1)).1,
have h3 : sided a c p,
exact (six7 h2 h_2).symm,
have h4 : side (l a b) c p,
exact nine12 (six14 (six26 h).1) (six17a a b) (six7 h2 h_2).symm h,
suffices : sided b c p,
exact (four10 h).2.2.2.1 (five4 h1.symm (or.inl h2.symm) (four11 (six4.1 this).1).1),
exact eleven15c h_1.symm h4
end
theorem eleven37 {a b c d e f a' b' c' d' e' f' : point} : ang_lt a b c d e f → eqa a b c a' b' c' →
eqa d e f d' e' f' → ang_lt a' b' c' d' e' f' :=
begin
rintro ⟨h, h1⟩ h2 h3,
refine ⟨eleven30 h h2 h3, _⟩,
intro h_1,
exact h1 (h2.trans (h_1.trans h3.symm))
end
theorem eleven37a {a b c d e f a' d' : point} : a' ≠ b → d' ≠ e → B a b a' → B d e d' →
ang_lt a b c d e f → ang_lt d' e f a' b c :=
begin
rintro h h1 h2 h3 h4,
refine ⟨eleven36a h h1 h2 h3 h4.1, _⟩,
intro h_1,
exact h4.2 (eleven13 h_1.symm (eleven33 h4.1).1 h2.symm (eleven33 h4.1).2.2.1 h3.symm)
end
theorem eleven38a {a b c d e f : point} : ang_lt a b c d e f ↔ a ≠ b ∧ c ≠ b ∧ d ≠ e ∧ f ≠ e ∧ ¬ang_le d e f a b c :=
begin
split,
rintro ⟨⟨p, h, h1⟩, h2⟩,
refine ⟨h1.1, h1.2.1, h1.2.2.1, h.2.1, _⟩,
intro h3,
exact h2 (eleven34 ⟨p, h, h1⟩ h3),
rintro ⟨h, h1, h2, h3, h4⟩,
split,
simpa [h4] using (eleven35 h h1 h2 h3),
intro h_1,
exact h4 (eleven30 (ang_le.refl h h1) h_1 (eqa.refl h h1))
end
theorem ang_lt_or_ge {a b c d e f : point} : a ≠ b → c ≠ b → d ≠ e → f ≠ e → (ang_lt a b c d e f ∨ ang_le d e f a b c) :=
begin
intros h h1 h2 h3,
by_cases h_1 : ang_le d e f a b c,
exact or.inr h_1,
exact or.inl (eleven38a.2 ⟨h, h1, h2, h3, h_1⟩)
end
theorem eleven38b {a b c d e f : point} : ang_lt a b c d e f → ang_lt d e f a b c → false :=
begin
intros h h1,
suffices : ¬ang_lt d e f a b c,
exact this h1,
intro h_1,
exact (eleven38a.1 h).2.2.2.2 h_1.1
end
theorem eleven39 {a b c d e f a' d' : point} : a ≠ b → a' ≠ b → d ≠ e → d' ≠ e → B a b a' → B d e d' →
(ang_lt a b c d e f ↔ ang_lt d' e f a' b c) :=
begin
intros h h1 h2 h3 h4 h5,
split,
intro h6,
refine ⟨(eleven36 h h1 h2 h3 h4 h5).1 h6.1, _⟩,
intro h_1,
exact h6.2 (eleven13 h_1.symm h h4.symm h2 h5.symm),
intro h6,
refine ⟨(eleven36 h h1 h2 h3 h4 h5).2 h6.1, _⟩,
intro h_1,
exact h6.2 (eleven13 h_1.symm h3 h5 h1 h4)
end
theorem ang_lt.trans {a b c d e f x y z : point} : ang_lt a b c d e f → ang_lt d e f x y z → ang_lt a b c x y z :=
begin
intros h h1,
refine ⟨ang_le.trans h.1 h1.1, _⟩,
intro h_1,
replace h1 := eleven37 h1 (eqa.refl (eleven38a.1 h1).1 (eleven38a.1 h1).2.1) h_1.symm,
exact eleven38b h h1
end
def ang_acute (a b c : point) : Prop := ∃ x y z, R x y z ∧ ang_lt a b c x y z
theorem tri_of_ang_acute {a b c : point} : ang_acute a b c → a ≠ b ∧ c ≠ b :=
λ ⟨x, y, z, h⟩, ⟨(eleven38a.1 h.2).1, (eleven38a.1 h.2).2.1⟩
theorem ang_acute.symm {a b c : point} : ang_acute a b c → ang_acute c b a :=
begin
rintro ⟨x, y, z, h, h1⟩,
refine ⟨x, y, z, h, (eleven37 h1 (eleven6 (eleven38a.1 h1).1 (eleven38a.1 h1).2.1) _)⟩,
exact (eqa.refl (eleven38a.1 h1).2.2.1 (eleven38a.1 h1).2.2.2.1)
end
theorem acute_of_sided {a b c : point} : sided b a c → ang_acute a b c :=
begin
intro h,
cases eight25 h.1 with d hd,
refine ⟨a, b, d, hd.1, eleven31a h h.1 hd.2, _⟩,
intro h1,
cases (eight9 hd.1 (six4.1 ((eleven21a h).1 h1)).1),
exact h.1 h_1,
exact hd.2 h_1
end
theorem sided_of_acute_col {a b c : point} : ang_acute a b c → col a b c → sided b a c :=
λ ⟨x, y, z, h⟩ h1, have h2 : _ := eleven38a.1 h.2,
(six1 h1).elim (λ h_1, (h2.2.2.2.2 (eleven31b h2.2.2.1 h2.2.2.2.1 h2.1 h2.2.1 h_1)).elim) id
def ang_obtuse (a b c : point) : Prop := ∃ x y z, R x y z ∧ ang_lt x y z a b c
theorem tri_of_ang_obtuse {a b c : point} : ang_obtuse a b c → a ≠ b ∧ c ≠ b ∧ a ≠ c :=
begin
rintro ⟨x, y, z, h⟩,
refine ⟨(eleven38a.1 h.2).2.2.1, (eleven38a.1 h.2).2.2.2.1, _⟩,
intro h_1,
subst c,
have h1 := eleven38a.1 h.2,
exact h1.2.2.2.2 (eleven31a (six5 h1.2.2.1) h1.1 h1.2.1)
end
theorem ang_obtuse.symm {a b c : point} : ang_obtuse a b c → ang_obtuse c b a :=
begin
rintro ⟨x, y, z, h, h1⟩,
refine ⟨x, y, z, h, (eleven37 h1 _ (eleven6 (eleven38a.1 h1).2.2.1 (eleven38a.1 h1).2.2.2.1))⟩,
exact (eqa.refl (eleven38a.1 h1).1 (eleven38a.1 h1).2.1)
end
theorem obtuse_of_B {a b c : point} : a ≠ b → c ≠ b → B a b c → ang_obtuse a b c :=
begin
intros h h1 h2,
cases eight25 h with d hd,
refine ⟨a, b, d, hd.1, eleven31b h hd.2 h h1 h2, _⟩,
intro h3,
cases (eight9 hd.1 (or.inl ((eleven21b h2) h3.symm))),
exact h h_1,
exact hd.2 h_1
end
theorem B_of_obtuse_col {a b c : point} : ang_obtuse a b c → col a b c → a ≠ b ∧ c ≠ b ∧ B a b c :=
begin
rintro ⟨x, y, z, h⟩ h1,
have h2 := eleven38a.1 h.2,
cases six1 h1,
exact ⟨h2.2.2.1, h2.2.2.2.1, h_1⟩,
exact (h2.2.2.2.2 (eleven31a h_1 h2.1 h2.2.1)).elim
end
theorem eleven40a {a b c d : point} : a ≠ b → c ≠ b → d ≠ b → B c b d → (ang_acute a b c ↔ ang_obtuse a b d) :=
begin
intros h h1 h2 h3,
split; rintro ⟨x, y, z, h4⟩,
exact ⟨x, y, S y z, h4.1.flip, (eleven37a h2 (seven12a (eleven33 h4.2.1).2.2.2) h3 (seven5 y z).1 h4.2.flip).flip⟩,
exact ⟨x, y, S y z, h4.1.flip, (eleven37a (seven12a (eleven33 h4.2.1).2.1) h1 (seven5 y z).1 h3.symm h4.2.flip).flip⟩
end
def ang_right (a b c : point) : Prop := a ≠ b ∧ c ≠ b ∧ R a b c
theorem ang_right.symm {a b c : point} : ang_right a b c → ang_right c b a :=
λ h, ⟨h.2.1, h.1, h.2.2.symm⟩
theorem ang_right.flip {a b c : point} : ang_right a b c → ang_right a b (S b c) :=
λ h, ⟨h.1, (seven12a h.2.1), h.2.2.flip⟩
theorem eleven16a {a b c d e f : point} : ang_right a b c → ang_right d e f → eqa a b c d e f :=
λ h h1, eleven16 h.1 h.2.1 h1.1 h1.2.1 h.2.2 h1.2.2
theorem eleven40b {a b c d : point} : a ≠ b → c ≠ b → d ≠ b → B c b d → (ang_right a b c ↔ ang_right a b d) :=
begin
intros h h1 h2 h3,
split; intro h4;
refine ⟨h, _, eleven17 h4.2.2.flip (eleven9 (six5 h) _)⟩; try {assumption},
exact (six2 h2 (seven12a h1) h1 h3.symm).1 (seven5 b c).1.symm,
exact (six2 h1 (seven12a h2) h2 h3).1 (seven5 b d).1.symm
end
theorem not_col_of_right {a b c : point} : ang_right a b c → ¬col a b c :=
λ h h1, (eight9 h.2.2 h1).elim h.1 h.2.1
theorem ang_acute.trans {a b c d e f : point} : ang_acute a b c → eqa a b c d e f → ang_acute d e f :=
λ ⟨x, y, z, h⟩ h1, ⟨x, y, z, h.1, eleven37 h.2 h1 (eqa.refl (eleven38a.1 h.2).2.2.1 (eleven38a.1 h.2).2.2.2.1)⟩
theorem ang_obtuse.trans {a b c d e f : point} : ang_obtuse a b c → eqa a b c d e f → ang_obtuse d e f :=
λ ⟨x, y, z, h⟩ h1, ⟨x, y, z, h.1, eleven37 h.2 (eqa.refl (eleven38a.1 h.2).1 (eleven38a.1 h.2).2.1) h1⟩
theorem ang_right.trans {a b c d e f : point} : ang_right a b c → eqa a b c d e f → ang_right d e f :=
λ h h1, ⟨h1.2.2.1, h1.2.2.2.1, eleven17 h.2.2 h1⟩
theorem lt_ang_right_of_ang_acute {a b c p q r : point} : ang_acute a b c → ang_right p q r → ang_lt a b c p q r :=
λ ⟨x, y, z, h⟩ h1, eleven37 h.2 (eqa.refl (eleven38a.1 h.2).1 (eleven38a.1 h.2).2.1)
(eleven16 (eleven38a.1 h.2).2.2.1 (eleven38a.1 h.2).2.2.2.1 h1.1 h1.2.1 h.1 h1.2.2)
theorem lt_ang_obtuse_of_ang_right {a b c p q r : point} : ang_right p q r → ang_obtuse a b c → ang_lt p q r a b c :=
λ h ⟨x, y, z, h1⟩, eleven37 h1.2 (eleven16 (eleven38a.1 h1.2).1 (eleven38a.1 h1.2).2.1 h.1 h.2.1 h1.1 h.2.2)
(eqa.refl (eleven38a.1 h1.2).2.2.1 (eleven38a.1 h1.2).2.2.2.1)
theorem lt_ang_obtuse_of_ang_acute {a b c d e f : point} : ang_acute a b c → ang_obtuse d e f → ang_lt a b c d e f :=
λ ⟨x, y, z, h⟩ h1, h.2.trans (lt_ang_obtuse_of_ang_right ⟨(eleven38a.1 h.2).2.2.1, (eleven38a.1 h.2).2.2.2.1, h.1⟩ h1)
theorem ang_total {a b c d e f : point} : a ≠ b → c ≠ b → d ≠ e → f ≠ e →
(ang_lt a b c d e f ∨ eqa a b c d e f ∨ ang_lt d e f a b c) :=
begin
intros h h1 h2 h3,
unfold ang_lt,
cases eleven35 h h1 h2 h3,
by_cases h_2 : eqa a b c d e f;
simp [h_1, h_2],
by_cases h_2 : eqa a b c d e f,
simp [h_2, h_1],
refine or.inr (or.inr ⟨h_1, _⟩),
intro h_3,
exact h_2 h_3.symm
end
theorem right_total {a b c : point} : a ≠ b → c ≠ b → (ang_acute a b c ∨ ang_right a b c ∨ ang_obtuse a b c) :=
begin
intros h h1,
cases eight25 h with t ht,
cases ang_lt_or_ge h h1 h ht.2,
exact or.inl ⟨a, b, t, ht.1, h_1⟩,
cases ang_lt_or_eq_of_le h_1,
exact or.inr (or.inr ⟨a, b, t, ht.1, h_2⟩),
exact or.inr (or.inl ⟨h, h1, (eleven17 ht.1 h_2)⟩)
end
lemma eleven41a {a b c d : point} : ¬col a b c → B b a d → d ≠ a → ang_lt a c b c a d :=
begin
intros h h1 h2,
generalize h3 : S (mid a c) b = p,
have h4 : eqa a c b c a p,
suffices : eqa a c b (S (mid a c) a) (S (mid a c) c) (S (mid a c) b),
rwa [h3, mid_to_Sa a c, mid.symm a c, mid_to_Sa c a] at this,
exact eleven12 (mid a c) (six26 h).2.2 (six26 h).2.1,
cases pasch h1.symm (seven5 (mid a c) b).1.symm with x hx,
rw h3 at hx,
have h5 : I p c a d,
suffices : I p (mid a c) a d,
apply eleven25 this (six7 (ten1 a c).1 _).symm (six5 this.2.1) (six5 this.2.2.1),
exact mid.neq (six26 h).2.2,
have h6 : x ≠ a,
intro h_1,
subst x,
apply h (six23.2 ⟨l d a, six14 h2,(six17b d a), or.inl h1.symm, _⟩),
exact or.inl (three7b hx.2.symm (ten1 a c).1 (mid.neq (six26 h).2.2).symm),
refine ⟨mid.neq (six26 h).2.2 , h2, _, or.inr ⟨x, hx.2, (six7 hx.1 h6)⟩⟩,
exact (six7 hx.1 h6).2.1,
refine ⟨⟨p, h5, h4⟩, _⟩,
intro h_1,
suffices h7 : side (l c a) d p,
suffices : ¬col d a p,
have h8 : ¬sided a d p,
intro h_2,
exact this (six4.1 h_2).1,
apply h8 (eleven15b (four10 h).1 (nine11 h7).2.1 h_1 _ h4 h7.symm),
exact side.trans h7 h7.symm,
intro h_2,
apply h (six23.2 ⟨l d a, six14 h2,(six17b d a), or.inl h1.symm, _⟩),
rw ←mid_to_Sa a c,
apply (seven24 (six14 h2) _).1 (six17b d a),
apply six27 (six14 h2) (or.inl h1.symm) h_2,
rw ←h3,
exact (seven5 (mid a c) b).1,
rw six17,
refine ⟨b, ⟨six14 (six26 h).2.2, _, (four10 h).1, ⟨a, (six17a a c), h1.symm⟩⟩, ⟨six14 (six26 h).2.2, _⟩⟩,
intro h_2,
exact h (six23.2 ⟨l d a, six14 h2,(six17b d a), or.inl h1.symm, (four11 h_2).2.2.2.1⟩),
subst p,
refine ⟨_, (four10 h).1, ⟨(mid a c), or.inr (or.inl (ten1 a c).1.symm), (seven5 (mid a c) b).1.symm⟩⟩,
intro h_2,
exact (four10 h).1 ((seven24 (six14 (six26 h).2.2) (or.inr (or.inl (ten1 a c).1.symm))).2 h_2),
end
theorem eleven41 {a b c d : point} : ¬col a b c → B b a d → d ≠ a → ang_lt a c b c a d ∧ ang_lt a b c c a d :=
begin
intros h h1 h2,
refine ⟨eleven41a h h1 h2, _⟩,
have h3 : eqa c a d b a (S a c),
apply ((eleven6 h2 (six26 h).2.2.symm).trans _).flip,
apply eleven14 (six26 h).2.2.symm h2 (seven12a (six26 h).2.2.symm) (six26 h).1.symm _ h1.symm,
exact (seven5 a c).1,
apply eleven37 _ (eqa.refl (six26 h).1 (six26 h).2.1.symm) h3.symm,
exact eleven41a (four10 h).1 (seven5 a c).1 (seven12a (six26 h).2.2.symm)
end
theorem eleven42a {a b c d e f : point} : ang_lt a b c d e f → ang_lt c b a d e f :=
λ h, ⟨eleven33a h.1, λ h_1, h.2 (eleven7 h_1)⟩
theorem eleven42b {a b c d e f : point} : ang_lt a b c d e f → ang_lt a b c f e d :=
λ h, ⟨eleven33b h.1, λ h_1, h.2 (eleven8 h_1)⟩
theorem eleven43 {a b c : point} : (ang_right b a c ∨ ang_obtuse b a c) → ang_acute a b c ∧ ang_acute a c b :=
begin
intro h1,
by_cases h : col a b c,
replace h1 : ang_obtuse b a c,
exact h1.elim (λ h_1, ((not_col_of_right h_1) (four11 h).2.1).elim) id,
replace h1 := B_of_obtuse_col h1 (four11 h).2.1,
exact ⟨acute_of_sided (six7 h1.2.2 h1.1.symm), acute_of_sided (six7 h1.2.2.symm h1.2.1.symm)⟩,
have h2 := eleven41 h (seven5 a b).1 (seven12a (six26 h).1.symm),
cases h1,
exact ⟨⟨c, a, (S a b), h1.2.2.symm.flip, h2.2⟩, c, a, (S a b), h1.2.2.symm.flip, h2.1⟩,
suffices : ang_acute c a (S a b),
rcases this with ⟨x, y, z, h3, h4⟩,
refine ⟨⟨x, y, z, h3, h2.2.trans h4⟩, x, y, z, h3, h2.1.trans h4⟩,
exact (eleven40a (six26 h).2.2.symm (seven12a (six26 h).1.symm) (six26 h).1.symm (seven5 a b).1.symm).2 h1.symm
end
lemma eleven44c {a b c : point} : ¬col a b c → eqd a b a c → eqa a c b a b c :=
begin
intros h h1,
suffices : cong a c b a b c,
exact eleven11 (six26 h).2.2 (six26 h).2.1 this,
exact ⟨h1.symm, two5 (eqd.refl c b), h1⟩
end
theorem eleven44d {a b c : point} : ¬col a b c → distlt a b a c → ang_lt a c b a b c :=
begin
intros h h1,
cases five13.1 h1 with d hd,
have h2 : ¬col d c b,
intro h_1,
exact (four10 h).2.2.2.1 (five4 hd.2.2.symm (or.inl hd.1.symm) (four11 h_1).2.1),
have h3 : ang_lt d b c b d a ∧ ang_lt d c b b d a,
exact eleven41 h2 hd.1.symm (two7 hd.2.1 (six26 h).1),
have h4 : ¬col a b d,
intro h_1,
exact h (five4 (two7 hd.2.1 (six26 h).1) (four11 h_1).1 (or.inl hd.1)),
suffices : ang_lt a b d a b c,
apply ang_lt.trans _ this,
apply eleven37 h3.2 (eleven9 _ (six5 (six26 h).2.1)) (eqa.trans _ (eleven44c h4 hd.2.1)),
exact (six7 hd.1.symm hd.2.2).symm,
exact (eleven6 (six26 h4).2.1 (six26 h4).2.2),
exact eleven32d h hd.2.2 hd.1
end
theorem eleven44a {a b c : point} : ¬col a b c → (eqd a b a c ↔ eqa a c b a b c) :=
begin
intro h,
refine ⟨eleven44c h, _⟩,
intro h1,
cases dist_total a b a c,
exact ((eleven44d h h_1).2 h1).elim,
cases h_1,
assumption,
exact ((eleven44d (four10 h).1 h_1).2 h1.symm).elim
end
theorem eleven44b {a b c : point} : ¬col a b c → (distlt a b a c ↔ ang_lt a c b a b c) :=
begin
intro h,
refine ⟨eleven44d h, _⟩,
intro h1,
cases dist_total a b a c,
assumption,
cases h_1,
exact (h1.2 (eleven44c h h_1)).elim,
exact (eleven38b h1 (eleven44d (four10 h).1 h_1)).elim
end
theorem eleven45a {a b c : point} : ang_acute a b c → ¬ang_right a b c ∧ ¬ang_obtuse a b c :=
λ h, ⟨λ h1, (lt_ang_right_of_ang_acute h h1).2 (eqa.refl (tri_of_ang_acute h).1 (tri_of_ang_acute h).2),
λ h1, (lt_ang_obtuse_of_ang_acute h h1).2 (eqa.refl (tri_of_ang_acute h).1 (tri_of_ang_acute h).2)⟩
theorem eleven45b {a b c : point} : ang_obtuse a b c → ¬ang_acute a b c ∧ ¬ang_right a b c :=
λ h, ⟨λ h1, (eleven45a h1).2 h, λ h1, (lt_ang_obtuse_of_ang_right h1 h).2
(eqa.refl (tri_of_ang_obtuse h).1 (tri_of_ang_obtuse h).2.1)⟩
theorem eleven45c {a b c : point} : ang_right a b c → ¬ang_acute a b c ∧ ¬ang_obtuse a b c :=
λ h, ⟨λ h1, (eleven45a h1).1 h, λ h1, (eleven45b h1).2 h⟩
theorem eleven46 {a b c : point} : (ang_right b a c ∨ ang_obtuse b a c) → distlt a b b c ∧ distlt a c b c :=
begin
intro h1,
by_cases h : col a b c,
replace h1 : ang_obtuse b a c,
exact h1.elim (λ h_1, ((not_col_of_right h_1) (four11 h).2.1).elim) id,
replace h1 := B_of_obtuse_col h1 (four11 h).2.1,
split,
apply five14 _ (eqd_refl b a) (eqd.refl b c),
exact five13.2 ⟨a, h1.2.2, eqd.refl b a, h1.2.1.symm⟩,
exact (five13.2 ⟨a, h1.2.2.symm, eqd.refl c a, h1.1.symm⟩).flip,
split,
apply five14 ((eleven44b (four10 h).2.1).2 _) (two5 (eqd.refl b a)) (eqd.refl b c),
cases h1,
exact lt_ang_right_of_ang_acute (eleven43 (or.inl h1)).2.symm h1,
exact lt_ang_obtuse_of_ang_acute (eleven43 (or.inr h1)).2.symm h1,
apply five14 ((eleven44b (four10 h).2.2.2.1).2 _) (two5 (eqd.refl c a)) (two5 (eqd.refl c b)),
cases h1,
exact lt_ang_right_of_ang_acute (eleven43 (or.inl h1)).1.symm h1.symm,
exact lt_ang_obtuse_of_ang_acute (eleven43 (or.inr h1)).1.symm h1.symm
end
theorem eleven47 {a b c x : point} : R a c b → xperp x (l c x) (l a b) → B a x b ∧ x ≠ a ∧ x ≠ b :=
begin
intros h h1,
have h2 : tri a b c,
apply six26,
intro h_1,
exact (eight14b h1) (six18 h1.2.1 (six13 h1.1) h_1 h1.2.2.2.1).symm,
have h3 := eleven43 (or.inl ⟨h2.2.2, h2.2.1, h⟩),
have h4 : x ≠ a,
intro h_1,
subst x,
exact (eleven45a h3.1).1 ⟨h2.2.2.symm, h2.1.symm, h1.2.2.2.2 (six17a c a) (six17b a b)⟩,
have h5 : x ≠ b,
intro h_1,
subst x,
exact (eleven45a h3.2).1 ⟨h2.2.1.symm, h4.symm, h1.2.2.2.2 (six17a c b) (six17a a b)⟩,
refine ⟨_, h4, h5⟩,
wlog h6 : distle b x a x := (five10 b x a x) using a b,
suffices : distle a x a b,
cases h1.2.2.2.1,
exact (six12 (six7 h_1 h2.1.symm).symm).1 this,
cases h_1,
exact h_1.symm,
suffices : distle b x b a,
exact ((six12 (six7 h_1.symm h2.1).symm).1 this).symm,
exact h6.trans (five6 this (eqd.refl a x) (two5 (eqd.refl a b))),
apply distle.trans _ (eleven46 (or.inl ⟨h2.2.2, h2.2.1, h⟩)).1.1,
exact five6 (eleven46 (or.inl ⟨six13 h1.1, h4.symm, (h1.2.2.2.2 (six17a c x) (six17a a b))⟩)).2.1 (two5 (eqd.refl x a)) (eqd.refl c a),
apply (this h.symm _ ⟨h2.1.symm, h2.2.2, h2.2.1⟩ h3.symm h5 h4).symm,
rwa six17 b a
end
theorem eleven48 {a b c d : point} : ang_acute a b c → d ∈ l b c → d ≠ b → R a d b → sided b c d :=
begin
intros h h1 h2 h3,
by_contradiction h_1,
replace h1 : B c b d,
simpa [h_1] using six1 (four11 h1).2.1,
replace h := (eleven40a (tri_of_ang_acute h).1 (tri_of_ang_acute h).2 h2 h1).1 h,
exact (eleven45a (eleven43 (or.inr h)).2).1 ⟨h2.symm, (tri_of_ang_obtuse h).2.2, h3.symm⟩
end
theorem eleven49 {a b c d : point} : ang_obtuse a b c → d ∈ l b c → d ≠ b → R a d b → B c b d :=
begin
intros h h1 h2 h3,
by_contradiction h_1,
replace h1 : sided b c d,
simpa [h_1] using six1 (four11 h1).2.1,
replace h := ang_obtuse.trans h (eleven9 (six5 (tri_of_ang_obtuse h).1) h1.symm),
exact (eleven45a (eleven43 (or.inr h)).2).1 ⟨h2.symm, (tri_of_ang_obtuse h).2.2, h3.symm⟩
end
theorem SAS {a b c a' b' c' : point} : eqa a b c a' b' c' → eqd a b a' b' → eqd c b c' b' →
eqd a c a' c' ∧ (a ≠ c → eqa b a c b' a' c' ∧ eqa b c a b' c' a') :=
begin
intros h h1 h2,
suffices : cong a b c a' b' c',
refine ⟨this.2.2, λ h1, _⟩,
refine ⟨eleven11 h.1.symm h1.symm (four4 this).2.1,
eleven11 h.2.1.symm h1 (four4 this).2.2.1⟩,
exact ⟨h1, h2.flip,
(eleven4.1 h).2.2.2.2 (six5 h.1) (six5 h.2.1) (six5 h.2.2.1) (six5 h.2.2.2.1) h1.flip h2.flip⟩
end
theorem ASA {a b c a' b' c' : point} : ¬col a b c → eqa b a c b' a' c' → eqa a b c a' b' c' →
eqd a b a' b' → eqd a c a' c' ∧ eqd b c b' c' ∧ eqa a c b a' c' b' :=
begin
intros h h1 h2 h3,
cases exists_of_exists_unique (six11 h1.2.2.2.1 h1.2.1.symm) with x hx,
have h4 : cong a b c a' b' x,
refine ⟨h3, _, hx.2.symm⟩,
exact (eleven4.1 h1).2.2.2.2 (six5 h1.1) (six5 h1.2.1) (six5 h1.2.2.1) hx.1 h3 hx.2.symm,
suffices : x = c',
subst x,
exact ⟨h4.2.2, h4.2.1, eleven11 h1.2.1.symm h2.2.1.symm (four4 h4).1⟩,
have h5 : ¬col a' b' c',
intro h_1,
exact h (eleven21d h_1 h2.symm),
suffices : sided b' x c',
apply six21a (six14 h1.2.2.2.1.symm) (six14 h2.2.2.2.1.symm) _ (four11 (six4.1 hx.1).1).2.2.1
(four11 (six4.1 this).1).2.2.1 (six17b a' c') (six17b b' c'),
intro h_1,
apply h5,
suffices : b' ∈ l a' c',
exact (four11 this).1,
rw h_1,
exact six17a b' c',
apply eleven15b h h5 (eleven11 h2.1 h2.2.1 h4) _ h2 (side.refla h5),
exact (nine12 (six14 h2.2.2.1) (six17a a' b') hx.1.symm h5).symm
end
theorem AAS {a b c a' b' c' : point} : ¬col a b c → eqa b c a b' c' a' → eqa a b c a' b' c' →
eqd a b a' b' → eqd a c a' c' ∧ eqd b c b' c' ∧ eqa b a c b' a' c' :=
begin
intros h h1 h2 h3,
cases exists_of_exists_unique (six11 h1.2.2.1.symm h1.1) with x hx,
have h4 : cong a b c a' b' x,
refine ⟨h3, hx.2.symm, _⟩,
exact (eleven4.1 h2).2.2.2.2 (six5 h2.1) (six5 h2.2.1) (six5 h2.2.2.1) hx.1 h3.flip hx.2.symm,
suffices : x = c',
subst x,
exact ⟨h4.2.2, h4.2.1, eleven11 h2.1.symm h1.2.1.symm (four4 h4).2.1⟩,
clear h2 h3,
replace hx := hx.1,
replace h4 := (eleven11 h1.1 h1.2.1 (four4 h4).2.2.1),
wlog h6 := hx.2.2 using x c',
by_contradiction h_1,
have h5 : ¬col x c' a',
intro h_2,
apply (four10 h).2.2.1 (eleven21d (six23.2 ⟨l x c', six14 h_1, _, six17b x c', h_2⟩) h1.symm),
exact (four11 (six4.1 hx).1).1,
apply (eleven41 h5 h6.symm hx.1.symm).2.2,
apply eleven8 (eqa.trans _ (h1.symm.trans h4)),
exact eleven9 (six7 h6.symm h_1).symm (six5 h1.2.2.2.1),
exact (this h4 hx.symm h1).symm
end
theorem SSS {a b c d e f : point} : tri a b c → cong a b c d e f →
eqa a b c d e f ∧ eqa b c a e f d ∧ eqa c a b f d e :=
λ h h1, ⟨eleven11 h.1 h.2.1.symm h1, eleven11 h.2.1 h.2.2 (four4 h1).2.2.1,
eleven11 h.2.2.symm h.1.symm (four4 h1).2.2.2.1⟩
theorem SSA {a b c a' b' c' : point} : eqa a b c a' b' c' → eqd a c a' c' → eqd b c b' c' → distle b c a c →
eqd a b a' b' ∧ eqa b a c b' a' c' ∧ eqa b c a b' c' a' :=
begin
intros h h1 h2 h3,
cases exists_of_exists_unique (six11 h.2.2.1 h.1.symm) with x hx,
have h4 : cong a b c x b' c',
refine ⟨hx.2.symm.flip, h2, _⟩,
exact (eleven4.1 h).2.2.2.2 (six5 h.1) (six5 h.2.1) hx.1 (six5 h.2.2.2.1) hx.2.symm h2,
have h5 : a ≠ c,
intro h_1,
subst c,
exact h.1.symm (id_eqd (five9 h3 (five11 a b a))),
suffices : x = a',
subst x,
exact ⟨h4.1, eleven11 h.1.symm h5.symm (four4 h4).2.1, eleven11 h.2.1.symm h5 (four4 h4).2.2.1⟩,
by_contradiction h_1,
cases hx.1.2.2.symm with h6 h6,
have h7 : ¬col a b c,
intro h_2,
apply dist_le_iff_not_lt.1 h3 (five14 _ h1.symm h2.symm),
suffices : B b' a' c',
refine ⟨((five12 (or.inl this)).1 this).2, λ h_3, _⟩,
apply h.2.2.1 (unique_of_exists_unique (six11 h.2.2.2.1.symm h.2.2.2.1) _ _),
exact ⟨six7 this.symm (two7 h1 h5), h_3.flip⟩,
exact ⟨six5 h.2.2.2.1.symm, eqd.refl c' b'⟩,
apply three5a h6 _,
cases seven20 _ (h1.symm.flip.trans h4.2.2.flip),
exact (h_1 h_3.symm).elim,
exact h_3.1,
apply (four11 (five4 h.2.2.2.1 (four11 (eleven21d h_2 h)).2.2.2.2 _)).2.1,
exact (four11 (four13 h_2 h4)).2.2.2.2,
apply dist_le_iff_not_lt.1 h3 (five14 _ h4.2.2.symm h2.symm),
apply ((eleven44b _).2 _).flip,
intro h_2,
exact h7 (four13 (four11 h_2).2.2.1 h4.symm),
have h8 : ¬col a' b' c',
intro h_2,
exact h7 (eleven21d h_2 h.symm),
suffices : ang_lt a' b' c' c' a' x,
apply eleven37 (eleven42a this) (eleven9 (six5 h.2.2.2.1) hx.1) (((eleven44a _).1 (h1.symm.trans h4.2.2).flip).symm.trans _),
intro h_2,
exact h8 (five4 (ne.symm h_1) (four11 (or.inl h6)).2.2.1 (four11 h_2).2.2.1),
exact eleven9 (six5 (two7 h4.2.2 h5).symm) (six7 h6.symm (ne.symm h_1)).symm,
exact (eleven41 h8 h6 h_1).2,
have h7 : ¬col a b c,
intro h_2,
apply dist_le_iff_not_lt.1 h3 (five14 _ h4.2.2.symm h4.2.1.symm),
suffices : B b' x c',
refine ⟨((five12 (or.inl this)).1 this).2, λ h_3, _⟩,
apply hx.1.1 (unique_of_exists_unique (six11 h.2.2.2.1.symm h.2.2.2.1) _ _),
exact ⟨six7 this.symm (two7 h4.2.2 h5), h_3.flip⟩,
exact ⟨six5 h.2.2.2.1.symm, eqd.refl c' b'⟩,
apply three5a h6 _,
cases seven20 _ (h1.symm.flip.trans h4.2.2.flip),
exact (h_1 h_3.symm).elim,
exact h_3.1.symm,
apply (four11 (five4 h.2.2.2.1 (four11 (eleven21d h_2 h)).2.2.2.2 _)).2.1,
exact (four11 (four13 h_2 h4)).2.2.2.2,
apply dist_le_iff_not_lt.1 h3 (five14 _ h1.symm h2.symm),
apply ((eleven44b _).2 _).flip,
intro h_2,
exact h7 (eleven21d (four11 h_2).2.2.1 h.symm),
have h8 : ¬col x b' c',
intro h_2,
exact h7 (four13 h_2 h4.symm),
suffices : ang_lt x b' c' c' x a',
apply eleven37 (eleven42a this) (eleven9 (six5 h.2.2.2.1) hx.1.symm) (((eleven44a _).1 (h4.2.2.symm.trans h1).flip).symm.trans _),
intro h_2,
exact h8 (five4 h_1 (four11 (or.inl h6)).2.2.1 (four11 h_2).2.2.1),
exact eleven9 (six5 (two7 h1 h5).symm) (six7 h6.symm h_1).symm,
exact (eleven41 h8 h6 (ne.symm h_1)).2
end
theorem eleven53 {a b c d : point} : R a d c → c ≠ d → a ≠ b → a ≠ d → B d a b → ang_lt d b c d a c ∧ distlt a c b c :=
begin
intros h h1 h2 h3 h4,
have h5 : c ∉ l a b,
intro h_1,
suffices : col a d c,
exact (eight9 h this).elim h3 h1,
suffices : l a b = l a d,
rwa this at h_1,
exact six16 h2 h3 (or.inr (or.inr h4)),
have h6 := (eleven41 h5 h4.symm h3.symm).2,
refine ⟨eleven37 (eleven42b h6) (eleven9 (six7 h4.symm h2).symm (six5 (six26 h5).2.1.symm))
(eqa.refl h3.symm (six26 h5).2.2.symm), _⟩,
have h7 : eqd c a c (S d a),
exact h.symm,
apply five14 _ h7.symm.flip (eqd.refl b c),
apply ((eleven44b _).2 _).flip,
intro h_1,
suffices : l a b = l (S d a) b,
rw this at h5,
exact h5 (four11 h_1).2.2.1,
apply six18 (six14 h2) _ (or.inr (or.inr (three7b h4.symm (seven5 d a).1 h3).symm)) (six17b a b),
intro h_2,
subst b,
exact h3 (three4 (seven5 d a).1 h4),
apply eleven37 (eleven42a h6) (eleven9 (six5 (six26 h5).2.1.symm) _) _,
exact (six7 (three7b h4.symm (seven5 d a).1 h3) h2).symm,
apply eleven10 _ (six5 (six26 h5).2.2.symm) (six7 (seven5 d a).1 h3.symm) (six5 (two7 h7 (six26 h5).2.2.symm))
(six7 (three7b h4.symm (seven5 d a).1 h3).symm (seven12b h3).symm).symm,
apply (eleven44a (four10 _).2.2.2.2).1 h7.symm,
intro h_1,
suffices : l a b = l a (S d a),
rw this at *,
exact h5 h_1,
exact six16 h2 (seven12b h3).symm (or.inr (or.inr (three7b h4.symm (seven5 d a).1 h3).symm))
end
end Euclidean_plane |
7c4ec13f63c279c30178d0630b0f314c955d94c5 | 86f6f4f8d827a196a32bfc646234b73328aeb306 | /examples/sets_functions_and_relations/unnamed_662.lean | 12f7bfa0a6b53ce25c430f1850af7267af197870 | [] | no_license | jamescheuk91/mathematics_in_lean | 09f1f87d2b0dce53464ff0cbe592c568ff59cf5e | 4452499264e2975bca2f42565c0925506ba5dda3 | refs/heads/master | 1,679,716,410,967 | 1,613,957,947,000 | 1,613,957,947,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 194 | lean | import tactic
open set
variables α I : Type*
variable A : I → set α
variable s : set α
-- BEGIN
open_locale classical
example : s ∪ (⋂ i, A i) = ⋂ i, (A i ∪ s) :=
sorry
-- END |
45154abad60f2867cf31d4ac1bdd07338429a84b | 76df16d6c3760cb415f1294caee997cc4736e09b | /lean/src/cs/lgl.lean | 1d2797dbffecdb5a82b9fbb316e6cc5165b6f041 | [
"MIT"
] | permissive | uw-unsat/leanette-popl22-artifact | 70409d9cbd8921d794d27b7992bf1d9a4087e9fe | 80fea2519e61b45a283fbf7903acdf6d5528dbe7 | refs/heads/master | 1,681,592,449,670 | 1,637,037,431,000 | 1,637,037,431,000 | 414,331,908 | 6 | 1 | null | null | null | null | UTF-8 | Lean | false | false | 17,508 | lean | import tactic.basic
import tactic.split_ifs
import tactic.linarith
import tactic.apply_fun
import .svm
import .lib
import .hp
import .mrg
namespace sym
open lang
section lgl
variables
{Model SymB SymV D O : Type}
[inhabited Model] [inhabited SymV]
(f : factory Model SymB SymV D O) {m : Model}
lemma factory.hlgl_eqv_lgl {σ : state SymB} {ρ : result SymB SymV} :
σ.legal f.to_has_eval m → ¬ σ.normal f.to_has_eval m → ρ.state.eqv f.to_has_eval m σ →
ρ.legal f.to_has_eval m :=
begin
intros hl_σ hnn heq,
simp only [state.normal, eq_ff_eq_not_eq_tt, not_and, bool.to_bool_and, bool.to_bool_coe, band_coe_iff] at hnn,
simp only [state.legal, bor_coe_iff, bool.to_bool_coe, bool.to_bool_or] at hl_σ,
cases ρ with σ' v σ'; simp only [state.eqv, result.state] at heq,
{ simp only [result.legal, state.legal, state.normal, heq, and_imp, bool.of_to_bool_iff],
simp only [hl_σ, true_and], },
{ simp only [result.legal, state.legal, state.normal, heq, hl_σ, true_and, eq_ff_eq_not_eq_tt, not_and, bool.of_to_bool_iff],
exact hnn, }
end
theorem svm_hlgl {x : exp D O} {ε : env SymV} {σ : state SymB} {ρ : result SymB SymV} :
σ.legal f.to_has_eval m → ¬ σ.normal f.to_has_eval m → evalS f x ε σ ρ →
ρ.legal f.to_has_eval m :=
by { intros hl_σ hnn hs, apply f.hlgl_eqv_lgl hl_σ hnn (svm_hp f hnn hs), }
lemma factory.compose_lgl {σ σ' : state SymB}
(hl_σ : (state.legal f.to_has_eval m σ))
(hl_σ' : (state.legal f.to_has_eval m σ')) :
(state.legal f.to_has_eval m (f.compose σ σ')) :=
begin
simp only [factory.compose, state.legal, f.and_sound, f.imp_sound, bool.of_to_bool_iff],
simp only [state.legal, bor_coe_iff, bool.to_bool_coe, bool.to_bool_or] at hl_σ hl_σ',
cases (f.to_has_eval.evalB m σ.assumes),
{ simp only [false_or, coe_sort_ff] at hl_σ,
simp only [hl_σ, forall_false_left, false_or, and_self, coe_sort_ff, false_and], },
{ simp only [true_and, coe_sort_tt, forall_true_left],
cases (f.to_has_eval.evalB m σ'.assumes),
{ simp only [false_or, coe_sort_ff] at hl_σ',
simp only [hl_σ', and_true, coe_sort_ff], finish, },
{ finish, } }
end
lemma factory.compose_normal {σ σ' : state SymB} :
((state.normal f.to_has_eval m σ) ∧ (state.normal f.to_has_eval m σ')) ↔
state.normal f.to_has_eval m (f.compose σ σ') :=
begin
simp only [factory.compose, state.normal, f.and_sound, f.imp_sound, bool.of_to_bool_iff],
constructor; intro h,
{ simp only [h, forall_true_left, and_self], },
{ simp only [h, and_self], }
end
lemma factory.merge_ρ_lgl {σ : state SymB} {grs : choices SymB (result SymB SymV)} :
σ.normal f.to_has_eval m → grs.one f.to_has_eval m →
(∀ (i : ℕ) (hi : i < grs.length), (grs.nth_le i hi).value.legal f.to_has_eval m) →
(result.legal f.to_has_eval m (f.merge_ρ σ grs)) :=
begin
intros hn hu hl_grs,
replace hu : grs.one (has_eval_result f.to_has_eval) m :=
by { simp only [has_eval_result, choices.one, choices.true],
simp only [choices.one, choices.true] at hu, exact hu, },
rewrite (choices.one_iff_filter (has_eval_result f.to_has_eval)) at hu,
rcases hu with ⟨i, hi, hf⟩,
simp only [has_eval_result] at hf,
rcases (f.merge_ρ_normal_eqv hn hf) with hm_σ,
rcases (f.merge_ρ_normal_eval hn hf (hl_grs i hi)) with h_eval,
specialize hl_grs i hi,
cases (f.merge_ρ σ grs) with σ' v' σ';
cases (list.nth_le grs i hi).value with σ'' v'' σ'';
simp only [result.legal, eq_ff_eq_not_eq_tt, bool.of_to_bool_iff];
simp only [result.legal, eq_ff_eq_not_eq_tt, bool.of_to_bool_iff] at hl_grs;
simp only [result.state] at hm_σ,
{ apply state.eqv_legal f.to_has_eval hl_grs (state.eqv.symm f.to_has_eval m hm_σ), },
{ apply state.eqv_legal f.to_has_eval hl_grs.left (state.eqv.symm f.to_has_eval m hm_σ), },
{ constructor,
{ apply state.eqv_legal f.to_has_eval hl_grs (state.eqv.symm f.to_has_eval m hm_σ), },
{ simp only [result.eval] at h_eval,
cases hn'' : (state.normal f.to_has_eval m σ'');
simp only [hn'', if_true, if_false, coe_sort_ff, coe_sort_tt] at h_eval,
{ rewrite ←bool_iff_false at hn'',
rewrite ←bool_iff_false,
apply state.eqv_abnormal f.to_has_eval hn'',
symmetry, exact hm_σ, },
{ contradiction, } } },
{ cases hl_grs with hl_grs hn'',
constructor,
{ apply state.eqv_legal f.to_has_eval hl_grs (state.eqv.symm f.to_has_eval m hm_σ), },
{ rewrite ←bool_iff_false at hn'',
rewrite ←bool_iff_false,
apply state.eqv_abnormal f.to_has_eval hn'',
symmetry, exact hm_σ, } },
end
lemma factory.assert_lgl {σ : state SymB} (b : SymB) :
σ.legal f.to_has_eval m → (f.assert σ b).legal f.to_has_eval m :=
begin
simp only [state.legal, factory.assert, bor_coe_iff, bool.to_bool_coe, bool.to_bool_or],
intro hl_σ,
cases ha : (f.to_has_eval.evalB m σ.assumes),
{ simp only [false_or, coe_sort_ff],
simp only [ha, false_or, coe_sort_ff] at hl_σ,
simp only [f.and_sound, f.imp_sound, hl_σ, ha, forall_false_left, to_bool_true_eq_tt, coe_sort_tt, and_self, coe_sort_ff], },
{ simp only [true_or, coe_sort_tt], }
end
lemma factory.assume_lgl {σ : state SymB} (b : SymB) :
σ.legal f.to_has_eval m → (f.assume σ b).legal f.to_has_eval m :=
begin
simp only [state.legal, factory.assume, bor_coe_iff, bool.to_bool_coe, bool.to_bool_or],
intro hl_σ,
cases ha : (f.to_has_eval.evalB m σ.asserts),
{ simp only [ha, or_false, coe_sort_ff] at hl_σ,
simp only [or_false, coe_sort_ff],
simp only [f.and_sound, f.imp_sound, ha, hl_σ, forall_false_left, to_bool_true_eq_tt, coe_sort_tt, and_self, coe_sort_ff], },
{ simp only [coe_sort_tt, or_true], }
end
lemma factory.app_lgl {ε : env SymV} {σ : state SymB} {o : O} {xs : list ℕ} {vs : list SymV}
(h1: xs.length = vs.length)
(h2: ∀ (i : ℕ) (hx : i < xs.length) (hv : i < vs.length),
evalS f (exp.var (xs.nth_le i hx)) ε σ (result.ans σ (vs.nth_le i hv)))
(ih : ∀ (i : ℕ) (hx : i < xs.length) (hv : i < vs.length), (λ {x : exp D O} {ε : env SymV} {σ : state SymB} {ρ : result SymB SymV} (hs : evalS f x ε σ ρ), (state.legal f.to_has_eval m σ) → (result.legal f.to_has_eval m ρ)) (h2 i hx hv))
(hl_σ : (state.legal f.to_has_eval m σ)) :
(result.legal f.to_has_eval m (f.strengthen σ (f.opS o vs))) :=
begin
rcases (f.opS_sound m o vs) with ⟨_, hl_σ'⟩,
cases (f.opS o vs) with σ' v σ';
simp only [factory.strengthen];
simp only [result.legal, bool.of_to_bool_iff] at hl_σ';
try { cases hl_σ' with hl_σ' hl_nσ' };
rcases (f.compose_lgl hl_σ hl_σ') with hlc,
{ simp only [factory.halt_or_ans],
cases hh : (f.halted (f.compose σ σ')),
{ simp only [result.legal, hlc, if_false, coe_sort_ff], },
{ simp only [result.legal, hlc, true_and, eq_ff_eq_not_eq_tt, if_true, bool.of_to_bool_iff, coe_sort_tt],
by_contradiction,
simp only [eq_tt_eq_not_eq_ff] at h,
rewrite bool.tt_eq_true at h,
simp only [state.normal, bool.to_bool_and, bool.to_bool_coe, band_coe_iff] at h,
simp only [factory.halted, bor_eq_true_eq_eq_tt_or_eq_tt] at hh,
cases hh,
all_goals
{ rewrite bool.tt_eq_true at hh,
simp only [f.is_ff_sound] at hh,
apply_fun (f.to_has_eval.evalB m) at hh,
simp only [f.mk_ff_sound] at hh,
simp only [hh, coe_sort_ff, false_and, and_false, coe_sort_ff] at h,
contradiction, },} },
{ simp only [result.legal, true_and, eq_ff_eq_not_eq_tt, bool.of_to_bool_iff],
by_contradiction,
simp only [hlc, true_and, eq_tt_eq_not_eq_ff] at h,
rewrite bool.tt_eq_true at h,
rewrite ←f.compose_normal at h,
cases h,
contradiction, }
end
lemma factory.call_sym_lgl {ε : env SymV} {σ σ' : state SymB}
{x1 x2 : ℕ} {c v : SymV} {grs : choices SymB (result SymB SymV)}
(h1 : evalS f (exp.var x1) ε σ (result.ans σ c))
(h2 : evalS f (exp.var x2) ε σ (result.ans σ v))
(h3 : σ' = f.assert σ (f.some choice.guard (f.cast c)))
(h4 : ¬(f.is_ff (f.some choice.guard (f.cast c))) ∧ ¬(f.halted σ'))
(h5 : list.map choice.guard (f.cast c) = list.map choice.guard grs)
(h6 : ∀ (i : ℕ) (hc : i < list.length (f.cast c)) (hr : i < list.length grs), evalS f (list.nth_le (f.cast c) i hc).value.exp (list.update_nth (list.nth_le (f.cast c) i hc).value.env (list.nth_le (f.cast c) i hc).value.var v) (f.assume σ' (list.nth_le (f.cast c) i hc).guard) (list.nth_le grs i hr).value)
(ih1 : (state.legal f.to_has_eval m σ) → (result.legal f.to_has_eval m (result.ans σ c)))
(ih2 : (state.legal f.to_has_eval m σ) → (result.legal f.to_has_eval m (result.ans σ v)))
(ih6 : ∀ (i : ℕ) (hc : i < list.length (f.cast c)) (hr : i < list.length grs),
(λ {x : exp D O} {ε : env SymV} {σ : state SymB} {ρ : result SymB SymV} (hs : evalS f x ε σ ρ),
(state.legal f.to_has_eval m σ) →
(result.legal f.to_has_eval m ρ)) (h6 i hc hr))
(hl_σ: (state.legal f.to_has_eval m σ)) :
(result.legal f.to_has_eval m (f.merge_ρ σ' grs)) :=
begin
cases hn : σ.normal f.to_has_eval m,
{ rewrite ←bool_iff_false at hn,
apply svm_hlgl f hl_σ hn (evalS.call_sym h1 h2 h3 h4 h5 h6), },
{ rewrite bool.tt_eq_true at hn,
have hl_σ' : ↥(σ'.legal f.to_has_eval m) := by { simp only [h3], apply f.assert_lgl _ hl_σ, },
cases hn' : σ'.normal f.to_has_eval m,
{ rewrite ←bool_iff_false at hn',
apply f.hlgl_eqv_lgl hl_σ' hn',
apply f.merge_ρ_eqp,
intros i hr,
rcases (list.map_bound (eq.symm h5) hr) with hc,
specialize h6 i hc hr,
transitivity (f.assume σ' (list.nth_le (f.cast c) i hc).guard),
{ apply svm_hp f _ h6, apply state.eqv_abnormal f.to_has_eval hn', symmetry, apply f.assume_hp hn', },
{ apply f.assume_hp hn', } },
{ rewrite bool.tt_eq_true at hn',
rcases (f.assert_some_cast_one hn hn' h3) with h_one,
apply f.merge_ρ_lgl hn' (choices.eq_one f.to_has_eval h5 h_one),
intros i hr,
rcases (list.map_bound (eq.symm h5) hr) with hc,
rcases (choices.one_implies_filter (has_eval_clos f.to_has_eval) h_one) with ⟨w, hw, hwp⟩,
cases classical.em (i = w),
{ apply ih6 i hc hr,
apply f.assume_lgl _ hl_σ', },
{ rewrite [←ne.def] at h,
apply svm_hlgl f _ _ (h6 i hc hr),
apply f.assume_lgl _ hl_σ',
apply f.assume_normal_false hn',
apply choices.filter_one_rest (has_eval_clos f.to_has_eval) hw hc hwp,
symmetry, exact h, } } }
end
lemma factory.call_halt_lgl {σ σ' : state SymB} {c : SymV}
(hσ' : σ' = f.assert σ (f.some choice.guard (f.cast c)))
(hh : ↥(f.is_ff (f.some choice.guard (f.cast c))) ∨ ↥(f.halted σ'))
(hl_σ : (state.legal f.to_has_eval m σ)) :
(result.legal f.to_has_eval m (result.halt σ')) :=
begin
rcases (f.assert_lgl (f.some choice.guard (f.cast c)) hl_σ) with h,
rewrite ←hσ' at h,
simp only [result.legal, h, state.normal, true_and, eq_ff_eq_not_eq_tt, bool.of_to_bool_iff, not_and],
intro ha,
cases hh,
{ simp only [hσ', factory.assert] at ha,
simp only [hσ', factory.assert, f.and_sound, f.imp_sound, ha, eq_ff_eq_not_eq_tt, not_and, to_bool_ff_iff, forall_true_left],
intro ha',
simp only [f.is_ff_sound] at hh,
simp only [hh, f.mk_ff_sound], },
{ simp only [factory.halted, bor_coe_iff] at hh,
cases hh; simp only [f.is_ff_sound] at hh,
{ rewrite hh at ha,
simp only [f.mk_ff_sound, coe_sort_ff] at ha,
contradiction, },
{ rewrite hh,
apply f.mk_ff_sound, } }
end
lemma factory.let0_lgl {ε : env SymV} {σ σ' : state SymB}
{y : ℕ} {x2: exp D O} {v : SymV} {r: result SymB SymV}
(h2 : evalS f x2 (list.update_nth ε y v) σ' r)
(ih1 : (state.legal f.to_has_eval m σ) → (result.legal f.to_has_eval m (result.ans σ' v)))
(ih2 : (state.legal f.to_has_eval m σ') → (result.legal f.to_has_eval m r))
(hl_σ : (state.legal f.to_has_eval m σ)) :
(result.legal f.to_has_eval m r) :=
begin
specialize ih1 hl_σ,
simp only [result.legal, bool.of_to_bool_iff] at ih1,
cases hn : (state.normal f.to_has_eval m σ'),
{ rewrite ←bool_iff_false at hn,
apply svm_hlgl f ih1 hn h2, },
{ apply ih2 ih1, }
end
lemma factory.if0_sym_lgl {ε : env SymV} {σ : state SymB}
{xc : ℕ} {xt xf : exp D O} {v : SymV} {rt rf: result SymB SymV}
(hc : evalS f (exp.var xc) ε σ (result.ans σ v))
(hv : ¬↥(f.is_tt (f.truth v)) ∧ ¬↥(f.is_ff (f.truth v)))
(ht : evalS f xt ε (f.assume σ (f.truth v)) rt)
(hf : evalS f xf ε (f.assume σ (f.not (f.truth v))) rf)
(iht: (state.legal f.to_has_eval m (f.assume σ (f.truth v))) → (result.legal f.to_has_eval m rt))
(ihf: (state.legal f.to_has_eval m (f.assume σ (f.not (f.truth v)))) → (result.legal f.to_has_eval m rf))
(hl_σ: (state.legal f.to_has_eval m σ)) :
(result.legal f.to_has_eval m (f.merge_ρ σ [{guard := f.truth v, value := rt}, {guard := f.not (f.truth v), value := rf}])) :=
begin
cases hn : σ.normal f.to_has_eval m,
{ rewrite ←bool_iff_false at hn,
apply svm_hlgl f hl_σ hn (evalS.if0_sym hc hv ht hf), },
{ rewrite bool.tt_eq_true at hn,
apply f.merge_ρ_lgl hn,
{ apply choices.one_of_ite, apply f.not_sound, },
{ intros i hi,
simp only [list.length, zero_add] at hi,
rcases (nat.lt2_implies_01 hi) with hi01,
cases hi01; simp only [hi01, list.nth_le],
{ apply iht, apply f.assume_lgl _ hl_σ, },
{ apply ihf, apply f.assume_lgl _ hl_σ, } } }
end
lemma factory.error_lgl {σ : state SymB}
(hl_σ : (state.legal f.to_has_eval m σ)) :
(result.legal f.to_has_eval m (result.halt (f.assert σ f.mk_ff))) :=
begin
rcases (f.assert_lgl f.mk_ff hl_σ) with h,
simp only [result.legal, eq_ff_eq_not_eq_tt, bool.of_to_bool_iff, h, true_and],
cases hn : (σ.normal f.to_has_eval m),
{ rewrite ←bool_iff_false at hn,
rcases (@factory.assert_hp Model SymB SymV D O _ _ f m σ f.mk_ff hn) with heqv,
rcases (state.eqv_abnormal f.to_has_eval hn (state.eqv.symm f.to_has_eval m heqv)) with hh,
rewrite bool_iff_false at hh,
exact hh, },
{ simp only [state.normal, band_eq_true_eq_eq_tt_and_eq_tt, bool.to_bool_and, bool.to_bool_coe] at hn,
simp only [state.normal, factory.assert, hn, f.and_sound, f.imp_sound, f.mk_ff_sound,
to_bool_false_eq_ff, coe_sort_tt, forall_true_left, and_false, coe_sort_ff], }
end
lemma factory.abort_lgl {σ : state SymB}
(hl_σ : (state.legal f.to_has_eval m σ)) :
(result.legal f.to_has_eval m (result.halt (f.assume σ f.mk_ff))) :=
begin
rcases (f.assume_lgl f.mk_ff hl_σ) with h,
simp only [result.legal, eq_ff_eq_not_eq_tt, bool.of_to_bool_iff, h, true_and],
cases hn : (σ.normal f.to_has_eval m),
{ rewrite ←bool_iff_false at hn,
rcases (@factory.assume_hp Model SymB SymV D O _ _ f m σ f.mk_ff hn) with heqv,
rcases (state.eqv_abnormal f.to_has_eval hn (state.eqv.symm f.to_has_eval m heqv)) with hh,
rewrite bool_iff_false at hh,
exact hh, },
{ simp only [state.normal, band_eq_true_eq_eq_tt_and_eq_tt, bool.to_bool_and, bool.to_bool_coe] at hn,
simp only [state.normal, factory.assume, hn, f.and_sound, f.imp_sound, f.mk_ff_sound,
to_bool_false_eq_ff, coe_sort_tt, forall_true_left, and_false, coe_sort_ff, false_and], }
end
-- The SVM rules preserve the legality of states across steps:
-- legal input state leads to a legal result.
-- A state is legal with respect to a model if its assumptions or
-- assertions (or both) are true under that model. A result is
-- legal if its state is legal.
theorem svm_lgl {x : exp D O} {ε : env SymV} {σ : state SymB} {ρ : result SymB SymV} :
σ.legal f.to_has_eval m →
evalS f x ε σ ρ →
ρ.legal f.to_has_eval m :=
begin
intros hl_σ hs,
induction hs,
case sym.evalS.app { apply f.app_lgl hs_h1 hs_h2 hs_ih hl_σ, },
case sym.evalS.call_sym { apply f.call_sym_lgl hs_h1 hs_h2 hs_h3 hs_h4 hs_h5 hs_h6 hs_ih_h1 hs_ih_h2 hs_ih_h6 hl_σ, },
case sym.evalS.call_halt { apply f.call_halt_lgl hs_h3 hs_h4 hl_σ, },
case sym.evalS.let0 { apply f.let0_lgl hs_h2 hs_ih_h1 hs_ih_h2 hl_σ, },
case sym.evalS.let0_halt { apply hs_ih hl_σ, },
case sym.evalS.if0_true { apply hs_ih_hr hl_σ, },
case sym.evalS.if0_false { apply hs_ih_hr hl_σ, },
case sym.evalS.if0_sym { apply f.if0_sym_lgl hs_hc hs_hv hs_ht hs_hf hs_ih_ht hs_ih_hf hl_σ, },
case sym.evalS.error { apply f.error_lgl hl_σ, },
case sym.evalS.abort { apply f.abort_lgl hl_σ, },
all_goals { -- bool, datum, lam, var
simp only [result.legal, hl_σ, f.bval_sound, f.dval_sound, f.cval_sound,
to_bool_true_eq_tt, implies_true_iff, coe_sort_tt, and_self], },
end
end lgl
end sym
|
cc8656429ce5b858084feeb99e76cf7c22c36f35 | 74addaa0e41490cbaf2abd313a764c96df57b05d | /Mathlib/topology/sheaves/stalks_auto.lean | 53d0e4bee1d93ad610ea8fe35485ef3a32369f01 | [] | 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 | 8,057 | 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 Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.topology.category.Top.open_nhds
import Mathlib.topology.sheaves.presheaf
import Mathlib.category_theory.limits.limits
import Mathlib.category_theory.limits.types
import Mathlib.PostPort
universes u v u_1
namespace Mathlib
namespace Top.presheaf
/-- Stalks are functorial with respect to morphisms of presheaves over a fixed `X`. -/
def stalk_functor (C : Type u) [category_theory.category C] [category_theory.limits.has_colimits C]
{X : Top} (x : ↥X) : presheaf C X ⥤ C :=
category_theory.functor.obj
(category_theory.whiskering_left (topological_space.open_nhds xᵒᵖ)
(topological_space.opens ↥Xᵒᵖ) C)
(category_theory.functor.op (topological_space.open_nhds.inclusion x)) ⋙
category_theory.limits.colim
/--
The stalk of a presheaf `F` at a point `x` is calculated as the colimit of the functor
nbhds x ⥤ opens F.X ⥤ C
-/
def stalk {C : Type u} [category_theory.category C] [category_theory.limits.has_colimits C]
{X : Top} (ℱ : presheaf C X) (x : ↥X) : C :=
category_theory.functor.obj (stalk_functor C x) ℱ
@[simp] theorem stalk_functor_obj {C : Type u} [category_theory.category C]
[category_theory.limits.has_colimits C] {X : Top} (ℱ : presheaf C X) (x : ↥X) :
category_theory.functor.obj (stalk_functor C x) ℱ = stalk ℱ x :=
rfl
/--
The germ of a section of a presheaf over an open at a point of that open.
-/
def germ {C : Type u} [category_theory.category C] [category_theory.limits.has_colimits C] {X : Top}
(F : presheaf C X) {U : topological_space.opens ↥X} (x : ↥U) :
category_theory.functor.obj F (opposite.op U) ⟶ stalk F ↑x :=
category_theory.limits.colimit.ι
(category_theory.functor.op (topological_space.open_nhds.inclusion (subtype.val x)) ⋙ F)
(opposite.op { val := U, property := sorry })
/-- For a `Type` valued presheaf, every point in a stalk is a germ. -/
theorem germ_exist {X : Top} (F : presheaf (Type v) X) (x : ↥X) (t : stalk F x) :
∃ (U : topological_space.opens ↥X),
∃ (m : x ∈ U),
∃ (s : category_theory.functor.obj F (opposite.op U)),
germ F { val := x, property := m } s = t :=
sorry
theorem germ_eq {X : Top} (F : presheaf (Type v) X) {U : topological_space.opens ↥X}
{V : topological_space.opens ↥X} (x : ↥X) (mU : x ∈ U) (mV : x ∈ V)
(s : category_theory.functor.obj F (opposite.op U))
(t : category_theory.functor.obj F (opposite.op V))
(h : germ F { val := x, property := mU } s = germ F { val := x, property := mV } t) :
∃ (W : topological_space.opens ↥X),
∃ (m : x ∈ W),
∃ (iU : W ⟶ U),
∃ (iV : W ⟶ V),
category_theory.functor.map F (category_theory.has_hom.hom.op iU) s =
category_theory.functor.map F (category_theory.has_hom.hom.op iV) t :=
sorry
@[simp] theorem germ_res {C : Type u} [category_theory.category C]
[category_theory.limits.has_colimits C] {X : Top} (F : presheaf C X)
{U : topological_space.opens ↥X} {V : topological_space.opens ↥X} (i : U ⟶ V) (x : ↥U) :
category_theory.functor.map F (category_theory.has_hom.hom.op i) ≫ germ F x =
germ F (coe_fn i x) :=
sorry
@[simp] theorem germ_res_apply {X : Top} (F : presheaf (Type v) X) {U : topological_space.opens ↥X}
{V : topological_space.opens ↥X} (i : U ⟶ V) (x : ↥U)
(f : category_theory.functor.obj F (opposite.op V)) :
germ F x (category_theory.functor.map F (category_theory.has_hom.hom.op i) f) =
germ F (coe_fn i x) f :=
sorry
/-- A variant when the open sets are written in `(opens X)ᵒᵖ`. -/
@[simp] theorem germ_res_apply' {X : Top} (F : presheaf (Type v) X)
{U : topological_space.opens ↥Xᵒᵖ} {V : topological_space.opens ↥Xᵒᵖ} (i : V ⟶ U)
(x : ↥(opposite.unop U)) (f : category_theory.functor.obj F V) :
germ F x (category_theory.functor.map F i f) =
germ F (coe_fn (category_theory.has_hom.hom.unop i) x) f :=
sorry
theorem germ_ext {X : Top} {D : Type u} [category_theory.category D]
[category_theory.concrete_category D] [category_theory.limits.has_colimits D] (F : presheaf D X)
{U : topological_space.opens ↥X} {V : topological_space.opens ↥X} {x : ↥X} {hxU : x ∈ U}
{hxV : x ∈ V} (W : topological_space.opens ↥X) (hxW : x ∈ W) (iWU : W ⟶ U) (iWV : W ⟶ V)
{sU : ↥(category_theory.functor.obj F (opposite.op U))}
{sV : ↥(category_theory.functor.obj F (opposite.op V))}
(ih :
coe_fn (category_theory.functor.map F (category_theory.has_hom.hom.op iWU)) sU =
coe_fn (category_theory.functor.map F (category_theory.has_hom.hom.op iWV)) sV) :
coe_fn (germ F { val := x, property := hxU }) sU =
coe_fn (germ F { val := x, property := hxV }) sV :=
sorry
theorem stalk_hom_ext {C : Type u} [category_theory.category C]
[category_theory.limits.has_colimits C] {X : Top} (F : presheaf C X) {x : ↥X} {Y : C}
{f₁ : stalk F x ⟶ Y} {f₂ : stalk F x ⟶ Y}
(ih :
∀ (U : topological_space.opens ↥X) (hxU : x ∈ U),
germ F { val := x, property := hxU } ≫ f₁ = germ F { val := x, property := hxU } ≫ f₂) :
f₁ = f₂ :=
sorry
def stalk_pushforward (C : Type u) [category_theory.category C]
[category_theory.limits.has_colimits C] {X : Top} {Y : Top} (f : X ⟶ Y) (ℱ : presheaf C X)
(x : ↥X) : stalk (f _* ℱ) (coe_fn f x) ⟶ stalk ℱ x :=
category_theory.functor.map category_theory.limits.colim
(category_theory.whisker_right
(category_theory.nat_trans.op
(category_theory.iso.inv (topological_space.open_nhds.inclusion_map_iso f x)))
ℱ) ≫
category_theory.limits.colimit.pre
(category_theory.functor.obj
(category_theory.functor.obj
(category_theory.whiskering_left (topological_space.open_nhds xᵒᵖ)
(topological_space.opens ↥Xᵒᵖ) C)
(category_theory.functor.op (topological_space.open_nhds.inclusion x)))
ℱ)
(category_theory.functor.op (topological_space.open_nhds.map f x))
-- Here are two other potential solutions, suggested by @fpvandoorn at
-- <https://github.com/leanprover-community/mathlib/pull/1018#discussion_r283978240>
-- However, I can't get the subsequent two proofs to work with either one.
-- def stalk_pushforward (f : X ⟶ Y) (ℱ : X.presheaf C) (x : X) : (f _* ℱ).stalk (f x) ⟶ ℱ.stalk x :=
-- colim.map ((functor.associator _ _ _).inv ≫
-- whisker_right (nat_trans.op (open_nhds.inclusion_map_iso f x).inv) ℱ) ≫
-- colimit.pre ((open_nhds.inclusion x).op ⋙ ℱ) (open_nhds.map f x).op
-- def stalk_pushforward (f : X ⟶ Y) (ℱ : X.presheaf C) (x : X) : (f _* ℱ).stalk (f x) ⟶ ℱ.stalk x :=
-- (colim.map (whisker_right (nat_trans.op (open_nhds.inclusion_map_iso f x).inv) ℱ) :
-- colim.obj ((open_nhds.inclusion (f x) ⋙ opens.map f).op ⋙ ℱ) ⟶ _) ≫
-- colimit.pre ((open_nhds.inclusion x).op ⋙ ℱ) (open_nhds.map f x).op
namespace stalk_pushforward
@[simp] theorem id (C : Type u) [category_theory.category C] [category_theory.limits.has_colimits C]
{X : Top} (ℱ : presheaf C X) (x : ↥X) :
stalk_pushforward C 𝟙 ℱ x =
category_theory.functor.map (stalk_functor C x)
(category_theory.iso.hom (pushforward.id ℱ)) :=
sorry
-- This proof is sadly not at all robust:
-- having to use `erw` at all is a bad sign.
@[simp] theorem comp (C : Type u) [category_theory.category C]
[category_theory.limits.has_colimits C] {X : Top} {Y : Top} {Z : Top} (ℱ : presheaf C X)
(f : X ⟶ Y) (g : Y ⟶ Z) (x : ↥X) :
stalk_pushforward C (f ≫ g) ℱ x =
stalk_pushforward C g (f _* ℱ) (coe_fn f x) ≫ stalk_pushforward C f ℱ x :=
sorry
end Mathlib |
a6fcc4336283dce7f141ece263cacdbaa90cf289 | b7f22e51856f4989b970961f794f1c435f9b8f78 | /tests/lean/K_bug.lean | 6408d202a744877d900357f469f7cc0bfad64dca | [
"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 | 374 | lean | open eq.ops
inductive Nat : Type :=
zero : Nat |
succ : Nat → Nat
namespace Nat
definition pred (n : Nat) := Nat.rec zero (fun m x, m) n
theorem pred_succ (n : Nat) : pred (succ n) = n := rfl
theorem succ.inj {n m : Nat} (H : succ n = succ m) : n = m
:= calc
n = pred (succ n) : pred_succ n
... = pred (succ m) : {H}
... = m : pred_succ m
end Nat
|
668b000399e80336ba123fcdc7b8b8ba317dcc42 | 64874bd1010548c7f5a6e3e8902efa63baaff785 | /tests/lean/run/nat_bug7.lean | b59f7297a0f5fe98db732ef54d5126553ccf5c04 | [
"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 | 431 | lean | import logic
namespace experiment
inductive nat : Type :=
zero : nat,
succ : nat → nat
namespace nat
definition add (x y : nat) : nat := nat.rec x (λn r, succ r) y
infixl `+` := add
axiom add_right_comm (n m k : nat) : n + m + k = n + k + m
open eq
print "==========================="
theorem bug (a b c d : nat) : a + b + c + d = a + c + b + d
:= subst (add_right_comm _ _ _) (eq.refl (a + b + c + d))
end nat
end experiment
|
a3eedd8b1ceca1d8230d2fcead6dca6679b2f9de | 26ac254ecb57ffcb886ff709cf018390161a9225 | /src/algebra/category/Group/limits.lean | 66af09305901f0ea59b1ede20127a032e9300837 | [
"Apache-2.0"
] | permissive | eric-wieser/mathlib | 42842584f584359bbe1fc8b88b3ff937c8acd72d | d0df6b81cd0920ad569158c06a3fd5abb9e63301 | refs/heads/master | 1,669,546,404,255 | 1,595,254,668,000 | 1,595,254,668,000 | 281,173,504 | 0 | 0 | Apache-2.0 | 1,595,263,582,000 | 1,595,263,581,000 | null | UTF-8 | Lean | false | false | 4,252 | 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.category.Group.basic
import category_theory.limits.types
import category_theory.limits.preserves
import algebra.pi_instances
/-!
# The category of abelian groups 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.
## Further work
A lot of this should be generalised / automated, as it's quite common for concrete
categories that the forgetful functor preserves limits.
-/
open category_theory
open category_theory.limits
universe u
namespace AddCommGroup
variables {J : Type u} [small_category J]
instance add_comm_group_obj (F : J ⥤ AddCommGroup) (j) :
add_comm_group ((F ⋙ forget AddCommGroup).obj j) :=
by { change add_comm_group (F.obj j), apply_instance }
instance sections_add_submonoid (F : J ⥤ AddCommGroup) :
is_add_submonoid (F ⋙ forget AddCommGroup).sections :=
{ zero_mem := λ j j' f,
begin
erw [functor.comp_map, forget_map_eq_coe, (F.map f).map_zero],
refl,
end,
add_mem := λ a b ah bh j j' f,
begin
erw [functor.comp_map, forget_map_eq_coe, (F.map f).map_add],
dsimp [functor.sections] at ah,
rw ah f,
dsimp [functor.sections] at bh,
rw bh f,
refl,
end }
instance sections_add_subgroup (F : J ⥤ AddCommGroup) :
is_add_subgroup (F ⋙ forget AddCommGroup).sections :=
{ neg_mem := λ a ah j j' f,
begin
erw [functor.comp_map, forget_map_eq_coe, (F.map f).map_neg],
dsimp [functor.sections] at ah,
rw ah f,
refl,
end,
..(AddCommGroup.sections_add_submonoid F) }
instance limit_add_comm_group (F : J ⥤ AddCommGroup) :
add_comm_group (limit (F ⋙ forget AddCommGroup)) :=
@subtype.add_comm_group ((Π (j : J), (F ⋙ forget _).obj j)) (by apply_instance) _
(by convert (AddCommGroup.sections_add_subgroup F))
/-- `limit.π (F ⋙ forget AddCommGroup) j` as a `add_monoid_hom`. -/
def limit_π_add_monoid_hom (F : J ⥤ AddCommGroup) (j) :
limit (F ⋙ forget AddCommGroup) →+ (F ⋙ forget AddCommGroup).obj j :=
{ to_fun := limit.π (F ⋙ forget AddCommGroup) j,
map_zero' := by { simp only [types.types_limit_π], refl },
map_add' := λ x y, by { simp only [types.types_limit_π], refl } }
namespace AddCommGroup_has_limits
-- The next two definitions are used in the construction of `has_limits AddCommGroup`.
-- 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 `AddCommGroup`.
(Internal use only; use the limits API.)
-/
def limit (F : J ⥤ AddCommGroup) : cone F :=
{ X := ⟨limit (F ⋙ forget _), by apply_instance⟩,
π :=
{ app := limit_π_add_monoid_hom F,
naturality' := λ j j' f,
add_monoid_hom.coe_inj ((limit.cone (F ⋙ forget _)).π.naturality f) } }
/--
Witness that the limit cone in `AddCommGroup` is a limit cone.
(Internal use only; use the limits API.)
-/
def limit_is_limit (F : J ⥤ AddCommGroup) : is_limit (limit F) :=
begin
refine is_limit.of_faithful
(forget AddCommGroup) (limit.is_limit _)
(λ s, ⟨_, _, _⟩) (λ s, rfl); dsimp,
{ apply subtype.eq, funext, dsimp,
erw (s.π.app j).map_zero, refl },
{ intros x y, apply subtype.eq, funext, dsimp,
erw (s.π.app j).map_add, refl }
end
end AddCommGroup_has_limits
open AddCommGroup_has_limits
/-- The category of abelian groups has all limits. -/
instance AddCommGroup_has_limits : has_limits AddCommGroup :=
{ has_limits_of_shape := λ J 𝒥,
{ has_limit := λ F, by exactI
{ cone := limit F,
is_limit := limit_is_limit F } } }
/--
The forgetful functor from abelian groups to types preserves all limits. (That is, the underlying
types could have been computed instead as limits in the category of types.)
-/
instance forget_preserves_limits : preserves_limits (forget AddCommGroup) :=
{ preserves_limits_of_shape := λ J 𝒥,
{ preserves_limit := λ F,
by exactI preserves_limit_of_preserves_limit_cone
(limit.is_limit F) (limit.is_limit (F ⋙ forget _)) } }
end AddCommGroup
|
a93f9670ef2f96590774d1ea1d711f7bb5c6e3ea | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/category_theory/limits/constructions/weakly_initial.lean | 54e737517a14ce584ab79b74bb9c186d497929cd | [
"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,562 | lean | /-
Copyright (c) 2021 Bhavik Mehta. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Bhavik Mehta
-/
import category_theory.limits.shapes.wide_equalizers
import category_theory.limits.shapes.products
import category_theory.limits.shapes.terminal
/-!
# Constructions related to weakly initial objects
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
This file gives constructions related to weakly initial objects, namely:
* If a category has small products and a small weakly initial set of objects, then it has a weakly
initial object.
* If a category has wide equalizers and a weakly initial object, then it has an initial object.
These are primarily useful to show the General Adjoint Functor Theorem.
-/
universes v u
namespace category_theory
open limits
variables {C : Type u} [category.{v} C]
/--
If `C` has (small) products and a small weakly initial set of objects, then it has a weakly initial
object.
-/
lemma has_weakly_initial_of_weakly_initial_set_and_has_products [has_products.{v} C]
{ι : Type v} {B : ι → C} (hB : ∀ (A : C), ∃ i, nonempty (B i ⟶ A)) :
∃ (T : C), ∀ X, nonempty (T ⟶ X) :=
⟨∏ B, λ X, ⟨pi.π _ _ ≫ (hB X).some_spec.some⟩⟩
/--
If `C` has (small) wide equalizers and a weakly initial object, then it has an initial object.
The initial object is constructed as the wide equalizer of all endomorphisms on the given weakly
initial object.
-/
lemma has_initial_of_weakly_initial_and_has_wide_equalizers [has_wide_equalizers.{v} C]
{T : C} (hT : ∀ X, nonempty (T ⟶ X)) :
has_initial C :=
begin
let endos := T ⟶ T,
let i := wide_equalizer.ι (id : endos → endos),
haveI : nonempty endos := ⟨𝟙 _⟩,
have : ∀ (X : C), unique (wide_equalizer (id : endos → endos) ⟶ X),
{ intro X,
refine ⟨⟨i ≫ classical.choice (hT X)⟩, λ a, _⟩,
let E := equalizer a (i ≫ classical.choice (hT _)),
let e : E ⟶ wide_equalizer id := equalizer.ι _ _,
let h : T ⟶ E := classical.choice (hT E),
have : ((i ≫ h) ≫ e) ≫ i = i ≫ 𝟙 _,
{ rw [category.assoc, category.assoc],
apply wide_equalizer.condition (id : endos → endos) (h ≫ e ≫ i) },
rw [category.comp_id, cancel_mono_id i] at this,
haveI : is_split_epi e := is_split_epi.mk' ⟨i ≫ h, this⟩,
rw ←cancel_epi e,
apply equalizer.condition },
exactI has_initial_of_unique (wide_equalizer (id : endos → endos)),
end
end category_theory
|
b67ddfabab59c62768000d9442f882dc1d3763b7 | bbecf0f1968d1fba4124103e4f6b55251d08e9c4 | /src/linear_algebra/general_linear_group.lean | dea2ab06557de7b887259260cb144ab8a81cd652 | [
"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 | 5,769 | lean | /-
Copyright (c) 2021 Chris Birkbeck. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Birkbeck
-/
import linear_algebra.matrix
import linear_algebra.matrix.nonsingular_inverse
import linear_algebra.special_linear_group
import linear_algebra.determinant
/-!
# The General Linear group $GL(n, R)$
This file defines the elements of the General Linear group `general_linear_group n R`,
consisting of all invertible `n` by `n` `R`-matrices.
## Main definitions
* `matrix.general_linear_group` is the type of matrices over R which are units in the matrix ring.
* `matrix.GL_pos` gives the subgroup of matrices with
positive determinant (over a linear ordered ring).
## Tags
matrix group, group, matrix inverse
-/
namespace matrix
universes u v
open_locale matrix
open linear_map
/-- `GL n R` is the group of `n` by `n` `R`-matrices with unit determinant.
Defined as a subtype of matrices-/
abbreviation general_linear_group (n : Type u) (R : Type v)
[decidable_eq n] [fintype n] [comm_ring R] : Type* := units (matrix n n R)
notation `GL` := general_linear_group
namespace general_linear_group
variables {n : Type u} [decidable_eq n] [fintype n] {R : Type v} [comm_ring R]
/-- The determinant of a unit matrix is itself a unit. -/
@[simps]
def det : GL n R →* units R :=
{ to_fun := λ A,
{ val := (↑A : matrix n n R).det,
inv := (↑(A⁻¹) : matrix n n R).det,
val_inv := by rw [←det_mul, ←mul_eq_mul, A.mul_inv, det_one],
inv_val := by rw [←det_mul, ←mul_eq_mul, A.inv_mul, det_one]},
map_one' := units.ext det_one,
map_mul' := λ A B, units.ext $ det_mul _ _ }
/--The `GL n R` and `general_linear_group R n` groups are multiplicatively equivalent-/
def to_lin : (GL n R) ≃* (linear_map.general_linear_group R (n → R)) :=
units.map_equiv to_lin_alg_equiv'.to_mul_equiv
/--Given a matrix with invertible determinant we get an element of `GL n R`-/
def mk' (A : matrix n n R) (h : invertible (matrix.det A)) : GL n R :=
unit_of_det_invertible A
/--Given a matrix with unit determinant we get an element of `GL n R`-/
noncomputable def mk'' (A : matrix n n R) (h : is_unit (matrix.det A)) : GL n R :=
nonsing_inv_unit A h
instance coe_fun : has_coe_to_fun (GL n R) :=
{ F := λ _, n → n → R,
coe := λ A, A.val }
lemma ext_iff (A B : GL n R) : A = B ↔ (∀ i j, (A : matrix n n R) i j = (B : matrix n n R) i j) :=
units.ext_iff.trans matrix.ext_iff.symm
/-- Not marked `@[ext]` as the `ext` tactic already solves this. -/
lemma ext ⦃A B : GL n R⦄ (h : ∀ i j, (A : matrix n n R) i j = (B : matrix n n R) i j) :
A = B :=
units.ext $ matrix.ext h
section coe_lemmas
variables (A B : GL n R)
@[simp] lemma coe_fn_eq_coe : ⇑A = (↑A : matrix n n R) := rfl
@[simp] lemma coe_mul : ↑(A * B) = (↑A : matrix n n R) ⬝ (↑B : matrix n n R) := rfl
@[simp] lemma coe_one : ↑(1 : GL n R) = (1 : matrix n n R) := rfl
lemma coe_inv : ↑(A⁻¹) = (↑A : matrix n n R)⁻¹ :=
begin
letI := A.invertible,
exact inv_eq_nonsing_inv_of_invertible (↑A : matrix n n R),
end
end coe_lemmas
end general_linear_group
namespace special_linear_group
variables {n : Type u} [decidable_eq n] [fintype n] {R : Type v} [comm_ring R]
instance has_coe_to_general_linear_group : has_coe (special_linear_group n R) (GL n R) :=
⟨λ A, ⟨↑A, ↑(A⁻¹), congr_arg coe (mul_right_inv A), congr_arg coe (mul_left_inv A)⟩⟩
end special_linear_group
section
variables {n : Type u} {R : Type v} [decidable_eq n] [fintype n] [linear_ordered_comm_ring R ]
section
variables (n R)
/-- This is the subgroup of `nxn` matrices with entries over a
linear ordered ring and positive determinant. -/
def GL_pos : subgroup (GL n R) :=
(units.pos_subgroup R).comap general_linear_group.det
end
@[simp] lemma mem_GL_pos (A : GL n R) : A ∈ GL_pos n R ↔ 0 < (A.det : R) := iff.rfl
end
section has_neg
variables {n : Type u} {R : Type v} [decidable_eq n] [fintype n] [linear_ordered_comm_ring R ]
[fact (even (fintype.card n))]
/-- Formal operation of negation on general linear group on even cardinality `n` given by negating
each element. -/
instance : has_neg (GL_pos n R) :=
⟨λ g,
⟨- g,
begin
simp only [mem_GL_pos, general_linear_group.coe_det_apply, units.coe_neg],
have := det_smul g (-1),
simp only [general_linear_group.coe_fn_eq_coe, one_smul, coe_fn_coe_base, neg_smul] at this,
rw this,
simp [nat.neg_one_pow_of_even (fact.out (even (fintype.card n)))],
have gdet := g.property,
simp only [mem_GL_pos, general_linear_group.coe_det_apply, subtype.val_eq_coe] at gdet,
exact gdet,
end⟩⟩
@[simp] lemma GL_pos_coe_neg (g : GL_pos n R) : ↑(- g) = - (↑g : matrix n n R) :=
rfl
@[simp]lemma GL_pos_neg_elt (g : GL_pos n R): ∀ i j, ( ↑(-g): matrix n n R) i j= - (g i j):=
begin
simp,
end
end has_neg
namespace special_linear_group
variables {n : Type u} [decidable_eq n] [fintype n] {R : Type v} [linear_ordered_comm_ring R]
/-- `special_linear_group n R` embeds into `GL_pos n R` -/
def to_GL_pos : special_linear_group n R →* GL_pos n R :=
{ to_fun := λ A, ⟨(A : GL n R), show 0 < (↑A : matrix n n R).det, from A.prop.symm ▸ zero_lt_one⟩,
map_one' := subtype.ext $ units.ext $ rfl,
map_mul' := λ A₁ A₂, subtype.ext $ units.ext $ rfl }
instance : has_coe (special_linear_group n R) (GL_pos n R) := ⟨to_GL_pos⟩
lemma coe_eq_to_GL_pos : (coe : special_linear_group n R → GL_pos n R) = to_GL_pos := rfl
lemma to_GL_pos_injective :
function.injective (to_GL_pos : special_linear_group n R → GL_pos n R) :=
(show function.injective ((coe : GL_pos n R → matrix n n R) ∘ to_GL_pos),
from subtype.coe_injective).of_comp
end special_linear_group
end matrix
|
b256255a7876fa65964e46397f73d3795571509a | 9cb9db9d79fad57d80ca53543dc07efb7c4f3838 | /src/pseudo_normed_group/with_Tinv.lean | de6f7dc4d71c12ae3709b9e0a7d36114a9132ba9 | [] | no_license | mr-infty/lean-liquid | 3ff89d1f66244b434654c59bdbd6b77cb7de0109 | a8db559073d2101173775ccbd85729d3a4f1ed4d | refs/heads/master | 1,678,465,145,334 | 1,614,565,310,000 | 1,614,565,310,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 7,037 | lean | import pseudo_normed_group.profinitely_filtered
open pseudo_normed_group profinitely_filtered_pseudo_normed_group
open_locale nnreal big_operators
local attribute [instance] type_pow
/-- A *profinitely filtered pseudo normed topological group with action by `T⁻¹`* is
a profinitely filtered pseudo normed topological group `M` together with a
nonnegative real `r` and homomorphism `Tinv : M → M` such that
`Tinv x ∈ filtration M (r⁻¹ * c)` for all `x ∈ filtration M c`.
Morphisms are continuous and strict homomorphisms. -/
class profinitely_filtered_pseudo_normed_group_with_Tinv (r : out_param $ ℝ≥0) (M : Type*)
extends profinitely_filtered_pseudo_normed_group M :=
(Tinv : profinitely_filtered_pseudo_normed_group_hom M M)
(Tinv_mem_filtration : ∀ c x, x ∈ filtration c → Tinv x ∈ filtration (r⁻¹ * c))
namespace profinitely_filtered_pseudo_normed_group_with_Tinv
variables {r : ℝ≥0} {M M₁ M₂ M₃ : Type*}
variables [profinitely_filtered_pseudo_normed_group_with_Tinv r M]
variables [profinitely_filtered_pseudo_normed_group_with_Tinv r M₁]
variables [profinitely_filtered_pseudo_normed_group_with_Tinv r M₂]
variables [profinitely_filtered_pseudo_normed_group_with_Tinv r M₃]
@[simps]
def Tinv₀ (c : ℝ≥0) (x : filtration M c) : filtration M (r⁻¹ * c) :=
⟨Tinv (x : M), Tinv_mem_filtration _ _ x.2⟩
lemma Tinv₀_continuous (c : ℝ≥0) : continuous (@Tinv₀ r M _ c) :=
Tinv.continuous _ $ λ x, rfl
end profinitely_filtered_pseudo_normed_group_with_Tinv
section
set_option old_structure_cmd true
open profinitely_filtered_pseudo_normed_group_with_Tinv
structure profinitely_filtered_pseudo_normed_group_with_Tinv_hom (r : ℝ≥0) (M₁ M₂ : Type*)
[profinitely_filtered_pseudo_normed_group_with_Tinv r M₁]
[profinitely_filtered_pseudo_normed_group_with_Tinv r M₂]
extends M₁ →+ M₂ :=
(strict' : ∀ ⦃c x⦄, x ∈ filtration M₁ c → to_fun x ∈ filtration M₂ c)
(continuous' : ∀ c, @continuous (filtration M₁ c) (filtration M₂ c) _ _ $
λ x, ⟨to_fun x, strict' x.2⟩)
(map_Tinv' : ∀ x, to_fun (Tinv x) = Tinv (to_fun x))
end
attribute [nolint doc_blame] profinitely_filtered_pseudo_normed_group_with_Tinv_hom.mk
profinitely_filtered_pseudo_normed_group_with_Tinv_hom.to_add_monoid_hom
namespace profinitely_filtered_pseudo_normed_group_with_Tinv_hom
open profinitely_filtered_pseudo_normed_group_with_Tinv
variables {r : ℝ≥0} {M M₁ M₂ M₃ : Type*}
variables [profinitely_filtered_pseudo_normed_group_with_Tinv r M]
variables [profinitely_filtered_pseudo_normed_group_with_Tinv r M₁]
variables [profinitely_filtered_pseudo_normed_group_with_Tinv r M₂]
variables [profinitely_filtered_pseudo_normed_group_with_Tinv r M₃]
variables (f g : profinitely_filtered_pseudo_normed_group_with_Tinv_hom r M₁ M₂)
instance : has_coe_to_fun (profinitely_filtered_pseudo_normed_group_with_Tinv_hom r M₁ M₂) :=
⟨_, profinitely_filtered_pseudo_normed_group_with_Tinv_hom.to_fun⟩
@[simp] lemma coe_mk (f) (h₁) (h₂) (h₃) (h₄) (h₅) :
⇑(⟨f, h₁, h₂, h₃, h₄, h₅⟩ : profinitely_filtered_pseudo_normed_group_with_Tinv_hom r M₁ M₂) = f :=
rfl
@[simp] lemma mk_to_monoid_hom (f) (h₁) (h₂) (h₃) (h₄) (h₅) :
(⟨f, h₁, h₂, h₃, h₄, h₅⟩ :
profinitely_filtered_pseudo_normed_group_with_Tinv_hom r M₁ M₂).to_add_monoid_hom =
⟨f, h₁, h₂⟩ := rfl
@[simp] lemma map_zero : f 0 = 0 := f.to_add_monoid_hom.map_zero
@[simp] lemma map_add (x y) : f (x + y) = f x + f y := f.to_add_monoid_hom.map_add _ _
@[simp] lemma map_sum {ι : Type*} (x : ι → M₁) (s : finset ι) :
f (∑ i in s, x i) = ∑ i in s, f (x i) :=
f.to_add_monoid_hom.map_sum _ _
@[simp] lemma map_sub (x y) : f (x - y) = f x - f y := f.to_add_monoid_hom.map_sub _ _
@[simp] lemma map_neg (x) : f (-x) = -(f x) := f.to_add_monoid_hom.map_neg _
lemma strict : ∀ ⦃c x⦄, x ∈ filtration M₁ c → f x ∈ filtration M₂ c := f.strict'
/-- `f.level c` is the function `filtration M₁ c → filtration M₂ c`
induced by a `profinitely_filtered_pseudo_normed_group_with_Tinv_hom M₁ M₂`. -/
@[simps] def level (c : ℝ≥0) (x : filtration M₁ c) : filtration M₂ c := ⟨f x, f.strict x.2⟩
lemma level_continuous (c : ℝ≥0) : continuous (f.level c) := f.continuous' c
lemma map_Tinv (x : M₁) : f (Tinv x) = Tinv (f x) := f.map_Tinv' x
variables {f g}
@[ext] theorem ext (H : ∀ x, f x = g x) : f = g :=
by cases f; cases g; congr'; exact funext H
instance : has_zero (profinitely_filtered_pseudo_normed_group_with_Tinv_hom r M₁ M₂) :=
⟨{ strict' := λ c x h, zero_mem_filtration _,
continuous' := λ c, @continuous_const _ (filtration M₂ c) _ _ 0,
map_Tinv' := λ x, show 0 = Tinv (0 : M₂), from Tinv.map_zero.symm,
.. (0 : M₁ →+ M₂) }⟩
instance : inhabited (profinitely_filtered_pseudo_normed_group_with_Tinv_hom r M₁ M₂) := ⟨0⟩
lemma coe_inj ⦃f g : profinitely_filtered_pseudo_normed_group_with_Tinv_hom r M₁ M₂⦄
(h : (f : M₁ → M₂) = g) :
f = g :=
by cases f; cases g; cases h; refl
/-- The identity function as `profinitely_filtered_pseudo_normed_group_with_Tinv_hom`. -/
@[simps] def id : profinitely_filtered_pseudo_normed_group_with_Tinv_hom r M M :=
{ strict' := λ c x, id,
continuous' := λ c, by { convert continuous_id, ext, refl },
map_Tinv' := λ x, rfl,
.. add_monoid_hom.id _ }
/-- The composition of `profinitely_filtered_pseudo_normed_group_with_Tinv_hom`s. -/
@[simps] def comp
(g : profinitely_filtered_pseudo_normed_group_with_Tinv_hom r M₂ M₃)
(f : profinitely_filtered_pseudo_normed_group_with_Tinv_hom r M₁ M₂) :
profinitely_filtered_pseudo_normed_group_with_Tinv_hom r M₁ M₃ :=
{ strict' := λ c x hx, g.strict (f.strict hx),
continuous' := λ c, (g.level_continuous c).comp (f.level_continuous c),
map_Tinv' := λ x,
calc g (f (Tinv x)) = g (Tinv (f x)) : by rw f.map_Tinv
... = Tinv (g (f x)) : by rw g.map_Tinv,
.. (g.to_add_monoid_hom.comp f.to_add_monoid_hom) }
/-- The `profinitely_filtered_pseudo_normed_group_hom` underlying a
`profinitely_filtered_pseudo_normed_group_with_Tinv_hom`. -/
def to_profinitely_filtered_pseudo_normed_group_hom :
profinitely_filtered_pseudo_normed_group_hom M₁ M₂ :=
profinitely_filtered_pseudo_normed_group_hom.mk' f.to_add_monoid_hom
begin
refine ⟨1, λ c, ⟨_, _⟩⟩,
{ rw one_mul, intros x h, exact f.strict h },
haveI : fact (1 * c ≤ c) := by { apply le_of_eq, rw one_mul },
rw (embedding_cast_le (1 * c) c).continuous_iff,
exact f.level_continuous c
end
end profinitely_filtered_pseudo_normed_group_with_Tinv_hom
namespace punit
instance profinitely_filtered_pseudo_normed_group_with_Tinv (r : ℝ≥0) :
profinitely_filtered_pseudo_normed_group_with_Tinv r punit :=
{ Tinv := profinitely_filtered_pseudo_normed_group_hom.id,
Tinv_mem_filtration := λ c x h, set.mem_univ _,
.. punit.profinitely_filtered_pseudo_normed_group }
end punit
|
a03536b582dfabbd569359729566142e4ece1c08 | 94e33a31faa76775069b071adea97e86e218a8ee | /src/algebra/hom/group.lean | c9a8ad1a93052b078ed7c49aeb61c3a34f4c97b8 | [
"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 | 52,300 | lean | /-
Copyright (c) 2018 Patrick Massot. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Massot, Kevin Buzzard, Scott Morrison, Johan Commelin, Chris Hughes,
Johannes Hölzl, Yury Kudryashov
-/
import algebra.group.commute
import algebra.group_with_zero.defs
import data.fun_like.basic
/-!
# Monoid and group homomorphisms
This file defines the bundled structures for monoid and group homomorphisms. Namely, we define
`monoid_hom` (resp., `add_monoid_hom`) to be bundled homomorphisms between multiplicative (resp.,
additive) monoids or groups.
We also define coercion to a function, and usual operations: composition, identity homomorphism,
pointwise multiplication and pointwise inversion.
This file also defines the lesser-used (and notation-less) homomorphism types which are used as
building blocks for other homomorphisms:
* `zero_hom`
* `one_hom`
* `add_hom`
* `mul_hom`
* `monoid_with_zero_hom`
## Notations
* `→+`: Bundled `add_monoid` homs. Also use for `add_group` homs.
* `→*`: Bundled `monoid` homs. Also use for `group` homs.
* `→*₀`: Bundled `monoid_with_zero` homs. Also use for `group_with_zero` homs.
* `→ₙ*`: Bundled `semigroup` homs.
## Implementation notes
There's a coercion from bundled homs to fun, and the canonical
notation is to use the bundled hom as a function via this coercion.
There is no `group_hom` -- the idea is that `monoid_hom` is used.
The constructor for `monoid_hom` needs a proof of `map_one` as well
as `map_mul`; a separate constructor `monoid_hom.mk'` will construct
group homs (i.e. monoid homs between groups) given only a proof
that multiplication is preserved,
Implicit `{}` brackets are often used instead of type class `[]` brackets. This is done when the
instances can be inferred because they are implicit arguments to the type `monoid_hom`. When they
can be inferred from the type it is faster to use this method than to use type class inference.
Historically this file also included definitions of unbundled homomorphism classes; they were
deprecated and moved to `deprecated/group`.
## Tags
monoid_hom, add_monoid_hom
-/
variables {α β M N P : Type*} -- monoids
variables {G : Type*} {H : Type*} -- groups
variables {F : Type*} -- homs
-- for easy multiple inheritance
set_option old_structure_cmd true
section zero
/-- `zero_hom M N` is the type of functions `M → N` that preserve zero.
When possible, instead of parametrizing results over `(f : zero_hom M N)`,
you should parametrize over `(F : Type*) [zero_hom_class F M N] (f : F)`.
When you extend this structure, make sure to also extend `zero_hom_class`.
-/
structure zero_hom (M : Type*) (N : Type*) [has_zero M] [has_zero N] :=
(to_fun : M → N)
(map_zero' : to_fun 0 = 0)
/-- `zero_hom_class F M N` states that `F` is a type of zero-preserving homomorphisms.
You should extend this typeclass when you extend `zero_hom`.
-/
class zero_hom_class (F : Type*) (M N : out_param $ Type*)
[has_zero M] [has_zero N] extends fun_like F M (λ _, N) :=
(map_zero : ∀ (f : F), f 0 = 0)
-- Instances and lemmas are defined below through `@[to_additive]`.
end zero
section add
/-- `add_hom M N` is the type of functions `M → N` that preserve addition.
When possible, instead of parametrizing results over `(f : add_hom M N)`,
you should parametrize over `(F : Type*) [add_hom_class F M N] (f : F)`.
When you extend this structure, make sure to extend `add_hom_class`.
-/
structure add_hom (M : Type*) (N : Type*) [has_add M] [has_add N] :=
(to_fun : M → N)
(map_add' : ∀ x y, to_fun (x + y) = to_fun x + to_fun y)
/-- `add_hom_class F M N` states that `F` is a type of addition-preserving homomorphisms.
You should declare an instance of this typeclass when you extend `add_hom`.
-/
class add_hom_class (F : Type*) (M N : out_param $ Type*)
[has_add M] [has_add N] extends fun_like F M (λ _, N) :=
(map_add : ∀ (f : F) (x y : M), f (x + y) = f x + f y)
-- Instances and lemmas are defined below through `@[to_additive]`.
end add
section add_zero
/-- `M →+ N` is the type of functions `M → N` that preserve the `add_zero_class` structure.
`add_monoid_hom` is also used for group homomorphisms.
When possible, instead of parametrizing results over `(f : M →+ N)`,
you should parametrize over `(F : Type*) [add_monoid_hom_class F M N] (f : F)`.
When you extend this structure, make sure to extend `add_monoid_hom_class`.
-/
@[ancestor zero_hom add_hom]
structure add_monoid_hom (M : Type*) (N : Type*) [add_zero_class M] [add_zero_class N]
extends zero_hom M N, add_hom M N
attribute [nolint doc_blame] add_monoid_hom.to_add_hom
attribute [nolint doc_blame] add_monoid_hom.to_zero_hom
infixr ` →+ `:25 := add_monoid_hom
/-- `add_monoid_hom_class F M N` states that `F` is a type of `add_zero_class`-preserving
homomorphisms.
You should also extend this typeclass when you extend `add_monoid_hom`.
-/
@[ancestor add_hom_class zero_hom_class]
class add_monoid_hom_class (F : Type*) (M N : out_param $ Type*)
[add_zero_class M] [add_zero_class N]
extends add_hom_class F M N, zero_hom_class F M N
-- Instances and lemmas are defined below through `@[to_additive]`.
end add_zero
section one
variables [has_one M] [has_one N]
/-- `one_hom M N` is the type of functions `M → N` that preserve one.
When possible, instead of parametrizing results over `(f : one_hom M N)`,
you should parametrize over `(F : Type*) [one_hom_class F M N] (f : F)`.
When you extend this structure, make sure to also extend `one_hom_class`.
-/
@[to_additive]
structure one_hom (M : Type*) (N : Type*) [has_one M] [has_one N] :=
(to_fun : M → N)
(map_one' : to_fun 1 = 1)
/-- `one_hom_class F M N` states that `F` is a type of one-preserving homomorphisms.
You should extend this typeclass when you extend `one_hom`.
-/
@[to_additive]
class one_hom_class (F : Type*) (M N : out_param $ Type*)
[has_one M] [has_one N]
extends fun_like F M (λ _, N) :=
(map_one : ∀ (f : F), f 1 = 1)
@[to_additive]
instance one_hom.one_hom_class : one_hom_class (one_hom M N) M N :=
{ coe := one_hom.to_fun,
coe_injective' := λ f g h, by cases f; cases g; congr',
map_one := one_hom.map_one' }
@[simp, to_additive] lemma map_one [one_hom_class F M N] (f : F) : f 1 = 1 :=
one_hom_class.map_one f
@[to_additive] lemma map_eq_one_iff [one_hom_class F M N] (f : F)
(hf : function.injective f) {x : M} : f x = 1 ↔ x = 1 :=
hf.eq_iff' (map_one f)
@[to_additive]
lemma map_ne_one_iff {R S F : Type*} [has_one R] [has_one S] [one_hom_class F R S]
(f : F) (hf : function.injective f) {x : R} :
f x ≠ 1 ↔ x ≠ 1 :=
(map_eq_one_iff f hf).not
@[to_additive]
lemma ne_one_of_map {R S F : Type*} [has_one R] [has_one S] [one_hom_class F R S]
{f : F} {x : R} (hx : f x ≠ 1) : x ≠ 1 :=
ne_of_apply_ne f $ ne_of_ne_of_eq hx (map_one f).symm
@[to_additive]
instance [one_hom_class F M N] : has_coe_t F (one_hom M N) :=
⟨λ f, { to_fun := f, map_one' := map_one f }⟩
end one
section mul
variables [has_mul M] [has_mul N]
/-- `M →ₙ* N` is the type of functions `M → N` that preserve multiplication. The `ₙ` in the notation
stands for "non-unital" because it is intended to match the notation for `non_unital_alg_hom` and
`non_unital_ring_hom`, so a `mul_hom` is a non-unital monoid hom.
When possible, instead of parametrizing results over `(f : M →ₙ* N)`,
you should parametrize over `(F : Type*) [mul_hom_class F M N] (f : F)`.
When you extend this structure, make sure to extend `mul_hom_class`.
-/
@[to_additive]
structure mul_hom (M : Type*) (N : Type*) [has_mul M] [has_mul N] :=
(to_fun : M → N)
(map_mul' : ∀ x y, to_fun (x * y) = to_fun x * to_fun y)
infixr ` →ₙ* `:25 := mul_hom
/-- `mul_hom_class F M N` states that `F` is a type of multiplication-preserving homomorphisms.
You should declare an instance of this typeclass when you extend `mul_hom`.
-/
@[to_additive]
class mul_hom_class (F : Type*) (M N : out_param $ Type*)
[has_mul M] [has_mul N] extends fun_like F M (λ _, N) :=
(map_mul : ∀ (f : F) (x y : M), f (x * y) = f x * f y)
@[to_additive]
instance mul_hom.mul_hom_class : mul_hom_class (M →ₙ* N) M N :=
{ coe := mul_hom.to_fun,
coe_injective' := λ f g h, by cases f; cases g; congr',
map_mul := mul_hom.map_mul' }
@[simp, to_additive] lemma map_mul [mul_hom_class F M N] (f : F) (x y : M) :
f (x * y) = f x * f y :=
mul_hom_class.map_mul f x y
@[to_additive]
instance [mul_hom_class F M N] : has_coe_t F (M →ₙ* N) :=
⟨λ f, { to_fun := f, map_mul' := map_mul f }⟩
end mul
section mul_one
variables [mul_one_class M] [mul_one_class N]
/-- `M →* N` is the type of functions `M → N` that preserve the `monoid` structure.
`monoid_hom` is also used for group homomorphisms.
When possible, instead of parametrizing results over `(f : M →+ N)`,
you should parametrize over `(F : Type*) [monoid_hom_class F M N] (f : F)`.
When you extend this structure, make sure to extend `monoid_hom_class`.
-/
@[ancestor one_hom mul_hom, to_additive]
structure monoid_hom (M : Type*) (N : Type*) [mul_one_class M] [mul_one_class N]
extends one_hom M N, M →ₙ* N
attribute [nolint doc_blame] monoid_hom.to_mul_hom
attribute [nolint doc_blame] monoid_hom.to_one_hom
infixr ` →* `:25 := monoid_hom
/-- `monoid_hom_class F M N` states that `F` is a type of `monoid`-preserving homomorphisms.
You should also extend this typeclass when you extend `monoid_hom`. -/
@[ancestor mul_hom_class one_hom_class, to_additive
"`add_monoid_hom_class F M N` states that `F` is a type of `add_monoid`-preserving homomorphisms.
You should also extend this typeclass when you extend `add_monoid_hom`."]
class monoid_hom_class (F : Type*) (M N : out_param $ Type*)
[mul_one_class M] [mul_one_class N]
extends mul_hom_class F M N, one_hom_class F M N
@[to_additive]
instance monoid_hom.monoid_hom_class : monoid_hom_class (M →* N) M N :=
{ coe := monoid_hom.to_fun,
coe_injective' := λ f g h, by cases f; cases g; congr',
map_mul := monoid_hom.map_mul',
map_one := monoid_hom.map_one' }
@[to_additive]
instance [monoid_hom_class F M N] : has_coe_t F (M →* N) :=
⟨λ f, { to_fun := f, map_one' := map_one f, map_mul' := map_mul f }⟩
@[to_additive]
lemma map_mul_eq_one [monoid_hom_class F M N] (f : F) {a b : M} (h : a * b = 1) :
f a * f b = 1 :=
by rw [← map_mul, h, map_one]
@[to_additive]
lemma map_div' [div_inv_monoid G] [div_inv_monoid H] [monoid_hom_class F G H] (f : F)
(hf : ∀ a, f a⁻¹ = (f a)⁻¹) (a b : G) : f (a / b) = f a / f b :=
by rw [div_eq_mul_inv, div_eq_mul_inv, map_mul, hf]
/-- Group homomorphisms preserve inverse. -/
@[simp, to_additive "Additive group homomorphisms preserve negation."]
lemma map_inv [group G] [division_monoid H] [monoid_hom_class F G H] (f : F) (a : G) :
f a⁻¹ = (f a)⁻¹ :=
eq_inv_of_mul_eq_one_left $ map_mul_eq_one f $ inv_mul_self _
/-- Group homomorphisms preserve division. -/
@[simp, to_additive "Additive group homomorphisms preserve subtraction."]
lemma map_mul_inv [group G] [division_monoid H] [monoid_hom_class F G H] (f : F) (a b : G) :
f (a * b⁻¹) = f a * (f b)⁻¹ :=
by rw [map_mul, map_inv]
/-- Group homomorphisms preserve division. -/
@[simp, to_additive "Additive group homomorphisms preserve subtraction."]
lemma map_div [group G] [division_monoid H] [monoid_hom_class F G H] (f : F) :
∀ a b, f (a / b) = f a / f b :=
map_div' _ $ map_inv f
-- to_additive puts the arguments in the wrong order, so generate an auxiliary lemma, then
-- swap its arguments.
@[to_additive map_nsmul.aux, simp] theorem map_pow [monoid G] [monoid H] [monoid_hom_class F G H]
(f : F) (a : G) :
∀ (n : ℕ), f (a ^ n) = (f a) ^ n
| 0 := by rw [pow_zero, pow_zero, map_one]
| (n+1) := by rw [pow_succ, pow_succ, map_mul, map_pow]
@[simp] theorem map_nsmul [add_monoid G] [add_monoid H] [add_monoid_hom_class F G H]
(f : F) (n : ℕ) (a : G) : f (n • a) = n • (f a) :=
map_nsmul.aux f a n
attribute [to_additive_reorder 8, to_additive] map_pow
@[to_additive]
theorem map_zpow' [div_inv_monoid G] [div_inv_monoid H] [monoid_hom_class F G H]
(f : F) (hf : ∀ (x : G), f (x⁻¹) = (f x)⁻¹) (a : G) :
∀ n : ℤ, f (a ^ n) = (f a) ^ n
| (n : ℕ) := by rw [zpow_coe_nat, map_pow, zpow_coe_nat]
| -[1+n] := by rw [zpow_neg_succ_of_nat, hf, map_pow, ← zpow_neg_succ_of_nat]
-- to_additive puts the arguments in the wrong order, so generate an auxiliary lemma, then
-- swap its arguments.
/-- Group homomorphisms preserve integer power. -/
@[to_additive map_zsmul.aux, simp]
theorem map_zpow [group G] [division_monoid H] [monoid_hom_class F G H] (f : F) (g : G) (n : ℤ) :
f (g ^ n) = (f g) ^ n :=
map_zpow' f (map_inv f) g n
/-- Additive group homomorphisms preserve integer scaling. -/
theorem map_zsmul [add_group G] [subtraction_monoid H] [add_monoid_hom_class F G H] (f : F)
(n : ℤ) (g : G) :
f (n • g) = n • f g :=
map_zsmul.aux f g n
attribute [to_additive_reorder 8, to_additive] map_zpow
end mul_one
section mul_zero_one
variables [mul_zero_one_class M] [mul_zero_one_class N]
/-- `M →*₀ N` is the type of functions `M → N` that preserve
the `monoid_with_zero` structure.
`monoid_with_zero_hom` is also used for group homomorphisms.
When possible, instead of parametrizing results over `(f : M →*₀ N)`,
you should parametrize over `(F : Type*) [monoid_with_zero_hom_class F M N] (f : F)`.
When you extend this structure, make sure to extend `monoid_with_zero_hom_class`.
-/
@[ancestor zero_hom monoid_hom]
structure monoid_with_zero_hom (M : Type*) (N : Type*) [mul_zero_one_class M] [mul_zero_one_class N]
extends zero_hom M N, monoid_hom M N
attribute [nolint doc_blame] monoid_with_zero_hom.to_monoid_hom
attribute [nolint doc_blame] monoid_with_zero_hom.to_zero_hom
infixr ` →*₀ `:25 := monoid_with_zero_hom
/-- `monoid_with_zero_hom_class F M N` states that `F` is a type of
`monoid_with_zero`-preserving homomorphisms.
You should also extend this typeclass when you extend `monoid_with_zero_hom`.
-/
class monoid_with_zero_hom_class (F : Type*) (M N : out_param $ Type*)
[mul_zero_one_class M] [mul_zero_one_class N]
extends monoid_hom_class F M N, zero_hom_class F M N
instance monoid_with_zero_hom.monoid_with_zero_hom_class :
monoid_with_zero_hom_class (M →*₀ N) M N :=
{ coe := monoid_with_zero_hom.to_fun,
coe_injective' := λ f g h, by cases f; cases g; congr',
map_mul := monoid_with_zero_hom.map_mul',
map_one := monoid_with_zero_hom.map_one',
map_zero := monoid_with_zero_hom.map_zero' }
instance [monoid_with_zero_hom_class F M N] : has_coe_t F (M →*₀ N) :=
⟨λ f, { to_fun := f, map_one' := map_one f, map_zero' := map_zero f, map_mul' := map_mul f }⟩
end mul_zero_one
-- completely uninteresting lemmas about coercion to function, that all homs need
section coes
/-! Bundled morphisms can be down-cast to weaker bundlings -/
@[to_additive]
instance monoid_hom.has_coe_to_one_hom {mM : mul_one_class M} {mN : mul_one_class N} :
has_coe (M →* N) (one_hom M N) := ⟨monoid_hom.to_one_hom⟩
@[to_additive]
instance monoid_hom.has_coe_to_mul_hom {mM : mul_one_class M} {mN : mul_one_class N} :
has_coe (M →* N) (M →ₙ* N) := ⟨monoid_hom.to_mul_hom⟩
instance monoid_with_zero_hom.has_coe_to_monoid_hom
{mM : mul_zero_one_class M} {mN : mul_zero_one_class N} :
has_coe (M →*₀ N) (M →* N) := ⟨monoid_with_zero_hom.to_monoid_hom⟩
instance monoid_with_zero_hom.has_coe_to_zero_hom
{mM : mul_zero_one_class M} {mN : mul_zero_one_class N} :
has_coe (M →*₀ N) (zero_hom M N) := ⟨monoid_with_zero_hom.to_zero_hom⟩
/-! The simp-normal form of morphism coercion is `f.to_..._hom`. This choice is primarily because
this is the way things were before the above coercions were introduced. Bundled morphisms defined
elsewhere in Mathlib may choose `↑f` as their simp-normal form instead. -/
@[simp, to_additive]
lemma monoid_hom.coe_eq_to_one_hom {mM : mul_one_class M} {mN : mul_one_class N} (f : M →* N) :
(f : one_hom M N) = f.to_one_hom := rfl
@[simp, to_additive]
lemma monoid_hom.coe_eq_to_mul_hom {mM : mul_one_class M} {mN : mul_one_class N} (f : M →* N) :
(f : M →ₙ* N) = f.to_mul_hom := rfl
@[simp]
lemma monoid_with_zero_hom.coe_eq_to_monoid_hom
{mM : mul_zero_one_class M} {mN : mul_zero_one_class N} (f : M →*₀ N) :
(f : M →* N) = f.to_monoid_hom := rfl
@[simp]
lemma monoid_with_zero_hom.coe_eq_to_zero_hom
{mM : mul_zero_one_class M} {mN : mul_zero_one_class N} (f : M →*₀ N) :
(f : zero_hom M N) = f.to_zero_hom := rfl
-- Fallback `has_coe_to_fun` instances to help the elaborator
@[to_additive]
instance {mM : has_one M} {mN : has_one N} : has_coe_to_fun (one_hom M N) (λ _, M → N) :=
⟨one_hom.to_fun⟩
@[to_additive]
instance {mM : has_mul M} {mN : has_mul N} : has_coe_to_fun (M →ₙ* N) (λ _, M → N) :=
⟨mul_hom.to_fun⟩
@[to_additive]
instance {mM : mul_one_class M} {mN : mul_one_class N} : has_coe_to_fun (M →* N) (λ _, M → N) :=
⟨monoid_hom.to_fun⟩
instance {mM : mul_zero_one_class M} {mN : mul_zero_one_class N} :
has_coe_to_fun (M →*₀ N) (λ _, M → N) :=
⟨monoid_with_zero_hom.to_fun⟩
-- these must come after the coe_to_fun definitions
initialize_simps_projections zero_hom (to_fun → apply)
initialize_simps_projections add_hom (to_fun → apply)
initialize_simps_projections add_monoid_hom (to_fun → apply)
initialize_simps_projections one_hom (to_fun → apply)
initialize_simps_projections mul_hom (to_fun → apply)
initialize_simps_projections monoid_hom (to_fun → apply)
initialize_simps_projections monoid_with_zero_hom (to_fun → apply)
@[simp, to_additive]
lemma one_hom.to_fun_eq_coe [has_one M] [has_one N] (f : one_hom M N) : f.to_fun = f := rfl
@[simp, to_additive]
lemma mul_hom.to_fun_eq_coe [has_mul M] [has_mul N] (f : M →ₙ* N) : f.to_fun = f := rfl
@[simp, to_additive]
lemma monoid_hom.to_fun_eq_coe [mul_one_class M] [mul_one_class N]
(f : M →* N) : f.to_fun = f := rfl
@[simp]
lemma monoid_with_zero_hom.to_fun_eq_coe [mul_zero_one_class M] [mul_zero_one_class N]
(f : M →*₀ N) : f.to_fun = f := rfl
@[simp, to_additive]
lemma one_hom.coe_mk [has_one M] [has_one N]
(f : M → N) (h1) : (one_hom.mk f h1 : M → N) = f := rfl
@[simp, to_additive]
lemma mul_hom.coe_mk [has_mul M] [has_mul N]
(f : M → N) (hmul) : (mul_hom.mk f hmul : M → N) = f := rfl
@[simp, to_additive]
lemma monoid_hom.coe_mk [mul_one_class M] [mul_one_class N]
(f : M → N) (h1 hmul) : (monoid_hom.mk f h1 hmul : M → N) = f := rfl
@[simp]
lemma monoid_with_zero_hom.coe_mk [mul_zero_one_class M] [mul_zero_one_class N]
(f : M → N) (h0 h1 hmul) : (monoid_with_zero_hom.mk f h0 h1 hmul : M → N) = f := rfl
@[simp, to_additive]
lemma monoid_hom.to_one_hom_coe [mul_one_class M] [mul_one_class N] (f : M →* N) :
(f.to_one_hom : M → N) = f := rfl
@[simp, to_additive]
lemma monoid_hom.to_mul_hom_coe [mul_one_class M] [mul_one_class N] (f : M →* N) :
(f.to_mul_hom : M → N) = f := rfl
@[simp]
lemma monoid_with_zero_hom.to_zero_hom_coe [mul_zero_one_class M] [mul_zero_one_class N]
(f : M →*₀ N) :
(f.to_zero_hom : M → N) = f := rfl
@[simp]
lemma monoid_with_zero_hom.to_monoid_hom_coe [mul_zero_one_class M] [mul_zero_one_class N]
(f : M →*₀ N) :
(f.to_monoid_hom : M → N) = f := rfl
@[ext, to_additive]
lemma one_hom.ext [has_one M] [has_one N] ⦃f g : one_hom M N⦄ (h : ∀ x, f x = g x) : f = g :=
fun_like.ext _ _ h
@[ext, to_additive]
lemma mul_hom.ext [has_mul M] [has_mul N] ⦃f g : M →ₙ* N⦄ (h : ∀ x, f x = g x) : f = g :=
fun_like.ext _ _ h
@[ext, to_additive]
lemma monoid_hom.ext [mul_one_class M] [mul_one_class N]
⦃f g : M →* N⦄ (h : ∀ x, f x = g x) : f = g :=
fun_like.ext _ _ h
@[ext]
lemma monoid_with_zero_hom.ext [mul_zero_one_class M] [mul_zero_one_class N] ⦃f g : M →*₀ N⦄
(h : ∀ x, f x = g x) : f = g :=
fun_like.ext _ _ h
section deprecated
/-- Deprecated: use `fun_like.congr_fun` instead. -/
@[to_additive "Deprecated: use `fun_like.congr_fun` instead."]
theorem one_hom.congr_fun [has_one M] [has_one N]
{f g : one_hom M N} (h : f = g) (x : M) : f x = g x :=
fun_like.congr_fun h x
/-- Deprecated: use `fun_like.congr_fun` instead. -/
@[to_additive "Deprecated: use `fun_like.congr_fun` instead."]
theorem mul_hom.congr_fun [has_mul M] [has_mul N]
{f g : M →ₙ* N} (h : f = g) (x : M) : f x = g x :=
fun_like.congr_fun h x
/-- Deprecated: use `fun_like.congr_fun` instead. -/
@[to_additive "Deprecated: use `fun_like.congr_fun` instead."]
theorem monoid_hom.congr_fun [mul_one_class M] [mul_one_class N]
{f g : M →* N} (h : f = g) (x : M) : f x = g x :=
fun_like.congr_fun h x
/-- Deprecated: use `fun_like.congr_fun` instead. -/
theorem monoid_with_zero_hom.congr_fun [mul_zero_one_class M] [mul_zero_one_class N] {f g : M →*₀ N}
(h : f = g) (x : M) : f x = g x :=
fun_like.congr_fun h x
/-- Deprecated: use `fun_like.congr_arg` instead. -/
@[to_additive "Deprecated: use `fun_like.congr_arg` instead."]
theorem one_hom.congr_arg [has_one M] [has_one N]
(f : one_hom M N) {x y : M} (h : x = y) : f x = f y :=
fun_like.congr_arg f h
/-- Deprecated: use `fun_like.congr_arg` instead. -/
@[to_additive "Deprecated: use `fun_like.congr_arg` instead."]
theorem mul_hom.congr_arg [has_mul M] [has_mul N]
(f : M →ₙ* N) {x y : M} (h : x = y) : f x = f y :=
fun_like.congr_arg f h
/-- Deprecated: use `fun_like.congr_arg` instead. -/
@[to_additive "Deprecated: use `fun_like.congr_arg` instead."]
theorem monoid_hom.congr_arg [mul_one_class M] [mul_one_class N]
(f : M →* N) {x y : M} (h : x = y) : f x = f y :=
fun_like.congr_arg f h
/-- Deprecated: use `fun_like.congr_arg` instead. -/
theorem monoid_with_zero_hom.congr_arg [mul_zero_one_class M] [mul_zero_one_class N] (f : M →*₀ N)
{x y : M} (h : x = y) : f x = f y :=
fun_like.congr_arg f h
/-- Deprecated: use `fun_like.coe_injective` instead. -/
@[to_additive "Deprecated: use `fun_like.coe_injective` instead."]
lemma one_hom.coe_inj [has_one M] [has_one N] ⦃f g : one_hom M N⦄ (h : (f : M → N) = g) : f = g :=
fun_like.coe_injective h
/-- Deprecated: use `fun_like.coe_injective` instead. -/
@[to_additive "Deprecated: use `fun_like.coe_injective` instead."]
lemma mul_hom.coe_inj [has_mul M] [has_mul N] ⦃f g : M →ₙ* N⦄ (h : (f : M → N) = g) : f = g :=
fun_like.coe_injective h
/-- Deprecated: use `fun_like.coe_injective` instead. -/
@[to_additive "Deprecated: use `fun_like.coe_injective` instead."]
lemma monoid_hom.coe_inj [mul_one_class M] [mul_one_class N]
⦃f g : M →* N⦄ (h : (f : M → N) = g) : f = g :=
fun_like.coe_injective h
/-- Deprecated: use `fun_like.coe_injective` instead. -/
lemma monoid_with_zero_hom.coe_inj [mul_zero_one_class M] [mul_zero_one_class N]
⦃f g : M →*₀ N⦄ (h : (f : M → N) = g) : f = g :=
fun_like.coe_injective h
/-- Deprecated: use `fun_like.ext_iff` instead. -/
@[to_additive "Deprecated: use `fun_like.ext_iff` instead."]
lemma one_hom.ext_iff [has_one M] [has_one N] {f g : one_hom M N} : f = g ↔ ∀ x, f x = g x :=
fun_like.ext_iff
/-- Deprecated: use `fun_like.ext_iff` instead. -/
@[to_additive]
lemma mul_hom.ext_iff [has_mul M] [has_mul N] {f g : M →ₙ* N} : f = g ↔ ∀ x, f x = g x :=
fun_like.ext_iff
/-- Deprecated: use `fun_like.ext_iff` instead. -/
@[to_additive]
lemma monoid_hom.ext_iff [mul_one_class M] [mul_one_class N]
{f g : M →* N} : f = g ↔ ∀ x, f x = g x :=
fun_like.ext_iff
/-- Deprecated: use `fun_like.ext_iff` instead. -/
lemma monoid_with_zero_hom.ext_iff [mul_zero_one_class M] [mul_zero_one_class N] {f g : M →*₀ N} :
f = g ↔ ∀ x, f x = g x :=
fun_like.ext_iff
end deprecated
@[simp, to_additive]
lemma one_hom.mk_coe [has_one M] [has_one N]
(f : one_hom M N) (h1) : one_hom.mk f h1 = f :=
one_hom.ext $ λ _, rfl
@[simp, to_additive]
lemma mul_hom.mk_coe [has_mul M] [has_mul N]
(f : M →ₙ* N) (hmul) : mul_hom.mk f hmul = f :=
mul_hom.ext $ λ _, rfl
@[simp, to_additive]
lemma monoid_hom.mk_coe [mul_one_class M] [mul_one_class N]
(f : M →* N) (h1 hmul) : monoid_hom.mk f h1 hmul = f :=
monoid_hom.ext $ λ _, rfl
@[simp]
lemma monoid_with_zero_hom.mk_coe [mul_zero_one_class M] [mul_zero_one_class N] (f : M →*₀ N)
(h0 h1 hmul) : monoid_with_zero_hom.mk f h0 h1 hmul = f :=
monoid_with_zero_hom.ext $ λ _, rfl
end coes
/-- Copy of a `one_hom` with a new `to_fun` equal to the old one. Useful to fix definitional
equalities. -/
@[to_additive "Copy of a `zero_hom` with a new `to_fun` equal to the old one. Useful to fix
definitional equalities."]
protected def one_hom.copy {hM : has_one M} {hN : has_one N} (f : one_hom M N) (f' : M → N)
(h : f' = f) : one_hom M N :=
{ to_fun := f',
map_one' := h.symm ▸ f.map_one' }
/-- Copy of a `mul_hom` with a new `to_fun` equal to the old one. Useful to fix definitional
equalities. -/
@[to_additive "Copy of an `add_hom` with a new `to_fun` equal to the old one. Useful to fix
definitional equalities."]
protected def mul_hom.copy {hM : has_mul M} {hN : has_mul N} (f : M →ₙ* N) (f' : M → N)
(h : f' = f) : M →ₙ* N :=
{ to_fun := f',
map_mul' := h.symm ▸ f.map_mul' }
/-- Copy of a `monoid_hom` with a new `to_fun` equal to the old one. Useful to fix
definitional equalities. -/
@[to_additive "Copy of an `add_monoid_hom` with a new `to_fun` equal to the old one. Useful to fix
definitional equalities."]
protected def monoid_hom.copy {hM : mul_one_class M} {hN : mul_one_class N} (f : M →* N)
(f' : M → N) (h : f' = f) : M →* N :=
{ ..f.to_one_hom.copy f' h, ..f.to_mul_hom.copy f' h }
/-- Copy of a `monoid_hom` with a new `to_fun` equal to the old one. Useful to fix
definitional equalities. -/
protected def monoid_with_zero_hom.copy {hM : mul_zero_one_class M} {hN : mul_zero_one_class N}
(f : M →*₀ N) (f' : M → N) (h : f' = f) : M →* N :=
{ ..f.to_zero_hom.copy f' h, ..f.to_monoid_hom.copy f' h }
@[to_additive]
protected lemma one_hom.map_one [has_one M] [has_one N] (f : one_hom M N) : f 1 = 1 := f.map_one'
/-- If `f` is a monoid homomorphism then `f 1 = 1`. -/
@[to_additive]
protected lemma monoid_hom.map_one [mul_one_class M] [mul_one_class N] (f : M →* N) :
f 1 = 1 := f.map_one'
protected lemma monoid_with_zero_hom.map_one [mul_zero_one_class M] [mul_zero_one_class N]
(f : M →*₀ N) : f 1 = 1 := f.map_one'
/-- If `f` is an additive monoid homomorphism then `f 0 = 0`. -/
add_decl_doc add_monoid_hom.map_zero
protected lemma monoid_with_zero_hom.map_zero [mul_zero_one_class M] [mul_zero_one_class N]
(f : M →*₀ N) : f 0 = 0 := f.map_zero'
@[to_additive]
protected lemma mul_hom.map_mul [has_mul M] [has_mul N]
(f : M →ₙ* N) (a b : M) : f (a * b) = f a * f b := f.map_mul' a b
/-- If `f` is a monoid homomorphism then `f (a * b) = f a * f b`. -/
@[to_additive]
protected lemma monoid_hom.map_mul [mul_one_class M] [mul_one_class N]
(f : M →* N) (a b : M) : f (a * b) = f a * f b := f.map_mul' a b
protected lemma monoid_with_zero_hom.map_mul [mul_zero_one_class M] [mul_zero_one_class N]
(f : M →*₀ N) (a b : M) : f (a * b) = f a * f b := f.map_mul' a b
/-- If `f` is an additive monoid homomorphism then `f (a + b) = f a + f b`. -/
add_decl_doc add_monoid_hom.map_add
namespace monoid_hom
variables {mM : mul_one_class M} {mN : mul_one_class N} [monoid_hom_class F M N]
include mM mN
/-- Given a monoid homomorphism `f : M →* N` and an element `x : M`, if `x` has a right inverse,
then `f x` has a right inverse too. For elements invertible on both sides see `is_unit.map`. -/
@[to_additive "Given an add_monoid homomorphism `f : M →+ N` and an element `x : M`, if `x` has
a right inverse, then `f x` has a right inverse too."]
lemma map_exists_right_inv (f : F) {x : M} (hx : ∃ y, x * y = 1) :
∃ y, f x * y = 1 :=
let ⟨y, hy⟩ := hx in ⟨f y, map_mul_eq_one f hy⟩
/-- Given a monoid homomorphism `f : M →* N` and an element `x : M`, if `x` has a left inverse,
then `f x` has a left inverse too. For elements invertible on both sides see `is_unit.map`. -/
@[to_additive "Given an add_monoid homomorphism `f : M →+ N` and an element `x : M`, if `x` has
a left inverse, then `f x` has a left inverse too. For elements invertible on both sides see
`is_add_unit.map`."]
lemma map_exists_left_inv (f : F) {x : M} (hx : ∃ y, y * x = 1) :
∃ y, y * f x = 1 :=
let ⟨y, hy⟩ := hx in ⟨f y, map_mul_eq_one f hy⟩
end monoid_hom
section division_comm_monoid
variables [division_comm_monoid α]
/-- Inversion on a commutative group, considered as a monoid homomorphism. -/
@[to_additive "Negation on a commutative additive group, considered as an additive monoid
homomorphism."]
def inv_monoid_hom : α →* α :=
{ to_fun := has_inv.inv,
map_one' := inv_one,
map_mul' := mul_inv }
@[simp] lemma coe_inv_monoid_hom : (inv_monoid_hom : α → α) = has_inv.inv := rfl
@[simp] lemma inv_monoid_hom_apply (a : α) : inv_monoid_hom a = a⁻¹ := rfl
end division_comm_monoid
/-- The identity map from a type with 1 to itself. -/
@[to_additive, simps]
def one_hom.id (M : Type*) [has_one M] : one_hom M M :=
{ to_fun := λ x, x, map_one' := rfl, }
/-- The identity map from a type with multiplication to itself. -/
@[to_additive, simps]
def mul_hom.id (M : Type*) [has_mul M] : M →ₙ* M :=
{ to_fun := λ x, x, map_mul' := λ _ _, rfl, }
/-- The identity map from a monoid to itself. -/
@[to_additive, simps]
def monoid_hom.id (M : Type*) [mul_one_class M] : M →* M :=
{ to_fun := λ x, x, map_one' := rfl, map_mul' := λ _ _, rfl, }
/-- The identity map from a monoid_with_zero to itself. -/
@[simps]
def monoid_with_zero_hom.id (M : Type*) [mul_zero_one_class M] : M →*₀ M :=
{ to_fun := λ x, x, map_zero' := rfl, map_one' := rfl, map_mul' := λ _ _, rfl, }
/-- The identity map from an type with zero to itself. -/
add_decl_doc zero_hom.id
/-- The identity map from an type with addition to itself. -/
add_decl_doc add_hom.id
/-- The identity map from an additive monoid to itself. -/
add_decl_doc add_monoid_hom.id
/-- Composition of `one_hom`s as a `one_hom`. -/
@[to_additive]
def one_hom.comp [has_one M] [has_one N] [has_one P]
(hnp : one_hom N P) (hmn : one_hom M N) : one_hom M P :=
{ to_fun := hnp ∘ hmn, map_one' := by simp, }
/-- Composition of `mul_hom`s as a `mul_hom`. -/
@[to_additive]
def mul_hom.comp [has_mul M] [has_mul N] [has_mul P]
(hnp : N →ₙ* P) (hmn : M →ₙ* N) : M →ₙ* P :=
{ to_fun := hnp ∘ hmn, map_mul' := by simp, }
/-- Composition of monoid morphisms as a monoid morphism. -/
@[to_additive]
def monoid_hom.comp [mul_one_class M] [mul_one_class N] [mul_one_class P]
(hnp : N →* P) (hmn : M →* N) : M →* P :=
{ to_fun := hnp ∘ hmn, map_one' := by simp, map_mul' := by simp, }
/-- Composition of `monoid_with_zero_hom`s as a `monoid_with_zero_hom`. -/
def monoid_with_zero_hom.comp [mul_zero_one_class M] [mul_zero_one_class N] [mul_zero_one_class P]
(hnp : N →*₀ P) (hmn : M →*₀ N) : M →*₀ P :=
{ to_fun := hnp ∘ hmn, map_zero' := by simp, map_one' := by simp, map_mul' := by simp, }
/-- Composition of `zero_hom`s as a `zero_hom`. -/
add_decl_doc zero_hom.comp
/-- Composition of `add_hom`s as a `add_hom`. -/
add_decl_doc add_hom.comp
/-- Composition of additive monoid morphisms as an additive monoid morphism. -/
add_decl_doc add_monoid_hom.comp
@[simp, to_additive] lemma one_hom.coe_comp [has_one M] [has_one N] [has_one P]
(g : one_hom N P) (f : one_hom M N) :
⇑(g.comp f) = g ∘ f := rfl
@[simp, to_additive] lemma mul_hom.coe_comp [has_mul M] [has_mul N] [has_mul P]
(g : N →ₙ* P) (f : M →ₙ* N) :
⇑(g.comp f) = g ∘ f := rfl
@[simp, to_additive] lemma monoid_hom.coe_comp [mul_one_class M] [mul_one_class N] [mul_one_class P]
(g : N →* P) (f : M →* N) :
⇑(g.comp f) = g ∘ f := rfl
@[simp] lemma monoid_with_zero_hom.coe_comp [mul_zero_one_class M] [mul_zero_one_class N]
[mul_zero_one_class P] (g : N →*₀ P) (f : M →*₀ N) :
⇑(g.comp f) = g ∘ f := rfl
@[to_additive] lemma one_hom.comp_apply [has_one M] [has_one N] [has_one P]
(g : one_hom N P) (f : one_hom M N) (x : M) :
g.comp f x = g (f x) := rfl
@[to_additive] lemma mul_hom.comp_apply [has_mul M] [has_mul N] [has_mul P]
(g : N →ₙ* P) (f : M →ₙ* N) (x : M) :
g.comp f x = g (f x) := rfl
@[to_additive] lemma monoid_hom.comp_apply [mul_one_class M] [mul_one_class N] [mul_one_class P]
(g : N →* P) (f : M →* N) (x : M) :
g.comp f x = g (f x) := rfl
lemma monoid_with_zero_hom.comp_apply [mul_zero_one_class M] [mul_zero_one_class N]
[mul_zero_one_class P] (g : N →*₀ P) (f : M →*₀ N) (x : M) :
g.comp f x = g (f x) := rfl
/-- Composition of monoid homomorphisms is associative. -/
@[to_additive] lemma one_hom.comp_assoc {Q : Type*} [has_one M] [has_one N] [has_one P] [has_one Q]
(f : one_hom M N) (g : one_hom N P) (h : one_hom P Q) :
(h.comp g).comp f = h.comp (g.comp f) := rfl
@[to_additive] lemma mul_hom.comp_assoc {Q : Type*} [has_mul M] [has_mul N] [has_mul P] [has_mul Q]
(f : M →ₙ* N) (g : N →ₙ* P) (h : P →ₙ* Q) :
(h.comp g).comp f = h.comp (g.comp f) := rfl
@[to_additive] lemma monoid_hom.comp_assoc {Q : Type*}
[mul_one_class M] [mul_one_class N] [mul_one_class P] [mul_one_class Q]
(f : M →* N) (g : N →* P) (h : P →* Q) :
(h.comp g).comp f = h.comp (g.comp f) := rfl
lemma monoid_with_zero_hom.comp_assoc {Q : Type*}
[mul_zero_one_class M] [mul_zero_one_class N] [mul_zero_one_class P] [mul_zero_one_class Q]
(f : M →*₀ N) (g : N →*₀ P) (h : P →*₀ Q) :
(h.comp g).comp f = h.comp (g.comp f) := rfl
@[to_additive]
lemma one_hom.cancel_right [has_one M] [has_one N] [has_one P]
{g₁ g₂ : one_hom N P} {f : one_hom M N} (hf : function.surjective f) :
g₁.comp f = g₂.comp f ↔ g₁ = g₂ :=
⟨λ h, one_hom.ext $ hf.forall.2 (one_hom.ext_iff.1 h), λ h, h ▸ rfl⟩
@[to_additive]
lemma mul_hom.cancel_right [has_mul M] [has_mul N] [has_mul P]
{g₁ g₂ : N →ₙ* P} {f : M →ₙ* N} (hf : function.surjective f) :
g₁.comp f = g₂.comp f ↔ g₁ = g₂ :=
⟨λ h, mul_hom.ext $ hf.forall.2 (mul_hom.ext_iff.1 h), λ h, h ▸ rfl⟩
@[to_additive]
lemma monoid_hom.cancel_right
[mul_one_class M] [mul_one_class N] [mul_one_class P]
{g₁ g₂ : N →* P} {f : M →* N} (hf : function.surjective f) :
g₁.comp f = g₂.comp f ↔ g₁ = g₂ :=
⟨λ h, monoid_hom.ext $ hf.forall.2 (monoid_hom.ext_iff.1 h), λ h, h ▸ rfl⟩
lemma monoid_with_zero_hom.cancel_right [mul_zero_one_class M] [mul_zero_one_class N]
[mul_zero_one_class P] {g₁ g₂ : N →*₀ P} {f : M →*₀ N} (hf : function.surjective f) :
g₁.comp f = g₂.comp f ↔ g₁ = g₂ :=
⟨λ h, monoid_with_zero_hom.ext $ hf.forall.2 (monoid_with_zero_hom.ext_iff.1 h),
λ h, h ▸ rfl⟩
@[to_additive]
lemma one_hom.cancel_left [has_one M] [has_one N] [has_one P]
{g : one_hom N P} {f₁ f₂ : one_hom M N} (hg : function.injective g) :
g.comp f₁ = g.comp f₂ ↔ f₁ = f₂ :=
⟨λ h, one_hom.ext $ λ x, hg $ by rw [← one_hom.comp_apply, h, one_hom.comp_apply],
λ h, h ▸ rfl⟩
@[to_additive]
lemma mul_hom.cancel_left [has_mul M] [has_mul N] [has_mul P]
{g : N →ₙ* P} {f₁ f₂ : M →ₙ* N} (hg : function.injective g) :
g.comp f₁ = g.comp f₂ ↔ f₁ = f₂ :=
⟨λ h, mul_hom.ext $ λ x, hg $ by rw [← mul_hom.comp_apply, h, mul_hom.comp_apply],
λ h, h ▸ rfl⟩
@[to_additive]
lemma monoid_hom.cancel_left [mul_one_class M] [mul_one_class N] [mul_one_class P]
{g : N →* P} {f₁ f₂ : M →* N} (hg : function.injective g) :
g.comp f₁ = g.comp f₂ ↔ f₁ = f₂ :=
⟨λ h, monoid_hom.ext $ λ x, hg $ by rw [← monoid_hom.comp_apply, h, monoid_hom.comp_apply],
λ h, h ▸ rfl⟩
lemma monoid_with_zero_hom.cancel_left [mul_zero_one_class M] [mul_zero_one_class N]
[mul_zero_one_class P] {g : N →*₀ P} {f₁ f₂ : M →*₀ N} (hg : function.injective g) :
g.comp f₁ = g.comp f₂ ↔ f₁ = f₂ :=
⟨λ h, monoid_with_zero_hom.ext $ λ x, hg $ by rw [
← monoid_with_zero_hom.comp_apply, h, monoid_with_zero_hom.comp_apply],
λ h, h ▸ rfl⟩
@[to_additive]
lemma monoid_hom.to_one_hom_injective [mul_one_class M] [mul_one_class N] :
function.injective (monoid_hom.to_one_hom : (M →* N) → one_hom M N) :=
λ f g h, monoid_hom.ext $ one_hom.ext_iff.mp h
@[to_additive]
lemma monoid_hom.to_mul_hom_injective [mul_one_class M] [mul_one_class N] :
function.injective (monoid_hom.to_mul_hom : (M →* N) → M →ₙ* N) :=
λ f g h, monoid_hom.ext $ mul_hom.ext_iff.mp h
lemma monoid_with_zero_hom.to_monoid_hom_injective [mul_zero_one_class M] [mul_zero_one_class N] :
function.injective (monoid_with_zero_hom.to_monoid_hom : (M →*₀ N) → M →* N) :=
λ f g h, monoid_with_zero_hom.ext $ monoid_hom.ext_iff.mp h
lemma monoid_with_zero_hom.to_zero_hom_injective [mul_zero_one_class M] [mul_zero_one_class N] :
function.injective (monoid_with_zero_hom.to_zero_hom : (M →*₀ N) → zero_hom M N) :=
λ f g h, monoid_with_zero_hom.ext $ zero_hom.ext_iff.mp h
@[simp, to_additive] lemma one_hom.comp_id [has_one M] [has_one N]
(f : one_hom M N) : f.comp (one_hom.id M) = f := one_hom.ext $ λ x, rfl
@[simp, to_additive] lemma mul_hom.comp_id [has_mul M] [has_mul N]
(f : M →ₙ* N) : f.comp (mul_hom.id M) = f := mul_hom.ext $ λ x, rfl
@[simp, to_additive] lemma monoid_hom.comp_id [mul_one_class M] [mul_one_class N]
(f : M →* N) : f.comp (monoid_hom.id M) = f := monoid_hom.ext $ λ x, rfl
@[simp] lemma monoid_with_zero_hom.comp_id [mul_zero_one_class M] [mul_zero_one_class N]
(f : M →*₀ N) : f.comp (monoid_with_zero_hom.id M) = f :=
monoid_with_zero_hom.ext $ λ x, rfl
@[simp, to_additive] lemma one_hom.id_comp [has_one M] [has_one N]
(f : one_hom M N) : (one_hom.id N).comp f = f := one_hom.ext $ λ x, rfl
@[simp, to_additive] lemma mul_hom.id_comp [has_mul M] [has_mul N]
(f : M →ₙ* N) : (mul_hom.id N).comp f = f := mul_hom.ext $ λ x, rfl
@[simp, to_additive] lemma monoid_hom.id_comp [mul_one_class M] [mul_one_class N]
(f : M →* N) : (monoid_hom.id N).comp f = f := monoid_hom.ext $ λ x, rfl
@[simp] lemma monoid_with_zero_hom.id_comp [mul_zero_one_class M] [mul_zero_one_class N]
(f : M →*₀ N) : (monoid_with_zero_hom.id N).comp f = f :=
monoid_with_zero_hom.ext $ λ x, rfl
@[to_additive add_monoid_hom.map_nsmul]
protected theorem monoid_hom.map_pow [monoid M] [monoid N] (f : M →* N) (a : M) (n : ℕ) :
f (a ^ n) = (f a) ^ n :=
map_pow f a n
@[to_additive]
protected theorem monoid_hom.map_zpow' [div_inv_monoid M] [div_inv_monoid N] (f : M →* N)
(hf : ∀ x, f (x⁻¹) = (f x)⁻¹) (a : M) (n : ℤ) :
f (a ^ n) = (f a) ^ n :=
map_zpow' f hf a n
section End
namespace monoid
variables (M) [mul_one_class M]
/-- The monoid of endomorphisms. -/
protected def End := M →* M
namespace End
instance : monoid (monoid.End M) :=
{ mul := monoid_hom.comp,
one := monoid_hom.id M,
mul_assoc := λ _ _ _, monoid_hom.comp_assoc _ _ _,
mul_one := monoid_hom.comp_id,
one_mul := monoid_hom.id_comp }
instance : inhabited (monoid.End M) := ⟨1⟩
instance : monoid_hom_class (monoid.End M) M M := monoid_hom.monoid_hom_class
end End
@[simp] lemma coe_one : ((1 : monoid.End M) : M → M) = id := rfl
@[simp] lemma coe_mul (f g) : ((f * g : monoid.End M) : M → M) = f ∘ g := rfl
end monoid
namespace add_monoid
variables (A : Type*) [add_zero_class A]
/-- The monoid of endomorphisms. -/
protected def End := A →+ A
namespace End
instance : monoid (add_monoid.End A) :=
{ mul := add_monoid_hom.comp,
one := add_monoid_hom.id A,
mul_assoc := λ _ _ _, add_monoid_hom.comp_assoc _ _ _,
mul_one := add_monoid_hom.comp_id,
one_mul := add_monoid_hom.id_comp }
instance : inhabited (add_monoid.End A) := ⟨1⟩
instance : add_monoid_hom_class (add_monoid.End A) A A := add_monoid_hom.add_monoid_hom_class
end End
@[simp] lemma coe_one : ((1 : add_monoid.End A) : A → A) = id := rfl
@[simp] lemma coe_mul (f g) : ((f * g : add_monoid.End A) : A → A) = f ∘ g := rfl
end add_monoid
end End
/-- `1` is the homomorphism sending all elements to `1`. -/
@[to_additive]
instance [has_one M] [has_one N] : has_one (one_hom M N) := ⟨⟨λ _, 1, rfl⟩⟩
/-- `1` is the multiplicative homomorphism sending all elements to `1`. -/
@[to_additive]
instance [has_mul M] [mul_one_class N] : has_one (M →ₙ* N) :=
⟨⟨λ _, 1, λ _ _, (one_mul 1).symm⟩⟩
/-- `1` is the monoid homomorphism sending all elements to `1`. -/
@[to_additive]
instance [mul_one_class M] [mul_one_class N] : has_one (M →* N) :=
⟨⟨λ _, 1, rfl, λ _ _, (one_mul 1).symm⟩⟩
/-- `0` is the homomorphism sending all elements to `0`. -/
add_decl_doc zero_hom.has_zero
/-- `0` is the additive homomorphism sending all elements to `0`. -/
add_decl_doc add_hom.has_zero
/-- `0` is the additive monoid homomorphism sending all elements to `0`. -/
add_decl_doc add_monoid_hom.has_zero
@[simp, to_additive] lemma one_hom.one_apply [has_one M] [has_one N]
(x : M) : (1 : one_hom M N) x = 1 := rfl
@[simp, to_additive] lemma monoid_hom.one_apply [mul_one_class M] [mul_one_class N]
(x : M) : (1 : M →* N) x = 1 := rfl
@[simp, to_additive] lemma one_hom.one_comp [has_one M] [has_one N] [has_one P] (f : one_hom M N) :
(1 : one_hom N P).comp f = 1 := rfl
@[simp, to_additive] lemma one_hom.comp_one [has_one M] [has_one N] [has_one P] (f : one_hom N P) :
f.comp (1 : one_hom M N) = 1 :=
by { ext, simp only [one_hom.map_one, one_hom.coe_comp, function.comp_app, one_hom.one_apply] }
@[to_additive]
instance [has_one M] [has_one N] : inhabited (one_hom M N) := ⟨1⟩
@[to_additive]
instance [has_mul M] [mul_one_class N] : inhabited (M →ₙ* N) := ⟨1⟩
@[to_additive]
instance [mul_one_class M] [mul_one_class N] : inhabited (M →* N) := ⟨1⟩
-- unlike the other homs, `monoid_with_zero_hom` does not have a `1` or `0`
instance [mul_zero_one_class M] : inhabited (M →*₀ M) := ⟨monoid_with_zero_hom.id M⟩
namespace mul_hom
/-- Given two mul morphisms `f`, `g` to a commutative semigroup, `f * g` is the mul morphism
sending `x` to `f x * g x`. -/
@[to_additive]
instance [has_mul M] [comm_semigroup N] : has_mul (M →ₙ* N) :=
⟨λ f g,
{ to_fun := λ m, f m * g m,
map_mul' := begin intros, show f (x * y) * g (x * y) = f x * g x * (f y * g y),
rw [f.map_mul, g.map_mul, ←mul_assoc, ←mul_assoc, mul_right_comm (f x)], end }⟩
/-- Given two additive morphisms `f`, `g` to an additive commutative semigroup, `f + g` is the
additive morphism sending `x` to `f x + g x`. -/
add_decl_doc add_hom.has_add
@[simp, to_additive] lemma mul_apply {M N} {mM : has_mul M} {mN : comm_semigroup N}
(f g : M →ₙ* N) (x : M) :
(f * g) x = f x * g x := rfl
@[to_additive] lemma mul_comp [has_mul M] [has_mul N] [comm_semigroup P]
(g₁ g₂ : N →ₙ* P) (f : M →ₙ* N) :
(g₁ * g₂).comp f = g₁.comp f * g₂.comp f := rfl
@[to_additive] lemma comp_mul [has_mul M] [comm_semigroup N] [comm_semigroup P]
(g : N →ₙ* P) (f₁ f₂ : M →ₙ* N) :
g.comp (f₁ * f₂) = g.comp f₁ * g.comp f₂ :=
by { ext, simp only [mul_apply, function.comp_app, map_mul, coe_comp] }
end mul_hom
namespace monoid_hom
variables [mM : mul_one_class M] [mN : mul_one_class N] [mP : mul_one_class P]
variables [group G] [comm_group H]
/-- Given two monoid morphisms `f`, `g` to a commutative monoid, `f * g` is the monoid morphism
sending `x` to `f x * g x`. -/
@[to_additive]
instance {M N} {mM : mul_one_class M} [comm_monoid N] : has_mul (M →* N) :=
⟨λ f g,
{ to_fun := λ m, f m * g m,
map_one' := show f 1 * g 1 = 1, by simp,
map_mul' := begin intros, show f (x * y) * g (x * y) = f x * g x * (f y * g y),
rw [f.map_mul, g.map_mul, ←mul_assoc, ←mul_assoc, mul_right_comm (f x)], end }⟩
/-- Given two additive monoid morphisms `f`, `g` to an additive commutative monoid, `f + g` is the
additive monoid morphism sending `x` to `f x + g x`. -/
add_decl_doc add_monoid_hom.has_add
@[simp, to_additive] lemma mul_apply {M N} {mM : mul_one_class M} {mN : comm_monoid N}
(f g : M →* N) (x : M) :
(f * g) x = f x * g x := rfl
@[simp, to_additive] lemma one_comp [mul_one_class M] [mul_one_class N] [mul_one_class P]
(f : M →* N) : (1 : N →* P).comp f = 1 := rfl
@[simp, to_additive] lemma comp_one [mul_one_class M] [mul_one_class N] [mul_one_class P]
(f : N →* P) : f.comp (1 : M →* N) = 1 :=
by { ext, simp only [map_one, coe_comp, function.comp_app, one_apply] }
@[to_additive] lemma mul_comp [mul_one_class M] [mul_one_class N] [comm_monoid P]
(g₁ g₂ : N →* P) (f : M →* N) :
(g₁ * g₂).comp f = g₁.comp f * g₂.comp f := rfl
@[to_additive] lemma comp_mul [mul_one_class M] [comm_monoid N] [comm_monoid P]
(g : N →* P) (f₁ f₂ : M →* N) :
g.comp (f₁ * f₂) = g.comp f₁ * g.comp f₂ :=
by { ext, simp only [mul_apply, function.comp_app, map_mul, coe_comp] }
/-- If two homomorphism from a group to a monoid are equal at `x`, then they are equal at `x⁻¹`. -/
@[to_additive "If two homomorphism from an additive group to an additive monoid are equal at `x`,
then they are equal at `-x`." ]
lemma eq_on_inv {G} [group G] [monoid M] [monoid_hom_class F G M] {f g : F} {x : G}
(h : f x = g x) : f x⁻¹ = g x⁻¹ :=
left_inv_eq_right_inv (map_mul_eq_one f $ inv_mul_self x) $
h.symm ▸ map_mul_eq_one g $ mul_inv_self x
/-- Group homomorphisms preserve inverse. -/
@[to_additive "Additive group homomorphisms preserve negation."]
protected lemma map_inv [group α] [division_monoid β] (f : α →* β) (a : α) : f a⁻¹ = (f a)⁻¹ :=
map_inv f _
/-- Group homomorphisms preserve integer power. -/
@[to_additive "Additive group homomorphisms preserve integer scaling."]
protected theorem map_zpow [group α] [division_monoid β] (f : α →* β) (g : α) (n : ℤ) :
f (g ^ n) = (f g) ^ n :=
map_zpow f g n
/-- Group homomorphisms preserve division. -/
@[to_additive "Additive group homomorphisms preserve subtraction."]
protected theorem map_div [group α] [division_monoid β] (f : α →* β) (g h : α) :
f (g / h) = f g / f h :=
map_div f g h
/-- Group homomorphisms preserve division. -/
@[to_additive "Additive group homomorphisms preserve subtraction."]
protected theorem map_mul_inv [group α] [division_monoid β] (f : α →* β) (g h : α) :
f (g * h⁻¹) = (f g) * (f h)⁻¹ :=
map_mul_inv f g h
/-- A homomorphism from a group to a monoid is injective iff its kernel is trivial.
For the iff statement on the triviality of the kernel, see `injective_iff_map_eq_one'`. -/
@[to_additive "A homomorphism from an additive group to an additive monoid is injective iff
its kernel is trivial. For the iff statement on the triviality of the kernel,
see `injective_iff_map_eq_zero'`."]
lemma _root_.injective_iff_map_eq_one {G H} [group G] [mul_one_class H] [monoid_hom_class F G H]
(f : F) : function.injective f ↔ (∀ a, f a = 1 → a = 1) :=
⟨λ h x, (map_eq_one_iff f h).mp,
λ h x y hxy, mul_inv_eq_one.1 $ h _ $ by rw [map_mul, hxy, ← map_mul, mul_inv_self, map_one]⟩
/-- A homomorphism from a group to a monoid is injective iff its kernel is trivial,
stated as an iff on the triviality of the kernel.
For the implication, see `injective_iff_map_eq_one`. -/
@[to_additive "A homomorphism from an additive group to an additive monoid is injective iff its
kernel is trivial, stated as an iff on the triviality of the kernel. For the implication, see
`injective_iff_map_eq_zero`."]
lemma _root_.injective_iff_map_eq_one' {G H} [group G] [mul_one_class H] [monoid_hom_class F G H]
(f : F) : function.injective f ↔ (∀ a, f a = 1 ↔ a = 1) :=
(injective_iff_map_eq_one f).trans $ forall_congr $ λ a, ⟨λ h, ⟨h, λ H, H.symm ▸ map_one f⟩, iff.mp⟩
include mM
/-- Makes a group homomorphism from a proof that the map preserves multiplication. -/
@[to_additive "Makes an additive group homomorphism from a proof that the map preserves addition.",
simps {fully_applied := ff}]
def mk' (f : M → G) (map_mul : ∀ a b : M, f (a * b) = f a * f b) : M →* G :=
{ to_fun := f,
map_mul' := map_mul,
map_one' := mul_left_eq_self.1 $ by rw [←map_mul, mul_one] }
omit mM
/-- Makes a group homomorphism from a proof that the map preserves right division `λ x y, x * y⁻¹`.
See also `monoid_hom.of_map_div` for a version using `λ x y, x / y`.
-/
@[to_additive "Makes an additive group homomorphism from a proof that the map preserves
the operation `λ a b, a + -b`. See also `add_monoid_hom.of_map_sub` for a version using
`λ a b, a - b`."]
def of_map_mul_inv {H : Type*} [group H] (f : G → H)
(map_div : ∀ a b : G, f (a * b⁻¹) = f a * (f b)⁻¹) :
G →* H :=
mk' f $ λ x y,
calc f (x * y) = f x * (f $ 1 * 1⁻¹ * y⁻¹)⁻¹ : by simp only [one_mul, inv_one, ← map_div, inv_inv]
... = f x * f y : by { simp only [map_div], simp only [mul_right_inv, one_mul, inv_inv] }
@[simp, to_additive] lemma coe_of_map_mul_inv {H : Type*} [group H] (f : G → H)
(map_div : ∀ a b : G, f (a * b⁻¹) = f a * (f b)⁻¹) :
⇑(of_map_mul_inv f map_div) = f :=
rfl
/-- Define a morphism of additive groups given a map which respects ratios. -/
@[to_additive /-"Define a morphism of additive groups given a map which respects difference."-/]
def of_map_div {H : Type*} [group H] (f : G → H) (hf : ∀ x y, f (x / y) = f x / f y) : G →* H :=
of_map_mul_inv f (by simpa only [div_eq_mul_inv] using hf)
@[simp, to_additive]
lemma coe_of_map_div {H : Type*} [group H] (f : G → H) (hf : ∀ x y, f (x / y) = f x / f y) :
⇑(of_map_div f hf) = f :=
rfl
/-- If `f` is a monoid homomorphism to a commutative group, then `f⁻¹` is the homomorphism sending
`x` to `(f x)⁻¹`. -/
@[to_additive]
instance {M G} [mul_one_class M] [comm_group G] : has_inv (M →* G) :=
⟨λ f, mk' (λ g, (f g)⁻¹) $ λ a b, by rw [←mul_inv, f.map_mul]⟩
/-- If `f` is an additive monoid homomorphism to an additive commutative group, then `-f` is the
homomorphism sending `x` to `-(f x)`. -/
add_decl_doc add_monoid_hom.has_neg
@[simp, to_additive] lemma inv_apply {M G} {mM : mul_one_class M} {gG : comm_group G}
(f : M →* G) (x : M) :
f⁻¹ x = (f x)⁻¹ := rfl
@[simp, to_additive] lemma inv_comp {M N A} {mM : mul_one_class M} {gN : mul_one_class N}
{gA : comm_group A} (φ : N →* A) (ψ : M →* N) : φ⁻¹.comp ψ = (φ.comp ψ)⁻¹ :=
by { ext, simp only [function.comp_app, inv_apply, coe_comp] }
@[simp, to_additive] lemma comp_inv {M A B} {mM : mul_one_class M} {mA : comm_group A}
{mB : comm_group B} (φ : A →* B) (ψ : M →* A) : φ.comp ψ⁻¹ = (φ.comp ψ)⁻¹ :=
by { ext, simp only [function.comp_app, inv_apply, map_inv, coe_comp] }
/-- If `f` and `g` are monoid homomorphisms to a commutative group, then `f / g` is the homomorphism
sending `x` to `(f x) / (g x)`. -/
@[to_additive]
instance {M G} [mul_one_class M] [comm_group G] : has_div (M →* G) :=
⟨λ f g, mk' (λ x, f x / g x) $ λ a b,
by simp [div_eq_mul_inv, mul_assoc, mul_left_comm, mul_comm]⟩
/-- If `f` and `g` are monoid homomorphisms to an additive commutative group, then `f - g`
is the homomorphism sending `x` to `(f x) - (g x)`. -/
add_decl_doc add_monoid_hom.has_sub
@[simp, to_additive] lemma div_apply {M G} {mM : mul_one_class M} {gG : comm_group G}
(f g : M →* G) (x : M) :
(f / g) x = f x / g x := rfl
end monoid_hom
/-- Given two monoid with zero morphisms `f`, `g` to a commutative monoid, `f * g` is the monoid
with zero morphism sending `x` to `f x * g x`. -/
instance {M N} {hM : mul_zero_one_class M} [comm_monoid_with_zero N] : has_mul (M →*₀ N) :=
⟨λ f g,
{ to_fun := λ a, f a * g a,
map_zero' := by rw [map_zero, zero_mul],
..(f * g : M →* N) }⟩
section commute
variables [has_mul M] [has_mul N] {a x y : M}
@[simp, to_additive]
protected lemma semiconj_by.map [mul_hom_class F M N] (h : semiconj_by a x y) (f : F) :
semiconj_by (f a) (f x) (f y) :=
by simpa only [semiconj_by, map_mul] using congr_arg f h
@[simp, to_additive]
protected lemma commute.map [mul_hom_class F M N] (h : commute x y) (f : F) :
commute (f x) (f y) :=
h.map f
end commute
|
085960152eb81d0a80385a17bd0a90f444c13e22 | b7f22e51856f4989b970961f794f1c435f9b8f78 | /library/logic/identities.lean | 9c418a47db4442d290f2320865b86e4d77a4538f | [
"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 | 4,216 | lean | /-
Copyright (c) 2014 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
Useful logical identities. Since we are not using propositional extensionality, some of the
calculations use the type class support provided by logic.instances.
-/
import logic.connectives logic.quantifiers logic.cast
open decidable
theorem or.right_comm (a b c : Prop) : (a ∨ b) ∨ c ↔ (a ∨ c) ∨ b :=
calc
(a ∨ b) ∨ c ↔ a ∨ (b ∨ c) : or.assoc
... ↔ a ∨ (c ∨ b) : {or.comm}
... ↔ (a ∨ c) ∨ b : iff.symm or.assoc
theorem and.right_comm (a b c : Prop) : (a ∧ b) ∧ c ↔ (a ∧ c) ∧ b :=
calc
(a ∧ b) ∧ c ↔ a ∧ (b ∧ c) : and.assoc
... ↔ a ∧ (c ∧ b) : {and.comm}
... ↔ (a ∧ c) ∧ b : iff.symm and.assoc
theorem or_not_self_iff (a : Prop) [D : decidable a] : a ∨ ¬ a ↔ true :=
iff.intro (assume H, trivial) (assume H, em a)
theorem not_or_self_iff (a : Prop) [D : decidable a] : ¬ a ∨ a ↔ true :=
iff.intro (λ H, trivial) (λ H, or.swap (em a))
theorem and_not_self_iff (a : Prop) : a ∧ ¬ a ↔ false :=
iff.intro (assume H, (and.right H) (and.left H)) (assume H, false.elim H)
theorem not_and_self_iff (a : Prop) : ¬ a ∧ a ↔ false :=
iff.intro (λ H, and.elim H (by contradiction)) (λ H, false.elim H)
theorem not_not_iff (a : Prop) [D : decidable a] : ¬¬a ↔ a :=
iff.intro by_contradiction not_not_intro
theorem not_not_elim {a : Prop} [D : decidable a] : ¬¬a → a :=
by_contradiction
theorem not_or_iff_not_and_not (a b : Prop) : ¬(a ∨ b) ↔ ¬a ∧ ¬b :=
or.imp_distrib
theorem not_or_not_of_not_and {a b : Prop} [Da : decidable a] (H : ¬ (a ∧ b)) : ¬ a ∨ ¬ b :=
by_cases (λHa, or.inr (not.mto (and.intro Ha) H)) or.inl
theorem not_or_not_of_not_and' {a b : Prop} [Db : decidable b] (H : ¬ (a ∧ b)) : ¬ a ∨ ¬ b :=
by_cases (λHb, or.inl (λHa, H (and.intro Ha Hb))) or.inr
theorem not_and_iff_not_or_not (a b : Prop) [Da : decidable a] :
¬(a ∧ b) ↔ ¬a ∨ ¬b :=
iff.intro
not_or_not_of_not_and
(or.rec (not.mto and.left) (not.mto and.right))
theorem or_iff_not_and_not (a b : Prop) [Da : decidable a] [Db : decidable b] :
a ∨ b ↔ ¬ (¬a ∧ ¬b) :=
by rewrite [-not_or_iff_not_and_not, not_not_iff]
theorem and_iff_not_or_not (a b : Prop) [Da : decidable a] [Db : decidable b] :
a ∧ b ↔ ¬ (¬ a ∨ ¬ b) :=
by rewrite [-not_and_iff_not_or_not, not_not_iff]
theorem imp_iff_not_or (a b : Prop) [Da : decidable a] : (a → b) ↔ ¬a ∨ b :=
iff.intro
(by_cases (λHa H, or.inr (H Ha)) (λHa H, or.inl Ha))
(or.rec not.elim imp.intro)
theorem not_implies_iff_and_not (a b : Prop) [Da : decidable a] :
¬(a → b) ↔ a ∧ ¬b :=
calc
¬(a → b) ↔ ¬(¬a ∨ b) : {imp_iff_not_or a b}
... ↔ ¬¬a ∧ ¬b : not_or_iff_not_and_not
... ↔ a ∧ ¬b : {not_not_iff a}
theorem and_not_of_not_implies {a b : Prop} [Da : decidable a] (H : ¬ (a → b)) : a ∧ ¬ b :=
iff.mp !not_implies_iff_and_not H
theorem not_implies_of_and_not {a b : Prop} [Da : decidable a] (H : a ∧ ¬ b) : ¬ (a → b) :=
iff.mpr !not_implies_iff_and_not H
theorem peirce (a b : Prop) [D : decidable a] : ((a → b) → a) → a :=
by_cases imp.intro (imp.syl imp.mp not.elim)
theorem forall_not_of_not_exists {A : Type} {p : A → Prop} [D : ∀x, decidable (p x)]
(H : ¬∃x, p x) : ∀x, ¬p x :=
take x, by_cases
(assume Hp : p x, absurd (exists.intro x Hp) H)
imp.id
theorem forall_of_not_exists_not {A : Type} {p : A → Prop} [D : decidable_pred p] :
¬(∃ x, ¬p x) → ∀ x, p x :=
imp.syl (forall_imp_forall (λa, not_not_elim)) forall_not_of_not_exists
theorem exists_not_of_not_forall {A : Type} {p : A → Prop} [D : ∀x, decidable (p x)]
[D' : decidable (∃x, ¬p x)] (H : ¬∀x, p x) :
∃x, ¬p x :=
by_contradiction (λH1, absurd (λx, not_not_elim (forall_not_of_not_exists H1 x)) H)
theorem exists_of_not_forall_not {A : Type} {p : A → Prop} [D : ∀x, decidable (p x)]
[D' : decidable (∃x, p x)] (H : ¬∀x, ¬ p x) :
∃x, p x :=
by_contradiction (imp.syl H forall_not_of_not_exists)
|
eea531dbc8ce3f23be2240665298502221cc730b | 33340b3a23ca62ef3c8a7f6a2d4e14c07c6d3354 | /lia/eval_qe.lean | bb5aa37fc31032fb12d791f590541d295a73c0b0 | [] | no_license | lclem/cooper | 79554e72ced343c64fed24b2d892d24bf9447dfe | 812afc6b158821f2e7dac9c91d3b6123c7a19faf | refs/heads/master | 1,607,554,257,488 | 1,578,694,133,000 | 1,578,694,133,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 2,701 | lean | import .nnf .qfree_sqe .wf_sqe .eval_sqe
def qe : formula → formula
| (p ∧' q) := and_o (qe p) (qe q)
| (p ∨' q) := or_o (qe p) (qe q)
| (¬' p) := not_o (qe p)
| (∃' p) := sqe (nnf (qe p))
| p := p
lemma qfree_qe :
∀ {f : formula}, qfree (qe f) :=
λ f, formula.rec_on f trivial trivial
(λ a, trivial)
(λ f1 f2 h1 h2, qfree_and_o h1 h2)
(λ f1 f2 h1 h2, qfree_or_o h1 h2)
(λ f1 h, qfree_not_o h)
(λ f1 h, begin simp [qe], apply qfree_sqe (nqfree_nnf h) end)
lemma wf_qe :
∀ {φ : formula}, formula.wf φ → formula.wf (qe φ)
| ⊤' h := by trivial
| ⊥' h := by trivial
| (A' a) h := by apply h
| (p ∧' q) h :=
begin
cases h with hp hq, simp [qe],
apply wf_and_o; apply wf_qe; assumption
end
| (p ∨' q) h :=
begin
cases h with hp hq, simp [qe],
apply wf_or_o; apply wf_qe; assumption
end
| (¬' p) h :=
begin
simp [qe], apply cases_not_o;
try {trivial}, simp [formula.wf], apply @wf_qe p h
end
| (∃' p) h :=
begin
simp [qe], apply wf_sqe,
apply wf_nnf qfree_qe (wf_qe _), apply h,
end
lemma eval_qe :
∀ {φ : formula}, φ.wf → ∀ {xs}, (qe φ).eval xs ↔ φ.eval xs
| ⊤' _ xs := begin simp [formula.eval] end
| ⊥' _ xs := begin simp [formula.eval], intro hc, cases hc end
| (A' a) _ xs := begin simp [formula.eval, qe] end
| (¬' φ) h xs :=
begin simp [qe, eval_not_o, eval_not, @eval_qe φ h] end
| (φ ∨' ψ) h xs :=
by simp [qe, eval_or_o, eval_or,
@eval_qe φ h.left, @eval_qe ψ h.right]
| (φ ∧' ψ) h xs :=
by simp [qe, eval_and_o, eval_and,
@eval_qe φ h.left, @eval_qe ψ h.right]
| (∃' p) h xs :=
begin
simp [qe, eval_ex],
apply iff.trans (eval_sqe _ _),
{ apply exists_iff_exists, intro x,
apply iff.trans (eval_nnf _),
apply @eval_qe p h, apply qfree_qe },
{ apply nqfree_nnf, apply qfree_qe },
{ apply wf_nnf qfree_qe (wf_qe _), apply h}
end
def dec_eval_of_qfree :
∀ (φ : formula), qfree φ → ∀ (ds), decidable (φ.eval ds)
| ⊤' h _ := decidable.true
| ⊥' h _ := decidable.false
| (A' a) h _ := begin simp [formula.eval], apply_instance end
| (¬' p) h _ :=
begin apply @not.decidable _ (dec_eval_of_qfree _ _ _), apply h end
| (p ∧' q) h _ :=
@and.decidable _ _
(dec_eval_of_qfree _ h.left _)
(dec_eval_of_qfree _ h.right _)
| (p ∨' q) h _ :=
@or.decidable _ _
(dec_eval_of_qfree _ h.left _)
(dec_eval_of_qfree _ h.right _)
| (∃' p) h _ := by cases h
instance dec_eval_qe (φ : formula) (zs : list znum) : decidable ((qe φ).eval zs) :=
dec_eval_of_qfree _ qfree_qe _
meta def quant_elim : tactic unit :=
pexact ``((eval_qe _).elim_left _) |
76f447d119834ada0be3034c9299289d4b9b979a | 7b02c598aa57070b4cf4fbfe2416d0479220187f | /algebra/exact_couple.hlean | 4d5150035ffde60efee2b59a2d4236552ea5cd6e | [
"Apache-2.0"
] | permissive | jdchristensen/Spectral | 50d4f0ddaea1484d215ef74be951da6549de221d | 6ded2b94d7ae07c4098d96a68f80a9cd3d433eb8 | refs/heads/master | 1,611,555,010,649 | 1,496,724,191,000 | 1,496,724,191,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 6,614 | hlean | /-
Copyright (c) 2016 Egbert Rijke. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Egbert Rijke, Steve Awodey
Exact couple, derived couples, and so on
-/
import algebra.group_theory hit.set_quotient types.sigma types.list types.sum .quotient_group .subgroup .ses
open eq algebra is_trunc set_quotient relation sigma sigma.ops prod prod.ops sum list trunc function group trunc
equiv is_equiv
definition is_differential {B : AbGroup} (d : B →g B) := Π(b:B), d (d b) = 1
definition image_subgroup_of_diff {B : AbGroup} (d : B →g B) (H : is_differential d) : subgroup_rel (ab_kernel d) :=
subgroup_rel_of_subgroup (image_subgroup d) (kernel_subgroup d)
begin
intro g p,
induction p with f, induction f with h p,
rewrite [p⁻¹],
esimp,
exact H h
end
definition diff_im_in_ker {B : AbGroup} (d : B →g B) (H : is_differential d) : Π(b : B), image_subgroup d b → kernel_subgroup d b :=
begin
intro b p,
induction p with q, induction q with b' p, induction p, exact H b'
end
definition homology {B : AbGroup} (d : B →g B) (H : is_differential d) : AbGroup :=
@quotient_ab_group (ab_kernel d) (image_subgroup_of_diff d H)
definition homology_ugly {B : AbGroup} (d : B →g B) (H : is_differential d) : AbGroup :=
@quotient_ab_group (ab_kernel d) (image_subgroup (ab_subgroup_of_subgroup_incl (diff_im_in_ker d H)))
definition homology_iso_ugly {B : AbGroup} (d : B →g B) (H : is_differential d) : (homology d H) ≃g (homology_ugly d H) :=
begin
fapply @iso_of_ab_qg_group (ab_kernel d),
intro a,
intro p, induction p with f, induction f with b p,
fapply tr, fapply fiber.mk, fapply sigma.mk, exact d b, fapply tr, fapply fiber.mk, exact b, reflexivity,
induction a with c q, fapply subtype_eq, refine p ⬝ _, reflexivity,
intro b p, induction p with f, induction f with c p, induction p,
induction c with a q, induction q with f, induction f with a' p, induction p,
fapply tr, fapply fiber.mk, exact a', reflexivity
end
definition SES_iso_C {A B C C' : AbGroup} (ses : SES A B C) (k : C ≃g C') : SES A B C' :=
begin
fapply SES.mk,
exact SES.f ses,
exact k ∘g SES.g ses,
exact SES.Hf ses,
fapply @is_surjective_compose _ _ _ k (SES.g ses),
exact is_surjective_of_is_equiv k,
exact SES.Hg ses,
fapply is_exact.mk,
intro a,
esimp,
note h := SES.ex ses,
note h2 := is_exact.im_in_ker h a,
refine ap k h2 ⬝ _ ,
exact to_respect_one k,
intro b,
intro k3,
note h := SES.ex ses,
note h3 := is_exact.ker_in_im h b,
fapply is_exact.ker_in_im h,
refine _ ⬝ ap k⁻¹ᵍ k3 ⬝ _ ,
esimp,
exact (to_left_inv (equiv_of_isomorphism k) ((SES.g ses) b))⁻¹,
exact to_respect_one k⁻¹ᵍ
end
definition SES_of_differential_ugly {B : AbGroup} (d : B →g B) (H : is_differential d) : SES (ab_image d) (ab_kernel d) (homology_ugly d H) :=
begin
exact SES_of_inclusion (ab_subgroup_of_subgroup_incl (diff_im_in_ker d H)) (is_embedding_ab_subgroup_of_subgroup_incl (diff_im_in_ker d H)),
end
definition SES_of_differential {B : AbGroup} (d : B →g B) (H : is_differential d) : SES (ab_image d) (ab_kernel d) (homology d H) :=
begin
fapply SES_iso_C,
fapply SES_of_inclusion (ab_subgroup_of_subgroup_incl (diff_im_in_ker d H)) (is_embedding_ab_subgroup_of_subgroup_incl (diff_im_in_ker d H)),
exact (homology_iso_ugly d H)⁻¹ᵍ
end
structure exact_couple (A B : AbGroup) : Type :=
( i : A →g A) (j : A →g B) (k : B →g A)
( exact_ij : is_exact i j)
( exact_jk : is_exact j k)
( exact_ki : is_exact k i)
definition differential {A B : AbGroup} (EC : exact_couple A B) : B →g B :=
(exact_couple.j EC) ∘g (exact_couple.k EC)
definition differential_is_differential {A B : AbGroup} (EC : exact_couple A B) : is_differential (differential EC) :=
begin
induction EC,
induction exact_jk,
intro b,
exact (ap (group_fun j) (im_in_ker (group_fun k b))) ⬝ (respect_one j)
end
section derived_couple
/-
A - i -> A
k ^ |
| v j
B ====== B
-/
parameters {A B : AbGroup} (EC : exact_couple A B)
local abbreviation i := exact_couple.i EC
local abbreviation j := exact_couple.j EC
local abbreviation k := exact_couple.k EC
local abbreviation d := differential EC
local abbreviation H := differential_is_differential EC
-- local abbreviation u := exact_couple.i (SES_of_differential d H)
definition derived_couple_A : AbGroup :=
ab_subgroup (image_subgroup i)
definition derived_couple_B : AbGroup :=
homology (differential EC) (differential_is_differential EC)
definition derived_couple_i : derived_couple_A →g derived_couple_A :=
(image_lift (exact_couple.i EC)) ∘g (image_incl (exact_couple.i EC))
definition SES_of_exact_couple_at_i : SES (ab_kernel i) A (ab_image i) :=
begin
fapply SES_iso_C,
fapply SES_of_subgroup (kernel_subgroup i),
fapply ab_group_first_iso_thm i,
end
definition kj_zero (a : A) : k (j a) = 1 :=
is_exact.im_in_ker (exact_couple.exact_jk EC) a
definition j_factor : A →g (ab_kernel d) :=
begin
fapply ab_hom_lift j,
intro a,
unfold kernel_subgroup,
exact calc
d (j a) = j (k (j a)) : rfl
... = j 1 : by exact ap j (kj_zero a)
... = 1 : to_respect_one,
end
definition subgroup_iso_exact_at_A : ab_kernel i ≃g ab_image k :=
begin
fapply ab_subgroup_iso,
intro a,
induction EC,
induction exact_ki,
exact ker_in_im a,
intro a b, induction b with f, induction f with b p, induction p,
induction EC,
induction exact_ki,
exact im_in_ker b,
end
definition subgroup_iso_exact_at_A_triangle : ab_kernel_incl i ~ ab_image_incl k ∘g subgroup_iso_exact_at_A :=
begin
fapply ab_subgroup_iso_triangle,
intro a b, induction b with f, induction f with b p, induction p,
induction EC, induction exact_ki, exact im_in_ker b,
end
definition subgroup_homom_ker_to_im : ab_kernel i →g ab_image d :=
(image_homomorphism k j) ∘g subgroup_iso_exact_at_A
open eq
definition left_square_derived_ses : j_factor ∘g (ab_kernel_incl i) ~ (SES.f (SES_of_differential d H)) ∘g subgroup_homom_ker_to_im :=
begin
intro x,
fapply subtype_eq,
refine sorry
-- fapply ab_hom_factors_through_lift _ _ ,
--(ap (j_factor) subgroup_iso_exact_at_A_triangle) ⬝ _,
end
/-definition derived_couple_j : derived_couple_A EC →g derived_couple_B EC :=
begin
exact sorry,
-- refine (comm_gq_map (comm_kernel (boundary CC)) (image_subgroup_of_bd (boundary CC) (boundary_is_boundary CC))) ∘g _,
end-/
end derived_couple
|
50bdbdc6e9ceacb318048932fb752382689110ae | 63abd62053d479eae5abf4951554e1064a4c45b4 | /src/data/nat/cast.lean | abf7d4c4ff903d5884209c5a3843df5d9ce31e3f | [
"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 | 9,887 | lean | /-
Copyright (c) 2014 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
Natural homomorphism from the natural numbers into a monoid with one.
-/
import algebra.ordered_field
import data.nat.basic
namespace nat
variables {α : Type*}
section
variables [has_zero α] [has_one α] [has_add α]
/-- Canonical homomorphism from `ℕ` to a type `α` with `0`, `1` and `+`. -/
protected def cast : ℕ → α
| 0 := 0
| (n+1) := cast n + 1
/--
Coercions such as `nat.cast_coe` that go from a concrete structure such as
`ℕ` to an arbitrary ring `α` should be set up as follows:
```lean
@[priority 900] instance : has_coe_t ℕ α := ⟨...⟩
```
It needs to be `has_coe_t` instead of `has_coe` because otherwise type-class
inference would loop when constructing the transitive coercion `ℕ → ℕ → ℕ → ...`.
The reduced priority is necessary so that it doesn't conflict with instances
such as `has_coe_t α (option α)`.
For this to work, we reduce the priority of the `coe_base` and `coe_trans`
instances because we want the instances for `has_coe_t` to be tried in the
following order:
1. `has_coe_t` instances declared in mathlib (such as `has_coe_t α (with_top α)`, etc.)
2. `coe_base`, which contains instances such as `has_coe (fin n) n`
3. `nat.cast_coe : has_coe_t ℕ α` etc.
4. `coe_trans`
If `coe_trans` is tried first, then `nat.cast_coe` doesn't get a chance to apply.
-/
library_note "coercion into rings"
attribute [instance, priority 950] coe_base
attribute [instance, priority 500] coe_trans
-- see note [coercion into rings]
@[priority 900] instance cast_coe : has_coe_t ℕ α := ⟨nat.cast⟩
@[simp, norm_cast] theorem cast_zero : ((0 : ℕ) : α) = 0 := rfl
theorem cast_add_one (n : ℕ) : ((n + 1 : ℕ) : α) = n + 1 := rfl
@[simp, norm_cast, priority 500]
theorem cast_succ (n : ℕ) : ((succ n : ℕ) : α) = n + 1 := rfl
@[simp, norm_cast] theorem cast_ite (P : Prop) [decidable P] (m n : ℕ) :
(((ite P m n) : ℕ) : α) = ite P (m : α) (n : α) :=
by { split_ifs; refl, }
end
@[simp, norm_cast] theorem cast_one [add_monoid α] [has_one α] : ((1 : ℕ) : α) = 1 := zero_add _
@[simp, norm_cast] theorem cast_add [add_monoid α] [has_one α] (m) : ∀ n, ((m + n : ℕ) : α) = m + n
| 0 := (add_zero _).symm
| (n+1) := show ((m + n : ℕ) : α) + 1 = m + (n + 1), by rw [cast_add n, add_assoc]
/-- `coe : ℕ → α` as an `add_monoid_hom`. -/
def cast_add_monoid_hom (α : Type*) [add_monoid α] [has_one α] : ℕ →+ α :=
{ to_fun := coe,
map_add' := cast_add,
map_zero' := cast_zero }
@[simp] lemma coe_cast_add_monoid_hom [add_monoid α] [has_one α] :
(cast_add_monoid_hom α : ℕ → α) = coe := rfl
@[simp, norm_cast] theorem cast_bit0 [add_monoid α] [has_one α] (n : ℕ) :
((bit0 n : ℕ) : α) = bit0 n := cast_add _ _
@[simp, norm_cast] theorem cast_bit1 [add_monoid α] [has_one α] (n : ℕ) :
((bit1 n : ℕ) : α) = bit1 n :=
by rw [bit1, cast_add_one, cast_bit0]; refl
lemma cast_two {α : Type*} [semiring α] : ((2 : ℕ) : α) = 2 := by simp
@[simp, norm_cast] theorem cast_pred [add_group α] [has_one α] :
∀ {n}, 0 < n → ((n - 1 : ℕ) : α) = n - 1
| (n+1) h := (add_sub_cancel (n:α) 1).symm
@[simp, norm_cast] theorem cast_sub [add_group α] [has_one α] {m n} (h : m ≤ n) :
((n - m : ℕ) : α) = n - m :=
eq_sub_of_add_eq $ by rw [← cast_add, nat.sub_add_cancel h]
@[simp, norm_cast] theorem cast_mul [semiring α] (m) : ∀ n, ((m * n : ℕ) : α) = m * n
| 0 := (mul_zero _).symm
| (n+1) := (cast_add _ _).trans $
show ((m * n : ℕ) : α) + m = m * (n + 1), by rw [cast_mul n, left_distrib, mul_one]
@[simp] theorem cast_dvd {α : Type*} [field α] {m n : ℕ} (n_dvd : n ∣ m) (n_nonzero : (n:α) ≠ 0) : ((m / n : ℕ) : α) = m / n :=
begin
rcases n_dvd with ⟨k, rfl⟩,
have : n ≠ 0, {rintro rfl, simpa using n_nonzero},
rw nat.mul_div_cancel_left _ (nat.pos_iff_ne_zero.2 this),
rw [nat.cast_mul, mul_div_cancel_left _ n_nonzero],
end
/-- `coe : ℕ → α` as a `ring_hom` -/
def cast_ring_hom (α : Type*) [semiring α] : ℕ →+* α :=
{ to_fun := coe,
map_one' := cast_one,
map_mul' := cast_mul,
.. cast_add_monoid_hom α }
@[simp] lemma coe_cast_ring_hom [semiring α] : (cast_ring_hom α : ℕ → α) = coe := rfl
lemma cast_commute [semiring α] (n : ℕ) (x : α) : commute ↑n x :=
nat.rec_on n (commute.zero_left x) $ λ n ihn, ihn.add_left $ commute.one_left x
lemma commute_cast [semiring α] (x : α) (n : ℕ) : commute x n :=
(n.cast_commute x).symm
@[simp] theorem cast_nonneg [linear_ordered_semiring α] : ∀ n : ℕ, 0 ≤ (n : α)
| 0 := le_refl _
| (n+1) := add_nonneg (cast_nonneg n) zero_le_one
theorem strict_mono_cast [linear_ordered_semiring α] : strict_mono (coe : ℕ → α) :=
λ m n h, nat.le_induction (lt_add_of_pos_right _ zero_lt_one)
(λ n _ h, lt_add_of_lt_of_pos h zero_lt_one) _ h
@[simp, norm_cast] theorem cast_le [linear_ordered_semiring α] {m n : ℕ} : (m : α) ≤ n ↔ m ≤ n :=
strict_mono_cast.le_iff_le
@[simp, norm_cast] theorem cast_lt [linear_ordered_semiring α] {m n : ℕ} : (m : α) < n ↔ m < n :=
strict_mono_cast.lt_iff_lt
@[simp] theorem cast_pos [linear_ordered_semiring α] {n : ℕ} : (0 : α) < n ↔ 0 < n :=
by rw [← cast_zero, cast_lt]
lemma cast_add_one_pos [linear_ordered_semiring α] (n : ℕ) : 0 < (n : α) + 1 :=
add_pos_of_nonneg_of_pos n.cast_nonneg zero_lt_one
@[simp, norm_cast] theorem one_lt_cast [linear_ordered_semiring α] {n : ℕ} : 1 < (n : α) ↔ 1 < n :=
by rw [← cast_one, cast_lt]
@[simp, norm_cast] theorem one_le_cast [linear_ordered_semiring α] {n : ℕ} : 1 ≤ (n : α) ↔ 1 ≤ n :=
by rw [← cast_one, cast_le]
@[simp, norm_cast] theorem cast_lt_one [linear_ordered_semiring α] {n : ℕ} : (n : α) < 1 ↔ n = 0 :=
by rw [← cast_one, cast_lt, lt_succ_iff, le_zero_iff]
@[simp, norm_cast] theorem cast_le_one [linear_ordered_semiring α] {n : ℕ} : (n : α) ≤ 1 ↔ n ≤ 1 :=
by rw [← cast_one, cast_le]
@[simp, norm_cast] theorem cast_min [linear_ordered_semiring α] {a b : ℕ} :
(↑(min a b) : α) = min a b :=
by by_cases a ≤ b; simp [h, min]
@[simp, norm_cast] theorem cast_max [linear_ordered_semiring α] {a b : ℕ} :
(↑(max a b) : α) = max a b :=
by by_cases a ≤ b; simp [h, max]
@[simp, norm_cast] theorem abs_cast [linear_ordered_comm_ring α] (a : ℕ) :
abs (a : α) = a :=
abs_of_nonneg (cast_nonneg a)
lemma coe_nat_dvd [comm_semiring α] {m n : ℕ} (h : m ∣ n) :
(m : α) ∣ (n : α) :=
ring_hom.map_dvd (nat.cast_ring_hom α) h
alias coe_nat_dvd ← has_dvd.dvd.nat_cast
section linear_ordered_field
variables [linear_ordered_field α]
lemma inv_pos_of_nat {n : ℕ} : 0 < ((n : α) + 1)⁻¹ :=
inv_pos.2 $ add_pos_of_nonneg_of_pos n.cast_nonneg zero_lt_one
lemma one_div_pos_of_nat {n : ℕ} : 0 < 1 / ((n : α) + 1) :=
by { rw one_div, exact inv_pos_of_nat }
lemma one_div_le_one_div {n m : ℕ} (h : n ≤ m) : 1 / ((m : α) + 1) ≤ 1 / ((n : α) + 1) :=
by { refine one_div_le_one_div_of_le _ _, exact nat.cast_add_one_pos _, simpa }
lemma one_div_lt_one_div {n m : ℕ} (h : n < m) : 1 / ((m : α) + 1) < 1 / ((n : α) + 1) :=
by { refine one_div_lt_one_div_of_lt _ _, exact nat.cast_add_one_pos _, simpa }
end linear_ordered_field
end nat
namespace add_monoid_hom
variables {A B : Type*} [add_monoid A]
@[ext] lemma ext_nat {f g : ℕ →+ A} (h : f 1 = g 1) : f = g :=
ext $ λ n, nat.rec_on n (f.map_zero.trans g.map_zero.symm) $ λ n ihn,
by simp only [nat.succ_eq_add_one, *, map_add]
variables [has_one A] [add_monoid B] [has_one B]
lemma eq_nat_cast (f : ℕ →+ A) (h1 : f 1 = 1) :
∀ n : ℕ, f n = n :=
congr_fun $ show f = nat.cast_add_monoid_hom A, from ext_nat (h1.trans nat.cast_one.symm)
lemma map_nat_cast (f : A →+ B) (h1 : f 1 = 1) (n : ℕ) : f n = n :=
(f.comp (nat.cast_add_monoid_hom A)).eq_nat_cast (by simp [h1]) _
end add_monoid_hom
namespace ring_hom
variables {R : Type*} {S : Type*} [semiring R] [semiring S]
@[simp] lemma eq_nat_cast (f : ℕ →+* R) (n : ℕ) : f n = n :=
f.to_add_monoid_hom.eq_nat_cast f.map_one n
@[simp] lemma map_nat_cast (f : R →+* S) (n : ℕ) :
f n = n :=
(f.comp (nat.cast_ring_hom R)).eq_nat_cast n
lemma ext_nat (f g : ℕ →+* R) : f = g :=
coe_add_monoid_hom_injective $ add_monoid_hom.ext_nat $ f.map_one.trans g.map_one.symm
end ring_hom
@[simp, norm_cast] theorem nat.cast_id (n : ℕ) : ↑n = n :=
((ring_hom.id ℕ).eq_nat_cast n).symm
@[simp] theorem nat.cast_with_bot : ∀ (n : ℕ),
@coe ℕ (with_bot ℕ) (@coe_to_lift _ _ nat.cast_coe) n = n
| 0 := rfl
| (n+1) := by rw [with_bot.coe_add, nat.cast_add, nat.cast_with_bot n]; refl
instance nat.subsingleton_ring_hom {R : Type*} [semiring R] : subsingleton (ℕ →+* R) :=
⟨ring_hom.ext_nat⟩
namespace with_top
variables {α : Type*}
variables [has_zero α] [has_one α] [has_add α]
@[simp, norm_cast] lemma coe_nat : ∀(n : nat), ((n : α) : with_top α) = n
| 0 := rfl
| (n+1) := by { push_cast, rw [coe_nat n] }
@[simp] lemma nat_ne_top (n : nat) : (n : with_top α) ≠ ⊤ :=
by { rw [←coe_nat n], apply coe_ne_top }
@[simp] lemma top_ne_nat (n : nat) : (⊤ : with_top α) ≠ n :=
by { rw [←coe_nat n], apply top_ne_coe }
lemma add_one_le_of_lt {i n : with_top ℕ} (h : i < n) : i + 1 ≤ n :=
begin
cases n, { exact le_top },
cases i, { exact (not_le_of_lt h le_top).elim },
exact with_top.coe_le_coe.2 (with_top.coe_lt_coe.1 h)
end
@[elab_as_eliminator]
lemma nat_induction {P : with_top ℕ → Prop} (a : with_top ℕ)
(h0 : P 0) (hsuc : ∀n:ℕ, P n → P n.succ) (htop : (∀n : ℕ, P n) → P ⊤) : P a :=
begin
have A : ∀n:ℕ, P n := λ n, nat.rec_on n h0 hsuc,
cases a,
{ exact htop A },
{ exact A a }
end
end with_top
|
b1cd676002edeaee62640a1593f1d5ad4819905d | e151e9053bfd6d71740066474fc500a087837323 | /src/hott/init/pathover.lean | 7fb6af578ee9bf8ec442a1b1a4bddcd5224404b2 | [
"Apache-2.0"
] | permissive | daniel-carranza/hott3 | 15bac2d90589dbb952ef15e74b2837722491963d | 913811e8a1371d3a5751d7d32ff9dec8aa6815d9 | refs/heads/master | 1,610,091,349,670 | 1,596,222,336,000 | 1,596,222,336,000 | 241,957,822 | 0 | 0 | Apache-2.0 | 1,582,222,839,000 | 1,582,222,838,000 | null | UTF-8 | Lean | false | false | 20,165 | lean | /-
Copyright (c) 2015 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Floris van Doorn
Basic theorems about pathovers
-/
import .path .equiv
universes u v l
hott_theory
namespace hott
open hott.equiv hott.is_equiv function
variables {A : Type _} {A' : Type _} {B : A → Type _} {B' : A → Type _} {B'' : A' → Type _} {C : Π⦃a⦄, B a → Type _}
{a a₂ a₃ a₄ : A} {p p' : a = a₂} {p₂ : a₂ = a₃} {p₃ : a₃ = a₄} {p₁₃ : a = a₃}
{b b' : B a} {b₂ b₂' : B a₂} {b₃ : B a₃} {b₄ : B a₄}
{c : C b} {c₂ : C b₂}
namespace eq
inductive pathover (B : A → Type l) (b : B a) : Π{a₂ : A}, a = a₂ → B a₂ → Type l
| idpatho : pathover (refl a) b
notation b ` =[`:50 p:0 `] `:0 b₂:50 := pathover _ b p b₂
notation b ` =[`:50 p:0 `; `:0 B `] `:0 b₂:50 := pathover B b p b₂
@[hott, refl, reducible]
def idpo : b =[refl a] b :=
pathover.idpatho b
@[hott, reducible] def idpatho (b : B a) : b =[refl a] b :=
pathover.idpatho b
/- equivalences with equality using transport -/
@[hott] def pathover_of_tr_eq (r : p ▸ b = b₂) : b =[p] b₂ :=
by hinduction p; hinduction r; constructor
@[hott] def pathover_of_eq_tr (r : b = p⁻¹ ▸ b₂) : b =[p] b₂ :=
begin hinduction p, dsimp at r, hinduction r, constructor end
@[hott] def tr_eq_of_pathover (r : b =[p] b₂) : p ▸ b = b₂ :=
by hinduction r; reflexivity
@[hott] def eq_tr_of_pathover (r : b =[p] b₂) : b = p⁻¹ ▸ b₂ :=
by hinduction r; reflexivity
@[hott] def pathover_equiv_tr_eq (p : a = a₂) (b : B a) (b₂ : B a₂)
: (b =[p] b₂) ≃ (p ▸ b = b₂) :=
begin
fapply equiv.MK,
{ exact tr_eq_of_pathover },
{ exact pathover_of_tr_eq },
{ intro r, hinduction p, hinduction r, refl },
{ intro r, hinduction r, refl },
end
@[hott] def pathover_equiv_eq_tr (p : a = a₂) (b : B a) (b₂ : B a₂)
: (b =[p] b₂) ≃ (b = p⁻¹ ▸ b₂) :=
begin
fapply equiv.MK,
{ exact eq_tr_of_pathover},
{ exact pathover_of_eq_tr},
{ intro r, hinduction p, change b = b₂ at r, hinduction r, apply idp},
{ intro r, hinduction r, apply idp},
end
@[hott] def pathover_tr (p : a = a₂) (b : B a) : b =[p] p ▸ b :=
by hinduction p; constructor
@[hott] def tr_pathover (p : a = a₂) (b : B a₂) : p⁻¹ ▸ b =[p] b :=
by hinduction p; constructor
@[hott] def concato (r : b =[p] b₂) (r₂ : b₂ =[p₂] b₃) : b =[p ⬝ p₂] b₃ :=
by hinduction r₂; exact r
@[hott] def inverseo (r : b =[p] b₂) : b₂ =[p⁻¹] b :=
by hinduction r; constructor
@[hott] def concato_eq (r : b =[p] b₂) (q : b₂ = b₂') : b =[p] b₂' :=
by hinduction q; exact r
@[hott] def eq_concato (q : b = b') (r : b' =[p] b₂) : b =[p] b₂ :=
by hinduction q; exact r
@[hott] def change_path (q : p = p') (r : b =[p] b₂) : b =[p'] b₂ :=
q ▸ r
@[hott, hsimp] def change_path_idp (r : b =[p] b₂) : change_path idp r = r :=
by reflexivity
-- infix ` ⬝ ` := concato
infix ` ⬝o `:72 := concato
infix ` ⬝op `:73 := concato_eq
infix ` ⬝po `:73 := eq_concato
-- postfix `⁻¹` := inverseo
postfix `⁻¹ᵒ`:(max+10) := inverseo
@[hott] def pathover_cancel_right (q : b =[p ⬝ p₂] b₃) (r : b₃ =[p₂⁻¹] b₂) : b =[p] b₂ :=
change_path (con_inv_cancel_right _ _) (q ⬝o r)
@[hott] def pathover_cancel_right' (q : b =[p₁₃ ⬝ p₂⁻¹] b₂) (r : b₂ =[p₂] b₃) : b =[p₁₃] b₃ :=
change_path (inv_con_cancel_right _ _) (q ⬝o r)
@[hott] def pathover_cancel_left (q : b₂ =[p⁻¹] b) (r : b =[p ⬝ p₂] b₃) : b₂ =[p₂] b₃ :=
change_path (inv_con_cancel_left _ _) (q ⬝o r)
@[hott] def pathover_cancel_left' (q : b =[p] b₂) (r : b₂ =[p⁻¹ ⬝ p₁₃] b₃) : b =[p₁₃] b₃ :=
change_path (con_inv_cancel_left _ _) (q ⬝o r)
/- Some of the theorems analogous to theorems for = in init.path -/
@[hott, hsimp] def idpo_invo : idpo⁻¹ᵒ = idpo :> b =[idp] b :=
by refl
@[hott, hsimp] def cono_idpo (r : b =[p] b₂) : r ⬝o idpo = r :=
by refl
@[hott] def idpo_cono (r : b =[p] b₂) : idpo ⬝o r =[idp_con p; λ x, b =[x] b₂] r :=
by hinduction r; refl
@[hott] def cono.assoc' (r : b =[p] b₂) (r₂ : b₂ =[p₂] b₃) (r₃ : b₃ =[p₃] b₄) :
r ⬝o (r₂ ⬝o r₃) =[con.assoc' _ _ _; λ x, b =[x] b₄] ((r ⬝o r₂) ⬝o r₃) :=
by hinduction r₃; hinduction r₂; hinduction r; refl
@[hott] def cono.assoc (r : b =[p] b₂) (r₂ : b₂ =[p₂] b₃) (r₃ : b₃ =[p₃] b₄) :
(r ⬝o r₂) ⬝o r₃ =[con.assoc _ _ _; λ x, b =[x] b₄] r ⬝o (r₂ ⬝o r₃) :=
by hinduction r₃; hinduction r₂; hinduction r; refl
@[hott] def cono.right_inv (r : b =[p] b₂) : r ⬝o r⁻¹ᵒ =[con.right_inv _; λ x, b =[x] b] idpo :=
by hinduction r; refl
@[hott] def cono.left_inv (r : b =[p] b₂) : r⁻¹ᵒ ⬝o r =[con.left_inv _; λ x, b₂ =[x] b₂] idpo :=
by hinduction r; refl
@[hott] def eq_of_pathover {a' a₂' : A'} (q : a' =[p; λ _, A'] a₂') : a' = a₂' :=
by hinduction q; refl
@[hott] def pathover_of_eq (p : a = a₂) {a' a₂' : A'} (q : a' = a₂') : a' =[p; λ _, A'] a₂' :=
by hinduction p; hinduction q; constructor
@[hott] def pathover_constant (p : a = a₂) (a' a₂' : A') : a' =[p; λ _, A'] a₂' ≃ a' = a₂' :=
begin
fapply equiv.MK,
{ exact eq_of_pathover},
{ exact pathover_of_eq p},
abstract { intro r, hinduction p, hinduction r, refl},
abstract { intro r, hinduction r, refl},
end
@[hott]
def pathover_of_eq_tr_constant_inv (p : a = a₂) (a' : A')
: pathover_of_eq p (tr_constant p a')⁻¹ = pathover_tr p a' :=
by hinduction p; constructor
@[hott, elab_simple]
def eq_of_pathover_idp {b' : B a} (q : b =[idpath a] b') : b = b' :=
tr_eq_of_pathover q
variable (B)
@[hott]
def pathover_idp_of_eq {b' : B a} (q : b = b') : b =[idpath a] b' :=
pathover_of_tr_eq q
@[hott]
def pathover_idp (b : B a) (b' : B a) : b =[idpath a] b' ≃ b = b' :=
begin
fapply equiv.MK,
{exact eq_of_pathover_idp},
{exact pathover_idp_of_eq B},
{intros, refine to_right_inv (pathover_equiv_tr_eq _ _ _) _ },
{intro r, refine to_left_inv (pathover_equiv_tr_eq _ _ _) r, }
end
variable {B}
@[hott, hsimp]
def eq_of_pathover_idp_pathover_of_eq {A X : Type _} (x : X) {a a' : A} (p : a = a') :
eq_of_pathover_idp (pathover_of_eq (idpath x) p) = p :=
by hinduction p; refl
variable (B)
@[hott, hsimp] def idpo_concato_eq (r : b = b') : eq_of_pathover_idp (@idpo A B a b ⬝op r) = r :=
by hinduction r; reflexivity
variable {B}
-- def pathover_idp (b : B a) (b' : B a) : b =[idpath a] b' ≃ b = b' :=
-- pathover_equiv_tr_eq idp b b'
-- def eq_of_pathover_idp [reducible] {b' : B a} (q : b =[idpath a] b') : b = b' :=
-- to_fun !pathover_idp q
-- def pathover_idp_of_eq [reducible] {b' : B a} (q : b = b') : b =[idpath a] b' :=
-- to_inv !pathover_idp q
attribute [induction, priority 1000] pathover.rec
@[hott, elab_as_eliminator, reducible, induction, priority 500] def idp_rec_on {P : Π⦃b₂ : B a⦄, b =[hott.eq.refl a] b₂ → Type u}
{b₂ : B a} (r : b =[hott.eq.refl a] b₂) (H : P idpo) : P r :=
by exact
have H2 : P (pathover_idp_of_eq B (eq_of_pathover_idp r)), from
eq.rec_on (eq_of_pathover_idp r) H,
have H3 : pathover_idp_of_eq B (eq_of_pathover_idp r) = r,
from to_left_inv (pathover_idp B b b₂) r,
H3 ▸ H2
@[hott] def rec_on_right {P : Π⦃b₂ : B a₂⦄, b =[p] b₂ → Type _}
{b₂ : B a₂} (r : b =[p] b₂) (H : P (pathover_tr _ _)) : P r :=
by hinduction r; exact H
@[hott] def rec_on_left {P : Π⦃b : B a⦄, b =[p] b₂ → Type _}
{b : B a} (r : b =[p] b₂) (H : P (tr_pathover _ _)) : P r :=
by hinduction r; exact H
@[hott] def pathover_ap (B' : A' → Type _) (f : A → A') {p : a = a₂}
{b : B' (f a)} {b₂ : B' (f a₂)} (q : b =[p; B' ∘ f] b₂) : b =[ap f p] b₂ :=
by hinduction q; constructor
@[hott] def pathover_of_pathover_ap (B' : A' → Type u) (f : A → A') {p : a = a₂}
{b : B' (f a)} {b₂ : B' (f a₂)} (q : b =[ap f p] b₂) : b =[p; B' ∘ f] b₂ :=
begin
hinduction p, hinduction q, exact idpo
end
@[hott] def pathover_compose (B' : A' → Type _) (f : A → A') (p : a = a₂)
(b : B' (f a)) (b₂ : B' (f a₂)) : b =[p; B' ∘ f] b₂ ≃ b =[ap f p] b₂ :=
begin
fapply equiv.MK,
{ exact pathover_ap B' f},
{ exact pathover_of_pathover_ap B' f},
{ intro q, hinduction p, hinduction q, refl},
{ intro q, hinduction q, refl},
end
@[hott] def pathover_of_pathover_tr (q : b =[p ⬝ p₂] p₂ ▸ b₂) : b =[p] b₂ :=
pathover_cancel_right q (pathover_tr _ _)⁻¹ᵒ
@[hott] def pathover_tr_of_pathover (q : b =[p₁₃ ⬝ p₂⁻¹] b₂) : b =[p₁₃] p₂ ▸ b₂ :=
pathover_cancel_right' q (pathover_tr _ _)
@[hott] def pathover_of_tr_pathover (q : p ▸ b =[p⁻¹ ⬝ p₁₃] b₃) : b =[p₁₃] b₃ :=
pathover_cancel_left' (pathover_tr _ _) q
@[hott] def tr_pathover_of_pathover (q : b =[p ⬝ p₂] b₃) : p ▸ b =[p₂] b₃ :=
pathover_cancel_left (pathover_tr _ _)⁻¹ᵒ q
@[hott] def pathover_tr_of_eq (q : b = b') : b =[p] p ▸ b' :=
by hinduction q;apply pathover_tr
@[hott] def tr_pathover_of_eq (q : b₂ = b₂') : p⁻¹ ▸ b₂ =[p] b₂' :=
by hinduction q;apply tr_pathover
@[hott] def eq_of_parallel_po_right (q : b =[p] b₂) (q' : b =[p] b₂') : b₂ = b₂' :=
begin
apply @eq_of_pathover_idp A B, apply change_path (con.left_inv p),
exact q⁻¹ᵒ ⬝o q'
end
@[hott] def eq_of_parallel_po_left (q : b =[p] b₂) (q' : b' =[p] b₂) : b = b' :=
begin
apply @eq_of_pathover_idp A B, apply change_path (con.right_inv p),
exact q ⬝o q'⁻¹ᵒ
end
variable (C)
@[hott, elab_simple] def transporto (r : b =[p] b₂) (c : C b) : C b₂ :=
by hinduction r;exact c
infix ` ▸o `:75 := transporto _
@[hott] def fn_tro_eq_tro_fn {C' : Π ⦃a : A⦄, B a → Type _} (q : b =[p] b₂)
(f : Π⦃a : A⦄ (b : B a), C b → C' b) (c : C b) : f b₂ (q ▸o c) = q ▸o (f b c) :=
by hinduction q; reflexivity
variable {C}
/- various variants of ap for pathovers -/
@[hott] def apd (f : Πa, B a) (p : a = a₂) : f a =[p] f a₂ :=
by hinduction p; constructor
@[hott, hsimp] def apd_idp (f : Πa, B a) : apd f (refl a) = idpo :=
by reflexivity
@[hott] def apo {f : A → A'} (g : Πa, B a → B'' (f a)) (q : b =[p] b₂) :
g a b =[p; B'' ∘ f] g a₂ b₂ :=
by hinduction q; constructor
@[hott] def apd011 (f : Πa, B a → A') (Ha : a = a₂) (Hb : b =[Ha] b₂)
: f a b = f a₂ b₂ :=
by hinduction Hb; reflexivity
@[hott] def apd0111 (f : Πa b, C b → A') (Ha : a = a₂) (Hb : b =[Ha] b₂)
(Hc : c =[apd011 C Ha Hb; id] c₂) : f a b c = f a₂ b₂ c₂ :=
begin hinduction Hb, hinduction Hc, refl end
@[hott] def apod11 {f : Πb, C b} {g : Πb₂, C b₂} (r : f =[p; λ a, Π b : B a, C b] g)
{b : B a} {b₂ : B a₂} (q : b =[p] b₂) : f b =[apd011 C p q; id] g b₂ :=
by hinduction r; hinduction q; constructor
@[hott] def apdo10 {f : Πb, C b} {g : Πb₂, C b₂} (r : f =[p; λ a, Π b : B a, C b] g)
(b : B a) : f b =[apd011 C p (pathover_tr _ _); id] g (p ▸ b) :=
by hinduction r; constructor
@[hott] def apo10 {f : B a → B' a} {g : B a₂ → B' a₂} (r : f =[p; λ a, B a → B' a] g)
(b : B a) : f b =[p] g (p ▸ b) :=
by hinduction r; constructor
@[hott] def apo10_constant_right {f : B a → A'} {g : B a₂ → A'} (r : f =[p; λ a, B a → A'] g)
(b : B a) : f b = g (p ▸ b) :=
by hinduction r; constructor
@[hott] def apo10_constant_left {f : A' → B a} {g : A' → B a₂} (r : f =[p; λ a, A' → B a] g)
(a' : A') : f a' =[p] g a' :=
by hinduction r; constructor
@[hott] def apo11 {f : B a → B' a} {g : B a₂ → B' a₂} (r : f =[p; λ a, B a → B' a] g)
(q : b =[p] b₂) : f b =[p] g b₂ :=
by hinduction q; exact apo10 r b
@[hott] def apo011 {A : Type _} {B C D : A → Type _} {a a' : A} {p : a = a'} {b : B a} {b' : B a'}
{c : C a} {c' : C a'} (f : Π⦃a⦄, B a → C a → D a) (q : b =[p] b') (r : c =[p] c') :
f b c =[p] f b' c' :=
begin hinduction q, hinduction r, exact idpo end
@[hott] def apdo011 {A : Type _} {B : A → Type _} {C : Π⦃a⦄, B a → Type _}
(f : Π⦃a⦄ (b : B a), C b) {a a' : A} (p : a = a') {b : B a} {b' : B a'} (q : b =[p] b')
: f b =[apd011 C p q; id] f b' :=
by hinduction q; constructor
@[hott] def apdo0111 {A : Type _} {B : A → Type _} {C C' : Π⦃a⦄, B a → Type _}
(f : Π⦃a⦄ {b : B a}, C b → C' b) {a a' : A} (p : a = a') {b : B a} {b' : B a'} (q : b =[p] b')
{c : C b} {c' : C b'} (r : c =[apd011 C p q; id] c')
: f c =[apd011 C' p q; id] f c' :=
begin
hinduction q, hinduction r, refl
end
@[hott] def apo11_constant_right {f : B a → A'} {g : B a₂ → A'}
(q : f =[p; λ a, B a → A'] g) (r : b =[p] b₂) : f b = g b₂ :=
eq_of_pathover (apo11 q r)
/- properties about these "ap"s, transporto and pathover_ap -/
@[hott] def apd_con (f : Πa, B a) (p : a = a₂) (q : a₂ = a₃)
: apd f (p ⬝ q) = apd f p ⬝o apd f q :=
by hinduction p; hinduction q; reflexivity
@[hott] def apd_inv (f : Πa, B a) (p : a = a₂) : apd f p⁻¹ = (apd f p)⁻¹ᵒ :=
by hinduction p; reflexivity
@[hott] def apd_eq_pathover_of_eq_ap (f : A → A') (p : a = a₂) :
apd f p = pathover_of_eq p (ap f p) :=
eq.rec_on p idp
@[hott] def apo_invo (f : Πa, B a → B' a) {Ha : a = a₂} (Hb : b =[Ha] b₂)
: (apo f Hb)⁻¹ᵒ = apo f Hb⁻¹ᵒ :=
by hinduction Hb; reflexivity
@[hott] def apd011_inv (f : Πa, B a → A') (Ha : a = a₂) (Hb : b =[Ha] b₂)
: (apd011 f Ha Hb)⁻¹ = (apd011 f Ha⁻¹ Hb⁻¹ᵒ) :=
by hinduction Hb; reflexivity
@[hott] def cast_apd011 (q : b =[p] b₂) (c : C b) : cast (apd011 C p q) c = q ▸o c :=
by hinduction q; reflexivity
@[hott] def apd_compose1 (g : Πa, B a → B' a) (f : Πa, B a) (p : a = a₂)
: apd (g ∘' f) p = apo g (apd f p) :=
by hinduction p; reflexivity
@[hott] def apd_compose2 (g : Πa', B'' a') (f : A → A') (p : a = a₂)
: apd (λa, g (f a)) p = pathover_of_pathover_ap B'' f (apd g (ap f p)) :=
by hinduction p; reflexivity
@[hott] def apo_tro (C : Π⦃a⦄, B' a → Type _) (f : Π⦃a⦄, B a → B' a) (q : b =[p] b₂)
(c : C (f b)) : apo f q ▸o c = q ▸o c :=
by hinduction q; reflexivity
@[hott] def pathover_ap_tro {B' : A' → Type _} (C : Π⦃a'⦄, B' a' → Type _) (f : A → A')
{b : B' (f a)} {b₂ : B' (f a₂)} (q : b =[p; B' ∘ f] b₂) (c : C b) :
pathover_ap B' f q ▸o c = q ▸o c :=
by hinduction q; reflexivity
@[hott] def pathover_ap_invo_tro {B' : A' → Type _} (C : Π⦃a'⦄, B' a' → Type _) (f : A → A')
{b : B' (f a)} {b₂ : B' (f a₂)} (q : b =[p; B' ∘ f] b₂) (c : C b₂)
: (pathover_ap B' f q)⁻¹ᵒ ▸o c = q⁻¹ᵒ ▸o c :=
by hinduction q; reflexivity
@[hott, elab_simple] def pathover_tro (q : b =[p] b₂) (c : C b) : c =[apd011 C p q; id] q ▸o c :=
by hinduction q; constructor
@[hott] def pathover_ap_invo {B' : A' → Type _} (f : A → A') {p : a = a₂}
{b : B' (f a)} {b₂ : B' (f a₂)} (q : b =[p; B' ∘ f] b₂)
: pathover_ap B' f q⁻¹ᵒ =[ap_inv f p; λ x, b₂ =[x] b] (pathover_ap B' f q)⁻¹ᵒ :=
by hinduction q; exact idpo
@[hott] def tro_invo_tro {A : Type _} {B : A → Type _} (C : Π⦃a⦄, B a → Type _)
{a a' : A} {p : a = a'} {b : B a} {b' : B a'} (q : b =[p] b') (c : C b') :
q ▸o (q⁻¹ᵒ ▸o c) = c :=
by hinduction q; reflexivity
@[hott] def invo_tro_tro {A : Type _} {B : A → Type _} (C : Π⦃a⦄, B a → Type _)
{a a' : A} {p : a = a'} {b : B a} {b' : B a'} (q : b =[p] b') (c : C b) :
q⁻¹ᵒ ▸o (q ▸o c) = c :=
by hinduction q; reflexivity
@[hott] def cono_tro {A : Type _} {B : A → Type _} (C : Π⦃a⦄, B a → Type _)
{a₁ a₂ a₃ : A} {p₁ : a₁ = a₂} {p₂ : a₂ = a₃} {b₁ : B a₁} {b₂ : B a₂} {b₃ : B a₃}
(q₁ : b₁ =[p₁] b₂) (q₂ : b₂ =[p₂] b₃) (c : C b₁) :
transporto C (q₁ ⬝o q₂) c = transporto C q₂ (transporto C q₁ c) :=
by hinduction q₂; reflexivity
@[hott] def is_equiv_transporto {A : Type _} {B : A → Type _} (C : Π⦃a⦄, B a → Type _)
{a a' : A} {p : a = a'} {b : B a} {b' : B a'} (q : b =[p] b') : is_equiv (transporto C q) :=
begin
fapply adjointify,
{ exact transporto C q⁻¹ᵒ},
{ exact tro_invo_tro C q},
{ exact invo_tro_tro C q}
end
@[hott] def equiv_apd011 {A : Type _} {B : A → Type _} (C : Π⦃a⦄, B a → Type _)
{a a' : A} {p : a = a'} {b : B a} {b' : B a'} (q : b =[p] b') : C b ≃ C b' :=
equiv.mk (transporto C q) (is_equiv_transporto _ _)
/- some cancellation laws for concato_eq an variants -/
@[hott] def cono.right_inv_eq (q : b = b') :
pathover_idp_of_eq B q ⬝op q⁻¹ = (idpo : b =[refl a] b) :=
by hinduction q;constructor
@[hott] def cono.right_inv_eq' (q : b = b') :
q ⬝po (pathover_idp_of_eq B q⁻¹) = (idpo : b =[refl a] b) :=
by hinduction q;constructor
@[hott] def cono.left_inv_eq (q : b = b') :
pathover_idp_of_eq B q⁻¹ ⬝op q = (idpo : b' =[refl a] b') :=
by hinduction q;constructor
@[hott] def cono.left_inv_eq' (q : b = b') :
q⁻¹ ⬝po pathover_idp_of_eq B q = (idpo : b' =[refl a] b') :=
by hinduction q;constructor
@[hott] def pathover_of_fn_pathover_fn (f : Π{a}, B a ≃ B' a) (r : f.to_fun b =[p] f.to_fun b₂) : b =[p] b₂ :=
(left_inv f.to_fun b)⁻¹ ⬝po apo (λa, to_fun f⁻¹ᵉ) r ⬝op left_inv f.to_fun b₂
/- a pathover in a pathover type where the only thing which varies is the path is the same as
an equality with a change_path -/
@[hott] def change_path_of_pathover (s : p = p') (r : b =[p] b₂) (r' : b =[p'] b₂)
(q : r =[s; λ p, b =[p] b₂] r') : change_path s r = r' :=
by hinduction s; hinduction q; reflexivity
@[hott] def pathover_of_change_path (s : p = p') (r : b =[p] b₂) (r' : b =[p'] b₂)
(q : change_path s r = r') : r =[s; λ p, b =[p] b₂] r' :=
by hinduction s; hinduction q; constructor
@[hott] def pathover_pathover_path (s : p = p') (r : b =[p] b₂) (r' : b =[p'] b₂) :
(r =[s; λ p, b =[p] b₂] r') ≃ change_path s r = r' :=
begin
fapply equiv.MK,
{ apply change_path_of_pathover},
{ apply pathover_of_change_path},
{ intro q, hinduction s, hinduction q, reflexivity},
{ intro q, hinduction s, hinduction q, reflexivity},
end
/- variants of inverse2 and concat2 -/
@[hott] def inverseo2 {r r' : b =[p] b₂} (s : r = r') : r⁻¹ᵒ = r'⁻¹ᵒ :=
by hinduction s; reflexivity
@[hott] def concato2 {r r' : b =[p] b₂} {r₂ r₂' : b₂ =[p₂] b₃}
(s : r = r') (s₂ : r₂ = r₂') : r ⬝o r₂ = r' ⬝o r₂' :=
by hinduction s; hinduction s₂; reflexivity
infixl ` ◾o `:75 := concato2
postfix [parsing_only] `⁻²ᵒ`:(max+10) := inverseo2 --this notation is abusive, should we use it?
-- find a better name for this
@[hott] def fn_tro_eq_tro_fn2 (q : b =[p] b₂)
{k : A → A} {l : Π⦃a⦄, B a → B (k a)} (m : Π⦃a⦄ {b : B a}, C b → C (l b))
(c : C b) :
m (q ▸o c) = (pathover_ap B k (apo l q)) ▸o (m c) :=
by hinduction q; reflexivity
@[hott] def apd0111_precompose (f : Π⦃a⦄ {b : B a}, C b → A')
{k : A → A} {l : Π⦃a⦄, B a → B (k a)} (m : Π⦃a⦄ {b : B a}, C b → C (l b))
{q : b =[p] b₂} (c : C b)
: @apd0111 _ _ B _ _ _ _ _ _ _ (λa b (c : C b), f (m c)) p q (pathover_tro q c) ⬝
ap (@f _ _) (fn_tro_eq_tro_fn2 q m c) =
apd0111 f (ap k p) (pathover_ap B k (apo l q)) (pathover_tro _ (m c)) :=
by hinduction q; reflexivity
end eq
end hott
|
2cf3d2ade32c5773cf185a65c5d3213893472d5e | a721fe7446524f18ba361625fc01033d9c8b7a78 | /elaborate/mul_cancel_total_order_no_tactic.stripped.lean | 9ba6b35b84c0253d771dd5a81ee79d64d653c521 | [] | no_license | Sterrs/leaning | 8fd80d1f0a6117a220bb2e57ece639b9a63deadc | 3901cc953694b33adda86cb88ca30ba99594db31 | refs/heads/master | 1,627,023,822,744 | 1,616,515,221,000 | 1,616,515,221,000 | 245,512,190 | 2 | 0 | null | 1,616,429,050,000 | 1,583,527,118,000 | Lean | UTF-8 | Lean | false | false | 17,398 | lean | λ (m n k : mynat) (hmnz : m = zero → false), or.rec (λ (h : ∃ (k_1 : mynat), k = add n k_1) («_» : (∃ (k_1 : mynat), k = add n k_1) ∨ ∃ (k_1 : mynat), n = add k k_1) (hmnmk : mul m n = mul m k), Exists.rec (λ (w : mynat) (h : k = add n w) («_» : ∃ (k_1 : mynat), k = add n k_1), eq.rec true.intro (eq.rec (eq.refl (n = k)) (eq.rec (eq.rec (eq.refl (n = k)) (eq.rec h (eq.rec (eq.refl (add n w)) (mynat.rec (λ (hmn0 : zero = zero), eq.rec true.intro (eq.rec (eq.refl (zero = zero)) (eq.rec (eq.refl (zero = zero)) (propext {mp := λ (hl : zero = zero), true.intro, mpr := λ (hr : true), eq.refl zero})))) (λ (n : mynat) (ih : mul m n = zero → n = zero) (hmn0 : add m (mul m n) = zero), false.rec (succ n = zero) (hmnz (mynat.rec (eq.rec true.intro (eq.rec (eq.refl (add zero (mul m n) = zero → zero = zero)) (eq.rec (propext {mp := λ (hab : add zero (mul m n) = zero → zero = zero) (hc : mul m n = zero), (eq.rec {mp := λ (h : zero = zero), h, mpr := λ (h : zero = zero), h} (eq.rec (eq.refl (zero = zero)) (propext {mp := λ (hl : zero = zero), true.intro, mpr := λ (hr : true), eq.refl zero}))).mp (hab ((eq.rec {mp := λ (h : add zero (mul m n) = zero), h, mpr := λ (h : add zero (mul m n) = zero), h} (eq.rec (eq.refl (add zero (mul m n) = zero)) (eq.rec (eq.refl (eq (add zero (mul m n)))) (eq.rec (eq.refl (add zero (mul m n))) (mynat.rec (eq.rec true.intro (eq.rec (eq.refl (zero = zero)) (eq.rec (eq.refl (zero = zero)) (propext {mp := λ (hl : zero = zero), true.intro, mpr := λ (hr : true), eq.refl zero})))) (λ (n_n : mynat) (n_ih : add zero n_n = n_n), eq.rec n_ih (eq.rec (eq.refl (succ (add zero n_n) = succ n_n)) (eq.rec (eq.refl (succ (add zero n_n) = succ n_n)) (propext {mp := λ (h : succ (add zero n_n) = succ n_n), eq.rec (λ (h11 : succ (add zero n_n) = succ (add zero n_n)) (a : add zero n_n = add zero n_n → add zero n_n = n_n), a (eq.refl (add zero n_n))) h h (λ (n_eq : add zero n_n = n_n), n_eq), mpr := λ (a : add zero n_n = n_n), eq.rec (eq.refl (succ (add zero n_n))) a})))) (mul m n)))))).mpr hc)), mpr := λ (hcd : mul m n = zero → true) (ha : add zero (mul m n) = zero), (eq.rec {mp := λ (h : zero = zero), h, mpr := λ (h : zero = zero), h} (eq.rec (eq.refl (zero = zero)) (propext {mp := λ (hl : zero = zero), true.intro, mpr := λ (hr : true), eq.refl zero}))).mpr (hcd ((eq.rec {mp := λ (h : add zero (mul m n) = zero), h, mpr := λ (h : add zero (mul m n) = zero), h} (eq.rec (eq.refl (add zero (mul m n) = zero)) (eq.rec (eq.refl (eq (add zero (mul m n)))) (eq.rec (eq.refl (add zero (mul m n))) (mynat.rec (eq.rec true.intro (eq.rec (eq.refl (zero = zero)) (eq.rec (eq.refl (zero = zero)) (propext {mp := λ (hl : zero = zero), true.intro, mpr := λ (hr : true), eq.refl zero})))) (λ (n_n : mynat) (n_ih : add zero n_n = n_n), eq.rec n_ih (eq.rec (eq.refl (succ (add zero n_n) = succ n_n)) (eq.rec (eq.refl (succ (add zero n_n) = succ n_n)) (propext {mp := λ (h : succ (add zero n_n) = succ n_n), eq.rec (λ (h11 : succ (add zero n_n) = succ (add zero n_n)) (a : add zero n_n = add zero n_n → add zero n_n = n_n), a (eq.refl (add zero n_n))) h h (λ (n_eq : add zero n_n = n_n), n_eq), mpr := λ (a : add zero n_n = n_n), eq.rec (eq.refl (succ (add zero n_n))) a})))) (mul m n)))))).mp ha))}) (propext {mp := λ (h : mul m n = zero → true), true.intro, mpr := λ (ha : true) (h : mul m n = zero), true.intro})))) (λ (n_1 : mynat) (ih : add n_1 (mul m n) = zero → n_1 = zero), eq.rec (λ (hsmnz : succ (add (mul m n) n_1) = zero), false.rec (succ n_1 = zero) (eq.rec (λ («_» : succ (add (mul m n) n_1) = succ (add (mul m n) n_1)) (a : zero = succ (add (mul m n) n_1)), eq.rec (λ (h11 : zero = zero) (a : hsmnz == eq.refl (succ (add (mul m n) n_1)) → false), a) a a) hsmnz hsmnz (eq.refl zero) (heq.refl hsmnz))) (eq.rec (eq.refl (add (succ n_1) (mul m n) = zero → succ n_1 = zero)) (propext {mp := λ (hab : add (succ n_1) (mul m n) = zero → succ n_1 = zero) (hc : succ (add (mul m n) n_1) = zero), hab ((eq.rec {mp := λ (h : add (succ n_1) (mul m n) = zero), h, mpr := λ (h : add (succ n_1) (mul m n) = zero), h} (eq.rec (eq.refl (add (succ n_1) (mul m n) = zero)) (eq.rec (eq.refl (eq (add (succ n_1) (mul m n)))) (mynat.rec (eq.rec true.intro (eq.rec (eq.refl (succ n_1 = succ (add zero n_1))) (eq.rec (eq.rec (eq.refl (succ n_1 = succ (add zero n_1))) (eq.rec (eq.refl (succ (add zero n_1))) (eq.rec (mynat.rec (eq.refl zero) (λ (m_n : mynat) (m_ih : add zero m_n = m_n), eq.rec m_ih (eq.rec (eq.refl (succ (add zero m_n) = succ m_n)) (eq.rec (eq.refl (succ (add zero m_n) = succ m_n)) (propext {mp := λ (h : succ (add zero m_n) = succ m_n), eq.rec (λ (h11 : … = …) (a : … → …), a …) h h (λ (n_eq : add zero m_n = m_n), n_eq), mpr := λ (a : add zero m_n = m_n), eq.rec (eq.refl (succ (add zero m_n))) a})))) n_1) (eq.rec (eq.refl (succ (add zero n_1) = succ n_1)) (eq.rec (eq.refl (succ (add zero n_1) = succ n_1)) (propext {mp := λ (h : succ (add zero n_1) = succ n_1), eq.rec (λ (h11 : succ (add zero n_1) = succ (add zero n_1)) (a : add zero n_1 = add zero n_1 → add zero n_1 = n_1), a (eq.refl (add zero n_1))) h h (λ (n_eq : add zero n_1 = n_1), n_eq), mpr := λ (a : add zero n_1 = n_1), eq.rec (eq.refl (succ (add zero n_1))) a})))))) (propext {mp := λ (hl : succ n_1 = succ n_1), true.intro, mpr := λ (hr : true), eq.refl (succ n_1)})))) (λ (n_n : mynat) (n_ih : add (succ n_1) n_n = succ (add n_n n_1)), eq.rec n_ih (eq.rec (eq.refl (succ (add (succ n_1) n_n) = succ (add (succ n_n) n_1))) (eq.rec (eq.rec (eq.refl (succ (add (succ n_1) n_n) = succ (add (succ n_n) n_1))) (eq.rec (mynat.rec (eq.refl (succ n_n)) (λ (n_n_1 : mynat) (n_ih : add (succ n_n) n_n_1 = succ (add n_n n_n_1)), eq.rec n_ih (eq.rec (eq.refl (succ (add (succ n_n) n_n_1) = succ (succ (add n_n n_n_1)))) (eq.rec (eq.refl (succ (add (succ n_n) n_n_1) = succ (succ (add n_n n_n_1)))) (propext {mp := λ (h : succ (add (succ n_n) n_n_1) = succ (succ (add n_n n_n_1))), eq.rec (λ (h11 : succ … = succ …) (a : … = … → … = …), a (eq.refl …)) h h (λ (n_eq : add (succ n_n) n_n_1 = succ (add n_n n_n_1)), n_eq), mpr := λ (a : add (succ n_n) n_n_1 = succ (add n_n n_n_1)), eq.rec (eq.refl (succ (add (succ n_n) n_n_1))) a})))) n_1) (eq.rec (eq.refl (succ (add (succ n_n) n_1) = succ (succ (add n_n n_1)))) (eq.rec (eq.refl (succ (add (succ n_n) n_1) = succ (succ (add n_n n_1)))) (propext {mp := λ (h : succ (add (succ n_n) n_1) = succ (succ (add n_n n_1))), eq.rec (λ (h11 : succ (add (succ n_n) n_1) = succ (add (succ n_n) n_1)) (a : add (succ n_n) n_1 = add (succ n_n) n_1 → add (succ n_n) n_1 = succ (add n_n n_1)), a (eq.refl (add (succ n_n) n_1))) h h (λ (n_eq : add (succ n_n) n_1 = succ (add n_n n_1)), n_eq), mpr := λ (a : add (succ n_n) n_1 = succ (add n_n n_1)), eq.rec (eq.refl (succ (add (succ n_n) n_1))) a}))))) (propext {mp := λ (h : succ (add (succ n_1) n_n) = succ (succ (add n_n n_1))), eq.rec (λ (h11 : succ (add (succ n_1) n_n) = succ (add (succ n_1) n_n)) (a : add (succ n_1) n_n = add (succ n_1) n_n → add (succ n_1) n_n = succ (add n_n n_1)), a (eq.refl (add (succ n_1) n_n))) h h (λ (n_eq : add (succ n_1) n_n = succ (add n_n n_1)), n_eq), mpr := λ (a : add (succ n_1) n_n = succ (add n_n n_1)), eq.rec (eq.refl (succ (add (succ n_1) n_n))) a})))) (mul m n))))).mpr hc), mpr := λ (hcd : succ (add (mul m n) n_1) = zero → succ n_1 = zero) (ha : add (succ n_1) (mul m n) = zero), hcd ((eq.rec {mp := λ (h : add (succ n_1) (mul m n) = zero), h, mpr := λ (h : add (succ n_1) (mul m n) = zero), h} (eq.rec (eq.refl (add (succ n_1) (mul m n) = zero)) (eq.rec (eq.refl (eq (add (succ n_1) (mul m n)))) (mynat.rec (eq.rec true.intro (eq.rec (eq.refl (succ n_1 = succ (add zero n_1))) (eq.rec (eq.rec (eq.refl (succ n_1 = succ (add zero n_1))) (eq.rec (eq.refl (succ (add zero n_1))) (eq.rec (mynat.rec (eq.refl zero) (λ (m_n : mynat) (m_ih : add zero m_n = m_n), eq.rec m_ih (eq.rec (eq.refl (succ (add zero m_n) = succ m_n)) (eq.rec (eq.refl (succ (add zero m_n) = succ m_n)) (propext {mp := λ (h : succ (add zero m_n) = succ m_n), eq.rec (λ (h11 : … = …) (a : … → …), a …) h h (λ (n_eq : add zero m_n = m_n), n_eq), mpr := λ (a : add zero m_n = m_n), eq.rec (eq.refl (succ (add zero m_n))) a})))) n_1) (eq.rec (eq.refl (succ (add zero n_1) = succ n_1)) (eq.rec (eq.refl (succ (add zero n_1) = succ n_1)) (propext {mp := λ (h : succ (add zero n_1) = succ n_1), eq.rec (λ (h11 : succ (add zero n_1) = succ (add zero n_1)) (a : add zero n_1 = add zero n_1 → add zero n_1 = n_1), a (eq.refl (add zero n_1))) h h (λ (n_eq : add zero n_1 = n_1), n_eq), mpr := λ (a : add zero n_1 = n_1), eq.rec (eq.refl (succ (add zero n_1))) a})))))) (propext {mp := λ (hl : succ n_1 = succ n_1), true.intro, mpr := λ (hr : true), eq.refl (succ n_1)})))) (λ (n_n : mynat) (n_ih : add (succ n_1) n_n = succ (add n_n n_1)), eq.rec n_ih (eq.rec (eq.refl (succ (add (succ n_1) n_n) = succ (add (succ n_n) n_1))) (eq.rec (eq.rec (eq.refl (succ (add (succ n_1) n_n) = succ (add (succ n_n) n_1))) (eq.rec (mynat.rec (eq.refl (succ n_n)) (λ (n_n_1 : mynat) (n_ih : add (succ n_n) n_n_1 = succ (add n_n n_n_1)), eq.rec n_ih (eq.rec (eq.refl (succ (add (succ n_n) n_n_1) = succ (succ (add n_n n_n_1)))) (eq.rec (eq.refl (succ (add (succ n_n) n_n_1) = succ (succ (add n_n n_n_1)))) (propext {mp := λ (h : succ (add (succ n_n) n_n_1) = succ (succ (add n_n n_n_1))), eq.rec (λ (h11 : succ … = succ …) (a : … = … → … = …), a (eq.refl …)) h h (λ (n_eq : add (succ n_n) n_n_1 = succ (add n_n n_n_1)), n_eq), mpr := λ (a : add (succ n_n) n_n_1 = succ (add n_n n_n_1)), eq.rec (eq.refl (succ (add (succ n_n) n_n_1))) a})))) n_1) (eq.rec (eq.refl (succ (add (succ n_n) n_1) = succ (succ (add n_n n_1)))) (eq.rec (eq.refl (succ (add (succ n_n) n_1) = succ (succ (add n_n n_1)))) (propext {mp := λ (h : succ (add (succ n_n) n_1) = succ (succ (add n_n n_1))), eq.rec (λ (h11 : succ (add (succ n_n) n_1) = succ (add (succ n_n) n_1)) (a : add (succ n_n) n_1 = add (succ n_n) n_1 → add (succ n_n) n_1 = succ (add n_n n_1)), a (eq.refl (add (succ n_n) n_1))) h h (λ (n_eq : add (succ n_n) n_1 = succ (add n_n n_1)), n_eq), mpr := λ (a : add (succ n_n) n_1 = succ (add n_n n_1)), eq.rec (eq.refl (succ (add (succ n_n) n_1))) a}))))) (propext {mp := λ (h : succ (add (succ n_1) n_n) = succ (succ (add n_n n_1))), eq.rec (λ (h11 : succ (add (succ n_1) n_n) = succ (add (succ n_1) n_n)) (a : add (succ n_1) n_n = add (succ n_1) n_n → add (succ n_1) n_n = succ (add n_n n_1)), a (eq.refl (add (succ n_1) n_n))) h h (λ (n_eq : add (succ n_1) n_n = succ (add n_n n_1)), n_eq), mpr := λ (a : add (succ n_1) n_n = succ (add n_n n_1)), eq.rec (eq.refl (succ (add (succ n_1) n_n))) a})))) (mul m n))))).mp ha)}))) m hmn0))) w (eq.rec (eq.refl zero) (mynat.rec (eq.rec (λ (a : zero = mul m w), eq.rec true.intro (eq.rec (eq.refl (zero = mul m w)) (propext {mp := λ (hl : zero = mul m w), true.intro, mpr := λ (hr : true), a}))) (eq.rec (eq.refl (zero = add zero (mul m w) → zero = mul m w)) (propext {mp := λ (hab : zero = add zero (mul m w) → zero = mul m w) (hc : zero = mul m w), hab ((eq.rec {mp := λ (h : zero = add zero (mul m w)), h, mpr := λ (h : zero = add zero (mul m w)), h} (eq.rec (eq.refl (zero = add zero (mul m w))) (eq.rec (eq.refl (add zero (mul m w))) (mynat.rec (eq.rec true.intro (eq.rec (eq.refl (zero = zero)) (eq.rec (eq.refl (zero = zero)) (propext {mp := λ (hl : zero = zero), true.intro, mpr := λ (hr : true), eq.refl zero})))) (λ (n_n : mynat) (n_ih : add zero n_n = n_n), eq.rec n_ih (eq.rec (eq.refl (succ (add zero n_n) = succ n_n)) (eq.rec (eq.refl (succ (add zero n_n) = succ n_n)) (propext {mp := λ (h : succ (add zero n_n) = succ n_n), eq.rec (λ (h11 : succ (add zero n_n) = succ (add zero n_n)) (a : add zero n_n = add zero n_n → add zero n_n = n_n), a (eq.refl (add zero n_n))) h h (λ (n_eq : add zero n_n = n_n), n_eq), mpr := λ (a : add zero n_n = n_n), eq.rec (eq.refl (succ (add zero n_n))) a})))) (mul m w))))).mpr hc), mpr := λ (hcd : zero = mul m w → zero = mul m w) (ha : zero = add zero (mul m w)), hcd ((eq.rec {mp := λ (h : zero = add zero (mul m w)), h, mpr := λ (h : zero = add zero (mul m w)), h} (eq.rec (eq.refl (zero = add zero (mul m w))) (eq.rec (eq.refl (add zero (mul m w))) (mynat.rec (eq.rec true.intro (eq.rec (eq.refl (zero = zero)) (eq.rec (eq.refl (zero = zero)) (propext {mp := λ (hl : zero = zero), true.intro, mpr := λ (hr : true), eq.refl zero})))) (λ (n_n : mynat) (n_ih : add zero n_n = n_n), eq.rec n_ih (eq.rec (eq.refl (succ (add zero n_n) = succ n_n)) (eq.rec (eq.refl (succ (add zero n_n) = succ n_n)) (propext {mp := λ (h : succ (add zero n_n) = succ n_n), eq.rec (λ (h11 : succ (add zero n_n) = succ (add zero n_n)) (a : add zero n_n = add zero n_n → add zero n_n = n_n), a (eq.refl (add zero n_n))) h h (λ (n_eq : add zero n_n = n_n), n_eq), mpr := λ (a : add zero n_n = n_n), eq.rec (eq.refl (succ (add zero n_n))) a})))) (mul m w))))).mp ha)}))) (λ (m_n : mynat) (m_ih : m_n = add m_n (mul m w) → zero = mul m w), eq.rec (eq.rec (eq.rec m_ih (eq.rec (eq.refl (m_n = add (mul m w) m_n → zero = mul m w)) (eq.rec (eq.refl (m_n = add (mul m w) m_n → zero = mul m w)) (mynat.rec (eq.rec true.intro (eq.rec (eq.refl (mul m w = add zero (mul m w))) (eq.rec (eq.rec (eq.refl (mul m w = add zero (mul m w))) (eq.rec (eq.refl (add zero (mul m w))) (mynat.rec (eq.refl zero) (λ (m_n : mynat) (m_ih : add zero m_n = m_n), eq.rec m_ih (eq.rec (eq.refl (succ (add zero m_n) = succ m_n)) (eq.rec (eq.refl (succ (add zero m_n) = succ m_n)) (propext {mp := λ (h : succ (add zero m_n) = succ m_n), eq.rec (λ (h11 : succ (add zero m_n) = succ (add zero m_n)) (a : add zero m_n = add zero m_n → add zero m_n = m_n), a (eq.refl (add zero m_n))) h h (λ (n_eq : add zero m_n = m_n), n_eq), mpr := λ (a : add zero m_n = m_n), eq.rec (eq.refl (succ (add zero m_n))) a})))) (mul m w)))) (propext {mp := λ (hl : mul m w = mul m w), true.intro, mpr := λ (hr : true), eq.refl (mul m w)})))) (λ (n_n : mynat) (n_ih : add (mul m w) n_n = add n_n (mul m w)), eq.rec n_ih (eq.rec (eq.refl (succ (add (mul m w) n_n) = add (succ n_n) (mul m w))) (eq.rec (eq.rec (eq.refl (succ (add (mul m w) n_n) = add (succ n_n) (mul m w))) (mynat.rec (eq.refl (succ n_n)) (λ (n_n_1 : mynat) (n_ih : add (succ n_n) n_n_1 = succ (add n_n n_n_1)), eq.rec n_ih (eq.rec (eq.refl (succ (add (succ n_n) n_n_1) = succ (succ (add n_n n_n_1)))) (eq.rec (eq.refl (succ (add (succ n_n) n_n_1) = succ (succ (add n_n n_n_1)))) (propext {mp := λ (h : succ (add (succ n_n) n_n_1) = succ (succ (add n_n n_n_1))), eq.rec (λ (h11 : succ (add (succ n_n) n_n_1) = succ (add (succ n_n) n_n_1)) (a : add (succ n_n) n_n_1 = add (succ n_n) n_n_1 → add (succ n_n) n_n_1 = succ (add n_n n_n_1)), a (eq.refl (add (succ n_n) n_n_1))) h h (λ (n_eq : add (succ n_n) n_n_1 = succ (add n_n n_n_1)), n_eq), mpr := λ (a : add (succ n_n) n_n_1 = succ (add n_n n_n_1)), eq.rec (eq.refl (succ (add (succ n_n) n_n_1))) a})))) (mul m w))) (propext {mp := λ (h : succ (add (mul m w) n_n) = succ (add n_n (mul m w))), eq.rec (λ (h11 : succ (add (mul m w) n_n) = succ (add (mul m w) n_n)) (a : add (mul m w) n_n = add (mul m w) n_n → add (mul m w) n_n = add n_n (mul m w)), a (eq.refl (add (mul m w) n_n))) h h (λ (n_eq : add (mul m w) n_n = add n_n (mul m w)), n_eq), mpr := λ (a : add (mul m w) n_n = add n_n (mul m w)), eq.rec (eq.refl (succ (add (mul m w) n_n))) a})))) m_n)))) (eq.rec (eq.refl (add zero m_n = add (mul m w) m_n → zero = mul m w)) (eq.rec (eq.refl (add zero m_n = add (mul m w) m_n → zero = mul m w)) (mynat.rec (eq.rec true.intro (eq.rec (eq.refl (zero = zero)) (eq.rec (eq.refl (zero = zero)) (propext {mp := λ (hl : zero = zero), true.intro, mpr := λ (hr : true), eq.refl zero})))) (λ (n_n : mynat) (n_ih : add zero n_n = n_n), eq.rec n_ih (eq.rec (eq.refl (succ (add zero n_n) = succ n_n)) (eq.rec (eq.refl (succ (add zero n_n) = succ n_n)) (propext {mp := λ (h : succ (add zero n_n) = succ n_n), eq.rec (λ (h11 : succ (add zero n_n) = succ (add zero n_n)) (a : add zero n_n = add zero n_n → add zero n_n = n_n), a (eq.refl (add zero n_n))) h h (λ (n_eq : add zero n_n = n_n), n_eq), mpr := λ (a : add zero n_n = n_n), eq.rec (eq.refl (succ (add zero n_n))) a})))) m_n)))) (eq.rec (eq.refl (succ m_n = add (succ m_n) (mul m w) → zero = mul m w)) (propext {mp := λ (hab : succ m_n = add (succ m_n) (mul m w) → zero = mul m w) (hc : add zero m_n = add (mul m w) m_n), hab ((eq.rec {mp := λ (h : succ m_n = add (succ m_n) (mul m w)), h, mpr := λ (h : succ m_n = add (succ m_n) (mul m w)), h} (eq.rec (eq.rec (eq.rec (eq.refl (succ m_n = add (succ m_n) (mul m w))) (mynat.rec (eq.rec true.intro (eq.rec (eq.refl (succ m_n = succ (add zero m_n))) (eq.rec (eq.rec (eq.refl (succ m_n = succ (add zero m_n))) (eq.rec (eq.refl (succ (add zero m_n))) (eq.rec (mynat.rec (eq.refl zero) (λ (m_n : mynat) (m_ih : add zero m_n = m_n), eq.rec m_ih (eq.rec (eq.refl (succ (add zero m_n) = succ m_n)) (eq.rec (eq.refl (succ (add zero m_n) = succ m_n)) (propext {mp := λ (h : succ (add zero m_n) = succ m_n), eq.rec (λ (h11 : succ … = succ …) (a : … = … → … = m_n), a (eq.refl …)) h h (λ (n_eq : add zero m_n = m_n), n_eq), mpr := …})))) m_n) …))) …))) … …)) …) …)).mpr hc), mpr := …}))) … …)))))) …))) h h) … … …
|
85820e6b723f94b0665b77ff0fc790d07ca6ca49 | 097294e9b80f0d9893ac160b9c7219aa135b51b9 | /instructor/identifiers/defz.lean | 3824c7c181db2f08a55a06f652b6f19396cf83ec | [] | no_license | AbigailCastro17/CS2102-Discrete-Math | cf296251be9418ce90206f5e66bde9163e21abf9 | d741e4d2d6a9b2e0c8380e51706218b8f608cee4 | refs/heads/main | 1,682,891,087,358 | 1,621,401,341,000 | 1,621,401,341,000 | 368,749,959 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 25 | lean | def z := nat.zero
#eval z |
d09d48c35fbe868c7a92a834a30a82769056a2ac | d406927ab5617694ec9ea7001f101b7c9e3d9702 | /src/data/int/cast/basic.lean | 913d5db16ef2f9d3b323cfad2d271768f48bbee5 | [
"Apache-2.0"
] | permissive | alreadydone/mathlib | dc0be621c6c8208c581f5170a8216c5ba6721927 | c982179ec21091d3e102d8a5d9f5fe06c8fafb73 | refs/heads/master | 1,685,523,275,196 | 1,670,184,141,000 | 1,670,184,141,000 | 287,574,545 | 0 | 0 | Apache-2.0 | 1,670,290,714,000 | 1,597,421,623,000 | Lean | UTF-8 | Lean | false | false | 3,844 | lean | /-
Copyright (c) 2017 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Gabriel Ebner
-/
import data.int.cast.defs
import algebra.group.basic
/-!
# Cast of integers (additional theorems)
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> https://github.com/leanprover-community/mathlib4/pull/670
> Any changes to this file require a corresponding PR to mathlib4.
This file proves additional properties about the *canonical* homomorphism from
the integers into an additive group with a one (`int.cast`).
There is also `data.int.cast.lemmas`,
which includes lemmas stated in terms of algebraic homomorphisms,
and results involving the order structure of `ℤ`.
By contrast, this file's only import beyond `data.int.cast.defs` is `algebra.group.basic`.
-/
universes u
namespace nat
variables {R : Type u} [add_group_with_one R]
@[simp, norm_cast] theorem cast_sub {m n} (h : m ≤ n) : ((n - m : ℕ) : R) = n - m :=
eq_sub_of_add_eq $ by rw [← cast_add, nat.sub_add_cancel h]
@[simp, norm_cast] theorem cast_pred : ∀ {n}, 0 < n → ((n - 1 : ℕ) : R) = n - 1
| 0 h := by cases h
| (n+1) h := by rw [cast_succ, add_sub_cancel]; refl
end nat
open nat
namespace int
variables {R : Type u} [add_group_with_one R]
@[simp] theorem cast_neg_succ_of_nat (n : ℕ) : (-[1+ n] : R) = -(n + 1 : ℕ) :=
add_group_with_one.int_cast_neg_succ_of_nat n
@[simp, norm_cast] theorem cast_zero : ((0 : ℤ) : R) = 0 := (cast_of_nat 0).trans nat.cast_zero
@[simp, norm_cast] theorem cast_coe_nat (n : ℕ) : ((n : ℤ) : R) = n := cast_of_nat _
@[simp, norm_cast] theorem cast_one : ((1 : ℤ) : R) = 1 :=
show (((1 : ℕ) : ℤ) : R) = 1, by simp
@[simp, norm_cast] theorem cast_neg : ∀ n, ((-n : ℤ) : R) = -n
| (0 : ℕ) := by erw [cast_zero, neg_zero]
| (n + 1 : ℕ) := by erw [cast_of_nat, cast_neg_succ_of_nat]; refl
| -[1+ n] := by erw [cast_of_nat, cast_neg_succ_of_nat, neg_neg]
@[simp] theorem cast_sub_nat_nat (m n) :
((int.sub_nat_nat m n : ℤ) : R) = m - n :=
begin
unfold sub_nat_nat, cases e : n - m,
{ simp only [sub_nat_nat, cast_of_nat], simp [e, nat.le_of_sub_eq_zero e] },
{ rw [sub_nat_nat, cast_neg_succ_of_nat, nat.add_one, ← e,
nat.cast_sub $ _root_.le_of_lt $ nat.lt_of_sub_eq_succ e, neg_sub] },
end
lemma neg_of_nat_eq (n : ℕ) : neg_of_nat n = -(n : ℤ) := by cases n; refl
@[simp] theorem cast_neg_of_nat (n : ℕ) : ((neg_of_nat n : ℤ) : R) = -n :=
by simp [neg_of_nat_eq]
@[simp, norm_cast] theorem cast_add : ∀ m n, ((m + n : ℤ) : R) = m + n
| (m : ℕ) (n : ℕ) := by simp [← int.coe_nat_add]
| (m : ℕ) -[1+ n] := by erw [cast_sub_nat_nat, cast_coe_nat, cast_neg_succ_of_nat, sub_eq_add_neg]
| -[1+ m] (n : ℕ) := by erw [cast_sub_nat_nat, cast_coe_nat, cast_neg_succ_of_nat,
sub_eq_iff_eq_add, add_assoc, eq_neg_add_iff_add_eq, ← nat.cast_add, ← nat.cast_add, nat.add_comm]
| -[1+ m] -[1+ n] := show (-[1+ m + n + 1] : R) = _,
by rw [cast_neg_succ_of_nat, cast_neg_succ_of_nat, cast_neg_succ_of_nat, ← neg_add_rev,
← nat.cast_add, nat.add_right_comm m n 1, nat.add_assoc, nat.add_comm]
@[simp, norm_cast] theorem cast_sub (m n) : ((m - n : ℤ) : R) = m - n :=
by simp [int.sub_eq_add_neg, sub_eq_add_neg]
@[simp, norm_cast]
theorem coe_nat_bit0 (n : ℕ) : (↑(bit0 n) : ℤ) = bit0 ↑n := rfl
@[simp, norm_cast]
theorem coe_nat_bit1 (n : ℕ) : (↑(bit1 n) : ℤ) = bit1 ↑n := rfl
@[simp, norm_cast] theorem cast_bit0 (n : ℤ) : ((bit0 n : ℤ) : R) = bit0 n :=
cast_add _ _
@[simp, norm_cast] theorem cast_bit1 (n : ℤ) : ((bit1 n : ℤ) : R) = bit1 n :=
by rw [bit1, cast_add, cast_one, cast_bit0]; refl
lemma cast_two : ((2 : ℤ) : R) = 2 := by simp
lemma cast_three : ((3 : ℤ) : R) = 3 := by simp
lemma cast_four : ((4 : ℤ) : R) = 4 := by simp
end int
|
105b80f25124c98e3365a1be8c63f0f7967fb22d | 302c785c90d40ad3d6be43d33bc6a558354cc2cf | /src/data/rat/basic.lean | 9772b8211475d6992fbcb79313c3e94231c2e7b5 | [
"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 | 29,457 | lean | /-
Copyright (c) 2019 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro
-/
import data.equiv.encodable.basic
import algebra.euclidean_domain
import data.nat.gcd
import data.int.cast
/-!
# Basics for the Rational Numbers
## Summary
We define a rational number `q` as a structure `{ num, denom, pos, cop }`, where
- `num` is the numerator of `q`,
- `denom` is the denominator of `q`,
- `pos` is a proof that `denom > 0`, and
- `cop` is a proof `num` and `denom` are coprime.
We then define the expected (discrete) field structure on `ℚ` and prove basic lemmas about it.
Moreoever, we provide the expected casts from `ℕ` and `ℤ` into `ℚ`, i.e. `(↑n : ℚ) = n / 1`.
## Main Definitions
- `rat` is the structure encoding `ℚ`.
- `rat.mk n d` constructs a rational number `q = n / d` from `n d : ℤ`.
## Notations
- `/.` is infix notation for `rat.mk`.
## Tags
rat, rationals, field, ℚ, numerator, denominator, num, denom
-/
/-- `rat`, or `ℚ`, is the type of rational numbers. It is defined
as the set of pairs ⟨n, d⟩ of integers such that `d` is positive and `n` and
`d` are coprime. This representation is preferred to the quotient
because without periodic reduction, the numerator and denominator can grow
exponentially (for example, adding 1/2 to itself repeatedly). -/
structure rat := mk' ::
(num : ℤ)
(denom : ℕ)
(pos : 0 < denom)
(cop : num.nat_abs.coprime denom)
notation `ℚ` := rat
namespace rat
/-- String representation of a rational numbers, used in `has_repr`, `has_to_string`, and
`has_to_format` instances. -/
protected def repr : ℚ → string
| ⟨n, d, _, _⟩ := if d = 1 then _root_.repr n else
_root_.repr n ++ "/" ++ _root_.repr d
instance : has_repr ℚ := ⟨rat.repr⟩
instance : has_to_string ℚ := ⟨rat.repr⟩
meta instance : has_to_format ℚ := ⟨coe ∘ rat.repr⟩
instance : encodable ℚ := encodable.of_equiv (Σ n : ℤ, {d : ℕ // 0 < d ∧ n.nat_abs.coprime d})
⟨λ ⟨a, b, c, d⟩, ⟨a, b, c, d⟩, λ⟨a, b, c, d⟩, ⟨a, b, c, d⟩,
λ ⟨a, b, c, d⟩, rfl, λ⟨a, b, c, d⟩, rfl⟩
/-- Embed an integer as a rational number -/
def of_int (n : ℤ) : ℚ :=
⟨n, 1, nat.one_pos, nat.coprime_one_right _⟩
instance : has_zero ℚ := ⟨of_int 0⟩
instance : has_one ℚ := ⟨of_int 1⟩
instance : inhabited ℚ := ⟨0⟩
/-- Form the quotient `n / d` where `n:ℤ` and `d:ℕ+` (not necessarily coprime) -/
def mk_pnat (n : ℤ) : ℕ+ → ℚ | ⟨d, dpos⟩ :=
let n' := n.nat_abs, g := n'.gcd d in
⟨n / g, d / g, begin
apply (nat.le_div_iff_mul_le _ _ (nat.gcd_pos_of_pos_right _ dpos)).2,
simp, exact nat.le_of_dvd dpos (nat.gcd_dvd_right _ _)
end, begin
have : int.nat_abs (n / ↑g) = n' / g,
{ cases int.nat_abs_eq n with e e; rw e, { refl },
rw [int.neg_div_of_dvd, int.nat_abs_neg], { refl },
exact int.coe_nat_dvd.2 (nat.gcd_dvd_left _ _) },
rw this,
exact nat.coprime_div_gcd_div_gcd (nat.gcd_pos_of_pos_right _ dpos)
end⟩
/-- Form the quotient `n / d` where `n:ℤ` and `d:ℕ`. In the case `d = 0`, we
define `n / 0 = 0` by convention. -/
def mk_nat (n : ℤ) (d : ℕ) : ℚ :=
if d0 : d = 0 then 0 else mk_pnat n ⟨d, nat.pos_of_ne_zero d0⟩
/-- Form the quotient `n / d` where `n d : ℤ`. -/
def mk : ℤ → ℤ → ℚ
| n (d : ℕ) := mk_nat n d
| n -[1+ d] := mk_pnat (-n) d.succ_pnat
localized "infix ` /. `:70 := rat.mk" in rat
theorem mk_pnat_eq (n d h) : mk_pnat n ⟨d, h⟩ = n /. d :=
by change n /. d with dite _ _ _; simp [ne_of_gt h]
theorem mk_nat_eq (n d) : mk_nat n d = n /. d := rfl
@[simp] theorem mk_zero (n) : n /. 0 = 0 := rfl
@[simp] theorem zero_mk_pnat (n) : mk_pnat 0 n = 0 :=
by cases n; simp [mk_pnat]; change int.nat_abs 0 with 0; simp *; refl
@[simp] theorem zero_mk_nat (n) : mk_nat 0 n = 0 :=
by by_cases n = 0; simp [*, mk_nat]
@[simp] theorem zero_mk (n) : 0 /. n = 0 :=
by cases n; simp [mk]
private lemma gcd_abs_dvd_left {a b} : (nat.gcd (int.nat_abs a) b : ℤ) ∣ a :=
int.dvd_nat_abs.1 $ int.coe_nat_dvd.2 $ nat.gcd_dvd_left (int.nat_abs a) b
@[simp] theorem mk_eq_zero {a b : ℤ} (b0 : b ≠ 0) : a /. b = 0 ↔ a = 0 :=
begin
constructor; intro h; [skip, {subst a, simp}],
have : ∀ {a b}, mk_pnat a b = 0 → a = 0,
{ intros a b e, cases b with b h,
injection e with e,
apply int.eq_mul_of_div_eq_right gcd_abs_dvd_left e },
cases b with b; simp [mk, mk_nat] at h,
{ simp [mt (congr_arg int.of_nat) b0] at h,
exact this h },
{ apply neg_injective, simp [this h] }
end
theorem mk_eq : ∀ {a b c d : ℤ} (hb : b ≠ 0) (hd : d ≠ 0),
a /. b = c /. d ↔ a * d = c * b :=
suffices ∀ a b c d hb hd, mk_pnat a ⟨b, hb⟩ = mk_pnat c ⟨d, hd⟩ ↔ a * d = c * b,
begin
intros, cases b with b b; simp [mk, mk_nat, nat.succ_pnat],
simp [mt (congr_arg int.of_nat) hb],
all_goals {
cases d with d d; simp [mk, mk_nat, nat.succ_pnat],
simp [mt (congr_arg int.of_nat) hd],
all_goals { rw this, try {refl} } },
{ change a * ↑(d.succ) = -c * ↑b ↔ a * -(d.succ) = c * b,
constructor; intro h; apply neg_injective; simpa [left_distrib, neg_add_eq_iff_eq_add,
eq_neg_iff_add_eq_zero, neg_eq_iff_add_eq_zero] using h },
{ change -a * ↑d = c * b.succ ↔ a * d = c * -b.succ,
constructor; intro h; apply neg_injective; simpa [left_distrib, eq_comm] using h },
{ change -a * d.succ = -c * b.succ ↔ a * -d.succ = c * -b.succ,
simp [left_distrib, sub_eq_add_neg], cc }
end,
begin
intros, simp [mk_pnat], constructor; intro h,
{ cases h with ha hb,
have ha, {
have dv := @gcd_abs_dvd_left,
have := int.eq_mul_of_div_eq_right dv ha,
rw ← int.mul_div_assoc _ dv at this,
exact int.eq_mul_of_div_eq_left (dvd_mul_of_dvd_right dv _) this.symm },
have hb, {
have dv := λ {a b}, nat.gcd_dvd_right (int.nat_abs a) b,
have := nat.eq_mul_of_div_eq_right dv hb,
rw ← nat.mul_div_assoc _ dv at this,
exact nat.eq_mul_of_div_eq_left (dvd_mul_of_dvd_right dv _) this.symm },
have m0 : (a.nat_abs.gcd b * c.nat_abs.gcd d : ℤ) ≠ 0, {
refine int.coe_nat_ne_zero.2 (ne_of_gt _),
apply mul_pos; apply nat.gcd_pos_of_pos_right; assumption },
apply mul_right_cancel' m0,
simpa [mul_comm, mul_left_comm] using
congr (congr_arg (*) ha.symm) (congr_arg coe hb) },
{ suffices : ∀ a c, a * d = c * b →
a / a.gcd b = c / c.gcd d ∧ b / a.gcd b = d / c.gcd d,
{ cases this a.nat_abs c.nat_abs
(by simpa [int.nat_abs_mul] using congr_arg int.nat_abs h) with h₁ h₂,
have hs := congr_arg int.sign h,
simp [int.sign_eq_one_of_pos (int.coe_nat_lt.2 hb),
int.sign_eq_one_of_pos (int.coe_nat_lt.2 hd)] at hs,
conv in a { rw ← int.sign_mul_nat_abs a },
conv in c { rw ← int.sign_mul_nat_abs c },
rw [int.mul_div_assoc, int.mul_div_assoc],
exact ⟨congr (congr_arg (*) hs) (congr_arg coe h₁), h₂⟩,
all_goals { exact int.coe_nat_dvd.2 (nat.gcd_dvd_left _ _) } },
intros a c h,
suffices bd : b / a.gcd b = d / c.gcd d,
{ refine ⟨_, bd⟩,
apply nat.eq_of_mul_eq_mul_left hb,
rw [← nat.mul_div_assoc _ (nat.gcd_dvd_left _ _), mul_comm,
nat.mul_div_assoc _ (nat.gcd_dvd_right _ _), bd,
← nat.mul_div_assoc _ (nat.gcd_dvd_right _ _), h, mul_comm,
nat.mul_div_assoc _ (nat.gcd_dvd_left _ _)] },
suffices : ∀ {a c : ℕ} (b>0) (d>0),
a * d = c * b → b / a.gcd b ≤ d / c.gcd d,
{ exact le_antisymm (this _ hb _ hd h) (this _ hd _ hb h.symm) },
intros a c b hb d hd h,
have gb0 := nat.gcd_pos_of_pos_right a hb,
have gd0 := nat.gcd_pos_of_pos_right c hd,
apply nat.le_of_dvd,
apply (nat.le_div_iff_mul_le _ _ gd0).2,
simp, apply nat.le_of_dvd hd (nat.gcd_dvd_right _ _),
apply (nat.coprime_div_gcd_div_gcd gb0).symm.dvd_of_dvd_mul_left,
refine ⟨c / c.gcd d, _⟩,
rw [← nat.mul_div_assoc _ (nat.gcd_dvd_left _ _),
← nat.mul_div_assoc _ (nat.gcd_dvd_right _ _)],
apply congr_arg (/ c.gcd d),
rw [mul_comm, ← nat.mul_div_assoc _ (nat.gcd_dvd_left _ _),
mul_comm, h, nat.mul_div_assoc _ (nat.gcd_dvd_right _ _), mul_comm] }
end
@[simp] theorem div_mk_div_cancel_left {a b c : ℤ} (c0 : c ≠ 0) :
(a * c) /. (b * c) = a /. b :=
begin
by_cases b0 : b = 0, { subst b0, simp },
apply (mk_eq (mul_ne_zero b0 c0) b0).2, simp [mul_comm, mul_assoc]
end
@[simp] theorem num_denom : ∀ {a : ℚ}, a.num /. a.denom = a
| ⟨n, d, h, (c:_=1)⟩ := show mk_nat n d = _,
by simp [mk_nat, ne_of_gt h, mk_pnat, c]
theorem num_denom' {n d h c} : (⟨n, d, h, c⟩ : ℚ) = n /. d := num_denom.symm
theorem of_int_eq_mk (z : ℤ) : of_int z = z /. 1 := num_denom'
/-- Define a (dependent) function or prove `∀ r : ℚ, p r` by dealing with rational
numbers of the form `n /. d` with `0 < d` and coprime `n`, `d`. -/
@[elab_as_eliminator] def {u} num_denom_cases_on {C : ℚ → Sort u}
: ∀ (a : ℚ) (H : ∀ n d, 0 < d → (int.nat_abs n).coprime d → C (n /. d)), C a
| ⟨n, d, h, c⟩ H := by rw num_denom'; exact H n d h c
/-- Define a (dependent) function or prove `∀ r : ℚ, p r` by dealing with rational
numbers of the form `n /. d` with `d ≠ 0`. -/
@[elab_as_eliminator] def {u} num_denom_cases_on' {C : ℚ → Sort u}
(a : ℚ) (H : ∀ (n:ℤ) (d:ℕ), d ≠ 0 → C (n /. d)) : C a :=
num_denom_cases_on a $ λ n d h c, H n d h.ne'
theorem num_dvd (a) {b : ℤ} (b0 : b ≠ 0) : (a /. b).num ∣ a :=
begin
cases e : a /. b with n d h c,
rw [rat.num_denom', rat.mk_eq b0
(ne_of_gt (int.coe_nat_pos.2 h))] at e,
refine (int.nat_abs_dvd.1 $ int.dvd_nat_abs.1 $ int.coe_nat_dvd.2 $
c.dvd_of_dvd_mul_right _),
have := congr_arg int.nat_abs e,
simp [int.nat_abs_mul, int.nat_abs_of_nat] at this, simp [this]
end
theorem denom_dvd (a b : ℤ) : ((a /. b).denom : ℤ) ∣ b :=
begin
by_cases b0 : b = 0, {simp [b0]},
cases e : a /. b with n d h c,
rw [num_denom', mk_eq b0 (ne_of_gt (int.coe_nat_pos.2 h))] at e,
refine (int.dvd_nat_abs.1 $ int.coe_nat_dvd.2 $ c.symm.dvd_of_dvd_mul_left _),
rw [← int.nat_abs_mul, ← int.coe_nat_dvd, int.dvd_nat_abs, ← e], simp
end
/-- Addition of rational numbers. Use `(+)` instead. -/
protected def add : ℚ → ℚ → ℚ
| ⟨n₁, d₁, h₁, c₁⟩ ⟨n₂, d₂, h₂, c₂⟩ := mk_pnat (n₁ * d₂ + n₂ * d₁) ⟨d₁ * d₂, mul_pos h₁ h₂⟩
instance : has_add ℚ := ⟨rat.add⟩
theorem lift_binop_eq (f : ℚ → ℚ → ℚ) (f₁ : ℤ → ℤ → ℤ → ℤ → ℤ) (f₂ : ℤ → ℤ → ℤ → ℤ → ℤ)
(fv : ∀ {n₁ d₁ h₁ c₁ n₂ d₂ h₂ c₂},
f ⟨n₁, d₁, h₁, c₁⟩ ⟨n₂, d₂, h₂, c₂⟩ = f₁ n₁ d₁ n₂ d₂ /. f₂ n₁ d₁ n₂ d₂)
(f0 : ∀ {n₁ d₁ n₂ d₂} (d₁0 : d₁ ≠ 0) (d₂0 : d₂ ≠ 0), f₂ n₁ d₁ n₂ d₂ ≠ 0)
(a b c d : ℤ) (b0 : b ≠ 0) (d0 : d ≠ 0)
(H : ∀ {n₁ d₁ n₂ d₂} (h₁ : a * d₁ = n₁ * b) (h₂ : c * d₂ = n₂ * d),
f₁ n₁ d₁ n₂ d₂ * f₂ a b c d = f₁ a b c d * f₂ n₁ d₁ n₂ d₂) :
f (a /. b) (c /. d) = f₁ a b c d /. f₂ a b c d :=
begin
generalize ha : a /. b = x, cases x with n₁ d₁ h₁ c₁, rw num_denom' at ha,
generalize hc : c /. d = x, cases x with n₂ d₂ h₂ c₂, rw num_denom' at hc,
rw fv,
have d₁0 := ne_of_gt (int.coe_nat_lt.2 h₁),
have d₂0 := ne_of_gt (int.coe_nat_lt.2 h₂),
exact (mk_eq (f0 d₁0 d₂0) (f0 b0 d0)).2 (H ((mk_eq b0 d₁0).1 ha) ((mk_eq d0 d₂0).1 hc))
end
@[simp] theorem add_def {a b c d : ℤ} (b0 : b ≠ 0) (d0 : d ≠ 0) :
a /. b + c /. d = (a * d + c * b) /. (b * d) :=
begin
apply lift_binop_eq rat.add; intros; try {assumption},
{ apply mk_pnat_eq },
{ apply mul_ne_zero d₁0 d₂0 },
calc (n₁ * d₂ + n₂ * d₁) * (b * d) =
(n₁ * b) * d₂ * d + (n₂ * d) * (d₁ * b) : by simp [mul_add, mul_comm, mul_left_comm]
... = (a * d₁) * d₂ * d + (c * d₂) * (d₁ * b) : by rw [h₁, h₂]
... = (a * d + c * b) * (d₁ * d₂) : by simp [mul_add, mul_comm, mul_left_comm]
end
/-- Negation of rational numbers. Use `-r` instead. -/
protected def neg (r : ℚ) : ℚ :=
⟨-r.num, r.denom, r.pos, by simp [r.cop]⟩
instance : has_neg ℚ := ⟨rat.neg⟩
@[simp] theorem neg_def {a b : ℤ} : -(a /. b) = -a /. b :=
begin
by_cases b0 : b = 0, { subst b0, simp, refl },
generalize ha : a /. b = x, cases x with n₁ d₁ h₁ c₁, rw num_denom' at ha,
show rat.mk' _ _ _ _ = _, rw num_denom',
have d0 := ne_of_gt (int.coe_nat_lt.2 h₁),
apply (mk_eq d0 b0).2, have h₁ := (mk_eq b0 d0).1 ha,
simp only [neg_mul_eq_neg_mul_symm, congr_arg has_neg.neg h₁]
end
/-- Multiplication of rational numbers. Use `(*)` instead. -/
protected def mul : ℚ → ℚ → ℚ
| ⟨n₁, d₁, h₁, c₁⟩ ⟨n₂, d₂, h₂, c₂⟩ := mk_pnat (n₁ * n₂) ⟨d₁ * d₂, mul_pos h₁ h₂⟩
instance : has_mul ℚ := ⟨rat.mul⟩
@[simp] theorem mul_def {a b c d : ℤ} (b0 : b ≠ 0) (d0 : d ≠ 0) :
(a /. b) * (c /. d) = (a * c) /. (b * d) :=
begin
apply lift_binop_eq rat.mul; intros; try {assumption},
{ apply mk_pnat_eq },
{ apply mul_ne_zero d₁0 d₂0 },
cc
end
/-- Inverse rational number. Use `r⁻¹` instead. -/
protected def inv : ℚ → ℚ
| ⟨(n+1:ℕ), d, h, c⟩ := ⟨d, n+1, n.succ_pos, c.symm⟩
| ⟨0, d, h, c⟩ := 0
| ⟨-[1+ n], d, h, c⟩ := ⟨-d, n+1, n.succ_pos, nat.coprime.symm $ by simp; exact c⟩
instance : has_inv ℚ := ⟨rat.inv⟩
@[simp] theorem inv_def {a b : ℤ} : (a /. b)⁻¹ = b /. a :=
begin
by_cases a0 : a = 0, { subst a0, simp, refl },
by_cases b0 : b = 0, { subst b0, simp, refl },
generalize ha : a /. b = x, cases x with n d h c, rw num_denom' at ha,
refine eq.trans (_ : rat.inv ⟨n, d, h, c⟩ = d /. n) _,
{ cases n with n; [cases n with n, skip],
{ refl },
{ change int.of_nat n.succ with (n+1:ℕ),
unfold rat.inv, rw num_denom' },
{ unfold rat.inv, rw num_denom', refl } },
have n0 : n ≠ 0,
{ refine mt (λ (n0 : n = 0), _) a0,
subst n0, simp at ha,
exact (mk_eq_zero b0).1 ha },
have d0 := ne_of_gt (int.coe_nat_lt.2 h),
have ha := (mk_eq b0 d0).1 ha,
apply (mk_eq n0 a0).2,
cc
end
variables (a b c : ℚ)
protected theorem add_zero : a + 0 = a :=
num_denom_cases_on' a $ λ n d h,
by rw [← zero_mk d]; simp [h, -zero_mk]
protected theorem zero_add : 0 + a = a :=
num_denom_cases_on' a $ λ n d h,
by rw [← zero_mk d]; simp [h, -zero_mk]
protected theorem add_comm : a + b = b + a :=
num_denom_cases_on' a $ λ n₁ d₁ h₁,
num_denom_cases_on' b $ λ n₂ d₂ h₂,
by simp [h₁, h₂]; cc
protected theorem add_assoc : a + b + c = a + (b + c) :=
num_denom_cases_on' a $ λ n₁ d₁ h₁,
num_denom_cases_on' b $ λ n₂ d₂ h₂,
num_denom_cases_on' c $ λ n₃ d₃ h₃,
by simp [h₁, h₂, h₃, mul_ne_zero, mul_add, mul_comm, mul_left_comm, add_left_comm, add_assoc]
protected theorem add_left_neg : -a + a = 0 :=
num_denom_cases_on' a $ λ n d h,
by simp [h]
protected theorem mul_one : a * 1 = a :=
num_denom_cases_on' a $ λ n d h,
by change (1:ℚ) with 1 /. 1; simp [h]
protected theorem one_mul : 1 * a = a :=
num_denom_cases_on' a $ λ n d h,
by change (1:ℚ) with 1 /. 1; simp [h]
protected theorem mul_comm : a * b = b * a :=
num_denom_cases_on' a $ λ n₁ d₁ h₁,
num_denom_cases_on' b $ λ n₂ d₂ h₂,
by simp [h₁, h₂, mul_comm]
protected theorem mul_assoc : a * b * c = a * (b * c) :=
num_denom_cases_on' a $ λ n₁ d₁ h₁,
num_denom_cases_on' b $ λ n₂ d₂ h₂,
num_denom_cases_on' c $ λ n₃ d₃ h₃,
by simp [h₁, h₂, h₃, mul_ne_zero, mul_comm, mul_left_comm]
protected theorem add_mul : (a + b) * c = a * c + b * c :=
num_denom_cases_on' a $ λ n₁ d₁ h₁,
num_denom_cases_on' b $ λ n₂ d₂ h₂,
num_denom_cases_on' c $ λ n₃ d₃ h₃,
by simp [h₁, h₂, h₃, mul_ne_zero];
refine (div_mk_div_cancel_left (int.coe_nat_ne_zero.2 h₃)).symm.trans _;
simp [mul_add, mul_comm, mul_assoc, mul_left_comm]
protected theorem mul_add : a * (b + c) = a * b + a * c :=
by rw [rat.mul_comm, rat.add_mul, rat.mul_comm, rat.mul_comm c a]
protected theorem zero_ne_one : 0 ≠ (1:ℚ) :=
mt (λ (h : 0 = 1 /. 1), (mk_eq_zero one_ne_zero).1 h.symm) one_ne_zero
protected theorem mul_inv_cancel : a ≠ 0 → a * a⁻¹ = 1 :=
num_denom_cases_on' a $ λ n d h a0,
have n0 : n ≠ 0, from mt (by intro e; subst e; simp) a0,
by simp [h, n0, mul_comm]; exact
eq.trans (by simp) (@div_mk_div_cancel_left 1 1 _ n0)
protected theorem inv_mul_cancel (h : a ≠ 0) : a⁻¹ * a = 1 :=
eq.trans (rat.mul_comm _ _) (rat.mul_inv_cancel _ h)
instance : decidable_eq ℚ := by tactic.mk_dec_eq_instance
instance : field ℚ :=
{ zero := 0,
add := rat.add,
neg := rat.neg,
one := 1,
mul := rat.mul,
inv := rat.inv,
zero_add := rat.zero_add,
add_zero := rat.add_zero,
add_comm := rat.add_comm,
add_assoc := rat.add_assoc,
add_left_neg := rat.add_left_neg,
mul_one := rat.mul_one,
one_mul := rat.one_mul,
mul_comm := rat.mul_comm,
mul_assoc := rat.mul_assoc,
left_distrib := rat.mul_add,
right_distrib := rat.add_mul,
exists_pair_ne := ⟨0, 1, rat.zero_ne_one⟩,
mul_inv_cancel := rat.mul_inv_cancel,
inv_zero := rfl }
/- Extra instances to short-circuit type class resolution -/
instance : division_ring ℚ := by apply_instance
instance : integral_domain ℚ := by apply_instance
-- TODO(Mario): this instance slows down data.real.basic
--instance : domain ℚ := by apply_instance
instance : nontrivial ℚ := by apply_instance
instance : comm_ring ℚ := by apply_instance
--instance : ring ℚ := by apply_instance
instance : comm_semiring ℚ := by apply_instance
instance : semiring ℚ := by apply_instance
instance : add_comm_group ℚ := by apply_instance
instance : add_group ℚ := by apply_instance
instance : add_comm_monoid ℚ := by apply_instance
instance : add_monoid ℚ := by apply_instance
instance : add_left_cancel_semigroup ℚ := by apply_instance
instance : add_right_cancel_semigroup ℚ := by apply_instance
instance : add_comm_semigroup ℚ := by apply_instance
instance : add_semigroup ℚ := by apply_instance
instance : comm_monoid ℚ := by apply_instance
instance : monoid ℚ := by apply_instance
instance : comm_semigroup ℚ := by apply_instance
instance : semigroup ℚ := by apply_instance
theorem sub_def {a b c d : ℤ} (b0 : b ≠ 0) (d0 : d ≠ 0) :
a /. b - c /. d = (a * d - c * b) /. (b * d) :=
by simp [b0, d0, sub_eq_add_neg]
@[simp] lemma denom_neg_eq_denom (q : ℚ) : (-q).denom = q.denom := rfl
@[simp] lemma num_neg_eq_neg_num (q : ℚ) : (-q).num = -(q.num) := rfl
@[simp] lemma num_zero : rat.num 0 = 0 := rfl
@[simp] lemma denom_zero : rat.denom 0 = 1 := rfl
lemma zero_of_num_zero {q : ℚ} (hq : q.num = 0) : q = 0 :=
have q = q.num /. q.denom, from num_denom.symm,
by simpa [hq]
lemma zero_iff_num_zero {q : ℚ} : q = 0 ↔ q.num = 0 :=
⟨λ _, by simp *, zero_of_num_zero⟩
lemma num_ne_zero_of_ne_zero {q : ℚ} (h : q ≠ 0) : q.num ≠ 0 :=
assume : q.num = 0,
h $ zero_of_num_zero this
@[simp] lemma num_one : (1 : ℚ).num = 1 := rfl
@[simp] lemma denom_one : (1 : ℚ).denom = 1 := rfl
lemma denom_ne_zero (q : ℚ) : q.denom ≠ 0 :=
ne_of_gt q.pos
lemma eq_iff_mul_eq_mul {p q : ℚ} : p = q ↔ p.num * q.denom = q.num * p.denom :=
begin
conv_lhs { rw [←(@num_denom p), ←(@num_denom q)] },
apply rat.mk_eq,
{ exact_mod_cast p.denom_ne_zero },
{ exact_mod_cast q.denom_ne_zero }
end
lemma mk_num_ne_zero_of_ne_zero {q : ℚ} {n d : ℤ} (hq : q ≠ 0) (hqnd : q = n /. d) : n ≠ 0 :=
assume : n = 0,
hq $ by simpa [this] using hqnd
lemma mk_denom_ne_zero_of_ne_zero {q : ℚ} {n d : ℤ} (hq : q ≠ 0) (hqnd : q = n /. d) : d ≠ 0 :=
assume : d = 0,
hq $ by simpa [this] using hqnd
lemma mk_ne_zero_of_ne_zero {n d : ℤ} (h : n ≠ 0) (hd : d ≠ 0) : n /. d ≠ 0 :=
assume : n /. d = 0,
h $ (mk_eq_zero hd).1 this
lemma mul_num_denom (q r : ℚ) : q * r = (q.num * r.num) /. ↑(q.denom * r.denom) :=
have hq' : (↑q.denom : ℤ) ≠ 0, by have := denom_ne_zero q; simpa,
have hr' : (↑r.denom : ℤ) ≠ 0, by have := denom_ne_zero r; simpa,
suffices (q.num /. ↑q.denom) * (r.num /. ↑r.denom) = (q.num * r.num) /. ↑(q.denom * r.denom),
by simpa using this,
by simp [mul_def hq' hr', -num_denom]
lemma div_num_denom (q r : ℚ) : q / r = (q.num * r.denom) /. (q.denom * r.num) :=
if hr : r.num = 0 then
have hr' : r = 0, from zero_of_num_zero hr,
by simp *
else
calc q / r = q * r⁻¹ : div_eq_mul_inv q r
... = (q.num /. q.denom) * (r.num /. r.denom)⁻¹ : by simp
... = (q.num /. q.denom) * (r.denom /. r.num) : by rw inv_def
... = (q.num * r.denom) /. (q.denom * r.num) : mul_def (by simpa using denom_ne_zero q) hr
lemma num_denom_mk {q : ℚ} {n d : ℤ} (hn : n ≠ 0) (hd : d ≠ 0) (qdf : q = n /. d) :
∃ c : ℤ, n = c * q.num ∧ d = c * q.denom :=
have hq : q ≠ 0, from
assume : q = 0,
hn $ (rat.mk_eq_zero hd).1 (by cc),
have q.num /. q.denom = n /. d, by rwa [num_denom],
have q.num * d = n * ↑(q.denom), from (rat.mk_eq (by simp [rat.denom_ne_zero]) hd).1 this,
begin
existsi n / q.num,
have hqdn : q.num ∣ n, begin rw qdf, apply rat.num_dvd, assumption end,
split,
{ rw int.div_mul_cancel hqdn },
{ apply int.eq_mul_div_of_mul_eq_mul_of_dvd_left,
{ apply rat.num_ne_zero_of_ne_zero hq },
repeat { assumption } }
end
theorem mk_pnat_num (n : ℤ) (d : ℕ+) :
(mk_pnat n d).num = n / nat.gcd n.nat_abs d :=
by cases d; refl
theorem mk_pnat_denom (n : ℤ) (d : ℕ+) :
(mk_pnat n d).denom = d / nat.gcd n.nat_abs d :=
by cases d; refl
theorem mk_pnat_denom_dvd (n : ℤ) (d : ℕ+) :
(mk_pnat n d).denom ∣ d.1 :=
begin
rw mk_pnat_denom,
apply nat.div_dvd_of_dvd,
apply nat.gcd_dvd_right
end
theorem add_denom_dvd (q₁ q₂ : ℚ) : (q₁ + q₂).denom ∣ q₁.denom * q₂.denom :=
by { cases q₁, cases q₂, apply mk_pnat_denom_dvd }
theorem mul_denom_dvd (q₁ q₂ : ℚ) : (q₁ * q₂).denom ∣ q₁.denom * q₂.denom :=
by { cases q₁, cases q₂, apply mk_pnat_denom_dvd }
theorem mul_num (q₁ q₂ : ℚ) : (q₁ * q₂).num =
(q₁.num * q₂.num) / nat.gcd (q₁.num * q₂.num).nat_abs (q₁.denom * q₂.denom) :=
by cases q₁; cases q₂; refl
theorem mul_denom (q₁ q₂ : ℚ) : (q₁ * q₂).denom =
(q₁.denom * q₂.denom) / nat.gcd (q₁.num * q₂.num).nat_abs (q₁.denom * q₂.denom) :=
by cases q₁; cases q₂; refl
theorem mul_self_num (q : ℚ) : (q * q).num = q.num * q.num :=
by rw [mul_num, int.nat_abs_mul, nat.coprime.gcd_eq_one, int.coe_nat_one, int.div_one];
exact (q.cop.mul_right q.cop).mul (q.cop.mul_right q.cop)
theorem mul_self_denom (q : ℚ) : (q * q).denom = q.denom * q.denom :=
by rw [rat.mul_denom, int.nat_abs_mul, nat.coprime.gcd_eq_one, nat.div_one];
exact (q.cop.mul_right q.cop).mul (q.cop.mul_right q.cop)
lemma add_num_denom (q r : ℚ) : q + r =
((q.num * r.denom + q.denom * r.num : ℤ)) /. (↑q.denom * ↑r.denom : ℤ) :=
have hqd : (q.denom : ℤ) ≠ 0, from int.coe_nat_ne_zero_iff_pos.2 q.3,
have hrd : (r.denom : ℤ) ≠ 0, from int.coe_nat_ne_zero_iff_pos.2 r.3,
by conv_lhs { rw [←@num_denom q, ←@num_denom r, rat.add_def hqd hrd] };
simp [mul_comm]
section casts
theorem coe_int_eq_mk : ∀ (z : ℤ), ↑z = z /. 1
| (n : ℕ) := show (n:ℚ) = n /. 1,
by induction n with n IH n; simp [*, show (1:ℚ) = 1 /. 1, from rfl]
| -[1+ n] := show (-(n + 1) : ℚ) = -[1+ n] /. 1, begin
induction n with n IH, {refl},
show -(n + 1 + 1 : ℚ) = -[1+ n.succ] /. 1,
rw [neg_add, IH],
simp [show -1 = (-1) /. 1, from rfl],
end
theorem mk_eq_div (n d : ℤ) : n /. d = ((n : ℚ) / d) :=
begin
by_cases d0 : d = 0, {simp [d0, div_zero]},
simp [division_def, coe_int_eq_mk, mul_def one_ne_zero d0]
end
theorem num_div_denom (r : ℚ) : (r.num / r.denom : ℚ) = r :=
by rw [← int.cast_coe_nat, ← mk_eq_div, num_denom]
lemma exists_eq_mul_div_num_and_eq_mul_div_denom {n d : ℤ} (n_ne_zero : n ≠ 0)
(d_ne_zero : d ≠ 0) :
∃ (c : ℤ), n = c * ((n : ℚ) / d).num ∧ (d : ℤ) = c * ((n : ℚ) / d).denom :=
begin
have : ((n : ℚ) / d) = rat.mk n d, by rw [←rat.mk_eq_div],
exact rat.num_denom_mk n_ne_zero d_ne_zero this
end
theorem coe_int_eq_of_int (z : ℤ) : ↑z = of_int z :=
(coe_int_eq_mk z).trans (of_int_eq_mk z).symm
@[simp, norm_cast] theorem coe_int_num (n : ℤ) : (n : ℚ).num = n :=
by rw coe_int_eq_of_int; refl
@[simp, norm_cast] theorem coe_int_denom (n : ℤ) : (n : ℚ).denom = 1 :=
by rw coe_int_eq_of_int; refl
lemma coe_int_num_of_denom_eq_one {q : ℚ} (hq : q.denom = 1) : ↑(q.num) = q :=
by { conv_rhs { rw [←(@num_denom q), hq] }, rw [coe_int_eq_mk], refl }
lemma denom_eq_one_iff (r : ℚ) : r.denom = 1 ↔ ↑r.num = r :=
⟨rat.coe_int_num_of_denom_eq_one, λ h, h ▸ rat.coe_int_denom r.num⟩
instance : can_lift ℚ ℤ :=
⟨coe, λ q, q.denom = 1, λ q hq, ⟨q.num, coe_int_num_of_denom_eq_one hq⟩⟩
theorem coe_nat_eq_mk (n : ℕ) : ↑n = n /. 1 :=
by rw [← int.cast_coe_nat, coe_int_eq_mk]
@[simp, norm_cast] theorem coe_nat_num (n : ℕ) : (n : ℚ).num = n :=
by rw [← int.cast_coe_nat, coe_int_num]
@[simp, norm_cast] theorem coe_nat_denom (n : ℕ) : (n : ℚ).denom = 1 :=
by rw [← int.cast_coe_nat, coe_int_denom]
-- Will be subsumed by `int.coe_inj` after we have defined
-- `linear_ordered_field ℚ` (which implies characteristic zero).
lemma coe_int_inj (m n : ℤ) : (m : ℚ) = n ↔ m = n :=
⟨λ h, by simpa using congr_arg num h, congr_arg _⟩
end casts
lemma inv_def' {q : ℚ} : q⁻¹ = (q.denom : ℚ) / q.num :=
by { conv_lhs { rw ←(@num_denom q) }, cases q, simp [div_num_denom] }
@[simp] lemma mul_denom_eq_num {q : ℚ} : q * q.denom = q.num :=
begin
suffices : mk (q.num) ↑(q.denom) * mk ↑(q.denom) 1 = mk (q.num) 1, by
{ conv { for q [1] { rw ←(@num_denom q) }}, rwa [coe_int_eq_mk, coe_nat_eq_mk] },
have : (q.denom : ℤ) ≠ 0, from ne_of_gt (by exact_mod_cast q.pos),
rw [(rat.mul_def this one_ne_zero), (mul_comm (q.denom : ℤ) 1), (div_mk_div_cancel_left this)]
end
lemma denom_div_cast_eq_one_iff (m n : ℤ) (hn : n ≠ 0) :
((m : ℚ) / n).denom = 1 ↔ n ∣ m :=
begin
replace hn : (n:ℚ) ≠ 0, by rwa [ne.def, ← int.cast_zero, coe_int_inj],
split,
{ intro h,
lift ((m : ℚ) / n) to ℤ using h with k hk,
use k,
rwa [eq_div_iff_mul_eq hn, ← int.cast_mul, mul_comm, eq_comm, coe_int_inj] at hk },
{ rintros ⟨d, rfl⟩,
rw [int.cast_mul, mul_comm, mul_div_cancel _ hn, rat.coe_int_denom] }
end
lemma num_div_eq_of_coprime {a b : ℤ} (hb0 : 0 < b) (h : nat.coprime a.nat_abs b.nat_abs) :
(a / b : ℚ).num = a :=
begin
lift b to ℕ using le_of_lt hb0,
norm_cast at hb0 h,
rw [← rat.mk_eq_div, ← rat.mk_pnat_eq a b hb0, rat.mk_pnat_num, pnat.mk_coe, h.gcd_eq_one,
int.coe_nat_one, int.div_one]
end
lemma denom_div_eq_of_coprime {a b : ℤ} (hb0 : 0 < b) (h : nat.coprime a.nat_abs b.nat_abs) :
((a / b : ℚ).denom : ℤ) = b :=
begin
lift b to ℕ using le_of_lt hb0,
norm_cast at hb0 h,
rw [← rat.mk_eq_div, ← rat.mk_pnat_eq a b hb0, rat.mk_pnat_denom, pnat.mk_coe, h.gcd_eq_one,
nat.div_one]
end
lemma div_int_inj {a b c d : ℤ} (hb0 : 0 < b) (hd0 : 0 < d)
(h1 : nat.coprime a.nat_abs b.nat_abs) (h2 : nat.coprime c.nat_abs d.nat_abs)
(h : (a : ℚ) / b = (c : ℚ) / d) : a = c ∧ b = d :=
begin
apply and.intro,
{ rw [← (num_div_eq_of_coprime hb0 h1), h, num_div_eq_of_coprime hd0 h2] },
{ rw [← (denom_div_eq_of_coprime hb0 h1), h, denom_div_eq_of_coprime hd0 h2] }
end
@[norm_cast] lemma coe_int_div_self (n : ℤ) : ((n / n : ℤ) : ℚ) = n / n :=
begin
by_cases hn : n = 0,
{ subst hn, simp only [int.cast_zero, euclidean_domain.zero_div] },
{ have : (n : ℚ) ≠ 0, { rwa ← coe_int_inj at hn },
simp only [int.div_self hn, int.cast_one, ne.def, not_false_iff, div_self this] }
end
@[norm_cast] lemma coe_nat_div_self (n : ℕ) : ((n / n : ℕ) : ℚ) = n / n :=
coe_int_div_self n
lemma coe_int_div (a b : ℤ) (h : b ∣ a) : ((a / b : ℤ) : ℚ) = a / b :=
begin
rcases h with ⟨c, rfl⟩,
simp only [mul_comm b, int.mul_div_assoc c (dvd_refl b), int.cast_mul, mul_div_assoc,
coe_int_div_self]
end
lemma coe_nat_div (a b : ℕ) (h : b ∣ a) : ((a / b : ℕ) : ℚ) = a / b :=
begin
rcases h with ⟨c, rfl⟩,
simp only [mul_comm b, nat.mul_div_assoc c (dvd_refl b), nat.cast_mul, mul_div_assoc,
coe_nat_div_self]
end
protected lemma «forall» {p : ℚ → Prop} : (∀ r, p r) ↔ ∀ a b : ℤ, p (a / b) :=
⟨λ h _ _, h _,
λ h q, (show q = q.num / q.denom, from by simp [rat.div_num_denom]).symm ▸ (h q.1 q.2)⟩
protected lemma «exists» {p : ℚ → Prop} : (∃ r, p r) ↔ ∃ a b : ℤ, p (a / b) :=
⟨λ ⟨r, hr⟩, ⟨r.num, r.denom, by rwa [← mk_eq_div, num_denom]⟩, λ ⟨a, b, h⟩, ⟨_, h⟩⟩
end rat
|
b0656835d612057cc0a466dcc034d54a169156aa | f4bff2062c030df03d65e8b69c88f79b63a359d8 | /src/game/topology/union_closed_sets.lean | 591863470f005e812acb8931d88768c10ac72393 | [
"Apache-2.0"
] | permissive | adastra7470/real-number-game | 776606961f52db0eb824555ed2f8e16f92216ea3 | f9dcb7d9255a79b57e62038228a23346c2dc301b | refs/heads/master | 1,669,221,575,893 | 1,594,669,800,000 | 1,594,669,800,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 566 | lean | import data.real.basic
import data.set.lattice
import topology.basic
import game.topology.union_open_sets
open set
--begin hide
namespace xena
-- end hide
def is_closed (X : set ℝ) := is_open {x : ℝ | x ∉ X }
-- begin hide
-- Checking mathlib definitions
variable β : Type* -- finite unions only
variable [fintype β]
-- end hide
/- Lemma
Finite union of closed sets is closed -- WIP, to do.
-/
lemma is_closed_fin_union_of_closed (X : β → set ℝ ) ( hj : ∀ j, is_closed (X j) )
: is_closed (Union X) :=
begin
sorry,
end
end xena -- hide |
cc169a0c662057ed788fd9c7c58dcf17a5237d55 | 432d948a4d3d242fdfb44b81c9e1b1baacd58617 | /test/aesop/default_rules.lean | 047a3e0b4aa2c864a186f17696103de00da17bd0 | [
"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 | 1,567 | lean | import tactic.aesop.default_rules
open tactic.aesop.default_rule (split_hyps)
/-!
# split_hyps
Note: the names of generated hypotheses are more or less arbitrary and should
not be relied upon.
-/
/- We can split product-like types. -/
example {P Q : Prop} {A B : Type}
(h₁ : P ∧ Q) (h₂ : A × B) (h₃ : pprod A B) : true :=
begin
split_hyps,
guard_hyp h₁_1 : P,
guard_hyp h₁_2 : Q,
guard_hyp h₂_1 : A,
guard_hyp h₂_2 : B,
guard_hyp h₃_1 : A,
guard_hyp h₃_2 : B,
trivial
end
/- We can split product-like types under leading Π binders. -/
example {X : Type} {P Q : X → Prop} (h : ∀ x, P x ∧ Q x) : true :=
begin
split_hyps,
guard_hyp h_1 : ∀ x, P x,
guard_hyp h_2 : ∀ x, Q x,
trivial
end
/- We can split sigma-like types. -/
example {X : Type} {P : X → Prop} {Q : X → Type}
(h₁ : ∃ x, P x) (h₂ : Σ x, Q x ) (h₃ : psigma Q) (h₄ : subtype P) : true :=
begin
split_hyps,
guard_hyp h₁_w : X,
guard_hyp h₁_h : P h₁_w,
guard_hyp h₂_fst : X,
guard_hyp h₂_snd : Q h₂_fst,
guard_hyp h₃_fst : X,
guard_hyp h₃_snd : Q h₃_fst,
guard_hyp h₄_val : X,
guard_hyp h₄_property : P h₄_val,
trivial
end
/- Splitting is recursive, so nested products are supported. -/
example {X Y : Type} {Z : Prop} {P Q : X → Y → Prop}
(h : (∃ x, ∃ y, P x y ∧ Q x y) ∧ Z) : true :=
begin
split_hyps,
guard_hyp h_2 : Z,
guard_hyp h_1_w : X,
guard_hyp h_1_h_w : Y,
guard_hyp h_1_h_h_1 : P h_1_w h_1_h_w,
guard_hyp h_1_h_h_2 : Q h_1_w h_1_h_w,
trivial
end
|
b4ffb7b16249e05c0f145c16c15f9916c425ed75 | 57aec6ee746bc7e3a3dd5e767e53bd95beb82f6d | /stage0/src/Lean/Data/Lsp/Extra.lean | 0bd811d4a21d3f7816f7518834ad51dd166d2592 | [
"Apache-2.0"
] | permissive | collares/lean4 | 861a9269c4592bce49b71059e232ff0bfe4594cc | 52a4f535d853a2c7c7eea5fee8a4fa04c682c1ee | refs/heads/master | 1,691,419,031,324 | 1,618,678,138,000 | 1,618,678,138,000 | 358,989,750 | 0 | 0 | Apache-2.0 | 1,618,696,333,000 | 1,618,696,333,000 | null | UTF-8 | Lean | false | false | 1,298 | lean | /-
Copyright (c) 2020 Marc Huisinga. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Marc Huisinga
-/
import Lean.Data.Json
import Lean.Data.JsonRpc
import Lean.Data.Lsp.Basic
/-!
This file contains Lean-specific extensions to LSP.
The following additional packets are supported:
- "textDocument/waitForDiagnostics": Yields a response when all the diagnostics for a version of the document
greater or equal to the specified one have been emitted. If the request specifies a version above the most
recently processed one, the server will delay the response until it does receive the specified version.
Exists for synchronization purposes, e.g. during testing or when external tools might want to use our LSP server.
-/
namespace Lean.Lsp
open Json
structure WaitForDiagnosticsParams where
uri : DocumentUri
version : Nat
deriving ToJson, FromJson
structure WaitForDiagnostics
instance : FromJson WaitForDiagnostics :=
⟨fun j => WaitForDiagnostics.mk⟩
instance : ToJson WaitForDiagnostics :=
⟨fun o => mkObj []⟩
structure PlainGoalParams extends TextDocumentPositionParams
deriving FromJson, ToJson
structure PlainGoal where
rendered : String
goals : Array String
deriving FromJson, ToJson
end Lean.Lsp
|
3dfde7a9ee62bb287f03bfd790d7ae9f0fc90f67 | 437dc96105f48409c3981d46fb48e57c9ac3a3e4 | /src/data/equiv/mul_add.lean | beb5ffbbe5745cfee032ccff44d8fc51d8c855d5 | [
"Apache-2.0"
] | permissive | dan-c-k/mathlib | 08efec79bd7481ee6da9cc44c24a653bff4fbe0d | 96efc220f6225bc7a5ed8349900391a33a38cc56 | refs/heads/master | 1,658,082,847,093 | 1,589,013,201,000 | 1,589,013,201,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 10,398 | 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, Callum Sutton, Yury Kudryashov
-/
import data.equiv.basic
import deprecated.group
/-!
# Multiplicative and additive equivs
In this file we define two extensions of `equiv` called `add_equiv` and `mul_equiv`, which are
datatypes representing isomorphisms of `add_monoid`s/`add_group`s and `monoid`s/`group`s. We also
introduce the corresponding groups of automorphisms `add_aut` and `mul_aut`.
## Notations
The extended equivs all have coercions to functions, and the coercions are the canonical
notation when treating the isomorphisms as maps.
## Implementation notes
The fields for `mul_equiv`, `add_equiv` now avoid the unbundled `is_mul_hom` and `is_add_hom`, as
these are deprecated.
Definition of multiplication in the groups of automorphisms agrees with function composition,
multiplication in `equiv.perm`, and multiplication in `category_theory.End`, not with
`category_theory.comp`.
## Tags
equiv, mul_equiv, add_equiv, mul_aut, add_aut
-/
variables {A : Type*} {B : Type*} {M : Type*} {N : Type*} {P : Type*} {G : Type*} {H : Type*}
set_option old_structure_cmd true
/-- add_equiv α β is the type of an equiv α ≃ β which preserves addition. -/
structure add_equiv (A B : Type*) [has_add A] [has_add B] extends A ≃ B :=
(map_add' : ∀ x y : A, to_fun (x + y) = to_fun x + to_fun y)
/-- `mul_equiv α β` is the type of an equiv `α ≃ β` which preserves multiplication. -/
@[to_additive]
structure mul_equiv (M N : Type*) [has_mul M] [has_mul N] extends M ≃ N :=
(map_mul' : ∀ x y : M, to_fun (x * y) = to_fun x * to_fun y)
infix ` ≃* `:25 := mul_equiv
infix ` ≃+ `:25 := add_equiv
namespace mul_equiv
@[to_additive]
instance [has_mul M] [has_mul N] : has_coe_to_fun (M ≃* N) := ⟨_, mul_equiv.to_fun⟩
variables [has_mul M] [has_mul N] [has_mul P]
/-- A multiplicative isomorphism preserves multiplication (canonical form). -/
@[to_additive]
lemma map_mul (f : M ≃* N) : ∀ x y, f (x * y) = f x * f y := f.map_mul'
/-- A multiplicative isomorphism preserves multiplication (deprecated). -/
@[to_additive]
instance (h : M ≃* N) : is_mul_hom h := ⟨h.map_mul⟩
/-- Makes a multiplicative isomorphism from a bijection which preserves multiplication. -/
@[to_additive]
def mk' (f : M ≃ N) (h : ∀ x y, f (x * y) = f x * f y) : M ≃* N :=
⟨f.1, f.2, f.3, f.4, h⟩
/-- The identity map is a multiplicative isomorphism. -/
@[refl, to_additive]
def refl (M : Type*) [has_mul M] : M ≃* M :=
{ map_mul' := λ _ _, rfl,
..equiv.refl _}
/-- The inverse of an isomorphism is an isomorphism. -/
@[symm, to_additive]
def symm (h : M ≃* N) : N ≃* M :=
{ map_mul' := λ n₁ n₂, function.injective_of_left_inverse h.left_inv begin
show h.to_equiv (h.to_equiv.symm (n₁ * n₂)) =
h ((h.to_equiv.symm n₁) * (h.to_equiv.symm n₂)),
rw h.map_mul,
show _ = h.to_equiv (_) * h.to_equiv (_),
rw [h.to_equiv.apply_symm_apply, h.to_equiv.apply_symm_apply, h.to_equiv.apply_symm_apply], end,
..h.to_equiv.symm}
@[simp, to_additive]
theorem to_equiv_symm (f : M ≃* N) : f.symm.to_equiv = f.to_equiv.symm := rfl
@[simp, to_additive]
theorem coe_mk (f : M → N) (g h₁ h₂ h₃) : ⇑(mul_equiv.mk f g h₁ h₂ h₃) = f := rfl
@[simp, to_additive]
theorem coe_symm_mk (f : M → N) (g h₁ h₂ h₃) : ⇑(mul_equiv.mk f g h₁ h₂ h₃).symm = g := rfl
/-- Transitivity of multiplication-preserving isomorphisms -/
@[trans, to_additive]
def trans (h1 : M ≃* N) (h2 : N ≃* P) : (M ≃* P) :=
{ map_mul' := λ x y, show h2 (h1 (x * y)) = h2 (h1 x) * h2 (h1 y),
by rw [h1.map_mul, h2.map_mul],
..h1.to_equiv.trans h2.to_equiv }
/-- e.right_inv in canonical form -/
@[simp, to_additive]
lemma apply_symm_apply (e : M ≃* N) : ∀ y, e (e.symm y) = y :=
e.to_equiv.apply_symm_apply
/-- e.left_inv in canonical form -/
@[simp, to_additive]
lemma symm_apply_apply (e : M ≃* N) : ∀ x, e.symm (e x) = x :=
e.to_equiv.symm_apply_apply
/-- a multiplicative equiv of monoids sends 1 to 1 (and is hence a monoid isomorphism) -/
@[simp, to_additive]
lemma map_one {M N} [monoid M] [monoid N] (h : M ≃* N) : h 1 = 1 :=
by rw [←mul_one (h 1), ←h.apply_symm_apply 1, ←h.map_mul, one_mul]
@[simp, to_additive]
lemma map_eq_one_iff {M N} [monoid M] [monoid N] (h : M ≃* N) {x : M} :
h x = 1 ↔ x = 1 :=
h.map_one ▸ h.to_equiv.apply_eq_iff_eq x 1
@[to_additive]
lemma map_ne_one_iff {M N} [monoid M] [monoid N] (h : M ≃* N) {x : M} :
h x ≠ 1 ↔ x ≠ 1 :=
⟨mt h.map_eq_one_iff.2, mt h.map_eq_one_iff.1⟩
/--
Extract the forward direction of a multiplicative equivalence
as a multiplication preserving function.
-/
@[to_additive to_add_monoid_hom]
def to_monoid_hom {M N} [monoid M] [monoid N] (h : M ≃* N) : (M →* N) :=
{ map_one' := h.map_one, .. h }
@[simp, to_additive]
lemma to_monoid_hom_apply {M N} [monoid M] [monoid N] (e : M ≃* N) (x : M) :
e.to_monoid_hom x = e x :=
rfl
/-- A multiplicative equivalence of groups preserves inversion. -/
@[to_additive]
lemma map_inv [group G] [group H] (h : G ≃* H) (x : G) : h x⁻¹ = (h x)⁻¹ :=
h.to_monoid_hom.map_inv x
/-- A multiplicative bijection between two monoids is a monoid hom
(deprecated -- use to_monoid_hom). -/
@[to_additive is_add_monoid_hom]
instance is_monoid_hom {M N} [monoid M] [monoid N] (h : M ≃* N) : is_monoid_hom h :=
⟨h.map_one⟩
/-- A multiplicative bijection between two groups is a group hom
(deprecated -- use to_monoid_hom). -/
@[to_additive is_add_group_hom]
instance is_group_hom {G H} [group G] [group H] (h : G ≃* H) :
is_group_hom h := { map_mul := h.map_mul }
/-- Two multiplicative isomorphisms agree if they are defined by the
same underlying function. -/
@[ext, to_additive
"Two additive isomorphisms agree if they are defined by the same underlying function."]
lemma ext {f g : mul_equiv M N} (h : ∀ x, f x = g x) : f = g :=
begin
have h₁ := equiv.ext f.to_equiv g.to_equiv h,
cases f, cases g, congr,
{ exact (funext h) },
{ exact congr_arg equiv.inv_fun h₁ }
end
attribute [ext] add_equiv.ext
end mul_equiv
/-- An additive equivalence of additive groups preserves subtraction. -/
lemma add_equiv.map_sub [add_group A] [add_group B] (h : A ≃+ B) (x y : A) :
h (x - y) = h x - h y :=
h.to_add_monoid_hom.map_sub x y
/-- The group of multiplicative automorphisms. -/
@[to_additive "The group of additive automorphisms."]
def mul_aut (M : Type*) [has_mul M] := M ≃* M
namespace mul_aut
variables (M) [has_mul M]
/--
The group operation on multiplicative automorphisms is defined by
`λ g h, mul_equiv.trans h g`.
This means that multiplication agrees with composition, `(g*h)(x) = g (h x)`.
-/
instance : group (mul_aut M) :=
by refine_struct
{ mul := λ g h, mul_equiv.trans h g,
one := mul_equiv.refl M,
inv := mul_equiv.symm };
intros; ext; try { refl }; apply equiv.left_inv
instance : inhabited (mul_aut M) := ⟨1⟩
/-- Monoid hom from the group of multiplicative automorphisms to the group of permutations. -/
def to_perm : mul_aut M →* equiv.perm M :=
by refine_struct { to_fun := mul_equiv.to_equiv }; intros; refl
end mul_aut
namespace add_aut
variables (A) [has_add A]
/--
The group operation on additive automorphisms is defined by
`λ g h, mul_equiv.trans h g`.
This means that multiplication agrees with composition, `(g*h)(x) = g (h x)`.
-/
instance group : group (add_aut A) :=
by refine_struct
{ mul := λ g h, add_equiv.trans h g,
one := add_equiv.refl A,
inv := add_equiv.symm };
intros; ext; try { refl }; apply equiv.left_inv
instance : inhabited (add_aut A) := ⟨1⟩
/-- Monoid hom from the group of multiplicative automorphisms to the group of permutations. -/
def to_perm : add_aut A →* equiv.perm A :=
by refine_struct { to_fun := add_equiv.to_equiv }; intros; refl
end add_aut
/-- A group is isomorphic to its group of units. -/
def to_units (G) [group G] : G ≃* units G :=
{ to_fun := λ x, ⟨x, x⁻¹, mul_inv_self _, inv_mul_self _⟩,
inv_fun := coe,
left_inv := λ x, rfl,
right_inv := λ u, units.ext rfl,
map_mul' := λ x y, units.ext rfl }
namespace units
variables [monoid M] [monoid N] [monoid P]
/-- A multiplicative equivalence of monoids defines a multiplicative equivalence
of their groups of units. -/
def map_equiv (h : M ≃* N) : units M ≃* units N :=
{ inv_fun := map h.symm.to_monoid_hom,
left_inv := λ u, ext $ h.left_inv u,
right_inv := λ u, ext $ h.right_inv u,
.. map h.to_monoid_hom }
end units
namespace equiv
section group
variables [group G]
@[to_additive]
protected def mul_left (a : G) : perm G :=
{ to_fun := λx, a * x,
inv_fun := λx, a⁻¹ * x,
left_inv := assume x, show a⁻¹ * (a * x) = x, from inv_mul_cancel_left a x,
right_inv := assume x, show a * (a⁻¹ * x) = x, from mul_inv_cancel_left a x }
@[to_additive]
protected def mul_right (a : G) : perm G :=
{ to_fun := λx, x * a,
inv_fun := λx, x * a⁻¹,
left_inv := assume x, show (x * a) * a⁻¹ = x, from mul_inv_cancel_right x a,
right_inv := assume x, show (x * a⁻¹) * a = x, from inv_mul_cancel_right x a }
variable (G)
@[to_additive]
protected def inv : perm G :=
{ to_fun := λa, a⁻¹,
inv_fun := λa, a⁻¹,
left_inv := assume a, inv_inv a,
right_inv := assume a, inv_inv a }
end group
section reflection
variables [add_comm_group A] (x y : A)
/-- Reflection in `x` as a permutation. -/
def reflection (x : A) : perm A :=
(equiv.neg A).trans (equiv.add_left (x + x))
lemma reflection_apply : reflection x y = x + x - y := rfl
@[simp] lemma reflection_self : reflection x x = x := add_sub_cancel _ _
lemma reflection_involutive : function.involutive (reflection x : A → A) :=
λ y, by simp only [reflection_apply, sub_sub_cancel]
@[simp] lemma reflection_symm : (reflection x).symm = reflection x :=
by { ext y, rw [symm_apply_eq, reflection_involutive x y] }
/-- `x` is the only fixed point of `reflection x`. This lemma requires `x + x = y + y ↔ x = y`.
There is no typeclass to use here, so we add it as an explicit argument. -/
lemma reflection_fixed_iff_of_bit0_inj {x y : A} (h : function.injective (bit0 : A → A)) :
reflection x y = y ↔ y = x :=
sub_eq_iff_eq_add.trans $ h.eq_iff.trans eq_comm
end reflection
end equiv
|
9c276ee09267f20cae5e92841188aa79e7d4739d | 453dcd7c0d1ef170b0843a81d7d8caedc9741dce | /analysis/measure_theory/measure_space.lean | 193ca47832a388e73622ef30f5e2d65e48a4019e | [
"Apache-2.0"
] | permissive | amswerdlow/mathlib | 9af77a1f08486d8fa059448ae2d97795bd12ec0c | 27f96e30b9c9bf518341705c99d641c38638dfd0 | refs/heads/master | 1,585,200,953,598 | 1,534,275,532,000 | 1,534,275,532,000 | 144,564,700 | 0 | 0 | null | 1,534,156,197,000 | 1,534,156,197,000 | null | UTF-8 | Lean | false | false | 25,345 | lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro
Measure spaces -- measures
Measures are restricted to a measurable space (associated by the type class `measurable_space`).
This allows us to prove equalities between measures by restricting to a generating set of the
measurable space.
On the other hand, the `μ.measure s` projection (i.e. the measure of `s` on the measure space `μ`)
is the _outer_ measure generated by `μ`. This gives us a unrestricted monotonicity rule and it is
somehow well-behaved on non-measurable sets.
This allows us for the `lebesgue` measure space to have the `borel` measurable space, but still be
a complete measure.
-/
import data.set order.galois_connection analysis.ennreal
analysis.measure_theory.outer_measure
noncomputable theory
open classical set lattice filter finset function
local attribute [instance] prop_decidable
universes u v w x
namespace measure_theory
section of_measurable
parameters {α : Type*} [measurable_space α]
parameters (m : Π (s : set α), is_measurable s → ennreal)
parameters (m0 : m ∅ is_measurable.empty = 0)
include m0
/-- Measure projection which is ∞ for non-measurable sets.
`measure'` is mainly used to derive the outer measure, for the main `measure` projection. -/
def measure' (s : set α) : ennreal := ⨅ h : is_measurable s, m s h
lemma measure'_eq {s} (h : is_measurable s) : measure' s = m s h :=
by simp [measure', h]
lemma measure'_empty : measure' ∅ = 0 :=
(measure'_eq is_measurable.empty).trans m0
lemma measure'_Union_nat
{f : ℕ → set α}
(hm : ∀i, is_measurable (f i))
(mU : m (⋃i, f i) (is_measurable.Union hm) = (∑i, m (f i) (hm i))) :
measure' (⋃i, f i) = (∑i, measure' (f i)) :=
(measure'_eq _).trans $ mU.trans $
by congr; funext i; rw measure'_eq
/-- outer measure of a measure -/
def outer_measure' : outer_measure α :=
outer_measure.of_function measure' measure'_empty
lemma measure'_Union_le_tsum_nat'
(mU : ∀ {f : ℕ → set α} (hm : ∀i, is_measurable (f i)),
m (⋃i, f i) (is_measurable.Union hm) ≤ (∑i, m (f i) (hm i)))
(s : ℕ → set α) :
measure' (⋃i, s i) ≤ (∑i, measure' (s i)) :=
begin
by_cases h : ∀i, is_measurable (s i),
{ rw [measure'_eq _ _ (is_measurable.Union h),
congr_arg tsum _], {apply mU h},
funext i, apply measure'_eq _ _ (h i) },
{ cases not_forall.1 h with i hi,
exact le_trans (le_infi $ λ h, hi.elim h) (ennreal.le_tsum i) }
end
parameter (mU : ∀ {f : ℕ → set α} (hm : ∀i, is_measurable (f i)),
pairwise (disjoint on f) →
m (⋃i, f i) (is_measurable.Union hm) = (∑i, m (f i) (hm i)))
include mU
lemma measure'_Union
{β} [encodable β] {f : β → set α}
(hd : pairwise (disjoint on f)) (hm : ∀i, is_measurable (f i)) :
measure' (⋃i, f i) = (∑i, measure' (f i)) :=
begin
rw [encodable.Union_decode2, outer_measure.Union_aux],
{ exact measure'_Union_nat _ _
(λ n, encodable.Union_decode2_cases is_measurable.empty hm)
(mU _ (measurable_space.Union_decode2_disjoint_on hd)) },
{ apply measure'_empty },
end
lemma measure'_union {s₁ s₂ : set α}
(hd : disjoint s₁ s₂) (h₁ : is_measurable s₁) (h₂ : is_measurable s₂) :
measure' (s₁ ∪ s₂) = measure' s₁ + measure' s₂ :=
begin
rw [union_eq_Union, measure'_Union _ _ @mU
(pairwise_disjoint_on_bool.2 hd) (bool.forall_bool.2 ⟨h₂, h₁⟩),
tsum_fintype],
change _+_ = _, simp
end
lemma measure'_mono {s₁ s₂ : set α} (h₁ : is_measurable s₁) (hs : s₁ ⊆ s₂) :
measure' s₁ ≤ measure' s₂ :=
le_infi $ λ h₂, begin
have := measure'_union _ _ @mU disjoint_diff h₁ (h₂.diff h₁),
rw union_diff_cancel hs at this,
rw ← measure'_eq m m0 _,
exact le_iff_exists_add.2 ⟨_, this⟩
end
lemma measure'_Union_le_tsum_nat : ∀ (s : ℕ → set α),
measure' (⋃i, s i) ≤ (∑i, measure' (s i)) :=
measure'_Union_le_tsum_nat' $ λ f h, begin
simp [Union_disjointed.symm] {single_pass := tt},
rw [mU (is_measurable.disjointed h) disjoint_disjointed],
refine ennreal.tsum_le_tsum (λ i, _),
rw [← measure'_eq m m0, ← measure'_eq m m0],
exact measure'_mono _ _ @mU (is_measurable.disjointed h _) (inter_subset_left _ _)
end
lemma outer_measure'_eq {s : set α} (hs : is_measurable s) :
outer_measure' s = m s hs :=
by rw ← measure'_eq m m0 hs; exact
(le_antisymm (outer_measure.of_function_le _ _ _) $
le_infi $ λ f, le_infi $ λ hf,
le_trans (measure'_mono _ _ @mU hs hf) $
measure'_Union_le_tsum_nat _ _ @mU _)
lemma outer_measure'_eq_measure' {s : set α} (hs : is_measurable s) :
outer_measure' s = measure' s :=
by rw [measure'_eq m m0 hs, outer_measure'_eq m m0 @mU hs]
end of_measurable
namespace outer_measure
variables {α : Type*} [measurable_space α] (m : outer_measure α)
def trim : outer_measure α :=
outer_measure' (λ s _, m s) m.empty
theorem trim_ge : m ≤ m.trim :=
λ s, le_infi $ λ f, le_infi $ λ hs,
le_trans (m.mono hs) $ le_trans (m.Union_nat f) $
ennreal.tsum_le_tsum $ λ i, le_infi $ λ hf, le_refl _
theorem trim_eq {s : set α} (hs : is_measurable s) : m.trim s = m s :=
le_antisymm (le_trans (of_function_le _ _ _) (infi_le _ hs)) (trim_ge _ _)
theorem trim_congr {m₁ m₂ : outer_measure α}
(H : ∀ {s : set α}, is_measurable s → m₁ s = m₂ s) :
m₁.trim = m₂.trim :=
by unfold trim; congr; funext s hs; exact H hs
theorem trim_le_trim {m₁ m₂ : outer_measure α} (H : m₁ ≤ m₂) : m₁.trim ≤ m₂.trim :=
λ s, infi_le_infi $ λ f, infi_le_infi $ λ hs,
ennreal.tsum_le_tsum $ λ b, infi_le_infi $ λ hf, H _
theorem le_trim_iff {m₁ m₂ : outer_measure α} : m₁ ≤ m₂.trim ↔
∀ s, is_measurable s → m₁ s ≤ m₂ s :=
le_of_function.trans $ forall_congr $ λ s, le_infi_iff
theorem trim_eq_infi (s : set α) : m.trim s = ⨅ t (st : s ⊆ t) (ht : is_measurable t), m t :=
begin
refine le_antisymm
(le_infi $ λ t, le_infi $ λ st, le_infi $ λ ht, _)
(le_infi $ λ f, le_infi $ λ hf, _),
{ rw ← trim_eq m ht, exact (trim m).mono st },
{ by_cases h : ∀i, is_measurable (f i),
{ refine infi_le_of_le _ (infi_le_of_le hf $
infi_le_of_le (is_measurable.Union h) _),
rw congr_arg tsum _, {exact m.Union_nat _},
funext i, exact measure'_eq _ _ (h i) },
{ cases not_forall.1 h with i hi,
exact le_trans (le_infi $ λ h, hi.elim h) (ennreal.le_tsum i) } }
end
theorem trim_eq_infi' (s : set α) : m.trim s = ⨅ t : {t // s ⊆ t ∧ is_measurable t}, m t.1 :=
by simp [infi_subtype, infi_and, trim_eq_infi]
theorem trim_trim (m : outer_measure α) : m.trim.trim = m.trim :=
le_antisymm (le_trim_iff.2 $ λ s hs, by simp [trim_eq _ hs]) (trim_ge _)
theorem trim_zero : (0 : outer_measure α).trim = 0 :=
ext $ λ s, le_antisymm
(le_trans ((trim 0).mono (subset_univ s)) $
le_of_eq $ trim_eq _ is_measurable_univ)
(zero_le _)
theorem trim_add (m₁ m₂ : outer_measure α) : (m₁ + m₂).trim = m₁.trim + m₂.trim :=
ext $ λ s, begin
simp [trim_eq_infi'],
rw ennreal.infi_add_infi,
rintro ⟨t₁, st₁, ht₁⟩ ⟨t₂, st₂, ht₂⟩,
exact ⟨⟨_, subset_inter_iff.2 ⟨st₁, st₂⟩, ht₁.inter ht₂⟩,
add_le_add'
(m₁.mono' (inter_subset_left _ _))
(m₂.mono' (inter_subset_right _ _))⟩,
end
theorem trim_sum_ge {ι} (m : ι → outer_measure α) : sum (λ i, (m i).trim) ≤ (sum m).trim :=
λ s, by simp [trim_eq_infi]; exact
λ t st ht, ennreal.tsum_le_tsum (λ i,
infi_le_of_le t $ infi_le_of_le st $ infi_le _ ht)
end outer_measure
structure measure (α : Type*) [measurable_space α] extends outer_measure α :=
(m_Union {f : ℕ → set α} :
(∀i, is_measurable (f i)) → pairwise (disjoint on f) →
measure_of (⋃i, f i) = (∑i, measure_of (f i)))
(trimmed : to_outer_measure.trim = to_outer_measure)
/-- Measure projections for a measure space.
For measurable sets this returns the measure assigned by the `measure_of` field in `measure`.
But we can extend this to _all_ sets, but using the outer measure. This gives us monotonicity and
subadditivity for all sets.
-/
instance {α} [measurable_space α] : has_coe_to_fun (measure α) :=
⟨λ _, set α → ennreal, λ m, m.to_outer_measure⟩
namespace measure
def of_measurable {α} [measurable_space α]
(m : Π (s : set α), is_measurable s → ennreal)
(m0 : m ∅ is_measurable.empty = 0)
(mU : ∀ {f : ℕ → set α} (h : ∀i, is_measurable (f i)),
pairwise (disjoint on f) →
m (⋃i, f i) (is_measurable.Union h) = (∑i, m (f i) (h i))) :
measure α :=
{ m_Union := λ f hf hd,
show outer_measure' m m0 (Union f) =
∑ i, outer_measure' m m0 (f i), begin
rw [outer_measure'_eq m m0 @mU, mU hf hd],
congr, funext n, rw outer_measure'_eq m m0 @mU
end,
trimmed :=
show (outer_measure' m m0).trim = outer_measure' m m0, begin
unfold outer_measure.trim,
congr, funext s hs,
exact outer_measure'_eq m m0 @mU hs
end,
..outer_measure' m m0 }
@[extensionality] lemma ext {α} [measurable_space α] :
∀ {μ₁ μ₂ : measure α}, (∀s, is_measurable s → μ₁ s = μ₂ s) → μ₁ = μ₂
| ⟨m₁, u₁, h₁⟩ ⟨m₂, u₂, h₂⟩ h := by congr; rw [← h₁, ← h₂];
exact outer_measure.trim_congr h
end measure
section
variables {α : Type*} {β : Type*} [measurable_space α] {μ μ₁ μ₂ : measure α} {s s₁ s₂ : set α}
@[simp] lemma to_outer_measure_apply (s) : μ.to_outer_measure s = μ s := rfl
lemma measure_eq_trim (s) : μ s = μ.to_outer_measure.trim s :=
by rw μ.trimmed; refl
lemma measure_eq_infi (s) : μ s = ⨅ t (st : s ⊆ t) (ht : is_measurable t), μ t :=
by rw [measure_eq_trim, outer_measure.trim_eq_infi]; refl
lemma measure_eq_outer_measure' :
μ s = outer_measure' (λ s _, μ s) μ.empty s :=
measure_eq_trim _
lemma to_outer_measure_eq_outer_measure' :
μ.to_outer_measure = outer_measure' (λ s _, μ s) μ.empty :=
μ.trimmed.symm
lemma measure_eq_measure' (hs : is_measurable s) :
μ s = measure' (λ s _, μ s) μ.empty s :=
by rw [measure_eq_outer_measure',
outer_measure'_eq_measure' (λ s _, μ s) _ μ.m_Union hs]
@[simp] lemma measure_empty : μ ∅ = 0 := μ.empty
lemma measure_mono (h : s₁ ⊆ s₂) : μ s₁ ≤ μ s₂ := μ.mono h
lemma measure_mono_null (h : s₁ ⊆ s₂) (h₂ : μ s₂ = 0) : μ s₁ = 0 :=
by rw [← le_zero_iff_eq, ← h₂]; exact measure_mono h
theorem measure_Union_le {β} [encodable β] (s : β → set α) : μ (⋃i, s i) ≤ (∑i, μ (s i)) :=
μ.to_outer_measure.Union _
lemma measure_Union_null {β} [encodable β] {s : β → set α} :
(∀ i, μ (s i) = 0) → μ (⋃i, s i) = 0 :=
μ.to_outer_measure.Union_null
theorem measure_union_le (s₁ s₂ : set α) : μ (s₁ ∪ s₂) ≤ μ s₁ + μ s₂ :=
μ.to_outer_measure.union _ _
lemma measure_union_null {s₁ s₂ : set α} : μ s₁ = 0 → μ s₂ = 0 → μ (s₁ ∪ s₂) = 0 :=
μ.to_outer_measure.union_null
lemma measure_Union {β} [encodable β] {f : β → set α}
(hn : pairwise (disjoint on f)) (h : ∀i, is_measurable (f i)) :
μ (⋃i, f i) = (∑i, μ (f i)) :=
by rw [measure_eq_measure' (is_measurable.Union h),
measure'_Union (λ s _, μ s) _ μ.m_Union hn h];
simp [measure_eq_measure', h]
lemma measure_union (hd : disjoint s₁ s₂) (h₁ : is_measurable s₁) (h₂ : is_measurable s₂) :
μ (s₁ ∪ s₂) = μ s₁ + μ s₂ :=
by rw [measure_eq_measure' (h₁.union h₂),
measure'_union (λ s _, μ s) _ μ.m_Union hd h₁ h₂];
simp [measure_eq_measure', h₁, h₂]
lemma measure_bUnion {s : set β} {f : β → set α} (hs : countable s)
(hd : pairwise_on s (disjoint on f)) (h : ∀b∈s, is_measurable (f b)) :
μ (⋃b∈s, f b) = ∑p:s, μ (f p.1) :=
begin
haveI := hs.to_encodable,
rw [← measure_Union, bUnion_eq_Union],
{ rintro ⟨i, hi⟩ ⟨j, hj⟩ ij x ⟨h₁, h₂⟩,
exact hd i hi j hj (mt subtype.eq' ij:_) ⟨h₁, h₂⟩ },
{ simpa }
end
lemma measure_sUnion [encodable β] {S : set (set α)} (hs : countable S)
(hd : pairwise_on S disjoint) (h : ∀s∈S, is_measurable s) :
μ (⋃₀ S) = ∑s:S, μ s.1 :=
by rw [sUnion_eq_bUnion, measure_bUnion hs hd h]
lemma measure_diff {s₁ s₂ : set α} (h : s₂ ⊆ s₁)
(h₁ : is_measurable s₁) (h₂ : is_measurable s₂)
(h_fin : μ s₂ < ⊤) : μ (s₁ \ s₂) = μ s₁ - μ s₂ :=
begin
refine (ennreal.add_sub_self' h_fin).symm.trans _,
rw [← measure_union disjoint_diff h₂ (h₁.diff h₂), union_diff_cancel h]
end
lemma measure_Union_eq_supr_nat {s : ℕ → set α} (h : ∀i, is_measurable (s i)) (hs : monotone s) :
μ (⋃i, s i) = (⨆i, μ (s i)) :=
begin
refine le_antisymm _ (supr_le $ λ i, measure_mono $ subset_Union _ _),
rw [← Union_disjointed,
measure_Union disjoint_disjointed (is_measurable.disjointed h),
ennreal.tsum_eq_supr_nat],
refine supr_le (λ n, _),
cases n, {apply zero_le},
suffices : sum (finset.range n.succ) (λ i, μ (disjointed s i)) = μ (s n),
{ rw this, exact le_supr _ n },
rw [← Union_disjointed_of_mono hs, measure_Union, tsum_eq_sum],
{ apply sum_congr rfl, intros i hi,
simp [finset.mem_range.1 hi] },
{ intros i hi, simp [mt finset.mem_range.2 hi] },
{ rintro i j ij x ⟨⟨_, ⟨_, rfl⟩, h₁⟩, ⟨_, ⟨_, rfl⟩, h₂⟩⟩,
exact disjoint_disjointed i j ij ⟨h₁, h₂⟩ },
{ intro i,
by_cases h' : i < n.succ; simp [h', is_measurable.empty],
apply is_measurable.disjointed h }
end
lemma measure_Inter_eq_infi_nat {s : ℕ → set α}
(h : ∀i, is_measurable (s i)) (hs : ∀i j, i ≤ j → s j ⊆ s i)
(hfin : ∃i, μ (s i) < ⊤) :
μ (⋂i, s i) = (⨅i, μ (s i)) :=
begin
rcases hfin with ⟨k, hk⟩,
rw [← ennreal.sub_sub_cancel (by exact hk) (infi_le _ k),
ennreal.sub_infi,
← ennreal.sub_sub_cancel (by exact hk) (measure_mono (Inter_subset _ k)),
← measure_diff (Inter_subset _ k) (h k) (is_measurable.Inter h)
(lt_of_le_of_lt (measure_mono (Inter_subset _ k)) hk),
diff_Inter_left, measure_Union_eq_supr_nat],
{ congr, funext i,
cases le_total k i with ik ik,
{ exact measure_diff (hs _ _ ik) (h k) (h i)
(lt_of_le_of_lt (measure_mono (hs _ _ ik)) hk) },
{ rw [diff_eq_empty.2 (hs _ _ ik), measure_empty,
ennreal.sub_eq_zero_of_le (measure_mono (hs _ _ ik))] } },
{ exact λ i, (h k).diff (h i) },
{ exact λ i j ij, diff_subset_diff_right (hs _ _ ij) }
end
end
def outer_measure.to_measure {α} (m : outer_measure α)
[ms : measurable_space α] (h : ms ≤ m.caratheodory) :
measure α :=
measure.of_measurable (λ s _, m s) m.empty
(λ f hf hd, m.Union_eq_of_caratheodory (λ i, h _ (hf i)) hd)
lemma le_to_outer_measure_caratheodory {α} [ms : measurable_space α]
(μ : measure α) : ms ≤ μ.to_outer_measure.caratheodory :=
λ s hs, begin
rw to_outer_measure_eq_outer_measure',
refine outer_measure.caratheodory_is_measurable (λ t, le_infi $ λ ht, _),
rw [← measure_eq_measure' (ht.inter hs),
← measure_eq_measure' (ht.diff hs),
← measure_union _ (ht.inter hs) (ht.diff hs),
inter_union_diff],
exact λ x ⟨⟨_, h₁⟩, _, h₂⟩, h₂ h₁
end
lemma to_measure_to_outer_measure {α} (m : outer_measure α)
[ms : measurable_space α] (h : ms ≤ m.caratheodory) :
(m.to_measure h).to_outer_measure = m.trim := rfl
@[simp] lemma to_measure_apply {α} (m : outer_measure α)
[ms : measurable_space α] (h : ms ≤ m.caratheodory)
{s : set α} (hs : is_measurable s) :
m.to_measure h s = m s := m.trim_eq hs
lemma to_outer_measure_to_measure {α : Type*} [ms : measurable_space α] {μ : measure α} :
μ.to_outer_measure.to_measure (le_to_outer_measure_caratheodory _) = μ :=
measure.ext $ λ s, μ.to_outer_measure.trim_eq
namespace measure
variables {α : Type*} {β : Type*} {γ : Type*}
[measurable_space α] [measurable_space β] [measurable_space γ]
instance : has_zero (measure α) :=
⟨{ to_outer_measure := 0,
m_Union := λ f hf hd, tsum_zero.symm,
trimmed := outer_measure.trim_zero }⟩
@[simp] theorem zero_to_outer_measure :
(0 : measure α).to_outer_measure = 0 := rfl
@[simp] theorem zero_apply (s : set α) : (0 : measure α) s = 0 := rfl
instance : inhabited (measure α) := ⟨0⟩
instance : has_add (measure α) :=
⟨λμ₁ μ₂, {
to_outer_measure := μ₁.to_outer_measure + μ₂.to_outer_measure,
m_Union := λs hs hd,
show μ₁ (⋃ i, s i) + μ₂ (⋃ i, s i) = ∑ i, μ₁ (s i) + μ₂ (s i),
by rw [ennreal.tsum_add, measure_Union hd hs, measure_Union hd hs],
trimmed := by rw [outer_measure.trim_add, μ₁.trimmed, μ₂.trimmed] }⟩
@[simp] theorem add_to_outer_measure (μ₁ μ₂ : measure α) :
(μ₁ + μ₂).to_outer_measure = μ₁.to_outer_measure + μ₂.to_outer_measure := rfl
@[simp] theorem add_apply (μ₁ μ₂ : measure α) (s : set α) :
(μ₁ + μ₂) s = μ₁ s + μ₂ s := rfl
instance : add_comm_monoid (measure α) :=
{ zero := 0,
add := (+),
add_assoc := assume a b c, ext $ assume s hs, add_assoc _ _ _,
add_comm := assume a b, ext $ assume s hs, add_comm _ _,
zero_add := assume a, ext $ assume s hs, zero_add _,
add_zero := assume a, ext $ assume s hs, add_zero _ }
instance : partial_order (measure α) :=
{ le := λm₁ m₂, ∀ s, is_measurable s → m₁ s ≤ m₂ s,
le_refl := assume m s hs, le_refl _,
le_trans := assume m₁ m₂ m₃ h₁ h₂ s hs, le_trans (h₁ s hs) (h₂ s hs),
le_antisymm := assume m₁ m₂ h₁ h₂, ext $
assume s hs, le_antisymm (h₁ s hs) (h₂ s hs) }
theorem le_iff {μ₁ μ₂ : measure α} :
μ₁ ≤ μ₂ ↔ ∀ s, is_measurable s → μ₁ s ≤ μ₂ s := iff.rfl
theorem to_outer_measure_le {μ₁ μ₂ : measure α} :
μ₁.to_outer_measure ≤ μ₂.to_outer_measure ↔ μ₁ ≤ μ₂ :=
by rw [← μ₂.trimmed, outer_measure.le_trim_iff]; refl
theorem le_iff' {μ₁ μ₂ : measure α} :
μ₁ ≤ μ₂ ↔ ∀ s, μ₁ s ≤ μ₂ s :=
to_outer_measure_le.symm
def map (f : α → β) (μ : measure α) : measure β :=
if hf : measurable f then
(μ.to_outer_measure.map f).to_measure $ λ s hs t,
le_to_outer_measure_caratheodory μ _ (hf _ hs) (f ⁻¹' t)
else 0
variables {μ : measure α}
@[simp] theorem map_apply {f : α → β} (hf : measurable f)
{s : set β} (hs : is_measurable s) :
(map f μ : measure β) s = μ (f ⁻¹' s) :=
by rw [map, dif_pos hf, to_measure_apply _ _ hs]; refl
@[simp] lemma map_id : map id μ = μ :=
ext $ λ s, map_apply measurable_id
lemma map_map {f : α → β} {g : β → γ} (hf : measurable f) (hg : measurable g) :
map g (map f μ) = map (g ∘ f) μ :=
ext $ λ s hs,
by simp [hf, hg, hs, hg.preimage hs, hf.comp hg];
rw ← preimage_comp
/-- The dirac measure. -/
def dirac (a : α) : measure α :=
(outer_measure.dirac a).to_measure (by simp)
@[simp] lemma dirac_apply (a : α) {s : set α} (hs : is_measurable s) :
(dirac a : measure α) s = ⨆ h : a ∈ s, 1 :=
to_measure_apply _ _ hs
/-- Sum of an indexed family of measures. -/
def sum {ι : Type*} (f : ι → measure α) : measure α :=
(outer_measure.sum (λ i, (f i).to_outer_measure)).to_measure $
le_trans
(by exact le_infi (λ i, le_to_outer_measure_caratheodory _))
(outer_measure.le_sum_caratheodory _)
/-- Counting measure on any measurable space. -/
def count : measure α := sum dirac
@[class] def is_complete {α} {_:measurable_space α} (μ : measure α) : Prop :=
∀ s, μ s = 0 → is_measurable s
end measure
end measure_theory
section is_complete
open measure_theory
variables {α : Type*} [measurable_space α] (μ : measure α)
def is_null_measurable (s : set α) : Prop :=
∃ t z, s = t ∪ z ∧ is_measurable t ∧ μ z = 0
theorem is_null_measurable_iff {μ : measure α} {s : set α} :
is_null_measurable μ s ↔
∃ t, t ⊆ s ∧ is_measurable t ∧ μ (s \ t) = 0 :=
begin
split,
{ rintro ⟨t, z, rfl, ht, hz⟩,
refine ⟨t, set.subset_union_left _ _, ht, measure_mono_null _ hz⟩,
simp [union_diff_left, diff_subset] },
{ rintro ⟨t, st, ht, hz⟩,
exact ⟨t, _, (union_diff_cancel st).symm, ht, hz⟩ }
end
theorem is_null_measurable_measure_eq {μ : measure α} {s t : set α}
(st : t ⊆ s) (hz : μ (s \ t) = 0) : μ s = μ t :=
begin
refine le_antisymm _ (measure_mono st),
have := measure_union_le t (s \ t),
rw [union_diff_cancel st, hz] at this, simpa
end
theorem is_measurable.is_null_measurable
{s : set α} (hs : is_measurable s) : is_null_measurable μ s :=
⟨s, ∅, by simp, hs, μ.empty⟩
theorem is_null_measurable_of_complete [c : μ.is_complete]
{s : set α} : is_null_measurable μ s ↔ is_measurable s :=
⟨by rintro ⟨t, z, rfl, ht, hz⟩; exact
is_measurable.union ht (c _ hz),
λ h, h.is_null_measurable _⟩
variables {μ}
theorem is_null_measurable.union_null {s z : set α}
(hs : is_null_measurable μ s) (hz : μ z = 0) :
is_null_measurable μ (s ∪ z) :=
begin
rcases hs with ⟨t, z', rfl, ht, hz'⟩,
exact ⟨t, z' ∪ z, set.union_assoc _ _ _, ht, le_zero_iff_eq.1
(le_trans (measure_union_le _ _) $ by simp [hz, hz'])⟩
end
theorem null_is_null_measurable {z : set α}
(hz : μ z = 0) : is_null_measurable μ z :=
by simpa using (is_measurable.empty.is_null_measurable _).union_null hz
theorem is_null_measurable.Union_nat {s : ℕ → set α}
(hs : ∀ i, is_null_measurable μ (s i)) :
is_null_measurable μ (Union s) :=
begin
cases axiom_of_choice
(λ i, is_null_measurable_iff.1 (hs i) : _) with t ht,
dsimp at t ht, simp [forall_and_distrib] at ht,
rcases ht with ⟨st, ht, hz⟩,
refine is_null_measurable_iff.2
⟨Union t, Union_subset_Union st, is_measurable.Union ht,
measure_mono_null _ (measure_Union_null hz)⟩,
rw [diff_subset_iff, ← Union_union_distrib],
exact Union_subset_Union (λ i, by rw ← diff_subset_iff)
end
theorem is_measurable.diff_null {s z : set α}
(hs : is_measurable s) (hz : μ z = 0) :
is_null_measurable μ (s \ z) :=
begin
rw measure_eq_infi at hz,
have : ∀ q : {q:ℚ//q>0}, ∃ t:set α,
z ⊆ t ∧ is_measurable t ∧ μ t < ennreal.of_real q.1,
{ rintro ⟨ε, ε0⟩,
have : 0 < ennreal.of_real ε, {simpa using ε0},
rw ← hz at this, simpa [infi_lt_iff] },
rcases axiom_of_choice this with ⟨f, hf⟩,
dsimp at f hf,
refine is_null_measurable_iff.2 ⟨s \ Inter f,
diff_subset_diff_right (subset_Inter (λ i, (hf i).1)),
hs.diff (is_measurable.Inter (λ i, (hf i).2.1)),
measure_mono_null _ (le_zero_iff_eq.1 $ le_of_not_lt $ λ h, _)⟩,
{ exact Inter f },
{ rw [diff_subset_iff, diff_union_self],
exact subset.trans (diff_subset _ _) (subset_union_left _ _) },
rcases ennreal.lt_iff_exists_rat_btwn.1 h with ⟨ε, ε0', ε0, h⟩,
simp at ε0,
apply not_le_of_lt (lt_trans (hf ⟨ε, ε0⟩).2.2 h),
exact measure_mono (Inter_subset _ _)
end
theorem is_null_measurable.diff_null {s z : set α}
(hs : is_null_measurable μ s) (hz : μ z = 0) :
is_null_measurable μ (s \ z) :=
begin
rcases hs with ⟨t, z', rfl, ht, hz'⟩,
rw [set.union_diff_distrib],
exact (ht.diff_null hz).union_null (measure_mono_null (diff_subset _ _) hz')
end
theorem is_null_measurable.compl {s : set α}
(hs : is_null_measurable μ s) :
is_null_measurable μ (-s) :=
begin
rcases hs with ⟨t, z, rfl, ht, hz⟩,
rw compl_union,
exact ht.compl.diff_null hz
end
def null_measurable {α : Type u} [measurable_space α]
(μ : measure α) : measurable_space α :=
{ is_measurable := is_null_measurable μ,
is_measurable_empty := is_measurable.empty.is_null_measurable _,
is_measurable_compl := λ s hs, hs.compl,
is_measurable_Union := λ f, is_null_measurable.Union_nat }
def completion {α : Type u} [measurable_space α] (μ : measure α) :
@measure_theory.measure α (null_measurable μ) :=
{ to_outer_measure := μ.to_outer_measure,
m_Union := λ s hs hd, show μ (Union s) = ∑ i, μ (s i), begin
rcases axiom_of_choice (λ i, is_null_measurable_iff.1 (hs i):_) with ⟨t, ht⟩,
dsimp at t ht, simp [forall_and_distrib] at ht, rcases ht with ⟨st, ht, hz⟩,
rw is_null_measurable_measure_eq (Union_subset_Union st),
{ rw measure_Union _ ht,
{ congr, funext i,
exact (is_null_measurable_measure_eq (st i) (hz i)).symm },
{ rintro i j ij x ⟨h₁, h₂⟩,
exact hd i j ij ⟨st i h₁, st j h₂⟩ } },
{ refine measure_mono_null _ (measure_Union_null hz),
rw [diff_subset_iff, ← Union_union_distrib],
exact Union_subset_Union (λ i, by rw ← diff_subset_iff) }
end,
trimmed := begin
letI := null_measurable μ,
refine le_antisymm (λ s, _) (outer_measure.trim_ge _),
rw outer_measure.trim_eq_infi,
dsimp, clear _inst,
rw measure_eq_infi s,
exact infi_le_infi (λ t, infi_le_infi $ λ st,
infi_le_infi2 $ λ ht, ⟨ht.is_null_measurable _, le_refl _⟩)
end }
instance completion.is_complete {α : Type u} [measurable_space α] (μ : measure α) :
(completion μ).is_complete :=
λ z hz, null_is_null_measurable hz
end is_complete
|
ad5401e52daa6d0bf6b4fd914f17f706f72cdcf7 | a9d0fb7b0e4f802bd3857b803e6c5c23d87fef91 | /tests/lean/run/def_brec3.lean | 6a4b6d81b37d0e76e9eb9163cbdc32f84fb943d6 | [
"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 | 504 | lean | open nat
inductive bv : nat → Type
| nil : bv 0
| cons : ∀ (n) (hd : bool) (tl : bv n), bv (succ n)
open bv
variable (f : bool → bool → bool)
definition map2 : ∀ {n}, bv n → bv n → bv n
| .0 nil nil := nil
| .(n+1) (cons n b1 v1) (cons .n b2 v2) := cons n (f b1 b2) (map2 v1 v2)
example : map2 f nil nil = nil :=
rfl
example (n : nat) (b1 b2 : bool) (v1 v2 : bv n) : map2 f (cons n b1 v1) (cons n b2 v2) = cons n (f b1 b2) (map2 f v1 v2) :=
rfl
print map2
|
a3b4fe425c9a49e3608a3a09ef268dad19ba83a4 | cf39355caa609c0f33405126beee2739aa3cb77e | /tests/lean/t13.lean | d0be9f25af5a2678337c8d11e8a461dbbffd24bf | [
"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 | 353 | lean | prelude constant A : Type.{1}
constant f : A → A → A
constant g : A → A → A
precedence `+` : 65
infixl (name := f) + := f
infixl (name := g) + := g
constant a : A
constant b : A
#print raw a+b -- + is overloaded
#check fun (h : A → A → A)
(infixl + := h), -- Like local declarations, local notation "shadows" global one.
a+b
|
2397c218565cfea419b1096991431eccc9210a53 | 3f7026ea8bef0825ca0339a275c03b911baef64d | /src/category_theory/isomorphism.lean | 0a3c64e5dcb40784fa3c04acce680673e540520a | [
"Apache-2.0"
] | permissive | rspencer01/mathlib | b1e3afa5c121362ef0881012cc116513ab09f18c | c7d36292c6b9234dc40143c16288932ae38fdc12 | refs/heads/master | 1,595,010,346,708 | 1,567,511,503,000 | 1,567,511,503,000 | 206,071,681 | 0 | 0 | Apache-2.0 | 1,567,513,643,000 | 1,567,513,643,000 | null | UTF-8 | Lean | false | false | 10,300 | lean | /-
Copyright (c) 2017 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Tim Baumann, Stephen Morgan, Scott Morrison, Floris van Doorn
-/
import category_theory.functor
import tactic.reassoc_axiom
/-!
# Isomorphisms
This file defines isomorphisms between objects of a category.
## Main definitions
- `structure iso` : a bundled isomorphism between two objects of a category;
- `class is_iso` : an unbundled version of `iso`; note that `is_iso f` is usually *not* a `Prop`,
because it holds the inverse morphism;
- `as_iso` : convert from `is_iso` to `iso`;
- `of_iso` : convert from `iso` to `is_iso`;
- standard operations on isomorphisms (composition, inverse etc)
## Notations
- `X ≅ Y` : same as `iso X Y`;
- `α ≪≫ β` : composition of two isomorphisms; it is called `iso.trans`
## Tags
category, category theory, isomorphism
-/
universes v u -- declare the `v`'s first; see `category_theory.category` for an explanation
namespace category_theory
open category
structure iso {C : Type u} [category.{v} C] (X Y : C) :=
(hom : X ⟶ Y)
(inv : Y ⟶ X)
(hom_inv_id' : hom ≫ inv = 𝟙 X . obviously)
(inv_hom_id' : inv ≫ hom = 𝟙 Y . obviously)
restate_axiom iso.hom_inv_id'
restate_axiom iso.inv_hom_id'
attribute [simp, reassoc] iso.hom_inv_id iso.inv_hom_id
infixr ` ≅ `:10 := iso -- type as \cong or \iso
variables {C : Type u} [𝒞 : category.{v} C]
include 𝒞
variables {X Y Z : C}
namespace iso
@[extensionality] lemma ext (α β : X ≅ Y) (w : α.hom = β.hom) : α = β :=
suffices α.inv = β.inv, by cases α; cases β; cc,
calc α.inv
= α.inv ≫ (β.hom ≫ β.inv) : by rw [iso.hom_inv_id, category.comp_id]
... = (α.inv ≫ α.hom) ≫ β.inv : by rw [category.assoc, ←w]
... = β.inv : by rw [iso.inv_hom_id, category.id_comp]
@[symm] def symm (I : X ≅ Y) : Y ≅ X :=
{ hom := I.inv,
inv := I.hom,
hom_inv_id' := I.inv_hom_id',
inv_hom_id' := I.hom_inv_id' }
@[simp] lemma symm_hom (α : X ≅ Y) : α.symm.hom = α.inv := rfl
@[simp] lemma symm_inv (α : X ≅ Y) : α.symm.inv = α.hom := rfl
@[simp] lemma symm_mk {X Y : C} (hom : X ⟶ Y) (inv : Y ⟶ X) (hom_inv_id) (inv_hom_id) :
iso.symm {hom := hom, inv := inv, hom_inv_id' := hom_inv_id, inv_hom_id' := inv_hom_id} =
{hom := inv, inv := hom, hom_inv_id' := inv_hom_id, inv_hom_id' := hom_inv_id} := rfl
@[simp] lemma symm_symm_eq {X Y : C} (α : X ≅ Y) : α.symm.symm = α :=
by cases α; refl
@[simp] lemma symm_eq_iff {X Y : C} {α β : X ≅ Y} : α.symm = β.symm ↔ α = β :=
⟨λ h, symm_symm_eq α ▸ symm_symm_eq β ▸ congr_arg symm h, congr_arg symm⟩
@[refl] def refl (X : C) : X ≅ X :=
{ hom := 𝟙 X,
inv := 𝟙 X }
@[simp] lemma refl_hom (X : C) : (iso.refl X).hom = 𝟙 X := rfl
@[simp] lemma refl_inv (X : C) : (iso.refl X).inv = 𝟙 X := rfl
@[simp] lemma refl_symm (X : C) : (iso.refl X).symm = iso.refl X := rfl
@[trans] def trans (α : X ≅ Y) (β : Y ≅ Z) : X ≅ Z :=
{ hom := α.hom ≫ β.hom,
inv := β.inv ≫ α.inv }
infixr ` ≪≫ `:80 := iso.trans -- type as `\ll \gg`.
@[simp] lemma trans_hom (α : X ≅ Y) (β : Y ≅ Z) : (α ≪≫ β).hom = α.hom ≫ β.hom := rfl
@[simp] lemma trans_inv (α : X ≅ Y) (β : Y ≅ Z) : (α ≪≫ β).inv = β.inv ≫ α.inv := rfl
@[simp] lemma trans_mk {X Y Z : C}
(hom : X ⟶ Y) (inv : Y ⟶ X) (hom_inv_id) (inv_hom_id)
(hom' : Y ⟶ Z) (inv' : Z ⟶ Y) (hom_inv_id') (inv_hom_id') (hom_inv_id'') (inv_hom_id'') :
iso.trans
{hom := hom, inv := inv, hom_inv_id' := hom_inv_id, inv_hom_id' := inv_hom_id}
{hom := hom', inv := inv', hom_inv_id' := hom_inv_id', inv_hom_id' := inv_hom_id'} =
{hom := hom ≫ hom', inv := inv' ≫ inv, hom_inv_id' := hom_inv_id'', inv_hom_id' := inv_hom_id''} :=
rfl
@[simp] lemma trans_symm (α : X ≅ Y) (β : Y ≅ Z) : (α ≪≫ β).symm = β.symm ≪≫ α.symm := rfl
@[simp] lemma trans_assoc {Z' : C} (α : X ≅ Y) (β : Y ≅ Z) (γ : Z ≅ Z') :
(α ≪≫ β) ≪≫ γ = α ≪≫ β ≪≫ γ :=
by ext; simp only [trans_hom, category.assoc]
@[simp] lemma refl_trans (α : X ≅ Y) : (iso.refl X) ≪≫ α = α := by ext; apply category.id_comp
@[simp] lemma trans_refl (α : X ≅ Y) : α ≪≫ (iso.refl Y) = α := by ext; apply category.comp_id
@[simp] lemma symm_self_id (α : X ≅ Y) : α.symm ≪≫ α = iso.refl Y := ext _ _ α.inv_hom_id
@[simp] lemma self_symm_id (α : X ≅ Y) : α ≪≫ α.symm = iso.refl X := ext _ _ α.hom_inv_id
@[simp] lemma symm_self_id_assoc (α : X ≅ Y) (β : Y ≅ Z) : α.symm ≪≫ α ≪≫ β = β :=
by rw [← trans_assoc, symm_self_id, refl_trans]
@[simp] lemma self_symm_id_assoc (α : X ≅ Y) (β : X ≅ Z) : α ≪≫ α.symm ≪≫ β = β :=
by rw [← trans_assoc, self_symm_id, refl_trans]
lemma inv_comp_eq (α : X ≅ Y) {f : X ⟶ Z} {g : Y ⟶ Z} : α.inv ≫ f = g ↔ f = α.hom ≫ g :=
⟨λ H, by simp [H.symm], λ H, by simp [H]⟩
lemma eq_inv_comp (α : X ≅ Y) {f : X ⟶ Z} {g : Y ⟶ Z} : g = α.inv ≫ f ↔ α.hom ≫ g = f :=
(inv_comp_eq α.symm).symm
lemma comp_inv_eq (α : X ≅ Y) {f : Z ⟶ Y} {g : Z ⟶ X} : f ≫ α.inv = g ↔ f = g ≫ α.hom :=
⟨λ H, by simp [H.symm], λ H, by simp [H]⟩
lemma eq_comp_inv (α : X ≅ Y) {f : Z ⟶ Y} {g : Z ⟶ X} : g = f ≫ α.inv ↔ g ≫ α.hom = f :=
(comp_inv_eq α.symm).symm
lemma inv_eq_inv (f g : X ≅ Y) : f.inv = g.inv ↔ f.hom = g.hom :=
have ∀{X Y : C} (f g : X ≅ Y), f.hom = g.hom → f.inv = g.inv, from λ X Y f g h, by rw [ext _ _ h],
⟨this f.symm g.symm, this f g⟩
lemma hom_comp_eq_id (α : X ≅ Y) {f : Y ⟶ X} : α.hom ≫ f = 𝟙 X ↔ f = α.inv :=
by rw [←eq_inv_comp, comp_id]
lemma comp_hom_eq_id (α : X ≅ Y) {f : Y ⟶ X} : f ≫ α.hom = 𝟙 Y ↔ f = α.inv :=
by rw [←eq_comp_inv, id_comp]
lemma hom_eq_inv (α : X ≅ Y) (β : Y ≅ X) : α.hom = β.inv ↔ β.hom = α.inv :=
by { erw [inv_eq_inv α.symm β, eq_comm], refl }
end iso
/-- `is_iso` typeclass expressing that a morphism is invertible.
This contains the data of the inverse, but is a subsingleton type. -/
class is_iso (f : X ⟶ Y) :=
(inv : Y ⟶ X)
(hom_inv_id' : f ≫ inv = 𝟙 X . obviously)
(inv_hom_id' : inv ≫ f = 𝟙 Y . obviously)
export is_iso (inv)
def as_iso (f : X ⟶ Y) [h : is_iso f] : X ≅ Y := { hom := f, ..h }
@[simp] lemma as_iso_hom (f : X ⟶ Y) [is_iso f] : (as_iso f).hom = f := rfl
@[simp] lemma as_iso_inv (f : X ⟶ Y) [is_iso f] : (as_iso f).inv = inv f := rfl
namespace is_iso
@[simp] lemma hom_inv_id (f : X ⟶ Y) [is_iso f] : f ≫ inv f = 𝟙 X :=
is_iso.hom_inv_id' f
@[simp] lemma inv_hom_id (f : X ⟶ Y) [is_iso f] : inv f ≫ f = 𝟙 Y :=
is_iso.inv_hom_id' f
@[simp] lemma hom_inv_id_assoc {Z} (f : X ⟶ Y) [is_iso f] (g : X ⟶ Z) :
f ≫ inv f ≫ g = g :=
(as_iso f).hom_inv_id_assoc g
@[simp] lemma inv_hom_id_assoc {Z} (f : X ⟶ Y) [is_iso f] (g : Y ⟶ Z) :
inv f ≫ f ≫ g = g :=
(as_iso f).inv_hom_id_assoc g
instance (X : C) : is_iso (𝟙 X) :=
{ inv := 𝟙 X }
instance of_iso (f : X ≅ Y) : is_iso f.hom :=
{ .. f }
instance of_iso_inverse (f : X ≅ Y) : is_iso f.inv :=
is_iso.of_iso f.symm
variables {f g : X ⟶ Y} {h : Y ⟶ Z}
instance inv_is_iso [is_iso f] : is_iso (inv f) :=
is_iso.of_iso_inverse (as_iso f)
instance comp_is_iso [is_iso f] [is_iso h] : is_iso (f ≫ h) :=
is_iso.of_iso $ (as_iso f) ≪≫ (as_iso h)
@[simp] lemma inv_id : inv (𝟙 X) = 𝟙 X := rfl
@[simp] lemma inv_comp [is_iso f] [is_iso h] : inv (f ≫ h) = inv h ≫ inv f := rfl
@[simp] lemma is_iso.inv_inv [is_iso f] : inv (inv f) = f := rfl
@[simp] lemma iso.inv_inv (f : X ≅ Y) : inv (f.inv) = f.hom := rfl
@[simp] lemma iso.inv_hom (f : X ≅ Y) : inv (f.hom) = f.inv := rfl
instance epi_of_iso (f : X ⟶ Y) [is_iso f] : epi f :=
{ left_cancellation := λ Z g h w,
-- This is an interesting test case for better rewrite automation.
by rw [← is_iso.inv_hom_id_assoc f g, w, is_iso.inv_hom_id_assoc f h] }
instance mono_of_iso (f : X ⟶ Y) [is_iso f] : mono f :=
{ right_cancellation := λ Z g h w,
by rw [←category.comp_id C g, ←category.comp_id C h, ←is_iso.hom_inv_id f, ←category.assoc, w, ←category.assoc] }
end is_iso
open is_iso
lemma eq_of_inv_eq_inv {f g : X ⟶ Y} [is_iso f] [is_iso g] (p : inv f = inv g) : f = g :=
begin
apply (cancel_epi (inv f)).1,
erw [inv_hom_id, p, inv_hom_id],
end
instance (f : X ⟶ Y) : subsingleton (is_iso f) :=
⟨λ a b,
suffices a.inv = b.inv, by cases a; cases b; congr; exact this,
show (@as_iso C _ _ _ f a).inv = (@as_iso C _ _ _ f b).inv,
by congr' 1; ext; refl⟩
lemma is_iso.inv_eq_inv {f g : X ⟶ Y} [is_iso f] [is_iso g] : inv f = inv g ↔ f = g :=
iso.inv_eq_inv (as_iso f) (as_iso g)
namespace functor
universes u₁ v₁ u₂ v₂
variables {D : Type u₂}
variables [𝒟 : category.{v₂} D]
include 𝒟
def map_iso (F : C ⥤ D) {X Y : C} (i : X ≅ Y) : F.obj X ≅ F.obj Y :=
{ hom := F.map i.hom,
inv := F.map i.inv,
hom_inv_id' := by rw [←map_comp, iso.hom_inv_id, ←map_id],
inv_hom_id' := by rw [←map_comp, iso.inv_hom_id, ←map_id] }
@[simp] lemma map_iso_hom (F : C ⥤ D) {X Y : C} (i : X ≅ Y) : (F.map_iso i).hom = F.map i.hom := rfl
@[simp] lemma map_iso_inv (F : C ⥤ D) {X Y : C} (i : X ≅ Y) : (F.map_iso i).inv = F.map i.inv := rfl
@[simp] lemma map_iso_symm (F : C ⥤ D) {X Y : C} (i : X ≅ Y) :
F.map_iso i.symm = (F.map_iso i).symm :=
rfl
@[simp] lemma map_iso_trans (F : C ⥤ D) {X Y Z : C} (i : X ≅ Y) (j : Y ≅ Z) :
F.map_iso (i ≪≫ j) = (F.map_iso i) ≪≫ (F.map_iso j) :=
by ext; apply functor.map_comp
instance map_is_iso (F : C ⥤ D) (f : X ⟶ Y) [is_iso f] : is_iso (F.map f) :=
is_iso.of_iso $ F.map_iso (as_iso f)
@[simp] lemma map_inv (F : C ⥤ D) {X Y : C} (f : X ⟶ Y) [is_iso f] :
F.map (inv f) = inv (F.map f) :=
rfl
@[simp] lemma map_hom_inv (F : C ⥤ D) {X Y : C} (f : X ⟶ Y) [is_iso f] :
F.map f ≫ F.map (inv f) = 𝟙 (F.obj X) :=
by rw [map_inv, is_iso.hom_inv_id]
@[simp] lemma map_inv_hom (F : C ⥤ D) {X Y : C} (f : X ⟶ Y) [is_iso f] :
F.map (inv f) ≫ F.map f = 𝟙 (F.obj Y) :=
by rw [map_inv, is_iso.inv_hom_id]
end functor
end category_theory
|
5e6db80aa99960a796032939f611c22fe9e93168 | 9dc8cecdf3c4634764a18254e94d43da07142918 | /src/topology/local_at_target.lean | 8506d806e0a7b7d0ae22c1509844ee226685b82e | [
"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 | 4,697 | 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 topology.sets.opens
/-!
# Properties of maps that are local at the target.
We show that the following properties of continuous maps are local at the target :
- `inducing`
- `embedding`
- `open_embedding`
- `closed_embedding`
-/
open topological_space set filter
open_locale topological_space filter
variables {α β : Type*} [topological_space α] [topological_space β] {f : α → β}
variables {s : set β} {ι : Type*} {U : ι → opens β} (hU : supr U = ⊤)
lemma set.restrict_preimage_inducing (s : set β) (h : inducing f) :
inducing (s.restrict_preimage f) :=
begin
simp_rw [inducing_coe.inducing_iff, inducing_iff_nhds, restrict_preimage, maps_to.coe_restrict,
restrict_eq, ← @filter.comap_comap _ _ _ _ coe f] at h ⊢,
intros a,
rw [← h, ← inducing_coe.nhds_eq_comap],
end
alias set.restrict_preimage_inducing ← inducing.restrict_preimage
lemma set.restrict_preimage_embedding (s : set β) (h : embedding f) :
embedding (s.restrict_preimage f) :=
⟨h.1.restrict_preimage s, h.2.restrict_preimage s⟩
alias set.restrict_preimage_embedding ← embedding.restrict_preimage
lemma set.restrict_preimage_open_embedding (s : set β) (h : open_embedding f) :
open_embedding (s.restrict_preimage f) :=
⟨h.1.restrict_preimage s,
(s.range_restrict_preimage f).symm ▸ continuous_subtype_coe.is_open_preimage _ h.2⟩
alias set.restrict_preimage_open_embedding ← open_embedding.restrict_preimage
lemma set.restrict_preimage_closed_embedding (s : set β) (h : closed_embedding f) :
closed_embedding (s.restrict_preimage f) :=
⟨h.1.restrict_preimage s,
(s.range_restrict_preimage f).symm ▸ inducing_coe.is_closed_preimage _ h.2⟩
alias set.restrict_preimage_closed_embedding ← closed_embedding.restrict_preimage
include hU
lemma open_iff_inter_of_supr_eq_top (s : set β) :
is_open s ↔ ∀ i, is_open (s ∩ U i) :=
begin
split,
{ exact λ H i, H.inter (U i).2 },
{ intro H,
have : (⋃ i, (U i : set β)) = set.univ := by { convert (congr_arg coe hU), simp },
rw [← s.inter_univ, ← this, set.inter_Union],
exact is_open_Union H }
end
lemma open_iff_coe_preimage_of_supr_eq_top (s : set β) :
is_open s ↔ ∀ i, is_open (coe ⁻¹' s : set (U i)) :=
begin
simp_rw [(U _).2.open_embedding_subtype_coe.open_iff_image_open,
set.image_preimage_eq_inter_range, subtype.range_coe],
apply open_iff_inter_of_supr_eq_top,
assumption
end
lemma closed_iff_coe_preimage_of_supr_eq_top (s : set β) :
is_closed s ↔ ∀ i, is_closed (coe ⁻¹' s : set (U i)) :=
by simpa using open_iff_coe_preimage_of_supr_eq_top hU sᶜ
lemma inducing_iff_inducing_of_supr_eq_top (h : continuous f) :
inducing f ↔ ∀ i, inducing ((U i).1.restrict_preimage f) :=
begin
simp_rw [inducing_coe.inducing_iff, inducing_iff_nhds, restrict_preimage, maps_to.coe_restrict,
restrict_eq, ← @filter.comap_comap _ _ _ _ coe f],
split,
{ intros H i x, rw [← H, ← inducing_coe.nhds_eq_comap] },
{ intros H x,
obtain ⟨i, hi⟩ := opens.mem_supr.mp (show f x ∈ supr U, by { rw hU, triv }),
erw ← open_embedding.map_nhds_eq (h.1 _ (U i).2).open_embedding_subtype_coe ⟨x, hi⟩,
rw [(H i) ⟨x, hi⟩, filter.subtype_coe_map_comap, function.comp_apply, subtype.coe_mk,
inf_eq_left, filter.le_principal_iff],
exact filter.preimage_mem_comap ((U i).2.mem_nhds hi) }
end
lemma embedding_iff_embedding_of_supr_eq_top (h : continuous f) :
embedding f ↔ ∀ i, embedding ((U i).1.restrict_preimage f) :=
begin
simp_rw embedding_iff,
rw forall_and_distrib,
apply and_congr,
{ apply inducing_iff_inducing_of_supr_eq_top; assumption },
{ apply set.injective_iff_injective_of_Union_eq_univ, convert (congr_arg coe hU), simp }
end
lemma open_embedding_iff_open_embedding_of_supr_eq_top (h : continuous f) :
open_embedding f ↔ ∀ i, open_embedding ((U i).1.restrict_preimage f) :=
begin
simp_rw open_embedding_iff,
rw forall_and_distrib,
apply and_congr,
{ apply embedding_iff_embedding_of_supr_eq_top; assumption },
{ simp_rw set.range_restrict_preimage, apply open_iff_coe_preimage_of_supr_eq_top hU }
end
lemma closed_embedding_iff_closed_embedding_of_supr_eq_top (h : continuous f) :
closed_embedding f ↔ ∀ i, closed_embedding ((U i).1.restrict_preimage f) :=
begin
simp_rw closed_embedding_iff,
rw forall_and_distrib,
apply and_congr,
{ apply embedding_iff_embedding_of_supr_eq_top; assumption },
{ simp_rw set.range_restrict_preimage, apply closed_iff_coe_preimage_of_supr_eq_top hU }
end
|
c4845da19d5a39847c7be61c381bd4a2b904c072 | d406927ab5617694ec9ea7001f101b7c9e3d9702 | /src/category_theory/preadditive/endo_functor.lean | c4c77a465cf8d2ce9274849dfcaeb2595a318d6d | [
"Apache-2.0"
] | permissive | alreadydone/mathlib | dc0be621c6c8208c581f5170a8216c5ba6721927 | c982179ec21091d3e102d8a5d9f5fe06c8fafb73 | refs/heads/master | 1,685,523,275,196 | 1,670,184,141,000 | 1,670,184,141,000 | 287,574,545 | 0 | 0 | Apache-2.0 | 1,670,290,714,000 | 1,597,421,623,000 | Lean | UTF-8 | Lean | false | false | 4,558 | lean | /-
Copyright (c) 2022 Julian Kuelshammer. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Julian Kuelshammer
-/
import category_theory.preadditive.basic
import category_theory.endofunctor.algebra
import category_theory.preadditive.additive_functor
/-!
# Preadditive structure on algebras over a monad
If `C` is a preadditive categories and `F` is an additive endofunctor on `C` then `algebra F` is
also preadditive. Dually, the category `coalgebra F` is also preadditive.
-/
universes v₁ u₁ -- morphism levels before object levels. See note [category_theory universes].
namespace category_theory
variables (C : Type u₁) [category.{v₁} C] [preadditive C] (F : C ⥤ C)
[functor.additive (F : C ⥤ C)]
open category_theory.limits preadditive
/-- The category of algebras over an additive endofunctor on a preadditive category is preadditive.
-/
@[simps]
instance endofunctor.algebra_preadditive : preadditive (endofunctor.algebra F) :=
{ hom_group := λ A₁ A₂, { add := λ α β,
{ f := α.f + β.f,
h' := by simp only [functor.map_add, add_comp, endofunctor.algebra.hom.h, comp_add] },
zero :=
{ f := 0,
h' := by simp only [functor.map_zero, zero_comp, comp_zero] },
nsmul := λ n α,
{ f := n • α.f,
h' := by rw [comp_nsmul, functor.map_nsmul, nsmul_comp, endofunctor.algebra.hom.h] },
neg := λ α,
{ f := -α.f,
h' := by simp only [functor.map_neg, neg_comp, endofunctor.algebra.hom.h, comp_neg] },
sub := λ α β,
{ f := α.f - β.f,
h' := by simp only [functor.map_sub, sub_comp, endofunctor.algebra.hom.h, comp_sub] },
zsmul := λ r α,
{ f := r • α.f,
h' := by rw [comp_zsmul, functor.map_zsmul, zsmul_comp, endofunctor.algebra.hom.h] },
add_assoc := by { intros, ext, apply add_assoc },
zero_add := by { intros, ext, apply zero_add },
add_zero := by { intros, ext, apply add_zero },
nsmul_zero' := by { intros, ext, apply zero_smul },
nsmul_succ' := by { intros, ext, apply succ_nsmul },
sub_eq_add_neg := by { intros, ext, apply sub_eq_add_neg },
zsmul_zero' := by { intros, ext, apply zero_smul },
zsmul_succ' := by { intros, ext, dsimp, simp only [coe_nat_zsmul, succ_nsmul], refl, },
zsmul_neg' := by { intros, ext, simp only [zsmul_neg_succ_of_nat, neg_inj,
nsmul_eq_smul_cast ℤ] },
add_left_neg := by { intros, ext, apply add_left_neg },
add_comm := by { intros, ext, apply add_comm } },
add_comp' := by { intros, ext, apply add_comp },
comp_add' := by { intros, ext, apply comp_add } }
instance algebra.forget_additive : (endofunctor.algebra.forget F).additive := {}
@[simps]
instance endofunctor.coalgebra_preadditive : preadditive (endofunctor.coalgebra F) :=
{ hom_group := λ A₁ A₂, { add := λ α β,
{ f := α.f + β.f,
h' := by simp only [functor.map_add, comp_add, endofunctor.coalgebra.hom.h, add_comp] },
zero :=
{ f := 0,
h' := by simp only [functor.map_zero, zero_comp, comp_zero] },
nsmul := λ n α,
{ f := n • α.f,
h' := by rw [functor.map_nsmul, comp_nsmul, endofunctor.coalgebra.hom.h, nsmul_comp] },
neg := λ α,
{ f := -α.f,
h' := by simp only [functor.map_neg, comp_neg, endofunctor.coalgebra.hom.h, neg_comp] },
sub := λ α β,
{ f := α.f - β.f,
h' := by simp only [functor.map_sub, comp_sub, endofunctor.coalgebra.hom.h, sub_comp] },
zsmul := λ r α,
{ f := r • α.f,
h' := by rw [functor.map_zsmul, comp_zsmul, endofunctor.coalgebra.hom.h, zsmul_comp] },
add_assoc := by { intros, ext, apply add_assoc },
zero_add := by { intros, ext, apply zero_add },
add_zero := by { intros, ext, apply add_zero },
nsmul_zero' := by { intros, ext, apply zero_smul },
nsmul_succ' := by { intros, ext, apply succ_nsmul },
sub_eq_add_neg := by { intros, ext, apply sub_eq_add_neg },
zsmul_zero' := by { intros, ext, apply zero_smul },
zsmul_succ' := by { intros, ext, dsimp, simp only [coe_nat_zsmul, succ_nsmul], refl, },
zsmul_neg' := by { intros, ext, simp only [zsmul_neg_succ_of_nat, neg_inj,
nsmul_eq_smul_cast ℤ] },
add_left_neg := by { intros, ext, apply add_left_neg },
add_comm := by { intros, ext, apply add_comm } },
add_comp' := by { intros, ext, apply add_comp },
comp_add' := by { intros, ext, apply comp_add } }
instance coalgebra.forget_additive : (endofunctor.coalgebra.forget F).additive := {}
end category_theory
|
a293d361666518639a237bbff3caa86d327ea064 | fa02ed5a3c9c0adee3c26887a16855e7841c668b | /src/set_theory/game.lean | a390f0e0b4bdcb293d87e0e6ad153eab5c9241c4 | [
"Apache-2.0"
] | permissive | jjgarzella/mathlib | 96a345378c4e0bf26cf604aed84f90329e4896a2 | 395d8716c3ad03747059d482090e2bb97db612c8 | refs/heads/master | 1,686,480,124,379 | 1,625,163,323,000 | 1,625,163,323,000 | 281,190,421 | 2 | 0 | Apache-2.0 | 1,595,268,170,000 | 1,595,268,169,000 | null | UTF-8 | Lean | false | false | 24,936 | 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, Apurva Nakade
-/
import set_theory.pgame
import tactic.abel
/-!
# Combinatorial games.
In this file we define the quotient of pre-games by the equivalence relation `p ≈ q ↔ p ≤ q ∧ q ≤
p`, and construct an instance `add_comm_group game`, as well as an instance `partial_order game`
(although note carefully the warning that the `<` field in this instance is not the usual relation
on combinatorial games).
## Multiplication on pre-games
We define the operations of multiplication and inverse on pre-games, and prove a few basic theorems
about them. Multiplication is not well-behaved under equivalence of pre-games i.e. `x.equiv y` does
not imply `(x*z).equiv (y*z)`. Hence, multiplication is not a well-defined operation on games.
Nevertheless, the abelian group structure on games allows us to simplify many proofs for pre-games.
-/
universes u
local infix ` ≈ ` := pgame.equiv
instance pgame.setoid : setoid pgame :=
⟨λ x y, x ≈ y,
λ x, pgame.equiv_refl _,
λ x y, pgame.equiv_symm,
λ x y z, pgame.equiv_trans⟩
/-- The type of combinatorial games. 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 combinatorial pre-game is built
inductively from two families of combinatorial 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.
A combinatorial game is then constructed by quotienting by the equivalence
`x ≈ y ↔ x ≤ y ∧ y ≤ x`. -/
abbreviation game := quotient pgame.setoid
open pgame
namespace game
/-- The relation `x ≤ y` on games. -/
def le : game → game → Prop :=
quotient.lift₂ (λ x y, x ≤ y) (λ x₁ y₁ x₂ y₂ hx hy, propext (le_congr hx hy))
instance : has_le game :=
{ le := le }
-- Adding `@[refl]` and `@[trans]` attributes here would override the ones on
-- `preorder.le_refl` and `preorder.le_trans`, which breaks all non-`game` uses of `≤`!
theorem le_refl : ∀ x : game, x ≤ x :=
by { rintro ⟨x⟩, apply pgame.le_refl }
theorem le_trans : ∀ x y z : game, x ≤ y → y ≤ z → x ≤ z :=
by { rintro ⟨x⟩ ⟨y⟩ ⟨z⟩, apply pgame.le_trans }
theorem le_antisymm : ∀ x y : game, x ≤ y → y ≤ x → x = y :=
by { rintro ⟨x⟩ ⟨y⟩ h₁ h₂, apply quot.sound, exact ⟨h₁, h₂⟩ }
/-- The relation `x < y` on games. -/
-- We don't yet make this into an instance, because it will conflict with the (incorrect) notion
-- of `<` provided by `partial_order` later.
def lt : game → game → Prop :=
quotient.lift₂ (λ x y, x < y) (λ x₁ y₁ x₂ y₂ hx hy, propext (lt_congr hx hy))
theorem not_le : ∀ {x y : game}, ¬ (x ≤ y) ↔ (lt y x) :=
by { rintro ⟨x⟩ ⟨y⟩, exact not_le }
instance : has_zero game := ⟨⟦0⟧⟩
instance : inhabited game := ⟨0⟩
instance : has_one game := ⟨⟦1⟧⟩
/-- The negation of `{L | R}` is `{-R | -L}`. -/
def neg : game → game :=
quot.lift (λ x, ⟦-x⟧) (λ x y h, quot.sound (@neg_congr x y h))
instance : has_neg game :=
{ neg := neg }
/-- The sum of `x = {xL | xR}` and `y = {yL | yR}` is `{xL + y, x + yL | xR + y, x + yR}`. -/
def add : game → game → game :=
quotient.lift₂ (λ x y : pgame, ⟦x + y⟧) (λ x₁ y₁ x₂ y₂ hx hy, quot.sound (pgame.add_congr hx hy))
instance : has_add game := ⟨add⟩
theorem add_assoc : ∀ (x y z : game), (x + y) + z = x + (y + z) :=
begin
rintros ⟨x⟩ ⟨y⟩ ⟨z⟩,
apply quot.sound,
exact add_assoc_equiv
end
instance : add_semigroup game.{u} :=
{ add_assoc := add_assoc,
..game.has_add }
theorem add_zero : ∀ (x : game), x + 0 = x :=
begin
rintro ⟨x⟩,
apply quot.sound,
apply add_zero_equiv
end
theorem zero_add : ∀ (x : game), 0 + x = x :=
begin
rintro ⟨x⟩,
apply quot.sound,
apply zero_add_equiv
end
instance : add_monoid game :=
{ add_zero := add_zero,
zero_add := zero_add,
..game.has_zero,
..game.add_semigroup }
theorem add_left_neg : ∀ (x : game), (-x) + x = 0 :=
begin
rintro ⟨x⟩,
apply quot.sound,
apply add_left_neg_equiv
end
instance : add_group game :=
{ add_left_neg := add_left_neg,
..game.has_neg,
..game.add_monoid }
theorem add_comm : ∀ (x y : game), x + y = y + x :=
begin
rintros ⟨x⟩ ⟨y⟩,
apply quot.sound,
exact add_comm_equiv
end
instance : add_comm_semigroup game :=
{ add_comm := add_comm,
..game.add_semigroup }
instance : add_comm_group game :=
{ ..game.add_comm_semigroup,
..game.add_group }
theorem add_le_add_left : ∀ (a b : game), a ≤ b → ∀ (c : game), c + a ≤ c + b :=
begin rintro ⟨a⟩ ⟨b⟩ h ⟨c⟩, apply pgame.add_le_add_left h, end
-- While it is very tempting to define a `partial_order` on games, and prove
-- that games form an `ordered_add_comm_group`, it is a bit dangerous.
-- The relations `≤` and `<` on games do not satisfy
-- `lt_iff_le_not_le : ∀ a b : α, a < b ↔ (a ≤ b ∧ ¬ b ≤ a)`
-- (Consider `a = 0`, `b = star`.)
-- (`lt_iff_le_not_le` is satisfied by surreal numbers, however.)
-- Thus we can not use `<` when defining a `partial_order`.
-- Because of this issue, we define the `partial_order` and `ordered_add_comm_group` instances,
-- but do not actually mark them as instances, for safety.
/-- The `<` operation provided by this partial order is not the usual `<` on games! -/
def game_partial_order : partial_order game :=
{ le_refl := le_refl,
le_trans := le_trans,
le_antisymm := le_antisymm,
..game.has_le }
/-- The `<` operation provided by this `ordered_add_comm_group` is not the usual `<` on games! -/
def ordered_add_comm_group_game : ordered_add_comm_group game :=
{ add_le_add_left := add_le_add_left,
..game.add_comm_group,
..game_partial_order }
end game
namespace pgame
@[simp] lemma quot_neg (a : pgame) : ⟦-a⟧ = -⟦a⟧ := rfl
@[simp] lemma quot_add (a b : pgame) : ⟦a + b⟧ = ⟦a⟧ + ⟦b⟧ := rfl
@[simp] lemma quot_sub (a b : pgame) : ⟦a - b⟧ = ⟦a⟧ - ⟦b⟧ := rfl
theorem quot_eq_of_mk_quot_eq {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
simp only [quotient.eq] at hl hr,
apply quotient.sound,
apply equiv_of_mk_equiv L R hl hr,
end
/-! Multiplicative operations can be defined at the level of pre-games,
but to prove their properties we need to use the abelian group structure of games.
Hence we define them here. -/
/-- The product of `x = {xL | xR}` and `y = {yL | yR}` is
`{xL*y + x*yL - xL*yL, xR*y + x*yR - xR*yR | xL*y + x*yR - xL*yR, x*yL + xR*y - xR*yL }`. -/
def mul (x y : pgame) : pgame :=
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, xl × yr ⊕ xr × yl, _, _⟩; rintro (⟨i, j⟩ | ⟨i, j⟩),
{ exact IHxl i y + IHyl j - IHxl i (yL j) },
{ exact IHxr i y + IHyr j - IHxr i (yR j) },
{ exact IHxl i y + IHyr j - IHxl i (yR j) },
{ exact IHxr i y + IHyl j - IHxr i (yL j) }
end
instance : has_mul pgame := ⟨mul⟩
/-- An explicit description of the moves for Left in `x * y`. -/
def left_moves_mul (x y : pgame) : (x * y).left_moves
≃ x.left_moves × y.left_moves ⊕ x.right_moves × y.right_moves :=
by { cases x, cases y, refl, }
/-- An explicit description of the moves for Right in `x * y`. -/
def right_moves_mul (x y : pgame) : (x * y).right_moves
≃ x.left_moves × y.right_moves ⊕ x.right_moves × y.left_moves :=
by { cases x, cases y, refl, }
@[simp] lemma mk_mul_move_left_inl {xl xr yl yr} {xL xR yL yR} {i j} :
(mk xl xr xL xR * mk yl yr yL yR).move_left (sum.inl (i, j))
= xL i * (mk yl yr yL yR) + (mk xl xr xL xR) * yL j - xL i * yL j :=
rfl
@[simp] lemma mul_move_left_inl {x y : pgame} {i j} :
(x * y).move_left ((left_moves_mul x y).symm (sum.inl (i, j)))
= x.move_left i * y + x * y.move_left j - x.move_left i * y.move_left j :=
by {cases x, cases y, refl}
@[simp] lemma mk_mul_move_left_inr {xl xr yl yr} {xL xR yL yR} {i j} :
(mk xl xr xL xR * mk yl yr yL yR).move_left (sum.inr (i, j))
= xR i * (mk yl yr yL yR) + (mk xl xr xL xR) * yR j - xR i * yR j :=
rfl
@[simp] lemma mul_move_left_inr {x y : pgame} {i j} :
(x * y).move_left ((left_moves_mul x y).symm (sum.inr (i, j)))
= x.move_right i * y + x * y.move_right j - x.move_right i * y.move_right j :=
by {cases x, cases y, refl}
@[simp] lemma mk_mul_move_right_inl {xl xr yl yr} {xL xR yL yR} {i j} :
(mk xl xr xL xR * mk yl yr yL yR).move_right (sum.inl (i, j))
= xL i * (mk yl yr yL yR) + (mk xl xr xL xR) * yR j - xL i * yR j :=
rfl
@[simp] lemma mul_move_right_inl {x y : pgame} {i j} :
(x * y).move_right ((right_moves_mul x y).symm (sum.inl (i, j)))
= x.move_left i * y + x * y.move_right j - x.move_left i * y.move_right j :=
by {cases x, cases y, refl}
@[simp] lemma mk_mul_move_right_inr {xl xr yl yr} {xL xR yL yR} {i j} :
(mk xl xr xL xR * mk yl yr yL yR).move_right (sum.inr (i,j))
= xR i * (mk yl yr yL yR) + (mk xl xr xL xR) * yL j - xR i * yL j :=
rfl
@[simp] lemma mul_move_right_inr {x y : pgame} {i j} :
(x * y).move_right ((right_moves_mul x y).symm (sum.inr (i, j)))
= x.move_right i * y + x * y.move_left j - x.move_right i * y.move_left j :=
by {cases x, cases y, refl}
theorem quot_mul_comm : Π (x y : pgame.{u}), ⟦x * y⟧ = ⟦y * x⟧
| (mk xl xr xL xR) (mk yl yr yL yR) :=
begin
let x := mk xl xr xL xR,
let y := mk yl yr yL yR,
refine quot_eq_of_mk_quot_eq _ _ _ _,
apply equiv.sum_congr (equiv.prod_comm _ _) (equiv.prod_comm _ _),
calc
xl × yr ⊕ xr × yl
≃ xr × yl ⊕ xl × yr : equiv.sum_comm _ _
... ≃ yl × xr ⊕ yr × xl : equiv.sum_congr (equiv.prod_comm _ _) (equiv.prod_comm _ _),
{ rintro (⟨i, j⟩ | ⟨i, j⟩),
{ change ⟦xL i * y⟧ + ⟦x * yL j⟧ - ⟦xL i * yL j⟧ = ⟦yL j * x⟧ + ⟦y * xL i⟧ - ⟦yL j * xL i⟧,
rw [quot_mul_comm (xL i) y, quot_mul_comm x (yL j), quot_mul_comm (xL i) (yL j)],
abel },
{ change ⟦xR i * y⟧ + ⟦x * yR j⟧ - ⟦xR i * yR j⟧ = ⟦yR j * x⟧ + ⟦y * xR i⟧ - ⟦yR j * xR i⟧,
rw [quot_mul_comm (xR i) y, quot_mul_comm x (yR j), quot_mul_comm (xR i) (yR j)],
abel } },
{ rintro (⟨j, i⟩ | ⟨j, i⟩),
{ change ⟦xR i * y⟧ + ⟦x * yL j⟧ - ⟦xR i * yL j⟧ = ⟦yL j * x⟧ + ⟦y * xR i⟧ - ⟦yL j * xR i⟧,
rw [quot_mul_comm (xR i) y, quot_mul_comm x (yL j), quot_mul_comm (xR i) (yL j)],
abel },
{ change ⟦xL i * y⟧ + ⟦x * yR j⟧ - ⟦xL i * yR j⟧ = ⟦yR j * x⟧ + ⟦y * xL i⟧ - ⟦yR j * xL i⟧,
rw [quot_mul_comm (xL i) y, quot_mul_comm x (yR j), quot_mul_comm (xL i) (yR j)],
abel } }
end
using_well_founded { dec_tac := pgame_wf_tac }
/-- `x * y` is equivalent to `y * x`. -/
theorem mul_comm_equiv (x y : pgame) : x * y ≈ y * x :=
quotient.exact $ quot_mul_comm _ _
/-- `x * 0` has exactly the same moves as `0`. -/
def mul_zero_relabelling : Π (x : pgame), relabelling (x * 0) 0
| (mk xl xr xL xR) :=
⟨by fsplit; rintro (⟨_,⟨⟩⟩ | ⟨_,⟨⟩⟩),
by fsplit; rintro (⟨_,⟨⟩⟩ | ⟨_,⟨⟩⟩),
by rintro (⟨_,⟨⟩⟩ | ⟨_,⟨⟩⟩),
by rintro ⟨⟩⟩
/-- `x * 0` is equivalent to `0`. -/
theorem mul_zero_equiv (x : pgame) : x * 0 ≈ 0 :=
(mul_zero_relabelling x).equiv
@[simp] theorem quot_mul_zero (x : pgame) : ⟦x * 0⟧ = ⟦0⟧ :=
@quotient.sound _ _ (x * 0) _ x.mul_zero_equiv
/-- `0 * x` has exactly the same moves as `0`. -/
def zero_mul_relabelling : Π (x : pgame), relabelling (0 * x) 0
| (mk xl xr xL xR) :=
⟨by fsplit; rintro (⟨⟨⟩,_⟩ | ⟨⟨⟩,_⟩),
by fsplit; rintro (⟨⟨⟩,_⟩ | ⟨⟨⟩,_⟩),
by rintro (⟨⟨⟩,_⟩ | ⟨⟨⟩,_⟩),
by rintro ⟨⟩⟩
/-- `0 * x` is equivalent to `0`. -/
theorem zero_mul_equiv (x : pgame) : 0 * x ≈ 0 :=
(zero_mul_relabelling x).equiv
@[simp] theorem quot_zero_mul (x : pgame) : ⟦0 * x⟧ = ⟦0⟧ :=
@quotient.sound _ _ (0 * x) _ x.zero_mul_equiv
@[simp] theorem quot_neg_mul : Π (x y : pgame), ⟦-x * y⟧ = -⟦x * y⟧
| (mk xl xr xL xR) (mk yl yr yL yR) :=
begin
let x := mk xl xr xL xR,
let y := mk yl yr yL yR,
refine quot_eq_of_mk_quot_eq _ _ _ _,
{ fsplit; rintro (⟨_, _⟩ | ⟨_, _⟩);
solve_by_elim [sum.inl, sum.inr, prod.mk] { max_depth := 4 } },
{ fsplit; rintro (⟨_, _⟩ | ⟨_, _⟩);
solve_by_elim [sum.inl, sum.inr, prod.mk] { max_depth := 4 } },
{ rintro (⟨i, j⟩ | ⟨i, j⟩),
{ change ⟦-xR i * y + (-x) * yL j - (-xR i) * yL j⟧ = ⟦-(xR i * y + x * yL j - xR i * yL j)⟧,
simp only [quot_add, quot_sub, quot_neg_mul],
simp, abel },
{ change ⟦-xL i * y + (-x) * yR j - (-xL i) * yR j⟧ = ⟦-(xL i * y + x * yR j - xL i * yR j)⟧,
simp only [quot_add, quot_sub, quot_neg_mul],
simp, abel } },
{ rintro (⟨i, j⟩ | ⟨i, j⟩),
{ change ⟦-xL i * y + (-x) * yL j - (-xL i) * yL j⟧ = ⟦-(xL i * y + x * yL j - xL i * yL j)⟧,
simp only [quot_add, quot_sub, quot_neg_mul],
simp, abel },
{ change ⟦-xR i * y + (-x) * yR j - (-xR i) * yR j⟧ = ⟦-(xR i * y + x * yR j - xR i * yR j)⟧,
simp only [quot_add, quot_sub, quot_neg_mul],
simp, abel } },
end
using_well_founded { dec_tac := pgame_wf_tac }
@[simp] theorem quot_mul_neg (x y : pgame) : ⟦x * -y⟧ = -⟦x * y⟧ :=
by rw [quot_mul_comm, quot_neg_mul, quot_mul_comm]
@[simp] theorem quot_left_distrib : Π (x y z : pgame), ⟦x * (y + z)⟧ = ⟦x * y⟧ + ⟦x * z⟧
| (mk xl xr xL xR) (mk yl yr yL yR) (mk zl zr zL zR) :=
begin
let x := mk xl xr xL xR,
let y := mk yl yr yL yR,
let z := mk zl zr zL zR,
refine quot_eq_of_mk_quot_eq _ _ _ _,
{ fsplit,
{ rintro (⟨_, _ | _⟩ | ⟨_, _ | _⟩);
solve_by_elim [sum.inl, sum.inr, prod.mk] { max_depth := 5 } },
{ rintro (⟨⟨_, _⟩ | ⟨_, _⟩⟩ | ⟨_, _⟩ | ⟨_, _⟩);
solve_by_elim [sum.inl, sum.inr, prod.mk] { max_depth := 5 } },
{ rintro (⟨_, _ | _⟩ | ⟨_, _ | _⟩); refl },
{ rintro (⟨⟨_, _⟩ | ⟨_, _⟩⟩ | ⟨_, _⟩ | ⟨_, _⟩); refl } },
{ fsplit,
{ rintro (⟨_, _ | _⟩ | ⟨_, _ | _⟩);
solve_by_elim [sum.inl, sum.inr, prod.mk] { max_depth := 5 } },
{ rintro (⟨⟨_, _⟩ | ⟨_, _⟩⟩ | ⟨_, _⟩ | ⟨_, _⟩);
solve_by_elim [sum.inl, sum.inr, prod.mk] { max_depth := 5 } },
{ rintro (⟨_, _ | _⟩ | ⟨_, _ | _⟩); refl },
{ rintro (⟨⟨_, _⟩ | ⟨_, _⟩⟩ | ⟨_, _⟩ | ⟨_, _⟩); refl } },
{ rintro (⟨i, j | k⟩ | ⟨i, j | k⟩),
{ change ⟦xL i * (y + z) + x * (yL j + z) - xL i * (yL j + z)⟧
= ⟦xL i * y + x * yL j - xL i * yL j + x * z⟧,
simp [quot_left_distrib], abel },
{ change ⟦xL i * (y + z) + x * (y + zL k) - xL i * (y + zL k)⟧
= ⟦x * y + (xL i * z + x * zL k - xL i * zL k)⟧,
simp [quot_left_distrib], abel },
{ change ⟦xR i * (y + z) + x * (yR j + z) - xR i * (yR j + z)⟧
= ⟦xR i * y + x * yR j - xR i * yR j + x * z⟧,
simp [quot_left_distrib], abel },
{ change ⟦xR i * (y + z) + x * (y + zR k) - xR i * (y + zR k)⟧
= ⟦x * y + (xR i * z + x * zR k - xR i * zR k)⟧,
simp [quot_left_distrib], abel } },
{ rintro (⟨⟨i, j⟩ | ⟨i, j⟩⟩ | ⟨i, k⟩ | ⟨i, k⟩),
{ change ⟦xL i * (y + z) + x * (yR j + z) - xL i * (yR j + z)⟧
= ⟦xL i * y + x * yR j - xL i * yR j + x * z⟧,
simp [quot_left_distrib], abel },
{ change ⟦xR i * (y + z) + x * (yL j + z) - xR i * (yL j + z)⟧
= ⟦xR i * y + x * yL j - xR i * yL j + x * z⟧,
simp [quot_left_distrib], abel },
{ change ⟦xL i * (y + z) + x * (y + zR k) - xL i * (y + zR k)⟧
= ⟦x * y + (xL i * z + x * zR k - xL i * zR k)⟧,
simp [quot_left_distrib], abel },
{ change ⟦xR i * (y + z) + x * (y + zL k) - xR i * (y + zL k)⟧
= ⟦x * y + (xR i * z + x * zL k - xR i * zL k)⟧,
simp [quot_left_distrib], abel } }
end
using_well_founded { dec_tac := pgame_wf_tac }
/-- `x * (y + z)` is equivalent to `x * y + x * z.`-/
theorem left_distrib_equiv (x y z : pgame) : x * (y + z) ≈ x * y + x * z :=
quotient.exact $ quot_left_distrib _ _ _
@[simp] theorem quot_left_distrib_sub (x y z : pgame) : ⟦x * (y - z)⟧ = ⟦x * y⟧ - ⟦x * z⟧ :=
by { change ⟦x * (y + -z)⟧ = ⟦x * y⟧ + -⟦x * z⟧, rw [quot_left_distrib, quot_mul_neg] }
@[simp] theorem quot_right_distrib (x y z : pgame) : ⟦(x + y) * z⟧ = ⟦x * z⟧ + ⟦y * z⟧ :=
by simp only [quot_mul_comm, quot_left_distrib]
/-- `(x + y) * z` is equivalent to `x * z + y * z.`-/
theorem right_distrib_equiv (x y z : pgame) : (x + y) * z ≈ x * z + y * z :=
quotient.exact $ quot_right_distrib _ _ _
@[simp] theorem quot_right_distrib_sub (x y z : pgame) : ⟦(y - z) * x⟧ = ⟦y * x⟧ - ⟦z * x⟧ :=
by { change ⟦(y + -z) * x⟧ = ⟦y * x⟧ + -⟦z * x⟧, rw [quot_right_distrib, quot_neg_mul] }
@[simp] theorem quot_mul_one : Π (x : pgame), ⟦x * 1⟧ = ⟦x⟧
| (mk xl xr xL xR) :=
begin
let x := mk xl xr xL xR,
refine quot_eq_of_mk_quot_eq _ _ _ _,
{ fsplit,
{ rintro (⟨_, ⟨ ⟩⟩ | ⟨_, ⟨ ⟩⟩), assumption },
{ rintro i, exact sum.inl(i, punit.star) },
{ rintro (⟨_, ⟨ ⟩⟩ | ⟨_, ⟨ ⟩⟩), refl },
{ rintro i, refl } },
{ fsplit,
{ rintro (⟨_, ⟨ ⟩⟩ | ⟨_, ⟨ ⟩⟩), assumption },
{ rintro i, exact sum.inr(i, punit.star) },
{ rintro (⟨_, ⟨ ⟩⟩ | ⟨_, ⟨ ⟩⟩), refl },
{ rintro i, refl } },
{ rintro (⟨i, ⟨ ⟩⟩ | ⟨i, ⟨ ⟩⟩),
change ⟦xL i * 1 + x * 0 - xL i * 0⟧ = ⟦xL i⟧,
simp [quot_mul_one] },
{ rintro i,
change ⟦xR i * 1 + x * 0 - xR i * 0⟧ = ⟦xR i⟧,
simp [quot_mul_one] }
end
/-- `x * 1` is equivalent to `x`. -/
theorem mul_one_equiv (x : pgame) : x * 1 ≈ x := quotient.exact $ quot_mul_one _
@[simp] theorem quot_one_mul (x : pgame) : ⟦1 * x⟧ = ⟦x⟧ :=
by rw [quot_mul_comm, quot_mul_one x]
/-- `1 * x` is equivalent to `x`. -/
theorem one_mul_equiv (x : pgame) : 1 * x ≈ x := quotient.exact $ quot_one_mul _
theorem quot_mul_assoc : Π (x y z : pgame), ⟦x * y * z⟧ = ⟦x * (y * z)⟧
| (mk xl xr xL xR) (mk yl yr yL yR) (mk zl zr zL zR) :=
begin
let x := mk xl xr xL xR,
let y := mk yl yr yL yR,
let z := mk zl zr zL zR,
refine quot_eq_of_mk_quot_eq _ _ _ _,
{ fsplit,
{ rintro (⟨⟨_, _⟩ | ⟨_, _⟩, _⟩ | ⟨⟨_, _⟩ | ⟨_, _⟩, _⟩);
solve_by_elim [sum.inl, sum.inr, prod.mk] { max_depth := 7 } },
{ rintro (⟨_, ⟨_, _⟩ | ⟨_, _⟩⟩ | ⟨_,⟨_, _⟩ | ⟨_, _⟩⟩);
solve_by_elim [sum.inl, sum.inr, prod.mk] { max_depth := 7 } },
{ rintro (⟨⟨_, _⟩ | ⟨_, _⟩, _⟩ | ⟨⟨_,_⟩ | ⟨_, _⟩,_⟩); refl },
{ rintro (⟨_, ⟨_, _⟩ | ⟨_, _⟩⟩ | ⟨_,⟨_, _⟩ | ⟨_, _⟩⟩); refl } },
{ fsplit,
{ rintro (⟨⟨_, _⟩ | ⟨_, _⟩, _⟩ | ⟨⟨_, _⟩ | ⟨_, _⟩,_⟩);
solve_by_elim [sum.inl, sum.inr, prod.mk] { max_depth := 7 } },
{ rintro (⟨_, ⟨_, _⟩ | ⟨_, _⟩⟩ | ⟨_, ⟨_, _⟩ | ⟨_, _⟩⟩);
solve_by_elim [sum.inl, sum.inr, prod.mk] { max_depth := 7 } },
{ rintro (⟨⟨_, _⟩ | ⟨_, _⟩, _⟩ | ⟨⟨_, _⟩ | ⟨_, _⟩,_⟩); refl },
{ rintro (⟨_, ⟨_, _⟩ | ⟨_, _⟩⟩ | ⟨_, ⟨_, _⟩ | ⟨_, _⟩⟩); refl } },
{ rintro (⟨⟨i, j⟩ | ⟨i, j⟩, k⟩ | ⟨⟨i, j⟩ | ⟨i, j⟩, k⟩),
{ change ⟦(xL i * y + x * yL j - xL i * yL j) * z + (x * y) * zL k
- (xL i * y + x * yL j - xL i * yL j) * zL k⟧
= ⟦xL i * (y * z) + x * (yL j * z + y * zL k - yL j * zL k)
- xL i * (yL j * z + y * zL k - yL j * zL k)⟧,
simp [quot_mul_assoc], abel },
{ change ⟦(xR i * y + x * yR j - xR i * yR j) * z + (x * y) * zL k
- (xR i * y + x * yR j - xR i * yR j) * zL k⟧
= ⟦xR i * (y * z) + x * (yR j * z + y * zL k - yR j * zL k)
- xR i * (yR j * z + y * zL k - yR j * zL k)⟧,
simp [quot_mul_assoc], abel },
{ change ⟦(xL i * y + x * yR j - xL i * yR j) * z + (x * y) * zR k
- (xL i * y + x * yR j - xL i * yR j) * zR k⟧
= ⟦xL i * (y * z) + x * (yR j * z + y * zR k - yR j * zR k)
- xL i * (yR j * z + y * zR k - yR j * zR k)⟧,
simp [quot_mul_assoc], abel },
{ change ⟦(xR i * y + x * yL j - xR i * yL j) * z + (x * y) * zR k
- (xR i * y + x * yL j - xR i * yL j) * zR k⟧
= ⟦xR i * (y * z) + x * (yL j * z + y * zR k - yL j * zR k)
- xR i * (yL j * z + y * zR k - yL j * zR k)⟧,
simp [quot_mul_assoc], abel } },
{ rintro (⟨i, ⟨j, k⟩ | ⟨j, k⟩⟩ | ⟨i, ⟨j, k⟩ | ⟨j, k⟩⟩),
{ change ⟦(xL i * y + x * yL j - xL i * yL j) * z + (x * y) * zR k
- (xL i * y + x * yL j - xL i * yL j) * zR k⟧
= ⟦xL i * (y * z) + x * (yL j * z + y * zR k - yL j * zR k)
- xL i * (yL j * z + y * zR k - yL j * zR k)⟧,
simp [quot_mul_assoc], abel },
{ change ⟦(xL i * y + x * yR j - xL i * yR j) * z + (x * y) * zL k
- (xL i * y + x * yR j - xL i * yR j) * zL k⟧
= ⟦xL i * (y * z) + x * (yR j * z + y * zL k - yR j * zL k)
- xL i * (yR j * z + y * zL k - yR j * zL k)⟧,
simp [quot_mul_assoc], abel },
{ change ⟦(xR i * y + x * yL j - xR i * yL j) * z + (x * y) * zL k
- (xR i * y + x * yL j - xR i * yL j) * zL k⟧
= ⟦xR i * (y * z) + x * (yL j * z + y * zL k - yL j * zL k)
- xR i * (yL j * z + y * zL k - yL j * zL k)⟧,
simp [quot_mul_assoc], abel },
{ change ⟦(xR i * y + x * yR j - xR i * yR j) * z + (x * y) * zR k
- (xR i * y + x * yR j - xR i * yR j) * zR k⟧
= ⟦xR i * (y * z) + x * (yR j * z + y * zR k - yR j * zR k)
- xR i * (yR j * z + y * zR k - yR j * zR k)⟧,
simp [quot_mul_assoc], abel } }
end
using_well_founded { dec_tac := pgame_wf_tac }
/-- `x * y * z` is equivalent to `x * (y * z).`-/
theorem mul_assoc_equiv (x y z : pgame) : x * y * z ≈ x * (y * z) :=
quotient.exact $ quot_mul_assoc _ _ _
/-- Because the two halves of the definition of `inv` produce more elements
on each side, we have to define the two families inductively.
This is the indexing set for the function, and `inv_val` is the function part. -/
inductive inv_ty (l r : Type u) : bool → Type u
| zero : inv_ty ff
| left₁ : r → inv_ty ff → inv_ty ff
| left₂ : l → inv_ty tt → inv_ty ff
| right₁ : l → inv_ty ff → inv_ty tt
| right₂ : r → inv_ty tt → inv_ty tt
/-- Because the two halves of the definition of `inv` produce more elements
of each side, we have to define the two families inductively.
This is the function part, defined by recursion on `inv_ty`. -/
def inv_val {l r} (L : l → pgame) (R : r → pgame)
(IHl : l → pgame) (IHr : r → pgame) : ∀ {b}, inv_ty l r b → pgame
| _ inv_ty.zero := 0
| _ (inv_ty.left₁ i j) := (1 + (R i - mk l r L R) * inv_val j) * IHr i
| _ (inv_ty.left₂ i j) := (1 + (L i - mk l r L R) * inv_val j) * IHl i
| _ (inv_ty.right₁ i j) := (1 + (L i - mk l r L R) * inv_val j) * IHl i
| _ (inv_ty.right₂ i j) := (1 + (R i - mk l r L R) * inv_val j) * IHr i
/-- The inverse of a positive surreal number `x = {L | R}` is
given by `x⁻¹ = {0,
(1 + (R - x) * x⁻¹L) * R, (1 + (L - x) * x⁻¹R) * L |
(1 + (L - x) * x⁻¹L) * L, (1 + (R - x) * x⁻¹R) * R}`.
Because the two halves `x⁻¹L, x⁻¹R` of `x⁻¹` are used in their own
definition, the sets and elements are inductively generated. -/
def inv' : pgame → pgame
| ⟨l, r, L, R⟩ :=
let l' := {i // 0 < L i},
L' : l' → pgame := λ i, L i.1,
IHl' : l' → pgame := λ i, inv' (L i.1),
IHr := λ i, inv' (R i) in
⟨inv_ty l' r ff, inv_ty l' r tt,
inv_val L' R IHl' IHr, inv_val L' R IHl' IHr⟩
/-- The inverse of a surreal number in terms of the inverse on positive surreals. -/
noncomputable def inv (x : pgame) : pgame :=
by classical; exact
if x = 0 then 0 else if 0 < x then inv' x else inv' (-x)
noncomputable instance : has_inv pgame := ⟨inv⟩
noncomputable instance : has_div pgame := ⟨λ x y, x * y⁻¹⟩
end pgame
|
9ac04e05548ef271c3a6e6238f793d97f0984c57 | 302c785c90d40ad3d6be43d33bc6a558354cc2cf | /src/algebra/pointwise.lean | 8074695486532ca0c987d396408333584ca34f31 | [
"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 | 19,106 | 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.basic
import data.set.finite
import group_theory.submonoid.basic
/-!
# 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 `α`.
* We also define pointwise multiplication on `finset`.
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}⟩
@[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_singleton [group α] : ((*) a) ⁻¹' {b} = {a⁻¹ * b} :=
by rw [← image_mul_left', image_singleton]
@[simp, to_additive]
lemma preimage_mul_right_singleton [group α] : (* a) ⁻¹' {b} = {b * a⁻¹} :=
by rw [← image_mul_right', image_singleton]
@[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_zero_class]
instance [mul_one_class α] : mul_one_class (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.has_one, ..set.has_mul }
@[to_additive set.add_semigroup]
instance [semigroup α] : semigroup (set α) :=
{ mul_assoc := λ _ _ _, image2_assoc mul_assoc,
..set.has_mul }
@[to_additive set.add_monoid]
instance [monoid α] : monoid (set α) :=
{ ..set.semigroup,
..set.mul_one_class }
@[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
@[to_additive]
lemma bdd_above_mul [ordered_comm_monoid α] {A B : set α} :
bdd_above A → bdd_above B → bdd_above (A * B) :=
begin
rintros ⟨bA, hbA⟩ ⟨bB, hbB⟩,
use bA * bB,
rintros x ⟨xa, xb, hxa, hxb, rfl⟩,
exact mul_le_mul' (hbA hxa) (hbB hxb),
end
/-! ### Properties about inversion -/
@[to_additive set.has_neg]
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
@[simp, to_additive]
lemma inv_subset_inv [group α] {s t : set α} : s⁻¹ ⊆ t⁻¹ ↔ s ⊆ t :=
(equiv.inv α).surjective.preimage_subset_preimage_iff
@[to_additive] lemma inv_subset [group α] {s t : set α} : s⁻¹ ⊆ t ↔ s ⊆ t⁻¹ :=
by { rw [← inv_subset_inv, set.inv_inv] }
/-! ### 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.add_comm_monoid : add_comm_monoid (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, }
instance set_semiring.mul_zero_class [has_mul α] : mul_zero_class (set_semiring α) :=
{ zero_mul := λ s, empty_mul,
mul_zero := λ s, mul_empty,
..set.has_mul, ..set_semiring.add_comm_monoid }
instance set_semiring.distrib [has_mul α] : distrib (set_semiring α) :=
{ left_distrib := λ _ _ _, mul_union,
right_distrib := λ _ _ _, union_mul,
..set.has_mul, ..set_semiring.add_comm_monoid }
instance set_semiring.semiring [monoid α] : semiring (set_semiring α) :=
{ ..set_semiring.add_comm_monoid,
..set_semiring.distrib,
..set_semiring.mul_zero_class,
..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
open set
section
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
namespace finset
variables {α : Type*} [decidable_eq α]
/-- The pointwise product of two finite sets `s` and `t`:
`st = s ⬝ t = s * t = { x * y | x ∈ s, y ∈ t }`. -/
@[to_additive "The pointwise sum of two finite sets `s` and `t`:
`s + t = { x + y | x ∈ s, y ∈ t }`."]
instance [has_mul α] : has_mul (finset α) :=
⟨λ s t, (s.product t).image (λ p : α × α, p.1 * p.2)⟩
@[to_additive]
lemma mul_def [has_mul α] {s t : finset α} :
s * t = (s.product t).image (λ p : α × α, p.1 * p.2) := rfl
@[to_additive]
lemma mem_mul [has_mul α] {s t : finset α} {x : α} :
x ∈ s * t ↔ ∃ y z, y ∈ s ∧ z ∈ t ∧ y * z = x :=
by { simp only [finset.mul_def, and.assoc, mem_image, exists_prop, prod.exists, mem_product] }
@[simp, norm_cast, to_additive]
lemma coe_mul [has_mul α] {s t : finset α} : (↑(s * t) : set α) = ↑s * ↑t :=
by { ext, simp only [mem_mul, set.mem_mul, mem_coe] }
@[to_additive]
lemma mul_mem_mul [has_mul α] {s t : finset α} {x y : α} (hx : x ∈ s) (hy : y ∈ t) :
x * y ∈ s * t :=
by { simp only [finset.mem_mul], exact ⟨x, y, hx, hy, rfl⟩ }
lemma add_card_le [has_add α] {s t : finset α} : (s + t).card ≤ s.card * t.card :=
by { convert finset.card_image_le, rw [finset.card_product, mul_comm] }
@[to_additive]
lemma mul_card_le [has_mul α] {s t : finset α} : (s * t).card ≤ s.card * t.card :=
by { convert finset.card_image_le, rw [finset.card_product, mul_comm] }
open_locale classical
/-- A finite set `U` contained in the product of two sets `S * S'` is also contained in the product
of two finite sets `T * T' ⊆ S * S'`. -/
@[to_additive]
lemma subset_mul {M : Type*} [monoid M] {S : set M} {S' : set M} {U : finset M} (f : ↑U ⊆ S * S') :
∃ (T T' : finset M), ↑T ⊆ S ∧ ↑T' ⊆ S' ∧ U ⊆ T * T' :=
begin
apply finset.induction_on' U,
{ use [∅, ∅], simp only [finset.empty_subset, finset.coe_empty, set.empty_subset, and_self], },
rintros a s haU hs has ⟨T, T', hS, hS', h⟩,
obtain ⟨x, y, hx, hy, ha⟩ := set.mem_mul.1 (f haU),
use [insert x T, insert y T'],
simp only [finset.coe_insert],
repeat { rw [set.insert_subset], },
use [hx, hS, hy, hS'],
refine finset.insert_subset.mpr ⟨_, _⟩,
{ rw finset.mem_mul,
use [x,y],
simpa only [true_and, true_or, eq_self_iff_true, finset.mem_insert], },
{ suffices g : (s : set M) ⊆ insert x T * insert y T', { norm_cast at g, assumption, },
transitivity ↑(T * T'),
apply h,
rw finset.coe_mul,
apply set.mul_subset_mul (set.subset_insert x T) (set.subset_insert y T'), },
end
end finset
/-! Some lemmas about pointwise multiplication and submonoids. Ideally we put these in
`group_theory.submonoid.basic`, but currently we cannot because that file is imported by this. -/
namespace submonoid
variables {M : Type*} [monoid M]
@[to_additive]
lemma mul_subset {s t : set M} {S : submonoid M} (hs : s ⊆ S) (ht : t ⊆ S) : s * t ⊆ S :=
by { rintro _ ⟨p, q, hp, hq, rfl⟩, exact submonoid.mul_mem _ (hs hp) (ht hq) }
@[to_additive]
lemma mul_subset_closure {s t u : set M} (hs : s ⊆ u) (ht : t ⊆ u) :
s * t ⊆ submonoid.closure u :=
mul_subset (subset.trans hs submonoid.subset_closure) (subset.trans ht submonoid.subset_closure)
@[to_additive]
lemma coe_mul_self_eq (s : submonoid M) : (s : set M) * s = s :=
begin
ext x,
refine ⟨_, λ h, ⟨x, 1, h, s.one_mem, mul_one x⟩⟩,
rintros ⟨a, b, ha, hb, rfl⟩,
exact s.mul_mem ha hb
end
@[to_additive]
lemma closure_mul_le (S T : set M) : closure (S * T) ≤ closure S ⊔ closure T :=
Inf_le $ λ x ⟨s, t, hs, ht, hx⟩, hx ▸ (closure S ⊔ closure T).mul_mem
(set_like.le_def.mp le_sup_left $ subset_closure hs)
(set_like.le_def.mp le_sup_right $ subset_closure ht)
@[to_additive]
lemma sup_eq_closure (H K : submonoid M) : H ⊔ K = closure (H * K) :=
le_antisymm
(sup_le
(λ h hh, subset_closure ⟨h, 1, hh, K.one_mem, mul_one h⟩)
(λ k hk, subset_closure ⟨1, k, H.one_mem, hk, one_mul k⟩))
(by conv_rhs { rw [← closure_eq H, ← closure_eq K] }; apply closure_mul_le)
end submonoid
|
be8b52c81d63ac32cc2e4084c41246c4ca07adce | 274261f7150b4ed5f1962f172c9357591be8a2b5 | /src/lattice_filtration.lean | 3f8c18b00e1ee2887c4bf065f697a9a1578fb5a9 | [] | no_license | rspencer01/lean_representation_theory | 219ea1edf4b9897b2997226b54473e44e1538b50 | 2eef2b4b39d99d7ce71bec7bbc3dcc2f7586fcb5 | refs/heads/master | 1,588,133,157,029 | 1,571,689,957,000 | 1,571,689,957,000 | 175,835,785 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 2,492 | lean | import order.order_iso
import .lists
open lattice
/-- A filtration is a list of (not-strictly) increasing elements of the lattice -/
structure filtration (α) [preorder α] := (modules : list α) (c : list.chain' (≤) modules)
namespace filtration
def le_pair (α) [has_le α] := { p : α × α // p.1 ≤ p.2}
instance (α) [preorder α]: has_coe (filtration α) (list α) := ⟨ λ F, F.modules ⟩
def factors_up {α} [bounded_lattice α] : filtration α → list (le_pair α)
| ⟨ [], _ ⟩ := []
| ⟨ [x], _ ⟩ := [⟨(x, ⊤), by simp⟩]
| ⟨ (x::y::l), h ⟩ := ⟨ (x, y) , list.chain'_of_first_two h⟩ ::
(factors_up ⟨ (y::l), (list.chain'_desc_left h)⟩)
@[simp]
def factors {α} [bounded_lattice α] : filtration α → list (le_pair α)
| ⟨ [], _ ⟩ := [ ⟨ (⊥ , ⊤) , by simp ⟩ ]
| ⟨ (x::l) , h ⟩ := ⟨ (⊥ , x), by simp ⟩ :: factors_up ⟨ (x::l) , h ⟩
@[simp]
lemma factors_not_empty {α} [bounded_lattice α]: Π (F : filtration α), F.factors ≠ []
| ⟨ [], _ ⟩ := by simp
| ⟨ (x::l), h ⟩ := by simp
def map {α} {β} [preorder α] [preorder β] (f : ((≤) : α → α → Prop) ≃o ((≤) : β → β → Prop)) :
filtration α → filtration β := λ F, {
modules := list.map f F.modules,
c := list.chain'_map_of_chain' f (λ a b, iff.elim_left (@order_iso.ord _ _ _ _ f a b)) F.c
}
def descend {α} [q : preorder α] (F : filtration α) (h : F.modules ≠ []) : list {x : α // x ≤ F.modules.last h} :=
(list.map₄ (λ x, x ≤ F.modules.last h) F.modules (λ a h2, (
@list.chain'_trans_last _ (≤) F.modules q.le_refl q.le_trans F.c h a h2 )))
def pop_back'' {α} [preorder α] (F : filtration α) (h : F.modules ≠ []) :
filtration {x // x ≤ F.modules.last h} := {
modules := descend F h,
c := begin
intros,
cases F,
cases F_modules,
exact absurd rfl h,
unfold descend,
exact list.chain'_map₄ _ (F_modules_hd :: F_modules_tl) _ F_c
end
}
def pop_back' {α} [preorder α] (F : filtration α) (h : F.modules ≠ []) :
filtration α := {
modules := list.init F.modules,
c := list.chain'_init _ F.c
}
def pop_back {α} [preorder α] (F : filtration α) (h : F.modules ≠ []) :
filtration {x // x ≤ F.modules.last h} := pop_back' (pop_back'' F h) (by cases F; cases F_modules; contradiction; finish)
end filtration
|
2e3168c94f1495746d3eb627793a6bd206ca7594 | 592ee40978ac7604005a4e0d35bbc4b467389241 | /Library/generated/mathscheme-lean/RightSelfInverse.lean | ad3b7cc7f582ee3c1b375b46ea311b035453fec7 | [] | no_license | ysharoda/Deriving-Definitions | 3e149e6641fae440badd35ac110a0bd705a49ad2 | dfecb27572022de3d4aa702cae8db19957523a59 | refs/heads/master | 1,679,127,857,700 | 1,615,939,007,000 | 1,615,939,007,000 | 229,785,731 | 4 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 6,301 | lean | import init.data.nat.basic
import init.data.fin.basic
import data.vector
import .Prelude
open Staged
open nat
open fin
open vector
section RightSelfInverse
structure RightSelfInverse (A : Type) : Type :=
(linv : (A → (A → A)))
(rightSelfInverse_linv : (∀ {x y : A} , (linv (linv x y) y) = x))
open RightSelfInverse
structure Sig (AS : Type) : Type :=
(linvS : (AS → (AS → AS)))
structure Product (A : Type) : Type :=
(linvP : ((Prod A A) → ((Prod A A) → (Prod A A))))
(rightSelfInverse_linvP : (∀ {xP yP : (Prod A A)} , (linvP (linvP xP yP) yP) = xP))
structure Hom {A1 : Type} {A2 : Type} (Ri1 : (RightSelfInverse A1)) (Ri2 : (RightSelfInverse A2)) : Type :=
(hom : (A1 → A2))
(pres_linv : (∀ {x1 x2 : A1} , (hom ((linv Ri1) x1 x2)) = ((linv Ri2) (hom x1) (hom x2))))
structure RelInterp {A1 : Type} {A2 : Type} (Ri1 : (RightSelfInverse A1)) (Ri2 : (RightSelfInverse A2)) : Type 1 :=
(interp : (A1 → (A2 → Type)))
(interp_linv : (∀ {x1 x2 : A1} {y1 y2 : A2} , ((interp x1 y1) → ((interp x2 y2) → (interp ((linv Ri1) x1 x2) ((linv Ri2) y1 y2))))))
inductive RightSelfInverseTerm : Type
| linvL : (RightSelfInverseTerm → (RightSelfInverseTerm → RightSelfInverseTerm))
open RightSelfInverseTerm
inductive ClRightSelfInverseTerm (A : Type) : Type
| sing : (A → ClRightSelfInverseTerm)
| linvCl : (ClRightSelfInverseTerm → (ClRightSelfInverseTerm → ClRightSelfInverseTerm))
open ClRightSelfInverseTerm
inductive OpRightSelfInverseTerm (n : ℕ) : Type
| v : ((fin n) → OpRightSelfInverseTerm)
| linvOL : (OpRightSelfInverseTerm → (OpRightSelfInverseTerm → OpRightSelfInverseTerm))
open OpRightSelfInverseTerm
inductive OpRightSelfInverseTerm2 (n : ℕ) (A : Type) : Type
| v2 : ((fin n) → OpRightSelfInverseTerm2)
| sing2 : (A → OpRightSelfInverseTerm2)
| linvOL2 : (OpRightSelfInverseTerm2 → (OpRightSelfInverseTerm2 → OpRightSelfInverseTerm2))
open OpRightSelfInverseTerm2
def simplifyCl {A : Type} : ((ClRightSelfInverseTerm A) → (ClRightSelfInverseTerm A))
| (linvCl x1 x2) := (linvCl (simplifyCl x1) (simplifyCl x2))
| (sing x1) := (sing x1)
def simplifyOpB {n : ℕ} : ((OpRightSelfInverseTerm n) → (OpRightSelfInverseTerm n))
| (linvOL x1 x2) := (linvOL (simplifyOpB x1) (simplifyOpB x2))
| (v x1) := (v x1)
def simplifyOp {n : ℕ} {A : Type} : ((OpRightSelfInverseTerm2 n A) → (OpRightSelfInverseTerm2 n A))
| (linvOL2 x1 x2) := (linvOL2 (simplifyOp x1) (simplifyOp x2))
| (v2 x1) := (v2 x1)
| (sing2 x1) := (sing2 x1)
def evalB {A : Type} : ((RightSelfInverse A) → (RightSelfInverseTerm → A))
| Ri (linvL x1 x2) := ((linv Ri) (evalB Ri x1) (evalB Ri x2))
def evalCl {A : Type} : ((RightSelfInverse A) → ((ClRightSelfInverseTerm A) → A))
| Ri (sing x1) := x1
| Ri (linvCl x1 x2) := ((linv Ri) (evalCl Ri x1) (evalCl Ri x2))
def evalOpB {A : Type} {n : ℕ} : ((RightSelfInverse A) → ((vector A n) → ((OpRightSelfInverseTerm n) → A)))
| Ri vars (v x1) := (nth vars x1)
| Ri vars (linvOL x1 x2) := ((linv Ri) (evalOpB Ri vars x1) (evalOpB Ri vars x2))
def evalOp {A : Type} {n : ℕ} : ((RightSelfInverse A) → ((vector A n) → ((OpRightSelfInverseTerm2 n A) → A)))
| Ri vars (v2 x1) := (nth vars x1)
| Ri vars (sing2 x1) := x1
| Ri vars (linvOL2 x1 x2) := ((linv Ri) (evalOp Ri vars x1) (evalOp Ri vars x2))
def inductionB {P : (RightSelfInverseTerm → Type)} : ((∀ (x1 x2 : RightSelfInverseTerm) , ((P x1) → ((P x2) → (P (linvL x1 x2))))) → (∀ (x : RightSelfInverseTerm) , (P x)))
| plinvl (linvL x1 x2) := (plinvl _ _ (inductionB plinvl x1) (inductionB plinvl x2))
def inductionCl {A : Type} {P : ((ClRightSelfInverseTerm A) → Type)} : ((∀ (x1 : A) , (P (sing x1))) → ((∀ (x1 x2 : (ClRightSelfInverseTerm A)) , ((P x1) → ((P x2) → (P (linvCl x1 x2))))) → (∀ (x : (ClRightSelfInverseTerm A)) , (P x))))
| psing plinvcl (sing x1) := (psing x1)
| psing plinvcl (linvCl x1 x2) := (plinvcl _ _ (inductionCl psing plinvcl x1) (inductionCl psing plinvcl x2))
def inductionOpB {n : ℕ} {P : ((OpRightSelfInverseTerm n) → Type)} : ((∀ (fin : (fin n)) , (P (v fin))) → ((∀ (x1 x2 : (OpRightSelfInverseTerm n)) , ((P x1) → ((P x2) → (P (linvOL x1 x2))))) → (∀ (x : (OpRightSelfInverseTerm n)) , (P x))))
| pv plinvol (v x1) := (pv x1)
| pv plinvol (linvOL x1 x2) := (plinvol _ _ (inductionOpB pv plinvol x1) (inductionOpB pv plinvol x2))
def inductionOp {n : ℕ} {A : Type} {P : ((OpRightSelfInverseTerm2 n A) → Type)} : ((∀ (fin : (fin n)) , (P (v2 fin))) → ((∀ (x1 : A) , (P (sing2 x1))) → ((∀ (x1 x2 : (OpRightSelfInverseTerm2 n A)) , ((P x1) → ((P x2) → (P (linvOL2 x1 x2))))) → (∀ (x : (OpRightSelfInverseTerm2 n A)) , (P x)))))
| pv2 psing2 plinvol2 (v2 x1) := (pv2 x1)
| pv2 psing2 plinvol2 (sing2 x1) := (psing2 x1)
| pv2 psing2 plinvol2 (linvOL2 x1 x2) := (plinvol2 _ _ (inductionOp pv2 psing2 plinvol2 x1) (inductionOp pv2 psing2 plinvol2 x2))
def stageB : (RightSelfInverseTerm → (Staged RightSelfInverseTerm))
| (linvL x1 x2) := (stage2 linvL (codeLift2 linvL) (stageB x1) (stageB x2))
def stageCl {A : Type} : ((ClRightSelfInverseTerm A) → (Staged (ClRightSelfInverseTerm A)))
| (sing x1) := (Now (sing x1))
| (linvCl x1 x2) := (stage2 linvCl (codeLift2 linvCl) (stageCl x1) (stageCl x2))
def stageOpB {n : ℕ} : ((OpRightSelfInverseTerm n) → (Staged (OpRightSelfInverseTerm n)))
| (v x1) := (const (code (v x1)))
| (linvOL x1 x2) := (stage2 linvOL (codeLift2 linvOL) (stageOpB x1) (stageOpB x2))
def stageOp {n : ℕ} {A : Type} : ((OpRightSelfInverseTerm2 n A) → (Staged (OpRightSelfInverseTerm2 n A)))
| (sing2 x1) := (Now (sing2 x1))
| (v2 x1) := (const (code (v2 x1)))
| (linvOL2 x1 x2) := (stage2 linvOL2 (codeLift2 linvOL2) (stageOp x1) (stageOp x2))
structure StagedRepr (A : Type) (Repr : (Type → Type)) : Type :=
(linvT : ((Repr A) → ((Repr A) → (Repr A))))
end RightSelfInverse |
8aa84c8a07b17096cb73797d9e1b312623999c09 | 35677d2df3f081738fa6b08138e03ee36bc33cad | /test/traversable.lean | 931b0828049b82c645a0afa303797ea5c8c6c9c8 | [
"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 | 1,940 | lean | import category.traversable.derive
import tactic
universes u
/- traversable -/
open tactic.interactive
run_cmd do
lawful_traversable_derive_handler' `test ``(is_lawful_traversable) ``list
-- the above creates local instances of `traversable` and `is_lawful_traversable`
-- for `list`
-- do not put in instances because they are not universe polymorphic
@[derive [traversable, is_lawful_traversable]]
structure my_struct (α : Type) :=
(y : ℤ)
@[derive [traversable, is_lawful_traversable]]
inductive either (α : Type u)
| left : α → ℤ → either
| right : α → either
@[derive [traversable, is_lawful_traversable]]
structure my_struct2 (α : Type u) : Type u :=
(x : α)
(y : ℤ)
(η : list α)
(k : list (list α))
@[derive [traversable, is_lawful_traversable]]
inductive rec_data3 (α : Type u) : Type u
| nil : rec_data3
| cons : ℕ → α → rec_data3 → rec_data3 → rec_data3
@[derive traversable]
meta structure meta_struct (α : Type u) : Type u :=
(x : α)
(y : ℤ)
(z : list α)
(k : list (list α))
(w : expr)
@[derive [traversable,is_lawful_traversable]]
inductive my_tree (α : Type)
| leaf : my_tree
| node : my_tree → my_tree → α → my_tree
section
open my_tree (hiding traverse)
def x : my_tree (list nat) :=
node
leaf
(node
(node leaf leaf [1,2,3])
leaf
[3,2])
[1]
/-- demonstrate the nested use of `traverse`. It traverses each node of the tree and
in each node, traverses each list. For each `ℕ` visited, apply an action `ℕ -> state (list ℕ) unit`
which adds its argument to the state. -/
def ex : state (list ℕ) (my_tree $ list unit) :=
do xs ← traverse (traverse $ λ a, modify $ list.cons a) x,
pure xs
example : (ex.run []).1 = node leaf (node (node leaf leaf [(), (), ()]) leaf [(), ()]) [()] := rfl
example : (ex.run []).2 = [1, 2, 3, 3, 2, 1] := rfl
example : is_lawful_traversable my_tree := my_tree.is_lawful_traversable
end
|
06790c576427ad0223112494620503b0aec58335 | 57c233acf9386e610d99ed20ef139c5f97504ba3 | /src/order/omega_complete_partial_order.lean | 741a53fb83d855db6e3a813015692a5870a6c2ac | [
"Apache-2.0"
] | permissive | robertylewis/mathlib | 3d16e3e6daf5ddde182473e03a1b601d2810952c | 1d13f5b932f5e40a8308e3840f96fc882fae01f0 | refs/heads/master | 1,651,379,945,369 | 1,644,276,960,000 | 1,644,276,960,000 | 98,875,504 | 0 | 0 | Apache-2.0 | 1,644,253,514,000 | 1,501,495,700,000 | Lean | UTF-8 | Lean | false | false | 27,464 | 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 control.monad.basic
import data.part
import order.hom.order
import tactic.monotonicity
import tactic.wlog
/-!
# Omega Complete Partial Orders
An omega-complete partial order is a partial order with a supremum
operation on increasing sequences indexed by natural numbers (which we
call `ωSup`). In this sense, it is strictly weaker than join complete
semi-lattices as only ω-sized totally ordered sets have a supremum.
The concept of an omega-complete partial order (ωCPO) is useful for the
formalization of the semantics of programming languages. Its notion of
supremum helps define the meaning of recursive procedures.
## Main definitions
* class `omega_complete_partial_order`
* `ite`, `map`, `bind`, `seq` as continuous morphisms
## Instances of `omega_complete_partial_order`
* `part`
* every `complete_lattice`
* pi-types
* product types
* `monotone_hom`
* `continuous_hom` (with notation →𝒄)
* an instance of `omega_complete_partial_order (α →𝒄 β)`
* `continuous_hom.of_fun`
* `continuous_hom.of_mono`
* continuous functions:
* `id`
* `ite`
* `const`
* `part.bind`
* `part.map`
* `part.seq`
## References
* [Chain-complete posets and directed sets with applications][markowsky1976]
* [Recursive definitions of partial functions and their computations][cadiou1972]
* [Semantics of Programming Languages: Structures and Techniques][gunter1992]
-/
universes u v
local attribute [-simp] part.bind_eq_bind part.map_eq_map
open_locale classical
namespace order_hom
variables (α : Type*) (β : Type*) {γ : Type*} {φ : Type*}
variables [preorder α] [preorder β] [preorder γ] [preorder φ]
variables {β γ}
variables {α} {α' : Type*} {β' : Type*} [preorder α'] [preorder β']
/-- `part.bind` as a monotone function -/
@[simps]
def bind {β γ} (f : α →o part β) (g : α →o β → part γ) : α →o part γ :=
{ to_fun := λ x, f x >>= g x,
monotone' :=
begin
intros x y h a,
simp only [and_imp, exists_prop, part.bind_eq_bind, part.mem_bind_iff,
exists_imp_distrib],
intros b hb ha,
refine ⟨b, f.monotone h _ hb, g.monotone h _ _ ha⟩,
end }
end order_hom
namespace omega_complete_partial_order
/-- A chain is a monotone sequence.
See the definition on page 114 of [gunter1992]. -/
def chain (α : Type u) [preorder α] :=
ℕ →o α
namespace chain
variables {α : Type u} {β : Type v} {γ : Type*}
variables [preorder α] [preorder β] [preorder γ]
instance : has_coe_to_fun (chain α) (λ _, ℕ → α) := order_hom.has_coe_to_fun
instance [inhabited α] : inhabited (chain α) :=
⟨ ⟨ λ _, default, λ _ _ _, le_rfl ⟩ ⟩
instance : has_mem α (chain α) :=
⟨λa (c : ℕ →o α), ∃ i, a = c i⟩
variables (c c' : chain α)
variables (f : α →o β)
variables (g : β →o γ)
instance : has_le (chain α) :=
{ le := λ x y, ∀ i, ∃ j, x i ≤ y j }
/-- `map` function for `chain` -/
@[simps {fully_applied := ff}] def map : chain β :=
f.comp c
variables {f}
lemma mem_map (x : α) : x ∈ c → f x ∈ chain.map c f :=
λ ⟨i,h⟩, ⟨i, h.symm ▸ rfl⟩
lemma exists_of_mem_map {b : β} : b ∈ c.map f → ∃ a, a ∈ c ∧ f a = b :=
λ ⟨i,h⟩, ⟨c i, ⟨i, rfl⟩, h.symm⟩
lemma mem_map_iff {b : β} : b ∈ c.map f ↔ ∃ a, a ∈ c ∧ f a = b :=
⟨ exists_of_mem_map _, λ h, by { rcases h with ⟨w,h,h'⟩, subst b, apply mem_map c _ h, } ⟩
@[simp]
lemma map_id : c.map order_hom.id = c :=
order_hom.comp_id _
lemma map_comp : (c.map f).map g = c.map (g.comp f) := rfl
@[mono]
lemma map_le_map {g : α →o β} (h : f ≤ g) : c.map f ≤ c.map g :=
λ i, by simp [mem_map_iff]; intros; existsi i; apply h
/-- `chain.zip` pairs up the elements of two chains that have the same index -/
@[simps]
def zip (c₀ : chain α) (c₁ : chain β) : chain (α × β) :=
order_hom.prod c₀ c₁
end chain
end omega_complete_partial_order
open omega_complete_partial_order
section prio
set_option extends_priority 50
/-- An omega-complete partial order is a partial order with a supremum
operation on increasing sequences indexed by natural numbers (which we
call `ωSup`). In this sense, it is strictly weaker than join complete
semi-lattices as only ω-sized totally ordered sets have a supremum.
See the definition on page 114 of [gunter1992]. -/
class omega_complete_partial_order (α : Type*) extends partial_order α :=
(ωSup : chain α → α)
(le_ωSup : ∀(c:chain α), ∀ i, c i ≤ ωSup c)
(ωSup_le : ∀(c:chain α) x, (∀ i, c i ≤ x) → ωSup c ≤ x)
end prio
namespace omega_complete_partial_order
variables {α : Type u} {β : Type v} {γ : Type*}
variables [omega_complete_partial_order α]
/-- Transfer a `omega_complete_partial_order` on `β` to a `omega_complete_partial_order` on `α`
using a strictly monotone function `f : β →o α`, a definition of ωSup and a proof that `f` is
continuous with regard to the provided `ωSup` and the ωCPO on `α`. -/
@[reducible]
protected def lift [partial_order β] (f : β →o α)
(ωSup₀ : chain β → β)
(h : ∀ x y, f x ≤ f y → x ≤ y)
(h' : ∀ c, f (ωSup₀ c) = ωSup (c.map f)) : omega_complete_partial_order β :=
{ ωSup := ωSup₀,
ωSup_le := λ c x hx, h _ _ (by rw h'; apply ωSup_le; intro; apply f.monotone (hx i)),
le_ωSup := λ c i, h _ _ (by rw h'; apply le_ωSup (c.map f)) }
lemma le_ωSup_of_le {c : chain α} {x : α} (i : ℕ) (h : x ≤ c i) : x ≤ ωSup c :=
le_trans h (le_ωSup c _)
lemma ωSup_total {c : chain α} {x : α} (h : ∀ i, c i ≤ x ∨ x ≤ c i) : ωSup c ≤ x ∨ x ≤ ωSup c :=
classical.by_cases
(assume : ∀ i, c i ≤ x, or.inl (ωSup_le _ _ this))
(assume : ¬ ∀ i, c i ≤ x,
have ∃ i, ¬ c i ≤ x,
by simp only [not_forall] at this ⊢; assumption,
let ⟨i, hx⟩ := this in
have x ≤ c i, from (h i).resolve_left hx,
or.inr $ le_ωSup_of_le _ this)
@[mono]
lemma ωSup_le_ωSup_of_le {c₀ c₁ : chain α} (h : c₀ ≤ c₁) : ωSup c₀ ≤ ωSup c₁ :=
ωSup_le _ _ $
λ i, Exists.rec_on (h i) $
λ j h, le_trans h (le_ωSup _ _)
lemma ωSup_le_iff (c : chain α) (x : α) : ωSup c ≤ x ↔ (∀ i, c i ≤ x) :=
begin
split; intros,
{ transitivity ωSup c,
exact le_ωSup _ _, assumption },
exact ωSup_le _ _ ‹_›,
end
/-- A subset `p : α → Prop` of the type closed under `ωSup` induces an
`omega_complete_partial_order` on the subtype `{a : α // p a}`. -/
def subtype {α : Type*} [omega_complete_partial_order α] (p : α → Prop)
(hp : ∀ (c : chain α), (∀ i ∈ c, p i) → p (ωSup c)) :
omega_complete_partial_order (subtype p) :=
omega_complete_partial_order.lift
(order_hom.subtype.val p)
(λ c, ⟨ωSup _, hp (c.map (order_hom.subtype.val p)) (λ i ⟨n, q⟩, q.symm ▸ (c n).2)⟩)
(λ x y h, h)
(λ c, rfl)
section continuity
open chain
variables [omega_complete_partial_order β]
variables [omega_complete_partial_order γ]
/-- A monotone function `f : α →o β` is continuous if it distributes over ωSup.
In order to distinguish it from the (more commonly used) continuity from topology
(see topology/basic.lean), the present definition is often referred to as
"Scott-continuity" (referring to Dana Scott). It corresponds to continuity
in Scott topological spaces (not defined here). -/
def continuous (f : α →o β) : Prop :=
∀ c : chain α, f (ωSup c) = ωSup (c.map f)
/-- `continuous' f` asserts that `f` is both monotone and continuous. -/
def continuous' (f : α → β) : Prop :=
∃ hf : monotone f, continuous ⟨f, hf⟩
lemma continuous'.to_monotone {f : α → β} (hf : continuous' f) : monotone f := hf.fst
lemma continuous.of_bundled (f : α → β) (hf : monotone f)
(hf' : continuous ⟨f, hf⟩) : continuous' f := ⟨hf, hf'⟩
lemma continuous.of_bundled' (f : α →o β) (hf' : continuous f) : continuous' f :=
⟨f.mono, hf'⟩
lemma continuous'.to_bundled (f : α → β) (hf : continuous' f) :
continuous ⟨f, hf.to_monotone⟩ := hf.snd
@[simp, norm_cast] lemma continuous'_coe : ∀ {f : α →o β}, continuous' f ↔ continuous f
| ⟨f, hf⟩ := ⟨λ ⟨hf', hc⟩, hc, λ hc, ⟨hf, hc⟩⟩
variables (f : α →o β) (g : β →o γ)
lemma continuous_id : continuous (@order_hom.id α _) :=
by intro; rw c.map_id; refl
lemma continuous_comp (hfc : continuous f) (hgc : continuous g) : continuous (g.comp f):=
begin
dsimp [continuous] at *, intro,
rw [hfc,hgc,chain.map_comp]
end
lemma id_continuous' : continuous' (@id α) :=
continuous_id.of_bundled' _
lemma continuous_const (x : β) : continuous (order_hom.const α x) :=
λ c, eq_of_forall_ge_iff $ λ z, by simp [ωSup_le_iff]
lemma const_continuous' (x: β) : continuous' (function.const α x) :=
continuous.of_bundled' (order_hom.const α x) (continuous_const x)
end continuity
end omega_complete_partial_order
namespace part
variables {α : Type u} {β : Type v} {γ : Type*}
open omega_complete_partial_order
lemma eq_of_chain {c : chain (part α)} {a b : α} (ha : some a ∈ c) (hb : some b ∈ c) : a = b :=
begin
cases ha with i ha, replace ha := ha.symm,
cases hb with j hb, replace hb := hb.symm,
wlog h : i ≤ j := le_total i j using [a b i j, b a j i],
rw [eq_some_iff] at ha hb,
have := c.monotone h _ ha, apply mem_unique this hb
end
/-- The (noncomputable) `ωSup` definition for the `ω`-CPO structure on `part α`. -/
protected noncomputable def ωSup (c : chain (part α)) : part α :=
if h : ∃a, some a ∈ c then some (classical.some h) else none
lemma ωSup_eq_some {c : chain (part α)} {a : α} (h : some a ∈ c) : part.ωSup c = some a :=
have ∃a, some a ∈ c, from ⟨a, h⟩,
have a' : some (classical.some this) ∈ c, from classical.some_spec this,
calc part.ωSup c = some (classical.some this) : dif_pos this
... = some a : congr_arg _ (eq_of_chain a' h)
lemma ωSup_eq_none {c : chain (part α)} (h : ¬∃a, some a ∈ c) : part.ωSup c = none :=
dif_neg h
lemma mem_chain_of_mem_ωSup {c : chain (part α)} {a : α} (h : a ∈ part.ωSup c) : some a ∈ c :=
begin
simp [part.ωSup] at h, split_ifs at h,
{ have h' := classical.some_spec h_1,
rw ← eq_some_iff at h, rw ← h, exact h' },
{ rcases h with ⟨ ⟨ ⟩ ⟩ }
end
noncomputable instance omega_complete_partial_order : omega_complete_partial_order (part α) :=
{ ωSup := part.ωSup,
le_ωSup := λ c i, by { intros x hx, rw ← eq_some_iff at hx ⊢,
rw [ωSup_eq_some, ← hx], rw ← hx, exact ⟨i,rfl⟩ },
ωSup_le := by { rintros c x hx a ha, replace ha := mem_chain_of_mem_ωSup ha,
cases ha with i ha, apply hx i, rw ← ha, apply mem_some } }
section inst
lemma mem_ωSup (x : α) (c : chain (part α)) : x ∈ ωSup c ↔ some x ∈ c :=
begin
simp [omega_complete_partial_order.ωSup,part.ωSup],
split,
{ split_ifs, swap, rintro ⟨⟨⟩⟩,
intro h', have hh := classical.some_spec h,
simp at h', subst x, exact hh },
{ intro h,
have h' : ∃ (a : α), some a ∈ c := ⟨_,h⟩,
rw dif_pos h', have hh := classical.some_spec h',
rw eq_of_chain hh h, simp }
end
end inst
end part
namespace pi
variables {α : Type*} {β : α → Type*} {γ : Type*}
open omega_complete_partial_order omega_complete_partial_order.chain
instance [∀a, omega_complete_partial_order (β a)] : omega_complete_partial_order (Πa, β a) :=
{ ωSup := λc a, ωSup (c.map (pi.eval_order_hom a)),
ωSup_le := assume c f hf a, ωSup_le _ _ $ by { rintro i, apply hf },
le_ωSup := assume c i x, le_ωSup_of_le _ $ le_rfl }
namespace omega_complete_partial_order
variables [∀ x, omega_complete_partial_order $ β x]
variables [omega_complete_partial_order γ]
lemma flip₁_continuous'
(f : ∀ x : α, γ → β x) (a : α) (hf : continuous' (λ x y, f y x)) :
continuous' (f a) :=
continuous.of_bundled _
(λ x y h, hf.to_monotone h a)
(λ c, congr_fun (hf.to_bundled _ c) a)
lemma flip₂_continuous'
(f : γ → Π x, β x) (hf : ∀ x, continuous' (λ g, f g x)) : continuous' f :=
continuous.of_bundled _
(λ x y h a, (hf a).to_monotone h)
(by intro c; ext a; apply (hf a).to_bundled _ c)
end omega_complete_partial_order
end pi
namespace prod
open omega_complete_partial_order
variables {α : Type*} {β : Type*} {γ : Type*}
variables [omega_complete_partial_order α]
variables [omega_complete_partial_order β]
variables [omega_complete_partial_order γ]
/-- The supremum of a chain in the product `ω`-CPO. -/
@[simps]
protected def ωSup (c : chain (α × β)) : α × β :=
(ωSup (c.map order_hom.fst), ωSup (c.map order_hom.snd))
@[simps ωSup_fst ωSup_snd]
instance : omega_complete_partial_order (α × β) :=
{ ωSup := prod.ωSup,
ωSup_le := λ c ⟨x,x'⟩ h, ⟨ωSup_le _ _ $ λ i, (h i).1, ωSup_le _ _ $ λ i, (h i).2⟩,
le_ωSup := λ c i,
⟨le_ωSup (c.map order_hom.fst) i, le_ωSup (c.map order_hom.snd) i⟩ }
end prod
namespace complete_lattice
variables (α : Type u)
/-- Any complete lattice has an `ω`-CPO structure where the countable supremum is a special case
of arbitrary suprema. -/
@[priority 100] -- see Note [lower instance priority]
instance [complete_lattice α] : omega_complete_partial_order α :=
{ ωSup := λc, ⨆ i, c i,
ωSup_le := λ ⟨c, _⟩ s hs, by simp only [supr_le_iff, order_hom.coe_fun_mk] at ⊢ hs;
intros i; apply hs i,
le_ωSup := assume ⟨c, _⟩ i, by simp only [order_hom.coe_fun_mk]; apply le_supr_of_le i; refl }
variables {α} {β : Type v} [omega_complete_partial_order α] [complete_lattice β]
open omega_complete_partial_order
lemma inf_continuous [is_total β (≤)] (f g : α →o β) (hf : continuous f) (hg : continuous g) :
continuous (f ⊓ g) :=
begin
intro c,
apply eq_of_forall_ge_iff, intro z,
simp only [inf_le_iff, hf c, hg c, ωSup_le_iff, ←forall_or_distrib_left, ←forall_or_distrib_right,
function.comp_app, chain.map_coe, order_hom.has_inf_inf_coe],
split,
{ introv h, apply h },
{ intros h i j,
apply or.imp _ _ (h (max i j)); apply le_trans; mono*; try { exact le_rfl },
{ apply le_max_left },
{ apply le_max_right }, },
end
lemma inf_continuous' [is_total β (≤)] {f g : α → β} (hf : continuous' f) (hg : continuous' g) :
continuous' (f ⊓ g) :=
⟨_, inf_continuous _ _ hf.snd hg.snd⟩
lemma Sup_continuous (s : set $ α →o β) (hs : ∀ f ∈ s, continuous f) :
continuous (Sup s) :=
begin
intro c, apply eq_of_forall_ge_iff, intro z,
suffices : (∀ (f ∈ s) n, (f : _) (c n) ≤ z) ↔ (∀ n (f ∈ s), (f : _) (c n) ≤ z),
by simpa [ωSup_le_iff, hs _ _ _] { contextual := tt },
exact ⟨λ H n f hf, H f hf n, λ H f hf n, H n f hf⟩
end
lemma supr_continuous {ι : Sort*} {f : ι → α →o β} (h : ∀ i, continuous (f i)) :
continuous (⨆ i, f i) :=
Sup_continuous _ $ set.forall_range_iff.2 h
theorem Sup_continuous' (s : set (α → β)) (hc : ∀ f ∈ s, continuous' f) :
continuous' (Sup s) :=
begin
lift s to set (α →o β) using λ f hf, (hc f hf).to_monotone,
simp only [set.ball_image_iff, continuous'_coe] at hc,
rw [Sup_image],
norm_cast,
exact supr_continuous (λ f, supr_continuous (λ hf, hc f hf)),
end
lemma sup_continuous {f g : α →o β} (hf : continuous f) (hg : continuous g) :
continuous (f ⊔ g) :=
begin
rw ← Sup_pair, apply Sup_continuous,
rintro f (rfl|rfl|_); assumption
end
lemma top_continuous :
continuous (⊤ : α →o β) :=
begin
intro c, apply eq_of_forall_ge_iff, intro z,
simp only [ωSup_le_iff, forall_const, chain.map_coe, (∘), function.const,
order_hom.has_top_top, order_hom.const_coe_coe],
end
lemma bot_continuous :
continuous (⊥ : α →o β) :=
begin
rw ← Sup_empty,
exact Sup_continuous _ (λ f hf, hf.elim),
end
end complete_lattice
namespace omega_complete_partial_order
variables {α : Type u} {α' : Type*} {β : Type v} {β' : Type*} {γ : Type*} {φ : Type*}
variables [omega_complete_partial_order α] [omega_complete_partial_order β]
variables [omega_complete_partial_order γ] [omega_complete_partial_order φ]
variables [omega_complete_partial_order α'] [omega_complete_partial_order β']
namespace order_hom
/-- The `ωSup` operator for monotone functions. -/
@[simps]
protected def ωSup (c : chain (α →o β)) : α →o β :=
{ to_fun := λ a, ωSup (c.map (order_hom.apply a)),
monotone' := λ x y h, ωSup_le_ωSup_of_le (chain.map_le_map _ $ λ a, a.monotone h) }
@[simps ωSup_coe]
instance omega_complete_partial_order : omega_complete_partial_order (α →o β) :=
omega_complete_partial_order.lift order_hom.coe_fn_hom order_hom.ωSup
(λ x y h, h) (λ c, rfl)
end order_hom
section
variables (α β)
/-- A monotone function on `ω`-continuous partial orders is said to be continuous
if for every chain `c : chain α`, `f (⊔ i, c i) = ⊔ i, f (c i)`.
This is just the bundled version of `order_hom.continuous`. -/
structure continuous_hom extends order_hom α β :=
(cont : continuous (order_hom.mk to_fun monotone'))
attribute [nolint doc_blame] continuous_hom.to_order_hom
infixr ` →𝒄 `:25 := continuous_hom -- Input: \r\MIc
instance : has_coe_to_fun (α →𝒄 β) (λ _, α → β) := ⟨λ f, f.to_order_hom.to_fun⟩
instance : has_coe (α →𝒄 β) (α →o β) :=
{ coe := continuous_hom.to_order_hom }
instance : partial_order (α →𝒄 β) :=
partial_order.lift (λ f, f.to_order_hom.to_fun) $ by rintro ⟨⟨⟩⟩ ⟨⟨⟩⟩ h; congr; exact h
/-- See Note [custom simps projection]. We need to specify this projection explicitly in this case,
because it is a composition of multiple projections. -/
def continuous_hom.simps.apply (h : α →𝒄 β) : α → β := h
initialize_simps_projections continuous_hom
(to_order_hom_to_fun → apply, -to_order_hom)
end
namespace continuous_hom
theorem congr_fun {f g : α →𝒄 β} (h : f = g) (x : α) : f x = g x :=
congr_arg (λ h : α →𝒄 β, h x) h
theorem congr_arg (f : α →𝒄 β) {x y : α} (h : x = y) : f x = f y :=
congr_arg (λ x : α, f x) h
protected lemma monotone (f : α →𝒄 β) : monotone f := f.monotone'
@[mono] lemma apply_mono {f g : α →𝒄 β} {x y : α} (h₁ : f ≤ g) (h₂ : x ≤ y) : f x ≤ g y :=
order_hom.apply_mono (show (f : α →o β) ≤ g, from h₁) h₂
lemma ite_continuous' {p : Prop} [hp : decidable p] (f g : α → β)
(hf : continuous' f) (hg : continuous' g) : continuous' (λ x, if p then f x else g x) :=
by split_ifs; simp *
lemma ωSup_bind {β γ : Type v} (c : chain α) (f : α →o part β) (g : α →o β → part γ) :
ωSup (c.map (f.bind g)) = ωSup (c.map f) >>= ωSup (c.map g) :=
begin
apply eq_of_forall_ge_iff, intro x,
simp only [ωSup_le_iff, part.bind_le, chain.mem_map_iff, and_imp, order_hom.bind_coe,
exists_imp_distrib],
split; intro h''',
{ intros b hb, apply ωSup_le _ _ _,
rintros i y hy, simp only [part.mem_ωSup] at hb,
rcases hb with ⟨j,hb⟩, replace hb := hb.symm,
simp only [part.eq_some_iff, chain.map_coe, function.comp_app, order_hom.apply_coe]
at hy hb,
replace hb : b ∈ f (c (max i j)) := f.mono (c.mono (le_max_right i j)) _ hb,
replace hy : y ∈ g (c (max i j)) b := g.mono (c.mono (le_max_left i j)) _ _ hy,
apply h''' (max i j),
simp only [exists_prop, part.bind_eq_bind, part.mem_bind_iff, chain.map_coe,
function.comp_app, order_hom.bind_coe],
exact ⟨_,hb,hy⟩, },
{ intros i, intros y hy,
simp only [exists_prop, part.bind_eq_bind, part.mem_bind_iff, chain.map_coe,
function.comp_app, order_hom.bind_coe] at hy,
rcases hy with ⟨b,hb₀,hb₁⟩,
apply h''' b _,
{ apply le_ωSup (c.map g) _ _ _ hb₁ },
{ apply le_ωSup (c.map f) i _ hb₀ } },
end
lemma bind_continuous' {β γ : Type v} (f : α → part β) (g : α → β → part γ) :
continuous' f → continuous' g →
continuous' (λ x, f x >>= g x)
| ⟨hf,hf'⟩ ⟨hg,hg'⟩ :=
continuous.of_bundled' (order_hom.bind ⟨f,hf⟩ ⟨g,hg⟩)
(by intro c; rw [ωSup_bind, ← hf', ← hg']; refl)
lemma map_continuous' {β γ : Type v} (f : β → γ) (g : α → part β)
(hg : continuous' g) :
continuous' (λ x, f <$> g x) :=
by simp only [map_eq_bind_pure_comp];
apply bind_continuous' _ _ hg;
apply const_continuous'
lemma seq_continuous' {β γ : Type v} (f : α → part (β → γ)) (g : α → part β)
(hf : continuous' f) (hg : continuous' g) :
continuous' (λ x, f x <*> g x) :=
by simp only [seq_eq_bind_map];
apply bind_continuous' _ _ hf;
apply pi.omega_complete_partial_order.flip₂_continuous'; intro;
apply map_continuous' _ _ hg
lemma continuous (F : α →𝒄 β) (C : chain α) : F (ωSup C) = ωSup (C.map F) :=
continuous_hom.cont _ _
/-- Construct a continuous function from a bare function, a continuous function, and a proof that
they are equal. -/
@[simps, reducible]
def of_fun (f : α → β) (g : α →𝒄 β) (h : f = g) : α →𝒄 β :=
by refine {to_order_hom := {to_fun := f, ..}, ..}; subst h; rcases g with ⟨⟨⟩⟩; assumption
/-- Construct a continuous function from a monotone function with a proof of continuity. -/
@[simps, reducible]
def of_mono (f : α →o β) (h : ∀ c : chain α, f (ωSup c) = ωSup (c.map f)) : α →𝒄 β :=
{ to_fun := f,
monotone' := f.monotone,
cont := h }
/-- The identity as a continuous function. -/
@[simps]
def id : α →𝒄 α :=
of_mono order_hom.id continuous_id
/-- The composition of continuous functions. -/
@[simps]
def comp (f : β →𝒄 γ) (g : α →𝒄 β) : α →𝒄 γ :=
of_mono (order_hom.comp (↑f) (↑g)) (continuous_comp _ _ g.cont f.cont)
@[ext]
protected lemma ext (f g : α →𝒄 β) (h : ∀ x, f x = g x) : f = g :=
by cases f; cases g; congr; ext; apply h
protected lemma coe_inj (f g : α →𝒄 β) (h : (f : α → β) = g) : f = g :=
continuous_hom.ext _ _ $ _root_.congr_fun h
@[simp]
lemma comp_id (f : β →𝒄 γ) : f.comp id = f := by ext; refl
@[simp]
lemma id_comp (f : β →𝒄 γ) : id.comp f = f := by ext; refl
@[simp]
lemma comp_assoc (f : γ →𝒄 φ) (g : β →𝒄 γ) (h : α →𝒄 β) : f.comp (g.comp h) = (f.comp g).comp h :=
by ext; refl
@[simp]
lemma coe_apply (a : α) (f : α →𝒄 β) : (f : α →o β) a = f a := rfl
/-- `function.const` is a continuous function. -/
def const (x : β) : α →𝒄 β :=
of_mono (order_hom.const _ x) (continuous_const x)
@[simp] theorem const_apply (f : β) (a : α) : const f a = f := rfl
instance [inhabited β] : inhabited (α →𝒄 β) :=
⟨ const default ⟩
namespace prod
/-- The application of continuous functions as a monotone function.
(It would make sense to make it a continuous function, but we are currently constructing a
`omega_complete_partial_order` instance for `α →𝒄 β`, and we cannot use it as the domain or image
of a continuous function before we do.) -/
@[simps]
def apply : (α →𝒄 β) × α →o β :=
{ to_fun := λ f, f.1 f.2,
monotone' := λ x y h, by dsimp; transitivity y.fst x.snd; [apply h.1, apply y.1.monotone h.2] }
end prod
/-- The map from continuous functions to monotone functions is itself a monotone function. -/
@[simps]
def to_mono : (α →𝒄 β) →o (α →o β) :=
{ to_fun := λ f, f,
monotone' := λ x y h, h }
/-- When proving that a chain of applications is below a bound `z`, it suffices to consider the
functions and values being selected from the same index in the chains.
This lemma is more specific than necessary, i.e. `c₀` only needs to be a
chain of monotone functions, but it is only used with continuous functions. -/
@[simp]
lemma forall_forall_merge (c₀ : chain (α →𝒄 β)) (c₁ : chain α) (z : β) :
(∀ (i j : ℕ), (c₀ i) (c₁ j) ≤ z) ↔ ∀ (i : ℕ), (c₀ i) (c₁ i) ≤ z :=
begin
split; introv h,
{ apply h },
{ apply le_trans _ (h (max i j)),
transitivity c₀ i (c₁ (max i j)),
{ apply (c₀ i).monotone, apply c₁.monotone, apply le_max_right },
{ apply c₀.monotone, apply le_max_left } }
end
@[simp]
lemma forall_forall_merge' (c₀ : chain (α →𝒄 β)) (c₁ : chain α) (z : β) :
(∀ (j i : ℕ), (c₀ i) (c₁ j) ≤ z) ↔ ∀ (i : ℕ), (c₀ i) (c₁ i) ≤ z :=
by rw [forall_swap,forall_forall_merge]
/-- The `ωSup` operator for continuous functions, which takes the pointwise countable supremum
of the functions in the `ω`-chain. -/
@[simps]
protected def ωSup (c : chain (α →𝒄 β)) : α →𝒄 β :=
continuous_hom.of_mono (ωSup $ c.map to_mono)
begin
intro c',
apply eq_of_forall_ge_iff, intro z,
simp only [ωSup_le_iff, (c _).continuous, chain.map_coe, order_hom.apply_coe,
to_mono_coe, coe_apply, order_hom.omega_complete_partial_order_ωSup_coe,
forall_forall_merge, forall_forall_merge', (∘), function.eval],
end
@[simps ωSup]
instance : omega_complete_partial_order (α →𝒄 β) :=
omega_complete_partial_order.lift continuous_hom.to_mono continuous_hom.ωSup
(λ x y h, h) (λ c, rfl)
lemma ωSup_def (c : chain (α →𝒄 β)) (x : α) : ωSup c x = continuous_hom.ωSup c x := rfl
lemma ωSup_ωSup (c₀ : chain (α →𝒄 β)) (c₁ : chain α) :
ωSup c₀ (ωSup c₁) = ωSup (continuous_hom.prod.apply.comp $ c₀.zip c₁) :=
begin
apply eq_of_forall_ge_iff, intro z,
simp only [ωSup_le_iff, (c₀ _).continuous, chain.map_coe, to_mono_coe, coe_apply,
order_hom.omega_complete_partial_order_ωSup_coe, ωSup_def, forall_forall_merge,
chain.zip_coe, order_hom.prod_map_coe, order_hom.diag_coe, prod.map_mk,
order_hom.apply_coe, function.comp_app, prod.apply_coe,
order_hom.comp_coe, ωSup_apply, function.eval],
end
/-- A family of continuous functions yields a continuous family of functions. -/
@[simps]
def flip {α : Type*} (f : α → β →𝒄 γ) : β →𝒄 α → γ :=
{ to_fun := λ x y, f y x,
monotone' := λ x y h a, (f a).monotone h,
cont := by intro; ext; change f x _ = _; rw [(f x).continuous ]; refl, }
/-- `part.bind` as a continuous function. -/
@[simps { rhs_md := reducible }]
noncomputable def bind {β γ : Type v}
(f : α →𝒄 part β) (g : α →𝒄 β → part γ) : α →𝒄 part γ :=
of_mono (order_hom.bind (↑f) (↑g)) $ λ c, begin
rw [order_hom.bind, ← order_hom.bind, ωSup_bind, ← f.continuous, ← g.continuous],
refl
end
/-- `part.map` as a continuous function. -/
@[simps {rhs_md := reducible}]
noncomputable def map {β γ : Type v} (f : β → γ) (g : α →𝒄 part β) : α →𝒄 part γ :=
of_fun (λ x, f <$> g x) (bind g (const (pure ∘ f))) $
by ext; simp only [map_eq_bind_pure_comp, bind_apply, order_hom.bind_coe, const_apply,
order_hom.const_coe_coe, coe_apply]
/-- `part.seq` as a continuous function. -/
@[simps {rhs_md := reducible}]
noncomputable def seq {β γ : Type v} (f : α →𝒄 part (β → γ)) (g : α →𝒄 part β) :
α →𝒄 part γ :=
of_fun (λ x, f x <*> g x) (bind f $ (flip $ _root_.flip map g))
(by ext; simp only [seq_eq_bind_map, flip, part.bind_eq_bind, map_apply, part.mem_bind_iff,
bind_apply, order_hom.bind_coe, coe_apply, flip_apply]; refl)
end continuous_hom
end omega_complete_partial_order
|
4adcddb6cd971bbf078a4d4785986707d5e347a4 | 56e5b79a7ab4f2c52e6eb94f76d8100a25273cf3 | /src/utils/default.lean | 37d33e667e90f3803c95c5814b1370fa9cbaebed | [
"Apache-2.0"
] | permissive | DyeKuu/lean-tpe-public | 3a9968f286ca182723ef7e7d97e155d8cb6b1e70 | 750ade767ab28037e80b7a80360d213a875038f8 | refs/heads/master | 1,682,842,633,115 | 1,621,330,793,000 | 1,621,330,793,000 | 368,475,816 | 0 | 0 | Apache-2.0 | 1,621,330,745,000 | 1,621,330,744,000 | null | UTF-8 | Lean | false | false | 39 | lean | import .util
import .sexp
import .json
|
967d4bcc850fb9f33b3924619aceb0f7bda0d0bb | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/representation_theory/Action.lean | df29ca63dca5a3da4acb4a9de903a351881ccfd8 | [
"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 | 28,698 | 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.category.Group.basic
import category_theory.single_obj
import category_theory.limits.functor_category
import category_theory.limits.preserves.basic
import category_theory.adjunction.limits
import category_theory.monoidal.functor_category
import category_theory.monoidal.transport
import category_theory.monoidal.rigid.of_equivalence
import category_theory.monoidal.rigid.functor_category
import category_theory.monoidal.linear
import category_theory.monoidal.braided
import category_theory.monoidal.types.symmetric
import category_theory.abelian.functor_category
import category_theory.abelian.transfer
import category_theory.conj
import category_theory.linear.functor_category
/-!
# `Action V G`, the category of actions of a monoid `G` inside some category `V`.
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
The prototypical example is `V = Module R`,
where `Action (Module R) G` is the category of `R`-linear representations of `G`.
We check `Action V G ≌ (single_obj G ⥤ V)`,
and construct the restriction functors `res {G H : Mon} (f : G ⟶ H) : Action V H ⥤ Action V G`.
* When `V` has (co)limits so does `Action V G`.
* When `V` is monoidal, braided, or symmetric, so is `Action V G`.
* When `V` is preadditive, linear, or abelian so is `Action V G`.
-/
universes u v
open category_theory
open category_theory.limits
variables (V : Type (u+1)) [large_category V]
/--
An `Action V G` represents a bundled action of
the monoid `G` on an object of some category `V`.
As an example, when `V = Module R`, this is an `R`-linear representation of `G`,
while when `V = Type` this is a `G`-action.
-/
-- Note: this is _not_ a categorical action of `G` on `V`.
structure Action (G : Mon.{u}) :=
(V : V)
(ρ : G ⟶ Mon.of (End V))
namespace Action
variable {V}
@[simp]
lemma ρ_one {G : Mon.{u}} (A : Action V G) : A.ρ 1 = 𝟙 A.V :=
by { rw [monoid_hom.map_one], refl, }
/-- When a group acts, we can lift the action to the group of automorphisms. -/
@[simps]
def ρ_Aut {G : Group.{u}} (A : Action V (Mon.of G)) : G ⟶ Group.of (Aut A.V) :=
{ to_fun := λ g,
{ hom := A.ρ g,
inv := A.ρ (g⁻¹ : G),
hom_inv_id' := ((A.ρ).map_mul (g⁻¹ : G) g).symm.trans (by rw [inv_mul_self, ρ_one]),
inv_hom_id' := ((A.ρ).map_mul g (g⁻¹ : G)).symm.trans (by rw [mul_inv_self, ρ_one]), },
map_one' := by { ext, exact A.ρ.map_one },
map_mul' := λ x y, by { ext, exact A.ρ.map_mul x y }, }
variable (G : Mon.{u})
section
instance inhabited' : inhabited (Action (Type u) G) := ⟨⟨punit, 1⟩⟩
/-- The trivial representation of a group. -/
def trivial : Action AddCommGroup G :=
{ V := AddCommGroup.of punit,
ρ := 1, }
instance : inhabited (Action AddCommGroup G) := ⟨trivial G⟩
end
variables {G V}
/--
A homomorphism of `Action V G`s is a morphism between the underlying objects,
commuting with the action of `G`.
-/
@[ext]
structure hom (M N : Action V G) :=
(hom : M.V ⟶ N.V)
(comm' : ∀ g : G, M.ρ g ≫ hom = hom ≫ N.ρ g . obviously)
restate_axiom hom.comm'
namespace hom
/-- The identity morphism on a `Action V G`. -/
@[simps]
def id (M : Action V G) : Action.hom M M :=
{ hom := 𝟙 M.V }
instance (M : Action V G) : inhabited (Action.hom M M) := ⟨id M⟩
/--
The composition of two `Action V G` homomorphisms is the composition of the underlying maps.
-/
@[simps]
def comp {M N K : Action V G} (p : Action.hom M N) (q : Action.hom N K) :
Action.hom M K :=
{ hom := p.hom ≫ q.hom,
comm' := λ g, by rw [←category.assoc, p.comm, category.assoc, q.comm, ←category.assoc] }
end hom
instance : category (Action V G) :=
{ hom := λ M N, hom M N,
id := λ M, hom.id M,
comp := λ M N K f g, hom.comp f g, }
@[simp]
lemma id_hom (M : Action V G) : (𝟙 M : hom M M).hom = 𝟙 M.V := rfl
@[simp]
lemma comp_hom {M N K : Action V G} (f : M ⟶ N) (g : N ⟶ K) :
(f ≫ g : hom M K).hom = f.hom ≫ g.hom :=
rfl
/-- Construct an isomorphism of `G` actions/representations
from an isomorphism of the the underlying objects,
where the forward direction commutes with the group action. -/
@[simps]
def mk_iso {M N : Action V G} (f : M.V ≅ N.V) (comm : ∀ g : G, M.ρ g ≫ f.hom = f.hom ≫ N.ρ g) :
M ≅ N :=
{ hom :=
{ hom := f.hom,
comm' := comm, },
inv :=
{ hom := f.inv,
comm' := λ g, by { have w := comm g =≫ f.inv, simp at w, simp [w], }, }}
@[priority 100]
instance is_iso_of_hom_is_iso {M N : Action V G} (f : M ⟶ N) [is_iso f.hom] : is_iso f :=
by { convert is_iso.of_iso (mk_iso (as_iso f.hom) f.comm), ext, refl, }
instance is_iso_hom_mk {M N : Action V G} (f : M.V ⟶ N.V) [is_iso f] (w) :
@is_iso _ _ M N ⟨f, w⟩ :=
is_iso.of_iso (mk_iso (as_iso f) w)
namespace functor_category_equivalence
/-- Auxilliary definition for `functor_category_equivalence`. -/
@[simps]
def functor : Action V G ⥤ (single_obj G ⥤ V) :=
{ obj := λ M,
{ obj := λ _, M.V,
map := λ _ _ g, M.ρ g,
map_id' := λ _, M.ρ.map_one,
map_comp' := λ _ _ _ g h, M.ρ.map_mul h g, },
map := λ M N f,
{ app := λ _, f.hom,
naturality' := λ _ _ g, f.comm g, } }
/-- Auxilliary definition for `functor_category_equivalence`. -/
@[simps]
def inverse : (single_obj G ⥤ V) ⥤ Action V G :=
{ obj := λ F,
{ V := F.obj punit.star,
ρ :=
{ to_fun := λ g, F.map g,
map_one' := F.map_id punit.star,
map_mul' := λ g h, F.map_comp h g, } },
map := λ M N f,
{ hom := f.app punit.star,
comm' := λ g, f.naturality g, } }.
/-- Auxilliary definition for `functor_category_equivalence`. -/
@[simps]
def unit_iso : 𝟭 (Action V G) ≅ functor ⋙ inverse :=
nat_iso.of_components (λ M, mk_iso ((iso.refl _)) (by tidy)) (by tidy).
/-- Auxilliary definition for `functor_category_equivalence`. -/
@[simps]
def counit_iso : inverse ⋙ functor ≅ 𝟭 (single_obj G ⥤ V) :=
nat_iso.of_components (λ M, nat_iso.of_components (by tidy) (by tidy)) (by tidy).
end functor_category_equivalence
section
open functor_category_equivalence
variables (V G)
/--
The category of actions of `G` in the category `V`
is equivalent to the functor category `single_obj G ⥤ V`.
-/
def functor_category_equivalence : Action V G ≌ (single_obj G ⥤ V) :=
{ functor := functor,
inverse := inverse,
unit_iso := unit_iso,
counit_iso := counit_iso, }
attribute [simps] functor_category_equivalence
lemma functor_category_equivalence.functor_def :
(functor_category_equivalence V G).functor = functor_category_equivalence.functor := rfl
lemma functor_category_equivalence.inverse_def :
(functor_category_equivalence V G).inverse = functor_category_equivalence.inverse := rfl
instance [has_finite_products V] : has_finite_products (Action V G) :=
{ out := λ n, adjunction.has_limits_of_shape_of_equivalence
(Action.functor_category_equivalence _ _).functor }
instance [has_finite_limits V] : has_finite_limits (Action V G) :=
{ out := λ J _ _, by exactI adjunction.has_limits_of_shape_of_equivalence
(Action.functor_category_equivalence _ _).functor }
instance [has_limits V] : has_limits (Action V G) :=
adjunction.has_limits_of_equivalence (Action.functor_category_equivalence _ _).functor
instance [has_colimits V] : has_colimits (Action V G) :=
adjunction.has_colimits_of_equivalence (Action.functor_category_equivalence _ _).functor
end
section forget
variables (V G)
/-- (implementation) The forgetful functor from bundled actions to the underlying objects.
Use the `category_theory.forget` API provided by the `concrete_category` instance below,
rather than using this directly.
-/
@[simps]
def forget : Action V G ⥤ V :=
{ obj := λ M, M.V,
map := λ M N f, f.hom, }
instance : faithful (forget V G) :=
{ map_injective' := λ X Y f g w, hom.ext _ _ w, }
instance [concrete_category V] : concrete_category (Action V G) :=
{ forget := forget V G ⋙ (concrete_category.forget V), }
instance has_forget_to_V [concrete_category V] : has_forget₂ (Action V G) V :=
{ forget₂ := forget V G }
/-- The forgetful functor is intertwined by `functor_category_equivalence` with
evaluation at `punit.star`. -/
def functor_category_equivalence_comp_evaluation :
(functor_category_equivalence V G).functor ⋙ (evaluation _ _).obj punit.star ≅ forget V G :=
iso.refl _
noncomputable instance [has_limits V] : limits.preserves_limits (forget V G) :=
limits.preserves_limits_of_nat_iso
(Action.functor_category_equivalence_comp_evaluation V G)
noncomputable instance [has_colimits V] : preserves_colimits (forget V G) :=
preserves_colimits_of_nat_iso
(Action.functor_category_equivalence_comp_evaluation V G)
-- TODO construct categorical images?
end forget
lemma iso.conj_ρ {M N : Action V G} (f : M ≅ N) (g : G) :
N.ρ g = (((forget V G).map_iso f).conj (M.ρ g)) :=
by { rw [iso.conj_apply, iso.eq_inv_comp], simp [f.hom.comm'] }
section has_zero_morphisms
variables [has_zero_morphisms V]
instance : has_zero_morphisms (Action V G) :=
{ has_zero := λ X Y, ⟨⟨0, by { intro g, simp }⟩⟩,
comp_zero' := λ P Q f R, by { ext1, simp },
zero_comp' := λ P Q R f, by { ext1, simp }, }
instance forget_preserves_zero_morphisms : functor.preserves_zero_morphisms (forget V G) := {}
instance forget₂_preserves_zero_morphisms [concrete_category V] :
functor.preserves_zero_morphisms (forget₂ (Action V G) V) := {}
instance functor_category_equivalence_preserves_zero_morphisms :
functor.preserves_zero_morphisms (functor_category_equivalence V G).functor := {}
end has_zero_morphisms
section preadditive
variables [preadditive V]
instance : preadditive (Action V G) :=
{ hom_group := λ X Y,
{ zero := ⟨0, by simp⟩,
add := λ f g, ⟨f.hom + g.hom, by simp [f.comm, g.comm]⟩,
neg := λ f, ⟨-f.hom, by simp [f.comm]⟩,
zero_add := by { intros, ext, exact zero_add _, },
add_zero := by { intros, ext, exact add_zero _, },
add_assoc := by { intros, ext, exact add_assoc _ _ _, },
add_left_neg := by { intros, ext, exact add_left_neg _, },
add_comm := by { intros, ext, exact add_comm _ _, }, },
add_comp' := by { intros, ext, exact preadditive.add_comp _ _ _ _ _ _, },
comp_add' := by { intros, ext, exact preadditive.comp_add _ _ _ _ _ _, }, }
instance forget_additive :
functor.additive (forget V G) := {}
instance forget₂_additive [concrete_category V] :
functor.additive (forget₂ (Action V G) V) := {}
instance functor_category_equivalence_additive :
functor.additive (functor_category_equivalence V G).functor := {}
@[simp] lemma zero_hom {X Y : Action V G} : (0 : X ⟶ Y).hom = 0 := rfl
@[simp] lemma neg_hom {X Y : Action V G} (f : X ⟶ Y) : (-f).hom = -f.hom := rfl
@[simp] lemma add_hom {X Y : Action V G} (f g : X ⟶ Y) : (f + g).hom = f.hom + g.hom := rfl
@[simp] lemma sum_hom {X Y : Action V G} {ι : Type*} (f : ι → (X ⟶ Y)) (s : finset ι) :
(s.sum f).hom = s.sum (λ i, (f i).hom) := (forget V G).map_sum f s
end preadditive
section linear
variables [preadditive V] {R : Type*} [semiring R] [linear R V]
instance : linear R (Action V G) :=
{ hom_module := λ X Y,
{ smul := λ r f, ⟨r • f.hom, by simp [f.comm]⟩,
one_smul := by { intros, ext, exact one_smul _ _, },
smul_zero := by { intros, ext, exact smul_zero _, },
zero_smul := by { intros, ext, exact zero_smul _ _, },
add_smul := by { intros, ext, exact add_smul _ _ _, },
smul_add := by { intros, ext, exact smul_add _ _ _, },
mul_smul := by { intros, ext, exact mul_smul _ _ _, }, },
smul_comp' := by { intros, ext, exact linear.smul_comp _ _ _ _ _ _, },
comp_smul' := by { intros, ext, exact linear.comp_smul _ _ _ _ _ _, }, }
instance forget_linear :
functor.linear R (forget V G) := {}
instance forget₂_linear [concrete_category V] :
functor.linear R (forget₂ (Action V G) V) := {}
instance functor_category_equivalence_linear :
functor.linear R (functor_category_equivalence V G).functor := {}
@[simp] lemma smul_hom {X Y : Action V G} (r : R) (f : X ⟶ Y) : (r • f).hom = r • f.hom := rfl
end linear
section abelian
/-- Auxilliary construction for the `abelian (Action V G)` instance. -/
def abelian_aux : Action V G ≌ (ulift.{u} (single_obj G) ⥤ V) :=
(functor_category_equivalence V G).trans (equivalence.congr_left ulift.equivalence)
noncomputable instance [abelian V] : abelian (Action V G) :=
abelian_of_equivalence abelian_aux.functor
end abelian
section monoidal
variables [monoidal_category V]
instance : monoidal_category (Action V G) :=
monoidal.transport (Action.functor_category_equivalence _ _).symm
@[simp] lemma tensor_unit_V : (𝟙_ (Action V G)).V = 𝟙_ V := rfl
@[simp] lemma tensor_unit_rho {g : G} : (𝟙_ (Action V G)).ρ g = 𝟙 (𝟙_ V) := rfl
@[simp] lemma tensor_V {X Y : Action V G} : (X ⊗ Y).V = X.V ⊗ Y.V := rfl
@[simp] lemma tensor_rho {X Y : Action V G} {g : G} : (X ⊗ Y).ρ g = X.ρ g ⊗ Y.ρ g := rfl
@[simp] lemma tensor_hom {W X Y Z : Action V G} (f : W ⟶ X) (g : Y ⟶ Z) :
(f ⊗ g).hom = f.hom ⊗ g.hom := rfl
@[simp] lemma associator_hom_hom {X Y Z : Action V G} :
hom.hom (α_ X Y Z).hom = (α_ X.V Y.V Z.V).hom :=
begin
dsimp [monoidal.transport_associator],
simp,
end
@[simp] lemma associator_inv_hom {X Y Z : Action V G} :
hom.hom (α_ X Y Z).inv = (α_ X.V Y.V Z.V).inv :=
begin
dsimp [monoidal.transport_associator],
simp,
end
@[simp] lemma left_unitor_hom_hom {X : Action V G} :
hom.hom (λ_ X).hom = (λ_ X.V).hom :=
begin
dsimp [monoidal.transport_left_unitor],
simp,
end
@[simp] lemma left_unitor_inv_hom {X : Action V G} :
hom.hom (λ_ X).inv = (λ_ X.V).inv :=
begin
dsimp [monoidal.transport_left_unitor],
simp,
end
@[simp] lemma right_unitor_hom_hom {X : Action V G} :
hom.hom (ρ_ X).hom = (ρ_ X.V).hom :=
begin
dsimp [monoidal.transport_right_unitor],
simp,
end
@[simp] lemma right_unitor_inv_hom {X : Action V G} :
hom.hom (ρ_ X).inv = (ρ_ X.V).inv :=
begin
dsimp [monoidal.transport_right_unitor],
simp,
end
/-- Given an object `X` isomorphic to the tensor unit of `V`, `X` equipped with the trivial action
is isomorphic to the tensor unit of `Action V G`. -/
def tensor_unit_iso {X : V} (f : 𝟙_ V ≅ X) :
𝟙_ (Action V G) ≅ Action.mk X 1 :=
Action.mk_iso f (λ g, by simp only [monoid_hom.one_apply, End.one_def, category.id_comp f.hom,
tensor_unit_rho, category.comp_id])
variables (V G)
/-- When `V` is monoidal the forgetful functor `Action V G` to `V` is monoidal. -/
@[simps]
def forget_monoidal : monoidal_functor (Action V G) V :=
{ ε := 𝟙 _,
μ := λ X Y, 𝟙 _,
..Action.forget _ _, }
instance forget_monoidal_faithful : faithful (forget_monoidal V G).to_functor :=
by { change faithful (forget V G), apply_instance, }
section
variables [braided_category V]
instance : braided_category (Action V G) :=
braided_category_of_faithful (forget_monoidal V G) (λ X Y, mk_iso (β_ _ _) (by tidy)) (by tidy)
/-- When `V` is braided the forgetful functor `Action V G` to `V` is braided. -/
@[simps]
def forget_braided : braided_functor (Action V G) V :=
{ ..forget_monoidal _ _, }
instance forget_braided_faithful : faithful (forget_braided V G).to_functor :=
by { change faithful (forget V G), apply_instance, }
end
instance [symmetric_category V] : symmetric_category (Action V G) :=
symmetric_category_of_faithful (forget_braided V G)
section
variables [preadditive V] [monoidal_preadditive V]
local attribute [simp] monoidal_preadditive.tensor_add monoidal_preadditive.add_tensor
instance : monoidal_preadditive (Action V G) := {}
variables {R : Type*} [semiring R] [linear R V] [monoidal_linear R V]
instance : monoidal_linear R (Action V G) := {}
end
variables (V G)
noncomputable theory
/-- Upgrading the functor `Action V G ⥤ (single_obj G ⥤ V)` to a monoidal functor. -/
def functor_category_monoidal_equivalence : monoidal_functor (Action V G) (single_obj G ⥤ V) :=
monoidal.from_transported (Action.functor_category_equivalence _ _).symm
instance : is_equivalence ((functor_category_monoidal_equivalence V G).to_functor) :=
by { change is_equivalence (Action.functor_category_equivalence _ _).functor, apply_instance, }
@[simp] lemma functor_category_monoidal_equivalence.μ_app (A B : Action V G) :
((functor_category_monoidal_equivalence V G).μ A B).app punit.star = 𝟙 _ :=
begin
dunfold functor_category_monoidal_equivalence,
simp only [monoidal.from_transported_to_lax_monoidal_functor_μ],
show (𝟙 A.V ⊗ 𝟙 B.V) ≫ 𝟙 (A.V ⊗ B.V) ≫ (𝟙 A.V ⊗ 𝟙 B.V) = 𝟙 (A.V ⊗ B.V),
simp only [monoidal_category.tensor_id, category.comp_id],
end
@[simp] lemma functor_category_monoidal_equivalence.μ_iso_inv_app (A B : Action V G) :
((functor_category_monoidal_equivalence V G).μ_iso A B).inv.app punit.star = 𝟙 _ :=
begin
rw [←nat_iso.app_inv, ←is_iso.iso.inv_hom],
refine is_iso.inv_eq_of_hom_inv_id _,
rw [category.comp_id, nat_iso.app_hom, monoidal_functor.μ_iso_hom,
functor_category_monoidal_equivalence.μ_app],
end
@[simp] lemma functor_category_monoidal_equivalence.ε_app :
(functor_category_monoidal_equivalence V G).ε.app punit.star = 𝟙 _ :=
begin
dunfold functor_category_monoidal_equivalence,
simp only [monoidal.from_transported_to_lax_monoidal_functor_ε],
show 𝟙 (monoidal_category.tensor_unit V) ≫ _ = 𝟙 (monoidal_category.tensor_unit V),
rw [nat_iso.is_iso_inv_app, category.id_comp],
exact is_iso.inv_id,
end
@[simp] lemma functor_category_monoidal_equivalence.inv_counit_app_hom (A : Action V G) :
((functor_category_monoidal_equivalence _ _).inv.adjunction.counit.app A).hom = 𝟙 _ :=
rfl
@[simp] lemma functor_category_monoidal_equivalence.counit_app (A : single_obj G ⥤ V) :
((functor_category_monoidal_equivalence _ _).adjunction.counit.app A).app punit.star = 𝟙 _ := rfl
@[simp] lemma functor_category_monoidal_equivalence.inv_unit_app_app
(A : single_obj G ⥤ V) :
((functor_category_monoidal_equivalence _ _).inv.adjunction.unit.app A).app
punit.star = 𝟙 _ := rfl
@[simp] lemma functor_category_monoidal_equivalence.unit_app_hom (A : Action V G) :
((functor_category_monoidal_equivalence _ _).adjunction.unit.app A).hom = 𝟙 _ :=
rfl
@[simp] lemma functor_category_monoidal_equivalence.functor_map {A B : Action V G} (f : A ⟶ B) :
(functor_category_monoidal_equivalence _ _).map f
= functor_category_equivalence.functor.map f := rfl
@[simp] lemma functor_category_monoidal_equivalence.inverse_map
{A B : single_obj G ⥤ V} (f : A ⟶ B) :
(functor_category_monoidal_equivalence _ _).inv.map f
= functor_category_equivalence.inverse.map f := rfl
variables (H : Group.{u})
instance [right_rigid_category V] : right_rigid_category (single_obj (H : Mon.{u}) ⥤ V) :=
by { change right_rigid_category (single_obj H ⥤ V), apply_instance }
/-- If `V` is right rigid, so is `Action V G`. -/
instance [right_rigid_category V] : right_rigid_category (Action V H) :=
right_rigid_category_of_equivalence (functor_category_monoidal_equivalence V _)
instance [left_rigid_category V] : left_rigid_category (single_obj (H : Mon.{u}) ⥤ V) :=
by { change left_rigid_category (single_obj H ⥤ V), apply_instance }
/-- If `V` is left rigid, so is `Action V G`. -/
instance [left_rigid_category V] : left_rigid_category (Action V H) :=
left_rigid_category_of_equivalence (functor_category_monoidal_equivalence V _)
instance [rigid_category V] : rigid_category (single_obj (H : Mon.{u}) ⥤ V) :=
by { change rigid_category (single_obj H ⥤ V), apply_instance }
/-- If `V` is rigid, so is `Action V G`. -/
instance [rigid_category V] : rigid_category (Action V H) :=
rigid_category_of_equivalence (functor_category_monoidal_equivalence V _)
variables {V H} (X : Action V H)
@[simp] lemma right_dual_V [right_rigid_category V] : (Xᘁ).V = (X.V)ᘁ := rfl
@[simp] lemma left_dual_V [left_rigid_category V] : (ᘁX).V = ᘁ(X.V) := rfl
@[simp] lemma right_dual_ρ [right_rigid_category V] (h : H) : (Xᘁ).ρ h = (X.ρ (h⁻¹ : H))ᘁ :=
by { rw ←single_obj.inv_as_inv, refl }
@[simp] lemma left_dual_ρ [left_rigid_category V] (h : H) : (ᘁX).ρ h = ᘁ(X.ρ (h⁻¹ : H)) :=
by { rw ←single_obj.inv_as_inv, refl }
end monoidal
/-- Actions/representations of the trivial group are just objects in the ambient category. -/
def Action_punit_equivalence : Action V (Mon.of punit) ≌ V :=
{ functor := forget V _,
inverse :=
{ obj := λ X, ⟨X, 1⟩,
map := λ X Y f, ⟨f, λ ⟨⟩, by simp⟩, },
unit_iso := nat_iso.of_components (λ X, mk_iso (iso.refl _) (λ ⟨⟩, by simpa using ρ_one X))
(by tidy),
counit_iso := nat_iso.of_components (λ X, iso.refl _) (by tidy), }
variables (V)
/--
The "restriction" functor along a monoid homomorphism `f : G ⟶ H`,
taking actions of `H` to actions of `G`.
(This makes sense for any homomorphism, but the name is natural when `f` is a monomorphism.)
-/
@[simps]
def res {G H : Mon} (f : G ⟶ H) : Action V H ⥤ Action V G :=
{ obj := λ M,
{ V := M.V,
ρ := f ≫ M.ρ },
map := λ M N p,
{ hom := p.hom,
comm' := λ g, p.comm (f g) } }
/--
The natural isomorphism from restriction along the identity homomorphism to
the identity functor on `Action V G`.
-/
def res_id {G : Mon} : res V (𝟙 G) ≅ 𝟭 (Action V G) :=
nat_iso.of_components (λ M, mk_iso (iso.refl _) (by tidy)) (by tidy)
attribute [simps] res_id
/--
The natural isomorphism from the composition of restrictions along homomorphisms
to the restriction along the composition of homomorphism.
-/
def res_comp {G H K : Mon} (f : G ⟶ H) (g : H ⟶ K) : res V g ⋙ res V f ≅ res V (f ≫ g) :=
nat_iso.of_components (λ M, mk_iso (iso.refl _) (by tidy)) (by tidy)
attribute [simps] res_comp
-- TODO promote `res` to a pseudofunctor from
-- the locally discrete bicategory constructed from `Monᵒᵖ` to `Cat`, sending `G` to `Action V G`.
variables {G} {H : Mon.{u}} (f : G ⟶ H)
instance res_additive [preadditive V] : (res V f).additive := {}
variables {R : Type*} [semiring R]
instance res_linear [preadditive V] [linear R V] : (res V f).linear R := {}
/-- Bundles a type `H` with a multiplicative action of `G` as an `Action`. -/
def of_mul_action (G H : Type u) [monoid G] [mul_action G H] : Action (Type u) (Mon.of G) :=
{ V := H,
ρ := @mul_action.to_End_hom _ _ _ (by assumption) }
@[simp] lemma of_mul_action_apply {G H : Type u} [monoid G] [mul_action G H] (g : G) (x : H) :
(of_mul_action G H).ρ g x = (g • x : H) :=
rfl
/-- Given a family `F` of types with `G`-actions, this is the limit cone demonstrating that the
product of `F` as types is a product in the category of `G`-sets. -/
def of_mul_action_limit_cone {ι : Type v} (G : Type (max v u)) [monoid G]
(F : ι → Type (max v u)) [Π i : ι, mul_action G (F i)] :
limit_cone (discrete.functor (λ i : ι, Action.of_mul_action G (F i))) :=
{ cone :=
{ X := Action.of_mul_action G (Π i : ι, F i),
π :=
{ app := λ i, ⟨λ x, x i.as, λ g, by ext; refl⟩,
naturality' := λ i j x,
begin
ext,
discrete_cases,
cases x,
congr
end } },
is_limit :=
{ lift := λ s,
{ hom := λ x i, (s.π.app ⟨i⟩).hom x,
comm' := λ g,
begin
ext x j,
dsimp,
exact congr_fun ((s.π.app ⟨j⟩).comm g) x,
end },
fac' := λ s j,
begin
ext,
dsimp,
congr,
rw discrete.mk_as,
end,
uniq' := λ s f h,
begin
ext x j,
dsimp at *,
rw ←h ⟨j⟩,
congr,
end } }
/-- The `G`-set `G`, acting on itself by left multiplication. -/
@[simps] def left_regular (G : Type u) [monoid G] : Action (Type u) (Mon.of G) :=
Action.of_mul_action G G
/-- The `G`-set `Gⁿ`, acting on itself by left multiplication. -/
@[simps] def diagonal (G : Type u) [monoid G] (n : ℕ) : Action (Type u) (Mon.of G) :=
Action.of_mul_action G (fin n → G)
/-- We have `fin 1 → G ≅ G` as `G`-sets, with `G` acting by left multiplication. -/
def diagonal_one_iso_left_regular (G : Type u) [monoid G] :
diagonal G 1 ≅ left_regular G := Action.mk_iso (equiv.fun_unique _ _).to_iso (λ g, rfl)
/-- Given `X : Action (Type u) (Mon.of G)` for `G` a group, then `G × X` (with `G` acting as left
multiplication on the first factor and by `X.ρ` on the second) is isomorphic as a `G`-set to
`G × X` (with `G` acting as left multiplication on the first factor and trivially on the second).
The isomorphism is given by `(g, x) ↦ (g, g⁻¹ • x)`. -/
@[simps] def left_regular_tensor_iso (G : Type u) [group G]
(X : Action (Type u) (Mon.of G)) :
left_regular G ⊗ X ≅ left_regular G ⊗ Action.mk X.V 1 :=
{ hom :=
{ hom := λ g, ⟨g.1, (X.ρ (g.1⁻¹ : G) g.2 : X.V)⟩,
comm' := λ g, funext $ λ x, prod.ext rfl $
show (X.ρ ((g * x.1)⁻¹ : G) * X.ρ g) x.2 = _,
by simpa only [mul_inv_rev, ←X.ρ.map_mul, inv_mul_cancel_right] },
inv :=
{ hom := λ g, ⟨g.1, X.ρ g.1 g.2⟩,
comm' := λ g, funext $ λ x, prod.ext rfl $
by simpa only [tensor_rho, types_comp_apply, tensor_apply, left_regular_ρ_apply, map_mul] },
hom_inv_id' := hom.ext _ _ (funext $ λ x, prod.ext rfl $
show (X.ρ x.1 * X.ρ (x.1⁻¹ : G)) x.2 = _,
by simpa only [←X.ρ.map_mul, mul_inv_self, X.ρ.map_one]),
inv_hom_id' := hom.ext _ _ (funext $ λ x, prod.ext rfl $
show (X.ρ (x.1⁻¹ : G) * X.ρ x.1) _ = _,
by simpa only [←X.ρ.map_mul, inv_mul_self, X.ρ.map_one]) }
/-- The natural isomorphism of `G`-sets `Gⁿ⁺¹ ≅ G × Gⁿ`, where `G` acts by left multiplication on
each factor. -/
@[simps] def diagonal_succ (G : Type u) [monoid G] (n : ℕ) :
diagonal G (n + 1) ≅ left_regular G ⊗ diagonal G n :=
mk_iso (equiv.pi_fin_succ_above_equiv _ 0).to_iso (λ g, rfl)
end Action
namespace category_theory.functor
variables {V} {W : Type (u+1)} [large_category W]
/-- A functor between categories induces a functor between
the categories of `G`-actions within those categories. -/
@[simps]
def map_Action (F : V ⥤ W) (G : Mon.{u}) : Action V G ⥤ Action W G :=
{ obj := λ M,
{ V := F.obj M.V,
ρ :=
{ to_fun := λ g, F.map (M.ρ g),
map_one' := by simp only [End.one_def, Action.ρ_one, F.map_id],
map_mul' := λ g h, by simp only [End.mul_def, F.map_comp, map_mul], }, },
map := λ M N f,
{ hom := F.map f.hom,
comm' := λ g, by { dsimp, rw [←F.map_comp, f.comm, F.map_comp], }, },
map_id' := λ M, by { ext, simp only [Action.id_hom, F.map_id], },
map_comp' := λ M N P f g, by { ext, simp only [Action.comp_hom, F.map_comp], }, }
variables (F : V ⥤ W) (G : Mon.{u}) [preadditive V] [preadditive W]
instance map_Action_preadditive [F.additive] : (F.map_Action G).additive := {}
variables {R : Type*} [semiring R] [category_theory.linear R V] [category_theory.linear R W]
instance map_Action_linear [F.additive] [F.linear R] : (F.map_Action G).linear R := {}
end category_theory.functor
namespace category_theory.monoidal_functor
open Action
variables {V} {W : Type (u+1)} [large_category W] [monoidal_category V] [monoidal_category W]
(F : monoidal_functor V W) (G : Mon.{u})
/-- A monoidal functor induces a monoidal functor between
the categories of `G`-actions within those categories. -/
@[simps] def map_Action :
monoidal_functor (Action V G) (Action W G) :=
{ ε :=
{ hom := F.ε,
comm' := λ g,
by { dsimp, erw [category.id_comp, category_theory.functor.map_id, category.comp_id], }, },
μ := λ X Y,
{ hom := F.μ X.V Y.V,
comm' := λ g, F.to_lax_monoidal_functor.μ_natural (X.ρ g) (Y.ρ g), },
ε_is_iso := by apply_instance,
μ_is_iso := by apply_instance,
μ_natural' := by { intros, ext, dsimp, simp, },
associativity' := by { intros, ext, dsimp, simp, dsimp, simp, }, -- See note [dsimp, simp].
left_unitality' := by { intros, ext, dsimp, simp, dsimp, simp, },
right_unitality' := by { intros, ext, dsimp, simp, dsimp, simp, },
..F.to_functor.map_Action G, }
@[simp] lemma map_Action_ε_inv_hom :
(inv (F.map_Action G).ε).hom = inv F.ε :=
begin
ext,
simp only [←F.map_Action_to_lax_monoidal_functor_ε_hom G, ←Action.comp_hom,
is_iso.hom_inv_id, id_hom],
end
@[simp] lemma map_Action_μ_inv_hom (X Y : Action V G) :
(inv ((F.map_Action G).μ X Y)).hom = inv (F.μ X.V Y.V) :=
begin
ext,
simpa only [←F.map_Action_to_lax_monoidal_functor_μ_hom G, ←Action.comp_hom,
is_iso.hom_inv_id, id_hom],
end
end category_theory.monoidal_functor
|
fd93326498c521112f2a544ee41906f6d4f3cf60 | cf39355caa609c0f33405126beee2739aa3cb77e | /tests/lean/run/ind_bug.lean | 246d30277b9fb2b51949136a25ebb31220372085 | [
"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 | 186 | lean | constant N : Type.{1}
constant I : Type.{1}
namespace foo
inductive p (a : N) : Prop
| intro : p
end foo
open foo
namespace bla
inductive p (a : I) : Prop
| intro : p
end bla
|
b9cf0d238c30724405780e4485249b79e7251e6c | d3aa99b88d7159fbbb8ab10d699374ab7be89e03 | /src/linear_algebra/basic.lean | 97466be75de7d926803ce48d1fe279f7c64ca714 | [
"Apache-2.0"
] | permissive | mzinkevi/mathlib | 62e0920edaf743f7fc53aaf42a08e372954af298 | c718a22925872db4cb5f64c36ed6e6a07bdf647c | refs/heads/master | 1,599,359,590,404 | 1,573,098,221,000 | 1,573,098,221,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 70,349 | lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro, Kevin Buzzard
-/
import algebra.pi_instances data.finsupp data.equiv.algebra order.order_iso
/-!
# Linear algebra
This file defines the basics of linear algebra. It sets up the "categorical/lattice structure" of
modules over a ring, submodules, and linear maps. If `p` and `q` are submodules of a module, `p ≤ q`
means that `p ⊆ q`.
Many of the relevant definitions, including `module`, `submodule`, and `linear_map`, are found in
`src/algebra/module.lean`.
## Main definitions
* Many constructors for linear maps, including `pair` and `copair`
* `submodule.span s` is defined to be the smallest submodule containing the set `s`.
* If `p` is a submodule of `M`, `submodule.quotient p` is the quotient of `M` with respect to `p`:
that is, elements of `M` are identified if their difference is in `p`. This is itself a module.
* The kernel `ker` and range `range` of a linear map are submodules of the domain and codomain
respectively.
* `lin_equiv M M₂`, the type of linear equivalences between `M` and `M₂`, is a structure that extends
`linear_map` and `equiv`.
* The general linear group is defined to be the group of invertible linear maps from `M` to itself.
## Main statements
* The first and second isomorphism laws for modules are proved as `quot_ker_equiv_range` and
`sup_quotient_equiv_quotient_inf`.
## Notations
* We continue to use the notation `M →ₗ[R] M₂` for the type of linear maps from `M` to `M₂` over the
ring `R`.
* We introduce the notations `M ≃ₗ M₂` and `M ≃ₗ[R] M₂` for `lin_equiv M M₂`. In the first, the ring
`R` is implicit.
## Implementation notes
We note that, when constructing linear maps, it is convenient to use operations defined on bundled
maps (`pair`, `copair`, arithmetic operations like `+`) instead of defining a function and proving
it is linear.
## Tags
linear algebra, vector space, module
-/
open function lattice
reserve infix ` ≃ₗ `:25
universes u v w x y z u' v' w' y'
variables {R : Type u} {K : Type u'} {M : Type v} {V : Type v'} {M₂ : Type w} {V₂ : Type w'}
variables {M₃ : Type y} {V₃ : Type y'} {M₄ : Type z} {ι : Type x}
namespace finset
lemma smul_sum {α : Type u} {M : Type v} {R : Type w}
[ring R] [add_comm_group M] [module R M]
{s : finset α} {a : R} {f : α → M} :
a • (s.sum f) = s.sum (λc, a • f c) :=
(finset.sum_hom ((•) a)).symm
end finset
namespace finsupp
lemma smul_sum {α : Type u} {β : Type v} {R : Type w} {M : Type y}
[has_zero β] [ring R] [add_comm_group M] [module R M]
{v : α →₀ β} {c : R} {h : α → β → M} :
c • (v.sum h) = v.sum (λa b, c • h a b) :=
finset.smul_sum
end finsupp
namespace linear_map
section
variables [ring R] [add_comm_group M] [add_comm_group M₂] [add_comm_group M₃] [add_comm_group M₄]
variables [module R M] [module R M₂] [module R M₃] [module R M₄]
variables (f g : M →ₗ[R] M₂)
include R
@[simp] theorem comp_id : f.comp id = f :=
linear_map.ext $ λ x, rfl
@[simp] theorem id_comp : id.comp f = f :=
linear_map.ext $ λ x, rfl
theorem comp_assoc (g : M₂ →ₗ[R] M₃) (h : M₃ →ₗ[R] M₄) : (h.comp g).comp f = h.comp (g.comp f) :=
rfl
/-- A linear map `f : M₂ → M` whose values lie in a submodule `p ⊆ M` can be restricted to a
linear map M₂ → p. -/
def cod_restrict (p : submodule R M) (f : M₂ →ₗ[R] M) (h : ∀c, f c ∈ p) : M₂ →ₗ[R] p :=
by refine {to_fun := λc, ⟨f c, h c⟩, ..}; intros; apply set_coe.ext; simp
@[simp] theorem cod_restrict_apply (p : submodule R M) (f : M₂ →ₗ[R] M) {h} (x : M₂) :
(cod_restrict p f h x : M) = f x := rfl
@[simp] lemma comp_cod_restrict (p : submodule R M₂) (h : ∀b, f b ∈ p) (g : M₃ →ₗ[R] M) :
(cod_restrict p f h).comp g = cod_restrict p (f.comp g) (assume b, h _) :=
ext $ assume b, rfl
@[simp] lemma subtype_comp_cod_restrict (p : submodule R M₂) (h : ∀b, f b ∈ p) :
p.subtype.comp (cod_restrict p f h) = f :=
ext $ assume b, rfl
/-- If a function `g` is a left and right inverse of a linear map `f`, then `g` is linear itself. -/
def inverse (g : M₂ → M) (h₁ : left_inverse g f) (h₂ : right_inverse g f) : M₂ →ₗ[R] M :=
by dsimp [left_inverse, function.right_inverse] at h₁ h₂; exact
⟨g, λ x y, by rw [← h₁ (g (x + y)), ← h₁ (g x + g y)]; simp [h₂],
λ a b, by rw [← h₁ (g (a • b)), ← h₁ (a • g b)]; simp [h₂]⟩
/-- The constant 0 map is linear. -/
instance : has_zero (M →ₗ[R] M₂) := ⟨⟨λ _, 0, by simp, by simp⟩⟩
@[simp] lemma zero_apply (x : M) : (0 : M →ₗ[R] M₂) x = 0 := rfl
/-- The negation of a linear map is linear. -/
instance : has_neg (M →ₗ[R] M₂) := ⟨λ f, ⟨λ b, - f b, by simp, by simp⟩⟩
@[simp] lemma neg_apply (x : M) : (- f) x = - f x := rfl
/-- The sum of two linear maps is linear. -/
instance : has_add (M →ₗ[R] M₂) := ⟨λ f g, ⟨λ b, f b + g b, by simp, by simp [smul_add]⟩⟩
@[simp] lemma add_apply (x : M) : (f + g) x = f x + g x := rfl
/-- The type of linear maps is an additive group. -/
instance : add_comm_group (M →ₗ[R] M₂) :=
by refine {zero := 0, add := (+), neg := has_neg.neg, ..};
intros; ext; simp
instance linear_map.is_add_group_hom : is_add_group_hom f :=
{ map_add := f.add }
instance linear_map_apply_is_add_group_hom (a : M) :
is_add_group_hom (λ f : M →ₗ[R] M₂, f a) :=
{ map_add := λ f g, linear_map.add_apply f g a }
lemma sum_apply (t : finset ι) (f : ι → M →ₗ[R] M₂) (b : M) :
t.sum f b = t.sum (λd, f d b) :=
(@finset.sum_hom _ _ _ t f _ _ (λ g : M →ₗ[R] M₂, g b) _).symm
@[simp] lemma sub_apply (x : M) : (f - g) x = f x - g x := rfl
/-- `λb, f b • x` is a linear map. -/
def smul_right (f : M₂ →ₗ[R] R) (x : M) : M₂ →ₗ[R] M :=
⟨λb, f b • x, by simp [add_smul], by simp [smul_smul]⟩.
@[simp] theorem smul_right_apply (f : M₂ →ₗ[R] R) (x : M) (c : M₂) :
(smul_right f x : M₂ → M) c = f c • x := rfl
instance : has_one (M →ₗ[R] M) := ⟨linear_map.id⟩
instance : has_mul (M →ₗ[R] M) := ⟨linear_map.comp⟩
@[simp] lemma one_app (x : M) : (1 : M →ₗ[R] M) x = x := rfl
@[simp] lemma mul_app (A B : M →ₗ[R] M) (x : M) : (A * B) x = A (B x) := rfl
@[simp] theorem comp_zero : f.comp (0 : M₃ →ₗ[R] M) = 0 :=
ext $ assume c, by rw [comp_apply, zero_apply, zero_apply, f.map_zero]
@[simp] theorem zero_comp : (0 : M₂ →ₗ[R] M₃).comp f = 0 :=
rfl
section
variables (R M)
include M
instance endomorphism_ring : ring (M →ₗ[R] M) :=
by refine {mul := (*), one := 1, ..linear_map.add_comm_group, ..};
{ intros, apply linear_map.ext, simp }
end
section
variables (R M M₂)
/-- The first projection of a product is a linear map. -/
def fst : M × M₂ →ₗ[R] M := ⟨prod.fst, λ x y, rfl, λ x y, rfl⟩
/-- The second projection of a product is a linear map. -/
def snd : M × M₂ →ₗ[R] M₂ := ⟨prod.snd, λ x y, rfl, λ x y, rfl⟩
end
@[simp] theorem fst_apply (x : M × M₂) : fst R M M₂ x = x.1 := rfl
@[simp] theorem snd_apply (x : M × M₂) : snd R M M₂ x = x.2 := rfl
/-- The pair of two linear maps is a linear map. -/
def pair (f : M →ₗ[R] M₂) (g : M →ₗ[R] M₃) : M →ₗ[R] M₂ × M₃ :=
⟨λ x, (f x, g x), λ x y, by simp, λ x y, by simp⟩
@[simp] theorem pair_apply (f : M →ₗ[R] M₂) (g : M →ₗ[R] M₃) (x : M) :
pair f g x = (f x, g x) := rfl
@[simp] theorem fst_pair (f : M →ₗ[R] M₂) (g : M →ₗ[R] M₃) :
(fst R M₂ M₃).comp (pair f g) = f := by ext; refl
@[simp] theorem snd_pair (f : M →ₗ[R] M₂) (g : M →ₗ[R] M₃) :
(snd R M₂ M₃).comp (pair f g) = g := by ext; refl
@[simp] theorem pair_fst_snd : pair (fst R M M₂) (snd R M M₂) = linear_map.id :=
by ext; refl
section
variables (R M M₂)
/-- The left injection into a product is a linear map. -/
def inl : M →ₗ[R] M × M₂ := by refine ⟨prod.inl, _, _⟩; intros; simp [prod.inl]
/-- The right injection into a product is a linear map. -/
def inr : M₂ →ₗ[R] M × M₂ := by refine ⟨prod.inr, _, _⟩; intros; simp [prod.inr]
end
@[simp] theorem inl_apply (x : M) : inl R M M₂ x = (x, 0) := rfl
@[simp] theorem inr_apply (x : M₂) : inr R M M₂ x = (0, x) := rfl
/-- The copair function `λ x : M × M₂, f x.1 + g x.2` is a linear map. -/
def copair (f : M →ₗ[R] M₃) (g : M₂ →ₗ[R] M₃) : M × M₂ →ₗ[R] M₃ :=
⟨λ x, f x.1 + g x.2, λ x y, by simp, λ x y, by simp [smul_add]⟩
@[simp] theorem copair_apply (f : M →ₗ[R] M₃) (g : M₂ →ₗ[R] M₃) (x : M) (y : M₂) :
copair f g (x, y) = f x + g y := rfl
@[simp] theorem copair_inl (f : M →ₗ[R] M₃) (g : M₂ →ₗ[R] M₃) :
(copair f g).comp (inl R M M₂) = f := by ext; simp
@[simp] theorem copair_inr (f : M →ₗ[R] M₃) (g : M₂ →ₗ[R] M₃) :
(copair f g).comp (inr R M M₂) = g := by ext; simp
@[simp] theorem copair_inl_inr : copair (inl R M M₂) (inr R M M₂) = linear_map.id :=
by ext ⟨x, y⟩; simp
theorem fst_eq_copair : fst R M M₂ = copair linear_map.id 0 := by ext ⟨x, y⟩; simp
theorem snd_eq_copair : snd R M M₂ = copair 0 linear_map.id := by ext ⟨x, y⟩; simp
theorem inl_eq_pair : inl R M M₂ = pair linear_map.id 0 := rfl
theorem inr_eq_pair : inr R M M₂ = pair 0 linear_map.id := rfl
end
section comm_ring
variables [comm_ring R] [add_comm_group M] [add_comm_group M₂] [add_comm_group M₃]
variables [module R M] [module R M₂] [module R M₃]
variables (f g : M →ₗ[R] M₂)
include R
instance : has_scalar R (M →ₗ[R] M₂) := ⟨λ a f,
⟨λ b, a • f b, by simp [smul_add], by simp [smul_smul, mul_comm]⟩⟩
@[simp] lemma smul_apply (a : R) (x : M) : (a • f) x = a • f x := rfl
instance : module R (M →ₗ[R] M₂) :=
module.of_core $ by refine { smul := (•), ..};
intros; ext; simp [smul_add, add_smul, smul_smul]
/-- Composition by `f : M₂ → M₃` is a linear map from the space of linear maps `M → M₂` to the space of
linear maps `M₂ → M₃`. -/
def congr_right (f : M₂ →ₗ[R] M₃) : (M →ₗ[R] M₂) →ₗ[R] (M →ₗ[R] M₃) :=
⟨linear_map.comp f,
λ _ _, linear_map.ext $ λ _, f.2 _ _,
λ _ _, linear_map.ext $ λ _, f.3 _ _⟩
theorem smul_comp (g : M₂ →ₗ[R] M₃) (a : R) : (a • g).comp f = a • (g.comp f) :=
rfl
theorem comp_smul (g : M₂ →ₗ[R] M₃) (a : R) : g.comp (a • f) = a • (g.comp f) :=
ext $ assume b, by rw [comp_apply, smul_apply, g.map_smul]; refl
end comm_ring
end linear_map
namespace submodule
variables [ring R] [add_comm_group M] [add_comm_group M₂] [add_comm_group M₃]
variables [module R M] [module R M₂] [module R M₃]
variables (p p' : submodule R M) (q q' : submodule R M₂)
variables {r : R} {x y : M}
open set lattice
instance : partial_order (submodule R M) :=
partial_order.lift (coe : submodule R M → set M) (λ a b, ext') (by apply_instance)
lemma le_def {p p' : submodule R M} : p ≤ p' ↔ (p : set M) ⊆ p' := iff.rfl
lemma le_def' {p p' : submodule R M} : p ≤ p' ↔ ∀ x ∈ p, x ∈ p' := iff.rfl
/-- If two submodules p and p' satisfy p ⊆ p', then `of_le p p'` is the linear map version of this
inclusion. -/
def of_le {p p' : submodule R M} (h : p ≤ p') : p →ₗ[R] p' :=
linear_map.cod_restrict _ p.subtype $ λ ⟨x, hx⟩, h hx
@[simp] theorem of_le_apply {p p' : submodule R M} (h : p ≤ p')
(x : p) : (of_le h x : M) = x := rfl
lemma subtype_comp_of_le (p q : submodule R M) (h : p ≤ q) :
(submodule.subtype q).comp (of_le h) = submodule.subtype p :=
by ext ⟨b, hb⟩; simp
/-- The set `{0}` is the bottom element of the lattice of submodules. -/
instance : has_bot (submodule R M) :=
⟨by split; try {exact {0}}; simp {contextual := tt}⟩
@[simp] lemma bot_coe : ((⊥ : submodule R M) : set M) = {0} := rfl
section
variables (R)
@[simp] lemma mem_bot : x ∈ (⊥ : submodule R M) ↔ x = 0 := mem_singleton_iff
end
instance : order_bot (submodule R M) :=
{ bot := ⊥,
bot_le := λ p x, by simp {contextual := tt},
..submodule.partial_order }
/-- The universal set is the top element of the lattice of submodules. -/
instance : has_top (submodule R M) :=
⟨by split; try {exact set.univ}; simp⟩
@[simp] lemma top_coe : ((⊤ : submodule R M) : set M) = univ := rfl
@[simp] lemma mem_top : x ∈ (⊤ : submodule R M) := trivial
lemma eq_bot_of_zero_eq_one (zero_eq_one : (0 : R) = 1) : p = ⊥ :=
by ext x; simp [semimodule.eq_zero_of_zero_eq_one _ x zero_eq_one]
instance : order_top (submodule R M) :=
{ top := ⊤,
le_top := λ p x _, trivial,
..submodule.partial_order }
instance : has_Inf (submodule R M) :=
⟨λ S, {
carrier := ⋂ s ∈ S, ↑s,
zero := by simp,
add := by simp [add_mem] {contextual := tt},
smul := by simp [smul_mem] {contextual := tt} }⟩
private lemma Inf_le' {S : set (submodule R M)} {p} : p ∈ S → Inf S ≤ p :=
bInter_subset_of_mem
private lemma le_Inf' {S : set (submodule R M)} {p} : (∀p' ∈ S, p ≤ p') → p ≤ Inf S :=
subset_bInter
instance : has_inf (submodule R M) :=
⟨λ p p', {
carrier := p ∩ p',
zero := by simp,
add := by simp [add_mem] {contextual := tt},
smul := by simp [smul_mem] {contextual := tt} }⟩
instance : complete_lattice (submodule R M) :=
{ sup := λ a b, Inf {x | a ≤ x ∧ b ≤ x},
le_sup_left := λ a b, le_Inf' $ λ x ⟨ha, hb⟩, ha,
le_sup_right := λ a b, le_Inf' $ λ x ⟨ha, hb⟩, hb,
sup_le := λ a b c h₁ h₂, Inf_le' ⟨h₁, h₂⟩,
inf := (⊓),
le_inf := λ a b c, subset_inter,
inf_le_left := λ a b, inter_subset_left _ _,
inf_le_right := λ a b, inter_subset_right _ _,
Sup := λtt, Inf {t | ∀t'∈tt, t' ≤ t},
le_Sup := λ s p hs, le_Inf' $ λ p' hp', hp' _ hs,
Sup_le := λ s p hs, Inf_le' hs,
Inf := Inf,
le_Inf := λ s a, le_Inf',
Inf_le := λ s a, Inf_le',
..submodule.lattice.order_top,
..submodule.lattice.order_bot }
instance : add_comm_monoid (submodule R M) :=
{ add := (⊔),
add_assoc := λ _ _ _, sup_assoc,
zero := ⊥,
zero_add := λ _, bot_sup_eq,
add_zero := λ _, sup_bot_eq,
add_comm := λ _ _, sup_comm }
@[simp] lemma add_eq_sup (p q : submodule R M) : p + q = p ⊔ q := rfl
@[simp] lemma zero_eq_bot : (0 : submodule R M) = ⊥ := rfl
lemma eq_top_iff' {p : submodule R M} : p = ⊤ ↔ ∀ x, x ∈ p :=
eq_top_iff.trans ⟨λ h x, @h x trivial, λ h x _, h x⟩
@[simp] theorem inf_coe : (p ⊓ p' : set M) = p ∩ p' := rfl
@[simp] theorem mem_inf {p p' : submodule R M} :
x ∈ p ⊓ p' ↔ x ∈ p ∧ x ∈ p' := iff.rfl
@[simp] theorem Inf_coe (P : set (submodule R M)) : (↑(Inf P) : set M) = ⋂ p ∈ P, ↑p := rfl
@[simp] theorem infi_coe {ι} (p : ι → submodule R M) :
(↑⨅ i, p i : set M) = ⋂ i, ↑(p i) :=
by rw [infi, Inf_coe]; ext a; simp; exact
⟨λ h i, h _ i rfl, λ h i x e, e ▸ h _⟩
@[simp] theorem mem_infi {ι} (p : ι → submodule R M) :
x ∈ (⨅ i, p i) ↔ ∀ i, x ∈ p i :=
by rw [← mem_coe, infi_coe, mem_Inter]; refl
theorem disjoint_def {p p' : submodule R M} :
disjoint p p' ↔ ∀ x ∈ p, x ∈ p' → x = (0:M) :=
show (∀ x, x ∈ p ∧ x ∈ p' → x ∈ ({0} : set M)) ↔ _, by simp
/-- The pushforward of a submodule `p ⊆ M` by `f : M → M₂` -/
def map (f : M →ₗ[R] M₂) (p : submodule R M) : submodule R M₂ :=
{ carrier := f '' p,
zero := ⟨0, p.zero_mem, f.map_zero⟩,
add := by rintro _ _ ⟨b₁, hb₁, rfl⟩ ⟨b₂, hb₂, rfl⟩;
exact ⟨_, p.add_mem hb₁ hb₂, f.map_add _ _⟩,
smul := by rintro a _ ⟨b, hb, rfl⟩;
exact ⟨_, p.smul_mem _ hb, f.map_smul _ _⟩ }
lemma map_coe (f : M →ₗ[R] M₂) (p : submodule R M) :
(map f p : set M₂) = f '' p := rfl
@[simp] lemma mem_map {f : M →ₗ[R] M₂} {p : submodule R M} {x : M₂} :
x ∈ map f p ↔ ∃ y, y ∈ p ∧ f y = x := iff.rfl
theorem mem_map_of_mem {f : M →ₗ[R] M₂} {p : submodule R M} {r} (h : r ∈ p) : f r ∈ map f p :=
set.mem_image_of_mem _ h
lemma map_id : map linear_map.id p = p :=
submodule.ext $ λ a, by simp
lemma map_comp (f : M →ₗ[R] M₂) (g : M₂ →ₗ[R] M₃) (p : submodule R M) :
map (g.comp f) p = map g (map f p) :=
submodule.ext' $ by simp [map_coe]; rw ← image_comp
lemma map_mono {f : M →ₗ[R] M₂} {p p' : submodule R M} : p ≤ p' → map f p ≤ map f p' :=
image_subset _
@[simp] lemma map_zero : map (0 : M →ₗ[R] M₂) p = ⊥ :=
have ∃ (x : M), x ∈ p := ⟨0, p.zero_mem⟩,
ext $ by simp [this, eq_comm]
/-- The pullback of a submodule `p ⊆ M₂` along `f : M → M₂` -/
def comap (f : M →ₗ[R] M₂) (p : submodule R M₂) : submodule R M :=
{ carrier := f ⁻¹' p,
zero := by simp,
add := λ x y h₁ h₂, by simp [p.add_mem h₁ h₂],
smul := λ a x h, by simp [p.smul_mem _ h] }
@[simp] lemma comap_coe (f : M →ₗ[R] M₂) (p : submodule R M₂) :
(comap f p : set M) = f ⁻¹' p := rfl
@[simp] lemma mem_comap {f : M →ₗ[R] M₂} {p : submodule R M₂} :
x ∈ comap f p ↔ f x ∈ p := iff.rfl
lemma comap_id : comap linear_map.id p = p :=
submodule.ext' rfl
lemma comap_comp (f : M →ₗ[R] M₂) (g : M₂ →ₗ[R] M₃) (p : submodule R M₃) :
comap (g.comp f) p = comap f (comap g p) := rfl
lemma comap_mono {f : M →ₗ[R] M₂} {q q' : submodule R M₂} : q ≤ q' → comap f q ≤ comap f q' :=
preimage_mono
lemma map_le_iff_le_comap {f : M →ₗ[R] M₂} {p : submodule R M} {q : submodule R M₂} :
map f p ≤ q ↔ p ≤ comap f q := image_subset_iff
lemma gc_map_comap (f : M →ₗ[R] M₂) : galois_connection (map f) (comap f)
| p q := map_le_iff_le_comap
@[simp] lemma map_bot (f : M →ₗ[R] M₂) : map f ⊥ = ⊥ :=
(gc_map_comap f).l_bot
@[simp] lemma map_sup (f : M →ₗ[R] M₂) : map f (p ⊔ p') = map f p ⊔ map f p' :=
(gc_map_comap f).l_sup
@[simp] lemma map_supr {ι : Sort*} (f : M →ₗ[R] M₂) (p : ι → submodule R M) :
map f (⨆i, p i) = (⨆i, map f (p i)) :=
(gc_map_comap f).l_supr
@[simp] lemma comap_top (f : M →ₗ[R] M₂) : comap f ⊤ = ⊤ := rfl
@[simp] lemma comap_inf (f : M →ₗ[R] M₂) : comap f (q ⊓ q') = comap f q ⊓ comap f q' := rfl
@[simp] lemma comap_infi {ι : Sort*} (f : M →ₗ[R] M₂) (p : ι → submodule R M₂) :
comap f (⨅i, p i) = (⨅i, comap f (p i)) :=
(gc_map_comap f).u_infi
@[simp] lemma comap_zero : comap (0 : M →ₗ[R] M₂) q = ⊤ :=
ext $ by simp
lemma map_comap_le (f : M →ₗ[R] M₂) (q : submodule R M₂) : map f (comap f q) ≤ q :=
(gc_map_comap f).l_u_le _
lemma le_comap_map (f : M →ₗ[R] M₂) (p : submodule R M) : p ≤ comap f (map f p) :=
(gc_map_comap f).le_u_l _
--TODO(Mario): is there a way to prove this from order properties?
lemma map_inf_eq_map_inf_comap {f : M →ₗ[R] M₂}
{p : submodule R M} {p' : submodule R M₂} :
map f p ⊓ p' = map f (p ⊓ comap f p') :=
le_antisymm
(by rintro _ ⟨⟨x, h₁, rfl⟩, h₂⟩; exact ⟨_, ⟨h₁, h₂⟩, rfl⟩)
(le_inf (map_mono inf_le_left) (map_le_iff_le_comap.2 inf_le_right))
lemma map_comap_subtype : map p.subtype (comap p.subtype p') = p ⊓ p' :=
ext $ λ x, ⟨by rintro ⟨⟨_, h₁⟩, h₂, rfl⟩; exact ⟨h₁, h₂⟩, λ ⟨h₁, h₂⟩, ⟨⟨_, h₁⟩, h₂, rfl⟩⟩
lemma eq_zero_of_bot_submodule : ∀(b : (⊥ : submodule R M)), b = 0
| ⟨b', hb⟩ := subtype.eq $ show b' = 0, from (mem_bot R).1 hb
section
variables (R)
/-- The span of a set `s ⊆ M` is the smallest submodule of M that contains `s`. -/
def span (s : set M) : submodule R M := Inf {p | s ⊆ p}
end
variables {s t : set M}
lemma mem_span : x ∈ span R s ↔ ∀ p : submodule R M, s ⊆ p → x ∈ p :=
mem_bInter_iff
lemma subset_span : s ⊆ span R s :=
λ x h, mem_span.2 $ λ p hp, hp h
lemma span_le {p} : span R s ≤ p ↔ s ⊆ p :=
⟨subset.trans subset_span, λ ss x h, mem_span.1 h _ ss⟩
lemma span_mono (h : s ⊆ t) : span R s ≤ span R t :=
span_le.2 $ subset.trans h subset_span
lemma span_eq_of_le (h₁ : s ⊆ p) (h₂ : p ≤ span R s) : span R s = p :=
le_antisymm (span_le.2 h₁) h₂
@[simp] lemma span_eq : span R (p : set M) = p :=
span_eq_of_le _ (subset.refl _) subset_span
/-- An induction principle for span membership. If `p` holds for 0 and all elements of `s`, and is
preserved under addition and scalar multiplication, then `p` holds for all elements of the span of
`s`. -/
@[elab_as_eliminator] lemma span_induction {p : M → Prop} (h : x ∈ span R s)
(Hs : ∀ x ∈ s, p x) (H0 : p 0)
(H1 : ∀ x y, p x → p y → p (x + y))
(H2 : ∀ (a:R) x, p x → p (a • x)) : p x :=
(@span_le _ _ _ _ _ _ ⟨p, H0, H1, H2⟩).2 Hs h
section
variables (R M)
/-- `span` forms a Galois insertion with the coercion from submodule to set. -/
protected def gi : galois_insertion (@span R M _ _ _) coe :=
{ choice := λ s _, span R s,
gc := λ s t, span_le,
le_l_u := λ s, subset_span,
choice_eq := λ s h, rfl }
end
@[simp] lemma span_empty : span R (∅ : set M) = ⊥ :=
(submodule.gi R M).gc.l_bot
@[simp] lemma span_univ : span R (univ : set M) = ⊤ :=
eq_top_iff.2 $ le_def.2 $ subset_span
lemma span_union (s t : set M) : span R (s ∪ t) = span R s ⊔ span R t :=
(submodule.gi R M).gc.l_sup
lemma span_Union {ι} (s : ι → set M) : span R (⋃ i, s i) = ⨆ i, span R (s i) :=
(submodule.gi R M).gc.l_supr
@[simp] theorem Union_coe_of_directed {ι} (hι : nonempty ι)
(S : ι → submodule R M)
(H : ∀ i j, ∃ k, S i ≤ S k ∧ S j ≤ S k) :
((supr S : submodule R M) : set M) = ⋃ i, S i :=
begin
refine subset.antisymm _ (Union_subset $ le_supr S),
rw [show supr S = ⨆ i, span R (S i), by simp, ← span_Union],
unfreezeI,
refine λ x hx, span_induction hx (λ _, id) _ _ _,
{ cases hι with i, exact mem_Union.2 ⟨i, by simp⟩ },
{ simp, intros x y i hi j hj,
rcases H i j with ⟨k, ik, jk⟩,
exact ⟨k, add_mem _ (ik hi) (jk hj)⟩ },
{ simp [-mem_coe]; exact λ a x i hi, ⟨i, smul_mem _ a hi⟩ },
end
lemma mem_supr_of_mem {ι : Sort*} {b : M} (p : ι → submodule R M) (i : ι) (h : b ∈ p i) :
b ∈ (⨆i, p i) :=
have p i ≤ (⨆i, p i) := le_supr p i,
@this b h
@[simp] theorem mem_supr_of_directed {ι} (hι : nonempty ι)
(S : ι → submodule R M)
(H : ∀ i j, ∃ k, S i ≤ S k ∧ S j ≤ S k) {x} :
x ∈ supr S ↔ ∃ i, x ∈ S i :=
by rw [← mem_coe, Union_coe_of_directed hι S H, mem_Union]; refl
theorem mem_Sup_of_directed {s : set (submodule R M)}
{z} (hzs : z ∈ Sup s) (x ∈ s)
(hdir : ∀ i ∈ s, ∀ j ∈ s, ∃ k ∈ s, i ≤ k ∧ j ≤ k) :
∃ y ∈ s, z ∈ y :=
begin
haveI := classical.dec, rw Sup_eq_supr at hzs,
have : ∃ (i : submodule R M), z ∈ ⨆ (H : i ∈ s), i,
{ refine (mem_supr_of_directed ⟨⊥⟩ _ (λ i j, _)).1 hzs,
by_cases his : i ∈ s; by_cases hjs : j ∈ s,
{ rcases hdir i his j hjs with ⟨k, hks, hik, hjk⟩,
exact ⟨k, le_supr_of_le hks (supr_le $ λ _, hik),
le_supr_of_le hks (supr_le $ λ _, hjk)⟩ },
{ exact ⟨i, le_refl _, supr_le $ hjs.elim⟩ },
{ exact ⟨j, supr_le $ his.elim, le_refl _⟩ },
{ exact ⟨⊥, supr_le $ his.elim, supr_le $ hjs.elim⟩ } },
cases this with N hzn, by_cases hns : N ∈ s,
{ have : (⨆ (H : N ∈ s), N) ≤ N := supr_le (λ _, le_refl _),
exact ⟨N, hns, this hzn⟩ },
{ have : (⨆ (H : N ∈ s), N) ≤ ⊥ := supr_le hns.elim,
cases (mem_bot R).1 (this hzn), exact ⟨x, H, x.zero_mem⟩ }
end
section
variables {p p'}
lemma mem_sup : x ∈ p ⊔ p' ↔ ∃ (y ∈ p) (z ∈ p'), y + z = x :=
⟨λ h, begin
rw [← span_eq p, ← span_eq p', ← span_union] at h,
apply span_induction h,
{ rintro y (h | h),
{ exact ⟨y, h, 0, by simp, by simp⟩ },
{ exact ⟨0, by simp, y, h, by simp⟩ } },
{ exact ⟨0, by simp, 0, by simp⟩ },
{ rintro _ _ ⟨y₁, hy₁, z₁, hz₁, rfl⟩ ⟨y₂, hy₂, z₂, hz₂, rfl⟩,
exact ⟨_, add_mem _ hy₁ hy₂, _, add_mem _ hz₁ hz₂, by simp⟩ },
{ rintro a _ ⟨y, hy, z, hz, rfl⟩,
exact ⟨_, smul_mem _ a hy, _, smul_mem _ a hz, by simp [smul_add]⟩ }
end,
by rintro ⟨y, hy, z, hz, rfl⟩; exact add_mem _
((le_sup_left : p ≤ p ⊔ p') hy)
((le_sup_right : p' ≤ p ⊔ p') hz)⟩
end
lemma mem_span_singleton {y : M} : x ∈ span R ({y} : set M) ↔ ∃ a:R, a • y = x :=
⟨λ h, begin
apply span_induction h,
{ rintro y (rfl|⟨⟨⟩⟩), exact ⟨1, by simp⟩ },
{ exact ⟨0, by simp⟩ },
{ rintro _ _ ⟨a, rfl⟩ ⟨b, rfl⟩,
exact ⟨a + b, by simp [add_smul]⟩ },
{ rintro a _ ⟨b, rfl⟩,
exact ⟨a * b, by simp [smul_smul]⟩ }
end,
by rintro ⟨a, y, rfl⟩; exact
smul_mem _ _ (subset_span $ by simp)⟩
lemma span_singleton_eq_range (y : M) : (span R ({y} : set M) : set M) = range ((• y) : R → M) :=
set.ext $ λ x, mem_span_singleton
lemma mem_span_insert {y} : x ∈ span R (insert y s) ↔ ∃ (a:R) (z ∈ span R s), x = a • y + z :=
begin
rw [← union_singleton, span_union, mem_sup],
simp [mem_span_singleton], split,
{ rintro ⟨z, hz, _, ⟨a, rfl⟩, rfl⟩, exact ⟨a, z, hz, rfl⟩ },
{ rintro ⟨a, z, hz, rfl⟩, exact ⟨z, hz, _, ⟨a, rfl⟩, rfl⟩ }
end
lemma mem_span_insert' {y} : x ∈ span R (insert y s) ↔ ∃(a:R), x + a • y ∈ span R s :=
begin
rw mem_span_insert, split,
{ rintro ⟨a, z, hz, rfl⟩, exact ⟨-a, by simp [hz]⟩ },
{ rintro ⟨a, h⟩, exact ⟨-a, _, h, by simp⟩ }
end
lemma span_insert_eq_span (h : x ∈ span R s) : span R (insert x s) = span R s :=
span_eq_of_le _ (set.insert_subset.mpr ⟨h, subset_span⟩) (span_mono $ subset_insert _ _)
lemma span_span : span R (span R s : set M) = span R s := span_eq _
lemma span_eq_bot : span R (s : set M) = ⊥ ↔ ∀ x ∈ s, (x:M) = 0 :=
eq_bot_iff.trans ⟨
λ H x h, (mem_bot R).1 $ H $ subset_span h,
λ H, span_le.2 (λ x h, (mem_bot R).2 $ H x h)⟩
lemma span_singleton_eq_bot : span R ({x} : set M) = ⊥ ↔ x = 0 :=
span_eq_bot.trans $ by simp
@[simp] lemma span_image (f : M →ₗ[R] M₂) : span R (f '' s) = map f (span R s) :=
span_eq_of_le _ (image_subset _ subset_span) $ map_le_iff_le_comap.2 $
span_le.2 $ image_subset_iff.1 subset_span
lemma linear_eq_on (s : set M) {f g : M →ₗ[R] M₂} (H : ∀x∈s, f x = g x) {x} (h : x ∈ span R s) :
f x = g x :=
by apply span_induction h H; simp {contextual := tt}
/-- The product of two submodules is a submodule. -/
def prod : submodule R (M × M₂) :=
{ carrier := set.prod p q,
zero := ⟨zero_mem _, zero_mem _⟩,
add := by rintro ⟨x₁, y₁⟩ ⟨x₂, y₂⟩ ⟨hx₁, hy₁⟩ ⟨hx₂, hy₂⟩;
exact ⟨add_mem _ hx₁ hx₂, add_mem _ hy₁ hy₂⟩,
smul := by rintro a ⟨x, y⟩ ⟨hx, hy⟩;
exact ⟨smul_mem _ a hx, smul_mem _ a hy⟩ }
@[simp] lemma prod_coe :
(prod p q : set (M × M₂)) = set.prod p q := rfl
@[simp] lemma mem_prod {p : submodule R M} {q : submodule R M₂} {x : M × M₂} :
x ∈ prod p q ↔ x.1 ∈ p ∧ x.2 ∈ q := set.mem_prod
lemma span_prod_le (s : set M) (t : set M₂) :
span R (set.prod s t) ≤ prod (span R s) (span R t) :=
span_le.2 $ set.prod_mono subset_span subset_span
@[simp] lemma prod_top : (prod ⊤ ⊤ : submodule R (M × M₂)) = ⊤ :=
by ext; simp
@[simp] lemma prod_bot : (prod ⊥ ⊥ : submodule R (M × M₂)) = ⊥ :=
by ext ⟨x, y⟩; simp [prod.zero_eq_mk]
lemma prod_mono {p p' : submodule R M} {q q' : submodule R M₂} :
p ≤ p' → q ≤ q' → prod p q ≤ prod p' q' := prod_mono
@[simp] lemma prod_inf_prod : prod p q ⊓ prod p' q' = prod (p ⊓ p') (q ⊓ q') :=
ext' set.prod_inter_prod
@[simp] lemma prod_sup_prod : prod p q ⊔ prod p' q' = prod (p ⊔ p') (q ⊔ q') :=
begin
refine le_antisymm (sup_le
(prod_mono le_sup_left le_sup_left)
(prod_mono le_sup_right le_sup_right)) _,
simp [le_def'], intros xx yy hxx hyy,
rcases mem_sup.1 hxx with ⟨x, hx, x', hx', rfl⟩,
rcases mem_sup.1 hyy with ⟨y, hy, y', hy', rfl⟩,
refine mem_sup.2 ⟨(x, y), ⟨hx, hy⟩, (x', y'), ⟨hx', hy'⟩, rfl⟩
end
-- TODO(Mario): Factor through add_subgroup
/-- The equivalence relation associated to a submodule `p`, defined by `x ≈ y` iff `y - x ∈ p`. -/
def quotient_rel : setoid M :=
⟨λ x y, x - y ∈ p, λ x, by simp,
λ x y h, by simpa using neg_mem _ h,
λ x y z h₁ h₂, by simpa using add_mem _ h₁ h₂⟩
/-- The quotient of a module `M` by a submodule `p ⊆ M`. -/
def quotient : Type* := quotient (quotient_rel p)
namespace quotient
/-- Map associating to an element of `M` the corresponding element of `M/p`,
when `p` is a submodule of `M`. -/
def mk {p : submodule R M} : M → quotient p := quotient.mk'
@[simp] theorem mk_eq_mk {p : submodule R M} (x : M) : (quotient.mk x : quotient p) = mk x := rfl
@[simp] theorem mk'_eq_mk {p : submodule R M} (x : M) : (quotient.mk' x : quotient p) = mk x := rfl
@[simp] theorem quot_mk_eq_mk {p : submodule R M} (x : M) : (quot.mk _ x : quotient p) = mk x := rfl
protected theorem eq {x y : M} : (mk x : quotient p) = mk y ↔ x - y ∈ p := quotient.eq'
instance : has_zero (quotient p) := ⟨mk 0⟩
@[simp] theorem mk_zero : mk 0 = (0 : quotient p) := rfl
@[simp] theorem mk_eq_zero : (mk x : quotient p) = 0 ↔ x ∈ p :=
by simpa using (quotient.eq p : mk x = 0 ↔ _)
instance : has_add (quotient p) :=
⟨λ a b, quotient.lift_on₂' a b (λ a b, mk (a + b)) $
λ a₁ a₂ b₁ b₂ h₁ h₂, (quotient.eq p).2 $ by simpa using add_mem p h₁ h₂⟩
@[simp] theorem mk_add : (mk (x + y) : quotient p) = mk x + mk y := rfl
instance : has_neg (quotient p) :=
⟨λ a, quotient.lift_on' a (λ a, mk (-a)) $
λ a b h, (quotient.eq p).2 $ by simpa using neg_mem p h⟩
@[simp] theorem mk_neg : (mk (-x) : quotient p) = -mk x := rfl
instance : add_comm_group (quotient p) :=
by refine {zero := 0, add := (+), neg := has_neg.neg, ..};
repeat {rintro ⟨⟩};
simp [-mk_zero, (mk_zero p).symm, -mk_add, (mk_add p).symm, -mk_neg, (mk_neg p).symm]
instance : has_scalar R (quotient p) :=
⟨λ a x, quotient.lift_on' x (λ x, mk (a • x)) $
λ x y h, (quotient.eq p).2 $ by simpa [smul_add] using smul_mem p a h⟩
@[simp] theorem mk_smul : (mk (r • x) : quotient p) = r • mk x := rfl
instance : module R (quotient p) :=
module.of_core $ by refine {smul := (•), ..};
repeat {rintro ⟨⟩ <|> intro}; simp [smul_add, add_smul, smul_smul,
-mk_add, (mk_add p).symm, -mk_smul, (mk_smul p).symm]
instance {K M} {R:discrete_field K} [add_comm_group M] [vector_space K M]
(p : submodule K M) : vector_space K (quotient p) := {}
end quotient
end submodule
namespace submodule
variables [discrete_field K]
variables [add_comm_group V] [vector_space K V]
variables [add_comm_group V₂] [vector_space K V₂]
lemma comap_smul (f : V →ₗ[K] V₂) (p : submodule K V₂) (a : K) (h : a ≠ 0) :
p.comap (a • f) = p.comap f :=
by ext b; simp only [submodule.mem_comap, p.smul_mem_iff h, linear_map.smul_apply]
lemma map_smul (f : V →ₗ[K] V₂) (p : submodule K V) (a : K) (h : a ≠ 0) :
p.map (a • f) = p.map f :=
le_antisymm
begin rw [map_le_iff_le_comap, comap_smul f _ a h, ← map_le_iff_le_comap], exact le_refl _ end
begin rw [map_le_iff_le_comap, ← comap_smul f _ a h, ← map_le_iff_le_comap], exact le_refl _ end
set_option class.instance_max_depth 40
lemma comap_smul' (f : V →ₗ[K] V₂) (p : submodule K V₂) (a : K) :
p.comap (a • f) = (⨅ h : a ≠ 0, p.comap f) :=
by by_cases a = 0; simp [h, comap_smul]
lemma map_smul' (f : V →ₗ[K] V₂) (p : submodule K V) (a : K) :
p.map (a • f) = (⨆ h : a ≠ 0, p.map f) :=
by by_cases a = 0; simp [h, map_smul]
end submodule
namespace linear_map
variables [ring R] [add_comm_group M] [add_comm_group M₂] [add_comm_group M₃]
variables [module R M] [module R M₂] [module R M₃]
include R
open submodule
@[simp] lemma finsupp_sum {R M M₂ γ} [ring R] [add_comm_group M] [module R M]
[add_comm_group M₂] [module R M₂] [has_zero γ]
(f : M →ₗ[R] M₂) {t : ι →₀ γ} {g : ι → γ → M} :
f (t.sum g) = t.sum (λi d, f (g i d)) := f.map_sum
theorem map_cod_restrict (p : submodule R M) (f : M₂ →ₗ[R] M) (h p') :
submodule.map (cod_restrict p f h) p' = comap p.subtype (p'.map f) :=
submodule.ext $ λ ⟨x, hx⟩, by simp [subtype.coe_ext]
theorem comap_cod_restrict (p : submodule R M) (f : M₂ →ₗ[R] M) (hf p') :
submodule.comap (cod_restrict p f hf) p' = submodule.comap f (map p.subtype p') :=
submodule.ext $ λ x, ⟨λ h, ⟨⟨_, hf x⟩, h, rfl⟩, by rintro ⟨⟨_, _⟩, h, ⟨⟩⟩; exact h⟩
/-- The range of a linear map `f : M → M₂` is a submodule of `M₂`. -/
def range (f : M →ₗ[R] M₂) : submodule R M₂ := map f ⊤
theorem range_coe (f : M →ₗ[R] M₂) : (range f : set M₂) = set.range f := set.image_univ
@[simp] theorem mem_range {f : M →ₗ[R] M₂} : ∀ {x}, x ∈ range f ↔ ∃ y, f y = x :=
(set.ext_iff _ _).1 (range_coe f).
@[simp] theorem range_id : range (linear_map.id : M →ₗ[R] M) = ⊤ := map_id _
theorem range_comp (f : M →ₗ[R] M₂) (g : M₂ →ₗ[R] M₃) : range (g.comp f) = map g (range f) :=
map_comp _ _ _
theorem range_comp_le_range (f : M →ₗ[R] M₂) (g : M₂ →ₗ[R] M₃) : range (g.comp f) ≤ range g :=
by rw range_comp; exact map_mono le_top
theorem range_eq_top {f : M →ₗ[R] M₂} : range f = ⊤ ↔ surjective f :=
by rw [← submodule.ext'_iff, range_coe, top_coe, set.range_iff_surjective]
lemma range_le_iff_comap {f : M →ₗ[R] M₂} {p : submodule R M₂} : range f ≤ p ↔ comap f p = ⊤ :=
by rw [range, map_le_iff_le_comap, eq_top_iff]
lemma map_le_range {f : M →ₗ[R] M₂} {p : submodule R M} : map f p ≤ range f :=
map_mono le_top
lemma sup_range_inl_inr :
(inl R M M₂).range ⊔ (inr R M M₂).range = ⊤ :=
begin
refine eq_top_iff'.2 (λ x, mem_sup.2 _),
rcases x with ⟨x₁, x₂⟩ ,
have h₁ : prod.mk x₁ (0 : M₂) ∈ (inl R M M₂).range,
by simp,
have h₂ : prod.mk (0 : M) x₂ ∈ (inr R M M₂).range,
by simp,
use [⟨x₁, 0⟩, h₁, ⟨0, x₂⟩, h₂],
simp
end
/-- The kernel of a linear map `f : M → M₂` is defined to be `comap f ⊥`. This is equivalent to the
set of `x : M` such that `f x = 0`. The kernel is a submodule of `M`. -/
def ker (f : M →ₗ[R] M₂) : submodule R M := comap f ⊥
@[simp] theorem mem_ker {f : M →ₗ[R] M₂} {y} : y ∈ ker f ↔ f y = 0 := mem_bot R
@[simp] theorem ker_id : ker (linear_map.id : M →ₗ[R] M) = ⊥ := rfl
theorem ker_comp (f : M →ₗ[R] M₂) (g : M₂ →ₗ[R] M₃) : ker (g.comp f) = comap f (ker g) := rfl
theorem ker_le_ker_comp (f : M →ₗ[R] M₂) (g : M₂ →ₗ[R] M₃) : ker f ≤ ker (g.comp f) :=
by rw ker_comp; exact comap_mono bot_le
theorem sub_mem_ker_iff {f : M →ₗ[R] M₂} {x y} : x - y ∈ f.ker ↔ f x = f y :=
by rw [mem_ker, map_sub, sub_eq_zero]
theorem disjoint_ker {f : M →ₗ[R] M₂} {p : submodule R M} :
disjoint p (ker f) ↔ ∀ x ∈ p, f x = 0 → x = 0 :=
by simp [disjoint_def]
theorem disjoint_ker' {f : M →ₗ[R] M₂} {p : submodule R M} :
disjoint p (ker f) ↔ ∀ x y ∈ p, f x = f y → x = y :=
disjoint_ker.trans
⟨λ H x y hx hy h, eq_of_sub_eq_zero $ H _ (sub_mem _ hx hy) (by simp [h]),
λ H x h₁ h₂, H x 0 h₁ (zero_mem _) (by simpa using h₂)⟩
theorem inj_of_disjoint_ker {f : M →ₗ[R] M₂} {p : submodule R M}
{s : set M} (h : s ⊆ p) (hd : disjoint p (ker f)) :
∀ x y ∈ s, f x = f y → x = y :=
λ x y hx hy, disjoint_ker'.1 hd _ _ (h hx) (h hy)
lemma disjoint_inl_inr : disjoint (inl R M M₂).range (inr R M M₂).range :=
by simp [disjoint_def, @eq_comm M 0, @eq_comm M₂ 0] {contextual := tt}; intros; refl
theorem ker_eq_bot {f : M →ₗ[R] M₂} : ker f = ⊥ ↔ injective f :=
by simpa [disjoint] using @disjoint_ker' _ _ _ _ _ _ _ _ f ⊤
theorem ker_eq_bot' {f : M →ₗ[R] M₂} :
ker f = ⊥ ↔ (∀ m, f m = 0 → m = 0) :=
have h : (∀ m ∈ (⊤ : submodule R M), f m = 0 → m = 0) ↔ (∀ m, f m = 0 → m = 0),
from ⟨λ h m, h m mem_top, λ h m _, h m⟩,
by simpa [h, disjoint] using @disjoint_ker _ _ _ _ _ _ _ _ f ⊤
lemma le_ker_iff_map {f : M →ₗ[R] M₂} {p : submodule R M} : p ≤ ker f ↔ map f p = ⊥ :=
by rw [ker, eq_bot_iff, map_le_iff_le_comap]
lemma ker_cod_restrict (p : submodule R M) (f : M₂ →ₗ[R] M) (hf) :
ker (cod_restrict p f hf) = ker f :=
by rw [ker, comap_cod_restrict, map_bot]; refl
lemma range_cod_restrict (p : submodule R M) (f : M₂ →ₗ[R] M) (hf) :
range (cod_restrict p f hf) = comap p.subtype f.range :=
map_cod_restrict _ _ _ _
lemma map_comap_eq (f : M →ₗ[R] M₂) (q : submodule R M₂) :
map f (comap f q) = range f ⊓ q :=
le_antisymm (le_inf (map_mono le_top) (map_comap_le _ _)) $
by rintro _ ⟨⟨x, _, rfl⟩, hx⟩; exact ⟨x, hx, rfl⟩
lemma map_comap_eq_self {f : M →ₗ[R] M₂} {q : submodule R M₂} (h : q ≤ range f) :
map f (comap f q) = q :=
by rw [map_comap_eq, inf_of_le_right h]
lemma comap_map_eq (f : M →ₗ[R] M₂) (p : submodule R M) :
comap f (map f p) = p ⊔ ker f :=
begin
refine le_antisymm _ (sup_le (le_comap_map _ _) (comap_mono bot_le)),
rintro x ⟨y, hy, e⟩,
exact mem_sup.2 ⟨y, hy, x - y, by simpa using sub_eq_zero.2 e.symm, by simp⟩
end
lemma comap_map_eq_self {f : M →ₗ[R] M₂} {p : submodule R M} (h : ker f ≤ p) :
comap f (map f p) = p :=
by rw [comap_map_eq, sup_of_le_left h]
@[simp] theorem ker_zero : ker (0 : M →ₗ[R] M₂) = ⊤ :=
eq_top_iff'.2 $ λ x, by simp
@[simp] theorem range_zero : range (0 : M →ₗ[R] M₂) = ⊥ :=
submodule.map_zero _
theorem ker_eq_top {f : M →ₗ[R] M₂} : ker f = ⊤ ↔ f = 0 :=
⟨λ h, ext $ λ x, mem_ker.1 $ h.symm ▸ trivial, λ h, h.symm ▸ ker_zero⟩
lemma range_le_bot_iff (f : M →ₗ[R] M₂) : range f ≤ ⊥ ↔ f = 0 :=
by rw [range_le_iff_comap]; exact ker_eq_top
theorem map_le_map_iff {f : M →ₗ[R] M₂} (hf : ker f = ⊥) {p p'} : map f p ≤ map f p' ↔ p ≤ p' :=
⟨λ H x hx, let ⟨y, hy, e⟩ := H ⟨x, hx, rfl⟩ in ker_eq_bot.1 hf e ▸ hy, map_mono⟩
theorem map_injective {f : M →ₗ[R] M₂} (hf : ker f = ⊥) : injective (map f) :=
λ p p' h, le_antisymm ((map_le_map_iff hf).1 (le_of_eq h)) ((map_le_map_iff hf).1 (ge_of_eq h))
theorem comap_le_comap_iff {f : M →ₗ[R] M₂} (hf : range f = ⊤) {p p'} : comap f p ≤ comap f p' ↔ p ≤ p' :=
⟨λ H x hx, by rcases range_eq_top.1 hf x with ⟨y, hy, rfl⟩; exact H hx, comap_mono⟩
theorem comap_injective {f : M →ₗ[R] M₂} (hf : range f = ⊤) : injective (comap f) :=
λ p p' h, le_antisymm ((comap_le_comap_iff hf).1 (le_of_eq h)) ((comap_le_comap_iff hf).1 (ge_of_eq h))
theorem map_copair_prod (f : M →ₗ[R] M₃) (g : M₂ →ₗ[R] M₃) (p : submodule R M) (q : submodule R M₂) :
map (copair f g) (p.prod q) = map f p ⊔ map g q :=
begin
refine le_antisymm _ (sup_le (map_le_iff_le_comap.2 _) (map_le_iff_le_comap.2 _)),
{ rw le_def', rintro _ ⟨x, ⟨h₁, h₂⟩, rfl⟩,
exact mem_sup.2 ⟨_, ⟨_, h₁, rfl⟩, _, ⟨_, h₂, rfl⟩, rfl⟩ },
{ exact λ x hx, ⟨(x, 0), by simp [hx]⟩ },
{ exact λ x hx, ⟨(0, x), by simp [hx]⟩ }
end
theorem comap_pair_prod (f : M →ₗ[R] M₂) (g : M →ₗ[R] M₃) (p : submodule R M₂) (q : submodule R M₃) :
comap (pair f g) (p.prod q) = comap f p ⊓ comap g q :=
submodule.ext $ λ x, iff.rfl
theorem prod_eq_inf_comap (p : submodule R M) (q : submodule R M₂) :
p.prod q = p.comap (linear_map.fst R M M₂) ⊓ q.comap (linear_map.snd R M M₂) :=
submodule.ext $ λ x, iff.rfl
theorem prod_eq_sup_map (p : submodule R M) (q : submodule R M₂) :
p.prod q = p.map (linear_map.inl R M M₂) ⊔ q.map (linear_map.inr R M M₂) :=
by rw [← map_copair_prod, copair_inl_inr, map_id]
lemma span_inl_union_inr {s : set M} {t : set M₂} :
span R (prod.inl '' s ∪ prod.inr '' t) = (span R s).prod (span R t) :=
by rw [span_union, prod_eq_sup_map, ← span_image, ← span_image]; refl
lemma ker_pair (f : M →ₗ[R] M₂) (g : M →ₗ[R] M₃) :
ker (pair f g) = ker f ⊓ ker g :=
by rw [ker, ← prod_bot, comap_pair_prod]; refl
end linear_map
namespace linear_map
variables [discrete_field K]
variables [add_comm_group V] [vector_space K V]
variables [add_comm_group V₂] [vector_space K V₂]
lemma ker_smul (f : V →ₗ[K] V₂) (a : K) (h : a ≠ 0) : ker (a • f) = ker f :=
submodule.comap_smul f _ a h
lemma ker_smul' (f : V →ₗ[K] V₂) (a : K) : ker (a • f) = ⨅(h : a ≠ 0), ker f :=
submodule.comap_smul' f _ a
lemma range_smul (f : V →ₗ[K] V₂) (a : K) (h : a ≠ 0) : range (a • f) = range f :=
submodule.map_smul f _ a h
lemma range_smul' (f : V →ₗ[K] V₂) (a : K) : range (a • f) = ⨆(h : a ≠ 0), range f :=
submodule.map_smul' f _ a
end linear_map
namespace is_linear_map
lemma is_linear_map_add {R M : Type*} [ring R] [add_comm_group M] [module R M]:
is_linear_map R (λ (x : M × M), x.1 + x.2) :=
begin
apply is_linear_map.mk,
{ intros x y,
simp },
{ intros x y,
simp [smul_add] }
end
lemma is_linear_map_sub {R M : Type*} [ring R] [add_comm_group M] [module R M]:
is_linear_map R (λ (x : M × M), x.1 - x.2) :=
begin
apply is_linear_map.mk,
{ intros x y,
simp },
{ intros x y,
simp [smul_add] }
end
end is_linear_map
namespace submodule
variables {T : ring R} [add_comm_group M] [add_comm_group M₂] [module R M] [module R M₂]
variables (p p' : submodule R M) (q : submodule R M₂)
include T
open linear_map
@[simp] theorem map_top (f : M →ₗ[R] M₂) : map f ⊤ = range f := rfl
@[simp] theorem comap_bot (f : M →ₗ[R] M₂) : comap f ⊥ = ker f := rfl
@[simp] theorem ker_subtype : p.subtype.ker = ⊥ :=
ker_eq_bot.2 $ λ x y, subtype.eq'
@[simp] theorem range_subtype : p.subtype.range = p :=
by simpa using map_comap_subtype p ⊤
lemma map_subtype_le (p' : submodule R p) : map p.subtype p' ≤ p :=
by simpa using (map_mono le_top : map p.subtype p' ≤ p.subtype.range)
@[simp] theorem ker_of_le (p p' : submodule R M) (h : p ≤ p') : (of_le h).ker = ⊥ :=
by rw [of_le, ker_cod_restrict, ker_subtype]
lemma range_of_le (p q : submodule R M) (h : p ≤ q) : (of_le h).range = comap q.subtype p :=
by rw [← map_top, of_le, linear_map.map_cod_restrict, map_top, range_subtype]
lemma disjoint_iff_comap_eq_bot (p q : submodule R M) :
disjoint p q ↔ comap p.subtype q = ⊥ :=
by rw [eq_bot_iff, ← map_le_map_iff p.ker_subtype, map_bot, map_comap_subtype]; refl
/-- If N ⊆ M then submodules of N are the same as submodules of M contained in N -/
def map_subtype.order_iso :
((≤) : submodule R p → submodule R p → Prop) ≃o
((≤) : {p' : submodule R M // p' ≤ p} → {p' : submodule R M // p' ≤ p} → Prop) :=
{ to_fun := λ p', ⟨map p.subtype p', map_subtype_le p _⟩,
inv_fun := λ q, comap p.subtype q,
left_inv := λ p', comap_map_eq_self $ by simp,
right_inv := λ ⟨q, hq⟩, subtype.eq' $ by simp [map_comap_subtype p, inf_of_le_right hq],
ord := λ p₁ p₂, (map_le_map_iff $ ker_subtype _).symm }
/-- If `p ⊆ M` is a submodule, the ordering of submodules of `p` is embedded in the ordering of
submodules of M. -/
def map_subtype.le_order_embedding :
((≤) : submodule R p → submodule R p → Prop) ≼o ((≤) : submodule R M → submodule R M → Prop) :=
(order_iso.to_order_embedding $ map_subtype.order_iso p).trans (subtype.order_embedding _ _)
@[simp] lemma map_subtype_embedding_eq (p' : submodule R p) :
map_subtype.le_order_embedding p p' = map p.subtype p' := rfl
/-- If `p ⊆ M` is a submodule, the ordering of submodules of `p` is embedded in the ordering of
submodules of M. -/
def map_subtype.lt_order_embedding :
((<) : submodule R p → submodule R p → Prop) ≼o ((<) : submodule R M → submodule R M → Prop) :=
(map_subtype.le_order_embedding p).lt_embedding_of_le_embedding
@[simp] theorem map_inl : p.map (inl R M M₂) = prod p ⊥ :=
by ext ⟨x, y⟩; simp [and.left_comm, eq_comm]
@[simp] theorem map_inr : q.map (inr R M M₂) = prod ⊥ q :=
by ext ⟨x, y⟩; simp [and.left_comm, eq_comm]
@[simp] theorem comap_fst : p.comap (fst R M M₂) = prod p ⊤ :=
by ext ⟨x, y⟩; simp
@[simp] theorem comap_snd : q.comap (snd R M M₂) = prod ⊤ q :=
by ext ⟨x, y⟩; simp
@[simp] theorem prod_comap_inl : (prod p q).comap (inl R M M₂) = p := by ext; simp
@[simp] theorem prod_comap_inr : (prod p q).comap (inr R M M₂) = q := by ext; simp
@[simp] theorem prod_map_fst : (prod p q).map (fst R M M₂) = p :=
by ext x; simp [(⟨0, zero_mem _⟩ : ∃ x, x ∈ q)]
@[simp] theorem prod_map_snd : (prod p q).map (snd R M M₂) = q :=
by ext x; simp [(⟨0, zero_mem _⟩ : ∃ x, x ∈ p)]
@[simp] theorem ker_inl : (inl R M M₂).ker = ⊥ :=
by rw [ker, ← prod_bot, prod_comap_inl]
@[simp] theorem ker_inr : (inr R M M₂).ker = ⊥ :=
by rw [ker, ← prod_bot, prod_comap_inr]
@[simp] theorem range_fst : (fst R M M₂).range = ⊤ :=
by rw [range, ← prod_top, prod_map_fst]
@[simp] theorem range_snd : (snd R M M₂).range = ⊤ :=
by rw [range, ← prod_top, prod_map_snd]
/-- The map from a module `M` to the quotient of `M` by a submodule `p` is a linear map. -/
def mkq : M →ₗ[R] p.quotient := ⟨quotient.mk, by simp, by simp⟩
@[simp] theorem mkq_apply (x : M) : p.mkq x = quotient.mk x := rfl
/-- The map from the quotient of `M` by a submodule `p` to `M₂` along `f : M → M₂` is linear. -/
def liftq (f : M →ₗ[R] M₂) (h : p ≤ f.ker) : p.quotient →ₗ[R] M₂ :=
⟨λ x, _root_.quotient.lift_on' x f $
λ a b (ab : a - b ∈ p), eq_of_sub_eq_zero $ by simpa using h ab,
by rintro ⟨x⟩ ⟨y⟩; exact f.map_add x y,
by rintro a ⟨x⟩; exact f.map_smul a x⟩
@[simp] theorem liftq_apply (f : M →ₗ[R] M₂) {h} (x : M) :
p.liftq f h (quotient.mk x) = f x := rfl
@[simp] theorem liftq_mkq (f : M →ₗ[R] M₂) (h) : (p.liftq f h).comp p.mkq = f :=
by ext; refl
@[simp] theorem range_mkq : p.mkq.range = ⊤ :=
eq_top_iff'.2 $ by rintro ⟨x⟩; exact ⟨x, trivial, rfl⟩
@[simp] theorem ker_mkq : p.mkq.ker = p :=
by ext; simp
lemma le_comap_mkq (p' : submodule R p.quotient) : p ≤ comap p.mkq p' :=
by simpa using (comap_mono bot_le : p.mkq.ker ≤ comap p.mkq p')
@[simp] theorem mkq_map_self : map p.mkq p = ⊥ :=
by rw [eq_bot_iff, map_le_iff_le_comap, comap_bot, ker_mkq]; exact le_refl _
@[simp] theorem comap_map_mkq : comap p.mkq (map p.mkq p') = p ⊔ p' :=
by simp [comap_map_eq, sup_comm]
/-- The map from the quotient of `M` by submodule `p` to the quotient of `M₂` by submodule `q` along
`f : M → M₂` is linear. -/
def mapq (f : M →ₗ[R] M₂) (h : p ≤ comap f q) : p.quotient →ₗ[R] q.quotient :=
p.liftq (q.mkq.comp f) $ by simpa [ker_comp] using h
@[simp] theorem mapq_apply (f : M →ₗ[R] M₂) {h} (x : M) :
mapq p q f h (quotient.mk x) = quotient.mk (f x) := rfl
theorem mapq_mkq (f : M →ₗ[R] M₂) {h} : (mapq p q f h).comp p.mkq = q.mkq.comp f :=
by ext x; refl
theorem comap_liftq (f : M →ₗ[R] M₂) (h) :
q.comap (p.liftq f h) = (q.comap f).map (mkq p) :=
le_antisymm
(by rintro ⟨x⟩ hx; exact ⟨_, hx, rfl⟩)
(by rw [map_le_iff_le_comap, ← comap_comp, liftq_mkq]; exact le_refl _)
theorem map_liftq (f : M →ₗ[R] M₂) (h) (q : submodule R (quotient p)) :
q.map (p.liftq f h) = (q.comap p.mkq).map f :=
le_antisymm
(by rintro _ ⟨⟨x⟩, hxq, rfl⟩; exact ⟨x, hxq, rfl⟩)
(by rintro _ ⟨x, hxq, rfl⟩; exact ⟨quotient.mk x, hxq, rfl⟩)
theorem ker_liftq (f : M →ₗ[R] M₂) (h) :
ker (p.liftq f h) = (ker f).map (mkq p) := comap_liftq _ _ _ _
theorem range_liftq (f : M →ₗ[R] M₂) (h) :
range (p.liftq f h) = range f := map_liftq _ _ _ _
theorem ker_liftq_eq_bot (f : M →ₗ[R] M₂) (h) (h' : ker f ≤ p) : ker (p.liftq f h) = ⊥ :=
by rw [ker_liftq, le_antisymm h h', mkq_map_self]
/-- The correspondence theorem for modules: there is an order isomorphism between submodules of the
quotient of `M` by `p`, and submodules of `M` larger than `p`. -/
def comap_mkq.order_iso :
((≤) : submodule R p.quotient → submodule R p.quotient → Prop) ≃o
((≤) : {p' : submodule R M // p ≤ p'} → {p' : submodule R M // p ≤ p'} → Prop) :=
{ to_fun := λ p', ⟨comap p.mkq p', le_comap_mkq p _⟩,
inv_fun := λ q, map p.mkq q,
left_inv := λ p', map_comap_eq_self $ by simp,
right_inv := λ ⟨q, hq⟩, subtype.eq' $ by simp [comap_map_mkq p, sup_of_le_right hq],
ord := λ p₁ p₂, (comap_le_comap_iff $ range_mkq _).symm }
/-- The ordering on submodules of the quotient of `M` by `p` embeds into the ordering on submodules
of `M`. -/
def comap_mkq.le_order_embedding :
((≤) : submodule R p.quotient → submodule R p.quotient → Prop) ≼o ((≤) : submodule R M → submodule R M → Prop) :=
(order_iso.to_order_embedding $ comap_mkq.order_iso p).trans (subtype.order_embedding _ _)
@[simp] lemma comap_mkq_embedding_eq (p' : submodule R p.quotient) :
comap_mkq.le_order_embedding p p' = comap p.mkq p' := rfl
/-- The ordering on submodules of the quotient of `M` by `p` embeds into the ordering on submodules
of `M`. -/
def comap_mkq.lt_order_embedding :
((<) : submodule R p.quotient → submodule R p.quotient → Prop) ≼o ((<) : submodule R M → submodule R M → Prop) :=
(comap_mkq.le_order_embedding p).lt_embedding_of_le_embedding
end submodule
section
set_option old_structure_cmd true
/-- A linear equivalence is an invertible linear map. -/
structure linear_equiv (R : Type u) (M : Type v) (M₂ : Type w)
[ring R] [add_comm_group M] [add_comm_group M₂] [module R M] [module R M₂]
extends M →ₗ[R] M₂, M ≃ M₂
end
infix ` ≃ₗ ` := linear_equiv _
notation M ` ≃ₗ[`:50 R `] ` M₂ := linear_equiv R M M₂
namespace linear_equiv
section ring
variables [ring R] [add_comm_group M] [add_comm_group M₂] [add_comm_group M₃]
variables [module R M] [module R M₂] [module R M₃]
include R
instance : has_coe (M ≃ₗ[R] M₂) (M →ₗ[R] M₂) := ⟨to_linear_map⟩
@[simp] theorem coe_apply (e : M ≃ₗ[R] M₂) (b : M) : (e : M →ₗ[R] M₂) b = e b := rfl
lemma to_equiv_injective : function.injective (to_equiv : (M ≃ₗ[R] M₂) → M ≃ M₂) :=
λ ⟨_, _, _, _, _, _⟩ ⟨_, _, _, _, _, _⟩ h, linear_equiv.mk.inj_eq.mpr (equiv.mk.inj h)
@[ext] lemma ext {f g : M ≃ₗ[R] M₂} (h : (f : M → M₂) = g) : f = g :=
to_equiv_injective (equiv.eq_of_to_fun_eq h)
section
variable (M)
/-- The identity map is a linear equivalence. -/
def refl : M ≃ₗ[R] M := { .. linear_map.id, .. equiv.refl M }
end
/-- Linear equivalences are symmetric. -/
def symm (e : M ≃ₗ[R] M₂) : M₂ ≃ₗ[R] M :=
{ .. e.to_linear_map.inverse e.inv_fun e.left_inv e.right_inv,
.. e.to_equiv.symm }
/-- Linear equivalences are transitive. -/
def trans (e₁ : M ≃ₗ[R] M₂) (e₂ : M₂ ≃ₗ[R] M₃) : M ≃ₗ[R] M₃ :=
{ .. e₂.to_linear_map.comp e₁.to_linear_map,
.. e₁.to_equiv.trans e₂.to_equiv }
@[simp] theorem apply_symm_apply (e : M ≃ₗ[R] M₂) (c : M₂) : e (e.symm c) = c := e.6 c
@[simp] theorem symm_apply_apply (e : M ≃ₗ[R] M₂) (b : M) : e.symm (e b) = b := e.5 b
/-- A bijective linear map is a linear equivalence. Here, bijectivity is described by saying that
the kernel of `f` is `{0}` and the range is the universal set. -/
noncomputable def of_bijective
(f : M →ₗ[R] M₂) (hf₁ : f.ker = ⊥) (hf₂ : f.range = ⊤) : M ≃ₗ[R] M₂ :=
{ ..f, ..@equiv.of_bijective _ _ f
⟨linear_map.ker_eq_bot.1 hf₁, linear_map.range_eq_top.1 hf₂⟩ }
@[simp] theorem of_bijective_apply (f : M →ₗ[R] M₂) {hf₁ hf₂} (x : M) :
of_bijective f hf₁ hf₂ x = f x := rfl
/-- If a linear map has an inverse, it is a linear equivalence. -/
def of_linear (f : M →ₗ[R] M₂) (g : M₂ →ₗ[R] M)
(h₁ : f.comp g = linear_map.id) (h₂ : g.comp f = linear_map.id) : M ≃ₗ[R] M₂ :=
{ inv_fun := g,
left_inv := linear_map.ext_iff.1 h₂,
right_inv := linear_map.ext_iff.1 h₁,
..f }
@[simp] theorem of_linear_apply (f : M →ₗ[R] M₂) (g : M₂ →ₗ[R] M) {h₁ h₂}
(x : M) : of_linear f g h₁ h₂ x = f x := rfl
@[simp] theorem of_linear_symm_apply (f : M →ₗ[R] M₂) (g : M₂ →ₗ[R] M) {h₁ h₂}
(x : M₂) : (of_linear f g h₁ h₂).symm x = g x := rfl
@[simp] protected theorem ker (f : M ≃ₗ[R] M₂) : (f : M →ₗ[R] M₂).ker = ⊥ :=
linear_map.ker_eq_bot.2 f.to_equiv.injective
@[simp] protected theorem range (f : M ≃ₗ[R] M₂) : (f : M →ₗ[R] M₂).range = ⊤ :=
linear_map.range_eq_top.2 f.to_equiv.surjective
/-- The top submodule of `M` is linearly equivalent to `M`. -/
def of_top (p : submodule R M) (h : p = ⊤) : p ≃ₗ[R] M :=
{ inv_fun := λ x, ⟨x, h.symm ▸ trivial⟩,
left_inv := λ ⟨x, h⟩, rfl,
right_inv := λ x, rfl,
.. p.subtype }
@[simp] theorem of_top_apply (p : submodule R M) {h} (x : p) :
of_top p h x = x := rfl
@[simp] theorem of_top_symm_apply (p : submodule R M) {h} (x : M) :
↑((of_top p h).symm x) = x := rfl
lemma eq_bot_of_equiv (p : submodule R M) (e : p ≃ₗ[R] (⊥ : submodule R M₂)) :
p = ⊥ :=
begin
refine bot_unique (submodule.le_def'.2 $ assume b hb, (submodule.mem_bot R).2 _),
have := e.symm_apply_apply ⟨b, hb⟩,
rw [← e.coe_apply, submodule.eq_zero_of_bot_submodule ((e : p →ₗ[R] (⊥ : submodule R M₂)) ⟨b, hb⟩),
← e.symm.coe_apply, linear_map.map_zero] at this,
exact congr_arg (coe : p → M) this.symm
end
end ring
section comm_ring
variables [comm_ring R] [add_comm_group M] [add_comm_group M₂] [add_comm_group M₃]
variables [module R M] [module R M₂] [module R M₃]
include R
open linear_map
set_option class.instance_max_depth 39
/-- Multiplying by a unit `a` of the ring `R` is a linear equivalence. -/
def smul_of_unit (a : units R) : M ≃ₗ[R] M :=
of_linear ((a:R) • 1 : M →ₗ M) (((a⁻¹ : units R) : R) • 1 : M →ₗ M)
(by rw [smul_comp, comp_smul, smul_smul, units.mul_inv, one_smul]; refl)
(by rw [smul_comp, comp_smul, smul_smul, units.inv_mul, one_smul]; refl)
/-- A linear isomorphism between the domains and codomains of two spaces of linear maps gives a
linear isomorphism between the two function spaces. -/
def arrow_congr {R M₁ M₂ M₂₁ M₂₂ : Sort*} [comm_ring R]
[add_comm_group M₁] [add_comm_group M₂] [add_comm_group M₂₁] [add_comm_group M₂₂]
[module R M₁] [module R M₂] [module R M₂₁] [module R M₂₂]
(e₁ : M₁ ≃ₗ[R] M₂) (e₂ : M₂₁ ≃ₗ[R] M₂₂) :
(M₁ →ₗ[R] M₂₁) ≃ₗ[R] (M₂ →ₗ[R] M₂₂) :=
{ to_fun := λ f, e₂.to_linear_map.comp $ f.comp e₁.symm.to_linear_map,
inv_fun := λ f, e₂.symm.to_linear_map.comp $ f.comp e₁.to_linear_map,
left_inv := λ f, by { ext x, unfold_coes,
change e₂.inv_fun (e₂.to_fun $ f.to_fun $ e₁.inv_fun $ e₁.to_fun x) = _,
rw [e₁.left_inv, e₂.left_inv] },
right_inv := λ f, by { ext x, unfold_coes,
change e₂.to_fun (e₂.inv_fun $ f.to_fun $ e₁.to_fun $ e₁.inv_fun x) = _,
rw [e₁.right_inv, e₂.right_inv] },
add := λ f g, by { ext x, change e₂.to_fun ((f + g) (e₁.inv_fun x)) = _,
rw [linear_map.add_apply, e₂.add], refl },
smul := λ c f, by { ext x, change e₂.to_fun ((c • f) (e₁.inv_fun x)) = _,
rw [linear_map.smul_apply, e₂.smul], refl } }
/-- If M₂ and M₃ are linearly isomorphic then the two spaces of linear maps from M into M₂ and
M into M₃ are linearly isomorphic. -/
def congr_right (f : M₂ ≃ₗ[R] M₃) : (M →ₗ[R] M₂) ≃ₗ (M →ₗ M₃) := arrow_congr (linear_equiv.refl M) f
/-- If M and M₂ are linearly isomorphic then the two spaces of linear maps from M and M₂ to themselves
are linearly isomorphic. -/
def conj (e : M ≃ₗ[R] M₂) : (M →ₗ[R] M) ≃ₗ[R] (M₂ →ₗ[R] M₂) := arrow_congr e e
end comm_ring
section field
variables [field K] [add_comm_group M] [add_comm_group M₂] [add_comm_group M₃]
variables [module K M] [module K M₂] [module K M₃]
variable (M)
open linear_map
/-- Multiplying by a nonzero element `a` of the field `K` is a linear equivalence. -/
def smul_of_ne_zero (a : K) (ha : a ≠ 0) : M ≃ₗ[K] M :=
smul_of_unit $ units.mk0 a ha
end field
end linear_equiv
namespace equiv
variables [ring R] [add_comm_group M] [module R M] [add_comm_group M₂] [module R M₂]
/-- An equivalence whose underlying function is linear is a linear equivalence. -/
def to_linear_equiv (e : M ≃ M₂) (h : is_linear_map R (e : M → M₂)) : M ≃ₗ[R] M₂ :=
{ add := h.add, smul := h.smul, .. e}
end equiv
namespace linear_map
variables [ring R] [add_comm_group M] [add_comm_group M₂] [add_comm_group M₃]
variables [module R M] [module R M₂] [module R M₃]
variables (f : M →ₗ[R] M₂)
/-- The first isomorphism law for modules. The quotient of `M` by the kernel of `f` is linearly
equivalent to the range of `f`. -/
noncomputable def quot_ker_equiv_range : f.ker.quotient ≃ₗ[R] f.range :=
have hr : ∀ x : f.range, ∃ y, f y = ↑x := λ x, x.2.imp $ λ _, and.right,
let F : f.ker.quotient →ₗ[R] f.range :=
f.ker.liftq (cod_restrict f.range f $ λ x, ⟨x, trivial, rfl⟩)
(λ x hx, by simp; apply subtype.coe_ext.2; simpa using hx) in
{ inv_fun := λx, submodule.quotient.mk (classical.some (hr x)),
left_inv := by rintro ⟨x⟩; exact
(submodule.quotient.eq _).2 (sub_mem_ker_iff.2 $
classical.some_spec $ hr $ F $ submodule.quotient.mk x),
right_inv := λ x : range f, subtype.eq $ classical.some_spec (hr x),
.. F }
open submodule
/--
Canonical linear map from the quotient p/(p ∩ p') to (p+p')/p', mapping x + (p ∩ p') to x + p',
where p and p' are submodules of an ambient module.
-/
def sup_quotient_to_quotient_inf (p p' : submodule R M) :
(comap p.subtype (p ⊓ p')).quotient →ₗ[R] (comap (p ⊔ p').subtype p').quotient :=
(comap p.subtype (p ⊓ p')).liftq
((comap (p ⊔ p').subtype p').mkq.comp (of_le le_sup_left)) begin
rw [ker_comp, of_le, comap_cod_restrict, ker_mkq, map_comap_subtype],
exact comap_mono (inf_le_inf le_sup_left (le_refl _)) end
set_option class.instance_max_depth 41
/--
Second Isomorphism Law : the canonical map from p/(p ∩ p') to (p+p')/p' as a linear isomorphism.
-/
noncomputable def sup_quotient_equiv_quotient_inf (p p' : submodule R M) :
(comap p.subtype (p ⊓ p')).quotient ≃ₗ[R] (comap (p ⊔ p').subtype p').quotient :=
{ .. sup_quotient_to_quotient_inf p p',
.. show (comap p.subtype (p ⊓ p')).quotient ≃ (comap (p ⊔ p').subtype p').quotient, from
@equiv.of_bijective _ _ (sup_quotient_to_quotient_inf p p') begin
constructor,
{ rw [← ker_eq_bot, sup_quotient_to_quotient_inf, ker_liftq_eq_bot],
rw [ker_comp, ker_mkq],
rintros ⟨x, hx1⟩ hx2, exact ⟨hx1, hx2⟩ },
rw [← range_eq_top, sup_quotient_to_quotient_inf, range_liftq, eq_top_iff'],
rintros ⟨x, hx⟩, rcases mem_sup.1 hx with ⟨y, hy, z, hz, rfl⟩,
use [⟨y, hy⟩, trivial], apply (submodule.quotient.eq _).2,
change y - (y + z) ∈ p', rwa [sub_add_eq_sub_sub, sub_self, zero_sub, neg_mem_iff]
end }
section prod
/-- The cartesian product of two linear maps as a linear map. -/
def prod {R M M₂ M₃ : Type*} [ring R] [add_comm_group M] [add_comm_group M₂] [add_comm_group M₃]
[module R M] [module R M₂] [module R M₃]
(f₁ : M →ₗ[R] M₂) (f₂ : M →ₗ[R] M₃) : M →ₗ[R] (M₂ × M₃) :=
{ to_fun := λx, (f₁ x, f₂ x),
add := λx y, begin
change (f₁ (x + y), f₂ (x+y)) = (f₁ x, f₂ x) + (f₁ y, f₂ y),
simp only [linear_map.map_add],
refl
end,
smul := λc x, by simp only [linear_map.map_smul] }
lemma is_linear_map_prod_iso {R M M₂ M₃ : Type*} [comm_ring R] [add_comm_group M] [add_comm_group M₂]
[add_comm_group M₃] [module R M] [module R M₂] [module R M₃] :
is_linear_map R (λ(p : (M →ₗ[R] M₂) × (M →ₗ[R] M₃)), (linear_map.prod p.1 p.2 : (M →ₗ[R] (M₂ × M₃)))) :=
⟨λu v, rfl, λc u, rfl⟩
end prod
section pi
universe i
variables {φ : ι → Type i}
variables [∀i, add_comm_group (φ i)] [∀i, module R (φ i)]
/-- `pi` construction for linear functions. From a family of linear functions it produces a linear
function into a family of modules. -/
def pi (f : Πi, M₂ →ₗ[R] φ i) : M₂ →ₗ[R] (Πi, φ i) :=
⟨λc i, f i c,
assume c d, funext $ assume i, (f i).add _ _, assume c d, funext $ assume i, (f i).smul _ _⟩
@[simp] lemma pi_apply (f : Πi, M₂ →ₗ[R] φ i) (c : M₂) (i : ι) :
pi f c i = f i c := rfl
lemma ker_pi (f : Πi, M₂ →ₗ[R] φ i) : ker (pi f) = (⨅i:ι, ker (f i)) :=
by ext c; simp [funext_iff]; refl
lemma pi_eq_zero (f : Πi, M₂ →ₗ[R] φ i) : pi f = 0 ↔ (∀i, f i = 0) :=
by simp only [linear_map.ext_iff, pi_apply, funext_iff]; exact ⟨λh a b, h b a, λh a b, h b a⟩
lemma pi_zero : pi (λi, 0 : Πi, M₂ →ₗ[R] φ i) = 0 :=
by ext; refl
lemma pi_comp (f : Πi, M₂ →ₗ[R] φ i) (g : M₃ →ₗ[R] M₂) : (pi f).comp g = pi (λi, (f i).comp g) :=
rfl
/-- The projections from a family of modules are linear maps. -/
def proj (i : ι) : (Πi, φ i) →ₗ[R] φ i :=
⟨ λa, a i, assume f g, rfl, assume c f, rfl ⟩
@[simp] lemma proj_apply (i : ι) (b : Πi, φ i) : (proj i : (Πi, φ i) →ₗ[R] φ i) b = b i := rfl
lemma proj_pi (f : Πi, M₂ →ₗ[R] φ i) (i : ι) : (proj i).comp (pi f) = f i :=
ext $ assume c, rfl
lemma infi_ker_proj : (⨅i, ker (proj i) : submodule R (Πi, φ i)) = ⊥ :=
bot_unique $ submodule.le_def'.2 $ assume a h,
begin
simp only [mem_infi, mem_ker, proj_apply] at h,
exact (mem_bot _).2 (funext $ assume i, h i)
end
section
variables (R φ)
/-- If `I` and `J` are disjoint index sets, the product of the kernels of the `J`th projections of
`φ` is linearly equivalent to the product over `I`. -/
def infi_ker_proj_equiv {I J : set ι} [decidable_pred (λi, i ∈ I)]
(hd : disjoint I J) (hu : set.univ ⊆ I ∪ J) :
(⨅i ∈ J, ker (proj i) : submodule R (Πi, φ i)) ≃ₗ[R] (Πi:I, φ i) :=
begin
refine linear_equiv.of_linear
(pi $ λi, (proj (i:ι)).comp (submodule.subtype _))
(cod_restrict _ (pi $ λi, if h : i ∈ I then proj (⟨i, h⟩ : I) else 0) _) _ _,
{ assume b,
simp only [mem_infi, mem_ker, funext_iff, proj_apply, pi_apply],
assume j hjJ,
have : j ∉ I := assume hjI, hd ⟨hjI, hjJ⟩,
rw [dif_neg this, zero_apply] },
{ simp only [pi_comp, comp_assoc, subtype_comp_cod_restrict, proj_pi, dif_pos, subtype.val_prop'],
ext b ⟨j, hj⟩, refl },
{ ext ⟨b, hb⟩,
apply subtype.coe_ext.2,
ext j,
have hb : ∀i ∈ J, b i = 0,
{ simpa only [mem_infi, mem_ker, proj_apply] using (mem_infi _).1 hb },
simp only [comp_apply, pi_apply, id_apply, proj_apply, subtype_apply, cod_restrict_apply],
split_ifs,
{ rw [dif_pos h], refl },
{ rw [dif_neg h],
exact (hb _ $ (hu trivial).resolve_left h).symm } }
end
end
section
variable [decidable_eq ι]
/-- `diag i j` is the identity map if `i = j`. Otherwise it is the constant 0 map. -/
def diag (i j : ι) : φ i →ₗ[R] φ j :=
@function.update ι (λj, φ i →ₗ[R] φ j) _ 0 i id j
lemma update_apply (f : Πi, M₂ →ₗ[R] φ i) (c : M₂) (i j : ι) (b : M₂ →ₗ[R] φ i) :
(update f i b j) c = update (λi, f i c) i (b c) j :=
begin
by_cases j = i,
{ rw [h, update_same, update_same] },
{ rw [update_noteq h, update_noteq h] }
end
end
section
variable [decidable_eq ι]
variables (R φ)
/-- The standard basis of the product of `φ`. -/
def std_basis (i : ι) : φ i →ₗ[R] (Πi, φ i) := pi (diag i)
lemma std_basis_apply (i : ι) (b : φ i) : std_basis R φ i b = update 0 i b :=
by ext j; rw [std_basis, pi_apply, diag, update_apply]; refl
@[simp] lemma std_basis_same (i : ι) (b : φ i) : std_basis R φ i b i = b :=
by rw [std_basis_apply, update_same]
lemma std_basis_ne (i j : ι) (h : j ≠ i) (b : φ i) : std_basis R φ i b j = 0 :=
by rw [std_basis_apply, update_noteq h]; refl
lemma ker_std_basis (i : ι) : ker (std_basis R φ i) = ⊥ :=
ker_eq_bot.2 $ assume f g hfg,
have std_basis R φ i f i = std_basis R φ i g i := hfg ▸ rfl,
by simpa only [std_basis_same]
lemma proj_comp_std_basis (i j : ι) : (proj i).comp (std_basis R φ j) = diag j i :=
by rw [std_basis, proj_pi]
lemma proj_std_basis_same (i : ι) : (proj i).comp (std_basis R φ i) = id :=
by ext b; simp
lemma proj_std_basis_ne (i j : ι) (h : i ≠ j) : (proj i).comp (std_basis R φ j) = 0 :=
by ext b; simp [std_basis_ne R φ _ _ h]
lemma supr_range_std_basis_le_infi_ker_proj (I J : set ι) (h : disjoint I J) :
(⨆i∈I, range (std_basis R φ i)) ≤ (⨅i∈J, ker (proj i)) :=
begin
refine (supr_le $ assume i, supr_le $ assume hi, range_le_iff_comap.2 _),
simp only [(ker_comp _ _).symm, eq_top_iff, le_def', mem_ker, comap_infi, mem_infi],
assume b hb j hj,
have : i ≠ j := assume eq, h ⟨hi, eq.symm ▸ hj⟩,
rw [proj_std_basis_ne R φ j i this.symm, zero_apply]
end
lemma infi_ker_proj_le_supr_range_std_basis {I : finset ι} {J : set ι} (hu : set.univ ⊆ ↑I ∪ J) :
(⨅ i∈J, ker (proj i)) ≤ (⨆i∈I, range (std_basis R φ i)) :=
submodule.le_def'.2
begin
assume b hb,
simp only [mem_infi, mem_ker, proj_apply] at hb,
rw ← show I.sum (λi, std_basis R φ i (b i)) = b,
{ ext i,
rw [pi.finset_sum_apply, ← std_basis_same R φ i (b i)],
refine finset.sum_eq_single i (assume j hjI ne, std_basis_ne _ _ _ _ ne.symm _) _,
assume hiI,
rw [std_basis_same],
exact hb _ ((hu trivial).resolve_left hiI) },
exact sum_mem _ (assume i hiI, mem_supr_of_mem _ i $ mem_supr_of_mem _ hiI $
linear_map.mem_range.2 ⟨_, rfl⟩)
end
lemma supr_range_std_basis_eq_infi_ker_proj {I J : set ι}
(hd : disjoint I J) (hu : set.univ ⊆ I ∪ J) (hI : set.finite I) :
(⨆i∈I, range (std_basis R φ i)) = (⨅i∈J, ker (proj i)) :=
begin
refine le_antisymm (supr_range_std_basis_le_infi_ker_proj _ _ _ _ hd) _,
have : set.univ ⊆ ↑hI.to_finset ∪ J, { rwa [finset.coe_to_finset] },
refine le_trans (infi_ker_proj_le_supr_range_std_basis R φ this) (supr_le_supr $ assume i, _),
rw [← finset.mem_coe, finset.coe_to_finset],
exact le_refl _
end
lemma supr_range_std_basis [fintype ι] : (⨆i:ι, range (std_basis R φ i)) = ⊤ :=
have (set.univ : set ι) ⊆ ↑(finset.univ : finset ι) ∪ ∅ := by rw [finset.coe_univ, set.union_empty],
begin
apply top_unique,
convert (infi_ker_proj_le_supr_range_std_basis R φ this),
exact infi_emptyset.symm,
exact (funext $ λi, (@supr_pos _ _ _ (λh, range (std_basis R φ i)) $ finset.mem_univ i).symm)
end
lemma disjoint_std_basis_std_basis (I J : set ι) (h : disjoint I J) :
disjoint (⨆i∈I, range (std_basis R φ i)) (⨆i∈J, range (std_basis R φ i)) :=
begin
refine disjoint_mono
(supr_range_std_basis_le_infi_ker_proj _ _ _ _ $ set.disjoint_compl I)
(supr_range_std_basis_le_infi_ker_proj _ _ _ _ $ set.disjoint_compl J) _,
simp only [disjoint, submodule.le_def', mem_infi, mem_inf, mem_ker, mem_bot, proj_apply,
funext_iff],
rintros b ⟨hI, hJ⟩ i,
classical,
by_cases hiI : i ∈ I,
{ by_cases hiJ : i ∈ J,
{ exact (h ⟨hiI, hiJ⟩).elim },
{ exact hJ i hiJ } },
{ exact hI i hiI }
end
lemma std_basis_eq_single {a : R} :
(λ (i : ι), (std_basis R (λ _ : ι, R) i) a) = λ (i : ι), (finsupp.single i a) :=
begin
ext i j,
rw [std_basis_apply, finsupp.single_apply],
split_ifs,
{ rw [h, function.update_same] },
{ rw [function.update_noteq (ne.symm h)], refl },
end
end
end pi
variables (R M)
instance automorphism_group : group (M ≃ₗ[R] M) :=
{ mul := λ f g, g.trans f,
one := linear_equiv.refl M,
inv := λ f, f.symm,
mul_assoc := λ f g h, by {ext, refl},
mul_one := λ f, by {ext, refl},
one_mul := λ f, by {ext, refl},
mul_left_inv := λ f, by {ext, exact f.left_inv x} }
instance automorphism_group.to_linear_map_is_monoid_hom :
is_monoid_hom (linear_equiv.to_linear_map : (M ≃ₗ[R] M) → (M →ₗ[R] M)) :=
{ map_one := rfl,
map_mul := λ f g, rfl }
/-- The group of invertible linear maps from `M` to itself -/
def general_linear_group := units (M →ₗ[R] M)
namespace general_linear_group
variables {R M}
instance : group (general_linear_group R M) := by delta general_linear_group; apply_instance
/-- An invertible linear map `f` determines an equivalence from `M` to itself. -/
def to_linear_equiv (f : general_linear_group R M) : (M ≃ₗ[R] M) :=
{ inv_fun := f.inv.to_fun,
left_inv := λ m, show (f.inv * f.val) m = m,
by erw f.inv_val; simp,
right_inv := λ m, show (f.val * f.inv) m = m,
by erw f.val_inv; simp,
..f.val }
/-- An equivalence from `M` to itself determines an invertible linear map. -/
def of_linear_equiv (f : (M ≃ₗ[R] M)) : general_linear_group R M :=
{ val := f,
inv := f.symm,
val_inv := linear_map.ext $ λ _, f.apply_symm_apply _,
inv_val := linear_map.ext $ λ _, f.symm_apply_apply _ }
variables (R M)
/-- The general linear group on `R` and `M` is multiplicatively equivalent to the type of linear
equivalences between `M` and itself. -/
def general_linear_equiv : general_linear_group R M ≃* (M ≃ₗ[R] M) :=
{ to_fun := to_linear_equiv,
inv_fun := of_linear_equiv,
left_inv := λ f,
begin
delta to_linear_equiv of_linear_equiv,
cases f with f f_inv, cases f, cases f_inv,
congr
end,
right_inv := λ f,
begin
delta to_linear_equiv of_linear_equiv,
cases f,
congr
end,
map_mul' := λ x y, by {ext, refl} }
@[simp] lemma general_linear_equiv_to_linear_map (f : general_linear_group R M) :
((general_linear_equiv R M).to_equiv f).to_linear_map = f.val :=
by {ext, refl}
end general_linear_group
end linear_map
|
355ddb114266cdf9cf50721dd665a85989aa382d | 9a0b1b3a653ea926b03d1495fef64da1d14b3174 | /tidy/rewrite_search/discovery/types.lean | 501c0898ae293562164bdeba798a1fbe00d378d0 | [
"Apache-2.0"
] | permissive | khoek/mathlib-tidy | 8623b27b4e04e7d598164e7eaf248610d58f768b | 866afa6ab597c47f1b72e8fe2b82b97fff5b980f | refs/heads/master | 1,585,598,975,772 | 1,538,659,544,000 | 1,538,659,544,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 507 | lean | import tidy.rewrite_search.core.shared
import .shared
import .bundle
universe u
open tidy.rewrite_search
namespace tidy.rewrite_search.discovery
meta def discovery_trace {α : Type u} [has_to_tactic_format α] (a : α) (nl : bool := tt) : tactic unit := do
str ← tactic.pp a,
let nlc := if nl then "\n" else "",
tactic.trace format!"(discovery): {str}{nlc}"
meta def collector := config → progress → list expr → tactic (progress × list (expr × bool))
end tidy.rewrite_search.discovery |
3608f1d481646002ec6eb175c996ee0726c34d50 | a4673261e60b025e2c8c825dfa4ab9108246c32e | /stage0/src/Lean/Compiler/Specialize.lean | 8229ed516b5b7a2e80c450c3c17f597454eeae09 | [
"Apache-2.0"
] | permissive | jcommelin/lean4 | c02dec0cc32c4bccab009285475f265f17d73228 | 2909313475588cc20ac0436e55548a4502050d0a | refs/heads/master | 1,674,129,550,893 | 1,606,415,348,000 | 1,606,415,348,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 4,347 | 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.Attributes
import Lean.Compiler.Util
namespace Lean.Compiler
inductive SpecializeAttributeKind :=
| specialize | nospecialize
namespace SpecializeAttributeKind
instance : Inhabited SpecializeAttributeKind := ⟨SpecializeAttributeKind.specialize⟩
protected def beq : SpecializeAttributeKind → SpecializeAttributeKind → Bool
| specialize, specialize => true
| nospecialize, nospecialize => true
| _, _ => false
instance : BEq SpecializeAttributeKind := ⟨SpecializeAttributeKind.beq⟩
end SpecializeAttributeKind
builtin_initialize specializeAttrs : EnumAttributes SpecializeAttributeKind ←
registerEnumAttributes `specializeAttrs
[(`specialize, "mark definition to always be specialized", SpecializeAttributeKind.specialize),
(`nospecialize, "mark definition to never be specialized", SpecializeAttributeKind.nospecialize) ]
/- TODO: fix the following hack.
We need to use the following hack because the equation compiler generates auxiliary
definitions that are compiled before we even finish the elaboration of the current command.
So, if the current command is a `@[specialize] def foo ...`, we must set the attribute `[specialize]`
before we start elaboration, otherwise when we compile the auxiliary definitions we will not be
able to test whether `@[specialize]` has been set or not.
In the new equation compiler we should pass all attributes and allow it to apply them to auxiliary definitions.
In the current implementation, we workaround this issue by using functions such as `hasSpecializeAttrAux`.
-/
(fun declName _ => pure ())
AttributeApplicationTime.beforeElaboration
private partial def hasSpecializeAttrAux (env : Environment) (kind : SpecializeAttributeKind) (n : Name) : Bool :=
match specializeAttrs.getValue env n with
| some k => kind == k
| none => if n.isInternal then hasSpecializeAttrAux env kind n.getPrefix else false
@[export lean_has_specialize_attribute]
def hasSpecializeAttribute (env : Environment) (n : Name) : Bool :=
hasSpecializeAttrAux env SpecializeAttributeKind.specialize n
@[export lean_has_nospecialize_attribute]
def hasNospecializeAttribute (env : Environment) (n : Name) : Bool :=
hasSpecializeAttrAux env SpecializeAttributeKind.nospecialize n
inductive SpecArgKind :=
| fixed
| fixedNeutral -- computationally neutral
| fixedHO -- higher order
| fixedInst -- type class instance
| other
structure SpecInfo :=
(mutualDecls : List Name)
(argKinds : SpecArgKind)
structure SpecState :=
(specInfo : SMap Name SpecInfo := {})
(cache : SMap Expr Name := {})
inductive SpecEntry :=
| info (name : Name) (info : SpecInfo)
| cache (key : Expr) (fn : Name)
namespace SpecState
instance : Inhabited SpecState := ⟨{}⟩
def addEntry (s : SpecState) (e : SpecEntry) : SpecState :=
match e with
| SpecEntry.info name info => { s with specInfo := s.specInfo.insert name info }
| SpecEntry.cache key fn => { s with cache := s.cache.insert key fn }
def switch : SpecState → SpecState
| ⟨m₁, m₂⟩ => ⟨m₁.switch, m₂.switch⟩
end SpecState
builtin_initialize specExtension : SimplePersistentEnvExtension SpecEntry SpecState ←
registerSimplePersistentEnvExtension {
name := `specialize,
addEntryFn := SpecState.addEntry,
addImportedFn := fun es => (mkStateFromImportedEntries SpecState.addEntry {} es).switch
}
@[export lean_add_specialization_info]
def addSpecializationInfo (env : Environment) (fn : Name) (info : SpecInfo) : Environment :=
specExtension.addEntry env (SpecEntry.info fn info)
@[export lean_get_specialization_info]
def getSpecializationInfo (env : Environment) (fn : Name) : Option SpecInfo :=
(specExtension.getState env).specInfo.find? fn
@[export lean_cache_specialization]
def cacheSpecialization (env : Environment) (e : Expr) (fn : Name) : Environment :=
specExtension.addEntry env (SpecEntry.cache e fn)
@[export lean_get_cached_specialization]
def getCachedSpecialization (env : Environment) (e : Expr) : Option Name :=
(specExtension.getState env).cache.find? e
end Lean.Compiler
|
feea64294010488761cc2ad95cd9ce9097103f8c | 491068d2ad28831e7dade8d6dff871c3e49d9431 | /library/theories/group_theory/pgroup.lean | 0c349b35fee3d571b2bbe097325544f2bf2987d5 | [
"Apache-2.0"
] | permissive | davidmueller13/lean | 65a3ed141b4088cd0a268e4de80eb6778b21a0e9 | c626e2e3c6f3771e07c32e82ee5b9e030de5b050 | refs/heads/master | 1,611,278,313,401 | 1,444,021,177,000 | 1,444,021,177,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 15,389 | lean | /-
Copyright (c) 2015 Haitao Zhang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author : Haitao Zhang
-/
import theories.number_theory.primes data algebra.group algebra.group_power algebra.group_bigops .cyclic .finsubg .hom .perm .action
open nat fin list algebra function subtype
namespace group
section pgroup
open finset fintype
variables {G S : Type} [ambientG : group G] [deceqG : decidable_eq G] [finS : fintype S] [deceqS : decidable_eq S]
include ambientG
definition psubg (H : finset G) (p m : nat) : Prop := prime p ∧ card H = p^m
include deceqG finS deceqS
variables {H : finset G} [subgH : is_finsubg H]
include subgH
variables {hom : G → perm S} [Hom : is_hom_class hom]
include Hom
open finset.partition
lemma card_mod_eq_of_action_by_psubg {p : nat} :
∀ {m : nat}, psubg H p m → (card S) mod p = (card (fixed_points hom H)) mod p
| 0 := by rewrite [↑psubg, pow_zero]; intro Psubg;
rewrite [finsubg_eq_singleton_one_of_card_one (and.right Psubg), fixed_points_of_one]
| (succ m) := take Ppsubg, begin
rewrite [@orbit_class_equation' G S ambientG finS deceqS hom Hom H subgH],
apply add_mod_eq_of_dvd, apply dvd_Sum_of_dvd,
intro s Psin,
rewrite mem_sep_iff at Psin,
cases Psin with Psinorbs Pcardne,
esimp [orbits, equiv_classes, orbit_partition] at Psinorbs,
rewrite mem_image_iff at Psinorbs,
cases Psinorbs with a Pa,
cases Pa with Pain Porb,
substvars,
cases Ppsubg with Pprime PcardH,
assert Pdvd : card (orbit hom H a) ∣ p ^ (succ m),
rewrite -PcardH,
apply dvd_of_eq_mul (finset.card (stab hom H a)),
apply orbit_stabilizer_theorem,
apply or.elim (eq_one_or_dvd_of_dvd_prime_pow Pprime Pdvd),
intro Pcardeq, contradiction,
intro Ppdvd, exact Ppdvd
end
end pgroup
section psubg_cosets
open finset fintype
variables {G : Type} [ambientG : group G] [finG : fintype G] [deceqG : decidable_eq G]
include ambientG deceqG finG
variables {H : finset G} [finsubgH : is_finsubg H]
include finsubgH
lemma card_psubg_cosets_mod_eq {p : nat} {m : nat} :
psubg H p m → (card (lcoset_type univ H)) mod p = card (lcoset_type (normalizer H) H) mod p :=
assume Psubg, by rewrite [-card_aol_fixed_points_eq_card_cosets]; exact card_mod_eq_of_action_by_psubg Psubg
end psubg_cosets
section cauchy
lemma prodl_rotl_eq_one_of_prodl_eq_one {A B : Type} [gB : group B] {f : A → B} :
∀ {l : list A}, Prodl l f = 1 → Prodl (list.rotl l) f = 1
| nil := assume Peq, rfl
| (a::l) := begin
rewrite [rotl_cons, Prodl_cons f, Prodl_append _ _ f, Prodl_singleton],
exact mul_eq_one_of_mul_eq_one
end
section rotl_peo
variables {A : Type} [ambA : group A]
include ambA
variable [finA : fintype A]
include finA
variable (A)
definition all_prodl_eq_one (n : nat) : list (list A) :=
map (λ l, cons (Prodl l id)⁻¹ l) (all_lists_of_len n)
variable {A}
lemma prodl_eq_one_of_mem_all_prodl_eq_one {n : nat} {l : list A} : l ∈ all_prodl_eq_one A n → Prodl l id = 1 :=
assume Plin, obtain l' Pl' Pl, from exists_of_mem_map Plin,
by substvars; rewrite [Prodl_cons id _ l', mul.left_inv]
lemma length_of_mem_all_prodl_eq_one {n : nat} {l : list A} : l ∈ all_prodl_eq_one A n → length l = succ n :=
assume Plin, obtain l' Pl' Pl, from exists_of_mem_map Plin,
begin substvars, rewrite [length_cons, length_mem_all_lists Pl'] end
lemma nodup_all_prodl_eq_one {n : nat} : nodup (all_prodl_eq_one A n) :=
nodup_map (take l₁ l₂ Peq, tail_eq_of_cons_eq Peq) nodup_all_lists
lemma all_prodl_eq_one_complete {n : nat} : ∀ {l : list A}, length l = succ n → Prodl l id = 1 → l ∈ all_prodl_eq_one A n
| nil := assume Pleq, by contradiction
| (a::l) := assume Pleq Pprod,
begin
rewrite length_cons at Pleq,
rewrite (Prodl_cons id a l) at Pprod,
rewrite [eq_inv_of_mul_eq_one Pprod],
apply mem_map, apply mem_all_lists, apply succ.inj Pleq
end
open fintype
lemma length_all_prodl_eq_one {n : nat} : length (@all_prodl_eq_one A _ _ n) = (card A)^n :=
eq.trans !length_map length_all_lists
open fin
definition prodseq {n : nat} (s : seq A n) : A := Prodl (upto n) s
definition peo [reducible] {n : nat} (s : seq A n) := prodseq s = 1
definition constseq {n : nat} (s : seq A (succ n)) := ∀ i, s i = s !zero
lemma prodseq_eq {n :nat} {s : seq A n} : prodseq s = Prodl (fun_to_list s) id :=
Prodl_map
lemma prodseq_eq_pow_of_constseq {n : nat} (s : seq A (succ n)) :
constseq s → prodseq s = (s !zero) ^ succ n :=
assume Pc, assert Pcl : ∀ i, i ∈ upto (succ n) → s i = s !zero,
from take i, assume Pin, Pc i,
by rewrite [↑prodseq, Prodl_eq_pow_of_const _ Pcl, fin.length_upto]
lemma seq_eq_of_constseq_of_eq {n : nat} {s₁ s₂ : seq A (succ n)} :
constseq s₁ → constseq s₂ → s₁ !zero = s₂ !zero → s₁ = s₂ :=
assume Pc₁ Pc₂ Peq, funext take i, by rewrite [Pc₁ i, Pc₂ i, Peq]
lemma peo_const_one : ∀ {n : nat}, peo (λ i : fin n, (1 : A))
| 0 := rfl
| (succ n) := let s := λ i : fin (succ n), (1 : A) in
assert Pconst : constseq s, from take i, rfl,
calc prodseq s = (s !zero) ^ succ n : prodseq_eq_pow_of_constseq s Pconst
... = (1 : A) ^ succ n : rfl
... = 1 : algebra.one_pow
variable [deceqA : decidable_eq A]
include deceqA
variable (A)
definition peo_seq [reducible] (n : nat) := {s : seq A (succ n) | peo s}
definition peo_seq_one (n : nat) : peo_seq A n :=
tag (λ i : fin (succ n), (1 : A)) peo_const_one
definition all_prodseq_eq_one (n : nat) : list (seq A (succ n)) :=
dmap (λ l, length l = card (fin (succ n))) list_to_fun (all_prodl_eq_one A n)
definition all_peo_seqs (n : nat) : list (peo_seq A n) :=
dmap peo tag (all_prodseq_eq_one A n)
variable {A}
lemma prodseq_eq_one_of_mem_all_prodseq_eq_one {n : nat} {s : seq A (succ n)} :
s ∈ all_prodseq_eq_one A n → prodseq s = 1 :=
assume Psin, obtain l Pex, from exists_of_mem_dmap Psin,
obtain leq Pin Peq, from Pex,
by rewrite [prodseq_eq, Peq, list_to_fun_to_list, prodl_eq_one_of_mem_all_prodl_eq_one Pin]
lemma all_prodseq_eq_one_complete {n : nat} {s : seq A (succ n)} :
prodseq s = 1 → s ∈ all_prodseq_eq_one A n :=
assume Peq,
assert Plin : map s (elems (fin (succ n))) ∈ all_prodl_eq_one A n,
from begin
apply all_prodl_eq_one_complete,
rewrite [length_map], exact length_upto (succ n),
rewrite prodseq_eq at Peq, exact Peq
end,
assert Psin : list_to_fun (map s (elems (fin (succ n)))) (length_map_of_fintype s) ∈ all_prodseq_eq_one A n,
from mem_dmap _ Plin,
by rewrite [fun_eq_list_to_fun_map s (length_map_of_fintype s)]; apply Psin
lemma nodup_all_prodseq_eq_one {n : nat} : nodup (all_prodseq_eq_one A n) :=
dmap_nodup_of_dinj dinj_list_to_fun nodup_all_prodl_eq_one
lemma rotl1_peo_of_peo {n : nat} {s : seq A n} : peo s → peo (rotl_fun 1 s) :=
begin rewrite [↑peo, *prodseq_eq, seq_rotl_eq_list_rotl], apply prodl_rotl_eq_one_of_prodl_eq_one end
section
local attribute perm.f [coercion]
lemma rotl_perm_peo_of_peo {n : nat} : ∀ {m} {s : seq A n}, peo s → peo (rotl_perm A n m s)
| 0 := begin rewrite [↑rotl_perm, rotl_seq_zero], intros, assumption end
| (succ m) := take s,
assert Pmul : rotl_perm A n (m + 1) s = rotl_fun 1 (rotl_perm A n m s), from
calc s ∘ (rotl (m + 1)) = s ∘ ((rotl m) ∘ (rotl 1)) : rotl_compose
... = s ∘ (rotl m) ∘ (rotl 1) : compose.assoc,
begin
rewrite [-add_one, Pmul], intro P,
exact rotl1_peo_of_peo (rotl_perm_peo_of_peo P)
end
end
lemma nodup_all_peo_seqs {n : nat} : nodup (all_peo_seqs A n) :=
dmap_nodup_of_dinj (dinj_tag peo) nodup_all_prodseq_eq_one
lemma all_peo_seqs_complete {n : nat} : ∀ s : peo_seq A n, s ∈ all_peo_seqs A n :=
take ps, subtype.destruct ps (take s, assume Ps,
assert Pin : s ∈ all_prodseq_eq_one A n, from all_prodseq_eq_one_complete Ps,
mem_dmap Ps Pin)
lemma length_all_peo_seqs {n : nat} : length (all_peo_seqs A n) = (card A)^n :=
eq.trans (eq.trans
(show length (all_peo_seqs A n) = length (all_prodseq_eq_one A n), from
assert Pmap : map elt_of (all_peo_seqs A n) = all_prodseq_eq_one A n,
from map_dmap_of_inv_of_pos (λ s P, rfl)
(λ s, prodseq_eq_one_of_mem_all_prodseq_eq_one),
by rewrite [-Pmap, length_map])
(show length (all_prodseq_eq_one A n) = length (all_prodl_eq_one A n), from
assert Pmap : map fun_to_list (all_prodseq_eq_one A n) = all_prodl_eq_one A n,
from map_dmap_of_inv_of_pos list_to_fun_to_list
(λ l Pin, by rewrite [length_of_mem_all_prodl_eq_one Pin, card_fin]),
by rewrite [-Pmap, length_map]))
length_all_prodl_eq_one
definition peo_seq_is_fintype [instance] {n : nat} : fintype (peo_seq A n) :=
fintype.mk (all_peo_seqs A n) nodup_all_peo_seqs all_peo_seqs_complete
lemma card_peo_seq {n : nat} : card (peo_seq A n) = (card A)^n :=
length_all_peo_seqs
section
variable (A)
local attribute perm.f [coercion]
definition rotl_peo_seq (n : nat) (m : nat) (s : peo_seq A n) : peo_seq A n :=
tag (rotl_perm A (succ n) m (elt_of s)) (rotl_perm_peo_of_peo (has_property s))
variable {A}
end
lemma rotl_peo_seq_zero {n : nat} : rotl_peo_seq A n 0 = id :=
funext take s, subtype.eq begin rewrite [↑rotl_peo_seq, ↑rotl_perm, rotl_seq_zero] end
lemma rotl_peo_seq_id {n : nat} : rotl_peo_seq A n (succ n) = id :=
funext take s, subtype.eq begin rewrite [↑rotl_peo_seq, -rotl_perm_pow_eq, rotl_perm_pow_eq_one] end
lemma rotl_peo_seq_compose {n i j : nat} :
(rotl_peo_seq A n i) ∘ (rotl_peo_seq A n j) = rotl_peo_seq A n (j + i) :=
funext take s, subtype.eq begin rewrite [↑rotl_peo_seq, ↑rotl_perm, ↑rotl_fun, compose.assoc, rotl_compose] end
lemma rotl_peo_seq_mod {n i : nat} : rotl_peo_seq A n i = rotl_peo_seq A n (i mod succ n) :=
funext take s, subtype.eq begin rewrite [↑rotl_peo_seq, rotl_perm_mod] end
lemma rotl_peo_seq_inj {n m : nat} : injective (rotl_peo_seq A n m) :=
take ps₁ ps₂, subtype.destruct ps₁ (λ s₁ P₁, subtype.destruct ps₂ (λ s₂ P₂,
assume Peq, tag_eq (rotl_fun_inj (dinj_tag peo _ _ Peq))))
variable (A)
definition rotl_perm_ps [reducible] (n : nat) (m : fin (succ n)) : perm (peo_seq A n) :=
perm.mk (rotl_peo_seq A n m) rotl_peo_seq_inj
variable {A}
variable {n : nat}
lemma rotl_perm_ps_eq {m : fin (succ n)} {s : peo_seq A n} : elt_of (perm.f (rotl_perm_ps A n m) s) = perm.f (rotl_perm A (succ n) m) (elt_of s) := rfl
lemma rotl_perm_ps_eq_of_rotl_perm_eq {i j : fin (succ n)} :
(rotl_perm A (succ n) i) = (rotl_perm A (succ n) j) → (rotl_perm_ps A n i) = (rotl_perm_ps A n j) :=
assume Peq, eq_of_feq (funext take s, subtype.eq (by rewrite [*rotl_perm_ps_eq, Peq]))
lemma rotl_perm_ps_hom (i j : fin (succ n)) :
rotl_perm_ps A n (i+j) = (rotl_perm_ps A n i) * (rotl_perm_ps A n j) :=
eq_of_feq (begin rewrite [↑rotl_perm_ps, {val (i+j)}val_madd, add.comm, -rotl_peo_seq_mod, -rotl_peo_seq_compose] end)
section
local attribute group_of_add_group [instance]
definition rotl_perm_ps_is_hom [instance] : is_hom_class (rotl_perm_ps A n) :=
is_hom_class.mk rotl_perm_ps_hom
open finset
lemma const_of_is_fixed_point {s : peo_seq A n} :
is_fixed_point (rotl_perm_ps A n) univ s → constseq (elt_of s) :=
assume Pfp, take i, begin
rewrite [-(Pfp i !mem_univ) at {1}, rotl_perm_ps_eq, ↑rotl_perm, ↑rotl_fun, {i}mk_mod_eq at {2}, rotl_to_zero]
end
lemma const_of_rotl_fixed_point {s : peo_seq A n} :
s ∈ fixed_points (rotl_perm_ps A n) univ → constseq (elt_of s) :=
assume Psin, take i, begin
apply const_of_is_fixed_point, exact is_fixed_point_of_mem_fixed_points Psin
end
lemma pow_eq_one_of_mem_fixed_points {s : peo_seq A n} :
s ∈ fixed_points (rotl_perm_ps A n) univ → (elt_of s !zero)^(succ n) = 1 :=
assume Psin, eq.trans
(eq.symm (prodseq_eq_pow_of_constseq (elt_of s) (const_of_rotl_fixed_point Psin)))
(has_property s)
lemma peo_seq_one_is_fixed_point : is_fixed_point (rotl_perm_ps A n) univ (peo_seq_one A n) :=
take h, assume Pin, by esimp [rotl_perm_ps]
lemma peo_seq_one_mem_fixed_points : peo_seq_one A n ∈ fixed_points (rotl_perm_ps A n) univ :=
mem_fixed_points_of_exists_of_is_fixed_point (exists.intro !zero !mem_univ) peo_seq_one_is_fixed_point
lemma generator_of_prime_of_dvd_order {p : nat}
: prime p → p ∣ card A → ∃ g : A, g ≠ 1 ∧ g^p = 1 :=
assume Pprime Pdvd,
let pp := nat.pred p, spp := nat.succ pp in
assert Peq : spp = p, from succ_pred_prime Pprime,
have Ppsubg : psubg (@univ (fin spp) _) spp 1,
from and.intro (eq.symm Peq ▸ Pprime) (by rewrite [Peq, card_fin, pow_one]),
have Pcardmod : (nat.pow (card A) pp) mod p = (card (fixed_points (rotl_perm_ps A pp) univ)) mod p,
from Peq ▸ card_peo_seq ▸ card_mod_eq_of_action_by_psubg Ppsubg,
have Pfpcardmod : (card (fixed_points (rotl_perm_ps A pp) univ)) mod p = 0,
from eq.trans (eq.symm Pcardmod) (mod_eq_zero_of_dvd (dvd_pow_of_dvd_of_pos Pdvd (pred_prime_pos Pprime))),
have Pfpcardpos : card (fixed_points (rotl_perm_ps A pp) univ) > 0,
from card_pos_of_mem peo_seq_one_mem_fixed_points,
have Pfpcardgt1 : card (fixed_points (rotl_perm_ps A pp) univ) > 1,
from gt_one_of_pos_of_prime_dvd Pprime Pfpcardpos Pfpcardmod,
obtain s₁ s₂ Pin₁ Pin₂ Psnes, from exists_two_of_card_gt_one Pfpcardgt1,
decidable.by_cases
(λ Pe₁ : elt_of s₁ !zero = 1,
assert Pne₂ : elt_of s₂ !zero ≠ 1,
from assume Pe₂,
absurd
(subtype.eq (seq_eq_of_constseq_of_eq
(const_of_rotl_fixed_point Pin₁)
(const_of_rotl_fixed_point Pin₂)
(eq.trans Pe₁ (eq.symm Pe₂))))
Psnes,
exists.intro (elt_of s₂ !zero)
(and.intro Pne₂ (Peq ▸ pow_eq_one_of_mem_fixed_points Pin₂)))
(λ Pne, exists.intro (elt_of s₁ !zero)
(and.intro Pne (Peq ▸ pow_eq_one_of_mem_fixed_points Pin₁)))
end
theorem cauchy_theorem {p : nat} : prime p → p ∣ card A → ∃ g : A, order g = p :=
assume Pprime Pdvd,
obtain g Pne Pgpow, from generator_of_prime_of_dvd_order Pprime Pdvd,
assert Porder : order g ∣ p, from order_dvd_of_pow_eq_one Pgpow,
or.elim (eq_one_or_eq_self_of_prime_of_dvd Pprime Porder)
(λ Pe, absurd (eq_one_of_order_eq_one Pe) Pne)
(λ Porderp, exists.intro g Porderp)
end rotl_peo
end cauchy
section sylow
open finset fintype
variables {G : Type} [ambientG : group G] [finG : fintype G] [deceqG : decidable_eq G]
include ambientG deceqG finG
theorem first_sylow_theorem {p : nat} (Pp : prime p) :
∀ n, p^n ∣ card G → ∃ (H : finset G) (finsubgH : is_finsubg H), card H = p^n
| 0 := assume Pdvd, exists.intro (singleton 1)
(exists.intro one_is_finsubg
(by rewrite [card_singleton, pow_zero]))
| (succ n) := assume Pdvd,
obtain H PfinsubgH PcardH, from first_sylow_theorem n (pow_dvd_of_pow_succ_dvd Pdvd),
assert Ppsubg : psubg H p n, from and.intro Pp PcardH,
assert Ppowsucc : p^(succ n) ∣ (card (lcoset_type univ H) * p^n),
by rewrite [-PcardH, -(lagrange_theorem' !subset_univ)]; exact Pdvd,
assert Ppdvd : p ∣ card (lcoset_type (normalizer H) H), from
dvd_of_mod_eq_zero
(by rewrite [-(card_psubg_cosets_mod_eq Ppsubg), -dvd_iff_mod_eq_zero];
exact dvd_of_pow_succ_dvd_mul_pow (pos_of_prime Pp) Ppowsucc),
obtain J PJ, from cauchy_theorem Pp Ppdvd,
exists.intro (fin_coset_Union (cyc J))
(exists.intro _
(by rewrite [pow_succ, -PcardH, -PJ]; apply card_Union_lcosets))
end sylow
end group
|
56361ad0bd4fe2af1d53d230803f8ff7b242601d | a0e23cfdd129a671bf3154ee1a8a3a72bf4c7940 | /stage0/src/Init/Data/Fin/Basic.lean | 84ef5c1163539beb2b290bdd56ae7e25250958fe | [
"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 | 2,991 | lean | /-
Copyright (c) 2016 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Leonardo de Moura
-/
prelude
import Init.Data.Nat.Div
import Init.Data.Nat.Bitwise
import Init.Coe
open Nat
namespace Fin
instance coeToNat {n} : Coe (Fin n) Nat :=
⟨fun v => v.val⟩
def elim0.{u} {α : Sort u} : Fin 0 → α
| ⟨_, h⟩ => absurd h (notLtZero _)
variable {n : Nat}
protected def ofNat {n : Nat} (a : Nat) : Fin (succ n) :=
⟨a % succ n, Nat.mod_lt _ (Nat.zeroLtSucc _)⟩
protected def ofNat' {n : Nat} (a : Nat) (h : n > 0) : Fin n :=
⟨a % n, Nat.mod_lt _ h⟩
private theorem mlt {b : Nat} : {a : Nat} → a < n → b % n < n
| 0, h => Nat.mod_lt _ h
| a+1, h =>
have : n > 0 := Nat.ltTrans (Nat.zeroLtSucc _) h;
Nat.mod_lt _ this
protected def add : Fin n → Fin n → Fin n
| ⟨a, h⟩, ⟨b, _⟩ => ⟨(a + b) % n, mlt h⟩
protected def mul : Fin n → Fin n → Fin n
| ⟨a, h⟩, ⟨b, _⟩ => ⟨(a * b) % n, mlt h⟩
protected def sub : Fin n → Fin n → Fin n
| ⟨a, h⟩, ⟨b, _⟩ => ⟨(a + (n - b)) % n, mlt h⟩
/-
Remark: mod/div/modn/land/lor can be defined without using (% n), but
we are trying to minimize the number of Nat theorems
needed to boostrap Lean.
-/
protected def mod : Fin n → Fin n → Fin n
| ⟨a, h⟩, ⟨b, _⟩ => ⟨(a % b) % n, mlt h⟩
protected def div : Fin n → Fin n → Fin n
| ⟨a, h⟩, ⟨b, _⟩ => ⟨(a / b) % n, mlt h⟩
protected def modn : Fin n → Nat → Fin n
| ⟨a, h⟩, m => ⟨(a % m) % n, mlt h⟩
def land : Fin n → Fin n → Fin n
| ⟨a, h⟩, ⟨b, _⟩ => ⟨(Nat.land a b) % n, mlt h⟩
def lor : Fin n → Fin n → Fin n
| ⟨a, h⟩, ⟨b, _⟩ => ⟨(Nat.lor a b) % n, mlt h⟩
def xor : Fin n → Fin n → Fin n
| ⟨a, h⟩, ⟨b, _⟩ => ⟨(Nat.xor a b) % n, mlt h⟩
def shiftLeft : Fin n → Fin n → Fin n
| ⟨a, h⟩, ⟨b, _⟩ => ⟨(a <<< b) % n, mlt h⟩
def shiftRight : Fin n → Fin n → Fin n
| ⟨a, h⟩, ⟨b, _⟩ => ⟨(a >>> b) % n, mlt h⟩
instance : Add (Fin n) where
add := Fin.add
instance : Sub (Fin n) where
sub := Fin.sub
instance : Mul (Fin n) where
mul := Fin.mul
instance : Mod (Fin n) where
mod := Fin.mod
instance : Div (Fin n) where
div := Fin.div
instance : AndOp (Fin n) where
and := Fin.land
instance : OrOp (Fin n) where
or := Fin.lor
instance : Xor (Fin n) where
xor := Fin.xor
instance : ShiftLeft (Fin n) where
shiftLeft := Fin.shiftLeft
instance : ShiftRight (Fin n) where
shiftRight := Fin.shiftRight
instance : HMod (Fin n) Nat (Fin n) where
hMod := Fin.modn
instance : OfNat (Fin (no_index (n+1))) i where
ofNat := Fin.ofNat i
theorem vneOfNe {i j : Fin n} (h : i ≠ j) : val i ≠ val j :=
fun h' => absurd (eqOfVeq h') h
theorem modn_lt : ∀ {m : Nat} (i : Fin n), m > 0 → (i % m).val < m
| m, ⟨a, h⟩, hp => Nat.ltOfLeOfLt (mod_le _ _) (mod_lt _ hp)
end Fin
open Fin
|
1aacbac83b1dfbfd157cf117af25a7893df0545b | 957a80ea22c5abb4f4670b250d55534d9db99108 | /tests/lean/run/match_convoy3.lean | 067eb8c032d9cd68024077fd83e507ae60ebcb27 | [
"Apache-2.0"
] | permissive | GaloisInc/lean | aa1e64d604051e602fcf4610061314b9a37ab8cd | f1ec117a24459b59c6ff9e56a1d09d9e9e60a6c0 | refs/heads/master | 1,592,202,909,807 | 1,504,624,387,000 | 1,504,624,387,000 | 75,319,626 | 2 | 1 | Apache-2.0 | 1,539,290,164,000 | 1,480,616,104,000 | C++ | UTF-8 | Lean | false | false | 1,570 | lean | constant bag_setoid : ∀ A, setoid (list A)
attribute [instance] bag_setoid
noncomputable definition bag (A : Type) : Type :=
quotient (bag_setoid A)
constant subcount : ∀ {A}, list A → list A → bool
constant list.count : ∀ {A}, A → list A → nat
constant all_of_subcount_eq_tt : ∀ {A} {l₁ l₂ : list A}, subcount l₁ l₂ = tt → ∀ a, list.count a l₁ ≤ list.count a l₂
constant ex_of_subcount_eq_ff : ∀ {A} {l₁ l₂ : list A}, subcount l₁ l₂ = ff → ∃ a, ¬ list.count a l₁ ≤ list.count a l₂
noncomputable definition count {A} (a : A) (b : bag A) : nat :=
quotient.lift_on b (λ l, list.count a l)
(λ l₁ l₂ h, sorry)
noncomputable definition subbag {A} (b₁ b₂ : bag A) := ∀ a, count a b₁ ≤ count a b₂
infix ⊆ := subbag
attribute [instance]
noncomputable definition decidable_subbag {A} (b₁ b₂ : bag A) : decidable (b₁ ⊆ b₂) :=
quotient.rec_on_subsingleton₂ b₁ b₂ (λ l₁ l₂,
match subcount l₁ l₂, rfl : ∀ (b : _), subcount l₁ l₂ = b → _ with
| tt, H := is_true (all_of_subcount_eq_tt H)
| ff, H := is_false (λ h, exists.elim (ex_of_subcount_eq_ff H) (λ w hw, hw (h w)))
end)
noncomputable definition decidable_subbag2 {A} (b₁ b₂ : bag A) : decidable (b₁ ⊆ b₂) :=
quotient.rec_on_subsingleton₂ b₁ b₂ (λ l₁ l₂,
match subcount l₁ l₂, rfl : ∀ (b : _), subcount l₁ l₂ = b → _ with
| tt, H := is_true (all_of_subcount_eq_tt H)
| ff, H := is_false (λ h, exists.elim (ex_of_subcount_eq_ff H) (λ w hw, absurd (h w) hw))
end)
|
143a207d5fd1ee449317131c8716c775a0d8ba81 | 57aec6ee746bc7e3a3dd5e767e53bd95beb82f6d | /src/Lean/Parser/Term.lean | 9cc5e166e0f0d84974838da3dc96780d20cd882a | [
"Apache-2.0"
] | permissive | collares/lean4 | 861a9269c4592bce49b71059e232ff0bfe4594cc | 52a4f535d853a2c7c7eea5fee8a4fa04c682c1ee | refs/heads/master | 1,691,419,031,324 | 1,618,678,138,000 | 1,618,678,138,000 | 358,989,750 | 0 | 0 | Apache-2.0 | 1,618,696,333,000 | 1,618,696,333,000 | null | UTF-8 | Lean | false | false | 17,269 | 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.Attr
import Lean.Parser.Level
namespace Lean
namespace Parser
namespace Command
def commentBody : Parser :=
{ fn := rawFn (fun c s => finishCommentBlock s.pos 1 c s) (trailingWs := true) }
@[combinatorParenthesizer Lean.Parser.Command.commentBody] def commentBody.parenthesizer := PrettyPrinter.Parenthesizer.visitToken
@[combinatorFormatter Lean.Parser.Command.commentBody] def commentBody.formatter := PrettyPrinter.Formatter.visitAtom Name.anonymous
def docComment := leading_parser ppDedent $ "/--" >> commentBody >> ppLine
end Command
builtin_initialize
registerBuiltinParserAttribute `builtinTacticParser `tactic LeadingIdentBehavior.both
registerBuiltinDynamicParserAttribute `tacticParser `tactic
@[inline] def tacticParser (rbp : Nat := 0) : Parser :=
categoryParser `tactic rbp
namespace Tactic
def tacticSeq1Indented : Parser :=
leading_parser many1Indent (group (ppLine >> tacticParser >> optional ";"))
def tacticSeqBracketed : Parser :=
leading_parser "{" >> many (group (ppLine >> tacticParser >> optional ";")) >> ppDedent (ppLine >> "}")
def tacticSeq :=
nodeWithAntiquot "tacticSeq" `Lean.Parser.Tactic.tacticSeq (tacticSeqBracketed <|> tacticSeq1Indented)
/- Raw sequence for quotation and grouping -/
def seq1 :=
node `Lean.Parser.Tactic.seq1 $ sepBy1 tacticParser ";\n" (allowTrailingSep := true)
end Tactic
def darrow : Parser := " => "
namespace Term
/- Built-in parsers -/
@[builtinTermParser] def byTactic := leading_parser:leadPrec "by " >> Tactic.tacticSeq
def optSemicolon (p : Parser) : Parser := ppDedent $ optional ";" >> ppLine >> p
-- `checkPrec` necessary for the pretty printer
@[builtinTermParser] def ident := checkPrec maxPrec >> Parser.ident
@[builtinTermParser] def num : Parser := checkPrec maxPrec >> numLit
@[builtinTermParser] def scientific : Parser := checkPrec maxPrec >> scientificLit
@[builtinTermParser] def str : Parser := checkPrec maxPrec >> strLit
@[builtinTermParser] def char : Parser := checkPrec maxPrec >> charLit
@[builtinTermParser] def type := leading_parser "Type" >> optional (checkWsBefore "" >> checkPrec leadPrec >> checkColGt >> levelParser maxPrec)
@[builtinTermParser] def sort := leading_parser "Sort" >> optional (checkWsBefore "" >> checkPrec leadPrec >> checkColGt >> levelParser maxPrec)
@[builtinTermParser] def prop := leading_parser "Prop"
@[builtinTermParser] def hole := leading_parser "_"
@[builtinTermParser] def syntheticHole := leading_parser "?" >> (ident <|> hole)
@[builtinTermParser] def «sorry» := leading_parser "sorry"
@[builtinTermParser] def cdot := leading_parser symbol "·" <|> "."
@[builtinTermParser] def emptyC := leading_parser "∅" <|> (symbol "{" >> "}")
def typeAscription := leading_parser " : " >> termParser
def tupleTail := leading_parser ", " >> sepBy1 termParser ", "
def parenSpecial : Parser := optional (tupleTail <|> typeAscription)
@[builtinTermParser] def paren := leading_parser "(" >> ppDedent (withoutPosition (withoutForbidden (optional (termParser >> parenSpecial)))) >> ")"
@[builtinTermParser] def anonymousCtor := leading_parser "⟨" >> sepBy termParser ", " >> "⟩"
def optIdent : Parser := optional (atomic (ident >> " : "))
def fromTerm := leading_parser " from " >> termParser
def haveAssign := leading_parser " := " >> termParser
def haveDecl := leading_parser optIdent >> termParser >> (haveAssign <|> fromTerm <|> byTactic)
@[builtinTermParser] def «have» := leading_parser:leadPrec withPosition ("have " >> haveDecl) >> optSemicolon termParser
def sufficesDecl := leading_parser optIdent >> termParser >> (fromTerm <|> byTactic)
@[builtinTermParser] def «suffices» := leading_parser:leadPrec withPosition ("suffices " >> sufficesDecl) >> optSemicolon termParser
@[builtinTermParser] def «show» := leading_parser:leadPrec "show " >> termParser >> (fromTerm <|> byTactic)
def structInstArrayRef := leading_parser "[" >> termParser >>"]"
def structInstLVal := leading_parser (ident <|> fieldIdx <|> structInstArrayRef) >> many (group ("." >> (ident <|> fieldIdx)) <|> structInstArrayRef)
def structInstField := ppGroup $ leading_parser structInstLVal >> " := " >> termParser
def optEllipsis := leading_parser optional ".."
@[builtinTermParser] def structInst := leading_parser "{" >> ppHardSpace >> optional (atomic (termParser >> " with "))
>> manyIndent (group (structInstField >> optional ", "))
>> optEllipsis
>> optional (" : " >> termParser) >> " }"
def typeSpec := leading_parser " : " >> termParser
def optType : Parser := optional typeSpec
@[builtinTermParser] def explicit := leading_parser "@" >> termParser maxPrec
@[builtinTermParser] def inaccessible := leading_parser ".(" >> termParser >> ")"
def binderIdent : Parser := ident <|> hole
def binderType (requireType := false) : Parser := if requireType then node nullKind (" : " >> termParser) else optional (" : " >> termParser)
def binderTactic := leading_parser atomic (symbol " := " >> " by ") >> Tactic.tacticSeq
def binderDefault := leading_parser " := " >> termParser
def explicitBinder (requireType := false) := ppGroup $ leading_parser "(" >> many1 binderIdent >> binderType requireType >> optional (binderTactic <|> binderDefault) >> ")"
def implicitBinder (requireType := false) := ppGroup $ leading_parser "{" >> many1 binderIdent >> binderType requireType >> "}"
def instBinder := ppGroup $ leading_parser "[" >> optIdent >> termParser >> "]"
def bracketedBinder (requireType := false) := withAntiquot (mkAntiquot "bracketedBinder" none (anonymous := false)) <|
explicitBinder requireType <|> implicitBinder requireType <|> instBinder
/-
It is feasible to support dependent arrows such as `{α} → α → α` without sacrificing the quality of the error messages for the longer case.
`{α} → α → α` would be short for `{α : Type} → α → α`
Here is the encoding:
```
def implicitShortBinder := node `Lean.Parser.Term.implicitBinder $ "{" >> many1 binderIdent >> pushNone >> "}"
def depArrowShortPrefix := try (implicitShortBinder >> unicodeSymbol " → " " -> ")
def depArrowLongPrefix := bracketedBinder true >> unicodeSymbol " → " " -> "
def depArrowPrefix := depArrowShortPrefix <|> depArrowLongPrefix
@[builtinTermParser] def depArrow := leading_parser depArrowPrefix >> termParser
```
Note that no changes in the elaborator are needed.
We decided to not use it because terms such as `{α} → α → α` may look too cryptic.
Note that we did not add a `explicitShortBinder` parser since `(α) → α → α` is really cryptic as a short for `(α : Type) → α → α`.
-/
@[builtinTermParser] def depArrow := leading_parser:25 bracketedBinder true >> unicodeSymbol " → " " -> " >> termParser
def simpleBinder := leading_parser many1 binderIdent >> optType
@[builtinTermParser]
def «forall» := leading_parser:leadPrec unicodeSymbol "∀" "forall" >> many1 (ppSpace >> (simpleBinder <|> bracketedBinder)) >> ", " >> termParser
def matchAlt (rhsParser : Parser := termParser) : Parser :=
nodeWithAntiquot "matchAlt" `Lean.Parser.Term.matchAlt $
"| " >> ppIndent (sepBy1 termParser ", " >> darrow >> checkColGe "alternative right-hand-side to start in a column greater than or equal to the corresponding '|'" >> rhsParser)
/--
Useful for syntax quotations. Note that generic patterns such as `` `(matchAltExpr| | ... => $rhs) `` should also
work with other `rhsParser`s (of arity 1). -/
def matchAltExpr := matchAlt
def matchAlts (rhsParser : Parser := termParser) : Parser :=
leading_parser ppDedent $ withPosition $ many1Indent (ppLine >> matchAlt rhsParser)
def matchDiscr := leading_parser optional (atomic (ident >> checkNoWsBefore "no space before ':'" >> ":")) >> termParser
def trueVal := leading_parser nonReservedSymbol "true"
def falseVal := leading_parser nonReservedSymbol "false"
def generalizingParam := leading_parser atomic ("(" >> nonReservedSymbol "generalizing") >> " := " >> (trueVal <|> falseVal) >> ")"
@[builtinTermParser] def «match» := leading_parser:leadPrec "match " >> optional generalizingParam >> sepBy1 matchDiscr ", " >> optType >> " with " >> matchAlts
@[builtinTermParser] def «nomatch» := leading_parser:leadPrec "nomatch " >> termParser
def funImplicitBinder := atomic (lookahead ("{" >> many1 binderIdent >> (symbol " : " <|> "}"))) >> implicitBinder
def funSimpleBinder := atomic (lookahead (many1 binderIdent >> " : ")) >> simpleBinder
def funBinder : Parser := funImplicitBinder <|> instBinder <|> funSimpleBinder <|> termParser maxPrec
-- NOTE: we use `nodeWithAntiquot` to ensure that `fun $b => ...` remains a `term` antiquotation
def basicFun : Parser := nodeWithAntiquot "basicFun" `Lean.Parser.Term.basicFun (many1 (ppSpace >> funBinder) >> darrow >> termParser)
@[builtinTermParser] def «fun» := leading_parser:maxPrec unicodeSymbol "λ" "fun" >> (basicFun <|> matchAlts)
def optExprPrecedence := optional (atomic ":" >> termParser maxPrec)
@[builtinTermParser] def «leading_parser» := leading_parser:leadPrec "leading_parser " >> optExprPrecedence >> termParser
@[builtinTermParser] def «trailing_parser» := leading_parser:leadPrec "trailing_parser " >> optExprPrecedence >> optExprPrecedence >> termParser
@[builtinTermParser] def borrowed := leading_parser "@&" >> termParser leadPrec
@[builtinTermParser] def quotedName := leading_parser nameLit
@[builtinTermParser] def doubleQuotedName := leading_parser "`" >> checkNoWsBefore >> nameLit
def simpleBinderWithoutType := nodeWithAntiquot "simpleBinder" `Lean.Parser.Term.simpleBinder (anonymous := true)
(many1 binderIdent >> pushNone)
/- Remark: we use `checkWsBefore` to ensure `let x[i] := e; b` is not parsed as `let x [i] := e; b` where `[i]` is an `instBinder`. -/
def letIdLhs : Parser := ident >> checkWsBefore "expected space before binders" >> many (ppSpace >> (simpleBinderWithoutType <|> bracketedBinder)) >> optType
def letIdDecl := nodeWithAntiquot "letIdDecl" `Lean.Parser.Term.letIdDecl $ atomic (letIdLhs >> " := ") >> termParser
def letPatDecl := nodeWithAntiquot "letPatDecl" `Lean.Parser.Term.letPatDecl $ atomic (termParser >> pushNone >> optType >> " := ") >> termParser
def letEqnsDecl := nodeWithAntiquot "letEqnsDecl" `Lean.Parser.Term.letEqnsDecl $ letIdLhs >> matchAlts
-- Remark: we use `nodeWithAntiquot` here to make sure anonymous antiquotations (e.g., `$x`) are not `letDecl`
def letDecl := nodeWithAntiquot "letDecl" `Lean.Parser.Term.letDecl (notFollowedBy (nonReservedSymbol "rec") "rec" >> (letIdDecl <|> letPatDecl <|> letEqnsDecl))
@[builtinTermParser] def «let» := leading_parser:leadPrec withPosition ("let " >> letDecl) >> optSemicolon termParser
@[builtinTermParser] def «let_fun» := leading_parser:leadPrec withPosition ((symbol "let_fun " <|> "let_λ") >> letDecl) >> optSemicolon termParser
@[builtinTermParser] def «let_delayed» := leading_parser:leadPrec withPosition ("let_delayed " >> letDecl) >> optSemicolon termParser
def «scoped» := leading_parser "scoped "
def «local» := leading_parser "local "
def attrKind := leading_parser optional («scoped» <|> «local»)
def attrInstance := ppGroup $ leading_parser attrKind >> attrParser
def attributes := leading_parser "@[" >> sepBy1 attrInstance ", " >> "]"
def letRecDecl := leading_parser optional Command.docComment >> optional «attributes» >> letDecl
def letRecDecls := leading_parser sepBy1 letRecDecl ", "
@[builtinTermParser]
def «letrec» := leading_parser:leadPrec withPosition (group ("let " >> nonReservedSymbol "rec ") >> letRecDecls) >> optSemicolon termParser
@[runBuiltinParserAttributeHooks]
def whereDecls := leading_parser "where " >> many1Indent (group (letRecDecl >> optional ";"))
@[runBuiltinParserAttributeHooks]
def matchAltsWhereDecls := leading_parser matchAlts >> optional whereDecls
@[builtinTermParser] def noindex := leading_parser "no_index " >> termParser maxPrec
@[builtinTermParser] def binrel := leading_parser "binrel% " >> ident >> ppSpace >> termParser maxPrec >> termParser maxPrec
@[builtinTermParser] def forInMacro := leading_parser "forIn% " >> termParser maxPrec >> termParser maxPrec >> termParser maxPrec
@[builtinTermParser] def typeOf := leading_parser "typeOf% " >> termParser maxPrec
@[builtinTermParser] def ensureTypeOf := leading_parser "ensureTypeOf% " >> termParser maxPrec >> strLit >> termParser
@[builtinTermParser] def ensureExpectedType := leading_parser "ensureExpectedType% " >> strLit >> termParser maxPrec
@[builtinTermParser] def noImplicitLambda := leading_parser "noImplicitLambda% " >> termParser maxPrec
def namedArgument := leading_parser atomic ("(" >> ident >> " := ") >> termParser >> ")"
def ellipsis := leading_parser ".."
def argument :=
checkWsBefore "expected space" >>
checkColGt "expected to be indented" >>
(namedArgument <|> ellipsis <|> termParser argPrec)
-- `app` precedence is `lead` (cannot be used as argument)
-- `lhs` precedence is `max` (i.e. does not accept `arg` precedence)
-- argument precedence is `arg` (i.e. does not accept `lead` precedence)
@[builtinTermParser] def app := trailing_parser:leadPrec:maxPrec many1 argument
@[builtinTermParser] def proj := trailing_parser checkNoWsBefore >> "." >> checkNoWsBefore >> (fieldIdx <|> ident)
@[builtinTermParser] def completion := trailing_parser checkNoWsBefore >> "."
@[builtinTermParser] def arrayRef := trailing_parser checkNoWsBefore >> "[" >> termParser >>"]"
@[builtinTermParser] def arrow := trailing_parser checkPrec 25 >> unicodeSymbol " → " " -> " >> termParser 25
def isIdent (stx : Syntax) : Bool :=
-- antiquotations should also be allowed where an identifier is expected
stx.isAntiquot || stx.isIdent
@[builtinTermParser] def explicitUniv : TrailingParser := trailing_parser checkStackTop isIdent "expected preceding identifier" >> checkNoWsBefore "no space before '.{'" >> ".{" >> sepBy1 levelParser ", " >> "}"
@[builtinTermParser] def namedPattern : TrailingParser := trailing_parser checkStackTop isIdent "expected preceding identifier" >> checkNoWsBefore "no space before '@'" >> "@" >> termParser maxPrec
@[builtinTermParser] def pipeProj := trailing_parser:minPrec " |>." >> checkNoWsBefore >> (fieldIdx <|> ident) >> many argument
@[builtinTermParser] def pipeCompletion := trailing_parser:minPrec " |>."
@[builtinTermParser] def subst := trailing_parser:75 " ▸ " >> sepBy1 (termParser 75) " ▸ "
-- NOTE: Doesn't call `categoryParser` directly in contrast to most other "static" quotations, so call `evalInsideQuot` explicitly
@[builtinTermParser] def funBinder.quot : Parser := leading_parser "`(funBinder|" >> toggleInsideQuot (evalInsideQuot ``funBinder funBinder) >> ")"
def bracketedBinderF := bracketedBinder -- no default arg
@[builtinTermParser] def bracketedBinder.quot : Parser := leading_parser "`(bracketedBinder|" >> toggleInsideQuot (evalInsideQuot ``bracketedBinderF bracketedBinder) >> ")"
@[builtinTermParser] def matchDiscr.quot : Parser := leading_parser "`(matchDiscr|" >> toggleInsideQuot (evalInsideQuot ``matchDiscr matchDiscr) >> ")"
@[builtinTermParser] def attr.quot : Parser := leading_parser "`(attr|" >> toggleInsideQuot attrParser >> ")"
@[builtinTermParser] def panic := leading_parser:leadPrec "panic! " >> termParser
@[builtinTermParser] def unreachable := leading_parser:leadPrec "unreachable!"
@[builtinTermParser] def dbgTrace := leading_parser:leadPrec withPosition ("dbg_trace" >> ((interpolatedStr termParser) <|> termParser)) >> optSemicolon termParser
@[builtinTermParser] def assert := leading_parser:leadPrec withPosition ("assert! " >> termParser) >> optSemicolon termParser
def macroArg := termParser maxPrec
def macroDollarArg := leading_parser "$" >> termParser 10
def macroLastArg := macroDollarArg <|> macroArg
-- Macro for avoiding exponentially big terms when using `STWorld`
@[builtinTermParser] def stateRefT := leading_parser "StateRefT" >> macroArg >> macroLastArg
@[builtinTermParser] def dynamicQuot := leading_parser "`(" >> ident >> "|" >> toggleInsideQuot (parserOfStack 1) >> ")"
end Term
@[builtinTermParser default+1] def Tactic.quot : Parser := leading_parser "`(tactic|" >> toggleInsideQuot tacticParser >> ")"
@[builtinTermParser] def Tactic.quotSeq : Parser := leading_parser "`(tactic|" >> toggleInsideQuot Tactic.seq1 >> ")"
@[builtinTermParser] def Level.quot : Parser := leading_parser "`(level|" >> toggleInsideQuot levelParser >> ")"
builtin_initialize
register_parser_alias "letDecl" Term.letDecl
register_parser_alias "haveDecl" Term.haveDecl
register_parser_alias "sufficesDecl" Term.sufficesDecl
register_parser_alias "letRecDecls" Term.letRecDecls
register_parser_alias "hole" Term.hole
register_parser_alias "syntheticHole" Term.syntheticHole
register_parser_alias "matchDiscr" Term.matchDiscr
register_parser_alias "bracketedBinder" Term.bracketedBinder
register_parser_alias "attrKind" Term.attrKind
end Parser
end Lean
|
8925dbb1574c79682d1144b6ea630be5b1fdb536 | 9be442d9ec2fcf442516ed6e9e1660aa9071b7bd | /tests/lean/structuralEqns.lean | 8002737675e50b6714206dc1be7eb007bc4a9d57 | [
"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 | 357 | lean | import Lean
open Lean
open Lean.Meta
def tst (declName : Name) : MetaM Unit := do
IO.println (← getUnfoldEqnFor? declName)
def foo (xs ys zs : List Nat) : List Nat :=
match (xs, ys) with
| (xs', ys') =>
match zs with
| z::zs => foo xs ys zs
| _ => match ys' with
| [] => [1]
| _ => [2]
#eval tst ``foo
#check foo._unfold
|
8b955c93d2a6898f4eaf462fcb38bc2a274eea8d | 4727251e0cd73359b15b664c3170e5d754078599 | /src/data/W/cardinal.lean | d5dd68d7b275931c875e2397e9f0ed7c1cc1c7f7 | [
"Apache-2.0"
] | permissive | Vierkantor/mathlib | 0ea59ac32a3a43c93c44d70f441c4ee810ccceca | 83bc3b9ce9b13910b57bda6b56222495ebd31c2f | refs/heads/master | 1,658,323,012,449 | 1,652,256,003,000 | 1,652,256,003,000 | 209,296,341 | 0 | 1 | Apache-2.0 | 1,568,807,655,000 | 1,568,807,655,000 | null | UTF-8 | Lean | false | false | 2,788 | lean | /-
Copyright (c) 2021 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes
-/
import data.W.basic
import set_theory.cardinal.ordinal
/-!
# Cardinality of W-types
This file proves some theorems about the cardinality of W-types. The main result is
`cardinal_mk_le_max_omega_of_fintype` which says that if for any `a : α`,
`β a` is finite, then the cardinality of `W_type β` is at most the maximum of the
cardinality of `α` and `cardinal.omega`.
This can be used to prove theorems about the cardinality of algebraic constructions such as
polynomials. There is a surjection from a `W_type` to `mv_polynomial` for example, and
this surjection can be used to put an upper bound on the cardinality of `mv_polynomial`.
## Tags
W, W type, cardinal, first order
-/
universe u
variables {α : Type u} {β : α → Type u}
noncomputable theory
namespace W_type
open_locale cardinal
open cardinal
lemma cardinal_mk_eq_sum : #(W_type β) = sum (λ a : α, #(W_type β) ^ #(β a)) :=
begin
simp only [cardinal.power_def, ← cardinal.mk_sigma],
exact mk_congr (equiv_sigma β)
end
/-- `#(W_type β)` is the least cardinal `κ` such that `sum (λ a : α, κ ^ #(β a)) ≤ κ` -/
lemma cardinal_mk_le_of_le {κ : cardinal.{u}} (hκ : sum (λ a : α, κ ^ #(β a)) ≤ κ) :
#(W_type β) ≤ κ :=
begin
induction κ using cardinal.induction_on with γ,
simp only [cardinal.power_def, ← cardinal.mk_sigma, cardinal.le_def] at hκ,
cases hκ,
exact cardinal.mk_le_of_injective (elim_injective _ hκ.1 hκ.2)
end
/-- If, for any `a : α`, `β a` is finite, then the cardinality of `W_type β`
is at most the maximum of the cardinality of `α` and `ω` -/
lemma cardinal_mk_le_max_omega_of_fintype [Π a, fintype (β a)] : #(W_type β) ≤ max (#α) ω :=
(is_empty_or_nonempty α).elim
(begin
introI h,
rw [cardinal.mk_eq_zero (W_type β)],
exact zero_le _
end) $
λ hn,
let m := max (#α) ω in
cardinal_mk_le_of_le $
calc cardinal.sum (λ a : α, m ^ #(β a))
≤ #α * cardinal.sup.{u u}
(λ a : α, m ^ cardinal.mk (β a)) :
cardinal.sum_le_sup _
... ≤ m * cardinal.sup.{u u}
(λ a : α, m ^ #(β a)) :
mul_le_mul' (le_max_left _ _) le_rfl
... = m : mul_eq_left.{u} (le_max_right _ _)
(cardinal.sup_le (λ i, begin
cases lt_omega.1 (lt_omega_of_fintype (β i)) with n hn,
rw [hn],
exact power_nat_le (le_max_right _ _)
end))
(pos_iff_ne_zero.1 (succ_le.1
begin
rw [succ_zero],
obtain ⟨a⟩ : nonempty α, from hn,
refine le_trans _ (le_sup _ a),
rw [← @power_zero m],
exact power_le_power_left (pos_iff_ne_zero.1
(lt_of_lt_of_le omega_pos (le_max_right _ _))) (zero_le _)
end))
end W_type
|
5a49de7a899c0617dbcbd9092d930b55ba7b1d60 | a4673261e60b025e2c8c825dfa4ab9108246c32e | /tests/lean/run/monadCache.lean | bf8e3737b03617550906e3685a0a1dc29690baac | [
"Apache-2.0"
] | permissive | jcommelin/lean4 | c02dec0cc32c4bccab009285475f265f17d73228 | 2909313475588cc20ac0436e55548a4502050d0a | refs/heads/master | 1,674,129,550,893 | 1,606,415,348,000 | 1,606,415,348,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 1,340 | lean | import Lean
open Lean
partial def mkTower : Nat → Expr
| 0 => mkConst `a
| n+1 => mkApp2 (mkConst `f) (mkTower n) (mkTower n)
partial def depth : Expr → MonadCacheT Expr Nat CoreM Nat
| e =>
checkCache e fun e =>
match e with
| Expr.const c [] _ => pure 1
| Expr.app f a _ => do pure $ Nat.max (← depth f) (← depth a) + 1
| _ => pure 0
#eval (depth (mkTower 100)).run
partial def visit : Expr → MonadCacheT Expr Expr CoreM Expr
| e =>
checkCache e fun e =>
match e with
| Expr.const `a [] _ => pure $ mkConst `b
| Expr.app f a _ => e.updateApp! <$> visit f <*> visit a
| _ => pure e
#eval (visit (mkTower 4)).run
def tst : CoreM Nat := do
let e ← (visit (mkTower 100)).run; (depth e).run
#eval tst
partial def visitNoCache : Expr → CoreM Expr
| e =>
match e with
| Expr.const `a [] _ => pure $ mkConst `b
| Expr.app f a _ => e.updateApp! <$> visitNoCache f <*> visitNoCache a
| _ => pure e
-- The following is super slow
-- #eval do e ← visitNoCache (mkTower 30); (depth e).run
def displayConsts (e : Expr) : CoreM Unit :=
e.forEach fun e => match e with
| Expr.const c _ _ => do IO.println c
| _ => pure ()
def tst2 : CoreM Unit := do
let e ← (visit (mkTower 100)).run; displayConsts e
#eval tst2
|
7da08ae6207ae926d502e032692d726db4336fb2 | 491068d2ad28831e7dade8d6dff871c3e49d9431 | /hott/algebra/category/constructions/initial.hlean | 109e93a9eecfc232766ce7d107ebfcc86e7b121f | [
"Apache-2.0"
] | permissive | davidmueller13/lean | 65a3ed141b4088cd0a268e4de80eb6778b21a0e9 | c626e2e3c6f3771e07c32e82ee5b9e030de5b050 | refs/heads/master | 1,611,278,313,401 | 1,444,021,177,000 | 1,444,021,177,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 1,376 | hlean | /-
Copyright (c) 2015 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn
Initial category
-/
import .indiscrete
open functor is_trunc eq
namespace category
definition initial_precategory [constructor] : precategory empty :=
indiscrete_precategory empty
definition Initial_precategory [constructor] : Precategory :=
precategory.Mk initial_precategory
notation 0 := Initial_precategory
definition zero_op : 0ᵒᵖ = 0 := idp
definition initial_functor [constructor] (C : Precategory) : 0 ⇒ C :=
functor.mk (λx, empty.elim x)
(λx y f, empty.elim x)
(λx, empty.elim x)
(λx y z g f, empty.elim x)
definition is_contr_zero_functor [instance] (C : Precategory) : is_contr (0 ⇒ C) :=
is_contr.mk (initial_functor C)
begin
intro F, fapply functor_eq,
{ intro x, exact empty.elim x},
{ intro x y f, exact empty.elim x}
end
definition initial_functor_op (C : Precategory)
: (initial_functor C)ᵒᵖ = initial_functor Cᵒᵖ :=
by apply @is_hprop.elim (0 ⇒ Cᵒᵖ)
definition initial_functor_comp {C D : Precategory} (F : C ⇒ D)
: F ∘f initial_functor C = initial_functor D :=
by apply @is_hprop.elim (0 ⇒ D)
end category
|
0a4a40270dcea277faa8eeef42c91653a4b2e26e | 205f0fc16279a69ea36e9fd158e3a97b06834ce2 | /EXAMS/exam3-practice.lean | ba45cf82561b4343bfb2337b89446a613efc5c08 | [] | no_license | kevinsullivan/cs-dm-lean | b21d3ca1a9b2a0751ba13fcb4e7b258010a5d124 | a06a94e98be77170ca1df486c8189338b16cf6c6 | refs/heads/master | 1,585,948,743,595 | 1,544,339,346,000 | 1,544,339,346,000 | 155,570,767 | 1 | 3 | null | 1,541,540,372,000 | 1,540,995,993,000 | Lean | UTF-8 | Lean | false | false | 8,088 | lean | import data.set
open set
/-
NOTE: The final exam is comprehensive, but this practice
exam is not. In addition to working through this practice
exam, you should revisit the exam1 and exam2 practice
exams.
-/
/- SETS -/
namespace sets
/-
1.
Prove that 1 is in the set {1, 2, 3, 4, 5}.
-/
example: 1 ∈ ({1, 2, 3, 4, 5}: set ℕ) :=
begin
_
end
/-
2.
Prove that 1 is not in the set {2, 3, 4}.
-/
example: 1 ∉ ({2, 3, 4}: set ℕ) :=
begin
_
end
/-
3.
Prove that there does not exist any natural number that is
a member of the empty set of natural numbers.
-/
example: ¬(∃ n:ℕ, n ∈ (∅: set ℕ)) :=
begin
_
end
/-
4.
Prove that the intersection of the sets of natural numbers
{1, 2} and {3, 4} is empty by showing that for all natural
numbers, they are not in the intersection of {1, 2} and
{3, 4}.
-/
#reduce 2 ∈ ({3, 4}: set ℕ)
example: ∀n: ℕ, n ∉ ({1, 2}: set ℕ) ∩ ({3, 4}: set ℕ) :=
begin
_
end
/-
5.
Prove that 1 is in the difference between {1, 2, 3} and {3, 4}
-/
example: 1 ∈ ({1, 2, 3}: set ℕ) \ ({3, 4}: set ℕ) :=
begin
_
end
/-
6.
Prove that {2, 3} is a subset of the union of {1, 2} and {3, 4}
Note: use ⊆ not ⊂
-/
example: ({2, 3}: set ℕ) ⊆ ({1, 2}: set ℕ) ∪ ({3, 4}: set ℕ) :=
begin
_
end
/-
7.
Prove that {2, 3} is an element of the powerset of {1, 2, 3, 4}
-/
#reduce {2, 3} ∈ 𝒫({1, 2, 3, 4}: set ℕ)
-- ∀ ⦃a : ℕ⦄, a = 3 ∨ a = 2 ∨ false → a = 4 ∨ a = 3 ∨ a = 2 ∨ a = 1 ∨ false
example: {2, 3} ∈ 𝒫({1, 2, 3, 4}: set ℕ) :=
begin
_
end
end sets
/- RELATIONS -/
namespace relations
/-
The following problems on relations use definitions
of properties of relations from the Lean library that
are identical to those we studied in class.
-/
/-
1.
Prove that disjunction has the symmetric property
-/
example: symmetric or :=
begin
_
end
/-
2.
Prove that conjunction is a subrelation of disjunction
-/
example: subrelation and or :=
begin
_
end
/-
3.
What is the transitive closure of the relation on
ℕ represented by the set { (1,2), (2, 3) }? Write
your answer as a related set in a comment below.
-/
/-
Your answer here:
-/
end relations
/-
===================================================
Inductive types, functions, properties, and proofs.
====================================================
-/
/-
1.
Define a function, sub_mynat : mynat → mynat → mynat,
that implements subtraction of the second argument, m,
from the first, n. If m >= n, the result should be 0,
otherwise it should be n - m. Hint: Think about cases
where one of the arguments is zero, and otherwise note
the following pattern: 3 - 2 = 2 - 1 = 1 - 0 = 1.
-/
namespace mynat
inductive mynat : Type
| zero : mynat
| succ : mynat → mynat
-- def sub_mynat: mynat → mynat → mynat
/-
2.
Prove that ∀ n, sub_mynat n n = 0.
-/
/-
3.
We give you a copy of the add_mynat function
below. Show that our definition of add_mynat
is associative.
-/
def add_mynat: mynat → mynat → mynat
| mynat.zero m := m
| (mynat.succ n') m :=
mynat.succ (add_mynat n' m)
example: ∀(a b c: mynat),
add_mynat a (add_mynat b c) = add_mynat (add_mynat a b) c :=
begin
_
end
end mynat
/-
Simple inductive types.
-----------------------
-/
/-
3.
Define a new type called day having
these seven constant constructors:
sunday, monday, tuesday, wednesday,
thursday, friday, saturday. We will
interpret these constructors as
representing the actual days of the
week. Write your code below here now.
-/
inductive day : Type
-- finish this definition here
-- We suggest you open the day namespace
open day
/-
4.
Define a function, nextday : day → day,
that, when given a value, d : day, returns
the day value that represents the next day
of the week. Hint: either write a function
using a "match d with ... end", or, if you
prefer, use a tactic script (to write code!).
If you use a tactic script, use "cases d"
and for each possible case of d, specify
the exact day to be returned in that case.
For extra credit do it both ways and write
a single sentence to describe how these two
representations correspond.
-/
def nextday (d : day) : day :=
begin
_
end
/-
5.
Formalize and prove the proposition that
for any day, d, if you apply nextday to d
seven times, the result is that very same
d. Write both the proposition to be proved
and its proof using "example".
-/
-- Your answer here
/-
Recursive (nested) inductive types.
-----------------------------------
-/
/-
6.
Give an inductive type definition for nat_list,
so that values of this type represent lists of
values of type ℕ.
While there's an infinity of such lists, we can
cleverly define the set inductively with just two
rules.
First, there is an empty list of natural numbers.
We will represent it with the constant constructor,
nil_nat. Make it one of the nat_list constructors.
Second, if we are given a nat_list value, l, and
a ℕ value, e : ℕ, we can always construct a list
that is one longer than by prepending e to l. To
do this, define a constructor called nat_cons. It
take arguments, e : ℕ and l : ₤st_nat, and yield a
nat_list.
-/
inductive nat_list : Type
-- finish the definition here
-- we suggest you open the nat_list namespace
open nat_list
/-
7.
Define X to be the nat_list value that we
interpret as representing the empty list of
natural numbers, []; Y to be the nat_list
value that represents the list, [1]; and
finally Z to represent the list, [2, 1].
-/
def X : nat_list := _
def Y : nat_list := _
def Z : nat_list := _
/-
8.
Define a function (it will be recursive)
that takes any nat_list value and that
returns its length (a natural number that
indicates how many values are in the list).
Call the function, length.
The challenge is to see the recursion in
the definition of the length of a list.
Hint questions: What is the length of the
empty list? What is the length of a list
that is not empty, and that thus must be
of the form (nat_cons h t), where h is the
value at the head of the list and t is the
rest of the list.
-/
/-
Uncomment the following line
and finish the definition
-/
--def length : nat_list → ℕ
/-
The stuff that follows is challenging
Get solid on the more basic stuff before
going here.
-/
/-
9.
Define a function, app (short for "append"),
that takes two nat_list values, let's call them
l1 and l2, and that returns the nat_list with
the elements of the first list followed by the
elements of the second list. For example,
(app Y Z) should return the list [1, 2, 1].
Hint: Consider the possible forms of l1. It
can only be either nat_nil or (nat_cons h t),
where, once again, h is is first element in
l1, and t is the rest of the list. Write the
function recursively accordingly.
-/
def app : nat_list → nat_list → nat_list
_
/-
10.
Prove the following
∀ l1 l2 : nat_list,
(length l1 + length l2) = length (append l1 l2)
Hint: use proof by induction on l1. There will be
two cases. In the first, l1 will be nat_nil, and
its length will reduce directly to 0. In the second
case, you will show that if the property is true for
some list l1', it is true for next bigger list: one
in the form of (nat_cons h l1').
-/
example : ∀ l1 l2 : nat_list,
(length l1 + length l2) =
length (app l1 l2) :=
begin
_
end
/- Formal Languages -/
namespace formal
/-
1.
Extend the following formal language to incorporate "or"
in a manner similar to "and"
-/
inductive pVar : Type
| mk : ℕ → pVar
inductive pExp : Type
| mk_lit_pexp : bool → pExp
| mk_var_pexp : pVar → pExp
| mk_not_pexp : pExp → pExp
| mk_and_pexp : pExp → pExp → pExp
open pExp
def pInterp := pVar → bool
def pEval : pExp → pInterp → bool
-- how to evaluate literal expression
| (mk_lit_pexp b) i := b
-- how to evaluate variable expression
| (mk_var_pexp v) i := i v
-- how to evaluate a "not" expression
| (mk_not_pexp e) i := bnot (pEval e i)
-- how to evaluate an "and" expression
| (mk_and_pexp e1 e2) i :=
band (pEval e1 i) (pEval e2 i)
end formal
|
28c13729682fdfa9c5d7caf255bfbb90320b50a6 | 94e33a31faa76775069b071adea97e86e218a8ee | /src/measure_theory/function/conditional_expectation.lean | f18b753473b651ebe1c6a49acbd05388f565f846 | [
"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 | 118,221 | lean | /-
Copyright (c) 2021 Rémy Degenne. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Rémy Degenne
-/
import analysis.inner_product_space.projection
import measure_theory.function.l2_space
import measure_theory.decomposition.radon_nikodym
import measure_theory.function.uniform_integrable
/-! # Conditional expectation
We build the conditional expectation of an integrable function `f` with value in a Banach space
with respect to a measure `μ` (defined on a measurable space structure `m0`) and a measurable space
structure `m` with `hm : m ≤ m0` (a sub-sigma-algebra). This is an `m`-strongly measurable
function `μ[f|hm]` which is integrable and verifies `∫ x in s, μ[f|hm] x ∂μ = ∫ x in s, f x ∂μ`
for all `m`-measurable sets `s`. It is unique as an element of `L¹`.
The construction is done in four steps:
* Define the conditional expectation of an `L²` function, as an element of `L²`. This is the
orthogonal projection on the subspace of almost everywhere `m`-measurable functions.
* Show that the conditional expectation of the indicator of a measurable set with finite measure
is integrable and define a map `set α → (E →L[ℝ] (α →₁[μ] E))` which to a set associates a linear
map. That linear map sends `x ∈ E` to the conditional expectation of the indicator of the set
with value `x`.
* Extend that map to `condexp_L1_clm : (α →₁[μ] E) →L[ℝ] (α →₁[μ] E)`. This is done using the same
construction as the Bochner integral (see the file `measure_theory/integral/set_to_L1`).
* Define the conditional expectation of a function `f : α → E`, which is an integrable function
`α → E` equal to 0 if `f` is not integrable, and equal to an `m`-measurable representative of
`condexp_L1_clm` applied to `[f]`, the equivalence class of `f` in `L¹`.
## Main results
The conditional expectation and its properties
* `condexp (m : measurable_space α) (μ : measure α) (f : α → E)`: conditional expectation of `f`
with respect to `m`.
* `integrable_condexp` : `condexp` is integrable.
* `strongly_measurable_condexp` : `condexp` is `m`-strongly-measurable.
* `set_integral_condexp (hf : integrable f μ) (hs : measurable_set[m] s)` : if `m ≤ m0` (the
σ-algebra over which the measure is defined), then the conditional expectation verifies
`∫ x in s, condexp m μ f x ∂μ = ∫ x in s, f x ∂μ` for any `m`-measurable set `s`.
While `condexp` is function-valued, we also define `condexp_L1` with value in `L1` and a continuous
linear map `condexp_L1_clm` from `L1` to `L1`. `condexp` should be used in most cases.
Uniqueness of the conditional expectation
* `Lp.ae_eq_of_forall_set_integral_eq'`: two `Lp` functions verifying the equality of integrals
defining the conditional expectation are equal.
* `ae_eq_of_forall_set_integral_eq_of_sigma_finite'`: two functions verifying the equality of
integrals defining the conditional expectation are equal almost everywhere.
Requires `[sigma_finite (μ.trim hm)]`.
* `ae_eq_condexp_of_forall_set_integral_eq`: an a.e. `m`-measurable function which verifies the
equality of integrals is a.e. equal to `condexp`.
## Notations
For a measure `μ` defined on a measurable space structure `m0`, another measurable space structure
`m` with `hm : m ≤ m0` (a sub-σ-algebra) and a function `f`, we define the notation
* `μ[f|m] = condexp m μ f`.
## Implementation notes
Most of the results in this file are valid for a complete real normed space `F`.
However, some lemmas also use `𝕜 : is_R_or_C`:
* `condexp_L2` is defined only for an `inner_product_space` for now, and we use `𝕜` for its field.
* results about scalar multiplication are stated not only for `ℝ` but also for `𝕜` if we happen to
have `normed_space 𝕜 F`.
TODO: split this file in two with one containing constructions and the other with basic
properties.
## Tags
conditional expectation, conditional expected value
-/
noncomputable theory
open topological_space measure_theory.Lp filter continuous_linear_map
open_locale nnreal ennreal topological_space big_operators measure_theory
namespace measure_theory
/-- A function `f` verifies `ae_strongly_measurable' m f μ` if it is `μ`-a.e. equal to
an `m`-strongly measurable function. This is similar to `ae_strongly_measurable`, but the
`measurable_space` structures used for the measurability statement and for the measure are
different. -/
def ae_strongly_measurable' {α β} [topological_space β]
(m : measurable_space α) {m0 : measurable_space α}
(f : α → β) (μ : measure α) : Prop :=
∃ g : α → β, strongly_measurable[m] g ∧ f =ᵐ[μ] g
namespace ae_strongly_measurable'
variables {α β 𝕜 : Type*} {m m0 : measurable_space α} {μ : measure α}
[topological_space β] {f g : α → β}
lemma congr (hf : ae_strongly_measurable' m f μ) (hfg : f =ᵐ[μ] g) :
ae_strongly_measurable' m g μ :=
by { obtain ⟨f', hf'_meas, hff'⟩ := hf, exact ⟨f', hf'_meas, hfg.symm.trans hff'⟩, }
lemma add [has_add β] [has_continuous_add β] (hf : ae_strongly_measurable' m f μ)
(hg : ae_strongly_measurable' m g μ) :
ae_strongly_measurable' m (f+g) μ :=
begin
rcases hf with ⟨f', h_f'_meas, hff'⟩,
rcases hg with ⟨g', h_g'_meas, hgg'⟩,
exact ⟨f' + g', h_f'_meas.add h_g'_meas, hff'.add hgg'⟩,
end
lemma neg [add_group β] [topological_add_group β]
{f : α → β} (hfm : ae_strongly_measurable' m f μ) :
ae_strongly_measurable' m (-f) μ :=
begin
rcases hfm with ⟨f', hf'_meas, hf_ae⟩,
refine ⟨-f', hf'_meas.neg, hf_ae.mono (λ x hx, _)⟩,
simp_rw pi.neg_apply,
rw hx,
end
lemma sub [add_group β] [topological_add_group β] {f g : α → β}
(hfm : ae_strongly_measurable' m f μ) (hgm : ae_strongly_measurable' m g μ) :
ae_strongly_measurable' m (f - g) μ :=
begin
rcases hfm with ⟨f', hf'_meas, hf_ae⟩,
rcases hgm with ⟨g', hg'_meas, hg_ae⟩,
refine ⟨f'-g', hf'_meas.sub hg'_meas, hf_ae.mp (hg_ae.mono (λ x hx1 hx2, _))⟩,
simp_rw pi.sub_apply,
rw [hx1, hx2],
end
lemma const_smul [has_smul 𝕜 β] [has_continuous_const_smul 𝕜 β]
(c : 𝕜) (hf : ae_strongly_measurable' m f μ) :
ae_strongly_measurable' m (c • f) μ :=
begin
rcases hf with ⟨f', h_f'_meas, hff'⟩,
refine ⟨c • f', h_f'_meas.const_smul c, _⟩,
exact eventually_eq.fun_comp hff' (λ x, c • x),
end
lemma const_inner {𝕜 β} [is_R_or_C 𝕜] [inner_product_space 𝕜 β]
{f : α → β} (hfm : ae_strongly_measurable' m f μ) (c : β) :
ae_strongly_measurable' m (λ x, (inner c (f x) : 𝕜)) μ :=
begin
rcases hfm with ⟨f', hf'_meas, hf_ae⟩,
refine ⟨λ x, (inner c (f' x) : 𝕜), (@strongly_measurable_const _ _ m _ _).inner hf'_meas,
hf_ae.mono (λ x hx, _)⟩,
dsimp only,
rw hx,
end
/-- An `m`-strongly measurable function almost everywhere equal to `f`. -/
def mk (f : α → β) (hfm : ae_strongly_measurable' m f μ) : α → β := hfm.some
lemma strongly_measurable_mk {f : α → β} (hfm : ae_strongly_measurable' m f μ) :
strongly_measurable[m] (hfm.mk f) :=
hfm.some_spec.1
lemma ae_eq_mk {f : α → β} (hfm : ae_strongly_measurable' m f μ) : f =ᵐ[μ] hfm.mk f :=
hfm.some_spec.2
lemma continuous_comp {γ} [topological_space γ] {f : α → β} {g : β → γ}
(hg : continuous g) (hf : ae_strongly_measurable' m f μ) :
ae_strongly_measurable' m (g ∘ f) μ :=
⟨λ x, g (hf.mk _ x),
@continuous.comp_strongly_measurable _ _ _ m _ _ _ _ hg hf.strongly_measurable_mk,
hf.ae_eq_mk.mono (λ x hx, by rw [function.comp_apply, hx])⟩
end ae_strongly_measurable'
lemma ae_strongly_measurable'_of_ae_strongly_measurable'_trim {α β} {m m0 m0' : measurable_space α}
[topological_space β] (hm0 : m0 ≤ m0') {μ : measure α} {f : α → β}
(hf : ae_strongly_measurable' m f (μ.trim hm0)) :
ae_strongly_measurable' m f μ :=
by { obtain ⟨g, hg_meas, hfg⟩ := hf, exact ⟨g, hg_meas, ae_eq_of_ae_eq_trim hfg⟩, }
lemma strongly_measurable.ae_strongly_measurable'
{α β} {m m0 : measurable_space α} [topological_space β]
{μ : measure α} {f : α → β} (hf : strongly_measurable[m] f) :
ae_strongly_measurable' m f μ :=
⟨f, hf, ae_eq_refl _⟩
lemma ae_eq_trim_iff_of_ae_strongly_measurable' {α β} [topological_space β] [metrizable_space β]
{m m0 : measurable_space α} {μ : measure α} {f g : α → β}
(hm : m ≤ m0) (hfm : ae_strongly_measurable' m f μ) (hgm : ae_strongly_measurable' m g μ) :
hfm.mk f =ᵐ[μ.trim hm] hgm.mk g ↔ f =ᵐ[μ] g :=
(ae_eq_trim_iff hm hfm.strongly_measurable_mk hgm.strongly_measurable_mk).trans
⟨λ h, hfm.ae_eq_mk.trans (h.trans hgm.ae_eq_mk.symm),
λ h, hfm.ae_eq_mk.symm.trans (h.trans hgm.ae_eq_mk)⟩
/-- If the restriction to a set `s` of a σ-algebra `m` is included in the restriction to `s` of
another σ-algebra `m₂` (hypothesis `hs`), the set `s` is `m` measurable and a function `f` almost
everywhere supported on `s` is `m`-ae-strongly-measurable, then `f` is also
`m₂`-ae-strongly-measurable. -/
lemma ae_strongly_measurable'.ae_strongly_measurable'_of_measurable_space_le_on
{α E} {m m₂ m0 : measurable_space α} {μ : measure α}
[topological_space E] [has_zero E] (hm : m ≤ m0) {s : set α} {f : α → E}
(hs_m : measurable_set[m] s) (hs : ∀ t, measurable_set[m] (s ∩ t) → measurable_set[m₂] (s ∩ t))
(hf : ae_strongly_measurable' m f μ) (hf_zero : f =ᵐ[μ.restrict sᶜ] 0) :
ae_strongly_measurable' m₂ f μ :=
begin
let f' := hf.mk f,
have h_ind_eq : s.indicator (hf.mk f) =ᵐ[μ] f,
{ refine filter.eventually_eq.trans _
(indicator_ae_eq_of_restrict_compl_ae_eq_zero (hm _ hs_m) hf_zero),
filter_upwards [hf.ae_eq_mk] with x hx,
by_cases hxs : x ∈ s,
{ simp [hxs, hx], },
{ simp [hxs], }, },
suffices : strongly_measurable[m₂] (s.indicator (hf.mk f)),
from ae_strongly_measurable'.congr this.ae_strongly_measurable' h_ind_eq,
have hf_ind : strongly_measurable[m] (s.indicator (hf.mk f)),
from hf.strongly_measurable_mk.indicator hs_m,
exact hf_ind.strongly_measurable_of_measurable_space_le_on hs_m hs
(λ x hxs, set.indicator_of_not_mem hxs _),
end
variables {α β γ E E' F F' G G' H 𝕜 : Type*} {p : ℝ≥0∞}
[is_R_or_C 𝕜] -- 𝕜 for ℝ or ℂ
[topological_space β] -- β for a generic topological space
-- E for an inner product space
[inner_product_space 𝕜 E]
-- E' for an inner product space on which we compute integrals
[inner_product_space 𝕜 E']
[complete_space E'] [normed_space ℝ E']
-- F for a Lp submodule
[normed_group F] [normed_space 𝕜 F]
-- F' for integrals on a Lp submodule
[normed_group F'] [normed_space 𝕜 F'] [normed_space ℝ F'] [complete_space F']
-- G for a Lp add_subgroup
[normed_group G]
-- G' for integrals on a Lp add_subgroup
[normed_group G'] [normed_space ℝ G'] [complete_space G']
-- H for a normed group (hypotheses of mem_ℒp)
[normed_group H]
section Lp_meas
/-! ## The subset `Lp_meas` of `Lp` functions a.e. measurable with respect to a sub-sigma-algebra -/
variables (F)
/-- `Lp_meas_subgroup F m p μ` is the subspace of `Lp F p μ` containing functions `f` verifying
`ae_strongly_measurable' m f μ`, i.e. functions which are `μ`-a.e. equal to
an `m`-strongly measurable function. -/
def Lp_meas_subgroup (m : measurable_space α) [measurable_space α] (p : ℝ≥0∞) (μ : measure α) :
add_subgroup (Lp F p μ) :=
{ carrier := {f : (Lp F p μ) | ae_strongly_measurable' m f μ} ,
zero_mem' := ⟨(0 : α → F), @strongly_measurable_zero _ _ m _ _, Lp.coe_fn_zero _ _ _⟩,
add_mem' := λ f g hf hg, (hf.add hg).congr (Lp.coe_fn_add f g).symm,
neg_mem' := λ f hf, ae_strongly_measurable'.congr hf.neg (Lp.coe_fn_neg f).symm, }
variables (𝕜)
/-- `Lp_meas F 𝕜 m p μ` is the subspace of `Lp F p μ` containing functions `f` verifying
`ae_strongly_measurable' m f μ`, i.e. functions which are `μ`-a.e. equal to
an `m`-strongly measurable function. -/
def Lp_meas (m : measurable_space α) [measurable_space α] (p : ℝ≥0∞)
(μ : measure α) :
submodule 𝕜 (Lp F p μ) :=
{ carrier := {f : (Lp F p μ) | ae_strongly_measurable' m f μ} ,
zero_mem' := ⟨(0 : α → F), @strongly_measurable_zero _ _ m _ _, Lp.coe_fn_zero _ _ _⟩,
add_mem' := λ f g hf hg, (hf.add hg).congr (Lp.coe_fn_add f g).symm,
smul_mem' := λ c f hf, (hf.const_smul c).congr (Lp.coe_fn_smul c f).symm, }
variables {F 𝕜}
variables
lemma mem_Lp_meas_subgroup_iff_ae_strongly_measurable' {m m0 : measurable_space α} {μ : measure α}
{f : Lp F p μ} :
f ∈ Lp_meas_subgroup F m p μ ↔ ae_strongly_measurable' m f μ :=
by rw [← add_subgroup.mem_carrier, Lp_meas_subgroup, set.mem_set_of_eq]
lemma mem_Lp_meas_iff_ae_strongly_measurable'
{m m0 : measurable_space α} {μ : measure α} {f : Lp F p μ} :
f ∈ Lp_meas F 𝕜 m p μ ↔ ae_strongly_measurable' m f μ :=
by rw [← set_like.mem_coe, ← submodule.mem_carrier, Lp_meas, set.mem_set_of_eq]
lemma Lp_meas.ae_strongly_measurable'
{m m0 : measurable_space α} {μ : measure α} (f : Lp_meas F 𝕜 m p μ) :
ae_strongly_measurable' m f μ :=
mem_Lp_meas_iff_ae_strongly_measurable'.mp f.mem
lemma mem_Lp_meas_self
{m0 : measurable_space α} (μ : measure α) (f : Lp F p μ) :
f ∈ Lp_meas F 𝕜 m0 p μ :=
mem_Lp_meas_iff_ae_strongly_measurable'.mpr (Lp.ae_strongly_measurable f)
lemma Lp_meas_subgroup_coe {m m0 : measurable_space α} {μ : measure α}
{f : Lp_meas_subgroup F m p μ} :
⇑f = (f : Lp F p μ) :=
coe_fn_coe_base f
lemma Lp_meas_coe {m m0 : measurable_space α} {μ : measure α} {f : Lp_meas F 𝕜 m p μ} :
⇑f = (f : Lp F p μ) :=
coe_fn_coe_base f
lemma mem_Lp_meas_indicator_const_Lp {m m0 : measurable_space α} (hm : m ≤ m0)
{μ : measure α} {s : set α} (hs : measurable_set[m] s) (hμs : μ s ≠ ∞) {c : F} :
indicator_const_Lp p (hm s hs) hμs c ∈ Lp_meas F 𝕜 m p μ :=
⟨s.indicator (λ x : α, c), (@strongly_measurable_const _ _ m _ _).indicator hs,
indicator_const_Lp_coe_fn⟩
section complete_subspace
/-! ## The subspace `Lp_meas` is complete.
We define an `isometric` between `Lp_meas_subgroup` and the `Lp` space corresponding to the
measure `μ.trim hm`. As a consequence, the completeness of `Lp` implies completeness of
`Lp_meas_subgroup` (and `Lp_meas`). -/
variables {ι : Type*} {m m0 : measurable_space α} {μ : measure α}
/-- If `f` belongs to `Lp_meas_subgroup F m p μ`, then the measurable function it is almost
everywhere equal to (given by `ae_measurable.mk`) belongs to `ℒp` for the measure `μ.trim hm`. -/
lemma mem_ℒp_trim_of_mem_Lp_meas_subgroup (hm : m ≤ m0) (f : Lp F p μ)
(hf_meas : f ∈ Lp_meas_subgroup F m p μ) :
mem_ℒp (mem_Lp_meas_subgroup_iff_ae_strongly_measurable'.mp hf_meas).some p (μ.trim hm) :=
begin
have hf : ae_strongly_measurable' m f μ,
from (mem_Lp_meas_subgroup_iff_ae_strongly_measurable'.mp hf_meas),
let g := hf.some,
obtain ⟨hg, hfg⟩ := hf.some_spec,
change mem_ℒp g p (μ.trim hm),
refine ⟨hg.ae_strongly_measurable, _⟩,
have h_snorm_fg : snorm g p (μ.trim hm) = snorm f p μ,
by { rw snorm_trim hm hg, exact snorm_congr_ae hfg.symm, },
rw h_snorm_fg,
exact Lp.snorm_lt_top f,
end
/-- If `f` belongs to `Lp` for the measure `μ.trim hm`, then it belongs to the subgroup
`Lp_meas_subgroup F m p μ`. -/
lemma mem_Lp_meas_subgroup_to_Lp_of_trim (hm : m ≤ m0) (f : Lp F p (μ.trim hm)) :
(mem_ℒp_of_mem_ℒp_trim hm (Lp.mem_ℒp f)).to_Lp f ∈ Lp_meas_subgroup F m p μ :=
begin
let hf_mem_ℒp := mem_ℒp_of_mem_ℒp_trim hm (Lp.mem_ℒp f),
rw mem_Lp_meas_subgroup_iff_ae_strongly_measurable',
refine ae_strongly_measurable'.congr _ (mem_ℒp.coe_fn_to_Lp hf_mem_ℒp).symm,
refine ae_strongly_measurable'_of_ae_strongly_measurable'_trim hm _,
exact Lp.ae_strongly_measurable f,
end
variables (F p μ)
/-- Map from `Lp_meas_subgroup` to `Lp F p (μ.trim hm)`. -/
def Lp_meas_subgroup_to_Lp_trim (hm : m ≤ m0) (f : Lp_meas_subgroup F m p μ) : Lp F p (μ.trim hm) :=
mem_ℒp.to_Lp (mem_Lp_meas_subgroup_iff_ae_strongly_measurable'.mp f.mem).some
(mem_ℒp_trim_of_mem_Lp_meas_subgroup hm f f.mem)
variables (𝕜)
/-- Map from `Lp_meas` to `Lp F p (μ.trim hm)`. -/
def Lp_meas_to_Lp_trim (hm : m ≤ m0) (f : Lp_meas F 𝕜 m p μ) : Lp F p (μ.trim hm) :=
mem_ℒp.to_Lp (mem_Lp_meas_iff_ae_strongly_measurable'.mp f.mem).some
(mem_ℒp_trim_of_mem_Lp_meas_subgroup hm f f.mem)
variables {𝕜}
/-- Map from `Lp F p (μ.trim hm)` to `Lp_meas_subgroup`, inverse of
`Lp_meas_subgroup_to_Lp_trim`. -/
def Lp_trim_to_Lp_meas_subgroup (hm : m ≤ m0) (f : Lp F p (μ.trim hm)) : Lp_meas_subgroup F m p μ :=
⟨(mem_ℒp_of_mem_ℒp_trim hm (Lp.mem_ℒp f)).to_Lp f, mem_Lp_meas_subgroup_to_Lp_of_trim hm f⟩
variables (𝕜)
/-- Map from `Lp F p (μ.trim hm)` to `Lp_meas`, inverse of `Lp_meas_to_Lp_trim`. -/
def Lp_trim_to_Lp_meas (hm : m ≤ m0) (f : Lp F p (μ.trim hm)) : Lp_meas F 𝕜 m p μ :=
⟨(mem_ℒp_of_mem_ℒp_trim hm (Lp.mem_ℒp f)).to_Lp f, mem_Lp_meas_subgroup_to_Lp_of_trim hm f⟩
variables {F 𝕜 p μ}
lemma Lp_meas_subgroup_to_Lp_trim_ae_eq (hm : m ≤ m0) (f : Lp_meas_subgroup F m p μ) :
Lp_meas_subgroup_to_Lp_trim F p μ hm f =ᵐ[μ] f :=
(ae_eq_of_ae_eq_trim (mem_ℒp.coe_fn_to_Lp (mem_ℒp_trim_of_mem_Lp_meas_subgroup hm ↑f f.mem))).trans
(mem_Lp_meas_subgroup_iff_ae_strongly_measurable'.mp f.mem).some_spec.2.symm
lemma Lp_trim_to_Lp_meas_subgroup_ae_eq (hm : m ≤ m0) (f : Lp F p (μ.trim hm)) :
Lp_trim_to_Lp_meas_subgroup F p μ hm f =ᵐ[μ] f :=
mem_ℒp.coe_fn_to_Lp _
lemma Lp_meas_to_Lp_trim_ae_eq (hm : m ≤ m0) (f : Lp_meas F 𝕜 m p μ) :
Lp_meas_to_Lp_trim F 𝕜 p μ hm f =ᵐ[μ] f :=
(ae_eq_of_ae_eq_trim (mem_ℒp.coe_fn_to_Lp (mem_ℒp_trim_of_mem_Lp_meas_subgroup hm ↑f f.mem))).trans
(mem_Lp_meas_subgroup_iff_ae_strongly_measurable'.mp f.mem).some_spec.2.symm
lemma Lp_trim_to_Lp_meas_ae_eq (hm : m ≤ m0) (f : Lp F p (μ.trim hm)) :
Lp_trim_to_Lp_meas F 𝕜 p μ hm f =ᵐ[μ] f :=
mem_ℒp.coe_fn_to_Lp _
/-- `Lp_trim_to_Lp_meas_subgroup` is a right inverse of `Lp_meas_subgroup_to_Lp_trim`. -/
lemma Lp_meas_subgroup_to_Lp_trim_right_inv (hm : m ≤ m0) :
function.right_inverse (Lp_trim_to_Lp_meas_subgroup F p μ hm)
(Lp_meas_subgroup_to_Lp_trim F p μ hm) :=
begin
intro f,
ext1,
refine ae_eq_trim_of_strongly_measurable hm
(Lp.strongly_measurable _) (Lp.strongly_measurable _) _,
exact (Lp_meas_subgroup_to_Lp_trim_ae_eq hm _).trans (Lp_trim_to_Lp_meas_subgroup_ae_eq hm _),
end
/-- `Lp_trim_to_Lp_meas_subgroup` is a left inverse of `Lp_meas_subgroup_to_Lp_trim`. -/
lemma Lp_meas_subgroup_to_Lp_trim_left_inv (hm : m ≤ m0) :
function.left_inverse (Lp_trim_to_Lp_meas_subgroup F p μ hm)
(Lp_meas_subgroup_to_Lp_trim F p μ hm) :=
begin
intro f,
ext1,
ext1,
rw ← Lp_meas_subgroup_coe,
exact (Lp_trim_to_Lp_meas_subgroup_ae_eq hm _).trans (Lp_meas_subgroup_to_Lp_trim_ae_eq hm _),
end
lemma Lp_meas_subgroup_to_Lp_trim_add (hm : m ≤ m0) (f g : Lp_meas_subgroup F m p μ) :
Lp_meas_subgroup_to_Lp_trim F p μ hm (f + g)
= Lp_meas_subgroup_to_Lp_trim F p μ hm f + Lp_meas_subgroup_to_Lp_trim F p μ hm g :=
begin
ext1,
refine eventually_eq.trans _ (Lp.coe_fn_add _ _).symm,
refine ae_eq_trim_of_strongly_measurable hm (Lp.strongly_measurable _) _ _,
{ exact (Lp.strongly_measurable _).add (Lp.strongly_measurable _), },
refine (Lp_meas_subgroup_to_Lp_trim_ae_eq hm _).trans _,
refine eventually_eq.trans _
(eventually_eq.add (Lp_meas_subgroup_to_Lp_trim_ae_eq hm f).symm
(Lp_meas_subgroup_to_Lp_trim_ae_eq hm g).symm),
refine (Lp.coe_fn_add _ _).trans _,
simp_rw Lp_meas_subgroup_coe,
exact eventually_of_forall (λ x, by refl),
end
lemma Lp_meas_subgroup_to_Lp_trim_neg (hm : m ≤ m0) (f : Lp_meas_subgroup F m p μ) :
Lp_meas_subgroup_to_Lp_trim F p μ hm (-f)
= -Lp_meas_subgroup_to_Lp_trim F p μ hm f :=
begin
ext1,
refine eventually_eq.trans _ (Lp.coe_fn_neg _).symm,
refine ae_eq_trim_of_strongly_measurable hm (Lp.strongly_measurable _) _ _,
{ exact @strongly_measurable.neg _ _ _ m _ _ _ (Lp.strongly_measurable _), },
refine (Lp_meas_subgroup_to_Lp_trim_ae_eq hm _).trans _,
refine eventually_eq.trans _
(eventually_eq.neg (Lp_meas_subgroup_to_Lp_trim_ae_eq hm f).symm),
refine (Lp.coe_fn_neg _).trans _,
simp_rw Lp_meas_subgroup_coe,
exact eventually_of_forall (λ x, by refl),
end
lemma Lp_meas_subgroup_to_Lp_trim_sub (hm : m ≤ m0) (f g : Lp_meas_subgroup F m p μ) :
Lp_meas_subgroup_to_Lp_trim F p μ hm (f - g)
= Lp_meas_subgroup_to_Lp_trim F p μ hm f - Lp_meas_subgroup_to_Lp_trim F p μ hm g :=
by rw [sub_eq_add_neg, sub_eq_add_neg, Lp_meas_subgroup_to_Lp_trim_add,
Lp_meas_subgroup_to_Lp_trim_neg]
lemma Lp_meas_to_Lp_trim_smul (hm : m ≤ m0) (c : 𝕜) (f : Lp_meas F 𝕜 m p μ) :
Lp_meas_to_Lp_trim F 𝕜 p μ hm (c • f) = c • Lp_meas_to_Lp_trim F 𝕜 p μ hm f :=
begin
ext1,
refine eventually_eq.trans _ (Lp.coe_fn_smul _ _).symm,
refine ae_eq_trim_of_strongly_measurable hm (Lp.strongly_measurable _) _ _,
{ exact (Lp.strongly_measurable _).const_smul c, },
refine (Lp_meas_to_Lp_trim_ae_eq hm _).trans _,
refine (Lp.coe_fn_smul _ _).trans _,
refine (Lp_meas_to_Lp_trim_ae_eq hm f).mono (λ x hx, _),
rw [pi.smul_apply, pi.smul_apply, hx],
refl,
end
/-- `Lp_meas_subgroup_to_Lp_trim` preserves the norm. -/
lemma Lp_meas_subgroup_to_Lp_trim_norm_map [hp : fact (1 ≤ p)] (hm : m ≤ m0)
(f : Lp_meas_subgroup F m p μ) :
∥Lp_meas_subgroup_to_Lp_trim F p μ hm f∥ = ∥f∥ :=
begin
rw [Lp.norm_def, snorm_trim hm (Lp.strongly_measurable _),
snorm_congr_ae (Lp_meas_subgroup_to_Lp_trim_ae_eq hm _), Lp_meas_subgroup_coe, ← Lp.norm_def],
congr,
end
lemma isometry_Lp_meas_subgroup_to_Lp_trim [hp : fact (1 ≤ p)] (hm : m ≤ m0) :
isometry (Lp_meas_subgroup_to_Lp_trim F p μ hm) :=
begin
rw isometry_emetric_iff_metric,
intros f g,
rw [dist_eq_norm, ← Lp_meas_subgroup_to_Lp_trim_sub, Lp_meas_subgroup_to_Lp_trim_norm_map,
dist_eq_norm],
end
variables (F p μ)
/-- `Lp_meas_subgroup` and `Lp F p (μ.trim hm)` are isometric. -/
def Lp_meas_subgroup_to_Lp_trim_iso [hp : fact (1 ≤ p)] (hm : m ≤ m0) :
Lp_meas_subgroup F m p μ ≃ᵢ Lp F p (μ.trim hm) :=
{ to_fun := Lp_meas_subgroup_to_Lp_trim F p μ hm,
inv_fun := Lp_trim_to_Lp_meas_subgroup F p μ hm,
left_inv := Lp_meas_subgroup_to_Lp_trim_left_inv hm,
right_inv := Lp_meas_subgroup_to_Lp_trim_right_inv hm,
isometry_to_fun := isometry_Lp_meas_subgroup_to_Lp_trim hm, }
variables (𝕜)
/-- `Lp_meas_subgroup` and `Lp_meas` are isometric. -/
def Lp_meas_subgroup_to_Lp_meas_iso [hp : fact (1 ≤ p)] :
Lp_meas_subgroup F m p μ ≃ᵢ Lp_meas F 𝕜 m p μ :=
isometric.refl (Lp_meas_subgroup F m p μ)
/-- `Lp_meas` and `Lp F p (μ.trim hm)` are isometric, with a linear equivalence. -/
def Lp_meas_to_Lp_trim_lie [hp : fact (1 ≤ p)] (hm : m ≤ m0) :
Lp_meas F 𝕜 m p μ ≃ₗᵢ[𝕜] Lp F p (μ.trim hm) :=
{ to_fun := Lp_meas_to_Lp_trim F 𝕜 p μ hm,
inv_fun := Lp_trim_to_Lp_meas F 𝕜 p μ hm,
left_inv := Lp_meas_subgroup_to_Lp_trim_left_inv hm,
right_inv := Lp_meas_subgroup_to_Lp_trim_right_inv hm,
map_add' := Lp_meas_subgroup_to_Lp_trim_add hm,
map_smul' := Lp_meas_to_Lp_trim_smul hm,
norm_map' := Lp_meas_subgroup_to_Lp_trim_norm_map hm, }
variables {F 𝕜 p μ}
instance [hm : fact (m ≤ m0)] [complete_space F] [hp : fact (1 ≤ p)] :
complete_space (Lp_meas_subgroup F m p μ) :=
by { rw (Lp_meas_subgroup_to_Lp_trim_iso F p μ hm.elim).complete_space_iff, apply_instance, }
instance [hm : fact (m ≤ m0)] [complete_space F] [hp : fact (1 ≤ p)] :
complete_space (Lp_meas F 𝕜 m p μ) :=
by { rw (Lp_meas_subgroup_to_Lp_meas_iso F 𝕜 p μ).symm.complete_space_iff, apply_instance, }
lemma is_complete_ae_strongly_measurable' [hp : fact (1 ≤ p)] [complete_space F] (hm : m ≤ m0) :
is_complete {f : Lp F p μ | ae_strongly_measurable' m f μ} :=
begin
rw ← complete_space_coe_iff_is_complete,
haveI : fact (m ≤ m0) := ⟨hm⟩,
change complete_space (Lp_meas_subgroup F m p μ),
apply_instance,
end
lemma is_closed_ae_strongly_measurable' [hp : fact (1 ≤ p)] [complete_space F] (hm : m ≤ m0) :
is_closed {f : Lp F p μ | ae_strongly_measurable' m f μ} :=
is_complete.is_closed (is_complete_ae_strongly_measurable' hm)
end complete_subspace
section strongly_measurable
variables {m m0 : measurable_space α} {μ : measure α}
/-- We do not get `ae_fin_strongly_measurable f (μ.trim hm)`, since we don't have
`f =ᵐ[μ.trim hm] Lp_meas_to_Lp_trim F 𝕜 p μ hm f` but only the weaker
`f =ᵐ[μ] Lp_meas_to_Lp_trim F 𝕜 p μ hm f`. -/
lemma Lp_meas.ae_fin_strongly_measurable' (hm : m ≤ m0) (f : Lp_meas F 𝕜 m p μ) (hp_ne_zero : p ≠ 0)
(hp_ne_top : p ≠ ∞) :
∃ g, fin_strongly_measurable g (μ.trim hm) ∧ f =ᵐ[μ] g :=
⟨Lp_meas_subgroup_to_Lp_trim F p μ hm f, Lp.fin_strongly_measurable _ hp_ne_zero hp_ne_top,
(Lp_meas_subgroup_to_Lp_trim_ae_eq hm f).symm⟩
/-- When applying the inverse of `Lp_meas_to_Lp_trim_lie` (which takes a function in the Lp space of
the sub-sigma algebra and returns its version in the larger Lp space) to an indicator of the
sub-sigma-algebra, we obtain an indicator in the Lp space of the larger sigma-algebra. -/
lemma Lp_meas_to_Lp_trim_lie_symm_indicator [one_le_p : fact (1 ≤ p)] [normed_space ℝ F]
{hm : m ≤ m0} {s : set α} {μ : measure α}
(hs : measurable_set[m] s) (hμs : μ.trim hm s ≠ ∞) (c : F) :
((Lp_meas_to_Lp_trim_lie F ℝ p μ hm).symm
(indicator_const_Lp p hs hμs c) : Lp F p μ)
= indicator_const_Lp p (hm s hs) ((le_trim hm).trans_lt hμs.lt_top).ne c :=
begin
ext1,
rw ← Lp_meas_coe,
change Lp_trim_to_Lp_meas F ℝ p μ hm (indicator_const_Lp p hs hμs c)
=ᵐ[μ] (indicator_const_Lp p _ _ c : α → F),
refine (Lp_trim_to_Lp_meas_ae_eq hm _).trans _,
exact (ae_eq_of_ae_eq_trim indicator_const_Lp_coe_fn).trans indicator_const_Lp_coe_fn.symm,
end
lemma Lp_meas_to_Lp_trim_lie_symm_to_Lp [one_le_p : fact (1 ≤ p)] [normed_space ℝ F]
(hm : m ≤ m0) (f : α → F) (hf : mem_ℒp f p (μ.trim hm)) :
((Lp_meas_to_Lp_trim_lie F ℝ p μ hm).symm (hf.to_Lp f) : Lp F p μ)
= (mem_ℒp_of_mem_ℒp_trim hm hf).to_Lp f :=
begin
ext1,
rw ← Lp_meas_coe,
refine (Lp_trim_to_Lp_meas_ae_eq hm _).trans _,
exact (ae_eq_of_ae_eq_trim (mem_ℒp.coe_fn_to_Lp hf)).trans (mem_ℒp.coe_fn_to_Lp _).symm,
end
end strongly_measurable
end Lp_meas
section induction
variables {m m0 : measurable_space α} {μ : measure α} [fact (1 ≤ p)] [normed_space ℝ F]
/-- Auxiliary lemma for `Lp.induction_strongly_measurable`. -/
@[elab_as_eliminator]
lemma Lp.induction_strongly_measurable_aux (hm : m ≤ m0) (hp_ne_top : p ≠ ∞) (P : Lp F p μ → Prop)
(h_ind : ∀ (c : F) {s : set α} (hs : measurable_set[m] s) (hμs : μ s < ∞),
P (Lp.simple_func.indicator_const p (hm s hs) hμs.ne c))
(h_add : ∀ ⦃f g⦄, ∀ hf : mem_ℒp f p μ, ∀ hg : mem_ℒp g p μ,
∀ hfm : ae_strongly_measurable' m f μ, ∀ hgm : ae_strongly_measurable' m g μ,
disjoint (function.support f) (function.support g) →
P (hf.to_Lp f) → P (hg.to_Lp g) → P ((hf.to_Lp f) + (hg.to_Lp g)))
(h_closed : is_closed {f : Lp_meas F ℝ m p μ | P f}) :
∀ f : Lp F p μ, ae_strongly_measurable' m f μ → P f :=
begin
intros f hf,
let f' := (⟨f, hf⟩ : Lp_meas F ℝ m p μ),
let g := Lp_meas_to_Lp_trim_lie F ℝ p μ hm f',
have hfg : f' = (Lp_meas_to_Lp_trim_lie F ℝ p μ hm).symm g,
by simp only [linear_isometry_equiv.symm_apply_apply],
change P ↑f',
rw hfg,
refine @Lp.induction α F m _ p (μ.trim hm) _ hp_ne_top
(λ g, P ((Lp_meas_to_Lp_trim_lie F ℝ p μ hm).symm g)) _ _ _ g,
{ intros b t ht hμt,
rw [Lp.simple_func.coe_indicator_const,
Lp_meas_to_Lp_trim_lie_symm_indicator ht hμt.ne b],
have hμt' : μ t < ∞, from (le_trim hm).trans_lt hμt,
specialize h_ind b ht hμt',
rwa Lp.simple_func.coe_indicator_const at h_ind, },
{ intros f g hf hg h_disj hfP hgP,
rw linear_isometry_equiv.map_add,
push_cast,
have h_eq : ∀ (f : α → F) (hf : mem_ℒp f p (μ.trim hm)),
((Lp_meas_to_Lp_trim_lie F ℝ p μ hm).symm (mem_ℒp.to_Lp f hf) : Lp F p μ)
= (mem_ℒp_of_mem_ℒp_trim hm hf).to_Lp f,
from Lp_meas_to_Lp_trim_lie_symm_to_Lp hm,
rw h_eq f hf at hfP ⊢,
rw h_eq g hg at hgP ⊢,
exact h_add (mem_ℒp_of_mem_ℒp_trim hm hf) (mem_ℒp_of_mem_ℒp_trim hm hg)
(ae_strongly_measurable'_of_ae_strongly_measurable'_trim hm hf.ae_strongly_measurable)
(ae_strongly_measurable'_of_ae_strongly_measurable'_trim hm hg.ae_strongly_measurable)
h_disj hfP hgP, },
{ change is_closed ((Lp_meas_to_Lp_trim_lie F ℝ p μ hm).symm ⁻¹' {g : Lp_meas F ℝ m p μ | P ↑g}),
exact is_closed.preimage (linear_isometry_equiv.continuous _) h_closed, },
end
/-- To prove something for an `Lp` function a.e. strongly measurable with respect to a
sub-σ-algebra `m` in a normed space, it suffices to show that
* the property holds for (multiples of) characteristic functions which are measurable w.r.t. `m`;
* is closed under addition;
* the set of functions in `Lp` strongly measurable w.r.t. `m` for which the property holds is
closed.
-/
@[elab_as_eliminator]
lemma Lp.induction_strongly_measurable (hm : m ≤ m0) (hp_ne_top : p ≠ ∞) (P : Lp F p μ → Prop)
(h_ind : ∀ (c : F) {s : set α} (hs : measurable_set[m] s) (hμs : μ s < ∞),
P (Lp.simple_func.indicator_const p (hm s hs) hμs.ne c))
(h_add : ∀ ⦃f g⦄, ∀ hf : mem_ℒp f p μ, ∀ hg : mem_ℒp g p μ,
∀ hfm : strongly_measurable[m] f, ∀ hgm : strongly_measurable[m] g,
disjoint (function.support f) (function.support g) →
P (hf.to_Lp f) → P (hg.to_Lp g) → P ((hf.to_Lp f) + (hg.to_Lp g)))
(h_closed : is_closed {f : Lp_meas F ℝ m p μ | P f}) :
∀ f : Lp F p μ, ae_strongly_measurable' m f μ → P f :=
begin
intros f hf,
suffices h_add_ae : ∀ ⦃f g⦄, ∀ hf : mem_ℒp f p μ, ∀ hg : mem_ℒp g p μ,
∀ hfm : ae_strongly_measurable' m f μ, ∀ hgm : ae_strongly_measurable' m g μ,
disjoint (function.support f) (function.support g) →
P (hf.to_Lp f) → P (hg.to_Lp g) → P ((hf.to_Lp f) + (hg.to_Lp g)),
from Lp.induction_strongly_measurable_aux hm hp_ne_top P h_ind h_add_ae h_closed f hf,
intros f g hf hg hfm hgm h_disj hPf hPg,
let s_f : set α := function.support (hfm.mk f),
have hs_f : measurable_set[m] s_f := hfm.strongly_measurable_mk.measurable_set_support,
have hs_f_eq : s_f =ᵐ[μ] function.support f := hfm.ae_eq_mk.symm.support,
let s_g : set α := function.support (hgm.mk g),
have hs_g : measurable_set[m] s_g := hgm.strongly_measurable_mk.measurable_set_support,
have hs_g_eq : s_g =ᵐ[μ] function.support g := hgm.ae_eq_mk.symm.support,
have h_inter_empty : ((s_f ∩ s_g) : set α) =ᵐ[μ] (∅ : set α),
{ refine (hs_f_eq.inter hs_g_eq).trans _,
suffices : function.support f ∩ function.support g = ∅, by rw this,
exact set.disjoint_iff_inter_eq_empty.mp h_disj, },
let f' := (s_f \ s_g).indicator (hfm.mk f),
have hff' : f =ᵐ[μ] f',
{ have : s_f \ s_g =ᵐ[μ] s_f,
{ rw [← set.diff_inter_self_eq_diff, set.inter_comm],
refine ((ae_eq_refl s_f).diff h_inter_empty).trans _,
rw set.diff_empty, },
refine ((indicator_ae_eq_of_ae_eq_set this).trans _).symm,
rw set.indicator_support,
exact hfm.ae_eq_mk.symm, },
have hf'_meas : strongly_measurable[m] f',
from hfm.strongly_measurable_mk.indicator (hs_f.diff hs_g),
have hf'_Lp : mem_ℒp f' p μ := hf.ae_eq hff',
let g' := (s_g \ s_f).indicator (hgm.mk g),
have hgg' : g =ᵐ[μ] g',
{ have : s_g \ s_f =ᵐ[μ] s_g,
{ rw [← set.diff_inter_self_eq_diff],
refine ((ae_eq_refl s_g).diff h_inter_empty).trans _,
rw set.diff_empty, },
refine ((indicator_ae_eq_of_ae_eq_set this).trans _).symm,
rw set.indicator_support,
exact hgm.ae_eq_mk.symm, },
have hg'_meas : strongly_measurable[m] g',
from hgm.strongly_measurable_mk.indicator (hs_g.diff hs_f),
have hg'_Lp : mem_ℒp g' p μ := hg.ae_eq hgg',
have h_disj : disjoint (function.support f') (function.support g'),
{ have : disjoint (s_f \ s_g) (s_g \ s_f) := disjoint_sdiff_sdiff,
exact this.mono set.support_indicator_subset set.support_indicator_subset, },
rw ← mem_ℒp.to_Lp_congr hf'_Lp hf hff'.symm at ⊢ hPf,
rw ← mem_ℒp.to_Lp_congr hg'_Lp hg hgg'.symm at ⊢ hPg,
exact h_add hf'_Lp hg'_Lp hf'_meas hg'_meas h_disj hPf hPg,
end
/-- To prove something for an arbitrary `mem_ℒp` function a.e. strongly measurable with respect
to a sub-σ-algebra `m` in a normed space, it suffices to show that
* the property holds for (multiples of) characteristic functions which are measurable w.r.t. `m`;
* is closed under addition;
* the set of functions in the `Lᵖ` space strongly measurable w.r.t. `m` for which the property
holds is closed.
* the property is closed under the almost-everywhere equal relation.
-/
@[elab_as_eliminator]
lemma mem_ℒp.induction_strongly_measurable (hm : m ≤ m0) (hp_ne_top : p ≠ ∞)
(P : (α → F) → Prop)
(h_ind : ∀ (c : F) ⦃s⦄, measurable_set[m] s → μ s < ∞ → P (s.indicator (λ _, c)))
(h_add : ∀ ⦃f g : α → F⦄, disjoint (function.support f) (function.support g)
→ mem_ℒp f p μ → mem_ℒp g p μ → strongly_measurable[m] f → strongly_measurable[m] g →
P f → P g → P (f + g))
(h_closed : is_closed {f : Lp_meas F ℝ m p μ | P f} )
(h_ae : ∀ ⦃f g⦄, f =ᵐ[μ] g → mem_ℒp f p μ → P f → P g) :
∀ ⦃f : α → F⦄ (hf : mem_ℒp f p μ) (hfm : ae_strongly_measurable' m f μ), P f :=
begin
intros f hf hfm,
let f_Lp := hf.to_Lp f,
have hfm_Lp : ae_strongly_measurable' m f_Lp μ, from hfm.congr hf.coe_fn_to_Lp.symm,
refine h_ae (hf.coe_fn_to_Lp) (Lp.mem_ℒp _) _,
change P f_Lp,
refine Lp.induction_strongly_measurable hm hp_ne_top (λ f, P ⇑f) _ _ h_closed f_Lp hfm_Lp,
{ intros c s hs hμs,
rw Lp.simple_func.coe_indicator_const,
refine h_ae (indicator_const_Lp_coe_fn).symm _ (h_ind c hs hμs),
exact mem_ℒp_indicator_const p (hm s hs) c (or.inr hμs.ne), },
{ intros f g hf_mem hg_mem hfm hgm h_disj hfP hgP,
have hfP' : P f := h_ae (hf_mem.coe_fn_to_Lp) (Lp.mem_ℒp _) hfP,
have hgP' : P g := h_ae (hg_mem.coe_fn_to_Lp) (Lp.mem_ℒp _) hgP,
specialize h_add h_disj hf_mem hg_mem hfm hgm hfP' hgP',
refine h_ae _ (hf_mem.add hg_mem) h_add,
exact ((hf_mem.coe_fn_to_Lp).symm.add (hg_mem.coe_fn_to_Lp).symm).trans
(Lp.coe_fn_add _ _).symm, },
end
end induction
section uniqueness_of_conditional_expectation
/-! ## Uniqueness of the conditional expectation -/
variables {m m0 : measurable_space α} {μ : measure α}
lemma Lp_meas.ae_eq_zero_of_forall_set_integral_eq_zero
(hm : m ≤ m0) (f : Lp_meas E' 𝕜 m p μ) (hp_ne_zero : p ≠ 0) (hp_ne_top : p ≠ ∞)
(hf_int_finite : ∀ s, measurable_set[m] s → μ s < ∞ → integrable_on f s μ)
(hf_zero : ∀ s : set α, measurable_set[m] s → μ s < ∞ → ∫ x in s, f x ∂μ = 0) :
f =ᵐ[μ] 0 :=
begin
obtain ⟨g, hg_sm, hfg⟩ := Lp_meas.ae_fin_strongly_measurable' hm f hp_ne_zero hp_ne_top,
refine hfg.trans _,
refine ae_eq_zero_of_forall_set_integral_eq_of_fin_strongly_measurable_trim hm _ _ hg_sm,
{ intros s hs hμs,
have hfg_restrict : f =ᵐ[μ.restrict s] g, from ae_restrict_of_ae hfg,
rw [integrable_on, integrable_congr hfg_restrict.symm],
exact hf_int_finite s hs hμs, },
{ intros s hs hμs,
have hfg_restrict : f =ᵐ[μ.restrict s] g, from ae_restrict_of_ae hfg,
rw integral_congr_ae hfg_restrict.symm,
exact hf_zero s hs hμs, },
end
include 𝕜
lemma Lp.ae_eq_zero_of_forall_set_integral_eq_zero'
(hm : m ≤ m0) (f : Lp E' p μ) (hp_ne_zero : p ≠ 0) (hp_ne_top : p ≠ ∞)
(hf_int_finite : ∀ s, measurable_set[m] s → μ s < ∞ → integrable_on f s μ)
(hf_zero : ∀ s : set α, measurable_set[m] s → μ s < ∞ → ∫ x in s, f x ∂μ = 0)
(hf_meas : ae_strongly_measurable' m f μ) :
f =ᵐ[μ] 0 :=
begin
let f_meas : Lp_meas E' 𝕜 m p μ := ⟨f, hf_meas⟩,
have hf_f_meas : f =ᵐ[μ] f_meas, by simp only [coe_fn_coe_base', subtype.coe_mk],
refine hf_f_meas.trans _,
refine Lp_meas.ae_eq_zero_of_forall_set_integral_eq_zero hm f_meas hp_ne_zero hp_ne_top _ _,
{ intros s hs hμs,
have hfg_restrict : f =ᵐ[μ.restrict s] f_meas, from ae_restrict_of_ae hf_f_meas,
rw [integrable_on, integrable_congr hfg_restrict.symm],
exact hf_int_finite s hs hμs, },
{ intros s hs hμs,
have hfg_restrict : f =ᵐ[μ.restrict s] f_meas, from ae_restrict_of_ae hf_f_meas,
rw integral_congr_ae hfg_restrict.symm,
exact hf_zero s hs hμs, },
end
/-- **Uniqueness of the conditional expectation** -/
lemma Lp.ae_eq_of_forall_set_integral_eq'
(hm : m ≤ m0) (f g : Lp E' p μ) (hp_ne_zero : p ≠ 0) (hp_ne_top : p ≠ ∞)
(hf_int_finite : ∀ s, measurable_set[m] s → μ s < ∞ → integrable_on f s μ)
(hg_int_finite : ∀ s, measurable_set[m] s → μ s < ∞ → integrable_on g s μ)
(hfg : ∀ s : set α, measurable_set[m] s → μ s < ∞ → ∫ x in s, f x ∂μ = ∫ x in s, g x ∂μ)
(hf_meas : ae_strongly_measurable' m f μ) (hg_meas : ae_strongly_measurable' m g μ) :
f =ᵐ[μ] g :=
begin
suffices h_sub : ⇑(f-g) =ᵐ[μ] 0,
by { rw ← sub_ae_eq_zero, exact (Lp.coe_fn_sub f g).symm.trans h_sub, },
have hfg' : ∀ s : set α, measurable_set[m] s → μ s < ∞ → ∫ x in s, (f - g) x ∂μ = 0,
{ intros s hs hμs,
rw integral_congr_ae (ae_restrict_of_ae (Lp.coe_fn_sub f g)),
rw integral_sub' (hf_int_finite s hs hμs) (hg_int_finite s hs hμs),
exact sub_eq_zero.mpr (hfg s hs hμs), },
have hfg_int : ∀ s, measurable_set[m] s → μ s < ∞ → integrable_on ⇑(f-g) s μ,
{ intros s hs hμs,
rw [integrable_on, integrable_congr (ae_restrict_of_ae (Lp.coe_fn_sub f g))],
exact (hf_int_finite s hs hμs).sub (hg_int_finite s hs hμs), },
have hfg_meas : ae_strongly_measurable' m ⇑(f - g) μ,
from ae_strongly_measurable'.congr (hf_meas.sub hg_meas) (Lp.coe_fn_sub f g).symm,
exact Lp.ae_eq_zero_of_forall_set_integral_eq_zero' hm (f-g) hp_ne_zero hp_ne_top hfg_int hfg'
hfg_meas,
end
omit 𝕜
lemma ae_eq_of_forall_set_integral_eq_of_sigma_finite' (hm : m ≤ m0) [sigma_finite (μ.trim hm)]
{f g : α → F'}
(hf_int_finite : ∀ s, measurable_set[m] s → μ s < ∞ → integrable_on f s μ)
(hg_int_finite : ∀ s, measurable_set[m] s → μ s < ∞ → integrable_on g s μ)
(hfg_eq : ∀ s : set α, measurable_set[m] s → μ s < ∞ → ∫ x in s, f x ∂μ = ∫ x in s, g x ∂μ)
(hfm : ae_strongly_measurable' m f μ) (hgm : ae_strongly_measurable' m g μ) :
f =ᵐ[μ] g :=
begin
rw ← ae_eq_trim_iff_of_ae_strongly_measurable' hm hfm hgm,
have hf_mk_int_finite : ∀ s, measurable_set[m] s → μ.trim hm s < ∞ →
@integrable_on _ _ m _ (hfm.mk f) s (μ.trim hm),
{ intros s hs hμs,
rw trim_measurable_set_eq hm hs at hμs,
rw [integrable_on, restrict_trim hm _ hs],
refine integrable.trim hm _ hfm.strongly_measurable_mk,
exact integrable.congr (hf_int_finite s hs hμs) (ae_restrict_of_ae hfm.ae_eq_mk), },
have hg_mk_int_finite : ∀ s, measurable_set[m] s → μ.trim hm s < ∞ →
@integrable_on _ _ m _ (hgm.mk g) s (μ.trim hm),
{ intros s hs hμs,
rw trim_measurable_set_eq hm hs at hμs,
rw [integrable_on, restrict_trim hm _ hs],
refine integrable.trim hm _ hgm.strongly_measurable_mk,
exact integrable.congr (hg_int_finite s hs hμs) (ae_restrict_of_ae hgm.ae_eq_mk), },
have hfg_mk_eq : ∀ s : set α, measurable_set[m] s → μ.trim hm s < ∞ →
∫ x in s, (hfm.mk f x) ∂(μ.trim hm) = ∫ x in s, (hgm.mk g x) ∂(μ.trim hm),
{ intros s hs hμs,
rw trim_measurable_set_eq hm hs at hμs,
rw [restrict_trim hm _ hs, ← integral_trim hm hfm.strongly_measurable_mk,
← integral_trim hm hgm.strongly_measurable_mk,
integral_congr_ae (ae_restrict_of_ae hfm.ae_eq_mk.symm),
integral_congr_ae (ae_restrict_of_ae hgm.ae_eq_mk.symm)],
exact hfg_eq s hs hμs, },
exact ae_eq_of_forall_set_integral_eq_of_sigma_finite hf_mk_int_finite hg_mk_int_finite hfg_mk_eq,
end
end uniqueness_of_conditional_expectation
section integral_norm_le
variables {m m0 : measurable_space α} {μ : measure α} {s : set α}
/-- Let `m` be a sub-σ-algebra of `m0`, `f` a `m0`-measurable function and `g` a `m`-measurable
function, such that their integrals coincide on `m`-measurable sets with finite measure.
Then `∫ x in s, ∥g x∥ ∂μ ≤ ∫ x in s, ∥f x∥ ∂μ` on all `m`-measurable sets with finite measure. -/
lemma integral_norm_le_of_forall_fin_meas_integral_eq (hm : m ≤ m0) {f g : α → ℝ}
(hf : strongly_measurable f) (hfi : integrable_on f s μ)
(hg : strongly_measurable[m] g) (hgi : integrable_on g s μ)
(hgf : ∀ t, measurable_set[m] t → μ t < ∞ → ∫ x in t, g x ∂μ = ∫ x in t, f x ∂μ)
(hs : measurable_set[m] s) (hμs : μ s ≠ ∞) :
∫ x in s, ∥g x∥ ∂μ ≤ ∫ x in s, ∥f x∥ ∂μ :=
begin
rw [integral_norm_eq_pos_sub_neg (hg.mono hm) hgi, integral_norm_eq_pos_sub_neg hf hfi],
have h_meas_nonneg_g : measurable_set[m] {x | 0 ≤ g x},
from (@strongly_measurable_const _ _ m _ _).measurable_set_le hg,
have h_meas_nonneg_f : measurable_set {x | 0 ≤ f x},
from strongly_measurable_const.measurable_set_le hf,
have h_meas_nonpos_g : measurable_set[m] {x | g x ≤ 0},
from hg.measurable_set_le (@strongly_measurable_const _ _ m _ _),
have h_meas_nonpos_f : measurable_set {x | f x ≤ 0},
from hf.measurable_set_le strongly_measurable_const,
refine sub_le_sub _ _,
{ rw [measure.restrict_restrict (hm _ h_meas_nonneg_g),
measure.restrict_restrict h_meas_nonneg_f,
hgf _ (@measurable_set.inter α m _ _ h_meas_nonneg_g hs)
((measure_mono (set.inter_subset_right _ _)).trans_lt (lt_top_iff_ne_top.mpr hμs)),
← measure.restrict_restrict (hm _ h_meas_nonneg_g),
← measure.restrict_restrict h_meas_nonneg_f],
exact set_integral_le_nonneg (hm _ h_meas_nonneg_g) hf hfi, },
{ rw [measure.restrict_restrict (hm _ h_meas_nonpos_g),
measure.restrict_restrict h_meas_nonpos_f,
hgf _ (@measurable_set.inter α m _ _ h_meas_nonpos_g hs)
((measure_mono (set.inter_subset_right _ _)).trans_lt (lt_top_iff_ne_top.mpr hμs)),
← measure.restrict_restrict (hm _ h_meas_nonpos_g),
← measure.restrict_restrict h_meas_nonpos_f],
exact set_integral_nonpos_le (hm _ h_meas_nonpos_g) hf hfi, },
end
/-- Let `m` be a sub-σ-algebra of `m0`, `f` a `m0`-measurable function and `g` a `m`-measurable
function, such that their integrals coincide on `m`-measurable sets with finite measure.
Then `∫⁻ x in s, ∥g x∥₊ ∂μ ≤ ∫⁻ x in s, ∥f x∥₊ ∂μ` on all `m`-measurable sets with finite
measure. -/
lemma lintegral_nnnorm_le_of_forall_fin_meas_integral_eq (hm : m ≤ m0) {f g : α → ℝ}
(hf : strongly_measurable f) (hfi : integrable_on f s μ)
(hg : strongly_measurable[m] g) (hgi : integrable_on g s μ)
(hgf : ∀ t, measurable_set[m] t → μ t < ∞ → ∫ x in t, g x ∂μ = ∫ x in t, f x ∂μ)
(hs : measurable_set[m] s) (hμs : μ s ≠ ∞) :
∫⁻ x in s, ∥g x∥₊ ∂μ ≤ ∫⁻ x in s, ∥f x∥₊ ∂μ :=
begin
rw [← of_real_integral_norm_eq_lintegral_nnnorm hfi,
← of_real_integral_norm_eq_lintegral_nnnorm hgi, ennreal.of_real_le_of_real_iff],
{ exact integral_norm_le_of_forall_fin_meas_integral_eq hm hf hfi hg hgi hgf hs hμs, },
{ exact integral_nonneg (λ x, norm_nonneg _), },
end
end integral_norm_le
/-! ## Conditional expectation in L2
We define a conditional expectation in `L2`: it is the orthogonal projection on the subspace
`Lp_meas`. -/
section condexp_L2
variables [complete_space E] {m m0 : measurable_space α} {μ : measure α}
{s t : set α}
local notation `⟪`x`, `y`⟫` := @inner 𝕜 E _ x y
local notation `⟪`x`, `y`⟫₂` := @inner 𝕜 (α →₂[μ] E) _ x y
variables (𝕜)
/-- Conditional expectation of a function in L2 with respect to a sigma-algebra -/
def condexp_L2 (hm : m ≤ m0) : (α →₂[μ] E) →L[𝕜] (Lp_meas E 𝕜 m 2 μ) :=
@orthogonal_projection 𝕜 (α →₂[μ] E) _ _ (Lp_meas E 𝕜 m 2 μ)
(by { haveI : fact (m ≤ m0) := ⟨hm⟩, exact infer_instance, })
variables {𝕜}
lemma ae_strongly_measurable'_condexp_L2 (hm : m ≤ m0) (f : α →₂[μ] E) :
ae_strongly_measurable' m (condexp_L2 𝕜 hm f) μ :=
Lp_meas.ae_strongly_measurable' _
lemma integrable_on_condexp_L2_of_measure_ne_top (hm : m ≤ m0) (hμs : μ s ≠ ∞) (f : α →₂[μ] E) :
integrable_on (condexp_L2 𝕜 hm f) s μ :=
integrable_on_Lp_of_measure_ne_top ((condexp_L2 𝕜 hm f) : α →₂[μ] E)
fact_one_le_two_ennreal.elim hμs
lemma integrable_condexp_L2_of_is_finite_measure (hm : m ≤ m0) [is_finite_measure μ]
{f : α →₂[μ] E} :
integrable (condexp_L2 𝕜 hm f) μ :=
integrable_on_univ.mp $ integrable_on_condexp_L2_of_measure_ne_top hm (measure_ne_top _ _) f
lemma norm_condexp_L2_le_one (hm : m ≤ m0) : ∥@condexp_L2 α E 𝕜 _ _ _ _ _ μ hm∥ ≤ 1 :=
by { haveI : fact (m ≤ m0) := ⟨hm⟩, exact orthogonal_projection_norm_le _, }
lemma norm_condexp_L2_le (hm : m ≤ m0) (f : α →₂[μ] E) : ∥condexp_L2 𝕜 hm f∥ ≤ ∥f∥ :=
((@condexp_L2 _ E 𝕜 _ _ _ _ _ μ hm).le_op_norm f).trans
(mul_le_of_le_one_left (norm_nonneg _) (norm_condexp_L2_le_one hm))
lemma snorm_condexp_L2_le (hm : m ≤ m0) (f : α →₂[μ] E) :
snorm (condexp_L2 𝕜 hm f) 2 μ ≤ snorm f 2 μ :=
begin
rw [Lp_meas_coe, ← ennreal.to_real_le_to_real (Lp.snorm_ne_top _) (Lp.snorm_ne_top _),
← Lp.norm_def, ← Lp.norm_def, submodule.norm_coe],
exact norm_condexp_L2_le hm f,
end
lemma norm_condexp_L2_coe_le (hm : m ≤ m0) (f : α →₂[μ] E) :
∥(condexp_L2 𝕜 hm f : α →₂[μ] E)∥ ≤ ∥f∥ :=
begin
rw [Lp.norm_def, Lp.norm_def, ← Lp_meas_coe],
refine (ennreal.to_real_le_to_real _ (Lp.snorm_ne_top _)).mpr (snorm_condexp_L2_le hm f),
exact Lp.snorm_ne_top _,
end
lemma inner_condexp_L2_left_eq_right (hm : m ≤ m0) {f g : α →₂[μ] E} :
⟪(condexp_L2 𝕜 hm f : α →₂[μ] E), g⟫₂ = ⟪f, (condexp_L2 𝕜 hm g : α →₂[μ] E)⟫₂ :=
by { haveI : fact (m ≤ m0) := ⟨hm⟩, exact inner_orthogonal_projection_left_eq_right _ f g, }
lemma condexp_L2_indicator_of_measurable (hm : m ≤ m0)
(hs : measurable_set[m] s) (hμs : μ s ≠ ∞) (c : E) :
(condexp_L2 𝕜 hm (indicator_const_Lp 2 (hm s hs) hμs c) : α →₂[μ] E)
= indicator_const_Lp 2 (hm s hs) hμs c :=
begin
rw condexp_L2,
haveI : fact (m ≤ m0) := ⟨hm⟩,
have h_mem : indicator_const_Lp 2 (hm s hs) hμs c ∈ Lp_meas E 𝕜 m 2 μ,
from mem_Lp_meas_indicator_const_Lp hm hs hμs,
let ind := (⟨indicator_const_Lp 2 (hm s hs) hμs c, h_mem⟩ : Lp_meas E 𝕜 m 2 μ),
have h_coe_ind : (ind : α →₂[μ] E) = indicator_const_Lp 2 (hm s hs) hμs c, by refl,
have h_orth_mem := orthogonal_projection_mem_subspace_eq_self ind,
rw [← h_coe_ind, h_orth_mem],
end
lemma inner_condexp_L2_eq_inner_fun (hm : m ≤ m0) (f g : α →₂[μ] E)
(hg : ae_strongly_measurable' m g μ) :
⟪(condexp_L2 𝕜 hm f : α →₂[μ] E), g⟫₂ = ⟪f, g⟫₂ :=
begin
symmetry,
rw [← sub_eq_zero, ← inner_sub_left, condexp_L2],
simp only [mem_Lp_meas_iff_ae_strongly_measurable'.mpr hg, orthogonal_projection_inner_eq_zero],
end
section real
variables {hm : m ≤ m0}
lemma integral_condexp_L2_eq_of_fin_meas_real (f : Lp 𝕜 2 μ) (hs : measurable_set[m] s)
(hμs : μ s ≠ ∞) :
∫ x in s, condexp_L2 𝕜 hm f x ∂μ = ∫ x in s, f x ∂μ :=
begin
rw ← L2.inner_indicator_const_Lp_one (hm s hs) hμs,
have h_eq_inner : ∫ x in s, condexp_L2 𝕜 hm f x ∂μ
= inner (indicator_const_Lp 2 (hm s hs) hμs (1 : 𝕜)) (condexp_L2 𝕜 hm f),
{ rw L2.inner_indicator_const_Lp_one (hm s hs) hμs,
congr, },
rw [h_eq_inner, ← inner_condexp_L2_left_eq_right, condexp_L2_indicator_of_measurable hm hs hμs],
end
lemma lintegral_nnnorm_condexp_L2_le (hs : measurable_set[m] s) (hμs : μ s ≠ ∞) (f : Lp ℝ 2 μ) :
∫⁻ x in s, ∥condexp_L2 ℝ hm f x∥₊ ∂μ ≤ ∫⁻ x in s, ∥f x∥₊ ∂μ :=
begin
let h_meas := Lp_meas.ae_strongly_measurable' (condexp_L2 ℝ hm f),
let g := h_meas.some,
have hg_meas : strongly_measurable[m] g, from h_meas.some_spec.1,
have hg_eq : g =ᵐ[μ] condexp_L2 ℝ hm f, from h_meas.some_spec.2.symm,
have hg_eq_restrict : g =ᵐ[μ.restrict s] condexp_L2 ℝ hm f, from ae_restrict_of_ae hg_eq,
have hg_nnnorm_eq : (λ x, (∥g x∥₊ : ℝ≥0∞))
=ᵐ[μ.restrict s] (λ x, (∥condexp_L2 ℝ hm f x∥₊ : ℝ≥0∞)),
{ refine hg_eq_restrict.mono (λ x hx, _),
dsimp only,
rw hx, },
rw lintegral_congr_ae hg_nnnorm_eq.symm,
refine lintegral_nnnorm_le_of_forall_fin_meas_integral_eq hm
(Lp.strongly_measurable f) _ _ _ _ hs hμs,
{ exact integrable_on_Lp_of_measure_ne_top f fact_one_le_two_ennreal.elim hμs, },
{ exact hg_meas, },
{ rw [integrable_on, integrable_congr hg_eq_restrict],
exact integrable_on_condexp_L2_of_measure_ne_top hm hμs f, },
{ intros t ht hμt,
rw ← integral_condexp_L2_eq_of_fin_meas_real f ht hμt.ne,
exact set_integral_congr_ae (hm t ht) (hg_eq.mono (λ x hx _, hx)), },
end
lemma condexp_L2_ae_eq_zero_of_ae_eq_zero (hs : measurable_set[m] s) (hμs : μ s ≠ ∞)
{f : Lp ℝ 2 μ} (hf : f =ᵐ[μ.restrict s] 0) :
condexp_L2 ℝ hm f =ᵐ[μ.restrict s] 0 :=
begin
suffices h_nnnorm_eq_zero : ∫⁻ x in s, ∥condexp_L2 ℝ hm f x∥₊ ∂μ = 0,
{ rw lintegral_eq_zero_iff at h_nnnorm_eq_zero,
refine h_nnnorm_eq_zero.mono (λ x hx, _),
dsimp only at hx,
rw pi.zero_apply at hx ⊢,
{ rwa [ennreal.coe_eq_zero, nnnorm_eq_zero] at hx, },
{ refine measurable.coe_nnreal_ennreal (measurable.nnnorm _),
rw Lp_meas_coe,
exact (Lp.strongly_measurable _).measurable }, },
refine le_antisymm _ (zero_le _),
refine (lintegral_nnnorm_condexp_L2_le hs hμs f).trans (le_of_eq _),
rw lintegral_eq_zero_iff,
{ refine hf.mono (λ x hx, _),
dsimp only,
rw hx,
simp, },
{ exact (Lp.strongly_measurable _).ennnorm, },
end
lemma lintegral_nnnorm_condexp_L2_indicator_le_real
(hs : measurable_set s) (hμs : μ s ≠ ∞) (ht : measurable_set[m] t) (hμt : μ t ≠ ∞) :
∫⁻ a in t, ∥condexp_L2 ℝ hm (indicator_const_Lp 2 hs hμs (1 : ℝ)) a∥₊ ∂μ ≤ μ (s ∩ t) :=
begin
refine (lintegral_nnnorm_condexp_L2_le ht hμt _).trans (le_of_eq _),
have h_eq : ∫⁻ x in t, ∥(indicator_const_Lp 2 hs hμs (1 : ℝ)) x∥₊ ∂μ
= ∫⁻ x in t, s.indicator (λ x, (1 : ℝ≥0∞)) x ∂μ,
{ refine lintegral_congr_ae (ae_restrict_of_ae _),
refine (@indicator_const_Lp_coe_fn _ _ _ 2 _ _ _ hs hμs (1 : ℝ)).mono (λ x hx, _),
rw hx,
classical,
simp_rw set.indicator_apply,
split_ifs; simp, },
rw [h_eq, lintegral_indicator _ hs, lintegral_const, measure.restrict_restrict hs],
simp only [one_mul, set.univ_inter, measurable_set.univ, measure.restrict_apply],
end
end real
/-- `condexp_L2` commutes with taking inner products with constants. See the lemma
`condexp_L2_comp_continuous_linear_map` for a more general result about commuting with continuous
linear maps. -/
lemma condexp_L2_const_inner (hm : m ≤ m0) (f : Lp E 2 μ) (c : E) :
condexp_L2 𝕜 hm (((Lp.mem_ℒp f).const_inner c).to_Lp (λ a, ⟪c, f a⟫))
=ᵐ[μ] λ a, ⟪c, condexp_L2 𝕜 hm f a⟫ :=
begin
rw Lp_meas_coe,
have h_mem_Lp : mem_ℒp (λ a, ⟪c, condexp_L2 𝕜 hm f a⟫) 2 μ,
{ refine mem_ℒp.const_inner _ _, rw Lp_meas_coe, exact Lp.mem_ℒp _, },
have h_eq : h_mem_Lp.to_Lp _ =ᵐ[μ] λ a, ⟪c, condexp_L2 𝕜 hm f a⟫, from h_mem_Lp.coe_fn_to_Lp,
refine eventually_eq.trans _ h_eq,
refine Lp.ae_eq_of_forall_set_integral_eq' hm _ _ ennreal.zero_lt_two.ne.symm ennreal.coe_ne_top
(λ s hs hμs, integrable_on_condexp_L2_of_measure_ne_top hm hμs.ne _) _ _ _ _,
{ intros s hs hμs,
rw [integrable_on, integrable_congr (ae_restrict_of_ae h_eq)],
exact (integrable_on_condexp_L2_of_measure_ne_top hm hμs.ne _).const_inner _, },
{ intros s hs hμs,
rw [← Lp_meas_coe, integral_condexp_L2_eq_of_fin_meas_real _ hs hμs.ne,
integral_congr_ae (ae_restrict_of_ae h_eq), Lp_meas_coe,
← L2.inner_indicator_const_Lp_eq_set_integral_inner 𝕜 ↑(condexp_L2 𝕜 hm f) (hm s hs) c hμs.ne,
← inner_condexp_L2_left_eq_right, condexp_L2_indicator_of_measurable,
L2.inner_indicator_const_Lp_eq_set_integral_inner 𝕜 f (hm s hs) c hμs.ne,
set_integral_congr_ae (hm s hs)
((mem_ℒp.coe_fn_to_Lp ((Lp.mem_ℒp f).const_inner c)).mono (λ x hx hxs, hx))], },
{ rw ← Lp_meas_coe, exact Lp_meas.ae_strongly_measurable' _, },
{ refine ae_strongly_measurable'.congr _ h_eq.symm,
exact (Lp_meas.ae_strongly_measurable' _).const_inner _, },
end
/-- `condexp_L2` verifies the equality of integrals defining the conditional expectation. -/
lemma integral_condexp_L2_eq (hm : m ≤ m0)
(f : Lp E' 2 μ) (hs : measurable_set[m] s) (hμs : μ s ≠ ∞) :
∫ x in s, condexp_L2 𝕜 hm f x ∂μ = ∫ x in s, f x ∂μ :=
begin
rw [← sub_eq_zero, Lp_meas_coe, ← integral_sub'
(integrable_on_Lp_of_measure_ne_top _ fact_one_le_two_ennreal.elim hμs)
(integrable_on_Lp_of_measure_ne_top _ fact_one_le_two_ennreal.elim hμs)],
refine integral_eq_zero_of_forall_integral_inner_eq_zero _ _ _,
{ rw integrable_congr (ae_restrict_of_ae (Lp.coe_fn_sub ↑(condexp_L2 𝕜 hm f) f).symm),
exact integrable_on_Lp_of_measure_ne_top _ fact_one_le_two_ennreal.elim hμs, },
intro c,
simp_rw [pi.sub_apply, inner_sub_right],
rw integral_sub
((integrable_on_Lp_of_measure_ne_top _ fact_one_le_two_ennreal.elim hμs).const_inner c)
((integrable_on_Lp_of_measure_ne_top _ fact_one_le_two_ennreal.elim hμs).const_inner c),
have h_ae_eq_f := mem_ℒp.coe_fn_to_Lp ((Lp.mem_ℒp f).const_inner c),
rw [← Lp_meas_coe, sub_eq_zero,
← set_integral_congr_ae (hm s hs) ((condexp_L2_const_inner hm f c).mono (λ x hx _, hx)),
← set_integral_congr_ae (hm s hs) (h_ae_eq_f.mono (λ x hx _, hx))],
exact integral_condexp_L2_eq_of_fin_meas_real _ hs hμs,
end
variables {E'' 𝕜' : Type*} [is_R_or_C 𝕜']
[inner_product_space 𝕜' E''] [complete_space E''] [normed_space ℝ E'']
variables (𝕜 𝕜')
lemma condexp_L2_comp_continuous_linear_map (hm : m ≤ m0) (T : E' →L[ℝ] E'') (f : α →₂[μ] E') :
(condexp_L2 𝕜' hm (T.comp_Lp f) : α →₂[μ] E'') =ᵐ[μ] T.comp_Lp (condexp_L2 𝕜 hm f : α →₂[μ] E') :=
begin
refine Lp.ae_eq_of_forall_set_integral_eq' hm _ _ ennreal.zero_lt_two.ne.symm ennreal.coe_ne_top
(λ s hs hμs, integrable_on_condexp_L2_of_measure_ne_top hm hμs.ne _)
(λ s hs hμs, integrable_on_Lp_of_measure_ne_top _ fact_one_le_two_ennreal.elim hμs.ne)
_ _ _,
{ intros s hs hμs,
rw [T.set_integral_comp_Lp _ (hm s hs),
T.integral_comp_comm
(integrable_on_Lp_of_measure_ne_top _ fact_one_le_two_ennreal.elim hμs.ne),
← Lp_meas_coe, ← Lp_meas_coe, integral_condexp_L2_eq hm f hs hμs.ne,
integral_condexp_L2_eq hm (T.comp_Lp f) hs hμs.ne, T.set_integral_comp_Lp _ (hm s hs),
T.integral_comp_comm
(integrable_on_Lp_of_measure_ne_top f fact_one_le_two_ennreal.elim hμs.ne)], },
{ rw ← Lp_meas_coe, exact Lp_meas.ae_strongly_measurable' _, },
{ have h_coe := T.coe_fn_comp_Lp (condexp_L2 𝕜 hm f : α →₂[μ] E'),
rw ← eventually_eq at h_coe,
refine ae_strongly_measurable'.congr _ h_coe.symm,
exact (Lp_meas.ae_strongly_measurable' (condexp_L2 𝕜 hm f)).continuous_comp T.continuous, },
end
variables {𝕜 𝕜'}
section condexp_L2_indicator
variables (𝕜)
lemma condexp_L2_indicator_ae_eq_smul (hm : m ≤ m0) (hs : measurable_set s) (hμs : μ s ≠ ∞)
(x : E') :
condexp_L2 𝕜 hm (indicator_const_Lp 2 hs hμs x)
=ᵐ[μ] λ a, (condexp_L2 ℝ hm (indicator_const_Lp 2 hs hμs (1 : ℝ)) a) • x :=
begin
rw indicator_const_Lp_eq_to_span_singleton_comp_Lp hs hμs x,
have h_comp := condexp_L2_comp_continuous_linear_map ℝ 𝕜 hm (to_span_singleton ℝ x)
(indicator_const_Lp 2 hs hμs (1 : ℝ)),
rw ← Lp_meas_coe at h_comp,
refine h_comp.trans _,
exact (to_span_singleton ℝ x).coe_fn_comp_Lp _,
end
lemma condexp_L2_indicator_eq_to_span_singleton_comp (hm : m ≤ m0) (hs : measurable_set s)
(hμs : μ s ≠ ∞) (x : E') :
(condexp_L2 𝕜 hm (indicator_const_Lp 2 hs hμs x) : α →₂[μ] E')
= (to_span_singleton ℝ x).comp_Lp (condexp_L2 ℝ hm (indicator_const_Lp 2 hs hμs (1 : ℝ))) :=
begin
ext1,
rw ← Lp_meas_coe,
refine (condexp_L2_indicator_ae_eq_smul 𝕜 hm hs hμs x).trans _,
have h_comp := (to_span_singleton ℝ x).coe_fn_comp_Lp
(condexp_L2 ℝ hm (indicator_const_Lp 2 hs hμs (1 : ℝ)) : α →₂[μ] ℝ),
rw ← eventually_eq at h_comp,
refine eventually_eq.trans _ h_comp.symm,
refine eventually_of_forall (λ y, _),
refl,
end
variables {𝕜}
lemma set_lintegral_nnnorm_condexp_L2_indicator_le (hm : m ≤ m0) (hs : measurable_set s)
(hμs : μ s ≠ ∞) (x : E') {t : set α} (ht : measurable_set[m] t) (hμt : μ t ≠ ∞) :
∫⁻ a in t, ∥condexp_L2 𝕜 hm (indicator_const_Lp 2 hs hμs x) a∥₊ ∂μ ≤ μ (s ∩ t) * ∥x∥₊ :=
calc ∫⁻ a in t, ∥condexp_L2 𝕜 hm (indicator_const_Lp 2 hs hμs x) a∥₊ ∂μ
= ∫⁻ a in t, ∥(condexp_L2 ℝ hm (indicator_const_Lp 2 hs hμs (1 : ℝ)) a) • x∥₊ ∂μ :
set_lintegral_congr_fun (hm t ht)
((condexp_L2_indicator_ae_eq_smul 𝕜 hm hs hμs x).mono (λ a ha hat, by rw ha))
... = ∫⁻ a in t, ∥condexp_L2 ℝ hm (indicator_const_Lp 2 hs hμs (1 : ℝ)) a∥₊ ∂μ * ∥x∥₊ :
begin
simp_rw [nnnorm_smul, ennreal.coe_mul],
rw [lintegral_mul_const, Lp_meas_coe],
exact (Lp.strongly_measurable _).ennnorm
end
... ≤ μ (s ∩ t) * ∥x∥₊ :
ennreal.mul_le_mul (lintegral_nnnorm_condexp_L2_indicator_le_real hs hμs ht hμt) le_rfl
lemma lintegral_nnnorm_condexp_L2_indicator_le (hm : m ≤ m0) (hs : measurable_set s)
(hμs : μ s ≠ ∞) (x : E') [sigma_finite (μ.trim hm)] :
∫⁻ a, ∥condexp_L2 𝕜 hm (indicator_const_Lp 2 hs hμs x) a∥₊ ∂μ ≤ μ s * ∥x∥₊ :=
begin
refine lintegral_le_of_forall_fin_meas_le' hm (μ s * ∥x∥₊) _ (λ t ht hμt, _),
{ rw Lp_meas_coe,
exact (Lp.ae_strongly_measurable _).ennnorm },
refine (set_lintegral_nnnorm_condexp_L2_indicator_le hm hs hμs x ht hμt).trans _,
refine ennreal.mul_le_mul _ le_rfl,
exact measure_mono (set.inter_subset_left _ _),
end
/-- If the measure `μ.trim hm` is sigma-finite, then the conditional expectation of a measurable set
with finite measure is integrable. -/
lemma integrable_condexp_L2_indicator (hm : m ≤ m0) [sigma_finite (μ.trim hm)]
(hs : measurable_set s) (hμs : μ s ≠ ∞) (x : E') :
integrable (condexp_L2 𝕜 hm (indicator_const_Lp 2 hs hμs x)) μ :=
begin
refine integrable_of_forall_fin_meas_le' hm (μ s * ∥x∥₊)
(ennreal.mul_lt_top hμs ennreal.coe_ne_top) _ _,
{ rw Lp_meas_coe, exact Lp.ae_strongly_measurable _, },
{ refine λ t ht hμt, (set_lintegral_nnnorm_condexp_L2_indicator_le hm hs hμs x ht hμt).trans _,
exact ennreal.mul_le_mul (measure_mono (set.inter_subset_left _ _)) le_rfl, },
end
end condexp_L2_indicator
section condexp_ind_smul
variables [normed_space ℝ G] {hm : m ≤ m0}
/-- Conditional expectation of the indicator of a measurable set with finite measure, in L2. -/
def condexp_ind_smul (hm : m ≤ m0) (hs : measurable_set s) (hμs : μ s ≠ ∞) (x : G) : Lp G 2 μ :=
(to_span_singleton ℝ x).comp_LpL 2 μ (condexp_L2 ℝ hm (indicator_const_Lp 2 hs hμs (1 : ℝ)))
lemma ae_strongly_measurable'_condexp_ind_smul
(hm : m ≤ m0) (hs : measurable_set s) (hμs : μ s ≠ ∞) (x : G) :
ae_strongly_measurable' m (condexp_ind_smul hm hs hμs x) μ :=
begin
have h : ae_strongly_measurable' m (condexp_L2 ℝ hm (indicator_const_Lp 2 hs hμs (1 : ℝ))) μ,
from ae_strongly_measurable'_condexp_L2 _ _,
rw condexp_ind_smul,
suffices : ae_strongly_measurable' m
((to_span_singleton ℝ x) ∘ (condexp_L2 ℝ hm (indicator_const_Lp 2 hs hμs (1 : ℝ)))) μ,
{ refine ae_strongly_measurable'.congr this _,
refine eventually_eq.trans _ (coe_fn_comp_LpL _ _).symm,
rw Lp_meas_coe, },
exact ae_strongly_measurable'.continuous_comp (to_span_singleton ℝ x).continuous h,
end
lemma condexp_ind_smul_add (hs : measurable_set s) (hμs : μ s ≠ ∞) (x y : G) :
condexp_ind_smul hm hs hμs (x + y)
= condexp_ind_smul hm hs hμs x + condexp_ind_smul hm hs hμs y :=
by { simp_rw [condexp_ind_smul], rw [to_span_singleton_add, add_comp_LpL, add_apply], }
lemma condexp_ind_smul_smul (hs : measurable_set s) (hμs : μ s ≠ ∞) (c : ℝ) (x : G) :
condexp_ind_smul hm hs hμs (c • x) = c • condexp_ind_smul hm hs hμs x :=
by { simp_rw [condexp_ind_smul], rw [to_span_singleton_smul, smul_comp_LpL, smul_apply], }
lemma condexp_ind_smul_smul' [normed_space ℝ F] [smul_comm_class ℝ 𝕜 F] (hs : measurable_set s)
(hμs : μ s ≠ ∞) (c : 𝕜) (x : F) :
condexp_ind_smul hm hs hμs (c • x) = c • condexp_ind_smul hm hs hμs x :=
by rw [condexp_ind_smul, condexp_ind_smul, to_span_singleton_smul',
(to_span_singleton ℝ x).smul_comp_LpL_apply c
↑(condexp_L2 ℝ hm (indicator_const_Lp 2 hs hμs (1 : ℝ)))]
lemma condexp_ind_smul_ae_eq_smul (hm : m ≤ m0) (hs : measurable_set s) (hμs : μ s ≠ ∞) (x : G) :
condexp_ind_smul hm hs hμs x
=ᵐ[μ] λ a, (condexp_L2 ℝ hm (indicator_const_Lp 2 hs hμs (1 : ℝ)) a) • x :=
(to_span_singleton ℝ x).coe_fn_comp_LpL _
lemma set_lintegral_nnnorm_condexp_ind_smul_le (hm : m ≤ m0) (hs : measurable_set s)
(hμs : μ s ≠ ∞) (x : G) {t : set α} (ht : measurable_set[m] t) (hμt : μ t ≠ ∞) :
∫⁻ a in t, ∥condexp_ind_smul hm hs hμs x a∥₊ ∂μ ≤ μ (s ∩ t) * ∥x∥₊ :=
calc ∫⁻ a in t, ∥condexp_ind_smul hm hs hμs x a∥₊ ∂μ
= ∫⁻ a in t, ∥condexp_L2 ℝ hm (indicator_const_Lp 2 hs hμs (1 : ℝ)) a • x∥₊ ∂μ :
set_lintegral_congr_fun (hm t ht)
((condexp_ind_smul_ae_eq_smul hm hs hμs x).mono (λ a ha hat, by rw ha ))
... = ∫⁻ a in t, ∥condexp_L2 ℝ hm (indicator_const_Lp 2 hs hμs (1 : ℝ)) a∥₊ ∂μ * ∥x∥₊ :
begin
simp_rw [nnnorm_smul, ennreal.coe_mul],
rw [lintegral_mul_const, Lp_meas_coe],
exact (Lp.strongly_measurable _).ennnorm
end
... ≤ μ (s ∩ t) * ∥x∥₊ :
ennreal.mul_le_mul (lintegral_nnnorm_condexp_L2_indicator_le_real hs hμs ht hμt) le_rfl
lemma lintegral_nnnorm_condexp_ind_smul_le (hm : m ≤ m0) (hs : measurable_set s)
(hμs : μ s ≠ ∞) (x : G) [sigma_finite (μ.trim hm)] :
∫⁻ a, ∥condexp_ind_smul hm hs hμs x a∥₊ ∂μ ≤ μ s * ∥x∥₊ :=
begin
refine lintegral_le_of_forall_fin_meas_le' hm (μ s * ∥x∥₊) _ (λ t ht hμt, _),
{ exact (Lp.ae_strongly_measurable _).ennnorm },
refine (set_lintegral_nnnorm_condexp_ind_smul_le hm hs hμs x ht hμt).trans _,
refine ennreal.mul_le_mul _ le_rfl,
exact measure_mono (set.inter_subset_left _ _),
end
/-- If the measure `μ.trim hm` is sigma-finite, then the conditional expectation of a measurable set
with finite measure is integrable. -/
lemma integrable_condexp_ind_smul (hm : m ≤ m0) [sigma_finite (μ.trim hm)]
(hs : measurable_set s) (hμs : μ s ≠ ∞) (x : G) :
integrable (condexp_ind_smul hm hs hμs x) μ :=
begin
refine integrable_of_forall_fin_meas_le' hm (μ s * ∥x∥₊)
(ennreal.mul_lt_top hμs ennreal.coe_ne_top) _ _,
{ exact Lp.ae_strongly_measurable _, },
{ refine λ t ht hμt, (set_lintegral_nnnorm_condexp_ind_smul_le hm hs hμs x ht hμt).trans _,
exact ennreal.mul_le_mul (measure_mono (set.inter_subset_left _ _)) le_rfl, },
end
lemma condexp_ind_smul_empty {x : G} :
condexp_ind_smul hm measurable_set.empty
((@measure_empty _ _ μ).le.trans_lt ennreal.coe_lt_top).ne x = 0 :=
begin
rw [condexp_ind_smul, indicator_const_empty],
simp only [coe_fn_coe_base, submodule.coe_zero, continuous_linear_map.map_zero],
end
lemma set_integral_condexp_L2_indicator (hs : measurable_set[m] s) (ht : measurable_set t)
(hμs : μ s ≠ ∞) (hμt : μ t ≠ ∞) :
∫ x in s, (condexp_L2 ℝ hm (indicator_const_Lp 2 ht hμt (1 : ℝ))) x ∂μ = (μ (t ∩ s)).to_real :=
calc ∫ x in s, (condexp_L2 ℝ hm (indicator_const_Lp 2 ht hμt (1 : ℝ))) x ∂μ
= ∫ x in s, indicator_const_Lp 2 ht hμt (1 : ℝ) x ∂μ :
@integral_condexp_L2_eq α _ ℝ _ _ _ _ _ _ _ _ hm (indicator_const_Lp 2 ht hμt (1 : ℝ)) hs hμs
... = (μ (t ∩ s)).to_real • 1 : set_integral_indicator_const_Lp (hm s hs) ht hμt (1 : ℝ)
... = (μ (t ∩ s)).to_real : by rw [smul_eq_mul, mul_one]
lemma set_integral_condexp_ind_smul (hs : measurable_set[m] s) (ht : measurable_set t)
(hμs : μ s ≠ ∞) (hμt : μ t ≠ ∞) (x : G') :
∫ a in s, (condexp_ind_smul hm ht hμt x) a ∂μ = (μ (t ∩ s)).to_real • x :=
calc ∫ a in s, (condexp_ind_smul hm ht hμt x) a ∂μ
= (∫ a in s, (condexp_L2 ℝ hm (indicator_const_Lp 2 ht hμt (1 : ℝ)) a • x) ∂μ) :
set_integral_congr_ae (hm s hs) ((condexp_ind_smul_ae_eq_smul hm ht hμt x).mono (λ x hx hxs, hx))
... = (∫ a in s, condexp_L2 ℝ hm (indicator_const_Lp 2 ht hμt (1 : ℝ)) a ∂μ) • x :
integral_smul_const _ x
... = (μ (t ∩ s)).to_real • x :
by rw set_integral_condexp_L2_indicator hs ht hμs hμt
lemma condexp_L2_indicator_nonneg (hm : m ≤ m0) (hs : measurable_set s) (hμs : μ s ≠ ∞)
[sigma_finite (μ.trim hm)] :
0 ≤ᵐ[μ] condexp_L2 ℝ hm (indicator_const_Lp 2 hs hμs (1 : ℝ)) :=
begin
have h : ae_strongly_measurable' m (condexp_L2 ℝ hm (indicator_const_Lp 2 hs hμs (1 : ℝ))) μ,
from ae_strongly_measurable'_condexp_L2 _ _,
refine eventually_le.trans_eq _ h.ae_eq_mk.symm,
refine @ae_le_of_ae_le_trim _ _ _ _ _ _ hm _ _ _,
refine ae_nonneg_of_forall_set_integral_nonneg_of_sigma_finite _ _,
{ intros t ht hμt,
refine @integrable.integrable_on _ _ m _ _ _ _ _,
refine integrable.trim hm _ _,
{ rw integrable_congr h.ae_eq_mk.symm,
exact integrable_condexp_L2_indicator hm hs hμs _, },
{ exact h.strongly_measurable_mk, }, },
{ intros t ht hμt,
rw ← set_integral_trim hm h.strongly_measurable_mk ht,
have h_ae : ∀ᵐ x ∂μ, x ∈ t → h.mk _ x = condexp_L2 ℝ hm (indicator_const_Lp 2 hs hμs (1 : ℝ)) x,
{ filter_upwards [h.ae_eq_mk] with x hx,
exact λ _, hx.symm, },
rw [set_integral_congr_ae (hm t ht) h_ae,
set_integral_condexp_L2_indicator ht hs ((le_trim hm).trans_lt hμt).ne hμs],
exact ennreal.to_real_nonneg, },
end
lemma condexp_ind_smul_nonneg {E} [normed_lattice_add_comm_group E] [normed_space ℝ E]
[ordered_smul ℝ E] [sigma_finite (μ.trim hm)]
(hs : measurable_set s) (hμs : μ s ≠ ∞) (x : E) (hx : 0 ≤ x) :
0 ≤ᵐ[μ] condexp_ind_smul hm hs hμs x :=
begin
refine eventually_le.trans_eq _ (condexp_ind_smul_ae_eq_smul hm hs hμs x).symm,
filter_upwards [condexp_L2_indicator_nonneg hm hs hμs] with a ha,
exact smul_nonneg ha hx,
end
end condexp_ind_smul
end condexp_L2
section condexp_ind
/-! ## Conditional expectation of an indicator as a continuous linear map.
The goal of this section is to build
`condexp_ind (hm : m ≤ m0) (μ : measure α) (s : set s) : G →L[ℝ] α →₁[μ] G`, which
takes `x : G` to the conditional expectation of the indicator of the set `s` with value `x`,
seen as an element of `α →₁[μ] G`.
-/
variables {m m0 : measurable_space α} {μ : measure α} {s t : set α} [normed_space ℝ G]
section condexp_ind_L1_fin
/-- Conditional expectation of the indicator of a measurable set with finite measure,
as a function in L1. -/
def condexp_ind_L1_fin (hm : m ≤ m0) [sigma_finite (μ.trim hm)] (hs : measurable_set s)
(hμs : μ s ≠ ∞) (x : G) : α →₁[μ] G :=
(integrable_condexp_ind_smul hm hs hμs x).to_L1 _
lemma condexp_ind_L1_fin_ae_eq_condexp_ind_smul (hm : m ≤ m0) [sigma_finite (μ.trim hm)]
(hs : measurable_set s) (hμs : μ s ≠ ∞) (x : G) :
condexp_ind_L1_fin hm hs hμs x =ᵐ[μ] condexp_ind_smul hm hs hμs x :=
(integrable_condexp_ind_smul hm hs hμs x).coe_fn_to_L1
variables {hm : m ≤ m0} [sigma_finite (μ.trim hm)]
lemma condexp_ind_L1_fin_add (hs : measurable_set s) (hμs : μ s ≠ ∞) (x y : G) :
condexp_ind_L1_fin hm hs hμs (x + y)
= condexp_ind_L1_fin hm hs hμs x + condexp_ind_L1_fin hm hs hμs y :=
begin
ext1,
refine (mem_ℒp.coe_fn_to_Lp _).trans _,
refine eventually_eq.trans _ (Lp.coe_fn_add _ _).symm,
refine eventually_eq.trans _
(eventually_eq.add (mem_ℒp.coe_fn_to_Lp _).symm (mem_ℒp.coe_fn_to_Lp _).symm),
rw condexp_ind_smul_add,
refine (Lp.coe_fn_add _ _).trans (eventually_of_forall (λ a, _)),
refl,
end
lemma condexp_ind_L1_fin_smul (hs : measurable_set s) (hμs : μ s ≠ ∞) (c : ℝ) (x : G) :
condexp_ind_L1_fin hm hs hμs (c • x) = c • condexp_ind_L1_fin hm hs hμs x :=
begin
ext1,
refine (mem_ℒp.coe_fn_to_Lp _).trans _,
refine eventually_eq.trans _ (Lp.coe_fn_smul _ _).symm,
rw condexp_ind_smul_smul hs hμs c x,
refine (Lp.coe_fn_smul _ _).trans _,
refine (condexp_ind_L1_fin_ae_eq_condexp_ind_smul hm hs hμs x).mono (λ y hy, _),
rw [pi.smul_apply, pi.smul_apply, hy],
end
lemma condexp_ind_L1_fin_smul' [normed_space ℝ F] [smul_comm_class ℝ 𝕜 F]
(hs : measurable_set s) (hμs : μ s ≠ ∞) (c : 𝕜) (x : F) :
condexp_ind_L1_fin hm hs hμs (c • x) = c • condexp_ind_L1_fin hm hs hμs x :=
begin
ext1,
refine (mem_ℒp.coe_fn_to_Lp _).trans _,
refine eventually_eq.trans _ (Lp.coe_fn_smul _ _).symm,
rw condexp_ind_smul_smul' hs hμs c x,
refine (Lp.coe_fn_smul _ _).trans _,
refine (condexp_ind_L1_fin_ae_eq_condexp_ind_smul hm hs hμs x).mono (λ y hy, _),
rw [pi.smul_apply, pi.smul_apply, hy],
end
lemma norm_condexp_ind_L1_fin_le (hs : measurable_set s) (hμs : μ s ≠ ∞) (x : G) :
∥condexp_ind_L1_fin hm hs hμs x∥ ≤ (μ s).to_real * ∥x∥ :=
begin
have : 0 ≤ ∫ (a : α), ∥condexp_ind_L1_fin hm hs hμs x a∥ ∂μ,
from integral_nonneg (λ a, norm_nonneg _),
rw [L1.norm_eq_integral_norm, ← ennreal.to_real_of_real (norm_nonneg x), ← ennreal.to_real_mul,
← ennreal.to_real_of_real this, ennreal.to_real_le_to_real ennreal.of_real_ne_top
(ennreal.mul_ne_top hμs ennreal.of_real_ne_top),
of_real_integral_norm_eq_lintegral_nnnorm],
swap, { rw [← mem_ℒp_one_iff_integrable], exact Lp.mem_ℒp _, },
have h_eq : ∫⁻ a, ∥condexp_ind_L1_fin hm hs hμs x a∥₊ ∂μ
= ∫⁻ a, ∥condexp_ind_smul hm hs hμs x a∥₊ ∂μ,
{ refine lintegral_congr_ae _,
refine (condexp_ind_L1_fin_ae_eq_condexp_ind_smul hm hs hμs x).mono (λ z hz, _),
dsimp only,
rw hz, },
rw [h_eq, of_real_norm_eq_coe_nnnorm],
exact lintegral_nnnorm_condexp_ind_smul_le hm hs hμs x,
end
lemma condexp_ind_L1_fin_disjoint_union (hs : measurable_set s) (ht : measurable_set t)
(hμs : μ s ≠ ∞) (hμt : μ t ≠ ∞) (hst : s ∩ t = ∅) (x : G) :
condexp_ind_L1_fin hm (hs.union ht) ((measure_union_le s t).trans_lt
(lt_top_iff_ne_top.mpr (ennreal.add_ne_top.mpr ⟨hμs, hμt⟩))).ne x
= condexp_ind_L1_fin hm hs hμs x + condexp_ind_L1_fin hm ht hμt x :=
begin
ext1,
have hμst := ((measure_union_le s t).trans_lt
(lt_top_iff_ne_top.mpr (ennreal.add_ne_top.mpr ⟨hμs, hμt⟩))).ne,
refine (condexp_ind_L1_fin_ae_eq_condexp_ind_smul hm (hs.union ht) hμst x).trans _,
refine eventually_eq.trans _ (Lp.coe_fn_add _ _).symm,
have hs_eq := condexp_ind_L1_fin_ae_eq_condexp_ind_smul hm hs hμs x,
have ht_eq := condexp_ind_L1_fin_ae_eq_condexp_ind_smul hm ht hμt x,
refine eventually_eq.trans _ (eventually_eq.add hs_eq.symm ht_eq.symm),
rw condexp_ind_smul,
rw indicator_const_Lp_disjoint_union hs ht hμs hμt hst (1 : ℝ),
rw (condexp_L2 ℝ hm).map_add,
push_cast,
rw ((to_span_singleton ℝ x).comp_LpL 2 μ).map_add,
refine (Lp.coe_fn_add _ _).trans _,
refine eventually_of_forall (λ y, _),
refl,
end
end condexp_ind_L1_fin
open_locale classical
section condexp_ind_L1
/-- Conditional expectation of the indicator of a set, as a function in L1. Its value for sets
which are not both measurable and of finite measure is not used: we set it to 0. -/
def condexp_ind_L1 {m m0 : measurable_space α} (hm : m ≤ m0) (μ : measure α) (s : set α)
[sigma_finite (μ.trim hm)] (x : G) :
α →₁[μ] G :=
if hs : measurable_set s ∧ μ s ≠ ∞ then condexp_ind_L1_fin hm hs.1 hs.2 x else 0
variables {hm : m ≤ m0} [sigma_finite (μ.trim hm)]
lemma condexp_ind_L1_of_measurable_set_of_measure_ne_top (hs : measurable_set s) (hμs : μ s ≠ ∞)
(x : G) :
condexp_ind_L1 hm μ s x = condexp_ind_L1_fin hm hs hμs x :=
by simp only [condexp_ind_L1, and.intro hs hμs, dif_pos, ne.def, not_false_iff, and_self]
lemma condexp_ind_L1_of_measure_eq_top (hμs : μ s = ∞) (x : G) :
condexp_ind_L1 hm μ s x = 0 :=
by simp only [condexp_ind_L1, hμs, eq_self_iff_true, not_true, ne.def, dif_neg, not_false_iff,
and_false]
lemma condexp_ind_L1_of_not_measurable_set (hs : ¬ measurable_set s) (x : G) :
condexp_ind_L1 hm μ s x = 0 :=
by simp only [condexp_ind_L1, hs, dif_neg, not_false_iff, false_and]
lemma condexp_ind_L1_add (x y : G) :
condexp_ind_L1 hm μ s (x + y) = condexp_ind_L1 hm μ s x + condexp_ind_L1 hm μ s y :=
begin
by_cases hs : measurable_set s,
swap, {simp_rw condexp_ind_L1_of_not_measurable_set hs, rw zero_add, },
by_cases hμs : μ s = ∞,
{ simp_rw condexp_ind_L1_of_measure_eq_top hμs, rw zero_add, },
{ simp_rw condexp_ind_L1_of_measurable_set_of_measure_ne_top hs hμs,
exact condexp_ind_L1_fin_add hs hμs x y, },
end
lemma condexp_ind_L1_smul (c : ℝ) (x : G) :
condexp_ind_L1 hm μ s (c • x) = c • condexp_ind_L1 hm μ s x :=
begin
by_cases hs : measurable_set s,
swap, {simp_rw condexp_ind_L1_of_not_measurable_set hs, rw smul_zero, },
by_cases hμs : μ s = ∞,
{ simp_rw condexp_ind_L1_of_measure_eq_top hμs, rw smul_zero, },
{ simp_rw condexp_ind_L1_of_measurable_set_of_measure_ne_top hs hμs,
exact condexp_ind_L1_fin_smul hs hμs c x, },
end
lemma condexp_ind_L1_smul' [normed_space ℝ F] [smul_comm_class ℝ 𝕜 F] (c : 𝕜) (x : F) :
condexp_ind_L1 hm μ s (c • x) = c • condexp_ind_L1 hm μ s x :=
begin
by_cases hs : measurable_set s,
swap, {simp_rw condexp_ind_L1_of_not_measurable_set hs, rw smul_zero, },
by_cases hμs : μ s = ∞,
{ simp_rw condexp_ind_L1_of_measure_eq_top hμs, rw smul_zero, },
{ simp_rw condexp_ind_L1_of_measurable_set_of_measure_ne_top hs hμs,
exact condexp_ind_L1_fin_smul' hs hμs c x, },
end
lemma norm_condexp_ind_L1_le (x : G) :
∥condexp_ind_L1 hm μ s x∥ ≤ (μ s).to_real * ∥x∥ :=
begin
by_cases hs : measurable_set s,
swap, {simp_rw condexp_ind_L1_of_not_measurable_set hs, rw Lp.norm_zero,
exact mul_nonneg ennreal.to_real_nonneg (norm_nonneg _), },
by_cases hμs : μ s = ∞,
{ rw [condexp_ind_L1_of_measure_eq_top hμs x, Lp.norm_zero],
exact mul_nonneg ennreal.to_real_nonneg (norm_nonneg _), },
{ rw condexp_ind_L1_of_measurable_set_of_measure_ne_top hs hμs x,
exact norm_condexp_ind_L1_fin_le hs hμs x, },
end
lemma continuous_condexp_ind_L1 : continuous (λ x : G, condexp_ind_L1 hm μ s x) :=
continuous_of_linear_of_bound condexp_ind_L1_add condexp_ind_L1_smul norm_condexp_ind_L1_le
lemma condexp_ind_L1_disjoint_union (hs : measurable_set s) (ht : measurable_set t)
(hμs : μ s ≠ ∞) (hμt : μ t ≠ ∞) (hst : s ∩ t = ∅) (x : G) :
condexp_ind_L1 hm μ (s ∪ t) x = condexp_ind_L1 hm μ s x + condexp_ind_L1 hm μ t x :=
begin
have hμst : μ (s ∪ t) ≠ ∞, from ((measure_union_le s t).trans_lt
(lt_top_iff_ne_top.mpr (ennreal.add_ne_top.mpr ⟨hμs, hμt⟩))).ne,
rw [condexp_ind_L1_of_measurable_set_of_measure_ne_top hs hμs x,
condexp_ind_L1_of_measurable_set_of_measure_ne_top ht hμt x,
condexp_ind_L1_of_measurable_set_of_measure_ne_top (hs.union ht) hμst x],
exact condexp_ind_L1_fin_disjoint_union hs ht hμs hμt hst x,
end
end condexp_ind_L1
/-- Conditional expectation of the indicator of a set, as a linear map from `G` to L1. -/
def condexp_ind {m m0 : measurable_space α} (hm : m ≤ m0) (μ : measure α) [sigma_finite (μ.trim hm)]
(s : set α) : G →L[ℝ] α →₁[μ] G :=
{ to_fun := condexp_ind_L1 hm μ s,
map_add' := condexp_ind_L1_add,
map_smul' := condexp_ind_L1_smul,
cont := continuous_condexp_ind_L1, }
lemma condexp_ind_ae_eq_condexp_ind_smul (hm : m ≤ m0) [sigma_finite (μ.trim hm)]
(hs : measurable_set s) (hμs : μ s ≠ ∞) (x : G) :
condexp_ind hm μ s x =ᵐ[μ] condexp_ind_smul hm hs hμs x :=
begin
refine eventually_eq.trans _ (condexp_ind_L1_fin_ae_eq_condexp_ind_smul hm hs hμs x),
simp [condexp_ind, condexp_ind_L1, hs, hμs],
end
variables {hm : m ≤ m0} [sigma_finite (μ.trim hm)]
lemma ae_strongly_measurable'_condexp_ind (hs : measurable_set s) (hμs : μ s ≠ ∞) (x : G) :
ae_strongly_measurable' m (condexp_ind hm μ s x) μ :=
ae_strongly_measurable'.congr (ae_strongly_measurable'_condexp_ind_smul hm hs hμs x)
(condexp_ind_ae_eq_condexp_ind_smul hm hs hμs x).symm
@[simp] lemma condexp_ind_empty : condexp_ind hm μ ∅ = (0 : G →L[ℝ] α →₁[μ] G) :=
begin
ext1,
ext1,
refine (condexp_ind_ae_eq_condexp_ind_smul hm measurable_set.empty (by simp) x).trans _,
rw condexp_ind_smul_empty,
refine (Lp.coe_fn_zero G 2 μ).trans _,
refine eventually_eq.trans _ (Lp.coe_fn_zero G 1 μ).symm,
refl,
end
lemma condexp_ind_smul' [normed_space ℝ F] [smul_comm_class ℝ 𝕜 F] (c : 𝕜) (x : F) :
condexp_ind hm μ s (c • x) = c • condexp_ind hm μ s x :=
condexp_ind_L1_smul' c x
lemma norm_condexp_ind_apply_le (x : G) : ∥condexp_ind hm μ s x∥ ≤ (μ s).to_real * ∥x∥ :=
norm_condexp_ind_L1_le x
lemma norm_condexp_ind_le : ∥(condexp_ind hm μ s : G →L[ℝ] α →₁[μ] G)∥ ≤ (μ s).to_real :=
continuous_linear_map.op_norm_le_bound _ ennreal.to_real_nonneg norm_condexp_ind_apply_le
lemma condexp_ind_disjoint_union_apply (hs : measurable_set s) (ht : measurable_set t)
(hμs : μ s ≠ ∞) (hμt : μ t ≠ ∞) (hst : s ∩ t = ∅) (x : G) :
condexp_ind hm μ (s ∪ t) x = condexp_ind hm μ s x + condexp_ind hm μ t x :=
condexp_ind_L1_disjoint_union hs ht hμs hμt hst x
lemma condexp_ind_disjoint_union (hs : measurable_set s) (ht : measurable_set t) (hμs : μ s ≠ ∞)
(hμt : μ t ≠ ∞) (hst : s ∩ t = ∅) :
(condexp_ind hm μ (s ∪ t) : G →L[ℝ] α →₁[μ] G) = condexp_ind hm μ s + condexp_ind hm μ t :=
by { ext1, push_cast, exact condexp_ind_disjoint_union_apply hs ht hμs hμt hst x, }
variables (G)
lemma dominated_fin_meas_additive_condexp_ind (hm : m ≤ m0) (μ : measure α)
[sigma_finite (μ.trim hm)] :
dominated_fin_meas_additive μ (condexp_ind hm μ : set α → G →L[ℝ] α →₁[μ] G) 1 :=
⟨λ s t, condexp_ind_disjoint_union, λ s _ _, norm_condexp_ind_le.trans (one_mul _).symm.le⟩
variables {G}
lemma set_integral_condexp_ind (hs : measurable_set[m] s) (ht : measurable_set t) (hμs : μ s ≠ ∞)
(hμt : μ t ≠ ∞) (x : G') :
∫ a in s, condexp_ind hm μ t x a ∂μ = (μ (t ∩ s)).to_real • x :=
calc
∫ a in s, condexp_ind hm μ t x a ∂μ = ∫ a in s, condexp_ind_smul hm ht hμt x a ∂μ :
set_integral_congr_ae (hm s hs)
((condexp_ind_ae_eq_condexp_ind_smul hm ht hμt x).mono (λ x hx hxs, hx))
... = (μ (t ∩ s)).to_real • x : set_integral_condexp_ind_smul hs ht hμs hμt x
lemma condexp_ind_of_measurable (hs : measurable_set[m] s) (hμs : μ s ≠ ∞) (c : G) :
condexp_ind hm μ s c = indicator_const_Lp 1 (hm s hs) hμs c :=
begin
ext1,
refine eventually_eq.trans _ indicator_const_Lp_coe_fn.symm,
refine (condexp_ind_ae_eq_condexp_ind_smul hm (hm s hs) hμs c).trans _,
refine (condexp_ind_smul_ae_eq_smul hm (hm s hs) hμs c).trans _,
rw [Lp_meas_coe, condexp_L2_indicator_of_measurable hm hs hμs (1 : ℝ)],
refine (@indicator_const_Lp_coe_fn α _ _ 2 μ _ s (hm s hs) hμs (1 : ℝ)).mono (λ x hx, _),
dsimp only,
rw hx,
by_cases hx_mem : x ∈ s; simp [hx_mem],
end
lemma condexp_ind_nonneg {E} [normed_lattice_add_comm_group E] [normed_space ℝ E] [ordered_smul ℝ E]
(hs : measurable_set s) (hμs : μ s ≠ ∞) (x : E) (hx : 0 ≤ x) :
0 ≤ condexp_ind hm μ s x :=
begin
rw ← coe_fn_le,
refine eventually_le.trans_eq _ (condexp_ind_ae_eq_condexp_ind_smul hm hs hμs x).symm,
exact (coe_fn_zero E 1 μ).trans_le (condexp_ind_smul_nonneg hs hμs x hx),
end
end condexp_ind
section condexp_L1
variables {m m0 : measurable_space α} {μ : measure α}
{hm : m ≤ m0} [sigma_finite (μ.trim hm)] {f g : α → F'} {s : set α}
/-- Conditional expectation of a function as a linear map from `α →₁[μ] F'` to itself. -/
def condexp_L1_clm (hm : m ≤ m0) (μ : measure α) [sigma_finite (μ.trim hm)] :
(α →₁[μ] F') →L[ℝ] α →₁[μ] F' :=
L1.set_to_L1 (dominated_fin_meas_additive_condexp_ind F' hm μ)
lemma condexp_L1_clm_smul (c : 𝕜) (f : α →₁[μ] F') :
condexp_L1_clm hm μ (c • f) = c • condexp_L1_clm hm μ f :=
L1.set_to_L1_smul (dominated_fin_meas_additive_condexp_ind F' hm μ)
(λ c s x, condexp_ind_smul' c x) c f
lemma condexp_L1_clm_indicator_const_Lp (hs : measurable_set s) (hμs : μ s ≠ ∞) (x : F') :
(condexp_L1_clm hm μ) (indicator_const_Lp 1 hs hμs x) = condexp_ind hm μ s x :=
L1.set_to_L1_indicator_const_Lp (dominated_fin_meas_additive_condexp_ind F' hm μ) hs hμs x
lemma condexp_L1_clm_indicator_const (hs : measurable_set s) (hμs : μ s ≠ ∞) (x : F') :
(condexp_L1_clm hm μ) ↑(simple_func.indicator_const 1 hs hμs x) = condexp_ind hm μ s x :=
by { rw Lp.simple_func.coe_indicator_const, exact condexp_L1_clm_indicator_const_Lp hs hμs x, }
/-- Auxiliary lemma used in the proof of `set_integral_condexp_L1_clm`. -/
lemma set_integral_condexp_L1_clm_of_measure_ne_top (f : α →₁[μ] F') (hs : measurable_set[m] s)
(hμs : μ s ≠ ∞) :
∫ x in s, condexp_L1_clm hm μ f x ∂μ = ∫ x in s, f x ∂μ :=
begin
refine Lp.induction ennreal.one_ne_top
(λ f : α →₁[μ] F', ∫ x in s, condexp_L1_clm hm μ f x ∂μ = ∫ x in s, f x ∂μ)
_ _ (is_closed_eq _ _) f,
{ intros x t ht hμt,
simp_rw condexp_L1_clm_indicator_const ht hμt.ne x,
rw [Lp.simple_func.coe_indicator_const, set_integral_indicator_const_Lp (hm _ hs)],
exact set_integral_condexp_ind hs ht hμs hμt.ne x, },
{ intros f g hf_Lp hg_Lp hfg_disj hf hg,
simp_rw (condexp_L1_clm hm μ).map_add,
rw set_integral_congr_ae (hm s hs) ((Lp.coe_fn_add (condexp_L1_clm hm μ (hf_Lp.to_Lp f))
(condexp_L1_clm hm μ (hg_Lp.to_Lp g))).mono (λ x hx hxs, hx)),
rw set_integral_congr_ae (hm s hs) ((Lp.coe_fn_add (hf_Lp.to_Lp f) (hg_Lp.to_Lp g)).mono
(λ x hx hxs, hx)),
simp_rw pi.add_apply,
rw [integral_add (L1.integrable_coe_fn _).integrable_on (L1.integrable_coe_fn _).integrable_on,
integral_add (L1.integrable_coe_fn _).integrable_on (L1.integrable_coe_fn _).integrable_on,
hf, hg], },
{ exact (continuous_set_integral s).comp (condexp_L1_clm hm μ).continuous, },
{ exact continuous_set_integral s, },
end
/-- The integral of the conditional expectation `condexp_L1_clm` over an `m`-measurable set is equal
to the integral of `f` on that set. See also `set_integral_condexp`, the similar statement for
`condexp`. -/
lemma set_integral_condexp_L1_clm (f : α →₁[μ] F') (hs : measurable_set[m] s) :
∫ x in s, condexp_L1_clm hm μ f x ∂μ = ∫ x in s, f x ∂μ :=
begin
let S := spanning_sets (μ.trim hm),
have hS_meas : ∀ i, measurable_set[m] (S i) := measurable_spanning_sets (μ.trim hm),
have hS_meas0 : ∀ i, measurable_set (S i) := λ i, hm _ (hS_meas i),
have hs_eq : s = ⋃ i, S i ∩ s,
{ simp_rw set.inter_comm,
rw [← set.inter_Union, (Union_spanning_sets (μ.trim hm)), set.inter_univ], },
have hS_finite : ∀ i, μ (S i ∩ s) < ∞,
{ refine λ i, (measure_mono (set.inter_subset_left _ _)).trans_lt _,
have hS_finite_trim := measure_spanning_sets_lt_top (μ.trim hm) i,
rwa trim_measurable_set_eq hm (hS_meas i) at hS_finite_trim, },
have h_mono : monotone (λ i, (S i) ∩ s),
{ intros i j hij x,
simp_rw set.mem_inter_iff,
exact λ h, ⟨monotone_spanning_sets (μ.trim hm) hij h.1, h.2⟩, },
have h_eq_forall : (λ i, ∫ x in (S i) ∩ s, condexp_L1_clm hm μ f x ∂μ)
= λ i, ∫ x in (S i) ∩ s, f x ∂μ,
from funext (λ i, set_integral_condexp_L1_clm_of_measure_ne_top f
(@measurable_set.inter α m _ _ (hS_meas i) hs) (hS_finite i).ne),
have h_right : tendsto (λ i, ∫ x in (S i) ∩ s, f x ∂μ) at_top (𝓝 (∫ x in s, f x ∂μ)),
{ have h := tendsto_set_integral_of_monotone (λ i, (hS_meas0 i).inter (hm s hs)) h_mono
(L1.integrable_coe_fn f).integrable_on,
rwa ← hs_eq at h, },
have h_left : tendsto (λ i, ∫ x in (S i) ∩ s, condexp_L1_clm hm μ f x ∂μ) at_top
(𝓝 (∫ x in s, condexp_L1_clm hm μ f x ∂μ)),
{ have h := tendsto_set_integral_of_monotone (λ i, (hS_meas0 i).inter (hm s hs))
h_mono (L1.integrable_coe_fn (condexp_L1_clm hm μ f)).integrable_on,
rwa ← hs_eq at h, },
rw h_eq_forall at h_left,
exact tendsto_nhds_unique h_left h_right,
end
lemma ae_strongly_measurable'_condexp_L1_clm (f : α →₁[μ] F') :
ae_strongly_measurable' m (condexp_L1_clm hm μ f) μ :=
begin
refine Lp.induction ennreal.one_ne_top
(λ f : α →₁[μ] F', ae_strongly_measurable' m (condexp_L1_clm hm μ f) μ)
_ _ _ f,
{ intros c s hs hμs,
rw condexp_L1_clm_indicator_const hs hμs.ne c,
exact ae_strongly_measurable'_condexp_ind hs hμs.ne c, },
{ intros f g hf hg h_disj hfm hgm,
rw (condexp_L1_clm hm μ).map_add,
refine ae_strongly_measurable'.congr _ (coe_fn_add _ _).symm,
exact ae_strongly_measurable'.add hfm hgm, },
{ have : {f : Lp F' 1 μ | ae_strongly_measurable' m (condexp_L1_clm hm μ f) μ}
= (condexp_L1_clm hm μ) ⁻¹' {f | ae_strongly_measurable' m f μ},
by refl,
rw this,
refine is_closed.preimage (condexp_L1_clm hm μ).continuous _,
exact is_closed_ae_strongly_measurable' hm, },
end
lemma condexp_L1_clm_Lp_meas (f : Lp_meas F' ℝ m 1 μ) :
condexp_L1_clm hm μ (f : α →₁[μ] F') = ↑f :=
begin
let g := Lp_meas_to_Lp_trim_lie F' ℝ 1 μ hm f,
have hfg : f = (Lp_meas_to_Lp_trim_lie F' ℝ 1 μ hm).symm g,
by simp only [linear_isometry_equiv.symm_apply_apply],
rw hfg,
refine @Lp.induction α F' m _ 1 (μ.trim hm) _ ennreal.coe_ne_top
(λ g : α →₁[μ.trim hm] F',
condexp_L1_clm hm μ ((Lp_meas_to_Lp_trim_lie F' ℝ 1 μ hm).symm g : α →₁[μ] F')
= ↑((Lp_meas_to_Lp_trim_lie F' ℝ 1 μ hm).symm g)) _ _ _ g,
{ intros c s hs hμs,
rw [Lp.simple_func.coe_indicator_const, Lp_meas_to_Lp_trim_lie_symm_indicator hs hμs.ne c,
condexp_L1_clm_indicator_const_Lp],
exact condexp_ind_of_measurable hs ((le_trim hm).trans_lt hμs).ne c, },
{ intros f g hf hg hfg_disj hf_eq hg_eq,
rw linear_isometry_equiv.map_add,
push_cast,
rw [map_add, hf_eq, hg_eq], },
{ refine is_closed_eq _ _,
{ refine (condexp_L1_clm hm μ).continuous.comp (continuous_induced_dom.comp _),
exact linear_isometry_equiv.continuous _, },
{ refine continuous_induced_dom.comp _,
exact linear_isometry_equiv.continuous _, }, },
end
lemma condexp_L1_clm_of_ae_strongly_measurable'
(f : α →₁[μ] F') (hfm : ae_strongly_measurable' m f μ) :
condexp_L1_clm hm μ f = f :=
condexp_L1_clm_Lp_meas (⟨f, hfm⟩ : Lp_meas F' ℝ m 1 μ)
/-- Conditional expectation of a function, in L1. Its value is 0 if the function is not
integrable. The function-valued `condexp` should be used instead in most cases. -/
def condexp_L1 (hm : m ≤ m0) (μ : measure α) [sigma_finite (μ.trim hm)] (f : α → F') : α →₁[μ] F' :=
set_to_fun μ (condexp_ind hm μ) (dominated_fin_meas_additive_condexp_ind F' hm μ) f
lemma condexp_L1_undef (hf : ¬ integrable f μ) : condexp_L1 hm μ f = 0 :=
set_to_fun_undef (dominated_fin_meas_additive_condexp_ind F' hm μ) hf
lemma condexp_L1_eq (hf : integrable f μ) :
condexp_L1 hm μ f = condexp_L1_clm hm μ (hf.to_L1 f) :=
set_to_fun_eq (dominated_fin_meas_additive_condexp_ind F' hm μ) hf
lemma condexp_L1_zero : condexp_L1 hm μ (0 : α → F') = 0 :=
set_to_fun_zero _
lemma ae_strongly_measurable'_condexp_L1 {f : α → F'} :
ae_strongly_measurable' m (condexp_L1 hm μ f) μ :=
begin
by_cases hf : integrable f μ,
{ rw condexp_L1_eq hf,
exact ae_strongly_measurable'_condexp_L1_clm _, },
{ rw condexp_L1_undef hf,
refine ae_strongly_measurable'.congr _ (coe_fn_zero _ _ _).symm,
exact strongly_measurable.ae_strongly_measurable' (@strongly_measurable_zero _ _ m _ _), },
end
lemma condexp_L1_congr_ae (hm : m ≤ m0) [sigma_finite (μ.trim hm)] (h : f =ᵐ[μ] g) :
condexp_L1 hm μ f = condexp_L1 hm μ g :=
set_to_fun_congr_ae _ h
lemma integrable_condexp_L1 (f : α → F') : integrable (condexp_L1 hm μ f) μ :=
L1.integrable_coe_fn _
/-- The integral of the conditional expectation `condexp_L1` over an `m`-measurable set is equal to
the integral of `f` on that set. See also `set_integral_condexp`, the similar statement for
`condexp`. -/
lemma set_integral_condexp_L1 (hf : integrable f μ) (hs : measurable_set[m] s) :
∫ x in s, condexp_L1 hm μ f x ∂μ = ∫ x in s, f x ∂μ :=
begin
simp_rw condexp_L1_eq hf,
rw set_integral_condexp_L1_clm (hf.to_L1 f) hs,
exact set_integral_congr_ae (hm s hs) ((hf.coe_fn_to_L1).mono (λ x hx hxs, hx)),
end
lemma condexp_L1_add (hf : integrable f μ) (hg : integrable g μ) :
condexp_L1 hm μ (f + g) = condexp_L1 hm μ f + condexp_L1 hm μ g :=
set_to_fun_add _ hf hg
lemma condexp_L1_neg (f : α → F') : condexp_L1 hm μ (-f) = - condexp_L1 hm μ f :=
set_to_fun_neg _ f
lemma condexp_L1_smul (c : 𝕜) (f : α → F') : condexp_L1 hm μ (c • f) = c • condexp_L1 hm μ f :=
set_to_fun_smul _ (λ c _ x, condexp_ind_smul' c x) c f
lemma condexp_L1_sub (hf : integrable f μ) (hg : integrable g μ) :
condexp_L1 hm μ (f - g) = condexp_L1 hm μ f - condexp_L1 hm μ g :=
set_to_fun_sub _ hf hg
lemma condexp_L1_of_ae_strongly_measurable'
(hfm : ae_strongly_measurable' m f μ) (hfi : integrable f μ) :
condexp_L1 hm μ f =ᵐ[μ] f :=
begin
rw condexp_L1_eq hfi,
refine eventually_eq.trans _ (integrable.coe_fn_to_L1 hfi),
rw condexp_L1_clm_of_ae_strongly_measurable',
exact ae_strongly_measurable'.congr hfm (integrable.coe_fn_to_L1 hfi).symm,
end
lemma condexp_L1_mono {E} [normed_lattice_add_comm_group E] [complete_space E] [normed_space ℝ E]
[ordered_smul ℝ E] {f g : α → E}
(hf : integrable f μ) (hg : integrable g μ) (hfg : f ≤ᵐ[μ] g) :
condexp_L1 hm μ f ≤ᵐ[μ] condexp_L1 hm μ g :=
begin
rw coe_fn_le,
have h_nonneg : ∀ s, measurable_set s → μ s < ∞ → ∀ x : E, 0 ≤ x → 0 ≤ condexp_ind hm μ s x,
from λ s hs hμs x hx, condexp_ind_nonneg hs hμs.ne x hx,
exact set_to_fun_mono (dominated_fin_meas_additive_condexp_ind E hm μ) h_nonneg hf hg hfg,
end
end condexp_L1
section condexp
/-! ### Conditional expectation of a function -/
open_locale classical
variables {𝕜} {m m0 : measurable_space α} {μ : measure α} {f g : α → F'} {s : set α}
/-- Conditional expectation of a function. Its value is 0 if the function is not integrable, if
the σ-algebra is not a sub-σ-algebra or if the measure is not σ-finite on that σ-algebra. -/
@[irreducible]
def condexp (m : measurable_space α) {m0 : measurable_space α} (μ : measure α) (f : α → F') :
α → F' :=
if hm : m ≤ m0
then if hμ : sigma_finite (μ.trim hm)
then if (strongly_measurable[m] f ∧ integrable f μ)
then f
else (@ae_strongly_measurable'_condexp_L1 _ _ _ _ _ m m0 μ hm hμ _).mk
(@condexp_L1 _ _ _ _ _ _ _ hm μ hμ f)
else 0
else 0
-- We define notation `μ[f|m]` for the conditional expectation of `f` with respect to `m`.
localized "notation μ `[` f `|` m `]` := measure_theory.condexp m μ f" in measure_theory
lemma condexp_of_not_le (hm_not : ¬ m ≤ m0) : μ[f|m] = 0 := by rw [condexp, dif_neg hm_not]
lemma condexp_of_not_sigma_finite (hm : m ≤ m0) (hμm_not : ¬ sigma_finite (μ.trim hm)) :
μ[f|m] = 0 :=
by rw [condexp, dif_pos hm, dif_neg hμm_not]
lemma condexp_of_sigma_finite (hm : m ≤ m0) [hμm : sigma_finite (μ.trim hm)] :
μ[f|m] =
if (strongly_measurable[m] f ∧ integrable f μ)
then f else ae_strongly_measurable'_condexp_L1.mk (condexp_L1 hm μ f) :=
by rw [condexp, dif_pos hm, dif_pos hμm]
lemma condexp_of_strongly_measurable (hm : m ≤ m0) [hμm : sigma_finite (μ.trim hm)]
{f : α → F'} (hf : strongly_measurable[m] f) (hfi : integrable f μ) :
μ[f|m] = f :=
by { rw [condexp_of_sigma_finite hm,
if_pos (⟨hf, hfi⟩ : strongly_measurable[m] f ∧ integrable f μ)], apply_instance, }
lemma condexp_const (hm : m ≤ m0) (c : F') [is_finite_measure μ] : μ[(λ x : α, c)|m] = λ _, c :=
condexp_of_strongly_measurable hm (@strongly_measurable_const _ _ m _ _) (integrable_const c)
lemma condexp_ae_eq_condexp_L1 (hm : m ≤ m0) [hμm : sigma_finite (μ.trim hm)]
(f : α → F') : μ[f|m] =ᵐ[μ] condexp_L1 hm μ f :=
begin
rw condexp_of_sigma_finite hm,
by_cases hfm : strongly_measurable[m] f,
{ by_cases hfi : integrable f μ,
{ rw if_pos (⟨hfm, hfi⟩ : strongly_measurable[m] f ∧ integrable f μ),
exact (condexp_L1_of_ae_strongly_measurable'
(strongly_measurable.ae_strongly_measurable' hfm) hfi).symm, },
{ simp only [hfi, if_false, and_false],
exact (ae_strongly_measurable'.ae_eq_mk ae_strongly_measurable'_condexp_L1).symm, }, },
simp only [hfm, if_false, false_and],
exact (ae_strongly_measurable'.ae_eq_mk ae_strongly_measurable'_condexp_L1).symm,
end
lemma condexp_ae_eq_condexp_L1_clm (hm : m ≤ m0) [sigma_finite (μ.trim hm)] (hf : integrable f μ) :
μ[f|m] =ᵐ[μ] condexp_L1_clm hm μ (hf.to_L1 f) :=
begin
refine (condexp_ae_eq_condexp_L1 hm f).trans (eventually_of_forall (λ x, _)),
rw condexp_L1_eq hf,
end
lemma condexp_undef (hf : ¬ integrable f μ) : μ[f|m] =ᵐ[μ] 0 :=
begin
by_cases hm : m ≤ m0,
swap, { rw condexp_of_not_le hm, },
by_cases hμm : sigma_finite (μ.trim hm),
swap, { rw condexp_of_not_sigma_finite hm hμm, },
haveI : sigma_finite (μ.trim hm) := hμm,
refine (condexp_ae_eq_condexp_L1 hm f).trans (eventually_eq.trans _ (coe_fn_zero _ 1 _)),
rw condexp_L1_undef hf,
end
@[simp] lemma condexp_zero : μ[(0 : α → F')|m] = 0 :=
begin
by_cases hm : m ≤ m0,
swap, { rw condexp_of_not_le hm, },
by_cases hμm : sigma_finite (μ.trim hm),
swap, { rw condexp_of_not_sigma_finite hm hμm, },
haveI : sigma_finite (μ.trim hm) := hμm,
exact condexp_of_strongly_measurable hm (@strongly_measurable_zero _ _ m _ _)
(integrable_zero _ _ _),
end
lemma strongly_measurable_condexp : strongly_measurable[m] (μ[f|m]) :=
begin
by_cases hm : m ≤ m0,
swap, { rw condexp_of_not_le hm, exact strongly_measurable_zero, },
by_cases hμm : sigma_finite (μ.trim hm),
swap, { rw condexp_of_not_sigma_finite hm hμm, exact strongly_measurable_zero, },
haveI : sigma_finite (μ.trim hm) := hμm,
rw condexp_of_sigma_finite hm,
swap, { apply_instance, },
by_cases hfm : strongly_measurable[m] f,
{ by_cases hfi : integrable f μ,
{ rwa if_pos (⟨hfm, hfi⟩ : strongly_measurable[m] f ∧ integrable f μ), },
{ simp only [hfi, if_false, and_false],
exact ae_strongly_measurable'.strongly_measurable_mk _, }, },
simp only [hfm, if_false, false_and],
exact ae_strongly_measurable'.strongly_measurable_mk _,
end
lemma condexp_congr_ae (h : f =ᵐ[μ] g) : μ[f | m] =ᵐ[μ] μ[g | m] :=
begin
by_cases hm : m ≤ m0,
swap, { simp_rw condexp_of_not_le hm, },
by_cases hμm : sigma_finite (μ.trim hm),
swap, { simp_rw condexp_of_not_sigma_finite hm hμm, },
haveI : sigma_finite (μ.trim hm) := hμm,
exact (condexp_ae_eq_condexp_L1 hm f).trans
(filter.eventually_eq.trans (by rw condexp_L1_congr_ae hm h)
(condexp_ae_eq_condexp_L1 hm g).symm),
end
lemma condexp_of_ae_strongly_measurable' (hm : m ≤ m0) [hμm : sigma_finite (μ.trim hm)]
{f : α → F'} (hf : ae_strongly_measurable' m f μ) (hfi : integrable f μ) :
μ[f|m] =ᵐ[μ] f :=
begin
refine ((condexp_congr_ae hf.ae_eq_mk).trans _).trans hf.ae_eq_mk.symm,
rw condexp_of_strongly_measurable hm hf.strongly_measurable_mk
((integrable_congr hf.ae_eq_mk).mp hfi),
end
lemma integrable_condexp : integrable (μ[f|m]) μ :=
begin
by_cases hm : m ≤ m0,
swap, { rw condexp_of_not_le hm, exact integrable_zero _ _ _, },
by_cases hμm : sigma_finite (μ.trim hm),
swap, { rw condexp_of_not_sigma_finite hm hμm, exact integrable_zero _ _ _, },
haveI : sigma_finite (μ.trim hm) := hμm,
exact (integrable_condexp_L1 f).congr (condexp_ae_eq_condexp_L1 hm f).symm,
end
/-- The integral of the conditional expectation `μ[f|hm]` over an `m`-measurable set is equal to
the integral of `f` on that set. -/
lemma set_integral_condexp (hm : m ≤ m0) [sigma_finite (μ.trim hm)]
(hf : integrable f μ) (hs : measurable_set[m] s) :
∫ x in s, μ[f|m] x ∂μ = ∫ x in s, f x ∂μ :=
begin
rw set_integral_congr_ae (hm s hs) ((condexp_ae_eq_condexp_L1 hm f).mono (λ x hx _, hx)),
exact set_integral_condexp_L1 hf hs,
end
lemma integral_condexp {hm : m ≤ m0} [hμm : sigma_finite (μ.trim hm)]
(hf : integrable f μ) : ∫ x, μ[f|m] x ∂μ = ∫ x, f x ∂μ :=
begin
suffices : ∫ x in set.univ, μ[f|m] x ∂μ = ∫ x in set.univ, f x ∂μ,
by { simp_rw integral_univ at this, exact this, },
exact set_integral_condexp hm hf (@measurable_set.univ _ m),
end
/-- **Uniqueness of the conditional expectation**
If a function is a.e. `m`-measurable, verifies an integrability condition and has same integral
as `f` on all `m`-measurable sets, then it is a.e. equal to `μ[f|hm]`. -/
lemma ae_eq_condexp_of_forall_set_integral_eq (hm : m ≤ m0) [sigma_finite (μ.trim hm)]
{f g : α → F'} (hf : integrable f μ)
(hg_int_finite : ∀ s, measurable_set[m] s → μ s < ∞ → integrable_on g s μ)
(hg_eq : ∀ s : set α, measurable_set[m] s → μ s < ∞ → ∫ x in s, g x ∂μ = ∫ x in s, f x ∂μ)
(hgm : ae_strongly_measurable' m g μ) :
g =ᵐ[μ] μ[f|m] :=
begin
refine ae_eq_of_forall_set_integral_eq_of_sigma_finite' hm hg_int_finite
(λ s hs hμs, integrable_condexp.integrable_on) (λ s hs hμs, _) hgm
(strongly_measurable.ae_strongly_measurable' strongly_measurable_condexp),
rw [hg_eq s hs hμs, set_integral_condexp hm hf hs],
end
lemma condexp_add (hf : integrable f μ) (hg : integrable g μ) :
μ[f + g | m] =ᵐ[μ] μ[f|m] + μ[g|m] :=
begin
by_cases hm : m ≤ m0,
swap, { simp_rw condexp_of_not_le hm, simp, },
by_cases hμm : sigma_finite (μ.trim hm),
swap, { simp_rw condexp_of_not_sigma_finite hm hμm, simp, },
haveI : sigma_finite (μ.trim hm) := hμm,
refine (condexp_ae_eq_condexp_L1 hm _).trans _,
rw condexp_L1_add hf hg,
exact (coe_fn_add _ _).trans
((condexp_ae_eq_condexp_L1 hm _).symm.add (condexp_ae_eq_condexp_L1 hm _).symm),
end
lemma condexp_smul (c : 𝕜) (f : α → F') : μ[c • f | m] =ᵐ[μ] c • μ[f|m] :=
begin
by_cases hm : m ≤ m0,
swap, { simp_rw condexp_of_not_le hm, simp, },
by_cases hμm : sigma_finite (μ.trim hm),
swap, { simp_rw condexp_of_not_sigma_finite hm hμm, simp, },
haveI : sigma_finite (μ.trim hm) := hμm,
refine (condexp_ae_eq_condexp_L1 hm _).trans _,
rw condexp_L1_smul c f,
refine (@condexp_ae_eq_condexp_L1 _ _ _ _ _ m _ _ hm _ f).mp _,
refine (coe_fn_smul c (condexp_L1 hm μ f)).mono (λ x hx1 hx2, _),
rw [hx1, pi.smul_apply, pi.smul_apply, hx2],
end
lemma condexp_neg (f : α → F') : μ[-f|m] =ᵐ[μ] - μ[f|m] :=
by letI : module ℝ (α → F') := @pi.module α (λ _, F') ℝ _ _ (λ _, infer_instance);
calc μ[-f|m] = μ[(-1 : ℝ) • f|m] : by rw neg_one_smul ℝ f
... =ᵐ[μ] (-1 : ℝ) • μ[f|m] : condexp_smul (-1) f
... = -μ[f|m] : neg_one_smul ℝ (μ[f|m])
lemma condexp_sub (hf : integrable f μ) (hg : integrable g μ) :
μ[f - g | m] =ᵐ[μ] μ[f|m] - μ[g|m] :=
begin
simp_rw sub_eq_add_neg,
exact (condexp_add hf hg.neg).trans (eventually_eq.rfl.add (condexp_neg g)),
end
lemma condexp_condexp_of_le {m₁ m₂ m0 : measurable_space α} {μ : measure α} (hm₁₂ : m₁ ≤ m₂)
(hm₂ : m₂ ≤ m0) [sigma_finite (μ.trim hm₂)] :
μ[ μ[f|m₂] | m₁] =ᵐ[μ] μ[f | m₁] :=
begin
by_cases hμm₁ : sigma_finite (μ.trim (hm₁₂.trans hm₂)),
swap, { simp_rw condexp_of_not_sigma_finite (hm₁₂.trans hm₂) hμm₁, },
haveI : sigma_finite (μ.trim (hm₁₂.trans hm₂)) := hμm₁,
refine ae_eq_of_forall_set_integral_eq_of_sigma_finite' (hm₁₂.trans hm₂)
(λ s hs hμs, integrable_condexp.integrable_on) (λ s hs hμs, integrable_condexp.integrable_on)
_ (strongly_measurable.ae_strongly_measurable' strongly_measurable_condexp)
(strongly_measurable.ae_strongly_measurable' strongly_measurable_condexp),
intros s hs hμs,
rw set_integral_condexp (hm₁₂.trans hm₂) integrable_condexp hs,
swap, { apply_instance, },
by_cases hf : integrable f μ,
{ rw [set_integral_condexp (hm₁₂.trans hm₂) hf hs, set_integral_condexp hm₂ hf (hm₁₂ s hs)], },
{ simp_rw integral_congr_ae (ae_restrict_of_ae (condexp_undef hf)), },
end
lemma condexp_mono {E} [normed_lattice_add_comm_group E] [complete_space E] [normed_space ℝ E]
[ordered_smul ℝ E] {f g : α → E} (hf : integrable f μ) (hg : integrable g μ) (hfg : f ≤ᵐ[μ] g) :
μ[f | m] ≤ᵐ[μ] μ[g | m] :=
begin
by_cases hm : m ≤ m0,
swap, { simp_rw condexp_of_not_le hm, },
by_cases hμm : sigma_finite (μ.trim hm),
swap, { simp_rw condexp_of_not_sigma_finite hm hμm, },
haveI : sigma_finite (μ.trim hm) := hμm,
exact (condexp_ae_eq_condexp_L1 hm _).trans_le
((condexp_L1_mono hf hg hfg).trans_eq (condexp_ae_eq_condexp_L1 hm _).symm),
end
section indicator
lemma condexp_ae_eq_restrict_zero (hs : measurable_set[m] s) (hf : f =ᵐ[μ.restrict s] 0) :
μ[f | m] =ᵐ[μ.restrict s] 0 :=
begin
by_cases hm : m ≤ m0,
swap, { simp_rw condexp_of_not_le hm, },
by_cases hμm : sigma_finite (μ.trim hm),
swap, { simp_rw condexp_of_not_sigma_finite hm hμm, },
haveI : sigma_finite (μ.trim hm) := hμm,
haveI : sigma_finite ((μ.restrict s).trim hm),
{ rw ← restrict_trim hm _ hs,
exact restrict.sigma_finite _ s, },
by_cases hf_int : integrable f μ,
swap, { exact ae_restrict_of_ae (condexp_undef hf_int), },
refine ae_eq_of_forall_set_integral_eq_of_sigma_finite' hm _ _ _ _ _,
{ exact λ t ht hμt, integrable_condexp.integrable_on.integrable_on, },
{ exact λ t ht hμt, (integrable_zero _ _ _).integrable_on, },
{ intros t ht hμt,
rw [measure.restrict_restrict (hm _ ht), set_integral_condexp hm hf_int (ht.inter hs),
← measure.restrict_restrict (hm _ ht)],
refine set_integral_congr_ae (hm _ ht) _,
filter_upwards [hf] with x hx h using hx, },
{ exact strongly_measurable_condexp.ae_strongly_measurable', },
{ exact strongly_measurable_zero.ae_strongly_measurable', },
end
/-- Auxiliary lemma for `condexp_indicator`. -/
lemma condexp_indicator_aux (hs : measurable_set[m] s) (hf : f =ᵐ[μ.restrict sᶜ] 0) :
μ[s.indicator f | m] =ᵐ[μ] s.indicator (μ[f | m]) :=
begin
by_cases hm : m ≤ m0,
swap, { simp_rw [condexp_of_not_le hm, set.indicator_zero'], },
have hsf_zero : ∀ g : α → F', g =ᵐ[μ.restrict sᶜ] 0 → s.indicator g =ᵐ[μ] g,
from λ g, indicator_ae_eq_of_restrict_compl_ae_eq_zero (hm _ hs),
refine ((hsf_zero (μ[f | m]) (condexp_ae_eq_restrict_zero hs.compl hf)).trans _).symm,
exact condexp_congr_ae (hsf_zero f hf).symm,
end
/-- The conditional expectation of the indicator of a function over an `m`-measurable set with
respect to the σ-algebra `m` is a.e. equal to the indicator of the conditional expectation. -/
lemma condexp_indicator (hf_int : integrable f μ) (hs : measurable_set[m] s) :
μ[s.indicator f | m] =ᵐ[μ] s.indicator (μ[f | m]) :=
begin
by_cases hm : m ≤ m0,
swap, { simp_rw [condexp_of_not_le hm, set.indicator_zero'], },
by_cases hμm : sigma_finite (μ.trim hm),
swap, { simp_rw [condexp_of_not_sigma_finite hm hμm, set.indicator_zero'], },
haveI : sigma_finite (μ.trim hm) := hμm,
-- use `have` to perform what should be the first calc step because of an error I don't
-- understand
have : s.indicator (μ[f|m]) =ᵐ[μ] s.indicator (μ[s.indicator f + sᶜ.indicator f|m]),
by rw set.indicator_self_add_compl s f,
refine (this.trans _).symm,
calc s.indicator (μ[s.indicator f + sᶜ.indicator f|m])
=ᵐ[μ] s.indicator (μ[s.indicator f|m] + μ[sᶜ.indicator f|m]) :
begin
have : μ[s.indicator f + sᶜ.indicator f|m] =ᵐ[μ] μ[s.indicator f|m] + μ[sᶜ.indicator f|m],
from condexp_add (hf_int.indicator (hm _ hs)) (hf_int.indicator (hm _ hs.compl)),
filter_upwards [this] with x hx,
classical,
rw [set.indicator_apply, set.indicator_apply, hx],
end
... = s.indicator (μ[s.indicator f|m]) + s.indicator (μ[sᶜ.indicator f|m]) :
s.indicator_add' _ _
... =ᵐ[μ] s.indicator (μ[s.indicator f|m]) + s.indicator (sᶜ.indicator (μ[sᶜ.indicator f|m])) :
begin
refine filter.eventually_eq.rfl.add _,
have : sᶜ.indicator (μ[sᶜ.indicator f|m]) =ᵐ[μ] μ[sᶜ.indicator f|m],
{ refine (condexp_indicator_aux hs.compl _).symm.trans _,
{ exact indicator_ae_eq_restrict_compl (hm _ hs.compl), },
{ rw [set.indicator_indicator, set.inter_self], }, },
filter_upwards [this] with x hx,
by_cases hxs : x ∈ s,
{ simp only [hx, hxs, set.indicator_of_mem], },
{ simp only [hxs, set.indicator_of_not_mem, not_false_iff], },
end
... =ᵐ[μ] s.indicator (μ[s.indicator f|m]) :
by rw [set.indicator_indicator, set.inter_compl_self, set.indicator_empty', add_zero]
... =ᵐ[μ] μ[s.indicator f|m] :
begin
refine (condexp_indicator_aux hs _).symm.trans _,
{ exact indicator_ae_eq_restrict_compl (hm _ hs), },
{ rw [set.indicator_indicator, set.inter_self], },
end
end
lemma condexp_restrict_ae_eq_restrict (hm : m ≤ m0) [sigma_finite (μ.trim hm)]
(hs_m : measurable_set[m] s) (hf_int : integrable f μ) :
(μ.restrict s)[f | m] =ᵐ[μ.restrict s] μ[f | m] :=
begin
haveI : sigma_finite ((μ.restrict s).trim hm),
{ rw ← restrict_trim hm _ hs_m, apply_instance, },
rw ae_eq_restrict_iff_indicator_ae_eq (hm _ hs_m),
swap, { apply_instance, },
refine eventually_eq.trans _ (condexp_indicator hf_int hs_m),
refine ae_eq_condexp_of_forall_set_integral_eq hm (hf_int.indicator (hm _ hs_m)) _ _ _,
{ intros t ht hμt,
rw [← integrable_indicator_iff (hm _ ht), set.indicator_indicator, set.inter_comm,
← set.indicator_indicator],
suffices h_int_restrict : integrable (t.indicator ((μ.restrict s)[f|m])) (μ.restrict s),
{ rw [integrable_indicator_iff (hm _ hs_m), integrable_on],
rw [integrable_indicator_iff (hm _ ht), integrable_on] at h_int_restrict ⊢,
exact h_int_restrict, },
exact integrable_condexp.indicator (hm _ ht), },
{ intros t ht hμt,
calc ∫ x in t, s.indicator ((μ.restrict s)[f|m]) x ∂μ
= ∫ x in t, ((μ.restrict s)[f|m]) x ∂(μ.restrict s) :
by rw [integral_indicator (hm _ hs_m), measure.restrict_restrict (hm _ hs_m),
measure.restrict_restrict (hm _ ht), set.inter_comm]
... = ∫ x in t, f x ∂(μ.restrict s) : set_integral_condexp hm hf_int.integrable_on ht
... = ∫ x in t, s.indicator f x ∂μ :
by rw [integral_indicator (hm _ hs_m), measure.restrict_restrict (hm _ hs_m),
measure.restrict_restrict (hm _ ht), set.inter_comm], },
{ exact (strongly_measurable_condexp.indicator hs_m).ae_strongly_measurable', },
end
/-- If the restriction to a `m`-measurable set `s` of a σ-algebra `m` is equal to the restriction
to `s` of another σ-algebra `m₂` (hypothesis `hs`), then `μ[f | m] =ᵐ[μ.restrict s] μ[f | m₂]`. -/
lemma condexp_ae_eq_restrict_of_measurable_space_eq_on {m m₂ m0 : measurable_space α}
{μ : measure α} (hm : m ≤ m0) (hm₂ : m₂ ≤ m0)
[sigma_finite (μ.trim hm)] [sigma_finite (μ.trim hm₂)]
(hs_m : measurable_set[m] s) (hs : ∀ t, measurable_set[m] (s ∩ t) ↔ measurable_set[m₂] (s ∩ t)) :
μ[f | m] =ᵐ[μ.restrict s] μ[f | m₂] :=
begin
rw ae_eq_restrict_iff_indicator_ae_eq (hm _ hs_m),
have hs_m₂ : measurable_set[m₂] s,
{ rwa [← set.inter_univ s, ← hs set.univ, set.inter_univ], },
by_cases hf_int : integrable f μ,
swap,
{ filter_upwards [@condexp_undef _ _ _ _ _ m _ μ _ hf_int,
@condexp_undef _ _ _ _ _ m₂ _ μ _ hf_int] with x hxm hxm₂,
simp only [set.indicator_apply, hxm, hxm₂], },
refine ((condexp_indicator hf_int hs_m).symm.trans _).trans (condexp_indicator hf_int hs_m₂),
refine ae_eq_of_forall_set_integral_eq_of_sigma_finite' hm₂
(λ s hs hμs, integrable_condexp.integrable_on)
(λ s hs hμs, integrable_condexp.integrable_on) _ _
strongly_measurable_condexp.ae_strongly_measurable',
swap,
{ have : strongly_measurable[m] (μ[s.indicator f | m]) := strongly_measurable_condexp,
refine this.ae_strongly_measurable'.ae_strongly_measurable'_of_measurable_space_le_on
hm hs_m (λ t, (hs t).mp) _,
exact condexp_ae_eq_restrict_zero hs_m.compl (indicator_ae_eq_restrict_compl (hm _ hs_m)), },
intros t ht hμt,
have : ∫ x in t, μ[s.indicator f|m] x ∂μ = ∫ x in s ∩ t, μ[s.indicator f|m] x ∂μ,
{ rw ← integral_add_compl (hm _ hs_m) integrable_condexp.integrable_on,
suffices : ∫ x in sᶜ, μ[s.indicator f|m] x ∂μ.restrict t = 0,
by rw [this, add_zero, measure.restrict_restrict (hm _ hs_m)],
rw measure.restrict_restrict (measurable_set.compl (hm _ hs_m)),
suffices : μ[s.indicator f|m] =ᵐ[μ.restrict sᶜ] 0,
{ rw [set.inter_comm, ← measure.restrict_restrict (hm₂ _ ht)],
calc ∫ (x : α) in t, μ[s.indicator f|m] x ∂μ.restrict sᶜ
= ∫ (x : α) in t, 0 ∂μ.restrict sᶜ : begin
refine set_integral_congr_ae (hm₂ _ ht) _,
filter_upwards [this] with x hx h using hx,
end
... = 0 : integral_zero _ _, },
refine condexp_ae_eq_restrict_zero hs_m.compl _,
exact indicator_ae_eq_restrict_compl (hm _ hs_m), },
have hst_m : measurable_set[m] (s ∩ t) := (hs _).mpr (hs_m₂.inter ht),
simp_rw [this, set_integral_condexp hm₂ (hf_int.indicator (hm _ hs_m)) ht,
set_integral_condexp hm (hf_int.indicator (hm _ hs_m)) hst_m,
integral_indicator (hm _ hs_m), measure.restrict_restrict (hm _ hs_m),
← set.inter_assoc, set.inter_self],
end
end indicator
section real
lemma rn_deriv_ae_eq_condexp {hm : m ≤ m0} [hμm : sigma_finite (μ.trim hm)] {f : α → ℝ}
(hf : integrable f μ) :
signed_measure.rn_deriv ((μ.with_densityᵥ f).trim hm) (μ.trim hm) =ᵐ[μ] μ[f | m] :=
begin
refine ae_eq_condexp_of_forall_set_integral_eq hm hf _ _ _,
{ exact λ _ _ _, (integrable_of_integrable_trim hm (signed_measure.integrable_rn_deriv
((μ.with_densityᵥ f).trim hm) (μ.trim hm))).integrable_on },
{ intros s hs hlt,
conv_rhs { rw [← hf.with_densityᵥ_trim_eq_integral hm hs,
← signed_measure.with_densityᵥ_rn_deriv_eq ((μ.with_densityᵥ f).trim hm) (μ.trim hm)
(hf.with_densityᵥ_trim_absolutely_continuous hm)], },
rw [with_densityᵥ_apply
(signed_measure.integrable_rn_deriv ((μ.with_densityᵥ f).trim hm) (μ.trim hm)) hs,
← set_integral_trim hm _ hs],
exact (signed_measure.measurable_rn_deriv _ _).strongly_measurable },
{ exact strongly_measurable.ae_strongly_measurable'
(signed_measure.measurable_rn_deriv _ _).strongly_measurable },
end
/-- TODO: this should be generalized and proved using Jensen's inequality
for the conditional expectation (not in mathlib yet) .-/
lemma snorm_one_condexp_le_snorm (f : α → ℝ) :
snorm (μ[f | m]) 1 μ ≤ snorm f 1 μ :=
begin
by_cases hf : integrable f μ,
swap, { rw [snorm_congr_ae (condexp_undef hf), snorm_zero], exact zero_le _ },
by_cases hm : m ≤ m0,
swap, { rw [condexp_of_not_le hm, snorm_zero], exact zero_le _ },
by_cases hsig : sigma_finite (μ.trim hm),
swap, { rw [condexp_of_not_sigma_finite hm hsig, snorm_zero], exact zero_le _ },
calc snorm (μ[f | m]) 1 μ ≤ snorm (μ[|f| | m]) 1 μ :
begin
refine snorm_mono_ae _,
filter_upwards [@condexp_mono _ m m0 _ _ _ _ _ _ _ _ hf hf.abs
(@ae_of_all _ m0 _ μ (λ x, le_abs_self (f x) : ∀ x, f x ≤ |f x|)),
eventually_le.trans (condexp_neg f).symm.le
(@condexp_mono _ m m0 _ _ _ _ _ _ _ _ hf.neg hf.abs
(@ae_of_all _ m0 _ μ (λ x, neg_le_abs_self (f x) : ∀ x, -f x ≤ |f x|)))] with x hx₁ hx₂,
exact abs_le_abs hx₁ hx₂,
end
... = snorm f 1 μ :
begin
rw [snorm_one_eq_lintegral_nnnorm, snorm_one_eq_lintegral_nnnorm,
← ennreal.to_real_eq_to_real (ne_of_lt integrable_condexp.2) (ne_of_lt hf.2),
← integral_norm_eq_lintegral_nnnorm
(strongly_measurable_condexp.mono hm).ae_strongly_measurable,
← integral_norm_eq_lintegral_nnnorm hf.1],
simp_rw [real.norm_eq_abs],
rw ← @integral_condexp _ _ _ _ _ m m0 μ _ hm hsig hf.abs,
refine integral_congr_ae _,
have : 0 ≤ᵐ[μ] μ[|f| | m],
{ rw ← @condexp_zero α ℝ _ _ _ m m0 μ,
exact condexp_mono (integrable_zero _ _ _) hf.abs
(@ae_of_all _ m0 _ μ (λ x, abs_nonneg (f x) : ∀ x, 0 ≤ |f x|)) },
filter_upwards [this] with x hx,
exact abs_eq_self.2 hx
end
end
/-- Given a integrable function `g`, the conditional expectations of `g` with respect to
a sequence of sub-σ-algebras is uniformly integrable. -/
lemma integrable.uniform_integrable_condexp {ι : Type*} [is_finite_measure μ]
{g : α → ℝ} (hint : integrable g μ) {ℱ : ι → measurable_space α} (hℱ : ∀ i, ℱ i ≤ m0) :
uniform_integrable (λ i, μ[g | ℱ i]) 1 μ :=
begin
have hmeas : ∀ n, ∀ C, measurable_set {x | C ≤ ∥μ[g | ℱ n] x∥₊} :=
λ n C, measurable_set_le measurable_const
(strongly_measurable_condexp.mono (hℱ n)).measurable.nnnorm,
have hg : mem_ℒp g 1 μ := mem_ℒp_one_iff_integrable.2 hint,
refine uniform_integrable_of le_rfl ennreal.one_ne_top
(λ n, strongly_measurable_condexp.mono (hℱ n)) (λ ε hε, _),
by_cases hne : snorm g 1 μ = 0,
{ rw snorm_eq_zero_iff hg.1 one_ne_zero at hne,
refine ⟨0, λ n, (le_of_eq $ (snorm_eq_zero_iff
((strongly_measurable_condexp.mono (hℱ n)).ae_strongly_measurable.indicator (hmeas n 0))
one_ne_zero).2 _).trans (zero_le _)⟩,
filter_upwards [@condexp_congr_ae _ _ _ _ _ (ℱ n) m0 μ _ _ hne] with x hx,
simp only [zero_le', set.set_of_true, set.indicator_univ, pi.zero_apply, hx, condexp_zero] },
obtain ⟨δ, hδ, h⟩ := hg.snorm_indicator_le μ le_rfl ennreal.one_ne_top hε,
set C : ℝ≥0 := ⟨δ, hδ.le⟩⁻¹ * (snorm g 1 μ).to_nnreal with hC,
have hCpos : 0 < C :=
mul_pos (nnreal.inv_pos.2 hδ) (ennreal.to_nnreal_pos hne hg.snorm_lt_top.ne),
have : ∀ n, μ {x : α | C ≤ ∥μ[g | ℱ n] x∥₊} ≤ ennreal.of_real δ,
{ intro n,
have := mul_meas_ge_le_pow_snorm' μ one_ne_zero ennreal.one_ne_top
((@strongly_measurable_condexp _ _ _ _ _ (ℱ n) _ μ g).mono
(hℱ n)).ae_strongly_measurable C,
rw [ennreal.one_to_real, ennreal.rpow_one, ennreal.rpow_one, mul_comm,
← ennreal.le_div_iff_mul_le (or.inl (ennreal.coe_ne_zero.2 hCpos.ne.symm))
(or.inl ennreal.coe_lt_top.ne)] at this,
simp_rw [ennreal.coe_le_coe] at this,
refine this.trans _,
rw [ennreal.div_le_iff_le_mul (or.inl (ennreal.coe_ne_zero.2 hCpos.ne.symm))
(or.inl ennreal.coe_lt_top.ne), hC, nonneg.inv_mk, ennreal.coe_mul,
ennreal.coe_to_nnreal hg.snorm_lt_top.ne, ← mul_assoc, ← ennreal.of_real_eq_coe_nnreal,
← ennreal.of_real_mul hδ.le, mul_inv_cancel hδ.ne.symm, ennreal.of_real_one, one_mul],
exact snorm_one_condexp_le_snorm _ },
refine ⟨C, λ n, le_trans _ (h {x : α | C ≤ ∥μ[g | ℱ n] x∥₊} (hmeas n C) (this n))⟩,
have hmeasℱ : measurable_set[ℱ n] {x : α | C ≤ ∥μ[g | ℱ n] x∥₊} :=
@measurable_set_le _ _ _ _ _ (ℱ n) _ _ _ _ _ measurable_const
(@measurable.nnnorm _ _ _ _ _ (ℱ n) _ strongly_measurable_condexp.measurable),
rw ← snorm_congr_ae (condexp_indicator hint hmeasℱ),
exact snorm_one_condexp_le_snorm _,
end
end real
end condexp
end measure_theory
|
c38e0b459ff34de048532c71818cfd42c7bedbdd | cf39355caa609c0f33405126beee2739aa3cb77e | /tests/lean/run/def11.lean | b03d8c70476dc7a9c73cf06de574ca728e00c215 | [
"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 | 55 | lean |
definition ex1 (a : nat) : nat.succ a = 0 → false
.
|
f2f498b2830f497efb47f4973acddf6eea2d6e2b | 74addaa0e41490cbaf2abd313a764c96df57b05d | /Mathlib/linear_algebra/smodeq_auto.lean | 579a5b1d89db0a7c62796304ec7d99fd6b13651d | [] | 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,621 | 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 Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.linear_algebra.basic
import Mathlib.PostPort
universes u_1 u_2 u_3
namespace Mathlib
/-!
# modular equivalence for submodule
-/
/-- A predicate saying two elements of a module are equivalent modulo a submodule. -/
def smodeq {R : Type u_1} [ring R] {M : Type u_2} [add_comm_group M] [module R M]
(U : submodule R M) (x : M) (y : M) :=
submodule.quotient.mk x = submodule.quotient.mk y
protected theorem smodeq.def {R : Type u_1} [ring R] {M : Type u_2} [add_comm_group M] [module R M]
{U : submodule R M} {x : M} {y : M} :
smodeq U x y ↔ submodule.quotient.mk x = submodule.quotient.mk y :=
iff.rfl
namespace smodeq
@[simp] theorem top {R : Type u_1} [ring R] {M : Type u_2} [add_comm_group M] [module R M] {x : M}
{y : M} : smodeq ⊤ x y :=
iff.mpr (submodule.quotient.eq ⊤) submodule.mem_top
@[simp] theorem bot {R : Type u_1} [ring R] {M : Type u_2} [add_comm_group M] [module R M] {x : M}
{y : M} : smodeq ⊥ x y ↔ x = y :=
sorry
theorem mono {R : Type u_1} [ring R] {M : Type u_2} [add_comm_group M] [module R M]
{U₁ : submodule R M} {U₂ : submodule R M} {x : M} {y : M} (HU : U₁ ≤ U₂) (hxy : smodeq U₁ x y) :
smodeq U₂ x y :=
iff.mpr (submodule.quotient.eq U₂) (HU (iff.mp (submodule.quotient.eq U₁) hxy))
theorem refl {R : Type u_1} [ring R] {M : Type u_2} [add_comm_group M] [module R M]
{U : submodule R M} {x : M} : smodeq U x x :=
Eq.refl (submodule.quotient.mk x)
theorem symm {R : Type u_1} [ring R] {M : Type u_2} [add_comm_group M] [module R M]
{U : submodule R M} {x : M} {y : M} (hxy : smodeq U x y) : smodeq U y x :=
Eq.symm hxy
theorem trans {R : Type u_1} [ring R] {M : Type u_2} [add_comm_group M] [module R M]
{U : submodule R M} {x : M} {y : M} {z : M} (hxy : smodeq U x y) (hyz : smodeq U y z) :
smodeq U x z :=
Eq.trans hxy hyz
theorem add {R : Type u_1} [ring R] {M : Type u_2} [add_comm_group M] [module R M]
{U : submodule R M} {x₁ : M} {x₂ : M} {y₁ : M} {y₂ : M} (hxy₁ : smodeq U x₁ y₁)
(hxy₂ : smodeq U x₂ y₂) : smodeq U (x₁ + x₂) (y₁ + y₂) :=
sorry
theorem smul {R : Type u_1} [ring R] {M : Type u_2} [add_comm_group M] [module R M]
{U : submodule R M} {x : M} {y : M} (hxy : smodeq U x y) (c : R) : smodeq U (c • x) (c • y) :=
sorry
theorem zero {R : Type u_1} [ring R] {M : Type u_2} [add_comm_group M] [module R M]
{U : submodule R M} {x : M} : smodeq U x 0 ↔ x ∈ U :=
sorry
theorem map {R : Type u_1} [ring R] {M : Type u_2} [add_comm_group M] [module R M]
{U : submodule R M} {x : M} {y : M} {N : Type u_3} [add_comm_group N] [module R N]
(hxy : smodeq U x y) (f : linear_map R M N) :
smodeq (submodule.map f U) (coe_fn f x) (coe_fn f y) :=
iff.mpr (submodule.quotient.eq (submodule.map f U))
(Eq.subst (linear_map.map_sub f x y) submodule.mem_map_of_mem
(iff.mp (submodule.quotient.eq U) hxy))
theorem comap {R : Type u_1} [ring R] {M : Type u_2} [add_comm_group M] [module R M] {x : M} {y : M}
{N : Type u_3} [add_comm_group N] [module R N] (V : submodule R N) {f : linear_map R M N}
(hxy : smodeq V (coe_fn f x) (coe_fn f y)) : smodeq (submodule.comap f V) x y :=
iff.mpr (submodule.quotient.eq (submodule.comap f V))
((fun (this : coe_fn f (x - y) ∈ V) => this)
(Eq.symm (linear_map.map_sub f x y) ▸ iff.mp (submodule.quotient.eq V) hxy))
end Mathlib |
040cbfee3cc7222fe657c150623f4f6d5cd70dca | 4727251e0cd73359b15b664c3170e5d754078599 | /src/algebra/homology/augment.lean | 6904f0708305b721c4bdced26553a051c46b191e | [
"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,971 | lean | /-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import algebra.homology.single
import tactic.linarith
/-!
# Augmentation and truncation of `ℕ`-indexed (co)chain complexes.
-/
noncomputable theory
open category_theory
open category_theory.limits
open homological_complex
universes v u
variables {V : Type u} [category.{v} V]
namespace chain_complex
/--
The truncation of a `ℕ`-indexed chain complex,
deleting the object at `0` and shifting everything else down.
-/
@[simps]
def truncate [has_zero_morphisms V] : chain_complex V ℕ ⥤ chain_complex V ℕ :=
{ obj := λ C,
{ X := λ i, C.X (i+1),
d := λ i j, C.d (i+1) (j+1),
shape' := λ i j w, by { apply C.shape, simpa }, },
map := λ C D f,
{ f := λ i, f.f (i+1), }, }
/--
There is a canonical chain map from the truncation of a chain map `C` to
the "single object" chain complex consisting of the truncated object `C.X 0` in degree 0.
The components of this chain map are `C.d 1 0` in degree 0, and zero otherwise.
-/
def truncate_to [has_zero_object V] [has_zero_morphisms V] (C : chain_complex V ℕ) :
truncate.obj C ⟶ (single₀ V).obj (C.X 0) :=
(to_single₀_equiv (truncate.obj C) (C.X 0)).symm ⟨C.d 1 0, by tidy⟩
-- PROJECT when `V` is abelian (but not generally?)
-- `[∀ n, exact (C.d (n+2) (n+1)) (C.d (n+1) n)] [epi (C.d 1 0)]` iff `quasi_iso (C.truncate_to)`
variables [has_zero_morphisms V]
/--
We can "augment" a chain complex by inserting an arbitrary object in degree zero
(shifting everything else up), along with a suitable differential.
-/
def augment (C : chain_complex V ℕ) {X : V} (f : C.X 0 ⟶ X) (w : C.d 1 0 ≫ f = 0) :
chain_complex V ℕ :=
{ X := λ i, match i with
| 0 := X
| (i+1) := C.X i
end,
d := λ i j, match i, j with
| 1, 0 := f
| (i+1), (j+1) := C.d i j
| _, _ := 0
end,
shape' := λ i j s, begin
simp at s,
rcases i with _|_|i; cases j; unfold_aux; try { simp },
{ simpa using s, },
{ rw [C.shape], simpa [← ne.def, nat.succ_ne_succ] using s },
end,
d_comp_d' := λ i j k hij hjk, begin
rcases i with _|_|i; rcases j with _|_|j; cases k; unfold_aux; try { simp },
cases i,
{ exact w, },
{ rw [C.shape, zero_comp],
simpa using i.succ_succ_ne_one.symm },
end, }
@[simp] lemma augment_X_zero (C : chain_complex V ℕ) {X : V} (f : C.X 0 ⟶ X) (w : C.d 1 0 ≫ f = 0) :
(augment C f w).X 0 = X := rfl
@[simp] lemma augment_X_succ (C : chain_complex V ℕ) {X : V} (f : C.X 0 ⟶ X) (w : C.d 1 0 ≫ f = 0)
(i : ℕ) :
(augment C f w).X (i+1) = C.X i := rfl
@[simp] lemma augment_d_one_zero
(C : chain_complex V ℕ) {X : V} (f : C.X 0 ⟶ X) (w : C.d 1 0 ≫ f = 0) :
(augment C f w).d 1 0 = f := rfl
@[simp] lemma augment_d_succ_succ
(C : chain_complex V ℕ) {X : V} (f : C.X 0 ⟶ X) (w : C.d 1 0 ≫ f = 0) (i j : ℕ) :
(augment C f w).d (i+1) (j+1) = C.d i j :=
by { dsimp [augment], rcases i with _|i, refl, refl, }
/--
Truncating an augmented chain complex is isomorphic (with components the identity)
to the original complex.
-/
def truncate_augment (C : chain_complex V ℕ) {X : V} (f : C.X 0 ⟶ X) (w : C.d 1 0 ≫ f = 0) :
truncate.obj (augment C f w) ≅ C :=
{ hom :=
{ f := λ i, 𝟙 _, },
inv :=
{ f := λ i, by { exact 𝟙 _, },
comm' := λ i j, by { cases j; { dsimp, simp, }, }, },
hom_inv_id' := by { ext i, cases i; { dsimp, simp, }, },
inv_hom_id' := by { ext i, cases i; { dsimp, simp, }, }, }.
@[simp] lemma truncate_augment_hom_f
(C : chain_complex V ℕ) {X : V} (f : C.X 0 ⟶ X) (w : C.d 1 0 ≫ f = 0) (i : ℕ) :
(truncate_augment C f w).hom.f i = 𝟙 (C.X i) := rfl
@[simp] lemma truncate_augment_inv_f
(C : chain_complex V ℕ) {X : V} (f : C.X 0 ⟶ X) (w : C.d 1 0 ≫ f = 0) (i : ℕ) :
(truncate_augment C f w).inv.f i = 𝟙 ((truncate.obj (augment C f w)).X i) :=
rfl
@[simp] lemma chain_complex_d_succ_succ_zero (C : chain_complex V ℕ) (i : ℕ) :
C.d (i+2) 0 = 0 :=
by { rw C.shape, simpa using i.succ_succ_ne_one.symm }
/--
Augmenting a truncated complex with the original object and morphism is isomorphic
(with components the identity) to the original complex.
-/
def augment_truncate (C : chain_complex V ℕ) :
augment (truncate.obj C) (C.d 1 0) (C.d_comp_d _ _ _) ≅ C :=
{ hom :=
{ f := λ i, by { cases i; exact 𝟙 _, },
comm' := λ i j, by { rcases i with _|_|i; cases j; { dsimp, simp, }, }, },
inv :=
{ f := λ i, by { cases i; exact 𝟙 _, },
comm' := λ i j, by { rcases i with _|_|i; cases j; { dsimp, simp, }, }, },
hom_inv_id' := by { ext i, cases i; { dsimp, simp, }, },
inv_hom_id' := by { ext i, cases i; { dsimp, simp, }, }, }.
@[simp] lemma augment_truncate_hom_f_zero (C : chain_complex V ℕ) :
(augment_truncate C).hom.f 0 = 𝟙 (C.X 0) :=
rfl
@[simp] lemma augment_truncate_hom_f_succ (C : chain_complex V ℕ) (i : ℕ) :
(augment_truncate C).hom.f (i+1) = 𝟙 (C.X (i+1)) :=
rfl
@[simp] lemma augment_truncate_inv_f_zero (C : chain_complex V ℕ) :
(augment_truncate C).inv.f 0 = 𝟙 (C.X 0) :=
rfl
@[simp] lemma augment_truncate_inv_f_succ (C : chain_complex V ℕ) (i : ℕ) :
(augment_truncate C).inv.f (i+1) = 𝟙 (C.X (i+1)) :=
rfl
/--
A chain map from a chain complex to a single object chain complex in degree zero
can be reinterpreted as a chain complex.
Ths is the inverse construction of `truncate_to`.
-/
def to_single₀_as_complex
[has_zero_object V] (C : chain_complex V ℕ) (X : V) (f : C ⟶ (single₀ V).obj X) :
chain_complex V ℕ :=
let ⟨f, w⟩ := to_single₀_equiv C X f in augment C f w
end chain_complex
namespace cochain_complex
/--
The truncation of a `ℕ`-indexed cochain complex,
deleting the object at `0` and shifting everything else down.
-/
@[simps]
def truncate [has_zero_morphisms V] : cochain_complex V ℕ ⥤ cochain_complex V ℕ :=
{ obj := λ C,
{ X := λ i, C.X (i+1),
d := λ i j, C.d (i+1) (j+1),
shape' := λ i j w, by { apply C.shape, simpa }, },
map := λ C D f,
{ f := λ i, f.f (i+1), }, }
/--
There is a canonical chain map from the truncation of a cochain complex `C` to
the "single object" cochain complex consisting of the truncated object `C.X 0` in degree 0.
The components of this chain map are `C.d 0 1` in degree 0, and zero otherwise.
-/
def to_truncate [has_zero_object V] [has_zero_morphisms V] (C : cochain_complex V ℕ) :
(single₀ V).obj (C.X 0) ⟶ truncate.obj C :=
(from_single₀_equiv (truncate.obj C) (C.X 0)).symm ⟨C.d 0 1, by tidy⟩
variables [has_zero_morphisms V]
/--
We can "augment" a cochain complex by inserting an arbitrary object in degree zero
(shifting everything else up), along with a suitable differential.
-/
def augment (C : cochain_complex V ℕ) {X : V} (f : X ⟶ C.X 0) (w : f ≫ C.d 0 1 = 0) :
cochain_complex V ℕ :=
{ X := λ i, match i with
| 0 := X
| (i+1) := C.X i
end,
d := λ i j, match i, j with
| 0, 1 := f
| (i+1), (j+1) := C.d i j
| _, _ := 0
end,
shape' := λ i j s, begin
simp at s,
rcases j with _|_|j; cases i; unfold_aux; try { simp },
{ simpa using s, },
{ rw [C.shape], simp only [complex_shape.up_rel], contrapose! s, rw ←s },
end,
d_comp_d' := λ i j k hij hjk, begin
rcases k with _|_|k; rcases j with _|_|j; cases i; unfold_aux; try { simp },
cases k,
{ exact w, },
{ rw [C.shape, comp_zero],
simp only [nat.nat_zero_eq_zero, complex_shape.up_rel, zero_add],
exact (nat.one_lt_succ_succ _).ne },
end, }
@[simp] lemma augment_X_zero
(C : cochain_complex V ℕ) {X : V} (f : X ⟶ C.X 0) (w : f ≫ C.d 0 1 = 0) :
(augment C f w).X 0 = X := rfl
@[simp] lemma augment_X_succ
(C : cochain_complex V ℕ) {X : V} (f : X ⟶ C.X 0) (w : f ≫ C.d 0 1 = 0) (i : ℕ) :
(augment C f w).X (i+1) = C.X i := rfl
@[simp] lemma augment_d_zero_one
(C : cochain_complex V ℕ) {X : V} (f : X ⟶ C.X 0) (w : f ≫ C.d 0 1 = 0) :
(augment C f w).d 0 1 = f := rfl
@[simp] lemma augment_d_succ_succ
(C : cochain_complex V ℕ) {X : V} (f : X ⟶ C.X 0) (w : f ≫ C.d 0 1 = 0) (i j : ℕ) :
(augment C f w).d (i+1) (j+1) = C.d i j :=
rfl
/--
Truncating an augmented cochain complex is isomorphic (with components the identity)
to the original complex.
-/
def truncate_augment (C : cochain_complex V ℕ) {X : V} (f : X ⟶ C.X 0) (w : f ≫ C.d 0 1 = 0) :
truncate.obj (augment C f w) ≅ C :=
{ hom :=
{ f := λ i, 𝟙 _, },
inv :=
{ f := λ i, by { exact 𝟙 _, },
comm' := λ i j, by { cases j; { dsimp, simp, }, }, },
hom_inv_id' := by { ext i, cases i; { dsimp, simp, }, },
inv_hom_id' := by { ext i, cases i; { dsimp, simp, }, }, }.
@[simp] lemma truncate_augment_hom_f
(C : cochain_complex V ℕ) {X : V} (f : X ⟶ C.X 0) (w : f ≫ C.d 0 1 = 0) (i : ℕ) :
(truncate_augment C f w).hom.f i = 𝟙 (C.X i) := rfl
@[simp] lemma truncate_augment_inv_f
(C : cochain_complex V ℕ) {X : V} (f : X ⟶ C.X 0) (w : f ≫ C.d 0 1 = 0) (i : ℕ) :
(truncate_augment C f w).inv.f i = 𝟙 ((truncate.obj (augment C f w)).X i) :=
rfl
@[simp] lemma cochain_complex_d_succ_succ_zero (C : cochain_complex V ℕ) (i : ℕ) :
C.d 0 (i+2) = 0 :=
by { rw C.shape, simp only [complex_shape.up_rel, zero_add], exact (nat.one_lt_succ_succ _).ne }
/--
Augmenting a truncated complex with the original object and morphism is isomorphic
(with components the identity) to the original complex.
-/
def augment_truncate (C : cochain_complex V ℕ) :
augment (truncate.obj C) (C.d 0 1) (C.d_comp_d _ _ _) ≅ C :=
{ hom :=
{ f := λ i, by { cases i; exact 𝟙 _, },
comm' := λ i j, by { rcases j with _|_|j; cases i; { dsimp, simp, }, }, },
inv :=
{ f := λ i, by { cases i; exact 𝟙 _, },
comm' := λ i j, by { rcases j with _|_|j; cases i; { dsimp, simp, }, }, },
hom_inv_id' := by { ext i, cases i; { dsimp, simp, }, },
inv_hom_id' := by { ext i, cases i; { dsimp, simp, }, }, }.
@[simp] lemma augment_truncate_hom_f_zero (C : cochain_complex V ℕ) :
(augment_truncate C).hom.f 0 = 𝟙 (C.X 0) :=
rfl
@[simp] lemma augment_truncate_hom_f_succ (C : cochain_complex V ℕ) (i : ℕ) :
(augment_truncate C).hom.f (i+1) = 𝟙 (C.X (i+1)) :=
rfl
@[simp] lemma augment_truncate_inv_f_zero (C : cochain_complex V ℕ) :
(augment_truncate C).inv.f 0 = 𝟙 (C.X 0) :=
rfl
@[simp] lemma augment_truncate_inv_f_succ (C : cochain_complex V ℕ) (i : ℕ) :
(augment_truncate C).inv.f (i+1) = 𝟙 (C.X (i+1)) :=
rfl
/--
A chain map from a single object cochain complex in degree zero to a cochain complex
can be reinterpreted as a cochain complex.
Ths is the inverse construction of `to_truncate`.
-/
def from_single₀_as_complex
[has_zero_object V] (C : cochain_complex V ℕ) (X : V) (f : (single₀ V).obj X ⟶ C) :
cochain_complex V ℕ :=
let ⟨f, w⟩ := from_single₀_equiv C X f in augment C f w
end cochain_complex
|
23f474fffa3ca7accd04bd22db43646ceccc02d8 | 432d948a4d3d242fdfb44b81c9e1b1baacd58617 | /src/data/set/basic.lean | 7a9682390f1d44c63c33951d15cf6853cfbc0d7b | [
"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 | 106,457 | lean | /-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import logic.unique
import order.boolean_algebra
/-!
# Basic properties of sets
Sets in Lean are homogeneous; all their elements have the same type. Sets whose elements
have type `X` are thus defined as `set X := X → Prop`. Note that this function need not
be decidable. The definition is in the core library.
This file provides some basic definitions related to sets and functions not present in the core
library, as well as extra lemmas for functions in the core library (empty set, univ, union,
intersection, insert, singleton, set-theoretic difference, complement, and powerset).
Note that a set is a term, not a type. There is a coercion from `set α` to `Type*` sending
`s` to the corresponding subtype `↥s`.
See also the file `set_theory/zfc.lean`, which contains an encoding of ZFC set theory in Lean.
## Main definitions
Notation used here:
- `f : α → β` is a function,
- `s : set α` and `s₁ s₂ : set α` are subsets of `α`
- `t : set β` is a subset of `β`.
Definitions in the file:
* `strict_subset s₁ s₂ : Prop` : the predicate `s₁ ⊆ s₂` but `s₁ ≠ s₂`.
* `nonempty s : Prop` : the predicate `s ≠ ∅`. Note that this is the preferred way to express the
fact that `s` has an element (see the Implementation Notes).
* `preimage f t : set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β.
* `subsingleton s : Prop` : the predicate saying that `s` has at most one element.
* `range f : set β` : the image of `univ` under `f`.
Also works for `{p : Prop} (f : p → α)` (unlike `image`)
* `s.prod t : set (α × β)` : the subset `s × t`.
* `inclusion s₁ s₂ : ↥s₁ → ↥s₂` : the map `↥s₁ → ↥s₂` induced by an inclusion `s₁ ⊆ s₂`.
## Notation
* `f ⁻¹' t` for `preimage f t`
* `f '' s` for `image f s`
* `sᶜ` for the complement of `s`
## Implementation notes
* `s.nonempty` is to be preferred to `s ≠ ∅` or `∃ x, x ∈ s`. It has the advantage that
the `s.nonempty` dot notation can be used.
* For `s : set α`, do not use `subtype s`. Instead use `↥s` or `(s : Type*)` or `s`.
## Tags
set, sets, subset, subsets, image, preimage, pre-image, range, union, intersection, insert,
singleton, complement, powerset
-/
/-! ### Set coercion to a type -/
open function
universe variables u v w x
run_cmd do e ← tactic.get_env,
tactic.set_env $ e.mk_protected `set.compl
namespace set
variable {α : Type*}
instance : has_le (set α) := ⟨(⊆)⟩
instance : has_lt (set α) := ⟨λ s t, s ≤ t ∧ ¬t ≤ s⟩ -- `⊂` is not defined until further down
instance {α : Type*} : boolean_algebra (set α) :=
{ sup := (∪),
le := (≤),
lt := (<),
inf := (∩),
bot := ∅,
compl := set.compl,
top := univ,
sdiff := (\),
.. (infer_instance : boolean_algebra (α → Prop)) }
@[simp] lemma top_eq_univ : (⊤ : set α) = univ := rfl
@[simp] lemma bot_eq_empty : (⊥ : set α) = ∅ := rfl
@[simp] lemma sup_eq_union : ((⊔) : set α → set α → set α) = (∪) := rfl
@[simp] lemma inf_eq_inter : ((⊓) : set α → set α → set α) = (∩) := rfl
@[simp] lemma le_eq_subset : ((≤) : set α → set α → Prop) = (⊆) := rfl
/-! `set.lt_eq_ssubset` is defined further down -/
/-- Coercion from a set to the corresponding subtype. -/
instance {α : Type*} : has_coe_to_sort (set α) := ⟨_, λ s, {x // x ∈ s}⟩
instance pi_set_coe.can_lift (ι : Type u) (α : Π i : ι, Type v) [ne : Π i, nonempty (α i)]
(s : set ι) :
can_lift (Π i : s, α i) (Π i, α i) :=
{ coe := λ f i, f i,
.. pi_subtype.can_lift ι α s }
instance pi_set_coe.can_lift' (ι : Type u) (α : Type v) [ne : nonempty α] (s : set ι) :
can_lift (s → α) (ι → α) :=
pi_set_coe.can_lift ι (λ _, α) s
instance set_coe.can_lift (s : set α) : can_lift α s :=
{ coe := coe,
cond := λ a, a ∈ s,
prf := λ a ha, ⟨⟨a, ha⟩, rfl⟩ }
end set
section set_coe
variables {α : Type u}
theorem set.set_coe_eq_subtype (s : set α) :
coe_sort.{(u+1) (u+2)} s = {x // x ∈ s} := rfl
@[simp] theorem set_coe.forall {s : set α} {p : s → Prop} :
(∀ x : s, p x) ↔ (∀ x (h : x ∈ s), p ⟨x, h⟩) :=
subtype.forall
@[simp] theorem set_coe.exists {s : set α} {p : s → Prop} :
(∃ x : s, p x) ↔ (∃ x (h : x ∈ s), p ⟨x, h⟩) :=
subtype.exists
theorem set_coe.exists' {s : set α} {p : Π x, x ∈ s → Prop} :
(∃ x (h : x ∈ s), p x h) ↔ (∃ x : s, p x x.2) :=
(@set_coe.exists _ _ $ λ x, p x.1 x.2).symm
theorem set_coe.forall' {s : set α} {p : Π x, x ∈ s → Prop} :
(∀ x (h : x ∈ s), p x h) ↔ (∀ x : s, p x x.2) :=
(@set_coe.forall _ _ $ λ x, p x.1 x.2).symm
@[simp] theorem set_coe_cast : ∀ {s t : set α} (H' : s = t) (H : @eq (Type u) s t) (x : s),
cast H x = ⟨x.1, H' ▸ x.2⟩
| s _ rfl _ ⟨x, h⟩ := rfl
theorem set_coe.ext {s : set α} {a b : s} : (↑a : α) = ↑b → a = b :=
subtype.eq
theorem set_coe.ext_iff {s : set α} {a b : s} : (↑a : α) = ↑b ↔ a = b :=
iff.intro set_coe.ext (assume h, h ▸ rfl)
end set_coe
/-- See also `subtype.prop` -/
lemma subtype.mem {α : Type*} {s : set α} (p : s) : (p : α) ∈ s := p.prop
lemma eq.subset {α} {s t : set α} : s = t → s ⊆ t :=
by { rintro rfl x hx, exact hx }
namespace set
variables {α : Type u} {β : Type v} {γ : Type w} {ι : Sort x} {a : α} {s t : set α}
instance : inhabited (set α) := ⟨∅⟩
@[ext]
theorem ext {a b : set α} (h : ∀ x, x ∈ a ↔ x ∈ b) : a = b :=
funext (assume x, propext (h x))
theorem ext_iff {s t : set α} : s = t ↔ ∀ x, x ∈ s ↔ x ∈ t :=
⟨λ h x, by rw h, ext⟩
@[trans] theorem mem_of_mem_of_subset {x : α} {s t : set α}
(hx : x ∈ s) (h : s ⊆ t) : x ∈ t := h hx
/-! ### Lemmas about `mem` and `set_of` -/
@[simp] theorem mem_set_of_eq {a : α} {p : α → Prop} : a ∈ {a | p a} = p a := rfl
theorem nmem_set_of_eq {a : α} {P : α → Prop} : a ∉ {a : α | P a} = ¬ P a := rfl
@[simp] theorem set_of_mem_eq {s : set α} : {x | x ∈ s} = s := rfl
theorem set_of_set {s : set α} : set_of s = s := rfl
lemma set_of_app_iff {p : α → Prop} {x : α} : { x | p x } x ↔ p x := iff.rfl
theorem mem_def {a : α} {s : set α} : a ∈ s ↔ s a := iff.rfl
instance decidable_mem (s : set α) [H : decidable_pred s] : ∀ a, decidable (a ∈ s) := H
instance decidable_set_of (p : α → Prop) [H : decidable_pred p] : decidable_pred {a | p a} := H
@[simp] theorem set_of_subset_set_of {p q : α → Prop} :
{a | p a} ⊆ {a | q a} ↔ (∀a, p a → q a) := iff.rfl
@[simp] lemma sep_set_of {p q : α → Prop} : {a ∈ {a | p a } | q a} = {a | p a ∧ q a} := rfl
lemma set_of_and {p q : α → Prop} : {a | p a ∧ q a} = {a | p a} ∩ {a | q a} := rfl
lemma set_of_or {p q : α → Prop} : {a | p a ∨ q a} = {a | p a} ∪ {a | q a} := rfl
/-! ### Lemmas about subsets -/
-- TODO(Jeremy): write a tactic to unfold specific instances of generic notation?
theorem subset_def {s t : set α} : (s ⊆ t) = ∀ x, x ∈ s → x ∈ t := rfl
@[refl] theorem subset.refl (a : set α) : a ⊆ a := assume x, id
theorem subset.rfl {s : set α} : s ⊆ s := subset.refl s
@[trans] theorem subset.trans {a b c : set α} (ab : a ⊆ b) (bc : b ⊆ c) : a ⊆ c :=
assume x h, bc (ab h)
@[trans] theorem mem_of_eq_of_mem {x y : α} {s : set α} (hx : x = y) (h : y ∈ s) : x ∈ s :=
hx.symm ▸ h
theorem subset.antisymm {a b : set α} (h₁ : a ⊆ b) (h₂ : b ⊆ a) : a = b :=
set.ext $ λ x, ⟨@h₁ _, @h₂ _⟩
theorem subset.antisymm_iff {a b : set α} : a = b ↔ a ⊆ b ∧ b ⊆ a :=
⟨λ e, ⟨e.subset, e.symm.subset⟩, λ ⟨h₁, h₂⟩, subset.antisymm h₁ h₂⟩
-- an alternative name
theorem eq_of_subset_of_subset {a b : set α} : a ⊆ b → b ⊆ a → a = b := subset.antisymm
theorem mem_of_subset_of_mem {s₁ s₂ : set α} {a : α} (h : s₁ ⊆ s₂) : a ∈ s₁ → a ∈ s₂ := @h _
theorem not_mem_subset (h : s ⊆ t) : a ∉ t → a ∉ s :=
mt $ mem_of_subset_of_mem h
theorem not_subset : (¬ s ⊆ t) ↔ ∃a ∈ s, a ∉ t := by simp only [subset_def, not_forall]
/-! ### Definition of strict subsets `s ⊂ t` and basic properties. -/
instance : has_ssubset (set α) := ⟨(<)⟩
@[simp] lemma lt_eq_ssubset : ((<) : set α → set α → Prop) = (⊂) := rfl
theorem ssubset_def : (s ⊂ t) = (s ⊆ t ∧ ¬ (t ⊆ s)) := rfl
theorem eq_or_ssubset_of_subset (h : s ⊆ t) : s = t ∨ s ⊂ t :=
eq_or_lt_of_le h
lemma exists_of_ssubset {s t : set α} (h : s ⊂ t) : (∃x∈t, x ∉ s) :=
not_subset.1 h.2
lemma ssubset_iff_subset_ne {s t : set α} : s ⊂ t ↔ s ⊆ t ∧ s ≠ t :=
@lt_iff_le_and_ne (set α) _ s t
lemma ssubset_iff_of_subset {s t : set α} (h : s ⊆ t) : s ⊂ t ↔ ∃ x ∈ t, x ∉ s :=
⟨exists_of_ssubset, λ ⟨x, hxt, hxs⟩, ⟨h, λ h, hxs $ h hxt⟩⟩
lemma ssubset_of_ssubset_of_subset {s₁ s₂ s₃ : set α} (hs₁s₂ : s₁ ⊂ s₂) (hs₂s₃ : s₂ ⊆ s₃) :
s₁ ⊂ s₃ :=
⟨subset.trans hs₁s₂.1 hs₂s₃, λ hs₃s₁, hs₁s₂.2 (subset.trans hs₂s₃ hs₃s₁)⟩
lemma ssubset_of_subset_of_ssubset {s₁ s₂ s₃ : set α} (hs₁s₂ : s₁ ⊆ s₂) (hs₂s₃ : s₂ ⊂ s₃) :
s₁ ⊂ s₃ :=
⟨subset.trans hs₁s₂ hs₂s₃.1, λ hs₃s₁, hs₂s₃.2 (subset.trans hs₃s₁ hs₁s₂)⟩
theorem not_mem_empty (x : α) : ¬ (x ∈ (∅ : set α)) := id
@[simp] theorem not_not_mem : ¬ (a ∉ s) ↔ a ∈ s := not_not
/-! ### Non-empty sets -/
/-- The property `s.nonempty` expresses the fact that the set `s` is not empty. It should be used
in theorem assumptions instead of `∃ x, x ∈ s` or `s ≠ ∅` as it gives access to a nice API thanks
to the dot notation. -/
protected def nonempty (s : set α) : Prop := ∃ x, x ∈ s
lemma nonempty_def : s.nonempty ↔ ∃ x, x ∈ s := iff.rfl
lemma nonempty_of_mem {x} (h : x ∈ s) : s.nonempty := ⟨x, h⟩
theorem nonempty.not_subset_empty : s.nonempty → ¬(s ⊆ ∅)
| ⟨x, hx⟩ hs := hs hx
theorem nonempty.ne_empty : ∀ {s : set α}, s.nonempty → s ≠ ∅
| _ ⟨x, hx⟩ rfl := hx
@[simp] theorem not_nonempty_empty : ¬(∅ : set α).nonempty :=
λ h, h.ne_empty rfl
/-- Extract a witness from `s.nonempty`. This function might be used instead of case analysis
on the argument. Note that it makes a proof depend on the `classical.choice` axiom. -/
protected noncomputable def nonempty.some (h : s.nonempty) : α := classical.some h
protected lemma nonempty.some_mem (h : s.nonempty) : h.some ∈ s := classical.some_spec h
lemma nonempty.mono (ht : s ⊆ t) (hs : s.nonempty) : t.nonempty := hs.imp ht
lemma nonempty_of_not_subset (h : ¬s ⊆ t) : (s \ t).nonempty :=
let ⟨x, xs, xt⟩ := not_subset.1 h in ⟨x, xs, xt⟩
lemma nonempty_of_ssubset (ht : s ⊂ t) : (t \ s).nonempty :=
nonempty_of_not_subset ht.2
lemma nonempty.of_diff (h : (s \ t).nonempty) : s.nonempty := h.imp $ λ _, and.left
lemma nonempty_of_ssubset' (ht : s ⊂ t) : t.nonempty := (nonempty_of_ssubset ht).of_diff
lemma nonempty.inl (hs : s.nonempty) : (s ∪ t).nonempty := hs.imp $ λ _, or.inl
lemma nonempty.inr (ht : t.nonempty) : (s ∪ t).nonempty := ht.imp $ λ _, or.inr
@[simp] lemma union_nonempty : (s ∪ t).nonempty ↔ s.nonempty ∨ t.nonempty := exists_or_distrib
lemma nonempty.left (h : (s ∩ t).nonempty) : s.nonempty := h.imp $ λ _, and.left
lemma nonempty.right (h : (s ∩ t).nonempty) : t.nonempty := h.imp $ λ _, and.right
lemma nonempty_inter_iff_exists_right : (s ∩ t).nonempty ↔ ∃ x : t, ↑x ∈ s :=
⟨λ ⟨x, xs, xt⟩, ⟨⟨x, xt⟩, xs⟩, λ ⟨⟨x, xt⟩, xs⟩, ⟨x, xs, xt⟩⟩
lemma nonempty_inter_iff_exists_left : (s ∩ t).nonempty ↔ ∃ x : s, ↑x ∈ t :=
⟨λ ⟨x, xs, xt⟩, ⟨⟨x, xs⟩, xt⟩, λ ⟨⟨x, xt⟩, xs⟩, ⟨x, xt, xs⟩⟩
lemma nonempty_iff_univ_nonempty : nonempty α ↔ (univ : set α).nonempty :=
⟨λ ⟨x⟩, ⟨x, trivial⟩, λ ⟨x, _⟩, ⟨x⟩⟩
@[simp] lemma univ_nonempty : ∀ [h : nonempty α], (univ : set α).nonempty
| ⟨x⟩ := ⟨x, trivial⟩
lemma nonempty.to_subtype (h : s.nonempty) : nonempty s :=
nonempty_subtype.2 h
instance [nonempty α] : nonempty (set.univ : set α) := set.univ_nonempty.to_subtype
@[simp] lemma nonempty_insert (a : α) (s : set α) : (insert a s).nonempty := ⟨a, or.inl rfl⟩
lemma nonempty_of_nonempty_subtype [nonempty s] : s.nonempty :=
nonempty_subtype.mp ‹_›
/-! ### Lemmas about the empty set -/
theorem empty_def : (∅ : set α) = {x | false} := rfl
@[simp] theorem mem_empty_eq (x : α) : x ∈ (∅ : set α) = false := rfl
@[simp] theorem set_of_false : {a : α | false} = ∅ := rfl
@[simp] theorem empty_subset (s : set α) : ∅ ⊆ s.
theorem subset_empty_iff {s : set α} : s ⊆ ∅ ↔ s = ∅ :=
(subset.antisymm_iff.trans $ and_iff_left (empty_subset _)).symm
theorem eq_empty_iff_forall_not_mem {s : set α} : s = ∅ ↔ ∀ x, x ∉ s := subset_empty_iff.symm
theorem eq_empty_of_subset_empty {s : set α} : s ⊆ ∅ → s = ∅ := subset_empty_iff.1
theorem eq_empty_of_not_nonempty (h : ¬nonempty α) (s : set α) : s = ∅ :=
eq_empty_of_subset_empty $ λ x hx, h ⟨x⟩
lemma not_nonempty_iff_eq_empty {s : set α} : ¬s.nonempty ↔ s = ∅ :=
by simp only [set.nonempty, eq_empty_iff_forall_not_mem, not_exists]
lemma empty_not_nonempty : ¬(∅ : set α).nonempty := λ h, h.ne_empty rfl
theorem ne_empty_iff_nonempty : s ≠ ∅ ↔ s.nonempty := not_iff_comm.1 not_nonempty_iff_eq_empty
lemma eq_empty_or_nonempty (s : set α) : s = ∅ ∨ s.nonempty :=
or_iff_not_imp_left.2 ne_empty_iff_nonempty.1
theorem subset_eq_empty {s t : set α} (h : t ⊆ s) (e : s = ∅) : t = ∅ :=
subset_empty_iff.1 $ e ▸ h
theorem ball_empty_iff {p : α → Prop} : (∀ x ∈ (∅ : set α), p x) ↔ true :=
iff_true_intro $ λ x, false.elim
/-!
### Universal set.
In Lean `@univ α` (or `univ : set α`) is the set that contains all elements of type `α`.
Mathematically it is the same as `α` but it has a different type.
-/
@[simp] theorem set_of_true : {x : α | true} = univ := rfl
@[simp] theorem mem_univ (x : α) : x ∈ @univ α := trivial
@[simp] lemma univ_eq_empty_iff : (univ : set α) = ∅ ↔ ¬ nonempty α :=
eq_empty_iff_forall_not_mem.trans ⟨λ H ⟨x⟩, H x trivial, λ H x _, H ⟨x⟩⟩
theorem empty_ne_univ [h : nonempty α] : (∅ : set α) ≠ univ :=
λ e, univ_eq_empty_iff.1 e.symm h
@[simp] theorem subset_univ (s : set α) : s ⊆ univ := λ x H, trivial
theorem univ_subset_iff {s : set α} : univ ⊆ s ↔ s = univ :=
(subset.antisymm_iff.trans $ and_iff_right (subset_univ _)).symm
theorem eq_univ_of_univ_subset {s : set α} : univ ⊆ s → s = univ := univ_subset_iff.1
theorem eq_univ_iff_forall {s : set α} : s = univ ↔ ∀ x, x ∈ s :=
univ_subset_iff.symm.trans $ forall_congr $ λ x, imp_iff_right ⟨⟩
theorem eq_univ_of_forall {s : set α} : (∀ x, x ∈ s) → s = univ := eq_univ_iff_forall.2
lemma eq_univ_of_subset {s t : set α} (h : s ⊆ t) (hs : s = univ) : t = univ :=
eq_univ_of_univ_subset $ hs ▸ h
lemma exists_mem_of_nonempty (α) : ∀ [nonempty α], ∃x:α, x ∈ (univ : set α)
| ⟨x⟩ := ⟨x, trivial⟩
instance univ_decidable : decidable_pred (@set.univ α) :=
λ x, is_true trivial
/-- `diagonal α` is the subset of `α × α` consisting of all pairs of the form `(a, a)`. -/
def diagonal (α : Type*) : set (α × α) := {p | p.1 = p.2}
@[simp]
lemma mem_diagonal {α : Type*} (x : α) : (x, x) ∈ diagonal α :=
by simp [diagonal]
/-! ### Lemmas about union -/
theorem union_def {s₁ s₂ : set α} : s₁ ∪ s₂ = {a | a ∈ s₁ ∨ a ∈ s₂} := rfl
theorem mem_union_left {x : α} {a : set α} (b : set α) : x ∈ a → x ∈ a ∪ b := or.inl
theorem mem_union_right {x : α} {b : set α} (a : set α) : x ∈ b → x ∈ a ∪ b := or.inr
theorem mem_or_mem_of_mem_union {x : α} {a b : set α} (H : x ∈ a ∪ b) : x ∈ a ∨ x ∈ b := H
theorem mem_union.elim {x : α} {a b : set α} {P : Prop}
(H₁ : x ∈ a ∪ b) (H₂ : x ∈ a → P) (H₃ : x ∈ b → P) : P :=
or.elim H₁ H₂ H₃
theorem mem_union (x : α) (a b : set α) : x ∈ a ∪ b ↔ x ∈ a ∨ x ∈ b := iff.rfl
@[simp] theorem mem_union_eq (x : α) (a b : set α) : x ∈ a ∪ b = (x ∈ a ∨ x ∈ b) := rfl
@[simp] theorem union_self (a : set α) : a ∪ a = a := ext $ λ x, or_self _
@[simp] theorem union_empty (a : set α) : a ∪ ∅ = a := ext $ λ x, or_false _
@[simp] theorem empty_union (a : set α) : ∅ ∪ a = a := ext $ λ x, false_or _
theorem union_comm (a b : set α) : a ∪ b = b ∪ a := ext $ λ x, or.comm
theorem union_assoc (a b c : set α) : (a ∪ b) ∪ c = a ∪ (b ∪ c) := ext $ λ x, or.assoc
instance union_is_assoc : is_associative (set α) (∪) := ⟨union_assoc⟩
instance union_is_comm : is_commutative (set α) (∪) := ⟨union_comm⟩
theorem union_left_comm (s₁ s₂ s₃ : set α) : s₁ ∪ (s₂ ∪ s₃) = s₂ ∪ (s₁ ∪ s₃) :=
ext $ λ x, or.left_comm
theorem union_right_comm (s₁ s₂ s₃ : set α) : (s₁ ∪ s₂) ∪ s₃ = (s₁ ∪ s₃) ∪ s₂ :=
ext $ λ x, or.right_comm
theorem union_eq_self_of_subset_left {s t : set α} (h : s ⊆ t) : s ∪ t = t :=
ext $ λ x, or_iff_right_of_imp $ @h _
theorem union_eq_self_of_subset_right {s t : set α} (h : t ⊆ s) : s ∪ t = s :=
ext $ λ x, or_iff_left_of_imp $ @h _
@[simp] theorem subset_union_left (s t : set α) : s ⊆ s ∪ t := λ x, or.inl
@[simp] theorem subset_union_right (s t : set α) : t ⊆ s ∪ t := λ x, or.inr
theorem union_subset {s t r : set α} (sr : s ⊆ r) (tr : t ⊆ r) : s ∪ t ⊆ r :=
λ x, or.rec (@sr _) (@tr _)
@[simp] theorem union_subset_iff {s t u : set α} : s ∪ t ⊆ u ↔ s ⊆ u ∧ t ⊆ u :=
(forall_congr (by exact λ x, or_imp_distrib)).trans forall_and_distrib
theorem union_subset_union {s₁ s₂ t₁ t₂ : set α}
(h₁ : s₁ ⊆ s₂) (h₂ : t₁ ⊆ t₂) : s₁ ∪ t₁ ⊆ s₂ ∪ t₂ := λ x, or.imp (@h₁ _) (@h₂ _)
theorem union_subset_union_left {s₁ s₂ : set α} (t) (h : s₁ ⊆ s₂) : s₁ ∪ t ⊆ s₂ ∪ t :=
union_subset_union h subset.rfl
theorem union_subset_union_right (s) {t₁ t₂ : set α} (h : t₁ ⊆ t₂) : s ∪ t₁ ⊆ s ∪ t₂ :=
union_subset_union subset.rfl h
lemma subset_union_of_subset_left {s t : set α} (h : s ⊆ t) (u : set α) : s ⊆ t ∪ u :=
subset.trans h (subset_union_left t u)
lemma subset_union_of_subset_right {s u : set α} (h : s ⊆ u) (t : set α) : s ⊆ t ∪ u :=
subset.trans h (subset_union_right t u)
@[simp] theorem union_empty_iff {s t : set α} : s ∪ t = ∅ ↔ s = ∅ ∧ t = ∅ :=
by simp only [← subset_empty_iff]; exact union_subset_iff
@[simp] lemma union_univ {s : set α} : s ∪ univ = univ := sup_top_eq
@[simp] lemma univ_union {s : set α} : univ ∪ s = univ := top_sup_eq
/-! ### Lemmas about intersection -/
theorem inter_def {s₁ s₂ : set α} : s₁ ∩ s₂ = {a | a ∈ s₁ ∧ a ∈ s₂} := rfl
theorem mem_inter_iff (x : α) (a b : set α) : x ∈ a ∩ b ↔ x ∈ a ∧ x ∈ b := iff.rfl
@[simp] theorem mem_inter_eq (x : α) (a b : set α) : x ∈ a ∩ b = (x ∈ a ∧ x ∈ b) := rfl
theorem mem_inter {x : α} {a b : set α} (ha : x ∈ a) (hb : x ∈ b) : x ∈ a ∩ b := ⟨ha, hb⟩
theorem mem_of_mem_inter_left {x : α} {a b : set α} (h : x ∈ a ∩ b) : x ∈ a := h.left
theorem mem_of_mem_inter_right {x : α} {a b : set α} (h : x ∈ a ∩ b) : x ∈ b := h.right
@[simp] theorem inter_self (a : set α) : a ∩ a = a := ext $ λ x, and_self _
@[simp] theorem inter_empty (a : set α) : a ∩ ∅ = ∅ := ext $ λ x, and_false _
@[simp] theorem empty_inter (a : set α) : ∅ ∩ a = ∅ := ext $ λ x, false_and _
theorem inter_comm (a b : set α) : a ∩ b = b ∩ a := ext $ λ x, and.comm
theorem inter_assoc (a b c : set α) : (a ∩ b) ∩ c = a ∩ (b ∩ c) := ext $ λ x, and.assoc
instance inter_is_assoc : is_associative (set α) (∩) := ⟨inter_assoc⟩
instance inter_is_comm : is_commutative (set α) (∩) := ⟨inter_comm⟩
theorem inter_left_comm (s₁ s₂ s₃ : set α) : s₁ ∩ (s₂ ∩ s₃) = s₂ ∩ (s₁ ∩ s₃) :=
ext $ λ x, and.left_comm
theorem inter_right_comm (s₁ s₂ s₃ : set α) : (s₁ ∩ s₂) ∩ s₃ = (s₁ ∩ s₃) ∩ s₂ :=
ext $ λ x, and.right_comm
@[simp] theorem inter_subset_left (s t : set α) : s ∩ t ⊆ s := λ x, and.left
@[simp] theorem inter_subset_right (s t : set α) : s ∩ t ⊆ t := λ x, and.right
theorem subset_inter {s t r : set α} (rs : r ⊆ s) (rt : r ⊆ t) : r ⊆ s ∩ t := λ x h, ⟨rs h, rt h⟩
@[simp] theorem subset_inter_iff {s t r : set α} : r ⊆ s ∩ t ↔ r ⊆ s ∧ r ⊆ t :=
(forall_congr (by exact λ x, imp_and_distrib)).trans forall_and_distrib
theorem inter_eq_left_iff_subset {s t : set α} : s ∩ t = s ↔ s ⊆ t :=
ext_iff.trans $ forall_congr $ λ x, and_iff_left_iff_imp
theorem inter_eq_right_iff_subset {s t : set α} : s ∩ t = t ↔ t ⊆ s :=
ext_iff.trans $ forall_congr $ λ x, and_iff_right_iff_imp
theorem inter_eq_self_of_subset_left {s t : set α} : s ⊆ t → s ∩ t = s :=
inter_eq_left_iff_subset.mpr
theorem inter_eq_self_of_subset_right {s t : set α} : t ⊆ s → s ∩ t = t :=
inter_eq_right_iff_subset.mpr
@[simp] theorem inter_univ (a : set α) : a ∩ univ = a :=
inter_eq_self_of_subset_left $ subset_univ _
@[simp] theorem univ_inter (a : set α) : univ ∩ a = a :=
inter_eq_self_of_subset_right $ subset_univ _
theorem inter_subset_inter {s₁ s₂ t₁ t₂ : set α}
(h₁ : s₁ ⊆ t₁) (h₂ : s₂ ⊆ t₂) : s₁ ∩ s₂ ⊆ t₁ ∩ t₂ := λ x, and.imp (@h₁ _) (@h₂ _)
theorem inter_subset_inter_left {s t : set α} (u : set α) (H : s ⊆ t) : s ∩ u ⊆ t ∩ u :=
inter_subset_inter H subset.rfl
theorem inter_subset_inter_right {s t : set α} (u : set α) (H : s ⊆ t) : u ∩ s ⊆ u ∩ t :=
inter_subset_inter subset.rfl H
theorem union_inter_cancel_left {s t : set α} : (s ∪ t) ∩ s = s :=
inter_eq_self_of_subset_right $ subset_union_left _ _
theorem union_inter_cancel_right {s t : set α} : (s ∪ t) ∩ t = t :=
inter_eq_self_of_subset_right $ subset_union_right _ _
/-! ### Distributivity laws -/
theorem inter_distrib_left (s t u : set α) : s ∩ (t ∪ u) = (s ∩ t) ∪ (s ∩ u) :=
inf_sup_left
theorem inter_union_distrib_left {s t u : set α} : s ∩ (t ∪ u) = (s ∩ t) ∪ (s ∩ u) :=
inf_sup_left
theorem inter_distrib_right (s t u : set α) : (s ∪ t) ∩ u = (s ∩ u) ∪ (t ∩ u) :=
inf_sup_right
theorem union_inter_distrib_right {s t u : set α} : (s ∪ t) ∩ u = (s ∩ u) ∪ (t ∩ u) :=
inf_sup_right
theorem union_distrib_left (s t u : set α) : s ∪ (t ∩ u) = (s ∪ t) ∩ (s ∪ u) :=
sup_inf_left
theorem union_inter_distrib_left {s t u : set α} : s ∪ (t ∩ u) = (s ∪ t) ∩ (s ∪ u) :=
sup_inf_left
theorem union_distrib_right (s t u : set α) : (s ∩ t) ∪ u = (s ∪ u) ∩ (t ∪ u) :=
sup_inf_right
theorem inter_union_distrib_right {s t u : set α} : (s ∩ t) ∪ u = (s ∪ u) ∩ (t ∪ u) :=
sup_inf_right
/-!
### Lemmas about `insert`
`insert α s` is the set `{α} ∪ s`.
-/
theorem insert_def (x : α) (s : set α) : insert x s = { y | y = x ∨ y ∈ s } := rfl
@[simp] theorem subset_insert (x : α) (s : set α) : s ⊆ insert x s := λ y, or.inr
theorem mem_insert (x : α) (s : set α) : x ∈ insert x s := or.inl rfl
theorem mem_insert_of_mem {x : α} {s : set α} (y : α) : x ∈ s → x ∈ insert y s := or.inr
theorem eq_or_mem_of_mem_insert {x a : α} {s : set α} : x ∈ insert a s → x = a ∨ x ∈ s := id
theorem mem_of_mem_insert_of_ne {x a : α} {s : set α} : x ∈ insert a s → x ≠ a → x ∈ s :=
or.resolve_left
@[simp] theorem mem_insert_iff {x a : α} {s : set α} : x ∈ insert a s ↔ x = a ∨ x ∈ s := iff.rfl
@[simp] theorem insert_eq_of_mem {a : α} {s : set α} (h : a ∈ s) : insert a s = s :=
ext $ λ x, or_iff_right_of_imp $ λ e, e.symm ▸ h
lemma ne_insert_of_not_mem {s : set α} (t : set α) {a : α} : a ∉ s → s ≠ insert a t :=
mt $ λ e, e.symm ▸ mem_insert _ _
theorem insert_subset : insert a s ⊆ t ↔ (a ∈ t ∧ s ⊆ t) :=
by simp only [subset_def, or_imp_distrib, forall_and_distrib, forall_eq, mem_insert_iff]
theorem insert_subset_insert (h : s ⊆ t) : insert a s ⊆ insert a t := λ x, or.imp_right (@h _)
theorem ssubset_iff_insert {s t : set α} : s ⊂ t ↔ ∃ a ∉ s, insert a s ⊆ t :=
begin
simp only [insert_subset, exists_and_distrib_right, ssubset_def, not_subset],
simp only [exists_prop, and_comm]
end
theorem ssubset_insert {s : set α} {a : α} (h : a ∉ s) : s ⊂ insert a s :=
ssubset_iff_insert.2 ⟨a, h, subset.refl _⟩
theorem insert_comm (a b : α) (s : set α) : insert a (insert b s) = insert b (insert a s) :=
ext $ λ x, or.left_comm
theorem insert_union : insert a s ∪ t = insert a (s ∪ t) := ext $ λ x, or.assoc
@[simp] theorem union_insert : s ∪ insert a t = insert a (s ∪ t) := ext $ λ x, or.left_comm
theorem insert_nonempty (a : α) (s : set α) : (insert a s).nonempty := ⟨a, mem_insert a s⟩
instance (a : α) (s : set α) : nonempty (insert a s : set α) := (insert_nonempty a s).to_subtype
lemma insert_inter (x : α) (s t : set α) : insert x (s ∩ t) = insert x s ∩ insert x t :=
ext $ λ y, or_and_distrib_left
-- useful in proofs by induction
theorem forall_of_forall_insert {P : α → Prop} {a : α} {s : set α}
(H : ∀ x, x ∈ insert a s → P x) (x) (h : x ∈ s) : P x := H _ (or.inr h)
theorem forall_insert_of_forall {P : α → Prop} {a : α} {s : set α}
(H : ∀ x, x ∈ s → P x) (ha : P a) (x) (h : x ∈ insert a s) : P x :=
h.elim (λ e, e.symm ▸ ha) (H _)
theorem bex_insert_iff {P : α → Prop} {a : α} {s : set α} :
(∃ x ∈ insert a s, P x) ↔ P a ∨ (∃ x ∈ s, P x) :=
bex_or_left_distrib.trans $ or_congr_left bex_eq_left
theorem ball_insert_iff {P : α → Prop} {a : α} {s : set α} :
(∀ x ∈ insert a s, P x) ↔ P a ∧ (∀x ∈ s, P x) :=
ball_or_left_distrib.trans $ and_congr_left' forall_eq
/-! ### Lemmas about singletons -/
theorem singleton_def (a : α) : ({a} : set α) = insert a ∅ := (insert_emptyc_eq _).symm
@[simp] theorem mem_singleton_iff {a b : α} : a ∈ ({b} : set α) ↔ a = b := iff.rfl
@[simp]
lemma set_of_eq_eq_singleton {a : α} : {n | n = a} = {a} :=
ext $ λ n, (set.mem_singleton_iff).symm
-- TODO: again, annotation needed
@[simp] theorem mem_singleton (a : α) : a ∈ ({a} : set α) := @rfl _ _
theorem eq_of_mem_singleton {x y : α} (h : x ∈ ({y} : set α)) : x = y := h
@[simp] theorem singleton_eq_singleton_iff {x y : α} : {x} = ({y} : set α) ↔ x = y :=
ext_iff.trans eq_iff_eq_cancel_left
theorem mem_singleton_of_eq {x y : α} (H : x = y) : x ∈ ({y} : set α) := H
theorem insert_eq (x : α) (s : set α) : insert x s = ({x} : set α) ∪ s := rfl
@[simp] theorem pair_eq_singleton (a : α) : ({a, a} : set α) = {a} := union_self _
theorem pair_comm (a b : α) : ({a, b} : set α) = {b, a} := union_comm _ _
@[simp] theorem singleton_nonempty (a : α) : ({a} : set α).nonempty :=
⟨a, rfl⟩
@[simp] theorem singleton_subset_iff {a : α} {s : set α} : {a} ⊆ s ↔ a ∈ s := forall_eq
theorem set_compr_eq_eq_singleton {a : α} : {b | b = a} = {a} := rfl
@[simp] theorem singleton_union : {a} ∪ s = insert a s := rfl
@[simp] theorem union_singleton : s ∪ {a} = insert a s := union_comm _ _
@[simp] theorem singleton_inter_nonempty : ({a} ∩ s).nonempty ↔ a ∈ s :=
by simp only [set.nonempty, mem_inter_eq, mem_singleton_iff, exists_eq_left]
@[simp] theorem inter_singleton_nonempty : (s ∩ {a}).nonempty ↔ a ∈ s :=
by rw [inter_comm, singleton_inter_nonempty]
@[simp] theorem singleton_inter_eq_empty : {a} ∩ s = ∅ ↔ a ∉ s :=
not_nonempty_iff_eq_empty.symm.trans $ not_congr singleton_inter_nonempty
@[simp] theorem inter_singleton_eq_empty : s ∩ {a} = ∅ ↔ a ∉ s :=
by rw [inter_comm, singleton_inter_eq_empty]
lemma nmem_singleton_empty {s : set α} : s ∉ ({∅} : set (set α)) ↔ s.nonempty :=
ne_empty_iff_nonempty
instance unique_singleton (a : α) : unique ↥({a} : set α) :=
⟨⟨⟨a, mem_singleton a⟩⟩, λ ⟨x, h⟩, subtype.eq h⟩
lemma eq_singleton_iff_unique_mem {s : set α} {a : α} : s = {a} ↔ a ∈ s ∧ ∀ x ∈ s, x = a :=
subset.antisymm_iff.trans $ and.comm.trans $ and_congr_left' singleton_subset_iff
lemma eq_singleton_iff_nonempty_unique_mem {s : set α} {a : α} :
s = {a} ↔ s.nonempty ∧ ∀ x ∈ s, x = a :=
eq_singleton_iff_unique_mem.trans $ and_congr_left $ λ H, ⟨λ h', ⟨_, h'⟩, λ ⟨x, h⟩, H x h ▸ h⟩
-- while `simp` is capable of proving this, it is not capable of turning the LHS into the RHS.
@[simp] lemma default_coe_singleton (x : α) :
default ({x} : set α) = ⟨x, rfl⟩ := rfl
/-! ### Lemmas about sets defined as `{x ∈ s | p x}`. -/
theorem mem_sep {s : set α} {p : α → Prop} {x : α} (xs : x ∈ s) (px : p x) : x ∈ {x ∈ s | p x} :=
⟨xs, px⟩
@[simp] theorem sep_mem_eq {s t : set α} : {x ∈ s | x ∈ t} = s ∩ t := rfl
@[simp] theorem mem_sep_eq {s : set α} {p : α → Prop} {x : α} :
x ∈ {x ∈ s | p x} = (x ∈ s ∧ p x) := rfl
theorem mem_sep_iff {s : set α} {p : α → Prop} {x : α} : x ∈ {x ∈ s | p x} ↔ x ∈ s ∧ p x :=
iff.rfl
theorem eq_sep_of_subset {s t : set α} (h : s ⊆ t) : s = {x ∈ t | x ∈ s} :=
(inter_eq_self_of_subset_right h).symm
theorem sep_subset (s : set α) (p : α → Prop) : {x ∈ s | p x} ⊆ s := λ x, and.left
theorem forall_not_of_sep_empty {s : set α} {p : α → Prop} (H : {x ∈ s | p x} = ∅)
(x) : x ∈ s → ¬ p x := not_and.1 (eq_empty_iff_forall_not_mem.1 H x : _)
@[simp] lemma sep_univ {α} {p : α → Prop} : {a ∈ (univ : set α) | p a} = {a | p a} := univ_inter _
@[simp] lemma sep_true : {a ∈ s | true} = s :=
by { ext, simp }
@[simp] lemma sep_false : {a ∈ s | false} = ∅ :=
by { ext, simp }
@[simp] lemma subset_singleton_iff {α : Type*} {s : set α} {x : α} : s ⊆ {x} ↔ ∀ y ∈ s, y = x :=
iff.rfl
lemma subset_singleton_iff_eq {s : set α} {x : α} : s ⊆ {x} ↔ s = ∅ ∨ s = {x} :=
begin
obtain (rfl | hs) := s.eq_empty_or_nonempty,
use ⟨λ _, or.inl rfl, λ _, empty_subset _⟩,
simp [eq_singleton_iff_nonempty_unique_mem, hs, ne_empty_iff_nonempty.2 hs],
end
lemma ssubset_singleton_iff {s : set α} {x : α} : s ⊂ {x} ↔ s = ∅ :=
begin
rw [ssubset_iff_subset_ne, subset_singleton_iff_eq, or_and_distrib_right, and_not_self, or_false,
and_iff_left_iff_imp],
rintro rfl,
refine ne_comm.1 (ne_empty_iff_nonempty.2 (singleton_nonempty _)),
end
lemma eq_empty_of_ssubset_singleton {s : set α} {x : α} (hs : s ⊂ {x}) : s = ∅ :=
ssubset_singleton_iff.1 hs
/-! ### Lemmas about complement -/
theorem mem_compl {s : set α} {x : α} (h : x ∉ s) : x ∈ sᶜ := h
lemma compl_set_of {α} (p : α → Prop) : {a | p a}ᶜ = { a | ¬ p a } := rfl
theorem not_mem_of_mem_compl {s : set α} {x : α} (h : x ∈ sᶜ) : x ∉ s := h
@[simp] theorem mem_compl_eq (s : set α) (x : α) : x ∈ sᶜ = (x ∉ s) := rfl
theorem mem_compl_iff (s : set α) (x : α) : x ∈ sᶜ ↔ x ∉ s := iff.rfl
@[simp] theorem inter_compl_self (s : set α) : s ∩ sᶜ = ∅ := inf_compl_eq_bot
@[simp] theorem compl_inter_self (s : set α) : sᶜ ∩ s = ∅ := compl_inf_eq_bot
@[simp] theorem compl_empty : (∅ : set α)ᶜ = univ := compl_bot
@[simp] theorem compl_union (s t : set α) : (s ∪ t)ᶜ = sᶜ ∩ tᶜ := compl_sup
theorem compl_inter (s t : set α) : (s ∩ t)ᶜ = sᶜ ∪ tᶜ := compl_inf
@[simp] theorem compl_univ : (univ : set α)ᶜ = ∅ := compl_top
@[simp] lemma compl_empty_iff {s : set α} : sᶜ = ∅ ↔ s = univ := compl_eq_bot
@[simp] lemma compl_univ_iff {s : set α} : sᶜ = univ ↔ s = ∅ := compl_eq_top
lemma nonempty_compl {s : set α} : sᶜ.nonempty ↔ s ≠ univ :=
ne_empty_iff_nonempty.symm.trans $ not_congr $ compl_empty_iff
lemma mem_compl_singleton_iff {a x : α} : x ∈ ({a} : set α)ᶜ ↔ x ≠ a :=
not_congr mem_singleton_iff
lemma compl_singleton_eq (a : α) : ({a} : set α)ᶜ = {x | x ≠ a} :=
ext $ λ x, mem_compl_singleton_iff
@[simp]
lemma compl_ne_eq_singleton (a : α) : ({x | x ≠ a} : set α)ᶜ = {a} :=
by { ext, simp, }
theorem union_eq_compl_compl_inter_compl (s t : set α) : s ∪ t = (sᶜ ∩ tᶜ)ᶜ :=
ext $ λ x, or_iff_not_and_not
theorem inter_eq_compl_compl_union_compl (s t : set α) : s ∩ t = (sᶜ ∪ tᶜ)ᶜ :=
ext $ λ x, and_iff_not_or_not
@[simp] theorem union_compl_self (s : set α) : s ∪ sᶜ = univ := eq_univ_iff_forall.2 $ λ x, em _
@[simp] theorem compl_union_self (s : set α) : sᶜ ∪ s = univ := by rw [union_comm, union_compl_self]
theorem compl_comp_compl : compl ∘ compl = @id (set α) := funext compl_compl
theorem compl_subset_comm {s t : set α} : sᶜ ⊆ t ↔ tᶜ ⊆ s := @compl_le_iff_compl_le _ s t _
@[simp] lemma compl_subset_compl {s t : set α} : sᶜ ⊆ tᶜ ↔ t ⊆ s := @compl_le_compl_iff_le _ t s _
theorem compl_subset_iff_union {s t : set α} : sᶜ ⊆ t ↔ s ∪ t = univ :=
iff.symm $ eq_univ_iff_forall.trans $ forall_congr $ λ a, or_iff_not_imp_left
theorem subset_compl_comm {s t : set α} : s ⊆ tᶜ ↔ t ⊆ sᶜ :=
forall_congr $ λ a, imp_not_comm
theorem subset_compl_iff_disjoint {s t : set α} : s ⊆ tᶜ ↔ s ∩ t = ∅ :=
iff.trans (forall_congr $ λ a, and_imp.symm) subset_empty_iff
lemma subset_compl_singleton_iff {a : α} {s : set α} : s ⊆ {a}ᶜ ↔ a ∉ s :=
subset_compl_comm.trans singleton_subset_iff
theorem inter_subset (a b c : set α) : a ∩ b ⊆ c ↔ a ⊆ bᶜ ∪ c :=
forall_congr $ λ x, and_imp.trans $ imp_congr_right $ λ _, imp_iff_not_or
lemma inter_compl_nonempty_iff {s t : set α} : (s ∩ tᶜ).nonempty ↔ ¬ s ⊆ t :=
(not_subset.trans $ exists_congr $ by exact λ x, by simp [mem_compl]).symm
/-! ### Lemmas about set difference -/
theorem diff_eq (s t : set α) : s \ t = s ∩ tᶜ := rfl
@[simp] theorem mem_diff {s t : set α} (x : α) : x ∈ s \ t ↔ x ∈ s ∧ x ∉ t := iff.rfl
theorem mem_diff_of_mem {s t : set α} {x : α} (h1 : x ∈ s) (h2 : x ∉ t) : x ∈ s \ t :=
⟨h1, h2⟩
theorem mem_of_mem_diff {s t : set α} {x : α} (h : x ∈ s \ t) : x ∈ s :=
h.left
theorem not_mem_of_mem_diff {s t : set α} {x : α} (h : x ∈ s \ t) : x ∉ t :=
h.right
theorem diff_eq_compl_inter {s t : set α} : s \ t = tᶜ ∩ s :=
by rw [diff_eq, inter_comm]
theorem nonempty_diff {s t : set α} : (s \ t).nonempty ↔ ¬ (s ⊆ t) := inter_compl_nonempty_iff
theorem diff_subset (s t : set α) : s \ t ⊆ s := show s \ t ≤ s, from sdiff_le
theorem union_diff_cancel' {s t u : set α} (h₁ : s ⊆ t) (h₂ : t ⊆ u) : t ∪ (u \ s) = u :=
sup_sdiff_cancel' h₁ h₂
theorem union_diff_cancel {s t : set α} (h : s ⊆ t) : s ∪ (t \ s) = t :=
sup_sdiff_of_le h
theorem union_diff_cancel_left {s t : set α} (h : s ∩ t ⊆ ∅) : (s ∪ t) \ s = t :=
disjoint.sup_sdiff_cancel_left h
theorem union_diff_cancel_right {s t : set α} (h : s ∩ t ⊆ ∅) : (s ∪ t) \ t = s :=
disjoint.sup_sdiff_cancel_right h
@[simp] theorem union_diff_left {s t : set α} : (s ∪ t) \ s = t \ s :=
sup_sdiff_left_self
@[simp] theorem union_diff_right {s t : set α} : (s ∪ t) \ t = s \ t :=
sup_sdiff_right_self
theorem union_diff_distrib {s t u : set α} : (s ∪ t) \ u = s \ u ∪ t \ u :=
sup_sdiff
theorem inter_diff_assoc (a b c : set α) : (a ∩ b) \ c = a ∩ (b \ c) :=
inf_sdiff_assoc
@[simp] theorem inter_diff_self (a b : set α) : a ∩ (b \ a) = ∅ :=
inf_sdiff_self_right
@[simp] theorem inter_union_diff (s t : set α) : (s ∩ t) ∪ (s \ t) = s :=
sup_inf_sdiff s t
@[simp] theorem inter_union_compl (s t : set α) : (s ∩ t) ∪ (s ∩ tᶜ) = s := inter_union_diff _ _
theorem diff_subset_diff {s₁ s₂ t₁ t₂ : set α} : s₁ ⊆ s₂ → t₂ ⊆ t₁ → s₁ \ t₁ ⊆ s₂ \ t₂ :=
show s₁ ≤ s₂ → t₂ ≤ t₁ → s₁ \ t₁ ≤ s₂ \ t₂, from sdiff_le_sdiff
theorem diff_subset_diff_left {s₁ s₂ t : set α} (h : s₁ ⊆ s₂) : s₁ \ t ⊆ s₂ \ t :=
sdiff_le_self_sdiff ‹s₁ ≤ s₂›
theorem diff_subset_diff_right {s t u : set α} (h : t ⊆ u) : s \ u ⊆ s \ t :=
sdiff_le_sdiff_self ‹t ≤ u›
theorem compl_eq_univ_diff (s : set α) : sᶜ = univ \ s :=
top_sdiff.symm
@[simp] lemma empty_diff (s : set α) : (∅ \ s : set α) = ∅ :=
bot_sdiff
theorem diff_eq_empty {s t : set α} : s \ t = ∅ ↔ s ⊆ t :=
sdiff_eq_bot_iff
@[simp] theorem diff_empty {s : set α} : s \ ∅ = s :=
sdiff_bot
@[simp] lemma diff_univ (s : set α) : s \ univ = ∅ := diff_eq_empty.2 (subset_univ s)
theorem diff_diff {u : set α} : s \ t \ u = s \ (t ∪ u) :=
sdiff_sdiff_left
-- the following statement contains parentheses to help the reader
lemma diff_diff_comm {s t u : set α} : (s \ t) \ u = (s \ u) \ t :=
sdiff_sdiff_comm
lemma diff_subset_iff {s t u : set α} : s \ t ⊆ u ↔ s ⊆ t ∪ u :=
show s \ t ≤ u ↔ s ≤ t ∪ u, from sdiff_le_iff
lemma subset_diff_union (s t : set α) : s ⊆ (s \ t) ∪ t :=
show s ≤ (s \ t) ∪ t, from le_sdiff_sup
lemma diff_union_of_subset {s t : set α} (h : t ⊆ s) :
(s \ t) ∪ t = s :=
subset.antisymm (union_subset (diff_subset _ _) h) (subset_diff_union _ _)
@[simp] lemma diff_singleton_subset_iff {x : α} {s t : set α} : s \ {x} ⊆ t ↔ s ⊆ insert x t :=
by { rw [←union_singleton, union_comm], apply diff_subset_iff }
lemma subset_diff_singleton {x : α} {s t : set α} (h : s ⊆ t) (hx : x ∉ s) : s ⊆ t \ {x} :=
subset_inter h $ subset_compl_comm.1 $ singleton_subset_iff.2 hx
lemma subset_insert_diff_singleton (x : α) (s : set α) : s ⊆ insert x (s \ {x}) :=
by rw [←diff_singleton_subset_iff]
lemma diff_subset_comm {s t u : set α} : s \ t ⊆ u ↔ s \ u ⊆ t :=
show s \ t ≤ u ↔ s \ u ≤ t, from sdiff_le_comm
lemma diff_inter {s t u : set α} : s \ (t ∩ u) = (s \ t) ∪ (s \ u) :=
sdiff_inf
lemma diff_inter_diff {s t u : set α} : s \ t ∩ (s \ u) = s \ (t ∪ u) :=
sdiff_sup.symm
lemma diff_compl : s \ tᶜ = s ∩ t := sdiff_compl
lemma diff_diff_right {s t u : set α} : s \ (t \ u) = (s \ t) ∪ (s ∩ u) :=
sdiff_sdiff_right'
@[simp] theorem insert_diff_of_mem (s) (h : a ∈ t) : insert a s \ t = s \ t :=
by { ext, split; simp [or_imp_distrib, h] {contextual := tt} }
theorem insert_diff_of_not_mem (s) (h : a ∉ t) : insert a s \ t = insert a (s \ t) :=
begin
classical,
ext x,
by_cases h' : x ∈ t,
{ have : x ≠ a,
{ assume H,
rw H at h',
exact h h' },
simp [h, h', this] },
{ simp [h, h'] }
end
lemma insert_diff_self_of_not_mem {a : α} {s : set α} (h : a ∉ s) :
insert a s \ {a} = s :=
by { ext, simp [and_iff_left_of_imp (λ hx : x ∈ s, show x ≠ a, from λ hxa, h $ hxa ▸ hx)] }
lemma insert_inter_of_mem {s₁ s₂ : set α} {a : α} (h : a ∈ s₂) :
insert a s₁ ∩ s₂ = insert a (s₁ ∩ s₂) :=
by simp [set.insert_inter, h]
lemma insert_inter_of_not_mem {s₁ s₂ : set α} {a : α} (h : a ∉ s₂) :
insert a s₁ ∩ s₂ = s₁ ∩ s₂ :=
begin
ext x,
simp only [mem_inter_iff, mem_insert_iff, mem_inter_eq, and.congr_left_iff, or_iff_right_iff_imp],
cc,
end
@[simp] theorem union_diff_self {s t : set α} : s ∪ (t \ s) = s ∪ t :=
sup_sdiff_self_right
@[simp] theorem diff_union_self {s t : set α} : (s \ t) ∪ t = s ∪ t :=
sup_sdiff_self_left
theorem diff_inter_self {a b : set α} : (b \ a) ∩ a = ∅ :=
inf_sdiff_self_left
theorem diff_inter_self_eq_diff {s t : set α} : s \ (t ∩ s) = s \ t :=
sdiff_inf_self_right
theorem diff_self_inter {s t : set α} : s \ (s ∩ t) = s \ t :=
sdiff_inf_self_left
theorem diff_eq_self {s t : set α} : s \ t = s ↔ t ∩ s ⊆ ∅ :=
show s \ t = s ↔ t ⊓ s ≤ ⊥, from sdiff_eq_self_iff_disjoint
@[simp] theorem diff_singleton_eq_self {a : α} {s : set α} (h : a ∉ s) : s \ {a} = s :=
diff_eq_self.2 $ by simp [singleton_inter_eq_empty.2 h]
@[simp] theorem insert_diff_singleton {a : α} {s : set α} :
insert a (s \ {a}) = insert a s :=
by simp [insert_eq, union_diff_self, -union_singleton, -singleton_union]
@[simp] lemma diff_self {s : set α} : s \ s = ∅ := sdiff_self
lemma diff_diff_cancel_left {s t : set α} (h : s ⊆ t) : t \ (t \ s) = s :=
sdiff_sdiff_eq_self h
lemma mem_diff_singleton {x y : α} {s : set α} : x ∈ s \ {y} ↔ (x ∈ s ∧ x ≠ y) :=
iff.rfl
lemma mem_diff_singleton_empty {s : set α} {t : set (set α)} :
s ∈ t \ {∅} ↔ (s ∈ t ∧ s.nonempty) :=
mem_diff_singleton.trans $ and_congr iff.rfl ne_empty_iff_nonempty
lemma union_eq_sdiff_union_sdiff_union_inter (s t : set α) :
s ∪ t = (s \ t) ∪ (t \ s) ∪ (s ∩ t) :=
sup_eq_sdiff_sup_sdiff_sup_inf
/-! ### Powerset -/
theorem mem_powerset {x s : set α} (h : x ⊆ s) : x ∈ powerset s := h
theorem subset_of_mem_powerset {x s : set α} (h : x ∈ powerset s) : x ⊆ s := h
@[simp] theorem mem_powerset_iff (x s : set α) : x ∈ powerset s ↔ x ⊆ s := iff.rfl
theorem powerset_inter (s t : set α) : 𝒫 (s ∩ t) = 𝒫 s ∩ 𝒫 t :=
ext $ λ u, subset_inter_iff
@[simp] theorem powerset_mono : 𝒫 s ⊆ 𝒫 t ↔ s ⊆ t :=
⟨λ h, h (subset.refl s), λ h u hu, subset.trans hu h⟩
theorem monotone_powerset : monotone (powerset : set α → set (set α)) :=
λ s t, powerset_mono.2
@[simp] theorem powerset_nonempty : (𝒫 s).nonempty :=
⟨∅, empty_subset s⟩
@[simp] theorem powerset_empty : 𝒫 (∅ : set α) = {∅} :=
ext $ λ s, subset_empty_iff
@[simp] theorem powerset_univ : 𝒫 (univ : set α) = univ :=
eq_univ_of_forall subset_univ
/-! ### If-then-else for sets -/
/-- `ite` for sets: `set.ite t s s' ∩ t = s ∩ t`, `set.ite t s s' ∩ tᶜ = s' ∩ tᶜ`.
Defined as `s ∩ t ∪ s' \ t`. -/
protected def ite (t s s' : set α) : set α := s ∩ t ∪ s' \ t
@[simp] lemma ite_inter_self (t s s' : set α) : t.ite s s' ∩ t = s ∩ t :=
by rw [set.ite, union_inter_distrib_right, diff_inter_self, inter_assoc, inter_self, union_empty]
@[simp] lemma ite_compl (t s s' : set α) : tᶜ.ite s s' = t.ite s' s :=
by rw [set.ite, set.ite, diff_compl, union_comm, diff_eq]
@[simp] lemma ite_inter_compl_self (t s s' : set α) : t.ite s s' ∩ tᶜ = s' ∩ tᶜ :=
by rw [← ite_compl, ite_inter_self]
@[simp] lemma ite_diff_self (t s s' : set α) : t.ite s s' \ t = s' \ t :=
ite_inter_compl_self t s s'
@[simp] lemma ite_same (t s : set α) : t.ite s s = s := inter_union_diff _ _
@[simp] lemma ite_left (s t : set α) : s.ite s t = s ∪ t := by simp [set.ite]
@[simp] lemma ite_right (s t : set α) : s.ite t s = t ∩ s := by simp [set.ite]
@[simp] lemma ite_empty (s s' : set α) : set.ite ∅ s s' = s' :=
by simp [set.ite]
@[simp] lemma ite_univ (s s' : set α) : set.ite univ s s' = s :=
by simp [set.ite]
@[simp] lemma ite_empty_left (t s : set α) : t.ite ∅ s = s \ t :=
by simp [set.ite]
@[simp] lemma ite_empty_right (t s : set α) : t.ite s ∅ = s ∩ t :=
by simp [set.ite]
lemma ite_mono (t : set α) {s₁ s₁' s₂ s₂' : set α} (h : s₁ ⊆ s₂) (h' : s₁' ⊆ s₂') :
t.ite s₁ s₁' ⊆ t.ite s₂ s₂' :=
union_subset_union (inter_subset_inter_left _ h) (inter_subset_inter_left _ h')
lemma ite_subset_union (t s s' : set α) : t.ite s s' ⊆ s ∪ s' :=
union_subset_union (inter_subset_left _ _) (diff_subset _ _)
lemma inter_subset_ite (t s s' : set α) : s ∩ s' ⊆ t.ite s s' :=
ite_same t (s ∩ s') ▸ ite_mono _ (inter_subset_left _ _) (inter_subset_right _ _)
lemma ite_inter_inter (t s₁ s₂ s₁' s₂' : set α) :
t.ite (s₁ ∩ s₂) (s₁' ∩ s₂') = t.ite s₁ s₁' ∩ t.ite s₂ s₂' :=
by { ext x, finish [set.ite, iff_def] }
lemma ite_inter (t s₁ s₂ s : set α) :
t.ite (s₁ ∩ s) (s₂ ∩ s) = t.ite s₁ s₂ ∩ s :=
by rw [ite_inter_inter, ite_same]
lemma ite_inter_of_inter_eq (t : set α) {s₁ s₂ s : set α} (h : s₁ ∩ s = s₂ ∩ s) :
t.ite s₁ s₂ ∩ s = s₁ ∩ s :=
by rw [← ite_inter, ← h, ite_same]
lemma subset_ite {t s s' u : set α} : u ⊆ t.ite s s' ↔ u ∩ t ⊆ s ∧ u \ t ⊆ s' :=
begin
simp only [subset_def, ← forall_and_distrib],
refine forall_congr (λ x, _),
by_cases hx : x ∈ t; simp [*, set.ite]
end
/-! ### Inverse image -/
/-- The preimage of `s : set β` by `f : α → β`, written `f ⁻¹' s`,
is the set of `x : α` such that `f x ∈ s`. -/
def preimage {α : Type u} {β : Type v} (f : α → β) (s : set β) : set α := {x | f x ∈ s}
infix ` ⁻¹' `:80 := preimage
section preimage
variables {f : α → β} {g : β → γ}
@[simp] theorem preimage_empty : f ⁻¹' ∅ = ∅ := rfl
@[simp] theorem mem_preimage {s : set β} {a : α} : (a ∈ f ⁻¹' s) ↔ (f a ∈ s) := iff.rfl
lemma preimage_congr {f g : α → β} {s : set β} (h : ∀ (x : α), f x = g x) : f ⁻¹' s = g ⁻¹' s :=
by { congr' with x, apply_assumption }
theorem preimage_mono {s t : set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t :=
assume x hx, h hx
@[simp] theorem preimage_univ : f ⁻¹' univ = univ := rfl
theorem subset_preimage_univ {s : set α} : s ⊆ f ⁻¹' univ := subset_univ _
@[simp] theorem preimage_inter {s t : set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t := rfl
@[simp] theorem preimage_union {s t : set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t := rfl
@[simp] theorem preimage_compl {s : set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ := rfl
@[simp] theorem preimage_diff (f : α → β) (s t : set β) :
f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t := rfl
@[simp] theorem preimage_ite (f : α → β) (s t₁ t₂ : set β) :
f ⁻¹' (s.ite t₁ t₂) = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) :=
rfl
@[simp] theorem preimage_set_of_eq {p : α → Prop} {f : β → α} : f ⁻¹' {a | p a} = {a | p (f a)} :=
rfl
@[simp] theorem preimage_id {s : set α} : id ⁻¹' s = s := rfl
@[simp] theorem preimage_id' {s : set α} : (λ x, x) ⁻¹' s = s := rfl
theorem preimage_const_of_mem {b : β} {s : set β} (h : b ∈ s) :
(λ (x : α), b) ⁻¹' s = univ :=
eq_univ_of_forall $ λ x, h
theorem preimage_const_of_not_mem {b : β} {s : set β} (h : b ∉ s) :
(λ (x : α), b) ⁻¹' s = ∅ :=
eq_empty_of_subset_empty $ λ x hx, h hx
theorem preimage_const (b : β) (s : set β) [decidable (b ∈ s)] :
(λ (x : α), b) ⁻¹' s = if b ∈ s then univ else ∅ :=
by { split_ifs with hb hb, exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb] }
theorem preimage_comp {s : set γ} : (g ∘ f) ⁻¹' s = f ⁻¹' (g ⁻¹' s) := rfl
lemma preimage_preimage {g : β → γ} {f : α → β} {s : set γ} :
f ⁻¹' (g ⁻¹' s) = (λ x, g (f x)) ⁻¹' s :=
preimage_comp.symm
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : set (subtype p)} {t : set α} :
s = subtype.val ⁻¹' t ↔ (∀x (h : p x), (⟨x, h⟩ : subtype p) ∈ s ↔ x ∈ t) :=
⟨assume s_eq x h, by { rw [s_eq], simp },
assume h, ext $ λ ⟨x, hx⟩, by simp [h]⟩
lemma preimage_coe_coe_diagonal {α : Type*} (s : set α) :
(prod.map coe coe) ⁻¹' (diagonal α) = diagonal s :=
begin
ext ⟨⟨x, x_in⟩, ⟨y, y_in⟩⟩,
simp [set.diagonal],
end
end preimage
/-! ### Image of a set under a function -/
section image
infix ` '' `:80 := image
theorem mem_image_iff_bex {f : α → β} {s : set α} {y : β} :
y ∈ f '' s ↔ ∃ x (_ : x ∈ s), f x = y := bex_def.symm
theorem mem_image_eq (f : α → β) (s : set α) (y: β) : y ∈ f '' s = ∃ x, x ∈ s ∧ f x = y := rfl
@[simp] theorem mem_image (f : α → β) (s : set α) (y : β) :
y ∈ f '' s ↔ ∃ x, x ∈ s ∧ f x = y := iff.rfl
lemma image_eta (f : α → β) : f '' s = (λ x, f x) '' s := rfl
theorem mem_image_of_mem (f : α → β) {x : α} {a : set α} (h : x ∈ a) : f x ∈ f '' a :=
⟨_, h, rfl⟩
theorem mem_image_of_injective {f : α → β} {a : α} {s : set α} (hf : injective f) :
f a ∈ f '' s ↔ a ∈ s :=
iff.intro
(assume ⟨b, hb, eq⟩, (hf eq) ▸ hb)
(assume h, mem_image_of_mem _ h)
theorem ball_image_iff {f : α → β} {s : set α} {p : β → Prop} :
(∀ y ∈ f '' s, p y) ↔ (∀ x ∈ s, p (f x)) :=
by simp
theorem ball_image_of_ball {f : α → β} {s : set α} {p : β → Prop}
(h : ∀ x ∈ s, p (f x)) : ∀ y ∈ f '' s, p y :=
ball_image_iff.2 h
theorem bex_image_iff {f : α → β} {s : set α} {p : β → Prop} :
(∃ y ∈ f '' s, p y) ↔ (∃ x ∈ s, p (f x)) :=
by simp
theorem mem_image_elim {f : α → β} {s : set α} {C : β → Prop} (h : ∀ (x : α), x ∈ s → C (f x)) :
∀{y : β}, y ∈ f '' s → C y
| ._ ⟨a, a_in, rfl⟩ := h a a_in
theorem mem_image_elim_on {f : α → β} {s : set α} {C : β → Prop} {y : β} (h_y : y ∈ f '' s)
(h : ∀ (x : α), x ∈ s → C (f x)) : C y :=
mem_image_elim h h_y
@[congr] lemma image_congr {f g : α → β} {s : set α}
(h : ∀a∈s, f a = g a) : f '' s = g '' s :=
by safe [ext_iff, iff_def]
/-- A common special case of `image_congr` -/
lemma image_congr' {f g : α → β} {s : set α} (h : ∀ (x : α), f x = g x) : f '' s = g '' s :=
image_congr (λx _, h x)
theorem image_comp (f : β → γ) (g : α → β) (a : set α) : (f ∘ g) '' a = f '' (g '' a) :=
subset.antisymm
(ball_image_of_ball $ assume a ha, mem_image_of_mem _ $ mem_image_of_mem _ ha)
(ball_image_of_ball $ ball_image_of_ball $ assume a ha, mem_image_of_mem _ ha)
/-- A variant of `image_comp`, useful for rewriting -/
lemma image_image (g : β → γ) (f : α → β) (s : set α) : g '' (f '' s) = (λ x, g (f x)) '' s :=
(image_comp g f s).symm
/-- Image is monotone with respect to `⊆`. See `set.monotone_image` for the statement in
terms of `≤`. -/
theorem image_subset {a b : set α} (f : α → β) (h : a ⊆ b) : f '' a ⊆ f '' b :=
by finish [subset_def, mem_image_eq]
theorem image_union (f : α → β) (s t : set α) :
f '' (s ∪ t) = f '' s ∪ f '' t :=
by finish [ext_iff, iff_def, mem_image_eq]
@[simp] theorem image_empty (f : α → β) : f '' ∅ = ∅ := by { ext, simp }
lemma image_inter_subset (f : α → β) (s t : set α) :
f '' (s ∩ t) ⊆ f '' s ∩ f '' t :=
subset_inter (image_subset _ $ inter_subset_left _ _) (image_subset _ $ inter_subset_right _ _)
theorem image_inter_on {f : α → β} {s t : set α} (h : ∀x∈t, ∀y∈s, f x = f y → x = y) :
f '' s ∩ f '' t = f '' (s ∩ t) :=
subset.antisymm
(assume b ⟨⟨a₁, ha₁, h₁⟩, ⟨a₂, ha₂, h₂⟩⟩,
have a₂ = a₁, from h _ ha₂ _ ha₁ (by simp *),
⟨a₁, ⟨ha₁, this ▸ ha₂⟩, h₁⟩)
(image_inter_subset _ _ _)
theorem image_inter {f : α → β} {s t : set α} (H : injective f) :
f '' s ∩ f '' t = f '' (s ∩ t) :=
image_inter_on (assume x _ y _ h, H h)
theorem image_univ_of_surjective {ι : Type*} {f : ι → β} (H : surjective f) : f '' univ = univ :=
eq_univ_of_forall $ by { simpa [image] }
@[simp] theorem image_singleton {f : α → β} {a : α} : f '' {a} = {f a} :=
by { ext, simp [image, eq_comm] }
@[simp] theorem nonempty.image_const {s : set α} (hs : s.nonempty) (a : β) : (λ _, a) '' s = {a} :=
ext $ λ x, ⟨λ ⟨y, _, h⟩, h ▸ mem_singleton _,
λ h, (eq_of_mem_singleton h).symm ▸ hs.imp (λ y hy, ⟨hy, rfl⟩)⟩
@[simp] lemma image_eq_empty {α β} {f : α → β} {s : set α} : f '' s = ∅ ↔ s = ∅ :=
by { simp only [eq_empty_iff_forall_not_mem],
exact ⟨λ H a ha, H _ ⟨_, ha, rfl⟩, λ H b ⟨_, ha, _⟩, H _ ha⟩ }
-- TODO(Jeremy): there is an issue with - t unfolding to compl t
theorem mem_compl_image (t : set α) (S : set (set α)) :
t ∈ compl '' S ↔ tᶜ ∈ S :=
begin
suffices : ∀ x, xᶜ = t ↔ tᶜ = x, { simp [this] },
intro x, split; { intro e, subst e, simp }
end
/-- A variant of `image_id` -/
@[simp] lemma image_id' (s : set α) : (λx, x) '' s = s := by { ext, simp }
theorem image_id (s : set α) : id '' s = s := by simp
theorem compl_compl_image (S : set (set α)) :
compl '' (compl '' S) = S :=
by rw [← image_comp, compl_comp_compl, image_id]
theorem image_insert_eq {f : α → β} {a : α} {s : set α} :
f '' (insert a s) = insert (f a) (f '' s) :=
by { ext, simp [and_or_distrib_left, exists_or_distrib, eq_comm, or_comm, and_comm] }
theorem image_pair (f : α → β) (a b : α) : f '' {a, b} = {f a, f b} :=
by simp only [image_insert_eq, image_singleton]
theorem image_subset_preimage_of_inverse {f : α → β} {g : β → α}
(I : left_inverse g f) (s : set α) : f '' s ⊆ g ⁻¹' s :=
λ b ⟨a, h, e⟩, e ▸ ((I a).symm ▸ h : g (f a) ∈ s)
theorem preimage_subset_image_of_inverse {f : α → β} {g : β → α}
(I : left_inverse g f) (s : set β) : f ⁻¹' s ⊆ g '' s :=
λ b h, ⟨f b, h, I b⟩
theorem image_eq_preimage_of_inverse {f : α → β} {g : β → α}
(h₁ : left_inverse g f) (h₂ : right_inverse g f) :
image f = preimage g :=
funext $ λ s, subset.antisymm
(image_subset_preimage_of_inverse h₁ s)
(preimage_subset_image_of_inverse h₂ s)
theorem mem_image_iff_of_inverse {f : α → β} {g : β → α} {b : β} {s : set α}
(h₁ : left_inverse g f) (h₂ : right_inverse g f) :
b ∈ f '' s ↔ g b ∈ s :=
by rw image_eq_preimage_of_inverse h₁ h₂; refl
theorem image_compl_subset {f : α → β} {s : set α} (H : injective f) : f '' sᶜ ⊆ (f '' s)ᶜ :=
subset_compl_iff_disjoint.2 $ by simp [image_inter H]
theorem subset_image_compl {f : α → β} {s : set α} (H : surjective f) : (f '' s)ᶜ ⊆ f '' sᶜ :=
compl_subset_iff_union.2 $
by { rw ← image_union, simp [image_univ_of_surjective H] }
theorem image_compl_eq {f : α → β} {s : set α} (H : bijective f) : f '' sᶜ = (f '' s)ᶜ :=
subset.antisymm (image_compl_subset H.1) (subset_image_compl H.2)
theorem subset_image_diff (f : α → β) (s t : set α) :
f '' s \ f '' t ⊆ f '' (s \ t) :=
begin
rw [diff_subset_iff, ← image_union, union_diff_self],
exact image_subset f (subset_union_right t s)
end
theorem image_diff {f : α → β} (hf : injective f) (s t : set α) :
f '' (s \ t) = f '' s \ f '' t :=
subset.antisymm
(subset.trans (image_inter_subset _ _ _) $ inter_subset_inter_right _ $ image_compl_subset hf)
(subset_image_diff f s t)
lemma nonempty.image (f : α → β) {s : set α} : s.nonempty → (f '' s).nonempty
| ⟨x, hx⟩ := ⟨f x, mem_image_of_mem f hx⟩
lemma nonempty.of_image {f : α → β} {s : set α} : (f '' s).nonempty → s.nonempty
| ⟨y, x, hx, _⟩ := ⟨x, hx⟩
@[simp] lemma nonempty_image_iff {f : α → β} {s : set α} :
(f '' s).nonempty ↔ s.nonempty :=
⟨nonempty.of_image, λ h, h.image f⟩
lemma nonempty.preimage {s : set β} (hs : s.nonempty) {f : α → β} (hf : surjective f) :
(f ⁻¹' s).nonempty :=
let ⟨y, hy⟩ := hs, ⟨x, hx⟩ := hf y in ⟨x, mem_preimage.2 $ hx.symm ▸ hy⟩
instance (f : α → β) (s : set α) [nonempty s] : nonempty (f '' s) :=
(set.nonempty.image f nonempty_of_nonempty_subtype).to_subtype
/-- image and preimage are a Galois connection -/
@[simp] theorem image_subset_iff {s : set α} {t : set β} {f : α → β} :
f '' s ⊆ t ↔ s ⊆ f ⁻¹' t :=
ball_image_iff
theorem image_preimage_subset (f : α → β) (s : set β) :
f '' (f ⁻¹' s) ⊆ s :=
image_subset_iff.2 (subset.refl _)
theorem subset_preimage_image (f : α → β) (s : set α) :
s ⊆ f ⁻¹' (f '' s) :=
λ x, mem_image_of_mem f
theorem preimage_image_eq {f : α → β} (s : set α) (h : injective f) : f ⁻¹' (f '' s) = s :=
subset.antisymm
(λ x ⟨y, hy, e⟩, h e ▸ hy)
(subset_preimage_image f s)
theorem image_preimage_eq {f : α → β} (s : set β) (h : surjective f) : f '' (f ⁻¹' s) = s :=
subset.antisymm
(image_preimage_subset f s)
(λ x hx, let ⟨y, e⟩ := h x in ⟨y, (e.symm ▸ hx : f y ∈ s), e⟩)
lemma preimage_eq_preimage {f : β → α} (hf : surjective f) : f ⁻¹' s = f ⁻¹' t ↔ s = t :=
iff.intro
(assume eq, by rw [← image_preimage_eq s hf, ← image_preimage_eq t hf, eq])
(assume eq, eq ▸ rfl)
lemma image_inter_preimage (f : α → β) (s : set α) (t : set β) :
f '' (s ∩ f ⁻¹' t) = f '' s ∩ t :=
begin
apply subset.antisymm,
{ calc f '' (s ∩ f ⁻¹' t) ⊆ f '' s ∩ (f '' (f⁻¹' t)) : image_inter_subset _ _ _
... ⊆ f '' s ∩ t : inter_subset_inter_right _ (image_preimage_subset f t) },
{ rintros _ ⟨⟨x, h', rfl⟩, h⟩,
exact ⟨x, ⟨h', h⟩, rfl⟩ }
end
lemma image_preimage_inter (f : α → β) (s : set α) (t : set β) :
f '' (f ⁻¹' t ∩ s) = t ∩ f '' s :=
by simp only [inter_comm, image_inter_preimage]
@[simp] lemma image_inter_nonempty_iff {f : α → β} {s : set α} {t : set β} :
(f '' s ∩ t).nonempty ↔ (s ∩ f ⁻¹' t).nonempty :=
by rw [←image_inter_preimage, nonempty_image_iff]
lemma image_diff_preimage {f : α → β} {s : set α} {t : set β} : f '' (s \ f ⁻¹' t) = f '' s \ t :=
by simp_rw [diff_eq, ← preimage_compl, image_inter_preimage]
theorem compl_image : image (compl : set α → set α) = preimage compl :=
image_eq_preimage_of_inverse compl_compl compl_compl
theorem compl_image_set_of {p : set α → Prop} :
compl '' {s | p s} = {s | p sᶜ} :=
congr_fun compl_image p
theorem inter_preimage_subset (s : set α) (t : set β) (f : α → β) :
s ∩ f ⁻¹' t ⊆ f ⁻¹' (f '' s ∩ t) :=
λ x h, ⟨mem_image_of_mem _ h.left, h.right⟩
theorem union_preimage_subset (s : set α) (t : set β) (f : α → β) :
s ∪ f ⁻¹' t ⊆ f ⁻¹' (f '' s ∪ t) :=
λ x h, or.elim h (λ l, or.inl $ mem_image_of_mem _ l) (λ r, or.inr r)
theorem subset_image_union (f : α → β) (s : set α) (t : set β) :
f '' (s ∪ f ⁻¹' t) ⊆ f '' s ∪ t :=
image_subset_iff.2 (union_preimage_subset _ _ _)
lemma preimage_subset_iff {A : set α} {B : set β} {f : α → β} :
f⁻¹' B ⊆ A ↔ (∀ a : α, f a ∈ B → a ∈ A) := iff.rfl
lemma image_eq_image {f : α → β} (hf : injective f) : f '' s = f '' t ↔ s = t :=
iff.symm $ iff.intro (assume eq, eq ▸ rfl) $ assume eq,
by rw [← preimage_image_eq s hf, ← preimage_image_eq t hf, eq]
lemma image_subset_image_iff {f : α → β} (hf : injective f) : f '' s ⊆ f '' t ↔ s ⊆ t :=
begin
refine (iff.symm $ iff.intro (image_subset f) $ assume h, _),
rw [← preimage_image_eq s hf, ← preimage_image_eq t hf],
exact preimage_mono h
end
lemma prod_quotient_preimage_eq_image [s : setoid α] (g : quotient s → β) {h : α → β}
(Hh : h = g ∘ quotient.mk) (r : set (β × β)) :
{x : quotient s × quotient s | (g x.1, g x.2) ∈ r} =
(λ a : α × α, (⟦a.1⟧, ⟦a.2⟧)) '' ((λ a : α × α, (h a.1, h a.2)) ⁻¹' r) :=
Hh.symm ▸ set.ext (λ ⟨a₁, a₂⟩, ⟨quotient.induction_on₂ a₁ a₂
(λ a₁ a₂ h, ⟨(a₁, a₂), h, rfl⟩),
λ ⟨⟨b₁, b₂⟩, h₁, h₂⟩, show (g a₁, g a₂) ∈ r, from
have h₃ : ⟦b₁⟧ = a₁ ∧ ⟦b₂⟧ = a₂ := prod.ext_iff.1 h₂,
h₃.1 ▸ h₃.2 ▸ h₁⟩)
/-- Restriction of `f` to `s` factors through `s.image_factorization f : s → f '' s`. -/
def image_factorization (f : α → β) (s : set α) : s → f '' s :=
λ p, ⟨f p.1, mem_image_of_mem f p.2⟩
lemma image_factorization_eq {f : α → β} {s : set α} :
subtype.val ∘ image_factorization f s = f ∘ subtype.val :=
funext $ λ p, rfl
lemma surjective_onto_image {f : α → β} {s : set α} :
surjective (image_factorization f s) :=
λ ⟨_, ⟨a, ha, rfl⟩⟩, ⟨⟨a, ha⟩, rfl⟩
end image
/-! ### Subsingleton -/
/-- A set `s` is a `subsingleton`, if it has at most one element. -/
protected def subsingleton (s : set α) : Prop :=
∀ ⦃x⦄ (hx : x ∈ s) ⦃y⦄ (hy : y ∈ s), x = y
lemma subsingleton.mono (ht : t.subsingleton) (hst : s ⊆ t) : s.subsingleton :=
λ x hx y hy, ht (hst hx) (hst hy)
lemma subsingleton.image (hs : s.subsingleton) (f : α → β) : (f '' s).subsingleton :=
λ _ ⟨x, hx, Hx⟩ _ ⟨y, hy, Hy⟩, Hx ▸ Hy ▸ congr_arg f (hs hx hy)
lemma subsingleton.eq_singleton_of_mem (hs : s.subsingleton) {x:α} (hx : x ∈ s) :
s = {x} :=
ext $ λ y, ⟨λ hy, (hs hx hy) ▸ mem_singleton _, λ hy, (eq_of_mem_singleton hy).symm ▸ hx⟩
@[simp] lemma subsingleton_empty : (∅ : set α).subsingleton := λ x, false.elim
@[simp] lemma subsingleton_singleton {a} : ({a} : set α).subsingleton :=
λ x hx y hy, (eq_of_mem_singleton hx).symm ▸ (eq_of_mem_singleton hy).symm ▸ rfl
lemma subsingleton_iff_singleton {x} (hx : x ∈ s) : s.subsingleton ↔ s = {x} :=
⟨λ h, h.eq_singleton_of_mem hx, λ h,h.symm ▸ subsingleton_singleton⟩
lemma subsingleton.eq_empty_or_singleton (hs : s.subsingleton) :
s = ∅ ∨ ∃ x, s = {x} :=
s.eq_empty_or_nonempty.elim or.inl (λ ⟨x, hx⟩, or.inr ⟨x, hs.eq_singleton_of_mem hx⟩)
lemma subsingleton.induction_on {p : set α → Prop} (hs : s.subsingleton) (he : p ∅)
(h₁ : ∀ x, p {x}) : p s :=
by { rcases hs.eq_empty_or_singleton with rfl|⟨x, rfl⟩, exacts [he, h₁ _] }
lemma subsingleton_univ [subsingleton α] : (univ : set α).subsingleton :=
λ x hx y hy, subsingleton.elim x y
/-- `s`, coerced to a type, is a subsingleton type if and only if `s`
is a subsingleton set. -/
@[simp, norm_cast] lemma subsingleton_coe (s : set α) : subsingleton s ↔ s.subsingleton :=
begin
split,
{ refine λ h, (λ a ha b hb, _),
exact set_coe.ext_iff.2 (@subsingleton.elim s h ⟨a, ha⟩ ⟨b, hb⟩) },
{ exact λ h, subsingleton.intro (λ a b, set_coe.ext (h a.property b.property)) }
end
/-- `s` is a subsingleton, if its image of an injective function is. -/
theorem subsingleton_of_image {α β : Type*} {f : α → β} (hf : function.injective f)
(s : set α) (hs : (f '' s).subsingleton) : s.subsingleton :=
λ a ha b hb, hf $ hs (mem_image_of_mem _ ha) (mem_image_of_mem _ hb)
theorem univ_eq_true_false : univ = ({true, false} : set Prop) :=
eq.symm $ eq_univ_of_forall $ classical.cases (by simp) (by simp)
/-! ### Lemmas about range of a function. -/
section range
variables {f : ι → α}
open function
/-- Range of a function.
This function is more flexible than `f '' univ`, as the image requires that the domain is in Type
and not an arbitrary Sort. -/
def range (f : ι → α) : set α := {x | ∃y, f y = x}
@[simp] theorem mem_range {x : α} : x ∈ range f ↔ ∃ y, f y = x := iff.rfl
@[simp] theorem mem_range_self (i : ι) : f i ∈ range f := ⟨i, rfl⟩
theorem forall_range_iff {p : α → Prop} : (∀ a ∈ range f, p a) ↔ (∀ i, p (f i)) :=
by simp
theorem exists_range_iff {p : α → Prop} : (∃ a ∈ range f, p a) ↔ (∃ i, p (f i)) :=
by simp
lemma exists_range_iff' {p : α → Prop} :
(∃ a, a ∈ range f ∧ p a) ↔ ∃ i, p (f i) :=
by simpa only [exists_prop] using exists_range_iff
theorem range_iff_surjective : range f = univ ↔ surjective f :=
eq_univ_iff_forall
alias range_iff_surjective ↔ _ function.surjective.range_eq
@[simp] theorem range_id : range (@id α) = univ := range_iff_surjective.2 surjective_id
theorem is_compl_range_inl_range_inr : is_compl (range $ @sum.inl α β) (range sum.inr) :=
⟨by { rintro y ⟨⟨x₁, rfl⟩, ⟨x₂, _⟩⟩, cc },
by { rintro (x|y) -; [left, right]; exact mem_range_self _ }⟩
@[simp] theorem range_inl_union_range_inr : range (sum.inl : α → α ⊕ β) ∪ range sum.inr = univ :=
is_compl_range_inl_range_inr.sup_eq_top
@[simp] theorem range_inl_inter_range_inr : range (sum.inl : α → α ⊕ β) ∩ range sum.inr = ∅ :=
is_compl_range_inl_range_inr.inf_eq_bot
@[simp] theorem range_inr_union_range_inl : range (sum.inr : β → α ⊕ β) ∪ range sum.inl = univ :=
is_compl_range_inl_range_inr.symm.sup_eq_top
@[simp] theorem range_inr_inter_range_inl : range (sum.inr : β → α ⊕ β) ∩ range sum.inl = ∅ :=
is_compl_range_inl_range_inr.symm.inf_eq_bot
@[simp] theorem preimage_inl_range_inr : sum.inl ⁻¹' range (sum.inr : β → α ⊕ β) = ∅ :=
by { ext, simp }
@[simp] theorem preimage_inr_range_inl : sum.inr ⁻¹' range (sum.inl : α → α ⊕ β) = ∅ :=
by { ext, simp }
@[simp] theorem range_quot_mk (r : α → α → Prop) : range (quot.mk r) = univ :=
(surjective_quot_mk r).range_eq
@[simp] theorem image_univ {ι : Type*} {f : ι → β} : f '' univ = range f :=
by { ext, simp [image, range] }
theorem image_subset_range {ι : Type*} (f : ι → β) (s : set ι) : f '' s ⊆ range f :=
by rw ← image_univ; exact image_subset _ (subset_univ _)
theorem range_comp (g : α → β) (f : ι → α) : range (g ∘ f) = g '' range f :=
subset.antisymm
(forall_range_iff.mpr $ assume i, mem_image_of_mem g (mem_range_self _))
(ball_image_iff.mpr $ forall_range_iff.mpr mem_range_self)
theorem range_subset_iff {s : set α} : range f ⊆ s ↔ ∀ y, f y ∈ s :=
forall_range_iff
lemma range_comp_subset_range (f : α → β) (g : β → γ) : range (g ∘ f) ⊆ range g :=
by rw range_comp; apply image_subset_range
lemma range_nonempty_iff_nonempty : (range f).nonempty ↔ nonempty ι :=
⟨λ ⟨y, x, hxy⟩, ⟨x⟩, λ ⟨x⟩, ⟨f x, mem_range_self x⟩⟩
lemma range_nonempty [h : nonempty ι] (f : ι → α) : (range f).nonempty :=
range_nonempty_iff_nonempty.2 h
@[simp] lemma range_eq_empty {f : ι → α} : range f = ∅ ↔ ¬ nonempty ι :=
not_nonempty_iff_eq_empty.symm.trans $ not_congr range_nonempty_iff_nonempty
instance [nonempty ι] (f : ι → α) : nonempty (range f) := (range_nonempty f).to_subtype
@[simp] lemma image_union_image_compl_eq_range (f : α → β) :
(f '' s) ∪ (f '' sᶜ) = range f :=
by rw [← image_union, ← image_univ, ← union_compl_self]
theorem image_preimage_eq_inter_range {f : α → β} {t : set β} :
f '' (f ⁻¹' t) = t ∩ range f :=
ext $ assume x, ⟨assume ⟨x, hx, heq⟩, heq ▸ ⟨hx, mem_range_self _⟩,
assume ⟨hx, ⟨y, h_eq⟩⟩, h_eq ▸ mem_image_of_mem f $
show y ∈ f ⁻¹' t, by simp [preimage, h_eq, hx]⟩
lemma image_preimage_eq_of_subset {f : α → β} {s : set β} (hs : s ⊆ range f) :
f '' (f ⁻¹' s) = s :=
by rw [image_preimage_eq_inter_range, inter_eq_self_of_subset_left hs]
lemma image_preimage_eq_iff {f : α → β} {s : set β} : f '' (f ⁻¹' s) = s ↔ s ⊆ range f :=
⟨by { intro h, rw [← h], apply image_subset_range }, image_preimage_eq_of_subset⟩
lemma preimage_subset_preimage_iff {s t : set α} {f : β → α} (hs : s ⊆ range f) :
f ⁻¹' s ⊆ f ⁻¹' t ↔ s ⊆ t :=
begin
split,
{ intros h x hx, rcases hs hx with ⟨y, rfl⟩, exact h hx },
intros h x, apply h
end
lemma preimage_eq_preimage' {s t : set α} {f : β → α} (hs : s ⊆ range f) (ht : t ⊆ range f) :
f ⁻¹' s = f ⁻¹' t ↔ s = t :=
begin
split,
{ intro h, apply subset.antisymm, rw [←preimage_subset_preimage_iff hs, h],
rw [←preimage_subset_preimage_iff ht, h] },
rintro rfl, refl
end
@[simp] theorem preimage_inter_range {f : α → β} {s : set β} : f ⁻¹' (s ∩ range f) = f ⁻¹' s :=
set.ext $ λ x, and_iff_left ⟨x, rfl⟩
@[simp] theorem preimage_range_inter {f : α → β} {s : set β} : f ⁻¹' (range f ∩ s) = f ⁻¹' s :=
by rw [inter_comm, preimage_inter_range]
theorem preimage_image_preimage {f : α → β} {s : set β} :
f ⁻¹' (f '' (f ⁻¹' s)) = f ⁻¹' s :=
by rw [image_preimage_eq_inter_range, preimage_inter_range]
@[simp] theorem quot_mk_range_eq [setoid α] : range (λx : α, ⟦x⟧) = univ :=
range_iff_surjective.2 quot.exists_rep
lemma range_const_subset {c : α} : range (λx:ι, c) ⊆ {c} :=
range_subset_iff.2 $ λ x, rfl
@[simp] lemma range_const : ∀ [nonempty ι] {c : α}, range (λx:ι, c) = {c}
| ⟨x⟩ c := subset.antisymm range_const_subset $
assume y hy, (mem_singleton_iff.1 hy).symm ▸ mem_range_self x
lemma diagonal_eq_range {α : Type*} : diagonal α = range (λ x, (x, x)) :=
by { ext ⟨x, y⟩, simp [diagonal, eq_comm] }
theorem preimage_singleton_nonempty {f : α → β} {y : β} :
(f ⁻¹' {y}).nonempty ↔ y ∈ range f :=
iff.rfl
theorem preimage_singleton_eq_empty {f : α → β} {y : β} :
f ⁻¹' {y} = ∅ ↔ y ∉ range f :=
not_nonempty_iff_eq_empty.symm.trans $ not_congr preimage_singleton_nonempty
lemma range_subset_singleton {f : ι → α} {x : α} : range f ⊆ {x} ↔ f = const ι x :=
by simp [range_subset_iff, funext_iff, mem_singleton]
lemma image_compl_preimage {f : α → β} {s : set β} : f '' ((f ⁻¹' s)ᶜ) = range f \ s :=
by rw [compl_eq_univ_diff, image_diff_preimage, image_univ]
@[simp] theorem range_sigma_mk {β : α → Type*} (a : α) :
range (sigma.mk a : β a → Σ a, β a) = sigma.fst ⁻¹' {a} :=
begin
apply subset.antisymm,
{ rintros _ ⟨b, rfl⟩, simp },
{ rintros ⟨x, y⟩ (rfl|_),
exact mem_range_self y }
end
/-- Any map `f : ι → β` factors through a map `range_factorization f : ι → range f`. -/
def range_factorization (f : ι → β) : ι → range f :=
λ i, ⟨f i, mem_range_self i⟩
lemma range_factorization_eq {f : ι → β} :
subtype.val ∘ range_factorization f = f :=
funext $ λ i, rfl
lemma surjective_onto_range : surjective (range_factorization f) :=
λ ⟨_, ⟨i, rfl⟩⟩, ⟨i, rfl⟩
lemma image_eq_range (f : α → β) (s : set α) : f '' s = range (λ(x : s), f x) :=
by { ext, split, rintro ⟨x, h1, h2⟩, exact ⟨⟨x, h1⟩, h2⟩, rintro ⟨⟨x, h1⟩, h2⟩, exact ⟨x, h1, h2⟩ }
@[simp] lemma sum.elim_range {α β γ : Type*} (f : α → γ) (g : β → γ) :
range (sum.elim f g) = range f ∪ range g :=
by simp [set.ext_iff, mem_range]
lemma range_ite_subset' {p : Prop} [decidable p] {f g : α → β} :
range (if p then f else g) ⊆ range f ∪ range g :=
begin
by_cases h : p, {rw if_pos h, exact subset_union_left _ _},
{rw if_neg h, exact subset_union_right _ _}
end
lemma range_ite_subset {p : α → Prop} [decidable_pred p] {f g : α → β} :
range (λ x, if p x then f x else g x) ⊆ range f ∪ range g :=
begin
rw range_subset_iff, intro x, by_cases h : p x,
simp [if_pos h, mem_union, mem_range_self],
simp [if_neg h, mem_union, mem_range_self]
end
@[simp] lemma preimage_range (f : α → β) : f ⁻¹' (range f) = univ :=
eq_univ_of_forall mem_range_self
/-- The range of a function from a `unique` type contains just the
function applied to its single value. -/
lemma range_unique [h : unique ι] : range f = {f $ default ι} :=
begin
ext x,
rw mem_range,
split,
{ rintros ⟨i, hi⟩,
rw h.uniq i at hi,
exact hi ▸ mem_singleton _ },
{ exact λ h, ⟨default ι, h.symm⟩ }
end
lemma range_diff_image_subset (f : α → β) (s : set α) :
range f \ f '' s ⊆ f '' sᶜ :=
λ y ⟨⟨x, h₁⟩, h₂⟩, ⟨x, λ h, h₂ ⟨x, h, h₁⟩, h₁⟩
lemma range_diff_image {f : α → β} (H : injective f) (s : set α) :
range f \ f '' s = f '' sᶜ :=
subset.antisymm (range_diff_image_subset f s) $ λ y ⟨x, hx, hy⟩, hy ▸
⟨mem_range_self _, λ ⟨x', hx', eq⟩, hx $ H eq ▸ hx'⟩
end range
/-- The set `s` is pairwise `r` if `r x y` for all *distinct* `x y ∈ s`. -/
def pairwise_on (s : set α) (r : α → α → Prop) := ∀ x ∈ s, ∀ y ∈ s, x ≠ y → r x y
theorem pairwise_on.mono {s t : set α} {r}
(h : t ⊆ s) (hp : pairwise_on s r) : pairwise_on t r :=
λ x xt y yt, hp x (h xt) y (h yt)
theorem pairwise_on.mono' {s : set α} {r r' : α → α → Prop}
(H : ∀ a b, r a b → r' a b) (hp : pairwise_on s r) : pairwise_on s r' :=
λ x xs y ys h, H _ _ (hp x xs y ys h)
/-- If and only if `f` takes pairwise equal values on `s`, there is
some value it takes everywhere on `s`. -/
lemma pairwise_on_eq_iff_exists_eq [nonempty β] (s : set α) (f : α → β) :
(pairwise_on s (λ x y, f x = f y)) ↔ ∃ z, ∀ x ∈ s, f x = z :=
begin
split,
{ intro h,
rcases eq_empty_or_nonempty s with rfl | ⟨x, hx⟩,
{ exact ⟨classical.arbitrary β, λ x hx, false.elim hx⟩ },
{ use f x,
intros y hy,
by_cases hyx : y = x,
{ rw hyx },
{ exact h y hy x hx hyx } } },
{ rintros ⟨z, hz⟩ x hx y hy hne,
rw [hz x hx, hz y hy] }
end
protected lemma subsingleton.pairwise_on (h : s.subsingleton) (r : α → α → Prop) :
pairwise_on s r :=
λ x hx y hy hne, (hne (h hx hy)).elim
@[simp] lemma pairwise_on_empty (r : α → α → Prop) :
(∅ : set α).pairwise_on r :=
subsingleton_empty.pairwise_on r
@[simp] lemma pairwise_on_singleton (a : α) (r : α → α → Prop) :
pairwise_on {a} r :=
subsingleton_singleton.pairwise_on r
lemma pairwise_on_insert_of_symmetric {α} {s : set α} {a : α} {r : α → α → Prop}
(hr : symmetric r) :
(insert a s).pairwise_on r ↔ s.pairwise_on r ∧ ∀ b ∈ s, a ≠ b → r a b :=
begin
refine ⟨λ h, ⟨_, _⟩, λ h, _⟩,
{ exact h.mono (s.subset_insert a) },
{ intros b hb hn,
exact h a (s.mem_insert _) b (set.mem_insert_of_mem _ hb) hn },
{ intros b hb c hc hn,
rw [mem_insert_iff] at hb hc,
rcases hb with (rfl | hb);
rcases hc with (rfl | hc),
{ exact absurd rfl hn },
{ exact h.right _ hc hn },
{ exact hr (h.right _ hb hn.symm) },
{ exact h.left _ hb _ hc hn } }
end
end set
open set
namespace function
variables {ι : Sort*} {α : Type*} {β : Type*} {f : α → β}
lemma surjective.preimage_injective (hf : surjective f) : injective (preimage f) :=
assume s t, (preimage_eq_preimage hf).1
lemma injective.preimage_image (hf : injective f) (s : set α) : f ⁻¹' (f '' s) = s :=
preimage_image_eq s hf
lemma injective.preimage_surjective (hf : injective f) : surjective (preimage f) :=
by { intro s, use f '' s, rw hf.preimage_image }
lemma injective.subsingleton_image_iff (hf : injective f) {s : set α} :
(f '' s).subsingleton ↔ s.subsingleton :=
⟨subsingleton_of_image hf s, λ h, h.image f⟩
lemma surjective.image_preimage (hf : surjective f) (s : set β) : f '' (f ⁻¹' s) = s :=
image_preimage_eq s hf
lemma surjective.image_surjective (hf : surjective f) : surjective (image f) :=
by { intro s, use f ⁻¹' s, rw hf.image_preimage }
lemma injective.image_injective (hf : injective f) : injective (image f) :=
by { intros s t h, rw [←preimage_image_eq s hf, ←preimage_image_eq t hf, h] }
lemma surjective.preimage_subset_preimage_iff {s t : set β} (hf : surjective f) :
f ⁻¹' s ⊆ f ⁻¹' t ↔ s ⊆ t :=
by { apply preimage_subset_preimage_iff, rw [hf.range_eq], apply subset_univ }
lemma surjective.range_comp {ι' : Sort*} {f : ι → ι'} (hf : surjective f) (g : ι' → α) :
range (g ∘ f) = range g :=
ext $ λ y, (@surjective.exists _ _ _ hf (λ x, g x = y)).symm
lemma injective.nonempty_apply_iff {f : set α → set β} (hf : injective f)
(h2 : f ∅ = ∅) {s : set α} : (f s).nonempty ↔ s.nonempty :=
by rw [← ne_empty_iff_nonempty, ← h2, ← ne_empty_iff_nonempty, hf.ne_iff]
lemma injective.mem_range_iff_exists_unique (hf : injective f) {b : β} :
b ∈ range f ↔ ∃! a, f a = b :=
⟨λ ⟨a, h⟩, ⟨a, h, λ a' ha, hf (ha.trans h.symm)⟩, exists_unique.exists⟩
lemma injective.exists_unique_of_mem_range (hf : injective f) {b : β} (hb : b ∈ range f) :
∃! a, f a = b :=
hf.mem_range_iff_exists_unique.mp hb
end function
open function
/-! ### Image and preimage on subtypes -/
namespace subtype
variable {α : Type*}
lemma coe_image {p : α → Prop} {s : set (subtype p)} :
coe '' s = {x | ∃h : p x, (⟨x, h⟩ : subtype p) ∈ s} :=
set.ext $ assume a,
⟨assume ⟨⟨a', ha'⟩, in_s, h_eq⟩, h_eq ▸ ⟨ha', in_s⟩,
assume ⟨ha, in_s⟩, ⟨⟨a, ha⟩, in_s, rfl⟩⟩
lemma range_coe {s : set α} :
range (coe : s → α) = s :=
by { rw ← set.image_univ, simp [-set.image_univ, coe_image] }
/-- A variant of `range_coe`. Try to use `range_coe` if possible.
This version is useful when defining a new type that is defined as the subtype of something.
In that case, the coercion doesn't fire anymore. -/
lemma range_val {s : set α} :
range (subtype.val : s → α) = s :=
range_coe
/-- We make this the simp lemma instead of `range_coe`. The reason is that if we write
for `s : set α` the function `coe : s → α`, then the inferred implicit arguments of `coe` are
`coe α (λ x, x ∈ s)`. -/
@[simp] lemma range_coe_subtype {p : α → Prop} :
range (coe : subtype p → α) = {x | p x} :=
range_coe
@[simp] lemma coe_preimage_self (s : set α) : (coe : s → α) ⁻¹' s = univ :=
by rw [← preimage_range (coe : s → α), range_coe]
lemma range_val_subtype {p : α → Prop} :
range (subtype.val : subtype p → α) = {x | p x} :=
range_coe
theorem coe_image_subset (s : set α) (t : set s) : coe '' t ⊆ s :=
λ x ⟨y, yt, yvaleq⟩, by rw ←yvaleq; exact y.property
theorem coe_image_univ (s : set α) : (coe : s → α) '' set.univ = s :=
image_univ.trans range_coe
@[simp] theorem image_preimage_coe (s t : set α) :
(coe : s → α) '' (coe ⁻¹' t) = t ∩ s :=
image_preimage_eq_inter_range.trans $ congr_arg _ range_coe
theorem image_preimage_val (s t : set α) :
(subtype.val : s → α) '' (subtype.val ⁻¹' t) = t ∩ s :=
image_preimage_coe s t
theorem preimage_coe_eq_preimage_coe_iff {s t u : set α} :
((coe : s → α) ⁻¹' t = coe ⁻¹' u) ↔ t ∩ s = u ∩ s :=
begin
rw [←image_preimage_coe, ←image_preimage_coe],
split, { intro h, rw h },
intro h, exact coe_injective.image_injective h
end
theorem preimage_val_eq_preimage_val_iff (s t u : set α) :
((subtype.val : s → α) ⁻¹' t = subtype.val ⁻¹' u) ↔ (t ∩ s = u ∩ s) :=
preimage_coe_eq_preimage_coe_iff
lemma exists_set_subtype {t : set α} (p : set α → Prop) :
(∃(s : set t), p (coe '' s)) ↔ ∃(s : set α), s ⊆ t ∧ p s :=
begin
split,
{ rintro ⟨s, hs⟩, refine ⟨coe '' s, _, hs⟩,
convert image_subset_range _ _, rw [range_coe] },
rintro ⟨s, hs₁, hs₂⟩, refine ⟨coe ⁻¹' s, _⟩,
rw [image_preimage_eq_of_subset], exact hs₂, rw [range_coe], exact hs₁
end
lemma preimage_coe_nonempty {s t : set α} : ((coe : s → α) ⁻¹' t).nonempty ↔ (s ∩ t).nonempty :=
by rw [inter_comm, ← image_preimage_coe, nonempty_image_iff]
lemma preimage_coe_eq_empty {s t : set α} : (coe : s → α) ⁻¹' t = ∅ ↔ s ∩ t = ∅ :=
by simp only [← not_nonempty_iff_eq_empty, preimage_coe_nonempty]
@[simp] lemma preimage_coe_compl (s : set α) : (coe : s → α) ⁻¹' sᶜ = ∅ :=
preimage_coe_eq_empty.2 (inter_compl_self s)
@[simp] lemma preimage_coe_compl' (s : set α) : (coe : sᶜ → α) ⁻¹' s = ∅ :=
preimage_coe_eq_empty.2 (compl_inter_self s)
end subtype
namespace set
/-! ### Lemmas about cartesian product of sets -/
section prod
variables {α : Type*} {β : Type*} {γ : Type*} {δ : Type*}
variables {s s₁ s₂ : set α} {t t₁ t₂ : set β}
/-- The cartesian product `prod s t` is the set of `(a, b)`
such that `a ∈ s` and `b ∈ t`. -/
protected def prod (s : set α) (t : set β) : set (α × β) :=
{p | p.1 ∈ s ∧ p.2 ∈ t}
lemma prod_eq (s : set α) (t : set β) : s.prod t = prod.fst ⁻¹' s ∩ prod.snd ⁻¹' t := rfl
theorem mem_prod_eq {p : α × β} : p ∈ s.prod t = (p.1 ∈ s ∧ p.2 ∈ t) := rfl
@[simp] theorem mem_prod {p : α × β} : p ∈ s.prod t ↔ p.1 ∈ s ∧ p.2 ∈ t := iff.rfl
@[simp] theorem prod_mk_mem_set_prod_eq {a : α} {b : β} :
(a, b) ∈ s.prod t = (a ∈ s ∧ b ∈ t) := rfl
lemma mk_mem_prod {a : α} {b : β} (a_in : a ∈ s) (b_in : b ∈ t) : (a, b) ∈ s.prod t :=
⟨a_in, b_in⟩
theorem prod_mono {s₁ s₂ : set α} {t₁ t₂ : set β} (hs : s₁ ⊆ s₂) (ht : t₁ ⊆ t₂) :
s₁.prod t₁ ⊆ s₂.prod t₂ :=
assume x ⟨h₁, h₂⟩, ⟨hs h₁, ht h₂⟩
lemma prod_subset_iff {P : set (α × β)} :
(s.prod t ⊆ P) ↔ ∀ (x ∈ s) (y ∈ t), (x, y) ∈ P :=
⟨λ h _ xin _ yin, h (mk_mem_prod xin yin), λ h ⟨_, _⟩ pin, h _ pin.1 _ pin.2⟩
lemma forall_prod_set {p : α × β → Prop} :
(∀ x ∈ s.prod t, p x) ↔ ∀ (x ∈ s) (y ∈ t), p (x, y) :=
prod_subset_iff
lemma exists_prod_set {p : α × β → Prop} :
(∃ x ∈ s.prod t, p x) ↔ ∃ (x ∈ s) (y ∈ t), p (x, y) :=
by simp [and_assoc]
@[simp] theorem prod_empty : s.prod ∅ = (∅ : set (α × β)) :=
by { ext, simp }
@[simp] theorem empty_prod : set.prod ∅ t = (∅ : set (α × β)) :=
by { ext, simp }
@[simp] theorem univ_prod_univ : (@univ α).prod (@univ β) = univ :=
by { ext ⟨x, y⟩, simp }
lemma univ_prod {t : set β} : set.prod (univ : set α) t = prod.snd ⁻¹' t :=
by simp [prod_eq]
lemma prod_univ {s : set α} : set.prod s (univ : set β) = prod.fst ⁻¹' s :=
by simp [prod_eq]
@[simp] theorem singleton_prod {a : α} : set.prod {a} t = prod.mk a '' t :=
by { ext ⟨x, y⟩, simp [and.left_comm, eq_comm] }
@[simp] theorem prod_singleton {b : β} : s.prod {b} = (λ a, (a, b)) '' s :=
by { ext ⟨x, y⟩, simp [and.left_comm, eq_comm] }
theorem singleton_prod_singleton {a : α} {b : β} : set.prod {a} {b} = ({(a, b)} : set (α × β)) :=
by simp
@[simp] theorem union_prod : (s₁ ∪ s₂).prod t = s₁.prod t ∪ s₂.prod t :=
by { ext ⟨x, y⟩, simp [or_and_distrib_right] }
@[simp] theorem prod_union : s.prod (t₁ ∪ t₂) = s.prod t₁ ∪ s.prod t₂ :=
by { ext ⟨x, y⟩, simp [and_or_distrib_left] }
theorem prod_inter_prod : s₁.prod t₁ ∩ s₂.prod t₂ = (s₁ ∩ s₂).prod (t₁ ∩ t₂) :=
by { ext ⟨x, y⟩, simp [and_assoc, and.left_comm] }
theorem insert_prod {a : α} : (insert a s).prod t = (prod.mk a '' t) ∪ s.prod t :=
by { ext ⟨x, y⟩, simp [image, iff_def, or_imp_distrib, imp.swap] {contextual := tt} }
theorem prod_insert {b : β} : s.prod (insert b t) = ((λa, (a, b)) '' s) ∪ s.prod t :=
by { ext ⟨x, y⟩, simp [image, iff_def, or_imp_distrib, imp.swap] {contextual := tt} }
theorem prod_preimage_eq {f : γ → α} {g : δ → β} :
(f ⁻¹' s).prod (g ⁻¹' t) = (λ p, (f p.1, g p.2)) ⁻¹' s.prod t := rfl
lemma prod_preimage_left {f : γ → α} : (f ⁻¹' s).prod t = (λp, (f p.1, p.2)) ⁻¹' (s.prod t) := rfl
lemma prod_preimage_right {g : δ → β} : s.prod (g ⁻¹' t) = (λp, (p.1, g p.2)) ⁻¹' (s.prod t) := rfl
lemma preimage_prod_map_prod (f : α → β) (g : γ → δ) (s : set β) (t : set δ) :
prod.map f g ⁻¹' (s.prod t) = (f ⁻¹' s).prod (g ⁻¹' t) :=
rfl
lemma mk_preimage_prod (f : γ → α) (g : γ → β) :
(λ x, (f x, g x)) ⁻¹' s.prod t = f ⁻¹' s ∩ g ⁻¹' t := rfl
@[simp] lemma mk_preimage_prod_left {y : β} (h : y ∈ t) : (λ x, (x, y)) ⁻¹' s.prod t = s :=
by { ext x, simp [h] }
@[simp] lemma mk_preimage_prod_right {x : α} (h : x ∈ s) : prod.mk x ⁻¹' s.prod t = t :=
by { ext y, simp [h] }
@[simp] lemma mk_preimage_prod_left_eq_empty {y : β} (hy : y ∉ t) :
(λ x, (x, y)) ⁻¹' s.prod t = ∅ :=
by { ext z, simp [hy] }
@[simp] lemma mk_preimage_prod_right_eq_empty {x : α} (hx : x ∉ s) :
prod.mk x ⁻¹' s.prod t = ∅ :=
by { ext z, simp [hx] }
lemma mk_preimage_prod_left_eq_if {y : β} [decidable_pred (∈ t)] :
(λ x, (x, y)) ⁻¹' s.prod t = if y ∈ t then s else ∅ :=
by { split_ifs; simp [h] }
lemma mk_preimage_prod_right_eq_if {x : α} [decidable_pred (∈ s)] :
prod.mk x ⁻¹' s.prod t = if x ∈ s then t else ∅ :=
by { split_ifs; simp [h] }
lemma mk_preimage_prod_left_fn_eq_if {y : β} [decidable_pred (∈ t)] (f : γ → α) :
(λ x, (f x, y)) ⁻¹' s.prod t = if y ∈ t then f ⁻¹' s else ∅ :=
by rw [← mk_preimage_prod_left_eq_if, prod_preimage_left, preimage_preimage]
lemma mk_preimage_prod_right_fn_eq_if {x : α} [decidable_pred (∈ s)] (g : δ → β) :
(λ y, (x, g y)) ⁻¹' s.prod t = if x ∈ s then g ⁻¹' t else ∅ :=
by rw [← mk_preimage_prod_right_eq_if, prod_preimage_right, preimage_preimage]
theorem image_swap_eq_preimage_swap : image (@prod.swap α β) = preimage prod.swap :=
image_eq_preimage_of_inverse prod.swap_left_inverse prod.swap_right_inverse
theorem preimage_swap_prod {s : set α} {t : set β} : prod.swap ⁻¹' t.prod s = s.prod t :=
by { ext ⟨x, y⟩, simp [and_comm] }
theorem image_swap_prod : prod.swap '' t.prod s = s.prod t :=
by rw [image_swap_eq_preimage_swap, preimage_swap_prod]
theorem prod_image_image_eq {m₁ : α → γ} {m₂ : β → δ} :
(m₁ '' s).prod (m₂ '' t) = image (λp:α×β, (m₁ p.1, m₂ p.2)) (s.prod t) :=
ext $ by simp [-exists_and_distrib_right, exists_and_distrib_right.symm, and.left_comm,
and.assoc, and.comm]
theorem prod_range_range_eq {α β γ δ} {m₁ : α → γ} {m₂ : β → δ} :
(range m₁).prod (range m₂) = range (λp:α×β, (m₁ p.1, m₂ p.2)) :=
ext $ by simp [range]
@[simp] theorem range_prod_map {α β γ δ} {m₁ : α → γ} {m₂ : β → δ} :
range (prod.map m₁ m₂) = (range m₁).prod (range m₂) :=
prod_range_range_eq.symm
theorem prod_range_univ_eq {α β γ} {m₁ : α → γ} :
(range m₁).prod (univ : set β) = range (λp:α×β, (m₁ p.1, p.2)) :=
ext $ by simp [range]
theorem prod_univ_range_eq {α β δ} {m₂ : β → δ} :
(univ : set α).prod (range m₂) = range (λp:α×β, (p.1, m₂ p.2)) :=
ext $ by simp [range]
theorem nonempty.prod : s.nonempty → t.nonempty → (s.prod t).nonempty
| ⟨x, hx⟩ ⟨y, hy⟩ := ⟨(x, y), ⟨hx, hy⟩⟩
theorem nonempty.fst : (s.prod t).nonempty → s.nonempty
| ⟨p, hp⟩ := ⟨p.1, hp.1⟩
theorem nonempty.snd : (s.prod t).nonempty → t.nonempty
| ⟨p, hp⟩ := ⟨p.2, hp.2⟩
theorem prod_nonempty_iff : (s.prod t).nonempty ↔ s.nonempty ∧ t.nonempty :=
⟨λ h, ⟨h.fst, h.snd⟩, λ h, nonempty.prod h.1 h.2⟩
theorem prod_eq_empty_iff :
s.prod t = ∅ ↔ (s = ∅ ∨ t = ∅) :=
by simp only [not_nonempty_iff_eq_empty.symm, prod_nonempty_iff, not_and_distrib]
lemma prod_sub_preimage_iff {W : set γ} {f : α × β → γ} :
s.prod t ⊆ f ⁻¹' W ↔ ∀ a b, a ∈ s → b ∈ t → f (a, b) ∈ W :=
by simp [subset_def]
lemma fst_image_prod_subset (s : set α) (t : set β) :
prod.fst '' (s.prod t) ⊆ s :=
λ _ h, let ⟨_, ⟨h₂, _⟩, h₁⟩ := (set.mem_image _ _ _).1 h in h₁ ▸ h₂
lemma prod_subset_preimage_fst (s : set α) (t : set β) :
s.prod t ⊆ prod.fst ⁻¹' s :=
image_subset_iff.1 (fst_image_prod_subset s t)
lemma fst_image_prod (s : set β) {t : set α} (ht : t.nonempty) :
prod.fst '' (s.prod t) = s :=
set.subset.antisymm (fst_image_prod_subset _ _)
$ λ y y_in, let ⟨x, x_in⟩ := ht in
⟨(y, x), ⟨y_in, x_in⟩, rfl⟩
lemma snd_image_prod_subset (s : set α) (t : set β) :
prod.snd '' (s.prod t) ⊆ t :=
λ _ h, let ⟨_, ⟨_, h₂⟩, h₁⟩ := (set.mem_image _ _ _).1 h in h₁ ▸ h₂
lemma prod_subset_preimage_snd (s : set α) (t : set β) :
s.prod t ⊆ prod.snd ⁻¹' t :=
image_subset_iff.1 (snd_image_prod_subset s t)
lemma snd_image_prod {s : set α} (hs : s.nonempty) (t : set β) :
prod.snd '' (s.prod t) = t :=
set.subset.antisymm (snd_image_prod_subset _ _)
$ λ y y_in, let ⟨x, x_in⟩ := hs in
⟨(x, y), ⟨x_in, y_in⟩, rfl⟩
lemma prod_diff_prod : s.prod t \ s₁.prod t₁ = s.prod (t \ t₁) ∪ (s \ s₁).prod t :=
by { ext x, by_cases h₁ : x.1 ∈ s₁; by_cases h₂ : x.2 ∈ t₁; simp * }
/-- A product set is included in a product set if and only factors are included, or a factor of the
first set is empty. -/
lemma prod_subset_prod_iff :
(s.prod t ⊆ s₁.prod t₁) ↔ (s ⊆ s₁ ∧ t ⊆ t₁) ∨ (s = ∅) ∨ (t = ∅) :=
begin
classical,
cases (s.prod t).eq_empty_or_nonempty with h h,
{ simp [h, prod_eq_empty_iff.1 h] },
{ have st : s.nonempty ∧ t.nonempty, by rwa [prod_nonempty_iff] at h,
split,
{ assume H : s.prod t ⊆ s₁.prod t₁,
have h' : s₁.nonempty ∧ t₁.nonempty := prod_nonempty_iff.1 (h.mono H),
refine or.inl ⟨_, _⟩,
show s ⊆ s₁,
{ have := image_subset (prod.fst : α × β → α) H,
rwa [fst_image_prod _ st.2, fst_image_prod _ h'.2] at this },
show t ⊆ t₁,
{ have := image_subset (prod.snd : α × β → β) H,
rwa [snd_image_prod st.1, snd_image_prod h'.1] at this } },
{ assume H,
simp only [st.1.ne_empty, st.2.ne_empty, or_false] at H,
exact prod_mono H.1 H.2 } }
end
end prod
/-! ### Lemmas about set-indexed products of sets -/
section pi
variables {ι : Type*} {α : ι → Type*} {s s₁ : set ι} {t t₁ t₂ : Π i, set (α i)}
/-- Given an index set `ι` and a family of sets `t : Π i, set (α i)`, `pi s t`
is the set of dependent functions `f : Πa, π a` such that `f a` belongs to `t a`
whenever `a ∈ s`. -/
def pi (s : set ι) (t : Π i, set (α i)) : set (Π i, α i) := { f | ∀i ∈ s, f i ∈ t i }
@[simp] lemma mem_pi {f : Π i, α i} : f ∈ s.pi t ↔ ∀ i ∈ s, f i ∈ t i :=
by refl
@[simp] lemma mem_univ_pi {f : Π i, α i} : f ∈ pi univ t ↔ ∀ i, f i ∈ t i :=
by simp
@[simp] lemma empty_pi (s : Π i, set (α i)) : pi ∅ s = univ := by { ext, simp [pi] }
@[simp] lemma pi_univ (s : set ι) : pi s (λ i, (univ : set (α i))) = univ :=
eq_univ_of_forall $ λ f i hi, mem_univ _
lemma pi_mono (h : ∀ i ∈ s, t₁ i ⊆ t₂ i) : pi s t₁ ⊆ pi s t₂ :=
λ x hx i hi, (h i hi $ hx i hi)
lemma pi_inter_distrib : s.pi (λ i, t i ∩ t₁ i) = s.pi t ∩ s.pi t₁ :=
ext $ λ x, by simp only [forall_and_distrib, mem_pi, mem_inter_eq]
lemma pi_congr (h : s = s₁) (h' : ∀ i ∈ s, t i = t₁ i) : pi s t = pi s₁ t₁ :=
h ▸ (ext $ λ x, forall_congr $ λ i, forall_congr $ λ hi, h' i hi ▸ iff.rfl)
lemma pi_eq_empty {i : ι} (hs : i ∈ s) (ht : t i = ∅) : s.pi t = ∅ :=
by { ext f, simp only [mem_empty_eq, not_forall, iff_false, mem_pi, not_imp],
exact ⟨i, hs, by simp [ht]⟩ }
lemma univ_pi_eq_empty {i : ι} (ht : t i = ∅) : pi univ t = ∅ :=
pi_eq_empty (mem_univ i) ht
lemma pi_nonempty_iff : (s.pi t).nonempty ↔ ∀ i, ∃ x, i ∈ s → x ∈ t i :=
by simp [classical.skolem, set.nonempty]
lemma univ_pi_nonempty_iff : (pi univ t).nonempty ↔ ∀ i, (t i).nonempty :=
by simp [classical.skolem, set.nonempty]
lemma pi_eq_empty_iff : s.pi t = ∅ ↔ ∃ i, (α i → false) ∨ (i ∈ s ∧ t i = ∅) :=
begin
rw [← not_nonempty_iff_eq_empty, pi_nonempty_iff], push_neg, apply exists_congr, intro i,
split,
{ intro h, by_cases hα : nonempty (α i),
{ cases hα with x, refine or.inr ⟨(h x).1, by simp [eq_empty_iff_forall_not_mem, h]⟩ },
{ exact or.inl (λ x, hα ⟨x⟩) }},
{ rintro (h|h) x, exfalso, exact h x, simp [h] }
end
lemma univ_pi_eq_empty_iff : pi univ t = ∅ ↔ ∃ i, t i = ∅ :=
by simp [← not_nonempty_iff_eq_empty, univ_pi_nonempty_iff]
@[simp] lemma range_dcomp {β : ι → Type*} (f : Π i, α i → β i) :
range (λ (g : Π i, α i), (λ i, f i (g i))) = pi univ (λ i, range (f i)) :=
begin
apply subset.antisymm,
{ rintro _ ⟨x, rfl⟩ i -,
exact ⟨x i, rfl⟩ },
{ intros x hx,
choose y hy using hx,
exact ⟨λ i, y i trivial, funext $ λ i, hy i trivial⟩ }
end
@[simp] lemma insert_pi (i : ι) (s : set ι) (t : Π i, set (α i)) :
pi (insert i s) t = (eval i ⁻¹' t i) ∩ pi s t :=
by { ext, simp [pi, or_imp_distrib, forall_and_distrib] }
@[simp] lemma singleton_pi (i : ι) (t : Π i, set (α i)) :
pi {i} t = (eval i ⁻¹' t i) :=
by { ext, simp [pi] }
lemma singleton_pi' (i : ι) (t : Π i, set (α i)) : pi {i} t = {x | x i ∈ t i} :=
singleton_pi i t
lemma pi_if {p : ι → Prop} [h : decidable_pred p] (s : set ι) (t₁ t₂ : Π i, set (α i)) :
pi s (λ i, if p i then t₁ i else t₂ i) = pi {i ∈ s | p i} t₁ ∩ pi {i ∈ s | ¬ p i} t₂ :=
begin
ext f,
split,
{ assume h, split; { rintros i ⟨his, hpi⟩, simpa [*] using h i } },
{ rintros ⟨ht₁, ht₂⟩ i his,
by_cases p i; simp * at * }
end
lemma union_pi : (s ∪ s₁).pi t = s.pi t ∩ s₁.pi t :=
by simp [pi, or_imp_distrib, forall_and_distrib, set_of_and]
@[simp] lemma pi_inter_compl (s : set ι) : pi s t ∩ pi sᶜ t = pi univ t :=
by rw [← union_pi, union_compl_self]
lemma pi_update_of_not_mem [decidable_eq ι] {β : Π i, Type*} {i : ι} (hi : i ∉ s) (f : Π j, α j)
(a : α i) (t : Π j, α j → set (β j)) :
s.pi (λ j, t j (update f i a j)) = s.pi (λ j, t j (f j)) :=
pi_congr rfl $ λ j hj, by { rw update_noteq, exact λ h, hi (h ▸ hj) }
lemma pi_update_of_mem [decidable_eq ι] {β : Π i, Type*} {i : ι} (hi : i ∈ s) (f : Π j, α j)
(a : α i) (t : Π j, α j → set (β j)) :
s.pi (λ j, t j (update f i a j)) = {x | x i ∈ t i a} ∩ (s \ {i}).pi (λ j, t j (f j)) :=
calc s.pi (λ j, t j (update f i a j)) = ({i} ∪ s \ {i}).pi (λ j, t j (update f i a j)) :
by rw [union_diff_self, union_eq_self_of_subset_left (singleton_subset_iff.2 hi)]
... = {x | x i ∈ t i a} ∩ (s \ {i}).pi (λ j, t j (f j)) :
by { rw [union_pi, singleton_pi', update_same, pi_update_of_not_mem], simp }
lemma univ_pi_update [decidable_eq ι] {β : Π i, Type*} (i : ι) (f : Π j, α j)
(a : α i) (t : Π j, α j → set (β j)) :
pi univ (λ j, t j (update f i a j)) = {x | x i ∈ t i a} ∩ pi {i}ᶜ (λ j, t j (f j)) :=
by rw [compl_eq_univ_diff, ← pi_update_of_mem (mem_univ _)]
lemma univ_pi_update_univ [decidable_eq ι] (i : ι) (s : set (α i)) :
pi univ (update (λ j : ι, (univ : set (α j))) i s) = eval i ⁻¹' s :=
by rw [univ_pi_update i (λ j, (univ : set (α j))) s (λ j t, t), pi_univ, inter_univ, preimage]
open_locale classical
lemma eval_image_pi {i : ι} (hs : i ∈ s) (ht : (s.pi t).nonempty) : eval i '' s.pi t = t i :=
begin
ext x, rcases ht with ⟨f, hf⟩, split,
{ rintro ⟨g, hg, rfl⟩, exact hg i hs },
{ intro hg, refine ⟨update f i x, _, by simp⟩,
intros j hj, by_cases hji : j = i,
{ subst hji, simp [hg] },
{ rw [mem_pi] at hf, simp [hji, hf, hj] }},
end
@[simp] lemma eval_image_univ_pi {i : ι} (ht : (pi univ t).nonempty) :
(λ f : Π i, α i, f i) '' pi univ t = t i :=
eval_image_pi (mem_univ i) ht
lemma eval_preimage {ι} {α : ι → Type*} {i : ι} {s : set (α i)} :
eval i ⁻¹' s = pi univ (update (λ i, univ) i s) :=
by { ext x, simp [@forall_update_iff _ (λ i, set (α i)) _ _ _ _ (λ i' y, x i' ∈ y)] }
lemma eval_preimage' {ι} {α : ι → Type*} {i : ι} {s : set (α i)} :
eval i ⁻¹' s = pi {i} (update (λ i, univ) i s) :=
by { ext, simp }
lemma update_preimage_pi {i : ι} {f : Π i, α i} (hi : i ∈ s)
(hf : ∀ j ∈ s, j ≠ i → f j ∈ t j) : (update f i) ⁻¹' s.pi t = t i :=
begin
ext x, split,
{ intro h, convert h i hi, simp },
{ intros hx j hj, by_cases h : j = i,
{ cases h, simpa },
{ rw [update_noteq h], exact hf j hj h }}
end
lemma update_preimage_univ_pi {i : ι} {f : Π i, α i} (hf : ∀ j ≠ i, f j ∈ t j) :
(update f i) ⁻¹' pi univ t = t i :=
update_preimage_pi (mem_univ i) (λ j _, hf j)
lemma subset_pi_eval_image (s : set ι) (u : set (Π i, α i)) : u ⊆ pi s (λ i, eval i '' u) :=
λ f hf i hi, ⟨f, hf, rfl⟩
lemma univ_pi_ite (s : set ι) (t : Π i, set (α i)) :
pi univ (λ i, if i ∈ s then t i else univ) = s.pi t :=
by { ext, simp_rw [mem_univ_pi], apply forall_congr, intro i, split_ifs; simp [h] }
end pi
/-! ### Lemmas about `inclusion`, the injection of subtypes induced by `⊆` -/
section inclusion
variable {α : Type*}
/-- `inclusion` is the "identity" function between two subsets `s` and `t`, where `s ⊆ t` -/
def inclusion {s t : set α} (h : s ⊆ t) : s → t :=
λ x : s, (⟨x, h x.2⟩ : t)
@[simp] lemma inclusion_self {s : set α} (x : s) :
inclusion (set.subset.refl _) x = x :=
by { cases x, refl }
@[simp] lemma inclusion_right {s t : set α} (h : s ⊆ t) (x : t) (m : (x : α) ∈ s) :
inclusion h ⟨x, m⟩ = x :=
by { cases x, refl }
@[simp] lemma inclusion_inclusion {s t u : set α} (hst : s ⊆ t) (htu : t ⊆ u)
(x : s) : inclusion htu (inclusion hst x) = inclusion (set.subset.trans hst htu) x :=
by { cases x, refl }
@[simp] lemma coe_inclusion {s t : set α} (h : s ⊆ t) (x : s) :
(inclusion h x : α) = (x : α) := rfl
lemma inclusion_injective {s t : set α} (h : s ⊆ t) :
function.injective (inclusion h)
| ⟨_, _⟩ ⟨_, _⟩ := subtype.ext_iff_val.2 ∘ subtype.ext_iff_val.1
@[simp] lemma range_inclusion {s t : set α} (h : s ⊆ t) :
range (inclusion h) = {x : t | (x:α) ∈ s} :=
by { ext ⟨x, hx⟩, simp [inclusion] }
lemma eq_of_inclusion_surjective {s t : set α} {h : s ⊆ t}
(h_surj : function.surjective (inclusion h)) : s = t :=
begin
rw [← range_iff_surjective, range_inclusion, eq_univ_iff_forall] at h_surj,
exact set.subset.antisymm h (λ x hx, h_surj ⟨x, hx⟩)
end
end inclusion
/-! ### Injectivity and surjectivity lemmas for image and preimage -/
section image_preimage
variables {α : Type u} {β : Type v} {f : α → β}
@[simp]
lemma preimage_injective : injective (preimage f) ↔ surjective f :=
begin
refine ⟨λ h y, _, surjective.preimage_injective⟩,
obtain ⟨x, hx⟩ : (f ⁻¹' {y}).nonempty,
{ rw [h.nonempty_apply_iff preimage_empty], apply singleton_nonempty },
exact ⟨x, hx⟩
end
@[simp]
lemma preimage_surjective : surjective (preimage f) ↔ injective f :=
begin
refine ⟨λ h x x' hx, _, injective.preimage_surjective⟩,
cases h {x} with s hs, have := mem_singleton x,
rwa [← hs, mem_preimage, hx, ← mem_preimage, hs, mem_singleton_iff, eq_comm] at this
end
@[simp] lemma image_surjective : surjective (image f) ↔ surjective f :=
begin
refine ⟨λ h y, _, surjective.image_surjective⟩,
cases h {y} with s hs,
have := mem_singleton y, rw [← hs] at this, rcases this with ⟨x, h1x, h2x⟩,
exact ⟨x, h2x⟩
end
@[simp] lemma image_injective : injective (image f) ↔ injective f :=
begin
refine ⟨λ h x x' hx, _, injective.image_injective⟩,
rw [← singleton_eq_singleton_iff], apply h,
rw [image_singleton, image_singleton, hx]
end
lemma preimage_eq_iff_eq_image {f : α → β} (hf : bijective f) {s t} :
f ⁻¹' s = t ↔ s = f '' t :=
by rw [← image_eq_image hf.1, hf.2.image_preimage]
lemma eq_preimage_iff_image_eq {f : α → β} (hf : bijective f) {s t} :
s = f ⁻¹' t ↔ f '' s = t :=
by rw [← image_eq_image hf.1, hf.2.image_preimage]
end image_preimage
/-! ### Lemmas about images of binary and ternary functions -/
section n_ary_image
variables {α β γ δ ε : Type*} {f f' : α → β → γ} {g g' : α → β → γ → δ}
variables {s s' : set α} {t t' : set β} {u u' : set γ} {a a' : α} {b b' : β} {c c' : γ} {d d' : δ}
/-- The image of a binary function `f : α → β → γ` as a function `set α → set β → set γ`.
Mathematically this should be thought of as the image of the corresponding function `α × β → γ`.
-/
def image2 (f : α → β → γ) (s : set α) (t : set β) : set γ :=
{c | ∃ a b, a ∈ s ∧ b ∈ t ∧ f a b = c }
lemma mem_image2_eq : c ∈ image2 f s t = ∃ a b, a ∈ s ∧ b ∈ t ∧ f a b = c := rfl
@[simp] lemma mem_image2 : c ∈ image2 f s t ↔ ∃ a b, a ∈ s ∧ b ∈ t ∧ f a b = c := iff.rfl
lemma mem_image2_of_mem (h1 : a ∈ s) (h2 : b ∈ t) : f a b ∈ image2 f s t :=
⟨a, b, h1, h2, rfl⟩
lemma mem_image2_iff (hf : injective2 f) : f a b ∈ image2 f s t ↔ a ∈ s ∧ b ∈ t :=
⟨ by { rintro ⟨a', b', ha', hb', h⟩, rcases hf h with ⟨rfl, rfl⟩, exact ⟨ha', hb'⟩ },
λ ⟨ha, hb⟩, mem_image2_of_mem ha hb⟩
/-- image2 is monotone with respect to `⊆`. -/
lemma image2_subset (hs : s ⊆ s') (ht : t ⊆ t') : image2 f s t ⊆ image2 f s' t' :=
by { rintro _ ⟨a, b, ha, hb, rfl⟩, exact mem_image2_of_mem (hs ha) (ht hb) }
lemma forall_image2_iff {p : γ → Prop} :
(∀ z ∈ image2 f s t, p z) ↔ ∀ (x ∈ s) (y ∈ t), p (f x y) :=
⟨λ h x hx y hy, h _ ⟨x, y, hx, hy, rfl⟩, λ h z ⟨x, y, hx, hy, hz⟩, hz ▸ h x hx y hy⟩
@[simp] lemma image2_subset_iff {u : set γ} :
image2 f s t ⊆ u ↔ ∀ (x ∈ s) (y ∈ t), f x y ∈ u :=
forall_image2_iff
lemma image2_union_left : image2 f (s ∪ s') t = image2 f s t ∪ image2 f s' t :=
begin
ext c, split,
{ rintros ⟨a, b, h1a|h2a, hb, rfl⟩;[left, right]; exact ⟨_, _, ‹_›, ‹_›, rfl⟩ },
{ rintro (⟨_, _, _, _, rfl⟩|⟨_, _, _, _, rfl⟩); refine ⟨_, _, _, ‹_›, rfl⟩; simp [mem_union, *] }
end
lemma image2_union_right : image2 f s (t ∪ t') = image2 f s t ∪ image2 f s t' :=
begin
ext c, split,
{ rintros ⟨a, b, ha, h1b|h2b, rfl⟩;[left, right]; exact ⟨_, _, ‹_›, ‹_›, rfl⟩ },
{ rintro (⟨_, _, _, _, rfl⟩|⟨_, _, _, _, rfl⟩); refine ⟨_, _, ‹_›, _, rfl⟩; simp [mem_union, *] }
end
@[simp] lemma image2_empty_left : image2 f ∅ t = ∅ := ext $ by simp
@[simp] lemma image2_empty_right : image2 f s ∅ = ∅ := ext $ by simp
lemma image2_inter_subset_left : image2 f (s ∩ s') t ⊆ image2 f s t ∩ image2 f s' t :=
by { rintro _ ⟨a, b, ⟨h1a, h2a⟩, hb, rfl⟩, split; exact ⟨_, _, ‹_›, ‹_›, rfl⟩ }
lemma image2_inter_subset_right : image2 f s (t ∩ t') ⊆ image2 f s t ∩ image2 f s t' :=
by { rintro _ ⟨a, b, ha, ⟨h1b, h2b⟩, rfl⟩, split; exact ⟨_, _, ‹_›, ‹_›, rfl⟩ }
@[simp] lemma image2_singleton_left : image2 f {a} t = f a '' t :=
ext $ λ x, by simp
@[simp] lemma image2_singleton_right : image2 f s {b} = (λ a, f a b) '' s :=
ext $ λ x, by simp
lemma image2_singleton : image2 f {a} {b} = {f a b} := by simp
@[congr] lemma image2_congr (h : ∀ (a ∈ s) (b ∈ t), f a b = f' a b) :
image2 f s t = image2 f' s t :=
by { ext, split; rintro ⟨a, b, ha, hb, rfl⟩; refine ⟨a, b, ha, hb, by rw h a ha b hb⟩ }
/-- A common special case of `image2_congr` -/
lemma image2_congr' (h : ∀ a b, f a b = f' a b) : image2 f s t = image2 f' s t :=
image2_congr (λ a _ b _, h a b)
/-- The image of a ternary function `f : α → β → γ → δ` as a function
`set α → set β → set γ → set δ`. Mathematically this should be thought of as the image of the
corresponding function `α × β × γ → δ`.
-/
def image3 (g : α → β → γ → δ) (s : set α) (t : set β) (u : set γ) : set δ :=
{d | ∃ a b c, a ∈ s ∧ b ∈ t ∧ c ∈ u ∧ g a b c = d }
@[simp] lemma mem_image3 : d ∈ image3 g s t u ↔ ∃ a b c, a ∈ s ∧ b ∈ t ∧ c ∈ u ∧ g a b c = d :=
iff.rfl
@[congr] lemma image3_congr (h : ∀ (a ∈ s) (b ∈ t) (c ∈ u), g a b c = g' a b c) :
image3 g s t u = image3 g' s t u :=
by { ext x,
split; rintro ⟨a, b, c, ha, hb, hc, rfl⟩; exact ⟨a, b, c, ha, hb, hc, by rw h a ha b hb c hc⟩ }
/-- A common special case of `image3_congr` -/
lemma image3_congr' (h : ∀ a b c, g a b c = g' a b c) : image3 g s t u = image3 g' s t u :=
image3_congr (λ a _ b _ c _, h a b c)
lemma image2_image2_left (f : δ → γ → ε) (g : α → β → δ) :
image2 f (image2 g s t) u = image3 (λ a b c, f (g a b) c) s t u :=
begin
ext, split,
{ rintro ⟨_, c, ⟨a, b, ha, hb, rfl⟩, hc, rfl⟩, refine ⟨a, b, c, ha, hb, hc, rfl⟩ },
{ rintro ⟨a, b, c, ha, hb, hc, rfl⟩, refine ⟨_, c, ⟨a, b, ha, hb, rfl⟩, hc, rfl⟩ }
end
lemma image2_image2_right (f : α → δ → ε) (g : β → γ → δ) :
image2 f s (image2 g t u) = image3 (λ a b c, f a (g b c)) s t u :=
begin
ext, split,
{ rintro ⟨a, _, ha, ⟨b, c, hb, hc, rfl⟩, rfl⟩, refine ⟨a, b, c, ha, hb, hc, rfl⟩ },
{ rintro ⟨a, b, c, ha, hb, hc, rfl⟩, refine ⟨a, _, ha, ⟨b, c, hb, hc, rfl⟩, rfl⟩ }
end
lemma image2_assoc {ε'} {f : δ → γ → ε} {g : α → β → δ} {f' : α → ε' → ε} {g' : β → γ → ε'}
(h_assoc : ∀ a b c, f (g a b) c = f' a (g' b c)) :
image2 f (image2 g s t) u = image2 f' s (image2 g' t u) :=
by simp only [image2_image2_left, image2_image2_right, h_assoc]
lemma image_image2 (f : α → β → γ) (g : γ → δ) :
g '' image2 f s t = image2 (λ a b, g (f a b)) s t :=
begin
ext, split,
{ rintro ⟨_, ⟨a, b, ha, hb, rfl⟩, rfl⟩, refine ⟨a, b, ha, hb, rfl⟩ },
{ rintro ⟨a, b, ha, hb, rfl⟩, refine ⟨_, ⟨a, b, ha, hb, rfl⟩, rfl⟩ }
end
lemma image2_image_left (f : γ → β → δ) (g : α → γ) :
image2 f (g '' s) t = image2 (λ a b, f (g a) b) s t :=
begin
ext, split,
{ rintro ⟨_, b, ⟨a, ha, rfl⟩, hb, rfl⟩, refine ⟨a, b, ha, hb, rfl⟩ },
{ rintro ⟨a, b, ha, hb, rfl⟩, refine ⟨_, b, ⟨a, ha, rfl⟩, hb, rfl⟩ }
end
lemma image2_image_right (f : α → γ → δ) (g : β → γ) :
image2 f s (g '' t) = image2 (λ a b, f a (g b)) s t :=
begin
ext, split,
{ rintro ⟨a, _, ha, ⟨b, hb, rfl⟩, rfl⟩, refine ⟨a, b, ha, hb, rfl⟩ },
{ rintro ⟨a, b, ha, hb, rfl⟩, refine ⟨a, _, ha, ⟨b, hb, rfl⟩, rfl⟩ }
end
lemma image2_swap (f : α → β → γ) (s : set α) (t : set β) :
image2 f s t = image2 (λ a b, f b a) t s :=
by { ext, split; rintro ⟨a, b, ha, hb, rfl⟩; refine ⟨b, a, hb, ha, rfl⟩ }
@[simp] lemma image2_left (h : t.nonempty) : image2 (λ x y, x) s t = s :=
by simp [nonempty_def.mp h, ext_iff]
@[simp] lemma image2_right (h : s.nonempty) : image2 (λ x y, y) s t = t :=
by simp [nonempty_def.mp h, ext_iff]
@[simp] lemma image_prod (f : α → β → γ) : (λ x : α × β, f x.1 x.2) '' s.prod t = image2 f s t :=
set.ext $ λ a,
⟨ by { rintros ⟨_, _, rfl⟩, exact ⟨_, _, (mem_prod.mp ‹_›).1, (mem_prod.mp ‹_›).2, rfl⟩ },
by { rintros ⟨_, _, _, _, rfl⟩, exact ⟨(_, _), mem_prod.mpr ⟨‹_›, ‹_›⟩, rfl⟩ }⟩
lemma nonempty.image2 (hs : s.nonempty) (ht : t.nonempty) : (image2 f s t).nonempty :=
by { cases hs with a ha, cases ht with b hb, exact ⟨f a b, ⟨a, b, ha, hb, rfl⟩⟩ }
end n_ary_image
end set
namespace subsingleton
variables {α : Type*} [subsingleton α]
lemma eq_univ_of_nonempty {s : set α} : s.nonempty → s = univ :=
λ ⟨x, hx⟩, eq_univ_of_forall $ λ y, subsingleton.elim x y ▸ hx
@[elab_as_eliminator]
lemma set_cases {p : set α → Prop} (h0 : p ∅) (h1 : p univ) (s) : p s :=
s.eq_empty_or_nonempty.elim (λ h, h.symm ▸ h0) $ λ h, (eq_univ_of_nonempty h).symm ▸ h1
end subsingleton
|
50bbed17b64beaf42b69dd1deef7f379d9425c60 | 618003631150032a5676f229d13a079ac875ff77 | /roadmap/topology/paracompact.lean | 0eb48b512a9b4fbe46143da5b6fd442266b59661 | [
"Apache-2.0"
] | permissive | awainverse/mathlib | 939b68c8486df66cfda64d327ad3d9165248c777 | ea76bd8f3ca0a8bf0a166a06a475b10663dec44a | refs/heads/master | 1,659,592,962,036 | 1,590,987,592,000 | 1,590,987,592,000 | 268,436,019 | 1 | 0 | Apache-2.0 | 1,590,990,500,000 | 1,590,990,500,000 | null | UTF-8 | Lean | false | false | 3,137 | 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 ..todo
import topology.subset_properties
import topology.separation
import topology.metric_space.basic
/-!
A formal roadmap for basic properties of paracompact spaces.
It contains the statements that compact spaces and metric spaces are paracompact,
and that paracompact t2 spaces are normal, as well as partially formalised proofs.
Any contributor should feel welcome to contribute complete proofs. When this happens,
we should also consider preserving the current file as an exemplar of a formal roadmap.
-/
open set filter
universe u
class paracompact_space (X : Type u) [topological_space X] : Prop :=
(locally_finite_refinement :
∀ {α : Type u} (u : α → set X) (uo : ∀ a, is_open (u a)) (uc : Union u = univ),
∃ {β : Type u} (v : β → set X) (vo : ∀ b, is_open (v b)) (vc : Union v = univ),
locally_finite v ∧ ∀ b, ∃ a, v b ⊆ u a)
/-- Any open cover of a paracompact space has a locally finite *precise* refinement, that is,
one indexed on the same type with each open set contained in the corresponding original one. -/
lemma paracompact_space.precise_refinement {X : Type u} [topological_space X] [paracompact_space X]
{α : Type u} (u : α → set X) (uo : ∀ a, is_open (u a)) (uc : Union u = univ) :
∃ v : α → set X, (∀ a, is_open (v a)) ∧ Union v = univ ∧ locally_finite v ∧ (∀ a, v a ⊆ u a) :=
begin
obtain ⟨β, w, wo, wc, lfw, wr⟩ := paracompact_space.locally_finite_refinement u uo uc,
choose f hf using wr,
refine ⟨λ a, ⋃₀ {s | ∃ b, f b = a ∧ s = w b}, λ a, _, _, _, λ a, _⟩,
{ apply is_open_sUnion _,
rintros t ⟨b, rfl, rfl⟩,
apply wo },
{ todo },
{ todo },
{ apply sUnion_subset,
rintros t ⟨b, rfl, rfl⟩,
apply hf }
end
lemma paracompact_of_compact {X : Type u} [topological_space X] [compact_space X] :
paracompact_space X :=
begin
refine ⟨λ α u uo uc, _⟩,
obtain ⟨s, _, sf, sc⟩ :=
compact_univ.elim_finite_subcover_image (λ a _, uo a) (by rwa [univ_subset_iff, bUnion_univ]),
refine ⟨s, λ b, u b.val, λ b, uo b.val, _, _, λ b, ⟨b.val, subset.refl _⟩⟩,
{ todo },
{ intro x,
refine ⟨univ, univ_mem_sets, _⟩,
todo },
end
lemma normal_of_paracompact_t2 {X : Type u} [topological_space X] [t2_space X]
[paracompact_space X] : normal_space X :=
todo
/-
Similar to the proof of `generalized_tube_lemma`, but different enough not to merge them.
Lemma: if `s : set X` is closed and can be separated from any point by open sets,
then `s` can also be separated from any closed set by open sets. Apply twice.
See
* Bourbaki, General Topology, Chapter IX, §4.4
* https://ncatlab.org/nlab/show/paracompact+Hausdorff+spaces+are+normal
-/
lemma paracompact_of_metric {X : Type u} [metric_space X] : paracompact_space X :=
todo
/-
See Mary Ellen Rudin, A new proof that metric spaces are paracompact.
https://www.ams.org/journals/proc/1969-020-02/S0002-9939-1969-0236876-3/S0002-9939-1969-0236876-3.pdf
-/
|
8c220a35823e3c30fcc09804615b08ceed503da7 | d406927ab5617694ec9ea7001f101b7c9e3d9702 | /src/algebra/order/monoid/with_top.lean | 8665adece4cc690e845f74752aae51cb01ada5e3 | [
"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 | 20,767 | 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.hom.group
import algebra.order.monoid.order_dual
import algebra.order.monoid.with_zero.basic
import data.nat.cast.defs
/-! # Adjoining top/bottom elements to ordered monoids. -/
universes u v
variables {α : Type u} {β : Type v}
open function
namespace with_top
section has_one
variables [has_one α]
@[to_additive] instance : has_one (with_top α) := ⟨(1 : α)⟩
@[simp, norm_cast, to_additive] lemma coe_one : ((1 : α) : with_top α) = 1 := rfl
@[simp, norm_cast, to_additive] lemma coe_eq_one {a : α} : (a : with_top α) = 1 ↔ a = 1 :=
coe_eq_coe
@[simp, norm_cast, to_additive coe_pos]
lemma one_lt_coe [has_lt α] {a : α} : 1 < (a : with_top α) ↔ 1 < a := coe_lt_coe
@[simp, norm_cast, to_additive coe_lt_zero]
lemma coe_lt_one [has_lt α] {a : α} : (a : with_top α) < 1 ↔ a < 1 := coe_lt_coe
@[simp, to_additive] protected lemma map_one {β} (f : α → β) :
(1 : with_top α).map f = (f 1 : with_top β) := rfl
@[simp, norm_cast, to_additive] theorem one_eq_coe {a : α} : 1 = (a : with_top α) ↔ a = 1 :=
trans eq_comm coe_eq_one
@[simp, to_additive] theorem top_ne_one : ⊤ ≠ (1 : with_top α) .
@[simp, to_additive] theorem one_ne_top : (1 : with_top α) ≠ ⊤ .
instance [has_zero α] [has_le α] [zero_le_one_class α] : zero_le_one_class (with_top α) :=
⟨some_le_some.2 zero_le_one⟩
end has_one
section has_add
variables [has_add α] {a b c d : with_top α} {x y : α}
instance : has_add (with_top α) := ⟨λ o₁ o₂, o₁.bind $ λ a, o₂.map $ (+) a⟩
@[norm_cast] lemma coe_add : ((x + y : α) : with_top α) = x + y := rfl
@[norm_cast] lemma coe_bit0 : ((bit0 x : α) : with_top α) = bit0 x := rfl
@[norm_cast] lemma coe_bit1 [has_one α] {a : α} : ((bit1 a : α) : with_top α) = bit1 a := rfl
@[simp] lemma top_add (a : with_top α) : ⊤ + a = ⊤ := rfl
@[simp] lemma add_top (a : with_top α) : a + ⊤ = ⊤ := by cases a; refl
@[simp] lemma add_eq_top : a + b = ⊤ ↔ a = ⊤ ∨ b = ⊤ :=
by cases a; cases b; simp [none_eq_top, some_eq_coe, ←with_top.coe_add]
lemma add_ne_top : a + b ≠ ⊤ ↔ a ≠ ⊤ ∧ b ≠ ⊤ := add_eq_top.not.trans not_or_distrib
lemma add_lt_top [partial_order α] {a b : with_top α} : a + b < ⊤ ↔ a < ⊤ ∧ b < ⊤ :=
by simp_rw [lt_top_iff_ne_top, add_ne_top]
lemma add_eq_coe : ∀ {a b : with_top α} {c : α},
a + b = c ↔ ∃ (a' b' : α), ↑a' = a ∧ ↑b' = b ∧ a' + b' = c
| none b c := by simp [none_eq_top]
| (some a) none c := by simp [none_eq_top]
| (some a) (some b) c :=
by simp only [some_eq_coe, ← coe_add, coe_eq_coe, exists_and_distrib_left, exists_eq_left]
@[simp] lemma add_coe_eq_top_iff {x : with_top α} {y : α} : x + y = ⊤ ↔ x = ⊤ :=
by { induction x using with_top.rec_top_coe; simp [← coe_add] }
@[simp] lemma coe_add_eq_top_iff {y : with_top α} : ↑x + y = ⊤ ↔ y = ⊤ :=
by { induction y using with_top.rec_top_coe; simp [← coe_add] }
instance covariant_class_add_le [has_le α] [covariant_class α α (+) (≤)] :
covariant_class (with_top α) (with_top α) (+) (≤) :=
⟨λ a b c h, begin
cases a; cases c; try { exact le_top },
rcases le_coe_iff.1 h with ⟨b, rfl, h'⟩,
exact coe_le_coe.2 (add_le_add_left (coe_le_coe.1 h) _)
end⟩
instance covariant_class_swap_add_le [has_le α] [covariant_class α α (swap (+)) (≤)] :
covariant_class (with_top α) (with_top α) (swap (+)) (≤) :=
⟨λ a b c h, begin
cases a; cases c; try { exact le_top },
rcases le_coe_iff.1 h with ⟨b, rfl, h'⟩,
exact coe_le_coe.2 (add_le_add_right (coe_le_coe.1 h) _)
end⟩
instance contravariant_class_add_lt [has_lt α] [contravariant_class α α (+) (<)] :
contravariant_class (with_top α) (with_top α) (+) (<) :=
⟨λ a b c h, begin
induction a using with_top.rec_top_coe, { exact (not_none_lt _ h).elim },
induction b using with_top.rec_top_coe, { exact (not_none_lt _ h).elim },
induction c using with_top.rec_top_coe,
{ exact coe_lt_top _ },
{ exact coe_lt_coe.2 (lt_of_add_lt_add_left $ coe_lt_coe.1 h) }
end⟩
instance contravariant_class_swap_add_lt [has_lt α] [contravariant_class α α (swap (+)) (<)] :
contravariant_class (with_top α) (with_top α) (swap (+)) (<) :=
⟨λ a b c h, begin
cases a; cases b; try { exact (not_none_lt _ h).elim },
cases c,
{ exact coe_lt_top _ },
{ exact coe_lt_coe.2 (lt_of_add_lt_add_right $ coe_lt_coe.1 h) }
end⟩
protected lemma le_of_add_le_add_left [has_le α] [contravariant_class α α (+) (≤)] (ha : a ≠ ⊤)
(h : a + b ≤ a + c) : b ≤ c :=
begin
lift a to α using ha,
induction c using with_top.rec_top_coe, { exact le_top },
induction b using with_top.rec_top_coe, { exact (not_top_le_coe _ h).elim },
simp only [← coe_add, coe_le_coe] at h ⊢,
exact le_of_add_le_add_left h
end
protected lemma le_of_add_le_add_right [has_le α] [contravariant_class α α (swap (+)) (≤)]
(ha : a ≠ ⊤) (h : b + a ≤ c + a) : b ≤ c :=
begin
lift a to α using ha,
cases c,
{ exact le_top },
cases b,
{ exact (not_top_le_coe _ h).elim },
{ exact coe_le_coe.2 (le_of_add_le_add_right $ coe_le_coe.1 h) }
end
protected lemma add_lt_add_left [has_lt α] [covariant_class α α (+) (<)] (ha : a ≠ ⊤) (h : b < c) :
a + b < a + c :=
begin
lift a to α using ha,
rcases lt_iff_exists_coe.1 h with ⟨b, rfl, h'⟩,
cases c,
{ exact coe_lt_top _ },
{ exact coe_lt_coe.2 (add_lt_add_left (coe_lt_coe.1 h) _) }
end
protected lemma add_lt_add_right [has_lt α] [covariant_class α α (swap (+)) (<)]
(ha : a ≠ ⊤) (h : b < c) :
b + a < c + a :=
begin
lift a to α using ha,
rcases lt_iff_exists_coe.1 h with ⟨b, rfl, h'⟩,
cases c,
{ exact coe_lt_top _ },
{ exact coe_lt_coe.2 (add_lt_add_right (coe_lt_coe.1 h) _) }
end
protected lemma add_le_add_iff_left [has_le α] [covariant_class α α (+) (≤)]
[contravariant_class α α (+) (≤)]
(ha : a ≠ ⊤) : a + b ≤ a + c ↔ b ≤ c :=
⟨with_top.le_of_add_le_add_left ha, λ h, add_le_add_left h a⟩
protected lemma add_le_add_iff_right [has_le α] [covariant_class α α (swap (+)) (≤)]
[contravariant_class α α (swap (+)) (≤)] (ha : a ≠ ⊤) : b + a ≤ c + a ↔ b ≤ c :=
⟨with_top.le_of_add_le_add_right ha, λ h, add_le_add_right h a⟩
protected lemma add_lt_add_iff_left [has_lt α] [covariant_class α α (+) (<)]
[contravariant_class α α (+) (<)] (ha : a ≠ ⊤) : a + b < a + c ↔ b < c :=
⟨lt_of_add_lt_add_left, with_top.add_lt_add_left ha⟩
protected lemma add_lt_add_iff_right [has_lt α] [covariant_class α α (swap (+)) (<)]
[contravariant_class α α (swap (+)) (<)] (ha : a ≠ ⊤) : b + a < c + a ↔ b < c :=
⟨lt_of_add_lt_add_right, with_top.add_lt_add_right ha⟩
protected lemma add_lt_add_of_le_of_lt [preorder α] [covariant_class α α (+) (<)]
[covariant_class α α (swap (+)) (≤)] (ha : a ≠ ⊤) (hab : a ≤ b) (hcd : c < d) : a + c < b + d :=
(with_top.add_lt_add_left ha hcd).trans_le $ add_le_add_right hab _
protected lemma add_lt_add_of_lt_of_le [preorder α] [covariant_class α α (+) (≤)]
[covariant_class α α (swap (+)) (<)] (hc : c ≠ ⊤) (hab : a < b) (hcd : c ≤ d) : a + c < b + d :=
(with_top.add_lt_add_right hc hab).trans_le $ add_le_add_left hcd _
/- There is no `with_top.map_mul_of_mul_hom`, since `with_top` does not have a multiplication. -/
@[simp] protected lemma map_add {F} [has_add β] [add_hom_class F α β] (f : F) (a b : with_top α) :
(a + b).map f = a.map f + b.map f :=
begin
induction a using with_top.rec_top_coe,
{ exact (top_add _).symm },
{ induction b using with_top.rec_top_coe,
{ exact (add_top _).symm },
{ rw [map_coe, map_coe, ← coe_add, ← coe_add, ← map_add],
refl } },
end
end has_add
instance [add_semigroup α] : add_semigroup (with_top α) :=
{ add_assoc := begin
repeat { refine with_top.rec_top_coe _ _; try { intro }};
simp [←with_top.coe_add, add_assoc]
end,
..with_top.has_add }
instance [add_comm_semigroup α] : add_comm_semigroup (with_top α) :=
{ add_comm :=
begin
repeat { refine with_top.rec_top_coe _ _; try { intro }};
simp [←with_top.coe_add, add_comm]
end,
..with_top.add_semigroup }
instance [add_zero_class α] : add_zero_class (with_top α) :=
{ zero_add :=
begin
refine with_top.rec_top_coe _ _,
{ simp },
{ intro,
rw [←with_top.coe_zero, ←with_top.coe_add, zero_add] }
end,
add_zero :=
begin
refine with_top.rec_top_coe _ _,
{ simp },
{ intro,
rw [←with_top.coe_zero, ←with_top.coe_add, add_zero] }
end,
..with_top.has_zero,
..with_top.has_add }
instance [add_monoid α] : add_monoid (with_top α) :=
{ ..with_top.add_zero_class,
..with_top.has_zero,
..with_top.add_semigroup }
instance [add_comm_monoid α] : add_comm_monoid (with_top α) :=
{ ..with_top.add_monoid, ..with_top.add_comm_semigroup }
instance [add_monoid_with_one α] : add_monoid_with_one (with_top α) :=
{ nat_cast := λ n, ↑(n : α),
nat_cast_zero := by rw [nat.cast_zero, with_top.coe_zero],
nat_cast_succ := λ n, by rw [nat.cast_add_one, with_top.coe_add, with_top.coe_one],
.. with_top.has_one, .. with_top.add_monoid }
instance [add_comm_monoid_with_one α] : add_comm_monoid_with_one (with_top α) :=
{ .. with_top.add_monoid_with_one, .. with_top.add_comm_monoid }
instance [ordered_add_comm_monoid α] : ordered_add_comm_monoid (with_top α) :=
{ add_le_add_left :=
begin
rintros a b h (_|c), { simp [none_eq_top] },
rcases b with (_|b), { simp [none_eq_top] },
rcases le_coe_iff.1 h with ⟨a, rfl, h⟩,
simp only [some_eq_coe, ← coe_add, coe_le_coe] at h ⊢,
exact add_le_add_left h c
end,
..with_top.partial_order, ..with_top.add_comm_monoid }
instance [linear_ordered_add_comm_monoid α] :
linear_ordered_add_comm_monoid_with_top (with_top α) :=
{ top_add' := with_top.top_add,
..with_top.order_top,
..with_top.linear_order,
..with_top.ordered_add_comm_monoid,
..option.nontrivial }
instance [has_le α] [has_add α] [has_exists_add_of_le α] : has_exists_add_of_le (with_top α) :=
⟨λ a b, match a, b with
| ⊤, ⊤ := by simp
| (a : α), ⊤ := λ _, ⟨⊤, rfl⟩
| (a : α), (b : α) := λ h, begin
obtain ⟨c, rfl⟩ := exists_add_of_le (with_top.coe_le_coe.1 h),
exact ⟨c, rfl⟩
end
| ⊤, (b : α) := λ h, (not_top_le_coe _ h).elim
end⟩
instance [canonically_ordered_add_monoid α] : canonically_ordered_add_monoid (with_top α) :=
{ le_self_add := λ a b, match a, b with
| ⊤, ⊤ := le_rfl
| (a : α), ⊤ := le_top
| (a : α), (b : α) := with_top.coe_le_coe.2 le_self_add
| ⊤, (b : α) := le_rfl
end,
..with_top.order_bot, ..with_top.ordered_add_comm_monoid, ..with_top.has_exists_add_of_le }
instance [canonically_linear_ordered_add_monoid α] :
canonically_linear_ordered_add_monoid (with_top α) :=
{ ..with_top.canonically_ordered_add_monoid, ..with_top.linear_order }
@[simp, norm_cast] lemma coe_nat [add_monoid_with_one α] (n : ℕ) : ((n : α) : with_top α) = n := rfl
@[simp] lemma nat_ne_top [add_monoid_with_one α] (n : ℕ) : (n : with_top α) ≠ ⊤ := coe_ne_top
@[simp] lemma top_ne_nat [add_monoid_with_one α] (n : ℕ) : (⊤ : with_top α) ≠ n := top_ne_coe
/-- Coercion from `α` to `with_top α` as an `add_monoid_hom`. -/
def coe_add_hom [add_monoid α] : α →+ with_top α :=
⟨coe, rfl, λ _ _, rfl⟩
@[simp] lemma coe_coe_add_hom [add_monoid α] : ⇑(coe_add_hom : α →+ with_top α) = coe := rfl
@[simp] lemma zero_lt_top [ordered_add_comm_monoid α] : (0 : with_top α) < ⊤ :=
coe_lt_top 0
@[simp, norm_cast] lemma zero_lt_coe [ordered_add_comm_monoid α] (a : α) :
(0 : with_top α) < a ↔ 0 < a :=
coe_lt_coe
/-- A version of `with_top.map` for `one_hom`s. -/
@[to_additive "A version of `with_top.map` for `zero_hom`s", simps { fully_applied := ff }]
protected def _root_.one_hom.with_top_map {M N : Type*} [has_one M] [has_one N] (f : one_hom M N) :
one_hom (with_top M) (with_top N) :=
{ to_fun := with_top.map f,
map_one' := by rw [with_top.map_one, map_one, coe_one] }
/-- A version of `with_top.map` for `add_hom`s. -/
@[simps { fully_applied := ff }] protected def _root_.add_hom.with_top_map
{M N : Type*} [has_add M] [has_add N] (f : add_hom M N) :
add_hom (with_top M) (with_top N) :=
{ to_fun := with_top.map f,
map_add' := with_top.map_add f }
/-- A version of `with_top.map` for `add_monoid_hom`s. -/
@[simps { fully_applied := ff }] protected def _root_.add_monoid_hom.with_top_map
{M N : Type*} [add_zero_class M] [add_zero_class N] (f : M →+ N) :
with_top M →+ with_top N :=
{ to_fun := with_top.map f,
.. f.to_zero_hom.with_top_map, .. f.to_add_hom.with_top_map }
end with_top
namespace with_bot
@[to_additive] instance [has_one α] : has_one (with_bot α) := with_top.has_one
instance [has_add α] : has_add (with_bot α) := with_top.has_add
instance [add_semigroup α] : add_semigroup (with_bot α) := with_top.add_semigroup
instance [add_comm_semigroup α] : add_comm_semigroup (with_bot α) := with_top.add_comm_semigroup
instance [add_zero_class α] : add_zero_class (with_bot α) := with_top.add_zero_class
instance [add_monoid α] : add_monoid (with_bot α) := with_top.add_monoid
instance [add_comm_monoid α] : add_comm_monoid (with_bot α) := with_top.add_comm_monoid
instance [add_monoid_with_one α] : add_monoid_with_one (with_bot α) := with_top.add_monoid_with_one
instance [add_comm_monoid_with_one α] : add_comm_monoid_with_one (with_bot α) :=
with_top.add_comm_monoid_with_one
instance [has_zero α] [has_one α] [has_le α] [zero_le_one_class α] :
zero_le_one_class (with_bot α) :=
⟨some_le_some.2 zero_le_one⟩
-- `by norm_cast` proves this lemma, so I did not tag it with `norm_cast`
@[to_additive]
lemma coe_one [has_one α] : ((1 : α) : with_bot α) = 1 := rfl
-- `by norm_cast` proves this lemma, so I did not tag it with `norm_cast`
@[to_additive]
lemma coe_eq_one [has_one α] {a : α} : (a : with_bot α) = 1 ↔ a = 1 :=
with_top.coe_eq_one
@[norm_cast, to_additive coe_pos]
lemma one_lt_coe [has_one α] [has_lt α] {a : α} : 1 < (a : with_bot α) ↔ 1 < a := coe_lt_coe
@[norm_cast, to_additive coe_lt_zero]
lemma coe_lt_one [has_one α] [has_lt α] {a : α} : (a : with_bot α) < 1 ↔ a < 1 := coe_lt_coe
@[to_additive] protected lemma map_one {β} [has_one α] (f : α → β) :
(1 : with_bot α).map f = (f 1 : with_bot β) := rfl
@[norm_cast] lemma coe_nat [add_monoid_with_one α] (n : ℕ) : ((n : α) : with_bot α) = n := rfl
@[simp] lemma nat_ne_bot [add_monoid_with_one α] (n : ℕ) : (n : with_bot α) ≠ ⊥ := coe_ne_bot
@[simp] lemma bot_ne_nat [add_monoid_with_one α] (n : ℕ) : (⊥ : with_bot α) ≠ n := bot_ne_coe
section has_add
variables [has_add α] {a b c d : with_bot α} {x y : α}
-- `norm_cast` proves those lemmas, because `with_top`/`with_bot` are reducible
lemma coe_add (a b : α) : ((a + b : α) : with_bot α) = a + b := rfl
lemma coe_bit0 : ((bit0 x : α) : with_bot α) = bit0 x := rfl
lemma coe_bit1 [has_one α] {a : α} : ((bit1 a : α) : with_bot α) = bit1 a := rfl
@[simp] lemma bot_add (a : with_bot α) : ⊥ + a = ⊥ := rfl
@[simp] lemma add_bot (a : with_bot α) : a + ⊥ = ⊥ := by cases a; refl
@[simp] lemma add_eq_bot : a + b = ⊥ ↔ a = ⊥ ∨ b = ⊥ := with_top.add_eq_top
lemma add_ne_bot : a + b ≠ ⊥ ↔ a ≠ ⊥ ∧ b ≠ ⊥ := with_top.add_ne_top
lemma bot_lt_add [partial_order α] {a b : with_bot α} : ⊥ < a + b ↔ ⊥ < a ∧ ⊥ < b :=
@with_top.add_lt_top αᵒᵈ _ _ _ _
lemma add_eq_coe : a + b = x ↔ ∃ (a' b' : α), ↑a' = a ∧ ↑b' = b ∧ a' + b' = x := with_top.add_eq_coe
@[simp] lemma add_coe_eq_bot_iff : a + y = ⊥ ↔ a = ⊥ := with_top.add_coe_eq_top_iff
@[simp] lemma coe_add_eq_bot_iff : ↑x + b = ⊥ ↔ b = ⊥ := with_top.coe_add_eq_top_iff
/- There is no `with_bot.map_mul_of_mul_hom`, since `with_bot` does not have a multiplication. -/
@[simp] protected lemma map_add {F} [has_add β] [add_hom_class F α β] (f : F) (a b : with_bot α) :
(a + b).map f = a.map f + b.map f :=
with_top.map_add f a b
/-- A version of `with_bot.map` for `one_hom`s. -/
@[to_additive "A version of `with_bot.map` for `zero_hom`s", simps { fully_applied := ff }]
protected def _root_.one_hom.with_bot_map {M N : Type*} [has_one M] [has_one N] (f : one_hom M N) :
one_hom (with_bot M) (with_bot N) :=
{ to_fun := with_bot.map f,
map_one' := by rw [with_bot.map_one, map_one, coe_one] }
/-- A version of `with_bot.map` for `add_hom`s. -/
@[simps { fully_applied := ff }] protected def _root_.add_hom.with_bot_map
{M N : Type*} [has_add M] [has_add N] (f : add_hom M N) :
add_hom (with_bot M) (with_bot N) :=
{ to_fun := with_bot.map f,
map_add' := with_bot.map_add f }
/-- A version of `with_bot.map` for `add_monoid_hom`s. -/
@[simps { fully_applied := ff }] protected def _root_.add_monoid_hom.with_bot_map
{M N : Type*} [add_zero_class M] [add_zero_class N] (f : M →+ N) :
with_bot M →+ with_bot N :=
{ to_fun := with_bot.map f,
.. f.to_zero_hom.with_bot_map, .. f.to_add_hom.with_bot_map }
variables [preorder α]
instance covariant_class_add_le [covariant_class α α (+) (≤)] :
covariant_class (with_bot α) (with_bot α) (+) (≤) :=
@order_dual.covariant_class_add_le (with_top αᵒᵈ) _ _ _
instance covariant_class_swap_add_le [covariant_class α α (swap (+)) (≤)] :
covariant_class (with_bot α) (with_bot α) (swap (+)) (≤) :=
@order_dual.covariant_class_swap_add_le (with_top αᵒᵈ) _ _ _
instance contravariant_class_add_lt [contravariant_class α α (+) (<)] :
contravariant_class (with_bot α) (with_bot α) (+) (<) :=
@order_dual.contravariant_class_add_lt (with_top αᵒᵈ) _ _ _
instance contravariant_class_swap_add_lt [contravariant_class α α (swap (+)) (<)] :
contravariant_class (with_bot α) (with_bot α) (swap (+)) (<) :=
@order_dual.contravariant_class_swap_add_lt (with_top αᵒᵈ) _ _ _
protected lemma le_of_add_le_add_left [contravariant_class α α (+) (≤)] (ha : a ≠ ⊥)
(h : a + b ≤ a + c) : b ≤ c :=
@with_top.le_of_add_le_add_left αᵒᵈ _ _ _ _ _ _ ha h
protected lemma le_of_add_le_add_right [contravariant_class α α (swap (+)) (≤)] (ha : a ≠ ⊥)
(h : b + a ≤ c + a) : b ≤ c :=
@with_top.le_of_add_le_add_right αᵒᵈ _ _ _ _ _ _ ha h
protected lemma add_lt_add_left [covariant_class α α (+) (<)] (ha : a ≠ ⊥) (h : b < c) :
a + b < a + c :=
@with_top.add_lt_add_left αᵒᵈ _ _ _ _ _ _ ha h
protected lemma add_lt_add_right [covariant_class α α (swap (+)) (<)] (ha : a ≠ ⊥) (h : b < c) :
b + a < c + a :=
@with_top.add_lt_add_right αᵒᵈ _ _ _ _ _ _ ha h
protected lemma add_le_add_iff_left [covariant_class α α (+) (≤)] [contravariant_class α α (+) (≤)]
(ha : a ≠ ⊥) : a + b ≤ a + c ↔ b ≤ c :=
⟨with_bot.le_of_add_le_add_left ha, λ h, add_le_add_left h a⟩
protected lemma add_le_add_iff_right [covariant_class α α (swap (+)) (≤)]
[contravariant_class α α (swap (+)) (≤)] (ha : a ≠ ⊥) : b + a ≤ c + a ↔ b ≤ c :=
⟨with_bot.le_of_add_le_add_right ha, λ h, add_le_add_right h a⟩
protected lemma add_lt_add_iff_left [covariant_class α α (+) (<)] [contravariant_class α α (+) (<)]
(ha : a ≠ ⊥) : a + b < a + c ↔ b < c :=
⟨lt_of_add_lt_add_left, with_bot.add_lt_add_left ha⟩
protected lemma add_lt_add_iff_right [covariant_class α α (swap (+)) (<)]
[contravariant_class α α (swap (+)) (<)] (ha : a ≠ ⊥) : b + a < c + a ↔ b < c :=
⟨lt_of_add_lt_add_right, with_bot.add_lt_add_right ha⟩
protected lemma add_lt_add_of_le_of_lt [covariant_class α α (+) (<)]
[covariant_class α α (swap (+)) (≤)] (hb : b ≠ ⊥) (hab : a ≤ b) (hcd : c < d) : a + c < b + d :=
@with_top.add_lt_add_of_le_of_lt αᵒᵈ _ _ _ _ _ _ _ _ hb hab hcd
protected lemma add_lt_add_of_lt_of_le [covariant_class α α (+) (≤)]
[covariant_class α α (swap (+)) (<)] (hd : d ≠ ⊥) (hab : a < b) (hcd : c ≤ d) : a + c < b + d :=
@with_top.add_lt_add_of_lt_of_le αᵒᵈ _ _ _ _ _ _ _ _ hd hab hcd
end has_add
instance [ordered_add_comm_monoid α] : ordered_add_comm_monoid (with_bot α) :=
{ add_le_add_left := λ a b h c, add_le_add_left h c,
..with_bot.partial_order,
..with_bot.add_comm_monoid }
instance [linear_ordered_add_comm_monoid α] : linear_ordered_add_comm_monoid (with_bot α) :=
{ ..with_bot.linear_order, ..with_bot.ordered_add_comm_monoid }
end with_bot
|
afeb823565f0c37757cbf86d7a6f845c60b793ef | 57c233acf9386e610d99ed20ef139c5f97504ba3 | /src/category_theory/subobject/factor_thru.lean | 8133b5c8a4e1eee1924372ea174b8082ff588195 | [
"Apache-2.0"
] | permissive | robertylewis/mathlib | 3d16e3e6daf5ddde182473e03a1b601d2810952c | 1d13f5b932f5e40a8308e3840f96fc882fae01f0 | refs/heads/master | 1,651,379,945,369 | 1,644,276,960,000 | 1,644,276,960,000 | 98,875,504 | 0 | 0 | Apache-2.0 | 1,644,253,514,000 | 1,501,495,700,000 | Lean | UTF-8 | Lean | false | false | 6,938 | lean | /-
Copyright (c) 2020 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Bhavik Mehta, Scott Morrison
-/
import category_theory.subobject.basic
import category_theory.preadditive
/-!
# Factoring through subobjects
The predicate `h : P.factors f`, for `P : subobject Y` and `f : X ⟶ Y`
asserts the existence of some `P.factor_thru f : X ⟶ (P : C)` making the obvious diagram commute.
-/
universes v₁ v₂ u₁ u₂
noncomputable theory
open category_theory category_theory.category category_theory.limits
variables {C : Type u₁} [category.{v₁} C] {X Y Z : C}
variables {D : Type u₂} [category.{v₂} D]
namespace category_theory
namespace mono_over
/-- When `f : X ⟶ Y` and `P : mono_over Y`,
`P.factors f` expresses that there exists a factorisation of `f` through `P`.
Given `h : P.factors f`, you can recover the morphism as `P.factor_thru f h`.
-/
def factors {X Y : C} (P : mono_over Y) (f : X ⟶ Y) : Prop := ∃ g : X ⟶ (P : C), g ≫ P.arrow = f
lemma factors_congr {X : C} {f g : mono_over X} {Y : C} (h : Y ⟶ X) (e : f ≅ g) :
f.factors h ↔ g.factors h :=
⟨λ ⟨u, hu⟩, ⟨u ≫ (((mono_over.forget _).map e.hom)).left, by simp [hu]⟩,
λ ⟨u, hu⟩, ⟨u ≫ (((mono_over.forget _).map e.inv)).left, by simp [hu]⟩⟩
/-- `P.factor_thru f h` provides a factorisation of `f : X ⟶ Y` through some `P : mono_over Y`,
given the evidence `h : P.factors f` that such a factorisation exists. -/
def factor_thru {X Y : C} (P : mono_over Y) (f : X ⟶ Y) (h : factors P f) : X ⟶ (P : C) :=
classical.some h
end mono_over
namespace subobject
/-- When `f : X ⟶ Y` and `P : subobject Y`,
`P.factors f` expresses that there exists a factorisation of `f` through `P`.
Given `h : P.factors f`, you can recover the morphism as `P.factor_thru f h`.
-/
def factors {X Y : C} (P : subobject Y) (f : X ⟶ Y) : Prop :=
quotient.lift_on' P (λ P, P.factors f)
begin
rintros P Q ⟨h⟩,
apply propext,
split,
{ rintro ⟨i, w⟩,
exact ⟨i ≫ h.hom.left, by erw [category.assoc, over.w h.hom, w]⟩, },
{ rintro ⟨i, w⟩,
exact ⟨i ≫ h.inv.left, by erw [category.assoc, over.w h.inv, w]⟩, },
end
@[simp] lemma mk_factors_iff {X Y Z : C} (f : Y ⟶ X) [mono f] (g : Z ⟶ X) :
(subobject.mk f).factors g ↔ (mono_over.mk' f).factors g :=
iff.rfl
lemma factors_iff {X Y : C} (P : subobject Y) (f : X ⟶ Y) :
P.factors f ↔ (representative.obj P).factors f :=
quot.induction_on P $ λ a, mono_over.factors_congr _ (representative_iso _).symm
lemma factors_self {X : C} (P : subobject X) : P.factors P.arrow :=
(factors_iff _ _).mpr ⟨𝟙 P, (by simp)⟩
lemma factors_comp_arrow {X Y : C} {P : subobject Y} (f : X ⟶ P) : P.factors (f ≫ P.arrow) :=
(factors_iff _ _).mpr ⟨f, rfl⟩
lemma factors_of_factors_right {X Y Z : C} {P : subobject Z} (f : X ⟶ Y) {g : Y ⟶ Z}
(h : P.factors g) : P.factors (f ≫ g) :=
begin
revert P,
refine quotient.ind' _,
intro P,
rintro ⟨g, rfl⟩,
exact ⟨f ≫ g, by simp⟩,
end
lemma factors_zero [has_zero_morphisms C] {X Y : C} {P : subobject Y} :
P.factors (0 : X ⟶ Y) :=
(factors_iff _ _).mpr ⟨0, by simp⟩
lemma factors_of_le {Y Z : C} {P Q : subobject Y} (f : Z ⟶ Y) (h : P ≤ Q) :
P.factors f → Q.factors f :=
by { simp only [factors_iff], exact λ ⟨u, hu⟩, ⟨u ≫ of_le _ _ h, by simp [←hu]⟩ }
/-- `P.factor_thru f h` provides a factorisation of `f : X ⟶ Y` through some `P : subobject Y`,
given the evidence `h : P.factors f` that such a factorisation exists. -/
def factor_thru {X Y : C} (P : subobject Y) (f : X ⟶ Y) (h : factors P f) : X ⟶ P :=
classical.some ((factors_iff _ _).mp h)
@[simp, reassoc] lemma factor_thru_arrow {X Y : C} (P : subobject Y) (f : X ⟶ Y) (h : factors P f) :
P.factor_thru f h ≫ P.arrow = f :=
classical.some_spec ((factors_iff _ _).mp h)
@[simp] lemma factor_thru_self {X : C} (P : subobject X) (h) :
P.factor_thru P.arrow h = 𝟙 P :=
by { ext, simp, }
@[simp] lemma factor_thru_comp_arrow {X Y : C} {P : subobject Y} (f : X ⟶ P) (h) :
P.factor_thru (f ≫ P.arrow) h = f :=
by { ext, simp, }
@[simp] lemma factor_thru_eq_zero [has_zero_morphisms C]
{X Y : C} {P : subobject Y} {f : X ⟶ Y} {h : factors P f} :
P.factor_thru f h = 0 ↔ f = 0 :=
begin
fsplit,
{ intro w,
replace w := w =≫ P.arrow,
simpa using w, },
{ rintro rfl,
ext, simp, },
end
lemma factor_thru_right {X Y Z : C} {P : subobject Z} (f : X ⟶ Y) (g : Y ⟶ Z) (h : P.factors g) :
f ≫ P.factor_thru g h = P.factor_thru (f ≫ g) (factors_of_factors_right f h) :=
begin
apply (cancel_mono P.arrow).mp,
simp,
end
@[simp]
lemma factor_thru_zero
[has_zero_morphisms C] {X Y : C} {P : subobject Y} (h : P.factors (0 : X ⟶ Y)) :
P.factor_thru 0 h = 0 :=
by simp
-- `h` is an explicit argument here so we can use
-- `rw factor_thru_le h`, obtaining a subgoal `P.factors f`.
-- (While the reverse direction looks plausible as a simp lemma, it seems to be unproductive.)
lemma factor_thru_of_le
{Y Z : C} {P Q : subobject Y} {f : Z ⟶ Y} (h : P ≤ Q) (w : P.factors f) :
Q.factor_thru f (factors_of_le f h w) = P.factor_thru f w ≫ of_le P Q h :=
by { ext, simp, }
section preadditive
variables [preadditive C]
lemma factors_add {X Y : C} {P : subobject Y} (f g : X ⟶ Y) (wf : P.factors f) (wg : P.factors g) :
P.factors (f + g) :=
(factors_iff _ _).mpr ⟨P.factor_thru f wf + P.factor_thru g wg, by simp⟩
-- This can't be a `simp` lemma as `wf` and `wg` may not exist.
-- However you can `rw` by it to assert that `f` and `g` factor through `P` separately.
lemma factor_thru_add {X Y : C} {P : subobject Y} (f g : X ⟶ Y)
(w : P.factors (f + g)) (wf : P.factors f) (wg : P.factors g) :
P.factor_thru (f + g) w = P.factor_thru f wf + P.factor_thru g wg :=
by { ext, simp, }
lemma factors_left_of_factors_add {X Y : C} {P : subobject Y} (f g : X ⟶ Y)
(w : P.factors (f + g)) (wg : P.factors g) : P.factors f :=
(factors_iff _ _).mpr ⟨P.factor_thru (f + g) w - P.factor_thru g wg, by simp⟩
@[simp]
lemma factor_thru_add_sub_factor_thru_right {X Y : C} {P : subobject Y} (f g : X ⟶ Y)
(w : P.factors (f + g)) (wg : P.factors g) :
P.factor_thru (f + g) w - P.factor_thru g wg =
P.factor_thru f (factors_left_of_factors_add f g w wg) :=
by { ext, simp, }
lemma factors_right_of_factors_add {X Y : C} {P : subobject Y} (f g : X ⟶ Y)
(w : P.factors (f + g)) (wf : P.factors f) : P.factors g :=
(factors_iff _ _).mpr ⟨P.factor_thru (f + g) w - P.factor_thru f wf, by simp⟩
@[simp]
lemma factor_thru_add_sub_factor_thru_left {X Y : C} {P : subobject Y} (f g : X ⟶ Y)
(w : P.factors (f + g)) (wf : P.factors f) :
P.factor_thru (f + g) w - P.factor_thru f wf =
P.factor_thru g (factors_right_of_factors_add f g w wf) :=
by { ext, simp, }
end preadditive
end subobject
end category_theory
|
6aee668aab30887274c682d50d4da8dcdd5a4f80 | b7f22e51856f4989b970961f794f1c435f9b8f78 | /tests/lean/run/tactic_notation.lean | 25d72169d0cef9ca1dda8477df987cf89ec338bb | [
"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 | 226 | lean | import logic
theorem tst1 (a b c : Prop) : a → b → a ∧ b :=
begin
intros,
apply and.intro,
repeat assumption
end
theorem tst2 (a b c : Prop) : a → b → a ∧ b :=
by intros; apply and.intro; repeat assumption
|
a516fd535bb4fc8d5a5652d8d40487b638adc0c6 | a0e23cfdd129a671bf3154ee1a8a3a72bf4c7940 | /tests/lean/run/simpOnly.lean | c39a6d717640aaf355f450679b73438095de139e | [
"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 | 300 | lean | theorem ex1 (n m : Nat) : 0 + (n, m).1 = n := by
simp only
rw [Nat.zero_add]
theorem ex2 (n m : Nat) : 0 + (n, m).1 = n := by
simp
theorem ex3 (n m : Nat) : 0 + (n, m).1 + 0 = n := by
simp only [Nat.add_zero]
rw [Nat.zero_add]
theorem ex4 (n m : Nat) : 0 + (n, m).1 + 0 = n := by
simp
|
8d0d35b0e175bb1f3b03add0f2253821fe15c0e6 | 957a80ea22c5abb4f4670b250d55534d9db99108 | /library/init/data/int/order.lean | f40879c90e86f63d49678e6929d368ace3fa7527 | [
"Apache-2.0"
] | permissive | GaloisInc/lean | aa1e64d604051e602fcf4610061314b9a37ab8cd | f1ec117a24459b59c6ff9e56a1d09d9e9e60a6c0 | refs/heads/master | 1,592,202,909,807 | 1,504,624,387,000 | 1,504,624,387,000 | 75,319,626 | 2 | 1 | Apache-2.0 | 1,539,290,164,000 | 1,480,616,104,000 | C++ | UTF-8 | Lean | false | false | 11,783 | lean | /-
Copyright (c) 2016 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad
The order relation on the integers.
-/
prelude
import init.data.int.basic
namespace int
private def nonneg (a : ℤ) : Prop := int.cases_on a (assume n, true) (assume n, false)
protected def le (a b : ℤ) : Prop := nonneg (b - a)
instance : has_le int := ⟨int.le⟩
protected def lt (a b : ℤ) : Prop := (a + 1) ≤ b
instance : has_lt int := ⟨int.lt⟩
private def decidable_nonneg (a : ℤ) : decidable (nonneg a) :=
int.cases_on a (assume a, decidable.true) (assume a, decidable.false)
instance decidable_le (a b : ℤ) : decidable (a ≤ b) := decidable_nonneg _
instance decidable_lt (a b : ℤ) : decidable (a < b) := decidable_nonneg _
lemma lt_iff_add_one_le (a b : ℤ) : a < b ↔ a + 1 ≤ b := iff.refl _
private lemma nonneg.elim {a : ℤ} : nonneg a → ∃ n : ℕ, a = n :=
int.cases_on a (assume n H, exists.intro n rfl) (assume n', false.elim)
private lemma nonneg_or_nonneg_neg (a : ℤ) : nonneg a ∨ nonneg (-a) :=
int.cases_on a (assume n, or.inl trivial) (assume n, or.inr trivial)
lemma le.intro_sub {a b : ℤ} {n : ℕ} (h : b - a = n) : a ≤ b :=
show nonneg (b - a), by rw h; trivial
lemma le.intro {a b : ℤ} {n : ℕ} (h : a + n = b) : a ≤ b :=
le.intro_sub (by rw [← h]; simp)
lemma le.dest_sub {a b : ℤ} (h : a ≤ b) : ∃ n : ℕ, b - a = n := nonneg.elim h
lemma le.dest {a b : ℤ} (h : a ≤ b) : ∃ n : ℕ, a + n = b :=
match (le.dest_sub h) with
| ⟨n, h₁⟩ := exists.intro n begin rw [← h₁, add_comm], simp end
end
lemma le.elim {a b : ℤ} (h : a ≤ b) {P : Prop} (h' : ∀ n : ℕ, a + ↑n = b → P) : P :=
exists.elim (le.dest h) h'
protected lemma le_total (a b : ℤ) : a ≤ b ∨ b ≤ a :=
or.imp_right
(assume H : nonneg (-(b - a)),
have -(b - a) = a - b, by simp,
show nonneg (a - b), from this ▸ H)
(nonneg_or_nonneg_neg (b - a))
lemma coe_nat_le_coe_nat_of_le {m n : ℕ} (h : m ≤ n) : (↑m : ℤ) ≤ ↑n :=
match nat.le.dest h with
| ⟨k, (hk : m + k = n)⟩ := le.intro (begin rw [← hk], reflexivity end)
end
lemma le_of_coe_nat_le_coe_nat {m n : ℕ} (h : (↑m : ℤ) ≤ ↑n) : m ≤ n :=
le.elim h (assume k, assume hk : ↑m + ↑k = ↑n,
have m + k = n, from int.coe_nat_inj ((int.coe_nat_add m k).trans hk),
nat.le.intro this)
lemma coe_nat_le_coe_nat_iff (m n : ℕ) : (↑m : ℤ) ≤ ↑n ↔ m ≤ n :=
iff.intro le_of_coe_nat_le_coe_nat coe_nat_le_coe_nat_of_le
lemma coe_zero_le (n : ℕ) : 0 ≤ (↑n : ℤ) :=
coe_nat_le_coe_nat_of_le n.zero_le
lemma eq_coe_of_zero_le {a : ℤ} (h : 0 ≤ a) : ∃ n : ℕ, a = n :=
by have t := le.dest_sub h; simp at t; exact t
lemma eq_succ_of_zero_lt {a : ℤ} (h : 0 < a) : ∃ n : ℕ, a = n.succ :=
let ⟨n, (h : ↑(1+n) = a)⟩ := le.dest h in
⟨n, by rw add_comm at h; exact h.symm⟩
lemma lt_add_succ (a : ℤ) (n : ℕ) : a < a + ↑(nat.succ n) :=
le.intro (show a + 1 + n = a + nat.succ n, begin simp [int.coe_nat_eq], reflexivity end)
lemma lt.intro {a b : ℤ} {n : ℕ} (h : a + nat.succ n = b) : a < b :=
h ▸ lt_add_succ a n
lemma lt.dest {a b : ℤ} (h : a < b) : ∃ n : ℕ, a + ↑(nat.succ n) = b :=
le.elim h (assume n, assume hn : a + 1 + n = b,
exists.intro n begin rw [← hn, add_assoc, add_comm (1 : int)], reflexivity end)
lemma lt.elim {a b : ℤ} (h : a < b) {P : Prop} (h' : ∀ n : ℕ, a + ↑(nat.succ n) = b → P) : P :=
exists.elim (lt.dest h) h'
lemma coe_nat_lt_coe_nat_iff (n m : ℕ) : (↑n : ℤ) < ↑m ↔ n < m :=
begin rw [lt_iff_add_one_le, ← int.coe_nat_succ, coe_nat_le_coe_nat_iff], reflexivity end
lemma lt_of_coe_nat_lt_coe_nat {m n : ℕ} (h : (↑m : ℤ) < ↑n) : m < n :=
(coe_nat_lt_coe_nat_iff _ _).mp h
lemma coe_nat_lt_coe_nat_of_lt {m n : ℕ} (h : m < n) : (↑m : ℤ) < ↑n :=
(coe_nat_lt_coe_nat_iff _ _).mpr h
/- show that the integers form an ordered additive group -/
protected lemma le_refl (a : ℤ) : a ≤ a :=
le.intro (add_zero a)
protected lemma le_trans {a b c : ℤ} (h₁ : a ≤ b) (h₂ : b ≤ c) : a ≤ c :=
le.elim h₁ (assume n, assume hn : a + n = b,
le.elim h₂ (assume m, assume hm : b + m = c,
begin apply le.intro, rw [← hm, ← hn, add_assoc], reflexivity end))
protected lemma le_antisymm {a b : ℤ} (h₁ : a ≤ b) (h₂ : b ≤ a) : a = b :=
le.elim h₁ (assume n, assume hn : a + n = b,
le.elim h₂ (assume m, assume hm : b + m = a,
have a + ↑(n + m) = a + 0, by rw [int.coe_nat_add, ← add_assoc, hn, hm, add_zero a],
have (↑(n + m) : ℤ) = 0, from add_left_cancel this,
have n + m = 0, from int.coe_nat_inj this,
have n = 0, from nat.eq_zero_of_add_eq_zero_right this,
show a = b, begin rw [← hn, this, int.coe_nat_zero, add_zero a] end))
protected lemma lt_irrefl (a : ℤ) : ¬ a < a :=
assume : a < a,
lt.elim this (assume n, assume hn : a + nat.succ n = a,
have a + nat.succ n = a + 0, by rw [hn, add_zero],
have nat.succ n = 0, from int.coe_nat_inj (add_left_cancel this),
show false, from nat.succ_ne_zero _ this)
protected lemma ne_of_lt {a b : ℤ} (h : a < b) : a ≠ b :=
(assume : a = b, absurd (begin rewrite this at h, exact h end) (int.lt_irrefl b))
lemma le_of_lt {a b : ℤ} (h : a < b) : a ≤ b :=
lt.elim h (assume n, assume hn : a + nat.succ n = b, le.intro hn)
protected lemma lt_iff_le_and_ne (a b : ℤ) : a < b ↔ (a ≤ b ∧ a ≠ b) :=
iff.intro
(assume h, ⟨le_of_lt h, int.ne_of_lt h⟩)
(assume ⟨aleb, aneb⟩,
le.elim aleb (assume n, assume hn : a + n = b,
have n ≠ 0,
from (assume : n = 0, aneb begin rw [← hn, this, int.coe_nat_zero, add_zero] end),
have n = nat.succ (nat.pred n),
from eq.symm (nat.succ_pred_eq_of_pos (nat.pos_of_ne_zero this)),
lt.intro (begin rewrite this at hn, exact hn end)))
lemma lt_succ (a : ℤ) : a < a + 1 :=
int.le_refl (a + 1)
protected lemma add_le_add_left {a b : ℤ} (h : a ≤ b) (c : ℤ) : c + a ≤ c + b :=
le.elim h (assume n, assume hn : a + n = b,
le.intro (show c + a + n = c + b, begin rw [add_assoc, hn] end))
protected lemma add_lt_add_left {a b : ℤ} (h : a < b) (c : ℤ) : c + a < c + b :=
iff.mpr (int.lt_iff_le_and_ne _ _)
(and.intro
(int.add_le_add_left (le_of_lt h) _)
(assume heq, int.lt_irrefl b begin rw add_left_cancel heq at h, exact h end))
protected lemma mul_nonneg {a b : ℤ} (ha : 0 ≤ a) (hb : 0 ≤ b) : 0 ≤ a * b :=
le.elim ha (assume n, assume hn,
le.elim hb (assume m, assume hm,
le.intro (show 0 + ↑n * ↑m = a * b, begin rw [← hn, ← hm], repeat {rw zero_add} end)))
protected lemma mul_pos {a b : ℤ} (ha : 0 < a) (hb : 0 < b) : 0 < a * b :=
lt.elim ha (assume n, assume hn,
lt.elim hb (assume m, assume hm,
lt.intro (show 0 + ↑(nat.succ (nat.succ n * m + n)) = a * b,
begin rw [← hn, ← hm], repeat {rw int.coe_nat_zero}, simp,
rw [← int.coe_nat_mul], simp [nat.mul_succ, nat.succ_add] end)))
protected lemma zero_lt_one : (0 : ℤ) < 1 := trivial
protected lemma lt_iff_le_not_le {a b : ℤ} : a < b ↔ (a ≤ b ∧ ¬ b ≤ a) :=
begin
simp [int.lt_iff_le_and_ne], split; intro h; cases h with hneq hab; split,
{assumption}, {intro hba, apply hneq, apply int.le_antisymm; assumption},
{intro heq, apply hab, subst heq, apply int.le_refl}, {assumption}
end
instance : decidable_linear_ordered_comm_ring int :=
{ int.comm_ring with
le := int.le,
le_refl := int.le_refl,
le_trans := @int.le_trans,
le_antisymm := @int.le_antisymm,
lt := int.lt,
lt_iff_le_not_le := @int.lt_iff_le_not_le,
add_le_add_left := @int.add_le_add_left,
add_lt_add_left := @int.add_lt_add_left,
zero_ne_one := zero_ne_one,
mul_nonneg := @int.mul_nonneg,
mul_pos := @int.mul_pos,
le_total := int.le_total,
zero_lt_one := int.zero_lt_one,
decidable_eq := int.decidable_eq,
decidable_le := int.decidable_le,
decidable_lt := int.decidable_lt }
instance : decidable_linear_ordered_comm_group int :=
by apply_instance
lemma eq_nat_abs_of_zero_le {a : ℤ} (h : 0 ≤ a) : a = nat_abs a :=
let ⟨n, e⟩ := eq_coe_of_zero_le h in by rw e; refl
lemma le_nat_abs {a : ℤ} : a ≤ nat_abs a :=
or.elim (le_total 0 a)
(λh, by rw eq_nat_abs_of_zero_le h; refl)
(λh, le_trans h (coe_zero_le _))
lemma neg_succ_lt_zero (n : ℕ) : -[1+ n] < 0 :=
lt_of_not_ge $ λ h, let ⟨m, h⟩ := eq_coe_of_zero_le h in by contradiction
lemma eq_neg_succ_of_lt_zero : ∀ {a : ℤ}, a < 0 → ∃ n : ℕ, a = -[1+ n]
| (n : ℕ) h := absurd h (not_lt_of_ge (coe_zero_le _))
| -[1+ n] h := ⟨n, rfl⟩
/- more facts specific to int -/
theorem of_nat_nonneg (n : ℕ) : 0 ≤ of_nat n := trivial
theorem coe_succ_pos (n : nat) : (nat.succ n : ℤ) > 0 :=
coe_nat_lt_coe_nat_of_lt (nat.succ_pos _)
theorem exists_eq_neg_of_nat {a : ℤ} (H : a ≤ 0) : ∃n : ℕ, a = -n :=
let ⟨n, h⟩ := eq_coe_of_zero_le (neg_nonneg_of_nonpos H) in
⟨n, eq_neg_of_eq_neg h.symm⟩
theorem nat_abs_of_nonneg {a : ℤ} (H : a ≥ 0) : (nat_abs a : ℤ) = a :=
match a, eq_coe_of_zero_le H with ._, ⟨n, rfl⟩ := rfl end
theorem of_nat_nat_abs_of_nonpos {a : ℤ} (H : a ≤ 0) : (nat_abs a : ℤ) = -a :=
by rw [← nat_abs_neg, nat_abs_of_nonneg (neg_nonneg_of_nonpos H)]
theorem abs_eq_nat_abs : ∀ a : ℤ, abs a = nat_abs a
| (n : ℕ) := abs_of_nonneg $ coe_zero_le _
| -[1+ n] := abs_of_nonpos $ le_of_lt $ neg_succ_lt_zero _
theorem nat_abs_abs (a : ℤ) : nat_abs (abs a) = nat_abs a :=
by rw [abs_eq_nat_abs]; refl
theorem lt_of_add_one_le {a b : ℤ} (H : a + 1 ≤ b) : a < b := H
theorem add_one_le_of_lt {a b : ℤ} (H : a < b) : a + 1 ≤ b := H
theorem lt_add_one_of_le {a b : ℤ} (H : a ≤ b) : a < b + 1 :=
add_le_add_right H 1
theorem le_of_lt_add_one {a b : ℤ} (H : a < b + 1) : a ≤ b :=
le_of_add_le_add_right H
theorem sub_one_le_of_lt {a b : ℤ} (H : a ≤ b) : a - 1 < b :=
sub_right_lt_of_lt_add $ lt_add_one_of_le H
theorem lt_of_sub_one_le {a b : ℤ} (H : a - 1 < b) : a ≤ b :=
le_of_lt_add_one $ lt_add_of_sub_right_lt H
theorem le_sub_one_of_lt {a b : ℤ} (H : a < b) : a ≤ b - 1 :=
le_sub_right_of_add_le H
theorem lt_of_le_sub_one {a b : ℤ} (H : a ≤ b - 1) : a < b :=
add_le_of_le_sub_right H
theorem sign_of_succ (n : nat) : sign (nat.succ n) = 1 := rfl
theorem sign_eq_one_of_pos {a : ℤ} (h : 0 < a) : sign a = 1 :=
match a, eq_succ_of_zero_lt h with ._, ⟨n, rfl⟩ := rfl end
theorem sign_eq_neg_one_of_neg {a : ℤ} (h : a < 0) : sign a = -1 :=
match a, eq_neg_succ_of_lt_zero h with ._, ⟨n, rfl⟩ := rfl end
lemma eq_zero_of_sign_eq_zero : Π {a : ℤ}, sign a = 0 → a = 0
| 0 _ := rfl
theorem pos_of_sign_eq_one : ∀ {a : ℤ}, sign a = 1 → 0 < a
| (n+1:ℕ) _ := coe_nat_lt_coe_nat_of_lt (nat.succ_pos _)
theorem neg_of_sign_eq_neg_one : ∀ {a : ℤ}, sign a = -1 → a < 0
| (n+1:ℕ) h := match h with end
| 0 h := match h with end
| -[1+ n] _ := neg_succ_lt_zero _
theorem sign_eq_one_iff_pos (a : ℤ) : sign a = 1 ↔ 0 < a :=
⟨pos_of_sign_eq_one, sign_eq_one_of_pos⟩
theorem sign_eq_neg_one_iff_neg (a : ℤ) : sign a = -1 ↔ a < 0 :=
⟨neg_of_sign_eq_neg_one, sign_eq_neg_one_of_neg⟩
theorem sign_eq_zero_iff_zero (a : ℤ) : sign a = 0 ↔ a = 0 :=
⟨eq_zero_of_sign_eq_zero, λ h, by rw [h, sign_zero]⟩
theorem sign_mul_abs (a : ℤ) : sign a * abs a = a :=
by rw [abs_eq_nat_abs, sign_mul_nat_abs]
theorem eq_one_of_mul_eq_self_left {a b : ℤ} (Hpos : a ≠ 0) (H : b * a = a) : b = 1 :=
eq_of_mul_eq_mul_right Hpos (by rw [one_mul, H])
theorem eq_one_of_mul_eq_self_right {a b : ℤ} (Hpos : b ≠ 0) (H : b * a = b) : a = 1 :=
eq_of_mul_eq_mul_left Hpos (by rw [mul_one, H])
end int
|
88d4e20abc2f3634388030dcbf74906742565974 | bbecf0f1968d1fba4124103e4f6b55251d08e9c4 | /src/topology/constructions.lean | 142added5ca0245ac84d5edc2a0daefe75607213 | [
"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 | 45,916 | lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro, Patrick Massot
-/
import topology.maps
/-!
# Constructions of new topological spaces from old ones
This file constructs products, sums, subtypes and quotients of topological spaces
and sets up their basic theory, such as criteria for maps into or out of these
constructions to be continuous; descriptions of the open sets, neighborhood filters,
and generators of these constructions; and their behavior with respect to embeddings
and other specific classes of maps.
## Implementation note
The constructed topologies are defined using induced and coinduced topologies
along with the complete lattice structure on topologies. Their universal properties
(for example, a map `X → Y × Z` is continuous if and only if both projections
`X → Y`, `X → Z` are) follow easily using order-theoretic descriptions of
continuity. With more work we can also extract descriptions of the open sets,
neighborhood filters and so on.
## Tags
product, sum, disjoint union, subspace, quotient space
-/
noncomputable theory
open topological_space set filter
open_locale classical topological_space filter
universes u v w x
variables {α : Type u} {β : Type v} {γ : Type w} {δ : Type x}
section constructions
instance {p : α → Prop} [t : topological_space α] : topological_space (subtype p) :=
induced coe t
instance {r : α → α → Prop} [t : topological_space α] : topological_space (quot r) :=
coinduced (quot.mk r) t
instance {s : setoid α} [t : topological_space α] : topological_space (quotient s) :=
coinduced quotient.mk t
instance [t₁ : topological_space α] [t₂ : topological_space β] : topological_space (α × β) :=
induced prod.fst t₁ ⊓ induced prod.snd t₂
instance [t₁ : topological_space α] [t₂ : topological_space β] : topological_space (α ⊕ β) :=
coinduced sum.inl t₁ ⊔ coinduced sum.inr t₂
instance {β : α → Type v} [t₂ : Πa, topological_space (β a)] : topological_space (sigma β) :=
⨆a, coinduced (sigma.mk a) (t₂ a)
instance Pi.topological_space {β : α → Type v} [t₂ : Πa, topological_space (β a)] :
topological_space (Πa, β a) :=
⨅a, induced (λf, f a) (t₂ a)
instance ulift.topological_space [t : topological_space α] : topological_space (ulift.{v u} α) :=
t.induced ulift.down
lemma quotient.preimage_mem_nhds [topological_space α] [s : setoid α]
{V : set $ quotient s} {a : α} (hs : V ∈ 𝓝 (quotient.mk a)) : quotient.mk ⁻¹' V ∈ 𝓝 a :=
preimage_nhds_coinduced hs
/-- The image of a dense set under `quotient.mk` is a dense set. -/
lemma dense.quotient [setoid α] [topological_space α] {s : set α} (H : dense s) :
dense (quotient.mk '' s) :=
(surjective_quotient_mk α).dense_range.dense_image continuous_coinduced_rng H
/-- The composition of `quotient.mk` and a function with dense range has dense range. -/
lemma dense_range.quotient [setoid α] [topological_space α] {f : β → α} (hf : dense_range f) :
dense_range (quotient.mk ∘ f) :=
(surjective_quotient_mk α).dense_range.comp hf continuous_coinduced_rng
instance {p : α → Prop} [topological_space α] [discrete_topology α] :
discrete_topology (subtype p) :=
⟨bot_unique $ assume s hs,
⟨coe '' s, is_open_discrete _, (set.preimage_image_eq _ subtype.coe_injective)⟩⟩
instance sum.discrete_topology [topological_space α] [topological_space β]
[hα : discrete_topology α] [hβ : discrete_topology β] : discrete_topology (α ⊕ β) :=
⟨by unfold sum.topological_space; simp [hα.eq_bot, hβ.eq_bot]⟩
instance sigma.discrete_topology {β : α → Type v} [Πa, topological_space (β a)]
[h : Πa, discrete_topology (β a)] : discrete_topology (sigma β) :=
⟨by { unfold sigma.topological_space, simp [λ a, (h a).eq_bot] }⟩
section topα
variable [topological_space α]
/-
The 𝓝 filter and the subspace topology.
-/
theorem mem_nhds_subtype (s : set α) (a : {x // x ∈ s}) (t : set {x // x ∈ s}) :
t ∈ 𝓝 a ↔ ∃ u ∈ 𝓝 (a : α), coe ⁻¹' u ⊆ t :=
mem_nhds_induced coe a t
theorem nhds_subtype (s : set α) (a : {x // x ∈ s}) :
𝓝 a = comap coe (𝓝 (a : α)) :=
nhds_induced coe a
end topα
end constructions
section prod
variables [topological_space α] [topological_space β] [topological_space γ] [topological_space δ]
@[continuity] lemma continuous_fst : continuous (@prod.fst α β) :=
continuous_inf_dom_left continuous_induced_dom
lemma continuous_at_fst {p : α × β} : continuous_at prod.fst p :=
continuous_fst.continuous_at
@[continuity] lemma continuous_snd : continuous (@prod.snd α β) :=
continuous_inf_dom_right continuous_induced_dom
lemma continuous_at_snd {p : α × β} : continuous_at prod.snd p :=
continuous_snd.continuous_at
@[continuity] lemma continuous.prod_mk {f : γ → α} {g : γ → β}
(hf : continuous f) (hg : continuous g) : continuous (λx, (f x, g x)) :=
continuous_inf_rng (continuous_induced_rng hf) (continuous_induced_rng hg)
@[continuity] lemma continuous.prod.mk (a : α) : continuous (prod.mk a : β → α × β) :=
continuous_const.prod_mk continuous_id'
lemma continuous.prod_map {f : γ → α} {g : δ → β} (hf : continuous f) (hg : continuous g) :
continuous (λ x : γ × δ, (f x.1, g x.2)) :=
(hf.comp continuous_fst).prod_mk (hg.comp continuous_snd)
lemma filter.eventually.prod_inl_nhds {p : α → Prop} {a : α} (h : ∀ᶠ x in 𝓝 a, p x) (b : β) :
∀ᶠ x in 𝓝 (a, b), p (x : α × β).1 :=
continuous_at_fst h
lemma filter.eventually.prod_inr_nhds {p : β → Prop} {b : β} (h : ∀ᶠ x in 𝓝 b, p x) (a : α) :
∀ᶠ x in 𝓝 (a, b), p (x : α × β).2 :=
continuous_at_snd h
lemma filter.eventually.prod_mk_nhds {pa : α → Prop} {a} (ha : ∀ᶠ x in 𝓝 a, pa x)
{pb : β → Prop} {b} (hb : ∀ᶠ y in 𝓝 b, pb y) :
∀ᶠ p in 𝓝 (a, b), pa (p : α × β).1 ∧ pb p.2 :=
(ha.prod_inl_nhds b).and (hb.prod_inr_nhds a)
lemma continuous_swap : continuous (prod.swap : α × β → β × α) :=
continuous.prod_mk continuous_snd continuous_fst
lemma continuous_uncurry_left {f : α → β → γ} (a : α)
(h : continuous (function.uncurry f)) : continuous (f a) :=
show continuous (function.uncurry f ∘ (λ b, (a, b))), from h.comp (by continuity)
lemma continuous_uncurry_right {f : α → β → γ} (b : β)
(h : continuous (function.uncurry f)) : continuous (λ a, f a b) :=
show continuous (function.uncurry f ∘ (λ a, (a, b))), from h.comp (by continuity)
lemma continuous_curry {g : α × β → γ} (a : α)
(h : continuous g) : continuous (function.curry g a) :=
show continuous (g ∘ (λ b, (a, b))), from h.comp (by continuity)
lemma is_open.prod {s : set α} {t : set β} (hs : is_open s) (ht : is_open t) :
is_open (set.prod s t) :=
is_open.inter (hs.preimage continuous_fst) (ht.preimage continuous_snd)
lemma nhds_prod_eq {a : α} {b : β} : 𝓝 (a, b) = 𝓝 a ×ᶠ 𝓝 b :=
by rw [filter.prod, prod.topological_space, nhds_inf, nhds_induced, nhds_induced]
lemma mem_nhds_prod_iff {a : α} {b : β} {s : set (α × β)} :
s ∈ 𝓝 (a, b) ↔ ∃ (u ∈ 𝓝 a) (v ∈ 𝓝 b), set.prod u v ⊆ s :=
by rw [nhds_prod_eq, mem_prod_iff]
lemma mem_nhds_prod_iff' {a : α} {b : β} {s : set (α × β)} :
s ∈ 𝓝 (a, b) ↔ ∃ u v, is_open u ∧ a ∈ u ∧ is_open v ∧ b ∈ v ∧ set.prod u v ⊆ s :=
begin
rw mem_nhds_prod_iff,
split,
{ rintros ⟨u, Hu, v, Hv, h⟩,
rcases mem_nhds_iff.1 Hu with ⟨u', u'u, u'_open, Hu'⟩,
rcases mem_nhds_iff.1 Hv with ⟨v', v'v, v'_open, Hv'⟩,
exact ⟨u', v', u'_open, Hu', v'_open, Hv', (set.prod_mono u'u v'v).trans h⟩ },
{ rintros ⟨u, v, u_open, au, v_open, bv, huv⟩,
exact ⟨u, u_open.mem_nhds au, v, v_open.mem_nhds bv, huv⟩ }
end
lemma filter.has_basis.prod_nhds {ιa ιb : Type*} {pa : ιa → Prop} {pb : ιb → Prop}
{sa : ιa → set α} {sb : ιb → set β} {a : α} {b : β} (ha : (𝓝 a).has_basis pa sa)
(hb : (𝓝 b).has_basis pb sb) :
(𝓝 (a, b)).has_basis (λ i : ιa × ιb, pa i.1 ∧ pb i.2) (λ i, (sa i.1).prod (sb i.2)) :=
by { rw nhds_prod_eq, exact ha.prod hb }
lemma filter.has_basis.prod_nhds' {ιa ιb : Type*} {pa : ιa → Prop} {pb : ιb → Prop}
{sa : ιa → set α} {sb : ιb → set β} {ab : α × β} (ha : (𝓝 ab.1).has_basis pa sa)
(hb : (𝓝 ab.2).has_basis pb sb) :
(𝓝 ab).has_basis (λ i : ιa × ιb, pa i.1 ∧ pb i.2) (λ i, (sa i.1).prod (sb i.2)) :=
by { cases ab, exact ha.prod_nhds hb }
instance [discrete_topology α] [discrete_topology β] : discrete_topology (α × β) :=
⟨eq_of_nhds_eq_nhds $ assume ⟨a, b⟩,
by rw [nhds_prod_eq, nhds_discrete α, nhds_discrete β, nhds_bot, filter.prod_pure_pure]⟩
lemma prod_mem_nhds_iff {s : set α} {t : set β} {a : α} {b : β} :
s.prod t ∈ 𝓝 (a, b) ↔ s ∈ 𝓝 a ∧ t ∈ 𝓝 b :=
by rw [nhds_prod_eq, prod_mem_prod_iff]
lemma prod_is_open.mem_nhds {s : set α} {t : set β} {a : α} {b : β}
(ha : s ∈ 𝓝 a) (hb : t ∈ 𝓝 b) : set.prod s t ∈ 𝓝 (a, b) :=
prod_mem_nhds_iff.2 ⟨ha, hb⟩
lemma nhds_swap (a : α) (b : β) : 𝓝 (a, b) = (𝓝 (b, a)).map prod.swap :=
by rw [nhds_prod_eq, filter.prod_comm, nhds_prod_eq]; refl
lemma filter.tendsto.prod_mk_nhds {γ} {a : α} {b : β} {f : filter γ} {ma : γ → α} {mb : γ → β}
(ha : tendsto ma f (𝓝 a)) (hb : tendsto mb f (𝓝 b)) :
tendsto (λc, (ma c, mb c)) f (𝓝 (a, b)) :=
by rw [nhds_prod_eq]; exact filter.tendsto.prod_mk ha hb
lemma filter.eventually.curry_nhds {p : α × β → Prop} {x : α} {y : β} (h : ∀ᶠ x in 𝓝 (x, y), p x) :
∀ᶠ x' in 𝓝 x, ∀ᶠ y' in 𝓝 y, p (x', y') :=
by { rw [nhds_prod_eq] at h, exact h.curry }
lemma continuous_at.prod {f : α → β} {g : α → γ} {x : α}
(hf : continuous_at f x) (hg : continuous_at g x) : continuous_at (λx, (f x, g x)) x :=
hf.prod_mk_nhds hg
lemma continuous_at.prod_map {f : α → γ} {g : β → δ} {p : α × β}
(hf : continuous_at f p.fst) (hg : continuous_at g p.snd) :
continuous_at (λ p : α × β, (f p.1, g p.2)) p :=
(hf.comp continuous_at_fst).prod (hg.comp continuous_at_snd)
lemma continuous_at.prod_map' {f : α → γ} {g : β → δ} {x : α} {y : β}
(hf : continuous_at f x) (hg : continuous_at g y) :
continuous_at (λ p : α × β, (f p.1, g p.2)) (x, y) :=
have hf : continuous_at f (x, y).fst, from hf,
have hg : continuous_at g (x, y).snd, from hg,
hf.prod_map hg
lemma prod_generate_from_generate_from_eq {α β : Type*} {s : set (set α)} {t : set (set β)}
(hs : ⋃₀ s = univ) (ht : ⋃₀ t = univ) :
@prod.topological_space α β (generate_from s) (generate_from t) =
generate_from {g | ∃u∈s, ∃v∈t, g = set.prod u v} :=
let G := generate_from {g | ∃u∈s, ∃v∈t, g = set.prod u v} in
le_antisymm
(le_generate_from $ assume g ⟨u, hu, v, hv, g_eq⟩, g_eq.symm ▸
@is_open.prod _ _ (generate_from s) (generate_from t) _ _
(generate_open.basic _ hu) (generate_open.basic _ hv))
(le_inf
(coinduced_le_iff_le_induced.mp $ le_generate_from $ assume u hu,
have (⋃v∈t, set.prod u v) = prod.fst ⁻¹' u,
from calc (⋃v∈t, set.prod u v) = set.prod u univ :
set.ext $ assume ⟨a, b⟩, by rw ← ht; simp [and.left_comm] {contextual:=tt}
... = prod.fst ⁻¹' u : by simp [set.prod, preimage],
show G.is_open (prod.fst ⁻¹' u),
from this ▸ @is_open_Union _ _ G _ $ assume v, @is_open_Union _ _ G _ $ assume hv,
generate_open.basic _ ⟨_, hu, _, hv, rfl⟩)
(coinduced_le_iff_le_induced.mp $ le_generate_from $ assume v hv,
have (⋃u∈s, set.prod u v) = prod.snd ⁻¹' v,
from calc (⋃u∈s, set.prod u v) = set.prod univ v:
set.ext $ assume ⟨a, b⟩, by rw [←hs]; by_cases b ∈ v; simp [h] {contextual:=tt}
... = prod.snd ⁻¹' v : by simp [set.prod, preimage],
show G.is_open (prod.snd ⁻¹' v),
from this ▸ @is_open_Union _ _ G _ $ assume u, @is_open_Union _ _ G _ $ assume hu,
generate_open.basic _ ⟨_, hu, _, hv, rfl⟩))
lemma prod_eq_generate_from :
prod.topological_space =
generate_from {g | ∃(s:set α) (t:set β), is_open s ∧ is_open t ∧ g = set.prod s t} :=
le_antisymm
(le_generate_from $ assume g ⟨s, t, hs, ht, g_eq⟩, g_eq.symm ▸ hs.prod ht)
(le_inf
(ball_image_of_ball $ λt ht, generate_open.basic _ ⟨t, univ, by simpa [set.prod_eq] using ht⟩)
(ball_image_of_ball $ λt ht, generate_open.basic _ ⟨univ, t, by simpa [set.prod_eq] using ht⟩))
lemma is_open_prod_iff {s : set (α×β)} : is_open s ↔
(∀a b, (a, b) ∈ s → ∃u v, is_open u ∧ is_open v ∧ a ∈ u ∧ b ∈ v ∧ set.prod u v ⊆ s) :=
begin
rw [is_open_iff_nhds],
simp_rw [le_principal_iff, prod.forall,
((nhds_basis_opens _).prod_nhds (nhds_basis_opens _)).mem_iff, prod.exists, exists_prop],
simp only [and_assoc, and.left_comm]
end
/-- A product of induced topologies is induced by the product map -/
lemma prod_induced_induced {α γ : Type*} (f : α → β) (g : γ → δ) :
@prod.topological_space α γ (induced f ‹_›) (induced g ‹_›) =
induced (λ p, (f p.1, g p.2)) prod.topological_space :=
begin
set fxg := (λ p : α × γ, (f p.1, g p.2)),
have key1 : f ∘ (prod.fst : α × γ → α) = (prod.fst : β × δ → β) ∘ fxg, from rfl,
have key2 : g ∘ (prod.snd : α × γ → γ) = (prod.snd : β × δ → δ) ∘ fxg, from rfl,
unfold prod.topological_space,
conv_lhs {
rw [induced_compose, induced_compose, key1, key2],
congr, rw ← induced_compose, skip, rw ← induced_compose, },
rw induced_inf
end
lemma continuous_uncurry_of_discrete_topology_left [discrete_topology α]
{f : α → β → γ} (h : ∀ a, continuous (f a)) : continuous (function.uncurry f) :=
continuous_iff_continuous_at.2 $ λ ⟨a, b⟩,
by simp only [continuous_at, nhds_prod_eq, nhds_discrete α, pure_prod, tendsto_map'_iff, (∘),
function.uncurry, (h a).tendsto]
/-- Given a neighborhood `s` of `(x, x)`, then `(x, x)` has a square open neighborhood
that is a subset of `s`. -/
lemma exists_nhds_square {s : set (α × α)} {x : α} (hx : s ∈ 𝓝 (x, x)) :
∃U, is_open U ∧ x ∈ U ∧ set.prod U U ⊆ s :=
by simpa [nhds_prod_eq, (nhds_basis_opens x).prod_self.mem_iff, and.assoc, and.left_comm] using hx
/-- `prod.fst` maps neighborhood of `x : α × β` within the section `prod.snd ⁻¹' {x.2}`
to `𝓝 x.1`. -/
lemma map_fst_nhds_within (x : α × β) : map prod.fst (𝓝[prod.snd ⁻¹' {x.2}] x) = 𝓝 x.1 :=
begin
refine le_antisymm (continuous_at_fst.mono_left inf_le_left) (λ s hs, _),
rcases x with ⟨x, y⟩,
rw [mem_map, nhds_within, mem_inf_principal, mem_nhds_prod_iff] at hs,
rcases hs with ⟨u, hu, v, hv, H⟩,
simp only [prod_subset_iff, mem_singleton_iff, mem_set_of_eq, mem_preimage] at H,
exact mem_of_superset hu (λ z hz, H _ hz _ (mem_of_mem_nhds hv) rfl)
end
@[simp] lemma map_fst_nhds (x : α × β) : map prod.fst (𝓝 x) = 𝓝 x.1 :=
le_antisymm continuous_at_fst $ (map_fst_nhds_within x).symm.trans_le (map_mono inf_le_left)
/-- The first projection in a product of topological spaces sends open sets to open sets. -/
lemma is_open_map_fst : is_open_map (@prod.fst α β) :=
is_open_map_iff_nhds_le.2 $ λ x, (map_fst_nhds x).ge
/-- `prod.snd` maps neighborhood of `x : α × β` within the section `prod.fst ⁻¹' {x.1}`
to `𝓝 x.2`. -/
lemma map_snd_nhds_within (x : α × β) : map prod.snd (𝓝[prod.fst ⁻¹' {x.1}] x) = 𝓝 x.2 :=
begin
refine le_antisymm (continuous_at_snd.mono_left inf_le_left) (λ s hs, _),
rcases x with ⟨x, y⟩,
rw [mem_map, nhds_within, mem_inf_principal, mem_nhds_prod_iff] at hs,
rcases hs with ⟨u, hu, v, hv, H⟩,
simp only [prod_subset_iff, mem_singleton_iff, mem_set_of_eq, mem_preimage] at H,
exact mem_of_superset hv (λ z hz, H _ (mem_of_mem_nhds hu) _ hz rfl)
end
@[simp] lemma map_snd_nhds (x : α × β) : map prod.snd (𝓝 x) = 𝓝 x.2 :=
le_antisymm continuous_at_snd $ (map_snd_nhds_within x).symm.trans_le (map_mono inf_le_left)
/-- The second projection in a product of topological spaces sends open sets to open sets. -/
lemma is_open_map_snd : is_open_map (@prod.snd α β) :=
is_open_map_iff_nhds_le.2 $ λ x, (map_snd_nhds x).ge
/-- A product set is open in a product space if and only if each factor is open, or one of them is
empty -/
lemma is_open_prod_iff' {s : set α} {t : set β} :
is_open (set.prod s t) ↔ (is_open s ∧ is_open t) ∨ (s = ∅) ∨ (t = ∅) :=
begin
cases (set.prod s t).eq_empty_or_nonempty with h h,
{ simp [h, prod_eq_empty_iff.1 h] },
{ have st : s.nonempty ∧ t.nonempty, from prod_nonempty_iff.1 h,
split,
{ assume H : is_open (set.prod s t),
refine or.inl ⟨_, _⟩,
show is_open s,
{ rw ← fst_image_prod s st.2,
exact is_open_map_fst _ H },
show is_open t,
{ rw ← snd_image_prod st.1 t,
exact is_open_map_snd _ H } },
{ assume H,
simp only [st.1.ne_empty, st.2.ne_empty, not_false_iff, or_false] at H,
exact H.1.prod H.2 } }
end
lemma closure_prod_eq {s : set α} {t : set β} :
closure (set.prod s t) = set.prod (closure s) (closure t) :=
set.ext $ assume ⟨a, b⟩,
have (𝓝 a ×ᶠ 𝓝 b) ⊓ 𝓟 (set.prod s t) = (𝓝 a ⊓ 𝓟 s) ×ᶠ (𝓝 b ⊓ 𝓟 t),
by rw [←prod_inf_prod, prod_principal_principal],
by simp [closure_eq_cluster_pts, cluster_pt, nhds_prod_eq, this]; exact prod_ne_bot
lemma interior_prod_eq (s : set α) (t : set β) :
interior (s.prod t) = (interior s).prod (interior t) :=
set.ext $ λ ⟨a, b⟩, by simp only [mem_interior_iff_mem_nhds, mem_prod, prod_mem_nhds_iff]
lemma frontier_prod_eq (s : set α) (t : set β) :
frontier (s.prod t) = (closure s).prod (frontier t) ∪ (frontier s).prod (closure t) :=
by simp only [frontier, closure_prod_eq, interior_prod_eq, prod_diff_prod]
@[simp] lemma frontier_prod_univ_eq (s : set α) :
frontier (s.prod (univ : set β)) = (frontier s).prod univ :=
by simp [frontier_prod_eq]
@[simp] lemma frontier_univ_prod_eq (s : set β) :
frontier ((univ : set α).prod s) = (univ : set α).prod (frontier s) :=
by simp [frontier_prod_eq]
lemma map_mem_closure2 {s : set α} {t : set β} {u : set γ} {f : α → β → γ} {a : α} {b : β}
(hf : continuous (λp:α×β, f p.1 p.2)) (ha : a ∈ closure s) (hb : b ∈ closure t)
(hu : ∀a b, a ∈ s → b ∈ t → f a b ∈ u) :
f a b ∈ closure u :=
have (a, b) ∈ closure (set.prod s t), by rw [closure_prod_eq]; from ⟨ha, hb⟩,
show (λp:α×β, f p.1 p.2) (a, b) ∈ closure u, from
map_mem_closure hf this $ assume ⟨a, b⟩ ⟨ha, hb⟩, hu a b ha hb
lemma is_closed.prod {s₁ : set α} {s₂ : set β} (h₁ : is_closed s₁) (h₂ : is_closed s₂) :
is_closed (set.prod s₁ s₂) :=
closure_eq_iff_is_closed.mp $ by simp only [h₁.closure_eq, h₂.closure_eq, closure_prod_eq]
/-- The product of two dense sets is a dense set. -/
lemma dense.prod {s : set α} {t : set β} (hs : dense s) (ht : dense t) :
dense (s.prod t) :=
λ x, by { rw closure_prod_eq, exact ⟨hs x.1, ht x.2⟩ }
/-- If `f` and `g` are maps with dense range, then `prod.map f g` has dense range. -/
lemma dense_range.prod_map {ι : Type*} {κ : Type*} {f : ι → β} {g : κ → γ}
(hf : dense_range f) (hg : dense_range g) : dense_range (prod.map f g) :=
by simpa only [dense_range, prod_range_range_eq] using hf.prod hg
lemma inducing.prod_mk {f : α → β} {g : γ → δ} (hf : inducing f) (hg : inducing g) :
inducing (λx:α×γ, (f x.1, g x.2)) :=
⟨by rw [prod.topological_space, prod.topological_space, hf.induced, hg.induced,
induced_compose, induced_compose, induced_inf, induced_compose, induced_compose]⟩
lemma embedding.prod_mk {f : α → β} {g : γ → δ} (hf : embedding f) (hg : embedding g) :
embedding (λx:α×γ, (f x.1, g x.2)) :=
{ inj := assume ⟨x₁, x₂⟩ ⟨y₁, y₂⟩, by simp; exact assume h₁ h₂, ⟨hf.inj h₁, hg.inj h₂⟩,
..hf.to_inducing.prod_mk hg.to_inducing }
protected lemma is_open_map.prod {f : α → β} {g : γ → δ} (hf : is_open_map f) (hg : is_open_map g) :
is_open_map (λ p : α × γ, (f p.1, g p.2)) :=
begin
rw [is_open_map_iff_nhds_le],
rintros ⟨a, b⟩,
rw [nhds_prod_eq, nhds_prod_eq, ← filter.prod_map_map_eq],
exact filter.prod_mono (is_open_map_iff_nhds_le.1 hf a) (is_open_map_iff_nhds_le.1 hg b)
end
protected lemma open_embedding.prod {f : α → β} {g : γ → δ}
(hf : open_embedding f) (hg : open_embedding g) : open_embedding (λx:α×γ, (f x.1, g x.2)) :=
open_embedding_of_embedding_open (hf.1.prod_mk hg.1)
(hf.is_open_map.prod hg.is_open_map)
lemma embedding_graph {f : α → β} (hf : continuous f) : embedding (λx, (x, f x)) :=
embedding_of_embedding_compose (continuous_id.prod_mk hf) continuous_fst embedding_id
end prod
section sum
open sum
variables [topological_space α] [topological_space β] [topological_space γ]
@[continuity] lemma continuous_inl : continuous (@inl α β) :=
continuous_sup_rng_left continuous_coinduced_rng
@[continuity] lemma continuous_inr : continuous (@inr α β) :=
continuous_sup_rng_right continuous_coinduced_rng
@[continuity] lemma continuous_sum_rec {f : α → γ} {g : β → γ}
(hf : continuous f) (hg : continuous g) : @continuous (α ⊕ β) γ _ _ (@sum.rec α β (λ_, γ) f g) :=
begin
apply continuous_sup_dom;
rw continuous_def at hf hg ⊢;
assumption
end
lemma is_open_sum_iff {s : set (α ⊕ β)} :
is_open s ↔ is_open (inl ⁻¹' s) ∧ is_open (inr ⁻¹' s) :=
iff.rfl
lemma is_open_map_sum {f : α ⊕ β → γ}
(h₁ : is_open_map (λ a, f (inl a))) (h₂ : is_open_map (λ b, f (inr b))) :
is_open_map f :=
begin
intros u hu,
rw is_open_sum_iff at hu,
cases hu with hu₁ hu₂,
have : u = inl '' (inl ⁻¹' u) ∪ inr '' (inr ⁻¹' u),
{ ext (_|_); simp },
rw [this, set.image_union, set.image_image, set.image_image],
exact is_open.union (h₁ _ hu₁) (h₂ _ hu₂)
end
lemma embedding_inl : embedding (@inl α β) :=
{ induced := begin
unfold sum.topological_space,
apply le_antisymm,
{ rw ← coinduced_le_iff_le_induced, exact le_sup_left },
{ intros u hu, existsi (inl '' u),
change
(is_open (inl ⁻¹' (@inl α β '' u)) ∧
is_open (inr ⁻¹' (@inl α β '' u))) ∧
inl ⁻¹' (inl '' u) = u,
have : inl ⁻¹' (@inl α β '' u) = u :=
preimage_image_eq u (λ _ _, inl.inj_iff.mp), rw this,
have : inr ⁻¹' (@inl α β '' u) = ∅ :=
eq_empty_iff_forall_not_mem.mpr (assume a ⟨b, _, h⟩, inl_ne_inr h), rw this,
exact ⟨⟨hu, is_open_empty⟩, rfl⟩ }
end,
inj := λ _ _, inl.inj_iff.mp }
lemma embedding_inr : embedding (@inr α β) :=
{ induced := begin
unfold sum.topological_space,
apply le_antisymm,
{ rw ← coinduced_le_iff_le_induced, exact le_sup_right },
{ intros u hu, existsi (inr '' u),
change
(is_open (inl ⁻¹' (@inr α β '' u)) ∧
is_open (inr ⁻¹' (@inr α β '' u))) ∧
inr ⁻¹' (inr '' u) = u,
have : inl ⁻¹' (@inr α β '' u) = ∅ :=
eq_empty_iff_forall_not_mem.mpr (assume b ⟨a, _, h⟩, inr_ne_inl h), rw this,
have : inr ⁻¹' (@inr α β '' u) = u :=
preimage_image_eq u (λ _ _, inr.inj_iff.mp), rw this,
exact ⟨⟨is_open_empty, hu⟩, rfl⟩ }
end,
inj := λ _ _, inr.inj_iff.mp }
lemma is_open_range_inl : is_open (range (inl : α → α ⊕ β)) :=
is_open_sum_iff.2 $ by simp
lemma is_open_range_inr : is_open (range (inr : β → α ⊕ β)) :=
is_open_sum_iff.2 $ by simp
lemma open_embedding_inl : open_embedding (inl : α → α ⊕ β) :=
{ open_range := is_open_range_inl,
.. embedding_inl }
lemma open_embedding_inr : open_embedding (inr : β → α ⊕ β) :=
{ open_range := is_open_range_inr,
.. embedding_inr }
end sum
section subtype
variables [topological_space α] [topological_space β] [topological_space γ] {p : α → Prop}
lemma embedding_subtype_coe : embedding (coe : subtype p → α) :=
⟨⟨rfl⟩, subtype.coe_injective⟩
lemma closed_embedding_subtype_coe (h : is_closed {a | p a}) :
closed_embedding (coe : subtype p → α) :=
⟨embedding_subtype_coe, by rwa [subtype.range_coe_subtype]⟩
@[continuity] lemma continuous_subtype_val : continuous (@subtype.val α p) :=
continuous_induced_dom
lemma continuous_subtype_coe : continuous (coe : subtype p → α) :=
continuous_subtype_val
lemma is_open.open_embedding_subtype_coe {s : set α} (hs : is_open s) :
open_embedding (coe : s → α) :=
{ induced := rfl,
inj := subtype.coe_injective,
open_range := (subtype.range_coe : range coe = s).symm ▸ hs }
lemma is_open.is_open_map_subtype_coe {s : set α} (hs : is_open s) :
is_open_map (coe : s → α) :=
hs.open_embedding_subtype_coe.is_open_map
lemma is_open_map.restrict {f : α → β} (hf : is_open_map f) {s : set α} (hs : is_open s) :
is_open_map (s.restrict f) :=
hf.comp hs.is_open_map_subtype_coe
lemma is_closed.closed_embedding_subtype_coe {s : set α} (hs : is_closed s) :
closed_embedding (coe : {x // x ∈ s} → α) :=
{ induced := rfl,
inj := subtype.coe_injective,
closed_range := (subtype.range_coe : range coe = s).symm ▸ hs }
@[continuity] lemma continuous_subtype_mk {f : β → α}
(hp : ∀x, p (f x)) (h : continuous f) : continuous (λx, (⟨f x, hp x⟩ : subtype p)) :=
continuous_induced_rng h
lemma continuous_inclusion {s t : set α} (h : s ⊆ t) : continuous (inclusion h) :=
continuous_subtype_mk _ continuous_subtype_coe
lemma continuous_at_subtype_coe {p : α → Prop} {a : subtype p} :
continuous_at (coe : subtype p → α) a :=
continuous_iff_continuous_at.mp continuous_subtype_coe _
lemma map_nhds_subtype_coe_eq {a : α} (ha : p a) (h : {a | p a} ∈ 𝓝 a) :
map (coe : subtype p → α) (𝓝 ⟨a, ha⟩) = 𝓝 a :=
map_nhds_induced_of_mem $ by simpa only [subtype.coe_mk, subtype.range_coe] using h
lemma nhds_subtype_eq_comap {a : α} {h : p a} :
𝓝 (⟨a, h⟩ : subtype p) = comap coe (𝓝 a) :=
nhds_induced _ _
lemma tendsto_subtype_rng {β : Type*} {p : α → Prop} {b : filter β} {f : β → subtype p} :
∀{a:subtype p}, tendsto f b (𝓝 a) ↔ tendsto (λx, (f x : α)) b (𝓝 (a : α))
| ⟨a, ha⟩ := by rw [nhds_subtype_eq_comap, tendsto_comap_iff, subtype.coe_mk]
lemma continuous_subtype_nhds_cover {ι : Sort*} {f : α → β} {c : ι → α → Prop}
(c_cover : ∀x:α, ∃i, {x | c i x} ∈ 𝓝 x)
(f_cont : ∀i, continuous (λ(x : subtype (c i)), f x)) :
continuous f :=
continuous_iff_continuous_at.mpr $ assume x,
let ⟨i, (c_sets : {x | c i x} ∈ 𝓝 x)⟩ := c_cover x in
let x' : subtype (c i) := ⟨x, mem_of_mem_nhds c_sets⟩ in
calc map f (𝓝 x) = map f (map coe (𝓝 x')) :
congr_arg (map f) (map_nhds_subtype_coe_eq _ $ c_sets).symm
... = map (λx:subtype (c i), f x) (𝓝 x') : rfl
... ≤ 𝓝 (f x) : continuous_iff_continuous_at.mp (f_cont i) x'
lemma continuous_subtype_is_closed_cover {ι : Sort*} {f : α → β} (c : ι → α → Prop)
(h_lf : locally_finite (λi, {x | c i x}))
(h_is_closed : ∀i, is_closed {x | c i x})
(h_cover : ∀x, ∃i, c i x)
(f_cont : ∀i, continuous (λ(x : subtype (c i)), f x)) :
continuous f :=
continuous_iff_is_closed.mpr $
assume s hs,
have ∀i, is_closed ((coe : {x | c i x} → α) '' (f ∘ coe ⁻¹' s)),
from assume i,
(closed_embedding_subtype_coe (h_is_closed _)).is_closed_map _ (hs.preimage (f_cont i)),
have is_closed (⋃i, (coe : {x | c i x} → α) '' (f ∘ coe ⁻¹' s)),
from locally_finite.is_closed_Union
(h_lf.subset $ assume i x ⟨⟨x', hx'⟩, _, heq⟩, heq ▸ hx')
this,
have f ⁻¹' s = (⋃i, (coe : {x | c i x} → α) '' (f ∘ coe ⁻¹' s)),
begin
apply set.ext,
have : ∀ (x : α), f x ∈ s ↔ ∃ (i : ι), c i x ∧ f x ∈ s :=
λ x, ⟨λ hx, let ⟨i, hi⟩ := h_cover x in ⟨i, hi, hx⟩,
λ ⟨i, hi, hx⟩, hx⟩,
simpa [and.comm, @and.left_comm (c _ _), ← exists_and_distrib_right],
end,
by rwa [this]
lemma closure_subtype {x : {a // p a}} {s : set {a // p a}}:
x ∈ closure s ↔ (x : α) ∈ closure ((coe : _ → α) '' s) :=
closure_induced
end subtype
section quotient
variables [topological_space α] [topological_space β] [topological_space γ]
variables {r : α → α → Prop} {s : setoid α}
lemma quotient_map_quot_mk : quotient_map (@quot.mk α r) :=
⟨quot.exists_rep, rfl⟩
@[continuity] lemma continuous_quot_mk : continuous (@quot.mk α r) :=
continuous_coinduced_rng
@[continuity] lemma continuous_quot_lift {f : α → β} (hr : ∀ a b, r a b → f a = f b)
(h : continuous f) : continuous (quot.lift f hr : quot r → β) :=
continuous_coinduced_dom h
lemma quotient_map_quotient_mk : quotient_map (@quotient.mk α s) :=
quotient_map_quot_mk
lemma continuous_quotient_mk : continuous (@quotient.mk α s) :=
continuous_coinduced_rng
lemma continuous_quotient_lift {f : α → β} (hs : ∀ a b, a ≈ b → f a = f b)
(h : continuous f) : continuous (quotient.lift f hs : quotient s → β) :=
continuous_coinduced_dom h
end quotient
section pi
variables {ι : Type*} {π : ι → Type*}
@[continuity]
lemma continuous_pi [topological_space α] [∀i, topological_space (π i)] {f : α → Πi:ι, π i}
(h : ∀i, continuous (λa, f a i)) : continuous f :=
continuous_infi_rng $ assume i, continuous_induced_rng $ h i
@[continuity]
lemma continuous_apply [∀i, topological_space (π i)] (i : ι) :
continuous (λp:Πi, π i, p i) :=
continuous_infi_dom continuous_induced_dom
lemma continuous_at_apply [∀i, topological_space (π i)] (i : ι) (x : Π i, π i) :
continuous_at (λ p : Π i, π i, p i) x :=
(continuous_apply i).continuous_at
lemma filter.tendsto.apply [∀i, topological_space (π i)] {l : filter α} {f : α → Π i, π i}
{x : Π i, π i} (h : tendsto f l (𝓝 x)) (i : ι) :
tendsto (λ a, f a i) l (𝓝 $ x i) :=
(continuous_at_apply i _).tendsto.comp h
lemma continuous_pi_iff [topological_space α] [∀ i, topological_space (π i)] {f : α → Π i, π i} :
continuous f ↔ ∀ i, continuous (λ y, f y i) :=
iff.intro (λ h i, (continuous_apply i).comp h) continuous_pi
lemma nhds_pi [t : ∀i, topological_space (π i)] {a : Πi, π i} :
𝓝 a = (⨅i, comap (λx, x i) (𝓝 (a i))) :=
calc 𝓝 a = (⨅i, @nhds _ (@topological_space.induced _ _ (λx:Πi, π i, x i) (t i)) a) : nhds_infi
... = (⨅i, comap (λx, x i) (𝓝 (a i))) : by simp [nhds_induced]
lemma tendsto_pi [t : ∀i, topological_space (π i)] {f : α → Πi, π i} {g : Πi, π i} {u : filter α} :
tendsto f u (𝓝 g) ↔ ∀ x, tendsto (λ i, f i x) u (𝓝 (g x)) :=
by simp [nhds_pi, filter.tendsto_comap_iff]
lemma continuous_at_pi [∀ i, topological_space (π i)] [topological_space α] {f : α → Π i, π i}
{x : α} :
continuous_at f x ↔ ∀ i, continuous_at (λ y, f y i) x :=
tendsto_pi
lemma filter.tendsto.update [∀i, topological_space (π i)] [decidable_eq ι]
{l : filter α} {f : α → Π i, π i} {x : Π i, π i} (hf : tendsto f l (𝓝 x)) (i : ι)
{g : α → π i} {xi : π i} (hg : tendsto g l (𝓝 xi)) :
tendsto (λ a, function.update (f a) i (g a)) l (𝓝 $ function.update x i xi) :=
tendsto_pi.2 $ λ j, by { rcases em (j = i) with rfl|hj; simp [*, hf.apply] }
lemma continuous_at.update [∀i, topological_space (π i)] [topological_space α] [decidable_eq ι]
{f : α → Π i, π i} {a : α} (hf : continuous_at f a) (i : ι) {g : α → π i}
(hg : continuous_at g a) :
continuous_at (λ a, function.update (f a) i (g a)) a :=
hf.update i hg
lemma continuous.update [∀i, topological_space (π i)] [topological_space α] [decidable_eq ι]
{f : α → Π i, π i} (hf : continuous f) (i : ι) {g : α → π i} (hg : continuous g) :
continuous (λ a, function.update (f a) i (g a)) :=
continuous_iff_continuous_at.2 $ λ x, hf.continuous_at.update i hg.continuous_at
/-- `function.update f i x` is continuous in `(f, x)`. -/
@[continuity] lemma continuous_update [∀i, topological_space (π i)] [decidable_eq ι] (i : ι) :
continuous (λ f : (Π j, π j) × π i, function.update f.1 i f.2) :=
continuous_fst.update i continuous_snd
lemma filter.tendsto.fin_insert_nth {n} {π : fin (n + 1) → Type*} [Π i, topological_space (π i)]
(i : fin (n + 1)) {f : α → π i} {l : filter α} {x : π i} (hf : tendsto f l (𝓝 x))
{g : α → Π j : fin n, π (i.succ_above j)} {y : Π j, π (i.succ_above j)} (hg : tendsto g l (𝓝 y)) :
tendsto (λ a, i.insert_nth (f a) (g a)) l (𝓝 $ i.insert_nth x y) :=
tendsto_pi.2 (λ j, fin.succ_above_cases i (by simpa) (by simpa using tendsto_pi.1 hg) j)
lemma continuous_at.fin_insert_nth {n} {π : fin (n + 1) → Type*} [Π i, topological_space (π i)]
[topological_space α] (i : fin (n + 1)) {f : α → π i} {a : α} (hf : continuous_at f a)
{g : α → Π j : fin n, π (i.succ_above j)} (hg : continuous_at g a) :
continuous_at (λ a, i.insert_nth (f a) (g a)) a :=
hf.fin_insert_nth i hg
lemma continuous.fin_insert_nth {n} {π : fin (n + 1) → Type*} [Π i, topological_space (π i)]
[topological_space α] (i : fin (n + 1)) {f : α → π i} (hf : continuous f)
{g : α → Π j : fin n, π (i.succ_above j)} (hg : continuous g) :
continuous (λ a, i.insert_nth (f a) (g a)) :=
continuous_iff_continuous_at.2 $ λ a, hf.continuous_at.fin_insert_nth i hg.continuous_at
lemma is_open_set_pi [∀a, topological_space (π a)] {i : set ι} {s : Πa, set (π a)}
(hi : finite i) (hs : ∀a∈i, is_open (s a)) : is_open (pi i s) :=
by rw [pi_def]; exact (is_open_bInter hi $ assume a ha, (hs _ ha).preimage (continuous_apply _))
lemma is_closed_set_pi [∀a, topological_space (π a)] {i : set ι} {s : Πa, set (π a)}
(hs : ∀a∈i, is_closed (s a)) : is_closed (pi i s) :=
by rw [pi_def];
exact (is_closed_Inter $ λ a, is_closed_Inter $ λ ha, (hs _ ha).preimage (continuous_apply _))
lemma mem_nhds_pi {ι : Type*} {α : ι → Type*} [Π (i : ι), topological_space (α i)]
{I : set ι} {s : Π i, set (α i)} (a : Π i, α i) (hs : I.pi s ∈ 𝓝 a) {i : ι} (hi : i ∈ I) :
s i ∈ 𝓝 (a i) :=
begin
set p := λ i, λ (x : Π (i : ι), α i), x i,
rw [nhds_pi, pi_def] at hs,
obtain ⟨t : ι → set (Π i, α i),
ht : ∀ i, t i ∈ comap (p i) (𝓝 (a i)), ht' : (⋂ i ∈ I, p i ⁻¹' s i) = ⋂ (i : ι), t i⟩ :=
exists_Inter_of_mem_infi hs,
simp only [exists_prop, mem_comap] at ht,
choose v hv hv' using ht,
apply mem_of_superset (hv i),
have := calc (⋂ i, p i ⁻¹' v i) ⊆ (⋂ i, t i) : Inter_subset_Inter hv'
... = ⋂ i ∈ I, p i ⁻¹' s i : by simp_rw ht'
... ⊆ p i ⁻¹' s i : bInter_subset_of_mem hi,
rwa [← image_subset_iff, image_projection_prod] at this,
use a,
rw [mem_univ_pi],
exact λ j, mem_of_mem_nhds (hv j)
end
lemma set_pi_mem_nhds [Π a, topological_space (π a)] {i : set ι} {s : Π a, set (π a)}
{x : Π a, π a} (hi : finite i) (hs : ∀ a ∈ i, s a ∈ 𝓝 (x a)) :
pi i s ∈ 𝓝 x :=
by { rw [pi_def, bInter_mem hi], exact λ a ha, (continuous_apply a).continuous_at (hs a ha) }
lemma set_pi_mem_nhds_iff [fintype ι] {α : ι → Type*} [Π (i : ι), topological_space (α i)]
{I : set ι} {s : Π i, set (α i)} (a : Π i, α i) :
I.pi s ∈ 𝓝 a ↔ ∀ (i : ι), i ∈ I → s i ∈ 𝓝 (a i) :=
⟨by apply mem_nhds_pi, set_pi_mem_nhds $ finite.of_fintype I⟩
lemma interior_pi_set [fintype ι] {α : ι → Type*} [Π i, topological_space (α i)]
{I : set ι} {s : Π i, set (α i)} :
interior (pi I s) = I.pi (λ i, interior (s i)) :=
by { ext a, simp only [mem_pi, mem_interior_iff_mem_nhds, set_pi_mem_nhds_iff] }
lemma exists_finset_piecewise_mem_of_mem_nhds [decidable_eq ι] [Π i, topological_space (π i)]
{s : set (Π a, π a)} {x : Π a, π a} (hs : s ∈ 𝓝 x) (y : Π a, π a) :
∃ I : finset ι, I.piecewise x y ∈ s :=
begin
simp only [nhds_pi, mem_infi', mem_comap] at hs,
rcases hs with ⟨I, hI, V, hV, hV_univ, rfl, -⟩,
choose t ht htV using hV,
refine ⟨hI.to_finset, mem_bInter $ λ i hi, htV i _⟩,
simpa [hI.mem_to_finset.2 hi] using mem_of_mem_nhds (ht i)
end
lemma pi_eq_generate_from [∀a, topological_space (π a)] :
Pi.topological_space =
generate_from {g | ∃(s:Πa, set (π a)) (i : finset ι), (∀a∈i, is_open (s a)) ∧ g = pi ↑i s} :=
le_antisymm
(le_generate_from $ assume g ⟨s, i, hi, eq⟩, eq.symm ▸ is_open_set_pi (finset.finite_to_set _) hi)
(le_infi $ assume a s ⟨t, ht, s_eq⟩, generate_open.basic _ $
⟨function.update (λa, univ) a t, {a}, by simpa using ht, by ext f; simp [s_eq.symm, pi]⟩)
lemma pi_generate_from_eq {g : Πa, set (set (π a))} :
@Pi.topological_space ι π (λa, generate_from (g a)) =
generate_from {t | ∃(s:Πa, set (π a)) (i : finset ι), (∀a∈i, s a ∈ g a) ∧ t = pi ↑i s} :=
let G := {t | ∃(s:Πa, set (π a)) (i : finset ι), (∀a∈i, s a ∈ g a) ∧ t = pi ↑i s} in
begin
rw [pi_eq_generate_from],
refine le_antisymm (generate_from_mono _) (le_generate_from _),
exact assume s ⟨t, i, ht, eq⟩, ⟨t, i, assume a ha, generate_open.basic _ (ht a ha), eq⟩,
{ rintros s ⟨t, i, hi, rfl⟩,
rw [pi_def],
apply is_open_bInter (finset.finite_to_set _),
assume a ha, show ((generate_from G).coinduced (λf:Πa, π a, f a)).is_open (t a),
refine le_generate_from _ _ (hi a ha),
exact assume s hs, generate_open.basic _ ⟨function.update (λa, univ) a s, {a}, by simp [hs]⟩ }
end
lemma pi_generate_from_eq_fintype {g : Πa, set (set (π a))} [fintype ι] (hg : ∀a, ⋃₀ g a = univ) :
@Pi.topological_space ι π (λa, generate_from (g a)) =
generate_from {t | ∃(s:Πa, set (π a)), (∀a, s a ∈ g a) ∧ t = pi univ s} :=
begin
rw [pi_generate_from_eq],
refine le_antisymm (generate_from_mono _) (le_generate_from _),
exact assume s ⟨t, ht, eq⟩, ⟨t, finset.univ, by simp [ht, eq]⟩,
{ rintros s ⟨t, i, ht, rfl⟩,
apply is_open_iff_forall_mem_open.2 _,
assume f hf,
choose c hc using show ∀a, ∃s, s ∈ g a ∧ f a ∈ s,
{ assume a, have : f a ∈ ⋃₀ g a, { rw [hg], apply mem_univ }, simpa },
refine ⟨pi univ (λa, if a ∈ i then t a else (c : Πa, set (π a)) a), _, _, _⟩,
{ simp [pi_if] },
{ refine generate_open.basic _ ⟨_, assume a, _, rfl⟩,
by_cases a ∈ i; simp [*, pi] at * },
{ have : f ∈ pi {a | a ∉ i} c, { simp [*, pi] at * },
simpa [pi_if, hf] } }
end
/-- Suppose `π i` is a family of topological spaces indexed by `i : ι`, and `X` is a type
endowed with a family of maps `f i : X → π i` for every `i : ι`, hence inducing a
map `g : X → Π i, π i`. This lemma shows that infimum of the topologies on `X` induced by
the `f i` as `i : ι` varies is simply the topology on `X` induced by `g : X → Π i, π i`
where `Π i, π i` is endowed with the usual product topology. -/
lemma inducing_infi_to_pi {X : Type*} [∀ i, topological_space (π i)] (f : Π i, X → π i) :
@inducing X (Π i, π i) (⨅ i, induced (f i) infer_instance) _ (λ x i, f i x) :=
begin
constructor,
erw induced_infi,
congr' 1,
funext,
erw induced_compose,
end
variables [fintype ι] [∀ i, topological_space (π i)] [∀ i, discrete_topology (π i)]
/-- A finite product of discrete spaces is discrete. -/
instance Pi.discrete_topology : discrete_topology (Π i, π i) :=
singletons_open_iff_discrete.mp (λ x,
begin
rw show {x} = ⋂ i, {y : Π i, π i | y i = x i},
{ ext, simp only [function.funext_iff, set.mem_singleton_iff, set.mem_Inter, set.mem_set_of_eq] },
exact is_open_Inter (λ i, (continuous_apply i).is_open_preimage {x i} (is_open_discrete {x i}))
end)
end pi
section sigma
variables {ι : Type*} {σ : ι → Type*} [Π i, topological_space (σ i)]
@[continuity]
lemma continuous_sigma_mk {i : ι} : continuous (@sigma.mk ι σ i) :=
continuous_supr_rng continuous_coinduced_rng
lemma is_open_sigma_iff {s : set (sigma σ)} : is_open s ↔ ∀ i, is_open (sigma.mk i ⁻¹' s) :=
by simp only [is_open_supr_iff, is_open_coinduced]
lemma is_closed_sigma_iff {s : set (sigma σ)} : is_closed s ↔ ∀ i, is_closed (sigma.mk i ⁻¹' s) :=
by simp [← is_open_compl_iff, is_open_sigma_iff]
lemma is_open_map_sigma_mk {i : ι} : is_open_map (@sigma.mk ι σ i) :=
begin
intros s hs,
rw is_open_sigma_iff,
intro j,
classical,
by_cases h : i = j,
{ subst j,
convert hs,
exact set.preimage_image_eq _ sigma_mk_injective },
{ convert is_open_empty,
apply set.eq_empty_of_subset_empty,
rintro x ⟨y, _, hy⟩,
have : i = j, by cc,
contradiction }
end
lemma is_open_range_sigma_mk {i : ι} : is_open (set.range (@sigma.mk ι σ i)) :=
by { rw ←set.image_univ, exact is_open_map_sigma_mk _ is_open_univ }
lemma is_closed_map_sigma_mk {i : ι} : is_closed_map (@sigma.mk ι σ i) :=
begin
intros s hs,
rw is_closed_sigma_iff,
intro j,
classical,
by_cases h : i = j,
{ subst j,
convert hs,
exact set.preimage_image_eq _ sigma_mk_injective },
{ convert is_closed_empty,
apply set.eq_empty_of_subset_empty,
rintro x ⟨y, _, hy⟩,
have : i = j, by cc,
contradiction }
end
lemma is_closed_sigma_mk {i : ι} : is_closed (set.range (@sigma.mk ι σ i)) :=
by { rw ←set.image_univ, exact is_closed_map_sigma_mk _ is_closed_univ }
lemma open_embedding_sigma_mk {i : ι} : open_embedding (@sigma.mk ι σ i) :=
open_embedding_of_continuous_injective_open
continuous_sigma_mk sigma_mk_injective is_open_map_sigma_mk
lemma closed_embedding_sigma_mk {i : ι} : closed_embedding (@sigma.mk ι σ i) :=
closed_embedding_of_continuous_injective_closed
continuous_sigma_mk sigma_mk_injective is_closed_map_sigma_mk
lemma embedding_sigma_mk {i : ι} : embedding (@sigma.mk ι σ i) :=
closed_embedding_sigma_mk.1
/-- A map out of a sum type is continuous if its restriction to each summand is. -/
@[continuity]
lemma continuous_sigma [topological_space β] {f : sigma σ → β}
(h : ∀ i, continuous (λ a, f ⟨i, a⟩)) : continuous f :=
continuous_supr_dom (λ i, continuous_coinduced_dom (h i))
@[continuity]
lemma continuous_sigma_map {κ : Type*} {τ : κ → Type*} [Π k, topological_space (τ k)]
{f₁ : ι → κ} {f₂ : Π i, σ i → τ (f₁ i)} (hf : ∀ i, continuous (f₂ i)) :
continuous (sigma.map f₁ f₂) :=
continuous_sigma $ λ i,
show continuous (λ a, sigma.mk (f₁ i) (f₂ i a)),
from continuous_sigma_mk.comp (hf i)
lemma is_open_map_sigma [topological_space β] {f : sigma σ → β}
(h : ∀ i, is_open_map (λ a, f ⟨i, a⟩)) : is_open_map f :=
begin
intros s hs,
rw is_open_sigma_iff at hs,
have : s = ⋃ i, sigma.mk i '' (sigma.mk i ⁻¹' s),
{ rw Union_image_preimage_sigma_mk_eq_self },
rw this,
rw [image_Union],
apply is_open_Union,
intro i,
rw [image_image],
exact h i _ (hs i)
end
/-- The sum of embeddings is an embedding. -/
lemma embedding_sigma_map {τ : ι → Type*} [Π i, topological_space (τ i)]
{f : Π i, σ i → τ i} (hf : ∀ i, embedding (f i)) : embedding (sigma.map id f) :=
begin
refine ⟨⟨_⟩, function.injective_id.sigma_map (λ i, (hf i).inj)⟩,
refine le_antisymm
(continuous_iff_le_induced.mp (continuous_sigma_map (λ i, (hf i).continuous))) _,
intros s hs,
replace hs := is_open_sigma_iff.mp hs,
have : ∀ i, ∃ t, is_open t ∧ f i ⁻¹' t = sigma.mk i ⁻¹' s,
{ intro i,
apply is_open_induced_iff.mp,
convert hs i,
exact (hf i).induced.symm },
choose t ht using this,
apply is_open_induced_iff.mpr,
refine ⟨⋃ i, sigma.mk i '' t i, is_open_Union (λ i, is_open_map_sigma_mk _ (ht i).1), _⟩,
ext ⟨i, x⟩,
change (sigma.mk i (f i x) ∈ ⋃ (i : ι), sigma.mk i '' t i) ↔ x ∈ sigma.mk i ⁻¹' s,
rw [←(ht i).2, mem_Union],
split,
{ rintro ⟨j, hj⟩,
rw mem_image at hj,
rcases hj with ⟨y, hy₁, hy₂⟩,
rcases sigma.mk.inj_iff.mp hy₂ with ⟨rfl, hy⟩,
replace hy := eq_of_heq hy,
subst y,
exact hy₁ },
{ intro hx,
use i,
rw mem_image,
exact ⟨f i x, hx, rfl⟩ }
end
end sigma
section ulift
@[continuity] lemma continuous_ulift_down [topological_space α] :
continuous (ulift.down : ulift.{v u} α → α) :=
continuous_induced_dom
@[continuity] lemma continuous_ulift_up [topological_space α] :
continuous (ulift.up : α → ulift.{v u} α) :=
continuous_induced_rng continuous_id
end ulift
lemma mem_closure_of_continuous [topological_space α] [topological_space β]
{f : α → β} {a : α} {s : set α} {t : set β}
(hf : continuous f) (ha : a ∈ closure s) (h : maps_to f s (closure t)) :
f a ∈ closure t :=
calc f a ∈ f '' closure s : mem_image_of_mem _ ha
... ⊆ closure (f '' s) : image_closure_subset_closure_image hf
... ⊆ closure t : closure_minimal h.image_subset is_closed_closure
lemma mem_closure_of_continuous2 [topological_space α] [topological_space β] [topological_space γ]
{f : α → β → γ} {a : α} {b : β} {s : set α} {t : set β} {u : set γ}
(hf : continuous (λp:α×β, f p.1 p.2)) (ha : a ∈ closure s) (hb : b ∈ closure t)
(h : ∀a∈s, ∀b∈t, f a b ∈ closure u) :
f a b ∈ closure u :=
have (a,b) ∈ closure (set.prod s t),
by simp [closure_prod_eq, ha, hb],
show f (a, b).1 (a, b).2 ∈ closure u,
from @mem_closure_of_continuous (α×β) _ _ _ (λp:α×β, f p.1 p.2) (a,b) _ u hf this $
assume ⟨p₁, p₂⟩ ⟨h₁, h₂⟩, h p₁ h₁ p₂ h₂
|
dad2c1db6a081ab5e518913444ebd78d2b65b42d | 450ef90ab419a8d1a41b0acbfcd9c40d706ef262 | /data/list/set.lean | 2375d6c7f9a81447fb0736b62530193e56d6c373 | [] | no_license | minchaowu/library_dev | 7bb62d254aaeae027dd78095cc4b1f0b0f3271ba | 9309df1085d8fb019f5b12d22fafd06bc1be6bf4 | refs/heads/master | 1,609,344,118,976 | 1,501,167,567,000 | 1,501,167,567,000 | 91,199,828 | 0 | 0 | null | 1,494,705,872,000 | 1,494,705,872,000 | null | UTF-8 | Lean | false | false | 31,641 | lean | /-
Copyright (c) 2015 Leonardo de Moura. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura, Jeremy Avigad
Set-like operations on lists.
-/
import data.list.basic data.list.comb .basic .comb
open nat function decidable
universe variables uu vv
variables {α : Type uu} {β : Type vv}
namespace list
section insert
variable [decidable_eq α]
@[simp]
theorem insert_nil (a : α) : insert a nil = [a] := rfl
theorem insert.def (a : α) (l : list α) : insert a l = if a ∈ l then l else concat l a := rfl
@[simp]
theorem insert_of_mem {a : α} {l : list α} (h : a ∈ l) : insert a l = l :=
by rw [insert.def, if_pos h]
@[simp]
theorem insert_of_not_mem {a : α} {l : list α} (h : a ∉ l) : insert a l = concat l a :=
by rw [insert.def, if_neg h]
@[simp]
theorem mem_insert_self (a : α) (l : list α) : a ∈ insert a l :=
by by_cases a ∈ l with h; simp [h]
@[simp]
theorem mem_insert_of_mem {a b : α} {l : list α} (h : a ∈ l) : a ∈ insert b l :=
by by_cases b ∈ l with h'; simp [h, h']
theorem eq_or_mem_of_mem_insert {a b : α} {l : list α} (h : a ∈ insert b l) : a = b ∨ a ∈ l :=
if h' : b ∈ l then
begin simp [h'] at h, simp [h] end
else
begin simp [h'] at h, assumption end
@[simp]
theorem mem_insert_iff (a b : α) (l : list α) : a ∈ insert b l ↔ a = b ∨ a ∈ l :=
iff.intro eq_or_mem_of_mem_insert
(λ h, or.elim h (begin intro h', simp [h'] end) mem_insert_of_mem)
@[simp]
theorem length_insert_of_mem {a : α} [decidable_eq α] {l : list α} (h : a ∈ l) :
length (insert a l) = length l :=
by simp [h]
@[simp]
theorem length_insert_of_not_mem {a : α} [decidable_eq α] {l : list α} (h : a ∉ l) :
length (insert a l) = length l + 1 :=
by simp [h]
theorem forall_mem_insert_of_forall_mem {p : α → Prop} {a : α} {l : list α}
(h₁ : p a) (h₂ : ∀ x ∈ l, p x) :
∀ x ∈ insert a l, p x :=
if h : a ∈ l then begin simp [h], exact h₂ end
else begin simp [h], intros b hb, cases hb with h₃ h₃, {rw h₃, assumption}, exact h₂ _ h₃ end
end insert
section erase
variable [decidable_eq α]
@[simp]
lemma erase_nil (a : α) : [].erase a = [] :=
rfl
lemma erase_cons (a b : α) (l : list α) : (b :: l).erase a = if b = a then l else b :: l.erase a :=
rfl
@[simp]
lemma erase_cons_head (a : α) (l : list α) : (a :: l).erase a = l :=
by simp [erase_cons, if_pos]
@[simp]
lemma erase_cons_tail {a b : α} (l : list α) (h : b ≠ a) : (b::l).erase a = b :: l.erase a :=
by simp [erase_cons, if_neg, h]
@[simp]
lemma length_erase_of_mem {a : α} : ∀{l:list α}, a ∈ l → length (l.erase a) = pred (length l)
| [] h := rfl
| [x] h := begin simp at h, simp [h] end
| (x::y::xs) h := if h' : x = a then
by simp [h', one_add]
else
have ainyxs : a ∈ y::xs, from or_resolve_right h $ by cc,
by simp [h', length_erase_of_mem ainyxs, one_add]
@[simp]
lemma erase_of_not_mem {a : α} : ∀{l : list α}, a ∉ l → l.erase a = l
| [] h := rfl
| (x::xs) h :=
have anex : x ≠ a, from λ aeqx : x = a, absurd (or.inl aeqx.symm) h,
have aninxs : a ∉ xs, from λ ainxs : a ∈ xs, absurd (or.inr ainxs) h,
by simp [anex, erase_of_not_mem aninxs]
lemma length_erase_of_not_mem {a : α} : ∀ {l : list α}, a ∉ l → length (l.erase a) = length l
:= λ l h, by rw erase_of_not_mem; exact h
lemma erase_append_left {a : α} : ∀ {l₁:list α} (l₂), a ∈ l₁ → (l₁++l₂).erase a = l₁.erase a ++ l₂
| [] l₂ h := absurd h (not_mem_nil a)
| (x::xs) l₂ h := if h' : x = a then by simp [h']
else
have a ∈ xs, from mem_of_ne_of_mem (assume h, h' h.symm) h,
by simp [erase_append_left l₂ this, h']
lemma erase_append_right {a : α} : ∀{l₁ : list α} (l₂), a ∉ l₁ → (l₁++l₂).erase a = l₁ ++ l₂.erase a
| [] l₂ h := rfl
| (x::xs) l₂ h := if h' : x = a then begin simp [h'] at h, contradiction end
else
have a ∉ xs, from not_mem_of_not_mem_cons h,
by simp [erase_append_right l₂ this, h']
lemma erase_sublist (a : α) : ∀(l : list α), l.erase a <+ l
| [] := sublist.refl nil
| (x :: xs) := if h : x = a then
by simp [h]
else
begin simp [h], apply cons_sublist_cons, apply erase_sublist xs end
lemma erase_subset (a : α) (l : list α) : l.erase a ⊆ l :=
subset_of_sublist (erase_sublist a l)
theorem mem_erase_of_ne_of_mem {a b : α} : ∀ {l : list α}, a ≠ b → a ∈ l → a ∈ l.erase b
| [] aneb anil := begin simp at anil, contradiction end
| (c :: l) aneb acl := if h : c = b then
begin simp [h, aneb] at acl, simp [h, acl] end
else
begin
simp [h], simp at acl, cases acl with h' h',
{ simp [h'] },
simp [mem_erase_of_ne_of_mem aneb h']
end
theorem mem_of_mem_erase {a b : α} : ∀{l:list α}, a ∈ l.erase b → a ∈ l
| [] h := begin simp at h, contradiction end
| (c :: l) h := if h' : c = b then
begin simp [h'] at h, simp [h] end
else
begin
simp [h'] at h, cases h with h'' h'',
{ simp [h''] },
simp [mem_of_mem_erase h'']
end
end erase
/- disjoint -/
section disjoint
def disjoint (l₁ l₂ : list α) : Prop := ∀ ⦃a⦄, (a ∈ l₁ → a ∈ l₂ → false)
lemma disjoint_left {l₁ l₂ : list α} : disjoint l₁ l₂ → ∀ {a}, a ∈ l₁ → a ∉ l₂ :=
λ d, d
lemma disjoint_right {l₁ l₂ : list α} : disjoint l₁ l₂ → ∀ {a}, a ∈ l₂ → a ∉ l₁ :=
λ d a i₂ i₁, d i₁ i₂
lemma disjoint.comm {l₁ l₂ : list α} : disjoint l₁ l₂ → disjoint l₂ l₁ :=
λ d a i₂ i₁, d i₁ i₂
lemma disjoint_of_subset_left {l₁ l₂ l : list α} : l₁ ⊆ l → disjoint l l₂ → disjoint l₁ l₂ :=
λ ss d x xinl₁, d (ss xinl₁)
lemma disjoint_of_subset_right {l₁ l₂ l : list α} : l₂ ⊆ l → disjoint l₁ l → disjoint l₁ l₂ :=
λ ss d x xinl xinl₁, d xinl (ss xinl₁)
lemma disjoint_of_disjoint_cons_left {a : α} {l₁ l₂} : disjoint (a::l₁) l₂ → disjoint l₁ l₂ :=
disjoint_of_subset_left (list.subset_cons _ _)
lemma disjoint_of_disjoint_cons_right {a : α} {l₁ l₂} : disjoint l₁ (a::l₂) → disjoint l₁ l₂ :=
disjoint_of_subset_right (list.subset_cons _ _)
lemma disjoint_nil_left (l : list α) : disjoint [] l :=
λ a ab, absurd ab (not_mem_nil a)
lemma disjoint_nil_right (l : list α) : disjoint l [] :=
disjoint.comm (disjoint_nil_left l)
lemma disjoint_cons_of_not_mem_of_disjoint {a : α} {l₁ l₂ : list α} :
a ∉ l₂ → disjoint l₁ l₂ → disjoint (a::l₁) l₂ :=
λ nainl₂ d x (xinal₁ : x ∈ a::l₁),
or.elim (eq_or_mem_of_mem_cons xinal₁)
(λ xeqa : x = a, eq.symm xeqa ▸ nainl₂)
(λ xinl₁ : x ∈ l₁, disjoint_left d xinl₁)
lemma disjoint_append_of_disjoint_left {l₁ l₂ l : list α} :
disjoint l₁ l → disjoint l₂ l → disjoint (l₁++l₂) l :=
λ d₁ d₂ x h, or.elim (mem_or_mem_of_mem_append h) (@d₁ x) (@d₂ x)
lemma disjoint_of_disjoint_append_left_left {l₁ l₂ l : list α} : disjoint (l₁++l₂) l → disjoint l₁ l :=
disjoint_of_subset_left (list.subset_append_left _ _)
lemma disjoint_of_disjoint_append_left_right {l₁ l₂ l : list α} : disjoint (l₁++l₂) l → disjoint l₂ l :=
disjoint_of_subset_left (list.subset_append_right _ _)
lemma disjoint_of_disjoint_append_right_left {l₁ l₂ l : list α} : disjoint l (l₁++l₂) → disjoint l l₁ :=
disjoint_of_subset_right (list.subset_append_left _ _)
lemma disjoint_of_disjoint_append_right_right {l₁ l₂ l : list α} : disjoint l (l₁++l₂) → disjoint l l₂ :=
disjoint_of_subset_right (list.subset_append_right _ _)
end disjoint
/- upto -/
def upto : nat → list nat
| 0 := []
| (n+1) := n :: upto n
@[simp]
theorem upto_nil : upto 0 = nil := rfl
@[simp]
theorem upto_succ (n : nat) : upto (succ n) = n :: upto n := rfl
@[simp]
theorem length_upto : ∀ n, length (upto n) = n
| 0 := rfl
| (succ n) := begin rw [upto_succ, length_cons, length_upto] end
theorem upto_ne_nil_of_ne_zero {n : ℕ} (h : n ≠ 0) : upto n ≠ nil :=
assume : upto n = nil,
have upto n = upto 0, from upto_nil ▸ this,
have n = 0, from calc
n = length (upto n) : by rw length_upto
... = length (upto 0) : by rw this
... = 0 : by rw length_upto,
h this
theorem lt_of_mem_upto : ∀ ⦃n i⦄, i ∈ upto n → i < n
| 0 := assume i imem, absurd imem (not_mem_nil _)
| (succ n) := assume i imem,
or.elim (eq_or_mem_of_mem_cons imem)
(λ h, begin rw h, apply lt_succ_self end)
(λ h, lt.trans (lt_of_mem_upto h) (lt_succ_self n))
theorem mem_upto_succ_of_mem_upto {n i : nat} : i ∈ upto n → i ∈ upto (succ n) :=
assume i, mem_cons_of_mem _ i
theorem mem_upto_of_lt : ∀ ⦃n i : nat⦄, i < n → i ∈ upto n
| 0 := λ i h, absurd h (not_lt_zero i)
| (succ n) := λ i h,
begin
cases nat.lt_or_eq_of_le (le_of_lt_succ h) with ilt ieq,
{ apply mem_upto_succ_of_mem_upto, apply mem_upto_of_lt ilt },
simp [ieq]
end
lemma upto_step : ∀ (n : nat), upto (succ n) = (map succ (upto n)) ++ [0]
| 0 := rfl
| (succ n) := by simp [(upto_step n)^.symm]
/- union -/
section union
variable [decidable_eq α]
@[simp]
theorem union_nil (l : list α) : l ∪ [] = l := rfl
@[simp]
theorem union_cons (l₁ l₂ : list α) (a : α) : l₁ ∪ (a :: l₂) = insert a l₁ ∪ l₂ := rfl
theorem mem_or_mem_of_mem_union : ∀ {l₁ l₂ : list α} {a : α}, a ∈ l₁ ∪ l₂ → a ∈ l₁ ∨ a ∈ l₂
| l₁ [] a h := begin simp at h, simp [h] end
| l₁ (b :: l₂) a h :=
if h' : b ∈ l₂ then
begin
simp at h,
cases mem_or_mem_of_mem_union h with h₀ h₀,
{ simp at h₀, cases h₀ with h₁ h₁, simp [h₁], simp [h₁] },
simp [h₀]
end
else
begin
simp [union_cons] at h,
cases mem_or_mem_of_mem_union h with h₀ h₀,
{ simp at h₀, cases h₀ with h₁ h₁, repeat { simp [h₁] } },
simp [h₀]
end
theorem mem_union_left {a : α} {l₁ : list α} (h : a ∈ l₁) (l₂ : list α) : a ∈ l₁ ∪ l₂ :=
begin
induction l₂ with b l₂ ih generalizing l₁,
{ simp [h] },
{ apply ih, simp [h] }
end
theorem mem_union_right {a : α} (l₁ : list α) {l₂ : list α} (h : a ∈ l₂) : a ∈ l₁ ∪ l₂ :=
begin
induction l₂ with b l₂ ih generalizing l₁,
{ simp at h, contradiction },
simp, simp at h,
cases h with h₀ h₀,
{ subst h₀, apply mem_union_left, simp },
apply ih h₀
end
@[simp]
theorem mem_union_iff (a : α) (l₁ l₂ : list α) : a ∈ l₁ ∪ l₂ ↔ a ∈ l₁ ∨ a ∈ l₂ :=
iff.intro mem_or_mem_of_mem_union (λ h, or.elim h (λ h', mem_union_left h' l₂) (mem_union_right l₁))
theorem forall_mem_union {p : α → Prop} {l₁ l₂ : list α} (h₁ : ∀ x ∈ l₁, p x) (h₂ : ∀ x ∈ l₂, p x) :
∀ x ∈ l₁ ∪ l₂, p x :=
begin
intro x, simp, intro h, cases h,
{ apply h₁, assumption },
apply h₂, assumption
end
theorem forall_mem_of_forall_mem_union_left {p : α → Prop} {l₁ l₂ : list α}
(h : ∀ x ∈ l₁ ∪ l₂, p x) :
∀ x ∈ l₁, p x :=
begin intros x xl₁, apply h, apply mem_union_left xl₁ end
theorem forall_mem_of_forall_mem_union_right {p : α → Prop} {l₁ l₂ : list α}
(h : ∀ x ∈ l₁ ∪ l₂, p x) :
∀ x ∈ l₂, p x :=
begin intros x xl₂, apply h, apply mem_union_right l₁ xl₂ end
end union
/- inter -/
section inter
variable [decidable_eq α]
@[simp]
theorem inter_nil (l : list α) : [] ∩ l = [] := rfl
@[simp]
theorem inter_cons_of_mem {a : α} (l₁ : list α) {l₂ : list α} (h : a ∈ l₂) :
(a::l₁) ∩ l₂ = a :: (l₁ ∩ l₂) :=
if_pos h
@[simp]
theorem inter_cons_of_not_mem {a : α} (l₁ : list α) {l₂ : list α} (h : a ∉ l₂) :
(a::l₁) ∩ l₂ = l₁ ∩ l₂ :=
if_neg h
theorem mem_of_mem_inter_left : ∀ {l₁ l₂ : list α} {a : α}, a ∈ l₁ ∩ l₂ → a ∈ l₁
| [] l₂ a i := absurd i (not_mem_nil a)
| (b::l₁) l₂ a i := by_cases
(λ binl₂ : b ∈ l₂,
have aux : a ∈ b :: l₁ ∩ l₂, begin rw [inter_cons_of_mem _ binl₂] at i, exact i end,
or.elim (eq_or_mem_of_mem_cons aux)
(λ aeqb : a = b, begin rw [aeqb], apply mem_cons_self end)
(λ aini, mem_cons_of_mem _ (mem_of_mem_inter_left aini)))
(λ nbinl₂ : b ∉ l₂,
have ainl₁ : a ∈ l₁,
begin rw [inter_cons_of_not_mem _ nbinl₂] at i, exact (mem_of_mem_inter_left i) end,
mem_cons_of_mem _ ainl₁)
theorem mem_of_mem_inter_right : ∀ {l₁ l₂ : list α} {a : α}, a ∈ l₁ ∩ l₂ → a ∈ l₂
| [] l₂ a i := absurd i (not_mem_nil _)
| (b::l₁) l₂ a i := by_cases
(λ binl₂ : b ∈ l₂,
have aux : a ∈ b :: l₁ ∩ l₂, begin rw [inter_cons_of_mem _ binl₂] at i, exact i end,
or.elim (eq_or_mem_of_mem_cons aux)
(λ aeqb : a = b, begin rw [aeqb], exact binl₂ end)
(λ aini : a ∈ l₁ ∩ l₂, mem_of_mem_inter_right aini))
(λ nbinl₂ : b ∉ l₂,
begin rw [inter_cons_of_not_mem _ nbinl₂] at i, exact (mem_of_mem_inter_right i) end)
theorem mem_inter_of_mem_of_mem : ∀ {l₁ l₂ : list α} {a : α}, a ∈ l₁ → a ∈ l₂ → a ∈ l₁ ∩ l₂
| [] l₂ a i₁ i₂ := absurd i₁ (not_mem_nil _)
| (b::l₁) l₂ a i₁ i₂ := by_cases
(λ binl₂ : b ∈ l₂,
or.elim (eq_or_mem_of_mem_cons i₁)
(λ aeqb : a = b,
begin rw [inter_cons_of_mem _ binl₂, aeqb], apply mem_cons_self end)
(λ ainl₁ : a ∈ l₁,
begin
rw [inter_cons_of_mem _ binl₂],
apply mem_cons_of_mem,
exact (mem_inter_of_mem_of_mem ainl₁ i₂)
end))
(λ nbinl₂ : b ∉ l₂,
or.elim (eq_or_mem_of_mem_cons i₁)
(λ aeqb : a = b,
begin rw aeqb at i₂, exact absurd i₂ nbinl₂ end)
(λ ainl₁ : a ∈ l₁,
begin rw [inter_cons_of_not_mem _ nbinl₂], exact (mem_inter_of_mem_of_mem ainl₁ i₂) end))
@[simp]
theorem mem_inter_iff (a : α) (l₁ l₂ : list α) : a ∈ l₁ ∩ l₂ ↔ a ∈ l₁ ∧ a ∈ l₂ :=
iff.intro
(λ h, and.intro (mem_of_mem_inter_left h) (mem_of_mem_inter_right h))
(λ h, mem_inter_of_mem_of_mem h^.left h^.right)
theorem inter_eq_nil_of_disjoint : ∀ {l₁ l₂ : list α}, disjoint l₁ l₂ → l₁ ∩ l₂ = []
| [] l₂ d := rfl
| (a::l₁) l₂ d :=
have aux_eq : l₁ ∩ l₂ = [], from inter_eq_nil_of_disjoint (disjoint_of_disjoint_cons_left d),
have nainl₂ : a ∉ l₂, from disjoint_left d (mem_cons_self _ _),
by rw [inter_cons_of_not_mem _ nainl₂, aux_eq]
theorem forall_mem_inter_of_forall_left {p : α → Prop} {l₁ : list α} (h : ∀ x ∈ l₁, p x)
(l₂ : list α) :
∀ x, x ∈ l₁ ∩ l₂ → p x :=
λ x xl₁l₂, h x (mem_of_mem_inter_left xl₁l₂)
theorem forall_mem_inter_of_forall_right {p : α → Prop} (l₁ : list α) {l₂ : list α}
(h : ∀ x ∈ l₂, p x) :
∀ x, x ∈ l₁ ∩ l₂ → p x :=
λ x xl₁l₂, h x (mem_of_mem_inter_right xl₁l₂)
end inter
/- no duplicates predicate -/
inductive nodup {α : Type uu} : list α → Prop
| ndnil : nodup []
| ndcons : ∀ {a : α} {l : list α}, a ∉ l → nodup l → nodup (a::l)
section nodup
open nodup
theorem nodup_nil : @nodup α [] :=
ndnil
theorem nodup_cons {a : α} {l : list α} : a ∉ l → nodup l → nodup (a::l) :=
λ i n, ndcons i n
theorem nodup_singleton (a : α) : nodup [a] :=
nodup_cons (not_mem_nil a) nodup_nil
theorem nodup_of_nodup_cons : ∀ {a : α} {l : list α}, nodup (a::l) → nodup l
| a xs (ndcons i n) := n
theorem not_mem_of_nodup_cons : ∀ {a : α} {l : list α}, nodup (a::l) → a ∉ l
| a xs (ndcons i n) := i
theorem not_nodup_cons_of_mem {a : α} {l : list α} : a ∈ l → ¬ nodup (a :: l) :=
λ ainl d, absurd ainl (not_mem_of_nodup_cons d)
theorem nodup_of_sublist : Π {l₁ l₂ : list α}, l₁ <+ l₂ → nodup l₂ → nodup l₁
| ._ ._ sublist.slnil h := h
| ._ ._ (sublist.cons l₁ l₂ a s) (ndcons i n) := nodup_of_sublist s n
| ._ ._ (sublist.cons2 l₁ l₂ a s) (ndcons i n) :=
ndcons (λh, i (subset_of_sublist s h)) (nodup_of_sublist s n)
theorem not_nodup_cons_of_not_nodup {a : α} {l : list α} : ¬ nodup l → ¬ nodup (a :: l) :=
mt nodup_of_nodup_cons
theorem nodup_of_nodup_append_left {l₁ l₂ : list α} : nodup (l₁++l₂) → nodup l₁ :=
nodup_of_sublist (sublist_append_left l₁ l₂)
theorem nodup_of_nodup_append_right : ∀ {l₁ l₂ : list α}, nodup (l₁++l₂) → nodup l₂
| [] l₂ n := n
| (x::xs) l₂ n := nodup_of_nodup_append_right (nodup_of_nodup_cons n)
theorem disjoint_of_nodup_append : ∀ {l₁ l₂ : list α}, nodup (l₁++l₂) → disjoint l₁ l₂
| [] l₂ d := disjoint_nil_left l₂
| (x::xs) l₂ d :=
have nodup (x::(xs++l₂)), from d,
have x ∉ xs++l₂, from not_mem_of_nodup_cons this,
have nxinl₂ : x ∉ l₂, from not_mem_of_not_mem_append_right this,
assume a, assume : a ∈ x::xs,
or.elim (eq_or_mem_of_mem_cons this)
(assume : a = x, eq.symm this ▸ nxinl₂)
(assume ainxs : a ∈ xs,
have nodup (x::(xs++l₂)), from d,
have nodup (xs++l₂), from nodup_of_nodup_cons this,
have disjoint xs l₂, from disjoint_of_nodup_append this,
disjoint_left this ainxs)
theorem nodup_append_of_nodup_of_nodup_of_disjoint :
∀ {l₁ l₂ : list α}, nodup l₁ → nodup l₂ → disjoint l₁ l₂ → nodup (l₁++l₂)
| [] l₂ d₁ d₂ dsj := begin rw [nil_append], exact d₂ end
| (x::xs) l₂ d₁ d₂ dsj :=
have ndxs : nodup xs, from nodup_of_nodup_cons d₁,
have disjoint xs l₂, from disjoint_of_disjoint_cons_left dsj,
have ndxsl₂ : nodup (xs++l₂), from nodup_append_of_nodup_of_nodup_of_disjoint ndxs d₂ this,
have nxinxs : x ∉ xs, from not_mem_of_nodup_cons d₁,
have x ∉ l₂, from disjoint_left dsj (mem_cons_self x xs),
have x ∉ xs++l₂, from not_mem_append nxinxs this,
nodup_cons this ndxsl₂
theorem nodup_app_comm {l₁ l₂ : list α} (d : nodup (l₁++l₂)) : nodup (l₂++l₁) :=
have d₁ : nodup l₁, from nodup_of_nodup_append_left d,
have d₂ : nodup l₂, from nodup_of_nodup_append_right d,
have dsj : disjoint l₁ l₂, from disjoint_of_nodup_append d,
nodup_append_of_nodup_of_nodup_of_disjoint d₂ d₁ (disjoint.comm dsj)
theorem nodup_head {a : α} {l₁ l₂ : list α} (d : nodup (l₁++(a::l₂))) : nodup (a::(l₁++l₂)) :=
have d₁ : nodup (a::(l₂++l₁)), from nodup_app_comm d,
have d₂ : nodup (l₂++l₁), from nodup_of_nodup_cons d₁,
have d₃ : nodup (l₁++l₂), from nodup_app_comm d₂,
have nain : a ∉ l₂++l₁, from not_mem_of_nodup_cons d₁,
have nain₂ : a ∉ l₂, from not_mem_of_not_mem_append_left nain,
have nain₁ : a ∉ l₁, from not_mem_of_not_mem_append_right nain,
nodup_cons (not_mem_append nain₁ nain₂) d₃
theorem nodup_middle {a : α} {l₁ l₂ : list α} (d : nodup (a::(l₁++l₂))) : nodup (l₁++(a::l₂)) :=
have d₁ : nodup (l₁++l₂), from nodup_of_nodup_cons d,
have nain : a ∉ l₁++l₂, from not_mem_of_nodup_cons d,
have disj : disjoint l₁ l₂, from disjoint_of_nodup_append d₁,
have d₂ : nodup l₁, from nodup_of_nodup_append_left d₁,
have d₃ : nodup l₂, from nodup_of_nodup_append_right d₁,
have nain₂ : a ∉ l₂, from not_mem_of_not_mem_append_right nain,
have nain₁ : a ∉ l₁, from not_mem_of_not_mem_append_left nain,
have d₄ : nodup (a::l₂), from nodup_cons nain₂ d₃,
have disj₂ : disjoint l₁ (a::l₂), from disjoint.comm (disjoint_cons_of_not_mem_of_disjoint nain₁
(disjoint.comm disj)),
nodup_append_of_nodup_of_nodup_of_disjoint d₂ d₄ disj₂
theorem nodup_map {f : α → β} (inj : injective f) : ∀ {l : list α}, nodup l → nodup (map f l)
| [] n := begin apply nodup_nil end
| (x::xs) n :=
have nxinxs : x ∉ xs, from not_mem_of_nodup_cons n,
have ndxs : nodup xs, from nodup_of_nodup_cons n,
have ndmfxs : nodup (map f xs), from nodup_map ndxs,
have nfxinm : f x ∉ map f xs, from
λ ab : f x ∈ map f xs,
match (exists_of_mem_map ab) with
| ⟨(y : α), (yinxs : y ∈ xs), (fyfx : f y = f x)⟩ :=
have yeqx : y = x, from inj fyfx,
begin subst y, contradiction end
end,
nodup_cons nfxinm ndmfxs
theorem nodup_erase_of_nodup [decidable_eq α] (a : α) : ∀ {l}, nodup l → nodup (l.erase a)
| [] n := nodup_nil
| (b::l) n := by_cases
(λ aeqb : b = a, begin rw [aeqb, erase_cons_head], exact (nodup_of_nodup_cons n) end)
(λ aneb : b ≠ a,
have nbinl : b ∉ l, from not_mem_of_nodup_cons n,
have ndl : nodup l, from nodup_of_nodup_cons n,
have ndeal : nodup (l.erase a), from nodup_erase_of_nodup ndl,
have nbineal : b ∉ l.erase a, from λ i, absurd (erase_subset _ _ i) nbinl,
have aux : nodup (b :: l.erase a), from nodup_cons nbineal ndeal,
begin rw [erase_cons_tail _ aneb], exact aux end)
theorem mem_erase_of_nodup [decidable_eq α] (a : α) : ∀ {l}, nodup l → a ∉ l.erase a
| [] n := (not_mem_nil _)
| (b::l) n :=
have ndl : nodup l, from nodup_of_nodup_cons n,
have naineal : a ∉ l.erase a, from mem_erase_of_nodup ndl,
have nbinl : b ∉ l, from not_mem_of_nodup_cons n,
by_cases
(λ aeqb : b = a, begin rw [aeqb.symm, erase_cons_head], exact nbinl end)
(λ aneb : b ≠ a,
have aux : a ∉ b :: l.erase a, from
assume ainbeal : a ∈ b :: l.erase a, or.elim (eq_or_mem_of_mem_cons ainbeal)
(λ aeqb : a = b, absurd aeqb.symm aneb)
(λ aineal : a ∈ l.erase a, absurd aineal naineal),
begin rw [erase_cons_tail _ aneb], exact aux end)
def erase_dup [decidable_eq α] : list α → list α
| [] := []
| (x :: xs) := if x ∈ xs then erase_dup xs else x :: erase_dup xs
theorem erase_dup_nil [decidable_eq α] : erase_dup [] = ([] : list α) := rfl
theorem erase_dup_cons_of_mem [decidable_eq α] {a : α} {l : list α} :
a ∈ l → erase_dup (a::l) = erase_dup l :=
assume ainl, calc
erase_dup (a::l) = if a ∈ l then erase_dup l else a :: erase_dup l : rfl
... = erase_dup l : if_pos ainl
theorem erase_dup_cons_of_not_mem [decidable_eq α] {a : α} {l : list α} :
a ∉ l → erase_dup (a::l) = a :: erase_dup l :=
assume nainl, calc
erase_dup (a::l) = if a ∈ l then erase_dup l else a :: erase_dup l : rfl
... = a :: erase_dup l : if_neg nainl
theorem mem_erase_dup [decidable_eq α] {a : α} : ∀ {l : list α}, a ∈ l → a ∈ erase_dup l
| [] h := absurd h (not_mem_nil _)
| (b::l) h := by_cases
(λ binl : b ∈ l, or.elim (eq_or_mem_of_mem_cons h)
(λ aeqb : a = b,
begin rw [erase_dup_cons_of_mem binl], rw ←aeqb at binl, exact (mem_erase_dup binl) end)
(λ ainl : a ∈ l,
begin rw [erase_dup_cons_of_mem binl], exact (mem_erase_dup ainl) end))
(λ nbinl : b ∉ l, or.elim (eq_or_mem_of_mem_cons h)
(λ aeqb : a = b,
begin rw [erase_dup_cons_of_not_mem nbinl, aeqb], apply mem_cons_self end)
(λ ainl : a ∈ l,
begin rw [erase_dup_cons_of_not_mem nbinl], exact (or.inr (mem_erase_dup ainl)) end))
theorem erase_dup_sublist [decidable_eq α] : ∀ (l : list α), erase_dup l <+ l
| [] := sublist.slnil
| (b::l) := if h : b ∈ l then
by simp[erase_dup, h]; exact sublist_cons_of_sublist _ (erase_dup_sublist l)
else
by simp[erase_dup, h]; exact cons_sublist_cons _ (erase_dup_sublist l)
theorem mem_of_mem_erase_dup [decidable_eq α] {a : α} : ∀ {l : list α}, a ∈ erase_dup l → a ∈ l
| [] h := begin rw [erase_dup_nil] at h, exact h end
| (b::l) h := by_cases
(λ binl : b ∈ l,
have h₁ : a ∈ erase_dup l,
begin rw [erase_dup_cons_of_mem binl] at h, exact h end,
or.inr (mem_of_mem_erase_dup h₁))
(λ nbinl : b ∉ l,
have h₁ : a ∈ b :: erase_dup l,
begin rw [erase_dup_cons_of_not_mem nbinl] at h, exact h end,
or.elim (eq_or_mem_of_mem_cons h₁)
(λ aeqb : a = b, begin rw aeqb, apply mem_cons_self end)
(λ ainel : a ∈ erase_dup l, or.inr (mem_of_mem_erase_dup ainel)))
@[simp]
theorem mem_erase_dup_iff [decidable_eq α] (a : α) (l : list α) : a ∈ erase_dup l ↔ a ∈ l :=
iff.intro mem_of_mem_erase_dup mem_erase_dup
theorem erase_dup_sub [decidable_eq α] (l : list α) : erase_dup l ⊆ l :=
λ a i, mem_of_mem_erase_dup i
theorem sub_erase_dup [decidable_eq α] (l : list α) : l ⊆ erase_dup l :=
λ a i, mem_erase_dup i
theorem nodup_erase_dup [decidable_eq α] : ∀ l : list α, nodup (erase_dup l)
| [] := begin rw erase_dup_nil, exact nodup_nil end
| (a::l) := by_cases
(λ ainl : a ∈ l, begin rw [erase_dup_cons_of_mem ainl], exact (nodup_erase_dup l) end)
(λ nainl : a ∉ l,
have r : nodup (erase_dup l), from nodup_erase_dup l,
have nin : a ∉ erase_dup l, from
assume ab : a ∈ erase_dup l, absurd (mem_of_mem_erase_dup ab) nainl,
begin rw [erase_dup_cons_of_not_mem nainl], exact (nodup_cons nin r) end)
theorem erase_dup_eq_of_nodup [decidable_eq α] : ∀ {l : list α}, nodup l → erase_dup l = l
| [] d := rfl
| (a::l) d :=
have nainl : a ∉ l, from not_mem_of_nodup_cons d,
have dl : nodup l, from nodup_of_nodup_cons d,
by rw [erase_dup_cons_of_not_mem nainl, erase_dup_eq_of_nodup dl]
attribute [instance]
def decidable_nodup [decidable_eq α] : ∀ (l : list α), decidable (nodup l)
| [] := is_true nodup_nil
| (a::l) :=
if h : a ∈ l then
is_false (not_nodup_cons_of_mem h)
else
match (decidable_nodup l) with
| (is_true nd) := is_true (nodup_cons h nd)
| (is_false d) := is_false (not_nodup_cons_of_not_nodup d)
end
private def dgen (a : α) : ∀ l, nodup l → nodup (map (λ b : β, (a, b)) l)
| [] h := nodup_nil
| (x::l) h :=
have dl : nodup l, from nodup_of_nodup_cons h,
have dm : nodup (map (λ b : β, (a, b)) l), from dgen l dl,
have nxin : x ∉ l, from not_mem_of_nodup_cons h,
have npin : (a, x) ∉ map (λ b, (a, b)) l, from
assume pin, absurd (mem_of_mem_map_pair₁ pin) nxin,
nodup_cons npin dm
theorem nodup_product : ∀ {l₁ : list α} {l₂ : list β}, nodup l₁ → nodup l₂ → nodup (product l₁ l₂)
| [] l₂ n₁ n₂ := nodup_nil
| (a::l₁) l₂ n₁ n₂ :=
have nainl₁ : a ∉ l₁, from not_mem_of_nodup_cons n₁,
have n₃ : nodup l₁, from nodup_of_nodup_cons n₁,
have n₄ : nodup (product l₁ l₂), from nodup_product n₃ n₂,
have dm : nodup (map (λ b : β, (a, b)) l₂), from dgen a l₂ n₂,
have dsj : disjoint (map (λ b : β, (a, b)) l₂) (product l₁ l₂), from
λ p : α × β, match p with
| (a₁, b₁) :=
λ (i₁ : (a₁, b₁) ∈ map (λ b, (a, b)) l₂) (i₂ : (a₁, b₁) ∈ product l₁ l₂),
have a₁inl₁ : a₁ ∈ l₁, from mem_of_mem_product_left i₂,
have a₁ = a, from eq_of_mem_map_pair₁ i₁,
have a ∈ l₁, begin rw ←this, assumption end,
absurd this nainl₁
end,
nodup_append_of_nodup_of_nodup_of_disjoint dm n₄ dsj
theorem nodup_filter (p : α → Prop) [decidable_pred p] :
∀ {l : list α}, nodup l → nodup (filter p l)
| [] nd := nodup_nil
| (a::l) nd :=
have nainl : a ∉ l, from not_mem_of_nodup_cons nd,
have ndl : nodup l, from nodup_of_nodup_cons nd,
have ndf : nodup (filter p l), from nodup_filter ndl,
have nainf : a ∉ filter p l, from
assume ainf, absurd (mem_of_mem_filter ainf) nainl,
by_cases
(λ pa : p a, begin rw [filter_cons_of_pos _ pa], exact (nodup_cons nainf ndf) end)
(λ npa : ¬ p a, begin rw [filter_cons_of_neg _ npa], exact ndf end)
lemma dmap_nodup_of_dinj {p : α → Prop} [h : decidable_pred p] {f : Π a, p a → β} (pdi : dinj p f) :
∀ {l : list α}, nodup l → nodup (dmap p f l)
| [] := assume P, nodup.ndnil
| (a::l) := assume Pnodup,
if pa : p a then
begin
rw [dmap_cons_of_pos pa],
apply nodup_cons,
apply (not_mem_dmap_of_dinj_of_not_mem pdi pa),
exact not_mem_of_nodup_cons Pnodup,
exact dmap_nodup_of_dinj (nodup_of_nodup_cons Pnodup)
end
else
begin
rw [dmap_cons_of_neg pa],
exact dmap_nodup_of_dinj (nodup_of_nodup_cons Pnodup)
end
theorem nodup_concat {a : α} {l : list α} (h : a ∉ l) (h' : nodup l) : nodup (concat l a) :=
begin
revert h, induction l with b l ih,
{ intro h₀, apply nodup_singleton },
intro h₀, rw [concat_cons], apply nodup_cons,
{ simp, intro h₁, apply h₀, simp, cases h₁ with h₂ h₂, simp [h₂],
exact absurd h₂ (not_mem_of_nodup_cons h') },
apply ih,
{ apply nodup_of_nodup_cons h' },
intro h₁, apply h₀, exact mem_cons_of_mem _ h₁
end
theorem nodup_insert [decidable_eq α] {a : α} {l : list α} (h : nodup l) : nodup (insert a l) :=
if h' : a ∈ l then by simp [h', h]
else begin rw [insert_of_not_mem h'], apply nodup_concat, repeat {assumption} end
theorem nodup_upto : ∀ n, nodup (upto n)
| 0 := nodup_nil
| (n+1) :=
have d : nodup (upto n), from nodup_upto n,
have n : n ∉ upto n, from
assume i : n ∈ upto n, absurd (lt_of_mem_upto i) (nat.lt_irrefl n),
nodup_cons n d
theorem nodup_union_of_nodup_of_nodup [decidable_eq α] {l₁ l₂ : list α}
(h₁ : nodup l₁) (h₂ : nodup l₂) :
nodup (l₁ ∪ l₂) :=
begin
induction l₂ with a l₂ ih generalizing l₁,
{ exact h₁ },
simp,
apply ih,
{ apply nodup_of_nodup_cons h₂ },
apply nodup_insert h₁
end
theorem nodup_inter_of_nodup [decidable_eq α] : ∀ {l₁ : list α} (l₂), nodup l₁ → nodup (l₁ ∩ l₂)
| [] l₂ d := nodup_nil
| (a::l₁) l₂ d :=
have d₁ : nodup l₁, from nodup_of_nodup_cons d,
have d₂ : nodup (l₁ ∩ l₂), from nodup_inter_of_nodup _ d₁,
have nainl₁ : a ∉ l₁, from not_mem_of_nodup_cons d,
have naini : a ∉ l₁ ∩ l₂, from λ i, absurd (mem_of_mem_inter_left i) nainl₁,
by_cases
(λ ainl₂ : a ∈ l₂, begin rw [inter_cons_of_mem _ ainl₂], exact (nodup_cons naini d₂) end)
(λ nainl₂ : a ∉ l₂, begin rw [inter_cons_of_not_mem _ nainl₂], exact d₂ end)
end nodup
end list
|
978cc85f3526829a465f07e31ecc741eb4c11904 | d406927ab5617694ec9ea7001f101b7c9e3d9702 | /src/topology/instances/matrix.lean | 9a783e84d865b6a121dfdbf2023a1ed1691c1cfc | [
"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 | 18,504 | lean | /-
Copyright (c) 2021 Oliver Nash. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Oliver Nash, Eric Wieser
-/
import topology.algebra.infinite_sum
import topology.algebra.ring
import topology.algebra.star
import linear_algebra.matrix.nonsingular_inverse
import linear_algebra.matrix.trace
/-!
# Topological properties of matrices
This file is a place to collect topological results about matrices.
## Main definitions:
* `matrix.topological_ring`: square matrices form a topological ring
## Main results
* Continuity:
* `continuous.matrix_det`: the determinant is continuous over a topological ring.
* `continuous.matrix_adjugate`: the adjugate is continuous over a topological ring.
* Infinite sums
* `matrix.transpose_tsum`: transpose commutes with infinite sums
* `matrix.diagonal_tsum`: diagonal commutes with infinite sums
* `matrix.block_diagonal_tsum`: block diagonal commutes with infinite sums
* `matrix.block_diagonal'_tsum`: non-uniform block diagonal commutes with infinite sums
-/
open matrix
open_locale matrix
variables {X α l m n p S R : Type*} {m' n' : l → Type*}
instance [topological_space R] : topological_space (matrix m n R) := Pi.topological_space
instance [topological_space R] [t2_space R] : t2_space (matrix m n R) := Pi.t2_space
/-! ### Lemmas about continuity of operations -/
section continuity
variables [topological_space X] [topological_space R]
instance [has_smul α R] [has_continuous_const_smul α R] :
has_continuous_const_smul α (matrix m n R) :=
pi.has_continuous_const_smul
instance [topological_space α] [has_smul α R] [has_continuous_smul α R] :
has_continuous_smul α (matrix m n R) :=
pi.has_continuous_smul
instance [has_add R] [has_continuous_add R] : has_continuous_add (matrix m n R) :=
pi.has_continuous_add
instance [has_neg R] [has_continuous_neg R] : has_continuous_neg (matrix m n R) :=
pi.has_continuous_neg
instance [add_group R] [topological_add_group R] : topological_add_group (matrix m n R) :=
pi.topological_add_group
/-- To show a function into matrices is continuous it suffices to show the coefficients of the
resulting matrix are continuous -/
@[continuity]
lemma continuous_matrix [topological_space α] {f : α → matrix m n R}
(h : ∀ i j, continuous (λ a, f a i j)) : continuous f :=
continuous_pi $ λ _, continuous_pi $ λ j, h _ _
lemma continuous.matrix_elem {A : X → matrix m n R} (hA : continuous A) (i : m) (j : n) :
continuous (λ x, A x i j) :=
(continuous_apply_apply i j).comp hA
@[continuity]
lemma continuous.matrix_map [topological_space S] {A : X → matrix m n S} {f : S → R}
(hA : continuous A) (hf : continuous f) :
continuous (λ x, (A x).map f) :=
continuous_matrix $ λ i j, hf.comp $ hA.matrix_elem _ _
@[continuity]
lemma continuous.matrix_transpose {A : X → matrix m n R} (hA : continuous A) :
continuous (λ x, (A x)ᵀ) :=
continuous_matrix $ λ i j, hA.matrix_elem j i
lemma continuous.matrix_conj_transpose [has_star R] [has_continuous_star R] {A : X → matrix m n R}
(hA : continuous A) : continuous (λ x, (A x)ᴴ) :=
hA.matrix_transpose.matrix_map continuous_star
instance [has_star R] [has_continuous_star R] : has_continuous_star (matrix m m R) :=
⟨continuous_id.matrix_conj_transpose⟩
@[continuity]
lemma continuous.matrix_col {A : X → n → R} (hA : continuous A) : continuous (λ x, col (A x)) :=
continuous_matrix $ λ i j, (continuous_apply _).comp hA
@[continuity]
lemma continuous.matrix_row {A : X → n → R} (hA : continuous A) : continuous (λ x, row (A x)) :=
continuous_matrix $ λ i j, (continuous_apply _).comp hA
@[continuity]
lemma continuous.matrix_diagonal [has_zero R] [decidable_eq n] {A : X → n → R} (hA : continuous A) :
continuous (λ x, diagonal (A x)) :=
continuous_matrix $ λ i j, ((continuous_apply i).comp hA).if_const _ continuous_zero
@[continuity]
lemma continuous.matrix_dot_product [fintype n] [has_mul R] [add_comm_monoid R]
[has_continuous_add R] [has_continuous_mul R]
{A : X → n → R} {B : X → n → R} (hA : continuous A) (hB : continuous B) :
continuous (λ x, dot_product (A x) (B x)) :=
continuous_finset_sum _ $ λ i _, ((continuous_apply i).comp hA).mul ((continuous_apply i).comp hB)
/-- For square matrices the usual `continuous_mul` can be used. -/
@[continuity]
lemma continuous.matrix_mul [fintype n] [has_mul R] [add_comm_monoid R] [has_continuous_add R]
[has_continuous_mul R]
{A : X → matrix m n R} {B : X → matrix n p R} (hA : continuous A) (hB : continuous B) :
continuous (λ x, (A x).mul (B x)) :=
continuous_matrix $ λ i j, continuous_finset_sum _ $ λ k _,
(hA.matrix_elem _ _).mul (hB.matrix_elem _ _)
instance [fintype n] [has_mul R] [add_comm_monoid R] [has_continuous_add R]
[has_continuous_mul R] : has_continuous_mul (matrix n n R) :=
⟨continuous_fst.matrix_mul continuous_snd⟩
instance [fintype n] [non_unital_non_assoc_semiring R] [topological_semiring R] :
topological_semiring (matrix n n R) :=
{}
instance [fintype n] [non_unital_non_assoc_ring R] [topological_ring R] :
topological_ring (matrix n n R) :=
{}
@[continuity]
lemma continuous.matrix_vec_mul_vec [has_mul R] [has_continuous_mul R]
{A : X → m → R} {B : X → n → R} (hA : continuous A) (hB : continuous B) :
continuous (λ x, vec_mul_vec (A x) (B x)) :=
continuous_matrix $ λ i j, ((continuous_apply _).comp hA).mul ((continuous_apply _).comp hB)
@[continuity]
lemma continuous.matrix_mul_vec [non_unital_non_assoc_semiring R] [has_continuous_add R]
[has_continuous_mul R] [fintype n]
{A : X → matrix m n R} {B : X → n → R} (hA : continuous A) (hB : continuous B) :
continuous (λ x, (A x).mul_vec (B x)) :=
continuous_pi $ λ i, ((continuous_apply i).comp hA).matrix_dot_product hB
@[continuity]
lemma continuous.matrix_vec_mul [non_unital_non_assoc_semiring R] [has_continuous_add R]
[has_continuous_mul R] [fintype m]
{A : X → m → R} {B : X → matrix m n R} (hA : continuous A) (hB : continuous B) :
continuous (λ x, vec_mul (A x) (B x)) :=
continuous_pi $ λ i, hA.matrix_dot_product $ continuous_pi $ λ j, hB.matrix_elem _ _
@[continuity]
lemma continuous.matrix_submatrix
{A : X → matrix l n R} (hA : continuous A) (e₁ : m → l) (e₂ : p → n) :
continuous (λ x, (A x).submatrix e₁ e₂) :=
continuous_matrix $ λ i j, hA.matrix_elem _ _
@[continuity]
lemma continuous.matrix_reindex {A : X → matrix l n R}
(hA : continuous A) (e₁ : l ≃ m) (e₂ : n ≃ p) :
continuous (λ x, reindex e₁ e₂ (A x)) :=
hA.matrix_submatrix _ _
@[continuity]
lemma continuous.matrix_diag {A : X → matrix n n R} (hA : continuous A) :
continuous (λ x, matrix.diag (A x)) :=
continuous_pi $ λ _, hA.matrix_elem _ _
-- note this doesn't elaborate well from the above
lemma continuous_matrix_diag : continuous (matrix.diag : matrix n n R → n → R) :=
show continuous (λ x : matrix n n R, matrix.diag x), from continuous_id.matrix_diag
@[continuity]
lemma continuous.matrix_trace [fintype n] [add_comm_monoid R] [has_continuous_add R]
{A : X → matrix n n R} (hA : continuous A) :
continuous (λ x, trace (A x)) :=
continuous_finset_sum _ $ λ i hi, hA.matrix_elem _ _
@[continuity]
lemma continuous.matrix_det [fintype n] [decidable_eq n] [comm_ring R] [topological_ring R]
{A : X → matrix n n R} (hA : continuous A) :
continuous (λ x, (A x).det) :=
begin
simp_rw matrix.det_apply,
refine continuous_finset_sum _ (λ l _, continuous.const_smul _ _),
refine continuous_finset_prod _ (λ l _, hA.matrix_elem _ _),
end
@[continuity]
lemma continuous.matrix_update_column [decidable_eq n] (i : n)
{A : X → matrix m n R} {B : X → m → R} (hA : continuous A) (hB : continuous B) :
continuous (λ x, (A x).update_column i (B x)) :=
continuous_matrix $ λ j k, (continuous_apply k).comp $
((continuous_apply _).comp hA).update i ((continuous_apply _).comp hB)
@[continuity]
lemma continuous.matrix_update_row [decidable_eq m] (i : m)
{A : X → matrix m n R} {B : X → n → R} (hA : continuous A) (hB : continuous B) :
continuous (λ x, (A x).update_row i (B x)) :=
hA.update i hB
@[continuity]
lemma continuous.matrix_cramer [fintype n] [decidable_eq n] [comm_ring R] [topological_ring R]
{A : X → matrix n n R} {B : X → n → R} (hA : continuous A) (hB : continuous B) :
continuous (λ x, (A x).cramer (B x)) :=
continuous_pi $ λ i, (hA.matrix_update_column _ hB).matrix_det
@[continuity]
lemma continuous.matrix_adjugate [fintype n] [decidable_eq n] [comm_ring R] [topological_ring R]
{A : X → matrix n n R} (hA : continuous A) :
continuous (λ x, (A x).adjugate) :=
continuous_matrix $ λ j k, (hA.matrix_transpose.matrix_update_column k continuous_const).matrix_det
/-- When `ring.inverse` is continuous at the determinant (such as in a `normed_ring`, or a
`topological_field`), so is `matrix.has_inv`. -/
lemma continuous_at_matrix_inv [fintype n] [decidable_eq n] [comm_ring R] [topological_ring R]
(A : matrix n n R) (h : continuous_at ring.inverse A.det) :
continuous_at has_inv.inv A :=
(h.comp continuous_id.matrix_det.continuous_at).smul continuous_id.matrix_adjugate.continuous_at
-- lemmas about functions in `data/matrix/block.lean`
section block_matrices
@[continuity]
lemma continuous.matrix_from_blocks
{A : X → matrix n l R} {B : X → matrix n m R} {C : X → matrix p l R} {D : X → matrix p m R}
(hA : continuous A) (hB : continuous B) (hC : continuous C) (hD : continuous D) :
continuous (λ x, matrix.from_blocks (A x) (B x) (C x) (D x)) :=
continuous_matrix $ λ i j,
by cases i; cases j; refine continuous.matrix_elem _ i j; assumption
@[continuity]
lemma continuous.matrix_block_diagonal [has_zero R] [decidable_eq p] {A : X → p → matrix m n R}
(hA : continuous A) :
continuous (λ x, block_diagonal (A x)) :=
continuous_matrix $ λ ⟨i₁, i₂⟩ ⟨j₁, j₂⟩,
(((continuous_apply i₂).comp hA).matrix_elem i₁ j₁).if_const _ continuous_zero
@[continuity]
lemma continuous.matrix_block_diag {A : X → matrix (m × p) (n × p) R} (hA : continuous A) :
continuous (λ x, block_diag (A x)) :=
continuous_pi $ λ i, continuous_matrix $ λ j k, hA.matrix_elem _ _
@[continuity]
lemma continuous.matrix_block_diagonal' [has_zero R] [decidable_eq l]
{A : X → Π i, matrix (m' i) (n' i) R} (hA : continuous A) :
continuous (λ x, block_diagonal' (A x)) :=
continuous_matrix $ λ ⟨i₁, i₂⟩ ⟨j₁, j₂⟩, begin
dsimp only [block_diagonal'],
split_ifs,
{ subst h,
exact ((continuous_apply i₁).comp hA).matrix_elem i₂ j₂ },
{ exact continuous_const },
end
@[continuity]
lemma continuous.matrix_block_diag' {A : X → matrix (Σ i, m' i) (Σ i, n' i) R} (hA : continuous A) :
continuous (λ x, block_diag' (A x)) :=
continuous_pi $ λ i, continuous_matrix $ λ j k, hA.matrix_elem _ _
end block_matrices
end continuity
/-! ### Lemmas about infinite sums -/
section tsum
variables [semiring α] [add_comm_monoid R] [topological_space R] [module α R]
lemma has_sum.matrix_transpose {f : X → matrix m n R} {a : matrix m n R} (hf : has_sum f a) :
has_sum (λ x, (f x)ᵀ) aᵀ :=
(hf.map (matrix.transpose_add_equiv m n R) continuous_id.matrix_transpose : _)
lemma summable.matrix_transpose {f : X → matrix m n R} (hf : summable f) :
summable (λ x, (f x)ᵀ) :=
hf.has_sum.matrix_transpose.summable
@[simp] lemma summable_matrix_transpose {f : X → matrix m n R} :
summable (λ x, (f x)ᵀ) ↔ summable f :=
(summable.map_iff_of_equiv (matrix.transpose_add_equiv m n R)
(@continuous_id (matrix m n R) _).matrix_transpose (continuous_id.matrix_transpose) : _)
lemma matrix.transpose_tsum [t2_space R] {f : X → matrix m n R} : (∑' x, f x)ᵀ = ∑' x, (f x)ᵀ :=
begin
by_cases hf : summable f,
{ exact hf.has_sum.matrix_transpose.tsum_eq.symm },
{ have hft := summable_matrix_transpose.not.mpr hf,
rw [tsum_eq_zero_of_not_summable hf, tsum_eq_zero_of_not_summable hft, transpose_zero] },
end
lemma has_sum.matrix_conj_transpose [star_add_monoid R] [has_continuous_star R]
{f : X → matrix m n R} {a : matrix m n R} (hf : has_sum f a) :
has_sum (λ x, (f x)ᴴ) aᴴ :=
(hf.map (matrix.conj_transpose_add_equiv m n R) continuous_id.matrix_conj_transpose : _)
lemma summable.matrix_conj_transpose [star_add_monoid R] [has_continuous_star R]
{f : X → matrix m n R} (hf : summable f) :
summable (λ x, (f x)ᴴ) :=
hf.has_sum.matrix_conj_transpose.summable
@[simp] lemma summable_matrix_conj_transpose [star_add_monoid R] [has_continuous_star R]
{f : X → matrix m n R} :
summable (λ x, (f x)ᴴ) ↔ summable f :=
(summable.map_iff_of_equiv (matrix.conj_transpose_add_equiv m n R)
(@continuous_id (matrix m n R) _).matrix_conj_transpose (continuous_id.matrix_conj_transpose) : _)
lemma matrix.conj_transpose_tsum [star_add_monoid R] [has_continuous_star R] [t2_space R]
{f : X → matrix m n R} : (∑' x, f x)ᴴ = ∑' x, (f x)ᴴ :=
begin
by_cases hf : summable f,
{ exact hf.has_sum.matrix_conj_transpose.tsum_eq.symm },
{ have hft := summable_matrix_conj_transpose.not.mpr hf,
rw [tsum_eq_zero_of_not_summable hf, tsum_eq_zero_of_not_summable hft, conj_transpose_zero] },
end
lemma has_sum.matrix_diagonal [decidable_eq n] {f : X → n → R} {a : n → R} (hf : has_sum f a) :
has_sum (λ x, diagonal (f x)) (diagonal a) :=
(hf.map (diagonal_add_monoid_hom n R) $ continuous.matrix_diagonal $ by exact continuous_id : _)
lemma summable.matrix_diagonal [decidable_eq n] {f : X → n → R} (hf : summable f) :
summable (λ x, diagonal (f x)) :=
hf.has_sum.matrix_diagonal.summable
@[simp] lemma summable_matrix_diagonal [decidable_eq n] {f : X → n → R} :
summable (λ x, diagonal (f x)) ↔ summable f :=
(summable.map_iff_of_left_inverse
(@matrix.diagonal_add_monoid_hom n R _ _) (matrix.diag_add_monoid_hom n R)
(by exact continuous.matrix_diagonal continuous_id)
continuous_matrix_diag
(λ A, diag_diagonal A) : _)
lemma matrix.diagonal_tsum [decidable_eq n] [t2_space R] {f : X → n → R} :
diagonal (∑' x, f x) = ∑' x, diagonal (f x) :=
begin
by_cases hf : summable f,
{ exact hf.has_sum.matrix_diagonal.tsum_eq.symm },
{ have hft := summable_matrix_diagonal.not.mpr hf,
rw [tsum_eq_zero_of_not_summable hf, tsum_eq_zero_of_not_summable hft],
exact diagonal_zero },
end
lemma has_sum.matrix_diag {f : X → matrix n n R} {a : matrix n n R} (hf : has_sum f a) :
has_sum (λ x, diag (f x)) (diag a) :=
(hf.map (diag_add_monoid_hom n R) continuous_matrix_diag : _)
lemma summable.matrix_diag {f : X → matrix n n R} (hf : summable f) : summable (λ x, diag (f x)) :=
hf.has_sum.matrix_diag.summable
section block_matrices
lemma has_sum.matrix_block_diagonal [decidable_eq p]
{f : X → p → matrix m n R} {a : p → matrix m n R} (hf : has_sum f a) :
has_sum (λ x, block_diagonal (f x)) (block_diagonal a) :=
(hf.map (block_diagonal_add_monoid_hom m n p R) $
continuous.matrix_block_diagonal $ by exact continuous_id : _)
lemma summable.matrix_block_diagonal [decidable_eq p] {f : X → p → matrix m n R} (hf : summable f) :
summable (λ x, block_diagonal (f x)) :=
hf.has_sum.matrix_block_diagonal.summable
lemma summable_matrix_block_diagonal [decidable_eq p] {f : X → p → matrix m n R} :
summable (λ x, block_diagonal (f x)) ↔ summable f :=
(summable.map_iff_of_left_inverse
(matrix.block_diagonal_add_monoid_hom m n p R) (matrix.block_diag_add_monoid_hom m n p R)
(by exact continuous.matrix_block_diagonal continuous_id)
(by exact continuous.matrix_block_diag continuous_id)
(λ A, block_diag_block_diagonal A) : _)
lemma matrix.block_diagonal_tsum [decidable_eq p] [t2_space R] {f : X → p → matrix m n R} :
block_diagonal (∑' x, f x) = ∑' x, block_diagonal (f x) :=
begin
by_cases hf : summable f,
{ exact hf.has_sum.matrix_block_diagonal.tsum_eq.symm },
{ have hft := summable_matrix_block_diagonal.not.mpr hf,
rw [tsum_eq_zero_of_not_summable hf, tsum_eq_zero_of_not_summable hft],
exact block_diagonal_zero },
end
lemma has_sum.matrix_block_diag {f : X → matrix (m × p) (n × p) R}
{a : matrix (m × p) (n × p) R} (hf : has_sum f a) :
has_sum (λ x, block_diag (f x)) (block_diag a) :=
(hf.map (block_diag_add_monoid_hom m n p R) $ continuous.matrix_block_diag continuous_id : _)
lemma summable.matrix_block_diag {f : X → matrix (m × p) (n × p) R} (hf : summable f) :
summable (λ x, block_diag (f x)) :=
hf.has_sum.matrix_block_diag.summable
lemma has_sum.matrix_block_diagonal' [decidable_eq l]
{f : X → Π i, matrix (m' i) (n' i) R} {a : Π i, matrix (m' i) (n' i) R} (hf : has_sum f a) :
has_sum (λ x, block_diagonal' (f x)) (block_diagonal' a) :=
(hf.map (block_diagonal'_add_monoid_hom m' n' R) $
continuous.matrix_block_diagonal' $ by exact continuous_id : _)
lemma summable.matrix_block_diagonal' [decidable_eq l]
{f : X → Π i, matrix (m' i) (n' i) R} (hf : summable f) :
summable (λ x, block_diagonal' (f x)) :=
hf.has_sum.matrix_block_diagonal'.summable
lemma summable_matrix_block_diagonal' [decidable_eq l] {f : X → Π i, matrix (m' i) (n' i) R} :
summable (λ x, block_diagonal' (f x)) ↔ summable f :=
(summable.map_iff_of_left_inverse
(matrix.block_diagonal'_add_monoid_hom m' n' R) (matrix.block_diag'_add_monoid_hom m' n' R)
(by exact continuous.matrix_block_diagonal' continuous_id)
(by exact continuous.matrix_block_diag' continuous_id)
(λ A, block_diag'_block_diagonal' A) : _)
lemma matrix.block_diagonal'_tsum [decidable_eq l] [t2_space R]
{f : X → Π i, matrix (m' i) (n' i) R} :
block_diagonal' (∑' x, f x) = ∑' x, block_diagonal' (f x) :=
begin
by_cases hf : summable f,
{ exact hf.has_sum.matrix_block_diagonal'.tsum_eq.symm },
{ have hft := summable_matrix_block_diagonal'.not.mpr hf,
rw [tsum_eq_zero_of_not_summable hf, tsum_eq_zero_of_not_summable hft],
exact block_diagonal'_zero },
end
lemma has_sum.matrix_block_diag' {f : X → matrix (Σ i, m' i) (Σ i, n' i) R}
{a : matrix (Σ i, m' i) (Σ i, n' i) R} (hf : has_sum f a) :
has_sum (λ x, block_diag' (f x)) (block_diag' a) :=
(hf.map (block_diag'_add_monoid_hom m' n' R) $ continuous.matrix_block_diag' continuous_id : _)
lemma summable.matrix_block_diag' {f : X → matrix (Σ i, m' i) (Σ i, n' i) R} (hf : summable f) :
summable (λ x, block_diag' (f x)) :=
hf.has_sum.matrix_block_diag'.summable
end block_matrices
end tsum
|
2d51bcada3377f13f8c44198da6dc62d5dc3528e | cf39355caa609c0f33405126beee2739aa3cb77e | /tests/lean/let3.lean | d313dd378487d659daa8f40e197f0804828e0402 | [
"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 | 142 | lean | --
constant f : nat → nat → nat → nat
#check
let a : nat := 10
in f a 10
/-
#check
let a := 10,
b := 10
in f a b 10
-/
|
85192c1af77f23cb1a5fbe6ae36607c3fc177e07 | 7da5ceac20aaab989eeb795a4be9639982e7b35a | /src/group_theory/classification.lean | f65339a842e806c2579e6b3d9fb3b6a8d300ba4c | [
"MIT"
] | permissive | formalabstracts/formalabstracts | 46c2f1b3a172e62ca6ffeb46fbbdf1705718af49 | b0173da1af45421239d44492eeecd54bf65ee0f6 | refs/heads/master | 1,606,896,370,374 | 1,572,988,776,000 | 1,572,988,776,000 | 96,763,004 | 165 | 28 | null | 1,555,709,319,000 | 1,499,680,948,000 | Lean | UTF-8 | Lean | false | false | 2,411 | lean | import .lie_type .sporadic_group
open nat monster
local infix ` ≅ `:60 := isomorphic
/-- Cyclic groups of prime order -/
structure is_cyclic_of_prime_order (G : Group) : Prop :=
(is_cyclic : is_cyclic G)
(is_finite : is_finite G)
(prime_order : prime (G.order is_finite))
/-- The finite simple alternating groups are the even permutations over a finite set with
more than 4 elements. -/
def is_simple_alternating_group (G : Group) : Prop :=
∃n > 4, G ≅ alternating_group n
/-- The simple groups of Lie type consist of the Chevalley groups, Steinberg groups, Ree groups, Suzuki groups and Tits groups -/
def is_of_lie_type (G : Group) : Prop :=
chevalley_group G ∨ steinberg_group G ∨ ree_group G ∨ suzuki_group G ∨ tits_group G
/-- The Mathieu groups are the first happy family of sporadic groups -/
def mathieu_group (G : Group) : Prop :=
G ≅ M11 ∨ G ≅ M12 ∨ G ≅ M22 ∨ G ≅ M23 ∨ G ≅ M24
/-- The second happy family of sporadic groups -/
def second_happy_family (G : Group) : Prop :=
G ≅ Co1 ∨ G ≅ Co2 ∨ G ≅ Co3 ∨ G ≅ McL ∨ G ≅ HS ∨ G ≅ J2 ∨ G ≅ Suz
/-- The third happy family of sporadic groups -/
def third_happy_family (G : Group) : Prop :=
G ≅ Monster ∨ G ≅ BabyMonster ∨ G ≅ Fi24' ∨ G ≅ Fi23 ∨ G ≅ Fi22 ∨ G ≅ Th ∨ G ≅ HN ∨ G ≅ He
/-- The pariahs -/
def pariah (G : Group) : Prop :=
G ≅ J1 ∨ G ≅ J3 ∨ G ≅ Ly ∨ G ≅ O'N ∨ G ≅ J4 ∨ G ≅ Ru
/-- The 26 sporadic groups are the finite simple groups which are not of Lie type -/
def is_sporadic_group (G : Group) : Prop :=
mathieu_group G ∨ second_happy_family G ∨ third_happy_family G ∨ pariah G
/- alternate way of writing this -/
-- inductive sporadic_group (G : Group) : Prop
-- | of_mathieu_group : mathieu_group G → sporadic_group
-- | of_second_happy_family : second_happy_family G → sporadic_group
-- | of_third_happy_family : third_happy_family G → sporadic_group
-- | of_pariah : pariah G → sporadic_group
variable {G : Group}
/-- The classification of finite simple groups: every finite simple group is cyclic, alternating, of Lie type or a sporadic group. -/
theorem classification_of_finite_simple_groups (h₁ : is_finite G) (h₂ : simple_group G) :
is_cyclic_of_prime_order G ∨
is_simple_alternating_group G ∨
is_of_lie_type G ∨
is_sporadic_group G :=
omitted
|
76eda497d09379526b65a86452a39a6068b89d92 | e61a235b8468b03aee0120bf26ec615c045005d2 | /src/Init/Lean/Data/KVMap.lean | 17cdbcfb8e95a8ce735ed65824bf71365d837d05 | [
"Apache-2.0"
] | permissive | SCKelemen/lean4 | 140dc63a80539f7c61c8e43e1c174d8500ec3230 | e10507e6615ddbef73d67b0b6c7f1e4cecdd82bc | refs/heads/master | 1,660,973,595,917 | 1,590,278,033,000 | 1,590,278,033,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 5,809 | lean | /-
Copyright (c) 2018 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
prelude
import Init.Data.Option.Basic
import Init.Data.Int
import Init.Lean.Data.Name
namespace Lean
inductive DataValue
| ofString (v : String)
| ofBool (v : Bool)
| ofName (v : Name)
| ofNat (v : Nat)
| ofInt (v : Int)
@[export lean_mk_bool_data_value] def mkBoolDataValueEx (b : Bool) : DataValue := DataValue.ofBool b
@[export lean_data_value_bool] def DataValue.getBoolEx : DataValue → Bool
| DataValue.ofBool b => b
| _ => false
def DataValue.beq : DataValue → DataValue → Bool
| DataValue.ofString s₁, DataValue.ofString s₂ => s₁ = s₂
| DataValue.ofNat n₁, DataValue.ofNat n₂ => n₂ = n₂
| DataValue.ofBool b₁, DataValue.ofBool b₂ => b₁ = b₂
| _, _ => false
def DataValue.sameCtor : DataValue → DataValue → Bool
| DataValue.ofString _, DataValue.ofString _ => true
| DataValue.ofBool _, DataValue.ofBool _ => true
| DataValue.ofName _, DataValue.ofName _ => true
| DataValue.ofNat _, DataValue.ofNat _ => true
| DataValue.ofInt _, DataValue.ofInt _ => true
| _, _ => false
instance DataValue.HasBeq : HasBeq DataValue := ⟨DataValue.beq⟩
@[export lean_data_value_to_string]
def DataValue.str : DataValue → String
| DataValue.ofString v => v
| DataValue.ofBool v => toString v
| DataValue.ofName v => toString v
| DataValue.ofNat v => toString v
| DataValue.ofInt v => toString v
instance DataValue.hasToString : HasToString DataValue := ⟨DataValue.str⟩
instance string2DataValue : HasCoe String DataValue := ⟨DataValue.ofString⟩
instance bool2DataValue : HasCoe Bool DataValue := ⟨DataValue.ofBool⟩
instance name2DataValue : HasCoe Name DataValue := ⟨DataValue.ofName⟩
instance nat2DataValue : HasCoe Nat DataValue := ⟨DataValue.ofNat⟩
instance int2DataValue : HasCoe Int DataValue := ⟨DataValue.ofInt⟩
/- Remark: we do not use RBMap here because we need to manipulate KVMap objects in
C++ and RBMap is implemented in Lean. So, we use just a List until we can
generate C++ code from Lean code. -/
structure KVMap :=
(entries : List (Name × DataValue) := [])
namespace KVMap
instance : Inhabited KVMap := ⟨{}⟩
instance : HasToString KVMap := ⟨fun m => toString m.entries⟩
def empty : KVMap :=
{}
def isEmpty : KVMap → Bool
| ⟨m⟩ => m.isEmpty
def size (m : KVMap) : Nat :=
m.entries.length
def findCore : List (Name × DataValue) → Name → Option DataValue
| [], k' => none
| (k,v)::m, k' => if k == k' then some v else findCore m k'
def find : KVMap → Name → Option DataValue
| ⟨m⟩, k => findCore m k
def findD (m : KVMap) (k : Name) (d₀ : DataValue) : DataValue :=
(m.find k).getD d₀
def insertCore : List (Name × DataValue) → Name → DataValue → List (Name × DataValue)
| [], k', v' => [(k',v')]
| (k,v)::m, k', v' => if k == k' then (k, v') :: m else (k, v) :: insertCore m k' v'
def insert : KVMap → Name → DataValue → KVMap
| ⟨m⟩, k, v => ⟨insertCore m k v⟩
def contains (m : KVMap) (n : Name) : Bool :=
(m.find n).isSome
def getString (m : KVMap) (k : Name) (defVal := "") : String :=
match m.find k with
| some (DataValue.ofString v) => v
| _ => defVal
def getNat (m : KVMap) (k : Name) (defVal := 0) : Nat :=
match m.find k with
| some (DataValue.ofNat v) => v
| _ => defVal
def getInt (m : KVMap) (k : Name) (defVal : Int := 0) : Int :=
match m.find k with
| some (DataValue.ofInt v) => v
| _ => defVal
def getBool (m : KVMap) (k : Name) (defVal := false) : Bool :=
match m.find k with
| some (DataValue.ofBool v) => v
| _ => defVal
def getName (m : KVMap) (k : Name) (defVal := Name.anonymous) : Name :=
match m.find k with
| some (DataValue.ofName v) => v
| _ => defVal
def setString (m : KVMap) (k : Name) (v : String) : KVMap :=
m.insert k (DataValue.ofString v)
def setNat (m : KVMap) (k : Name) (v : Nat) : KVMap :=
m.insert k (DataValue.ofNat v)
def setInt (m : KVMap) (k : Name) (v : Int) : KVMap :=
m.insert k (DataValue.ofInt v)
def setBool (m : KVMap) (k : Name) (v : Bool) : KVMap :=
m.insert k (DataValue.ofBool v)
def setName (m : KVMap) (k : Name) (v : Name) : KVMap :=
m.insert k (DataValue.ofName v)
def subsetAux : List (Name × DataValue) → KVMap → Bool
| [], m₂ => true
| (k, v₁)::m₁, m₂ =>
match m₂.find k with
| some v₂ => v₁ == v₂ && subsetAux m₁ m₂
| none => false
def subset : KVMap → KVMap → Bool
| ⟨m₁⟩, m₂ => subsetAux m₁ m₂
def eqv (m₁ m₂ : KVMap) : Bool :=
subset m₁ m₂ && subset m₂ m₁
instance : HasBeq KVMap := ⟨eqv⟩
class isKVMapVal (α : Type) :=
(defVal : α)
(set : KVMap → Name → α → KVMap)
(get : KVMap → Name → α → α)
export isKVMapVal (set)
@[inline] def get {α : Type} [isKVMapVal α] (m : KVMap) (k : Name) (defVal := isKVMapVal.defVal) : α :=
isKVMapVal.get m k defVal
instance boolVal : isKVMapVal Bool :=
{ defVal := false, set := setBool, get := fun k n v => getBool k n v }
instance natVal : isKVMapVal Nat :=
{ defVal := 0, set := setNat, get := fun k n v => getNat k n v }
instance intVal : isKVMapVal Int :=
{ defVal := 0, set := setInt, get := fun k n v => getInt k n v }
instance nameVal : isKVMapVal Name :=
{ defVal := Name.anonymous, set := setName, get := fun k n v => getName k n v }
instance stringVal : isKVMapVal String :=
{ defVal := "", set := setString, get := fun k n v => getString k n v }
end KVMap
end Lean
|
16ce1f39927d5ed1c3f7cd124d09aefc9fc775a2 | 737dc4b96c97368cb66b925eeea3ab633ec3d702 | /stage0/src/Lean/Meta/WHNF.lean | 6b6862c2aa7836dc09d0a6d3dbb9295f285c19ea | [
"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 | 24,871 | 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.ToExpr
import Lean.AuxRecursor
import Lean.ProjFns
import Lean.Meta.Basic
import Lean.Meta.LevelDefEq
import Lean.Meta.GetConst
import Lean.Meta.Match.MatcherInfo
namespace Lean.Meta
/- ===========================
Smart unfolding support
=========================== -/
def smartUnfoldingSuffix := "_sunfold"
@[inline] def mkSmartUnfoldingNameFor (declName : Name) : Name :=
Name.mkStr declName smartUnfoldingSuffix
register_builtin_option smartUnfolding : Bool := {
defValue := true
descr := "when computing weak head normal form, use auxiliary definition created for functions defined by structural recursion"
}
/- ===========================
Helper methods
=========================== -/
def isAuxDef (constName : Name) : MetaM Bool := do
let env ← getEnv
return isAuxRecursor env constName || isNoConfusion env constName
@[inline] private def matchConstAux {α} (e : Expr) (failK : Unit → MetaM α) (k : ConstantInfo → List Level → MetaM α) : MetaM α :=
match e with
| Expr.const name lvls _ => do
let (some cinfo) ← getConst? name | failK ()
k cinfo lvls
| _ => failK ()
/- ===========================
Helper functions for reducing recursors
=========================== -/
private def getFirstCtor (d : Name) : MetaM (Option Name) := do
let some (ConstantInfo.inductInfo { ctors := ctor::_, ..}) ← getConstNoEx? d | pure none
return some ctor
private def mkNullaryCtor (type : Expr) (nparams : Nat) : MetaM (Option Expr) := do
match type.getAppFn with
| Expr.const d lvls _ =>
let (some ctor) ← getFirstCtor d | pure none
return mkAppN (mkConst ctor lvls) (type.getAppArgs.shrink nparams)
| _ =>
return none
def toCtorIfLit : Expr → Expr
| Expr.lit (Literal.natVal v) _ =>
if v == 0 then mkConst `Nat.zero
else mkApp (mkConst `Nat.succ) (mkRawNatLit (v-1))
| Expr.lit (Literal.strVal v) _ =>
mkApp (mkConst `String.mk) (toExpr v.toList)
| e => e
private def getRecRuleFor (recVal : RecursorVal) (major : Expr) : Option RecursorRule :=
match major.getAppFn with
| Expr.const fn _ _ => recVal.rules.find? fun r => r.ctor == fn
| _ => none
private def toCtorWhenK (recVal : RecursorVal) (major : Expr) : MetaM (Option Expr) := do
let majorType ← inferType major
let majorType ← instantiateMVars (← whnf majorType)
let majorTypeI := majorType.getAppFn
if !majorTypeI.isConstOf recVal.getInduct then
return none
else if majorType.hasExprMVar && majorType.getAppArgs[recVal.numParams:].any Expr.hasExprMVar then
return none
else do
let (some newCtorApp) ← mkNullaryCtor majorType recVal.numParams | pure none
let newType ← inferType newCtorApp
if (← isDefEq majorType newType) then
return newCtorApp
else
return none
/-- Auxiliary function for reducing recursor applications. -/
private def reduceRec (recVal : RecursorVal) (recLvls : List Level) (recArgs : Array Expr) (failK : Unit → MetaM α) (successK : Expr → MetaM α) : MetaM α :=
let majorIdx := recVal.getMajorIdx
if h : majorIdx < recArgs.size then do
let major := recArgs.get ⟨majorIdx, h⟩
let mut major ← whnf major
if recVal.k then
let newMajor ← toCtorWhenK recVal major
major := newMajor.getD major
major := toCtorIfLit major
match getRecRuleFor recVal major with
| some rule =>
let majorArgs := major.getAppArgs
if recLvls.length != recVal.levelParams.length then
failK ()
else
let rhs := rule.rhs.instantiateLevelParams recVal.levelParams recLvls
-- Apply parameters, motives and minor premises from recursor application.
let rhs := mkAppRange rhs 0 (recVal.numParams+recVal.numMotives+recVal.numMinors) recArgs
/- The number of parameters in the constructor is not necessarily
equal to the number of parameters in the recursor when we have
nested inductive types. -/
let nparams := majorArgs.size - rule.nfields
let rhs := mkAppRange rhs nparams majorArgs.size majorArgs
let rhs := mkAppRange rhs (majorIdx + 1) recArgs.size recArgs
successK rhs
| none => failK ()
else
failK ()
/- ===========================
Helper functions for reducing Quot.lift and Quot.ind
=========================== -/
/-- Auxiliary function for reducing `Quot.lift` and `Quot.ind` applications. -/
private def reduceQuotRec (recVal : QuotVal) (recLvls : List Level) (recArgs : Array Expr) (failK : Unit → MetaM α) (successK : Expr → MetaM α) : MetaM α :=
let process (majorPos argPos : Nat) : MetaM α :=
if h : majorPos < recArgs.size then do
let major := recArgs.get ⟨majorPos, h⟩
let major ← whnf major
match major with
| Expr.app (Expr.app (Expr.app (Expr.const majorFn _ _) _ _) _ _) majorArg _ => do
let some (ConstantInfo.quotInfo { kind := QuotKind.ctor, .. }) ← getConstNoEx? majorFn | failK ()
let f := recArgs[argPos]
let r := mkApp f majorArg
let recArity := majorPos + 1
successK $ mkAppRange r recArity recArgs.size recArgs
| _ => failK ()
else
failK ()
match recVal.kind with
| QuotKind.lift => process 5 3
| QuotKind.ind => process 4 3
| _ => failK ()
/- ===========================
Helper function for extracting "stuck term"
=========================== -/
mutual
private partial def isRecStuck? (recVal : RecursorVal) (recLvls : List Level) (recArgs : Array Expr) : MetaM (Option MVarId) :=
if recVal.k then
-- TODO: improve this case
return none
else do
let majorIdx := recVal.getMajorIdx
if h : majorIdx < recArgs.size then do
let major := recArgs.get ⟨majorIdx, h⟩
let major ← whnf major
getStuckMVar? major
else
return none
private partial def isQuotRecStuck? (recVal : QuotVal) (recLvls : List Level) (recArgs : Array Expr) : MetaM (Option MVarId) :=
let process? (majorPos : Nat) : MetaM (Option MVarId) :=
if h : majorPos < recArgs.size then do
let major := recArgs.get ⟨majorPos, h⟩
let major ← whnf major
getStuckMVar? major
else
return none
match recVal.kind with
| QuotKind.lift => process? 5
| QuotKind.ind => process? 4
| _ => return none
/-- Return `some (Expr.mvar mvarId)` if metavariable `mvarId` is blocking reduction. -/
partial def getStuckMVar? : Expr → MetaM (Option MVarId)
| Expr.mdata _ e _ => getStuckMVar? e
| Expr.proj _ _ e _ => do getStuckMVar? (← whnf e)
| e@(Expr.mvar ..) => do
let e ← instantiateMVars e
match e with
| Expr.mvar mvarId _ => pure (some mvarId)
| _ => getStuckMVar? e
| e@(Expr.app f _ _) =>
let f := f.getAppFn
match f with
| Expr.mvar mvarId _ => return some mvarId
| Expr.const fName fLvls _ => do
let cinfo? ← getConstNoEx? fName
match cinfo? with
| some $ ConstantInfo.recInfo recVal => isRecStuck? recVal fLvls e.getAppArgs
| some $ ConstantInfo.quotInfo recVal => isQuotRecStuck? recVal fLvls e.getAppArgs
| _ => return none
| _ => return none
| _ => return none
end
/- ===========================
Weak Head Normal Form auxiliary combinators
=========================== -/
/-- Auxiliary combinator for handling easy WHNF cases. It takes a function for handling the "hard" cases as an argument -/
@[specialize] partial def whnfEasyCases (e : Expr) (k : Expr → MetaM Expr) : MetaM Expr := do
match e with
| Expr.forallE .. => return e
| Expr.lam .. => return e
| Expr.sort .. => return e
| Expr.lit .. => return e
| Expr.bvar .. => unreachable!
| Expr.letE .. => k e
| Expr.const .. => k e
| Expr.app .. => k e
| Expr.proj .. => k e
| Expr.mdata _ e _ => whnfEasyCases e k
| Expr.fvar fvarId _ =>
let decl ← getLocalDecl fvarId
match decl with
| LocalDecl.cdecl .. => return e
| LocalDecl.ldecl (value := v) (nonDep := nonDep) .. =>
let cfg ← getConfig
if nonDep && !cfg.zetaNonDep then
return e
else
if cfg.trackZeta then
modify fun s => { s with zetaFVarIds := s.zetaFVarIds.insert fvarId }
whnfEasyCases v k
| Expr.mvar mvarId _ =>
match (← getExprMVarAssignment? mvarId) with
| some v => whnfEasyCases v k
| none => return e
/-- Return true iff term is of the form `idRhs ...` -/
private def isIdRhsApp (e : Expr) : Bool :=
e.isAppOf `idRhs
/-- (@idRhs T f a_1 ... a_n) ==> (f a_1 ... a_n) -/
private def extractIdRhs (e : Expr) : Expr :=
if !isIdRhsApp e then e
else
let args := e.getAppArgs
if args.size < 2 then e
else mkAppRange args[1] 2 args.size args
@[specialize] private def deltaDefinition (c : ConstantInfo) (lvls : List Level)
(failK : Unit → α) (successK : Expr → α) : α :=
if c.levelParams.length != lvls.length then failK ()
else
let val := c.instantiateValueLevelParams lvls
successK (extractIdRhs val)
@[specialize] private def deltaBetaDefinition (c : ConstantInfo) (lvls : List Level) (revArgs : Array Expr)
(failK : Unit → α) (successK : Expr → α) : α :=
if c.levelParams.length != lvls.length then
failK ()
else
let val := c.instantiateValueLevelParams lvls
let val := val.betaRev revArgs
successK (extractIdRhs val)
inductive ReduceMatcherResult where
| reduced (val : Expr)
| stuck (val : Expr)
| notMatcher
| partialApp
def reduceMatcher? (e : Expr) : MetaM ReduceMatcherResult := do
match e.getAppFn with
| Expr.const declName declLevels _ =>
let some info ← getMatcherInfo? declName
| return ReduceMatcherResult.notMatcher
let args := e.getAppArgs
let prefixSz := info.numParams + 1 + info.numDiscrs
if args.size < prefixSz + info.numAlts then
return ReduceMatcherResult.partialApp
else
let constInfo ← getConstInfo declName
let f := constInfo.instantiateValueLevelParams declLevels
let auxApp := mkAppN f args[0:prefixSz]
let auxAppType ← inferType auxApp
forallBoundedTelescope auxAppType info.numAlts fun hs _ => do
let auxApp := mkAppN auxApp hs
/- When reducing `match` expressions, if the reducibility setting is at `TransparencyMode.reducible`,
we increase it to `TransparencyMode.instance`. We use the `TransparencyMode.reducible` in many places (e.g., `simp`),
and this setting prevents us from reducing `match` expressions where the discriminants are terms such as `OfNat.ofNat α n inst`.
For example, `simp [Int.div]` will not unfold the application `Int.div 2 1` occuring in the target.
TODO: consider other solutions; investigate whether the solution above produces counterintuitive behavior. -/
let mut transparency ← getTransparency
if transparency == TransparencyMode.reducible then
transparency := TransparencyMode.instances
let auxApp ← withTransparency transparency <| whnf auxApp
let auxAppFn := auxApp.getAppFn
let mut i := prefixSz
for h in hs do
if auxAppFn == h then
let result := mkAppN args[i] auxApp.getAppArgs
let result := mkAppN result args[prefixSz + info.numAlts:args.size]
return ReduceMatcherResult.reduced result.headBeta
i := i + 1
return ReduceMatcherResult.stuck auxApp
| _ => pure ReduceMatcherResult.notMatcher
/- Given an expression `e`, compute its WHNF and if the result is a constructor, return field #i. -/
def project? (e : Expr) (i : Nat) : MetaM (Option Expr) := do
let e ← whnf e
let e := toCtorIfLit e
matchConstCtor e.getAppFn (fun _ => pure none) fun ctorVal _ =>
let numArgs := e.getAppNumArgs
let idx := ctorVal.numParams + i
if idx < numArgs then
return some (e.getArg! idx)
else
return none
/-- Reduce kernel projection `Expr.proj ..` expression. -/
def reduceProj? (e : Expr) : MetaM (Option Expr) := do
match e with
| Expr.proj _ i c _ => project? c i
| _ => return none
/-
Auxiliary method for reducing terms of the form `?m t_1 ... t_n` where `?m` is delayed assigned.
Recall that we can only expand a delayed assignment when all holes/metavariables in the assigned value have been "filled".
-/
private def whnfDelayedAssigned? (f' : Expr) (e : Expr) : MetaM (Option Expr) := do
if f'.isMVar then
match (← getDelayedAssignment? f'.mvarId!) with
| none => return none
| some { fvars := fvars, val := val, .. } =>
let args := e.getAppArgs
if fvars.size > args.size then
-- Insufficient number of argument to expand delayed assignment
return none
else
let newVal ← instantiateMVars val
if newVal.hasExprMVar then
-- Delayed assignment still contains metavariables
return none
else
let newVal := newVal.abstract fvars
let result := newVal.instantiateRevRange 0 fvars.size args
return mkAppRange result fvars.size args.size args
else
return none
/--
Apply beta-reduction, zeta-reduction (i.e., unfold let local-decls), iota-reduction,
expand let-expressions, expand assigned meta-variables. -/
partial def whnfCore (e : Expr) : MetaM Expr :=
whnfEasyCases e fun e => do
trace[Meta.whnf] e
match e with
| Expr.const .. => pure e
| Expr.letE _ _ v b _ => whnfCore $ b.instantiate1 v
| Expr.app f .. =>
let f := f.getAppFn
let f' ← whnfCore f
if f'.isLambda then
let revArgs := e.getAppRevArgs
whnfCore <| f'.betaRev revArgs
else if let some eNew ← whnfDelayedAssigned? f' e then
whnfCore eNew
else
let e := if f == f' then e else e.updateFn f'
match (← reduceMatcher? e) with
| ReduceMatcherResult.reduced eNew => whnfCore eNew
| ReduceMatcherResult.partialApp => pure e
| ReduceMatcherResult.stuck _ => pure e
| ReduceMatcherResult.notMatcher =>
matchConstAux f' (fun _ => return e) fun cinfo lvls =>
match cinfo with
| ConstantInfo.recInfo rec => reduceRec rec lvls e.getAppArgs (fun _ => return e) whnfCore
| ConstantInfo.quotInfo rec => reduceQuotRec rec lvls e.getAppArgs (fun _ => return e) whnfCore
| c@(ConstantInfo.defnInfo _) => do
if (← isAuxDef c.name) then
deltaBetaDefinition c lvls e.getAppRevArgs (fun _ => return e) whnfCore
else
return e
| _ => return e
| Expr.proj .. => match (← reduceProj? e) with
| some e => whnfCore e
| none => return e
| _ => unreachable!
mutual
/-- Reduce `e` until `idRhs` application is exposed or it gets stuck.
This is a helper method for implementing smart unfolding. -/
private partial def whnfUntilIdRhs (e : Expr) : MetaM Expr := do
let e ← whnfCore e
match (← getStuckMVar? e) with
| some mvarId =>
/- Try to "unstuck" by resolving pending TC problems -/
if (← Meta.synthPending mvarId) then
whnfUntilIdRhs e
else
return e -- failed because metavariable is blocking reduction
| _ =>
if isIdRhsApp e then
return e -- done
else
match (← unfoldDefinition? e) with
| some e => whnfUntilIdRhs e
| none => pure e -- failed because of symbolic argument
/--
Auxiliary method for unfolding a class projection when transparency is set to `TransparencyMode.instances`.
Recall that class instance projections are not marked with `[reducible]` because we want them to be
in "reducible canonical form".
-/
private partial def unfoldProjInst (e : Expr) : MetaM (Option Expr) := do
if (← getTransparency) != TransparencyMode.instances then
return none
else
match e.getAppFn with
| Expr.const declName .. =>
match (← getProjectionFnInfo? declName) with
| some { fromClass := true, .. } =>
match (← withDefault <| unfoldDefinition? e) with
| none => return none
| some e =>
match (← reduceProj? e.getAppFn) with
| none => return none
| some r => return mkAppN r e.getAppArgs |>.headBeta
| _ => return none
| _ => return none
/-- Unfold definition using "smart unfolding" if possible. -/
partial def unfoldDefinition? (e : Expr) : MetaM (Option Expr) :=
match e with
| Expr.app f _ _ =>
matchConstAux f.getAppFn (fun _ => unfoldProjInst e) fun fInfo fLvls => do
if fInfo.levelParams.length != fLvls.length then
return none
else
let unfoldDefault (_ : Unit) : MetaM (Option Expr) :=
if fInfo.hasValue then
deltaBetaDefinition fInfo fLvls e.getAppRevArgs (fun _ => pure none) (fun e => pure (some e))
else
return none
if smartUnfolding.get (← getOptions) then
match (← getConstNoEx? (mkSmartUnfoldingNameFor fInfo.name)) with
| some fAuxInfo@(ConstantInfo.defnInfo _) =>
deltaBetaDefinition fAuxInfo fLvls e.getAppRevArgs (fun _ => pure none) fun e₁ => do
let e₂ ← whnfUntilIdRhs e₁
if isIdRhsApp e₂ then
return some (extractIdRhs e₂)
else
return none
| _ =>
if (← getMatcherInfo? fInfo.name).isSome then
-- Recall that `whnfCore` tries to reduce "matcher" applications.
return none
else
unfoldDefault ()
else
unfoldDefault ()
| Expr.const declName lvls _ => do
if smartUnfolding.get (← getOptions) && (← getEnv).contains (mkSmartUnfoldingNameFor declName) then
return none
else
let (some (cinfo@(ConstantInfo.defnInfo _))) ← getConstNoEx? declName | pure none
deltaDefinition cinfo lvls
(fun _ => pure none)
(fun e => pure (some e))
| _ => return none
end
def unfoldDefinition (e : Expr) : MetaM Expr := do
let some e ← unfoldDefinition? e | throwError "failed to unfold definition{indentExpr e}"
return e
@[specialize] partial def whnfHeadPred (e : Expr) (pred : Expr → MetaM Bool) : MetaM Expr :=
whnfEasyCases e fun e => do
let e ← whnfCore e
if (← pred e) then
match (← unfoldDefinition? e) with
| some e => whnfHeadPred e pred
| none => return e
else
return e
def whnfUntil (e : Expr) (declName : Name) : MetaM (Option Expr) := do
let e ← whnfHeadPred e (fun e => return !e.isAppOf declName)
if e.isAppOf declName then
return e
else
return none
/-- Try to reduce matcher/recursor/quot applications. We say they are all "morally" recursor applications. -/
def reduceRecMatcher? (e : Expr) : MetaM (Option Expr) := do
if !e.isApp then
return none
else match (← reduceMatcher? e) with
| ReduceMatcherResult.reduced e => return e
| _ => matchConstAux e.getAppFn (fun _ => pure none) fun cinfo lvls => do
match cinfo with
| ConstantInfo.recInfo «rec» => reduceRec «rec» lvls e.getAppArgs (fun _ => pure none) (fun e => pure (some e))
| ConstantInfo.quotInfo «rec» => reduceQuotRec «rec» lvls e.getAppArgs (fun _ => pure none) (fun e => pure (some e))
| c@(ConstantInfo.defnInfo _) =>
if (← isAuxDef c.name) then
deltaBetaDefinition c lvls e.getAppRevArgs (fun _ => pure none) (fun e => pure (some e))
else
return none
| _ => return none
unsafe def reduceBoolNativeUnsafe (constName : Name) : MetaM Bool := evalConstCheck Bool `Bool constName
unsafe def reduceNatNativeUnsafe (constName : Name) : MetaM Nat := evalConstCheck Nat `Nat constName
@[implementedBy reduceBoolNativeUnsafe] constant reduceBoolNative (constName : Name) : MetaM Bool
@[implementedBy reduceNatNativeUnsafe] constant reduceNatNative (constName : Name) : MetaM Nat
def reduceNative? (e : Expr) : MetaM (Option Expr) :=
match e with
| Expr.app (Expr.const fName _ _) (Expr.const argName _ _) _ =>
if fName == `Lean.reduceBool then do
return toExpr (← reduceBoolNative argName)
else if fName == `Lean.reduceNat then do
return toExpr (← reduceNatNative argName)
else
return none
| _ =>
return none
@[inline] def withNatValue {α} (a : Expr) (k : Nat → MetaM (Option α)) : MetaM (Option α) := do
let a ← whnf a
match a with
| Expr.const `Nat.zero _ _ => k 0
| Expr.lit (Literal.natVal v) _ => k v
| _ => return none
def reduceUnaryNatOp (f : Nat → Nat) (a : Expr) : MetaM (Option Expr) :=
withNatValue a fun a =>
return mkRawNatLit <| f a
def reduceBinNatOp (f : Nat → Nat → Nat) (a b : Expr) : MetaM (Option Expr) :=
withNatValue a fun a =>
withNatValue b fun b => do
trace[Meta.isDefEq.whnf.reduceBinOp] "{a} op {b}"
return mkRawNatLit <| f a b
def reduceBinNatPred (f : Nat → Nat → Bool) (a b : Expr) : MetaM (Option Expr) := do
withNatValue a fun a =>
withNatValue b fun b =>
return toExpr <| f a b
def reduceNat? (e : Expr) : MetaM (Option Expr) :=
if e.hasFVar || e.hasMVar then
return none
else match e with
| Expr.app (Expr.const fn _ _) a _ =>
if fn == `Nat.succ then
reduceUnaryNatOp Nat.succ a
else
return none
| Expr.app (Expr.app (Expr.const fn _ _) a1 _) a2 _ =>
if fn == `Nat.add then reduceBinNatOp Nat.add a1 a2
else if fn == `Nat.sub then reduceBinNatOp Nat.sub a1 a2
else if fn == `Nat.mul then reduceBinNatOp Nat.mul a1 a2
else if fn == `Nat.div then reduceBinNatOp Nat.div a1 a2
else if fn == `Nat.mod then reduceBinNatOp Nat.mod a1 a2
else if fn == `Nat.beq then reduceBinNatPred Nat.beq a1 a2
else if fn == `Nat.ble then reduceBinNatPred Nat.ble a1 a2
else return none
| _ =>
return none
@[inline] private def useWHNFCache (e : Expr) : MetaM Bool := do
-- We cache only closed terms without expr metavars.
-- Potential refinement: cache if `e` is not stuck at a metavariable
if e.hasFVar || e.hasExprMVar then
return false
else
match (← getConfig).transparency with
| TransparencyMode.default => true
| TransparencyMode.all => true
| _ => false
@[inline] private def cached? (useCache : Bool) (e : Expr) : MetaM (Option Expr) := do
if useCache then
match (← getConfig).transparency with
| TransparencyMode.default => return (← get).cache.whnfDefault.find? e
| TransparencyMode.all => return (← get).cache.whnfAll.find? e
| _ => unreachable!
else
return none
private def cache (useCache : Bool) (e r : Expr) : MetaM Expr := do
if useCache then
match (← getConfig).transparency with
| TransparencyMode.default => modify fun s => { s with cache.whnfDefault := s.cache.whnfDefault.insert e r }
| TransparencyMode.all => modify fun s => { s with cache.whnfAll := s.cache.whnfAll.insert e r }
| _ => unreachable!
return r
@[export lean_whnf]
partial def whnfImp (e : Expr) : MetaM Expr :=
withIncRecDepth <| whnfEasyCases e fun e => do
checkMaxHeartbeats "whnf"
let useCache ← useWHNFCache e
match (← cached? useCache e) with
| some e' => pure e'
| none =>
let e' ← whnfCore e
match (← reduceNat? e') with
| some v => cache useCache e v
| none =>
match (← reduceNative? e') with
| some v => cache useCache e v
| none =>
match (← unfoldDefinition? e') with
| some e => whnfImp e
| none => cache useCache e e'
/-- If `e` is a projection function that satisfies `p`, then reduce it -/
def reduceProjOf? (e : Expr) (p : Name → Bool) : MetaM (Option Expr) := do
if !e.isApp then
pure none
else match e.getAppFn with
| Expr.const name .. => do
let env ← getEnv
match env.getProjectionStructureName? name with
| some structName =>
if p structName then
Meta.unfoldDefinition? e
else
pure none
| none => pure none
| _ => pure none
builtin_initialize
registerTraceClass `Meta.whnf
end Lean.Meta
|
fe94b44d702761c9976f545f5c25372eea18d3dc | 82b86ba2ae0d5aed0f01f49c46db5afec0eb2bd7 | /src/Lean/Parser/Syntax.lean | e8118d4a5ebeb9de3eed67d4cb097483f6dd915c | [
"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,153 | 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.Command
import Lean.Parser.Tactic
namespace Lean
namespace Parser
builtin_initialize
registerBuiltinParserAttribute `builtinSyntaxParser `stx (leadingIdentAsSymbol := true)
builtin_initialize
registerBuiltinDynamicParserAttribute `stxParser `stx
@[inline] def syntaxParser (rbp : Nat := 0) : Parser :=
categoryParser `stx rbp
-- TODO: `max` is a bad precedence name. Find a new one.
def maxSymbol := parser! nonReservedSymbol "max" true
def precedenceLit : Parser := numLit <|> maxSymbol
def «precedence» := parser! ":" >> precedenceLit
def optPrecedence := optional («try» «precedence»)
namespace Syntax
@[builtinSyntaxParser] def paren := parser! "(" >> many1 syntaxParser >> ")"
@[builtinSyntaxParser] def cat := parser! ident >> optPrecedence
@[builtinSyntaxParser] def atom := parser! strLit
@[builtinSyntaxParser] def num := parser! nonReservedSymbol "num"
@[builtinSyntaxParser] def str := parser! nonReservedSymbol "str"
@[builtinSyntaxParser] def char := parser! nonReservedSymbol "char"
@[builtinSyntaxParser] def ident := parser! nonReservedSymbol "ident"
@[builtinSyntaxParser] def noWs := parser! nonReservedSymbol "noWs"
@[builtinSyntaxParser] def interpolatedStr := parser! nonReservedSymbol "interpolatedStr " >> syntaxParser maxPrec
@[builtinSyntaxParser] def «try» := parser! nonReservedSymbol "try " >> syntaxParser maxPrec
@[builtinSyntaxParser] def lookahead := parser! nonReservedSymbol "lookahead " >> syntaxParser maxPrec
def allowTrailingSep := parser! "(" >> nonReservedSymbol "allowTrailingSep" >> ":=" >> nonReservedSymbol "true" >> ")"
@[builtinSyntaxParser] def sepBy := parser! nonReservedSymbol "sepBy " >> optional allowTrailingSep >> syntaxParser maxPrec >> syntaxParser maxPrec
@[builtinSyntaxParser] def sepBy1 := parser! nonReservedSymbol "sepBy1 " >> optional allowTrailingSep >> syntaxParser maxPrec >> syntaxParser maxPrec
@[builtinSyntaxParser] def notFollowedBy := parser! nonReservedSymbol "notFollowedBy " >> syntaxParser maxPrec
@[builtinSyntaxParser] def withPosition := parser! nonReservedSymbol "withPosition " >> syntaxParser maxPrec
@[builtinSyntaxParser] def checkColGt := parser! ">" >> nonReservedSymbol "col"
@[builtinSyntaxParser] def checkColGe := parser! unicodeSymbol "≥" ">=" >> nonReservedSymbol "col"
@[builtinSyntaxParser] def optional := tparser! "?"
@[builtinSyntaxParser] def many := tparser! "*"
@[builtinSyntaxParser] def many1 := tparser! "+"
@[builtinSyntaxParser] def orelse := tparser!:2 " <|> " >> syntaxParser 1
end Syntax
namespace Term
@[builtinTermParser] def stx.quot : Parser := parser! "`(stx|" >> toggleInsideQuot syntaxParser >> ")"
end Term
namespace Command
def «prefix» := parser! "prefix"
def «infix» := parser! "infix"
def «infixl» := parser! "infixl"
def «infixr» := parser! "infixr"
def «postfix» := parser! "postfix"
def mixfixKind := «prefix» <|> «infix» <|> «infixl» <|> «infixr» <|> «postfix»
@[builtinCommandParser] def «mixfix» := parser! mixfixKind >> optPrecedence >> ppSpace >> strLit >> darrow >> termParser
-- NOTE: We use `suppressInsideQuot` in the following parsers because quotations inside them are evaluated in the same stage and
-- thus should be ignored when we use `checkInsideQuot` to prepare the next stage for a builtin syntax change
def identPrec := parser! ident >> optPrecedence
def optKind : Parser := optional ("[" >> ident >> "]")
def notationItem := ppSpace >> withAntiquot (mkAntiquot "notationItem" `Lean.Parser.Command.notationItem) (strLit <|> identPrec)
@[builtinCommandParser] def «notation» := parser! "notation" >> optPrecedence >> many notationItem >> darrow >> termParser
@[builtinCommandParser] def «macro_rules» := suppressInsideQuot (parser! "macro_rules" >> optKind >> Term.matchAlts)
def parserKind := parser! ident
def parserPrio := parser! numLit
def parserKindPrio := parser! «try» (ident >> ", ") >> numLit
def optKindPrio : Parser := optional ("[" >> (parserKindPrio <|> parserKind <|> parserPrio) >> "]")
@[builtinCommandParser] def «syntax» := parser! "syntax " >> optPrecedence >> optKindPrio >> many1 syntaxParser >> " : " >> ident
@[builtinCommandParser] def syntaxAbbrev := parser! "syntax " >> ident >> " := " >> many1 syntaxParser
@[builtinCommandParser] def syntaxCat := parser! "declare_syntax_cat " >> ident
def macroArgSimple := parser! ident >> checkNoWsBefore "no space before ':'" >> ":" >> syntaxParser maxPrec
def macroArg := «try» strLit <|> «try» macroArgSimple
def macroHead := macroArg <|> «try» ident
def macroTailTactic : Parser := «try» (" : " >> identEq "tactic") >> darrow >> ("`(" >> toggleInsideQuot Tactic.seq1 >> ")" <|> termParser)
def macroTailCommand : Parser := «try» (" : " >> identEq "command") >> darrow >> ("`(" >> toggleInsideQuot (many1Unbox commandParser) >> ")" <|> termParser)
def macroTailDefault : Parser := «try» (" : " >> ident) >> darrow >> (("`(" >> toggleInsideQuot (categoryParserOfStack 2) >> ")") <|> termParser)
def macroTail := macroTailTactic <|> macroTailCommand <|> macroTailDefault
def optPrio := optional ("[" >> numLit >> "]")
@[builtinCommandParser] def «macro» := parser! suppressInsideQuot ("macro " >> optPrecedence >> optPrio >> macroHead >> many macroArg >> macroTail)
@[builtinCommandParser] def «elab_rules» := parser! suppressInsideQuot ("elab_rules" >> optKind >> optional (" : " >> ident) >> Term.matchAlts)
def elabHead := macroHead
def elabArg := macroArg
def elabTail := «try» (" : " >> ident >> optional (" <= " >> ident)) >> darrow >> termParser
@[builtinCommandParser] def «elab» := parser! suppressInsideQuot ("elab " >> optPrecedence >> optPrio >> elabHead >> many elabArg >> elabTail)
end Command
end Parser
end Lean
|
b12053e017e3dd6cdba71b6b6c9e042787d2574c | 4d2583807a5ac6caaffd3d7a5f646d61ca85d532 | /src/measure_theory/group/basic.lean | bc78e622ebfc44d1141b8a2b04a0e7dadbae8998 | [
"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 | 20,403 | lean | /-
Copyright (c) 2020 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn
-/
import measure_theory.integral.lebesgue
import measure_theory.measure.regular
/-!
# Measures on Groups
We develop some properties of measures on (topological) groups
* We define properties on measures: left and right invariant measures.
* We define the measure `μ.inv : A ↦ μ(A⁻¹)` and show that it is right invariant iff
`μ` is left invariant.
* We define a class `is_haar_measure μ`, requiring that the measure `μ` is left-invariant, finite
on compact sets, and positive on open sets.
We also give analogues of all these notions in the additive world.
-/
noncomputable theory
open_locale ennreal pointwise big_operators
open has_inv set function measure_theory.measure
namespace measure_theory
variables {G : Type*}
section
variables [measurable_space G] [has_mul G]
/-- A measure `μ` on a topological group is left invariant
if the measure of left translations of a set are equal to the measure of the set itself.
To left translate sets we use preimage under left multiplication,
since preimages are nicer to work with than images. -/
@[to_additive "A measure on a topological group is left invariant
if the measure of left translations of a set are equal to the measure of the set itself.
To left translate sets we use preimage under left addition,
since preimages are nicer to work with than images."]
def is_mul_left_invariant (μ : set G → ℝ≥0∞) : Prop :=
∀ (g : G) {A : set G} (h : measurable_set A), μ ((λ h, g * h) ⁻¹' A) = μ A
/-- A measure `μ` on a topological group is right invariant
if the measure of right translations of a set are equal to the measure of the set itself.
To right translate sets we use preimage under right multiplication,
since preimages are nicer to work with than images. -/
@[to_additive "A measure on a topological group is right invariant
if the measure of right translations of a set are equal to the measure of the set itself.
To right translate sets we use preimage under right addition,
since preimages are nicer to work with than images."]
def is_mul_right_invariant (μ : set G → ℝ≥0∞) : Prop :=
∀ (g : G) {A : set G} (h : measurable_set A), μ ((λ h, h * g) ⁻¹' A) = μ A
@[to_additive measure_theory.is_add_left_invariant.smul]
lemma is_mul_left_invariant.smul {μ : measure G} (h : is_mul_left_invariant μ) (c : ℝ≥0∞) :
is_mul_left_invariant ((c • μ : measure G) : set G → ℝ≥0∞) :=
λ g A hA, by rw [smul_apply, smul_apply, h g hA]
@[to_additive measure_theory.is_add_right_invariant.smul]
lemma is_mul_right_invariant.smul {μ : measure G} (h : is_mul_right_invariant μ) (c : ℝ≥0∞) :
is_mul_right_invariant ((c • μ : measure G) : set G → ℝ≥0∞) :=
λ g A hA, by rw [smul_apply, smul_apply, h g hA]
end
namespace measure
variables [measurable_space G]
@[to_additive]
lemma map_mul_left_eq_self [topological_space G] [has_mul G] [has_continuous_mul G] [borel_space G]
{μ : measure G} : (∀ g, measure.map ((*) g) μ = μ) ↔ is_mul_left_invariant μ :=
begin
apply forall_congr, intro g, rw [measure.ext_iff], apply forall_congr, intro A,
apply forall_congr, intro hA, rw [map_apply (measurable_const_mul g) hA]
end
@[to_additive]
lemma _root_.measure_theory.is_mul_left_invariant.measure_preimage_mul
[topological_space G] [group G] [topological_group G] [borel_space G]
{μ : measure G} (h : is_mul_left_invariant μ) (g : G) (A : set G) :
μ ((λ h, g * h) ⁻¹' A) = μ A :=
calc μ ((λ h, g * h) ⁻¹' A) = measure.map (λ h, g * h) μ A :
((homeomorph.mul_left g).to_measurable_equiv.map_apply A).symm
... = μ A : by rw map_mul_left_eq_self.2 h g
@[to_additive]
lemma map_mul_right_eq_self [topological_space G] [has_mul G] [has_continuous_mul G] [borel_space G]
{μ : measure G} :
(∀ g, measure.map (λ h, h * g) μ = μ) ↔ is_mul_right_invariant μ :=
begin
apply forall_congr, intro g, rw [measure.ext_iff], apply forall_congr, intro A,
apply forall_congr, intro hA, rw [map_apply (measurable_mul_const g) hA]
end
/-- The measure `A ↦ μ (A⁻¹)`, where `A⁻¹` is the pointwise inverse of `A`. -/
@[to_additive "The measure `A ↦ μ (- A)`, where `- A` is the pointwise negation of `A`."]
protected def inv [has_inv G] (μ : measure G) : measure G :=
measure.map inv μ
variables [group G] [topological_space G] [topological_group G] [borel_space G]
@[to_additive]
lemma inv_apply (μ : measure G) {s : set G} (hs : measurable_set s) :
μ.inv s = μ s⁻¹ :=
measure.map_apply measurable_inv hs
@[simp, to_additive] protected lemma inv_inv (μ : measure G) : μ.inv.inv = μ :=
begin
ext1 s hs, rw [μ.inv.inv_apply hs, μ.inv_apply, set.inv_inv],
exact measurable_inv hs
end
variables {μ : measure G}
@[to_additive]
instance regular.inv [t2_space G] [regular μ] : regular μ.inv :=
regular.map (homeomorph.inv G)
end measure
section inv
variables [measurable_space G] [group G] [topological_space G] [topological_group G] [borel_space G]
{μ : measure G}
@[simp, to_additive] lemma regular_inv_iff [t2_space G] : μ.inv.regular ↔ μ.regular :=
begin
split,
{ introI h,
rw ←μ.inv_inv,
exact measure.regular.inv },
{ introI h,
exact measure.regular.inv }
end
@[to_additive]
lemma is_mul_left_invariant.inv (h : is_mul_left_invariant μ) :
is_mul_right_invariant μ.inv :=
begin
intros g A hA,
rw [μ.inv_apply (measurable_mul_const g hA), μ.inv_apply hA],
convert h g⁻¹ (measurable_inv hA) using 2,
simp only [←preimage_comp, ← inv_preimage],
apply preimage_congr,
intro h,
simp only [mul_inv_rev, comp_app, inv_inv]
end
@[to_additive]
lemma is_mul_right_invariant.inv (h : is_mul_right_invariant μ) : is_mul_left_invariant μ.inv :=
begin
intros g A hA,
rw [μ.inv_apply (measurable_const_mul g hA), μ.inv_apply hA],
convert h g⁻¹ (measurable_inv hA) using 2,
simp only [←preimage_comp, ← inv_preimage],
apply preimage_congr,
intro h,
simp only [mul_inv_rev, comp_app, inv_inv]
end
@[simp, to_additive]
lemma is_mul_right_invariant_inv : is_mul_right_invariant μ.inv ↔ is_mul_left_invariant μ :=
⟨λ h, by { rw ← μ.inv_inv, exact h.inv }, λ h, h.inv⟩
@[simp, to_additive]
lemma is_mul_left_invariant_inv : is_mul_left_invariant μ.inv ↔ is_mul_right_invariant μ :=
⟨λ h, by { rw ← μ.inv_inv, exact h.inv }, λ h, h.inv⟩
end inv
section group
variables [measurable_space G] [topological_space G] [borel_space G] {μ : measure G}
variables [group G] [topological_group G]
/-- If a left-invariant measure gives positive mass to a compact set, then
it gives positive mass to any open set. -/
@[to_additive]
lemma is_mul_left_invariant.measure_pos_of_is_open (hμ : is_mul_left_invariant μ)
(K : set G) (hK : is_compact K) (h : μ K ≠ 0) {U : set G} (hU : is_open U) (h'U : U.nonempty) :
0 < μ U :=
begin
contrapose! h,
rw ← nonpos_iff_eq_zero,
rw nonpos_iff_eq_zero at h,
rw ← hU.interior_eq at h'U,
obtain ⟨t, hKt⟩ : ∃ (t : finset G), K ⊆ ⋃ (g : G) (H : g ∈ t), (λ (h : G), g * h) ⁻¹' U :=
compact_covered_by_mul_left_translates hK h'U,
calc μ K ≤ μ (⋃ (g : G) (H : g ∈ t), (λ (h : G), g * h) ⁻¹' U) : measure_mono hKt
... ≤ ∑ g in t, μ ((λ (h : G), g * h) ⁻¹' U) : measure_bUnion_finset_le _ _
... = 0 : by simp [hμ _ hU.measurable_set, h]
end
/-! A nonzero left-invariant regular measure gives positive mass to any open set. -/
@[to_additive]
lemma is_mul_left_invariant.null_iff_empty [regular μ] (hμ : is_mul_left_invariant μ)
(h3μ : μ ≠ 0) {s : set G} (hs : is_open s) :
μ s = 0 ↔ s = ∅ :=
begin
obtain ⟨K, hK, h2K⟩ := regular.exists_compact_not_null.mpr h3μ,
refine ⟨λ h, _, λ h, by simp only [h, measure_empty]⟩,
contrapose h,
exact (hμ.measure_pos_of_is_open K hK h2K hs (ne_empty_iff_nonempty.mp h)).ne'
end
@[to_additive]
lemma is_mul_left_invariant.null_iff [regular μ] (h2μ : is_mul_left_invariant μ)
{s : set G} (hs : is_open s) :
μ s = 0 ↔ s = ∅ ∨ μ = 0 :=
begin
by_cases h3μ : μ = 0, { simp [h3μ] },
simp only [h3μ, or_false],
exact h2μ.null_iff_empty h3μ hs,
end
@[to_additive]
lemma is_mul_left_invariant.measure_ne_zero_iff_nonempty [regular μ]
(h2μ : is_mul_left_invariant μ) (h3μ : μ ≠ 0) {s : set G} (hs : is_open s) :
μ s ≠ 0 ↔ s.nonempty :=
by simp_rw [← ne_empty_iff_nonempty, ne.def, h2μ.null_iff_empty h3μ hs]
@[to_additive]
lemma is_mul_left_invariant.measure_pos_iff_nonempty [regular μ]
(h2μ : is_mul_left_invariant μ) (h3μ : μ ≠ 0) {s : set G} (hs : is_open s) :
0 < μ s ↔ s.nonempty :=
pos_iff_ne_zero.trans $ h2μ.measure_ne_zero_iff_nonempty h3μ hs
/-- If a left-invariant measure gives finite mass to a nonempty open set, then
it gives finite mass to any compact set. -/
@[to_additive]
lemma is_mul_left_invariant.measure_lt_top_of_is_compact (hμ : is_mul_left_invariant μ)
(U : set G) (hU : is_open U) (h'U : U.nonempty) (h : μ U ≠ ∞) {K : set G} (hK : is_compact K) :
μ K < ∞ :=
begin
rw ← hU.interior_eq at h'U,
obtain ⟨t, hKt⟩ : ∃ (t : finset G), K ⊆ ⋃ (g : G) (H : g ∈ t), (λ (h : G), g * h) ⁻¹' U :=
compact_covered_by_mul_left_translates hK h'U,
calc μ K ≤ μ (⋃ (g : G) (H : g ∈ t), (λ (h : G), g * h) ⁻¹' U) : measure_mono hKt
... ≤ ∑ g in t, μ ((λ (h : G), g * h) ⁻¹' U) : measure_bUnion_finset_le _ _
... = finset.card t * μ U : by simp only [hμ _ hU.measurable_set, finset.sum_const, nsmul_eq_mul]
... < ∞ : ennreal.mul_lt_top ennreal.coe_nat_ne_top h
end
/-- If a left-invariant measure gives finite mass to a set with nonempty interior, then
it gives finite mass to any compact set. -/
@[to_additive]
lemma is_mul_left_invariant.measure_lt_top_of_is_compact' (hμ : is_mul_left_invariant μ)
(U : set G) (hU : (interior U).nonempty) (h : μ U ≠ ∞) {K : set G} (hK : is_compact K) :
μ K < ∞ :=
hμ.measure_lt_top_of_is_compact (interior U) is_open_interior hU
((measure_mono (interior_subset)).trans_lt (lt_top_iff_ne_top.2 h)).ne hK
/-- For nonzero regular left invariant measures, the integral of a continuous nonnegative function
`f` is 0 iff `f` is 0. -/
@[to_additive]
lemma lintegral_eq_zero_of_is_mul_left_invariant [regular μ]
(h2μ : is_mul_left_invariant μ) (h3μ : μ ≠ 0) {f : G → ℝ≥0∞} (hf : continuous f) :
∫⁻ x, f x ∂μ = 0 ↔ f = 0 :=
begin
split, swap, { rintro rfl, simp_rw [pi.zero_apply, lintegral_zero] },
intro h, contrapose h,
simp_rw [funext_iff, not_forall, pi.zero_apply] at h, cases h with x hx,
obtain ⟨r, h1r, h2r⟩ : ∃ r : ℝ≥0∞, 0 < r ∧ r < f x :=
exists_between (pos_iff_ne_zero.mpr hx),
have h3r := hf.is_open_preimage (Ioi r) is_open_Ioi,
let s := Ioi r,
rw [← ne.def, ← pos_iff_ne_zero],
have : 0 < r * μ (f ⁻¹' Ioi r),
{ have : (f ⁻¹' Ioi r).nonempty, from ⟨x, h2r⟩,
simpa [h1r.ne', h2μ.measure_pos_iff_nonempty h3μ h3r, h1r] },
refine this.trans_le _,
rw [← set_lintegral_const, ← lintegral_indicator _ h3r.measurable_set],
apply lintegral_mono,
refine indicator_le (λ y, le_of_lt),
end
end group
section integration
variables [measurable_space G] [topological_space G] [borel_space G] {μ : measure G}
variables [group G] [has_continuous_mul G]
open measure
/-- Translating a function by left-multiplication does not change its `lintegral` with respect to
a left-invariant measure. -/
@[to_additive]
lemma lintegral_mul_left_eq_self (hμ : is_mul_left_invariant μ) (f : G → ℝ≥0∞) (g : G) :
∫⁻ x, f (g * x) ∂μ = ∫⁻ x, f x ∂μ :=
begin
have : measure.map (has_mul.mul g) μ = μ,
{ rw ← map_mul_left_eq_self at hμ,
exact hμ g },
convert (lintegral_map_equiv f (homeomorph.mul_left g).to_measurable_equiv).symm,
simp [this]
end
/-- Translating a function by right-multiplication does not change its `lintegral` with respect to
a right-invariant measure. -/
@[to_additive]
lemma lintegral_mul_right_eq_self (hμ : is_mul_right_invariant μ) (f : G → ℝ≥0∞) (g : G) :
∫⁻ x, f (x * g) ∂μ = ∫⁻ x, f x ∂μ :=
begin
have : measure.map (homeomorph.mul_right g) μ = μ,
{ rw ← map_mul_right_eq_self at hμ,
exact hμ g },
convert (lintegral_map_equiv f (homeomorph.mul_right g).to_measurable_equiv).symm,
simp [this]
end
end integration
section haar
namespace measure
/-- A measure on a group is a Haar measure if it is left-invariant, and gives finite mass to compact
sets and positive mass to open sets. -/
class is_haar_measure {G : Type*} [group G] [topological_space G] [measurable_space G]
(μ : measure G) : Prop :=
(left_invariant : is_mul_left_invariant μ)
(compact_lt_top : ∀ (K : set G), is_compact K → μ K < ∞)
(open_pos : ∀ (U : set G), is_open U → U.nonempty → 0 < μ U)
/-- A measure on an additive group is an additive Haar measure if it is left-invariant, and gives
finite mass to compact sets and positive mass to open sets. -/
class is_add_haar_measure {G : Type*} [add_group G] [topological_space G] [measurable_space G]
(μ : measure G) : Prop :=
(add_left_invariant : is_add_left_invariant μ)
(compact_lt_top : ∀ (K : set G), is_compact K → μ K < ∞)
(open_pos : ∀ (U : set G), is_open U → U.nonempty → 0 < μ U)
attribute [to_additive] is_haar_measure
section
variables [group G] [measurable_space G] [topological_space G] (μ : measure G) [is_haar_measure μ]
@[to_additive]
lemma _root_.is_compact.haar_lt_top {K : set G} (hK : is_compact K) :
μ K < ∞ :=
is_haar_measure.compact_lt_top K hK
@[to_additive]
lemma _root_.is_open.haar_pos {U : set G} (hU : is_open U) (h'U : U.nonempty) :
0 < μ U :=
is_haar_measure.open_pos U hU h'U
@[to_additive]
lemma haar_pos_of_nonempty_interior {U : set G} (hU : (interior U).nonempty) : 0 < μ U :=
lt_of_lt_of_le (is_open_interior.haar_pos μ hU) (measure_mono (interior_subset))
@[to_additive]
lemma is_mul_left_invariant_haar : is_mul_left_invariant μ :=
is_haar_measure.left_invariant
@[simp, to_additive]
lemma haar_preimage_mul [topological_group G] [borel_space G] (g : G) (A : set G) :
μ ((λ h, g * h) ⁻¹' A) = μ A :=
(is_mul_left_invariant_haar μ).measure_preimage_mul _ _
@[simp, to_additive]
lemma haar_singleton [topological_group G] [borel_space G] (g : G) :
μ {g} = μ {(1 : G)} :=
begin
convert haar_preimage_mul μ (g⁻¹) _,
simp only [mul_one, preimage_mul_left_singleton, inv_inv],
end
@[simp, to_additive]
lemma haar_preimage_mul_right {G : Type*}
[comm_group G] [measurable_space G] [topological_space G] (μ : measure G) [is_haar_measure μ]
[topological_group G] [borel_space G] (g : G) (A : set G) :
μ ((λ h, h * g) ⁻¹' A) = μ A :=
by simp_rw [mul_comm, haar_preimage_mul μ g A]
@[to_additive measure_theory.measure.is_add_haar_measure.smul]
lemma is_haar_measure.smul {c : ℝ≥0∞} (cpos : c ≠ 0) (ctop : c ≠ ∞) :
is_haar_measure (c • μ) :=
{ left_invariant := (is_mul_left_invariant_haar μ).smul _,
compact_lt_top := λ K hK, begin
change c * μ K < ∞,
simp [lt_top_iff_ne_top, (hK.haar_lt_top μ).ne, cpos, ctop],
end,
open_pos := λ U U_open U_ne, bot_lt_iff_ne_bot.2 $ begin
change c * μ U ≠ 0,
simp [cpos, (_root_.is_open.haar_pos μ U_open U_ne).ne'],
end }
/-- If a left-invariant measure gives positive mass to some compact set with nonempty interior, then
it is a Haar measure -/
@[to_additive]
lemma is_haar_measure_of_is_compact_nonempty_interior [topological_group G] [borel_space G]
(μ : measure G) (hμ : is_mul_left_invariant μ)
(K : set G) (hK : is_compact K) (h'K : (interior K).nonempty) (h : μ K ≠ 0) (h' : μ K ≠ ∞) :
is_haar_measure μ :=
{ left_invariant := hμ,
compact_lt_top := λ L hL, hμ.measure_lt_top_of_is_compact' _ h'K h' hL,
open_pos := λ U hU, hμ.measure_pos_of_is_open K hK h hU }
/-- The image of a Haar measure under a group homomorphism which is also a homeomorphism is again
a Haar measure. -/
@[to_additive]
lemma is_haar_measure_map [borel_space G] [topological_group G] {H : Type*} [group H]
[topological_space H] [measurable_space H] [borel_space H] [t2_space H] [topological_group H]
(f : G ≃* H) (hf : continuous f) (hfsymm : continuous f.symm) :
is_haar_measure (measure.map f μ) :=
{ left_invariant := begin
rw ← map_mul_left_eq_self,
assume h,
rw map_map (continuous_mul_left h).measurable hf.measurable,
conv_rhs { rw ← map_mul_left_eq_self.2 (is_mul_left_invariant_haar μ) (f.symm h) },
rw map_map hf.measurable (continuous_mul_left _).measurable,
congr' 2,
ext y,
simp only [mul_equiv.apply_symm_apply, comp_app, mul_equiv.map_mul],
end,
compact_lt_top := begin
assume K hK,
rw map_apply hf.measurable hK.measurable_set,
have : f.symm '' K = f ⁻¹' K := equiv.image_eq_preimage _ _,
rw ← this,
exact is_compact.haar_lt_top _ (hK.image hfsymm)
end,
open_pos := begin
assume U hU h'U,
rw map_apply hf.measurable hU.measurable_set,
refine (hU.preimage hf).haar_pos _ _,
have : f.symm '' U = f ⁻¹' U := equiv.image_eq_preimage _ _,
rw ← this,
simp [h'U],
end }
/-- A Haar measure on a sigma-compact space is sigma-finite. -/
@[priority 100, to_additive] -- see Note [lower instance priority]
instance is_haar_measure.sigma_finite
{G : Type*} [group G] [measurable_space G] [topological_space G] [sigma_compact_space G]
(μ : measure G) [μ.is_haar_measure] :
sigma_finite μ :=
⟨⟨{ set := compact_covering G,
set_mem := λ n, mem_univ _,
finite := λ n, is_compact.haar_lt_top μ $ is_compact_compact_covering G n,
spanning := Union_compact_covering G }⟩⟩
open_locale topological_space
open filter
/-- If the neutral element of a group is not isolated, then a Haar measure on this group has
no atom.
This applies in particular to show that an additive Haar measure on a nontrivial
finite-dimensional real vector space has no atom. -/
@[priority 100, to_additive]
instance is_haar_measure.has_no_atoms
{G : Type*} [group G] [measurable_space G] [topological_space G] [t1_space G]
[topological_group G] [locally_compact_space G] [borel_space G] [(𝓝[{(1 : G)}ᶜ] (1 : G)).ne_bot]
(μ : measure G) [μ.is_haar_measure] :
has_no_atoms μ :=
begin
suffices H : μ {(1 : G)} ≤ 0, by { constructor, simp [le_bot_iff.1 H] },
obtain ⟨K, K_compact, K_int⟩ : ∃ (K : set G), is_compact K ∧ (1 : G) ∈ interior K,
{ rcases exists_compact_subset is_open_univ (mem_univ (1 : G)) with ⟨K, hK⟩,
exact ⟨K, hK.1, hK.2.1⟩ },
have K_inf : set.infinite K := infinite_of_mem_nhds (1 : G) (mem_interior_iff_mem_nhds.1 K_int),
have μKlt : μ K ≠ ∞ := (K_compact.haar_lt_top μ).ne,
have I : ∀ (n : ℕ), μ {(1 : G)} ≤ μ K / n,
{ assume n,
obtain ⟨t, tK, tn⟩ : ∃ (t : finset G), ↑t ⊆ K ∧ t.card = n := K_inf.exists_subset_card_eq n,
have A : μ t ≤ μ K := measure_mono tK,
have B : μ t = n * μ {(1 : G)},
{ rw ← bUnion_of_singleton ↑t,
change μ (⋃ (x ∈ t), {x}) = n * μ {1},
rw @measure_bUnion_finset G G _ μ t (λ i, {i}),
{ simp only [tn, finset.sum_const, nsmul_eq_mul, haar_singleton] },
{ assume x hx y hy xy,
simp only [on_fun, xy.symm, mem_singleton_iff, not_false_iff, disjoint_singleton_right] },
{ assume b hb, exact measurable_set_singleton b } },
rw B at A,
rwa [ennreal.le_div_iff_mul_le _ (or.inr μKlt), mul_comm],
right,
apply ne_of_gt (haar_pos_of_nonempty_interior μ ⟨_, K_int⟩) },
have J : tendsto (λ (n : ℕ), μ K / n) at_top (𝓝 (μ K / ∞)) :=
ennreal.tendsto.const_div ennreal.tendsto_nat_nhds_top (or.inr μKlt),
simp only [ennreal.div_top] at J,
exact ge_of_tendsto' J I,
end
/- The above instance applies in particular to show that an additive Haar measure on a nontrivial
finite-dimensional real vector space has no atom. -/
example {E : Type*} [normed_group E] [normed_space ℝ E] [nontrivial E] [finite_dimensional ℝ E]
[measurable_space E] [borel_space E] (μ : measure E) [is_add_haar_measure μ] :
has_no_atoms μ := by apply_instance
end
end measure
end haar
end measure_theory
|
388fb02cec703b66bd8dffb49a66b2e0225af5e8 | 453dcd7c0d1ef170b0843a81d7d8caedc9741dce | /category/basic.lean | 4e057c19685d89c18b9f7ffd1bf3a16919f4509e | [
"Apache-2.0"
] | permissive | amswerdlow/mathlib | 9af77a1f08486d8fa059448ae2d97795bd12ec0c | 27f96e30b9c9bf518341705c99d641c38638dfd0 | refs/heads/master | 1,585,200,953,598 | 1,534,275,532,000 | 1,534,275,532,000 | 144,564,700 | 0 | 0 | null | 1,534,156,197,000 | 1,534,156,197,000 | null | UTF-8 | Lean | false | false | 3,488 | 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
Extends the theory on functors, applicatives and monads.
-/
universes u v
variables {α β γ : Type u}
notation a ` $< `:1 f:1 := f a
section functor
variables {f : Type u → Type v} [functor f] [is_lawful_functor f]
run_cmd mk_simp_attr `functor_norm
@[functor_norm] protected theorem map_map (m : α → β) (g : β → γ) (x : f α) :
g <$> (m <$> x) = (g ∘ m) <$> x :=
(comp_map _ _ _).symm
@[simp] theorem id_map' (x : f α) : (λa, a) <$> x = x := id_map _
end functor
section applicative
variables {f : Type u → Type v} [applicative f]
def mzip_with
{α₁ α₂ φ : Type u}
(g : α₁ → α₂ → f φ) :
Π (ma₁ : list α₁) (ma₂: list α₂), f (list φ)
| (x :: xs) (y :: ys) := (::) <$> g x y <*> mzip_with xs ys
| _ _ := pure []
def mzip_with' (g : α → β → f γ) : list α → list β → f punit
| (x :: xs) (y :: ys) := g x y *> mzip_with' xs ys
| [] _ := pure punit.star
| _ [] := pure punit.star
variables [is_lawful_applicative f]
attribute [functor_norm] seq_assoc pure_seq_eq_map
@[simp] theorem pure_id'_seq (x : f α) : pure (λx, x) <*> x = x :=
pure_id_seq x
variables [is_lawful_applicative f]
attribute [functor_norm] seq_assoc pure_seq_eq_map
@[functor_norm] theorem seq_map_assoc (x : f (α → β)) (g : γ → α) (y : f γ) :
(x <*> (g <$> y)) = (λ(m:α→β), m ∘ g) <$> x <*> y :=
begin
simp [(pure_seq_eq_map _ _).symm],
simp [seq_assoc, (comp_map _ _ _).symm, (∘)],
simp [pure_seq_eq_map]
end
@[functor_norm] theorem map_seq (g : β → γ) (x : f (α → β)) (y : f α) :
(g <$> (x <*> y)) = ((∘) g) <$> x <*> y :=
by simp [(pure_seq_eq_map _ _).symm]; simp [seq_assoc]
end applicative
-- TODO: setup `functor_norm` for `monad` laws
section monad
variables {m : Type u → Type v} [monad m] [is_lawful_monad m]
lemma map_bind (x : m α) {g : α → m β} {f : β → γ} : f <$> (x >>= g) = (x >>= λa, f <$> g a) :=
by rw [← bind_pure_comp_eq_map,bind_assoc]; simp [bind_pure_comp_eq_map]
lemma seq_bind_eq (x : m α) {g : β → m γ} {f : α → β} : (f <$> x) >>= g = (x >>= g ∘ f) :=
show bind (f <$> x) g = bind x (g ∘ f),
by rw [← bind_pure_comp_eq_map, bind_assoc]; simp [pure_bind]
lemma seq_eq_bind_map {x : m α} {f : m (α → β)} : f <*> x = (f >>= (<$> x)) :=
(bind_map_eq_seq m f x).symm
end monad
section alternative
variables {f : Type → Type v} [alternative f]
@[simp] theorem guard_true {h : decidable true} :
@guard f _ true h = pure () := by simp [guard]
@[simp] theorem guard_false {h : decidable false} :
@guard f _ false h = failure := by simp [guard]
end alternative
class is_comm_applicative (m : Type* → Type*) [applicative m] extends is_lawful_applicative m : Prop :=
(commutative_prod : ∀{α β} (a : m α) (b : m β), prod.mk <$> a <*> b = (λb a, (a, b)) <$> b <*> a)
lemma is_comm_applicative.commutative_map
{m : Type* → Type*} [applicative m] [is_comm_applicative m]
{α β γ} (a : m α) (b : m β) {f : α → β → γ} :
f <$> a <*> b = flip f <$> b <*> a :=
calc f <$> a <*> b = (λp:α×β, f p.1 p.2) <$> (prod.mk <$> a <*> b) :
by simp [seq_map_assoc, map_seq, seq_assoc, seq_pure, map_map]
... = (λb a, f a b) <$> b <*> a :
by rw [is_comm_applicative.commutative_prod];
simp [seq_map_assoc, map_seq, seq_assoc, seq_pure, map_map]
|
0e3697db14cbf32c415596267cac8ab6da97efcd | 69d4931b605e11ca61881fc4f66db50a0a875e39 | /src/data/polynomial/coeff.lean | 4ba24082a3dfcb8805b2e0b77e279bc0f914e1b6 | [
"Apache-2.0"
] | permissive | abentkamp/mathlib | d9a75d291ec09f4637b0f30cc3880ffb07549ee5 | 5360e476391508e092b5a1e5210bd0ed22dc0755 | refs/heads/master | 1,682,382,954,948 | 1,622,106,077,000 | 1,622,106,077,000 | 149,285,665 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 7,199 | lean | /-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Johannes Hölzl, Scott Morrison, Jens Wagemaker
-/
import data.polynomial.basic
import data.finset.nat_antidiagonal
/-!
# Theory of univariate polynomials
The theorems include formulas for computing coefficients, such as
`coeff_add`, `coeff_sum`, `coeff_mul`
-/
noncomputable theory
open finsupp finset add_monoid_algebra
open_locale big_operators
namespace polynomial
universes u v
variables {R : Type u} {S : Type v} {a b : R} {n m : ℕ}
variables [semiring R] {p q r : polynomial R}
section coeff
lemma coeff_one (n : ℕ) : coeff (1 : polynomial R) n = if 0 = n then 1 else 0 :=
coeff_monomial
@[simp]
lemma coeff_add (p q : polynomial R) (n : ℕ) : coeff (p + q) n = coeff p n + coeff q n :=
by { rcases p, rcases q, simp [coeff, add_to_finsupp] }
@[simp] lemma coeff_smul [semiring S] [module R S] (r : R) (p : polynomial S) (n : ℕ) :
coeff (r • p) n = r • coeff p n :=
by { rcases p, simp [coeff, smul_to_finsupp] }
lemma support_smul [semiring S] [module R S] (r : R) (p : polynomial S) :
support (r • p) ⊆ support p :=
begin
assume i hi,
simp [mem_support_iff] at hi ⊢,
contrapose! hi,
simp [hi]
end
variable (R)
/-- The nth coefficient, as a linear map. -/
def lcoeff (n : ℕ) : polynomial R →ₗ[R] R :=
{ to_fun := λ p, coeff p n,
map_add' := λ p q, coeff_add p q n,
map_smul' := λ r p, coeff_smul r p n }
variable {R}
@[simp] lemma lcoeff_apply (n : ℕ) (f : polynomial R) : lcoeff R n f = coeff f n := rfl
@[simp] lemma finset_sum_coeff {ι : Type*} (s : finset ι) (f : ι → polynomial R) (n : ℕ) :
coeff (∑ b in s, f b) n = ∑ b in s, coeff (f b) n :=
(s.sum_hom (λ q : polynomial R, lcoeff R n q)).symm
lemma coeff_sum [semiring S] (n : ℕ) (f : ℕ → R → polynomial S) :
coeff (p.sum f) n = p.sum (λ a b, coeff (f a b) n) :=
by { rcases p, simp [polynomial.sum, support, coeff] }
/-- Decomposes the coefficient of the product `p * q` as a sum
over `nat.antidiagonal`. A version which sums over `range (n + 1)` can be obtained
by using `finset.nat.sum_antidiagonal_eq_sum_range_succ`. -/
lemma coeff_mul (p q : polynomial R) (n : ℕ) :
coeff (p * q) n = ∑ x in nat.antidiagonal n, coeff p x.1 * coeff q x.2 :=
begin
rcases p, rcases q,
simp only [coeff, mul_to_finsupp],
exact add_monoid_algebra.mul_apply_antidiagonal p q n _ (λ x, nat.mem_antidiagonal)
end
@[simp] lemma mul_coeff_zero (p q : polynomial R) : coeff (p * q) 0 = coeff p 0 * coeff q 0 :=
by simp [coeff_mul]
lemma coeff_mul_X_zero (p : polynomial R) : coeff (p * X) 0 = 0 :=
by simp
lemma coeff_X_mul_zero (p : polynomial R) : coeff (X * p) 0 = 0 :=
by simp
lemma coeff_C_mul_X (x : R) (k n : ℕ) :
coeff (C x * X^k : polynomial R) n = if n = k then x else 0 :=
by { rw [← monomial_eq_C_mul_X, coeff_monomial], congr' 1, simp [eq_comm] }
@[simp] lemma coeff_C_mul (p : polynomial R) : coeff (C a * p) n = a * coeff p n :=
by { rcases p, simp only [C, monomial, monomial_fun, mul_to_finsupp, ring_hom.coe_mk,
coeff, add_monoid_algebra.single_zero_mul_apply p a n] }
lemma C_mul' (a : R) (f : polynomial R) : C a * f = a • f :=
by { ext, rw [coeff_C_mul, coeff_smul, smul_eq_mul] }
@[simp] lemma coeff_mul_C (p : polynomial R) (n : ℕ) (a : R) :
coeff (p * C a) n = coeff p n * a :=
by { rcases p, simp only [C, monomial, monomial_fun, mul_to_finsupp, ring_hom.coe_mk,
coeff, add_monoid_algebra.mul_single_zero_apply p a n] }
lemma coeff_X_pow (k n : ℕ) :
coeff (X^k : polynomial R) n = if n = k then 1 else 0 :=
by simp only [one_mul, ring_hom.map_one, ← coeff_C_mul_X]
@[simp]
lemma coeff_X_pow_self (n : ℕ) :
coeff (X^n : polynomial R) n = 1 :=
by simp [coeff_X_pow]
theorem coeff_mul_X_pow (p : polynomial R) (n d : ℕ) :
coeff (p * polynomial.X ^ n) (d + n) = coeff p d :=
begin
rw [coeff_mul, sum_eq_single (d,n), coeff_X_pow, if_pos rfl, mul_one],
{ rintros ⟨i,j⟩ h1 h2, rw [coeff_X_pow, if_neg, mul_zero], rintro rfl, apply h2,
rw [nat.mem_antidiagonal, add_right_cancel_iff] at h1, subst h1 },
{ exact λ h1, (h1 (nat.mem_antidiagonal.2 rfl)).elim }
end
lemma coeff_mul_X_pow' (p : polynomial R) (n d : ℕ) :
(p * X ^ n).coeff d = ite (n ≤ d) (p.coeff (d - n)) 0 :=
begin
split_ifs,
{ rw [←@nat.sub_add_cancel d n h, coeff_mul_X_pow, nat.add_sub_cancel] },
{ refine (coeff_mul _ _ _).trans (finset.sum_eq_zero (λ x hx, _)),
rw [coeff_X_pow, if_neg, mul_zero],
exact ne_of_lt (lt_of_le_of_lt (nat.le_of_add_le_right
(le_of_eq (finset.nat.mem_antidiagonal.mp hx))) (not_le.mp h)) },
end
@[simp] theorem coeff_mul_X (p : polynomial R) (n : ℕ) :
coeff (p * X) (n + 1) = coeff p n :=
by simpa only [pow_one] using coeff_mul_X_pow p 1 n
theorem mul_X_pow_eq_zero {p : polynomial R} {n : ℕ}
(H : p * X ^ n = 0) : p = 0 :=
ext $ λ k, (coeff_mul_X_pow p n k).symm.trans $ ext_iff.1 H (k+n)
lemma C_mul_X_pow_eq_monomial (c : R) (n : ℕ) : C c * X^n = monomial n c :=
by { ext1, rw [monomial_eq_smul_X, coeff_smul, coeff_C_mul, smul_eq_mul] }
lemma support_mul_X_pow (c : R) (n : ℕ) (H : c ≠ 0) : (C c * X^n).support = singleton n :=
by rw [C_mul_X_pow_eq_monomial, support_monomial n c H]
lemma support_C_mul_X_pow' {c : R} {n : ℕ} : (C c * X^n).support ⊆ singleton n :=
by { rw [C_mul_X_pow_eq_monomial], exact support_monomial' n c }
lemma C_dvd_iff_dvd_coeff (r : R) (φ : polynomial R) :
C r ∣ φ ↔ ∀ i, r ∣ φ.coeff i :=
begin
split,
{ rintros ⟨φ, rfl⟩ c, rw coeff_C_mul, apply dvd_mul_right },
{ intro h,
choose c hc using h,
classical,
let c' : ℕ → R := λ i, if i ∈ φ.support then c i else 0,
let ψ : polynomial R := ∑ i in φ.support, monomial i (c' i),
use ψ,
ext i,
simp only [ψ, c', coeff_C_mul, mem_support_iff, coeff_monomial,
finset_sum_coeff, finset.sum_ite_eq'],
split_ifs with hi hi,
{ rw hc },
{ rw [not_not] at hi, rwa mul_zero } },
end
lemma coeff_bit0_mul (P Q : polynomial R) (n : ℕ) :
coeff (bit0 P * Q) n = 2 * coeff (P * Q) n :=
by simp [bit0, add_mul]
lemma coeff_bit1_mul (P Q : polynomial R) (n : ℕ) :
coeff (bit1 P * Q) n = 2 * coeff (P * Q) n + coeff Q n :=
by simp [bit1, add_mul, coeff_bit0_mul]
end coeff
section cast
@[simp] lemma nat_cast_coeff_zero {n : ℕ} {R : Type*} [semiring R] :
(n : polynomial R).coeff 0 = n :=
begin
induction n with n ih,
{ simp, },
{ simp [ih], },
end
@[simp, norm_cast] theorem nat_cast_inj
{m n : ℕ} {R : Type*} [semiring R] [char_zero R] : (↑m : polynomial R) = ↑n ↔ m = n :=
begin
fsplit,
{ intro h,
apply_fun (λ p, p.coeff 0) at h,
simpa using h, },
{ rintro rfl, refl, },
end
@[simp] lemma int_cast_coeff_zero {i : ℤ} {R : Type*} [ring R] :
(i : polynomial R).coeff 0 = i :=
by cases i; simp
@[simp, norm_cast] theorem int_cast_inj
{m n : ℤ} {R : Type*} [ring R] [char_zero R] : (↑m : polynomial R) = ↑n ↔ m = n :=
begin
fsplit,
{ intro h,
apply_fun (λ p, p.coeff 0) at h,
simpa using h, },
{ rintro rfl, refl, },
end
end cast
end polynomial
|
7cf718a9efbc2643a1739256e101ea03916da691 | 3f7026ea8bef0825ca0339a275c03b911baef64d | /src/algebra/ordered_group.lean | 9f27dfb162d0b52a9d653adf8b16b993b82288f7 | [
"Apache-2.0"
] | permissive | rspencer01/mathlib | b1e3afa5c121362ef0881012cc116513ab09f18c | c7d36292c6b9234dc40143c16288932ae38fdc12 | refs/heads/master | 1,595,010,346,708 | 1,567,511,503,000 | 1,567,511,503,000 | 206,071,681 | 0 | 0 | Apache-2.0 | 1,567,513,643,000 | 1,567,513,643,000 | null | UTF-8 | Lean | false | false | 25,658 | lean | /-
Copyright (c) 2017 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Johannes Hölzl
Ordered monoids and groups.
-/
import algebra.group order.bounded_lattice tactic.basic
universe u
variable {α : Type u}
section old_structure_cmd
set_option old_structure_cmd true
/-- An ordered (additive) commutative monoid is a commutative monoid
with a partial order such that addition is an order embedding, i.e.
`a + b ≤ a + c ↔ b ≤ c`. These monoids are automatically cancellative. -/
class ordered_comm_monoid (α : Type*) extends add_comm_monoid α, partial_order α :=
(add_le_add_left : ∀ a b : α, a ≤ b → ∀ c : α, c + a ≤ c + b)
(lt_of_add_lt_add_left : ∀ a b c : α, a + b < a + c → b < c)
/-- A canonically ordered monoid is an ordered commutative monoid
in which the ordering coincides with the divisibility relation,
which is to say, `a ≤ b` iff there exists `c` with `b = a + c`.
This is satisfied by the natural numbers, for example, but not
the integers or other ordered groups. -/
class canonically_ordered_monoid (α : Type*) extends ordered_comm_monoid α, lattice.order_bot α :=
(le_iff_exists_add : ∀a b:α, a ≤ b ↔ ∃c, b = a + c)
end old_structure_cmd
section ordered_comm_monoid
variables [ordered_comm_monoid α] {a b c d : α}
lemma add_le_add_left' (h : a ≤ b) : c + a ≤ c + b :=
ordered_comm_monoid.add_le_add_left a b h c
lemma add_le_add_right' (h : a ≤ b) : a + c ≤ b + c :=
add_comm c a ▸ add_comm c b ▸ add_le_add_left' h
lemma lt_of_add_lt_add_left' : a + b < a + c → b < c :=
ordered_comm_monoid.lt_of_add_lt_add_left a b c
lemma add_le_add' (h₁ : a ≤ b) (h₂ : c ≤ d) : a + c ≤ b + d :=
le_trans (add_le_add_right' h₁) (add_le_add_left' h₂)
lemma le_add_of_nonneg_right' (h : b ≥ 0) : a ≤ a + b :=
have a + b ≥ a + 0, from add_le_add_left' h,
by rwa add_zero at this
lemma le_add_of_nonneg_left' (h : b ≥ 0) : a ≤ b + a :=
have 0 + a ≤ b + a, from add_le_add_right' h,
by rwa zero_add at this
lemma lt_of_add_lt_add_right' (h : a + b < c + b) : a < c :=
lt_of_add_lt_add_left'
(show b + a < b + c, begin rw [add_comm b a, add_comm b c], assumption end)
-- here we start using properties of zero.
lemma le_add_of_nonneg_of_le' (ha : 0 ≤ a) (hbc : b ≤ c) : b ≤ a + c :=
zero_add b ▸ add_le_add' ha hbc
lemma le_add_of_le_of_nonneg' (hbc : b ≤ c) (ha : 0 ≤ a) : b ≤ c + a :=
add_zero b ▸ add_le_add' hbc ha
lemma add_nonneg' (ha : 0 ≤ a) (hb : 0 ≤ b) : 0 ≤ a + b :=
le_add_of_nonneg_of_le' ha hb
lemma add_pos_of_pos_of_nonneg' (ha : 0 < a) (hb : 0 ≤ b) : 0 < a + b :=
lt_of_lt_of_le ha $ le_add_of_nonneg_right' hb
lemma add_pos' (ha : 0 < a) (hb : 0 < b) : 0 < a + b :=
add_pos_of_pos_of_nonneg' ha $ le_of_lt hb
lemma add_pos_of_nonneg_of_pos' (ha : 0 ≤ a) (hb : 0 < b) : 0 < a + b :=
lt_of_lt_of_le hb $ le_add_of_nonneg_left' ha
lemma add_nonpos' (ha : a ≤ 0) (hb : b ≤ 0) : a + b ≤ 0 :=
zero_add (0:α) ▸ (add_le_add' ha hb)
lemma add_le_of_nonpos_of_le' (ha : a ≤ 0) (hbc : b ≤ c) : a + b ≤ c :=
zero_add c ▸ add_le_add' ha hbc
lemma add_le_of_le_of_nonpos' (hbc : b ≤ c) (ha : a ≤ 0) : b + a ≤ c :=
add_zero c ▸ add_le_add' hbc ha
lemma add_neg_of_neg_of_nonpos' (ha : a < 0) (hb : b ≤ 0) : a + b < 0 :=
lt_of_le_of_lt (add_le_of_le_of_nonpos' (le_refl _) hb) ha
lemma add_neg_of_nonpos_of_neg' (ha : a ≤ 0) (hb : b < 0) : a + b < 0 :=
lt_of_le_of_lt (add_le_of_nonpos_of_le' ha (le_refl _)) hb
lemma add_neg' (ha : a < 0) (hb : b < 0) : a + b < 0 :=
add_neg_of_nonpos_of_neg' (le_of_lt ha) hb
lemma lt_add_of_nonneg_of_lt' (ha : 0 ≤ a) (hbc : b < c) : b < a + c :=
lt_of_lt_of_le hbc $ le_add_of_nonneg_left' ha
lemma lt_add_of_lt_of_nonneg' (hbc : b < c) (ha : 0 ≤ a) : b < c + a :=
lt_of_lt_of_le hbc $ le_add_of_nonneg_right' ha
lemma lt_add_of_pos_of_lt' (ha : 0 < a) (hbc : b < c) : b < a + c :=
lt_add_of_nonneg_of_lt' (le_of_lt ha) hbc
lemma lt_add_of_lt_of_pos' (hbc : b < c) (ha : 0 < a) : b < c + a :=
lt_add_of_lt_of_nonneg' hbc (le_of_lt ha)
lemma add_lt_of_nonpos_of_lt' (ha : a ≤ 0) (hbc : b < c) : a + b < c :=
lt_of_le_of_lt (add_le_of_nonpos_of_le' ha (le_refl _)) hbc
lemma add_lt_of_lt_of_nonpos' (hbc : b < c) (ha : a ≤ 0) : b + a < c :=
lt_of_le_of_lt (add_le_of_le_of_nonpos' (le_refl _) ha) hbc
lemma add_lt_of_neg_of_lt' (ha : a < 0) (hbc : b < c) : a + b < c :=
add_lt_of_nonpos_of_lt' (le_of_lt ha) hbc
lemma add_lt_of_lt_of_neg' (hbc : b < c) (ha : a < 0) : b + a < c :=
add_lt_of_lt_of_nonpos' hbc (le_of_lt ha)
lemma add_eq_zero_iff' (ha : 0 ≤ a) (hb : 0 ≤ b) : a + b = 0 ↔ a = 0 ∧ b = 0 :=
iff.intro
(assume hab : a + b = 0,
have a ≤ 0, from hab ▸ le_add_of_le_of_nonneg' (le_refl _) hb,
have a = 0, from le_antisymm this ha,
have b ≤ 0, from hab ▸ le_add_of_nonneg_of_le' ha (le_refl _),
have b = 0, from le_antisymm this hb,
and.intro ‹a = 0› ‹b = 0›)
(assume ⟨ha', hb'⟩, by rw [ha', hb', add_zero])
lemma bit0_pos {a : α} (h : 0 < a) : 0 < bit0 a :=
add_pos' h h
end ordered_comm_monoid
namespace units
instance [monoid α] [i : preorder α] : preorder (units α) :=
preorder.lift (coe : units α → α) i
@[simp] theorem coe_le_coe [monoid α] [preorder α] {a b : units α} :
(a : α) ≤ b ↔ a ≤ b := iff.rfl
@[simp] theorem coe_lt_coe [monoid α] [preorder α] {a b : units α} :
(a : α) < b ↔ a < b := iff.rfl
instance [monoid α] [i : partial_order α] : partial_order (units α) :=
partial_order.lift (coe : units α → α) (by ext) i
instance [monoid α] [i : linear_order α] : linear_order (units α) :=
linear_order.lift (coe : units α → α) (by ext) i
instance [monoid α] [i : decidable_linear_order α] : decidable_linear_order (units α) :=
decidable_linear_order.lift (coe : units α → α) (by ext) i
theorem max_coe [monoid α] [decidable_linear_order α] {a b : units α} :
(↑(max a b) : α) = max a b :=
by by_cases a ≤ b; simp [max, h]
theorem min_coe [monoid α] [decidable_linear_order α] {a b : units α} :
(↑(min a b) : α) = min a b :=
by by_cases a ≤ b; simp [min, h]
end units
namespace with_zero
open lattice
instance [preorder α] : preorder (with_zero α) := with_bot.preorder
instance [partial_order α] : partial_order (with_zero α) := with_bot.partial_order
instance [partial_order α] : order_bot (with_zero α) := with_bot.order_bot
instance [lattice α] : lattice (with_zero α) := with_bot.lattice
instance [linear_order α] : linear_order (with_zero α) := with_bot.linear_order
instance [decidable_linear_order α] :
decidable_linear_order (with_zero α) := with_bot.decidable_linear_order
def ordered_comm_monoid [ordered_comm_monoid α]
(zero_le : ∀ a : α, 0 ≤ a) : ordered_comm_monoid (with_zero α) :=
begin
suffices, refine {
add_le_add_left := this,
..with_zero.partial_order,
..with_zero.add_comm_monoid, .. },
{ intros a b c h,
have h' := lt_iff_le_not_le.1 h,
rw lt_iff_le_not_le at ⊢,
refine ⟨λ b h₂, _, λ h₂, h'.2 $ this _ _ h₂ _⟩,
cases h₂, cases c with c,
{ cases h'.2 (this _ _ bot_le a) },
{ refine ⟨_, rfl, _⟩,
cases a with a,
{ exact with_bot.some_le_some.1 h'.1 },
{ exact le_of_lt (lt_of_add_lt_add_left' $
with_bot.some_lt_some.1 h), } } },
{ intros a b h c ca h₂,
cases b with b,
{ rw le_antisymm h bot_le at h₂,
exact ⟨_, h₂, le_refl _⟩ },
cases a with a,
{ change c + 0 = some ca at h₂,
simp at h₂, simp [h₂],
exact ⟨_, rfl, by simpa using add_le_add_left' (zero_le b)⟩ },
{ simp at h,
cases c with c; change some _ = _ at h₂;
simp [-add_comm] at h₂; subst ca; refine ⟨_, rfl, _⟩,
{ exact h },
{ exact add_le_add_left' h } } }
end
end with_zero
namespace with_top
open lattice
instance [add_semigroup α] : add_semigroup (with_top α) :=
{ add := λ o₁ o₂, o₁.bind (λ a, o₂.map (λ b, a + b)),
..@additive.add_semigroup _ $ @with_zero.semigroup (multiplicative α) _ }
lemma coe_add [add_semigroup α] {a b : α} : ((a + b : α) : with_top α) = a + b := rfl
instance [add_comm_semigroup α] : add_comm_semigroup (with_top α) :=
{ ..@additive.add_comm_semigroup _ $
@with_zero.comm_semigroup (multiplicative α) _ }
instance [add_monoid α] : add_monoid (with_top α) :=
{ zero := some 0,
add := (+),
..@additive.add_monoid _ $ @with_zero.monoid (multiplicative α) _ }
instance [add_comm_monoid α] : add_comm_monoid (with_top α) :=
{ zero := 0,
add := (+),
..@additive.add_comm_monoid _ $
@with_zero.comm_monoid (multiplicative α) _ }
instance [ordered_comm_monoid α] : ordered_comm_monoid (with_top α) :=
begin
suffices, refine {
add_le_add_left := this,
..with_top.partial_order,
..with_top.add_comm_monoid, ..},
{ intros a b c h,
refine ⟨λ c h₂, _, λ h₂, h.2 $ this _ _ h₂ _⟩,
cases h₂, cases a with a,
{ exact (not_le_of_lt h).elim le_top },
cases b with b,
{ exact (not_le_of_lt h).elim le_top },
{ exact ⟨_, rfl, le_of_lt (lt_of_add_lt_add_left' $
with_top.some_lt_some.1 h)⟩ } },
{ intros a b h c cb h₂,
cases c with c, {cases h₂},
cases b with b; cases h₂,
cases a with a, {cases le_antisymm h le_top},
simp at h,
exact ⟨_, rfl, add_le_add_left' h⟩, }
end
@[simp] lemma zero_lt_top [ordered_comm_monoid α] : (0 : with_top α) < ⊤ :=
coe_lt_top 0
@[simp] lemma zero_lt_coe [ordered_comm_monoid α] (a : α) : (0 : with_top α) < a ↔ 0 < a :=
coe_lt_coe
@[simp] lemma add_top [ordered_comm_monoid α] : ∀{a : with_top α}, a + ⊤ = ⊤
| none := rfl
| (some a) := rfl
@[simp] lemma top_add [ordered_comm_monoid α] {a : with_top α} : ⊤ + a = ⊤ := rfl
lemma add_eq_top [ordered_comm_monoid α] (a b : with_top α) : a + b = ⊤ ↔ a = ⊤ ∨ b = ⊤ :=
by cases a; cases b; simp [none_eq_top, some_eq_coe, coe_add.symm]
lemma add_lt_top [ordered_comm_monoid α] (a b : with_top α) : a + b < ⊤ ↔ a < ⊤ ∧ b < ⊤ :=
begin
apply not_iff_not.1,
simp [lt_top_iff_ne_top, add_eq_top],
finish,
apply classical.dec _,
apply classical.dec _,
end
instance [canonically_ordered_monoid α] : canonically_ordered_monoid (with_top α) :=
{ le_iff_exists_add := assume a b,
match a, b with
| a, none := show a ≤ ⊤ ↔ ∃c, ⊤ = a + c, by simp; refine ⟨⊤, _⟩; cases a; refl
| (some a), (some b) := show (a:with_top α) ≤ ↑b ↔ ∃c:with_top α, ↑b = ↑a + c,
begin
simp [canonically_ordered_monoid.le_iff_exists_add, -add_comm],
split,
{ rintro ⟨c, rfl⟩, refine ⟨c, _⟩, simp [coe_add] },
{ exact assume h, match b, h with _, ⟨some c, rfl⟩ := ⟨_, rfl⟩ end }
end
| none, some b := show (⊤ : with_top α) ≤ b ↔ ∃c:with_top α, ↑b = ⊤ + c, by simp
end,
.. with_top.order_bot,
.. with_top.ordered_comm_monoid }
end with_top
namespace with_bot
open lattice
instance [add_semigroup α] : add_semigroup (with_bot α) := with_top.add_semigroup
instance [add_comm_semigroup α] : add_comm_semigroup (with_bot α) := with_top.add_comm_semigroup
instance [add_monoid α] : add_monoid (with_bot α) := with_top.add_monoid
instance [add_comm_monoid α] : add_comm_monoid (with_bot α) := with_top.add_comm_monoid
instance [ordered_comm_monoid α] : ordered_comm_monoid (with_bot α) :=
begin
suffices, refine {
add_le_add_left := this,
..with_bot.partial_order,
..with_bot.add_comm_monoid, ..},
{ intros a b c h,
have h' := h,
rw lt_iff_le_not_le at h' ⊢,
refine ⟨λ b h₂, _, λ h₂, h'.2 $ this _ _ h₂ _⟩,
cases h₂, cases a with a,
{ exact (not_le_of_lt h).elim bot_le },
cases c with c,
{ exact (not_le_of_lt h).elim bot_le },
{ exact ⟨_, rfl, le_of_lt (lt_of_add_lt_add_left' $
with_bot.some_lt_some.1 h)⟩ } },
{ intros a b h c ca h₂,
cases c with c, {cases h₂},
cases a with a; cases h₂,
cases b with b, {cases le_antisymm h bot_le},
simp at h,
exact ⟨_, rfl, add_le_add_left' h⟩, }
end
@[simp] lemma coe_zero [add_monoid α] : ((0 : α) : with_bot α) = 0 := rfl
@[simp] lemma coe_add [add_semigroup α] (a b : α) : ((a + b : α) : with_bot α) = a + b := rfl
@[simp] lemma bot_add [ordered_comm_monoid α] (a : with_bot α) : ⊥ + a = ⊥ := rfl
@[simp] lemma add_bot [ordered_comm_monoid α] (a : with_bot α) : a + ⊥ = ⊥ := by cases a; refl
instance has_one [has_one α] : has_one (with_bot α) := ⟨(1 : α)⟩
@[simp] lemma coe_one [has_one α] : ((1 : α) : with_bot α) = 1 := rfl
end with_bot
section canonically_ordered_monoid
variables [canonically_ordered_monoid α] {a b c d : α}
lemma le_iff_exists_add : a ≤ b ↔ ∃c, b = a + c :=
canonically_ordered_monoid.le_iff_exists_add a b
@[simp] lemma zero_le (a : α) : 0 ≤ a := le_iff_exists_add.mpr ⟨a, by simp⟩
lemma bot_eq_zero : (⊥ : α) = 0 :=
le_antisymm lattice.bot_le (zero_le ⊥)
@[simp] lemma add_eq_zero_iff : a + b = 0 ↔ a = 0 ∧ b = 0 :=
add_eq_zero_iff' (zero_le _) (zero_le _)
@[simp] lemma le_zero_iff_eq : a ≤ 0 ↔ a = 0 :=
iff.intro
(assume h, le_antisymm h (zero_le a))
(assume h, h ▸ le_refl a)
protected lemma zero_lt_iff_ne_zero : 0 < a ↔ a ≠ 0 :=
iff.intro ne_of_gt $ assume hne, lt_of_le_of_ne (zero_le _) hne.symm
lemma le_add_left (h : a ≤ c) : a ≤ b + c :=
calc a = 0 + a : by simp
... ≤ b + c : add_le_add' (zero_le _) h
lemma le_add_right (h : a ≤ b) : a ≤ b + c :=
calc a = a + 0 : by simp
... ≤ b + c : add_le_add' h (zero_le _)
instance with_zero.canonically_ordered_monoid :
canonically_ordered_monoid (with_zero α) :=
{ le_iff_exists_add := λ a b, begin
cases a with a,
{ exact iff_of_true lattice.bot_le ⟨b, (zero_add b).symm⟩ },
cases b with b,
{ exact iff_of_false
(mt (le_antisymm lattice.bot_le) (by simp))
(λ ⟨c, h⟩, by cases c; cases h) },
{ simp [le_iff_exists_add, -add_comm],
split; intro h; rcases h with ⟨c, h⟩,
{ exact ⟨some c, congr_arg some h⟩ },
{ cases c; cases h,
{ exact ⟨_, (add_zero _).symm⟩ },
{ exact ⟨_, rfl⟩ } } }
end,
bot := 0,
bot_le := assume a a' h, option.no_confusion h,
.. with_zero.ordered_comm_monoid zero_le }
end canonically_ordered_monoid
instance ordered_cancel_comm_monoid.to_ordered_comm_monoid
[H : ordered_cancel_comm_monoid α] : ordered_comm_monoid α :=
{ lt_of_add_lt_add_left := @lt_of_add_lt_add_left _ _, ..H }
section ordered_cancel_comm_monoid
variables [ordered_cancel_comm_monoid α] {a b c x y : α}
@[simp] lemma add_le_add_iff_left (a : α) {b c : α} : a + b ≤ a + c ↔ b ≤ c :=
⟨le_of_add_le_add_left, λ h, add_le_add_left h _⟩
@[simp] lemma add_le_add_iff_right (c : α) : a + c ≤ b + c ↔ a ≤ b :=
add_comm c a ▸ add_comm c b ▸ add_le_add_iff_left c
@[simp] lemma add_lt_add_iff_left (a : α) {b c : α} : a + b < a + c ↔ b < c :=
⟨lt_of_add_lt_add_left, λ h, add_lt_add_left h _⟩
@[simp] lemma add_lt_add_iff_right (c : α) : a + c < b + c ↔ a < b :=
add_comm c a ▸ add_comm c b ▸ add_lt_add_iff_left c
@[simp] lemma le_add_iff_nonneg_right (a : α) {b : α} : a ≤ a + b ↔ 0 ≤ b :=
have a + 0 ≤ a + b ↔ 0 ≤ b, from add_le_add_iff_left a,
by rwa add_zero at this
@[simp] lemma le_add_iff_nonneg_left (a : α) {b : α} : a ≤ b + a ↔ 0 ≤ b :=
by rw [add_comm, le_add_iff_nonneg_right]
@[simp] lemma lt_add_iff_pos_right (a : α) {b : α} : a < a + b ↔ 0 < b :=
have a + 0 < a + b ↔ 0 < b, from add_lt_add_iff_left a,
by rwa add_zero at this
@[simp] lemma lt_add_iff_pos_left (a : α) {b : α} : a < b + a ↔ 0 < b :=
by rw [add_comm, lt_add_iff_pos_right]
@[simp] lemma add_le_iff_nonpos_left : x + y ≤ y ↔ x ≤ 0 :=
by { convert add_le_add_iff_right y, rw [zero_add] }
@[simp] lemma add_le_iff_nonpos_right : x + y ≤ x ↔ y ≤ 0 :=
by { convert add_le_add_iff_left x, rw [add_zero] }
@[simp] lemma add_lt_iff_neg_right : x + y < y ↔ x < 0 :=
by { convert add_lt_add_iff_right y, rw [zero_add] }
@[simp] lemma add_lt_iff_neg_left : x + y < x ↔ y < 0 :=
by { convert add_lt_add_iff_left x, rw [add_zero] }
lemma add_eq_zero_iff_eq_zero_of_nonneg
(ha : 0 ≤ a) (hb : 0 ≤ b) : a + b = 0 ↔ a = 0 ∧ b = 0 :=
⟨λ hab : a + b = 0,
by split; apply le_antisymm; try {assumption};
rw ← hab; simp [ha, hb],
λ ⟨ha', hb'⟩, by rw [ha', hb', add_zero]⟩
lemma with_top.add_lt_add_iff_left :
∀{a b c : with_top α}, a < ⊤ → (a + c < a + b ↔ c < b)
| none := assume b c h, (lt_irrefl ⊤ h).elim
| (some a) :=
begin
assume b c h,
cases b; cases c;
simp [with_top.none_eq_top, with_top.some_eq_coe, with_top.coe_lt_top, with_top.coe_lt_coe],
{ rw [← with_top.coe_add], exact with_top.coe_lt_top _ },
{ rw [← with_top.coe_add, ← with_top.coe_add, with_top.coe_lt_coe],
exact add_lt_add_iff_left _ }
end
lemma with_top.add_lt_add_iff_right
{a b c : with_top α} : a < ⊤ → (c + a < b + a ↔ c < b) :=
by simpa [add_comm] using @with_top.add_lt_add_iff_left _ _ a b c
end ordered_cancel_comm_monoid
section ordered_comm_group
variables [ordered_comm_group α] {a b c : α}
lemma neg_neg_iff_pos {α : Type} [_inst_1 : ordered_comm_group α] {a : α} : -a < 0 ↔ 0 < a :=
⟨ pos_of_neg_neg, neg_neg_of_pos ⟩
@[simp] lemma neg_le_neg_iff : -a ≤ -b ↔ b ≤ a :=
have a + b + -a ≤ a + b + -b ↔ -a ≤ -b, from add_le_add_iff_left _,
by simp at this; simp [this]
lemma neg_le : -a ≤ b ↔ -b ≤ a :=
have -a ≤ -(-b) ↔ -b ≤ a, from neg_le_neg_iff,
by rwa neg_neg at this
lemma le_neg : a ≤ -b ↔ b ≤ -a :=
have -(-a) ≤ -b ↔ b ≤ -a, from neg_le_neg_iff,
by rwa neg_neg at this
@[simp] lemma neg_nonpos : -a ≤ 0 ↔ 0 ≤ a :=
have -a ≤ -0 ↔ 0 ≤ a, from neg_le_neg_iff,
by rwa neg_zero at this
@[simp] lemma neg_nonneg : 0 ≤ -a ↔ a ≤ 0 :=
have -0 ≤ -a ↔ a ≤ 0, from neg_le_neg_iff,
by rwa neg_zero at this
@[simp] lemma neg_lt_neg_iff : -a < -b ↔ b < a :=
have a + b + -a < a + b + -b ↔ -a < -b, from add_lt_add_iff_left _,
by simp at this; simp [this]
lemma neg_lt_zero : -a < 0 ↔ 0 < a :=
have -a < -0 ↔ 0 < a, from neg_lt_neg_iff,
by rwa neg_zero at this
lemma neg_pos : 0 < -a ↔ a < 0 :=
have -0 < -a ↔ a < 0, from neg_lt_neg_iff,
by rwa neg_zero at this
lemma neg_lt : -a < b ↔ -b < a :=
have -a < -(-b) ↔ -b < a, from neg_lt_neg_iff,
by rwa neg_neg at this
lemma lt_neg : a < -b ↔ b < -a :=
have -(-a) < -b ↔ b < -a, from neg_lt_neg_iff,
by rwa neg_neg at this
lemma sub_le_sub_iff_left (a : α) {b c : α} : a - b ≤ a - c ↔ c ≤ b :=
(add_le_add_iff_left _).trans neg_le_neg_iff
lemma sub_le_sub_iff_right (c : α) : a - c ≤ b - c ↔ a ≤ b :=
add_le_add_iff_right _
lemma sub_lt_sub_iff_left (a : α) {b c : α} : a - b < a - c ↔ c < b :=
(add_lt_add_iff_left _).trans neg_lt_neg_iff
lemma sub_lt_sub_iff_right (c : α) : a - c < b - c ↔ a < b :=
add_lt_add_iff_right _
@[simp] lemma sub_nonneg : 0 ≤ a - b ↔ b ≤ a :=
have a - a ≤ a - b ↔ b ≤ a, from sub_le_sub_iff_left a,
by rwa sub_self at this
@[simp] lemma sub_nonpos : a - b ≤ 0 ↔ a ≤ b :=
have a - b ≤ b - b ↔ a ≤ b, from sub_le_sub_iff_right b,
by rwa sub_self at this
@[simp] lemma sub_pos : 0 < a - b ↔ b < a :=
have a - a < a - b ↔ b < a, from sub_lt_sub_iff_left a,
by rwa sub_self at this
@[simp] lemma sub_lt_zero : a - b < 0 ↔ a < b :=
have a - b < b - b ↔ a < b, from sub_lt_sub_iff_right b,
by rwa sub_self at this
lemma le_neg_add_iff_add_le : b ≤ -a + c ↔ a + b ≤ c :=
have -a + (a + b) ≤ -a + c ↔ a + b ≤ c, from add_le_add_iff_left _,
by rwa neg_add_cancel_left at this
lemma le_sub_iff_add_le' : b ≤ c - a ↔ a + b ≤ c :=
by rw [sub_eq_add_neg, add_comm, le_neg_add_iff_add_le]
lemma le_sub_iff_add_le : a ≤ c - b ↔ a + b ≤ c :=
by rw [le_sub_iff_add_le', add_comm]
@[simp] lemma neg_add_le_iff_le_add : -b + a ≤ c ↔ a ≤ b + c :=
have -b + a ≤ -b + (b + c) ↔ a ≤ b + c, from add_le_add_iff_left _,
by rwa neg_add_cancel_left at this
lemma sub_le_iff_le_add' : a - b ≤ c ↔ a ≤ b + c :=
by rw [sub_eq_add_neg, add_comm, neg_add_le_iff_le_add]
lemma sub_le_iff_le_add : a - c ≤ b ↔ a ≤ b + c :=
by rw [sub_le_iff_le_add', add_comm]
@[simp] lemma add_neg_le_iff_le_add : a + -c ≤ b ↔ a ≤ b + c :=
sub_le_iff_le_add
@[simp] lemma add_neg_le_iff_le_add' : a + -b ≤ c ↔ a ≤ b + c :=
sub_le_iff_le_add'
lemma neg_add_le_iff_le_add' : -c + a ≤ b ↔ a ≤ b + c :=
by rw [neg_add_le_iff_le_add, add_comm]
@[simp] lemma neg_le_sub_iff_le_add : -b ≤ a - c ↔ c ≤ a + b :=
le_sub_iff_add_le.trans neg_add_le_iff_le_add'
lemma neg_le_sub_iff_le_add' : -a ≤ b - c ↔ c ≤ a + b :=
by rw [neg_le_sub_iff_le_add, add_comm]
lemma sub_le : a - b ≤ c ↔ a - c ≤ b :=
sub_le_iff_le_add'.trans sub_le_iff_le_add.symm
theorem le_sub : a ≤ b - c ↔ c ≤ b - a :=
le_sub_iff_add_le'.trans le_sub_iff_add_le.symm
@[simp] lemma lt_neg_add_iff_add_lt : b < -a + c ↔ a + b < c :=
have -a + (a + b) < -a + c ↔ a + b < c, from add_lt_add_iff_left _,
by rwa neg_add_cancel_left at this
lemma lt_sub_iff_add_lt' : b < c - a ↔ a + b < c :=
by rw [sub_eq_add_neg, add_comm, lt_neg_add_iff_add_lt]
lemma lt_sub_iff_add_lt : a < c - b ↔ a + b < c :=
by rw [lt_sub_iff_add_lt', add_comm]
@[simp] lemma neg_add_lt_iff_lt_add : -b + a < c ↔ a < b + c :=
have -b + a < -b + (b + c) ↔ a < b + c, from add_lt_add_iff_left _,
by rwa neg_add_cancel_left at this
lemma sub_lt_iff_lt_add' : a - b < c ↔ a < b + c :=
by rw [sub_eq_add_neg, add_comm, neg_add_lt_iff_lt_add]
lemma sub_lt_iff_lt_add : a - c < b ↔ a < b + c :=
by rw [sub_lt_iff_lt_add', add_comm]
lemma neg_add_lt_iff_lt_add_right : -c + a < b ↔ a < b + c :=
by rw [neg_add_lt_iff_lt_add, add_comm]
@[simp] lemma neg_lt_sub_iff_lt_add : -b < a - c ↔ c < a + b :=
lt_sub_iff_add_lt.trans neg_add_lt_iff_lt_add_right
lemma neg_lt_sub_iff_lt_add' : -a < b - c ↔ c < a + b :=
by rw [neg_lt_sub_iff_lt_add, add_comm]
lemma sub_lt : a - b < c ↔ a - c < b :=
sub_lt_iff_lt_add'.trans sub_lt_iff_lt_add.symm
theorem lt_sub : a < b - c ↔ c < b - a :=
lt_sub_iff_add_lt'.trans lt_sub_iff_add_lt.symm
lemma sub_le_self_iff (a : α) {b : α} : a - b ≤ a ↔ 0 ≤ b :=
sub_le_iff_le_add'.trans (le_add_iff_nonneg_left _)
lemma sub_lt_self_iff (a : α) {b : α} : a - b < a ↔ 0 < b :=
sub_lt_iff_lt_add'.trans (lt_add_iff_pos_left _)
end ordered_comm_group
namespace decidable_linear_ordered_comm_group
variables [s : decidable_linear_ordered_comm_group α]
include s
instance : decidable_linear_ordered_cancel_comm_monoid α :=
{ le_of_add_le_add_left := λ x y z, le_of_add_le_add_left,
add_left_cancel := λ x y z, add_left_cancel,
add_right_cancel := λ x y z, add_right_cancel,
..s }
lemma eq_of_abs_sub_nonpos {a b : α} (h : abs (a - b) ≤ 0) : a = b :=
eq_of_abs_sub_eq_zero (le_antisymm _ _ h (abs_nonneg (a - b)))
end decidable_linear_ordered_comm_group
set_option old_structure_cmd true
/-- This is not so much a new structure as a construction mechanism
for ordered groups, by specifying only the "positive cone" of the group. -/
class nonneg_comm_group (α : Type*) extends add_comm_group α :=
(nonneg : α → Prop)
(pos : α → Prop := λ a, nonneg a ∧ ¬ nonneg (neg a))
(pos_iff : ∀ a, pos a ↔ nonneg a ∧ ¬ nonneg (-a) . order_laws_tac)
(zero_nonneg : nonneg 0)
(add_nonneg : ∀ {a b}, nonneg a → nonneg b → nonneg (a + b))
(nonneg_antisymm : ∀ {a}, nonneg a → nonneg (-a) → a = 0)
namespace nonneg_comm_group
variable [s : nonneg_comm_group α]
include s
@[reducible] instance to_ordered_comm_group : ordered_comm_group α :=
{ le := λ a b, nonneg (b - a),
lt := λ a b, pos (b - a),
lt_iff_le_not_le := λ a b, by simp; rw [pos_iff]; simp,
le_refl := λ a, by simp [zero_nonneg],
le_trans := λ a b c nab nbc, by simp [-sub_eq_add_neg];
rw ← sub_add_sub_cancel; exact add_nonneg nbc nab,
le_antisymm := λ a b nab nba, eq_of_sub_eq_zero $
nonneg_antisymm nba (by rw neg_sub; exact nab),
add_le_add_left := λ a b nab c, by simpa [(≤), preorder.le] using nab,
add_lt_add_left := λ a b nab c, by simpa [(<), preorder.lt] using nab, ..s }
theorem nonneg_def {a : α} : nonneg a ↔ 0 ≤ a :=
show _ ↔ nonneg _, by simp
theorem pos_def {a : α} : pos a ↔ 0 < a :=
show _ ↔ pos _, by simp
theorem not_zero_pos : ¬ pos (0 : α) :=
mt pos_def.1 (lt_irrefl _)
theorem zero_lt_iff_nonneg_nonneg {a : α} :
0 < a ↔ nonneg a ∧ ¬ nonneg (-a) :=
pos_def.symm.trans (pos_iff α _)
theorem nonneg_total_iff :
(∀ a : α, nonneg a ∨ nonneg (-a)) ↔
(∀ a b : α, a ≤ b ∨ b ≤ a) :=
⟨λ h a b, by have := h (b - a); rwa [neg_sub] at this,
λ h a, by rw [nonneg_def, nonneg_def, neg_nonneg]; apply h⟩
def to_decidable_linear_ordered_comm_group
[decidable_pred (@nonneg α _)]
(nonneg_total : ∀ a : α, nonneg a ∨ nonneg (-a))
: decidable_linear_ordered_comm_group α :=
{ le := (≤),
lt := (<),
lt_iff_le_not_le := @lt_iff_le_not_le _ _,
le_refl := @le_refl _ _,
le_trans := @le_trans _ _,
le_antisymm := @le_antisymm _ _,
le_total := nonneg_total_iff.1 nonneg_total,
decidable_le := by apply_instance,
decidable_eq := by apply_instance,
decidable_lt := by apply_instance,
..@nonneg_comm_group.to_ordered_comm_group _ s }
end nonneg_comm_group
|
c1a56a816b535a8826276121cfa0ba739205bcd1 | 6432ea7a083ff6ba21ea17af9ee47b9c371760f7 | /tests/lean/run/rc_tests.lean | de32d5bdb1aba14b00082cf6d3fda465198b0aa5 | [
"Apache-2.0",
"LLVM-exception",
"NCSA",
"LGPL-3.0-only",
"LicenseRef-scancode-inner-net-2.0",
"BSD-3-Clause",
"LGPL-2.0-or-later",
"Spencer-94",
"LGPL-2.1-or-later",
"HPND",
"LicenseRef-scancode-pcre",
"ISC",
"LGPL-2.1-only",
"LicenseRef-scancode-other-permissive",
"SunPro",
"CMU-Mach"... | permissive | leanprover/lean4 | 4bdf9790294964627eb9be79f5e8f6157780b4cc | f1f9dc0f2f531af3312398999d8b8303fa5f096b | refs/heads/master | 1,693,360,665,786 | 1,693,350,868,000 | 1,693,350,868,000 | 129,571,436 | 2,827 | 311 | Apache-2.0 | 1,694,716,156,000 | 1,523,760,560,000 | Lean | UTF-8 | Lean | false | false | 1,127 | lean |
universe u v
-- set_option pp.binderTypes false
set_option pp.explicit true
set_option trace.compiler.llnf true
-- set_option trace.compiler.boxed true
namespace x1
def f (x : Bool) (y z : Nat) : Nat :=
match x with
| true => y
| false => z + y + y
end x1
namespace x2
def f (x : Nat) : Nat := x
end x2
namespace x3
def f (x y : Nat) : Nat := x
end x3
namespace x4
@[noinline] def h (x y : Nat) : Nat := x + y
def f1 (x y : Nat) : Nat :=
h x y
def f2 (x y : Nat) : Nat :=
h (h x y) (h y x)
def f3 (x y : Nat) : Nat :=
h (h x x) x
def f4 (x y : Nat) : Nat :=
h (h 1 0) x
def f5 (x y : Nat) : Nat :=
h (h 1 1) x
end x4
namespace x5
partial def myMap {α : Type u} {β : Type v} (f : α → β) : List α → List β
| [] => []
| x::xs => f x :: myMap f xs
end x5
namespace x6
@[noinline] def act : StateM Nat Unit :=
modify (fun a => a + 1)
def f : StateM Nat Unit :=
act *> act
end x6
namespace x7
inductive S
| v1 | v2 | v3
def foo : S → S × S
| S.v1 => (S.v2, S.v1)
| S.v2 => (S.v3, S.v2)
| S.v3 => (S.v1, S.v2)
end x7
namespace x8
def f (x : Nat) : List Nat :=
x :: x :: []
end x8
|
ddae60c95521514f9fa282fa7bfb544824815f83 | 6432ea7a083ff6ba21ea17af9ee47b9c371760f7 | /src/Init/Control/Basic.lean | d9e9218aaa218ab8fa88c9d47c462deb8d826544 | [
"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 | 9,739 | lean | /-
Copyright (c) 2020 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Leonardo de Moura, Sebastian Ullrich
-/
prelude
import Init.Core
universe u v w
@[reducible]
def Functor.mapRev {f : Type u → Type v} [Functor f] {α β : Type u} : f α → (α → β) → f β :=
fun a f => f <$> a
infixr:100 " <&> " => Functor.mapRev
@[always_inline, inline]
def Functor.discard {f : Type u → Type v} {α : Type u} [Functor f] (x : f α) : f PUnit :=
Functor.mapConst PUnit.unit x
export Functor (discard)
class Alternative (f : Type u → Type v) extends Applicative f : Type (max (u+1) v) where
failure : {α : Type u} → f α
orElse : {α : Type u} → f α → (Unit → f α) → f α
instance (f : Type u → Type v) (α : Type u) [Alternative f] : OrElse (f α) := ⟨Alternative.orElse⟩
variable {f : Type u → Type v} [Alternative f] {α : Type u}
export Alternative (failure)
@[always_inline, inline] def guard {f : Type → Type v} [Alternative f] (p : Prop) [Decidable p] : f Unit :=
if p then pure () else failure
@[always_inline, inline] def optional (x : f α) : f (Option α) :=
some <$> x <|> pure none
class ToBool (α : Type u) where
toBool : α → Bool
export ToBool (toBool)
instance : ToBool Bool where
toBool b := b
@[macro_inline] def bool {β : Type u} {α : Type v} [ToBool β] (f t : α) (b : β) : α :=
match toBool b with
| true => t
| false => f
@[macro_inline] def orM {m : Type u → Type v} {β : Type u} [Monad m] [ToBool β] (x y : m β) : m β := do
let b ← x
match toBool b with
| true => pure b
| false => y
infixr:30 " <||> " => orM
@[macro_inline] def andM {m : Type u → Type v} {β : Type u} [Monad m] [ToBool β] (x y : m β) : m β := do
let b ← x
match toBool b with
| true => y
| false => pure b
infixr:35 " <&&> " => andM
@[macro_inline] def notM {m : Type → Type v} [Applicative m] (x : m Bool) : m Bool :=
not <$> x
/-!
# How `MonadControl` works
There is a [tutorial by Alexis King](https://lexi-lambda.github.io/blog/2019/09/07/demystifying-monadbasecontrol/) that this docstring is based on.
Suppose we have `foo : ∀ α, IO α → IO α` and `bar : StateT σ IO β` (ie, `bar : σ → IO (σ × β)`).
We might want to 'map' `bar` by `foo`. Concretely we would write this as:
```lean
opaque foo : ∀ {α}, IO α → IO α
opaque bar : StateT σ IO β
def mapped_foo : StateT σ IO β := do
let s ← get
let (b, s') ← liftM <| foo <| StateT.run bar s
set s'
return b
```
This is fine but it's not going to generalise, what if we replace `StateT Nat IO` with a large tower of monad transformers?
We would have to rewrite the above to handle each of the `run` functions for each transformer in the stack.
Is there a way to generalise `run` as a kind of inverse of `lift`?
We have `lift : m α → StateT σ m α` for all `m`, but we also need to 'unlift' the state.
But `unlift : StateT σ IO α → IO α` can't be implemented. So we need something else.
If we look at the definition of `mapped_foo`, we see that `lift <| foo <| StateT.run bar s`
has the type `IO (σ × β)`. The key idea is that `σ × β` contains all of the information needed to reconstruct the state and the new value.
Now lets define some values to generalise `mapped_foo`:
- Write `IO (σ × β)` as `IO (stM β)`
- Write `StateT.run . s` as `mapInBase : StateT σ IO α → IO (stM β)`
- Define `restoreM : IO (stM α) → StateT σ IO α` as below
```lean
def stM (α : Type) := α × σ
def restoreM (x : IO (stM α)) : StateT σ IO α := do
let (a,s) ← liftM x
set s
return a
```
To get:
```lean
def mapped_foo' : StateT σ IO β := do
let s ← get
let mapInBase := fun z => StateT.run z s
restoreM <| foo <| mapInBase bar
```
and finally define
```lean
def control {α : Type}
(f : ({β : Type} → StateT σ IO β → IO (stM β)) → IO (stM α))
: StateT σ IO α := do
let s ← get
let mapInBase := fun {β} (z : StateT σ IO β) => StateT.run z s
let r : IO (stM α) := f mapInBase
restoreM r
```
Now we can write `mapped_foo` as:
```lean
def mapped_foo'' : StateT σ IO β :=
control (fun mapInBase => foo (mapInBase bar))
```
The core idea of `mapInBase` is that given any `β`, it runs an instance of
`StateT σ IO β` and 'packages' the result and state as `IO (stM β)` so that it can be piped through `foo`.
Once it's been through `foo` we can then unpack the state again with `restoreM`.
Hence we can apply `foo` to `bar` without losing track of the state.
Here `stM β = σ × β` is the 'packaged result state', but we can generalise:
if we have a tower `StateT σ₁ <| StateT σ₂ <| IO`, then the
composite packaged state is going to be `stM₁₂ β := σ₁ × σ₂ × β` or `stM₁₂ := stM₁ ∘ stM₂`.
`MonadControl m n` means that when programming in the monad `n`,
we can switch to a base monad `m` using `control`, just like with `liftM`.
In contrast to `liftM`, however, we also get a function `runInBase` that
allows us to "lower" actions in `n` into `m`.
This is really useful when we have large towers of monad transformers, as we do in the metaprogramming library.
For example there is a function `withNewMCtxDepthImp : MetaM α → MetaM α` that runs the input monad instance
in a new nested metavariable context. We can lift this to `withNewMctxDepth : n α → n α` using `MonadControlT MetaM n`
(`MonadControlT` is the transitive closure of `MonadControl`).
Which means that we can also run `withNewMctxDepth` in the `Tactic` monad without needing to
faff around with lifts and all the other boilerplate needed in `mapped_foo`.
## Relationship to `MonadFunctor`
A stricter form of `MonadControl` is `MonadFunctor`, which defines
`monadMap {α} : (∀ {β}, m β → m β) → n α → n α`. Using `monadMap` it is also possible to define `mapped_foo` above.
However there are some mappings which can't be derived using `MonadFunctor`. For example:
```lean,ignore
@[inline] def map1MetaM [MonadControlT MetaM n] [Monad n] (f : forall {α}, (β → MetaM α) → MetaM α) {α} (k : β → n α) : n α :=
control fun runInBase => f fun b => runInBase <| k b
@[inline] def map2MetaM [MonadControlT MetaM n] [Monad n] (f : forall {α}, (β → γ → MetaM α) → MetaM α) {α} (k : β → γ → n α) : n α :=
control fun runInBase => f fun b c => runInBase <| k b c
```
In `monadMap`, we can only 'run in base' a single computation in `n` into the base monad `m`.
Using `control` means that `runInBase` can be used multiple times.
-/
/-- MonadControl is a way of stating that the monad `m` can be 'run inside' the monad `n`.
This is the same as [`MonadBaseControl`](https://hackage.haskell.org/package/monad-control-1.0.3.1/docs/Control-Monad-Trans-Control.html#t:MonadBaseControl) in Haskell.
To learn about `MonadControl`, see the comment above this docstring.
-/
class MonadControl (m : semiOutParam (Type u → Type v)) (n : Type u → Type w) where
stM : Type u → Type u
liftWith : {α : Type u} → (({β : Type u} → n β → m (stM β)) → m α) → n α
restoreM : {α : Type u} → m (stM α) → n α
/-- Transitive closure of MonadControl. -/
class MonadControlT (m : Type u → Type v) (n : Type u → Type w) where
stM : Type u → Type u
liftWith : {α : Type u} → (({β : Type u} → n β → m (stM β)) → m α) → n α
restoreM {α : Type u} : stM α → n α
export MonadControlT (stM liftWith restoreM)
@[always_inline]
instance (m n o) [MonadControl n o] [MonadControlT m n] : MonadControlT m o where
stM α := stM m n (MonadControl.stM n o α)
liftWith f := MonadControl.liftWith fun x₂ => liftWith fun x₁ => f (x₁ ∘ x₂)
restoreM := MonadControl.restoreM ∘ restoreM
instance (m : Type u → Type v) [Pure m] : MonadControlT m m where
stM α := α
liftWith f := f fun x => x
restoreM x := pure x
@[always_inline, inline]
def controlAt (m : Type u → Type v) {n : Type u → Type w} [MonadControlT m n] [Bind n] {α : Type u}
(f : ({β : Type u} → n β → m (stM m n β)) → m (stM m n α)) : n α :=
liftWith f >>= restoreM
@[always_inline, inline]
def control {m : Type u → Type v} {n : Type u → Type w} [MonadControlT m n] [Bind n] {α : Type u}
(f : ({β : Type u} → n β → m (stM m n β)) → m (stM m n α)) : n α :=
controlAt m f
/--
Typeclass for the polymorphic `forM` operation described in the "do unchained" paper.
Remark:
- `γ` is a "container" type of elements of type `α`.
- `α` is treated as an output parameter by the typeclass resolution procedure.
That is, it tries to find an instance using only `m` and `γ`.
-/
class ForM (m : Type u → Type v) (γ : Type w₁) (α : outParam (Type w₂)) where
forM [Monad m] : γ → (α → m PUnit) → m PUnit
export ForM (forM)
/-- Left-to-right composition of Kleisli arrows. -/
@[always_inline]
def Bind.kleisliRight [Bind m] (f₁ : α → m β) (f₂ : β → m γ) (a : α) : m γ :=
f₁ a >>= f₂
/-- Right-to-left composition of Kleisli arrows. -/
@[always_inline]
def Bind.kleisliLeft [Bind m] (f₂ : β → m γ) (f₁ : α → m β) (a : α) : m γ :=
f₁ a >>= f₂
/-- Same as `Bind.bind` but with arguments swapped. -/
@[always_inline]
def Bind.bindLeft [Bind m] (f : α → m β) (ma : m α) : m β :=
ma >>= f
-- Precedence choice taken to be the same as in haskell:
-- https://hackage.haskell.org/package/base-4.17.0.0/docs/Control-Monad.html#v:-61--60--60-
@[inherit_doc] infixr:55 " >=> " => Bind.kleisliRight
@[inherit_doc] infixr:55 " <=< " => Bind.kleisliLeft
@[inherit_doc] infixr:55 " =<< " => Bind.bindLeft
|
70b8698beae9139b5ff72d4f3921600c00c1d01a | 82e44445c70db0f03e30d7be725775f122d72f3e | /src/set_theory/schroeder_bernstein.lean | 4aca6f87c4358ef1f8c5c81ac98177ab4df604cc | [
"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 | 6,245 | 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 order.fixed_points
import order.zorn
/-!
# Schröder-Bernstein theorem, well-ordering of cardinals
This file proves the Schröder-Bernstein theorem (see `schroeder_bernstein`), the well-ordering of
cardinals (see `min_injective`) and the totality of their order (see `total`).
## Notes
Cardinals are naturally ordered by `α ≤ β ↔ ∃ f : a → β, injective f`:
* `schroeder_bernstein` states that, given injections `α → β` and `β → α`, one can get a
bijection `α → β`. This corresponds to the antisymmetry of the order.
* The order is also well-founded: any nonempty set of cardinals has a minimal element.
`min_injective` states that by saying that there exists an element of the set that injects into
all others.
Cardinals are defined and further developed in the file `set_theory.cardinal`.
-/
open set classical
open_locale classical
universes u v
namespace function
namespace embedding
section antisymm
variables {α : Type u} {β : Type v}
/-- **The Schröder-Bernstein Theorem**:
Given injections `α → β` and `β → α`, we can get a bijection `α → β`. -/
theorem schroeder_bernstein {f : α → β} {g : β → α}
(hf : function.injective f) (hg : function.injective g) : ∃ h : α → β, bijective h :=
let s : set α := lfp $ λ s, (g '' (f '' s)ᶜ)ᶜ in
have hs : (g '' (f '' s)ᶜ)ᶜ = s,
from lfp_fixed_point (λ x y hxy, compl_subset_compl.mpr $ image_subset _ $
compl_subset_compl.mpr $ image_subset _ hxy : monotone (λ s, (g '' (f '' s)ᶜ)ᶜ)),
have hns : sᶜ = g '' (f '' s)ᶜ,
from compl_injective $ by simp [hs],
let g' := λ a, @inv_fun β ⟨f a⟩ α g a in
have g'g : g' ∘ g = id,
from funext $ λ b, @left_inverse_inv_fun _ ⟨f (g b)⟩ _ _ hg b,
have hg'ns : g' '' sᶜ = (f '' s)ᶜ,
by rw [hns, ←image_comp, g'g, image_id],
let h := λ a, if a ∈ s then f a else g' a in
have h '' univ = univ,
from calc h '' univ = h '' s ∪ h '' sᶜ : by rw [←image_union, union_compl_self]
... = f '' s ∪ g' '' sᶜ :
congr (congr_arg (∪)
(image_congr $ by simp [h, if_pos] {contextual := tt}))
(image_congr $ by simp [h, if_neg] {contextual := tt})
... = univ : by rw [hg'ns, union_compl_self],
have surjective h,
from λ b,
have b ∈ h '' univ, by rw [this]; trivial,
let ⟨a, _, eq⟩ := this in
⟨a, eq⟩,
have split : ∀ x ∈ s, ∀ y ∉ s, h x = h y → false,
from λ x hx y hy eq,
have y ∈ g '' (f '' s)ᶜ, by rwa [←hns],
let ⟨y', hy', eq_y'⟩ := this in
have f x = y',
from calc f x = g' y : by simp [h, hx, hy, if_pos, if_neg] at eq; assumption
... = (g' ∘ g) y' : by simp [(∘), eq_y']
... = _ : by simp [g'g],
have y' ∈ f '' s, from this ▸ mem_image_of_mem _ hx,
hy' this,
have function.injective h,
from λ x y eq,
by_cases
(λ hx : x ∈ s, by_cases
(λ hy : y ∈ s, by simp [h, hx, hy, if_pos, if_neg] at eq; exact hf eq)
(λ hy : y ∉ s, (split x hx y hy eq).elim))
(λ hx : x ∉ s, by_cases
(λ hy : y ∈ s, (split y hy x hx eq.symm).elim)
(λ hy : y ∉ s,
have x ∈ g '' (f '' s)ᶜ, by rwa [←hns],
let ⟨x', hx', eqx⟩ := this in
have y ∈ g '' (f '' s)ᶜ, by rwa [←hns],
let ⟨y', hy', eqy⟩ := this in
have g' x = g' y, by simp [h, hx, hy, if_pos, if_neg] at eq; assumption,
have (g' ∘ g) x' = (g' ∘ g) y', by simp [(∘), eqx, eqy, this],
have x' = y', by rwa [g'g] at this,
calc x = g x' : eqx.symm
... = g y' : by rw [this]
... = y : eqy)),
⟨h, ‹function.injective h›, ‹function.surjective h›⟩
theorem antisymm : (α ↪ β) → (β ↪ α) → nonempty (α ≃ β)
| ⟨e₁, h₁⟩ ⟨e₂, h₂⟩ :=
let ⟨f, hf⟩ := schroeder_bernstein h₁ h₂ in
⟨equiv.of_bijective f hf⟩
end antisymm
section wo
parameters {ι : Type u} {β : ι → Type v}
@[reducible] private def sets := {s : set (∀ i, β i) |
∀ (x ∈ s) (y ∈ s) i, (x : ∀ i, β i) i = y i → x = y}
/-- The cardinals are well-ordered. We express it here by the fact that in any set of cardinals
there is an element that injects into the others. See `cardinal.linear_order` for (one of) the
lattice instance. -/
theorem min_injective (I : nonempty ι) : ∃ i, nonempty (∀ j, β i ↪ β j) :=
let ⟨s, hs, ms⟩ := show ∃ s ∈ sets, ∀ a ∈ sets, s ⊆ a → a = s, from
zorn.zorn_subset sets (λ c hc hcc, ⟨⋃₀ c,
λ x ⟨p, hpc, hxp⟩ y ⟨q, hqc, hyq⟩ i hi, (hcc.total hpc hqc).elim
(λ h, hc hqc x (h hxp) y hyq i hi) (λ h, hc hpc x hxp y (h hyq) i hi),
λ _, subset_sUnion_of_mem⟩) in
let ⟨i, e⟩ := show ∃ i, ∀ y, ∃ x ∈ s, (x : ∀ i, β i) i = y, from
classical.by_contradiction $ λ h,
have h : ∀ i, ∃ y, ∀ x ∈ s, (x : ∀ i, β i) i ≠ y,
by simpa only [not_exists, not_forall] using h,
let ⟨f, hf⟩ := axiom_of_choice h in
have f ∈ s, from
have insert f s ∈ sets := λ x hx y hy, begin
cases hx; cases hy, {simp [hx, hy]},
{ subst x, exact λ i e, (hf i y hy e.symm).elim },
{ subst y, exact λ i e, (hf i x hx e).elim },
{ exact hs x hx y hy }
end, ms _ this (subset_insert f s) ▸ mem_insert _ _,
let ⟨i⟩ := I in hf i f this rfl in
let ⟨f, hf⟩ := axiom_of_choice e in
⟨i, ⟨λ j, ⟨λ a, f a j, λ a b e',
let ⟨sa, ea⟩ := hf a, ⟨sb, eb⟩ := hf b in
by rw [← ea, ← eb, hs _ sa _ sb _ e']⟩⟩⟩
end wo
/-- The cardinals are totally ordered. See `cardinal.linear_order` for (one of) the lattice
instance. -/
theorem total {α : Type u} {β : Type v} : nonempty (α ↪ β) ∨ nonempty (β ↪ α) :=
match @min_injective bool (λ b, cond b (ulift α) (ulift.{(max u v) v} β)) ⟨tt⟩ with
| ⟨tt, ⟨h⟩⟩ := let ⟨f, hf⟩ := h ff in or.inl ⟨embedding.congr equiv.ulift equiv.ulift ⟨f, hf⟩⟩
| ⟨ff, ⟨h⟩⟩ := let ⟨f, hf⟩ := h tt in or.inr ⟨embedding.congr equiv.ulift equiv.ulift ⟨f, hf⟩⟩
end
end embedding
end function
|
5b282aec347eed833ffe8007354818a6ee56ae1a | fa02ed5a3c9c0adee3c26887a16855e7841c668b | /src/tactic/find_unused.lean | 3ab8c74762ed6b291e571c1bab347256f44d1458 | [
"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 | 4,383 | 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 tactic.core
/-!
# list_unused_decls
`#list_unused_decls` is a command used for theory development.
When writing a new theory one often tries
multiple variations of the same definitions: `foo`, `foo'`, `foo₂`,
`foo₃`, etc. Once the main definition or theorem has been written,
it's time to clean up and the file can contain a lot of dead code.
Mark the main declarations with `@[main_declaration]` and
`#list_unused_decls` will show the declarations in the file
that are not needed to define the main declarations.
Some of the so-called "unused" declarations may turn out to be useful
after all. The oversight can be corrected by marking those as
`@[main_declaration]`. `#list_unused_decls` will revise the list of
unused declarations. By default, the list of unused declarations will
not include any dependency of the main declarations.
The `@[main_declaration]` attribute should be removed before submitting
code to mathlib as it is merely a tool for cleaning up a module.
-/
namespace tactic
/-- Attribute `main_declaration` is used to mark declarations that are featured
in the current file. Then, the `#list_unused_decls` command can be used to
list the declaration present in the file that are not used by the main
declarations of the file. -/
@[user_attribute]
meta def main_declaration_attr : user_attribute :=
{ name := `main_declaration,
descr := "tag essential declarations to help identify unused definitions" }
/-- `update_unsed_decls_list n m` removes from the map of unneeded declarations those
referenced by declaration named `n` which is considerred to be a
main declaration -/
private meta def update_unsed_decls_list :
name → name_map declaration → tactic (name_map declaration)
| n m :=
do d ← get_decl n,
if m.contains n then do
let m := m.erase n,
let ns := d.value.list_constant.union d.type.list_constant,
ns.mfold m update_unsed_decls_list
else pure m
/-- In the current file, list all the declaration that are not marked as `@[main_declaration]` and
that are not referenced by such declarations -/
meta def all_unused (fs : list (option string)) : tactic (name_map declaration) :=
do ds ← get_decls_from fs,
ls ← ds.keys.mfilter (succeeds ∘ user_attribute.get_param_untyped main_declaration_attr),
ds ← ls.mfoldl (flip update_unsed_decls_list) ds,
ds.mfilter $ λ n d, do
e ← get_env,
return $ !d.is_auto_or_internal e
/-- expecting a string literal (e.g. `"src/tactic/find_unused.lean"`)
-/
meta def parse_file_name (fn : pexpr) : tactic (option string) :=
some <$> (to_expr fn >>= eval_expr string) <|> fail "expecting: \"src/dir/file-name\""
setup_tactic_parser
/-- The command `#list_unused_decls` lists the declarations that that
are not used the main features of the present file. The main features
of a file are taken as the declaration tagged with
`@[main_declaration]`.
A list of files can be given to `#list_unused_decls` as follows:
```lean
#list_unused_decls ["src/tactic/core.lean","src/tactic/interactive.lean"]
```
They are given in a list that contains file names written as Lean
strings. With a list of files, the declarations from all those files
in addition to the declarations above `#list_unused_decls` in the
current file will be considered and their interdependencies will be
analyzed to see which declarations are unused by declarations marked
as `@[main_declaration]`. The files listed must be imported by the
current file. The path of the file names is expected to be relative to
the root of the project (i.e. the location of `leanpkg.toml` when it
is present).
Neither `#list_unused_decls` nor `@[main_declaration]` should appear
in a finished mathlib development. -/
@[user_command]
meta def unused_decls_cmd (_ : parse $ tk "#list_unused_decls") : lean.parser unit :=
do fs ← pexpr_list,
show tactic unit, from
do fs ← fs.mmap parse_file_name,
ds ← all_unused $ none :: fs,
ds.to_list.mmap' $ λ ⟨n,_⟩, trace!"#print {n}"
add_tactic_doc
{ name := "#list_unused_decls",
category := doc_category.cmd,
decl_names := [`tactic.unused_decls_cmd],
tags := ["debugging"] }
end tactic
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.