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
a34b410a20460ebd267dfbe5687b639d97ed3f9c
a9d0fb7b0e4f802bd3857b803e6c5c23d87fef91
/library/init/prod.lean
4fee1b1086ae23b6ece23c7c0656ba9b937e4626
[ "Apache-2.0" ]
permissive
soonhokong/lean-osx
4a954262c780e404c1369d6c06516161d07fcb40
3670278342d2f4faa49d95b46d86642d7875b47c
refs/heads/master
1,611,410,334,552
1,474,425,686,000
1,474,425,686,000
12,043,103
5
1
null
null
null
null
UTF-8
Lean
false
false
1,249
lean
/- Copyright (c) 2014 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Leonardo de Moura, Jeremy Avigad -/ prelude import init.num init.relation notation A × B := prod A B -- notation for n-ary tuples notation `(` h `, ` t:(foldr `, ` (e r, prod.mk e r)) `)` := prod.mk h t namespace prod notation `pr₁` := pr1 notation `pr₂` := pr2 postfix `.1`:(max+1) := pr1 postfix `.2`:(max+1) := pr2 end prod universe variables u v attribute [instance] protected definition prod.is_inhabited {A : Type u} {B : Type v} [inhabited A] [inhabited B] : inhabited (prod A B) := ⟨(default A, default B)⟩ attribute [instance] protected definition prod.has_decidable_eq {A : Type u} {B : Type v} [h₁ : decidable_eq A] [h₂ : decidable_eq B] : ∀ p₁ p₂ : A × B, decidable (p₁ = p₂) | (a, b) (a', b') := match (h₁ a a') with | (is_true e₁) := match (h₂ b b') with | (is_true e₂) := is_true (eq.rec_on e₁ (eq.rec_on e₂ rfl)) | (is_false n₂) := is_false (assume h, prod.no_confusion h (λ e₁' e₂', absurd e₂' n₂)) end | (is_false n₁) := is_false (assume h, prod.no_confusion h (λ e₁' e₂', absurd e₁' n₁)) end
8478fb529570a6fe8f17a7fdee919dde8a9f009c
4727251e0cd73359b15b664c3170e5d754078599
/src/logic/equiv/nat.lean
977b44562e24be8cc9ea064e58b83443247aba6b
[ "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,066
lean
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import data.nat.pairing import data.pnat.basic /-! # Equivalences involving `ℕ` This file defines some additional constructive equivalences using `encodable` and the pairing function on `ℕ`. -/ open nat namespace equiv variables {α : Type*} /-- An equivalence between `ℕ × ℕ` and `ℕ`, using the `mkpair` and `unpair` functions in `data.nat.pairing`. -/ @[simp] def nat_prod_nat_equiv_nat : ℕ × ℕ ≃ ℕ := ⟨λ p, nat.mkpair p.1 p.2, nat.unpair, λ p, begin cases p, apply nat.unpair_mkpair end, nat.mkpair_unpair⟩ /-- An equivalence between `bool × ℕ` and `ℕ`, by mapping `(tt, x)` to `2 * x + 1` and `(ff, x)` to `2 * x`. -/ @[simp] def bool_prod_nat_equiv_nat : bool × ℕ ≃ ℕ := ⟨λ ⟨b, n⟩, bit b n, bodd_div2, λ ⟨b, n⟩, by simp [bool_prod_nat_equiv_nat._match_1, bodd_bit, div2_bit], λ n, by simp [bool_prod_nat_equiv_nat._match_1, bit_decomp]⟩ /-- An equivalence between `ℕ ⊕ ℕ` and `ℕ`, by mapping `(sum.inl x)` to `2 * x` and `(sum.inr x)` to `2 * x + 1`. -/ @[simp] def nat_sum_nat_equiv_nat : ℕ ⊕ ℕ ≃ ℕ := (bool_prod_equiv_sum ℕ).symm.trans bool_prod_nat_equiv_nat /-- An equivalence between `ℤ` and `ℕ`, through `ℤ ≃ ℕ ⊕ ℕ` and `ℕ ⊕ ℕ ≃ ℕ`. -/ def int_equiv_nat : ℤ ≃ ℕ := int_equiv_nat_sum_nat.trans nat_sum_nat_equiv_nat /-- An equivalence between `α × α` and `α`, given that there is an equivalence between `α` and `ℕ`. -/ def prod_equiv_of_equiv_nat (e : α ≃ ℕ) : α × α ≃ α := calc α × α ≃ ℕ × ℕ : prod_congr e e ... ≃ ℕ : nat_prod_nat_equiv_nat ... ≃ α : e.symm /-- An equivalence between `ℕ+` and `ℕ`, by mapping `x` in `ℕ+` to `x - 1` in `ℕ`. -/ def pnat_equiv_nat : ℕ+ ≃ ℕ := ⟨λ n, pred n.1, succ_pnat, λ ⟨n, h⟩, by { cases n, cases h, simp [succ_pnat, h] }, λ n, by simp [succ_pnat] ⟩ end equiv
c8628b55524bb9f8b18c10e80087e9a9933a187b
947b78d97130d56365ae2ec264df196ce769371a
/stage0/src/Lean/Meta/SynthInstance.lean
8c6ed2751992de1fde358eb433872f42a4c3645a
[ "Apache-2.0" ]
permissive
shyamalschandra/lean4
27044812be8698f0c79147615b1d5090b9f4b037
6e7a883b21eaf62831e8111b251dc9b18f40e604
refs/heads/master
1,671,417,126,371
1,601,859,995,000
1,601,860,020,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
24,589
lean
/- Copyright (c) 2019 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Daniel Selsam, Leonardo de Moura Type class instance synthesizer using tabled resolution. -/ import Lean.Meta.Basic import Lean.Meta.Instances import Lean.Meta.LevelDefEq import Lean.Meta.AbstractMVars import Lean.Meta.WHNF namespace Lean namespace Meta namespace SynthInstance open Std (HashMap) def mkInferTCGoalsLRAttr : IO TagAttribute := registerTagAttribute `inferTCGoalsLR "instruct type class resolution procedure to solve goals from left to right for this instance" @[init mkInferTCGoalsLRAttr] constant inferTCGoalsLRAttr : TagAttribute := arbitrary _ def hasInferTCGoalsLRAttribute (env : Environment) (constName : Name) : Bool := inferTCGoalsLRAttr.hasTag env constName structure GeneratorNode := (mvar : Expr) (key : Expr) (mctx : MetavarContext) (instances : Array Expr) (currInstanceIdx : Nat) instance GeneratorNode.inhabited : Inhabited GeneratorNode := ⟨⟨arbitrary _, arbitrary _, arbitrary _, arbitrary _, 0⟩⟩ structure ConsumerNode := (mvar : Expr) (key : Expr) (mctx : MetavarContext) (subgoals : List Expr) instance Consumernode.inhabited : Inhabited ConsumerNode := ⟨⟨arbitrary _, arbitrary _, arbitrary _, []⟩⟩ inductive Waiter | consumerNode : ConsumerNode → Waiter | root : Waiter def Waiter.isRoot : Waiter → Bool | Waiter.consumerNode _ => false | Waiter.root => true /- In tabled resolution, we creating a mapping from goals (e.g., `HasCoe Nat ?x`) to answers and waiters. Waiters are consumer nodes that are waiting for answers for a particular node. We implement this mapping using a `HashMap` where the keys are normalized expressions. That is, we replace assignable metavariables with auxiliary free variables of the form `_tc.<idx>`. We do not declare these free variables in any local context, and we should view them as "normalized names" for metavariables. For example, the term `f ?m ?m ?n` is normalized as `f _tc.0 _tc.0 _tc.1`. This approach is structural, and we may visit the same goal more than once if the different occurrences are just definitionally equal, but not structurally equal. Remark: a metavariable is assignable only if its depth is equal to the metavar context depth. -/ namespace MkTableKey structure State := (nextIdx : Nat := 0) (lmap : HashMap MVarId Level := {}) (emap : HashMap MVarId Expr := {}) abbrev M := ReaderT MetavarContext (StateM State) partial def normLevel : Level → M Level | u => if !u.hasMVar then pure u else match u with | Level.succ v _ => do v ← normLevel v; pure $ u.updateSucc! v | Level.max v w _ => do v ← normLevel v; w ← normLevel w; pure $ u.updateMax! v w | Level.imax v w _ => do v ← normLevel v; w ← normLevel w; pure $ u.updateIMax! v w | Level.mvar mvarId _ => do mctx ← read; if !mctx.isLevelAssignable mvarId then pure u else do s ← get; match s.lmap.find? mvarId with | some u' => pure u' | none => do let u' := mkLevelParam $ mkNameNum `_tc s.nextIdx; modify $ fun s => { s with nextIdx := s.nextIdx + 1, lmap := s.lmap.insert mvarId u' }; pure u' | u => pure u partial def normExpr : Expr → M Expr | e => if !e.hasMVar then pure e else match e with | Expr.const _ us _ => do us ← us.mapM normLevel; pure $ e.updateConst! us | Expr.sort u _ => do u ← normLevel u; pure $ e.updateSort! u | Expr.app f a _ => do f ← normExpr f; a ← normExpr a; pure $ e.updateApp! f a | Expr.letE _ t v b _ => do t ← normExpr t; v ← normExpr v; b ← normExpr b; pure $ e.updateLet! t v b | Expr.forallE _ d b _ => do d ← normExpr d; b ← normExpr b; pure $ e.updateForallE! d b | Expr.lam _ d b _ => do d ← normExpr d; b ← normExpr b; pure $ e.updateLambdaE! d b | Expr.mdata _ b _ => do b ← normExpr b; pure $ e.updateMData! b | Expr.proj _ _ b _ => do b ← normExpr b; pure $ e.updateProj! b | Expr.mvar mvarId _ => do mctx ← read; if !mctx.isExprAssignable mvarId then pure e else do s ← get; match s.emap.find? mvarId with | some e' => pure e' | none => do let e' := mkFVar $ mkNameNum `_tc s.nextIdx; modify $ fun s => { s with nextIdx := s.nextIdx + 1, emap := s.emap.insert mvarId e' }; pure e' | _ => pure e end MkTableKey /- Remark: `mkTableKey` assumes `e` does not contain assigned metavariables. -/ def mkTableKey (mctx : MetavarContext) (e : Expr) : Expr := (MkTableKey.normExpr e mctx).run' {} structure Answer := (result : AbstractMVarsResult) (resultType : Expr) instance Answer.inhabited : Inhabited Answer := ⟨⟨arbitrary _, arbitrary _⟩⟩ structure TableEntry := (waiters : Array Waiter) (answers : Array Answer := #[]) /- Remark: the SynthInstance.State is not really an extension of `Meta.State`. The field `postponed` is not needed, and the field `mctx` is misleading since `synthInstance` methods operate over different `MetavarContext`s simultaneously. That being said, we still use `extends` because it makes it simpler to move from `M` to `MetaM`. -/ structure State := (result : Option Expr := none) (generatorStack : Array GeneratorNode := #[]) (resumeStack : Array (ConsumerNode × Answer) := #[]) (tableEntries : HashMap Expr TableEntry := {}) abbrev SynthM := StateRefT State MetaM @[inline] def mapMetaM (f : forall {α}, MetaM α → MetaM α) {α} : SynthM α → SynthM α := monadMap @f instance SynthM.inhabited {α} : Inhabited (SynthM α) := ⟨fun _ => arbitrary _⟩ /-- Return globals and locals instances that may unify with `type` -/ def getInstances (type : Expr) : MetaM (Array Expr) := do -- We must retrieve `localInstances` before we use `forallTelescopeReducing` because it will update the set of local instances localInstances ← getLocalInstances; forallTelescopeReducing type $ fun _ type => do className? ← isClass? type; match className? with | none => throwError $ "type class instance expected" ++ indentExpr type | some className => do globalInstances ← getGlobalInstances; result ← globalInstances.getUnify type; result ← result.mapM $ fun c => match c with | Expr.const constName us _ => do us ← us.mapM (fun _ => mkFreshLevelMVar); pure $ c.updateConst! us | _ => panic! "global instance is not a constant"; trace! `Meta.synthInstance.globalInstances (type ++ " " ++ result); let result := localInstances.foldl (fun (result : Array Expr) linst => if linst.className == className then result.push linst.fvar else result) result; pure result def mkGeneratorNode? (key mvar : Expr) : MetaM (Option GeneratorNode) := do mvarType ← inferType mvar; mvarType ← instantiateMVars mvarType; instances ← getInstances mvarType; if instances.isEmpty then pure none else do mctx ← getMCtx; pure $ some { mvar := mvar, key := key, mctx := mctx, instances := instances, currInstanceIdx := instances.size } /-- Create a new generator node for `mvar` and add `waiter` as its waiter. `key` must be `mkTableKey mctx mvarType`. -/ def newSubgoal (mctx : MetavarContext) (key : Expr) (mvar : Expr) (waiter : Waiter) : SynthM Unit := withMCtx mctx $ do trace! `Meta.synthInstance.newSubgoal key; node? ← liftM $ mkGeneratorNode? key mvar; match node? with | none => pure () | some node => let entry : TableEntry := { waiters := #[waiter] }; modify $ fun s => { s with generatorStack := s.generatorStack.push node, tableEntries := s.tableEntries.insert key entry } def findEntry? (key : Expr) : SynthM (Option TableEntry) := do s ← get; pure $ s.tableEntries.find? key def getEntry (key : Expr) : SynthM TableEntry := do entry? ← findEntry? key; match entry? with | none => panic! "invalid key at synthInstance" | some entry => pure entry /-- Create a `key` for the goal associated with the given metavariable. That is, we create a key for the type of the metavariable. We must instantiate assigned metavariables before we invoke `mkTableKey`. -/ def mkTableKeyFor (mctx : MetavarContext) (mvar : Expr) : SynthM Expr := withMCtx mctx $ do mvarType ← inferType mvar; mvarType ← instantiateMVars mvarType; pure $ mkTableKey mctx mvarType /- See `getSubgoals` and `getSubgoalsAux` We use the parameter `j` to reduce the number of `instantiate*` invocations. It is the same approach we use at `forallTelescope` and `lambdaTelescope`. Given `getSubgoalsAux args j subgoals instVal type`, we have that `type.instantiateRevRange j args.size args` does not have loose bound variables. -/ structure SubgoalsResult : Type := (subgoals : List Expr) (instVal : Expr) (instTypeBody : Expr) private partial def getSubgoalsAux (lctx : LocalContext) (localInsts : LocalInstances) (xs : Array Expr) : Array Expr → Nat → List Expr → Expr → Expr → MetaM SubgoalsResult | args, j, subgoals, instVal, Expr.forallE n d b c => do let d := d.instantiateRevRange j args.size args; mvarType ← mkForallFVars xs d; mvar ← mkFreshExprMVarAt lctx localInsts mvarType; let arg := mkAppN mvar xs; let instVal := mkApp instVal arg; let subgoals := if c.binderInfo.isInstImplicit then mvar::subgoals else subgoals; let args := args.push (mkAppN mvar xs); getSubgoalsAux args j subgoals instVal b | args, j, subgoals, instVal, type => do let type := type.instantiateRevRange j args.size args; type ← whnf type; if type.isForall then getSubgoalsAux args args.size subgoals instVal type else pure ⟨subgoals, instVal, type⟩ /-- `getSubgoals lctx localInsts xs inst` creates the subgoals for the instance `inst`. The subgoals are in the context of the free variables `xs`, and `(lctx, localInsts)` is the local context and instances before we added the free variables to it. This extra complication is required because 1- We want all metavariables created by `synthInstance` to share the same local context. 2- We want to ensure that applications such as `mvar xs` are higher order patterns. The method `getGoals` create a new metavariable for each parameter of `inst`. For example, suppose the type of `inst` is `forall (x_1 : A_1) ... (x_n : A_n), B x_1 ... x_n`. Then, we create the metavariables `?m_i : forall xs, A_i`, and return the subset of these metavariables that are instance implicit arguments, and the expressions: - `inst (?m_1 xs) ... (?m_n xs)` (aka `instVal`) - `B (?m_1 xs) ... (?m_n xs)` -/ def getSubgoals (lctx : LocalContext) (localInsts : LocalInstances) (xs : Array Expr) (inst : Expr) : MetaM SubgoalsResult := do instType ← inferType inst; result ← getSubgoalsAux lctx localInsts xs #[] 0 [] inst instType; match inst.getAppFn with | Expr.const constName _ _ => do env ← getEnv; if hasInferTCGoalsLRAttribute env constName then pure { result with subgoals := result.subgoals.reverse } else pure result | _ => pure result def tryResolveCore (mvar : Expr) (inst : Expr) : MetaM (Option (MetavarContext × List Expr)) := do mvarType ← inferType mvar; lctx ← getLCtx; localInsts ← getLocalInstances; forallTelescopeReducing mvarType $ fun xs mvarTypeBody => do ⟨subgoals, instVal, instTypeBody⟩ ← getSubgoals lctx localInsts xs inst; trace! `Meta.synthInstance.tryResolve (mvarTypeBody ++ " =?= " ++ instTypeBody); condM (isDefEq mvarTypeBody instTypeBody) (do instVal ← mkLambdaFVars xs instVal; condM (isDefEq mvar instVal) (do trace! `Meta.synthInstance.tryResolve "success"; mctx ← getMCtx; pure (some (mctx, subgoals))) (do trace! `Meta.synthInstance.tryResolve "failure assigning"; pure none)) (do trace! `Meta.synthInstance.tryResolve "failure"; pure none) /-- Try to synthesize metavariable `mvar` using the instance `inst`. Remark: `mctx` contains `mvar`. If it succeeds, the result is a new updated metavariable context and a new list of subgoals. A subgoal is created for each instance implicit parameter of `inst`. -/ def tryResolve (mctx : MetavarContext) (mvar : Expr) (inst : Expr) : SynthM (Option (MetavarContext × List Expr)) := liftM $ traceCtx `Meta.synthInstance.tryResolve $ withMCtx mctx $ tryResolveCore mvar inst /-- Assign a precomputed answer to `mvar`. If it succeeds, the result is a new updated metavariable context and a new list of subgoals. -/ def tryAnswer (mctx : MetavarContext) (mvar : Expr) (answer : Answer) : SynthM (Option MetavarContext) := liftM $ withMCtx mctx $ do (_, _, val) ← openAbstractMVarsResult answer.result; condM (isDefEq mvar val) (do mctx ← getMCtx; pure $ some mctx) (pure none) /-- Move waiters that are waiting for the given answer to the resume stack. -/ def wakeUp (answer : Answer) : Waiter → SynthM Unit | Waiter.root => if answer.result.paramNames.isEmpty && answer.result.numMVars == 0 then do modify $ fun s => { s with result := answer.result.expr } else do (_, _, answerExpr) ← liftM $ openAbstractMVarsResult answer.result; trace! `Meta.synthInstance ("skip answer containing metavariables " ++ answerExpr); pure () | Waiter.consumerNode cNode => modify $ fun s => { s with resumeStack := s.resumeStack.push (cNode, answer) } def isNewAnswer (oldAnswers : Array Answer) (answer : Answer) : Bool := oldAnswers.all $ fun oldAnswer => do -- Remark: isDefEq here is too expensive. TODO: if `==` is too imprecise, add some light normalization to `resultType` at `addAnswer` -- iseq ← isDefEq oldAnswer.resultType answer.resultType; pure (!iseq) oldAnswer.resultType != answer.resultType private def mkAnswer (cNode : ConsumerNode) : MetaM Answer := withMCtx cNode.mctx do traceM `Meta.synthInstance.newAnswer $ do { mvarType ← inferType cNode.mvar; pure mvarType }; val ← instantiateMVars cNode.mvar; result ← abstractMVars val; -- assignable metavariables become parameters resultType ← inferType result.expr; pure { result := result, resultType := resultType } /-- Create a new answer after `cNode` resolved all subgoals. That is, `cNode.subgoals == []`. And then, store it in the tabled entries map, and wakeup waiters. -/ def addAnswer (cNode : ConsumerNode) : SynthM Unit := do answer ← liftM $ mkAnswer cNode; -- Remark: `answer` does not contain assignable or assigned metavariables. let key := cNode.key; entry ← getEntry key; when (isNewAnswer entry.answers answer) $ do let newEntry := { entry with answers := entry.answers.push answer }; modify $ fun s => { s with tableEntries := s.tableEntries.insert key newEntry }; entry.waiters.forM (wakeUp answer) /-- Process the next subgoal in the given consumer node. -/ def consume (cNode : ConsumerNode) : SynthM Unit := match cNode.subgoals with | [] => addAnswer cNode | mvar::_ => do let waiter := Waiter.consumerNode cNode; key ← mkTableKeyFor cNode.mctx mvar; entry? ← findEntry? key; match entry? with | none => newSubgoal cNode.mctx key mvar waiter | some entry => modify $ fun s => { s with resumeStack := entry.answers.foldl (fun s answer => s.push (cNode, answer)) s.resumeStack, tableEntries := s.tableEntries.insert key { entry with waiters := entry.waiters.push waiter } } def getTop : SynthM GeneratorNode := do s ← get; pure s.generatorStack.back @[inline] def modifyTop (f : GeneratorNode → GeneratorNode) : SynthM Unit := modify $ fun s => { s with generatorStack := s.generatorStack.modify (s.generatorStack.size - 1) f } /-- Try the next instance in the node on the top of the generator stack. -/ def generate : SynthM Unit := do gNode ← getTop; if gNode.currInstanceIdx == 0 then modify $ fun s => { s with generatorStack := s.generatorStack.pop } else do let key := gNode.key; let idx := gNode.currInstanceIdx - 1; let inst := gNode.instances.get! idx; let mctx := gNode.mctx; let mvar := gNode.mvar; trace! `Meta.synthInstance.generate ("instance " ++ inst); modifyTop $ fun gNode => { gNode with currInstanceIdx := idx }; result? ← tryResolve mctx mvar inst; match result? with | none => pure () | some (mctx, subgoals) => consume { key := key, mvar := mvar, subgoals := subgoals, mctx := mctx } def getNextToResume : SynthM (ConsumerNode × Answer) := do s ← get; let r := s.resumeStack.back; modify $ fun s => { s with resumeStack := s.resumeStack.pop }; pure r /-- Given `(cNode, answer)` on the top of the resume stack, continue execution by using `answer` to solve the next subgoal. -/ def resume : SynthM Unit := do (cNode, answer) ← getNextToResume; match cNode.subgoals with | [] => panic! "resume found no remaining subgoals" | mvar::rest => do result? ← tryAnswer cNode.mctx mvar answer; match result? with | none => pure () | some mctx => do withMCtx mctx $ traceM `Meta.synthInstance.resume $ do { goal ← inferType cNode.mvar; subgoal ← inferType mvar; pure (goal ++ " <== " ++ subgoal) }; consume { key := cNode.key, mvar := cNode.mvar, subgoals := rest, mctx := mctx } def step : SynthM Bool := do s ← get; if !s.resumeStack.isEmpty then do resume; pure true else if !s.generatorStack.isEmpty then do generate; pure true else pure false def getResult : SynthM (Option Expr) := do s ← get; pure s.result def synth : Nat → SynthM (Option Expr) | 0 => do trace! `Meta.synthInstance "synthInstance is out of fuel"; pure none | fuel+1 => do trace! `Meta.synthInstance ("remaining fuel " ++ toString fuel); condM step (do result? ← getResult; match result? with | none => synth fuel | some result => pure result) (do trace! `Meta.synthInstance "failed"; pure none) def main (type : Expr) (fuel : Nat) : MetaM (Option Expr) := traceCtx `Meta.synthInstance $ do trace! `Meta.synthInstance ("main goal " ++ type); mvar ← mkFreshExprMVar type; mctx ← getMCtx; let key := mkTableKey mctx type; let action : SynthM (Option Expr) := do { newSubgoal mctx key mvar Waiter.root; synth fuel }; action.run' {} end SynthInstance /- Type class parameters can be annotated with `outParam` annotations. Given `C a_1 ... a_n`, we replace `a_i` with a fresh metavariable `?m_i` IF `a_i` is an `outParam`. The result is type correct because we reject type class declarations IF it contains a regular parameter X that depends on an `out` parameter Y. Then, we execute type class resolution as usual. If it succeeds, and metavariables ?m_i have been assigned, we try to unify the original type `C a_1 ... a_n` witht the normalized one. -/ private def preprocess (type : Expr) : MetaM Expr := forallTelescopeReducing type $ fun xs type => do type ← whnf type; mkForallFVars xs type private def preprocessLevels (us : List Level) : MetaM (List Level) := do us ← us.foldlM (fun (r : List Level) (u : Level) => do u ← instantiateLevelMVars u; if u.hasMVar then do u' ← mkFreshLevelMVar; pure (u'::r) else pure (u::r)) []; pure $ us.reverse private partial def preprocessArgs : Expr → Nat → Array Expr → MetaM (Array Expr) | type, i, args => if h : i < args.size then do type ← whnf type; match type with | Expr.forallE _ d b _ => do let arg := args.get ⟨i, h⟩; arg ← if isOutParam d then mkFreshExprMVar d else pure arg; let args := args.set ⟨i, h⟩ arg; preprocessArgs (b.instantiate1 arg) (i+1) args | _ => throwError "type class resolution failed, insufficient number of arguments" -- TODO improve error message else pure args private def preprocessOutParam (type : Expr) : MetaM Expr := forallTelescope type $ fun xs typeBody => match typeBody.getAppFn with | c@(Expr.const constName us _) => do env ← getEnv; if !hasOutParams env constName then pure type else do let args := typeBody.getAppArgs; us ← preprocessLevels us; let c := mkConst constName us; cType ← inferType c; args ← preprocessArgs cType 0 args; mkForallFVars xs (mkAppN c args) | _ => pure type def maxStepsDefault := 1000 @[init] def maxStepsOption : IO Unit := registerOption `synthInstance.maxSteps { defValue := maxStepsDefault, group := "", descr := "maximum steps for the type class instance synthesis procedure" } private def getMaxSteps (opts : Options) : Nat := opts.getNat `synthInstance.maxSteps maxStepsDefault private def synthInstanceImp? (type : Expr) : MetaM (Option Expr) := do opts ← getOptions; let fuel := getMaxSteps opts; inputConfig ← getConfig; withConfig (fun config => { config with isDefEqStuckEx := true, transparency := TransparencyMode.reducible, foApprox := true, ctxApprox := true, constApprox := false }) do type ← instantiateMVars type; type ← preprocess type; s ← get; match s.cache.synthInstance.find? type with | some result => pure result | none => do result? ← withNewMCtxDepth $ do { normType ← preprocessOutParam type; trace! `Meta.synthInstance (type ++ " ==> " ++ normType); result? ← SynthInstance.main normType fuel; match result? with | none => pure none | some result => do trace! `Meta.synthInstance ("FOUND result " ++ result); result ← instantiateMVars result; condM (hasAssignableMVar result) (pure none) (pure (some result)) }; result? ← match result? with | none => pure none | some result => do { trace! `Meta.synthInstance ("result " ++ result); resultType ← inferType result; condM (withConfig (fun _ => inputConfig) $ isDefEq type resultType) (do result ← instantiateMVars result; pure (some result)) (pure none) }; if type.hasMVar then pure result? else do modify $ fun s => { s with cache := { s.cache with synthInstance := s.cache.synthInstance.insert type result? } }; pure result? /-- Return `LOption.some r` if succeeded, `LOption.none` if it failed, and `LOption.undef` if instance cannot be synthesized right now because `type` contains metavariables. -/ private def trySynthInstanceImp (type : Expr) : MetaM (LOption Expr) := do catchInternalId isDefEqStuckExceptionId (toLOptionM $ synthInstanceImp? type) (fun _ => pure LOption.undef) private def synthInstanceImp (type : Expr) : MetaM Expr := catchInternalId isDefEqStuckExceptionId (do result? ← synthInstanceImp? type; match result? with | some result => pure result | none => throwError $ "failed to synthesize" ++ indentExpr type) (fun _ => throwError $ "failed to synthesize" ++ indentExpr type) private def synthPendingImp (mvarId : MVarId) : MetaM Bool := do mvarDecl ← getMVarDecl mvarId; match mvarDecl.kind with | MetavarKind.synthetic => do c? ← isClass? mvarDecl.type; match c? with | none => pure false | some _ => do val? ← catchInternalId isDefEqStuckExceptionId (synthInstanceImp? mvarDecl.type) (fun _ => pure none); match val? with | none => pure false | some val => condM (isExprMVarAssigned mvarId) (pure false) $ do assignExprMVar mvarId val; pure true | _ => pure false @[init] def setSynthPendingRef : IO Unit := synthPendingRef.set synthPendingImp @[init] private def regTraceClasses : IO Unit := do registerTraceClass `Meta.synthInstance; registerTraceClass `Meta.synthInstance.globalInstances; registerTraceClass `Meta.synthInstance.newSubgoal; registerTraceClass `Meta.synthInstance.tryResolve; registerTraceClass `Meta.synthInstance.resume; registerTraceClass `Meta.synthInstance.generate variables {m : Type → Type} [MonadLiftT MetaM m] def synthInstance? (type : Expr) : m (Option Expr) := liftMetaM $ synthInstanceImp? type def trySynthInstance (type : Expr) : m (LOption Expr) := liftMetaM $ trySynthInstanceImp type def synthInstance (type : Expr) : m Expr := liftMetaM $ synthInstanceImp type end Meta end Lean
54bd796d7ec7443381a539683fb70967f96bab9d
592ee40978ac7604005a4e0d35bbc4b467389241
/Library/generated/mathscheme-lean/Shelf.lean
0c3a7f92c4f458e11c8f477f6e82d5cb2e0371d3
[]
no_license
ysharoda/Deriving-Definitions
3e149e6641fae440badd35ac110a0bd705a49ad2
dfecb27572022de3d4aa702cae8db19957523a59
refs/heads/master
1,679,127,857,700
1,615,939,007,000
1,615,939,007,000
229,785,731
4
0
null
null
null
null
UTF-8
Lean
false
false
8,400
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 Shelf structure Shelf (A : Type) : Type := (linv : (A → (A → A))) (rinv : (A → (A → A))) (leftDistributive : (∀ {x y z : A} , (linv x (linv y z)) = (linv (linv x y) (linv x z)))) (rightDistributive : (∀ {x y z : A} , (rinv (rinv y z) x) = (rinv (rinv y x) (rinv z x)))) open Shelf structure Sig (AS : Type) : Type := (linvS : (AS → (AS → AS))) (rinvS : (AS → (AS → AS))) structure Product (A : Type) : Type := (linvP : ((Prod A A) → ((Prod A A) → (Prod A A)))) (rinvP : ((Prod A A) → ((Prod A A) → (Prod A A)))) (leftDistributiveP : (∀ {xP yP zP : (Prod A A)} , (linvP xP (linvP yP zP)) = (linvP (linvP xP yP) (linvP xP zP)))) (rightDistributiveP : (∀ {xP yP zP : (Prod A A)} , (rinvP (rinvP yP zP) xP) = (rinvP (rinvP yP xP) (rinvP zP xP)))) structure Hom {A1 : Type} {A2 : Type} (Sh1 : (Shelf A1)) (Sh2 : (Shelf A2)) : Type := (hom : (A1 → A2)) (pres_linv : (∀ {x1 x2 : A1} , (hom ((linv Sh1) x1 x2)) = ((linv Sh2) (hom x1) (hom x2)))) (pres_rinv : (∀ {x1 x2 : A1} , (hom ((rinv Sh1) x1 x2)) = ((rinv Sh2) (hom x1) (hom x2)))) structure RelInterp {A1 : Type} {A2 : Type} (Sh1 : (Shelf A1)) (Sh2 : (Shelf A2)) : Type 1 := (interp : (A1 → (A2 → Type))) (interp_linv : (∀ {x1 x2 : A1} {y1 y2 : A2} , ((interp x1 y1) → ((interp x2 y2) → (interp ((linv Sh1) x1 x2) ((linv Sh2) y1 y2)))))) (interp_rinv : (∀ {x1 x2 : A1} {y1 y2 : A2} , ((interp x1 y1) → ((interp x2 y2) → (interp ((rinv Sh1) x1 x2) ((rinv Sh2) y1 y2)))))) inductive ShelfTerm : Type | linvL : (ShelfTerm → (ShelfTerm → ShelfTerm)) | rinvL : (ShelfTerm → (ShelfTerm → ShelfTerm)) open ShelfTerm inductive ClShelfTerm (A : Type) : Type | sing : (A → ClShelfTerm) | linvCl : (ClShelfTerm → (ClShelfTerm → ClShelfTerm)) | rinvCl : (ClShelfTerm → (ClShelfTerm → ClShelfTerm)) open ClShelfTerm inductive OpShelfTerm (n : ℕ) : Type | v : ((fin n) → OpShelfTerm) | linvOL : (OpShelfTerm → (OpShelfTerm → OpShelfTerm)) | rinvOL : (OpShelfTerm → (OpShelfTerm → OpShelfTerm)) open OpShelfTerm inductive OpShelfTerm2 (n : ℕ) (A : Type) : Type | v2 : ((fin n) → OpShelfTerm2) | sing2 : (A → OpShelfTerm2) | linvOL2 : (OpShelfTerm2 → (OpShelfTerm2 → OpShelfTerm2)) | rinvOL2 : (OpShelfTerm2 → (OpShelfTerm2 → OpShelfTerm2)) open OpShelfTerm2 def simplifyCl {A : Type} : ((ClShelfTerm A) → (ClShelfTerm A)) | (linvCl x1 x2) := (linvCl (simplifyCl x1) (simplifyCl x2)) | (rinvCl x1 x2) := (rinvCl (simplifyCl x1) (simplifyCl x2)) | (sing x1) := (sing x1) def simplifyOpB {n : ℕ} : ((OpShelfTerm n) → (OpShelfTerm n)) | (linvOL x1 x2) := (linvOL (simplifyOpB x1) (simplifyOpB x2)) | (rinvOL x1 x2) := (rinvOL (simplifyOpB x1) (simplifyOpB x2)) | (v x1) := (v x1) def simplifyOp {n : ℕ} {A : Type} : ((OpShelfTerm2 n A) → (OpShelfTerm2 n A)) | (linvOL2 x1 x2) := (linvOL2 (simplifyOp x1) (simplifyOp x2)) | (rinvOL2 x1 x2) := (rinvOL2 (simplifyOp x1) (simplifyOp x2)) | (v2 x1) := (v2 x1) | (sing2 x1) := (sing2 x1) def evalB {A : Type} : ((Shelf A) → (ShelfTerm → A)) | Sh (linvL x1 x2) := ((linv Sh) (evalB Sh x1) (evalB Sh x2)) | Sh (rinvL x1 x2) := ((rinv Sh) (evalB Sh x1) (evalB Sh x2)) def evalCl {A : Type} : ((Shelf A) → ((ClShelfTerm A) → A)) | Sh (sing x1) := x1 | Sh (linvCl x1 x2) := ((linv Sh) (evalCl Sh x1) (evalCl Sh x2)) | Sh (rinvCl x1 x2) := ((rinv Sh) (evalCl Sh x1) (evalCl Sh x2)) def evalOpB {A : Type} {n : ℕ} : ((Shelf A) → ((vector A n) → ((OpShelfTerm n) → A))) | Sh vars (v x1) := (nth vars x1) | Sh vars (linvOL x1 x2) := ((linv Sh) (evalOpB Sh vars x1) (evalOpB Sh vars x2)) | Sh vars (rinvOL x1 x2) := ((rinv Sh) (evalOpB Sh vars x1) (evalOpB Sh vars x2)) def evalOp {A : Type} {n : ℕ} : ((Shelf A) → ((vector A n) → ((OpShelfTerm2 n A) → A))) | Sh vars (v2 x1) := (nth vars x1) | Sh vars (sing2 x1) := x1 | Sh vars (linvOL2 x1 x2) := ((linv Sh) (evalOp Sh vars x1) (evalOp Sh vars x2)) | Sh vars (rinvOL2 x1 x2) := ((rinv Sh) (evalOp Sh vars x1) (evalOp Sh vars x2)) def inductionB {P : (ShelfTerm → Type)} : ((∀ (x1 x2 : ShelfTerm) , ((P x1) → ((P x2) → (P (linvL x1 x2))))) → ((∀ (x1 x2 : ShelfTerm) , ((P x1) → ((P x2) → (P (rinvL x1 x2))))) → (∀ (x : ShelfTerm) , (P x)))) | plinvl prinvl (linvL x1 x2) := (plinvl _ _ (inductionB plinvl prinvl x1) (inductionB plinvl prinvl x2)) | plinvl prinvl (rinvL x1 x2) := (prinvl _ _ (inductionB plinvl prinvl x1) (inductionB plinvl prinvl x2)) def inductionCl {A : Type} {P : ((ClShelfTerm A) → Type)} : ((∀ (x1 : A) , (P (sing x1))) → ((∀ (x1 x2 : (ClShelfTerm A)) , ((P x1) → ((P x2) → (P (linvCl x1 x2))))) → ((∀ (x1 x2 : (ClShelfTerm A)) , ((P x1) → ((P x2) → (P (rinvCl x1 x2))))) → (∀ (x : (ClShelfTerm A)) , (P x))))) | psing plinvcl prinvcl (sing x1) := (psing x1) | psing plinvcl prinvcl (linvCl x1 x2) := (plinvcl _ _ (inductionCl psing plinvcl prinvcl x1) (inductionCl psing plinvcl prinvcl x2)) | psing plinvcl prinvcl (rinvCl x1 x2) := (prinvcl _ _ (inductionCl psing plinvcl prinvcl x1) (inductionCl psing plinvcl prinvcl x2)) def inductionOpB {n : ℕ} {P : ((OpShelfTerm n) → Type)} : ((∀ (fin : (fin n)) , (P (v fin))) → ((∀ (x1 x2 : (OpShelfTerm n)) , ((P x1) → ((P x2) → (P (linvOL x1 x2))))) → ((∀ (x1 x2 : (OpShelfTerm n)) , ((P x1) → ((P x2) → (P (rinvOL x1 x2))))) → (∀ (x : (OpShelfTerm n)) , (P x))))) | pv plinvol prinvol (v x1) := (pv x1) | pv plinvol prinvol (linvOL x1 x2) := (plinvol _ _ (inductionOpB pv plinvol prinvol x1) (inductionOpB pv plinvol prinvol x2)) | pv plinvol prinvol (rinvOL x1 x2) := (prinvol _ _ (inductionOpB pv plinvol prinvol x1) (inductionOpB pv plinvol prinvol x2)) def inductionOp {n : ℕ} {A : Type} {P : ((OpShelfTerm2 n A) → Type)} : ((∀ (fin : (fin n)) , (P (v2 fin))) → ((∀ (x1 : A) , (P (sing2 x1))) → ((∀ (x1 x2 : (OpShelfTerm2 n A)) , ((P x1) → ((P x2) → (P (linvOL2 x1 x2))))) → ((∀ (x1 x2 : (OpShelfTerm2 n A)) , ((P x1) → ((P x2) → (P (rinvOL2 x1 x2))))) → (∀ (x : (OpShelfTerm2 n A)) , (P x)))))) | pv2 psing2 plinvol2 prinvol2 (v2 x1) := (pv2 x1) | pv2 psing2 plinvol2 prinvol2 (sing2 x1) := (psing2 x1) | pv2 psing2 plinvol2 prinvol2 (linvOL2 x1 x2) := (plinvol2 _ _ (inductionOp pv2 psing2 plinvol2 prinvol2 x1) (inductionOp pv2 psing2 plinvol2 prinvol2 x2)) | pv2 psing2 plinvol2 prinvol2 (rinvOL2 x1 x2) := (prinvol2 _ _ (inductionOp pv2 psing2 plinvol2 prinvol2 x1) (inductionOp pv2 psing2 plinvol2 prinvol2 x2)) def stageB : (ShelfTerm → (Staged ShelfTerm)) | (linvL x1 x2) := (stage2 linvL (codeLift2 linvL) (stageB x1) (stageB x2)) | (rinvL x1 x2) := (stage2 rinvL (codeLift2 rinvL) (stageB x1) (stageB x2)) def stageCl {A : Type} : ((ClShelfTerm A) → (Staged (ClShelfTerm A))) | (sing x1) := (Now (sing x1)) | (linvCl x1 x2) := (stage2 linvCl (codeLift2 linvCl) (stageCl x1) (stageCl x2)) | (rinvCl x1 x2) := (stage2 rinvCl (codeLift2 rinvCl) (stageCl x1) (stageCl x2)) def stageOpB {n : ℕ} : ((OpShelfTerm n) → (Staged (OpShelfTerm n))) | (v x1) := (const (code (v x1))) | (linvOL x1 x2) := (stage2 linvOL (codeLift2 linvOL) (stageOpB x1) (stageOpB x2)) | (rinvOL x1 x2) := (stage2 rinvOL (codeLift2 rinvOL) (stageOpB x1) (stageOpB x2)) def stageOp {n : ℕ} {A : Type} : ((OpShelfTerm2 n A) → (Staged (OpShelfTerm2 n A))) | (sing2 x1) := (Now (sing2 x1)) | (v2 x1) := (const (code (v2 x1))) | (linvOL2 x1 x2) := (stage2 linvOL2 (codeLift2 linvOL2) (stageOp x1) (stageOp x2)) | (rinvOL2 x1 x2) := (stage2 rinvOL2 (codeLift2 rinvOL2) (stageOp x1) (stageOp x2)) structure StagedRepr (A : Type) (Repr : (Type → Type)) : Type := (linvT : ((Repr A) → ((Repr A) → (Repr A)))) (rinvT : ((Repr A) → ((Repr A) → (Repr A)))) end Shelf
19d0af5fffd54c3abdd480016ea77033358af188
fa02ed5a3c9c0adee3c26887a16855e7841c668b
/src/geometry/manifold/basic_smooth_bundle.lean
9b515116da7ee2720c6c881a4fb6d3b72d162121
[ "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
31,797
lean
/- Copyright (c) 2019 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel -/ import topology.topological_fiber_bundle import geometry.manifold.smooth_manifold_with_corners /-! # Basic smooth bundles In general, a smooth bundle is a bundle over a smooth manifold, whose fiber is a manifold, and for which the coordinate changes are smooth. In this definition, there are charts involved at several places: in the manifold structure of the base, in the manifold structure of the fibers, and in the local trivializations. This makes it a complicated object in general. There is however a specific situation where things are much simpler: when the fiber is a vector space (no need for charts for the fibers), and when the local trivializations of the bundle and the charts of the base coincide. Then everything is expressed in terms of the charts of the base, making for a much simpler overall structure, which is easier to manipulate formally. Most vector bundles that naturally occur in differential geometry are of this form: the tangent bundle, the cotangent bundle, differential forms (used to define de Rham cohomology) and the bundle of Riemannian metrics. Therefore, it is worth defining a specific constructor for this kind of bundle, that we call basic smooth bundles. A basic smooth bundle is thus a smooth bundle over a smooth manifold whose fiber is a vector space, and which is trivial in the coordinate charts of the base. (We recall that in our notion of manifold there is a distinguished atlas, which does not need to be maximal: we require the triviality above this specific atlas). It can be constructed from a basic smooth bundled core, defined below, specifying the changes in the fiber when one goes from one coordinate chart to another one. We do not require that this changes in fiber are linear, but only diffeomorphisms. ## Main definitions * `basic_smooth_bundle_core I M F`: assuming that `M` is a smooth manifold over the model with corners `I` on `(𝕜, E, H)`, and `F` is a normed vector space over `𝕜`, this structure registers, for each pair of charts of `M`, a smooth change of coordinates on `F`. This is the core structure from which one will build a smooth bundle with fiber `F` over `M`. Let `Z` be a basic smooth bundle core over `M` with fiber `F`. We define `Z.to_topological_fiber_bundle_core`, the (topological) fiber bundle core associated to `Z`. From it, we get a space `Z.to_topological_fiber_bundle_core.total_space` (which as a Type is just `Σ (x : M), F`), with the fiber bundle topology. It inherits a manifold structure (where the charts are in bijection with the charts of the basis). We show that this manifold is smooth. Then we use this machinery to construct the tangent bundle of a smooth manifold. * `tangent_bundle_core I M`: the basic smooth bundle core associated to a smooth manifold `M` over a model with corners `I`. * `tangent_bundle I M` : the total space of `tangent_bundle_core I M`. It is itself a smooth manifold over the model with corners `I.tangent`, the product of `I` and the trivial model with corners on `E`. * `tangent_space I x` : the tangent space to `M` at `x` * `tangent_bundle.proj I M`: the projection from the tangent bundle to the base manifold ## Implementation notes In the definition of a basic smooth bundle core, we do not require that the coordinate changes of the fibers are linear map, only that they are diffeomorphisms. Therefore, the fibers of the resulting fiber bundle do not inherit a vector space structure (as an algebraic object) in general. As the fiber, as a type, is just `F`, one can still always register the vector space structure, but it does not make sense to do so (i.e., it will not lead to any useful theorem) unless this structure is canonical, i.e., the coordinate changes are linear maps. For instance, we register the vector space structure on the fibers of the tangent bundle. However, we do not register the normed space structure coming from that of `F` (as it is not canonical, and we also want to keep the possibility to add a Riemannian structure on the manifold later on without having two competing normed space instances on the tangent spaces). We require `F` to be a normed space, and not just a topological vector space, as we want to talk about smooth functions on `F`. The notion of derivative requires a norm to be defined. ## TODO construct the cotangent bundle, and the bundles of differential forms. They should follow functorially from the description of the tangent bundle as a basic smooth bundle. ## Tags Smooth fiber bundle, vector bundle, tangent space, tangent bundle -/ noncomputable theory universe u open topological_space set open_locale manifold topological_space /-- Core structure used to create a smooth bundle above `M` (a manifold over the model with corner `I`) with fiber the normed vector space `F` over `𝕜`, which is trivial in the chart domains of `M`. This structure registers the changes in the fibers when one changes coordinate charts in the base. We do not require the change of coordinates of the fibers to be linear, only smooth. Therefore, the fibers of the resulting bundle will not inherit a canonical vector space structure in general. -/ structure basic_smooth_bundle_core {𝕜 : Type*} [nondiscrete_normed_field 𝕜] {E : Type*} [normed_group E] [normed_space 𝕜 E] {H : Type*} [topological_space H] (I : model_with_corners 𝕜 E H) (M : Type*) [topological_space M] [charted_space H M] [smooth_manifold_with_corners I M] (F : Type*) [normed_group F] [normed_space 𝕜 F] := (coord_change : atlas H M → atlas H M → H → F → F) (coord_change_self : ∀ i : atlas H M, ∀ x ∈ i.1.target, ∀ v, coord_change i i x v = v) (coord_change_comp : ∀ i j k : atlas H M, ∀ x ∈ ((i.1.symm.trans j.1).trans (j.1.symm.trans k.1)).source, ∀ v, (coord_change j k ((i.1.symm.trans j.1) x)) (coord_change i j x v) = coord_change i k x v) (coord_change_smooth : ∀ i j : atlas H M, times_cont_diff_on 𝕜 ∞ (λp : E × F, coord_change i j (I.symm p.1) p.2) ((I '' (i.1.symm.trans j.1).source).prod (univ : set F))) /-- The trivial basic smooth bundle core, in which all the changes of coordinates are the identity. -/ def trivial_basic_smooth_bundle_core {𝕜 : Type*} [nondiscrete_normed_field 𝕜] {E : Type*} [normed_group E] [normed_space 𝕜 E] {H : Type*} [topological_space H] (I : model_with_corners 𝕜 E H) (M : Type*) [topological_space M] [charted_space H M] [smooth_manifold_with_corners I M] (F : Type*) [normed_group F] [normed_space 𝕜 F] : basic_smooth_bundle_core I M F := { coord_change := λ i j x v, v, coord_change_self := λ i x hx v, rfl, coord_change_comp := λ i j k x hx v, rfl, coord_change_smooth := λ i j, times_cont_diff_snd.times_cont_diff_on } namespace basic_smooth_bundle_core variables {𝕜 : Type*} [nondiscrete_normed_field 𝕜] {E : Type*} [normed_group E] [normed_space 𝕜 E] {H : Type*} [topological_space H] {I : model_with_corners 𝕜 E H} {M : Type*} [topological_space M] [charted_space H M] [smooth_manifold_with_corners I M] {F : Type*} [normed_group F] [normed_space 𝕜 F] (Z : basic_smooth_bundle_core I M F) instance : inhabited (basic_smooth_bundle_core I M F) := ⟨trivial_basic_smooth_bundle_core I M F⟩ /-- Fiber bundle core associated to a basic smooth bundle core -/ def to_topological_fiber_bundle_core : topological_fiber_bundle_core (atlas H M) M F := { base_set := λi, i.1.source, is_open_base_set := λi, i.1.open_source, index_at := λx, ⟨chart_at H x, chart_mem_atlas H x⟩, mem_base_set_at := λx, mem_chart_source H x, coord_change := λi j x v, Z.coord_change i j (i.1 x) v, coord_change_self := λi x hx v, Z.coord_change_self i (i.1 x) (i.1.map_source hx) v, coord_change_comp := λi j k x ⟨⟨hx1, hx2⟩, hx3⟩ v, begin have := Z.coord_change_comp i j k (i.1 x) _ v, convert this using 2, { simp only [hx1] with mfld_simps }, { simp only [hx1, hx2, hx3] with mfld_simps } end, coord_change_continuous := λi j, begin have A : continuous_on (λp : E × F, Z.coord_change i j (I.symm p.1) p.2) ((I '' (i.1.symm.trans j.1).source).prod (univ : set F)) := (Z.coord_change_smooth i j).continuous_on, have B : continuous_on (λx : M, I (i.1 x)) i.1.source := I.continuous.comp_continuous_on i.1.continuous_on, have C : continuous_on (λp : M × F, (⟨I (i.1 p.1), p.2⟩ : E × F)) (i.1.source.prod univ), { apply continuous_on.prod _ continuous_snd.continuous_on, exact B.comp continuous_fst.continuous_on (prod_subset_preimage_fst _ _) }, have C' : continuous_on (λp : M × F, (⟨I (i.1 p.1), p.2⟩ : E × F)) ((i.1.source ∩ j.1.source).prod univ) := continuous_on.mono C (prod_mono (inter_subset_left _ _) (subset.refl _)), have D : (i.1.source ∩ j.1.source).prod univ ⊆ (λ (p : M × F), (I (i.1 p.1), p.2)) ⁻¹' ((I '' (i.1.symm.trans j.1).source).prod univ), { rintros ⟨x, v⟩ hx, simp only with mfld_simps at hx, simp only [hx] with mfld_simps }, convert continuous_on.comp A C' D, ext p, simp only with mfld_simps end } @[simp, mfld_simps] lemma base_set (i : atlas H M) : (Z.to_topological_fiber_bundle_core.local_triv_ext i).base_set = i.1.source := rfl /-- Local chart for the total space of a basic smooth bundle -/ def chart {e : local_homeomorph M H} (he : e ∈ atlas H M) : local_homeomorph (Z.to_topological_fiber_bundle_core.total_space) (model_prod H F) := (Z.to_topological_fiber_bundle_core.local_triv ⟨e, he⟩).trans (local_homeomorph.prod e (local_homeomorph.refl F)) @[simp, mfld_simps] lemma chart_source (e : local_homeomorph M H) (he : e ∈ atlas H M) : (Z.chart he).source = Z.to_topological_fiber_bundle_core.proj ⁻¹' e.source := by { simp only [chart, mem_prod], mfld_set_tac } @[simp, mfld_simps] lemma chart_target (e : local_homeomorph M H) (he : e ∈ atlas H M) : (Z.chart he).target = e.target.prod univ := by { simp only [chart], mfld_set_tac } /-- The total space of a basic smooth bundle is endowed with a charted space structure, where the charts are in bijection with the charts of the basis. -/ instance to_charted_space : charted_space (model_prod H F) Z.to_topological_fiber_bundle_core.total_space := { atlas := ⋃(e : local_homeomorph M H) (he : e ∈ atlas H M), {Z.chart he}, chart_at := λp, Z.chart (chart_mem_atlas H p.1), mem_chart_source := λp, by simp [mem_chart_source], chart_mem_atlas := λp, begin simp only [mem_Union, mem_singleton_iff, chart_mem_atlas], exact ⟨chart_at H p.1, chart_mem_atlas H p.1, rfl⟩ end } lemma mem_atlas_iff (f : local_homeomorph Z.to_topological_fiber_bundle_core.total_space (model_prod H F)) : f ∈ atlas (model_prod H F) Z.to_topological_fiber_bundle_core.total_space ↔ ∃(e : local_homeomorph M H) (he : e ∈ atlas H M), f = Z.chart he := by simp only [atlas, mem_Union, mem_singleton_iff] @[simp, mfld_simps] lemma mem_chart_source_iff (p q : Z.to_topological_fiber_bundle_core.total_space) : p ∈ (chart_at (model_prod H F) q).source ↔ p.1 ∈ (chart_at H q.1).source := by simp only [chart_at] with mfld_simps @[simp, mfld_simps] lemma mem_chart_target_iff (p : H × F) (q : Z.to_topological_fiber_bundle_core.total_space) : p ∈ (chart_at (model_prod H F) q).target ↔ p.1 ∈ (chart_at H q.1).target := by simp only [chart_at] with mfld_simps @[simp, mfld_simps] lemma coe_chart_at_fst (p q : Z.to_topological_fiber_bundle_core.total_space) : ((chart_at (model_prod H F) q) p).1 = chart_at H q.1 p.1 := rfl @[simp, mfld_simps] lemma coe_chart_at_symm_fst (p : H × F) (q : Z.to_topological_fiber_bundle_core.total_space) : ((chart_at (model_prod H F) q).symm p).1 = ((chart_at H q.1).symm : H → M) p.1 := rfl /-- Smooth manifold structure on the total space of a basic smooth bundle -/ instance to_smooth_manifold : smooth_manifold_with_corners (I.prod (𝓘(𝕜, F))) Z.to_topological_fiber_bundle_core.total_space := begin /- We have to check that the charts belong to the smooth groupoid, i.e., they are smooth on their source, and their inverses are smooth on the target. Since both objects are of the same kind, it suffices to prove the first statement in A below, and then glue back the pieces at the end. -/ let J := model_with_corners.to_local_equiv (I.prod (𝓘(𝕜, F))), have A : ∀ (e e' : local_homeomorph M H) (he : e ∈ atlas H M) (he' : e' ∈ atlas H M), times_cont_diff_on 𝕜 ∞ (J ∘ ((Z.chart he).symm.trans (Z.chart he')) ∘ J.symm) (J.symm ⁻¹' ((Z.chart he).symm.trans (Z.chart he')).source ∩ range J), { assume e e' he he', have : J.symm ⁻¹' ((chart Z he).symm.trans (chart Z he')).source ∩ range J = (I.symm ⁻¹' (e.symm.trans e').source ∩ range I).prod univ, by { simp only [J, chart, model_with_corners.prod], mfld_set_tac }, rw this, -- check separately that the two components of the coordinate change are smooth apply times_cont_diff_on.prod, show times_cont_diff_on 𝕜 ∞ (λ (p : E × F), (I ∘ e' ∘ e.symm ∘ I.symm) p.1) ((I.symm ⁻¹' (e.symm.trans e').source ∩ range I).prod (univ : set F)), { -- the coordinate change on the base is just a coordinate change for `M`, smooth since -- `M` is smooth have A : times_cont_diff_on 𝕜 ∞ (I ∘ (e.symm.trans e') ∘ I.symm) (I.symm ⁻¹' (e.symm.trans e').source ∩ range I) := (has_groupoid.compatible (times_cont_diff_groupoid ∞ I) he he').1, have B : times_cont_diff_on 𝕜 ∞ (λp : E × F, p.1) ((I.symm ⁻¹' (e.symm.trans e').source ∩ range I).prod univ) := times_cont_diff_fst.times_cont_diff_on, exact times_cont_diff_on.comp A B (prod_subset_preimage_fst _ _) }, show times_cont_diff_on 𝕜 ∞ (λ (p : E × F), Z.coord_change ⟨chart_at H (e.symm (I.symm p.1)), _⟩ ⟨e', he'⟩ ((chart_at H (e.symm (I.symm p.1)) : M → H) (e.symm (I.symm p.1))) (Z.coord_change ⟨e, he⟩ ⟨chart_at H (e.symm (I.symm p.1)), _⟩ (e (e.symm (I.symm p.1))) p.2)) ((I.symm ⁻¹' (e.symm.trans e').source ∩ range I).prod (univ : set F)), { /- The coordinate change in the fiber is more complicated as its definition involves the reference chart chosen at each point. However, it appears with its inverse, so using the cocycle property one can get rid of it, and then conclude using the smoothness of the cocycle as given in the definition of basic smooth bundles. -/ have := Z.coord_change_smooth ⟨e, he⟩ ⟨e', he'⟩, rw I.image_eq at this, apply times_cont_diff_on.congr this, rintros ⟨x, v⟩ hx, simp only with mfld_simps at hx, let f := chart_at H (e.symm (I.symm x)), have A : I.symm x ∈ ((e.symm.trans f).trans (f.symm.trans e')).source, by simp only [hx.1.1, hx.1.2] with mfld_simps, rw e.right_inv hx.1.1, have := Z.coord_change_comp ⟨e, he⟩ ⟨f, chart_mem_atlas _ _⟩ ⟨e', he'⟩ (I.symm x) A v, simpa only [] using this } }, constructor, assume e₀ e₀' he₀ he₀', rcases (Z.mem_atlas_iff _).1 he₀ with ⟨e, he, rfl⟩, rcases (Z.mem_atlas_iff _).1 he₀' with ⟨e', he', rfl⟩, rw [times_cont_diff_groupoid, mem_groupoid_of_pregroupoid], exact ⟨A e e' he he', A e' e he' he⟩ end end basic_smooth_bundle_core section tangent_bundle variables {𝕜 : Type*} [nondiscrete_normed_field 𝕜] {E : Type*} [normed_group E] [normed_space 𝕜 E] {H : Type*} [topological_space H] (I : model_with_corners 𝕜 E H) (M : Type*) [topological_space M] [charted_space H M] [smooth_manifold_with_corners I M] /-- Basic smooth bundle core version of the tangent bundle of a smooth manifold `M` modelled over a model with corners `I` on `(E, H)`. The fibers are equal to `E`, and the coordinate change in the fiber corresponds to the derivative of the coordinate change in `M`. -/ def tangent_bundle_core : basic_smooth_bundle_core I M E := { coord_change := λi j x v, (fderiv_within 𝕜 (I ∘ j.1 ∘ i.1.symm ∘ I.symm) (range I) (I x) : E → E) v, coord_change_smooth := λi j, begin /- To check that the coordinate change of the bundle is smooth, one should just use the smoothness of the charts, and thus the smoothness of their derivatives. -/ rw I.image_eq, have A : times_cont_diff_on 𝕜 ∞ (I ∘ (i.1.symm.trans j.1) ∘ I.symm) (I.symm ⁻¹' (i.1.symm.trans j.1).source ∩ range I) := (has_groupoid.compatible (times_cont_diff_groupoid ∞ I) i.2 j.2).1, have B : unique_diff_on 𝕜 (I.symm ⁻¹' (i.1.symm.trans j.1).source ∩ range I) := I.unique_diff_preimage_source, have C : times_cont_diff_on 𝕜 ∞ (λ (p : E × E), (fderiv_within 𝕜 (I ∘ j.1 ∘ i.1.symm ∘ I.symm) (I.symm ⁻¹' (i.1.symm.trans j.1).source ∩ range I) p.1 : E → E) p.2) ((I.symm ⁻¹' (i.1.symm.trans j.1).source ∩ range I).prod univ) := times_cont_diff_on_fderiv_within_apply A B le_top, have D : ∀ x ∈ (I.symm ⁻¹' (i.1.symm.trans j.1).source ∩ range I), fderiv_within 𝕜 (I ∘ j.1 ∘ i.1.symm ∘ I.symm) (range I) x = fderiv_within 𝕜 (I ∘ j.1 ∘ i.1.symm ∘ I.symm) (I.symm ⁻¹' (i.1.symm.trans j.1).source ∩ range I) x, { assume x hx, have N : I.symm ⁻¹' (i.1.symm.trans j.1).source ∈ nhds x := I.continuous_symm.continuous_at.preimage_mem_nhds (is_open.mem_nhds (local_homeomorph.open_source _) hx.1), symmetry, rw inter_comm, exact fderiv_within_inter N (I.unique_diff _ hx.2) }, apply times_cont_diff_on.congr C, rintros ⟨x, v⟩ hx, have E : x ∈ I.symm ⁻¹' (i.1.symm.trans j.1).source ∩ range I, by simpa only [prod_mk_mem_set_prod_eq, and_true, mem_univ] using hx, have : I (I.symm x) = x, by simp [E.2], dsimp [-subtype.val_eq_coe], rw [this, D x E], refl end, coord_change_self := λi x hx v, begin /- Locally, a self-change of coordinate is just the identity, thus its derivative is the identity. One just needs to write this carefully, paying attention to the sets where the functions are defined. -/ have A : I.symm ⁻¹' (i.1.symm.trans i.1).source ∩ range I ∈ 𝓝[range I] (I x), { rw inter_comm, apply inter_mem_nhds_within, apply I.continuous_symm.continuous_at.preimage_mem_nhds (is_open.mem_nhds (local_homeomorph.open_source _) _), simp only [hx, i.1.map_target] with mfld_simps }, have B : ∀ᶠ y in 𝓝[range I] (I x), (I ∘ i.1 ∘ i.1.symm ∘ I.symm) y = (id : E → E) y, { filter_upwards [A], assume y hy, rw ← I.image_eq at hy, rcases hy with ⟨z, hz⟩, simp only with mfld_simps at hz, simp only [hz.2.symm, hz.1] with mfld_simps }, have C : fderiv_within 𝕜 (I ∘ i.1 ∘ i.1.symm ∘ I.symm) (range I) (I x) = fderiv_within 𝕜 (id : E → E) (range I) (I x) := filter.eventually_eq.fderiv_within_eq I.unique_diff_at_image B (by simp only [hx] with mfld_simps), rw fderiv_within_id I.unique_diff_at_image at C, rw C, refl end, coord_change_comp := λi j u x hx, begin /- The cocycle property is just the fact that the derivative of a composition is the product of the derivatives. One needs however to check that all the functions one considers are smooth, and to pay attention to the domains where these functions are defined, making this proof a little bit cumbersome although there is nothing complicated here. -/ have M : I x ∈ (I.symm ⁻¹' ((i.1.symm.trans j.1).trans (j.1.symm.trans u.1)).source ∩ range I) := ⟨by simpa only [mem_preimage, model_with_corners.left_inv] using hx, mem_range_self _⟩, have U : unique_diff_within_at 𝕜 (I.symm ⁻¹' ((i.1.symm.trans j.1).trans (j.1.symm.trans u.1)).source ∩ range I) (I x) := I.unique_diff_preimage_source _ M, have A : fderiv_within 𝕜 ((I ∘ u.1 ∘ j.1.symm ∘ I.symm) ∘ (I ∘ j.1 ∘ i.1.symm ∘ I.symm)) (I.symm ⁻¹' ((i.1.symm.trans j.1).trans (j.1.symm.trans u.1)).source ∩ range I) (I x) = (fderiv_within 𝕜 (I ∘ u.1 ∘ j.1.symm ∘ I.symm) (I.symm ⁻¹' (j.1.symm.trans u.1).source ∩ range I) ((I ∘ j.1 ∘ i.1.symm ∘ I.symm) (I x))).comp (fderiv_within 𝕜 (I ∘ j.1 ∘ i.1.symm ∘ I.symm) (I.symm ⁻¹' ((i.1.symm.trans j.1).trans (j.1.symm.trans u.1)).source ∩ range I) (I x)), { apply fderiv_within.comp _ _ _ _ U, show differentiable_within_at 𝕜 (I ∘ j.1 ∘ i.1.symm ∘ I.symm) (I.symm ⁻¹' ((i.1.symm.trans j.1).trans (j.1.symm.trans u.1)).source ∩ range I) (I x), { have A : times_cont_diff_on 𝕜 ∞ (I ∘ (i.1.symm.trans j.1) ∘ I.symm) (I.symm ⁻¹' (i.1.symm.trans j.1).source ∩ range I) := (has_groupoid.compatible (times_cont_diff_groupoid ∞ I) i.2 j.2).1, have B : differentiable_on 𝕜 (I ∘ j.1 ∘ i.1.symm ∘ I.symm) (I.symm ⁻¹' ((i.1.symm.trans j.1).trans (j.1.symm.trans u.1)).source ∩ range I), { apply (A.differentiable_on le_top).mono, have : ((i.1.symm.trans j.1).trans (j.1.symm.trans u.1)).source ⊆ (i.1.symm.trans j.1).source := inter_subset_left _ _, exact inter_subset_inter (preimage_mono this) (subset.refl (range I)) }, apply B, simpa only [] with mfld_simps using hx }, show differentiable_within_at 𝕜 (I ∘ u.1 ∘ j.1.symm ∘ I.symm) (I.symm ⁻¹' (j.1.symm.trans u.1).source ∩ range I) ((I ∘ j.1 ∘ i.1.symm ∘ I.symm) (I x)), { have A : times_cont_diff_on 𝕜 ∞ (I ∘ (j.1.symm.trans u.1) ∘ I.symm) (I.symm ⁻¹' (j.1.symm.trans u.1).source ∩ range I) := (has_groupoid.compatible (times_cont_diff_groupoid ∞ I) j.2 u.2).1, apply A.differentiable_on le_top, rw [local_homeomorph.trans_source] at hx, simp only with mfld_simps, exact hx.2 }, show (I.symm ⁻¹' ((i.1.symm.trans j.1).trans (j.1.symm.trans u.1)).source ∩ range I) ⊆ (I ∘ j.1 ∘ i.1.symm ∘ I.symm) ⁻¹' (I.symm ⁻¹' (j.1.symm.trans u.1).source ∩ range I), { assume y hy, simp only with mfld_simps at hy, rw [local_homeomorph.left_inv] at hy, { simp only [hy] with mfld_simps }, { exact hy.1.1.2 } } }, have B : fderiv_within 𝕜 ((I ∘ u.1 ∘ j.1.symm ∘ I.symm) ∘ (I ∘ j.1 ∘ i.1.symm ∘ I.symm)) (I.symm ⁻¹' ((i.1.symm.trans j.1).trans (j.1.symm.trans u.1)).source ∩ range I) (I x) = fderiv_within 𝕜 (I ∘ u.1 ∘ i.1.symm ∘ I.symm) (I.symm ⁻¹' ((i.1.symm.trans j.1).trans (j.1.symm.trans u.1)).source ∩ range I) (I x), { have E : ∀ y ∈ (I.symm ⁻¹' ((i.1.symm.trans j.1).trans (j.1.symm.trans u.1)).source ∩ range I), ((I ∘ u.1 ∘ j.1.symm ∘ I.symm) ∘ (I ∘ j.1 ∘ i.1.symm ∘ I.symm)) y = (I ∘ u.1 ∘ i.1.symm ∘ I.symm) y, { assume y hy, simp only [function.comp_app, model_with_corners.left_inv], rw [j.1.left_inv], exact hy.1.1.2 }, exact fderiv_within_congr U E (E _ M) }, have C : fderiv_within 𝕜 (I ∘ u.1 ∘ i.1.symm ∘ I.symm) (I.symm ⁻¹' ((i.1.symm.trans j.1).trans (j.1.symm.trans u.1)).source ∩ range I) (I x) = fderiv_within 𝕜 (I ∘ u.1 ∘ i.1.symm ∘ I.symm) (range I) (I x), { rw inter_comm, apply fderiv_within_inter _ I.unique_diff_at_image, apply I.continuous_symm.continuous_at.preimage_mem_nhds (is_open.mem_nhds (local_homeomorph.open_source _) _), simpa only [model_with_corners.left_inv] using hx }, have D : fderiv_within 𝕜 (I ∘ u.1 ∘ j.1.symm ∘ I.symm) (I.symm ⁻¹' (j.1.symm.trans u.1).source ∩ range I) ((I ∘ j.1 ∘ i.1.symm ∘ I.symm) (I x)) = fderiv_within 𝕜 (I ∘ u.1 ∘ j.1.symm ∘ I.symm) (range I) ((I ∘ j.1 ∘ i.1.symm ∘ I.symm) (I x)), { rw inter_comm, apply fderiv_within_inter _ I.unique_diff_at_image, apply I.continuous_symm.continuous_at.preimage_mem_nhds (is_open.mem_nhds (local_homeomorph.open_source _) _), rw [local_homeomorph.trans_source] at hx, simp only with mfld_simps, exact hx.2 }, have E : fderiv_within 𝕜 (I ∘ j.1 ∘ i.1.symm ∘ I.symm) (I.symm ⁻¹' ((i.1.symm.trans j.1).trans (j.1.symm.trans u.1)).source ∩ range I) (I x) = fderiv_within 𝕜 (I ∘ j.1 ∘ i.1.symm ∘ I.symm) (range I) (I x), { rw inter_comm, apply fderiv_within_inter _ I.unique_diff_at_image, apply I.continuous_symm.continuous_at.preimage_mem_nhds (is_open.mem_nhds (local_homeomorph.open_source _) _), simpa only [model_with_corners.left_inv] using hx }, rw [B, C, D, E] at A, simp only [A, continuous_linear_map.coe_comp'] with mfld_simps end } variable {M} include I /-- The tangent space at a point of the manifold `M`. It is just `E`. We could use instead `(tangent_bundle_core I M).to_topological_fiber_bundle_core.fiber x`, but we use `E` to help the kernel. -/ @[nolint unused_arguments] def tangent_space (x : M) : Type* := E omit I variable (M) /-- The tangent bundle to a smooth manifold, as a plain type. We could use `(tangent_bundle_core I M).to_topological_fiber_bundle_core.total_space`, but instead we use the (definitionally equal) `Σ (x : M), tangent_space I x`, to make sure that rcasing an element of the tangent bundle gives a second component in the tangent space. -/ @[nolint has_inhabited_instance, reducible] -- is empty if the base manifold is empty def tangent_bundle := Σ (x : M), tangent_space I x /-- The projection from the tangent bundle of a smooth manifold to the manifold. As the tangent bundle is represented internally as a product type, the notation `p.1` also works for the projection of the point `p`. -/ def tangent_bundle.proj : tangent_bundle I M → M := λ p, p.1 variable {M} @[simp, mfld_simps] lemma tangent_bundle.proj_apply (x : M) (v : tangent_space I x) : tangent_bundle.proj I M ⟨x, v⟩ = x := rfl section tangent_bundle_instances /- In general, the definition of tangent_bundle and tangent_space are not reducible, so that type class inference does not pick wrong instances. In this section, we record the right instances for them, noting in particular that the tangent bundle is a smooth manifold. -/ variable (M) instance : topological_space (tangent_bundle I M) := (tangent_bundle_core I M).to_topological_fiber_bundle_core.to_topological_space (atlas H M) instance : charted_space (model_prod H E) (tangent_bundle I M) := (tangent_bundle_core I M).to_charted_space instance : smooth_manifold_with_corners I.tangent (tangent_bundle I M) := (tangent_bundle_core I M).to_smooth_manifold local attribute [reducible] tangent_space variables {M} (x : M) instance : has_continuous_smul 𝕜 (tangent_space I x) := by apply_instance instance : topological_space (tangent_space I x) := by apply_instance instance : add_comm_group (tangent_space I x) := by apply_instance instance : topological_add_group (tangent_space I x) := by apply_instance instance : module 𝕜 (tangent_space I x) := by apply_instance instance : inhabited (tangent_space I x) := ⟨0⟩ end tangent_bundle_instances variable (M) /-- The tangent bundle projection on the basis is a continuous map. -/ lemma tangent_bundle_proj_continuous : continuous (tangent_bundle.proj I M) := topological_fiber_bundle_core.continuous_proj _ /-- The tangent bundle projection on the basis is an open map. -/ lemma tangent_bundle_proj_open : is_open_map (tangent_bundle.proj I M) := topological_fiber_bundle_core.is_open_map_proj _ /-- In the tangent bundle to the model space, the charts are just the canonical identification between a product type and a sigma type, a.k.a. `equiv.sigma_equiv_prod`. -/ @[simp, mfld_simps] lemma tangent_bundle_model_space_chart_at (p : tangent_bundle I H) : (chart_at (model_prod H E) p).to_local_equiv = (equiv.sigma_equiv_prod H E).to_local_equiv := begin have A : ∀ x_fst, fderiv_within 𝕜 (I ∘ I.symm) (range I) (I x_fst) = continuous_linear_map.id 𝕜 E, { assume x_fst, have : fderiv_within 𝕜 (I ∘ I.symm) (range I) (I x_fst) = fderiv_within 𝕜 id (range I) (I x_fst), { refine fderiv_within_congr I.unique_diff_at_image (λy hy, _) (by simp), exact model_with_corners.right_inv _ hy }, rwa fderiv_within_id I.unique_diff_at_image at this }, ext x : 1, show (chart_at (model_prod H E) p : tangent_bundle I H → model_prod H E) x = (equiv.sigma_equiv_prod H E) x, { cases x, simp only [chart_at, basic_smooth_bundle_core.chart, tangent_bundle_core, basic_smooth_bundle_core.to_topological_fiber_bundle_core, A, prod.mk.inj_iff, continuous_linear_map.coe_id'] with mfld_simps, }, show ∀ x, ((chart_at (model_prod H E) p).to_local_equiv).symm x = (equiv.sigma_equiv_prod H E).symm x, { rintros ⟨x_fst, x_snd⟩, simp only [chart_at, basic_smooth_bundle_core.chart, tangent_bundle_core, continuous_linear_map.coe_id', basic_smooth_bundle_core.to_topological_fiber_bundle_core, A] with mfld_simps }, show ((chart_at (model_prod H E) p).to_local_equiv).source = univ, by simp only [chart_at] with mfld_simps, end @[simp, mfld_simps] lemma tangent_bundle_model_space_coe_chart_at (p : tangent_bundle I H) : ⇑(chart_at (model_prod H E) p) = equiv.sigma_equiv_prod H E := by { unfold_coes, simp only with mfld_simps } @[simp, mfld_simps] lemma tangent_bundle_model_space_coe_chart_at_symm (p : tangent_bundle I H) : ((chart_at (model_prod H E) p).symm : model_prod H E → tangent_bundle I H) = (equiv.sigma_equiv_prod H E).symm := by { unfold_coes, simp only with mfld_simps } variable (H) /-- The canonical identification between the tangent bundle to the model space and the product, as a homeomorphism -/ def tangent_bundle_model_space_homeomorph : tangent_bundle I H ≃ₜ model_prod H E := { continuous_to_fun := begin let p : tangent_bundle I H := ⟨I.symm (0 : E), (0 : E)⟩, have : continuous (chart_at (model_prod H E) p), { rw continuous_iff_continuous_on_univ, convert local_homeomorph.continuous_on _, simp only with mfld_simps }, simpa only with mfld_simps using this, end, continuous_inv_fun := begin let p : tangent_bundle I H := ⟨I.symm (0 : E), (0 : E)⟩, have : continuous (chart_at (model_prod H E) p).symm, { rw continuous_iff_continuous_on_univ, convert local_homeomorph.continuous_on _, simp only with mfld_simps }, simpa only with mfld_simps using this, end, .. equiv.sigma_equiv_prod H E } @[simp, mfld_simps] lemma tangent_bundle_model_space_homeomorph_coe : (tangent_bundle_model_space_homeomorph H I : tangent_bundle I H → model_prod H E) = equiv.sigma_equiv_prod H E := rfl @[simp, mfld_simps] lemma tangent_bundle_model_space_homeomorph_coe_symm : ((tangent_bundle_model_space_homeomorph H I).symm : model_prod H E → tangent_bundle I H) = (equiv.sigma_equiv_prod H E).symm := rfl end tangent_bundle
2f05695c9eebbc368b2b73add8506af20798460a
c31182a012eec69da0a1f6c05f42b0f0717d212d
/src/prop_92/prop_92.lean
fcfeb3c5bbc9f73d597872d6d2d339f3adfe2b02
[]
no_license
Ja1941/lean-liquid
fbec3ffc7fc67df1b5ca95b7ee225685ab9ffbdc
8e80ed0cbdf5145d6814e833a674eaf05a1495c1
refs/heads/master
1,689,437,983,362
1,628,362,719,000
1,628,362,719,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
2,551
lean
import pseudo_normed_group.CLC import prop_92.concrete noncomputable theory open_locale nnreal namespace CLCFP variables (r r' : ℝ≥0) (V : SemiNormedGroup) [normed_with_aut r V] (c c₁ c₂ : ℝ≥0) (n : ℕ) variables [fact (0 < r)] [fact (0 < r')] [fact (r' ≤ 1)] [fact (c₂ ≤ r' * c₁)] [fact (c₂ ≤ c₁)] variables (M : (ProFiltPseuNormGrpWithTinv r')ᵒᵖ) include r def T_inv_sub_Tinv := CLCFP.res V r' c₁ c₂ n ≫ CLCFP.T_inv r V r' c₂ n - CLCFP.Tinv V r' c₁ c₂ n lemma norm_T_inv_sub_Tinv_le : ∥(T_inv_sub_Tinv r r' V c₁ c₂ n).app M∥ ≤ (1 + r⁻¹) := begin rw [T_inv_sub_Tinv, sub_eq_neg_add], refine le_trans (norm_add_le _ _) (add_le_add _ _), { rw [category_theory.nat_trans.app_neg, norm_neg], refine le_trans (normed_group_hom.norm_completion_le _) _, exact normed_group_hom.norm_noninc.norm_noninc_iff_norm_le_one.1 (SemiNormedGroup.LocallyConstant_obj_map_norm_noninc _ _ _ _) }, { refine normed_group_hom.norm_comp_le_of_le' 1 r⁻¹ r⁻¹ (mul_one _).symm _ _, { exact CLC.norm_T_inv_le r V _ }, { exact normed_group_hom.norm_noninc.norm_noninc_iff_norm_le_one.1 (res_norm_noninc V r' c₁ c₂ n M) } }, end variables {V c n M} open profinitely_filtered_pseudo_normed_group profinitely_filtered_pseudo_normed_group_with_Tinv open locally_constant category_theory /-- 9.2 of Analytic.pdf -/ lemma T_inv_sub_Tinv_exists_preimage [hr1 : fact (r < 1)] (f : (CLCFP V r' (r' * c) n).obj M) (ε : ℝ≥0) (hε : 0 < ε) : ∃ g : (CLCFP V r' c n).obj M, (T_inv_sub_Tinv r r' V c (r' * c) n).app M g = f ∧ (∥g∥ ≤ (r / (1 - r) + ε) * ∥f∥) := begin obtain ⟨g, hg1, hg2⟩ := @concrete_92 _ _ _ _ _ _ _ _ ((FiltrationPow.cast_le _ _ _ _).app _) (embedding_cast_le _ _) ((FiltrationPow.Tinv r' (r' * c) c _).app _) r V _ (Tinv₀_continuous _ _) hr1 _ f ε hε, refine ⟨g, _, hg2⟩, rw ← hg1, clear hg1, dsimp only [T_inv_sub_Tinv, CLC, T_inv, CLC.T_inv, Tinv, CLCFP.res, whisker_left_app, nat_trans.app_sub, nat_trans.comp_app, whisker_right_app, normed_group_hom.sub_apply, whisker_right_app, functor.comp_map], rw [← SemiNormedGroup.Completion.map_comp, ← normed_group_hom.sub_apply, ← functor.map_sub], refl end variables (V c n M) lemma T_inv_sub_Tinv_surjective [fact (r < 1)] : function.surjective ((T_inv_sub_Tinv r r' V c (r' * c) n).app M) := begin intros f, obtain ⟨g, hg, -⟩ := T_inv_sub_Tinv_exists_preimage r r' f 1 zero_lt_one, exact ⟨g, hg⟩ end end CLCFP
adffb968be577e3cb82b13e860df505bfccaa8c4
b7f22e51856f4989b970961f794f1c435f9b8f78
/tests/lean/run/constr_tac2.lean
20beb9118c574588179035ec0df026d63a682141
[ "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
95
lean
open nat example (n m : ℕ) (H : n < m) : n < succ m := begin constructor 2, exact H end
f3998399fdce246af035a19873e3160224ff8ea6
9dc8cecdf3c4634764a18254e94d43da07142918
/src/data/polynomial/coeff.lean
5e53ed55b57433df1a891872c2a1c80dff09f1e5
[ "Apache-2.0" ]
permissive
jcommelin/mathlib
d8456447c36c176e14d96d9e76f39841f69d2d9b
ee8279351a2e434c2852345c51b728d22af5a156
refs/heads/master
1,664,782,136,488
1,663,638,983,000
1,663,638,983,000
132,563,656
0
0
Apache-2.0
1,663,599,929,000
1,525,760,539,000
Lean
UTF-8
Lean
false
false
12,078
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 import data.nat.choose.sum /-! # 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 polynomial namespace polynomial universes u v variables {R : Type u} {S : Type v} {a b : R} {n m : ℕ} variables [semiring R] {p q r : R[X]} section coeff lemma coeff_one (n : ℕ) : coeff (1 : R[X]) n = if 0 = n then 1 else 0 := coeff_monomial @[simp] lemma coeff_add (p q : R[X]) (n : ℕ) : coeff (p + q) n = coeff p n + coeff q n := by { rcases p, rcases q, simp_rw [←of_finsupp_add, coeff], exact finsupp.add_apply _ _ _ } @[simp] lemma coeff_bit0 (p : R[X]) (n : ℕ) : coeff (bit0 p) n = bit0 (coeff p n) := by simp [bit0] @[simp] lemma coeff_smul [monoid S] [distrib_mul_action S R] (r : S) (p : R[X]) (n : ℕ) : coeff (r • p) n = r • coeff p n := by { rcases p, simp_rw [←of_finsupp_smul, coeff], exact finsupp.smul_apply _ _ _ } lemma support_smul [monoid S] [distrib_mul_action S R] (r : S) (p : R[X]) : support (r • p) ⊆ support p := begin assume i hi, simp [mem_support_iff] at hi ⊢, contrapose! hi, simp [hi] end /-- `polynomial.sum` as a linear map. -/ @[simps] def lsum {R A M : Type*} [semiring R] [semiring A] [add_comm_monoid M] [module R A] [module R M] (f : ℕ → A →ₗ[R] M) : polynomial A →ₗ[R] M := { to_fun := λ p, p.sum (λ n r, f n r), map_add' := λ p q, sum_add_index p q _ (λ n, (f n).map_zero) (λ n _ _, (f n).map_add _ _), map_smul' := λ c p, begin rw [sum_eq_of_subset _ (λ n r, f n r) (λ n, (f n).map_zero) _ (support_smul c p)], simp only [sum_def, finset.smul_sum, coeff_smul, linear_map.map_smul, ring_hom.id_apply] end } variable (R) /-- The nth coefficient, as a linear map. -/ def lcoeff (n : ℕ) : R[X] →ₗ[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 : R[X]) : lcoeff R n f = coeff f n := rfl @[simp] lemma finset_sum_coeff {ι : Type*} (s : finset ι) (f : ι → R[X]) (n : ℕ) : coeff (∑ b in s, f b) n = ∑ b in s, coeff (f b) n := (lcoeff R n).map_sum lemma coeff_sum [semiring S] (n : ℕ) (f : ℕ → R → S[X]) : 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 : R[X]) (n : ℕ) : coeff (p * q) n = ∑ x in nat.antidiagonal n, coeff p x.1 * coeff q x.2 := begin rcases p, rcases q, simp_rw [←of_finsupp_mul, coeff], exact add_monoid_algebra.mul_apply_antidiagonal p q n _ (λ x, nat.mem_antidiagonal) end @[simp] lemma mul_coeff_zero (p q : R[X]) : coeff (p * q) 0 = coeff p 0 * coeff q 0 := by simp [coeff_mul] lemma coeff_mul_X_zero (p : R[X]) : coeff (p * X) 0 = 0 := by simp lemma coeff_X_mul_zero (p : R[X]) : coeff (X * p) 0 = 0 := by simp lemma coeff_C_mul_X_pow (x : R) (k n : ℕ) : coeff (C x * X^k : R[X]) n = if n = k then x else 0 := by { rw [← monomial_eq_C_mul_X, coeff_monomial], congr' 1, simp [eq_comm] } lemma coeff_C_mul_X (x : R) (n : ℕ) : coeff (C x * X : R[X]) n = if n = 1 then x else 0 := by rw [← pow_one X, coeff_C_mul_X_pow] @[simp] lemma coeff_C_mul (p : R[X]) : coeff (C a * p) n = a * coeff p n := begin rcases p, simp_rw [←monomial_zero_left, ←of_finsupp_single, ←of_finsupp_mul, coeff], exact add_monoid_algebra.single_zero_mul_apply p a n end lemma C_mul' (a : R) (f : R[X]) : C a * f = a • f := by { ext, rw [coeff_C_mul, coeff_smul, smul_eq_mul] } @[simp] lemma coeff_mul_C (p : R[X]) (n : ℕ) (a : R) : coeff (p * C a) n = coeff p n * a := begin rcases p, simp_rw [←monomial_zero_left, ←of_finsupp_single, ←of_finsupp_mul, coeff], exact add_monoid_algebra.mul_single_zero_apply p a n end lemma coeff_X_pow (k n : ℕ) : coeff (X^k : R[X]) n = if n = k then 1 else 0 := by simp only [one_mul, ring_hom.map_one, ← coeff_C_mul_X_pow] @[simp] lemma coeff_X_pow_self (n : ℕ) : coeff (X^n : R[X]) n = 1 := by simp [coeff_X_pow] section fewnomials open finset lemma support_binomial {k m : ℕ} (hkm : k ≠ m) {x y : R} (hx : x ≠ 0) (hy : y ≠ 0) : (C x * X ^ k + C y * X ^ m).support = {k, m} := begin apply subset_antisymm (support_binomial' k m x y), simp_rw [insert_subset, singleton_subset_iff, mem_support_iff, coeff_add, coeff_C_mul, coeff_X_pow_self, mul_one, coeff_X_pow, if_neg hkm, if_neg hkm.symm, mul_zero, zero_add, add_zero, ne.def, hx, hy, and_self, not_false_iff], end lemma support_trinomial {k m n : ℕ} (hkm : k < m) (hmn : m < n) {x y z : R} (hx : x ≠ 0) (hy : y ≠ 0) (hz : z ≠ 0) : (C x * X ^ k + C y * X ^ m + C z * X ^ n).support = {k, m, n} := begin apply subset_antisymm (support_trinomial' k m n x y z), simp_rw [insert_subset, singleton_subset_iff, mem_support_iff, coeff_add, coeff_C_mul, coeff_X_pow_self, mul_one, coeff_X_pow, if_neg hkm.ne, if_neg hkm.ne', if_neg hmn.ne, if_neg hmn.ne', if_neg (hkm.trans hmn).ne, if_neg (hkm.trans hmn).ne', mul_zero, add_zero, zero_add, ne.def, hx, hy, hz, and_self, not_false_iff], end lemma card_support_binomial {k m : ℕ} (h : k ≠ m) {x y : R} (hx : x ≠ 0) (hy : y ≠ 0) : (C x * X ^ k + C y * X ^ m).support.card = 2 := by rw [support_binomial h hx hy, card_insert_of_not_mem (mt mem_singleton.mp h), card_singleton] lemma card_support_trinomial {k m n : ℕ} (hkm : k < m) (hmn : m < n) {x y z : R} (hx : x ≠ 0) (hy : y ≠ 0) (hz : z ≠ 0) : (C x * X ^ k + C y * X ^ m + C z * X ^ n).support.card = 3 := by rw [support_trinomial hkm hmn hx hy hz, card_insert_of_not_mem (mt mem_insert.mp (not_or hkm.ne (mt mem_singleton.mp (hkm.trans hmn).ne))), card_insert_of_not_mem (mt mem_singleton.mp hmn.ne), card_singleton] end fewnomials @[simp] theorem coeff_mul_X_pow (p : R[X]) (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 @[simp] theorem coeff_X_pow_mul (p : R[X]) (n d : ℕ) : coeff (polynomial.X ^ n * p) (d + n) = coeff p d := by rw [(commute_X_pow p n).eq, coeff_mul_X_pow] lemma coeff_mul_X_pow' (p : R[X]) (n d : ℕ) : (p * X ^ n).coeff d = ite (n ≤ d) (p.coeff (d - n)) 0 := begin split_ifs, { rw [← tsub_add_cancel_of_le h, coeff_mul_X_pow, add_tsub_cancel_right] }, { refine (coeff_mul _ _ _).trans (finset.sum_eq_zero (λ x hx, _)), rw [coeff_X_pow, if_neg, mul_zero], exact ((le_of_add_le_right (finset.nat.mem_antidiagonal.mp hx).le).trans_lt $ not_le.mp h).ne } end lemma coeff_X_pow_mul' (p : R[X]) (n d : ℕ) : (X ^ n * p).coeff d = ite (n ≤ d) (p.coeff (d - n)) 0 := by rw [(commute_X_pow p n).eq, coeff_mul_X_pow'] @[simp] theorem coeff_mul_X (p : R[X]) (n : ℕ) : coeff (p * X) (n + 1) = coeff p n := by simpa only [pow_one] using coeff_mul_X_pow p 1 n @[simp] theorem coeff_X_mul (p : R[X]) (n : ℕ) : coeff (X * p) (n + 1) = coeff p n := by rw [(commute_X p).eq, coeff_mul_X] theorem coeff_mul_monomial (p : R[X]) (n d : ℕ) (r : R) : coeff (p * monomial n r) (d + n) = coeff p d * r := by rw [monomial_eq_C_mul_X, ←X_pow_mul, ←mul_assoc, coeff_mul_C, coeff_mul_X_pow] theorem coeff_monomial_mul (p : R[X]) (n d : ℕ) (r : R) : coeff (monomial n r * p) (d + n) = r * coeff p d := by rw [monomial_eq_C_mul_X, mul_assoc, coeff_C_mul, X_pow_mul, coeff_mul_X_pow] -- This can already be proved by `simp`. theorem coeff_mul_monomial_zero (p : R[X]) (d : ℕ) (r : R) : coeff (p * monomial 0 r) d = coeff p d * r := coeff_mul_monomial p 0 d r -- This can already be proved by `simp`. theorem coeff_monomial_zero_mul (p : R[X]) (d : ℕ) (r : R) : coeff (monomial 0 r * p) d = r * coeff p d := coeff_monomial_mul p 0 d r theorem mul_X_pow_eq_zero {p : R[X]} {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 mul_X_pow_injective (n : ℕ) : function.injective (λ P : R[X], X ^ n * P) := begin intros P Q hPQ, simp only at hPQ, ext i, rw [← coeff_X_pow_mul P n i, hPQ, coeff_X_pow_mul Q n i] end lemma mul_X_injective : function.injective (λ P : R[X], X * P) := pow_one (X : R[X]) ▸ mul_X_pow_injective 1 lemma C_mul_X_pow_eq_monomial (c : R) (n : ℕ) : C c * X^n = monomial n c := monomial_eq_C_mul_X.symm lemma coeff_X_add_C_pow (r : R) (n k : ℕ) : ((X + C r) ^ n).coeff k = r ^ (n - k) * (n.choose k : R) := begin rw [(commute_X (C r : R[X])).add_pow, ← lcoeff_apply, linear_map.map_sum], simp only [one_pow, mul_one, lcoeff_apply, ← C_eq_nat_cast, ←C_pow, coeff_mul_C, nat.cast_id], rw [finset.sum_eq_single k, coeff_X_pow_self, one_mul], { intros _ _ h, simp [coeff_X_pow, h.symm] }, { simp only [coeff_X_pow_self, one_mul, not_lt, finset.mem_range], intro h, rw [nat.choose_eq_zero_of_lt h, nat.cast_zero, mul_zero] } end lemma coeff_X_add_one_pow (R : Type*) [semiring R] (n k : ℕ) : ((X + 1) ^ n).coeff k = (n.choose k : R) := by rw [←C_1, coeff_X_add_C_pow, one_pow, one_mul] lemma coeff_one_add_X_pow (R : Type*) [semiring R] (n k : ℕ) : ((1 + X) ^ n).coeff k = (n.choose k : R) := by rw [add_comm _ X, coeff_X_add_one_pow] lemma C_dvd_iff_dvd_coeff (r : R) (φ : R[X]) : 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 ψ : R[X] := ∑ 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 : R[X]) (n : ℕ) : coeff (bit0 P * Q) n = 2 * coeff (P * Q) n := by simp [bit0, add_mul] lemma coeff_bit1_mul (P Q : R[X]) (n : ℕ) : coeff (bit1 P * Q) n = 2 * coeff (P * Q) n + coeff Q n := by simp [bit1, add_mul, coeff_bit0_mul] lemma smul_eq_C_mul (a : R) : a • p = C a * p := by simp [ext_iff] lemma update_eq_add_sub_coeff {R : Type*} [ring R] (p : R[X]) (n : ℕ) (a : R) : p.update n a = p + (polynomial.C (a - p.coeff n) * polynomial.X ^ n) := begin ext, rw [coeff_update_apply, coeff_add, coeff_C_mul_X_pow], split_ifs with h; simp [h] end end coeff section cast @[simp] lemma nat_cast_coeff_zero {n : ℕ} {R : Type*} [semiring R] : (n : R[X]).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 : R[X]) = ↑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 : R[X]).coeff 0 = i := by cases i; simp @[simp, norm_cast] theorem int_cast_inj {m n : ℤ} {R : Type*} [ring R] [char_zero R] : (↑m : R[X]) = ↑n ↔ m = n := begin fsplit, { intro h, apply_fun (λ p, p.coeff 0) at h, simpa using h, }, { rintro rfl, refl, }, end end cast instance [char_zero R] : char_zero R[X] := { cast_injective := λ x y, nat_cast_inj.mp } end polynomial
ea1f65e9be77aee71e89a86a048cdb4a21b0a4c9
b7f22e51856f4989b970961f794f1c435f9b8f78
/tests/lean/run/esimp1.lean
b7ce1e4d6d8167c61b386aa6f840837766ba90cb
[ "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
572
lean
open nat example (x y : nat) (H : (fun (a : nat), sigma.pr1 ⟨a, y⟩) x = 0) : x = 0 := begin esimp at H, exact H end definition foo [irreducible] (a : nat) := a example (x y : nat) (H : (fun (a : nat), sigma.pr1 ⟨foo a, y⟩) x = 0) : x = 0 := begin esimp at H, esimp ↑foo at H, exact H end example (x y : nat) (H : x = 0) : (fun (a : nat), sigma.pr1 ⟨foo a, y⟩) x = 0 := begin esimp, esimp ↑foo, exact H end example (x y : nat) (H : x = 0) : (fun (a : nat), sigma.pr1 ⟨foo a, y⟩) x = 0 := begin esimp, unfold foo, exact H end
a0c92c73d094814be4bfad355e299be8ef698fce
947fa6c38e48771ae886239b4edce6db6e18d0fb
/src/analysis/inner_product_space/pi_L2.lean
77fe7cf13684417956a99220220e859633b69d46
[ "Apache-2.0" ]
permissive
ramonfmir/mathlib
c5dc8b33155473fab97c38bd3aa6723dc289beaa
14c52e990c17f5a00c0cc9e09847af16fabbed25
refs/heads/master
1,661,979,343,526
1,660,830,384,000
1,660,830,384,000
182,072,989
0
0
null
1,555,585,876,000
1,555,585,876,000
null
UTF-8
Lean
false
false
35,191
lean
/- Copyright (c) 2020 Joseph Myers. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joseph Myers, Sébastien Gouëzel, Heather Macbeth -/ import analysis.inner_product_space.projection import linear_algebra.finite_dimensional import analysis.normed_space.pi_Lp /-! # `L²` inner product space structure on finite products of inner product spaces The `L²` norm on a finite product of inner product spaces is compatible with an inner product $$ \langle x, y\rangle = \sum \langle x_i, y_i \rangle. $$ This is recorded in this file as an inner product space instance on `pi_Lp 2`. This file develops the notion of a finite dimensional Hilbert space over `𝕜 = ℂ, ℝ`, referred to as `E`. We define an `orthonormal_basis 𝕜 ι E` as a linear isometric equivalence between `E` and `euclidean_space 𝕜 ι`. Then `std_orthonormal_basis` shows that such an equivalence always exists if `E` is finite dimensional. We provide language for converting between a basis that is orthonormal and an orthonormal basis (e.g. `basis.to_orthonormal_basis`). We show that orthonormal bases for each summand in a direct sum of spaces can be combined into an orthonormal basis for the the whole sum in `direct_sum.submodule_is_internal.subordinate_orthonormal_basis`. In the last section, various properties of matrices are explored. ## Main definitions - `euclidean_space 𝕜 n`: defined to be `pi_Lp 2 (n → 𝕜)` for any `fintype n`, i.e., the space from functions to `n` to `𝕜` with the `L²` norm. We register several instances on it (notably that it is a finite-dimensional inner product space). - `orthonormal_basis 𝕜 ι`: defined to be an isometry to Euclidean space from a given finite-dimensional innner product space, `E ≃ₗᵢ[𝕜] euclidean_space 𝕜 ι`. - `basis.to_orthonormal_basis`: constructs an `orthonormal_basis` for a finite-dimensional Euclidean space from a `basis` which is `orthonormal`. - `orthonormal.exists_orthonormal_basis_extension`: provides an existential result of an `orthonormal_basis` extending a given orthonormal set - `exists_orthonormal_basis`: provides an orthonormal basis on a finite dimensional vector space - `std_orthonormal_basis`: provides an arbitrarily-chosen `orthonormal_basis` of a given finite dimensional inner product space For consequences in infinite dimension (Hilbert bases, etc.), see the file `analysis.inner_product_space.l2_space`. -/ open real set filter is_R_or_C submodule open_locale big_operators uniformity topological_space nnreal ennreal complex_conjugate direct_sum noncomputable theory variables {ι : Type*} {ι' : Type*} variables {𝕜 : Type*} [is_R_or_C 𝕜] {E : Type*} [inner_product_space 𝕜 E] variables {E' : Type*} [inner_product_space 𝕜 E'] variables {F : Type*} [inner_product_space ℝ F] variables {F' : Type*} [inner_product_space ℝ F'] local notation `⟪`x`, `y`⟫` := @inner 𝕜 _ _ x y /- If `ι` is a finite type and each space `f i`, `i : ι`, is an inner product space, then `Π i, f i` is an inner product space as well. Since `Π i, f i` is endowed with the sup norm, we use instead `pi_Lp 2 f` for the product space, which is endowed with the `L^2` norm. -/ instance pi_Lp.inner_product_space {ι : Type*} [fintype ι] (f : ι → Type*) [Π i, inner_product_space 𝕜 (f i)] : inner_product_space 𝕜 (pi_Lp 2 f) := { inner := λ x y, ∑ i, inner (x i) (y i), norm_sq_eq_inner := λ x, by simp only [pi_Lp.norm_sq_eq_of_L2, add_monoid_hom.map_sum, ← norm_sq_eq_inner, one_div], conj_sym := begin intros x y, unfold inner, rw ring_hom.map_sum, apply finset.sum_congr rfl, rintros z -, apply inner_conj_sym, end, add_left := λ x y z, show ∑ i, inner (x i + y i) (z i) = ∑ i, inner (x i) (z i) + ∑ i, inner (y i) (z i), by simp only [inner_add_left, finset.sum_add_distrib], smul_left := λ x y r, show ∑ (i : ι), inner (r • x i) (y i) = (conj r) * ∑ i, inner (x i) (y i), by simp only [finset.mul_sum, inner_smul_left] } @[simp] lemma pi_Lp.inner_apply {ι : Type*} [fintype ι] {f : ι → Type*} [Π i, inner_product_space 𝕜 (f i)] (x y : pi_Lp 2 f) : ⟪x, y⟫ = ∑ i, ⟪x i, y i⟫ := rfl /-- The standard real/complex Euclidean space, functions on a finite type. For an `n`-dimensional space use `euclidean_space 𝕜 (fin n)`. -/ @[reducible, nolint unused_arguments] def euclidean_space (𝕜 : Type*) [is_R_or_C 𝕜] (n : Type*) [fintype n] : Type* := pi_Lp 2 (λ (i : n), 𝕜) lemma euclidean_space.nnnorm_eq {𝕜 : Type*} [is_R_or_C 𝕜] {n : Type*} [fintype n] (x : euclidean_space 𝕜 n) : ∥x∥₊ = nnreal.sqrt (∑ i, ∥x i∥₊ ^ 2) := pi_Lp.nnnorm_eq_of_L2 x lemma euclidean_space.norm_eq {𝕜 : Type*} [is_R_or_C 𝕜] {n : Type*} [fintype n] (x : euclidean_space 𝕜 n) : ∥x∥ = real.sqrt (∑ i, ∥x i∥ ^ 2) := by simpa only [real.coe_sqrt, nnreal.coe_sum] using congr_arg (coe : ℝ≥0 → ℝ) x.nnnorm_eq lemma euclidean_space.dist_eq {𝕜 : Type*} [is_R_or_C 𝕜] {n : Type*} [fintype n] (x y : euclidean_space 𝕜 n) : dist x y = (∑ i, dist (x i) (y i) ^ 2).sqrt := (pi_Lp.dist_eq_of_L2 x y : _) lemma euclidean_space.nndist_eq {𝕜 : Type*} [is_R_or_C 𝕜] {n : Type*} [fintype n] (x y : euclidean_space 𝕜 n) : nndist x y = (∑ i, nndist (x i) (y i) ^ 2).sqrt := (pi_Lp.nndist_eq_of_L2 x y : _) lemma euclidean_space.edist_eq {𝕜 : Type*} [is_R_or_C 𝕜] {n : Type*} [fintype n] (x y : euclidean_space 𝕜 n) : edist x y = (∑ i, edist (x i) (y i) ^ 2) ^ (1 / 2 : ℝ) := (pi_Lp.edist_eq_of_L2 x y : _) variables [fintype ι] section local attribute [reducible] pi_Lp instance : finite_dimensional 𝕜 (euclidean_space 𝕜 ι) := by apply_instance instance : inner_product_space 𝕜 (euclidean_space 𝕜 ι) := by apply_instance @[simp] lemma finrank_euclidean_space : finite_dimensional.finrank 𝕜 (euclidean_space 𝕜 ι) = fintype.card ι := by simp lemma finrank_euclidean_space_fin {n : ℕ} : finite_dimensional.finrank 𝕜 (euclidean_space 𝕜 (fin n)) = n := by simp lemma euclidean_space.inner_eq_star_dot_product (x y : euclidean_space 𝕜 ι) : ⟪x, y⟫ = matrix.dot_product (star $ pi_Lp.equiv _ _ x) (pi_Lp.equiv _ _ y) := rfl /-- A finite, mutually orthogonal family of subspaces of `E`, which span `E`, induce an isometry from `E` to `pi_Lp 2` of the subspaces equipped with the `L2` inner product. -/ def direct_sum.is_internal.isometry_L2_of_orthogonal_family [decidable_eq ι] {V : ι → submodule 𝕜 E} (hV : direct_sum.is_internal V) (hV' : @orthogonal_family 𝕜 _ _ _ _ (λ i, V i) _ (λ i, (V i).subtypeₗᵢ)) : E ≃ₗᵢ[𝕜] pi_Lp 2 (λ i, V i) := begin let e₁ := direct_sum.linear_equiv_fun_on_fintype 𝕜 ι (λ i, V i), let e₂ := linear_equiv.of_bijective (direct_sum.coe_linear_map V) hV.injective hV.surjective, refine (e₂.symm.trans e₁).isometry_of_inner _, suffices : ∀ v w, ⟪v, w⟫ = ⟪e₂ (e₁.symm v), e₂ (e₁.symm w)⟫, { intros v₀ w₀, convert this (e₁ (e₂.symm v₀)) (e₁ (e₂.symm w₀)); simp only [linear_equiv.symm_apply_apply, linear_equiv.apply_symm_apply] }, intros v w, transitivity ⟪(∑ i, (V i).subtypeₗᵢ (v i)), ∑ i, (V i).subtypeₗᵢ (w i)⟫, { simp only [sum_inner, hV'.inner_right_fintype, pi_Lp.inner_apply] }, { congr; simp } end @[simp] lemma direct_sum.is_internal.isometry_L2_of_orthogonal_family_symm_apply [decidable_eq ι] {V : ι → submodule 𝕜 E} (hV : direct_sum.is_internal V) (hV' : @orthogonal_family 𝕜 _ _ _ _ (λ i, V i) _ (λ i, (V i).subtypeₗᵢ)) (w : pi_Lp 2 (λ i, V i)) : (hV.isometry_L2_of_orthogonal_family hV').symm w = ∑ i, (w i : E) := begin classical, let e₁ := direct_sum.linear_equiv_fun_on_fintype 𝕜 ι (λ i, V i), let e₂ := linear_equiv.of_bijective (direct_sum.coe_linear_map V) hV.injective hV.surjective, suffices : ∀ v : ⨁ i, V i, e₂ v = ∑ i, e₁ v i, { exact this (e₁.symm w) }, intros v, simp [e₂, direct_sum.coe_linear_map, direct_sum.to_module, dfinsupp.sum_add_hom_apply] end end variables (ι 𝕜) -- TODO : This should be generalized to `pi_Lp` with finite dimensional factors. /-- `pi_Lp.linear_equiv` upgraded to a continuous linear map between `euclidean_space 𝕜 ι` and `ι → 𝕜`. -/ @[simps] def euclidean_space.equiv : euclidean_space 𝕜 ι ≃L[𝕜] (ι → 𝕜) := (pi_Lp.linear_equiv 2 𝕜 (λ i : ι, 𝕜)).to_continuous_linear_equiv variables {ι 𝕜} -- TODO : This should be generalized to `pi_Lp`. /-- The projection on the `i`-th coordinate of `euclidean_space 𝕜 ι`, as a linear map. -/ @[simps] def euclidean_space.projₗ (i : ι) : euclidean_space 𝕜 ι →ₗ[𝕜] 𝕜 := (linear_map.proj i).comp (pi_Lp.linear_equiv 2 𝕜 (λ i : ι, 𝕜) : euclidean_space 𝕜 ι →ₗ[𝕜] ι → 𝕜) -- TODO : This should be generalized to `pi_Lp`. /-- The projection on the `i`-th coordinate of `euclidean_space 𝕜 ι`, as a continuous linear map. -/ @[simps] def euclidean_space.proj (i : ι) : euclidean_space 𝕜 ι →L[𝕜] 𝕜 := ⟨euclidean_space.projₗ i, continuous_apply i⟩ -- TODO : This should be generalized to `pi_Lp`. /-- The vector given in euclidean space by being `1 : 𝕜` at coordinate `i : ι` and `0 : 𝕜` at all other coordinates. -/ def euclidean_space.single [decidable_eq ι] (i : ι) (a : 𝕜) : euclidean_space 𝕜 ι := (pi_Lp.equiv _ _).symm (pi.single i a) @[simp] lemma pi_Lp.equiv_single [decidable_eq ι] (i : ι) (a : 𝕜) : pi_Lp.equiv _ _ (euclidean_space.single i a) = pi.single i a := rfl @[simp] lemma pi_Lp.equiv_symm_single [decidable_eq ι] (i : ι) (a : 𝕜) : (pi_Lp.equiv _ _).symm (pi.single i a) = euclidean_space.single i a := rfl @[simp] theorem euclidean_space.single_apply [decidable_eq ι] (i : ι) (a : 𝕜) (j : ι) : (euclidean_space.single i a) j = ite (j = i) a 0 := by { rw [euclidean_space.single, pi_Lp.equiv_symm_apply, ← pi.single_apply i a j] } lemma euclidean_space.inner_single_left [decidable_eq ι] (i : ι) (a : 𝕜) (v : euclidean_space 𝕜 ι) : ⟪euclidean_space.single i (a : 𝕜), v⟫ = conj a * (v i) := by simp [apply_ite conj] lemma euclidean_space.inner_single_right [decidable_eq ι] (i : ι) (a : 𝕜) (v : euclidean_space 𝕜 ι) : ⟪v, euclidean_space.single i (a : 𝕜)⟫ = a * conj (v i) := by simp [apply_ite conj, mul_comm] lemma euclidean_space.pi_Lp_congr_left_single [decidable_eq ι] {ι' : Type*} [fintype ι'] [decidable_eq ι'] (e : ι' ≃ ι) (i' : ι') : linear_isometry_equiv.pi_Lp_congr_left 2 𝕜 𝕜 e (euclidean_space.single i' (1:𝕜)) = euclidean_space.single (e i') (1:𝕜) := begin ext i, simpa using if_congr e.symm_apply_eq rfl rfl end variables (ι 𝕜 E) /-- An orthonormal basis on E is an identification of `E` with its dimensional-matching `euclidean_space 𝕜 ι`. -/ structure orthonormal_basis := of_repr :: (repr : E ≃ₗᵢ[𝕜] euclidean_space 𝕜 ι) variables {ι 𝕜 E} namespace orthonormal_basis instance : inhabited (orthonormal_basis ι 𝕜 (euclidean_space 𝕜 ι)) := ⟨of_repr (linear_isometry_equiv.refl 𝕜 (euclidean_space 𝕜 ι))⟩ /-- `b i` is the `i`th basis vector. -/ instance : has_coe_to_fun (orthonormal_basis ι 𝕜 E) (λ _, ι → E) := { coe := λ b i, by classical; exact b.repr.symm (euclidean_space.single i (1 : 𝕜)) } @[simp] lemma coe_of_repr [decidable_eq ι] (e : E ≃ₗᵢ[𝕜] euclidean_space 𝕜 ι) : ⇑(orthonormal_basis.of_repr e) = λ i, e.symm (euclidean_space.single i (1 : 𝕜)) := begin rw coe_fn, unfold has_coe_to_fun.coe, funext, congr, simp only [eq_iff_true_of_subsingleton], end @[simp] protected lemma repr_symm_single [decidable_eq ι] (b : orthonormal_basis ι 𝕜 E) (i : ι) : b.repr.symm (euclidean_space.single i (1:𝕜)) = b i := by { classical, congr, simp, } @[simp] protected lemma repr_self [decidable_eq ι] (b : orthonormal_basis ι 𝕜 E) (i : ι) : b.repr (b i) = euclidean_space.single i (1:𝕜) := by rw [← b.repr_symm_single i, linear_isometry_equiv.apply_symm_apply] protected lemma repr_apply_apply (b : orthonormal_basis ι 𝕜 E) (v : E) (i : ι) : b.repr v i = ⟪b i, v⟫ := begin classical, rw [← b.repr.inner_map_map (b i) v, b.repr_self i, euclidean_space.inner_single_left], simp only [one_mul, eq_self_iff_true, map_one], end @[simp] protected lemma orthonormal (b : orthonormal_basis ι 𝕜 E) : orthonormal 𝕜 b := begin classical, rw orthonormal_iff_ite, intros i j, rw [← b.repr.inner_map_map (b i) (b j), b.repr_self i, b.repr_self j, euclidean_space.inner_single_left, euclidean_space.single_apply, map_one, one_mul], end /-- The `basis ι 𝕜 E` underlying the `orthonormal_basis` --/ protected def to_basis (b : orthonormal_basis ι 𝕜 E) : basis ι 𝕜 E := basis.of_equiv_fun b.repr.to_linear_equiv @[simp] protected lemma coe_to_basis (b : orthonormal_basis ι 𝕜 E) : (⇑b.to_basis : ι → E) = ⇑b := begin change ⇑(basis.of_equiv_fun b.repr.to_linear_equiv) = b, ext j, rw basis.coe_of_equiv_fun, congr, end @[simp] protected lemma coe_to_basis_repr (b : orthonormal_basis ι 𝕜 E) : b.to_basis.equiv_fun = b.repr.to_linear_equiv := begin change (basis.of_equiv_fun b.repr.to_linear_equiv).equiv_fun = b.repr.to_linear_equiv, ext x j, simp only [basis.of_equiv_fun_repr_apply, linear_isometry_equiv.coe_to_linear_equiv, basis.equiv_fun_apply], end @[simp] protected lemma coe_to_basis_repr_apply (b : orthonormal_basis ι 𝕜 E) (x : E) (i : ι) : b.to_basis.repr x i = b.repr x i := by {rw [← basis.equiv_fun_apply, orthonormal_basis.coe_to_basis_repr, linear_isometry_equiv.coe_to_linear_equiv]} protected lemma sum_repr (b : orthonormal_basis ι 𝕜 E) (x : E) : ∑ i, b.repr x i • b i = x := by { simp_rw [← b.coe_to_basis_repr_apply, ← b.coe_to_basis], exact b.to_basis.sum_repr x } protected lemma sum_repr_symm (b : orthonormal_basis ι 𝕜 E) (v : euclidean_space 𝕜 ι) : ∑ i , v i • b i = (b.repr.symm v) := by { simpa using (b.to_basis.equiv_fun_symm_apply v).symm } protected lemma sum_inner_mul_inner (b : orthonormal_basis ι 𝕜 E) (x y : E) : ∑ i, ⟪x, b i⟫ * ⟪b i, y⟫ = ⟪x, y⟫ := begin have := congr_arg (@innerSL 𝕜 _ _ _ x) (b.sum_repr y), rw map_sum at this, convert this, ext i, rw [smul_hom_class.map_smul, b.repr_apply_apply, mul_comm], refl, end /-- Mapping an orthonormal basis along a `linear_isometry_equiv`. -/ protected def map {G : Type*} [inner_product_space 𝕜 G] (b : orthonormal_basis ι 𝕜 E) (L : E ≃ₗᵢ[𝕜] G) : orthonormal_basis ι 𝕜 G := { repr := L.symm.trans b.repr } @[simp] protected lemma map_apply {G : Type*} [inner_product_space 𝕜 G] (b : orthonormal_basis ι 𝕜 E) (L : E ≃ₗᵢ[𝕜] G) (i : ι) : b.map L i = L (b i) := rfl /-- A basis that is orthonormal is an orthonormal basis. -/ def _root_.basis.to_orthonormal_basis (v : basis ι 𝕜 E) (hv : orthonormal 𝕜 v) : orthonormal_basis ι 𝕜 E := orthonormal_basis.of_repr $ linear_equiv.isometry_of_inner v.equiv_fun begin intros x y, let p : euclidean_space 𝕜 ι := v.equiv_fun x, let q : euclidean_space 𝕜 ι := v.equiv_fun y, have key : ⟪p, q⟫ = ⟪∑ i, p i • v i, ∑ i, q i • v i⟫, { simp [sum_inner, inner_smul_left, hv.inner_right_fintype] }, convert key, { rw [← v.equiv_fun.symm_apply_apply x, v.equiv_fun_symm_apply] }, { rw [← v.equiv_fun.symm_apply_apply y, v.equiv_fun_symm_apply] } end @[simp] lemma _root_.basis.coe_to_orthonormal_basis_repr (v : basis ι 𝕜 E) (hv : orthonormal 𝕜 v) : ((v.to_orthonormal_basis hv).repr : E → euclidean_space 𝕜 ι) = v.equiv_fun := rfl @[simp] lemma _root_.basis.coe_to_orthonormal_basis_repr_symm (v : basis ι 𝕜 E) (hv : orthonormal 𝕜 v) : ((v.to_orthonormal_basis hv).repr.symm : euclidean_space 𝕜 ι → E) = v.equiv_fun.symm := rfl @[simp] lemma _root_.basis.to_basis_to_orthonormal_basis (v : basis ι 𝕜 E) (hv : orthonormal 𝕜 v) : (v.to_orthonormal_basis hv).to_basis = v := by simp [basis.to_orthonormal_basis, orthonormal_basis.to_basis] @[simp] lemma _root_.basis.coe_to_orthonormal_basis (v : basis ι 𝕜 E) (hv : orthonormal 𝕜 v) : (v.to_orthonormal_basis hv : ι → E) = (v : ι → E) := calc (v.to_orthonormal_basis hv : ι → E) = ((v.to_orthonormal_basis hv).to_basis : ι → E) : by { classical, rw orthonormal_basis.coe_to_basis } ... = (v : ι → E) : by simp variable {v : ι → E} /-- A finite orthonormal set that spans is an orthonormal basis -/ protected def mk (hon : orthonormal 𝕜 v) (hsp: ⊤ ≤ submodule.span 𝕜 (set.range v)): orthonormal_basis ι 𝕜 E := (basis.mk (orthonormal.linear_independent hon) hsp).to_orthonormal_basis (by rwa basis.coe_mk) @[simp] protected lemma coe_mk (hon : orthonormal 𝕜 v) (hsp: ⊤ ≤ submodule.span 𝕜 (set.range v)) : ⇑(orthonormal_basis.mk hon hsp) = v := by classical; rw [orthonormal_basis.mk, _root_.basis.coe_to_orthonormal_basis, basis.coe_mk] /-- Any finite subset of a orthonormal family is an `orthonormal_basis` for its span. -/ protected def span {v' : ι' → E} (h : orthonormal 𝕜 v') (s : finset ι') : orthonormal_basis s 𝕜 (span 𝕜 (s.image v' : set E)) := let e₀' : basis s 𝕜 _ := basis.span (h.linear_independent.comp (coe : s → ι') subtype.coe_injective), e₀ : orthonormal_basis s 𝕜 _ := orthonormal_basis.mk begin convert orthonormal_span (h.comp (coe : s → ι') subtype.coe_injective), ext, simp [e₀', basis.span_apply], end e₀'.span_eq.ge, φ : span 𝕜 (s.image v' : set E) ≃ₗᵢ[𝕜] span 𝕜 (range (v' ∘ (coe : s → ι'))) := linear_isometry_equiv.of_eq _ _ begin rw [finset.coe_image, image_eq_range], refl end in e₀.map φ.symm @[simp] protected lemma span_apply {v' : ι' → E} (h : orthonormal 𝕜 v') (s : finset ι') (i : s) : (orthonormal_basis.span h s i : E) = v' i := by simp only [orthonormal_basis.span, basis.span_apply, linear_isometry_equiv.of_eq_symm, orthonormal_basis.map_apply, orthonormal_basis.coe_mk, linear_isometry_equiv.coe_of_eq_apply] open submodule /-- A finite orthonormal family of vectors whose span has trivial orthogonal complement is an orthonormal basis. -/ protected def mk_of_orthogonal_eq_bot (hon : orthonormal 𝕜 v) (hsp : (span 𝕜 (set.range v))ᗮ = ⊥) : orthonormal_basis ι 𝕜 E := orthonormal_basis.mk hon begin refine eq.ge _, haveI : finite_dimensional 𝕜 (span 𝕜 (range v)) := finite_dimensional.span_of_finite 𝕜 (finite_range v), haveI : complete_space (span 𝕜 (range v)) := finite_dimensional.complete 𝕜 _, rwa orthogonal_eq_bot_iff at hsp, end @[simp] protected lemma coe_of_orthogonal_eq_bot_mk (hon : orthonormal 𝕜 v) (hsp : (span 𝕜 (set.range v))ᗮ = ⊥) : ⇑(orthonormal_basis.mk_of_orthogonal_eq_bot hon hsp) = v := orthonormal_basis.coe_mk hon _ variables [fintype ι'] /-- `b.reindex (e : ι ≃ ι')` is an `orthonormal_basis` indexed by `ι'` -/ def reindex (b : orthonormal_basis ι 𝕜 E) (e : ι ≃ ι') : orthonormal_basis ι' 𝕜 E := orthonormal_basis.of_repr (b.repr.trans (linear_isometry_equiv.pi_Lp_congr_left 2 𝕜 𝕜 e)) protected lemma reindex_apply (b : orthonormal_basis ι 𝕜 E) (e : ι ≃ ι') (i' : ι') : (b.reindex e) i' = b (e.symm i') := begin classical, dsimp [reindex, orthonormal_basis.has_coe_to_fun], rw coe_of_repr, dsimp, rw [← b.repr_symm_single, linear_isometry_equiv.pi_Lp_congr_left_symm, euclidean_space.pi_Lp_congr_left_single], end @[simp] protected lemma coe_reindex (b : orthonormal_basis ι 𝕜 E) (e : ι ≃ ι') : ⇑(b.reindex e) = ⇑b ∘ ⇑(e.symm) := funext (b.reindex_apply e) @[simp] protected lemma reindex_repr (b : orthonormal_basis ι 𝕜 E) (e : ι ≃ ι') (x : E) (i' : ι') : ((b.reindex e).repr x) i' = (b.repr x) (e.symm i') := by { classical, rw [orthonormal_basis.repr_apply_apply, b.repr_apply_apply, orthonormal_basis.coe_reindex] } end orthonormal_basis /-- If `f : E ≃ₗᵢ[𝕜] E'` is a linear isometry of inner product spaces then an orthonormal basis `v` of `E` determines a linear isometry `e : E' ≃ₗᵢ[𝕜] euclidean_space 𝕜 ι`. This result states that `e` may be obtained either by transporting `v` to `E'` or by composing with the linear isometry `E ≃ₗᵢ[𝕜] euclidean_space 𝕜 ι` provided by `v`. -/ @[simp] lemma basis.map_isometry_euclidean_of_orthonormal (v : basis ι 𝕜 E) (hv : orthonormal 𝕜 v) (f : E ≃ₗᵢ[𝕜] E') : ((v.map f.to_linear_equiv).to_orthonormal_basis (hv.map_linear_isometry_equiv f)).repr = f.symm.trans (v.to_orthonormal_basis hv).repr := linear_isometry_equiv.to_linear_equiv_injective $ v.map_equiv_fun _ /-- `ℂ` is isometric to `ℝ²` with the Euclidean inner product. -/ def complex.isometry_euclidean : ℂ ≃ₗᵢ[ℝ] (euclidean_space ℝ (fin 2)) := (complex.basis_one_I.to_orthonormal_basis begin rw orthonormal_iff_ite, intros i, fin_cases i; intros j; fin_cases j; simp [real_inner_eq_re_inner] end).repr @[simp] lemma complex.isometry_euclidean_symm_apply (x : euclidean_space ℝ (fin 2)) : complex.isometry_euclidean.symm x = (x 0) + (x 1) * I := begin convert complex.basis_one_I.equiv_fun_symm_apply x, { simpa }, { simp }, end lemma complex.isometry_euclidean_proj_eq_self (z : ℂ) : ↑(complex.isometry_euclidean z 0) + ↑(complex.isometry_euclidean z 1) * (I : ℂ) = z := by rw [← complex.isometry_euclidean_symm_apply (complex.isometry_euclidean z), complex.isometry_euclidean.symm_apply_apply z] @[simp] lemma complex.isometry_euclidean_apply_zero (z : ℂ) : complex.isometry_euclidean z 0 = z.re := by { conv_rhs { rw ← complex.isometry_euclidean_proj_eq_self z }, simp } @[simp] lemma complex.isometry_euclidean_apply_one (z : ℂ) : complex.isometry_euclidean z 1 = z.im := by { conv_rhs { rw ← complex.isometry_euclidean_proj_eq_self z }, simp } /-- The isometry between `ℂ` and a two-dimensional real inner product space given by a basis. -/ def complex.isometry_of_orthonormal {v : basis (fin 2) ℝ F} (hv : orthonormal ℝ v) : ℂ ≃ₗᵢ[ℝ] F := complex.isometry_euclidean.trans (v.to_orthonormal_basis hv).repr.symm @[simp] lemma complex.map_isometry_of_orthonormal {v : basis (fin 2) ℝ F} (hv : orthonormal ℝ v) (f : F ≃ₗᵢ[ℝ] F') : complex.isometry_of_orthonormal (hv.map_linear_isometry_equiv f) = (complex.isometry_of_orthonormal hv).trans f := by simp [complex.isometry_of_orthonormal, linear_isometry_equiv.trans_assoc] lemma complex.isometry_of_orthonormal_symm_apply {v : basis (fin 2) ℝ F} (hv : orthonormal ℝ v) (f : F) : (complex.isometry_of_orthonormal hv).symm f = (v.coord 0 f : ℂ) + (v.coord 1 f : ℂ) * I := by simp [complex.isometry_of_orthonormal] lemma complex.isometry_of_orthonormal_apply {v : basis (fin 2) ℝ F} (hv : orthonormal ℝ v) (z : ℂ) : complex.isometry_of_orthonormal hv z = z.re • v 0 + z.im • v 1 := by simp [complex.isometry_of_orthonormal, (dec_trivial : (finset.univ : finset (fin 2)) = {0, 1})] open finite_dimensional /-! ### Existence of orthonormal basis, etc. -/ section finite_dimensional variables {v : set E} variables {A : ι → submodule 𝕜 E} /-- Given an internal direct sum decomposition of a module `M`, and an orthonormal basis for each of the components of the direct sum, the disjoint union of these orthonormal bases is an orthonormal basis for `M`. -/ noncomputable def direct_sum.is_internal.collected_orthonormal_basis (hV : @orthogonal_family 𝕜 _ _ _ _ (λ i, A i) _ (λ i, (A i).subtypeₗᵢ)) [decidable_eq ι] (hV_sum : direct_sum.is_internal (λ i, A i)) {α : ι → Type*} [Π i, fintype (α i)] (v_family : Π i, orthonormal_basis (α i) 𝕜 (A i)) : orthonormal_basis (Σ i, α i) 𝕜 E := (hV_sum.collected_basis (λ i, (v_family i).to_basis)).to_orthonormal_basis $ by simpa using hV.orthonormal_sigma_orthonormal (show (∀ i, orthonormal 𝕜 (v_family i).to_basis), by simp) lemma direct_sum.is_internal.collected_orthonormal_basis_mem [decidable_eq ι] (h : direct_sum.is_internal A) {α : ι → Type*} [Π i, fintype (α i)] (hV : @orthogonal_family 𝕜 _ _ _ _ (λ i, A i) _ (λ i, (A i).subtypeₗᵢ)) (v : Π i, orthonormal_basis (α i) 𝕜 (A i)) (a : Σ i, α i) : h.collected_orthonormal_basis hV v a ∈ A a.1 := by simp [direct_sum.is_internal.collected_orthonormal_basis] variables [finite_dimensional 𝕜 E] /-- In a finite-dimensional `inner_product_space`, any orthonormal subset can be extended to an orthonormal basis. -/ lemma _root_.orthonormal.exists_orthonormal_basis_extension (hv : orthonormal 𝕜 (coe : v → E)) : ∃ {u : finset E} (b : orthonormal_basis u 𝕜 E), v ⊆ u ∧ ⇑b = coe := begin obtain ⟨u₀, hu₀s, hu₀, hu₀_max⟩ := exists_maximal_orthonormal hv, rw maximal_orthonormal_iff_orthogonal_complement_eq_bot hu₀ at hu₀_max, have hu₀_finite : u₀.finite := hu₀.linear_independent.finite, let u : finset E := hu₀_finite.to_finset, let fu : ↥u ≃ ↥u₀ := equiv.cast (congr_arg coe_sort hu₀_finite.coe_to_finset), have hfu : (coe : u → E) = (coe : u₀ → E) ∘ fu := by { ext, simp }, have hu : orthonormal 𝕜 (coe : u → E) := by simpa [hfu] using hu₀.comp _ fu.injective, refine ⟨u, orthonormal_basis.mk_of_orthogonal_eq_bot hu _, _, _⟩, { simpa using hu₀_max }, { simpa using hu₀s }, { simp }, end variables (𝕜 E) /-- A finite-dimensional inner product space admits an orthonormal basis. -/ lemma _root_.exists_orthonormal_basis : ∃ (w : finset E) (b : orthonormal_basis w 𝕜 E), ⇑b = (coe : w → E) := let ⟨w, hw, hw', hw''⟩ := (orthonormal_empty 𝕜 E).exists_orthonormal_basis_extension in ⟨w, hw, hw''⟩ /-- Index for an arbitrary orthonormal basis on a finite-dimensional `inner_product_space`. -/ def orthonormal_basis_index : finset E := classical.some (exists_orthonormal_basis 𝕜 E) /-- A finite-dimensional `inner_product_space` has an orthonormal basis. -/ def std_orthonormal_basis : orthonormal_basis (orthonormal_basis_index 𝕜 E) 𝕜 E := classical.some (classical.some_spec (exists_orthonormal_basis 𝕜 E)) @[simp] lemma coe_std_orthonormal_basis : ⇑(std_orthonormal_basis 𝕜 E) = coe := classical.some_spec (classical.some_spec (exists_orthonormal_basis 𝕜 E)) variables {𝕜 E} /-- An `n`-dimensional `inner_product_space` has an orthonormal basis indexed by `fin n`. -/ def fin_std_orthonormal_basis {n : ℕ} (hn : finrank 𝕜 E = n) : orthonormal_basis (fin n) 𝕜 E := have h : fintype.card (orthonormal_basis_index 𝕜 E) = n, by rw [← finrank_eq_card_basis (std_orthonormal_basis 𝕜 E).to_basis, hn], (std_orthonormal_basis 𝕜 E).reindex (fintype.equiv_fin_of_card_eq h) section subordinate_orthonormal_basis open direct_sum variables {n : ℕ} (hn : finrank 𝕜 E = n) [decidable_eq ι] {V : ι → submodule 𝕜 E} (hV : is_internal V) /-- Exhibit a bijection between `fin n` and the index set of a certain basis of an `n`-dimensional inner product space `E`. This should not be accessed directly, but only via the subsequent API. -/ @[irreducible] def direct_sum.is_internal.sigma_orthonormal_basis_index_equiv (hV' : @orthogonal_family 𝕜 _ _ _ _ (λ i, V i) _ (λ i, (V i).subtypeₗᵢ)) : (Σ i, orthonormal_basis_index 𝕜 (V i)) ≃ fin n := let b := hV.collected_orthonormal_basis hV' (λ i, (std_orthonormal_basis 𝕜 (V i))) in fintype.equiv_fin_of_card_eq $ (finite_dimensional.finrank_eq_card_basis b.to_basis).symm.trans hn /-- An `n`-dimensional `inner_product_space` equipped with a decomposition as an internal direct sum has an orthonormal basis indexed by `fin n` and subordinate to that direct sum. -/ @[irreducible] def direct_sum.is_internal.subordinate_orthonormal_basis (hV' : @orthogonal_family 𝕜 _ _ _ _ (λ i, V i) _ (λ i, (V i).subtypeₗᵢ)) : orthonormal_basis (fin n) 𝕜 E := ((hV.collected_orthonormal_basis hV' (λ i, (std_orthonormal_basis 𝕜 (V i)))).reindex (hV.sigma_orthonormal_basis_index_equiv hn hV')) /-- An `n`-dimensional `inner_product_space` equipped with a decomposition as an internal direct sum has an orthonormal basis indexed by `fin n` and subordinate to that direct sum. This function provides the mapping by which it is subordinate. -/ def direct_sum.is_internal.subordinate_orthonormal_basis_index (a : fin n) (hV' : @orthogonal_family 𝕜 _ _ _ _ (λ i, V i) _ (λ i, (V i).subtypeₗᵢ)) : ι := ((hV.sigma_orthonormal_basis_index_equiv hn hV').symm a).1 /-- The basis constructed in `orthogonal_family.subordinate_orthonormal_basis` is subordinate to the `orthogonal_family` in question. -/ lemma direct_sum.is_internal.subordinate_orthonormal_basis_subordinate (a : fin n) (hV' : @orthogonal_family 𝕜 _ _ _ _ (λ i, V i) _ (λ i, (V i).subtypeₗᵢ)) : (hV.subordinate_orthonormal_basis hn hV' a) ∈ V (hV.subordinate_orthonormal_basis_index hn a hV') := by simpa only [direct_sum.is_internal.subordinate_orthonormal_basis, orthonormal_basis.coe_reindex] using hV.collected_orthonormal_basis_mem hV' (λ i, (std_orthonormal_basis 𝕜 (V i))) ((hV.sigma_orthonormal_basis_index_equiv hn hV').symm a) attribute [irreducible] direct_sum.is_internal.subordinate_orthonormal_basis_index end subordinate_orthonormal_basis end finite_dimensional local attribute [instance] fact_finite_dimensional_of_finrank_eq_succ /-- Given a natural number `n` one less than the `finrank` of a finite-dimensional inner product space, there exists an isometry from the orthogonal complement of a nonzero singleton to `euclidean_space 𝕜 (fin n)`. -/ def orthonormal_basis.from_orthogonal_span_singleton (n : ℕ) [fact (finrank 𝕜 E = n + 1)] {v : E} (hv : v ≠ 0) : orthonormal_basis (fin n) 𝕜 (𝕜 ∙ v)ᗮ := (fin_std_orthonormal_basis (finrank_orthogonal_span_singleton hv)) section linear_isometry variables {V : Type*} [inner_product_space 𝕜 V] [finite_dimensional 𝕜 V] variables {S : submodule 𝕜 V} {L : S →ₗᵢ[𝕜] V} open finite_dimensional /-- Let `S` be a subspace of a finite-dimensional complex inner product space `V`. A linear isometry mapping `S` into `V` can be extended to a full isometry of `V`. TODO: The case when `S` is a finite-dimensional subspace of an infinite-dimensional `V`.-/ noncomputable def linear_isometry.extend (L : S →ₗᵢ[𝕜] V): V →ₗᵢ[𝕜] V := begin -- Build an isometry from Sᗮ to L(S)ᗮ through euclidean_space let d := finrank 𝕜 Sᗮ, have dim_S_perp : finrank 𝕜 Sᗮ = d := rfl, let LS := L.to_linear_map.range, have E : Sᗮ ≃ₗᵢ[𝕜] LSᗮ, { have dim_LS_perp : finrank 𝕜 LSᗮ = d, calc finrank 𝕜 LSᗮ = finrank 𝕜 V - finrank 𝕜 LS : by simp only [← LS.finrank_add_finrank_orthogonal, add_tsub_cancel_left] ... = finrank 𝕜 V - finrank 𝕜 S : by simp only [linear_map.finrank_range_of_inj L.injective] ... = finrank 𝕜 Sᗮ : by simp only [← S.finrank_add_finrank_orthogonal, add_tsub_cancel_left] ... = d : dim_S_perp, let BS := (fin_std_orthonormal_basis dim_S_perp), let BLS := (fin_std_orthonormal_basis dim_LS_perp), exact BS.repr.trans BLS.repr.symm }, let L3 := (LS)ᗮ.subtypeₗᵢ.comp E.to_linear_isometry, -- Project onto S and Sᗮ haveI : complete_space S := finite_dimensional.complete 𝕜 S, haveI : complete_space V := finite_dimensional.complete 𝕜 V, let p1 := (orthogonal_projection S).to_linear_map, let p2 := (orthogonal_projection Sᗮ).to_linear_map, -- Build a linear map from the isometries on S and Sᗮ let M := L.to_linear_map.comp p1 + L3.to_linear_map.comp p2, -- Prove that M is an isometry have M_norm_map : ∀ (x : V), ∥M x∥ = ∥x∥, { intro x, -- Apply M to the orthogonal decomposition of x have Mx_decomp : M x = L (p1 x) + L3 (p2 x), { simp only [linear_map.add_apply, linear_map.comp_apply, linear_map.comp_apply, linear_isometry.coe_to_linear_map]}, -- Mx_decomp is the orthogonal decomposition of M x have Mx_orth : ⟪ L (p1 x), L3 (p2 x) ⟫ = 0, { have Lp1x : L (p1 x) ∈ L.to_linear_map.range := L.to_linear_map.mem_range_self (p1 x), have Lp2x : L3 (p2 x) ∈ (L.to_linear_map.range)ᗮ, { simp only [L3, linear_isometry.coe_comp, function.comp_app, submodule.coe_subtypeₗᵢ, ← submodule.range_subtype (LSᗮ)], apply linear_map.mem_range_self}, apply submodule.inner_right_of_mem_orthogonal Lp1x Lp2x}, -- Apply the Pythagorean theorem and simplify rw [← sq_eq_sq (norm_nonneg _) (norm_nonneg _), norm_sq_eq_add_norm_sq_projection x S], simp only [sq, Mx_decomp], rw norm_add_sq_eq_norm_sq_add_norm_sq_of_inner_eq_zero (L (p1 x)) (L3 (p2 x)) Mx_orth, simp only [linear_isometry.norm_map, p1, p2, continuous_linear_map.to_linear_map_eq_coe, add_left_inj, mul_eq_mul_left_iff, norm_eq_zero, true_or, eq_self_iff_true, continuous_linear_map.coe_coe, submodule.coe_norm, submodule.coe_eq_zero] }, exact { to_linear_map := M, norm_map' := M_norm_map }, end lemma linear_isometry.extend_apply (L : S →ₗᵢ[𝕜] V) (s : S): L.extend s = L s := begin haveI : complete_space S := finite_dimensional.complete 𝕜 S, simp only [linear_isometry.extend, continuous_linear_map.to_linear_map_eq_coe, ←linear_isometry.coe_to_linear_map], simp only [add_right_eq_self, linear_isometry.coe_to_linear_map, linear_isometry_equiv.coe_to_linear_isometry, linear_isometry.coe_comp, function.comp_app, orthogonal_projection_mem_subspace_eq_self, linear_map.coe_comp, continuous_linear_map.coe_coe, submodule.coe_subtype, linear_map.add_apply, submodule.coe_eq_zero, linear_isometry_equiv.map_eq_zero_iff, submodule.coe_subtypeₗᵢ, orthogonal_projection_mem_subspace_orthogonal_complement_eq_zero, submodule.orthogonal_orthogonal, submodule.coe_mem], end end linear_isometry section matrix open_locale matrix variables {n m : ℕ} local notation `⟪`x`, `y`⟫ₘ` := @inner 𝕜 (euclidean_space 𝕜 (fin m)) _ x y local notation `⟪`x`, `y`⟫ₙ` := @inner 𝕜 (euclidean_space 𝕜 (fin n)) _ x y /-- The inner product of a row of A and a row of B is an entry of B ⬝ Aᴴ. -/ lemma inner_matrix_row_row (A B : matrix (fin n) (fin m) 𝕜) (i j : (fin n)) : ⟪A i, B j⟫ₘ = (B ⬝ Aᴴ) j i := by {simp only [inner, matrix.mul_apply, star_ring_end_apply, matrix.conj_transpose_apply,mul_comm]} /-- The inner product of a column of A and a column of B is an entry of Aᴴ ⬝ B -/ lemma inner_matrix_col_col (A B : matrix (fin n) (fin m) 𝕜) (i j : (fin m)) : ⟪Aᵀ i, Bᵀ j⟫ₙ = (Aᴴ ⬝ B) i j := rfl end matrix
3d43306d1c0600afeefeafa94553f20aac840478
957a80ea22c5abb4f4670b250d55534d9db99108
/tests/lean/run/class6.lean
1e1c9acd719694434cbbc4b1bde9db75d93a3a33
[ "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
320
lean
open tactic inductive t1 : Type | mk1 : t1 inductive t2 : Type | mk2 : t2 theorem inhabited_t1 : inhabited t1 := inhabited.mk t1.mk1 theorem inhabited_t2 : inhabited t2 := inhabited.mk t2.mk2 attribute [instance] inhabited_t1 attribute [instance] inhabited_t2 theorem T : inhabited (t1 × t2) := by apply_instance
89cdc475f9bec1bdfda171f625f2531ec24854b6
e1da55f4222dac91b940ca052928eaace09762da
/src/chunk.lean
3884e51a3a55593095da6cf27a7db306ed5fe780
[]
no_license
b-mehta/regularity-lemma
c5826e22c280d0b073a4e62dba731f4dd3d1b69f
cf26082b0c88fa54276e6fdc3338c15e607c52c6
refs/heads/master
1,658,209,524,267
1,644,406,456,000
1,644,406,456,000
457,327,371
1
0
null
null
null
null
UTF-8
Lean
false
false
28,519
lean
/- Copyright (c) 2021 Yaël Dillies, Bhavik Mehta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies, Bhavik Mehta -/ import .bounds import .finpartitions import .prereqs import .witness /-! # Chunk of `increment` -/ open finpartition finset fintype relation open_locale big_operators classical variables {α : Type*} [fintype α] {P : finpartition (univ : finset α)} (hP : P.is_equipartition) (G : simple_graph α) (ε : ℝ) {U : finset α} (hU : U ∈ P.parts) (V : finset α) local notation `m` := (card α/exp_bound P.parts.card : ℕ) /-- The witnesses of non uniformity among the parts of a finpartition. -/ noncomputable def finpartition.witnesses (P : finpartition (univ : finset α)) (G : simple_graph α) (ε : ℝ) (U : finset α) := (P.parts.filter (λ V, U ≠ V ∧ ¬G.is_uniform ε U V)).image (G.witness ε U) /-- The portion of `increment` that partitions `U`. -/ noncomputable def finpartition.is_equipartition.chunk_increment : finpartition U := dite (U.card = m * 4^P.parts.card + (card α/P.parts.card - m * 4^P.parts.card)) (λ hUcard, (atomise U (P.witnesses G ε U)).equitabilise $ card_aux₂ hUcard) (λ hUcard, (atomise U (P.witnesses G ε U)).equitabilise $ card_aux₃ hP hU hUcard) -- hP and hU are used to get that U has size m * 4^P.parts.card + a or m * 4^P.parts.card + a + 1 /-- The portion of `chunk_increment` that's contained in the witness of non uniformity of `U` and `V`. -/ noncomputable def finpartition.is_equipartition.star (V : finset α) : finset (finset α) := (hP.chunk_increment G ε hU).parts.filter (λ x, x ⊆ G.witness ε U V) /-! # star -/ /-- Each thing in star is a subset of the witness. -/ lemma subset_witness_of_mem_star : ∀ A ∈ hP.star G ε hU V, A ⊆ G.witness ε U V := λ A hA, (mem_filter.1 hA).2 lemma bUnion_star_subset_witness : (hP.star G ε hU V).bUnion id ⊆ G.witness ε U V := bUnion_subset_iff_forall_subset.2 (subset_witness_of_mem_star hP G ε hU V) variables {hP G ε hU V} lemma star_subset_chunk_increment : hP.star G ε hU V ⊆ (hP.chunk_increment G ε hU).parts := filter_subset _ _ lemma star_pairwise_disjoint : (hP.star G ε hU V : set (finset α)).pairwise_disjoint id := (hP.chunk_increment G ε hU).disjoint.subset star_subset_chunk_increment lemma witness_sdiff_bUnion_star_small (hV : V ∈ P.parts) (hUV : U ≠ V) (h₂ : ¬G.is_uniform ε U V) : (G.witness ε U V \ (hP.star G ε hU V).bUnion id).card ≤ 2^(P.parts.card - 1) * m := begin have hX : G.witness ε U V ∈ P.witnesses G ε U := mem_image_of_mem _ (by simp [hUV, hV, h₂]), have q : G.witness ε U V \ (hP.star G ε hU V).bUnion id ⊆ ((atomise U (P.witnesses G ε U)).parts.filter (λ B, B ⊆ G.witness ε U V ∧ B.nonempty)).bUnion (λ B, B \ ((hP.chunk_increment G ε hU).parts.filter (λ x, x ⊆ B)).bUnion id), { intros x hx, rw [←union_of_atoms' (G.witness ε U V) hX (G.witness_subset h₂), finpartition.is_equipartition.star, mem_sdiff, mem_bUnion] at hx, simp only [not_exists, mem_bUnion, and_imp, filter_congr_decidable, exists_prop, mem_filter, not_and, mem_sdiff, id.def, mem_sdiff] at hx ⊢, obtain ⟨⟨B, hB₁, hB₂⟩, hx⟩ := hx, exact ⟨B, hB₁, hB₂, λ A hA AB, hx A hA $ AB.trans hB₁.2.1⟩ }, apply (card_le_of_subset q).trans (card_bUnion_le.trans _), have : ∑ i in (atomise U (P.witnesses G ε U)).parts.filter (λ B, B ⊆ G.witness ε U V ∧ B.nonempty), m ≤ 2 ^ (P.parts.card - 1) * m, { rw sum_const_nat, { apply nat.mul_le_mul_right, have t := partial_atomise (G.witness ε U V) hX, rw filter_congr_decidable at t, apply t.trans (pow_le_pow (by norm_num) (nat.sub_le_sub_right _ _)), apply card_image_le.trans (card_le_of_subset (filter_subset _ _)) }, { intros, refl } }, apply le_trans _ this, have : ∀ B ∈ (atomise U (P.witnesses G ε U)).parts, (B \ ((hP.chunk_increment G ε hU).parts.filter (λ x, x ⊆ B)).bUnion id).card ≤ m, { intros B hB, rw [finpartition.is_equipartition.chunk_increment], split_ifs with h₁, { convert almost_in_atoms_of_mem_parts_equitabilise (card_aux₂ h₁) hB }, convert almost_in_atoms_of_mem_parts_equitabilise (card_aux₃ hP hU h₁) hB }, apply sum_le_sum (λ B hB, this B (filter_subset _ _ hB)), end lemma one_sub_eps_mul_card_witness_le_card_star (hV : V ∈ P.parts) (hUV : U ≠ V) (hunif : ¬G.is_uniform ε U V) (hPε : 100 ≤ 4^P.parts.card * ε^5) (hε₁ : ε ≤ 1) : (1 - ε/10) * (G.witness ε U V).card ≤ ((hP.star G ε hU V).bUnion id).card := begin have hP₁ : 0 < P.parts.card := finset.card_pos.2 ⟨_, hU⟩, have : (2^P.parts.card : ℝ) * m/(U.card * ε) ≤ ε/10, { rw [←div_div_eq_div_mul, div_le_iff' (eps_pos hPε)], refine le_of_mul_le_mul_left _ (pow_pos zero_lt_two P.parts.card), calc 2^P.parts.card * ((2^P.parts.card * m : ℝ)/U.card) = (2 * 2)^P.parts.card * m/U.card : by rw [mul_pow, ←mul_div_assoc, mul_assoc] ... = 4^P.parts.card * m/U.card : by norm_num ... ≤ 1 : div_le_one_of_le (pow_mul_m_le_card_part hP hU) (nat.cast_nonneg _) ... ≤ 2^P.parts.card * ε^2 / 10 : begin refine (one_le_sq_iff (div_nonneg (mul_nonneg (pow_nonneg (@zero_le_two ℝ _) _) $ sq_nonneg _) $ by norm_num)).1 _, rw [div_pow, mul_pow, pow_right_comm, ←pow_mul ε, one_le_div (sq_pos_of_ne_zero (10 : ℝ) $ by norm_num)], calc (10 ^ 2 : ℝ) = 100 : by norm_num ... ≤ 4^P.parts.card * ε^5 : hPε ... ≤ 4^P.parts.card * ε^4 : mul_le_mul_of_nonneg_left (pow_le_pow_of_le_one (eps_pos hPε).le hε₁ (nat.le_succ _)) (pow_nonneg zero_lt_four.le _) ... = (2^2)^P.parts.card * ε ^ (2 * 2) : by norm_num, end ... = 2^P.parts.card * (ε * (ε / 10)) : by rw [mul_div_assoc, sq, mul_div_assoc] }, calc (1 - ε/10) * (G.witness ε U V).card ≤ (1 - 2^P.parts.card * m/(U.card * ε)) * (G.witness ε U V).card : mul_le_mul_of_nonneg_right (sub_le_sub_left this _) (nat.cast_nonneg _) ... = (G.witness ε U V).card - 2^P.parts.card * m/(U.card * ε) * (G.witness ε U V).card : by rw [sub_mul, one_mul] ... ≤ (G.witness ε U V).card - 2^(P.parts.card - 1) * m : begin refine sub_le_sub_left _ _, have : (2 : ℝ)^P.parts.card = 2^(P.parts.card - 1) * 2, { rw [←pow_succ', nat.sub_add_cancel hP₁] }, rw [←mul_div_right_comm, this, mul_right_comm _ (2 : ℝ), mul_assoc, le_div_iff (mul_pos (nat.cast_pos.2 (P.nonempty_of_mem_parts hU).card_pos) (eps_pos hPε))], refine mul_le_mul_of_nonneg_left _ _, exact (G.witness_card hunif).trans (le_mul_of_one_le_left (nat.cast_nonneg _) one_le_two), exact mul_nonneg (pow_nonneg zero_le_two _) (nat.cast_nonneg _), end ... ≤ ((hP.star G ε hU V).bUnion id).card : begin norm_cast, rw [sub_le, ←nat.cast_sub (finset.card_le_of_subset $ bUnion_star_subset_witness hP G ε hU V), ←card_sdiff (bUnion_star_subset_witness hP G ε hU V), nat.cast_le], exact witness_sdiff_bUnion_star_small hV hUV hunif, end end variables {hP G ε U hU V} /-! # chunk_increment -/ lemma card_chunk_increment (m_pos : 0 < m) : (hP.chunk_increment G ε hU).parts.card = 4^P.parts.card := begin rw finpartition.is_equipartition.chunk_increment, split_ifs, { rw [equitabilise.parts_card m_pos, nat.sub_add_cancel], exact le_of_lt a_add_one_le_four_pow_parts_card }, { rw [equitabilise.parts_card m_pos, nat.sub_add_cancel a_add_one_le_four_pow_parts_card] } end lemma card_eq_of_mem_parts_chunk_increment {A : finset α} (hA : A ∈ (hP.chunk_increment G ε hU).parts) : A.card = m ∨ A.card = m + 1 := begin rw [finpartition.is_equipartition.chunk_increment] at hA, split_ifs at hA; apply card_eq_of_mem_parts_equitabilise _ hA, end lemma m_le_card_of_mem_chunk_increment_parts {A : finset α} (hA : A ∈ (hP.chunk_increment G ε hU).parts) : m ≤ A.card := (card_eq_of_mem_parts_chunk_increment hA).elim ge_of_eq (λ i, by simp [i]) lemma card_le_m_add_one_of_mem_chunk_increment_parts {A : finset α} (hA : A ∈ (hP.chunk_increment G ε hU).parts) : A.card ≤ m + 1 := (card_eq_of_mem_parts_chunk_increment hA).elim (λ i, by simp [i]) (λ i, i.le) lemma card_bUnion_star_le_m_add_one_card_star_mul : (((hP.star G ε hU V).bUnion id).card : ℝ) ≤ (hP.star G ε hU V).card * (m + 1) := by exact_mod_cast (card_bUnion_le_card_mul _ _ _ $ λ s hs, card_le_m_add_one_of_mem_chunk_increment_parts $ star_subset_chunk_increment hs) lemma le_sum_card_subset_chunk_increment_parts {A : finset (finset α)} (hA : A ⊆ (hP.chunk_increment G ε hU).parts) {u : finset α} (hu : u ∈ A) : (A.card : ℝ) * u.card * (m/(m+1)) ≤ (A.sup id).card := begin rw [mul_div_assoc', div_le_iff coe_m_add_one_pos, mul_right_comm], refine mul_le_mul _ _ (nat.cast_nonneg _) (nat.cast_nonneg _), { rw [←(of_subset _ hA rfl).sum_card_parts, of_subset_parts, ←nat.cast_mul, nat.cast_le], exact le_sum_of_forall_le _ _ _ (λ x hx, m_le_card_of_mem_chunk_increment_parts (hA hx)) }, { exact_mod_cast card_le_m_add_one_of_mem_chunk_increment_parts (hA hu) }, end lemma sum_card_subset_chunk_increment_parts_le (m_pos : (0 : ℝ) < m) {A : finset (finset α)} (hA : A ⊆ (hP.chunk_increment G ε hU).parts) {u : finset α} (hu : u ∈ A) : ((A.sup id).card : ℝ) ≤ (A.card * u.card) * ((m+1)/m) := begin rw [sup_eq_bUnion, mul_div_assoc', le_div_iff m_pos, mul_right_comm], refine mul_le_mul _ _ (nat.cast_nonneg _) (by exact_mod_cast nat.zero_le _), { norm_cast, refine card_bUnion_le_card_mul _ _ _ (λ x hx, _), apply card_le_m_add_one_of_mem_chunk_increment_parts (hA hx) }, { exact_mod_cast m_le_card_of_mem_chunk_increment_parts (hA hu) }, end lemma one_sub_le_m_div_m_add_one_sq [nonempty α] (hPα : P.parts.card * 16^P.parts.card ≤ card α) (hPε : 100 ≤ 4^P.parts.card * ε^5) : 1 - ε^5/50 ≤ (m/(m + 1))^2 := begin have : ((m:ℝ) / (m+1)) = 1 - 1/(m+1), { rw [one_sub_div coe_m_add_one_pos.ne', add_sub_cancel] }, rw [this, sub_sq, one_pow, mul_one], refine le_trans _ (le_add_of_nonneg_right (sq_nonneg _)), rw [sub_le_sub_iff_left, ←le_div_iff' (show (0:ℝ) < 2, by norm_num), div_div_eq_div_mul, one_div_le coe_m_add_one_pos (div_pos (eps_pow_five_pos hPε) (show (0:ℝ) < 50*2, by norm_num)), one_div_div], refine le_trans _ (le_add_of_nonneg_right zero_le_one), norm_num, apply hundred_div_ε_pow_five_le_m hPα hPε, end lemma m_add_one_div_m_le_one_add [nonempty α] (hPα : P.parts.card * 16^P.parts.card ≤ card α) (hPε : 100 ≤ 4^P.parts.card * ε^5) (hε₁ : ε ≤ 1) : ((m + 1 : ℝ)/m)^2 ≤ 1 + ε^5/49 := begin rw same_add_div (m_coe_pos hPα).ne', have : 1 + 1/(m:ℝ) ≤ 1 + ε^5/100, { rw [add_le_add_iff_left, ←one_div_div (100:ℝ)], refine one_div_le_one_div_of_le (div_pos (by norm_num) (eps_pow_five_pos hPε)) _, apply hundred_div_ε_pow_five_le_m hPα hPε }, refine (pow_le_pow_of_le_left _ this 2).trans _, { exact add_nonneg zero_le_one (one_div_nonneg.2 (nat.cast_nonneg _)) }, rw [add_sq, one_pow, add_assoc, add_le_add_iff_left, mul_one, ←le_sub_iff_add_le', div_eq_mul_one_div _ (49:ℝ), mul_div_comm (2:ℝ), ←mul_sub_left_distrib, div_pow, div_le_iff (show (0:ℝ) < 100^2, by norm_num), mul_assoc, sq], refine mul_le_mul_of_nonneg_left _ (eps_pow_five_pos hPε).le, refine (pow_le_one 5 (eps_pos hPε).le hε₁).trans (by norm_num), end lemma density_sub_eps_le_sum_density_div_card [nonempty α] (hPα : P.parts.card * 16^P.parts.card ≤ card α) (hPε : 100 ≤ 4^P.parts.card * ε^5) {U V : finset α} {hU : U ∈ P.parts} {hV : V ∈ P.parts} {A B : finset (finset α)} (hA : A ⊆ (hP.chunk_increment G ε hU).parts) (hB : B ⊆ (hP.chunk_increment G ε hV).parts) : G.edge_density (A.bUnion id) (B.bUnion id) - ε^5/50 ≤ (∑ ab in A.product B, G.edge_density ab.1 ab.2)/(A.card * B.card) := begin have : G.edge_density (A.bUnion id) (B.bUnion id) - ε^5/50 ≤ (1 - ε^5/50) * G.edge_density (A.bUnion id) (B.bUnion id), { rw [sub_mul, one_mul, sub_le_sub_iff_left], refine mul_le_of_le_one_right (div_nonneg (eps_pow_five_pos hPε).le (by norm_num)) _, apply G.edge_density_le_one _ _ }, refine this.trans _, simp only [simple_graph.edge_density, pairs_density, ←sup_eq_bUnion, nat.cast_sum, relation.pairs_count_finpartition (of_subset _ hA rfl) (of_subset _ hB rfl), of_subset_parts, sum_div, mul_sum, div_div_eq_div_mul, mul_div_comm ((1:ℝ) - _)], apply sum_le_sum, simp only [and_imp, prod.forall, mem_product], rintro x y hx hy, rw [mul_mul_mul_comm, mul_comm (x.card : ℝ), mul_comm (y.card : ℝ), le_div_iff, mul_assoc], { apply mul_le_of_le_one_right (nat.cast_nonneg _), rw [div_mul_eq_mul_div, ←mul_assoc, mul_assoc], refine div_le_one_of_le _ (mul_nonneg (nat.cast_nonneg _) (nat.cast_nonneg _)), refine (mul_le_mul_of_nonneg_right (one_sub_le_m_div_m_add_one_sq hPα hPε) _).trans _, { exact_mod_cast (nat.zero_le _) }, rw [sq, mul_mul_mul_comm, mul_comm ((m:ℝ)/_), mul_comm ((m:ℝ)/_)], refine mul_le_mul _ _ _ (nat.cast_nonneg _), apply le_sum_card_subset_chunk_increment_parts hA hx, apply le_sum_card_subset_chunk_increment_parts hB hy, apply mul_nonneg (mul_nonneg (nat.cast_nonneg _) (nat.cast_nonneg _)) _, refine div_nonneg (nat.cast_nonneg m) coe_m_add_one_pos.le }, refine mul_pos (mul_pos _ _) (mul_pos _ _); rw [nat.cast_pos, finset.card_pos], exacts [⟨_, hx⟩, nonempty_of_mem_parts _ (hA hx), ⟨_, hy⟩, nonempty_of_mem_parts _ (hB hy)] end lemma sum_density_div_card_le_density_add_eps [nonempty α] (hPα : P.parts.card * 16^P.parts.card ≤ card α) (hPε : 100 ≤ 4^P.parts.card * ε^5) (hε₁ : ε ≤ 1) {U V : finset α} {hU : U ∈ P.parts} {hV : V ∈ P.parts} {A B : finset (finset α)} (hA : A ⊆ (hP.chunk_increment G ε hU).parts) (hB : B ⊆ (hP.chunk_increment G ε hV).parts) : (∑ ab in A.product B, G.edge_density ab.1 ab.2)/(A.card * B.card) ≤ G.edge_density (A.bUnion id) (B.bUnion id) + ε^5/49 := begin have : (1 + ε^5/49) * G.edge_density (A.bUnion id) (B.bUnion id) ≤ G.edge_density (A.bUnion id) (B.bUnion id) + ε^5/49, { rw [add_mul, one_mul, add_le_add_iff_left], refine mul_le_of_le_one_right (div_nonneg (eps_pow_five_pos hPε).le (by norm_num)) _, apply G.edge_density_le_one }, refine le_trans _ this, simp only [simple_graph.edge_density, pairs_density, ←sup_eq_bUnion, nat.cast_sum, mul_sum, sum_div, relation.pairs_count_finpartition (of_subset _ hA rfl) (of_subset _ hB rfl), of_subset_parts, mul_div_comm ((1:ℝ) + _), div_div_eq_div_mul], apply sum_le_sum, simp only [and_imp, prod.forall, mem_product], intros x y hx hy, rw [mul_mul_mul_comm, mul_comm (x.card : ℝ), mul_comm (y.card : ℝ), div_le_iff, mul_assoc], { refine le_mul_of_one_le_right (nat.cast_nonneg _) _, rw [div_mul_eq_mul_div, one_le_div], refine le_trans _ (mul_le_mul_of_nonneg_right (m_add_one_div_m_le_one_add hPα hPε hε₁) _), { rw [sq, mul_mul_mul_comm, mul_comm (_/(m:ℝ)), mul_comm (_/(m:ℝ))], refine mul_le_mul _ _ (nat.cast_nonneg _) _, apply sum_card_subset_chunk_increment_parts_le (m_coe_pos hPα) hA hx, apply sum_card_subset_chunk_increment_parts_le (m_coe_pos hPα) hB hy, apply mul_nonneg (mul_nonneg (nat.cast_nonneg _) (nat.cast_nonneg _)) _, refine div_nonneg coe_m_add_one_pos.le (nat.cast_nonneg m) }, { exact_mod_cast (nat.zero_le _) }, rw [←nat.cast_mul, nat.cast_pos], apply nat.mul_pos; rw [finset.card_pos, sup_eq_bUnion, bUnion_nonempty], { exact ⟨_, hx, nonempty_of_mem_parts _ (hA hx)⟩ }, { exact ⟨_, hy, nonempty_of_mem_parts _ (hB hy)⟩ } }, refine mul_pos (mul_pos _ _) (mul_pos _ _); rw [nat.cast_pos, finset.card_pos], exacts [⟨_, hx⟩, nonempty_of_mem_parts _ (hA hx), ⟨_, hy⟩, nonempty_of_mem_parts _ (hB hy)] end lemma average_density_near_total_density [nonempty α] (hPα : P.parts.card * 16^P.parts.card ≤ card α) (hPε : 100 ≤ 4^P.parts.card * ε^5) (hε₁ : ε ≤ 1) {U V : finset α} {hU : U ∈ P.parts} {hV : V ∈ P.parts} {A B : finset (finset α)} (hA : A ⊆ (hP.chunk_increment G ε hU).parts) (hB : B ⊆ (hP.chunk_increment G ε hV).parts) : |(∑ ab in A.product B, G.edge_density ab.1 ab.2)/(A.card * B.card) - G.edge_density (A.bUnion id) (B.bUnion id)| ≤ ε^5/49 := begin rw abs_sub_le_iff, split, { rw sub_le_iff_le_add', apply sum_density_div_card_le_density_add_eps hPα hPε hε₁ hA hB }, suffices : G.edge_density (A.bUnion id) (B.bUnion id) - (∑ ab in A.product B, G.edge_density ab.1 ab.2)/(A.card * B.card) ≤ ε^5/50, { apply this.trans, exact div_le_div_of_le_left (eps_pow_five_pos hPε).le (by norm_num) (by norm_num) }, rw [sub_le_iff_le_add, ←sub_le_iff_le_add'], apply density_sub_eps_le_sum_density_div_card hPα hPε hA hB, end -- predagger inequality lemma sq_density_sub_eps_le_sum_sq_density_div_card_aux [nonempty α] (hPα : P.parts.card * 16^P.parts.card ≤ card α) (hPε : 100 ≤ 4^P.parts.card * ε^5) {U V : finset α} (hU : U ∈ P.parts) (hV : V ∈ P.parts) : G.edge_density U V^2 - ε^5/25 ≤ ((∑ ab in (hP.chunk_increment G ε hU).parts.product (hP.chunk_increment G ε hV).parts, G.edge_density ab.1 ab.2)/16^P.parts.card)^2 := begin obtain hGε | hGε := le_total (G.edge_density U V) (ε^5/50), { refine (sub_nonpos_of_le _).trans (sq_nonneg _), refine (sq_le (G.edge_density_nonneg _ _) (G.edge_density_le_one _ _)).trans (hGε.trans _), exact div_le_div_of_le_left (eps_pow_five_pos hPε).le (by norm_num) (by norm_num) }, rw ←sub_nonneg at hGε, have : G.edge_density U V - ε ^ 5 / 50 ≤ (∑ ab in (hP.chunk_increment G ε hU).parts.product (hP.chunk_increment G ε hV).parts, G.edge_density ab.1 ab.2) / (16 ^ P.parts.card), { apply (le_trans _ (density_sub_eps_le_sum_density_div_card hPα hPε (set.subset.refl (hP.chunk_increment G ε hU).parts) (set.subset.refl (hP.chunk_increment G ε hV).parts))).trans _, { rw [bUnion_parts, bUnion_parts] }, { rw [card_chunk_increment (m_pos hPα), card_chunk_increment (m_pos hPα), ←nat.cast_mul, ←mul_pow, nat.cast_pow], norm_cast } }, apply le_trans _ (pow_le_pow_of_le_left hGε this 2), rw [sub_sq, sub_add, sub_le_sub_iff_left], apply (sub_le_self _ (sq_nonneg (ε^5/50))).trans, rw [mul_right_comm, mul_div_comm, div_eq_mul_one_div (ε^5), (show (2:ℝ)/50 = 1/25, by norm_num)], refine mul_le_of_le_one_right (mul_nonneg _ (by norm_num)) (G.edge_density_le_one _ _), apply (eps_pow_five_pos hPε).le, end -- dagger inequality lemma sq_density_sub_eps_le_sum_sq_density_div_card [nonempty α] (hPα : P.parts.card * 16^P.parts.card ≤ card α) (hPε : 100 ≤ 4^P.parts.card * ε^5) {U V : finset α} (hU : U ∈ P.parts) (hV : V ∈ P.parts) : G.edge_density U V^2 - ε^5/25 ≤ (∑ ab in (hP.chunk_increment G ε hU).parts.product (hP.chunk_increment G ε hV).parts, G.edge_density ab.1 ab.2^2)/16^P.parts.card := begin apply (sq_density_sub_eps_le_sum_sq_density_div_card_aux hPα hPε hU hV).trans, convert chebyshev _ _; rw [card_product, nat.cast_mul, card_chunk_increment (m_pos hPα), card_chunk_increment (m_pos hPα), ←nat.cast_mul, ←mul_pow]; norm_cast, end lemma abs_density_star_sub_density_le_eps (hPε : 100 ≤ 4^P.parts.card * ε^5) (hε₁ : ε ≤ 1) {U V : finset α} {hU : U ∈ P.parts} {hV : V ∈ P.parts} (hUV' : U ≠ V) (hUV : ¬ G.is_uniform ε U V) : |G.edge_density ((hP.star G ε hU V).bUnion id) ((hP.star G ε hV U).bUnion id) - G.edge_density (G.witness ε U V) (G.witness ε V U)| ≤ ε/5 := begin convert lemma_A G.adj (bUnion_star_subset_witness hP G ε hU V) (bUnion_star_subset_witness hP G ε hV U) (div_nonneg (eps_pos hPε).le $ by norm_num) (one_sub_eps_mul_card_witness_le_card_star hV hUV' hUV hPε hε₁) (one_sub_eps_mul_card_witness_le_card_star hU hUV'.symm (λ hVU, hUV hVU.symm) hPε hε₁), linarith, end lemma m_bound {x : ℝ} (hx : 0 < x) : (x + 1) * (1 - 1/x) / x ≤ 1 := begin rw [div_le_one hx, one_sub_div hx.ne', mul_div_assoc', div_le_iff hx], linarith, end lemma eps_le_card_star_div [nonempty α] (hPα : P.parts.card * 16^P.parts.card ≤ card α) (hPε : 100 ≤ 4^P.parts.card * ε^5) (hε₁ : ε ≤ 1) {U V : finset α} (hU : U ∈ P.parts) (hV : V ∈ P.parts) (hUV : U ≠ V) (hunif : ¬ G.is_uniform ε U V) : 4/5 * ε ≤ (hP.star G ε hU V).card / 4^P.parts.card := begin have hm : (0 : ℝ) ≤ 1 - 1/m := sub_nonneg_of_le (one_div_le_one_of_one_le $ one_le_m_coe hPα), have hε : 0 ≤ 1 - ε / 10 := sub_nonneg_of_le (div_le_one_of_le (hε₁.trans $ by norm_num) $ by norm_num), calc 4/5 * ε = (1 - 1/10) * (1 - 1/9) * ε : by norm_num ... ≤ (1 - ε/10) * (1 - 1/m) * ((G.witness ε U V).card / U.card) : mul_le_mul (mul_le_mul (sub_le_sub_left (div_le_div_of_le_of_nonneg hε₁ $ by norm_num) _) (sub_le_sub_left (div_le_div_of_le_left zero_le_one (by norm_num) (by exact_mod_cast ((show 9 ≤ 100, by norm_num).trans $ hundred_le_m hPα hPε hε₁))) _) (by norm_num) hε) ((le_div_iff' $ (@nat.cast_pos ℝ _ _ _).2 (P.nonempty_of_mem_parts hU).card_pos).2 (G.witness_card hunif)) (eps_pos hPε).le (mul_nonneg hε hm) ... = (1 - ε/10) * (G.witness ε U V).card * ((1 - 1/m) / U.card) : by rw [mul_assoc, mul_assoc, mul_div_comm] ... ≤ ((hP.star G ε hU V).bUnion id).card * ((1 - 1/m) / U.card) : (mul_le_mul_of_nonneg_right (one_sub_eps_mul_card_witness_le_card_star hV hUV hunif hPε hε₁) (div_nonneg hm $ nat.cast_nonneg _)) ... ≤ (hP.star G ε hU V).card * (m + 1) * ((1 - 1/m) / U.card) : mul_le_mul_of_nonneg_right card_bUnion_star_le_m_add_one_card_star_mul (div_nonneg hm $ nat.cast_nonneg _) ... ≤ (hP.star G ε hU V).card * (m + 1) * ((1 - 1/m) / (4^P.parts.card * m)) : mul_le_mul_of_nonneg_left (div_le_div_of_le_left hm (mul_pos four_pow_pos $ m_coe_pos hPα) $ pow_mul_m_le_card_part hP hU) (mul_nonneg (nat.cast_nonneg _) $ add_nonneg (nat.cast_nonneg _) zero_le_one) ... ≤ (hP.star G ε hU V).card / 4^P.parts.card : begin rw [mul_assoc, mul_comm ((4:ℝ)^P.parts.card), ←div_div_eq_div_mul, ←mul_div_assoc, ←div_mul_eq_mul_div_comm], refine mul_le_of_le_one_right (div_nonneg (nat.cast_nonneg _) four_pow_pos.le) _, rw mul_div_assoc', apply m_bound (m_coe_pos hPα), end end lemma stuff [nonempty α] (hPα : P.parts.card * 16^P.parts.card ≤ card α) (hPε : 100 ≤ 4^P.parts.card * ε^5) (hε₁ : ε ≤ 1) {U V : finset α} {hU : U ∈ P.parts} {hV : V ∈ P.parts} (h_diff : U ≠ V) (hUV : ¬ G.is_uniform ε U V) : 3/4 * ε ≤ |(∑ ab in (hP.star G ε hU V).product (hP.star G ε hV U), G.edge_density ab.1 ab.2) / ((hP.star G ε hU V).card * (hP.star G ε hV U).card) - (∑ ab in (hP.chunk_increment G ε hU).parts.product (hP.chunk_increment G ε hV).parts, G.edge_density ab.1 ab.2)/16^P.parts.card| := begin rw [(show (16:ℝ) = 4^2, by norm_num), pow_right_comm, sq ((4:ℝ)^_)], set p := (∑ ab in (hP.star G ε hU V).product (hP.star G ε hV U), G.edge_density ab.1 ab.2) / ((hP.star G ε hU V).card * (hP.star G ε hV U).card), set q := (∑ ab in (hP.chunk_increment G ε hU).parts.product (hP.chunk_increment G ε hV).parts, G.edge_density ab.1 ab.2)/(4 ^ P.parts.card * 4 ^ P.parts.card), change _ ≤ |p - q|, set r := G.edge_density ((hP.star G ε hU V).bUnion id) ((hP.star G ε hV U).bUnion id), set s := G.edge_density (G.witness ε U V) (G.witness ε V U), set t := G.edge_density U V, have hrs : |r - s| ≤ ε/5 := abs_density_star_sub_density_le_eps hPε hε₁ h_diff hUV, have hst : ε ≤ |s - t| := G.witness_pair_spec h_diff hUV, have hpr : |p - r| ≤ ε^5/49 := average_density_near_total_density hPα hPε hε₁ star_subset_chunk_increment star_subset_chunk_increment, have hqt : |q - t| ≤ ε^5/49, { have := average_density_near_total_density hPα hPε hε₁ (subset.refl (hP.chunk_increment G ε hU).parts) (subset.refl (hP.chunk_increment G ε hV).parts), simp_rw [←sup_eq_bUnion, sup_parts, card_chunk_increment (m_pos hPα), nat.cast_pow] at this, norm_num at this, exact this }, have hε : 0 < ε := eps_pos hPε, have hpr' : |p - r| ≤ ε/49, { refine hpr.trans (div_le_div_of_le_of_nonneg _ (by norm_num)), simpa using pow_le_pow_of_le_one hε.le hε₁ (show 1 ≤ 5, by norm_num) }, have hqt' : |q - t| ≤ ε/49, { apply hqt.trans (div_le_div_of_le_of_nonneg _ (by norm_num)), simpa using pow_le_pow_of_le_one hε.le hε₁ (show 1 ≤ 5, by norm_num) }, rw abs_sub_le_iff at hrs hpr' hqt', rw le_abs at hst ⊢, cases hst, left, linarith, right, linarith, end -- double dagger inequality lemma sq_density_sub_eps_le_sum_sq_density_div_card_of_nonuniform [nonempty α] (hPα : P.parts.card * 16^P.parts.card ≤ card α) (hPε : 100 ≤ 4^P.parts.card * ε^5) (hε₁ : ε ≤ 1) {U V : finset α} {hU : U ∈ P.parts} {hV : V ∈ P.parts} (h_diff : U ≠ V) (hUV : ¬ G.is_uniform ε U V) : G.edge_density U V^2 - ε^5/25 + ε^4/3 ≤ (∑ ab in (hP.chunk_increment G ε hU).parts.product (hP.chunk_increment G ε hV).parts, G.edge_density ab.1 ab.2^2)/16^P.parts.card := calc G.edge_density U V^2 - ε^5/25 + ε^4/3 ≤ G.edge_density U V^2 - ε^5/25 + (hP.star G ε hU V).card * (hP.star G ε hV U).card/16^P.parts.card * (9/16) * ε^2 : begin apply add_le_add_left, have Ul : 4/5 * ε ≤ (hP.star G ε hU V).card / _ := eps_le_card_star_div hPα hPε hε₁ hU hV h_diff hUV, have Vl : 4/5 * ε ≤ (hP.star G ε hV U).card / _ := eps_le_card_star_div hPα hPε hε₁ hV hU h_diff.symm (λ h, hUV h.symm), rw [(show (16:ℝ) = 4^2, by norm_num), pow_right_comm, sq ((4:ℝ)^_), ←div_mul_div, mul_assoc], have UVl := mul_le_mul Ul Vl (mul_nonneg (by norm_num) (eps_pos hPε).le) (div_nonneg (nat.cast_nonneg _) four_pow_pos.le), apply le_trans _ (mul_le_mul_of_nonneg_right UVl _), { field_simp, ring_nf, apply mul_le_mul_of_nonneg_right, norm_num, exact pow_nonneg (eps_pos hPε).le _ }, { norm_num, exact pow_nonneg (eps_pos hPε).le _ }, end ... ≤ (∑ ab in (hP.chunk_increment G ε hU).parts.product (hP.chunk_increment G ε hV).parts, G.edge_density ab.1 ab.2^2)/16^P.parts.card : begin have t : (hP.star G ε hU V).product (hP.star G ε hV U) ⊆ (hP.chunk_increment G ε hU).parts.product (hP.chunk_increment G ε hV).parts := product_subset_product star_subset_chunk_increment star_subset_chunk_increment, have hε : 0 ≤ ε := (eps_pos hPε).le, have h₁ : 0 ≤ 3/4 * ε := by linarith, have := lemma_B_ineq t (λ x, G.edge_density x.1 x.2) (G.edge_density U V^2 - ε^5/25) h₁ _ _, { simp_rw [card_product, card_chunk_increment (m_pos hPα), ←mul_pow, nat.cast_pow, mul_pow, div_pow, ←mul_assoc] at this, norm_num at this, exact this }, { simp_rw [card_product, card_chunk_increment (m_pos hPα), ←mul_pow], norm_num, exact stuff hPα hPε hε₁ h_diff hUV }, { rw card_product, apply (sq_density_sub_eps_le_sum_sq_density_div_card_aux hPα hPε hU hV).trans, rw [card_chunk_increment (m_pos hPα), card_chunk_increment (m_pos hPα), ←mul_pow], norm_num, exact hP } end
3c8598f524f0280041c36eb3b22f1fb5c01f1954
8b9f17008684d796c8022dab552e42f0cb6fb347
/hott/algebra/relation.hlean
95d476061543a2b17951219f2d8122f717c2b85f
[ "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
4,446
hlean
/- Copyright (c) 2014 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Module: algebra.relation Author: Jeremy Avigad General properties of relations, and classes for equivalence relations and congruences. -/ namespace relation /- properties of binary relations -/ section variables {T : Type} (R : T → T → Type) definition reflexive : Type := Πx, R x x definition symmetric : Type := Π⦃x y⦄, R x y → R y x definition transitive : Type := Π⦃x y z⦄, R x y → R y z → R x z end /- classes for equivalence relations -/ structure is_reflexive [class] {T : Type} (R : T → T → Type) := (refl : reflexive R) structure is_symmetric [class] {T : Type} (R : T → T → Type) := (symm : symmetric R) structure is_transitive [class] {T : Type} (R : T → T → Type) := (trans : transitive R) structure is_equivalence [class] {T : Type} (R : T → T → Type) extends is_reflexive R, is_symmetric R, is_transitive R -- partial equivalence relation structure is_PER {T : Type} (R : T → T → Type) extends is_symmetric R, is_transitive R -- Generic notation. For example, is_refl R is the reflexivity of R, if that can be -- inferred by type class inference section variables {T : Type} (R : T → T → Type) definition rel_refl [C : is_reflexive R] := is_reflexive.refl R definition rel_symm [C : is_symmetric R] := is_symmetric.symm R definition rel_trans [C : is_transitive R] := is_transitive.trans R end /- classes for unary and binary congruences with respect to arbitrary relations -/ structure is_congruence [class] {T1 : Type} (R1 : T1 → T1 → Type) {T2 : Type} (R2 : T2 → T2 → Type) (f : T1 → T2) := (congr : Π{x y}, R1 x y → R2 (f x) (f y)) structure is_congruence2 [class] {T1 : Type} (R1 : T1 → T1 → Type) {T2 : Type} (R2 : T2 → T2 → Type) {T3 : Type} (R3 : T3 → T3 → Type) (f : T1 → T2 → T3) := (congr2 : Π{x1 y1 : T1} {x2 y2 : T2}, R1 x1 y1 → R2 x2 y2 → R3 (f x1 x2) (f y1 y2)) namespace is_congruence -- makes the type class explicit definition app {T1 : Type} {R1 : T1 → T1 → Type} {T2 : Type} {R2 : T2 → T2 → Type} {f : T1 → T2} (C : is_congruence R1 R2 f) ⦃x y : T1⦄ : R1 x y → R2 (f x) (f y) := is_congruence.rec (λu, u) C x y definition app2 {T1 : Type} {R1 : T1 → T1 → Type} {T2 : Type} {R2 : T2 → T2 → Type} {T3 : Type} {R3 : T3 → T3 → Type} {f : T1 → T2 → T3} (C : is_congruence2 R1 R2 R3 f) ⦃x1 y1 : T1⦄ ⦃x2 y2 : T2⦄ : R1 x1 y1 → R2 x2 y2 → R3 (f x1 x2) (f y1 y2) := is_congruence2.rec (λu, u) C x1 y1 x2 y2 /- tools to build instances -/ theorem compose {T2 : Type} {R2 : T2 → T2 → Type} {T3 : Type} {R3 : T3 → T3 → Type} {g : T2 → T3} (C2 : is_congruence R2 R3 g) ⦃T1 : Type⦄ {R1 : T1 → T1 → Type} {f : T1 → T2} (C1 : is_congruence R1 R2 f) : is_congruence R1 R3 (λx, g (f x)) := is_congruence.mk (λx1 x2 H, app C2 (app C1 H)) theorem compose21 {T2 : Type} {R2 : T2 → T2 → Type} {T3 : Type} {R3 : T3 → T3 → Type} {T4 : Type} {R4 : T4 → T4 → Type} {g : T2 → T3 → T4} (C3 : is_congruence2 R2 R3 R4 g) ⦃T1 : Type⦄ {R1 : T1 → T1 → Type} {f1 : T1 → T2} (C1 : is_congruence R1 R2 f1) {f2 : T1 → T3} (C2 : is_congruence R1 R3 f2) : is_congruence R1 R4 (λx, g (f1 x) (f2 x)) := is_congruence.mk (λx1 x2 H, app2 C3 (app C1 H) (app C2 H)) theorem const {T2 : Type} (R2 : T2 → T2 → Type) (H : relation.reflexive R2) ⦃T1 : Type⦄ (R1 : T1 → T1 → Type) (c : T2) : is_congruence R1 R2 (λu : T1, c) := is_congruence.mk (λx y H1, H c) end is_congruence theorem congruence_const [instance] {T2 : Type} (R2 : T2 → T2 → Type) [C : is_reflexive R2] ⦃T1 : Type⦄ (R1 : T1 → T1 → Type) (c : T2) : is_congruence R1 R2 (λu : T1, c) := is_congruence.const R2 (is_reflexive.refl R2) R1 c theorem congruence_trivial [instance] {T : Type} (R : T → T → Type) : is_congruence R R (λu, u) := is_congruence.mk (λx y H, H) /- relations that can be coerced to functions / implications-/ structure mp_like [class] (R : Type → Type → Type) := (app : Π{a b : Type}, R a b → (a → b)) definition rel_mp (R : Type → Type → Type) [C : mp_like R] {a b : Type} (H : R a b) := mp_like.app H end relation
653d123946487a86d2dde35578f1e3af677fb131
8cae430f0a71442d02dbb1cbb14073b31048e4b0
/src/topology/algebra/uniform_mul_action.lean
55eefec7ba24562811eee24ada07d00e646ac96d
[ "Apache-2.0" ]
permissive
leanprover-community/mathlib
56a2cadd17ac88caf4ece0a775932fa26327ba0e
442a83d738cb208d3600056c489be16900ba701d
refs/heads/master
1,693,584,102,358
1,693,471,902,000
1,693,471,902,000
97,922,418
1,595
352
Apache-2.0
1,694,693,445,000
1,500,624,130,000
Lean
UTF-8
Lean
false
false
7,412
lean
/- Copyright (c) 2022 Yury G. Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury G. Kudryashov -/ import topology.algebra.uniform_group import topology.uniform_space.completion /-! # Multiplicative action on the completion of a uniform space > THIS FILE IS SYNCHRONIZED WITH MATHLIB4. > Any changes to this file require a corresponding PR to mathlib4. In this file we define typeclasses `has_uniform_continuous_const_vadd` and `has_uniform_continuous_const_smul` and prove that a multiplicative action on `X` with uniformly continuous `(•) c` can be extended to a multiplicative action on `uniform_space.completion X`. In later files once the additive group structure is set up, we provide * `uniform_space.completion.distrib_mul_action` * `uniform_space.completion.mul_action_with_zero` * `uniform_space.completion.module` TODO: Generalise the results here from the concrete `completion` to any `abstract_completion`. -/ universes u v w x y z noncomputable theory variables (R : Type u) (M : Type v) (N : Type w) (X : Type x) (Y : Type y) [uniform_space X] [uniform_space Y] /-- An additive action such that for all `c`, the map `λ x, c +ᵥ x` is uniformly continuous. -/ class has_uniform_continuous_const_vadd [has_vadd M X] : Prop := (uniform_continuous_const_vadd : ∀ (c : M), uniform_continuous ((+ᵥ) c : X → X)) /-- A multiplicative action such that for all `c`, the map `λ x, c • x` is uniformly continuous. -/ @[to_additive] class has_uniform_continuous_const_smul [has_smul M X] : Prop := (uniform_continuous_const_smul : ∀ (c : M), uniform_continuous ((•) c : X → X)) export has_uniform_continuous_const_vadd (uniform_continuous_const_vadd) has_uniform_continuous_const_smul (uniform_continuous_const_smul) instance add_monoid.has_uniform_continuous_const_smul_nat [add_group X] [uniform_add_group X] : has_uniform_continuous_const_smul ℕ X := ⟨uniform_continuous_const_nsmul⟩ instance add_group.has_uniform_continuous_const_smul_int [add_group X] [uniform_add_group X] : has_uniform_continuous_const_smul ℤ X := ⟨uniform_continuous_const_zsmul⟩ /-- A `distrib_mul_action` that is continuous on a uniform group is uniformly continuous. This can't be an instance due to it forming a loop with `has_uniform_continuous_const_smul.to_has_continuous_const_smul` -/ lemma has_uniform_continuous_const_smul_of_continuous_const_smul [monoid R] [add_comm_group M] [distrib_mul_action R M] [uniform_space M] [uniform_add_group M] [has_continuous_const_smul R M] : has_uniform_continuous_const_smul R M := ⟨λ r, uniform_continuous_of_continuous_at_zero (distrib_mul_action.to_add_monoid_hom M r) (continuous.continuous_at (continuous_const_smul r))⟩ /-- The action of `semiring.to_module` is uniformly continuous. -/ instance ring.has_uniform_continuous_const_smul [ring R] [uniform_space R] [uniform_add_group R] [has_continuous_mul R] : has_uniform_continuous_const_smul R R := has_uniform_continuous_const_smul_of_continuous_const_smul _ _ /-- The action of `semiring.to_opposite_module` is uniformly continuous. -/ instance ring.has_uniform_continuous_const_op_smul [ring R] [uniform_space R] [uniform_add_group R] [has_continuous_mul R] : has_uniform_continuous_const_smul Rᵐᵒᵖ R := has_uniform_continuous_const_smul_of_continuous_const_smul _ _ section has_smul variable [has_smul M X] @[priority 100, to_additive] instance has_uniform_continuous_const_smul.to_has_continuous_const_smul [has_uniform_continuous_const_smul M X] : has_continuous_const_smul M X := ⟨λ c, (uniform_continuous_const_smul c).continuous⟩ variables {M X Y} @[to_additive] lemma uniform_continuous.const_smul [has_uniform_continuous_const_smul M X] {f : Y → X} (hf : uniform_continuous f) (c : M) : uniform_continuous (c • f) := (uniform_continuous_const_smul c).comp hf /-- If a scalar action is central, then its right action is uniform continuous when its left action is. -/ @[priority 100, to_additive "If an additive action is central, then its right action is uniform continuous when its left action,is."] instance has_uniform_continuous_const_smul.op [has_smul Mᵐᵒᵖ X] [is_central_scalar M X] [has_uniform_continuous_const_smul M X] : has_uniform_continuous_const_smul Mᵐᵒᵖ X := ⟨mul_opposite.rec $ λ c, begin change uniform_continuous (λ m, mul_opposite.op c • m), simp_rw op_smul_eq_smul, exact uniform_continuous_const_smul c, end⟩ @[to_additive] instance mul_opposite.has_uniform_continuous_const_smul [has_uniform_continuous_const_smul M X] : has_uniform_continuous_const_smul M Xᵐᵒᵖ := ⟨λ c, mul_opposite.uniform_continuous_op.comp $ mul_opposite.uniform_continuous_unop.const_smul c⟩ end has_smul @[to_additive] instance uniform_group.to_has_uniform_continuous_const_smul {G : Type u} [group G] [uniform_space G] [uniform_group G] : has_uniform_continuous_const_smul G G := ⟨λ c, uniform_continuous_const.mul uniform_continuous_id⟩ namespace uniform_space namespace completion section has_smul variable [has_smul M X] @[to_additive] instance : has_smul M (completion X) := ⟨λ c, completion.map ((•) c)⟩ @[to_additive] lemma smul_def (c : M) (x : completion X) : c • x = completion.map ((•) c) x := rfl @[to_additive] instance : has_uniform_continuous_const_smul M (completion X) := ⟨λ c, uniform_continuous_map⟩ @[to_additive] instance [has_smul N X] [has_smul M N] [has_uniform_continuous_const_smul M X] [has_uniform_continuous_const_smul N X] [is_scalar_tower M N X] : is_scalar_tower M N (completion X) := ⟨λ m n x, begin have : _ = (_ : completion X → completion X) := map_comp (uniform_continuous_const_smul m) (uniform_continuous_const_smul n), refine eq.trans _ (congr_fun this.symm x), exact congr_arg (λ f, completion.map f x) (by exact funext (smul_assoc _ _)), end⟩ @[to_additive] instance [has_smul N X] [smul_comm_class M N X] [has_uniform_continuous_const_smul M X] [has_uniform_continuous_const_smul N X] : smul_comm_class M N (completion X) := ⟨λ m n x, begin have hmn : m • n • x = (( completion.map (has_smul.smul m)) ∘ (completion.map (has_smul.smul n))) x := rfl, have hnm : n • m • x = (( completion.map (has_smul.smul n)) ∘ (completion.map (has_smul.smul m))) x := rfl, rw [hmn, hnm, map_comp, map_comp], exact congr_arg (λ f, completion.map f x) (by exact funext (smul_comm _ _)), repeat{ exact uniform_continuous_const_smul _}, end⟩ @[to_additive] instance [has_smul Mᵐᵒᵖ X] [is_central_scalar M X] : is_central_scalar M (completion X) := ⟨λ c a, congr_arg (λ f, completion.map f a) $ by exact funext (op_smul_eq_smul c)⟩ variables {M X} [has_uniform_continuous_const_smul M X] @[simp, norm_cast, to_additive] lemma coe_smul (c : M) (x : X) : ↑(c • x) = (c • x : completion X) := (map_coe (uniform_continuous_const_smul c) x).symm end has_smul @[to_additive] instance [monoid M] [mul_action M X] [has_uniform_continuous_const_smul M X] : mul_action M (completion X) := { smul := (•), one_smul := ext' (continuous_const_smul _) continuous_id $ λ a, by rw [← coe_smul, one_smul], mul_smul := λ x y, ext' (continuous_const_smul _) ((continuous_const_smul _).const_smul _) $ λ a, by simp only [← coe_smul, mul_smul] } end completion end uniform_space
0438f00428da5cc089db50bc9df4d423434bdc3c
7282d49021d38dacd06c4ce45a48d09627687fe0
/tests/lean/exists8.lean
725cceaed9e865f6eca5776939a1cfb21a59293a
[ "Apache-2.0" ]
permissive
steveluc/lean
5a0b4431acefaf77f15b25bbb49294c2449923ad
92ba4e8b2d040a799eda7deb8d2a7cdd3e69c496
refs/heads/master
1,611,332,256,930
1,391,013,244,000
1,391,013,244,000
16,361,079
1
0
null
null
null
null
UTF-8
Lean
false
false
1,126
lean
import Int. variable P : Int -> Int -> Bool theorem T1 (R1 : not (exists x y, P x y)) : forall x y, not (P x y) := fun a b, (not_exists_elim (not_exists_elim R1 a)) b axiom Ax : forall x, exists y, P x y theorem T2 : exists x y, P x y := refute (fun R : not (exists x y, P x y), let L1 : forall x y, not (P x y) := fun a b, (not_exists_elim ((not_exists_elim R) a)) b, L2 : exists y, P 0 y := Ax 0 in exists_elim L2 (fun (w : Int) (H : P 0 w), absurd H (L1 0 w))). theorem T3 (A : (Type U)) (P : A -> A -> Bool) (a : A) (H1 : forall x, exists y, P x y) : exists x y, P x y := refute (fun R : not (exists x y, P x y), let L1 : forall x y, not (P x y) := fun a b, (not_exists_elim ((not_exists_elim R) a)) b, L2 : exists y, P a y := H1 a in exists_elim L2 (fun (w : A) (H : P a w), absurd H ((L1 a) w))).
abd4c8db1fc2820aa3398f156532212f4a49ed9f
69d4931b605e11ca61881fc4f66db50a0a875e39
/src/algebra/group/hom_instances.lean
be6ea16686823d85816cde123443a01476d60fc7
[ "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
9,572
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_power.basic /-! # Instances on spaces of monoid and group morphisms We endow the space of monoid morphisms `M →* N` with a `comm_monoid` structure when the target is commutative, through pointwise multiplication, and with a `comm_group` structure when the target is a commutative group. We also prove the same instances for additive situations. Since these structures permit morphisms of morphisms, we also provide some composition-like operations. -/ universes uM uN uP uQ variables {M : Type uM} {N : Type uN} {P : Type uP} {Q : Type uQ} lemma nat.succ_eq_one_add (n : ℕ) : n.succ = 1 + n := by rw [nat.succ_eq_add_one, nat.add_comm] /-- `(M →* N)` is a `comm_monoid` if `N` is commutative. -/ instance [mul_one_class M] [comm_monoid N] : comm_monoid (M →* N) := { mul := (*), mul_assoc := by intros; ext; apply mul_assoc, one := 1, one_mul := by intros; ext; apply one_mul, mul_one := by intros; ext; apply mul_one, mul_comm := by intros; ext; apply mul_comm, npow := λ n f, { to_fun := λ x, npow n (f x), map_one' := by simp, map_mul' := λ x y, by simp [mul_pow] }, npow_zero' := λ f, by { ext x, simp }, npow_succ' := λ n f, by { ext x, simp [pow_succ] } } /-- `(M →+ N)` is an `add_comm_monoid` if `N` is commutative. -/ instance [add_zero_class M] [add_comm_monoid N] : add_comm_monoid (M →+ N) := { add := (+), add_assoc := by intros; ext; apply add_assoc, zero := 0, zero_add := by intros; ext; apply zero_add, add_zero := by intros; ext; apply add_zero, add_comm := by intros; ext; apply add_comm, nsmul := λ n f, { to_fun := λ x, nsmul n (f x), map_zero' := by simp [nsmul_zero], map_add' := λ x y, by simp [nsmul_add] }, nsmul_zero' := λ f, by { ext x, simp [zero_nsmul], }, nsmul_succ' := λ n f, by { ext x, simp [nat.succ_eq_one_add, add_nsmul] } } attribute [to_additive] monoid_hom.comm_monoid /-- If `G` is a commutative group, then `M →* G` is a commutative group too. -/ instance {M G} [mul_one_class M] [comm_group G] : comm_group (M →* G) := { inv := has_inv.inv, div := has_div.div, div_eq_mul_inv := by { intros, ext, apply div_eq_mul_inv }, mul_left_inv := by intros; ext; apply mul_left_inv, gpow := λ n f, { to_fun := λ x, gpow n (f x), map_one' := by simp, map_mul' := λ x y, by simp [mul_gpow] }, gpow_zero' := λ f, by { ext x, simp }, gpow_succ' := λ n f, by { ext x, simp [gpow_of_nat, pow_succ] }, gpow_neg' := λ n f, by { ext x, simp }, ..monoid_hom.comm_monoid } /-- If `G` is an additive commutative group, then `M →+ G` is an additive commutative group too. -/ instance {M G} [add_zero_class M] [add_comm_group G] : add_comm_group (M →+ G) := { neg := has_neg.neg, sub := has_sub.sub, sub_eq_add_neg := by { intros, ext, apply sub_eq_add_neg }, add_left_neg := by intros; ext; apply add_left_neg, gsmul := λ n f, { to_fun := λ x, gsmul n (f x), map_zero' := by simp, map_add' := λ x y, by simp [gsmul_add] }, gsmul_zero' := λ f, by { ext x, simp }, gsmul_succ' := λ n f, by { ext x, simp [gsmul_of_nat, nat.succ_eq_one_add, add_nsmul] }, gsmul_neg' := λ n f, by { ext x, simp }, ..add_monoid_hom.add_comm_monoid } attribute [to_additive] monoid_hom.comm_group /-! ### Morphisms of morphisms The structures above permit morphisms that themselves produce morphisms, provided the codomain is commutative. -/ namespace monoid_hom @[to_additive] lemma ext_iff₂ {mM : mul_one_class M} {mN : mul_one_class N} {mP : comm_monoid P} {f g : M →* N →* P} : f = g ↔ (∀ x y, f x y = g x y) := monoid_hom.ext_iff.trans $ forall_congr $ λ _, monoid_hom.ext_iff /-- `flip` arguments of `f : M →* N →* P` -/ @[to_additive "`flip` arguments of `f : M →+ N →+ P`"] def flip {mM : mul_one_class M} {mN : mul_one_class N} {mP : comm_monoid P} (f : M →* N →* P) : N →* M →* P := { to_fun := λ y, ⟨λ x, f x y, by rw [f.map_one, one_apply], λ x₁ x₂, by rw [f.map_mul, mul_apply]⟩, map_one' := ext $ λ x, (f x).map_one, map_mul' := λ y₁ y₂, ext $ λ x, (f x).map_mul y₁ y₂ } @[simp, to_additive] lemma flip_apply {mM : mul_one_class M} {mN : mul_one_class N} {mP : comm_monoid P} (f : M →* N →* P) (x : M) (y : N) : f.flip y x = f x y := rfl /-- Evaluation of a `monoid_hom` at a point as a monoid homomorphism. See also `monoid_hom.apply` for the evaluation of any function at a point. -/ @[to_additive "Evaluation of an `add_monoid_hom` at a point as an additive monoid homomorphism. See also `add_monoid_hom.apply` for the evaluation of any function at a point.", simps] def eval [mul_one_class M] [comm_monoid N] : M →* (M →* N) →* N := (monoid_hom.id (M →* N)).flip /-- The expression `λ g m, g (f m)` as a `monoid_hom`. Equivalently, `(λ g, monoid_hom.comp g f)` as a `monoid_hom`. -/ @[to_additive "The expression `λ g m, g (f m)` as a `add_monoid_hom`. Equivalently, `(λ g, monoid_hom.comp g f)` as a `add_monoid_hom`. This also exists in a `linear_map` version, `linear_map.lcomp`.", simps] def comp_hom' [mul_one_class M] [mul_one_class N] [comm_monoid P] (f : M →* N) : (N →* P) →* M →* P := flip $ eval.comp f /-- Composition of monoid morphisms (`monoid_hom.comp`) as a monoid morphism. Note that unlike `monoid_hom.comp_hom'` this requires commutativity of `N`. -/ @[to_additive "Composition of additive monoid morphisms (`add_monoid_hom.comp`) as an additive monoid morphism. Note that unlike `add_monoid_hom.comp_hom'` this requires commutativity of `N`. This also exists in a `linear_map` version, `linear_map.llcomp`.", simps] def comp_hom [mul_one_class M] [comm_monoid N] [comm_monoid P] : (N →* P) →* (M →* N) →* (M →* P) := { to_fun := λ g, { to_fun := g.comp, map_one' := comp_one g, map_mul' := comp_mul g }, map_one' := by { ext1 f, exact one_comp f }, map_mul' := λ g₁ g₂, by { ext1 f, exact mul_comp g₁ g₂ f } } /-- Flipping arguments of monoid morphisms (`monoid_hom.flip`) as a monoid morphism. -/ @[to_additive "Flipping arguments of additive monoid morphisms (`add_monoid_hom.flip`) as an additive monoid morphism.", simps] def flip_hom {mM : mul_one_class M} {mN : mul_one_class N} {mP : comm_monoid P} : (M →* N →* P) →* (N →* M →* P) := { to_fun := monoid_hom.flip, map_one' := rfl, map_mul' := λ f g, rfl } /-- The expression `λ m q, f m (g q)` as a `monoid_hom`. Note that the expression `λ q n, f (g q) n` is simply `monoid_hom.comp`. -/ @[to_additive "The expression `λ m q, f m (g q)` as an `add_monoid_hom`. Note that the expression `λ q n, f (g q) n` is simply `add_monoid_hom.comp`. This also exists as a `linear_map` version, `linear_map.compl₂`"] def compl₂ [mul_one_class M] [mul_one_class N] [comm_monoid P] [comm_monoid Q] (f : M →* N →* P) (g : Q →* N) : M →* Q →* P := (comp_hom' g).comp f @[simp, to_additive] lemma compl₂_apply [mul_one_class M] [mul_one_class N] [comm_monoid P] [comm_monoid Q] (f : M →* N →* P) (g : Q →* N) (m : M) (q : Q) : (compl₂ f g) m q = f m (g q) := rfl /-- The expression `λ m n, g (f m n)` as a `monoid_hom`. -/ @[to_additive "The expression `λ m n, g (f m n)` as an `add_monoid_hom`. This also exists as a linear_map version, `linear_map.compr₂`"] def compr₂ [mul_one_class M] [mul_one_class N] [comm_monoid P] [comm_monoid Q] (f : M →* N →* P) (g : P →* Q) : M →* N →* Q := (comp_hom g).comp f @[simp, to_additive] lemma compr₂_apply [mul_one_class M] [mul_one_class N] [comm_monoid P] [comm_monoid Q] (f : M →* N →* P) (g : P →* Q) (m : M) (n : N) : (compr₂ f g) m n = g (f m n) := rfl end monoid_hom /-! ### Miscellaneous definitions Due to the fact this file imports `algebra.group_power.basic`, it is not possible to import it in some of the lower-level files like `algebra.ring.basic`. The following lemmas should be rehomed if the import structure permits them to be. -/ section semiring variables {R S : Type*} [semiring R] [semiring S] /-- Multiplication of an element of a (semi)ring is an `add_monoid_hom` in both arguments. This is a more-strongly bundled version of `add_monoid_hom.mul_left` and `add_monoid_hom.mul_right`. A stronger version of this exists for algebras as `algebra.lmul`. -/ def add_monoid_hom.mul : R →+ R →+ R := { to_fun := add_monoid_hom.mul_left, map_zero' := add_monoid_hom.ext $ zero_mul, map_add' := λ a b, add_monoid_hom.ext $ add_mul a b } lemma add_monoid_hom.mul_apply (x y : R) : add_monoid_hom.mul x y = x * y := rfl @[simp] lemma add_monoid_hom.coe_mul : ⇑(add_monoid_hom.mul : R →+ R →+ R) = add_monoid_hom.mul_left := rfl @[simp] lemma add_monoid_hom.coe_flip_mul : ⇑(add_monoid_hom.mul : R →+ R →+ R).flip = add_monoid_hom.mul_right := rfl /-- An `add_monoid_hom` preserves multiplication if pre- and post- composition with `add_monoid_hom.mul` are equivalent. By converting the statement into an equality of `add_monoid_hom`s, this lemma allows various specialized `ext` lemmas about `→+` to then be applied. -/ lemma add_monoid_hom.map_mul_iff (f : R →+ S) : (∀ x y, f (x * y) = f x * f y) ↔ (add_monoid_hom.mul : R →+ R →+ R).compr₂ f = (add_monoid_hom.mul.comp f).compl₂ f := iff.symm add_monoid_hom.ext_iff₂ end semiring
817f0f72719b9efee6837e7ee0606044ec5e1bcd
4950bf76e5ae40ba9f8491647d0b6f228ddce173
/src/data/equiv/ring.lean
c8bd07e14a45add3e6d7bd46a1c53b71f444dc13
[ "Apache-2.0" ]
permissive
ntzwq/mathlib
ca50b21079b0a7c6781c34b62199a396dd00cee2
36eec1a98f22df82eaccd354a758ef8576af2a7f
refs/heads/master
1,675,193,391,478
1,607,822,996,000
1,607,822,996,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
11,441
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.mul_add import algebra.field import algebra.opposites /-! # (Semi)ring equivs In this file we define extension of `equiv` called `ring_equiv`, which is a datatype representing an isomorphism of `semiring`s, `ring`s, `division_ring`s, or `field`s. We also introduce the corresponding group of automorphisms `ring_aut`. ## Notations The extended equiv have coercions to functions, and the coercion is the canonical notation when treating the isomorphism as maps. ## Implementation notes The fields for `ring_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, ring_equiv, mul_aut, add_aut, ring_aut -/ variables {R : Type*} {S : Type*} {S' : Type*} set_option old_structure_cmd true /-- An equivalence between two (semi)rings that preserves the algebraic structure. -/ structure ring_equiv (R S : Type*) [has_mul R] [has_add R] [has_mul S] [has_add S] extends R ≃ S, R ≃* S, R ≃+ S infix ` ≃+* `:25 := ring_equiv /-- The "plain" equivalence of types underlying an equivalence of (semi)rings. -/ add_decl_doc ring_equiv.to_equiv /-- The equivalence of additive monoids underlying an equivalence of (semi)rings. -/ add_decl_doc ring_equiv.to_add_equiv /-- The equivalence of multiplicative monoids underlying an equivalence of (semi)rings. -/ add_decl_doc ring_equiv.to_mul_equiv namespace ring_equiv section basic variables [has_mul R] [has_add R] [has_mul S] [has_add S] [has_mul S'] [has_add S'] instance : has_coe_to_fun (R ≃+* S) := ⟨_, ring_equiv.to_fun⟩ @[simp] lemma to_fun_eq_coe_fun (f : R ≃+* S) : f.to_fun = f := rfl /-- A ring isomorphism preserves multiplication. -/ @[simp] lemma map_mul (e : R ≃+* S) (x y : R) : e (x * y) = e x * e y := e.map_mul' x y /-- A ring isomorphism preserves addition. -/ @[simp] lemma map_add (e : R ≃+* S) (x y : R) : e (x + y) = e x + e y := e.map_add' x y /-- Two ring isomorphisms agree if they are defined by the same underlying function. -/ @[ext] lemma ext {f g : R ≃+* S} (h : ∀ x, f x = g x) : f = g := begin have h₁ : f.to_equiv = g.to_equiv := equiv.ext h, cases f, cases g, congr, { exact (funext h) }, { exact congr_arg equiv.inv_fun h₁ } end instance has_coe_to_mul_equiv : has_coe (R ≃+* S) (R ≃* S) := ⟨ring_equiv.to_mul_equiv⟩ instance has_coe_to_add_equiv : has_coe (R ≃+* S) (R ≃+ S) := ⟨ring_equiv.to_add_equiv⟩ @[norm_cast] lemma coe_mul_equiv (f : R ≃+* S) (a : R) : (f : R ≃* S) a = f a := rfl @[norm_cast] lemma coe_add_equiv (f : R ≃+* S) (a : R) : (f : R ≃+ S) a = f a := rfl variable (R) /-- The identity map is a ring isomorphism. -/ @[refl] protected def refl : R ≃+* R := { .. mul_equiv.refl R, .. add_equiv.refl R } @[simp] lemma refl_apply (x : R) : ring_equiv.refl R x = x := rfl @[simp] lemma coe_add_equiv_refl : (ring_equiv.refl R : R ≃+ R) = add_equiv.refl R := rfl @[simp] lemma coe_mul_equiv_refl : (ring_equiv.refl R : R ≃* R) = mul_equiv.refl R := rfl instance : inhabited (R ≃+* R) := ⟨ring_equiv.refl R⟩ variables {R} /-- The inverse of a ring isomorphism is a ring isomorphism. -/ @[symm] protected def symm (e : R ≃+* S) : S ≃+* R := { .. e.to_mul_equiv.symm, .. e.to_add_equiv.symm } /-- See Note [custom simps projection] -/ def simps.inv_fun (e : R ≃+* S) : S → R := e.symm initialize_simps_projections ring_equiv (to_fun → apply, inv_fun → symm_apply) @[simp] lemma symm_symm (e : R ≃+* S) : e.symm.symm = e := ext $ λ x, rfl @[simp] lemma coe_symm_mk (f : R → S) (g h₁ h₂ h₃ h₄) : ⇑(mk f g h₁ h₂ h₃ h₄).symm = g := rfl /-- Transitivity of `ring_equiv`. -/ @[trans] protected def trans (e₁ : R ≃+* S) (e₂ : S ≃+* S') : R ≃+* S' := { .. (e₁.to_mul_equiv.trans e₂.to_mul_equiv), .. (e₁.to_add_equiv.trans e₂.to_add_equiv) } @[simp] lemma trans_apply {A B C : Type*} [semiring A] [semiring B] [semiring C] (e : A ≃+* B) (f : B ≃+* C) (a : A) : e.trans f a = f (e a) := rfl protected lemma bijective (e : R ≃+* S) : function.bijective e := e.to_equiv.bijective protected lemma injective (e : R ≃+* S) : function.injective e := e.to_equiv.injective protected lemma surjective (e : R ≃+* S) : function.surjective e := e.to_equiv.surjective @[simp] lemma apply_symm_apply (e : R ≃+* S) : ∀ x, e (e.symm x) = x := e.to_equiv.apply_symm_apply @[simp] lemma symm_apply_apply (e : R ≃+* S) : ∀ x, e.symm (e x) = x := e.to_equiv.symm_apply_apply lemma image_eq_preimage (e : R ≃+* S) (s : set R) : e '' s = e.symm ⁻¹' s := e.to_equiv.image_eq_preimage s end basic section comm_semiring open opposite variables (R) [comm_semiring R] /-- A commutative ring is isomorphic to its opposite. -/ def to_opposite : R ≃+* Rᵒᵖ := { map_add' := λ x y, rfl, map_mul' := λ x y, mul_comm (op y) (op x), ..equiv_to_opposite } @[simp] lemma to_opposite_apply (r : R) : to_opposite R r = op r := rfl @[simp] lemma to_opposite_symm_apply (r : Rᵒᵖ) : (to_opposite R).symm r = unop r := rfl end comm_semiring section semiring variables [semiring R] [semiring S] (f : R ≃+* S) (x y : R) /-- A ring isomorphism sends one to one. -/ @[simp] lemma map_one : f 1 = 1 := (f : R ≃* S).map_one /-- A ring isomorphism sends zero to zero. -/ @[simp] lemma map_zero : f 0 = 0 := (f : R ≃+ S).map_zero variable {x} @[simp] lemma map_eq_one_iff : f x = 1 ↔ x = 1 := (f : R ≃* S).map_eq_one_iff @[simp] lemma map_eq_zero_iff : f x = 0 ↔ x = 0 := (f : R ≃+ S).map_eq_zero_iff lemma map_ne_one_iff : f x ≠ 1 ↔ x ≠ 1 := (f : R ≃* S).map_ne_one_iff lemma map_ne_zero_iff : f x ≠ 0 ↔ x ≠ 0 := (f : R ≃+ S).map_ne_zero_iff /-- Produce a ring isomorphism from a bijective ring homomorphism. -/ noncomputable def of_bijective (f : R →+* S) (hf : function.bijective f) : R ≃+* S := { .. equiv.of_bijective f hf, .. f } end semiring section variables [ring R] [ring S] (f : R ≃+* S) (x y : R) @[simp] lemma map_neg : f (-x) = -f x := (f : R ≃+ S).map_neg x @[simp] lemma map_sub : f (x - y) = f x - f y := (f : R ≃+ S).map_sub x y @[simp] lemma map_neg_one : f (-1) = -1 := f.map_one ▸ f.map_neg 1 end section semiring_hom variables [semiring R] [semiring S] [semiring S'] /-- Reinterpret a ring equivalence as a ring homomorphism. -/ def to_ring_hom (e : R ≃+* S) : R →+* S := { .. e.to_mul_equiv.to_monoid_hom, .. e.to_add_equiv.to_add_monoid_hom } lemma to_ring_hom_injective : function.injective (to_ring_hom : (R ≃+* S) → R →+* S) := λ f g h, ring_equiv.ext (ring_hom.ext_iff.1 h) instance has_coe_to_ring_hom : has_coe (R ≃+* S) (R →+* S) := ⟨ring_equiv.to_ring_hom⟩ @[norm_cast] lemma coe_ring_hom (f : R ≃+* S) (a : R) : (f : R →+* S) a = f a := rfl lemma coe_ring_hom_inj_iff {R S : Type*} [semiring R] [semiring S] (f g : R ≃+* S) : f = g ↔ (f : R →+* S) = g := ⟨congr_arg _, λ h, ext $ ring_hom.ext_iff.mp h⟩ /-- Reinterpret a ring equivalence as a monoid homomorphism. -/ abbreviation to_monoid_hom (e : R ≃+* S) : R →* S := e.to_ring_hom.to_monoid_hom /-- Reinterpret a ring equivalence as an `add_monoid` homomorphism. -/ abbreviation to_add_monoid_hom (e : R ≃+* S) : R →+ S := e.to_ring_hom.to_add_monoid_hom @[simp] lemma to_ring_hom_refl : (ring_equiv.refl R).to_ring_hom = ring_hom.id R := rfl @[simp] lemma to_monoid_hom_refl : (ring_equiv.refl R).to_monoid_hom = monoid_hom.id R := rfl @[simp] lemma to_add_monoid_hom_refl : (ring_equiv.refl R).to_add_monoid_hom = add_monoid_hom.id R := rfl @[simp] lemma to_ring_hom_apply_symm_to_ring_hom_apply (e : R ≃+* S) : ∀ (y : S), e.to_ring_hom (e.symm.to_ring_hom y) = y := e.to_equiv.apply_symm_apply @[simp] lemma symm_to_ring_hom_apply_to_ring_hom_apply (e : R ≃+* S) : ∀ (x : R), e.symm.to_ring_hom (e.to_ring_hom x) = x := equiv.symm_apply_apply (e.to_equiv) @[simp] lemma to_ring_hom_trans (e₁ : R ≃+* S) (e₂ : S ≃+* S') : (e₁.trans e₂).to_ring_hom = e₂.to_ring_hom.comp e₁.to_ring_hom := rfl /-- Construct an equivalence of rings from homomorphisms in both directions, which are inverses. -/ def of_hom_inv (hom : R →+* S) (inv : S →+* R) (hom_inv_id : inv.comp hom = ring_hom.id R) (inv_hom_id : hom.comp inv = ring_hom.id S) : R ≃+* S := { inv_fun := inv, left_inv := λ x, ring_hom.congr_fun hom_inv_id x, right_inv := λ x, ring_hom.congr_fun inv_hom_id x, ..hom } @[simp] lemma of_hom_inv_apply (hom : R →+* S) (inv : S →+* R) (hom_inv_id inv_hom_id) (r : R) : (of_hom_inv hom inv hom_inv_id inv_hom_id) r = hom r := rfl @[simp] lemma of_hom_inv_symm_apply (hom : R →+* S) (inv : S →+* R) (hom_inv_id inv_hom_id) (s : S) : (of_hom_inv hom inv hom_inv_id inv_hom_id).symm s = inv s := rfl end semiring_hom end ring_equiv namespace mul_equiv /-- Gives a `ring_equiv` from a `mul_equiv` preserving addition.-/ def to_ring_equiv {R : Type*} {S : Type*} [has_add R] [has_add S] [has_mul R] [has_mul S] (h : R ≃* S) (H : ∀ x y : R, h (x + y) = h x + h y) : R ≃+* S := {..h.to_equiv, ..h, ..add_equiv.mk' h.to_equiv H } end mul_equiv namespace ring_equiv variables [has_add R] [has_add S] [has_mul R] [has_mul S] @[simp] theorem trans_symm (e : R ≃+* S) : e.trans e.symm = ring_equiv.refl R := ext e.3 @[simp] theorem symm_trans (e : R ≃+* S) : e.symm.trans e = ring_equiv.refl S := ext e.4 /-- If two rings are isomorphic, and the second is an integral domain, then so is the first. -/ protected lemma is_integral_domain {A : Type*} (B : Type*) [ring A] [ring B] (hB : is_integral_domain B) (e : A ≃+* B) : is_integral_domain A := { mul_comm := λ x y, have e.symm (e x * e y) = e.symm (e y * e x), by rw hB.mul_comm, by simpa, eq_zero_or_eq_zero_of_mul_eq_zero := λ x y hxy, have e x * e y = 0, by rw [← e.map_mul, hxy, e.map_zero], (hB.eq_zero_or_eq_zero_of_mul_eq_zero _ _ this).imp (λ hx, by simpa using congr_arg e.symm hx) (λ hy, by simpa using congr_arg e.symm hy), exists_pair_ne := ⟨e.symm 0, e.symm 1, by { haveI : nontrivial B := hB.to_nontrivial, exact e.symm.injective.ne zero_ne_one }⟩ } /-- If two rings are isomorphic, and the second is an integral domain, then so is the first. -/ protected def integral_domain {A : Type*} (B : Type*) [ring A] [integral_domain B] (e : A ≃+* B) : integral_domain A := { .. (‹_› : ring A), .. e.is_integral_domain B (integral_domain.to_is_integral_domain B) } end ring_equiv namespace equiv variables (K : Type*) [division_ring K] /-- In a division ring `K`, the unit group `units K` is equivalent to the subtype of nonzero elements. -/ -- TODO: this might already exist elsewhere for `group_with_zero` -- deduplicate or generalize def units_equiv_ne_zero : units K ≃ {a : K | a ≠ 0} := ⟨λ a, ⟨a.1, a.ne_zero⟩, λ a, units.mk0 _ a.2, λ ⟨_, _, _, _⟩, units.ext rfl, λ ⟨_, _⟩, rfl⟩ variable {K} @[simp] lemma coe_units_equiv_ne_zero (a : units K) : ((units_equiv_ne_zero K a) : K) = a := rfl end equiv
657f1510fc255ff0bc3b88a237f4e143804ad481
26ac254ecb57ffcb886ff709cf018390161a9225
/src/algebra/group/with_one.lean
ca4a08c3dd25a2fda46f122174dd343a554385c6
[ "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
7,980
lean
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Johan Commelin -/ import algebra.ring universes u v variable {α : Type u} @[to_additive] def with_one (α) := option α namespace with_one @[to_additive] instance : monad with_one := option.monad @[to_additive] instance : has_one (with_one α) := ⟨none⟩ @[to_additive] instance : inhabited (with_one α) := ⟨1⟩ @[to_additive] instance [nonempty α] : nontrivial (with_one α) := option.nontrivial @[to_additive] instance : has_coe_t α (with_one α) := ⟨some⟩ @[simp, to_additive] lemma one_ne_coe {a : α} : (1 : with_one α) ≠ a := λ h, option.no_confusion h @[simp, to_additive] lemma coe_ne_one {a : α} : (a : with_one α) ≠ (1 : with_one α) := λ h, option.no_confusion h @[to_additive] lemma ne_one_iff_exists : ∀ {x : with_one α}, x ≠ 1 ↔ ∃ (a : α), x = a | 1 := ⟨λ h, false.elim $ h rfl, by { rintros ⟨a,ha⟩ h, simpa using h }⟩ | (a : α) := ⟨λ h, ⟨a, rfl⟩, λ h, with_one.coe_ne_one⟩ @[to_additive] lemma coe_inj {a b : α} : (a : with_one α) = b ↔ a = b := option.some_inj @[elab_as_eliminator, to_additive] protected lemma cases_on {P : with_one α → Prop} : ∀ (x : with_one α), P 1 → (∀ a : α, P a) → P x := option.cases_on @[to_additive] instance [has_mul α] : has_mul (with_one α) := { mul := option.lift_or_get (*) } @[simp, to_additive] lemma mul_coe [has_mul α] (a b : α) : (a : with_one α) * b = (a * b : α) := rfl @[to_additive add_monoid] instance [semigroup α] : monoid (with_one α) := { mul_assoc := (option.lift_or_get_assoc _).1, one_mul := (option.lift_or_get_is_left_id _).1, mul_one := (option.lift_or_get_is_right_id _).1, ..with_one.has_one, ..with_one.has_mul } @[to_additive add_comm_monoid] instance [comm_semigroup α] : comm_monoid (with_one α) := { mul_comm := (option.lift_or_get_comm _).1, ..with_one.monoid } section lift variables [semigroup α] {β : Type v} [monoid β] /-- Lift a semigroup homomorphism `f` to a bundled monoid homorphism. We have no bundled semigroup homomorphisms, so this function takes `∀ x y, f (x * y) = f x * f y` as an explicit argument. -/ @[to_additive] def lift (f : α → β) (hf : ∀ x y, f (x * y) = f x * f y) : (with_one α) →* β := { to_fun := λ x, option.cases_on x 1 f, map_one' := rfl, map_mul' := λ x y, with_one.cases_on x (by { rw one_mul, exact (one_mul _).symm }) $ λ x, with_one.cases_on y (by { rw mul_one, exact (mul_one _).symm }) $ λ y, hf x y } variables (f : α → β) (hf : ∀ x y, f (x * y) = f x * f y) @[simp, to_additive] lemma lift_coe (x : α) : lift f hf x = f x := rfl @[simp, to_additive] lemma lift_one : lift f hf 1 = 1 := rfl @[to_additive] theorem lift_unique (f : with_one α →* β) : f = lift (f ∘ coe) (λ x y, f.map_mul x y) := monoid_hom.ext $ λ x, with_one.cases_on x f.map_one $ λ x, rfl end lift section map variables {β : Type v} [semigroup α] [semigroup β] @[to_additive] def map (f : α → β) (hf : ∀ x y, f (x * y) = f x * f y) : with_one α →* with_one β := lift (coe ∘ f) (λ x y, coe_inj.2 $ hf x y) end map end with_one namespace with_zero instance [one : has_one α] : has_one (with_zero α) := { ..one } lemma coe_one [has_one α] : ((1 : α) : with_zero α) = 1 := rfl instance [has_mul α] : mul_zero_class (with_zero α) := { mul := λ o₁ o₂, o₁.bind (λ a, option.map (λ b, a * b) o₂), zero_mul := λ a, rfl, mul_zero := λ a, by cases a; refl, ..with_zero.has_zero } @[simp] lemma mul_coe [has_mul α] (a b : α) : (a : with_zero α) * b = (a * b : α) := rfl instance [semigroup α] : semigroup (with_zero α) := { mul_assoc := λ a b c, match a, b, c with | none, _, _ := rfl | some a, none, _ := rfl | some a, some b, none := rfl | some a, some b, some c := congr_arg some (mul_assoc _ _ _) end, ..with_zero.mul_zero_class } instance [comm_semigroup α] : comm_semigroup (with_zero α) := { mul_comm := λ a b, match a, b with | none, _ := (mul_zero _).symm | some a, none := rfl | some a, some b := congr_arg some (mul_comm _ _) end, ..with_zero.semigroup } instance [monoid α] : monoid_with_zero (with_zero α) := { one_mul := λ a, match a with | none := rfl | some a := congr_arg some $ one_mul _ end, mul_one := λ a, match a with | none := rfl | some a := congr_arg some $ mul_one _ end, ..with_zero.mul_zero_class, ..with_zero.has_one, ..with_zero.semigroup } instance [comm_monoid α] : comm_monoid_with_zero (with_zero α) := { ..with_zero.monoid_with_zero, ..with_zero.comm_semigroup } definition inv [has_inv α] (x : with_zero α) : with_zero α := do a ← x, return a⁻¹ instance [has_inv α] : has_inv (with_zero α) := ⟨with_zero.inv⟩ @[simp] lemma inv_coe [has_inv α] (a : α) : (a : with_zero α)⁻¹ = (a⁻¹ : α) := rfl @[simp] lemma inv_zero [has_inv α] : (0 : with_zero α)⁻¹ = 0 := rfl section group variables [group α] @[simp] lemma inv_one : (1 : with_zero α)⁻¹ = 1 := show ((1⁻¹ : α) : with_zero α) = 1, by simp [coe_one] definition div (x y : with_zero α) : with_zero α := x * y⁻¹ instance : has_div (with_zero α) := ⟨with_zero.div⟩ @[simp] lemma zero_div (a : with_zero α) : 0 / a = 0 := rfl @[simp] lemma div_zero (a : with_zero α) : a / 0 = 0 := by change a * _ = _; simp lemma div_coe (a b : α) : (a : with_zero α) / b = (a * b⁻¹ : α) := rfl lemma one_div (x : with_zero α) : 1 / x = x⁻¹ := one_mul _ @[simp] lemma div_one : ∀ (x : with_zero α), x / 1 = x | 0 := rfl | (a : α) := show _ * _ = _, by simp @[simp] lemma mul_right_inv : ∀ (x : with_zero α) (h : x ≠ 0), x * x⁻¹ = 1 | 0 h := false.elim $ h rfl | (a : α) h := by simp [coe_one] @[simp] lemma mul_left_inv : ∀ (x : with_zero α) (h : x ≠ 0), x⁻¹ * x = 1 | 0 h := false.elim $ h rfl | (a : α) h := by simp [coe_one] @[simp] lemma mul_inv_rev : ∀ (x y : with_zero α), (x * y)⁻¹ = y⁻¹ * x⁻¹ | 0 0 := rfl | 0 (b : α) := rfl | (a : α) 0 := rfl | (a : α) (b : α) := by simp @[simp] lemma mul_div_cancel {a b : with_zero α} (hb : b ≠ 0) : a * b / b = a := show _ * _ * _ = _, by simp [mul_assoc, hb] @[simp] lemma div_mul_cancel {a b : with_zero α} (hb : b ≠ 0) : a / b * b = a := show _ * _ * _ = _, by simp [mul_assoc, hb] lemma div_eq_iff_mul_eq {a b c : with_zero α} (hb : b ≠ 0) : a / b = c ↔ c * b = a := by split; intro h; simp [h.symm, hb] end group section comm_group variables [comm_group α] {a b c d : with_zero α} lemma div_eq_div (hb : b ≠ 0) (hd : d ≠ 0) : a / b = c / d ↔ a * d = b * c := begin rw ne_zero_iff_exists at hb hd, rcases hb with ⟨b, rfl⟩, rcases hd with ⟨d, rfl⟩, induction a using with_zero.cases_on; induction c using with_zero.cases_on, { refl }, { simp [div_coe] }, { simp [div_coe] }, erw [with_zero.coe_inj, with_zero.coe_inj], show a * b⁻¹ = c * d⁻¹ ↔ a * d = b * c, split; intro H, { rw mul_inv_eq_iff_eq_mul at H, rw [H, mul_right_comm, inv_mul_cancel_right, mul_comm] }, { rw [mul_inv_eq_iff_eq_mul, mul_right_comm, mul_comm c, ← H, mul_inv_cancel_right] } end end comm_group section semiring instance [semiring α] : semiring (with_zero α) := { left_distrib := λ a b c, begin cases a with a, {refl}, cases b with b; cases c with c; try {refl}, exact congr_arg some (left_distrib _ _ _) end, right_distrib := λ a b c, begin cases c with c, { change (a + b) * 0 = a * 0 + b * 0, simp }, cases a with a; cases b with b; try {refl}, exact congr_arg some (right_distrib _ _ _) end, ..with_zero.add_comm_monoid, ..with_zero.mul_zero_class, ..with_zero.monoid_with_zero } end semiring end with_zero
34093976945c989fed74ae74cae8badb018ba1cd
6432ea7a083ff6ba21ea17af9ee47b9c371760f7
/tests/lean/run/expectedTypePropagation.lean
1616b6be65f475f2c8630b47d37215fb824edd33
[ "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
305
lean
instance : Coe Nat Int := ⟨fun n => Int.ofNat n⟩ def f (x : Nat) : List Int := [x] def g1 (x : Nat) : List Int := [x, x] def g2 (n : Nat) (i : Int) : Int := 0 + n + i def g3 (n : Nat) (i : Int) : Int := let x : Int := n+i; x + x def g4 (n : Nat) (i : Int) : Int := let f := fun x => x + i; f n
0bc973da58b30fb430e73fed1e12262ecf3e227f
6432ea7a083ff6ba21ea17af9ee47b9c371760f7
/tests/lean/run/resolveLVal.lean
78f89c27635ad3e7ce9c9bf27f4d13561c9e1165
[ "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
269
lean
namespace Foo structure A := (x : Nat) def A.doubleX (a : A) := 2 * a.x structure B extends A := (y : Nat) def f (b : B) : Nat := b.x + b.doubleX theorem ex1 : { x := 10, y := 0 : B }.doubleX = 20 := rfl theorem ex2 : f { x := 10, y := 0 } = 30 := rfl end Foo
b23c6f7e6e5e37ce4ae59fd26e6c4c074a7a9f60
94e33a31faa76775069b071adea97e86e218a8ee
/src/analysis/inner_product_space/rayleigh.lean
4ef2624b746dae6b9577583ac0a661eba432d222
[ "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
12,774
lean
/- Copyright (c) 2021 Heather Macbeth. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Heather Macbeth, Frédéric Dupuis -/ import analysis.inner_product_space.calculus import analysis.inner_product_space.dual import analysis.inner_product_space.adjoint import analysis.calculus.lagrange_multipliers import linear_algebra.eigenspace /-! # The Rayleigh quotient The Rayleigh quotient of a self-adjoint operator `T` on an inner product space `E` is the function `λ x, ⟪T x, x⟫ / ∥x∥ ^ 2`. The main results of this file are `is_self_adjoint.has_eigenvector_of_is_max_on` and `is_self_adjoint.has_eigenvector_of_is_min_on`, which state that if `E` is complete, and if the Rayleigh quotient attains its global maximum/minimum over some sphere at the point `x₀`, then `x₀` is an eigenvector of `T`, and the `supr`/`infi` of `λ x, ⟪T x, x⟫ / ∥x∥ ^ 2` is the corresponding eigenvalue. The corollaries `is_self_adjoint.has_eigenvalue_supr_of_finite_dimensional` and `is_self_adjoint.has_eigenvalue_supr_of_finite_dimensional` state that if `E` is finite-dimensional and nontrivial, then `T` has some (nonzero) eigenvectors with eigenvalue the `supr`/`infi` of `λ x, ⟪T x, x⟫ / ∥x∥ ^ 2`. ## TODO A slightly more elaborate corollary is that if `E` is complete and `T` is a compact operator, then `T` has some (nonzero) eigenvector with eigenvalue either `⨆ x, ⟪T x, x⟫ / ∥x∥ ^ 2` or `⨅ x, ⟪T x, x⟫ / ∥x∥ ^ 2` (not necessarily both). -/ variables {𝕜 : Type*} [is_R_or_C 𝕜] variables {E : Type*} [inner_product_space 𝕜 E] local notation `⟪`x`, `y`⟫` := @inner 𝕜 _ _ x y open_locale nnreal open module.End metric namespace continuous_linear_map variables (T : E →L[𝕜] E) local notation `rayleigh_quotient` := λ x : E, T.re_apply_inner_self x / ∥(x:E)∥ ^ 2 lemma rayleigh_smul (x : E) {c : 𝕜} (hc : c ≠ 0) : rayleigh_quotient (c • x) = rayleigh_quotient x := begin by_cases hx : x = 0, { simp [hx] }, have : ∥c∥ ≠ 0 := by simp [hc], have : ∥x∥ ≠ 0 := by simp [hx], field_simp [norm_smul, T.re_apply_inner_self_smul], ring end lemma image_rayleigh_eq_image_rayleigh_sphere {r : ℝ} (hr : 0 < r) : rayleigh_quotient '' {0}ᶜ = rayleigh_quotient '' (sphere 0 r) := begin ext a, split, { rintros ⟨x, (hx : x ≠ 0), hxT⟩, have : ∥x∥ ≠ 0 := by simp [hx], let c : 𝕜 := ↑∥x∥⁻¹ * r, have : c ≠ 0 := by simp [c, hx, hr.ne'], refine ⟨c • x, _, _⟩, { field_simp [norm_smul, is_R_or_C.norm_eq_abs, abs_of_nonneg hr.le] }, { rw T.rayleigh_smul x this, exact hxT } }, { rintros ⟨x, hx, hxT⟩, exact ⟨x, ne_zero_of_mem_sphere hr.ne' ⟨x, hx⟩, hxT⟩ }, end lemma supr_rayleigh_eq_supr_rayleigh_sphere {r : ℝ} (hr : 0 < r) : (⨆ x : {x : E // x ≠ 0}, rayleigh_quotient x) = ⨆ x : sphere (0:E) r, rayleigh_quotient x := show (⨆ x : ({0} : set E)ᶜ, rayleigh_quotient x) = _, by simp only [@csupr_set _ _ _ _ rayleigh_quotient, T.image_rayleigh_eq_image_rayleigh_sphere hr] lemma infi_rayleigh_eq_infi_rayleigh_sphere {r : ℝ} (hr : 0 < r) : (⨅ x : {x : E // x ≠ 0}, rayleigh_quotient x) = ⨅ x : sphere (0:E) r, rayleigh_quotient x := show (⨅ x : ({0} : set E)ᶜ, rayleigh_quotient x) = _, by simp only [@cinfi_set _ _ _ _ rayleigh_quotient, T.image_rayleigh_eq_image_rayleigh_sphere hr] end continuous_linear_map namespace inner_product_space namespace is_self_adjoint section real variables {F : Type*} [inner_product_space ℝ F] lemma has_strict_fderiv_at_re_apply_inner_self {T : F →L[ℝ] F} (hT : is_self_adjoint (T : F →ₗ[ℝ] F)) (x₀ : F) : has_strict_fderiv_at T.re_apply_inner_self (bit0 (innerSL (T x₀))) x₀ := begin convert T.has_strict_fderiv_at.inner (has_strict_fderiv_at_id x₀), ext y, simp [bit0, hT.apply_clm x₀ y, real_inner_comm x₀] end variables [complete_space F] {T : F →L[ℝ] F} local notation `rayleigh_quotient` := λ x : F, T.re_apply_inner_self x / ∥(x:F)∥ ^ 2 lemma linearly_dependent_of_is_local_extr_on (hT : is_self_adjoint (T : F →ₗ[ℝ] F)) {x₀ : F} (hextr : is_local_extr_on T.re_apply_inner_self (sphere (0:F) ∥x₀∥) x₀) : ∃ a b : ℝ, (a, b) ≠ 0 ∧ a • x₀ + b • T x₀ = 0 := begin have H : is_local_extr_on T.re_apply_inner_self {x : F | ∥x∥ ^ 2 = ∥x₀∥ ^ 2} x₀, { convert hextr, ext x, simp [dist_eq_norm] }, -- find Lagrange multipliers for the function `T.re_apply_inner_self` and the -- hypersurface-defining function `λ x, ∥x∥ ^ 2` obtain ⟨a, b, h₁, h₂⟩ := is_local_extr_on.exists_multipliers_of_has_strict_fderiv_at_1d H (has_strict_fderiv_at_norm_sq x₀) (hT.has_strict_fderiv_at_re_apply_inner_self x₀), refine ⟨a, b, h₁, _⟩, apply (inner_product_space.to_dual_map ℝ F).injective, simp only [linear_isometry.map_add, linear_isometry.map_smul, linear_isometry.map_zero], change a • innerSL x₀ + b • innerSL (T x₀) = 0, apply smul_right_injective (F →L[ℝ] ℝ) (two_ne_zero : (2:ℝ) ≠ 0), simpa only [bit0, add_smul, smul_add, one_smul, add_zero] using h₂ end lemma eq_smul_self_of_is_local_extr_on_real (hT : is_self_adjoint (T : F →ₗ[ℝ] F)) {x₀ : F} (hextr : is_local_extr_on T.re_apply_inner_self (sphere (0:F) ∥x₀∥) x₀) : T x₀ = (rayleigh_quotient x₀) • x₀ := begin obtain ⟨a, b, h₁, h₂⟩ := hT.linearly_dependent_of_is_local_extr_on hextr, by_cases hx₀ : x₀ = 0, { simp [hx₀] }, by_cases hb : b = 0, { have : a ≠ 0 := by simpa [hb] using h₁, refine absurd _ hx₀, apply smul_right_injective F this, simpa [hb] using h₂ }, let c : ℝ := - b⁻¹ * a, have hc : T x₀ = c • x₀, { have : b * (b⁻¹ * a) = a := by field_simp [mul_comm], apply smul_right_injective F hb, simp [c, eq_neg_of_add_eq_zero_left h₂, ← mul_smul, this] }, convert hc, have : ∥x₀∥ ≠ 0 := by simp [hx₀], field_simp, simpa [inner_smul_left, real_inner_self_eq_norm_mul_norm, sq] using congr_arg (λ x, ⟪x, x₀⟫_ℝ) hc, end end real section complete_space variables [complete_space E] {T : E →L[𝕜] E} local notation `rayleigh_quotient` := λ x : E, T.re_apply_inner_self x / ∥(x:E)∥ ^ 2 lemma eq_smul_self_of_is_local_extr_on (hT : is_self_adjoint (T : E →ₗ[𝕜] E)) {x₀ : E} (hextr : is_local_extr_on T.re_apply_inner_self (sphere (0:E) ∥x₀∥) x₀) : T x₀ = (↑(rayleigh_quotient x₀) : 𝕜) • x₀ := begin letI := inner_product_space.is_R_or_C_to_real 𝕜 E, let S : E →L[ℝ] E := @continuous_linear_map.restrict_scalars 𝕜 E E _ _ _ _ _ _ _ ℝ _ _ _ _ T, have hSA : is_self_adjoint (S : E →ₗ[ℝ] E) := λ x y, by { have := hT x y, simp only [continuous_linear_map.coe_coe] at this, simp only [real_inner_eq_re_inner, this, continuous_linear_map.coe_restrict_scalars, continuous_linear_map.coe_coe, linear_map.coe_restrict_scalars_eq_coe] }, exact eq_smul_self_of_is_local_extr_on_real hSA hextr, end /-- For a self-adjoint operator `T`, a local extremum of the Rayleigh quotient of `T` on a sphere centred at the origin is an eigenvector of `T`. -/ lemma has_eigenvector_of_is_local_extr_on (hT : is_self_adjoint (T : E →ₗ[𝕜] E)) {x₀ : E} (hx₀ : x₀ ≠ 0) (hextr : is_local_extr_on T.re_apply_inner_self (sphere (0:E) ∥x₀∥) x₀) : has_eigenvector (T : E →ₗ[𝕜] E) ↑(rayleigh_quotient x₀) x₀ := begin refine ⟨_, hx₀⟩, rw module.End.mem_eigenspace_iff, exact hT.eq_smul_self_of_is_local_extr_on hextr end /-- For a self-adjoint operator `T`, a maximum of the Rayleigh quotient of `T` on a sphere centred at the origin is an eigenvector of `T`, with eigenvalue the global supremum of the Rayleigh quotient. -/ lemma has_eigenvector_of_is_max_on (hT : is_self_adjoint (T : E →ₗ[𝕜] E)) {x₀ : E} (hx₀ : x₀ ≠ 0) (hextr : is_max_on T.re_apply_inner_self (sphere (0:E) ∥x₀∥) x₀) : has_eigenvector (T : E →ₗ[𝕜] E) ↑(⨆ x : {x : E // x ≠ 0}, rayleigh_quotient x) x₀ := begin convert hT.has_eigenvector_of_is_local_extr_on hx₀ (or.inr hextr.localize), have hx₀' : 0 < ∥x₀∥ := by simp [hx₀], have hx₀'' : x₀ ∈ sphere (0:E) (∥x₀∥) := by simp, rw T.supr_rayleigh_eq_supr_rayleigh_sphere hx₀', refine is_max_on.supr_eq hx₀'' _, intros x hx, dsimp, have : ∥x∥ = ∥x₀∥ := by simpa using hx, rw this, exact div_le_div_of_le (sq_nonneg ∥x₀∥) (hextr hx) end /-- For a self-adjoint operator `T`, a minimum of the Rayleigh quotient of `T` on a sphere centred at the origin is an eigenvector of `T`, with eigenvalue the global infimum of the Rayleigh quotient. -/ lemma has_eigenvector_of_is_min_on (hT : is_self_adjoint (T : E →ₗ[𝕜] E)) {x₀ : E} (hx₀ : x₀ ≠ 0) (hextr : is_min_on T.re_apply_inner_self (sphere (0:E) ∥x₀∥) x₀) : has_eigenvector (T : E →ₗ[𝕜] E) ↑(⨅ x : {x : E // x ≠ 0}, rayleigh_quotient x) x₀ := begin convert hT.has_eigenvector_of_is_local_extr_on hx₀ (or.inl hextr.localize), have hx₀' : 0 < ∥x₀∥ := by simp [hx₀], have hx₀'' : x₀ ∈ sphere (0:E) (∥x₀∥) := by simp, rw T.infi_rayleigh_eq_infi_rayleigh_sphere hx₀', refine is_min_on.infi_eq hx₀'' _, intros x hx, dsimp, have : ∥x∥ = ∥x₀∥ := by simpa using hx, rw this, exact div_le_div_of_le (sq_nonneg ∥x₀∥) (hextr hx) end end complete_space section finite_dimensional variables [finite_dimensional 𝕜 E] [_i : nontrivial E] {T : E →ₗ[𝕜] E} include _i /-- The supremum of the Rayleigh quotient of a self-adjoint operator `T` on a nontrivial finite-dimensional vector space is an eigenvalue for that operator. -/ lemma has_eigenvalue_supr_of_finite_dimensional (hT : is_self_adjoint T) : has_eigenvalue T ↑(⨆ x : {x : E // x ≠ 0}, is_R_or_C.re ⟪T x, x⟫ / ∥(x:E)∥ ^ 2) := begin haveI := finite_dimensional.proper_is_R_or_C 𝕜 E, let T' : E →L[𝕜] E := T.to_continuous_linear_map, have hT' : is_self_adjoint (T' : E →ₗ[𝕜] E) := hT, obtain ⟨x, hx⟩ : ∃ x : E, x ≠ 0 := exists_ne 0, have H₁ : is_compact (sphere (0:E) ∥x∥) := is_compact_sphere _ _, have H₂ : (sphere (0:E) ∥x∥).nonempty := ⟨x, by simp⟩, -- key point: in finite dimension, a continuous function on the sphere has a max obtain ⟨x₀, hx₀', hTx₀⟩ := H₁.exists_forall_ge H₂ T'.re_apply_inner_self_continuous.continuous_on, have hx₀ : ∥x₀∥ = ∥x∥ := by simpa using hx₀', have : is_max_on T'.re_apply_inner_self (sphere 0 ∥x₀∥) x₀, { simpa only [← hx₀] using hTx₀ }, have hx₀_ne : x₀ ≠ 0, { have : ∥x₀∥ ≠ 0 := by simp only [hx₀, norm_eq_zero, hx, ne.def, not_false_iff], simpa [← norm_eq_zero, ne.def] }, exact has_eigenvalue_of_has_eigenvector (hT'.has_eigenvector_of_is_max_on hx₀_ne this) end /-- The infimum of the Rayleigh quotient of a self-adjoint operator `T` on a nontrivial finite-dimensional vector space is an eigenvalue for that operator. -/ lemma has_eigenvalue_infi_of_finite_dimensional (hT : is_self_adjoint T) : has_eigenvalue T ↑(⨅ x : {x : E // x ≠ 0}, is_R_or_C.re ⟪T x, x⟫ / ∥(x:E)∥ ^ 2) := begin haveI := finite_dimensional.proper_is_R_or_C 𝕜 E, let T' : E →L[𝕜] E := T.to_continuous_linear_map, have hT' : is_self_adjoint (T' : E →ₗ[𝕜] E) := hT, obtain ⟨x, hx⟩ : ∃ x : E, x ≠ 0 := exists_ne 0, have H₁ : is_compact (sphere (0:E) ∥x∥) := is_compact_sphere _ _, have H₂ : (sphere (0:E) ∥x∥).nonempty := ⟨x, by simp⟩, -- key point: in finite dimension, a continuous function on the sphere has a min obtain ⟨x₀, hx₀', hTx₀⟩ := H₁.exists_forall_le H₂ T'.re_apply_inner_self_continuous.continuous_on, have hx₀ : ∥x₀∥ = ∥x∥ := by simpa using hx₀', have : is_min_on T'.re_apply_inner_self (sphere 0 ∥x₀∥) x₀, { simpa only [← hx₀] using hTx₀ }, have hx₀_ne : x₀ ≠ 0, { have : ∥x₀∥ ≠ 0 := by simp only [hx₀, norm_eq_zero, hx, ne.def, not_false_iff], simpa [← norm_eq_zero, ne.def] }, exact has_eigenvalue_of_has_eigenvector (hT'.has_eigenvector_of_is_min_on hx₀_ne this) end omit _i lemma subsingleton_of_no_eigenvalue_finite_dimensional (hT : is_self_adjoint T) (hT' : ∀ μ : 𝕜, module.End.eigenspace (T : E →ₗ[𝕜] E) μ = ⊥) : subsingleton E := (subsingleton_or_nontrivial E).resolve_right (λ h, by exactI absurd (hT' _) hT.has_eigenvalue_supr_of_finite_dimensional) end finite_dimensional end is_self_adjoint end inner_product_space
26586aff53105cf5944fc559d782063c1b87d072
ea5678cc400c34ff95b661fa26d15024e27ea8cd
/mertens.lean
97082df5c90dc31a298a5d85b3643fa3a045bfdb
[]
no_license
ChrisHughes24/leanstuff
dca0b5349c3ed893e8792ffbd98cbcadaff20411
9efa85f72efaccd1d540385952a6acc18fce8687
refs/heads/master
1,654,883,241,759
1,652,873,885,000
1,652,873,885,000
134,599,537
1
0
null
null
null
null
UTF-8
Lean
false
false
6,603
lean
import data.nat.basic data.complex.basic data.rea l.cau_seq .exponential.series local attribute [instance, priority 0] classical.prop_decidable noncomputable theory open nat is_absolute_value lemma series_series_diag {α : Type*} [add_comm_monoid α] (f : ℕ → ℕ → α) (n : ℕ) : series (λ i, series (λ k, f k (i - k)) i) n = series (λ i, series (λ k, f i k) (n - i)) n := begin have : ∀ m : ℕ, m ≤ n → series (λ (i : ℕ), series (λ k, f k (i - k)) (min m i)) n = series (λ i, series (λ k, f i k) (n - i)) m, assume m mn, induction m with m' hi, simp[series_succ,series_zero,mul_add,max_eq_left (zero_le n)], simp only [series_succ _ m'],rw ←hi (le_of_succ_le mn),clear hi, induction n with n' hi, simp[series_succ],exact absurd mn dec_trivial,cases n' with n₂, simp [series_succ],rw [min_eq_left mn,series_succ,min_eq_left (le_of_succ_le mn)], rw eq_zero_of_le_zero (le_of_succ_le_succ mn),simp, cases lt_or_eq_of_le mn, simp [series_succ _ (succ n₂),min_eq_left mn,hi (le_of_lt_succ h)],rw [←add_assoc,←add_assoc], suffices : series (f (succ m')) (n₂ - m') + series (λ (k : ℕ), f k (succ (succ n₂) - k)) (succ m') = series (f (succ m')) (succ n₂ - m') + series (λ (k : ℕ), f k (succ (succ n₂) - k)) (min m' (succ (succ n₂))), rw this,rw[min_eq_left (le_of_succ_le mn),series_succ,succ_sub_succ,succ_sub (le_of_succ_le_succ (le_of_lt_succ h)),series_succ], rw [add_comm (series (λ (k : ℕ), f k (succ (succ n₂) - k)) m'),add_assoc], rw ←h,simp[nat.sub_self],clear hi mn h,simp[series_succ,nat.sub_self], suffices : series (λ (i : ℕ), series (λ (k : ℕ), f k (i - k)) (min (succ m') i)) m' = series (λ (i : ℕ), series (λ (k : ℕ), f k (i - k)) (min m' i)) m', rw [this,min_eq_left (le_succ _)],clear n₂, have h₁ : ∀ i ≤ m', (λ (i : ℕ), series (λ (k : ℕ), f k (i - k)) (min (succ m') i)) i = (λ (i : ℕ), series (λ (k : ℕ), f k (i - k)) (min m' i)) i, assume i im,simp, rw [min_eq_right im,min_eq_right (le_succ_of_le im)], rw series_congr h₁, specialize this n (le_refl _), rw ←this,refine series_congr _,assume i ni,rw min_eq_right ni, end lemma series_merten {α β : Type*} [discrete_linear_ordered_field α] [ring β] {a b : ℕ → β} {abv : β → α} [is_absolute_value abv] : is_cau_seq abs (series (λ n, abv (a n))) → is_cau_seq abv (series b) → ∀ ε : α, 0 < ε → ∃ i : ℕ, ∀ j ≥ i, abv (series a j * series b j - series (λ n, series (λ m, a m * b (n - m)) n) j) < ε := begin assume ha hb ε ε0, cases seq_bounded_above_of_cau hb with Q hQ, cases seq_bounded_above_of_cau ha with P hP, have P0 : 0 < P,exact lt_of_le_of_lt (abs_nonneg _) (hP 0), have Pε0 := div_pos ε0 (mul_pos (show (2 : α) > 0, from by norm_num) P0), cases cau_seq.cauchy₂ ⟨_, hb⟩ Pε0 with N hN,simp at hN, have Qε0 := div_pos ε0 (mul_pos (show (4 : α) > 0, from by norm_num) (lt_of_le_of_lt (abv_nonneg _ _) (hQ 0))), cases cau_seq.cauchy₂ ⟨_, ha⟩ Qε0 with M hM,simp at hM, existsi 2 * (max N M + 1), assume K hK,have := diag_swap1 (λ m n, a m * b n) K,simp at this,rw this,clear this, have : (λ (i : ℕ), series (λ (k : ℕ), a i * b k) (K - i)) = (λ (i : ℕ), a i * series (λ (k : ℕ), b k) (K - i)), {apply funext,assume i,rw series_mul_left}, rw this,clear this,simp, have : series (λ (i : ℕ), a i * series b (K - i)) K = series (λ (i : ℕ), a i * (series b (K - i) - series b K)) K + series (λ i, a i * series b K) K, {rw ←series_add,simp[(mul_add _ _ _).symm]}, rw this, clear this, rw series_mul_series,simp, rw abv_neg abv, refine lt_of_le_of_lt (abv_series_le_series_abv _) _, simp [abv_mul abv], suffices : series (λ (i : ℕ), abv (a i) * abv (series b (K - i) + -series b K)) (max N M + 1) + (series (λ (i : ℕ), abv (a i) * abv (series b (K - i) + -series b K)) K -series (λ (i : ℕ), abv (a i) * abv (series b (K - i) + -series b K)) (max N M + 1)) < ε / (2 * P) * P + ε / (4 * Q) * (2 * Q), { simp [(div_div_eq_div_mul _ _ _).symm] at this, rwa[div_mul_cancel _ (ne_of_lt P0).symm,(by norm_num : (4 : α) = 2 * 2),←div_div_eq_div_mul,mul_comm (2 : α),←mul_assoc, div_mul_cancel _ (ne_of_lt (lt_of_le_of_lt (abv_nonneg _ _) (hQ 0))).symm,div_mul_cancel,add_halves] at this, norm_num}, refine add_lt_add _ _, {have : series (λ (i : ℕ), abv (a i) * abv (series b (K - i) + -series b K)) (max N M + 1) ≤ series (λ (i : ℕ), abv (a i) * (ε / (2 * P))) (max N M + 1), {refine series_le_series _,assume m mJ,refine mul_le_mul_of_nonneg_left _ _, {refine le_of_lt (hN (K - m) K _ _),{ refine nat.le_sub_left_of_add_le (le_trans _ hK), rw[succ_mul,one_mul], exact add_le_add mJ (le_trans (le_max_left _ _) (le_of_lt (lt_add_one _)))}, {refine le_trans _ hK,rw ←one_mul N, refine mul_le_mul (by norm_num) (by rw one_mul;exact le_trans (le_max_left _ _) (le_of_lt (lt_add_one _))) (zero_le _) (zero_le _)}}, exact abv_nonneg abv _}, refine lt_of_le_of_lt this _, rw [series_mul_right,mul_comm], specialize hP (max N M + 1),rwa abs_of_nonneg at hP, refine (mul_lt_mul_left Pε0).mpr hP, refine series_nonneg _,assume x h,exact abv_nonneg abv _}, {have hNMK : max N M + 1 < K, {refine lt_of_lt_of_le _ hK, rw [succ_mul,one_mul,←add_zero (max N M + 1)], refine add_lt_add_of_le_of_lt (le_refl _) _,rw add_zero, refine add_pos_of_nonneg_of_pos (zero_le _) (by norm_num)}, rw series_sub_series _ hNMK, have : nat.sum (λ (i : ℕ), abv (a i) * abv (series b (K - i) + -series b K)) (max N M + 2) K ≤ nat.sum (λ (i : ℕ), abv (a i) * (2 * Q)) (max N M + 2) K, {unfold nat.sum,refine series_le_series _, assume m hm, refine mul_le_mul_of_nonneg_left _ _, {refine le_trans (abv_add abv _ _) _, rw ←(by ring : Q + Q = 2 * Q), refine add_le_add (le_of_lt (hQ _)) _, rw abv_neg abv, exact le_of_lt (hQ _)}, exact abv_nonneg abv _}, refine lt_of_le_of_lt this _, rw [←series_sub_series _ hNMK,series_mul_right,series_mul_right,←sub_mul], refine (mul_lt_mul_right (mul_pos (by norm_num) (lt_of_le_of_lt (abv_nonneg abv _) (hQ 0)))).mpr _, refine lt_of_le_of_lt (le_abs_self _) _, refine hM _ _ _ (le_trans (le_max_right _ _) (le_of_lt (lt_add_one _))), refine le_trans _ hK, rw [succ_mul,one_mul,←add_zero M], exact add_le_add (le_trans (le_max_right _ _) (le_of_lt (lt_add_one _))) (zero_le _)}, end #print series_merten
0f107b55c80e48d70e69e27cf85c98a3512c6be2
432d948a4d3d242fdfb44b81c9e1b1baacd58617
/src/group_theory/nielsen_schreier.lean
bda61f8124bd4d7ab1d5376dc1c66a121a5a77a0
[ "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
12,022
lean
/- Copyright (c) 2021 David Wärn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Wärn -/ import category_theory.action import combinatorics.quiver import group_theory.is_free_group /-! # The Nielsen-Schreier theorem This file proves that a subgroup of a free group is itself free. ## Main result - `subgroup_is_free_of_is_free H`: an instance saying that a subgroup of a free group is free. ## Proof overview The proof is analogous to the proof using covering spaces and fundamental groups of graphs, but we work directly with groupoids instead of topological spaces. Under this analogy, - `is_free_groupoid G` corresponds to saying that a space is a graph. - `End_mul_equiv_subgroup H` plays the role of replacing 'subgroup of fundamental group' with 'fundamental group of covering space'. - `action_category_is_free G A` corresponds to the fact that a covering of a (single-vertex) graph is a graph. - `End_is_free_group_of_arborescence` corresponds to the fact that, given a spanning tree of a graph, its fundamental group is free (generated by loops from the complement of the tree). ## Implementation notes Our definition of `is_free_groupoid` is nonstandard. Normally one would require that functors `G ⥤ X` to any _groupoid_ `X` are given by graph homomorphisms from the generators, but we only consider _groups_ `X`. This simplifies the argument since functor equality is complicated in general, but simple for functors to single object categories. ## References https://ncatlab.org/nlab/show/Nielsen-Schreier+theorem ## Tags free group, free groupoid, Nielsen-Schreier -/ noncomputable theory open_locale classical universes v u open category_theory category_theory.action_category category_theory.single_obj quiver is_free_group as fgp /-- `is_free_groupoid.generators G` is a type synonym for `G`. We think of this as the vertices of the generating quiver of `G` when `G` is free. We can't use `G` directly, since `G` already has a quiver instance from being a groupoid. -/ @[nolint unused_arguments has_inhabited_instance] def is_free_groupoid.generators (G) [groupoid G] := G /-- A groupoid `G` is free when we have the following data: - a quiver on `is_free_groupoid.generators G` (a type synonym for `G`) - a function `of` taking a generating arrow to a morphism in `G` - such that a functor from `G` to any group `X` is uniquely determined by assigning labels in `X` to the generating arrows. This definition is nonstandard. Normally one would require that functors `G ⥤ X` to any _groupoid_ `X` are given by graph homomorphisms from `generators`. -/ class is_free_groupoid (G) [groupoid.{v} G] := (quiver_generators : quiver.{v+1} (is_free_groupoid.generators G)) (of : Π {a b : is_free_groupoid.generators G}, (a ⟶ b) → ((show G, from a) ⟶ b)) (unique_lift : ∀ {X : Type v} [group X] (f : labelling (is_free_groupoid.generators G) X), ∃! F : G ⥤ single_obj X, ∀ a b (g : a ⟶ b), F.map (of g) = f g) namespace is_free_groupoid attribute [instance] quiver_generators /-- Two functors from a free groupoid to a group are equal when they agree on the generating quiver. -/ @[ext] lemma ext_functor {G} [groupoid.{v} G] [is_free_groupoid G] {X : Type v} [group X] (f g : G ⥤ single_obj X) (h : ∀ a b (e : a ⟶ b), f.map (of e) = g.map (of e)) : f = g := let ⟨_, _, u⟩ := @unique_lift G _ _ X _ (λ (a b : generators G) (e : a ⟶ b), g.map (of e)) in trans (u _ h) (u _ (λ _ _ _, rfl)).symm /-- An action groupoid over a free froup is free. More generally, one could show that the groupoid of elements over a free groupoid is free, but this version is easier to prove and suffices for our purposes. Analogous to the fact that a covering space of a graph is a graph. (A free groupoid is like a graph, and a groupoid of elements is like a covering space.) -/ instance action_groupoid_is_free {G A : Type u} [group G] [is_free_group G] [mul_action G A] : is_free_groupoid (action_category G A) := { quiver_generators := ⟨λ a b, { e : fgp.generators G // fgp.of e • a.back = b.back }⟩, of := λ a b e, ⟨fgp.of e, e.property⟩, unique_lift := begin introsI X _ f, let f' : fgp.generators G → (A → X) ⋊[mul_aut_arrow] G := λ e, ⟨λ b, @f ⟨(), _⟩ ⟨(), b⟩ ⟨e, smul_inv_smul _ b⟩, fgp.of e⟩, rcases fgp.unique_lift f' with ⟨F', hF', uF'⟩, refine ⟨uncurry F' _, _, _⟩, { suffices : semidirect_product.right_hom.comp F' = monoid_hom.id _, { exact monoid_hom.ext_iff.mp this }, ext, rw [monoid_hom.comp_apply, hF'], refl }, { rintros ⟨⟨⟩, a : A⟩ ⟨⟨⟩, b⟩ ⟨e, h : fgp.of e • a = b⟩, change (F' (fgp.of _)).left _ = _, rw hF', cases (inv_smul_eq_iff.mpr h.symm), refl }, { intros E hE, have : curry E = F', { apply uF', intro e, ext, { convert hE _ _ _, refl }, { refl } }, apply functor.hext, { intro, apply unit.ext }, { refine action_category.cases _, intros, simp only [←this, uncurry_map, curry_apply_left, coe_back, hom_of_pair.val] } }, end } namespace spanning_tree /- In this section, we suppose we have a free groupoid with a spanning tree for its generating quiver. The goal is to prove that the vertex group at the root is free. A picture to have in mind is that we are 'pulling' the endpoints of all the edges of the quiver along the spanning tree to the root. -/ variables {G : Type u} [groupoid.{u} G] [is_free_groupoid G] (T : wide_subquiver (symmetrify $ generators G)) [arborescence T] /-- The root of `T`, except its type is `G` instead of the type synonym `T`. -/ private def root' : G := show T, from root T /-- A path in the tree gives a hom, by composition. -/ -- this has to be marked noncomputable, see issue #451. -- It might be nicer to define this in terms of `compose_path` noncomputable def hom_of_path : Π {a : G}, path (root T) a → (root' T ⟶ a) | _ path.nil := 𝟙 _ | a (path.cons p f) := hom_of_path p ≫ sum.rec_on f.val (λ e, of e) (λ e, inv (of e)) /-- For every vertex `a`, there is a canonical hom from the root, given by the path in the tree. -/ def tree_hom (a : G) : root' T ⟶ a := hom_of_path T (default _) /-- Any path to `a` gives `tree_hom T a`, since paths in the tree are unique. -/ lemma tree_hom_eq {a : G} (p : path (root T) a) : tree_hom T a = hom_of_path T p := by rw [tree_hom, unique.default_eq] @[simp] lemma tree_hom_root : tree_hom T (root' T) = 𝟙 _ := -- this should just be `tree_hom_eq T path.nil`, but Lean treats `hom_of_path` with suspicion. trans (tree_hom_eq T path.nil) rfl /-- Any hom in `G` can be made into a loop, by conjugating with `tree_hom`s. -/ def loop_of_hom {a b : G} (p : a ⟶ b) : End (root' T) := tree_hom T a ≫ p ≫ inv (tree_hom T b) /-- Turning an edge in the spanning tree into a loop gives the indentity loop. -/ lemma loop_of_hom_eq_id {a b : generators G} (e ∈ wide_subquiver_symmetrify T a b) : loop_of_hom T (of e) = 𝟙 (root' T) := begin rw [loop_of_hom, ←category.assoc, is_iso.comp_inv_eq, category.id_comp], cases H, { rw [tree_hom_eq T (path.cons (default _) ⟨sum.inl e, H⟩), hom_of_path], refl }, { rw [tree_hom_eq T (path.cons (default _) ⟨sum.inr e, H⟩), hom_of_path], simp only [is_iso.inv_hom_id, category.comp_id, category.assoc, tree_hom] } end /-- Since a hom gives a loop, any homomorphism from the vertex group at the root extends to a functor on the whole groupoid. -/ @[simps] def functor_of_monoid_hom {X} [monoid X] (f : End (root' T) →* X) : G ⥤ single_obj X := { obj := λ _, (), map := λ a b p, f (loop_of_hom T p), map_id' := begin intro a, rw [loop_of_hom, category.id_comp, is_iso.hom_inv_id, ←End.one_def, f.map_one, id_as_one], end, map_comp' := begin intros, rw [comp_as_mul, ←f.map_mul], simp only [is_iso.inv_hom_id_assoc, loop_of_hom, End.mul_def, category.assoc] end } /-- Given a free groupoid and an arborescence of its generating quiver, the vertex group at the root is freely generated by loops coming from generating arrows in the complement of the tree. -/ def End_is_free : is_free_group (End (root' T)) := { generators := set.compl (wide_subquiver_equiv_set_total $ wide_subquiver_symmetrify T), of := λ e, loop_of_hom T (of e.val.hom), unique_lift' := begin introsI X _ f, let f' : labelling (generators G) X := λ a b e, if h : e ∈ wide_subquiver_symmetrify T a b then 1 else f ⟨⟨a, b, e⟩, h⟩, rcases unique_lift f' with ⟨F', hF', uF'⟩, refine ⟨F'.map_End _, _, _⟩, { suffices : ∀ {x y} (q : x ⟶ y), F'.map (loop_of_hom T q) = (F'.map q : X), { rintro ⟨⟨a, b, e⟩, h⟩, rw [functor.map_End_apply, this, hF'], exact dif_neg h }, intros, suffices : ∀ {a} (p : path (root' T) a), F'.map (hom_of_path T p) = 1, { simp only [this, tree_hom, comp_as_mul, inv_as_inv, loop_of_hom, one_inv, mul_one, one_mul, functor.map_inv, functor.map_comp] }, intros a p, induction p with b c p e ih, { rw [hom_of_path, F'.map_id, id_as_one] }, rw [hom_of_path, F'.map_comp, comp_as_mul, ih, mul_one], rcases e with ⟨e | e, eT⟩, { rw hF', exact dif_pos (or.inl eT) }, { rw [F'.map_inv, inv_as_inv, inv_eq_one, hF'], exact dif_pos (or.inr eT) } }, { intros E hE, ext, suffices : (functor_of_monoid_hom T E).map x = F'.map x, { simpa only [loop_of_hom, functor_of_monoid_hom_map, is_iso.inv_id, tree_hom_root, category.id_comp, category.comp_id] using this }, congr, apply uF', intros a b e, change E (loop_of_hom T _) = dite _ _ _, split_ifs, { rw [loop_of_hom_eq_id T e h, ←End.one_def, E.map_one] }, { exact hE ⟨⟨a, b, e⟩, h⟩ } } end } end spanning_tree /-- Another name for the identity function `G → G`, to help type checking. -/ private def symgen {G : Type u} [groupoid.{v} G] [is_free_groupoid G] : G → symmetrify (generators G) := id /-- If there exists a morphism `a → b` in a free groupoid, then there also exists a zigzag from `a` to `b` in the generating quiver. -/ lemma path_nonempty_of_hom {G} [groupoid.{u u} G] [is_free_groupoid G] {a b : G} : nonempty (a ⟶ b) → nonempty (path (symgen a) (symgen b)) := begin rintro ⟨p⟩, rw [←weakly_connected_component.eq, eq_comm, ←free_group.of_injective.eq_iff, ←mul_inv_eq_one], let X := free_group (weakly_connected_component $ symmetrify $ generators G), let f : G → X := λ g, free_group.of ↑(symgen g), let F : G ⥤ single_obj X := single_obj.difference_functor f, change F.map p = ((category_theory.functor.const G).obj ()).map p, congr, ext, rw [functor.const.obj_map, id_as_one, difference_functor_map, mul_inv_eq_one], apply congr_arg free_group.of, rw weakly_connected_component.eq, exact ⟨hom.to_path (sum.inr e)⟩, end /-- Given a connected free groupoid, its generating quiver is rooted-connected. -/ instance generators_connected (G) [groupoid.{u u} G] [is_connected G] [is_free_groupoid G] (r : G) : rooted_connected (symgen r) := ⟨λ b, path_nonempty_of_hom (category_theory.nonempty_hom_of_connected_groupoid r b)⟩ /-- A vertex group in a free connected groupoid is free. With some work one could drop the connectedness assumption, by looking at connected components. -/ instance End_is_free_of_connected_free {G} [groupoid G] [is_connected G] [is_free_groupoid G] (r : G) : is_free_group (End r) := spanning_tree.End_is_free $ geodesic_subtree (symgen r) end is_free_groupoid /-- The Nielsen-Schreier theorem: a subgroup of a free group is free. -/ instance subgroup_is_free_of_is_free {G : Type u} [group G] [is_free_group G] (H : subgroup G) : is_free_group H := is_free_group.of_mul_equiv (End_mul_equiv_subgroup H)
14d6a8438bf5036d45a9979ea78c94df8963aad7
c777c32c8e484e195053731103c5e52af26a25d1
/src/representation_theory/group_cohomology/basic.lean
a972d9f61f84910eaa17c2c9d48b2ac8f9f56316
[ "Apache-2.0" ]
permissive
kbuzzard/mathlib
2ff9e85dfe2a46f4b291927f983afec17e946eb8
58537299e922f9c77df76cb613910914a479c1f7
refs/heads/master
1,685,313,702,744
1,683,974,212,000
1,683,974,212,000
128,185,277
1
0
null
1,522,920,600,000
1,522,920,600,000
null
UTF-8
Lean
false
false
8,578
lean
/- Copyright (c) 2023 Amelia Livingston. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Amelia Livingston -/ import algebra.homology.opposite import representation_theory.group_cohomology.resolution /-! # The group cohomology of a `k`-linear `G`-representation Let `k` be a commutative ring and `G` a group. This file defines the group cohomology of `A : Rep k G` to be the cohomology of the complex $$0 \to \mathrm{Fun}(G^0, A) \to \mathrm{Fun}(G^1, A) \to \mathrm{Fun}(G^2, A) \to \dots$$ with differential $d^n$ sending $f: G^n \to A$ to the function mapping $(g_0, \dots, g_n)$ to $$\rho(g_0)(f(g_1, \dots, g_n)) + \sum_{i = 0}^{n - 1} (-1)^{i + 1}\cdot f(g_0, \dots, g_ig_{i + 1}, \dots, g_n)$$ $$+ (-1)^{n + 1}\cdot f(g_0, \dots, g_{n - 1})$$ (where `ρ` is the representation attached to `A`). We have a `k`-linear isomorphism $\mathrm{Fun}(G^n, A) \cong \mathrm{Hom}(k[G^{n + 1}], A)$, where the righthand side is morphisms in `Rep k G`, and the representation on $k[G^{n + 1}]$ is induced by the diagonal action of `G`. If we conjugate the $n$th differential in $\mathrm{Hom}(P, A)$ by this isomorphism, where `P` is the standard resolution of `k` as a trivial `k`-linear `G`-representation, then the resulting map agrees with the differential $d^n$ defined above, a fact we prove. This gives us for free a proof that our $d^n$ squares to zero. It also gives us an isomorphism $\mathrm{H}^n(G, A) \cong \mathrm{Ext}^n(k, A),$ where $\mathrm{Ext}$ is taken in the category `Rep k G`. ## Main definitions * `group_cohomology.linear_yoneda_obj_resolution A`: a complex whose objects are the representation morphisms $\mathrm{Hom}(k[G^{n + 1}], A)$ and whose cohomology is the group cohomology $\mathrm{H}^n(G, A)$. * `group_cohomology.inhomogeneous_cochains A`: a complex whose objects are $\mathrm{Fun}(G^n, A)$ and whose cohomology is the group cohomology $\mathrm{H}^n(G, A).$ * `group_cohomology.inhomogeneous_cochains_iso A`: an isomorphism between the above two complexes. * `group_cohomology A n`: this is $\mathrm{H}^n(G, A),$ defined as the $n$th cohomology of the second complex, `inhomogeneous_cochains A`. * `group_cohomology_iso_Ext A n`: an isomorphism $\mathrm{H}^n(G, A) \cong \mathrm{Ext}^n(k, A)$ (where $\mathrm{Ext}$ is taken in the category `Rep k G`) induced by `inhomogeneous_cochains_iso A`. ## Implementation notes Group cohomology is typically stated for `G`-modules, or equivalently modules over the group ring `ℤ[G].` However, `ℤ` can be generalized to any commutative ring `k`, which is what we use. Moreover, we express `k[G]`-module structures on a module `k`-module `A` using the `Rep` definition. We avoid using instances `module (monoid_algebra k G) A` so that we do not run into possible scalar action diamonds. ## TODO * API for cohomology in low degree: $\mathrm{H}^0, \mathrm{H}^1$ and $\mathrm{H}^2.$ For example, the inflation-restriction exact sequence. * The long exact sequence in cohomology attached to a short exact sequence of representations. * Upgrading `group_cohomology_iso_Ext` to an isomorphism of derived functors. * Profinite cohomology. Longer term: * The Hochschild-Serre spectral sequence (this is perhaps a good toy example for the theory of spectral sequences in general). -/ noncomputable theory universes u variables {k G : Type u} [comm_ring k] {n : ℕ} open category_theory namespace group_cohomology variables [monoid G] /-- The complex `Hom(P, A)`, where `P` is the standard resolution of `k` as a trivial `k`-linear `G`-representation. -/ abbreviation linear_yoneda_obj_resolution (A : Rep k G) : cochain_complex (Module.{u} k) ℕ := homological_complex.unop ((((linear_yoneda k (Rep k G)).obj A).right_op.map_homological_complex _).obj (resolution k G)) lemma linear_yoneda_obj_resolution_d_apply {A : Rep k G} (i j : ℕ) (x : (resolution k G).X i ⟶ A) : (linear_yoneda_obj_resolution A).d i j x = (resolution k G).d j i ≫ x := rfl end group_cohomology namespace inhomogeneous_cochains open Rep group_cohomology /-- The differential in the complex of inhomogeneous cochains used to calculate group cohomology. -/ @[simps] def d [monoid G] (n : ℕ) (A : Rep k G) : ((fin n → G) → A) →ₗ[k] (fin (n + 1) → G) → A := { to_fun := λ f g, A.ρ (g 0) (f (λ i, g i.succ)) + finset.univ.sum (λ j : fin (n + 1), (-1 : k) ^ ((j : ℕ) + 1) • f (fin.contract_nth j (*) g)), map_add' := λ f g, begin ext x, simp only [pi.add_apply, map_add, smul_add, finset.sum_add_distrib, add_add_add_comm], end, map_smul' := λ r f, begin ext x, simp only [pi.smul_apply, ring_hom.id_apply, map_smul, smul_add, finset.smul_sum, ←smul_assoc, smul_eq_mul, mul_comm r], end } variables [group G] (n) (A : Rep k G) /-- The theorem that our isomorphism `Fun(Gⁿ, A) ≅ Hom(k[Gⁿ⁺¹], A)` (where the righthand side is morphisms in `Rep k G`) commutes with the differentials in the complex of inhomogeneous cochains and the homogeneous `linear_yoneda_obj_resolution`. -/ lemma d_eq : d n A = ((diagonal_hom_equiv n A).to_Module_iso.inv ≫ (linear_yoneda_obj_resolution A).d n (n + 1) ≫ (diagonal_hom_equiv (n + 1) A).to_Module_iso.hom) := begin ext f g, simp only [Module.coe_comp, linear_equiv.coe_coe, function.comp_app, linear_equiv.to_Module_iso_inv, linear_yoneda_obj_resolution_d_apply, linear_equiv.to_Module_iso_hom, diagonal_hom_equiv_apply, Action.comp_hom, resolution.d_eq k G n, resolution.d_of (fin.partial_prod g), linear_map.map_sum, ←finsupp.smul_single_one _ ((-1 : k) ^ _), map_smul, d_apply], simp only [@fin.sum_univ_succ _ _ (n + 1), fin.coe_zero, pow_zero, one_smul, fin.succ_above_zero, diagonal_hom_equiv_symm_apply f (fin.partial_prod g ∘ @fin.succ (n + 1)), function.comp_app, fin.partial_prod_succ, fin.cast_succ_zero, fin.partial_prod_zero, one_mul], congr' 1, { congr, ext, have := fin.partial_prod_right_inv g (fin.cast_succ x), simp only [mul_inv_rev, fin.cast_succ_fin_succ] at *, rw [mul_assoc, ←mul_assoc _ _ (g x.succ), this, inv_mul_cancel_left] }, { exact finset.sum_congr rfl (λ j hj, by rw [diagonal_hom_equiv_symm_partial_prod_succ, fin.coe_succ]) } end end inhomogeneous_cochains namespace group_cohomology variables [group G] (n) (A : Rep k G) open inhomogeneous_cochains /-- Given a `k`-linear `G`-representation `A`, this is the complex of inhomogeneous cochains $$0 \to \mathrm{Fun}(G^0, A) \to \mathrm{Fun}(G^1, A) \to \mathrm{Fun}(G^2, A) \to \dots$$ which calculates the group cohomology of `A`. -/ noncomputable abbreviation inhomogeneous_cochains : cochain_complex (Module k) ℕ := cochain_complex.of (λ n, Module.of k ((fin n → G) → A)) (λ n, inhomogeneous_cochains.d n A) (λ n, begin ext x y, have := linear_map.ext_iff.1 ((linear_yoneda_obj_resolution A).d_comp_d n (n + 1) (n + 2)), simp only [Module.coe_comp, function.comp_app] at this, simp only [Module.coe_comp, function.comp_app, d_eq, linear_equiv.to_Module_iso_hom, linear_equiv.to_Module_iso_inv, linear_equiv.coe_coe, linear_equiv.symm_apply_apply, this, linear_map.zero_apply, map_zero, pi.zero_apply], end) /-- Given a `k`-linear `G`-representation `A`, the complex of inhomogeneous cochains is isomorphic to `Hom(P, A)`, where `P` is the standard resolution of `k` as a trivial `G`-representation. -/ def inhomogeneous_cochains_iso : inhomogeneous_cochains A ≅ linear_yoneda_obj_resolution A := homological_complex.hom.iso_of_components (λ i, (Rep.diagonal_hom_equiv i A).to_Module_iso.symm) $ begin rintros i j (h : i + 1 = j), subst h, simp only [cochain_complex.of_d, d_eq, category.assoc, iso.symm_hom, iso.hom_inv_id, category.comp_id], end end group_cohomology open group_cohomology /-- The group cohomology of a `k`-linear `G`-representation `A`, as the cohomology of its complex of inhomogeneous cochains. -/ def group_cohomology [group G] (A : Rep k G) (n : ℕ) : Module k := (inhomogeneous_cochains A).homology n /-- The `n`th group cohomology of a `k`-linear `G`-representation `A` is isomorphic to `Extⁿ(k, A)` (taken in `Rep k G`), where `k` is a trivial `k`-linear `G`-representation. -/ def group_cohomology_iso_Ext [group G] (A : Rep k G) (n : ℕ) : group_cohomology A n ≅ ((Ext k (Rep k G) n).obj (opposite.op $ Rep.trivial k G k)).obj A := (homology_obj_iso_of_homotopy_equiv (homotopy_equiv.of_iso (inhomogeneous_cochains_iso _)) _) ≪≫ (homological_complex.homology_unop _ _) ≪≫ (Ext_iso k G A n).symm
f9de2c88461f3ce0a61122fa7a2712d7a85563af
57c233acf9386e610d99ed20ef139c5f97504ba3
/src/order/basic.lean
9e149ab14bdd54a92d29eeb012d58bc150195af9
[ "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
25,072
lean
/- Copyright (c) 2014 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Mario Carneiro -/ import data.prod import data.subtype /-! # Basic definitions about `≤` and `<` This file proves basic results about orders, provides extensive dot notation, defines useful order classes and allows to transfer order instances. ## Type synonyms * `order_dual α` : A type synonym reversing the meaning of all inequalities. * `as_linear_order α`: A type synonym to promote `partial_order α` to `linear_order α` using `is_total α (≤)`. ### Transfering orders - `order.preimage`, `preorder.lift`: Transfers a (pre)order on `β` to an order on `α` using a function `f : α → β`. - `partial_order.lift`, `linear_order.lift`: Transfers a partial (resp., linear) order on `β` to a partial (resp., linear) order on `α` using an injective function `f`. ### Extra class - `densely_ordered`: An order with no gap, i.e. for any two elements `a < b` there exists `c` such that `a < c < b`. ## Notes `≤` and `<` are highly favored over `≥` and `>` in mathlib. The reason is that we can formulate all lemmas using `≤`/`<`, and `rw` has trouble unifying `≤` and `≥`. Hence choosing one direction spares us useless duplication. This is enforced by a linter. See Note [nolint_ge] for more infos. Dot notation is particularly useful on `≤` (`has_le.le`) and `<` (`has_lt.lt`). To that end, we provide many aliases to dot notation-less lemmas. For example, `le_trans` is aliased with `has_le.le.trans` and can be used to construct `hab.trans hbc : a ≤ c` when `hab : a ≤ b`, `hbc : b ≤ c`, `lt_of_le_of_lt` is aliased as `has_le.le.trans_lt` and can be used to construct `hab.trans hbc : a < c` when `hab : a ≤ b`, `hbc : b < c`. ## TODO - expand module docs - automatic construction of dual definitions / theorems ## Tags preorder, order, partial order, poset, linear order, chain -/ open function universes u v w variables {α : Type u} {β : Type v} {γ : Type w} {r : α → α → Prop} lemma ge_antisymm [partial_order α] {a b : α} (hab : a ≤ b) (hba : b ≤ a) : b = a := le_antisymm hba hab attribute [simp] le_refl attribute [ext] has_le alias le_trans ← has_le.le.trans alias lt_of_le_of_lt ← has_le.le.trans_lt alias le_antisymm ← has_le.le.antisymm alias ge_antisymm ← has_le.le.antisymm' alias lt_of_le_of_ne ← has_le.le.lt_of_ne alias lt_of_le_not_le ← has_le.le.lt_of_not_le alias lt_or_eq_of_le ← has_le.le.lt_or_eq alias decidable.lt_or_eq_of_le ← has_le.le.lt_or_eq_dec alias le_of_lt ← has_lt.lt.le alias lt_trans ← has_lt.lt.trans alias lt_of_lt_of_le ← has_lt.lt.trans_le alias ne_of_lt ← has_lt.lt.ne alias lt_asymm ← has_lt.lt.asymm has_lt.lt.not_lt alias le_of_eq ← eq.le attribute [nolint decidable_classical] has_le.le.lt_or_eq_dec /-- A version of `le_refl` where the argument is implicit -/ lemma le_rfl [preorder α] {x : α} : x ≤ x := le_refl x @[simp] lemma lt_self_iff_false [preorder α] (x : α) : x < x ↔ false := ⟨lt_irrefl x, false.elim⟩ namespace eq /-- If `x = y` then `y ≤ x`. Note: this lemma uses `y ≤ x` instead of `x ≥ y`, because `le` is used almost exclusively in mathlib. -/ protected lemma ge [preorder α] {x y : α} (h : x = y) : y ≤ x := h.symm.le lemma trans_le [preorder α] {x y z : α} (h1 : x = y) (h2 : y ≤ z) : x ≤ z := h1.le.trans h2 lemma not_lt [partial_order α] {x y : α} (h : x = y) : ¬(x < y) := λ h', h'.ne h lemma not_gt [partial_order α] {x y : α} (h : x = y) : ¬(y < x) := h.symm.not_lt end eq namespace has_le.le @[nolint ge_or_gt] -- see Note [nolint_ge] protected lemma ge [has_le α] {x y : α} (h : x ≤ y) : y ≥ x := h lemma trans_eq [preorder α] {x y z : α} (h1 : x ≤ y) (h2 : y = z) : x ≤ z := h1.trans h2.le lemma lt_iff_ne [partial_order α] {x y : α} (h : x ≤ y) : x < y ↔ x ≠ y := ⟨λ h, h.ne, h.lt_of_ne⟩ lemma le_iff_eq [partial_order α] {x y : α} (h : x ≤ y) : y ≤ x ↔ y = x := ⟨λ h', h'.antisymm h, eq.le⟩ lemma lt_or_le [linear_order α] {a b : α} (h : a ≤ b) (c : α) : a < c ∨ c ≤ b := (lt_or_ge a c).imp id $ λ hc, le_trans hc h lemma le_or_lt [linear_order α] {a b : α} (h : a ≤ b) (c : α) : a ≤ c ∨ c < b := (le_or_gt a c).imp id $ λ hc, lt_of_lt_of_le hc h lemma le_or_le [linear_order α] {a b : α} (h : a ≤ b) (c : α) : a ≤ c ∨ c ≤ b := (h.le_or_lt c).elim or.inl (λ h, or.inr $ le_of_lt h) end has_le.le namespace has_lt.lt @[nolint ge_or_gt] -- see Note [nolint_ge] protected lemma gt [has_lt α] {x y : α} (h : x < y) : y > x := h protected lemma false [preorder α] {x : α} : x < x → false := lt_irrefl x lemma ne' [preorder α] {x y : α} (h : x < y) : y ≠ x := h.ne.symm lemma lt_or_lt [linear_order α] {x y : α} (h : x < y) (z : α) : x < z ∨ z < y := (lt_or_ge z y).elim or.inr (λ hz, or.inl $ h.trans_le hz) end has_lt.lt @[nolint ge_or_gt] -- see Note [nolint_ge] protected lemma ge.le [has_le α] {x y : α} (h : x ≥ y) : y ≤ x := h @[nolint ge_or_gt] -- see Note [nolint_ge] protected lemma gt.lt [has_lt α] {x y : α} (h : x > y) : y < x := h @[nolint ge_or_gt] -- see Note [nolint_ge] theorem ge_of_eq [preorder α] {a b : α} (h : a = b) : a ≥ b := h.ge @[simp, nolint ge_or_gt] -- see Note [nolint_ge] lemma ge_iff_le [preorder α] {a b : α} : a ≥ b ↔ b ≤ a := iff.rfl @[simp, nolint ge_or_gt] -- see Note [nolint_ge] lemma gt_iff_lt [preorder α] {a b : α} : a > b ↔ b < a := iff.rfl lemma not_le_of_lt [preorder α] {a b : α} (h : a < b) : ¬ b ≤ a := (le_not_le_of_lt h).right alias not_le_of_lt ← has_lt.lt.not_le lemma not_lt_of_le [preorder α] {a b : α} (h : a ≤ b) : ¬ b < a := λ hba, hba.not_le h alias not_lt_of_le ← has_le.le.not_lt lemma ne_of_not_le [preorder α] {a b : α} (h : ¬ a ≤ b) : a ≠ b := λ hab, h (le_of_eq hab) -- See Note [decidable namespace] protected lemma decidable.le_iff_eq_or_lt [partial_order α] [@decidable_rel α (≤)] {a b : α} : a ≤ b ↔ a = b ∨ a < b := decidable.le_iff_lt_or_eq.trans or.comm lemma le_iff_eq_or_lt [partial_order α] {a b : α} : a ≤ b ↔ a = b ∨ a < b := le_iff_lt_or_eq.trans or.comm lemma lt_iff_le_and_ne [partial_order α] {a b : α} : a < b ↔ a ≤ b ∧ a ≠ b := ⟨λ h, ⟨le_of_lt h, ne_of_lt h⟩, λ ⟨h1, h2⟩, h1.lt_of_ne h2⟩ -- See Note [decidable namespace] protected lemma decidable.eq_iff_le_not_lt [partial_order α] [@decidable_rel α (≤)] {a b : α} : a = b ↔ a ≤ b ∧ ¬ a < b := ⟨λ h, ⟨h.le, h ▸ lt_irrefl _⟩, λ ⟨h₁, h₂⟩, h₁.antisymm $ decidable.by_contradiction $ λ h₃, h₂ (h₁.lt_of_not_le h₃)⟩ lemma eq_iff_le_not_lt [partial_order α] {a b : α} : a = b ↔ a ≤ b ∧ ¬ a < b := by haveI := classical.dec; exact decidable.eq_iff_le_not_lt lemma eq_or_lt_of_le [partial_order α] {a b : α} (h : a ≤ b) : a = b ∨ a < b := h.lt_or_eq.symm lemma eq_or_gt_of_le [partial_order α] {a b : α} (h : a ≤ b) : b = a ∨ a < b := h.lt_or_eq.symm.imp eq.symm id alias decidable.eq_or_lt_of_le ← has_le.le.eq_or_lt_dec alias eq_or_lt_of_le ← has_le.le.eq_or_lt alias eq_or_gt_of_le ← has_le.le.eq_or_gt attribute [nolint decidable_classical] has_le.le.eq_or_lt_dec lemma eq_of_le_of_not_lt [partial_order α] {a b : α} (hab : a ≤ b) (hba : ¬ a < b) : a = b := hab.eq_or_lt.resolve_right hba lemma eq_of_ge_of_not_gt [partial_order α] {a b : α} (hab : a ≤ b) (hba : ¬ a < b) : b = a := (hab.eq_or_lt.resolve_right hba).symm alias eq_of_le_of_not_lt ← has_le.le.eq_of_not_lt alias eq_of_ge_of_not_gt ← has_le.le.eq_of_not_gt lemma ne.le_iff_lt [partial_order α] {a b : α} (h : a ≠ b) : a ≤ b ↔ a < b := ⟨λ h', lt_of_le_of_ne h' h, λ h, h.le⟩ -- See Note [decidable namespace] protected lemma decidable.ne_iff_lt_iff_le [partial_order α] [@decidable_rel α (≤)] {a b : α} : (a ≠ b ↔ a < b) ↔ a ≤ b := ⟨λ h, decidable.by_cases le_of_eq (le_of_lt ∘ h.mp), λ h, ⟨lt_of_le_of_ne h, ne_of_lt⟩⟩ @[simp] lemma ne_iff_lt_iff_le [partial_order α] {a b : α} : (a ≠ b ↔ a < b) ↔ a ≤ b := by haveI := classical.dec; exact decidable.ne_iff_lt_iff_le lemma lt_of_not_ge' [linear_order α] {a b : α} (h : ¬ b ≤ a) : a < b := ((le_total _ _).resolve_right h).lt_of_not_le h lemma lt_iff_not_ge' [linear_order α] {x y : α} : x < y ↔ ¬ y ≤ x := ⟨not_le_of_gt, lt_of_not_ge'⟩ lemma ne.lt_or_lt [linear_order α] {x y : α} (h : x ≠ y) : x < y ∨ y < x := lt_or_gt_of_ne h /-- A version of `ne_iff_lt_or_gt` with LHS and RHS reversed. -/ @[simp] lemma lt_or_lt_iff_ne [linear_order α] {x y : α} : x < y ∨ y < x ↔ x ≠ y := ne_iff_lt_or_gt.symm lemma not_lt_iff_eq_or_lt [linear_order α] {a b : α} : ¬ a < b ↔ a = b ∨ b < a := not_lt.trans $ decidable.le_iff_eq_or_lt.trans $ or_congr eq_comm iff.rfl lemma exists_ge_of_linear [linear_order α] (a b : α) : ∃ c, a ≤ c ∧ b ≤ c := match le_total a b with | or.inl h := ⟨_, h, le_rfl⟩ | or.inr h := ⟨_, le_rfl, h⟩ end lemma lt_imp_lt_of_le_imp_le {β} [linear_order α] [preorder β] {a b : α} {c d : β} (H : a ≤ b → c ≤ d) (h : d < c) : b < a := lt_of_not_ge' $ λ h', (H h').not_lt h lemma le_imp_le_iff_lt_imp_lt {β} [linear_order α] [linear_order β] {a b : α} {c d : β} : (a ≤ b → c ≤ d) ↔ (d < c → b < a) := ⟨lt_imp_lt_of_le_imp_le, le_imp_le_of_lt_imp_lt⟩ lemma lt_iff_lt_of_le_iff_le' {β} [preorder α] [preorder β] {a b : α} {c d : β} (H : a ≤ b ↔ c ≤ d) (H' : b ≤ a ↔ d ≤ c) : b < a ↔ d < c := lt_iff_le_not_le.trans $ (and_congr H' (not_congr H)).trans lt_iff_le_not_le.symm lemma lt_iff_lt_of_le_iff_le {β} [linear_order α] [linear_order β] {a b : α} {c d : β} (H : a ≤ b ↔ c ≤ d) : b < a ↔ d < c := not_le.symm.trans $ (not_congr H).trans $ not_le lemma le_iff_le_iff_lt_iff_lt {β} [linear_order α] [linear_order β] {a b : α} {c d : β} : (a ≤ b ↔ c ≤ d) ↔ (b < a ↔ d < c) := ⟨lt_iff_lt_of_le_iff_le, λ H, not_lt.symm.trans $ (not_congr H).trans $ not_lt⟩ lemma eq_of_forall_le_iff [partial_order α] {a b : α} (H : ∀ c, c ≤ a ↔ c ≤ b) : a = b := ((H _).1 le_rfl).antisymm ((H _).2 le_rfl) lemma le_of_forall_le [preorder α] {a b : α} (H : ∀ c, c ≤ a → c ≤ b) : a ≤ b := H _ le_rfl lemma le_of_forall_le' [preorder α] {a b : α} (H : ∀ c, a ≤ c → b ≤ c) : b ≤ a := H _ le_rfl lemma le_of_forall_lt [linear_order α] {a b : α} (H : ∀ c, c < a → c < b) : a ≤ b := le_of_not_lt $ λ h, lt_irrefl _ (H _ h) lemma forall_lt_iff_le [linear_order α] {a b : α} : (∀ ⦃c⦄, c < a → c < b) ↔ a ≤ b := ⟨le_of_forall_lt, λ h c hca, lt_of_lt_of_le hca h⟩ lemma le_of_forall_lt' [linear_order α] {a b : α} (H : ∀ c, a < c → b < c) : b ≤ a := le_of_not_lt $ λ h, lt_irrefl _ (H _ h) lemma forall_lt_iff_le' [linear_order α] {a b : α} : (∀ ⦃c⦄, a < c → b < c) ↔ b ≤ a := ⟨le_of_forall_lt', λ h c hac, lt_of_le_of_lt h hac⟩ lemma eq_of_forall_ge_iff [partial_order α] {a b : α} (H : ∀ c, a ≤ c ↔ b ≤ c) : a = b := ((H _).2 le_rfl).antisymm ((H _).1 le_rfl) /-- monotonicity of `≤` with respect to `→` -/ lemma le_implies_le_of_le_of_le {a b c d : α} [preorder α] (hca : c ≤ a) (hbd : b ≤ d) : a ≤ b → c ≤ d := λ hab, (hca.trans hab).trans hbd @[ext] lemma preorder.to_has_le_injective {α : Type*} : function.injective (@preorder.to_has_le α) := λ A B h, begin cases A, cases B, injection h with h_le, have : A_lt = B_lt, { funext a b, dsimp [(≤)] at A_lt_iff_le_not_le B_lt_iff_le_not_le h_le, simp [A_lt_iff_le_not_le, B_lt_iff_le_not_le, h_le], }, congr', end @[ext] lemma partial_order.to_preorder_injective {α : Type*} : function.injective (@partial_order.to_preorder α) := λ A B h, by { cases A, cases B, injection h, congr' } @[ext] lemma linear_order.to_partial_order_injective {α : Type*} : function.injective (@linear_order.to_partial_order α) := begin intros A B h, cases A, cases B, injection h, obtain rfl : A_le = B_le := ‹_›, obtain rfl : A_lt = B_lt := ‹_›, obtain rfl : A_decidable_le = B_decidable_le := subsingleton.elim _ _, obtain rfl : A_max = B_max := A_max_def.trans B_max_def.symm, obtain rfl : A_min = B_min := A_min_def.trans B_min_def.symm, congr end theorem preorder.ext {α} {A B : preorder α} (H : ∀ x y : α, (by haveI := A; exact x ≤ y) ↔ x ≤ y) : A = B := by { ext x y, exact H x y } theorem partial_order.ext {α} {A B : partial_order α} (H : ∀ x y : α, (by haveI := A; exact x ≤ y) ↔ x ≤ y) : A = B := by { ext x y, exact H x y } theorem linear_order.ext {α} {A B : linear_order α} (H : ∀ x y : α, (by haveI := A; exact x ≤ y) ↔ x ≤ y) : A = B := by { ext x y, exact H x y } /-- Given a relation `R` on `β` and a function `f : α → β`, the preimage relation on `α` is defined by `x ≤ y ↔ f x ≤ f y`. It is the unique relation on `α` making `f` a `rel_embedding` (assuming `f` is injective). -/ @[simp] def order.preimage {α β} (f : α → β) (s : β → β → Prop) (x y : α) : Prop := s (f x) (f y) infix ` ⁻¹'o `:80 := order.preimage /-- The preimage of a decidable order is decidable. -/ instance order.preimage.decidable {α β} (f : α → β) (s : β → β → Prop) [H : decidable_rel s] : decidable_rel (f ⁻¹'o s) := λ x y, H _ _ /-! ### Order dual -/ /-- Type synonym to equip a type with the dual order: `≤` means `≥` and `<` means `>`. -/ def order_dual (α : Type*) : Type* := α namespace order_dual instance (α : Type*) [h : nonempty α] : nonempty (order_dual α) := h instance (α : Type*) [h : subsingleton α] : subsingleton (order_dual α) := h instance (α : Type*) [has_le α] : has_le (order_dual α) := ⟨λ x y : α, y ≤ x⟩ instance (α : Type*) [has_lt α] : has_lt (order_dual α) := ⟨λ x y : α, y < x⟩ instance (α : Type*) [has_zero α] : has_zero (order_dual α) := ⟨(0 : α)⟩ -- `dual_le` and `dual_lt` should not be simp lemmas: -- they cause a loop since `α` and `order_dual α` are definitionally equal lemma dual_le [has_le α] {a b : α} : @has_le.le (order_dual α) _ a b ↔ @has_le.le α _ b a := iff.rfl lemma dual_lt [has_lt α] {a b : α} : @has_lt.lt (order_dual α) _ a b ↔ @has_lt.lt α _ b a := iff.rfl instance (α : Type*) [preorder α] : preorder (order_dual α) := { le_refl := le_refl, le_trans := λ a b c hab hbc, hbc.trans hab, lt_iff_le_not_le := λ _ _, lt_iff_le_not_le, .. order_dual.has_le α, .. order_dual.has_lt α } instance (α : Type*) [partial_order α] : partial_order (order_dual α) := { le_antisymm := λ a b hab hba, @le_antisymm α _ a b hba hab, .. order_dual.preorder α } instance (α : Type*) [linear_order α] : linear_order (order_dual α) := { le_total := λ a b : α, le_total b a, decidable_le := (infer_instance : decidable_rel (λ a b : α, b ≤ a)), decidable_lt := (infer_instance : decidable_rel (λ a b : α, b < a)), min := @max α _, max := @min α _, min_def := @linear_order.max_def α _, max_def := @linear_order.min_def α _, .. order_dual.partial_order α } instance : Π [inhabited α], inhabited (order_dual α) := id theorem preorder.dual_dual (α : Type*) [H : preorder α] : order_dual.preorder (order_dual α) = H := preorder.ext $ λ _ _, iff.rfl theorem partial_order.dual_dual (α : Type*) [H : partial_order α] : order_dual.partial_order (order_dual α) = H := partial_order.ext $ λ _ _, iff.rfl theorem linear_order.dual_dual (α : Type*) [H : linear_order α] : order_dual.linear_order (order_dual α) = H := linear_order.ext $ λ _ _, iff.rfl end order_dual /-! ### Order instances on the function space -/ instance pi.has_le {ι : Type u} {α : ι → Type v} [∀ i, has_le (α i)] : has_le (Π i, α i) := { le := λ x y, ∀ i, x i ≤ y i } lemma pi.le_def {ι : Type u} {α : ι → Type v} [∀ i, has_le (α i)] {x y : Π i, α i} : x ≤ y ↔ ∀ i, x i ≤ y i := iff.rfl instance pi.preorder {ι : Type u} {α : ι → Type v} [∀ i, preorder (α i)] : preorder (Π i, α i) := { le_refl := λ a i, le_refl (a i), le_trans := λ a b c h₁ h₂ i, le_trans (h₁ i) (h₂ i), ..pi.has_le } lemma pi.lt_def {ι : Type u} {α : ι → Type v} [∀ i, preorder (α i)] {x y : Π i, α i} : x < y ↔ x ≤ y ∧ ∃ i, x i < y i := by simp [lt_iff_le_not_le, pi.le_def] {contextual := tt} lemma le_update_iff {ι : Type u} {α : ι → Type v} [∀ i, preorder (α i)] [decidable_eq ι] {x y : Π i, α i} {i : ι} {a : α i} : x ≤ function.update y i a ↔ x i ≤ a ∧ ∀ j ≠ i, x j ≤ y j := function.forall_update_iff _ (λ j z, x j ≤ z) lemma update_le_iff {ι : Type u} {α : ι → Type v} [∀ i, preorder (α i)] [decidable_eq ι] {x y : Π i, α i} {i : ι} {a : α i} : function.update x i a ≤ y ↔ a ≤ y i ∧ ∀ j ≠ i, x j ≤ y j := function.forall_update_iff _ (λ j z, z ≤ y j) lemma update_le_update_iff {ι : Type u} {α : ι → Type v} [∀ i, preorder (α i)] [decidable_eq ι] {x y : Π i, α i} {i : ι} {a b : α i} : function.update x i a ≤ function.update y i b ↔ a ≤ b ∧ ∀ j ≠ i, x j ≤ y j := by simp [update_le_iff] {contextual := tt} instance pi.partial_order {ι : Type u} {α : ι → Type v} [∀ i, partial_order (α i)] : partial_order (Π i, α i) := { le_antisymm := λ f g h1 h2, funext (λ b, (h1 b).antisymm (h2 b)), ..pi.preorder } /-! ### Lifts of order instances -/ /-- Transfer a `preorder` on `β` to a `preorder` on `α` using a function `f : α → β`. See note [reducible non-instances]. -/ @[reducible] def preorder.lift {α β} [preorder β] (f : α → β) : preorder α := { le := λ x y, f x ≤ f y, le_refl := λ a, le_rfl, le_trans := λ a b c, le_trans, lt := λ x y, f x < f y, lt_iff_le_not_le := λ a b, lt_iff_le_not_le } /-- Transfer a `partial_order` on `β` to a `partial_order` on `α` using an injective function `f : α → β`. See note [reducible non-instances]. -/ @[reducible] def partial_order.lift {α β} [partial_order β] (f : α → β) (inj : injective f) : partial_order α := { le_antisymm := λ a b h₁ h₂, inj (h₁.antisymm h₂), .. preorder.lift f } /-- Transfer a `linear_order` on `β` to a `linear_order` on `α` using an injective function `f : α → β`. See note [reducible non-instances]. -/ @[reducible] def linear_order.lift {α β} [linear_order β] (f : α → β) (inj : injective f) : linear_order α := { le_total := λ x y, le_total (f x) (f y), decidable_le := λ x y, (infer_instance : decidable (f x ≤ f y)), decidable_lt := λ x y, (infer_instance : decidable (f x < f y)), decidable_eq := λ x y, decidable_of_iff _ inj.eq_iff, .. partial_order.lift f inj } instance subtype.preorder {α} [preorder α] (p : α → Prop) : preorder (subtype p) := preorder.lift (coe : subtype p → α) @[simp] lemma subtype.mk_le_mk {α} [preorder α] {p : α → Prop} {x y : α} {hx : p x} {hy : p y} : (⟨x, hx⟩ : subtype p) ≤ ⟨y, hy⟩ ↔ x ≤ y := iff.rfl @[simp] lemma subtype.mk_lt_mk {α} [preorder α] {p : α → Prop} {x y : α} {hx : p x} {hy : p y} : (⟨x, hx⟩ : subtype p) < ⟨y, hy⟩ ↔ x < y := iff.rfl @[simp, norm_cast] lemma subtype.coe_le_coe {α} [preorder α] {p : α → Prop} {x y : subtype p} : (x : α) ≤ y ↔ x ≤ y := iff.rfl @[simp, norm_cast] lemma subtype.coe_lt_coe {α} [preorder α] {p : α → Prop} {x y : subtype p} : (x : α) < y ↔ x < y := iff.rfl instance subtype.partial_order {α} [partial_order α] (p : α → Prop) : partial_order (subtype p) := partial_order.lift coe subtype.coe_injective /-- A subtype of a linear order is a linear order. We explicitly give the proof of decidable equality as the existing instance, in order to not have two instances of decidable equality that are not definitionally equal. -/ instance subtype.linear_order {α} [linear_order α] (p : α → Prop) : linear_order (subtype p) := { decidable_eq := subtype.decidable_eq, .. linear_order.lift coe subtype.coe_injective } /-! ### Pointwise order on `α × β` The lexicographic order is defined in `order.lexicographic`, and the instances are available via the type synonym `α ×ₗ β = α × β`. -/ namespace prod instance (α : Type u) (β : Type v) [has_le α] [has_le β] : has_le (α × β) := ⟨λ p q, p.1 ≤ q.1 ∧ p.2 ≤ q.2⟩ lemma le_def [has_le α] [has_le β] {x y : α × β} : x ≤ y ↔ x.1 ≤ y.1 ∧ x.2 ≤ y.2 := iff.rfl @[simp] lemma mk_le_mk [has_le α] [has_le β] {x₁ x₂ : α} {y₁ y₂ : β} : (x₁, y₁) ≤ (x₂, y₂) ↔ x₁ ≤ x₂ ∧ y₁ ≤ y₂ := iff.rfl instance (α : Type u) (β : Type v) [preorder α] [preorder β] : preorder (α × β) := { le_refl := λ ⟨a, b⟩, ⟨le_refl a, le_refl b⟩, le_trans := λ ⟨a, b⟩ ⟨c, d⟩ ⟨e, f⟩ ⟨hac, hbd⟩ ⟨hce, hdf⟩, ⟨le_trans hac hce, le_trans hbd hdf⟩, .. prod.has_le α β } lemma lt_iff [preorder α] [preorder β] {a b : α × β} : a < b ↔ a.1 < b.1 ∧ a.2 ≤ b.2 ∨ a.1 ≤ b.1 ∧ a.2 < b.2 := begin refine ⟨λ h, _, _⟩, { by_cases h₁ : b.1 ≤ a.1, { exact or.inr ⟨h.1.1, h.1.2.lt_of_not_le $ λ h₂, h.2 ⟨h₁, h₂⟩⟩ }, { exact or.inl ⟨h.1.1.lt_of_not_le h₁, h.1.2⟩ } }, { rintro (⟨h₁, h₂⟩ | ⟨h₁, h₂⟩), { exact ⟨⟨h₁.le, h₂⟩, λ h, h₁.not_le h.1⟩ }, { exact ⟨⟨h₁, h₂.le⟩, λ h, h₂.not_le h.2⟩ } } end @[simp] lemma mk_lt_mk [preorder α] [preorder β] {x₁ x₂ : α} {y₁ y₂ : β} : (x₁, y₁) < (x₂, y₂) ↔ x₁ < x₂ ∧ y₁ ≤ y₂ ∨ x₁ ≤ x₂ ∧ y₁ < y₂ := lt_iff /-- The pointwise partial order on a product. (The lexicographic ordering is defined in order/lexicographic.lean, and the instances are available via the type synonym `α ×ₗ β = α × β`.) -/ instance (α : Type u) (β : Type v) [partial_order α] [partial_order β] : partial_order (α × β) := { le_antisymm := λ ⟨a, b⟩ ⟨c, d⟩ ⟨hac, hbd⟩ ⟨hca, hdb⟩, prod.ext (hac.antisymm hca) (hbd.antisymm hdb), .. prod.preorder α β } end prod /-! ### Additional order classes -/ /-- An order is dense if there is an element between any pair of distinct elements. -/ class densely_ordered (α : Type u) [has_lt α] : Prop := (dense : ∀ a₁ a₂ : α, a₁ < a₂ → ∃ a, a₁ < a ∧ a < a₂) lemma exists_between [has_lt α] [densely_ordered α] : ∀ {a₁ a₂ : α}, a₁ < a₂ → ∃ a, a₁ < a ∧ a < a₂ := densely_ordered.dense instance order_dual.densely_ordered (α : Type u) [has_lt α] [densely_ordered α] : densely_ordered (order_dual α) := ⟨λ a₁ a₂ ha, (@exists_between α _ _ _ _ ha).imp $ λ a, and.symm⟩ lemma le_of_forall_le_of_dense [linear_order α] [densely_ordered α] {a₁ a₂ : α} (h : ∀ a, a₂ < a → a₁ ≤ a) : a₁ ≤ a₂ := le_of_not_gt $ λ ha, let ⟨a, ha₁, ha₂⟩ := exists_between ha in lt_irrefl a $ lt_of_lt_of_le ‹a < a₁› (h _ ‹a₂ < a›) lemma eq_of_le_of_forall_le_of_dense [linear_order α] [densely_ordered α] {a₁ a₂ : α} (h₁ : a₂ ≤ a₁) (h₂ : ∀ a, a₂ < a → a₁ ≤ a) : a₁ = a₂ := le_antisymm (le_of_forall_le_of_dense h₂) h₁ lemma le_of_forall_ge_of_dense [linear_order α] [densely_ordered α] {a₁ a₂ : α} (h : ∀ a₃ < a₁, a₃ ≤ a₂) : a₁ ≤ a₂ := le_of_not_gt $ λ ha, let ⟨a, ha₁, ha₂⟩ := exists_between ha in lt_irrefl a $ lt_of_le_of_lt (h _ ‹a < a₁›) ‹a₂ < a› lemma eq_of_le_of_forall_ge_of_dense [linear_order α] [densely_ordered α] {a₁ a₂ : α} (h₁ : a₂ ≤ a₁) (h₂ : ∀ a₃ < a₁, a₃ ≤ a₂) : a₁ = a₂ := (le_of_forall_ge_of_dense h₂).antisymm h₁ lemma dense_or_discrete [linear_order α] (a₁ a₂ : α) : (∃ a, a₁ < a ∧ a < a₂) ∨ ((∀ a, a₁ < a → a₂ ≤ a) ∧ (∀ a < a₂, a ≤ a₁)) := or_iff_not_imp_left.2 $ λ h, ⟨λ a ha₁, le_of_not_gt $ λ ha₂, h ⟨a, ha₁, ha₂⟩, λ a ha₂, le_of_not_gt $ λ ha₁, h ⟨a, ha₁, ha₂⟩⟩ variables {s : β → β → Prop} {t : γ → γ → Prop} /-! ### Linear order from a total partial order -/ /-- Type synonym to create an instance of `linear_order` from a `partial_order` and `is_total α (≤)` -/ def as_linear_order (α : Type u) := α instance {α} [inhabited α] : inhabited (as_linear_order α) := ⟨ (default : α) ⟩ noncomputable instance as_linear_order.linear_order {α} [partial_order α] [is_total α (≤)] : linear_order (as_linear_order α) := { le_total := @total_of α (≤) _, decidable_le := classical.dec_rel _, .. (_ : partial_order α) }
d5607cf05cb0add831fdc88cc2dd39a30f413549
7cef822f3b952965621309e88eadf618da0c8ae9
/test/linarith.lean
8586169385460df654d84aab8aa360d54f4e1ae7
[ "Apache-2.0" ]
permissive
rmitta/mathlib
8d90aee30b4db2b013e01f62c33f297d7e64a43d
883d974b608845bad30ae19e27e33c285200bf84
refs/heads/master
1,585,776,832,544
1,576,874,096,000
1,576,874,096,000
153,663,165
0
2
Apache-2.0
1,544,806,490,000
1,539,884,365,000
Lean
UTF-8
Lean
false
false
4,413
lean
import tactic.linarith example (e b c a v0 v1 : ℚ) (h1 : v0 = 5*a) (h2 : v1 = 3*b) (h3 : v0 + v1 + c = 10) : v0 + 5 + (v1 - 3) + (c - 2) = 10 := by linarith example (ε : ℚ) (h1 : ε > 0) : ε / 2 + ε / 3 + ε / 7 < ε := by linarith example (x y z : ℚ) (h1 : 2*x < 3*y) (h2 : -4*x + z/2 < 0) (h3 : 12*y - z < 0) : false := by linarith example (ε : ℚ) (h1 : ε > 0) : ε / 2 < ε := by linarith example (ε : ℚ) (h1 : ε > 0) : ε / 3 + ε / 3 + ε / 3 = ε := by linarith example (a b c : ℚ) (h2 : b + 2 > 3 + b) : false := by linarith {discharger := `[ring SOP]} example (a b c : ℚ) (h2 : b + 2 > 3 + b) : false := by linarith example (a b c : ℚ) (x y : ℤ) (h1 : x ≤ 3*y) (h2 : b + 2 > 3 + b) : false := by linarith {restrict_type := ℚ} example (g v V c h : ℚ) (h1 : h = 0) (h2 : v = V) (h3 : V > 0) (h4 : g > 0) (h5 : 0 ≤ c) (h6 : c < 1) : v ≤ V := by linarith example (x y z : ℚ) (h1 : 2*x + ((-3)*y) < 0) (h2 : (-4)*x + 2*z < 0) (h3 : 12*y + (-4)* z < 0) (h4 : nat.prime 7) : false := by linarith example (x y z : ℚ) (h1 : 2*1*x + (3)*(y*(-1)) < 0) (h2 : (-2)*x*2 < -(z + z)) (h3 : 12*y + (-4)* z < 0) (h4 : nat.prime 7) : false := by linarith example (x y z : ℤ) (h1 : 2*x < 3*y) (h2 : -4*x + 2*z < 0) (h3 : 12*y - 4* z < 0) : false := by linarith example (x y z : ℤ) (h1 : 2*x < 3*y) (h2 : -4*x + 2*z < 0) (h3 : x*y < 5) (h3 : 12*y - 4* z < 0) : false := by linarith example (x y z : ℤ) (h1 : 2*x < 3*y) (h2 : -4*x + 2*z < 0) (h3 : x*y < 5) : ¬ 12*y - 4* z < 0 := by linarith example (w x y z : ℤ) (h1 : 4*x + (-3)*y + 6*w ≤ 0) (h2 : (-1)*x < 0) (h3 : y < 0) (h4 : w ≥ 0) (h5 : nat.prime x.nat_abs) : false := by linarith example (a b c : ℚ) (h1 : a > 0) (h2 : b > 5) (h3 : c < -10) (h4 : a + b - c < 3) : false := by linarith example (a b c : ℚ) (h2 : b > 0) (h3 : ¬ b ≥ 0) : false := by linarith example (a b c : ℚ) (h2 : (2 : ℚ) > 3) : a + b - c ≥ 3 := by linarith {exfalso := ff} example (x : ℚ) (hx : x > 0) (h : x.num < 0) : false := by linarith [rat.num_pos_iff_pos.mpr hx, h] example (x : ℚ) (hx : x > 0) (h : x.num < 0) : false := by linarith only [rat.num_pos_iff_pos.mpr hx, h] example (x y z : ℚ) (hx : x ≤ 3*y) (h2 : y ≤ 2*z) (h3 : x ≥ 6*z) : x = 3*y := by linarith example (x y z : ℕ) (hx : x ≤ 3*y) (h2 : y ≤ 2*z) (h3 : x ≥ 6*z) : x = 3*y := by linarith example (x y z : ℚ) (hx : ¬ x > 3*y) (h2 : ¬ y > 2*z) (h3 : x ≥ 6*z) : x = 3*y := by linarith example (h1 : (1 : ℕ) < 1) : false := by linarith example (a b c : ℚ) (h2 : b > 0) (h3 : b < 0) : nat.prime 10 := by linarith example (a b c : ℕ) : a + b ≥ a := by linarith example (a b c : ℕ) : ¬ a + b < a := by linarith example (x y : ℚ) (h : 6 + ((x + 4) * x + (6 + 3 * y) * y) = 3) (h' : (x + 4) * x ≥ 0) (h'' : (6 + 3 * y) * y ≥ 0) : false := by linarith example (x y : ℕ) (h : 6 + ((x + 4) * x + (6 + 3 * y) * y) = 3) : false := by linarith example (a b i : ℕ) (h1 : ¬ a < i) (h2 : b < i) (h3 : a ≤ b) : false := by linarith example (n : ℕ) (h1 : n ≤ 3) (h2 : n > 2) : n = 3 := by linarith example (z : ℕ) (hz : ¬ z ≥ 2) (h2 : ¬ z + 1 ≤ 2) : false := by linarith example (z : ℕ) (hz : ¬ z ≥ 2) : z + 1 ≤ 2 := by linarith example (a b c : ℚ) (h1 : 1 / a < b) (h2 : b < c) : 1 / a < c := by linarith example (N : ℕ) (n : ℕ) (Hirrelevant : n > N) (A : ℚ) (l : ℚ) (h : A - l ≤ -(A - l)) (h_1 : ¬A ≤ -A) (h_2 : ¬l ≤ -l) (h_3 : -(A - l) < 1) : A < l + 1 := by linarith example (d : ℚ) (q n : ℕ) (h1 : ((q : ℚ) - 1)*n ≥ 0) (h2 : d = 2/3*(((q : ℚ) - 1)*n)) : d ≤ ((q : ℚ) - 1)*n := by linarith example (d : ℚ) (q n : ℕ) (h1 : ((q : ℚ) - 1)*n ≥ 0) (h2 : d = 2/3*(((q : ℚ) - 1)*n)) : ((q : ℚ) - 1)*n - d = 1/3 * (((q : ℚ) - 1)*n) := by linarith example (a : ℚ) (ha : 0 ≤ a) : 0 * 0 ≤ 2 * a := by linarith example (x : ℚ) : id x ≥ x := by success_if_fail {linarith}; linarith! example (x y z : ℚ) (hx : x < 5) (hx2 : x > 5) (hy : y < 5000000000) (hz : z > 34*y) : false := by linarith only [hx, hx2] example (x y z : ℚ) (hx : x < 5) (hy : y < 5000000000) (hz : z > 34*y) : x ≤ 5 := by linarith only [hx] example (x y : ℚ) (h : x < y) : x ≠ y := by linarith example (x y : ℚ) (h : x < y) : ¬ x = y := by linarith
587e2b5a6f6dace7f0e1cc461b3fb214a1af4aaa
367134ba5a65885e863bdc4507601606690974c1
/src/tactic/norm_cast.lean
3aefd8dc882bfc33c686ea0f54463a7a02608dce
[ "Apache-2.0" ]
permissive
kodyvajjha/mathlib
9bead00e90f68269a313f45f5561766cfd8d5cad
b98af5dd79e13a38d84438b850a2e8858ec21284
refs/heads/master
1,624,350,366,310
1,615,563,062,000
1,615,563,062,000
162,666,963
0
0
Apache-2.0
1,545,367,651,000
1,545,367,651,000
null
UTF-8
Lean
false
false
26,441
lean
/- Copyright (c) 2019 Paul-Nicolas Madelaine. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Paul-Nicolas Madelaine, Robert Y. Lewis Normalizing casts inside expressions. -/ import tactic.converter.interactive import tactic.hint /-! # A tactic for normalizing casts inside expressions This tactic normalizes casts inside expressions. It can be thought of as a call to the simplifier with a specific set of lemmas to move casts upwards in the expression. It has special handling of numerals and a simple heuristic to help moving casts "past" binary operators. Contrary to simp, it should be safe to use as a non-terminating tactic. The algorithm implemented here is described in the paper <https://lean-forward.github.io/norm_cast/norm_cast.pdf>. ## Important definitions * `tactic.interactive.norm_cast` * `tactic.interactive.push_cast` * `tactic.interactive.exact_mod_cast` * `tactic.interactive.apply_mod_cast` * `tactic.interactive.rw_mod_cast` * `tactic.interactive.assumption_mod_cast` -/ setup_tactic_parser namespace tactic /-- Runs `mk_instance` with a time limit. This is a work around to the fact that in some cases mk_instance times out instead of failing, for example: `has_lift_t ℤ ℕ` `mk_instance_fast` is used when we assume the type class search should end instantly. -/ meta def mk_instance_fast (e : expr) (timeout := 1000) : tactic expr := try_for timeout (mk_instance e) end tactic namespace norm_cast open tactic expr declare_trace norm_cast /-- Output a trace message if `trace.norm_cast` is enabled. -/ meta def trace_norm_cast {α} [has_to_tactic_format α] (msg : string) (a : α) : tactic unit := when_tracing `norm_cast $ do a ← pp a, trace ("[norm_cast] " ++ msg ++ a : format) mk_simp_attribute push_cast "The `push_cast` simp attribute uses `norm_cast` lemmas to move casts toward the leaf nodes of the expression." /-- `label` is a type used to classify `norm_cast` lemmas. * elim lemma: LHS has 0 head coes and ≥ 1 internal coe * move lemma: LHS has 1 head coe and 0 internal coes, RHS has 0 head coes and ≥ 1 internal coes * squash lemma: LHS has ≥ 1 head coes and 0 internal coes, RHS has fewer head coes -/ @[derive [decidable_eq, has_reflect, inhabited]] inductive label | elim : label | move : label | squash : label namespace label /-- Convert `label` into `string`. -/ protected def to_string : label → string | elim := "elim" | move := "move" | squash := "squash" instance : has_to_string label := ⟨label.to_string⟩ instance : has_repr label := ⟨label.to_string⟩ meta instance : has_to_format label := ⟨λ l, l.to_string⟩ /-- Convert `string` into `label`. -/ def of_string : string -> option label | "elim" := some elim | "move" := some move | "squash" := some squash | _ := none end label open label /-- Count how many coercions are at the top of the expression. -/ meta def count_head_coes : expr → ℕ | `(coe %%e) := count_head_coes e + 1 | `(coe_sort %%e) := count_head_coes e + 1 | `(coe_fn %%e) := count_head_coes e + 1 | _ := 0 /-- Count how many coercions are inside the expression, including the top ones. -/ meta def count_coes : expr → tactic ℕ | `(coe %%e) := (+1) <$> count_coes e | `(coe_sort %%e) := (+1) <$> count_coes e | `(coe_fn %%e) := (+1) <$> count_coes e | (app `(coe_fn %%e) x) := (+) <$> count_coes x <*> (+1) <$> count_coes e | (expr.lam n bi t e) := do l ← mk_local' n bi t, count_coes $ e.instantiate_var l | e := do as ← e.get_simp_args, list.sum <$> as.mmap count_coes /-- Count how many coercions are inside the expression, excluding the top ones. -/ private meta def count_internal_coes (e : expr) : tactic ℕ := do ncoes ← count_coes e, pure $ ncoes - count_head_coes e /-- Classifies a declaration of type `ty` as a `norm_cast` rule. -/ meta def classify_type (ty : expr) : tactic label := do (_, ty) ← open_pis ty, (lhs, rhs) ← match ty with | `(%%lhs = %%rhs) := pure (lhs, rhs) | `(%%lhs ↔ %%rhs) := pure (lhs, rhs) | _ := fail "norm_cast: lemma must be = or ↔" end, lhs_coes ← count_coes lhs, when (lhs_coes = 0) $ fail "norm_cast: badly shaped lemma, lhs must contain at least one coe", let lhs_head_coes := count_head_coes lhs, lhs_internal_coes ← count_internal_coes lhs, let rhs_head_coes := count_head_coes rhs, rhs_internal_coes ← count_internal_coes rhs, if lhs_head_coes = 0 then return elim else if lhs_head_coes = 1 then do when (rhs_head_coes ≠ 0) $ fail "norm_cast: badly shaped lemma, rhs can't start with coe", if rhs_internal_coes = 0 then return squash else return move else if rhs_head_coes < lhs_head_coes then do return squash else do fail "norm_cast: badly shaped shaped squash lemma, rhs must have fewer head coes than lhs" /-- The cache for `norm_cast` attribute stores three `simp_lemma` objects. -/ meta structure norm_cast_cache := (up : simp_lemmas) (down : simp_lemmas) (squash : simp_lemmas) /-- Empty `norm_cast_cache`. -/ meta def empty_cache : norm_cast_cache := { up := simp_lemmas.mk, down := simp_lemmas.mk, squash := simp_lemmas.mk, } meta instance : inhabited norm_cast_cache := ⟨empty_cache⟩ /-- `add_elim cache e` adds `e` as an `elim` lemma to `cache`. -/ meta def add_elim (cache : norm_cast_cache) (e : expr) : tactic norm_cast_cache := do new_up ← simp_lemmas.add cache.up e, return { up := new_up, down := cache.down, squash := cache.squash, } /-- `add_move cache e` adds `e` as a `move` lemma to `cache`. -/ meta def add_move (cache : norm_cast_cache) (e : expr) : tactic norm_cast_cache := do ty ← infer_type e, new_up ← cache.up.add e tt, new_down ← simp_lemmas.add cache.down e, return { up := new_up, down := new_down, squash := cache.squash, } /-- `add_squash cache e` adds `e` as an `squash` lemma to `cache`. -/ meta def add_squash (cache : norm_cast_cache) (e : expr) : tactic norm_cast_cache := do new_squash ← simp_lemmas.add cache.squash e, new_down ← simp_lemmas.add cache.down e, return { up := cache.up, down := new_down, squash := new_squash, } /-- The type of the `norm_cast` attribute. The optional label is used to overwrite the classifier. -/ meta def norm_cast_attr_ty : Type := user_attribute norm_cast_cache (option label) /-- Efficient getter for the `@[norm_cast]` attribute parameter that does not call `eval_expr`. See Note [user attribute parameters]. -/ meta def get_label_param (attr : norm_cast_attr_ty) (decl : name) : tactic (option label) := do p ← attr.get_param_untyped decl, match p with | `(none) := pure none | `(some label.elim) := pure label.elim | `(some label.move) := pure label.move | `(some label.squash) := pure label.squash | _ := fail p end /-- `add_lemma cache decl` infers the proper `norm_cast` attribute for `decl` and adds it to `cache`. -/ meta def add_lemma (attr : norm_cast_attr_ty) (cache : norm_cast_cache) (decl : name) : tactic norm_cast_cache := do e ← mk_const decl, param ← get_label_param attr decl, l ← param <|> (infer_type e >>= classify_type), match l with | elim := add_elim cache e | move := add_move cache e | squash := add_squash cache e end -- special lemmas to handle the ≥, > and ≠ operators private lemma ge_from_le {α} [has_le α] : ∀ (x y : α), x ≥ y ↔ y ≤ x := λ _ _, iff.rfl private lemma gt_from_lt {α} [has_lt α] : ∀ (x y : α), x > y ↔ y < x := λ _ _, iff.rfl private lemma ne_from_not_eq {α} : ∀ (x y : α), x ≠ y ↔ ¬(x = y) := λ _ _, iff.rfl /-- `mk_cache names` creates a `norm_cast_cache`. It infers the proper `norm_cast` attributes for names in `names`, and collects the lemmas attributed with specific `norm_cast` attributes. -/ meta def mk_cache (attr : thunk norm_cast_attr_ty) (names : list name) : tactic norm_cast_cache := do -- names has the declarations in reverse order cache ← names.mfoldr (λ name cache, add_lemma (attr ()) cache name) empty_cache, --some special lemmas to handle binary relations let up := cache.up, up ← up.add_simp ``ge_from_le, up ← up.add_simp ``gt_from_lt, up ← up.add_simp ``ne_from_not_eq, let down := cache.down, down ← down.add_simp ``coe_coe, pure { up := up, down := down, squash := cache.squash } /-- The `norm_cast` attribute. -/ @[user_attribute] meta def norm_cast_attr : user_attribute norm_cast_cache (option label) := { name := `norm_cast, descr := "attribute for norm_cast", parser := (do some l ← (label.of_string ∘ to_string) <$> ident, return l) <|> return none, after_set := some (λ decl prio persistent, do param ← get_label_param norm_cast_attr decl, match param with | some l := when (l ≠ elim) $ simp_attr.push_cast.set decl () tt | none := do e ← mk_const decl, ty ← infer_type e, l ← classify_type ty, norm_cast_attr.set decl l persistent prio end), before_unset := some $ λ _ _, tactic.skip, cache_cfg := { mk_cache := mk_cache norm_cast_attr, dependencies := [] } } /-- Classify a declaration as a `norm_cast` rule. -/ meta def make_guess (decl : name) : tactic label := do e ← mk_const decl, ty ← infer_type e, classify_type ty /-- Gets the `norm_cast` classification label for a declaration. Applies the override specified on the attribute, if necessary. -/ meta def get_label (decl : name) : tactic label := do param ← get_label_param norm_cast_attr decl, param <|> make_guess decl end norm_cast namespace tactic.interactive open norm_cast /-- `push_cast` rewrites the expression to move casts toward the leaf nodes. For example, `↑(a + b)` will be written to `↑a + ↑b`. Equivalent to `simp only with push_cast`. Can also be used at hypotheses. `push_cast` can also be used at hypotheses and with extra simp rules. ```lean example (a b : ℕ) (h1 : ((a + b : ℕ) : ℤ) = 10) (h2 : ((a + b + 0 : ℕ) : ℤ) = 10) : ((a + b : ℕ) : ℤ) = 10 := begin push_cast, push_cast at h1, push_cast [int.add_zero] at h2, end ``` -/ meta def push_cast (hs : parse tactic.simp_arg_list) (l : parse location) : tactic unit := tactic.interactive.simp none none tt hs [`push_cast] l end tactic.interactive namespace norm_cast open tactic expr /-- Prove `a = b` using the given simp set. -/ meta def prove_eq_using (s : simp_lemmas) (a b : expr) : tactic expr := do (a', a_a', _) ← simplify s [] a {fail_if_unchanged := ff}, (b', b_b', _) ← simplify s [] b {fail_if_unchanged := ff}, on_exception (trace_norm_cast "failed: " (to_expr ``(%%a' = %%b') >>= pp)) $ is_def_eq a' b' reducible, b'_b ← mk_eq_symm b_b', mk_eq_trans a_a' b'_b /-- Prove `a = b` by simplifying using move and squash lemmas. -/ meta def prove_eq_using_down (a b : expr) : tactic expr := do cache ← norm_cast_attr.get_cache, trace_norm_cast "proving: " (to_expr ``(%%a = %%b) >>= pp), prove_eq_using cache.down a b /-- This is the main heuristic used alongside the elim and move lemmas. The goal is to help casts move past operators by adding intermediate casts. An expression of the shape: op (↑(x : α) : γ) (↑(y : β) : γ) is rewritten to: op (↑(↑(x : α) : β) : γ) (↑(y : β) : γ) when (↑(↑(x : α) : β) : γ) = (↑(x : α) : γ) can be proven with a squash lemma -/ meta def splitting_procedure : expr → tactic (expr × expr) | (app (app op x) y) := (do `(@coe %%α %%δ %%coe1 %%xx) ← return x, `(@coe %%β %%γ %%coe2 %%yy) ← return y, success_if_fail $ is_def_eq α β, is_def_eq δ γ, (do coe3 ← mk_app `has_lift_t [α, β] >>= mk_instance_fast, new_x ← to_expr ``(@coe %%β %%δ %%coe2 (@coe %%α %%β %%coe3 %%xx)), let new_e := app (app op new_x) y, eq_x ← prove_eq_using_down x new_x, pr ← mk_congr_arg op eq_x, pr ← mk_congr_fun pr y, return (new_e, pr) ) <|> (do coe3 ← mk_app `has_lift_t [β, α] >>= mk_instance_fast, new_y ← to_expr ``(@coe %%α %%δ %%coe1 (@coe %%β %%α %%coe3 %%yy)), let new_e := app (app op x) new_y, eq_y ← prove_eq_using_down y new_y, pr ← mk_congr_arg (app op x) eq_y, return (new_e, pr) ) ) <|> (do `(@coe %%α %%β %%coe1 %%xx) ← return x, `(@has_one.one %%β %%h1) ← return y, h2 ← to_expr ``(has_one %%α) >>= mk_instance_fast, new_y ← to_expr ``(@coe %%α %%β %%coe1 (@has_one.one %%α %%h2)), eq_y ← prove_eq_using_down y new_y, let new_e := app (app op x) new_y, pr ← mk_congr_arg (app op x) eq_y, return (new_e, pr) ) <|> (do `(@coe %%α %%β %%coe1 %%xx) ← return x, `(@has_zero.zero %%β %%h1) ← return y, h2 ← to_expr ``(has_zero %%α) >>= mk_instance_fast, new_y ← to_expr ``(@coe %%α %%β %%coe1 (@has_zero.zero %%α %%h2)), eq_y ← prove_eq_using_down y new_y, let new_e := app (app op x) new_y, pr ← mk_congr_arg (app op x) eq_y, return (new_e, pr) ) <|> (do `(@has_one.one %%β %%h1) ← return x, `(@coe %%α %%β %%coe1 %%xx) ← return y, h1 ← to_expr ``(has_one %%α) >>= mk_instance_fast, new_x ← to_expr ``(@coe %%α %%β %%coe1 (@has_one.one %%α %%h1)), eq_x ← prove_eq_using_down x new_x, let new_e := app (app op new_x) y, pr ← mk_congr_arg (lam `x binder_info.default β (app (app op (var 0)) y)) eq_x, return (new_e, pr) ) <|> (do `(@has_zero.zero %%β %%h1) ← return x, `(@coe %%α %%β %%coe1 %%xx) ← return y, h1 ← to_expr ``(has_zero %%α) >>= mk_instance_fast, new_x ← to_expr ``(@coe %%α %%β %%coe1 (@has_zero.zero %%α %%h1)), eq_x ← prove_eq_using_down x new_x, let new_e := app (app op new_x) y, pr ← mk_congr_arg (lam `x binder_info.default β (app (app op (var 0)) y)) eq_x, return (new_e, pr) ) | _ := failed /-- Discharging function used during simplification in the "squash" step. TODO: norm_cast takes a list of expressions to use as lemmas for the discharger TODO: a tactic to print the results the discharger fails to proove -/ private meta def prove : tactic unit := assumption /-- Core rewriting function used in the "squash" step, which moves casts upwards and eliminates them. It tries to rewrite an expression using the elim and move lemmas. On failure, it calls the splitting procedure heuristic. -/ meta def upward_and_elim (s : simp_lemmas) (e : expr) : tactic (expr × expr) := (do r ← mcond (is_prop e) (return `iff) (return `eq), (new_e, pr) ← s.rewrite e prove r, pr ← match r with | `iff := mk_app `propext [pr] | _ := return pr end, return (new_e, pr) ) <|> splitting_procedure e /-! The following auxiliary functions are used to handle numerals. -/ /-- If possible, rewrite `(n : α)` to `((n : ℕ) : α)` where `n` is a numeral and `α ≠ ℕ`. Returns a pair of the new expression and proof that they are equal. -/ meta def numeral_to_coe (e : expr) : tactic (expr × expr) := do α ← infer_type e, success_if_fail $ is_def_eq α `(ℕ), n ← e.to_nat, h1 ← mk_app `has_lift_t [`(ℕ), α] >>= mk_instance_fast, let new_e : expr := reflect n, new_e ← to_expr ``(@coe ℕ %%α %%h1 %%new_e), pr ← prove_eq_using_down e new_e, return (new_e, pr) /-- If possible, rewrite `((n : ℕ) : α)` to `(n : α)` where `n` is a numeral. Returns a pair of the new expression and proof that they are equal. -/ meta def coe_to_numeral (e : expr) : tactic (expr × expr) := do `(@coe ℕ %%α %%h1 %%e') ← return e, n ← e'.to_nat, -- replace e' by normalized numeral is_def_eq (reflect n) e' reducible, let e := e.app_fn (reflect n), new_e ← expr.of_nat α n, pr ← prove_eq_using_down e new_e, return (new_e, pr) /-- A local variant on `simplify_top_down`. -/ private meta def simplify_top_down' {α} (a : α) (pre : α → expr → tactic (α × expr × expr)) (e : expr) (cfg : simp_config := {}) : tactic (α × expr × expr) := ext_simplify_core a cfg simp_lemmas.mk (λ _, failed) (λ a _ _ _ e, do (new_a, new_e, pr) ← pre a e, guard (¬ new_e =ₐ e), return (new_a, new_e, some pr, ff)) (λ _ _ _ _ _, failed) `eq e /-- The core simplification routine of `norm_cast`. -/ meta def derive (e : expr) : tactic (expr × expr) := do cache ← norm_cast_attr.get_cache, e ← instantiate_mvars e, let cfg : simp_config := { zeta := ff, beta := ff, eta := ff, proj := ff, iota := ff, iota_eqn := ff, fail_if_unchanged := ff }, let e0 := e, -- step 1: pre-processing of numerals ((), e1, pr1) ← simplify_top_down' () (λ _ e, prod.mk () <$> numeral_to_coe e) e0 cfg, trace_norm_cast "after numeral_to_coe: " e1, -- step 2: casts are moved upwards and eliminated ((), e2, pr2) ← simplify_bottom_up () (λ _ e, prod.mk () <$> upward_and_elim cache.up e) e1 cfg, trace_norm_cast "after upward_and_elim: " e2, -- step 3: casts are squashed (e3, pr3, _) ← simplify cache.squash [] e2 cfg, trace_norm_cast "after squashing: " e3, -- step 4: post-processing of numerals ((), e4, pr4) ← simplify_top_down' () (λ _ e, prod.mk () <$> coe_to_numeral e) e3 cfg, trace_norm_cast "after coe_to_numeral: " e4, let new_e := e4, guard (¬ new_e =ₐ e), pr ← mk_eq_trans pr1 pr2, pr ← mk_eq_trans pr pr3, pr ← mk_eq_trans pr pr4, return (new_e, pr) /-- A small variant of `push_cast` suited for non-interactive use. `derive_push_cast extra_lems e` returns an expression `e'` and a proof that `e = e'`. -/ meta def derive_push_cast (extra_lems : list simp_arg_type) (e : expr) : tactic (expr × expr) := do (s, _) ← mk_simp_set tt [`push_cast] extra_lems, (e, prf, _) ← simplify (s.erase [`int.coe_nat_succ]) [] e {fail_if_unchanged := ff}, return (e, prf) end norm_cast namespace tactic open expr norm_cast /-- `aux_mod_cast e` runs `norm_cast` on `e` and returns the result. If `include_goal` is true, it also normalizes the goal. -/ meta def aux_mod_cast (e : expr) (include_goal : bool := tt) : tactic expr := match e with | local_const _ lc _ _ := do e ← get_local lc, replace_at derive [e] include_goal, get_local lc | e := do t ← infer_type e, e ← assertv `this t e, replace_at derive [e] include_goal, get_local `this end /-- `exact_mod_cast e` runs `norm_cast` on the goal and `e`, and tries to use `e` to close the goal. -/ meta def exact_mod_cast (e : expr) : tactic unit := decorate_error "exact_mod_cast failed:" $ do new_e ← aux_mod_cast e, exact new_e /-- `apply_mod_cast e` runs `norm_cast` on the goal and `e`, and tries to apply `e`. -/ meta def apply_mod_cast (e : expr) : tactic (list (name × expr)) := decorate_error "apply_mod_cast failed:" $ do new_e ← aux_mod_cast e, apply new_e /-- `assumption_mod_cast` runs `norm_cast` on the goal. For each local hypothesis `h`, it also normalizes `h` and tries to use that to close the goal. -/ meta def assumption_mod_cast : tactic unit := decorate_error "assumption_mod_cast failed:" $ do let cfg : simp_config := { fail_if_unchanged := ff, canonize_instances := ff, canonize_proofs := ff, proj := ff }, replace_at derive [] tt, ctx ← local_context, try_lst $ ctx.map (λ h, aux_mod_cast h ff >>= tactic.exact) end tactic namespace tactic.interactive open tactic norm_cast /-- Normalize casts at the given locations by moving them "upwards". As opposed to simp, norm_cast can be used without necessarily closing the goal. -/ meta def norm_cast (loc : parse location) : tactic unit := do ns ← loc.get_locals, tt ← replace_at derive ns loc.include_goal | fail "norm_cast failed to simplify", when loc.include_goal $ try tactic.reflexivity, when loc.include_goal $ try tactic.triv, when (¬ ns.empty) $ try tactic.contradiction /-- Rewrite with the given rules and normalize casts between steps. -/ meta def rw_mod_cast (rs : parse rw_rules) (loc : parse location) : tactic unit := decorate_error "rw_mod_cast failed:" $ do let cfg_norm : simp_config := {}, let cfg_rw : rewrite_cfg := {}, ns ← loc.get_locals, monad.mapm' (λ r : rw_rule, do save_info r.pos, replace_at derive ns loc.include_goal, rw ⟨[r], none⟩ loc {} ) rs.rules, replace_at derive ns loc.include_goal, skip /-- Normalize the goal and the given expression, then close the goal with exact. -/ meta def exact_mod_cast (e : parse texpr) : tactic unit := do e ← i_to_expr e <|> do { ty ← target, e ← i_to_expr_strict ``(%%e : %%ty), pty ← pp ty, ptgt ← pp e, fail ("exact_mod_cast failed, expression type not directly " ++ "inferrable. Try:\n\nexact_mod_cast ...\nshow " ++ to_fmt pty ++ ",\nfrom " ++ ptgt : format) }, tactic.exact_mod_cast e /-- Normalize the goal and the given expression, then apply the expression to the goal. -/ meta def apply_mod_cast (e : parse texpr) : tactic unit := do e ← i_to_expr_for_apply e, concat_tags $ tactic.apply_mod_cast e /-- Normalize the goal and every expression in the local context, then close the goal with assumption. -/ meta def assumption_mod_cast : tactic unit := tactic.assumption_mod_cast end tactic.interactive namespace conv.interactive open conv open norm_cast (derive) /-- the converter version of `norm_cast' -/ meta def norm_cast : conv unit := replace_lhs derive end conv.interactive -- TODO: move this elsewhere? @[norm_cast] lemma ite_cast {α β} [has_lift_t α β] {c : Prop} [decidable c] {a b : α} : ↑(ite c a b) = ite c (↑a : β) (↑b : β) := by by_cases h : c; simp [h] @[norm_cast] lemma dite_cast {α β} [has_lift_t α β] {c : Prop} [decidable c] {a : c → α} {b : ¬ c → α} : ↑(dite c a b) = dite c (λ h, (↑(a h) : β)) (λ h, (↑(b h) : β)) := by by_cases h : c; simp [h] add_hint_tactic "norm_cast at *" /-- The `norm_cast` family of tactics is used to normalize casts inside expressions. It is basically a simp tactic with a specific set of lemmas to move casts upwards in the expression. Therefore it can be used more safely as a non-terminating tactic. It also has special handling of numerals. For instance, given an assumption ```lean a b : ℤ h : ↑a + ↑b < (10 : ℚ) ``` writing `norm_cast at h` will turn `h` into ```lean h : a + b < 10 ``` You can also use `exact_mod_cast`, `apply_mod_cast`, `rw_mod_cast` or `assumption_mod_cast`. Writing `exact_mod_cast h` and `apply_mod_cast h` will normalize the goal and `h` before using `exact h` or `apply h`. Writing `assumption_mod_cast` will normalize the goal and for every expression `h` in the context it will try to normalize `h` and use `exact h`. `rw_mod_cast` acts like the `rw` tactic but it applies `norm_cast` between steps. `push_cast` rewrites the expression to move casts toward the leaf nodes. This uses `norm_cast` lemmas in the forward direction. For example, `↑(a + b)` will be written to `↑a + ↑b`. It is equivalent to `simp only with push_cast`. It can also be used at hypotheses with `push_cast at h` and with extra simp lemmas with `push_cast [int.add_zero]`. ```lean example (a b : ℕ) (h1 : ((a + b : ℕ) : ℤ) = 10) (h2 : ((a + b + 0 : ℕ) : ℤ) = 10) : ((a + b : ℕ) : ℤ) = 10 := begin push_cast, push_cast at h1, push_cast [int.add_zero] at h2, end ``` The implementation and behavior of the `norm_cast` family is described in detail at <https://lean-forward.github.io/norm_cast/norm_cast.pdf>. -/ add_tactic_doc { name := "norm_cast", category := doc_category.tactic, decl_names := [``tactic.interactive.norm_cast, ``tactic.interactive.rw_mod_cast, ``tactic.interactive.apply_mod_cast, ``tactic.interactive.assumption_mod_cast, ``tactic.interactive.exact_mod_cast, ``tactic.interactive.push_cast], tags := ["coercions", "simplification"] } /-- The `norm_cast` attribute should be given to lemmas that describe the behaviour of a coercion in regard to an operator, a relation, or a particular function. It only concerns equality or iff lemmas involving `↑`, `⇑` and `↥`, describing the behavior of the coercion functions. It does not apply to the explicit functions that define the coercions. Examples: ```lean @[norm_cast] theorem coe_nat_inj' {m n : ℕ} : (↑m : ℤ) = ↑n ↔ m = n @[norm_cast] theorem coe_int_denom (n : ℤ) : (n : ℚ).denom = 1 @[norm_cast] theorem cast_id : ∀ n : ℚ, ↑n = n @[norm_cast] theorem coe_nat_add (m n : ℕ) : (↑(m + n) : ℤ) = ↑m + ↑n @[norm_cast] theorem cast_sub [add_group α] [has_one α] {m n} (h : m ≤ n) : ((n - m : ℕ) : α) = n - m @[norm_cast] theorem coe_nat_bit0 (n : ℕ) : (↑(bit0 n) : ℤ) = bit0 ↑n @[norm_cast] theorem cast_coe_nat (n : ℕ) : ((n : ℤ) : α) = n @[norm_cast] theorem cast_one : ((1 : ℚ) : α) = 1 ``` Lemmas tagged with `@[norm_cast]` are classified into three categories: `move`, `elim`, and `squash`. They are classified roughly as follows: * elim lemma: LHS has 0 head coes and ≥ 1 internal coe * move lemma: LHS has 1 head coe and 0 internal coes, RHS has 0 head coes and ≥ 1 internal coes * squash lemma: LHS has ≥ 1 head coes and 0 internal coes, RHS has fewer head coes `norm_cast` uses `move` and `elim` lemmas to factor coercions toward the root of an expression and to cancel them from both sides of an equation or relation. It uses `squash` lemmas to clean up the result. Occasionally you may want to override the automatic classification. You can do this by giving an optional `elim`, `move`, or `squash` parameter to the attribute. ```lean @[simp, norm_cast elim] lemma nat_cast_re (n : ℕ) : (n : ℂ).re = n := by rw [← of_real_nat_cast, of_real_re] ``` Don't do this unless you understand what you are doing. A full description of the tactic, and the use of each lemma category, can be found at <https://lean-forward.github.io/norm_cast/norm_cast.pdf>. -/ add_tactic_doc { name := "norm_cast attributes", category := doc_category.attr, decl_names := [``norm_cast.norm_cast_attr], tags := ["coercions", "simplification"] } -- Lemmas defined in core. attribute [norm_cast] int.nat_abs_of_nat int.coe_nat_sub int.coe_nat_mul int.coe_nat_zero int.coe_nat_one int.coe_nat_add -- Lemmas about nat.succ need to get a low priority, so that they are tried last. -- This is because `nat.succ _` matches `1`, `3`, `x+1`, etc. -- Rewriting would then produce really wrong terms. attribute [norm_cast, priority 500] int.coe_nat_succ
0de284b10fc879326350f6d61cbf6c8c788071c9
31f556cdeb9239ffc2fad8f905e33987ff4feab9
/src/Lean/Compiler/LCNF/Simp/SimpM.lean
a067ea300d1a13c015645e2d609ae1d213250b46
[ "Apache-2.0", "LLVM-exception", "NCSA", "LGPL-3.0-only", "LicenseRef-scancode-inner-net-2.0", "BSD-3-Clause", "LGPL-2.0-or-later", "Spencer-94", "LGPL-2.1-or-later", "HPND", "LicenseRef-scancode-pcre", "ISC", "LGPL-2.1-only", "LicenseRef-scancode-other-permissive", "SunPro", "CMU-Mach"...
permissive
tobiasgrosser/lean4
ce0fd9cca0feba1100656679bf41f0bffdbabb71
ebdbdc10436a4d9d6b66acf78aae7a23f5bd073f
refs/heads/master
1,673,103,412,948
1,664,930,501,000
1,664,930,501,000
186,870,185
0
0
Apache-2.0
1,665,129,237,000
1,557,939,901,000
Lean
UTF-8
Lean
false
false
9,646
lean
/- Copyright (c) 2022 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura -/ import Lean.Compiler.ImplementedByAttr import Lean.Compiler.LCNF.Renaming import Lean.Compiler.LCNF.ElimDead import Lean.Compiler.LCNF.AlphaEqv import Lean.Compiler.LCNF.PrettyPrinter import Lean.Compiler.LCNF.Bind import Lean.Compiler.LCNF.Internalize import Lean.Compiler.LCNF.Simp.JpCases import Lean.Compiler.LCNF.Simp.DiscrM import Lean.Compiler.LCNF.Simp.FunDeclInfo import Lean.Compiler.LCNF.Simp.Config namespace Lean.Compiler.LCNF namespace Simp structure Context where /-- Name of the declaration being simplified. We currently use this information because we are generating phase1 declarations on demand, and it may trigger non-termination when trying to access the phase1 declaration. -/ declName : Name config : Config := {} /-- Stack of global declarations being recursively inlined. -/ inlineStack : List Name := [] /-- Mapping from declaration names to number of occurrences at `inlineStack` -/ inlineStackOccs : PHashMap Name Nat := {} structure State where /-- Free variable substitution. We use it to implement inlining and removing redundant variables `let _x.i := _x.j` -/ subst : FVarSubst := {} /-- Track used local declarations to be able to eliminate dead variables. -/ used : UsedLocalDecls := {} /-- Mapping containing free variables ids that need to be renamed (i.e., the `binderName`). We use this map to preserve user provide names. -/ binderRenaming : Renaming := {} /-- Mapping used to decide whether a local function declaration must be inlined or not. -/ funDeclInfoMap : FunDeclInfoMap := {} /-- `true` if some simplification was performed in the current simplification pass. -/ simplified : Bool := false /-- Number of visited `let-declarations` and terminal values. This is a performance counter, and currently has no impact on code generation. -/ visited : Nat := 0 /-- Number of definitions inlined. This is a performance counter. -/ inline : Nat := 0 /-- Number of local functions inlined. This is a performance counter. -/ inlineLocal : Nat := 0 abbrev SimpM := ReaderT Context $ StateRefT State DiscrM instance : MonadFVarSubst SimpM false where getSubst := return (← get).subst instance : MonadFVarSubstState SimpM where modifySubst f := modify fun s => { s with subst := f s.subst } /-- Set the `simplified` flag to `true`. -/ def markSimplified : SimpM Unit := modify fun s => { s with simplified := true } /-- Increment `visited` performance counter. -/ def incVisited : SimpM Unit := modify fun s => { s with visited := s.visited + 1 } /-- Increment `inline` performance counter. It is the number of inlined global declarations. -/ def incInline : SimpM Unit := modify fun s => { s with inline := s.inline + 1 } /-- Increment `inlineLocal` performance counter. It is the number of inlined local function and join point declarations. -/ def incInlineLocal : SimpM Unit := modify fun s => { s with inlineLocal := s.inlineLocal + 1 } /-- Mark the local function declaration or join point with the given id as a "must inline". -/ def addMustInline (fvarId : FVarId) : SimpM Unit := modify fun s => { s with funDeclInfoMap := s.funDeclInfoMap.addMustInline fvarId } /-- Add a new occurrence of local function `fvarId`. -/ def addFunOcc (fvarId : FVarId) : SimpM Unit := modify fun s => { s with funDeclInfoMap := s.funDeclInfoMap.add fvarId } /-- Add a new occurrence of local function `fvarId` in argument position . -/ def addFunHoOcc (fvarId : FVarId) : SimpM Unit := modify fun s => { s with funDeclInfoMap := s.funDeclInfoMap.addHo fvarId } @[inheritDoc FunDeclInfoMap.update] partial def updateFunDeclInfo (code : Code) (mustInline := false) : SimpM Unit := do let map ← modifyGet fun s => (s.funDeclInfoMap, { s with funDeclInfoMap := {} }) let map ← map.update code mustInline modify fun s => { s with funDeclInfoMap := map } /-- Execute `x` with an updated `inlineStack`. If `value` is of the form `const ...`, add `const` to the stack. Otherwise, do not change the `inlineStack`. -/ def withInlining (value : Expr) (recursive : Bool) (x : SimpM α) : SimpM α := do let f := value.getAppFn if let .const declName _ := f then trace[Compiler.simp.inline] "{declName}" let numOccs := (← read).inlineStackOccs.find? declName |>.getD 0 let numOccs := numOccs + 1 if recursive && hasInlineIfReduceAttribute (← getEnv) declName && numOccs > (← getConfig).maxRecInlineIfReduce then throwError "function `{declName}` has been recursively inlined more than #{(← getConfig).maxRecInlineIfReduce}, consider removing the attribute `[inlineIfReduce]` from this declaration or increasing the limit using `set_option compiler.maxRecInlineIfReduce <num>`" withReader (fun ctx => { ctx with inlineStack := declName :: ctx.inlineStack, inlineStackOccs := ctx.inlineStackOccs.insert declName numOccs }) x else x /-- Similar to the default `Lean.withIncRecDepth`, but include the `inlineStack` in the error messsage. -/ @[inline] def withIncRecDepth (x : SimpM α) : SimpM α := do let curr ← MonadRecDepth.getRecDepth let max ← MonadRecDepth.getMaxRecDepth if curr == max then throwMaxRecDepth else MonadRecDepth.withRecDepth (curr+1) x where throwMaxRecDepth : SimpM α := do match (← read).inlineStack with | [] => throwError maxRecDepthErrorMessage | declName :: stack => let mut fmt := f!"{declName}\n" let mut prev := declName let mut ellipsis := false for declName in stack do if prev == declName then unless ellipsis do ellipsis := true fmt := fmt ++ "...\n" else fmt := fmt ++ f!"{declName}\n" prev := declName ellipsis := false throwError "maximum recursion depth reached in the code generator\nfunction inline stack:\n{fmt}" /-- Execute `x` with `fvarId` set as `mustInline`. After execution the original setting is restored. -/ def withAddMustInline (fvarId : FVarId) (x : SimpM α) : SimpM α := do let saved? := (← get).funDeclInfoMap.map.find? fvarId try addMustInline fvarId x finally modify fun s => { s with funDeclInfoMap := s.funDeclInfoMap.restore fvarId saved? } /-- Return true if the given local function declaration or join point id is marked as `once` or `mustInline`. We use this information to decide whether to inline them. -/ def isOnceOrMustInline (fvarId : FVarId) : SimpM Bool := do match (← get).funDeclInfoMap.map.find? fvarId with | some .once | some .mustInline => return true | _ => return false /-- Return `true` if the given code is considered "small". -/ def isSmall (code : Code) : SimpM Bool := return code.sizeLe (← getConfig).smallThreshold /-- Return `true` if the given local function declaration should be inlined. -/ def shouldInlineLocal (decl : FunDecl) : SimpM Bool := do if (← isOnceOrMustInline decl.fvarId) then return true else isSmall decl.value /-- LCNF "Beta-reduce". The equivalent of `(fun params => code) args`. If `mustInline` is true, the local function declarations in the resulting code are marked as `.mustInline`. See comment at `updateFunDeclInfo`. -/ def betaReduce (params : Array Param) (code : Code) (args : Array Expr) (mustInline := false) : SimpM Code := do let mut subst := {} let mut castDecls := #[] for param in params, arg in args do /- If `param` hast type `⊤` but `arg` does not, we must insert a cast. Otherwise, the resulting code may be type incorrect. For example, the following code is type correct before inlining `f` because `x : ⊤`. ``` def foo (g : A → A) (a : B) := fun f (x : ⊤) := let _x.1 := g x ... let _x.2 := f a ... ``` We must introduce a cast around `a` to make sure the resulting expression is type correct. -/ if param.type.isAnyType && !(← inferType arg).isAnyType then let castArg ← mkLcCast arg anyTypeExpr let castDecl ← mkAuxLetDecl castArg castDecls := castDecls.push (CodeDecl.let castDecl) subst := subst.insert param.fvarId (.fvar castDecl.fvarId) else subst := subst.insert param.fvarId arg let code ← code.internalize subst let code := LCNF.attachCodeDecls castDecls code updateFunDeclInfo code mustInline return code /-- Erase the given let-declaration from the local context, and set the `simplified` flag to true. -/ def eraseLetDecl (decl : LetDecl) : SimpM Unit := do LCNF.eraseLetDecl decl markSimplified /-- Erase the given local function declaration from the local context, and set the `simplified` flag to true. -/ def eraseFunDecl (decl : FunDecl) : SimpM Unit := do LCNF.eraseFunDecl decl markSimplified /-- Similar to `LCNF.addFVarSubst`. That is, add the entry `fvarId ↦ fvarId'` to the free variable substitution. If `fvarId` has a non-internal binder name `n`, but `fvarId'` does not, this method also adds the entry `fvarId' ↦ n` to the `binderRenaming` map. The goal is to preserve user provided names. -/ def addFVarSubst (fvarId : FVarId) (fvarId' : FVarId) : SimpM Unit := do LCNF.addFVarSubst fvarId fvarId' let binderName ← getBinderName fvarId unless binderName.isInternal do let binderName' ← getBinderName fvarId' if binderName'.isInternal then modify fun s => { s with binderRenaming := s.binderRenaming.insert fvarId' binderName }
83fdb9d21d1504b7c85211dd190c8ef79dc404eb
74addaa0e41490cbaf2abd313a764c96df57b05d
/Mathlib/Lean3Lib/data/dlist.lean
a07d447f132b24d88d705fd2d140c51e66c638ad
[]
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
2,427
lean
/- Copyright (c) 2017 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Leonardo de Moura -/ import Mathlib.PrePort import Mathlib.Lean3Lib.init.default universes u l namespace Mathlib /-- A difference list is a function that, given a list, returns the original contents of the difference list prepended to the given list. This structure supports `O(1)` `append` and `concat` operations on lists, making it useful for append-heavy uses such as logging and pretty printing. -/ structure dlist (α : Type u) where apply : List α → List α invariant : ∀ (l : List α), apply l = apply [] ++ l namespace dlist /-- Convert a list to a dlist -/ def of_list {α : Type u} (l : List α) : dlist α := mk (append l) sorry /-- Convert a lazily-evaluated list to a dlist -/ def lazy_of_list {α : Type u} (l : thunk (List α)) : dlist α := mk (fun (xs : List α) => l Unit.unit ++ xs) sorry /-- Convert a dlist to a list -/ def to_list {α : Type u} : dlist α → List α := sorry /-- Create a dlist containing no elements -/ def empty {α : Type u} : dlist α := mk id sorry /-- Create dlist with a single element -/ def singleton {α : Type u} (x : α) : dlist α := mk (List.cons x) sorry /-- `O(1)` Prepend a single element to a dlist -/ def cons {α : Type u} (x : α) : dlist α → dlist α := sorry /-- `O(1)` Append a single element to a dlist -/ def concat {α : Type u} (x : α) : dlist α → dlist α := sorry /-- `O(1)` Append dlists -/ protected def append {α : Type u} : dlist α → dlist α → dlist α := sorry protected instance has_append {α : Type u} : Append (dlist α) := { append := dlist.append } theorem to_list_of_list {α : Type u} (l : List α) : to_list (of_list l) = l := sorry theorem of_list_to_list {α : Type u} (l : dlist α) : of_list (to_list l) = l := sorry theorem to_list_empty {α : Type u} : to_list empty = [] := sorry theorem to_list_singleton {α : Type u} (x : α) : to_list (singleton x) = [x] := sorry theorem to_list_append {α : Type u} (l₁ : dlist α) (l₂ : dlist α) : to_list (l₁ ++ l₂) = to_list l₁ ++ to_list l₂ := sorry theorem to_list_cons {α : Type u} (x : α) (l : dlist α) : to_list (cons x l) = x :: to_list l := sorry theorem to_list_concat {α : Type u} (x : α) (l : dlist α) : to_list (concat x l) = to_list l ++ [x] := sorry
a58a4fb3b39cf635c63deef3f6a28baf4c2af7d0
5d76f062116fa5bd22eda20d6fd74da58dba65bb
/src/snarks/pinocchio/vars.lean
d9dc3b5dfa75fed216917a4aa8a867550c015b62
[]
no_license
brando90/formal_baby_snark
59e4732dfb43f97776a3643f2731262f58d2bb81
4732da237784bd461ff949729cc011db83917907
refs/heads/master
1,682,650,246,414
1,621,103,975,000
1,621,103,975,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
271
lean
section /-- An inductive type from which to index the variables of the 3-variable polynomials the proof manages -/ @[derive decidable_eq] inductive vars : Type | r_v : vars | r_w : vars | s : vars | α_v : vars | α_w : vars | α_y : vars | β : vars | γ : vars end
41d7fbba4a69dd18a363f62f23cf450bf85aa996
e00ea76a720126cf9f6d732ad6216b5b824d20a7
/src/tactic/push_neg.lean
d29c01defda63cef4c1f89d6a08df1ca18e363a5
[ "Apache-2.0" ]
permissive
vaibhavkarve/mathlib
a574aaf68c0a431a47fa82ce0637f0f769826bfe
17f8340912468f49bdc30acdb9a9fa02eeb0473a
refs/heads/master
1,621,263,802,637
1,585,399,588,000
1,585,399,588,000
250,833,447
0
0
Apache-2.0
1,585,410,341,000
1,585,410,341,000
null
UTF-8
Lean
false
false
7,974
lean
/- Copyright (c) 2019 Patrick Massot All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Patrick Massot, Simon Hudon A tactic pushing negations into an expression -/ import tactic.interactive import algebra.order open tactic expr namespace push_neg section universe u variable {α : Sort u} variables (p q : Prop) variable (s : α → Prop) local attribute [instance, priority 10] classical.prop_decidable theorem not_not_eq : (¬ ¬ p) = p := propext not_not theorem not_and_eq : (¬ (p ∧ q)) = (¬ p ∨ ¬ q) := propext not_and_distrib theorem not_or_eq : (¬ (p ∨ q)) = (¬ p ∧ ¬ q) := propext not_or_distrib theorem not_forall_eq : (¬ ∀ x, s x) = (∃ x, ¬ s x) := propext not_forall theorem not_exists_eq : (¬ ∃ x, s x) = (∀ x, ¬ s x) := propext not_exists theorem not_implies_eq : (¬ (p → q)) = (p ∧ ¬ q) := propext not_imp theorem classical.implies_iff_not_or : (p → q) ↔ (¬ p ∨ q) := imp_iff_not_or theorem not_eq (a b : α) : (¬ a = b) ↔ (a ≠ b) := iff.rfl variable {β : Type u} variable [linear_order β] theorem not_le_eq (a b : β) : (¬ (a ≤ b)) = (b < a) := propext not_le theorem not_lt_eq (a b : β) : (¬ (a < b)) = (b ≤ a) := propext not_lt end meta def whnf_reducible (e : expr) : tactic expr := whnf e reducible private meta def transform_negation_step (e : expr) : tactic (option (expr × expr)) := do e ← whnf_reducible e, match e with | `(¬ %%ne) := (do ne ← whnf_reducible ne, match ne with | `(¬ %%a) := do pr ← mk_app ``not_not_eq [a], return (some (a, pr)) | `(%%a ∧ %%b) := do pr ← mk_app ``not_and_eq [a, b], return (some (`(¬ %%a ∨ ¬ %%b), pr)) | `(%%a ∨ %%b) := do pr ← mk_app ``not_or_eq [a, b], return (some (`(¬ %%a ∧ ¬ %%b), pr)) | `(%%a ≤ %%b) := do e ← to_expr ``(%%b < %%a), pr ← mk_app ``not_le_eq [a, b], return (some (e, pr)) | `(%%a < %%b) := do e ← to_expr ``(%%b ≤ %%a), pr ← mk_app ``not_lt_eq [a, b], return (some (e, pr)) | `(Exists %%p) := do pr ← mk_app ``not_exists_eq [p], e ← match p with | (lam n bi typ bo) := do body ← mk_app ``not [bo], return (pi n bi typ body) | _ := tactic.fail "Unexpected failure negating ∃" end, return (some (e, pr)) | (pi n bi d p) := if p.has_var then do pr ← mk_app ``not_forall_eq [lam n bi d p], body ← mk_app ``not [p], e ← mk_app ``Exists [lam n bi d body], return (some (e, pr)) else do pr ← mk_app ``not_implies_eq [d, p], `(%%_ = %%e') ← infer_type pr, return (some (e', pr)) | _ := return none end) | _ := return none end private meta def transform_negation : expr → tactic (option (expr × expr)) | e := do (some (e', pr)) ← transform_negation_step e | return none, (some (e'', pr')) ← transform_negation e' | return (some (e', pr)), pr'' ← mk_eq_trans pr pr', return (some (e'', pr'')) meta def normalize_negations (t : expr) : tactic (expr × expr) := do (_, e, pr) ← simplify_top_down () (λ _, λ e, do oepr ← transform_negation e, match oepr with | (some (e', pr)) := return ((), e', pr) | none := do pr ← mk_eq_refl e, return ((), e, pr) end) t { eta := ff }, return (e, pr) meta def push_neg_at_hyp (h : name) : tactic unit := do H ← get_local h, t ← infer_type H, (e, pr) ← normalize_negations t, replace_hyp H e pr, skip meta def push_neg_at_goal : tactic unit := do H ← target, (e, pr) ← normalize_negations H, replace_target e pr end push_neg open interactive (parse loc.ns loc.wildcard) open interactive.types (location texpr) open lean.parser (tk ident many) interactive.loc local postfix `?`:9001 := optional local postfix *:9001 := many open push_neg /-- Push negations in the goal of some assumption. For instance, a hypothesis `h : ¬ ∀ x, ∃ y, x ≤ y` will be transformed by `push_neg at h` into `h : ∃ x, ∀ y, y < x`. Variables names are conserved. This tactic pushes negations inside expressions. For instance, given an assumption ```lean h : ¬ ∀ ε > 0, ∃ δ > 0, ∀ x, |x - x₀| ≤ δ → |f x - y₀| ≤ ε) ``` writing `push_neg at h` will turn `h` into ```lean h : ∃ ε, ε > 0 ∧ ∀ δ, δ > 0 → (∃ x, |x - x₀| ≤ δ ∧ ε < |f x - y₀|), ``` (the pretty printer does *not* use the abreviations `∀ δ > 0` and `∃ ε > 0` but this issue has nothing to do with `push_neg`). Note that names are conserved by this tactic, contrary to what would happen with `simp` using the relevant lemmas. One can also use this tactic at the goal using `push_neg`, at every assumption and the goal using `push_neg at *` or at selected assumptions and the goal using say `push_neg at h h' ⊢` as usual. -/ meta def tactic.interactive.push_neg : parse location → tactic unit | (loc.ns loc_l) := loc_l.mmap' (λ l, match l with | some h := do push_neg_at_hyp h, try `[simp only [push_neg.not_eq] at h { eta := ff }] | none := do push_neg_at_goal, try `[simp only [push_neg.not_eq] { eta := ff }] end) | loc.wildcard := do push_neg_at_goal, local_context >>= mmap' (λ h, push_neg_at_hyp (local_pp_name h)) , try `[simp only [push_neg.not_eq] at * { eta := ff }] add_tactic_doc { name := "push_neg", category := doc_category.tactic, decl_names := [`tactic.interactive.push_neg], tags := ["logic"] } lemma imp_of_not_imp_not (P Q : Prop) [decidable Q] : (¬ Q → ¬ P) → (P → Q) := λ h hP, by_contradiction (λ h', h h' hP) /-- Matches either an identifier "h" or a pair of identifiers "h with k" -/ meta def name_with_opt : lean.parser (name × option name) := prod.mk <$> ident <*> (some <$> (tk "with" >> ident) <|> return none) /-- Transforms the goal into its contrapositive. * `contrapose` turns a goal `P → Q` into `¬ Q → ¬ P` * `contrapose!` turns a goal `P → Q` into `¬ Q → ¬ P` and pushes negations inside `P` and `Q` using `push_neg` * `contrapose h` first reverts the local assumption `h`, and then uses `contrapose` and `intro h` * `contrapose! h` first reverts the local assumption `h`, and then uses `contrapose!` and `intro h` * `contrapose h with new_h` uses the name `new_h` for the introduced hypothesis -/ meta def tactic.interactive.contrapose (push : parse (tk "!" )?) : parse name_with_opt? → tactic unit | (some (h, h')) := get_local h >>= revert >> tactic.interactive.contrapose none >> intro (h'.get_or_else h) >> skip | none := do `(%%P → %%Q) ← target | fail "The goal is not an implication, and you didn't specify an assumption", cp ← mk_mapp `imp_of_not_imp_not [P, Q, none] <|> fail "contrapose only applies to nondependent arrows between decidable props", apply cp, when push.is_some $ try (tactic.interactive.push_neg (loc.ns [none])) add_tactic_doc { name := "contrapose", category := doc_category.tactic, decl_names := [`tactic.interactive.contrapose], tags := ["logic"] }
c225f8a08eb2cf447523a12a7ab4224844bd98fb
82b86ba2ae0d5aed0f01f49c46db5afec0eb2bd7
/tests/lean/run/frontend1.lean
d7aa814e931e878cdecc467aca208776646feb92
[ "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
7,156
lean
#lang lean4 import Lean.Elab open Lean open Lean.Elab def runM (input : String) (failIff : Bool := true) : CoreM Unit := do let env ← getEnv; let opts ← getOptions; let (env, messages) ← liftIO $ process input env opts; messages.forM $ fun msg => (liftIO msg.toString) >>= IO.println; when (failIff && messages.hasErrors) $ throwError "errors have been found"; when (!failIff && !messages.hasErrors) $ throwError "there are no errors"; pure () def fail (input : String) : CoreM Unit := runM input false def M := IO Unit def zero := 0 def one := 1 def two := 2 def hello : String := "hello" def act1 : IO String := pure "hello" #eval runM "#check @Add.add" #eval runM "#check [zero, one, two]" #eval runM "#check id $ Nat.succ one" #eval runM "#check Add.add one two" #eval runM "#check one + two > one ∧ True" #eval runM "#check act1 >>= IO.println" #eval runM "#check one + two == one" #eval fail "#check one + one + hello == hello ++ one" #eval runM "#check Nat.add one $ Nat.add one two" #eval runM "universe u universe v export ToString (toString) section namespace foo.bla end bla end foo variable (p q : Prop) variable (_ b : _) variable {α : Type} variable {m : Type → Type} variable [Monad m] #check m #check Type #check Prop #check toString zero #check id Nat.zero (α := Nat) #check id _ (α := Nat) #check id Nat.zero #check id (α := Nat) #check @id Nat #check p #check α #check Nat.succ #check Nat.add #check id #check forall (α : Type), α → α #check (α : Type) → α → α #check {α : Type} → {β : Type} → M → (α → β) → α → β #check () end" structure S1 := (x y : Nat := 0) structure S2 extends S1 := (z : Nat := 0) def fD {α} [ToString α] (a b : α) : String := toString a ++ toString b structure S3 := (w : Nat := 0) (f : forall {α : Type} [ToString α], α → α → String := @fD) structure S4 extends S2, S3 := (s : Nat := 0) def s4 : S4 := {} structure S (α : Type) := (field1 : S4 := {}) (field2 : S4 × S4 := ({}, {})) (field3 : α) (field4 : List α × Nat := ([], 0)) (vec : Array (α × α) := #[]) (map : Std.HashMap String α := {}) inductive D (α : Type) | mk (a : α) (s : S4) : D α def s : S Nat := { field3 := 0 } def d : D Nat := D.mk 10 {} def i : Nat := 10 def k : String := "hello" universes u class Monoid (α : Type u) := (one : α) (mul : α → α → α) def m : Monoid Nat := { one := 1, mul := Nat.mul } def f (x y z : Nat) : Nat := x + y + z #eval runM "#check s4.x" #eval runM "#check s.field1.x" #eval runM "#check s.field2.fst" #eval runM "#check s.field2.fst.w" #eval runM "#check s.1.x" #eval runM "#check s.2.1.x" #eval runM "#check d.1" #eval runM "#check d.2.x" #eval runM "#check s4.f s4.x" #eval runM "#check m.mul m.one" #eval runM "#check s.field4.1.length.succ" #eval runM "#check s.field4.1.map Nat.succ" #eval runM "#check s.vec[i].1" #eval runM "#check \"hello\"" #eval runM "#check 1" #eval runM "#check Nat.succ 1" #eval runM "#check fun _ a (x y : Int) => x + y + a" #eval runM "#check (one)" #eval runM "#check ()" #eval runM "#check (one, two, zero)" #eval runM "#check (one, two, zero)" #eval runM "#check (1 : Int)" #eval runM "#check ((1, 2) : Nat × Int)" #eval runM "#check (· + one)" #eval runM "#check (· + · : Nat → Nat → Nat)" #eval runM "#check (f one · zero)" #eval runM "#check (f · · zero)" #eval runM "#check fun (_ b : Nat) => b + 1" def foo {α β} (a : α) (b : β) (a' : α) : α := a def bla {α β} (f : α → β) (a : α) : β := f a -- #check fun x => foo x x.w s4 -- fails in old elaborator -- #check bla (fun x => x.w) s4 -- fails in the old elaborator -- #check #[1, 2, 3].foldl (fun r a => r.push a) #[] -- fails in the old elaborator #eval runM "#check fun x => foo x x.w s4" #eval runM "#check bla (fun x => x.w) s4" #eval runM "#check #[1, 2, 3].foldl (fun r a => r.push a) #[]" #eval runM "#check #[1, 2, 3].foldl (fun r a => (r.push a).push a) #[]" #eval runM "#check #[1, 2, 3].foldl (fun r a => ((r.push a).push a).push a) #[]" #eval runM "#check #[].push one $.push two $.push zero $.size.succ" #eval runM "#check #[1, 2].foldl (fun r a => r.push a $.push a $.push a) #[]" #eval runM "#check #[1, 2].foldl (init := #[]) $ fun r a => r.push a $.push a" #eval runM "#check let x := one + zero; x + x" -- set_option trace.Elab true #eval runM "#check (fun x => let v := x.w; v + v) s4" #eval runM "#check fun x => foo x (let v := x.w; v + one) s4" #eval runM "#check fun x => foo x (let v := x.w; let w := x.x; v + w + one) s4" #eval fail "#check id.{1,1}" #eval fail "#check @id.{0} Nat" #eval runM "#check @id.{1} Nat" #eval runM "universes u #check id.{u}" #eval fail "universes u #check id.{v}" #eval runM "universes u #check Type u" #eval runM "universes u #check Sort u" #eval runM "#check Type 1" #eval runM "#check Type 0" #eval runM "universes u v #check Sort (max u v)" #eval runM "universes u v #check Type (max u v)" #eval runM "#check 'a'" #eval fail "#check #['a', \"hello\"]" #eval runM "#check fun (a : Array Nat) => a.size" #eval runM "#check if 0 = 1 then 'a' else 'b'" #eval runM "#check fun (i : Nat) (a : Array Nat) => if h : i < a.size then a.get (Fin.mk i h) else i" #eval runM "#check { x : Nat // x > 0 }" #eval runM "#check { x // x > 0 }" #eval runM "#check fun (i : Nat) (a : Array Nat) => if h : i < a.size then a.get ⟨i, h⟩ else i" #eval runM "#check Prod.fst ⟨1, 2⟩" #eval runM "#check let x := ⟨1, 2⟩; Prod.fst x" #eval runM "#check show Nat from 1" #eval runM "#check show Int from 1" #eval runM "#check have Nat from one + zero; this + this" #eval runM "#check have x : Nat from one + zero; x + x" #eval runM "#check have Nat := one + zero; this + this" #eval runM "#check have x : Nat := one + zero; x + x" #eval runM "variables {α β} axiom x (n : Nat) : α → α #check x 1 0" #eval runM "#check ToString.toString 0" #eval runM "@[instance] axiom newInst : ToString Nat #check newInst #check ToString.toString 0" #eval runM "variables {β σ} universes w1 w2 /-- Testing axiom -/ unsafe axiom Nat.aux (γ : Type w1) (v : Nat) : β → (α : Type _) → v = zero /- Nat.zero -/ → Array α #check @Nat.aux" #eval runM "def x : Nat := Nat.zero #check x" #eval runM "def x := Nat.zero #check x" #eval runM "open Lean.Parser def x := parser! symbol \"foo\" #check x" #eval runM "open Lean.Parser def x := parser!:50 symbol \"foo\" #check x" #eval runM "open Lean.Parser def x := tparser! symbol \"foo\" #check x" #eval runM "def x : Nat := 1 #check x" def g (x : Nat := zero) (y : Nat := one) (z : Nat := two) : Nat := x + y + z def three := 3 #eval runM "#check g" #eval runM "#check g (x := three) (z := zero)" #eval runM "#check g (y := three)" #eval runM "#check g (z := three)" #eval runM "#check g three (z := zero)" #eval runM "#check (fun stx => if True then let e := stx; Pure.pure e else Pure.pure stx : Nat → Id Nat)" #eval runM "constant n : Nat #check n" #eval fail "#check Nat.succ 'a'" #eval runM "universes u v #check Type (max u v)" #eval runM "universes u v #check Type (imax u v)" #eval fail "namespace Boo def f (x : Nat) := x def s := 'a' #check (fun x => f x) s end Boo"
00c8e764eccfa25923de7b3a40d2c5de9dec6adb
1ce2e14f78a7f514bae439fbbb1f7fa2932dd7dd
/src/list.lean
827b26a0940a57bd91e5dff422e3e3425b5b9f7e
[ "MIT" ]
permissive
wudcscheme/lean-mathgirls
b88faf76d12e5ca07b83d6e5580663380b0bb45c
95b64a33ffb34f3c45e212c4adff3cc988dcbc60
refs/heads/master
1,678,994,115,961
1,585,127,877,000
1,585,127,877,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
2,996
lean
import data.list init.algebra.classes import tactic.norm_num tactic.tauto tactic.rewrite tactic.rewrite_all tactic.omega tactic.tidy import tactic.hint variables {α: Type*} variables [semiring α] @[simp] theorem map_id {l: list α}: list.map (λ x, x) l = l := begin induction l, reflexivity, simp, assumption, end theorem map_forall {β: Type*} {l: list α} {f: α -> β} {p: β -> Prop} (h: ∀ b:β, p b): (∀ a ∈ l, p (f a)) -> ∀ b ∈ (list.map f l), p b := by tidy @[simp] def scalar_l (x: α) (l: list α) := list.map (λ y, x*y) l infixr `[*]`:1000 := scalar_l @[simp] def scalar_add_l (x: α) (l: list α) := list.map (λ y, x+y) l infixr `[+]`:500 := scalar_add_l @[simp] def scalar_r (l: list α) (x: α) := list.map (λ y, y*x) l @[simp] def scalar_add_r (l: list α) (x: α) := list.map (λ y, y+x) l @[simp] def tensor : list α -> list α -> list α | [] ys := [] | (x::xs) ys := (x [*] ys) ++ (tensor xs ys) infixr `<*>` := tensor infixr ` ⊗`:1000 := tensor @[simp] def vec_add: list α -> list α -> list α | [] ys := ys | xs [] := xs | (x::xs) (y::ys) := (x+y)::(vec_add xs ys) infixr `<+>`:500 := vec_add @[simp] theorem scalar_l_sum {x: α} {l: list α}: (x [*] l).sum = x * l.sum := begin induction l, simp, case list.cons: hd tl ih { rw list.sum_cons, simp, simp at ih, rw ih, rw left_distrib, } end @[simp] theorem scalar_l_cons {x y: α} {l: list α}: (x [*] (y::l)) = (x*y)::(x [*] l) := by simp @[simp] theorem add_scalar_l_distrib {x y: α} {l: list α}: (x + y) [*] l = (x[*]l) <+> (y[*]l) := begin induction l, reflexivity, case list.cons: hd tl ih { repeat {rw scalar_l_cons }, rw ih, simp, rw semiring.right_distrib, reflexivity, } end @[simp] theorem tensor_l_id {l: list α}: [1] <*> l = l := begin induction l, reflexivity, case list.cons: hd tl ih { simp, } end @[simp] theorem tensor_r_id {l: list α}: l <*> [1] = l := begin induction l, reflexivity, simp, assumption, end @[simp] theorem tensor_sum {l1 l2: list α}: (l1 <*> l2).sum = l1.sum * l2.sum := begin induction l1, { rw tensor, simp, }, case list.cons: hd tl ih { rw list.sum_cons, rw right_distrib, rw tensor, rw list.sum_append, rw scalar_l_sum, rw ih, } end -- geom (n, e) = [n^0, n^1, ..., n^e] @[simp, reducible] def geom (p: α × ℕ) := list.map (λ c, (p.1 ^ c)) (list.range (p.2+1)) notation `<|` p `|>` := geom p @[simp] theorem geom_zero (e: α): <| (e, 0) |> = [1] := rfl @[simp] theorem geom_succ (p: α × ℕ): <| (p.1, p.2+1) |> = 1::(p.1 [*] <| p |>) := begin simp, repeat { rw add_comm, rw list.range_succ_eq_map, rw list.map_cons}, simp, have: (pow p.fst) ∘ nat.succ ∘ nat.succ = (pow p.fst ∘ nat.succ) ∘ nat.succ, by simp, rw this, clear this, have: (pow p.fst ∘ nat.succ) = (has_mul.mul p.fst ∘ pow p.fst), { apply funext, intro, simp, rw pow_succ, }, rw this, end
acb709c8c8d8291dc6cf8414a2d4294c3e5a50f9
82b86ba2ae0d5aed0f01f49c46db5afec0eb2bd7
/stage0/src/Lean/CoreM.lean
d20c6bec642a06901ead58e32eb9150e51620b95
[ "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
4,097
lean
/- Copyright (c) 2020 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura -/ import Lean.Util.RecDepth import Lean.Util.Trace import Lean.Environment import Lean.Exception import Lean.InternalExceptionId import Lean.Eval import Lean.MonadEnv namespace Lean namespace Core structure State := (env : Environment) (nextMacroScope : MacroScope := firstFrontendMacroScope + 1) (ngen : NameGenerator := {}) (traceState : TraceState := {}) instance : Inhabited State := ⟨{ env := arbitrary _ }⟩ structure Context := (options : Options := {}) (currRecDepth : Nat := 0) (maxRecDepth : Nat := 1000) (ref : Syntax := Syntax.missing) abbrev CoreM := ReaderT Context $ StateRefT State (EIO Exception) instance {α} : Inhabited (CoreM α) := ⟨fun _ _ => throw $ arbitrary _⟩ instance : Ref CoreM := { getRef := do let ctx ← read; pure ctx.ref, withRef := fun ref x => withReader (fun ctx => { ctx with ref := ref }) x } instance : MonadEnv CoreM := { getEnv := do pure (← get).env, modifyEnv := fun f => modify fun s => { s with env := f s.env } } instance : MonadOptions CoreM := { getOptions := do pure (← read).options } instance : AddMessageContext CoreM := { addMessageContext := addMessageContextPartial } instance : MonadNameGenerator CoreM := { getNGen := do pure (← get).ngen, setNGen := fun ngen => modify fun s => { s with ngen := ngen } } instance : MonadRecDepth CoreM := { withRecDepth := fun d x => withReader (fun ctx => { ctx with currRecDepth := d }) x, getRecDepth := do pure (← read).currRecDepth, getMaxRecDepth := do pure (← read).maxRecDepth } @[inline] def liftIOCore {α} (x : IO α) : CoreM α := do let ref ← getRef IO.toEIO (fun (err : IO.Error) => Exception.error ref (toString err)) x instance : MonadIO CoreM := { liftIO := @liftIOCore } instance : MonadTrace CoreM := { getTraceState := do pure (← get).traceState, modifyTraceState := fun f => modify fun s => { s with traceState := f s.traceState } } private def mkFreshNameImp (n : Name) : CoreM Name := do let fresh ← modifyGet fun s => (s.nextMacroScope, { s with nextMacroScope := s.nextMacroScope + 1 }) let env ← getEnv pure $ addMacroScope env.mainModule n fresh def mkFreshUserName {m} [MonadLiftT CoreM m] (n : Name) : m Name := liftM $ mkFreshNameImp n @[inline] def CoreM.run {α} (x : CoreM α) (ctx : Context) (s : State) : EIO Exception (α × State) := (x ctx).run s @[inline] def CoreM.run' {α} (x : CoreM α) (ctx : Context) (s : State) : EIO Exception α := Prod.fst <$> x.run ctx s @[inline] def CoreM.toIO {α} (x : CoreM α) (ctx : Context) (s : State) : IO (α × State) := do match (← (x.run ctx s).toIO') with | Except.error (Exception.error _ msg) => do let e ← msg.toString; throw $ IO.userError e | Except.error (Exception.internal id) => throw $ IO.userError $ "internal exception #" ++ toString id.idx | Except.ok a => pure a instance {α} [MetaEval α] : MetaEval (CoreM α) := { eval := fun env opts x _ => do let x : CoreM α := do try x finally printTraces let (a, s) ← x.toIO { maxRecDepth := getMaxRecDepth opts, options := opts } { env := env } MetaEval.eval s.env opts a (hideUnit := true) } end Core export Core (CoreM mkFreshUserName) @[inline] def catchInternalId {α} {m : Type → Type} [Monad m] [MonadExcept Exception m] (id : InternalExceptionId) (x : m α) (h : Exception → m α) : m α := do try x catch ex => match ex with | Exception.error _ _ => throw ex | Exception.internal id' => if id == id' then h ex else throw ex @[inline] def catchInternalIds {α} {m : Type → Type} [Monad m] [MonadExcept Exception m] (ids : List InternalExceptionId) (x : m α) (h : Exception → m α) : m α := do try x catch ex => match ex with | Exception.error _ _ => throw ex | Exception.internal id => if ids.contains id then h ex else throw ex end Lean
762abc8450b64d48779718ae8c6dbcea85c30193
94e33a31faa76775069b071adea97e86e218a8ee
/src/analysis/box_integral/partition/measure.lean
59650c2282b00d257843908c57d0103a37fae2d0
[ "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
4,074
lean
/- Copyright (c) 2021 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import analysis.box_integral.partition.additive import measure_theory.measure.lebesgue /-! # Box-additive functions defined by measures In this file we prove a few simple facts about rectangular boxes, partitions, and measures: - given a box `I : box ι`, its coercion to `set (ι → ℝ)` and `I.Icc` are measurable sets; - if `μ` is a locally finite measure, then `(I : set (ι → ℝ))` and `I.Icc` have finite measure; - if `μ` is a locally finite measure, then `λ J, (μ J).to_real` is a box additive function. For the last statement, we both prove it as a proposition and define a bundled `box_integral.box_additive` function. ### Tags rectangular box, measure -/ open set noncomputable theory open_locale ennreal big_operators classical box_integral variables {ι : Type*} namespace box_integral open measure_theory namespace box lemma measure_Icc_lt_top (I : box ι) (μ : measure (ι → ℝ)) [is_locally_finite_measure μ] : μ I.Icc < ∞ := show μ (Icc I.lower I.upper) < ∞, from I.is_compact_Icc.measure_lt_top lemma measure_coe_lt_top (I : box ι) (μ : measure (ι → ℝ)) [is_locally_finite_measure μ] : μ I < ∞ := (measure_mono $ coe_subset_Icc).trans_lt (I.measure_Icc_lt_top μ) variables [fintype ι] (I : box ι) lemma measurable_set_coe : measurable_set (I : set (ι → ℝ)) := begin rw [coe_eq_pi], haveI := fintype.to_encodable ι, exact measurable_set.univ_pi (λ i, measurable_set_Ioc) end lemma measurable_set_Icc : measurable_set I.Icc := measurable_set_Icc lemma measurable_set_Ioo : measurable_set I.Ioo := (measurable_set_pi (set.to_finite _).countable).2 $ or.inl $ λ i hi, measurable_set_Ioo lemma coe_ae_eq_Icc : (I : set (ι → ℝ)) =ᵐ[volume] I.Icc := by { rw coe_eq_pi, exact measure.univ_pi_Ioc_ae_eq_Icc } lemma Ioo_ae_eq_Icc : I.Ioo =ᵐ[volume] I.Icc := measure.univ_pi_Ioo_ae_eq_Icc end box lemma prepartition.measure_Union_to_real [fintype ι] {I : box ι} (π : prepartition I) (μ : measure (ι → ℝ)) [is_locally_finite_measure μ] : (μ π.Union).to_real = ∑ J in π.boxes, (μ J).to_real := begin erw [← ennreal.to_real_sum, π.Union_def, measure_bUnion_finset π.pairwise_disjoint], exacts [λ J hJ, J.measurable_set_coe, λ J hJ, (J.measure_coe_lt_top μ).ne] end end box_integral open box_integral box_integral.box variables [fintype ι] namespace measure_theory namespace measure /-- If `μ` is a locally finite measure on `ℝⁿ`, then `λ J, (μ J).to_real` is a box-additive function. -/ @[simps] def to_box_additive (μ : measure (ι → ℝ)) [is_locally_finite_measure μ] : ι →ᵇᵃ[⊤] ℝ := { to_fun := λ J, (μ J).to_real, sum_partition_boxes' := λ J hJ π hπ, by rw [← π.measure_Union_to_real, hπ.Union_eq] } end measure end measure_theory namespace box_integral open measure_theory namespace box @[simp] lemma volume_apply (I : box ι) : (volume : measure (ι → ℝ)).to_box_additive I = ∏ i, (I.upper i - I.lower i) := by rw [measure.to_box_additive_apply, coe_eq_pi, real.volume_pi_Ioc_to_real I.lower_le_upper] lemma volume_face_mul {n} (i : fin (n + 1)) (I : box (fin (n + 1))) : (∏ j, ((I.face i).upper j - (I.face i).lower j)) * (I.upper i - I.lower i) = ∏ j, (I.upper j - I.lower j) := by simp only [face_lower, face_upper, (∘), fin.prod_univ_succ_above _ i, mul_comm] end box namespace box_additive_map /-- Box-additive map sending each box `I` to the continuous linear endomorphism `x ↦ (volume I).to_real • x`. -/ protected def volume {E : Type*} [normed_group E] [normed_space ℝ E] : ι →ᵇᵃ (E →L[ℝ] E) := (volume : measure (ι → ℝ)).to_box_additive.to_smul lemma volume_apply {E : Type*} [normed_group E] [normed_space ℝ E] (I : box ι) (x : E) : box_additive_map.volume I x = (∏ j, (I.upper j - I.lower j)) • x := congr_arg2 (•) I.volume_apply rfl end box_additive_map end box_integral
748c861450e67696846475ecf7c7daf3699ede8d
c777c32c8e484e195053731103c5e52af26a25d1
/src/set_theory/ordinal/natural_ops.lean
ff6f1e849beffe3554a5aff9ae98298204fb1910
[ "Apache-2.0" ]
permissive
kbuzzard/mathlib
2ff9e85dfe2a46f4b291927f983afec17e946eb8
58537299e922f9c77df76cb613910914a479c1f7
refs/heads/master
1,685,313,702,744
1,683,974,212,000
1,683,974,212,000
128,185,277
1
0
null
1,522,920,600,000
1,522,920,600,000
null
UTF-8
Lean
false
false
12,152
lean
/- Copyright (c) 2022 Violeta Hernández Palacios. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Violeta Hernández Palacios -/ import set_theory.ordinal.arithmetic /-! # Natural operations on ordinals > THIS FILE IS SYNCHRONIZED WITH MATHLIB4. > Any changes to this file require a corresponding PR to mathlib4. The goal of this file is to define natural addition and multiplication on ordinals, also known as the Hessenberg sum and product, and provide a basic API. The natural addition of two ordinals `a ♯ b` is recursively defined as the least ordinal greater than `a' ♯ b` and `a ♯ b'` for `a' < a` and `b' < b`. The natural multiplication `a ⨳ b` is likewise recursively defined as the least ordinal such that `a ⨳ b ♯ a' ⨳ b'` is greater than `a' ⨳ b ♯ a ⨳ b'` for any `a' < a` and `b' < b`. These operations form a rich algebraic structure: they're commutative, associative, preserve order, have the usual `0` and `1` from ordinals, and distribute over one another. Moreover, these operations are the addition and multiplication of ordinals when viewed as combinatorial `game`s. This makes them particularly useful for game theory. Finally, both operations admit simple, intuitive descriptions in terms of the Cantor normal form. The natural addition of two ordinals corresponds to adding their Cantor normal forms as if they were polynomials in `ω`. Likewise, their natural multiplication corresponds to multiplying the Cantor normal forms as polynomials. # Implementation notes Given the rich algebraic structure of these two operations, we choose to create a type synonym `nat_ordinal`, where we provide the appropriate instances. However, to avoid casting back and forth between both types, we attempt to prove and state most results on `ordinal`. # Todo - Define natural multiplication and provide a basic API. - Prove the characterizations of natural addition and multiplication in terms of the Cantor normal form. -/ universes u v open function order noncomputable theory /-- A type synonym for ordinals with natural addition and multiplication. -/ @[derive [has_zero, inhabited, has_one, linear_order, succ_order, has_well_founded]] def nat_ordinal : Type* := ordinal /-- The identity function between `ordinal` and `nat_ordinal`. -/ @[pattern] def ordinal.to_nat_ordinal : ordinal ≃o nat_ordinal := order_iso.refl _ /-- The identity function between `nat_ordinal` and `ordinal`. -/ @[pattern] def nat_ordinal.to_ordinal : nat_ordinal ≃o ordinal := order_iso.refl _ open ordinal namespace nat_ordinal variables {a b c : nat_ordinal.{u}} @[simp] theorem to_ordinal_symm_eq : nat_ordinal.to_ordinal.symm = ordinal.to_nat_ordinal := rfl @[simp] theorem to_ordinal_to_nat_ordinal (a : nat_ordinal) : a.to_ordinal.to_nat_ordinal = a := rfl theorem lt_wf : @well_founded nat_ordinal (<) := ordinal.lt_wf instance : well_founded_lt nat_ordinal := ordinal.well_founded_lt instance : is_well_order nat_ordinal (<) := ordinal.has_lt.lt.is_well_order @[simp] theorem to_ordinal_zero : to_ordinal 0 = 0 := rfl @[simp] theorem to_ordinal_one : to_ordinal 1 = 1 := rfl @[simp] theorem to_ordinal_eq_zero (a) : to_ordinal a = 0 ↔ a = 0 := iff.rfl @[simp] theorem to_ordinal_eq_one (a) : to_ordinal a = 1 ↔ a = 1 := iff.rfl @[simp] theorem to_ordinal_max : (max a b).to_ordinal = max a.to_ordinal b.to_ordinal := rfl @[simp] theorem to_ordinal_min : (min a b).to_ordinal = min a.to_ordinal b.to_ordinal := rfl theorem succ_def (a : nat_ordinal) : succ a = (a.to_ordinal + 1).to_nat_ordinal := rfl /-- A recursor for `nat_ordinal`. Use as `induction x using nat_ordinal.rec`. -/ protected def rec {β : nat_ordinal → Sort*} (h : Π a, β (to_nat_ordinal a)) : Π a, β a := λ a, h a.to_ordinal /-- `ordinal.induction` but for `nat_ordinal`. -/ theorem induction {p : nat_ordinal → Prop} : ∀ i (h : ∀ j, (∀ k, k < j → p k) → p j), p i := ordinal.induction end nat_ordinal namespace ordinal variables {a b c : ordinal.{u}} @[simp] theorem to_nat_ordinal_symm_eq : to_nat_ordinal.symm = nat_ordinal.to_ordinal := rfl @[simp] theorem to_nat_ordinal_to_ordinal (a : ordinal) : a.to_nat_ordinal.to_ordinal = a := rfl @[simp] theorem to_nat_ordinal_zero : to_nat_ordinal 0 = 0 := rfl @[simp] theorem to_nat_ordinal_one : to_nat_ordinal 1 = 1 := rfl @[simp] theorem to_nat_ordinal_eq_zero (a) : to_nat_ordinal a = 0 ↔ a = 0 := iff.rfl @[simp] theorem to_nat_ordinal_eq_one (a) : to_nat_ordinal a = 1 ↔ a = 1 := iff.rfl @[simp] theorem to_nat_ordinal_max : to_nat_ordinal (max a b) = max a.to_nat_ordinal b.to_nat_ordinal := rfl @[simp] theorem to_nat_ordinal_min : (linear_order.min a b).to_nat_ordinal = linear_order.min a.to_nat_ordinal b.to_nat_ordinal := rfl /-- Natural addition on ordinals `a ♯ b`, also known as the Hessenberg sum, is recursively defined as the least ordinal greater than `a' ♯ b` and `a ♯ b'` for all `a' < a` and `b' < b`. In contrast to normal ordinal addition, it is commutative. Natural addition can equivalently be characterized as the ordinal resulting from adding up corresponding coefficients in the Cantor normal forms of `a` and `b`. -/ noncomputable def nadd : ordinal → ordinal → ordinal | a b := max (blsub.{u u} a $ λ a' h, nadd a' b) (blsub.{u u} b $ λ b' h, nadd a b') using_well_founded { dec_tac := `[solve_by_elim [psigma.lex.left, psigma.lex.right]] } localized "infix (name := ordinal.nadd) ` ♯ `:65 := ordinal.nadd" in natural_ops theorem nadd_def (a b : ordinal) : a ♯ b = max (blsub.{u u} a $ λ a' h, a' ♯ b) (blsub.{u u} b $ λ b' h, a ♯ b') := by rw nadd theorem lt_nadd_iff : a < b ♯ c ↔ (∃ b' < b, a ≤ b' ♯ c) ∨ ∃ c' < c, a ≤ b ♯ c' := by { rw nadd_def, simp [lt_blsub_iff] } theorem nadd_le_iff : b ♯ c ≤ a ↔ (∀ b' < b, b' ♯ c < a) ∧ ∀ c' < c, b ♯ c' < a := by { rw nadd_def, simp [blsub_le_iff] } theorem nadd_lt_nadd_left (h : b < c) (a) : a ♯ b < a ♯ c := lt_nadd_iff.2 (or.inr ⟨b, h, le_rfl⟩) theorem nadd_lt_nadd_right (h : b < c) (a) : b ♯ a < c ♯ a := lt_nadd_iff.2 (or.inl ⟨b, h, le_rfl⟩) theorem nadd_le_nadd_left (h : b ≤ c) (a) : a ♯ b ≤ a ♯ c := begin rcases lt_or_eq_of_le h with h | rfl, { exact (nadd_lt_nadd_left h a).le }, { exact le_rfl } end theorem nadd_le_nadd_right (h : b ≤ c) (a) : b ♯ a ≤ c ♯ a := begin rcases lt_or_eq_of_le h with h | rfl, { exact (nadd_lt_nadd_right h a).le }, { exact le_rfl } end variables (a b) theorem nadd_comm : ∀ a b, a ♯ b = b ♯ a | a b := begin rw [nadd_def, nadd_def, max_comm], congr; ext c hc; apply nadd_comm end using_well_founded { dec_tac := `[solve_by_elim [psigma.lex.left, psigma.lex.right]] } theorem blsub_nadd_of_mono {f : Π c < a ♯ b, ordinal.{max u v}} (hf : ∀ {i j} hi hj, i ≤ j → f i hi ≤ f j hj) : blsub _ f = max (blsub.{u v} a (λ a' ha', f (a' ♯ b) $ nadd_lt_nadd_right ha' b)) (blsub.{u v} b (λ b' hb', f (a ♯ b') $ nadd_lt_nadd_left hb' a)) := begin apply (blsub_le_iff.2 (λ i h, _)).antisymm (max_le _ _), { rcases lt_nadd_iff.1 h with ⟨a', ha', hi⟩ | ⟨b', hb', hi⟩, { exact lt_max_of_lt_left ((hf h (nadd_lt_nadd_right ha' b) hi).trans_lt (lt_blsub _ _ _)) }, { exact lt_max_of_lt_right ((hf h (nadd_lt_nadd_left hb' a) hi).trans_lt (lt_blsub _ _ _)) } }, all_goals { apply blsub_le_of_brange_subset.{u u v}, rintro c ⟨d, hd, rfl⟩, apply mem_brange_self } end theorem nadd_assoc : ∀ a b c, a ♯ b ♯ c = a ♯ (b ♯ c) | a b c := begin rw [nadd_def a (b ♯ c), nadd_def, blsub_nadd_of_mono, blsub_nadd_of_mono, max_assoc], { congr; ext d hd; apply nadd_assoc }, { exact λ i j _ _ h, nadd_le_nadd_left h a }, { exact λ i j _ _ h, nadd_le_nadd_right h c } end using_well_founded { dec_tac := `[solve_by_elim [psigma.lex.left, psigma.lex.right]] } @[simp] theorem nadd_zero : a ♯ 0 = a := begin induction a using ordinal.induction with a IH, rw [nadd_def, blsub_zero, max_zero_right], convert blsub_id a, ext b hb, exact IH _ hb end @[simp] theorem zero_nadd : 0 ♯ a = a := by rw [nadd_comm, nadd_zero] @[simp] theorem nadd_one : a ♯ 1 = succ a := begin induction a using ordinal.induction with a IH, rw [nadd_def, blsub_one, nadd_zero, max_eq_right_iff, blsub_le_iff], intros i hi, rwa [IH i hi, succ_lt_succ_iff] end @[simp] theorem one_nadd : 1 ♯ a = succ a := by rw [nadd_comm, nadd_one] theorem nadd_succ : a ♯ succ b = succ (a ♯ b) := by rw [←nadd_one (a ♯ b), nadd_assoc, nadd_one] theorem succ_nadd : succ a ♯ b = succ (a ♯ b) := by rw [←one_nadd (a ♯ b), ←nadd_assoc, one_nadd] @[simp] theorem nadd_nat (n : ℕ) : a ♯ n = a + n := begin induction n with n hn, { simp }, { rw [nat.cast_succ, add_one_eq_succ, nadd_succ, add_succ, hn] } end @[simp] theorem nat_nadd (n : ℕ) : ↑n ♯ a = a + n := by rw [nadd_comm, nadd_nat] theorem add_le_nadd : a + b ≤ a ♯ b := begin apply b.limit_rec_on, { simp }, { intros c h, rwa [add_succ, nadd_succ, succ_le_succ_iff] }, { intros c hc H, rw [←is_normal.blsub_eq.{u u} (add_is_normal a) hc, blsub_le_iff], exact λ i hi, (H i hi).trans_lt (nadd_lt_nadd_left hi a) } end end ordinal open ordinal namespace nat_ordinal instance : has_add nat_ordinal := ⟨nadd⟩ instance add_covariant_class_lt : covariant_class nat_ordinal.{u} nat_ordinal.{u} (+) (<) := ⟨λ a b c h, nadd_lt_nadd_left h a⟩ instance add_covariant_class_le : covariant_class nat_ordinal.{u} nat_ordinal.{u} (+) (≤) := ⟨λ a b c h, nadd_le_nadd_left h a⟩ instance add_contravariant_class_le : contravariant_class nat_ordinal.{u} nat_ordinal.{u} (+) (≤) := ⟨λ a b c h, by { by_contra' h', exact h.not_lt (add_lt_add_left h' a) }⟩ instance : ordered_cancel_add_comm_monoid nat_ordinal := { add := (+), add_assoc := nadd_assoc, add_le_add_left := λ a b, add_le_add_left, le_of_add_le_add_left := λ a b c, le_of_add_le_add_left, zero := 0, zero_add := zero_nadd, add_zero := nadd_zero, add_comm := nadd_comm, ..nat_ordinal.linear_order } instance : add_monoid_with_one nat_ordinal := add_monoid_with_one.unary @[simp] theorem add_one_eq_succ : ∀ a : nat_ordinal, a + 1 = succ a := nadd_one @[simp] theorem to_ordinal_cast_nat (n : ℕ) : to_ordinal n = n := begin induction n with n hn, { refl }, { change nadd (to_ordinal n) 1 = n + 1, rw hn, apply nadd_one } end end nat_ordinal open nat_ordinal open_locale natural_ops namespace ordinal @[simp] theorem to_nat_ordinal_cast_nat (n : ℕ) : to_nat_ordinal n = n := by { rw ←to_ordinal_cast_nat n, refl } theorem lt_of_nadd_lt_nadd_left : ∀ {a b c}, a ♯ b < a ♯ c → b < c := @lt_of_add_lt_add_left nat_ordinal _ _ _ theorem lt_of_nadd_lt_nadd_right : ∀ {a b c}, b ♯ a < c ♯ a → b < c := @_root_.lt_of_add_lt_add_right nat_ordinal _ _ _ theorem le_of_nadd_le_nadd_left : ∀ {a b c}, a ♯ b ≤ a ♯ c → b ≤ c := @le_of_add_le_add_left nat_ordinal _ _ _ theorem le_of_nadd_le_nadd_right : ∀ {a b c}, b ♯ a ≤ c ♯ a → b ≤ c := @le_of_add_le_add_right nat_ordinal _ _ _ theorem nadd_lt_nadd_iff_left : ∀ a {b c}, a ♯ b < a ♯ c ↔ b < c := @add_lt_add_iff_left nat_ordinal _ _ _ _ theorem nadd_lt_nadd_iff_right : ∀ a {b c}, b ♯ a < c ♯ a ↔ b < c := @add_lt_add_iff_right nat_ordinal _ _ _ _ theorem nadd_le_nadd_iff_left : ∀ a {b c}, a ♯ b ≤ a ♯ c ↔ b ≤ c := @add_le_add_iff_left nat_ordinal _ _ _ _ theorem nadd_le_nadd_iff_right : ∀ a {b c}, b ♯ a ≤ c ♯ a ↔ b ≤ c := @_root_.add_le_add_iff_right nat_ordinal _ _ _ _ theorem nadd_left_cancel : ∀ {a b c}, a ♯ b = a ♯ c → b = c := @_root_.add_left_cancel nat_ordinal _ _ theorem nadd_right_cancel : ∀ {a b c}, a ♯ b = c ♯ b → a = c := @_root_.add_right_cancel nat_ordinal _ _ theorem nadd_left_cancel_iff : ∀ {a b c}, a ♯ b = a ♯ c ↔ b = c := @add_left_cancel_iff nat_ordinal _ _ theorem nadd_right_cancel_iff : ∀ {a b c}, b ♯ a = c ♯ a ↔ b = c := @add_right_cancel_iff nat_ordinal _ _ end ordinal
1b12e037a6c6a27e9557b35654ab924b3d0557bd
c777c32c8e484e195053731103c5e52af26a25d1
/src/linear_algebra/exterior_algebra/of_alternating.lean
0aaeb47af7172350267b536a12c4f183ada0cb70
[ "Apache-2.0" ]
permissive
kbuzzard/mathlib
2ff9e85dfe2a46f4b291927f983afec17e946eb8
58537299e922f9c77df76cb613910914a479c1f7
refs/heads/master
1,685,313,702,744
1,683,974,212,000
1,683,974,212,000
128,185,277
1
0
null
1,522,920,600,000
1,522,920,600,000
null
UTF-8
Lean
false
false
6,188
lean
/- Copyright (c) 2022 Eric Wieser. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Wieser -/ import linear_algebra.clifford_algebra.fold import linear_algebra.exterior_algebra.basic /-! # Extending an alternating map to the exterior algebra ## Main definitions * `exterior_algebra.lift_alternating`: construct a linear map out of the exterior algebra given alternating maps (corresponding to maps out of the exterior powers). * `exterior_algebra.lift_alternating_equiv`: the above as a linear equivalence ## Main results * `exterior_algebra.lhom_ext`: linear maps from the exterior algebra agree if they agree on the exterior powers. -/ variables {R M N N' : Type*} variables [comm_ring R] [add_comm_group M] [add_comm_group N] [add_comm_group N'] variables [module R M] [module R N] [module R N'] -- This instance can't be found where it's needed if we don't remind lean that it exists. instance alternating_map.module_add_comm_group {ι : Type*} : module R (alternating_map R M N ι) := by apply_instance namespace exterior_algebra open clifford_algebra (hiding ι) /-- Build a map out of the exterior algebra given a collection of alternating maps acting on each exterior power -/ def lift_alternating : (Π i, alternating_map R M N (fin i)) →ₗ[R] exterior_algebra R M →ₗ[R] N := begin suffices : (Π i, alternating_map R M N (fin i)) →ₗ[R] exterior_algebra R M →ₗ[R] (Π i, alternating_map R M N (fin i)), { refine linear_map.compr₂ this _, refine linear_equiv.to_linear_map _ ∘ₗ linear_map.proj 0, exact alternating_map.const_linear_equiv_of_is_empty.symm }, refine clifford_algebra.foldl _ _ _, { refine linear_map.mk₂ R (λ m f i, (f i.succ).curry_left m) (λ m₁ m₂ f, _) (λ c m f, _) (λ m f₁ f₂, _) (λ c m f, _), all_goals { ext i : 1, simp only [map_smul, map_add, pi.add_apply, pi.smul_apply, alternating_map.curry_left_add, alternating_map.curry_left_smul, map_add, map_smul, linear_map.add_apply, linear_map.smul_apply] } }, { -- when applied twice with the same `m`, this recursive step produces 0 intros m x, dsimp only [linear_map.mk₂_apply, quadratic_form.coe_fn_zero, pi.zero_apply], simp_rw zero_smul, ext i : 1, exact alternating_map.curry_left_same _ _, } end @[simp] lemma lift_alternating_ι (f : Π i, alternating_map R M N (fin i)) (m : M) : lift_alternating f (ι R m) = f 1 ![m] := begin dsimp [lift_alternating], rw [foldl_ι, linear_map.mk₂_apply, alternating_map.curry_left_apply_apply], congr, end lemma lift_alternating_ι_mul (f : Π i, alternating_map R M N (fin i)) (m : M) (x : exterior_algebra R M): lift_alternating f (ι R m * x) = lift_alternating (λ i, (f i.succ).curry_left m) x := begin dsimp [lift_alternating], rw [foldl_mul, foldl_ι], refl, end @[simp] lemma lift_alternating_one (f : Π i, alternating_map R M N (fin i)) : lift_alternating f (1 : exterior_algebra R M) = f 0 0 := begin dsimp [lift_alternating], rw foldl_one, end @[simp] lemma lift_alternating_algebra_map (f : Π i, alternating_map R M N (fin i)) (r : R) : lift_alternating f (algebra_map _ (exterior_algebra R M) r) = r • f 0 0 := by rw [algebra.algebra_map_eq_smul_one, map_smul, lift_alternating_one] @[simp] lemma lift_alternating_apply_ι_multi {n : ℕ} (f : Π i, alternating_map R M N (fin i)) (v : fin n → M) : lift_alternating f (ι_multi R n v) = f n v := begin rw ι_multi_apply, induction n with n ih generalizing f v, { rw [list.of_fn_zero, list.prod_nil, lift_alternating_one, subsingleton.elim 0 v] }, { rw [list.of_fn_succ, list.prod_cons, lift_alternating_ι_mul, ih, alternating_map.curry_left_apply_apply], congr', exact matrix.cons_head_tail _ } end @[simp] lemma lift_alternating_comp_ι_multi {n : ℕ} (f : Π i, alternating_map R M N (fin i)) : (lift_alternating f).comp_alternating_map (ι_multi R n) = f n := alternating_map.ext $ lift_alternating_apply_ι_multi f @[simp] lemma lift_alternating_comp (g : N →ₗ[R] N') (f : Π i, alternating_map R M N (fin i)) : lift_alternating (λ i, g.comp_alternating_map (f i)) = g ∘ₗ lift_alternating f := begin ext v, rw linear_map.comp_apply, induction v using clifford_algebra.left_induction with r x y hx hy x m hx generalizing f, { rw [lift_alternating_algebra_map, lift_alternating_algebra_map, map_smul, linear_map.comp_alternating_map_apply] }, { rw [map_add, map_add, map_add, hx, hy] }, { rw [lift_alternating_ι_mul, lift_alternating_ι_mul, ←hx], simp_rw alternating_map.curry_left_comp_alternating_map }, end @[simp] lemma lift_alternating_ι_multi : lift_alternating (by exact (ι_multi R)) = (linear_map.id : exterior_algebra R M →ₗ[R] exterior_algebra R M) := begin ext v, dsimp, induction v using clifford_algebra.left_induction with r x y hx hy x m hx, { rw [lift_alternating_algebra_map, ι_multi_zero_apply, algebra.algebra_map_eq_smul_one] }, { rw [map_add, hx, hy] }, { simp_rw [lift_alternating_ι_mul, ι_multi_succ_curry_left, lift_alternating_comp, linear_map.comp_apply, linear_map.mul_left_apply, hx] }, end /-- `exterior_algebra.lift_alternating` is an equivalence. -/ @[simps apply symm_apply] def lift_alternating_equiv : (Π i, alternating_map R M N (fin i)) ≃ₗ[R] exterior_algebra R M →ₗ[R] N := { to_fun := lift_alternating, map_add' := map_add _, map_smul' := map_smul _, inv_fun := λ F i, F.comp_alternating_map (ι_multi R i), left_inv := λ f, funext $ λ i, lift_alternating_comp_ι_multi _, right_inv := λ F, (lift_alternating_comp _ _).trans $ by rw [lift_alternating_ι_multi, linear_map.comp_id]} /-- To show that two linear maps from the exterior algebra agree, it suffices to show they agree on the exterior powers. See note [partially-applied ext lemmas] -/ @[ext] lemma lhom_ext ⦃f g : exterior_algebra R M →ₗ[R] N⦄ (h : ∀ i, f.comp_alternating_map (ι_multi R i) = g.comp_alternating_map (ι_multi R i)) : f = g := lift_alternating_equiv.symm.injective $ funext h end exterior_algebra
1e0060a111b78a190f26aa8742d0d4411e998c47
69d4931b605e11ca61881fc4f66db50a0a875e39
/src/topology/algebra/ordered/basic.lean
68a45f6afc72b5acdac73a15b1e4374ddb4dce37
[ "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
168,910
lean
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro, Yury Kudryashov -/ import tactic.tfae import algebra.group_with_zero.power import data.set.intervals.pi import topology.algebra.group import order.filter.interval /-! # Theory of topology on ordered spaces ## Main definitions The order topology on an ordered space is the topology generated by all open intervals (or equivalently by those of the form `(-∞, a)` and `(b, +∞)`). We define it as `preorder.topology α`. However, we do *not* register it as an instance (as many existing ordered types already have topologies, which would be equal but not definitionally equal to `preorder.topology α`). Instead, we introduce a class `order_topology α` (which is a `Prop`, also known as a mixin) saying that on the type `α` having already a topological space structure and a preorder structure, the topological structure is equal to the order topology. We also introduce another (mixin) class `order_closed_topology α` saying that the set of points `(x, y)` with `x ≤ y` is closed in the product space. This is automatically satisfied on a linear order with the order topology. We prove many basic properties of such topologies. ## Main statements This file contains the proofs of the following facts. For exact requirements (`order_closed_topology` vs `order_topology`, `preorder` vs `partial_order` vs `linear_order` etc) see their statements. ### Open / closed sets * `is_open_lt` : if `f` and `g` are continuous functions, then `{x | f x < g x}` is open; * `is_open_Iio`, `is_open_Ioi`, `is_open_Ioo` : open intervals are open; * `is_closed_le` : if `f` and `g` are continuous functions, then `{x | f x ≤ g x}` is closed; * `is_closed_Iic`, `is_closed_Ici`, `is_closed_Icc` : closed intervals are closed; * `frontier_le_subset_eq`, `frontier_lt_subset_eq` : frontiers of both `{x | f x ≤ g x}` and `{x | f x < g x}` are included by `{x | f x = g x}`; * `exists_Ioc_subset_of_mem_nhds`, `exists_Ico_subset_of_mem_nhds` : if `x < y`, then any neighborhood of `x` includes an interval `[x, z)` for some `z ∈ (x, y]`, and any neighborhood of `y` includes an interval `(z, y]` for some `z ∈ [x, y)`. ### Convergence and inequalities * `le_of_tendsto_of_tendsto` : if `f` converges to `a`, `g` converges to `b`, and eventually `f x ≤ g x`, then `a ≤ b` * `le_of_tendsto`, `ge_of_tendsto` : if `f` converges to `a` and eventually `f x ≤ b` (resp., `b ≤ f x`), then `a ≤ b` (resp., `b ≤ a); we also provide primed versions that assume the inequalities to hold for all `x`. ### Min, max, `Sup` and `Inf` * `continuous.min`, `continuous.max`: pointwise `min`/`max` of two continuous functions is continuous. * `tendsto.min`, `tendsto.max` : if `f` tends to `a` and `g` tends to `b`, then their pointwise `min`/`max` tend to `min a b` and `max a b`, respectively. * `tendsto_of_tendsto_of_tendsto_of_le_of_le` : theorem known as squeeze theorem, sandwich theorem, theorem of Carabinieri, and two policemen (and a drunk) theorem; if `g` and `h` both converge to `a`, and eventually `g x ≤ f x ≤ h x`, then `f` converges to `a`. ### Connected sets and Intermediate Value Theorem * `is_preconnected_I??` : all intervals `I??` are preconnected, * `is_preconnected.intermediate_value`, `intermediate_value_univ` : Intermediate Value Theorem for connected sets and connected spaces, respectively; * `intermediate_value_Icc`, `intermediate_value_Icc'`: Intermediate Value Theorem for functions on closed intervals. ### Miscellaneous facts * `is_compact.exists_forall_le`, `is_compact.exists_forall_ge` : extreme value theorem, a continuous function on a compact set takes its minimum and maximum values. * `is_closed.Icc_subset_of_forall_mem_nhds_within` : “Continuous induction” principle; if `s ∩ [a, b]` is closed, `a ∈ s`, and for each `x ∈ [a, b) ∩ s` some of its right neighborhoods is included `s`, then `[a, b] ⊆ s`. * `is_closed.Icc_subset_of_forall_exists_gt`, `is_closed.mem_of_ge_of_forall_exists_gt` : two other versions of the “continuous induction” principle. ## Implementation We do _not_ register the order topology as an instance on a preorder (or even on a linear order). Indeed, on many such spaces, a topology has already been constructed in a different way (think of the discrete spaces `ℕ` or `ℤ`, or `ℝ` that could inherit a topology as the completion of `ℚ`), and is in general not defeq to the one generated by the intervals. We make it available as a definition `preorder.topology α` though, that can be registered as an instance when necessary, or for specific types. -/ open classical set filter topological_space open function open_locale topological_space classical filter universes u v w variables {α : Type u} {β : Type v} {γ : Type w} /-- A topology on a set which is both a topological space and a preorder is _order-closed_ if the set of points `(x, y)` with `x ≤ y` is closed in the product space. We introduce this as a mixin. This property is satisfied for the order topology on a linear order, but it can be satisfied more generally, and suffices to derive many interesting properties relating order and topology. -/ class order_closed_topology (α : Type*) [topological_space α] [preorder α] : Prop := (is_closed_le' : is_closed {p:α×α | p.1 ≤ p.2}) instance : Π [topological_space α], topological_space (order_dual α) := id @[to_additive] instance [topological_space α] [has_mul α] [h : has_continuous_mul α] : has_continuous_mul (order_dual α) := h section order_closed_topology section preorder variables [topological_space α] [preorder α] [t : order_closed_topology α] include t lemma is_closed_le_prod : is_closed {p : α × α | p.1 ≤ p.2} := t.is_closed_le' lemma is_closed_le [topological_space β] {f g : β → α} (hf : continuous f) (hg : continuous g) : is_closed {b | f b ≤ g b} := continuous_iff_is_closed.mp (hf.prod_mk hg) _ is_closed_le_prod lemma is_closed_le' (a : α) : is_closed {b | b ≤ a} := is_closed_le continuous_id continuous_const lemma is_closed_Iic {a : α} : is_closed (Iic a) := is_closed_le' a lemma is_closed_ge' (a : α) : is_closed {b | a ≤ b} := is_closed_le continuous_const continuous_id lemma is_closed_Ici {a : α} : is_closed (Ici a) := is_closed_ge' a instance : order_closed_topology (order_dual α) := ⟨(@order_closed_topology.is_closed_le' α _ _ _).preimage continuous_swap⟩ lemma is_closed_Icc {a b : α} : is_closed (Icc a b) := is_closed.inter is_closed_Ici is_closed_Iic @[simp] lemma closure_Icc (a b : α) : closure (Icc a b) = Icc a b := is_closed_Icc.closure_eq @[simp] lemma closure_Iic (a : α) : closure (Iic a) = Iic a := is_closed_Iic.closure_eq @[simp] lemma closure_Ici (a : α) : closure (Ici a) = Ici a := is_closed_Ici.closure_eq lemma le_of_tendsto_of_tendsto {f g : β → α} {b : filter β} {a₁ a₂ : α} [ne_bot b] (hf : tendsto f b (𝓝 a₁)) (hg : tendsto g b (𝓝 a₂)) (h : f ≤ᶠ[b] g) : a₁ ≤ a₂ := have tendsto (λb, (f b, g b)) b (𝓝 (a₁, a₂)), by rw [nhds_prod_eq]; exact hf.prod_mk hg, show (a₁, a₂) ∈ {p:α×α | p.1 ≤ p.2}, from t.is_closed_le'.mem_of_tendsto this h lemma le_of_tendsto_of_tendsto' {f g : β → α} {b : filter β} {a₁ a₂ : α} [ne_bot b] (hf : tendsto f b (𝓝 a₁)) (hg : tendsto g b (𝓝 a₂)) (h : ∀ x, f x ≤ g x) : a₁ ≤ a₂ := le_of_tendsto_of_tendsto hf hg (eventually_of_forall h) lemma le_of_tendsto {f : β → α} {a b : α} {x : filter β} [ne_bot x] (lim : tendsto f x (𝓝 a)) (h : ∀ᶠ c in x, f c ≤ b) : a ≤ b := le_of_tendsto_of_tendsto lim tendsto_const_nhds h lemma le_of_tendsto' {f : β → α} {a b : α} {x : filter β} [ne_bot x] (lim : tendsto f x (𝓝 a)) (h : ∀ c, f c ≤ b) : a ≤ b := le_of_tendsto lim (eventually_of_forall h) lemma ge_of_tendsto {f : β → α} {a b : α} {x : filter β} [ne_bot x] (lim : tendsto f x (𝓝 a)) (h : ∀ᶠ c in x, b ≤ f c) : b ≤ a := le_of_tendsto_of_tendsto tendsto_const_nhds lim h lemma ge_of_tendsto' {f : β → α} {a b : α} {x : filter β} [ne_bot x] (lim : tendsto f x (𝓝 a)) (h : ∀ c, b ≤ f c) : b ≤ a := ge_of_tendsto lim (eventually_of_forall h) @[simp] lemma closure_le_eq [topological_space β] {f g : β → α} (hf : continuous f) (hg : continuous g) : closure {b | f b ≤ g b} = {b | f b ≤ g b} := (is_closed_le hf hg).closure_eq lemma closure_lt_subset_le [topological_space β] {f g : β → α} (hf : continuous f) (hg : continuous g) : closure {b | f b < g b} ⊆ {b | f b ≤ g b} := by { rw [←closure_le_eq hf hg], exact closure_mono (λ b, le_of_lt) } lemma continuous_within_at.closure_le [topological_space β] {f g : β → α} {s : set β} {x : β} (hx : x ∈ closure s) (hf : continuous_within_at f s x) (hg : continuous_within_at g s x) (h : ∀ y ∈ s, f y ≤ g y) : f x ≤ g x := show (f x, g x) ∈ {p : α × α | p.1 ≤ p.2}, from order_closed_topology.is_closed_le'.closure_subset ((hf.prod hg).mem_closure hx h) /-- If `s` is a closed set and two functions `f` and `g` are continuous on `s`, then the set `{x ∈ s | f x ≤ g x}` is a closed set. -/ lemma is_closed.is_closed_le [topological_space β] {f g : β → α} {s : set β} (hs : is_closed s) (hf : continuous_on f s) (hg : continuous_on g s) : is_closed {x ∈ s | f x ≤ g x} := (hf.prod hg).preimage_closed_of_closed hs order_closed_topology.is_closed_le' omit t lemma nhds_within_Ici_ne_bot {a b : α} (H₂ : a ≤ b) : ne_bot (𝓝[Ici a] b) := nhds_within_ne_bot_of_mem H₂ @[instance] lemma nhds_within_Ici_self_ne_bot (a : α) : ne_bot (𝓝[Ici a] a) := nhds_within_Ici_ne_bot (le_refl a) lemma nhds_within_Iic_ne_bot {a b : α} (H : a ≤ b) : ne_bot (𝓝[Iic b] a) := nhds_within_ne_bot_of_mem H @[instance] lemma nhds_within_Iic_self_ne_bot (a : α) : ne_bot (𝓝[Iic a] a) := nhds_within_Iic_ne_bot (le_refl a) end preorder section partial_order variables [topological_space α] [partial_order α] [t : order_closed_topology α] include t private lemma is_closed_eq_aux : is_closed {p : α × α | p.1 = p.2} := by simp only [le_antisymm_iff]; exact is_closed.inter t.is_closed_le' (is_closed_le continuous_snd continuous_fst) @[priority 90] -- see Note [lower instance priority] instance order_closed_topology.to_t2_space : t2_space α := { t2 := have is_open {p : α × α | p.1 ≠ p.2} := is_closed_eq_aux.is_open_compl, assume a b h, let ⟨u, v, hu, hv, ha, hb, h⟩ := is_open_prod_iff.mp this a b h in ⟨u, v, hu, hv, ha, hb, set.eq_empty_iff_forall_not_mem.2 $ assume a ⟨h₁, h₂⟩, have a ≠ a, from @h (a, a) ⟨h₁, h₂⟩, this rfl⟩ } end partial_order section linear_order variables [topological_space α] [linear_order α] [order_closed_topology α] lemma is_open_lt_prod : is_open {p : α × α | p.1 < p.2} := by { simp_rw [← is_closed_compl_iff, compl_set_of, not_lt], exact is_closed_le continuous_snd continuous_fst } lemma is_open_lt [topological_space β] {f g : β → α} (hf : continuous f) (hg : continuous g) : is_open {b | f b < g b} := by simp [lt_iff_not_ge, -not_le]; exact (is_closed_le hg hf).is_open_compl variables {a b : α} lemma is_open_Iio : is_open (Iio a) := is_open_lt continuous_id continuous_const lemma is_open_Ioi : is_open (Ioi a) := is_open_lt continuous_const continuous_id lemma is_open_Ioo : is_open (Ioo a b) := is_open.inter is_open_Ioi is_open_Iio @[simp] lemma interior_Ioi : interior (Ioi a) = Ioi a := is_open_Ioi.interior_eq @[simp] lemma interior_Iio : interior (Iio a) = Iio a := is_open_Iio.interior_eq @[simp] lemma interior_Ioo : interior (Ioo a b) = Ioo a b := is_open_Ioo.interior_eq lemma eventually_le_of_tendsto_lt {l : filter γ} {f : γ → α} {u v : α} (hv : v < u) (h : tendsto f l (𝓝 v)) : ∀ᶠ a in l, f a ≤ u := eventually.mono (tendsto_nhds.1 h (< u) is_open_Iio hv) (λ v, le_of_lt) lemma eventually_ge_of_tendsto_gt {l : filter γ} {f : γ → α} {u v : α} (hv : u < v) (h : tendsto f l (𝓝 v)) : ∀ᶠ a in l, u ≤ f a := eventually.mono (tendsto_nhds.1 h (> u) is_open_Ioi hv) (λ v, le_of_lt) variables [topological_space γ] /-- Intermediate value theorem for two functions: if `f` and `g` are two continuous functions on a preconnected space and `f a ≤ g a` and `g b ≤ f b`, then for some `x` we have `f x = g x`. -/ lemma intermediate_value_univ₂ [preconnected_space γ] {a b : γ} {f g : γ → α} (hf : continuous f) (hg : continuous g) (ha : f a ≤ g a) (hb : g b ≤ f b) : ∃ x, f x = g x := begin obtain ⟨x, h, hfg, hgf⟩ : (univ ∩ {x | f x ≤ g x ∧ g x ≤ f x}).nonempty, from is_preconnected_closed_iff.1 preconnected_space.is_preconnected_univ _ _ (is_closed_le hf hg) (is_closed_le hg hf) (λ x hx, le_total _ _) ⟨a, trivial, ha⟩ ⟨b, trivial, hb⟩, exact ⟨x, le_antisymm hfg hgf⟩ end lemma intermediate_value_univ₂_eventually₁ [preconnected_space γ] {a : γ} {l : filter γ} [ne_bot l] {f g : γ → α} (hf : continuous f) (hg : continuous g) (ha : f a ≤ g a) (he : g ≤ᶠ[l] f) : ∃ x, f x = g x := let ⟨c, hc⟩ := he.frequently.exists in intermediate_value_univ₂ hf hg ha hc lemma intermediate_value_univ₂_eventually₂ [preconnected_space γ] {l₁ l₂ : filter γ} [ne_bot l₁] [ne_bot l₂] {f g : γ → α} (hf : continuous f) (hg : continuous g) (he₁ : f ≤ᶠ[l₁] g ) (he₂ : g ≤ᶠ[l₂] f) : ∃ x, f x = g x := let ⟨c₁, hc₁⟩ := he₁.frequently.exists, ⟨c₂, hc₂⟩ := he₂.frequently.exists in intermediate_value_univ₂ hf hg hc₁ hc₂ /-- Intermediate value theorem for two functions: if `f` and `g` are two functions continuous on a preconnected set `s` and for some `a b ∈ s` we have `f a ≤ g a` and `g b ≤ f b`, then for some `x ∈ s` we have `f x = g x`. -/ lemma is_preconnected.intermediate_value₂ {s : set γ} (hs : is_preconnected s) {a b : γ} (ha : a ∈ s) (hb : b ∈ s) {f g : γ → α} (hf : continuous_on f s) (hg : continuous_on g s) (ha' : f a ≤ g a) (hb' : g b ≤ f b) : ∃ x ∈ s, f x = g x := let ⟨x, hx⟩ := @intermediate_value_univ₂ α s _ _ _ _ (subtype.preconnected_space hs) ⟨a, ha⟩ ⟨b, hb⟩ _ _ (continuous_on_iff_continuous_restrict.1 hf) (continuous_on_iff_continuous_restrict.1 hg) ha' hb' in ⟨x, x.2, hx⟩ lemma is_preconnected.intermediate_value₂_eventually₁ {s : set γ} (hs : is_preconnected s) {a : γ} {l : filter γ} (ha : a ∈ s) [ne_bot l] (hl : l ≤ 𝓟 s) {f g : γ → α} (hf : continuous_on f s) (hg : continuous_on g s) (ha' : f a ≤ g a) (he : g ≤ᶠ[l] f) : ∃ x ∈ s, f x = g x := begin rw continuous_on_iff_continuous_restrict at hf hg, obtain ⟨b, h⟩ := @intermediate_value_univ₂_eventually₁ _ _ _ _ _ _ (subtype.preconnected_space hs) ⟨a, ha⟩ _ (comap_coe_ne_bot_of_le_principal hl) _ _ hf hg ha' (eventually_comap' he), exact ⟨b, b.prop, h⟩, end lemma is_preconnected.intermediate_value₂_eventually₂ {s : set γ} (hs : is_preconnected s) {l₁ l₂ : filter γ} [ne_bot l₁] [ne_bot l₂] (hl₁ : l₁ ≤ 𝓟 s) (hl₂ : l₂ ≤ 𝓟 s) {f g : γ → α} (hf : continuous_on f s) (hg : continuous_on g s) (he₁ : f ≤ᶠ[l₁] g) (he₂ : g ≤ᶠ[l₂] f) : ∃ x ∈ s, f x = g x := begin rw continuous_on_iff_continuous_restrict at hf hg, obtain ⟨b, h⟩ := @intermediate_value_univ₂_eventually₂ _ _ _ _ _ _ (subtype.preconnected_space hs) _ _ (comap_coe_ne_bot_of_le_principal hl₁) (comap_coe_ne_bot_of_le_principal hl₂) _ _ hf hg (eventually_comap' he₁) (eventually_comap' he₂), exact ⟨b, b.prop, h⟩, end /-- Intermediate Value Theorem for continuous functions on connected sets. -/ lemma is_preconnected.intermediate_value {s : set γ} (hs : is_preconnected s) {a b : γ} (ha : a ∈ s) (hb : b ∈ s) {f : γ → α} (hf : continuous_on f s) : Icc (f a) (f b) ⊆ f '' s := λ x hx, mem_image_iff_bex.2 $ hs.intermediate_value₂ ha hb hf continuous_on_const hx.1 hx.2 lemma is_preconnected.intermediate_value_Ico {s : set γ} (hs : is_preconnected s) {a : γ} {l : filter γ} (ha : a ∈ s) [ne_bot l] (hl : l ≤ 𝓟 s) {f : γ → α} (hf : continuous_on f s) {v : α} (ht : tendsto f l (𝓝 v)) : Ico (f a) v ⊆ f '' s := λ y h, bex_def.1 $ hs.intermediate_value₂_eventually₁ ha hl hf continuous_on_const h.1 (eventually_ge_of_tendsto_gt h.2 ht) lemma is_preconnected.intermediate_value_Ioc {s : set γ} (hs : is_preconnected s) {a : γ} {l : filter γ} (ha : a ∈ s) [ne_bot l] (hl : l ≤ 𝓟 s) {f : γ → α} (hf : continuous_on f s) {v : α} (ht : tendsto f l (𝓝 v)) : Ioc v (f a) ⊆ f '' s := λ y h, bex_def.1 $ bex.imp_right (λ x _, eq.symm) $ hs.intermediate_value₂_eventually₁ ha hl continuous_on_const hf h.2 (eventually_le_of_tendsto_lt h.1 ht) lemma is_preconnected.intermediate_value_Ioo {s : set γ} (hs : is_preconnected s) {l₁ l₂ : filter γ} [ne_bot l₁] [ne_bot l₂] (hl₁ : l₁ ≤ 𝓟 s) (hl₂ : l₂ ≤ 𝓟 s) {f : γ → α} (hf : continuous_on f s) {v₁ v₂ : α} (ht₁ : tendsto f l₁ (𝓝 v₁)) (ht₂ : tendsto f l₂ (𝓝 v₂)) : Ioo v₁ v₂ ⊆ f '' s := λ y h, bex_def.1 $ hs.intermediate_value₂_eventually₂ hl₁ hl₂ hf continuous_on_const (eventually_le_of_tendsto_lt h.1 ht₁) (eventually_ge_of_tendsto_gt h.2 ht₂) lemma is_preconnected.intermediate_value_Ici {s : set γ} (hs : is_preconnected s) {a : γ} {l : filter γ} (ha : a ∈ s) [ne_bot l] (hl : l ≤ 𝓟 s) {f : γ → α} (hf : continuous_on f s) (ht : tendsto f l at_top) : Ici (f a) ⊆ f '' s := λ y h, bex_def.1 $ hs.intermediate_value₂_eventually₁ ha hl hf continuous_on_const h (tendsto_at_top.1 ht y) lemma is_preconnected.intermediate_value_Iic {s : set γ} (hs : is_preconnected s) {a : γ} {l : filter γ} (ha : a ∈ s) [ne_bot l] (hl : l ≤ 𝓟 s) {f : γ → α} (hf : continuous_on f s) (ht : tendsto f l at_bot) : Iic (f a) ⊆ f '' s := λ y h, bex_def.1 $ bex.imp_right (λ x _, eq.symm) $ hs.intermediate_value₂_eventually₁ ha hl continuous_on_const hf h (tendsto_at_bot.1 ht y) lemma is_preconnected.intermediate_value_Ioi {s : set γ} (hs : is_preconnected s) {l₁ l₂ : filter γ} [ne_bot l₁] [ne_bot l₂] (hl₁ : l₁ ≤ 𝓟 s) (hl₂ : l₂ ≤ 𝓟 s) {f : γ → α} (hf : continuous_on f s) {v : α} (ht₁ : tendsto f l₁ (𝓝 v)) (ht₂ : tendsto f l₂ at_top) : Ioi v ⊆ f '' s := λ y h, bex_def.1 $ hs.intermediate_value₂_eventually₂ hl₁ hl₂ hf continuous_on_const (eventually_le_of_tendsto_lt h ht₁) (tendsto_at_top.1 ht₂ y) lemma is_preconnected.intermediate_value_Iio {s : set γ} (hs : is_preconnected s) {l₁ l₂ : filter γ} [ne_bot l₁] [ne_bot l₂] (hl₁ : l₁ ≤ 𝓟 s) (hl₂ : l₂ ≤ 𝓟 s) {f : γ → α} (hf : continuous_on f s) {v : α} (ht₁ : tendsto f l₁ at_bot) (ht₂ : tendsto f l₂ (𝓝 v)) : Iio v ⊆ f '' s := λ y h, bex_def.1 $ hs.intermediate_value₂_eventually₂ hl₁ hl₂ hf continuous_on_const (tendsto_at_bot.1 ht₁ y) (eventually_ge_of_tendsto_gt h ht₂) lemma is_preconnected.intermediate_value_Iii {s : set γ} (hs : is_preconnected s) {l₁ l₂ : filter γ} [ne_bot l₁] [ne_bot l₂] (hl₁ : l₁ ≤ 𝓟 s) (hl₂ : l₂ ≤ 𝓟 s) {f : γ → α} (hf : continuous_on f s) (ht₁ : tendsto f l₁ at_bot) (ht₂ : tendsto f l₂ at_top) : univ ⊆ f '' s := λ y h, bex_def.1 $ hs.intermediate_value₂_eventually₂ hl₁ hl₂ hf continuous_on_const (tendsto_at_bot.1 ht₁ y) (tendsto_at_top.1 ht₂ y) /-- Intermediate Value Theorem for continuous functions on connected spaces. -/ lemma intermediate_value_univ [preconnected_space γ] (a b : γ) {f : γ → α} (hf : continuous f) : Icc (f a) (f b) ⊆ range f := λ x hx, intermediate_value_univ₂ hf continuous_const hx.1 hx.2 /-- Intermediate Value Theorem for continuous functions on connected spaces. -/ lemma mem_range_of_exists_le_of_exists_ge [preconnected_space γ] {c : α} {f : γ → α} (hf : continuous f) (h₁ : ∃ a, f a ≤ c) (h₂ : ∃ b, c ≤ f b) : c ∈ range f := let ⟨a, ha⟩ := h₁, ⟨b, hb⟩ := h₂ in intermediate_value_univ a b hf ⟨ha, hb⟩ /-- If a preconnected set contains endpoints of an interval, then it includes the whole interval. -/ lemma is_preconnected.Icc_subset {s : set α} (hs : is_preconnected s) {a b : α} (ha : a ∈ s) (hb : b ∈ s) : Icc a b ⊆ s := by simpa only [image_id] using hs.intermediate_value ha hb continuous_on_id /-- If a preconnected set contains endpoints of an interval, then it includes the whole interval. -/ lemma is_connected.Icc_subset {s : set α} (hs : is_connected s) {a b : α} (ha : a ∈ s) (hb : b ∈ s) : Icc a b ⊆ s := hs.2.Icc_subset ha hb /-- If preconnected set in a linear order space is unbounded below and above, then it is the whole space. -/ lemma is_preconnected.eq_univ_of_unbounded {s : set α} (hs : is_preconnected s) (hb : ¬bdd_below s) (ha : ¬bdd_above s) : s = univ := begin refine eq_univ_of_forall (λ x, _), obtain ⟨y, ys, hy⟩ : ∃ y ∈ s, y < x := not_bdd_below_iff.1 hb x, obtain ⟨z, zs, hz⟩ : ∃ z ∈ s, x < z := not_bdd_above_iff.1 ha x, exact hs.Icc_subset ys zs ⟨le_of_lt hy, le_of_lt hz⟩ end /-! ### Neighborhoods to the left and to the right on an `order_closed_topology` Limits to the left and to the right of real functions are defined in terms of neighborhoods to the left and to the right, either open or closed, i.e., members of `𝓝[Ioi a] a` and `𝓝[Ici a] a` on the right, and similarly on the left. Here we simply prove that all right-neighborhoods of a point are equal, and we'll prove later other useful characterizations which require the stronger hypothesis `order_topology α` -/ /-! #### Right neighborhoods, point excluded -/ lemma Ioo_mem_nhds_within_Ioi {a b c : α} (H : b ∈ Ico a c) : Ioo a c ∈ 𝓝[Ioi b] b := mem_nhds_within.2 ⟨Iio c, is_open_Iio, H.2, by rw [inter_comm, Ioi_inter_Iio]; exact Ioo_subset_Ioo_left H.1⟩ lemma Ioc_mem_nhds_within_Ioi {a b c : α} (H : b ∈ Ico a c) : Ioc a c ∈ 𝓝[Ioi b] b := mem_sets_of_superset (Ioo_mem_nhds_within_Ioi H) Ioo_subset_Ioc_self lemma Ico_mem_nhds_within_Ioi {a b c : α} (H : b ∈ Ico a c) : Ico a c ∈ 𝓝[Ioi b] b := mem_sets_of_superset (Ioo_mem_nhds_within_Ioi H) Ioo_subset_Ico_self lemma Icc_mem_nhds_within_Ioi {a b c : α} (H : b ∈ Ico a c) : Icc a c ∈ 𝓝[Ioi b] b := mem_sets_of_superset (Ioo_mem_nhds_within_Ioi H) Ioo_subset_Icc_self @[simp] lemma nhds_within_Ioc_eq_nhds_within_Ioi {a b : α} (h : a < b) : 𝓝[Ioc a b] a = 𝓝[Ioi a] a := le_antisymm (nhds_within_mono _ Ioc_subset_Ioi_self) $ nhds_within_le_of_mem $ Ioc_mem_nhds_within_Ioi $ left_mem_Ico.2 h @[simp] lemma nhds_within_Ioo_eq_nhds_within_Ioi {a b : α} (h : a < b) : 𝓝[Ioo a b] a = 𝓝[Ioi a] a := le_antisymm (nhds_within_mono _ Ioo_subset_Ioi_self) $ nhds_within_le_of_mem $ Ioo_mem_nhds_within_Ioi $ left_mem_Ico.2 h @[simp] lemma continuous_within_at_Ioc_iff_Ioi [topological_space β] {a b : α} {f : α → β} (h : a < b) : continuous_within_at f (Ioc a b) a ↔ continuous_within_at f (Ioi a) a := by simp only [continuous_within_at, nhds_within_Ioc_eq_nhds_within_Ioi h] @[simp] lemma continuous_within_at_Ioo_iff_Ioi [topological_space β] {a b : α} {f : α → β} (h : a < b) : continuous_within_at f (Ioo a b) a ↔ continuous_within_at f (Ioi a) a := by simp only [continuous_within_at, nhds_within_Ioo_eq_nhds_within_Ioi h] /-! #### Left neighborhoods, point excluded -/ lemma Ioo_mem_nhds_within_Iio {a b c : α} (H : b ∈ Ioc a c) : Ioo a c ∈ 𝓝[Iio b] b := by simpa only [dual_Ioo] using @Ioo_mem_nhds_within_Ioi (order_dual α) _ _ _ _ _ _ ⟨H.2, H.1⟩ lemma Ico_mem_nhds_within_Iio {a b c : α} (H : b ∈ Ioc a c) : Ico a c ∈ 𝓝[Iio b] b := mem_sets_of_superset (Ioo_mem_nhds_within_Iio H) Ioo_subset_Ico_self lemma Ioc_mem_nhds_within_Iio {a b c : α} (H : b ∈ Ioc a c) : Ioc a c ∈ 𝓝[Iio b] b := mem_sets_of_superset (Ioo_mem_nhds_within_Iio H) Ioo_subset_Ioc_self lemma Icc_mem_nhds_within_Iio {a b c : α} (H : b ∈ Ioc a c) : Icc a c ∈ 𝓝[Iio b] b := mem_sets_of_superset (Ioo_mem_nhds_within_Iio H) Ioo_subset_Icc_self @[simp] lemma nhds_within_Ico_eq_nhds_within_Iio {a b : α} (h : a < b) : 𝓝[Ico a b] b = 𝓝[Iio b] b := by simpa only [dual_Ioc] using @nhds_within_Ioc_eq_nhds_within_Ioi (order_dual α) _ _ _ _ _ h @[simp] lemma nhds_within_Ioo_eq_nhds_within_Iio {a b : α} (h : a < b) : 𝓝[Ioo a b] b = 𝓝[Iio b] b := by simpa only [dual_Ioo] using @nhds_within_Ioo_eq_nhds_within_Ioi (order_dual α) _ _ _ _ _ h @[simp] lemma continuous_within_at_Ico_iff_Iio {a b : α} {f : α → γ} (h : a < b) : continuous_within_at f (Ico a b) b ↔ continuous_within_at f (Iio b) b := by simp only [continuous_within_at, nhds_within_Ico_eq_nhds_within_Iio h] @[simp] lemma continuous_within_at_Ioo_iff_Iio {a b : α} {f : α → γ} (h : a < b) : continuous_within_at f (Ioo a b) b ↔ continuous_within_at f (Iio b) b := by simp only [continuous_within_at, nhds_within_Ioo_eq_nhds_within_Iio h] /-! #### Right neighborhoods, point included -/ lemma Ioo_mem_nhds_within_Ici {a b c : α} (H : b ∈ Ioo a c) : Ioo a c ∈ 𝓝[Ici b] b := mem_nhds_within_of_mem_nhds $ is_open.mem_nhds is_open_Ioo H lemma Ioc_mem_nhds_within_Ici {a b c : α} (H : b ∈ Ioo a c) : Ioc a c ∈ 𝓝[Ici b] b := mem_sets_of_superset (Ioo_mem_nhds_within_Ici H) Ioo_subset_Ioc_self lemma Ico_mem_nhds_within_Ici {a b c : α} (H : b ∈ Ico a c) : Ico a c ∈ 𝓝[Ici b] b := mem_nhds_within.2 ⟨Iio c, is_open_Iio, H.2, by simp only [inter_comm, Ici_inter_Iio, Ico_subset_Ico_left H.1]⟩ lemma Icc_mem_nhds_within_Ici {a b c : α} (H : b ∈ Ico a c) : Icc a c ∈ 𝓝[Ici b] b := mem_sets_of_superset (Ico_mem_nhds_within_Ici H) Ico_subset_Icc_self @[simp] lemma nhds_within_Icc_eq_nhds_within_Ici {a b : α} (h : a < b) : 𝓝[Icc a b] a = 𝓝[Ici a] a := le_antisymm (nhds_within_mono _ Icc_subset_Ici_self) $ nhds_within_le_of_mem $ Icc_mem_nhds_within_Ici $ left_mem_Ico.2 h @[simp] lemma nhds_within_Ico_eq_nhds_within_Ici {a b : α} (h : a < b) : 𝓝[Ico a b] a = 𝓝[Ici a] a := le_antisymm (nhds_within_mono _ (λ x, and.left)) $ nhds_within_le_of_mem $ Ico_mem_nhds_within_Ici $ left_mem_Ico.2 h @[simp] lemma continuous_within_at_Icc_iff_Ici [topological_space β] {a b : α} {f : α → β} (h : a < b) : continuous_within_at f (Icc a b) a ↔ continuous_within_at f (Ici a) a := by simp only [continuous_within_at, nhds_within_Icc_eq_nhds_within_Ici h] @[simp] lemma continuous_within_at_Ico_iff_Ici [topological_space β] {a b : α} {f : α → β} (h : a < b) : continuous_within_at f (Ico a b) a ↔ continuous_within_at f (Ici a) a := by simp only [continuous_within_at, nhds_within_Ico_eq_nhds_within_Ici h] /-! #### Left neighborhoods, point included -/ lemma Ioo_mem_nhds_within_Iic {a b c : α} (H : b ∈ Ioo a c) : Ioo a c ∈ 𝓝[Iic b] b := mem_nhds_within_of_mem_nhds $ is_open.mem_nhds is_open_Ioo H lemma Ico_mem_nhds_within_Iic {a b c : α} (H : b ∈ Ioo a c) : Ico a c ∈ 𝓝[Iic b] b := mem_sets_of_superset (Ioo_mem_nhds_within_Iic H) Ioo_subset_Ico_self lemma Ioc_mem_nhds_within_Iic {a b c : α} (H : b ∈ Ioc a c) : Ioc a c ∈ 𝓝[Iic b] b := by simpa only [dual_Ico] using @Ico_mem_nhds_within_Ici (order_dual α) _ _ _ _ _ _ ⟨H.2, H.1⟩ lemma Icc_mem_nhds_within_Iic {a b c : α} (H : b ∈ Ioc a c) : Icc a c ∈ 𝓝[Iic b] b := mem_sets_of_superset (Ioc_mem_nhds_within_Iic H) Ioc_subset_Icc_self @[simp] lemma nhds_within_Icc_eq_nhds_within_Iic {a b : α} (h : a < b) : 𝓝[Icc a b] b = 𝓝[Iic b] b := by simpa only [dual_Icc] using @nhds_within_Icc_eq_nhds_within_Ici (order_dual α) _ _ _ _ _ h @[simp] lemma nhds_within_Ioc_eq_nhds_within_Iic {a b : α} (h : a < b) : 𝓝[Ioc a b] b = 𝓝[Iic b] b := by simpa only [dual_Ico] using @nhds_within_Ico_eq_nhds_within_Ici (order_dual α) _ _ _ _ _ h @[simp] lemma continuous_within_at_Icc_iff_Iic [topological_space β] {a b : α} {f : α → β} (h : a < b) : continuous_within_at f (Icc a b) b ↔ continuous_within_at f (Iic b) b := by simp only [continuous_within_at, nhds_within_Icc_eq_nhds_within_Iic h] @[simp] lemma continuous_within_at_Ioc_iff_Iic [topological_space β] {a b : α} {f : α → β} (h : a < b) : continuous_within_at f (Ioc a b) b ↔ continuous_within_at f (Iic b) b := by simp only [continuous_within_at, nhds_within_Ioc_eq_nhds_within_Iic h] end linear_order section linear_order variables [topological_space α] [linear_order α] [order_closed_topology α] {f g : β → α} section variables [topological_space β] lemma frontier_le_subset_eq (hf : continuous f) (hg : continuous g) : frontier {b | f b ≤ g b} ⊆ {b | f b = g b} := begin rw [frontier_eq_closure_inter_closure, closure_le_eq hf hg], rintros b ⟨hb₁, hb₂⟩, refine le_antisymm hb₁ (closure_lt_subset_le hg hf _), convert hb₂ using 2, simp only [not_le.symm], refl end lemma frontier_Iic_subset (a : α) : frontier (Iic a) ⊆ {a} := frontier_le_subset_eq (@continuous_id α _) continuous_const lemma frontier_Ici_subset (a : α) : frontier (Ici a) ⊆ {a} := @frontier_Iic_subset (order_dual α) _ _ _ _ lemma frontier_lt_subset_eq (hf : continuous f) (hg : continuous g) : frontier {b | f b < g b} ⊆ {b | f b = g b} := by rw ← frontier_compl; convert frontier_le_subset_eq hg hf; simp [ext_iff, eq_comm] lemma continuous_if_le [topological_space γ] [Π x, decidable (f x ≤ g x)] {f' g' : β → γ} (hf : continuous f) (hg : continuous g) (hf' : continuous_on f' {x | f x ≤ g x}) (hg' : continuous_on g' {x | g x ≤ f x}) (hfg : ∀ x, f x = g x → f' x = g' x) : continuous (λ x, if f x ≤ g x then f' x else g' x) := begin refine continuous_if (λ a ha, hfg _ (frontier_le_subset_eq hf hg ha)) _ (hg'.mono _), { rwa [(is_closed_le hf hg).closure_eq] }, { simp only [not_le], exact closure_lt_subset_le hg hf } end lemma continuous.if_le [topological_space γ] [Π x, decidable (f x ≤ g x)] {f' g' : β → γ} (hf' : continuous f') (hg' : continuous g') (hf : continuous f) (hg : continuous g) (hfg : ∀ x, f x = g x → f' x = g' x) : continuous (λ x, if f x ≤ g x then f' x else g' x) := continuous_if_le hf hg hf'.continuous_on hg'.continuous_on hfg @[continuity] lemma continuous.min (hf : continuous f) (hg : continuous g) : continuous (λb, min (f b) (g b)) := hf.if_le hg hf hg (λ x, id) @[continuity] lemma continuous.max (hf : continuous f) (hg : continuous g) : continuous (λb, max (f b) (g b)) := @continuous.min (order_dual α) _ _ _ _ _ _ _ hf hg end lemma continuous_min : continuous (λ p : α × α, min p.1 p.2) := continuous_fst.min continuous_snd lemma continuous_max : continuous (λ p : α × α, max p.1 p.2) := continuous_fst.max continuous_snd lemma filter.tendsto.max {b : filter β} {a₁ a₂ : α} (hf : tendsto f b (𝓝 a₁)) (hg : tendsto g b (𝓝 a₂)) : tendsto (λb, max (f b) (g b)) b (𝓝 (max a₁ a₂)) := (continuous_max.tendsto (a₁, a₂)).comp (hf.prod_mk_nhds hg) lemma filter.tendsto.min {b : filter β} {a₁ a₂ : α} (hf : tendsto f b (𝓝 a₁)) (hg : tendsto g b (𝓝 a₂)) : tendsto (λb, min (f b) (g b)) b (𝓝 (min a₁ a₂)) := (continuous_min.tendsto (a₁, a₂)).comp (hf.prod_mk_nhds hg) end linear_order end order_closed_topology /-- The order topology on an ordered type is the topology generated by open intervals. We register it on a preorder, but it is mostly interesting in linear orders, where it is also order-closed. We define it as a mixin. If you want to introduce the order topology on a preorder, use `preorder.topology`. -/ class order_topology (α : Type*) [t : topological_space α] [preorder α] : Prop := (topology_eq_generate_intervals : t = generate_from {s | ∃a, s = Ioi a ∨ s = Iio a}) /-- (Order) topology on a partial order `α` generated by the subbase of open intervals `(a, ∞) = { x ∣ a < x }, (-∞ , b) = {x ∣ x < b}` for all `a, b` in `α`. We do not register it as an instance as many ordered sets are already endowed with the same topology, most often in a non-defeq way though. Register as a local instance when necessary. -/ def preorder.topology (α : Type*) [preorder α] : topological_space α := generate_from {s : set α | ∃ (a : α), s = {b : α | a < b} ∨ s = {b : α | b < a}} section order_topology instance {α : Type*} [topological_space α] [partial_order α] [order_topology α] : order_topology (order_dual α) := ⟨by convert @order_topology.topology_eq_generate_intervals α _ _ _; conv in (_ ∨ _) { rw or.comm }; refl⟩ section partial_order variables [topological_space α] [partial_order α] [t : order_topology α] include t lemma is_open_iff_generate_intervals {s : set α} : is_open s ↔ generate_open {s | ∃a, s = Ioi a ∨ s = Iio a} s := by rw [t.topology_eq_generate_intervals]; refl lemma is_open_lt' (a : α) : is_open {b:α | a < b} := by rw [@is_open_iff_generate_intervals α _ _ t]; exact generate_open.basic _ ⟨a, or.inl rfl⟩ lemma is_open_gt' (a : α) : is_open {b:α | b < a} := by rw [@is_open_iff_generate_intervals α _ _ t]; exact generate_open.basic _ ⟨a, or.inr rfl⟩ lemma lt_mem_nhds {a b : α} (h : a < b) : ∀ᶠ x in 𝓝 b, a < x := is_open.mem_nhds (is_open_lt' _) h lemma le_mem_nhds {a b : α} (h : a < b) : ∀ᶠ x in 𝓝 b, a ≤ x := (𝓝 b).sets_of_superset (lt_mem_nhds h) $ assume b hb, le_of_lt hb lemma gt_mem_nhds {a b : α} (h : a < b) : ∀ᶠ x in 𝓝 a, x < b := is_open.mem_nhds (is_open_gt' _) h lemma ge_mem_nhds {a b : α} (h : a < b) : ∀ᶠ x in 𝓝 a, x ≤ b := (𝓝 a).sets_of_superset (gt_mem_nhds h) $ assume b hb, le_of_lt hb lemma nhds_eq_order (a : α) : 𝓝 a = (⨅b ∈ Iio a, 𝓟 (Ioi b)) ⊓ (⨅b ∈ Ioi a, 𝓟 (Iio b)) := by rw [t.topology_eq_generate_intervals, nhds_generate_from]; from le_antisymm (le_inf (le_binfi $ assume b hb, infi_le_of_le {c : α | b < c} $ infi_le _ ⟨hb, b, or.inl rfl⟩) (le_binfi $ assume b hb, infi_le_of_le {c : α | c < b} $ infi_le _ ⟨hb, b, or.inr rfl⟩)) (le_infi $ assume s, le_infi $ assume ⟨ha, b, hs⟩, match s, ha, hs with | _, h, (or.inl rfl) := inf_le_left_of_le $ infi_le_of_le b $ infi_le _ h | _, h, (or.inr rfl) := inf_le_right_of_le $ infi_le_of_le b $ infi_le _ h end) lemma tendsto_order {f : β → α} {a : α} {x : filter β} : tendsto f x (𝓝 a) ↔ (∀ a' < a, ∀ᶠ b in x, a' < f b) ∧ (∀ a' > a, ∀ᶠ b in x, f b < a') := by simp [nhds_eq_order a, tendsto_inf, tendsto_infi, tendsto_principal] instance tendsto_Icc_class_nhds (a : α) : tendsto_Ixx_class Icc (𝓝 a) (𝓝 a) := begin simp only [nhds_eq_order, infi_subtype'], refine ((has_basis_infi_principal_finite _).inf (has_basis_infi_principal_finite _)).tendsto_Ixx_class (λ s hs, _), refine ((ord_connected_bInter _).inter (ord_connected_bInter _)).out; intros _ _, exacts [ord_connected_Ioi, ord_connected_Iio] end instance tendsto_Ico_class_nhds (a : α) : tendsto_Ixx_class Ico (𝓝 a) (𝓝 a) := tendsto_Ixx_class_of_subset (λ _ _, Ico_subset_Icc_self) instance tendsto_Ioc_class_nhds (a : α) : tendsto_Ixx_class Ioc (𝓝 a) (𝓝 a) := tendsto_Ixx_class_of_subset (λ _ _, Ioc_subset_Icc_self) instance tendsto_Ioo_class_nhds (a : α) : tendsto_Ixx_class Ioo (𝓝 a) (𝓝 a) := tendsto_Ixx_class_of_subset (λ _ _, Ioo_subset_Icc_self) /-- Also known as squeeze or sandwich theorem. This version assumes that inequalities hold eventually for the filter. -/ lemma tendsto_of_tendsto_of_tendsto_of_le_of_le' {f g h : β → α} {b : filter β} {a : α} (hg : tendsto g b (𝓝 a)) (hh : tendsto h b (𝓝 a)) (hgf : ∀ᶠ b in b, g b ≤ f b) (hfh : ∀ᶠ b in b, f b ≤ h b) : tendsto f b (𝓝 a) := tendsto_order.2 ⟨assume a' h', have ∀ᶠ b in b, a' < g b, from (tendsto_order.1 hg).left a' h', by filter_upwards [this, hgf] assume a, lt_of_lt_of_le, assume a' h', have ∀ᶠ b in b, h b < a', from (tendsto_order.1 hh).right a' h', by filter_upwards [this, hfh] assume a h₁ h₂, lt_of_le_of_lt h₂ h₁⟩ /-- Also known as squeeze or sandwich theorem. This version assumes that inequalities hold everywhere. -/ lemma tendsto_of_tendsto_of_tendsto_of_le_of_le {f g h : β → α} {b : filter β} {a : α} (hg : tendsto g b (𝓝 a)) (hh : tendsto h b (𝓝 a)) (hgf : g ≤ f) (hfh : f ≤ h) : tendsto f b (𝓝 a) := tendsto_of_tendsto_of_tendsto_of_le_of_le' hg hh (eventually_of_forall hgf) (eventually_of_forall hfh) lemma nhds_order_unbounded {a : α} (hu : ∃u, a < u) (hl : ∃l, l < a) : 𝓝 a = (⨅l (h₂ : l < a) u (h₂ : a < u), 𝓟 (Ioo l u)) := have ∃ u, u ∈ Ioi a, from hu, have ∃ l, l ∈ Iio a, from hl, by { simp only [nhds_eq_order, inf_binfi, binfi_inf, *, inf_principal, Ioi_inter_Iio], refl } lemma tendsto_order_unbounded {f : β → α} {a : α} {x : filter β} (hu : ∃u, a < u) (hl : ∃l, l < a) (h : ∀l u, l < a → a < u → ∀ᶠ b in x, l < f b ∧ f b < u) : tendsto f x (𝓝 a) := by rw [nhds_order_unbounded hu hl]; from (tendsto_infi.2 $ assume l, tendsto_infi.2 $ assume hl, tendsto_infi.2 $ assume u, tendsto_infi.2 $ assume hu, tendsto_principal.2 $ h l u hl hu) end partial_order instance tendsto_Ixx_nhds_within {α : Type*} [preorder α] [topological_space α] (a : α) {s t : set α} {Ixx} [tendsto_Ixx_class Ixx (𝓝 a) (𝓝 a)] [tendsto_Ixx_class Ixx (𝓟 s) (𝓟 t)]: tendsto_Ixx_class Ixx (𝓝[s] a) (𝓝[t] a) := filter.tendsto_Ixx_class_inf instance tendsto_Icc_class_nhds_pi {ι : Type*} {α : ι → Type*} [Π i, partial_order (α i)] [Π i, topological_space (α i)] [∀ i, order_topology (α i)] (f : Π i, α i) : tendsto_Ixx_class Icc (𝓝 f) (𝓝 f) := begin constructor, conv in ((𝓝 f).lift' powerset) { rw [nhds_pi] }, simp only [lift'_infi_powerset, comap_lift'_eq2 monotone_powerset, tendsto_infi, tendsto_lift', mem_powerset_iff, subset_def, mem_preimage], intros i s hs, have : tendsto (λ g : Π i, α i, g i) (𝓝 f) (𝓝 (f i)) := ((continuous_apply i).tendsto f), refine (tendsto_lift'.1 ((this.comp tendsto_fst).Icc (this.comp tendsto_snd)) s hs).mono _, exact λ p hp g hg, hp ⟨hg.1 _, hg.2 _⟩ end theorem induced_order_topology' {α : Type u} {β : Type v} [partial_order α] [ta : topological_space β] [partial_order β] [order_topology β] (f : α → β) (hf : ∀ {x y}, f x < f y ↔ x < y) (H₁ : ∀ {a x}, x < f a → ∃ b < a, x ≤ f b) (H₂ : ∀ {a x}, f a < x → ∃ b > a, f b ≤ x) : @order_topology _ (induced f ta) _ := begin letI := induced f ta, refine ⟨eq_of_nhds_eq_nhds (λ a, _)⟩, rw [nhds_induced, nhds_generate_from, nhds_eq_order (f a)], apply le_antisymm, { refine le_infi (λ s, le_infi $ λ hs, le_principal_iff.2 _), rcases hs with ⟨ab, b, rfl|rfl⟩, { exact mem_comap_sets.2 ⟨{x | f b < x}, mem_inf_sets_of_left $ mem_infi_sets _ $ mem_infi_sets (hf.2 ab) $ mem_principal_self _, λ x, hf.1⟩ }, { exact mem_comap_sets.2 ⟨{x | x < f b}, mem_inf_sets_of_right $ mem_infi_sets _ $ mem_infi_sets (hf.2 ab) $ mem_principal_self _, λ x, hf.1⟩ } }, { rw [← map_le_iff_le_comap], refine le_inf _ _; refine le_infi (λ x, le_infi $ λ h, le_principal_iff.2 _); simp, { rcases H₁ h with ⟨b, ab, xb⟩, refine mem_infi_sets _ (mem_infi_sets ⟨ab, b, or.inl rfl⟩ (mem_principal_sets.2 _)), exact λ c hc, lt_of_le_of_lt xb (hf.2 hc) }, { rcases H₂ h with ⟨b, ab, xb⟩, refine mem_infi_sets _ (mem_infi_sets ⟨ab, b, or.inr rfl⟩ (mem_principal_sets.2 _)), exact λ c hc, lt_of_lt_of_le (hf.2 hc) xb } }, end theorem induced_order_topology {α : Type u} {β : Type v} [partial_order α] [ta : topological_space β] [partial_order β] [order_topology β] (f : α → β) (hf : ∀ {x y}, f x < f y ↔ x < y) (H : ∀ {x y}, x < y → ∃ a, x < f a ∧ f a < y) : @order_topology _ (induced f ta) _ := induced_order_topology' f @hf (λ a x xa, let ⟨b, xb, ba⟩ := H xa in ⟨b, hf.1 ba, le_of_lt xb⟩) (λ a x ax, let ⟨b, ab, bx⟩ := H ax in ⟨b, hf.1 ab, le_of_lt bx⟩) /-- On an `ord_connected` subset of a linear order, the order topology for the restriction of the order is the same as the restriction to the subset of the order topology. -/ instance order_topology_of_ord_connected {α : Type u} [ta : topological_space α] [linear_order α] [order_topology α] {t : set α} [ht : ord_connected t] : order_topology t := begin letI := induced (coe : t → α) ta, refine ⟨eq_of_nhds_eq_nhds (λ a, _)⟩, rw [nhds_induced, nhds_generate_from, nhds_eq_order (a : α)], apply le_antisymm, { refine le_infi (λ s, le_infi $ λ hs, le_principal_iff.2 _), rcases hs with ⟨ab, b, rfl|rfl⟩, { refine ⟨Ioi b, _, λ _, id⟩, refine mem_inf_sets_of_left (mem_infi_sets b _), exact mem_infi_sets ab (mem_principal_self (Ioi ↑b)) }, { refine ⟨Iio b, _, λ _, id⟩, refine mem_inf_sets_of_right (mem_infi_sets b _), exact mem_infi_sets ab (mem_principal_self (Iio b)) } }, { rw [← map_le_iff_le_comap], refine le_inf _ _, { refine le_infi (λ x, le_infi $ λ h, le_principal_iff.2 _), by_cases hx : x ∈ t, { refine mem_infi_sets (Ioi ⟨x, hx⟩) (mem_infi_sets ⟨h, ⟨⟨x, hx⟩, or.inl rfl⟩⟩ _), exact λ _, id }, simp only [set_coe.exists, mem_set_of_eq, mem_map], convert univ_sets _, suffices hx' : ∀ (y : t), ↑y ∈ Ioi x, { simp [hx'] }, intros y, revert hx, contrapose!, -- here we use the `ord_connected` hypothesis exact λ hx, ht.out y.2 a.2 ⟨le_of_not_gt hx, le_of_lt h⟩ }, { refine le_infi (λ x, le_infi $ λ h, le_principal_iff.2 _), by_cases hx : x ∈ t, { refine mem_infi_sets (Iio ⟨x, hx⟩) (mem_infi_sets ⟨h, ⟨⟨x, hx⟩, or.inr rfl⟩⟩ _), exact λ _, id }, simp only [set_coe.exists, mem_set_of_eq, mem_map], convert univ_sets _, suffices hx' : ∀ (y : t), ↑y ∈ Iio x, { simp [hx'] }, intros y, revert hx, contrapose!, -- here we use the `ord_connected` hypothesis exact λ hx, ht.out a.2 y.2 ⟨le_of_lt h, le_of_not_gt hx⟩ } } end lemma nhds_top_order [topological_space α] [order_top α] [order_topology α] : 𝓝 (⊤:α) = (⨅l (h₂ : l < ⊤), 𝓟 (Ioi l)) := by simp [nhds_eq_order (⊤:α)] lemma nhds_bot_order [topological_space α] [order_bot α] [order_topology α] : 𝓝 (⊥:α) = (⨅l (h₂ : ⊥ < l), 𝓟 (Iio l)) := by simp [nhds_eq_order (⊥:α)] lemma tendsto_nhds_top_mono [topological_space β] [order_top β] [order_topology β] {l : filter α} {f g : α → β} (hf : tendsto f l (𝓝 ⊤)) (hg : f ≤ᶠ[l] g) : tendsto g l (𝓝 ⊤) := begin simp only [nhds_top_order, tendsto_infi, tendsto_principal] at hf ⊢, intros x hx, filter_upwards [hf x hx, hg], exact λ x, lt_of_lt_of_le end lemma tendsto_nhds_bot_mono [topological_space β] [order_bot β] [order_topology β] {l : filter α} {f g : α → β} (hf : tendsto f l (𝓝 ⊥)) (hg : g ≤ᶠ[l] f) : tendsto g l (𝓝 ⊥) := @tendsto_nhds_top_mono α (order_dual β) _ _ _ _ _ _ hf hg lemma tendsto_nhds_top_mono' [topological_space β] [order_top β] [order_topology β] {l : filter α} {f g : α → β} (hf : tendsto f l (𝓝 ⊤)) (hg : f ≤ g) : tendsto g l (𝓝 ⊤) := tendsto_nhds_top_mono hf (eventually_of_forall hg) lemma tendsto_nhds_bot_mono' [topological_space β] [order_bot β] [order_topology β] {l : filter α} {f g : α → β} (hf : tendsto f l (𝓝 ⊥)) (hg : g ≤ f) : tendsto g l (𝓝 ⊥) := tendsto_nhds_bot_mono hf (eventually_of_forall hg) section linear_order variables [topological_space α] [linear_order α] [order_topology α] lemma exists_Ioc_subset_of_mem_nhds' {a : α} {s : set α} (hs : s ∈ 𝓝 a) {l : α} (hl : l < a) : ∃ l' ∈ Ico l a, Ioc l' a ⊆ s := begin rw [nhds_eq_order a] at hs, rcases hs with ⟨t₁, ht₁, t₂, ht₂, hts⟩, -- First we show that `t₂` includes `(-∞, a]`, so it suffices to show `(l', ∞) ⊆ t₁` suffices : ∃ l' ∈ Ico l a, Ioi l' ⊆ t₁, { have A : 𝓟 (Iic a) ≤ ⨅ b ∈ Ioi a, 𝓟 (Iio b), from (le_infi $ λ b, le_infi $ λ hb, principal_mono.2 $ Iic_subset_Iio.2 hb), have B : t₁ ∩ Iic a ⊆ s, from subset.trans (inter_subset_inter_right _ (A ht₂)) hts, from this.imp (λ l', Exists.imp $ λ hl' hl x hx, B ⟨hl hx.1, hx.2⟩) }, clear hts ht₂ t₂, -- Now we find `l` such that `(l', ∞) ⊆ t₁` rw [mem_binfi] at ht₁, { rcases ht₁ with ⟨b, hb, hb'⟩, exact ⟨max b l, ⟨le_max_right _ _, max_lt hb hl⟩, λ x hx, hb' $ Ioi_subset_Ioi (le_max_left _ _) hx⟩ }, { intros b hb b' hb', simp only [mem_Iio] at hb hb', use [max b b', max_lt hb hb'], simp [le_refl] }, exact ⟨l, hl⟩ end lemma exists_Ico_subset_of_mem_nhds' {a : α} {s : set α} (hs : s ∈ 𝓝 a) {u : α} (hu : a < u) : ∃ u' ∈ Ioc a u, Ico a u' ⊆ s := begin convert @exists_Ioc_subset_of_mem_nhds' (order_dual α) _ _ _ _ _ hs _ hu, ext, rw [dual_Ico, dual_Ioc] end lemma exists_Ioc_subset_of_mem_nhds {a : α} {s : set α} (hs : s ∈ 𝓝 a) (h : ∃ l, l < a) : ∃ l < a, Ioc l a ⊆ s := let ⟨l', hl'⟩ := h in let ⟨l, hl⟩ := exists_Ioc_subset_of_mem_nhds' hs hl' in ⟨l, hl.fst.2, hl.snd⟩ lemma exists_Ico_subset_of_mem_nhds {a : α} {s : set α} (hs : s ∈ 𝓝 a) (h : ∃ u, a < u) : ∃ u (_ : a < u), Ico a u ⊆ s := let ⟨l', hl'⟩ := h in let ⟨l, hl⟩ := exists_Ico_subset_of_mem_nhds' hs hl' in ⟨l, hl.fst.1, hl.snd⟩ lemma order_separated {a₁ a₂ : α} (h : a₁ < a₂) : ∃u v : set α, is_open u ∧ is_open v ∧ a₁ ∈ u ∧ a₂ ∈ v ∧ (∀b₁∈u, ∀b₂∈v, b₁ < b₂) := match dense_or_discrete a₁ a₂ with | or.inl ⟨a, ha₁, ha₂⟩ := ⟨{a' | a' < a}, {a' | a < a'}, is_open_gt' a, is_open_lt' a, ha₁, ha₂, assume b₁ h₁ b₂ h₂, lt_trans h₁ h₂⟩ | or.inr ⟨h₁, h₂⟩ := ⟨{a | a < a₂}, {a | a₁ < a}, is_open_gt' a₂, is_open_lt' a₁, h, h, assume b₁ hb₁ b₂ hb₂, calc b₁ ≤ a₁ : h₂ _ hb₁ ... < a₂ : h ... ≤ b₂ : h₁ _ hb₂⟩ end @[priority 100] -- see Note [lower instance priority] instance order_topology.to_order_closed_topology : order_closed_topology α := { is_closed_le' := is_open_compl_iff.1 $ is_open_prod_iff.mpr $ assume a₁ a₂ (h : ¬ a₁ ≤ a₂), have h : a₂ < a₁, from lt_of_not_ge h, let ⟨u, v, hu, hv, ha₁, ha₂, h⟩ := order_separated h in ⟨v, u, hv, hu, ha₂, ha₁, assume ⟨b₁, b₂⟩ ⟨h₁, h₂⟩, not_le_of_gt $ h b₂ h₂ b₁ h₁⟩ } lemma order_topology.t2_space : t2_space α := by apply_instance @[priority 100] -- see Note [lower instance priority] instance order_topology.regular_space : regular_space α := { regular := assume s a hs ha, have hs' : sᶜ ∈ 𝓝 a, from is_open.mem_nhds hs.is_open_compl ha, have ∃t:set α, is_open t ∧ (∀l∈ s, l < a → l ∈ t) ∧ 𝓝[t] a = ⊥, from by_cases (assume h : ∃l, l < a, let ⟨l, hl, h⟩ := exists_Ioc_subset_of_mem_nhds hs' h in match dense_or_discrete l a with | or.inl ⟨b, hb₁, hb₂⟩ := ⟨{a | a < b}, is_open_gt' _, assume c hcs hca, show c < b, from lt_of_not_ge $ assume hbc, h ⟨lt_of_lt_of_le hb₁ hbc, le_of_lt hca⟩ hcs, inf_principal_eq_bot.2 $ (𝓝 a).sets_of_superset ((is_open_lt' _).mem_nhds hb₂) $ assume x (hx : b < x), show ¬ x < b, from not_lt.2 $ le_of_lt hx⟩ | or.inr ⟨h₁, h₂⟩ := ⟨{a' | a' < a}, is_open_gt' _, assume b hbs hba, hba, inf_principal_eq_bot.2 $ (𝓝 a).sets_of_superset ((is_open_lt' _).mem_nhds hl) $ assume x (hx : l < x), show ¬ x < a, from not_lt.2 $ h₁ _ hx⟩ end) (assume : ¬ ∃l, l < a, ⟨∅, is_open_empty, assume l _ hl, (this ⟨l, hl⟩).elim, nhds_within_empty _⟩), let ⟨t₁, ht₁o, ht₁s, ht₁a⟩ := this in have ∃t:set α, is_open t ∧ (∀u∈ s, u>a → u ∈ t) ∧ 𝓝[t] a = ⊥, from by_cases (assume h : ∃u, u > a, let ⟨u, hu, h⟩ := exists_Ico_subset_of_mem_nhds hs' h in match dense_or_discrete a u with | or.inl ⟨b, hb₁, hb₂⟩ := ⟨{a | b < a}, is_open_lt' _, assume c hcs hca, show c > b, from lt_of_not_ge $ assume hbc, h ⟨le_of_lt hca, lt_of_le_of_lt hbc hb₂⟩ hcs, inf_principal_eq_bot.2 $ (𝓝 a).sets_of_superset ((is_open_gt' _).mem_nhds hb₁) $ assume x (hx : b > x), show ¬ x > b, from not_lt.2 $ le_of_lt hx⟩ | or.inr ⟨h₁, h₂⟩ := ⟨{a' | a' > a}, is_open_lt' _, assume b hbs hba, hba, inf_principal_eq_bot.2 $ (𝓝 a).sets_of_superset ((is_open_gt' _).mem_nhds hu) $ assume x (hx : u > x), show ¬ x > a, from not_lt.2 $ h₂ _ hx⟩ end) (assume : ¬ ∃u, u > a, ⟨∅, is_open_empty, assume l _ hl, (this ⟨l, hl⟩).elim, nhds_within_empty _⟩), let ⟨t₂, ht₂o, ht₂s, ht₂a⟩ := this in ⟨t₁ ∪ t₂, is_open.union ht₁o ht₂o, assume x hx, have x ≠ a, from assume eq, ha $ eq ▸ hx, (ne_iff_lt_or_gt.mp this).imp (ht₁s _ hx) (ht₂s _ hx), by rw [nhds_within_union, ht₁a, ht₂a, bot_sup_eq]⟩, ..order_topology.t2_space } /-- A set is a neighborhood of `a` if and only if it contains an interval `(l, u)` containing `a`, provided `a` is neither a bottom element nor a top element. -/ lemma mem_nhds_iff_exists_Ioo_subset' {a : α} {s : set α} (hl : ∃ l, l < a) (hu : ∃ u, a < u) : s ∈ 𝓝 a ↔ ∃l u, a ∈ Ioo l u ∧ Ioo l u ⊆ s := begin split, { assume h, rcases exists_Ico_subset_of_mem_nhds h hu with ⟨u, au, hu⟩, rcases exists_Ioc_subset_of_mem_nhds h hl with ⟨l, la, hl⟩, refine ⟨l, u, ⟨la, au⟩, λx hx, _⟩, cases le_total a x with hax hax, { exact hu ⟨hax, hx.2⟩ }, { exact hl ⟨hx.1, hax⟩ } }, { rintros ⟨l, u, ha, h⟩, apply mem_sets_of_superset (is_open.mem_nhds is_open_Ioo ha) h } end /-- A set is a neighborhood of `a` if and only if it contains an interval `(l, u)` containing `a`. -/ lemma mem_nhds_iff_exists_Ioo_subset [no_top_order α] [no_bot_order α] {a : α} {s : set α} : s ∈ 𝓝 a ↔ ∃l u, a ∈ Ioo l u ∧ Ioo l u ⊆ s := mem_nhds_iff_exists_Ioo_subset' (no_bot a) (no_top a) lemma nhds_basis_Ioo' {a : α} (hl : ∃ l, l < a) (hu : ∃ u, a < u) : (𝓝 a).has_basis (λ b : α × α, b.1 < a ∧ a < b.2) (λ b, Ioo b.1 b.2) := ⟨λ s, (mem_nhds_iff_exists_Ioo_subset' hl hu).trans $ by simp⟩ lemma nhds_basis_Ioo [no_top_order α] [no_bot_order α] (a : α) : (𝓝 a).has_basis (λ b : α × α, b.1 < a ∧ a < b.2) (λ b, Ioo b.1 b.2) := nhds_basis_Ioo' (no_bot a) (no_top a) lemma filter.eventually.exists_Ioo_subset [no_top_order α] [no_bot_order α] {a : α} {p : α → Prop} (hp : ∀ᶠ x in 𝓝 a, p x) : ∃ l u, a ∈ Ioo l u ∧ Ioo l u ⊆ {x | p x} := mem_nhds_iff_exists_Ioo_subset.1 hp lemma Iio_mem_nhds {a b : α} (h : a < b) : Iio b ∈ 𝓝 a := is_open.mem_nhds is_open_Iio h lemma Ioi_mem_nhds {a b : α} (h : a < b) : Ioi a ∈ 𝓝 b := is_open.mem_nhds is_open_Ioi h lemma Iic_mem_nhds {a b : α} (h : a < b) : Iic b ∈ 𝓝 a := mem_sets_of_superset (Iio_mem_nhds h) Iio_subset_Iic_self lemma Ici_mem_nhds {a b : α} (h : a < b) : Ici a ∈ 𝓝 b := mem_sets_of_superset (Ioi_mem_nhds h) Ioi_subset_Ici_self lemma Ioo_mem_nhds {a b x : α} (ha : a < x) (hb : x < b) : Ioo a b ∈ 𝓝 x := is_open.mem_nhds is_open_Ioo ⟨ha, hb⟩ lemma Ioc_mem_nhds {a b x : α} (ha : a < x) (hb : x < b) : Ioc a b ∈ 𝓝 x := mem_sets_of_superset (Ioo_mem_nhds ha hb) Ioo_subset_Ioc_self lemma Ico_mem_nhds {a b x : α} (ha : a < x) (hb : x < b) : Ico a b ∈ 𝓝 x := mem_sets_of_superset (Ioo_mem_nhds ha hb) Ioo_subset_Ico_self lemma Icc_mem_nhds {a b x : α} (ha : a < x) (hb : x < b) : Icc a b ∈ 𝓝 x := mem_sets_of_superset (Ioo_mem_nhds ha hb) Ioo_subset_Icc_self section pi /-! ### Intervals in `Π i, π i` belong to `𝓝 x` For each lemma `pi_Ixx_mem_nhds` we add a non-dependent version `pi_Ixx_mem_nhds'` because sometimes Lean fails to unify different instances while trying to apply the dependent version to, e.g., `ι → ℝ`. -/ variables {ι : Type*} {π : ι → Type*} [fintype ι] [Π i, linear_order (π i)] [Π i, topological_space (π i)] [∀ i, order_topology (π i)] {a b x : Π i, π i} {a' b' x' : ι → α} lemma pi_Iic_mem_nhds (ha : ∀ i, x i < a i) : Iic a ∈ 𝓝 x := pi_univ_Iic a ▸ set_pi_mem_nhds (finite.of_fintype _) (λ i _, Iic_mem_nhds (ha _)) lemma pi_Iic_mem_nhds' (ha : ∀ i, x' i < a' i) : Iic a' ∈ 𝓝 x' := pi_Iic_mem_nhds ha lemma pi_Ici_mem_nhds (ha : ∀ i, a i < x i) : Ici a ∈ 𝓝 x := pi_univ_Ici a ▸ set_pi_mem_nhds (finite.of_fintype _) (λ i _, Ici_mem_nhds (ha _)) lemma pi_Ici_mem_nhds' (ha : ∀ i, a' i < x' i) : Ici a' ∈ 𝓝 x' := pi_Ici_mem_nhds ha lemma pi_Icc_mem_nhds (ha : ∀ i, a i < x i) (hb : ∀ i, x i < b i) : Icc a b ∈ 𝓝 x := pi_univ_Icc a b ▸ set_pi_mem_nhds (finite.of_fintype _) (λ i _, Icc_mem_nhds (ha _) (hb _)) lemma pi_Icc_mem_nhds' (ha : ∀ i, a' i < x' i) (hb : ∀ i, x' i < b' i) : Icc a' b' ∈ 𝓝 x' := pi_Icc_mem_nhds ha hb variables [nonempty ι] lemma pi_Iio_mem_nhds (ha : ∀ i, x i < a i) : Iio a ∈ 𝓝 x := begin refine mem_sets_of_superset (set_pi_mem_nhds (finite.of_fintype _) (λ i _, _)) (pi_univ_Iio_subset a), exact Iio_mem_nhds (ha i) end lemma pi_Iio_mem_nhds' (ha : ∀ i, x' i < a' i) : Iio a' ∈ 𝓝 x' := pi_Iio_mem_nhds ha lemma pi_Ioi_mem_nhds (ha : ∀ i, a i < x i) : Ioi a ∈ 𝓝 x := @pi_Iio_mem_nhds ι (λ i, order_dual (π i)) _ _ _ _ _ _ _ ha lemma pi_Ioi_mem_nhds' (ha : ∀ i, a' i < x' i) : Ioi a' ∈ 𝓝 x' := pi_Ioi_mem_nhds ha lemma pi_Ioc_mem_nhds (ha : ∀ i, a i < x i) (hb : ∀ i, x i < b i) : Ioc a b ∈ 𝓝 x := begin refine mem_sets_of_superset (set_pi_mem_nhds (finite.of_fintype _) (λ i _, _)) (pi_univ_Ioc_subset a b), exact Ioc_mem_nhds (ha i) (hb i) end lemma pi_Ioc_mem_nhds' (ha : ∀ i, a' i < x' i) (hb : ∀ i, x' i < b' i) : Ioc a' b' ∈ 𝓝 x' := pi_Ioc_mem_nhds ha hb lemma pi_Ico_mem_nhds (ha : ∀ i, a i < x i) (hb : ∀ i, x i < b i) : Ico a b ∈ 𝓝 x := begin refine mem_sets_of_superset (set_pi_mem_nhds (finite.of_fintype _) (λ i _, _)) (pi_univ_Ico_subset a b), exact Ico_mem_nhds (ha i) (hb i) end lemma pi_Ico_mem_nhds' (ha : ∀ i, a' i < x' i) (hb : ∀ i, x' i < b' i) : Ico a' b' ∈ 𝓝 x' := pi_Ico_mem_nhds ha hb lemma pi_Ioo_mem_nhds (ha : ∀ i, a i < x i) (hb : ∀ i, x i < b i) : Ioo a b ∈ 𝓝 x := begin refine mem_sets_of_superset (set_pi_mem_nhds (finite.of_fintype _) (λ i _, _)) (pi_univ_Ioo_subset a b), exact Ioo_mem_nhds (ha i) (hb i) end lemma pi_Ioo_mem_nhds' (ha : ∀ i, a' i < x' i) (hb : ∀ i, x' i < b' i) : Ioo a' b' ∈ 𝓝 x' := pi_Ioo_mem_nhds ha hb end pi lemma disjoint_nhds_at_top [no_top_order α] (x : α) : disjoint (𝓝 x) at_top := begin rw filter.disjoint_iff, cases no_top x with a ha, use [Iio a, Iio_mem_nhds ha, Ici a, mem_at_top a], rw [inter_comm, Ici_inter_Iio, Ico_self] end @[simp] lemma inf_nhds_at_top [no_top_order α] (x : α) : 𝓝 x ⊓ at_top = ⊥ := disjoint_iff.1 (disjoint_nhds_at_top x) lemma disjoint_nhds_at_bot [no_bot_order α] (x : α) : disjoint (𝓝 x) at_bot := @disjoint_nhds_at_top (order_dual α) _ _ _ _ x @[simp] lemma inf_nhds_at_bot [no_bot_order α] (x : α) : 𝓝 x ⊓ at_bot = ⊥ := @inf_nhds_at_top (order_dual α) _ _ _ _ x lemma not_tendsto_nhds_of_tendsto_at_top [no_top_order α] {F : filter β} [ne_bot F] {f : β → α} (hf : tendsto f F at_top) (x : α) : ¬ tendsto f F (𝓝 x) := hf.not_tendsto (disjoint_nhds_at_top x).symm lemma not_tendsto_at_top_of_tendsto_nhds [no_top_order α] {F : filter β} [ne_bot F] {f : β → α} {x : α} (hf : tendsto f F (𝓝 x)) : ¬ tendsto f F at_top := hf.not_tendsto (disjoint_nhds_at_top x) lemma not_tendsto_nhds_of_tendsto_at_bot [no_bot_order α] {F : filter β} [ne_bot F] {f : β → α} (hf : tendsto f F at_bot) (x : α) : ¬ tendsto f F (𝓝 x) := hf.not_tendsto (disjoint_nhds_at_bot x).symm lemma not_tendsto_at_bot_of_tendsto_nhds [no_bot_order α] {F : filter β} [ne_bot F] {f : β → α} {x : α} (hf : tendsto f F (𝓝 x)) : ¬ tendsto f F at_bot := hf.not_tendsto (disjoint_nhds_at_bot x) /-! ### Neighborhoods to the left and to the right on an `order_topology` We've seen some properties of left and right neighborhood of a point in an `order_closed_topology`. In an `order_topology`, such neighborhoods can be characterized as the sets containing suitable intervals to the right or to the left of `a`. We give now these characterizations. -/ -- NB: If you extend the list, append to the end please to avoid breaking the API /-- The following statements are equivalent: 0. `s` is a neighborhood of `a` within `(a, +∞)` 1. `s` is a neighborhood of `a` within `(a, b]` 2. `s` is a neighborhood of `a` within `(a, b)` 3. `s` includes `(a, u)` for some `u ∈ (a, b]` 4. `s` includes `(a, u)` for some `u > a` -/ lemma tfae_mem_nhds_within_Ioi {a b : α} (hab : a < b) (s : set α) : tfae [s ∈ 𝓝[Ioi a] a, -- 0 : `s` is a neighborhood of `a` within `(a, +∞)` s ∈ 𝓝[Ioc a b] a, -- 1 : `s` is a neighborhood of `a` within `(a, b]` s ∈ 𝓝[Ioo a b] a, -- 2 : `s` is a neighborhood of `a` within `(a, b)` ∃ u ∈ Ioc a b, Ioo a u ⊆ s, -- 3 : `s` includes `(a, u)` for some `u ∈ (a, b]` ∃ u ∈ Ioi a, Ioo a u ⊆ s] := -- 4 : `s` includes `(a, u)` for some `u > a` begin tfae_have : 1 ↔ 2, by rw [nhds_within_Ioc_eq_nhds_within_Ioi hab], tfae_have : 1 ↔ 3, by rw [nhds_within_Ioo_eq_nhds_within_Ioi hab], tfae_have : 4 → 5, from λ ⟨u, umem, hu⟩, ⟨u, umem.1, hu⟩, tfae_have : 5 → 1, { rintros ⟨u, hau, hu⟩, exact mem_sets_of_superset (Ioo_mem_nhds_within_Ioi ⟨le_refl a, hau⟩) hu }, tfae_have : 1 → 4, { assume h, rcases mem_nhds_within_iff_exists_mem_nhds_inter.1 h with ⟨v, va, hv⟩, rcases exists_Ico_subset_of_mem_nhds' va hab with ⟨u, au, hu⟩, refine ⟨u, au, λx hx, _⟩, refine hv ⟨hu ⟨le_of_lt hx.1, hx.2⟩, _⟩, exact hx.1 }, tfae_finish end lemma mem_nhds_within_Ioi_iff_exists_mem_Ioc_Ioo_subset {a u' : α} {s : set α} (hu' : a < u') : s ∈ 𝓝[Ioi a] a ↔ ∃u ∈ Ioc a u', Ioo a u ⊆ s := (tfae_mem_nhds_within_Ioi hu' s).out 0 3 /-- A set is a neighborhood of `a` within `(a, +∞)` if and only if it contains an interval `(a, u)` with `a < u < u'`, provided `a` is not a top element. -/ lemma mem_nhds_within_Ioi_iff_exists_Ioo_subset' {a u' : α} {s : set α} (hu' : a < u') : s ∈ 𝓝[Ioi a] a ↔ ∃u ∈ Ioi a, Ioo a u ⊆ s := (tfae_mem_nhds_within_Ioi hu' s).out 0 4 /-- A set is a neighborhood of `a` within `(a, +∞)` if and only if it contains an interval `(a, u)` with `a < u`. -/ lemma mem_nhds_within_Ioi_iff_exists_Ioo_subset [no_top_order α] {a : α} {s : set α} : s ∈ 𝓝[Ioi a] a ↔ ∃u ∈ Ioi a, Ioo a u ⊆ s := let ⟨u', hu'⟩ := no_top a in mem_nhds_within_Ioi_iff_exists_Ioo_subset' hu' /-- A set is a neighborhood of `a` within `(a, +∞)` if and only if it contains an interval `(a, u]` with `a < u`. -/ lemma mem_nhds_within_Ioi_iff_exists_Ioc_subset [no_top_order α] [densely_ordered α] {a : α} {s : set α} : s ∈ 𝓝[Ioi a] a ↔ ∃u ∈ Ioi a, Ioc a u ⊆ s := begin rw mem_nhds_within_Ioi_iff_exists_Ioo_subset, split, { rintros ⟨u, au, as⟩, rcases exists_between au with ⟨v, hv⟩, exact ⟨v, hv.1, λx hx, as ⟨hx.1, lt_of_le_of_lt hx.2 hv.2⟩⟩ }, { rintros ⟨u, au, as⟩, exact ⟨u, au, subset.trans Ioo_subset_Ioc_self as⟩ } end /-- The following statements are equivalent: 0. `s` is a neighborhood of `b` within `(-∞, b)` 1. `s` is a neighborhood of `b` within `[a, b)` 2. `s` is a neighborhood of `b` within `(a, b)` 3. `s` includes `(l, b)` for some `l ∈ [a, b)` 4. `s` includes `(l, b)` for some `l < b` -/ lemma tfae_mem_nhds_within_Iio {a b : α} (h : a < b) (s : set α) : tfae [s ∈ 𝓝[Iio b] b, -- 0 : `s` is a neighborhood of `b` within `(-∞, b)` s ∈ 𝓝[Ico a b] b, -- 1 : `s` is a neighborhood of `b` within `[a, b)` s ∈ 𝓝[Ioo a b] b, -- 2 : `s` is a neighborhood of `b` within `(a, b)` ∃ l ∈ Ico a b, Ioo l b ⊆ s, -- 3 : `s` includes `(l, b)` for some `l ∈ [a, b)` ∃ l ∈ Iio b, Ioo l b ⊆ s] := -- 4 : `s` includes `(l, b)` for some `l < b` begin have := @tfae_mem_nhds_within_Ioi (order_dual α) _ _ _ _ _ h s, -- If we call `convert` here, it generates wrong equations, so we need to simplify first simp only [exists_prop] at this ⊢, rw [dual_Ioi, dual_Ioc, dual_Ioo] at this, convert this; ext l; rw [dual_Ioo] end lemma mem_nhds_within_Iio_iff_exists_mem_Ico_Ioo_subset {a l' : α} {s : set α} (hl' : l' < a) : s ∈ 𝓝[Iio a] a ↔ ∃l ∈ Ico l' a, Ioo l a ⊆ s := (tfae_mem_nhds_within_Iio hl' s).out 0 3 /-- A set is a neighborhood of `a` within `(-∞, a)` if and only if it contains an interval `(l, a)` with `l < a`, provided `a` is not a bottom element. -/ lemma mem_nhds_within_Iio_iff_exists_Ioo_subset' {a l' : α} {s : set α} (hl' : l' < a) : s ∈ 𝓝[Iio a] a ↔ ∃l ∈ Iio a, Ioo l a ⊆ s := (tfae_mem_nhds_within_Iio hl' s).out 0 4 /-- A set is a neighborhood of `a` within `(-∞, a)` if and only if it contains an interval `(l, a)` with `l < a`. -/ lemma mem_nhds_within_Iio_iff_exists_Ioo_subset [no_bot_order α] {a : α} {s : set α} : s ∈ 𝓝[Iio a] a ↔ ∃l ∈ Iio a, Ioo l a ⊆ s := let ⟨l', hl'⟩ := no_bot a in mem_nhds_within_Iio_iff_exists_Ioo_subset' hl' /-- A set is a neighborhood of `a` within `(-∞, a)` if and only if it contains an interval `[l, a)` with `l < a`. -/ lemma mem_nhds_within_Iio_iff_exists_Ico_subset [no_bot_order α] [densely_ordered α] {a : α} {s : set α} : s ∈ 𝓝[Iio a] a ↔ ∃l ∈ Iio a, Ico l a ⊆ s := begin convert @mem_nhds_within_Ioi_iff_exists_Ioc_subset (order_dual α) _ _ _ _ _ _ _, simp only [dual_Ioc], refl end /-- The following statements are equivalent: 0. `s` is a neighborhood of `a` within `[a, +∞)` 1. `s` is a neighborhood of `a` within `[a, b]` 2. `s` is a neighborhood of `a` within `[a, b)` 3. `s` includes `[a, u)` for some `u ∈ (a, b]` 4. `s` includes `[a, u)` for some `u > a` -/ lemma tfae_mem_nhds_within_Ici {a b : α} (hab : a < b) (s : set α) : tfae [s ∈ 𝓝[Ici a] a, -- 0 : `s` is a neighborhood of `a` within `[a, +∞)` s ∈ 𝓝[Icc a b] a, -- 1 : `s` is a neighborhood of `a` within `[a, b]` s ∈ 𝓝[Ico a b] a, -- 2 : `s` is a neighborhood of `a` within `[a, b)` ∃ u ∈ Ioc a b, Ico a u ⊆ s, -- 3 : `s` includes `[a, u)` for some `u ∈ (a, b]` ∃ u ∈ Ioi a, Ico a u ⊆ s] := -- 4 : `s` includes `[a, u)` for some `u > a` begin tfae_have : 1 ↔ 2, by rw [nhds_within_Icc_eq_nhds_within_Ici hab], tfae_have : 1 ↔ 3, by rw [nhds_within_Ico_eq_nhds_within_Ici hab], tfae_have : 4 → 5, from λ ⟨u, umem, hu⟩, ⟨u, umem.1, hu⟩, tfae_have : 5 → 1, { rintros ⟨u, hau, hu⟩, exact mem_sets_of_superset (Ico_mem_nhds_within_Ici ⟨le_refl a, hau⟩) hu }, tfae_have : 1 → 4, { assume h, rcases mem_nhds_within_iff_exists_mem_nhds_inter.1 h with ⟨v, va, hv⟩, rcases exists_Ico_subset_of_mem_nhds' va hab with ⟨u, au, hu⟩, refine ⟨u, au, λx hx, _⟩, refine hv ⟨hu ⟨hx.1, hx.2⟩, _⟩, exact hx.1 }, tfae_finish end lemma mem_nhds_within_Ici_iff_exists_mem_Ioc_Ico_subset {a u' : α} {s : set α} (hu' : a < u') : s ∈ 𝓝[Ici a] a ↔ ∃u ∈ Ioc a u', Ico a u ⊆ s := (tfae_mem_nhds_within_Ici hu' s).out 0 3 (by norm_num) (by norm_num) /-- A set is a neighborhood of `a` within `[a, +∞)` if and only if it contains an interval `[a, u)` with `a < u < u'`, provided `a` is not a top element. -/ lemma mem_nhds_within_Ici_iff_exists_Ico_subset' {a u' : α} {s : set α} (hu' : a < u') : s ∈ 𝓝[Ici a] a ↔ ∃u ∈ Ioi a, Ico a u ⊆ s := (tfae_mem_nhds_within_Ici hu' s).out 0 4 (by norm_num) (by norm_num) /-- A set is a neighborhood of `a` within `[a, +∞)` if and only if it contains an interval `[a, u)` with `a < u`. -/ lemma mem_nhds_within_Ici_iff_exists_Ico_subset [no_top_order α] {a : α} {s : set α} : s ∈ 𝓝[Ici a] a ↔ ∃u ∈ Ioi a, Ico a u ⊆ s := let ⟨u', hu'⟩ := no_top a in mem_nhds_within_Ici_iff_exists_Ico_subset' hu' /-- A set is a neighborhood of `a` within `[a, +∞)` if and only if it contains an interval `[a, u]` with `a < u`. -/ lemma mem_nhds_within_Ici_iff_exists_Icc_subset' [no_top_order α] [densely_ordered α] {a : α} {s : set α} : s ∈ 𝓝[Ici a] a ↔ ∃u ∈ Ioi a, Icc a u ⊆ s := begin rw mem_nhds_within_Ici_iff_exists_Ico_subset, split, { rintros ⟨u, au, as⟩, rcases exists_between au with ⟨v, hv⟩, exact ⟨v, hv.1, λx hx, as ⟨hx.1, lt_of_le_of_lt hx.2 hv.2⟩⟩ }, { rintros ⟨u, au, as⟩, exact ⟨u, au, subset.trans Ico_subset_Icc_self as⟩ } end /-- The following statements are equivalent: 0. `s` is a neighborhood of `b` within `(-∞, b]` 1. `s` is a neighborhood of `b` within `[a, b]` 2. `s` is a neighborhood of `b` within `(a, b]` 3. `s` includes `(l, b]` for some `l ∈ [a, b)` 4. `s` includes `(l, b]` for some `l < b` -/ lemma tfae_mem_nhds_within_Iic {a b : α} (h : a < b) (s : set α) : tfae [s ∈ 𝓝[Iic b] b, -- 0 : `s` is a neighborhood of `b` within `(-∞, b]` s ∈ 𝓝[Icc a b] b, -- 1 : `s` is a neighborhood of `b` within `[a, b]` s ∈ 𝓝[Ioc a b] b, -- 2 : `s` is a neighborhood of `b` within `(a, b]` ∃ l ∈ Ico a b, Ioc l b ⊆ s, -- 3 : `s` includes `(l, b]` for some `l ∈ [a, b)` ∃ l ∈ Iio b, Ioc l b ⊆ s] := -- 4 : `s` includes `(l, b]` for some `l < b` begin have := @tfae_mem_nhds_within_Ici (order_dual α) _ _ _ _ _ h s, -- If we call `convert` here, it generates wrong equations, so we need to simplify first simp only [exists_prop] at this ⊢, rw [dual_Icc, dual_Ioc, dual_Ioi] at this, convert this; ext l; rw [dual_Ico] end lemma mem_nhds_within_Iic_iff_exists_mem_Ico_Ioc_subset {a l' : α} {s : set α} (hl' : l' < a) : s ∈ 𝓝[Iic a] a ↔ ∃l ∈ Ico l' a, Ioc l a ⊆ s := (tfae_mem_nhds_within_Iic hl' s).out 0 3 (by norm_num) (by norm_num) /-- A set is a neighborhood of `a` within `(-∞, a]` if and only if it contains an interval `(l, a]` with `l < a`, provided `a` is not a bottom element. -/ lemma mem_nhds_within_Iic_iff_exists_Ioc_subset' {a l' : α} {s : set α} (hl' : l' < a) : s ∈ 𝓝[Iic a] a ↔ ∃l ∈ Iio a, Ioc l a ⊆ s := (tfae_mem_nhds_within_Iic hl' s).out 0 4 (by norm_num) (by norm_num) /-- A set is a neighborhood of `a` within `(-∞, a]` if and only if it contains an interval `(l, a]` with `l < a`. -/ lemma mem_nhds_within_Iic_iff_exists_Ioc_subset [no_bot_order α] {a : α} {s : set α} : s ∈ 𝓝[Iic a] a ↔ ∃l ∈ Iio a, Ioc l a ⊆ s := let ⟨l', hl'⟩ := no_bot a in mem_nhds_within_Iic_iff_exists_Ioc_subset' hl' /-- A set is a neighborhood of `a` within `(-∞, a]` if and only if it contains an interval `[l, a]` with `l < a`. -/ lemma mem_nhds_within_Iic_iff_exists_Icc_subset' [no_bot_order α] [densely_ordered α] {a : α} {s : set α} : s ∈ 𝓝[Iic a] a ↔ ∃l ∈ Iio a, Icc l a ⊆ s := begin convert @mem_nhds_within_Ici_iff_exists_Icc_subset' (order_dual α) _ _ _ _ _ _ _, simp_rw (show ∀ u : order_dual α, @Icc (order_dual α) _ a u = @Icc α _ u a, from λ u, dual_Icc), refl, end /-- A set is a neighborhood of `a` within `[a, +∞)` if and only if it contains an interval `[a, u]` with `a < u`. -/ lemma mem_nhds_within_Ici_iff_exists_Icc_subset [no_top_order α] [densely_ordered α] {a : α} {s : set α} : s ∈ 𝓝[Ici a] a ↔ ∃u, a < u ∧ Icc a u ⊆ s := begin rw mem_nhds_within_Ici_iff_exists_Ico_subset, split, { rintros ⟨u, au, as⟩, rcases exists_between au with ⟨v, hv⟩, exact ⟨v, hv.1, λx hx, as ⟨hx.1, lt_of_le_of_lt hx.2 hv.2⟩⟩ }, { rintros ⟨u, au, as⟩, exact ⟨u, au, subset.trans Ico_subset_Icc_self as⟩ } end /-- A set is a neighborhood of `a` within `(-∞, a]` if and only if it contains an interval `[l, a]` with `l < a`. -/ lemma mem_nhds_within_Iic_iff_exists_Icc_subset [no_bot_order α] [densely_ordered α] {a : α} {s : set α} : s ∈ 𝓝[Iic a] a ↔ ∃l, l < a ∧ Icc l a ⊆ s := begin rw mem_nhds_within_Iic_iff_exists_Ioc_subset, split, { rintros ⟨l, la, as⟩, rcases exists_between la with ⟨v, hv⟩, refine ⟨v, hv.2, λx hx, as ⟨lt_of_lt_of_le hv.1 hx.1, hx.2⟩⟩, }, { rintros ⟨l, la, as⟩, exact ⟨l, la, subset.trans Ioc_subset_Icc_self as⟩ } end end linear_order section linear_ordered_add_comm_group variables [topological_space α] [linear_ordered_add_comm_group α] [order_topology α] variables {l : filter β} {f g : β → α} local notation `|` x `|` := abs x lemma nhds_eq_infi_abs_sub (a : α) : 𝓝 a = (⨅r>0, 𝓟 {b | |a - b| < r}) := begin simp only [le_antisymm_iff, nhds_eq_order, le_inf_iff, le_infi_iff, le_principal_iff, mem_Ioi, mem_Iio, abs_sub_lt_iff, @sub_lt_iff_lt_add _ _ _ _ a, @sub_lt _ _ a, set_of_and], refine ⟨_, _, _⟩, { intros ε ε0, exact inter_mem_inf_sets (mem_infi_sets (a - ε) $ mem_infi_sets (sub_lt_self a ε0) (mem_principal_self _)) (mem_infi_sets (ε + a) $ mem_infi_sets (by simpa) (mem_principal_self _)) }, { intros b hb, exact mem_infi_sets (a - b) (mem_infi_sets (sub_pos.2 hb) (by simp [Ioi])) }, { intros b hb, exact mem_infi_sets (b - a) (mem_infi_sets (sub_pos.2 hb) (by simp [Iio])) } end lemma order_topology_of_nhds_abs {α : Type*} [topological_space α] [linear_ordered_add_comm_group α] (h_nhds : ∀a:α, 𝓝 a = (⨅r>0, 𝓟 {b | |a - b| < r})) : order_topology α := begin refine ⟨eq_of_nhds_eq_nhds $ λ a, _⟩, rw [h_nhds], letI := preorder.topology α, letI : order_topology α := ⟨rfl⟩, exact (nhds_eq_infi_abs_sub a).symm end lemma linear_ordered_add_comm_group.tendsto_nhds {x : filter β} {a : α} : tendsto f x (𝓝 a) ↔ ∀ ε > (0 : α), ∀ᶠ b in x, |f b - a| < ε := by simp [nhds_eq_infi_abs_sub, abs_sub a] lemma eventually_abs_sub_lt (a : α) {ε : α} (hε : 0 < ε) : ∀ᶠ x in 𝓝 a, |x - a| < ε := (nhds_eq_infi_abs_sub a).symm ▸ mem_infi_sets ε (mem_infi_sets hε $ by simp only [abs_sub, mem_principal_self]) @[priority 100] -- see Note [lower instance priority] instance linear_ordered_add_comm_group.topological_add_group : topological_add_group α := { continuous_add := begin refine continuous_iff_continuous_at.2 _, rintro ⟨a, b⟩, refine linear_ordered_add_comm_group.tendsto_nhds.2 (λ ε ε0, _), rcases dense_or_discrete 0 ε with (⟨δ, δ0, δε⟩|⟨h₁, h₂⟩), { -- If there exists `δ ∈ (0, ε)`, then we choose `δ`-nhd of `a` and `(ε-δ)`-nhd of `b` filter_upwards [prod_is_open.mem_nhds (eventually_abs_sub_lt a δ0) (eventually_abs_sub_lt b (sub_pos.2 δε))], rintros ⟨x, y⟩ ⟨hx : |x - a| < δ, hy : |y - b| < ε - δ⟩, rw [add_sub_comm], calc |x - a + (y - b)| ≤ |x - a| + |y - b| : abs_add _ _ ... < δ + (ε - δ) : add_lt_add hx hy ... = ε : add_sub_cancel'_right _ _ }, { -- Otherewise `ε`-nhd of each point `a` is `{a}` have hε : ∀ {x y}, abs (x - y) < ε → x = y, { intros x y h, simpa [sub_eq_zero] using h₂ _ h }, filter_upwards [prod_is_open.mem_nhds (eventually_abs_sub_lt a ε0) (eventually_abs_sub_lt b ε0)], rintros ⟨x, y⟩ ⟨hx : |x - a| < ε, hy : |y - b| < ε⟩, simpa [hε hx, hε hy] } end, continuous_neg := continuous_iff_continuous_at.2 $ λ a, linear_ordered_add_comm_group.tendsto_nhds.2 $ λ ε ε0, (eventually_abs_sub_lt a ε0).mono $ λ x hx, by rwa [neg_sub_neg, abs_sub] } @[continuity] lemma continuous_abs : continuous (abs : α → α) := continuous_id.max continuous_neg lemma filter.tendsto.abs {f : β → α} {a : α} {l : filter β} (h : tendsto f l (𝓝 a)) : tendsto (λ x, |f x|) l (𝓝 (|a|)) := (continuous_abs.tendsto _).comp h lemma nhds_basis_Ioo_pos [no_bot_order α] [no_top_order α] (a : α) : (𝓝 a).has_basis (λ ε : α, (0 : α) < ε) (λ ε, Ioo (a-ε) (a+ε)) := ⟨begin refine λ t, (nhds_basis_Ioo a).mem_iff.trans ⟨_, _⟩, { rintros ⟨⟨l, u⟩, ⟨hl : l < a, hu : a < u⟩, h' : Ioo l u ⊆ t⟩, refine ⟨min (a-l) (u-a), by apply lt_min; rwa sub_pos, _⟩, rintros x ⟨hx, hx'⟩, apply h', rw [sub_lt, lt_min_iff, sub_lt_sub_iff_left] at hx, rw [← sub_lt_iff_lt_add', lt_min_iff, sub_lt_sub_iff_right] at hx', exact ⟨hx.1, hx'.2⟩ }, { rintros ⟨ε, ε_pos, h⟩, exact ⟨(a-ε, a+ε), by simp [ε_pos], h⟩ }, end⟩ lemma nhds_basis_abs_sub_lt [no_bot_order α] [no_top_order α] (a : α) : (𝓝 a).has_basis (λ ε : α, (0 : α) < ε) (λ ε, {b | abs (b - a) < ε}) := begin convert nhds_basis_Ioo_pos a, { ext ε, change abs (x - a) < ε ↔ a - ε < x ∧ x < a + ε, simp [abs_lt, sub_lt_iff_lt_add, add_comm ε a] }, end variable (α) lemma nhds_basis_zero_abs_sub_lt [no_bot_order α] [no_top_order α] : (𝓝 (0 : α)).has_basis (λ ε : α, (0 : α) < ε) (λ ε, {b | abs b < ε}) := by simpa using nhds_basis_abs_sub_lt (0 : α) variable {α} /-- If `a` is positive we can form a basis from only nonnegative `Ioo` intervals -/ lemma nhds_basis_Ioo_pos_of_pos [no_bot_order α] [no_top_order α] {a : α} (ha : 0 < a) : (𝓝 a).has_basis (λ ε : α, (0 : α) < ε ∧ ε ≤ a) (λ ε, Ioo (a-ε) (a+ε)) := ⟨ λ t, (nhds_basis_Ioo_pos a).mem_iff.trans ⟨λ h, let ⟨i, hi, hit⟩ := h in ⟨min i a, ⟨lt_min hi ha, min_le_right i a⟩, trans (Ioo_subset_Ioo (sub_le_sub_left (min_le_left i a) a) (add_le_add_left (min_le_left i a) a)) hit⟩, λ h, let ⟨i, hi, hit⟩ := h in ⟨i, hi.1, hit⟩ ⟩ ⟩ section variables [topological_space β] {b : β} {a : α} {s : set β} lemma continuous.abs (h : continuous f) : continuous (λ x, |f x|) := continuous_abs.comp h lemma continuous_at.abs (h : continuous_at f b) : continuous_at (λ x, |f x|) b := h.abs lemma continuous_within_at.abs (h : continuous_within_at f s b) : continuous_within_at (λ x, |f x|) s b := h.abs lemma continuous_on.abs (h : continuous_on f s) : continuous_on (λ x, |f x|) s := λ x hx, (h x hx).abs lemma tendsto_abs_nhds_within_zero : tendsto (abs : α → α) (𝓝[{0}ᶜ] 0) (𝓝[Ioi 0] 0) := (continuous_abs.tendsto' (0 : α) 0 abs_zero).inf $ tendsto_principal_principal.2 $ λ x, abs_pos.2 end /-- In a linearly ordered additive commutative group with the order topology, if `f` tends to `C` and `g` tends to `at_top` then `f + g` tends to `at_top`. -/ lemma filter.tendsto.add_at_top {C : α} (hf : tendsto f l (𝓝 C)) (hg : tendsto g l at_top) : tendsto (λ x, f x + g x) l at_top := begin nontriviality α, obtain ⟨C', hC'⟩ : ∃ C', C' < C := no_bot C, refine tendsto_at_top_add_left_of_le' _ C' _ hg, exact (hf.eventually (lt_mem_nhds hC')).mono (λ x, le_of_lt) end /-- In a linearly ordered additive commutative group with the order topology, if `f` tends to `C` and `g` tends to `at_bot` then `f + g` tends to `at_bot`. -/ lemma filter.tendsto.add_at_bot {C : α} (hf : tendsto f l (𝓝 C)) (hg : tendsto g l at_bot) : tendsto (λ x, f x + g x) l at_bot := @filter.tendsto.add_at_top (order_dual α) _ _ _ _ _ _ _ _ hf hg /-- In a linearly ordered additive commutative group with the order topology, if `f` tends to `at_top` and `g` tends to `C` then `f + g` tends to `at_top`. -/ lemma filter.tendsto.at_top_add {C : α} (hf : tendsto f l at_top) (hg : tendsto g l (𝓝 C)) : tendsto (λ x, f x + g x) l at_top := by { conv in (_ + _) { rw add_comm }, exact hg.add_at_top hf } /-- In a linearly ordered additive commutative group with the order topology, if `f` tends to `at_bot` and `g` tends to `C` then `f + g` tends to `at_bot`. -/ lemma filter.tendsto.at_bot_add {C : α} (hf : tendsto f l at_bot) (hg : tendsto g l (𝓝 C)) : tendsto (λ x, f x + g x) l at_bot := by { conv in (_ + _) { rw add_comm }, exact hg.add_at_bot hf } end linear_ordered_add_comm_group section linear_ordered_field variables [linear_ordered_field α] [topological_space α] [order_topology α] variables {l : filter β} {f g : β → α} section continuous_mul lemma mul_tendsto_nhds_zero_right (x : α) : tendsto (uncurry ((*) : α → α → α)) (𝓝 0 ×ᶠ 𝓝 x) $ 𝓝 0 := begin have hx : 0 < 2 * (1 + abs x) := (mul_pos (zero_lt_two) $ lt_of_lt_of_le zero_lt_one $ le_add_of_le_of_nonneg le_rfl (abs_nonneg x)), rw ((nhds_basis_zero_abs_sub_lt α).prod $ nhds_basis_abs_sub_lt x).tendsto_iff (nhds_basis_zero_abs_sub_lt α), refine λ ε ε_pos, ⟨(ε/(2 * (1 + abs x)), 1), ⟨div_pos ε_pos hx, zero_lt_one⟩, _⟩, suffices : ∀ (a b : α), abs a < ε / (2 * (1 + abs x)) → abs (b - x) < 1 → (abs a) * (abs b) < ε, by simpa only [and_imp, prod.forall, mem_prod, ← abs_mul], intros a b h h', refine lt_of_le_of_lt (mul_le_mul_of_nonneg_left _ (abs_nonneg a)) ((lt_div_iff hx).1 h), calc abs b = abs ((b - x) + x) : by rw sub_add_cancel b x ... ≤ abs (b - x) + abs x : abs_add (b - x) x ... ≤ 1 + abs x : add_le_add_right (le_of_lt h') (abs x) ... ≤ 2 * (1 + abs x) : by linarith, end lemma mul_tendsto_nhds_zero_left (x : α) : tendsto (uncurry ((*) : α → α → α)) (𝓝 x ×ᶠ 𝓝 0) $ 𝓝 0 := begin intros s hs, have := mul_tendsto_nhds_zero_right x hs, rw [filter.mem_map, mem_prod_iff] at this ⊢, obtain ⟨U, hU, V, hV, h⟩ := this, exact ⟨V, hV, U, hU, λ y hy, ((mul_comm y.2 y.1) ▸ h (⟨hy.2, hy.1⟩ : (prod.mk y.2 y.1) ∈ (U.prod V)) : y.1 * y.2 ∈ s)⟩, end lemma nhds_eq_map_mul_left_nhds_one {x₀ : α} (hx₀ : x₀ ≠ 0) : 𝓝 x₀ = map (λ x, x₀*x) (𝓝 1) := begin have hx₀' : 0 < abs x₀ := abs_pos.2 hx₀, refine filter.ext (λ t, _), simp only [exists_prop, set_of_subset_set_of, (nhds_basis_abs_sub_lt x₀).mem_iff, (nhds_basis_abs_sub_lt (1 : α)).mem_iff, filter.mem_map], refine ⟨λ h, _, λ h, _⟩, { obtain ⟨i, hi, hit⟩ := h, refine ⟨i / (abs x₀), div_pos hi (abs_pos.2 hx₀), λ x hx, hit _⟩, calc abs (x₀ * x - x₀) = abs (x₀ * (x - 1)) : congr_arg abs (by ring_nf) ... = abs x₀ * abs (x - 1) : abs_mul x₀ (x - 1) ... < abs x₀ * (i / abs x₀) : mul_lt_mul' le_rfl hx (abs_nonneg (x - 1)) (abs_pos.2 hx₀) ... = abs x₀ * i / abs x₀ : by ring ... = i : mul_div_cancel_left i (λ h, hx₀ (abs_eq_zero.1 h)) }, { obtain ⟨i, hi, hit⟩ := h, refine ⟨i * (abs x₀), mul_pos hi (abs_pos.2 hx₀), λ x hx, _⟩, have : abs (x / x₀ - 1) < i, calc abs (x / x₀ - 1) = abs (x / x₀ - x₀ / x₀) : (by rw div_self hx₀) ... = abs ((x - x₀) / x₀) : congr_arg abs (sub_div x x₀ x₀).symm ... = abs (x - x₀) / abs x₀ : abs_div (x - x₀) x₀ ... < i * abs x₀ / abs x₀ : div_lt_div hx le_rfl (mul_nonneg (le_of_lt hi) (abs_nonneg x₀)) (abs_pos.2 hx₀) ... = i : by rw [← mul_div_assoc', div_self (ne_of_lt $ abs_pos.2 hx₀).symm, mul_one], specialize hit (x / x₀) this, rwa [mul_div_assoc', mul_div_cancel_left x hx₀] at hit } end lemma nhds_eq_map_mul_right_nhds_one {x₀ : α} (hx₀ : x₀ ≠ 0) : 𝓝 x₀ = map (λ x, x*x₀) (𝓝 1) := by simp_rw [mul_comm _ x₀, nhds_eq_map_mul_left_nhds_one hx₀] lemma mul_tendsto_nhds_one_nhds_one : tendsto (uncurry ((*) : α → α → α)) (𝓝 1 ×ᶠ 𝓝 1) $ 𝓝 1 := begin rw ((nhds_basis_Ioo_pos (1 : α)).prod $ nhds_basis_Ioo_pos (1 : α)).tendsto_iff (nhds_basis_Ioo_pos_of_pos (zero_lt_one : (0 : α) < 1)), intros ε hε, have hε' : 0 ≤ 1 - ε / 4 := by linarith, have ε_pos : 0 < ε / 4 := by linarith, have ε_pos' : 0 < ε / 2 := by linarith, simp only [and_imp, prod.forall, mem_Ioo, function.uncurry_apply_pair, mem_prod, prod.exists], refine ⟨ε/4, ε/4, ⟨ε_pos, ε_pos⟩, λ a b ha ha' hb hb', _⟩, have ha0 : 0 ≤ a := le_trans hε' (le_of_lt ha), have hb0 : 0 ≤ b := le_trans hε' (le_of_lt hb), refine ⟨lt_of_le_of_lt _ (mul_lt_mul'' ha hb hε' hε'), lt_of_lt_of_le (mul_lt_mul'' ha' hb' ha0 hb0) _⟩, { calc 1 - ε = 1 - ε / 2 - ε/2 : by ring_nf ... ≤ 1 - ε/2 - ε/2 + (ε/2)*(ε/2) : le_add_of_nonneg_right (le_of_lt (mul_pos ε_pos' ε_pos')) ... = (1 - ε/2) * (1 - ε/2) : by ring_nf ... ≤ (1 - ε/4) * (1 - ε/4) : mul_le_mul (by linarith) (by linarith) (by linarith) hε' }, { calc (1 + ε/4) * (1 + ε/4) = 1 + ε/2 + (ε/4)*(ε/4) : by ring_nf ... = 1 + ε/2 + (ε * ε) / 16 : by ring_nf ... ≤ 1 + ε/2 + ε/2 : add_le_add_left (div_le_div (le_of_lt hε.1) (le_trans ((mul_le_mul_left hε.1).2 hε.2) (le_of_eq $ mul_one ε)) zero_lt_two (by linarith)) (1 + ε/2) ... ≤ 1 + ε : by ring_nf } end @[priority 100] instance linear_ordered_field.has_continuous_mul : has_continuous_mul α := ⟨begin rw continuous_iff_continuous_at, rintro ⟨x₀, y₀⟩, by_cases hx₀ : x₀ = 0, { rw [hx₀, continuous_at, zero_mul, nhds_prod_eq], exact mul_tendsto_nhds_zero_right y₀ }, by_cases hy₀ : y₀ = 0, { rw [hy₀, continuous_at, mul_zero, nhds_prod_eq], exact mul_tendsto_nhds_zero_left x₀ }, have hxy : x₀ * y₀ ≠ 0 := mul_ne_zero hx₀ hy₀, have key : (λ p : α × α, x₀ * p.1 * (p.2 * y₀)) = ((λ x, x₀*x) ∘ (λ x, x*y₀)) ∘ (uncurry (*)), { ext p, simp [uncurry, mul_assoc] }, have key₂ : (λ x, x₀*x) ∘ (λ x, y₀*x) = λ x, (x₀ *y₀)*x, { ext x, simp }, calc map (uncurry (*)) (𝓝 (x₀, y₀)) = map (uncurry (*)) (𝓝 x₀ ×ᶠ 𝓝 y₀) : by rw nhds_prod_eq ... = map (λ (p : α × α), x₀ * p.1 * (p.2 * y₀)) ((𝓝 1) ×ᶠ (𝓝 1)) : by rw [uncurry, nhds_eq_map_mul_left_nhds_one hx₀, nhds_eq_map_mul_right_nhds_one hy₀, prod_map_map_eq, filter.map_map] ... = map ((λ x, x₀ * x) ∘ λ x, x * y₀) (map (uncurry (*)) (𝓝 1 ×ᶠ 𝓝 1)) : by rw [key, ← filter.map_map] ... ≤ map ((λ (x : α), x₀ * x) ∘ λ x, x * y₀) (𝓝 1) : map_mono (mul_tendsto_nhds_one_nhds_one) ... = 𝓝 (x₀*y₀) : by rw [← filter.map_map, ← nhds_eq_map_mul_right_nhds_one hy₀, nhds_eq_map_mul_left_nhds_one hy₀, filter.map_map, key₂, ← nhds_eq_map_mul_left_nhds_one hxy], end⟩ end continuous_mul /-- In a linearly ordered field with the order topology, if `f` tends to `at_top` and `g` tends to a positive constant `C` then `f * g` tends to `at_top`. -/ lemma filter.tendsto.at_top_mul {C : α} (hC : 0 < C) (hf : tendsto f l at_top) (hg : tendsto g l (𝓝 C)) : tendsto (λ x, (f x * g x)) l at_top := begin refine tendsto_at_top_mono' _ _ (hf.at_top_mul_const (half_pos hC)), filter_upwards [hg.eventually (lt_mem_nhds (half_lt_self hC)), hf.eventually (eventually_ge_at_top 0)], exact λ x hg hf, mul_le_mul_of_nonneg_left hg.le hf end /-- In a linearly ordered field with the order topology, if `f` tends to a positive constant `C` and `g` tends to `at_top` then `f * g` tends to `at_top`. -/ lemma filter.tendsto.mul_at_top {C : α} (hC : 0 < C) (hf : tendsto f l (𝓝 C)) (hg : tendsto g l at_top) : tendsto (λ x, (f x * g x)) l at_top := by simpa only [mul_comm] using hg.at_top_mul hC hf /-- In a linearly ordered field with the order topology, if `f` tends to `at_top` and `g` tends to a negative constant `C` then `f * g` tends to `at_bot`. -/ lemma filter.tendsto.at_top_mul_neg {C : α} (hC : C < 0) (hf : tendsto f l at_top) (hg : tendsto g l (𝓝 C)) : tendsto (λ x, (f x * g x)) l at_bot := by simpa only [(∘), neg_mul_eq_mul_neg, neg_neg] using tendsto_neg_at_top_at_bot.comp (hf.at_top_mul (neg_pos.2 hC) hg.neg) /-- In a linearly ordered field with the order topology, if `f` tends to a negative constant `C` and `g` tends to `at_top` then `f * g` tends to `at_bot`. -/ lemma filter.tendsto.neg_mul_at_top {C : α} (hC : C < 0) (hf : tendsto f l (𝓝 C)) (hg : tendsto g l at_top) : tendsto (λ x, (f x * g x)) l at_bot := by simpa only [mul_comm] using hg.at_top_mul_neg hC hf /-- In a linearly ordered field with the order topology, if `f` tends to `at_bot` and `g` tends to a positive constant `C` then `f * g` tends to `at_bot`. -/ lemma filter.tendsto.at_bot_mul {C : α} (hC : 0 < C) (hf : tendsto f l at_bot) (hg : tendsto g l (𝓝 C)) : tendsto (λ x, (f x * g x)) l at_bot := by simpa [(∘)] using tendsto_neg_at_top_at_bot.comp ((tendsto_neg_at_bot_at_top.comp hf).at_top_mul hC hg) /-- In a linearly ordered field with the order topology, if `f` tends to `at_bot` and `g` tends to a negative constant `C` then `f * g` tends to `at_top`. -/ lemma filter.tendsto.at_bot_mul_neg {C : α} (hC : C < 0) (hf : tendsto f l at_bot) (hg : tendsto g l (𝓝 C)) : tendsto (λ x, (f x * g x)) l at_top := by simpa [(∘)] using tendsto_neg_at_bot_at_top.comp ((tendsto_neg_at_bot_at_top.comp hf).at_top_mul_neg hC hg) /-- In a linearly ordered field with the order topology, if `f` tends to a positive constant `C` and `g` tends to `at_bot` then `f * g` tends to `at_bot`. -/ lemma filter.tendsto.mul_at_bot {C : α} (hC : 0 < C) (hf : tendsto f l (𝓝 C)) (hg : tendsto g l at_bot) : tendsto (λ x, (f x * g x)) l at_bot := by simpa only [mul_comm] using hg.at_bot_mul hC hf /-- In a linearly ordered field with the order topology, if `f` tends to a negative constant `C` and `g` tends to `at_bot` then `f * g` tends to `at_top`. -/ lemma filter.tendsto.neg_mul_at_bot {C : α} (hC : C < 0) (hf : tendsto f l (𝓝 C)) (hg : tendsto g l at_bot) : tendsto (λ x, (f x * g x)) l at_top := by simpa only [mul_comm] using hg.at_bot_mul_neg hC hf /-- The function `x ↦ x⁻¹` tends to `+∞` on the right of `0`. -/ lemma tendsto_inv_zero_at_top : tendsto (λx:α, x⁻¹) (𝓝[set.Ioi (0:α)] 0) at_top := begin refine (at_top_basis' 1).tendsto_right_iff.2 (λ b hb, _), have hb' : 0 < b := zero_lt_one.trans_le hb, filter_upwards [Ioc_mem_nhds_within_Ioi ⟨le_rfl, inv_pos.2 hb'⟩], exact λ x hx, (le_inv hx.1 hb').1 hx.2 end /-- The function `r ↦ r⁻¹` tends to `0` on the right as `r → +∞`. -/ lemma tendsto_inv_at_top_zero' : tendsto (λr:α, r⁻¹) at_top (𝓝[set.Ioi (0:α)] 0) := begin refine (has_basis.tendsto_iff at_top_basis ⟨λ s, mem_nhds_within_Ioi_iff_exists_Ioc_subset⟩).2 _, refine λ b hb, ⟨b⁻¹, trivial, λ x hx, _⟩, have : 0 < x := lt_of_lt_of_le (inv_pos.2 hb) hx, exact ⟨inv_pos.2 this, (inv_le this hb).2 hx⟩ end lemma tendsto_inv_at_top_zero : tendsto (λr:α, r⁻¹) at_top (𝓝 0) := tendsto_inv_at_top_zero'.mono_right inf_le_left lemma filter.tendsto.div_at_top [has_continuous_mul α] {f g : β → α} {l : filter β} {a : α} (h : tendsto f l (𝓝 a)) (hg : tendsto g l at_top) : tendsto (λ x, f x / g x) l (𝓝 0) := by { simp only [div_eq_mul_inv], exact mul_zero a ▸ h.mul (tendsto_inv_at_top_zero.comp hg) } lemma filter.tendsto.inv_tendsto_at_top (h : tendsto f l at_top) : tendsto (f⁻¹) l (𝓝 0) := tendsto_inv_at_top_zero.comp h lemma filter.tendsto.inv_tendsto_zero (h : tendsto f l (𝓝[set.Ioi 0] 0)) : tendsto (f⁻¹) l at_top := tendsto_inv_zero_at_top.comp h /-- The function `x^(-n)` tends to `0` at `+∞` for any positive natural `n`. A version for positive real powers exists as `tendsto_rpow_neg_at_top`. -/ lemma tendsto_pow_neg_at_top {n : ℕ} (hn : 1 ≤ n) : tendsto (λ x : α, x ^ (-(n:ℤ))) at_top (𝓝 0) := tendsto.congr (λ x, (fpow_neg x n).symm) (filter.tendsto.inv_tendsto_at_top (by simpa [gpow_coe_nat] using tendsto_pow_at_top hn)) lemma tendsto_fpow_at_top_zero {n : ℤ} (hn : n < 0) : tendsto (λ x : α, x^n) at_top (𝓝 0) := begin have : 1 ≤ -n := le_neg.mp (int.le_of_lt_add_one (hn.trans_le (neg_add_self 1).symm.le)), apply tendsto.congr (show ∀ x : α, x^-(-n) = x^n, by simp), lift -n to ℕ using le_of_lt (neg_pos.mpr hn) with N, exact tendsto_pow_neg_at_top (by exact_mod_cast this) end lemma tendsto_const_mul_fpow_at_top_zero {n : ℤ} {c : α} (hn : n < 0) : tendsto (λ x, c * x ^ n) at_top (𝓝 0) := (mul_zero c) ▸ (filter.tendsto.const_mul c (tendsto_fpow_at_top_zero hn)) lemma tendsto_const_mul_pow_nhds_iff {n : ℕ} {c d : α} (hc : c ≠ 0) : tendsto (λ x : α, c * x ^ n) at_top (𝓝 d) ↔ n = 0 ∧ c = d := begin refine ⟨λ h, _, λ h, _⟩, { have hn : n = 0, { by_contradiction hn, have hn : 1 ≤ n := nat.succ_le_iff.2 (lt_of_le_of_ne (zero_le _) (ne.symm hn)), by_cases hc' : 0 < c, { have := (tendsto_const_mul_pow_at_top_iff c n).2 ⟨hn, hc'⟩, exact not_tendsto_nhds_of_tendsto_at_top this d h }, { have := (tendsto_neg_const_mul_pow_at_top_iff c n).2 ⟨hn, lt_of_le_of_ne (not_lt.1 hc') hc⟩, exact not_tendsto_nhds_of_tendsto_at_bot this d h } }, have : (λ x : α, c * x ^ n) = (λ x : α, c), by simp [hn], rw [this, tendsto_const_nhds_iff] at h, exact ⟨hn, h⟩ }, { obtain ⟨hn, hcd⟩ := h, simpa [hn, hcd] using tendsto_const_nhds } end lemma tendsto_const_mul_fpow_at_top_zero_iff {n : ℤ} {c d : α} (hc : c ≠ 0) : tendsto (λ x : α, c * x ^ n) at_top (𝓝 d) ↔ (n = 0 ∧ c = d) ∨ (n < 0 ∧ d = 0) := begin refine ⟨λ h, _, λ h, _⟩, { by_cases hn : 0 ≤ n, { lift n to ℕ using hn, simp only [gpow_coe_nat] at h, rw [tendsto_const_mul_pow_nhds_iff hc, ← int.coe_nat_eq_zero] at h, exact or.inl h }, { rw not_le at hn, refine or.inr ⟨hn, tendsto_nhds_unique h (tendsto_const_mul_fpow_at_top_zero hn)⟩ } }, { cases h, { simp only [h.left, h.right, gpow_zero, mul_one], exact tendsto_const_nhds }, { exact h.2.symm ▸ tendsto_const_mul_fpow_at_top_zero h.1} } end end linear_ordered_field lemma preimage_neg [add_group α] : preimage (has_neg.neg : α → α) = image (has_neg.neg : α → α) := (image_eq_preimage_of_inverse neg_neg neg_neg).symm lemma filter.map_neg [add_group α] : map (has_neg.neg : α → α) = comap (has_neg.neg : α → α) := funext $ assume f, map_eq_comap_of_inverse (funext neg_neg) (funext neg_neg) section order_topology variables [topological_space α] [topological_space β] [linear_order α] [linear_order β] [order_topology α] [order_topology β] lemma is_lub.frequently_mem {a : α} {s : set α} (ha : is_lub s a) (hs : s.nonempty) : ∃ᶠ x in 𝓝[Iic a] a, x ∈ s := begin rcases hs with ⟨a', ha'⟩, intro h, rcases (ha.1 ha').eq_or_lt with (rfl|ha'a), { exact h.self_of_nhds_within le_rfl ha' }, { rcases (mem_nhds_within_Iic_iff_exists_Ioc_subset' ha'a).1 h with ⟨b, hba, hb⟩, rcases ha.exists_between hba with ⟨b', hb's, hb'⟩, exact hb hb' hb's }, end lemma is_lub.frequently_nhds_mem {a : α} {s : set α} (ha : is_lub s a) (hs : s.nonempty) : ∃ᶠ x in 𝓝 a, x ∈ s := (ha.frequently_mem hs).filter_mono inf_le_left lemma is_glb.frequently_mem {a : α} {s : set α} (ha : is_glb s a) (hs : s.nonempty) : ∃ᶠ x in 𝓝[Ici a] a, x ∈ s := @is_lub.frequently_mem (order_dual α) _ _ _ _ _ ha hs lemma is_glb.frequently_nhds_mem {a : α} {s : set α} (ha : is_glb s a) (hs : s.nonempty) : ∃ᶠ x in 𝓝 a, x ∈ s := (ha.frequently_mem hs).filter_mono inf_le_left lemma is_lub.mem_closure {a : α} {s : set α} (ha : is_lub s a) (hs : s.nonempty) : a ∈ closure s := (ha.frequently_nhds_mem hs).mem_closure lemma is_glb.mem_closure {a : α} {s : set α} (ha : is_glb s a) (hs : s.nonempty) : a ∈ closure s := (ha.frequently_nhds_mem hs).mem_closure lemma is_lub.nhds_within_ne_bot {a : α} {s : set α} (ha : is_lub s a) (hs : s.nonempty) : ne_bot (𝓝[s] a) := mem_closure_iff_nhds_within_ne_bot.1 (ha.mem_closure hs) lemma is_glb.nhds_within_ne_bot : ∀ {a : α} {s : set α}, is_glb s a → s.nonempty → ne_bot (𝓝[s] a) := @is_lub.nhds_within_ne_bot (order_dual α) _ _ _ lemma is_lub_of_mem_nhds {s : set α} {a : α} {f : filter α} (hsa : a ∈ upper_bounds s) (hsf : s ∈ f) [ne_bot (f ⊓ 𝓝 a)] : is_lub s a := ⟨hsa, assume b hb, not_lt.1 $ assume hba, have s ∩ {a | b < a} ∈ f ⊓ 𝓝 a, from inter_mem_inf_sets hsf (is_open.mem_nhds (is_open_lt' _) hba), let ⟨x, ⟨hxs, hxb⟩⟩ := nonempty_of_mem_sets this in have b < b, from lt_of_lt_of_le hxb $ hb hxs, lt_irrefl b this⟩ lemma is_glb_of_mem_nhds : ∀ {s : set α} {a : α} {f : filter α}, a ∈ lower_bounds s → s ∈ f → ne_bot (f ⊓ 𝓝 a) → is_glb s a := @is_lub_of_mem_nhds (order_dual α) _ _ _ lemma is_lub.mem_upper_bounds_of_tendsto [preorder γ] [topological_space γ] [order_closed_topology γ] {f : α → γ} {s : set α} {a : α} {b : γ} (hf : ∀x∈s, ∀y∈s, x ≤ y → f x ≤ f y) (ha : is_lub s a) (hb : tendsto f (𝓝[s] a) (𝓝 b)) : b ∈ upper_bounds (f '' s) := begin rintro _ ⟨x, hx, rfl⟩, replace ha := ha.inter_Ici_of_mem hx, haveI := ha.nhds_within_ne_bot ⟨x, hx, le_rfl⟩, refine ge_of_tendsto (hb.mono_left (nhds_within_mono _ (inter_subset_left s (Ici x)))) _, exact mem_sets_of_superset self_mem_nhds_within (λ y hy, hf _ hx _ hy.1 hy.2) end lemma is_lub.is_lub_of_tendsto [preorder γ] [topological_space γ] [order_closed_topology γ] {f : α → γ} {s : set α} {a : α} {b : γ} (hf : ∀x∈s, ∀y∈s, x ≤ y → f x ≤ f y) (ha : is_lub s a) (hs : s.nonempty) (hb : tendsto f (𝓝[s] a) (𝓝 b)) : is_lub (f '' s) b := begin haveI := ha.nhds_within_ne_bot hs, exact ⟨ha.mem_upper_bounds_of_tendsto hf hb, λ b' hb', le_of_tendsto hb (mem_sets_of_superset self_mem_nhds_within $ λ x hx, hb' $ mem_image_of_mem _ hx)⟩ end lemma is_glb.mem_lower_bounds_of_tendsto [preorder γ] [topological_space γ] [order_closed_topology γ] {f : α → γ} {s : set α} {a : α} {b : γ} (hf : ∀x∈s, ∀y∈s, x ≤ y → f x ≤ f y) (ha : is_glb s a) (hb : tendsto f (𝓝[s] a) (𝓝 b)) : b ∈ lower_bounds (f '' s) := @is_lub.mem_upper_bounds_of_tendsto (order_dual α) (order_dual γ) _ _ _ _ _ _ _ _ _ _ (λ x hx y hy, hf y hy x hx) ha hb lemma is_glb.is_glb_of_tendsto [preorder γ] [topological_space γ] [order_closed_topology γ] {f : α → γ} {s : set α} {a : α} {b : γ} (hf : ∀x∈s, ∀y∈s, x ≤ y → f x ≤ f y) : is_glb s a → s.nonempty → tendsto f (𝓝[s] a) (𝓝 b) → is_glb (f '' s) b := @is_lub.is_lub_of_tendsto (order_dual α) (order_dual γ) _ _ _ _ _ _ f s a b (λ x hx y hy, hf y hy x hx) lemma is_lub.mem_lower_bounds_of_tendsto [preorder γ] [topological_space γ] [order_closed_topology γ] {f : α → γ} {s : set α} {a : α} {b : γ} (hf : ∀x∈s, ∀y∈s, x ≤ y → f y ≤ f x) (ha : is_lub s a) (hb : tendsto f (𝓝[s] a) (𝓝 b)) : b ∈ lower_bounds (f '' s) := @is_lub.mem_upper_bounds_of_tendsto α (order_dual γ) _ _ _ _ _ _ _ _ _ _ hf ha hb lemma is_lub.is_glb_of_tendsto [preorder γ] [topological_space γ] [order_closed_topology γ] : ∀ {f : α → γ} {s : set α} {a : α} {b : γ}, (∀x∈s, ∀y∈s, x ≤ y → f y ≤ f x) → is_lub s a → s.nonempty → tendsto f (𝓝[s] a) (𝓝 b) → is_glb (f '' s) b := @is_lub.is_lub_of_tendsto α (order_dual γ) _ _ _ _ _ _ lemma is_glb.mem_upper_bounds_of_tendsto [preorder γ] [topological_space γ] [order_closed_topology γ] {f : α → γ} {s : set α} {a : α} {b : γ} (hf : ∀x∈s, ∀y∈s, x ≤ y → f y ≤ f x) (ha : is_glb s a) (hb : tendsto f (𝓝[s] a) (𝓝 b)) : b ∈ upper_bounds (f '' s) := @is_glb.mem_lower_bounds_of_tendsto α (order_dual γ) _ _ _ _ _ _ _ _ _ _ hf ha hb lemma is_glb.is_lub_of_tendsto [preorder γ] [topological_space γ] [order_closed_topology γ] : ∀ {f : α → γ} {s : set α} {a : α} {b : γ}, (∀x∈s, ∀y∈s, x ≤ y → f y ≤ f x) → is_glb s a → s.nonempty → tendsto f (𝓝[s] a) (𝓝 b) → is_lub (f '' s) b := @is_glb.is_glb_of_tendsto α (order_dual γ) _ _ _ _ _ _ lemma is_lub.mem_of_is_closed {a : α} {s : set α} (ha : is_lub s a) (hs : s.nonempty) (sc : is_closed s) : a ∈ s := sc.closure_subset $ ha.mem_closure hs alias is_lub.mem_of_is_closed ← is_closed.is_lub_mem lemma is_glb.mem_of_is_closed {a : α} {s : set α} (ha : is_glb s a) (hs : s.nonempty) (sc : is_closed s) : a ∈ s := sc.closure_subset $ ha.mem_closure hs alias is_glb.mem_of_is_closed ← is_closed.is_glb_mem /-- A compact set is bounded below -/ lemma is_compact.bdd_below {α : Type u} [topological_space α] [linear_order α] [order_closed_topology α] [nonempty α] {s : set α} (hs : is_compact s) : bdd_below s := begin by_contra H, rcases hs.elim_finite_subcover_image (λ x (_ : x ∈ s), @is_open_Ioi _ _ _ _ x) _ with ⟨t, st, ft, ht⟩, { refine H (ft.bdd_below.imp $ λ C hC y hy, _), rcases mem_bUnion_iff.1 (ht hy) with ⟨x, hx, xy⟩, exact le_trans (hC hx) (le_of_lt xy) }, { refine λ x hx, mem_bUnion_iff.2 (not_imp_comm.1 _ H), exact λ h, ⟨x, λ y hy, le_of_not_lt (h.imp $ λ ys, ⟨_, hy, ys⟩)⟩ } end /-- A compact set is bounded above -/ lemma is_compact.bdd_above {α : Type u} [topological_space α] [linear_order α] [order_topology α] : Π [nonempty α] {s : set α}, is_compact s → bdd_above s := @is_compact.bdd_below (order_dual α) _ _ _ end order_topology section linear_order variables [topological_space α] [linear_order α] [order_topology α] [densely_ordered α] /-- The closure of the interval `(a, +∞)` is the closed interval `[a, +∞)`, unless `a` is a top element. -/ lemma closure_Ioi' {a b : α} (hab : a < b) : closure (Ioi a) = Ici a := begin apply subset.antisymm, { exact closure_minimal Ioi_subset_Ici_self is_closed_Ici }, { rw [← diff_subset_closure_iff, Ici_diff_Ioi_same, singleton_subset_iff], exact is_glb_Ioi.mem_closure ⟨_, hab⟩ } end /-- The closure of the interval `(a, +∞)` is the closed interval `[a, +∞)`. -/ @[simp] lemma closure_Ioi (a : α) [no_top_order α] : closure (Ioi a) = Ici a := let ⟨b, hb⟩ := no_top a in closure_Ioi' hb /-- The closure of the interval `(-∞, a)` is the closed interval `(-∞, a]`, unless `a` is a bottom element. -/ lemma closure_Iio' {a b : α} (hab : b < a) : closure (Iio a) = Iic a := @closure_Ioi' (order_dual α) _ _ _ _ _ _ hab /-- The closure of the interval `(-∞, a)` is the interval `(-∞, a]`. -/ @[simp] lemma closure_Iio (a : α) [no_bot_order α] : closure (Iio a) = Iic a := let ⟨b, hb⟩ := no_bot a in closure_Iio' hb /-- The closure of the open interval `(a, b)` is the closed interval `[a, b]`. -/ @[simp] lemma closure_Ioo {a b : α} (hab : a < b) : closure (Ioo a b) = Icc a b := begin apply subset.antisymm, { exact closure_minimal Ioo_subset_Icc_self is_closed_Icc }, { rw [← diff_subset_closure_iff, Icc_diff_Ioo_same hab.le], have hab' : (Ioo a b).nonempty, from nonempty_Ioo.2 hab, simp only [insert_subset, singleton_subset_iff], exact ⟨(is_glb_Ioo hab).mem_closure hab', (is_lub_Ioo hab).mem_closure hab'⟩ } end /-- The closure of the interval `(a, b]` is the closed interval `[a, b]`. -/ @[simp] lemma closure_Ioc {a b : α} (hab : a < b) : closure (Ioc a b) = Icc a b := begin apply subset.antisymm, { exact closure_minimal Ioc_subset_Icc_self is_closed_Icc }, { apply subset.trans _ (closure_mono Ioo_subset_Ioc_self), rw closure_Ioo hab } end /-- The closure of the interval `[a, b)` is the closed interval `[a, b]`. -/ @[simp] lemma closure_Ico {a b : α} (hab : a < b) : closure (Ico a b) = Icc a b := begin apply subset.antisymm, { exact closure_minimal Ico_subset_Icc_self is_closed_Icc }, { apply subset.trans _ (closure_mono Ioo_subset_Ico_self), rw closure_Ioo hab } end @[simp] lemma interior_Ici [no_bot_order α] {a : α} : interior (Ici a) = Ioi a := by rw [← compl_Iio, interior_compl, closure_Iio, compl_Iic] @[simp] lemma interior_Iic [no_top_order α] {a : α} : interior (Iic a) = Iio a := by rw [← compl_Ioi, interior_compl, closure_Ioi, compl_Ici] @[simp] lemma interior_Icc [no_bot_order α] [no_top_order α] {a b : α}: interior (Icc a b) = Ioo a b := by rw [← Ici_inter_Iic, interior_inter, interior_Ici, interior_Iic, Ioi_inter_Iio] @[simp] lemma interior_Ico [no_bot_order α] {a b : α} : interior (Ico a b) = Ioo a b := by rw [← Ici_inter_Iio, interior_inter, interior_Ici, interior_Iio, Ioi_inter_Iio] @[simp] lemma interior_Ioc [no_top_order α] {a b : α} : interior (Ioc a b) = Ioo a b := by rw [← Ioi_inter_Iic, interior_inter, interior_Ioi, interior_Iic, Ioi_inter_Iio] @[simp] lemma frontier_Ici [no_bot_order α] {a : α} : frontier (Ici a) = {a} := by simp [frontier] @[simp] lemma frontier_Iic [no_top_order α] {a : α} : frontier (Iic a) = {a} := by simp [frontier] @[simp] lemma frontier_Ioi [no_top_order α] {a : α} : frontier (Ioi a) = {a} := by simp [frontier] @[simp] lemma frontier_Iio [no_bot_order α] {a : α} : frontier (Iio a) = {a} := by simp [frontier] @[simp] lemma frontier_Icc [no_bot_order α] [no_top_order α] {a b : α} (h : a < b) : frontier (Icc a b) = {a, b} := by simp [frontier, le_of_lt h, Icc_diff_Ioo_same] @[simp] lemma frontier_Ioo {a b : α} (h : a < b) : frontier (Ioo a b) = {a, b} := by simp [frontier, h, le_of_lt h, Icc_diff_Ioo_same] @[simp] lemma frontier_Ico [no_bot_order α] {a b : α} (h : a < b) : frontier (Ico a b) = {a, b} := by simp [frontier, h, le_of_lt h, Icc_diff_Ioo_same] @[simp] lemma frontier_Ioc [no_top_order α] {a b : α} (h : a < b) : frontier (Ioc a b) = {a, b} := by simp [frontier, h, le_of_lt h, Icc_diff_Ioo_same] lemma nhds_within_Ioi_ne_bot' {a b c : α} (H₁ : a < c) (H₂ : a ≤ b) : ne_bot (𝓝[Ioi a] b) := mem_closure_iff_nhds_within_ne_bot.1 $ by { rw [closure_Ioi' H₁], exact H₂ } lemma nhds_within_Ioi_ne_bot [no_top_order α] {a b : α} (H : a ≤ b) : ne_bot (𝓝[Ioi a] b) := let ⟨c, hc⟩ := no_top a in nhds_within_Ioi_ne_bot' hc H lemma nhds_within_Ioi_self_ne_bot' {a b : α} (H : a < b) : ne_bot (𝓝[Ioi a] a) := nhds_within_Ioi_ne_bot' H (le_refl a) @[instance] lemma nhds_within_Ioi_self_ne_bot [no_top_order α] (a : α) : ne_bot (𝓝[Ioi a] a) := nhds_within_Ioi_ne_bot (le_refl a) lemma nhds_within_Iio_ne_bot' {a b c : α} (H₁ : a < c) (H₂ : b ≤ c) : ne_bot (𝓝[Iio c] b) := mem_closure_iff_nhds_within_ne_bot.1 $ by { rw [closure_Iio' H₁], exact H₂ } lemma nhds_within_Iio_ne_bot [no_bot_order α] {a b : α} (H : a ≤ b) : ne_bot (𝓝[Iio b] a) := let ⟨c, hc⟩ := no_bot b in nhds_within_Iio_ne_bot' hc H lemma nhds_within_Iio_self_ne_bot' {a b : α} (H : a < b) : ne_bot (𝓝[Iio b] b) := nhds_within_Iio_ne_bot' H (le_refl b) @[instance] lemma nhds_within_Iio_self_ne_bot [no_bot_order α] (a : α) : ne_bot (𝓝[Iio a] a) := nhds_within_Iio_ne_bot (le_refl a) lemma right_nhds_within_Ico_ne_bot {a b : α} (H : a < b) : ne_bot (𝓝[Ico a b] b) := (is_lub_Ico H).nhds_within_ne_bot (nonempty_Ico.2 H) lemma left_nhds_within_Ioc_ne_bot {a b : α} (H : a < b) : ne_bot (𝓝[Ioc a b] a) := (is_glb_Ioc H).nhds_within_ne_bot (nonempty_Ioc.2 H) lemma left_nhds_within_Ioo_ne_bot {a b : α} (H : a < b) : ne_bot (𝓝[Ioo a b] a) := (is_glb_Ioo H).nhds_within_ne_bot (nonempty_Ioo.2 H) lemma right_nhds_within_Ioo_ne_bot {a b : α} (H : a < b) : ne_bot (𝓝[Ioo a b] b) := (is_lub_Ioo H).nhds_within_ne_bot (nonempty_Ioo.2 H) end linear_order section linear_order variables [topological_space α] [linear_order α] [order_topology α] [densely_ordered α] {a b : α} {s : set α} lemma comap_coe_nhds_within_Iio_of_Ioo_subset (hb : s ⊆ Iio b) (hs : s.nonempty → ∃ a < b, Ioo a b ⊆ s) : comap (coe : s → α) (𝓝[Iio b] b) = at_top := begin nontriviality, haveI : nonempty s := nontrivial_iff_nonempty.1 ‹_›, rcases hs (nonempty_subtype.1 ‹_›) with ⟨a, h, hs⟩, ext u, split, { rintros ⟨t, ht, hts⟩, obtain ⟨x, ⟨hxa : a ≤ x, hxb : x < b⟩, hxt : Ioo x b ⊆ t⟩ := (mem_nhds_within_Iio_iff_exists_mem_Ico_Ioo_subset h).mp ht, obtain ⟨y, hxy, hyb⟩ := exists_between hxb, refine mem_sets_of_superset (mem_at_top ⟨y, hs ⟨hxa.trans_lt hxy, hyb⟩⟩) _, rintros ⟨z, hzs⟩ (hyz : y ≤ z), refine hts (hxt ⟨hxy.trans_le _, hb _⟩); assumption }, { intros hu, obtain ⟨x : s, hx : ∀ z, x ≤ z → z ∈ u⟩ := mem_at_top_sets.1 hu, exact ⟨Ioo x b, Ioo_mem_nhds_within_Iio (right_mem_Ioc.2 $ hb x.2), λ z hz, hx _ hz.1.le⟩ } end lemma comap_coe_nhds_within_Ioi_of_Ioo_subset (ha : s ⊆ Ioi a) (hs : s.nonempty → ∃ b > a, Ioo a b ⊆ s) : comap (coe : s → α) (𝓝[Ioi a] a) = at_bot := begin refine @comap_coe_nhds_within_Iio_of_Ioo_subset (order_dual α) _ _ _ _ _ _ ha (λ h, _), rcases hs h with ⟨b, hab, h⟩, use [b, hab], rwa dual_Ioo end lemma map_coe_at_top_of_Ioo_subset (hb : s ⊆ Iio b) (hs : ∀ a' < b, ∃ a < b, Ioo a b ⊆ s) : map (coe : s → α) at_top = 𝓝[Iio b] b := begin rcases eq_empty_or_nonempty (Iio b) with (hb'|⟨a, ha⟩), { rw [filter_eq_bot_of_not_nonempty at_top, map_bot, hb', nhds_within_empty], exact λ ⟨⟨x, hx⟩⟩, not_nonempty_iff_eq_empty.2 hb' ⟨x, hb hx⟩ }, { rw [← comap_coe_nhds_within_Iio_of_Ioo_subset hb (λ _, hs a ha), map_comap_of_mem], rw subtype.range_coe, exact (mem_nhds_within_Iio_iff_exists_Ioo_subset' ha).2 (hs a ha) }, end lemma map_coe_at_bot_of_Ioo_subset (ha : s ⊆ Ioi a) (hs : ∀ b' > a, ∃ b > a, Ioo a b ⊆ s) : map (coe : s → α) at_bot = (𝓝[Ioi a] a) := begin refine @map_coe_at_top_of_Ioo_subset (order_dual α) _ _ _ _ a s ha (λ b' hb', _), rcases hs b' hb' with ⟨b, hab, hbs⟩, use [b, hab], rwa dual_Ioo end /-- The `at_top` filter for an open interval `Ioo a b` comes from the left-neighbourhoods filter at the right endpoint in the ambient order. -/ lemma comap_coe_Ioo_nhds_within_Iio (a b : α) : comap (coe : Ioo a b → α) (𝓝[Iio b] b) = at_top := comap_coe_nhds_within_Iio_of_Ioo_subset Ioo_subset_Iio_self $ λ h, ⟨a, nonempty_Ioo.1 h, subset.refl _⟩ /-- The `at_bot` filter for an open interval `Ioo a b` comes from the right-neighbourhoods filter at the left endpoint in the ambient order. -/ lemma comap_coe_Ioo_nhds_within_Ioi (a b : α) : comap (coe : Ioo a b → α) (𝓝[Ioi a] a) = at_bot := comap_coe_nhds_within_Ioi_of_Ioo_subset Ioo_subset_Ioi_self $ λ h, ⟨b, nonempty_Ioo.1 h, subset.refl _⟩ lemma comap_coe_Ioi_nhds_within_Ioi (a : α) : comap (coe : Ioi a → α) (𝓝[Ioi a] a) = at_bot := comap_coe_nhds_within_Ioi_of_Ioo_subset (subset.refl _) $ λ ⟨x, hx⟩, ⟨x, hx, Ioo_subset_Ioi_self⟩ lemma comap_coe_Iio_nhds_within_Iio (a : α) : comap (coe : Iio a → α) (𝓝[Iio a] a) = at_top := @comap_coe_Ioi_nhds_within_Ioi (order_dual α) _ _ _ _ a @[simp] lemma map_coe_Ioo_at_top {a b : α} (h : a < b) : map (coe : Ioo a b → α) at_top = 𝓝[Iio b] b := map_coe_at_top_of_Ioo_subset Ioo_subset_Iio_self $ λ _ _, ⟨_, h, subset.refl _⟩ @[simp] lemma map_coe_Ioo_at_bot {a b : α} (h : a < b) : map (coe : Ioo a b → α) at_bot = 𝓝[Ioi a] a := map_coe_at_bot_of_Ioo_subset Ioo_subset_Ioi_self $ λ _ _, ⟨_, h, subset.refl _⟩ @[simp] lemma map_coe_Ioi_at_bot (a : α) : map (coe : Ioi a → α) at_bot = 𝓝[Ioi a] a := map_coe_at_bot_of_Ioo_subset (subset.refl _) $ λ b hb, ⟨b, hb, Ioo_subset_Ioi_self⟩ @[simp] lemma map_coe_Iio_at_top (a : α) : map (coe : Iio a → α) at_top = 𝓝[Iio a] a := @map_coe_Ioi_at_bot (order_dual α) _ _ _ _ _ variables {l : filter β} {f : α → β} @[simp] lemma tendsto_comp_coe_Ioo_at_top (h : a < b) : tendsto (λ x : Ioo a b, f x) at_top l ↔ tendsto f (𝓝[Iio b] b) l := by rw [← map_coe_Ioo_at_top h, tendsto_map'_iff] @[simp] lemma tendsto_comp_coe_Ioo_at_bot (h : a < b) : tendsto (λ x : Ioo a b, f x) at_bot l ↔ tendsto f (𝓝[Ioi a] a) l := by rw [← map_coe_Ioo_at_bot h, tendsto_map'_iff] @[simp] lemma tendsto_comp_coe_Ioi_at_bot : tendsto (λ x : Ioi a, f x) at_bot l ↔ tendsto f (𝓝[Ioi a] a) l := by rw [← map_coe_Ioi_at_bot, tendsto_map'_iff] @[simp] lemma tendsto_comp_coe_Iio_at_top : tendsto (λ x : Iio a, f x) at_top l ↔ tendsto f (𝓝[Iio a] a) l := by rw [← map_coe_Iio_at_top, tendsto_map'_iff] @[simp] lemma tendsto_Ioo_at_top {f : β → Ioo a b} : tendsto f l at_top ↔ tendsto (λ x, (f x : α)) l (𝓝[Iio b] b) := by rw [← comap_coe_Ioo_nhds_within_Iio, tendsto_comap_iff] @[simp] lemma tendsto_Ioo_at_bot {f : β → Ioo a b} : tendsto f l at_bot ↔ tendsto (λ x, (f x : α)) l (𝓝[Ioi a] a) := by rw [← comap_coe_Ioo_nhds_within_Ioi, tendsto_comap_iff] @[simp] lemma tendsto_Ioi_at_bot {f : β → Ioi a} : tendsto f l at_bot ↔ tendsto (λ x, (f x : α)) l (𝓝[Ioi a] a) := by rw [← comap_coe_Ioi_nhds_within_Ioi, tendsto_comap_iff] @[simp] lemma tendsto_Iio_at_top {f : β → Iio a} : tendsto f l at_top ↔ tendsto (λ x, (f x : α)) l (𝓝[Iio a] a) := by rw [← comap_coe_Iio_nhds_within_Iio, tendsto_comap_iff] end linear_order section complete_linear_order variables [complete_linear_order α] [topological_space α] [order_topology α] [complete_linear_order β] [topological_space β] [order_topology β] [nonempty γ] lemma Sup_mem_closure {α : Type u} [topological_space α] [complete_linear_order α] [order_topology α] {s : set α} (hs : s.nonempty) : Sup s ∈ closure s := (is_lub_Sup s).mem_closure hs lemma Inf_mem_closure {α : Type u} [topological_space α] [complete_linear_order α] [order_topology α] {s : set α} (hs : s.nonempty) : Inf s ∈ closure s := (is_glb_Inf s).mem_closure hs lemma is_closed.Sup_mem {α : Type u} [topological_space α] [complete_linear_order α] [order_topology α] {s : set α} (hs : s.nonempty) (hc : is_closed s) : Sup s ∈ s := (is_lub_Sup s).mem_of_is_closed hs hc lemma is_closed.Inf_mem {α : Type u} [topological_space α] [complete_linear_order α] [order_topology α] {s : set α} (hs : s.nonempty) (hc : is_closed s) : Inf s ∈ s := (is_glb_Inf s).mem_of_is_closed hs hc /-- A monotone function continuous at the supremum of a nonempty set sends this supremum to the supremum of the image of this set. -/ lemma map_Sup_of_continuous_at_of_monotone' {f : α → β} {s : set α} (Cf : continuous_at f (Sup s)) (Mf : monotone f) (hs : s.nonempty) : f (Sup s) = Sup (f '' s) := --This is a particular case of the more general is_lub.is_lub_of_tendsto ((is_lub_Sup _).is_lub_of_tendsto (λ x hx y hy xy, Mf xy) hs $ Cf.mono_left inf_le_left).Sup_eq.symm /-- A monotone function `s` sending `bot` to `bot` and continuous at the supremum of a set sends this supremum to the supremum of the image of this set. -/ lemma map_Sup_of_continuous_at_of_monotone {f : α → β} {s : set α} (Cf : continuous_at f (Sup s)) (Mf : monotone f) (fbot : f ⊥ = ⊥) : f (Sup s) = Sup (f '' s) := begin cases s.eq_empty_or_nonempty with h h, { simp [h, fbot] }, { exact map_Sup_of_continuous_at_of_monotone' Cf Mf h } end /-- A monotone function continuous at the indexed supremum over a nonempty `Sort` sends this indexed supremum to the indexed supremum of the composition. -/ lemma map_supr_of_continuous_at_of_monotone' {ι : Sort*} [nonempty ι] {f : α → β} {g : ι → α} (Cf : continuous_at f (supr g)) (Mf : monotone f) : f (⨆ i, g i) = ⨆ i, f (g i) := by rw [supr, map_Sup_of_continuous_at_of_monotone' Cf Mf (range_nonempty g), ← range_comp, supr] /-- If a monotone function sending `bot` to `bot` is continuous at the indexed supremum over a `Sort`, then it sends this indexed supremum to the indexed supremum of the composition. -/ lemma map_supr_of_continuous_at_of_monotone {ι : Sort*} {f : α → β} {g : ι → α} (Cf : continuous_at f (supr g)) (Mf : monotone f) (fbot : f ⊥ = ⊥) : f (⨆ i, g i) = ⨆ i, f (g i) := by rw [supr, map_Sup_of_continuous_at_of_monotone Cf Mf fbot, ← range_comp, supr] /-- A monotone function continuous at the infimum of a nonempty set sends this infimum to the infimum of the image of this set. -/ lemma map_Inf_of_continuous_at_of_monotone' {f : α → β} {s : set α} (Cf : continuous_at f (Inf s)) (Mf : monotone f) (hs : s.nonempty) : f (Inf s) = Inf (f '' s) := @map_Sup_of_continuous_at_of_monotone' (order_dual α) (order_dual β) _ _ _ _ _ _ f s Cf Mf.order_dual hs /-- A monotone function `s` sending `top` to `top` and continuous at the infimum of a set sends this infimum to the infimum of the image of this set. -/ lemma map_Inf_of_continuous_at_of_monotone {f : α → β} {s : set α} (Cf : continuous_at f (Inf s)) (Mf : monotone f) (ftop : f ⊤ = ⊤) : f (Inf s) = Inf (f '' s) := @map_Sup_of_continuous_at_of_monotone (order_dual α) (order_dual β) _ _ _ _ _ _ f s Cf Mf.order_dual ftop /-- A monotone function continuous at the indexed infimum over a nonempty `Sort` sends this indexed infimum to the indexed infimum of the composition. -/ lemma map_infi_of_continuous_at_of_monotone' {ι : Sort*} [nonempty ι] {f : α → β} {g : ι → α} (Cf : continuous_at f (infi g)) (Mf : monotone f) : f (⨅ i, g i) = ⨅ i, f (g i) := @map_supr_of_continuous_at_of_monotone' (order_dual α) (order_dual β) _ _ _ _ _ _ ι _ f g Cf Mf.order_dual /-- If a monotone function sending `top` to `top` is continuous at the indexed infimum over a `Sort`, then it sends this indexed infimum to the indexed infimum of the composition. -/ lemma map_infi_of_continuous_at_of_monotone {ι : Sort*} {f : α → β} {g : ι → α} (Cf : continuous_at f (infi g)) (Mf : monotone f) (ftop : f ⊤ = ⊤) : f (infi g) = infi (f ∘ g) := @map_supr_of_continuous_at_of_monotone (order_dual α) (order_dual β) _ _ _ _ _ _ ι f g Cf Mf.order_dual ftop end complete_linear_order section conditionally_complete_linear_order variables [conditionally_complete_linear_order α] [topological_space α] [order_topology α] [conditionally_complete_linear_order β] [topological_space β] [order_topology β] [nonempty γ] lemma cSup_mem_closure {s : set α} (hs : s.nonempty) (B : bdd_above s) : Sup s ∈ closure s := (is_lub_cSup hs B).mem_closure hs lemma cInf_mem_closure {s : set α} (hs : s.nonempty) (B : bdd_below s) : Inf s ∈ closure s := (is_glb_cInf hs B).mem_closure hs lemma is_closed.cSup_mem {s : set α} (hc : is_closed s) (hs : s.nonempty) (B : bdd_above s) : Sup s ∈ s := (is_lub_cSup hs B).mem_of_is_closed hs hc lemma is_closed.cInf_mem {s : set α} (hc : is_closed s) (hs : s.nonempty) (B : bdd_below s) : Inf s ∈ s := (is_glb_cInf hs B).mem_of_is_closed hs hc /-- If a monotone function is continuous at the supremum of a nonempty bounded above set `s`, then it sends this supremum to the supremum of the image of `s`. -/ lemma map_cSup_of_continuous_at_of_monotone {f : α → β} {s : set α} (Cf : continuous_at f (Sup s)) (Mf : monotone f) (ne : s.nonempty) (H : bdd_above s) : f (Sup s) = Sup (f '' s) := begin refine ((is_lub_cSup (ne.image f) (Mf.map_bdd_above H)).unique _).symm, refine (is_lub_cSup ne H).is_lub_of_tendsto (λx hx y hy xy, Mf xy) ne _, exact Cf.mono_left inf_le_left end /-- If a monotone function is continuous at the indexed supremum of a bounded function on a nonempty `Sort`, then it sends this supremum to the supremum of the composition. -/ lemma map_csupr_of_continuous_at_of_monotone {f : α → β} {g : γ → α} (Cf : continuous_at f (⨆ i, g i)) (Mf : monotone f) (H : bdd_above (range g)) : f (⨆ i, g i) = ⨆ i, f (g i) := by rw [supr, map_cSup_of_continuous_at_of_monotone Cf Mf (range_nonempty _) H, ← range_comp, supr] /-- If a monotone function is continuous at the infimum of a nonempty bounded below set `s`, then it sends this infimum to the infimum of the image of `s`. -/ lemma map_cInf_of_continuous_at_of_monotone {f : α → β} {s : set α} (Cf : continuous_at f (Inf s)) (Mf : monotone f) (ne : s.nonempty) (H : bdd_below s) : f (Inf s) = Inf (f '' s) := @map_cSup_of_continuous_at_of_monotone (order_dual α) (order_dual β) _ _ _ _ _ _ f s Cf Mf.order_dual ne H /-- A continuous monotone function sends indexed infimum to indexed infimum in conditionally complete linear order, under a boundedness assumption. -/ lemma map_cinfi_of_continuous_at_of_monotone {f : α → β} {g : γ → α} (Cf : continuous_at f (⨅ i, g i)) (Mf : monotone f) (H : bdd_below (range g)) : f (⨅ i, g i) = ⨅ i, f (g i) := @map_csupr_of_continuous_at_of_monotone (order_dual α) (order_dual β) _ _ _ _ _ _ _ _ _ _ Cf Mf.order_dual H /-- A bounded connected subset of a conditionally complete linear order includes the open interval `(Inf s, Sup s)`. -/ lemma is_connected.Ioo_cInf_cSup_subset {s : set α} (hs : is_connected s) (hb : bdd_below s) (ha : bdd_above s) : Ioo (Inf s) (Sup s) ⊆ s := λ x hx, let ⟨y, ys, hy⟩ := (is_glb_lt_iff (is_glb_cInf hs.nonempty hb)).1 hx.1 in let ⟨z, zs, hz⟩ := (lt_is_lub_iff (is_lub_cSup hs.nonempty ha)).1 hx.2 in hs.Icc_subset ys zs ⟨le_of_lt hy, le_of_lt hz⟩ lemma eq_Icc_cInf_cSup_of_connected_bdd_closed {s : set α} (hc : is_connected s) (hb : bdd_below s) (ha : bdd_above s) (hcl : is_closed s) : s = Icc (Inf s) (Sup s) := subset.antisymm (subset_Icc_cInf_cSup hb ha) $ hc.Icc_subset (hcl.cInf_mem hc.nonempty hb) (hcl.cSup_mem hc.nonempty ha) lemma is_preconnected.Ioi_cInf_subset {s : set α} (hs : is_preconnected s) (hb : bdd_below s) (ha : ¬bdd_above s) : Ioi (Inf s) ⊆ s := begin have sne : s.nonempty := @nonempty_of_not_bdd_above α _ s ⟨Inf ∅⟩ ha, intros x hx, obtain ⟨y, ys, hy⟩ : ∃ y ∈ s, y < x := (is_glb_lt_iff (is_glb_cInf sne hb)).1 hx, obtain ⟨z, zs, hz⟩ : ∃ z ∈ s, x < z := not_bdd_above_iff.1 ha x, exact hs.Icc_subset ys zs ⟨le_of_lt hy, le_of_lt hz⟩ end lemma is_preconnected.Iio_cSup_subset {s : set α} (hs : is_preconnected s) (hb : ¬bdd_below s) (ha : bdd_above s) : Iio (Sup s) ⊆ s := @is_preconnected.Ioi_cInf_subset (order_dual α) _ _ _ s hs ha hb /-- A preconnected set in a conditionally complete linear order is either one of the intervals `[Inf s, Sup s]`, `[Inf s, Sup s)`, `(Inf s, Sup s]`, `(Inf s, Sup s)`, `[Inf s, +∞)`, `(Inf s, +∞)`, `(-∞, Sup s]`, `(-∞, Sup s)`, `(-∞, +∞)`, or `∅`. The converse statement requires `α` to be densely ordererd. -/ lemma is_preconnected.mem_intervals {s : set α} (hs : is_preconnected s) : s ∈ ({Icc (Inf s) (Sup s), Ico (Inf s) (Sup s), Ioc (Inf s) (Sup s), Ioo (Inf s) (Sup s), Ici (Inf s), Ioi (Inf s), Iic (Sup s), Iio (Sup s), univ, ∅} : set (set α)) := begin rcases s.eq_empty_or_nonempty with rfl|hne, { apply_rules [or.inr, mem_singleton] }, have hs' : is_connected s := ⟨hne, hs⟩, by_cases hb : bdd_below s; by_cases ha : bdd_above s, { rcases mem_Icc_Ico_Ioc_Ioo_of_subset_of_subset (hs'.Ioo_cInf_cSup_subset hb ha) (subset_Icc_cInf_cSup hb ha) with hs|hs|hs|hs, { exact (or.inl hs) }, { exact (or.inr $ or.inl hs) }, { exact (or.inr $ or.inr $ or.inl hs) }, { exact (or.inr $ or.inr $ or.inr $ or.inl hs) } }, { refine (or.inr $ or.inr $ or.inr $ or.inr _), cases mem_Ici_Ioi_of_subset_of_subset (hs.Ioi_cInf_subset hb ha) (λ x hx, cInf_le hb hx) with hs hs, { exact or.inl hs }, { exact or.inr (or.inl hs) } }, { iterate 6 { apply or.inr }, cases mem_Iic_Iio_of_subset_of_subset (hs.Iio_cSup_subset hb ha) (λ x hx, le_cSup ha hx) with hs hs, { exact or.inl hs }, { exact or.inr (or.inl hs) } }, { iterate 8 { apply or.inr }, exact or.inl (hs.eq_univ_of_unbounded hb ha) } end /-- A preconnected set is either one of the intervals `Icc`, `Ico`, `Ioc`, `Ioo`, `Ici`, `Ioi`, `Iic`, `Iio`, or `univ`, or `∅`. The converse statement requires `α` to be densely ordererd. Though one can represent `∅` as `(Inf s, Inf s)`, we include it into the list of possible cases to improve readability. -/ lemma set_of_is_preconnected_subset_of_ordered : {s : set α | is_preconnected s} ⊆ -- bounded intervals (range (uncurry Icc) ∪ range (uncurry Ico) ∪ range (uncurry Ioc) ∪ range (uncurry Ioo)) ∪ -- unbounded intervals and `univ` (range Ici ∪ range Ioi ∪ range Iic ∪ range Iio ∪ {univ, ∅}) := begin intros s hs, rcases hs.mem_intervals with hs|hs|hs|hs|hs|hs|hs|hs|hs|hs, { exact (or.inl $ or.inl $ or.inl $ or.inl ⟨(Inf s, Sup s), hs.symm⟩) }, { exact (or.inl $ or.inl $ or.inl $ or.inr ⟨(Inf s, Sup s), hs.symm⟩) }, { exact (or.inl $ or.inl $ or.inr ⟨(Inf s, Sup s), hs.symm⟩) }, { exact (or.inl $ or.inr ⟨(Inf s, Sup s), hs.symm⟩) }, { exact (or.inr $ or.inl $ or.inl $ or.inl $ or.inl ⟨Inf s, hs.symm⟩) }, { exact (or.inr $ or.inl $ or.inl $ or.inl $ or.inr ⟨Inf s, hs.symm⟩) }, { exact (or.inr $ or.inl $ or.inl $ or.inr ⟨Sup s, hs.symm⟩) }, { exact (or.inr $ or.inl $ or.inr ⟨Sup s, hs.symm⟩) }, { exact (or.inr $ or.inr $ or.inl hs) }, { exact (or.inr $ or.inr $ or.inr hs) } end /-- A "continuous induction principle" for a closed interval: if a set `s` meets `[a, b]` on a closed subset, contains `a`, and the set `s ∩ [a, b)` has no maximal point, then `b ∈ s`. -/ lemma is_closed.mem_of_ge_of_forall_exists_gt {a b : α} {s : set α} (hs : is_closed (s ∩ Icc a b)) (ha : a ∈ s) (hab : a ≤ b) (hgt : ∀ x ∈ s ∩ Ico a b, (s ∩ Ioc x b).nonempty) : b ∈ s := begin let S := s ∩ Icc a b, replace ha : a ∈ S, from ⟨ha, left_mem_Icc.2 hab⟩, have Sbd : bdd_above S, from ⟨b, λ z hz, hz.2.2⟩, let c := Sup (s ∩ Icc a b), have c_mem : c ∈ S, from hs.cSup_mem ⟨_, ha⟩ Sbd, have c_le : c ≤ b, from cSup_le ⟨_, ha⟩ (λ x hx, hx.2.2), cases eq_or_lt_of_le c_le with hc hc, from hc ▸ c_mem.1, exfalso, rcases hgt c ⟨c_mem.1, c_mem.2.1, hc⟩ with ⟨x, xs, cx, xb⟩, exact not_lt_of_le (le_cSup Sbd ⟨xs, le_trans (le_cSup Sbd ha) (le_of_lt cx), xb⟩) cx end /-- A "continuous induction principle" for a closed interval: if a set `s` meets `[a, b]` on a closed subset, contains `a`, and for any `a ≤ x < y ≤ b`, `x ∈ s`, the set `s ∩ (x, y]` is not empty, then `[a, b] ⊆ s`. -/ lemma is_closed.Icc_subset_of_forall_exists_gt {a b : α} {s : set α} (hs : is_closed (s ∩ Icc a b)) (ha : a ∈ s) (hgt : ∀ x ∈ s ∩ Ico a b, ∀ y ∈ Ioi x, (s ∩ Ioc x y).nonempty) : Icc a b ⊆ s := begin assume y hy, have : is_closed (s ∩ Icc a y), { suffices : s ∩ Icc a y = s ∩ Icc a b ∩ Icc a y, { rw this, exact is_closed.inter hs is_closed_Icc }, rw [inter_assoc], congr, exact (inter_eq_self_of_subset_right $ Icc_subset_Icc_right hy.2).symm }, exact is_closed.mem_of_ge_of_forall_exists_gt this ha hy.1 (λ x hx, hgt x ⟨hx.1, Ico_subset_Ico_right hy.2 hx.2⟩ y hx.2.2) end section densely_ordered variables [densely_ordered α] {a b : α} /-- A "continuous induction principle" for a closed interval: if a set `s` meets `[a, b]` on a closed subset, contains `a`, and for any `x ∈ s ∩ [a, b)` the set `s` includes some open neighborhood of `x` within `(x, +∞)`, then `[a, b] ⊆ s`. -/ lemma is_closed.Icc_subset_of_forall_mem_nhds_within {a b : α} {s : set α} (hs : is_closed (s ∩ Icc a b)) (ha : a ∈ s) (hgt : ∀ x ∈ s ∩ Ico a b, s ∈ 𝓝[Ioi x] x) : Icc a b ⊆ s := begin apply hs.Icc_subset_of_forall_exists_gt ha, rintros x ⟨hxs, hxab⟩ y hyxb, have : s ∩ Ioc x y ∈ 𝓝[Ioi x] x, from inter_mem_sets (hgt x ⟨hxs, hxab⟩) (Ioc_mem_nhds_within_Ioi ⟨le_refl _, hyxb⟩), exact (nhds_within_Ioi_self_ne_bot' hxab.2).nonempty_of_mem this end /-- A closed interval in a densely ordered conditionally complete linear order is preconnected. -/ lemma is_preconnected_Icc : is_preconnected (Icc a b) := is_preconnected_closed_iff.2 begin rintros s t hs ht hab ⟨x, hx⟩ ⟨y, hy⟩, wlog hxy : x ≤ y := le_total x y using [x y s t, y x t s], have xyab : Icc x y ⊆ Icc a b := Icc_subset_Icc hx.1.1 hy.1.2, by_contradiction hst, suffices : Icc x y ⊆ s, from hst ⟨y, xyab $ right_mem_Icc.2 hxy, this $ right_mem_Icc.2 hxy, hy.2⟩, apply (is_closed.inter hs is_closed_Icc).Icc_subset_of_forall_mem_nhds_within hx.2, rintros z ⟨zs, hz⟩, have zt : z ∈ tᶜ, from λ zt, hst ⟨z, xyab $ Ico_subset_Icc_self hz, zs, zt⟩, have : tᶜ ∩ Ioc z y ∈ 𝓝[Ioi z] z, { rw [← nhds_within_Ioc_eq_nhds_within_Ioi hz.2], exact mem_nhds_within.2 ⟨tᶜ, ht.is_open_compl, zt, subset.refl _⟩}, apply mem_sets_of_superset this, have : Ioc z y ⊆ s ∪ t, from λ w hw, hab (xyab ⟨le_trans hz.1 (le_of_lt hw.1), hw.2⟩), exact λ w ⟨wt, wzy⟩, (this wzy).elim id (λ h, (wt h).elim) end lemma is_preconnected_interval : is_preconnected (interval a b) := is_preconnected_Icc lemma is_preconnected_iff_ord_connected {s : set α} : is_preconnected s ↔ ord_connected s := ⟨λ h, ⟨λ x hx y hy, h.Icc_subset hx hy⟩, λ h, is_preconnected_of_forall_pair $ λ x y hx hy, ⟨interval x y, h.interval_subset hx hy, left_mem_interval, right_mem_interval, is_preconnected_interval⟩⟩ alias is_preconnected_iff_ord_connected ↔ is_preconnected.ord_connected set.ord_connected.is_preconnected lemma is_preconnected_Ici : is_preconnected (Ici a) := ord_connected_Ici.is_preconnected lemma is_preconnected_Iic : is_preconnected (Iic a) := ord_connected_Iic.is_preconnected lemma is_preconnected_Iio : is_preconnected (Iio a) := ord_connected_Iio.is_preconnected lemma is_preconnected_Ioi : is_preconnected (Ioi a) := ord_connected_Ioi.is_preconnected lemma is_preconnected_Ioo : is_preconnected (Ioo a b) := ord_connected_Ioo.is_preconnected lemma is_preconnected_Ioc : is_preconnected (Ioc a b) := ord_connected_Ioc.is_preconnected lemma is_preconnected_Ico : is_preconnected (Ico a b) := ord_connected_Ico.is_preconnected @[priority 100] instance ordered_connected_space : preconnected_space α := ⟨ord_connected_univ.is_preconnected⟩ /-- In a dense conditionally complete linear order, the set of preconnected sets is exactly the set of the intervals `Icc`, `Ico`, `Ioc`, `Ioo`, `Ici`, `Ioi`, `Iic`, `Iio`, `(-∞, +∞)`, or `∅`. Though one can represent `∅` as `(Inf s, Inf s)`, we include it into the list of possible cases to improve readability. -/ lemma set_of_is_preconnected_eq_of_ordered : {s : set α | is_preconnected s} = -- bounded intervals (range (uncurry Icc) ∪ range (uncurry Ico) ∪ range (uncurry Ioc) ∪ range (uncurry Ioo)) ∪ -- unbounded intervals and `univ` (range Ici ∪ range Ioi ∪ range Iic ∪ range Iio ∪ {univ, ∅}) := begin refine subset.antisymm set_of_is_preconnected_subset_of_ordered _, simp only [subset_def, -mem_range, forall_range_iff, uncurry, or_imp_distrib, forall_and_distrib, mem_union, mem_set_of_eq, insert_eq, mem_singleton_iff, forall_eq, forall_true_iff, and_true, is_preconnected_Icc, is_preconnected_Ico, is_preconnected_Ioc, is_preconnected_Ioo, is_preconnected_Ioi, is_preconnected_Iio, is_preconnected_Ici, is_preconnected_Iic, is_preconnected_univ, is_preconnected_empty], end variables {δ : Type*} [linear_order δ] [topological_space δ] [order_closed_topology δ] /-- Intermediate Value Theorem for continuous functions on closed intervals, case `f a ≤ t ≤ f b`.-/ lemma intermediate_value_Icc {a b : α} (hab : a ≤ b) {f : α → δ} (hf : continuous_on f (Icc a b)) : Icc (f a) (f b) ⊆ f '' (Icc a b) := is_preconnected_Icc.intermediate_value (left_mem_Icc.2 hab) (right_mem_Icc.2 hab) hf /-- Intermediate Value Theorem for continuous functions on closed intervals, case `f a ≥ t ≥ f b`.-/ lemma intermediate_value_Icc' {a b : α} (hab : a ≤ b) {f : α → δ} (hf : continuous_on f (Icc a b)) : Icc (f b) (f a) ⊆ f '' (Icc a b) := is_preconnected_Icc.intermediate_value (right_mem_Icc.2 hab) (left_mem_Icc.2 hab) hf /-- Intermediate Value Theorem for continuous functions on closed intervals, unordered case. -/ lemma intermediate_value_interval {a b : α} {f : α → δ} (hf : continuous_on f (interval a b)) : interval (f a) (f b) ⊆ f '' interval a b := by cases le_total (f a) (f b); simp [*, is_preconnected_interval.intermediate_value] lemma intermediate_value_Ico {a b : α} (hab : a ≤ b) {f : α → δ} (hf : continuous_on f (Icc a b)) : Ico (f a) (f b) ⊆ f '' (Ico a b) := or.elim (eq_or_lt_of_le hab) (λ he y h, absurd h.2 (not_lt_of_le (he ▸ h.1))) (λ hlt, @is_preconnected.intermediate_value_Ico _ _ _ _ _ _ _ (is_preconnected_Ico) _ _ ⟨refl a, hlt⟩ (right_nhds_within_Ico_ne_bot hlt) inf_le_right _ (hf.mono Ico_subset_Icc_self) _ ((hf.continuous_within_at ⟨hab, refl b⟩).mono Ico_subset_Icc_self)) lemma intermediate_value_Ico' {a b : α} (hab : a ≤ b) {f : α → δ} (hf : continuous_on f (Icc a b)) : Ioc (f b) (f a) ⊆ f '' (Ico a b) := or.elim (eq_or_lt_of_le hab) (λ he y h, absurd h.1 (not_lt_of_le (he ▸ h.2))) (λ hlt, @is_preconnected.intermediate_value_Ioc _ _ _ _ _ _ _ (is_preconnected_Ico) _ _ ⟨refl a, hlt⟩ (right_nhds_within_Ico_ne_bot hlt) inf_le_right _ (hf.mono Ico_subset_Icc_self) _ ((hf.continuous_within_at ⟨hab, refl b⟩).mono Ico_subset_Icc_self)) lemma intermediate_value_Ioc {a b : α} (hab : a ≤ b) {f : α → δ} (hf : continuous_on f (Icc a b)) : Ioc (f a) (f b) ⊆ f '' (Ioc a b) := or.elim (eq_or_lt_of_le hab) (λ he y h, absurd h.2 (not_le_of_lt (he ▸ h.1))) (λ hlt, @is_preconnected.intermediate_value_Ioc _ _ _ _ _ _ _ (is_preconnected_Ioc) _ _ ⟨hlt, refl b⟩ (left_nhds_within_Ioc_ne_bot hlt) inf_le_right _ (hf.mono Ioc_subset_Icc_self) _ ((hf.continuous_within_at ⟨refl a, hab⟩).mono Ioc_subset_Icc_self)) lemma intermediate_value_Ioc' {a b : α} (hab : a ≤ b) {f : α → δ} (hf : continuous_on f (Icc a b)) : Ico (f b) (f a) ⊆ f '' (Ioc a b) := or.elim (eq_or_lt_of_le hab) (λ he y h, absurd h.1 (not_le_of_lt (he ▸ h.2))) (λ hlt, @is_preconnected.intermediate_value_Ico _ _ _ _ _ _ _ (is_preconnected_Ioc) _ _ ⟨hlt, refl b⟩ (left_nhds_within_Ioc_ne_bot hlt) inf_le_right _ (hf.mono Ioc_subset_Icc_self) _ ((hf.continuous_within_at ⟨refl a, hab⟩).mono Ioc_subset_Icc_self)) lemma intermediate_value_Ioo {a b : α} (hab : a ≤ b) {f : α → δ} (hf : continuous_on f (Icc a b)) : Ioo (f a) (f b) ⊆ f '' (Ioo a b) := or.elim (eq_or_lt_of_le hab) (λ he y h, absurd h.2 (not_lt_of_lt (he ▸ h.1))) (λ hlt, @is_preconnected.intermediate_value_Ioo _ _ _ _ _ _ _ (is_preconnected_Ioo) _ _ (left_nhds_within_Ioo_ne_bot hlt) (right_nhds_within_Ioo_ne_bot hlt) inf_le_right inf_le_right _ (hf.mono Ioo_subset_Icc_self) _ _ ((hf.continuous_within_at ⟨refl a, hab⟩).mono Ioo_subset_Icc_self) ((hf.continuous_within_at ⟨hab, refl b⟩).mono Ioo_subset_Icc_self)) lemma intermediate_value_Ioo' {a b : α} (hab : a ≤ b) {f : α → δ} (hf : continuous_on f (Icc a b)) : Ioo (f b) (f a) ⊆ f '' (Ioo a b) := or.elim (eq_or_lt_of_le hab) (λ he y h, absurd h.1 (not_lt_of_lt (he ▸ h.2))) (λ hlt, @is_preconnected.intermediate_value_Ioo _ _ _ _ _ _ _ (is_preconnected_Ioo) _ _ (right_nhds_within_Ioo_ne_bot hlt) (left_nhds_within_Ioo_ne_bot hlt) inf_le_right inf_le_right _ (hf.mono Ioo_subset_Icc_self) _ _ ((hf.continuous_within_at ⟨hab, refl b⟩).mono Ioo_subset_Icc_self) ((hf.continuous_within_at ⟨refl a, hab⟩).mono Ioo_subset_Icc_self)) /-- A continuous function which tendsto `at_top` `at_top` and to `at_bot` `at_bot` is surjective. -/ lemma continuous.surjective {f : α → δ} (hf : continuous f) (h_top : tendsto f at_top at_top) (h_bot : tendsto f at_bot at_bot) : function.surjective f := λ p, mem_range_of_exists_le_of_exists_ge hf (h_bot.eventually (eventually_le_at_bot p)).exists (h_top.eventually (eventually_ge_at_top p)).exists /-- A continuous function which tendsto `at_bot` `at_top` and to `at_top` `at_bot` is surjective. -/ lemma continuous.surjective' {f : α → δ} (hf : continuous f) (h_top : tendsto f at_bot at_top) (h_bot : tendsto f at_top at_bot) : function.surjective f := @continuous.surjective (order_dual α) _ _ _ _ _ _ _ _ _ hf h_top h_bot /-- If a function `f : α → β` is continuous on a nonempty interval `s`, its restriction to `s` tends to `at_bot : filter β` along `at_bot : filter ↥s` and tends to `at_top : filter β` along `at_top : filter ↥s`, then the restriction of `f` to `s` is surjective. We formulate the conclusion as `surj_on f s univ`. -/ lemma continuous_on.surj_on_of_tendsto {f : α → β} {s : set α} [ord_connected s] (hs : s.nonempty) (hf : continuous_on f s) (hbot : tendsto (λ x : s, f x) at_bot at_bot) (htop : tendsto (λ x : s, f x) at_top at_top) : surj_on f s univ := by haveI := inhabited_of_nonempty hs.to_subtype; exact (surj_on_iff_surjective.2 $ (continuous_on_iff_continuous_restrict.1 hf).surjective htop hbot) /-- If a function `f : α → β` is continuous on a nonempty interval `s`, its restriction to `s` tends to `at_top : filter β` along `at_bot : filter ↥s` and tends to `at_bot : filter β` along `at_top : filter ↥s`, then the restriction of `f` to `s` is surjective. We formulate the conclusion as `surj_on f s univ`. -/ lemma continuous_on.surj_on_of_tendsto' {f : α → β} {s : set α} [ord_connected s] (hs : s.nonempty) (hf : continuous_on f s) (hbot : tendsto (λ x : s, f x) at_bot at_top) (htop : tendsto (λ x : s, f x) at_top at_bot) : surj_on f s univ := @continuous_on.surj_on_of_tendsto α (order_dual β) _ _ _ _ _ _ _ _ _ _ hs hf hbot htop end densely_ordered /-- A closed interval in a conditionally complete linear order is compact. -/ lemma compact_Icc {a b : α} : is_compact (Icc a b) := begin cases le_or_lt a b with hab hab, swap, { simp [hab] }, refine is_compact_iff_ultrafilter_le_nhds.2 (λ f hf, _), contrapose! hf, rw [le_principal_iff], have hpt : ∀ x ∈ Icc a b, {x} ∉ f, from λ x hx hxf, hf x hx ((le_pure_iff.2 hxf).trans (pure_le_nhds x)), set s := {x ∈ Icc a b | Icc a x ∉ f}, have hsb : b ∈ upper_bounds s, from λ x hx, hx.1.2, have sbd : bdd_above s, from ⟨b, hsb⟩, have ha : a ∈ s, by simp [hpt, hab], rcases hab.eq_or_lt with rfl|hlt, { exact ha.2 }, set c := Sup s, have hsc : is_lub s c, from is_lub_cSup ⟨a, ha⟩ sbd, have hc : c ∈ Icc a b, from ⟨hsc.1 ha, hsc.2 hsb⟩, specialize hf c hc, have hcs : c ∈ s, { cases hc.1.eq_or_lt with heq hlt, { rwa ← heq }, refine ⟨hc, λ hcf, hf (λ U hU, _)⟩, rcases (mem_nhds_within_Iic_iff_exists_Ioc_subset' hlt).1 (mem_nhds_within_of_mem_nhds hU) with ⟨x, hxc, hxU⟩, rcases ((hsc.frequently_mem ⟨a, ha⟩).and_eventually (Ioc_mem_nhds_within_Iic ⟨hxc, le_rfl⟩)).exists with ⟨y, ⟨hyab, hyf⟩, hy⟩, refine mem_sets_of_superset(f.diff_mem_iff.2 ⟨hcf, hyf⟩) (subset.trans _ hxU), rw diff_subset_iff, exact subset.trans Icc_subset_Icc_union_Ioc (union_subset_union subset.rfl $ Ioc_subset_Ioc_left hy.1.le) }, cases hc.2.eq_or_lt with heq hlt, { rw ← heq, exact hcs.2 }, contrapose! hf, intros U hU, rcases (mem_nhds_within_Ici_iff_exists_mem_Ioc_Ico_subset hlt).1 (mem_nhds_within_of_mem_nhds hU) with ⟨y, hxy, hyU⟩, refine mem_sets_of_superset _ hyU, clear_dependent U, have hy : y ∈ Icc a b, from ⟨hc.1.trans hxy.1.le, hxy.2⟩, by_cases hay : Icc a y ∈ f, { refine mem_sets_of_superset (f.diff_mem_iff.2 ⟨f.diff_mem_iff.2 ⟨hay, hcs.2⟩, hpt y hy⟩) _, rw [diff_subset_iff, union_comm, Ico_union_right hxy.1.le, diff_subset_iff], exact Icc_subset_Icc_union_Icc }, { exact ((hsc.1 ⟨hy, hay⟩).not_lt hxy.1).elim }, end /-- An unordered closed interval in a conditionally complete linear order is compact. -/ lemma compact_interval {a b : α} : is_compact (interval a b) := compact_Icc lemma compact_pi_Icc {ι : Type*} {α : ι → Type*} [Π i, conditionally_complete_linear_order (α i)] [Π i, topological_space (α i)] [Π i, order_topology (α i)] (a b : Π i, α i) : is_compact (Icc a b) := pi_univ_Icc a b ▸ is_compact_univ_pi $ λ i, compact_Icc instance compact_space_Icc (a b : α) : compact_space (Icc a b) := is_compact_iff_compact_space.mp compact_Icc instance compact_space_pi_Icc {ι : Type*} {α : ι → Type*} [Π i, conditionally_complete_linear_order (α i)] [Π i, topological_space (α i)] [Π i, order_topology (α i)] (a b : Π i, α i) : compact_space (Icc a b) := is_compact_iff_compact_space.mp (compact_pi_Icc a b) @[priority 100] -- See note [lower instance priority] instance compact_space_of_complete_linear_order {α : Type*} [complete_linear_order α] [topological_space α] [order_topology α] : compact_space α := ⟨by simp only [← Icc_bot_top, compact_Icc]⟩ lemma is_compact.Inf_mem {s : set α} (hs : is_compact s) (ne_s : s.nonempty) : Inf s ∈ s := hs.is_closed.cInf_mem ne_s hs.bdd_below lemma is_compact.Sup_mem {s : set α} (hs : is_compact s) (ne_s : s.nonempty) : Sup s ∈ s := @is_compact.Inf_mem (order_dual α) _ _ _ _ hs ne_s lemma is_compact.is_glb_Inf {s : set α} (hs : is_compact s) (ne_s : s.nonempty) : is_glb s (Inf s) := is_glb_cInf ne_s hs.bdd_below lemma is_compact.is_lub_Sup {s : set α} (hs : is_compact s) (ne_s : s.nonempty) : is_lub s (Sup s) := @is_compact.is_glb_Inf (order_dual α) _ _ _ _ hs ne_s lemma is_compact.is_least_Inf {s : set α} (hs : is_compact s) (ne_s : s.nonempty) : is_least s (Inf s) := ⟨hs.Inf_mem ne_s, (hs.is_glb_Inf ne_s).1⟩ lemma is_compact.is_greatest_Sup {s : set α} (hs : is_compact s) (ne_s : s.nonempty) : is_greatest s (Sup s) := @is_compact.is_least_Inf (order_dual α) _ _ _ _ hs ne_s lemma is_compact.exists_is_least {s : set α} (hs : is_compact s) (ne_s : s.nonempty) : ∃ x, is_least s x := ⟨_, hs.is_least_Inf ne_s⟩ lemma is_compact.exists_is_greatest {s : set α} (hs : is_compact s) (ne_s : s.nonempty) : ∃ x, is_greatest s x := ⟨_, hs.is_greatest_Sup ne_s⟩ lemma is_compact.exists_is_glb {s : set α} (hs : is_compact s) (ne_s : s.nonempty) : ∃ x ∈ s, is_glb s x := ⟨_, hs.Inf_mem ne_s, hs.is_glb_Inf ne_s⟩ lemma is_compact.exists_is_lub {s : set α} (hs : is_compact s) (ne_s : s.nonempty) : ∃ x ∈ s, is_lub s x := ⟨_, hs.Sup_mem ne_s, hs.is_lub_Sup ne_s⟩ lemma is_compact.exists_Inf_image_eq {α : Type u} [topological_space α] {s : set α} (hs : is_compact s) (ne_s : s.nonempty) {f : α → β} (hf : continuous_on f s) : ∃ x ∈ s, Inf (f '' s) = f x := let ⟨x, hxs, hx⟩ := (hs.image_of_continuous_on hf).Inf_mem (ne_s.image f) in ⟨x, hxs, hx.symm⟩ lemma is_compact.exists_Sup_image_eq {α : Type u} [topological_space α]: ∀ {s : set α}, is_compact s → s.nonempty → ∀ {f : α → β}, continuous_on f s → ∃ x ∈ s, Sup (f '' s) = f x := @is_compact.exists_Inf_image_eq (order_dual β) _ _ _ _ _ lemma eq_Icc_of_connected_compact {s : set α} (h₁ : is_connected s) (h₂ : is_compact s) : s = Icc (Inf s) (Sup s) := eq_Icc_cInf_cSup_of_connected_bdd_closed h₁ h₂.bdd_below h₂.bdd_above h₂.is_closed /-- The extreme value theorem: a continuous function realizes its minimum on a compact set -/ lemma is_compact.exists_forall_le {α : Type u} [topological_space α] {s : set α} (hs : is_compact s) (ne_s : s.nonempty) {f : α → β} (hf : continuous_on f s) : ∃x∈s, ∀y∈s, f x ≤ f y := begin rcases hs.exists_Inf_image_eq ne_s hf with ⟨x, hxs, hx⟩, refine ⟨x, hxs, λ y hy, _⟩, rw ← hx, exact ((hs.image_of_continuous_on hf).is_glb_Inf (ne_s.image f)).1 (mem_image_of_mem _ hy) end /-- The extreme value theorem: a continuous function realizes its maximum on a compact set -/ lemma is_compact.exists_forall_ge {α : Type u} [topological_space α]: ∀ {s : set α}, is_compact s → s.nonempty → ∀ {f : α → β}, continuous_on f s → ∃x∈s, ∀y∈s, f y ≤ f x := @is_compact.exists_forall_le (order_dual β) _ _ _ _ _ /-- The extreme value theorem: if a continuous function `f` tends to infinity away from compact sets, then it has a global minimum. -/ lemma continuous.exists_forall_le {α : Type*} [topological_space α] [nonempty α] {f : α → β} (hf : continuous f) (hlim : tendsto f (cocompact α) at_top) : ∃ x, ∀ y, f x ≤ f y := begin inhabit α, obtain ⟨s : set α, hsc : is_compact s, hsf : ∀ x ∉ s, f (default α) ≤ f x⟩ := (has_basis_cocompact.tendsto_iff at_top_basis).1 hlim (f $ default α) trivial, obtain ⟨x, -, hx⟩ := (hsc.insert (default α)).exists_forall_le (nonempty_insert _ _) hf.continuous_on, refine ⟨x, λ y, _⟩, by_cases hy : y ∈ s, exacts [hx y (or.inr hy), (hx _ (or.inl rfl)).trans (hsf y hy)] end /-- The extreme value theorem: if a continuous function `f` tends to negative infinity away from compactx sets, then it has a global maximum. -/ lemma continuous.exists_forall_ge {α : Type*} [topological_space α] [nonempty α] {f : α → β} (hf : continuous f) (hlim : tendsto f (cocompact α) at_bot) : ∃ x, ∀ y, f y ≤ f x := @continuous.exists_forall_le (order_dual β) _ _ _ _ _ _ _ hf hlim end conditionally_complete_linear_order end order_topology /-! Here is a counter-example to a version of the following with `conditionally_complete_lattice α`. Take `α = [0, 1) → ℝ` with the natural lattice structure, `ι = ℕ`. Put `f n x = -x^n`. Then `⨆ n, f n = 0` while none of `f n` is strictly greater than the constant function `-0.5`. -/ lemma tendsto_at_top_csupr {ι α : Type*} [preorder ι] [topological_space α] [conditionally_complete_linear_order α] [order_topology α] {f : ι → α} (h_mono : monotone f) (hbdd : bdd_above $ range f) : tendsto f at_top (𝓝 (⨆i, f i)) := begin by_cases hi : nonempty ι, { resetI, rw tendsto_order, split, { intros a h, cases exists_lt_of_lt_csupr h with N hN, apply eventually.mono (mem_at_top N), exact λ i hi, lt_of_lt_of_le hN (h_mono hi) }, { exact λ a h, eventually_of_forall (λ n, lt_of_le_of_lt (le_csupr hbdd n) h) } }, { exact tendsto_of_not_nonempty hi } end lemma tendsto_at_bot_cinfi {ι α : Type*} [preorder ι] [topological_space α] [conditionally_complete_linear_order α] [order_topology α] {f : ι → α} (h_mono : monotone f) (hbdd : bdd_below $ range f) : tendsto f at_bot (𝓝 (⨅i, f i)) := @tendsto_at_top_csupr (order_dual ι) (order_dual α) _ _ _ _ _ h_mono.order_dual hbdd lemma tendsto_at_top_cinfi {ι α : Type*} [preorder ι] [topological_space α] [conditionally_complete_linear_order α] [order_topology α] {f : ι → α} (h_mono : ∀ ⦃i j⦄, i ≤ j → f j ≤ f i) (hbdd : bdd_below $ range f) : tendsto f at_top (𝓝 (⨅i, f i)) := @tendsto_at_top_csupr _ (order_dual α) _ _ _ _ _ @h_mono hbdd lemma tendsto_at_bot_csupr {ι α : Type*} [preorder ι] [topological_space α] [conditionally_complete_linear_order α] [order_topology α] {f : ι → α} (h_mono : ∀ ⦃i j⦄, i ≤ j → f j ≤ f i) (hbdd : bdd_above $ range f) : tendsto f at_bot (𝓝 (⨆i, f i)) := @tendsto_at_bot_cinfi ι (order_dual α) _ _ _ _ _ h_mono hbdd lemma tendsto_at_top_supr {ι α : Type*} [preorder ι] [topological_space α] [complete_linear_order α] [order_topology α] {f : ι → α} (h_mono : monotone f) : tendsto f at_top (𝓝 (⨆i, f i)) := tendsto_at_top_csupr h_mono (order_top.bdd_above _) lemma tendsto_at_bot_infi {ι α : Type*} [preorder ι] [topological_space α] [complete_linear_order α] [order_topology α] {f : ι → α} (h_mono : monotone f) : tendsto f at_bot (𝓝 (⨅i, f i)) := tendsto_at_bot_cinfi h_mono (order_bot.bdd_below _) lemma tendsto_at_top_infi {ι α : Type*} [preorder ι] [topological_space α] [complete_linear_order α] [order_topology α] {f : ι → α} (h_mono : ∀ ⦃i j⦄, i ≤ j → f j ≤ f i) : tendsto f at_top (𝓝 (⨅i, f i)) := tendsto_at_top_cinfi @h_mono (order_bot.bdd_below _) lemma tendsto_at_bot_supr {ι α : Type*} [preorder ι] [topological_space α] [complete_linear_order α] [order_topology α] {f : ι → α} (h_mono : ∀ ⦃i j⦄, i ≤ j → f j ≤ f i) : tendsto f at_bot (𝓝 (⨆i, f i)) := tendsto_at_bot_csupr h_mono (order_top.bdd_above _) lemma tendsto_of_monotone {ι α : Type*} [preorder ι] [topological_space α] [conditionally_complete_linear_order α] [order_topology α] {f : ι → α} (h_mono : monotone f) : tendsto f at_top at_top ∨ (∃ l, tendsto f at_top (𝓝 l)) := if H : bdd_above (range f) then or.inr ⟨_, tendsto_at_top_csupr h_mono H⟩ else or.inl $ tendsto_at_top_at_top_of_monotone' h_mono H lemma supr_eq_of_tendsto {α β} [topological_space α] [complete_linear_order α] [order_topology α] [nonempty β] [semilattice_sup β] {f : β → α} {a : α} (hf : monotone f) : tendsto f at_top (𝓝 a) → supr f = a := tendsto_nhds_unique (tendsto_at_top_supr hf) lemma infi_eq_of_tendsto {α} [topological_space α] [complete_linear_order α] [order_topology α] [nonempty β] [semilattice_sup β] {f : β → α} {a : α} (hf : ∀n m, n ≤ m → f m ≤ f n) : tendsto f at_top (𝓝 a) → infi f = a := tendsto_nhds_unique (tendsto_at_top_infi hf) @[to_additive] lemma tendsto_inv_nhds_within_Ioi [ordered_comm_group α] [topological_space α] [topological_group α] {a : α} : tendsto has_inv.inv (𝓝[Ioi a] a) (𝓝[Iio (a⁻¹)] (a⁻¹)) := (continuous_inv.tendsto a).inf $ by simp [tendsto_principal_principal] @[to_additive] lemma tendsto_inv_nhds_within_Iio [ordered_comm_group α] [topological_space α] [topological_group α] {a : α} : tendsto has_inv.inv (𝓝[Iio a] a) (𝓝[Ioi (a⁻¹)] (a⁻¹)) := (continuous_inv.tendsto a).inf $ by simp [tendsto_principal_principal] @[to_additive] lemma tendsto_inv_nhds_within_Ioi_inv [ordered_comm_group α] [topological_space α] [topological_group α] {a : α} : tendsto has_inv.inv (𝓝[Ioi (a⁻¹)] (a⁻¹)) (𝓝[Iio a] a) := by simpa only [inv_inv] using @tendsto_inv_nhds_within_Ioi _ _ _ _ (a⁻¹) @[to_additive] lemma tendsto_inv_nhds_within_Iio_inv [ordered_comm_group α] [topological_space α] [topological_group α] {a : α} : tendsto has_inv.inv (𝓝[Iio (a⁻¹)] (a⁻¹)) (𝓝[Ioi a] a) := by simpa only [inv_inv] using @tendsto_inv_nhds_within_Iio _ _ _ _ (a⁻¹) @[to_additive] lemma tendsto_inv_nhds_within_Ici [ordered_comm_group α] [topological_space α] [topological_group α] {a : α} : tendsto has_inv.inv (𝓝[Ici a] a) (𝓝[Iic (a⁻¹)] (a⁻¹)) := (continuous_inv.tendsto a).inf $ by simp [tendsto_principal_principal] @[to_additive] lemma tendsto_inv_nhds_within_Iic [ordered_comm_group α] [topological_space α] [topological_group α] {a : α} : tendsto has_inv.inv (𝓝[Iic a] a) (𝓝[Ici (a⁻¹)] (a⁻¹)) := (continuous_inv.tendsto a).inf $ by simp [tendsto_principal_principal] @[to_additive] lemma tendsto_inv_nhds_within_Ici_inv [ordered_comm_group α] [topological_space α] [topological_group α] {a : α} : tendsto has_inv.inv (𝓝[Ici (a⁻¹)] (a⁻¹)) (𝓝[Iic a] a) := by simpa only [inv_inv] using @tendsto_inv_nhds_within_Ici _ _ _ _ (a⁻¹) @[to_additive] lemma tendsto_inv_nhds_within_Iic_inv [ordered_comm_group α] [topological_space α] [topological_group α] {a : α} : tendsto has_inv.inv (𝓝[Iic (a⁻¹)] (a⁻¹)) (𝓝[Ici a] a) := by simpa only [inv_inv] using @tendsto_inv_nhds_within_Iic _ _ _ _ (a⁻¹) lemma nhds_left_sup_nhds_right (a : α) [topological_space α] [linear_order α] : 𝓝[Iic a] a ⊔ 𝓝[Ici a] a = 𝓝 a := by rw [← nhds_within_union, Iic_union_Ici, nhds_within_univ] lemma nhds_left'_sup_nhds_right (a : α) [topological_space α] [linear_order α] : 𝓝[Iio a] a ⊔ 𝓝[Ici a] a = 𝓝 a := by rw [← nhds_within_union, Iio_union_Ici, nhds_within_univ] lemma nhds_left_sup_nhds_right' (a : α) [topological_space α] [linear_order α] : 𝓝[Iic a] a ⊔ 𝓝[Ioi a] a = 𝓝 a := by rw [← nhds_within_union, Iic_union_Ioi, nhds_within_univ] lemma continuous_at_iff_continuous_left_right [topological_space α] [linear_order α] [topological_space β] {a : α} {f : α → β} : continuous_at f a ↔ continuous_within_at f (Iic a) a ∧ continuous_within_at f (Ici a) a := by simp only [continuous_within_at, continuous_at, ← tendsto_sup, nhds_left_sup_nhds_right] lemma continuous_within_at_Ioi_iff_Ici {α β : Type*} [topological_space α] [partial_order α] [topological_space β] {a : α} {f : α → β} : continuous_within_at f (Ioi a) a ↔ continuous_within_at f (Ici a) a := by simp only [← Ici_diff_left, continuous_within_at_diff_self] lemma continuous_within_at_Iio_iff_Iic {α β : Type*} [topological_space α] [linear_order α] [topological_space β] {a : α} {f : α → β} : continuous_within_at f (Iio a) a ↔ continuous_within_at f (Iic a) a := begin have := @continuous_within_at_Ioi_iff_Ici (order_dual α) _ _ _ _ _ f, erw [dual_Ici, dual_Ioi] at this, exact this, end lemma continuous_at_iff_continuous_left'_right' [topological_space α] [linear_order α] [topological_space β] {a : α} {f : α → β} : continuous_at f a ↔ continuous_within_at f (Iio a) a ∧ continuous_within_at f (Ioi a) a := by rw [continuous_within_at_Ioi_iff_Ici, continuous_within_at_Iio_iff_Iic, continuous_at_iff_continuous_left_right] /-! ### Continuity of monotone functions In this section we prove the following fact: if `f` is a monotone function on a neighborhood of `a` and the image of this neighborhood is a neighborhood of `f a`, then `f` is continuous at `a`, see `continuous_at_of_mono_incr_on_of_image_mem_nhds`, as well as several similar facts. -/ section linear_order variables [linear_order α] [topological_space α] [order_topology α] variables [linear_order β] [topological_space β] [order_topology β] /-- If `f` is a function strictly monotonically increasing on a right neighborhood of `a` and the image of this neighborhood under `f` meets every interval `(f a, b]`, `b > f a`, then `f` is continuous at `a` from the right. The assumption `hfs : ∀ b > f a, ∃ c ∈ s, f c ∈ Ioc (f a) b` is required because otherwise the function `f : ℝ → ℝ` given by `f x = if x ≤ 0 then x else x + 1` would be a counter-example at `a = 0`. -/ lemma strict_mono_incr_on.continuous_at_right_of_exists_between {f : α → β} {s : set α} {a : α} (h_mono : strict_mono_incr_on f s) (hs : s ∈ 𝓝[Ici a] a) (hfs : ∀ b > f a, ∃ c ∈ s, f c ∈ Ioc (f a) b) : continuous_within_at f (Ici a) a := begin have ha : a ∈ Ici a := left_mem_Ici, have has : a ∈ s := mem_of_mem_nhds_within ha hs, refine tendsto_order.2 ⟨λ b hb, _, λ b hb, _⟩, { filter_upwards [hs, self_mem_nhds_within], intros x hxs hxa, exact hb.trans_le ((h_mono.le_iff_le has hxs).2 hxa) }, { rcases hfs b hb with ⟨c, hcs, hac, hcb⟩, rw [h_mono.lt_iff_lt has hcs] at hac, filter_upwards [hs, Ico_mem_nhds_within_Ici (left_mem_Ico.2 hac)], rintros x hx ⟨hax, hxc⟩, exact ((h_mono.lt_iff_lt hx hcs).2 hxc).trans_le hcb } end /-- If `f` is a function monotonically increasing function on a right neighborhood of `a` and the image of this neighborhood under `f` meets every interval `(f a, b)`, `b > f a`, then `f` is continuous at `a` from the right. The assumption `hfs : ∀ b > f a, ∃ c ∈ s, f c ∈ Ioo (f a) b` cannot be replaced by the weaker assumption `hfs : ∀ b > f a, ∃ c ∈ s, f c ∈ Ioc (f a) b` we use for strictly monotone functions because otherwise the function `ceil : ℝ → ℤ` would be a counter-example at `a = 0`. -/ lemma continuous_at_right_of_mono_incr_on_of_exists_between {f : α → β} {s : set α} {a : α} (h_mono : ∀ (x ∈ s) (y ∈ s), x ≤ y → f x ≤ f y) (hs : s ∈ 𝓝[Ici a] a) (hfs : ∀ b > f a, ∃ c ∈ s, f c ∈ Ioo (f a) b) : continuous_within_at f (Ici a) a := begin have ha : a ∈ Ici a := left_mem_Ici, have has : a ∈ s := mem_of_mem_nhds_within ha hs, refine tendsto_order.2 ⟨λ b hb, _, λ b hb, _⟩, { filter_upwards [hs, self_mem_nhds_within], intros x hxs hxa, exact hb.trans_le (h_mono _ has _ hxs hxa) }, { rcases hfs b hb with ⟨c, hcs, hac, hcb⟩, have : a < c, from not_le.1 (λ h, hac.not_le $ h_mono _ hcs _ has h), filter_upwards [hs, Ico_mem_nhds_within_Ici (left_mem_Ico.2 this)], rintros x hx ⟨hax, hxc⟩, exact (h_mono _ hx _ hcs hxc.le).trans_lt hcb } end /-- If a function `f` with a densely ordered codomain is monotonically increasing on a right neighborhood of `a` and the closure of the image of this neighborhood under `f` is a right neighborhood of `f a`, then `f` is continuous at `a` from the right. -/ lemma continuous_at_right_of_mono_incr_on_of_closure_image_mem_nhds_within [densely_ordered β] {f : α → β} {s : set α} {a : α} (h_mono : ∀ (x ∈ s) (y ∈ s), x ≤ y → f x ≤ f y) (hs : s ∈ 𝓝[Ici a] a) (hfs : closure (f '' s) ∈ 𝓝[Ici (f a)] (f a)) : continuous_within_at f (Ici a) a := begin refine continuous_at_right_of_mono_incr_on_of_exists_between h_mono hs (λ b hb, _), rcases (mem_nhds_within_Ici_iff_exists_mem_Ioc_Ico_subset hb).1 hfs with ⟨b', ⟨hab', hbb'⟩, hb'⟩, rcases exists_between hab' with ⟨c', hc'⟩, rcases mem_closure_iff.1 (hb' ⟨hc'.1.le, hc'.2⟩) (Ioo (f a) b') is_open_Ioo hc' with ⟨_, hc, ⟨c, hcs, rfl⟩⟩, exact ⟨c, hcs, hc.1, hc.2.trans_le hbb'⟩ end /-- If a function `f` with a densely ordered codomain is monotonically increasing on a right neighborhood of `a` and the image of this neighborhood under `f` is a right neighborhood of `f a`, then `f` is continuous at `a` from the right. -/ lemma continuous_at_right_of_mono_incr_on_of_image_mem_nhds_within [densely_ordered β] {f : α → β} {s : set α} {a : α} (h_mono : ∀ (x ∈ s) (y ∈ s), x ≤ y → f x ≤ f y) (hs : s ∈ 𝓝[Ici a] a) (hfs : f '' s ∈ 𝓝[Ici (f a)] (f a)) : continuous_within_at f (Ici a) a := continuous_at_right_of_mono_incr_on_of_closure_image_mem_nhds_within h_mono hs $ mem_sets_of_superset hfs subset_closure /-- If a function `f` with a densely ordered codomain is strictly monotonically increasing on a right neighborhood of `a` and the closure of the image of this neighborhood under `f` is a right neighborhood of `f a`, then `f` is continuous at `a` from the right. -/ lemma strict_mono_incr_on.continuous_at_right_of_closure_image_mem_nhds_within [densely_ordered β] {f : α → β} {s : set α} {a : α} (h_mono : strict_mono_incr_on f s) (hs : s ∈ 𝓝[Ici a] a) (hfs : closure (f '' s) ∈ 𝓝[Ici (f a)] (f a)) : continuous_within_at f (Ici a) a := continuous_at_right_of_mono_incr_on_of_closure_image_mem_nhds_within (λ x hx y hy, (h_mono.le_iff_le hx hy).2) hs hfs /-- If a function `f` with a densely ordered codomain is strictly monotonically increasing on a right neighborhood of `a` and the image of this neighborhood under `f` is a right neighborhood of `f a`, then `f` is continuous at `a` from the right. -/ lemma strict_mono_incr_on.continuous_at_right_of_image_mem_nhds_within [densely_ordered β] {f : α → β} {s : set α} {a : α} (h_mono : strict_mono_incr_on f s) (hs : s ∈ 𝓝[Ici a] a) (hfs : f '' s ∈ 𝓝[Ici (f a)] (f a)) : continuous_within_at f (Ici a) a := h_mono.continuous_at_right_of_closure_image_mem_nhds_within hs (mem_sets_of_superset hfs subset_closure) /-- If a function `f` is strictly monotonically increasing on a right neighborhood of `a` and the image of this neighborhood under `f` includes `Ioi (f a)`, then `f` is continuous at `a` from the right. -/ lemma strict_mono_incr_on.continuous_at_right_of_surj_on {f : α → β} {s : set α} {a : α} (h_mono : strict_mono_incr_on f s) (hs : s ∈ 𝓝[Ici a] a) (hfs : surj_on f s (Ioi (f a))) : continuous_within_at f (Ici a) a := h_mono.continuous_at_right_of_exists_between hs $ λ b hb, let ⟨c, hcs, hcb⟩ := hfs hb in ⟨c, hcs, hcb.symm ▸ hb, hcb.le⟩ /-- If `f` is a function strictly monotonically increasing on a left neighborhood of `a` and the image of this neighborhood under `f` meets every interval `[b, f a)`, `b < f a`, then `f` is continuous at `a` from the left. The assumption `hfs : ∀ b < f a, ∃ c ∈ s, f c ∈ Ico b (f a)` is required because otherwise the function `f : ℝ → ℝ` given by `f x = if x < 0 then x else x + 1` would be a counter-example at `a = 0`. -/ lemma strict_mono_incr_on.continuous_at_left_of_exists_between {f : α → β} {s : set α} {a : α} (h_mono : strict_mono_incr_on f s) (hs : s ∈ 𝓝[Iic a] a) (hfs : ∀ b < f a, ∃ c ∈ s, f c ∈ Ico b (f a)) : continuous_within_at f (Iic a) a := h_mono.dual.continuous_at_right_of_exists_between hs $ λ b hb, let ⟨c, hcs, hcb, hca⟩ := hfs b hb in ⟨c, hcs, hca, hcb⟩ /-- If `f` is a function monotonically increasing function on a left neighborhood of `a` and the image of this neighborhood under `f` meets every interval `(b, f a)`, `b < f a`, then `f` is continuous at `a` from the left. The assumption `hfs : ∀ b < f a, ∃ c ∈ s, f c ∈ Ioo b (f a)` cannot be replaced by the weaker assumption `hfs : ∀ b < f a, ∃ c ∈ s, f c ∈ Ico b (f a)` we use for strictly monotone functions because otherwise the function `floor : ℝ → ℤ` would be a counter-example at `a = 0`. -/ lemma continuous_at_left_of_mono_incr_on_of_exists_between {f : α → β} {s : set α} {a : α} (h_mono : ∀ (x ∈ s) (y ∈ s), x ≤ y → f x ≤ f y) (hs : s ∈ 𝓝[Iic a] a) (hfs : ∀ b < f a, ∃ c ∈ s, f c ∈ Ioo b (f a)) : continuous_within_at f (Iic a) a := @continuous_at_right_of_mono_incr_on_of_exists_between (order_dual α) (order_dual β) _ _ _ _ _ _ f s a (λ x hx y hy, h_mono y hy x hx) hs $ λ b hb, let ⟨c, hcs, hcb, hca⟩ := hfs b hb in ⟨c, hcs, hca, hcb⟩ /-- If a function `f` with a densely ordered codomain is monotonically increasing on a left neighborhood of `a` and the closure of the image of this neighborhood under `f` is a left neighborhood of `f a`, then `f` is continuous at `a` from the left -/ lemma continuous_at_left_of_mono_incr_on_of_closure_image_mem_nhds_within [densely_ordered β] {f : α → β} {s : set α} {a : α} (h_mono : ∀ (x ∈ s) (y ∈ s), x ≤ y → f x ≤ f y) (hs : s ∈ 𝓝[Iic a] a) (hfs : closure (f '' s) ∈ 𝓝[Iic (f a)] (f a)) : continuous_within_at f (Iic a) a := @continuous_at_right_of_mono_incr_on_of_closure_image_mem_nhds_within (order_dual α) (order_dual β) _ _ _ _ _ _ _ f s a (λ x hx y hy, h_mono y hy x hx) hs hfs /-- If a function `f` with a densely ordered codomain is monotonically increasing on a left neighborhood of `a` and the image of this neighborhood under `f` is a left neighborhood of `f a`, then `f` is continuous at `a` from the left. -/ lemma continuous_at_left_of_mono_incr_on_of_image_mem_nhds_within [densely_ordered β] {f : α → β} {s : set α} {a : α} (h_mono : ∀ (x ∈ s) (y ∈ s), x ≤ y → f x ≤ f y) (hs : s ∈ 𝓝[Iic a] a) (hfs : f '' s ∈ 𝓝[Iic (f a)] (f a)) : continuous_within_at f (Iic a) a := continuous_at_left_of_mono_incr_on_of_closure_image_mem_nhds_within h_mono hs (mem_sets_of_superset hfs subset_closure) /-- If a function `f` with a densely ordered codomain is strictly monotonically increasing on a left neighborhood of `a` and the closure of the image of this neighborhood under `f` is a left neighborhood of `f a`, then `f` is continuous at `a` from the left. -/ lemma strict_mono_incr_on.continuous_at_left_of_closure_image_mem_nhds_within [densely_ordered β] {f : α → β} {s : set α} {a : α} (h_mono : strict_mono_incr_on f s) (hs : s ∈ 𝓝[Iic a] a) (hfs : closure (f '' s) ∈ 𝓝[Iic (f a)] (f a)) : continuous_within_at f (Iic a) a := h_mono.dual.continuous_at_right_of_closure_image_mem_nhds_within hs hfs /-- If a function `f` with a densely ordered codomain is strictly monotonically increasing on a left neighborhood of `a` and the image of this neighborhood under `f` is a left neighborhood of `f a`, then `f` is continuous at `a` from the left. -/ lemma strict_mono_incr_on.continuous_at_left_of_image_mem_nhds_within [densely_ordered β] {f : α → β} {s : set α} {a : α} (h_mono : strict_mono_incr_on f s) (hs : s ∈ 𝓝[Iic a] a) (hfs : f '' s ∈ 𝓝[Iic (f a)] (f a)) : continuous_within_at f (Iic a) a := h_mono.dual.continuous_at_right_of_image_mem_nhds_within hs hfs /-- If a function `f` is strictly monotonically increasing on a left neighborhood of `a` and the image of this neighborhood under `f` includes `Iio (f a)`, then `f` is continuous at `a` from the left. -/ lemma strict_mono_incr_on.continuous_at_left_of_surj_on {f : α → β} {s : set α} {a : α} (h_mono : strict_mono_incr_on f s) (hs : s ∈ 𝓝[Iic a] a) (hfs : surj_on f s (Iio (f a))) : continuous_within_at f (Iic a) a := h_mono.dual.continuous_at_right_of_surj_on hs hfs /-- If a function `f` is strictly monotonically increasing on a neighborhood of `a` and the image of this neighborhood under `f` meets every interval `[b, f a)`, `b < f a`, and every interval `(f a, b]`, `b > f a`, then `f` is continuous at `a`. -/ lemma strict_mono_incr_on.continuous_at_of_exists_between {f : α → β} {s : set α} {a : α} (h_mono : strict_mono_incr_on f s) (hs : s ∈ 𝓝 a) (hfs_l : ∀ b < f a, ∃ c ∈ s, f c ∈ Ico b (f a)) (hfs_r : ∀ b > f a, ∃ c ∈ s, f c ∈ Ioc (f a) b) : continuous_at f a := continuous_at_iff_continuous_left_right.2 ⟨h_mono.continuous_at_left_of_exists_between (mem_nhds_within_of_mem_nhds hs) hfs_l, h_mono.continuous_at_right_of_exists_between (mem_nhds_within_of_mem_nhds hs) hfs_r⟩ /-- If a function `f` with a densely ordered codomain is strictly monotonically increasing on a neighborhood of `a` and the closure of the image of this neighborhood under `f` is a neighborhood of `f a`, then `f` is continuous at `a`. -/ lemma strict_mono_incr_on.continuous_at_of_closure_image_mem_nhds [densely_ordered β] {f : α → β} {s : set α} {a : α} (h_mono : strict_mono_incr_on f s) (hs : s ∈ 𝓝 a) (hfs : closure (f '' s) ∈ 𝓝 (f a)) : continuous_at f a := continuous_at_iff_continuous_left_right.2 ⟨h_mono.continuous_at_left_of_closure_image_mem_nhds_within (mem_nhds_within_of_mem_nhds hs) (mem_nhds_within_of_mem_nhds hfs), h_mono.continuous_at_right_of_closure_image_mem_nhds_within (mem_nhds_within_of_mem_nhds hs) (mem_nhds_within_of_mem_nhds hfs)⟩ /-- If a function `f` with a densely ordered codomain is strictly monotonically increasing on a neighborhood of `a` and the image of this set under `f` is a neighborhood of `f a`, then `f` is continuous at `a`. -/ lemma strict_mono_incr_on.continuous_at_of_image_mem_nhds [densely_ordered β] {f : α → β} {s : set α} {a : α} (h_mono : strict_mono_incr_on f s) (hs : s ∈ 𝓝 a) (hfs : f '' s ∈ 𝓝 (f a)) : continuous_at f a := h_mono.continuous_at_of_closure_image_mem_nhds hs (mem_sets_of_superset hfs subset_closure) /-- If `f` is a function monotonically increasing function on a neighborhood of `a` and the image of this neighborhood under `f` meets every interval `(b, f a)`, `b < f a`, and every interval `(f a, b)`, `b > f a`, then `f` is continuous at `a`. -/ lemma continuous_at_of_mono_incr_on_of_exists_between {f : α → β} {s : set α} {a : α} (h_mono : ∀ (x ∈ s) (y ∈ s), x ≤ y → f x ≤ f y) (hs : s ∈ 𝓝 a) (hfs_l : ∀ b < f a, ∃ c ∈ s, f c ∈ Ioo b (f a)) (hfs_r : ∀ b > f a, ∃ c ∈ s, f c ∈ Ioo (f a) b) : continuous_at f a := continuous_at_iff_continuous_left_right.2 ⟨continuous_at_left_of_mono_incr_on_of_exists_between h_mono (mem_nhds_within_of_mem_nhds hs) hfs_l, continuous_at_right_of_mono_incr_on_of_exists_between h_mono (mem_nhds_within_of_mem_nhds hs) hfs_r⟩ /-- If a function `f` with a densely ordered codomain is monotonically increasing on a neighborhood of `a` and the closure of the image of this neighborhood under `f` is a neighborhood of `f a`, then `f` is continuous at `a`. -/ lemma continuous_at_of_mono_incr_on_of_closure_image_mem_nhds [densely_ordered β] {f : α → β} {s : set α} {a : α} (h_mono : ∀ (x ∈ s) (y ∈ s), x ≤ y → f x ≤ f y) (hs : s ∈ 𝓝 a) (hfs : closure (f '' s) ∈ 𝓝 (f a)) : continuous_at f a := continuous_at_iff_continuous_left_right.2 ⟨continuous_at_left_of_mono_incr_on_of_closure_image_mem_nhds_within h_mono (mem_nhds_within_of_mem_nhds hs) (mem_nhds_within_of_mem_nhds hfs), continuous_at_right_of_mono_incr_on_of_closure_image_mem_nhds_within h_mono (mem_nhds_within_of_mem_nhds hs) (mem_nhds_within_of_mem_nhds hfs)⟩ /-- If a function `f` with a densely ordered codomain is monotonically increasing on a neighborhood of `a` and the image of this neighborhood under `f` is a neighborhood of `f a`, then `f` is continuous at `a`. -/ lemma continuous_at_of_mono_incr_on_of_image_mem_nhds [densely_ordered β] {f : α → β} {s : set α} {a : α} (h_mono : ∀ (x ∈ s) (y ∈ s), x ≤ y → f x ≤ f y) (hs : s ∈ 𝓝 a) (hfs : f '' s ∈ 𝓝 (f a)) : continuous_at f a := continuous_at_of_mono_incr_on_of_closure_image_mem_nhds h_mono hs (mem_sets_of_superset hfs subset_closure) /-- A monotone function with densely ordered codomain and a dense range is continuous. -/ lemma monotone.continuous_of_dense_range [densely_ordered β] {f : α → β} (h_mono : monotone f) (h_dense : dense_range f) : continuous f := continuous_iff_continuous_at.mpr $ λ a, continuous_at_of_mono_incr_on_of_closure_image_mem_nhds (λ x hx y hy hxy, h_mono hxy) univ_mem_sets $ by simp only [image_univ, h_dense.closure_eq, univ_mem_sets] /-- A monotone surjective function with a densely ordered codomain is surjective. -/ lemma monotone.continuous_of_surjective [densely_ordered β] {f : α → β} (h_mono : monotone f) (h_surj : function.surjective f) : continuous f := h_mono.continuous_of_dense_range h_surj.dense_range end linear_order /-! ### Continuity of order isomorphisms In this section we prove that an `order_iso` is continuous, hence it is a `homeomorph`. We prove this for an `order_iso` between to partial orders with order topology. -/ namespace order_iso variables [partial_order α] [partial_order β] [topological_space α] [topological_space β] [order_topology α] [order_topology β] protected lemma continuous (e : α ≃o β) : continuous e := begin rw [‹order_topology β›.topology_eq_generate_intervals], refine continuous_generated_from (λ s hs, _), rcases hs with ⟨a, rfl|rfl⟩, { rw e.preimage_Ioi, apply is_open_lt' }, { rw e.preimage_Iio, apply is_open_gt' } end /-- An order isomorphism between two linear order `order_topology` spaces is a homeomorphism. -/ def to_homeomorph (e : α ≃o β) : α ≃ₜ β := { continuous_to_fun := e.continuous, continuous_inv_fun := e.symm.continuous, .. e } @[simp] lemma coe_to_homeomorph (e : α ≃o β) : ⇑e.to_homeomorph = e := rfl @[simp] lemma coe_to_homeomorph_symm (e : α ≃o β) : ⇑e.to_homeomorph.symm = e.symm := rfl end order_iso
d022733d6273130b796e0c3cb4d6db2e4ccf4be2
83bd63fd58ebbb33f769cbf6d6a67463ba1bc637
/src/day_3/subgroups.lean
4dcf98b1d458d5733d6b1ea0eb0f903f83f37552
[]
no_license
Wornbard/mbl_lean_workshop
6ebdafebac74f1b1148f67a528242a3687af17e1
6b68ce25fdc49043fd5ab409de8e4a2987def22e
refs/heads/main
1,690,205,591,845
1,630,953,271,000
1,630,953,271,000
403,417,180
0
0
null
null
null
null
UTF-8
Lean
false
false
4,429
lean
import day_3.groups /-! ## Subgroups We define the structure `subgroup G`, whose terms are subgroups of `G`. A subgroup of `G` is implemented as a subset of `G` closed under `1`, `*` and `⁻¹`. -/ namespace mbl /-- A subgroup of a group G is a subset containing 1 and closed under multiplication and inverse. -/ structure subgroup (G : Type) [group G] := (carrier : set G) (one_mem' : (1 : G) ∈ carrier) (mul_mem' {x y} : x ∈ carrier → y ∈ carrier → x * y ∈ carrier) (inv_mem' {x} : x ∈ carrier → x⁻¹ ∈ carrier) /- At this point, here's what we have. A term `H` of type `subgroup G`, written `H : subgroup G`, is a *quadruple*. To give a term `H : subgroup G` is to give the following four things: 1) `H.carrier` (a subset of `G`), 2) `H.one_mem'` (a proof that `1 ∈ H.carrier`), 3) `H.mul_mem'` (a proof that `H` is closed under multiplication) 4) `H.inv_mem'` (a proof that `H` is closed under inverses). Note in particular that Lean, being super-pedantic, *distinguishes* between the subgroup `H` and the subset `H.carrier`. One is a subgroup, one is a subset. When we get going we will start by setting up some infrastructure so that this difference will be hard to notice. Note also that if `x` is in the subgroup `H` of `H` then the _type_ of `x` is still `G`, and `x ∈ carrier` is a Proposition. Note also that `x : carrier` doesn't make sense (`carrier` is a term, not a type, rather counterintuitively). -/ namespace subgroup open mbl.group variables {G : Type} [group G] (H J K : subgroup G) /- We don't want to write `H.carrier` to refer to the underlying set everywhere, because we want to be able to identify the subgroup `H` with its underlying subset `H.carrier`. Note that these things are not _equal_, firstly because `H` contains the proof that `H.carrier` is a subgroup, and secondly because these terms have different types! `H` has type `subgroup G` and `H.carrier` has type `set G`. Let's start by sorting this out. -/ -- If `x : G` and `H : subgroup G` then let's define the notation -- `x ∈ H` to mean `x ∈ H.carrier` instance : has_mem G (subgroup G) := ⟨λ m H, m ∈ H.carrier⟩ -- Let's also define a "coercion", a.k.a. an "invisible map" -- from subgroups of `G` to subsets of `G`, sending `H` to `H.carrier`. -- The map is not completely invisible -- it's a little ↑. So -- if you see `↑H` in the future, it means the subset `H.carrier` by definition. instance : has_coe (subgroup G) (set G) := ⟨λ H, H.carrier⟩ /-- `g` is in the underlying subset of `H` iff `g ∈ H`. -/ @[simp] lemma mem_carrier {g : G} : g ∈ H.carrier ↔ g ∈ H := begin -- true by definition refl end /-- `g` is in `H` considered as a subset of `G`, iff `g` is in `H` considered as subgroup of `G`. -/ @[simp] lemma mem_coe {g : G} : g ∈ (↑H : set G) ↔ g ∈ H := begin -- true by definition refl end -- Now let's define theorems without the `'`s in, which use this -- more natural notation /-- A subgroup contains the group's 1. -/ theorem one_mem : (1 : G) ∈ H := begin sorry, end /-- A subgroup is closed under multiplication. -/ theorem mul_mem {x y : G} : x ∈ H → y ∈ H → x * y ∈ H := begin sorry, end /-- A subgroup is closed under inverse -/ theorem inv_mem {x : G} : x ∈ H → x⁻¹ ∈ H := begin sorry, end /- So here are the three theorems which you need to remember about subgroups. Say `H : subgroup G`. Then: `H.one_mem : (1 : G) ∈ H` `H.mul_mem {x y : G} : x ∈ H → y ∈ H → x * y ∈ H` `H.inv_mem {x : G} : x ∈ H → x⁻¹ ∈ H` These now look like the way a mathematician would write things. Now let's start to prove basic theorems about subgroups (or, as a the computer scientists would say, make a basic _interface_ or _API_ for subgroups), using this sensible notation. Here's an example; let's prove `x ∈ H ↔ x⁻¹ ∈ H`. Let's put the more complicated expression on the left hand side of the `↔` though, because then we can make it a `simp` lemma. -/ -- Remember that `xena.group.inv_inv x` is the statement that `x⁻¹⁻¹ = x` @[simp] theorem inv_mem_iff {x : G} : x⁻¹ ∈ H ↔ x ∈ H := begin sorry, end -- We could prove a bunch more theorems here. Let's just do one more. -- Let's show that if x and xy are in H then so is y. theorem mem_of_mem_mul_mem {x y : G} (hx : x ∈ H) (hxy : x * y ∈ H) : y ∈ H := begin sorry, end end subgroup end mbl
d3b9b5c65ca53d4114f5538397e21448656c2550
05f637fa14ac28031cb1ea92086a0f4eb23ff2b1
/tests/lean/elab_bug1.lean
939f5a7ec70fc7b46f89969a2cc513e9ac525fc5
[ "Apache-2.0" ]
permissive
codyroux/lean0.1
1ce92751d664aacff0529e139083304a7bbc8a71
0dc6fb974aa85ed6f305a2f4b10a53a44ee5f0ef
refs/heads/master
1,610,830,535,062
1,402,150,480,000
1,402,150,480,000
19,588,851
2
0
null
null
null
null
UTF-8
Lean
false
false
145
lean
set_option pp::implicit true check let P : Nat → Bool := λ x, x ≠ 0, Q : ∀ x, P (x + 1) := λ x, Nat::succ_nz x in Q
76feed89ebf125fbe0cfb2737493a29c38d9da3b
d406927ab5617694ec9ea7001f101b7c9e3d9702
/src/data/ulift.lean
1c45f97e97983c0a93692a716b9801408822e690
[ "Apache-2.0" ]
permissive
alreadydone/mathlib
dc0be621c6c8208c581f5170a8216c5ba6721927
c982179ec21091d3e102d8a5d9f5fe06c8fafb73
refs/heads/master
1,685,523,275,196
1,670,184,141,000
1,670,184,141,000
287,574,545
0
0
Apache-2.0
1,670,290,714,000
1,597,421,623,000
Lean
UTF-8
Lean
false
false
2,849
lean
/- Copyright (c) 2021 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import logic.equiv.basic /-! # Extra lemmas about `ulift` and `plift` > THIS FILE IS SYNCHRONIZED WITH MATHLIB4. > https://github.com/leanprover-community/mathlib4/pull/703 > Any changes to this file require a corresponding PR to mathlib4. In this file we provide `subsingleton`, `unique`, `decidable_eq`, and `is_empty` instances for `ulift α` and `plift α`. We also prove `ulift.forall`, `ulift.exists`, `plift.forall`, and `plift.exists`. -/ universes u v open function namespace plift variables {α : Sort u} {β : Sort v} instance [subsingleton α] : subsingleton (plift α) := equiv.plift.subsingleton instance [nonempty α] : nonempty (plift α) := equiv.plift.nonempty instance [unique α] : unique (plift α) := equiv.plift.unique instance [decidable_eq α] : decidable_eq (plift α) := equiv.plift.decidable_eq instance [is_empty α] : is_empty (plift α) := equiv.plift.is_empty lemma up_injective : injective (@up α) := equiv.plift.symm.injective lemma up_surjective : surjective (@up α) := equiv.plift.symm.surjective lemma up_bijective : bijective (@up α) := equiv.plift.symm.bijective @[simp] lemma up_inj {x y : α} : up x = up y ↔ x = y := up_injective.eq_iff lemma down_surjective : surjective (@down α) := equiv.plift.surjective lemma down_bijective : bijective (@down α) := equiv.plift.bijective @[simp] lemma «forall» {p : plift α → Prop} : (∀ x, p x) ↔ ∀ x : α, p (plift.up x) := up_surjective.forall @[simp] lemma «exists» {p : plift α → Prop} : (∃ x, p x) ↔ ∃ x : α, p (plift.up x) := up_surjective.exists end plift namespace ulift variables {α : Type u} {β : Type v} instance [subsingleton α] : subsingleton (ulift α) := equiv.ulift.subsingleton instance [nonempty α] : nonempty (ulift α) := equiv.ulift.nonempty instance [unique α] : unique (ulift α) := equiv.ulift.unique instance [decidable_eq α] : decidable_eq (ulift α) := equiv.ulift.decidable_eq instance [is_empty α] : is_empty (ulift α) := equiv.ulift.is_empty lemma up_injective : injective (@up α) := equiv.ulift.symm.injective lemma up_surjective : surjective (@up α) := equiv.ulift.symm.surjective lemma up_bijective : bijective (@up α) := equiv.ulift.symm.bijective @[simp] lemma up_inj {x y : α} : up x = up y ↔ x = y := up_injective.eq_iff lemma down_surjective : surjective (@down α) := equiv.ulift.surjective lemma down_bijective : bijective (@down α) := equiv.ulift.bijective @[simp] lemma «forall» {p : ulift α → Prop} : (∀ x, p x) ↔ ∀ x : α, p (ulift.up x) := up_surjective.forall @[simp] lemma «exists» {p : ulift α → Prop} : (∃ x, p x) ↔ ∃ x : α, p (ulift.up x) := up_surjective.exists end ulift
20f6324517d9476763fa3d1ea76713aca221bc94
9e90bb7eb4d1bde1805f9eb6187c333fdf09588a
/src/stump/setup_measurable.lean
17d523a375cf0b693c877b6907a559463ea7ce69
[ "Apache-2.0" ]
permissive
alexjbest/stump-learnable
6311d0c3a1a1a0e65ce83edcbb3b4b7cecabb851
f8fd812fc646d2ece312ff6ffc2a19848ac76032
refs/heads/master
1,659,486,805,691
1,590,454,024,000
1,590,454,024,000
266,173,720
0
0
Apache-2.0
1,590,169,884,000
1,590,169,883,000
null
UTF-8
Lean
false
false
10,921
lean
/- Copyright © 2019, Oracle and/or its affiliates. All rights reserved. -/ import .setup_definition .setup_properties open set open measure_theory open probability_measure open lattice local attribute [instance] classical.prop_decidable namespace stump variables (μ: probability_measure ℍ) (target: ℍ) lemma is_meas_to_target: is_measurable {a: nnreal | a ≤ target} := begin apply is_closed.is_measurable, have TEST: Icc 0 target = {a: nnreal | a ≤ target}, { unfold Icc, rw ext_iff, intro, simp at *, }, rw ← TEST, apply is_closed_Icc, end @[simp] lemma label_measurable: measurable (label target) := begin dunfold label, apply measurable.prod, apply measurable_id, unfold rle, unfold to_bool, apply measurable.if, apply is_meas_to_target, apply measurable_const, apply measurable_const, end lemma measurable_interval_function: ∀ f: nnreal → nnreal, (∀ x: nnreal, is_measurable (f ⁻¹' Iio x)) → measurable f := begin intros, have FOO:= borel_eq_generate_Iio nnreal, unfold measurable, unfold stump.meas_ℍ, --rw FOO, apply measurable_generate_from, intros, rw mem_set_of_eq at H, cases H, unfold is_measurable, unfold is_measurable at a, unfold stump.meas_ℍ at a, --rw FOO at a, sorry;{rw ← H_h, apply a,} end lemma measurable_lt :let f := λ x: nnreal, μ (Icc 0 x) in ∀ y : nnreal, (∃ θ : nnreal, {x : nnreal | f x < y} = Ico 0 θ) ∨ {x : nnreal | f x < y} = ∅ ∨ (∃ θ : nnreal, {x : nnreal | f x < y} = Icc 0 θ) ∨ {x : nnreal | f x < y} = Ici 0 := begin intros f y, let S := {x : ℍ | f x < y}, have hm : monotone f, from assume a b hab, prob_mono _ (Icc_subset_Icc (by refl) hab), have hm' : ∀ {x y}, f x < f y → x < y, { by_contradiction, push_neg at a, choose x₀ y₀ hxy using a, rcases hxy with ⟨hxy₁,hxy₂⟩, have : f y₀ ≤ f x₀, from hm hxy₂, rw ←not_lt at this, exact this hxy₁, }, by_cases (∃ u, f(u) ≥ y), swap, push_neg at h, have hS : S = Ici 0, { ext z, dsimp [S, Ici], fsplit, assume h₁, by_contra, simp at *, assumption, assume h₁, apply h, }, right, right, right, assumption, let T := {x : ℍ | f x ≥ y}, have Tne : T ≠ ∅, { assume not, choose u hyp using h, have : u ∈ T, by assumption, finish, }, have Tbdbl : bdd_below T, from ⟨ 0 , assume y hy, zero_le _ ⟩, let θ := Inf T, have Sleθ : ∀ x ∈ S, x ≤ θ, { assume s hs, refine le_cInf (ne_empty_iff_nonempty.mp Tne) _, assume b hb, dsimp [T,S] at hb hs, suffices : f s < f b, exact le_of_lt (hm' this), exact lt_of_lt_of_le hs hb, }, by_cases case : (f θ < y), have hS : S = Icc 0 θ, from set.ext (assume x, iff.intro (assume h₁, ⟨ by simp , Sleθ _ h₁⟩) (assume h₂, lt_of_le_of_lt (hm h₂.2) case)), right, right, left, existsi θ, exact hS, have hS : S = Ico 0 θ, { ext x, fsplit, assume h₁, suffices : x ≠ θ, dsimp [Ico], refine ⟨ by simp , lt_of_le_of_ne (Sleθ _ h₁) this ⟩, assume not, have : θ ∉ S, from case, rw not at h₁, exact this h₁, assume h₁, dsimp [S,Ico] at h₁ ⊢, have : x ∉ T, assume not, have : θ ≤ x, from cInf_le Tbdbl not, replace h₁ := h₁.2, rw ←not_le at h₁, exact h₁ this, simp at this, assumption, }, left, existsi θ, exact hS, end lemma measurable_Icc_0_x: measurable (λ x: nnreal, μ (Icc 0 x)) := begin apply measurable_interval_function, intros, unfold set.preimage, unfold Iio, conv { congr, congr, funext, rw mem_set_of_eq, skip, }, have FOO := measurable_lt μ x, cases FOO, cases FOO, rw FOO_h, exact is_measurable_Ico, cases FOO, rw FOO, exact is_measurable.empty, cases FOO, cases FOO, rw FOO_h, apply is_closed.is_measurable, apply is_closed_Icc, rw FOO, have COMPL: (Ici (0: nnreal) = - Iio 0), { unfold Ici, unfold Iio, rw ext_iff, intro, rw mem_set_of_eq, rw compl_set_of, rw mem_set_of_eq, split; intro, simp, simp at a, tidy, }, rw COMPL, apply is_measurable.compl, exact is_measurable_Iio, end noncomputable def error1: nnreal → nnreal := λ h, μ (Icc 0 target) - μ (Icc 0 h) noncomputable def error2: nnreal → nnreal := λ h, μ (Icc 0 h) - μ (Icc 0 target) noncomputable def error_decomposed: nnreal → nnreal := λ h, ite (rle h target) (error1 μ target h) (error2 μ target h) lemma decompose_error: error μ target = error_decomposed μ target := begin funext, unfold error_decomposed, by_cases (rle h target = tt), { dedup, rw h_1, simp, unfold error1, rw error_interval_1, rw ← Icc_diff_Ioc 0 h target, have INCL: Icc 0 h ⊆ Icc 0 target, swap, { have FOO:= @measure_diff nnreal _ μ _ _ INCL _ _ _, unfold_coes, unfold_coes at FOO, rw FOO, rw ← ennreal.coe_eq_coe, rw to_nnreal_sub, exact to_measure_lt_top μ (Icc 0 target), exact to_measure_lt_top μ (Icc 0 h), apply is_closed.is_measurable, apply is_closed_Icc, apply is_closed.is_measurable, apply is_closed_Icc, exact probability_measure.to_measure_lt_top μ (Icc 0 h), }, { have H: h ≤ target, { unfold rle at h_1, tidy, }, unfold Icc, rw subset_def, intros, rw mem_set_of_eq, rw mem_set_of_eq at a, cases a, split, assumption, transitivity h; assumption, }, { tidy, }, repeat { unfold rle at h_1, tidy, }, }, { dedup, simp at h_1, rw h_1, simp, unfold error2, rw error_interval_2, rw ← Icc_diff_Ioc 0 target h, have INCL: Icc 0 target ⊆ Icc 0 h, swap, { have FOO:= @measure_diff nnreal _ μ _ _ INCL _ _ _, unfold_coes, unfold_coes at FOO, rw FOO, rw ← ennreal.coe_eq_coe, rw to_nnreal_sub, exact to_measure_lt_top μ (Icc 0 h), exact to_measure_lt_top μ (Icc 0 target), apply is_closed.is_measurable, apply is_closed_Icc, apply is_closed.is_measurable, apply is_closed_Icc, exact probability_measure.to_measure_lt_top μ (Icc 0 target) }, { have H: target < h, { unfold rle at h_1, tidy, }, unfold Icc, rw subset_def, intros, rw mem_set_of_eq, rw mem_set_of_eq at a, cases a, split, assumption, transitivity target; try {assumption}, exact le_of_lt H, }, { tidy, }, { unfold rle at h_1, simp at h_1, exact le_of_lt h_1, }, { unfold rle at h_1, simp at h_1, exact h_1, }, }, end lemma error_measurable: measurable (error μ target) := begin rw decompose_error, unfold error_decomposed, apply measurable.if, { unfold rle, simp, apply is_meas_to_target, }, { unfold error1, apply measurable.sub_nnreal, { apply measurable_const, }, { apply measurable_Icc_0_x, }, }, { unfold error2, apply measurable.sub_nnreal, { apply measurable_Icc_0_x, }, { apply measurable_const, }, }, end @[simp] lemma is_meas_gamma_1: ∀ ε, is_measurable {h: ℍ | error μ target h > ε} := begin intro, have COMPL: {h: ℍ | error μ target h > ε} = -{h: ℍ | error μ target h ≤ ε}, { rw compl_set_of, simp, }, rw COMPL, apply is_measurable.compl, refine is_measurable_le _ _, apply error_measurable, apply measurable_const, end @[simp] lemma is_meas_gamma_2: ∀ ε, is_measurable {h: ℍ | error μ target h ≤ ε} := begin intros, have COMPL: {h: ℍ | error μ target h ≤ ε} = -{h: ℍ | error μ target h > ε}, { rw compl_set_of, simp, }, rw COMPL, apply is_measurable.compl, apply is_meas_gamma_1, end @[simp] lemma is_meas_one: ∀ θ, θ > 0 → is_measurable {x: ℍ | ∀ p = label target x, (if p.snd then p.fst else 0) < θ} := begin introv T0, convert_to (is_measurable {x: ℍ | (if (label target x).snd then (label target x).fst else 0) < θ}), { rw ext_iff, intro, repeat {rw mem_set_of_eq}, split; intros, apply a, trivial, rw H, assumption, }, unfold label, simp, unfold rle, rw ite_equals_union_interval θ T0 target, apply is_measurable.union, { exact is_measurable_Ico, }, { rw Ioi_complement target, apply is_measurable.compl, apply is_measurable.union, exact is_measurable_Iio, rw ← (Ico_diff_Ioo_eq_singleton (by exact lt_add_one target)), apply is_measurable.diff, exact is_measurable_Ico, exact is_measurable_Ioo, }, end @[simp] lemma is_meas_forall: ∀ θ, θ > 0 → ∀ n, is_measurable {S: vec ℍ n | ∀ (i: dfin (nat.succ n)), ∀ p = label target (kth_projn S i), (if p.snd then p.fst else 0) < θ} := begin intros, convert_to (is_measurable {S: vec ℍ n | ∀ (i: dfin (nat.succ n)), (if (label target (kth_projn S i)).snd then (label target (kth_projn S i)).fst else 0) < θ}), { rw ext_iff, intro, repeat {rw mem_set_of_eq}, split; intros, apply (a_1 i), trivial, rw H, apply (a_1 i), }, have FOO:= is_measurable_simple_vec (λ x, (if (label target x).snd then (label target x).fst else 0) < θ), apply FOO, convert_to (is_measurable {x: ℍ | ∀ p = label target x, (if p.snd then p.fst else 0) < θ}), { rw ext_iff, intro, repeat {rw mem_set_of_eq}, split; intros, rw H, assumption, apply a_1, trivial, }, apply is_meas_one; assumption, end end stump
0d7d5cb56e4046aca9c625aca9e0b06abe634c0f
2caa8cd2737f8e6ea2ec83101247ef95d28a4406
/src/chapter2.lean
3b9d2e22a4d10a7a4829bb104172ebb5c779b314
[]
no_license
ruler501/DescriptiveSetTheory
1a079368bf2b06fbcba6864f31f4d3ff2a89195c
08a91bcd1533a88a28c2fac45d26ff223de2e9e6
refs/heads/master
1,676,123,700,591
1,610,658,976,000
1,610,658,976,000
327,178,014
0
0
null
null
null
null
UTF-8
Lean
false
false
2,754
lean
import set_theory.ordinal import tactic.linarith open set classical universes u variables {α : Type u} {m : ℕ} {n : ℕ} def lift_value (is : fin m) (h : m ≤ n) : fin n := let i := is.val in let hi : i < m := is.property in ⟨i, gt_of_ge_of_gt h hi⟩ -- instance nat_to_subtype : has_coe ℕ Type := ⟨λ (n : ℕ), {m // m < n}⟩ notation A `^` n := n.to_type → A def finite_sequence (α : Type u) (n : ℕ) := fin n → α def infinite_sequence (α : Type*) := ℕ → α notation A `^<ℕ` := Σ(n : ℕ), finite_sequence A n notation A `^ℕ` := infinite_sequence A namespace finite_sequence def length (s : α^<ℕ) : ℕ := s.fst def initial_segment (s : finite_sequence α n) (h : m ≤ n) : finite_sequence α m := λ i, s (lift_value i h) def initial_segment_of (s : finite_sequence α m) (t : finite_sequence α n) : Prop := if h : m ≤ n then s = t.initial_segment h else false def extension_of (t : finite_sequence α n) (s : finite_sequence α m) : Prop := initial_segment_of s t def compatible (s : finite_sequence α m) (t : finite_sequence α n) : Prop := initial_segment_of s t ∨ extension_of s t notation s `⊥` t := ¬(compatible s t) def concat (s : finite_sequence α m) (t : finite_sequence α n) : finite_sequence α (m + n) := λ is, let i := is.val in let hi := is.property in if h : i < m then s ⟨i, h⟩ else have h2 : i - m < n, { simp at h, have h4 := (@nat.sub_lt_right_iff_lt_add i n m h).2, apply h4, rwa nat.add_comm n m, }, t ⟨i - m, h2⟩ theorem initial_segment_of_concat (s : finite_sequence α m) (t : finite_sequence α n) : s.initial_segment_of (s.concat t) := begin unfold initial_segment_of, unfold initial_segment, unfold lift_value, simp, apply funext, intro is, unfold concat, simp, split_ifs, refl, have x := h is.property, exfalso, exact x, end end finite_sequence namespace infinite_sequence def initial_segment (s : α^ℕ) (m : ℕ) : finite_sequence α m := λ is, s is def initial_segment_of (s : finite_sequence α m) (t : α^ℕ) : Prop := s = initial_segment t m def concat (s : finite_sequence α m) (t : α^ℕ) : α^ℕ := λ i, if h : i < m then s ⟨i, h⟩ else t (i - m) theorem initial_segment_of_concat (s : finite_sequence α m) (t : α^ℕ) : initial_segment_of s (concat s t) := begin unfold initial_segment_of, unfold initial_segment, apply funext, intro is, unfold concat, split_ifs, simp, exfalso, exact h is.property, end def concat_sequence : ℕ → ((α^<ℕ)^ℕ) → α | i := λ (sᵢ : (α^<ℕ)^ℕ), let ⟨m, s₀⟩ := sᵢ 0 in if h : i < m then s₀ ⟨i, h⟩ else concat_sequence (i - m) (λ j, sᵢ j + 1) end infinite_sequence
fc9448aebf6da1950017163aa16f12edcca4a3d5
5ae26df177f810c5006841e9c73dc56e01b978d7
/src/data/int/basic.lean
3d3fd48b7f4ab778a032ba41d8f78bb35b202e8f
[ "Apache-2.0" ]
permissive
ChrisHughes24/mathlib
98322577c460bc6b1fe5c21f42ce33ad1c3e5558
a2a867e827c2a6702beb9efc2b9282bd801d5f9a
refs/heads/master
1,583,848,251,477
1,565,164,247,000
1,565,164,247,000
129,409,993
0
1
Apache-2.0
1,565,164,817,000
1,523,628,059,000
Lean
UTF-8
Lean
false
false
50,454
lean
/- Copyright (c) 2016 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad The integers, with addition, multiplication, and subtraction. -/ import data.nat.basic data.list.basic algebra.char_zero algebra.order_functions open nat namespace int instance : inhabited ℤ := ⟨int.zero⟩ @[simp] lemma default_eq_zero : default ℤ = 0 := rfl meta instance : has_to_format ℤ := ⟨λ z, int.rec_on z (λ k, ↑k) (λ k, "-("++↑k++"+1)")⟩ meta instance : has_reflect ℤ := by tactic.mk_has_reflect_instance attribute [simp] int.coe_nat_add int.coe_nat_mul int.coe_nat_zero int.coe_nat_one int.coe_nat_succ @[simp] theorem add_def {a b : ℤ} : int.add a b = a + b := rfl @[simp] theorem mul_def {a b : ℤ} : int.mul a b = a * b := rfl @[simp] theorem coe_nat_mul_neg_succ (m n : ℕ) : (m : ℤ) * -[1+ n] = -(m * succ n) := rfl @[simp] theorem neg_succ_mul_coe_nat (m n : ℕ) : -[1+ m] * n = -(succ m * n) := rfl @[simp] theorem neg_succ_mul_neg_succ (m n : ℕ) : -[1+ m] * -[1+ n] = succ m * succ n := rfl @[simp, elim_cast] theorem coe_nat_le {m n : ℕ} : (↑m : ℤ) ≤ ↑n ↔ m ≤ n := coe_nat_le_coe_nat_iff m n @[simp, elim_cast] theorem coe_nat_lt {m n : ℕ} : (↑m : ℤ) < ↑n ↔ m < n := coe_nat_lt_coe_nat_iff m n @[simp, elim_cast] theorem coe_nat_inj' {m n : ℕ} : (↑m : ℤ) = ↑n ↔ m = n := int.coe_nat_eq_coe_nat_iff m n @[simp] theorem coe_nat_pos {n : ℕ} : (0 : ℤ) < n ↔ 0 < n := by rw [← int.coe_nat_zero, coe_nat_lt] @[simp] theorem coe_nat_eq_zero {n : ℕ} : (n : ℤ) = 0 ↔ n = 0 := by rw [← int.coe_nat_zero, coe_nat_inj'] @[simp] theorem coe_nat_ne_zero {n : ℕ} : (n : ℤ) ≠ 0 ↔ n ≠ 0 := not_congr coe_nat_eq_zero lemma coe_nat_nonneg (n : ℕ) : 0 ≤ (n : ℤ) := coe_nat_le.2 (nat.zero_le _) lemma coe_nat_ne_zero_iff_pos {n : ℕ} : (n : ℤ) ≠ 0 ↔ 0 < n := ⟨λ h, nat.pos_of_ne_zero (coe_nat_ne_zero.1 h), λ h, (ne_of_lt (coe_nat_lt.2 h)).symm⟩ lemma coe_nat_succ_pos (n : ℕ) : 0 < (n.succ : ℤ) := int.coe_nat_pos.2 (succ_pos n) @[simp, elim_cast] theorem coe_nat_abs (n : ℕ) : abs (n : ℤ) = n := abs_of_nonneg (coe_nat_nonneg n) /- succ and pred -/ /-- Immediate successor of an integer: `succ n = n + 1` -/ def succ (a : ℤ) := a + 1 /-- Immediate predecessor of an integer: `pred n = n - 1` -/ def pred (a : ℤ) := a - 1 theorem nat_succ_eq_int_succ (n : ℕ) : (nat.succ n : ℤ) = int.succ n := rfl theorem pred_succ (a : ℤ) : pred (succ a) = a := add_sub_cancel _ _ theorem succ_pred (a : ℤ) : succ (pred a) = a := sub_add_cancel _ _ theorem neg_succ (a : ℤ) : -succ a = pred (-a) := neg_add _ _ theorem succ_neg_succ (a : ℤ) : succ (-succ a) = -a := by rw [neg_succ, succ_pred] theorem neg_pred (a : ℤ) : -pred a = succ (-a) := by rw [eq_neg_of_eq_neg (neg_succ (-a)).symm, neg_neg] theorem pred_neg_pred (a : ℤ) : pred (-pred a) = -a := by rw [neg_pred, pred_succ] theorem pred_nat_succ (n : ℕ) : pred (nat.succ n) = n := pred_succ n theorem neg_nat_succ (n : ℕ) : -(nat.succ n : ℤ) = pred (-n) := neg_succ n theorem succ_neg_nat_succ (n : ℕ) : succ (-nat.succ n) = -n := succ_neg_succ n theorem lt_succ_self (a : ℤ) : a < succ a := lt_add_of_pos_right _ zero_lt_one theorem pred_self_lt (a : ℤ) : pred a < a := sub_lt_self _ zero_lt_one theorem add_one_le_iff {a b : ℤ} : a + 1 ≤ b ↔ a < b := iff.rfl theorem lt_add_one_iff {a b : ℤ} : a < b + 1 ↔ a ≤ b := @add_le_add_iff_right _ _ a b 1 theorem sub_one_lt_iff {a b : ℤ} : a - 1 < b ↔ a ≤ b := sub_lt_iff_lt_add.trans lt_add_one_iff theorem le_sub_one_iff {a b : ℤ} : a ≤ b - 1 ↔ a < b := le_sub_iff_add_le @[elab_as_eliminator] protected lemma induction_on {p : ℤ → Prop} (i : ℤ) (hz : p 0) (hp : ∀i : ℕ, p i → p (i + 1)) (hn : ∀i : ℕ, p (-i) → p (-i - 1)) : p i := begin induction i, { induction i, { exact hz }, { exact hp _ i_ih } }, { have : ∀n:ℕ, p (- n), { intro n, induction n, { simp [hz] }, { have := hn _ n_ih, simpa } }, exact this (i + 1) } end protected def induction_on' {C : ℤ → Sort*} (z : ℤ) (b : ℤ) : C b → (∀ k ≥ b, C k → C (k + 1)) → (∀ k ≤ b, C k → C (k - 1)) → C z := λ H0 Hs Hp, begin rw ←sub_add_cancel z b, induction (z - b), { induction a with n ih, { rwa [of_nat_zero, zero_add] }, rw [of_nat_succ, add_assoc, add_comm 1 b, ←add_assoc], exact Hs _ (le_add_of_nonneg_left (of_nat_nonneg _)) ih }, { induction a with n ih, { rw [neg_succ_of_nat_eq, ←of_nat_eq_coe, of_nat_zero, zero_add, neg_add_eq_sub], exact Hp _ (le_refl _) H0 }, { rw [neg_succ_of_nat_coe', nat.succ_eq_add_one, ←neg_succ_of_nat_coe, sub_add_eq_add_sub], exact Hp _ (le_of_lt (add_lt_of_neg_of_le (neg_succ_lt_zero _) (le_refl _))) ih } } end /- nat abs -/ attribute [simp] nat_abs nat_abs_of_nat nat_abs_zero nat_abs_one theorem nat_abs_add_le (a b : ℤ) : nat_abs (a + b) ≤ nat_abs a + nat_abs b := begin have : ∀ (a b : ℕ), nat_abs (sub_nat_nat a (nat.succ b)) ≤ nat.succ (a + b), { refine (λ a b : ℕ, sub_nat_nat_elim a b.succ (λ m n i, n = b.succ → nat_abs i ≤ (m + b).succ) _ _ rfl); intros i n e, { subst e, rw [add_comm _ i, add_assoc], exact nat.le_add_right i (b.succ + b).succ }, { apply succ_le_succ, rw [← succ_inj e, ← add_assoc, add_comm], apply nat.le_add_right } }, cases a; cases b with b b; simp [nat_abs, nat.succ_add]; try {refl}; [skip, rw add_comm a b]; apply this end theorem nat_abs_neg_of_nat (n : ℕ) : nat_abs (neg_of_nat n) = n := by cases n; refl theorem nat_abs_mul (a b : ℤ) : nat_abs (a * b) = (nat_abs a) * (nat_abs b) := by cases a; cases b; simp only [(*), int.mul, nat_abs_neg_of_nat, eq_self_iff_true, int.nat_abs] @[simp] lemma nat_abs_mul_self' (a : ℤ) : (nat_abs a * nat_abs a : ℤ) = a * a := by rw [← int.coe_nat_mul, nat_abs_mul_self] theorem neg_succ_of_nat_eq' (m : ℕ) : -[1+ m] = -m - 1 := by simp [neg_succ_of_nat_eq] lemma nat_abs_ne_zero_of_ne_zero {z : ℤ} (hz : z ≠ 0) : z.nat_abs ≠ 0 := λ h, hz $ int.eq_zero_of_nat_abs_eq_zero h /- / -/ @[simp] theorem of_nat_div (m n : ℕ) : of_nat (m / n) = (of_nat m) / (of_nat n) := rfl @[simp, move_cast] theorem coe_nat_div (m n : ℕ) : ((m / n : ℕ) : ℤ) = m / n := rfl theorem neg_succ_of_nat_div (m : ℕ) {b : ℤ} (H : b > 0) : -[1+m] / b = -(m / b + 1) := match b, eq_succ_of_zero_lt H with ._, ⟨n, rfl⟩ := rfl end @[simp] protected theorem div_neg : ∀ (a b : ℤ), a / -b = -(a / b) | (m : ℕ) 0 := show of_nat (m / 0) = -(m / 0 : ℕ), by rw nat.div_zero; refl | (m : ℕ) (n+1:ℕ) := rfl | 0 -[1+ n] := rfl | (m+1:ℕ) -[1+ n] := (neg_neg _).symm | -[1+ m] 0 := rfl | -[1+ m] (n+1:ℕ) := rfl | -[1+ m] -[1+ n] := rfl theorem div_of_neg_of_pos {a b : ℤ} (Ha : a < 0) (Hb : b > 0) : a / b = -((-a - 1) / b + 1) := match a, b, eq_neg_succ_of_lt_zero Ha, eq_succ_of_zero_lt Hb with | ._, ._, ⟨m, rfl⟩, ⟨n, rfl⟩ := by change (- -[1+ m] : ℤ) with (m+1 : ℤ); rw add_sub_cancel; refl end protected theorem div_nonneg {a b : ℤ} (Ha : a ≥ 0) (Hb : b ≥ 0) : a / b ≥ 0 := match a, b, eq_coe_of_zero_le Ha, eq_coe_of_zero_le Hb with | ._, ._, ⟨m, rfl⟩, ⟨n, rfl⟩ := coe_zero_le _ end protected theorem div_nonpos {a b : ℤ} (Ha : a ≥ 0) (Hb : b ≤ 0) : a / b ≤ 0 := nonpos_of_neg_nonneg $ by rw [← int.div_neg]; exact int.div_nonneg Ha (neg_nonneg_of_nonpos Hb) theorem div_neg' {a b : ℤ} (Ha : a < 0) (Hb : b > 0) : a / b < 0 := match a, b, eq_neg_succ_of_lt_zero Ha, eq_succ_of_zero_lt Hb with | ._, ._, ⟨m, rfl⟩, ⟨n, rfl⟩ := neg_succ_lt_zero _ end @[simp] protected theorem zero_div : ∀ (b : ℤ), 0 / b = 0 | 0 := rfl | (n+1:ℕ) := rfl | -[1+ n] := rfl @[simp] protected theorem div_zero : ∀ (a : ℤ), a / 0 = 0 | 0 := rfl | (n+1:ℕ) := rfl | -[1+ n] := rfl @[simp] protected theorem div_one : ∀ (a : ℤ), a / 1 = a | 0 := rfl | (n+1:ℕ) := congr_arg of_nat (nat.div_one _) | -[1+ n] := congr_arg neg_succ_of_nat (nat.div_one _) theorem div_eq_zero_of_lt {a b : ℤ} (H1 : 0 ≤ a) (H2 : a < b) : a / b = 0 := match a, b, eq_coe_of_zero_le H1, eq_succ_of_zero_lt (lt_of_le_of_lt H1 H2), H2 with | ._, ._, ⟨m, rfl⟩, ⟨n, rfl⟩, H2 := congr_arg of_nat $ nat.div_eq_of_lt $ lt_of_coe_nat_lt_coe_nat H2 end theorem div_eq_zero_of_lt_abs {a b : ℤ} (H1 : 0 ≤ a) (H2 : a < abs b) : a / b = 0 := match b, abs b, abs_eq_nat_abs b, H2 with | (n : ℕ), ._, rfl, H2 := div_eq_zero_of_lt H1 H2 | -[1+ n], ._, rfl, H2 := neg_inj $ by rw [← int.div_neg]; exact div_eq_zero_of_lt H1 H2 end protected theorem add_mul_div_right (a b : ℤ) {c : ℤ} (H : c ≠ 0) : (a + b * c) / c = a / c + b := have ∀ {k n : ℕ} {a : ℤ}, (a + n * k.succ) / k.succ = a / k.succ + n, from λ k n a, match a with | (m : ℕ) := congr_arg of_nat $ nat.add_mul_div_right _ _ k.succ_pos | -[1+ m] := show ((n * k.succ:ℕ) - m.succ : ℤ) / k.succ = n - (m / k.succ + 1 : ℕ), begin cases lt_or_ge m (n*k.succ) with h h, { rw [← int.coe_nat_sub h, ← int.coe_nat_sub ((nat.div_lt_iff_lt_mul _ _ k.succ_pos).2 h)], apply congr_arg of_nat, rw [mul_comm, nat.mul_sub_div], rwa mul_comm }, { change (↑(n * nat.succ k) - (m + 1) : ℤ) / ↑(nat.succ k) = ↑n - ((m / nat.succ k : ℕ) + 1), rw [← sub_sub, ← sub_sub, ← neg_sub (m:ℤ), ← neg_sub _ (n:ℤ), ← int.coe_nat_sub h, ← int.coe_nat_sub ((nat.le_div_iff_mul_le _ _ k.succ_pos).2 h), ← neg_succ_of_nat_coe', ← neg_succ_of_nat_coe'], { apply congr_arg neg_succ_of_nat, rw [mul_comm, nat.sub_mul_div], rwa mul_comm } } end end, have ∀ {a b c : ℤ}, c > 0 → (a + b * c) / c = a / c + b, from λ a b c H, match c, eq_succ_of_zero_lt H, b with | ._, ⟨k, rfl⟩, (n : ℕ) := this | ._, ⟨k, rfl⟩, -[1+ n] := show (a - n.succ * k.succ) / k.succ = (a / k.succ) - n.succ, from eq_sub_of_add_eq $ by rw [← this, sub_add_cancel] end, match lt_trichotomy c 0 with | or.inl hlt := neg_inj $ by rw [← int.div_neg, neg_add, ← int.div_neg, ← neg_mul_neg]; apply this (neg_pos_of_neg hlt) | or.inr (or.inl heq) := absurd heq H | or.inr (or.inr hgt) := this hgt end protected theorem add_mul_div_left (a : ℤ) {b : ℤ} (c : ℤ) (H : b ≠ 0) : (a + b * c) / b = a / b + c := by rw [mul_comm, int.add_mul_div_right _ _ H] @[simp] protected theorem mul_div_cancel (a : ℤ) {b : ℤ} (H : b ≠ 0) : a * b / b = a := by have := int.add_mul_div_right 0 a H; rwa [zero_add, int.zero_div, zero_add] at this @[simp] protected theorem mul_div_cancel_left {a : ℤ} (b : ℤ) (H : a ≠ 0) : a * b / a = b := by rw [mul_comm, int.mul_div_cancel _ H] @[simp] protected theorem div_self {a : ℤ} (H : a ≠ 0) : a / a = 1 := by have := int.mul_div_cancel 1 H; rwa one_mul at this /- mod -/ theorem of_nat_mod (m n : nat) : (m % n : ℤ) = of_nat (m % n) := rfl @[simp] theorem coe_nat_mod (m n : ℕ) : (↑(m % n) : ℤ) = ↑m % ↑n := rfl theorem neg_succ_of_nat_mod (m : ℕ) {b : ℤ} (bpos : b > 0) : -[1+m] % b = b - 1 - m % b := by rw [sub_sub, add_comm]; exact match b, eq_succ_of_zero_lt bpos with ._, ⟨n, rfl⟩ := rfl end @[simp] theorem mod_neg : ∀ (a b : ℤ), a % -b = a % b | (m : ℕ) n := @congr_arg ℕ ℤ _ _ (λ i, ↑(m % i)) (nat_abs_neg _) | -[1+ m] n := @congr_arg ℕ ℤ _ _ (λ i, sub_nat_nat i (nat.succ (m % i))) (nat_abs_neg _) @[simp] theorem mod_abs (a b : ℤ) : a % (abs b) = a % b := abs_by_cases (λ i, a % i = a % b) rfl (mod_neg _ _) @[simp] theorem zero_mod (b : ℤ) : 0 % b = 0 := congr_arg of_nat $ nat.zero_mod _ @[simp] theorem mod_zero : ∀ (a : ℤ), a % 0 = a | (m : ℕ) := congr_arg of_nat $ nat.mod_zero _ | -[1+ m] := congr_arg neg_succ_of_nat $ nat.mod_zero _ @[simp] theorem mod_one : ∀ (a : ℤ), a % 1 = 0 | (m : ℕ) := congr_arg of_nat $ nat.mod_one _ | -[1+ m] := show (1 - (m % 1).succ : ℤ) = 0, by rw nat.mod_one; refl theorem mod_eq_of_lt {a b : ℤ} (H1 : 0 ≤ a) (H2 : a < b) : a % b = a := match a, b, eq_coe_of_zero_le H1, eq_coe_of_zero_le (le_trans H1 (le_of_lt H2)), H2 with | ._, ._, ⟨m, rfl⟩, ⟨n, rfl⟩, H2 := congr_arg of_nat $ nat.mod_eq_of_lt (lt_of_coe_nat_lt_coe_nat H2) end theorem mod_nonneg : ∀ (a : ℤ) {b : ℤ}, b ≠ 0 → a % b ≥ 0 | (m : ℕ) n H := coe_zero_le _ | -[1+ m] n H := sub_nonneg_of_le $ coe_nat_le_coe_nat_of_le $ nat.mod_lt _ (nat_abs_pos_of_ne_zero H) theorem mod_lt_of_pos (a : ℤ) {b : ℤ} (H : b > 0) : a % b < b := match a, b, eq_succ_of_zero_lt H with | (m : ℕ), ._, ⟨n, rfl⟩ := coe_nat_lt_coe_nat_of_lt (nat.mod_lt _ (nat.succ_pos _)) | -[1+ m], ._, ⟨n, rfl⟩ := sub_lt_self _ (coe_nat_lt_coe_nat_of_lt $ nat.succ_pos _) end theorem mod_lt (a : ℤ) {b : ℤ} (H : b ≠ 0) : a % b < abs b := by rw [← mod_abs]; exact mod_lt_of_pos _ (abs_pos_of_ne_zero H) theorem mod_add_div_aux (m n : ℕ) : (n - (m % n + 1) - (n * (m / n) + n) : ℤ) = -[1+ m] := begin rw [← sub_sub, neg_succ_of_nat_coe, sub_sub (n:ℤ)], apply eq_neg_of_eq_neg, rw [neg_sub, sub_sub_self, add_right_comm], exact @congr_arg ℕ ℤ _ _ (λi, (i + 1 : ℤ)) (nat.mod_add_div _ _).symm end theorem mod_add_div : ∀ (a b : ℤ), a % b + b * (a / b) = a | (m : ℕ) 0 := congr_arg of_nat (nat.mod_add_div _ _) | (m : ℕ) (n+1:ℕ) := congr_arg of_nat (nat.mod_add_div _ _) | 0 -[1+ n] := rfl | (m+1:ℕ) -[1+ n] := show (_ + -(n+1) * -((m + 1) / (n + 1) : ℕ) : ℤ) = _, by rw [neg_mul_neg]; exact congr_arg of_nat (nat.mod_add_div _ _) | -[1+ m] 0 := by rw [mod_zero, int.div_zero]; refl | -[1+ m] (n+1:ℕ) := mod_add_div_aux m n.succ | -[1+ m] -[1+ n] := mod_add_div_aux m n.succ theorem mod_def (a b : ℤ) : a % b = a - b * (a / b) := eq_sub_of_add_eq (mod_add_div _ _) @[simp] theorem add_mul_mod_self {a b c : ℤ} : (a + b * c) % c = a % c := if cz : c = 0 then by rw [cz, mul_zero, add_zero] else by rw [mod_def, mod_def, int.add_mul_div_right _ _ cz, mul_add, mul_comm, add_sub_add_right_eq_sub] @[simp] theorem add_mul_mod_self_left (a b c : ℤ) : (a + b * c) % b = a % b := by rw [mul_comm, add_mul_mod_self] @[simp] theorem add_mod_self {a b : ℤ} : (a + b) % b = a % b := by have := add_mul_mod_self_left a b 1; rwa mul_one at this @[simp] theorem add_mod_self_left {a b : ℤ} : (a + b) % a = b % a := by rw [add_comm, add_mod_self] @[simp] theorem mod_add_mod (m n k : ℤ) : (m % n + k) % n = (m + k) % n := by have := (add_mul_mod_self_left (m % n + k) n (m / n)).symm; rwa [add_right_comm, mod_add_div] at this @[simp] theorem add_mod_mod (m n k : ℤ) : (m + n % k) % k = (m + n) % k := by rw [add_comm, mod_add_mod, add_comm] theorem add_mod_eq_add_mod_right {m n k : ℤ} (i : ℤ) (H : m % n = k % n) : (m + i) % n = (k + i) % n := by rw [← mod_add_mod, ← mod_add_mod k, H] theorem add_mod_eq_add_mod_left {m n k : ℤ} (i : ℤ) (H : m % n = k % n) : (i + m) % n = (i + k) % n := by rw [add_comm, add_mod_eq_add_mod_right _ H, add_comm] theorem mod_add_cancel_right {m n k : ℤ} (i) : (m + i) % n = (k + i) % n ↔ m % n = k % n := ⟨λ H, by have := add_mod_eq_add_mod_right (-i) H; rwa [add_neg_cancel_right, add_neg_cancel_right] at this, add_mod_eq_add_mod_right _⟩ theorem mod_add_cancel_left {m n k i : ℤ} : (i + m) % n = (i + k) % n ↔ m % n = k % n := by rw [add_comm, add_comm i, mod_add_cancel_right] theorem mod_sub_cancel_right {m n k : ℤ} (i) : (m - i) % n = (k - i) % n ↔ m % n = k % n := mod_add_cancel_right _ theorem mod_eq_mod_iff_mod_sub_eq_zero {m n k : ℤ} : m % n = k % n ↔ (m - k) % n = 0 := (mod_sub_cancel_right k).symm.trans $ by simp @[simp] theorem mul_mod_left (a b : ℤ) : (a * b) % b = 0 := by rw [← zero_add (a * b), add_mul_mod_self, zero_mod] @[simp] theorem mul_mod_right (a b : ℤ) : (a * b) % a = 0 := by rw [mul_comm, mul_mod_left] @[simp] theorem mod_self {a : ℤ} : a % a = 0 := by have := mul_mod_left 1 a; rwa one_mul at this @[simp] theorem mod_mod (a b : ℤ) : a % b % b = a % b := by conv {to_rhs, rw [← mod_add_div a b, add_mul_mod_self_left]} @[simp] theorem mod_mod_of_dvd (n : int) {m k : int} (h : m ∣ k) : n % k % m = n % m := begin conv { to_rhs, rw ←mod_add_div n k }, rcases h with ⟨t, rfl⟩, rw [mul_assoc, add_mul_mod_self_left] end /- properties of / and % -/ @[simp] theorem mul_div_mul_of_pos {a : ℤ} (b c : ℤ) (H : a > 0) : a * b / (a * c) = b / c := suffices ∀ (m k : ℕ) (b : ℤ), (m.succ * b / (m.succ * k) : ℤ) = b / k, from match a, eq_succ_of_zero_lt H, c, eq_coe_or_neg c with | ._, ⟨m, rfl⟩, ._, ⟨k, or.inl rfl⟩ := this _ _ _ | ._, ⟨m, rfl⟩, ._, ⟨k, or.inr rfl⟩ := by rw [← neg_mul_eq_mul_neg, int.div_neg, int.div_neg]; apply congr_arg has_neg.neg; apply this end, λ m k b, match b, k with | (n : ℕ), k := congr_arg of_nat (nat.mul_div_mul _ _ m.succ_pos) | -[1+ n], 0 := by rw [int.coe_nat_zero, mul_zero, int.div_zero, int.div_zero] | -[1+ n], k+1 := congr_arg neg_succ_of_nat $ show (m.succ * n + m) / (m.succ * k.succ) = n / k.succ, begin apply nat.div_eq_of_lt_le, { refine le_trans _ (nat.le_add_right _ _), rw [← nat.mul_div_mul _ _ m.succ_pos], apply nat.div_mul_le_self }, { change m.succ * n.succ ≤ _, rw [mul_left_comm], apply nat.mul_le_mul_left, apply (nat.div_lt_iff_lt_mul _ _ k.succ_pos).1, apply nat.lt_succ_self } end end @[simp] theorem mul_div_mul_of_pos_left (a : ℤ) {b : ℤ} (c : ℤ) (H : b > 0) : a * b / (c * b) = a / c := by rw [mul_comm, mul_comm c, mul_div_mul_of_pos _ _ H] @[simp] theorem mul_mod_mul_of_pos {a : ℤ} (b c : ℤ) (H : a > 0) : a * b % (a * c) = a * (b % c) := by rw [mod_def, mod_def, mul_div_mul_of_pos _ _ H, mul_sub_left_distrib, mul_assoc] theorem lt_div_add_one_mul_self (a : ℤ) {b : ℤ} (H : b > 0) : a < (a / b + 1) * b := by rw [add_mul, one_mul, mul_comm]; apply lt_add_of_sub_left_lt; rw [← mod_def]; apply mod_lt_of_pos _ H theorem abs_div_le_abs : ∀ (a b : ℤ), abs (a / b) ≤ abs a := suffices ∀ (a : ℤ) (n : ℕ), abs (a / n) ≤ abs a, from λ a b, match b, eq_coe_or_neg b with | ._, ⟨n, or.inl rfl⟩ := this _ _ | ._, ⟨n, or.inr rfl⟩ := by rw [int.div_neg, abs_neg]; apply this end, λ a n, by rw [abs_eq_nat_abs, abs_eq_nat_abs]; exact coe_nat_le_coe_nat_of_le (match a, n with | (m : ℕ), n := nat.div_le_self _ _ | -[1+ m], 0 := nat.zero_le _ | -[1+ m], n+1 := nat.succ_le_succ (nat.div_le_self _ _) end) theorem div_le_self {a : ℤ} (b : ℤ) (Ha : a ≥ 0) : a / b ≤ a := by have := le_trans (le_abs_self _) (abs_div_le_abs a b); rwa [abs_of_nonneg Ha] at this theorem mul_div_cancel_of_mod_eq_zero {a b : ℤ} (H : a % b = 0) : b * (a / b) = a := by have := mod_add_div a b; rwa [H, zero_add] at this theorem div_mul_cancel_of_mod_eq_zero {a b : ℤ} (H : a % b = 0) : a / b * b = a := by rw [mul_comm, mul_div_cancel_of_mod_eq_zero H] lemma mod_two_eq_zero_or_one (n : ℤ) : n % 2 = 0 ∨ n % 2 = 1 := have h : n % 2 < 2 := abs_of_nonneg (show (2 : ℤ) ≥ 0, from dec_trivial) ▸ int.mod_lt _ dec_trivial, have h₁ : n % 2 ≥ 0 := int.mod_nonneg _ dec_trivial, match (n % 2), h, h₁ with | (0 : ℕ) := λ _ _, or.inl rfl | (1 : ℕ) := λ _ _, or.inr rfl | (k + 2 : ℕ) := λ h _, absurd h dec_trivial | -[1+ a] := λ _ h₁, absurd h₁ dec_trivial end /- dvd -/ @[elim_cast] theorem coe_nat_dvd {m n : ℕ} : (↑m : ℤ) ∣ ↑n ↔ m ∣ n := ⟨λ ⟨a, ae⟩, m.eq_zero_or_pos.elim (λm0, by simp [m0] at ae; simp [ae, m0]) (λm0l, by { cases eq_coe_of_zero_le (@nonneg_of_mul_nonneg_left ℤ _ m a (by simp [ae.symm]) (by simpa using m0l)) with k e, subst a, exact ⟨k, int.coe_nat_inj ae⟩ }), λ ⟨k, e⟩, dvd.intro k $ by rw [e, int.coe_nat_mul]⟩ theorem coe_nat_dvd_left {n : ℕ} {z : ℤ} : (↑n : ℤ) ∣ z ↔ n ∣ z.nat_abs := by rcases nat_abs_eq z with eq | eq; rw eq; simp [coe_nat_dvd] theorem coe_nat_dvd_right {n : ℕ} {z : ℤ} : z ∣ (↑n : ℤ) ↔ z.nat_abs ∣ n := by rcases nat_abs_eq z with eq | eq; rw eq; simp [coe_nat_dvd] theorem dvd_antisymm {a b : ℤ} (H1 : a ≥ 0) (H2 : b ≥ 0) : a ∣ b → b ∣ a → a = b := begin rw [← abs_of_nonneg H1, ← abs_of_nonneg H2, abs_eq_nat_abs, abs_eq_nat_abs], rw [coe_nat_dvd, coe_nat_dvd, coe_nat_inj'], apply nat.dvd_antisymm end theorem dvd_of_mod_eq_zero {a b : ℤ} (H : b % a = 0) : a ∣ b := ⟨b / a, (mul_div_cancel_of_mod_eq_zero H).symm⟩ theorem mod_eq_zero_of_dvd : ∀ {a b : ℤ}, a ∣ b → b % a = 0 | a ._ ⟨c, rfl⟩ := mul_mod_right _ _ theorem dvd_iff_mod_eq_zero (a b : ℤ) : a ∣ b ↔ b % a = 0 := ⟨mod_eq_zero_of_dvd, dvd_of_mod_eq_zero⟩ theorem nat_abs_dvd {a b : ℤ} : (a.nat_abs : ℤ) ∣ b ↔ a ∣ b := (nat_abs_eq a).elim (λ e, by rw ← e) (λ e, by rw [← neg_dvd_iff_dvd, ← e]) theorem dvd_nat_abs {a b : ℤ} : a ∣ b.nat_abs ↔ a ∣ b := (nat_abs_eq b).elim (λ e, by rw ← e) (λ e, by rw [← dvd_neg_iff_dvd, ← e]) instance decidable_dvd : @decidable_rel ℤ (∣) := assume a n, decidable_of_decidable_of_iff (by apply_instance) (dvd_iff_mod_eq_zero _ _).symm protected theorem div_mul_cancel {a b : ℤ} (H : b ∣ a) : a / b * b = a := div_mul_cancel_of_mod_eq_zero (mod_eq_zero_of_dvd H) protected theorem mul_div_cancel' {a b : ℤ} (H : a ∣ b) : a * (b / a) = b := by rw [mul_comm, int.div_mul_cancel H] protected theorem mul_div_assoc (a : ℤ) : ∀ {b c : ℤ}, c ∣ b → (a * b) / c = a * (b / c) | ._ c ⟨d, rfl⟩ := if cz : c = 0 then by simp [cz] else by rw [mul_left_comm, int.mul_div_cancel_left _ cz, int.mul_div_cancel_left _ cz] theorem div_dvd_div : ∀ {a b c : ℤ} (H1 : a ∣ b) (H2 : b ∣ c), b / a ∣ c / a | a ._ ._ ⟨b, rfl⟩ ⟨c, rfl⟩ := if az : a = 0 then by simp [az] else by rw [int.mul_div_cancel_left _ az, mul_assoc, int.mul_div_cancel_left _ az]; apply dvd_mul_right protected theorem eq_mul_of_div_eq_right {a b c : ℤ} (H1 : b ∣ a) (H2 : a / b = c) : a = b * c := by rw [← H2, int.mul_div_cancel' H1] protected theorem div_eq_of_eq_mul_right {a b c : ℤ} (H1 : b ≠ 0) (H2 : a = b * c) : a / b = c := by rw [H2, int.mul_div_cancel_left _ H1] protected theorem div_eq_iff_eq_mul_right {a b c : ℤ} (H : b ≠ 0) (H' : b ∣ a) : a / b = c ↔ a = b * c := ⟨int.eq_mul_of_div_eq_right H', int.div_eq_of_eq_mul_right H⟩ protected theorem div_eq_iff_eq_mul_left {a b c : ℤ} (H : b ≠ 0) (H' : b ∣ a) : a / b = c ↔ a = c * b := by rw mul_comm; exact int.div_eq_iff_eq_mul_right H H' protected theorem eq_mul_of_div_eq_left {a b c : ℤ} (H1 : b ∣ a) (H2 : a / b = c) : a = c * b := by rw [mul_comm, int.eq_mul_of_div_eq_right H1 H2] protected theorem div_eq_of_eq_mul_left {a b c : ℤ} (H1 : b ≠ 0) (H2 : a = c * b) : a / b = c := int.div_eq_of_eq_mul_right H1 (by rw [mul_comm, H2]) theorem neg_div_of_dvd : ∀ {a b : ℤ} (H : b ∣ a), -a / b = -(a / b) | ._ b ⟨c, rfl⟩ := if bz : b = 0 then by simp [bz] else by rw [neg_mul_eq_mul_neg, int.mul_div_cancel_left _ bz, int.mul_div_cancel_left _ bz] lemma add_div_of_dvd {a b c : ℤ} : c ∣ a → c ∣ b → (a + b) / c = a / c + b / c := begin intros h1 h2, by_cases h3 : c = 0, { rw [h3, zero_dvd_iff] at *, rw [h1, h2, h3], refl }, { apply eq_of_mul_eq_mul_right h3, rw add_mul, repeat {rw [int.div_mul_cancel]}; try {apply dvd_add}; assumption } end theorem div_sign : ∀ a b, a / sign b = a * sign b | a (n+1:ℕ) := by unfold sign; simp | a 0 := by simp [sign] | a -[1+ n] := by simp [sign] @[simp] theorem sign_mul : ∀ a b, sign (a * b) = sign a * sign b | a 0 := by simp | 0 b := by simp | (m+1:ℕ) (n+1:ℕ) := rfl | (m+1:ℕ) -[1+ n] := rfl | -[1+ m] (n+1:ℕ) := rfl | -[1+ m] -[1+ n] := rfl protected theorem sign_eq_div_abs (a : ℤ) : sign a = a / (abs a) := if az : a = 0 then by simp [az] else (int.div_eq_of_eq_mul_left (mt eq_zero_of_abs_eq_zero az) (sign_mul_abs _).symm).symm theorem mul_sign : ∀ (i : ℤ), i * sign i = nat_abs i | (n+1:ℕ) := mul_one _ | 0 := mul_zero _ | -[1+ n] := mul_neg_one _ theorem le_of_dvd {a b : ℤ} (bpos : b > 0) (H : a ∣ b) : a ≤ b := match a, b, eq_succ_of_zero_lt bpos, H with | (m : ℕ), ._, ⟨n, rfl⟩, H := coe_nat_le_coe_nat_of_le $ nat.le_of_dvd n.succ_pos $ coe_nat_dvd.1 H | -[1+ m], ._, ⟨n, rfl⟩, _ := le_trans (le_of_lt $ neg_succ_lt_zero _) (coe_zero_le _) end theorem eq_one_of_dvd_one {a : ℤ} (H : a ≥ 0) (H' : a ∣ 1) : a = 1 := match a, eq_coe_of_zero_le H, H' with | ._, ⟨n, rfl⟩, H' := congr_arg coe $ nat.eq_one_of_dvd_one $ coe_nat_dvd.1 H' end theorem eq_one_of_mul_eq_one_right {a b : ℤ} (H : a ≥ 0) (H' : a * b = 1) : a = 1 := eq_one_of_dvd_one H ⟨b, H'.symm⟩ theorem eq_one_of_mul_eq_one_left {a b : ℤ} (H : b ≥ 0) (H' : a * b = 1) : b = 1 := eq_one_of_mul_eq_one_right H (by rw [mul_comm, H']) lemma of_nat_dvd_of_dvd_nat_abs {a : ℕ} : ∀ {z : ℤ} (haz : a ∣ z.nat_abs), ↑a ∣ z | (int.of_nat _) haz := int.coe_nat_dvd.2 haz | -[1+k] haz := begin change ↑a ∣ -(k+1 : ℤ), apply dvd_neg_of_dvd, apply int.coe_nat_dvd.2, exact haz end lemma dvd_nat_abs_of_of_nat_dvd {a : ℕ} : ∀ {z : ℤ} (haz : ↑a ∣ z), a ∣ z.nat_abs | (int.of_nat _) haz := int.coe_nat_dvd.1 (int.dvd_nat_abs.2 haz) | -[1+k] haz := have haz' : (↑a:ℤ) ∣ (↑(k+1):ℤ), from dvd_of_dvd_neg haz, int.coe_nat_dvd.1 haz' lemma pow_dvd_of_le_of_pow_dvd {p m n : ℕ} {k : ℤ} (hmn : m ≤ n) (hdiv : ↑(p ^ n) ∣ k) : ↑(p ^ m) ∣ k := begin induction k, { apply int.coe_nat_dvd.2, apply pow_dvd_of_le_of_pow_dvd hmn, apply int.coe_nat_dvd.1 hdiv }, { change -[1+k] with -(↑(k+1) : ℤ), apply dvd_neg_of_dvd, apply int.coe_nat_dvd.2, apply pow_dvd_of_le_of_pow_dvd hmn, apply int.coe_nat_dvd.1, apply dvd_of_dvd_neg, exact hdiv } end lemma dvd_of_pow_dvd {p k : ℕ} {m : ℤ} (hk : 1 ≤ k) (hpk : ↑(p^k) ∣ m) : ↑p ∣ m := by rw ←nat.pow_one p; exact pow_dvd_of_le_of_pow_dvd hk hpk /- / and ordering -/ protected theorem div_mul_le (a : ℤ) {b : ℤ} (H : b ≠ 0) : a / b * b ≤ a := le_of_sub_nonneg $ by rw [mul_comm, ← mod_def]; apply mod_nonneg _ H protected theorem div_le_of_le_mul {a b c : ℤ} (H : c > 0) (H' : a ≤ b * c) : a / c ≤ b := le_of_mul_le_mul_right (le_trans (int.div_mul_le _ (ne_of_gt H)) H') H protected theorem mul_lt_of_lt_div {a b c : ℤ} (H : c > 0) (H3 : a < b / c) : a * c < b := lt_of_not_ge $ mt (int.div_le_of_le_mul H) (not_le_of_gt H3) protected theorem mul_le_of_le_div {a b c : ℤ} (H1 : c > 0) (H2 : a ≤ b / c) : a * c ≤ b := le_trans (mul_le_mul_of_nonneg_right H2 (le_of_lt H1)) (int.div_mul_le _ (ne_of_gt H1)) protected theorem le_div_of_mul_le {a b c : ℤ} (H1 : c > 0) (H2 : a * c ≤ b) : a ≤ b / c := le_of_lt_add_one $ lt_of_mul_lt_mul_right (lt_of_le_of_lt H2 (lt_div_add_one_mul_self _ H1)) (le_of_lt H1) protected theorem le_div_iff_mul_le {a b c : ℤ} (H : c > 0) : a ≤ b / c ↔ a * c ≤ b := ⟨int.mul_le_of_le_div H, int.le_div_of_mul_le H⟩ protected theorem div_le_div {a b c : ℤ} (H : c > 0) (H' : a ≤ b) : a / c ≤ b / c := int.le_div_of_mul_le H (le_trans (int.div_mul_le _ (ne_of_gt H)) H') protected theorem div_lt_of_lt_mul {a b c : ℤ} (H : c > 0) (H' : a < b * c) : a / c < b := lt_of_not_ge $ mt (int.mul_le_of_le_div H) (not_le_of_gt H') protected theorem lt_mul_of_div_lt {a b c : ℤ} (H1 : c > 0) (H2 : a / c < b) : a < b * c := lt_of_not_ge $ mt (int.le_div_of_mul_le H1) (not_le_of_gt H2) protected theorem div_lt_iff_lt_mul {a b c : ℤ} (H : c > 0) : a / c < b ↔ a < b * c := ⟨int.lt_mul_of_div_lt H, int.div_lt_of_lt_mul H⟩ protected theorem le_mul_of_div_le {a b c : ℤ} (H1 : b ≥ 0) (H2 : b ∣ a) (H3 : a / b ≤ c) : a ≤ c * b := by rw [← int.div_mul_cancel H2]; exact mul_le_mul_of_nonneg_right H3 H1 protected theorem lt_div_of_mul_lt {a b c : ℤ} (H1 : b ≥ 0) (H2 : b ∣ c) (H3 : a * b < c) : a < c / b := lt_of_not_ge $ mt (int.le_mul_of_div_le H1 H2) (not_le_of_gt H3) protected theorem lt_div_iff_mul_lt {a b : ℤ} (c : ℤ) (H : c > 0) (H' : c ∣ b) : a < b / c ↔ a * c < b := ⟨int.mul_lt_of_lt_div H, int.lt_div_of_mul_lt (le_of_lt H) H'⟩ theorem div_pos_of_pos_of_dvd {a b : ℤ} (H1 : a > 0) (H2 : b ≥ 0) (H3 : b ∣ a) : a / b > 0 := int.lt_div_of_mul_lt H2 H3 (by rwa zero_mul) theorem div_eq_div_of_mul_eq_mul {a b c d : ℤ} (H1 : b ∣ a) (H2 : d ∣ c) (H3 : b ≠ 0) (H4 : d ≠ 0) (H5 : a * d = b * c) : a / b = c / d := int.div_eq_of_eq_mul_right H3 $ by rw [← int.mul_div_assoc _ H2]; exact (int.div_eq_of_eq_mul_left H4 H5.symm).symm theorem eq_mul_div_of_mul_eq_mul_of_dvd_left {a b c d : ℤ} (hb : b ≠ 0) (hd : d ≠ 0) (hbc : b ∣ c) (h : b * a = c * d) : a = c / b * d := begin cases hbc with k hk, subst hk, rw int.mul_div_cancel_left, rw mul_assoc at h, apply _root_.eq_of_mul_eq_mul_left _ h, repeat {assumption} end theorem of_nat_add_neg_succ_of_nat_of_lt {m n : ℕ} (h : m < n.succ) : of_nat m + -[1+n] = -[1+ n - m] := begin change sub_nat_nat _ _ = _, have h' : n.succ - m = (n - m).succ, apply succ_sub, apply le_of_lt_succ h, simp [*, sub_nat_nat] end theorem of_nat_add_neg_succ_of_nat_of_ge {m n : ℕ} (h : m ≥ n.succ) : of_nat m + -[1+n] = of_nat (m - n.succ) := begin change sub_nat_nat _ _ = _, have h' : n.succ - m = 0, apply sub_eq_zero_of_le h, simp [*, sub_nat_nat] end @[simp] theorem neg_add_neg (m n : ℕ) : -[1+m] + -[1+n] = -[1+nat.succ(m+n)] := rfl /- to_nat -/ theorem to_nat_eq_max : ∀ (a : ℤ), (to_nat a : ℤ) = max a 0 | (n : ℕ) := (max_eq_left (coe_zero_le n)).symm | -[1+ n] := (max_eq_right (le_of_lt (neg_succ_lt_zero n))).symm @[simp] theorem to_nat_of_nonneg {a : ℤ} (h : 0 ≤ a) : (to_nat a : ℤ) = a := by rw [to_nat_eq_max, max_eq_left h] @[simp] theorem to_nat_coe_nat (n : ℕ) : to_nat ↑n = n := rfl theorem le_to_nat (a : ℤ) : a ≤ to_nat a := by rw [to_nat_eq_max]; apply le_max_left @[simp] theorem to_nat_le (a : ℤ) (n : ℕ) : to_nat a ≤ n ↔ a ≤ n := by rw [(coe_nat_le_coe_nat_iff _ _).symm, to_nat_eq_max, max_le_iff]; exact and_iff_left (coe_zero_le _) theorem to_nat_le_to_nat {a b : ℤ} (h : a ≤ b) : to_nat a ≤ to_nat b := by rw to_nat_le; exact le_trans h (le_to_nat b) def to_nat' : ℤ → option ℕ | (n : ℕ) := some n | -[1+ n] := none theorem mem_to_nat' : ∀ (a : ℤ) (n : ℕ), n ∈ to_nat' a ↔ a = n | (m : ℕ) n := option.some_inj.trans coe_nat_inj'.symm | -[1+ m] n := by split; intro h; cases h /- units -/ @[simp] theorem units_nat_abs (u : units ℤ) : nat_abs u = 1 := units.ext_iff.1 $ nat.units_eq_one ⟨nat_abs u, nat_abs ↑u⁻¹, by rw [← nat_abs_mul, units.mul_inv]; refl, by rw [← nat_abs_mul, units.inv_mul]; refl⟩ theorem units_eq_one_or (u : units ℤ) : u = 1 ∨ u = -1 := by simpa [units.ext_iff, units_nat_abs] using nat_abs_eq u lemma units_inv_eq_self (u : units ℤ) : u⁻¹ = u := (units_eq_one_or u).elim (λ h, h.symm ▸ rfl) (λ h, h.symm ▸ rfl) /- bitwise ops -/ @[simp] lemma bodd_zero : bodd 0 = ff := rfl @[simp] lemma bodd_one : bodd 1 = tt := rfl @[simp] lemma bodd_two : bodd 2 = ff := rfl @[simp] lemma bodd_sub_nat_nat (m n : ℕ) : bodd (sub_nat_nat m n) = bxor m.bodd n.bodd := by apply sub_nat_nat_elim m n (λ m n i, bodd i = bxor m.bodd n.bodd); intros i m; simp [bodd]; cases i.bodd; cases m.bodd; refl @[simp] lemma bodd_neg_of_nat (n : ℕ) : bodd (neg_of_nat n) = n.bodd := by cases n; simp; refl @[simp] lemma bodd_neg (n : ℤ) : bodd (-n) = bodd n := by cases n; unfold has_neg.neg; simp [int.coe_nat_eq, int.neg, bodd] @[simp] lemma bodd_add (m n : ℤ) : bodd (m + n) = bxor (bodd m) (bodd n) := by cases m with m m; cases n with n n; unfold has_add.add; simp [int.add, bodd]; cases m.bodd; cases n.bodd; refl @[simp] lemma bodd_mul (m n : ℤ) : bodd (m * n) = bodd m && bodd n := by cases m with m m; cases n with n n; unfold has_mul.mul; simp [int.mul, bodd]; cases m.bodd; cases n.bodd; refl theorem bodd_add_div2 : ∀ n, cond (bodd n) 1 0 + 2 * div2 n = n | (n : ℕ) := by rw [show (cond (bodd n) 1 0 : ℤ) = (cond (bodd n) 1 0 : ℕ), by cases bodd n; refl]; exact congr_arg of_nat n.bodd_add_div2 | -[1+ n] := begin refine eq.trans _ (congr_arg neg_succ_of_nat n.bodd_add_div2), dsimp [bodd], cases nat.bodd n; dsimp [cond, bnot, div2, int.mul], { change -[1+ 2 * nat.div2 n] = _, rw zero_add }, { rw [zero_add, add_comm], refl } end theorem div2_val : ∀ n, div2 n = n / 2 | (n : ℕ) := congr_arg of_nat n.div2_val | -[1+ n] := congr_arg neg_succ_of_nat n.div2_val lemma bit0_val (n : ℤ) : bit0 n = 2 * n := (two_mul _).symm lemma bit1_val (n : ℤ) : bit1 n = 2 * n + 1 := congr_arg (+(1:ℤ)) (bit0_val _) lemma bit_val (b n) : bit b n = 2 * n + cond b 1 0 := by { cases b, apply (bit0_val n).trans (add_zero _).symm, apply bit1_val } lemma bit_decomp (n : ℤ) : bit (bodd n) (div2 n) = n := (bit_val _ _).trans $ (add_comm _ _).trans $ bodd_add_div2 _ def {u} bit_cases_on {C : ℤ → Sort u} (n) (h : ∀ b n, C (bit b n)) : C n := by rw [← bit_decomp n]; apply h @[simp] lemma bit_zero : bit ff 0 = 0 := rfl @[simp] lemma bit_coe_nat (b) (n : ℕ) : bit b n = nat.bit b n := by rw [bit_val, nat.bit_val]; cases b; refl @[simp] lemma bit_neg_succ (b) (n : ℕ) : bit b -[1+ n] = -[1+ nat.bit (bnot b) n] := by rw [bit_val, nat.bit_val]; cases b; refl @[simp] lemma bodd_bit (b n) : bodd (bit b n) = b := by rw bit_val; simp; cases b; cases bodd n; refl @[simp] lemma div2_bit (b n) : div2 (bit b n) = n := begin rw [bit_val, div2_val, add_comm, int.add_mul_div_left, (_ : (_/2:ℤ) = 0), zero_add], cases b, all_goals {exact dec_trivial} end @[simp] lemma test_bit_zero (b) : ∀ n, test_bit (bit b n) 0 = b | (n : ℕ) := by rw [bit_coe_nat]; apply nat.test_bit_zero | -[1+ n] := by rw [bit_neg_succ]; dsimp [test_bit]; rw [nat.test_bit_zero]; clear test_bit_zero; cases b; refl @[simp] lemma test_bit_succ (m b) : ∀ n, test_bit (bit b n) (nat.succ m) = test_bit n m | (n : ℕ) := by rw [bit_coe_nat]; apply nat.test_bit_succ | -[1+ n] := by rw [bit_neg_succ]; dsimp [test_bit]; rw [nat.test_bit_succ] private meta def bitwise_tac : tactic unit := `[ funext m, funext n, cases m with m m; cases n with n n; try {refl}, all_goals { apply congr_arg of_nat <|> apply congr_arg neg_succ_of_nat, try {dsimp [nat.land, nat.ldiff, nat.lor]}, try {rw [ show nat.bitwise (λ a b, a && bnot b) n m = nat.bitwise (λ a b, b && bnot a) m n, from congr_fun (congr_fun (@nat.bitwise_swap (λ a b, b && bnot a) rfl) n) m]}, apply congr_arg (λ f, nat.bitwise f m n), funext a, funext b, cases a; cases b; refl }, all_goals {unfold nat.land nat.ldiff nat.lor} ] theorem bitwise_or : bitwise bor = lor := by bitwise_tac theorem bitwise_and : bitwise band = land := by bitwise_tac theorem bitwise_diff : bitwise (λ a b, a && bnot b) = ldiff := by bitwise_tac theorem bitwise_xor : bitwise bxor = lxor := by bitwise_tac @[simp] lemma bitwise_bit (f : bool → bool → bool) (a m b n) : bitwise f (bit a m) (bit b n) = bit (f a b) (bitwise f m n) := begin cases m with m m; cases n with n n; repeat { rw [← int.coe_nat_eq] <|> rw bit_coe_nat <|> rw bit_neg_succ }; unfold bitwise nat_bitwise bnot; [ induction h : f ff ff, induction h : f ff tt, induction h : f tt ff, induction h : f tt tt ], all_goals { unfold cond, rw nat.bitwise_bit, repeat { rw bit_coe_nat <|> rw bit_neg_succ <|> rw bnot_bnot } }, all_goals { unfold bnot {fail_if_unchanged := ff}; rw h; refl } end @[simp] lemma lor_bit (a m b n) : lor (bit a m) (bit b n) = bit (a || b) (lor m n) := by rw [← bitwise_or, bitwise_bit] @[simp] lemma land_bit (a m b n) : land (bit a m) (bit b n) = bit (a && b) (land m n) := by rw [← bitwise_and, bitwise_bit] @[simp] lemma ldiff_bit (a m b n) : ldiff (bit a m) (bit b n) = bit (a && bnot b) (ldiff m n) := by rw [← bitwise_diff, bitwise_bit] @[simp] lemma lxor_bit (a m b n) : lxor (bit a m) (bit b n) = bit (bxor a b) (lxor m n) := by rw [← bitwise_xor, bitwise_bit] @[simp] lemma lnot_bit (b) : ∀ n, lnot (bit b n) = bit (bnot b) (lnot n) | (n : ℕ) := by simp [lnot] | -[1+ n] := by simp [lnot] @[simp] lemma test_bit_bitwise (f : bool → bool → bool) (m n k) : test_bit (bitwise f m n) k = f (test_bit m k) (test_bit n k) := begin induction k with k IH generalizing m n; apply bit_cases_on m; intros a m'; apply bit_cases_on n; intros b n'; rw bitwise_bit, { simp [test_bit_zero] }, { simp [test_bit_succ, IH] } end @[simp] lemma test_bit_lor (m n k) : test_bit (lor m n) k = test_bit m k || test_bit n k := by rw [← bitwise_or, test_bit_bitwise] @[simp] lemma test_bit_land (m n k) : test_bit (land m n) k = test_bit m k && test_bit n k := by rw [← bitwise_and, test_bit_bitwise] @[simp] lemma test_bit_ldiff (m n k) : test_bit (ldiff m n) k = test_bit m k && bnot (test_bit n k) := by rw [← bitwise_diff, test_bit_bitwise] @[simp] lemma test_bit_lxor (m n k) : test_bit (lxor m n) k = bxor (test_bit m k) (test_bit n k) := by rw [← bitwise_xor, test_bit_bitwise] @[simp] lemma test_bit_lnot : ∀ n k, test_bit (lnot n) k = bnot (test_bit n k) | (n : ℕ) k := by simp [lnot, test_bit] | -[1+ n] k := by simp [lnot, test_bit] lemma shiftl_add : ∀ (m : ℤ) (n : ℕ) (k : ℤ), shiftl m (n + k) = shiftl (shiftl m n) k | (m : ℕ) n (k:ℕ) := congr_arg of_nat (nat.shiftl_add _ _ _) | -[1+ m] n (k:ℕ) := congr_arg neg_succ_of_nat (nat.shiftl'_add _ _ _ _) | (m : ℕ) n -[1+k] := sub_nat_nat_elim n k.succ (λ n k i, shiftl ↑m i = nat.shiftr (nat.shiftl m n) k) (λ i n, congr_arg coe $ by rw [← nat.shiftl_sub, nat.add_sub_cancel_left]; apply nat.le_add_right) (λ i n, congr_arg coe $ by rw [add_assoc, nat.shiftr_add, ← nat.shiftl_sub, nat.sub_self]; refl) | -[1+ m] n -[1+k] := sub_nat_nat_elim n k.succ (λ n k i, shiftl -[1+ m] i = -[1+ nat.shiftr (nat.shiftl' tt m n) k]) (λ i n, congr_arg neg_succ_of_nat $ by rw [← nat.shiftl'_sub, nat.add_sub_cancel_left]; apply nat.le_add_right) (λ i n, congr_arg neg_succ_of_nat $ by rw [add_assoc, nat.shiftr_add, ← nat.shiftl'_sub, nat.sub_self]; refl) lemma shiftl_sub (m : ℤ) (n : ℕ) (k : ℤ) : shiftl m (n - k) = shiftr (shiftl m n) k := shiftl_add _ _ _ @[simp] lemma shiftl_neg (m n : ℤ) : shiftl m (-n) = shiftr m n := rfl @[simp] lemma shiftr_neg (m n : ℤ) : shiftr m (-n) = shiftl m n := by rw [← shiftl_neg, neg_neg] @[simp] lemma shiftl_coe_nat (m n : ℕ) : shiftl m n = nat.shiftl m n := rfl @[simp] lemma shiftr_coe_nat (m n : ℕ) : shiftr m n = nat.shiftr m n := by cases n; refl @[simp] lemma shiftl_neg_succ (m n : ℕ) : shiftl -[1+ m] n = -[1+ nat.shiftl' tt m n] := rfl @[simp] lemma shiftr_neg_succ (m n : ℕ) : shiftr -[1+ m] n = -[1+ nat.shiftr m n] := by cases n; refl lemma shiftr_add : ∀ (m : ℤ) (n k : ℕ), shiftr m (n + k) = shiftr (shiftr m n) k | (m : ℕ) n k := by rw [shiftr_coe_nat, shiftr_coe_nat, ← int.coe_nat_add, shiftr_coe_nat, nat.shiftr_add] | -[1+ m] n k := by rw [shiftr_neg_succ, shiftr_neg_succ, ← int.coe_nat_add, shiftr_neg_succ, nat.shiftr_add] lemma shiftl_eq_mul_pow : ∀ (m : ℤ) (n : ℕ), shiftl m n = m * ↑(2 ^ n) | (m : ℕ) n := congr_arg coe (nat.shiftl_eq_mul_pow _ _) | -[1+ m] n := @congr_arg ℕ ℤ _ _ (λi, -i) (nat.shiftl'_tt_eq_mul_pow _ _) lemma shiftr_eq_div_pow : ∀ (m : ℤ) (n : ℕ), shiftr m n = m / ↑(2 ^ n) | (m : ℕ) n := by rw shiftr_coe_nat; exact congr_arg coe (nat.shiftr_eq_div_pow _ _) | -[1+ m] n := begin rw [shiftr_neg_succ, neg_succ_of_nat_div, nat.shiftr_eq_div_pow], refl, exact coe_nat_lt_coe_nat_of_lt (nat.pos_pow_of_pos _ dec_trivial) end lemma one_shiftl (n : ℕ) : shiftl 1 n = (2 ^ n : ℕ) := congr_arg coe (nat.one_shiftl _) @[simp] lemma zero_shiftl : ∀ n : ℤ, shiftl 0 n = 0 | (n : ℕ) := congr_arg coe (nat.zero_shiftl _) | -[1+ n] := congr_arg coe (nat.zero_shiftr _) @[simp] lemma zero_shiftr (n) : shiftr 0 n = 0 := zero_shiftl _ /- Least upper bound property for integers -/ theorem exists_least_of_bdd {P : ℤ → Prop} [HP : decidable_pred P] (Hbdd : ∃ b : ℤ, ∀ z : ℤ, P z → b ≤ z) (Hinh : ∃ z : ℤ, P z) : ∃ lb : ℤ, P lb ∧ (∀ z : ℤ, P z → lb ≤ z) := let ⟨b, Hb⟩ := Hbdd in have EX : ∃ n : ℕ, P (b + n), from let ⟨elt, Helt⟩ := Hinh in match elt, le.dest (Hb _ Helt), Helt with | ._, ⟨n, rfl⟩, Hn := ⟨n, Hn⟩ end, ⟨b + (nat.find EX : ℤ), nat.find_spec EX, λ z h, match z, le.dest (Hb _ h), h with | ._, ⟨n, rfl⟩, h := add_le_add_left (int.coe_nat_le.2 $ nat.find_min' _ h) _ end⟩ theorem exists_greatest_of_bdd {P : ℤ → Prop} [HP : decidable_pred P] (Hbdd : ∃ b : ℤ, ∀ z : ℤ, P z → z ≤ b) (Hinh : ∃ z : ℤ, P z) : ∃ ub : ℤ, P ub ∧ (∀ z : ℤ, P z → z ≤ ub) := have Hbdd' : ∃ (b : ℤ), ∀ (z : ℤ), P (-z) → b ≤ z, from let ⟨b, Hb⟩ := Hbdd in ⟨-b, λ z h, neg_le.1 (Hb _ h)⟩, have Hinh' : ∃ z : ℤ, P (-z), from let ⟨elt, Helt⟩ := Hinh in ⟨-elt, by rw [neg_neg]; exact Helt⟩, let ⟨lb, Plb, al⟩ := exists_least_of_bdd Hbdd' Hinh' in ⟨-lb, Plb, λ z h, le_neg.1 $ al _ $ by rwa neg_neg⟩ /- cast (injection into groups with one) -/ @[simp] theorem nat_cast_eq_coe_nat : ∀ n, @coe ℕ ℤ (@coe_to_lift _ _ (@coe_base _ _ nat.cast_coe)) n = @coe ℕ ℤ (@coe_to_lift _ _ (@coe_base _ _ int.has_coe)) n | 0 := rfl | (n+1) := congr_arg (+(1:ℤ)) (nat_cast_eq_coe_nat n) section cast variables {α : Type*} section variables [has_neg α] [has_zero α] [has_one α] [has_add α] /-- Canonical homomorphism from the integers to any ring(-like) structure `α` -/ protected def cast : ℤ → α | (n : ℕ) := n | -[1+ n] := -(n+1) @[priority 0] instance cast_coe : has_coe ℤ α := ⟨int.cast⟩ @[simp, squash_cast] theorem cast_zero : ((0 : ℤ) : α) = 0 := rfl @[simp] theorem cast_of_nat (n : ℕ) : (of_nat n : α) = n := rfl @[simp, squash_cast] theorem cast_coe_nat (n : ℕ) : ((n : ℤ) : α) = n := rfl @[simp] theorem cast_coe_nat' (n : ℕ) : (@coe ℕ ℤ (@coe_to_lift _ _ (@coe_base _ _ nat.cast_coe)) n : α) = n := by simp @[simp, move_cast] theorem cast_neg_succ_of_nat (n : ℕ) : (-[1+ n] : α) = -(n + 1) := rfl end @[simp, squash_cast] theorem cast_one [add_monoid α] [has_one α] [has_neg α] : ((1 : ℤ) : α) = 1 := nat.cast_one @[simp, move_cast] theorem cast_sub_nat_nat [add_group α] [has_one α] (m n) : ((int.sub_nat_nat m n : ℤ) : α) = m - n := begin unfold sub_nat_nat, cases e : n - m, { simp [sub_nat_nat, e, nat.le_of_sub_eq_zero e] }, { rw [sub_nat_nat, cast_neg_succ_of_nat, ← nat.cast_succ, ← e, nat.cast_sub $ _root_.le_of_lt $ nat.lt_of_sub_eq_succ e, neg_sub] }, end @[simp, move_cast] theorem cast_neg_of_nat [add_group α] [has_one α] : ∀ n, ((neg_of_nat n : ℤ) : α) = -n | 0 := neg_zero.symm | (n+1) := rfl @[simp, move_cast] theorem cast_add [add_group α] [has_one α] : ∀ m n, ((m + n : ℤ) : α) = m + n | (m : ℕ) (n : ℕ) := nat.cast_add _ _ | (m : ℕ) -[1+ n] := cast_sub_nat_nat _ _ | -[1+ m] (n : ℕ) := (cast_sub_nat_nat _ _).trans $ sub_eq_of_eq_add $ show (n:α) = -(m+1) + n + (m+1), by rw [add_assoc, ← cast_succ, ← nat.cast_add, add_comm, nat.cast_add, cast_succ, neg_add_cancel_left] | -[1+ m] -[1+ n] := show -((m + n + 1 + 1 : ℕ) : α) = -(m + 1) + -(n + 1), by rw [← neg_add_rev, ← nat.cast_add_one, ← nat.cast_add_one, ← nat.cast_add]; apply congr_arg (λ x:ℕ, -(x:α)); simp @[simp, move_cast] theorem cast_neg [add_group α] [has_one α] : ∀ n, ((-n : ℤ) : α) = -n | (n : ℕ) := cast_neg_of_nat _ | -[1+ n] := (neg_neg _).symm @[move_cast] theorem cast_sub [add_group α] [has_one α] (m n) : ((m - n : ℤ) : α) = m - n := by simp @[simp] theorem cast_eq_zero [add_group α] [has_one α] [char_zero α] {n : ℤ} : (n : α) = 0 ↔ n = 0 := ⟨λ h, begin cases n, { exact congr_arg coe (nat.cast_eq_zero.1 h) }, { rw [cast_neg_succ_of_nat, neg_eq_zero, ← cast_succ, nat.cast_eq_zero] at h, contradiction } end, λ h, by rw [h, cast_zero]⟩ @[simp, elim_cast] theorem cast_inj [add_group α] [has_one α] [char_zero α] {m n : ℤ} : (m : α) = n ↔ m = n := by rw [← sub_eq_zero, ← cast_sub, cast_eq_zero, sub_eq_zero] theorem cast_injective [add_group α] [has_one α] [char_zero α] : function.injective (coe : ℤ → α) | m n := cast_inj.1 @[simp] theorem cast_ne_zero [add_group α] [has_one α] [char_zero α] {n : ℤ} : (n : α) ≠ 0 ↔ n ≠ 0 := not_congr cast_eq_zero @[simp, move_cast] theorem cast_mul [ring α] : ∀ m n, ((m * n : ℤ) : α) = m * n | (m : ℕ) (n : ℕ) := nat.cast_mul _ _ | (m : ℕ) -[1+ n] := (cast_neg_of_nat _).trans $ show (-(m * (n + 1) : ℕ) : α) = m * -(n + 1), by rw [nat.cast_mul, nat.cast_add_one, neg_mul_eq_mul_neg] | -[1+ m] (n : ℕ) := (cast_neg_of_nat _).trans $ show (-((m + 1) * n : ℕ) : α) = -(m + 1) * n, by rw [nat.cast_mul, nat.cast_add_one, neg_mul_eq_neg_mul] | -[1+ m] -[1+ n] := show (((m + 1) * (n + 1) : ℕ) : α) = -(m + 1) * -(n + 1), by rw [nat.cast_mul, nat.cast_add_one, nat.cast_add_one, neg_mul_neg] instance cast.is_ring_hom [ring α] : is_ring_hom (int.cast : ℤ → α) := ⟨cast_one, cast_mul, cast_add⟩ instance coe.is_ring_hom [ring α] : is_ring_hom (coe : ℤ → α) := cast.is_ring_hom theorem mul_cast_comm [ring α] (a : α) (n : ℤ) : a * n = n * a := by cases n; simp [nat.mul_cast_comm, left_distrib, right_distrib, *] @[simp, squash_cast, move_cast] theorem coe_nat_bit0 (n : ℕ) : (↑(bit0 n) : ℤ) = bit0 ↑n := by {unfold bit0, simp} @[simp, squash_cast, move_cast] theorem coe_nat_bit1 (n : ℕ) : (↑(bit1 n) : ℤ) = bit1 ↑n := by {unfold bit1, unfold bit0, simp} @[simp, squash_cast, move_cast] theorem cast_bit0 [ring α] (n : ℤ) : ((bit0 n : ℤ) : α) = bit0 n := cast_add _ _ @[simp, squash_cast, move_cast] theorem cast_bit1 [ring α] (n : ℤ) : ((bit1 n : ℤ) : α) = bit1 n := by rw [bit1, cast_add, cast_one, cast_bit0]; refl lemma cast_two [ring α] : ((2 : ℤ) : α) = 2 := by simp theorem cast_nonneg [linear_ordered_ring α] : ∀ {n : ℤ}, (0 : α) ≤ n ↔ 0 ≤ n | (n : ℕ) := by simp | -[1+ n] := by simpa [not_le_of_gt (neg_succ_lt_zero n)] using show -(n:α) < 1, from lt_of_le_of_lt (by simp) zero_lt_one @[simp, elim_cast] theorem cast_le [linear_ordered_ring α] {m n : ℤ} : (m : α) ≤ n ↔ m ≤ n := by rw [← sub_nonneg, ← cast_sub, cast_nonneg, sub_nonneg] @[simp, elim_cast] theorem cast_lt [linear_ordered_ring α] {m n : ℤ} : (m : α) < n ↔ m < n := by simpa [-cast_le] using not_congr (@cast_le α _ n m) @[simp] theorem cast_nonpos [linear_ordered_ring α] {n : ℤ} : (n : α) ≤ 0 ↔ n ≤ 0 := by rw [← cast_zero, cast_le] @[simp] theorem cast_pos [linear_ordered_ring α] {n : ℤ} : (0 : α) < n ↔ 0 < n := by rw [← cast_zero, cast_lt] @[simp] theorem cast_lt_zero [linear_ordered_ring α] {n : ℤ} : (n : α) < 0 ↔ n < 0 := by rw [← cast_zero, cast_lt] theorem eq_cast [add_group α] [has_one α] (f : ℤ → α) (H1 : f 1 = 1) (Hadd : ∀ x y, f (x + y) = f x + f y) (n : ℤ) : f n = n := begin have H : ∀ (n : ℕ), f n = n := nat.eq_cast' (λ n, f n) H1 (λ x y, Hadd x y), cases n, {apply H}, apply eq_neg_of_add_eq_zero, rw [← nat.cast_zero, ← H 0, int.coe_nat_zero, ← show -[1+ n] + (↑n + 1) = 0, from neg_add_self (↑n+1), Hadd, show f (n+1) = n+1, from H (n+1)] end lemma eq_cast' [ring α] (f : ℤ → α) [is_ring_hom f] : f = int.cast := funext $ int.eq_cast f (is_ring_hom.map_one f) (λ _ _, is_ring_hom.map_add f) @[simp, squash_cast] theorem cast_id (n : ℤ) : ↑n = n := (eq_cast id rfl (λ _ _, rfl) n).symm @[simp, move_cast] theorem cast_min [decidable_linear_ordered_comm_ring α] {a b : ℤ} : (↑(min a b) : α) = min a b := by by_cases a ≤ b; simp [h, min] @[simp, move_cast] theorem cast_max [decidable_linear_ordered_comm_ring α] {a b : ℤ} : (↑(max a b) : α) = max a b := by by_cases a ≤ b; simp [h, max] @[simp, move_cast] theorem cast_abs [decidable_linear_ordered_comm_ring α] {q : ℤ} : ((abs q : ℤ) : α) = abs q := by simp [abs] end cast section decidable def range (m n : ℤ) : list ℤ := (list.range (to_nat (n-m))).map $ λ r, m+r theorem mem_range_iff {m n r : ℤ} : r ∈ range m n ↔ m ≤ r ∧ r < n := ⟨λ H, let ⟨s, h1, h2⟩ := list.mem_map.1 H in h2 ▸ ⟨le_add_of_nonneg_right trivial, add_lt_of_lt_sub_left $ match n-m, h1 with | (k:ℕ), h1 := by rwa [list.mem_range, to_nat_coe_nat, ← coe_nat_lt] at h1 end⟩, λ ⟨h1, h2⟩, list.mem_map.2 ⟨to_nat (r-m), list.mem_range.2 $ by rw [← coe_nat_lt, to_nat_of_nonneg (sub_nonneg_of_le h1), to_nat_of_nonneg (sub_nonneg_of_le (le_of_lt (lt_of_le_of_lt h1 h2)))]; exact sub_lt_sub_right h2 _, show m + _ = _, by rw [to_nat_of_nonneg (sub_nonneg_of_le h1), add_sub_cancel'_right]⟩⟩ instance decidable_le_lt (P : int → Prop) [decidable_pred P] (m n : ℤ) : decidable (∀ r, m ≤ r → r < n → P r) := decidable_of_iff (∀ r ∈ range m n, P r) $ by simp only [mem_range_iff, and_imp] instance decidable_le_le (P : int → Prop) [decidable_pred P] (m n : ℤ) : decidable (∀ r, m ≤ r → r ≤ n → P r) := decidable_of_iff (∀ r ∈ range m (n+1), P r) $ by simp only [mem_range_iff, and_imp, lt_add_one_iff] instance decidable_lt_lt (P : int → Prop) [decidable_pred P] (m n : ℤ) : decidable (∀ r, m < r → r < n → P r) := int.decidable_le_lt P _ _ instance decidable_lt_le (P : int → Prop) [decidable_pred P] (m n : ℤ) : decidable (∀ r, m < r → r ≤ n → P r) := int.decidable_le_le P _ _ end decidable end int
84df06aa7baa074019d7c9693c3dc86c894a7fd2
82e44445c70db0f03e30d7be725775f122d72f3e
/src/data/equiv/mul_add.lean
76a3badc0f642302599c245b5bd1ee43563344ff
[ "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
24,506
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 algebra.group.hom import algebra.group.type_tags import algebra.group.units_hom import algebra.group_with_zero /-! # 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. ## Notations * ``infix ` ≃* `:25 := mul_equiv`` * ``infix ` ≃+ `:25 := add_equiv`` 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. ## Tags equiv, mul_equiv, add_equiv -/ variables {A : Type*} {B : Type*} {M : Type*} {N : Type*} {P : Type*} {Q : Type*} {G : Type*} {H : Type*} /-- Makes a multiplicative inverse from a bijection which preserves multiplication. -/ @[to_additive "Makes an additive inverse from a bijection which preserves addition."] def mul_hom.inverse [has_mul M] [has_mul N] (f : mul_hom M N) (g : N → M) (h₁ : function.left_inverse g f) (h₂ : function.right_inverse g f) : mul_hom N M := { to_fun := g, map_mul' := λ x y, calc g (x * y) = g (f (g x) * f (g y)) : by rw [h₂ x, h₂ y] ... = g (f (g x * g y)) : by rw f.map_mul ... = g x * g y : h₁ _, } /-- The inverse of a bijective `monoid_hom` is a `monoid_hom`. -/ @[to_additive "The inverse of a bijective `add_monoid_hom` is an `add_monoid_hom`.", simps] def monoid_hom.inverse {A B : Type*} [monoid A] [monoid B] (f : A →* B) (g : B → A) (h₁ : function.left_inverse g f) (h₂ : function.right_inverse g f) : B →* A := { to_fun := g, map_one' := by rw [← f.map_one, h₁], .. (f : mul_hom A B).inverse g h₁ h₂, } set_option old_structure_cmd true /-- add_equiv α β is the type of an equiv α ≃ β which preserves addition. -/ @[ancestor equiv add_hom] structure add_equiv (A B : Type*) [has_add A] [has_add B] extends A ≃ B, add_hom A B /-- The `equiv` underlying an `add_equiv`. -/ add_decl_doc add_equiv.to_equiv /-- The `add_hom` underlying a `add_equiv`. -/ add_decl_doc add_equiv.to_add_hom /-- `mul_equiv α β` is the type of an equiv `α ≃ β` which preserves multiplication. -/ @[ancestor equiv mul_hom, to_additive] structure mul_equiv (M N : Type*) [has_mul M] [has_mul N] extends M ≃ N, mul_hom M N /-- The `equiv` underlying a `mul_equiv`. -/ add_decl_doc mul_equiv.to_equiv /-- The `mul_hom` underlying a `mul_equiv`. -/ add_decl_doc mul_equiv.to_mul_hom 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] [has_mul Q] @[simp, to_additive] lemma to_fun_eq_coe {f : M ≃* N} : f.to_fun = f := rfl @[simp, to_additive] lemma coe_to_equiv {f : M ≃* N} : ⇑f.to_equiv = f := rfl @[simp, to_additive] lemma coe_to_mul_hom {f : M ≃* N} : ⇑f.to_mul_hom = f := rfl /-- A multiplicative isomorphism preserves multiplication (canonical form). -/ @[simp, to_additive] lemma map_mul (f : M ≃* N) : ∀ x y, f (x * y) = f x * f y := f.map_mul' /-- Makes a multiplicative isomorphism from a bijection which preserves multiplication. -/ @[to_additive "Makes an additive isomorphism from a bijection which preserves addition."] 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⟩ @[to_additive] protected lemma bijective (e : M ≃* N) : function.bijective e := e.to_equiv.bijective @[to_additive] protected lemma injective (e : M ≃* N) : function.injective e := e.to_equiv.injective @[to_additive] protected lemma surjective (e : M ≃* N) : function.surjective e := e.to_equiv.surjective /-- The identity map is a multiplicative isomorphism. -/ @[refl, to_additive "The identity map is an additive isomorphism."] def refl (M : Type*) [has_mul M] : M ≃* M := { map_mul' := λ _ _, rfl, ..equiv.refl _} @[to_additive] instance : inhabited (M ≃* M) := ⟨refl M⟩ /-- The inverse of an isomorphism is an isomorphism. -/ @[symm, to_additive "The inverse of an isomorphism is an isomorphism."] def symm (h : M ≃* N) : N ≃* M := { map_mul' := (h.to_mul_hom.inverse h.to_equiv.symm h.left_inv h.right_inv).map_mul, .. h.to_equiv.symm} /-- See Note [custom simps projection] -/ -- we don't hyperlink the note in the additive version, since that breaks syntax highlighting -- in the whole file. @[to_additive "See Note custom simps projection"] def simps.symm_apply (e : M ≃* N) : N → M := e.symm initialize_simps_projections add_equiv (to_fun → apply, inv_fun → symm_apply) initialize_simps_projections mul_equiv (to_fun → apply, inv_fun → symm_apply) @[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] lemma symm_symm : ∀ (f : M ≃* N), f.symm.symm = f | ⟨f, g, h₁, h₂, h₃⟩ := rfl @[to_additive] lemma symm_bijective : function.bijective (symm : (M ≃* N) → (N ≃* M)) := equiv.bijective ⟨symm, symm, symm_symm, symm_symm⟩ @[simp, to_additive] theorem symm_mk (f : M → N) (g h₁ h₂ h₃) : (mul_equiv.mk f g h₁ h₂ h₃).symm = { to_fun := g, inv_fun := f, ..(mul_equiv.mk f g h₁ h₂ h₃).symm} := rfl /-- Transitivity of multiplication-preserving isomorphisms -/ @[trans, to_additive "Transitivity of addition-preserving isomorphisms"] 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 @[simp, to_additive] theorem symm_comp_self (e : M ≃* N) : e.symm ∘ e = id := funext e.symm_apply_apply @[simp, to_additive] theorem self_comp_symm (e : M ≃* N) : e ∘ e.symm = id := funext e.apply_symm_apply @[simp, to_additive] theorem coe_refl : ⇑(refl M) = id := rfl @[to_additive] theorem refl_apply (m : M) : refl M m = m := rfl @[simp, to_additive] theorem coe_trans (e₁ : M ≃* N) (e₂ : N ≃* P) : ⇑(e₁.trans e₂) = e₂ ∘ e₁ := rfl @[to_additive] theorem trans_apply (e₁ : M ≃* N) (e₂ : N ≃* P) (m : M) : e₁.trans e₂ m = e₂ (e₁ m) := rfl @[simp, to_additive] theorem apply_eq_iff_eq (e : M ≃* N) {x y : M} : e x = e y ↔ x = y := e.injective.eq_iff @[to_additive] lemma apply_eq_iff_symm_apply (e : M ≃* N) {x : M} {y : N} : e x = y ↔ x = e.symm y := e.to_equiv.apply_eq_iff_eq_symm_apply @[to_additive] lemma symm_apply_eq (e : M ≃* N) {x y} : e.symm x = y ↔ x = e y := e.to_equiv.symm_apply_eq @[to_additive] lemma eq_symm_apply (e : M ≃* N) {x y} : y = e.symm x ↔ e y = x := e.to_equiv.eq_symm_apply /-- 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₁ : f.to_equiv = g.to_equiv := equiv.ext h, cases f, cases g, congr, { exact (funext h) }, { exact congr_arg equiv.inv_fun h₁ } end attribute [ext] add_equiv.ext @[to_additive] lemma ext_iff {f g : mul_equiv M N} : f = g ↔ ∀ x, f x = g x := ⟨λ h x, h ▸ rfl, ext⟩ @[simp, to_additive] lemma mk_coe (e : M ≃* N) (e' h₁ h₂ h₃) : (⟨e, e', h₁, h₂, h₃⟩ : M ≃* N) = e := ext $ λ _, rfl @[simp, to_additive] lemma mk_coe' (e : M ≃* N) (f h₁ h₂ h₃) : (mul_equiv.mk f ⇑e h₁ h₂ h₃ : N ≃* M) = e.symm := symm_bijective.injective $ ext $ λ x, rfl @[to_additive] protected lemma congr_arg {f : mul_equiv M N} : Π {x x' : M}, x = x' → f x = f x' | _ _ rfl := rfl @[to_additive] protected lemma congr_fun {f g : mul_equiv M N} (h : f = g) (x : M) : f x = g x := h ▸ rfl /-- The `mul_equiv` between two monoids with a unique element. -/ @[to_additive "The `add_equiv` between two add_monoids with a unique element."] def mul_equiv_of_unique_of_unique {M N} [unique M] [unique N] [has_mul M] [has_mul N] : M ≃* N := { map_mul' := λ _ _, subsingleton.elim _ _, ..equiv_of_unique_of_unique } /-- There is a unique monoid homomorphism between two monoids with a unique element. -/ @[to_additive] instance {M N} [unique M] [unique N] [has_mul M] [has_mul N] : unique (M ≃* N) := { default := mul_equiv_of_unique_of_unique , uniq := λ _, ext $ λ x, subsingleton.elim _ _} /-! ## Monoids -/ /-- A multiplicative equiv of monoids sends 1 to 1 (and is hence a monoid isomorphism). -/ @[simp, to_additive] lemma map_one {M N} [mul_one_class M] [mul_one_class 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} [mul_one_class M] [mul_one_class N] (h : M ≃* N) {x : M} : h x = 1 ↔ x = 1 := h.map_one ▸ h.to_equiv.apply_eq_iff_eq @[to_additive] lemma map_ne_one_iff {M N} [mul_one_class M] [mul_one_class 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⟩ /-- A bijective `monoid` homomorphism is an isomorphism -/ @[to_additive "A bijective `add_monoid` homomorphism is an isomorphism"] noncomputable def of_bijective {M N} [mul_one_class M] [mul_one_class N] (f : M →* N) (hf : function.bijective f) : M ≃* N := { map_mul' := f.map_mul', ..equiv.of_bijective f hf } /-- Extract the forward direction of a multiplicative equivalence as a multiplication-preserving function. -/ @[to_additive "Extract the forward direction of an additive equivalence as an addition-preserving function."] def to_monoid_hom {M N} [mul_one_class M] [mul_one_class N] (h : M ≃* N) : (M →* N) := { map_one' := h.map_one, .. h } @[simp, to_additive] lemma coe_to_monoid_hom {M N} [mul_one_class M] [mul_one_class N] (e : M ≃* N) : ⇑e.to_monoid_hom = e := rfl @[to_additive] lemma to_monoid_hom_injective {M N} [mul_one_class M] [mul_one_class N] : function.injective (to_monoid_hom : (M ≃* N) → M →* N) := λ f g h, mul_equiv.ext (monoid_hom.ext_iff.1 h) /-- A multiplicative analogue of `equiv.arrow_congr`, where the equivalence between the targets is multiplicative. -/ @[to_additive "An additive analogue of `equiv.arrow_congr`, where the equivalence between the targets is additive.", simps apply] def arrow_congr {M N P Q : Type*} [mul_one_class P] [mul_one_class Q] (f : M ≃ N) (g : P ≃* Q) : (M → P) ≃* (N → Q) := { to_fun := λ h n, g (h (f.symm n)), inv_fun := λ k m, g.symm (k (f m)), left_inv := λ h, by { ext, simp, }, right_inv := λ k, by { ext, simp, }, map_mul' := λ h k, by { ext, simp, }, } /-- A multiplicative analogue of `equiv.arrow_congr`, for multiplicative maps from a monoid to a commutative monoid. -/ @[to_additive "An additive analogue of `equiv.arrow_congr`, for additive maps from an additive monoid to a commutative additive monoid.", simps apply] def monoid_hom_congr {M N P Q} [mul_one_class M] [mul_one_class N] [comm_monoid P] [comm_monoid Q] (f : M ≃* N) (g : P ≃* Q) : (M →* P) ≃* (N →* Q) := { to_fun := λ h, g.to_monoid_hom.comp (h.comp f.symm.to_monoid_hom), inv_fun := λ k, g.symm.to_monoid_hom.comp (k.comp f.to_monoid_hom), left_inv := λ h, by { ext, simp, }, right_inv := λ k, by { ext, simp, }, map_mul' := λ h k, by { ext, simp, }, } /-- A family of multiplicative equivalences `Π j, (Ms j ≃* Ns j)` generates a multiplicative equivalence between `Π j, Ms j` and `Π j, Ns j`. This is the `mul_equiv` version of `equiv.Pi_congr_right`, and the dependent version of `mul_equiv.arrow_congr`. -/ @[to_additive add_equiv.Pi_congr_right "A family of additive equivalences `Π j, (Ms j ≃+ Ns j)` generates an additive equivalence between `Π j, Ms j` and `Π j, Ns j`. This is the `add_equiv` version of `equiv.Pi_congr_right`, and the dependent version of `add_equiv.arrow_congr`.", simps apply] def Pi_congr_right {η : Type*} {Ms Ns : η → Type*} [Π j, mul_one_class (Ms j)] [Π j, mul_one_class (Ns j)] (es : ∀ j, Ms j ≃* Ns j) : (Π j, Ms j) ≃* (Π j, Ns j) := { to_fun := λ x j, es j (x j), inv_fun := λ x j, (es j).symm (x j), map_mul' := λ x y, funext $ λ j, (es j).map_mul (x j) (y j), .. equiv.Pi_congr_right (λ j, (es j).to_equiv) } @[simp] lemma Pi_congr_right_refl {η : Type*} {Ms : η → Type*} [Π j, mul_one_class (Ms j)] : Pi_congr_right (λ j, mul_equiv.refl (Ms j)) = mul_equiv.refl _ := rfl @[simp] lemma Pi_congr_right_symm {η : Type*} {Ms Ns : η → Type*} [Π j, mul_one_class (Ms j)] [Π j, mul_one_class (Ns j)] (es : ∀ j, Ms j ≃* Ns j) : (Pi_congr_right es).symm = (Pi_congr_right $ λ i, (es i).symm) := rfl @[simp] lemma Pi_congr_right_trans {η : Type*} {Ms Ns Ps : η → Type*} [Π j, mul_one_class (Ms j)] [Π j, mul_one_class (Ns j)] [Π j, mul_one_class (Ps j)] (es : ∀ j, Ms j ≃* Ns j) (fs : ∀ j, Ns j ≃* Ps j) : (Pi_congr_right es).trans (Pi_congr_right fs) = (Pi_congr_right $ λ i, (es i).trans (fs i)) := rfl /-! # Groups -/ /-- A multiplicative equivalence of groups preserves inversion. -/ @[simp, 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 end mul_equiv -- We don't use `to_additive` to generate definition because it fails to tell Lean about -- equational lemmas /-- Given a pair of additive monoid homomorphisms `f`, `g` such that `g.comp f = id` and `f.comp g = id`, returns an additive equivalence with `to_fun = f` and `inv_fun = g`. This constructor is useful if the underlying type(s) have specialized `ext` lemmas for additive monoid homomorphisms. -/ def add_monoid_hom.to_add_equiv [add_zero_class M] [add_zero_class N] (f : M →+ N) (g : N →+ M) (h₁ : g.comp f = add_monoid_hom.id _) (h₂ : f.comp g = add_monoid_hom.id _) : M ≃+ N := { to_fun := f, inv_fun := g, left_inv := add_monoid_hom.congr_fun h₁, right_inv := add_monoid_hom.congr_fun h₂, map_add' := f.map_add } /-- Given a pair of monoid homomorphisms `f`, `g` such that `g.comp f = id` and `f.comp g = id`, returns an multiplicative equivalence with `to_fun = f` and `inv_fun = g`. This constructor is useful if the underlying type(s) have specialized `ext` lemmas for monoid homomorphisms. -/ @[to_additive, simps {fully_applied := ff}] def monoid_hom.to_mul_equiv [mul_one_class M] [mul_one_class N] (f : M →* N) (g : N →* M) (h₁ : g.comp f = monoid_hom.id _) (h₂ : f.comp g = monoid_hom.id _) : M ≃* N := { to_fun := f, inv_fun := g, left_inv := monoid_hom.congr_fun h₁, right_inv := monoid_hom.congr_fun h₂, map_mul' := f.map_mul } /-- 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 /-- A group is isomorphic to its group of units. -/ @[to_additive to_add_units "An additive group is isomorphic to its group of additive units"] def to_units [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 } @[simp, to_additive coe_to_add_units] lemma coe_to_units [group G] (g : G) : (to_units g : G) = g := rfl protected lemma group.is_unit {G} [group G] (x : G) : is_unit x := (to_units x).is_unit namespace units @[simp, to_additive] lemma coe_inv [group G] (u : units G) : ↑u⁻¹ = (u⁻¹ : G) := to_units.symm.map_inv u 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 } /-- Left multiplication by a unit of a monoid is a permutation of the underlying type. -/ @[to_additive "Left addition of an additive unit is a permutation of the underlying type.", simps apply {fully_applied := ff}] def mul_left (u : units M) : equiv.perm M := { to_fun := λx, u * x, inv_fun := λx, ↑u⁻¹ * x, left_inv := u.inv_mul_cancel_left, right_inv := u.mul_inv_cancel_left } @[simp, to_additive] lemma mul_left_symm (u : units M) : u.mul_left.symm = u⁻¹.mul_left := equiv.ext $ λ x, rfl /-- Right multiplication by a unit of a monoid is a permutation of the underlying type. -/ @[to_additive "Right addition of an additive unit is a permutation of the underlying type.", simps apply {fully_applied := ff}] def mul_right (u : units M) : equiv.perm M := { to_fun := λx, x * u, inv_fun := λx, x * ↑u⁻¹, left_inv := λ x, mul_inv_cancel_right x u, right_inv := λ x, inv_mul_cancel_right x u } @[simp, to_additive] lemma mul_right_symm (u : units M) : u.mul_right.symm = u⁻¹.mul_right := equiv.ext $ λ x, rfl end units namespace equiv section group variables [group G] /-- Left multiplication in a `group` is a permutation of the underlying type. -/ @[to_additive "Left addition in an `add_group` is a permutation of the underlying type."] protected def mul_left (a : G) : perm G := (to_units a).mul_left @[simp, to_additive] lemma coe_mul_left (a : G) : ⇑(equiv.mul_left a) = (*) a := rfl /-- extra simp lemma that `dsimp` can use. `simp` will never use this. -/ @[simp, nolint simp_nf, to_additive] lemma mul_left_symm_apply (a : G) : ((equiv.mul_left a).symm : G → G) = (*) a⁻¹ := rfl @[simp, to_additive] lemma mul_left_symm (a : G) : (equiv.mul_left a).symm = equiv.mul_left a⁻¹ := ext $ λ x, rfl /-- Right multiplication in a `group` is a permutation of the underlying type. -/ @[to_additive "Right addition in an `add_group` is a permutation of the underlying type."] protected def mul_right (a : G) : perm G := (to_units a).mul_right @[simp, to_additive] lemma coe_mul_right (a : G) : ⇑(equiv.mul_right a) = λ x, x * a := rfl @[simp, to_additive] lemma mul_right_symm (a : G) : (equiv.mul_right a).symm = equiv.mul_right a⁻¹ := ext $ λ x, rfl /-- extra simp lemma that `dsimp` can use. `simp` will never use this. -/ @[simp, nolint simp_nf, to_additive] lemma mul_right_symm_apply (a : G) : ((equiv.mul_right a).symm : G → G) = λ x, x * a⁻¹ := rfl attribute [nolint simp_nf] add_left_symm_apply add_right_symm_apply variable (G) /-- Inversion on a `group` is a permutation of the underlying type. -/ @[to_additive "Negation on an `add_group` is a permutation of the underlying type.", simps apply {fully_applied := ff}] 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 } variable {G} @[simp, to_additive] lemma inv_symm : (equiv.inv G).symm = equiv.inv G := rfl /-- A version of `equiv.mul_left a b⁻¹` that is defeq to `a / b`. -/ @[to_additive /-" A version of `equiv.add_left a (-b)` that is defeq to `a - b`. "-/, simps] protected def div_left (a : G) : G ≃ G := { to_fun := λ b, a / b, inv_fun := λ b, b⁻¹ * a, left_inv := λ b, by simp [div_eq_mul_inv], right_inv := λ b, by simp [div_eq_mul_inv] } @[to_additive] lemma div_left_eq_inv_trans_mul_left (a : G) : equiv.div_left a = (equiv.inv G).trans (equiv.mul_left a) := ext $ λ _, div_eq_mul_inv _ _ /-- A version of `equiv.mul_right a⁻¹ b` that is defeq to `b / a`. -/ @[to_additive /-" A version of `equiv.add_right (-a) b` that is defeq to `b - a`. "-/, simps] protected def div_right (a : G) : G ≃ G := { to_fun := λ b, b / a, inv_fun := λ b, b * a, left_inv := λ b, by simp [div_eq_mul_inv], right_inv := λ b, by simp [div_eq_mul_inv] } @[to_additive] lemma div_right_eq_mul_right_inv (a : G) : equiv.div_right a = equiv.mul_right a⁻¹ := ext $ λ _, div_eq_mul_inv _ _ end group section group_with_zero variables [group_with_zero G] /-- Left multiplication by a nonzero element in a `group_with_zero` is a permutation of the underlying type. -/ @[simps {fully_applied := ff}] protected def mul_left' (a : G) (ha : a ≠ 0) : perm G := { to_fun := λ x, a * x, inv_fun := λ x, a⁻¹ * x, left_inv := λ x, by { dsimp, rw [← mul_assoc, inv_mul_cancel ha, one_mul] }, right_inv := λ x, by { dsimp, rw [← mul_assoc, mul_inv_cancel ha, one_mul] } } /-- Right multiplication by a nonzero element in a `group_with_zero` is a permutation of the underlying type. -/ @[simps {fully_applied := ff}] protected def mul_right' (a : G) (ha : a ≠ 0) : perm G := { to_fun := λ x, x * a, inv_fun := λ x, x * a⁻¹, left_inv := λ x, by { dsimp, rw [mul_assoc, mul_inv_cancel ha, mul_one] }, right_inv := λ x, by { dsimp, rw [mul_assoc, inv_mul_cancel ha, mul_one] } } end group_with_zero end equiv /-- When the group is commutative, `equiv.inv` is a `mul_equiv`. There is a variant of this `mul_equiv.inv' G : G ≃* Gᵒᵖ` for the non-commutative case. -/ @[to_additive "When the `add_group` is commutative, `equiv.neg` is an `add_equiv`."] def mul_equiv.inv (G : Type*) [comm_group G] : G ≃* G := { to_fun := has_inv.inv, inv_fun := has_inv.inv, map_mul' := mul_inv, ..equiv.inv G} section type_tags /-- Reinterpret `G ≃+ H` as `multiplicative G ≃* multiplicative H`. -/ def add_equiv.to_multiplicative [add_zero_class G] [add_zero_class H] : (G ≃+ H) ≃ (multiplicative G ≃* multiplicative H) := { to_fun := λ f, ⟨f.to_add_monoid_hom.to_multiplicative, f.symm.to_add_monoid_hom.to_multiplicative, f.3, f.4, f.5⟩, inv_fun := λ f, ⟨f.to_monoid_hom, f.symm.to_monoid_hom, f.3, f.4, f.5⟩, left_inv := λ x, by { ext, refl, }, right_inv := λ x, by { ext, refl, }, } /-- Reinterpret `G ≃* H` as `additive G ≃+ additive H`. -/ def mul_equiv.to_additive [mul_one_class G] [mul_one_class H] : (G ≃* H) ≃ (additive G ≃+ additive H) := { to_fun := λ f, ⟨f.to_monoid_hom.to_additive, f.symm.to_monoid_hom.to_additive, f.3, f.4, f.5⟩, inv_fun := λ f, ⟨f.to_add_monoid_hom, f.symm.to_add_monoid_hom, f.3, f.4, f.5⟩, left_inv := λ x, by { ext, refl, }, right_inv := λ x, by { ext, refl, }, } /-- Reinterpret `additive G ≃+ H` as `G ≃* multiplicative H`. -/ def add_equiv.to_multiplicative' [mul_one_class G] [add_zero_class H] : (additive G ≃+ H) ≃ (G ≃* multiplicative H) := { to_fun := λ f, ⟨f.to_add_monoid_hom.to_multiplicative', f.symm.to_add_monoid_hom.to_multiplicative'', f.3, f.4, f.5⟩, inv_fun := λ f, ⟨f.to_monoid_hom, f.symm.to_monoid_hom, f.3, f.4, f.5⟩, left_inv := λ x, by { ext, refl, }, right_inv := λ x, by { ext, refl, }, } /-- Reinterpret `G ≃* multiplicative H` as `additive G ≃+ H` as. -/ def mul_equiv.to_additive' [mul_one_class G] [add_zero_class H] : (G ≃* multiplicative H) ≃ (additive G ≃+ H) := add_equiv.to_multiplicative'.symm /-- Reinterpret `G ≃+ additive H` as `multiplicative G ≃* H`. -/ def add_equiv.to_multiplicative'' [add_zero_class G] [mul_one_class H] : (G ≃+ additive H) ≃ (multiplicative G ≃* H) := { to_fun := λ f, ⟨f.to_add_monoid_hom.to_multiplicative'', f.symm.to_add_monoid_hom.to_multiplicative', f.3, f.4, f.5⟩, inv_fun := λ f, ⟨f.to_monoid_hom, f.symm.to_monoid_hom, f.3, f.4, f.5⟩, left_inv := λ x, by { ext, refl, }, right_inv := λ x, by { ext, refl, }, } /-- Reinterpret `multiplicative G ≃* H` as `G ≃+ additive H` as. -/ def mul_equiv.to_additive'' [add_zero_class G] [mul_one_class H] : (multiplicative G ≃* H) ≃ (G ≃+ additive H) := add_equiv.to_multiplicative''.symm end type_tags
bdd4d1adc6496d55c150e0abbc6ce6d4e976dc5e
618003631150032a5676f229d13a079ac875ff77
/src/algebra/category/Group/limits.lean
0fa7d14d3f192b6c04ff8a9a5c89ab795c900d26
[ "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
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 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.{u}) (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.{u}) : 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.{u}) : 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.{u}) : 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.{u}) (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.{u}) : 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.{u}) : 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.{u} AddCommGroup.{u} := { 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.{u}) := { 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
8b9584bc68d894566801696af03ddf45c811b55b
d7189ea2ef694124821b033e533f18905b5e87ef
/galois/csp/class.lean
0bc06eb3f31ff86e043cd255e2002c5e8468fae3
[ "Apache-2.0" ]
permissive
digama0/lean-protocol-support
eaa7e6f8b8e0d5bbfff1f7f52bfb79a3b11b0f59
cabfa3abedbdd6fdca6e2da6fbbf91a13ed48dda
refs/heads/master
1,625,421,450,627
1,506,035,462,000
1,506,035,462,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
1,047
lean
universe variable u namespace csp -- | This defines the monad process class for messages. -- -- Defined as a class so that components can depend on this. class has_send_receive (msg_t : Type) (m : Type → Type u) := (send : msg_t → m unit) (receive : Π (guard : msg_t → bool), m (psigma (λ(m : msg_t), guard m = tt))) @[reducible] def send {msg_t : Type} {m :Type → Type u} [has_send_receive msg_t m] : msg_t → m unit := has_send_receive.send m @[reducible] def receive {msg_t : Type} {m :Type → Type u} [has_send_receive msg_t m] (guard : msg_t → bool) : m (psigma (λ(m : msg_t), guard m = tt)) := has_send_receive.receive m guard -- Define state_t transformation for has_send_receive instance state_t_has_send_receive (s : Type) (msg_t : Type) (m : Type → Type) [monad m] [has_send_receive msg_t m] : has_send_receive msg_t (state_t s m) := { send := λ(msg : msg_t), state_t.lift $ send msg , receive := λ(guard : msg_t → bool), state_t.lift $ receive guard } end csp
37c128ddb846ecd5f1854eb1b63cea6817e1222f
957a80ea22c5abb4f4670b250d55534d9db99108
/tests/lean/run/calc_auto_trans_eq.lean
bc39e13752c68ebabad9aa92d66dfeb60d75861d
[ "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
513
lean
constant R : Π {A : Type}, A → A → Prop infix `~` := R example {A : Type} {a b c d : list nat} (H₁ : a ~ b) (H₂ : b = c) (H₃ : c = d) : a ~ d := calc a ~ b : H₁ ... = c : H₂ ... = d : H₃ example {A : Type} {a b c d : list nat} (H₁ : a = b) (H₂ : b = c) (H₃ : c ~ d) : a ~ d := calc a = b : H₁ ... = c : H₂ ... ~ d : H₃ example {A : Type} {a b c d : list nat} (H₁ : a = b) (H₂ : b ~ c) (H₃ : c = d) : a ~ d := calc a = b : H₁ ... ~ c : H₂ ... = d : H₃
9a00481c4e751eb088e0d4c3fcac39483e8d7cec
b7f22e51856f4989b970961f794f1c435f9b8f78
/tests/lean/run/constr_tac4.lean
e3a62d79a89f8c6fa5e556beb71fda0a32b9c83f
[ "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
567
lean
import data.nat open nat namespace foo definition lt.trans {a b c : nat} (H₁ : a < b) (H₂ : b < c) : a < c := have aux : a < b → a < c, from le.rec_on H₂ (λ h₁, lt.step h₁) (λ b₁ bb₁ ih h₁, by constructor; exact ih h₁), aux H₁ definition succ_lt_succ {a b : nat} (H : a < b) : succ a < succ b := le.rec_on H (by constructor) (λ b hlt ih, lt.trans ih (by constructor)) definition lt_of_succ_lt {a b : nat} (H : succ a < b) : a < b := le.rec_on H (by constructor; constructor) (λ b h ih, by constructor; exact ih) end foo
324fd012d3a355d0d0b89c6eb99d048f08197a4e
cf39355caa609c0f33405126beee2739aa3cb77e
/tests/lean/pp_numeral_types.lean
8381057a7ff25ee6a0cc3616d34f3986877e2832
[ "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
507
lean
local attribute [pp_numeral_type] fin #check (17 : fin 22) local attribute [pp_numeral_type] nat #check (17 : fin 22) #check nat.zero.succ.succ.succ set_option pp.numeral_types true #check 2 + 1 = 3 #check (17 : fin 22) #check 3 #check nat.zero.succ.succ.succ set_option pp.all true #check 3 #check nat.zero.succ.succ.succ set_option pp.all false set_option pp.nat_numerals false set_option pp.numeral_types false local attribute [-pp_numeral_type] nat #check 3 #check nat.zero.succ.succ.succ
99a123bc89c58394e0ddc65fc8394de11883d414
4727251e0cd73359b15b664c3170e5d754078599
/src/topology/sheaves/sheaf_condition/opens_le_cover.lean
56b72565bbdddacf2e14b4ccea7a68587d32de6d
[ "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
13,936
lean
/- Copyright (c) 2020 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import topology.sheaves.presheaf import category_theory.limits.final import topology.sheaves.sheaf_condition.pairwise_intersections /-! # Another version of the sheaf condition. Given a family of open sets `U : ι → opens X` we can form the subcategory `{ V : opens X // ∃ i, V ≤ U i }`, which has `supr U` as a cocone. The sheaf condition on a presheaf `F` is equivalent to `F` sending the opposite of this cocone to a limit cone in `C`, for every `U`. This condition is particularly nice when checking the sheaf condition because we don't need to do any case bashing (depending on whether we're looking at single or double intersections, or equivalently whether we're looking at the first or second object in an equalizer diagram). ## References * This is the definition Lurie uses in [Spectral Algebraic Geometry][LurieSAG]. -/ universes v u noncomputable theory open category_theory open category_theory.limits open topological_space open opposite open topological_space.opens namespace Top variables {C : Type u} [category.{v} C] variables {X : Top.{v}} (F : presheaf C X) {ι : Type v} (U : ι → opens X) namespace presheaf namespace sheaf_condition /-- The category of open sets contained in some element of the cover. -/ def opens_le_cover : Type v := { V : opens X // ∃ i, V ≤ U i } instance [inhabited ι] : inhabited (opens_le_cover U) := ⟨⟨⊥, default, bot_le⟩⟩ instance : category (opens_le_cover U) := category_theory.full_subcategory _ namespace opens_le_cover variables {U} /-- An arbitrarily chosen index such that `V ≤ U i`. -/ def index (V : opens_le_cover U) : ι := V.property.some /-- The morphism from `V` to `U i` for some `i`. -/ def hom_to_index (V : opens_le_cover U) : V.val ⟶ U (index V) := (V.property.some_spec).hom end opens_le_cover /-- `supr U` as a cocone over the opens sets contained in some element of the cover. (In fact this is a colimit cocone.) -/ def opens_le_cover_cocone : cocone (full_subcategory_inclusion _ : opens_le_cover U ⥤ opens X) := { X := supr U, ι := { app := λ V : opens_le_cover U, V.hom_to_index ≫ opens.le_supr U _, } } end sheaf_condition open sheaf_condition /-- An equivalent formulation of the sheaf condition (which we prove equivalent to the usual one below as `is_sheaf_iff_is_sheaf_opens_le_cover`). A presheaf is a sheaf if `F` sends the cone `(opens_le_cover_cocone U).op` to a limit cone. (Recall `opens_le_cover_cocone U`, has cone point `supr U`, mapping down to any `V` which is contained in some `U i`.) -/ def is_sheaf_opens_le_cover : Prop := ∀ ⦃ι : Type v⦄ (U : ι → opens X), nonempty (is_limit (F.map_cone (opens_le_cover_cocone U).op)) namespace sheaf_condition open category_theory.pairwise /-- Implementation detail: the object level of `pairwise_to_opens_le_cover : pairwise ι ⥤ opens_le_cover U` -/ @[simp] def pairwise_to_opens_le_cover_obj : pairwise ι → opens_le_cover U | (single i) := ⟨U i, ⟨i, le_rfl⟩⟩ | (pair i j) := ⟨U i ⊓ U j, ⟨i, inf_le_left⟩⟩ open category_theory.pairwise.hom /-- Implementation detail: the morphism level of `pairwise_to_opens_le_cover : pairwise ι ⥤ opens_le_cover U` -/ def pairwise_to_opens_le_cover_map : Π {V W : pairwise ι}, (V ⟶ W) → (pairwise_to_opens_le_cover_obj U V ⟶ pairwise_to_opens_le_cover_obj U W) | _ _ (id_single i) := 𝟙 _ | _ _ (id_pair i j) := 𝟙 _ | _ _ (left i j) := hom_of_le inf_le_left | _ _ (right i j) := hom_of_le inf_le_right /-- The category of single and double intersections of the `U i` maps into the category of open sets below some `U i`. -/ @[simps] def pairwise_to_opens_le_cover : pairwise ι ⥤ opens_le_cover U := { obj := pairwise_to_opens_le_cover_obj U, map := λ V W i, pairwise_to_opens_le_cover_map U i, } instance (V : opens_le_cover U) : nonempty (structured_arrow V (pairwise_to_opens_le_cover U)) := ⟨{ right := single (V.index), hom := V.hom_to_index }⟩ /-- The diagram consisting of the `U i` and `U i ⊓ U j` is cofinal in the diagram of all opens contained in some `U i`. -/ -- This is a case bash: for each pair of types of objects in `pairwise ι`, -- we have to explicitly construct a zigzag. instance : functor.final (pairwise_to_opens_le_cover U) := ⟨λ V, is_connected_of_zigzag $ λ A B, begin rcases A with ⟨⟨⟩, ⟨i⟩|⟨i,j⟩, a⟩; rcases B with ⟨⟨⟩, ⟨i'⟩|⟨i',j'⟩, b⟩; dsimp at *, { refine ⟨[ { left := punit.star, right := pair i i', hom := (le_inf a.le b.le).hom, }, _], _, rfl⟩, exact list.chain.cons (or.inr ⟨{ left := 𝟙 _, right := left i i', }⟩) (list.chain.cons (or.inl ⟨{ left := 𝟙 _, right := right i i', }⟩) list.chain.nil) }, { refine ⟨[ { left := punit.star, right := pair i' i, hom := (le_inf (b.le.trans inf_le_left) a.le).hom, }, { left := punit.star, right := single i', hom := (b.le.trans inf_le_left).hom, }, _], _, rfl⟩, exact list.chain.cons (or.inr ⟨{ left := 𝟙 _, right := right i' i, }⟩) (list.chain.cons (or.inl ⟨{ left := 𝟙 _, right := left i' i, }⟩) (list.chain.cons (or.inr ⟨{ left := 𝟙 _, right := left i' j', }⟩) list.chain.nil)) }, { refine ⟨[ { left := punit.star, right := single i, hom := (a.le.trans inf_le_left).hom, }, { left := punit.star, right := pair i i', hom := (le_inf (a.le.trans inf_le_left) b.le).hom, }, _], _, rfl⟩, exact list.chain.cons (or.inl ⟨{ left := 𝟙 _, right := left i j, }⟩) (list.chain.cons (or.inr ⟨{ left := 𝟙 _, right := left i i', }⟩) (list.chain.cons (or.inl ⟨{ left := 𝟙 _, right := right i i', }⟩) list.chain.nil)) }, { refine ⟨[ { left := punit.star, right := single i, hom := (a.le.trans inf_le_left).hom, }, { left := punit.star, right := pair i i', hom := (le_inf (a.le.trans inf_le_left) (b.le.trans inf_le_left)).hom, }, { left := punit.star, right := single i', hom := (b.le.trans inf_le_left).hom, }, _], _, rfl⟩, exact list.chain.cons (or.inl ⟨{ left := 𝟙 _, right := left i j, }⟩) (list.chain.cons (or.inr ⟨{ left := 𝟙 _, right := left i i', }⟩) (list.chain.cons (or.inl ⟨{ left := 𝟙 _, right := right i i', }⟩) (list.chain.cons (or.inr ⟨{ left := 𝟙 _, right := left i' j', }⟩) list.chain.nil))), }, end⟩ /-- The diagram in `opens X` indexed by pairwise intersections from `U` is isomorphic (in fact, equal) to the diagram factored through `opens_le_cover U`. -/ def pairwise_diagram_iso : pairwise.diagram U ≅ pairwise_to_opens_le_cover U ⋙ full_subcategory_inclusion _ := { hom := { app := begin rintro (i|⟨i,j⟩); exact 𝟙 _, end, }, inv := { app := begin rintro (i|⟨i,j⟩); exact 𝟙 _, end, }, } /-- The cocone `pairwise.cocone U` with cocone point `supr U` over `pairwise.diagram U` is isomorphic to the cocone `opens_le_cover_cocone U` (with the same cocone point) after appropriate whiskering and postcomposition. -/ def pairwise_cocone_iso : (pairwise.cocone U).op ≅ (cones.postcompose_equivalence (nat_iso.op (pairwise_diagram_iso U : _) : _)).functor.obj ((opens_le_cover_cocone U).op.whisker (pairwise_to_opens_le_cover U).op) := cones.ext (iso.refl _) (by tidy) end sheaf_condition open sheaf_condition /-- The sheaf condition in terms of a limit diagram over all `{ V : opens X // ∃ i, V ≤ U i }` is equivalent to the reformulation in terms of a limit diagram over `U i` and `U i ⊓ U j`. -/ lemma is_sheaf_opens_le_cover_iff_is_sheaf_pairwise_intersections (F : presheaf C X) : F.is_sheaf_opens_le_cover ↔ F.is_sheaf_pairwise_intersections := forall₂_congr $ λ ι U, equiv.nonempty_congr $ calc is_limit (F.map_cone (opens_le_cover_cocone U).op) ≃ is_limit ((F.map_cone (opens_le_cover_cocone U).op).whisker (pairwise_to_opens_le_cover U).op) : (functor.initial.is_limit_whisker_equiv (pairwise_to_opens_le_cover U).op _).symm ... ≃ is_limit (F.map_cone ((opens_le_cover_cocone U).op.whisker (pairwise_to_opens_le_cover U).op)) : is_limit.equiv_iso_limit F.map_cone_whisker.symm ... ≃ is_limit ((cones.postcompose_equivalence _).functor.obj (F.map_cone ((opens_le_cover_cocone U).op.whisker (pairwise_to_opens_le_cover U).op))) : (is_limit.postcompose_hom_equiv _ _).symm ... ≃ is_limit (F.map_cone ((cones.postcompose_equivalence _).functor.obj ((opens_le_cover_cocone U).op.whisker (pairwise_to_opens_le_cover U).op))) : is_limit.equiv_iso_limit (functor.map_cone_postcompose_equivalence_functor _).symm ... ≃ is_limit (F.map_cone (pairwise.cocone U).op) : is_limit.equiv_iso_limit ((cones.functoriality _ _).map_iso (pairwise_cocone_iso U : _).symm) section variables {Y : opens X} (hY : Y = supr U) /-- Given a family of opens `U` and an open `Y` equal to the union of opens in `U`, we may take the presieve on `Y` associated to `U` and the sieve generated by it, and form the full subcategory (subposet) of opens contained in `Y` (`over Y`) consisting of arrows in the sieve. This full subcategory is equivalent to `opens_le_cover U`, the (poset) category of opens contained in some `U i`. -/ @[simps] def generate_equivalence_opens_le : {f : over Y // (sieve.generate (presieve_of_covering_aux U Y)).arrows f.hom} ≌ opens_le_cover U := { functor := { obj := λ f, ⟨f.1.left, let ⟨_,h,_,⟨i,hY⟩,_⟩ := f.2 in ⟨i, hY ▸ h.le⟩⟩, map := λ _ _ g, g.left }, inverse := { obj := λ V, ⟨over.mk (hY.substr (let ⟨i,h⟩ := V.2 in h.trans (le_supr U i))).hom, let ⟨i,h⟩ := V.2 in ⟨U i, h.hom, (hY.substr (le_supr U i)).hom, ⟨i, rfl⟩, rfl⟩⟩, map := λ _ _ g, over.hom_mk g }, unit_iso := eq_to_iso $ category_theory.functor.ext (by {rintro ⟨⟨_,_⟩,_⟩, dsimp, congr; ext}) (by {intros, ext}), counit_iso := eq_to_iso $ category_theory.functor.hext (by {intro, ext, refl}) (by {intros, refl}) } /-- Given a family of opens `opens_le_cover_cocone U` is essentially the natural cocone associated to the sieve generated by the presieve associated to `U` with indexing category changed using the above equivalence. -/ @[simps] def whisker_iso_map_generate_cocone : cone.whisker (generate_equivalence_opens_le U hY).op.functor (F.map_cone (opens_le_cover_cocone U).op) ≅ F.map_cone (sieve.generate (presieve_of_covering_aux U Y)).arrows.cocone.op := { hom := { hom := F.map (eq_to_hom (congr_arg op hY.symm)), w' := λ j, by { erw ← F.map_comp, congr } }, inv := { hom := F.map (eq_to_hom (congr_arg op hY)), w' := λ j, by { erw ← F.map_comp, congr } }, hom_inv_id' := by { ext, simp }, inv_hom_id' := by { ext, simp } } /-- Given a presheaf `F` on the topological space `X` and a family of opens `U` of `X`, the natural cone associated to `F` and `U` used in the definition of `F.is_sheaf_opens_le_cover` is a limit cone iff the natural cone associated to `F` and the sieve generated by the presieve associated to `U` is a limit cone. -/ def is_limit_opens_le_equiv_generate₁ : is_limit (F.map_cone (opens_le_cover_cocone U).op) ≃ is_limit (F.map_cone (sieve.generate (presieve_of_covering_aux U Y)).arrows.cocone.op) := (is_limit.whisker_equivalence_equiv (generate_equivalence_opens_le U hY).op).trans (is_limit.equiv_iso_limit (whisker_iso_map_generate_cocone F U hY)) /-- Given a presheaf `F` on the topological space `X` and a presieve `R` whose generated sieve is covering for the associated Grothendieck topology (equivalently, the presieve is covering for the associated pretopology), the natural cone associated to `F` and the family of opens associated to `R` is a limit cone iff the natural cone associated to `F` and the generated sieve is a limit cone. Since only the existence of a 1-1 correspondence will be used, the exact definition does not matter, so tactics are used liberally. -/ def is_limit_opens_le_equiv_generate₂ (R : presieve Y) (hR : sieve.generate R ∈ opens.grothendieck_topology X Y) : is_limit (F.map_cone (opens_le_cover_cocone (covering_of_presieve Y R)).op) ≃ is_limit (F.map_cone (sieve.generate R).arrows.cocone.op) := begin convert is_limit_opens_le_equiv_generate₁ F (covering_of_presieve Y R) (covering_of_presieve.supr_eq_of_mem_grothendieck Y R hR).symm using 2; rw covering_presieve_eq_self R, end /-- A presheaf `(opens X)ᵒᵖ ⥤ C` on a topological space `X` is a sheaf on the site `opens X` iff it satisfies the `is_sheaf_opens_le_cover` sheaf condition. The latter is not the official definition of sheaves on spaces, but has the advantage that it does not require `has_products C`. -/ lemma is_sheaf_sites_iff_is_sheaf_opens_le_cover : category_theory.presheaf.is_sheaf (opens.grothendieck_topology X) F ↔ F.is_sheaf_opens_le_cover := begin rw presheaf.is_sheaf_iff_is_limit, split, { intros h ι U, rw (is_limit_opens_le_equiv_generate₁ F U rfl).nonempty_congr, apply h, apply presieve_of_covering.mem_grothendieck_topology }, { intros h Y S, rw ← sieve.generate_sieve S, intro hS, rw ← (is_limit_opens_le_equiv_generate₂ F S hS).nonempty_congr, apply h }, end end variable [has_products C] /-- The sheaf condition in terms of an equalizer diagram is equivalent to the reformulation in terms of a limit diagram over all `{ V : opens X // ∃ i, V ≤ U i }`. -/ lemma is_sheaf_iff_is_sheaf_opens_le_cover (F : presheaf C X) : F.is_sheaf ↔ F.is_sheaf_opens_le_cover := iff.trans (is_sheaf_iff_is_sheaf_pairwise_intersections F) (is_sheaf_opens_le_cover_iff_is_sheaf_pairwise_intersections F).symm end presheaf end Top
59f20f02ad0a1c0d41062b5834fc022fe6ed778f
dd0f5513e11c52db157d2fcc8456d9401a6cd9da
/11_Tactic-Style_Proofs.org.4.lean
25a90bb861430f49319523d6f19d7cf50079ddb3
[]
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
151
lean
import standard -- BEGIN theorem test (p q : Prop) (Hp : p) (Hq : q) : p ∧ q ∧ p := begin apply (and.intro Hp), exact (and.intro Hq Hp) end -- END
d956af22f65e6aa571d74215164aa600f39836c7
86f6f4f8d827a196a32bfc646234b73328aeb306
/examples/sets_functions_and_relations/unnamed_178.lean
afc2ebdbb0c0f55be9173608c443c1772ec91572
[]
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
238
lean
import tactic variable {α : Type*} variables (s t u : set α) -- BEGIN example : s ∩ (t ∪ u) ⊆ (s ∩ t) ∪ (s ∩ u) := begin rintros x ⟨xs, xt | xu⟩, { left, exact ⟨xs, xt⟩ }, right, exact ⟨xs, xu⟩ end -- END
3d162306e173e216af0b04f7499a04f214550f26
54c9ed381c63410c9b6af3b0a1722c41152f037f
/experiments/delaborate/Delaborate.lean
1b6d5cff36d3689331205fd3a7b92649ef5daddf
[ "Apache-2.0" ]
permissive
dselsam/binport
0233f1aa961a77c4fc96f0dccc780d958c5efc6c
aef374df0e169e2c3f1dc911de240c076315805c
refs/heads/master
1,687,453,448,108
1,627,483,296,000
1,627,483,296,000
333,825,622
0
0
null
null
null
null
UTF-8
Lean
false
false
6,501
lean
/- Copyright (c) 2021 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Daniel Selsam -/ import Lean import Std.Data.HashSet open Lean Lean.Meta Lean.Elab.Term open Std (HashSet mkHashSet) def Lean.MessageLog.getErrorMessages (log : MessageLog) : MessageLog := { msgs := log.msgs.filter fun m => match m.severity with | MessageSeverity.error => true | _ => false } namespace DelaborateExperiment def BLACK_LIST : HashSet Name := (({} : HashSet Name).insert `Mathlib.CommRing.colimits.relation.casesOn).insert `Mathlib.Mon.colimits.relation.casesOn inductive DelaborateResult where | success : DelaborateResult | failedToElaborate : DelaborateResult | sorryAx : DelaborateResult | nonDefEq : DelaborateResult | timeout : DelaborateResult | other : DelaborateResult deriving Inhabited instance : ToString DelaborateResult := ⟨fun | DelaborateResult.success => "success" | DelaborateResult.failedToElaborate => "failedToElaborate" | DelaborateResult.sorryAx => "sorryAx" | DelaborateResult.nonDefEq => "nonDefEq" | DelaborateResult.timeout => "timeout" | DelaborateResult.other => "other" ⟩ structure DataPoint where declName : Name inType : Bool result : DelaborateResult abbrev Job := Task (Except IO.Error (Array DataPoint)) instance : Inhabited Job := ⟨⟨pure #[]⟩⟩ structure Context where structure State where datapoints : Array DataPoint := #[] abbrev DelaborateExperimentM := ReaderT Context (StateRefT State MetaM) def emit (datapoint : DataPoint) : DelaborateExperimentM Unit := modify fun s => { s with datapoints := s.datapoints.push datapoint } def elabCtx : Lean.Elab.Term.Context := { fileName := "<no-file>" fileMap := FileMap.ofString "code panics if there is nothing here" } inductive ElabResult where | term : Expr → ElabResult | errors : List Message → ElabResult def checkExpr (declName : Name) (levelNames : List Name) (inType : Bool) (e : Expr) : DelaborateExperimentM Unit := do -- Notes: -- - declName.getPrefix is also the currentNamespace passed to CoreM -- - the pretty printing options are declared in `withEnvOpts` below -- - (by default, pp.all is set to true) -- TODO: huh? why the errors without the braces? try { let type ← inferType e let stx ← Lean.PrettyPrinter.delab declName.getPrefix [] e let elabResult ← TermElabM.run' (ctx := elabCtx) (s := { levelNames := levelNames}) $ do let e' ← elabTermAndSynthesize stx (some type) if (← get).messages.hasErrors then ElabResult.errors $ (← get).messages.getErrorMessages.toList else ElabResult.term e' match elabResult with | ElabResult.errors errs => let f' ← PrettyPrinter.ppTerm stx let s := f'.pretty' -- println! "[warn:elab:{declName}]\nSyntax:\n{s}\n" -- for err in errs do println! "[warn:elab:{declName}] {← err.data.toString}" emit { declName := declName, inType := inType, result := DelaborateResult.failedToElaborate } | ElabResult.term e' => do match ← isDefEq e e' with | true => emit { declName := declName, inType := inType, result := DelaborateResult.success } | false => emit { declName := declName, inType := inType, result := DelaborateResult.nonDefEq } } catch ex => { -- println! "[warn:other:{declName}] {← ex.toMessageData.toString}"; emit { declName := declName, inType := inType, result := DelaborateResult.other } } def checkConstant (env : Environment) (opts : Options) (cinfo : ConstantInfo) : IO (Array DataPoint) := do -- Note: currNamespace is the prefix of the constant's name. -- This is also the namespace we pass to delab let ((_, s), _, _) ← MetaM.toIO ((core.run {}).run {}) { options := opts, currNamespace := cinfo.name.getPrefix } { env := env } pure s.datapoints where core : DelaborateExperimentM (Array DataPoint) := do checkExpr cinfo.name cinfo.levelParams true cinfo.type match cinfo.value? with | some value => pure () -- TODO: checkExpr cinfo.name false value | _ => pure () (← get).datapoints def runDelaborateExperiment (env : Environment) (opts : Options) : IO Unit := do let jobs ← env.constants.map₁.foldM (init := #[]) collectJobs let jobs ← env.constants.map₂.foldlM (init := jobs) collectJobs IO.FS.withFile "results.csv" IO.FS.Mode.write fun handle => do println! "-- waiting for {jobs.size} jobs --" let mut i := 0 for (declName, job) in jobs do println! "[{i}] {declName}" (← IO.getStdout).flush i := i + 1 match ← IO.wait job with | Except.ok datapoints => dumpResults handle datapoints | Except.error err => pure () -- println! "[warn:task] {err}" where collectJobs (jobs : Array (Name × Job)) (name : Name) (cinfo : ConstantInfo) : IO (Array (Name × Job)) := do -- if !jobs.isEmpty then return jobs if BLACK_LIST.contains name then return jobs if isPrivateName name then return jobs if name.isInternal then return jobs if not ((`Mathlib).isPrefixOf name) then return jobs jobs.push (name, ← IO.asTask $ checkConstant env opts cinfo) dumpResults handle datapoints := do for ⟨declName, inType, result⟩ in datapoints do handle.putStr s!"{declName} {toString inType} {toString result}\n" end DelaborateExperiment open DelaborateExperiment unsafe def withEnvOpts {α : Type} (f : Environment → Options → IO α) : IO α := do let imports := [{ module := `Init : Import }, { module := `Mathlib : Import }] let some LEAN_PATH ← IO.getEnv "LEAN_PATH" | throw (IO.userError "LEAN_PATH not set") initSearchPath LEAN_PATH let opts : Options := {} let opts : Options := opts.insert `pp.all (DataValue.ofBool true) let opts : Options := opts.insert `pp.binder_types (DataValue.ofBool true) -- let opts : Options := opts.insert `synthInstance.maxHeartbeats (DataValue.ofNat 50000) let imports : List Import := [ { module := `Init : Import }, -- { module := `PrePort : Import }, -- { module := `Lean3Lib.all : Import } { module := `Mathlib : Import } -- { module := `PostPort : Import } ] withImportModules imports (opts := opts) (trustLevel := 0) fun env => f env opts unsafe def main : IO Unit := withEnvOpts runDelaborateExperiment
0e7d237b7ea57877cfe1313ce3147a644d99cc7a
26ac254ecb57ffcb886ff709cf018390161a9225
/src/linear_algebra/direct_sum_module.lean
473074a13ad699f616c7e186b1faf66af1ec8cd8
[ "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,808
lean
/- Copyright (c) 2018 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau Direct sum of modules over commutative rings, indexed by a discrete type. -/ import algebra.direct_sum import linear_algebra.basic /-! # Direct sum of modules over commutative rings, indexed by a discrete type. This file provides constructors for finite direct sums of modules. It provides a construction of the direct sum using the universal property and proves its uniqueness. ## Implementation notes All of this file assumes that * `R` is a commutative ring, * `ι` is a discrete type, * `S` is a finite set in `ι`, * `M` is a family of `R` semimodules indexed over `ι`. -/ universes u v w u₁ variables (R : Type u) [semiring R] variables (ι : Type v) [decidable_eq ι] (M : ι → Type w) variables [Π i, add_comm_group (M i)] [Π i, semimodule R (M i)] include R namespace direct_sum variables {R ι M} instance : semimodule R (direct_sum ι M) := dfinsupp.to_semimodule variables R ι M /-- Create the direct sum given a family `M` of `R` semimodules indexed over `ι`. -/ def lmk : Π s : finset ι, (Π i : (↑s : set ι), M i.val) →ₗ[R] direct_sum ι M := dfinsupp.lmk M R /-- Inclusion of each component into the direct sum. -/ def lof : Π i : ι, M i →ₗ[R] direct_sum ι M := dfinsupp.lsingle M R variables {ι M} lemma single_eq_lof (i : ι) (b : M i) : dfinsupp.single i b = lof R ι M i b := rfl /-- Scalar multiplication commutes with direct sums. -/ theorem mk_smul (s : finset ι) (c : R) (x) : mk M s (c • x) = c • mk M s x := (lmk R ι M s).map_smul c x /-- Scalar multiplication commutes with the inclusion of each component into the direct sum. -/ theorem of_smul (i : ι) (c : R) (x) : of M i (c • x) = c • of M i x := (lof R ι M i).map_smul c x variables {N : Type u₁} [add_comm_group N] [semimodule R N] variables (φ : Π i, M i →ₗ[R] N) variables (ι N φ) /-- The linear map constructed using the universal property of the coproduct. -/ def to_module : direct_sum ι M →ₗ[R] N := { to_fun := to_group (λ i, φ i), map_add' := to_group_add _, map_smul' := λ c x, direct_sum.induction_on x (by rw [smul_zero, to_group_zero, smul_zero]) (λ i x, by rw [← of_smul, to_group_of, to_group_of, (φ i).map_smul c x]) (λ x y ihx ihy, by rw [smul_add, to_group_add, ihx, ihy, to_group_add, smul_add]) } variables {ι N φ} /-- The map constructed using the universal property gives back the original maps when restricted to each component. -/ @[simp] lemma to_module_lof (i) (x : M i) : to_module R ι N φ (lof R ι M i x) = φ i x := to_group_of (λ i, φ i) i x variables (ψ : direct_sum ι M →ₗ[R] N) /-- Every linear map from a direct sum agrees with the one obtained by applying the universal property to each of its components. -/ theorem to_module.unique (f : direct_sum ι M) : ψ f = to_module R ι N (λ i, ψ.comp $ lof R ι M i) f := to_group.unique ψ f variables {ψ} {ψ' : direct_sum ι M →ₗ[R] N} theorem to_module.ext (H : ∀ i, ψ.comp (lof R ι M i) = ψ'.comp (lof R ι M i)) (f : direct_sum ι M) : ψ f = ψ' f := by rw [to_module.unique R ψ, to_module.unique R ψ', funext H] /-- The inclusion of a subset of the direct summands into a larger subset of the direct summands, as a linear map. -/ def lset_to_set (S T : set ι) (H : S ⊆ T) : direct_sum S (M ∘ subtype.val) →ₗ direct_sum T (M ∘ subtype.val) := to_module R _ _ $ λ i, lof R T (M ∘ @subtype.val _ T) ⟨i.1, H i.2⟩ protected def lid (M : Type v) [add_comm_group M] [semimodule R M] : direct_sum punit (λ _, M) ≃ₗ M := { .. direct_sum.id M, .. to_module R punit M (λ i, linear_map.id) } variables (ι M) /-- The projection map onto one component, as a linear map. -/ def component (i : ι) : direct_sum ι M →ₗ[R] M i := { to_fun := λ f, f i, map_add' := λ _ _, dfinsupp.add_apply, map_smul' := λ _ _, dfinsupp.smul_apply } variables {ι M} @[simp] lemma lof_apply (i : ι) (b : M i) : ((lof R ι M i) b) i = b := by rw [lof, dfinsupp.lsingle_apply, dfinsupp.single_apply, dif_pos rfl] lemma apply_eq_component (f : direct_sum ι M) (i : ι) : f i = component R ι M i f := rfl @[simp] lemma component.lof_self (i : ι) (b : M i) : component R ι M i ((lof R ι M i) b) = b := lof_apply R i b lemma component.of (i j : ι) (b : M j) : component R ι M i ((lof R ι M j) b) = if h : j = i then eq.rec_on h b else 0 := dfinsupp.single_apply @[ext] lemma ext {f g : direct_sum ι M} (h : ∀ i, component R ι M i f = component R ι M i g) : f = g := dfinsupp.ext h lemma ext_iff {f g : direct_sum ι M} : f = g ↔ ∀ i, component R ι M i f = component R ι M i g := ⟨λ h _, by rw h, ext R⟩ end direct_sum
f1766786368ef7b908dd1dbaed39d9ccbb946703
618003631150032a5676f229d13a079ac875ff77
/src/algebra/order.lean
13f75d3cdc1493c8745375cd6a743acddc2c8b1a
[ "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
9,514
lean
/- Copyright (c) 2017 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ universe u variables {α : Type u} @[simp] lemma ge_iff_le [preorder α] {a b : α} : a ≥ b ↔ b ≤ a := iff.rfl @[simp] lemma gt_iff_lt [preorder α] {a b : α} : a > b ↔ b < a := iff.rfl lemma not_le_of_lt [preorder α] {a b : α} (h : a < b) : ¬ b ≤ a := (le_not_le_of_lt h).right lemma not_lt_of_le [preorder α] {a b : α} (h : a ≤ b) : ¬ b < a | hab := not_le_of_gt hab h lemma le_iff_eq_or_lt [partial_order α] {a b : α} : a ≤ b ↔ a = b ∨ a < b := le_iff_lt_or_eq.trans or.comm lemma lt_of_le_of_ne' [partial_order α] {a b : α} (h₁ : a ≤ b) (h₂ : a ≠ b) : a < b := lt_of_le_not_le h₁ $ mt (le_antisymm h₁) h₂ lemma lt_iff_le_and_ne [partial_order α] {a b : α} : a < b ↔ a ≤ b ∧ a ≠ b := ⟨λ h, ⟨le_of_lt h, ne_of_lt h⟩, λ ⟨h1, h2⟩, lt_of_le_of_ne h1 h2⟩ lemma eq_iff_le_not_lt [partial_order α] {a b : α} : a = b ↔ a ≤ b ∧ ¬ a < b := ⟨λ h, ⟨le_of_eq h, h ▸ lt_irrefl _⟩, λ ⟨h₁, h₂⟩, le_antisymm h₁ $ classical.by_contradiction $ λ h₃, h₂ (lt_of_le_not_le h₁ h₃)⟩ lemma eq_or_lt_of_le [partial_order α] {a b : α} (h : a ≤ b) : a = b ∨ a < b := (lt_or_eq_of_le h).symm lemma lt_of_not_ge' [linear_order α] {a b : α} (h : ¬ b ≤ a) : a < b := lt_of_le_not_le ((le_total _ _).resolve_right h) h lemma lt_iff_not_ge' [linear_order α] {x y : α} : x < y ↔ ¬ y ≤ x := ⟨not_le_of_gt, lt_of_not_ge'⟩ @[simp] lemma not_lt [linear_order α] {a b : α} : ¬ a < b ↔ b ≤ a := ⟨le_of_not_gt, not_lt_of_ge⟩ lemma le_of_not_lt [linear_order α] {a b : α} : ¬ a < b → b ≤ a := not_lt.1 @[simp] lemma not_le [linear_order α] {a b : α} : ¬ a ≤ b ↔ b < a := lt_iff_not_ge'.symm lemma lt_or_le [linear_order α] : ∀ a b : α, a < b ∨ b ≤ a := lt_or_ge lemma le_or_lt [linear_order α] : ∀ a b : α, a ≤ b ∨ b < a := le_or_gt lemma not_lt_iff_eq_or_lt [linear_order α] {a b : α} : ¬ a < b ↔ a = b ∨ b < a := not_lt.trans $ le_iff_eq_or_lt.trans $ or_congr eq_comm iff.rfl lemma exists_ge_of_linear [linear_order α] (a b : α) : ∃ c, a ≤ c ∧ b ≤ c := match le_total a b with | or.inl h := ⟨_, h, le_refl _⟩ | or.inr h := ⟨_, le_refl _, h⟩ end lemma lt_imp_lt_of_le_imp_le {β} [linear_order α] [preorder β] {a b : α} {c d : β} (H : a ≤ b → c ≤ d) (h : d < c) : b < a := lt_of_not_ge' $ λ h', not_lt_of_ge (H h') h lemma le_imp_le_of_lt_imp_lt {β} [preorder α] [linear_order β] {a b : α} {c d : β} (H : d < c → b < a) (h : a ≤ b) : c ≤ d := le_of_not_gt $ λ h', not_le_of_gt (H h') h lemma le_imp_le_iff_lt_imp_lt {β} [linear_order α] [linear_order β] {a b : α} {c d : β} : (a ≤ b → c ≤ d) ↔ (d < c → b < a) := ⟨lt_imp_lt_of_le_imp_le, le_imp_le_of_lt_imp_lt⟩ lemma lt_iff_lt_of_le_iff_le' {β} [preorder α] [preorder β] {a b : α} {c d : β} (H : a ≤ b ↔ c ≤ d) (H' : b ≤ a ↔ d ≤ c) : b < a ↔ d < c := lt_iff_le_not_le.trans $ (and_congr H' (not_congr H)).trans lt_iff_le_not_le.symm lemma lt_iff_lt_of_le_iff_le {β} [linear_order α] [linear_order β] {a b : α} {c d : β} (H : a ≤ b ↔ c ≤ d) : b < a ↔ d < c := not_le.symm.trans $ iff.trans (not_congr H) $ not_le lemma le_iff_le_iff_lt_iff_lt {β} [linear_order α] [linear_order β] {a b : α} {c d : β} : (a ≤ b ↔ c ≤ d) ↔ (b < a ↔ d < c) := ⟨lt_iff_lt_of_le_iff_le, λ H, not_lt.symm.trans $ iff.trans (not_congr H) $ not_lt⟩ lemma eq_of_forall_le_iff [partial_order α] {a b : α} (H : ∀ c, c ≤ a ↔ c ≤ b) : a = b := le_antisymm ((H _).1 (le_refl _)) ((H _).2 (le_refl _)) lemma le_of_forall_le [preorder α] {a b : α} (H : ∀ c, c ≤ a → c ≤ b) : a ≤ b := H _ (le_refl _) lemma le_of_forall_le' [preorder α] {a b : α} (H : ∀ c, a ≤ c → b ≤ c) : b ≤ a := H _ (le_refl _) lemma le_of_forall_lt [linear_order α] {a b : α} (H : ∀ c, c < a → c < b) : a ≤ b := le_of_not_lt $ λ h, lt_irrefl _ (H _ h) lemma forall_lt_iff_le [linear_order α] {a b : α} : (∀ ⦃c⦄, c < a → c < b) ↔ a ≤ b := ⟨le_of_forall_lt, λ h c hca, lt_of_lt_of_le hca h⟩ lemma le_of_forall_lt' [linear_order α] {a b : α} (H : ∀ c, a < c → b < c) : b ≤ a := le_of_not_lt $ λ h, lt_irrefl _ (H _ h) lemma forall_lt_iff_le' [linear_order α] {a b : α} : (∀ ⦃c⦄, a < c → b < c) ↔ b ≤ a := ⟨le_of_forall_lt', λ h c hac, lt_of_le_of_lt h hac⟩ lemma eq_of_forall_ge_iff [partial_order α] {a b : α} (H : ∀ c, a ≤ c ↔ b ≤ c) : a = b := le_antisymm ((H _).2 (le_refl _)) ((H _).1 (le_refl _)) /-- monotonicity of `≤` with respect to `→` -/ lemma le_implies_le_of_le_of_le {a b c d : α} [preorder α] (h₀ : c ≤ a) (h₁ : b ≤ d) : a ≤ b → c ≤ d := assume h₂ : a ≤ b, calc c ≤ a : h₀ ... ≤ b : h₂ ... ≤ d : h₁ namespace decidable local attribute [instance, priority 10] classical.prop_decidable lemma lt_or_eq_of_le [partial_order α] {a b : α} (hab : a ≤ b) : a < b ∨ a = b := if hba : b ≤ a then or.inr (le_antisymm hab hba) else or.inl (lt_of_le_not_le hab hba) lemma eq_or_lt_of_le [partial_order α] {a b : α} (hab : a ≤ b) : a = b ∨ a < b := (lt_or_eq_of_le hab).swap lemma le_iff_lt_or_eq [partial_order α] {a b : α} : a ≤ b ↔ a < b ∨ a = b := ⟨lt_or_eq_of_le, le_of_lt_or_eq⟩ lemma le_of_not_lt [linear_order α] {a b : α} (h : ¬ b < a) : a ≤ b := decidable.by_contradiction $ λ h', h $ lt_of_le_not_le ((le_total _ _).resolve_right h') h' lemma not_lt [linear_order α] {a b : α} : ¬ a < b ↔ b ≤ a := ⟨le_of_not_lt, not_lt_of_ge⟩ lemma lt_or_le [linear_order α] (a b : α) : a < b ∨ b ≤ a := if hba : b ≤ a then or.inr hba else or.inl $ not_le.1 hba lemma le_or_lt [linear_order α] (a b : α) : a ≤ b ∨ b < a := (lt_or_le b a).swap lemma lt_trichotomy [linear_order α] (a b : α) : a < b ∨ a = b ∨ b < a := (lt_or_le _ _).imp_right $ λ h, (eq_or_lt_of_le h).imp_left eq.symm lemma lt_or_gt_of_ne [linear_order α] {a b : α} (h : a ≠ b) : a < b ∨ b < a := (lt_trichotomy a b).imp_right $ λ h', h'.resolve_left h def lt_by_cases [decidable_linear_order α] (x y : α) {P : Sort*} (h₁ : x < y → P) (h₂ : x = y → P) (h₃ : y < x → P) : P := begin by_cases h : x < y, { exact h₁ h }, by_cases h' : y < x, { exact h₃ h' }, apply h₂, apply le_antisymm; apply le_of_not_gt; assumption end lemma ne_iff_lt_or_gt [linear_order α] {a b : α} : a ≠ b ↔ a < b ∨ b < a := ⟨lt_or_gt_of_ne, λo, o.elim ne_of_lt ne_of_gt⟩ lemma le_imp_le_of_lt_imp_lt {β} [preorder α] [linear_order β] {a b : α} {c d : β} (H : d < c → b < a) (h : a ≤ b) : c ≤ d := le_of_not_lt $ λ h', not_le_of_gt (H h') h lemma le_imp_le_iff_lt_imp_lt {β} [linear_order α] [linear_order β] {a b : α} {c d : β} : (a ≤ b → c ≤ d) ↔ (d < c → b < a) := ⟨lt_imp_lt_of_le_imp_le, le_imp_le_of_lt_imp_lt⟩ lemma le_iff_le_iff_lt_iff_lt {β} [linear_order α] [linear_order β] {a b : α} {c d : β} : (a ≤ b ↔ c ≤ d) ↔ (b < a ↔ d < c) := ⟨lt_iff_lt_of_le_iff_le, λ H, not_lt.symm.trans $ iff.trans (not_congr H) $ not_lt⟩ end decidable namespace ordering /-- `compares o a b` means that `a` and `b` have the ordering relation `o` between them, assuming that the relation `a < b` is defined -/ @[simp] def compares [has_lt α] : ordering → α → α → Prop | lt a b := a < b | eq a b := a = b | gt a b := a > b theorem compares.eq_lt [preorder α] : ∀ {o} {a b : α}, compares o a b → (o = lt ↔ a < b) | lt a b h := ⟨λ _, h, λ _, rfl⟩ | eq a b h := ⟨λ h, by injection h, λ h', (ne_of_lt h' h).elim⟩ | gt a b h := ⟨λ h, by injection h, λ h', (lt_asymm h h').elim⟩ theorem compares.eq_eq [preorder α] : ∀ {o} {a b : α}, compares o a b → (o = eq ↔ a = b) | lt a b h := ⟨λ h, by injection h, λ h', (ne_of_lt h h').elim⟩ | eq a b h := ⟨λ _, h, λ _, rfl⟩ | gt a b h := ⟨λ h, by injection h, λ h', (ne_of_gt h h').elim⟩ theorem compares.eq_gt [preorder α] : ∀ {o} {a b : α}, compares o a b → (o = gt ↔ a > b) | lt a b h := ⟨λ h, by injection h, λ h', (lt_asymm h h').elim⟩ | eq a b h := ⟨λ h, by injection h, λ h', (ne_of_gt h' h).elim⟩ | gt a b h := ⟨λ _, h, λ _, rfl⟩ theorem compares.inj [preorder α] {o₁} : ∀ {o₂} {a b : α}, compares o₁ a b → compares o₂ a b → o₁ = o₂ | lt a b h₁ h₂ := h₁.eq_lt.2 h₂ | eq a b h₁ h₂ := h₁.eq_eq.2 h₂ | gt a b h₁ h₂ := h₁.eq_gt.2 h₂ theorem swap_or_else (o₁ o₂) : (or_else o₁ o₂).swap = or_else o₁.swap o₂.swap := by cases o₁; try {refl}; cases o₂; refl theorem or_else_eq_lt (o₁ o₂) : or_else o₁ o₂ = lt ↔ o₁ = lt ∨ (o₁ = eq ∧ o₂ = lt) := by cases o₁; cases o₂; exact dec_trivial end ordering theorem cmp_compares [decidable_linear_order α] (a b : α) : (cmp a b).compares a b := begin unfold cmp cmp_using, by_cases a < b; simp [h], by_cases h₂ : b < a; simp [h₂, gt], exact (lt_or_eq_of_le (le_of_not_gt h₂)).resolve_left h end theorem cmp_swap [preorder α] [@decidable_rel α (<)] (a b : α) : (cmp a b).swap = cmp b a := begin unfold cmp cmp_using, by_cases a < b; by_cases h₂ : b < a; simp [h, h₂, gt, ordering.swap], exact lt_asymm h h₂ end
270495ecb380b0c9c465ba64d3fdb51d6d43c87a
31f556cdeb9239ffc2fad8f905e33987ff4feab9
/src/Lean/PrettyPrinter.lean
5b8682616ce390ab7a909de1c20acf057c38f459
[ "Apache-2.0", "LLVM-exception", "NCSA", "LGPL-3.0-only", "LicenseRef-scancode-inner-net-2.0", "BSD-3-Clause", "LGPL-2.0-or-later", "Spencer-94", "LGPL-2.1-or-later", "HPND", "LicenseRef-scancode-pcre", "ISC", "LGPL-2.1-only", "LicenseRef-scancode-other-permissive", "SunPro", "CMU-Mach"...
permissive
tobiasgrosser/lean4
ce0fd9cca0feba1100656679bf41f0bffdbabb71
ebdbdc10436a4d9d6b66acf78aae7a23f5bd073f
refs/heads/master
1,673,103,412,948
1,664,930,501,000
1,664,930,501,000
186,870,185
0
0
Apache-2.0
1,665,129,237,000
1,557,939,901,000
Lean
UTF-8
Lean
false
false
4,404
lean
/- Copyright (c) 2020 Sebastian Ullrich. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sebastian Ullrich -/ import Lean.PrettyPrinter.Delaborator import Lean.PrettyPrinter.Parenthesizer import Lean.PrettyPrinter.Formatter import Lean.Parser.Module import Lean.ParserCompiler namespace Lean def PPContext.runCoreM {α : Type} (ppCtx : PPContext) (x : CoreM α) : IO α := Prod.fst <$> x.toIO { options := ppCtx.opts, currNamespace := ppCtx.currNamespace, openDecls := ppCtx.openDecls, fileName := "<PrettyPrinter>", fileMap := default } { env := ppCtx.env, ngen := { namePrefix := `_pp_uniq } } def PPContext.runMetaM {α : Type} (ppCtx : PPContext) (x : MetaM α) : IO α := ppCtx.runCoreM <| x.run' { lctx := ppCtx.lctx } { mctx := ppCtx.mctx } namespace PrettyPrinter def ppCategory (cat : Name) (stx : Syntax) : CoreM Format := do let opts ← getOptions let stx := (sanitizeSyntax stx).run' { options := opts } parenthesizeCategory cat stx >>= formatCategory cat def ppTerm (stx : Term) : CoreM Format := ppCategory `term stx def ppUsing (e : Expr) (delab : Expr → MetaM Term) : MetaM Format := do let lctx := (← getLCtx).sanitizeNames.run' { options := (← getOptions) } Meta.withLCtx lctx #[] do ppTerm (← delab e) def ppExpr (e : Expr) : MetaM Format := do ppUsing e delab /-- Return a `fmt` representing pretty-printed `e` together with a map from tags in `fmt` to `Elab.Info` nodes produced by the delaborator at various subexpressions of `e`. -/ def ppExprWithInfos (e : Expr) (optsPerPos : Delaborator.OptionsPerPos := {}) (delab := Delaborator.delab) : MetaM (Format × RBMap Nat Elab.Info compare) := do let lctx := (← getLCtx).sanitizeNames.run' { options := (← getOptions) } Meta.withLCtx lctx #[] do let (stx, infos) ← delabCore e optsPerPos delab let fmt ← ppTerm stx return (fmt, infos) def ppConst (e : Expr) : MetaM Format := do ppUsing e fun e => return (← delabCore e (delab := Delaborator.delabConst)).1 @[export lean_pp_expr] def ppExprLegacy (env : Environment) (mctx : MetavarContext) (lctx : LocalContext) (opts : Options) (e : Expr) : IO Format := Prod.fst <$> ((ppExpr e).run' { lctx := lctx } { mctx := mctx }).toIO { options := opts, fileName := "<PrettyPrinter>", fileMap := default } { env := env } def ppTactic (stx : TSyntax `tactic) : CoreM Format := ppCategory `tactic stx def ppCommand (stx : Syntax.Command) : CoreM Format := ppCategory `command stx def ppModule (stx : TSyntax ``Parser.Module.module) : CoreM Format := do parenthesize Lean.Parser.Module.module.parenthesizer stx >>= format Lean.Parser.Module.module.formatter private partial def noContext : MessageData → MessageData | MessageData.withContext _ msg => noContext msg | MessageData.withNamingContext ctx msg => MessageData.withNamingContext ctx (noContext msg) | MessageData.nest n msg => MessageData.nest n (noContext msg) | MessageData.group msg => MessageData.group (noContext msg) | MessageData.compose msg₁ msg₂ => MessageData.compose (noContext msg₁) (noContext msg₂) | MessageData.tagged tag msg => MessageData.tagged tag (noContext msg) | MessageData.trace cls header children collapsed => MessageData.trace cls (noContext header) (children.map noContext) collapsed | msg => msg -- strip context (including environments with registered pretty printers) to prevent infinite recursion when pretty printing pretty printer error private def withoutContext {m} [MonadExcept Exception m] (x : m Format) : m Format := tryCatch x fun | Exception.error ref msg => throw <| Exception.error ref (noContext msg) | ex => throw ex builtin_initialize ppFnsRef.set { ppExpr := fun ctx e => ctx.runMetaM <| withoutContext <| ppExpr e, ppTerm := fun ctx stx => ctx.runCoreM <| withoutContext <| ppTerm stx, ppGoal := fun ctx mvarId => ctx.runMetaM <| withoutContext <| Meta.ppGoal mvarId } builtin_initialize registerTraceClass `PrettyPrinter @[builtinInit] unsafe def registerParserCompilers : IO Unit := do ParserCompiler.registerParserCompiler ⟨`parenthesizer, parenthesizerAttribute, combinatorParenthesizerAttribute⟩ ParserCompiler.registerParserCompiler ⟨`formatter, formatterAttribute, combinatorFormatterAttribute⟩ end PrettyPrinter end Lean
e83dc2b2bc70d300a3d4be46a63babcd69bfccfd
60bf3fa4185ec5075eaea4384181bfbc7e1dc319
/src/game/sup_inf/level04.lean
c8564f2bc1b12b6558ea5173877790bb17617c04
[ "Apache-2.0" ]
permissive
anrddh/real-number-game
660f1127d03a78fd35986c771d65c3132c5f4025
c708c4e02ec306c657e1ea67862177490db041b0
refs/heads/master
1,668,214,277,092
1,593,105,075,000
1,593,105,075,000
264,269,218
0
0
null
1,589,567,264,000
1,589,567,264,000
null
UTF-8
Lean
false
false
1,443
lean
import data.real.basic namespace xena -- hide /- # Chapter 3 : Sup and Inf ## Level 4 -/ definition is_upper_bound (S : set ℝ) (x : ℝ) := ∀ s ∈ S, s ≤ x definition is_lub' (S : set ℝ) (x : ℝ) := is_upper_bound S x ∧ ∀ y : ℝ, is_upper_bound S y → x ≤ y definition has_lub (S : set ℝ) := ∃ x, is_lub' S x /- A generalization of the result in the previous level. -/ -- begin hide -- these three helper results to go in sidebar lemma two_real_ne_zero : (2:ℝ) ≠ 0 := begin intro, linarith, end lemma avg_lt_max {mn mx: ℝ} (H : mn < mx) : (mn+mx) / 2 < mx := begin apply (mul_lt_mul_right (show (0:ℝ)<2, by norm_num)).1, rw [div_mul_cancel _ (two_real_ne_zero)], simp [H,mul_two], end lemma min_lt_avg {mn mx: ℝ} (H : mn < mx) : mn < (mn+mx) / 2 := begin apply (mul_lt_mul_right (show (0:ℝ)<2, by norm_num)).1, rw [div_mul_cancel _ (two_real_ne_zero)], simp [H,mul_two], end -- end hide /- Lemma A more general version of the previous level... -/ lemma lub_open (y : ℝ) : is_lub' {x : ℝ | x < y} y := begin split, { intros a ha, exact le_of_lt ha, }, --unfold lower_bounds, intro b, intro Hb, refine le_of_not_gt _, intro Hnb, let c:=(b+y)/2, --unfold upper_bounds at Hb, have H2 := Hb c, clear Hb, have H : c ∈ {x : ℝ | x < y}, { exact avg_lt_max Hnb, }, have Hcleb := H2 H, have Hbltc : b < c := min_lt_avg Hnb, exact not_lt.2 Hcleb Hbltc, end end xena -- hide
d09b31f5c910e13123b080741141aa1fa7438e6b
8cae430f0a71442d02dbb1cbb14073b31048e4b0
/src/analysis/complex/arg.lean
3ca878c0a8de30390da16b757a0b9152ffe3f074
[ "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,088
lean
/- Copyright (c) 2022 Eric Rodriguez. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Rodriguez -/ import analysis.inner_product_space.basic import analysis.special_functions.complex.arg /-! # Rays in the complex numbers > THIS FILE IS SYNCHRONIZED WITH MATHLIB4. > Any changes to this file require a corresponding PR to mathlib4. This file links the definition `same_ray ℝ x y` with the equality of arguments of complex numbers, the usual way this is considered. ## Main statements * `complex.same_ray_iff` : Two complex numbers are on the same ray iff one of them is zero, or they have the same argument. * `complex.abs_add_eq/complex.abs_sub_eq`: If two non zero complex numbers have the same argument, then the triangle inequality is an equality. -/ variables {x y : ℂ} namespace complex lemma same_ray_iff : same_ray ℝ x y ↔ x = 0 ∨ y = 0 ∨ x.arg = y.arg := begin rcases eq_or_ne x 0 with rfl | hx, { simp }, rcases eq_or_ne y 0 with rfl | hy, { simp }, simp only [hx, hy, false_or, same_ray_iff_norm_smul_eq, arg_eq_arg_iff hx hy], field_simp [hx, hy], rw [mul_comm, eq_comm] end lemma same_ray_iff_arg_div_eq_zero : same_ray ℝ x y ↔ arg (x / y) = 0 := begin rw [←real.angle.to_real_zero, ←arg_coe_angle_eq_iff_eq_to_real, same_ray_iff], by_cases hx : x = 0, { simp [hx] }, by_cases hy : y = 0, { simp [hy] }, simp [hx, hy, arg_div_coe_angle, sub_eq_zero] end lemma abs_add_eq_iff : (x + y).abs = x.abs + y.abs ↔ x = 0 ∨ y = 0 ∨ x.arg = y.arg := same_ray_iff_norm_add.symm.trans same_ray_iff lemma abs_sub_eq_iff : (x - y).abs = |x.abs - y.abs| ↔ x = 0 ∨ y = 0 ∨ x.arg = y.arg := same_ray_iff_norm_sub.symm.trans same_ray_iff lemma same_ray_of_arg_eq (h : x.arg = y.arg) : same_ray ℝ x y := same_ray_iff.mpr $ or.inr $ or.inr h lemma abs_add_eq (h : x.arg = y.arg) : (x + y).abs = x.abs + y.abs := (same_ray_of_arg_eq h).norm_add lemma abs_sub_eq (h : x.arg = y.arg) : (x - y).abs = ‖x.abs - y.abs‖ := (same_ray_of_arg_eq h).norm_sub end complex
98aac41a30008471927f593e50d6a782cddb78ad
0d22ec5e0205ec4203aae2ddf07e1f695ff21a61
/src/mv_polynomial_derivations.lean
79a594c128b1a4d3dae8eba26dbeaaa3733ea0f1
[ "Apache-2.0" ]
permissive
shingtaklam1324/step3-06-q8-lean
4611fda6b002797d38d3f625253960dcfeb2a987
20e5161fab8b5c3c2dd051bd707a26f1dc50dac2
refs/heads/master
1,649,936,589,910
1,585,242,273,000
1,585,242,273,000
250,318,324
2
0
Apache-2.0
1,585,389,271,000
1,585,241,690,000
Lean
UTF-8
Lean
false
false
715
lean
import tactic data.mv_polynomial structure mv_polynomial_derivation (R : Type) (S : Type) [comm_ring R] := (to_fun : mv_polynomial S R → mv_polynomial S R) -- Delta (map_add' : ∀ (f g : mv_polynomial S R), to_fun (f + g) = to_fun f + to_fun g) (map_C_mul' : ∀ (k : R) (f : mv_polynomial S R), to_fun (mv_polynomial.C k * f) = mv_polynomial.C k * to_fun f) (map_mul' : ∀ (f g : mv_polynomial S R), to_fun (f * g) = f * to_fun g + g * to_fun f) namespace mv_polynomial_derivation variables {R : Type} [comm_ring R] variable {S : Type} instance : has_coe_to_fun (mv_polynomial_derivation R S) := { F := λ _, mv_polynomial S R → mv_polynomial S R, coe := to_fun } end mv_polynomial_derivation
91e7d7fc53b78eb8c2e3f3f9f4bcadfefe202c20
6fca17f8d5025f89be1b2d9d15c9e0c4b4900cbf
/src/game/world10/level7.lean
211fc01a082c43e7ffb43feaaeb68e5824653f07
[ "Apache-2.0" ]
permissive
arolihas/natural_number_game
4f0c93feefec93b8824b2b96adff8b702b8b43ce
8e4f7b4b42888a3b77429f90cce16292bd288138
refs/heads/master
1,621,872,426,808
1,586,270,467,000
1,586,270,467,000
253,648,466
0
0
null
1,586,219,694,000
1,586,219,694,000
null
UTF-8
Lean
false
false
424
lean
import game.world10.level6 -- hide namespace mynat -- hide /- # Inequality world ## Level 7: `le_zero` We proved `add_right_eq_zero` back in advanced addition world. Note that you can do things like `have h2 := add_right_eq_zero _ _ h1` if `h1 : a + c = 0`. -/ /- Lemma For all naturals $a$, if $a\le 0$ then $a = 0$. -/ lemma le_zero (a : mynat) (h : a ≤ 0) : a = 0 := begin [nat_num_game] end end mynat -- hide
831d4577652baaaf3d9e565b98f9da8ce2519f94
36c7a18fd72e5b57229bd8ba36493daf536a19ce
/library/data/nat/examples/partial_sum.lean
f50793686332a76b6bc0eda64e282afc2aae2b3d
[ "Apache-2.0" ]
permissive
YHVHvx/lean
732bf0fb7a298cd7fe0f15d82f8e248c11db49e9
038369533e0136dd395dc252084d3c1853accbf2
refs/heads/master
1,610,701,080,210
1,449,128,595,000
1,449,128,595,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
1,173
lean
/- Copyright (c) 2015 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Leonardo de Moura -/ import data.nat open nat algebra definition partial_sum : nat → nat | 0 := 0 | (succ n) := succ n + partial_sum n example : partial_sum 5 = 15 := rfl example : partial_sum 6 = 21 := rfl lemma two_mul_partial_sum_eq : ∀ n, 2 * partial_sum n = (succ n) * n | 0 := by reflexivity | (succ n) := calc 2 * (succ n + partial_sum n) = 2 * succ n + 2 * partial_sum n : left_distrib ... = 2 * succ n + succ n * n : two_mul_partial_sum_eq ... = 2 * succ n + n * succ n : mul.comm ... = (2 + n) * succ n : right_distrib ... = (n + 2) * succ n : add.comm ... = (succ (succ n)) * succ n : rfl theorem partial_sum_eq : ∀ n, partial_sum n = ((n + 1) * n) / 2 := take n, assert h₁ : (2 * partial_sum n) / 2 = ((succ n) * n) / 2, by rewrite two_mul_partial_sum_eq, assert h₂ : (2:nat) > 0, from dec_trivial, by rewrite [nat.mul_div_cancel_left _ h₂ at h₁]; exact h₁
28d68fb6130191e07c1beed859caadbada02e958
cf39355caa609c0f33405126beee2739aa3cb77e
/tests/lean/run/blast_unit2.lean
779cb333f7cabcb5c54266c439b2fa1a07bfb8b6
[ "Apache-2.0" ]
permissive
leanprover-community/lean
12b87f69d92e614daea8bcc9d4de9a9ace089d0e
cce7990ea86a78bdb383e38ed7f9b5ba93c60ce0
refs/heads/master
1,687,508,156,644
1,684,951,104,000
1,684,951,104,000
169,960,991
457
107
Apache-2.0
1,686,744,372,000
1,549,790,268,000
C++
UTF-8
Lean
false
false
1,113
lean
variables {A₁ A₂ A₃ A₄ B₁ B₂ B₃ B₄ : Prop} meta def blast : tactic unit := using_smt $ smt_tactic.intros >> return () constants (a b c d e : nat) constants (p : nat → Prop) constants (q : nat → nat → Prop) constants (f : nat → nat) lemma lemma1 : a = d → b = e → p b → (p a → (¬ p e) ∧ p c) → ¬ p d := by blast lemma lemma2a : ¬ p b → (p d → p b ∧ p c) → d = e → e = a → ¬ p a := by blast lemma lemma2b : ¬ p (f b) → (p (f a) → p (f d) ∧ p (f c)) → b = d → ¬ p (f a) := by blast lemma lemma3 : p (f (f b)) → (p (f a) → p (f c) ∧ (¬ p (f (f (f (f b)))))) → b = f b → ¬ p (f a) := by blast lemma lemma4a : b = f b → ¬ p (f (f b)) → (p a → q c c ∧ p (f (f (f (f (f b)))))) → ¬ p a := by blast lemma lemma4b : b = f b → ¬ p (f (f b)) → (p a → q c c ∧ q e c ∧ q d e ∧ p (f (f (f (f (f b))))) ∧ q e d) → ¬ p a := by blast lemma lemma5 : p b → (p (f a) → (¬ p b) ∧ p e ∧ p c) → ¬ p (f a) := by blast lemma lemma6 : ¬ (q b a) → d = a → (p a → p e ∧ (q b d) ∧ p c) → ¬ p a := by blast
51c159e13936138bc5051a345d8c76885c5272c4
4d2583807a5ac6caaffd3d7a5f646d61ca85d532
/src/algebra/category/Mon/filtered_colimits.lean
58b4bd14b1e676588561fcabe8ebc23289284b55
[ "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
14,297
lean
/- Copyright (c) 2021 Justus Springer. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Justus Springer -/ import algebra.category.Mon.basic import category_theory.limits.concrete_category import category_theory.limits.preserves.filtered /-! # The forgetful functor from (commutative) (additive) monoids preserves filtered colimits. Forgetful functors from algebraic categories usually don't preserve colimits. However, they tend to preserve _filtered_ colimits. In this file, we start with a small filtered category `J` and a functor `F : J ⥤ Mon`. We then construct a monoid structure on the colimit of `F ⋙ forget Mon` (in `Type`), thereby showing that the forgetful functor `forget Mon` preserves filtered colimits. Similarly for `AddMon`, `CommMon` and `AddCommMon`. -/ universe v noncomputable theory open_locale classical open category_theory open category_theory.limits open category_theory.is_filtered (renaming max → max') -- avoid name collision with `_root_.max`. namespace Mon.filtered_colimits section -- We use parameters here, mainly so we can have the abbreviations `M` and `M.mk` below, without -- passing around `F` all the time. parameters {J : Type v} [small_category J] (F : J ⥤ Mon.{v}) /-- The colimit of `F ⋙ forget Mon` in the category of types. In the following, we will construct a monoid structure on `M`. -/ @[to_additive "The colimit of `F ⋙ forget AddMon` in the category of types. In the following, we will construct an additive monoid structure on `M`."] abbreviation M : Type v := types.quot (F ⋙ forget Mon) /-- The canonical projection into the colimit, as a quotient type. -/ @[to_additive "The canonical projection into the colimit, as a quotient type."] abbreviation M.mk : (Σ j, F.obj j) → M := quot.mk (types.quot.rel (F ⋙ forget Mon)) @[to_additive] lemma M.mk_eq (x y : Σ j, F.obj j) (h : ∃ (k : J) (f : x.1 ⟶ k) (g : y.1 ⟶ k), F.map f x.2 = F.map g y.2) : M.mk x = M.mk y := quot.eqv_gen_sound (types.filtered_colimit.eqv_gen_quot_rel_of_rel (F ⋙ forget Mon) x y h) variables [is_filtered J] /-- As `J` is nonempty, we can pick an arbitrary object `j₀ : J`. We use this object to define the "one" in the colimit as the equivalence class of `⟨j₀, 1 : F.obj j₀⟩`. -/ @[to_additive "As `J` is nonempty, we can pick an arbitrary object `j₀ : J`. We use this object to define the \"zero\" in the colimit as the equivalence class of `⟨j₀, 0 : F.obj j₀⟩`."] instance colimit_has_one : has_one M := { one := M.mk ⟨is_filtered.nonempty.some, 1⟩ } /-- The definition of the "one" in the colimit is independent of the chosen object of `J`. In particular, this lemma allows us to "unfold" the definition of `colimit_one` at a custom chosen object `j`. -/ @[to_additive "The definition of the \"zero\" in the colimit is independent of the chosen object of `J`. In particular, this lemma allows us to \"unfold\" the definition of `colimit_zero` at a custom chosen object `j`."] lemma colimit_one_eq (j : J) : (1 : M) = M.mk ⟨j, 1⟩ := begin apply M.mk_eq, refine ⟨max' _ j, left_to_max _ j, right_to_max _ j, _⟩, simp, end /-- The "unlifted" version of multiplication in the colimit. To multiply two dependent pairs `⟨j₁, x⟩` and `⟨j₂, y⟩`, we pass to a common successor of `j₁` and `j₂` (given by `is_filtered.max`) and multiply them there. -/ @[to_additive "The \"unlifted\" version of addition in the colimit. To add two dependent pairs `⟨j₁, x⟩` and `⟨j₂, y⟩`, we pass to a common successor of `j₁` and `j₂` (given by `is_filtered.max`) and add them there."] def colimit_mul_aux (x y : Σ j, F.obj j) : M := M.mk ⟨max' x.1 y.1, F.map (left_to_max x.1 y.1) x.2 * F.map (right_to_max x.1 y.1) y.2⟩ /-- Multiplication in the colimit is well-defined in the left argument. -/ @[to_additive "Addition in the colimit is well-defined in the left argument."] lemma colimit_mul_aux_eq_of_rel_left {x x' y : Σ j, F.obj j} (hxx' : types.filtered_colimit.rel (F ⋙ forget Mon) x x') : colimit_mul_aux x y = colimit_mul_aux x' y := begin cases x with j₁ x, cases y with j₂ y, cases x' with j₃ x', obtain ⟨l, f, g, hfg⟩ := hxx', simp at hfg, obtain ⟨s, α, β, γ, h₁, h₂, h₃⟩ := tulip (left_to_max j₁ j₂) (right_to_max j₁ j₂) (right_to_max j₃ j₂) (left_to_max j₃ j₂) f g, apply M.mk_eq, use [s, α, γ], dsimp, simp_rw [monoid_hom.map_mul, ← comp_apply, ← F.map_comp, h₁, h₂, h₃, F.map_comp, comp_apply, hfg] end /-- Multiplication in the colimit is well-defined in the right argument. -/ @[to_additive "Addition in the colimit is well-defined in the right argument."] lemma colimit_mul_aux_eq_of_rel_right {x y y' : Σ j, F.obj j} (hyy' : types.filtered_colimit.rel (F ⋙ forget Mon) y y') : colimit_mul_aux x y = colimit_mul_aux x y' := begin cases y with j₁ y, cases x with j₂ x, cases y' with j₃ y', obtain ⟨l, f, g, hfg⟩ := hyy', simp at hfg, obtain ⟨s, α, β, γ, h₁, h₂, h₃⟩ := tulip (right_to_max j₂ j₁) (left_to_max j₂ j₁) (left_to_max j₂ j₃) (right_to_max j₂ j₃) f g, apply M.mk_eq, use [s, α, γ], dsimp, simp_rw [monoid_hom.map_mul, ← comp_apply, ← F.map_comp, h₁, h₂, h₃, F.map_comp, comp_apply, hfg] end /-- Multiplication in the colimit. See also `colimit_mul_aux`. -/ @[to_additive "Addition in the colimit. See also `colimit_add_aux`."] instance colimit_has_mul : has_mul M := { mul := λ x y, begin refine quot.lift₂ (colimit_mul_aux F) _ _ x y, { intros x y y' h, apply colimit_mul_aux_eq_of_rel_right, apply types.filtered_colimit.rel_of_quot_rel, exact h }, { intros x x' y h, apply colimit_mul_aux_eq_of_rel_left, apply types.filtered_colimit.rel_of_quot_rel, exact h }, end } /-- Multiplication in the colimit is independent of the chosen "maximum" in the filtered category. In particular, this lemma allows us to "unfold" the definition of the multiplication of `x` and `y`, using a custom object `k` and morphisms `f : x.1 ⟶ k` and `g : y.1 ⟶ k`. -/ @[to_additive "Addition in the colimit is independent of the chosen \"maximum\" in the filtered category. In particular, this lemma allows us to \"unfold\" the definition of the addition of `x` and `y`, using a custom object `k` and morphisms `f : x.1 ⟶ k` and `g : y.1 ⟶ k`."] lemma colimit_mul_mk_eq (x y : Σ j, F.obj j) (k : J) (f : x.1 ⟶ k) (g : y.1 ⟶ k) : (M.mk x) * (M.mk y) = M.mk ⟨k, F.map f x.2 * F.map g y.2⟩ := begin cases x with j₁ x, cases y with j₂ y, obtain ⟨s, α, β, h₁, h₂⟩ := bowtie (left_to_max j₁ j₂) f (right_to_max j₁ j₂) g, apply M.mk_eq, use [s, α, β], dsimp, simp_rw [monoid_hom.map_mul, ← comp_apply, ← F.map_comp, h₁, h₂], end @[to_additive] instance colimit_monoid : monoid M := { one_mul := λ x, begin apply quot.induction_on x, clear x, intro x, cases x with j x, rw [colimit_one_eq F j, colimit_mul_mk_eq F ⟨j, 1⟩ ⟨j, x⟩ j (𝟙 j) (𝟙 j), monoid_hom.map_one, one_mul, F.map_id, id_apply], end, mul_one := λ x, begin apply quot.induction_on x, clear x, intro x, cases x with j x, rw [colimit_one_eq F j, colimit_mul_mk_eq F ⟨j, x⟩ ⟨j, 1⟩ j (𝟙 j) (𝟙 j), monoid_hom.map_one, mul_one, F.map_id, id_apply], end, mul_assoc := λ x y z, begin apply quot.induction_on₃ x y z, clear x y z, intros x y z, cases x with j₁ x, cases y with j₂ y, cases z with j₃ z, rw [colimit_mul_mk_eq F ⟨j₁, x⟩ ⟨j₂, y⟩ _ (first_to_max₃ j₁ j₂ j₃) (second_to_max₃ j₁ j₂ j₃), colimit_mul_mk_eq F ⟨max₃ j₁ j₂ j₃, _⟩ ⟨j₃, z⟩ _ (𝟙 _) (third_to_max₃ j₁ j₂ j₃), colimit_mul_mk_eq F ⟨j₂, y⟩ ⟨j₃, z⟩ _ (second_to_max₃ j₁ j₂ j₃) (third_to_max₃ j₁ j₂ j₃), colimit_mul_mk_eq F ⟨j₁, x⟩ ⟨max₃ j₁ j₂ j₃, _⟩ _ (first_to_max₃ j₁ j₂ j₃) (𝟙 _)], simp only [F.map_id, id_apply, mul_assoc], end, ..colimit_has_one, ..colimit_has_mul } /-- The bundled monoid giving the filtered colimit of a diagram. -/ @[to_additive "The bundled additive monoid giving the filtered colimit of a diagram."] def colimit : Mon := Mon.of M /-- The monoid homomorphism from a given monoid in the diagram to the colimit monoid. -/ @[to_additive "The additive monoid homomorphism from a given additive monoid in the diagram to the colimit additive monoid."] def cocone_morphism (j : J) : F.obj j ⟶ colimit := { to_fun := (types.colimit_cocone (F ⋙ forget Mon)).ι.app j, map_one' := (colimit_one_eq j).symm, map_mul' := λ x y, begin convert (colimit_mul_mk_eq F ⟨j, x⟩ ⟨j, y⟩ j (𝟙 j) (𝟙 j)).symm, rw [F.map_id, id_apply, id_apply], refl, end } @[simp, to_additive] lemma cocone_naturality {j j' : J} (f : j ⟶ j') : F.map f ≫ (cocone_morphism j') = cocone_morphism j := monoid_hom.coe_inj ((types.colimit_cocone (F ⋙ forget Mon)).ι.naturality f) /-- The cocone over the proposed colimit monoid. -/ @[to_additive "/-- The cocone over the proposed colimit additive monoid. -/"] def colimit_cocone : cocone F := { X := colimit, ι := { app := cocone_morphism } }. /-- Given a cocone `t` of `F`, the induced monoid homomorphism from the colimit to the cocone point. As a function, this is simply given by the induced map of the corresponding cocone in `Type`. The only thing left to see is that it is a monoid homomorphism. -/ @[to_additive "Given a cocone `t` of `F`, the induced additive monoid homomorphism from the colimit to the cocone point. As a function, this is simply given by the induced map of the corresponding cocone in `Type`. The only thing left to see is that it is an additive monoid homomorphism."] def colimit_desc (t : cocone F) : colimit ⟶ t.X := { to_fun := (types.colimit_cocone_is_colimit (F ⋙ forget Mon)).desc ((forget Mon).map_cocone t), map_one' := begin rw colimit_one_eq F is_filtered.nonempty.some, exact monoid_hom.map_one _, end, map_mul' := λ x y, begin apply quot.induction_on₂ x y, clear x y, intros x y, cases x with i x, cases y with j y, rw colimit_mul_mk_eq F ⟨i, x⟩ ⟨j, y⟩ (max' i j) (left_to_max i j) (right_to_max i j), dsimp [types.colimit_cocone_is_colimit], rw [monoid_hom.map_mul, t.w_apply, t.w_apply], end } /-- The proposed colimit cocone is a colimit in `Mon`. -/ @[to_additive "The proposed colimit cocone is a colimit in `AddMon`."] def colimit_cocone_is_colimit : is_colimit colimit_cocone := { desc := colimit_desc, fac' := λ t j, monoid_hom.coe_inj ((types.colimit_cocone_is_colimit (F ⋙ forget Mon)).fac ((forget Mon).map_cocone t) j), uniq' := λ t m h, monoid_hom.coe_inj $ (types.colimit_cocone_is_colimit (F ⋙ forget Mon)).uniq ((forget Mon).map_cocone t) m (λ j, funext $ λ x, monoid_hom.congr_fun (h j) x) } @[to_additive] instance forget_preserves_filtered_colimits : preserves_filtered_colimits (forget Mon) := { preserves_filtered_colimits := λ J _ _, by exactI { preserves_colimit := λ F, preserves_colimit_of_preserves_colimit_cocone (colimit_cocone_is_colimit F) (types.colimit_cocone_is_colimit (F ⋙ forget Mon)) } } end end Mon.filtered_colimits namespace CommMon.filtered_colimits open Mon.filtered_colimits (colimit_mul_mk_eq) section -- We use parameters here, mainly so we can have the abbreviation `M` below, without -- passing around `F` all the time. parameters {J : Type v} [small_category J] [is_filtered J] (F : J ⥤ CommMon.{v}) /-- The colimit of `F ⋙ forget₂ CommMon Mon` in the category `Mon`. In the following, we will show that this has the structure of a _commutative_ monoid. -/ @[to_additive "The colimit of `F ⋙ forget₂ AddCommMon AddMon` in the category `AddMon`. In the following, we will show that this has the structure of a _commutative_ additive monoid."] abbreviation M : Mon := Mon.filtered_colimits.colimit (F ⋙ forget₂ CommMon Mon.{v}) @[to_additive] instance colimit_comm_monoid : comm_monoid M := { mul_comm := λ x y, begin apply quot.induction_on₂ x y, clear x y, intros x y, let k := max' x.1 y.1, let f := left_to_max x.1 y.1, let g := right_to_max x.1 y.1, rw [colimit_mul_mk_eq _ x y k f g, colimit_mul_mk_eq _ y x k g f], dsimp, rw mul_comm, end ..M.monoid } /-- The bundled commutative monoid giving the filtered colimit of a diagram. -/ @[to_additive "The bundled additive commutative monoid giving the filtered colimit of a diagram."] def colimit : CommMon := CommMon.of M /-- The cocone over the proposed colimit commutative monoid. -/ @[to_additive "The cocone over the proposed colimit additive commutative monoid."] def colimit_cocone : cocone F := { X := colimit, ι := { ..(Mon.filtered_colimits.colimit_cocone (F ⋙ forget₂ CommMon Mon.{v})).ι } } /-- The proposed colimit cocone is a colimit in `CommMon`. -/ @[to_additive "The proposed colimit cocone is a colimit in `AddCommMon`."] def colimit_cocone_is_colimit : is_colimit colimit_cocone := { desc := λ t, Mon.filtered_colimits.colimit_desc (F ⋙ forget₂ CommMon Mon.{v}) ((forget₂ CommMon Mon.{v}).map_cocone t), fac' := λ t j, monoid_hom.coe_inj $ (types.colimit_cocone_is_colimit (F ⋙ forget CommMon)).fac ((forget CommMon).map_cocone t) j, uniq' := λ t m h, monoid_hom.coe_inj $ (types.colimit_cocone_is_colimit (F ⋙ forget CommMon)).uniq ((forget CommMon).map_cocone t) m ((λ j, funext $ λ x, monoid_hom.congr_fun (h j) x)) } @[to_additive forget₂_AddMon_preserves_filtered_colimits] instance forget₂_Mon_preserves_filtered_colimits : preserves_filtered_colimits (forget₂ CommMon Mon.{v}) := { preserves_filtered_colimits := λ J _ _, by exactI { preserves_colimit := λ F, preserves_colimit_of_preserves_colimit_cocone (colimit_cocone_is_colimit F) (Mon.filtered_colimits.colimit_cocone_is_colimit (F ⋙ forget₂ CommMon Mon.{v})) } } @[to_additive] instance forget_preserves_filtered_colimits : preserves_filtered_colimits (forget CommMon) := limits.comp_preserves_filtered_colimits (forget₂ CommMon Mon) (forget Mon) end end CommMon.filtered_colimits
6b19c6e48c8e652da8fd02b98594460168b4c147
8cae430f0a71442d02dbb1cbb14073b31048e4b0
/src/logic/embedding/set.lean
60952eac1fe061315f368cf7e4270b6c755d3e81
[ "Apache-2.0" ]
permissive
leanprover-community/mathlib
56a2cadd17ac88caf4ece0a775932fa26327ba0e
442a83d738cb208d3600056c489be16900ba701d
refs/heads/master
1,693,584,102,358
1,693,471,902,000
1,693,471,902,000
97,922,418
1,595
352
Apache-2.0
1,694,693,445,000
1,500,624,130,000
Lean
UTF-8
Lean
false
false
4,173
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 logic.embedding.basic import data.set.image /-! # Interactions between embeddings and sets. > THIS FILE IS SYNCHRONIZED WITH MATHLIB4. > Any changes to this file require a corresponding PR to mathlib4. -/ universes u v w x section equiv variables {α : Sort u} {β : Sort v} (f : α ≃ β) @[simp] lemma equiv.as_embedding_range {α β : Sort*} {p : β → Prop} (e : α ≃ subtype p) : set.range e.as_embedding = set_of p := set.ext $ λ x, ⟨λ ⟨y, h⟩, h ▸ subtype.coe_prop (e y), λ hs, ⟨e.symm ⟨x, hs⟩, by simp⟩⟩ end equiv namespace function namespace embedding /-- Embedding into `with_top α`. -/ @[simps] def coe_with_top {α} : α ↪ with_top α := { to_fun := coe, ..embedding.some} /-- Given an embedding `f : α ↪ β` and a point outside of `set.range f`, construct an embedding `option α ↪ β`. -/ @[simps] def option_elim {α β} (f : α ↪ β) (x : β) (h : x ∉ set.range f) : option α ↪ β := ⟨option.elim x f, option.injective_iff.2 ⟨f.2, h⟩⟩ /-- Equivalence between embeddings of `option α` and a sigma type over the embeddings of `α`. -/ @[simps] def option_embedding_equiv (α β) : (option α ↪ β) ≃ Σ f : α ↪ β, ↥(set.range f)ᶜ := { to_fun := λ f, ⟨coe_option.trans f, f none, λ ⟨x, hx⟩, option.some_ne_none x $ f.injective hx⟩, inv_fun := λ f, f.1.option_elim f.2 f.2.2, left_inv := λ f, ext $ by { rintro (_|_); simp [option.coe_def] }, right_inv := λ ⟨f, y, hy⟩, by { ext; simp [option.coe_def] } } /-- Restrict the codomain of an embedding. -/ def cod_restrict {α β} (p : set β) (f : α ↪ β) (H : ∀ a, f a ∈ p) : α ↪ p := ⟨λ a, ⟨f a, H a⟩, λ a b h, f.injective (@congr_arg _ _ _ _ subtype.val h)⟩ @[simp] theorem cod_restrict_apply {α β} (p) (f : α ↪ β) (H a) : cod_restrict p f H a = ⟨f a, H a⟩ := rfl open set /-- `set.image` as an embedding `set α ↪ set β`. -/ @[simps apply] protected def image {α β} (f : α ↪ β) : set α ↪ set β := ⟨image f, f.2.image_injective⟩ end embedding end function namespace set /-- The injection map is an embedding between subsets. -/ @[simps apply] def embedding_of_subset {α} (s t : set α) (h : s ⊆ t) : s ↪ t := ⟨λ x, ⟨x.1, h x.2⟩, λ ⟨x, hx⟩ ⟨y, hy⟩ h, by { congr, injection h }⟩ end set section subtype variable {α : Type*} /-- A subtype `{x // p x ∨ q x}` over a disjunction of `p q : α → Prop` is equivalent to a sum of subtypes `{x // p x} ⊕ {x // q x}` such that `¬ p x` is sent to the right, when `disjoint p q`. See also `equiv.sum_compl`, for when `is_compl p q`. -/ @[simps apply] def subtype_or_equiv (p q : α → Prop) [decidable_pred p] (h : disjoint p q) : {x // p x ∨ q x} ≃ {x // p x} ⊕ {x // q x} := { to_fun := subtype_or_left_embedding p q, inv_fun := sum.elim (subtype.imp_embedding _ _ (λ x hx, (or.inl hx : p x ∨ q x))) (subtype.imp_embedding _ _ (λ x hx, (or.inr hx : p x ∨ q x))), left_inv := λ x, begin by_cases hx : p x, { rw subtype_or_left_embedding_apply_left _ hx, simp [subtype.ext_iff] }, { rw subtype_or_left_embedding_apply_right _ hx, simp [subtype.ext_iff] }, end, right_inv := λ x, begin cases x, { simp only [sum.elim_inl], rw subtype_or_left_embedding_apply_left, { simp }, { simpa using x.prop } }, { simp only [sum.elim_inr], rw subtype_or_left_embedding_apply_right, { simp }, { suffices : ¬ p x, { simpa }, intro hp, simpa using h.le_bot x ⟨hp, x.prop⟩ } } end } @[simp] lemma subtype_or_equiv_symm_inl (p q : α → Prop) [decidable_pred p] (h : disjoint p q) (x : {x // p x}) : (subtype_or_equiv p q h).symm (sum.inl x) = ⟨x, or.inl x.prop⟩ := rfl @[simp] lemma subtype_or_equiv_symm_inr (p q : α → Prop) [decidable_pred p] (h : disjoint p q) (x : {x // q x}) : (subtype_or_equiv p q h).symm (sum.inr x) = ⟨x, or.inr x.prop⟩ := rfl end subtype
00eda042c5e6152f7caf686f69a849efb29f715c
7cef822f3b952965621309e88eadf618da0c8ae9
/src/tactic/omega/main.lean
7c3758025ec357746808be0df30ab60045676b69
[ "Apache-2.0" ]
permissive
rmitta/mathlib
8d90aee30b4db2b013e01f62c33f297d7e64a43d
883d974b608845bad30ae19e27e33c285200bf84
refs/heads/master
1,585,776,832,544
1,576,874,096,000
1,576,874,096,000
153,663,165
0
2
Apache-2.0
1,544,806,490,000
1,539,884,365,000
Lean
UTF-8
Lean
false
false
4,592
lean
/- Copyright (c) 2019 Seul Baek. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Seul Baek A tactic for discharging linear integer & natural number arithmetic goals using the Omega test. -/ import tactic.omega.int.main import tactic.omega.nat.main namespace omega open tactic meta def revert_cond (t : expr → tactic unit) (x : expr) : tactic unit := (t x >> revert x >> skip) <|> skip meta def revert_cond_all (t : expr → tactic unit) : tactic unit := do hs ← local_context, mmap (revert_cond t) hs, skip meta def select_domain (t s : tactic (option bool)) : tactic (option bool) := do a ← t, b ← s, match a, b with | a, none := return a | none, b := return b | (some tt), (some tt) := return (some tt) | (some ff), (some ff) := return (some ff) | _, _ := failed end meta def type_domain (x : expr) : tactic (option bool) := if x = `(int) then return (some tt) else if x = `(nat) then return (some ff) else failed /- Detects domain of a formula from its expr. - Returns none, if domain can be either ℤ or ℕ - Returns some tt, if domain is exclusively ℤ - Returns some ff, if domain is exclusively ℕ - Fails, if domain is neither ℤ nor ℕ -/ meta def form_domain : expr → tactic (option bool) | `(¬ %%px) := form_domain px | `(%%px ∨ %%qx) := select_domain (form_domain px) (form_domain qx) | `(%%px ∧ %%qx) := select_domain (form_domain px) (form_domain qx) | `(%%px ↔ %%qx) := select_domain (form_domain px) (form_domain qx) | `(%%(expr.pi _ _ px qx)) := monad.cond (if expr.has_var px then return tt else is_prop px) (select_domain (form_domain px) (form_domain qx)) (select_domain (type_domain px) (form_domain qx)) | `(@has_lt.lt %%dx %%h _ _) := type_domain dx | `(@has_le.le %%dx %%h _ _) := type_domain dx | `(@eq %%dx _ _) := type_domain dx | `(@ge %%dx %%h _ _) := type_domain dx | `(@gt %%dx %%h _ _) := type_domain dx | `(@ne %%dx _ _) := type_domain dx | `(true) := return none | `(false) := return none | x := failed meta def form_wf (x : expr) : tactic bool := (form_domain x >> return tt) <|> return ff meta def term_domain (x : expr) : tactic (option bool) := infer_type x >>= type_domain meta def is_lia_form (x : expr) : tactic unit := do (some tt) ← infer_type x >>= form_domain, skip meta def is_lia_term (x : expr) : tactic unit := do (some tt) ← term_domain x, skip meta def rev_lia : tactic unit := do revert_cond_all is_lia_form, revert_cond_all is_lia_term meta def is_lna_form (x : expr) : tactic unit := do (some ff) ← infer_type x >>= form_domain, skip meta def is_lna_term (x : expr) : tactic unit := do (some ff) ← term_domain x, skip meta def rev_lna : tactic unit := do revert_cond_all is_lna_form, revert_cond_all is_lna_term meta def goal_domain_aux : list expr → tactic bool | [] := failed | (x::xs) := do b1 ← ((form_domain x >>= return ∘ some) <|> return none), match b1 with | none := goal_domain_aux xs | (some none) := goal_domain_aux xs | (some (some tt)) := return tt | (some (some ff)) := return ff end meta def goal_domain : tactic bool := do gx ← target, hxs ← local_context >>= monad.mapm infer_type, goal_domain_aux (gx::hxs) meta def clear_unused_hyp (hx : expr) : tactic unit := do x ← infer_type hx, b ← form_wf x, if (b ∨ x = `(nat) ∨ x = `(int)) then skip else clear hx >> skip meta def clear_unused_hyps : tactic unit := local_context >>= mmap' clear_unused_hyp meta def preprocess (opt : list name) : tactic unit := if `manual ∈ opt then skip else clear_unused_hyps >> if `int ∈ opt then rev_lia else if `nat ∈ opt then rev_lna else monad.cond goal_domain rev_lia rev_lna end omega open lean.parser interactive omega /-- Attempts to discharge goals in the quantifier-free fragment of linear integer and natural number arithmetic using the Omega test. Guesses the correct domain by looking at the goal and hypotheses, and then reverts all relevant hypotheses and variables. Use `omega manual` to disable automatic reverts, and `omega int` or `omega nat` to specify the domain. -/ meta def tactic.interactive.omega (opt : parse (many ident)) : tactic unit := preprocess opt >> if `int ∈ opt then omega_int else if `nat ∈ opt then omega_nat else mcond goal_domain omega_int omega_nat
9120e1340e5d0c8e7e9d94e28602df28904fecdb
1a9d3677cccdaaccacb163507570e75d34043a38
/src/week_1/kb_solutions/Part_D_relations_solutions.lean
efe050bef3e1839349f2b3e57f34092fe70269ee
[ "Apache-2.0" ]
permissive
alreadydone/formalising-mathematics
687d386a72065795e784e270f5c05ea3948b67dd
65869362cd7a2ac74dd1a97c7f9471835726570b
refs/heads/master
1,680,260,936,332
1,616,563,371,000
1,616,563,371,000
348,780,769
0
0
null
null
null
null
UTF-8
Lean
false
false
10,136
lean
import tactic /-! # Equivalence relations are the same as partitions In this file we prove that there's a bijection between the equivalence relations on a type, and the partitions of a type. Three sections: 1) partitions 2) equivalence classes 3) the proof ## Overview Say `α` is a type, and `R : α → α → Prop` is a binary relation on `α`. The following things are already in Lean: `reflexive R := ∀ (x : α), R x x` `symmetric R := ∀ ⦃x y : α⦄, R x y → R y x` `transitive R := ∀ ⦃x y z : α⦄, R x y → R y z → R x z` `equivalence R := reflexive R ∧ symmetric R ∧ transitive R` In the file below, we will define partitions of `α` and "build some interface" (i.e. prove some propositions). We will define equivalence classes and do the same thing. Finally, we will prove that there's a bijection between equivalence relations on `α` and partitions of `α`. -/ /- # 1) Partitions We define a partition, and prove some lemmas about partitions. Some I prove myself (not always using tactics) and some I leave for you. ## Definition of a partition Let `α` be a type. A *partition* on `α` is defined to be the following data: 1) A set C of subsets of α, called "blocks". 2) A hypothesis (i.e. a proof!) that all the blocks are non-empty. 3) A hypothesis that every term of type α is in one of the blocks. 4) A hypothesis that two blocks with non-empty intersection are equal. -/ /-- The structure of a partition on a Type α. -/ @[ext] structure partition (α : Type) := (C : set (set α)) (Hnonempty : ∀ X ∈ C, (X : set α).nonempty) (Hcover : ∀ a, ∃ X ∈ C, a ∈ X) (Hdisjoint : ∀ X Y ∈ C, (X ∩ Y : set α).nonempty → X = Y) /- ## Basic interface for partitions Here's the way notation works. If `α` is a type (i.e. a set) then a term `P` of type `partition α` is a partition of `α`, that is, a set of disjoint nonempty subsets of `α` whose union is `α`. The collection of sets underlying `P` is `P.C`, the proof that they're all nonempty is `P.Hnonempty` and so on. -/ namespace partition -- let α be a type, and fix a partition P on α. Let X and Y be subsets of α. variables {α : Type} {P : partition α} {X Y : set α} /-- If X and Y are blocks, and a is in X and Y, then X = Y. -/ theorem eq_of_mem (hX : X ∈ P.C) (hY : Y ∈ P.C) {a : α} (haX : a ∈ X) (haY : a ∈ Y) : X = Y := -- Proof: follows immediately from the disjointness hypothesis. P.Hdisjoint _ _ hX hY ⟨a, haX, haY⟩ /-- If a is in two blocks X and Y, and if b is in X, then b is in Y (as X=Y) -/ theorem mem_of_mem (hX : X ∈ P.C) (hY : Y ∈ P.C) {a b : α} (haX : a ∈ X) (haY : a ∈ Y) (hbX : b ∈ X) : b ∈ Y := begin -- you might want to start with `have hXY : X = Y` -- and prove it from the previous lemma have hXY : X = Y, { exact eq_of_mem hX hY haX haY }, rw ← hXY, assumption, end /-- Every term of type `α` is in one of the blocks for a partition `P`. -/ theorem mem_block (a : α) : ∃ X : set α, X ∈ P.C ∧ a ∈ X := begin -- an interesting way to start is -- `obtain ⟨X, hX, haX⟩ := P.Hcover a,` obtain ⟨X, hX, haX⟩ := P.Hcover a, use X, exact ⟨hX, haX⟩, end end partition /- # 2) Equivalence classes. We define equivalence classes and prove a few basic results about them. -/ section equivalence_classes /-! ## Definition of equivalence classes -/ -- Notation and variables for the equivalence class section: -- let α be a type, and let R be a binary relation on R. variables {α : Type} (R : α → α → Prop) /-- The equivalence class of `a` is the set of `b` related to `a`. -/ def cl (a : α) := {b : α | R b a} /-! ## Basic lemmas about equivalence classes -/ /-- Useful for rewriting -- `b` is in the equivalence class of `a` iff `b` is related to `a`. True by definition. -/ theorem mem_cl_iff {a b : α} : b ∈ cl R a ↔ R b a := begin -- true by definition refl end -- Assume now that R is an equivalence relation. variables {R} (hR : equivalence R) include hR /-- x is in cl(x) -/ lemma mem_cl_self (a : α) : a ∈ cl R a := begin -- Note that `hR : equivalence R` is a package of three things. -- You can extract the things with -- `rcases hR with ⟨hrefl, hsymm, htrans⟩,` or -- `obtain ⟨hrefl, hsymm, htrans⟩ := hR,` obtain ⟨hrefl, hsymm, htrans⟩ := hR, rw mem_cl_iff, -- not necessary, apply hrefl, end lemma cl_sub_cl_of_mem_cl {a b : α} : a ∈ cl R b → cl R a ⊆ cl R b := begin -- remember `set.subset_def` says `X ⊆ Y ↔ ∀ a, a ∈ X → a ∈ Y intro hab, intros z hza, rw mem_cl_iff at hab hza ⊢, obtain ⟨hrefl, hsymm, htrans⟩ := hR, exact htrans hza hab, end lemma cl_eq_cl_of_mem_cl {a b : α} : a ∈ cl R b → cl R a = cl R b := begin intro hab, -- remember `set.subset.antisymm` says `X ⊆ Y → Y ⊆ X → X = Y` apply set.subset.antisymm, { exact cl_sub_cl_of_mem_cl hR hab}, { apply cl_sub_cl_of_mem_cl hR, obtain ⟨hrefl, hsymm, htrans⟩ := hR, exact hsymm hab } end end equivalence_classes -- section /-! # 3) The theorem Let `α` be a type (i.e. a collection of stucff). There is a bijection between equivalence relations on `α` and partitions of `α`. We prove this by writing down constructions in each direction and proving that the constructions are two-sided inverses of one another. -/ open partition example (α : Type) : {R : α → α → Prop // equivalence R} ≃ partition α := -- We define constructions (functions!) in both directions and prove that -- one is a two-sided inverse of the other { -- Here is the first construction, from equivalence -- relations to partitions. -- Let R be an equivalence relation. to_fun := λ R, { -- Let C be the set of equivalence classes for R. C := { B : set α | ∃ x : α, B = cl R.1 x}, -- I claim that C is a partition. We need to check the three -- hypotheses for a partition (`Hnonempty`, `Hcover` and `Hdisjoint`), -- so we need to supply three proofs. Hnonempty := begin cases R with R hR, -- If X is an equivalence class then X is nonempty. show ∀ (X : set α), (∃ (a : α), X = cl R a) → X.nonempty, rintros _ ⟨a, rfl⟩, use a, rw mem_cl_iff, obtain ⟨hrefl, hsymm, htrans⟩ := hR, apply hrefl, end, Hcover := begin cases R with R hR, -- The equivalence classes cover α show ∀ (a : α), ∃ (X : set α) (H : ∃ (b : α), X = cl R b), a ∈ X, intro a, use cl R a, split, { use a }, { apply hR.1 }, end, Hdisjoint := begin cases R with R hR, -- If two equivalence classes overlap, they are equal. show ∀ (X Y : set α), (∃ (a : α), X = cl R a) → (∃ (b : α), Y = cl _ b) → (X ∩ Y).nonempty → X = Y, rintros X Y ⟨a, rfl⟩ ⟨b, rfl⟩ ⟨c, hca, hcb⟩, apply cl_eq_cl_of_mem_cl hR, apply hR.2.2, apply hR.2.1, exact hca, exact hcb, end }, -- Conversely, say P is an partition. inv_fun := λ P, -- Let's define a binary relation `R` thus: -- `R a b` iff *every* block containing `a` also contains `b`. -- Because only one block contains a, this will work, -- and it turns out to be a nice way of thinking about it. ⟨λ a b, ∀ X ∈ P.C, b ∈ X → a ∈ X, begin -- I claim this is an equivalence relation. split, { -- It's reflexive show ∀ (a : α) (X : set α), X ∈ P.C → a ∈ X → a ∈ X, intros a X hXC haX, assumption, }, split, { -- it's symmetric show ∀ (a b : α), (∀ (X : set α), X ∈ P.C → b ∈ X → a ∈ X) → ∀ (X : set α), X ∈ P.C → a ∈ X → b ∈ X, intros a b h X hX haX, obtain ⟨Y, hY, hbY⟩ := P.Hcover b, specialize h Y hY hbY, exact mem_of_mem hY hX h haX hbY, }, { -- it's transitive unfold transitive, show ∀ (a b c : α), (∀ (X : set α), X ∈ P.C → b ∈ X → a ∈ X) → (∀ (X : set α), X ∈ P.C → c ∈ X → b ∈ X) → ∀ (X : set α), X ∈ P.C → c ∈ X → a ∈ X, intros a b c haX hbX X hX hcX, apply haX, assumption, apply hbX, assumption, assumption, } end⟩, -- If you start with the equivalence relation, and then make the partition -- and a new equivalence relation, you get back to where you started. left_inv := begin rintro ⟨R, hR⟩, -- Tidying up the mess... suffices : (λ (a b : α), ∀ (c : α), b ∈ cl R c → a ∈ cl R c) = R, simpa, -- ... you have to prove two binary relations are equal. ext a b, -- so you have to prove an if and only if. show (∀ (c : α), b ∈ cl R c → a ∈ cl R c) ↔ R a b, split, { intros hab, apply hab, apply hR.1, }, { intros hab c hbc, apply hR.2.2, exact hab, exact hbc, } end, -- Similarly, if you start with the partition, and then make the -- equivalence relation, and then construct the corresponding partition -- into equivalence classes, you have the same partition you started with. right_inv := begin -- Let P be a partition intro P, -- It suffices to prove that a subset X is in the original partition -- if and only if it's in the one made from the equivalence relation. ext X, show (∃ (a : α), X = cl _ a) ↔ X ∈ P.C, dsimp only, split, { rintro ⟨a, rfl⟩, obtain ⟨X, hX, haX⟩ := P.Hcover a, convert hX, ext b, rw mem_cl_iff, split, { intro haY, exact haY X hX haX, }, { intros hbX Y hY haY, apply mem_of_mem hX hY haX haY hbX, } }, { intro hX, rcases P.Hnonempty X hX with ⟨a, ha⟩, use a, ext b, split, { intro hbX, rw mem_cl_iff, intros Y hY haY, exact mem_of_mem hX hY ha haY hbX, }, { rw mem_cl_iff, intro haY, exact haY X hX ha, } } end }
a8a54b124976afcc1d1a74a35a945aec02719b91
4d2583807a5ac6caaffd3d7a5f646d61ca85d532
/src/field_theory/is_alg_closed/algebraic_closure.lean
e614ed0bbe571afb575df73edb220a2669a9e2fc
[ "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
10,817
lean
/- Copyright (c) 2020 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau -/ import algebra.direct_limit import field_theory.is_alg_closed.basic /-! # Algebraic Closure In this file we construct the algebraic closure of a field ## Main Definitions - `algebraic_closure k` is an algebraic closure of `k` (in the same universe). It is constructed by taking the polynomial ring generated by indeterminates `x_f` corresponding to monic irreducible polynomials `f` with coefficients in `k`, and quotienting out by a maximal ideal containing every `f(x_f)`, and then repeating this step countably many times. See Exercise 1.13 in Atiyah--Macdonald. ## Tags algebraic closure, algebraically closed -/ universes u v w noncomputable theory open_locale classical big_operators open polynomial variables (k : Type u) [field k] namespace algebraic_closure open mv_polynomial /-- The subtype of monic irreducible polynomials -/ @[reducible] def monic_irreducible : Type u := { f : polynomial k // monic f ∧ irreducible f } /-- Sends a monic irreducible polynomial `f` to `f(x_f)` where `x_f` is a formal indeterminate. -/ def eval_X_self (f : monic_irreducible k) : mv_polynomial (monic_irreducible k) k := polynomial.eval₂ mv_polynomial.C (X f) f /-- The span of `f(x_f)` across monic irreducible polynomials `f` where `x_f` is an indeterminate. -/ def span_eval : ideal (mv_polynomial (monic_irreducible k) k) := ideal.span $ set.range $ eval_X_self k /-- Given a finset of monic irreducible polynomials, construct an algebra homomorphism to the splitting field of the product of the polynomials sending each indeterminate `x_f` represented by the polynomial `f` in the finset to a root of `f`. -/ def to_splitting_field (s : finset (monic_irreducible k)) : mv_polynomial (monic_irreducible k) k →ₐ[k] splitting_field (∏ x in s, x : polynomial k) := mv_polynomial.aeval $ λ f, if hf : f ∈ s then root_of_splits _ ((splits_prod_iff _ $ λ (j : monic_irreducible k) _, j.2.2.ne_zero).1 (splitting_field.splits _) f hf) (mt is_unit_iff_degree_eq_zero.2 f.2.2.not_unit) else 37 theorem to_splitting_field_eval_X_self {s : finset (monic_irreducible k)} {f} (hf : f ∈ s) : to_splitting_field k s (eval_X_self k f) = 0 := by { rw [to_splitting_field, eval_X_self, ← alg_hom.coe_to_ring_hom, hom_eval₂, alg_hom.coe_to_ring_hom, mv_polynomial.aeval_X, dif_pos hf, ← algebra_map_eq, alg_hom.comp_algebra_map], exact map_root_of_splits _ _ _ } theorem span_eval_ne_top : span_eval k ≠ ⊤ := begin rw [ideal.ne_top_iff_one, span_eval, ideal.span, ← set.image_univ, finsupp.mem_span_image_iff_total], rintros ⟨v, _, hv⟩, replace hv := congr_arg (to_splitting_field k v.support) hv, rw [alg_hom.map_one, finsupp.total_apply, finsupp.sum, alg_hom.map_sum, finset.sum_eq_zero] at hv, { exact zero_ne_one hv }, intros j hj, rw [smul_eq_mul, alg_hom.map_mul, to_splitting_field_eval_X_self k hj, mul_zero] end /-- A random maximal ideal that contains `span_eval k` -/ def max_ideal : ideal (mv_polynomial (monic_irreducible k) k) := classical.some $ ideal.exists_le_maximal _ $ span_eval_ne_top k instance max_ideal.is_maximal : (max_ideal k).is_maximal := (classical.some_spec $ ideal.exists_le_maximal _ $ span_eval_ne_top k).1 theorem le_max_ideal : span_eval k ≤ max_ideal k := (classical.some_spec $ ideal.exists_le_maximal _ $ span_eval_ne_top k).2 /-- The first step of constructing `algebraic_closure`: adjoin a root of all monic polynomials -/ def adjoin_monic : Type u := (max_ideal k).quotient instance adjoin_monic.field : field (adjoin_monic k) := ideal.quotient.field _ instance adjoin_monic.inhabited : inhabited (adjoin_monic k) := ⟨37⟩ /-- The canonical ring homomorphism to `adjoin_monic k`. -/ def to_adjoin_monic : k →+* adjoin_monic k := (ideal.quotient.mk _).comp C instance adjoin_monic.algebra : algebra k (adjoin_monic k) := (to_adjoin_monic k).to_algebra theorem adjoin_monic.algebra_map : algebra_map k (adjoin_monic k) = (ideal.quotient.mk _).comp C := rfl theorem adjoin_monic.is_integral (z : adjoin_monic k) : is_integral k z := let ⟨p, hp⟩ := ideal.quotient.mk_surjective z in hp ▸ mv_polynomial.induction_on p (λ x, is_integral_algebra_map) (λ p q, is_integral_add) (λ p f ih, @is_integral_mul _ _ _ _ _ _ (ideal.quotient.mk _ _) ih ⟨f, f.2.1, by { erw [adjoin_monic.algebra_map, ← hom_eval₂, ideal.quotient.eq_zero_iff_mem], exact le_max_ideal k (ideal.subset_span ⟨f, rfl⟩) }⟩) theorem adjoin_monic.exists_root {f : polynomial k} (hfm : f.monic) (hfi : irreducible f) : ∃ x : adjoin_monic k, f.eval₂ (to_adjoin_monic k) x = 0 := ⟨ideal.quotient.mk _ $ X (⟨f, hfm, hfi⟩ : monic_irreducible k), by { rw [to_adjoin_monic, ← hom_eval₂, ideal.quotient.eq_zero_iff_mem], exact le_max_ideal k (ideal.subset_span $ ⟨_, rfl⟩) }⟩ /-- The `n`th step of constructing `algebraic_closure`, together with its `field` instance. -/ def step_aux (n : ℕ) : Σ α : Type u, field α := nat.rec_on n ⟨k, infer_instance⟩ $ λ n ih, ⟨@adjoin_monic ih.1 ih.2, @adjoin_monic.field ih.1 ih.2⟩ /-- The `n`th step of constructing `algebraic_closure`. -/ def step (n : ℕ) : Type u := (step_aux k n).1 instance step.field (n : ℕ) : field (step k n) := (step_aux k n).2 instance step.inhabited (n) : inhabited (step k n) := ⟨37⟩ /-- The canonical inclusion to the `0`th step. -/ def to_step_zero : k →+* step k 0 := ring_hom.id k /-- The canonical ring homomorphism to the next step. -/ def to_step_succ (n : ℕ) : step k n →+* step k (n + 1) := @to_adjoin_monic (step k n) (step.field k n) instance step.algebra_succ (n) : algebra (step k n) (step k (n + 1)) := (to_step_succ k n).to_algebra theorem to_step_succ.exists_root {n} {f : polynomial (step k n)} (hfm : f.monic) (hfi : irreducible f) : ∃ x : step k (n + 1), f.eval₂ (to_step_succ k n) x = 0 := @adjoin_monic.exists_root _ (step.field k n) _ hfm hfi /-- The canonical ring homomorphism to a step with a greater index. -/ def to_step_of_le (m n : ℕ) (h : m ≤ n) : step k m →+* step k n := { to_fun := nat.le_rec_on h (λ n, to_step_succ k n), map_one' := begin induction h with n h ih, { exact nat.le_rec_on_self 1 }, rw [nat.le_rec_on_succ h, ih, ring_hom.map_one] end, map_mul' := λ x y, begin induction h with n h ih, { simp_rw nat.le_rec_on_self }, simp_rw [nat.le_rec_on_succ h, ih, ring_hom.map_mul] end, map_zero' := begin induction h with n h ih, { exact nat.le_rec_on_self 0 }, rw [nat.le_rec_on_succ h, ih, ring_hom.map_zero] end, map_add' := λ x y, begin induction h with n h ih, { simp_rw nat.le_rec_on_self }, simp_rw [nat.le_rec_on_succ h, ih, ring_hom.map_add] end } @[simp] lemma coe_to_step_of_le (m n : ℕ) (h : m ≤ n) : (to_step_of_le k m n h : step k m → step k n) = nat.le_rec_on h (λ n, to_step_succ k n) := rfl instance step.algebra (n) : algebra k (step k n) := (to_step_of_le k 0 n n.zero_le).to_algebra instance step.scalar_tower (n) : is_scalar_tower k (step k n) (step k (n + 1)) := is_scalar_tower.of_algebra_map_eq $ λ z, @nat.le_rec_on_succ (step k) 0 n n.zero_le (n + 1).zero_le (λ n, to_step_succ k n) z theorem step.is_integral (n) : ∀ z : step k n, is_integral k z := nat.rec_on n (λ z, is_integral_algebra_map) $ λ n ih z, is_integral_trans ih _ (adjoin_monic.is_integral (step k n) z : _) instance to_step_of_le.directed_system : directed_system (step k) (λ i j h, to_step_of_le k i j h) := ⟨λ i x h, nat.le_rec_on_self x, λ i₁ i₂ i₃ h₁₂ h₂₃ x, (nat.le_rec_on_trans h₁₂ h₂₃ x).symm⟩ end algebraic_closure /-- The canonical algebraic closure of a field, the direct limit of adding roots to the field for each polynomial over the field. -/ def algebraic_closure : Type u := ring.direct_limit (algebraic_closure.step k) (λ i j h, algebraic_closure.to_step_of_le k i j h) namespace algebraic_closure instance : field (algebraic_closure k) := field.direct_limit.field _ _ instance : inhabited (algebraic_closure k) := ⟨37⟩ /-- The canonical ring embedding from the `n`th step to the algebraic closure. -/ def of_step (n : ℕ) : step k n →+* algebraic_closure k := ring.direct_limit.of _ _ _ instance algebra_of_step (n) : algebra (step k n) (algebraic_closure k) := (of_step k n).to_algebra theorem of_step_succ (n : ℕ) : (of_step k (n + 1)).comp (to_step_succ k n) = of_step k n := ring_hom.ext $ λ x, show ring.direct_limit.of (step k) (λ i j h, to_step_of_le k i j h) _ _ = _, by { convert ring.direct_limit.of_f n.le_succ x, ext x, exact (nat.le_rec_on_succ' x).symm } theorem exists_of_step (z : algebraic_closure k) : ∃ n x, of_step k n x = z := ring.direct_limit.exists_of z -- slow theorem exists_root {f : polynomial (algebraic_closure k)} (hfm : f.monic) (hfi : irreducible f) : ∃ x : algebraic_closure k, f.eval x = 0 := begin have : ∃ n p, polynomial.map (of_step k n) p = f, { convert ring.direct_limit.polynomial.exists_of f }, unfreezingI { obtain ⟨n, p, rfl⟩ := this }, rw monic_map_iff at hfm, have := hfm.irreducible_of_irreducible_map (of_step k n) p hfi, obtain ⟨x, hx⟩ := to_step_succ.exists_root k hfm this, refine ⟨of_step k (n + 1) x, _⟩, rw [← of_step_succ k n, eval_map, ← hom_eval₂, hx, ring_hom.map_zero] end instance : is_alg_closed (algebraic_closure k) := is_alg_closed.of_exists_root _ $ λ f, exists_root k instance {R : Type*} [comm_semiring R] [alg : algebra R k] : algebra R (algebraic_closure k) := ((of_step k 0).comp (@algebra_map _ _ _ _ alg)).to_algebra lemma algebra_map_def {R : Type*} [comm_semiring R] [alg : algebra R k] : algebra_map R (algebraic_closure k) = ((of_step k 0 : k →+* _).comp (@algebra_map _ _ _ _ alg)) := rfl instance {R S : Type*} [comm_semiring R] [comm_semiring S] [algebra R S] [algebra S k] [algebra R k] [is_scalar_tower R S k] : is_scalar_tower R S (algebraic_closure k) := is_scalar_tower.of_algebra_map_eq (λ x, ring_hom.congr_arg _ (is_scalar_tower.algebra_map_apply R S k x : _)) /-- Canonical algebra embedding from the `n`th step to the algebraic closure. -/ def of_step_hom (n) : step k n →ₐ[k] algebraic_closure k := { commutes' := λ x, ring.direct_limit.of_f n.zero_le x, .. of_step k n } theorem is_algebraic : algebra.is_algebraic k (algebraic_closure k) := λ z, (is_algebraic_iff_is_integral _).2 $ let ⟨n, x, hx⟩ := exists_of_step k z in hx ▸ is_integral_alg_hom (of_step_hom k n) (step.is_integral k n x) instance : is_alg_closure k (algebraic_closure k) := ⟨algebraic_closure.is_alg_closed k, is_algebraic k⟩ end algebraic_closure
144f48a70dd128646949e1b106f5072135ce8558
9dc8cecdf3c4634764a18254e94d43da07142918
/src/set_theory/game/birthday.lean
d8d1345df6ff3989d1d32720e7c1b015a4e16d05
[ "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,280
lean
/- Copyright (c) 2022 Violeta Hernández Palacios. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Violeta Hernández Palacios -/ import set_theory.game.ordinal /-! # Birthdays of games The birthday of a game is an ordinal that represents at which "step" the game was constructed. We define it recursively as the least ordinal larger than the birthdays of its left and right games. We prove the basic properties about these. # Main declarations - `pgame.birthday`: The birthday of a pre-game. # Todo - Define the birthdays of `game`s and `surreal`s. - Characterize the birthdays of basic arithmetical operations. -/ universe u open ordinal open_locale pgame namespace pgame /-- The birthday of a pre-game is inductively defined as the least strict upper bound of the birthdays of its left and right games. It may be thought as the "step" in which a certain game is constructed. -/ noncomputable def birthday : pgame.{u} → ordinal.{u} | ⟨xl, xr, xL, xR⟩ := max (lsub.{u u} $ λ i, birthday (xL i)) (lsub.{u u} $ λ i, birthday (xR i)) theorem birthday_def (x : pgame) : birthday x = max (lsub.{u u} (λ i, birthday (x.move_left i))) (lsub.{u u} (λ i, birthday (x.move_right i))) := by { cases x, rw birthday, refl } theorem birthday_move_left_lt {x : pgame} (i : x.left_moves) : (x.move_left i).birthday < x.birthday := by { cases x, rw birthday, exact lt_max_of_lt_left (lt_lsub _ i) } theorem birthday_move_right_lt {x : pgame} (i : x.right_moves) : (x.move_right i).birthday < x.birthday := by { cases x, rw birthday, exact lt_max_of_lt_right (lt_lsub _ i) } theorem lt_birthday_iff {x : pgame} {o : ordinal} : o < x.birthday ↔ (∃ i : x.left_moves, o ≤ (x.move_left i).birthday) ∨ (∃ i : x.right_moves, o ≤ (x.move_right i).birthday) := begin split, { rw birthday_def, intro h, cases lt_max_iff.1 h with h' h', { left, rwa lt_lsub_iff at h' }, { right, rwa lt_lsub_iff at h' } }, { rintro (⟨i, hi⟩ | ⟨i, hi⟩), { exact hi.trans_lt (birthday_move_left_lt i) }, { exact hi.trans_lt (birthday_move_right_lt i) } } end theorem relabelling.birthday_congr : ∀ {x y : pgame.{u}}, x ≡r y → birthday x = birthday y | ⟨xl, xr, xL, xR⟩ ⟨yl, yr, yL, yR⟩ r := begin unfold birthday, congr' 1, all_goals { apply lsub_eq_of_range_eq.{u u u}, ext i, split }, all_goals { rintro ⟨j, rfl⟩ }, { exact ⟨_, (r.move_left j).birthday_congr.symm⟩ }, { exact ⟨_, (r.move_left_symm j).birthday_congr⟩ }, { exact ⟨_, (r.move_right j).birthday_congr.symm⟩ }, { exact ⟨_, (r.move_right_symm j).birthday_congr⟩ } end using_well_founded { dec_tac := pgame_wf_tac } @[simp] theorem birthday_add_zero (x : pgame) : birthday (x + 0) = birthday x := (add_zero_relabelling x).birthday_congr @[simp] theorem birthday_zero_add (x : pgame) : birthday (0 + x) = birthday x := (zero_add_relabelling x).birthday_congr @[simp] theorem birthday_eq_zero (x : pgame) : birthday x = 0 ↔ is_empty x.left_moves ∧ is_empty x.right_moves := by rw [birthday_def, max_eq_zero, lsub_eq_zero_iff, lsub_eq_zero_iff] @[simp] theorem birthday_zero : birthday 0 = 0 := by simp [pempty.is_empty] @[simp] theorem birthday_one : birthday 1 = 1 := by { rw birthday_def, simp } @[simp] theorem birthday_star : birthday star = 1 := by { rw birthday_def, simp } @[simp] theorem neg_birthday : ∀ x : pgame, (-x).birthday = x.birthday | ⟨xl, xr, xL, xR⟩ := begin rw [birthday_def, birthday_def, max_comm], congr; funext; apply neg_birthday end @[simp] theorem to_pgame_birthday (o : ordinal) : o.to_pgame.birthday = o := begin induction o using ordinal.induction with o IH, rw [to_pgame_def, pgame.birthday], simp only [lsub_empty, max_zero_right], nth_rewrite 0 ←lsub_typein o, congr' with x, exact IH _ (typein_lt_self x) end theorem le_birthday : ∀ x : pgame, x ≤ x.birthday.to_pgame | ⟨xl, _, xL, _⟩ := le_def.2 ⟨λ i, or.inl ⟨to_left_moves_to_pgame ⟨_, birthday_move_left_lt i⟩, by simp [le_birthday (xL i)]⟩, is_empty_elim⟩ theorem neg_birthday_le (x : pgame) : -x.birthday.to_pgame ≤ x := let h := le_birthday (-x) in by rwa [neg_birthday, neg_le_iff] at h end pgame
9ef301d6f9bed51043c83e3907eb71512169bc64
618003631150032a5676f229d13a079ac875ff77
/src/order/lattice.lean
c72f1b42349a375e6d83ba6e15f2f9e6aa500bc2
[ "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
18,273
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 Defines the inf/sup (semi)-lattice with optionally top/bot type class hierarchy. -/ import order.basic set_option old_structure_cmd true universes u v w variables {α : Type u} {β : Type v} -- TODO: move this eventually, if we decide to use them attribute [ematch] le_trans lt_of_le_of_lt lt_of_lt_of_le lt_trans section -- TODO: this seems crazy, but it also seems to work reasonably well @[ematch] theorem le_antisymm' [partial_order α] : ∀ {a b : α}, (: a ≤ b :) → b ≤ a → a = b := @le_antisymm _ _ end /- TODO: automatic construction of dual definitions / theorems -/ reserve infixl ` ⊓ `:70 reserve infixl ` ⊔ `:65 /-- Typeclass for the `⊔` (`\lub`) notation -/ class has_sup (α : Type u) := (sup : α → α → α) /-- Typeclass for the `⊓` (`\glb`) notation -/ class has_inf (α : Type u) := (inf : α → α → α) infix ⊔ := has_sup.sup infix ⊓ := has_inf.inf section prio set_option default_priority 100 -- see Note [default priority] /-- A `semilattice_sup` is a join-semilattice, that is, a partial order with a join (a.k.a. lub / least upper bound, sup / supremum) operation `⊔` which is the least element larger than both factors. -/ class semilattice_sup (α : Type u) extends has_sup α, partial_order α := (le_sup_left : ∀ a b : α, a ≤ a ⊔ b) (le_sup_right : ∀ a b : α, b ≤ a ⊔ b) (sup_le : ∀ a b c : α, a ≤ c → b ≤ c → a ⊔ b ≤ c) end prio section semilattice_sup variables [semilattice_sup α] {a b c d : α} @[simp] theorem le_sup_left : a ≤ a ⊔ b := semilattice_sup.le_sup_left a b @[ematch] theorem le_sup_left' : a ≤ (: a ⊔ b :) := le_sup_left @[simp] theorem le_sup_right : b ≤ a ⊔ b := semilattice_sup.le_sup_right a b @[ematch] theorem le_sup_right' : b ≤ (: a ⊔ b :) := le_sup_right theorem le_sup_left_of_le (h : c ≤ a) : c ≤ a ⊔ b := le_trans h le_sup_left theorem le_sup_right_of_le (h : c ≤ b) : c ≤ a ⊔ b := le_trans h le_sup_right theorem sup_le : a ≤ c → b ≤ c → a ⊔ b ≤ c := semilattice_sup.sup_le a b c @[simp] theorem sup_le_iff : a ⊔ b ≤ c ↔ a ≤ c ∧ b ≤ c := ⟨assume h : a ⊔ b ≤ c, ⟨le_trans le_sup_left h, le_trans le_sup_right h⟩, assume ⟨h₁, h₂⟩, sup_le h₁ h₂⟩ @[simp] theorem sup_eq_left : a ⊔ b = a ↔ b ≤ a := le_antisymm_iff.trans $ by simp [le_refl] theorem sup_of_le_left (h : b ≤ a) : a ⊔ b = a := sup_eq_left.2 h @[simp] theorem left_eq_sup : a = a ⊔ b ↔ b ≤ a := eq_comm.trans sup_eq_left @[simp] theorem sup_eq_right : a ⊔ b = b ↔ a ≤ b := le_antisymm_iff.trans $ by simp [le_refl] theorem sup_of_le_right (h : a ≤ b) : a ⊔ b = b := sup_eq_right.2 h @[simp] theorem right_eq_sup : b = a ⊔ b ↔ a ≤ b := eq_comm.trans sup_eq_right theorem sup_le_sup (h₁ : a ≤ b) (h₂ : c ≤ d) : a ⊔ c ≤ b ⊔ d := sup_le (le_sup_left_of_le h₁) (le_sup_right_of_le h₂) theorem sup_le_sup_left (h₁ : a ≤ b) (c) : c ⊔ a ≤ c ⊔ b := sup_le_sup (le_refl _) h₁ theorem sup_le_sup_right (h₁ : a ≤ b) (c) : a ⊔ c ≤ b ⊔ c := sup_le_sup h₁ (le_refl _) theorem le_of_sup_eq (h : a ⊔ b = b) : a ≤ b := by { rw ← h, simp } /-- A monotone function on a sup-semilattice is directed. -/ lemma directed_of_mono (f : α → β) {r : β → β → Prop} (H : ∀ ⦃i j⦄, i ≤ j → r (f i) (f j)) : directed r f := λ a b, ⟨a ⊔ b, H le_sup_left, H le_sup_right⟩ lemma sup_ind [is_total α (≤)] (a b : α) {p : α → Prop} (ha : p a) (hb : p b) : p (a ⊔ b) := (is_total.total a b).elim (λ h : a ≤ b, by rwa sup_eq_right.2 h) (λ h, by rwa sup_eq_left.2 h) @[simp] lemma sup_lt_iff [is_total α (≤)] {a b c : α} : b ⊔ c < a ↔ b < a ∧ c < a := ⟨λ h, ⟨lt_of_le_of_lt le_sup_left h, lt_of_le_of_lt le_sup_right h⟩, λ h, sup_ind b c h.1 h.2⟩ @[simp] theorem sup_idem : a ⊔ a = a := by apply le_antisymm; simp instance sup_is_idempotent : is_idempotent α (⊔) := ⟨@sup_idem _ _⟩ theorem sup_comm : a ⊔ b = b ⊔ a := by apply le_antisymm; simp instance sup_is_commutative : is_commutative α (⊔) := ⟨@sup_comm _ _⟩ theorem sup_assoc : a ⊔ b ⊔ c = a ⊔ (b ⊔ c) := le_antisymm (sup_le (sup_le le_sup_left (le_sup_right_of_le le_sup_left)) (le_sup_right_of_le le_sup_right)) (sup_le (le_sup_left_of_le le_sup_left) (sup_le (le_sup_left_of_le le_sup_right) le_sup_right)) instance sup_is_associative : is_associative α (⊔) := ⟨@sup_assoc _ _⟩ @[simp] lemma sup_left_idem : a ⊔ (a ⊔ b) = a ⊔ b := by rw [← sup_assoc, sup_idem] @[simp] lemma sup_right_idem : (a ⊔ b) ⊔ b = a ⊔ b := by rw [sup_assoc, sup_idem] lemma sup_left_comm (a b c : α) : a ⊔ (b ⊔ c) = b ⊔ (a ⊔ c) := by rw [← sup_assoc, ← sup_assoc, @sup_comm α _ a] lemma forall_le_or_exists_lt_sup (a : α) : (∀b, b ≤ a) ∨ (∃b, a < b) := suffices (∃b, ¬b ≤ a) → (∃b, a < b), by rwa [classical.or_iff_not_imp_left, classical.not_forall], assume ⟨b, hb⟩, ⟨a ⊔ b, lt_of_le_of_ne le_sup_left $ mt left_eq_sup.1 hb⟩ theorem semilattice_sup.ext_sup {α} {A B : semilattice_sup α} (H : ∀ x y : α, (by haveI := A; exact x ≤ y) ↔ x ≤ y) (x y : α) : (by haveI := A; exact (x ⊔ y)) = x ⊔ y := eq_of_forall_ge_iff $ λ c, by simp only [sup_le_iff]; rw [← H, @sup_le_iff α A, H, H] theorem semilattice_sup.ext {α} {A B : semilattice_sup α} (H : ∀ x y : α, (by haveI := A; exact x ≤ y) ↔ x ≤ y) : A = B := begin haveI this := partial_order.ext H, have ss := funext (λ x, funext $ semilattice_sup.ext_sup H x), cases A; cases B; injection this; congr' end lemma directed_of_sup {β : Type*} {r : β → β → Prop} {f : α → β} (hf : ∀a₁ a₂, a₁ ≤ a₂ → r (f a₁) (f a₂)) : directed r f := assume x y, ⟨x ⊔ y, hf _ _ le_sup_left, hf _ _ le_sup_right⟩ end semilattice_sup section prio set_option default_priority 100 -- see Note [default priority] /-- A `semilattice_inf` is a meet-semilattice, that is, a partial order with a meet (a.k.a. glb / greatest lower bound, inf / infimum) operation `⊓` which is the greatest element smaller than both factors. -/ class semilattice_inf (α : Type u) extends has_inf α, partial_order α := (inf_le_left : ∀ a b : α, a ⊓ b ≤ a) (inf_le_right : ∀ a b : α, a ⊓ b ≤ b) (le_inf : ∀ a b c : α, a ≤ b → a ≤ c → a ≤ b ⊓ c) end prio section semilattice_inf variables [semilattice_inf α] {a b c d : α} @[simp] theorem inf_le_left : a ⊓ b ≤ a := semilattice_inf.inf_le_left a b @[ematch] theorem inf_le_left' : (: a ⊓ b :) ≤ a := semilattice_inf.inf_le_left a b @[simp] theorem inf_le_right : a ⊓ b ≤ b := semilattice_inf.inf_le_right a b @[ematch] theorem inf_le_right' : (: a ⊓ b :) ≤ b := semilattice_inf.inf_le_right a b theorem le_inf : a ≤ b → a ≤ c → a ≤ b ⊓ c := semilattice_inf.le_inf a b c theorem inf_le_left_of_le (h : a ≤ c) : a ⊓ b ≤ c := le_trans inf_le_left h theorem inf_le_right_of_le (h : b ≤ c) : a ⊓ b ≤ c := le_trans inf_le_right h @[simp] theorem le_inf_iff : a ≤ b ⊓ c ↔ a ≤ b ∧ a ≤ c := ⟨assume h : a ≤ b ⊓ c, ⟨le_trans h inf_le_left, le_trans h inf_le_right⟩, assume ⟨h₁, h₂⟩, le_inf h₁ h₂⟩ @[simp] theorem inf_eq_left : a ⊓ b = a ↔ a ≤ b := le_antisymm_iff.trans $ by simp [le_refl] theorem inf_of_le_left (h : a ≤ b) : a ⊓ b = a := inf_eq_left.2 h @[simp] theorem left_eq_inf : a = a ⊓ b ↔ a ≤ b := eq_comm.trans inf_eq_left @[simp] theorem inf_eq_right : a ⊓ b = b ↔ b ≤ a := le_antisymm_iff.trans $ by simp [le_refl] theorem inf_of_le_right (h : b ≤ a) : a ⊓ b = b := inf_eq_right.2 h @[simp] theorem right_eq_inf : b = a ⊓ b ↔ b ≤ a := eq_comm.trans inf_eq_right theorem inf_le_inf (h₁ : a ≤ b) (h₂ : c ≤ d) : a ⊓ c ≤ b ⊓ d := le_inf (inf_le_left_of_le h₁) (inf_le_right_of_le h₂) lemma inf_le_inf_right (a : α) {b c : α} (h : b ≤ c) : b ⊓ a ≤ c ⊓ a := inf_le_inf h (le_refl _) lemma inf_le_inf_left (a : α) {b c : α} (h : b ≤ c) : a ⊓ b ≤ a ⊓ c := inf_le_inf (le_refl _) h theorem le_of_inf_eq (h : a ⊓ b = a) : a ≤ b := by { rw ← h, simp } lemma inf_ind [is_total α (≤)] (a b : α) {p : α → Prop} (ha : p a) (hb : p b) : p (a ⊓ b) := (is_total.total a b).elim (λ h : a ≤ b, by rwa inf_eq_left.2 h) (λ h, by rwa inf_eq_right.2 h) @[simp] lemma lt_inf_iff [is_total α (≤)] {a b c : α} : a < b ⊓ c ↔ a < b ∧ a < c := ⟨λ h, ⟨lt_of_lt_of_le h inf_le_left, lt_of_lt_of_le h inf_le_right⟩, λ h, inf_ind b c h.1 h.2⟩ @[simp] theorem inf_idem : a ⊓ a = a := by apply le_antisymm; simp instance inf_is_idempotent : is_idempotent α (⊓) := ⟨@inf_idem _ _⟩ theorem inf_comm : a ⊓ b = b ⊓ a := by apply le_antisymm; simp instance inf_is_commutative : is_commutative α (⊓) := ⟨@inf_comm _ _⟩ theorem inf_assoc : a ⊓ b ⊓ c = a ⊓ (b ⊓ c) := le_antisymm (le_inf (inf_le_left_of_le inf_le_left) (le_inf (inf_le_left_of_le inf_le_right) inf_le_right)) (le_inf (le_inf inf_le_left (inf_le_right_of_le inf_le_left)) (inf_le_right_of_le inf_le_right)) instance inf_is_associative : is_associative α (⊓) := ⟨@inf_assoc _ _⟩ @[simp] lemma inf_left_idem : a ⊓ (a ⊓ b) = a ⊓ b := by rw [← inf_assoc, inf_idem] @[simp] lemma inf_right_idem : (a ⊓ b) ⊓ b = a ⊓ b := by rw [inf_assoc, inf_idem] lemma inf_left_comm (a b c : α) : a ⊓ (b ⊓ c) = b ⊓ (a ⊓ c) := by rw [← inf_assoc, ← inf_assoc, @inf_comm α _ a] lemma forall_le_or_exists_lt_inf (a : α) : (∀b, a ≤ b) ∨ (∃b, b < a) := suffices (∃b, ¬a ≤ b) → (∃b, b < a), by rwa [classical.or_iff_not_imp_left, classical.not_forall], assume ⟨b, hb⟩, have a ⊓ b ≠ a, from assume eq, hb $ eq ▸ inf_le_right, ⟨a ⊓ b, lt_of_le_of_ne inf_le_left ‹a ⊓ b ≠ a›⟩ theorem semilattice_inf.ext_inf {α} {A B : semilattice_inf α} (H : ∀ x y : α, (by haveI := A; exact x ≤ y) ↔ x ≤ y) (x y : α) : (by haveI := A; exact (x ⊓ y)) = x ⊓ y := eq_of_forall_le_iff $ λ c, by simp only [le_inf_iff]; rw [← H, @le_inf_iff α A, H, H] theorem semilattice_inf.ext {α} {A B : semilattice_inf α} (H : ∀ x y : α, (by haveI := A; exact x ≤ y) ↔ x ≤ y) : A = B := begin haveI this := partial_order.ext H, have ss := funext (λ x, funext $ semilattice_inf.ext_inf H x), cases A; cases B; injection this; congr' end /-- An antimonotone function on an inf-semilattice is directed. -/ lemma directed_of_inf {r : β → β → Prop} {f : α → β} (hf : ∀a₁ a₂, a₁ ≤ a₂ → r (f a₂) (f a₁)) : directed r f := assume x y, ⟨x ⊓ y, hf _ _ inf_le_left, hf _ _ inf_le_right⟩ end semilattice_inf /- Lattices -/ section prio set_option default_priority 100 -- see Note [default priority] /-- A lattice is a join-semilattice which is also a meet-semilattice. -/ class lattice (α : Type u) extends semilattice_sup α, semilattice_inf α end prio section lattice variables [lattice α] {a b c d : α} /- Distributivity laws -/ /- TODO: better names? -/ theorem sup_inf_le : a ⊔ (b ⊓ c) ≤ (a ⊔ b) ⊓ (a ⊔ c) := le_inf (sup_le_sup_left inf_le_left _) (sup_le_sup_left inf_le_right _) theorem le_inf_sup : (a ⊓ b) ⊔ (a ⊓ c) ≤ a ⊓ (b ⊔ c) := sup_le (inf_le_inf_left _ le_sup_left) (inf_le_inf_left _ le_sup_right) theorem inf_sup_self : a ⊓ (a ⊔ b) = a := by simp theorem sup_inf_self : a ⊔ (a ⊓ b) = a := by simp theorem lattice.ext {α} {A B : lattice α} (H : ∀ x y : α, (by haveI := A; exact x ≤ y) ↔ x ≤ y) : A = B := begin have SS : @lattice.to_semilattice_sup α A = @lattice.to_semilattice_sup α B := semilattice_sup.ext H, have II := semilattice_inf.ext H, resetI, cases A; cases B; injection SS; injection II; congr' end end lattice section prio set_option default_priority 100 -- see Note [default priority] /-- A distributive lattice is a lattice that satisfies any of four equivalent distribution properties (of sup over inf or inf over sup, on the left or right). A classic example of a distributive lattice is the lattice of subsets of a set, and in fact this example is generic in the sense that every distributive lattice is realizable as a sublattice of a powerset lattice. -/ class distrib_lattice α extends lattice α := (le_sup_inf : ∀x y z : α, (x ⊔ y) ⊓ (x ⊔ z) ≤ x ⊔ (y ⊓ z)) end prio section distrib_lattice variables [distrib_lattice α] {x y z : α} theorem le_sup_inf : ∀{x y z : α}, (x ⊔ y) ⊓ (x ⊔ z) ≤ x ⊔ (y ⊓ z) := distrib_lattice.le_sup_inf theorem sup_inf_left : x ⊔ (y ⊓ z) = (x ⊔ y) ⊓ (x ⊔ z) := le_antisymm sup_inf_le le_sup_inf theorem sup_inf_right : (y ⊓ z) ⊔ x = (y ⊔ x) ⊓ (z ⊔ x) := by simp only [sup_inf_left, λy:α, @sup_comm α _ y x, eq_self_iff_true] theorem inf_sup_left : x ⊓ (y ⊔ z) = (x ⊓ y) ⊔ (x ⊓ z) := calc x ⊓ (y ⊔ z) = (x ⊓ (x ⊔ z)) ⊓ (y ⊔ z) : by rw [inf_sup_self] ... = x ⊓ ((x ⊓ y) ⊔ z) : by simp only [inf_assoc, sup_inf_right, eq_self_iff_true] ... = (x ⊔ (x ⊓ y)) ⊓ ((x ⊓ y) ⊔ z) : by rw [sup_inf_self] ... = ((x ⊓ y) ⊔ x) ⊓ ((x ⊓ y) ⊔ z) : by rw [sup_comm] ... = (x ⊓ y) ⊔ (x ⊓ z) : by rw [sup_inf_left] theorem inf_sup_right : (y ⊔ z) ⊓ x = (y ⊓ x) ⊔ (z ⊓ x) := by simp only [inf_sup_left, λy:α, @inf_comm α _ y x, eq_self_iff_true] lemma le_of_inf_le_sup_le (h₁ : x ⊓ z ≤ y ⊓ z) (h₂ : x ⊔ z ≤ y ⊔ z) : x ≤ y := calc x ≤ (y ⊓ z) ⊔ x : le_sup_right ... = (y ⊔ x) ⊓ (x ⊔ z) : by rw [sup_inf_right, @sup_comm _ _ x] ... ≤ (y ⊔ x) ⊓ (y ⊔ z) : inf_le_inf_left _ h₂ ... = y ⊔ (x ⊓ z) : sup_inf_left.symm ... ≤ y ⊔ (y ⊓ z) : sup_le_sup_left h₁ _ ... ≤ _ : sup_le (le_refl y) inf_le_left lemma eq_of_inf_eq_sup_eq {α : Type u} [distrib_lattice α] {a b c : α} (h₁ : b ⊓ a = c ⊓ a) (h₂ : b ⊔ a = c ⊔ a) : b = c := le_antisymm (le_of_inf_le_sup_le (le_of_eq h₁) (le_of_eq h₂)) (le_of_inf_le_sup_le (le_of_eq h₁.symm) (le_of_eq h₂.symm)) end distrib_lattice /- Lattices derived from linear orders -/ @[priority 100] -- see Note [lower instance priority] instance lattice_of_decidable_linear_order {α : Type u} [o : decidable_linear_order α] : lattice α := { sup := max, le_sup_left := le_max_left, le_sup_right := le_max_right, sup_le := assume a b c, max_le, inf := min, inf_le_left := min_le_left, inf_le_right := min_le_right, le_inf := assume a b c, le_min, ..o } theorem sup_eq_max [decidable_linear_order α] {x y : α} : x ⊔ y = max x y := rfl theorem inf_eq_min [decidable_linear_order α] {x y : α} : x ⊓ y = min x y := rfl @[priority 100] -- see Note [lower instance priority] instance distrib_lattice_of_decidable_linear_order {α : Type u} [o : decidable_linear_order α] : distrib_lattice α := { le_sup_inf := assume a b c, match le_total b c with | or.inl h := inf_le_left_of_le $ sup_le_sup_left (le_inf (le_refl b) h) _ | or.inr h := inf_le_right_of_le $ sup_le_sup_left (le_inf h (le_refl c)) _ end, ..lattice_of_decidable_linear_order } instance nat.distrib_lattice : distrib_lattice ℕ := by apply_instance namespace monotone lemma le_map_sup [semilattice_sup α] [semilattice_sup β] {f : α → β} (h : monotone f) (x y : α) : f x ⊔ f y ≤ f (x ⊔ y) := sup_le (h le_sup_left) (h le_sup_right) lemma map_inf_le [semilattice_inf α] [semilattice_inf β] {f : α → β} (h : monotone f) (x y : α) : f (x ⊓ y) ≤ f x ⊓ f y := le_inf (h inf_le_left) (h inf_le_right) end monotone namespace order_dual variable (α) instance [has_inf α] : has_sup (order_dual α) := ⟨((⊓) : α → α → α)⟩ instance [has_sup α] : has_inf (order_dual α) := ⟨((⊔) : α → α → α)⟩ instance [semilattice_inf α] : semilattice_sup (order_dual α) := { le_sup_left := @inf_le_left α _, le_sup_right := @inf_le_right α _, sup_le := assume a b c hca hcb, @le_inf α _ _ _ _ hca hcb, .. order_dual.partial_order α, .. order_dual.has_sup α } instance [semilattice_sup α] : semilattice_inf (order_dual α) := { inf_le_left := @le_sup_left α _, inf_le_right := @le_sup_right α _, le_inf := assume a b c hca hcb, @sup_le α _ _ _ _ hca hcb, .. order_dual.partial_order α, .. order_dual.has_inf α } instance [lattice α] : lattice (order_dual α) := { .. order_dual.semilattice_sup α, .. order_dual.semilattice_inf α } instance [distrib_lattice α] : distrib_lattice (order_dual α) := { le_sup_inf := assume x y z, le_of_eq inf_sup_left.symm, .. order_dual.lattice α } end order_dual namespace prod variables (α β) instance [has_sup α] [has_sup β] : has_sup (α × β) := ⟨λp q, ⟨p.1 ⊔ q.1, p.2 ⊔ q.2⟩⟩ instance [has_inf α] [has_inf β] : has_inf (α × β) := ⟨λp q, ⟨p.1 ⊓ q.1, p.2 ⊓ q.2⟩⟩ instance [semilattice_sup α] [semilattice_sup β] : semilattice_sup (α × β) := { sup_le := assume a b c h₁ h₂, ⟨sup_le h₁.1 h₂.1, sup_le h₁.2 h₂.2⟩, le_sup_left := assume a b, ⟨le_sup_left, le_sup_left⟩, le_sup_right := assume a b, ⟨le_sup_right, le_sup_right⟩, .. prod.partial_order α β, .. prod.has_sup α β } instance [semilattice_inf α] [semilattice_inf β] : semilattice_inf (α × β) := { le_inf := assume a b c h₁ h₂, ⟨le_inf h₁.1 h₂.1, le_inf h₁.2 h₂.2⟩, inf_le_left := assume a b, ⟨inf_le_left, inf_le_left⟩, inf_le_right := assume a b, ⟨inf_le_right, inf_le_right⟩, .. prod.partial_order α β, .. prod.has_inf α β } instance [lattice α] [lattice β] : lattice (α × β) := { .. prod.semilattice_inf α β, .. prod.semilattice_sup α β } instance [distrib_lattice α] [distrib_lattice β] : distrib_lattice (α × β) := { le_sup_inf := assume a b c, ⟨le_sup_inf, le_sup_inf⟩, .. prod.lattice α β } end prod
66ce4be1e3da298b4ac5de3004470af7b7665e5a
9dc8cecdf3c4634764a18254e94d43da07142918
/src/analysis/normed_space/enorm.lean
4af078e526972e14ae1cdd2537048bee92eeaa9b
[ "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
7,853
lean
/- Copyright (c) 2020 Yury G. Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury G. Kudryashov -/ import analysis.normed_space.basic /-! # Extended norm In this file we define a structure `enorm 𝕜 V` representing an extended norm (i.e., a norm that can take the value `∞`) on a vector space `V` over a normed field `𝕜`. We do not use `class` for an `enorm` because the same space can have more than one extended norm. For example, the space of measurable functions `f : α → ℝ` has a family of `L_p` extended norms. We prove some basic inequalities, then define * `emetric_space` structure on `V` corresponding to `e : enorm 𝕜 V`; * the subspace of vectors with finite norm, called `e.finite_subspace`; * a `normed_space` structure on this space. The last definition is an instance because the type involves `e`. ## Implementation notes We do not define extended normed groups. They can be added to the chain once someone will need them. ## Tags normed space, extended norm -/ noncomputable theory local attribute [instance, priority 1001] classical.prop_decidable open_locale ennreal /-- Extended norm on a vector space. As in the case of normed spaces, we require only `∥c • x∥ ≤ ∥c∥ * ∥x∥` in the definition, then prove an equality in `map_smul`. -/ structure enorm (𝕜 : Type*) (V : Type*) [normed_field 𝕜] [add_comm_group V] [module 𝕜 V] := (to_fun : V → ℝ≥0∞) (eq_zero' : ∀ x, to_fun x = 0 → x = 0) (map_add_le' : ∀ x y : V, to_fun (x + y) ≤ to_fun x + to_fun y) (map_smul_le' : ∀ (c : 𝕜) (x : V), to_fun (c • x) ≤ ∥c∥₊ * to_fun x) namespace enorm variables {𝕜 : Type*} {V : Type*} [normed_field 𝕜] [add_comm_group V] [module 𝕜 V] (e : enorm 𝕜 V) instance : has_coe_to_fun (enorm 𝕜 V) (λ _, V → ℝ≥0∞) := ⟨enorm.to_fun⟩ lemma coe_fn_injective : function.injective (coe_fn : enorm 𝕜 V → (V → ℝ≥0∞)) := λ e₁ e₂ h, by cases e₁; cases e₂; congr; exact h @[ext] lemma ext {e₁ e₂ : enorm 𝕜 V} (h : ∀ x, e₁ x = e₂ x) : e₁ = e₂ := coe_fn_injective $ funext h lemma ext_iff {e₁ e₂ : enorm 𝕜 V} : e₁ = e₂ ↔ ∀ x, e₁ x = e₂ x := ⟨λ h x, h ▸ rfl, ext⟩ @[simp, norm_cast] lemma coe_inj {e₁ e₂ : enorm 𝕜 V} : (e₁ : V → ℝ≥0∞) = e₂ ↔ e₁ = e₂ := coe_fn_injective.eq_iff @[simp] lemma map_smul (c : 𝕜) (x : V) : e (c • x) = ∥c∥₊ * e x := le_antisymm (e.map_smul_le' c x) $ begin by_cases hc : c = 0, { simp [hc] }, calc (∥c∥₊ : ℝ≥0∞) * e x = ∥c∥₊ * e (c⁻¹ • c • x) : by rw [inv_smul_smul₀ hc] ... ≤ ∥c∥₊ * (∥c⁻¹∥₊ * e (c • x)) : _ ... = e (c • x) : _, { exact ennreal.mul_le_mul le_rfl (e.map_smul_le' _ _) }, { rw [← mul_assoc, nnnorm_inv, ennreal.coe_inv, ennreal.mul_inv_cancel _ ennreal.coe_ne_top, one_mul]; simp [hc] } end @[simp] lemma map_zero : e 0 = 0 := by { rw [← zero_smul 𝕜 (0:V), e.map_smul], norm_num } @[simp] lemma eq_zero_iff {x : V} : e x = 0 ↔ x = 0 := ⟨e.eq_zero' x, λ h, h.symm ▸ e.map_zero⟩ @[simp] lemma map_neg (x : V) : e (-x) = e x := calc e (-x) = ∥(-1 : 𝕜)∥₊ * e x : by rw [← map_smul, neg_one_smul] ... = e x : by simp lemma map_sub_rev (x y : V) : e (x - y) = e (y - x) := by rw [← neg_sub, e.map_neg] lemma map_add_le (x y : V) : e (x + y) ≤ e x + e y := e.map_add_le' x y lemma map_sub_le (x y : V) : e (x - y) ≤ e x + e y := calc e (x - y) = e (x + -y) : by rw sub_eq_add_neg ... ≤ e x + e (-y) : e.map_add_le x (-y) ... = e x + e y : by rw [e.map_neg] instance : partial_order (enorm 𝕜 V) := { le := λ e₁ e₂, ∀ x, e₁ x ≤ e₂ x, le_refl := λ e x, le_rfl, le_trans := λ e₁ e₂ e₃ h₁₂ h₂₃ x, le_trans (h₁₂ x) (h₂₃ x), le_antisymm := λ e₁ e₂ h₁₂ h₂₁, ext $ λ x, le_antisymm (h₁₂ x) (h₂₁ x) } /-- The `enorm` sending each non-zero vector to infinity. -/ noncomputable instance : has_top (enorm 𝕜 V) := ⟨{ to_fun := λ x, if x = 0 then 0 else ⊤, eq_zero' := λ x, by { split_ifs; simp [*] }, map_add_le' := λ x y, begin split_ifs with hxy hx hy hy hx hy hy; try { simp [*] }, simpa [hx, hy] using hxy end, map_smul_le' := λ c x, begin split_ifs with hcx hx hx; simp only [smul_eq_zero, not_or_distrib] at hcx, { simp only [mul_zero, le_refl] }, { have : c = 0, by tauto, simp [this] }, { tauto }, { simp [hcx.1] } end }⟩ noncomputable instance : inhabited (enorm 𝕜 V) := ⟨⊤⟩ lemma top_map {x : V} (hx : x ≠ 0) : (⊤ : enorm 𝕜 V) x = ⊤ := if_neg hx noncomputable instance : order_top (enorm 𝕜 V) := { top := ⊤, le_top := λ e x, if h : x = 0 then by simp [h] else by simp [top_map h] } noncomputable instance : semilattice_sup (enorm 𝕜 V) := { le := (≤), lt := (<), sup := λ e₁ e₂, { to_fun := λ x, max (e₁ x) (e₂ x), eq_zero' := λ x h, e₁.eq_zero_iff.1 (ennreal.max_eq_zero_iff.1 h).1, map_add_le' := λ x y, max_le (le_trans (e₁.map_add_le _ _) $ add_le_add (le_max_left _ _) (le_max_left _ _)) (le_trans (e₂.map_add_le _ _) $ add_le_add (le_max_right _ _) (le_max_right _ _)), map_smul_le' := λ c x, le_of_eq $ by simp only [map_smul, ennreal.mul_max] }, le_sup_left := λ e₁ e₂ x, le_max_left _ _, le_sup_right := λ e₁ e₂ x, le_max_right _ _, sup_le := λ e₁ e₂ e₃ h₁ h₂ x, max_le (h₁ x) (h₂ x), .. enorm.partial_order } @[simp, norm_cast] lemma coe_max (e₁ e₂ : enorm 𝕜 V) : ⇑(e₁ ⊔ e₂) = λ x, max (e₁ x) (e₂ x) := rfl @[norm_cast] lemma max_map (e₁ e₂ : enorm 𝕜 V) (x : V) : (e₁ ⊔ e₂) x = max (e₁ x) (e₂ x) := rfl /-- Structure of an `emetric_space` defined by an extended norm. -/ @[reducible] def emetric_space : emetric_space V := { edist := λ x y, e (x - y), edist_self := λ x, by simp, eq_of_edist_eq_zero := λ x y, by simp [sub_eq_zero], edist_comm := e.map_sub_rev, edist_triangle := λ x y z, calc e (x - z) = e ((x - y) + (y - z)) : by rw [sub_add_sub_cancel] ... ≤ e (x - y) + e (y - z) : e.map_add_le (x - y) (y - z) } /-- The subspace of vectors with finite enorm. -/ def finite_subspace : subspace 𝕜 V := { carrier := {x | e x < ⊤}, zero_mem' := by simp, add_mem' := λ x y hx hy, lt_of_le_of_lt (e.map_add_le x y) (ennreal.add_lt_top.2 ⟨hx, hy⟩), smul_mem' := λ c x (hx : _ < _), calc e (c • x) = ∥c∥₊ * e x : e.map_smul c x ... < ⊤ : ennreal.mul_lt_top ennreal.coe_ne_top hx.ne } /-- Metric space structure on `e.finite_subspace`. We use `emetric_space.to_metric_space` to ensure that this definition agrees with `e.emetric_space`. -/ instance : metric_space e.finite_subspace := begin letI := e.emetric_space, refine emetric_space.to_metric_space (λ x y, _), change e (x - y) ≠ ⊤, exact ne_top_of_le_ne_top (ennreal.add_lt_top.2 ⟨x.2, y.2⟩).ne (e.map_sub_le x y) end lemma finite_dist_eq (x y : e.finite_subspace) : dist x y = (e (x - y)).to_real := rfl lemma finite_edist_eq (x y : e.finite_subspace) : edist x y = e (x - y) := rfl /-- Normed group instance on `e.finite_subspace`. -/ instance : normed_add_comm_group e.finite_subspace := { norm := λ x, (e x).to_real, dist_eq := λ x y, rfl, .. finite_subspace.metric_space e, .. submodule.add_comm_group _ } lemma finite_norm_eq (x : e.finite_subspace) : ∥x∥ = (e x).to_real := rfl /-- Normed space instance on `e.finite_subspace`. -/ instance : normed_space 𝕜 e.finite_subspace := { norm_smul_le := λ c x, le_of_eq $ by simp [finite_norm_eq, ennreal.to_real_mul] } end enorm
60e7110237875f3aad29a69e5cb00cbb94cec2b6
9dc8cecdf3c4634764a18254e94d43da07142918
/src/data/rat/cast.lean
780ae00f4e71f017373dce779fdb93a13d9dde8e
[ "Apache-2.0" ]
permissive
jcommelin/mathlib
d8456447c36c176e14d96d9e76f39841f69d2d9b
ee8279351a2e434c2852345c51b728d22af5a156
refs/heads/master
1,664,782,136,488
1,663,638,983,000
1,663,638,983,000
132,563,656
0
0
Apache-2.0
1,663,599,929,000
1,525,760,539,000
Lean
UTF-8
Lean
false
false
15,313
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.rat.order import data.int.char_zero import algebra.field.opposite /-! # Casts for Rational Numbers ## Summary We define the canonical injection from ℚ into an arbitrary division ring and prove various casting lemmas showing the well-behavedness of this injection. ## Notations - `/.` is infix notation for `rat.mk`. ## Tags rat, rationals, field, ℚ, numerator, denominator, num, denom, cast, coercion, casting -/ open_locale big_operators variables {F ι α β : Type*} namespace rat open_locale rat section with_div_ring variable [division_ring α] @[simp] theorem cast_of_int (n : ℤ) : (of_int n : α) = n := (cast_def _).trans $ show (n / (1:ℕ) : α) = n, by rw [nat.cast_one, div_one] @[simp, norm_cast] theorem cast_coe_int (n : ℤ) : ((n : ℚ) : α) = n := by rw [coe_int_eq_of_int, cast_of_int] @[simp, norm_cast] theorem cast_coe_nat (n : ℕ) : ((n : ℚ) : α) = n := by rw [← int.cast_coe_nat, cast_coe_int, int.cast_coe_nat] @[simp, norm_cast] theorem cast_zero : ((0 : ℚ) : α) = 0 := (cast_of_int _).trans int.cast_zero @[simp, norm_cast] theorem cast_one : ((1 : ℚ) : α) = 1 := (cast_of_int _).trans int.cast_one theorem cast_commute (r : ℚ) (a : α) : commute ↑r a := by simpa only [cast_def] using (r.1.cast_commute a).div_left (r.2.cast_commute a) theorem cast_comm (r : ℚ) (a : α) : (r : α) * a = a * r := (cast_commute r a).eq theorem commute_cast (a : α) (r : ℚ) : commute a r := (r.cast_commute a).symm @[norm_cast] theorem cast_mk_of_ne_zero (a b : ℤ) (b0 : (b:α) ≠ 0) : (a /. b : α) = a / b := begin have b0' : b ≠ 0, { refine mt _ b0, simp {contextual := tt} }, cases e : a /. b with n d h c, have d0 : (d:α) ≠ 0, { intro d0, have dd := denom_dvd a b, cases (show (d:ℤ) ∣ b, by rwa e at dd) with k ke, have : (b:α) = (d:α) * (k:α), {rw [ke, int.cast_mul, int.cast_coe_nat]}, rw [d0, zero_mul] at this, contradiction }, rw [num_denom'] at e, have := congr_arg (coe : ℤ → α) ((mk_eq b0' $ ne_of_gt $ int.coe_nat_pos.2 h).1 e), rw [int.cast_mul, int.cast_mul, int.cast_coe_nat] at this, symmetry, rw [cast_def, div_eq_mul_inv, eq_div_iff_mul_eq d0, mul_assoc, (d.commute_cast _).eq, ← mul_assoc, this, mul_assoc, mul_inv_cancel b0, mul_one] end @[norm_cast] theorem cast_add_of_ne_zero : ∀ {m n : ℚ}, (m.denom : α) ≠ 0 → (n.denom : α) ≠ 0 → ((m + n : ℚ) : α) = m + n | ⟨n₁, d₁, h₁, c₁⟩ ⟨n₂, d₂, h₂, c₂⟩ := λ (d₁0 : (d₁:α) ≠ 0) (d₂0 : (d₂:α) ≠ 0), begin have d₁0' : (d₁:ℤ) ≠ 0 := int.coe_nat_ne_zero.2 (λ e, by rw e at d₁0; exact d₁0 nat.cast_zero), have d₂0' : (d₂:ℤ) ≠ 0 := int.coe_nat_ne_zero.2 (λ e, by rw e at d₂0; exact d₂0 nat.cast_zero), rw [num_denom', num_denom', add_def d₁0' d₂0'], suffices : (n₁ * (d₂ * (d₂⁻¹ * d₁⁻¹)) + n₂ * (d₁ * d₂⁻¹) * d₁⁻¹ : α) = n₁ * d₁⁻¹ + n₂ * d₂⁻¹, { rw [cast_mk_of_ne_zero, cast_mk_of_ne_zero, cast_mk_of_ne_zero], { simpa [division_def, left_distrib, right_distrib, mul_inv_rev, d₁0, d₂0, mul_assoc] }, all_goals {simp [d₁0, d₂0]} }, rw [← mul_assoc (d₂:α), mul_inv_cancel d₂0, one_mul, (nat.cast_commute _ _).eq], simp [d₁0, mul_assoc] end @[simp, norm_cast] theorem cast_neg : ∀ n, ((-n : ℚ) : α) = -n | ⟨n, d, h, c⟩ := by simpa only [cast_def] using show (↑-n / d : α) = -(n / d), by rw [div_eq_mul_inv, div_eq_mul_inv, int.cast_neg, neg_mul_eq_neg_mul] @[norm_cast] theorem cast_sub_of_ne_zero {m n : ℚ} (m0 : (m.denom : α) ≠ 0) (n0 : (n.denom : α) ≠ 0) : ((m - n : ℚ) : α) = m - n := have ((-n).denom : α) ≠ 0, by cases n; exact n0, by simp [sub_eq_add_neg, (cast_add_of_ne_zero m0 this)] @[norm_cast] theorem cast_mul_of_ne_zero : ∀ {m n : ℚ}, (m.denom : α) ≠ 0 → (n.denom : α) ≠ 0 → ((m * n : ℚ) : α) = m * n | ⟨n₁, d₁, h₁, c₁⟩ ⟨n₂, d₂, h₂, c₂⟩ := λ (d₁0 : (d₁:α) ≠ 0) (d₂0 : (d₂:α) ≠ 0), begin have d₁0' : (d₁:ℤ) ≠ 0 := int.coe_nat_ne_zero.2 (λ e, by rw e at d₁0; exact d₁0 nat.cast_zero), have d₂0' : (d₂:ℤ) ≠ 0 := int.coe_nat_ne_zero.2 (λ e, by rw e at d₂0; exact d₂0 nat.cast_zero), rw [num_denom', num_denom', mul_def d₁0' d₂0'], suffices : (n₁ * ((n₂ * d₂⁻¹) * d₁⁻¹) : α) = n₁ * (d₁⁻¹ * (n₂ * d₂⁻¹)), { rw [cast_mk_of_ne_zero, cast_mk_of_ne_zero, cast_mk_of_ne_zero], { simpa [division_def, mul_inv_rev, d₁0, d₂0, mul_assoc] }, all_goals {simp [d₁0, d₂0]} }, rw [(d₁.commute_cast (_:α)).inv_right₀.eq] end @[simp] theorem cast_inv_nat (n : ℕ) : ((n⁻¹ : ℚ) : α) = n⁻¹ := begin cases n, { simp }, simp_rw [coe_nat_eq_mk, inv_def, mk, mk_nat, dif_neg n.succ_ne_zero, mk_pnat], simp [cast_def] end @[simp] theorem cast_inv_int (n : ℤ) : ((n⁻¹ : ℚ) : α) = n⁻¹ := begin cases n, { simp [cast_inv_nat] }, { simp only [int.cast_neg_succ_of_nat, ← nat.cast_succ, cast_neg, inv_neg, cast_inv_nat] } end @[norm_cast] theorem cast_inv_of_ne_zero : ∀ {n : ℚ}, (n.num : α) ≠ 0 → (n.denom : α) ≠ 0 → ((n⁻¹ : ℚ) : α) = n⁻¹ | ⟨n, d, h, c⟩ := λ (n0 : (n:α) ≠ 0) (d0 : (d:α) ≠ 0), begin have n0' : (n:ℤ) ≠ 0 := λ e, by rw e at n0; exact n0 int.cast_zero, have d0' : (d:ℤ) ≠ 0 := int.coe_nat_ne_zero.2 (λ e, by rw e at d0; exact d0 nat.cast_zero), rw [num_denom', inv_def], rw [cast_mk_of_ne_zero, cast_mk_of_ne_zero, inv_div]; simp [n0, d0] end @[norm_cast] theorem cast_div_of_ne_zero {m n : ℚ} (md : (m.denom : α) ≠ 0) (nn : (n.num : α) ≠ 0) (nd : (n.denom : α) ≠ 0) : ((m / n : ℚ) : α) = m / n := have (n⁻¹.denom : ℤ) ∣ n.num, by conv in n⁻¹.denom { rw [←(@num_denom n), inv_def] }; apply denom_dvd, have (n⁻¹.denom : α) = 0 → (n.num : α) = 0, from λ h, let ⟨k, e⟩ := this in by have := congr_arg (coe : ℤ → α) e; rwa [int.cast_mul, int.cast_coe_nat, h, zero_mul] at this, by rw [division_def, cast_mul_of_ne_zero md (mt this nn), cast_inv_of_ne_zero nn nd, division_def] @[simp, norm_cast] theorem cast_inj [char_zero α] : ∀ {m n : ℚ}, (m : α) = n ↔ m = n | ⟨n₁, d₁, h₁, c₁⟩ ⟨n₂, d₂, h₂, c₂⟩ := begin refine ⟨λ h, _, congr_arg _⟩, have d₁0 : d₁ ≠ 0 := ne_of_gt h₁, have d₂0 : d₂ ≠ 0 := ne_of_gt h₂, have d₁a : (d₁:α) ≠ 0 := nat.cast_ne_zero.2 d₁0, have d₂a : (d₂:α) ≠ 0 := nat.cast_ne_zero.2 d₂0, rw [num_denom', num_denom'] at h ⊢, rw [cast_mk_of_ne_zero, cast_mk_of_ne_zero] at h; simp [d₁0, d₂0] at h ⊢, rwa [eq_div_iff_mul_eq d₂a, division_def, mul_assoc, (d₁.cast_commute (d₂:α)).inv_left₀.eq, ← mul_assoc, ← division_def, eq_comm, eq_div_iff_mul_eq d₁a, eq_comm, ← int.cast_coe_nat d₁, ← int.cast_mul, ← int.cast_coe_nat d₂, ← int.cast_mul, int.cast_inj, ← mk_eq (int.coe_nat_ne_zero.2 d₁0) (int.coe_nat_ne_zero.2 d₂0)] at h end theorem cast_injective [char_zero α] : function.injective (coe : ℚ → α) | m n := cast_inj.1 @[simp] theorem cast_eq_zero [char_zero α] {n : ℚ} : (n : α) = 0 ↔ n = 0 := by rw [← cast_zero, cast_inj] theorem cast_ne_zero [char_zero α] {n : ℚ} : (n : α) ≠ 0 ↔ n ≠ 0 := not_congr cast_eq_zero @[simp, norm_cast] theorem cast_add [char_zero α] (m n) : ((m + n : ℚ) : α) = m + n := cast_add_of_ne_zero (nat.cast_ne_zero.2 $ ne_of_gt m.pos) (nat.cast_ne_zero.2 $ ne_of_gt n.pos) @[simp, norm_cast] theorem cast_sub [char_zero α] (m n) : ((m - n : ℚ) : α) = m - n := cast_sub_of_ne_zero (nat.cast_ne_zero.2 $ ne_of_gt m.pos) (nat.cast_ne_zero.2 $ ne_of_gt n.pos) @[simp, norm_cast] theorem cast_mul [char_zero α] (m n) : ((m * n : ℚ) : α) = m * n := cast_mul_of_ne_zero (nat.cast_ne_zero.2 $ ne_of_gt m.pos) (nat.cast_ne_zero.2 $ ne_of_gt n.pos) @[simp, norm_cast] theorem cast_bit0 [char_zero α] (n : ℚ) : ((bit0 n : ℚ) : α) = bit0 n := cast_add _ _ @[simp, norm_cast] theorem cast_bit1 [char_zero α] (n : ℚ) : ((bit1 n : ℚ) : α) = bit1 n := by rw [bit1, cast_add, cast_one, cast_bit0]; refl variables (α) [char_zero α] /-- Coercion `ℚ → α` as a `ring_hom`. -/ def cast_hom : ℚ →+* α := ⟨coe, cast_one, cast_mul, cast_zero, cast_add⟩ variable {α} @[simp] lemma coe_cast_hom : ⇑(cast_hom α) = coe := rfl @[simp, norm_cast] theorem cast_inv (n) : ((n⁻¹ : ℚ) : α) = n⁻¹ := map_inv₀ (cast_hom α) _ @[simp, norm_cast] theorem cast_div (m n) : ((m / n : ℚ) : α) = m / n := map_div₀ (cast_hom α) _ _ @[simp, norm_cast] theorem cast_zpow (q : ℚ) (n : ℤ) : ((q ^ n : ℚ) : α) = q ^ n := map_zpow₀ (cast_hom α) q n @[norm_cast] theorem cast_mk (a b : ℤ) : ((a /. b) : α) = a / b := by simp only [mk_eq_div, cast_div, cast_coe_int] @[simp, norm_cast] theorem cast_pow (q) (k : ℕ) : ((q ^ k : ℚ) : α) = q ^ k := (cast_hom α).map_pow q k @[simp, norm_cast] lemma cast_list_sum (s : list ℚ) : (↑(s.sum) : α) = (s.map coe).sum := map_list_sum (rat.cast_hom α) _ @[simp, norm_cast] lemma cast_multiset_sum (s : multiset ℚ) : (↑(s.sum) : α) = (s.map coe).sum := map_multiset_sum (rat.cast_hom α) _ @[simp, norm_cast] lemma cast_sum (s : finset ι) (f : ι → ℚ) : (↑(∑ i in s, f i) : α) = ∑ i in s, f i := map_sum (rat.cast_hom α) _ _ @[simp, norm_cast] lemma cast_list_prod (s : list ℚ) : (↑(s.prod) : α) = (s.map coe).prod := map_list_prod (rat.cast_hom α) _ end with_div_ring section field variables [field α] [char_zero α] @[simp, norm_cast] lemma cast_multiset_prod (s : multiset ℚ) : (↑(s.prod) : α) = (s.map coe).prod := map_multiset_prod (rat.cast_hom α) _ @[simp, norm_cast] lemma cast_prod (s : finset ι) (f : ι → ℚ) : (↑(∏ i in s, f i) : α) = ∏ i in s, f i := map_prod (rat.cast_hom α) _ _ end field section linear_ordered_field variables {K : Type*} [linear_ordered_field K] lemma cast_pos_of_pos {r : ℚ} (hr : 0 < r) : (0 : K) < r := begin rw [rat.cast_def], exact div_pos (int.cast_pos.2 $ num_pos_iff_pos.2 hr) (nat.cast_pos.2 r.pos) end @[mono] lemma cast_strict_mono : strict_mono (coe : ℚ → K) := λ m n, by simpa only [sub_pos, cast_sub] using @cast_pos_of_pos K _ (n - m) @[mono] lemma cast_mono : monotone (coe : ℚ → K) := cast_strict_mono.monotone /-- Coercion from `ℚ` as an order embedding. -/ @[simps] def cast_order_embedding : ℚ ↪o K := order_embedding.of_strict_mono coe cast_strict_mono @[simp, norm_cast] theorem cast_le {m n : ℚ} : (m : K) ≤ n ↔ m ≤ n := cast_order_embedding.le_iff_le @[simp, norm_cast] theorem cast_lt {m n : ℚ} : (m : K) < n ↔ m < n := cast_strict_mono.lt_iff_lt @[simp] theorem cast_nonneg {n : ℚ} : 0 ≤ (n : K) ↔ 0 ≤ n := by norm_cast @[simp] theorem cast_nonpos {n : ℚ} : (n : K) ≤ 0 ↔ n ≤ 0 := by norm_cast @[simp] theorem cast_pos {n : ℚ} : (0 : K) < n ↔ 0 < n := by norm_cast @[simp] theorem cast_lt_zero {n : ℚ} : (n : K) < 0 ↔ n < 0 := by norm_cast @[simp, norm_cast] theorem cast_min {a b : ℚ} : (↑(min a b) : K) = min a b := (@cast_mono K _).map_min @[simp, norm_cast] theorem cast_max {a b : ℚ} : (↑(max a b) : K) = max a b := (@cast_mono K _).map_max @[simp, norm_cast] theorem cast_abs {q : ℚ} : ((|q| : ℚ) : K) = |q| := by simp [abs_eq_max_neg] open set @[simp] lemma preimage_cast_Icc (a b : ℚ) : coe ⁻¹' (Icc (a : K) b) = Icc a b := by { ext x, simp } @[simp] lemma preimage_cast_Ico (a b : ℚ) : coe ⁻¹' (Ico (a : K) b) = Ico a b := by { ext x, simp } @[simp] lemma preimage_cast_Ioc (a b : ℚ) : coe ⁻¹' (Ioc (a : K) b) = Ioc a b := by { ext x, simp } @[simp] lemma preimage_cast_Ioo (a b : ℚ) : coe ⁻¹' (Ioo (a : K) b) = Ioo a b := by { ext x, simp } @[simp] lemma preimage_cast_Ici (a : ℚ) : coe ⁻¹' (Ici (a : K)) = Ici a := by { ext x, simp } @[simp] lemma preimage_cast_Iic (a : ℚ) : coe ⁻¹' (Iic (a : K)) = Iic a := by { ext x, simp } @[simp] lemma preimage_cast_Ioi (a : ℚ) : coe ⁻¹' (Ioi (a : K)) = Ioi a := by { ext x, simp } @[simp] lemma preimage_cast_Iio (a : ℚ) : coe ⁻¹' (Iio (a : K)) = Iio a := by { ext x, simp } end linear_ordered_field @[norm_cast] theorem cast_id (n : ℚ) : (↑n : ℚ) = n := by rw [cast_def, num_div_denom] @[simp] theorem cast_eq_id : (coe : ℚ → ℚ) = id := funext cast_id @[simp] lemma cast_hom_rat : cast_hom ℚ = ring_hom.id ℚ := ring_hom.ext cast_id end rat open rat @[simp] lemma map_rat_cast [division_ring α] [division_ring β] [ring_hom_class F α β] (f : F) (q : ℚ) : f q = q := by rw [cast_def, map_div₀, map_int_cast, map_nat_cast, cast_def] @[simp] lemma eq_rat_cast {k} [division_ring k] [ring_hom_class F ℚ k] (f : F) (r : ℚ) : f r = r := by rw [← map_rat_cast f, rat.cast_id] namespace monoid_with_zero_hom variables {M₀ : Type*} [monoid_with_zero M₀] [monoid_with_zero_hom_class F ℚ M₀] {f g : F} include M₀ /-- If `f` and `g` agree on the integers then they are equal `φ`. -/ theorem ext_rat' (h : ∀ m : ℤ, f m = g m) : f = g := fun_like.ext f g $ λ r, by rw [← r.num_div_denom, div_eq_mul_inv, map_mul, map_mul, h, ← int.cast_coe_nat, eq_on_inv₀ f g (h _)] /-- If `f` and `g` agree on the integers then they are equal `φ`. See note [partially-applied ext lemmas] for why `comp` is used here. -/ @[ext] theorem ext_rat {f g : ℚ →*₀ M₀} (h : f.comp (int.cast_ring_hom ℚ : ℤ →*₀ ℚ) = g.comp (int.cast_ring_hom ℚ)) : f = g := ext_rat' $ congr_fun h /-- Positive integer values of a morphism `φ` and its value on `-1` completely determine `φ`. -/ theorem ext_rat_on_pnat (same_on_neg_one : f (-1) = g (-1)) (same_on_pnat : ∀ n : ℕ, 0 < n → f n = g n) : f = g := ext_rat' $ fun_like.congr_fun $ show (f : ℚ →*₀ M₀).comp (int.cast_ring_hom ℚ : ℤ →*₀ ℚ) = (g : ℚ →*₀ M₀).comp (int.cast_ring_hom ℚ : ℤ →*₀ ℚ), from ext_int' (by simpa) (by simpa) end monoid_with_zero_hom /-- Any two ring homomorphisms from `ℚ` to a semiring are equal. If the codomain is a division ring, then this lemma follows from `eq_rat_cast`. -/ lemma ring_hom.ext_rat {R : Type*} [semiring R] [ring_hom_class F ℚ R] (f g : F) : f = g := monoid_with_zero_hom.ext_rat' $ ring_hom.congr_fun $ ((f : ℚ →+* R).comp (int.cast_ring_hom ℚ)).ext_int ((g : ℚ →+* R).comp (int.cast_ring_hom ℚ)) instance rat.subsingleton_ring_hom {R : Type*} [semiring R] : subsingleton (ℚ →+* R) := ⟨ring_hom.ext_rat⟩ namespace mul_opposite variables [division_ring α] @[simp, norm_cast] lemma op_rat_cast (r : ℚ) : op (r : α) = (↑r : αᵐᵒᵖ) := by rw [cast_def, div_eq_mul_inv, op_mul, op_inv, op_nat_cast, op_int_cast, (commute.cast_int_right _ r.num).eq, cast_def, div_eq_mul_inv] @[simp, norm_cast] lemma unop_rat_cast (r : ℚ) : unop (r : αᵐᵒᵖ) = r := by rw [cast_def, div_eq_mul_inv, unop_mul, unop_inv, unop_nat_cast, unop_int_cast, (commute.cast_int_right _ r.num).eq, cast_def, div_eq_mul_inv] end mul_opposite
ddc68fe139d6dac7a49b2db92c421cebbc2dfa5c
e0f9ba56b7fedc16ef8697f6caeef5898b435143
/src/analysis/calculus/tangent_cone.lean
269604620998ab0c8bd5da9727d012d546c9d1e4
[ "Apache-2.0" ]
permissive
anrddh/mathlib
6a374da53c7e3a35cb0298b0cd67824efef362b4
a4266a01d2dcb10de19369307c986d038c7bb6a6
refs/heads/master
1,656,710,827,909
1,589,560,456,000
1,589,560,456,000
264,271,800
0
0
Apache-2.0
1,589,568,062,000
1,589,568,061,000
null
UTF-8
Lean
false
false
16,506
lean
/- Copyright (c) 2019 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel -/ import analysis.convex.basic import analysis.normed_space.bounded_linear_maps import analysis.specific_limits /-! # Tangent cone In this file, we define two predicates `unique_diff_within_at 𝕜 s x` and `unique_diff_on 𝕜 s` ensuring that, if a function has two derivatives, then they have to coincide. As a direct definition of this fact (quantifying on all target types and all functions) would depend on universes, we use a more intrinsic definition: if all the possible tangent directions to the set `s` at the point `x` span a dense subset of the whole subset, it is easy to check that the derivative has to be unique. Therefore, we introduce the set of all tangent directions, named `tangent_cone_at`, and express `unique_diff_within_at` and `unique_diff_on` in terms of it. One should however think of this definition as an implementation detail: the only reason to introduce the predicates `unique_diff_within_at` and `unique_diff_on` is to ensure the uniqueness of the derivative. This is why their names reflect their uses, and not how they are defined. ## Implementation details Note that this file is imported by `fderiv.lean`. Hence, derivatives are not defined yet. The property of uniqueness of the derivative is therefore proved in `fderiv.lean`, but based on the properties of the tangent cone we prove here. -/ variables (𝕜 : Type*) [nondiscrete_normed_field 𝕜] variables {E : Type*} [normed_group E] [normed_space 𝕜 E] variables {F : Type*} [normed_group F] [normed_space 𝕜 F] variables {G : Type*} [normed_group G] [normed_space ℝ G] open filter set open_locale topological_space /-- The set of all tangent directions to the set `s` at the point `x`. -/ def tangent_cone_at (s : set E) (x : E) : set E := {y : E | ∃(c : ℕ → 𝕜) (d : ℕ → E), (∀ᶠ n in at_top, x + d n ∈ s) ∧ (tendsto (λn, ∥c n∥) at_top at_top) ∧ (tendsto (λn, c n • d n) at_top (𝓝 y))} /-- A property ensuring that the tangent cone to `s` at `x` spans a dense subset of the whole space. The main role of this property is to ensure that the differential within `s` at `x` is unique, hence this name. The uniqueness it asserts is proved in `unique_diff_within_at.eq` in `fderiv.lean`. To avoid pathologies in dimension 0, we also require that `x` belongs to the closure of `s` (which is automatic when `E` is not `0`-dimensional). -/ def unique_diff_within_at (s : set E) (x : E) : Prop := closure ((submodule.span 𝕜 (tangent_cone_at 𝕜 s x)) : set E) = univ ∧ x ∈ closure s /-- A property ensuring that the tangent cone to `s` at any of its points spans a dense subset of the whole space. The main role of this property is to ensure that the differential along `s` is unique, hence this name. The uniqueness it asserts is proved in `unique_diff_on.eq` in `fderiv.lean`. -/ def unique_diff_on (s : set E) : Prop := ∀x ∈ s, unique_diff_within_at 𝕜 s x variables {𝕜} {x y : E} {s t : set E} section tangent_cone /- This section is devoted to the properties of the tangent cone. -/ open normed_field lemma tangent_cone_univ : tangent_cone_at 𝕜 univ x = univ := begin refine univ_subset_iff.1 (λy hy, _), rcases exists_one_lt_norm 𝕜 with ⟨w, hw⟩, refine ⟨λn, w^n, λn, (w^n)⁻¹ • y, univ_mem_sets' (λn, mem_univ _), _, _⟩, { simp only [norm_pow], exact tendsto_pow_at_top_at_top_of_gt_1 hw }, { convert tendsto_const_nhds, ext n, have : w ^ n * (w ^ n)⁻¹ = 1, { apply mul_inv_cancel, apply pow_ne_zero, simpa [norm_eq_zero] using (ne_of_lt (lt_trans zero_lt_one hw)).symm }, rw [smul_smul, this, one_smul] } end lemma tangent_cone_mono (h : s ⊆ t) : tangent_cone_at 𝕜 s x ⊆ tangent_cone_at 𝕜 t x := begin rintros y ⟨c, d, ds, ctop, clim⟩, exact ⟨c, d, mem_sets_of_superset ds (λn hn, h hn), ctop, clim⟩ end /-- Auxiliary lemma ensuring that, under the assumptions defining the tangent cone, the sequence `d` tends to 0 at infinity. -/ lemma tangent_cone_at.lim_zero {α : Type*} (l : filter α) {c : α → 𝕜} {d : α → E} (hc : tendsto (λn, ∥c n∥) l at_top) (hd : tendsto (λn, c n • d n) l (𝓝 y)) : tendsto d l (𝓝 0) := begin have A : tendsto (λn, ∥c n∥⁻¹) l (𝓝 0) := tendsto_inv_at_top_zero.comp hc, have B : tendsto (λn, ∥c n • d n∥) l (𝓝 ∥y∥) := (continuous_norm.tendsto _).comp hd, have C : tendsto (λn, ∥c n∥⁻¹ * ∥c n • d n∥) l (𝓝 (0 * ∥y∥)) := A.mul B, rw zero_mul at C, have : ∀ᶠ n in l, ∥c n∥⁻¹ * ∥c n • d n∥ = ∥d n∥, { apply (eventually_ne_of_tendsto_norm_at_top hc 0).mono (λn hn, _), rw [norm_smul, ← mul_assoc, inv_mul_cancel, one_mul], rwa [ne.def, norm_eq_zero] }, have D : tendsto (λ n, ∥d n∥) l (𝓝 0) := tendsto.congr' this C, rw tendsto_zero_iff_norm_tendsto_zero, exact D end lemma tangent_cone_mono_nhds (h : nhds_within x s ≤ nhds_within x t) : tangent_cone_at 𝕜 s x ⊆ tangent_cone_at 𝕜 t x := begin rintros y ⟨c, d, ds, ctop, clim⟩, refine ⟨c, d, _, ctop, clim⟩, suffices : tendsto (λ n, x + d n) at_top (nhds_within x t), from tendsto_principal.1 (tendsto_inf.1 this).2, apply tendsto_le_right h, refine tendsto_inf.2 ⟨_, tendsto_principal.2 ds⟩, simpa only [add_zero] using tendsto_const_nhds.add (tangent_cone_at.lim_zero at_top ctop clim) end /-- Tangent cone of `s` at `x` depends only on `nhds_within x s`. -/ lemma tangent_cone_congr (h : nhds_within x s = nhds_within x t) : tangent_cone_at 𝕜 s x = tangent_cone_at 𝕜 t x := subset.antisymm (tangent_cone_mono_nhds $ le_of_eq h) (tangent_cone_mono_nhds $ le_of_eq h.symm) /-- Intersecting with a neighborhood of the point does not change the tangent cone. -/ lemma tangent_cone_inter_nhds (ht : t ∈ 𝓝 x) : tangent_cone_at 𝕜 (s ∩ t) x = tangent_cone_at 𝕜 s x := tangent_cone_congr (nhds_within_restrict' _ ht).symm /-- The tangent cone of a product contains the tangent cone of its left factor. -/ lemma subset_tangent_cone_prod_left {t : set F} {y : F} (ht : y ∈ closure t) : prod.inl '' (tangent_cone_at 𝕜 s x) ⊆ tangent_cone_at 𝕜 (set.prod s t) (x, y) := begin rintros _ ⟨v, ⟨c, d, hd, hc, hy⟩, rfl⟩, have : ∀n, ∃d', y + d' ∈ t ∧ ∥c n • d'∥ ≤ ((1:ℝ)/2)^n, { assume n, have c_pos : 0 < 1 + ∥c n∥ := add_pos_of_pos_of_nonneg zero_lt_one (norm_nonneg _), rcases metric.mem_closure_iff.1 ht ((1 + ∥c n∥)⁻¹ * (1/2)^n) _ with ⟨z, z_pos, hz⟩, refine ⟨z - y, _, _⟩, { convert z_pos, abel }, { rw [norm_smul, ← dist_eq_norm, dist_comm], calc ∥c n∥ * dist y z ≤ (1 + ∥c n∥) * ((1 + ∥c n∥)⁻¹ * (1/2)^n) : begin apply mul_le_mul _ (le_of_lt hz) dist_nonneg (le_of_lt c_pos), simp only [zero_le_one, le_add_iff_nonneg_left] end ... = (1/2)^n : begin rw [← mul_assoc, mul_inv_cancel, one_mul], exact ne_of_gt c_pos end }, { apply mul_pos (inv_pos.2 c_pos) (pow_pos _ _), norm_num } }, choose d' hd' using this, refine ⟨c, λn, (d n, d' n), _, hc, _⟩, show ∀ᶠ n in at_top, (x, y) + (d n, d' n) ∈ set.prod s t, { apply filter.mem_sets_of_superset hd, assume n hn, simp at hn, simp [hn, (hd' n).1] }, { apply hy.prod_mk_nhds, change tendsto (λ (n : ℕ), c n • d' n) at_top (𝓝 0), rw tendsto_zero_iff_norm_tendsto_zero, refine squeeze_zero (λn, norm_nonneg _) (λn, (hd' n).2) _, apply tendsto_pow_at_top_nhds_0_of_lt_1; norm_num } end /-- The tangent cone of a product contains the tangent cone of its right factor. -/ lemma subset_tangent_cone_prod_right {t : set F} {y : F} (hs : x ∈ closure s) : prod.inr '' (tangent_cone_at 𝕜 t y) ⊆ tangent_cone_at 𝕜 (set.prod s t) (x, y) := begin rintros _ ⟨w, ⟨c, d, hd, hc, hy⟩, rfl⟩, have : ∀n, ∃d', x + d' ∈ s ∧ ∥c n • d'∥ ≤ ((1:ℝ)/2)^n, { assume n, have c_pos : 0 < 1 + ∥c n∥ := add_pos_of_pos_of_nonneg zero_lt_one (norm_nonneg _), rcases metric.mem_closure_iff.1 hs ((1 + ∥c n∥)⁻¹ * (1/2)^n) _ with ⟨z, z_pos, hz⟩, refine ⟨z - x, _, _⟩, { convert z_pos, abel }, { rw [norm_smul, ← dist_eq_norm, dist_comm], calc ∥c n∥ * dist x z ≤ (1 + ∥c n∥) * ((1 + ∥c n∥)⁻¹ * (1/2)^n) : begin apply mul_le_mul _ (le_of_lt hz) dist_nonneg (le_of_lt c_pos), simp only [zero_le_one, le_add_iff_nonneg_left] end ... = (1/2)^n : begin rw [← mul_assoc, mul_inv_cancel, one_mul], exact ne_of_gt c_pos end }, { apply mul_pos (inv_pos.2 c_pos) (pow_pos _ _), norm_num } }, choose d' hd' using this, refine ⟨c, λn, (d' n, d n), _, hc, _⟩, show ∀ᶠ n in at_top, (x, y) + (d' n, d n) ∈ set.prod s t, { apply filter.mem_sets_of_superset hd, assume n hn, simp at hn, simp [hn, (hd' n).1] }, { apply tendsto.prod_mk_nhds _ hy, change tendsto (λ (n : ℕ), c n • d' n) at_top (𝓝 0), rw tendsto_zero_iff_norm_tendsto_zero, refine squeeze_zero (λn, norm_nonneg _) (λn, (hd' n).2) _, apply tendsto_pow_at_top_nhds_0_of_lt_1; norm_num } end /-- If a subset of a real vector space contains a segment, then the direction of this segment belongs to the tangent cone at its endpoints. -/ lemma mem_tangent_cone_of_segment_subset {s : set G} {x y : G} (h : segment x y ⊆ s) : y - x ∈ tangent_cone_at ℝ s x := begin let w : ℝ := 2, let c := λn:ℕ, (2:ℝ)^n, let d := λn:ℕ, (c n)⁻¹ • (y-x), refine ⟨c, d, filter.univ_mem_sets' (λn, h _), _, _⟩, show x + d n ∈ segment x y, { rw segment_eq_image, refine ⟨(c n)⁻¹, ⟨_, _⟩, _⟩, { rw inv_nonneg, apply pow_nonneg, norm_num }, { apply inv_le_one, apply one_le_pow_of_one_le, norm_num }, { simp only [d, sub_smul, smul_sub, one_smul], abel } }, show filter.tendsto (λ (n : ℕ), ∥c n∥) filter.at_top filter.at_top, { have : (λ (n : ℕ), ∥c n∥) = c, by { ext n, exact abs_of_nonneg (pow_nonneg (by norm_num) _) }, rw this, exact tendsto_pow_at_top_at_top_of_gt_1 (by norm_num) }, show filter.tendsto (λ (n : ℕ), c n • d n) filter.at_top (𝓝 (y - x)), { have : (λ (n : ℕ), c n • d n) = (λn, y - x), { ext n, simp only [d, smul_smul], rw [mul_inv_cancel, one_smul], exact pow_ne_zero _ (by norm_num) }, rw this, apply tendsto_const_nhds } end end tangent_cone section unique_diff /- This section is devoted to properties of the predicates `unique_diff_within_at` and `unique_diff_on`. -/ lemma unique_diff_within_at_univ : unique_diff_within_at 𝕜 univ x := by { rw [unique_diff_within_at, tangent_cone_univ], simp } lemma unique_diff_on_univ : unique_diff_on 𝕜 (univ : set E) := λx hx, unique_diff_within_at_univ lemma unique_diff_on_empty : unique_diff_on 𝕜 (∅ : set E) := λ x hx, hx.elim lemma unique_diff_within_at.mono_nhds (h : unique_diff_within_at 𝕜 s x) (st : nhds_within x s ≤ nhds_within x t) : unique_diff_within_at 𝕜 t x := begin unfold unique_diff_within_at at *, rw [← univ_subset_iff, ← h.1], rw [mem_closure_iff_nhds_within_ne_bot] at h ⊢, exact ⟨closure_mono (submodule.span_mono (tangent_cone_mono_nhds st)), ne_bot_of_le_ne_bot h.2 st⟩ end lemma unique_diff_within_at.mono (h : unique_diff_within_at 𝕜 s x) (st : s ⊆ t) : unique_diff_within_at 𝕜 t x := h.mono_nhds $ nhds_within_mono _ st lemma unique_diff_within_at_congr (st : nhds_within x s = nhds_within x t) : unique_diff_within_at 𝕜 s x ↔ unique_diff_within_at 𝕜 t x := ⟨λ h, h.mono_nhds $ le_of_eq st, λ h, h.mono_nhds $ le_of_eq st.symm⟩ lemma unique_diff_within_at_inter (ht : t ∈ 𝓝 x) : unique_diff_within_at 𝕜 (s ∩ t) x ↔ unique_diff_within_at 𝕜 s x := unique_diff_within_at_congr $ (nhds_within_restrict' _ ht).symm lemma unique_diff_within_at.inter (hs : unique_diff_within_at 𝕜 s x) (ht : t ∈ 𝓝 x) : unique_diff_within_at 𝕜 (s ∩ t) x := (unique_diff_within_at_inter ht).2 hs lemma unique_diff_within_at_inter' (ht : t ∈ nhds_within x s) : unique_diff_within_at 𝕜 (s ∩ t) x ↔ unique_diff_within_at 𝕜 s x := unique_diff_within_at_congr $ (nhds_within_restrict'' _ ht).symm lemma unique_diff_within_at.inter' (hs : unique_diff_within_at 𝕜 s x) (ht : t ∈ nhds_within x s) : unique_diff_within_at 𝕜 (s ∩ t) x := (unique_diff_within_at_inter' ht).2 hs lemma is_open.unique_diff_within_at (hs : is_open s) (xs : x ∈ s) : unique_diff_within_at 𝕜 s x := begin have := unique_diff_within_at_univ.inter (mem_nhds_sets hs xs), rwa univ_inter at this end lemma unique_diff_on.inter (hs : unique_diff_on 𝕜 s) (ht : is_open t) : unique_diff_on 𝕜 (s ∩ t) := λx hx, (hs x hx.1).inter (mem_nhds_sets ht hx.2) lemma is_open.unique_diff_on (hs : is_open s) : unique_diff_on 𝕜 s := λx hx, is_open.unique_diff_within_at hs hx /-- The product of two sets of unique differentiability at points `x` and `y` has unique differentiability at `(x, y)`. -/ lemma unique_diff_within_at.prod {t : set F} {y : F} (hs : unique_diff_within_at 𝕜 s x) (ht : unique_diff_within_at 𝕜 t y) : unique_diff_within_at 𝕜 (set.prod s t) (x, y) := begin rw [unique_diff_within_at] at ⊢ hs ht, rw [← univ_subset_iff, closure_prod_eq], refine ⟨_, hs.2, ht.2⟩, have : _ ⊆ tangent_cone_at 𝕜 (s.prod t) (x, y) := union_subset (subset_tangent_cone_prod_left ht.2) (subset_tangent_cone_prod_right hs.2), refine subset.trans _ (closure_mono $ submodule.span_mono this), rw [linear_map.span_inl_union_inr, submodule.prod_coe, closure_prod_eq, hs.1, ht.1, univ_prod_univ] end /-- The product of two sets of unique differentiability is a set of unique differentiability. -/ lemma unique_diff_on.prod {t : set F} (hs : unique_diff_on 𝕜 s) (ht : unique_diff_on 𝕜 t) : unique_diff_on 𝕜 (set.prod s t) := λ ⟨x, y⟩ h, unique_diff_within_at.prod (hs x h.1) (ht y h.2) /-- In a real vector space, a convex set with nonempty interior is a set of unique differentiability. -/ theorem unique_diff_on_convex {s : set G} (conv : convex s) (hs : (interior s).nonempty) : unique_diff_on ℝ s := begin assume x xs, rcases hs with ⟨y, hy⟩, suffices : y - x ∈ interior (tangent_cone_at ℝ s x), { refine ⟨_, subset_closure xs⟩, rw [submodule.eq_top_of_nonempty_interior _ ⟨y - x, interior_mono submodule.subset_span this⟩, submodule.top_coe, closure_univ] }, rw [mem_interior_iff_mem_nhds] at hy ⊢, apply mem_sets_of_superset ((is_open_map_add_right (-x)).image_mem_nhds hy), rintros _ ⟨z, zs, rfl⟩, exact mem_tangent_cone_of_segment_subset (conv.segment_subset xs zs) end lemma unique_diff_on_Ici (a : ℝ) : unique_diff_on ℝ (Ici a) := unique_diff_on_convex (convex_Ici a) $ by simp only [interior_Ici, nonempty_Ioi] lemma unique_diff_on_Iic (a : ℝ) : unique_diff_on ℝ (Iic a) := unique_diff_on_convex (convex_Iic a) $ by simp only [interior_Iic, nonempty_Iio] lemma unique_diff_on_Ioi (a : ℝ) : unique_diff_on ℝ (Ioi a) := is_open_Ioi.unique_diff_on lemma unique_diff_on_Iio (a : ℝ) : unique_diff_on ℝ (Iio a) := is_open_Iio.unique_diff_on lemma unique_diff_on_Icc {a b : ℝ} (hab : a < b) : unique_diff_on ℝ (Icc a b) := unique_diff_on_convex (convex_Icc a b) $ by simp only [interior_Icc, nonempty_Ioo, hab] lemma unique_diff_on_Ico (a b : ℝ) : unique_diff_on ℝ (Ico a b) := if hab : a < b then unique_diff_on_convex (convex_Ico a b) $ by simp only [interior_Ico, nonempty_Ioo, hab] else by simp only [Ico_eq_empty (le_of_not_lt hab), unique_diff_on_empty] lemma unique_diff_on_Ioc (a b : ℝ) : unique_diff_on ℝ (Ioc a b) := if hab : a < b then unique_diff_on_convex (convex_Ioc a b) $ by simp only [interior_Ioc, nonempty_Ioo, hab] else by simp only [Ioc_eq_empty (le_of_not_lt hab), unique_diff_on_empty] lemma unique_diff_on_Ioo (a b : ℝ) : unique_diff_on ℝ (Ioo a b) := is_open_Ioo.unique_diff_on /-- The real interval `[0, 1]` is a set of unique differentiability. -/ lemma unique_diff_on_Icc_zero_one : unique_diff_on ℝ (Icc (0:ℝ) 1) := unique_diff_on_Icc zero_lt_one end unique_diff
0526fb00cbabfb028a0d01bfb7058dc974155d80
cf39355caa609c0f33405126beee2739aa3cb77e
/tests/lean/widget/widget4.lean
b8197e8dfad5509dd91369f6d364f3a15a642ba1
[ "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
56
lean
open tactic widget #eval trace_widget term_goal_widget
fd67153fdc78718a7849db9096586cb47a5c0e45
94e33a31faa76775069b071adea97e86e218a8ee
/src/geometry/manifold/diffeomorph.lean
4427d841552c66b07ba36f74b7352bf674dae50f
[ "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,932
lean
/- Copyright © 2020 Nicolò Cavalleri. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Nicolò Cavalleri, Yury Kudryashov -/ import geometry.manifold.cont_mdiff_map /-! # Diffeomorphisms This file implements diffeomorphisms. ## Definitions * `diffeomorph I I' M M' n`: `n`-times continuously differentiable diffeomorphism between `M` and `M'` with respect to I and I'; we do not introduce a separate definition for the case `n = ∞`; we use notation instead. * `diffeomorph.to_homeomorph`: reinterpret a diffeomorphism as a homeomorphism. * `continuous_linear_equiv.to_diffeomorph`: reinterpret a continuous equivalence as a diffeomorphism. * `model_with_corners.trans_diffeomorph`: compose a given `model_with_corners` with a diffeomorphism between the old and the new target spaces. Useful, e.g, to turn any finite dimensional manifold into a manifold modelled on a Euclidean space. * `diffeomorph.to_trans_diffeomorph`: the identity diffeomorphism between `M` with model `I` and `M` with model `I.trans_diffeomorph e`. ## Notations * `M ≃ₘ^n⟮I, I'⟯ M'` := `diffeomorph I J M N n` * `M ≃ₘ⟮I, I'⟯ M'` := `diffeomorph I J M N ⊤` * `E ≃ₘ^n[𝕜] E'` := `E ≃ₘ^n⟮𝓘(𝕜, E), 𝓘(𝕜, E')⟯ E'` * `E ≃ₘ[𝕜] E'` := `E ≃ₘ⟮𝓘(𝕜, E), 𝓘(𝕜, E')⟯ E'` ## Implementation notes This notion of diffeomorphism is needed although there is already a notion of structomorphism because structomorphisms do not allow the model spaces `H` and `H'` of the two manifolds to be different, i.e. for a structomorphism one has to impose `H = H'` which is often not the case in practice. ## Keywords diffeomorphism, manifold -/ open_locale manifold topological_space open function set variables {𝕜 : Type*} [nondiscrete_normed_field 𝕜] {E : Type*} [normed_group E] [normed_space 𝕜 E] {E' : Type*} [normed_group E'] [normed_space 𝕜 E'] {F : Type*} [normed_group F] [normed_space 𝕜 F] {H : Type*} [topological_space H] {H' : Type*} [topological_space H'] {G : Type*} [topological_space G] {G' : Type*} [topological_space G'] {I : model_with_corners 𝕜 E H} {I' : model_with_corners 𝕜 E' H'} {J : model_with_corners 𝕜 F G} {J' : model_with_corners 𝕜 F G'} variables {M : Type*} [topological_space M] [charted_space H M] {M' : Type*} [topological_space M'] [charted_space H' M'] {N : Type*} [topological_space N] [charted_space G N] {N' : Type*} [topological_space N'] [charted_space G' N'] {n : with_top ℕ} section defs variables (I I' M M' n) /-- `n`-times continuously differentiable diffeomorphism between `M` and `M'` with respect to I and I' -/ @[protect_proj, nolint has_inhabited_instance] structure diffeomorph extends M ≃ M' := (cont_mdiff_to_fun : cont_mdiff I I' n to_equiv) (cont_mdiff_inv_fun : cont_mdiff I' I n to_equiv.symm) end defs localized "notation M ` ≃ₘ^` n:1000 `⟮`:50 I `,` J `⟯ ` N := diffeomorph I J M N n" in manifold localized "notation M ` ≃ₘ⟮` I `,` J `⟯ ` N := diffeomorph I J M N ⊤" in manifold localized "notation E ` ≃ₘ^` n:1000 `[`:50 𝕜 `] ` E' := diffeomorph (model_with_corners_self 𝕜 E) (model_with_corners_self 𝕜 E') E E' n" in manifold localized "notation E ` ≃ₘ[` 𝕜 `] ` E' := diffeomorph (model_with_corners_self 𝕜 E) (model_with_corners_self 𝕜 E') E E' ⊤" in manifold namespace diffeomorph instance : has_coe_to_fun (M ≃ₘ^n⟮I, I'⟯ M') (λ _, M → M') := ⟨λe, e.to_equiv⟩ instance : has_coe (M ≃ₘ^n⟮I, I'⟯ M') C^n⟮I, M; I', M'⟯ := ⟨λ Φ, ⟨Φ, Φ.cont_mdiff_to_fun⟩⟩ @[continuity] protected lemma continuous (h : M ≃ₘ^n⟮I, I'⟯ M') : continuous h := h.cont_mdiff_to_fun.continuous protected lemma cont_mdiff (h : M ≃ₘ^n⟮I, I'⟯ M') : cont_mdiff I I' n h := h.cont_mdiff_to_fun protected lemma cont_mdiff_at (h : M ≃ₘ^n⟮I, I'⟯ M') {x} : cont_mdiff_at I I' n h x := h.cont_mdiff.cont_mdiff_at protected lemma cont_mdiff_within_at (h : M ≃ₘ^n⟮I, I'⟯ M') {s x} : cont_mdiff_within_at I I' n h s x := h.cont_mdiff_at.cont_mdiff_within_at protected lemma cont_diff (h : E ≃ₘ^n[𝕜] E') : cont_diff 𝕜 n h := h.cont_mdiff.cont_diff protected lemma smooth (h : M ≃ₘ⟮I, I'⟯ M') : smooth I I' h := h.cont_mdiff_to_fun protected lemma mdifferentiable (h : M ≃ₘ^n⟮I, I'⟯ M') (hn : 1 ≤ n) : mdifferentiable I I' h := h.cont_mdiff.mdifferentiable hn protected lemma mdifferentiable_on (h : M ≃ₘ^n⟮I, I'⟯ M') (s : set M) (hn : 1 ≤ n) : mdifferentiable_on I I' h s := (h.mdifferentiable hn).mdifferentiable_on @[simp] lemma coe_to_equiv (h : M ≃ₘ^n⟮I, I'⟯ M') : ⇑h.to_equiv = h := rfl @[simp, norm_cast] lemma coe_coe (h : M ≃ₘ^n⟮I, I'⟯ M') : ⇑(h : C^n⟮I, M; I', M'⟯) = h := rfl lemma to_equiv_injective : injective (diffeomorph.to_equiv : (M ≃ₘ^n⟮I, I'⟯ M') → (M ≃ M')) | ⟨e, _, _⟩ ⟨e', _, _⟩ rfl := rfl @[simp] lemma to_equiv_inj {h h' : M ≃ₘ^n⟮I, I'⟯ M'} : h.to_equiv = h'.to_equiv ↔ h = h' := to_equiv_injective.eq_iff /-- Coercion to function `λ h : M ≃ₘ^n⟮I, I'⟯ M', (h : M → M')` is injective. -/ lemma coe_fn_injective : injective (λ (h : M ≃ₘ^n⟮I, I'⟯ M') (x : M), h x) := equiv.coe_fn_injective.comp to_equiv_injective @[ext] lemma ext {h h' : M ≃ₘ^n⟮I, I'⟯ M'} (Heq : ∀ x, h x = h' x) : h = h' := coe_fn_injective $ funext Heq section variables (M I n) /-- Identity map as a diffeomorphism. -/ protected def refl : M ≃ₘ^n⟮I, I⟯ M := { cont_mdiff_to_fun := cont_mdiff_id, cont_mdiff_inv_fun := cont_mdiff_id, to_equiv := equiv.refl M } @[simp] lemma refl_to_equiv : (diffeomorph.refl I M n).to_equiv = equiv.refl _ := rfl @[simp] lemma coe_refl : ⇑(diffeomorph.refl I M n) = id := rfl end /-- Composition of two diffeomorphisms. -/ protected def trans (h₁ : M ≃ₘ^n⟮I, I'⟯ M') (h₂ : M' ≃ₘ^n⟮I', J⟯ N) : M ≃ₘ^n⟮I, J⟯ N := { cont_mdiff_to_fun := h₂.cont_mdiff_to_fun.comp h₁.cont_mdiff_to_fun, cont_mdiff_inv_fun := h₁.cont_mdiff_inv_fun.comp h₂.cont_mdiff_inv_fun, to_equiv := h₁.to_equiv.trans h₂.to_equiv } @[simp] lemma trans_refl (h : M ≃ₘ^n⟮I, I'⟯ M') : h.trans (diffeomorph.refl I' M' n) = h := ext $ λ _, rfl @[simp] lemma refl_trans (h : M ≃ₘ^n⟮I, I'⟯ M') : (diffeomorph.refl I M n).trans h = h := ext $ λ _, rfl @[simp] lemma coe_trans (h₁ : M ≃ₘ^n⟮I, I'⟯ M') (h₂ : M' ≃ₘ^n⟮I', J⟯ N) : ⇑(h₁.trans h₂) = h₂ ∘ h₁ := rfl /-- Inverse of a diffeomorphism. -/ protected def symm (h : M ≃ₘ^n⟮I, J⟯ N) : N ≃ₘ^n⟮J, I⟯ M := { cont_mdiff_to_fun := h.cont_mdiff_inv_fun, cont_mdiff_inv_fun := h.cont_mdiff_to_fun, to_equiv := h.to_equiv.symm } @[simp] lemma apply_symm_apply (h : M ≃ₘ^n⟮I, J⟯ N) (x : N) : h (h.symm x) = x := h.to_equiv.apply_symm_apply x @[simp] lemma symm_apply_apply (h : M ≃ₘ^n⟮I, J⟯ N) (x : M) : h.symm (h x) = x := h.to_equiv.symm_apply_apply x @[simp] lemma symm_refl : (diffeomorph.refl I M n).symm = diffeomorph.refl I M n := ext $ λ _, rfl @[simp] lemma self_trans_symm (h : M ≃ₘ^n⟮I, J⟯ N) : h.trans h.symm = diffeomorph.refl I M n := ext h.symm_apply_apply @[simp] lemma symm_trans_self (h : M ≃ₘ^n⟮I, J⟯ N) : h.symm.trans h = diffeomorph.refl J N n := ext h.apply_symm_apply @[simp] lemma symm_trans' (h₁ : M ≃ₘ^n⟮I, I'⟯ M') (h₂ : M' ≃ₘ^n⟮I', J⟯ N) : (h₁.trans h₂).symm = h₂.symm.trans h₁.symm := rfl @[simp] lemma symm_to_equiv (h : M ≃ₘ^n⟮I, J⟯ N) : h.symm.to_equiv = h.to_equiv.symm := rfl @[simp, mfld_simps] lemma to_equiv_coe_symm (h : M ≃ₘ^n⟮I, J⟯ N) : ⇑h.to_equiv.symm = h.symm := rfl lemma image_eq_preimage (h : M ≃ₘ^n⟮I, J⟯ N) (s : set M) : h '' s = h.symm ⁻¹' s := h.to_equiv.image_eq_preimage s lemma symm_image_eq_preimage (h : M ≃ₘ^n⟮I, J⟯ N) (s : set N) : h.symm '' s = h ⁻¹' s := h.symm.image_eq_preimage s @[simp, mfld_simps] lemma range_comp {α} (h : M ≃ₘ^n⟮I, J⟯ N) (f : α → M) : range (h ∘ f) = h.symm ⁻¹' (range f) := by rw [range_comp, image_eq_preimage] @[simp] lemma image_symm_image (h : M ≃ₘ^n⟮I, J⟯ N) (s : set N) : h '' (h.symm '' s) = s := h.to_equiv.image_symm_image s @[simp] lemma symm_image_image (h : M ≃ₘ^n⟮I, J⟯ N) (s : set M) : h.symm '' (h '' s) = s := h.to_equiv.symm_image_image s /-- A diffeomorphism is a homeomorphism. -/ def to_homeomorph (h : M ≃ₘ^n⟮I, J⟯ N) : M ≃ₜ N := ⟨h.to_equiv, h.continuous, h.symm.continuous⟩ @[simp] lemma to_homeomorph_to_equiv (h : M ≃ₘ^n⟮I, J⟯ N) : h.to_homeomorph.to_equiv = h.to_equiv := rfl @[simp] lemma symm_to_homeomorph (h : M ≃ₘ^n⟮I, J⟯ N) : h.symm.to_homeomorph = h.to_homeomorph.symm := rfl @[simp] lemma coe_to_homeomorph (h : M ≃ₘ^n⟮I, J⟯ N) : ⇑h.to_homeomorph = h := rfl @[simp] lemma coe_to_homeomorph_symm (h : M ≃ₘ^n⟮I, J⟯ N) : ⇑h.to_homeomorph.symm = h.symm := rfl @[simp] lemma cont_mdiff_within_at_comp_diffeomorph_iff {m} (h : M ≃ₘ^n⟮I, J⟯ N) {f : N → M'} {s x} (hm : m ≤ n) : cont_mdiff_within_at I I' m (f ∘ h) s x ↔ cont_mdiff_within_at J I' m f (h.symm ⁻¹' s) (h x) := begin split, { intro Hfh, rw [← h.symm_apply_apply x] at Hfh, simpa only [(∘), h.apply_symm_apply] using Hfh.comp (h x) (h.symm.cont_mdiff_within_at.of_le hm) (maps_to_preimage _ _) }, { rw ← h.image_eq_preimage, exact λ hf, hf.comp x (h.cont_mdiff_within_at.of_le hm) (maps_to_image _ _) } end @[simp] lemma cont_mdiff_on_comp_diffeomorph_iff {m} (h : M ≃ₘ^n⟮I, J⟯ N) {f : N → M'} {s} (hm : m ≤ n) : cont_mdiff_on I I' m (f ∘ h) s ↔ cont_mdiff_on J I' m f (h.symm ⁻¹' s) := h.to_equiv.forall_congr $ λ x, by simp only [hm, coe_to_equiv, symm_apply_apply, cont_mdiff_within_at_comp_diffeomorph_iff, mem_preimage] @[simp] lemma cont_mdiff_at_comp_diffeomorph_iff {m} (h : M ≃ₘ^n⟮I, J⟯ N) {f : N → M'} {x} (hm : m ≤ n) : cont_mdiff_at I I' m (f ∘ h) x ↔ cont_mdiff_at J I' m f (h x) := h.cont_mdiff_within_at_comp_diffeomorph_iff hm @[simp] lemma cont_mdiff_comp_diffeomorph_iff {m} (h : M ≃ₘ^n⟮I, J⟯ N) {f : N → M'} (hm : m ≤ n) : cont_mdiff I I' m (f ∘ h) ↔ cont_mdiff J I' m f := h.to_equiv.forall_congr $ λ x, (h.cont_mdiff_at_comp_diffeomorph_iff hm) @[simp] lemma cont_mdiff_within_at_diffeomorph_comp_iff {m} (h : M ≃ₘ^n⟮I, J⟯ N) {f : M' → M} (hm : m ≤ n) {s x} : cont_mdiff_within_at I' J m (h ∘ f) s x ↔ cont_mdiff_within_at I' I m f s x := ⟨λ Hhf, by simpa only [(∘), h.symm_apply_apply] using (h.symm.cont_mdiff_at.of_le hm).comp_cont_mdiff_within_at _ Hhf, λ Hf, (h.cont_mdiff_at.of_le hm).comp_cont_mdiff_within_at _ Hf⟩ @[simp] lemma cont_mdiff_at_diffeomorph_comp_iff {m} (h : M ≃ₘ^n⟮I, J⟯ N) {f : M' → M} (hm : m ≤ n) {x} : cont_mdiff_at I' J m (h ∘ f) x ↔ cont_mdiff_at I' I m f x := h.cont_mdiff_within_at_diffeomorph_comp_iff hm @[simp] lemma cont_mdiff_on_diffeomorph_comp_iff {m} (h : M ≃ₘ^n⟮I, J⟯ N) {f : M' → M} (hm : m ≤ n) {s} : cont_mdiff_on I' J m (h ∘ f) s ↔ cont_mdiff_on I' I m f s := forall₂_congr $ λ x hx, h.cont_mdiff_within_at_diffeomorph_comp_iff hm @[simp] lemma cont_mdiff_diffeomorph_comp_iff {m} (h : M ≃ₘ^n⟮I, J⟯ N) {f : M' → M} (hm : m ≤ n) : cont_mdiff I' J m (h ∘ f) ↔ cont_mdiff I' I m f := forall_congr $ λ x, h.cont_mdiff_within_at_diffeomorph_comp_iff hm lemma to_local_homeomorph_mdifferentiable (h : M ≃ₘ^n⟮I, J⟯ N) (hn : 1 ≤ n) : h.to_homeomorph.to_local_homeomorph.mdifferentiable I J := ⟨h.mdifferentiable_on _ hn, h.symm.mdifferentiable_on _ hn⟩ section constructions /-- Product of two diffeomorphisms. -/ def prod_congr (h₁ : M ≃ₘ^n⟮I, I'⟯ M') (h₂ : N ≃ₘ^n⟮J, J'⟯ N') : M × N ≃ₘ^n⟮I.prod J, I'.prod J'⟯ M' × N' := { cont_mdiff_to_fun := (h₁.cont_mdiff.comp cont_mdiff_fst).prod_mk (h₂.cont_mdiff.comp cont_mdiff_snd), cont_mdiff_inv_fun := (h₁.symm.cont_mdiff.comp cont_mdiff_fst).prod_mk (h₂.symm.cont_mdiff.comp cont_mdiff_snd), to_equiv := h₁.to_equiv.prod_congr h₂.to_equiv } @[simp] lemma prod_congr_symm (h₁ : M ≃ₘ^n⟮I, I'⟯ M') (h₂ : N ≃ₘ^n⟮J, J'⟯ N') : (h₁.prod_congr h₂).symm = h₁.symm.prod_congr h₂.symm := rfl @[simp] lemma coe_prod_congr (h₁ : M ≃ₘ^n⟮I, I'⟯ M') (h₂ : N ≃ₘ^n⟮J, J'⟯ N') : ⇑(h₁.prod_congr h₂) = prod.map h₁ h₂ := rfl section variables (I J J' M N N' n) /-- `M × N` is diffeomorphic to `N × M`. -/ def prod_comm : M × N ≃ₘ^n⟮I.prod J, J.prod I⟯ N × M := { cont_mdiff_to_fun := cont_mdiff_snd.prod_mk cont_mdiff_fst, cont_mdiff_inv_fun := cont_mdiff_snd.prod_mk cont_mdiff_fst, to_equiv := equiv.prod_comm M N } @[simp] lemma prod_comm_symm : (prod_comm I J M N n).symm = prod_comm J I N M n := rfl @[simp] lemma coe_prod_comm : ⇑(prod_comm I J M N n) = prod.swap := rfl /-- `(M × N) × N'` is diffeomorphic to `M × (N × N')`. -/ def prod_assoc : (M × N) × N' ≃ₘ^n⟮(I.prod J).prod J', I.prod (J.prod J')⟯ M × (N × N') := { cont_mdiff_to_fun := (cont_mdiff_fst.comp cont_mdiff_fst).prod_mk ((cont_mdiff_snd.comp cont_mdiff_fst).prod_mk cont_mdiff_snd), cont_mdiff_inv_fun := (cont_mdiff_fst.prod_mk (cont_mdiff_fst.comp cont_mdiff_snd)).prod_mk (cont_mdiff_snd.comp cont_mdiff_snd), to_equiv := equiv.prod_assoc M N N' } end end constructions variables [smooth_manifold_with_corners I M] [smooth_manifold_with_corners J N] lemma unique_mdiff_on_image_aux (h : M ≃ₘ^n⟮I, J⟯ N) (hn : 1 ≤ n) {s : set M} (hs : unique_mdiff_on I s) : unique_mdiff_on J (h '' s) := begin convert hs.unique_mdiff_on_preimage (h.to_local_homeomorph_mdifferentiable hn), simp [h.image_eq_preimage] end @[simp] lemma unique_mdiff_on_image (h : M ≃ₘ^n⟮I, J⟯ N) (hn : 1 ≤ n) {s : set M} : unique_mdiff_on J (h '' s) ↔ unique_mdiff_on I s := ⟨λ hs, h.symm_image_image s ▸ h.symm.unique_mdiff_on_image_aux hn hs, h.unique_mdiff_on_image_aux hn⟩ @[simp] lemma unique_mdiff_on_preimage (h : M ≃ₘ^n⟮I, J⟯ N) (hn : 1 ≤ n) {s : set N} : unique_mdiff_on I (h ⁻¹' s) ↔ unique_mdiff_on J s := h.symm_image_eq_preimage s ▸ h.symm.unique_mdiff_on_image hn @[simp] lemma unique_diff_on_image (h : E ≃ₘ^n[𝕜] F) (hn : 1 ≤ n) {s : set E} : unique_diff_on 𝕜 (h '' s) ↔ unique_diff_on 𝕜 s := by simp only [← unique_mdiff_on_iff_unique_diff_on, unique_mdiff_on_image, hn] @[simp] lemma unique_diff_on_preimage (h : E ≃ₘ^n[𝕜] F) (hn : 1 ≤ n) {s : set F} : unique_diff_on 𝕜 (h ⁻¹' s) ↔ unique_diff_on 𝕜 s := h.symm_image_eq_preimage s ▸ h.symm.unique_diff_on_image hn end diffeomorph namespace continuous_linear_equiv variable (e : E ≃L[𝕜] E') /-- A continuous linear equivalence between normed spaces is a diffeomorphism. -/ def to_diffeomorph : E ≃ₘ[𝕜] E' := { cont_mdiff_to_fun := e.cont_diff.cont_mdiff, cont_mdiff_inv_fun := e.symm.cont_diff.cont_mdiff, to_equiv := e.to_linear_equiv.to_equiv } @[simp] lemma coe_to_diffeomorph : ⇑e.to_diffeomorph = e := rfl @[simp] lemma symm_to_diffeomorph : e.symm.to_diffeomorph = e.to_diffeomorph.symm := rfl @[simp] lemma coe_to_diffeomorph_symm : ⇑e.to_diffeomorph.symm = e.symm := rfl end continuous_linear_equiv namespace model_with_corners variables (I) (e : E ≃ₘ[𝕜] E') /-- Apply a diffeomorphism (e.g., a continuous linear equivalence) to the model vector space. -/ def trans_diffeomorph (I : model_with_corners 𝕜 E H) (e : E ≃ₘ[𝕜] E') : model_with_corners 𝕜 E' H := { to_local_equiv := I.to_local_equiv.trans e.to_equiv.to_local_equiv, source_eq := by simp, unique_diff' := by simp [range_comp e, I.unique_diff], continuous_to_fun := e.continuous.comp I.continuous, continuous_inv_fun := I.continuous_symm.comp e.symm.continuous } @[simp, mfld_simps] lemma coe_trans_diffeomorph : ⇑(I.trans_diffeomorph e) = e ∘ I := rfl @[simp, mfld_simps] lemma coe_trans_diffeomorph_symm : ⇑(I.trans_diffeomorph e).symm = I.symm ∘ e.symm := rfl lemma trans_diffeomorph_range : range (I.trans_diffeomorph e) = e '' (range I) := range_comp e I lemma coe_ext_chart_at_trans_diffeomorph (x : M) : ⇑(ext_chart_at (I.trans_diffeomorph e) x) = e ∘ ext_chart_at I x := rfl lemma coe_ext_chart_at_trans_diffeomorph_symm (x : M) : ⇑(ext_chart_at (I.trans_diffeomorph e) x).symm = (ext_chart_at I x).symm ∘ e.symm := rfl lemma ext_chart_at_trans_diffeomorph_target (x : M) : (ext_chart_at (I.trans_diffeomorph e) x).target = e.symm ⁻¹' (ext_chart_at I x).target := by simp only [range_comp e, e.image_eq_preimage, preimage_preimage] with mfld_simps end model_with_corners namespace diffeomorph variables (e : E ≃ₘ[𝕜] F) instance smooth_manifold_with_corners_trans_diffeomorph [smooth_manifold_with_corners I M] : smooth_manifold_with_corners (I.trans_diffeomorph e) M := begin refine smooth_manifold_with_corners_of_cont_diff_on _ _ (λ e₁ e₂ h₁ h₂, _), refine e.cont_diff.comp_cont_diff_on (((cont_diff_groupoid ⊤ I).compatible h₁ h₂).1.comp e.symm.cont_diff.cont_diff_on _), mfld_set_tac end variables (I M) /-- The identity diffeomorphism between a manifold with model `I` and the same manifold with model `I.trans_diffeomorph e`. -/ def to_trans_diffeomorph (e : E ≃ₘ[𝕜] F) : M ≃ₘ⟮I, I.trans_diffeomorph e⟯ M := { to_equiv := equiv.refl M, cont_mdiff_to_fun := λ x, begin refine cont_mdiff_within_at_iff'.2 ⟨continuous_within_at_id, _⟩, refine e.cont_diff.cont_diff_within_at.congr' (λ y hy, _) _, { simp only [equiv.coe_refl, id, (∘), I.coe_ext_chart_at_trans_diffeomorph, (ext_chart_at I x).right_inv hy.1] }, exact ⟨(ext_chart_at I x).map_source (mem_ext_chart_source I x), trivial, by simp only with mfld_simps⟩ end, cont_mdiff_inv_fun := λ x, begin refine cont_mdiff_within_at_iff'.2 ⟨continuous_within_at_id, _⟩, refine e.symm.cont_diff.cont_diff_within_at.congr' (λ y hy, _) _, { simp only [mem_inter_eq, I.ext_chart_at_trans_diffeomorph_target] at hy, simp only [equiv.coe_refl, equiv.refl_symm, id, (∘), I.coe_ext_chart_at_trans_diffeomorph_symm, (ext_chart_at I x).right_inv hy.1] }, exact ⟨(ext_chart_at _ x).map_source (mem_ext_chart_source _ x), trivial, by simp only [e.symm_apply_apply, equiv.refl_symm, equiv.coe_refl] with mfld_simps⟩ end } variables {I M} @[simp] lemma cont_mdiff_within_at_trans_diffeomorph_right {f : M' → M} {x s} : cont_mdiff_within_at I' (I.trans_diffeomorph e) n f s x ↔ cont_mdiff_within_at I' I n f s x := (to_trans_diffeomorph I M e).cont_mdiff_within_at_diffeomorph_comp_iff le_top @[simp] lemma cont_mdiff_at_trans_diffeomorph_right {f : M' → M} {x} : cont_mdiff_at I' (I.trans_diffeomorph e) n f x ↔ cont_mdiff_at I' I n f x := (to_trans_diffeomorph I M e).cont_mdiff_at_diffeomorph_comp_iff le_top @[simp] lemma cont_mdiff_on_trans_diffeomorph_right {f : M' → M} {s} : cont_mdiff_on I' (I.trans_diffeomorph e) n f s ↔ cont_mdiff_on I' I n f s := (to_trans_diffeomorph I M e).cont_mdiff_on_diffeomorph_comp_iff le_top @[simp] lemma cont_mdiff_trans_diffeomorph_right {f : M' → M} : cont_mdiff I' (I.trans_diffeomorph e) n f ↔ cont_mdiff I' I n f := (to_trans_diffeomorph I M e).cont_mdiff_diffeomorph_comp_iff le_top @[simp] lemma smooth_trans_diffeomorph_right {f : M' → M} : smooth I' (I.trans_diffeomorph e) f ↔ smooth I' I f := cont_mdiff_trans_diffeomorph_right e @[simp] lemma cont_mdiff_within_at_trans_diffeomorph_left {f : M → M'} {x s} : cont_mdiff_within_at (I.trans_diffeomorph e) I' n f s x ↔ cont_mdiff_within_at I I' n f s x := ((to_trans_diffeomorph I M e).cont_mdiff_within_at_comp_diffeomorph_iff le_top).symm @[simp] lemma cont_mdiff_at_trans_diffeomorph_left {f : M → M'} {x} : cont_mdiff_at (I.trans_diffeomorph e) I' n f x ↔ cont_mdiff_at I I' n f x := ((to_trans_diffeomorph I M e).cont_mdiff_at_comp_diffeomorph_iff le_top).symm @[simp] lemma cont_mdiff_on_trans_diffeomorph_left {f : M → M'} {s} : cont_mdiff_on (I.trans_diffeomorph e) I' n f s ↔ cont_mdiff_on I I' n f s := ((to_trans_diffeomorph I M e).cont_mdiff_on_comp_diffeomorph_iff le_top).symm @[simp] lemma cont_mdiff_trans_diffeomorph_left {f : M → M'} : cont_mdiff (I.trans_diffeomorph e) I' n f ↔ cont_mdiff I I' n f := ((to_trans_diffeomorph I M e).cont_mdiff_comp_diffeomorph_iff le_top).symm @[simp] lemma smooth_trans_diffeomorph_left {f : M → M'} : smooth (I.trans_diffeomorph e) I' f ↔ smooth I I' f := e.cont_mdiff_trans_diffeomorph_left end diffeomorph
39767b16d93638ec43469b7d99575ae2936dc695
e030b0259b777fedcdf73dd966f3f1556d392178
/library/init/algebra/group.lean
a22f01b0f7b146c6cf302f3b42eeff669b70b546
[ "Apache-2.0" ]
permissive
fgdorais/lean
17b46a095b70b21fa0790ce74876658dc5faca06
c3b7c54d7cca7aaa25328f0a5660b6b75fe26055
refs/heads/master
1,611,523,590,686
1,484,412,902,000
1,484,412,902,000
38,489,734
0
0
null
1,435,923,380,000
1,435,923,379,000
null
UTF-8
Lean
false
false
15,923
lean
/- Copyright (c) 2016 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Leonardo de Moura -/ prelude import init.logic init.algebra.ac init.meta init.meta.decl_cmds /- Make sure instances defined in this file have lower priority than the ones defined for concrete structures -/ set_option default_priority 100 universe variable u variables {α : Type u} class semigroup (α : Type u) extends has_mul α := (mul_assoc : ∀ a b c : α, a * b * c = a * (b * c)) class comm_semigroup (α : Type u) extends semigroup α := (mul_comm : ∀ a b : α, a * b = b * a) class left_cancel_semigroup (α : Type u) extends semigroup α := (mul_left_cancel : ∀ a b c : α, a * b = a * c → b = c) class right_cancel_semigroup (α : Type u) extends semigroup α := (mul_right_cancel : ∀ a b c : α, a * b = c * b → a = c) class monoid (α : Type u) extends semigroup α, has_one α := (one_mul : ∀ a : α, 1 * a = a) (mul_one : ∀ a : α, a * 1 = a) class comm_monoid (α : Type u) extends monoid α, comm_semigroup α class group (α : Type u) extends monoid α, has_inv α := (mul_left_inv : ∀ a : α, a⁻¹ * a = 1) class comm_group (α : Type u) extends group α, comm_monoid α @[simp] lemma mul_assoc [semigroup α] : ∀ a b c : α, a * b * c = a * (b * c) := semigroup.mul_assoc instance semigroup_to_is_associative [semigroup α] : is_associative α mul := ⟨mul_assoc⟩ @[simp] lemma mul_comm [comm_semigroup α] : ∀ a b : α, a * b = b * a := comm_semigroup.mul_comm instance comm_semigroup_to_is_commutative [comm_semigroup α] : is_commutative α mul := ⟨mul_comm⟩ @[simp] lemma mul_left_comm [comm_semigroup α] : ∀ a b c : α, a * (b * c) = b * (a * c) := left_comm mul mul_comm mul_assoc lemma mul_left_cancel [left_cancel_semigroup α] {a b c : α} : a * b = a * c → b = c := left_cancel_semigroup.mul_left_cancel a b c lemma mul_right_cancel [right_cancel_semigroup α] {a b c : α} : a * b = c * b → a = c := right_cancel_semigroup.mul_right_cancel a b c @[simp] lemma one_mul [monoid α] : ∀ a : α, 1 * a = a := monoid.one_mul @[simp] lemma mul_one [monoid α] : ∀ a : α, a * 1 = a := monoid.mul_one @[simp] lemma mul_left_inv [group α] : ∀ a : α, a⁻¹ * a = 1 := group.mul_left_inv def inv_mul_self := @mul_left_inv @[simp] lemma inv_mul_cancel_left [group α] (a b : α) : a⁻¹ * (a * b) = b := by rw [-mul_assoc, mul_left_inv, one_mul] @[simp] lemma inv_mul_cancel_right [group α] (a b : α) : a * b⁻¹ * b = a := by simp @[simp] lemma inv_eq_of_mul_eq_one [group α] {a b : α} (h : a * b = 1) : a⁻¹ = b := by rw [-mul_one a⁻¹, -h, -mul_assoc, mul_left_inv, one_mul] @[simp] lemma one_inv [group α] : 1⁻¹ = (1 : α) := inv_eq_of_mul_eq_one (one_mul 1) @[simp] lemma inv_inv [group α] (a : α) : (a⁻¹)⁻¹ = a := inv_eq_of_mul_eq_one (mul_left_inv a) @[simp] lemma mul_right_inv [group α] (a : α) : a * a⁻¹ = 1 := have a⁻¹⁻¹ * a⁻¹ = 1, by rw mul_left_inv, by rwa [inv_inv] at this def mul_inv_self := @mul_right_inv lemma inv_inj [group α] {a b : α} (h : a⁻¹ = b⁻¹) : a = b := have a = a⁻¹⁻¹, by simp, begin rw this, simp [h] end lemma group.mul_left_cancel [group α] {a b c : α} (h : a * b = a * c) : b = c := have a⁻¹ * (a * b) = b, by simp, begin simp [h] at this, rw this end lemma group.mul_right_cancel [group α] {a b c : α} (h : a * b = c * b) : a = c := have a * b * b⁻¹ = a, by simp, begin simp [h] at this, rw this end instance group.to_left_cancel_semigroup [s : group α] : left_cancel_semigroup α := { s with mul_left_cancel := @group.mul_left_cancel α s } instance group.to_right_cancel_semigroup [s : group α] : right_cancel_semigroup α := { s with mul_right_cancel := @group.mul_right_cancel α s } lemma mul_inv_cancel_left [group α] (a b : α) : a * (a⁻¹ * b) = b := by rw [-mul_assoc, mul_right_inv, one_mul] lemma mul_inv_cancel_right [group α] (a b : α) : a * b * b⁻¹ = a := by rw [mul_assoc, mul_right_inv, mul_one] @[simp] lemma mul_inv_rev [group α] (a b : α) : (a * b)⁻¹ = b⁻¹ * a⁻¹ := inv_eq_of_mul_eq_one begin rw [mul_assoc, -mul_assoc b, mul_right_inv, one_mul, mul_right_inv] end lemma eq_inv_of_eq_inv [group α] {a b : α} (h : a = b⁻¹) : b = a⁻¹ := by simp [h] lemma eq_inv_of_mul_eq_one [group α] {a b : α} (h : a * b = 1) : a = b⁻¹ := have a⁻¹ = b, from inv_eq_of_mul_eq_one h, by simp [this^.symm] lemma eq_mul_inv_of_mul_eq [group α] {a b c : α} (h : a * c = b) : a = b * c⁻¹ := by simp [h^.symm] lemma eq_inv_mul_of_mul_eq [group α] {a b c : α} (h : b * a = c) : a = b⁻¹ * c := by simp [h^.symm] lemma inv_mul_eq_of_eq_mul [group α] {a b c : α} (h : b = a * c) : a⁻¹ * b = c := by simp [h] lemma mul_inv_eq_of_eq_mul [group α] {a b c : α} (h : a = c * b) : a * b⁻¹ = c := by simp [h] lemma eq_mul_of_mul_inv_eq [group α] {a b c : α} (h : a * c⁻¹ = b) : a = b * c := by simp [h^.symm] lemma eq_mul_of_inv_mul_eq [group α] {a b c : α} (h : b⁻¹ * a = c) : a = b * c := by simp [h^.symm, mul_inv_cancel_left] lemma mul_eq_of_eq_inv_mul [group α] {a b c : α} (h : b = a⁻¹ * c) : a * b = c := by rw [h, mul_inv_cancel_left] lemma mul_eq_of_eq_mul_inv [group α] {a b c : α} (h : a = c * b⁻¹) : a * b = c := by simp [h] lemma mul_inv [comm_group α] (a b : α) : (a * b)⁻¹ = a⁻¹ * b⁻¹ := by rw [mul_inv_rev, mul_comm] /- αdditive "sister" structures. Example, add_semigroup mirrors semigroup. These structures exist just to help automation. In an alternative design, we could have the binary operation as an extra argument for semigroup, monoid, group, etc. However, the lemmas would be hard to index since they would not contain any constant. For example, mul_assoc would be lemma mul_assoc {α : Type u} {op : α → α → α} [semigroup α op] : ∀ a b c : α, op (op a b) c = op a (op b c) := semigroup.mul_assoc The simplifier cannot effectively use this lemma since the pattern for the left-hand-side would be ?op (?op ?a ?b) ?c Remark: we use a tactic for transporting theorems from the multiplicative fragment to the additive one. -/ @[class] def add_semigroup := semigroup @[class] def add_monoid := monoid @[class] def add_group := group @[class] def add_comm_semigroup := comm_semigroup @[class] def add_comm_monoid := comm_monoid @[class] def add_comm_group := comm_group @[class] def add_left_cancel_semigroup := left_cancel_semigroup @[class] def add_right_cancel_semigroup := right_cancel_semigroup instance add_semigroup.to_has_add {α : Type u} [s : add_semigroup α] : has_add α := ⟨@semigroup.mul α s⟩ instance add_monoid.to_has_zero {α : Type u} [s : add_monoid α] : has_zero α := ⟨@monoid.one α s⟩ instance add_group.to_has_neg {α : Type u} [s : add_group α] : has_neg α := ⟨@group.inv α s⟩ open tactic meta def transport_with_dict (dict : name_map name) (src : name) (tgt : name) : command := copy_decl_updating_type dict src tgt >> copy_attribute `reducible src tt tgt >> copy_attribute `simp src tt tgt >> copy_attribute `instance src tt tgt meta def name_map_of_list_name (l : list name) : tactic (name_map name) := do list_pair_name ← monad.for l (λ nm, do e ← mk_const nm, eval_expr (list (name × name)) e), return $ rb_map.of_list (list.join list_pair_name) meta def transport_using_attr (attr : caching_user_attribute (name_map name)) (src : name) (tgt : name) : command := do dict ← caching_user_attribute.get_cache attr, transport_with_dict dict src tgt meta def multiplicative_to_additive_transport_attr : caching_user_attribute (name_map name) := { name := `multiplicative_to_additive_transport, descr := "list of name pairs for transporting multiplicative facts to additive ones", mk_cache := name_map_of_list_name, dependencies := [] } run_command attribute.register `multiplicative_to_additive_transport_attr meta def transport_to_additive : name → name → command := transport_using_attr multiplicative_to_additive_transport_attr @[multiplicative_to_additive_transport] meta def multiplicative_to_additive_pairs : list (name × name) := [/- map operations -/ (`mul, `add), (`one, `zero), (`inv, `neg), /- map structures -/ (`semigroup, `add_semigroup), (`monoid, `add_monoid), (`group, `add_group), (`comm_semigroup, `add_comm_semigroup), (`comm_monoid, `add_comm_monoid), (`comm_group, `add_comm_group), (`left_cancel_semigroup, `add_left_cancel_semigroup), (`right_cancel_semigroup, `add_right_cancel_semigroup), /- map instances -/ (`semigroup.to_has_mul, `add_semigroup.to_has_add), (`monoid.to_has_one, `add_monoid.to_has_zero), (`group.to_has_inv, `add_group.to_has_neg), (`comm_semigroup.to_semigroup, `add_comm_semigroup.to_add_semigroup), (`monoid.to_semigroup, `add_monoid.to_add_semigroup), (`comm_monoid.to_monoid, `add_comm_monoid.to_add_monoid), (`comm_monoid.to_comm_semigroup, `add_comm_monoid.to_add_comm_semigroup), (`group.to_monoid, `add_group.to_add_monoid), (`comm_group.to_group, `add_comm_group.to_add_group), (`comm_group.to_comm_monoid, `add_comm_group.to_add_comm_monoid), (`left_cancel_semigroup.to_semigroup, `add_left_cancel_semigroup.to_add_semigroup), (`right_cancel_semigroup.to_semigroup, `add_right_cancel_semigroup.to_add_semigroup) ] /- Make sure all constants at multiplicative_to_additive are declared -/ meta def init_multiplicative_to_additive : command := list.foldl (λ (tac : tactic unit) (p : name × name), do (s, t) ← return p, env ← get_env, if (env^.get t)^.to_bool = ff then tac >> transport_to_additive s t else tac) skip multiplicative_to_additive_pairs run_command init_multiplicative_to_additive run_command transport_to_additive `mul_assoc `add_assoc run_command transport_to_additive `mul_comm `add_comm run_command transport_to_additive `mul_left_comm `add_left_comm run_command transport_to_additive `one_mul `zero_add run_command transport_to_additive `mul_one `add_zero run_command transport_to_additive `mul_left_inv `add_left_neg run_command transport_to_additive `mul_left_cancel `add_left_cancel run_command transport_to_additive `mul_right_cancel `add_right_cancel run_command transport_to_additive `mul_inv_cancel_left `add_neg_cancel_left run_command transport_to_additive `mul_inv_cancel_right `add_neg_cancel_right run_command transport_to_additive `inv_mul_cancel_left `neg_add_cancel_left run_command transport_to_additive `inv_mul_cancel_right `neg_add_cancel_right run_command transport_to_additive `inv_eq_of_mul_eq_one `neg_eq_of_add_eq_zero run_command transport_to_additive `one_inv `neg_zero run_command transport_to_additive `inv_inv `neg_neg run_command transport_to_additive `mul_right_inv `add_right_neg run_command transport_to_additive `mul_inv_rev `neg_add_rev run_command transport_to_additive `mul_inv `neg_add run_command transport_to_additive `inv_inj `neg_inj run_command transport_to_additive `group.to_left_cancel_semigroup `add_group.to_left_cancel_add_semigroup run_command transport_to_additive `group.to_right_cancel_semigroup `add_group.to_right_cancel_add_semigroup run_command transport_to_additive `eq_inv_of_eq_inv `eq_neg_of_eq_neg run_command transport_to_additive `eq_inv_of_mul_eq_one `eq_neg_of_add_eq_zero run_command transport_to_additive `eq_mul_inv_of_mul_eq `eq_add_neg_of_add_eq run_command transport_to_additive `eq_inv_mul_of_mul_eq `eq_neg_add_of_add_eq run_command transport_to_additive `inv_mul_eq_of_eq_mul `neg_add_eq_of_eq_add run_command transport_to_additive `mul_inv_eq_of_eq_mul `add_neg_eq_of_eq_add run_command transport_to_additive `eq_mul_of_mul_inv_eq `eq_add_of_add_neg_eq run_command transport_to_additive `eq_mul_of_inv_mul_eq `eq_add_of_neg_add_eq run_command transport_to_additive `mul_eq_of_eq_inv_mul `add_eq_of_eq_neg_add run_command transport_to_additive `mul_eq_of_eq_mul_inv `add_eq_of_eq_add_neg instance add_semigroup_to_is_eq_associative [add_semigroup α] : is_associative α add := ⟨add_assoc⟩ instance add_comm_semigroup_to_is_eq_commutative [add_comm_semigroup α] : is_commutative α add := ⟨add_comm⟩ def neg_add_self := @add_left_neg def add_neg_self := @add_right_neg def eq_of_add_eq_add_left := @add_left_cancel def eq_of_add_eq_add_right := @add_right_cancel @[reducible] protected def algebra.sub [add_group α] (a b : α) : α := a + -b instance add_group_has_sub [add_group α] : has_sub α := ⟨algebra.sub⟩ @[simp] lemma sub_eq_add_neg [add_group α] (a b : α) : a - b = a + -b := rfl lemma sub_self [add_group α] (a : α) : a - a = 0 := add_right_neg a lemma sub_add_cancel [add_group α] (a b : α) : a - b + b = a := neg_add_cancel_right a b lemma add_sub_cancel [add_group α] (a b : α) : a + b - b = a := add_neg_cancel_right a b lemma add_sub_assoc [add_group α] (a b c : α) : a + b - c = a + (b - c) := by rw [sub_eq_add_neg, add_assoc, -sub_eq_add_neg] lemma eq_of_sub_eq_zero [add_group α] {a b : α} (h : a - b = 0) : a = b := have 0 + b = b, by rw zero_add, have (a - b) + b = b, by rwa h, by rwa [sub_eq_add_neg, neg_add_cancel_right] at this lemma sub_eq_zero_of_eq [add_group α] {a b : α} (h : a = b) : a - b = 0 := by rw [h, sub_self] lemma zero_sub [add_group α] (a : α) : 0 - a = -a := zero_add (-a) lemma sub_zero [add_group α] (a : α) : a - 0 = a := by rw [sub_eq_add_neg, neg_zero, add_zero] lemma sub_ne_zero_of_ne [add_group α] {a b : α} (h : a ≠ b) : a - b ≠ 0 := begin intro hab, apply h, apply eq_of_sub_eq_zero hab end lemma sub_neg_eq_add [add_group α] (a b : α) : a - (-b) = a + b := by rw [sub_eq_add_neg, neg_neg] lemma neg_sub [add_group α] (a b : α) : -(a - b) = b - a := neg_eq_of_add_eq_zero (by rw [sub_eq_add_neg, sub_eq_add_neg, add_assoc, neg_add_cancel_left, add_right_neg]) lemma add_sub [add_group α] (a b c : α) : a + (b - c) = a + b - c := by simp lemma sub_add_eq_sub_sub_swap [add_group α] (a b c : α) : a - (b + c) = a - c - b := by simp lemma eq_sub_of_add_eq [add_group α] {a b c : α} (h : a + c = b) : a = b - c := by simp [h^.symm] lemma sub_eq_of_eq_add [add_group α] {a b c : α} (h : a = c + b) : a - b = c := by simp [h] lemma eq_add_of_sub_eq [add_group α] {a b c : α} (h : a - c = b) : a = b + c := by simp [h^.symm] lemma add_eq_of_eq_sub [add_group α] {a b c : α} (h : a = c - b) : a + b = c := by simp [h] lemma sub_add_eq_sub_sub [add_comm_group α] (a b c : α) : a - (b + c) = a - b - c := by simp lemma neg_add_eq_sub [add_comm_group α] (a b : α) : -a + b = b - a := by simp lemma sub_add_eq_add_sub [add_comm_group α] (a b c : α) : a - b + c = a + c - b := by simp lemma sub_sub [add_comm_group α] (a b c : α) : a - b - c = a - (b + c) := by simp lemma add_sub_add_left_eq_sub [add_comm_group α] (a b c : α) : (c + a) - (c + b) = a - b := by simp lemma eq_sub_of_add_eq' [add_comm_group α] {a b c : α} (h : c + a = b) : a = b - c := by simp [h^.symm] lemma sub_eq_of_eq_add' [add_comm_group α] {a b c : α} (h : a = b + c) : a - b = c := by simp [h] lemma eq_add_of_sub_eq' [add_comm_group α] {a b c : α} (h : a - b = c) : a = b + c := by simp [h^.symm] lemma add_eq_of_eq_sub' [add_comm_group α] {a b c : α} (h : b = c - a) : a + b = c := begin simp [h], rw [add_comm c, add_neg_cancel_left] end lemma sub_sub_self [add_comm_group α] (a b : α) : a - (a - b) = b := begin simp, rw [add_comm b, add_neg_cancel_left] end lemma add_sub_comm [add_comm_group α] (a b c d : α) : a + b - (c + d) = (a - c) + (b - d) := by simp lemma sub_eq_sub_add_sub [add_comm_group α] (a b c : α) : a - b = c - b + (a - c) := by simp lemma neg_neg_sub_neg [add_comm_group α] (a b : α) : - (-a - -b) = a - b := by simp
807079dd5cbafcd84f3cf4308be69119bd52a3b7
97c8e5d8aca4afeebb5b335f26a492c53680efc8
/ground_zero/proto.lean
b2734e8e2e6914bd986057afd39b7655bd5fc4cf
[]
no_license
jfrancese/lean
cf32f0d8d5520b6f0e9d3987deb95841c553c53c
06e7efaecce4093d97fb5ecc75479df2ef1dbbdb
refs/heads/master
1,587,915,151,351
1,551,012,140,000
1,551,012,140,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
247
lean
namespace ground_zero.proto universes u v structure iff (α : Sort u) (β : Sort v) := (left : α → β) (right : β → α) infix ↔ := iff notation [parsing_only] `𝟎` := empty notation [parsing_only] `𝟐` := bool end ground_zero.proto
37969eeef188b77bc4a599af1c8597f65499383b
64874bd1010548c7f5a6e3e8902efa63baaff785
/hott/init/axioms/funext_from_ua.hlean
973941e09c140505884e01310ba1da15934eb655
[ "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
5,053
hlean
-- Copyright (c) 2014 Jakob von Raumer. All rights reserved. -- Released under Apache 2.0 license as described in the file LICENSE. -- Author: Jakob von Raumer -- Ported from Coq HoTT prelude import ..equiv ..datatypes ..types.prod import .funext_varieties .ua .funext open eq function prod sigma truncation equiv is_equiv unit context universe variables l protected theorem ua_isequiv_postcompose {A B : Type.{l}} {C : Type} {w : A → B} {H0 : is_equiv w} : is_equiv (@compose C A B w) := let w' := equiv.mk w H0 in let eqinv : A = B := ((@is_equiv.inv _ _ _ (ua_is_equiv A B)) w') in let eq' := equiv_path eqinv in is_equiv.adjointify (@compose C A B w) (@compose C B A (is_equiv.inv w)) (λ (x : C → B), have eqretr : eq' = w', from (@retr _ _ (@equiv_path A B) (ua_is_equiv A B) w'), have invs_eq : (to_fun eq')⁻¹ = (to_fun w')⁻¹, from inv_eq eq' w' eqretr, have eqfin : (to_fun eq') ∘ ((to_fun eq')⁻¹ ∘ x) = x, from (λ p, (@eq.rec_on Type.{l} A (λ B' p', Π (x' : C → B'), (to_fun (equiv_path p')) ∘ ((to_fun (equiv_path p'))⁻¹ ∘ x') = x') B p (λ x', idp)) ) eqinv x, have eqfin' : (to_fun w') ∘ ((to_fun eq')⁻¹ ∘ x) = x, from eqretr ▹ eqfin, have eqfin'' : (to_fun w') ∘ ((to_fun w')⁻¹ ∘ x) = x, from invs_eq ▹ eqfin', eqfin'' ) (λ (x : C → A), have eqretr : eq' = w', from (@retr _ _ (@equiv_path A B) (ua_is_equiv A B) w'), have invs_eq : (to_fun eq')⁻¹ = (to_fun w')⁻¹, from inv_eq eq' w' eqretr, have eqfin : (to_fun eq')⁻¹ ∘ ((to_fun eq') ∘ x) = x, from (λ p, eq.rec_on p idp) eqinv, have eqfin' : (to_fun eq')⁻¹ ∘ ((to_fun w') ∘ x) = x, from eqretr ▹ eqfin, have eqfin'' : (to_fun w')⁻¹ ∘ ((to_fun w') ∘ x) = x, from invs_eq ▹ eqfin', eqfin'' ) -- We are ready to prove functional extensionality, -- starting with the naive non-dependent version. protected definition diagonal [reducible] (B : Type) : Type := Σ xy : B × B, pr₁ xy = pr₂ xy protected definition isequiv_src_compose {A B : Type} : @is_equiv (A → diagonal B) (A → B) (compose (pr₁ ∘ pr1)) := @ua_isequiv_postcompose _ _ _ (pr₁ ∘ pr1) (is_equiv.adjointify (pr₁ ∘ pr1) (λ x, sigma.mk (x , x) idp) (λx, idp) (λ x, sigma.rec_on x (λ xy, prod.rec_on xy (λ b c p, eq.rec_on p idp)))) protected definition isequiv_tgt_compose {A B : Type} : @is_equiv (A → diagonal B) (A → B) (compose (pr₂ ∘ pr1)) := @ua_isequiv_postcompose _ _ _ (pr2 ∘ pr1) (is_equiv.adjointify (pr2 ∘ pr1) (λ x, sigma.mk (x , x) idp) (λx, idp) (λ x, sigma.rec_on x (λ xy, prod.rec_on xy (λ b c p, eq.rec_on p idp)))) theorem nondep_funext_from_ua {A : Type} {B : Type} : Π {f g : A → B}, f ∼ g → f = g := (λ (f g : A → B) (p : f ∼ g), let d := λ (x : A), sigma.mk (f x , f x) idp in let e := λ (x : A), sigma.mk (f x , g x) (p x) in let precomp1 := compose (pr₁ ∘ pr1) in have equiv1 [visible] : is_equiv precomp1, from @isequiv_src_compose A B, have equiv2 [visible] : Π x y, is_equiv (ap precomp1), from is_equiv.ap_closed precomp1, have H' : Π (x y : A → diagonal B), pr₁ ∘ pr1 ∘ x = pr₁ ∘ pr1 ∘ y → x = y, from (λ x y, is_equiv.inv (ap precomp1)), have eq2 : pr₁ ∘ pr1 ∘ d = pr₁ ∘ pr1 ∘ e, from idp, have eq0 : d = e, from H' d e eq2, have eq1 : (pr₂ ∘ pr1) ∘ d = (pr₂ ∘ pr1) ∘ e, from ap _ eq0, eq1 ) end -- Now we use this to prove weak funext, which as we know -- implies (with dependent eta) also the strong dependent funext. theorem weak_funext_from_ua : weak_funext := (λ (A : Type) (P : A → Type) allcontr, let U := (λ (x : A), unit) in have pequiv : Π (x : A), P x ≃ U x, from (λ x, @equiv_contr_unit(P x) (allcontr x)), have psim : Π (x : A), P x = U x, from (λ x, @is_equiv.inv _ _ equiv_path (ua_is_equiv _ _) (pequiv x)), have p : P = U, from @nondep_funext_from_ua A Type P U psim, have tU' : is_contr (A → unit), from is_contr.mk (λ x, ⋆) (λ f, @nondep_funext_from_ua A unit (λ x, ⋆) f (λ x, unit.rec_on (f x) idp)), have tU : is_contr (Π x, U x), from tU', have tlast : is_contr (Πx, P x), from eq.transport _ (p⁻¹) tU, tlast ) -- In the following we will proof function extensionality using the univalence axiom definition funext_from_ua [instance] : funext := funext_from_weak_funext (@weak_funext_from_ua)
5f3d88e23d5864314c1c70182a84d5dfb95ae5ab
07c6143268cfb72beccd1cc35735d424ebcb187b
/src/data/real/ennreal.lean
8d2bf411a21b2a7a616a376a54f7d43d68a86306
[ "Apache-2.0" ]
permissive
khoek/mathlib
bc49a842910af13a3c372748310e86467d1dc766
aa55f8b50354b3e11ba64792dcb06cccb2d8ee28
refs/heads/master
1,588,232,063,837
1,587,304,803,000
1,587,304,803,000
176,688,517
0
0
Apache-2.0
1,553,070,585,000
1,553,070,585,000
null
UTF-8
Lean
false
false
44,707
lean
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Johannes Hölzl, Yury Kudryashov Extended non-negative reals -/ import data.real.nnreal order.bounds data.set.intervals tactic.norm_num noncomputable theory open classical set open_locale classical variables {α : Type*} {β : Type*} /-- The extended nonnegative real numbers. This is usually denoted [0, ∞], and is relevant as the codomain of a measure. -/ @[derive canonically_ordered_comm_semiring, derive complete_linear_order, derive densely_ordered] def ennreal := with_top nnreal localized "notation `∞` := (⊤ : ennreal)" in ennreal namespace ennreal variables {a b c d : ennreal} {r p q : nnreal} instance : inhabited ennreal := ⟨0⟩ instance : has_coe nnreal ennreal := ⟨ option.some ⟩ instance : can_lift ennreal nnreal := { coe := coe, cond := λ r, r ≠ ∞, prf := λ x hx, ⟨option.get $ option.ne_none_iff_is_some.1 hx, option.some_get _⟩ } @[simp] lemma none_eq_top : (none : ennreal) = (⊤ : ennreal) := rfl @[simp] lemma some_eq_coe (a : nnreal) : (some a : ennreal) = (↑a : ennreal) := rfl /-- `to_nnreal x` returns `x` if it is real, otherwise 0. -/ protected def to_nnreal : ennreal → nnreal | (some r) := r | none := 0 /-- `to_real x` returns `x` if it is real, `0` otherwise. -/ protected def to_real (a : ennreal) : real := coe (a.to_nnreal) /-- `of_real x` returns `x` if it is nonnegative, `0` otherwise. -/ protected def of_real (r : real) : ennreal := coe (nnreal.of_real r) @[simp, norm_cast] lemma to_nnreal_coe : (r : ennreal).to_nnreal = r := rfl @[simp] lemma coe_to_nnreal : ∀{a:ennreal}, a ≠ ∞ → ↑(a.to_nnreal) = a | (some r) h := rfl | none h := (h rfl).elim @[simp] lemma of_real_to_real {a : ennreal} (h : a ≠ ∞) : ennreal.of_real (a.to_real) = a := by simp [ennreal.to_real, ennreal.of_real, h] @[simp] lemma to_real_of_real {r : real} (h : 0 ≤ r) : ennreal.to_real (ennreal.of_real r) = r := by simp [ennreal.to_real, ennreal.of_real, nnreal.coe_of_real _ h] lemma coe_to_nnreal_le_self : ∀{a:ennreal}, ↑(a.to_nnreal) ≤ a | (some r) := by rw [some_eq_coe, to_nnreal_coe]; exact le_refl _ | none := le_top lemma coe_nnreal_eq (r : nnreal) : (r : ennreal) = ennreal.of_real r := by { rw [ennreal.of_real, nnreal.of_real], cases r with r h, congr, dsimp, rw max_eq_left h } lemma of_real_eq_coe_nnreal {x : real} (h : 0 ≤ x) : ennreal.of_real x = @coe nnreal ennreal _ (⟨x, h⟩ : nnreal) := by { rw [coe_nnreal_eq], refl } @[simp, norm_cast] lemma coe_zero : ↑(0 : nnreal) = (0 : ennreal) := rfl @[simp, norm_cast] lemma coe_one : ↑(1 : nnreal) = (1 : ennreal) := rfl @[simp] lemma to_real_nonneg {a : ennreal} : 0 ≤ a.to_real := by simp [ennreal.to_real] @[simp] lemma top_to_nnreal : ∞.to_nnreal = 0 := rfl @[simp] lemma top_to_real : ∞.to_real = 0 := rfl @[simp] lemma coe_to_real (r : nnreal) : (r : ennreal).to_real = r := rfl @[simp] lemma zero_to_nnreal : (0 : ennreal).to_nnreal = 0 := rfl @[simp] lemma zero_to_real : (0 : ennreal).to_real = 0 := rfl @[simp] lemma of_real_zero : ennreal.of_real (0 : ℝ) = 0 := by simp [ennreal.of_real]; refl @[simp] lemma of_real_one : ennreal.of_real (1 : ℝ) = (1 : ennreal) := by simp [ennreal.of_real] lemma of_real_to_real_le {a : ennreal} : ennreal.of_real (a.to_real) ≤ a := if ha : a = ∞ then ha.symm ▸ le_top else le_of_eq (of_real_to_real ha) lemma forall_ennreal {p : ennreal → Prop} : (∀a, p a) ↔ (∀r:nnreal, p r) ∧ p ∞ := ⟨assume h, ⟨assume r, h _, h _⟩, assume ⟨h₁, h₂⟩ a, match a with some r := h₁ _ | none := h₂ end⟩ lemma to_nnreal_eq_zero_iff (x : ennreal) : x.to_nnreal = 0 ↔ x = 0 ∨ x = ⊤ := ⟨begin cases x, { simp [none_eq_top] }, { have A : some (0:nnreal) = (0:ennreal) := rfl, simp [ennreal.to_nnreal, A] {contextual := tt} } end, by intro h; cases h; simp [h]⟩ lemma to_real_eq_zero_iff (x : ennreal) : x.to_real = 0 ↔ x = 0 ∨ x = ⊤ := by simp [ennreal.to_real, to_nnreal_eq_zero_iff] @[simp] lemma coe_ne_top : (r : ennreal) ≠ ∞ := with_top.coe_ne_top @[simp] lemma top_ne_coe : ∞ ≠ (r : ennreal) := with_top.top_ne_coe @[simp] lemma of_real_ne_top {r : ℝ} : ennreal.of_real r ≠ ∞ := by simp [ennreal.of_real] @[simp] lemma top_ne_of_real {r : ℝ} : ∞ ≠ ennreal.of_real r := by simp [ennreal.of_real] @[simp] lemma zero_ne_top : 0 ≠ ∞ := coe_ne_top @[simp] lemma top_ne_zero : ∞ ≠ 0 := top_ne_coe @[simp] lemma one_ne_top : 1 ≠ ∞ := coe_ne_top @[simp] lemma top_ne_one : ∞ ≠ 1 := top_ne_coe @[simp, norm_cast] lemma coe_eq_coe : (↑r : ennreal) = ↑q ↔ r = q := with_top.coe_eq_coe @[simp, norm_cast] lemma coe_le_coe : (↑r : ennreal) ≤ ↑q ↔ r ≤ q := with_top.coe_le_coe @[simp, norm_cast] lemma coe_lt_coe : (↑r : ennreal) < ↑q ↔ r < q := with_top.coe_lt_coe lemma coe_mono : monotone (coe : nnreal → ennreal) := λ _ _, coe_le_coe.2 @[simp, norm_cast] lemma coe_eq_zero : (↑r : ennreal) = 0 ↔ r = 0 := coe_eq_coe @[simp, norm_cast] lemma zero_eq_coe : 0 = (↑r : ennreal) ↔ 0 = r := coe_eq_coe @[simp, norm_cast] lemma coe_eq_one : (↑r : ennreal) = 1 ↔ r = 1 := coe_eq_coe @[simp, norm_cast] lemma one_eq_coe : 1 = (↑r : ennreal) ↔ 1 = r := coe_eq_coe @[simp, norm_cast] lemma coe_nonneg : 0 ≤ (↑r : ennreal) ↔ 0 ≤ r := coe_le_coe @[simp, norm_cast] lemma coe_pos : 0 < (↑r : ennreal) ↔ 0 < r := coe_lt_coe @[simp, norm_cast] lemma coe_add : ↑(r + p) = (r + p : ennreal) := with_top.coe_add @[simp, norm_cast] lemma coe_mul : ↑(r * p) = (r * p : ennreal) := with_top.coe_mul @[simp, norm_cast] lemma coe_bit0 : (↑(bit0 r) : ennreal) = bit0 r := coe_add @[simp, norm_cast] lemma coe_bit1 : (↑(bit1 r) : ennreal) = bit1 r := by simp [bit1] lemma coe_two : ((2:nnreal) : ennreal) = 2 := by norm_cast protected lemma zero_lt_one : 0 < (1 : ennreal) := canonically_ordered_semiring.zero_lt_one @[simp] lemma one_lt_two : (1:ennreal) < 2 := coe_one ▸ coe_two ▸ by exact_mod_cast one_lt_two @[simp] lemma two_pos : (0:ennreal) < 2 := lt_trans ennreal.zero_lt_one one_lt_two lemma two_ne_zero : (2:ennreal) ≠ 0 := ne_of_gt two_pos lemma two_ne_top : (2:ennreal) ≠ ∞ := coe_two ▸ coe_ne_top @[simp] lemma add_top : a + ∞ = ∞ := with_top.add_top @[simp] lemma top_add : ∞ + a = ∞ := with_top.top_add instance : is_semiring_hom (coe : nnreal → ennreal) := by refine_struct {..}; simp @[simp, norm_cast] lemma coe_pow (n : ℕ) : (↑(r^n) : ennreal) = r^n := is_monoid_hom.map_pow coe r n lemma add_eq_top : a + b = ∞ ↔ a = ∞ ∨ b = ∞ := with_top.add_eq_top _ _ lemma add_lt_top : a + b < ∞ ↔ a < ∞ ∧ b < ∞ := with_top.add_lt_top _ _ lemma to_nnreal_add {r₁ r₂ : ennreal} (h₁ : r₁ < ⊤) (h₂ : r₂ < ⊤) : (r₁ + r₂).to_nnreal = r₁.to_nnreal + r₂.to_nnreal := begin rw [← coe_eq_coe, coe_add, coe_to_nnreal, coe_to_nnreal, coe_to_nnreal]; apply @ne_top_of_lt ennreal _ _ ⊤, exact h₂, exact h₁, exact add_lt_top.2 ⟨h₁, h₂⟩ end /- rw has trouble with the generic lt_top_iff_ne_top and bot_lt_iff_ne_bot (contrary to erw). This is solved with the next lemmas -/ protected lemma lt_top_iff_ne_top : a < ∞ ↔ a ≠ ∞ := lt_top_iff_ne_top protected lemma bot_lt_iff_ne_bot : 0 < a ↔ a ≠ 0 := bot_lt_iff_ne_bot lemma add_ne_top : a + b ≠ ∞ ↔ a ≠ ∞ ∧ b ≠ ∞ := by simpa only [lt_top_iff_ne_top] using add_lt_top lemma mul_top : a * ∞ = (if a = 0 then 0 else ∞) := begin split_ifs, { simp [h] }, { exact with_top.mul_top h } end lemma top_mul : ∞ * a = (if a = 0 then 0 else ∞) := begin split_ifs, { simp [h] }, { exact with_top.top_mul h } end @[simp] lemma top_mul_top : ∞ * ∞ = ∞ := with_top.top_mul_top lemma top_pow {n:ℕ} (h : 0 < n) : ∞^n = ∞ := nat.le_induction (pow_one _) (λ m hm hm', by rw [pow_succ, hm', top_mul_top]) _ (nat.succ_le_of_lt h) lemma mul_eq_top {a b : ennreal} : a * b = ⊤ ↔ (a ≠ 0 ∧ b = ⊤) ∨ (a = ⊤ ∧ b ≠ 0) := with_top.mul_eq_top_iff lemma mul_ne_top {a b : ennreal} : a ≠ ∞ → b ≠ ∞ → a * b ≠ ∞ := by simp [(≠), mul_eq_top] {contextual := tt} lemma mul_lt_top {a b : ennreal} : a < ⊤ → b < ⊤ → a * b < ⊤ := by simpa only [ennreal.lt_top_iff_ne_top] using mul_ne_top lemma pow_eq_top : ∀ n:ℕ, a^n=∞ → a=∞ | 0 := by simp | (n+1) := λ o, (mul_eq_top.1 o).elim (λ h, pow_eq_top n h.2) and.left lemma pow_ne_top (h : a ≠ ∞) {n:ℕ} : a^n ≠ ∞ := mt (pow_eq_top n) h lemma pow_lt_top : a < ∞ → ∀ n:ℕ, a^n < ∞ := by simpa only [lt_top_iff_ne_top] using pow_ne_top @[simp, norm_cast] lemma coe_finset_sum {s : finset α} {f : α → nnreal} : ↑(s.sum f) = (s.sum (λa, f a) : ennreal) := (s.sum_hom coe).symm @[simp, norm_cast] lemma coe_finset_prod {s : finset α} {f : α → nnreal} : ↑(s.prod f) = (s.prod (λa, f a) : ennreal) := (s.prod_hom coe).symm section order @[simp] lemma bot_eq_zero : (⊥ : ennreal) = 0 := rfl @[simp] lemma coe_lt_top : coe r < ∞ := with_top.coe_lt_top r @[simp] lemma not_top_le_coe : ¬ (⊤:ennreal) ≤ ↑r := with_top.not_top_le_coe r lemma zero_lt_coe_iff : 0 < (↑p : ennreal) ↔ 0 < p := coe_lt_coe @[simp, norm_cast] lemma one_le_coe_iff : (1:ennreal) ≤ ↑r ↔ 1 ≤ r := coe_le_coe @[simp, norm_cast] lemma coe_le_one_iff : ↑r ≤ (1:ennreal) ↔ r ≤ 1 := coe_le_coe @[simp, norm_cast] lemma coe_lt_one_iff : (↑p : ennreal) < 1 ↔ p < 1 := coe_lt_coe @[simp, norm_cast] lemma one_lt_coe_iff : 1 < (↑p : ennreal) ↔ 1 < p := coe_lt_coe @[simp, norm_cast] lemma coe_nat (n : nat) : ((n : nnreal) : ennreal) = n := with_top.coe_nat n @[simp] lemma nat_ne_top (n : nat) : (n : ennreal) ≠ ⊤ := with_top.nat_ne_top n @[simp] lemma top_ne_nat (n : nat) : (⊤ : ennreal) ≠ n := with_top.top_ne_nat n lemma le_coe_iff : a ≤ ↑r ↔ (∃p:nnreal, a = p ∧ p ≤ r) := with_top.le_coe_iff r a lemma coe_le_iff : ↑r ≤ a ↔ (∀p:nnreal, a = p → r ≤ p) := with_top.coe_le_iff r a lemma lt_iff_exists_coe : a < b ↔ (∃p:nnreal, a = p ∧ ↑p < b) := with_top.lt_iff_exists_coe a b lemma pow_le_pow {n m : ℕ} (ha : 1 ≤ a) (h : n ≤ m) : a ^ n ≤ a ^ m := begin cases a, { cases m, { rw eq_bot_iff.mpr h, exact le_refl _ }, { rw [none_eq_top, top_pow (nat.succ_pos m)], exact le_top } }, { rw [some_eq_coe, ← coe_pow, ← coe_pow, coe_le_coe], exact pow_le_pow (by simpa using ha) h } end @[simp] lemma max_eq_zero_iff : max a b = 0 ↔ a = 0 ∧ b = 0 := by simp only [le_zero_iff_eq.symm, max_le_iff] @[simp] lemma max_zero_left : max 0 a = a := max_eq_right (zero_le a) @[simp] lemma max_zero_right : max a 0 = a := max_eq_left (zero_le a) -- TODO: why this is not a `rfl`? There is some hidden diamond here. @[simp] lemma sup_eq_max : a ⊔ b = max a b := eq_of_forall_ge_iff $ λ c, sup_le_iff.trans max_le_iff.symm protected lemma pow_pos : 0 < a → ∀ n : ℕ, 0 < a^n := canonically_ordered_semiring.pow_pos protected lemma pow_ne_zero : a ≠ 0 → ∀ n : ℕ, a^n ≠ 0 := by simpa only [zero_lt_iff_ne_zero] using ennreal.pow_pos @[simp] lemma not_lt_zero : ¬ a < 0 := by simp lemma add_lt_add_iff_left : a < ⊤ → (a + c < a + b ↔ c < b) := with_top.add_lt_add_iff_left lemma add_lt_add_iff_right : a < ⊤ → (c + a < b + a ↔ c < b) := with_top.add_lt_add_iff_right lemma lt_add_right (ha : a < ⊤) (hb : 0 < b) : a < a + b := by rwa [← add_lt_add_iff_left ha, add_zero] at hb lemma le_of_forall_epsilon_le : ∀{a b : ennreal}, (∀ε:nnreal, 0 < ε → b < ∞ → a ≤ b + ε) → a ≤ b | a none h := le_top | none (some a) h := have (⊤:ennreal) ≤ ↑a + ↑(1:nnreal), from h 1 zero_lt_one coe_lt_top, by rw [← coe_add] at this; exact (not_top_le_coe this).elim | (some a) (some b) h := by simp only [none_eq_top, some_eq_coe, coe_add.symm, coe_le_coe, coe_lt_top, true_implies_iff] at *; exact nnreal.le_of_forall_epsilon_le h lemma lt_iff_exists_rat_btwn : a < b ↔ (∃q:ℚ, 0 ≤ q ∧ a < nnreal.of_real q ∧ (nnreal.of_real q:ennreal) < b) := ⟨λ h, begin rcases lt_iff_exists_coe.1 h with ⟨p, rfl, _⟩, rcases dense h with ⟨c, pc, cb⟩, rcases lt_iff_exists_coe.1 cb with ⟨r, rfl, _⟩, rcases (nnreal.lt_iff_exists_rat_btwn _ _).1 (coe_lt_coe.1 pc) with ⟨q, hq0, pq, qr⟩, exact ⟨q, hq0, coe_lt_coe.2 pq, lt_trans (coe_lt_coe.2 qr) cb⟩ end, λ ⟨q, q0, qa, qb⟩, lt_trans qa qb⟩ lemma lt_iff_exists_real_btwn : a < b ↔ (∃r:ℝ, 0 ≤ r ∧ a < ennreal.of_real r ∧ (ennreal.of_real r:ennreal) < b) := ⟨λ h, let ⟨q, q0, aq, qb⟩ := ennreal.lt_iff_exists_rat_btwn.1 h in ⟨q, rat.cast_nonneg.2 q0, aq, qb⟩, λ ⟨q, q0, qa, qb⟩, lt_trans qa qb⟩ lemma lt_iff_exists_nnreal_btwn : a < b ↔ (∃r:nnreal, a < r ∧ (r : ennreal) < b) := with_top.lt_iff_exists_coe_btwn lemma lt_iff_exists_add_pos_lt : a < b ↔ (∃ r : nnreal, 0 < r ∧ a + r < b) := begin refine ⟨λ hab, _, λ ⟨r, rpos, hr⟩, lt_of_le_of_lt (le_add_right (le_refl _)) hr⟩, cases a, { simpa using hab }, rcases lt_iff_exists_real_btwn.1 hab with ⟨c, c_nonneg, ac, cb⟩, let d : nnreal := ⟨c, c_nonneg⟩, have ad : a < d, { rw of_real_eq_coe_nnreal c_nonneg at ac, exact coe_lt_coe.1 ac }, refine ⟨d-a, nnreal.sub_pos.2 ad, _⟩, rw [some_eq_coe, ← coe_add], convert cb, have : nnreal.of_real c = d, by { rw [← nnreal.coe_eq, nnreal.coe_of_real _ c_nonneg], refl }, rw [add_comm, this], exact nnreal.sub_add_cancel_of_le (le_of_lt ad) end lemma coe_nat_lt_coe {n : ℕ} : (n : ennreal) < r ↔ ↑n < r := ennreal.coe_nat n ▸ coe_lt_coe lemma coe_lt_coe_nat {n : ℕ} : (r : ennreal) < n ↔ r < n := ennreal.coe_nat n ▸ coe_lt_coe @[norm_cast] lemma coe_nat_lt_coe_nat {m n : ℕ} : (m : ennreal) < n ↔ m < n := ennreal.coe_nat n ▸ coe_nat_lt_coe.trans nat.cast_lt lemma coe_nat_ne_top {n : ℕ} : (n : ennreal) ≠ ∞ := ennreal.coe_nat n ▸ coe_ne_top lemma coe_nat_mono : strict_mono (coe : ℕ → ennreal) := λ _ _, coe_nat_lt_coe_nat.2 @[norm_cast] lemma coe_nat_le_coe_nat {m n : ℕ} : (m : ennreal) ≤ n ↔ m ≤ n := coe_nat_mono.le_iff_le instance : char_zero ennreal := ⟨coe_nat_mono.injective⟩ protected lemma exists_nat_gt {r : ennreal} (h : r ≠ ⊤) : ∃n:ℕ, r < n := begin rcases lt_iff_exists_coe.1 (lt_top_iff_ne_top.2 h) with ⟨r, rfl, hb⟩, rcases exists_nat_gt r with ⟨n, hn⟩, exact ⟨n, coe_lt_coe_nat.2 hn⟩, end lemma add_lt_add (ac : a < c) (bd : b < d) : a + b < c + d := begin rcases dense ac with ⟨a', aa', a'c⟩, rcases lt_iff_exists_coe.1 aa' with ⟨aR, rfl, _⟩, rcases lt_iff_exists_coe.1 a'c with ⟨a'R, rfl, _⟩, rcases dense bd with ⟨b', bb', b'd⟩, rcases lt_iff_exists_coe.1 bb' with ⟨bR, rfl, _⟩, rcases lt_iff_exists_coe.1 b'd with ⟨b'R, rfl, _⟩, have I : ↑aR + ↑bR < ↑a'R + ↑b'R := begin rw [← coe_add, ← coe_add, coe_lt_coe], apply add_lt_add (coe_lt_coe.1 aa') (coe_lt_coe.1 bb') end, have J : ↑a'R + ↑b'R ≤ c + d := add_le_add' (le_of_lt a'c) (le_of_lt b'd), apply lt_of_lt_of_le I J end @[norm_cast] lemma coe_min : ((min r p:nnreal):ennreal) = min r p := coe_mono.map_min @[norm_cast] lemma coe_max : ((max r p:nnreal):ennreal) = max r p := coe_mono.map_max end order section complete_lattice lemma coe_Sup {s : set nnreal} : bdd_above s → (↑(Sup s) : ennreal) = (⨆a∈s, ↑a) := with_top.coe_Sup lemma coe_Inf {s : set nnreal} : s.nonempty → (↑(Inf s) : ennreal) = (⨅a∈s, ↑a) := with_top.coe_Inf @[simp] lemma top_mem_upper_bounds {s : set ennreal} : ∞ ∈ upper_bounds s := assume x hx, le_top lemma coe_mem_upper_bounds {s : set nnreal} : ↑r ∈ upper_bounds ((coe : nnreal → ennreal) '' s) ↔ r ∈ upper_bounds s := by simp [upper_bounds, ball_image_iff, -mem_image, *] {contextual := tt} lemma infi_ennreal {α : Type*} [complete_lattice α] {f : ennreal → α} : (⨅n, f n) = (⨅n:nnreal, f n) ⊓ f ⊤ := le_antisymm (le_inf (le_infi $ assume i, infi_le _ _) (infi_le _ _)) (le_infi $ forall_ennreal.2 ⟨assume r, inf_le_left_of_le $ infi_le _ _, inf_le_right⟩) end complete_lattice section mul lemma mul_le_mul : a ≤ b → c ≤ d → a * c ≤ b * d := canonically_ordered_semiring.mul_le_mul lemma mul_left_mono : monotone ((*) a) := λ b c, mul_le_mul (le_refl a) lemma mul_right_mono : monotone (λ x, x * a) := λ b c h, mul_le_mul h (le_refl a) lemma max_mul : max a b * c = max (a * c) (b * c) := mul_right_mono.map_max lemma mul_max : a * max b c = max (a * b) (a * c) := mul_left_mono.map_max lemma mul_eq_mul_left : a ≠ 0 → a ≠ ⊤ → (a * b = a * c ↔ b = c) := begin cases a; cases b; cases c; simp [none_eq_top, some_eq_coe, mul_top, top_mul, -coe_mul, coe_mul.symm, nnreal.mul_eq_mul_left] {contextual := tt}, end lemma mul_eq_mul_right : c ≠ 0 → c ≠ ∞ → (a * c = b * c ↔ a = b) := mul_comm c a ▸ mul_comm c b ▸ mul_eq_mul_left lemma mul_le_mul_left : a ≠ 0 → a ≠ ⊤ → (a * b ≤ a * c ↔ b ≤ c) := begin cases a; cases b; cases c; simp [none_eq_top, some_eq_coe, mul_top, top_mul, -coe_mul, coe_mul.symm] {contextual := tt}, assume h, exact mul_le_mul_left (zero_lt_iff_ne_zero.2 h) end lemma mul_le_mul_right : c ≠ 0 → c ≠ ∞ → (a * c ≤ b * c ↔ a ≤ b) := mul_comm c a ▸ mul_comm c b ▸ mul_le_mul_left lemma mul_lt_mul_left : a ≠ 0 → a ≠ ⊤ → (a * b < a * c ↔ b < c) := λ h0 ht, by simp only [mul_le_mul_left h0 ht, lt_iff_le_not_le] lemma mul_lt_mul_right : c ≠ 0 → c ≠ ∞ → (a * c < b * c ↔ a < b) := mul_comm c a ▸ mul_comm c b ▸ mul_lt_mul_left lemma mul_eq_zero {a b : ennreal} : a * b = 0 ↔ a = 0 ∨ b = 0 := canonically_ordered_comm_semiring.mul_eq_zero_iff _ _ end mul section sub instance : has_sub ennreal := ⟨λa b, Inf {d | a ≤ d + b}⟩ @[norm_cast] lemma coe_sub : ↑(p - r) = (↑p:ennreal) - r := le_antisymm (le_Inf $ assume b (hb : ↑p ≤ b + r), coe_le_iff.2 $ by rintros d rfl; rwa [← coe_add, coe_le_coe, ← nnreal.sub_le_iff_le_add] at hb) (Inf_le $ show (↑p : ennreal) ≤ ↑(p - r) + ↑r, by rw [← coe_add, coe_le_coe, ← nnreal.sub_le_iff_le_add]) @[simp] lemma top_sub_coe : ∞ - ↑r = ∞ := top_unique $ le_Inf $ by simp [add_eq_top] @[simp] lemma sub_eq_zero_of_le (h : a ≤ b) : a - b = 0 := le_antisymm (Inf_le $ le_add_left h) (zero_le _) @[simp] lemma sub_self : a - a = 0 := sub_eq_zero_of_le $ le_refl _ @[simp] lemma zero_sub : 0 - a = 0 := le_antisymm (Inf_le $ zero_le _) (zero_le _) @[simp] lemma sub_infty : a - ∞ = 0 := le_antisymm (Inf_le $ by simp) (zero_le _) lemma sub_le_sub (h₁ : a ≤ b) (h₂ : d ≤ c) : a - c ≤ b - d := Inf_le_Inf $ assume e (h : b ≤ e + d), calc a ≤ b : h₁ ... ≤ e + d : h ... ≤ e + c : add_le_add' (le_refl _) h₂ @[simp] lemma add_sub_self : ∀{a b : ennreal}, b < ∞ → (a + b) - b = a | a none := by simp [none_eq_top] | none (some b) := by simp [none_eq_top, some_eq_coe] | (some a) (some b) := by simp [some_eq_coe]; rw [← coe_add, ← coe_sub, coe_eq_coe, nnreal.add_sub_cancel] @[simp] lemma add_sub_self' (h : a < ∞) : (a + b) - a = b := by rw [add_comm, add_sub_self h] lemma add_left_inj (h : a < ∞) : a + b = a + c ↔ b = c := ⟨λ e, by simpa [h] using congr_arg (λ x, x - a) e, congr_arg _⟩ lemma add_right_inj (h : a < ∞) : b + a = c + a ↔ b = c := by rw [add_comm, add_comm c, add_left_inj h] @[simp] lemma sub_add_cancel_of_le : ∀{a b : ennreal}, b ≤ a → (a - b) + b = a := begin simp [forall_ennreal, le_coe_iff, -add_comm] {contextual := tt}, rintros r p x rfl h, rw [← coe_sub, ← coe_add, nnreal.sub_add_cancel_of_le h] end @[simp] lemma add_sub_cancel_of_le (h : b ≤ a) : b + (a - b) = a := by rwa [add_comm, sub_add_cancel_of_le] lemma sub_add_self_eq_max : (a - b) + b = max a b := match le_total a b with | or.inl h := by simp [h, max_eq_right] | or.inr h := by simp [h, max_eq_left] end lemma le_sub_add_self : a ≤ (a - b) + b := by { rw sub_add_self_eq_max, exact le_max_left a b } @[simp] protected lemma sub_le_iff_le_add : a - b ≤ c ↔ a ≤ c + b := iff.intro (assume h : a - b ≤ c, calc a ≤ (a - b) + b : le_sub_add_self ... ≤ c + b : add_le_add_right' h) (assume h : a ≤ c + b, calc a - b ≤ (c + b) - b : sub_le_sub h (le_refl _) ... ≤ c : Inf_le (le_refl (c + b))) protected lemma sub_le_iff_le_add' : a - b ≤ c ↔ a ≤ b + c := add_comm c b ▸ ennreal.sub_le_iff_le_add lemma sub_eq_of_add_eq : b ≠ ∞ → a + b = c → c - b = a := λ hb hc, hc ▸ add_sub_self (lt_top_iff_ne_top.2 hb) protected lemma sub_le_of_sub_le (h : a - b ≤ c) : a - c ≤ b := ennreal.sub_le_iff_le_add.2 $ by { rw add_comm, exact ennreal.sub_le_iff_le_add.1 h } protected lemma sub_lt_sub_self : a ≠ ⊤ → a ≠ 0 → 0 < b → a - b < a := match a, b with | none, _ := by { have := none_eq_top, assume h, contradiction } | (some a), none := by {intros, simp only [none_eq_top, sub_infty, zero_lt_iff_ne_zero], assumption} | (some a), (some b) := begin simp only [some_eq_coe, coe_sub.symm, coe_pos, coe_eq_zero, coe_lt_coe, ne.def], assume h₁ h₂, apply nnreal.sub_lt_self, exact zero_lt_iff_ne_zero.2 h₂ end end @[simp] lemma sub_eq_zero_iff_le : a - b = 0 ↔ a ≤ b := by simpa [-ennreal.sub_le_iff_le_add] using @ennreal.sub_le_iff_le_add a b 0 @[simp] lemma zero_lt_sub_iff_lt : 0 < a - b ↔ b < a := by simpa [ennreal.bot_lt_iff_ne_bot, -sub_eq_zero_iff_le] using not_iff_not.2 (@sub_eq_zero_iff_le a b) lemma lt_sub_iff_add_lt : a < b - c ↔ a + c < b := begin cases a, { simp }, cases c, { simp }, cases b, { simp only [true_iff, coe_lt_top, some_eq_coe, top_sub_coe, none_eq_top, ← coe_add] }, simp only [some_eq_coe], rw [← coe_add, ← coe_sub, coe_lt_coe, coe_lt_coe, nnreal.lt_sub_iff_add_lt], end lemma sub_le_self (a b : ennreal) : a - b ≤ a := ennreal.sub_le_iff_le_add.2 $ le_add_of_nonneg_right' $ zero_le _ @[simp] lemma sub_zero : a - 0 = a := eq.trans (add_zero (a - 0)).symm $ by simp /-- A version of triangle inequality for difference as a "distance". -/ lemma sub_le_sub_add_sub : a - c ≤ a - b + (b - c) := ennreal.sub_le_iff_le_add.2 $ calc a ≤ a - b + b : le_sub_add_self ... ≤ a - b + ((b - c) + c) : add_le_add_left' le_sub_add_self ... = a - b + (b - c) + c : (add_assoc _ _ _).symm lemma sub_sub_cancel (h : a < ∞) (h2 : b ≤ a) : a - (a - b) = b := by rw [← add_right_inj (lt_of_le_of_lt (sub_le_self _ _) h), sub_add_cancel_of_le (sub_le_self _ _), add_sub_cancel_of_le h2] lemma sub_left_inj {a b c : ennreal} (ha : a < ⊤) (hb : b ≤ a) (hc : c ≤ a) : a - b = a - c ↔ b = c := iff.intro begin assume h, have : a - (a - b) = a - (a - c), rw h, rw [sub_sub_cancel ha hb, sub_sub_cancel ha hc] at this, exact this end (λ h, by rw h) lemma sub_mul (h : 0 < b → b < a → c ≠ ∞) : (a - b) * c = a * c - b * c := begin cases le_or_lt a b with hab hab, { simp [hab, mul_right_mono hab] }, symmetry, cases eq_or_lt_of_le (zero_le b) with hb hb, { subst b, simp }, apply sub_eq_of_add_eq, { exact mul_ne_top (ne_top_of_lt hab) (h hb hab) }, rw [← add_mul, sub_add_cancel_of_le (le_of_lt hab)] end lemma mul_sub (h : 0 < c → c < b → a ≠ ∞) : a * (b - c) = a * b - a * c := by { simp only [mul_comm a], exact sub_mul h } lemma sub_mul_ge : a * c - b * c ≤ (a - b) * c := begin -- with `0 < b → b < a → c ≠ ∞` Lean names the first variable `a` by_cases h : ∀ (hb : 0 < b), b < a → c ≠ ∞, { rw [sub_mul h], exact le_refl _ }, { push_neg at h, rcases h with ⟨hb, hba, hc⟩, subst c, simp only [mul_top, if_neg (ne_of_gt hb), if_neg (ne_of_gt $ lt_trans hb hba), sub_self, zero_le] } end end sub section sum open finset /-- sum of finte numbers is still finite -/ lemma sum_lt_top {s : finset α} {f : α → ennreal} : (∀a∈s, f a < ⊤) → s.sum f < ⊤ := with_top.sum_lt_top /-- sum of finte numbers is still finite -/ lemma sum_lt_top_iff {s : finset α} {f : α → ennreal} : s.sum f < ⊤ ↔ (∀a∈s, f a < ⊤) := with_top.sum_lt_top_iff /-- seeing `ennreal` as `nnreal` does not change their sum, unless one of the `ennreal` is infinity -/ lemma to_nnreal_sum {s : finset α} {f : α → ennreal} (hf : ∀a∈s, f a < ⊤) : ennreal.to_nnreal (s.sum f) = s.sum (λa, ennreal.to_nnreal (f a)) := begin rw [← coe_eq_coe, coe_to_nnreal, coe_finset_sum, sum_congr], { refl }, { intros x hx, rw coe_to_nnreal, rw ← ennreal.lt_top_iff_ne_top, exact hf x hx }, { rw ← ennreal.lt_top_iff_ne_top, exact sum_lt_top hf } end /-- seeing `ennreal` as `real` does not change their sum, unless one of the `ennreal` is infinity -/ lemma to_real_sum {s : finset α} {f : α → ennreal} (hf : ∀a∈s, f a < ⊤) : ennreal.to_real (s.sum f) = s.sum (λa, ennreal.to_real (f a)) := by { rw [ennreal.to_real, to_nnreal_sum hf, nnreal.coe_sum], refl } end sum section interval variables {x y z : ennreal} {ε ε₁ ε₂ : ennreal} {s : set ennreal} protected lemma Ico_eq_Iio : (Ico 0 y) = (Iio y) := ext $ assume a, iff.intro (assume ⟨_, hx⟩, hx) (assume hx, ⟨zero_le _, hx⟩) lemma mem_Iio_self_add : x ≠ ⊤ → 0 < ε → x ∈ Iio (x + ε) := assume xt ε0, lt_add_right (by rwa lt_top_iff_ne_top) ε0 lemma not_mem_Ioo_self_sub : x = 0 → x ∉ Ioo (x - ε) y := assume x0, by simp [x0] lemma mem_Ioo_self_sub_add : x ≠ ⊤ → x ≠ 0 → 0 < ε₁ → 0 < ε₂ → x ∈ Ioo (x - ε₁) (x + ε₂) := assume xt x0 ε0 ε0', ⟨ennreal.sub_lt_sub_self xt x0 ε0, lt_add_right (by rwa [lt_top_iff_ne_top]) ε0'⟩ end interval section bit @[simp] lemma bit0_inj : bit0 a = bit0 b ↔ a = b := ⟨λh, begin rcases (lt_trichotomy a b) with h₁| h₂| h₃, { exact (absurd h (ne_of_lt (add_lt_add h₁ h₁))) }, { exact h₂ }, { exact (absurd h.symm (ne_of_lt (add_lt_add h₃ h₃))) } end, λh, congr_arg _ h⟩ @[simp] lemma bit0_eq_zero_iff : bit0 a = 0 ↔ a = 0 := by simpa only [bit0_zero] using @bit0_inj a 0 @[simp] lemma bit0_eq_top_iff : bit0 a = ∞ ↔ a = ∞ := by rw [bit0, add_eq_top, or_self] @[simp] lemma bit1_inj : bit1 a = bit1 b ↔ a = b := ⟨λh, begin unfold bit1 at h, rwa [add_right_inj, bit0_inj] at h, simp [lt_top_iff_ne_top] end, λh, congr_arg _ h⟩ @[simp] lemma bit1_ne_zero : bit1 a ≠ 0 := by unfold bit1; simp @[simp] lemma bit1_eq_one_iff : bit1 a = 1 ↔ a = 0 := by simpa only [bit1_zero] using @bit1_inj a 0 @[simp] lemma bit1_eq_top_iff : bit1 a = ∞ ↔ a = ∞ := by unfold bit1; rw add_eq_top; simp end bit section inv instance : has_inv ennreal := ⟨λa, Inf {b | 1 ≤ a * b}⟩ instance : has_div ennreal := ⟨λa b, a * b⁻¹⟩ lemma div_def : a / b = a * b⁻¹ := rfl lemma mul_div_assoc : (a * b) / c = a * (b / c) := mul_assoc _ _ _ @[simp] lemma inv_zero : (0 : ennreal)⁻¹ = ∞ := show Inf {b : ennreal | 1 ≤ 0 * b} = ∞, by simp; refl @[simp] lemma inv_top : (∞ : ennreal)⁻¹ = 0 := bot_unique $ le_of_forall_le_of_dense $ λ a (h : a > 0), Inf_le $ by simp [*, ne_of_gt h, top_mul] @[simp, norm_cast] lemma coe_inv (hr : r ≠ 0) : (↑r⁻¹ : ennreal) = (↑r)⁻¹ := le_antisymm (le_Inf $ assume b (hb : 1 ≤ ↑r * b), coe_le_iff.2 $ by rintros b rfl; rwa [← coe_mul, ← coe_one, coe_le_coe, ← nnreal.inv_le hr] at hb) (Inf_le $ by simp; rw [← coe_mul, nnreal.mul_inv_cancel hr]; exact le_refl 1) lemma coe_inv_le : (↑r⁻¹ : ennreal) ≤ (↑r)⁻¹ := if hr : r = 0 then by simp only [hr, nnreal.inv_zero, inv_zero, coe_zero, zero_le] else by simp only [coe_inv hr, le_refl] @[norm_cast] lemma coe_inv_two : ((2⁻¹:nnreal):ennreal) = 2⁻¹ := by rw [coe_inv (ne_of_gt zero_lt_two), coe_two] @[simp, norm_cast] lemma coe_div (hr : r ≠ 0) : (↑(p / r) : ennreal) = p / r := show ↑(p * r⁻¹) = ↑p * (↑r)⁻¹, by rw [coe_mul, coe_inv hr] @[simp] lemma inv_one : (1:ennreal)⁻¹ = 1 := by simpa only [coe_inv one_ne_zero, coe_one] using coe_eq_coe.2 nnreal.inv_one @[simp] lemma div_one {a : ennreal} : a / 1 = a := by simp [ennreal.div_def] protected lemma inv_pow {n : ℕ} : (a^n)⁻¹ = (a⁻¹)^n := begin by_cases a = 0; cases a; cases n; simp [*, none_eq_top, some_eq_coe, zero_pow, top_pow, nat.zero_lt_succ] at *, rw [← coe_inv h, ← coe_pow, ← coe_inv, nnreal.inv_pow, coe_pow], rw [← ne.def] at h, rw [← zero_lt_iff_ne_zero] at *, apply pow_pos h end @[simp] lemma inv_inv : (a⁻¹)⁻¹ = a := by by_cases a = 0; cases a; simp [*, none_eq_top, some_eq_coe, -coe_inv, (coe_inv _).symm] at * lemma inv_involutive : function.involutive (λ a:ennreal, a⁻¹) := λ a, ennreal.inv_inv lemma inv_bijective : function.bijective (λ a:ennreal, a⁻¹) := ennreal.inv_involutive.bijective @[simp] lemma inv_eq_inv : a⁻¹ = b⁻¹ ↔ a = b := inv_bijective.1.eq_iff @[simp] lemma inv_eq_top : a⁻¹ = ∞ ↔ a = 0 := inv_zero ▸ inv_eq_inv lemma inv_ne_top : a⁻¹ ≠ ∞ ↔ a ≠ 0 := by simp @[simp] lemma inv_eq_zero : a⁻¹ = 0 ↔ a = ∞ := inv_top ▸ inv_eq_inv lemma inv_ne_zero : a⁻¹ ≠ 0 ↔ a ≠ ∞ := by simp @[simp] lemma inv_pos : 0 < a⁻¹ ↔ a ≠ ∞ := zero_lt_iff_ne_zero.trans inv_ne_zero @[simp] lemma inv_lt_inv : a⁻¹ < b⁻¹ ↔ b < a := begin cases a; cases b; simp only [some_eq_coe, none_eq_top, inv_top], { simp only [lt_irrefl] }, { exact inv_pos.trans lt_top_iff_ne_top.symm }, { simp only [not_lt_zero, not_top_lt] }, { cases eq_or_lt_of_le (zero_le a) with ha ha; cases eq_or_lt_of_le (zero_le b) with hb hb, { subst a, subst b, simp }, { subst a, simp }, { subst b, simp [zero_lt_iff_ne_zero, lt_top_iff_ne_top, inv_ne_top] }, { rw [← coe_inv (ne_of_gt ha), ← coe_inv (ne_of_gt hb), coe_lt_coe, coe_lt_coe], simp only [nnreal.coe_lt_coe.symm] at *, exact inv_lt_inv ha hb } } end lemma inv_lt_iff_inv_lt : a⁻¹ < b ↔ b⁻¹ < a := by simpa only [inv_inv] using @inv_lt_inv a b⁻¹ lemma lt_inv_iff_lt_inv : a < b⁻¹ ↔ b < a⁻¹ := by simpa only [inv_inv] using @inv_lt_inv a⁻¹ b @[simp, priority 1100] -- higher than le_inv_iff_mul_le lemma inv_le_inv : a⁻¹ ≤ b⁻¹ ↔ b ≤ a := by simp only [le_iff_lt_or_eq, inv_lt_inv, inv_eq_inv, eq_comm] lemma inv_le_iff_inv_le : a⁻¹ ≤ b ↔ b⁻¹ ≤ a := by simpa only [inv_inv] using @inv_le_inv a b⁻¹ lemma le_inv_iff_le_inv : a ≤ b⁻¹ ↔ b ≤ a⁻¹ := by simpa only [inv_inv] using @inv_le_inv a⁻¹ b @[simp] lemma inv_lt_one : a⁻¹ < 1 ↔ 1 < a := inv_lt_iff_inv_lt.trans $ by rw [inv_one] lemma top_div : ∞ / a = if a = ∞ then 0 else ∞ := by by_cases a = ∞; simp [div_def, top_mul, *] @[simp] lemma div_top : a / ∞ = 0 := by simp only [div_def, inv_top, mul_zero] @[simp] lemma zero_div : 0 / a = 0 := zero_mul a⁻¹ lemma div_eq_top : a / b = ⊤ ↔ (a ≠ 0 ∧ b = 0) ∨ (a = ⊤ ∧ b ≠ ⊤) := by simp [ennreal.div_def, ennreal.mul_eq_top] lemma le_div_iff_mul_le (h0 : b ≠ 0 ∨ c ≠ 0) (ht : b ≠ ⊤ ∨ c ≠ ⊤) : a ≤ c / b ↔ a * b ≤ c := begin cases b, { simp at ht, split, { assume ha, simp at ha, simp [ha] }, { contrapose, assume ha, simp at ha, have : a * ⊤ = ⊤, by simp [ennreal.mul_eq_top, ha], simp [this, ht] } }, by_cases hb : b ≠ 0, { have : (b : ennreal) ≠ 0, by simp [hb], rw [← ennreal.mul_le_mul_left this coe_ne_top], suffices : ↑b * a ≤ (↑b * ↑b⁻¹) * c ↔ a * ↑b ≤ c, { simpa [some_eq_coe, div_def, hb, mul_left_comm, mul_comm, mul_assoc] }, rw [← coe_mul, nnreal.mul_inv_cancel hb, coe_one, one_mul, mul_comm] }, { simp at hb, simp [hb] at h0, have : c / 0 = ⊤, by simp [div_eq_top, h0], simp [hb, this] } end lemma div_le_iff_le_mul (hb0 : b ≠ 0 ∨ c ≠ ⊤) (hbt : b ≠ ⊤ ∨ c ≠ 0) : a / b ≤ c ↔ a ≤ c * b := begin suffices : a * b⁻¹ ≤ c ↔ a ≤ c / b⁻¹, by simpa [div_def], apply (le_div_iff_mul_le _ _).symm, simpa [inv_ne_zero] using hbt, simpa [inv_ne_zero] using hb0 end lemma div_le_of_le_mul (h : a ≤ b * c) : a / c ≤ b := begin by_cases h0 : c = 0, { have : a = 0, by simpa [h0] using h, simp [*] }, by_cases hinf : c = ⊤, by simp [hinf], exact (div_le_iff_le_mul (or.inl h0) (or.inl hinf)).2 h end lemma mul_lt_of_lt_div (h : a < b / c) : a * c < b := by { contrapose! h, exact ennreal.div_le_of_le_mul h } lemma inv_le_iff_le_mul : (b = ⊤ → a ≠ 0) → (a = ⊤ → b ≠ 0) → (a⁻¹ ≤ b ↔ 1 ≤ a * b) := begin cases a; cases b; simp [none_eq_top, some_eq_coe, mul_top, top_mul] {contextual := tt}, by_cases a = 0; simp [*, -coe_mul, coe_mul.symm, -coe_inv, (coe_inv _).symm, nnreal.inv_le] end @[simp] lemma le_inv_iff_mul_le : a ≤ b⁻¹ ↔ a * b ≤ 1 := begin cases b, { by_cases a = 0; simp [*, none_eq_top, mul_top] }, by_cases b = 0; simp [*, some_eq_coe, le_div_iff_mul_le], suffices : a ≤ 1 / b ↔ a * b ≤ 1, { simpa [div_def, h] }, exact le_div_iff_mul_le (or.inl (mt coe_eq_coe.1 h)) (or.inl coe_ne_top) end lemma mul_inv_cancel (h0 : a ≠ 0) (ht : a ≠ ⊤) : a * a⁻¹ = 1 := begin lift a to nnreal using ht, norm_cast at h0, norm_cast, exact nnreal.mul_inv_cancel h0 end lemma inv_mul_cancel (h0 : a ≠ 0) (ht : a ≠ ∞) : a⁻¹ * a = 1 := mul_comm a a⁻¹ ▸ mul_inv_cancel h0 ht lemma mul_le_iff_le_inv {a b r : ennreal} (hr₀ : r ≠ 0) (hr₁ : r ≠ ⊤) : (r * a ≤ b ↔ a ≤ r⁻¹ * b) := by rw [← @ennreal.mul_le_mul_left _ a _ hr₀ hr₁, ← mul_assoc, mul_inv_cancel hr₀ hr₁, one_mul] lemma le_of_forall_lt_one_mul_lt : ∀{x y : ennreal}, (∀a<1, a * x ≤ y) → x ≤ y := forall_ennreal.2 $ and.intro (assume r, forall_ennreal.2 $ and.intro (assume q h, coe_le_coe.2 $ nnreal.le_of_forall_lt_one_mul_lt $ assume a ha, begin rw [← coe_le_coe, coe_mul], exact h _ (coe_lt_coe.2 ha) end) (assume h, le_top)) (assume r hr, have ((1 / 2 : nnreal) : ennreal) * ⊤ ≤ r := hr _ (coe_lt_coe.2 ((@nnreal.coe_lt_coe (1/2) 1).1 one_half_lt_one)), have ne : ((1 / 2 : nnreal) : ennreal) ≠ 0, begin rw [(≠), coe_eq_zero], refine zero_lt_iff_ne_zero.1 _, show 0 < (1 / 2 : ℝ), exact div_pos zero_lt_one _root_.two_pos end, by rwa [mul_top, if_neg ne] at this) lemma div_add_div_same {a b c : ennreal} : a / c + b / c = (a + b) / c := eq.symm $ right_distrib a b (c⁻¹) lemma div_self (h0 : a ≠ 0) (hI : a ≠ ∞) : a / a = 1 := mul_inv_cancel h0 hI lemma mul_div_cancel (h0 : a ≠ 0) (hI : a ≠ ∞) : (b / a) * a = b := by rw [div_def, mul_assoc, inv_mul_cancel h0 hI, mul_one] lemma mul_div_cancel' (h0 : a ≠ 0) (hI : a ≠ ∞) : a * (b / a) = b := by rw [mul_comm, mul_div_cancel h0 hI] lemma inv_two_add_inv_two : (2:ennreal)⁻¹ + 2⁻¹ = 1 := by rw [← two_mul, ← div_def, div_self two_ne_zero two_ne_top] lemma add_halves (a : ennreal) : a / 2 + a / 2 = a := by rw [div_def, ← mul_add, inv_two_add_inv_two, mul_one] @[simp] lemma div_zero_iff {a b : ennreal} : a / b = 0 ↔ a = 0 ∨ b = ⊤ := by simp [div_def, mul_eq_zero] @[simp] lemma div_pos_iff {a b : ennreal} : 0 < a / b ↔ a ≠ 0 ∧ b ≠ ⊤ := by simp [zero_lt_iff_ne_zero, not_or_distrib] lemma half_pos {a : ennreal} (h : 0 < a) : 0 < a / 2 := by simp [ne_of_gt h] lemma one_half_lt_one : (2⁻¹:ennreal) < 1 := inv_lt_one.2 $ one_lt_two lemma half_lt_self {a : ennreal} (hz : a ≠ 0) (ht : a ≠ ⊤) : a / 2 < a := begin lift a to nnreal using ht, have h : (2 : ennreal) = ((2 : nnreal) : ennreal), from rfl, have h' : (2 : nnreal) ≠ 0, from _root_.two_ne_zero', rw [h, ← coe_div h', coe_lt_coe], -- `norm_cast` fails to apply `coe_div` norm_cast at hz, exact nnreal.half_lt_self hz end lemma sub_half (h : a ≠ ∞) : a - a / 2 = a / 2 := begin lift a to nnreal using h, exact sub_eq_of_add_eq (mul_ne_top coe_ne_top $ by simp) (add_halves a) end lemma one_sub_inv_two : (1:ennreal) - 2⁻¹ = 2⁻¹ := by simpa only [div_def, one_mul] using sub_half one_ne_top lemma exists_inv_nat_lt {a : ennreal} (h : a ≠ 0) : ∃n:ℕ, (n:ennreal)⁻¹ < a := @inv_inv a ▸ by simp only [inv_lt_inv, ennreal.exists_nat_gt (inv_ne_top.2 h)] end inv section real lemma to_real_add (ha : a ≠ ⊤) (hb : b ≠ ⊤) : (a+b).to_real = a.to_real + b.to_real := begin lift a to nnreal using ha, lift b to nnreal using hb, refl end lemma to_real_add_le : (a+b).to_real ≤ a.to_real + b.to_real := if ha : a = ⊤ then by simp only [ha, top_add, top_to_real, zero_add, to_real_nonneg] else if hb : b = ⊤ then by simp only [hb, add_top, top_to_real, add_zero, to_real_nonneg] else le_of_eq (to_real_add ha hb) lemma of_real_add {p q : ℝ} (hp : 0 ≤ p) (hq : 0 ≤ q) : ennreal.of_real (p + q) = ennreal.of_real p + ennreal.of_real q := by rw [ennreal.of_real, ennreal.of_real, ennreal.of_real, ← coe_add, coe_eq_coe, nnreal.of_real_add hp hq] @[simp] lemma to_real_le_to_real (ha : a ≠ ⊤) (hb : b ≠ ⊤) : a.to_real ≤ b.to_real ↔ a ≤ b := begin lift a to nnreal using ha, lift b to nnreal using hb, norm_cast end @[simp] lemma to_real_lt_to_real (ha : a ≠ ⊤) (hb : b ≠ ⊤) : a.to_real < b.to_real ↔ a < b := begin lift a to nnreal using ha, lift b to nnreal using hb, norm_cast end lemma to_real_max (hr : a ≠ ⊤) (hp : b ≠ ⊤) : ennreal.to_real (max a b) = max (ennreal.to_real a) (ennreal.to_real b) := (le_total a b).elim (λ h, by simp only [h, (ennreal.to_real_le_to_real hr hp).2 h, max_eq_right]) (λ h, by simp only [h, (ennreal.to_real_le_to_real hp hr).2 h, max_eq_left]) lemma to_nnreal_pos_iff : 0 < a.to_nnreal ↔ (0 < a ∧ a ≠ ∞) := begin cases a, { simp [none_eq_top] }, { simp [some_eq_coe] } end lemma to_real_pos_iff : 0 < a.to_real ↔ (0 < a ∧ a ≠ ∞):= (nnreal.coe_pos).trans to_nnreal_pos_iff lemma of_real_le_of_real {p q : ℝ} (h : p ≤ q) : ennreal.of_real p ≤ ennreal.of_real q := by simp [ennreal.of_real, nnreal.of_real_le_of_real h] @[simp] lemma of_real_le_of_real_iff {p q : ℝ} (h : 0 ≤ q) : ennreal.of_real p ≤ ennreal.of_real q ↔ p ≤ q := by rw [ennreal.of_real, ennreal.of_real, coe_le_coe, nnreal.of_real_le_of_real_iff h] @[simp] lemma of_real_lt_of_real_iff {p q : ℝ} (h : 0 < q) : ennreal.of_real p < ennreal.of_real q ↔ p < q := by rw [ennreal.of_real, ennreal.of_real, coe_lt_coe, nnreal.of_real_lt_of_real_iff h] lemma of_real_lt_of_real_iff_of_nonneg {p q : ℝ} (hp : 0 ≤ p) : ennreal.of_real p < ennreal.of_real q ↔ p < q := by rw [ennreal.of_real, ennreal.of_real, coe_lt_coe, nnreal.of_real_lt_of_real_iff_of_nonneg hp] @[simp] lemma of_real_pos {p : ℝ} : 0 < ennreal.of_real p ↔ 0 < p := by simp [ennreal.of_real] @[simp] lemma of_real_eq_zero {p : ℝ} : ennreal.of_real p = 0 ↔ p ≤ 0 := by simp [ennreal.of_real] lemma of_real_le_iff_le_to_real {a : ℝ} {b : ennreal} (hb : b ≠ ⊤) : ennreal.of_real a ≤ b ↔ a ≤ ennreal.to_real b := begin lift b to nnreal using hb, simpa [ennreal.of_real, ennreal.to_real] using nnreal.of_real_le_iff_le_coe end lemma of_real_lt_iff_lt_to_real {a : ℝ} {b : ennreal} (ha : 0 ≤ a) (hb : b ≠ ⊤) : ennreal.of_real a < b ↔ a < ennreal.to_real b := begin lift b to nnreal using hb, simpa [ennreal.of_real, ennreal.to_real] using nnreal.of_real_lt_iff_lt_coe ha end lemma le_of_real_iff_to_real_le {a : ennreal} {b : ℝ} (ha : a ≠ ⊤) (hb : 0 ≤ b) : a ≤ ennreal.of_real b ↔ ennreal.to_real a ≤ b := begin lift a to nnreal using ha, simpa [ennreal.of_real, ennreal.to_real] using nnreal.le_of_real_iff_coe_le hb end lemma to_real_le_of_le_of_real {a : ennreal} {b : ℝ} (hb : 0 ≤ b) (h : a ≤ ennreal.of_real b) : ennreal.to_real a ≤ b := have ha : a ≠ ⊤, from ne_top_of_le_ne_top of_real_ne_top h, (le_of_real_iff_to_real_le ha hb).1 h lemma lt_of_real_iff_to_real_lt {a : ennreal} {b : ℝ} (ha : a ≠ ⊤) : a < ennreal.of_real b ↔ ennreal.to_real a < b := begin lift a to nnreal using ha, simpa [ennreal.of_real, ennreal.to_real] using nnreal.lt_of_real_iff_coe_lt end lemma of_real_mul {p q : ℝ} (hp : 0 ≤ p) : ennreal.of_real (p * q) = (ennreal.of_real p) * (ennreal.of_real q) := by { simp only [ennreal.of_real, coe_mul.symm, coe_eq_coe], exact nnreal.of_real_mul hp } lemma to_real_of_real_mul (c : ℝ) (a : ennreal) (h : 0 ≤ c) : ennreal.to_real ((ennreal.of_real c) * a) = c * ennreal.to_real a := begin cases a, { simp only [none_eq_top, ennreal.to_real, top_to_nnreal, nnreal.coe_zero, mul_zero, mul_top], by_cases h' : c ≤ 0, { rw [if_pos], { simp }, { convert of_real_zero, exact le_antisymm h' h } }, { rw [if_neg], refl, rw [of_real_eq_zero], assumption } }, { simp only [ennreal.to_real, ennreal.to_nnreal], simp only [some_eq_coe, ennreal.of_real, coe_mul.symm, to_nnreal_coe, nnreal.coe_mul], congr, apply nnreal.coe_of_real, exact h } end @[simp] lemma to_real_mul_top (a : ennreal) : ennreal.to_real (a * ⊤) = 0 := begin by_cases h : a = 0, { rw [h, zero_mul, zero_to_real] }, { rw [mul_top, if_neg h, top_to_real] } end @[simp] lemma to_real_top_mul (a : ennreal) : ennreal.to_real (⊤ * a) = 0 := by { rw mul_comm, exact to_real_mul_top _ } lemma to_real_eq_to_real {a b : ennreal} (ha : a < ⊤) (hb : b < ⊤) : ennreal.to_real a = ennreal.to_real b ↔ a = b := begin rw ennreal.lt_top_iff_ne_top at *, split, { assume h, apply le_antisymm, rw ← to_real_le_to_real ha hb, exact le_of_eq h, rw ← to_real_le_to_real hb ha, exact le_of_eq h.symm }, { assume h, rw h } end lemma to_real_mul_to_real {a b : ennreal} : (ennreal.to_real a) * (ennreal.to_real b) = ennreal.to_real (a * b) := begin by_cases ha : a = ⊤, { rw ha, simp }, by_cases hb : b = ⊤, { rw hb, simp }, have ha : ennreal.of_real (ennreal.to_real a) = a := of_real_to_real ha, have hb : ennreal.of_real (ennreal.to_real b) = b := of_real_to_real hb, conv_rhs { rw [← ha, ← hb, ← of_real_mul to_real_nonneg] }, rw [to_real_of_real (mul_nonneg to_real_nonneg to_real_nonneg)] end end real section infi variables {ι : Sort*} {f g : ι → ennreal} lemma infi_add : infi f + a = ⨅i, f i + a := le_antisymm (le_infi $ assume i, add_le_add' (infi_le _ _) $ le_refl _) (ennreal.sub_le_iff_le_add.1 $ le_infi $ assume i, ennreal.sub_le_iff_le_add.2 $ infi_le _ _) lemma supr_sub : (⨆i, f i) - a = (⨆i, f i - a) := le_antisymm (ennreal.sub_le_iff_le_add.2 $ supr_le $ assume i, ennreal.sub_le_iff_le_add.1 $ le_supr _ i) (supr_le $ assume i, ennreal.sub_le_sub (le_supr _ _) (le_refl a)) lemma sub_infi : a - (⨅i, f i) = (⨆i, a - f i) := begin refine (eq_of_forall_ge_iff $ λ c, _), rw [ennreal.sub_le_iff_le_add, add_comm, infi_add], simp [ennreal.sub_le_iff_le_add, sub_eq_add_neg, add_comm], end lemma Inf_add {s : set ennreal} : Inf s + a = ⨅b∈s, b + a := by simp [Inf_eq_infi, infi_add] lemma add_infi {a : ennreal} : a + infi f = ⨅b, a + f b := by rw [add_comm, infi_add]; simp [add_comm] lemma infi_add_infi (h : ∀i j, ∃k, f k + g k ≤ f i + g j) : infi f + infi g = (⨅a, f a + g a) := suffices (⨅a, f a + g a) ≤ infi f + infi g, from le_antisymm (le_infi $ assume a, add_le_add' (infi_le _ _) (infi_le _ _)) this, calc (⨅a, f a + g a) ≤ (⨅ a a', f a + g a') : le_infi $ assume a, le_infi $ assume a', let ⟨k, h⟩ := h a a' in infi_le_of_le k h ... ≤ infi f + infi g : by simp [add_infi, infi_add, -add_comm, -le_infi_iff]; exact le_refl _ lemma infi_sum {f : ι → α → ennreal} {s : finset α} [nonempty ι] (h : ∀(t : finset α) (i j : ι), ∃k, ∀a∈t, f k a ≤ f i a ∧ f k a ≤ f j a) : (⨅i, s.sum (f i)) = s.sum (λa, ⨅i, f i a) := finset.induction_on s (by simp) $ assume a s ha ih, have ∀ (i j : ι), ∃ (k : ι), f k a + s.sum (f k) ≤ f i a + s.sum (f j), from assume i j, let ⟨k, hk⟩ := h (insert a s) i j in ⟨k, add_le_add' (hk a (finset.mem_insert_self _ _)).left $ finset.sum_le_sum $ assume a ha, (hk _ $ finset.mem_insert_of_mem ha).right⟩, by simp [ha, ih.symm, infi_add_infi this] end infi section supr lemma supr_coe_nat : (⨆n:ℕ, (n : ennreal)) = ⊤ := (supr_eq_top _).2 $ assume b hb, ennreal.exists_nat_gt (lt_top_iff_ne_top.1 hb) end supr end ennreal
9b0b729c8fba46b5f3e2f83d49dd89cbdd03b63d
957a80ea22c5abb4f4670b250d55534d9db99108
/tests/lean/run/662.lean
8e316f4781408c33480568112c216c07783e792a
[ "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,160
lean
open nat inductive type : Type | Nat : type | Func : type → type → type open type section var variable {var : type → Type} inductive term : type → Type | Var : ∀ {t}, var t → term t | Const : nat → term Nat | Plus : term Nat → term Nat → term Nat | Abs : ∀ {dom ran}, (var dom → term ran) → term (Func dom ran) | App : ∀ {dom ran}, term (Func dom ran) → term dom → term ran | Let : ∀ {t1 t2}, term t1 → (var t1 → term t2) → term t2 end var open term definition Term t := Π (var : type → Type), @term var t open unit definition count_vars : Π {t : type}, @term (λ x, unit) t -> nat | A (Var x) := 1 | Nat (Const x) := 0 | Nat (Plus e1 e2) := count_vars e1 + count_vars e2 | (Func A B) (Abs e1) := count_vars (e1 star) | B (@App ._ A .(B) e1 e2) := count_vars e1 + count_vars e2 | B (@Let ._ A .(B) e1 e2) := count_vars e1 + count_vars (e2 star) definition var (t : type) : @term (λ x, unit) t := Var star example : count_vars (App (App (var (Func Nat (Func Nat Nat))) (var Nat)) (var Nat)) = 3 := rfl
a684fce88bf7bafbc60f9fb57d3d5862f9a9afee
7cef822f3b952965621309e88eadf618da0c8ae9
/src/category_theory/adjunction/basic.lean
d3192aac4d04bd4c74ddc918c7b4f0a753e08877
[ "Apache-2.0" ]
permissive
rmitta/mathlib
8d90aee30b4db2b013e01f62c33f297d7e64a43d
883d974b608845bad30ae19e27e33c285200bf84
refs/heads/master
1,585,776,832,544
1,576,874,096,000
1,576,874,096,000
153,663,165
0
2
Apache-2.0
1,544,806,490,000
1,539,884,365,000
Lean
UTF-8
Lean
false
false
10,556
lean
/- Copyright (c) 2019 Reid Barton. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Reid Barton, Johan Commelin -/ import category_theory.equivalence import data.equiv.basic namespace category_theory open category universes v₁ v₂ v₃ u₁ u₂ u₃ -- declare the `v`'s first; see `category_theory.category` for an explanation local attribute [elab_simple] whisker_left whisker_right variables {C : Type u₁} [𝒞 : category.{v₁} C] {D : Type u₂} [𝒟 : category.{v₂} D] include 𝒞 𝒟 /-- `F ⊣ G` represents the data of an adjunction between two functors `F : C ⥤ D` and `G : D ⥤ C`. `F` is the left adjoint and `G` is the right adjoint. -/ structure adjunction (F : C ⥤ D) (G : D ⥤ C) := (hom_equiv : Π (X Y), (F.obj X ⟶ Y) ≃ (X ⟶ G.obj Y)) (unit : 𝟭 C ⟶ F.comp G) (counit : G.comp F ⟶ 𝟭 D) (hom_equiv_unit' : Π {X Y f}, (hom_equiv X Y) f = (unit : _ ⟶ _).app X ≫ G.map f . obviously) (hom_equiv_counit' : Π {X Y g}, (hom_equiv X Y).symm g = F.map g ≫ counit.app Y . obviously) infix ` ⊣ `:15 := adjunction class is_left_adjoint (left : C ⥤ D) := (right : D ⥤ C) (adj : left ⊣ right) class is_right_adjoint (right : D ⥤ C) := (left : C ⥤ D) (adj : left ⊣ right) def left_adjoint (R : D ⥤ C) [is_right_adjoint R] : C ⥤ D := is_right_adjoint.left R def right_adjoint (L : C ⥤ D) [is_left_adjoint L] : D ⥤ C := is_left_adjoint.right L namespace adjunction restate_axiom hom_equiv_unit' restate_axiom hom_equiv_counit' attribute [simp, priority 10] hom_equiv_unit hom_equiv_counit section variables {F : C ⥤ D} {G : D ⥤ C} (adj : F ⊣ G) {X' X : C} {Y Y' : D} @[simp, priority 10] lemma hom_equiv_naturality_left_symm (f : X' ⟶ X) (g : X ⟶ G.obj Y) : (adj.hom_equiv X' Y).symm (f ≫ g) = F.map f ≫ (adj.hom_equiv X Y).symm g := by rw [hom_equiv_counit, F.map_comp, assoc, adj.hom_equiv_counit.symm] @[simp] lemma hom_equiv_naturality_left (f : X' ⟶ X) (g : F.obj X ⟶ Y) : (adj.hom_equiv X' Y) (F.map f ≫ g) = f ≫ (adj.hom_equiv X Y) g := by rw [← equiv.eq_symm_apply]; simp [-hom_equiv_unit] @[simp, priority 10] lemma hom_equiv_naturality_right (f : F.obj X ⟶ Y) (g : Y ⟶ Y') : (adj.hom_equiv X Y') (f ≫ g) = (adj.hom_equiv X Y) f ≫ G.map g := by rw [hom_equiv_unit, G.map_comp, ← assoc, ←hom_equiv_unit] @[simp] lemma hom_equiv_naturality_right_symm (f : X ⟶ G.obj Y) (g : Y ⟶ Y') : (adj.hom_equiv X Y').symm (f ≫ G.map g) = (adj.hom_equiv X Y).symm f ≫ g := by rw [equiv.symm_apply_eq]; simp [-hom_equiv_counit] @[simp] lemma left_triangle : (whisker_right adj.unit F) ≫ (whisker_left F adj.counit) = nat_trans.id _ := begin ext1 X, dsimp, erw [← adj.hom_equiv_counit, equiv.symm_apply_eq, adj.hom_equiv_unit], simp end @[simp] lemma right_triangle : (whisker_left G adj.unit) ≫ (whisker_right adj.counit G) = nat_trans.id _ := begin ext1 Y, dsimp, erw [← adj.hom_equiv_unit, ← equiv.eq_symm_apply, adj.hom_equiv_counit], simp end @[simp, reassoc] lemma left_triangle_components : F.map (adj.unit.app X) ≫ adj.counit.app (F.obj X) = 𝟙 (F.obj X) := congr_arg (λ (t : nat_trans _ (𝟭 C ⋙ F)), t.app X) adj.left_triangle @[simp, reassoc] lemma right_triangle_components {Y : D} : adj.unit.app (G.obj Y) ≫ G.map (adj.counit.app Y) = 𝟙 (G.obj Y) := congr_arg (λ (t : nat_trans _ (G ⋙ 𝟭 C)), t.app Y) adj.right_triangle @[simp, reassoc] lemma counit_naturality {X Y : D} (f : X ⟶ Y) : F.map (G.map f) ≫ (adj.counit).app Y = (adj.counit).app X ≫ f := adj.counit.naturality f @[simp, reassoc] lemma unit_naturality {X Y : C} (f : X ⟶ Y) : (adj.unit).app X ≫ G.map (F.map f) = f ≫ (adj.unit).app Y := (adj.unit.naturality f).symm end end adjunction namespace adjunction structure core_hom_equiv (F : C ⥤ D) (G : D ⥤ C) := (hom_equiv : Π (X Y), (F.obj X ⟶ Y) ≃ (X ⟶ G.obj Y)) (hom_equiv_naturality_left_symm' : Π {X' X Y} (f : X' ⟶ X) (g : X ⟶ G.obj Y), (hom_equiv X' Y).symm (f ≫ g) = F.map f ≫ (hom_equiv X Y).symm g . obviously) (hom_equiv_naturality_right' : Π {X Y Y'} (f : F.obj X ⟶ Y) (g : Y ⟶ Y'), (hom_equiv X Y') (f ≫ g) = (hom_equiv X Y) f ≫ G.map g . obviously) namespace core_hom_equiv restate_axiom hom_equiv_naturality_left_symm' restate_axiom hom_equiv_naturality_right' attribute [simp, priority 10] hom_equiv_naturality_left_symm hom_equiv_naturality_right variables {F : C ⥤ D} {G : D ⥤ C} (adj : core_hom_equiv F G) {X' X : C} {Y Y' : D} @[simp] lemma hom_equiv_naturality_left (f : X' ⟶ X) (g : F.obj X ⟶ Y) : (adj.hom_equiv X' Y) (F.map f ≫ g) = f ≫ (adj.hom_equiv X Y) g := by rw [← equiv.eq_symm_apply]; simp @[simp] lemma hom_equiv_naturality_right_symm (f : X ⟶ G.obj Y) (g : Y ⟶ Y') : (adj.hom_equiv X Y').symm (f ≫ G.map g) = (adj.hom_equiv X Y).symm f ≫ g := by rw [equiv.symm_apply_eq]; simp end core_hom_equiv structure core_unit_counit (F : C ⥤ D) (G : D ⥤ C) := (unit : 𝟭 C ⟶ F.comp G) (counit : G.comp F ⟶ 𝟭 D) (left_triangle' : whisker_right unit F ≫ (functor.associator F G F).hom ≫ whisker_left F counit = nat_trans.id (𝟭 C ⋙ F) . obviously) (right_triangle' : whisker_left G unit ≫ (functor.associator G F G).inv ≫ whisker_right counit G = nat_trans.id (G ⋙ 𝟭 C) . obviously) namespace core_unit_counit restate_axiom left_triangle' restate_axiom right_triangle' attribute [simp] left_triangle right_triangle end core_unit_counit variables {F : C ⥤ D} {G : D ⥤ C} def mk_of_hom_equiv (adj : core_hom_equiv F G) : F ⊣ G := { unit := { app := λ X, (adj.hom_equiv X (F.obj X)) (𝟙 (F.obj X)), naturality' := begin intros, erw [← adj.hom_equiv_naturality_left, ← adj.hom_equiv_naturality_right], dsimp, simp end }, counit := { app := λ Y, (adj.hom_equiv _ _).inv_fun (𝟙 (G.obj Y)), naturality' := begin intros, erw [← adj.hom_equiv_naturality_left_symm, ← adj.hom_equiv_naturality_right_symm], dsimp, simp end }, hom_equiv_unit' := λ X Y f, by erw [← adj.hom_equiv_naturality_right]; simp, hom_equiv_counit' := λ X Y f, by erw [← adj.hom_equiv_naturality_left_symm]; simp, .. adj } def mk_of_unit_counit (adj : core_unit_counit F G) : F ⊣ G := { hom_equiv := λ X Y, { to_fun := λ f, adj.unit.app X ≫ G.map f, inv_fun := λ g, F.map g ≫ adj.counit.app Y, left_inv := λ f, begin change F.map (_ ≫ _) ≫ _ = _, rw [F.map_comp, assoc, ←functor.comp_map, adj.counit.naturality, ←assoc], convert id_comp _ f, have t := congr_arg (λ t : nat_trans _ _, t.app _) adj.left_triangle, dsimp at t, simp only [id_comp] at t, exact t, end, right_inv := λ g, begin change _ ≫ G.map (_ ≫ _) = _, rw [G.map_comp, ←assoc, ←functor.comp_map, ←adj.unit.naturality, assoc], convert comp_id _ g, have t := congr_arg (λ t : nat_trans _ _, t.app _) adj.right_triangle, dsimp at t, simp only [id_comp] at t, exact t, end }, .. adj } section omit 𝒟 def id : 𝟭 C ⊣ 𝟭 C := { hom_equiv := λ X Y, equiv.refl _, unit := 𝟙 _, counit := 𝟙 _ } end section variables {E : Type u₃} [ℰ : category.{v₃} E] (H : D ⥤ E) (I : E ⥤ D) def comp (adj₁ : F ⊣ G) (adj₂ : H ⊣ I) : F ⋙ H ⊣ I ⋙ G := { hom_equiv := λ X Z, equiv.trans (adj₂.hom_equiv _ _) (adj₁.hom_equiv _ _), unit := adj₁.unit ≫ (whisker_left F $ whisker_right adj₂.unit G) ≫ (functor.associator _ _ _).inv, counit := (functor.associator _ _ _).hom ≫ (whisker_left I $ whisker_right adj₁.counit H) ≫ adj₂.counit } end section construct_left -- Construction of a left adjoint. In order to construct a left -- adjoint to a functor G : D → C, it suffices to give the object part -- of a functor F : C → D together with isomorphisms Hom(FX, Y) ≃ -- Hom(X, GY) natural in Y. The action of F on morphisms can be -- constructed from this data. variables {F_obj : C → D} {G} variables (e : Π X Y, (F_obj X ⟶ Y) ≃ (X ⟶ G.obj Y)) variables (he : Π X Y Y' g h, e X Y' (h ≫ g) = e X Y h ≫ G.map g) include he private lemma he' {X Y Y'} (f g) : (e X Y').symm (f ≫ G.map g) = (e X Y).symm f ≫ g := by intros; rw [equiv.symm_apply_eq, he]; simp def left_adjoint_of_equiv : C ⥤ D := { obj := F_obj, map := λ X X' f, (e X (F_obj X')).symm (f ≫ e X' (F_obj X') (𝟙 _)), map_comp' := λ X X' X'' f f', begin rw [equiv.symm_apply_eq, he, equiv.apply_symm_apply], conv { to_rhs, rw [assoc, ←he, id_comp, equiv.apply_symm_apply] }, simp end } def adjunction_of_equiv_left : left_adjoint_of_equiv e he ⊣ G := mk_of_hom_equiv { hom_equiv := e, hom_equiv_naturality_left_symm' := begin intros, erw [← he' e he, ← equiv.apply_eq_iff_eq], simp [(he _ _ _ _ _).symm] end } end construct_left section construct_right -- Construction of a right adjoint, analogous to the above. variables {F} {G_obj : D → C} variables (e : Π X Y, (F.obj X ⟶ Y) ≃ (X ⟶ G_obj Y)) variables (he : Π X' X Y f g, e X' Y (F.map f ≫ g) = f ≫ e X Y g) include he private lemma he' {X' X Y} (f g) : F.map f ≫ (e X Y).symm g = (e X' Y).symm (f ≫ g) := by intros; rw [equiv.eq_symm_apply, he]; simp def right_adjoint_of_equiv : D ⥤ C := { obj := G_obj, map := λ Y Y' g, (e (G_obj Y) Y') ((e (G_obj Y) Y).symm (𝟙 _) ≫ g), map_comp' := λ Y Y' Y'' g g', begin rw [← equiv.eq_symm_apply, ← he' e he, equiv.symm_apply_apply], conv { to_rhs, rw [← assoc, he' e he, comp_id, equiv.symm_apply_apply] }, simp end } def adjunction_of_equiv_right : F ⊣ right_adjoint_of_equiv e he := mk_of_hom_equiv { hom_equiv := e, hom_equiv_naturality_left_symm' := by intros; rw [equiv.symm_apply_eq, he]; simp, hom_equiv_naturality_right' := begin intros X Y Y' g h, erw [←he, equiv.apply_eq_iff_eq, ←assoc, he' e he, comp_id, equiv.symm_apply_apply] end } end construct_right end adjunction open adjunction namespace equivalence def to_adjunction (e : C ≌ D) : e.functor ⊣ e.inverse := mk_of_unit_counit ⟨e.unit, e.counit, by { ext, dsimp, simp only [id_comp], exact e.functor_unit_comp X, }, by { ext, dsimp, simp only [id_comp], exact e.unit_inverse_comp X, }⟩ end equivalence namespace functor def adjunction (E : C ⥤ D) [is_equivalence E] : E ⊣ E.inv := (E.as_equivalence).to_adjunction end functor end category_theory
367d3e8f96880e2ee4aa252834adc71a6e70409c
9028d228ac200bbefe3a711342514dd4e4458bff
/src/data/polynomial/monomial.lean
59f84f76d79abe102ffe6e5dce2ae28f45c8f90d
[ "Apache-2.0" ]
permissive
mcncm/mathlib
8d25099344d9d2bee62822cb9ed43aa3e09fa05e
fde3d78cadeec5ef827b16ae55664ef115e66f57
refs/heads/master
1,672,743,316,277
1,602,618,514,000
1,602,618,514,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
2,863
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 /-! # Univariate monomials Preparatory lemmas for degree_basic. -/ noncomputable theory open finsupp namespace polynomial universes u variables {R : Type u} {a b : R} {m n : ℕ} variables [semiring R] {p q r : polynomial R} /-- `C a` is the constant polynomial `a`. `C` is provided as a ring homomorphism. -/ def C : R →+* polynomial R := add_monoid_algebra.single_zero_ring_hom @[simp] lemma monomial_zero_left (a : R) : monomial 0 a = C a := rfl 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 @[simp] lemma C_bit0 : C (bit0 a) = bit0 (C a) := C_add @[simp] lemma C_bit1 : C (bit1 a) = bit1 (C a) := by simp [bit1, C_bit0] lemma C_pow : C (a ^ n) = C a ^ n := C.map_pow a n @[simp] lemma C_eq_nat_cast (n : ℕ) : C (n : R) = (n : polynomial R) := C.map_nat_cast n @[simp] lemma sum_C_index {a} {β} [add_comm_monoid β] {f : ℕ → R → β} (h : f 0 0 = 0) : (C a).sum f = f 0 a := sum_single_index h lemma coeff_C : coeff (C a) n = ite (n = 0) a 0 := by { convert coeff_monomial using 2, simp [eq_comm], } @[simp] lemma coeff_C_zero : coeff (C a) 0 = a := coeff_monomial theorem nonzero.of_polynomial_ne (h : p ≠ q) : nontrivial R := ⟨⟨0, 1, λ h01 : 0 = 1, h $ by rw [← mul_one p, ← mul_one q, ← C_1, ← h01, C_0, mul_zero, mul_zero] ⟩⟩ 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, monomial_mul_monomial, 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 C_inj : C a = C b ↔ a = b := ⟨λ h, coeff_C_zero.symm.trans (h.symm ▸ coeff_C_zero), congr_arg C⟩ instance [nontrivial R] : infinite (polynomial R) := infinite.of_injective (λ i, monomial i 1) begin intros m n h, have := (single_eq_single_iff _ _ _ _).mp h, simpa only [and_true, eq_self_iff_true, or_false, one_ne_zero, and_self], end lemma monomial_one_eq_X_pow : ∀{n}, monomial n (1 : R) = X^n | 0 := rfl | (n+1) := calc monomial (n + 1) (1 : R) = monomial n 1 * X : by rw [X, monomial_mul_monomial, mul_one] ... = X^n * X : by rw [monomial_one_eq_X_pow] ... = X^(n+1) : by simp only [pow_add, pow_one] lemma monomial_eq_smul_X {n} : monomial n (a : R) = a • X^n := begin calc monomial n a = monomial n (a * 1) : by simp ... = a • monomial n 1 : (smul_single' _ _ _).symm ... = a • X^n : by rw monomial_one_eq_X_pow end end polynomial
1644330f8bcd4ecd5bcc210c071922863f4404be
43390109ab88557e6090f3245c47479c123ee500
/src/Euclid_old/tarski_3.lean
0da131e26a531fb24a6df44b48402c64dc4a0ae3
[ "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
23,167
lean
import Euclid.tarski_2 open classical set namespace Euclidean_plane variables {point : Type} [Euclidean_plane point] local attribute [instance] prop_decidable -- Right Angles def R (a b c : point) : Prop := eqd a c a (S b c) theorem R.symm {a b c : point} : R a b c → R c b a := begin intro h, have h1 := seven13 b a (S b c), simp at h1, unfold R at h, exact (eqd.trans h h1).flip end theorem eight3 {a b c a' : point} : R a b c → a ≠ b → col b a a' → R a' b c := begin intros h h1 h2, unfold R at *, exact four17 h1.symm h2 (seven5 b c).2 h end theorem R.flip {a b c : point} : R a b c → R a b (S b c) := begin intro h, unfold R at *, simpa using h.symm end @[simp] theorem eight4 (a b : point) : R a a b := (seven5 a b).2 @[simp] theorem eight5a (a b : point) : R a b b := (eight4 b a).symm theorem eight6 {a b c a' : point} : R a b c → R a' b c → B a c a' → b = c := begin intros h h1 h2, unfold R at *, generalize h3 : S b c = c', rw h3 at *, have : c = c', exact four19 h2 h h1.flip, rw ←this at *, exact (seven10.1 h3).symm end theorem eight7 {a b c : point} : R a b c → R a c b → b = c := begin intros h h1, have h_1 : eqd a c a (S b c), unfold R at h, exact h, have h_2 : eqd a b a (S c b), unfold R at h1, exact h1, have h2 := seven5 b c, generalize h3 : S b c = c', rw h3 at *, generalize h4 : S c a = a', by_contradiction h5, have h6 : col c b c', left, exact h2.1, have h7 := eight3 h1.symm h5 h6, unfold R at h7, rw h4 at h7, have h8 := seven5 c a, rw h4 at h8, have h9 := h8.2, have h10 : R a' b c, unfold R, rw h3, exact eqd.trans h9.symm.flip (eqd.trans h_1 h7.flip), exact h5 (eight6 h h10 h8.1) end theorem eight8 {a b : point} : R a b a → a = b := begin intro h, exact eight7 (eight5a b a).symm h end theorem eight9 {a b c : point} : R a b c → col a b c → a = b ∨ c = b := begin intros h h1, cases em (a = b), simp *, right, have h2 := eight3 h h_1 (four11 h1).2.1, exact eight8 h2 end theorem eight10 {a b c a' b' c' : point} : R a b c → cong a b c a' b' c' → R a' b' c' := begin intros h h1, cases em (b = c), rw h_1 at *, have h2 : b' = c', exact id_eqd h1.2.1.symm, rw h2, exact eight5a a' c', unfold R at *, generalize h2 : S b c = d, generalize h3 : S b' c' = d', have h4 := seven5 b c, have h5 := seven5 b' c', rw h2 at *, rw h3 at *, have h6 : afs c b d a c' b' d' a', repeat {split}, exact h4.1, exact h5.1, exact h1.2.1.flip, exact eqd.trans h4.2.symm (eqd.trans h1.2.1 h5.2), exact h1.2.2.flip, exact h1.1.flip, have h7 := afive_seg h6 (ne.symm h_1), exact eqd.trans h1.2.2.symm (eqd.trans h h7.flip) end def xperp (x : point) (A A' : set point) : Prop := line A ∧ line A' ∧ x ∈ A ∧ x ∈ A' ∧ ∀ {u v}, u ∈ A → v ∈ A' → R u x v def perp (A A' : set point) : Prop := ∃ x, xperp x A A' notation A ` ⊥ ` B := perp A B theorem xperp.symm {x : point} {A A' : set point} : xperp x A A' → xperp x A' A := begin intro h, unfold xperp at *, split, exact h.2.1, split, exact h.1, split, exact h.2.2.2.1, split, exact h.2.2.1, intros u v hu hv, exact (h.2.2.2.2 hv hu).symm end theorem perp.symm {A A' : set point} : perp A A' → perp A' A := begin intro h, cases h with x hx, constructor, exact hx.symm end theorem eight14a {A A' : set point} : perp A A' → A ≠ A' := begin intros h h1, unfold perp at h, cases h with x hx, unfold xperp at hx, cases hx.1 with u hu, cases hu with v hv, cases em (u = x), rw h at *, rw ←h1 at *, rw hv.2 at *, have h2 := hx.2.2.2.2 (six17b x v) (six17b x v), exact hv.1 (eight8 h2).symm, rw ←h1 at *, rw hv.2 at *, have h2 := hx.2.2.2.2 (six17a u v) (six17a u v), exact h (eight8 h2) end theorem eight14b {x : point} {A A' : set point} : xperp x A A' → A ≠ A' := begin intro h, apply eight14a, constructor, exact h end theorem eight14c {x : point} {A A' : set point} : xperp x A A' ↔ perp A A' ∧ is x A A' := begin split, intro h, split, constructor, exact h, have h1 : perp A A', constructor, exact h, unfold xperp at h, unfold is, split, exact h.1, split, exact h.2.1, split, exact eight14a h1, split, exact h.2.2.1, exact h.2.2.2.1, intro h, cases h with h h1, cases h with y hy, unfold is at h1, suffices : x = y, rwa ←this at hy, by_contradiction, suffices : A = A', exact h1.2.2.1 this, apply six21 a h1.1 h1.2.1 h1.2.2.2.1 h1.2.2.2.2, unfold xperp at hy, exact hy.2.2.1, exact hy.2.2.2.1 end theorem eight14d {x y : point} {A A' : set point} : xperp x A A' → xperp y A A' → x = y := begin intros hx hy, by_contradiction, have h : perp A A', constructor, exact hx, have h1 := eight14a h, suffices : A = A', exact h1 this, unfold xperp at *, exact six21 a hx.1 hx.2.1 hx.2.2.1 hx.2.2.2.1 hy.2.2.1 hy.2.2.2.1 end theorem eight14e {A A' : set point} : perp A A' → line A ∧ line A' := begin intro h, cases h with x hx, split, exact hx.1, exact hx.2.1 end theorem eight14f {a b c : point} {A : set point} : perp (l a b) A → col a b c → a ≠ c → perp (l a c) A := begin intros h h1 h2, suffices : l a b = l a c, rwa ←this, exact six18 (eight14e h).1 h2 (six17a a b) h1 end theorem eight13 {x : point} {A A' : set point} : xperp x A A' ↔ line A ∧ line A' ∧ x ∈ A ∧ x ∈ A' ∧ ∃ u v, u ∈ A ∧ v ∈ A' ∧ u ≠ x ∧ v ≠ x ∧ R u x v := begin split, intro h, split, exact h.1, split, exact h.2.1, split, exact h.2.2.1, split, exact h.2.2.2.1, unfold xperp at h, cases six22 h.1 h.2.2.1 with u hu, cases six22 h.2.1 h.2.2.2.1 with v hv, existsi u, existsi v, have h1 : u ∈ A, rw hu.2, simp, have h2 : v ∈ A', rw hv.2, simp, split, exact h1, split, exact h2, split, exact hu.1.symm, split, exact hv.1.symm, exact h.2.2.2.2 h1 h2, intro h, unfold xperp, split, exact h.1, split, exact h.2.1, split, exact h.2.2.1, split, exact h.2.2.2.1, intros a b ha hb, cases h.2.2.2.2 with u hu, cases hu with v hv, have h1 : R a x v, apply eight3 hv.2.2.2.2 hv.2.2.1, have h_1 : A = l x u, exact six18 h.1 hv.2.2.1.symm h.2.2.1 hv.1, rw h_1 at ha, exact ha, apply R.symm, apply eight3 h1.symm hv.2.2.2.1, have h_2 : A' = l x v, exact six18 h.2.1 hv.2.2.2.1.symm h.2.2.2.1 hv.2.1, rw h_2 at hb, exact hb end theorem eight15 {x : point} {A B : set point} : perp A B → x ∈ A → x ∈ B → xperp x A B := begin intros h h1 h2, cases h with y hy, suffices : x = y, subst x, exact hy, by_contradiction h_1, apply eight14b hy, apply six21 h_1, exact hy.1, exact hy.2.1, exact h1, exact h2, exact hy.2.2.1, exact hy.2.2.2.1 end theorem eight16 {a b c u x : point} : col a b x → col a b u → u ≠ x → (c ≠ x ∧ perp (l a b) (l c x) ↔ ¬col a b c ∧ R c x u) := begin intros h1 h2 h3, split, intro h4, have h5 : xperp x (l a b) (l c x), exact eight15 h4.2 h1 (six17b c x), split, intro h_1, apply eight14b h5, exact six18 h5.1 h4.1 h_1 h1, apply R.symm, exact h5.2.2.2.2 h2 (six17a c x), intro h4, cases h4 with h4 h5, have h_1 : c ≠ x, intro h_1, rw h_1 at h4, exact h4 h1, split, exact h_1, existsi x, apply eight13.2, split, exact six14 (six26 h4).1, split, exact six14 h_1, split, exact h1, split, simp, existsi u, existsi c, split, exact h2, split, exact (six17a c x), split, exact h3, split, exact h_1, exact h5.symm end theorem eight18 {c : point} {A : set point} : line A → c ∉ A → ∃! x, x ∈ A ∧ perp A (l c x) := begin intros h1 h, rcases h1 with ⟨a, b, ha, h2⟩, subst h2, cases seg_cons a a c b with y hy, cases seven25 hy.2.symm with p hp, have h1: R a p y, unfold R, suffices : S p y = c, rw this, exact hy.2, exact (seven6 hp.symm).symm, cases seg_cons y y p a with z hz, cases seg_cons y y a p with q hq, generalize hq' : S z q = q', cases seg_cons y y c q' with c' hc', have h2 : afs a y z q q y p a, focus {repeat {split}}, exact hz.1, exact hq.1.symm, exact hq.2.symm.flip, exact hz.2, exact two5 (eqd.refl a q), exact hq.2, have h3 : a ≠ y, intro h_1, rw h_1 at *, have : y = c, exact id_eqd hy.2.symm, exact (six26 h).2.2 this, have h4 := afive_seg h2 h3, have h5 : cong a p y q z y, split, exact h4.symm.flip, split, exact hz.2.symm.flip, exact hq.2.symm.flip, have h6 := (eight10 h1 h5).symm, have h7 : eqd y q y q', unfold R at h6, rwa hq' at h6, cases seven25 hc'.2 with x hx, existsi x, have h8 : R y x c, unfold R, suffices : S x c = c', rw this, exact hc'.2.symm, exact (seven6 hx.symm).symm, have h9 : c ≠ y, intro h_1, rw ←h_1 at hy, apply h, right, right, exact hy.1.symm, have h10 : y ≠ p, intro h_1, rw ←h_1 at hp, unfold M at hp, apply h9, exact id_eqd hp.2.flip, have h11 : hourglass q q' y c c' z x, have h_1 := seven5 z q, rw hq' at h_1, focus {repeat {split}}, exact (three7a hp.1 hq.1 h10.symm).symm, exact hc'.1, exact h7, exact hc'.2.symm, exact h_1.1, exact h_1.2, exact hx.1.symm, exact hx.2.symm, have h12 := seven22 h11, have h13 : y ≠ z, intro h_1, rw ←h_1 at hz, exact h10 (id_eqd hz.2.symm), have h14 : a ≠ y, intro h_1, rw ←h_1 at hy, apply (six26 h).2.2, exact id_eqd hy.2.symm, have h15 : l y z = l a b, apply six18 (six14 h13) (six26 h).1, right, right, exact hz.1, right, right, exact three7a hy.1 hz.1 h14, have h16 : c ≠ x, intro h_1, rw h_1 at *, apply h, have h_2 : x ∈ l a b, rw ←h15, right, right, exact h12.symm, exact h_2, have h17 : q ≠ z, intro h_1, rw h_1 at *, have h_2 : B z y c, exact three7b hq.1.symm hp.1.symm h10, apply h, suffices : c ∈ l a b, exact this, rw ←h15, right, right, exact h_2.symm, have h18 : xperp x (l y z) (l c x), apply eight13.2, split, exact six14 h13, split, exact (six14 h16), split, right, right, exact h12.symm, split, simp, existsi y, existsi c, simp, split, intro h_1, rw h_1 at *, have h_1 : q ∈ l c x, left, exact three7a hp.1 hq.1 h10.symm, have h_2 : q' ∈ l c x, suffices : c' ≠ x, cases five2 this hx.1 hc'.1.symm, right, right, exact h_2.symm, right, left, exact h_2, intro h_2, rw h_2 at *, apply h9, exact id_eqd hx.2.symm.flip, have h_3 := seven5 z q, rw hq' at h_3, have h_4 : q ≠ q', intro h_4, rw ←h_4 at *, apply h17, exact seven3.1 h_3, have h_5 : l c x = l q q', exact six18 (six14 h9) h_4 h_1 h_2, have h_6 : z ∈ l c x, rw h_5, right, left, exact h_3.1.symm, have h_7 := (four11 h_6).2.2.1, have h_8 : c ∈ l a b, rw ←h15, exact h_7, exact h h_8, split, exact h16, exact h8, rw h15 at h18, have h19 : x ∈ l y z, right, right, exact h12.symm, split, split, rw h15 at h19, exact h19, constructor, exact h18, intros x' hx', have h20 : c ≠ x', intro h_1, apply h, rw ←h_1 at hx', exact hx'.1, have h21 : xperp x' (l a b) (l c x'), exact eight15 hx'.2 hx'.1 (six17b c x'), have h22 : R c x x', apply (h18.symm).2.2.2.2, simp, exact hx'.1, have h23 : R c x' x, apply (h21.symm).2.2.2.2, simp, rw ←h15, exact h19, exact eight7 h23 h22 end theorem eight17 {a : point} {A : set point}: line A → a ∉ A → ∃! x, x ∈ A ∧ perp A (l a x) := begin intros h h1, cases h with p hp, cases hp with q hq, cases hq with hq h2, subst h2, have h3 : ¬col p q a, intro h_1, exact h1 h_1, exact eight18 (six14 hq) h3 end theorem eight19 {p q r : point} (a : point) : R p q r ↔ R (S a p) (S a q) (S a r) := begin unfold R, split, intro h, suffices : (S (S a q) (S a r)) = (S a (S q r)), rw this, exact (seven16 a).1 h, have h1 := seven5 (S a q) (S a r), suffices : M (S a r) (S a q) (S a (S q r)), exact unique_of_exists_unique (seven4 (S a q) (S a r)) h1 this, apply (seven14 a).1, exact seven5 q r, intro h, suffices : S a ((S (S a q) (S a r))) = S q r, rw ←this, apply (seven16 a).2, simp, exact h, suffices : S a (S a (S (S a q) (S a r))) = (S a (S q r)), exact seven9 this, simp, have h1 := seven5 (S a q) (S a r), suffices : M (S a r) (S a q) (S a (S q r)), exact unique_of_exists_unique (seven4 (S a q) (S a r)) h1 this, apply (seven14 a).1, exact seven5 q r end theorem eight20 {a b c p : point} : R a b c → M (S a c) p (S b c) → R b a p ∧ (b ≠ c → a ≠ p) := begin intros h h1, have h2 := seven5 b c, have h3 := seven5 a b, have h4 := seven5 a c, have h5 := seven5 a (S b c), have h6 := seven5 a p, have h7 : R (S a b) b c, cases em (a = b), rw h_1 at *, simp, apply eight3 h h_1, left, exact h3.1, have h8 := (eight19 a).1 h7, unfold R at h7, have h9 := (seven16 a).1 h7, simp at *, have h10 : ifs (S a c) p (S b c) b (S a (S b c)) (S a p) c b, focus {repeat {split}}, exact h1.1, have h_1 := (seven15 a).1 h1.1, simp at h_1, exact h_1.symm, apply two5, have h_2 := seven13 a (S a c) (S b c), simp at h_2, exact h_2, apply eqd.trans h1.2.symm, have h_3 := seven13 a p (S a c), simp at h_3, exact h_3, exact h9.flip, exact h2.2.symm.flip, have h11 := four2 h10, split, unfold R, exact h11.flip, intros hbc hap, apply hbc, have h12 := seven7 a c, rw hap at *, have h13 := seven5 p (S p c), simp at h13, have h14 := unique_of_exists_unique (seven4 p (S p c)) h13 h1, rw ←h14 at h2, exact (seven3.1 h2).symm end theorem eight21 {a b : point} (hab : a ≠ b) (c : point) : ∃ p t, perp (l a b) (l p a) ∧ col a b t ∧ B c t p := begin cases em (col a b c) with habc h, cases six25 hab with c' h, cases eight18 (six14 hab) h with x hx, have h1 : c' ≠ x, intro h_1, rw h_1 at *, exact h hx.1.1, have h2 : xperp x (l a b) (l c' x), exact eight15 hx.1.2 hx.1.1 (six17b c' x), unfold xperp at h2, have h3 := h2.2.2.2.2 (six17a a b) (six17a c' x), unfold R at h3, have h4 := seven5 a c', cases seven25 (eqd.trans h4.2.symm h3) with p hp, have h5 := eight20 (h2.2.2.2.2 (six17a a b) (six17a c' x)) hp, have h6 := h5.2 h1.symm, existsi p, existsi c, cases em (x = a), rw h_1 at hx, rw h_1 at hp, have h_2 : S a c' = p, exact seven3.1 hp, rw h_2 at h4, have h_3 : col c' a p, left, exact h4.1, have h_4 : l c' a = l p a, apply six18 (six14 (six26 h).2.2.symm) h6.symm h_3 (six17b c' a), have h_5 := hx.1, rw h_4 at h_5, split, exact h_5.2, split, exact habc, exact three3 c p, split, existsi a, apply eight13.2, split, exact six14 (six26 h).1, split, exact six14 h6.symm, split, simp, split, simp, existsi x, existsi p, split, exact hx.1.1, simp, split, exact h_1, split, exact h6.symm, exact h5.1, split, exact habc, exact three3 c p, cases eight18 (six14 hab) h with x hx, have h1 : c ≠ x, intro h_1, rw h_1 at *, exact h hx.1.1, have h2 : xperp x (l a b) (l c x), exact eight15 hx.1.2 hx.1.1 (six17b c x), unfold xperp at h2, have h3 := h2.2.2.2.2 (six17a a b) (six17a c x), unfold R at h3, have h4 := seven5 a c, cases seven25 (eqd.trans h4.2.symm h3) with p hp, have h5 := eight20 (h2.2.2.2.2 (six17a a b) (six17a c x)) hp, have h6 := h5.2 h1.symm, cases three17 (seven5 x c).1.symm h4.1.symm hp.1.symm with t ht, cases em (x = a), rw h_1 at ht, existsi p, existsi a, have h_2 : t = a, exact (bet_same ht.2).symm, rw h_2 at *, rw h_1 at hx, have h_3 := hx.1, have h_4 : l c a = l p a, apply six18 (six14 (six26 h).2.2.symm) h6.symm, left, exact ht.1.symm, simp, rw h_4 at h_3, split, exact h_3.2, split, exact h_3.1, exact ht.1.symm, existsi p, existsi t, have h7 : col a b t, have h_2 : col a x t, right, left, exact ht.2, exact five4 (ne.symm h_1) (four11 hx.1.1).1 h_2, split, existsi a, apply eight13.2, split, exact six14 (six26 h).1, split, exact six14 h6.symm, split, simp, split, simp, existsi x, existsi p, split, exact hx.1.1, split, simp, split, exact h_1, split, exact h6.symm, exact h5.1, split, exact h7, exact ht.1.symm end lemma eight23 {a b p q t t' r : point} (hp : ((l a b) ⊥ l p a) ∧ col a b t' ∧ B a t' p) (ht : ((l b a) ⊥ l q b) ∧ col b a t ∧ B p t q) (hr : B b r q ∧ eqd a p b r): ∃ x, M a x b ∧ M p x r := begin have h : a ≠ b, exact six13 (eight14e hp.1).1, cases pasch ht.2.2 hr.1 with x hx, have h1 : col a b x, have h_1 : col b t x, right, left, exact hx.1, cases em (b = t), rw ←h_2 at *, have h_3 : x = b, exact (bet_same hx.1).symm, rw h_3, left, exact three1 a b, exact (four11 (five4 h_2 (four11 ht.2.1).1 h_1)).2.1, have h2 : xperp a (l a b) (l p a), exact eight15 hp.1 (four11 (four12 a b)).1 (six17b p a), have h3 : xperp b (l b a) (l q b), exact eight15 ht.1 (four11 (four12 b a)).1 (six17b q b), have h4 := h2.2.2.2.2 (six17b a b) (six17a p a), have h5 := h3.2.2.2.2 (six17b b a) (six17a q b), have h6 : R a b r, have : col b q r, right, left, exact hr.1.symm, exact (eight3 h5.symm (six13 h3.2.1) this).symm, have h7 : ¬col a p b, intro h_1, cases eight9 h4 (four11 h_1).2.2.2.1, exact h h_2.symm, exact (six13 h2.2.1) h_2, have h8 : ¬col a b r, intro h_1, cases eight9 h6 h_1, exact h h_2, rw h_2 at *, exact (six13 h2.2.1).symm (id_eqd hr.2), suffices : eqd b p a r, have h_1 : p ≠ r, intro h_1, rw h_1 at hx, have h_2 : r = x, exact bet_same hx.2, rw h_2 at h8, exact h8 h1, constructor, apply seven21 h7 h_1 hr.2 this.flip (four11 h1).1, left, exact hx.2.symm, have h9 : x ≠ a, intro h_1, rw h_1 at *, have h_2 : col a p r, right, right, exact hx.2, have h_3 : R r a b, exact eight3 h4.symm (six13 h2.2.1) h_2, apply h, exact eight7 h_3 h6.symm, have h10 := seven5 a p, cases seg_cons x x r (S a p) with r' hr', cases seven25 hr'.2 with m hm, have h11 := seven5 m r, have h12 := unique_of_exists_unique (seven4 m r) h11 hm.symm, have h13 : R x m r, unfold R, rw ←h12 at hr', exact hr'.2.symm, have h14 : R x a p, exact eight3 h4 (ne.symm h) h1, have h15 : ¬col x p (S a p), intro h_1, have h_2 : col p a (S a p), left, exact (seven5 a p).1, have h_3 : p ≠ (S a p), intro h_3, exact (six13 h2.2.1) (seven10.1 h_3.symm), have h_3 : col p a x, exact five4 h_3 (four11 h_2).1 (four11 h_1).2.2.1, cases eight9 h14.symm h_3, exact (six13 h2.2.1) h_4, exact h9 h_4, have h16 : hourglass p (S a p) x r r' a m, focus {repeat {split}}, exact hx.2.symm, exact hr'.1, unfold R at h14, exact h14, exact hr'.2.symm, exact h10.1, exact h10.2, rw ←h12, exact h11.1, rw ←h12, exact h11.2, have h17 := seven22 h16, have h18 : r ≠ m, intro h_1, rw ←h_1 at h17, have h_2 : col a x r, left, exact h17, apply h8, exact five4 h9.symm (four11 h1).1 h_2, have h19 : x ≠ m, intro h_1, have h_2 : col r x p, left, exact hx.2, have h_3 : x ≠ r', intro h_3, rw [←h_1, ←h_3] at h12, rw ←h_1 at h18, apply h18, exact seven9 (eq.trans h12 (seven11 x).symm), have h_4 : col r x (S a p), have h_4 : col x r' (S a p), right, right, exact hr'.1, have h_5 : col x r' r, rw h_1, right, right, exact hm.1.symm, exact (four11 (five4 h_3 h_5 h_4)).2.1, have h_5 : x ≠ r, intro h_5, rw h_5 at h_1, exact h18 h_1, apply h15, exact five4 h_5 (four11 h_2).2.1 (four11 h_4).2.1, have h20 : col a b m, have h_1 : col a x m, left, exact h17, exact five4 h9.symm (four11 h1).1 h_1, have h21 : xperp b (l a b) (l r b), apply eight13.2, split, exact six14 h, split, exact six14 (six26 h8).2.1.symm, split, simp, split, simp, existsi a, existsi r, simp, split, exact h, split, exact (six26 h8).2.1.symm, exact h6, have h22 : xperp m (l a b) (l r m), apply eight13.2, split, exact six14 h, split, exact six14 h18, split, exact h20, split, simp, existsi x, existsi r, split, exact h1, simp, split, exact h19, split, exact h18, exact h13, have h23 : perp (l a b) (l r b), constructor, exact h21, have h24 : perp (l a b) (l r m), constructor, exact h22, have h25 : m = b, apply unique_of_exists_unique (eight18 (six14 h) h8), split, exact h20, exact h24, split, left, exact three1 a b, exact h23, subst m, have h26 : ifs (S a p) a p r r b r' (S a p), focus {repeat {split}}, exact h10.1.symm, exact hm.1.symm, apply two4, apply two11 h10.1 hm.1.symm, exact hr.2.flip, exact eqd.trans h10.2.symm (eqd.trans hr.2 hm.2.symm), exact eqd.trans hr.2 hm.2.symm, exact two4 (eqd.refl r (S a p)), apply two5, apply two11 hx.2.symm hr'.1, unfold R at h14, exact h14.flip, exact hr'.2.symm, have h27 := four2 h26, unfold R at h4, exact eqd.trans h4 h27.symm end theorem eight22 (a b : point) : ∃! x, M a x b := begin cases em (a = b), rw h, existsi b, split, apply seven3.2, refl, intros y hy, exact (seven3.1 hy).symm, apply exists_unique_of_exists_of_unique, cases eight21 h a with p hp, cases eight21 (ne.symm h) p with q hq, cases hp with t' hp, cases hq with t ht, cases five10 a p b q, cases h_1 with r hr, cases eight23 hp ht hr with x hx, constructor, exact hx.1, suffices : ∃ x, M b x a, cases this with x hx, constructor, exact hx.symm, cases h_1 with r hr, have : ∃ x, M b x a ∧ M q x r, apply eight23, split, exact ht.1, split, exact (four11 (four12 b a)).1, exact three3 b q, split, exact hp.1, split, exact (four11 ht.2.1).2.1, exact ht.2.2.symm, exact hr, cases this with x hx, constructor, exact hx.1, intros x y hx hy, exact seven17 hx hy end theorem eight24 {a b p q r t : point} : perp (l p a) (l a b) → perp (l q b) (l a b) → col a b t → B p t q → B b r q → eqd a p b r → ∃ x, M a x b ∧ M p x r := begin intros g3 g4 g5 g6 g7 g8, have g9 := (four11 (four12 a b)).1, have g10 := three3 a p, have g11 := six17 a b, rw g11 at g4, have hp : ((l a b) ⊥ l p a) ∧ col a b a ∧ B a a p, exact ⟨g3.symm, ⟨g9, g10⟩⟩, have ht : ((l b a) ⊥ l q b) ∧ col b a t ∧ B p t q, exact ⟨g4.symm, ⟨(four11 g5).2.1, g6⟩⟩, have hr : B b r q ∧ eqd a p b r, exact ⟨g7, g8⟩, exact eight23 hp ht hr end theorem eight25 {a b : point} : a ≠ b → ∃ c, R a b c ∧ c ≠ b := begin intro h, rcases eight21 h.symm a with ⟨c, p, h1⟩, refine ⟨c, (eight15 h1.1 (six17a b a) (six17b c b)).2.2.2.2 (six17b b a) (six17a c b), _⟩, exact six13 (eight14e h1.1).2 end end Euclidean_plane
a200ca40bbe7b831f45a5e105b6c4e4282e6c407
fa02ed5a3c9c0adee3c26887a16855e7841c668b
/src/linear_algebra/matrix/default.lean
6ac169c9a9c9da8ddef92331c154b70680c4da67
[ "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
293
lean
import linear_algebra.determinant import linear_algebra.matrix.basis import linear_algebra.matrix.block import linear_algebra.matrix.diagonal import linear_algebra.matrix.dot_product import linear_algebra.matrix.to_linear_equiv import linear_algebra.matrix.reindex import linear_algebra.trace
b4a34a637452b247944e209d7209fd16b388e4a2
d9d511f37a523cd7659d6f573f990e2a0af93c6f
/src/field_theory/fixed.lean
4f50337864cb79051409dee0b2d781b02be6069e
[ "Apache-2.0" ]
permissive
hikari0108/mathlib
b7ea2b7350497ab1a0b87a09d093ecc025a50dfa
a9e7d333b0cfd45f13a20f7b96b7d52e19fa2901
refs/heads/master
1,690,483,608,260
1,631,541,580,000
1,631,541,580,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
14,502
lean
/- Copyright (c) 2020 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau -/ import algebra.polynomial.group_ring_action import field_theory.normal import field_theory.separable import field_theory.tower import ring_theory.polynomial /-! # Fixed field under a group action. This is the basis of the Fundamental Theorem of Galois Theory. Given a (finite) group `G` that acts on a field `F`, we define `fixed_points G F`, the subfield consisting of elements of `F` fixed_points by every element of `G`. This subfield is then normal and separable, and in addition (TODO) if `G` acts faithfully on `F` then `finrank (fixed_points G F) F = fintype.card G`. ## Main Definitions - `fixed_points G F`, the subfield consisting of elements of `F` fixed_points by every element of `G`, where `G` is a group that acts on `F`. -/ noncomputable theory open_locale classical big_operators open mul_action finset finite_dimensional universes u v w variables {M : Type u} [monoid M] variables (G : Type u) [group G] variables (F : Type v) [field F] [mul_semiring_action M F] [mul_semiring_action G F] (m : M) /-- The subfield of F fixed by the field endomorphism `m`. -/ def fixed_by.subfield : subfield F := { carrier := fixed_by M F m, zero_mem' := smul_zero m, add_mem' := λ x y hx hy, (smul_add m x y).trans $ congr_arg2 _ hx hy, neg_mem' := λ x hx, (smul_neg m x).trans $ congr_arg _ hx, one_mem' := smul_one m, mul_mem' := λ x y hx hy, (smul_mul' m x y).trans $ congr_arg2 _ hx hy, inv_mem' := λ x hx, (smul_inv'' m x).trans $ congr_arg _ hx } section invariant_subfields variables (M) {F} /-- A typeclass for subrings invariant under a `mul_semiring_action`. -/ class is_invariant_subfield (S : subfield F) : Prop := (smul_mem : ∀ (m : M) {x : F}, x ∈ S → m • x ∈ S) variable (S : subfield F) instance is_invariant_subfield.to_mul_semiring_action [is_invariant_subfield M S] : mul_semiring_action M S := { smul := λ m x, ⟨m • x, is_invariant_subfield.smul_mem m x.2⟩, one_smul := λ s, subtype.eq $ one_smul M s, mul_smul := λ m₁ m₂ s, subtype.eq $ mul_smul m₁ m₂ s, smul_add := λ m s₁ s₂, subtype.eq $ smul_add m s₁ s₂, smul_zero := λ m, subtype.eq $ smul_zero m, smul_one := λ m, subtype.eq $ smul_one m, smul_mul := λ m s₁ s₂, subtype.eq $ smul_mul' m s₁ s₂ } instance [is_invariant_subfield M S] : is_invariant_subring M (S.to_subring) := { smul_mem := is_invariant_subfield.smul_mem } end invariant_subfields namespace fixed_points variable (M) -- we use `subfield.copy` so that the underlying set is `fixed_points M F` /-- The subfield of fixed points by a monoid action. -/ def subfield : subfield F := subfield.copy (⨅ (m : M), fixed_by.subfield F m) (fixed_points M F) (by { ext z, simp [fixed_points, fixed_by.subfield, infi, subfield.mem_Inf] }) instance : is_invariant_subfield M (fixed_points.subfield M F) := { smul_mem := λ g x hx g', by rw [hx, hx] } instance : smul_comm_class M (fixed_points.subfield M F) F := { smul_comm := λ m f f', show m • (↑f * f') = f * (m • f'), by rw [smul_mul', f.prop m] } instance smul_comm_class' : smul_comm_class (fixed_points.subfield M F) M F := smul_comm_class.symm _ _ _ @[simp] theorem smul (m : M) (x : fixed_points.subfield M F) : m • x = x := subtype.eq $ x.2 m -- Why is this so slow? @[simp] theorem smul_polynomial (m : M) (p : polynomial (fixed_points.subfield M F)) : m • p = p := polynomial.induction_on p (λ x, by rw [polynomial.smul_C, smul]) (λ p q ihp ihq, by rw [smul_add, ihp, ihq]) (λ n x ih, by rw [smul_mul', polynomial.smul_C, smul, smul_pow, polynomial.smul_X]) instance : algebra (fixed_points.subfield M F) F := algebra.of_subring (fixed_points.subfield M F).to_subring theorem coe_algebra_map : algebra_map (fixed_points.subfield M F) F = subfield.subtype (fixed_points.subfield M F) := rfl lemma linear_independent_smul_of_linear_independent {s : finset F} : linear_independent (fixed_points.subfield G F) (λ i : (s : set F), (i : F)) → linear_independent F (λ i : (s : set F), mul_action.to_fun G F i) := begin haveI : is_empty ((∅ : finset F) : set F) := ⟨subtype.prop⟩, refine finset.induction_on s (λ _, linear_independent_empty_type) (λ a s has ih hs, _), rw coe_insert at hs ⊢, rw linear_independent_insert (mt mem_coe.1 has) at hs, rw linear_independent_insert' (mt mem_coe.1 has), refine ⟨ih hs.1, λ ha, _⟩, rw finsupp.mem_span_image_iff_total at ha, rcases ha with ⟨l, hl, hla⟩, rw [finsupp.total_apply_of_mem_supported F hl] at hla, suffices : ∀ i ∈ s, l i ∈ fixed_points.subfield G F, { replace hla := (sum_apply _ _ (λ i, l i • to_fun G F i)).symm.trans (congr_fun hla 1), simp_rw [pi.smul_apply, to_fun_apply, one_smul] at hla, refine hs.2 (hla ▸ submodule.sum_mem _ (λ c hcs, _)), change (⟨l c, this c hcs⟩ : fixed_points.subfield G F) • c ∈ _, exact submodule.smul_mem _ _ (submodule.subset_span $ mem_coe.2 hcs) }, intros i his g, refine eq_of_sub_eq_zero (linear_independent_iff'.1 (ih hs.1) s.attach (λ i, g • l i - l i) _ ⟨i, his⟩ (mem_attach _ _) : _), refine (@sum_attach _ _ s _ (λ i, (g • l i - l i) • (to_fun G F) i)).trans _, ext g', dsimp only, conv_lhs { rw sum_apply, congr, skip, funext, rw [pi.smul_apply, sub_smul, smul_eq_mul] }, rw [sum_sub_distrib, pi.zero_apply, sub_eq_zero], conv_lhs { congr, skip, funext, rw [to_fun_apply, ← mul_inv_cancel_left g g', mul_smul, ← smul_mul', ← to_fun_apply _ x] }, show ∑ x in s, g • (λ y, l y • to_fun G F y) x (g⁻¹ * g') = ∑ x in s, (λ y, l y • to_fun G F y) x g', rw [← smul_sum, ← sum_apply _ _ (λ y, l y • to_fun G F y), ← sum_apply _ _ (λ y, l y • to_fun G F y)], dsimp only, rw [hla, to_fun_apply, to_fun_apply, smul_smul, mul_inv_cancel_left] end variables [fintype G] (x : F) /-- `minpoly G F x` is the minimal polynomial of `(x : F)` over `fixed_points G F`. -/ def minpoly : polynomial (fixed_points.subfield G F) := (prod_X_sub_smul G F x).to_subring (fixed_points.subfield G F).to_subring $ λ c hc g, let ⟨n, hc0, hn⟩ := polynomial.mem_frange_iff.1 hc in hn.symm ▸ prod_X_sub_smul.coeff G F x g n namespace minpoly theorem monic : (minpoly G F x).monic := by { simp only [minpoly, polynomial.monic_to_subring], exact prod_X_sub_smul.monic G F x } theorem eval₂ : polynomial.eval₂ (subring.subtype $ (fixed_points.subfield G F).to_subring) x (minpoly G F x) = 0 := begin rw [← prod_X_sub_smul.eval G F x, polynomial.eval₂_eq_eval_map], simp only [minpoly, polynomial.map_to_subring], end theorem eval₂' : polynomial.eval₂ (subfield.subtype $ (fixed_points.subfield G F)) x (minpoly G F x) = 0 := eval₂ G F x theorem ne_one : minpoly G F x ≠ (1 : polynomial (fixed_points.subfield G F)) := λ H, have _ := eval₂ G F x, (one_ne_zero : (1 : F) ≠ 0) $ by rwa [H, polynomial.eval₂_one] at this theorem of_eval₂ (f : polynomial (fixed_points.subfield G F)) (hf : polynomial.eval₂ (subfield.subtype $ fixed_points.subfield G F) x f = 0) : minpoly G F x ∣ f := begin erw [← polynomial.map_dvd_map' (subfield.subtype $ fixed_points.subfield G F), minpoly, polynomial.map_to_subring _ (subfield G F).to_subring, prod_X_sub_smul], refine fintype.prod_dvd_of_coprime (polynomial.pairwise_coprime_X_sub $ mul_action.injective_of_quotient_stabilizer G x) (λ y, quotient_group.induction_on y $ λ g, _), rw [polynomial.dvd_iff_is_root, polynomial.is_root.def, mul_action.of_quotient_stabilizer_mk, polynomial.eval_smul', ← subfield.to_subring.subtype_eq_subtype, ← is_invariant_subring.coe_subtype_hom' G (fixed_points.subfield G F).to_subring, ← mul_semiring_action_hom.coe_polynomial, ← mul_semiring_action_hom.map_smul, smul_polynomial, mul_semiring_action_hom.coe_polynomial, is_invariant_subring.coe_subtype_hom', polynomial.eval_map, subfield.to_subring.subtype_eq_subtype, hf, smul_zero] end /- Why is this so slow? -/ theorem irreducible_aux (f g : polynomial (fixed_points.subfield G F)) (hf : f.monic) (hg : g.monic) (hfg : f * g = minpoly G F x) : f = 1 ∨ g = 1 := begin have hf2 : f ∣ minpoly G F x, { rw ← hfg, exact dvd_mul_right _ _ }, have hg2 : g ∣ minpoly G F x, { rw ← hfg, exact dvd_mul_left _ _ }, have := eval₂ G F x, rw [← hfg, polynomial.eval₂_mul, mul_eq_zero] at this, cases this, { right, have hf3 : f = minpoly G F x, { exact polynomial.eq_of_monic_of_associated hf (monic G F x) (associated_of_dvd_dvd hf2 $ @of_eval₂ G _ F _ _ _ x f this) }, rwa [← mul_one (minpoly G F x), hf3, mul_right_inj' (monic G F x).ne_zero] at hfg }, { left, have hg3 : g = minpoly G F x, { exact polynomial.eq_of_monic_of_associated hg (monic G F x) (associated_of_dvd_dvd hg2 $ @of_eval₂ G _ F _ _ _ x g this) }, rwa [← one_mul (minpoly G F x), hg3, mul_left_inj' (monic G F x).ne_zero] at hfg } end theorem irreducible : irreducible (minpoly G F x) := (polynomial.irreducible_of_monic (monic G F x) (ne_one G F x)).2 (irreducible_aux G F x) end minpoly theorem is_integral : is_integral (fixed_points.subfield G F) x := ⟨minpoly G F x, minpoly.monic G F x, minpoly.eval₂ G F x⟩ theorem minpoly_eq_minpoly : minpoly G F x = _root_.minpoly (fixed_points.subfield G F) x := minpoly.unique' (minpoly.irreducible G F x) (minpoly.eval₂ G F x) (minpoly.monic G F x) instance normal : normal (fixed_points.subfield G F) F := ⟨λ x, is_integral G F x, λ x, (polynomial.splits_id_iff_splits _).1 $ by { rw [← minpoly_eq_minpoly, minpoly, coe_algebra_map, ← subfield.to_subring.subtype_eq_subtype, polynomial.map_to_subring _ (fixed_points.subfield G F).to_subring, prod_X_sub_smul], exact polynomial.splits_prod _ (λ _ _, polynomial.splits_X_sub_C _) }⟩ instance separable : is_separable (fixed_points.subfield G F) F := ⟨λ x, is_integral G F x, λ x, by { -- this was a plain rw when we were using unbundled subrings erw [← minpoly_eq_minpoly, ← polynomial.separable_map (fixed_points.subfield G F).subtype, minpoly, polynomial.map_to_subring _ ((subfield G F).to_subring) ], exact polynomial.separable_prod_X_sub_C_iff.2 (injective_of_quotient_stabilizer G x) }⟩ lemma dim_le_card : module.rank (fixed_points.subfield G F) F ≤ fintype.card G := begin refine dim_le (λ s hs, cardinal.nat_cast_le.1 _), rw [← @dim_fun' F G, ← cardinal.lift_nat_cast.{v (max u v)}, cardinal.finset_card, ← cardinal.lift_id (module.rank F (G → F))], exact cardinal_lift_le_dim_of_linear_independent.{_ _ _ (max u v)} (linear_independent_smul_of_linear_independent G F hs) end instance : finite_dimensional (fixed_points.subfield G F) F := is_noetherian.iff_dim_lt_omega.2 $ lt_of_le_of_lt (dim_le_card G F) (cardinal.nat_lt_omega _) lemma finrank_le_card : finrank (fixed_points.subfield G F) F ≤ fintype.card G := begin rw [← cardinal.nat_cast_le, finrank_eq_dim], apply dim_le_card, end end fixed_points lemma linear_independent_to_linear_map (R : Type u) (A : Type v) (B : Type w) [comm_semiring R] [integral_domain A] [algebra R A] [integral_domain B] [algebra R B] : linear_independent B (alg_hom.to_linear_map : (A →ₐ[R] B) → (A →ₗ[R] B)) := have linear_independent B (linear_map.lto_fun R A B ∘ alg_hom.to_linear_map), from ((linear_independent_monoid_hom A B).comp (coe : (A →ₐ[R] B) → (A →* B)) (λ f g hfg, alg_hom.ext $ monoid_hom.ext_iff.1 hfg) : _), this.of_comp _ lemma cardinal_mk_alg_hom (K : Type u) (V : Type v) (W : Type w) [field K] [field V] [algebra K V] [finite_dimensional K V] [field W] [algebra K W] [finite_dimensional K W] : cardinal.mk (V →ₐ[K] W) ≤ finrank W (V →ₗ[K] W) := cardinal_mk_le_finrank_of_linear_independent $ linear_independent_to_linear_map K V W noncomputable instance alg_hom.fintype (K : Type u) (V : Type v) (W : Type w) [field K] [field V] [algebra K V] [finite_dimensional K V] [field W] [algebra K W] [finite_dimensional K W] : fintype (V →ₐ[K] W) := classical.choice $ cardinal.lt_omega_iff_fintype.1 $ lt_of_le_of_lt (cardinal_mk_alg_hom K V W) (cardinal.nat_lt_omega _) noncomputable instance alg_equiv.fintype (K : Type u) (V : Type v) [field K] [field V] [algebra K V] [finite_dimensional K V] : fintype (V ≃ₐ[K] V) := fintype.of_equiv (V →ₐ[K] V) (alg_equiv_equiv_alg_hom K V).symm lemma finrank_alg_hom (K : Type u) (V : Type v) [field K] [field V] [algebra K V] [finite_dimensional K V] : fintype.card (V →ₐ[K] V) ≤ finrank V (V →ₗ[K] V) := fintype_card_le_finrank_of_linear_independent $ linear_independent_to_linear_map K V V namespace fixed_points theorem finrank_eq_card (G : Type u) (F : Type v) [group G] [field F] [fintype G] [mul_semiring_action G F] [has_faithful_scalar G F] : finrank (fixed_points.subfield G F) F = fintype.card G := le_antisymm (fixed_points.finrank_le_card G F) $ calc fintype.card G ≤ fintype.card (F →ₐ[fixed_points.subfield G F] F) : fintype.card_le_of_injective _ (mul_semiring_action.to_alg_hom_injective _ F) ... ≤ finrank F (F →ₗ[fixed_points.subfield G F] F) : finrank_alg_hom (fixed_points G F) F ... = finrank (fixed_points.subfield G F) F : finrank_linear_map' _ _ _ /-- `mul_semiring_action.to_alg_hom` is bijective. -/ theorem to_alg_hom_bijective (G : Type u) (F : Type v) [group G] [field F] [fintype G] [mul_semiring_action G F] [has_faithful_scalar G F] : function.bijective (mul_semiring_action.to_alg_hom _ _ : G → F →ₐ[subfield G F] F) := begin rw fintype.bijective_iff_injective_and_card, split, { exact mul_semiring_action.to_alg_hom_injective _ F }, { apply le_antisymm, { exact fintype.card_le_of_injective _ (mul_semiring_action.to_alg_hom_injective _ F) }, { rw ← finrank_eq_card G F, exact has_le.le.trans_eq (finrank_alg_hom _ F) (finrank_linear_map' _ _ _) } }, end /-- Bijection between G and algebra homomorphisms that fix the fixed points -/ def to_alg_hom_equiv (G : Type u) (F : Type v) [group G] [field F] [fintype G] [mul_semiring_action G F] [has_faithful_scalar G F] : G ≃ (F →ₐ[fixed_points.subfield G F] F) := equiv.of_bijective _ (to_alg_hom_bijective G F) end fixed_points
5ec63624ee2960ee9500956d1258e6e9708e7094
2a70b774d16dbdf5a533432ee0ebab6838df0948
/_target/deps/mathlib/src/topology/instances/ennreal.lean
ebf3714f51264f9b38032956b4dad4e7009c3e19
[ "Apache-2.0" ]
permissive
hjvromen/lewis
40b035973df7c77ebf927afab7878c76d05ff758
105b675f73630f028ad5d890897a51b3c1146fb0
refs/heads/master
1,677,944,636,343
1,676,555,301,000
1,676,555,301,000
327,553,599
0
0
null
null
null
null
UTF-8
Lean
false
false
43,907
lean
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Johannes Hölzl -/ import topology.instances.nnreal /-! # Extended non-negative reals -/ noncomputable theory open classical set filter metric open_locale classical topological_space ennreal nnreal big_operators filter variables {α : Type*} {β : Type*} {γ : Type*} namespace ennreal variables {a b c d : ennreal} {r p q : ℝ≥0} variables {x y z : ennreal} {ε ε₁ ε₂ : ennreal} {s : set ennreal} section topological_space open topological_space /-- Topology on `ennreal`. Note: this is different from the `emetric_space` topology. The `emetric_space` topology has `is_open {⊤}`, while this topology doesn't have singleton elements. -/ instance : topological_space ennreal := preorder.topology ennreal instance : order_topology ennreal := ⟨rfl⟩ instance : t2_space ennreal := by apply_instance -- short-circuit type class inference instance : second_countable_topology ennreal := ⟨⟨⋃q ≥ (0:ℚ), {{a : ennreal | a < nnreal.of_real q}, {a : ennreal | ↑(nnreal.of_real q) < a}}, (countable_encodable _).bUnion $ assume a ha, (countable_singleton _).insert _, le_antisymm (le_generate_from $ by simp [or_imp_distrib, is_open_lt', is_open_gt'] {contextual := tt}) (le_generate_from $ λ s h, begin rcases h with ⟨a, hs | hs⟩; [ rw show s = ⋃q∈{q:ℚ | 0 ≤ q ∧ a < nnreal.of_real q}, {b | ↑(nnreal.of_real q) < b}, from set.ext (assume b, by simp [hs, @ennreal.lt_iff_exists_rat_btwn a b, and_assoc]), rw show s = ⋃q∈{q:ℚ | 0 ≤ q ∧ ↑(nnreal.of_real q) < a}, {b | b < ↑(nnreal.of_real q)}, from set.ext (assume b, by simp [hs, @ennreal.lt_iff_exists_rat_btwn b a, and_comm, and_assoc])]; { apply is_open_Union, intro q, apply is_open_Union, intro hq, exact generate_open.basic _ (mem_bUnion hq.1 $ by simp) } end)⟩⟩ lemma embedding_coe : embedding (coe : ℝ≥0 → ennreal) := ⟨⟨begin refine le_antisymm _ _, { rw [@order_topology.topology_eq_generate_intervals ennreal _, ← coinduced_le_iff_le_induced], refine le_generate_from (assume s ha, _), rcases ha with ⟨a, rfl | rfl⟩, show is_open {b : ℝ≥0 | a < ↑b}, { cases a; simp [none_eq_top, some_eq_coe, is_open_lt'] }, show is_open {b : ℝ≥0 | ↑b < a}, { cases a; simp [none_eq_top, some_eq_coe, is_open_gt', is_open_const] } }, { rw [@order_topology.topology_eq_generate_intervals ℝ≥0 _], refine le_generate_from (assume s ha, _), rcases ha with ⟨a, rfl | rfl⟩, exact ⟨Ioi a, is_open_Ioi, by simp [Ioi]⟩, exact ⟨Iio a, is_open_Iio, by simp [Iio]⟩ } end⟩, assume a b, coe_eq_coe.1⟩ lemma is_open_ne_top : is_open {a : ennreal | a ≠ ⊤} := is_open_ne lemma is_open_Ico_zero : is_open (Ico 0 b) := by { rw ennreal.Ico_eq_Iio, exact is_open_Iio} lemma coe_range_mem_nhds : range (coe : ℝ≥0 → ennreal) ∈ 𝓝 (r : ennreal) := have {a : ennreal | a ≠ ⊤} = range (coe : ℝ≥0 → ennreal), from set.ext $ assume a, by cases a; simp [none_eq_top, some_eq_coe], this ▸ mem_nhds_sets is_open_ne_top coe_ne_top @[norm_cast] lemma tendsto_coe {f : filter α} {m : α → ℝ≥0} {a : ℝ≥0} : tendsto (λa, (m a : ennreal)) f (𝓝 ↑a) ↔ tendsto m f (𝓝 a) := embedding_coe.tendsto_nhds_iff.symm lemma continuous_coe : continuous (coe : ℝ≥0 → ennreal) := embedding_coe.continuous lemma continuous_coe_iff {α} [topological_space α] {f : α → ℝ≥0} : continuous (λa, (f a : ennreal)) ↔ continuous f := embedding_coe.continuous_iff.symm lemma nhds_coe {r : ℝ≥0} : 𝓝 (r : ennreal) = (𝓝 r).map coe := by rw [embedding_coe.induced, map_nhds_induced_eq coe_range_mem_nhds] lemma nhds_coe_coe {r p : ℝ≥0} : 𝓝 ((r : ennreal), (p : ennreal)) = (𝓝 (r, p)).map (λp:ℝ≥0×ℝ≥0, (p.1, p.2)) := begin rw [(embedding_coe.prod_mk embedding_coe).map_nhds_eq], rw [← prod_range_range_eq], exact prod_mem_nhds_sets coe_range_mem_nhds coe_range_mem_nhds end lemma continuous_of_real : continuous ennreal.of_real := (continuous_coe_iff.2 continuous_id).comp nnreal.continuous_of_real lemma tendsto_of_real {f : filter α} {m : α → ℝ} {a : ℝ} (h : tendsto m f (𝓝 a)) : tendsto (λa, ennreal.of_real (m a)) f (𝓝 (ennreal.of_real a)) := tendsto.comp (continuous.tendsto continuous_of_real _) h lemma tendsto_to_nnreal {a : ennreal} : a ≠ ⊤ → tendsto (ennreal.to_nnreal) (𝓝 a) (𝓝 a.to_nnreal) := begin cases a; simp [some_eq_coe, none_eq_top, nhds_coe, tendsto_map'_iff, (∘)], exact tendsto_id end lemma continuous_on_to_nnreal : continuous_on ennreal.to_nnreal {a | a ≠ ∞} := continuous_on_iff_continuous_restrict.2 $ continuous_iff_continuous_at.2 $ λ x, (tendsto_to_nnreal x.2).comp continuous_at_subtype_coe lemma tendsto_to_real {a : ennreal} : a ≠ ⊤ → tendsto (ennreal.to_real) (𝓝 a) (𝓝 a.to_real) := λ ha, tendsto.comp ((@nnreal.tendsto_coe _ (𝓝 a.to_nnreal) id (a.to_nnreal)).2 tendsto_id) (tendsto_to_nnreal ha) /-- The set of finite `ennreal` numbers is homeomorphic to `ℝ≥0`. -/ def ne_top_homeomorph_nnreal : {a | a ≠ ∞} ≃ₜ ℝ≥0 := { continuous_to_fun := continuous_on_iff_continuous_restrict.1 continuous_on_to_nnreal, continuous_inv_fun := continuous_subtype_mk _ continuous_coe, .. ne_top_equiv_nnreal } /-- The set of finite `ennreal` numbers is homeomorphic to `ℝ≥0`. -/ def lt_top_homeomorph_nnreal : {a | a < ∞} ≃ₜ ℝ≥0 := by refine (homeomorph.set_congr $ set.ext $ λ x, _).trans ne_top_homeomorph_nnreal; simp only [mem_set_of_eq, lt_top_iff_ne_top] lemma nhds_top : 𝓝 ∞ = ⨅ a ≠ ∞, 𝓟 (Ioi a) := nhds_top_order.trans $ by simp [lt_top_iff_ne_top, Ioi] lemma nhds_top' : 𝓝 ∞ = ⨅ r : ℝ≥0, 𝓟 (Ioi r) := nhds_top.trans $ infi_ne_top _ lemma tendsto_nhds_top_iff_nnreal {m : α → ennreal} {f : filter α} : tendsto m f (𝓝 ⊤) ↔ ∀ x : ℝ≥0, ∀ᶠ a in f, ↑x < m a := by simp only [nhds_top', tendsto_infi, tendsto_principal, mem_Ioi] lemma tendsto_nhds_top_iff_nat {m : α → ennreal} {f : filter α} : tendsto m f (𝓝 ⊤) ↔ ∀ n : ℕ, ∀ᶠ a in f, ↑n < m a := tendsto_nhds_top_iff_nnreal.trans ⟨λ h n, by simpa only [ennreal.coe_nat] using h n, λ h x, let ⟨n, hn⟩ := exists_nat_gt x in (h n).mono (λ y, lt_trans $ by rwa [← ennreal.coe_nat, coe_lt_coe])⟩ lemma tendsto_nhds_top {m : α → ennreal} {f : filter α} (h : ∀ n : ℕ, ∀ᶠ a in f, ↑n < m a) : tendsto m f (𝓝 ⊤) := tendsto_nhds_top_iff_nat.2 h lemma tendsto_nat_nhds_top : tendsto (λ n : ℕ, ↑n) at_top (𝓝 ∞) := tendsto_nhds_top $ λ n, mem_at_top_sets.2 ⟨n+1, λ m hm, ennreal.coe_nat_lt_coe_nat.2 $ nat.lt_of_succ_le hm⟩ @[simp, norm_cast] lemma tendsto_coe_nhds_top {f : α → ℝ≥0} {l : filter α} : tendsto (λ x, (f x : ennreal)) l (𝓝 ∞) ↔ tendsto f l at_top := by rw [tendsto_nhds_top_iff_nnreal, at_top_basis_Ioi.tendsto_right_iff]; [simp, apply_instance, apply_instance] lemma nhds_zero : 𝓝 (0 : ennreal) = ⨅a ≠ 0, 𝓟 (Iio a) := nhds_bot_order.trans $ by simp [bot_lt_iff_ne_bot, Iio] -- using Icc because -- • don't have 'Ioo (x - ε) (x + ε) ∈ 𝓝 x' unless x > 0 -- • (x - y ≤ ε ↔ x ≤ ε + y) is true, while (x - y < ε ↔ x < ε + y) is not lemma Icc_mem_nhds : x ≠ ⊤ → 0 < ε → Icc (x - ε) (x + ε) ∈ 𝓝 x := begin assume xt ε0, rw mem_nhds_sets_iff, by_cases x0 : x = 0, { use Iio (x + ε), have : Iio (x + ε) ⊆ Icc (x - ε) (x + ε), assume a, rw x0, simpa using le_of_lt, use this, exact ⟨is_open_Iio, mem_Iio_self_add xt ε0⟩ }, { use Ioo (x - ε) (x + ε), use Ioo_subset_Icc_self, exact ⟨is_open_Ioo, mem_Ioo_self_sub_add xt x0 ε0 ε0 ⟩ } end lemma nhds_of_ne_top : x ≠ ⊤ → 𝓝 x = ⨅ε > 0, 𝓟 (Icc (x - ε) (x + ε)) := begin assume xt, refine le_antisymm _ _, -- first direction simp only [le_infi_iff, le_principal_iff], assume ε ε0, exact Icc_mem_nhds xt ε0, -- second direction rw nhds_generate_from, refine le_infi (assume s, le_infi $ assume hs, _), simp only [mem_set_of_eq] at hs, rcases hs with ⟨xs, ⟨a, ha⟩⟩, cases ha, { rw ha at *, rcases exists_between xs with ⟨b, ⟨ab, bx⟩⟩, have xb_pos : x - b > 0 := zero_lt_sub_iff_lt.2 bx, have xxb : x - (x - b) = b := sub_sub_cancel (by rwa lt_top_iff_ne_top) (le_of_lt bx), refine infi_le_of_le (x - b) (infi_le_of_le xb_pos _), simp only [mem_principal_sets, le_principal_iff], assume y, rintros ⟨h₁, h₂⟩, rw xxb at h₁, calc a < b : ab ... ≤ y : h₁ }, { rw ha at *, rcases exists_between xs with ⟨b, ⟨xb, ba⟩⟩, have bx_pos : b - x > 0 := zero_lt_sub_iff_lt.2 xb, have xbx : x + (b - x) = b := add_sub_cancel_of_le (le_of_lt xb), refine infi_le_of_le (b - x) (infi_le_of_le bx_pos _), simp only [mem_principal_sets, le_principal_iff], assume y, rintros ⟨h₁, h₂⟩, rw xbx at h₂, calc y ≤ b : h₂ ... < a : ba }, end /-- Characterization of neighborhoods for `ennreal` numbers. See also `tendsto_order` for a version with strict inequalities. -/ protected theorem tendsto_nhds {f : filter α} {u : α → ennreal} {a : ennreal} (ha : a ≠ ⊤) : tendsto u f (𝓝 a) ↔ ∀ ε > 0, ∀ᶠ x in f, (u x) ∈ Icc (a - ε) (a + ε) := by simp only [nhds_of_ne_top ha, tendsto_infi, tendsto_principal, mem_Icc] protected lemma tendsto_at_top [nonempty β] [semilattice_sup β] {f : β → ennreal} {a : ennreal} (ha : a ≠ ⊤) : tendsto f at_top (𝓝 a) ↔ ∀ε>0, ∃N, ∀n≥N, (f n) ∈ Icc (a - ε) (a + ε) := by simp only [ennreal.tendsto_nhds ha, mem_at_top_sets, mem_set_of_eq, filter.eventually] instance : has_continuous_add ennreal := begin refine ⟨continuous_iff_continuous_at.2 _⟩, rintro ⟨(_|a), b⟩, { exact tendsto_nhds_top_mono' continuous_at_fst (λ p, le_add_right le_rfl) }, rcases b with (_|b), { exact tendsto_nhds_top_mono' continuous_at_snd (λ p, le_add_left le_rfl) }, simp only [continuous_at, some_eq_coe, nhds_coe_coe, ← coe_add, tendsto_map'_iff, (∘), tendsto_coe, tendsto_add] end protected lemma tendsto_mul (ha : a ≠ 0 ∨ b ≠ ⊤) (hb : b ≠ 0 ∨ a ≠ ⊤) : tendsto (λp:ennreal×ennreal, p.1 * p.2) (𝓝 (a, b)) (𝓝 (a * b)) := have ht : ∀b:ennreal, b ≠ 0 → tendsto (λp:ennreal×ennreal, p.1 * p.2) (𝓝 ((⊤:ennreal), b)) (𝓝 ⊤), begin refine assume b hb, tendsto_nhds_top_iff_nnreal.2 $ assume n, _, rcases lt_iff_exists_nnreal_btwn.1 (pos_iff_ne_zero.2 hb) with ⟨ε, hε, hεb⟩, replace hε : 0 < ε, from coe_pos.1 hε, filter_upwards [prod_mem_nhds_sets (lt_mem_nhds $ @coe_lt_top (n / ε)) (lt_mem_nhds hεb)], rintros ⟨a₁, a₂⟩ ⟨h₁, h₂⟩, dsimp at h₁ h₂ ⊢, rw [← div_mul_cancel n hε.ne', coe_mul], exact mul_lt_mul h₁ h₂ end, begin cases a, {simp [none_eq_top] at hb, simp [none_eq_top, ht b hb, top_mul, hb] }, cases b, { simp [none_eq_top] at ha, simp [*, nhds_swap (a : ennreal) ⊤, none_eq_top, some_eq_coe, top_mul, tendsto_map'_iff, (∘), mul_comm] }, simp [some_eq_coe, nhds_coe_coe, tendsto_map'_iff, (∘)], simp only [coe_mul.symm, tendsto_coe, tendsto_mul] end protected lemma tendsto.mul {f : filter α} {ma : α → ennreal} {mb : α → ennreal} {a b : ennreal} (hma : tendsto ma f (𝓝 a)) (ha : a ≠ 0 ∨ b ≠ ⊤) (hmb : tendsto mb f (𝓝 b)) (hb : b ≠ 0 ∨ a ≠ ⊤) : tendsto (λa, ma a * mb a) f (𝓝 (a * b)) := show tendsto ((λp:ennreal×ennreal, p.1 * p.2) ∘ (λa, (ma a, mb a))) f (𝓝 (a * b)), from tendsto.comp (ennreal.tendsto_mul ha hb) (hma.prod_mk_nhds hmb) protected lemma tendsto.const_mul {f : filter α} {m : α → ennreal} {a b : ennreal} (hm : tendsto m f (𝓝 b)) (hb : b ≠ 0 ∨ a ≠ ⊤) : tendsto (λb, a * m b) f (𝓝 (a * b)) := by_cases (assume : a = 0, by simp [this, tendsto_const_nhds]) (assume ha : a ≠ 0, ennreal.tendsto.mul tendsto_const_nhds (or.inl ha) hm hb) protected lemma tendsto.mul_const {f : filter α} {m : α → ennreal} {a b : ennreal} (hm : tendsto m f (𝓝 a)) (ha : a ≠ 0 ∨ b ≠ ⊤) : tendsto (λx, m x * b) f (𝓝 (a * b)) := by simpa only [mul_comm] using ennreal.tendsto.const_mul hm ha protected lemma continuous_at_const_mul {a b : ennreal} (h : a ≠ ⊤ ∨ b ≠ 0) : continuous_at ((*) a) b := tendsto.const_mul tendsto_id h.symm protected lemma continuous_at_mul_const {a b : ennreal} (h : a ≠ ⊤ ∨ b ≠ 0) : continuous_at (λ x, x * a) b := tendsto.mul_const tendsto_id h.symm protected lemma continuous_const_mul {a : ennreal} (ha : a ≠ ⊤) : continuous ((*) a) := continuous_iff_continuous_at.2 $ λ x, ennreal.continuous_at_const_mul (or.inl ha) protected lemma continuous_mul_const {a : ennreal} (ha : a ≠ ⊤) : continuous (λ x, x * a) := continuous_iff_continuous_at.2 $ λ x, ennreal.continuous_at_mul_const (or.inl ha) lemma le_of_forall_lt_one_mul_le {x y : ennreal} (h : ∀ a < 1, a * x ≤ y) : x ≤ y := begin have : tendsto (* x) (𝓝[Iio 1] 1) (𝓝 (1 * x)) := (ennreal.continuous_at_mul_const (or.inr one_ne_zero)).mono_left inf_le_left, rw one_mul at this, haveI : (𝓝[Iio 1] (1 : ennreal)).ne_bot := nhds_within_Iio_self_ne_bot' ennreal.zero_lt_one, exact le_of_tendsto this (eventually_nhds_within_iff.2 $ eventually_of_forall h) end lemma infi_mul_left {ι} [nonempty ι] {f : ι → ennreal} {a : ennreal} (h : a = ⊤ → (⨅ i, f i) = 0 → ∃ i, f i = 0) : (⨅ i, a * f i) = a * ⨅ i, f i := begin by_cases H : a = ⊤ ∧ (⨅ i, f i) = 0, { rcases h H.1 H.2 with ⟨i, hi⟩, rw [H.2, mul_zero, ← bot_eq_zero, infi_eq_bot], exact λ b hb, ⟨i, by rwa [hi, mul_zero, ← bot_eq_zero]⟩ }, { rw not_and_distrib at H, exact (map_infi_of_continuous_at_of_monotone' (ennreal.continuous_at_const_mul H) ennreal.mul_left_mono).symm } end lemma infi_mul_right {ι} [nonempty ι] {f : ι → ennreal} {a : ennreal} (h : a = ⊤ → (⨅ i, f i) = 0 → ∃ i, f i = 0) : (⨅ i, f i * a) = (⨅ i, f i) * a := by simpa only [mul_comm a] using infi_mul_left h protected lemma continuous_inv : continuous (has_inv.inv : ennreal → ennreal) := continuous_iff_continuous_at.2 $ λ a, tendsto_order.2 ⟨begin assume b hb, simp only [@ennreal.lt_inv_iff_lt_inv b], exact gt_mem_nhds (ennreal.lt_inv_iff_lt_inv.1 hb), end, begin assume b hb, simp only [gt_iff_lt, @ennreal.inv_lt_iff_inv_lt _ b], exact lt_mem_nhds (ennreal.inv_lt_iff_inv_lt.1 hb) end⟩ @[simp] protected lemma tendsto_inv_iff {f : filter α} {m : α → ennreal} {a : ennreal} : tendsto (λ x, (m x)⁻¹) f (𝓝 a⁻¹) ↔ tendsto m f (𝓝 a) := ⟨λ h, by simpa only [function.comp, ennreal.inv_inv] using (ennreal.continuous_inv.tendsto a⁻¹).comp h, (ennreal.continuous_inv.tendsto a).comp⟩ protected lemma tendsto.div {f : filter α} {ma : α → ennreal} {mb : α → ennreal} {a b : ennreal} (hma : tendsto ma f (𝓝 a)) (ha : a ≠ 0 ∨ b ≠ 0) (hmb : tendsto mb f (𝓝 b)) (hb : b ≠ ⊤ ∨ a ≠ ⊤) : tendsto (λa, ma a / mb a) f (𝓝 (a / b)) := by { apply tendsto.mul hma _ (ennreal.tendsto_inv_iff.2 hmb) _; simp [ha, hb] } protected lemma tendsto.const_div {f : filter α} {m : α → ennreal} {a b : ennreal} (hm : tendsto m f (𝓝 b)) (hb : b ≠ ⊤ ∨ a ≠ ⊤) : tendsto (λb, a / m b) f (𝓝 (a / b)) := by { apply tendsto.const_mul (ennreal.tendsto_inv_iff.2 hm), simp [hb] } protected lemma tendsto.div_const {f : filter α} {m : α → ennreal} {a b : ennreal} (hm : tendsto m f (𝓝 a)) (ha : a ≠ 0 ∨ b ≠ 0) : tendsto (λx, m x / b) f (𝓝 (a / b)) := by { apply tendsto.mul_const hm, simp [ha] } protected lemma tendsto_inv_nat_nhds_zero : tendsto (λ n : ℕ, (n : ennreal)⁻¹) at_top (𝓝 0) := ennreal.inv_top ▸ ennreal.tendsto_inv_iff.2 tendsto_nat_nhds_top lemma Sup_add {s : set ennreal} (hs : s.nonempty) : Sup s + a = ⨆b∈s, b + a := have Sup ((λb, b + a) '' s) = Sup s + a, from is_lub.Sup_eq (is_lub_of_is_lub_of_tendsto (assume x _ y _ h, add_le_add h (le_refl _)) (is_lub_Sup s) hs (tendsto.add (tendsto_id' inf_le_left) tendsto_const_nhds)), by simp [Sup_image, -add_comm] at this; exact this.symm lemma supr_add {ι : Sort*} {s : ι → ennreal} [h : nonempty ι] : supr s + a = ⨆b, s b + a := let ⟨x⟩ := h in calc supr s + a = Sup (range s) + a : by simp [Sup_range] ... = (⨆b∈range s, b + a) : Sup_add ⟨s x, x, rfl⟩ ... = _ : supr_range lemma add_supr {ι : Sort*} {s : ι → ennreal} [h : nonempty ι] : a + supr s = ⨆b, a + s b := by rw [add_comm, supr_add]; simp [add_comm] lemma supr_add_supr {ι : Sort*} {f g : ι → ennreal} (h : ∀i j, ∃k, f i + g j ≤ f k + g k) : supr f + supr g = (⨆ a, f a + g a) := begin by_cases hι : nonempty ι, { letI := hι, refine le_antisymm _ (supr_le $ λ a, add_le_add (le_supr _ _) (le_supr _ _)), simpa [add_supr, supr_add] using λ i j:ι, show f i + g j ≤ ⨆ a, f a + g a, from let ⟨k, hk⟩ := h i j in le_supr_of_le k hk }, { have : ∀f:ι → ennreal, (⨆i, f i) = 0 := λ f, bot_unique (supr_le $ assume i, (hι ⟨i⟩).elim), rw [this, this, this, zero_add] } end lemma supr_add_supr_of_monotone {ι : Sort*} [semilattice_sup ι] {f g : ι → ennreal} (hf : monotone f) (hg : monotone g) : supr f + supr g = (⨆ a, f a + g a) := supr_add_supr $ assume i j, ⟨i ⊔ j, add_le_add (hf $ le_sup_left) (hg $ le_sup_right)⟩ lemma finset_sum_supr_nat {α} {ι} [semilattice_sup ι] {s : finset α} {f : α → ι → ennreal} (hf : ∀a, monotone (f a)) : ∑ a in s, supr (f a) = (⨆ n, ∑ a in s, f a n) := begin refine finset.induction_on s _ _, { simp, exact (bot_unique $ supr_le $ assume i, le_refl ⊥).symm }, { assume a s has ih, simp only [finset.sum_insert has], rw [ih, supr_add_supr_of_monotone (hf a)], assume i j h, exact (finset.sum_le_sum $ assume a ha, hf a h) } end lemma mul_Sup {s : set ennreal} {a : ennreal} : a * Sup s = ⨆i∈s, a * i := begin by_cases hs : ∀x∈s, x = (0:ennreal), { have h₁ : Sup s = 0 := (bot_unique $ Sup_le $ assume a ha, (hs a ha).symm ▸ le_refl 0), have h₂ : (⨆i ∈ s, a * i) = 0 := (bot_unique $ supr_le $ assume a, supr_le $ assume ha, by simp [hs a ha]), rw [h₁, h₂, mul_zero] }, { simp only [not_forall] at hs, rcases hs with ⟨x, hx, hx0⟩, have s₁ : Sup s ≠ 0 := pos_iff_ne_zero.1 (lt_of_lt_of_le (pos_iff_ne_zero.2 hx0) (le_Sup hx)), have : Sup ((λb, a * b) '' s) = a * Sup s := is_lub.Sup_eq (is_lub_of_is_lub_of_tendsto (assume x _ y _ h, canonically_ordered_semiring.mul_le_mul (le_refl _) h) (is_lub_Sup _) ⟨x, hx⟩ (ennreal.tendsto.const_mul (tendsto_id' inf_le_left) (or.inl s₁))), rw [this.symm, Sup_image] } end lemma mul_supr {ι : Sort*} {f : ι → ennreal} {a : ennreal} : a * supr f = ⨆i, a * f i := by rw [← Sup_range, mul_Sup, supr_range] lemma supr_mul {ι : Sort*} {f : ι → ennreal} {a : ennreal} : supr f * a = ⨆i, f i * a := by rw [mul_comm, mul_supr]; congr; funext; rw [mul_comm] protected lemma tendsto_coe_sub : ∀{b:ennreal}, tendsto (λb:ennreal, ↑r - b) (𝓝 b) (𝓝 (↑r - b)) := begin refine (forall_ennreal.2 $ and.intro (assume a, _) _), { simp [@nhds_coe a, tendsto_map'_iff, (∘), tendsto_coe, coe_sub.symm], exact tendsto_const_nhds.sub tendsto_id }, simp, exact (tendsto.congr' (mem_sets_of_superset (lt_mem_nhds $ @coe_lt_top r) $ by simp [le_of_lt] {contextual := tt})) tendsto_const_nhds end lemma sub_supr {ι : Sort*} [hι : nonempty ι] {b : ι → ennreal} (hr : a < ⊤) : a - (⨆i, b i) = (⨅i, a - b i) := let ⟨i⟩ := hι in let ⟨r, eq, _⟩ := lt_iff_exists_coe.mp hr in have Inf ((λb, ↑r - b) '' range b) = ↑r - (⨆i, b i), from is_glb.Inf_eq $ is_glb_of_is_lub_of_tendsto (assume x _ y _, sub_le_sub (le_refl _)) is_lub_supr ⟨_, i, rfl⟩ (tendsto.comp ennreal.tendsto_coe_sub (tendsto_id' inf_le_left)), by rw [eq, ←this]; simp [Inf_image, infi_range, -mem_range]; exact le_refl _ lemma supr_eq_zero {ι : Sort*} {f : ι → ennreal} : (⨆ i, f i) = 0 ↔ ∀ i, f i = 0 := by simp_rw [← nonpos_iff_eq_zero, supr_le_iff] end topological_space section tsum variables {f g : α → ennreal} @[norm_cast] protected lemma has_sum_coe {f : α → ℝ≥0} {r : ℝ≥0} : has_sum (λa, (f a : ennreal)) ↑r ↔ has_sum f r := have (λs:finset α, ∑ a in s, ↑(f a)) = (coe : ℝ≥0 → ennreal) ∘ (λs:finset α, ∑ a in s, f a), from funext $ assume s, ennreal.coe_finset_sum.symm, by unfold has_sum; rw [this, tendsto_coe] protected lemma tsum_coe_eq {f : α → ℝ≥0} (h : has_sum f r) : (∑'a, (f a : ennreal)) = r := (ennreal.has_sum_coe.2 h).tsum_eq protected lemma coe_tsum {f : α → ℝ≥0} : summable f → ↑(tsum f) = (∑'a, (f a : ennreal)) | ⟨r, hr⟩ := by rw [hr.tsum_eq, ennreal.tsum_coe_eq hr] protected lemma has_sum : has_sum f (⨆s:finset α, ∑ a in s, f a) := tendsto_order.2 ⟨assume a' ha', let ⟨s, hs⟩ := lt_supr_iff.mp ha' in mem_at_top_sets.mpr ⟨s, assume t ht, lt_of_lt_of_le hs $ finset.sum_le_sum_of_subset ht⟩, assume a' ha', univ_mem_sets' $ assume s, have ∑ a in s, f a ≤ ⨆(s : finset α), ∑ a in s, f a, from le_supr (λ(s : finset α), ∑ a in s, f a) s, lt_of_le_of_lt this ha'⟩ @[simp] protected lemma summable : summable f := ⟨_, ennreal.has_sum⟩ lemma tsum_coe_ne_top_iff_summable {f : β → ℝ≥0} : (∑' b, (f b:ennreal)) ≠ ∞ ↔ summable f := begin refine ⟨λ h, _, λ h, ennreal.coe_tsum h ▸ ennreal.coe_ne_top⟩, lift (∑' b, (f b:ennreal)) to ℝ≥0 using h with a ha, refine ⟨a, ennreal.has_sum_coe.1 _⟩, rw ha, exact ennreal.summable.has_sum end protected lemma tsum_eq_supr_sum : (∑'a, f a) = (⨆s:finset α, ∑ a in s, f a) := ennreal.has_sum.tsum_eq protected lemma tsum_eq_supr_sum' {ι : Type*} (s : ι → finset α) (hs : ∀ t, ∃ i, t ⊆ s i) : (∑' a, f a) = ⨆ i, ∑ a in s i, f a := begin rw [ennreal.tsum_eq_supr_sum], symmetry, change (⨆i:ι, (λ t : finset α, ∑ a in t, f a) (s i)) = ⨆s:finset α, ∑ a in s, f a, exact (finset.sum_mono_set f).supr_comp_eq hs end protected lemma tsum_sigma {β : α → Type*} (f : Πa, β a → ennreal) : (∑'p:Σa, β a, f p.1 p.2) = (∑'a b, f a b) := tsum_sigma' (assume b, ennreal.summable) ennreal.summable protected lemma tsum_sigma' {β : α → Type*} (f : (Σ a, β a) → ennreal) : (∑'p:(Σa, β a), f p) = (∑'a b, f ⟨a, b⟩) := tsum_sigma' (assume b, ennreal.summable) ennreal.summable protected lemma tsum_prod {f : α → β → ennreal} : (∑'p:α×β, f p.1 p.2) = (∑'a, ∑'b, f a b) := tsum_prod' ennreal.summable $ λ _, ennreal.summable protected lemma tsum_comm {f : α → β → ennreal} : (∑'a, ∑'b, f a b) = (∑'b, ∑'a, f a b) := tsum_comm' ennreal.summable (λ _, ennreal.summable) (λ _, ennreal.summable) protected lemma tsum_add : (∑'a, f a + g a) = (∑'a, f a) + (∑'a, g a) := tsum_add ennreal.summable ennreal.summable protected lemma tsum_le_tsum (h : ∀a, f a ≤ g a) : (∑'a, f a) ≤ (∑'a, g a) := tsum_le_tsum h ennreal.summable ennreal.summable protected lemma sum_le_tsum {f : α → ennreal} (s : finset α) : ∑ x in s, f x ≤ ∑' x, f x := sum_le_tsum s (λ x hx, zero_le _) ennreal.summable protected lemma tsum_eq_supr_nat' {f : ℕ → ennreal} {N : ℕ → ℕ} (hN : tendsto N at_top at_top) : (∑'i:ℕ, f i) = (⨆i:ℕ, ∑ a in finset.range (N i), f a) := ennreal.tsum_eq_supr_sum' _ $ λ t, let ⟨n, hn⟩ := t.exists_nat_subset_range, ⟨k, _, hk⟩ := exists_le_of_tendsto_at_top hN 0 n in ⟨k, finset.subset.trans hn (finset.range_mono hk)⟩ protected lemma tsum_eq_supr_nat {f : ℕ → ennreal} : (∑'i:ℕ, f i) = (⨆i:ℕ, ∑ a in finset.range i, f a) := ennreal.tsum_eq_supr_sum' _ finset.exists_nat_subset_range protected lemma le_tsum (a : α) : f a ≤ (∑'a, f a) := le_tsum' ennreal.summable a protected lemma tsum_eq_top_of_eq_top : (∃ a, f a = ∞) → (∑' a, f a) = ∞ | ⟨a, ha⟩ := top_unique $ ha ▸ ennreal.le_tsum a protected lemma ne_top_of_tsum_ne_top (h : (∑' a, f a) ≠ ∞) (a : α) : f a ≠ ∞ := λ ha, h $ ennreal.tsum_eq_top_of_eq_top ⟨a, ha⟩ protected lemma tsum_mul_left : (∑'i, a * f i) = a * (∑'i, f i) := if h : ∀i, f i = 0 then by simp [h] else let ⟨i, (hi : f i ≠ 0)⟩ := not_forall.mp h in have sum_ne_0 : (∑'i, f i) ≠ 0, from ne_of_gt $ calc 0 < f i : lt_of_le_of_ne (zero_le _) hi.symm ... ≤ (∑'i, f i) : ennreal.le_tsum _, have tendsto (λs:finset α, ∑ j in s, a * f j) at_top (𝓝 (a * (∑'i, f i))), by rw [← show (*) a ∘ (λs:finset α, ∑ j in s, f j) = λs, ∑ j in s, a * f j, from funext $ λ s, finset.mul_sum]; exact ennreal.tendsto.const_mul ennreal.summable.has_sum (or.inl sum_ne_0), has_sum.tsum_eq this protected lemma tsum_mul_right : (∑'i, f i * a) = (∑'i, f i) * a := by simp [mul_comm, ennreal.tsum_mul_left] @[simp] lemma tsum_supr_eq {α : Type*} (a : α) {f : α → ennreal} : (∑'b:α, ⨆ (h : a = b), f b) = f a := le_antisymm (by rw [ennreal.tsum_eq_supr_sum]; exact supr_le (assume s, calc (∑ b in s, ⨆ (h : a = b), f b) ≤ ∑ b in {a}, ⨆ (h : a = b), f b : finset.sum_le_sum_of_ne_zero $ assume b _ hb, suffices a = b, by simpa using this.symm, classical.by_contradiction $ assume h, by simpa [h] using hb ... = f a : by simp)) (calc f a ≤ (⨆ (h : a = a), f a) : le_supr (λh:a=a, f a) rfl ... ≤ (∑'b:α, ⨆ (h : a = b), f b) : ennreal.le_tsum _) lemma has_sum_iff_tendsto_nat {f : ℕ → ennreal} (r : ennreal) : has_sum f r ↔ tendsto (λn:ℕ, ∑ i in finset.range n, f i) at_top (𝓝 r) := begin refine ⟨has_sum.tendsto_sum_nat, assume h, _⟩, rw [← supr_eq_of_tendsto _ h, ← ennreal.tsum_eq_supr_nat], { exact ennreal.summable.has_sum }, { exact assume s t hst, finset.sum_le_sum_of_subset (finset.range_subset.2 hst) } end lemma to_nnreal_apply_of_tsum_ne_top {α : Type*} {f : α → ennreal} (hf : (∑' i, f i) ≠ ∞) (x : α) : (((ennreal.to_nnreal ∘ f) x : ℝ≥0) : ennreal) = f x := coe_to_nnreal $ ennreal.ne_top_of_tsum_ne_top hf _ lemma summable_to_nnreal_of_tsum_ne_top {α : Type*} {f : α → ennreal} (hf : (∑' i, f i) ≠ ∞) : summable (ennreal.to_nnreal ∘ f) := by simpa only [←tsum_coe_ne_top_iff_summable, to_nnreal_apply_of_tsum_ne_top hf] using hf protected lemma tsum_apply {ι α : Type*} {f : ι → α → ennreal} {x : α} : (∑' i, f i) x = ∑' i, f i x := tsum_apply $ pi.summable.mpr $ λ _, ennreal.summable lemma tsum_sub {f : ℕ → ennreal} {g : ℕ → ennreal} (h₁ : (∑' i, g i) < ∞) (h₂ : g ≤ f) : (∑' i, (f i - g i)) = (∑' i, f i) - (∑' i, g i) := begin have h₃:(∑' i, (f i - g i)) = (∑' i, (f i - g i) + (g i))-(∑' i, g i), { rw [ennreal.tsum_add, add_sub_self h₁]}, have h₄:(λ i, (f i - g i) + (g i)) = f, { ext n, rw ennreal.sub_add_cancel_of_le (h₂ n)}, rw h₄ at h₃, apply h₃, end end tsum end ennreal namespace nnreal open_locale nnreal /-- Comparison test of convergence of `ℝ≥0`-valued series. -/ lemma exists_le_has_sum_of_le {f g : β → ℝ≥0} {r : ℝ≥0} (hgf : ∀b, g b ≤ f b) (hfr : has_sum f r) : ∃p≤r, has_sum g p := have (∑'b, (g b : ennreal)) ≤ r, begin refine has_sum_le (assume b, _) ennreal.summable.has_sum (ennreal.has_sum_coe.2 hfr), exact ennreal.coe_le_coe.2 (hgf _) end, let ⟨p, eq, hpr⟩ := ennreal.le_coe_iff.1 this in ⟨p, hpr, ennreal.has_sum_coe.1 $ eq ▸ ennreal.summable.has_sum⟩ /-- Comparison test of convergence of `ℝ≥0`-valued series. -/ lemma summable_of_le {f g : β → ℝ≥0} (hgf : ∀b, g b ≤ f b) : summable f → summable g | ⟨r, hfr⟩ := let ⟨p, _, hp⟩ := exists_le_has_sum_of_le hgf hfr in hp.summable /-- A series of non-negative real numbers converges to `r` in the sense of `has_sum` if and only if the sequence of partial sum converges to `r`. -/ lemma has_sum_iff_tendsto_nat {f : ℕ → ℝ≥0} {r : ℝ≥0} : has_sum f r ↔ tendsto (λn:ℕ, ∑ i in finset.range n, f i) at_top (𝓝 r) := begin rw [← ennreal.has_sum_coe, ennreal.has_sum_iff_tendsto_nat], simp only [ennreal.coe_finset_sum.symm], exact ennreal.tendsto_coe end lemma not_summable_iff_tendsto_nat_at_top {f : ℕ → ℝ≥0} : ¬ summable f ↔ tendsto (λ n : ℕ, ∑ i in finset.range n, f i) at_top at_top := begin split, { intros h, refine ((tendsto_of_monotone _).resolve_right h).comp _, exacts [finset.sum_mono_set _, tendsto_finset_range] }, { rintros hnat ⟨r, hr⟩, exact not_tendsto_nhds_of_tendsto_at_top hnat _ (has_sum_iff_tendsto_nat.1 hr) } end lemma summable_iff_not_tendsto_nat_at_top {f : ℕ → ℝ≥0} : summable f ↔ ¬ tendsto (λ n : ℕ, ∑ i in finset.range n, f i) at_top at_top := by rw [← not_iff_not, not_not, not_summable_iff_tendsto_nat_at_top] lemma summable_of_sum_range_le {f : ℕ → ℝ≥0} {c : ℝ≥0} (h : ∀ n, ∑ i in finset.range n, f i ≤ c) : summable f := begin apply summable_iff_not_tendsto_nat_at_top.2 (λ H, _), rcases exists_lt_of_tendsto_at_top H 0 c with ⟨n, -, hn⟩, exact lt_irrefl _ (hn.trans_le (h n)), end lemma tsum_le_of_sum_range_le {f : ℕ → ℝ≥0} {c : ℝ≥0} (h : ∀ n, ∑ i in finset.range n, f i ≤ c) : (∑' n, f n) ≤ c := le_of_tendsto' (has_sum_iff_tendsto_nat.1 (summable_of_sum_range_le h).has_sum) h lemma tsum_comp_le_tsum_of_inj {β : Type*} {f : α → ℝ≥0} (hf : summable f) {i : β → α} (hi : function.injective i) : (∑' x, f (i x)) ≤ ∑' x, f x := tsum_le_tsum_of_inj i hi (λ c hc, zero_le _) (λ b, le_refl _) (summable_comp_injective hf hi) hf lemma summable_sigma {β : Π x : α, Type*} {f : (Σ x, β x) → ℝ≥0} : summable f ↔ (∀ x, summable (λ y, f ⟨x, y⟩)) ∧ summable (λ x, ∑' y, f ⟨x, y⟩) := begin split, { simp only [← nnreal.summable_coe, nnreal.coe_tsum], exact λ h, ⟨h.sigma_factor, h.sigma⟩ }, { rintro ⟨h₁, h₂⟩, simpa only [← ennreal.tsum_coe_ne_top_iff_summable, ennreal.tsum_sigma', ennreal.coe_tsum, h₁] using h₂ } end open finset /-- For `f : ℕ → ℝ≥0`, then `∑' k, f (k + i)` tends to zero. This does not require a summability assumption on `f`, as otherwise all sums are zero. -/ lemma tendsto_sum_nat_add (f : ℕ → ℝ≥0) : tendsto (λ i, ∑' k, f (k + i)) at_top (𝓝 0) := begin rw ← tendsto_coe, convert tendsto_sum_nat_add (λ i, (f i : ℝ)), norm_cast, end end nnreal namespace ennreal lemma tendsto_sum_nat_add (f : ℕ → ennreal) (hf : (∑' i, f i) ≠ ∞) : tendsto (λ i, ∑' k, f (k + i)) at_top (𝓝 0) := begin have : ∀ i, (∑' k, (((ennreal.to_nnreal ∘ f) (k + i) : ℝ≥0) : ennreal)) = (∑' k, (ennreal.to_nnreal ∘ f) (k + i) : ℝ≥0) := λ i, (ennreal.coe_tsum (nnreal.summable_nat_add _ (summable_to_nnreal_of_tsum_ne_top hf) _)).symm, simp only [λ x, (to_nnreal_apply_of_tsum_ne_top hf x).symm, ←ennreal.coe_zero, this, ennreal.tendsto_coe] { single_pass := tt }, exact nnreal.tendsto_sum_nat_add _ end end ennreal lemma tsum_comp_le_tsum_of_inj {β : Type*} {f : α → ℝ} (hf : summable f) (hn : ∀ a, 0 ≤ f a) {i : β → α} (hi : function.injective i) : tsum (f ∘ i) ≤ tsum f := begin let g : α → ℝ≥0 := λ a, ⟨f a, hn a⟩, have hg : summable g, by rwa ← nnreal.summable_coe, convert nnreal.coe_le_coe.2 (nnreal.tsum_comp_le_tsum_of_inj hg hi); { rw nnreal.coe_tsum, congr } end /-- Comparison test of convergence of series of non-negative real numbers. -/ lemma summable_of_nonneg_of_le {f g : β → ℝ} (hg : ∀b, 0 ≤ g b) (hgf : ∀b, g b ≤ f b) (hf : summable f) : summable g := let f' (b : β) : ℝ≥0 := ⟨f b, le_trans (hg b) (hgf b)⟩ in let g' (b : β) : ℝ≥0 := ⟨g b, hg b⟩ in have summable f', from nnreal.summable_coe.1 hf, have summable g', from nnreal.summable_of_le (assume b, (@nnreal.coe_le_coe (g' b) (f' b)).2 $ hgf b) this, show summable (λb, g' b : β → ℝ), from nnreal.summable_coe.2 this /-- A series of non-negative real numbers converges to `r` in the sense of `has_sum` if and only if the sequence of partial sum converges to `r`. -/ lemma has_sum_iff_tendsto_nat_of_nonneg {f : ℕ → ℝ} (hf : ∀i, 0 ≤ f i) (r : ℝ) : has_sum f r ↔ tendsto (λ n : ℕ, ∑ i in finset.range n, f i) at_top (𝓝 r) := begin lift f to ℕ → ℝ≥0 using hf, simp only [has_sum, ← nnreal.coe_sum, nnreal.tendsto_coe'], exact exists_congr (λ hr, nnreal.has_sum_iff_tendsto_nat) end lemma not_summable_iff_tendsto_nat_at_top_of_nonneg {f : ℕ → ℝ} (hf : ∀ n, 0 ≤ f n) : ¬ summable f ↔ tendsto (λ n : ℕ, ∑ i in finset.range n, f i) at_top at_top := begin lift f to ℕ → ℝ≥0 using hf, exact_mod_cast nnreal.not_summable_iff_tendsto_nat_at_top end lemma summable_iff_not_tendsto_nat_at_top_of_nonneg {f : ℕ → ℝ} (hf : ∀ n, 0 ≤ f n) : summable f ↔ ¬ tendsto (λ n : ℕ, ∑ i in finset.range n, f i) at_top at_top := by rw [← not_iff_not, not_not, not_summable_iff_tendsto_nat_at_top_of_nonneg hf] lemma summable_sigma_of_nonneg {β : Π x : α, Type*} {f : (Σ x, β x) → ℝ} (hf : ∀ x, 0 ≤ f x) : summable f ↔ (∀ x, summable (λ y, f ⟨x, y⟩)) ∧ summable (λ x, ∑' y, f ⟨x, y⟩) := by { lift f to (Σ x, β x) → ℝ≥0 using hf, exact_mod_cast nnreal.summable_sigma } lemma summable_of_sum_range_le {f : ℕ → ℝ} {c : ℝ} (hf : ∀ n, 0 ≤ f n) (h : ∀ n, ∑ i in finset.range n, f i ≤ c) : summable f := begin apply (summable_iff_not_tendsto_nat_at_top_of_nonneg hf).2 (λ H, _), rcases exists_lt_of_tendsto_at_top H 0 c with ⟨n, -, hn⟩, exact lt_irrefl _ (hn.trans_le (h n)), end lemma tsum_le_of_sum_range_le {f : ℕ → ℝ} {c : ℝ} (hf : ∀ n, 0 ≤ f n) (h : ∀ n, ∑ i in finset.range n, f i ≤ c) : (∑' n, f n) ≤ c := le_of_tendsto' ((has_sum_iff_tendsto_nat_of_nonneg hf _).1 (summable_of_sum_range_le hf h).has_sum) h section variables [emetric_space β] open ennreal filter emetric /-- In an emetric ball, the distance between points is everywhere finite -/ lemma edist_ne_top_of_mem_ball {a : β} {r : ennreal} (x y : ball a r) : edist x.1 y.1 ≠ ⊤ := lt_top_iff_ne_top.1 $ calc edist x y ≤ edist a x + edist a y : edist_triangle_left x.1 y.1 a ... < r + r : by rw [edist_comm a x, edist_comm a y]; exact add_lt_add x.2 y.2 ... ≤ ⊤ : le_top /-- Each ball in an extended metric space gives us a metric space, as the edist is everywhere finite. -/ def metric_space_emetric_ball (a : β) (r : ennreal) : metric_space (ball a r) := emetric_space.to_metric_space edist_ne_top_of_mem_ball local attribute [instance] metric_space_emetric_ball lemma nhds_eq_nhds_emetric_ball (a x : β) (r : ennreal) (h : x ∈ ball a r) : 𝓝 x = map (coe : ball a r → β) (𝓝 ⟨x, h⟩) := (map_nhds_subtype_coe_eq _ $ mem_nhds_sets emetric.is_open_ball h).symm end section variable [emetric_space α] open emetric lemma tendsto_iff_edist_tendsto_0 {l : filter β} {f : β → α} {y : α} : tendsto f l (𝓝 y) ↔ tendsto (λ x, edist (f x) y) l (𝓝 0) := by simp only [emetric.nhds_basis_eball.tendsto_right_iff, emetric.mem_ball, @tendsto_order ennreal β _ _, forall_prop_of_false ennreal.not_lt_zero, forall_const, true_and] /-- Yet another metric characterization of Cauchy sequences on integers. This one is often the most efficient. -/ lemma emetric.cauchy_seq_iff_le_tendsto_0 [nonempty β] [semilattice_sup β] {s : β → α} : cauchy_seq s ↔ (∃ (b: β → ennreal), (∀ n m N : β, N ≤ n → N ≤ m → edist (s n) (s m) ≤ b N) ∧ (tendsto b at_top (𝓝 0))) := ⟨begin assume hs, rw emetric.cauchy_seq_iff at hs, /- `s` is Cauchy sequence. The sequence `b` will be constructed by taking the supremum of the distances between `s n` and `s m` for `n m ≥ N`-/ let b := λN, Sup ((λ(p : β × β), edist (s p.1) (s p.2))''{p | p.1 ≥ N ∧ p.2 ≥ N}), --Prove that it bounds the distances of points in the Cauchy sequence have C : ∀ n m N, N ≤ n → N ≤ m → edist (s n) (s m) ≤ b N, { refine λm n N hm hn, le_Sup _, use (prod.mk m n), simp only [and_true, eq_self_iff_true, set.mem_set_of_eq], exact ⟨hm, hn⟩ }, --Prove that it tends to `0`, by using the Cauchy property of `s` have D : tendsto b at_top (𝓝 0), { refine tendsto_order.2 ⟨λa ha, absurd ha (ennreal.not_lt_zero), λε εpos, _⟩, rcases exists_between εpos with ⟨δ, δpos, δlt⟩, rcases hs δ δpos with ⟨N, hN⟩, refine filter.mem_at_top_sets.2 ⟨N, λn hn, _⟩, have : b n ≤ δ := Sup_le begin simp only [and_imp, set.mem_image, set.mem_set_of_eq, exists_imp_distrib, prod.exists], intros d p q hp hq hd, rw ← hd, exact le_of_lt (hN p q (le_trans hn hp) (le_trans hn hq)) end, simpa using lt_of_le_of_lt this δlt }, -- Conclude exact ⟨b, ⟨C, D⟩⟩ end, begin rintros ⟨b, ⟨b_bound, b_lim⟩⟩, /-b : ℕ → ℝ, b_bound : ∀ (n m N : ℕ), N ≤ n → N ≤ m → edist (s n) (s m) ≤ b N, b_lim : tendsto b at_top (𝓝 0)-/ refine emetric.cauchy_seq_iff.2 (λε εpos, _), have : ∀ᶠ n in at_top, b n < ε := (tendsto_order.1 b_lim ).2 _ εpos, rcases filter.mem_at_top_sets.1 this with ⟨N, hN⟩, exact ⟨N, λm n hm hn, calc edist (s m) (s n) ≤ b N : b_bound m n N hm hn ... < ε : (hN _ (le_refl N)) ⟩ end⟩ lemma continuous_of_le_add_edist {f : α → ennreal} (C : ennreal) (hC : C ≠ ⊤) (h : ∀x y, f x ≤ f y + C * edist x y) : continuous f := begin refine continuous_iff_continuous_at.2 (λx, tendsto_order.2 ⟨_, _⟩), show ∀e, e < f x → ∀ᶠ y in 𝓝 x, e < f y, { assume e he, let ε := min (f x - e) 1, have : ε < ⊤ := lt_of_le_of_lt (min_le_right _ _) (by simp [lt_top_iff_ne_top]), have : 0 < ε := by simp [ε, hC, he, ennreal.zero_lt_one], have : 0 < C⁻¹ * (ε/2) := bot_lt_iff_ne_bot.2 (by simp [hC, (ne_of_lt this).symm, mul_eq_zero]), have I : C * (C⁻¹ * (ε/2)) < ε, { by_cases C_zero : C = 0, { simp [C_zero, ‹0 < ε›] }, { calc C * (C⁻¹ * (ε/2)) = (C * C⁻¹) * (ε/2) : by simp [mul_assoc] ... = ε/2 : by simp [ennreal.mul_inv_cancel C_zero hC] ... < ε : ennreal.half_lt_self (‹0 < ε›.ne') (‹ε < ⊤›.ne) }}, have : ball x (C⁻¹ * (ε/2)) ⊆ {y : α | e < f y}, { rintros y hy, by_cases htop : f y = ⊤, { simp [htop, lt_top_iff_ne_top, ne_top_of_lt he] }, { simp at hy, have : e + ε < f y + ε := calc e + ε ≤ e + (f x - e) : add_le_add_left (min_le_left _ _) _ ... = f x : by simp [le_of_lt he] ... ≤ f y + C * edist x y : h x y ... = f y + C * edist y x : by simp [edist_comm] ... ≤ f y + C * (C⁻¹ * (ε/2)) : add_le_add_left (canonically_ordered_semiring.mul_le_mul (le_refl _) (le_of_lt hy)) _ ... < f y + ε : (ennreal.add_lt_add_iff_left (lt_top_iff_ne_top.2 htop)).2 I, show e < f y, from (ennreal.add_lt_add_iff_right ‹ε < ⊤›).1 this }}, apply filter.mem_sets_of_superset (ball_mem_nhds _ (‹0 < C⁻¹ * (ε/2)›)) this }, show ∀e, f x < e → ∀ᶠ y in 𝓝 x, f y < e, { assume e he, let ε := min (e - f x) 1, have : ε < ⊤ := lt_of_le_of_lt (min_le_right _ _) (by simp [lt_top_iff_ne_top]), have : 0 < ε := by simp [ε, he, ennreal.zero_lt_one], have : 0 < C⁻¹ * (ε/2) := bot_lt_iff_ne_bot.2 (by simp [hC, (ne_of_lt this).symm, mul_eq_zero]), have I : C * (C⁻¹ * (ε/2)) < ε, { by_cases C_zero : C = 0, simp [C_zero, ‹0 < ε›], calc C * (C⁻¹ * (ε/2)) = (C * C⁻¹) * (ε/2) : by simp [mul_assoc] ... = ε/2 : by simp [ennreal.mul_inv_cancel C_zero hC] ... < ε : ennreal.half_lt_self (‹0 < ε›.ne') (‹ε < ⊤›.ne) }, have : ball x (C⁻¹ * (ε/2)) ⊆ {y : α | f y < e}, { rintros y hy, have htop : f x ≠ ⊤ := ne_top_of_lt he, show f y < e, from calc f y ≤ f x + C * edist y x : h y x ... ≤ f x + C * (C⁻¹ * (ε/2)) : add_le_add_left (canonically_ordered_semiring.mul_le_mul (le_refl _) (le_of_lt hy)) _ ... < f x + ε : (ennreal.add_lt_add_iff_left (lt_top_iff_ne_top.2 htop)).2 I ... ≤ f x + (e - f x) : add_le_add_left (min_le_left _ _) _ ... = e : by simp [le_of_lt he] }, apply filter.mem_sets_of_superset (ball_mem_nhds _ (‹0 < C⁻¹ * (ε/2)›)) this }, end theorem continuous_edist : continuous (λp:α×α, edist p.1 p.2) := begin apply continuous_of_le_add_edist 2 (by norm_num), rintros ⟨x, y⟩ ⟨x', y'⟩, calc edist x y ≤ edist x x' + edist x' y' + edist y' y : edist_triangle4 _ _ _ _ ... = edist x' y' + (edist x x' + edist y y') : by simp [edist_comm]; cc ... ≤ edist x' y' + (edist (x, y) (x', y') + edist (x, y) (x', y')) : add_le_add_left (add_le_add (le_max_left _ _) (le_max_right _ _)) _ ... = edist x' y' + 2 * edist (x, y) (x', y') : by rw [← mul_two, mul_comm] end theorem continuous.edist [topological_space β] {f g : β → α} (hf : continuous f) (hg : continuous g) : continuous (λb, edist (f b) (g b)) := continuous_edist.comp (hf.prod_mk hg : _) theorem filter.tendsto.edist {f g : β → α} {x : filter β} {a b : α} (hf : tendsto f x (𝓝 a)) (hg : tendsto g x (𝓝 b)) : tendsto (λx, edist (f x) (g x)) x (𝓝 (edist a b)) := (continuous_edist.tendsto (a, b)).comp (hf.prod_mk_nhds hg) lemma cauchy_seq_of_edist_le_of_tsum_ne_top {f : ℕ → α} (d : ℕ → ennreal) (hf : ∀ n, edist (f n) (f n.succ) ≤ d n) (hd : tsum d ≠ ∞) : cauchy_seq f := begin lift d to (ℕ → nnreal) using (λ i, ennreal.ne_top_of_tsum_ne_top hd i), rw ennreal.tsum_coe_ne_top_iff_summable at hd, exact cauchy_seq_of_edist_le_of_summable d hf hd end lemma emetric.is_closed_ball {a : α} {r : ennreal} : is_closed (closed_ball a r) := is_closed_le (continuous_id.edist continuous_const) continuous_const /-- If `edist (f n) (f (n+1))` is bounded above by a function `d : ℕ → ennreal`, then the distance from `f n` to the limit is bounded by `∑'_{k=n}^∞ d k`. -/ lemma edist_le_tsum_of_edist_le_of_tendsto {f : ℕ → α} (d : ℕ → ennreal) (hf : ∀ n, edist (f n) (f n.succ) ≤ d n) {a : α} (ha : tendsto f at_top (𝓝 a)) (n : ℕ) : edist (f n) a ≤ ∑' m, d (n + m) := begin refine le_of_tendsto (tendsto_const_nhds.edist ha) (mem_at_top_sets.2 ⟨n, λ m hnm, _⟩), refine le_trans (edist_le_Ico_sum_of_edist_le hnm (λ k _ _, hf k)) _, rw [finset.sum_Ico_eq_sum_range], exact sum_le_tsum _ (λ _ _, zero_le _) ennreal.summable end /-- If `edist (f n) (f (n+1))` is bounded above by a function `d : ℕ → ennreal`, then the distance from `f 0` to the limit is bounded by `∑'_{k=0}^∞ d k`. -/ lemma edist_le_tsum_of_edist_le_of_tendsto₀ {f : ℕ → α} (d : ℕ → ennreal) (hf : ∀ n, edist (f n) (f n.succ) ≤ d n) {a : α} (ha : tendsto f at_top (𝓝 a)) : edist (f 0) a ≤ ∑' m, d m := by simpa using edist_le_tsum_of_edist_le_of_tendsto d hf ha 0 end --section
8a4ce1a444fdf0ac917d00de65adbee44087ee6d
d406927ab5617694ec9ea7001f101b7c9e3d9702
/src/algebra/category/Module/basic.lean
ddd4a0f5691c101f0a4c7fc176bf6ca6f3add4d9
[ "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
11,072
lean
/- Copyright (c) 2019 Robert A. Spencer. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Robert A. Spencer, Markus Himmel -/ import algebra.category.Group.preadditive import category_theory.linear.basic import category_theory.elementwise import linear_algebra.basic import category_theory.conj import category_theory.preadditive.additive_functor /-! # The category of `R`-modules `Module.{v} R` is the category of bundled `R`-modules with carrier in the universe `v`. We show that it is preadditive and show that being an isomorphism, monomorphism and epimorphism is equivalent to being a linear equivalence, an injective linear map and a surjective linear map, respectively. ## Implementation details To construct an object in the category of `R`-modules from a type `M` with an instance of the `module` typeclass, write `of R M`. There is a coercion in the other direction. Similarly, there is a coercion from morphisms in `Module R` to linear maps. Unfortunately, Lean is not smart enough to see that, given an object `M : Module R`, the expression `of R M`, where we coerce `M` to the carrier type, is definitionally equal to `M` itself. This means that to go the other direction, i.e., from linear maps/equivalences to (iso)morphisms in the category of `R`-modules, we have to take care not to inadvertently end up with an `of R M` where `M` is already an object. Hence, given `f : M →ₗ[R] N`, * if `M N : Module R`, simply use `f`; * if `M : Module R` and `N` is an unbundled `R`-module, use `↿f` or `as_hom_left f`; * if `M` is an unbundled `R`-module and `N : Module R`, use `↾f` or `as_hom_right f`; * if `M` and `N` are unbundled `R`-modules, use `↟f` or `as_hom f`. Similarly, given `f : M ≃ₗ[R] N`, use `to_Module_iso`, `to_Module_iso'_left`, `to_Module_iso'_right` or `to_Module_iso'`, respectively. The arrow notations are localized, so you may have to `open_locale Module` to use them. Note that the notation for `as_hom_left` clashes with the notation used to promote functions between types to morphisms in the category `Type`, so to avoid confusion, it is probably a good idea to avoid having the locales `Module` and `category_theory.Type` open at the same time. If you get an error when trying to apply a theorem and the `convert` tactic produces goals of the form `M = of R M`, then you probably used an incorrect variant of `as_hom` or `to_Module_iso`. -/ open category_theory open category_theory.limits open category_theory.limits.walking_parallel_pair universes v u variables (R : Type u) [ring R] /-- The category of R-modules and their morphisms. Note that in the case of `R = ℤ`, we can not impose here that the `ℤ`-multiplication field from the module structure is defeq to the one coming from the `is_add_comm_group` structure (contrary to what we do for all module structures in mathlib), which creates some difficulties down the road. -/ structure Module := (carrier : Type v) [is_add_comm_group : add_comm_group carrier] [is_module : module R carrier] attribute [instance] Module.is_add_comm_group Module.is_module namespace Module instance : has_coe_to_sort (Module.{v} R) (Type v) := ⟨Module.carrier⟩ instance Module_category : category (Module.{v} R) := { hom := λ M N, M →ₗ[R] N, id := λ M, 1, comp := λ A B C f g, g.comp f, id_comp' := λ X Y f, linear_map.id_comp _, comp_id' := λ X Y f, linear_map.comp_id _, assoc' := λ W X Y Z f g h, linear_map.comp_assoc _ _ _ } instance Module_concrete_category : concrete_category.{v} (Module.{v} R) := { forget := { obj := λ R, R, map := λ R S f, (f : R → S) }, forget_faithful := { } } instance has_forget_to_AddCommGroup : has_forget₂ (Module R) AddCommGroup := { forget₂ := { obj := λ M, AddCommGroup.of M, map := λ M₁ M₂ f, linear_map.to_add_monoid_hom f } } instance (M N : Module R) : linear_map_class (M ⟶ N) R M N := { coe := λ f, f, .. linear_map.semilinear_map_class } /-- The object in the category of R-modules associated to an R-module -/ def of (X : Type v) [add_comm_group X] [module R X] : Module R := ⟨X⟩ @[simp] lemma forget₂_obj (X : Module R) : (forget₂ (Module R) AddCommGroup).obj X = AddCommGroup.of X := rfl @[simp] lemma forget₂_obj_Module_of (X : Type v) [add_comm_group X] [module R X] : (forget₂ (Module R) AddCommGroup).obj (of R X) = AddCommGroup.of X := rfl @[simp] lemma forget₂_map (X Y : Module R) (f : X ⟶ Y) : (forget₂ (Module R) AddCommGroup).map f = linear_map.to_add_monoid_hom f := rfl /-- Typecheck a `linear_map` as a morphism in `Module R`. -/ def of_hom {R : Type u} [ring R] {X Y : Type v} [add_comm_group X] [module R X] [add_comm_group Y] [module R Y] (f : X →ₗ[R] Y) : of R X ⟶ of R Y := f @[simp] lemma of_hom_apply {R : Type u} [ring R] {X Y : Type v} [add_comm_group X] [module R X] [add_comm_group Y] [module R Y] (f : X →ₗ[R] Y) (x : X) : of_hom f x = f x := rfl instance : inhabited (Module R) := ⟨of R punit⟩ instance of_unique {X : Type v} [add_comm_group X] [module R X] [i : unique X] : unique (of R X) := i @[simp] lemma coe_of (X : Type v) [add_comm_group X] [module R X] : (of R X : Type v) = X := rfl variables {R} /-- Forgetting to the underlying type and then building the bundled object returns the original module. -/ @[simps] def of_self_iso (M : Module R) : Module.of R M ≅ M := { hom := 𝟙 M, inv := 𝟙 M } lemma is_zero_of_subsingleton (M : Module R) [subsingleton M] : is_zero M := begin refine ⟨λ X, ⟨⟨⟨0⟩, λ f, _⟩⟩, λ X, ⟨⟨⟨0⟩, λ f, _⟩⟩⟩, { ext, have : x = 0 := subsingleton.elim _ _, rw [this, map_zero, map_zero], }, { ext, apply subsingleton.elim } end instance : has_zero_object (Module.{v} R) := ⟨⟨of R punit, is_zero_of_subsingleton _⟩⟩ variables {R} {M N U : Module.{v} R} @[simp] lemma id_apply (m : M) : (𝟙 M : M → M) m = m := rfl @[simp] lemma coe_comp (f : M ⟶ N) (g : N ⟶ U) : ((f ≫ g) : M → U) = g ∘ f := rfl lemma comp_def (f : M ⟶ N) (g : N ⟶ U) : f ≫ g = g.comp f := rfl end Module variables {R} variables {X₁ X₂ : Type v} /-- Reinterpreting a linear map in the category of `R`-modules. -/ def Module.as_hom [add_comm_group X₁] [module R X₁] [add_comm_group X₂] [module R X₂] : (X₁ →ₗ[R] X₂) → (Module.of R X₁ ⟶ Module.of R X₂) := id localized "notation (name := Module.as_hom) `↟` f : 1024 := Module.as_hom f" in Module /-- Reinterpreting a linear map in the category of `R`-modules. -/ def Module.as_hom_right [add_comm_group X₁] [module R X₁] {X₂ : Module.{v} R} : (X₁ →ₗ[R] X₂) → (Module.of R X₁ ⟶ X₂) := id localized "notation (name := Module.as_hom_right) `↾` f : 1024 := Module.as_hom_right f" in Module /-- Reinterpreting a linear map in the category of `R`-modules. -/ def Module.as_hom_left {X₁ : Module.{v} R} [add_comm_group X₂] [module R X₂] : (X₁ →ₗ[R] X₂) → (X₁ ⟶ Module.of R X₂) := id localized "notation (name := Module.as_hom_left) `↿` f : 1024 := Module.as_hom_left f" in Module /-- Build an isomorphism in the category `Module R` from a `linear_equiv` between `module`s. -/ @[simps] def linear_equiv.to_Module_iso {g₁ : add_comm_group X₁} {g₂ : add_comm_group X₂} {m₁ : module R X₁} {m₂ : module R X₂} (e : X₁ ≃ₗ[R] X₂) : Module.of R X₁ ≅ Module.of R X₂ := { hom := (e : X₁ →ₗ[R] X₂), inv := (e.symm : X₂ →ₗ[R] X₁), hom_inv_id' := begin ext, exact e.left_inv x, end, inv_hom_id' := begin ext, exact e.right_inv x, end, } /-- Build an isomorphism in the category `Module R` from a `linear_equiv` between `module`s. This version is better than `linear_equiv_to_Module_iso` when applicable, because Lean can't see `Module.of R M` is defeq to `M` when `M : Module R`. -/ @[simps] def linear_equiv.to_Module_iso' {M N : Module.{v} R} (i : M ≃ₗ[R] N) : M ≅ N := { hom := i, inv := i.symm, hom_inv_id' := linear_map.ext $ λ x, by simp, inv_hom_id' := linear_map.ext $ λ x, by simp } /-- Build an isomorphism in the category `Module R` from a `linear_equiv` between `module`s. This version is better than `linear_equiv_to_Module_iso` when applicable, because Lean can't see `Module.of R M` is defeq to `M` when `M : Module R`. -/ @[simps] def linear_equiv.to_Module_iso'_left {X₁ : Module.{v} R} {g₂ : add_comm_group X₂} {m₂ : module R X₂} (e : X₁ ≃ₗ[R] X₂) : X₁ ≅ Module.of R X₂ := { hom := (e : X₁ →ₗ[R] X₂), inv := (e.symm : X₂ →ₗ[R] X₁), hom_inv_id' := linear_map.ext $ λ x, by simp, inv_hom_id' := linear_map.ext $ λ x, by simp } /-- Build an isomorphism in the category `Module R` from a `linear_equiv` between `module`s. This version is better than `linear_equiv_to_Module_iso` when applicable, because Lean can't see `Module.of R M` is defeq to `M` when `M : Module R`. -/ @[simps] def linear_equiv.to_Module_iso'_right {g₁ : add_comm_group X₁} {m₁ : module R X₁} {X₂ : Module.{v} R} (e : X₁ ≃ₗ[R] X₂) : Module.of R X₁ ≅ X₂ := { hom := (e : X₁ →ₗ[R] X₂), inv := (e.symm : X₂ →ₗ[R] X₁), hom_inv_id' := linear_map.ext $ λ x, by simp, inv_hom_id' := linear_map.ext $ λ x, by simp } namespace category_theory.iso /-- Build a `linear_equiv` from an isomorphism in the category `Module R`. -/ @[simps] def to_linear_equiv {X Y : Module R} (i : X ≅ Y) : X ≃ₗ[R] Y := { to_fun := i.hom, inv_fun := i.inv, left_inv := by tidy, right_inv := by tidy, map_add' := by tidy, map_smul' := by tidy, }. end category_theory.iso /-- linear equivalences between `module`s are the same as (isomorphic to) isomorphisms in `Module` -/ @[simps] def linear_equiv_iso_Module_iso {X Y : Type u} [add_comm_group X] [add_comm_group Y] [module R X] [module R Y] : (X ≃ₗ[R] Y) ≅ (Module.of R X ≅ Module.of R Y) := { hom := λ e, e.to_Module_iso, inv := λ i, i.to_linear_equiv, } namespace Module instance : preadditive (Module.{v} R) := { add_comp' := λ P Q R f f' g, show (f + f') ≫ g = f ≫ g + f' ≫ g, by { ext, simp }, comp_add' := λ P Q R f g g', show f ≫ (g + g') = f ≫ g + f ≫ g', by { ext, simp } } instance forget₂_AddCommGroup_additive : (forget₂ (Module.{v} R) AddCommGroup).additive := {} section variables {S : Type u} [comm_ring S] instance : linear S (Module.{v} S) := { hom_module := λ X Y, linear_map.module, smul_comp' := by { intros, ext, simp }, comp_smul' := by { intros, ext, simp }, } variables {X Y X' Y' : Module.{v} S} lemma iso.hom_congr_eq_arrow_congr (i : X ≅ X') (j : Y ≅ Y') (f : X ⟶ Y) : iso.hom_congr i j f = linear_equiv.arrow_congr i.to_linear_equiv j.to_linear_equiv f := rfl lemma iso.conj_eq_conj (i : X ≅ X') (f : End X) : iso.conj i f = linear_equiv.conj i.to_linear_equiv f := rfl end end Module instance (M : Type u) [add_comm_group M] [module R M] : has_coe (submodule R M) (Module R) := ⟨ λ N, Module.of R N ⟩
abba4fa721b09f3a7b2ccefa7a2a2339b035ad8b
4fa161becb8ce7378a709f5992a594764699e268
/src/topology/uniform_space/cauchy.lean
9806fa3e966e56e92be69e37145e25e2e5727f20
[ "Apache-2.0" ]
permissive
laughinggas/mathlib
e4aa4565ae34e46e834434284cb26bd9d67bc373
86dcd5cda7a5017c8b3c8876c89a510a19d49aad
refs/heads/master
1,669,496,232,688
1,592,831,995,000
1,592,831,995,000
274,155,979
0
0
Apache-2.0
1,592,835,190,000
1,592,835,189,000
null
UTF-8
Lean
false
false
26,171
lean
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import topology.uniform_space.basic import topology.bases import data.set.intervals /-! # Theory of Cauchy filters in uniform spaces. Complete uniform spaces. Totally bounded subsets. -/ universes u v open filter topological_space set classical uniform_space open_locale classical variables {α : Type u} {β : Type v} [uniform_space α] open_locale uniformity topological_space /-- A filter `f` is Cauchy if for every entourage `r`, there exists an `s ∈ f` such that `s × s ⊆ r`. This is a generalization of Cauchy sequences, because if `a : ℕ → α` then the filter of sets containing cofinitely many of the `a n` is Cauchy iff `a` is a Cauchy sequence. -/ def cauchy (f : filter α) := f ≠ ⊥ ∧ filter.prod f f ≤ (𝓤 α) /-- A set `s` is called *complete*, if any Cauchy filter `f` such that `s ∈ f` has a limit in `s` (formally, it satisfies `f ≤ 𝓝 x` for some `x ∈ s`). -/ def is_complete (s : set α) := ∀f, cauchy f → f ≤ principal s → ∃x∈s, f ≤ 𝓝 x lemma filter.has_basis.cauchy_iff {p : β → Prop} {s : β → set (α × α)} (h : (𝓤 α).has_basis p s) {f : filter α} : cauchy f ↔ (f ≠ ⊥ ∧ (∀ i, p i → ∃ t ∈ f, ∀ x y ∈ t, (x, y) ∈ s i)) := and_congr iff.rfl $ (f.basis_sets.prod_self.le_basis_iff h).trans $ by simp only [subset_def, prod.forall, mem_prod_eq, and_imp, id] lemma cauchy_iff' {f : filter α} : cauchy f ↔ (f ≠ ⊥ ∧ (∀ s ∈ 𝓤 α, ∃t∈f, ∀ x y ∈ t, (x, y) ∈ s)) := (𝓤 α).basis_sets.cauchy_iff lemma cauchy_iff {f : filter α} : cauchy f ↔ (f ≠ ⊥ ∧ (∀ s ∈ 𝓤 α, ∃t∈f, (set.prod t t) ⊆ s)) := (𝓤 α).basis_sets.cauchy_iff.trans $ by simp only [subset_def, prod.forall, mem_prod_eq, and_imp, id] lemma cauchy_map_iff {l : filter β} {f : β → α} : cauchy (l.map f) ↔ (l ≠ ⊥ ∧ tendsto (λp:β×β, (f p.1, f p.2)) (l.prod l) (𝓤 α)) := by rw [cauchy, (≠), map_eq_bot_iff, prod_map_map_eq]; refl lemma cauchy_downwards {f g : filter α} (h_c : cauchy f) (hg : g ≠ ⊥) (h_le : g ≤ f) : cauchy g := ⟨hg, le_trans (filter.prod_mono h_le h_le) h_c.right⟩ lemma cauchy_nhds {a : α} : cauchy (𝓝 a) := ⟨nhds_ne_bot, calc filter.prod (𝓝 a) (𝓝 a) = (𝓤 α).lift (λs:set (α×α), (𝓤 α).lift' (λt:set(α×α), set.prod {y : α | (y, a) ∈ s} {y : α | (a, y) ∈ t})) : nhds_nhds_eq_uniformity_uniformity_prod ... ≤ (𝓤 α).lift' (λs:set (α×α), comp_rel s s) : le_infi $ assume s, le_infi $ assume hs, infi_le_of_le s $ infi_le_of_le hs $ infi_le_of_le s $ infi_le_of_le hs $ principal_mono.mpr $ assume ⟨x, y⟩ ⟨(hx : (x, a) ∈ s), (hy : (a, y) ∈ s)⟩, ⟨a, hx, hy⟩ ... ≤ 𝓤 α : comp_le_uniformity⟩ lemma cauchy_pure {a : α} : cauchy (pure a) := cauchy_downwards cauchy_nhds pure_ne_bot (pure_le_nhds a) /-- The common part of the proofs of `le_nhds_of_cauchy_adhp` and `sequentially_complete.le_nhds_of_seq_tendsto_nhds`: if for any entourage `s` one can choose a set `t ∈ f` of diameter `s` such that it contains a point `y` with `(x, y) ∈ s`, then `f` converges to `x`. -/ lemma le_nhds_of_cauchy_adhp_aux {f : filter α} {x : α} (adhs : ∀ s ∈ 𝓤 α, ∃ t ∈ f, (set.prod t t ⊆ s) ∧ ∃ y, (y ∈ t) ∧ (x, y) ∈ s) : f ≤ 𝓝 x := begin -- Consider a neighborhood `s` of `x` assume s hs, -- Take an entourage twice smaller than `s` rcases comp_mem_uniformity_sets (mem_nhds_uniformity_iff_right.1 hs) with ⟨U, U_mem, hU⟩, -- Take a set `t ∈ f`, `t × t ⊆ U`, and a point `y ∈ t` such that `(x, y) ∈ U` rcases adhs U U_mem with ⟨t, t_mem, ht, y, hy, hxy⟩, apply mem_sets_of_superset t_mem, -- Given a point `z ∈ t`, we have `(x, y) ∈ U` and `(y, z) ∈ t × t ⊆ U`, hence `z ∈ s` exact (λ z hz, hU (prod_mk_mem_comp_rel hxy (ht $ mk_mem_prod hy hz)) rfl) end /-- If `x` is an adherent (cluster) point for a Cauchy filter `f`, then it is a limit point for `f`. -/ lemma le_nhds_of_cauchy_adhp {f : filter α} {x : α} (hf : cauchy f) (adhs : f ⊓ 𝓝 x ≠ ⊥) : f ≤ 𝓝 x := le_nhds_of_cauchy_adhp_aux begin assume s hs, -- Take `t ∈ f` such that `t × t ⊆ s`. rcases (cauchy_iff.1 hf).2 s hs with ⟨t, t_mem, ht⟩, use [t, t_mem, ht], exact (forall_sets_nonempty_iff_ne_bot.2 adhs _ (inter_mem_inf_sets t_mem (mem_nhds_left x hs))) end lemma le_nhds_iff_adhp_of_cauchy {f : filter α} {x : α} (hf : cauchy f) : f ≤ 𝓝 x ↔ f ⊓ 𝓝 x ≠ ⊥ := ⟨assume h, left_eq_inf.2 h ▸ hf.left, le_nhds_of_cauchy_adhp hf⟩ lemma cauchy_map [uniform_space β] {f : filter α} {m : α → β} (hm : uniform_continuous m) (hf : cauchy f) : cauchy (map m f) := ⟨have f ≠ ⊥, from hf.left, by simp; assumption, calc filter.prod (map m f) (map m f) = map (λp:α×α, (m p.1, m p.2)) (filter.prod f f) : filter.prod_map_map_eq ... ≤ map (λp:α×α, (m p.1, m p.2)) (𝓤 α) : map_mono hf.right ... ≤ 𝓤 β : hm⟩ lemma cauchy_comap [uniform_space β] {f : filter β} {m : α → β} (hm : comap (λp:α×α, (m p.1, m p.2)) (𝓤 β) ≤ 𝓤 α) (hf : cauchy f) (hb : comap m f ≠ ⊥) : cauchy (comap m f) := ⟨hb, calc filter.prod (comap m f) (comap m f) = comap (λp:α×α, (m p.1, m p.2)) (filter.prod f f) : filter.prod_comap_comap_eq ... ≤ comap (λp:α×α, (m p.1, m p.2)) (𝓤 β) : comap_mono hf.right ... ≤ 𝓤 α : hm⟩ /-- Cauchy sequences. Usually defined on ℕ, but often it is also useful to say that a function defined on ℝ is Cauchy at +∞ to deduce convergence. Therefore, we define it in a type class that is general enough to cover both ℕ and ℝ, which are the main motivating examples. -/ def cauchy_seq [semilattice_sup β] (u : β → α) := cauchy (at_top.map u) lemma cauchy_seq.mem_entourage {ι : Type*} [nonempty ι] [decidable_linear_order ι] {u : ι → α} (h : cauchy_seq u) {V : set (α × α)} (hV : V ∈ 𝓤 α) : ∃ k₀, ∀ i j, k₀ ≤ i → k₀ ≤ j → (u i, u j) ∈ V := begin have := h.right hV, obtain ⟨⟨i₀, j₀⟩, H⟩ : ∃ a, ∀ b : ι × ι, b ≥ a → prod.map u u b ∈ V, by rwa [prod_map_at_top_eq, mem_map, mem_at_top_sets] at this, refine ⟨max i₀ j₀, _⟩, intros i j hi hj, exact H (i, j) ⟨le_of_max_le_left hi, le_of_max_le_right hj⟩, end lemma cauchy_seq_of_tendsto_nhds [semilattice_sup β] [nonempty β] (f : β → α) {x} (hx : tendsto f at_top (𝓝 x)) : cauchy_seq f := cauchy_downwards cauchy_nhds (map_ne_bot at_top_ne_bot) hx lemma cauchy_seq_iff_tendsto [nonempty β] [semilattice_sup β] {u : β → α} : cauchy_seq u ↔ tendsto (prod.map u u) at_top (𝓤 α) := cauchy_map_iff.trans $ (and_iff_right at_top_ne_bot).trans $ by simp only [prod_at_top_at_top_eq, prod.map_def] /-- If a Cauchy sequence has a convergent subsequence, then it converges. -/ lemma tendsto_nhds_of_cauchy_seq_of_subseq [semilattice_sup β] {u : β → α} (hu : cauchy_seq u) {ι : Type*} {f : ι → β} {p : filter ι} (hp : p ≠ ⊥) (hf : tendsto f p at_top) {a : α} (ha : tendsto (λ i, u (f i)) p (𝓝 a)) : tendsto u at_top (𝓝 a) := begin apply le_nhds_of_cauchy_adhp hu, rw ← bot_lt_iff_ne_bot, have : ⊥ < map (λ i, u (f i)) p ⊓ 𝓝 a, by { rw [bot_lt_iff_ne_bot, inf_of_le_left ha], exact map_ne_bot hp }, exact lt_of_lt_of_le this (inf_le_inf_right _ (map_mono hf)) end @[nolint ge_or_gt] -- see Note [nolint_ge] lemma filter.has_basis.cauchy_seq_iff {γ} [nonempty β] [semilattice_sup β] {u : β → α} {p : γ → Prop} {s : γ → set (α × α)} (h : (𝓤 α).has_basis p s) : cauchy_seq u ↔ ∀ i, p i → ∃N, ∀m n≥N, (u m, u n) ∈ s i := begin rw [cauchy_seq_iff_tendsto, ← prod_at_top_at_top_eq], refine (at_top_basis.prod_self.tendsto_iff h).trans _, simp only [exists_prop, true_and, maps_to, preimage, subset_def, prod.forall, mem_prod_eq, mem_set_of_eq, mem_Ici, and_imp, prod.map] end @[nolint ge_or_gt] -- see Note [nolint_ge] lemma filter.has_basis.cauchy_seq_iff' {γ} [nonempty β] [semilattice_sup β] {u : β → α} {p : γ → Prop} {s : γ → set (α × α)} (H : (𝓤 α).has_basis p s) : cauchy_seq u ↔ ∀ i, p i → ∃N, ∀n≥N, (u n, u N) ∈ s i := begin refine H.cauchy_seq_iff.trans ⟨λ h i hi, _, λ h i hi, _⟩, { exact (h i hi).imp (λ N hN n hn, hN n N hn (le_refl N)) }, { rcases comp_symm_of_uniformity (H.mem_of_mem hi) with ⟨t, ht, ht', hts⟩, rcases H.mem_iff.1 ht with ⟨j, hj, hjt⟩, refine (h j hj).imp (λ N hN m n hm hn, hts ⟨u N, hjt _, ht' $ hjt _⟩), { exact hN m hm }, { exact hN n hn } } end lemma cauchy_seq_of_controlled [semilattice_sup β] [nonempty β] (U : β → set (α × α)) (hU : ∀ s ∈ 𝓤 α, ∃ n, U n ⊆ s) {f : β → α} (hf : ∀ {N m n : β}, N ≤ m → N ≤ n → (f m, f n) ∈ U N) : cauchy_seq f := cauchy_seq_iff_tendsto.2 begin assume s hs, rw [mem_map, mem_at_top_sets], cases hU s hs with N hN, refine ⟨(N, N), λ mn hmn, _⟩, cases mn with m n, exact hN (hf hmn.1 hmn.2) end /-- A complete space is defined here using uniformities. A uniform space is complete if every Cauchy filter converges. -/ class complete_space (α : Type u) [uniform_space α] : Prop := (complete : ∀{f:filter α}, cauchy f → ∃x, f ≤ 𝓝 x) lemma complete_univ {α : Type u} [uniform_space α] [complete_space α] : is_complete (univ : set α) := begin assume f hf _, rcases complete_space.complete hf with ⟨x, hx⟩, exact ⟨x, mem_univ x, hx⟩ end lemma cauchy_prod [uniform_space β] {f : filter α} {g : filter β} : cauchy f → cauchy g → cauchy (filter.prod f g) | ⟨f_proper, hf⟩ ⟨g_proper, hg⟩ := ⟨filter.prod_ne_bot.2 ⟨f_proper, g_proper⟩, let p_α := λp:(α×β)×(α×β), (p.1.1, p.2.1), p_β := λp:(α×β)×(α×β), (p.1.2, p.2.2) in suffices (f.prod f).comap p_α ⊓ (g.prod g).comap p_β ≤ (𝓤 α).comap p_α ⊓ (𝓤 β).comap p_β, by simpa [uniformity_prod, filter.prod, filter.comap_inf, filter.comap_comap_comp, (∘), inf_assoc, inf_comm, inf_left_comm], inf_le_inf (filter.comap_mono hf) (filter.comap_mono hg)⟩ instance complete_space.prod [uniform_space β] [complete_space α] [complete_space β] : complete_space (α × β) := { complete := λ f hf, let ⟨x1, hx1⟩ := complete_space.complete $ cauchy_map uniform_continuous_fst hf in let ⟨x2, hx2⟩ := complete_space.complete $ cauchy_map uniform_continuous_snd hf in ⟨(x1, x2), by rw [nhds_prod_eq, filter.prod_def]; from filter.le_lift (λ s hs, filter.le_lift' $ λ t ht, have H1 : prod.fst ⁻¹' s ∈ f.sets := hx1 hs, have H2 : prod.snd ⁻¹' t ∈ f.sets := hx2 ht, filter.inter_mem_sets H1 H2)⟩ } /--If `univ` is complete, the space is a complete space -/ lemma complete_space_of_is_complete_univ (h : is_complete (univ : set α)) : complete_space α := ⟨λ f hf, let ⟨x, _, hx⟩ := h f hf ((@principal_univ α).symm ▸ le_top) in ⟨x, hx⟩⟩ lemma complete_space_iff_is_complete_univ : complete_space α ↔ is_complete (univ : set α) := ⟨@complete_univ α _, complete_space_of_is_complete_univ⟩ lemma cauchy_iff_exists_le_nhds [complete_space α] {l : filter α} (hl : l ≠ ⊥) : cauchy l ↔ (∃x, l ≤ 𝓝 x) := ⟨complete_space.complete, assume ⟨x, hx⟩, cauchy_downwards cauchy_nhds hl hx⟩ lemma cauchy_map_iff_exists_tendsto [complete_space α] {l : filter β} {f : β → α} (hl : l ≠ ⊥) : cauchy (l.map f) ↔ (∃x, tendsto f l (𝓝 x)) := cauchy_iff_exists_le_nhds (map_ne_bot hl) /-- A Cauchy sequence in a complete space converges -/ theorem cauchy_seq_tendsto_of_complete [semilattice_sup β] [complete_space α] {u : β → α} (H : cauchy_seq u) : ∃x, tendsto u at_top (𝓝 x) := complete_space.complete H /-- If `K` is a complete subset, then any cauchy sequence in `K` converges to a point in `K` -/ lemma cauchy_seq_tendsto_of_is_complete [semilattice_sup β] {K : set α} (h₁ : is_complete K) {u : β → α} (h₂ : ∀ n, u n ∈ K) (h₃ : cauchy_seq u) : ∃ v ∈ K, tendsto u at_top (𝓝 v) := h₁ _ h₃ $ le_principal_iff.2 $ mem_map_sets_iff.2 ⟨univ, univ_mem_sets, by { simp only [image_univ], rintros _ ⟨n, rfl⟩, exact h₂ n }⟩ theorem cauchy.le_nhds_Lim [complete_space α] [nonempty α] {f : filter α} (hf : cauchy f) : f ≤ 𝓝 (Lim f) := Lim_spec (complete_space.complete hf) theorem cauchy_seq.tendsto_lim [semilattice_sup β] [complete_space α] [nonempty α] {u : β → α} (h : cauchy_seq u) : tendsto u at_top (𝓝 $ lim at_top u) := h.le_nhds_Lim lemma is_complete_of_is_closed [complete_space α] {s : set α} (h : is_closed s) : is_complete s := λ f cf fs, let ⟨x, hx⟩ := complete_space.complete cf in ⟨x, is_closed_iff_nhds.mp h x (ne_bot_of_le_ne_bot cf.left (le_inf hx fs)), hx⟩ /-- A set `s` is totally bounded if for every entourage `d` there is a finite set of points `t` such that every element of `s` is `d`-near to some element of `t`. -/ def totally_bounded (s : set α) : Prop := ∀d ∈ 𝓤 α, ∃t : set α, finite t ∧ s ⊆ (⋃y∈t, {x | (x,y) ∈ d}) theorem totally_bounded_iff_subset {s : set α} : totally_bounded s ↔ ∀d ∈ 𝓤 α, ∃t ⊆ s, finite t ∧ s ⊆ (⋃y∈t, {x | (x,y) ∈ d}) := ⟨λ H d hd, begin rcases comp_symm_of_uniformity hd with ⟨r, hr, rs, rd⟩, rcases H r hr with ⟨k, fk, ks⟩, let u := {y ∈ k | ∃ x, x ∈ s ∧ (x, y) ∈ r}, let f : u → α := λ x, classical.some x.2.2, have : ∀ x : u, f x ∈ s ∧ (f x, x.1) ∈ r := λ x, classical.some_spec x.2.2, refine ⟨range f, _, _, _⟩, { exact range_subset_iff.2 (λ x, (this x).1) }, { have : finite u := finite_subset fk (λ x h, h.1), exact ⟨@set.fintype_range _ _ _ _ this.fintype⟩ }, { intros x xs, have := ks xs, simp at this, rcases this with ⟨y, hy, xy⟩, let z : coe_sort u := ⟨y, hy, x, xs, xy⟩, exact mem_bUnion_iff.2 ⟨_, ⟨z, rfl⟩, rd $ mem_comp_rel.2 ⟨_, xy, rs (this z).2⟩⟩ } end, λ H d hd, let ⟨t, _, ht⟩ := H d hd in ⟨t, ht⟩⟩ lemma totally_bounded_of_forall_symm {s : set α} (h : ∀ V ∈ 𝓤 α, symmetric_rel V → ∃ t : set α, finite t ∧ s ⊆ ⋃ y ∈ t, ball y V) : totally_bounded s := begin intros V V_in, rcases h _ (symmetrize_mem_uniformity V_in) (symmetric_symmetrize_rel V) with ⟨t, tfin, h⟩, refine ⟨t, tfin, subset.trans h _⟩, mono, intros x x_in z z_in, exact z_in.right end lemma totally_bounded_subset {s₁ s₂ : set α} (hs : s₁ ⊆ s₂) (h : totally_bounded s₂) : totally_bounded s₁ := assume d hd, let ⟨t, ht₁, ht₂⟩ := h d hd in ⟨t, ht₁, subset.trans hs ht₂⟩ lemma totally_bounded_empty : totally_bounded (∅ : set α) := λ d hd, ⟨∅, finite_empty, empty_subset _⟩ lemma totally_bounded_closure {s : set α} (h : totally_bounded s) : totally_bounded (closure s) := assume t ht, let ⟨t', ht', hct', htt'⟩ := mem_uniformity_is_closed ht, ⟨c, hcf, hc⟩ := h t' ht' in ⟨c, hcf, calc closure s ⊆ closure (⋃ (y : α) (H : y ∈ c), {x : α | (x, y) ∈ t'}) : closure_mono hc ... = _ : closure_eq_of_is_closed $ is_closed_bUnion hcf $ assume i hi, continuous_iff_is_closed.mp (continuous_id.prod_mk continuous_const) _ hct' ... ⊆ _ : bUnion_subset $ assume i hi, subset.trans (assume x, @htt' (x, i)) (subset_bUnion_of_mem hi)⟩ lemma totally_bounded_image [uniform_space β] {f : α → β} {s : set α} (hf : uniform_continuous f) (hs : totally_bounded s) : totally_bounded (f '' s) := assume t ht, have {p:α×α | (f p.1, f p.2) ∈ t} ∈ 𝓤 α, from hf ht, let ⟨c, hfc, hct⟩ := hs _ this in ⟨f '' c, finite_image f hfc, begin simp [image_subset_iff], simp [subset_def] at hct, intros x hx, simp, exact hct x hx end⟩ lemma cauchy_of_totally_bounded_of_ultrafilter {s : set α} {f : filter α} (hs : totally_bounded s) (hf : is_ultrafilter f) (h : f ≤ principal s) : cauchy f := ⟨hf.left, assume t ht, let ⟨t', ht'₁, ht'_symm, ht'_t⟩ := comp_symm_of_uniformity ht in let ⟨i, hi, hs_union⟩ := hs t' ht'₁ in have (⋃y∈i, {x | (x,y) ∈ t'}) ∈ f.sets, from mem_sets_of_superset (le_principal_iff.mp h) hs_union, have ∃y∈i, {x | (x,y) ∈ t'} ∈ f.sets, from mem_of_finite_Union_ultrafilter hf hi this, let ⟨y, hy, hif⟩ := this in have set.prod {x | (x,y) ∈ t'} {x | (x,y) ∈ t'} ⊆ comp_rel t' t', from assume ⟨x₁, x₂⟩ ⟨(h₁ : (x₁, y) ∈ t'), (h₂ : (x₂, y) ∈ t')⟩, ⟨y, h₁, ht'_symm h₂⟩, (filter.prod f f).sets_of_superset (prod_mem_prod hif hif) (subset.trans this ht'_t)⟩ lemma totally_bounded_iff_filter {s : set α} : totally_bounded s ↔ (∀f, f ≠ ⊥ → f ≤ principal s → ∃c ≤ f, cauchy c) := ⟨assume : totally_bounded s, assume f hf hs, ⟨ultrafilter_of f, ultrafilter_of_le, cauchy_of_totally_bounded_of_ultrafilter this (ultrafilter_ultrafilter_of hf) (le_trans ultrafilter_of_le hs)⟩, assume h : ∀f, f ≠ ⊥ → f ≤ principal s → ∃c ≤ f, cauchy c, assume d hd, classical.by_contradiction $ assume hs, have hd_cover : ∀{t:set α}, finite t → ¬ s ⊆ (⋃y∈t, {x | (x,y) ∈ d}), by simpa using hs, let f := ⨅t:{t : set α // finite t}, principal (s \ (⋃y∈t.val, {x | (x,y) ∈ d})), ⟨a, ha⟩ := (@ne_empty_iff_nonempty α s).1 (assume h, hd_cover finite_empty $ h.symm ▸ empty_subset _) in have f ≠ ⊥, from infi_ne_bot_of_directed ⟨a⟩ (assume ⟨t₁, ht₁⟩ ⟨t₂, ht₂⟩, ⟨⟨t₁ ∪ t₂, finite_union ht₁ ht₂⟩, principal_mono.mpr $ diff_subset_diff_right $ Union_subset_Union $ assume t, Union_subset_Union_const or.inl, principal_mono.mpr $ diff_subset_diff_right $ Union_subset_Union $ assume t, Union_subset_Union_const or.inr⟩) (assume ⟨t, ht⟩, by simp [diff_eq_empty]; exact hd_cover ht), have f ≤ principal s, from infi_le_of_le ⟨∅, finite_empty⟩ $ by simp; exact subset.refl s, let ⟨c, (hc₁ : c ≤ f), (hc₂ : cauchy c)⟩ := h f ‹f ≠ ⊥› this, ⟨m, hm, (hmd : set.prod m m ⊆ d)⟩ := (@mem_prod_same_iff α c d).mp $ hc₂.right hd in have c ≤ principal s, from le_trans ‹c ≤ f› this, have m ∩ s ∈ c.sets, from inter_mem_sets hm $ le_principal_iff.mp this, let ⟨y, hym, hys⟩ := nonempty_of_mem_sets hc₂.left this in let ys := (⋃y'∈({y}:set α), {x | (x, y') ∈ d}) in have m ⊆ ys, from assume y' hy', show y' ∈ (⋃y'∈({y}:set α), {x | (x, y') ∈ d}), by simp; exact @hmd (y', y) ⟨hy', hym⟩, have c ≤ principal (s - ys), from le_trans hc₁ $ infi_le_of_le ⟨{y}, finite_singleton _⟩ $ le_refl _, have (s - ys) ∩ (m ∩ s) ∈ c.sets, from inter_mem_sets (le_principal_iff.mp this) ‹m ∩ s ∈ c.sets›, have ∅ ∈ c.sets, from c.sets_of_superset this $ assume x ⟨⟨hxs, hxys⟩, hxm, _⟩, hxys $ ‹m ⊆ ys› hxm, hc₂.left $ empty_in_sets_eq_bot.mp this⟩ lemma totally_bounded_iff_ultrafilter {s : set α} : totally_bounded s ↔ (∀f, is_ultrafilter f → f ≤ principal s → cauchy f) := ⟨assume hs f, cauchy_of_totally_bounded_of_ultrafilter hs, assume h, totally_bounded_iff_filter.mpr $ assume f hf hfs, have cauchy (ultrafilter_of f), from h (ultrafilter_of f) (ultrafilter_ultrafilter_of hf) (le_trans ultrafilter_of_le hfs), ⟨ultrafilter_of f, ultrafilter_of_le, this⟩⟩ lemma compact_iff_totally_bounded_complete {s : set α} : compact s ↔ totally_bounded s ∧ is_complete s := ⟨λ hs, ⟨totally_bounded_iff_ultrafilter.2 (λ f hf1 hf2, let ⟨x, xs, fx⟩ := compact_iff_ultrafilter_le_nhds.1 hs f hf1 hf2 in cauchy_downwards (cauchy_nhds) (hf1.1) fx), λ f fc fs, let ⟨a, as, fa⟩ := hs f fc.1 fs in ⟨a, as, le_nhds_of_cauchy_adhp fc fa⟩⟩, λ ⟨ht, hc⟩, compact_iff_ultrafilter_le_nhds.2 (λf hf hfs, hc _ (totally_bounded_iff_ultrafilter.1 ht _ hf hfs) hfs)⟩ @[priority 100] -- see Note [lower instance priority] instance complete_of_compact {α : Type u} [uniform_space α] [compact_space α] : complete_space α := ⟨λf hf, by simpa [principal_univ] using (compact_iff_totally_bounded_complete.1 compact_univ).2 f hf⟩ lemma compact_of_totally_bounded_is_closed [complete_space α] {s : set α} (ht : totally_bounded s) (hc : is_closed s) : compact s := (@compact_iff_totally_bounded_complete α _ s).2 ⟨ht, is_complete_of_is_closed hc⟩ /-! ### Sequentially complete space In this section we prove that a uniform space is complete provided that it is sequentially complete (i.e., any Cauchy sequence converges) and its uniformity filter admits a countable generating set. In particular, this applies to (e)metric spaces, see the files `topology/metric_space/emetric_space` and `topology/metric_space/basic`. More precisely, we assume that there is a sequence of entourages `U_n` such that any other entourage includes one of `U_n`. Then any Cauchy filter `f` generates a decreasing sequence of sets `s_n ∈ f` such that `s_n × s_n ⊆ U_n`. Choose a sequence `x_n∈s_n`. It is easy to show that this is a Cauchy sequence. If this sequence converges to some `a`, then `f ≤ 𝓝 a`. -/ namespace sequentially_complete variables {f : filter α} (hf : cauchy f) {U : ℕ → set (α × α)} (U_mem : ∀ n, U n ∈ 𝓤 α) (U_le : ∀ s ∈ 𝓤 α, ∃ n, U n ⊆ s) open set finset noncomputable theory /-- An auxiliary sequence of sets approximating a Cauchy filter. -/ def set_seq_aux (n : ℕ) : {s : set α // ∃ (_ : s ∈ f), s.prod s ⊆ U n } := indefinite_description _ $ (cauchy_iff.1 hf).2 (U n) (U_mem n) /-- Given a Cauchy filter `f` and a sequence `U` of entourages, `set_seq` provides a sequence of monotonically decreasing sets `s n ∈ f` such that `(s n).prod (s n) ⊆ U`. -/ def set_seq (n : ℕ) : set α := ⋂ m ∈ Iic n, (set_seq_aux hf U_mem m).val lemma set_seq_mem (n : ℕ) : set_seq hf U_mem n ∈ f := Inter_mem_sets (finite_le_nat n) (λ m _, (set_seq_aux hf U_mem m).2.fst) lemma set_seq_mono ⦃m n : ℕ⦄ (h : m ≤ n) : set_seq hf U_mem n ⊆ set_seq hf U_mem m := bInter_subset_bInter_left (λ k hk, le_trans hk h) lemma set_seq_sub_aux (n : ℕ) : set_seq hf U_mem n ⊆ set_seq_aux hf U_mem n := bInter_subset_of_mem right_mem_Iic lemma set_seq_prod_subset {N m n} (hm : N ≤ m) (hn : N ≤ n) : (set_seq hf U_mem m).prod (set_seq hf U_mem n) ⊆ U N := begin assume p hp, refine (set_seq_aux hf U_mem N).2.snd ⟨_, _⟩; apply set_seq_sub_aux, exact set_seq_mono hf U_mem hm hp.1, exact set_seq_mono hf U_mem hn hp.2 end /-- A sequence of points such that `seq n ∈ set_seq n`. Here `set_seq` is a monotonically decreasing sequence of sets `set_seq n ∈ f` with diameters controlled by a given sequence of entourages. -/ def seq (n : ℕ) : α := some $ nonempty_of_mem_sets hf.1 (set_seq_mem hf U_mem n) lemma seq_mem (n : ℕ) : seq hf U_mem n ∈ set_seq hf U_mem n := some_spec $ nonempty_of_mem_sets hf.1 (set_seq_mem hf U_mem n) lemma seq_pair_mem ⦃N m n : ℕ⦄ (hm : N ≤ m) (hn : N ≤ n) : (seq hf U_mem m, seq hf U_mem n) ∈ U N := set_seq_prod_subset hf U_mem hm hn ⟨seq_mem hf U_mem m, seq_mem hf U_mem n⟩ include U_le theorem seq_is_cauchy_seq : cauchy_seq $ seq hf U_mem := cauchy_seq_of_controlled U U_le $ seq_pair_mem hf U_mem /-- If the sequence `sequentially_complete.seq` converges to `a`, then `f ≤ 𝓝 a`. -/ theorem le_nhds_of_seq_tendsto_nhds ⦃a : α⦄ (ha : tendsto (seq hf U_mem) at_top (𝓝 a)) : f ≤ 𝓝 a := le_nhds_of_cauchy_adhp_aux begin assume s hs, rcases U_le s hs with ⟨m, hm⟩, rcases (tendsto_at_top' _ _).1 ha _ (mem_nhds_left a (U_mem m)) with ⟨n, hn⟩, refine ⟨set_seq hf U_mem (max m n), set_seq_mem hf U_mem _, _, seq hf U_mem (max m n), seq_mem hf U_mem _, _⟩, { have := le_max_left m n, exact set.subset.trans (set_seq_prod_subset hf U_mem this this) hm }, { exact hm (hn _ $ le_max_right m n) } end end sequentially_complete namespace uniform_space open sequentially_complete variables (H : is_countably_generated (𝓤 α)) include H /-- A uniform space is complete provided that (a) its uniformity filter has a countable basis; (b) any sequence satisfying a "controlled" version of the Cauchy condition converges. -/ theorem complete_of_convergent_controlled_sequences (U : ℕ → set (α × α)) (U_mem : ∀ n, U n ∈ 𝓤 α) (HU : ∀ u : ℕ → α, (∀ N m n, N ≤ m → N ≤ n → (u m, u n) ∈ U N) → ∃ a, tendsto u at_top (𝓝 a)) : complete_space α := begin rcases H.exists_antimono_seq' with ⟨U', U'_mono, hU'⟩, have Hmem : ∀ n, U n ∩ U' n ∈ 𝓤 α, from λ n, inter_mem_sets (U_mem n) (hU'.2 ⟨n, subset.refl _⟩), refine ⟨λ f hf, (HU (seq hf Hmem) (λ N m n hm hn, _)).imp $ le_nhds_of_seq_tendsto_nhds _ _ (λ s hs, _)⟩, { rcases (hU'.1 hs) with ⟨N, hN⟩, exact ⟨N, subset.trans (inter_subset_right _ _) hN⟩ }, { exact inter_subset_left _ _ (seq_pair_mem hf Hmem hm hn) } end /-- A sequentially complete uniform space with a countable basis of the uniformity filter is complete. -/ theorem complete_of_cauchy_seq_tendsto (H' : ∀ u : ℕ → α, cauchy_seq u → ∃a, tendsto u at_top (𝓝 a)) : complete_space α := let ⟨U', U'_mono, hU'⟩ := H.exists_antimono_seq' in complete_of_convergent_controlled_sequences H U' (λ n, hU'.2 ⟨n, subset.refl _⟩) (λ u hu, H' u $ cauchy_seq_of_controlled U' (λ s hs, hU'.1 hs) hu) protected lemma first_countable_topology : first_countable_topology α := ⟨λ a, by { rw nhds_eq_comap_uniformity, exact H.comap (prod.mk a) }⟩ end uniform_space
c0b2de450043c1f6edeca7a15b068dab11f2741a
9a0b1b3a653ea926b03d1495fef64da1d14b3174
/tidy/rewrite_search/discovery/shared.lean
311c0b3962861b8fd49772432aebff3d0e78e2b4
[ "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
811
lean
import .bundle namespace tidy.rewrite_search.discovery -- I've resisted the urge to pick funny vague adjectives here even though it kills me -- I can only dream: (resolute, determined, obstinate, unwavering, etc.) -- vs. (idle, indolent, etc.) @[derive decidable_eq] inductive persistence | speedy | try_bundles | try_everything export persistence (speedy) export persistence (try_bundles) export persistence (try_everything) def persistence.level : persistence → ℕ | speedy := 0 | try_bundles := 1 | try_everything := 2 instance : has_lt persistence := ⟨λ a b, a.level < b.level⟩ instance : has_le persistence := ⟨λ a b, a.level ≤ b.level⟩ meta structure progress := (persistence : persistence) (seen_bundles : list bundle_ref) end tidy.rewrite_search.discovery
285e4ee1aab5b023bc6e6ca4cd84e8c068e0e8dd
4b846d8dabdc64e7ea03552bad8f7fa74763fc67
/library/init/data/fin/basic.lean
4a78ca99fd019562c28d4d394d4ca597024bc543
[ "Apache-2.0" ]
permissive
pacchiano/lean
9324b33f3ac3b5c5647285160f9f6ea8d0d767dc
fdadada3a970377a6df8afcd629a6f2eab6e84e8
refs/heads/master
1,611,357,380,399
1,489,870,101,000
1,489,870,101,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
976
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.basic open nat structure fin (n : nat) := (val : nat) (is_lt : val < n) namespace fin variable {n : nat} lemma eq_of_veq : ∀ {i j : fin n}, (val i) = (val j) → i = j | ⟨iv, ilt₁⟩ ⟨.iv, ilt₂⟩ rfl := rfl lemma veq_of_eq : ∀ {i j : fin n}, i = j → (val i) = (val j) | ⟨iv, ilt⟩ .⟨iv, ilt⟩ rfl := rfl lemma ne_of_vne {i j : fin n} (h : val i ≠ val j) : i ≠ j := λ h', absurd (veq_of_eq h') h lemma vne_of_ne {i j : fin n} (h : i ≠ j) : val i ≠ val j := λ h', absurd (eq_of_veq h') h end fin open fin instance (n : nat) : decidable_eq (fin n) | ⟨ival, ilt⟩ ⟨jval, jlt⟩ := match nat.decidable_eq ival jval with | is_true h₁ := is_true (eq_of_veq h₁) | is_false h₁ := is_false (λ h₂, absurd (veq_of_eq h₂) h₁) end
93c08db64fdc3f1293a0cca63152365d3038176a
74addaa0e41490cbaf2abd313a764c96df57b05d
/Mathlib/linear_algebra/multilinear.lean
724e9ef9c091ef2d3763cca2989e3aa7406e9296
[]
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
54,259
lean
/- Copyright (c) 2020 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel -/ import Mathlib.PrePort import Mathlib.Lean3Lib.init.default import Mathlib.linear_algebra.basic import Mathlib.algebra.algebra.basic import Mathlib.tactic.omega.default import Mathlib.data.fintype.sort import Mathlib.PostPort universes u v w u' l v₁ v₂ u_1 v₃ v' u_2 u_3 u_5 u_6 u_7 u_4 namespace Mathlib /-! # Multilinear maps We define multilinear maps as maps from `Π(i : ι), M₁ i` to `M₂` which are linear in each coordinate. Here, `M₁ i` and `M₂` are modules over a ring `R`, and `ι` is an arbitrary type (although some statements will require it to be a fintype). This space, denoted by `multilinear_map R M₁ M₂`, inherits a module structure by pointwise addition and multiplication. ## Main definitions * `multilinear_map R M₁ M₂` is the space of multilinear maps from `Π(i : ι), M₁ i` to `M₂`. * `f.map_smul` is the multiplicativity of the multilinear map `f` along each coordinate. * `f.map_add` is the additivity of the multilinear map `f` along each coordinate. * `f.map_smul_univ` expresses the multiplicativity of `f` over all coordinates at the same time, writing `f (λi, c i • m i)` as `(∏ i, c i) • f m`. * `f.map_add_univ` expresses the additivity of `f` over all coordinates at the same time, writing `f (m + m')` as the sum over all subsets `s` of `ι` of `f (s.piecewise m m')`. * `f.map_sum` expresses `f (Σ_{j₁} g₁ j₁, ..., Σ_{jₙ} gₙ jₙ)` as the sum of `f (g₁ (r 1), ..., gₙ (r n))` where `r` ranges over all possible functions. We also register isomorphisms corresponding to currying or uncurrying variables, transforming a multilinear function `f` on `n+1` variables into a linear function taking values in multilinear functions in `n` variables, and into a multilinear function in `n` variables taking values in linear functions. These operations are called `f.curry_left` and `f.curry_right` respectively (with inverses `f.uncurry_left` and `f.uncurry_right`). These operations induce linear equivalences between spaces of multilinear functions in `n+1` variables and spaces of linear functions into multilinear functions in `n` variables (resp. multilinear functions in `n` variables taking values in linear functions), called respectively `multilinear_curry_left_equiv` and `multilinear_curry_right_equiv`. ## Implementation notes Expressing that a map is linear along the `i`-th coordinate when all other coordinates are fixed can be done in two (equivalent) different ways: * fixing a vector `m : Π(j : ι - i), M₁ j.val`, and then choosing separately the `i`-th coordinate * fixing a vector `m : Πj, M₁ j`, and then modifying its `i`-th coordinate The second way is more artificial as the value of `m` at `i` is not relevant, but it has the advantage of avoiding subtype inclusion issues. This is the definition we use, based on `function.update` that allows to change the value of `m` at `i`. -/ /-- Multilinear maps over the ring `R`, from `Πi, M₁ i` to `M₂` where `M₁ i` and `M₂` are modules over `R`. -/ structure multilinear_map (R : Type u) {ι : Type u'} (M₁ : ι → Type v) (M₂ : Type w) [DecidableEq ι] [semiring R] [(i : ι) → add_comm_monoid (M₁ i)] [add_comm_monoid M₂] [(i : ι) → semimodule R (M₁ i)] [semimodule R M₂] where to_fun : ((i : ι) → M₁ i) → M₂ map_add' : ∀ (m : (i : ι) → M₁ i) (i : ι) (x y : M₁ i), to_fun (function.update m i (x + y)) = to_fun (function.update m i x) + to_fun (function.update m i y) map_smul' : ∀ (m : (i : ι) → M₁ i) (i : ι) (c : R) (x : M₁ i), to_fun (function.update m i (c • x)) = c • to_fun (function.update m i x) namespace multilinear_map protected instance has_coe_to_fun {R : Type u} {ι : Type u'} {M₁ : ι → Type v₁} {M₂ : Type v₂} [DecidableEq ι] [semiring R] [(i : ι) → add_comm_monoid (M₁ i)] [add_comm_monoid M₂] [(i : ι) → semimodule R (M₁ i)] [semimodule R M₂] : has_coe_to_fun (multilinear_map R M₁ M₂) := has_coe_to_fun.mk (fun (x : multilinear_map R M₁ M₂) => ((i : ι) → M₁ i) → M₂) to_fun @[simp] theorem to_fun_eq_coe {R : Type u} {ι : Type u'} {M₁ : ι → Type v₁} {M₂ : Type v₂} [DecidableEq ι] [semiring R] [(i : ι) → add_comm_monoid (M₁ i)] [add_comm_monoid M₂] [(i : ι) → semimodule R (M₁ i)] [semimodule R M₂] (f : multilinear_map R M₁ M₂) : to_fun f = ⇑f := rfl @[simp] theorem coe_mk {R : Type u} {ι : Type u'} {M₁ : ι → Type v₁} {M₂ : Type v₂} [DecidableEq ι] [semiring R] [(i : ι) → add_comm_monoid (M₁ i)] [add_comm_monoid M₂] [(i : ι) → semimodule R (M₁ i)] [semimodule R M₂] (f : ((i : ι) → M₁ i) → M₂) (h₁ : ∀ (m : (i : ι) → M₁ i) (i : ι) (x y : M₁ i), f (function.update m i (x + y)) = f (function.update m i x) + f (function.update m i y)) (h₂ : ∀ (m : (i : ι) → M₁ i) (i : ι) (c : R) (x : M₁ i), f (function.update m i (c • x)) = c • f (function.update m i x)) : ⇑(mk f h₁ h₂) = f := rfl theorem congr_fun {R : Type u} {ι : Type u'} {M₁ : ι → Type v₁} {M₂ : Type v₂} [DecidableEq ι] [semiring R] [(i : ι) → add_comm_monoid (M₁ i)] [add_comm_monoid M₂] [(i : ι) → semimodule R (M₁ i)] [semimodule R M₂] {f : multilinear_map R M₁ M₂} {g : multilinear_map R M₁ M₂} (h : f = g) (x : (i : ι) → M₁ i) : coe_fn f x = coe_fn g x := congr_arg (fun (h : multilinear_map R M₁ M₂) => coe_fn h x) h theorem congr_arg {R : Type u} {ι : Type u'} {M₁ : ι → Type v₁} {M₂ : Type v₂} [DecidableEq ι] [semiring R] [(i : ι) → add_comm_monoid (M₁ i)] [add_comm_monoid M₂] [(i : ι) → semimodule R (M₁ i)] [semimodule R M₂] (f : multilinear_map R M₁ M₂) {x : (i : ι) → M₁ i} {y : (i : ι) → M₁ i} (h : x = y) : coe_fn f x = coe_fn f y := congr_arg (fun (x : (i : ι) → M₁ i) => coe_fn f x) h theorem coe_inj {R : Type u} {ι : Type u'} {M₁ : ι → Type v₁} {M₂ : Type v₂} [DecidableEq ι] [semiring R] [(i : ι) → add_comm_monoid (M₁ i)] [add_comm_monoid M₂] [(i : ι) → semimodule R (M₁ i)] [semimodule R M₂] {f : multilinear_map R M₁ M₂} {g : multilinear_map R M₁ M₂} (h : ⇑f = ⇑g) : f = g := sorry theorem ext {R : Type u} {ι : Type u'} {M₁ : ι → Type v₁} {M₂ : Type v₂} [DecidableEq ι] [semiring R] [(i : ι) → add_comm_monoid (M₁ i)] [add_comm_monoid M₂] [(i : ι) → semimodule R (M₁ i)] [semimodule R M₂] {f : multilinear_map R M₁ M₂} {f' : multilinear_map R M₁ M₂} (H : ∀ (x : (i : ι) → M₁ i), coe_fn f x = coe_fn f' x) : f = f' := coe_inj (funext H) theorem ext_iff {R : Type u} {ι : Type u'} {M₁ : ι → Type v₁} {M₂ : Type v₂} [DecidableEq ι] [semiring R] [(i : ι) → add_comm_monoid (M₁ i)] [add_comm_monoid M₂] [(i : ι) → semimodule R (M₁ i)] [semimodule R M₂] {f : multilinear_map R M₁ M₂} {g : multilinear_map R M₁ M₂} : f = g ↔ ∀ (x : (i : ι) → M₁ i), coe_fn f x = coe_fn g x := { mp := fun (h : f = g) (x : (i : ι) → M₁ i) => h ▸ rfl, mpr := fun (h : ∀ (x : (i : ι) → M₁ i), coe_fn f x = coe_fn g x) => ext h } @[simp] theorem map_add {R : Type u} {ι : Type u'} {M₁ : ι → Type v₁} {M₂ : Type v₂} [DecidableEq ι] [semiring R] [(i : ι) → add_comm_monoid (M₁ i)] [add_comm_monoid M₂] [(i : ι) → semimodule R (M₁ i)] [semimodule R M₂] (f : multilinear_map R M₁ M₂) (m : (i : ι) → M₁ i) (i : ι) (x : M₁ i) (y : M₁ i) : coe_fn f (function.update m i (x + y)) = coe_fn f (function.update m i x) + coe_fn f (function.update m i y) := map_add' f m i x y @[simp] theorem map_smul {R : Type u} {ι : Type u'} {M₁ : ι → Type v₁} {M₂ : Type v₂} [DecidableEq ι] [semiring R] [(i : ι) → add_comm_monoid (M₁ i)] [add_comm_monoid M₂] [(i : ι) → semimodule R (M₁ i)] [semimodule R M₂] (f : multilinear_map R M₁ M₂) (m : (i : ι) → M₁ i) (i : ι) (c : R) (x : M₁ i) : coe_fn f (function.update m i (c • x)) = c • coe_fn f (function.update m i x) := map_smul' f m i c x theorem map_coord_zero {R : Type u} {ι : Type u'} {M₁ : ι → Type v₁} {M₂ : Type v₂} [DecidableEq ι] [semiring R] [(i : ι) → add_comm_monoid (M₁ i)] [add_comm_monoid M₂] [(i : ι) → semimodule R (M₁ i)] [semimodule R M₂] (f : multilinear_map R M₁ M₂) {m : (i : ι) → M₁ i} (i : ι) (h : m i = 0) : coe_fn f m = 0 := sorry @[simp] theorem map_update_zero {R : Type u} {ι : Type u'} {M₁ : ι → Type v₁} {M₂ : Type v₂} [DecidableEq ι] [semiring R] [(i : ι) → add_comm_monoid (M₁ i)] [add_comm_monoid M₂] [(i : ι) → semimodule R (M₁ i)] [semimodule R M₂] (f : multilinear_map R M₁ M₂) (m : (i : ι) → M₁ i) (i : ι) : coe_fn f (function.update m i 0) = 0 := map_coord_zero f i (function.update_same i 0 m) @[simp] theorem map_zero {R : Type u} {ι : Type u'} {M₁ : ι → Type v₁} {M₂ : Type v₂} [DecidableEq ι] [semiring R] [(i : ι) → add_comm_monoid (M₁ i)] [add_comm_monoid M₂] [(i : ι) → semimodule R (M₁ i)] [semimodule R M₂] (f : multilinear_map R M₁ M₂) [Nonempty ι] : coe_fn f 0 = 0 := Exists.dcases_on (set.exists_mem_of_nonempty ι) fun (i : ι) (h : i ∈ set.univ) => map_coord_zero f i rfl protected instance has_add {R : Type u} {ι : Type u'} {M₁ : ι → Type v₁} {M₂ : Type v₂} [DecidableEq ι] [semiring R] [(i : ι) → add_comm_monoid (M₁ i)] [add_comm_monoid M₂] [(i : ι) → semimodule R (M₁ i)] [semimodule R M₂] : Add (multilinear_map R M₁ M₂) := { add := fun (f f' : multilinear_map R M₁ M₂) => mk (fun (x : (i : ι) → M₁ i) => coe_fn f x + coe_fn f' x) sorry sorry } @[simp] theorem add_apply {R : Type u} {ι : Type u'} {M₁ : ι → Type v₁} {M₂ : Type v₂} [DecidableEq ι] [semiring R] [(i : ι) → add_comm_monoid (M₁ i)] [add_comm_monoid M₂] [(i : ι) → semimodule R (M₁ i)] [semimodule R M₂] (f : multilinear_map R M₁ M₂) (f' : multilinear_map R M₁ M₂) (m : (i : ι) → M₁ i) : coe_fn (f + f') m = coe_fn f m + coe_fn f' m := rfl protected instance has_zero {R : Type u} {ι : Type u'} {M₁ : ι → Type v₁} {M₂ : Type v₂} [DecidableEq ι] [semiring R] [(i : ι) → add_comm_monoid (M₁ i)] [add_comm_monoid M₂] [(i : ι) → semimodule R (M₁ i)] [semimodule R M₂] : HasZero (multilinear_map R M₁ M₂) := { zero := mk (fun (_x : (i : ι) → M₁ i) => 0) sorry sorry } protected instance inhabited {R : Type u} {ι : Type u'} {M₁ : ι → Type v₁} {M₂ : Type v₂} [DecidableEq ι] [semiring R] [(i : ι) → add_comm_monoid (M₁ i)] [add_comm_monoid M₂] [(i : ι) → semimodule R (M₁ i)] [semimodule R M₂] : Inhabited (multilinear_map R M₁ M₂) := { default := 0 } @[simp] theorem zero_apply {R : Type u} {ι : Type u'} {M₁ : ι → Type v₁} {M₂ : Type v₂} [DecidableEq ι] [semiring R] [(i : ι) → add_comm_monoid (M₁ i)] [add_comm_monoid M₂] [(i : ι) → semimodule R (M₁ i)] [semimodule R M₂] (m : (i : ι) → M₁ i) : coe_fn 0 m = 0 := rfl protected instance add_comm_monoid {R : Type u} {ι : Type u'} {M₁ : ι → Type v₁} {M₂ : Type v₂} [DecidableEq ι] [semiring R] [(i : ι) → add_comm_monoid (M₁ i)] [add_comm_monoid M₂] [(i : ι) → semimodule R (M₁ i)] [semimodule R M₂] : add_comm_monoid (multilinear_map R M₁ M₂) := add_comm_monoid.mk Add.add sorry 0 sorry sorry sorry @[simp] theorem sum_apply {R : Type u} {ι : Type u'} {M₁ : ι → Type v₁} {M₂ : Type v₂} [DecidableEq ι] [semiring R] [(i : ι) → add_comm_monoid (M₁ i)] [add_comm_monoid M₂] [(i : ι) → semimodule R (M₁ i)] [semimodule R M₂] {α : Type u_1} (f : α → multilinear_map R M₁ M₂) (m : (i : ι) → M₁ i) {s : finset α} : coe_fn (finset.sum s fun (a : α) => f a) m = finset.sum s fun (a : α) => coe_fn (f a) m := sorry /-- If `f` is a multilinear map, then `f.to_linear_map m i` is the linear map obtained by fixing all coordinates but `i` equal to those of `m`, and varying the `i`-th coordinate. -/ def to_linear_map {R : Type u} {ι : Type u'} {M₁ : ι → Type v₁} {M₂ : Type v₂} [DecidableEq ι] [semiring R] [(i : ι) → add_comm_monoid (M₁ i)] [add_comm_monoid M₂] [(i : ι) → semimodule R (M₁ i)] [semimodule R M₂] (f : multilinear_map R M₁ M₂) (m : (i : ι) → M₁ i) (i : ι) : linear_map R (M₁ i) M₂ := linear_map.mk (fun (x : M₁ i) => coe_fn f (function.update m i x)) sorry sorry /-- The cartesian product of two multilinear maps, as a multilinear map. -/ def prod {R : Type u} {ι : Type u'} {M₁ : ι → Type v₁} {M₂ : Type v₂} {M₃ : Type v₃} [DecidableEq ι] [semiring R] [(i : ι) → add_comm_monoid (M₁ i)] [add_comm_monoid M₂] [add_comm_monoid M₃] [(i : ι) → semimodule R (M₁ i)] [semimodule R M₂] [semimodule R M₃] (f : multilinear_map R M₁ M₂) (g : multilinear_map R M₁ M₃) : multilinear_map R M₁ (M₂ × M₃) := mk (fun (m : (i : ι) → M₁ i) => (coe_fn f m, coe_fn g m)) sorry sorry /-- Given a multilinear map `f` on `n` variables (parameterized by `fin n`) and a subset `s` of `k` of these variables, one gets a new multilinear map on `fin k` by varying these variables, and fixing the other ones equal to a given value `z`. It is denoted by `f.restr s hk z`, where `hk` is a proof that the cardinality of `s` is `k`. The implicit identification between `fin k` and `s` that we use is the canonical (increasing) bijection. -/ def restr {R : Type u} {M₂ : Type v₂} {M' : Type v'} [semiring R] [add_comm_monoid M₂] [add_comm_monoid M'] [semimodule R M₂] [semimodule R M'] {k : ℕ} {n : ℕ} (f : multilinear_map R (fun (i : fin n) => M') M₂) (s : finset (fin n)) (hk : finset.card s = k) (z : M') : multilinear_map R (fun (i : fin k) => M') M₂ := mk (fun (v : fin k → M') => coe_fn f fun (j : fin n) => dite (j ∈ s) (fun (h : j ∈ s) => v (coe_fn (order_iso.symm (finset.order_iso_of_fin s hk)) { val := j, property := h })) fun (h : ¬j ∈ s) => z) sorry sorry /-- In the specific case of multilinear maps on spaces indexed by `fin (n+1)`, where one can build an element of `Π(i : fin (n+1)), M i` using `cons`, one can express directly the additivity of a multilinear map along the first variable. -/ theorem cons_add {R : Type u} {n : ℕ} {M : fin (Nat.succ n) → Type v} {M₂ : Type v₂} [semiring R] [(i : fin (Nat.succ n)) → add_comm_monoid (M i)] [add_comm_monoid M₂] [(i : fin (Nat.succ n)) → semimodule R (M i)] [semimodule R M₂] (f : multilinear_map R M M₂) (m : (i : fin n) → M (fin.succ i)) (x : M 0) (y : M 0) : coe_fn f (fin.cons (x + y) m) = coe_fn f (fin.cons x m) + coe_fn f (fin.cons y m) := sorry /-- In the specific case of multilinear maps on spaces indexed by `fin (n+1)`, where one can build an element of `Π(i : fin (n+1)), M i` using `cons`, one can express directly the multiplicativity of a multilinear map along the first variable. -/ theorem cons_smul {R : Type u} {n : ℕ} {M : fin (Nat.succ n) → Type v} {M₂ : Type v₂} [semiring R] [(i : fin (Nat.succ n)) → add_comm_monoid (M i)] [add_comm_monoid M₂] [(i : fin (Nat.succ n)) → semimodule R (M i)] [semimodule R M₂] (f : multilinear_map R M M₂) (m : (i : fin n) → M (fin.succ i)) (c : R) (x : M 0) : coe_fn f (fin.cons (c • x) m) = c • coe_fn f (fin.cons x m) := sorry /-- In the specific case of multilinear maps on spaces indexed by `fin (n+1)`, where one can build an element of `Π(i : fin (n+1)), M i` using `snoc`, one can express directly the additivity of a multilinear map along the first variable. -/ theorem snoc_add {R : Type u} {n : ℕ} {M : fin (Nat.succ n) → Type v} {M₂ : Type v₂} [semiring R] [(i : fin (Nat.succ n)) → add_comm_monoid (M i)] [add_comm_monoid M₂] [(i : fin (Nat.succ n)) → semimodule R (M i)] [semimodule R M₂] (f : multilinear_map R M M₂) (m : (i : fin n) → M (coe_fn fin.cast_succ i)) (x : M (fin.last n)) (y : M (fin.last n)) : coe_fn f (fin.snoc m (x + y)) = coe_fn f (fin.snoc m x) + coe_fn f (fin.snoc m y) := sorry /-- In the specific case of multilinear maps on spaces indexed by `fin (n+1)`, where one can build an element of `Π(i : fin (n+1)), M i` using `cons`, one can express directly the multiplicativity of a multilinear map along the first variable. -/ theorem snoc_smul {R : Type u} {n : ℕ} {M : fin (Nat.succ n) → Type v} {M₂ : Type v₂} [semiring R] [(i : fin (Nat.succ n)) → add_comm_monoid (M i)] [add_comm_monoid M₂] [(i : fin (Nat.succ n)) → semimodule R (M i)] [semimodule R M₂] (f : multilinear_map R M M₂) (m : (i : fin n) → M (coe_fn fin.cast_succ i)) (c : R) (x : M (fin.last n)) : coe_fn f (fin.snoc m (c • x)) = c • coe_fn f (fin.snoc m x) := sorry /-- If `g` is a multilinear map and `f` is a collection of linear maps, then `g (f₁ m₁, ..., fₙ mₙ)` is again a multilinear map, that we call `g.comp_linear_map f`. -/ def comp_linear_map {R : Type u} {ι : Type u'} {M₁ : ι → Type v₁} {M₂ : Type v₂} [DecidableEq ι] [semiring R] [(i : ι) → add_comm_monoid (M₁ i)] [add_comm_monoid M₂] [(i : ι) → semimodule R (M₁ i)] [semimodule R M₂] {M₁' : ι → Type u_1} [(i : ι) → add_comm_monoid (M₁' i)] [(i : ι) → semimodule R (M₁' i)] (g : multilinear_map R M₁' M₂) (f : (i : ι) → linear_map R (M₁ i) (M₁' i)) : multilinear_map R M₁ M₂ := mk (fun (m : (i : ι) → M₁ i) => coe_fn g fun (i : ι) => coe_fn (f i) (m i)) sorry sorry @[simp] theorem comp_linear_map_apply {R : Type u} {ι : Type u'} {M₁ : ι → Type v₁} {M₂ : Type v₂} [DecidableEq ι] [semiring R] [(i : ι) → add_comm_monoid (M₁ i)] [add_comm_monoid M₂] [(i : ι) → semimodule R (M₁ i)] [semimodule R M₂] {M₁' : ι → Type u_1} [(i : ι) → add_comm_monoid (M₁' i)] [(i : ι) → semimodule R (M₁' i)] (g : multilinear_map R M₁' M₂) (f : (i : ι) → linear_map R (M₁ i) (M₁' i)) (m : (i : ι) → M₁ i) : coe_fn (comp_linear_map g f) m = coe_fn g fun (i : ι) => coe_fn (f i) (m i) := rfl /-- If one adds to a vector `m'` another vector `m`, but only for coordinates in a finset `t`, then the image under a multilinear map `f` is the sum of `f (s.piecewise m m')` along all subsets `s` of `t`. This is mainly an auxiliary statement to prove the result when `t = univ`, given in `map_add_univ`, although it can be useful in its own right as it does not require the index set `ι` to be finite.-/ theorem map_piecewise_add {R : Type u} {ι : Type u'} {M₁ : ι → Type v₁} {M₂ : Type v₂} [DecidableEq ι] [semiring R] [(i : ι) → add_comm_monoid (M₁ i)] [add_comm_monoid M₂] [(i : ι) → semimodule R (M₁ i)] [semimodule R M₂] (f : multilinear_map R M₁ M₂) (m : (i : ι) → M₁ i) (m' : (i : ι) → M₁ i) (t : finset ι) : coe_fn f (finset.piecewise t (m + m') m') = finset.sum (finset.powerset t) fun (s : finset ι) => coe_fn f (finset.piecewise s m m') := sorry /-- Additivity of a multilinear map along all coordinates at the same time, writing `f (m + m')` as the sum of `f (s.piecewise m m')` over all sets `s`. -/ theorem map_add_univ {R : Type u} {ι : Type u'} {M₁ : ι → Type v₁} {M₂ : Type v₂} [DecidableEq ι] [semiring R] [(i : ι) → add_comm_monoid (M₁ i)] [add_comm_monoid M₂] [(i : ι) → semimodule R (M₁ i)] [semimodule R M₂] (f : multilinear_map R M₁ M₂) [fintype ι] (m : (i : ι) → M₁ i) (m' : (i : ι) → M₁ i) : coe_fn f (m + m') = finset.sum finset.univ fun (s : finset ι) => coe_fn f (finset.piecewise s m m') := sorry /-- If `f` is multilinear, then `f (Σ_{j₁ ∈ A₁} g₁ j₁, ..., Σ_{jₙ ∈ Aₙ} gₙ jₙ)` is the sum of `f (g₁ (r 1), ..., gₙ (r n))` where `r` ranges over all functions with `r 1 ∈ A₁`, ..., `r n ∈ Aₙ`. This follows from multilinearity by expanding successively with respect to each coordinate. Here, we give an auxiliary statement tailored for an inductive proof. Use instead `map_sum_finset`. -/ theorem map_sum_finset_aux {R : Type u} {ι : Type u'} {M₁ : ι → Type v₁} {M₂ : Type v₂} [DecidableEq ι] [semiring R] [(i : ι) → add_comm_monoid (M₁ i)] [add_comm_monoid M₂] [(i : ι) → semimodule R (M₁ i)] [semimodule R M₂] (f : multilinear_map R M₁ M₂) {α : ι → Type u_1} (g : (i : ι) → α i → M₁ i) (A : (i : ι) → finset (α i)) [fintype ι] {n : ℕ} (h : (finset.sum finset.univ fun (i : ι) => finset.card (A i)) = n) : (coe_fn f fun (i : ι) => finset.sum (A i) fun (j : α i) => g i j) = finset.sum (fintype.pi_finset A) fun (r : (a : ι) → α a) => coe_fn f fun (i : ι) => g i (r i) := sorry /-- If `f` is multilinear, then `f (Σ_{j₁ ∈ A₁} g₁ j₁, ..., Σ_{jₙ ∈ Aₙ} gₙ jₙ)` is the sum of `f (g₁ (r 1), ..., gₙ (r n))` where `r` ranges over all functions with `r 1 ∈ A₁`, ..., `r n ∈ Aₙ`. This follows from multilinearity by expanding successively with respect to each coordinate. -/ theorem map_sum_finset {R : Type u} {ι : Type u'} {M₁ : ι → Type v₁} {M₂ : Type v₂} [DecidableEq ι] [semiring R] [(i : ι) → add_comm_monoid (M₁ i)] [add_comm_monoid M₂] [(i : ι) → semimodule R (M₁ i)] [semimodule R M₂] (f : multilinear_map R M₁ M₂) {α : ι → Type u_1} (g : (i : ι) → α i → M₁ i) (A : (i : ι) → finset (α i)) [fintype ι] : (coe_fn f fun (i : ι) => finset.sum (A i) fun (j : α i) => g i j) = finset.sum (fintype.pi_finset A) fun (r : (a : ι) → α a) => coe_fn f fun (i : ι) => g i (r i) := map_sum_finset_aux f (fun (i : ι) (j : α i) => g i j) (fun (i : ι) => A i) rfl /-- If `f` is multilinear, then `f (Σ_{j₁} g₁ j₁, ..., Σ_{jₙ} gₙ jₙ)` is the sum of `f (g₁ (r 1), ..., gₙ (r n))` where `r` ranges over all functions `r`. This follows from multilinearity by expanding successively with respect to each coordinate. -/ theorem map_sum {R : Type u} {ι : Type u'} {M₁ : ι → Type v₁} {M₂ : Type v₂} [DecidableEq ι] [semiring R] [(i : ι) → add_comm_monoid (M₁ i)] [add_comm_monoid M₂] [(i : ι) → semimodule R (M₁ i)] [semimodule R M₂] (f : multilinear_map R M₁ M₂) {α : ι → Type u_1} (g : (i : ι) → α i → M₁ i) [fintype ι] [(i : ι) → fintype (α i)] : (coe_fn f fun (i : ι) => finset.sum finset.univ fun (j : α i) => g i j) = finset.sum finset.univ fun (r : (i : ι) → α i) => coe_fn f fun (i : ι) => g i (r i) := map_sum_finset f g fun (i : ι) => finset.univ theorem map_update_sum {R : Type u} {ι : Type u'} {M₁ : ι → Type v₁} {M₂ : Type v₂} [DecidableEq ι] [semiring R] [(i : ι) → add_comm_monoid (M₁ i)] [add_comm_monoid M₂] [(i : ι) → semimodule R (M₁ i)] [semimodule R M₂] (f : multilinear_map R M₁ M₂) {α : Type u_1} (t : finset α) (i : ι) (g : α → M₁ i) (m : (i : ι) → M₁ i) : coe_fn f (function.update m i (finset.sum t fun (a : α) => g a)) = finset.sum t fun (a : α) => coe_fn f (function.update m i (g a)) := sorry /-- Reinterpret an `A`-multilinear map as an `R`-multilinear map, if `A` is an algebra over `R` and their actions on all involved semimodules agree with the action of `R` on `A`. -/ def restrict_scalars (R : Type u) {ι : Type u'} {M₁ : ι → Type v₁} {M₂ : Type v₂} [DecidableEq ι] [semiring R] [(i : ι) → add_comm_monoid (M₁ i)] [add_comm_monoid M₂] [(i : ι) → semimodule R (M₁ i)] [semimodule R M₂] {A : Type u_1} [semiring A] [has_scalar R A] [(i : ι) → semimodule A (M₁ i)] [semimodule A M₂] [∀ (i : ι), is_scalar_tower R A (M₁ i)] [is_scalar_tower R A M₂] (f : multilinear_map A M₁ M₂) : multilinear_map R M₁ M₂ := mk ⇑f sorry sorry @[simp] theorem coe_restrict_scalars (R : Type u) {ι : Type u'} {M₁ : ι → Type v₁} {M₂ : Type v₂} [DecidableEq ι] [semiring R] [(i : ι) → add_comm_monoid (M₁ i)] [add_comm_monoid M₂] [(i : ι) → semimodule R (M₁ i)] [semimodule R M₂] {A : Type u_1} [semiring A] [has_scalar R A] [(i : ι) → semimodule A (M₁ i)] [semimodule A M₂] [∀ (i : ι), is_scalar_tower R A (M₁ i)] [is_scalar_tower R A M₂] (f : multilinear_map A M₁ M₂) : ⇑(restrict_scalars R f) = ⇑f := rfl /-- Transfer the arguments to a map along an equivalence between argument indices. The naming is derived from `finsupp.dom_congr`, noting that here the permutation applies to the domain of the domain. -/ @[simp] theorem dom_dom_congr_apply {R : Type u} {M₂ : Type v₂} {M₃ : Type v₃} [semiring R] [add_comm_monoid M₂] [add_comm_monoid M₃] [semimodule R M₂] [semimodule R M₃] {ι₁ : Type u_1} {ι₂ : Type u_2} [DecidableEq ι₁] [DecidableEq ι₂] (σ : ι₁ ≃ ι₂) (m : multilinear_map R (fun (i : ι₁) => M₂) M₃) (v : ι₂ → M₂) : coe_fn (dom_dom_congr σ m) v = coe_fn m fun (i : ι₁) => v (coe_fn σ i) := Eq.refl (coe_fn (dom_dom_congr σ m) v) theorem dom_dom_congr_trans {R : Type u} {M₂ : Type v₂} {M₃ : Type v₃} [semiring R] [add_comm_monoid M₂] [add_comm_monoid M₃] [semimodule R M₂] [semimodule R M₃] {ι₁ : Type u_1} {ι₂ : Type u_2} {ι₃ : Type u_3} [DecidableEq ι₁] [DecidableEq ι₂] [DecidableEq ι₃] (σ₁ : ι₁ ≃ ι₂) (σ₂ : ι₂ ≃ ι₃) (m : multilinear_map R (fun (i : ι₁) => M₂) M₃) : dom_dom_congr (equiv.trans σ₁ σ₂) m = dom_dom_congr σ₂ (dom_dom_congr σ₁ m) := rfl theorem dom_dom_congr_mul {R : Type u} {M₂ : Type v₂} {M₃ : Type v₃} [semiring R] [add_comm_monoid M₂] [add_comm_monoid M₃] [semimodule R M₂] [semimodule R M₃] {ι₁ : Type u_1} [DecidableEq ι₁] (σ₁ : equiv.perm ι₁) (σ₂ : equiv.perm ι₁) (m : multilinear_map R (fun (i : ι₁) => M₂) M₃) : dom_dom_congr (σ₂ * σ₁) m = dom_dom_congr σ₂ (dom_dom_congr σ₁ m) := rfl /-- `multilinear_map.dom_dom_congr` as an equivalence. This is declared separately because it does not work with dot notation. -/ def dom_dom_congr_equiv {R : Type u} {M₂ : Type v₂} {M₃ : Type v₃} [semiring R] [add_comm_monoid M₂] [add_comm_monoid M₃] [semimodule R M₂] [semimodule R M₃] {ι₁ : Type u_1} {ι₂ : Type u_2} [DecidableEq ι₁] [DecidableEq ι₂] (σ : ι₁ ≃ ι₂) : multilinear_map R (fun (i : ι₁) => M₂) M₃ ≃+ multilinear_map R (fun (i : ι₂) => M₂) M₃ := add_equiv.mk (dom_dom_congr σ) (dom_dom_congr (equiv.symm σ)) sorry sorry sorry end multilinear_map namespace linear_map /-- Composing a multilinear map with a linear map gives again a multilinear map. -/ def comp_multilinear_map {R : Type u} {ι : Type u'} {M₁ : ι → Type v₁} {M₂ : Type v₂} {M₃ : Type v₃} [DecidableEq ι] [semiring R] [(i : ι) → add_comm_monoid (M₁ i)] [add_comm_monoid M₂] [add_comm_monoid M₃] [(i : ι) → semimodule R (M₁ i)] [semimodule R M₂] [semimodule R M₃] (g : linear_map R M₂ M₃) (f : multilinear_map R M₁ M₂) : multilinear_map R M₁ M₃ := multilinear_map.mk (⇑g ∘ ⇑f) sorry sorry @[simp] theorem coe_comp_multilinear_map {R : Type u} {ι : Type u'} {M₁ : ι → Type v₁} {M₂ : Type v₂} {M₃ : Type v₃} [DecidableEq ι] [semiring R] [(i : ι) → add_comm_monoid (M₁ i)] [add_comm_monoid M₂] [add_comm_monoid M₃] [(i : ι) → semimodule R (M₁ i)] [semimodule R M₂] [semimodule R M₃] (g : linear_map R M₂ M₃) (f : multilinear_map R M₁ M₂) : ⇑(comp_multilinear_map g f) = ⇑g ∘ ⇑f := rfl theorem comp_multilinear_map_apply {R : Type u} {ι : Type u'} {M₁ : ι → Type v₁} {M₂ : Type v₂} {M₃ : Type v₃} [DecidableEq ι] [semiring R] [(i : ι) → add_comm_monoid (M₁ i)] [add_comm_monoid M₂] [add_comm_monoid M₃] [(i : ι) → semimodule R (M₁ i)] [semimodule R M₂] [semimodule R M₃] (g : linear_map R M₂ M₃) (f : multilinear_map R M₁ M₂) (m : (i : ι) → M₁ i) : coe_fn (comp_multilinear_map g f) m = coe_fn g (coe_fn f m) := rfl @[simp] theorem comp_multilinear_map_dom_dom_congr {R : Type u} {M₂ : Type v₂} {M₃ : Type v₃} {M' : Type v'} [semiring R] [add_comm_monoid M₂] [add_comm_monoid M₃] [add_comm_monoid M'] [semimodule R M₂] [semimodule R M₃] [semimodule R M'] {ι₁ : Type u_1} {ι₂ : Type u_2} [DecidableEq ι₁] [DecidableEq ι₂] (σ : ι₁ ≃ ι₂) (g : linear_map R M₂ M₃) (f : multilinear_map R (fun (i : ι₁) => M') M₂) : multilinear_map.dom_dom_congr σ (comp_multilinear_map g f) = comp_multilinear_map g (multilinear_map.dom_dom_congr σ f) := sorry end linear_map namespace multilinear_map /-- If one multiplies by `c i` the coordinates in a finset `s`, then the image under a multilinear map is multiplied by `∏ i in s, c i`. This is mainly an auxiliary statement to prove the result when `s = univ`, given in `map_smul_univ`, although it can be useful in its own right as it does not require the index set `ι` to be finite. -/ theorem map_piecewise_smul {R : Type u} {ι : Type u'} {M₁ : ι → Type v₁} {M₂ : Type v₂} [DecidableEq ι] [comm_semiring R] [(i : ι) → add_comm_monoid (M₁ i)] [add_comm_monoid M₂] [(i : ι) → semimodule R (M₁ i)] [semimodule R M₂] (f : multilinear_map R M₁ M₂) (c : ι → R) (m : (i : ι) → M₁ i) (s : finset ι) : coe_fn f (finset.piecewise s (fun (i : ι) => c i • m i) m) = (finset.prod s fun (i : ι) => c i) • coe_fn f m := sorry /-- Multiplicativity of a multilinear map along all coordinates at the same time, writing `f (λi, c i • m i)` as `(∏ i, c i) • f m`. -/ theorem map_smul_univ {R : Type u} {ι : Type u'} {M₁ : ι → Type v₁} {M₂ : Type v₂} [DecidableEq ι] [comm_semiring R] [(i : ι) → add_comm_monoid (M₁ i)] [add_comm_monoid M₂] [(i : ι) → semimodule R (M₁ i)] [semimodule R M₂] (f : multilinear_map R M₁ M₂) [fintype ι] (c : ι → R) (m : (i : ι) → M₁ i) : (coe_fn f fun (i : ι) => c i • m i) = (finset.prod finset.univ fun (i : ι) => c i) • coe_fn f m := sorry protected instance has_scalar {ι : Type u'} {M₁ : ι → Type v₁} {M₂ : Type v₂} [DecidableEq ι] [(i : ι) → add_comm_monoid (M₁ i)] [add_comm_monoid M₂] {R' : Type u_1} {A : Type u_2} [monoid R'] [semiring A] [(i : ι) → semimodule A (M₁ i)] [distrib_mul_action R' M₂] [semimodule A M₂] [smul_comm_class A R' M₂] : has_scalar R' (multilinear_map A M₁ M₂) := has_scalar.mk fun (c : R') (f : multilinear_map A M₁ M₂) => mk (fun (m : (i : ι) → M₁ i) => c • coe_fn f m) sorry sorry @[simp] theorem smul_apply {ι : Type u'} {M₁ : ι → Type v₁} {M₂ : Type v₂} [DecidableEq ι] [(i : ι) → add_comm_monoid (M₁ i)] [add_comm_monoid M₂] {R' : Type u_1} {A : Type u_2} [monoid R'] [semiring A] [(i : ι) → semimodule A (M₁ i)] [distrib_mul_action R' M₂] [semimodule A M₂] [smul_comm_class A R' M₂] (f : multilinear_map A M₁ M₂) (c : R') (m : (i : ι) → M₁ i) : coe_fn (c • f) m = c • coe_fn f m := rfl protected instance distrib_mul_action {ι : Type u'} {M₁ : ι → Type v₁} {M₂ : Type v₂} [DecidableEq ι] [(i : ι) → add_comm_monoid (M₁ i)] [add_comm_monoid M₂] {R' : Type u_1} {A : Type u_2} [monoid R'] [semiring A] [(i : ι) → semimodule A (M₁ i)] [distrib_mul_action R' M₂] [semimodule A M₂] [smul_comm_class A R' M₂] : distrib_mul_action R' (multilinear_map A M₁ M₂) := distrib_mul_action.mk sorry sorry /-- The space of multilinear maps over an algebra over `R` is a module over `R`, for the pointwise addition and scalar multiplication. -/ protected instance semimodule {ι : Type u'} {M₁ : ι → Type v₁} {M₂ : Type v₂} [DecidableEq ι] [(i : ι) → add_comm_monoid (M₁ i)] [add_comm_monoid M₂] {R' : Type u_1} {A : Type u_2} [semiring R'] [semiring A] [(i : ι) → semimodule A (M₁ i)] [semimodule R' M₂] [semimodule A M₂] [smul_comm_class A R' M₂] : semimodule R' (multilinear_map A M₁ M₂) := semimodule.mk sorry sorry /-- Given two multilinear maps `(ι₁ → N) → N₁` and `(ι₂ → N) → N₂`, this produces the map `(ι₁ ⊕ ι₂ → N) → N₁ ⊗ N₂` by taking the coproduct of the domain and the tensor product of the codomain. This can be thought of as combining `equiv.sum_arrow_equiv_prod_arrow.symm` with `tensor_product.map`, noting that the two operations can't be separated as the intermediate result is not a `multilinear_map`. While this can be generalized to work for dependent `Π i : ι₁, N'₁ i` instead of `ι₁ → N`, doing so introduces `sum.elim N'₁ N'₂` types in the result which are difficult to work with and not defeq to the simple case defined here. See [this zulip thread]( https://leanprover.zulipchat.com/#narrow/stream/217875-Is-there.20code.20for.20X.3F/topic/Instances.20on.20.60sum.2Eelim.20A.20B.20i.60/near/218484619). -/ def dom_coprod {R : Type u} [comm_semiring R] {ι₁ : Type u_1} {ι₂ : Type u_2} [DecidableEq ι₁] [DecidableEq ι₂] {N₁ : Type u_5} [add_comm_monoid N₁] [semimodule R N₁] {N₂ : Type u_6} [add_comm_monoid N₂] [semimodule R N₂] {N : Type u_7} [add_comm_monoid N] [semimodule R N] (a : multilinear_map R (fun (_x : ι₁) => N) N₁) (b : multilinear_map R (fun (_x : ι₂) => N) N₂) : multilinear_map R (fun (_x : ι₁ ⊕ ι₂) => N) (tensor_product R N₁ N₂) := mk (fun (v : ι₁ ⊕ ι₂ → N) => tensor_product.tmul R (coe_fn a fun (i : ι₁) => v (sum.inl i)) (coe_fn b fun (i : ι₂) => v (sum.inr i))) sorry sorry /-- A more bundled version of `multilinear_map.dom_coprod` that maps `((ι₁ → N) → N₁) ⊗ ((ι₂ → N) → N₂)` to `(ι₁ ⊕ ι₂ → N) → N₁ ⊗ N₂`. -/ def dom_coprod' {R : Type u} [comm_semiring R] {ι₁ : Type u_1} {ι₂ : Type u_2} [DecidableEq ι₁] [DecidableEq ι₂] {N₁ : Type u_5} [add_comm_monoid N₁] [semimodule R N₁] {N₂ : Type u_6} [add_comm_monoid N₂] [semimodule R N₂] {N : Type u_7} [add_comm_monoid N] [semimodule R N] : linear_map R (tensor_product R (multilinear_map R (fun (_x : ι₁) => N) N₁) (multilinear_map R (fun (_x : ι₂) => N) N₂)) (multilinear_map R (fun (_x : ι₁ ⊕ ι₂) => N) (tensor_product R N₁ N₂)) := tensor_product.lift (linear_map.mk₂ R dom_coprod sorry sorry sorry sorry) @[simp] theorem dom_coprod'_apply {R : Type u} [comm_semiring R] {ι₁ : Type u_1} {ι₂ : Type u_2} [DecidableEq ι₁] [DecidableEq ι₂] {N₁ : Type u_5} [add_comm_monoid N₁] [semimodule R N₁] {N₂ : Type u_6} [add_comm_monoid N₂] [semimodule R N₂] {N : Type u_7} [add_comm_monoid N] [semimodule R N] (a : multilinear_map R (fun (_x : ι₁) => N) N₁) (b : multilinear_map R (fun (_x : ι₂) => N) N₂) : coe_fn dom_coprod' (tensor_product.tmul R a b) = dom_coprod a b := rfl /-- When passed an `equiv.sum_congr`, `multilinear_map.dom_dom_congr` distributes over `multilinear_map.dom_coprod`. -/ theorem dom_coprod_dom_dom_congr_sum_congr {R : Type u} [comm_semiring R] {ι₁ : Type u_1} {ι₂ : Type u_2} {ι₃ : Type u_3} {ι₄ : Type u_4} [DecidableEq ι₁] [DecidableEq ι₂] [DecidableEq ι₃] [DecidableEq ι₄] {N₁ : Type u_5} [add_comm_monoid N₁] [semimodule R N₁] {N₂ : Type u_6} [add_comm_monoid N₂] [semimodule R N₂] {N : Type u_7} [add_comm_monoid N] [semimodule R N] (a : multilinear_map R (fun (_x : ι₁) => N) N₁) (b : multilinear_map R (fun (_x : ι₂) => N) N₂) (σa : ι₁ ≃ ι₃) (σb : ι₂ ≃ ι₄) : dom_dom_congr (equiv.sum_congr σa σb) (dom_coprod a b) = dom_coprod (dom_dom_congr σa a) (dom_dom_congr σb b) := rfl /-- Given an `R`-algebra `A`, `mk_pi_algebra` is the multilinear map on `A^ι` associating to `m` the product of all the `m i`. See also `multilinear_map.mk_pi_algebra_fin` for a version that works with a non-commutative algebra `A` but requires `ι = fin n`. -/ protected def mk_pi_algebra (R : Type u) (ι : Type u') [DecidableEq ι] [comm_semiring R] (A : Type u_1) [comm_semiring A] [algebra R A] [fintype ι] : multilinear_map R (fun (i : ι) => A) A := mk (fun (m : ι → A) => finset.prod finset.univ fun (i : ι) => m i) sorry sorry @[simp] theorem mk_pi_algebra_apply {R : Type u} {ι : Type u'} [DecidableEq ι] [comm_semiring R] {A : Type u_1} [comm_semiring A] [algebra R A] [fintype ι] (m : ι → A) : coe_fn (multilinear_map.mk_pi_algebra R ι A) m = finset.prod finset.univ fun (i : ι) => m i := rfl /-- Given an `R`-algebra `A`, `mk_pi_algebra_fin` is the multilinear map on `A^n` associating to `m` the product of all the `m i`. See also `multilinear_map.mk_pi_algebra` for a version that assumes `[comm_semiring A]` but works for `A^ι` with any finite type `ι`. -/ protected def mk_pi_algebra_fin (R : Type u) (n : ℕ) [comm_semiring R] (A : Type u_1) [semiring A] [algebra R A] : multilinear_map R (fun (i : fin n) => A) A := mk (fun (m : fin n → A) => list.prod (list.of_fn m)) sorry sorry @[simp] theorem mk_pi_algebra_fin_apply {R : Type u} {n : ℕ} [comm_semiring R] {A : Type u_1} [semiring A] [algebra R A] (m : fin n → A) : coe_fn (multilinear_map.mk_pi_algebra_fin R n A) m = list.prod (list.of_fn m) := rfl theorem mk_pi_algebra_fin_apply_const {R : Type u} {n : ℕ} [comm_semiring R] {A : Type u_1} [semiring A] [algebra R A] (a : A) : (coe_fn (multilinear_map.mk_pi_algebra_fin R n A) fun (_x : fin n) => a) = a ^ n := sorry /-- Given an `R`-multilinear map `f` taking values in `R`, `f.smul_right z` is the map sending `m` to `f m • z`. -/ def smul_right {R : Type u} {ι : Type u'} {M₁ : ι → Type v₁} {M₂ : Type v₂} [DecidableEq ι] [comm_semiring R] [(i : ι) → add_comm_monoid (M₁ i)] [add_comm_monoid M₂] [(i : ι) → semimodule R (M₁ i)] [semimodule R M₂] (f : multilinear_map R M₁ R) (z : M₂) : multilinear_map R M₁ M₂ := linear_map.comp_multilinear_map (linear_map.smul_right linear_map.id z) f @[simp] theorem smul_right_apply {R : Type u} {ι : Type u'} {M₁ : ι → Type v₁} {M₂ : Type v₂} [DecidableEq ι] [comm_semiring R] [(i : ι) → add_comm_monoid (M₁ i)] [add_comm_monoid M₂] [(i : ι) → semimodule R (M₁ i)] [semimodule R M₂] (f : multilinear_map R M₁ R) (z : M₂) (m : (i : ι) → M₁ i) : coe_fn (smul_right f z) m = coe_fn f m • z := rfl /-- The canonical multilinear map on `R^ι` when `ι` is finite, associating to `m` the product of all the `m i` (multiplied by a fixed reference element `z` in the target module). See also `mk_pi_algebra` for a more general version. -/ protected def mk_pi_ring (R : Type u) (ι : Type u') {M₂ : Type v₂} [DecidableEq ι] [comm_semiring R] [add_comm_monoid M₂] [semimodule R M₂] [fintype ι] (z : M₂) : multilinear_map R (fun (i : ι) => R) M₂ := smul_right (multilinear_map.mk_pi_algebra R ι R) z @[simp] theorem mk_pi_ring_apply {R : Type u} {ι : Type u'} {M₂ : Type v₂} [DecidableEq ι] [comm_semiring R] [add_comm_monoid M₂] [semimodule R M₂] [fintype ι] (z : M₂) (m : ι → R) : coe_fn (multilinear_map.mk_pi_ring R ι z) m = (finset.prod finset.univ fun (i : ι) => m i) • z := rfl theorem mk_pi_ring_apply_one_eq_self {R : Type u} {ι : Type u'} {M₂ : Type v₂} [DecidableEq ι] [comm_semiring R] [add_comm_monoid M₂] [semimodule R M₂] [fintype ι] (f : multilinear_map R (fun (i : ι) => R) M₂) : multilinear_map.mk_pi_ring R ι (coe_fn f fun (i : ι) => 1) = f := sorry protected instance has_neg {R : Type u} {ι : Type u'} {M₁ : ι → Type v₁} {M₂ : Type v₂} [DecidableEq ι] [semiring R] [(i : ι) → add_comm_monoid (M₁ i)] [add_comm_group M₂] [(i : ι) → semimodule R (M₁ i)] [semimodule R M₂] : Neg (multilinear_map R M₁ M₂) := { neg := fun (f : multilinear_map R M₁ M₂) => mk (fun (m : (i : ι) → M₁ i) => -coe_fn f m) sorry sorry } @[simp] theorem neg_apply {R : Type u} {ι : Type u'} {M₁ : ι → Type v₁} {M₂ : Type v₂} [DecidableEq ι] [semiring R] [(i : ι) → add_comm_monoid (M₁ i)] [add_comm_group M₂] [(i : ι) → semimodule R (M₁ i)] [semimodule R M₂] (f : multilinear_map R M₁ M₂) (m : (i : ι) → M₁ i) : coe_fn (-f) m = -coe_fn f m := rfl protected instance has_sub {R : Type u} {ι : Type u'} {M₁ : ι → Type v₁} {M₂ : Type v₂} [DecidableEq ι] [semiring R] [(i : ι) → add_comm_monoid (M₁ i)] [add_comm_group M₂] [(i : ι) → semimodule R (M₁ i)] [semimodule R M₂] : Sub (multilinear_map R M₁ M₂) := { sub := fun (f g : multilinear_map R M₁ M₂) => mk (fun (m : (i : ι) → M₁ i) => coe_fn f m - coe_fn g m) sorry sorry } @[simp] theorem sub_apply {R : Type u} {ι : Type u'} {M₁ : ι → Type v₁} {M₂ : Type v₂} [DecidableEq ι] [semiring R] [(i : ι) → add_comm_monoid (M₁ i)] [add_comm_group M₂] [(i : ι) → semimodule R (M₁ i)] [semimodule R M₂] (f : multilinear_map R M₁ M₂) (g : multilinear_map R M₁ M₂) (m : (i : ι) → M₁ i) : coe_fn (f - g) m = coe_fn f m - coe_fn g m := rfl protected instance add_comm_group {R : Type u} {ι : Type u'} {M₁ : ι → Type v₁} {M₂ : Type v₂} [DecidableEq ι] [semiring R] [(i : ι) → add_comm_monoid (M₁ i)] [add_comm_group M₂] [(i : ι) → semimodule R (M₁ i)] [semimodule R M₂] : add_comm_group (multilinear_map R M₁ M₂) := add_comm_group.mk Add.add sorry 0 sorry sorry Neg.neg Sub.sub sorry sorry @[simp] theorem map_neg {R : Type u} {ι : Type u'} {M₁ : ι → Type v₁} {M₂ : Type v₂} [DecidableEq ι] [semiring R] [(i : ι) → add_comm_group (M₁ i)] [add_comm_group M₂] [(i : ι) → semimodule R (M₁ i)] [semimodule R M₂] (f : multilinear_map R M₁ M₂) (m : (i : ι) → M₁ i) (i : ι) (x : M₁ i) : coe_fn f (function.update m i (-x)) = -coe_fn f (function.update m i x) := sorry @[simp] theorem map_sub {R : Type u} {ι : Type u'} {M₁ : ι → Type v₁} {M₂ : Type v₂} [DecidableEq ι] [semiring R] [(i : ι) → add_comm_group (M₁ i)] [add_comm_group M₂] [(i : ι) → semimodule R (M₁ i)] [semimodule R M₂] (f : multilinear_map R M₁ M₂) (m : (i : ι) → M₁ i) (i : ι) (x : M₁ i) (y : M₁ i) : coe_fn f (function.update m i (x - y)) = coe_fn f (function.update m i x) - coe_fn f (function.update m i y) := sorry /-- When `ι` is finite, multilinear maps on `R^ι` with values in `M₂` are in bijection with `M₂`, as such a multilinear map is completely determined by its value on the constant vector made of ones. We register this bijection as a linear equivalence in `multilinear_map.pi_ring_equiv`. -/ protected def pi_ring_equiv {R : Type u} {ι : Type u'} {M₂ : Type v₂} [DecidableEq ι] [comm_semiring R] [add_comm_group M₂] [semimodule R M₂] [fintype ι] : linear_equiv R M₂ (multilinear_map R (fun (i : ι) => R) M₂) := linear_equiv.mk (fun (z : M₂) => multilinear_map.mk_pi_ring R ι z) sorry sorry (fun (f : multilinear_map R (fun (i : ι) => R) M₂) => coe_fn f fun (i : ι) => 1) sorry sorry end multilinear_map /-! ### Currying We associate to a multilinear map in `n+1` variables (i.e., based on `fin n.succ`) two curried functions, named `f.curry_left` (which is a linear map on `E 0` taking values in multilinear maps in `n` variables) and `f.curry_right` (wich is a multilinear map in `n` variables taking values in linear maps on `E 0`). In both constructions, the variable that is singled out is `0`, to take advantage of the operations `cons` and `tail` on `fin n`. The inverse operations are called `uncurry_left` and `uncurry_right`. We also register linear equiv versions of these correspondences, in `multilinear_curry_left_equiv` and `multilinear_curry_right_equiv`. -/ /-! #### Left currying -/ /-- Given a linear map `f` from `M 0` to multilinear maps on `n` variables, construct the corresponding multilinear map on `n+1` variables obtained by concatenating the variables, given by `m ↦ f (m 0) (tail m)`-/ def linear_map.uncurry_left {R : Type u} {n : ℕ} {M : fin (Nat.succ n) → Type v} {M₂ : Type v₂} [comm_semiring R] [(i : fin (Nat.succ n)) → add_comm_monoid (M i)] [add_comm_monoid M₂] [(i : fin (Nat.succ n)) → semimodule R (M i)] [semimodule R M₂] (f : linear_map R (M 0) (multilinear_map R (fun (i : fin n) => M (fin.succ i)) M₂)) : multilinear_map R M M₂ := multilinear_map.mk (fun (m : (i : fin (Nat.succ n)) → M i) => coe_fn (coe_fn f (m 0)) (fin.tail m)) sorry sorry @[simp] theorem linear_map.uncurry_left_apply {R : Type u} {n : ℕ} {M : fin (Nat.succ n) → Type v} {M₂ : Type v₂} [comm_semiring R] [(i : fin (Nat.succ n)) → add_comm_monoid (M i)] [add_comm_monoid M₂] [(i : fin (Nat.succ n)) → semimodule R (M i)] [semimodule R M₂] (f : linear_map R (M 0) (multilinear_map R (fun (i : fin n) => M (fin.succ i)) M₂)) (m : (i : fin (Nat.succ n)) → M i) : coe_fn (linear_map.uncurry_left f) m = coe_fn (coe_fn f (m 0)) (fin.tail m) := rfl /-- Given a multilinear map `f` in `n+1` variables, split the first variable to obtain a linear map into multilinear maps in `n` variables, given by `x ↦ (m ↦ f (cons x m))`. -/ def multilinear_map.curry_left {R : Type u} {n : ℕ} {M : fin (Nat.succ n) → Type v} {M₂ : Type v₂} [comm_semiring R] [(i : fin (Nat.succ n)) → add_comm_monoid (M i)] [add_comm_monoid M₂] [(i : fin (Nat.succ n)) → semimodule R (M i)] [semimodule R M₂] (f : multilinear_map R M M₂) : linear_map R (M 0) (multilinear_map R (fun (i : fin n) => M (fin.succ i)) M₂) := linear_map.mk (fun (x : M 0) => multilinear_map.mk (fun (m : (i : fin n) → M (fin.succ i)) => coe_fn f (fin.cons x m)) sorry sorry) sorry sorry @[simp] theorem multilinear_map.curry_left_apply {R : Type u} {n : ℕ} {M : fin (Nat.succ n) → Type v} {M₂ : Type v₂} [comm_semiring R] [(i : fin (Nat.succ n)) → add_comm_monoid (M i)] [add_comm_monoid M₂] [(i : fin (Nat.succ n)) → semimodule R (M i)] [semimodule R M₂] (f : multilinear_map R M M₂) (x : M 0) (m : (i : fin n) → M (fin.succ i)) : coe_fn (coe_fn (multilinear_map.curry_left f) x) m = coe_fn f (fin.cons x m) := rfl @[simp] theorem linear_map.curry_uncurry_left {R : Type u} {n : ℕ} {M : fin (Nat.succ n) → Type v} {M₂ : Type v₂} [comm_semiring R] [(i : fin (Nat.succ n)) → add_comm_monoid (M i)] [add_comm_monoid M₂] [(i : fin (Nat.succ n)) → semimodule R (M i)] [semimodule R M₂] (f : linear_map R (M 0) (multilinear_map R (fun (i : fin n) => M (fin.succ i)) M₂)) : multilinear_map.curry_left (linear_map.uncurry_left f) = f := sorry @[simp] theorem multilinear_map.uncurry_curry_left {R : Type u} {n : ℕ} {M : fin (Nat.succ n) → Type v} {M₂ : Type v₂} [comm_semiring R] [(i : fin (Nat.succ n)) → add_comm_monoid (M i)] [add_comm_monoid M₂] [(i : fin (Nat.succ n)) → semimodule R (M i)] [semimodule R M₂] (f : multilinear_map R M M₂) : linear_map.uncurry_left (multilinear_map.curry_left f) = f := sorry /-- The space of multilinear maps on `Π(i : fin (n+1)), M i` is canonically isomorphic to the space of linear maps from `M 0` to the space of multilinear maps on `Π(i : fin n), M i.succ `, by separating the first variable. We register this isomorphism as a linear isomorphism in `multilinear_curry_left_equiv R M M₂`. The direct and inverse maps are given by `f.uncurry_left` and `f.curry_left`. Use these unless you need the full framework of linear equivs. -/ def multilinear_curry_left_equiv (R : Type u) {n : ℕ} (M : fin (Nat.succ n) → Type v) (M₂ : Type v₂) [comm_semiring R] [(i : fin (Nat.succ n)) → add_comm_monoid (M i)] [add_comm_monoid M₂] [(i : fin (Nat.succ n)) → semimodule R (M i)] [semimodule R M₂] : linear_equiv R (linear_map R (M 0) (multilinear_map R (fun (i : fin n) => M (fin.succ i)) M₂)) (multilinear_map R M M₂) := linear_equiv.mk linear_map.uncurry_left sorry sorry multilinear_map.curry_left linear_map.curry_uncurry_left sorry /-! #### Right currying -/ /-- Given a multilinear map `f` in `n` variables to the space of linear maps from `M (last n)` to `M₂`, construct the corresponding multilinear map on `n+1` variables obtained by concatenating the variables, given by `m ↦ f (init m) (m (last n))`-/ def multilinear_map.uncurry_right {R : Type u} {n : ℕ} {M : fin (Nat.succ n) → Type v} {M₂ : Type v₂} [comm_semiring R] [(i : fin (Nat.succ n)) → add_comm_monoid (M i)] [add_comm_monoid M₂] [(i : fin (Nat.succ n)) → semimodule R (M i)] [semimodule R M₂] (f : multilinear_map R (fun (i : fin n) => M (coe_fn fin.cast_succ i)) (linear_map R (M (fin.last n)) M₂)) : multilinear_map R M M₂ := multilinear_map.mk (fun (m : (i : fin (Nat.succ n)) → M i) => coe_fn (coe_fn f (fin.init m)) (m (fin.last n))) sorry sorry @[simp] theorem multilinear_map.uncurry_right_apply {R : Type u} {n : ℕ} {M : fin (Nat.succ n) → Type v} {M₂ : Type v₂} [comm_semiring R] [(i : fin (Nat.succ n)) → add_comm_monoid (M i)] [add_comm_monoid M₂] [(i : fin (Nat.succ n)) → semimodule R (M i)] [semimodule R M₂] (f : multilinear_map R (fun (i : fin n) => M (coe_fn fin.cast_succ i)) (linear_map R (M (fin.last n)) M₂)) (m : (i : fin (Nat.succ n)) → M i) : coe_fn (multilinear_map.uncurry_right f) m = coe_fn (coe_fn f (fin.init m)) (m (fin.last n)) := rfl /-- Given a multilinear map `f` in `n+1` variables, split the last variable to obtain a multilinear map in `n` variables taking values in linear maps from `M (last n)` to `M₂`, given by `m ↦ (x ↦ f (snoc m x))`. -/ def multilinear_map.curry_right {R : Type u} {n : ℕ} {M : fin (Nat.succ n) → Type v} {M₂ : Type v₂} [comm_semiring R] [(i : fin (Nat.succ n)) → add_comm_monoid (M i)] [add_comm_monoid M₂] [(i : fin (Nat.succ n)) → semimodule R (M i)] [semimodule R M₂] (f : multilinear_map R M M₂) : multilinear_map R (fun (i : fin n) => M (coe_fn fin.cast_succ i)) (linear_map R (M (fin.last n)) M₂) := multilinear_map.mk (fun (m : (i : fin n) → M (coe_fn fin.cast_succ i)) => linear_map.mk (fun (x : M (fin.last n)) => coe_fn f (fin.snoc m x)) sorry sorry) sorry sorry @[simp] theorem multilinear_map.curry_right_apply {R : Type u} {n : ℕ} {M : fin (Nat.succ n) → Type v} {M₂ : Type v₂} [comm_semiring R] [(i : fin (Nat.succ n)) → add_comm_monoid (M i)] [add_comm_monoid M₂] [(i : fin (Nat.succ n)) → semimodule R (M i)] [semimodule R M₂] (f : multilinear_map R M M₂) (m : (i : fin n) → M (coe_fn fin.cast_succ i)) (x : M (fin.last n)) : coe_fn (coe_fn (multilinear_map.curry_right f) m) x = coe_fn f (fin.snoc m x) := rfl @[simp] theorem multilinear_map.curry_uncurry_right {R : Type u} {n : ℕ} {M : fin (Nat.succ n) → Type v} {M₂ : Type v₂} [comm_semiring R] [(i : fin (Nat.succ n)) → add_comm_monoid (M i)] [add_comm_monoid M₂] [(i : fin (Nat.succ n)) → semimodule R (M i)] [semimodule R M₂] (f : multilinear_map R (fun (i : fin n) => M (coe_fn fin.cast_succ i)) (linear_map R (M (fin.last n)) M₂)) : multilinear_map.curry_right (multilinear_map.uncurry_right f) = f := sorry @[simp] theorem multilinear_map.uncurry_curry_right {R : Type u} {n : ℕ} {M : fin (Nat.succ n) → Type v} {M₂ : Type v₂} [comm_semiring R] [(i : fin (Nat.succ n)) → add_comm_monoid (M i)] [add_comm_monoid M₂] [(i : fin (Nat.succ n)) → semimodule R (M i)] [semimodule R M₂] (f : multilinear_map R M M₂) : multilinear_map.uncurry_right (multilinear_map.curry_right f) = f := sorry /-- The space of multilinear maps on `Π(i : fin (n+1)), M i` is canonically isomorphic to the space of linear maps from the space of multilinear maps on `Π(i : fin n), M i.cast_succ` to the space of linear maps on `M (last n)`, by separating the last variable. We register this isomorphism as a linear isomorphism in `multilinear_curry_right_equiv R M M₂`. The direct and inverse maps are given by `f.uncurry_right` and `f.curry_right`. Use these unless you need the full framework of linear equivs. -/ def multilinear_curry_right_equiv (R : Type u) {n : ℕ} (M : fin (Nat.succ n) → Type v) (M₂ : Type v₂) [comm_semiring R] [(i : fin (Nat.succ n)) → add_comm_monoid (M i)] [add_comm_monoid M₂] [(i : fin (Nat.succ n)) → semimodule R (M i)] [semimodule R M₂] : linear_equiv R (multilinear_map R (fun (i : fin n) => M (coe_fn fin.cast_succ i)) (linear_map R (M (fin.last n)) M₂)) (multilinear_map R M M₂) := linear_equiv.mk multilinear_map.uncurry_right sorry sorry multilinear_map.curry_right multilinear_map.curry_uncurry_right sorry namespace multilinear_map /-- The pushforward of an indexed collection of submodule `p i ⊆ M₁ i` by `f : M₁ → M₂`. Note that this is not a submodule - it is not closed under addition. -/ def map {R : Type u} {ι : Type u'} {M₁ : ι → Type v₁} {M₂ : Type v₂} [DecidableEq ι] [ring R] [(i : ι) → add_comm_monoid (M₁ i)] [add_comm_monoid M₂] [(i : ι) → semimodule R (M₁ i)] [semimodule R M₂] [Nonempty ι] (f : multilinear_map R M₁ M₂) (p : (i : ι) → submodule R (M₁ i)) : sub_mul_action R M₂ := sub_mul_action.mk (⇑f '' set_of fun (v : (i : ι) → M₁ i) => ∀ (i : ι), v i ∈ p i) sorry /-- The map is always nonempty. This lemma is needed to apply `sub_mul_action.zero_mem`. -/ theorem map_nonempty {R : Type u} {ι : Type u'} {M₁ : ι → Type v₁} {M₂ : Type v₂} [DecidableEq ι] [ring R] [(i : ι) → add_comm_monoid (M₁ i)] [add_comm_monoid M₂] [(i : ι) → semimodule R (M₁ i)] [semimodule R M₂] [Nonempty ι] (f : multilinear_map R M₁ M₂) (p : (i : ι) → submodule R (M₁ i)) : set.nonempty ↑(map f p) := Exists.intro (coe_fn f 0) (Exists.intro 0 { left := fun (i : ι) => submodule.zero_mem (p i), right := rfl }) /-- The range of a multilinear map, closed under scalar multiplication. -/ def range {R : Type u} {ι : Type u'} {M₁ : ι → Type v₁} {M₂ : Type v₂} [DecidableEq ι] [ring R] [(i : ι) → add_comm_monoid (M₁ i)] [add_comm_monoid M₂] [(i : ι) → semimodule R (M₁ i)] [semimodule R M₂] [Nonempty ι] (f : multilinear_map R M₁ M₂) : sub_mul_action R M₂ := map f fun (i : ι) => ⊤
4bc181e625b4ca44b6347398c6ef611fcc7f9f8c
05f637fa14ac28031cb1ea92086a0f4eb23ff2b1
/tests/lean/lua5.lean
f56bab9ebd5d8acb3cb4af3bcf24449b5da074f9
[ "Apache-2.0" ]
permissive
codyroux/lean0.1
1ce92751d664aacff0529e139083304a7bbc8a71
0dc6fb974aa85ed6f305a2f4b10a53a44ee5f0ef
refs/heads/master
1,610,830,535,062
1,402,150,480,000
1,402,150,480,000
19,588,851
2
0
null
null
null
null
UTF-8
Lean
false
false
263
lean
import Int. variable x : Int (* local N = 100 local env = get_environment() -- Create N variables with the same type of x typeofx = env:type_check(Const("x")) for i = 1, N do env:add_var("y_" .. i, typeofx) end *) print environment 101 check x + y_1 + y_2
c6d49264efc72426503a949d02d287042a08ea36
74addaa0e41490cbaf2abd313a764c96df57b05d
/Mathlib/algebra/group_power/default_auto.lean
aa9ea20c6099f60d5d3526aff2eb6a530a8eb000
[]
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
157
lean
import Mathlib.PrePort import Mathlib.Lean3Lib.init.default import Mathlib.algebra.group_power.lemmas import Mathlib.PostPort namespace Mathlib end Mathlib
12fe51f34eace5711343487cba29b02081a7b719
8d65764a9e5f0923a67fc435eb1a5a1d02fd80e3
/src/group_theory/perm/cycle_type.lean
970d4c2b0f5f8bc7d3a4d41a7d862aa2eed6b3ec
[ "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
19,720
lean
/- Copyright (c) 2020 Thomas Browning. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Thomas Browning -/ import algebra.gcd_monoid.multiset import combinatorics.partition import group_theory.perm.cycles import group_theory.sylow import ring_theory.int.basic import tactic.linarith /-! # Cycle Types In this file we define the cycle type of a partition. ## Main definitions - `σ.cycle_type` where `σ` is a permutation of a `fintype` - `σ.partition` where `σ` is a permutation of a `fintype` ## Main results - `sum_cycle_type` : The sum of `σ.cycle_type` equals `σ.support.card` - `lcm_cycle_type` : The lcm of `σ.cycle_type` equals `order_of σ` - `is_conj_iff_cycle_type_eq` : Two permutations are conjugate if and only if they have the same cycle type. -/ namespace equiv.perm open equiv list multiset variables {α : Type*} [fintype α] section cycle_type variables [decidable_eq α] /-- The cycle type of a permutation -/ def cycle_type (σ : perm α) : multiset ℕ := σ.cycle_factors_finset.1.map (finset.card ∘ support) lemma cycle_type_def (σ : perm α) : σ.cycle_type = σ.cycle_factors_finset.1.map (finset.card ∘ support) := rfl lemma cycle_type_eq' {σ : perm α} (s : finset (perm α)) (h1 : ∀ f : perm α, f ∈ s → f.is_cycle) (h2 : ∀ (a ∈ s) (b ∈ s), a ≠ b → disjoint a b) (h0 : s.noncomm_prod id (λ a ha b hb, (em (a = b)).by_cases (λ h, h ▸ commute.refl a) (set.pairwise_on.mono' (λ _ _, disjoint.commute) h2 a ha b hb)) = σ) : σ.cycle_type = s.1.map (finset.card ∘ support) := begin rw cycle_type_def, congr, rw cycle_factors_finset_eq_finset, exact ⟨h1, h2, h0⟩ end lemma cycle_type_eq {σ : perm α} (l : list (perm α)) (h0 : l.prod = σ) (h1 : ∀ σ : perm α, σ ∈ l → σ.is_cycle) (h2 : l.pairwise disjoint) : σ.cycle_type = l.map (finset.card ∘ support) := begin have hl : l.nodup := nodup_of_pairwise_disjoint_cycles h1 h2, rw cycle_type_eq' l.to_finset, { simp [list.erase_dup_eq_self.mpr hl] }, { simpa using h1 }, { simpa [hl] using h0 }, { simpa [list.erase_dup_eq_self.mpr hl] using list.forall_of_pairwise disjoint.symmetric h2 } end lemma cycle_type_one : (1 : perm α).cycle_type = 0 := cycle_type_eq [] rfl (λ _, false.elim) pairwise.nil lemma cycle_type_eq_zero {σ : perm α} : σ.cycle_type = 0 ↔ σ = 1 := by simp [cycle_type_def, cycle_factors_finset_eq_empty_iff] lemma card_cycle_type_eq_zero {σ : perm α} : σ.cycle_type.card = 0 ↔ σ = 1 := by rw [card_eq_zero, cycle_type_eq_zero] lemma two_le_of_mem_cycle_type {σ : perm α} {n : ℕ} (h : n ∈ σ.cycle_type) : 2 ≤ n := begin simp only [cycle_type_def, ←finset.mem_def, function.comp_app, multiset.mem_map, mem_cycle_factors_finset_iff] at h, obtain ⟨_, ⟨hc, -⟩, rfl⟩ := h, exact hc.two_le_card_support end lemma one_lt_of_mem_cycle_type {σ : perm α} {n : ℕ} (h : n ∈ σ.cycle_type) : 1 < n := two_le_of_mem_cycle_type h lemma is_cycle.cycle_type {σ : perm α} (hσ : is_cycle σ) : σ.cycle_type = [σ.support.card] := cycle_type_eq [σ] (mul_one σ) (λ τ hτ, (congr_arg is_cycle (list.mem_singleton.mp hτ)).mpr hσ) (pairwise_singleton disjoint σ) lemma card_cycle_type_eq_one {σ : perm α} : σ.cycle_type.card = 1 ↔ σ.is_cycle := begin rw card_eq_one, simp_rw [cycle_type_def, multiset.map_eq_singleton, ←finset.singleton_val, finset.val_inj, cycle_factors_finset_eq_singleton_iff], split, { rintro ⟨_, _, ⟨h, -⟩, -⟩, exact h }, { intro h, use [σ.support.card, σ], simp [h] } end lemma disjoint.cycle_type {σ τ : perm α} (h : disjoint σ τ) : (σ * τ).cycle_type = σ.cycle_type + τ.cycle_type := begin rw [cycle_type_def, cycle_type_def, cycle_type_def, h.cycle_factors_finset_mul_eq_union, ←map_add, finset.union_val, multiset.add_eq_union_iff_disjoint.mpr _], rw [←finset.disjoint_val], exact h.disjoint_cycle_factors_finset end lemma cycle_type_inv (σ : perm α) : σ⁻¹.cycle_type = σ.cycle_type := cycle_induction_on (λ τ : perm α, τ⁻¹.cycle_type = τ.cycle_type) σ rfl (λ σ hσ, by rw [hσ.cycle_type, hσ.inv.cycle_type, support_inv]) (λ σ τ hστ hc hσ hτ, by rw [mul_inv_rev, hστ.cycle_type, ←hσ, ←hτ, add_comm, disjoint.cycle_type (λ x, or.imp (λ h : τ x = x, inv_eq_iff_eq.mpr h.symm) (λ h : σ x = x, inv_eq_iff_eq.mpr h.symm) (hστ x).symm)]) lemma cycle_type_conj {σ τ : perm α} : (τ * σ * τ⁻¹).cycle_type = σ.cycle_type := begin revert τ, apply cycle_induction_on _ σ, { intro, simp }, { intros σ hσ τ, rw [hσ.cycle_type, hσ.is_cycle_conj.cycle_type, card_support_conj] }, { intros σ τ hd hc hσ hτ π, rw [← conj_mul, hd.cycle_type, disjoint.cycle_type, hσ, hτ], intro a, apply (hd (π⁻¹ a)).imp _ _; { intro h, rw [perm.mul_apply, perm.mul_apply, h, apply_inv_self] } } end lemma sum_cycle_type (σ : perm α) : σ.cycle_type.sum = σ.support.card := cycle_induction_on (λ τ : perm α, τ.cycle_type.sum = τ.support.card) σ (by rw [cycle_type_one, sum_zero, support_one, finset.card_empty]) (λ σ hσ, by rw [hσ.cycle_type, coe_sum, list.sum_singleton]) (λ σ τ hστ hc hσ hτ, by rw [hστ.cycle_type, sum_add, hσ, hτ, hστ.card_support_mul]) lemma sign_of_cycle_type (σ : perm α) : sign σ = (σ.cycle_type.map (λ n, -(-1 : units ℤ) ^ n)).prod := cycle_induction_on (λ τ : perm α, sign τ = (τ.cycle_type.map (λ n, -(-1 : units ℤ) ^ n)).prod) σ (by rw [sign_one, cycle_type_one, map_zero, prod_zero]) (λ σ hσ, by rw [hσ.sign, hσ.cycle_type, coe_map, coe_prod, list.map_singleton, list.prod_singleton]) (λ σ τ hστ hc hσ hτ, by rw [sign_mul, hσ, hτ, hστ.cycle_type, map_add, prod_add]) lemma lcm_cycle_type (σ : perm α) : σ.cycle_type.lcm = order_of σ := cycle_induction_on (λ τ : perm α, τ.cycle_type.lcm = order_of τ) σ (by rw [cycle_type_one, lcm_zero, order_of_one]) (λ σ hσ, by rw [hσ.cycle_type, ←singleton_coe, lcm_singleton, order_of_is_cycle hσ, normalize_eq]) (λ σ τ hστ hc hσ hτ, by rw [hστ.cycle_type, lcm_add, lcm_eq_nat_lcm, hστ.order_of, hσ, hτ]) lemma dvd_of_mem_cycle_type {σ : perm α} {n : ℕ} (h : n ∈ σ.cycle_type) : n ∣ order_of σ := begin rw ← lcm_cycle_type, exact dvd_lcm h, end lemma order_of_cycle_of_dvd_order_of (f : perm α) (x : α) : order_of (cycle_of f x) ∣ order_of f := begin by_cases hx : f x = x, { rw ←cycle_of_eq_one_iff at hx, simp [hx] }, { refine dvd_of_mem_cycle_type _, rw [cycle_type, multiset.mem_map], refine ⟨f.cycle_of x, _, _⟩, { rwa [←finset.mem_def, cycle_of_mem_cycle_factors_finset_iff, mem_support] }, { simp [order_of_is_cycle (is_cycle_cycle_of _ hx)] } } end lemma two_dvd_card_support {σ : perm α} (hσ : σ ^ 2 = 1) : 2 ∣ σ.support.card := (congr_arg (has_dvd.dvd 2) σ.sum_cycle_type).mp (multiset.dvd_sum (λ n hn, by rw le_antisymm (nat.le_of_dvd zero_lt_two (dvd_trans (dvd_of_mem_cycle_type hn) (order_of_dvd_of_pow_eq_one hσ))) (two_le_of_mem_cycle_type hn))) lemma cycle_type_prime_order {σ : perm α} (hσ : (order_of σ).prime) : ∃ n : ℕ, σ.cycle_type = repeat (order_of σ) (n + 1) := begin rw eq_repeat_of_mem (λ n hn, or_iff_not_imp_left.mp (hσ.2 n (dvd_of_mem_cycle_type hn)) (ne_of_gt (one_lt_of_mem_cycle_type hn))), use σ.cycle_type.card - 1, rw nat.sub_add_cancel, rw [nat.succ_le_iff, pos_iff_ne_zero, ne, card_cycle_type_eq_zero], rintro rfl, rw order_of_one at hσ, exact hσ.ne_one rfl, end lemma is_cycle_of_prime_order {σ : perm α} (h1 : (order_of σ).prime) (h2 : σ.support.card < 2 * (order_of σ)) : σ.is_cycle := begin obtain ⟨n, hn⟩ := cycle_type_prime_order h1, rw [←σ.sum_cycle_type, hn, multiset.sum_repeat, nsmul_eq_mul, nat.cast_id, mul_lt_mul_right (order_of_pos σ), nat.succ_lt_succ_iff, nat.lt_succ_iff, nat.le_zero_iff] at h2, rw [←card_cycle_type_eq_one, hn, card_repeat, h2], end lemma cycle_type_le_of_mem_cycle_factors_finset {f g : perm α} (hf : f ∈ g.cycle_factors_finset) : f.cycle_type ≤ g.cycle_type := begin rw mem_cycle_factors_finset_iff at hf, rw [cycle_type_def, cycle_type_def, hf.left.cycle_factors_finset_eq_singleton], refine map_le_map _, simpa [←finset.mem_def, mem_cycle_factors_finset_iff] using hf end lemma cycle_type_mul_mem_cycle_factors_finset_eq_sub {f g : perm α} (hf : f ∈ g.cycle_factors_finset) : (g * f⁻¹).cycle_type = g.cycle_type - f.cycle_type := begin suffices : (g * f⁻¹).cycle_type + f.cycle_type = g.cycle_type - f.cycle_type + f.cycle_type, { rw multiset.sub_add_cancel (cycle_type_le_of_mem_cycle_factors_finset hf) at this, simp [←this] }, simp [←(disjoint_mul_inv_of_mem_cycle_factors_finset hf).cycle_type, multiset.sub_add_cancel (cycle_type_le_of_mem_cycle_factors_finset hf)] end theorem is_conj_of_cycle_type_eq {σ τ : perm α} (h : cycle_type σ = cycle_type τ) : is_conj σ τ := begin revert τ, apply cycle_induction_on _ σ, { intros τ h, rw [cycle_type_one, eq_comm, cycle_type_eq_zero] at h, rw h }, { intros σ hσ τ hστ, have hτ := card_cycle_type_eq_one.2 hσ, rw [hστ, card_cycle_type_eq_one] at hτ, apply hσ.is_conj hτ, rw [hσ.cycle_type, hτ.cycle_type, coe_eq_coe, singleton_perm] at hστ, simp only [and_true, eq_self_iff_true] at hστ, exact hστ }, { intros σ τ hστ hσ h1 h2 π hπ, rw [hστ.cycle_type] at hπ, { have h : σ.support.card ∈ map (finset.card ∘ perm.support) π.cycle_factors_finset.val, { simp [←cycle_type_def, ←hπ, hσ.cycle_type] }, obtain ⟨σ', hσ'l, hσ'⟩ := multiset.mem_map.mp h, have key : is_conj (σ' * (π * σ'⁻¹)) π, { rw is_conj_iff, use σ'⁻¹, simp [mul_assoc] }, refine is_conj_trans _ key, have hs : σ.cycle_type = σ'.cycle_type, { rw [←finset.mem_def, mem_cycle_factors_finset_iff] at hσ'l, rw [hσ.cycle_type, ←hσ', hσ'l.left.cycle_type] }, refine hστ.is_conj_mul (h1 hs) (h2 _) _, { rw [cycle_type_mul_mem_cycle_factors_finset_eq_sub, ←hπ, add_comm, hs, multiset.add_sub_cancel], rwa finset.mem_def }, { exact (disjoint_mul_inv_of_mem_cycle_factors_finset hσ'l).symm } } } end theorem is_conj_iff_cycle_type_eq {σ τ : perm α} : is_conj σ τ ↔ σ.cycle_type = τ.cycle_type := ⟨λ h, begin obtain ⟨π, rfl⟩ := is_conj_iff.1 h, rw cycle_type_conj, end, is_conj_of_cycle_type_eq⟩ @[simp] lemma cycle_type_extend_domain {β : Type*} [fintype β] [decidable_eq β] {p : β → Prop} [decidable_pred p] (f : α ≃ subtype p) {g : perm α} : cycle_type (g.extend_domain f) = cycle_type g := begin apply cycle_induction_on _ g, { rw [extend_domain_one, cycle_type_one, cycle_type_one] }, { intros σ hσ, rw [(hσ.extend_domain f).cycle_type, hσ.cycle_type, card_support_extend_domain] }, { intros σ τ hd hc hσ hτ, rw [hd.cycle_type, ← extend_domain_mul, (hd.extend_domain f).cycle_type, hσ, hτ] } end lemma mem_cycle_type_iff {n : ℕ} {σ : perm α} : n ∈ cycle_type σ ↔ ∃ c τ : perm α, σ = c * τ ∧ disjoint c τ ∧ is_cycle c ∧ c.support.card = n := begin split, { intro h, obtain ⟨l, rfl, hlc, hld⟩ := trunc_cycle_factors σ, rw cycle_type_eq _ rfl hlc hld at h, obtain ⟨c, cl, rfl⟩ := list.exists_of_mem_map h, rw (list.perm_cons_erase cl).pairwise_iff (λ _ _ hd, _) at hld, swap, { exact hd.symm }, refine ⟨c, (l.erase c).prod, _, _, hlc _ cl, rfl⟩, { rw [← list.prod_cons, (list.perm_cons_erase cl).symm.prod_eq' (hld.imp (λ _ _, disjoint.commute))] }, { exact disjoint_prod_right _ (λ g, list.rel_of_pairwise_cons hld) } }, { rintros ⟨c, t, rfl, hd, hc, rfl⟩, simp [hd.cycle_type, hc.cycle_type] } end lemma le_card_support_of_mem_cycle_type {n : ℕ} {σ : perm α} (h : n ∈ cycle_type σ) : n ≤ σ.support.card := (le_sum_of_mem h).trans (le_of_eq σ.sum_cycle_type) lemma cycle_type_of_card_le_mem_cycle_type_add_two {n : ℕ} {g : perm α} (hn2 : fintype.card α < n + 2) (hng : n ∈ g.cycle_type) : g.cycle_type = {n} := begin obtain ⟨c, g', rfl, hd, hc, rfl⟩ := mem_cycle_type_iff.1 hng, by_cases g'1 : g' = 1, { rw [hd.cycle_type, hc.cycle_type, multiset.singleton_eq_singleton, multiset.singleton_coe, g'1, cycle_type_one, add_zero] }, contrapose! hn2, apply le_trans _ (c * g').support.card_le_univ, rw [hd.card_support_mul], exact add_le_add_left (two_le_card_support_of_ne_one g'1) _, end end cycle_type lemma is_cycle_of_prime_order' {σ : perm α} (h1 : (order_of σ).prime) (h2 : fintype.card α < 2 * (order_of σ)) : σ.is_cycle := begin classical, exact is_cycle_of_prime_order h1 (lt_of_le_of_lt σ.support.card_le_univ h2), end lemma is_cycle_of_prime_order'' {σ : perm α} (h1 : (fintype.card α).prime) (h2 : order_of σ = fintype.card α) : σ.is_cycle := is_cycle_of_prime_order' ((congr_arg nat.prime h2).mpr h1) begin classical, rw [←one_mul (fintype.card α), ←h2, mul_lt_mul_right (order_of_pos σ)], exact one_lt_two, end lemma subgroup_eq_top_of_swap_mem [decidable_eq α] {H : subgroup (perm α)} [d : decidable_pred (∈ H)] {τ : perm α} (h0 : (fintype.card α).prime) (h1 : fintype.card α ∣ fintype.card H) (h2 : τ ∈ H) (h3 : is_swap τ) : H = ⊤ := begin haveI : fact (fintype.card α).prime := ⟨h0⟩, obtain ⟨σ, hσ⟩ := sylow.exists_prime_order_of_dvd_card (fintype.card α) h1, have hσ1 : order_of (σ : perm α) = fintype.card α := (order_of_subgroup σ).trans hσ, have hσ2 : is_cycle ↑σ := is_cycle_of_prime_order'' h0 hσ1, have hσ3 : (σ : perm α).support = ⊤ := finset.eq_univ_of_card (σ : perm α).support ((order_of_is_cycle hσ2).symm.trans hσ1), have hσ4 : subgroup.closure {↑σ, τ} = ⊤ := closure_prime_cycle_swap h0 hσ2 hσ3 h3, rw [eq_top_iff, ←hσ4, subgroup.closure_le, set.insert_subset, set.singleton_subset_iff], exact ⟨subtype.mem σ, h2⟩, end section partition variables [decidable_eq α] /-- The partition corresponding to a permutation -/ def partition (σ : perm α) : partition (fintype.card α) := { parts := σ.cycle_type + repeat 1 (fintype.card α - σ.support.card), parts_pos := λ n hn, begin cases mem_add.mp hn with hn hn, { exact zero_lt_one.trans (one_lt_of_mem_cycle_type hn) }, { exact lt_of_lt_of_le zero_lt_one (ge_of_eq (multiset.eq_of_mem_repeat hn)) }, end, parts_sum := by rw [sum_add, sum_cycle_type, multiset.sum_repeat, nsmul_eq_mul, nat.cast_id, mul_one, nat.add_sub_cancel' σ.support.card_le_univ] } lemma parts_partition {σ : perm α} : σ.partition.parts = σ.cycle_type + repeat 1 (fintype.card α - σ.support.card) := rfl lemma filter_parts_partition_eq_cycle_type {σ : perm α} : (partition σ).parts.filter (λ n, 2 ≤ n) = σ.cycle_type := begin rw [parts_partition, filter_add, multiset.filter_eq_self.2 (λ _, two_le_of_mem_cycle_type), multiset.filter_eq_nil.2 (λ a h, _), add_zero], rw multiset.eq_of_mem_repeat h, dec_trivial end lemma partition_eq_of_is_conj {σ τ : perm α} : is_conj σ τ ↔ σ.partition = τ.partition := begin rw [is_conj_iff_cycle_type_eq], refine ⟨λ h, _, λ h, _⟩, { rw [partition.ext_iff, parts_partition, parts_partition, ← sum_cycle_type, ← sum_cycle_type, h] }, { rw [← filter_parts_partition_eq_cycle_type, ← filter_parts_partition_eq_cycle_type, h] } end end partition /-! ### 3-cycles -/ /-- A three-cycle is a cycle of length 3. -/ def is_three_cycle [decidable_eq α] (σ : perm α) : Prop := σ.cycle_type = {3} namespace is_three_cycle variables [decidable_eq α] {σ : perm α} lemma cycle_type (h : is_three_cycle σ) : σ.cycle_type = {3} := h lemma card_support (h : is_three_cycle σ) : σ.support.card = 3 := by rw [←sum_cycle_type, h.cycle_type, singleton_eq_singleton, multiset.sum_cons, sum_zero] lemma _root_.card_support_eq_three_iff : σ.support.card = 3 ↔ σ.is_three_cycle := begin refine ⟨λ h, _, is_three_cycle.card_support⟩, by_cases h0 : σ.cycle_type = 0, { rw [←sum_cycle_type, h0, sum_zero] at h, exact (ne_of_lt zero_lt_three h).elim }, obtain ⟨n, hn⟩ := exists_mem_of_ne_zero h0, by_cases h1 : σ.cycle_type.erase n = 0, { rw [←sum_cycle_type, ←cons_erase hn, h1, multiset.sum_singleton] at h, rw [is_three_cycle, ←cons_erase hn, h1, h, singleton_eq_singleton] }, obtain ⟨m, hm⟩ := exists_mem_of_ne_zero h1, rw [←sum_cycle_type, ←cons_erase hn, ←cons_erase hm, multiset.sum_cons, multiset.sum_cons] at h, linarith [two_le_of_mem_cycle_type hn, two_le_of_mem_cycle_type (mem_of_mem_erase hm)], end lemma is_cycle (h : is_three_cycle σ) : is_cycle σ := by rw [←card_cycle_type_eq_one, h.cycle_type, singleton_eq_singleton, card_singleton] lemma sign (h : is_three_cycle σ) : sign σ = 1 := begin rw [sign_of_cycle_type, h.cycle_type], refl, end lemma inv {f : perm α} (h : is_three_cycle f) : is_three_cycle (f⁻¹) := by rwa [is_three_cycle, cycle_type_inv] @[simp] lemma inv_iff {f : perm α} : is_three_cycle (f⁻¹) ↔ is_three_cycle f := ⟨by { rw ← inv_inv f, apply inv }, inv⟩ lemma order_of {g : perm α} (ht : is_three_cycle g) : order_of g = 3 := by rw [←lcm_cycle_type, ht.cycle_type, multiset.singleton_eq_singleton, multiset.lcm_singleton, normalize_eq] lemma is_three_cycle_sq {g : perm α} (ht : is_three_cycle g) : is_three_cycle (g * g) := begin rw [←pow_two, ←card_support_eq_three_iff, support_pow_coprime, ht.card_support], rw [ht.order_of, nat.coprime_iff_gcd_eq_one], norm_num, end end is_three_cycle section variable [decidable_eq α] lemma is_three_cycle_swap_mul_swap_same {a b c : α} (ab : a ≠ b) (ac : a ≠ c) (bc : b ≠ c) : is_three_cycle (swap a b * swap a c) := begin suffices h : support (swap a b * swap a c) = {a, b, c}, { rw [←card_support_eq_three_iff, h], simp [ab, ac, bc] }, apply le_antisymm ((support_mul_le _ _).trans (λ x, _)) (λ x hx, _), { simp [ab, ac, bc] }, { simp only [finset.mem_insert, finset.mem_singleton] at hx, rw mem_support, simp only [perm.coe_mul, function.comp_app, ne.def], obtain rfl | rfl | rfl := hx, { rw [swap_apply_left, swap_apply_of_ne_of_ne ac.symm bc.symm], exact ac.symm }, { rw [swap_apply_of_ne_of_ne ab.symm bc, swap_apply_right], exact ab }, { rw [swap_apply_right, swap_apply_left], exact bc } } end open subgroup lemma swap_mul_swap_same_mem_closure_three_cycles {a b c : α} (ab : a ≠ b) (ac : a ≠ c) : (swap a b * swap a c) ∈ closure {σ : perm α | is_three_cycle σ } := begin by_cases bc : b = c, { subst bc, simp [one_mem] }, exact subset_closure (is_three_cycle_swap_mul_swap_same ab ac bc) end lemma is_swap.mul_mem_closure_three_cycles {σ τ : perm α} (hσ : is_swap σ) (hτ : is_swap τ) : σ * τ ∈ closure {σ : perm α | is_three_cycle σ } := begin obtain ⟨a, b, ab, rfl⟩ := hσ, obtain ⟨c, d, cd, rfl⟩ := hτ, by_cases ac : a = c, { subst ac, exact swap_mul_swap_same_mem_closure_three_cycles ab cd }, have h' : swap a b * swap c d = swap a b * swap a c * (swap c a * swap c d), { simp [swap_comm c a, mul_assoc] }, rw h', exact mul_mem _ (swap_mul_swap_same_mem_closure_three_cycles ab ac) (swap_mul_swap_same_mem_closure_three_cycles (ne.symm ac) cd), end end end equiv.perm
c0edf6ea89b66f688523770f1cf1dbd3d1e64a49
367134ba5a65885e863bdc4507601606690974c1
/src/data/matrix/notation.lean
dd6703256ec6ac885f4f47d5b3499122b49b6c25
[ "Apache-2.0" ]
permissive
kodyvajjha/mathlib
9bead00e90f68269a313f45f5561766cfd8d5cad
b98af5dd79e13a38d84438b850a2e8858ec21284
refs/heads/master
1,624,350,366,310
1,615,563,062,000
1,615,563,062,000
162,666,963
0
0
Apache-2.0
1,545,367,651,000
1,545,367,651,000
null
UTF-8
Lean
false
false
17,833
lean
/- Copyright (c) 2020 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen Notation for vectors and matrices -/ import data.fintype.card import data.matrix.basic import tactic.fin_cases /-! # Matrix and vector notation This file defines notation for vectors and matrices. Given `a b c d : α`, the notation allows us to write `![a, b, c, d] : fin 4 → α`. Nesting vectors gives a matrix, so `![![a, b], ![c, d]] : matrix (fin 2) (fin 2) α`. This file includes `simp` lemmas for applying operations in `data.matrix.basic` to values built out of this notation. ## Main definitions * `vec_empty` is the empty vector (or `0` by `n` matrix) `![]` * `vec_cons` prepends an entry to a vector, so `![a, b]` is `vec_cons a (vec_cons b vec_empty)` ## Implementation notes The `simp` lemmas require that one of the arguments is of the form `vec_cons _ _`. This ensures `simp` works with entries only when (some) entries are already given. In other words, this notation will only appear in the output of `simp` if it already appears in the input. ## Notations The main new notation is `![a, b]`, which gets expanded to `vec_cons a (vec_cons b vec_empty)`. ## Examples Examples of usage can be found in the `test/matrix.lean` file. -/ namespace matrix universe u variables {α : Type u} open_locale matrix section matrix_notation /-- `![]` is the vector with no entries. -/ def vec_empty : fin 0 → α := fin_zero_elim /-- `vec_cons h t` prepends an entry `h` to a vector `t`. The inverse functions are `vec_head` and `vec_tail`. The notation `![a, b, ...]` expands to `vec_cons a (vec_cons b ...)`. -/ def vec_cons {n : ℕ} (h : α) (t : fin n → α) : fin n.succ → α := fin.cons h t notation `![` l:(foldr `, ` (h t, vec_cons h t) vec_empty `]`) := l /-- `vec_head v` gives the first entry of the vector `v` -/ def vec_head {n : ℕ} (v : fin n.succ → α) : α := v 0 /-- `vec_tail v` gives a vector consisting of all entries of `v` except the first -/ def vec_tail {n : ℕ} (v : fin n.succ → α) : fin n → α := v ∘ fin.succ end matrix_notation variables {m n o : ℕ} {m' n' o' : Type*} [fintype m'] [fintype n'] [fintype o'] lemma empty_eq (v : fin 0 → α) : v = ![] := by { ext i, fin_cases i } section val @[simp] lemma head_fin_const (a : α) : vec_head (λ (i : fin (n + 1)), a) = a := rfl @[simp] lemma cons_val_zero (x : α) (u : fin m → α) : vec_cons x u 0 = x := rfl lemma cons_val_zero' (h : 0 < m.succ) (x : α) (u : fin m → α) : vec_cons x u ⟨0, h⟩ = x := rfl @[simp] lemma cons_val_succ (x : α) (u : fin m → α) (i : fin m) : vec_cons x u i.succ = u i := by simp [vec_cons] @[simp] lemma cons_val_succ' {i : ℕ} (h : i.succ < m.succ) (x : α) (u : fin m → α) : vec_cons x u ⟨i.succ, h⟩ = u ⟨i, nat.lt_of_succ_lt_succ h⟩ := by simp only [vec_cons, fin.cons, fin.cases_succ'] @[simp] lemma head_cons (x : α) (u : fin m → α) : vec_head (vec_cons x u) = x := rfl @[simp] lemma tail_cons (x : α) (u : fin m → α) : vec_tail (vec_cons x u) = u := by { ext, simp [vec_tail] } @[simp] lemma empty_val' {n' : Type*} (j : n') : (λ i, (![] : fin 0 → n' → α) i j) = ![] := empty_eq _ @[simp] lemma cons_val' (v : n' → α) (B : matrix (fin m) n' α) (i j) : vec_cons v B i j = vec_cons (v j) (λ i, B i j) i := by { refine fin.cases _ _ i; simp } @[simp] lemma head_val' (B : matrix (fin m.succ) n' α) (j : n') : vec_head (λ i, B i j) = vec_head B j := rfl @[simp] lemma tail_val' (B : matrix (fin m.succ) n' α) (j : n') : vec_tail (λ i, B i j) = λ i, vec_tail B i j := by { ext, simp [vec_tail] } @[simp] lemma cons_head_tail (u : fin m.succ → α) : vec_cons (vec_head u) (vec_tail u) = u := fin.cons_self_tail _ @[simp] lemma range_cons (x : α) (u : fin n → α) : set.range (vec_cons x u) = {x} ∪ set.range u := set.ext $ λ y, by simp [fin.exists_fin_succ, eq_comm] @[simp] lemma range_empty (u : fin 0 → α) : set.range u = ∅ := set.range_eq_empty.2 $ λ ⟨k⟩, k.elim0 /-- `![a, b, ...] 1` is equal to `b`. The simplifier needs a special lemma for length `≥ 2`, in addition to `cons_val_succ`, because `1 : fin 1 = 0 : fin 1`. -/ @[simp] lemma cons_val_one (x : α) (u : fin m.succ → α) : vec_cons x u 1 = vec_head u := cons_val_succ x u 0 @[simp] lemma cons_val_fin_one (x : α) (u : fin 0 → α) (i : fin 1) : vec_cons x u i = x := by { fin_cases i, refl } lemma cons_fin_one (x : α) (u : fin 0 → α) : vec_cons x u = (λ _, x) := funext (cons_val_fin_one x u) /-! ### Numeral (`bit0` and `bit1`) indices The following definitions and `simp` lemmas are to allow any numeral-indexed element of a vector given with matrix notation to be extracted by `simp` (even when the numeral is larger than the number of elements in the vector, which is taken modulo that number of elements by virtue of the semantics of `bit0` and `bit1` and of addition on `fin n`). -/ @[simp] lemma empty_append (v : fin n → α) : fin.append (zero_add _).symm ![] v = v := by { ext, simp [fin.append] } @[simp] lemma cons_append (ho : o + 1 = m + 1 + n) (x : α) (u : fin m → α) (v : fin n → α) : fin.append ho (vec_cons x u) v = vec_cons x (fin.append (by rwa [add_assoc, add_comm 1, ←add_assoc, add_right_cancel_iff] at ho) u v) := begin ext i, simp_rw [fin.append], split_ifs with h, { rcases i with ⟨⟨⟩ | i, hi⟩, { simp }, { simp only [nat.succ_eq_add_one, add_lt_add_iff_right, fin.coe_mk] at h, simp [h] } }, { rcases i with ⟨⟨⟩ | i, hi⟩, { simpa using h }, { rw [not_lt, fin.coe_mk, nat.succ_eq_add_one, add_le_add_iff_right] at h, simp [h] } } end /-- `vec_alt0 v` gives a vector with half the length of `v`, with only alternate elements (even-numbered). -/ def vec_alt0 (hm : m = n + n) (v : fin m → α) (k : fin n) : α := v ⟨(k : ℕ) + k, hm.symm ▸ add_lt_add k.property k.property⟩ /-- `vec_alt1 v` gives a vector with half the length of `v`, with only alternate elements (odd-numbered). -/ def vec_alt1 (hm : m = n + n) (v : fin m → α) (k : fin n) : α := v ⟨(k : ℕ) + k + 1, hm.symm ▸ nat.add_succ_lt_add k.property k.property⟩ lemma vec_alt0_append (v : fin n → α) : vec_alt0 rfl (fin.append rfl v v) = v ∘ bit0 := begin ext i, simp_rw [function.comp, bit0, vec_alt0, fin.append], split_ifs with h; congr, { rw fin.coe_mk at h, simp only [fin.ext_iff, fin.coe_add, fin.coe_mk], exact (nat.mod_eq_of_lt h).symm }, { rw [fin.coe_mk, not_lt] at h, simp only [fin.ext_iff, fin.coe_add, fin.coe_mk, nat.mod_eq_sub_mod h], refine (nat.mod_eq_of_lt _).symm, rw nat.sub_lt_left_iff_lt_add h, exact add_lt_add i.property i.property } end lemma vec_alt1_append (v : fin (n + 1) → α) : vec_alt1 rfl (fin.append rfl v v) = v ∘ bit1 := begin ext i, simp_rw [function.comp, vec_alt1, fin.append], cases n, { simp, congr }, { split_ifs with h; simp_rw [bit1, bit0]; congr, { rw fin.coe_mk at h, simp only [fin.ext_iff, fin.coe_add, fin.coe_mk], rw nat.mod_eq_of_lt (nat.lt_of_succ_lt h), exact (nat.mod_eq_of_lt h).symm }, { rw [fin.coe_mk, not_lt] at h, simp only [fin.ext_iff, fin.coe_add, fin.coe_mk, nat.mod_add_mod, fin.coe_one, nat.mod_eq_sub_mod h], refine (nat.mod_eq_of_lt _).symm, rw nat.sub_lt_left_iff_lt_add h, exact nat.add_succ_lt_add i.property i.property } } end @[simp] lemma vec_head_vec_alt0 (hm : (m + 2) = (n + 1) + (n + 1)) (v : fin (m + 2) → α) : vec_head (vec_alt0 hm v) = v 0 := rfl @[simp] lemma vec_head_vec_alt1 (hm : (m + 2) = (n + 1) + (n + 1)) (v : fin (m + 2) → α) : vec_head (vec_alt1 hm v) = v 1 := rfl @[simp] lemma cons_vec_bit0_eq_alt0 (x : α) (u : fin n → α) (i : fin (n + 1)) : vec_cons x u (bit0 i) = vec_alt0 rfl (fin.append rfl (vec_cons x u) (vec_cons x u)) i := by rw vec_alt0_append @[simp] lemma cons_vec_bit1_eq_alt1 (x : α) (u : fin n → α) (i : fin (n + 1)) : vec_cons x u (bit1 i) = vec_alt1 rfl (fin.append rfl (vec_cons x u) (vec_cons x u)) i := by rw vec_alt1_append @[simp] lemma cons_vec_alt0 (h : m + 1 + 1 = (n + 1) + (n + 1)) (x y : α) (u : fin m → α) : vec_alt0 h (vec_cons x (vec_cons y u)) = vec_cons x (vec_alt0 (by rwa [add_assoc n, add_comm 1, ←add_assoc, ←add_assoc, add_right_cancel_iff, add_right_cancel_iff] at h) u) := begin ext i, simp_rw [vec_alt0], rcases i with ⟨⟨⟩ | i, hi⟩, { refl }, { simp [vec_alt0, nat.succ_add] } end -- Although proved by simp, extracting element 8 of a five-element -- vector does not work by simp unless this lemma is present. @[simp] lemma empty_vec_alt0 (α) {h} : vec_alt0 h (![] : fin 0 → α) = ![] := by simp @[simp] lemma cons_vec_alt1 (h : m + 1 + 1 = (n + 1) + (n + 1)) (x y : α) (u : fin m → α) : vec_alt1 h (vec_cons x (vec_cons y u)) = vec_cons y (vec_alt1 (by rwa [add_assoc n, add_comm 1, ←add_assoc, ←add_assoc, add_right_cancel_iff, add_right_cancel_iff] at h) u) := begin ext i, simp_rw [vec_alt1], rcases i with ⟨⟨⟩ | i, hi⟩, { refl }, { simp [vec_alt1, nat.succ_add] } end -- Although proved by simp, extracting element 9 of a five-element -- vector does not work by simp unless this lemma is present. @[simp] lemma empty_vec_alt1 (α) {h} : vec_alt1 h (![] : fin 0 → α) = ![] := by simp end val section dot_product variables [add_comm_monoid α] [has_mul α] @[simp] lemma dot_product_empty (v w : fin 0 → α) : dot_product v w = 0 := finset.sum_empty @[simp] lemma cons_dot_product (x : α) (v : fin n → α) (w : fin n.succ → α) : dot_product (vec_cons x v) w = x * vec_head w + dot_product v (vec_tail w) := by simp [dot_product, fin.sum_univ_succ, vec_head, vec_tail] @[simp] lemma dot_product_cons (v : fin n.succ → α) (x : α) (w : fin n → α) : dot_product v (vec_cons x w) = vec_head v * x + dot_product (vec_tail v) w := by simp [dot_product, fin.sum_univ_succ, vec_head, vec_tail] end dot_product section col_row @[simp] lemma col_empty (v : fin 0 → α) : col v = vec_empty := empty_eq _ @[simp] lemma col_cons (x : α) (u : fin m → α) : col (vec_cons x u) = vec_cons (λ _, x) (col u) := by { ext i j, refine fin.cases _ _ i; simp [vec_head, vec_tail] } @[simp] lemma row_empty : row (vec_empty : fin 0 → α) = λ _, vec_empty := by { ext, refl } @[simp] lemma row_cons (x : α) (u : fin m → α) : row (vec_cons x u) = λ _, vec_cons x u := by { ext, refl } end col_row section transpose @[simp] lemma transpose_empty_rows (A : matrix m' (fin 0) α) : Aᵀ = ![] := empty_eq _ @[simp] lemma transpose_empty_cols : (![] : matrix (fin 0) m' α)ᵀ = λ i, ![] := funext (λ i, empty_eq _) @[simp] lemma cons_transpose (v : n' → α) (A : matrix (fin m) n' α) : (vec_cons v A)ᵀ = λ i, vec_cons (v i) (Aᵀ i) := by { ext i j, refine fin.cases _ _ j; simp } @[simp] lemma head_transpose (A : matrix m' (fin n.succ) α) : vec_head (Aᵀ) = vec_head ∘ A := rfl @[simp] lemma tail_transpose (A : matrix m' (fin n.succ) α) : vec_tail (Aᵀ) = (vec_tail ∘ A)ᵀ := by { ext i j, refl } end transpose section mul variables [semiring α] @[simp] lemma empty_mul (A : matrix (fin 0) n' α) (B : matrix n' o' α) : A ⬝ B = ![] := empty_eq _ @[simp] lemma empty_mul_empty (A : matrix m' (fin 0) α) (B : matrix (fin 0) o' α) : A ⬝ B = 0 := rfl @[simp] lemma mul_empty (A : matrix m' n' α) (B : matrix n' (fin 0) α) : A ⬝ B = λ _, ![] := funext (λ _, empty_eq _) lemma mul_val_succ (A : matrix (fin m.succ) n' α) (B : matrix n' o' α) (i : fin m) (j : o') : (A ⬝ B) i.succ j = (vec_tail A ⬝ B) i j := rfl @[simp] lemma cons_mul (v : n' → α) (A : matrix (fin m) n' α) (B : matrix n' o' α) : vec_cons v A ⬝ B = vec_cons (vec_mul v B) (A ⬝ B) := by { ext i j, refine fin.cases _ _ i, { refl }, simp [mul_val_succ] } end mul section vec_mul variables [semiring α] @[simp] lemma empty_vec_mul (v : fin 0 → α) (B : matrix (fin 0) o' α) : vec_mul v B = 0 := rfl @[simp] lemma vec_mul_empty (v : n' → α) (B : matrix n' (fin 0) α) : vec_mul v B = ![] := empty_eq _ @[simp] lemma cons_vec_mul (x : α) (v : fin n → α) (B : matrix (fin n.succ) o' α) : vec_mul (vec_cons x v) B = x • (vec_head B) + vec_mul v (vec_tail B) := by { ext i, simp [vec_mul] } @[simp] lemma vec_mul_cons (v : fin n.succ → α) (w : o' → α) (B : matrix (fin n) o' α) : vec_mul v (vec_cons w B) = vec_head v • w + vec_mul (vec_tail v) B := by { ext i, simp [vec_mul] } end vec_mul section mul_vec variables [semiring α] @[simp] lemma empty_mul_vec (A : matrix (fin 0) n' α) (v : n' → α) : mul_vec A v = ![] := empty_eq _ @[simp] lemma mul_vec_empty (A : matrix m' (fin 0) α) (v : fin 0 → α) : mul_vec A v = 0 := rfl @[simp] lemma cons_mul_vec (v : n' → α) (A : fin m → n' → α) (w : n' → α) : mul_vec (vec_cons v A) w = vec_cons (dot_product v w) (mul_vec A w) := by { ext i, refine fin.cases _ _ i; simp [mul_vec] } @[simp] lemma mul_vec_cons {α} [comm_semiring α] (A : m' → (fin n.succ) → α) (x : α) (v : fin n → α) : mul_vec A (vec_cons x v) = (x • vec_head ∘ A) + mul_vec (vec_tail ∘ A) v := by { ext i, simp [mul_vec, mul_comm] } end mul_vec section vec_mul_vec variables [semiring α] @[simp] lemma empty_vec_mul_vec (v : fin 0 → α) (w : n' → α) : vec_mul_vec v w = ![] := empty_eq _ @[simp] lemma vec_mul_vec_empty (v : m' → α) (w : fin 0 → α) : vec_mul_vec v w = λ _, ![] := funext (λ i, empty_eq _) @[simp] lemma cons_vec_mul_vec (x : α) (v : fin m → α) (w : n' → α) : vec_mul_vec (vec_cons x v) w = vec_cons (x • w) (vec_mul_vec v w) := by { ext i, refine fin.cases _ _ i; simp [vec_mul_vec] } @[simp] lemma vec_mul_vec_cons (v : m' → α) (x : α) (w : fin n → α) : vec_mul_vec v (vec_cons x w) = λ i, v i • vec_cons x w := by { ext i j, simp [vec_mul_vec]} end vec_mul_vec section smul variables [semiring α] @[simp] lemma smul_empty (x : α) (v : fin 0 → α) : x • v = ![] := empty_eq _ @[simp] lemma smul_mat_empty {m' : Type*} (x : α) (A : fin 0 → m' → α) : x • A = ![] := empty_eq _ @[simp] lemma smul_cons (x y : α) (v : fin n → α) : x • vec_cons y v = vec_cons (x * y) (x • v) := by { ext i, refine fin.cases _ _ i; simp } @[simp] lemma smul_mat_cons (x : α) (v : n' → α) (A : matrix (fin m) n' α) : x • vec_cons v A = vec_cons (x • v) (x • A) := by { ext i, refine fin.cases _ _ i; simp } end smul section add variables [has_add α] @[simp] lemma empty_add_empty (v w : fin 0 → α) : v + w = ![] := empty_eq _ @[simp] lemma cons_add (x : α) (v : fin n → α) (w : fin n.succ → α) : vec_cons x v + w = vec_cons (x + vec_head w) (v + vec_tail w) := by { ext i, refine fin.cases _ _ i; simp [vec_head, vec_tail] } @[simp] lemma add_cons (v : fin n.succ → α) (y : α) (w : fin n → α) : v + vec_cons y w = vec_cons (vec_head v + y) (vec_tail v + w) := by { ext i, refine fin.cases _ _ i; simp [vec_head, vec_tail] } @[simp] lemma head_add (a b : fin n.succ → α) : vec_head (a + b) = vec_head a + vec_head b := rfl @[simp] lemma tail_add (a b : fin n.succ → α) : vec_tail (a + b) = vec_tail a + vec_tail b := rfl end add section sub variables [has_sub α] @[simp] lemma empty_sub_empty (v w : fin 0 → α) : v - w = ![] := empty_eq _ @[simp] lemma cons_sub (x : α) (v : fin n → α) (w : fin n.succ → α) : vec_cons x v - w = vec_cons (x - vec_head w) (v - vec_tail w) := by { ext i, refine fin.cases _ _ i; simp [vec_head, vec_tail] } @[simp] lemma sub_cons (v : fin n.succ → α) (y : α) (w : fin n → α) : v - vec_cons y w = vec_cons (vec_head v - y) (vec_tail v - w) := by { ext i, refine fin.cases _ _ i; simp [vec_head, vec_tail] } @[simp] lemma head_sub (a b : fin n.succ → α) : vec_head (a - b) = vec_head a - vec_head b := rfl @[simp] lemma tail_sub (a b : fin n.succ → α) : vec_tail (a - b) = vec_tail a - vec_tail b := rfl end sub section zero variables [has_zero α] @[simp] lemma zero_empty : (0 : fin 0 → α) = ![] := empty_eq _ @[simp] lemma cons_zero_zero : vec_cons (0 : α) (0 : fin n → α) = 0 := by { ext i j, refine fin.cases _ _ i, { refl }, simp } @[simp] lemma head_zero : vec_head (0 : fin n.succ → α) = 0 := rfl @[simp] lemma tail_zero : vec_tail (0 : fin n.succ → α) = 0 := rfl @[simp] lemma cons_eq_zero_iff {v : fin n → α} {x : α} : vec_cons x v = 0 ↔ x = 0 ∧ v = 0 := ⟨ λ h, ⟨ congr_fun h 0, by { convert congr_arg vec_tail h, simp } ⟩, λ ⟨hx, hv⟩, by simp [hx, hv] ⟩ open_locale classical lemma cons_nonzero_iff {v : fin n → α} {x : α} : vec_cons x v ≠ 0 ↔ (x ≠ 0 ∨ v ≠ 0) := ⟨ λ h, not_and_distrib.mp (h ∘ cons_eq_zero_iff.mpr), λ h, mt cons_eq_zero_iff.mp (not_and_distrib.mpr h) ⟩ end zero section neg variables [has_neg α] @[simp] lemma neg_empty (v : fin 0 → α) : -v = ![] := empty_eq _ @[simp] lemma neg_cons (x : α) (v : fin n → α) : -(vec_cons x v) = vec_cons (-x) (-v) := by { ext i, refine fin.cases _ _ i; simp } @[simp] lemma head_neg (a : fin n.succ → α) : vec_head (-a) = -vec_head a := rfl @[simp] lemma tail_neg (a : fin n.succ → α) : vec_tail (-a) = -vec_tail a := rfl end neg section minor @[simp] lemma minor_empty (A : matrix m' n' α) (row : fin 0 → m') (col : o' → n') : minor A row col = ![] := empty_eq _ @[simp] lemma minor_cons_row (A : matrix m' n' α) (i : m') (row : fin m → m') (col : o' → n') : minor A (vec_cons i row) col = vec_cons (λ j, A i (col j)) (minor A row col) := by { ext i j, refine fin.cases _ _ i; simp [minor] } end minor end matrix
d4c4a7601e72469be1cf10a8a89f7c9472916e9e
74addaa0e41490cbaf2abd313a764c96df57b05d
/Mathlib/Lean3Lib/init/data/list/basic_auto.lean
60f96c7a6d783fcd6ce6395cd1d9225d4898a091
[]
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,659
lean
/- Copyright (c) 2016 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Leonardo de Moura -/ import Mathlib.PrePort import Mathlib.Lean3Lib.init.logic import Mathlib.Lean3Lib.init.data.nat.basic import Mathlib.Lean3Lib.init.data.bool.basic import Mathlib.Lean3Lib.init.propext universes u u_1 v w namespace Mathlib protected instance list.inhabited (α : Type u) : Inhabited (List α) := { default := [] } namespace list protected def has_dec_eq {α : Type u} [s : DecidableEq α] : DecidableEq (List α) := sorry protected instance decidable_eq {α : Type u} [DecidableEq α] : DecidableEq (List α) := list.has_dec_eq @[simp] protected def append {α : Type u} : List α → List α → List α := sorry protected instance has_append {α : Type u} : Append (List α) := { append := list.append } protected def mem {α : Type u} : α → List α → Prop := sorry protected instance has_mem {α : Type u} : has_mem α (List α) := has_mem.mk list.mem protected instance decidable_mem {α : Type u} [DecidableEq α] (a : α) (l : List α) : Decidable (a ∈ l) := sorry protected instance has_emptyc {α : Type u} : has_emptyc (List α) := has_emptyc.mk [] protected def erase {α : Type u_1} [DecidableEq α] : List α → α → List α := sorry protected def bag_inter {α : Type u_1} [DecidableEq α] : List α → List α → List α := sorry protected def diff {α : Type u_1} [DecidableEq α] : List α → List α → List α := sorry @[simp] def length {α : Type u} : List α → ℕ := sorry def empty {α : Type u} : List α → Bool := sorry @[simp] def nth {α : Type u} : List α → ℕ → Option α := sorry @[simp] def nth_le {α : Type u} (l : List α) (n : ℕ) : n < length l → α := sorry @[simp] def head {α : Type u} [Inhabited α] : List α → α := sorry @[simp] def tail {α : Type u} : List α → List α := sorry def reverse_core {α : Type u} : List α → List α → List α := sorry def reverse {α : Type u} : List α → List α := fun (l : List α) => reverse_core l [] @[simp] def map {α : Type u} {β : Type v} (f : α → β) : List α → List β := sorry @[simp] def map₂ {α : Type u} {β : Type v} {γ : Type w} (f : α → β → γ) : List α → List β → List γ := sorry def map_with_index_core {α : Type u} {β : Type v} (f : ℕ → α → β) : ℕ → List α → List β := sorry /-- Given a function `f : ℕ → α → β` and `as : list α`, `as = [a₀, a₁, ...]`, returns the list `[f 0 a₀, f 1 a₁, ...]`. -/ def map_with_index {α : Type u} {β : Type v} (f : ℕ → α → β) (as : List α) : List β := map_with_index_core f 0 as def join {α : Type u} : List (List α) → List α := sorry def filter_map {α : Type u} {β : Type v} (f : α → Option β) : List α → List β := sorry def filter {α : Type u} (p : α → Prop) [decidable_pred p] : List α → List α := sorry def partition {α : Type u} (p : α → Prop) [decidable_pred p] : List α → List α × List α := sorry def drop_while {α : Type u} (p : α → Prop) [decidable_pred p] : List α → List α := sorry /-- `after p xs` is the suffix of `xs` after the first element that satisfies `p`, not including that element. ```lean after (eq 1) [0, 1, 2, 3] = [2, 3] drop_while (not ∘ eq 1) [0, 1, 2, 3] = [1, 2, 3] ``` -/ def after {α : Type u} (p : α → Prop) [decidable_pred p] : List α → List α := sorry def span {α : Type u} (p : α → Prop) [decidable_pred p] : List α → List α × List α := sorry def find_index {α : Type u} (p : α → Prop) [decidable_pred p] : List α → ℕ := sorry def index_of {α : Type u} [DecidableEq α] (a : α) : List α → ℕ := find_index (Eq a) def remove_all {α : Type u} [DecidableEq α] (xs : List α) (ys : List α) : List α := filter (fun (_x : α) => ¬_x ∈ ys) xs def update_nth {α : Type u} : List α → ℕ → α → List α := sorry def remove_nth {α : Type u} : List α → ℕ → List α := sorry @[simp] def drop {α : Type u} : ℕ → List α → List α := sorry @[simp] def take {α : Type u} : ℕ → List α → List α := sorry @[simp] def foldl {α : Type u} {β : Type v} (f : α → β → α) : α → List β → α := sorry @[simp] def foldr {α : Type u} {β : Type v} (f : α → β → β) (b : β) : List α → β := sorry def any {α : Type u} (l : List α) (p : α → Bool) : Bool := foldr (fun (a : α) (r : Bool) => p a || r) false l def all {α : Type u} (l : List α) (p : α → Bool) : Bool := foldr (fun (a : α) (r : Bool) => p a && r) tt l def bor (l : List Bool) : Bool := any l id def band (l : List Bool) : Bool := all l id def zip_with {α : Type u} {β : Type v} {γ : Type w} (f : α → β → γ) : List α → List β → List γ := sorry def zip {α : Type u} {β : Type v} : List α → List β → List (α × β) := zip_with Prod.mk def unzip {α : Type u} {β : Type v} : List (α × β) → List α × List β := sorry protected def insert {α : Type u} [DecidableEq α] (a : α) (l : List α) : List α := ite (a ∈ l) l (a :: l) protected instance has_insert {α : Type u} [DecidableEq α] : has_insert α (List α) := has_insert.mk list.insert protected instance has_singleton {α : Type u} : has_singleton α (List α) := has_singleton.mk fun (x : α) => [x] protected instance is_lawful_singleton {α : Type u} [DecidableEq α] : is_lawful_singleton α (List α) := is_lawful_singleton.mk fun (x : α) => (fun (this : ite (x ∈ []) [] [x] = [x]) => this) (if_neg not_false) protected def union {α : Type u} [DecidableEq α] (l₁ : List α) (l₂ : List α) : List α := foldr insert l₂ l₁ protected instance has_union {α : Type u} [DecidableEq α] : has_union (List α) := has_union.mk list.union protected def inter {α : Type u} [DecidableEq α] (l₁ : List α) (l₂ : List α) : List α := filter (fun (_x : α) => _x ∈ l₂) l₁ protected instance has_inter {α : Type u} [DecidableEq α] : has_inter (List α) := has_inter.mk list.inter @[simp] def repeat {α : Type u} (a : α) : ℕ → List α := sorry def range_core : ℕ → List ℕ → List ℕ := sorry def range (n : ℕ) : List ℕ := range_core n [] def iota : ℕ → List ℕ := sorry def enum_from {α : Type u} : ℕ → List α → List (ℕ × α) := sorry def enum {α : Type u} : List α → List (ℕ × α) := enum_from 0 @[simp] def last {α : Type u} (l : List α) : l ≠ [] → α := sorry def ilast {α : Type u} [Inhabited α] : List α → α := sorry def init {α : Type u} : List α → List α := sorry def intersperse {α : Type u} (sep : α) : List α → List α := sorry def intercalate {α : Type u} (sep : List α) (xs : List (List α)) : List α := join (intersperse sep xs) protected def bind {α : Type u} {β : Type v} (a : List α) (b : α → List β) : List β := join (map b a) protected def ret {α : Type u} (a : α) : List α := [a] protected def lt {α : Type u} [HasLess α] : List α → List α → Prop := sorry protected instance has_lt {α : Type u} [HasLess α] : HasLess (List α) := { Less := list.lt } protected instance has_decidable_lt {α : Type u} [HasLess α] [h : DecidableRel Less] (l₁ : List α) (l₂ : List α) : Decidable (l₁ < l₂) := sorry protected def le {α : Type u} [HasLess α] (a : List α) (b : List α) := ¬b < a protected instance has_le {α : Type u} [HasLess α] : HasLessEq (List α) := { LessEq := list.le } protected instance has_decidable_le {α : Type u} [HasLess α] [h : DecidableRel Less] (l₁ : List α) (l₂ : List α) : Decidable (l₁ ≤ l₂) := not.decidable theorem le_eq_not_gt {α : Type u} [HasLess α] (l₁ : List α) (l₂ : List α) : l₁ ≤ l₂ = (¬l₂ < l₁) := rfl theorem lt_eq_not_ge {α : Type u} [HasLess α] [DecidableRel Less] (l₁ : List α) (l₂ : List α) : l₁ < l₂ = (¬l₂ ≤ l₁) := (fun (this : l₁ < l₂ = (¬¬l₁ < l₂)) => this) (Eq.symm (propext (decidable.not_not_iff (l₁ < l₂))) ▸ rfl) /-- `is_prefix_of l₁ l₂` returns `tt` iff `l₁` is a prefix of `l₂`. -/ def is_prefix_of {α : Type u} [DecidableEq α] : List α → List α → Bool := sorry /-- `is_suffix_of l₁ l₂` returns `tt` iff `l₁` is a suffix of `l₂`. -/ def is_suffix_of {α : Type u} [DecidableEq α] (l₁ : List α) (l₂ : List α) : Bool := is_prefix_of (reverse l₁) (reverse l₂) end list namespace bin_tree def to_list {α : Type u} (t : bin_tree α) : List α := to_list_aux t [] end Mathlib
439766886ceb88f53607e424c257d50fa3960866
432d948a4d3d242fdfb44b81c9e1b1baacd58617
/src/deprecated/group.lean
0d07d3df7442c34cad02d7d3ccbd5f940b917b15
[ "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
13,584
lean
/- Copyright (c) 2019 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import algebra.group.type_tags import algebra.group.units_hom import algebra.ring.basic import data.equiv.mul_add /-! # Unbundled monoid and group homomorphisms (deprecated) This file defines typeclasses for unbundled monoid and group homomorphisms. Though these classes are deprecated, they are still widely used in mathlib, and probably will not go away before Lean 4 because Lean 3 often fails to coerce a bundled homomorphism to a function. ## main definitions is_monoid_hom (deprecated), is_group_hom (deprecated) ## 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, ## Tags is_group_hom, is_monoid_hom, monoid_hom -/ /-- We have lemmas stating that the composition of two morphisms is again a morphism. Since composition is reducible, type class inference will always succeed in applying these instances. For example when the goal is just `⊢ is_mul_hom f` the instance `is_mul_hom.comp` will still succeed, unifying `f` with `f ∘ (λ x, x)`. This causes type class inference to loop. To avoid this, we do not make these lemmas instances. -/ library_note "no instance on morphisms" universes u v variables {α : Type u} {β : Type v} /-- Predicate for maps which preserve an addition. -/ class is_add_hom {α β : Type*} [has_add α] [has_add β] (f : α → β) : Prop := (map_add [] : ∀ x y, f (x + y) = f x + f y) /-- Predicate for maps which preserve a multiplication. -/ @[to_additive] class is_mul_hom {α β : Type*} [has_mul α] [has_mul β] (f : α → β) : Prop := (map_mul [] : ∀ x y, f (x * y) = f x * f y) namespace is_mul_hom variables [has_mul α] [has_mul β] {γ : Type*} [has_mul γ] /-- The identity map preserves multiplication. -/ @[to_additive "The identity map preserves addition"] instance id : is_mul_hom (id : α → α) := {map_mul := λ _ _, rfl} /-- The composition of maps which preserve multiplication, also preserves multiplication. -/ -- see Note [no instance on morphisms] @[to_additive "The composition of addition preserving maps also preserves addition"] lemma comp (f : α → β) (g : β → γ) [is_mul_hom f] [hg : is_mul_hom g] : is_mul_hom (g ∘ f) := { map_mul := λ x y, by simp only [function.comp, map_mul f, map_mul g] } /-- A product of maps which preserve multiplication, preserves multiplication when the target is commutative. -/ @[instance, priority 10, to_additive] lemma mul {α β} [semigroup α] [comm_semigroup β] (f g : α → β) [is_mul_hom f] [is_mul_hom g] : is_mul_hom (λa, f a * g a) := { map_mul := assume a b, by simp only [map_mul f, map_mul g, mul_comm, mul_assoc, mul_left_comm] } /-- The inverse of a map which preserves multiplication, preserves multiplication when the target is commutative. -/ @[instance, to_additive] lemma inv {α β} [has_mul α] [comm_group β] (f : α → β) [is_mul_hom f] : is_mul_hom (λa, (f a)⁻¹) := { map_mul := assume a b, (map_mul f a b).symm ▸ mul_inv _ _ } end is_mul_hom /-- Predicate for add_monoid homomorphisms (deprecated -- use the bundled `monoid_hom` version). -/ class is_add_monoid_hom [add_zero_class α] [add_zero_class β] (f : α → β) extends is_add_hom f : Prop := (map_zero [] : f 0 = 0) /-- Predicate for monoid homomorphisms (deprecated -- use the bundled `monoid_hom` version). -/ @[to_additive] class is_monoid_hom [mul_one_class α] [mul_one_class β] (f : α → β) extends is_mul_hom f : Prop := (map_one [] : f 1 = 1) namespace monoid_hom /-! Throughout this section, some `monoid` arguments are specified with `{}` instead of `[]`. See note [implicit instance arguments]. -/ variables {M : Type*} {N : Type*} {P : Type*} [mM : monoid M] [mN : monoid N] {mP : monoid P} variables {G : Type*} {H : Type*} [group G] [comm_group H] include mM mN /-- Interpret a map `f : M → N` as a homomorphism `M →* N`. -/ @[to_additive "Interpret a map `f : M → N` as a homomorphism `M →+ N`."] def of (f : M → N) [h : is_monoid_hom f] : M →* N := { to_fun := f, map_one' := h.2, map_mul' := h.1.1 } variables {mM mN mP} @[simp, to_additive] lemma coe_of (f : M → N) [is_monoid_hom f] : ⇑ (monoid_hom.of f) = f := rfl @[to_additive] instance (f : M →* N) : is_monoid_hom (f : M → N) := { map_mul := f.map_mul, map_one := f.map_one } end monoid_hom namespace mul_equiv variables {M : Type*} {N : Type*} [monoid M] [monoid N] /-- A multiplicative isomorphism preserves multiplication (deprecated). -/ @[to_additive] instance (h : M ≃* N) : is_mul_hom h := ⟨h.map_mul⟩ /-- A multiplicative bijection between two monoids is a monoid hom (deprecated -- use to_monoid_hom). -/ @[to_additive] instance {M N} [monoid M] [monoid N] (h : M ≃* N) : is_monoid_hom h := ⟨h.map_one⟩ end mul_equiv namespace is_monoid_hom variables [monoid α] [monoid β] (f : α → β) [is_monoid_hom f] /-- A monoid homomorphism preserves multiplication. -/ @[to_additive] lemma map_mul (x y) : f (x * y) = f x * f y := is_mul_hom.map_mul f x y end is_monoid_hom /-- A map to a group preserving multiplication is a monoid homomorphism. -/ @[to_additive] theorem is_monoid_hom.of_mul [monoid α] [group β] (f : α → β) [is_mul_hom f] : is_monoid_hom f := { map_one := mul_right_eq_self.1 $ by rw [← is_mul_hom.map_mul f, one_mul] } namespace is_monoid_hom variables [monoid α] [monoid β] (f : α → β) [is_monoid_hom f] /-- The identity map is a monoid homomorphism. -/ @[to_additive] instance id : is_monoid_hom (@id α) := { map_one := rfl } /-- The composite of two monoid homomorphisms is a monoid homomorphism. -/ @[to_additive] -- see Note [no instance on morphisms] lemma comp {γ} [monoid γ] (g : β → γ) [is_monoid_hom g] : is_monoid_hom (g ∘ f) := { map_one := show g _ = 1, by rw [map_one f, map_one g], ..is_mul_hom.comp _ _ } end is_monoid_hom namespace is_add_monoid_hom /-- Left multiplication in a ring is an additive monoid morphism. -/ instance is_add_monoid_hom_mul_left {γ : Type*} [semiring γ] (x : γ) : is_add_monoid_hom (λ y : γ, x * y) := { map_zero := mul_zero x, map_add := λ y z, mul_add x y z } /-- Right multiplication in a ring is an additive monoid morphism. -/ instance is_add_monoid_hom_mul_right {γ : Type*} [semiring γ] (x : γ) : is_add_monoid_hom (λ y : γ, y * x) := { map_zero := zero_mul x, map_add := λ y z, add_mul y z x } end is_add_monoid_hom /-- Predicate for additive group homomorphism (deprecated -- use bundled `monoid_hom`). -/ class is_add_group_hom [add_group α] [add_group β] (f : α → β) extends is_add_hom f : Prop /-- Predicate for group homomorphisms (deprecated -- use bundled `monoid_hom`). -/ @[to_additive] class is_group_hom [group α] [group β] (f : α → β) extends is_mul_hom f : Prop @[to_additive] instance monoid_hom.is_group_hom {G H : Type*} {_ : group G} {_ : group H} (f : G →* H) : is_group_hom (f : G → H) := { map_mul := f.map_mul } @[to_additive] instance mul_equiv.is_group_hom {G H : Type*} {_ : group G} {_ : group H} (h : G ≃* H) : is_group_hom h := { map_mul := h.map_mul } /-- Construct `is_group_hom` from its only hypothesis. The default constructor tries to get `is_mul_hom` from class instances, and this makes some proofs fail. -/ @[to_additive] lemma is_group_hom.mk' [group α] [group β] {f : α → β} (hf : ∀ x y, f (x * y) = f x * f y) : is_group_hom f := { map_mul := hf } namespace is_group_hom variables [group α] [group β] (f : α → β) [is_group_hom f] open is_mul_hom (map_mul) /-- A group homomorphism is a monoid homomorphism. -/ @[priority 100, to_additive] -- see Note [lower instance priority] instance to_is_monoid_hom : is_monoid_hom f := is_monoid_hom.of_mul f /-- A group homomorphism sends 1 to 1. -/ @[to_additive] lemma map_one : f 1 = 1 := is_monoid_hom.map_one f /-- A group homomorphism sends inverses to inverses. -/ @[to_additive] theorem map_inv (a : α) : f a⁻¹ = (f a)⁻¹ := eq_inv_of_mul_eq_one $ by rw [← map_mul f, inv_mul_self, map_one f] /-- The identity is a group homomorphism. -/ @[to_additive] instance id : is_group_hom (@id α) := { } /-- The composition of two group homomorphisms is a group homomorphism. -/ @[to_additive] -- see Note [no instance on morphisms] lemma comp {γ} [group γ] (g : β → γ) [is_group_hom g] : is_group_hom (g ∘ f) := { ..is_mul_hom.comp _ _ } /-- A group homomorphism is injective iff its kernel is trivial. -/ @[to_additive] lemma injective_iff (f : α → β) [is_group_hom f] : function.injective f ↔ (∀ a, f a = 1 → a = 1) := ⟨λ h _, by rw ← is_group_hom.map_one f; exact @h _ _, λ h x y hxy, by rw [← inv_inv (f x), inv_eq_iff_mul_eq_one, ← map_inv f, ← map_mul f] at hxy; simpa using inv_eq_of_mul_eq_one (h _ hxy)⟩ /-- The product of group homomorphisms is a group homomorphism if the target is commutative. -/ @[instance, priority 10, to_additive] lemma mul {α β} [group α] [comm_group β] (f g : α → β) [is_group_hom f] [is_group_hom g] : is_group_hom (λa, f a * g a) := { } /-- The inverse of a group homomorphism is a group homomorphism if the target is commutative. -/ @[instance, to_additive] lemma inv {α β} [group α] [comm_group β] (f : α → β) [is_group_hom f] : is_group_hom (λa, (f a)⁻¹) := { } end is_group_hom namespace ring_hom /-! These instances look redundant, because `deprecated.ring` provides `is_ring_hom` for a `→+*`. Nevertheless these are harmless, and helpful for stripping out dependencies on `deprecated.ring`. -/ variables {R : Type*} {S : Type*} section variables [semiring R] [semiring S] instance (f : R →+* S) : is_monoid_hom f := { map_one := f.map_one, map_mul := f.map_mul } instance (f : R →+* S) : is_add_monoid_hom f := { map_zero := f.map_zero, map_add := f.map_add } end section variables [ring R] [ring S] instance (f : R →+* S) : is_add_group_hom f := { map_add := f.map_add } end end ring_hom /-- Inversion is a group homomorphism if the group is commutative. -/ @[instance, to_additive neg.is_add_group_hom "Negation is an `add_group` homomorphism if the `add_group` is commutative."] lemma inv.is_group_hom [comm_group α] : is_group_hom (has_inv.inv : α → α) := { map_mul := mul_inv } namespace is_add_group_hom variables [add_group α] [add_group β] (f : α → β) [is_add_group_hom f] /-- Additive group homomorphisms commute with subtraction. -/ lemma map_sub (a b) : f (a - b) = f a - f b := calc f (a - b) = f (a + -b) : congr_arg f (sub_eq_add_neg a b) ... = f a + f (-b) : is_add_hom.map_add f _ _ ... = f a + -f b : by rw [map_neg f] ... = f a - f b : (sub_eq_add_neg _ _).symm end is_add_group_hom /-- The difference of two additive group homomorphisms is an additive group homomorphism if the target is commutative. -/ @[instance] lemma is_add_group_hom.sub {α β} [add_group α] [add_comm_group β] (f g : α → β) [is_add_group_hom f] [is_add_group_hom g] : is_add_group_hom (λa, f a - g a) := by { simp only [sub_eq_add_neg], exact is_add_group_hom.add f (λa, - g a) } namespace units variables {M : Type*} {N : Type*} [monoid M] [monoid N] /-- The group homomorphism on units induced by a multiplicative morphism. -/ @[reducible] def map' (f : M → N) [is_monoid_hom f] : units M →* units N := map (monoid_hom.of f) @[simp] lemma coe_map' (f : M → N) [is_monoid_hom f] (x : units M) : ↑((map' f : units M → units N) x) = f x := rfl instance coe_is_monoid_hom : is_monoid_hom (coe : units M → M) := (coe_hom M).is_monoid_hom end units namespace is_unit variables {M : Type*} {N : Type*} [monoid M] [monoid N] {x : M} lemma map' (f : M → N) {x : M} (h : is_unit x) [is_monoid_hom f] : is_unit (f x) := h.map (monoid_hom.of f) end is_unit lemma additive.is_add_hom [has_mul α] [has_mul β] (f : α → β) [is_mul_hom f] : @is_add_hom (additive α) (additive β) _ _ f := { map_add := @is_mul_hom.map_mul α β _ _ f _ } lemma multiplicative.is_mul_hom [has_add α] [has_add β] (f : α → β) [is_add_hom f] : @is_mul_hom (multiplicative α) (multiplicative β) _ _ f := { map_mul := @is_add_hom.map_add α β _ _ f _ } lemma additive.is_add_monoid_hom [monoid α] [monoid β] (f : α → β) [is_monoid_hom f] : @is_add_monoid_hom (additive α) (additive β) _ _ f := { map_zero := @is_monoid_hom.map_one α β _ _ f _, ..additive.is_add_hom f } lemma multiplicative.is_monoid_hom [add_monoid α] [add_monoid β] (f : α → β) [is_add_monoid_hom f] : @is_monoid_hom (multiplicative α) (multiplicative β) _ _ f := { map_one := @is_add_monoid_hom.map_zero α β _ _ f _, ..multiplicative.is_mul_hom f } lemma additive.is_add_group_hom [group α] [group β] (f : α → β) [is_group_hom f] : @is_add_group_hom (additive α) (additive β) _ _ f := { map_add := @is_mul_hom.map_mul α β _ _ f _ } lemma multiplicative.is_group_hom [add_group α] [add_group β] (f : α → β) [is_add_group_hom f] : @is_group_hom (multiplicative α) (multiplicative β) _ _ f := { map_mul := @is_add_hom.map_add α β _ _ f _ }
bbfa818432f959c7ac3d50ef667bd8bcba89325d
c8d830ce6c7de4840cf0c892d8b58e7e8df97e37
/src/property_catalogue/LTL/patterns.lean
df71d3d01a2ea6b9c12de3432d3011de63c96019
[]
no_license
loganrjmurphy/lean-strategies
4b8dd54771bb421c929a8bcb93a528ce6c1a70f1
020e2a65dc2ab475696dfea5ad8935a0a4085918
refs/heads/main
1,682,732,168,860
1,614,820,630,000
1,614,820,630,000
278,458,841
3
0
null
1,613,755,728,000
1,594,324,763,000
Lean
UTF-8
Lean
false
false
2,756
lean
import LTS.defs variable {M : LTS} set_option pp.beta true @[reducible] def init_state (s : M.S) [has_coe M.S (formula M)] : formula M := ↑s @[reducible] def holds_over_transition (s : M.S) [has_coe M.S (formula M)] : formula M := ◾(↑s ⇒ formula.next ↑s) @[reducible] def not_init (s : M.S) [has_coe M.S (formula M)] : formula M := !↑s @[reducible] def transitions_safe (s : M.S) [has_coe M.S (formula M)] : formula M := ◾(!↑s ⇒ ! formula.next ↑s) namespace absent def globally (P : formula M) : formula M := ◾ (!P) def before (P R : formula M) : formula M := (◆R) ⇒ ((!P) U R) def after (P Q : formula M) : formula M := ◾(Q ⇒ ◾!P) def between (P Q R : formula M) : formula M := ◾((Q & !R & ◆ R) ⇒ (!P U R)) def after_until (P Q R: formula M) : formula M := ◾((Q & !R) ⇒ ((!P) W R)) end absent namespace exist def globally (P : formula M) : formula M := ◆P def before (P R : formula M) : formula M := (!R) W (P & !R) def after (P Q : formula M) : formula M := (◾(!Q)) ⅋ ◆(Q & ◆ P) def between (P Q R : formula M) : formula M := ◾((Q & !R) ⇒ ((!R) W (P & !R))) def after_until (P Q R: formula M) : formula M := ◾((Q & !R) ⇒ (!R U (P & !R))) end exist namespace universal def globally (P : formula M) : formula M := ◾ P def before (P R : formula M) : formula M := (◆R) ⇒ (P U R) def after (P Q : formula M) : formula M := ◾(Q ⇒ ◾P) def between (P Q R : formula M) : formula M := ◾((Q & !R & ◆R) ⇒ (P U R)) def after_until (P Q R: formula M) : formula M := ◾((Q & !R) ⇒ (P W R)) end universal namespace precedes def globally (S P : formula M) : formula M := (!P) W S def before (S P R : formula M) : formula M := (◆R) ⇒ ((!P) U (S ⅋ R)) def after (S P Q : formula M) : formula M := (◾!Q) ⅋ ◆(Q & ((!P) W S)) def between (S P Q R : formula M) : formula M := ◾((Q & (!R) & ◆R) ⇒ (!P U (S ⅋ R))) def after_until (S P Q R: formula M) : formula M := ◾((Q & !R) ⇒ ((!P) W (S ⅋ R))) end precedes namespace responds def globally (P S : formula M) : formula M := ◾(P ⇒ ◆S) def before (S P R : formula M) : formula M := (◆R) ⇒ ((P ⇒ (!R U (S & !R))) U R) def after (S P Q : formula M) : formula M := ◾(Q ⇒ ◾(P ⇒ ◆S)) def between (S P Q R : formula M) : formula M := ◾((Q & !R & ◆R) ⇒ (P ⇒ (!R U (S & !R))) U R) def after_until (S P Q R: formula M) : formula M := ◾((Q & !R) ⇒ ((P ⇒ (!R U (S & !R))) W R)) end responds lemma sat_em (P : formula M) (π : path M) : sat P π → ¬sat ( !P) π := by {intros, rw sat, tidy}
2f2dbc5d5ebf83086a08b03f9afa876f747782b3
f02b05b665ad2d2cd970e93758a98d57f310a822
/test/test2.lean
d6940c39ee7453eac98dd7fad774d9cf6a6d40c8
[]
no_license
khoek/leancache
b0ed5d2a9a2e87f58d4ad27343d957a9cd49ce5f
5c8329f7b647b8d82966ab180c4473b20d1f249c
refs/heads/master
1,585,344,140,717
1,549,094,327,000
1,549,094,327,000
147,138,187
0
0
null
null
null
null
UTF-8
Lean
false
false
132
lean
import tactic.tcache set_option trace.cache true namespace charlie theorem lol : 1 + 2 = 3 := by c begin simp end end charlie
61b1339aa2eb61805a4c52222aa57bc45b9534cd
88fb7558b0636ec6b181f2a548ac11ad3919f8a5
/tests/lean/run/isabelle.lean
38103e5c12abb54ffa105763b9e1a6922aad98bc
[ "Apache-2.0" ]
permissive
moritayasuaki/lean
9f666c323cb6fa1f31ac597d777914aed41e3b7a
ae96ebf6ee953088c235ff7ae0e8c95066ba8001
refs/heads/master
1,611,135,440,814
1,493,852,869,000
1,493,852,869,000
90,269,903
0
0
null
1,493,906,291,000
1,493,906,291,000
null
UTF-8
Lean
false
false
2,235
lean
/- Isabelle style tactics. This test is based on a file created by Gabriel Ebner. -/ import data.lazy_list universe variables u meta def lazy_tactic (α : Type u) := tactic_state → lazy_list (α × tactic_state) namespace lazy_tactic open lazy_list meta def of_tactic {α : Type u} (t : tactic α) : lazy_tactic α := λ s, match t s with | result.success a new_s := lazy_list.singleton (a, new_s) | result.exception f e s := lazy_list.nil end meta instance {α : Type} : has_coe (tactic α) (lazy_tactic α) := ⟨of_tactic⟩ protected meta def return {α} (a : α) : lazy_tactic α := λ s, lazy_list.singleton (a, s) protected meta def bind {α β} : lazy_tactic α → (α → lazy_tactic β) → lazy_tactic β := λ t₁ t₂ s, join (for (t₁ s) (λ ⟨a, new_s⟩, t₂ a new_s)) protected meta def orelse {α} (t₁ t₂ : lazy_tactic α) : lazy_tactic α := λ s, append (t₁ s) (t₂ s) protected meta def failure {α} : lazy_tactic α := λ s, nil meta instance : monad lazy_tactic := unsafe_monad_from_pure_bind @lazy_tactic.return @lazy_tactic.bind meta instance : alternative lazy_tactic := { lazy_tactic.monad with failure := @lazy_tactic.failure, orelse := @lazy_tactic.orelse } meta def choose {α} (xs : list α) : lazy_tactic α := λ s, of_list $ xs^.for (λ a, (a, s)) meta def run {α} (t : lazy_tactic α) : tactic α := λ s, match t s with | nil := tactic.failed s | cons (a, new_s) ss := result.success a new_s end open tactic private meta def try_constructors : list name → lazy_tactic unit | [] := failure | (c::cs) := (mk_const c >>= apply : tactic unit) <|> try_constructors cs /- Backtracking version of constructor -/ meta def constructor : lazy_tactic unit := do t ← target, cs ← get_constructors_for t, try_constructors cs end lazy_tactic open lazy_tactic example (p q : Prop) : q → p ∨ q := by run $ do tactic.intros, constructor, tactic.trace_state, tactic.assumption meta def naive_instantiation : lazy_tactic unit := let vals := [`(1),`(2),`(3)] in do x ← choose vals, y ← choose vals, e ← tactic.to_expr `(nat.add_comm %%x %%y), tactic.trace e, tactic.exact e lemma ex : 1 + 3 = 3 + 1 := by naive_instantiation^.run