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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
91cd12a255f31675b7152adb99169a57ccd0c8dd | 9cba98daa30c0804090f963f9024147a50292fa0 | /old/metrology/quantity.lean | 6a43d64150293da034f40b32f5d56d64096ef90c | [] | no_license | kevinsullivan/phys | dcb192f7b3033797541b980f0b4a7e75d84cea1a | ebc2df3779d3605ff7a9b47eeda25c2a551e011f | refs/heads/master | 1,637,490,575,500 | 1,629,899,064,000 | 1,629,899,064,000 | 168,012,884 | 0 | 3 | null | 1,629,644,436,000 | 1,548,699,832,000 | Lean | UTF-8 | Lean | false | false | 4,550 | lean | import .measurement
import .dimensions
import .scalar
namespace quantity
open measurementSystem
open dimension
/-
We express a physical quantity as a tuple of scalars, each
of a type consistent with its base dimension, relative to a
given (potentially derived) dimension and measurement system.
So, for example, to express the concept of 2 m/s, the dimension
would be <1,0,-1,0,0,0,0> and the scalar tuple we'd want here
would be <2,0,0,0,0,0,0>. The measurement argument then answers
the question, two of what units, e.g., feet or meters. In this
way, scalars are combined with units to yield quantities. So,
for example, to express 2 m/s, the MeasurementSystem object
would have "meters" (as a measurement unit forilength) n its "
length" field.
Open question, do we really need all of this complexity around
the Quantity scalar tuple. I.e., do we really need seven fields
in this type?
TODO: Maybe just one scalar is fine, because a quantity is a
scalar times a dimension relative to a measurement systems,
not a seven-tuple of scalars times a simension relative to a
measurement system.
-/
structure Quantity (d : Dimension) (m : MeasurementSystem) : Type :=
mk ::
(length : scalar.length)
(mass : scalar.mass)
(time : scalar.time)
(current : scalar.current)
(temperature : scalar.temperature)
(quantity : scalar.quantity)
(intensity : scalar.intensity)
-- Make quantity of one unit of basic dimension in given measurement system
-- need little lemma that 0 >= 0
lemma zgez : (0 : ℝ) ≥ 0 := by linarith
def mkQuantity (d : BasicDimension) (m : MeasurementSystem) (s : basicDimScalarType d) :
Quantity (basicDimToDim d) m :=
match d, s with
| BasicDimension.length, s := Quantity.mk s ⟨0, zgez ⟩ 0 0 ⟨0, zgez ⟩ 0 ⟨ 0, zgez ⟩
| BasicDimension.mass, s := Quantity.mk 0 ⟨0, zgez⟩ 0 0 ⟨ 0, zgez ⟩ 0 ⟨0, zgez⟩
| BasicDimension.time, s := Quantity.mk 0 ⟨0, zgez⟩ s 0 ⟨ 0, zgez ⟩ 0 ⟨0, zgez⟩
| BasicDimension.current, s := Quantity.mk 0 ⟨0, zgez⟩ 0 s ⟨ 0, zgez ⟩ 0 ⟨0, zgez⟩
| BasicDimension.temperature, s := Quantity.mk 0 ⟨0, zgez⟩ 0 0 s 0 ⟨0, zgez⟩
| BasicDimension.quantity, s := Quantity.mk 0 ⟨0, zgez⟩ 0 0 ⟨ 0, zgez ⟩ s ⟨0, zgez⟩
| BasicDimension.intensity, s := Quantity.mk 0 ⟨0, zgez⟩ 0 0 ⟨ 0, zgez ⟩ 0 s
end
open scalar
open dimension
/-
We can add quantities as long as they are in the same physical
dimensions and expressed with respect to the same measurement
systems.
We note that we could build measurement system conversions in
here. We choose not to do so, leaving designers to make such
conversions explicit where needed.
Proofs will be required that we aren't violating any
algebraic invariants. For example, we mustn't subtract a large
mass from a small mass to obtain a negative mass, because mass
(in the ordinary physics we formalize) can't be negative.
-/
def add
{d : Dimension}
{ms : MeasurementSystem}
(q1 q2 : Quantity d ms) :
Quantity d ms :=
match q1 with
| Quantity.mk l m t c p q i :=
match q2 with
| Quantity.mk l' m' t' c' p' q' i' :=
Quantity.mk (l+l') (scalar.add_mass m m') (t+t') (c+c') (scalar.add_temperature p p') (q+q') (scalar.add_intensity i i')
end
end
def sub {d : Dimension} {ms : MeasurementSystem} (q1 q2 : Quantity d ms) :
Quantity d ms :=
match q1 with
| Quantity.mk l m t c p q i :=
match q2 with
| Quantity.mk l' m' t' c' p' q' i' :=
Quantity.mk (l-l') (scalar.sub_mass m m') (t-t') (c-c') (scalar.sub_temperature p p') (q-q') (scalar.sub_intensity i i')
end
end
/-
We can multiple quantities as long as they are expressed with
respect to the same measurement systems. Clearly they don't need
to be in the same units, as we'd then be able to multiple, e.g.,
quantities expressed in meters and in seconds, respectively.
We note that we could build measurement system conversions in
here. We choose not to do so, leaving designers to make such
conversions explicit where needed.
-/
def mul
{ms : MeasurementSystem}
{d1 d2 : Dimension}
(q1 : Quantity d1 ms)
(q2 : Quantity d2 ms) : Quantity (mul d1 d2) ms :=
match q1 with
| Quantity.mk l m t c p q i :=
match q2 with
| Quantity.mk l' m' t' c' p' q' i' :=
Quantity.mk (l*l') (scalar.mul_mass m m') (t*t') (c*c') (scalar.mul_temperature p p') (q*q') (scalar.mul_intensity i i')
end
end
end quantity
|
f3e03e394fd19a9b8dfd15a3b9dc5891bd4a8bff | 500f65bb93c499cd35c3254d894d762208cae042 | /src/tactic/core.lean | 2b519fe9affac9fcf3d30df802570041d697000d | [
"Apache-2.0"
] | permissive | PatrickMassot/mathlib | c39dc0ff18bbde42f1c93a1642f6e429adad538c | 45df75b3c9da159fe3192fa7f769dfbec0bd6bda | refs/heads/master | 1,623,168,646,390 | 1,566,940,765,000 | 1,566,940,765,000 | 115,220,590 | 0 | 1 | null | 1,514,061,524,000 | 1,514,061,524,000 | null | UTF-8 | Lean | false | false | 39,997 | lean | /-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Simon Hudon, Scott Morrison, Keeley Hoek
-/
import data.dlist.basic category.basic meta.expr meta.rb_map data.string.defs
namespace expr
open tactic
attribute [derive has_reflect] binder_info
protected meta def of_nat (α : expr) : ℕ → tactic expr :=
nat.binary_rec
(tactic.mk_mapp ``has_zero.zero [some α, none])
(λ b n tac, if n = 0 then mk_mapp ``has_one.one [some α, none] else
do e ← tac, tactic.mk_app (cond b ``bit1 ``bit0) [e])
protected meta def of_int (α : expr) : ℤ → tactic expr
| (n : ℕ) := expr.of_nat α n
| -[1+ n] := do
e ← expr.of_nat α (n+1),
tactic.mk_app ``has_neg.neg [e]
/- only traverses the direct descendents -/
meta def {u} traverse {m : Type → Type u} [applicative m]
{elab elab' : bool} (f : expr elab → m (expr elab')) :
expr elab → m (expr elab')
| (var v) := pure $ var v
| (sort l) := pure $ sort l
| (const n ls) := pure $ const n ls
| (mvar n n' e) := mvar n n' <$> f e
| (local_const n n' bi e) := local_const n n' bi <$> f e
| (app e₀ e₁) := app <$> f e₀ <*> f e₁
| (lam n bi e₀ e₁) := lam n bi <$> f e₀ <*> f e₁
| (pi n bi e₀ e₁) := pi n bi <$> f e₀ <*> f e₁
| (elet n e₀ e₁ e₂) := elet n <$> f e₀ <*> f e₁ <*> f e₂
| (macro mac es) := macro mac <$> list.traverse f es
meta def mfoldl {α : Type} {m} [monad m] (f : α → expr → m α) : α → expr → m α
| x e := prod.snd <$> (state_t.run (e.traverse $ λ e',
(get >>= monad_lift ∘ flip f e' >>= put) $> e') x : m _)
end expr
namespace interaction_monad
open result
meta def get_result {σ α} (tac : interaction_monad σ α) :
interaction_monad σ (interaction_monad.result σ α) | s :=
match tac s with
| r@(success _ s') := success r s'
| r@(exception _ _ s') := success r s'
end
end interaction_monad
namespace lean.parser
open lean interaction_monad.result
meta def of_tactic' {α} (tac : tactic α) : parser α :=
do r ← of_tactic (interaction_monad.get_result tac),
match r with
| (success a _) := return a
| (exception f pos _) := exception f pos
end
-- Override the builtin `lean.parser.of_tactic` coe, which is broken.
-- (See test/tactics.lean for a failure case.)
@[priority 2000]
meta instance has_coe' {α} : has_coe (tactic α) (parser α) :=
⟨of_tactic'⟩
meta def emit_command_here (str : string) : lean.parser string :=
do (_, left) ← with_input command_like str,
return left
-- Emit a source code string at the location being parsed.
meta def emit_code_here : string → lean.parser unit
| str := do left ← emit_command_here str,
if left.length = 0 then return ()
else emit_code_here left
end lean.parser
namespace format
meta def intercalate (x : format) : list format → format :=
format.join ∘ list.intersperse x
end format
namespace tactic
meta def eval_expr' (α : Type*) [_inst_1 : reflected α] (e : expr) : tactic α :=
mk_app ``id [e] >>= eval_expr α
-- `mk_fresh_name` returns identifiers starting with underscores,
-- which are not legal when emitted by tactic programs. Turn the
-- useful source of random names provided by `mk_fresh_name` into
-- names which are usable by tactic programs.
--
-- The returned name has four components which are all strings.
meta def mk_user_fresh_name : tactic name :=
do nm ← mk_fresh_name,
return $ `user__ ++ nm.pop_prefix.sanitize_name ++ `user__
meta def is_simp_lemma : name → tactic bool :=
succeeds ∘ tactic.has_attribute `simp
meta def local_decls : tactic (name_map declaration) :=
do e ← tactic.get_env,
let xs := e.fold native.mk_rb_map
(λ d s, if environment.in_current_file' e d.to_name
then s.insert d.to_name d else s),
pure xs
/--
Returns a pair (e, t), where `e ← mk_const d.to_name`, and `t = d.type`
but with universe params updated to match the fresh universe metavariables in `e`.
This should have the same effect as just
```
do e ← mk_const d.to_name,
t ← infer_type e,
return (e, t)
```
but is hopefully faster.
-/
meta def decl_mk_const (d : declaration) : tactic (expr × expr) :=
do subst ← d.univ_params.mmap $ λ u, prod.mk u <$> mk_meta_univ,
let e : expr := expr.const d.to_name (prod.snd <$> subst),
return (e, d.type.instantiate_univ_params subst)
meta def simp_lemmas_from_file : tactic name_set :=
do s ← local_decls,
let s := s.map (expr.list_constant ∘ declaration.value),
xs ← s.to_list.mmap ((<$>) name_set.of_list ∘ mfilter tactic.is_simp_lemma ∘ name_set.to_list ∘ prod.snd),
return $ name_set.filter (λ x, ¬ s.contains x) (xs.foldl name_set.union mk_name_set)
meta def file_simp_attribute_decl (attr : name) : tactic unit :=
do s ← simp_lemmas_from_file,
trace format!"run_cmd mk_simp_attr `{attr}",
let lmms := format.join $ list.intersperse " " $ s.to_list.map to_fmt,
trace format!"local attribute [{attr}] {lmms}"
meta def mk_local (n : name) : expr :=
expr.local_const n n binder_info.default (expr.const n [])
meta def local_def_value (e : expr) : tactic expr := do
do (v,_) ← solve_aux `(true) (do
(expr.elet n t v _) ← (revert e >> target)
| fail format!"{e} is not a local definition",
return v),
return v
meta def check_defn (n : name) (e : pexpr) : tactic unit :=
do (declaration.defn _ _ _ d _ _) ← get_decl n,
e' ← to_expr e,
guard (d =ₐ e') <|> trace d >> failed
-- meta def compile_eqn (n : name) (univ : list name) (args : list expr) (val : expr) (num : ℕ) : tactic unit :=
-- do let lhs := (expr.const n $ univ.map level.param).mk_app args,
-- stmt ← mk_app `eq [lhs,val],
-- let vs := stmt.list_local_const,
-- let stmt := stmt.pis vs,
-- (_,pr) ← solve_aux stmt (tactic.intros >> reflexivity),
-- add_decl $ declaration.thm (n <.> "equations" <.> to_string (format!"_eqn_{num}")) univ stmt (pure pr)
meta def to_implicit : expr → expr
| (expr.local_const uniq n bi t) := expr.local_const uniq n binder_info.implicit t
| e := e
meta def pis : list expr → expr → tactic expr
| (e@(expr.local_const uniq pp info _) :: es) f := do
t ← infer_type e,
f' ← pis es f,
pure $ expr.pi pp info t (expr.abstract_local f' uniq)
| _ f := pure f
meta def lambdas : list expr → expr → tactic expr
| (e@(expr.local_const uniq pp info _) :: es) f := do
t ← infer_type e,
f' ← lambdas es f,
pure $ expr.lam pp info t (expr.abstract_local f' uniq)
| _ f := pure f
meta def extract_def (n : name) (trusted : bool) (elab_def : tactic unit) : tactic unit :=
do cxt ← list.map to_implicit <$> local_context,
t ← target,
(eqns,d) ← solve_aux t elab_def,
d ← instantiate_mvars d,
t' ← pis cxt t,
d' ← lambdas cxt d,
let univ := t'.collect_univ_params,
add_decl $ declaration.defn n univ t' d' (reducibility_hints.regular 1 tt) trusted,
applyc n
meta def exact_dec_trivial : tactic unit := `[exact dec_trivial]
/-- Runs a tactic for a result, reverting the state after completion -/
meta def retrieve {α} (tac : tactic α) : tactic α :=
λ s, result.cases_on (tac s)
(λ a s', result.success a s)
result.exception
/-- Repeat a tactic at least once, calling it recursively on all subgoals,
until it fails. This tactic fails if the first invocation fails. -/
meta def repeat1 (t : tactic unit) : tactic unit := t; repeat t
/-- `iterate_range m n t`: Repeat the given tactic at least `m` times and
at most `n` times or until `t` fails. Fails if `t` does not run at least m times. -/
meta def iterate_range : ℕ → ℕ → tactic unit → tactic unit
| 0 0 t := skip
| 0 (n+1) t := try (t >> iterate_range 0 n t)
| (m+1) n t := t >> iterate_range m (n-1) t
meta def replace_at (tac : expr → tactic (expr × expr)) (hs : list expr) (tgt : bool) : tactic bool :=
do to_remove ← hs.mfilter $ λ h, do {
h_type ← infer_type h,
succeeds $ do
(new_h_type, pr) ← tac h_type,
assert h.local_pp_name new_h_type,
mk_eq_mp pr h >>= tactic.exact },
goal_simplified ← succeeds $ do {
guard tgt,
(new_t, pr) ← target >>= tac,
replace_target new_t pr },
to_remove.mmap' (λ h, try (clear h)),
return (¬ to_remove.empty ∨ goal_simplified)
meta def simp_bottom_up' (post : expr → tactic (expr × expr)) (e : expr) (cfg : simp_config := {}) : tactic (expr × expr) :=
prod.snd <$> simplify_bottom_up () (λ _, (<$>) (prod.mk ()) ∘ post) e cfg
meta structure instance_cache :=
(α : expr)
(univ : level)
(inst : name_map expr)
meta def mk_instance_cache (α : expr) : tactic instance_cache :=
do u ← mk_meta_univ,
infer_type α >>= unify (expr.sort (level.succ u)),
u ← get_univ_assignment u,
return ⟨α, u, mk_name_map⟩
namespace instance_cache
meta def get (c : instance_cache) (n : name) : tactic (instance_cache × expr) :=
match c.inst.find n with
| some i := return (c, i)
| none := do e ← mk_app n [c.α] >>= mk_instance,
return (⟨c.α, c.univ, c.inst.insert n e⟩, e)
end
open expr
meta def append_typeclasses : expr → instance_cache → list expr →
tactic (instance_cache × list expr)
| (pi _ binder_info.inst_implicit (app (const n _) (var _)) body) c l :=
do (c, p) ← c.get n, return (c, p :: l)
| _ c l := return (c, l)
meta def mk_app (c : instance_cache) (n : name) (l : list expr) : tactic (instance_cache × expr) :=
do d ← get_decl n,
(c, l) ← append_typeclasses d.type.binding_body c l,
return (c, (expr.const n [c.univ]).mk_app (c.α :: l))
end instance_cache
meta def match_head (e : expr) : expr → tactic unit
| e' :=
unify e e'
<|> do `(_ → %%e') ← whnf e',
v ← mk_mvar,
match_head (e'.instantiate_var v)
meta def find_matching_head : expr → list expr → tactic (list expr)
| e [] := return []
| e (H :: Hs) :=
do t ← infer_type H,
((::) H <$ match_head e t <|> pure id) <*> find_matching_head e Hs
meta def subst_locals (s : list (expr × expr)) (e : expr) : expr :=
(e.abstract_locals (s.map (expr.local_uniq_name ∘ prod.fst)).reverse).instantiate_vars (s.map prod.snd)
meta def set_binder : expr → list binder_info → expr
| e [] := e
| (expr.pi v _ d b) (bi :: bs) := expr.pi v bi d (set_binder b bs)
| e _ := e
meta def last_explicit_arg : expr → tactic expr
| (expr.app f e) :=
do t ← infer_type f >>= whnf,
if t.binding_info = binder_info.default
then pure e
else last_explicit_arg f
| e := pure e
private meta def get_expl_pi_arity_aux : expr → tactic nat
| (expr.pi n bi d b) :=
do m ← mk_fresh_name,
let l := expr.local_const m n bi d,
new_b ← whnf (expr.instantiate_var b l),
r ← get_expl_pi_arity_aux new_b,
if bi = binder_info.default then
return (r + 1)
else
return r
| e := return 0
/-- Compute the arity of explicit arguments of the given (Pi-)type -/
meta def get_expl_pi_arity (type : expr) : tactic nat :=
whnf type >>= get_expl_pi_arity_aux
/-- Compute the arity of explicit arguments of the given function -/
meta def get_expl_arity (fn : expr) : tactic nat :=
infer_type fn >>= get_expl_pi_arity
/-- variation on `assert` where a (possibly incomplete)
proof of the assertion is provided as a parameter.
``(h,gs) ← local_proof `h p tac`` creates a local `h : p` and
use `tac` to (partially) construct a proof for it. `gs` is the
list of remaining goals in the proof of `h`.
The benefits over assert are:
- unlike with ``h ← assert `h p, tac`` , `h` cannot be used by `tac`;
- when `tac` does not complete the proof of `h`, returning the list
of goals allows one to write a tactic using `h` and with the confidence
that a proof will not boil over to goals left over from the proof of `h`,
unlike what would be the case when using `tactic.swap`.
-/
meta def local_proof (h : name) (p : expr) (tac₀ : tactic unit) :
tactic (expr × list expr) :=
focus1 $
do h' ← assert h p,
[g₀,g₁] ← get_goals,
set_goals [g₀], tac₀,
gs ← get_goals,
set_goals [g₁],
return (h', gs)
meta def var_names : expr → list name
| (expr.pi n _ _ b) := n :: var_names b
| _ := []
meta def drop_binders : expr → tactic expr
| (expr.pi n bi t b) := b.instantiate_var <$> mk_local' n bi t >>= drop_binders
| e := pure e
meta def subobject_names (struct_n : name) : tactic (list name × list name) :=
do env ← get_env,
[c] ← pure $ env.constructors_of struct_n | fail "too many constructors",
vs ← var_names <$> (mk_const c >>= infer_type),
fields ← env.structure_fields struct_n,
return $ fields.partition (λ fn, ↑("_" ++ fn.to_string) ∈ vs)
meta def expanded_field_list' : name → tactic (dlist $ name × name) | struct_n :=
do (so,fs) ← subobject_names struct_n,
ts ← so.mmap (λ n, do
e ← mk_const (n.update_prefix struct_n) >>= infer_type >>= drop_binders,
expanded_field_list' $ e.get_app_fn.const_name),
return $ dlist.join ts ++ dlist.of_list (fs.map $ prod.mk struct_n)
open functor function
meta def expanded_field_list (struct_n : name) : tactic (list $ name × name) :=
dlist.to_list <$> expanded_field_list' struct_n
meta def get_classes (e : expr) : tactic (list name) :=
attribute.get_instances `class >>= list.mfilter (λ n,
succeeds $ mk_app n [e] >>= mk_instance)
open nat
meta def mk_mvar_list : ℕ → tactic (list expr)
| 0 := pure []
| (succ n) := (::) <$> mk_mvar <*> mk_mvar_list n
/-- Returns the only goal, or fails if there isn't just one goal. -/
meta def get_goal : tactic expr :=
do gs ← get_goals,
match gs with
| [a] := return a
| [] := fail "there are no goals"
| _ := fail "there are too many goals"
end
/--`iterate_at_most_on_all_goals n t`: repeat the given tactic at most `n` times on all goals,
or until it fails. Always succeeds. -/
meta def iterate_at_most_on_all_goals : nat → tactic unit → tactic unit
| 0 tac := trace "maximal iterations reached"
| (succ n) tac := tactic.all_goals $ (do tac, iterate_at_most_on_all_goals n tac) <|> skip
/--`iterate_at_most_on_subgoals n t`: repeat the tactic `t` at most `n` times on the first
goal and on all subgoals thus produced, or until it fails. Fails iff `t` fails on
current goal. -/
meta def iterate_at_most_on_subgoals : nat → tactic unit → tactic unit
| 0 tac := trace "maximal iterations reached"
| (succ n) tac := focus1 (do tac, iterate_at_most_on_all_goals n tac)
/--`apply_list l`: try to apply the tactics in the list `l` on the first goal, and
fail if none succeeds -/
meta def apply_list_expr : list expr → tactic unit
| [] := fail "no matching rule"
| (h::t) := do interactive.concat_tags (apply h) <|> apply_list_expr t
/-- constructs a list of expressions given a list of p-expressions, as follows:
- if the p-expression is the name of a theorem, use `i_to_expr_for_apply` on it
- if the p-expression is a user attribute, add all the theorems with this attribute
to the list.-/
meta def build_list_expr_for_apply : list pexpr → tactic (list expr)
| [] := return []
| (h::t) := do
tail ← build_list_expr_for_apply t,
a ← i_to_expr_for_apply h,
(do l ← attribute.get_instances (expr.const_name a),
m ← list.mmap mk_const l,
return (m.append tail))
<|> return (a::tail)
/--`apply_rules hs n`: apply the list of rules `hs` (given as pexpr) and `assumption` on the
first goal and the resulting subgoals, iteratively, at most `n` times -/
meta def apply_rules (hs : list pexpr) (n : nat) : tactic unit :=
do l ← build_list_expr_for_apply hs,
iterate_at_most_on_subgoals n (assumption <|> apply_list_expr l)
meta def replace (h : name) (p : pexpr) : tactic unit :=
do h' ← get_local h,
p ← to_expr p,
note h none p,
clear h'
/-- Auxiliary function for `iff_mp` and `iff_mpr`. Takes a name, which should be either `` `iff.mp``
or `` `iff.mpr``. If the passed expression is an iterated function type eventually producing an
`iff`, returns an expression with the `iff` converted to either the forwards or backwards
implication, as requested. -/
meta def mk_iff_mp_app (iffmp : name) : expr → (nat → expr) → option expr
| (expr.pi n bi e t) f := expr.lam n bi e <$> mk_iff_mp_app t (λ n, f (n+1) (expr.var n))
| `(%%a ↔ %%b) f := some $ @expr.const tt iffmp [] a b (f 0)
| _ f := none
meta def iff_mp_core (e ty: expr) : option expr :=
mk_iff_mp_app `iff.mp ty (λ_, e)
meta def iff_mpr_core (e ty: expr) : option expr :=
mk_iff_mp_app `iff.mpr ty (λ_, e)
/-- Given an expression whose type is (a possibly iterated function producing) an `iff`,
create the expression which is the forward implication. -/
meta def iff_mp (e : expr) : tactic expr :=
do t ← infer_type e,
iff_mp_core e t <|> fail "Target theorem must have the form `Π x y z, a ↔ b`"
/-- Given an expression whose type is (a possibly iterated function producing) an `iff`,
create the expression which is the reverse implication. -/
meta def iff_mpr (e : expr) : tactic expr :=
do t ← infer_type e,
iff_mpr_core e t <|> fail "Target theorem must have the form `Π x y z, a ↔ b`"
/--
Attempts to apply `e`, and if that fails, if `e` is an `iff`,
try applying both directions separately.
-/
meta def apply_iff (e : expr) : tactic (list (name × expr)) :=
let ap e := tactic.apply e {new_goals := new_goals.non_dep_only} in
ap e <|> (iff_mp e >>= ap) <|> (iff_mpr e >>= ap)
meta def symm_apply (e : expr) (cfg : apply_cfg := {}) : tactic (list (name × expr)) :=
tactic.apply e cfg <|> (symmetry >> tactic.apply e cfg)
meta def apply_assumption
(asms : tactic (list expr) := local_context)
(tac : tactic unit := skip) : tactic unit :=
do { ctx ← asms,
ctx.any_of (λ H, symm_apply H >> tac) } <|>
do { exfalso,
ctx ← asms,
ctx.any_of (λ H, symm_apply H >> tac) }
<|> fail "assumption tactic failed"
meta def change_core (e : expr) : option expr → tactic unit
| none := tactic.change e
| (some h) :=
do num_reverted : ℕ ← revert h,
expr.pi n bi d b ← target,
tactic.change $ expr.pi n bi e b,
intron num_reverted
/--
assuming olde and newe are defeq when elaborated, replaces occurences of olde with newe at hypothesis h.
-/
meta def change_with_at (olde newe : pexpr) (hyp : name) : tactic unit :=
do h ← get_local hyp,
tp ← infer_type h,
olde ← to_expr olde, newe ← to_expr newe,
let repl_tp := tp.replace (λ a n, if a = olde then some newe else none),
change_core repl_tp (some h)
meta def metavariables : tactic (list expr) :=
do r ← result,
pure (r.list_meta_vars)
/-- Succeeds only if the current goal is a proposition. -/
meta def propositional_goal : tactic unit :=
do goals ← get_goals,
p ← is_proof goals.head,
guard p
/-- Succeeds only if we can construct an instance showing the
current goal is a subsingleton type. -/
meta def subsingleton_goal : tactic unit :=
do goals ← get_goals,
ty ← infer_type goals.head >>= instantiate_mvars,
to_expr ``(subsingleton %%ty) >>= mk_instance >> skip
/-- Succeeds only if the current goal is "terminal", in the sense
that no other goals depend on it. -/
meta def terminal_goal : tactic unit :=
-- We can't merely test for subsingletons, as sometimes in the presence of metavariables
-- `propositional_goal` succeeds while `subsingleton_goal` does not.
propositional_goal <|> subsingleton_goal <|>
do g₀ :: _ ← get_goals,
mvars ← (λ L, list.erase L g₀) <$> metavariables,
mvars.mmap' $ λ g, do
t ← infer_type g >>= instantiate_mvars,
d ← kdepends_on t g₀,
monad.whenb d $
pp t >>= λ s, fail ("The current goal is not terminal: " ++ s.to_string ++ " depends on it.")
meta def triv' : tactic unit := do c ← mk_const `trivial, exact c reducible
variable {α : Type}
private meta def iterate_aux (t : tactic α) : list α → tactic (list α)
| L := (do r ← t, iterate_aux (r :: L)) <|> return L
/-- Apply a tactic as many times as possible, collecting the results in a list. -/
meta def iterate' (t : tactic α) : tactic (list α) :=
list.reverse <$> iterate_aux t []
/-- Like iterate', but fail if the tactic does not succeed at least once. -/
meta def iterate1 (t : tactic α) : tactic (α × list α) :=
do r ← decorate_ex "iterate1 failed: tactic did not succeed" t,
L ← iterate' t,
return (r, L)
meta def intros1 : tactic (list expr) :=
iterate1 intro1 >>= λ p, return (p.1 :: p.2)
/-- `successes` invokes each tactic in turn, returning the list of successful results. -/
meta def successes (tactics : list (tactic α)) : tactic (list α) :=
list.filter_map id <$> monad.sequence (tactics.map (λ t, try_core t))
/-- Return target after instantiating metavars and whnf -/
private meta def target' : tactic expr :=
target >>= instantiate_mvars >>= whnf
/--
Just like `split`, `fsplit` applies the constructor when the type of the target is an inductive data type with one constructor.
However it does not reorder goals or invoke `auto_param` tactics.
-/
-- FIXME check if we can remove `auto_param := ff`
meta def fsplit : tactic unit :=
do [c] ← target' >>= get_constructors_for | tactic.fail "fsplit tactic failed, target is not an inductive datatype with only one constructor",
mk_const c >>= λ e, apply e {new_goals := new_goals.all, auto_param := ff} >> skip
run_cmd add_interactive [`fsplit]
/-- Calls `injection` on each hypothesis, and then, for each hypothesis on which `injection`
succeeds, clears the old hypothesis. -/
meta def injections_and_clear : tactic unit :=
do l ← local_context,
results ← successes $ l.map $ λ e, injection e >> clear e,
when (results.empty) (fail "could not use `injection` then `clear` on any hypothesis")
run_cmd add_interactive [`injections_and_clear]
/-- calls `cases` on every local hypothesis, succeeding if
it succeeds on at least one hypothesis. -/
meta def case_bash : tactic unit :=
do l ← local_context,
r ← successes (l.reverse.map (λ h, cases h >> skip)),
when (r.empty) failed
/-- given a proof `pr : t`, adds `h : t` to the current context, where the name `h` is fresh. -/
meta def note_anon (e : expr) : tactic expr :=
do n ← get_unused_name "lh",
note n none e
/-- `find_local t` returns a local constant with type t, or fails if none exists. -/
meta def find_local (t : pexpr) : tactic expr :=
do t' ← to_expr t,
prod.snd <$> solve_aux t' assumption
/-- `dependent_pose_core l`: introduce dependent hypothesis, where the proofs depend on the values
of the previous local constants. `l` is a list of local constants and their values. -/
meta def dependent_pose_core (l : list (expr × expr)) : tactic unit := do
let lc := l.map prod.fst,
let lm := l.map (λ⟨l, v⟩, (l.local_uniq_name, v)),
t ← target,
new_goal ← mk_meta_var (t.pis lc),
old::other_goals ← get_goals,
set_goals (old :: new_goal :: other_goals),
exact ((new_goal.mk_app lc).instantiate_locals lm),
return ()
/-- like `mk_local_pis` but translating into weak head normal form before checking if it is a Π. -/
meta def mk_local_pis_whnf : expr → tactic (list expr × expr) | e := do
(expr.pi n bi d b) ← whnf e | return ([], e),
p ← mk_local' n bi d,
(ps, r) ← mk_local_pis (expr.instantiate_var b p),
return ((p :: ps), r)
/-- Changes `(h : ∀xs, ∃a:α, p a) ⊢ g` to `(d : ∀xs, a) (s : ∀xs, p (d xs) ⊢ g` -/
meta def choose1 (h : expr) (data : name) (spec : name) : tactic expr := do
t ← infer_type h,
(ctxt, t) ← mk_local_pis_whnf t,
`(@Exists %%α %%p) ← whnf t transparency.all | fail "expected a term of the shape ∀xs, ∃a, p xs a",
α_t ← infer_type α,
expr.sort u ← whnf α_t transparency.all,
value ← mk_local_def data (α.pis ctxt),
t' ← head_beta (p.app (value.mk_app ctxt)),
spec ← mk_local_def spec (t'.pis ctxt),
dependent_pose_core [
(value, ((((expr.const `classical.some [u]).app α).app p).app (h.mk_app ctxt)).lambdas ctxt),
(spec, ((((expr.const `classical.some_spec [u]).app α).app p).app (h.mk_app ctxt)).lambdas ctxt)],
try (tactic.clear h),
intro1,
intro1
/-- Changes `(h : ∀xs, ∃as, p as) ⊢ g` to a list of functions `as`, an a final hypothesis on `p as` -/
meta def choose : expr → list name → tactic unit
| h [] := fail "expect list of variables"
| h [n] := do
cnt ← revert h,
intro n,
intron (cnt - 1),
return ()
| h (n::ns) := do
v ← get_unused_name >>= choose1 h n,
choose v ns
/-- This makes sure that the execution of the tactic does not change the tactic state.
This can be helpful while using rewrite, apply, or expr munging.
Remember to instantiate your metavariables before you're done! -/
meta def lock_tactic_state {α} (t : tactic α) : tactic α
| s := match t s with
| result.success a s' := result.success a s
| result.exception msg pos s' := result.exception msg pos s
end
/-- similar to `mk_local_pis` but make meta variables instead of
local constants -/
meta def mk_meta_pis : expr → tactic (list expr × expr)
| (expr.pi n bi d b) := do
p ← mk_meta_var d,
(ps, r) ← mk_meta_pis (expr.instantiate_var b p),
return ((p :: ps), r)
| e := return ([], e)
/--
Hole command used to fill in a structure's field when specifying an instance.
In the following:
```
instance : monad id :=
{! !}
```
invoking hole command `Instance Stub` produces:
```
instance : monad id :=
{ map := _,
map_const := _,
pure := _,
seq := _,
seq_left := _,
seq_right := _,
bind := _ }
```
-/
@[hole_command] meta def instance_stub : hole_command :=
{ name := "Instance Stub",
descr := "Generate a skeleton for the structure under construction.",
action := λ _,
do tgt ← target >>= whnf,
let cl := tgt.get_app_fn.const_name,
env ← get_env,
fs ← expanded_field_list cl,
let fs := fs.map prod.snd,
let fs := format.intercalate (",\n " : format) $ fs.map (λ fn, format!"{fn} := _"),
let out := format.to_string format!"{{ {fs} }",
return [(out,"")] }
meta def strip_prefix' (n : name) : list string → name → tactic name
| s name.anonymous := pure $ s.foldl (flip name.mk_string) name.anonymous
| s (name.mk_string a p) :=
do let n' := s.foldl (flip name.mk_string) name.anonymous,
do { n'' ← tactic.resolve_constant n',
if n'' = n
then pure n'
else strip_prefix' (a :: s) p }
<|> strip_prefix' (a :: s) p
| s (name.mk_numeral a p) := interaction_monad.failed
meta def strip_prefix : name → tactic name
| n@(name.mk_string a a_1) := strip_prefix' n [a] a_1
| _ := interaction_monad.failed
meta def local_binding_info : expr → binder_info
| (expr.local_const _ _ bi _) := bi
| _ := binder_info.default
meta def is_default_local : expr → bool
| (expr.local_const _ _ binder_info.default _) := tt
| _ := ff
meta def mk_patterns (t : expr) : tactic (list format) :=
do let cl := t.get_app_fn.const_name,
env ← get_env,
let fs := env.constructors_of cl,
fs.mmap $ λ f,
do { (vs,_) ← mk_const f >>= infer_type >>= mk_local_pis,
let vs := vs.filter (λ v, is_default_local v),
vs ← vs.mmap (λ v,
do v' ← get_unused_name v.local_pp_name,
pose v' none `(()),
pure v' ),
vs.mmap' $ λ v, get_local v >>= clear,
let args := list.intersperse (" " : format) $ vs.map to_fmt,
f ← strip_prefix f,
if args.empty
then pure $ format!"| {f} := _\n"
else pure format!"| ({f} {format.join args}) := _\n" }
/--
Hole command used to generate a `match` expression.
In the following:
```
meta def foo (e : expr) : tactic unit :=
{! e !}
```
invoking hole command `Match Stub` produces:
```
meta def foo (e : expr) : tactic unit :=
match e with
| (expr.var a) := _
| (expr.sort a) := _
| (expr.const a a_1) := _
| (expr.mvar a a_1 a_2) := _
| (expr.local_const a a_1 a_2 a_3) := _
| (expr.app a a_1) := _
| (expr.lam a a_1 a_2 a_3) := _
| (expr.pi a a_1 a_2 a_3) := _
| (expr.elet a a_1 a_2 a_3) := _
| (expr.macro a a_1) := _
end
```
-/
@[hole_command] meta def match_stub : hole_command :=
{ name := "Match Stub",
descr := "Generate a list of equations for a `match` expression.",
action := λ es,
do [e] ← pure es | fail "expecting one expression",
e ← to_expr e,
t ← infer_type e >>= whnf,
fs ← mk_patterns t,
e ← pp e,
let out := format.to_string format!"match {e} with\n{format.join fs}end\n",
return [(out,"")] }
/--
Hole command used to generate a `match` expression.
In the following:
```
meta def foo : {! expr → tactic unit !} -- `:=` is omitted
```
invoking hole command `Equations Stub` produces:
```
meta def foo : expr → tactic unit
| (expr.var a) := _
| (expr.sort a) := _
| (expr.const a a_1) := _
| (expr.mvar a a_1 a_2) := _
| (expr.local_const a a_1 a_2 a_3) := _
| (expr.app a a_1) := _
| (expr.lam a a_1 a_2 a_3) := _
| (expr.pi a a_1 a_2 a_3) := _
| (expr.elet a a_1 a_2 a_3) := _
| (expr.macro a a_1) := _
```
A similar result can be obtained by invoking `Equations Stub` on the following:
```
meta def foo : expr → tactic unit := -- do not forget to write `:=`!!
{! !}
```
```
meta def foo : expr → tactic unit := -- don't forget to erase `:=`!!
| (expr.var a) := _
| (expr.sort a) := _
| (expr.const a a_1) := _
| (expr.mvar a a_1 a_2) := _
| (expr.local_const a a_1 a_2 a_3) := _
| (expr.app a a_1) := _
| (expr.lam a a_1 a_2 a_3) := _
| (expr.pi a a_1 a_2 a_3) := _
| (expr.elet a a_1 a_2 a_3) := _
| (expr.macro a a_1) := _
```
-/
@[hole_command] meta def eqn_stub : hole_command :=
{ name := "Equations Stub",
descr := "Generate a list of equations for a recursive definition.",
action := λ es,
do t ← match es with
| [t] := to_expr t
| [] := target
| _ := fail "expecting one type"
end,
e ← whnf t,
(v :: _,_) ← mk_local_pis e | fail "expecting a Pi-type",
t' ← infer_type v,
fs ← mk_patterns t',
t ← pp t,
let out :=
if es.empty then
format.to_string format!"-- do not forget to erase `:=`!!\n{format.join fs}"
else format.to_string format!"{t}\n{format.join fs}",
return [(out,"")] }
/--
This command lists the constructors that can be used to satisfy the expected type.
When used in the following hole:
```
def foo : ℤ ⊕ ℕ :=
{! !}
```
the command will produce:
```
def foo : ℤ ⊕ ℕ :=
{! sum.inl, sum.inr !}
```
and will display:
```
sum.inl : ℤ → ℤ ⊕ ℕ
sum.inr : ℕ → ℤ ⊕ ℕ
```
-/
@[hole_command] meta def list_constructors_hole : hole_command :=
{ name := "List Constructors",
descr := "Show the list of constructors of the expected type.",
action := λ es,
do t ← target >>= whnf,
(_,t) ← mk_local_pis t,
let cl := t.get_app_fn.const_name,
let args := t.get_app_args,
env ← get_env,
let cs := env.constructors_of cl,
ts ← cs.mmap $ λ c,
do { e ← mk_const c,
t ← infer_type (e.mk_app args) >>= pp,
c ← strip_prefix c,
pure format!"\n{c} : {t}\n" },
fs ← format.intercalate ", " <$> cs.mmap (strip_prefix >=> pure ∘ to_fmt),
let out := format.to_string format!"{{! {fs} !}",
trace (format.join ts).to_string,
return [(out,"")] }
meta def classical : tactic unit :=
do h ← get_unused_name `_inst,
mk_const `classical.prop_decidable >>= note h none,
reset_instance_cache
open expr
meta def add_prime : name → name
| (name.mk_string s p) := name.mk_string (s ++ "'") p
| n := (name.mk_string "x'" n)
meta def mk_comp (v : expr) : expr → tactic expr
| (app f e) :=
if e = v then pure f
else do
guard (¬ v.occurs f) <|> fail "bad guard",
e' ← mk_comp e >>= instantiate_mvars,
f ← instantiate_mvars f,
mk_mapp ``function.comp [none,none,none,f,e']
| e :=
do guard (e = v),
t ← infer_type e,
mk_mapp ``id [t]
meta def mk_higher_order_type : expr → tactic expr
| (pi n bi d b@(pi _ _ _ _)) :=
do v ← mk_local_def n d,
let b' := (b.instantiate_var v),
(pi n bi d ∘ flip abstract_local v.local_uniq_name) <$> mk_higher_order_type b'
| (pi n bi d b) :=
do v ← mk_local_def n d,
let b' := (b.instantiate_var v),
(l,r) ← match_eq b' <|> fail format!"not an equality {b'}",
l' ← mk_comp v l,
r' ← mk_comp v r,
mk_app ``eq [l',r']
| e := failed
open lean.parser interactive.types
@[user_attribute]
meta def higher_order_attr : user_attribute unit (option name) :=
{ name := `higher_order,
parser := optional ident,
descr :=
"From a lemma of the shape `f (g x) = h x` derive an auxiliary lemma of the
form `f ∘ g = h` for reasoning about higher-order functions.",
after_set := some $ λ lmm _ _,
do env ← get_env,
decl ← env.get lmm,
let num := decl.univ_params.length,
let lvls := (list.iota num).map (`l).append_after,
let l : expr := expr.const lmm $ lvls.map level.param,
t ← infer_type l >>= instantiate_mvars,
t' ← mk_higher_order_type t,
(_,pr) ← solve_aux t' $ do {
intros, applyc ``_root_.funext, intro1, applyc lmm; assumption },
pr ← instantiate_mvars pr,
lmm' ← higher_order_attr.get_param lmm,
lmm' ← (flip name.update_prefix lmm.get_prefix <$> lmm') <|> pure (add_prime lmm),
add_decl $ declaration.thm lmm' lvls t' (pure pr),
copy_attribute `simp lmm tt lmm',
copy_attribute `functor_norm lmm tt lmm' }
attribute [higher_order map_comp_pure] map_pure
private meta def tactic.use_aux (h : pexpr) : tactic unit :=
(focus1 (refine h >> done)) <|> (fconstructor >> tactic.use_aux)
meta def tactic.use (l : list pexpr) : tactic unit :=
focus1 $ l.mmap' $ λ h, tactic.use_aux h <|> fail format!"failed to instantiate goal with {h}"
meta def clear_aux_decl_aux : list expr → tactic unit
| [] := skip
| (e::l) := do cond e.is_aux_decl (tactic.clear e) skip, clear_aux_decl_aux l
meta def clear_aux_decl : tactic unit :=
local_context >>= clear_aux_decl_aux
/-- `apply_at_aux e et [] h ht` (with `et` the type of `e` and `ht` the type of `h`)
finds a list of expressions `vs` and returns (e.mk_args (vs ++ [h]), vs) -/
meta def apply_at_aux (arg t : expr) : list expr → expr → expr → tactic (expr × list expr)
| vs e (pi n bi d b) :=
do { v ← mk_meta_var d,
apply_at_aux (v :: vs) (e v) (b.instantiate_var v) } <|>
(e arg, vs) <$ unify d t
| vs e _ := failed
/-- `apply_at e h` applies implication `e` on hypothesis `h` and replaces `h` with the result -/
meta def apply_at (e h : expr) : tactic unit :=
do ht ← infer_type h,
et ← infer_type e,
(h', gs') ← apply_at_aux h ht [] e et,
note h.local_pp_name none h',
clear h,
gs' ← gs'.mfilter is_assigned,
(g :: gs) ← get_goals,
set_goals (g :: gs' ++ gs)
/-- `symmetry_hyp h` applies symmetry on hypothesis `h` -/
meta def symmetry_hyp (h : expr) (md := semireducible) : tactic unit :=
do tgt ← infer_type h,
env ← get_env,
let r := get_app_fn tgt,
match env.symm_for (const_name r) with
| (some symm) := do s ← mk_const symm,
apply_at s h
| none := fail "symmetry tactic failed, target is not a relation application with the expected property."
end
precedence `setup_tactic_parser`:0
@[user_command]
meta def setup_tactic_parser_cmd (_ : interactive.parse $ tk "setup_tactic_parser") : lean.parser unit :=
emit_code_here "
open lean
open lean.parser
open interactive interactive.types
local postfix `?`:9001 := optional
local postfix *:9001 := many .
"
meta def trace_error (msg : string) (t : tactic α) : tactic α
| s := match t s with
| (result.success r s') := result.success r s'
| (result.exception (some msg') p s') := (trace msg >> trace (msg' ()) >> result.exception (some msg') p) s'
| (result.exception none p s') := result.exception none p s'
end
/--
This combinator is for testing purposes. It succeeds if `t` fails with message `msg`,
and fails otherwise.
-/
meta def {u} success_if_fail_with_msg {α : Type u} (t : tactic α) (msg : string) : tactic unit :=
λ s, match t s with
| (interaction_monad.result.exception msg' _ s') :=
if msg = (msg'.iget ()).to_string then result.success () s
else mk_exception "failure messages didn't match" none s
| (interaction_monad.result.success a s) :=
mk_exception "success_if_fail_with_msg combinator failed, given tactic succeeded" none s
end
open lean interactive
meta def pformat := tactic format
meta def pformat.mk (fmt : format) : pformat := pure fmt
meta def to_pfmt {α} [has_to_tactic_format α] (x : α) : pformat :=
pp x
meta instance pformat.has_to_tactic_format : has_to_tactic_format pformat :=
⟨ id ⟩
meta instance : has_append pformat :=
⟨ λ x y, (++) <$> x <*> y ⟩
meta instance tactic.has_to_tactic_format [has_to_tactic_format α] : has_to_tactic_format (tactic α) :=
⟨ λ x, x >>= to_pfmt ⟩
private meta def parse_pformat : string → list char → parser pexpr
| acc [] := pure ``(to_pfmt %%(reflect acc))
| acc ('\n'::s) :=
do f ← parse_pformat "" s,
pure ``(to_pfmt %%(reflect acc) ++ pformat.mk format.line ++ %%f)
| acc ('{'::'{'::s) := parse_pformat (acc ++ "{") s
| acc ('{'::s) :=
do (e, s) ← with_input (lean.parser.pexpr 0) s.as_string,
'}'::s ← return s.to_list | fail "'}' expected",
f ← parse_pformat "" s,
pure ``(to_pfmt %%(reflect acc) ++ to_pfmt %%e ++ %%f)
| acc (c::s) := parse_pformat (acc.str c) s
reserve prefix `pformat! `:100
/-- See `format!` in `init/meta/interactive_base.lean`.
The main differences are that `pp` is called instead of `to_fmt` and that we can use
arguments of type `tactic α` in the quotations.
Now, consider the following:
```
e ← to_expr ``(3 + 7),
trace format!"{e}" -- outputs `has_add.add.{0} nat nat.has_add (bit1.{0} nat nat.has_one nat.has_add (has_one.one.{0} nat nat.has_one)) ...`
trace pformat!"{e}" -- outputs `3 + 7`
```
The difference is significant. And now, the following is expressible:
```
e ← to_expr ``(3 + 7),
trace pformat!"{e} : {infer_type e}" -- outputs `3 + 7 : ℕ`
```
See also: `trace!` and `fail!`
-/
@[user_notation]
meta def pformat_macro (_ : parse $ tk "pformat!") (s : string) : parser pexpr :=
do e ← parse_pformat "" s.to_list,
return ``(%%e : pformat)
reserve prefix `fail! `:100
/--
the combination of `pformat` and `fail`
-/
@[user_notation]
meta def fail_macro (_ : parse $ tk "fail!") (s : string) : parser pexpr :=
do e ← pformat_macro () s,
pure ``((%%e : pformat) >>= fail)
reserve prefix `trace! `:100
/--
the combination of `pformat` and `fail`
-/
@[user_notation]
meta def trace_macro (_ : parse $ tk "trace!") (s : string) : parser pexpr :=
do e ← pformat_macro () s,
pure ``((%%e : pformat) >>= trace)
/-- A hackish way to get the `src` directory of mathlib. -/
meta def get_mathlib_dir : tactic string :=
do e ← get_env,
s ← e.decl_olean `tactic.reset_instance_cache,
return $ s.popn_back 17
/-- Checks whether `ml` is a prefix of the file where `n` is declared.
If you want to run `is_in_mathlib` many times, you should use this tactic instead,
since it is expensive to execute get_mathlib_dir many times. -/
meta def is_in_mathlib_aux (ml : string) (n : name) : tactic bool :=
do e ← get_env, return $ ml.is_prefix_of $ (e.decl_olean n).get_or_else ""
/-- Checks whether a declaration with the given name is declared in mathlib.
If you want to run this tactic many times, you should use `is_in_mathlib_aux` instead,
since it is expensive to execute get_mathlib_dir many times. -/
meta def is_in_mathlib (n : name) : tactic bool :=
do ml ← get_mathlib_dir, is_in_mathlib_aux ml n
end tactic
open tactic
|
70a0791e6a7ff6b041e090d495f5ec45901b46c3 | 9dc8cecdf3c4634764a18254e94d43da07142918 | /src/data/finset/nat_antidiagonal.lean | ce3779bfd31ef8a1777dfc3c484e490eb894b6f1 | [
"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,799 | lean | /-
Copyright (c) 2019 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin
-/
import data.finset.card
import data.multiset.nat_antidiagonal
/-!
# Antidiagonals in ℕ × ℕ as finsets
This file defines the antidiagonals of ℕ × ℕ as finsets: the `n`-th antidiagonal is the finset of
pairs `(i, j)` such that `i + j = n`. This is useful for polynomial multiplication and more
generally for sums going from `0` to `n`.
## Notes
This refines files `data.list.nat_antidiagonal` and `data.multiset.nat_antidiagonal`.
-/
namespace finset
namespace nat
/-- The antidiagonal of a natural number `n` is
the finset of pairs `(i, j)` such that `i + j = n`. -/
def antidiagonal (n : ℕ) : finset (ℕ × ℕ) :=
⟨multiset.nat.antidiagonal n, multiset.nat.nodup_antidiagonal n⟩
/-- A pair (i, j) is contained in the antidiagonal of `n` if and only if `i + j = n`. -/
@[simp] lemma mem_antidiagonal {n : ℕ} {x : ℕ × ℕ} :
x ∈ antidiagonal n ↔ x.1 + x.2 = n :=
by rw [antidiagonal, mem_def, multiset.nat.mem_antidiagonal]
/-- The cardinality of the antidiagonal of `n` is `n + 1`. -/
@[simp] lemma card_antidiagonal (n : ℕ) : (antidiagonal n).card = n+1 :=
by simp [antidiagonal]
/-- The antidiagonal of `0` is the list `[(0, 0)]` -/
@[simp] lemma antidiagonal_zero : antidiagonal 0 = {(0, 0)} :=
rfl
lemma antidiagonal_succ (n : ℕ) :
antidiagonal (n + 1) = cons (0, n + 1) ((antidiagonal n).map
(function.embedding.prod_map ⟨nat.succ, nat.succ_injective⟩ (function.embedding.refl _)))
(by simp) :=
begin
apply eq_of_veq,
rw [cons_val, map_val],
{ apply multiset.nat.antidiagonal_succ },
end
lemma antidiagonal_succ' (n : ℕ) :
antidiagonal (n + 1) = cons (n + 1, 0) ((antidiagonal n).map
(function.embedding.prod_map (function.embedding.refl _) ⟨nat.succ, nat.succ_injective⟩))
(by simp) :=
begin
apply eq_of_veq,
rw [cons_val, map_val],
exact multiset.nat.antidiagonal_succ',
end
lemma antidiagonal_succ_succ' {n : ℕ} :
antidiagonal (n + 2) =
cons (0, n + 2)
(cons (n + 2, 0) ((antidiagonal n).map
(function.embedding.prod_map ⟨nat.succ, nat.succ_injective⟩ ⟨nat.succ, nat.succ_injective⟩))
$ by simp) (by simp) :=
by { simp_rw [antidiagonal_succ (n + 1), antidiagonal_succ', finset.map_cons, map_map], refl }
lemma map_swap_antidiagonal {n : ℕ} :
(antidiagonal n).map ⟨prod.swap, prod.swap_right_inverse.injective⟩ = antidiagonal n :=
eq_of_veq $ by simp [antidiagonal, multiset.nat.map_swap_antidiagonal]
/-- A point in the antidiagonal is determined by its first co-ordinate. -/
lemma antidiagonal_congr {n : ℕ} {p q : ℕ × ℕ} (hp : p ∈ antidiagonal n)
(hq : q ∈ antidiagonal n) : p = q ↔ p.fst = q.fst :=
begin
refine ⟨congr_arg prod.fst, (λ h, prod.ext h ((add_right_inj q.fst).mp _))⟩,
rw mem_antidiagonal at hp hq,
rw [hq, ← h, hp],
end
lemma antidiagonal.fst_le {n : ℕ} {kl : ℕ × ℕ} (hlk : kl ∈ antidiagonal n) :
kl.1 ≤ n :=
begin
rw le_iff_exists_add,
use kl.2,
rwa [mem_antidiagonal, eq_comm] at hlk
end
lemma antidiagonal.snd_le {n : ℕ} {kl : ℕ × ℕ} (hlk : kl ∈ antidiagonal n) :
kl.2 ≤ n :=
begin
rw le_iff_exists_add,
use kl.1,
rwa [mem_antidiagonal, eq_comm, add_comm] at hlk
end
lemma filter_fst_eq_antidiagonal (n m : ℕ) :
filter (λ x : ℕ × ℕ, x.fst = m) (antidiagonal n) = if m ≤ n then {(m, n - m)} else ∅ :=
begin
ext ⟨x, y⟩,
simp only [mem_filter, nat.mem_antidiagonal],
split_ifs with h h,
{ simp [and_comm, eq_tsub_iff_add_eq_of_le h, add_comm] {contextual := tt} },
{ rw not_le at h,
simp only [not_mem_empty, iff_false, not_and],
exact λ hn, ne_of_lt (lt_of_le_of_lt (le_self_add.trans hn.le) h) }
end
lemma filter_snd_eq_antidiagonal (n m : ℕ) :
filter (λ x : ℕ × ℕ, x.snd = m) (antidiagonal n) = if m ≤ n then {(n - m, m)} else ∅ :=
begin
have : (λ (x : ℕ × ℕ), x.snd = m) ∘ prod.swap = (λ (x : ℕ × ℕ), x.fst = m),
{ ext, simp },
rw ←map_swap_antidiagonal,
simp [map_filter, this, filter_fst_eq_antidiagonal, apply_ite (finset.map _)]
end
section equiv_prod
/-- The disjoint union of antidiagonals `Σ (n : ℕ), antidiagonal n` is equivalent to the product
`ℕ × ℕ`. This is such an equivalence, obtained by mapping `(n, (k, l))` to `(k, l)`. -/
@[simps] def sigma_antidiagonal_equiv_prod : (Σ (n : ℕ), antidiagonal n) ≃ ℕ × ℕ :=
{ to_fun := λ x, x.2,
inv_fun := λ x, ⟨x.1 + x.2, x, mem_antidiagonal.mpr rfl⟩,
left_inv :=
begin
rintros ⟨n, ⟨k, l⟩, h⟩,
rw mem_antidiagonal at h,
exact sigma.subtype_ext h rfl,
end,
right_inv := λ x, rfl }
end equiv_prod
end nat
end finset
|
d5ff43e2e6c7479ba91bec3cf3979d4f5a7757b6 | 1437b3495ef9020d5413178aa33c0a625f15f15f | /category_theory/types.lean | 2341ace1984c3462e065865afa9ec7b9625ec8d9 | [
"Apache-2.0"
] | permissive | jean002/mathlib | c66bbb2d9fdc9c03ae07f869acac7ddbfce67a30 | dc6c38a765799c99c4d9c8d5207d9e6c9e0e2cfd | refs/heads/master | 1,587,027,806,375 | 1,547,306,358,000 | 1,547,306,358,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 2,655 | lean | -- Copyright (c) 2017 Scott Morrison. All rights reserved.
-- Released under Apache 2.0 license as described in the file LICENSE.
-- Authors: Stephen Morgan, Scott Morrison, Johannes Hölzl
import category_theory.functor_category
import category_theory.fully_faithful
namespace category_theory
universes v v' w u u' -- declare the `v`'s first; see `category_theory.category` for an explanation
instance types : large_category (Type u) :=
{ hom := λ a b, (a → b),
id := λ a, id,
comp := λ _ _ _ f g, g ∘ f }
@[simp] lemma types_hom {α β : Type u} : (α ⟶ β) = (α → β) := rfl
@[simp] lemma types_id {α : Type u} (a : α) : (𝟙 α : α → α) a = a := rfl
@[simp] lemma types_comp {α β γ : Type u} (f : α → β) (g : β → γ) (a : α) : (((f : α ⟶ β) ≫ (g : β ⟶ γ)) : α ⟶ γ) a = g (f a) := rfl
namespace functor_to_types
variables {C : Type u} [𝒞 : category.{v} C] (F G H : C ⥤ (Type w)) {X Y Z : C}
include 𝒞
variables (σ : F ⟹ G) (τ : G ⟹ H)
@[simp] lemma map_comp (f : X ⟶ Y) (g : Y ⟶ Z) (a : F.obj X) : (F.map (f ≫ g)) a = (F.map g) ((F.map f) a) :=
by simp
@[simp] lemma map_id (a : F.obj X) : (F.map (𝟙 X)) a = a :=
by simp
lemma naturality (f : X ⟶ Y) (x : F.obj X) : σ.app Y ((F.map f) x) = (G.map f) (σ.app X x) :=
congr_fun (σ.naturality f) x
@[simp] lemma vcomp (x : F.obj X) : (σ ⊟ τ).app X x = τ.app X (σ.app X x) := rfl
variables {D : Type u'} [𝒟 : category.{u'} D] (I J : D ⥤ C) (ρ : I ⟹ J) {W : D}
@[simp] lemma hcomp (x : (I ⋙ F).obj W) : (ρ ◫ σ).app W x = (G.map (ρ.app W)) (σ.app (I.obj W) x) := rfl
end functor_to_types
def ulift_trivial (V : Type u) : ulift.{u} V ≅ V := by tidy
def ulift_functor : (Type u) ⥤ (Type (max u v)) :=
{ obj := λ X, ulift.{v} X,
map := λ X Y f, λ x : ulift.{v} X, ulift.up (f x.down) }
@[simp] lemma ulift_functor.map {X Y : Type u} (f : X ⟶ Y) (x : ulift.{v} X) :
ulift_functor.map f x = ulift.up (f x.down) := rfl
instance ulift_functor_faithful : fully_faithful ulift_functor :=
{ preimage := λ X Y f x, (f (ulift.up x)).down,
injectivity' := λ X Y f g p, funext $ λ x,
congr_arg ulift.down ((congr_fun p (ulift.up x)) : ((ulift.up (f x)) = (ulift.up (g x)))) }
section forget
variables {C : Type u → Type v} {hom : ∀α β, C α → C β → (α → β) → Prop} [i : concrete_category hom]
include i
/-- The forgetful functor from a bundled category to `Type`. -/
def forget : bundled C ⥤ Type u := { obj := bundled.α, map := λa b h, h.1 }
instance forget.faithful : faithful (forget : bundled C ⥤ Type u) := {}
end forget
end category_theory
|
5f93a7127d8974d4916bebbcce8e65f3f570a97d | 4d2583807a5ac6caaffd3d7a5f646d61ca85d532 | /src/data/list/func.lean | 9fb1c9d410ec2e56f060feaf1088169a6c1722c8 | [
"Apache-2.0"
] | permissive | AntoineChambert-Loir/mathlib | 64aabb896129885f12296a799818061bc90da1ff | 07be904260ab6e36a5769680b6012f03a4727134 | refs/heads/master | 1,693,187,631,771 | 1,636,719,886,000 | 1,636,719,886,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 11,366 | lean | /-
Copyright (c) 2019 Seul Baek. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Seul Baek
-/
import data.nat.basic
/-!
# Lists as Functions
Definitions for using lists as finite representations of finitely-supported functions with domain
ℕ.
These include pointwise operations on lists, as well as get and set operations.
## Notations
An index notation is introduced in this file for setting a particular element of a list. With `as`
as a list `m` as an index, and `a` as a new element, the notation is `as {m ↦ a}`.
So, for example
`[1, 3, 5] {1 ↦ 9}` would result in `[1, 9, 5]`
This notation is in the locale `list.func`.
-/
open list
universes u v w
variables {α : Type u} {β : Type v} {γ : Type w}
namespace list
namespace func
variables {a : α}
variables {as as1 as2 as3 : list α}
/-- Elementwise negation of a list -/
def neg [has_neg α] (as : list α) := as.map (λ a, -a)
variables [inhabited α] [inhabited β]
/--
Update element of a list by index. If the index is out of range, extend the list with default
elements
-/
@[simp] def set (a : α) : list α → ℕ → list α
| (_::as) 0 := a::as
| [] 0 := [a]
| (h::as) (k+1) := h::(set as k)
| [] (k+1) := (default α)::(set ([] : list α) k)
localized "notation as ` {` m ` ↦ ` a `}` := list.func.set a as m" in list.func
/-- Get element of a list by index. If the index is out of range, return the default element -/
@[simp] def get : ℕ → list α → α
| _ [] := default α
| 0 (a::as) := a
| (n+1) (a::as) := get n as
/--
Pointwise equality of lists. If lists are different lengths, compare with the default
element.
-/
def equiv (as1 as2 : list α) : Prop :=
∀ (m : nat), get m as1 = get m as2
/-- Pointwise operations on lists. If lists are different lengths, use the default element. -/
@[simp] def pointwise (f : α → β → γ) : list α → list β → list γ
| [] [] := []
| [] (b::bs) := map (f $ default α) (b::bs)
| (a::as) [] := map (λ x, f x $ default β) (a::as)
| (a::as) (b::bs) := (f a b)::(pointwise as bs)
/-- Pointwise addition on lists. If lists are different lengths, use zero. -/
def add {α : Type u} [has_zero α] [has_add α] : list α → list α → list α :=
@pointwise α α α ⟨0⟩ ⟨0⟩ (+)
/-- Pointwise subtraction on lists. If lists are different lengths, use zero. -/
def sub {α : Type u} [has_zero α] [has_sub α] : list α → list α → list α :=
@pointwise α α α ⟨0⟩ ⟨0⟩ (@has_sub.sub α _)
/- set -/
lemma length_set : ∀ {m : ℕ} {as : list α},
(as {m ↦ a}).length = max as.length (m+1)
| 0 [] := rfl
| 0 (a::as) := by {rw max_eq_left, refl, simp [nat.le_add_right]}
| (m+1) [] := by simp only [set, nat.zero_max, length, @length_set m]
| (m+1) (a::as) := by simp only [set, nat.max_succ_succ, length, @length_set m]
@[simp] lemma get_nil {k : ℕ} : get k [] = default α :=
by {cases k; refl}
lemma get_eq_default_of_le :
∀ (k : ℕ) {as : list α}, as.length ≤ k → get k as = default α
| 0 [] h1 := rfl
| 0 (a::as) h1 := by cases h1
| (k+1) [] h1 := rfl
| (k+1) (a::as) h1 :=
begin
apply get_eq_default_of_le k,
rw ← nat.succ_le_succ_iff, apply h1,
end
@[simp] lemma get_set {a : α} :
∀ {k : ℕ} {as : list α}, get k (as {k ↦ a}) = a
| 0 as := by {cases as; refl, }
| (k+1) as := by {cases as; simp [get_set]}
lemma eq_get_of_mem {a : α} :
∀ {as : list α}, a ∈ as → ∃ n : nat, ∀ d : α, a = (get n as)
| [] h := by cases h
| (b::as) h :=
begin
rw mem_cons_iff at h, cases h,
{ existsi 0, intro d, apply h },
{ cases eq_get_of_mem h with n h2,
existsi (n+1), apply h2 }
end
lemma mem_get_of_le :
∀ {n : ℕ} {as : list α}, n < as.length → get n as ∈ as
| _ [] h1 := by cases h1
| 0 (a::as) _ := or.inl rfl
| (n+1) (a::as) h1 :=
begin
apply or.inr, unfold get,
apply mem_get_of_le,
apply nat.lt_of_succ_lt_succ h1,
end
lemma mem_get_of_ne_zero :
∀ {n : ℕ} {as : list α},
get n as ≠ default α → get n as ∈ as
| _ [] h1 := begin exfalso, apply h1, rw get_nil end
| 0 (a::as) h1 := or.inl rfl
| (n+1) (a::as) h1 :=
begin
unfold get,
apply (or.inr (mem_get_of_ne_zero _)),
apply h1
end
lemma get_set_eq_of_ne {a : α} :
∀ {as : list α} (k : ℕ) (m : ℕ),
m ≠ k → get m (as {k ↦ a}) = get m as
| as 0 m h1 :=
by { cases m, contradiction, cases as;
simp only [set, get, get_nil] }
| as (k+1) m h1 :=
begin
cases as; cases m,
simp only [set, get],
{ have h3 : get m (nil {k ↦ a}) = default α,
{ rw [get_set_eq_of_ne k m, get_nil],
intro hc, apply h1, simp [hc] },
apply h3 },
simp only [set, get],
{ apply get_set_eq_of_ne k m,
intro hc, apply h1, simp [hc], }
end
lemma get_map {f : α → β} : ∀ {n : ℕ} {as : list α}, n < as.length →
get n (as.map f) = f (get n as)
| _ [] h := by cases h
| 0 (a::as) h := rfl
| (n+1) (a::as) h1 :=
begin
have h2 : n < length as,
{ rw [← nat.succ_le_iff, ← nat.lt_succ_iff],
apply h1 },
apply get_map h2,
end
lemma get_map' {f : α → β} {n : ℕ} {as : list α} :
f (default α) = (default β) →
get n (as.map f) = f (get n as) :=
begin
intro h1, by_cases h2 : n < as.length,
{ apply get_map h2, },
{ rw not_lt at h2,
rw [get_eq_default_of_le _ h2, get_eq_default_of_le, h1],
rw [length_map], apply h2 }
end
lemma forall_val_of_forall_mem {as : list α} {p : α → Prop} :
p (default α) → (∀ x ∈ as, p x) → (∀ n, p (get n as)) :=
begin
intros h1 h2 n,
by_cases h3 : n < as.length,
{ apply h2 _ (mem_get_of_le h3) },
{ rw not_lt at h3,
rw get_eq_default_of_le _ h3, apply h1 }
end
/- equiv -/
lemma equiv_refl : equiv as as := λ k, rfl
lemma equiv_symm : equiv as1 as2 → equiv as2 as1 :=
λ h1 k, (h1 k).symm
lemma equiv_trans :
equiv as1 as2 → equiv as2 as3 → equiv as1 as3 :=
λ h1 h2 k, eq.trans (h1 k) (h2 k)
lemma equiv_of_eq : as1 = as2 → equiv as1 as2 :=
begin intro h1, rw h1, apply equiv_refl end
lemma eq_of_equiv : ∀ {as1 as2 : list α}, as1.length = as2.length →
equiv as1 as2 → as1 = as2
| [] [] h1 h2 := rfl
| (_::_) [] h1 h2 := by cases h1
| [] (_::_) h1 h2 := by cases h1
| (a1::as1) (a2::as2) h1 h2 :=
begin
congr,
{ apply h2 0 },
have h3 : as1.length = as2.length,
{ simpa [add_left_inj, add_comm, length] using h1 },
apply eq_of_equiv h3,
intro m, apply h2 (m+1)
end
end func
-- We want to drop the `inhabited` instances for a moment,
-- so we close and open the namespace
namespace func
/- neg -/
@[simp] lemma get_neg [add_group α] {k : ℕ} {as : list α} :
@get α ⟨0⟩ k (neg as) = -(@get α ⟨0⟩ k as) :=
by {unfold neg, rw (@get_map' α α ⟨0⟩), apply neg_zero}
@[simp] lemma length_neg [has_neg α] (as : list α) : (neg as).length = as.length :=
by simp only [neg, length_map]
variables [inhabited α] [inhabited β]
/- pointwise -/
lemma nil_pointwise {f : α → β → γ} : ∀ bs : list β, pointwise f [] bs = bs.map (f $ default α)
| [] := rfl
| (b::bs) :=
by simp only [nil_pointwise bs, pointwise,
eq_self_iff_true, and_self, map]
lemma pointwise_nil {f : α → β → γ} :
∀ as : list α, pointwise f as [] = as.map (λ a, f a $ default β)
| [] := rfl
| (a::as) :=
by simp only [pointwise_nil as, pointwise,
eq_self_iff_true, and_self, list.map]
lemma get_pointwise [inhabited γ] {f : α → β → γ} (h1 : f (default α) (default β) = default γ) :
∀ (k : nat) (as : list α) (bs : list β),
get k (pointwise f as bs) = f (get k as) (get k bs)
| k [] [] := by simp only [h1, get_nil, pointwise, get]
| 0 [] (b::bs) :=
by simp only [get_pointwise, get_nil,
pointwise, get, nat.nat_zero_eq_zero, map]
| (k+1) [] (b::bs) :=
by { have : get k (map (f $ default α) bs) = f (default α) (get k bs),
{ simpa [nil_pointwise, get_nil] using (get_pointwise k [] bs) },
simpa [get, get_nil, pointwise, map] }
| 0 (a::as) [] :=
by simp only [get_pointwise, get_nil,
pointwise, get, nat.nat_zero_eq_zero, map]
| (k+1) (a::as) [] :=
by simpa [get, get_nil, pointwise, map, pointwise_nil, get_nil]
using get_pointwise k as []
| 0 (a::as) (b::bs) := by simp only [pointwise, get]
| (k+1) (a::as) (b::bs) :=
by simp only [pointwise, get, get_pointwise k]
lemma length_pointwise {f : α → β → γ} :
∀ {as : list α} {bs : list β},
(pointwise f as bs).length = max as.length bs.length
| [] [] := rfl
| [] (b::bs) :=
by simp only [pointwise, length, length_map,
max_eq_right (nat.zero_le (length bs + 1))]
| (a::as) [] :=
by simp only [pointwise, length, length_map,
max_eq_left (nat.zero_le (length as + 1))]
| (a::as) (b::bs) :=
by simp only [pointwise, length,
nat.max_succ_succ, @length_pointwise as bs]
end func
namespace func
/- add -/
@[simp] lemma get_add {α : Type u} [add_monoid α] {k : ℕ} {xs ys : list α} :
@get α ⟨0⟩ k (add xs ys) = ( @get α ⟨0⟩ k xs + @get α ⟨0⟩ k ys) :=
by {apply get_pointwise, apply zero_add}
@[simp] lemma length_add {α : Type u}
[has_zero α] [has_add α] {xs ys : list α} :
(add xs ys).length = max xs.length ys.length :=
@length_pointwise α α α ⟨0⟩ ⟨0⟩ _ _ _
@[simp] lemma nil_add {α : Type u} [add_monoid α]
(as : list α) : add [] as = as :=
begin
rw [add, @nil_pointwise α α α ⟨0⟩ ⟨0⟩],
apply eq.trans _ (map_id as),
congr' with x,
have : @default α ⟨0⟩ = 0 := rfl,
rw [this, zero_add], refl
end
@[simp] lemma add_nil {α : Type u} [add_monoid α]
(as : list α) : add as [] = as :=
begin
rw [add, @pointwise_nil α α α ⟨0⟩ ⟨0⟩],
apply eq.trans _ (map_id as),
congr' with x,
have : @default α ⟨0⟩ = 0 := rfl,
rw [this, add_zero], refl
end
lemma map_add_map {α : Type u} [add_monoid α] (f g : α → α) {as : list α} :
add (as.map f) (as.map g) = as.map (λ x, f x + g x) :=
begin
apply @eq_of_equiv _ (⟨0⟩ : inhabited α),
{ rw [length_map, length_add, max_eq_left, length_map],
apply le_of_eq,
rw [length_map, length_map] },
intros m,
rw [get_add],
by_cases h : m < length as,
{ repeat {rw [@get_map α α ⟨0⟩ ⟨0⟩ _ _ _ h]} },
rw not_lt at h,
repeat {rw [get_eq_default_of_le m]};
try {rw length_map, apply h},
apply zero_add
end
/- sub -/
@[simp] lemma get_sub {α : Type u}
[add_group α] {k : ℕ} {xs ys : list α} :
@get α ⟨0⟩ k (sub xs ys) = (@get α ⟨0⟩ k xs - @get α ⟨0⟩ k ys) :=
by {apply get_pointwise, apply sub_zero}
@[simp] lemma length_sub [has_zero α] [has_sub α] {xs ys : list α} :
(sub xs ys).length = max xs.length ys.length :=
@length_pointwise α α α ⟨0⟩ ⟨0⟩ _ _ _
@[simp] lemma nil_sub {α : Type} [add_group α]
(as : list α) : sub [] as = neg as :=
begin
rw [sub, nil_pointwise],
congr' with x,
have : @default α ⟨0⟩ = 0 := rfl,
rw [this, zero_sub]
end
@[simp] lemma sub_nil {α : Type} [add_group α]
(as : list α) : sub as [] = as :=
begin
rw [sub, pointwise_nil],
apply eq.trans _ (map_id as),
congr' with x,
have : @default α ⟨0⟩ = 0 := rfl,
rw [this, sub_zero], refl
end
end func
end list
|
47de91a07d3bd55a79f89576cf2bb3b5e90adec5 | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/data/nat/interval.lean | a7efc2bf8d37068c98666ab097bacda61deabb69 | [
"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 | 12,319 | lean | /-
Copyright (c) 2021 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import data.finset.locally_finite
/-!
# Finite intervals of naturals
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
This file proves that `ℕ` is a `locally_finite_order` and calculates the cardinality of its
intervals as finsets and fintypes.
## TODO
Some lemmas can be generalized using `ordered_group`, `canonically_ordered_monoid` or `succ_order`
and subsequently be moved upstream to `data.finset.locally_finite`.
-/
open finset nat
instance : locally_finite_order ℕ :=
{ finset_Icc := λ a b, ⟨list.range' a (b + 1 - a), list.nodup_range' _ _⟩,
finset_Ico := λ a b, ⟨list.range' a (b - a), list.nodup_range' _ _⟩,
finset_Ioc := λ a b, ⟨list.range' (a + 1) (b - a), list.nodup_range' _ _⟩,
finset_Ioo := λ a b, ⟨list.range' (a + 1) (b - a - 1), list.nodup_range' _ _⟩,
finset_mem_Icc := λ a b x, begin
rw [finset.mem_mk, multiset.mem_coe, list.mem_range'],
cases le_or_lt a b,
{ rw [add_tsub_cancel_of_le (nat.lt_succ_of_le h).le, nat.lt_succ_iff] },
{ rw [tsub_eq_zero_iff_le.2 (succ_le_of_lt h), add_zero],
exact iff_of_false (λ hx, hx.2.not_le hx.1) (λ hx, h.not_le (hx.1.trans hx.2)) }
end,
finset_mem_Ico := λ a b x, begin
rw [finset.mem_mk, multiset.mem_coe, list.mem_range'],
cases le_or_lt a b,
{ rw [add_tsub_cancel_of_le h] },
{ rw [tsub_eq_zero_iff_le.2 h.le, add_zero],
exact iff_of_false (λ hx, hx.2.not_le hx.1) (λ hx, h.not_le (hx.1.trans hx.2.le)) }
end,
finset_mem_Ioc := λ a b x, begin
rw [finset.mem_mk, multiset.mem_coe, list.mem_range'],
cases le_or_lt a b,
{ rw [←succ_sub_succ, add_tsub_cancel_of_le (succ_le_succ h), nat.lt_succ_iff,
nat.succ_le_iff] },
{ rw [tsub_eq_zero_iff_le.2 h.le, add_zero],
exact iff_of_false (λ hx, hx.2.not_le hx.1) (λ hx, h.not_le (hx.1.le.trans hx.2)) }
end,
finset_mem_Ioo := λ a b x, begin
rw [finset.mem_mk, multiset.mem_coe, list.mem_range', ← tsub_add_eq_tsub_tsub],
cases le_or_lt (a + 1) b,
{ rw [add_tsub_cancel_of_le h, nat.succ_le_iff] },
{ rw [tsub_eq_zero_iff_le.2 h.le, add_zero],
exact iff_of_false (λ hx, hx.2.not_le hx.1) (λ hx, h.not_le (hx.1.trans hx.2)) }
end }
variables (a b c : ℕ)
namespace nat
lemma Icc_eq_range' : Icc a b = ⟨list.range' a (b + 1 - a), list.nodup_range' _ _⟩ := rfl
lemma Ico_eq_range' : Ico a b = ⟨list.range' a (b - a), list.nodup_range' _ _⟩ := rfl
lemma Ioc_eq_range' : Ioc a b = ⟨list.range' (a + 1) (b - a), list.nodup_range' _ _⟩ := rfl
lemma Ioo_eq_range' : Ioo a b = ⟨list.range' (a + 1) (b - a - 1), list.nodup_range' _ _⟩ := rfl
lemma uIcc_eq_range' :
uIcc a b = ⟨list.range' (min a b) (max a b + 1 - min a b), list.nodup_range' _ _⟩ := rfl
lemma Iio_eq_range : Iio = range := by { ext b x, rw [mem_Iio, mem_range] }
@[simp] lemma Ico_zero_eq_range : Ico 0 = range := by rw [←bot_eq_zero, ←Iio_eq_Ico, Iio_eq_range]
lemma _root_.finset.range_eq_Ico : range = Ico 0 := Ico_zero_eq_range.symm
@[simp] lemma card_Icc : (Icc a b).card = b + 1 - a := list.length_range' _ _
@[simp] lemma card_Ico : (Ico a b).card = b - a := list.length_range' _ _
@[simp] lemma card_Ioc : (Ioc a b).card = b - a := list.length_range' _ _
@[simp] lemma card_Ioo : (Ioo a b).card = b - a - 1 := list.length_range' _ _
@[simp] lemma card_uIcc : (uIcc a b).card = (b - a : ℤ).nat_abs + 1 :=
begin
refine (card_Icc _ _).trans (int.coe_nat_inj _),
rw [sup_eq_max, inf_eq_min, int.coe_nat_sub],
{ rw [add_comm, int.coe_nat_add, add_sub_assoc],
norm_cast,
push_cast,
rw [max_sub_min_eq_abs, add_comm] },
{ exact min_le_max.trans le_self_add }
end
@[simp] lemma card_Iic : (Iic b).card = b + 1 :=
by rw [Iic_eq_Icc, card_Icc, bot_eq_zero, tsub_zero]
@[simp] lemma card_Iio : (Iio b).card = b := by rw [Iio_eq_Ico, card_Ico, bot_eq_zero, tsub_zero]
@[simp] lemma card_fintype_Icc : fintype.card (set.Icc a b) = b + 1 - a :=
by rw [fintype.card_of_finset, card_Icc]
@[simp] lemma card_fintype_Ico : fintype.card (set.Ico a b) = b - a :=
by rw [fintype.card_of_finset, card_Ico]
@[simp] lemma card_fintype_Ioc : fintype.card (set.Ioc a b) = b - a :=
by rw [fintype.card_of_finset, card_Ioc]
@[simp] lemma card_fintype_Ioo : fintype.card (set.Ioo a b) = b - a - 1 :=
by rw [fintype.card_of_finset, card_Ioo]
@[simp] lemma card_fintype_Iic : fintype.card (set.Iic b) = b + 1 :=
by rw [fintype.card_of_finset, card_Iic]
@[simp] lemma card_fintype_Iio : fintype.card (set.Iio b) = b :=
by rw [fintype.card_of_finset, card_Iio]
-- TODO@Yaël: Generalize all the following lemmas to `succ_order`
lemma Icc_succ_left : Icc a.succ b = Ioc a b := by { ext x, rw [mem_Icc, mem_Ioc, succ_le_iff] }
lemma Ico_succ_right : Ico a b.succ = Icc a b := by { ext x, rw [mem_Ico, mem_Icc, lt_succ_iff] }
lemma Ico_succ_left : Ico a.succ b = Ioo a b := by { ext x, rw [mem_Ico, mem_Ioo, succ_le_iff] }
lemma Icc_pred_right {b : ℕ} (h : 0 < b) : Icc a (b - 1) = Ico a b :=
by { ext x, rw [mem_Icc, mem_Ico, lt_iff_le_pred h] }
lemma Ico_succ_succ : Ico a.succ b.succ = Ioc a b :=
by { ext x, rw [mem_Ico, mem_Ioc, succ_le_iff, lt_succ_iff] }
@[simp] lemma Ico_succ_singleton : Ico a (a + 1) = {a} := by rw [Ico_succ_right, Icc_self]
@[simp] lemma Ico_pred_singleton {a : ℕ} (h : 0 < a) : Ico (a - 1) a = {a - 1} :=
by rw [←Icc_pred_right _ h, Icc_self]
@[simp] lemma Ioc_succ_singleton : Ioc b (b + 1) = {b+1} :=
by rw [← nat.Icc_succ_left, Icc_self]
variables {a b c}
lemma Ico_succ_right_eq_insert_Ico (h : a ≤ b) : Ico a (b + 1) = insert b (Ico a b) :=
by rw [Ico_succ_right, ←Ico_insert_right h]
lemma Ico_insert_succ_left (h : a < b) : insert a (Ico a.succ b) = Ico a b :=
by rw [Ico_succ_left, ←Ioo_insert_left h]
lemma image_sub_const_Ico (h : c ≤ a) : (Ico a b).image (λ x, x - c) = Ico (a - c) (b - c) :=
begin
ext x,
rw mem_image,
split,
{ rintro ⟨x, hx, rfl⟩,
rw [mem_Ico] at ⊢ hx,
exact ⟨tsub_le_tsub_right hx.1 _, tsub_lt_tsub_right_of_le (h.trans hx.1) hx.2⟩ },
{ rintro h,
refine ⟨x + c, _, add_tsub_cancel_right _ _⟩,
rw mem_Ico at ⊢ h,
exact ⟨tsub_le_iff_right.1 h.1, lt_tsub_iff_right.1 h.2⟩ }
end
lemma Ico_image_const_sub_eq_Ico (hac : a ≤ c) :
(Ico a b).image (λ x, c - x) = Ico (c + 1 - b) (c + 1 - a) :=
begin
ext x,
rw [mem_image, mem_Ico],
split,
{ rintro ⟨x, hx, rfl⟩,
rw mem_Ico at hx,
refine ⟨_, ((tsub_le_tsub_iff_left hac).2 hx.1).trans_lt ((tsub_lt_tsub_iff_right hac).2
(nat.lt_succ_self _))⟩,
cases lt_or_le c b,
{ rw tsub_eq_zero_iff_le.mpr (succ_le_of_lt h),
exact zero_le _ },
{ rw ←succ_sub_succ c,
exact (tsub_le_tsub_iff_left (succ_le_succ $ hx.2.le.trans h)).2 hx.2 } },
{ rintro ⟨hb, ha⟩,
rw [lt_tsub_iff_left, lt_succ_iff] at ha,
have hx : x ≤ c := (nat.le_add_left _ _).trans ha,
refine ⟨c - x, _, tsub_tsub_cancel_of_le hx⟩,
{ rw mem_Ico,
exact ⟨le_tsub_of_add_le_right ha, (tsub_lt_iff_left hx).2 $ succ_le_iff.1 $
tsub_le_iff_right.1 hb⟩ } }
end
lemma Ico_succ_left_eq_erase_Ico : Ico a.succ b = erase (Ico a b) a :=
begin
ext x,
rw [Ico_succ_left, mem_erase, mem_Ico, mem_Ioo, ←and_assoc, ne_comm, and_comm (a ≠ x),
lt_iff_le_and_ne],
end
lemma mod_inj_on_Ico (n a : ℕ) : set.inj_on (% a) (finset.Ico n (n+a)) :=
begin
induction n with n ih,
{ simp only [zero_add, nat_zero_eq_zero, Ico_zero_eq_range],
rintro k hk l hl (hkl : k % a = l % a),
simp only [finset.mem_range, finset.mem_coe] at hk hl,
rwa [mod_eq_of_lt hk, mod_eq_of_lt hl] at hkl, },
rw [Ico_succ_left_eq_erase_Ico, succ_add, Ico_succ_right_eq_insert_Ico le_self_add],
rintro k hk l hl (hkl : k % a = l % a),
have ha : 0 < a,
{ by_contra ha, simp only [not_lt, nonpos_iff_eq_zero] at ha, simpa [ha] using hk },
simp only [finset.mem_coe, finset.mem_insert, finset.mem_erase] at hk hl,
rcases hk with ⟨hkn, (rfl|hk)⟩; rcases hl with ⟨hln, (rfl|hl)⟩,
{ refl },
{ rw add_mod_right at hkl,
refine (hln $ ih hl _ hkl.symm).elim,
simp only [lt_add_iff_pos_right, set.left_mem_Ico, finset.coe_Ico, ha], },
{ rw add_mod_right at hkl,
suffices : k = n, { contradiction },
refine ih hk _ hkl,
simp only [lt_add_iff_pos_right, set.left_mem_Ico, finset.coe_Ico, ha], },
{ refine ih _ _ hkl; simp only [finset.mem_coe, hk, hl], },
end
/-- Note that while this lemma cannot be easily generalized to a type class, it holds for ℤ as
well. See `int.image_Ico_mod` for the ℤ version. -/
lemma image_Ico_mod (n a : ℕ) :
(Ico n (n+a)).image (% a) = range a :=
begin
obtain rfl | ha := eq_or_ne a 0,
{ rw [range_zero, add_zero, Ico_self, image_empty], },
ext i,
simp only [mem_image, exists_prop, mem_range, mem_Ico],
split,
{ rintro ⟨i, h, rfl⟩, exact mod_lt i ha.bot_lt },
intro hia,
have hn := nat.mod_add_div n a,
obtain hi | hi := lt_or_le i (n % a),
{ refine ⟨i + a * (n/a + 1), ⟨_, _⟩, _⟩,
{ rw [add_comm (n/a), mul_add, mul_one, ← add_assoc],
refine hn.symm.le.trans (add_le_add_right _ _),
simpa only [zero_add] using add_le_add (zero_le i) (nat.mod_lt n ha.bot_lt).le, },
{ refine lt_of_lt_of_le (add_lt_add_right hi (a * (n/a + 1))) _,
rw [mul_add, mul_one, ← add_assoc, hn], },
{ rw [nat.add_mul_mod_self_left, nat.mod_eq_of_lt hia], } },
{ refine ⟨i + a * (n/a), ⟨_, _⟩, _⟩,
{ exact hn.symm.le.trans (add_le_add_right hi _), },
{ rw [add_comm n a],
refine add_lt_add_of_lt_of_le hia (le_trans _ hn.le),
simp only [zero_le, le_add_iff_nonneg_left], },
{ rw [nat.add_mul_mod_self_left, nat.mod_eq_of_lt hia], } },
end
section multiset
open multiset
lemma multiset_Ico_map_mod (n a : ℕ) : (multiset.Ico n (n+a)).map (% a) = range a :=
begin
convert congr_arg finset.val (image_Ico_mod n a),
refine ((nodup_map_iff_inj_on (finset.Ico _ _).nodup).2 $ _).dedup.symm,
exact mod_inj_on_Ico _ _,
end
end multiset
end nat
namespace finset
lemma range_image_pred_top_sub (n : ℕ) : (finset.range n).image (λ j, n - 1 - j) = finset.range n :=
begin
cases n,
{ rw [range_zero, image_empty] },
{ rw [finset.range_eq_Ico, nat.Ico_image_const_sub_eq_Ico (zero_le _)],
simp_rw [succ_sub_succ, tsub_zero, tsub_self] }
end
lemma range_add_eq_union : range (a + b) = range a ∪ (range b).map (add_left_embedding a) :=
begin
rw [finset.range_eq_Ico, map_eq_image],
convert (Ico_union_Ico_eq_Ico a.zero_le le_self_add).symm,
exact image_add_left_Ico _ _ _,
end
end finset
section induction
variables {P : ℕ → Prop} (h : ∀ n, P (n + 1) → P n)
include h
lemma nat.decreasing_induction_of_not_bdd_above (hP : ¬ bdd_above {x | P x}) (n : ℕ) : P n :=
let ⟨m, hm, hl⟩ := not_bdd_above_iff.1 hP n in decreasing_induction h hl.le hm
lemma nat.decreasing_induction_of_infinite (hP : {x | P x}.infinite) (n : ℕ) : P n :=
nat.decreasing_induction_of_not_bdd_above h (mt bdd_above.finite hP) n
lemma nat.cauchy_induction' (seed : ℕ) (hs : P seed)
(hi : ∀ x, seed ≤ x → P x → ∃ y, x < y ∧ P y) (n : ℕ) : P n :=
begin
apply nat.decreasing_induction_of_infinite h (λ hf, _),
obtain ⟨m, hP, hm⟩ := hf.exists_maximal_wrt id _ ⟨seed, hs⟩,
obtain ⟨y, hl, hy⟩ := hi m (le_of_not_lt $ λ hl, hl.ne $ hm seed hs hl.le) hP,
exact hl.ne (hm y hy hl.le),
end
lemma nat.cauchy_induction (seed : ℕ) (hs : P seed) (f : ℕ → ℕ)
(hf : ∀ x, seed ≤ x → P x → x < f x ∧ P (f x)) (n : ℕ) : P n :=
seed.cauchy_induction' h hs (λ x hl hx, ⟨f x, hf x hl hx⟩) n
lemma nat.cauchy_induction_mul (k seed : ℕ) (hk : 1 < k) (hs : P seed.succ)
(hm : ∀ x, seed < x → P x → P (k * x)) (n : ℕ) : P n :=
begin
apply nat.cauchy_induction h _ hs ((*) k) (λ x hl hP, ⟨_, hm x hl hP⟩),
convert (mul_lt_mul_right $ seed.succ_pos.trans_le hl).2 hk,
rw one_mul,
end
lemma nat.cauchy_induction_two_mul (seed : ℕ) (hs : P seed.succ)
(hm : ∀ x, seed < x → P x → P (2 * x)) (n : ℕ) : P n :=
nat.cauchy_induction_mul h 2 seed one_lt_two hs hm n
end induction
|
a3b65e1b31a11f2dd5958909c8ee448d142b3109 | 618003631150032a5676f229d13a079ac875ff77 | /src/data/seq/wseq.lean | 4fecabc0f0290711a6ce9a29d24215cb2946b718 | [
"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 | 55,018 | lean | /-
Copyright (c) 2017 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Mario Carneiro
-/
import data.seq.seq
import data.dlist
universes u v w
/-
coinductive wseq (α : Type u) : Type u
| nil : wseq α
| cons : α → wseq α → wseq α
| think : wseq α → wseq α
-/
/-- Weak sequences.
While the `seq` structure allows for lists which may not be finite,
a weak sequence also allows the computation of each element to
involve an indeterminate amount of computation, including possibly
an infinite loop. This is represented as a regular `seq` interspersed
with `none` elements to indicate that computation is ongoing.
This model is appropriate for Haskell style lazy lists, and is closed
under most interesting computation patterns on infinite lists,
but conversely it is difficult to extract elements from it. -/
def wseq (α) := seq (option α)
namespace wseq
variables {α : Type u} {β : Type v} {γ : Type w}
/-- Turn a sequence into a weak sequence -/
def of_seq : seq α → wseq α := (<$>) some
/-- Turn a list into a weak sequence -/
def of_list (l : list α) : wseq α := of_seq l
/-- Turn a stream into a weak sequence -/
def of_stream (l : stream α) : wseq α := of_seq l
instance coe_seq : has_coe (seq α) (wseq α) := ⟨of_seq⟩
instance coe_list : has_coe (list α) (wseq α) := ⟨of_list⟩
instance coe_stream : has_coe (stream α) (wseq α) := ⟨of_stream⟩
/-- The empty weak sequence -/
def nil : wseq α := seq.nil
instance : inhabited (wseq α) := ⟨nil⟩
/-- Prepend an element to a weak sequence -/
def cons (a : α) : wseq α → wseq α := seq.cons (some a)
/-- Compute for one tick, without producing any elements -/
def think : wseq α → wseq α := seq.cons none
/-- Destruct a weak sequence, to (eventually possibly) produce either
`none` for `nil` or `some (a, s)` if an element is produced. -/
def destruct : wseq α → computation (option (α × wseq α)) :=
computation.corec (λs, match seq.destruct s with
| none := sum.inl none
| some (none, s') := sum.inr s'
| some (some a, s') := sum.inl (some (a, s'))
end)
def cases_on {C : wseq α → Sort v} (s : wseq α) (h1 : C nil)
(h2 : ∀ x s, C (cons x s)) (h3 : ∀ s, C (think s)) : C s :=
seq.cases_on s h1 (λ o, option.cases_on o h3 h2)
protected def mem (a : α) (s : wseq α) := seq.mem (some a) s
instance : has_mem α (wseq α) :=
⟨wseq.mem⟩
theorem not_mem_nil (a : α) : a ∉ @nil α := seq.not_mem_nil a
/-- Get the head of a weak sequence. This involves a possibly
infinite computation. -/
def head (s : wseq α) : computation (option α) :=
computation.map ((<$>) prod.fst) (destruct s)
/-- Encode a computation yielding a weak sequence into additional
`think` constructors in a weak sequence -/
def flatten : computation (wseq α) → wseq α :=
seq.corec (λc, match computation.destruct c with
| sum.inl s := seq.omap return (seq.destruct s)
| sum.inr c' := some (none, c')
end)
/-- Get the tail of a weak sequence. This doesn't need a `computation`
wrapper, unlike `head`, because `flatten` allows us to hide this
in the construction of the weak sequence itself. -/
def tail (s : wseq α) : wseq α :=
flatten $ (λo, option.rec_on o nil prod.snd) <$> destruct s
/-- drop the first `n` elements from `s`. -/
def drop (s : wseq α) : ℕ → wseq α
| 0 := s
| (n+1) := tail (drop n)
attribute [simp] drop
/-- Get the nth element of `s`. -/
def nth (s : wseq α) (n : ℕ) : computation (option α) := head (drop s n)
/-- Convert `s` to a list (if it is finite and completes in finite time). -/
def to_list (s : wseq α) : computation (list α) :=
@computation.corec (list α) (list α × wseq α) (λ⟨l, s⟩,
match seq.destruct s with
| none := sum.inl l.reverse
| some (none, s') := sum.inr (l, s')
| some (some a, s') := sum.inr (a::l, s')
end) ([], s)
/-- Get the length of `s` (if it is finite and completes in finite time). -/
def length (s : wseq α) : computation ℕ :=
@computation.corec ℕ (ℕ × wseq α) (λ⟨n, s⟩,
match seq.destruct s with
| none := sum.inl n
| some (none, s') := sum.inr (n, s')
| some (some a, s') := sum.inr (n+1, s')
end) (0, s)
/-- A weak sequence is finite if `to_list s` terminates. Equivalently,
it is a finite number of `think` and `cons` applied to `nil`. -/
@[class] def is_finite (s : wseq α) : Prop := (to_list s).terminates
instance to_list_terminates (s : wseq α) [h : is_finite s] : (to_list s).terminates := h
/-- Get the list corresponding to a finite weak sequence. -/
def get (s : wseq α) [is_finite s] : list α := (to_list s).get
/-- A weak sequence is *productive* if it never stalls forever - there are
always a finite number of `think`s between `cons` constructors.
The sequence itself is allowed to be infinite though. -/
@[class] def productive (s : wseq α) : Prop := ∀ n, (nth s n).terminates
instance nth_terminates (s : wseq α) [h : productive s] : ∀ n, (nth s n).terminates := h
instance head_terminates (s : wseq α) [h : productive s] : (head s).terminates := h 0
/-- Replace the `n`th element of `s` with `a`. -/
def update_nth (s : wseq α) (n : ℕ) (a : α) : wseq α :=
@seq.corec (option α) (ℕ × wseq α) (λ⟨n, s⟩,
match seq.destruct s, n with
| none, n := none
| some (none, s'), n := some (none, n, s')
| some (some a', s'), 0 := some (some a', 0, s')
| some (some a', s'), 1 := some (some a, 0, s')
| some (some a', s'), (n+2) := some (some a', n+1, s')
end) (n+1, s)
/-- Remove the `n`th element of `s`. -/
def remove_nth (s : wseq α) (n : ℕ) : wseq α :=
@seq.corec (option α) (ℕ × wseq α) (λ⟨n, s⟩,
match seq.destruct s, n with
| none, n := none
| some (none, s'), n := some (none, n, s')
| some (some a', s'), 0 := some (some a', 0, s')
| some (some a', s'), 1 := some (none, 0, s')
| some (some a', s'), (n+2) := some (some a', n+1, s')
end) (n+1, s)
/-- Map the elements of `s` over `f`, removing any values that yield `none`. -/
def filter_map (f : α → option β) : wseq α → wseq β :=
seq.corec (λs, match seq.destruct s with
| none := none
| some (none, s') := some (none, s')
| some (some a, s') := some (f a, s')
end)
/-- Select the elements of `s` that satisfy `p`. -/
def filter (p : α → Prop) [decidable_pred p] : wseq α → wseq α :=
filter_map (λa, if p a then some a else none)
-- example of infinite list manipulations
/-- Get the first element of `s` satisfying `p`. -/
def find (p : α → Prop) [decidable_pred p] (s : wseq α) : computation (option α) :=
head $ filter p s
/-- Zip a function over two weak sequences -/
def zip_with (f : α → β → γ) (s1 : wseq α) (s2 : wseq β) : wseq γ :=
@seq.corec (option γ) (wseq α × wseq β) (λ⟨s1, s2⟩,
match seq.destruct s1, seq.destruct s2 with
| some (none, s1'), some (none, s2') := some (none, s1', s2')
| some (some a1, s1'), some (none, s2') := some (none, s1, s2')
| some (none, s1'), some (some a2, s2') := some (none, s1', s2)
| some (some a1, s1'), some (some a2, s2') := some (some (f a1 a2), s1', s2')
| _, _ := none
end) (s1, s2)
/-- Zip two weak sequences into a single sequence of pairs -/
def zip : wseq α → wseq β → wseq (α × β) := zip_with prod.mk
/-- Get the list of indexes of elements of `s` satisfying `p` -/
def find_indexes (p : α → Prop) [decidable_pred p] (s : wseq α) : wseq ℕ :=
(zip s (stream.nats : wseq ℕ)).filter_map
(λ ⟨a, n⟩, if p a then some n else none)
/-- Get the index of the first element of `s` satisfying `p` -/
def find_index (p : α → Prop) [decidable_pred p] (s : wseq α) : computation ℕ :=
(λ o, option.get_or_else o 0) <$> head (find_indexes p s)
/-- Get the index of the first occurrence of `a` in `s` -/
def index_of [decidable_eq α] (a : α) : wseq α → computation ℕ := find_index (eq a)
/-- Get the indexes of occurrences of `a` in `s` -/
def indexes_of [decidable_eq α] (a : α) : wseq α → wseq ℕ := find_indexes (eq a)
/-- `union s1 s2` is a weak sequence which interleaves `s1` and `s2` in
some order (nondeterministically). -/
def union (s1 s2 : wseq α) : wseq α :=
@seq.corec (option α) (wseq α × wseq α) (λ⟨s1, s2⟩,
match seq.destruct s1, seq.destruct s2 with
| none, none := none
| some (a1, s1'), none := some (a1, s1', nil)
| none, some (a2, s2') := some (a2, nil, s2')
| some (none, s1'), some (none, s2') := some (none, s1', s2')
| some (some a1, s1'), some (none, s2') := some (some a1, s1', s2')
| some (none, s1'), some (some a2, s2') := some (some a2, s1', s2')
| some (some a1, s1'), some (some a2, s2') := some (some a1, cons a2 s1', s2')
end) (s1, s2)
/-- Returns `tt` if `s` is `nil` and `ff` if `s` has an element -/
def is_empty (s : wseq α) : computation bool :=
computation.map option.is_none $ head s
/-- Calculate one step of computation -/
def compute (s : wseq α) : wseq α :=
match seq.destruct s with
| some (none, s') := s'
| _ := s
end
/-- Get the first `n` elements of a weak sequence -/
def take (s : wseq α) (n : ℕ) : wseq α :=
@seq.corec (option α) (ℕ × wseq α) (λ⟨n, s⟩,
match n, seq.destruct s with
| 0, _ := none
| m+1, none := none
| m+1, some (none, s') := some (none, m+1, s')
| m+1, some (some a, s') := some (some a, m, s')
end) (n, s)
/-- Split the sequence at position `n` into a finite initial segment
and the weak sequence tail -/
def split_at (s : wseq α) (n : ℕ) : computation (list α × wseq α) :=
@computation.corec (list α × wseq α) (ℕ × list α × wseq α) (λ⟨n, l, s⟩,
match n, seq.destruct s with
| 0, _ := sum.inl (l.reverse, s)
| m+1, none := sum.inl (l.reverse, s)
| m+1, some (none, s') := sum.inr (n, l, s')
| m+1, some (some a, s') := sum.inr (m, a::l, s')
end) (n, [], s)
/-- Returns `tt` if any element of `s` satisfies `p` -/
def any (s : wseq α) (p : α → bool) : computation bool :=
computation.corec (λs : wseq α,
match seq.destruct s with
| none := sum.inl ff
| some (none, s') := sum.inr s'
| some (some a, s') := if p a then sum.inl tt else sum.inr s'
end) s
/-- Returns `tt` if every element of `s` satisfies `p` -/
def all (s : wseq α) (p : α → bool) : computation bool :=
computation.corec (λs : wseq α,
match seq.destruct s with
| none := sum.inl tt
| some (none, s') := sum.inr s'
| some (some a, s') := if p a then sum.inr s' else sum.inl ff
end) s
/-- Apply a function to the elements of the sequence to produce a sequence
of partial results. (There is no `scanr` because this would require
working from the end of the sequence, which may not exist.) -/
def scanl (f : α → β → α) (a : α) (s : wseq β) : wseq α :=
cons a $ @seq.corec (option α) (α × wseq β) (λ⟨a, s⟩,
match seq.destruct s with
| none := none
| some (none, s') := some (none, a, s')
| some (some b, s') := let a' := f a b in some (some a', a', s')
end) (a, s)
/-- Get the weak sequence of initial segments of the input sequence -/
def inits (s : wseq α) : wseq (list α) :=
cons [] $ @seq.corec (option (list α)) (dlist α × wseq α) (λ ⟨l, s⟩,
match seq.destruct s with
| none := none
| some (none, s') := some (none, l, s')
| some (some a, s') := let l' := l.concat a in
some (some l'.to_list, l', s')
end) (dlist.empty, s)
/-- Like take, but does not wait for a result. Calculates `n` steps of
computation and returns the sequence computed so far -/
def collect (s : wseq α) (n : ℕ) : list α :=
(seq.take n s).filter_map id
/-- Append two weak sequences. As with `seq.append`, this may not use
the second sequence if the first one takes forever to compute -/
def append : wseq α → wseq α → wseq α := seq.append
/-- Map a function over a weak sequence -/
def map (f : α → β) : wseq α → wseq β := seq.map (option.map f)
/-- Flatten a sequence of weak sequences. (Note that this allows
empty sequences, unlike `seq.join`.) -/
def join (S : wseq (wseq α)) : wseq α :=
seq.join ((λo : option (wseq α), match o with
| none := seq1.ret none
| some s := (none, s)
end) <$> S)
/-- Monadic bind operator for weak sequences -/
def bind (s : wseq α) (f : α → wseq β) : wseq β :=
join (map f s)
@[simp] def lift_rel_o (R : α → β → Prop) (C : wseq α → wseq β → Prop) :
option (α × wseq α) → option (β × wseq β) → Prop
| none none := true
| (some (a, s)) (some (b, t)) := R a b ∧ C s t
| _ _ := false
theorem lift_rel_o.imp {R S : α → β → Prop} {C D : wseq α → wseq β → Prop}
(H1 : ∀ a b, R a b → S a b) (H2 : ∀ s t, C s t → D s t) :
∀ {o p}, lift_rel_o R C o p → lift_rel_o S D o p
| none none h := trivial
| (some (a, s)) (some (b, t)) h := and.imp (H1 _ _) (H2 _ _) h
| none (some _) h := false.elim h
| (some (_, _)) none h := false.elim h
theorem lift_rel_o.imp_right (R : α → β → Prop) {C D : wseq α → wseq β → Prop}
(H : ∀ s t, C s t → D s t) {o p} : lift_rel_o R C o p → lift_rel_o R D o p :=
lift_rel_o.imp (λ _ _, id) H
@[simp] def bisim_o (R : wseq α → wseq α → Prop) :
option (α × wseq α) → option (α × wseq α) → Prop := lift_rel_o (=) R
theorem bisim_o.imp {R S : wseq α → wseq α → Prop} (H : ∀ s t, R s t → S s t) {o p} :
bisim_o R o p → bisim_o S o p :=
lift_rel_o.imp_right _ H
/-- Two weak sequences are `lift_rel R` related if they are either both empty,
or they are both nonempty and the heads are `R` related and the tails are
`lift_rel R` related. (This is a coinductive definition.) -/
def lift_rel (R : α → β → Prop) (s : wseq α) (t : wseq β) : Prop :=
∃ C : wseq α → wseq β → Prop, C s t ∧
∀ {s t}, C s t → computation.lift_rel (lift_rel_o R C) (destruct s) (destruct t)
/-- If two sequences are equivalent, then they have the same values and
the same computational behavior (i.e. if one loops forever then so does
the other), although they may differ in the number of `think`s needed to
arrive at the answer. -/
def equiv : wseq α → wseq α → Prop := lift_rel (=)
theorem lift_rel_destruct {R : α → β → Prop} {s : wseq α} {t : wseq β} :
lift_rel R s t →
computation.lift_rel (lift_rel_o R (lift_rel R)) (destruct s) (destruct t)
| ⟨R, h1, h2⟩ :=
by refine computation.lift_rel.imp _ _ _ (h2 h1);
apply lift_rel_o.imp_right; exact λ s' t' h', ⟨R, h', @h2⟩
theorem lift_rel_destruct_iff {R : α → β → Prop} {s : wseq α} {t : wseq β} :
lift_rel R s t ↔
computation.lift_rel (lift_rel_o R (lift_rel R)) (destruct s) (destruct t) :=
⟨lift_rel_destruct, λ h, ⟨λ s t, lift_rel R s t ∨
computation.lift_rel (lift_rel_o R (lift_rel R)) (destruct s) (destruct t),
or.inr h, λ s t h, begin
have h : computation.lift_rel (lift_rel_o R (lift_rel R)) (destruct s) (destruct t),
{ cases h with h h, exact lift_rel_destruct h, assumption },
apply computation.lift_rel.imp _ _ _ h,
intros a b, apply lift_rel_o.imp_right,
intros s t, apply or.inl
end⟩⟩
infix ~ := equiv
theorem destruct_congr {s t : wseq α} :
s ~ t → computation.lift_rel (bisim_o (~)) (destruct s) (destruct t) :=
lift_rel_destruct
theorem destruct_congr_iff {s t : wseq α} :
s ~ t ↔ computation.lift_rel (bisim_o (~)) (destruct s) (destruct t) :=
lift_rel_destruct_iff
theorem lift_rel.refl (R : α → α → Prop) (H : reflexive R) : reflexive (lift_rel R) :=
λ s, begin
refine ⟨(=), rfl, λ s t (h : s = t), _⟩,
rw ←h, apply computation.lift_rel.refl,
intro a, cases a with a, simp, cases a; simp, apply H
end
theorem lift_rel_o.swap (R : α → β → Prop) (C) :
function.swap (lift_rel_o R C) = lift_rel_o (function.swap R) (function.swap C) :=
by funext x y; cases x with x; [skip, cases x]; { cases y with y; [skip, cases y]; refl }
theorem lift_rel.swap_lem {R : α → β → Prop} {s1 s2} (h : lift_rel R s1 s2) :
lift_rel (function.swap R) s2 s1 :=
begin
refine ⟨function.swap (lift_rel R), h, λ s t (h : lift_rel R t s), _⟩,
rw [←lift_rel_o.swap, computation.lift_rel.swap],
apply lift_rel_destruct h
end
theorem lift_rel.swap (R : α → β → Prop) :
function.swap (lift_rel R) = lift_rel (function.swap R) :=
funext $ λ x, funext $ λ y, propext ⟨lift_rel.swap_lem, lift_rel.swap_lem⟩
theorem lift_rel.symm (R : α → α → Prop) (H : symmetric R) : symmetric (lift_rel R) :=
λ s1 s2 (h : function.swap (lift_rel R) s2 s1),
by rwa [lift_rel.swap, show function.swap R = R, from
funext $ λ a, funext $ λ b, propext $ by constructor; apply H] at h
theorem lift_rel.trans (R : α → α → Prop) (H : transitive R) : transitive (lift_rel R) :=
λ s t u h1 h2, begin
refine ⟨λ s u, ∃ t, lift_rel R s t ∧ lift_rel R t u, ⟨t, h1, h2⟩, λ s u h, _⟩,
rcases h with ⟨t, h1, h2⟩,
have h1 := lift_rel_destruct h1,
have h2 := lift_rel_destruct h2,
refine computation.lift_rel_def.2
⟨(computation.terminates_of_lift_rel h1).trans
(computation.terminates_of_lift_rel h2), λ a c ha hc, _⟩,
rcases h1.left ha with ⟨b, hb, t1⟩,
have t2 := computation.rel_of_lift_rel h2 hb hc,
cases a with a; cases c with c,
{ trivial },
{ cases b, {cases t2}, {cases t1} },
{ cases a, cases b with b, {cases t1}, {cases b, cases t2} },
{ cases a with a s, cases b with b, {cases t1},
cases b with b t, cases c with c u,
cases t1 with ab st, cases t2 with bc tu,
exact ⟨H ab bc, t, st, tu⟩ }
end
theorem lift_rel.equiv (R : α → α → Prop) : equivalence R → equivalence (lift_rel R)
| ⟨refl, symm, trans⟩ :=
⟨lift_rel.refl R refl, lift_rel.symm R symm, lift_rel.trans R trans⟩
@[refl] theorem equiv.refl : ∀ (s : wseq α), s ~ s :=
lift_rel.refl (=) eq.refl
@[symm] theorem equiv.symm : ∀ {s t : wseq α}, s ~ t → t ~ s :=
lift_rel.symm (=) (@eq.symm _)
@[trans] theorem equiv.trans : ∀ {s t u : wseq α}, s ~ t → t ~ u → s ~ u :=
lift_rel.trans (=) (@eq.trans _)
theorem equiv.equivalence : equivalence (@equiv α) :=
⟨@equiv.refl _, @equiv.symm _, @equiv.trans _⟩
open computation
local notation `return` := computation.return
@[simp] theorem destruct_nil : destruct (nil : wseq α) = return none :=
computation.destruct_eq_ret rfl
@[simp] theorem destruct_cons (a : α) (s) : destruct (cons a s) = return (some (a, s)) :=
computation.destruct_eq_ret $ by simp [destruct, cons, computation.rmap]
@[simp] theorem destruct_think (s : wseq α) : destruct (think s) = (destruct s).think :=
computation.destruct_eq_think $ by simp [destruct, think, computation.rmap]
@[simp] theorem seq_destruct_nil : seq.destruct (nil : wseq α) = none :=
seq.destruct_nil
@[simp] theorem seq_destruct_cons (a : α) (s) : seq.destruct (cons a s) = some (some a, s) :=
seq.destruct_cons _ _
@[simp] theorem seq_destruct_think (s : wseq α) : seq.destruct (think s) = some (none, s) :=
seq.destruct_cons _ _
@[simp] theorem head_nil : head (nil : wseq α) = return none := by simp [head]; refl
@[simp] theorem head_cons (a : α) (s) : head (cons a s) = return (some a) := by simp [head]; refl
@[simp] theorem head_think (s : wseq α) : head (think s) = (head s).think := by simp [head]; refl
@[simp] theorem flatten_ret (s : wseq α) : flatten (return s) = s :=
begin
refine seq.eq_of_bisim (λs1 s2, flatten (return s2) = s1) _ rfl,
intros s' s h, rw ←h, simp [flatten],
cases seq.destruct s, { simp },
{ cases val with o s', simp }
end
@[simp] theorem flatten_think (c : computation (wseq α)) : flatten c.think = think (flatten c) :=
seq.destruct_eq_cons $ by simp [flatten, think]
@[simp] theorem destruct_flatten (c : computation (wseq α)) : destruct (flatten c) = c >>= destruct :=
begin
refine computation.eq_of_bisim (λc1 c2, c1 = c2 ∨
∃ c, c1 = destruct (flatten c) ∧ c2 = computation.bind c destruct) _ (or.inr ⟨c, rfl, rfl⟩),
intros c1 c2 h, exact match c1, c2, h with
| _, _, (or.inl $ eq.refl c) := by cases c.destruct; simp
| _, _, (or.inr ⟨c, rfl, rfl⟩) := begin
apply c.cases_on (λa, _) (λc', _); repeat {simp},
{ cases (destruct a).destruct; simp },
{ exact or.inr ⟨c', rfl, rfl⟩ }
end end
end
theorem head_terminates_iff (s : wseq α) : terminates (head s) ↔ terminates (destruct s) :=
terminates_map_iff _ (destruct s)
@[simp] theorem tail_nil : tail (nil : wseq α) = nil := by simp [tail]
@[simp] theorem tail_cons (a : α) (s) : tail (cons a s) = s := by simp [tail]
@[simp] theorem tail_think (s : wseq α) : tail (think s) = (tail s).think := by simp [tail]
@[simp] theorem dropn_nil (n) :
drop (nil : wseq α) n = nil := by induction n; simp [*, drop]
@[simp] theorem dropn_cons (a : α) (s) (n) :
drop (cons a s) (n+1) = drop s n := by induction n; simp [*, drop]
@[simp] theorem dropn_think (s : wseq α) (n) :
drop (think s) n = (drop s n).think := by induction n; simp [*, drop]
theorem dropn_add (s : wseq α) (m) : ∀ n, drop s (m + n) = drop (drop s m) n
| 0 := rfl
| (n+1) := congr_arg tail (dropn_add n)
theorem dropn_tail (s : wseq α) (n) : drop (tail s) n = drop s (n + 1) :=
by rw add_comm; symmetry; apply dropn_add
theorem nth_add (s : wseq α) (m n) : nth s (m + n) = nth (drop s m) n :=
congr_arg head (dropn_add _ _ _)
theorem nth_tail (s : wseq α) (n) : nth (tail s) n = nth s (n + 1) :=
congr_arg head (dropn_tail _ _)
@[simp] theorem join_nil : join nil = (nil : wseq α) := seq.join_nil
@[simp] theorem join_think (S : wseq (wseq α)) :
join (think S) = think (join S) :=
by { simp [think, join], unfold functor.map, simp [join, seq1.ret] }
@[simp] theorem join_cons (s : wseq α) (S) :
join (cons s S) = think (append s (join S)) :=
by { simp [think, join], unfold functor.map, simp [join, cons, append] }
@[simp] theorem nil_append (s : wseq α) : append nil s = s := seq.nil_append _
@[simp] theorem cons_append (a : α) (s t) :
append (cons a s) t = cons a (append s t) := seq.cons_append _ _ _
@[simp] theorem think_append (s t : wseq α) :
append (think s) t = think (append s t) := seq.cons_append _ _ _
@[simp] theorem append_nil (s : wseq α) : append s nil = s := seq.append_nil _
@[simp] theorem append_assoc (s t u : wseq α) :
append (append s t) u = append s (append t u) := seq.append_assoc _ _ _
@[simp] def tail.aux : option (α × wseq α) → computation (option (α × wseq α))
| none := return none
| (some (a, s)) := destruct s
theorem destruct_tail (s : wseq α) :
destruct (tail s) = destruct s >>= tail.aux :=
begin
dsimp [tail], simp, rw [← bind_pure_comp_eq_map, is_lawful_monad.bind_assoc],
apply congr_arg, funext o,
rcases o with _|⟨a, s⟩;
apply (@pure_bind computation _ _ _ _ _ _).trans _; simp
end
@[simp] def drop.aux : ℕ → option (α × wseq α) → computation (option (α × wseq α))
| 0 := return
| (n+1) := λ a, tail.aux a >>= drop.aux n
theorem drop.aux_none : ∀ n, @drop.aux α n none = return none
| 0 := rfl
| (n+1) := show computation.bind (return none) (drop.aux n) = return none,
by rw [ret_bind, drop.aux_none]
theorem destruct_dropn :
∀ (s : wseq α) n, destruct (drop s n) = destruct s >>= drop.aux n
| s 0 := (bind_ret' _).symm
| s (n+1) := by rw [← dropn_tail, destruct_dropn _ n,
destruct_tail, is_lawful_monad.bind_assoc]; refl
theorem head_terminates_of_head_tail_terminates (s : wseq α) [T : terminates (head (tail s))] :
terminates (head s) :=
(head_terminates_iff _).2 $ begin
cases (head_terminates_iff _).1 T with a h,
simp [tail] at h,
rcases exists_of_mem_bind h with ⟨s', h1, h2⟩,
unfold functor.map at h1,
exact let ⟨t, h3, h4⟩ := exists_of_mem_map h1 in terminates_of_mem h3
end
theorem destruct_some_of_destruct_tail_some {s : wseq α} {a}
(h : some a ∈ destruct (tail s)) : ∃ a', some a' ∈ destruct s :=
begin
unfold tail functor.map at h, simp at h,
rcases exists_of_mem_bind h with ⟨t, tm, td⟩, clear h,
rcases exists_of_mem_map tm with ⟨t', ht', ht2⟩, clear tm,
cases t' with t'; rw ←ht2 at td; simp at td,
{ have := mem_unique td (ret_mem _), contradiction },
{ exact ⟨_, ht'⟩ }
end
theorem head_some_of_head_tail_some {s : wseq α} {a}
(h : some a ∈ head (tail s)) : ∃ a', some a' ∈ head s :=
begin
unfold head at h,
rcases exists_of_mem_map h with ⟨o, md, e⟩, clear h,
cases o with o; injection e with h', clear e h',
cases destruct_some_of_destruct_tail_some md with a am,
exact ⟨_, mem_map ((<$>) (@prod.fst α (wseq α))) am⟩
end
theorem head_some_of_nth_some {s : wseq α} {a n}
(h : some a ∈ nth s n) : ∃ a', some a' ∈ head s :=
begin
revert a, induction n with n IH; intros,
exacts [⟨_, h⟩, let ⟨a', h'⟩ := head_some_of_head_tail_some h in IH h']
end
instance productive_tail (s : wseq α) [productive s] : productive (tail s) :=
λ n, by rw [nth_tail]; apply_instance
instance productive_dropn (s : wseq α) [productive s] (n) : productive (drop s n) :=
λ m, by rw [←nth_add]; apply_instance
/-- Given a productive weak sequence, we can collapse all the `think`s to
produce a sequence. -/
def to_seq (s : wseq α) [productive s] : seq α :=
⟨λ n, (nth s n).get, λn h,
begin
cases e : computation.get (nth s (n + 1)), {assumption},
have := mem_of_get_eq _ e,
simp [nth] at this h, cases head_some_of_head_tail_some this with a' h',
have := mem_unique h' (@mem_of_get_eq _ _ _ _ h),
contradiction
end⟩
theorem nth_terminates_le {s : wseq α} {m n} (h : m ≤ n) : terminates (nth s n) → terminates (nth s m) :=
by induction h with m' h IH; [exact id,
exact λ T, IH (@head_terminates_of_head_tail_terminates _ _ T)]
theorem head_terminates_of_nth_terminates {s : wseq α} {n} : terminates (nth s n) → terminates (head s) :=
nth_terminates_le (nat.zero_le n)
theorem destruct_terminates_of_nth_terminates {s : wseq α} {n} (T : terminates (nth s n)) : terminates (destruct s) :=
(head_terminates_iff _).1 $ head_terminates_of_nth_terminates T
theorem mem_rec_on {C : wseq α → Prop} {a s} (M : a ∈ s)
(h1 : ∀ b s', (a = b ∨ C s') → C (cons b s'))
(h2 : ∀ s, C s → C (think s)) : C s :=
begin
apply seq.mem_rec_on M,
intros o s' h, cases o with b,
{ apply h2, cases h, {contradiction}, {assumption} },
{ apply h1, apply or.imp_left _ h, intro h, injection h }
end
@[simp] theorem mem_think (s : wseq α) (a) : a ∈ think s ↔ a ∈ s :=
begin
cases s with f al,
change some (some a) ∈ some none :: f ↔ some (some a) ∈ f,
constructor; intro h,
{ apply (stream.eq_or_mem_of_mem_cons h).resolve_left,
intro, injections },
{ apply stream.mem_cons_of_mem _ h }
end
theorem eq_or_mem_iff_mem {s : wseq α} {a a' s'} :
some (a', s') ∈ destruct s → (a ∈ s ↔ a = a' ∨ a ∈ s') :=
begin
generalize e : destruct s = c, intro h,
revert s, apply computation.mem_rec_on h _ (λ c IH, _); intro s;
apply s.cases_on _ (λ x s, _) (λ s, _); intros m;
have := congr_arg computation.destruct m; simp at this;
cases this with i1 i2,
{ rw [i1, i2],
cases s' with f al,
unfold cons has_mem.mem wseq.mem seq.mem seq.cons, simp,
have h_a_eq_a' : a = a' ↔ some (some a) = some (some a'), {simp},
rw [h_a_eq_a'],
refine ⟨stream.eq_or_mem_of_mem_cons, λo, _⟩,
{ cases o with e m,
{ rw e, apply stream.mem_cons },
{ exact stream.mem_cons_of_mem _ m } } },
{ simp, exact IH this }
end
@[simp] theorem mem_cons_iff (s : wseq α) (b) {a} : a ∈ cons b s ↔ a = b ∨ a ∈ s :=
eq_or_mem_iff_mem $ by simp [ret_mem]
theorem mem_cons_of_mem {s : wseq α} (b) {a} (h : a ∈ s) : a ∈ cons b s :=
(mem_cons_iff _ _).2 (or.inr h)
theorem mem_cons (s : wseq α) (a) : a ∈ cons a s :=
(mem_cons_iff _ _).2 (or.inl rfl)
theorem mem_of_mem_tail {s : wseq α} {a} : a ∈ tail s → a ∈ s :=
begin
intro h, have := h, cases h with n e, revert s, simp [stream.nth],
induction n with n IH; intro s; apply s.cases_on _ (λx s, _) (λ s, _);
repeat{simp}; intros m e; injections,
{ exact or.inr m },
{ exact or.inr m },
{ apply IH m, rw e, cases tail s, refl }
end
theorem mem_of_mem_dropn {s : wseq α} {a} : ∀ {n}, a ∈ drop s n → a ∈ s
| 0 h := h
| (n+1) h := @mem_of_mem_dropn n (mem_of_mem_tail h)
theorem nth_mem {s : wseq α} {a n} : some a ∈ nth s n → a ∈ s :=
begin
revert s, induction n with n IH; intros s h,
{ rcases exists_of_mem_map h with ⟨o, h1, h2⟩,
cases o with o; injection h2 with h',
cases o with a' s',
exact (eq_or_mem_iff_mem h1).2 (or.inl h'.symm) },
{ have := @IH (tail s), rw nth_tail at this,
exact mem_of_mem_tail (this h) }
end
theorem exists_nth_of_mem {s : wseq α} {a} (h : a ∈ s) : ∃ n, some a ∈ nth s n :=
begin
apply mem_rec_on h,
{ intros a' s' h, cases h with h h,
{ existsi 0, simp [nth], rw h, apply ret_mem },
{ cases h with n h, existsi n+1,
simp [nth], exact h } },
{ intros s' h, cases h with n h,
existsi n, simp [nth], apply think_mem h }
end
theorem exists_dropn_of_mem {s : wseq α} {a} (h : a ∈ s) :
∃ n s', some (a, s') ∈ destruct (drop s n) :=
let ⟨n, h⟩ := exists_nth_of_mem h in ⟨n, begin
cases (head_terminates_iff _).1 ⟨_, h⟩ with o om,
have := mem_unique (mem_map _ om) h,
cases o with o; injection this with i,
cases o with a' s', dsimp at i,
rw i at om, exact ⟨_, om⟩
end⟩
theorem lift_rel_dropn_destruct {R : α → β → Prop} {s t} (H : lift_rel R s t) :
∀ n, computation.lift_rel (lift_rel_o R (lift_rel R))
(destruct (drop s n)) (destruct (drop t n))
| 0 := lift_rel_destruct H
| (n+1) := begin
simp [destruct_tail],
apply lift_rel_bind,
apply lift_rel_dropn_destruct n,
exact λ a b o, match a, b, o with
| none, none, _ := by simp
| some (a, s), some (b, t), ⟨h1, h2⟩ := by simp [tail.aux]; apply lift_rel_destruct h2
end
end
theorem exists_of_lift_rel_left {R : α → β → Prop} {s t}
(H : lift_rel R s t) {a} (h : a ∈ s) : ∃ {b}, b ∈ t ∧ R a b :=
let ⟨n, h⟩ := exists_nth_of_mem h,
⟨some (._, s'), sd, rfl⟩ := exists_of_mem_map h,
⟨some (b, t'), td, ⟨ab, _⟩⟩ := (lift_rel_dropn_destruct H n).left sd in
⟨b, nth_mem (mem_map ((<$>) prod.fst.{v v}) td), ab⟩
theorem exists_of_lift_rel_right {R : α → β → Prop} {s t}
(H : lift_rel R s t) {b} (h : b ∈ t) : ∃ {a}, a ∈ s ∧ R a b :=
by rw ←lift_rel.swap at H; exact exists_of_lift_rel_left H h
theorem head_terminates_of_mem {s : wseq α} {a} (h : a ∈ s) : terminates (head s) :=
let ⟨n, h⟩ := exists_nth_of_mem h in head_terminates_of_nth_terminates ⟨_, h⟩
theorem of_mem_append {s₁ s₂ : wseq α} {a : α} : a ∈ append s₁ s₂ → a ∈ s₁ ∨ a ∈ s₂ :=
seq.of_mem_append
theorem mem_append_left {s₁ s₂ : wseq α} {a : α} : a ∈ s₁ → a ∈ append s₁ s₂ :=
seq.mem_append_left
theorem exists_of_mem_map {f} {b : β} : ∀ {s : wseq α}, b ∈ map f s → ∃ a, a ∈ s ∧ f a = b
| ⟨g, al⟩ h := let ⟨o, om, oe⟩ := seq.exists_of_mem_map h in
by cases o with a; injection oe with h'; exact ⟨a, om, h'⟩
@[simp] theorem lift_rel_nil (R : α → β → Prop) : lift_rel R nil nil :=
by rw [lift_rel_destruct_iff]; simp
@[simp] theorem lift_rel_cons (R : α → β → Prop) (a b s t) :
lift_rel R (cons a s) (cons b t) ↔ R a b ∧ lift_rel R s t :=
by rw [lift_rel_destruct_iff]; simp
@[simp] theorem lift_rel_think_left (R : α → β → Prop) (s t) :
lift_rel R (think s) t ↔ lift_rel R s t :=
by rw [lift_rel_destruct_iff, lift_rel_destruct_iff]; simp
@[simp] theorem lift_rel_think_right (R : α → β → Prop) (s t) :
lift_rel R s (think t) ↔ lift_rel R s t :=
by rw [lift_rel_destruct_iff, lift_rel_destruct_iff]; simp
theorem cons_congr {s t : wseq α} (a : α) (h : s ~ t) : cons a s ~ cons a t :=
by unfold equiv; simp; exact h
theorem think_equiv (s : wseq α) : think s ~ s :=
by unfold equiv; simp; apply equiv.refl
theorem think_congr {s t : wseq α} (a : α) (h : s ~ t) : think s ~ think t :=
by unfold equiv; simp; exact h
theorem head_congr : ∀ {s t : wseq α}, s ~ t → head s ~ head t :=
suffices ∀ {s t : wseq α}, s ~ t → ∀ {o}, o ∈ head s → o ∈ head t, from
λ s t h o, ⟨this h, this h.symm⟩,
begin
intros s t h o ho,
rcases @computation.exists_of_mem_map _ _ _ _ (destruct s) ho with ⟨ds, dsm, dse⟩,
rw ←dse,
cases destruct_congr h with l r,
rcases l dsm with ⟨dt, dtm, dst⟩,
cases ds with a; cases dt with b,
{ apply mem_map _ dtm },
{ cases b, cases dst },
{ cases a, cases dst },
{ cases a with a s', cases b with b t', rw dst.left,
exact @mem_map _ _ (@functor.map _ _ (α × wseq α) _ prod.fst)
_ (destruct t) dtm }
end
theorem flatten_equiv {c : computation (wseq α)} {s} (h : s ∈ c) : flatten c ~ s :=
begin
apply computation.mem_rec_on h, { simp },
{ intro s', apply equiv.trans, simp [think_equiv] }
end
theorem lift_rel_flatten {R : α → β → Prop} {c1 : computation (wseq α)} {c2 : computation (wseq β)}
(h : c1.lift_rel (lift_rel R) c2) : lift_rel R (flatten c1) (flatten c2) :=
let S := λ s t,
∃ c1 c2, s = flatten c1 ∧ t = flatten c2 ∧ computation.lift_rel (lift_rel R) c1 c2 in
⟨S, ⟨c1, c2, rfl, rfl, h⟩, λ s t h,
match s, t, h with ._, ._, ⟨c1, c2, rfl, rfl, h⟩ := begin
simp, apply lift_rel_bind _ _ h,
intros a b ab, apply computation.lift_rel.imp _ _ _ (lift_rel_destruct ab),
intros a b, apply lift_rel_o.imp_right,
intros s t h, refine ⟨return s, return t, _, _, _⟩; simp [h]
end end⟩
theorem flatten_congr {c1 c2 : computation (wseq α)} :
computation.lift_rel equiv c1 c2 → flatten c1 ~ flatten c2 := lift_rel_flatten
theorem tail_congr {s t : wseq α} (h : s ~ t) : tail s ~ tail t :=
begin
apply flatten_congr,
unfold functor.map, rw [←bind_ret, ←bind_ret],
apply lift_rel_bind _ _ (destruct_congr h),
intros a b h, simp,
cases a with a; cases b with b,
{ trivial },
{ cases h },
{ cases a, cases h },
{ cases a with a s', cases b with b t', exact h.right }
end
theorem dropn_congr {s t : wseq α} (h : s ~ t) (n) : drop s n ~ drop t n :=
by induction n; simp [*, tail_congr]
theorem nth_congr {s t : wseq α} (h : s ~ t) (n) : nth s n ~ nth t n :=
head_congr (dropn_congr h _)
theorem mem_congr {s t : wseq α} (h : s ~ t) (a) : a ∈ s ↔ a ∈ t :=
suffices ∀ {s t : wseq α}, s ~ t → a ∈ s → a ∈ t, from ⟨this h, this h.symm⟩,
λ s t h as, let ⟨n, hn⟩ := exists_nth_of_mem as in
nth_mem ((nth_congr h _ _).1 hn)
theorem productive_congr {s t : wseq α} (h : s ~ t) : productive s ↔ productive t :=
forall_congr $ λn, terminates_congr $ nth_congr h _
theorem equiv.ext {s t : wseq α} (h : ∀ n, nth s n ~ nth t n) : s ~ t :=
⟨λ s t, ∀ n, nth s n ~ nth t n, h, λs t h, begin
refine lift_rel_def.2 ⟨_, _⟩,
{ rw [←head_terminates_iff, ←head_terminates_iff],
exact terminates_congr (h 0) },
{ intros a b ma mb,
cases a with a; cases b with b,
{ trivial },
{ injection mem_unique (mem_map _ ma) ((h 0 _).2 (mem_map _ mb)) },
{ injection mem_unique (mem_map _ ma) ((h 0 _).2 (mem_map _ mb)) },
{ cases a with a s', cases b with b t',
injection mem_unique (mem_map _ ma) ((h 0 _).2 (mem_map _ mb)) with ab,
refine ⟨ab, λ n, _⟩,
refine (nth_congr (flatten_equiv (mem_map _ ma)) n).symm.trans
((_ : nth (tail s) n ~ nth (tail t) n).trans
(nth_congr (flatten_equiv (mem_map _ mb)) n)),
rw [nth_tail, nth_tail], apply h } }
end⟩
theorem length_eq_map (s : wseq α) : length s = computation.map list.length (to_list s) :=
begin
refine eq_of_bisim
(λ c1 c2, ∃ (l : list α) (s : wseq α),
c1 = corec length._match_2 (l.length, s) ∧
c2 = computation.map list.length (corec to_list._match_2 (l, s)))
_ ⟨[], s, rfl, rfl⟩,
intros s1 s2 h, rcases h with ⟨l, s, h⟩, rw [h.left, h.right],
apply s.cases_on _ (λ a s, _) (λ s, _);
repeat {simp [to_list, nil, cons, think, length]},
{ refine ⟨a::l, s, _, _⟩; simp },
{ refine ⟨l, s, _, _⟩; simp }
end
@[simp] theorem of_list_nil : of_list [] = (nil : wseq α) := rfl
@[simp] theorem of_list_cons (a : α) (l) :
of_list (a :: l) = cons a (of_list l) :=
show seq.map some (seq.of_list (a :: l)) =
seq.cons (some a) (seq.map some (seq.of_list l)), by simp
@[simp] theorem to_list'_nil (l : list α) :
corec to_list._match_2 (l, nil) = return l.reverse :=
destruct_eq_ret rfl
@[simp] theorem to_list'_cons (l : list α) (s : wseq α) (a : α) :
corec to_list._match_2 (l, cons a s) =
(corec to_list._match_2 (a::l, s)).think :=
destruct_eq_think $ by simp [to_list, cons]
@[simp] theorem to_list'_think (l : list α) (s : wseq α) :
corec to_list._match_2 (l, think s) =
(corec to_list._match_2 (l, s)).think :=
destruct_eq_think $ by simp [to_list, think]
theorem to_list'_map (l : list α) (s : wseq α) :
corec to_list._match_2 (l, s) =
((++) l.reverse) <$> to_list s :=
begin
refine eq_of_bisim
(λ c1 c2, ∃ (l' : list α) (s : wseq α),
c1 = corec to_list._match_2 (l' ++ l, s) ∧
c2 = computation.map ((++) l.reverse) (corec to_list._match_2 (l', s)))
_ ⟨[], s, rfl, rfl⟩,
intros s1 s2 h, rcases h with ⟨l', s, h⟩, rw [h.left, h.right],
apply s.cases_on _ (λ a s, _) (λ s, _);
repeat {simp [to_list, nil, cons, think, length]},
{ refine ⟨a::l', s, _, _⟩; simp },
{ refine ⟨l', s, _, _⟩; simp }
end
@[simp] theorem to_list_cons (a : α) (s) :
to_list (cons a s) = (list.cons a <$> to_list s).think :=
destruct_eq_think $ by unfold to_list; simp; rw to_list'_map; simp; refl
@[simp] theorem to_list_nil : to_list (nil : wseq α) = return [] :=
destruct_eq_ret rfl
theorem to_list_of_list (l : list α) : l ∈ to_list (of_list l) :=
by induction l with a l IH; simp [ret_mem]; exact think_mem (mem_map _ IH)
@[simp] theorem destruct_of_seq (s : seq α) :
destruct (of_seq s) = return (s.head.map $ λ a, (a, of_seq s.tail)) :=
destruct_eq_ret $ begin
simp [of_seq, head, destruct, seq.destruct, seq.head],
rw [show seq.nth (some <$> s) 0 = some <$> seq.nth s 0, by apply seq.map_nth],
cases seq.nth s 0 with a, { refl },
unfold functor.map,
simp [destruct]
end
@[simp] theorem head_of_seq (s : seq α) : head (of_seq s) = return s.head :=
by simp [head]; cases seq.head s; refl
@[simp] theorem tail_of_seq (s : seq α) : tail (of_seq s) = of_seq s.tail :=
begin
simp [tail], apply s.cases_on _ (λ x s, _); simp [of_seq], {refl},
rw [seq.head_cons, seq.tail_cons], refl
end
@[simp] theorem dropn_of_seq (s : seq α) : ∀ n, drop (of_seq s) n = of_seq (s.drop n)
| 0 := rfl
| (n+1) := by dsimp [drop]; rw [dropn_of_seq, tail_of_seq]
theorem nth_of_seq (s : seq α) (n) : nth (of_seq s) n = return (seq.nth s n) :=
by dsimp [nth]; rw [dropn_of_seq, head_of_seq, seq.head_dropn]
instance productive_of_seq (s : seq α) : productive (of_seq s) :=
λ n, by rw nth_of_seq; apply_instance
theorem to_seq_of_seq (s : seq α) : to_seq (of_seq s) = s :=
begin
apply subtype.eq, funext n,
dsimp [to_seq], apply get_eq_of_mem,
rw nth_of_seq, apply ret_mem
end
/-- The monadic `return a` is a singleton list containing `a`. -/
def ret (a : α) : wseq α := of_list [a]
@[simp] theorem map_nil (f : α → β) : map f nil = nil := rfl
@[simp] theorem map_cons (f : α → β) (a s) :
map f (cons a s) = cons (f a) (map f s) := seq.map_cons _ _ _
@[simp] theorem map_think (f : α → β) (s) :
map f (think s) = think (map f s) := seq.map_cons _ _ _
@[simp] theorem map_id (s : wseq α) : map id s = s := by simp [map]
@[simp] theorem map_ret (f : α → β) (a) : map f (ret a) = ret (f a) := by simp [ret]
@[simp] theorem map_append (f : α → β) (s t) : map f (append s t) = append (map f s) (map f t) :=
seq.map_append _ _ _
theorem map_comp (f : α → β) (g : β → γ) (s : wseq α) :
map (g ∘ f) s = map g (map f s) :=
begin
dsimp [map], rw ←seq.map_comp,
apply congr_fun, apply congr_arg,
funext o, cases o; refl
end
theorem mem_map (f : α → β) {a : α} {s : wseq α} : a ∈ s → f a ∈ map f s :=
seq.mem_map (option.map f)
-- The converse is not true without additional assumptions
theorem exists_of_mem_join {a : α} : ∀ {S : wseq (wseq α)}, a ∈ join S → ∃ s, s ∈ S ∧ a ∈ s :=
suffices ∀ ss : wseq α, a ∈ ss → ∀ s S, append s (join S) = ss →
a ∈ append s (join S) → a ∈ s ∨ ∃ s, s ∈ S ∧ a ∈ s, from λ S h,
(this _ h nil S (by simp) (by simp [h])).resolve_left (not_mem_nil _),
begin
intros ss h, apply mem_rec_on h (λ b ss o, _) (λ ss IH, _); intros s S,
{ refine s.cases_on (S.cases_on _ (λ s S, _) (λ S, _)) (λ b' s, _) (λ s, _);
intros ej m; simp at ej;
have := congr_arg seq.destruct ej; simp at this;
try {cases this}; try {contradiction},
substs b' ss,
simp at m ⊢,
cases o with e IH, { simp [e] },
cases m with e m, { simp [e] },
exact or.imp_left or.inr (IH _ _ rfl m) },
{ refine s.cases_on (S.cases_on _ (λ s S, _) (λ S, _)) (λ b' s, _) (λ s, _);
intros ej m; simp at ej;
have := congr_arg seq.destruct ej; simp at this;
try { try {have := this.1}, contradiction }; subst ss,
{ apply or.inr, simp at m ⊢,
cases IH s S rfl m with as ex,
{ exact ⟨s, or.inl rfl, as⟩ },
{ rcases ex with ⟨s', sS, as⟩,
exact ⟨s', or.inr sS, as⟩ } },
{ apply or.inr, simp at m,
rcases (IH nil S (by simp) (by simp [m])).resolve_left (not_mem_nil _) with ⟨s, sS, as⟩,
exact ⟨s, by simp [sS], as⟩ },
{ simp at m IH ⊢, apply IH _ _ rfl m } }
end
theorem exists_of_mem_bind {s : wseq α} {f : α → wseq β} {b}
(h : b ∈ bind s f) : ∃ a ∈ s, b ∈ f a :=
let ⟨t, tm, bt⟩ := exists_of_mem_join h,
⟨a, as, e⟩ := exists_of_mem_map tm in ⟨a, as, by rwa e⟩
theorem destruct_map (f : α → β) (s : wseq α) :
destruct (map f s) = computation.map (option.map (prod.map f (map f))) (destruct s) :=
begin
apply eq_of_bisim (λ c1 c2, ∃ s, c1 = destruct (map f s) ∧
c2 = computation.map (option.map (prod.map f (map f))) (destruct s)),
{ intros c1 c2 h, cases h with s h, rw [h.left, h.right],
apply s.cases_on _ (λ a s, _) (λ s, _); simp,
exact ⟨s, rfl, rfl⟩ },
{ exact ⟨s, rfl, rfl⟩ }
end
theorem lift_rel_map {δ} (R : α → β → Prop) (S : γ → δ → Prop)
{s1 : wseq α} {s2 : wseq β}
{f1 : α → γ} {f2 : β → δ}
(h1 : lift_rel R s1 s2) (h2 : ∀ {a b}, R a b → S (f1 a) (f2 b))
: lift_rel S (map f1 s1) (map f2 s2) :=
⟨λ s1 s2, ∃ s t, s1 = map f1 s ∧ s2 = map f2 t ∧ lift_rel R s t,
⟨s1, s2, rfl, rfl, h1⟩,
λ s1 s2 h, match s1, s2, h with ._, ._, ⟨s, t, rfl, rfl, h⟩ := begin
simp [destruct_map], apply computation.lift_rel_map _ _ (lift_rel_destruct h),
intros o p h,
cases o with a; cases p with b; simp,
{ cases b; cases h },
{ cases a; cases h },
{ cases a with a s; cases b with b t, cases h with r h,
exact ⟨h2 r, s, rfl, t, rfl, h⟩ }
end end⟩
theorem map_congr (f : α → β) {s t : wseq α} (h : s ~ t) : map f s ~ map f t :=
lift_rel_map _ _ h (λ _ _, congr_arg _)
@[simp] def destruct_append.aux (t : wseq α) :
option (α × wseq α) → computation (option (α × wseq α))
| none := destruct t
| (some (a, s)) := return (some (a, append s t))
theorem destruct_append (s t : wseq α) :
destruct (append s t) = (destruct s).bind (destruct_append.aux t) :=
begin
apply eq_of_bisim (λ c1 c2, ∃ s t, c1 = destruct (append s t) ∧
c2 = (destruct s).bind (destruct_append.aux t)) _ ⟨s, t, rfl, rfl⟩,
intros c1 c2 h, rcases h with ⟨s, t, h⟩, rw [h.left, h.right],
apply s.cases_on _ (λ a s, _) (λ s, _); simp,
{ apply t.cases_on _ (λ b t, _) (λ t, _); simp,
{ refine ⟨nil, t, _, _⟩; simp } },
{ exact ⟨s, t, rfl, rfl⟩ }
end
@[simp] def destruct_join.aux : option (wseq α × wseq (wseq α)) → computation (option (α × wseq α))
| none := return none
| (some (s, S)) := (destruct (append s (join S))).think
theorem destruct_join (S : wseq (wseq α)) :
destruct (join S) = (destruct S).bind destruct_join.aux :=
begin
apply eq_of_bisim (λ c1 c2, c1 = c2 ∨ ∃ S, c1 = destruct (join S) ∧
c2 = (destruct S).bind destruct_join.aux) _ (or.inr ⟨S, rfl, rfl⟩),
intros c1 c2 h, exact match c1, c2, h with
| _, _, (or.inl $ eq.refl c) := by cases c.destruct; simp
| _, _, or.inr ⟨S, rfl, rfl⟩ := begin
apply S.cases_on _ (λ s S, _) (λ S, _); simp,
{ refine or.inr ⟨S, rfl, rfl⟩ }
end end
end
theorem lift_rel_append (R : α → β → Prop) {s1 s2 : wseq α} {t1 t2 : wseq β}
(h1 : lift_rel R s1 t1) (h2 : lift_rel R s2 t2) :
lift_rel R (append s1 s2) (append t1 t2) :=
⟨λ s t, lift_rel R s t ∨ ∃ s1 t1, s = append s1 s2 ∧ t = append t1 t2 ∧ lift_rel R s1 t1,
or.inr ⟨s1, t1, rfl, rfl, h1⟩,
λ s t h, match s, t, h with
| s, t, or.inl h := begin
apply computation.lift_rel.imp _ _ _ (lift_rel_destruct h),
intros a b, apply lift_rel_o.imp_right,
intros s t, apply or.inl
end
| ._, ._, or.inr ⟨s1, t1, rfl, rfl, h⟩ := begin
simp [destruct_append],
apply computation.lift_rel_bind _ _ (lift_rel_destruct h),
intros o p h,
cases o with a; cases p with b,
{ simp, apply computation.lift_rel.imp _ _ _ (lift_rel_destruct h2),
intros a b, apply lift_rel_o.imp_right,
intros s t, apply or.inl },
{ cases b; cases h },
{ cases a; cases h },
{ cases a with a s; cases b with b t, cases h with r h,
simp, exact ⟨r, or.inr ⟨s, rfl, t, rfl, h⟩⟩ }
end
end⟩
theorem lift_rel_join.lem (R : α → β → Prop) {S T} {U : wseq α → wseq β → Prop}
(ST : lift_rel (lift_rel R) S T) (HU : ∀ s1 s2, (∃ s t S T,
s1 = append s (join S) ∧ s2 = append t (join T) ∧
lift_rel R s t ∧ lift_rel (lift_rel R) S T) → U s1 s2) {a} (ma : a ∈ destruct (join S)) :
∃ {b}, b ∈ destruct (join T) ∧ lift_rel_o R U a b :=
begin
cases exists_results_of_mem ma with n h, clear ma, revert a S T,
apply nat.strong_induction_on n _,
intros n IH a S T ST ra, simp [destruct_join] at ra, exact
let ⟨o, m, k, rs1, rs2, en⟩ := of_results_bind ra,
⟨p, mT, rop⟩ := computation.exists_of_lift_rel_left (lift_rel_destruct ST) rs1.mem in
by exact match o, p, rop, rs1, rs2, mT with
| none, none, _, rs1, rs2, mT := by simp [destruct_join]; exact
⟨none, mem_bind mT (ret_mem _), by rw eq_of_ret_mem rs2.mem; trivial⟩
| some (s, S'), some (t, T'), ⟨st, ST'⟩, rs1, rs2, mT :=
by simp [destruct_append] at rs2; exact
let ⟨k1, rs3, ek⟩ := of_results_think rs2,
⟨o', m1, n1, rs4, rs5, ek1⟩ := of_results_bind rs3,
⟨p', mt, rop'⟩ := computation.exists_of_lift_rel_left (lift_rel_destruct st) rs4.mem in
by exact match o', p', rop', rs4, rs5, mt with
| none, none, _, rs4, rs5', mt :=
have n1 < n, begin
rw [en, ek, ek1],
apply lt_of_lt_of_le _ (nat.le_add_right _ _),
apply nat.lt_succ_of_le (nat.le_add_right _ _)
end,
let ⟨ob, mb, rob⟩ := IH _ this ST' rs5' in by refine ⟨ob, _, rob⟩;
{ simp [destruct_join], apply mem_bind mT, simp [destruct_append],
apply think_mem, apply mem_bind mt, exact mb }
| some (a, s'), some (b, t'), ⟨ab, st'⟩, rs4, rs5, mt := begin
simp at rs5,
refine ⟨some (b, append t' (join T')), _, _⟩,
{ simp [destruct_join], apply mem_bind mT, simp [destruct_append],
apply think_mem, apply mem_bind mt, apply ret_mem },
rw eq_of_ret_mem rs5.mem,
exact ⟨ab, HU _ _ ⟨s', t', S', T', rfl, rfl, st', ST'⟩⟩
end end
end
end
theorem lift_rel_join (R : α → β → Prop) {S : wseq (wseq α)} {T : wseq (wseq β)}
(h : lift_rel (lift_rel R) S T) : lift_rel R (join S) (join T) :=
⟨λ s1 s2, ∃ s t S T,
s1 = append s (join S) ∧ s2 = append t (join T) ∧
lift_rel R s t ∧ lift_rel (lift_rel R) S T,
⟨nil, nil, S, T, by simp, by simp, by simp, h⟩,
λs1 s2 ⟨s, t, S, T, h1, h2, st, ST⟩, begin
clear _fun_match _x,
rw [h1, h2], rw [destruct_append, destruct_append],
apply computation.lift_rel_bind _ _ (lift_rel_destruct st),
exact λ o p h, match o, p, h with
| some (a, s), some (b, t), ⟨h1, h2⟩ :=
by simp; exact ⟨h1, s, t, S, rfl, T, rfl, h2, ST⟩
| none, none, _ := begin
dsimp [destruct_append.aux, computation.lift_rel], constructor,
{ intro, apply lift_rel_join.lem _ ST (λ _ _, id) },
{ intros b mb,
rw [←lift_rel_o.swap], apply lift_rel_join.lem (function.swap R),
{ rw [←lift_rel.swap R, ←lift_rel.swap], apply ST },
{ rw [←lift_rel.swap R, ←lift_rel.swap (lift_rel R)],
exact λ s1 s2 ⟨s, t, S, T, h1, h2, st, ST⟩,
⟨t, s, T, S, h2, h1, st, ST⟩ },
{ exact mb } }
end end
end⟩
theorem join_congr {S T : wseq (wseq α)} (h : lift_rel equiv S T) : join S ~ join T :=
lift_rel_join _ h
theorem lift_rel_bind {δ} (R : α → β → Prop) (S : γ → δ → Prop)
{s1 : wseq α} {s2 : wseq β}
{f1 : α → wseq γ} {f2 : β → wseq δ}
(h1 : lift_rel R s1 s2) (h2 : ∀ {a b}, R a b → lift_rel S (f1 a) (f2 b))
: lift_rel S (bind s1 f1) (bind s2 f2) :=
lift_rel_join _ (lift_rel_map _ _ h1 @h2)
theorem bind_congr {s1 s2 : wseq α} {f1 f2 : α → wseq β}
(h1 : s1 ~ s2) (h2 : ∀ a, f1 a ~ f2 a) : bind s1 f1 ~ bind s2 f2 :=
lift_rel_bind _ _ h1 (λ a b h, by rw h; apply h2)
@[simp] theorem join_ret (s : wseq α) : join (ret s) ~ s :=
by simp [ret]; apply think_equiv
@[simp] theorem join_map_ret (s : wseq α) : join (map ret s) ~ s :=
begin
refine ⟨λ s1 s2, join (map ret s2) = s1, rfl, _⟩,
intros s' s h, rw ←h,
apply lift_rel_rec
(λ c1 c2, ∃ s,
c1 = destruct (join (map ret s)) ∧ c2 = destruct s),
{ exact λ c1 c2 h, match c1, c2, h with
| ._, ._, ⟨s, rfl, rfl⟩ := begin
clear h _match,
apply s.cases_on _ (λ a s, _) (λ s, _); simp [ret],
{ refine ⟨_, ret_mem _, _⟩, simp },
{ exact ⟨s, rfl, rfl⟩ }
end end },
{ exact ⟨s, rfl, rfl⟩ }
end
@[simp] theorem join_append (S T : wseq (wseq α)) :
join (append S T) ~ append (join S) (join T) :=
begin
refine ⟨λ s1 s2, ∃ s S T,
s1 = append s (join (append S T)) ∧
s2 = append s (append (join S) (join T)), ⟨nil, S, T, by simp, by simp⟩, _⟩,
intros s1 s2 h,
apply lift_rel_rec (λ c1 c2, ∃ (s : wseq α) S T,
c1 = destruct (append s (join (append S T))) ∧
c2 = destruct (append s (append (join S) (join T)))) _ _ _
(let ⟨s, S, T, h1, h2⟩ := h in
⟨s, S, T, congr_arg destruct h1, congr_arg destruct h2⟩),
intros c1 c2 h,
exact match c1, c2, h with ._, ._, ⟨s, S, T, rfl, rfl⟩ := begin
clear _match h h,
apply wseq.cases_on s _ (λ a s, _) (λ s, _); simp,
{ apply wseq.cases_on S _ (λ s S, _) (λ S, _); simp,
{ apply wseq.cases_on T _ (λ s T, _) (λ T, _); simp,
{ refine ⟨s, nil, T, _, _⟩; simp },
{ refine ⟨nil, nil, T, _, _⟩; simp } },
{ exact ⟨s, S, T, rfl, rfl⟩ },
{ refine ⟨nil, S, T, _, _⟩; simp } },
{ exact ⟨s, S, T, rfl, rfl⟩ },
{ exact ⟨s, S, T, rfl, rfl⟩ }
end end
end
@[simp] theorem bind_ret (f : α → β) (s) : bind s (ret ∘ f) ~ map f s :=
begin
dsimp [bind], change (λx, ret (f x)) with (ret ∘ f),
rw [map_comp], apply join_map_ret
end
@[simp] theorem ret_bind (a : α) (f : α → wseq β) :
bind (ret a) f ~ f a := by simp [bind]
@[simp] theorem map_join (f : α → β) (S) :
map f (join S) = join (map (map f) S) :=
begin
apply seq.eq_of_bisim (λs1 s2,
∃ s S, s1 = append s (map f (join S)) ∧
s2 = append s (join (map (map f) S))),
{ intros s1 s2 h,
exact match s1, s2, h with ._, ._, ⟨s, S, rfl, rfl⟩ := begin
apply wseq.cases_on s _ (λ a s, _) (λ s, _); simp,
{ apply wseq.cases_on S _ (λ s S, _) (λ S, _); simp,
{ exact ⟨map f s, S, rfl, rfl⟩ },
{ refine ⟨nil, S, _, _⟩; simp } },
{ exact ⟨_, _, rfl, rfl⟩ },
{ exact ⟨_, _, rfl, rfl⟩ }
end end },
{ refine ⟨nil, S, _, _⟩; simp }
end
@[simp] theorem join_join (SS : wseq (wseq (wseq α))) :
join (join SS) ~ join (map join SS) :=
begin
refine ⟨λ s1 s2, ∃ s S SS,
s1 = append s (join (append S (join SS))) ∧
s2 = append s (append (join S) (join (map join SS))),
⟨nil, nil, SS, by simp, by simp⟩, _⟩,
intros s1 s2 h,
apply lift_rel_rec (λ c1 c2, ∃ s S SS,
c1 = destruct (append s (join (append S (join SS)))) ∧
c2 = destruct (append s (append (join S) (join (map join SS)))))
_ (destruct s1) (destruct s2)
(let ⟨s, S, SS, h1, h2⟩ := h in ⟨s, S, SS, by simp [h1], by simp [h2]⟩),
intros c1 c2 h,
exact match c1, c2, h with ._, ._, ⟨s, S, SS, rfl, rfl⟩ := begin
clear _match h h,
apply wseq.cases_on s _ (λ a s, _) (λ s, _); simp,
{ apply wseq.cases_on S _ (λ s S, _) (λ S, _); simp,
{ apply wseq.cases_on SS _ (λ S SS, _) (λ SS, _); simp,
{ refine ⟨nil, S, SS, _, _⟩; simp },
{ refine ⟨nil, nil, SS, _, _⟩; simp } },
{ exact ⟨s, S, SS, rfl, rfl⟩ },
{ refine ⟨nil, S, SS, _, _⟩; simp } },
{ exact ⟨s, S, SS, rfl, rfl⟩ },
{ exact ⟨s, S, SS, rfl, rfl⟩ }
end end
end
@[simp] theorem bind_assoc (s : wseq α) (f : α → wseq β) (g : β → wseq γ) :
bind (bind s f) g ~ bind s (λ (x : α), bind (f x) g) :=
begin
simp [bind], rw [← map_comp f (map g), map_comp (map g ∘ f) join],
apply join_join
end
instance : monad wseq :=
{ map := @map,
pure := @ret,
bind := @bind }
/-
Unfortunately, wseq is not a lawful monad, because it does not satisfy
the monad laws exactly, only up to sequence equivalence.
Furthermore, even quotienting by the equivalence is not sufficient,
because the join operation involves lists of quotient elements,
with a lifted equivalence relation, and pure quotients cannot handle
this type of construction.
instance : is_lawful_monad wseq :=
{ id_map := @map_id,
bind_pure_comp_eq_map := @bind_ret,
pure_bind := @ret_bind,
bind_assoc := @bind_assoc }
-/
end wseq
|
c51c7d72e07ae1897eb76f3f58386dfe8a539789 | 4d2583807a5ac6caaffd3d7a5f646d61ca85d532 | /src/analysis/convex/quasiconvex.lean | d06a29bc4695bc9a9f85b007c09c76c6653fb100 | [
"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 | 7,894 | lean | /-
Copyright (c) 2021 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import analysis.convex.function
/-!
# Quasiconvex and quasiconcave functions
This file defines quasiconvexity, quasiconcavity and quasilinearity of functions, which are
generalizations of unimodality and monotonicity. Convexity implies quasiconvexity, concavity implies
quasiconcavity, and monotonicity implies quasilinearity.
## Main declarations
* `quasiconvex_on 𝕜 s f`: Quasiconvexity of the function `f` on the set `s` with scalars `𝕜`. This
means that, for all `r`, `{x ∈ s | f x ≤ r}` is `𝕜`-convex.
* `quasiconcave_on 𝕜 s f`: Quasiconcavity of the function `f` on the set `s` with scalars `𝕜`. This
means that, for all `r`, `{x ∈ s | r ≤ f x}` is `𝕜`-convex.
* `quasilinear_on 𝕜 s f`: Quasilinearity of the function `f` on the set `s` with scalars `𝕜`. This
means that `f` is both quasiconvex and quasiconcave.
## TODO
Prove that a quasilinear function between two linear orders is either monotone or antitone. This is
not hard but quite a pain to go about as there are many cases to consider.
## References
* https://en.wikipedia.org/wiki/Quasiconvex_function
-/
open set
variables {𝕜 E F β : Type*}
section ordered_semiring
variables [ordered_semiring 𝕜]
section add_comm_monoid
variables [add_comm_monoid E] [add_comm_monoid F]
section ordered_add_comm_monoid
variables (𝕜) [ordered_add_comm_monoid β] [has_scalar 𝕜 E] (s : set E) (f : E → β)
/-- A function is quasiconvex if all its sublevels are convex.
This means that, for all `r`, `{x ∈ s | f x ≤ r}` is `𝕜`-convex. -/
def quasiconvex_on : Prop :=
∀ r, convex 𝕜 {x ∈ s | f x ≤ r}
/-- A function is quasiconcave if all its superlevels are convex.
This means that, for all `r`, `{x ∈ s | r ≤ f x}` is `𝕜`-convex. -/
def quasiconcave_on : Prop :=
∀ r, convex 𝕜 {x ∈ s | r ≤ f x}
/-- A function is quasilinear if it is both quasiconvex and quasiconcave.
This means that, for all `r`,
the sets `{x ∈ s | f x ≤ r}` and `{x ∈ s | r ≤ f x}` are `𝕜`-convex. -/
def quasilinear_on : Prop :=
quasiconvex_on 𝕜 s f ∧ quasiconcave_on 𝕜 s f
variables {𝕜 s f}
lemma quasiconvex_on.dual (hf : quasiconvex_on 𝕜 s f) :
@quasiconcave_on 𝕜 E (order_dual β) _ _ _ _ s f :=
hf
lemma quasiconcave_on.dual (hf : quasiconcave_on 𝕜 s f) :
@quasiconvex_on 𝕜 E (order_dual β) _ _ _ _ s f :=
hf
lemma quasilinear_on.dual (hf : quasilinear_on 𝕜 s f) :
@quasilinear_on 𝕜 E (order_dual β) _ _ _ _ s f :=
⟨hf.2, hf.1⟩
lemma convex.quasiconvex_on_of_convex_le (hs : convex 𝕜 s) (h : ∀ r, convex 𝕜 {x | f x ≤ r}) :
quasiconvex_on 𝕜 s f :=
λ r, hs.inter (h r)
lemma convex.quasiconcave_on_of_convex_ge (hs : convex 𝕜 s) (h : ∀ r, convex 𝕜 {x | r ≤ f x}) :
quasiconcave_on 𝕜 s f :=
@convex.quasiconvex_on_of_convex_le 𝕜 E (order_dual β) _ _ _ _ _ _ hs h
end ordered_add_comm_monoid
section linear_ordered_add_comm_monoid
variables [linear_ordered_add_comm_monoid β]
section has_scalar
variables [has_scalar 𝕜 E] {s : set E} {f g : E → β}
-- This only requires `directed_order β` but we don't have `directed_ordered_add_comm_monoid`
lemma quasiconvex_on.convex (hf : quasiconvex_on 𝕜 s f) : convex 𝕜 s :=
λ x y hx hy a b ha hb hab, (hf _ ⟨hx, le_max_left _ _⟩ ⟨hy, le_max_right _ _⟩ ha hb hab).1
lemma quasiconcave_on.convex (hf : quasiconcave_on 𝕜 s f) : convex 𝕜 s :=
hf.dual.convex
lemma quasiconvex_on.sup (hf : quasiconvex_on 𝕜 s f) (hg : quasiconvex_on 𝕜 s g) :
quasiconvex_on 𝕜 s (f ⊔ g) :=
begin
intro r,
simp_rw [pi.sup_def, sup_le_iff, ←set.sep_inter_sep],
exact (hf r).inter (hg r),
end
lemma quasiconcave_on.inf (hf : quasiconcave_on 𝕜 s f) (hg : quasiconcave_on 𝕜 s g) :
quasiconcave_on 𝕜 s (f ⊓ g) :=
hf.dual.sup hg
lemma quasiconvex_on_iff_le_max :
quasiconvex_on 𝕜 s f ↔ convex 𝕜 s ∧
∀ ⦃x y : E⦄, x ∈ s → y ∈ s → ∀ ⦃a b : 𝕜⦄, 0 ≤ a → 0 ≤ b → a + b = 1 →
f (a • x + b • y) ≤ max (f x) (f y) :=
⟨λ hf, ⟨hf.convex, λ x y hx hy a b ha hb hab,
(hf _ ⟨hx, le_max_left _ _⟩ ⟨hy, le_max_right _ _⟩ ha hb hab).2⟩,
λ hf r x y hx hy a b ha hb hab,
⟨hf.1 hx.1 hy.1 ha hb hab, (hf.2 hx.1 hy.1 ha hb hab).trans $ max_le hx.2 hy.2⟩⟩
lemma quasiconcave_on_iff_min_le :
quasiconcave_on 𝕜 s f ↔ convex 𝕜 s ∧
∀ ⦃x y : E⦄, x ∈ s → y ∈ s → ∀ ⦃a b : 𝕜⦄, 0 ≤ a → 0 ≤ b → a + b = 1 →
min (f x) (f y) ≤ f (a • x + b • y) :=
@quasiconvex_on_iff_le_max 𝕜 E (order_dual β) _ _ _ _ _ _
lemma quasilinear_on_iff_mem_interval :
quasilinear_on 𝕜 s f ↔ convex 𝕜 s ∧
∀ ⦃x y : E⦄, x ∈ s → y ∈ s → ∀ ⦃a b : 𝕜⦄, 0 ≤ a → 0 ≤ b → a + b = 1 →
f (a • x + b • y) ∈ interval (f x) (f y) :=
begin
rw [quasilinear_on, quasiconvex_on_iff_le_max, quasiconcave_on_iff_min_le, and_and_and_comm,
and_self],
apply and_congr_right',
simp_rw [←forall_and_distrib, interval, mem_Icc, and_comm],
end
lemma quasiconvex_on.convex_lt (hf : quasiconvex_on 𝕜 s f) (r : β) : convex 𝕜 {x ∈ s | f x < r} :=
begin
refine λ x y hx hy a b ha hb hab, _,
have h := hf _ ⟨hx.1, le_max_left _ _⟩ ⟨hy.1, le_max_right _ _⟩ ha hb hab,
exact ⟨h.1, h.2.trans_lt $ max_lt hx.2 hy.2⟩,
end
lemma quasiconcave_on.convex_gt (hf : quasiconcave_on 𝕜 s f) (r : β) : convex 𝕜 {x ∈ s | r < f x} :=
hf.dual.convex_lt r
end has_scalar
section ordered_smul
variables [has_scalar 𝕜 E] [module 𝕜 β] [ordered_smul 𝕜 β] {s : set E} {f : E → β}
lemma convex_on.quasiconvex_on (hf : convex_on 𝕜 s f) : quasiconvex_on 𝕜 s f :=
hf.convex_le
lemma concave_on.quasiconcave_on (hf : concave_on 𝕜 s f) : quasiconcave_on 𝕜 s f :=
hf.convex_ge
end ordered_smul
end linear_ordered_add_comm_monoid
end add_comm_monoid
section linear_ordered_add_comm_monoid
variables [linear_ordered_add_comm_monoid E] [ordered_add_comm_monoid β] [module 𝕜 E]
[ordered_smul 𝕜 E] {s : set E} {f : E → β}
lemma monotone_on.quasiconvex_on (hf : monotone_on f s) (hs : convex 𝕜 s) : quasiconvex_on 𝕜 s f :=
hf.convex_le hs
lemma monotone_on.quasiconcave_on (hf : monotone_on f s) (hs : convex 𝕜 s) :
quasiconcave_on 𝕜 s f :=
hf.convex_ge hs
lemma monotone_on.quasilinear_on (hf : monotone_on f s) (hs : convex 𝕜 s) : quasilinear_on 𝕜 s f :=
⟨hf.quasiconvex_on hs, hf.quasiconcave_on hs⟩
lemma antitone_on.quasiconvex_on (hf : antitone_on f s) (hs : convex 𝕜 s) : quasiconvex_on 𝕜 s f :=
hf.convex_le hs
lemma antitone_on.quasiconcave_on (hf : antitone_on f s) (hs : convex 𝕜 s) :
quasiconcave_on 𝕜 s f :=
hf.convex_ge hs
lemma antitone_on.quasilinear_on (hf : antitone_on f s) (hs : convex 𝕜 s) : quasilinear_on 𝕜 s f :=
⟨hf.quasiconvex_on hs, hf.quasiconcave_on hs⟩
lemma monotone.quasiconvex_on (hf : monotone f) : quasiconvex_on 𝕜 univ f :=
(hf.monotone_on _).quasiconvex_on convex_univ
lemma monotone.quasiconcave_on (hf : monotone f) : quasiconcave_on 𝕜 univ f :=
(hf.monotone_on _).quasiconcave_on convex_univ
lemma monotone.quasilinear_on (hf : monotone f) : quasilinear_on 𝕜 univ f :=
⟨hf.quasiconvex_on, hf.quasiconcave_on⟩
lemma antitone.quasiconvex_on (hf : antitone f) : quasiconvex_on 𝕜 univ f :=
(hf.antitone_on _).quasiconvex_on convex_univ
lemma antitone.quasiconcave_on (hf : antitone f) : quasiconcave_on 𝕜 univ f :=
(hf.antitone_on _).quasiconcave_on convex_univ
lemma antitone.quasilinear_on (hf : antitone f) : quasilinear_on 𝕜 univ f :=
⟨hf.quasiconvex_on, hf.quasiconcave_on⟩
end linear_ordered_add_comm_monoid
end ordered_semiring
|
99445b4e1c76119c57481c5ff69085de4017b649 | 957a80ea22c5abb4f4670b250d55534d9db99108 | /tests/lean/run/over_subst.lean | f890b3557a2071a6cc56c756a479d34ee701b175 | [
"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 | 716 | lean | namespace experiment
namespace nat
constant nat : Type.{1}
constant add : nat → nat → nat
constant le : nat → nat → Prop
constant one : nat
infixl `+` := add
infix `≤` := le
axiom add_assoc (a b c : nat) : (a + b) + c = a + (b + c)
axiom add_le_left {a b : nat} (H : a ≤ b) (c : nat) : c + a ≤ c + b
end nat
namespace int
constant int : Type.{1}
constant add : int → int → int
constant le : int → int → Prop
constant one1 : int
infixl `+` := add
infix `≤` := le
axiom add_assoc (a b c : int) : (a + b) + c = a + (b + c)
axiom add_le_left {a b : int} (H : a ≤ b) (c : int) : c + a ≤ c + b
noncomputable definition lt (a b : int) := a + one1 ≤ b
infix `<` := lt
end int
end experiment
|
86ff4a46ec7527ef8daa7095192798ef2c0e6f1f | ac92829298855d39b757cf1fddca8f058436f027 | /hott/function.hlean | a63df8e540167404992f1bbf30bd2b1c8a90aa11 | [
"Apache-2.0"
] | permissive | avigad/lean2 | 7af27190b9697b69a13268a133c1d3c8df85d2cf | 34dbd6c3ae612186b8f0f80d12fbf5ae7a059ec9 | refs/heads/master | 1,592,027,477,851 | 1,500,732,234,000 | 1,500,732,234,000 | 75,484,066 | 0 | 0 | null | 1,480,781,056,000 | 1,480,781,056,000 | null | UTF-8 | Lean | false | false | 14,190 | hlean | /-
Copyright (c) 2015 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Floris van Doorn
Ported from Coq HoTT
Theorems about embeddings and surjections
-/
import hit.trunc types.equiv cubical.square types.nat
open equiv sigma sigma.ops eq trunc is_trunc pi is_equiv fiber prod pointed nat
variables {A B C : Type} (f f' : A → B) {b : B}
/- the image of a map is the (-1)-truncated fiber -/
definition image' [constructor] (f : A → B) (b : B) : Type := ∥ fiber f b ∥
definition is_prop_image' [instance] (f : A → B) (b : B) : is_prop (image' f b) := !is_trunc_trunc
definition image [constructor] (f : A → B) (b : B) : Prop := Prop.mk (image' f b) _
definition total_image {A B : Type} (f : A → B) : Type := sigma (image f)
definition is_embedding [class] (f : A → B) := Π(a a' : A), is_equiv (ap f : a = a' → f a = f a')
definition is_surjective [class] (f : A → B) := Π(b : B), image f b
definition is_split_surjective [class] (f : A → B) := Π(b : B), fiber f b
structure is_retraction [class] (f : A → B) :=
(sect : B → A)
(right_inverse : Π(b : B), f (sect b) = b)
structure is_section [class] (f : A → B) :=
(retr : B → A)
(left_inverse : Π(a : A), retr (f a) = a)
definition is_weakly_constant [class] (f : A → B) := Π(a a' : A), f a = f a'
structure is_constant [class] (f : A → B) :=
(pt : B)
(eq : Π(a : A), f a = pt)
structure is_conditionally_constant [class] (f : A → B) :=
(g : ∥A∥ → B)
(eq : Π(a : A), f a = g (tr a))
section image
protected definition image.mk [constructor] {f : A → B} {b : B} (a : A) (p : f a = b)
: image f b :=
tr (fiber.mk a p)
protected definition image.rec [unfold 8] [recursor 8] {f : A → B} {b : B} {P : image' f b → Type}
[H : Πv, is_prop (P v)] (H : Π(a : A) (p : f a = b), P (image.mk a p)) (v : image' f b) : P v :=
begin unfold [image'] at *, induction v with v, induction v with a p, exact H a p end
definition image.elim {A B : Type} {f : A → B} {C : Type} [is_prop C] {b : B}
(H : image f b) (H' : ∀ (a : A), f a = b → C) : C :=
begin
refine (trunc.elim _ H),
intro H'', cases H'' with a Ha, exact H' a Ha
end
definition image.equiv_exists {A B : Type} {f : A → B} {b : B} : image f b ≃ ∃ a, f a = b :=
trunc_equiv_trunc _ (fiber.sigma_char _ _)
definition image_pathover {f : A → B} {x y : B} (p : x = y) (u : image f x) (v : image f y) :
u =[p] v :=
!is_prop.elimo
/- total_image.elim_set is in hit.prop_trunc to avoid dependency cycle -/
end image
namespace function
abbreviation sect [unfold 4] := @is_retraction.sect
abbreviation right_inverse [unfold 4] := @is_retraction.right_inverse
abbreviation retr [unfold 4] := @is_section.retr
abbreviation left_inverse [unfold 4] := @is_section.left_inverse
definition is_equiv_ap_of_embedding [instance] [H : is_embedding f] (a a' : A)
: is_equiv (ap f : a = a' → f a = f a') :=
H a a'
definition ap_inv_idp {a : A} {H : is_equiv (ap f : a = a → f a = f a)}
: (ap f)⁻¹ᶠ idp = idp :> a = a :=
!left_inv
variable {f}
definition is_injective_of_is_embedding [reducible] [H : is_embedding f] {a a' : A}
: f a = f a' → a = a' :=
(ap f)⁻¹
definition is_embedding_of_is_injective [HA : is_set A] [HB : is_set B]
(H : Π(a a' : A), f a = f a' → a = a') : is_embedding f :=
begin
intro a a',
fapply adjointify,
{exact (H a a')},
{intro p, apply is_set.elim},
{intro p, apply is_set.elim}
end
variable (f)
definition is_prop_is_embedding [instance] : is_prop (is_embedding f) :=
by unfold is_embedding; exact _
definition is_embedding_equiv_is_injective [HA : is_set A] [HB : is_set B]
: is_embedding f ≃ (Π(a a' : A), f a = f a' → a = a') :=
begin
fapply equiv.MK,
{ apply @is_injective_of_is_embedding},
{ apply is_embedding_of_is_injective},
{ intro H, apply is_prop.elim},
{ intro H, apply is_prop.elim, }
end
definition is_prop_fiber_of_is_embedding [H : is_embedding f] (b : B) :
is_prop (fiber f b) :=
begin
apply is_prop.mk, intro v w,
induction v with a p, induction w with a' q, induction q,
fapply fiber_eq,
{ esimp, apply is_injective_of_is_embedding p},
{ esimp [is_injective_of_is_embedding], symmetry, apply right_inv}
end
definition is_prop_fun_of_is_embedding [H : is_embedding f] : is_trunc_fun -1 f :=
is_prop_fiber_of_is_embedding f
definition is_embedding_of_is_prop_fun [constructor] [H : is_trunc_fun -1 f] : is_embedding f :=
begin
intro a a', fapply adjointify,
{ intro p, exact ap point (@is_prop.elim (fiber f (f a')) _ (fiber.mk a p) (fiber.mk a' idp))},
{ intro p, rewrite [-ap_compose], esimp, apply ap_con_eq (@point_eq _ _ f (f a'))},
{ intro p, induction p, apply ap (ap point), apply is_prop_elim_self}
end
variable {f}
definition is_surjective_rec_on {P : Type} (H : is_surjective f) (b : B) [Pt : is_prop P]
(IH : fiber f b → P) : P :=
trunc.rec_on (H b) IH
variable (f)
definition is_surjective_of_is_split_surjective [instance] [H : is_split_surjective f]
: is_surjective f :=
λb, tr (H b)
definition is_prop_is_surjective [instance] : is_prop (is_surjective f) :=
begin unfold is_surjective, exact _ end
definition is_surjective_cancel_right {A B C : Type} (g : B → C) (f : A → B)
[H : is_surjective (g ∘ f)] : is_surjective g :=
begin
intro c,
induction H c with a p,
exact tr (fiber.mk (f a) p)
end
definition is_weakly_constant_ap [instance] [H : is_weakly_constant f] (a a' : A) :
is_weakly_constant (ap f : a = a' → f a = f a') :=
take p q : a = a',
have Π{b c : A} {r : b = c}, (H a b)⁻¹ ⬝ H a c = ap f r, from
(λb c r, eq.rec_on r !con.left_inv),
this⁻¹ ⬝ this
definition is_constant_ap [unfold 4] [instance] [H : is_constant f] (a a' : A)
: is_constant (ap f : a = a' → f a = f a') :=
begin
induction H with b q,
fapply is_constant.mk,
{ exact q a ⬝ (q a')⁻¹},
{ intro p, induction p, exact !con.right_inv⁻¹}
end
definition is_contr_is_retraction [instance] [H : is_equiv f] : is_contr (is_retraction f) :=
begin
have H2 : (Σ(g : B → A), Πb, f (g b) = b) ≃ is_retraction f,
begin
fapply equiv.MK,
{intro x, induction x with g p, constructor, exact p},
{intro h, induction h, apply sigma.mk, assumption},
{intro h, induction h, reflexivity},
{intro x, induction x, reflexivity},
end,
apply is_trunc_equiv_closed, exact H2,
apply is_equiv.is_contr_right_inverse
end
definition is_contr_is_section [instance] [H : is_equiv f] : is_contr (is_section f) :=
begin
have H2 : (Σ(g : B → A), Πa, g (f a) = a) ≃ is_section f,
begin
fapply equiv.MK,
{intro x, induction x with g p, constructor, exact p},
{intro h, induction h, apply sigma.mk, assumption},
{intro h, induction h, reflexivity},
{intro x, induction x, reflexivity},
end,
apply is_trunc_equiv_closed, exact H2,
fapply is_trunc_equiv_closed,
{apply sigma_equiv_sigma_right, intro g, apply eq_equiv_homotopy},
fapply is_trunc_equiv_closed,
{apply fiber.sigma_char},
fapply is_contr_fiber_of_is_equiv,
exact to_is_equiv (arrow_equiv_arrow_left_rev A (equiv.mk f H)),
end
definition is_embedding_of_is_equiv [instance] [H : is_equiv f] : is_embedding f :=
λa a', _
definition is_equiv_of_is_surjective_of_is_embedding
[H : is_embedding f] [H' : is_surjective f] : is_equiv f :=
@is_equiv_of_is_contr_fun _ _ _
(λb, is_surjective_rec_on H' b
(λa, is_contr.mk a
(λa',
fiber_eq ((ap f)⁻¹ ((point_eq a) ⬝ (point_eq a')⁻¹))
(by rewrite (right_inv (ap f)); rewrite inv_con_cancel_right))))
definition is_split_surjective_of_is_retraction [H : is_retraction f] : is_split_surjective f :=
λb, fiber.mk (sect f b) (right_inverse f b)
definition is_constant_compose_point [constructor] [instance] (b : B)
: is_constant (f ∘ point : fiber f b → B) :=
is_constant.mk b (λv, by induction v with a p;exact p)
definition is_embedding_of_is_prop_fiber [H : Π(b : B), is_prop (fiber f b)] : is_embedding f :=
is_embedding_of_is_prop_fun _
definition is_retraction_of_is_equiv [instance] [H : is_equiv f] : is_retraction f :=
is_retraction.mk f⁻¹ (right_inv f)
definition is_section_of_is_equiv [instance] [H : is_equiv f] : is_section f :=
is_section.mk f⁻¹ (left_inv f)
definition is_equiv_of_is_section_of_is_retraction [H1 : is_retraction f] [H2 : is_section f]
: is_equiv f :=
let g := sect f in let h := retr f in
adjointify f
g
(right_inverse f)
(λa, calc
g (f a) = h (f (g (f a))) : left_inverse
... = h (f a) : right_inverse f
... = a : left_inverse)
section
local attribute is_equiv_of_is_section_of_is_retraction [instance] [priority 10000]
local attribute trunctype.struct [instance] [priority 1] -- remove after #842 is closed
variable (f)
definition is_prop_is_retraction_prod_is_section : is_prop (is_retraction f × is_section f) :=
begin
apply is_prop_of_imp_is_contr, intro H, induction H with H1 H2,
exact _,
end
end
definition is_retraction_trunc_functor [instance] (r : A → B) [H : is_retraction r]
(n : trunc_index) : is_retraction (trunc_functor n r) :=
is_retraction.mk
(trunc_functor n (sect r))
(λb,
((trunc_functor_compose n (sect r) r) b)⁻¹
⬝ trunc_homotopy n (right_inverse r) b
⬝ trunc_functor_id n B b)
-- Lemma 3.11.7
definition is_contr_retract (r : A → B) [H : is_retraction r] : is_contr A → is_contr B :=
begin
intro CA,
apply is_contr.mk (r (center A)),
intro b,
exact ap r (center_eq (is_retraction.sect r b)) ⬝ (is_retraction.right_inverse r b)
end
local attribute is_prop_is_retraction_prod_is_section [instance]
definition is_retraction_prod_is_section_equiv_is_equiv [constructor]
: (is_retraction f × is_section f) ≃ is_equiv f :=
begin
apply equiv_of_is_prop,
intro H, induction H, apply is_equiv_of_is_section_of_is_retraction,
intro H, split, repeat exact _
end
definition is_retraction_equiv_is_split_surjective :
is_retraction f ≃ is_split_surjective f :=
begin
fapply equiv.MK,
{ intro H, induction H with g p, intro b, constructor, exact p b},
{ intro H, constructor, intro b, exact point_eq (H b)},
{ intro H, esimp, apply eq_of_homotopy, intro b, esimp, induction H b, reflexivity},
{ intro H, induction H with g p, reflexivity},
end
definition is_embedding_compose (g : B → C) (f : A → B)
(H₁ : is_embedding g) (H₂ : is_embedding f) : is_embedding (g ∘ f) :=
begin
intros, apply @(is_equiv.homotopy_closed (ap g ∘ ap f)),
{ apply is_equiv_compose},
symmetry, exact ap_compose g f
end
definition is_surjective_compose (g : B → C) (f : A → B)
(H₁ : is_surjective g) (H₂ : is_surjective f) : is_surjective (g ∘ f) :=
begin
intro c, induction H₁ c with b p, induction H₂ b with a q,
exact image.mk a (ap g q ⬝ p)
end
definition is_split_surjective_compose (g : B → C) (f : A → B)
(H₁ : is_split_surjective g) (H₂ : is_split_surjective f) : is_split_surjective (g ∘ f) :=
begin
intro c, induction H₁ c with b p, induction H₂ b with a q,
exact fiber.mk a (ap g q ⬝ p)
end
definition is_injective_compose (g : B → C) (f : A → B)
(H₁ : Π⦃b b'⦄, g b = g b' → b = b') (H₂ : Π⦃a a'⦄, f a = f a' → a = a')
⦃a a' : A⦄ (p : g (f a) = g (f a')) : a = a' :=
H₂ (H₁ p)
definition is_embedding_pr1 [instance] [constructor] {A : Type} (B : A → Type) [H : Π a, is_prop (B a)]
: is_embedding (@pr1 A B) :=
λv v', to_is_equiv (sigma_eq_equiv v v' ⬝e !sigma_equiv_of_is_contr_right)
variables {f f'}
definition is_embedding_homotopy_closed (p : f ~ f') (H : is_embedding f) : is_embedding f' :=
begin
intro a a', fapply is_equiv_of_equiv_of_homotopy,
exact equiv.mk (ap f) _ ⬝e equiv_eq_closed_left _ (p a) ⬝e equiv_eq_closed_right _ (p a'),
intro q, esimp, exact (eq_bot_of_square (transpose (natural_square p q)))⁻¹
end
definition is_embedding_homotopy_closed_rev (p : f' ~ f) (H : is_embedding f) : is_embedding f' :=
is_embedding_homotopy_closed p⁻¹ʰᵗʸ H
definition is_surjective_homotopy_closed (p : f ~ f') (H : is_surjective f) : is_surjective f' :=
begin
intro b, induction H b with a q,
exact image.mk a ((p a)⁻¹ ⬝ q)
end
definition is_surjective_homotopy_closed_rev (p : f' ~ f) (H : is_surjective f) :
is_surjective f' :=
is_surjective_homotopy_closed p⁻¹ʰᵗʸ H
definition is_equiv_ap1_gen_of_is_embedding {A B : Type} (f : A → B) [is_embedding f]
{a a' : A} {b b' : B} (q : f a = b) (q' : f a' = b') : is_equiv (ap1_gen f q q') :=
begin
induction q, induction q',
exact is_equiv.homotopy_closed _ (ap1_gen_idp_left f)⁻¹ʰᵗʸ,
end
definition is_equiv_ap1_of_is_embedding {A B : Type*} (f : A →* B) [is_embedding f] :
is_equiv (Ω→ f) :=
is_equiv_ap1_gen_of_is_embedding f (respect_pt f) (respect_pt f)
definition loop_pequiv_loop_of_is_embedding [constructor] {A B : Type*} (f : A →* B)
[is_embedding f] : Ω A ≃* Ω B :=
pequiv_of_pmap (Ω→ f) (is_equiv_ap1_of_is_embedding f)
definition loopn_pequiv_loopn_of_is_embedding [constructor] (n : ℕ) [H : is_succ n]
{A B : Type*} (f : A →* B) [is_embedding f] : Ω[n] A ≃* Ω[n] B :=
begin
induction H with n,
exact !loopn_succ_in ⬝e*
loopn_pequiv_loopn n (loop_pequiv_loop_of_is_embedding f) ⬝e*
!loopn_succ_in⁻¹ᵉ*
end
/-
The definitions
is_surjective_of_is_equiv
is_equiv_equiv_is_embedding_times_is_surjective
are in types.trunc
See types.arrow_2 for retractions
-/
end function
|
160367cee13f4771cc1053a2243043bfb48dd0ba | 4d2583807a5ac6caaffd3d7a5f646d61ca85d532 | /src/topology/homeomorph.lean | 55694eb69dc74b9f90f101e72c3610caa558f097 | [
"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 | 17,424 | lean | /-
Copyright (c) 2019 Reid Barton. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Patrick Massot, Sébastien Gouëzel, Zhouhang Zhou, Reid Barton
-/
import topology.dense_embedding
import data.equiv.fin
/-!
# Homeomorphisms
This file defines homeomorphisms between two topological spaces. They are bijections with both
directions continuous. We denote homeomorphisms with the notation `≃ₜ`.
# Main definitions
* `homeomorph α β`: The type of homeomorphisms from `α` to `β`.
This type can be denoted using the following notation: `α ≃ₜ β`.
# Main results
* Pretty much every topological property is preserved under homeomorphisms.
* `homeomorph.homeomorph_of_continuous_open`: A continuous bijection that is
an open map is a homeomorphism.
-/
open set filter
open_locale topological_space
variables {α : Type*} {β : Type*} {γ : Type*} {δ : Type*}
/-- Homeomorphism between `α` and `β`, also called topological isomorphism -/
@[nolint has_inhabited_instance] -- not all spaces are homeomorphic to each other
structure homeomorph (α : Type*) (β : Type*) [topological_space α] [topological_space β]
extends α ≃ β :=
(continuous_to_fun : continuous to_fun . tactic.interactive.continuity')
(continuous_inv_fun : continuous inv_fun . tactic.interactive.continuity')
infix ` ≃ₜ `:25 := homeomorph
namespace homeomorph
variables [topological_space α] [topological_space β] [topological_space γ] [topological_space δ]
instance : has_coe_to_fun (α ≃ₜ β) (λ _, α → β) := ⟨λe, e.to_equiv⟩
@[simp] lemma homeomorph_mk_coe (a : equiv α β) (b c) :
((homeomorph.mk a b c) : α → β) = a :=
rfl
@[simp] lemma coe_to_equiv (h : α ≃ₜ β) : ⇑h.to_equiv = h := rfl
/-- Inverse of a homeomorphism. -/
protected def symm (h : α ≃ₜ β) : β ≃ₜ α :=
{ continuous_to_fun := h.continuous_inv_fun,
continuous_inv_fun := h.continuous_to_fun,
to_equiv := h.to_equiv.symm }
/-- See Note [custom simps projection]. We need to specify this projection explicitly in this case,
because it is a composition of multiple projections. -/
def simps.apply (h : α ≃ₜ β) : α → β := h
/-- See Note [custom simps projection] -/
def simps.symm_apply (h : α ≃ₜ β) : β → α := h.symm
initialize_simps_projections homeomorph
(to_equiv_to_fun → apply, to_equiv_inv_fun → symm_apply, -to_equiv)
lemma to_equiv_injective : function.injective (to_equiv : α ≃ₜ β → α ≃ β)
| ⟨e, h₁, h₂⟩ ⟨e', h₁', h₂'⟩ rfl := rfl
@[ext] lemma ext {h h' : α ≃ₜ β} (H : ∀ x, h x = h' x) : h = h' :=
to_equiv_injective $ equiv.ext H
/-- Identity map as a homeomorphism. -/
@[simps apply {fully_applied := ff}]
protected def refl (α : Type*) [topological_space α] : α ≃ₜ α :=
{ continuous_to_fun := continuous_id,
continuous_inv_fun := continuous_id,
to_equiv := equiv.refl α }
/-- Composition of two homeomorphisms. -/
protected def trans (h₁ : α ≃ₜ β) (h₂ : β ≃ₜ γ) : α ≃ₜ γ :=
{ continuous_to_fun := h₂.continuous_to_fun.comp h₁.continuous_to_fun,
continuous_inv_fun := h₁.continuous_inv_fun.comp h₂.continuous_inv_fun,
to_equiv := equiv.trans h₁.to_equiv h₂.to_equiv }
@[simp] lemma homeomorph_mk_coe_symm (a : equiv α β) (b c) :
((homeomorph.mk a b c).symm : β → α) = a.symm :=
rfl
@[simp] lemma refl_symm : (homeomorph.refl α).symm = homeomorph.refl α := rfl
@[continuity]
protected lemma continuous (h : α ≃ₜ β) : continuous h := h.continuous_to_fun
@[continuity] -- otherwise `by continuity` can't prove continuity of `h.to_equiv.symm`
protected lemma continuous_symm (h : α ≃ₜ β) : continuous (h.symm) := h.continuous_inv_fun
@[simp] lemma apply_symm_apply (h : α ≃ₜ β) (x : β) : h (h.symm x) = x :=
h.to_equiv.apply_symm_apply x
@[simp] lemma symm_apply_apply (h : α ≃ₜ β) (x : α) : h.symm (h x) = x :=
h.to_equiv.symm_apply_apply x
protected lemma bijective (h : α ≃ₜ β) : function.bijective h := h.to_equiv.bijective
protected lemma injective (h : α ≃ₜ β) : function.injective h := h.to_equiv.injective
protected lemma surjective (h : α ≃ₜ β) : function.surjective h := h.to_equiv.surjective
/-- Change the homeomorphism `f` to make the inverse function definitionally equal to `g`. -/
def change_inv (f : α ≃ₜ β) (g : β → α) (hg : function.right_inverse g f) : α ≃ₜ β :=
have g = f.symm, from funext (λ x, calc g x = f.symm (f (g x)) : (f.left_inv (g x)).symm
... = f.symm x : by rw hg x),
{ to_fun := f,
inv_fun := g,
left_inv := by convert f.left_inv,
right_inv := by convert f.right_inv,
continuous_to_fun := f.continuous,
continuous_inv_fun := by convert f.symm.continuous }
@[simp] lemma symm_comp_self (h : α ≃ₜ β) : ⇑h.symm ∘ ⇑h = id :=
funext h.symm_apply_apply
@[simp] lemma self_comp_symm (h : α ≃ₜ β) : ⇑h ∘ ⇑h.symm = id :=
funext h.apply_symm_apply
@[simp] lemma range_coe (h : α ≃ₜ β) : range h = univ :=
h.surjective.range_eq
lemma image_symm (h : α ≃ₜ β) : image h.symm = preimage h :=
funext h.symm.to_equiv.image_eq_preimage
lemma preimage_symm (h : α ≃ₜ β) : preimage h.symm = image h :=
(funext h.to_equiv.image_eq_preimage).symm
@[simp] lemma image_preimage (h : α ≃ₜ β) (s : set β) : h '' (h ⁻¹' s) = s :=
h.to_equiv.image_preimage s
@[simp] lemma preimage_image (h : α ≃ₜ β) (s : set α) : h ⁻¹' (h '' s) = s :=
h.to_equiv.preimage_image s
protected lemma inducing (h : α ≃ₜ β) : inducing h :=
inducing_of_inducing_compose h.continuous h.symm.continuous $
by simp only [symm_comp_self, inducing_id]
lemma induced_eq (h : α ≃ₜ β) : topological_space.induced h ‹_› = ‹_› := h.inducing.1.symm
protected lemma quotient_map (h : α ≃ₜ β) : quotient_map h :=
quotient_map.of_quotient_map_compose h.symm.continuous h.continuous $
by simp only [self_comp_symm, quotient_map.id]
lemma coinduced_eq (h : α ≃ₜ β) : topological_space.coinduced h ‹_› = ‹_› :=
h.quotient_map.2.symm
protected lemma embedding (h : α ≃ₜ β) : embedding h :=
⟨h.inducing, h.injective⟩
/-- Homeomorphism given an embedding. -/
noncomputable def of_embedding (f : α → β) (hf : embedding f) : α ≃ₜ (set.range f) :=
{ continuous_to_fun := continuous_subtype_mk _ hf.continuous,
continuous_inv_fun := by simp [hf.continuous_iff, continuous_subtype_coe],
.. equiv.of_injective f hf.inj }
protected lemma second_countable_topology [topological_space.second_countable_topology β]
(h : α ≃ₜ β) :
topological_space.second_countable_topology α :=
h.inducing.second_countable_topology
lemma compact_image {s : set α} (h : α ≃ₜ β) : is_compact (h '' s) ↔ is_compact s :=
h.embedding.is_compact_iff_is_compact_image.symm
lemma compact_preimage {s : set β} (h : α ≃ₜ β) : is_compact (h ⁻¹' s) ↔ is_compact s :=
by rw ← image_symm; exact h.symm.compact_image
lemma compact_space [compact_space α] (h : α ≃ₜ β) : compact_space β :=
{ compact_univ := by { rw [← image_univ_of_surjective h.surjective, h.compact_image],
apply compact_space.compact_univ } }
lemma t2_space [t2_space α] (h : α ≃ₜ β) : t2_space β :=
{ t2 :=
begin
intros x y hxy,
obtain ⟨u, v, hu, hv, hxu, hyv, huv⟩ := t2_separation (h.symm.injective.ne hxy),
refine ⟨h.symm ⁻¹' u, h.symm ⁻¹' v,
h.symm.continuous.is_open_preimage _ hu,
h.symm.continuous.is_open_preimage _ hv,
hxu, hyv, _⟩,
rw [← preimage_inter, huv, preimage_empty],
end }
protected lemma dense_embedding (h : α ≃ₜ β) : dense_embedding h :=
{ dense := h.surjective.dense_range,
.. h.embedding }
@[simp] lemma is_open_preimage (h : α ≃ₜ β) {s : set β} : is_open (h ⁻¹' s) ↔ is_open s :=
h.quotient_map.is_open_preimage
@[simp] lemma is_open_image (h : α ≃ₜ β) {s : set α} : is_open (h '' s) ↔ is_open s :=
by rw [← preimage_symm, is_open_preimage]
@[simp] lemma is_closed_preimage (h : α ≃ₜ β) {s : set β} : is_closed (h ⁻¹' s) ↔ is_closed s :=
by simp only [← is_open_compl_iff, ← preimage_compl, is_open_preimage]
@[simp] lemma is_closed_image (h : α ≃ₜ β) {s : set α} : is_closed (h '' s) ↔ is_closed s :=
by rw [← preimage_symm, is_closed_preimage]
lemma preimage_closure (h : α ≃ₜ β) (s : set β) : h ⁻¹' (closure s) = closure (h ⁻¹' s) :=
by rw [h.embedding.closure_eq_preimage_closure_image, h.image_preimage]
lemma image_closure (h : α ≃ₜ β) (s : set α) : h '' (closure s) = closure (h '' s) :=
by rw [← preimage_symm, preimage_closure]
protected lemma is_open_map (h : α ≃ₜ β) : is_open_map h := λ s, h.is_open_image.2
protected lemma is_closed_map (h : α ≃ₜ β) : is_closed_map h := λ s, h.is_closed_image.2
protected lemma closed_embedding (h : α ≃ₜ β) : closed_embedding h :=
closed_embedding_of_embedding_closed h.embedding h.is_closed_map
@[simp] lemma map_nhds_eq (h : α ≃ₜ β) (x : α) : map h (𝓝 x) = 𝓝 (h x) :=
h.embedding.map_nhds_of_mem _ (by simp)
lemma symm_map_nhds_eq (h : α ≃ₜ β) (x : α) : map h.symm (𝓝 (h x)) = 𝓝 x :=
by rw [h.symm.map_nhds_eq, h.symm_apply_apply]
lemma nhds_eq_comap (h : α ≃ₜ β) (x : α) : 𝓝 x = comap h (𝓝 (h x)) :=
h.embedding.to_inducing.nhds_eq_comap x
@[simp] lemma comap_nhds_eq (h : α ≃ₜ β) (y : β) : comap h (𝓝 y) = 𝓝 (h.symm y) :=
by rw [h.nhds_eq_comap, h.apply_symm_apply]
/-- If an bijective map `e : α ≃ β` is continuous and open, then it is a homeomorphism. -/
def homeomorph_of_continuous_open (e : α ≃ β) (h₁ : continuous e) (h₂ : is_open_map e) :
α ≃ₜ β :=
{ continuous_to_fun := h₁,
continuous_inv_fun := begin
rw continuous_def,
intros s hs,
convert ← h₂ s hs using 1,
apply e.image_eq_preimage
end,
to_equiv := e }
@[simp] lemma comp_continuous_on_iff (h : α ≃ₜ β) (f : γ → α) (s : set γ) :
continuous_on (h ∘ f) s ↔ continuous_on f s :=
h.inducing.continuous_on_iff.symm
@[simp] lemma comp_continuous_iff (h : α ≃ₜ β) {f : γ → α} :
continuous (h ∘ f) ↔ continuous f :=
h.inducing.continuous_iff.symm
@[simp] lemma comp_continuous_iff' (h : α ≃ₜ β) {f : β → γ} :
continuous (f ∘ h) ↔ continuous f :=
h.quotient_map.continuous_iff.symm
lemma comp_continuous_at_iff (h : α ≃ₜ β) (f : γ → α) (x : γ) :
continuous_at (h ∘ f) x ↔ continuous_at f x :=
h.inducing.continuous_at_iff.symm
lemma comp_continuous_at_iff' (h : α ≃ₜ β) (f : β → γ) (x : α) :
continuous_at (f ∘ h) x ↔ continuous_at f (h x) :=
h.inducing.continuous_at_iff' (by simp)
lemma comp_continuous_within_at_iff (h : α ≃ₜ β) (f : γ → α) (s : set γ) (x : γ) :
continuous_within_at f s x ↔ continuous_within_at (h ∘ f) s x :=
h.inducing.continuous_within_at_iff
@[simp] lemma comp_is_open_map_iff (h : α ≃ₜ β) {f : γ → α} :
is_open_map (h ∘ f) ↔ is_open_map f :=
begin
refine ⟨_, λ hf, h.is_open_map.comp hf⟩,
intros hf,
rw [← function.comp.left_id f, ← h.symm_comp_self, function.comp.assoc],
exact h.symm.is_open_map.comp hf,
end
@[simp] lemma comp_is_open_map_iff' (h : α ≃ₜ β) {f : β → γ} :
is_open_map (f ∘ h) ↔ is_open_map f :=
begin
refine ⟨_, λ hf, hf.comp h.is_open_map⟩,
intros hf,
rw [← function.comp.right_id f, ← h.self_comp_symm, ← function.comp.assoc],
exact hf.comp h.symm.is_open_map,
end
/-- If two sets are equal, then they are homeomorphic. -/
def set_congr {s t : set α} (h : s = t) : s ≃ₜ t :=
{ continuous_to_fun := continuous_subtype_mk _ continuous_subtype_val,
continuous_inv_fun := continuous_subtype_mk _ continuous_subtype_val,
to_equiv := equiv.set_congr h }
/-- Sum of two homeomorphisms. -/
def sum_congr (h₁ : α ≃ₜ β) (h₂ : γ ≃ₜ δ) : α ⊕ γ ≃ₜ β ⊕ δ :=
{ continuous_to_fun :=
begin
convert continuous_sum_rec (continuous_inl.comp h₁.continuous)
(continuous_inr.comp h₂.continuous),
ext x, cases x; refl,
end,
continuous_inv_fun :=
begin
convert continuous_sum_rec (continuous_inl.comp h₁.symm.continuous)
(continuous_inr.comp h₂.symm.continuous),
ext x, cases x; refl
end,
to_equiv := h₁.to_equiv.sum_congr h₂.to_equiv }
/-- Product of two homeomorphisms. -/
def prod_congr (h₁ : α ≃ₜ β) (h₂ : γ ≃ₜ δ) : α × γ ≃ₜ β × δ :=
{ continuous_to_fun := (h₁.continuous.comp continuous_fst).prod_mk
(h₂.continuous.comp continuous_snd),
continuous_inv_fun := (h₁.symm.continuous.comp continuous_fst).prod_mk
(h₂.symm.continuous.comp continuous_snd),
to_equiv := h₁.to_equiv.prod_congr h₂.to_equiv }
@[simp] lemma prod_congr_symm (h₁ : α ≃ₜ β) (h₂ : γ ≃ₜ δ) :
(h₁.prod_congr h₂).symm = h₁.symm.prod_congr h₂.symm := rfl
@[simp] lemma coe_prod_congr (h₁ : α ≃ₜ β) (h₂ : γ ≃ₜ δ) :
⇑(h₁.prod_congr h₂) = prod.map h₁ h₂ := rfl
section
variables (α β γ)
/-- `α × β` is homeomorphic to `β × α`. -/
def prod_comm : α × β ≃ₜ β × α :=
{ continuous_to_fun := continuous_snd.prod_mk continuous_fst,
continuous_inv_fun := continuous_snd.prod_mk continuous_fst,
to_equiv := equiv.prod_comm α β }
@[simp] lemma prod_comm_symm : (prod_comm α β).symm = prod_comm β α := rfl
@[simp] lemma coe_prod_comm : ⇑(prod_comm α β) = prod.swap := rfl
/-- `(α × β) × γ` is homeomorphic to `α × (β × γ)`. -/
def prod_assoc : (α × β) × γ ≃ₜ α × (β × γ) :=
{ continuous_to_fun := (continuous_fst.comp continuous_fst).prod_mk
((continuous_snd.comp continuous_fst).prod_mk continuous_snd),
continuous_inv_fun := (continuous_fst.prod_mk (continuous_fst.comp continuous_snd)).prod_mk
(continuous_snd.comp continuous_snd),
to_equiv := equiv.prod_assoc α β γ }
/-- `α × {*}` is homeomorphic to `α`. -/
@[simps apply {fully_applied := ff}]
def prod_punit : α × punit ≃ₜ α :=
{ to_equiv := equiv.prod_punit α,
continuous_to_fun := continuous_fst,
continuous_inv_fun := continuous_id.prod_mk continuous_const }
/-- `{*} × α` is homeomorphic to `α`. -/
def punit_prod : punit × α ≃ₜ α :=
(prod_comm _ _).trans (prod_punit _)
@[simp] lemma coe_punit_prod : ⇑(punit_prod α) = prod.snd := rfl
end
/-- `ulift α` is homeomorphic to `α`. -/
def {u v} ulift {α : Type u} [topological_space α] : ulift.{v u} α ≃ₜ α :=
{ continuous_to_fun := continuous_ulift_down,
continuous_inv_fun := continuous_ulift_up,
to_equiv := equiv.ulift }
section distrib
/-- `(α ⊕ β) × γ` is homeomorphic to `α × γ ⊕ β × γ`. -/
def sum_prod_distrib : (α ⊕ β) × γ ≃ₜ α × γ ⊕ β × γ :=
begin
refine (homeomorph.homeomorph_of_continuous_open (equiv.sum_prod_distrib α β γ).symm _ _).symm,
{ convert continuous_sum_rec
((continuous_inl.comp continuous_fst).prod_mk continuous_snd)
((continuous_inr.comp continuous_fst).prod_mk continuous_snd),
ext1 x, cases x; refl, },
{ exact (is_open_map_sum
(open_embedding_inl.prod open_embedding_id).is_open_map
(open_embedding_inr.prod open_embedding_id).is_open_map) }
end
/-- `α × (β ⊕ γ)` is homeomorphic to `α × β ⊕ α × γ`. -/
def prod_sum_distrib : α × (β ⊕ γ) ≃ₜ α × β ⊕ α × γ :=
(prod_comm _ _).trans $
sum_prod_distrib.trans $
sum_congr (prod_comm _ _) (prod_comm _ _)
variables {ι : Type*} {σ : ι → Type*} [Π i, topological_space (σ i)]
/-- `(Σ i, σ i) × β` is homeomorphic to `Σ i, (σ i × β)`. -/
def sigma_prod_distrib : ((Σ i, σ i) × β) ≃ₜ (Σ i, (σ i × β)) :=
homeomorph.symm $
homeomorph_of_continuous_open (equiv.sigma_prod_distrib σ β).symm
(continuous_sigma $ λ i,
(continuous_sigma_mk.comp continuous_fst).prod_mk continuous_snd)
(is_open_map_sigma $ λ i,
(open_embedding_sigma_mk.prod open_embedding_id).is_open_map)
end distrib
/-- If `ι` has a unique element, then `ι → α` is homeomorphic to `α`. -/
@[simps { fully_applied := ff }]
def fun_unique (ι α : Type*) [unique ι] [topological_space α] : (ι → α) ≃ₜ α :=
{ to_equiv := equiv.fun_unique ι α,
continuous_to_fun := continuous_apply _,
continuous_inv_fun := continuous_pi (λ _, continuous_id) }
/-- Homeomorphism between dependent functions `Π i : fin 2, α i` and `α 0 × α 1`. -/
@[simps { fully_applied := ff }]
def {u} pi_fin_two (α : fin 2 → Type u) [Π i, topological_space (α i)] : (Π i, α i) ≃ₜ α 0 × α 1 :=
{ to_equiv := pi_fin_two_equiv α,
continuous_to_fun := (continuous_apply 0).prod_mk (continuous_apply 1),
continuous_inv_fun := continuous_pi $ fin.forall_fin_two.2 ⟨continuous_fst, continuous_snd⟩ }
/-- Homeomorphism between `α² = fin 2 → α` and `α × α`. -/
@[simps { fully_applied := ff }] def fin_two_arrow : (fin 2 → α) ≃ₜ α × α :=
{ to_equiv := fin_two_arrow_equiv α, .. pi_fin_two (λ _, α) }
/--
A subset of a topological space is homeomorphic to its image under a homeomorphism.
-/
def image (e : α ≃ₜ β) (s : set α) : s ≃ₜ e '' s :=
{ continuous_to_fun := by continuity!,
continuous_inv_fun := by continuity!,
..e.to_equiv.image s, }
end homeomorph
|
a96a88d345a7329d1390973a7ccbb1f20c87f709 | fecda8e6b848337561d6467a1e30cf23176d6ad0 | /src/category_theory/is_connected.lean | 4e919a886e6982923de66193bfb060001e9ee63e | [
"Apache-2.0"
] | permissive | spolu/mathlib | bacf18c3d2a561d00ecdc9413187729dd1f705ed | 480c92cdfe1cf3c2d083abded87e82162e8814f4 | refs/heads/master | 1,671,684,094,325 | 1,600,736,045,000 | 1,600,736,045,000 | 297,564,749 | 1 | 0 | null | 1,600,758,368,000 | 1,600,758,367,000 | null | UTF-8 | Lean | false | false | 10,011 | lean | /-
Copyright (c) 2020 Bhavik Mehta. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Bhavik Mehta
-/
import data.list.chain
import category_theory.punit
/-!
# Connected category
Define a connected category as a _nonempty_ category for which every functor
to a discrete category is isomorphic to the constant functor.
NB. Some authors include the empty category as connected, we do not.
We instead are interested in categories with exactly one 'connected
component'.
We give some equivalent definitions:
- A nonempty category for which every functor to a discrete category is
constant on objects.
See `any_functor_const_on_obj` and `connected.of_any_functor_const_on_obj`.
- A nonempty category for which every function `F` for which the presence of a
morphism `f : j₁ ⟶ j₂` implies `F j₁ = F j₂` must be constant everywhere.
See `constant_of_preserves_morphisms` and `connected.of_constant_of_preserves_morphisms`.
- A nonempty category for which any subset of its elements containing the
default and closed under morphisms is everything.
See `induct_on_objects` and `connected.of_induct`.
- A nonempty category for which every object is related under the reflexive
transitive closure of the relation "there is a morphism in some direction
from `j₁` to `j₂`".
See `connected_zigzag` and `zigzag_connected`.
- A nonempty category for which for any two objects there is a sequence of
morphisms (some reversed) from one to the other.
See `exists_zigzag'` and `connected_of_zigzag`.
We also prove the result that the functor given by `(X × -)` preserves any
connected limit. That is, any limit of shape `J` where `J` is a connected
category is preserved by the functor `(X × -)`. This appears in `category_theory.limits.connected`.
-/
universes v₁ v₂ u₁ u₂
noncomputable theory
open category_theory.category
namespace category_theory
/--
A possibly empty category for which every functor to a discrete category is constant.
-/
class is_preconnected (J : Type v₂) [category.{v₁} J] : Prop :=
(iso_constant : Π {α : Type v₂} (F : J ⥤ discrete α) (j : J),
nonempty (F ≅ (functor.const J).obj (F.obj j)))
/--
We define a connected category as a _nonempty_ category for which every
functor to a discrete category is constant.
NB. Some authors include the empty category as connected, we do not.
We instead are interested in categories with exactly one 'connected
component'.
This allows us to show that the functor X ⨯ - preserves connected limits.
See https://stacks.math.columbia.edu/tag/002S
-/
class is_connected (J : Type v₂) [category.{v₁} J] extends is_preconnected J : Prop :=
[is_nonempty : nonempty J]
attribute [instance, priority 100] is_connected.is_nonempty
variables {J : Type v₂} [category.{v₁} J]
/--
If `J` is connected, any functor `F : J ⥤ discrete α` is isomorphic to
the constant functor with value `F.obj j` (for any choice of `j`).
-/
def iso_constant [is_preconnected J] {α : Type v₂} (F : J ⥤ discrete α) (j : J) :
F ≅ (functor.const J).obj (F.obj j) :=
(is_preconnected.iso_constant F j).some
/--
If J is connected, any functor to a discrete category is constant on objects.
The converse is given in `is_connected.of_any_functor_const_on_obj`.
-/
lemma any_functor_const_on_obj [is_preconnected J]
{α : Type v₂} (F : J ⥤ discrete α) (j j' : J) :
F.obj j = F.obj j' :=
((iso_constant F j').hom.app j).down.1
/--
If any functor to a discrete category is constant on objects, J is connected.
The converse of `any_functor_const_on_obj`.
-/
lemma is_connected.of_any_functor_const_on_obj [nonempty J]
(h : ∀ {α : Type v₂} (F : J ⥤ discrete α), ∀ (j j' : J), F.obj j = F.obj j') :
is_connected J :=
{ iso_constant := λ α F j',
⟨nat_iso.of_components (λ j, eq_to_iso (h F j j')) (λ _ _ _, subsingleton.elim _ _)⟩ }
/--
If `J` is connected, then given any function `F` such that the presence of a
morphism `j₁ ⟶ j₂` implies `F j₁ = F j₂`, we have that `F` is constant.
This can be thought of as a local-to-global property.
The converse is shown in `is_connected.of_constant_of_preserves_morphisms`
-/
lemma constant_of_preserves_morphisms [is_preconnected J] {α : Type v₂} (F : J → α)
(h : ∀ (j₁ j₂ : J) (f : j₁ ⟶ j₂), F j₁ = F j₂) (j j' : J) :
F j = F j' :=
any_functor_const_on_obj { obj := F, map := λ _ _ f, eq_to_hom (h _ _ f) } j j'
/--
`J` is connected if: given any function `F : J → α` which is constant for any
`j₁, j₂` for which there is a morphism `j₁ ⟶ j₂`, then `F` is constant.
This can be thought of as a local-to-global property.
The converse of `constant_of_preserves_morphisms`.
-/
lemma is_connected.of_constant_of_preserves_morphisms [nonempty J]
(h : ∀ {α : Type v₂} (F : J → α), (∀ {j₁ j₂ : J} (f : j₁ ⟶ j₂), F j₁ = F j₂) → (∀ j j' : J, F j = F j')) :
is_connected J :=
is_connected.of_any_functor_const_on_obj (λ _ F, h F.obj (λ _ _ f, (F.map f).down.1))
/--
An inductive-like property for the objects of a connected category.
If the set `p` is nonempty, and `p` is closed under morphisms of `J`,
then `p` contains all of `J`.
The converse is given in `is_connected.of_induct`.
-/
lemma induct_on_objects [is_preconnected J] (p : set J) {j₀ : J} (h0 : j₀ ∈ p)
(h1 : ∀ {j₁ j₂ : J} (f : j₁ ⟶ j₂), j₁ ∈ p ↔ j₂ ∈ p) (j : J) :
j ∈ p :=
begin
injection (constant_of_preserves_morphisms (λ k, ulift.up (k ∈ p)) (λ j₁ j₂ f, _) j j₀) with i,
rwa i,
dsimp,
exact congr_arg ulift.up (propext (h1 f)),
end
/--
If any maximal connected component containing some element j₀ of J is all of J, then J is connected.
The converse of `induct_on_objects`.
-/
lemma is_connected.of_induct [nonempty J]
{j₀ : J} (h : ∀ (p : set J), j₀ ∈ p → (∀ {j₁ j₂ : J} (f : j₁ ⟶ j₂), j₁ ∈ p ↔ j₂ ∈ p) → ∀ (j : J), j ∈ p) :
is_connected J :=
is_connected.of_constant_of_preserves_morphisms (λ α F a,
begin
have w := h {j | F j = F j₀} rfl (λ _ _ f, by simp [a f]),
dsimp at w,
intros j j',
rw [w j, w j'],
end)
/-- j₁ and j₂ are related by `zag` if there is a morphism between them. -/
@[reducible]
def zag (j₁ j₂ : J) : Prop := nonempty (j₁ ⟶ j₂) ∨ nonempty (j₂ ⟶ j₁)
/--
`j₁` and `j₂` are related by `zigzag` if there is a chain of
morphisms from `j₁` to `j₂`, with backward morphisms allowed.
-/
@[reducible]
def zigzag : J → J → Prop := relation.refl_trans_gen zag
/-- Any equivalence relation containing (⟶) holds for all pairs of a connected category. -/
lemma equiv_relation [is_connected J] (r : J → J → Prop) (hr : _root_.equivalence r)
(h : ∀ {j₁ j₂ : J} (f : j₁ ⟶ j₂), r j₁ j₂) :
∀ (j₁ j₂ : J), r j₁ j₂ :=
begin
have z : ∀ (j : J), r (classical.arbitrary J) j :=
induct_on_objects (λ k, r (classical.arbitrary J) k)
(hr.1 (classical.arbitrary J)) (λ _ _ f, ⟨λ t, hr.2.2 t (h f), λ t, hr.2.2 t (hr.2.1 (h f))⟩),
intros, apply hr.2.2 (hr.2.1 (z _)) (z _)
end
/-- In a connected category, any two objects are related by `zigzag`. -/
lemma is_connected_zigzag [is_connected J] (j₁ j₂ : J) : zigzag j₁ j₂ :=
equiv_relation _
(mk_equivalence _
relation.reflexive_refl_trans_gen
(relation.refl_trans_gen.symmetric (λ _ _ _, by rwa [zag, or_comm]))
relation.transitive_refl_trans_gen)
(λ _ _ f, relation.refl_trans_gen.single (or.inl (nonempty.intro f))) _ _
/--
If any two objects in an nonempty category are related by `zigzag`, the category is connected.
-/
lemma zigzag_is_connected [nonempty J] (h : ∀ (j₁ j₂ : J), zigzag j₁ j₂) : is_connected J :=
begin
apply is_connected.of_induct,
intros,
have: ∀ (j₁ j₂ : J), zigzag j₁ j₂ → (j₁ ∈ p ↔ j₂ ∈ p),
{ introv k,
induction k,
{ refl },
{ rw k_ih,
rcases k_a_1 with ⟨⟨_⟩⟩ | ⟨⟨_⟩⟩,
apply a_1 k_a_1,
apply (a_1 k_a_1).symm } },
rwa this j (classical.arbitrary J) (h _ _)
end
lemma exists_zigzag' [is_connected J] (j₁ j₂ : J) :
∃ l, list.chain zag j₁ l ∧ list.last (j₁ :: l) (list.cons_ne_nil _ _) = j₂ :=
list.exists_chain_of_relation_refl_trans_gen (is_connected_zigzag _ _)
/--
If any two objects in an nonempty category are linked by a sequence of (potentially reversed)
morphisms, then J is connected.
The converse of `exists_zigzag'`.
-/
lemma is_connected_of_zigzag [nonempty J]
(h : ∀ (j₁ j₂ : J), ∃ l, list.chain zag j₁ l ∧ list.last (j₁ :: l) (list.cons_ne_nil _ _) = j₂) :
is_connected J :=
begin
apply is_connected.of_induct,
intros p d k j,
obtain ⟨l, zags, lst⟩ := h j (classical.arbitrary J),
apply list.chain.induction p l zags lst _ d,
rintros _ _ (⟨⟨_⟩⟩ | ⟨⟨_⟩⟩),
{ exact (k a).2 },
{ exact (k a).1 }
end
/-- If `discrete α` is connected, then `α` is (type-)equivalent to `punit`. -/
def discrete_is_connected_equiv_punit {α : Type*} [is_connected (discrete α)] : α ≃ punit :=
discrete.equiv_of_equivalence
{ functor := functor.star α,
inverse := discrete.functor (λ _, classical.arbitrary _),
unit_iso := by { exact (iso_constant _ (classical.arbitrary _)), },
counit_iso := functor.punit_ext _ _ }
variables {C : Type u₂} [category.{v₂} C]
/--
For objects `X Y : C`, any natural transformation `α : const X ⟶ const Y` from a connected
category must be constant.
This is the key property of connected categories which we use to establish properties about limits.
-/
lemma nat_trans_from_is_connected [is_preconnected J] {X Y : C}
(α : (functor.const J).obj X ⟶ (functor.const J).obj Y) :
∀ (j j' : J), α.app j = (α.app j' : X ⟶ Y) :=
@constant_of_preserves_morphisms _ _ _
(X ⟶ Y)
(λ j, α.app j)
(λ _ _ f, (by { have := α.naturality f, erw [id_comp, comp_id] at this, exact this.symm }))
end category_theory
|
d8c0c599c593fb396dda0a6379f5728c7ad42c2c | 30b012bb72d640ec30c8fdd4c45fdfa67beb012c | /category_theory/functor_category.lean | a3aeea9b481b58723fd519b0f14943f70f158edb | [
"Apache-2.0"
] | permissive | kckennylau/mathlib | 21fb810b701b10d6606d9002a4004f7672262e83 | 47b3477e20ffb5a06588dd3abb01fe0fe3205646 | refs/heads/master | 1,634,976,409,281 | 1,542,042,832,000 | 1,542,319,733,000 | 109,560,458 | 0 | 0 | Apache-2.0 | 1,542,369,208,000 | 1,509,867,494,000 | Lean | UTF-8 | Lean | false | false | 2,262 | lean | -- Copyright (c) 2017 Scott Morrison. All rights reserved.
-- Released under Apache 2.0 license as described in the file LICENSE.
-- Authors: Tim Baumann, Stephen Morgan, Scott Morrison
import category_theory.natural_transformation
namespace category_theory
universes u₁ v₁ u₂ v₂ u₃ v₃
open nat_trans
/--
`functor.category C D` gives the category structure on functor and natural transformations between categories `C` and `D`.
Notice that if `C` and `D` are both small categories at the same universe level, this is another small category at that level.
However if `C` and `D` are both large categories at the same universe level, this is a small category at the next higher level.
-/
instance functor.category (C : Type u₁) [category.{u₁ v₁} C] (D : Type u₂) [category.{u₂ v₂} D] :
category.{(max u₁ v₁ u₂ v₂) (max u₁ v₂)} (C ⥤ D) :=
{ hom := λ F G, F ⟹ G,
id := λ F, nat_trans.id F,
comp := λ _ _ _ α β, α ⊟ β }
namespace functor.category
section
variables {C : Type u₁} [𝒞 : category.{u₁ v₁} C] {D : Type u₂} [𝒟 : category.{u₂ v₂} D]
include 𝒞 𝒟
@[simp] lemma id_app (F : C ⥤ D) (X : C) : (𝟙 F : F ⟹ F).app X = 𝟙 (F.obj X) := rfl
@[simp] lemma comp_app {F G H : C ⥤ D} (α : F ⟶ G) (β : G ⟶ H) (X : C) :
((α ≫ β) : F ⟹ H).app X = (α : F ⟹ G).app X ≫ (β : G ⟹ H).app X := rfl
end
namespace nat_trans
-- This section gives two lemmas about natural transformations between functors into functor categories,
-- spelling them out in components.
variables {C : Type u₁} [𝒞 : category.{u₁ v₁} C]
{D : Type u₂} [𝒟 : category.{u₂ v₂} D]
{E : Type u₃} [ℰ : category.{u₃ v₃} E]
include 𝒞 𝒟 ℰ
lemma app_naturality {F G : C ⥤ (D ⥤ E)} (T : F ⟹ G) (X : C) {Y Z : D} (f : Y ⟶ Z) :
((F.obj X).map f) ≫ ((T.app X).app Z) = ((T.app X).app Y) ≫ ((G.obj X).map f) := (T.app X).naturality f
lemma naturality_app {F G : C ⥤ (D ⥤ E)} (T : F ⟹ G) (Z : D) {X Y : C} (f : X ⟶ Y) :
((F.map f).app Z) ≫ ((T.app Y).app Z) = ((T.app X).app Z) ≫ ((G.map f).app Z) := congr_fun (congr_arg app (T.naturality f)) Z
end nat_trans
end functor.category
end category_theory
|
d7fdecda7dc0c1381d0733cf936de899a288031a | 2eab05920d6eeb06665e1a6df77b3157354316ad | /src/analysis/special_functions/exp.lean | 817d76ba8c6af4aa9205a9be0f8710b6d81530d6 | [
"Apache-2.0"
] | permissive | ayush1801/mathlib | 78949b9f789f488148142221606bf15c02b960d2 | ce164e28f262acbb3de6281b3b03660a9f744e3c | refs/heads/master | 1,692,886,907,941 | 1,635,270,866,000 | 1,635,270,866,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 10,466 | lean | /-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle Sönne
-/
import analysis.complex.basic
import data.complex.exponential
/-!
# Complex and real exponential
In this file we prove continuity of `complex.exp` and `real.exp`. We also prove a few facts about
limits of `real.exp` at infinity.
## Tags
exp
-/
noncomputable theory
open finset filter metric asymptotics set function
open_locale classical topological_space
namespace complex
variables {z y x : ℝ}
lemma exp_bound_sq (x z : ℂ) (hz : ∥z∥ ≤ 1) :
∥exp (x + z) - exp x - z • exp x∥ ≤ ∥exp x∥ * ∥z∥ ^ 2 :=
calc ∥exp (x + z) - exp x - z * exp x∥
= ∥exp x * (exp z - 1 - z)∥ : by { congr, rw [exp_add], ring }
... = ∥exp x∥ * ∥exp z - 1 - z∥ : normed_field.norm_mul _ _
... ≤ ∥exp x∥ * ∥z∥^2 : mul_le_mul_of_nonneg_left (abs_exp_sub_one_sub_id_le hz) (norm_nonneg _)
lemma locally_lipschitz_exp {r : ℝ} (hr_nonneg : 0 ≤ r) (hr_le : r ≤ 1) (x y : ℂ)
(hyx : ∥y - x∥ < r) :
∥exp y - exp x∥ ≤ (1 + r) * ∥exp x∥ * ∥y - x∥ :=
begin
have hy_eq : y = x + (y - x), by abel,
have hyx_sq_le : ∥y - x∥ ^ 2 ≤ r * ∥y - x∥,
{ rw pow_two,
exact mul_le_mul hyx.le le_rfl (norm_nonneg _) hr_nonneg, },
have h_sq : ∀ z, ∥z∥ ≤ 1 → ∥exp (x + z) - exp x∥ ≤ ∥z∥ * ∥exp x∥ + ∥exp x∥ * ∥z∥ ^ 2,
{ intros z hz,
have : ∥exp (x + z) - exp x - z • exp x∥ ≤ ∥exp x∥ * ∥z∥ ^ 2, from exp_bound_sq x z hz,
rw [← sub_le_iff_le_add', ← norm_smul z],
exact (norm_sub_norm_le _ _).trans this, },
calc ∥exp y - exp x∥ = ∥exp (x + (y - x)) - exp x∥ : by nth_rewrite 0 hy_eq
... ≤ ∥y - x∥ * ∥exp x∥ + ∥exp x∥ * ∥y - x∥ ^ 2 : h_sq (y - x) (hyx.le.trans hr_le)
... ≤ ∥y - x∥ * ∥exp x∥ + ∥exp x∥ * (r * ∥y - x∥) :
add_le_add_left (mul_le_mul le_rfl hyx_sq_le (sq_nonneg _) (norm_nonneg _)) _
... = (1 + r) * ∥exp x∥ * ∥y - x∥ : by ring,
end
@[continuity] lemma continuous_exp : continuous exp :=
continuous_iff_continuous_at.mpr $
λ x, continuous_at_of_locally_lipschitz zero_lt_one (2 * ∥exp x∥)
(locally_lipschitz_exp zero_le_one le_rfl x)
lemma continuous_on_exp {s : set ℂ} : continuous_on exp s :=
continuous_exp.continuous_on
end complex
section complex_continuous_exp_comp
variable {α : Type*}
open complex
lemma filter.tendsto.cexp {l : filter α} {f : α → ℂ} {z : ℂ} (hf : tendsto f l (𝓝 z)) :
tendsto (λ x, exp (f x)) l (𝓝 (exp z)) :=
(continuous_exp.tendsto _).comp hf
variables [topological_space α] {f : α → ℂ} {s : set α} {x : α}
lemma continuous_within_at.cexp (h : continuous_within_at f s x) :
continuous_within_at (λ y, exp (f y)) s x :=
h.cexp
lemma continuous_at.cexp (h : continuous_at f x) : continuous_at (λ y, exp (f y)) x :=
h.cexp
lemma continuous_on.cexp (h : continuous_on f s) : continuous_on (λ y, exp (f y)) s :=
λ x hx, (h x hx).cexp
lemma continuous.cexp (h : continuous f) : continuous (λ y, exp (f y)) :=
continuous_iff_continuous_at.2 $ λ x, h.continuous_at.cexp
end complex_continuous_exp_comp
namespace real
@[continuity] lemma continuous_exp : continuous exp :=
complex.continuous_re.comp complex.continuous_of_real.cexp
lemma continuous_on_exp {s : set ℝ} : continuous_on exp s :=
continuous_exp.continuous_on
end real
section real_continuous_exp_comp
variable {α : Type*}
open real
lemma filter.tendsto.exp {l : filter α} {f : α → ℝ} {z : ℝ} (hf : tendsto f l (𝓝 z)) :
tendsto (λ x, exp (f x)) l (𝓝 (exp z)) :=
(continuous_exp.tendsto _).comp hf
variables [topological_space α] {f : α → ℝ} {s : set α} {x : α}
lemma continuous_within_at.exp (h : continuous_within_at f s x) :
continuous_within_at (λ y, exp (f y)) s x :=
h.exp
lemma continuous_at.exp (h : continuous_at f x) : continuous_at (λ y, exp (f y)) x :=
h.exp
lemma continuous_on.exp (h : continuous_on f s) : continuous_on (λ y, exp (f y)) s :=
λ x hx, (h x hx).exp
lemma continuous.exp (h : continuous f) : continuous (λ y, exp (f y)) :=
continuous_iff_continuous_at.2 $ λ x, h.continuous_at.exp
end real_continuous_exp_comp
namespace real
variables {x y z : ℝ}
/-- The real exponential function tends to `+∞` at `+∞`. -/
lemma tendsto_exp_at_top : tendsto exp at_top at_top :=
begin
have A : tendsto (λx:ℝ, x + 1) at_top at_top :=
tendsto_at_top_add_const_right at_top 1 tendsto_id,
have B : ∀ᶠ x in at_top, x + 1 ≤ exp x :=
eventually_at_top.2 ⟨0, λx hx, add_one_le_exp_of_nonneg hx⟩,
exact tendsto_at_top_mono' at_top B A
end
/-- The real exponential function tends to `0` at `-∞` or, equivalently, `exp(-x)` tends to `0`
at `+∞` -/
lemma tendsto_exp_neg_at_top_nhds_0 : tendsto (λx, exp (-x)) at_top (𝓝 0) :=
(tendsto_inv_at_top_zero.comp tendsto_exp_at_top).congr (λx, (exp_neg x).symm)
/-- The real exponential function tends to `1` at `0`. -/
lemma tendsto_exp_nhds_0_nhds_1 : tendsto exp (𝓝 0) (𝓝 1) :=
by { convert continuous_exp.tendsto 0, simp }
lemma tendsto_exp_at_bot : tendsto exp at_bot (𝓝 0) :=
(tendsto_exp_neg_at_top_nhds_0.comp tendsto_neg_at_bot_at_top).congr $
λ x, congr_arg exp $ neg_neg x
lemma tendsto_exp_at_bot_nhds_within : tendsto exp at_bot (𝓝[Ioi 0] 0) :=
tendsto_inf.2 ⟨tendsto_exp_at_bot, tendsto_principal.2 $ eventually_of_forall exp_pos⟩
/-- The function `exp(x)/x^n` tends to `+∞` at `+∞`, for any natural number `n` -/
lemma tendsto_exp_div_pow_at_top (n : ℕ) : tendsto (λx, exp x / x^n) at_top at_top :=
begin
refine (at_top_basis_Ioi.tendsto_iff (at_top_basis' 1)).2 (λ C hC₁, _),
have hC₀ : 0 < C, from zero_lt_one.trans_le hC₁,
have : 0 < (exp 1 * C)⁻¹ := inv_pos.2 (mul_pos (exp_pos _) hC₀),
obtain ⟨N, hN⟩ : ∃ N, ∀ k ≥ N, (↑k ^ n : ℝ) / exp 1 ^ k < (exp 1 * C)⁻¹ :=
eventually_at_top.1 ((tendsto_pow_const_div_const_pow_of_one_lt n
(one_lt_exp_iff.2 zero_lt_one)).eventually (gt_mem_nhds this)),
simp only [← exp_nat_mul, mul_one, div_lt_iff, exp_pos, ← div_eq_inv_mul] at hN,
refine ⟨N, trivial, λ x hx, _⟩, rw set.mem_Ioi at hx,
have hx₀ : 0 < x, from N.cast_nonneg.trans_lt hx,
rw [set.mem_Ici, le_div_iff (pow_pos hx₀ _), ← le_div_iff' hC₀],
calc x ^ n ≤ ⌈x⌉₊ ^ n : pow_le_pow_of_le_left hx₀.le (nat.le_ceil _) _
... ≤ exp ⌈x⌉₊ / (exp 1 * C) : (hN _ (nat.lt_ceil.2 hx).le).le
... ≤ exp (x + 1) / (exp 1 * C) : div_le_div_of_le (mul_pos (exp_pos _) hC₀).le
(exp_le_exp.2 $ (nat.ceil_lt_add_one hx₀.le).le)
... = exp x / C : by rw [add_comm, exp_add, mul_div_mul_left _ _ (exp_pos _).ne']
end
/-- The function `x^n * exp(-x)` tends to `0` at `+∞`, for any natural number `n`. -/
lemma tendsto_pow_mul_exp_neg_at_top_nhds_0 (n : ℕ) : tendsto (λx, x^n * exp (-x)) at_top (𝓝 0) :=
(tendsto_inv_at_top_zero.comp (tendsto_exp_div_pow_at_top n)).congr $ λx,
by rw [comp_app, inv_eq_one_div, div_div_eq_mul_div, one_mul, div_eq_mul_inv, exp_neg]
/-- The function `(b * exp x + c) / (x ^ n)` tends to `+∞` at `+∞`, for any positive natural number
`n` and any real numbers `b` and `c` such that `b` is positive. -/
lemma tendsto_mul_exp_add_div_pow_at_top (b c : ℝ) (n : ℕ) (hb : 0 < b) (hn : 1 ≤ n) :
tendsto (λ x, (b * (exp x) + c) / (x^n)) at_top at_top :=
begin
refine tendsto.congr' (eventually_eq_of_mem (Ioi_mem_at_top 0) _)
(((tendsto_exp_div_pow_at_top n).const_mul_at_top hb).at_top_add
((tendsto_pow_neg_at_top hn).mul (@tendsto_const_nhds _ _ _ c _))),
intros x hx,
simp only [fpow_neg x n],
ring,
end
/-- The function `(x ^ n) / (b * exp x + c)` tends to `0` at `+∞`, for any positive natural number
`n` and any real numbers `b` and `c` such that `b` is nonzero. -/
lemma tendsto_div_pow_mul_exp_add_at_top (b c : ℝ) (n : ℕ) (hb : 0 ≠ b) (hn : 1 ≤ n) :
tendsto (λ x, x^n / (b * (exp x) + c)) at_top (𝓝 0) :=
begin
have H : ∀ d e, 0 < d → tendsto (λ (x:ℝ), x^n / (d * (exp x) + e)) at_top (𝓝 0),
{ intros b' c' h,
convert (tendsto_mul_exp_add_div_pow_at_top b' c' n h hn).inv_tendsto_at_top ,
ext x,
simpa only [pi.inv_apply] using inv_div.symm },
cases lt_or_gt_of_ne hb,
{ exact H b c h },
{ convert (H (-b) (-c) (neg_pos.mpr h)).neg,
{ ext x,
field_simp,
rw [← neg_add (b * exp x) c, neg_div_neg_eq] },
{ exact neg_zero.symm } },
end
/-- `real.exp` as an order isomorphism between `ℝ` and `(0, +∞)`. -/
def exp_order_iso : ℝ ≃o Ioi (0 : ℝ) :=
strict_mono.order_iso_of_surjective _ (exp_strict_mono.cod_restrict exp_pos) $
(continuous_subtype_mk _ continuous_exp).surjective
(by simp only [tendsto_Ioi_at_top, subtype.coe_mk, tendsto_exp_at_top])
(by simp [tendsto_exp_at_bot_nhds_within])
@[simp] lemma coe_exp_order_iso_apply (x : ℝ) : (exp_order_iso x : ℝ) = exp x := rfl
@[simp] lemma coe_comp_exp_order_iso : coe ∘ exp_order_iso = exp := rfl
@[simp] lemma range_exp : range exp = Ioi 0 :=
by rw [← coe_comp_exp_order_iso, range_comp, exp_order_iso.range_eq, image_univ, subtype.range_coe]
@[simp] lemma map_exp_at_top : map exp at_top = at_top :=
by rw [← coe_comp_exp_order_iso, ← filter.map_map, order_iso.map_at_top, map_coe_Ioi_at_top]
@[simp] lemma comap_exp_at_top : comap exp at_top = at_top :=
by rw [← map_exp_at_top, comap_map exp_injective, map_exp_at_top]
@[simp] lemma tendsto_exp_comp_at_top {α : Type*} {l : filter α} {f : α → ℝ} :
tendsto (λ x, exp (f x)) l at_top ↔ tendsto f l at_top :=
by rw [← tendsto_comap_iff, comap_exp_at_top]
lemma tendsto_comp_exp_at_top {α : Type*} {l : filter α} {f : ℝ → α} :
tendsto (λ x, f (exp x)) at_top l ↔ tendsto f at_top l :=
by rw [← tendsto_map'_iff, map_exp_at_top]
@[simp] lemma map_exp_at_bot : map exp at_bot = 𝓝[Ioi 0] 0 :=
by rw [← coe_comp_exp_order_iso, ← filter.map_map, exp_order_iso.map_at_bot, ← map_coe_Ioi_at_bot]
lemma comap_exp_nhds_within_Ioi_zero : comap exp (𝓝[Ioi 0] 0) = at_bot :=
by rw [← map_exp_at_bot, comap_map exp_injective]
lemma tendsto_comp_exp_at_bot {α : Type*} {l : filter α} {f : ℝ → α} :
tendsto (λ x, f (exp x)) at_bot l ↔ tendsto f (𝓝[Ioi 0] 0) l :=
by rw [← map_exp_at_bot, tendsto_map'_iff]
end real
|
8c233bdde98b5710ec7dc7b9ccc1dbd1328d43c6 | 49bd2218ae088932d847f9030c8dbff1c5607bb7 | /src/ring_theory/ideal_operations.lean | 7f7e0c609b316621ccbe67ccb94b50a260bc81c2 | [
"Apache-2.0"
] | permissive | FredericLeRoux/mathlib | e8f696421dd3e4edc8c7edb3369421c8463d7bac | 3645bf8fb426757e0a20af110d1fdded281d286e | refs/heads/master | 1,607,062,870,732 | 1,578,513,186,000 | 1,578,513,186,000 | 231,653,181 | 0 | 0 | Apache-2.0 | 1,578,080,327,000 | 1,578,080,326,000 | null | UTF-8 | Lean | false | false | 26,867 | lean | /-
Copyright (c) 2018 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau
More operations on modules and ideals.
-/
import ring_theory.ideals data.nat.choose order.zorn
import linear_algebra.tensor_product
import data.equiv.algebra
import ring_theory.algebra_operations
universes u v w x
open lattice
namespace submodule
variables {R : Type u} {M : Type v}
variables [comm_ring R] [add_comm_group M] [module R M]
instance has_scalar' : has_scalar (ideal R) (submodule R M) :=
⟨λ I N, ⨆ r : I, N.map (r.1 • linear_map.id)⟩
def annihilator (N : submodule R M) : ideal R :=
(linear_map.lsmul R N).ker
def colon (N P : submodule R M) : ideal R :=
annihilator (P.map N.mkq)
variables {I J : ideal R} {N N₁ N₂ P P₁ P₂ : submodule R M}
theorem mem_annihilator {r} : r ∈ N.annihilator ↔ ∀ n ∈ N, r • n = (0:M) :=
⟨λ hr n hn, congr_arg subtype.val (linear_map.ext_iff.1 (linear_map.mem_ker.1 hr) ⟨n, hn⟩),
λ h, linear_map.mem_ker.2 $ linear_map.ext $ λ n, subtype.eq $ h n.1 n.2⟩
theorem mem_annihilator' {r} : r ∈ N.annihilator ↔ N ≤ comap (r • linear_map.id) ⊥ :=
mem_annihilator.trans ⟨λ H n hn, (mem_bot R).2 $ H n hn, λ H n hn, (mem_bot R).1 $ H hn⟩
theorem annihilator_bot : (⊥ : submodule R M).annihilator = ⊤ :=
(ideal.eq_top_iff_one _).2 $ mem_annihilator'.2 bot_le
theorem annihilator_eq_top_iff : N.annihilator = ⊤ ↔ N = ⊥ :=
⟨λ H, eq_bot_iff.2 $ λ (n:M) hn, (mem_bot R).2 $ one_smul R n ▸ mem_annihilator.1 ((ideal.eq_top_iff_one _).1 H) n hn,
λ H, H.symm ▸ annihilator_bot⟩
theorem annihilator_mono (h : N ≤ P) : P.annihilator ≤ N.annihilator :=
λ r hrp, mem_annihilator.2 $ λ n hn, mem_annihilator.1 hrp n $ h hn
theorem annihilator_supr (ι : Type w) (f : ι → submodule R M) :
(annihilator ⨆ i, f i) = ⨅ i, annihilator (f i) :=
le_antisymm (le_infi $ λ i, annihilator_mono $ le_supr _ _)
(λ r H, mem_annihilator'.2 $ supr_le $ λ i,
have _ := (mem_infi _).1 H i, mem_annihilator'.1 this)
theorem mem_colon {r} : r ∈ N.colon P ↔ ∀ p ∈ P, r • p ∈ N :=
mem_annihilator.trans ⟨λ H p hp, (quotient.mk_eq_zero N).1 (H (quotient.mk p) (mem_map_of_mem hp)),
λ H m ⟨p, hp, hpm⟩, hpm ▸ (N.mkq).map_smul r p ▸ (quotient.mk_eq_zero N).2 $ H p hp⟩
theorem mem_colon' {r} : r ∈ N.colon P ↔ P ≤ comap (r • linear_map.id) N :=
mem_colon
theorem colon_mono (hn : N₁ ≤ N₂) (hp : P₁ ≤ P₂) : N₁.colon P₂ ≤ N₂.colon P₁ :=
λ r hrnp, mem_colon.2 $ λ p₁ hp₁, hn $ mem_colon.1 hrnp p₁ $ hp hp₁
theorem infi_colon_supr (ι₁ : Type w) (f : ι₁ → submodule R M)
(ι₂ : Type x) (g : ι₂ → submodule R M) :
(⨅ i, f i).colon (⨆ j, g j) = ⨅ i j, (f i).colon (g j) :=
le_antisymm (le_infi $ λ i, le_infi $ λ j, colon_mono (infi_le _ _) (le_supr _ _))
(λ r H, mem_colon'.2 $ supr_le $ λ j, map_le_iff_le_comap.1 $ le_infi $ λ i,
map_le_iff_le_comap.2 $ mem_colon'.1 $ have _ := ((mem_infi _).1 H i),
have _ := ((mem_infi _).1 this j), this)
theorem smul_mem_smul {r} {n} (hr : r ∈ I) (hn : n ∈ N) : r • n ∈ I • N :=
(le_supr _ ⟨r, hr⟩ : _ ≤ I • N) ⟨n, hn, rfl⟩
theorem smul_le {P : submodule R M} : I • N ≤ P ↔ ∀ (r ∈ I) (n ∈ N), r • n ∈ P :=
⟨λ H r hr n hn, H $ smul_mem_smul hr hn,
λ H, supr_le $ λ r, map_le_iff_le_comap.2 $ λ n hn, H r.1 r.2 n hn⟩
@[elab_as_eliminator]
theorem smul_induction_on {p : M → Prop} {x} (H : x ∈ I • N)
(Hb : ∀ (r ∈ I) (n ∈ N), p (r • n)) (H0 : p 0)
(H1 : ∀ x y, p x → p y → p (x + y))
(H2 : ∀ (c:R) n, p n → p (c • n)) : p x :=
(@smul_le _ _ _ _ _ _ _ ⟨p, H0, H1, H2⟩).2 Hb H
theorem mem_smul_span_singleton {I : ideal R} {m : M} {x : M} :
x ∈ I • span R ({m} : set M) ↔ ∃ y ∈ I, y • m = x :=
⟨λ hx, smul_induction_on hx
(λ r hri n hnm, let ⟨s, hs⟩ := mem_span_singleton.1 hnm in ⟨r * s, I.mul_mem_right hri, hs ▸ mul_smul r s m⟩)
⟨0, I.zero_mem, by rw [zero_smul]⟩
(λ m1 m2 ⟨y1, hyi1, hy1⟩ ⟨y2, hyi2, hy2⟩, ⟨y1 + y2, I.add_mem hyi1 hyi2, by rw [add_smul, hy1, hy2]⟩)
(λ c r ⟨y, hyi, hy⟩, ⟨c * y, I.mul_mem_left hyi, by rw [mul_smul, hy]⟩),
λ ⟨y, hyi, hy⟩, hy ▸ smul_mem_smul hyi (subset_span $ set.mem_singleton m)⟩
theorem smul_le_right : I • N ≤ N :=
smul_le.2 $ λ r hr n, N.smul_mem r
theorem smul_mono (hij : I ≤ J) (hnp : N ≤ P) : I • N ≤ J • P :=
smul_le.2 $ λ r hr n hn, smul_mem_smul (hij hr) (hnp hn)
theorem smul_mono_left (h : I ≤ J) : I • N ≤ J • N :=
smul_mono h (le_refl N)
theorem smul_mono_right (h : N ≤ P) : I • N ≤ I • P :=
smul_mono (le_refl I) h
variables (I J N P)
@[simp] theorem smul_bot : I • (⊥ : submodule R M) = ⊥ :=
eq_bot_iff.2 $ smul_le.2 $ λ r hri s hsb,
(submodule.mem_bot R).2 $ ((submodule.mem_bot R).1 hsb).symm ▸ smul_zero r
@[simp] theorem bot_smul : (⊥ : ideal R) • N = ⊥ :=
eq_bot_iff.2 $ smul_le.2 $ λ r hrb s hsi,
(submodule.mem_bot R).2 $ ((submodule.mem_bot R).1 hrb).symm ▸ zero_smul _ s
@[simp] theorem top_smul : (⊤ : ideal R) • N = N :=
le_antisymm smul_le_right $ λ r hri, one_smul R r ▸ smul_mem_smul mem_top hri
theorem smul_sup : I • (N ⊔ P) = I • N ⊔ I • P :=
le_antisymm (smul_le.2 $ λ r hri m hmnp, let ⟨n, hn, p, hp, hnpm⟩ := mem_sup.1 hmnp in
mem_sup.2 ⟨_, smul_mem_smul hri hn, _, smul_mem_smul hri hp, hnpm ▸ (smul_add _ _ _).symm⟩)
(sup_le (smul_mono_right le_sup_left)
(smul_mono_right le_sup_right))
theorem sup_smul : (I ⊔ J) • N = I • N ⊔ J • N :=
le_antisymm (smul_le.2 $ λ r hrij n hn, let ⟨ri, hri, rj, hrj, hrijr⟩ := mem_sup.1 hrij in
mem_sup.2 ⟨_, smul_mem_smul hri hn, _, smul_mem_smul hrj hn, hrijr ▸ (add_smul _ _ _).symm⟩)
(sup_le (smul_mono_left le_sup_left)
(smul_mono_left le_sup_right))
theorem smul_assoc : (I • J) • N = I • (J • N) :=
le_antisymm (smul_le.2 $ λ rs hrsij t htn,
smul_induction_on hrsij
(λ r hr s hs, (@smul_eq_mul R _ r s).symm ▸ smul_smul _ r s t ▸ smul_mem_smul hr (smul_mem_smul hs htn))
((zero_smul R t).symm ▸ submodule.zero_mem _)
(λ x y, (add_smul x y t).symm ▸ submodule.add_mem _)
(λ r s h, (@smul_eq_mul R _ r s).symm ▸ smul_smul _ r s t ▸ submodule.smul_mem _ _ h))
(smul_le.2 $ λ r hr sn hsn, suffices J • N ≤ submodule.comap (r • linear_map.id) ((I • J) • N), from this hsn,
smul_le.2 $ λ s hs n hn, show r • (s • n) ∈ (I • J) • N, from mul_smul r s n ▸ smul_mem_smul (smul_mem_smul hr hs) hn)
variables (S : set R) (T : set M)
theorem span_smul_span : (ideal.span S) • (span R T) =
span R (⋃ (s ∈ S) (t ∈ T), {s • t}) :=
le_antisymm (smul_le.2 $ λ r hrS n hnT, span_induction hrS
(λ r hrS, span_induction hnT
(λ n hnT, subset_span $ set.mem_bUnion hrS $
set.mem_bUnion hnT $ set.mem_singleton _)
((smul_zero r : r • 0 = (0:M)).symm ▸ submodule.zero_mem _)
(λ x y, (smul_add r x y).symm ▸ submodule.add_mem _)
(λ c m, by rw [smul_smul, mul_comm, mul_smul]; exact submodule.smul_mem _ _))
((zero_smul R n).symm ▸ submodule.zero_mem _)
(λ r s, (add_smul r s n).symm ▸ submodule.add_mem _)
(λ c r, by rw [smul_eq_mul, mul_smul]; exact submodule.smul_mem _ _)) $
span_le.2 $ set.bUnion_subset $ λ r hrS, set.bUnion_subset $ λ n hnT, set.singleton_subset_iff.2 $
smul_mem_smul (subset_span hrS) (subset_span hnT)
end submodule
namespace ideal
section chinese_remainder
variables {R : Type u} [comm_ring R] {ι : Type v}
theorem exists_sub_one_mem_and_mem (s : finset ι) {f : ι → ideal R}
(hf : ∀ i ∈ s, ∀ j ∈ s, i ≠ j → f i ⊔ f j = ⊤) (i : ι) (his : i ∈ s) :
∃ r : R, r - 1 ∈ f i ∧ ∀ j ∈ s, j ≠ i → r ∈ f j :=
begin
have : ∀ j ∈ s, j ≠ i → ∃ r : R, ∃ H : r - 1 ∈ f i, r ∈ f j,
{ intros j hjs hji, specialize hf i his j hjs hji.symm,
rw [eq_top_iff_one, submodule.mem_sup] at hf,
rcases hf with ⟨r, hri, s, hsj, hrs⟩, refine ⟨1 - r, _, _⟩,
{ rw [sub_right_comm, sub_self, zero_sub], exact (f i).neg_mem hri },
{ rw [← hrs, add_sub_cancel'], exact hsj } },
classical,
have : ∃ g : ι → R, (∀ j, g j - 1 ∈ f i) ∧ ∀ j ∈ s, j ≠ i → g j ∈ f j,
{ choose g hg1 hg2,
refine ⟨λ j, if H : j ∈ s ∧ j ≠ i then g j H.1 H.2 else 1, λ j, _, λ j, _⟩,
{ split_ifs with h, { apply hg1 }, rw sub_self, exact (f i).zero_mem },
{ intros hjs hji, rw dif_pos, { apply hg2 }, exact ⟨hjs, hji⟩ } },
rcases this with ⟨g, hgi, hgj⟩, use (s.erase i).prod g, split,
{ rw [← quotient.eq, quotient.mk_one, ← finset.prod_hom _ (quotient.mk (f i))],
apply finset.prod_eq_one, intros, rw [← quotient.mk_one, quotient.eq], apply hgi },
intros j hjs hji, rw [← quotient.eq_zero_iff_mem, ← finset.prod_hom _ (quotient.mk (f j))],
refine finset.prod_eq_zero (finset.mem_erase_of_ne_of_mem hji hjs) _,
rw quotient.eq_zero_iff_mem, exact hgj j hjs hji
end
theorem exists_sub_mem [fintype ι] {f : ι → ideal R}
(hf : ∀ i j, i ≠ j → f i ⊔ f j = ⊤) (g : ι → R) :
∃ r : R, ∀ i, r - g i ∈ f i :=
begin
have : ∃ φ : ι → R, (∀ i, φ i - 1 ∈ f i) ∧ (∀ i j, i ≠ j → φ i ∈ f j),
{ have := exists_sub_one_mem_and_mem (finset.univ : finset ι) (λ i _ j _ hij, hf i j hij),
choose φ hφ,
existsi λ i, φ i (finset.mem_univ i),
exact ⟨λ i, (hφ i _).1, λ i j hij, (hφ i _).2 j (finset.mem_univ j) hij.symm⟩ },
rcases this with ⟨φ, hφ1, hφ2⟩,
use finset.univ.sum (λ i, g i * φ i),
intros i,
rw [← quotient.eq, ← finset.univ.sum_hom (quotient.mk (f i))],
refine eq.trans (finset.sum_eq_single i _ _) _,
{ intros j _ hji, rw quotient.eq_zero_iff_mem, exact (f i).mul_mem_left (hφ2 j i hji) },
{ intros hi, exact (hi $ finset.mem_univ i).elim },
specialize hφ1 i, rw [← quotient.eq, quotient.mk_one] at hφ1,
rw [quotient.mk_mul, hφ1, mul_one]
end
def quotient_inf_to_pi_quotient (f : ι → ideal R) :
(⨅ i, f i).quotient → Π i, (f i).quotient :=
@@quotient.lift _ _ (⨅ i, f i) (λ r i, ideal.quotient.mk (f i) r)
(@pi.is_ring_hom_pi ι (λ i, (f i).quotient) _ R _ _ _)
(λ r hr, funext $ λ i, quotient.eq_zero_iff_mem.2 $ (submodule.mem_infi _).1 hr i)
theorem is_ring_hom_quotient_inf_to_pi_quotient (f : ι → ideal R) :
is_ring_hom (quotient_inf_to_pi_quotient f) :=
@@quotient.is_ring_hom _ _ _
(@pi.is_ring_hom_pi ι (λ i, (f i).quotient) _ R _ _ _) _
theorem bijective_quotient_inf_to_pi_quotient [fintype ι] {f : ι → ideal R}
(hf : ∀ i j, i ≠ j → f i ⊔ f j = ⊤) :
function.bijective (quotient_inf_to_pi_quotient f) :=
⟨λ x y, quotient.induction_on₂' x y $ λ r s hrs, quotient.eq.2 $
(submodule.mem_infi _).2 $ λ i, quotient.eq.1 $
show quotient_inf_to_pi_quotient f (quotient.mk' r) i = _, by rw hrs; refl,
λ g, let ⟨r, hr⟩ := exists_sub_mem hf (λ i, quotient.out' (g i)) in
⟨quotient.mk _ r, funext $ λ i, quotient.out_eq' (g i) ▸ quotient.eq.2 (hr i)⟩⟩
/-- Chinese Remainder Theorem. Eisenbud Ex.2.6. Similar to Atiyah-Macdonald 1.10 and Stacks 00DT -/
noncomputable def quotient_inf_ring_equiv_pi_quotient [fintype ι] (f : ι → ideal R)
(hf : ∀ i j, i ≠ j → f i ⊔ f j = ⊤) :
(⨅ i, f i).quotient ≃+* Π i, (f i).quotient :=
by haveI : is_ring_hom (equiv.of_bijective (bijective_quotient_inf_to_pi_quotient hf)) :=
is_ring_hom_quotient_inf_to_pi_quotient f;
exact ring_equiv.of (equiv.of_bijective (bijective_quotient_inf_to_pi_quotient hf))
end chinese_remainder
section mul_and_radical
variables {R : Type u} [comm_ring R]
variables {I J K L: ideal R}
instance : has_mul (ideal R) := ⟨(•)⟩
theorem mul_mem_mul {r s} (hr : r ∈ I) (hs : s ∈ J) : r * s ∈ I * J :=
submodule.smul_mem_smul hr hs
theorem mul_mem_mul_rev {r s} (hr : r ∈ I) (hs : s ∈ J) : s * r ∈ I * J :=
mul_comm r s ▸ mul_mem_mul hr hs
theorem mul_le : I * J ≤ K ↔ ∀ (r ∈ I) (s ∈ J), r * s ∈ K :=
submodule.smul_le
variables (I J K)
protected theorem mul_comm : I * J = J * I :=
le_antisymm (mul_le.2 $ λ r hrI s hsJ, mul_mem_mul_rev hsJ hrI)
(mul_le.2 $ λ r hrJ s hsI, mul_mem_mul_rev hsI hrJ)
protected theorem mul_assoc : (I * J) * K = I * (J * K) :=
submodule.smul_assoc I J K
theorem span_mul_span (S T : set R) : span S * span T =
span ⋃ (s ∈ S) (t ∈ T), {s * t} :=
submodule.span_smul_span S T
variables {I J K}
theorem mul_le_inf : I * J ≤ I ⊓ J :=
mul_le.2 $ λ r hri s hsj, ⟨I.mul_mem_right hri, J.mul_mem_left hsj⟩
theorem mul_eq_inf_of_coprime (h : I ⊔ J = ⊤) : I * J = I ⊓ J :=
le_antisymm mul_le_inf $ λ r ⟨hri, hrj⟩,
let ⟨s, hsi, t, htj, hst⟩ := submodule.mem_sup.1 ((eq_top_iff_one _).1 h) in
mul_one r ▸ hst ▸ (mul_add r s t).symm ▸ ideal.add_mem (I * J) (mul_mem_mul_rev hsi hrj) (mul_mem_mul hri htj)
variables (I)
theorem mul_bot : I * ⊥ = ⊥ :=
submodule.smul_bot I
theorem bot_mul : ⊥ * I = ⊥ :=
submodule.bot_smul I
theorem mul_top : I * ⊤ = I :=
ideal.mul_comm ⊤ I ▸ submodule.top_smul I
theorem top_mul : ⊤ * I = I :=
submodule.top_smul I
variables {I}
theorem mul_mono (hik : I ≤ K) (hjl : J ≤ L) : I * J ≤ K * L :=
submodule.smul_mono hik hjl
theorem mul_mono_left (h : I ≤ J) : I * K ≤ J * K :=
submodule.smul_mono_left h
theorem mul_mono_right (h : J ≤ K) : I * J ≤ I * K :=
submodule.smul_mono_right h
variables (I J K)
theorem mul_sup : I * (J ⊔ K) = I * J ⊔ I * K :=
submodule.smul_sup I J K
theorem sup_mul : (I ⊔ J) * K = I * K ⊔ J * K :=
submodule.sup_smul I J K
variables {I J K}
lemma pow_le_pow {m n : ℕ} (h : m ≤ n) :
I^n ≤ I^m :=
begin
cases nat.exists_eq_add_of_le h with k hk,
rw [hk, pow_add],
exact le_trans (mul_le_inf) (lattice.inf_le_left)
end
/-- The radical of an ideal `I` consists of the elements `r` such that `r^n ∈ I` for some `n`. -/
def radical (I : ideal R) : ideal R :=
{ carrier := { r | ∃ n : ℕ, r ^ n ∈ I },
zero := ⟨1, (pow_one (0:R)).symm ▸ I.zero_mem⟩,
add := λ x y ⟨m, hxmi⟩ ⟨n, hyni⟩, ⟨m + n,
(add_pow x y (m + n)).symm ▸ I.sum_mem $
show ∀ c ∈ finset.range (nat.succ (m + n)), x ^ c * y ^ (m + n - c) * (nat.choose (m + n) c) ∈ I,
from λ c hc, or.cases_on (le_total c m)
(λ hcm, I.mul_mem_right $ I.mul_mem_left $ nat.add_comm n m ▸ (nat.add_sub_assoc hcm n).symm ▸
(pow_add y n (m-c)).symm ▸ I.mul_mem_right hyni)
(λ hmc, I.mul_mem_right $ I.mul_mem_right $ nat.add_sub_cancel' hmc ▸
(pow_add x m (c-m)).symm ▸ I.mul_mem_right hxmi)⟩,
smul := λ r s ⟨n, hsni⟩, ⟨n, show (r * s)^n ∈ I,
from (mul_pow r s n).symm ▸ I.mul_mem_left hsni⟩ }
theorem le_radical : I ≤ radical I :=
λ r hri, ⟨1, (pow_one r).symm ▸ hri⟩
variables (R)
theorem radical_top : (radical ⊤ : ideal R) = ⊤ :=
(eq_top_iff_one _).2 ⟨0, submodule.mem_top⟩
variables {R}
theorem radical_mono (H : I ≤ J) : radical I ≤ radical J :=
λ r ⟨n, hrni⟩, ⟨n, H hrni⟩
variables (I)
theorem radical_idem : radical (radical I) = radical I :=
le_antisymm (λ r ⟨n, k, hrnki⟩, ⟨n * k, (pow_mul r n k).symm ▸ hrnki⟩) le_radical
variables {I}
theorem radical_eq_top : radical I = ⊤ ↔ I = ⊤ :=
⟨λ h, (eq_top_iff_one _).2 $ let ⟨n, hn⟩ := (eq_top_iff_one _).1 h in
@one_pow R _ n ▸ hn, λ h, h.symm ▸ radical_top R⟩
theorem is_prime.radical (H : is_prime I) : radical I = I :=
le_antisymm (λ r ⟨n, hrni⟩, H.mem_of_pow_mem n hrni) le_radical
variables (I J)
theorem radical_sup : radical (I ⊔ J) = radical (radical I ⊔ radical J) :=
le_antisymm (radical_mono $ sup_le_sup le_radical le_radical) $
λ r ⟨n, hrnij⟩, let ⟨s, hs, t, ht, hst⟩ := submodule.mem_sup.1 hrnij in
@radical_idem _ _ (I ⊔ J) ▸ ⟨n, hst ▸ ideal.add_mem _
(radical_mono le_sup_left hs) (radical_mono le_sup_right ht)⟩
theorem radical_inf : radical (I ⊓ J) = radical I ⊓ radical J :=
le_antisymm (le_inf (radical_mono inf_le_left) (radical_mono inf_le_right))
(λ r ⟨⟨m, hrm⟩, ⟨n, hrn⟩⟩, ⟨m + n, (pow_add r m n).symm ▸ I.mul_mem_right hrm,
(pow_add r m n).symm ▸ J.mul_mem_left hrn⟩)
theorem radical_mul : radical (I * J) = radical I ⊓ radical J :=
le_antisymm (radical_inf I J ▸ radical_mono $ @mul_le_inf _ _ I J)
(λ r ⟨⟨m, hrm⟩, ⟨n, hrn⟩⟩, ⟨m + n, (pow_add r m n).symm ▸ mul_mem_mul hrm hrn⟩)
variables {I J}
theorem is_prime.radical_le_iff (hj : is_prime J) :
radical I ≤ J ↔ I ≤ J :=
⟨le_trans le_radical, λ hij r ⟨n, hrni⟩, hj.mem_of_pow_mem n $ hij hrni⟩
theorem radical_eq_Inf (I : ideal R) :
radical I = Inf { J : ideal R | I ≤ J ∧ is_prime J } :=
le_antisymm (le_Inf $ λ J hJ, hJ.2.radical_le_iff.2 hJ.1) $
λ r hr, classical.by_contradiction $ λ hri,
let ⟨m, (hrm : r ∉ radical m), him, hm⟩ := zorn.zorn_partial_order₀ {K : ideal R | r ∉ radical K}
(λ c hc hcc y hyc, ⟨Sup c, λ ⟨n, hrnc⟩, let ⟨y, hyc, hrny⟩ :=
submodule.mem_Sup_of_directed hrnc y hyc hcc.directed_on in hc hyc ⟨n, hrny⟩,
λ z, le_Sup⟩) I hri in
have ∀ x ∉ m, r ∈ radical (m ⊔ span {x}) := λ x hxm, classical.by_contradiction $ λ hrmx, hxm $
hm (m ⊔ span {x}) hrmx le_sup_left ▸ (le_sup_right : _ ≤ m ⊔ span {x}) (subset_span $ set.mem_singleton _),
have is_prime m, from ⟨by rintro rfl; rw radical_top at hrm; exact hrm trivial,
λ x y hxym, classical.or_iff_not_imp_left.2 $ λ hxm, classical.by_contradiction $ λ hym,
let ⟨n, hrn⟩ := this _ hxm, ⟨p, hpm, q, hq, hpqrn⟩ := submodule.mem_sup.1 hrn, ⟨c, hcxq⟩ := mem_span_singleton'.1 hq in
let ⟨k, hrk⟩ := this _ hym, ⟨f, hfm, g, hg, hfgrk⟩ := submodule.mem_sup.1 hrk, ⟨d, hdyg⟩ := mem_span_singleton'.1 hg in
hrm ⟨n + k, by rw [pow_add, ← hpqrn, ← hcxq, ← hfgrk, ← hdyg, add_mul, mul_add (c*x), mul_assoc c x (d*y), mul_left_comm x, ← mul_assoc];
refine m.add_mem (m.mul_mem_right hpm) (m.add_mem (m.mul_mem_left hfm) (m.mul_mem_left hxym))⟩⟩,
hrm $ this.radical.symm ▸ (Inf_le ⟨him, this⟩ : Inf {J : ideal R | I ≤ J ∧ is_prime J} ≤ m) hr
instance : comm_semiring (ideal R) := submodule.comm_semiring
@[simp] lemma add_eq_sup : I + J = I ⊔ J := rfl
@[simp] lemma zero_eq_bot : (0 : ideal R) = ⊥ := rfl
@[simp] lemma one_eq_top : (1 : ideal R) = ⊤ :=
by erw [submodule.one_eq_map_top, submodule.map_id]
variables (I)
theorem radical_pow (n : ℕ) (H : n > 0) : radical (I^n) = radical I :=
nat.rec_on n (not.elim dec_trivial) (λ n ih H,
or.cases_on (lt_or_eq_of_le $ nat.le_of_lt_succ H)
(λ H, calc radical (I^(n+1))
= radical I ⊓ radical (I^n) : radical_mul _ _
... = radical I ⊓ radical I : by rw ih H
... = radical I : inf_idem)
(λ H, H ▸ (pow_one I).symm ▸ rfl)) H
end mul_and_radical
section map_and_comap
variables {R : Type u} {S : Type v} [comm_ring R] [comm_ring S]
variables (f : R → S) [is_ring_hom f]
variables {I J : ideal R} {K L : ideal S}
def map (I : ideal R) : ideal S :=
span (f '' I)
/-- `I.comap f` is the preimage of `I` under `f`. -/
def comap (I : ideal S) : ideal R :=
{ carrier := f ⁻¹' I,
zero := show f 0 ∈ I, by rw is_ring_hom.map_zero f; exact I.zero_mem,
add := λ x y hx hy, show f (x + y) ∈ I, by rw is_ring_hom.map_add f; exact I.add_mem hx hy,
smul := λ c x hx, show f (c * x) ∈ I, by rw is_ring_hom.map_mul f; exact I.mul_mem_left hx }
variables {f}
theorem map_mono (h : I ≤ J) : map f I ≤ map f J :=
span_mono $ set.image_subset _ h
theorem mem_map_of_mem {x} (h : x ∈ I) : f x ∈ map f I :=
subset_span ⟨x, h, rfl⟩
theorem map_le_iff_le_comap :
map f I ≤ K ↔ I ≤ comap f K :=
span_le.trans set.image_subset_iff
@[simp] theorem mem_comap {x} : x ∈ comap f K ↔ f x ∈ K := iff.rfl
theorem comap_mono (h : K ≤ L) : comap f K ≤ comap f L :=
set.preimage_mono h
variables (f)
theorem comap_ne_top (hK : K ≠ ⊤) : comap f K ≠ ⊤ :=
(ne_top_iff_one _).2 $ by rw [mem_comap, is_ring_hom.map_one f];
exact (ne_top_iff_one _).1 hK
instance is_prime.comap {hK : K.is_prime} : (comap f K).is_prime :=
⟨comap_ne_top _ hK.1, λ x y,
by simp only [mem_comap, is_ring_hom.map_mul f]; apply hK.2⟩
variables (I J K L)
theorem map_bot : map f ⊥ = ⊥ :=
le_antisymm (map_le_iff_le_comap.2 bot_le) bot_le
theorem map_top : map f ⊤ = ⊤ :=
(eq_top_iff_one _).2 $ subset_span ⟨1, trivial, is_ring_hom.map_one f⟩
theorem comap_top : comap f ⊤ = ⊤ :=
(eq_top_iff_one _).2 trivial
theorem map_sup : map f (I ⊔ J) = map f I ⊔ map f J :=
le_antisymm (map_le_iff_le_comap.2 $ sup_le
(map_le_iff_le_comap.1 le_sup_left)
(map_le_iff_le_comap.1 le_sup_right))
(sup_le (map_mono le_sup_left) (map_mono le_sup_right))
theorem map_mul : map f (I * J) = map f I * map f J :=
le_antisymm (map_le_iff_le_comap.2 $ mul_le.2 $ λ r hri s hsj,
show f (r * s) ∈ _, by rw is_ring_hom.map_mul f;
exact mul_mem_mul (mem_map_of_mem hri) (mem_map_of_mem hsj))
(trans_rel_right _ (span_mul_span _ _) $ span_le.2 $
set.bUnion_subset $ λ i ⟨r, hri, hfri⟩,
set.bUnion_subset $ λ j ⟨s, hsj, hfsj⟩,
set.singleton_subset_iff.2 $ hfri ▸ hfsj ▸
by rw [← is_ring_hom.map_mul f];
exact mem_map_of_mem (mul_mem_mul hri hsj))
theorem comap_inf : comap f (K ⊓ L) = comap f K ⊓ comap f L := rfl
theorem comap_radical : comap f (radical K) = radical (comap f K) :=
le_antisymm (λ r ⟨n, hfrnk⟩, ⟨n, show f (r ^ n) ∈ K,
from (is_semiring_hom.map_pow f r n).symm ▸ hfrnk⟩)
(λ r ⟨n, hfrnk⟩, ⟨n, is_semiring_hom.map_pow f r n ▸ hfrnk⟩)
@[simp] lemma map_quotient_self :
map (quotient.mk I) I = ⊥ :=
lattice.eq_bot_iff.2 $ ideal.map_le_iff_le_comap.2 $ λ x hx,
(submodule.mem_bot I.quotient).2 $ ideal.quotient.eq_zero_iff_mem.2 hx
variables {I J K L}
theorem map_inf_le : map f (I ⊓ J) ≤ map f I ⊓ map f J :=
map_le_iff_le_comap.2 $ (comap_inf f (map f I) (map f J)).symm ▸
inf_le_inf (map_le_iff_le_comap.1 $ le_refl _) (map_le_iff_le_comap.1 $ le_refl _)
theorem map_radical_le : map f (radical I) ≤ radical (map f I) :=
map_le_iff_le_comap.2 $ λ r ⟨n, hrni⟩, ⟨n, is_semiring_hom.map_pow f r n ▸ mem_map_of_mem hrni⟩
theorem le_comap_sup : comap f K ⊔ comap f L ≤ comap f (K ⊔ L) :=
map_le_iff_le_comap.1 $ (map_sup f (comap f K) (comap f L)).symm ▸
sup_le_sup (map_le_iff_le_comap.2 $ le_refl _) (map_le_iff_le_comap.2 $ le_refl _)
theorem le_comap_mul : comap f K * comap f L ≤ comap f (K * L) :=
map_le_iff_le_comap.1 $ (map_mul f (comap f K) (comap f L)).symm ▸
mul_mono (map_le_iff_le_comap.2 $ le_refl _) (map_le_iff_le_comap.2 $ le_refl _)
section surjective
variables (hf : function.surjective f)
include hf
theorem map_comap_of_surjective (I : ideal S) :
map f (comap f I) = I :=
le_antisymm (map_le_iff_le_comap.2 (le_refl _))
(λ s hsi, let ⟨r, hfrs⟩ := hf s in
hfrs ▸ (mem_map_of_mem $ show f r ∈ I, from hfrs.symm ▸ hsi))
theorem mem_image_of_mem_map_of_surjective {I : ideal R} {y}
(H : y ∈ map f I) : y ∈ f '' I :=
submodule.span_induction H (λ _, id) ⟨0, I.zero_mem, is_ring_hom.map_zero f⟩
(λ y1 y2 ⟨x1, hx1i, hxy1⟩ ⟨x2, hx2i, hxy2⟩, ⟨x1 + x2, I.add_mem hx1i hx2i, hxy1 ▸ hxy2 ▸ is_ring_hom.map_add f⟩)
(λ c y ⟨x, hxi, hxy⟩, let ⟨d, hdc⟩ := hf c in ⟨d • x, I.smul_mem _ hxi, hdc ▸ hxy ▸ is_ring_hom.map_mul f⟩)
theorem comap_map_of_surjective (I : ideal R) :
comap f (map f I) = I ⊔ comap f ⊥ :=
le_antisymm (assume r h, let ⟨s, hsi, hfsr⟩ := mem_image_of_mem_map_of_surjective f hf h in
submodule.mem_sup.2 ⟨s, hsi, r - s, (submodule.mem_bot S).2 $ by rw [is_ring_hom.map_sub f, hfsr, sub_self],
add_sub_cancel'_right s r⟩)
(sup_le (map_le_iff_le_comap.1 (le_refl _)) (comap_mono bot_le))
/-- Correspondence theorem -/
def order_iso_of_surjective :
((≤) : ideal S → ideal S → Prop) ≃o
((≤) : { p : ideal R // comap f ⊥ ≤ p } → { p : ideal R // comap f ⊥ ≤ p } → Prop) :=
{ to_fun := λ J, ⟨comap f J, comap_mono bot_le⟩,
inv_fun := λ I, map f I.1,
left_inv := λ J, map_comap_of_surjective f hf J,
right_inv := λ I, subtype.eq $ show comap f (map f I.1) = I.1,
from (comap_map_of_surjective f hf I).symm ▸ le_antisymm
(sup_le (le_refl _) I.2) le_sup_left,
ord := λ I1 I2, ⟨comap_mono, λ H, map_comap_of_surjective f hf I1 ▸
map_comap_of_surjective f hf I2 ▸ map_mono H⟩ }
def le_order_embedding_of_surjective :
((≤) : ideal S → ideal S → Prop) ≼o ((≤) : ideal R → ideal R → Prop) :=
(order_iso_of_surjective f hf).to_order_embedding.trans (subtype.order_embedding _ _)
def lt_order_embedding_of_surjective :
((<) : ideal S → ideal S → Prop) ≼o ((<) : ideal R → ideal R → Prop) :=
(le_order_embedding_of_surjective f hf).lt_embedding_of_le_embedding
end surjective
end map_and_comap
end ideal
namespace is_ring_hom
variables {R : Type u} {S : Type v} (f : R → S) [comm_ring R]
section comm_ring
variables [comm_ring S] [is_ring_hom f]
def ker : ideal R := ideal.comap f ⊥
/-- An element is in the kernel if and only if it maps to zero.-/
lemma mem_ker {r} : r ∈ ker f ↔ f r = 0 :=
by rw [ker, ideal.mem_comap, submodule.mem_bot]
lemma ker_eq : ((ker f) : set R) = is_add_group_hom.ker f := rfl
lemma inj_iff_ker_eq_bot : function.injective f ↔ ker f = ⊥ :=
by rw [←submodule.ext'_iff, ker_eq]; exact is_add_group_hom.inj_iff_trivial_ker f
lemma ker_eq_bot_iff_eq_zero : ker f = ⊥ ↔ ∀ x, f x = 0 → x = 0 :=
by rw [←submodule.ext'_iff, ker_eq]; exact is_add_group_hom.trivial_ker_iff_eq_zero f
lemma injective_iff : function.injective f ↔ ∀ x, f x = 0 → x = 0 :=
is_add_group_hom.injective_iff f
end comm_ring
/-- If the target is not the zero ring, then one is not in the kernel.-/
lemma not_one_mem_ker [nonzero_comm_ring S] [is_ring_hom f] : (1:R) ∉ ker f :=
by { rw [mem_ker, is_ring_hom.map_one f], exact one_ne_zero }
/-- The kernel of a homomorphism to an integral domain is a prime ideal.-/
lemma ker_is_prime [integral_domain S] [is_ring_hom f] :
(ker f).is_prime :=
⟨by { rw [ne.def, ideal.eq_top_iff_one], exact not_one_mem_ker f },
λ x y, by simpa only [mem_ker, is_ring_hom.map_mul f] using eq_zero_or_eq_zero_of_mul_eq_zero⟩
end is_ring_hom
namespace submodule
variables {R : Type u} {M : Type v}
variables [comm_ring R] [add_comm_group M] [module R M]
-- It is even a semialgebra. But those aren't in mathlib yet.
instance : semimodule (ideal R) (submodule R M) :=
{ smul_add := smul_sup,
add_smul := sup_smul,
mul_smul := smul_assoc,
one_smul := by simp,
zero_smul := bot_smul,
smul_zero := smul_bot }
end submodule
|
c686fb1eef5f591e286f8b381c70baa6d121d350 | 0d9b0a832bc57849732c5bd008a7a142f7e49656 | /src/boolset2d.lean | 58bd19cb750a29bbc50db503a81e2559d7243de9 | [] | no_license | mirefek/sokoban.lean | bb9414af67894e4d8ce75f8c8d7031df02d371d0 | 451c92308afb4d3f8e566594b9751286f93b899b | refs/heads/master | 1,681,025,245,267 | 1,618,997,832,000 | 1,618,997,832,000 | 359,491,681 | 10 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 17,887 | lean | import data.list.func
import .helpers
import .list2d
import .find_indexes2d
def bset1d := list bool
def bset2d := list2d bool
instance : inhabited bset1d := ⟨[]⟩
instance : inhabited bset2d := ⟨[]⟩
instance : has_mem ℕ bset1d :=
⟨λ n l, list.func.get n l = tt⟩
instance : has_mem (ℕ×ℕ) bset2d :=
⟨λ xy l, list2d.get2d xy l = tt⟩
lemma bset1d.has_mem.unfold {n : ℕ} {l : bset1d}
: n ∈ l = (list.func.get n l = tt) := rfl
lemma bset2d.has_mem.unfold {xy : ℕ×ℕ} {l : bset2d}
: xy ∈ l = (list2d.get2d xy l = tt) := rfl
instance : has_sdiff bset2d
:= ⟨list2d.pointwise2d (λ a b, (cond b ff a))⟩
instance : has_inter bset2d
:= ⟨list2d.pointwise2d band⟩
instance : has_union bset2d
:= ⟨list2d.pointwise2d bor⟩
def pic_str1d (l : bset1d) : string :=
string.push (list.as_string (l.map (λb, cond b '*' '.'))) '\n'
def pic_str2d (l : bset2d) : string :=
string.join (l.map pic_str1d)
instance : has_repr bset1d := ⟨pic_str1d⟩
instance : has_repr bset2d := ⟨pic_str2d⟩
-- _ _
-- ___ _ _| |__ ___ ___| |_
-- / __| | | | '_ \/ __|/ _ \ __|
-- \__ \ |_| | |_) \__ \ __/ |_
-- |___/\__,_|_.__/|___/\___|\__|
--
def bset1d.subset (l1 : bset1d) (l2 : bset1d) : Prop
:= ∀ x : ℕ, x ∈ l1 → x ∈ l2
def bset2d.subset (l1 : bset2d) (l2 : bset2d) : Prop
:= ∀ xy : ℕ×ℕ, xy ∈ l1 → xy ∈ l2
instance : has_subset bset1d := ⟨bset1d.subset⟩
instance : has_subset bset2d := ⟨bset2d.subset⟩
def bset2d.disjoint (l1 : bset2d) (l2 : bset2d) : Prop
:= ∀ xy : ℕ×ℕ, xy ∈ l1 → xy ∈ l2 → false
theorem bset2d.subset.refl : ∀ {l1 : bset2d}, l1 ⊆ l1
:= assume l1 xy H, H
theorem bset2d.subset.trans : ∀ {l1 l2 l3 : bset2d},
l1 ⊆ l2 → l2 ⊆ l3 → l1 ⊆ l3
:= assume l1 l2 l3 H12 H23 xy H1, H23 xy (H12 xy H1)
theorem bset2d.subset_of_equiv : ∀ {l1 l2 : bset2d},
list2d.equiv l1 l2 → l1 ⊆ l2 :=
begin
intros l1 l2 Heq xy Hget,
unfold has_mem.mem at Hget,
rw Heq xy at Hget, exact Hget,
end
-- _ _
-- ___ ___ _ _ _ __ | |_(_)_ __ __ _
-- / __/ _ \| | | | '_ \| __| | '_ \ / _` |
-- | (_| (_) | |_| | | | | |_| | | | | (_| |
-- \___\___/ \__,_|_| |_|\__|_|_| |_|\__, |
-- |___/
def bset1d.count (l : bset1d) : ℕ := list.sum (list.map bool.to_nat l)
def bset2d.count (l : bset2d) : ℕ := list.sum (list.map bset1d.count l)
@[simp] theorem bset1d.count_nil : bset1d.count [] = 0 := rfl
@[simp] theorem bset2d.count_nil : bset2d.count [] = 0 := rfl
@[simp] theorem bset1d.count_cons : ∀ (h : bool) (t : bset1d),
bset1d.count (h::t) = (bool.to_nat h) + t.count := by simp [bset1d.count]
@[simp] theorem bset2d.count_cons : ∀ (h : bset1d) (t : bset2d),
bset2d.count (h::t) = h.count + t.count := by simp [bset2d.count]
-- _ _ _
-- ___ ___ _ _ _ __ | |_ _ ___ _ _| |__ ___ ___| |_
-- / __/ _ \| | | | '_ \| __| _| |_ / __| | | | '_ \/ __|/ _ \ __|
-- | (_| (_) | |_| | | | | |_ |_ _| \__ \ |_| | |_) \__ \ __/ |_
-- \___\___/ \__,_|_| |_|\__| |_| |___/\__,_|_.__/|___/\___|\__|
--
theorem bool_to_nat_le {b1 b2 : bool} :
(b1.to_nat ≤ b2.to_nat) ↔ (b1 = tt → b2 = tt) :=
begin
intros, split, {
intro H, cases b1, simp,
cases b2, simp [bool.to_nat] at H, contradiction,
simp,
}, {
intro H, cases b1, simp [bool.to_nat],
cases b2, simp at H, contradiction,
apply le_rfl,
}
end
theorem bset1d.subset_cons : ∀ (h1 h2 : bool) (t1 t2 : bset1d),
bset1d.subset (h1::t1) (h2::t2) = (h1.to_nat ≤ h2.to_nat ∧ t1 ⊆ t2) :=
begin
intros, apply propext, split, {
intro H, split, exact bool_to_nat_le.2 (H 0),
intro n, exact H n.succ
}, {
intro H, cases H with H1 H2,
intro n, cases n, exact bool_to_nat_le.1 H1,
exact H2 n,
}
end
theorem bset2d.subset_cons : ∀ (h1 h2 : bset1d) (t1 t2 : bset2d),
bset2d.subset (h1::t1) (h2::t2) = (h1 ⊆ h2 ∧ t1 ⊆ t2) :=
begin
intros, apply propext, split, {
intro H, split, intro x, exact H (x,0),
intro xy, cases xy with x y, exact H (x,y+1)
}, {
intro H, cases H with H1 H2,
intro xy, cases xy with x y, cases y, apply H1,
exact H2 (x, y),
}
end
theorem bset1d.count_0_of_subset_nil : ∀ l : bset1d,
bset1d.subset l list.nil → l.count = 0
| [] := by simp
| (h::t) := begin
intro H, simp, split, {
have := H 0, simp [has_mem.mem] at this,
rw bool_eq_false this, refl,
}, {
apply bset1d.count_0_of_subset_nil,
intros n H2, specialize H (n+1), simp [has_mem.mem] at H, contradiction,
}
end
theorem bset2d.count_0_of_subset_nil : ∀ l : bset2d,
bset2d.subset l list.nil → l.count = 0
| [] := by simp
| (h::t) := begin
intro H, simp, split, {
apply bset1d.count_0_of_subset_nil,
intro x, exact H (x,0),
}, {
apply bset2d.count_0_of_subset_nil,
intros xy H2, cases xy with x y,
specialize H (x,y+1), simp [has_mem.mem] at H, contradiction,
}
end
theorem bset1d.count_le_of_subset : ∀ l1 l2 : bset1d,
l1 ⊆ l2 → l1.count ≤ l2.count
| [] _ := by simp
| _ [] := begin
intros H, have H := bset1d.count_0_of_subset_nil _ H, rewrite H,
apply zero_le,
end
| (h1::t1) (h2::t2) := begin
simp [has_subset.subset, bset1d.subset_cons], intros Hh Ht, apply add_le_add,
exact Hh,
exact bset1d.count_le_of_subset _ _ Ht,
end
theorem bset2d.count_le_of_subset : ∀ l1 l2 : bset2d,
l1 ⊆ l2 → l1.count ≤ l2.count
| [] _ := by simp
| _ [] := begin
intros H, have H := bset2d.count_0_of_subset_nil _ H, rewrite H,
apply zero_le,
end
| (h1::t1) (h2::t2) := begin
simp [has_subset.subset, bset2d.subset_cons], intros Hh Ht, apply add_le_add,
exact bset1d.count_le_of_subset _ _ Hh,
exact bset2d.count_le_of_subset _ _ Ht,
end
lemma leq_sum_equal {a b c d : ℕ} :
a ≤ b → c ≤ d → a+c = b+d → a=b ∧ c=d := by omega
theorem bset1d.subset_nil_of_count_0 : ∀ l : bset1d,
l.count = 0 → bset1d.subset l list.nil
| [] := λ _ _ H, H
| (h::t) := begin
simp, intros Hh Ht n, cases n, {
cases h, intro H, simp at H, contradiction,
simp [bool.to_nat] at Hh, contradiction,
}, {
have := bset1d.subset_nil_of_count_0 t Ht n,
simp [has_mem.mem], simp [has_mem.mem] at this, exact this,
}
end
theorem bset2d.subset_nil_of_count_0 : ∀ l : bset2d,
l.count = 0 → bset2d.subset l list.nil
| [] := λ _ _ H, H
| (h::t) := begin
simp, intros Hh Ht xy, cases xy with x y, cases y, {
exact bset1d.subset_nil_of_count_0 h Hh x,
}, {
have := bset2d.subset_nil_of_count_0 t Ht (x,y),
simp [has_mem.mem], simp [has_mem.mem] at this, exact this,
}
end
theorem bset1d.subset_eq_of_count_eq : ∀ l1 l2 : bset1d,
l1 ⊆ l2 → l1.count = l2.count → l2 ⊆ l1
| _ [] := begin simp [has_mem.mem, has_subset.subset, bset1d.subset], end
| [] l2 := begin
intros Hh Hc, simp at Hc,
apply bset1d.subset_nil_of_count_0 l2 (eq.symm Hc),
end
| (h1::t1) (h2::t2) := begin
simp [has_subset.subset, bset1d.subset_cons], intros Hh Ht Hc,
have Ht_le := bset1d.count_le_of_subset t1 t2 Ht,
cases leq_sum_equal Hh Ht_le Hc with Eh Et,
split, simp! [Eh],
exact bset1d.subset_eq_of_count_eq t1 t2 Ht Et,
end
theorem bset2d.subset_eq_of_count_eq : ∀ l1 l2 : bset2d,
l1 ⊆ l2 → l1.count = l2.count → l2 ⊆ l1
| _ [] := by simp [has_mem.mem, has_subset.subset, bset2d.subset]
| [] l2 := begin
intros Hh Hc, simp at Hc,
apply bset2d.subset_nil_of_count_0 l2 (eq.symm Hc),
end
| (h1::t1) (h2::t2) := begin
simp [has_subset.subset, bset1d.subset_cons, bset2d.subset_cons],
intros Hh Ht Hc,
have Hh_le := bset1d.count_le_of_subset h1 h2 Hh,
have Ht_le := bset2d.count_le_of_subset t1 t2 Ht,
cases leq_sum_equal Hh_le Ht_le Hc with Eh Et,
split, apply bset1d.subset_eq_of_count_eq h1 h2 Hh Eh,
exact bset2d.subset_eq_of_count_eq t1 t2 Ht Et,
end
-- _ _
-- __ _ __| | __| | _ _ __ ___ _ __ ___ _____ _____
-- / _` |/ _` |/ _` | _| |_ | '__/ _ \ '_ ` _ \ / _ \ \ / / _ \
-- | (_| | (_| | (_| | |_ _| | | | __/ | | | | | (_) \ V / __/
-- \__,_|\__,_|\__,_| |_| |_| \___|_| |_| |_|\___/ \_/ \___|
--
def bset2d.add (xy : ℕ×ℕ) (l : bset2d) : bset2d := list2d.set2d tt l xy
def bset2d.remove (xy : ℕ×ℕ) (l : bset2d) : bset2d := list2d.set2d ff l xy
lemma bset2d.mem_add {xy : ℕ×ℕ} {l : bset2d}
: xy ∈ (l.add xy) := list2d.get2d_set2d
lemma bset2d.mem_add_of_mem {xy xy' : ℕ×ℕ} {l : bset2d}
: xy ∈ l → xy ∈ (l.add xy') := begin
assume H, by_cases C : xy = xy', rw C, exact list2d.get2d_set2d,
exact eq.trans (list2d.get2d_set2d_eq_of_ne C) H,
end
lemma bset2d.nmem_add_of_neq_nmem {xy xy' : ℕ×ℕ} {l : bset2d}
: xy ≠ xy' → xy ∉ l → xy ∉ (l.add xy')
:= λ Hn Hl Hadd, Hl (eq.trans (list2d.get2d_set2d_eq_of_ne Hn).symm Hadd)
lemma bset2d.nmem_remove {xy : ℕ×ℕ} {l : bset2d}
: xy ∉ (l.remove xy)
:= by simp [has_mem.mem, bset2d.remove, list2d.get2d_set2d]
lemma bset2d.nmem_remove_of_nmem {xy xy' : ℕ×ℕ} {l : bset2d}
: xy ∉ l → xy ∉ (l.remove xy') := begin
assume H, by_cases C : xy = xy', rw C, exact bset2d.nmem_remove,
assume Hrem, exact H (eq.trans (list2d.get2d_set2d_eq_of_ne C).symm Hrem),
end
lemma bset2d.mem_remove_of_neq_mem {xy xy' : ℕ×ℕ} {l : bset2d}
: xy ≠ xy' → xy ∈ l → xy ∈ (l.remove xy')
:= λ Hn Hl, eq.trans (list2d.get2d_set2d_eq_of_ne Hn) Hl
lemma bset2d.of_mem_add {xy xy' : ℕ×ℕ} {l : bset2d}
: xy ∈ (l.add xy') → xy = xy' ∨ xy ∈ l := begin
intro H, by_cases C : xy = xy', left, exact C,
right, by_contradiction Hnl,
exact bset2d.nmem_add_of_neq_nmem C Hnl H,
end
lemma bset2d.nmem_of_nmem_add {xy xy' : ℕ×ℕ} {l : bset2d}
: xy ∉ (l.add xy') → xy ∉ l :=
begin
intros Hnadd, by_contradiction Hl,
exact Hnadd (bset2d.mem_add_of_mem Hl),
end
lemma bset2d.neq_of_nmem_add {xy xy' : ℕ×ℕ} {l : bset2d}
: xy ∉ (l.add xy') → xy ≠ xy' :=
begin
intros Hnadd Heq, rw Heq at Hnadd,
exact Hnadd (bset2d.mem_add),
end
lemma bset2d.of_nmem_remove {xy xy' : ℕ×ℕ} {l : bset2d}
: xy ∉ (l.remove xy') → xy = xy' ∨ xy ∉ l := begin
intro H, by_cases C : xy = xy', left, exact C,
right, by_contradiction Hl,
refine H (bset2d.mem_remove_of_neq_mem _ Hl),
assume Cn, exact C Cn,
end
lemma bset2d.mem_of_mem_remove {xy xy' : ℕ×ℕ} {l : bset2d}
: xy ∈ (l.remove xy') → xy ∈ l := begin
intro Hrem, by_contradiction Hnl,
exact bset2d.nmem_remove_of_nmem Hnl Hrem,
end
lemma bset2d.neq_of_mem_remove {xy xy' : ℕ×ℕ} {l : bset2d}
: xy ∈ (l.remove xy') → xy ≠ xy' := begin
intros Hrem Heq, rw Heq at Hrem,
exact bset2d.nmem_remove Hrem,
end
lemma bset2d.subset_add_same {l1 l2 : bset2d} {xy : ℕ×ℕ}
: l1 ⊆ l2 → l1.add xy ⊆ l2.add xy
:= begin
intros Hsub xy' Hin, cases bset2d.of_mem_add Hin,
rw h, exact bset2d.mem_add,
apply bset2d.mem_add_of_mem, exact Hsub xy' h,
end
lemma bset2d.subset_remove_same {l1 l2 : bset2d} {xy : ℕ×ℕ}
: l1 ⊆ l2 → l1.remove xy ⊆ l2.remove xy
:= begin
intros Hsub xy' Hin, apply bset2d.mem_remove_of_neq_mem,
exact bset2d.neq_of_mem_remove Hin,
apply Hsub,
exact bset2d.mem_of_mem_remove Hin,
end
-- _ _ _
-- ___ ___ _ _ _ __ | |_ _ _ _ _ __ __| | __ _| |_ ___
-- / __/ _ \| | | | '_ \| __| _| |_ | | | | '_ \ / _` |/ _` | __/ _ \
-- | (_| (_) | |_| | | | | |_ |_ _| | |_| | |_) | (_| | (_| | || __/
-- \___\___/ \__,_|_| |_|\__| |_| \__,_| .__/ \__,_|\__,_|\__\___|
-- |_|
lemma bset1d.count_update : ∀ (b : bool) (l : bset1d) (n : ℕ),
∃ c, bset1d.count l = c + (list.func.get n l).to_nat
∧ bset1d.count (list.func.set b l n) = c + b.to_nat
:=
list.sum_map_update bool.to_nat rfl
lemma bset2d.count_update : ∀ (b : bool) (l : bset2d) (xy : ℕ×ℕ),
∃ c, bset2d.count l = c + (list2d.get2d xy l).to_nat
∧ bset2d.count (list2d.set2d b l xy) = c + b.to_nat
:=
begin
intros, cases xy with x y,
rcases list.sum_map_update bset1d.count rfl
(list.func.set b (list.func.get y l) x) l y
with ⟨c1, H1old, H1new⟩,
rcases bset1d.count_update b (list.func.get y l) x
with ⟨c2, H2old, H2new⟩,
existsi c1 + c2,
split, {
unfold bset2d.count, rw H1old, rw H2old,
rw ←add_assoc, refl,
}, {
unfold bset2d.count, unfold list2d.set2d,
rw H1new, rw H2new, rw ←add_assoc,
}
end
lemma bset2d.count_add {xy : ℕ×ℕ} {l : bset2d}
: xy ∉ l → (l.add xy).count = l.count+1
:=
begin
rcases bset2d.count_update tt l xy with ⟨c,Hold,Hnew⟩,
assume Hnin : xy ∉ l,
rw bool_eq_false Hnin at Hold, clear Hnin,
unfold bset2d.add, rw Hnew, rw Hold,
simp [bool.to_nat],
end
lemma bset2d.count_remove {xy : ℕ×ℕ} {l : bset2d}
: xy ∈ l → (l.remove xy).count+1 = l.count
:=
begin
rcases bset2d.count_update ff l xy with ⟨c,Hold,Hnew⟩,
assume Hin : xy ∈ l,
rw bset2d.has_mem.unfold at Hin, rw Hin at Hold, clear Hin,
unfold bset2d.remove, rw Hnew, rw Hold,
simp [bool.to_nat],
end
-- _ _ __ __
-- ___ __| (_)/ _|/ _|
-- / __|/ _` | | |_| |_
-- \__ \ (_| | | _| _|
-- |___/\__,_|_|_| |_|
--
lemma bset2d.mem_sdiff_of_mem_nmem {xy : ℕ×ℕ} {l1 l2 : bset2d}
: xy ∈ l1 → xy ∉ l2 → xy ∈ l1 \ l2 :=
begin
simp [has_sdiff.sdiff, has_mem.mem, list2d.get2d_pointwise],
intros H1 H2, simp! [H1, H2],
end
lemma bset2d.mem_of_mem_sdiff {xy : ℕ×ℕ} {l1 l2 : bset2d}
: xy ∈ l1 \ l2 → xy ∈ l1 :=
begin
simp [has_sdiff.sdiff, has_mem.mem, list2d.get2d_pointwise],
assume H, cases (list2d.get2d xy l2), exact H, exact bool.no_confusion H,
end
lemma bset2d.nmem_of_mem_sdiff {xy : ℕ×ℕ} {l1 l2 : bset2d}
: xy ∈ l1 \ l2 → xy ∉ l2 :=
begin
simp [has_sdiff.sdiff, has_mem.mem, list2d.get2d_pointwise],
assume H, cases (list2d.get2d xy l2), refl, exact bool.no_confusion H,
end
lemma bset2d.sdiff_subset {l1 l2 : bset2d} : l1 \ l2 ⊆ l1
:= assume xy, bset2d.mem_of_mem_sdiff
-- _ _ _
-- (_)_ __ | |_ ___ _ __ _ _ _ _ __ (_) ___ _ __
-- | | '_ \| __/ _ \ '__| _| |_ | | | | '_ \| |/ _ \| '_ \
-- | | | | | || __/ | |_ _| | |_| | | | | | (_) | | | |
-- |_|_| |_|\__\___|_| |_| \__,_|_| |_|_|\___/|_| |_|
--
lemma bset2d.inter_subset_left {l1 l2 : bset2d} : l1 ∩ l2 ⊆ l1
:=
assume xy,
assume H,
have this : list2d.get2d xy l1 && list2d.get2d xy l2 = tt
:= eq.trans (eq.symm (list2d.get2d_pointwise rfl _ _ _)) H,
show xy ∈ l1, from ((band_coe_iff _ _).mp this).1
lemma bset2d.inter_subset_right {l1 l2 : bset2d} : l1 ∩ l2 ⊆ l2
:=
assume xy,
assume H,
have this : list2d.get2d xy l1 && list2d.get2d xy l2 = tt
:= eq.trans (eq.symm (list2d.get2d_pointwise rfl _ _ _)) H,
show xy ∈ l2, from ((band_coe_iff _ _).mp this).2
lemma bset2d.union_subset {l1 l2 l3 : bset2d} : l1 ⊆ l3 → l2 ⊆ l3 → l1 ∪ l2 ⊆ l3
:=
begin
assume H1 H2 xy Hin,
have this : list2d.get2d xy l1 || list2d.get2d xy l2 = tt
:= eq.trans (eq.symm (list2d.get2d_pointwise rfl _ _ _)) Hin,
cases (bor_coe_iff _ _).mp this with Hin1 Hin2,
exact H1 xy Hin1,
exact H2 xy Hin2,
end
lemma bset2d.union_supset_left {l1 l2 : bset2d} : l1 ⊆ l1 ∪ l2
:=
begin
assume xy,
assume H,
refine eq.trans (list2d.get2d_pointwise rfl _ _ _) _,
exact (congr_arg (λ a, a || list2d.get2d xy l2) H).trans (tt_bor _),
end
lemma bset2d.union_supset_right {l1 l2 : bset2d} : l2 ⊆ l1 ∪ l2
:=
begin
assume xy,
assume H,
refine eq.trans (list2d.get2d_pointwise rfl _ _ _) _,
exact (congr_arg (bor _) H).trans (bor_tt _),
end
-- _ _
-- (_)_ __ __| | _____ _____ ___
-- | | '_ \ / _` |/ _ \ \/ / _ \/ __|
-- | | | | | (_| | __/> < __/\__ \
-- |_|_| |_|\__,_|\___/_/\_\___||___/
--
def bset2d.from_index (xy : ℕ×ℕ) : bset2d := list2d.set2d tt [] xy
def bset2d.from_indexes (xys : list (ℕ × ℕ)) : bset2d
:= list.foldr (λ (xy : ℕ×ℕ) (l : bset2d), l.set2d tt xy) [] xys
def bset2d.to_indexes (s : bset2d) : list (ℕ × ℕ)
:= s.find_indexes2d (eq tt)
theorem bset2d.from_index_iff (xy : ℕ×ℕ)
: ∀ xy' : ℕ×ℕ, xy' ∈ bset2d.from_index xy ↔ xy' = xy :=
begin
intro xy', split, {
intro H, by_contradiction C,
unfold has_mem.mem at H, unfold bset2d.from_index at H,
rw list2d.get2d_set2d_eq_of_ne at H, simp at H, exact H, exact C,
}, {
intro H, rw H, unfold bset2d.from_index, unfold has_mem.mem,
exact list2d.get2d_set2d,
}
end
theorem bset2d.from_indexes_iff (xys : list (ℕ×ℕ))
: ∀ xy : ℕ×ℕ, xy ∈ bset2d.from_indexes xys ↔ xy ∈ xys :=
begin
intro xy, induction xys with xy' t IH, {
simp! [bset2d.from_indexes, has_mem.mem],
}, {
by_cases C : xy = xy',
{ rw ←C, simp! [has_mem.mem, bset2d.from_indexes, list2d.get2d_set2d], },
simp [bset2d.from_indexes], unfold has_mem.mem,
rw list2d.get2d_set2d_eq_of_ne C,
split,
{ intro H, right, exact IH.mp H, },
{ intro H, cases H, exact false.elim (C H),
exact IH.mpr H, },
},
end
theorem bset2d.to_indexes_iff (s : bset2d)
: ∀ xy : ℕ×ℕ, xy ∈ bset2d.to_indexes s ↔ xy ∈ s :=
begin
intro xy,
unfold bset2d.to_indexes, rw bset2d.has_mem.unfold,
rw ←list2d.find_indexes2d_iff, exact eq_comm, simp!,
end
|
3752e38addf6f5ffc36f43dadf280bd3fb3bdec5 | efa51dd2edbbbbd6c34bd0ce436415eb405832e7 | /20150320_CMU/undecidable.lean | 67b1ae46d7dee2d9147c4c3cbd17618e54368b20 | [
"Apache-2.0"
] | permissive | leanprover/presentations | dd031a05bcb12c8855676c77e52ed84246bd889a | 3ce2d132d299409f1de269fa8e95afa1333d644e | refs/heads/master | 1,688,703,388,796 | 1,686,838,383,000 | 1,687,465,742,000 | 29,750,158 | 12 | 9 | Apache-2.0 | 1,540,211,670,000 | 1,422,042,683,000 | Lean | UTF-8 | Lean | false | false | 781 | lean | -- Church number λx f, f (f (f ... (f x) ...))
constant i : Type₁
definition Num := i → (i → i) → i
definition add (n : Num) (m : Num) : Num :=
λx f, n (m x f) f
definition mul (n : Num) (m : Num) : Num :=
λx f, n x (λz, (m z f))
definition zero : Num := λx f, x
definition one : Num := λx f, f x
definition two : Num := λx f, f (f x)
definition three : Num := λx f, f (f (f x))
definition four : Num := λx f, f (f (f (f x)))
attribute zero one two three add mul four [reducible]
notation a + b := add a b
notation a * b := mul a b
notation 0 := zero
notation 1 := one
notation 2 := two
notation 3 := three
notation 4 := four
constant C : Num → Type₁
constant mk : Π (n : Num), C n
example : C (3 + 3 + 2) := mk (2 * _)
|
953266708cff7c1c9d880a25828d39ca6433c76d | 4727251e0cd73359b15b664c3170e5d754078599 | /src/geometry/manifold/local_invariant_properties.lean | 5ac943c74f0a5881afaaa1468721aeec58116dbd | [
"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 | 25,412 | 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 geometry.manifold.charted_space
/-!
# Local properties invariant under a groupoid
We study properties of a triple `(g, s, x)` where `g` is a function between two spaces `H` and `H'`,
`s` is a subset of `H` and `x` is a point of `H`. Our goal is to register how such a property
should behave to make sense in charted spaces modelled on `H` and `H'`.
The main examples we have in mind are the properties "`g` is differentiable at `x` within `s`", or
"`g` is smooth at `x` within `s`". We want to develop general results that, when applied in these
specific situations, say that the notion of smooth function in a manifold behaves well under
restriction, intersection, is local, and so on.
## Main definitions
* `local_invariant_prop G G' P` says that a property `P` of a triple `(g, s, x)` is local, and
invariant under composition by elements of the groupoids `G` and `G'` of `H` and `H'`
respectively.
* `charted_space.lift_prop_within_at` (resp. `lift_prop_at`, `lift_prop_on` and `lift_prop`):
given a property `P` of `(g, s, x)` where `g : H → H'`, define the corresponding property
for functions `M → M'` where `M` and `M'` are charted spaces modelled respectively on `H` and
`H'`. We define these properties within a set at a point, or at a point, or on a set, or in the
whole space. This lifting process (obtained by restricting to suitable chart domains) can always
be done, but it only behaves well under locality and invariance assumptions.
Given `hG : local_invariant_prop G G' P`, we deduce many properties of the lifted property on the
charted spaces. For instance, `hG.lift_prop_within_at_inter` says that `P g s x` is equivalent to
`P g (s ∩ t) x` whenever `t` is a neighborhood of `x`.
## Implementation notes
We do not use dot notation for properties of the lifted property. For instance, we have
`hG.lift_prop_within_at_congr` saying that if `lift_prop_within_at P g s x` holds, and `g` and `g'`
coincide on `s`, then `lift_prop_within_at P g' s x` holds. We can't call it
`lift_prop_within_at.congr` as it is in the namespace associated to `local_invariant_prop`, not
in the one for `lift_prop_within_at`.
-/
noncomputable theory
open_locale classical manifold topological_space
open set
variables {H : Type*} {M : Type*} [topological_space H] [topological_space M] [charted_space H M]
{H' : Type*} {M' : Type*} [topological_space H'] [topological_space M'] [charted_space H' M']
namespace structure_groupoid
variables (G : structure_groupoid H) (G' : structure_groupoid H')
/-- Structure recording good behavior of a property of a triple `(f, s, x)` where `f` is a function,
`s` a set and `x` a point. Good behavior here means locality and invariance under given groupoids
(both in the source and in the target). Given such a good behavior, the lift of this property
to charted spaces admitting these groupoids will inherit the good behavior. -/
structure local_invariant_prop (P : (H → H') → (set H) → H → Prop) : Prop :=
(is_local : ∀ {s x u} {f : H → H'}, is_open u → x ∈ u → (P f s x ↔ P f (s ∩ u) x))
(right_invariance : ∀ {s x f} {e : local_homeomorph H H}, e ∈ G → x ∈ e.source → P f s x →
P (f ∘ e.symm) (e.target ∩ e.symm ⁻¹' s) (e x))
(congr : ∀ {s x} {f g : H → H'}, (∀ y ∈ s, f y = g y) → (f x = g x) → P f s x → P g s x)
(left_invariance : ∀ {s x f} {e' : local_homeomorph H' H'}, e' ∈ G' → s ⊆ f ⁻¹' (e'.source) →
f x ∈ e'.source → P f s x → P (e' ∘ f) s x)
end structure_groupoid
/-- Given a property of germs of functions and sets in the model space, then one defines
a corresponding property in a charted space, by requiring that it holds at the preferred chart at
this point. (When the property is local and invariant, it will in fact hold using any chart, see
`lift_prop_within_at_indep_chart`). We require continuity in the lifted property, as otherwise one
single chart might fail to capture the behavior of the function.
-/
def charted_space.lift_prop_within_at (P : (H → H') → set H → H → Prop)
(f : M → M') (s : set M) (x : M) : Prop :=
continuous_within_at f s x ∧
P ((chart_at H' (f x)) ∘ f ∘ (chart_at H x).symm)
((chart_at H x).target ∩ (chart_at H x).symm ⁻¹' (s ∩ f ⁻¹' (chart_at H' (f x)).source))
(chart_at H x x)
/-- Given a property of germs of functions and sets in the model space, then one defines
a corresponding property of functions on sets in a charted space, by requiring that it holds
around each point of the set, in the preferred charts. -/
def charted_space.lift_prop_on (P : (H → H') → set H → H → Prop) (f : M → M') (s : set M) :=
∀ x ∈ s, charted_space.lift_prop_within_at P f s x
/-- Given a property of germs of functions and sets in the model space, then one defines
a corresponding property of a function at a point in a charted space, by requiring that it holds
in the preferred chart. -/
def charted_space.lift_prop_at (P : (H → H') → set H → H → Prop) (f : M → M') (x : M) :=
charted_space.lift_prop_within_at P f univ x
/-- Given a property of germs of functions and sets in the model space, then one defines
a corresponding property of a function in a charted space, by requiring that it holds
in the preferred chart around every point. -/
def charted_space.lift_prop (P : (H → H') → set H → H → Prop) (f : M → M') :=
∀ x, charted_space.lift_prop_at P f x
open charted_space
namespace structure_groupoid
variables {G : structure_groupoid H} {G' : structure_groupoid H'}
{e e' : local_homeomorph M H} {f f' : local_homeomorph M' H'}
{P : (H → H') → set H → H → Prop} {g g' : M → M'} {s t : set M} {x : M}
{Q : (H → H) → set H → H → Prop}
lemma lift_prop_within_at_univ :
lift_prop_within_at P g univ x ↔ lift_prop_at P g x :=
iff.rfl
lemma lift_prop_on_univ :
lift_prop_on P g univ ↔ lift_prop P g :=
by simp [lift_prop_on, lift_prop, lift_prop_at]
namespace local_invariant_prop
variable (hG : G.local_invariant_prop G' P)
include hG
/-- If a property of a germ of function `g` on a pointed set `(s, x)` is invariant under the
structure groupoid (by composition in the source space and in the target space), then
expressing it in charted spaces does not depend on the element of the maximal atlas one uses
both in the source and in the target manifolds, provided they are defined around `x` and `g x`
respectively, and provided `g` is continuous within `s` at `x` (otherwise, the local behavior
of `g` at `x` can not be captured with a chart in the target). -/
lemma lift_prop_within_at_indep_chart_aux
(he : e ∈ G.maximal_atlas M) (xe : x ∈ e.source)
(he' : e' ∈ G.maximal_atlas M) (xe' : x ∈ e'.source)
(hf : f ∈ G'.maximal_atlas M') (xf : g x ∈ f.source)
(hf' : f' ∈ G'.maximal_atlas M') (xf' : g x ∈ f'.source)
(hgs : continuous_within_at g s x)
(h : P (f ∘ g ∘ e.symm) (e.target ∩ e.symm ⁻¹' (s ∩ g⁻¹' f.source)) (e x)) :
P (f' ∘ g ∘ e'.symm) (e'.target ∩ e'.symm ⁻¹' (s ∩ g⁻¹' f'.source)) (e' x) :=
begin
obtain ⟨o, o_open, xo, oe, oe', of, of'⟩ :
∃ (o : set M), is_open o ∧ x ∈ o ∧ o ⊆ e.source ∧ o ⊆ e'.source ∧
o ∩ s ⊆ g ⁻¹' f.source ∧ o ∩ s ⊆ g⁻¹' f'.to_local_equiv.source,
{ have : f.source ∩ f'.source ∈ 𝓝 (g x) :=
is_open.mem_nhds (is_open.inter f.open_source f'.open_source) ⟨xf, xf'⟩,
rcases mem_nhds_within.1 (hgs.preimage_mem_nhds_within this) with ⟨u, u_open, xu, hu⟩,
refine ⟨u ∩ e.source ∩ e'.source, _, ⟨⟨xu, xe⟩, xe'⟩, _, _, _, _⟩,
{ exact is_open.inter (is_open.inter u_open e.open_source) e'.open_source },
{ assume x hx, exact hx.1.2 },
{ assume x hx, exact hx.2 },
{ assume x hx, exact (hu ⟨hx.1.1.1, hx.2⟩).1 },
{ assume x hx, exact (hu ⟨hx.1.1.1, hx.2⟩).2 } },
have A : P (f ∘ g ∘ e.symm)
(e.target ∩ e.symm ⁻¹' (s ∩ g⁻¹' f.source) ∩ (e.target ∩ e.symm ⁻¹' o)) (e x),
{ apply (hG.is_local _ _).1 h,
{ exact e.continuous_on_symm.preimage_open_of_open e.open_target o_open },
{ simp only [xe, xo] with mfld_simps} },
have B : P ((f.symm ≫ₕ f') ∘ (f ∘ g ∘ e.symm))
(e.target ∩ e.symm ⁻¹' (s ∩ g⁻¹' f.source) ∩ (e.target ∩ e.symm ⁻¹' o)) (e x),
{ refine hG.left_invariance (compatible_of_mem_maximal_atlas hf hf') (λ y hy, _)
(by simp only [xe, xf, xf'] with mfld_simps) A,
simp only with mfld_simps at hy,
have : e.symm y ∈ o ∩ s, by simp only [hy] with mfld_simps,
simpa only [hy] with mfld_simps using of' this },
have C : P (f' ∘ g ∘ e.symm)
(e.target ∩ e.symm ⁻¹' (s ∩ g⁻¹' f.source) ∩ (e.target ∩ e.symm ⁻¹' o)) (e x),
{ refine hG.congr (λ y hy, _) (by simp only [xe, xf] with mfld_simps) B,
simp only [local_homeomorph.coe_trans, function.comp_app],
rw f.left_inv,
apply of,
simp only with mfld_simps at hy,
simp only [hy] with mfld_simps },
let w := e.symm ≫ₕ e',
let ow := w.target ∩ w.symm ⁻¹'
(e.target ∩ e.symm ⁻¹' (s ∩ g⁻¹' f.source) ∩ (e.target ∩ e.symm ⁻¹' o)),
have wG : w ∈ G := compatible_of_mem_maximal_atlas he he',
have D : P ((f' ∘ g ∘ e.symm) ∘ w.symm) ow (w (e x)) :=
hG.right_invariance wG (by simp only [w, xe, xe'] with mfld_simps) C,
have E : P (f' ∘ g ∘ e'.symm) ow (w (e x)),
{ refine hG.congr _ (by simp only [xe, xe'] with mfld_simps) D,
assume y hy,
simp only with mfld_simps,
rw e.left_inv,
simp only with mfld_simps at hy,
simp only [hy] with mfld_simps },
have : w (e x) = e' x, by simp only [w, xe] with mfld_simps,
rw this at E,
have : ow = (e'.target ∩ e'.symm ⁻¹' (s ∩ g⁻¹' f'.source))
∩ (w.target ∩ (e'.target ∩ e'.symm ⁻¹' o)),
{ ext y,
split,
{ assume hy,
have : e.symm (e ((e'.symm) y)) = e'.symm y,
by { simp only with mfld_simps at hy, simp only [hy] with mfld_simps },
simp only [this] with mfld_simps at hy,
have : g (e'.symm y) ∈ f'.source, by { apply of', simp only [hy] with mfld_simps },
simp only [hy, this] with mfld_simps },
{ assume hy,
simp only with mfld_simps at hy,
have : g (e'.symm y) ∈ f.source, by { apply of, simp only [hy] with mfld_simps },
simp only [this, hy] with mfld_simps } },
rw this at E,
apply (hG.is_local _ _).2 E,
{ exact is_open.inter w.open_target
(e'.continuous_on_symm.preimage_open_of_open e'.open_target o_open) },
{ simp only [xe', xe, xo] with mfld_simps },
end
lemma lift_prop_within_at_indep_chart [has_groupoid M G] [has_groupoid M' G']
(he : e ∈ G.maximal_atlas M) (xe : x ∈ e.source)
(hf : f ∈ G'.maximal_atlas M') (xf : g x ∈ f.source) :
lift_prop_within_at P g s x ↔
continuous_within_at g s x ∧ P (f ∘ g ∘ e.symm)
(e.target ∩ e.symm ⁻¹' (s ∩ g⁻¹' f.source)) (e x) :=
⟨λ H, ⟨H.1,
hG.lift_prop_within_at_indep_chart_aux (chart_mem_maximal_atlas _ _) (mem_chart_source _ _) he xe
(chart_mem_maximal_atlas _ _) (mem_chart_source _ _) hf xf H.1 H.2⟩,
λ H, ⟨H.1,
hG.lift_prop_within_at_indep_chart_aux he xe (chart_mem_maximal_atlas _ _) (mem_chart_source _ _)
hf xf (chart_mem_maximal_atlas _ _) (mem_chart_source _ _) H.1 H.2⟩⟩
lemma lift_prop_on_indep_chart [has_groupoid M G] [has_groupoid M' G']
(he : e ∈ G.maximal_atlas M) (hf : f ∈ G'.maximal_atlas M') (h : lift_prop_on P g s) :
∀ y ∈ e.target ∩ e.symm ⁻¹' (s ∩ g ⁻¹' f.source),
P (f ∘ g ∘ e.symm) (e.target ∩ e.symm ⁻¹' (s ∩ g ⁻¹' f.source)) y :=
begin
assume y hy,
simp only with mfld_simps at hy,
have : e.symm y ∈ s, by simp only [hy] with mfld_simps,
convert ((hG.lift_prop_within_at_indep_chart he _ hf _).1 (h _ this)).2,
repeat { simp only [hy] with mfld_simps },
end
lemma lift_prop_within_at_inter' (ht : t ∈ 𝓝[s] x) :
lift_prop_within_at P g (s ∩ t) x ↔ lift_prop_within_at P g s x :=
begin
by_cases hcont : ¬ (continuous_within_at g s x),
{ have : ¬ (continuous_within_at g (s ∩ t) x), by rwa [continuous_within_at_inter' ht],
simp only [lift_prop_within_at, hcont, this, false_and] },
push_neg at hcont,
have A : continuous_within_at g (s ∩ t) x, by rwa [continuous_within_at_inter' ht],
obtain ⟨o, o_open, xo, oc, oc', ost⟩ :
∃ (o : set M), is_open o ∧ x ∈ o ∧ o ⊆ (chart_at H x).source ∧
o ∩ s ⊆ g ⁻¹' (chart_at H' (g x)).source ∧ o ∩ s ⊆ t,
{ rcases mem_nhds_within.1 ht with ⟨u, u_open, xu, ust⟩,
have : (chart_at H' (g x)).source ∈ 𝓝 (g x) :=
is_open.mem_nhds ((chart_at H' (g x))).open_source (mem_chart_source H' (g x)),
rcases mem_nhds_within.1 (hcont.preimage_mem_nhds_within this) with ⟨v, v_open, xv, hv⟩,
refine ⟨u ∩ v ∩ (chart_at H x).source, _, ⟨⟨xu, xv⟩, mem_chart_source _ _⟩, _, _, _⟩,
{ exact is_open.inter (is_open.inter u_open v_open) (chart_at H x).open_source },
{ assume y hy, exact hy.2 },
{ assume y hy, exact hv ⟨hy.1.1.2, hy.2⟩ },
{ assume y hy, exact ust ⟨hy.1.1.1, hy.2⟩ } },
simp only [lift_prop_within_at, A, hcont, true_and, preimage_inter],
have B : is_open ((chart_at H x).target ∩ (chart_at H x).symm⁻¹' o) :=
(chart_at H x).preimage_open_of_open_symm o_open,
have C : (chart_at H x) x ∈ (chart_at H x).target ∩ (chart_at H x).symm⁻¹' o,
by simp only [xo] with mfld_simps,
conv_lhs { rw hG.is_local B C },
conv_rhs { rw hG.is_local B C },
congr' 2,
have : ∀ y, y ∈ o ∩ s → y ∈ t := ost,
mfld_set_tac
end
lemma lift_prop_within_at_inter (ht : t ∈ 𝓝 x) :
lift_prop_within_at P g (s ∩ t) x ↔ lift_prop_within_at P g s x :=
hG.lift_prop_within_at_inter' (mem_nhds_within_of_mem_nhds ht)
lemma lift_prop_at_of_lift_prop_within_at (h : lift_prop_within_at P g s x) (hs : s ∈ 𝓝 x) :
lift_prop_at P g x :=
begin
have : s = univ ∩ s, by rw univ_inter,
rwa [this, hG.lift_prop_within_at_inter hs] at h,
end
lemma lift_prop_within_at_of_lift_prop_at_of_mem_nhds (h : lift_prop_at P g x) (hs : s ∈ 𝓝 x) :
lift_prop_within_at P g s x :=
begin
have : s = univ ∩ s, by rw univ_inter,
rwa [this, hG.lift_prop_within_at_inter hs],
end
lemma lift_prop_on_of_locally_lift_prop_on
(h : ∀x∈s, ∃u, is_open u ∧ x ∈ u ∧ lift_prop_on P g (s ∩ u)) :
lift_prop_on P g s :=
begin
assume x hx,
rcases h x hx with ⟨u, u_open, xu, hu⟩,
have := hu x ⟨hx, xu⟩,
rwa hG.lift_prop_within_at_inter at this,
exact is_open.mem_nhds u_open xu,
end
lemma lift_prop_of_locally_lift_prop_on
(h : ∀x, ∃u, is_open u ∧ x ∈ u ∧ lift_prop_on P g u) :
lift_prop P g :=
begin
rw ← lift_prop_on_univ,
apply hG.lift_prop_on_of_locally_lift_prop_on (λ x hx, _),
simp [h x],
end
lemma lift_prop_within_at_congr
(h : lift_prop_within_at P g s x) (h₁ : ∀ y ∈ s, g' y = g y) (hx : g' x = g x) :
lift_prop_within_at P g' s x :=
begin
refine ⟨h.1.congr h₁ hx, _⟩,
have A : s ∩ g' ⁻¹' (chart_at H' (g' x)).source = s ∩ g ⁻¹' (chart_at H' (g' x)).source,
{ ext y,
split,
{ assume hy,
simp only with mfld_simps at hy,
simp only [hy, ← h₁ _ hy.1] with mfld_simps },
{ assume hy,
simp only with mfld_simps at hy,
simp only [hy, h₁ _ hy.1] with mfld_simps } },
have := h.2,
rw [← hx, ← A] at this,
convert hG.congr _ _ this using 2,
{ assume y hy,
simp only with mfld_simps at hy,
have : (chart_at H x).symm y ∈ s, by simp only [hy],
simp only [hy, h₁ _ this] with mfld_simps },
{ simp only [hx] with mfld_simps }
end
lemma lift_prop_within_at_congr_iff (h₁ : ∀ y ∈ s, g' y = g y) (hx : g' x = g x) :
lift_prop_within_at P g' s x ↔ lift_prop_within_at P g s x :=
⟨λ h, hG.lift_prop_within_at_congr h (λ y hy, (h₁ y hy).symm) hx.symm,
λ h, hG.lift_prop_within_at_congr h h₁ hx⟩
lemma lift_prop_within_at_congr_of_eventually_eq
(h : lift_prop_within_at P g s x) (h₁ : g' =ᶠ[𝓝[s] x] g) (hx : g' x = g x) :
lift_prop_within_at P g' s x :=
begin
rcases h₁.exists_mem with ⟨t, t_nhd, ht⟩,
rw ← hG.lift_prop_within_at_inter' t_nhd at h ⊢,
exact hG.lift_prop_within_at_congr h (λ y hy, ht hy.2) hx
end
lemma lift_prop_within_at_congr_iff_of_eventually_eq
(h₁ : g' =ᶠ[𝓝[s] x] g) (hx : g' x = g x) :
lift_prop_within_at P g' s x ↔ lift_prop_within_at P g s x :=
⟨λ h, hG.lift_prop_within_at_congr_of_eventually_eq h h₁.symm hx.symm,
λ h, hG.lift_prop_within_at_congr_of_eventually_eq h h₁ hx⟩
lemma lift_prop_at_congr_of_eventually_eq (h : lift_prop_at P g x) (h₁ : g' =ᶠ[𝓝 x] g) :
lift_prop_at P g' x :=
begin
apply hG.lift_prop_within_at_congr_of_eventually_eq h _ h₁.eq_of_nhds,
convert h₁,
rw nhds_within_univ
end
lemma lift_prop_at_congr_iff_of_eventually_eq
(h₁ : g' =ᶠ[𝓝 x] g) : lift_prop_at P g' x ↔ lift_prop_at P g x :=
⟨λ h, hG.lift_prop_at_congr_of_eventually_eq h h₁.symm,
λ h, hG.lift_prop_at_congr_of_eventually_eq h h₁⟩
lemma lift_prop_on_congr (h : lift_prop_on P g s) (h₁ : ∀ y ∈ s, g' y = g y) :
lift_prop_on P g' s :=
λ x hx, hG.lift_prop_within_at_congr (h x hx) h₁ (h₁ x hx)
lemma lift_prop_on_congr_iff (h₁ : ∀ y ∈ s, g' y = g y) :
lift_prop_on P g' s ↔ lift_prop_on P g s :=
⟨λ h, hG.lift_prop_on_congr h (λ y hy, (h₁ y hy).symm), λ h, hG.lift_prop_on_congr h h₁⟩
omit hG
lemma lift_prop_within_at_mono
(mono : ∀ ⦃s x t⦄ ⦃f : H → H'⦄, t ⊆ s → P f s x → P f t x)
(h : lift_prop_within_at P g t x) (hst : s ⊆ t) :
lift_prop_within_at P g s x :=
begin
refine ⟨h.1.mono hst, _⟩,
apply mono (λ y hy, _) h.2,
simp only with mfld_simps at hy,
simp only [hy, hst _] with mfld_simps,
end
lemma lift_prop_within_at_of_lift_prop_at
(mono : ∀ ⦃s x t⦄ ⦃f : H → H'⦄, t ⊆ s → P f s x → P f t x) (h : lift_prop_at P g x) :
lift_prop_within_at P g s x :=
begin
rw ← lift_prop_within_at_univ at h,
exact lift_prop_within_at_mono mono h (subset_univ _),
end
lemma lift_prop_on_mono (mono : ∀ ⦃s x t⦄ ⦃f : H → H'⦄, t ⊆ s → P f s x → P f t x)
(h : lift_prop_on P g t) (hst : s ⊆ t) :
lift_prop_on P g s :=
λ x hx, lift_prop_within_at_mono mono (h x (hst hx)) hst
lemma lift_prop_on_of_lift_prop
(mono : ∀ ⦃s x t⦄ ⦃f : H → H'⦄, t ⊆ s → P f s x → P f t x) (h : lift_prop P g) :
lift_prop_on P g s :=
begin
rw ← lift_prop_on_univ at h,
exact lift_prop_on_mono mono h (subset_univ _)
end
lemma lift_prop_at_of_mem_maximal_atlas [has_groupoid M G]
(hG : G.local_invariant_prop G Q) (hQ : ∀ y, Q id univ y)
(he : e ∈ maximal_atlas M G) (hx : x ∈ e.source) : lift_prop_at Q e x :=
begin
suffices h : Q (e ∘ e.symm) e.target (e x),
{ rw [lift_prop_at, hG.lift_prop_within_at_indep_chart he hx G.id_mem_maximal_atlas (mem_univ _)],
refine ⟨(e.continuous_at hx).continuous_within_at, _⟩,
simpa only with mfld_simps },
have A : Q id e.target (e x),
{ have : e x ∈ e.target, by simp only [hx] with mfld_simps,
simpa only with mfld_simps using (hG.is_local e.open_target this).1 (hQ (e x)) },
apply hG.congr _ _ A;
simp only [hx] with mfld_simps {contextual := tt}
end
lemma lift_prop_on_of_mem_maximal_atlas [has_groupoid M G]
(hG : G.local_invariant_prop G Q) (hQ : ∀ y, Q id univ y) (he : e ∈ maximal_atlas M G) :
lift_prop_on Q e e.source :=
begin
assume x hx,
apply hG.lift_prop_within_at_of_lift_prop_at_of_mem_nhds
(hG.lift_prop_at_of_mem_maximal_atlas hQ he hx),
apply is_open.mem_nhds e.open_source hx,
end
lemma lift_prop_at_symm_of_mem_maximal_atlas [has_groupoid M G] {x : H}
(hG : G.local_invariant_prop G Q) (hQ : ∀ y, Q id univ y)
(he : e ∈ maximal_atlas M G) (hx : x ∈ e.target) : lift_prop_at Q e.symm x :=
begin
suffices h : Q (e ∘ e.symm) e.target x,
{ have A : e.symm ⁻¹' e.source ∩ e.target = e.target,
by mfld_set_tac,
have : e.symm x ∈ e.source, by simp only [hx] with mfld_simps,
rw [lift_prop_at,
hG.lift_prop_within_at_indep_chart G.id_mem_maximal_atlas (mem_univ _) he this],
refine ⟨(e.symm.continuous_at hx).continuous_within_at, _⟩,
simp only with mfld_simps,
rwa [hG.is_local e.open_target hx, A] },
have A : Q id e.target x,
by simpa only with mfld_simps using (hG.is_local e.open_target hx).1 (hQ x),
apply hG.congr _ _ A;
simp only [hx] with mfld_simps {contextual := tt}
end
lemma lift_prop_on_symm_of_mem_maximal_atlas [has_groupoid M G]
(hG : G.local_invariant_prop G Q) (hQ : ∀ y, Q id univ y) (he : e ∈ maximal_atlas M G) :
lift_prop_on Q e.symm e.target :=
begin
assume x hx,
apply hG.lift_prop_within_at_of_lift_prop_at_of_mem_nhds
(hG.lift_prop_at_symm_of_mem_maximal_atlas hQ he hx),
apply is_open.mem_nhds e.open_target hx,
end
lemma lift_prop_at_chart [has_groupoid M G]
(hG : G.local_invariant_prop G Q) (hQ : ∀ y, Q id univ y) : lift_prop_at Q (chart_at H x) x :=
hG.lift_prop_at_of_mem_maximal_atlas hQ (chart_mem_maximal_atlas G x) (mem_chart_source H x)
lemma lift_prop_on_chart [has_groupoid M G]
(hG : G.local_invariant_prop G Q) (hQ : ∀ y, Q id univ y) :
lift_prop_on Q (chart_at H x) (chart_at H x).source :=
hG.lift_prop_on_of_mem_maximal_atlas hQ (chart_mem_maximal_atlas G x)
lemma lift_prop_at_chart_symm [has_groupoid M G]
(hG : G.local_invariant_prop G Q) (hQ : ∀ y, Q id univ y) :
lift_prop_at Q (chart_at H x).symm ((chart_at H x) x) :=
hG.lift_prop_at_symm_of_mem_maximal_atlas hQ (chart_mem_maximal_atlas G x) (by simp)
lemma lift_prop_on_chart_symm [has_groupoid M G]
(hG : G.local_invariant_prop G Q) (hQ : ∀ y, Q id univ y) :
lift_prop_on Q (chart_at H x).symm (chart_at H x).target :=
hG.lift_prop_on_symm_of_mem_maximal_atlas hQ (chart_mem_maximal_atlas G x)
lemma lift_prop_id (hG : G.local_invariant_prop G Q) (hQ : ∀ y, Q id univ y) :
lift_prop Q (id : M → M) :=
begin
assume x,
dsimp [lift_prop_at, lift_prop_within_at],
refine ⟨continuous_within_at_id, _⟩,
let t := ((chart_at H x).target ∩ (chart_at H x).symm ⁻¹' (chart_at H x).source),
suffices H : Q id t ((chart_at H x) x),
{ simp only with mfld_simps,
refine hG.congr (λ y hy, _) (by simp) H,
simp only with mfld_simps at hy,
simp only [hy] with mfld_simps },
have : t = univ ∩ (chart_at H x).target, by mfld_set_tac,
rw this,
exact (hG.is_local (chart_at H x).open_target (by simp)).1 (hQ _)
end
end local_invariant_prop
section local_structomorph
variables (G)
open local_homeomorph
/-- A function from a model space `H` to itself is a local structomorphism, with respect to a
structure groupoid `G` for `H`, relative to a set `s` in `H`, if for all points `x` in the set, the
function agrees with a `G`-structomorphism on `s` in a neighbourhood of `x`. -/
def is_local_structomorph_within_at (f : H → H) (s : set H) (x : H) : Prop :=
(x ∈ s) → ∃ (e : local_homeomorph H H), e ∈ G ∧ eq_on f e.to_fun (s ∩ e.source) ∧ x ∈ e.source
/-- For a groupoid `G` which is `closed_under_restriction`, being a local structomorphism is a local
invariant property. -/
lemma is_local_structomorph_within_at_local_invariant_prop [closed_under_restriction G] :
local_invariant_prop G G (is_local_structomorph_within_at G) :=
{ is_local := begin
intros s x u f hu hux,
split,
{ rintros h hx,
rcases h hx.1 with ⟨e, heG, hef, hex⟩,
have : s ∩ u ∩ e.source ⊆ s ∩ e.source := by mfld_set_tac,
exact ⟨e, heG, hef.mono this, hex⟩ },
{ rintros h hx,
rcases h ⟨hx, hux⟩ with ⟨e, heG, hef, hex⟩,
refine ⟨e.restr (interior u), _, _, _⟩,
{ exact closed_under_restriction' heG (is_open_interior) },
{ have : s ∩ u ∩ e.source = s ∩ (e.source ∩ u) := by mfld_set_tac,
simpa only [this, interior_interior, hu.interior_eq] with mfld_simps using hef },
{ simp only [*, interior_interior, hu.interior_eq] with mfld_simps } }
end,
right_invariance := begin
intros s x f e' he'G he'x h hx,
have hxs : x ∈ s := by simpa only [e'.left_inv he'x] with mfld_simps using hx.2,
rcases h hxs with ⟨e, heG, hef, hex⟩,
refine ⟨e'.symm.trans e, G.trans (G.symm he'G) heG, _, _⟩,
{ intros y hy,
simp only with mfld_simps at hy,
simp only [hef ⟨hy.1.2, hy.2.2⟩] with mfld_simps },
{ simp only [hex, he'x] with mfld_simps }
end,
congr := begin
intros s x f g hfgs hfg' h hx,
rcases h hx with ⟨e, heG, hef, hex⟩,
refine ⟨e, heG, _, hex⟩,
intros y hy,
rw [← hef hy, hfgs y hy.1]
end,
left_invariance := begin
intros s x f e' he'G he' hfx h hx,
rcases h hx with ⟨e, heG, hef, hex⟩,
refine ⟨e.trans e', G.trans heG he'G, _, _⟩,
{ intros y hy,
simp only with mfld_simps at hy,
simp only [hef ⟨hy.1, hy.2.1⟩] with mfld_simps },
{ simpa only [hex, hef ⟨hx, hex⟩] with mfld_simps using hfx }
end }
end local_structomorph
end structure_groupoid
|
d8269a53dbd0a201866a3a961a54589723ff466b | 4d2583807a5ac6caaffd3d7a5f646d61ca85d532 | /src/analysis/normed_space/conformal_linear_map.lean | b4dc3b597be260761c0f1e19ea5e846bf2872b1e | [
"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 | 3,788 | lean | /-
Copyright (c) 2021 Yourong Zang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yourong Zang
-/
import analysis.normed_space.linear_isometry
/-!
# Conformal Linear Maps
A continuous linear map between `R`-normed spaces `X` and `Y` `is_conformal_map` if it is
a nonzero multiple of a linear isometry.
## Main definitions
* `is_conformal_map`: the main definition of conformal linear maps
## Main results
* The conformality of the composition of two conformal linear maps, the identity map
and multiplications by nonzero constants as continuous linear maps
* `is_conformal_map_of_subsingleton`: all continuous linear maps on singleton spaces are conformal
* `is_conformal_map.preserves_angle`: if a continuous linear map is conformal, then it
preserves all angles in the normed space
See `analysis.normed_space.conformal_linear_map.inner_product` for
* `is_conformal_map_iff`: a map between inner product spaces is conformal
iff it preserves inner products up to a fixed scalar factor.
## Tags
conformal
## Warning
The definition of conformality in this file does NOT require the maps to be orientation-preserving.
-/
noncomputable theory
open linear_isometry continuous_linear_map
/-- A continuous linear map `f'` is said to be conformal if it's
a nonzero multiple of a linear isometry. -/
def is_conformal_map {R : Type*} {X Y : Type*} [normed_field R]
[semi_normed_group X] [semi_normed_group Y] [semi_normed_space R X] [semi_normed_space R Y]
(f' : X →L[R] Y) :=
∃ (c : R) (hc : c ≠ 0) (li : X →ₗᵢ[R] Y), (f' : X → Y) = c • li
variables {R M N G M' : Type*} [normed_field R]
[semi_normed_group M] [semi_normed_group N] [semi_normed_group G]
[semi_normed_space R M] [semi_normed_space R N] [semi_normed_space R G]
[normed_group M'] [normed_space R M']
lemma is_conformal_map_id : is_conformal_map (id R M) :=
⟨1, one_ne_zero, id, by { ext, simp }⟩
lemma is_conformal_map_const_smul {c : R} (hc : c ≠ 0) : is_conformal_map (c • (id R M)) :=
⟨c, hc, id, by { ext, simp }⟩
lemma linear_isometry.is_conformal_map (f' : M →ₗᵢ[R] N) :
is_conformal_map f'.to_continuous_linear_map :=
⟨1, one_ne_zero, f', by { ext, simp }⟩
lemma is_conformal_map_of_subsingleton [h : subsingleton M] (f' : M →L[R] N) :
is_conformal_map f' :=
begin
rw subsingleton_iff at h,
have minor : (f' : M → N) = function.const M 0 := by ext x'; rw h x' 0; exact f'.map_zero,
have key : ∀ (x' : M), ∥(0 : M →ₗ[R] N) x'∥ = ∥x'∥ := λ x',
by { rw [linear_map.zero_apply, h x' 0], repeat { rw norm_zero }, },
exact ⟨(1 : R), one_ne_zero, ⟨0, key⟩,
by { rw pi.smul_def, ext p, rw [one_smul, minor], refl, }⟩,
end
namespace is_conformal_map
lemma comp {f' : M →L[R] N} {g' : N →L[R] G}
(hg' : is_conformal_map g') (hf' : is_conformal_map f') :
is_conformal_map (g'.comp f') :=
begin
rcases hf' with ⟨cf, hcf, lif, hlif⟩,
rcases hg' with ⟨cg, hcg, lig, hlig⟩,
refine ⟨cg * cf, mul_ne_zero hcg hcf, lig.comp lif, funext (λ x, _)⟩,
simp only [coe_comp', linear_isometry.coe_comp, hlif, hlig, pi.smul_apply,
function.comp_app, linear_isometry.map_smul, smul_smul],
end
lemma injective {f' : M' →L[R] N} (h : is_conformal_map f') : function.injective f' :=
let ⟨c, hc, li, hf'⟩ := h in by simp only [hf', pi.smul_def];
exact (smul_right_injective _ hc).comp li.injective
lemma ne_zero [nontrivial M'] {f' : M' →L[R] N} (hf' : is_conformal_map f') :
f' ≠ 0 :=
begin
intros w,
rcases exists_ne (0 : M') with ⟨a, ha⟩,
have : f' a = f' 0,
{ simp_rw [w, continuous_linear_map.zero_apply], },
exact ha (hf'.injective this),
end
end is_conformal_map
|
401e5877bf066e7647c6c52aa2723197a434a4c0 | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/representation_theory/basic.lean | 8d13447b4d399faccdcaa8d20ace9c829512a481 | [
"Apache-2.0"
] | permissive | leanprover-community/mathlib | 56a2cadd17ac88caf4ece0a775932fa26327ba0e | 442a83d738cb208d3600056c489be16900ba701d | refs/heads/master | 1,693,584,102,358 | 1,693,471,902,000 | 1,693,471,902,000 | 97,922,418 | 1,595 | 352 | Apache-2.0 | 1,694,693,445,000 | 1,500,624,130,000 | Lean | UTF-8 | Lean | false | false | 14,390 | lean | /-
Copyright (c) 2022 Antoine Labelle. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Antoine Labelle
-/
import algebra.module.basic
import algebra.module.linear_map
import algebra.monoid_algebra.basic
import linear_algebra.dual
import linear_algebra.contraction
import ring_theory.tensor_product
/-!
# Monoid representations
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
This file introduces monoid representations and their characters and defines a few ways to construct
representations.
## Main definitions
* representation.representation
* representation.character
* representation.tprod
* representation.lin_hom
* represensation.dual
## Implementation notes
Representations of a monoid `G` on a `k`-module `V` are implemented as
homomorphisms `G →* (V →ₗ[k] V)`.
-/
open monoid_algebra (lift) (of)
open linear_map
section
variables (k G V : Type*) [comm_semiring k] [monoid G] [add_comm_monoid V] [module k V]
/--
A representation of `G` on the `k`-module `V` is an homomorphism `G →* (V →ₗ[k] V)`.
-/
abbreviation representation := G →* (V →ₗ[k] V)
end
namespace representation
section trivial
variables (k : Type*) {G V : Type*} [comm_semiring k] [monoid G] [add_comm_monoid V] [module k V]
/--
The trivial representation of `G` on a `k`-module V.
-/
def trivial : representation k G V := 1
@[simp]
lemma trivial_def (g : G) (v : V) : trivial k g v = v := rfl
end trivial
section monoid_algebra
variables {k G V : Type*} [comm_semiring k] [monoid G] [add_comm_monoid V] [module k V]
variables (ρ : representation k G V)
/--
A `k`-linear representation of `G` on `V` can be thought of as
an algebra map from `monoid_algebra k G` into the `k`-linear endomorphisms of `V`.
-/
noncomputable def as_algebra_hom : monoid_algebra k G →ₐ[k] (module.End k V) :=
(lift k G _) ρ
lemma as_algebra_hom_def : as_algebra_hom ρ = (lift k G _) ρ :=
rfl
@[simp]
lemma as_algebra_hom_single (g : G) (r : k) :
(as_algebra_hom ρ (finsupp.single g r)) = r • ρ g :=
by simp only [as_algebra_hom_def, monoid_algebra.lift_single]
lemma as_algebra_hom_single_one (g : G):
(as_algebra_hom ρ (finsupp.single g 1)) = ρ g :=
by simp
lemma as_algebra_hom_of (g : G) :
(as_algebra_hom ρ (of k G g)) = ρ g :=
by simp only [monoid_algebra.of_apply, as_algebra_hom_single, one_smul]
/--
If `ρ : representation k G V`, then `ρ.as_module` is a type synonym for `V`,
which we equip with an instance `module (monoid_algebra k G) ρ.as_module`.
You should use `as_module_equiv : ρ.as_module ≃+ V` to translate terms.
-/
@[nolint unused_arguments, derive [add_comm_monoid, module (module.End k V)]]
def as_module (ρ : representation k G V) := V
instance : inhabited ρ.as_module := ⟨0⟩
/--
A `k`-linear representation of `G` on `V` can be thought of as
a module over `monoid_algebra k G`.
-/
noncomputable instance as_module_module : module (monoid_algebra k G) ρ.as_module :=
module.comp_hom V (as_algebra_hom ρ).to_ring_hom
/--
The additive equivalence from the `module (monoid_algebra k G)` to the original vector space
of the representative.
This is just the identity, but it is helpful for typechecking and keeping track of instances.
-/
def as_module_equiv : ρ.as_module ≃+ V :=
add_equiv.refl _
@[simp]
lemma as_module_equiv_map_smul (r : monoid_algebra k G) (x : ρ.as_module) :
ρ.as_module_equiv (r • x) = ρ.as_algebra_hom r (ρ.as_module_equiv x) :=
rfl
@[simp]
lemma as_module_equiv_symm_map_smul (r : k) (x : V) :
ρ.as_module_equiv.symm (r • x) =
algebra_map k (monoid_algebra k G) r • (ρ.as_module_equiv.symm x) :=
begin
apply_fun ρ.as_module_equiv,
simp,
end
@[simp]
lemma as_module_equiv_symm_map_rho (g : G) (x : V) :
ρ.as_module_equiv.symm (ρ g x) = monoid_algebra.of k G g • (ρ.as_module_equiv.symm x) :=
begin
apply_fun ρ.as_module_equiv,
simp,
end
/--
Build a `representation k G M` from a `[module (monoid_algebra k G) M]`.
This version is not always what we want, as it relies on an existing `[module k M]`
instance, along with a `[is_scalar_tower k (monoid_algebra k G) M]` instance.
We remedy this below in `of_module`
(with the tradeoff that the representation is defined
only on a type synonym of the original module.)
-/
noncomputable
def of_module' (M : Type*) [add_comm_monoid M] [module k M] [module (monoid_algebra k G) M]
[is_scalar_tower k (monoid_algebra k G) M] : representation k G M :=
(monoid_algebra.lift k G (M →ₗ[k] M)).symm (algebra.lsmul k M)
section
variables (k G) (M : Type*) [add_comm_monoid M] [module (monoid_algebra k G) M]
/--
Build a `representation` from a `[module (monoid_algebra k G) M]`.
Note that the representation is built on `restrict_scalars k (monoid_algebra k G) M`,
rather than on `M` itself.
-/
noncomputable
def of_module :
representation k G (restrict_scalars k (monoid_algebra k G) M) :=
(monoid_algebra.lift k G
(restrict_scalars k (monoid_algebra k G) M →ₗ[k] restrict_scalars k (monoid_algebra k G) M)).symm
(restrict_scalars.lsmul k (monoid_algebra k G) M)
/-!
## `of_module` and `as_module` are inverses.
This requires a little care in both directions:
this is a categorical equivalence, not an isomorphism.
See `Rep.equivalence_Module_monoid_algebra` for the full statement.
Starting with `ρ : representation k G V`, converting to a module and back again
we have a `representation k G (restrict_scalars k (monoid_algebra k G) ρ.as_module)`.
To compare these, we use the composition of `restrict_scalars_add_equiv` and `ρ.as_module_equiv`.
Similarly, starting with `module (monoid_algebra k G) M`,
after we convert to a representation and back to a module,
we have `module (monoid_algebra k G) (restrict_scalars k (monoid_algebra k G) M)`.
-/
@[simp] lemma of_module_as_algebra_hom_apply_apply
(r : monoid_algebra k G) (m : restrict_scalars k (monoid_algebra k G) M) :
((((of_module k G M).as_algebra_hom) r) m) =
(restrict_scalars.add_equiv _ _ _).symm (r • restrict_scalars.add_equiv _ _ _ m) :=
begin
apply monoid_algebra.induction_on r,
{ intros g,
simp only [one_smul, monoid_algebra.lift_symm_apply, monoid_algebra.of_apply,
representation.as_algebra_hom_single, representation.of_module,
add_equiv.apply_eq_iff_eq, restrict_scalars.lsmul_apply_apply], },
{ intros f g fw gw,
simp only [fw, gw, map_add, add_smul, linear_map.add_apply], },
{ intros r f w,
simp only [w, alg_hom.map_smul, linear_map.smul_apply,
restrict_scalars.add_equiv_symm_map_smul_smul], }
end
@[simp]
lemma of_module_as_module_act (g : G) (x : restrict_scalars k (monoid_algebra k G) ρ.as_module) :
of_module k G (ρ.as_module) g x =
(restrict_scalars.add_equiv _ _ _).symm ((ρ.as_module_equiv).symm
(ρ g (ρ.as_module_equiv (restrict_scalars.add_equiv _ _ _ x)))) :=
begin
apply_fun restrict_scalars.add_equiv _ _ ρ.as_module using
(restrict_scalars.add_equiv _ _ _).injective,
dsimp [of_module, restrict_scalars.lsmul_apply_apply],
simp,
end
lemma smul_of_module_as_module (r : monoid_algebra k G)
(m : (of_module k G M).as_module) :
(restrict_scalars.add_equiv _ _ _) ((of_module k G M).as_module_equiv (r • m)) =
r • (restrict_scalars.add_equiv _ _ _) ((of_module k G M).as_module_equiv m) :=
by { dsimp, simp only [add_equiv.apply_symm_apply, of_module_as_algebra_hom_apply_apply], }
end
end monoid_algebra
section add_comm_group
variables {k G V : Type*} [comm_ring k] [monoid G] [I : add_comm_group V] [module k V]
variables (ρ : representation k G V)
instance : add_comm_group ρ.as_module := I
end add_comm_group
section mul_action
variables (k : Type*) [comm_semiring k] (G : Type*) [monoid G] (H : Type*) [mul_action G H]
/-- A `G`-action on `H` induces a representation `G →* End(k[H])` in the natural way. -/
noncomputable def of_mul_action : representation k G (H →₀ k) :=
{ to_fun := λ g, finsupp.lmap_domain k k ((•) g),
map_one' := by { ext x y, dsimp, simp },
map_mul' := λ x y, by { ext z w, simp [mul_smul] }}
variables {k G H}
lemma of_mul_action_def (g : G) : of_mul_action k G H g = finsupp.lmap_domain k k ((•) g) := rfl
lemma of_mul_action_single (g : G) (x : H) (r : k) :
of_mul_action k G H g (finsupp.single x r) = finsupp.single (g • x) r :=
finsupp.map_domain_single
end mul_action
section group
variables {k G V : Type*} [comm_semiring k] [group G] [add_comm_monoid V] [module k V]
variables (ρ : representation k G V)
@[simp] lemma of_mul_action_apply {H : Type*} [mul_action G H]
(g : G) (f : H →₀ k) (h : H) : of_mul_action k G H g f h = f (g⁻¹ • h) :=
begin
conv_lhs { rw ← smul_inv_smul g h, },
let h' := g⁻¹ • h,
change of_mul_action k G H g f (g • h') = f h',
have hg : function.injective ((•) g : H → H), { intros h₁ h₂, simp, },
simp only [of_mul_action_def, finsupp.lmap_domain_apply, finsupp.map_domain_apply, hg],
end
lemma of_mul_action_self_smul_eq_mul
(x : monoid_algebra k G) (y : (of_mul_action k G G).as_module) :
x • y = (x * y : monoid_algebra k G) :=
x.induction_on (λ g, by show as_algebra_hom _ _ _ = _; ext; simp)
(λ x y hx hy, by simp only [hx, hy, add_mul, add_smul])
(λ r x hx, by show as_algebra_hom _ _ _ = _; simpa [←hx])
/-- If we equip `k[G]` with the `k`-linear `G`-representation induced by the left regular action of
`G` on itself, the resulting object is isomorphic as a `k[G]`-module to `k[G]` with its natural
`k[G]`-module structure. -/
@[simps] noncomputable def of_mul_action_self_as_module_equiv :
(of_mul_action k G G).as_module ≃ₗ[monoid_algebra k G] monoid_algebra k G :=
{ map_smul' := of_mul_action_self_smul_eq_mul, ..as_module_equiv _ }
/--
When `G` is a group, a `k`-linear representation of `G` on `V` can be thought of as
a group homomorphism from `G` into the invertible `k`-linear endomorphisms of `V`.
-/
def as_group_hom : G →* units (V →ₗ[k] V) :=
monoid_hom.to_hom_units ρ
lemma as_group_hom_apply (g : G) : ↑(as_group_hom ρ g) = ρ g :=
by simp only [as_group_hom, monoid_hom.coe_to_hom_units]
end group
section tensor_product
variables {k G V W : Type*} [comm_semiring k] [monoid G]
variables [add_comm_monoid V] [module k V] [add_comm_monoid W] [module k W]
variables (ρV : representation k G V) (ρW : representation k G W)
open_locale tensor_product
/--
Given representations of `G` on `V` and `W`, there is a natural representation of `G` on their
tensor product `V ⊗[k] W`.
-/
def tprod : representation k G (V ⊗[k] W) :=
{ to_fun := λ g, tensor_product.map (ρV g) (ρW g),
map_one' := by simp only [map_one, tensor_product.map_one],
map_mul' := λ g h, by simp only [map_mul, tensor_product.map_mul] }
local notation ρV ` ⊗ ` ρW := tprod ρV ρW
@[simp]
lemma tprod_apply (g : G) : (ρV ⊗ ρW) g = tensor_product.map (ρV g) (ρW g) := rfl
lemma smul_tprod_one_as_module (r : monoid_algebra k G) (x : V) (y : W) :
(r • (x ⊗ₜ y) : (ρV.tprod 1).as_module) = (r • x : ρV.as_module) ⊗ₜ y :=
begin
show as_algebra_hom _ _ _ = as_algebra_hom _ _ _ ⊗ₜ _,
simp only [as_algebra_hom_def, monoid_algebra.lift_apply,
tprod_apply, monoid_hom.one_apply, linear_map.finsupp_sum_apply,
linear_map.smul_apply, tensor_product.map_tmul, linear_map.one_apply],
simp only [finsupp.sum, tensor_product.sum_tmul],
refl,
end
lemma smul_one_tprod_as_module (r : monoid_algebra k G) (x : V) (y : W) :
(r • (x ⊗ₜ y) : ((1 : representation k G V).tprod ρW).as_module) = x ⊗ₜ (r • y : ρW.as_module) :=
begin
show as_algebra_hom _ _ _ = _ ⊗ₜ as_algebra_hom _ _ _,
simp only [as_algebra_hom_def, monoid_algebra.lift_apply,
tprod_apply, monoid_hom.one_apply, linear_map.finsupp_sum_apply,
linear_map.smul_apply, tensor_product.map_tmul, linear_map.one_apply],
simp only [finsupp.sum, tensor_product.tmul_sum, tensor_product.tmul_smul],
end
end tensor_product
section linear_hom
variables {k G V W : Type*} [comm_semiring k] [group G]
variables [add_comm_monoid V] [module k V] [add_comm_monoid W] [module k W]
variables (ρV : representation k G V) (ρW : representation k G W)
/--
Given representations of `G` on `V` and `W`, there is a natural representation of `G` on the
module `V →ₗ[k] W`, where `G` acts by conjugation.
-/
def lin_hom : representation k G (V →ₗ[k] W) :=
{ to_fun := λ g,
{ to_fun := λ f, (ρW g) ∘ₗ f ∘ₗ (ρV g⁻¹),
map_add' := λ f₁ f₂, by simp_rw [add_comp, comp_add],
map_smul' := λ r f, by simp_rw [ring_hom.id_apply, smul_comp, comp_smul]},
map_one' := linear_map.ext $ λ x,
by simp_rw [coe_mk, inv_one, map_one, one_apply, one_eq_id, comp_id, id_comp],
map_mul' := λ g h, linear_map.ext $ λ x,
by simp_rw [coe_mul, coe_mk, function.comp_apply, mul_inv_rev, map_mul, mul_eq_comp,
comp_assoc ]}
@[simp]
lemma lin_hom_apply (g : G) (f : V →ₗ[k] W) : (lin_hom ρV ρW) g f = (ρW g) ∘ₗ f ∘ₗ (ρV g⁻¹) := rfl
/--
The dual of a representation `ρ` of `G` on a module `V`, given by `(dual ρ) g f = f ∘ₗ (ρ g⁻¹)`,
where `f : module.dual k V`.
-/
def dual : representation k G (module.dual k V) :=
{ to_fun := λ g,
{ to_fun := λ f, f ∘ₗ (ρV g⁻¹),
map_add' := λ f₁ f₂, by simp only [add_comp],
map_smul' := λ r f,
by {ext, simp only [coe_comp, function.comp_app, smul_apply, ring_hom.id_apply]} },
map_one' :=
by {ext, simp only [coe_comp, function.comp_app, map_one, inv_one, coe_mk, one_apply]},
map_mul' := λ g h,
by {ext, simp only [coe_comp, function.comp_app, mul_inv_rev, map_mul, coe_mk, mul_apply]}}
@[simp]
lemma dual_apply (g : G) : (dual ρV) g = module.dual.transpose (ρV g⁻¹) := rfl
/--
Given $k$-modules $V, W$, there is a homomorphism $φ : V^* ⊗ W → Hom_k(V, W)$
(implemented by `linear_algebra.contraction.dual_tensor_hom`).
Given representations of $G$ on $V$ and $W$,there are representations of $G$ on $V^* ⊗ W$ and on
$Hom_k(V, W)$.
This lemma says that $φ$ is $G$-linear.
-/
lemma dual_tensor_hom_comm (g : G) :
(dual_tensor_hom k V W) ∘ₗ (tensor_product.map (ρV.dual g) (ρW g)) =
(lin_hom ρV ρW) g ∘ₗ (dual_tensor_hom k V W) :=
begin
ext, simp [module.dual.transpose_apply],
end
end linear_hom
end representation
|
8e0a5a7cd57d8dbee0bf9892e5f99a0efc97fdc1 | 367134ba5a65885e863bdc4507601606690974c1 | /src/order/pfilter.lean | 8c1a6b1e5ec1126f5830809b253d6eba5b1ce839 | [
"Apache-2.0"
] | permissive | kodyvajjha/mathlib | 9bead00e90f68269a313f45f5561766cfd8d5cad | b98af5dd79e13a38d84438b850a2e8858ec21284 | refs/heads/master | 1,624,350,366,310 | 1,615,563,062,000 | 1,615,563,062,000 | 162,666,963 | 0 | 0 | Apache-2.0 | 1,545,367,651,000 | 1,545,367,651,000 | null | UTF-8 | Lean | false | false | 3,306 | lean | /-
Copyright (c) 2020 Mathieu Guay-Paquet. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mathieu Guay-Paquet
-/
import order.ideal
/-!
# Order filters
## Main definitions
Throughout this file, `P` is at least a preorder, but some sections
require more structure, such as a bottom element, a top element, or
a join-semilattice structure.
- `pfilter P`: The type of nonempty, downward directed, upward closed
subsets of `P`. This is dual to `order.ideal`, so it
simply wraps `order.ideal (order_dual P)`.
Note the relation between `order/filter` and `order/pfilter`: for any
type `α`, `filter α` represents the same mathematical object as
`pfilter (set α)`.
## References
- <https://en.wikipedia.org/wiki/Filter_(mathematics)>
## Tags
pfilter, filter, ideal, dual
-/
variables {P : Type*}
/-- A filter on a preorder `P` is a subset of `P` that is
- nonempty
- downward directed
- upward closed. -/
structure pfilter (P) [preorder P] :=
(dual : order.ideal (order_dual P))
namespace pfilter
section preorder
variables [preorder P] {x y : P} {F G : pfilter P}
/-- A filter on `P` is a subset of `P`. -/
instance : has_coe (pfilter P) (set P) := ⟨λ F, F.dual.carrier⟩
/-- For the notation `x ∈ F`. -/
instance : has_mem P (pfilter P) := ⟨λ x F, x ∈ (F : set P)⟩
lemma nonempty : (F : set P).nonempty := F.dual.nonempty
lemma directed : directed_on (≥) (F : set P) := F.dual.directed
lemma mem_of_le : x ≤ y → x ∈ F → y ∈ F := λ h, F.dual.mem_of_le h
/-- The smallest filter containing a given element. -/
def principal (p : P) : pfilter P := ⟨order.ideal.principal p⟩
instance [inhabited P] : inhabited (pfilter P) := ⟨⟨default _⟩⟩
/-- Two filters are equal when their underlying sets are equal. -/
@[ext] lemma ext : ∀ (F G : pfilter P), (F : set P) = G → F = G
| ⟨⟨_, _, _, _⟩⟩ ⟨⟨_, _, _, _⟩⟩ rfl := rfl
/-- The partial ordering by subset inclusion, inherited from `set P`. -/
instance : partial_order (pfilter P) := partial_order.lift coe ext
@[trans] lemma mem_of_mem_of_le : x ∈ F → F ≤ G → x ∈ G :=
order.ideal.mem_of_mem_of_le
@[simp] lemma principal_le_iff : principal x ≤ F ↔ x ∈ F :=
order.ideal.principal_le_iff
end preorder
section order_top
variables [order_top P] {F : pfilter P}
/-- A specific witness of `pfilter.nonempty` when `P` has a top element. -/
@[simp] lemma top_mem : ⊤ ∈ F :=
order.ideal.bot_mem
/-- There is a bottom filter when `P` has a top element. -/
instance : order_bot (pfilter P) :=
{ bot := ⟨⊥⟩,
bot_le := λ F, (bot_le : ⊥ ≤ F.dual),
.. pfilter.partial_order }
end order_top
/-- There is a top filter when `P` has a bottom element. -/
instance {P} [order_bot P] : order_top (pfilter P) :=
{ top := ⟨⊤⟩,
le_top := λ F, (le_top : F.dual ≤ ⊤),
.. pfilter.partial_order }
section semilattice_inf
variables [semilattice_inf P] {x y : P} {F : pfilter P}
/-- A specific witness of `pfilter.directed` when `P` has meets. -/
lemma inf_mem (x y ∈ F) : x ⊓ y ∈ F :=
order.ideal.sup_mem x y ‹x ∈ F› ‹y ∈ F›
@[simp] lemma inf_mem_iff : x ⊓ y ∈ F ↔ x ∈ F ∧ y ∈ F :=
order.ideal.sup_mem_iff
end semilattice_inf
end pfilter
|
b675a3696cc2c9fc2dcee41ca1677971b5cd2c63 | 4727251e0cd73359b15b664c3170e5d754078599 | /src/analysis/special_functions/non_integrable.lean | bdc86f7af12298b88d49ce908519186409ef3982 | [
"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 | 9,627 | 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.special_functions.integrals
import analysis.calculus.fderiv_measurable
/-!
# Non integrable functions
In this file we prove that the derivative of a function that tends to infinity is not interval
integrable, see `interval_integral.not_integrable_has_deriv_at_of_tendsto_norm_at_top_filter` and
`interval_integral.not_integrable_has_deriv_at_of_tendsto_norm_at_top_punctured`. Then we apply the
latter lemma to prove that the function `λ x, x⁻¹` is integrable on `a..b` if and only if `a = b` or
`0 ∉ [a, b]`.
## Main results
* `not_interval_integrable_of_tendsto_norm_at_top_of_deriv_is_O_punctured`: if `f` tends to infinity
along `𝓝[≠] c` and `f' = O(g)` along the same filter, then `g` is not interval integrable on any
nontrivial integral `a..b`, `c ∈ [a, b]`.
* `not_interval_integrable_of_tendsto_norm_at_top_of_deriv_is_O_filter`: a version of
`not_interval_integrable_of_tendsto_norm_at_top_of_deriv_is_O_punctured` that works for one-sided
neighborhoods;
* `not_interval_integrable_of_sub_inv_is_O_punctured`: if `1 / (x - c) = O(f)` as `x → c`, `x ≠ c`,
then `f` is not interval integrable on any nontrivial interval `a..b`, `c ∈ [a, b]`;
* `interval_integrable_sub_inv_iff`, `interval_integrable_inv_iff`: integrability conditions for
`(x - c)⁻¹` and `x⁻¹`.
## Tags
integrable function
-/
open_locale measure_theory topological_space interval nnreal ennreal
open measure_theory topological_space set filter asymptotics interval_integral
variables {E F : Type*} [normed_group E] [normed_space ℝ E] [second_countable_topology E]
[complete_space E] [normed_group F]
/-- If `f` is eventually differentiable along a nontrivial filter `l : filter ℝ` that is generated
by convex sets, the norm of `f` tends to infinity along `l`, and `f' = O(g)` along `l`, where `f'`
is the derivative of `f`, then `g` is not integrable on any interval `a..b` such that
`[a, b] ∈ l`. -/
lemma not_interval_integrable_of_tendsto_norm_at_top_of_deriv_is_O_filter {f : ℝ → E} {g : ℝ → F}
{a b : ℝ} (l : filter ℝ) [ne_bot l] [tendsto_Ixx_class Icc l l] (hl : [a, b] ∈ l)
(hd : ∀ᶠ x in l, differentiable_at ℝ f x) (hf : tendsto (λ x, ∥f x∥) l at_top)
(hfg : is_O (deriv f) g l) :
¬interval_integrable g volume a b :=
begin
intro hgi,
obtain ⟨C, hC₀, s, hsl, hsub, hfd, hg⟩ : ∃ (C : ℝ) (hC₀ : 0 ≤ C) (s ∈ l),
(∀ (x ∈ s) (y ∈ s), [x, y] ⊆ [a, b]) ∧
(∀ (x ∈ s) (y ∈ s) (z ∈ [x, y]), differentiable_at ℝ f z) ∧
(∀ (x ∈ s) (y ∈ s) (z ∈ [x, y]), ∥deriv f z∥ ≤ C * ∥g z∥),
{ rcases hfg.exists_nonneg with ⟨C, C₀, hC⟩,
have h : ∀ᶠ x : ℝ × ℝ in l.prod l, ∀ y ∈ [x.1, x.2], (differentiable_at ℝ f y ∧
∥deriv f y∥ ≤ C * ∥g y∥) ∧ y ∈ [a, b],
from (tendsto_fst.interval tendsto_snd).eventually ((hd.and hC.bound).and hl).small_sets,
rcases mem_prod_self_iff.1 h with ⟨s, hsl, hs⟩,
simp only [prod_subset_iff, mem_set_of_eq] at hs,
exact ⟨C, C₀, s, hsl, λ x hx y hy z hz, (hs x hx y hy z hz).2,
λ x hx y hy z hz, (hs x hx y hy z hz).1.1, λ x hx y hy z hz, (hs x hx y hy z hz).1.2⟩ },
replace hgi : interval_integrable (λ x, C * ∥g x∥) volume a b, by convert hgi.norm.smul C,
obtain ⟨c, hc, d, hd, hlt⟩ : ∃ (c ∈ s) (d ∈ s), ∥f c∥ + ∫ y in Ι a b, C * ∥g y∥ < ∥f d∥,
{ rcases filter.nonempty_of_mem hsl with ⟨c, hc⟩,
have : ∀ᶠ x in l, ∥f c∥ + ∫ y in Ι a b, C * ∥g y∥ < ∥f x∥,
from hf.eventually (eventually_gt_at_top _),
exact ⟨c, hc, (this.and hsl).exists.imp (λ d hd, ⟨hd.2, hd.1⟩)⟩ },
specialize hsub c hc d hd, specialize hfd c hc d hd,
replace hg : ∀ x ∈ Ι c d, ∥deriv f x∥ ≤ C * ∥g x∥, from λ z hz, hg c hc d hd z ⟨hz.1.le, hz.2⟩,
have hg_ae : ∀ᵐ x ∂(volume.restrict (Ι c d)), ∥deriv f x∥ ≤ C * ∥g x∥,
from (ae_restrict_mem measurable_set_interval_oc).mono hg,
have hsub' : Ι c d ⊆ Ι a b,
from interval_oc_subset_interval_oc_of_interval_subset_interval hsub,
have hfi : interval_integrable (deriv f) volume c d,
from (hgi.mono_set hsub).mono_fun' (ae_strongly_measurable_deriv _ _) hg_ae,
refine hlt.not_le (sub_le_iff_le_add'.1 _),
calc ∥f d∥ - ∥f c∥ ≤ ∥f d - f c∥ : norm_sub_norm_le _ _
... = ∥∫ x in c..d, deriv f x∥ : congr_arg _ (integral_deriv_eq_sub hfd hfi).symm
... = ∥∫ x in Ι c d, deriv f x∥ : norm_integral_eq_norm_integral_Ioc _
... ≤ ∫ x in Ι c d, ∥deriv f x∥ : norm_integral_le_integral_norm _
... ≤ ∫ x in Ι c d, C * ∥g x∥ :
set_integral_mono_on hfi.norm.def (hgi.def.mono_set hsub') measurable_set_interval_oc hg
... ≤ ∫ x in Ι a b, C * ∥g x∥ :
set_integral_mono_set hgi.def (ae_of_all _ $ λ x, mul_nonneg hC₀ (norm_nonneg _))
hsub'.eventually_le
end
/-- If `a ≠ b`, `c ∈ [a, b]`, `f` is differentiable in the neighborhood of `c` within
`[a, b] \ {c}`, `∥f x∥ → ∞` as `x → c` within `[a, b] \ {c}`, and `f' = O(g)` along
`𝓝[[a, b] \ {c}] c`, where `f'` is the derivative of `f`, then `g` is not interval integrable on
`a..b`. -/
lemma not_interval_integrable_of_tendsto_norm_at_top_of_deriv_is_O_within_diff_singleton
{f : ℝ → E} {g : ℝ → F} {a b c : ℝ} (hne : a ≠ b) (hc : c ∈ [a, b])
(h_deriv : ∀ᶠ x in 𝓝[[a, b] \ {c}] c, differentiable_at ℝ f x)
(h_infty : tendsto (λ x, ∥f x∥) (𝓝[[a, b] \ {c}] c) at_top)
(hg : is_O (deriv f) g (𝓝[[a, b] \ {c}] c)) :
¬interval_integrable g volume a b :=
begin
obtain ⟨l, hl, hl', hle, hmem⟩ : ∃ l : filter ℝ, tendsto_Ixx_class Icc l l ∧ l.ne_bot ∧
l ≤ 𝓝 c ∧ [a, b] \ {c} ∈ l,
{ cases (min_lt_max.2 hne).lt_or_lt c with hlt hlt,
{ refine ⟨𝓝[<] c, infer_instance, infer_instance, inf_le_left, _⟩,
rw ← Iic_diff_right,
exact diff_mem_nhds_within_diff (Icc_mem_nhds_within_Iic ⟨hlt, hc.2⟩) _ },
{ refine ⟨𝓝[>] c, infer_instance, infer_instance, inf_le_left, _⟩,
rw ← Ici_diff_left,
exact diff_mem_nhds_within_diff (Icc_mem_nhds_within_Ici ⟨hc.1, hlt⟩) _ } },
resetI,
have : l ≤ 𝓝[[a, b] \ {c}] c, from le_inf hle (le_principal_iff.2 hmem),
exact not_interval_integrable_of_tendsto_norm_at_top_of_deriv_is_O_filter l
(mem_of_superset hmem (diff_subset _ _))
(h_deriv.filter_mono this) (h_infty.mono_left this) (hg.mono this),
end
/-- If `f` is differentiable in a punctured neighborhood of `c`, `∥f x∥ → ∞` as `x → c` (more
formally, along the filter `𝓝[≠] c`), and `f' = O(g)` along `𝓝[≠] c`, where `f'` is the derivative
of `f`, then `g` is not interval integrable on any nontrivial interval `a..b` such that
`c ∈ [a, b]`. -/
lemma not_interval_integrable_of_tendsto_norm_at_top_of_deriv_is_O_punctured {f : ℝ → E} {g : ℝ → F}
{a b c : ℝ} (h_deriv : ∀ᶠ x in 𝓝[≠] c, differentiable_at ℝ f x)
(h_infty : tendsto (λ x, ∥f x∥) (𝓝[≠] c) at_top) (hg : is_O (deriv f) g (𝓝[≠] c))
(hne : a ≠ b) (hc : c ∈ [a, b]) :
¬interval_integrable g volume a b :=
have 𝓝[[a, b] \ {c}] c ≤ 𝓝[≠] c, from nhds_within_mono _ (inter_subset_right _ _),
not_interval_integrable_of_tendsto_norm_at_top_of_deriv_is_O_within_diff_singleton hne hc
(h_deriv.filter_mono this) (h_infty.mono_left this) (hg.mono this)
/-- If `f` grows in the punctured neighborhood of `c : ℝ` at least as fast as `1 / (x - c)`,
then it is not interval integrable on any nontrivial interval `a..b`, `c ∈ [a, b]`. -/
lemma not_interval_integrable_of_sub_inv_is_O_punctured {f : ℝ → F} {a b c : ℝ}
(hf : is_O (λ x, (x - c)⁻¹) f (𝓝[≠] c)) (hne : a ≠ b) (hc : c ∈ [a, b]) :
¬interval_integrable f volume a b :=
begin
have A : ∀ᶠ x in 𝓝[≠] c, has_deriv_at (λ x, real.log (x - c)) (x - c)⁻¹ x,
{ filter_upwards [self_mem_nhds_within] with x hx,
simpa using ((has_deriv_at_id x).sub_const c).log (sub_ne_zero.2 hx) },
have B : tendsto (λ x, ∥real.log (x - c)∥) (𝓝[≠] c) at_top,
{ refine tendsto_abs_at_bot_at_top.comp (real.tendsto_log_nhds_within_zero.comp _),
rw ← sub_self c,
exact ((has_deriv_at_id c).sub_const c).tendsto_punctured_nhds one_ne_zero },
exact not_interval_integrable_of_tendsto_norm_at_top_of_deriv_is_O_punctured
(A.mono (λ x hx, hx.differentiable_at)) B
(hf.congr' (A.mono $ λ x hx, hx.deriv.symm) eventually_eq.rfl) hne hc
end
/-- The function `λ x, (x - c)⁻¹` is integrable on `a..b` if and only if `a = b` or `c ∉ [a, b]`. -/
@[simp] lemma interval_integrable_sub_inv_iff {a b c : ℝ} :
interval_integrable (λ x, (x - c)⁻¹) volume a b ↔ a = b ∨ c ∉ [a, b] :=
begin
split,
{ refine λ h, or_iff_not_imp_left.2 (λ hne hc, _),
exact not_interval_integrable_of_sub_inv_is_O_punctured (is_O_refl _ _) hne hc h },
{ rintro (rfl|h₀),
exacts [interval_integrable.refl,
interval_integrable_inv (λ x hx, sub_ne_zero.2 $ ne_of_mem_of_not_mem hx h₀)
(continuous_on_id.sub continuous_on_const)] }
end
/-- The function `λ x, x⁻¹` is integrable on `a..b` if and only if `a = b` or `0 ∉ [a, b]`. -/
@[simp] lemma interval_integrable_inv_iff {a b : ℝ} :
interval_integrable (λ x, x⁻¹) volume a b ↔ a = b ∨ (0 : ℝ) ∉ [a, b] :=
by simp only [← interval_integrable_sub_inv_iff, sub_zero]
|
6e8ecb1b7720f2ec70936d46bed355e222c0a4f6 | f68ef9a599ec5575db7b285d4960e63c5d464ccc | /Exercises/Lista 4/garrafas.lean | 8ef894c600b181a7bfedc3b14b2b854d31dae24a | [] | no_license | lucasmoschen/discrete-mathematics | a38d5970cc571b0b9d202bf6a43efeb8ed6f66e3 | 0f1945cc5eb094814c926cd6ae4a8b4c5c579a1e | refs/heads/master | 1,677,111,757,003 | 1,611,500,097,000 | 1,611,500,097,000 | 205,903,359 | 1 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 1,048 | lean | /-
Alunos:
- Fulano da Silva
- Beltrano Rodrigues
Considere uma fonte de água inesgotável e duas garrafas, uma de 5 e
outra de 7 litros, as quais não possuem quaisquer marcações que
possibilitem medidas de volumes intermediários às suas respectivas
capacidades. O formato das mesmas também impede o uso de aparelhos de
medição indireta, assim como não há uma balança disponível.
Considerando essas condições, pergunta-se se é possível armazenar o
volume exato de 6 litros de água.
É possível que você já conheça a solução deste problema ou mesmo saiba
que, no caso geral de duas garrafas com capacidade que representem
números primos entre si, pode-se medir qualquer volume inteiro até a
capacidade da maior garrafa. De qq forma, pretende-se construir
primeiro um conjunto de sentenças que representem o problema e somente
depois, via o uso do conceito de consequência lógica, verificar se é
possível medir 6 litros nas condições estipuladas. Neste exercício,
pede-se apenas a formalização em FOL.
-/
|
dd5718b33096b7c7a11063518bce8042a36bdabc | 07f5f86b00fed90a419ccda4298d8b795a68f657 | /tests/lean/run/quote_bas.lean | 20253e3b9d4c49b1911fd141b963428e9f260fad | [
"Apache-2.0"
] | permissive | VBaratham/lean | 8ec5c3167b4835cfbcd7f25e2173d61ad9416b3a | 450ca5834c1c35318e4b47d553bb9820c1b3eee7 | refs/heads/master | 1,629,649,471,814 | 1,512,060,373,000 | 1,512,060,469,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 2,502 | lean | universes u v w
namespace quote_bas
inductive Expr (V : Type u)
| One {} : Expr
| Var (v : V) : Expr
| Mult (a b : Expr) : Expr
@[reducible] def Value := nat
def Env (V : Type u) := V → Value
open Expr
def evalExpr {V} (vs : Env V) : Expr V → Value
| One := 1
| (Var v) := vs v
| (Mult a b) := evalExpr a * evalExpr b
def novars : Env empty :=
empty.rec _
def singlevar (x : Value) : Env unit :=
λ _, x
open sum
def merge {A : Type u} {B : Type v} (a : Env A) (b : Env B) : Env (sum A B)
| (inl j) := a j
| (inr j) := b j
def map_var {A : Type u} {B : Type v} (f : A → B) : Expr A → Expr B
| One := One
| (Var v) := Var (f v)
| (Mult a b) := Mult (map_var a) (map_var b)
def sum_assoc {A : Type u} {B : Type v} {C : Type w} : sum (sum A B) C → sum A (sum B C)
| (inl (inl a)) := inl a
| (inl (inr b)) := inr (inl b)
| (inr c) := inr (inr c)
attribute [simp] evalExpr map_var sum_assoc merge
@[simp] lemma eval_map_var_shift {A : Type u} {B : Type v} (v : Env A) (v' : Env B) (e : Expr A) : evalExpr (merge v v') (map_var inl e) = evalExpr v e :=
begin
induction e,
reflexivity,
reflexivity,
simp [*]
end
@[simp] lemma eval_map_var_sum_assoc {A : Type u} {B : Type v} {C : Type w} (v : Env A) (v' : Env B) (v'' : Env C) (e : Expr (sum (sum A B) C)) :
evalExpr (merge v (merge v' v'')) (map_var sum_assoc e) = evalExpr (merge (merge v v') v'') e :=
begin
induction e,
reflexivity,
{ cases v_1 with v₁, cases v₁, all_goals {simp} },
{ simp [*] }
end
class Quote {V : inout Type u} (l : inout Env V) (n : Value) {V' : inout Type v} (r : inout Env V') :=
(quote : Expr (sum V V'))
(eval_quote : evalExpr (merge l r) quote = n)
def quote {V : Type u} {l : Env V} (n : nat) {V' : Type v} {r : Env V'} [Quote l n r] : Expr (sum V V') :=
Quote.quote l n r
@[simp] lemma eval_quote {V : Type u} {l : Env V} (n : nat) {V' : Type v} {r : Env V'} [Quote l n r] : evalExpr (merge l r) (quote n) = n :=
Quote.eval_quote l n r
instance quote_one (V) (v : Env V) : Quote v 1 novars :=
{ quote := One,
eval_quote := rfl }
instance quote_mul {V : Type u} (v : Env V) (n) {V' : Type v} (v' : Env V') (m) {V'' : Type w} (v'' : Env V'')
[Quote v n v'] [Quote (merge v v') m v''] :
Quote v (n * m) (merge v' v'') :=
{ quote := Mult (map_var sum_assoc (map_var inl (quote n))) (map_var sum_assoc (quote m)),
eval_quote := by simp }
end quote_bas
|
81862e73b02d0957f2a6af9b9efd148e932cdb01 | a9d0fb7b0e4f802bd3857b803e6c5c23d87fef91 | /hott/types/pointed.hlean | 178fd7dd4f9372b4f845d65f1220b804da45a769 | [
"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 | 18,774 | hlean | /-
Copyright (c) 2014 Jakob von Raumer. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jakob von Raumer, Floris van Doorn
Ported from Coq HoTT
-/
import arity .eq .bool .unit .sigma .nat.basic prop_trunc
open is_trunc eq prod sigma nat equiv option is_equiv bool unit algebra sigma.ops
structure pointed [class] (A : Type) :=
(point : A)
structure pType :=
(carrier : Type)
(Point : carrier)
notation `Type*` := pType
section
universe variable u
structure ptrunctype (n : trunc_index) extends trunctype.{u} n, pType.{u}
end
notation n `-Type*` := ptrunctype n
abbreviation pSet [parsing_only] := 0-Type*
notation `Set*` := pSet
namespace pointed
attribute pType.carrier [coercion]
variables {A B : Type}
definition pt [unfold 2] [H : pointed A] := point A
definition Point [unfold 1] (A : Type*) := pType.Point A
abbreviation carrier [unfold 1] (A : Type*) := pType.carrier A
protected definition Mk [constructor] {A : Type} (a : A) := pType.mk A a
protected definition MK [constructor] (A : Type) (a : A) := pType.mk A a
protected definition mk' [constructor] (A : Type) [H : pointed A] : Type* :=
pType.mk A (point A)
definition pointed_carrier [instance] [constructor] (A : Type*) : pointed A :=
pointed.mk (Point A)
-- Any contractible type is pointed
definition pointed_of_is_contr [instance] [priority 800] [constructor]
(A : Type) [H : is_contr A] : pointed A :=
pointed.mk !center
-- A pi type with a pointed target is pointed
definition pointed_pi [instance] [constructor] (P : A → Type) [H : Πx, pointed (P x)]
: pointed (Πx, P x) :=
pointed.mk (λx, pt)
-- A sigma type of pointed components is pointed
definition pointed_sigma [instance] [constructor] (P : A → Type) [G : pointed A]
[H : pointed (P pt)] : pointed (Σx, P x) :=
pointed.mk ⟨pt,pt⟩
definition pointed_prod [instance] [constructor] (A B : Type) [H1 : pointed A] [H2 : pointed B]
: pointed (A × B) :=
pointed.mk (pt,pt)
definition pointed_loop [instance] [constructor] (a : A) : pointed (a = a) :=
pointed.mk idp
definition pointed_bool [instance] [constructor] : pointed bool :=
pointed.mk ff
definition pprod [constructor] (A B : Type*) : Type* :=
pointed.mk' (A × B)
infixr ` ×* `:35 := pprod
definition pointed_fun_closed [constructor] (f : A → B) [H : pointed A] : pointed B :=
pointed.mk (f pt)
definition ploop_space [reducible] [constructor] (A : Type*) : Type* :=
pointed.mk' (point A = point A)
definition iterated_ploop_space [reducible] : ℕ → Type* → Type*
| iterated_ploop_space 0 X := X
| iterated_ploop_space (n+1) X := ploop_space (iterated_ploop_space n X)
prefix `Ω`:(max+5) := ploop_space
notation `Ω[`:95 n:0 `] `:0 A:95 := iterated_ploop_space n A
definition iterated_ploop_space_zero [unfold_full] (A : Type*)
: Ω[0] A = A := rfl
definition iterated_ploop_space_succ [unfold_full] (k : ℕ) (A : Type*)
: Ω[succ k] A = Ω Ω[k] A := rfl
definition rfln [constructor] [reducible] {A : Type*} {n : ℕ} : Ω[n] A := pt
definition refln [constructor] [reducible] (A : Type*) (n : ℕ) : Ω[n] A := pt
definition refln_eq_refl (A : Type*) (n : ℕ) : rfln = rfl :> Ω[succ n] A := rfl
definition iterated_loop_space [unfold 3] (A : Type) [H : pointed A] (n : ℕ) : Type :=
Ω[n] (pointed.mk' A)
definition pType_eq {A B : Type*} (f : A ≃ B) (p : f pt = pt) : A = B :=
begin
cases A with A a, cases B with B b, esimp at *,
fapply apd011 @pType.mk,
{ apply ua f},
{ rewrite [cast_ua,p]},
end
definition pType_eq_elim {A B : Type*} (p : A = B :> Type*)
: Σ(p : carrier A = carrier B :> Type), cast p pt = pt :=
by induction p; exact ⟨idp, idp⟩
protected definition pType.sigma_char.{u} : pType.{u} ≃ Σ(X : Type.{u}), X :=
begin
fapply equiv.MK,
{ intro x, induction x with X x, exact ⟨X, x⟩},
{ intro x, induction x with X x, exact pointed.MK X x},
{ intro x, induction x with X x, reflexivity},
{ intro x, induction x with X x, reflexivity},
end
definition add_point [constructor] (A : Type) : Type* :=
pointed.Mk (none : option A)
postfix `₊`:(max+1) := add_point
-- the inclusion A → A₊ is called "some", the extra point "pt" or "none" ("@none A")
end pointed open pointed
protected definition ptrunctype.mk' [constructor] (n : trunc_index)
(A : Type) [pointed A] [is_trunc n A] : n-Type* :=
ptrunctype.mk A _ pt
protected definition pSet.mk [constructor] := @ptrunctype.mk (-1.+1)
protected definition pSet.mk' [constructor] := ptrunctype.mk' (-1.+1)
definition ptrunctype_of_trunctype [constructor] {n : trunc_index} (A : n-Type) (a : A) : n-Type* :=
ptrunctype.mk A _ a
definition ptrunctype_of_pType [constructor] {n : trunc_index} (A : Type*) (H : is_trunc n A)
: n-Type* :=
ptrunctype.mk A _ pt
definition pSet_of_Set [constructor] (A : Set) (a : A) : Set* :=
ptrunctype.mk A _ a
definition pSet_of_pType [constructor] (A : Type*) (H : is_set A) : Set* :=
ptrunctype.mk A _ pt
attribute pType._trans_to_carrier ptrunctype.to_pType ptrunctype.to_trunctype [unfold 2]
definition ptrunctype_eq {n : trunc_index} {A B : n-Type*} (p : A = B :> Type) (q : cast p pt = pt)
: A = B :=
begin
induction A with A HA a, induction B with B HB b, esimp at *,
induction p, induction q,
esimp,
refine ap010 (ptrunctype.mk A) _ a,
exact !is_prop.elim
end
definition ptrunctype_eq_of_pType_eq {n : trunc_index} {A B : n-Type*} (p : A = B :> Type*)
: A = B :=
begin
cases pType_eq_elim p with q r,
exact ptrunctype_eq q r
end
namespace pointed
definition pbool [constructor] : Set* :=
pSet.mk' bool
definition punit [constructor] : Set* :=
pSet.mk' unit
/- properties of iterated loop space -/
variable (A : Type*)
definition loop_space_succ_eq_in (n : ℕ) : Ω[succ n] A = Ω[n] (Ω A) :=
begin
induction n with n IH,
{ reflexivity},
{ exact ap ploop_space IH}
end
definition loop_space_add (n m : ℕ) : Ω[n] (Ω[m] A) = Ω[m+n] (A) :=
begin
induction n with n IH,
{ reflexivity},
{ exact ap ploop_space IH}
end
definition loop_space_succ_eq_out (n : ℕ) : Ω[succ n] A = Ω(Ω[n] A) :=
idp
variable {A}
/- the equality [loop_space_succ_eq_in] preserves concatenation -/
theorem loop_space_succ_eq_in_concat {n : ℕ} (p q : Ω[succ (succ n)] A) :
transport carrier (ap ploop_space (loop_space_succ_eq_in A n)) (p ⬝ q)
= transport carrier (ap ploop_space (loop_space_succ_eq_in A n)) p
⬝ transport carrier (ap ploop_space (loop_space_succ_eq_in A n)) q :=
begin
rewrite [-+tr_compose, ↑function.compose],
rewrite [+@transport_eq_FlFr_D _ _ _ _ Point Point, +con.assoc], apply whisker_left,
rewrite [-+con.assoc], apply whisker_right, rewrite [con_inv_cancel_right, ▸*, -ap_con]
end
definition loop_space_loop_irrel (p : point A = point A) : Ω(pointed.Mk p) = Ω[2] A :=
begin
intros, fapply pType_eq,
{ esimp, transitivity _,
apply eq_equiv_fn_eq_of_equiv (equiv_eq_closed_right _ p⁻¹),
esimp, apply eq_equiv_eq_closed, apply con.right_inv, apply con.right_inv},
{ esimp, apply con.left_inv}
end
definition iterated_loop_space_loop_irrel (n : ℕ) (p : point A = point A)
: Ω[succ n](pointed.Mk p) = Ω[succ (succ n)] A :> pType :=
calc
Ω[succ n](pointed.Mk p) = Ω[n](Ω (pointed.Mk p)) : loop_space_succ_eq_in
... = Ω[n] (Ω[2] A) : loop_space_loop_irrel
... = Ω[2+n] A : loop_space_add
... = Ω[n+2] A : by rewrite [algebra.add.comm]
end pointed open pointed
/- pointed maps -/
structure pmap (A B : Type*) :=
(to_fun : A → B)
(resp_pt : to_fun (Point A) = Point B)
namespace pointed
abbreviation respect_pt [unfold 3] := @pmap.resp_pt
notation `map₊` := pmap
infix ` →* `:30 := pmap
attribute pmap.to_fun [coercion]
end pointed open pointed
/- pointed homotopies -/
structure phomotopy {A B : Type*} (f g : A →* B) :=
(homotopy : f ~ g)
(homotopy_pt : homotopy pt ⬝ respect_pt g = respect_pt f)
namespace pointed
variables {A B C D : Type*} {f g h : A →* B}
infix ` ~* `:50 := phomotopy
abbreviation to_homotopy_pt [unfold 5] := @phomotopy.homotopy_pt
abbreviation to_homotopy [coercion] [unfold 5] (p : f ~* g) : Πa, f a = g a :=
phomotopy.homotopy p
/- categorical properties of pointed maps -/
definition pid [constructor] [refl] (A : Type*) : A →* A :=
pmap.mk id idp
definition pcompose [constructor] [trans] (g : B →* C) (f : A →* B) : A →* C :=
pmap.mk (λa, g (f a)) (ap g (respect_pt f) ⬝ respect_pt g)
infixr ` ∘* `:60 := pcompose
definition passoc (h : C →* D) (g : B →* C) (f : A →* B) : (h ∘* g) ∘* f ~* h ∘* (g ∘* f) :=
begin
fconstructor, intro a, reflexivity,
cases A, cases B, cases C, cases D, cases f with f pf, cases g with g pg, cases h with h ph,
esimp at *,
induction pf, induction pg, induction ph, reflexivity
end
definition pid_comp (f : A →* B) : pid B ∘* f ~* f :=
begin
fconstructor,
{ intro a, reflexivity},
{ reflexivity}
end
definition comp_pid (f : A →* B) : f ∘* pid A ~* f :=
begin
fconstructor,
{ intro a, reflexivity},
{ reflexivity}
end
/- equivalences and equalities -/
definition pmap_eq (r : Πa, f a = g a) (s : respect_pt f = (r pt) ⬝ respect_pt g) : f = g :=
begin
cases f with f p, cases g with g q,
esimp at *,
fapply apo011 pmap.mk,
{ exact eq_of_homotopy r},
{ apply concato_eq, apply pathover_eq_Fl, apply inv_con_eq_of_eq_con,
rewrite [ap_eq_ap10,↑ap10,apd10_eq_of_homotopy,s]}
end
definition pmap_equiv_left (A : Type) (B : Type*) : A₊ →* B ≃ (A → B) :=
begin
fapply equiv.MK,
{ intro f a, cases f with f p, exact f (some a)},
{ intro f, fconstructor,
intro a, cases a, exact pt, exact f a,
reflexivity},
{ intro f, reflexivity},
{ intro f, cases f with f p, esimp, fapply pmap_eq,
{ intro a, cases a; all_goals (esimp at *), exact p⁻¹},
{ esimp, exact !con.left_inv⁻¹}},
end
definition pmap_equiv_right (A : Type*) (B : Type)
: (Σ(b : B), A →* (pointed.Mk b)) ≃ (A → B) :=
begin
fapply equiv.MK,
{ intro u a, exact pmap.to_fun u.2 a},
{ intro f, refine ⟨f pt, _⟩, fapply pmap.mk,
intro a, esimp, exact f a,
reflexivity},
{ intro f, reflexivity},
{ intro u, cases u with b f, cases f with f p, esimp at *, induction p,
reflexivity}
end
definition pmap_bool_equiv (B : Type*) : (pbool →* B) ≃ B :=
begin
fapply equiv.MK,
{ intro f, cases f with f p, exact f tt},
{ intro b, fconstructor,
intro u, cases u, exact pt, exact b,
reflexivity},
{ intro b, reflexivity},
{ intro f, cases f with f p, esimp, fapply pmap_eq,
{ intro a, cases a; all_goals (esimp at *), exact p⁻¹},
{ esimp, exact !con.left_inv⁻¹}},
end
-- The constant pointed map between any two types
definition pconst [constructor] (A B : Type*) : A →* B :=
pmap.mk (λ a, Point B) idp
-- the pointed type of pointed maps
definition ppmap [constructor] (A B : Type*) : Type* :=
pType.mk (A →* B) (pconst A B)
/- instances of pointed maps -/
definition ap1 [constructor] (f : A →* B) : Ω A →* Ω B :=
begin
fconstructor,
{ intro p, exact !respect_pt⁻¹ ⬝ ap f p ⬝ !respect_pt},
{ esimp, apply con.left_inv}
end
definition apn (n : ℕ) (f : map₊ A B) : Ω[n] A →* Ω[n] B :=
begin
induction n with n IH,
{ exact f},
{ esimp [iterated_ploop_space], exact ap1 IH}
end
prefix `Ω→`:(max+5) := ap1
notation `Ω→[`:95 n:0 `] `:0 f:95 := apn n f
definition apn_zero (f : map₊ A B) : Ω→[0] f = f := idp
definition apn_succ (n : ℕ) (f : map₊ A B) : Ω→[n + 1] f = ap1 (Ω→[n] f) := idp
definition pcast [constructor] {A B : Type*} (p : A = B) : A →* B :=
proof pmap.mk (cast (ap pType.carrier p)) (by induction p; reflexivity) qed
definition pinverse [constructor] {X : Type*} : Ω X →* Ω X :=
pmap.mk eq.inverse idp
/- categorical properties of pointed homotopies -/
protected definition phomotopy.refl [constructor] [refl] (f : A →* B) : f ~* f :=
begin
fconstructor,
{ intro a, exact idp},
{ apply idp_con}
end
protected definition phomotopy.rfl [constructor] {A B : Type*} {f : A →* B} : f ~* f :=
phomotopy.refl f
protected definition phomotopy.trans [constructor] [trans] (p : f ~* g) (q : g ~* h)
: f ~* h :=
phomotopy.mk (λa, p a ⬝ q a)
abstract begin
induction f, induction g, induction p with p p', induction q with q q', esimp at *,
induction p', induction q', esimp, apply con.assoc
end end
protected definition phomotopy.symm [constructor] [symm] (p : f ~* g) : g ~* f :=
phomotopy.mk (λa, (p a)⁻¹)
abstract begin
induction f, induction p with p p', esimp at *,
induction p', esimp, apply inv_con_cancel_left
end end
infix ` ⬝* `:75 := phomotopy.trans
postfix `⁻¹*`:(max+1) := phomotopy.symm
/- properties about the given pointed maps -/
definition is_equiv_ap1 {A B : Type*} (f : A →* B) [is_equiv f] : is_equiv (ap1 f) :=
begin
induction B with B b, induction f with f pf, esimp at *, cases pf, esimp,
apply is_equiv.homotopy_closed (ap f),
intro p, exact !idp_con⁻¹
end
definition is_equiv_apn {A B : Type*} (n : ℕ) (f : A →* B) [H : is_equiv f]
: is_equiv (apn n f) :=
begin
induction n with n IH,
{ exact H},
{ exact is_equiv_ap1 (apn n f)}
end
definition ap1_id [constructor] {A : Type*} : ap1 (pid A) ~* pid (Ω A) :=
begin
fapply phomotopy.mk,
{ intro p, esimp, refine !idp_con ⬝ !ap_id},
{ reflexivity}
end
definition ap1_pinverse {A : Type*} : ap1 (@pinverse A) ~* @pinverse (Ω A) :=
begin
fapply phomotopy.mk,
{ intro p, esimp, refine !idp_con ⬝ _, exact !inverse_eq_inverse2⁻¹ },
{ reflexivity}
end
definition ap1_compose (g : B →* C) (f : A →* B) : ap1 (g ∘* f) ~* ap1 g ∘* ap1 f :=
begin
induction B, induction C, induction g with g pg, induction f with f pf, esimp at *,
induction pg, induction pf,
fconstructor,
{ intro p, esimp, apply whisker_left, exact ap_compose g f p ⬝ ap (ap g) !idp_con⁻¹},
{ reflexivity}
end
definition ap1_compose_pinverse (f : A →* B) : ap1 f ∘* pinverse ~* pinverse ∘* ap1 f :=
begin
fconstructor,
{ intro p, esimp, refine !con.assoc ⬝ _ ⬝ !con_inv⁻¹, apply whisker_left,
refine whisker_right !ap_inv _ ⬝ _ ⬝ !con_inv⁻¹, apply whisker_left,
exact !inv_inv⁻¹},
{ induction B with B b, induction f with f pf, esimp at *, induction pf, reflexivity},
end
theorem ap1_con (f : A →* B) (p q : Ω A) : ap1 f (p ⬝ q) = ap1 f p ⬝ ap1 f q :=
begin
rewrite [▸*,ap_con, +con.assoc, con_inv_cancel_left], repeat apply whisker_left
end
theorem ap1_inv (f : A →* B) (p : Ω A) : ap1 f p⁻¹ = (ap1 f p)⁻¹ :=
begin
rewrite [▸*,ap_inv, +con_inv, inv_inv, +con.assoc], repeat apply whisker_left
end
definition pcast_ap_loop_space {A B : Type*} (p : A = B)
: pcast (ap ploop_space p) ~* Ω→ (pcast p) :=
begin
induction p, exact !ap1_id⁻¹*
end
definition pinverse_con [constructor] {X : Type*} (p q : Ω X)
: pinverse (p ⬝ q) = pinverse q ⬝ pinverse p :=
!con_inv
definition pinverse_inv [constructor] {X : Type*} (p : Ω X)
: pinverse p⁻¹ = (pinverse p)⁻¹ :=
idp
/- more on pointed homotopies -/
definition phomotopy_of_eq [constructor] {A B : Type*} {f g : A →* B} (p : f = g) : f ~* g :=
phomotopy.mk (ap010 pmap.to_fun p) begin induction p, apply idp_con end
definition pconcat_eq [constructor] {A B : Type*} {f g h : A →* B} (p : f ~* g) (q : g = h)
: f ~* h :=
p ⬝* phomotopy_of_eq q
definition eq_pconcat [constructor] {A B : Type*} {f g h : A →* B} (p : f = g) (q : g ~* h)
: f ~* h :=
phomotopy_of_eq p ⬝* q
definition pwhisker_left [constructor] (h : B →* C) (p : f ~* g) : h ∘* f ~* h ∘* g :=
phomotopy.mk (λa, ap h (p a))
abstract begin
induction A, induction B, induction C,
induction f with f pf, induction g with g pg, induction h with h ph,
induction p with p p', esimp at *, induction ph, induction pg, induction p', reflexivity
end end
definition pwhisker_right [constructor] (h : C →* A) (p : f ~* g) : f ∘* h ~* g ∘* h :=
phomotopy.mk (λa, p (h a))
abstract begin
induction A, induction B, induction C,
induction f with f pf, induction g with g pg, induction h with h ph,
induction p with p p', esimp at *, induction ph, induction pg, induction p', esimp,
exact !idp_con⁻¹
end end
definition pconcat2 [constructor] {A B C : Type*} {h i : B →* C} {f g : A →* B}
(q : h ~* i) (p : f ~* g) : h ∘* f ~* i ∘* g :=
pwhisker_left _ p ⬝* pwhisker_right _ q
definition eq_of_phomotopy (p : f ~* g) : f = g :=
begin
fapply pmap_eq,
{ intro a, exact p a},
{ exact !to_homotopy_pt⁻¹}
end
definition pap {A B C D : Type*} (F : (A →* B) → (C →* D))
{f g : A →* B} (p : f ~* g) : F f ~* F g :=
phomotopy.mk (ap010 F (eq_of_phomotopy p)) begin cases eq_of_phomotopy p, apply idp_con end
-- TODO: give proof without using function extensionality (commented out part is a start)
definition ap1_phomotopy {A B : Type*} {f g : A →* B} (p : f ~* g)
: ap1 f ~* ap1 g :=
pap ap1 p
/- begin
induction p with p q, induction f with f pf, induction g with g pg, induction B with B b,
esimp at *, induction q, induction pg,
fapply phomotopy.mk,
{ intro l, esimp, refine _ ⬝ !idp_con⁻¹, refine !con.assoc ⬝ _, apply inv_con_eq_of_eq_con,
apply ap_con_eq_con_ap},
{ esimp, }
end -/
definition apn_compose (n : ℕ) (g : B →* C) (f : A →* B) : apn n (g ∘* f) ~* apn n g ∘* apn n f :=
begin
induction n with n IH,
{ reflexivity},
{ refine ap1_phomotopy IH ⬝* _, apply ap1_compose}
end
theorem apn_con (n : ℕ) (f : A →* B) (p q : Ω[n+1] A)
: apn (n+1) f (p ⬝ q) = apn (n+1) f p ⬝ apn (n+1) f q :=
by rewrite [+apn_succ, ap1_con]
theorem apn_inv (n : ℕ) (f : A →* B) (p : Ω[n+1] A) : apn (n+1) f p⁻¹ = (apn (n+1) f p)⁻¹ :=
by rewrite [+apn_succ, ap1_inv]
infix ` ⬝*p `:75 := pconcat_eq
infix ` ⬝p* `:75 := eq_pconcat
end pointed
|
2c702eb28d5b597c578a69088e87045fc0d1ef60 | c31182a012eec69da0a1f6c05f42b0f0717d212d | /src/for_mathlib/Fintype.lean | bd90df039b117d40c8c3601b757d4860a19b3b29 | [] | 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 | 367 | lean | import category_theory.Fintype
namespace Fintype
/-- An equivalence between finite types induces an isomorphism in `Fintype`. -/
@[simps]
def iso_of_equiv {A B : Fintype} (e : A ≃ B) : A ≅ B :=
{ hom := e,
inv := e.symm,
hom_inv_id' := by { ext t, change e.symm (e t) = t, simp },
inv_hom_id' := by { ext t, change e (e.symm t) = t, simp } }
end Fintype
|
de9c686d62f4a94dcf66c25b67ff8f9bd61d2a3c | 969dbdfed67fda40a6f5a2b4f8c4a3c7dc01e0fb | /src/category_theory/limits/cones.lean | 11736101d4480fce9c2a72e2fecca6f7630c6840 | [
"Apache-2.0"
] | permissive | SAAluthwela/mathlib | 62044349d72dd63983a8500214736aa7779634d3 | 83a4b8b990907291421de54a78988c024dc8a552 | refs/heads/master | 1,679,433,873,417 | 1,615,998,031,000 | 1,615,998,031,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 29,487 | lean | /-
Copyright (c) 2017 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Stephen Morgan, Scott Morrison, Floris van Doorn
-/
import category_theory.const
import category_theory.discrete_category
import category_theory.yoneda
import category_theory.reflects_isomorphisms
universes v u u' -- declare the `v`'s first; see `category_theory.category` for an explanation
open category_theory
variables {J : Type v} [small_category J]
variables {C : Type u} [category.{v} C]
open category_theory
open category_theory.category
open category_theory.functor
open opposite
namespace category_theory
namespace functor
variables {J C} (F : J ⥤ C)
/--
`F.cones` is the functor assigning to an object `X` the type of
natural transformations from the constant functor with value `X` to `F`.
An object representing this functor is a limit of `F`.
-/
@[simps]
def cones : Cᵒᵖ ⥤ Type v := (const J).op ⋙ (yoneda.obj F)
/--
`F.cocones` is the functor assigning to an object `X` the type of
natural transformations from `F` to the constant functor with value `X`.
An object corepresenting this functor is a colimit of `F`.
-/
@[simps]
def cocones : C ⥤ Type v := const J ⋙ coyoneda.obj (op F)
end functor
section
variables (J C)
/--
Functorially associated to each functor `J ⥤ C`, we have the `C`-presheaf consisting of
cones with a given cone point.
-/
@[simps] def cones : (J ⥤ C) ⥤ (Cᵒᵖ ⥤ Type v) :=
{ obj := functor.cones,
map := λ F G f, whisker_left (const J).op (yoneda.map f) }
/--
Contravariantly associated to each functor `J ⥤ C`, we have the `C`-copresheaf consisting of
cocones with a given cocone point.
-/
@[simps] def cocones : (J ⥤ C)ᵒᵖ ⥤ (C ⥤ Type v) :=
{ obj := λ F, functor.cocones (unop F),
map := λ F G f, whisker_left (const J) (coyoneda.map f) }
end
namespace limits
/--
A `c : cone F` is:
* an object `c.X` and
* a natural transformation `c.π : c.X ⟶ F` from the constant `c.X` functor to `F`.
`cone F` is equivalent, via `cone.equiv` below, to `Σ X, F.cones.obj X`.
-/
structure cone (F : J ⥤ C) :=
(X : C)
(π : (const J).obj X ⟶ F)
instance inhabited_cone (F : discrete punit ⥤ C) : inhabited (cone F) :=
⟨{ X := F.obj punit.star,
π :=
{ app := λ X, match X with
| punit.star := 𝟙 _
end } }⟩
@[simp, reassoc] lemma cone.w {F : J ⥤ C} (c : cone F) {j j' : J} (f : j ⟶ j') :
c.π.app j ≫ F.map f = c.π.app j' :=
by { rw ← (c.π.naturality f), apply id_comp }
/--
A `c : cocone F` is
* an object `c.X` and
* a natural transformation `c.ι : F ⟶ c.X` from `F` to the constant `c.X` functor.
`cocone F` is equivalent, via `cone.equiv` below, to `Σ X, F.cocones.obj X`.
-/
structure cocone (F : J ⥤ C) :=
(X : C)
(ι : F ⟶ (const J).obj X)
instance inhabited_cocone (F : discrete punit ⥤ C) : inhabited (cocone F) :=
⟨{ X := F.obj punit.star,
ι :=
{ app := λ X, match X with
| punit.star := 𝟙 _
end } }⟩
@[simp, reassoc] lemma cocone.w {F : J ⥤ C} (c : cocone F) {j j' : J} (f : j ⟶ j') :
F.map f ≫ c.ι.app j' = c.ι.app j :=
by { rw (c.ι.naturality f), apply comp_id }
variables {F : J ⥤ C}
namespace cone
/-- The isomorphism between a cone on `F` and an element of the functor `F.cones`. -/
def equiv (F : J ⥤ C) : cone F ≅ Σ X, F.cones.obj X :=
{ hom := λ c, ⟨op c.X, c.π⟩,
inv := λ c, { X := unop c.1, π := c.2 },
hom_inv_id' := begin ext1, cases x, refl, end,
inv_hom_id' := begin ext1, cases x, refl, end }
/-- A map to the vertex of a cone naturally induces a cone by composition. -/
@[simp] def extensions (c : cone F) : yoneda.obj c.X ⟶ F.cones :=
{ app := λ X f, (const J).map f ≫ c.π }
/-- A map to the vertex of a cone induces a cone by composition. -/
@[simp] def extend (c : cone F) {X : C} (f : X ⟶ c.X) : cone F :=
{ X := X,
π := c.extensions.app (op X) f }
@[simp] lemma extend_π (c : cone F) {X : Cᵒᵖ} (f : unop X ⟶ c.X) :
(extend c f).π = c.extensions.app X f :=
rfl
/-- Whisker a cone by precomposition of a functor. -/
@[simps] def whisker {K : Type v} [small_category K] (E : K ⥤ J) (c : cone F) : cone (E ⋙ F) :=
{ X := c.X,
π := whisker_left E c.π }
end cone
namespace cocone
/-- The isomorphism between a cocone on `F` and an element of the functor `F.cocones`. -/
def equiv (F : J ⥤ C) : cocone F ≅ Σ X, F.cocones.obj X :=
{ hom := λ c, ⟨c.X, c.ι⟩,
inv := λ c, { X := c.1, ι := c.2 },
hom_inv_id' := begin ext1, cases x, refl, end,
inv_hom_id' := begin ext1, cases x, refl, end }
/-- A map from the vertex of a cocone naturally induces a cocone by composition. -/
@[simp] def extensions (c : cocone F) : coyoneda.obj (op c.X) ⟶ F.cocones :=
{ app := λ X f, c.ι ≫ (const J).map f }
/-- A map from the vertex of a cocone induces a cocone by composition. -/
@[simp] def extend (c : cocone F) {X : C} (f : c.X ⟶ X) : cocone F :=
{ X := X,
ι := c.extensions.app X f }
@[simp] lemma extend_ι (c : cocone F) {X : C} (f : c.X ⟶ X) :
(extend c f).ι = c.extensions.app X f :=
rfl
/--
Whisker a cocone by precomposition of a functor. See `whiskering` for a functorial
version.
-/
@[simps] def whisker {K : Type v} [small_category K] (E : K ⥤ J) (c : cocone F) : cocone (E ⋙ F) :=
{ X := c.X,
ι := whisker_left E c.ι }
end cocone
/-- A cone morphism between two cones for the same diagram is a morphism of the cone points which
commutes with the cone legs. -/
@[ext] structure cone_morphism (A B : cone F) :=
(hom : A.X ⟶ B.X)
(w' : ∀ j : J, hom ≫ B.π.app j = A.π.app j . obviously)
restate_axiom cone_morphism.w'
attribute [simp, reassoc] cone_morphism.w
instance inhabited_cone_morphism (A : cone F) : inhabited (cone_morphism A A) :=
⟨{ hom := 𝟙 _}⟩
/-- The category of cones on a given diagram. -/
@[simps] instance cone.category : category.{v} (cone F) :=
{ hom := λ A B, cone_morphism A B,
comp := λ X Y Z f g, { hom := f.hom ≫ g.hom },
id := λ B, { hom := 𝟙 B.X } }
namespace cones
/-- To give an isomorphism between cones, it suffices to give an
isomorphism between their vertices which commutes with the cone
maps. -/
@[ext, simps] def ext {c c' : cone F}
(φ : c.X ≅ c'.X) (w : ∀ j, c.π.app j = φ.hom ≫ c'.π.app j) : c ≅ c' :=
{ hom := { hom := φ.hom },
inv := { hom := φ.inv, w' := λ j, φ.inv_comp_eq.mpr (w j) } }
/--
Given a cone morphism whose object part is an isomorphism, produce an
isomorphism of cones.
-/
lemma cone_iso_of_hom_iso {K : J ⥤ C} {c d : cone K} (f : c ⟶ d) [i : is_iso f.hom] :
is_iso f :=
⟨{ hom := inv f.hom,
w' := λ j, (as_iso f.hom).inv_comp_eq.2 (f.w j).symm }, by tidy⟩
/--
Functorially postcompose a cone for `F` by a natural transformation `F ⟶ G` to give a cone for `G`.
-/
@[simps] def postcompose {G : J ⥤ C} (α : F ⟶ G) : cone F ⥤ cone G :=
{ obj := λ c, { X := c.X, π := c.π ≫ α },
map := λ c₁ c₂ f, { hom := f.hom, w' :=
by intro; erw ← category.assoc; simp [-category.assoc] } }
/-- Postcomposing a cone by the composite natural transformation `α ≫ β` is the same as
postcomposing by `α` and then by `β`. -/
def postcompose_comp {G H : J ⥤ C} (α : F ⟶ G) (β : G ⟶ H) :
postcompose (α ≫ β) ≅ postcompose α ⋙ postcompose β :=
nat_iso.of_components (λ s, cones.ext (iso.refl _) (by tidy)) (by tidy)
/-- Postcomposing by the identity does not change the cone up to isomorphism. -/
def postcompose_id : postcompose (𝟙 F) ≅ 𝟭 (cone F) :=
nat_iso.of_components (λ s, cones.ext (iso.refl _) (by tidy)) (by tidy)
/--
If `F` and `G` are naturally isomorphic functors, then they have equivalent categories of
cones.
-/
@[simps]
def postcompose_equivalence {G : J ⥤ C} (α : F ≅ G) : cone F ≌ cone G :=
{ functor := postcompose α.hom,
inverse := postcompose α.inv,
unit_iso := nat_iso.of_components (λ s, cones.ext (iso.refl _) (by tidy)) (by tidy),
counit_iso := nat_iso.of_components (λ s, cones.ext (iso.refl _) (by tidy)) (by tidy) }
/--
Whiskering on the left by `E : K ⥤ J` gives a functor from `cone F` to `cone (E ⋙ F)`.
-/
@[simps]
def whiskering {K : Type v} [small_category K] (E : K ⥤ J) : cone F ⥤ cone (E ⋙ F) :=
{ obj := λ c, c.whisker E,
map := λ c c' f, { hom := f.hom, } }
/--
Whiskering by an equivalence gives an equivalence between categories of cones.
-/
@[simps]
def whiskering_equivalence {K : Type v} [small_category K] (e : K ≌ J) :
cone F ≌ cone (e.functor ⋙ F) :=
{ functor := whiskering e.functor,
inverse := whiskering e.inverse ⋙
postcompose ((functor.associator _ _ _).inv ≫ (whisker_right (e.counit_iso).hom F) ≫
(functor.left_unitor F).hom),
unit_iso := nat_iso.of_components (λ s, cones.ext (iso.refl _) (by tidy)) (by tidy),
counit_iso := nat_iso.of_components (λ s, cones.ext (iso.refl _)
(begin
intro k,
have t := s.π.naturality (e.unit_inv.app k),
dsimp at t,
simp only [←e.counit_app_functor k, id_comp] at t,
dsimp,
simp [t],
end)) (by tidy), }
/--
The categories of cones over `F` and `G` are equivalent if `F` and `G` are naturally isomorphic
(possibly after changing the indexing category by an equivalence).
-/
@[simps functor_obj]
def equivalence_of_reindexing {K : Type v} [small_category K] {G : K ⥤ C}
(e : K ≌ J) (α : e.functor ⋙ F ≅ G) : cone F ≌ cone G :=
(whiskering_equivalence e).trans (postcompose_equivalence α)
section
variable (F)
/-- Forget the cone structure and obtain just the cone point. -/
@[simps]
def forget : cone F ⥤ C :=
{ obj := λ t, t.X, map := λ s t f, f.hom }
variables {D : Type u'} [category.{v} D] (G : C ⥤ D)
/-- A functor `G : C ⥤ D` sends cones over `F` to cones over `F ⋙ G` functorially. -/
@[simps] def functoriality : cone F ⥤ cone (F ⋙ G) :=
{ obj := λ A,
{ X := G.obj A.X,
π := { app := λ j, G.map (A.π.app j), naturality' := by intros; erw ←G.map_comp; tidy } },
map := λ X Y f,
{ hom := G.map f.hom,
w' := by intros; rw [←functor.map_comp, f.w] } }
instance functoriality_full [full G] [faithful G] : full (functoriality F G) :=
{ preimage := λ X Y t,
{ hom := G.preimage t.hom,
w' := λ j, G.map_injective (by simpa using t.w j) } }
instance functoriality_faithful [faithful G] : faithful (cones.functoriality F G) :=
{ map_injective' := λ X Y f g e, by { ext1, injection e, apply G.map_injective h_1 } }
/--
If `e : C ≌ D` is an equivalence of categories, then `functoriality F e.functor` induces an
equivalence between cones over `F` and cones over `F ⋙ e.functor`.
-/
@[simps]
def functoriality_equivalence (e : C ≌ D) : cone F ≌ cone (F ⋙ e.functor) :=
let f : (F ⋙ e.functor) ⋙ e.inverse ≅ F :=
functor.associator _ _ _ ≪≫ iso_whisker_left _ (e.unit_iso).symm ≪≫ functor.right_unitor _ in
{ functor := functoriality F e.functor,
inverse := (functoriality (F ⋙ e.functor) e.inverse) ⋙
(postcompose_equivalence f).functor,
unit_iso := nat_iso.of_components (λ c, cones.ext (e.unit_iso.app _) (by tidy)) (by tidy),
counit_iso := nat_iso.of_components (λ c, cones.ext (e.counit_iso.app _) (by tidy)) (by tidy), }
/--
If `F` reflects isomorphisms, then `cones.functoriality F` reflects isomorphisms
as well.
-/
instance reflects_cone_isomorphism (F : C ⥤ D) [reflects_isomorphisms F] (K : J ⥤ C) :
reflects_isomorphisms (cones.functoriality K F) :=
begin
constructor,
introsI,
haveI : is_iso (F.map f.hom) :=
(cones.forget (K ⋙ F)).map_is_iso ((cones.functoriality K F).map f),
haveI := reflects_isomorphisms.reflects F f.hom,
apply cone_iso_of_hom_iso
end
end
end cones
/-- A cocone morphism between two cocones for the same diagram is a morphism of the cocone points
which commutes with the cocone legs. -/
@[ext] structure cocone_morphism (A B : cocone F) :=
(hom : A.X ⟶ B.X)
(w' : ∀ j : J, A.ι.app j ≫ hom = B.ι.app j . obviously)
instance inhabited_cocone_morphism (A : cocone F) : inhabited (cocone_morphism A A) :=
⟨{ hom := 𝟙 _ }⟩
restate_axiom cocone_morphism.w'
attribute [simp, reassoc] cocone_morphism.w
@[simps] instance cocone.category : category.{v} (cocone F) :=
{ hom := λ A B, cocone_morphism A B,
comp := λ _ _ _ f g,
{ hom := f.hom ≫ g.hom },
id := λ B, { hom := 𝟙 B.X } }
namespace cocones
/-- To give an isomorphism between cocones, it suffices to give an
isomorphism between their vertices which commutes with the cocone
maps. -/
@[ext, simps] def ext {c c' : cocone F}
(φ : c.X ≅ c'.X) (w : ∀ j, c.ι.app j ≫ φ.hom = c'.ι.app j) : c ≅ c' :=
{ hom := { hom := φ.hom },
inv := { hom := φ.inv, w' := λ j, φ.comp_inv_eq.mpr (w j).symm } }
/--
Given a cocone morphism whose object part is an isomorphism, produce an
isomorphism of cocones.
-/
lemma cocone_iso_of_hom_iso {K : J ⥤ C} {c d : cocone K} (f : c ⟶ d) [i : is_iso f.hom] :
is_iso f :=
⟨{ hom := inv f.hom,
w' := λ j, (as_iso f.hom).comp_inv_eq.2 (f.w j).symm }, by tidy⟩
/-- Functorially precompose a cocone for `F` by a natural transformation `G ⟶ F` to give a cocone
for `G`. -/
@[simps] def precompose {G : J ⥤ C} (α : G ⟶ F) : cocone F ⥤ cocone G :=
{ obj := λ c, { X := c.X, ι := α ≫ c.ι },
map := λ c₁ c₂ f, { hom := f.hom } }
/-- Precomposing a cocone by the composite natural transformation `α ≫ β` is the same as
precomposing by `β` and then by `α`. -/
def precompose_comp {G H : J ⥤ C} (α : F ⟶ G) (β : G ⟶ H) :
precompose (α ≫ β) ≅ precompose β ⋙ precompose α :=
nat_iso.of_components (λ s, cocones.ext (iso.refl _) (by tidy)) (by tidy)
/-- Precomposing by the identity does not change the cocone up to isomorphism. -/
def precompose_id : precompose (𝟙 F) ≅ 𝟭 (cocone F) :=
nat_iso.of_components (λ s, cocones.ext (iso.refl _) (by tidy)) (by tidy)
/--
If `F` and `G` are naturally isomorphic functors, then they have equivalent categories of
cocones.
-/
@[simps]
def precompose_equivalence {G : J ⥤ C} (α : G ≅ F) : cocone F ≌ cocone G :=
{ functor := precompose α.hom,
inverse := precompose α.inv,
unit_iso := nat_iso.of_components (λ s, cocones.ext (iso.refl _) (by tidy)) (by tidy),
counit_iso := nat_iso.of_components (λ s, cocones.ext (iso.refl _) (by tidy)) (by tidy) }
/--
Whiskering on the left by `E : K ⥤ J` gives a functor from `cocone F` to `cocone (E ⋙ F)`.
-/
@[simps]
def whiskering {K : Type v} [small_category K] (E : K ⥤ J) : cocone F ⥤ cocone (E ⋙ F) :=
{ obj := λ c, c.whisker E,
map := λ c c' f, { hom := f.hom, } }
/--
Whiskering by an equivalence gives an equivalence between categories of cones.
-/
@[simps]
def whiskering_equivalence {K : Type v} [small_category K] (e : K ≌ J) :
cocone F ≌ cocone (e.functor ⋙ F) :=
{ functor := whiskering e.functor,
inverse := whiskering e.inverse ⋙
precompose ((functor.left_unitor F).inv ≫ (whisker_right (e.counit_iso).inv F) ≫
(functor.associator _ _ _).inv),
unit_iso := nat_iso.of_components (λ s, cocones.ext (iso.refl _) (by tidy)) (by tidy),
counit_iso := nat_iso.of_components (λ s, cocones.ext (iso.refl _)
(begin
intro k,
have t := s.ι.naturality (e.unit.app k),
dsimp at t,
simp only [←e.counit_inv_app_functor k, comp_id] at t,
dsimp,
simp [t],
end)) (by tidy), }
/--
The categories of cocones over `F` and `G` are equivalent if `F` and `G` are naturally isomorphic
(possibly after changing the indexing category by an equivalence).
-/
@[simps functor_obj]
def equivalence_of_reindexing {K : Type v} [small_category K] {G : K ⥤ C}
(e : K ≌ J) (α : e.functor ⋙ F ≅ G) : cocone F ≌ cocone G :=
(whiskering_equivalence e).trans (precompose_equivalence α.symm)
section
variable (F)
/-- Forget the cocone structure and obtain just the cocone point. -/
@[simps]
def forget : cocone F ⥤ C :=
{ obj := λ t, t.X, map := λ s t f, f.hom }
variables {D : Type u'} [category.{v} D] (G : C ⥤ D)
/-- A functor `G : C ⥤ D` sends cocones over `F` to cocones over `F ⋙ G` functorially. -/
@[simps] def functoriality : cocone F ⥤ cocone (F ⋙ G) :=
{ obj := λ A,
{ X := G.obj A.X,
ι := { app := λ j, G.map (A.ι.app j), naturality' := by intros; erw ←G.map_comp; tidy } },
map := λ _ _ f,
{ hom := G.map f.hom,
w' := by intros; rw [←functor.map_comp, cocone_morphism.w] } }
instance functoriality_full [full G] [faithful G] : full (functoriality F G) :=
{ preimage := λ X Y t,
{ hom := G.preimage t.hom,
w' := λ j, G.map_injective (by simpa using t.w j) } }
instance functoriality_faithful [faithful G] : faithful (functoriality F G) :=
{ map_injective' := λ X Y f g e, by { ext1, injection e, apply G.map_injective h_1 } }
/--
If `e : C ≌ D` is an equivalence of categories, then `functoriality F e.functor` induces an
equivalence between cocones over `F` and cocones over `F ⋙ e.functor`.
-/
@[simps]
def functoriality_equivalence (e : C ≌ D) : cocone F ≌ cocone (F ⋙ e.functor) :=
let f : (F ⋙ e.functor) ⋙ e.inverse ≅ F :=
functor.associator _ _ _ ≪≫ iso_whisker_left _ (e.unit_iso).symm ≪≫ functor.right_unitor _ in
{ functor := functoriality F e.functor,
inverse := (functoriality (F ⋙ e.functor) e.inverse) ⋙
(precompose_equivalence f.symm).functor,
unit_iso := nat_iso.of_components (λ c, cocones.ext (e.unit_iso.app _) (by tidy)) (by tidy),
counit_iso := nat_iso.of_components (λ c, cocones.ext (e.counit_iso.app _)
begin
-- Unfortunately this doesn't work by `tidy`.
-- In this configuration `simp` reaches a dead-end and needs help.
intros j,
dsimp,
simp only [←equivalence.counit_inv_app_functor, iso.inv_hom_id_app, map_comp,
equivalence.fun_inv_map, assoc, id_comp, iso.inv_hom_id_app_assoc],
dsimp, simp, -- See note [dsimp, simp].
end)
(λ c c' f, by { ext, dsimp, simp, dsimp, simp, }), }
/--
If `F` reflects isomorphisms, then `cocones.functoriality F` reflects isomorphisms
as well.
-/
instance reflects_cocone_isomorphism (F : C ⥤ D) [reflects_isomorphisms F] (K : J ⥤ C) :
reflects_isomorphisms (cocones.functoriality K F) :=
begin
constructor,
introsI,
haveI : is_iso (F.map f.hom) :=
(cocones.forget (K ⋙ F)).map_is_iso ((cocones.functoriality K F).map f),
haveI := reflects_isomorphisms.reflects F f.hom,
apply cocone_iso_of_hom_iso
end
end
end cocones
end limits
namespace functor
variables {D : Type u'} [category.{v} D]
variables {F : J ⥤ C} {G : J ⥤ C} (H : C ⥤ D)
open category_theory.limits
/-- The image of a cone in C under a functor G : C ⥤ D is a cone in D. -/
@[simps]
def map_cone (c : cone F) : cone (F ⋙ H) := (cones.functoriality F H).obj c
/-- The image of a cocone in C under a functor G : C ⥤ D is a cocone in D. -/
@[simps]
def map_cocone (c : cocone F) : cocone (F ⋙ H) := (cocones.functoriality F H).obj c
/-- Given a cone morphism `c ⟶ c'`, construct a cone morphism on the mapped cones functorially. -/
def map_cone_morphism {c c' : cone F} (f : c ⟶ c') :
H.map_cone c ⟶ H.map_cone c' := (cones.functoriality F H).map f
/-- Given a cocone morphism `c ⟶ c'`, construct a cocone morphism on the mapped cocones
functorially. -/
def map_cocone_morphism {c c' : cocone F} (f : c ⟶ c') :
H.map_cocone c ⟶ H.map_cocone c' := (cocones.functoriality F H).map f
/-- If `H` is an equivalence, we invert `H.map_cone` and get a cone for `F` from a cone
for `F ⋙ H`.-/
def map_cone_inv [is_equivalence H]
(c : cone (F ⋙ H)) : cone F :=
(limits.cones.functoriality_equivalence F (as_equivalence H)).inverse.obj c
/-- `map_cone` is the left inverse to `map_cone_inv`. -/
def map_cone_map_cone_inv {F : J ⥤ D} (H : D ⥤ C) [is_equivalence H] (c : cone (F ⋙ H)) :
map_cone H (map_cone_inv H c) ≅ c :=
(limits.cones.functoriality_equivalence F (as_equivalence H)).counit_iso.app c
/-- `map_cone` is the right inverse to `map_cone_inv`. -/
def map_cone_inv_map_cone {F : J ⥤ D} (H : D ⥤ C) [is_equivalence H] (c : cone F) :
map_cone_inv H (map_cone H c) ≅ c :=
(limits.cones.functoriality_equivalence F (as_equivalence H)).unit_iso.symm.app c
/-- If `H` is an equivalence, we invert `H.map_cone` and get a cone for `F` from a cone
for `F ⋙ H`.-/
def map_cocone_inv [is_equivalence H]
(c : cocone (F ⋙ H)) : cocone F :=
(limits.cocones.functoriality_equivalence F (as_equivalence H)).inverse.obj c
/-- `map_cocone` is the left inverse to `map_cocone_inv`. -/
def map_cocone_map_cocone_inv {F : J ⥤ D} (H : D ⥤ C) [is_equivalence H] (c : cocone (F ⋙ H)) :
map_cocone H (map_cocone_inv H c) ≅ c :=
(limits.cocones.functoriality_equivalence F (as_equivalence H)).counit_iso.app c
/-- `map_cocone` is the right inverse to `map_cocone_inv`. -/
def map_cocone_inv_map_cocone {F : J ⥤ D} (H : D ⥤ C) [is_equivalence H] (c : cocone F) :
map_cocone_inv H (map_cocone H c) ≅ c :=
(limits.cocones.functoriality_equivalence F (as_equivalence H)).unit_iso.symm.app c
/-- `functoriality F _ ⋙ postcompose (whisker_left F _)` simplifies to `functoriality F _`. -/
@[simps]
def functoriality_comp_postcompose {H H' : C ⥤ D} (α : H ≅ H') :
cones.functoriality F H ⋙ cones.postcompose (whisker_left F α.hom) ≅ cones.functoriality F H' :=
nat_iso.of_components (λ c, cones.ext (α.app _) (by tidy)) (by tidy)
/--
For `F : J ⥤ C`, given a cone `c : cone F`, and a natural isomorphism `α : H ≅ H'` for functors
`H H' : C ⥤ D`, the postcomposition of the cone `H.map_cone` using the isomorphism `α` is
isomorphic to the cone `H'.map_cone`.
-/
@[simps]
def postcompose_whisker_left_map_cone {H H' : C ⥤ D} (α : H ≅ H') (c : cone F) :
(cones.postcompose (whisker_left F α.hom : _)).obj (H.map_cone c) ≅ H'.map_cone c :=
(functoriality_comp_postcompose α).app c
/--
`map_cone` commutes with `postcompose`. In particular, for `F : J ⥤ C`, given a cone `c : cone F`, a
natural transformation `α : F ⟶ G` and a functor `H : C ⥤ D`, we have two obvious ways of producing
a cone over `G ⋙ H`, and they are both isomorphic.
-/
@[simps]
def map_cone_postcompose {α : F ⟶ G} {c} :
H.map_cone ((cones.postcompose α).obj c) ≅
(cones.postcompose (whisker_right α H : _)).obj (H.map_cone c) :=
cones.ext (iso.refl _) (by tidy)
/--
`map_cone` commutes with `postcompose_equivalence`
-/
@[simps]
def map_cone_postcompose_equivalence_functor {α : F ≅ G} {c} :
H.map_cone ((cones.postcompose_equivalence α).functor.obj c) ≅
(cones.postcompose_equivalence (iso_whisker_right α H : _)).functor.obj (H.map_cone c) :=
cones.ext (iso.refl _) (by tidy)
/-- `functoriality F _ ⋙ precompose (whisker_left F _)` simplifies to `functoriality F _`. -/
@[simps]
def functoriality_comp_precompose {H H' : C ⥤ D} (α : H ≅ H') :
cocones.functoriality F H ⋙ cocones.precompose (whisker_left F α.inv)
≅ cocones.functoriality F H' :=
nat_iso.of_components (λ c, cocones.ext (α.app _) (by tidy)) (by tidy)
/--
For `F : J ⥤ C`, given a cocone `c : cocone F`, and a natural isomorphism `α : H ≅ H'` for functors
`H H' : C ⥤ D`, the precomposition of the cocone `H.map_cocone` using the isomorphism `α` is
isomorphic to the cocone `H'.map_cocone`.
-/
@[simps]
def precompose_whisker_left_map_cocone {H H' : C ⥤ D} (α : H ≅ H') (c : cocone F) :
(cocones.precompose (whisker_left F α.inv : _)).obj (H.map_cocone c) ≅ H'.map_cocone c :=
(functoriality_comp_precompose α).app c
/--
`map_cocone` commutes with `precompose`. In particular, for `F : J ⥤ C`, given a cocone
`c : cocone F`, a natural transformation `α : F ⟶ G` and a functor `H : C ⥤ D`, we have two obvious
ways of producing a cocone over `G ⋙ H`, and they are both isomorphic.
-/
@[simps]
def map_cocone_precompose {α : F ⟶ G} {c} :
H.map_cocone ((cocones.precompose α).obj c) ≅
(cocones.precompose (whisker_right α H : _)).obj (H.map_cocone c) :=
cocones.ext (iso.refl _) (by tidy)
/--
`map_cocone` commutes with `precompose_equivalence`
-/
@[simps]
def map_cocone_precompose_equivalence_functor {α : F ≅ G} {c} :
H.map_cocone ((cocones.precompose_equivalence α).functor.obj c) ≅
(cocones.precompose_equivalence (iso_whisker_right α H : _)).functor.obj (H.map_cocone c) :=
cocones.ext (iso.refl _) (by tidy)
variables {K : Type v} [small_category K]
/--
`map_cone` commutes with `whisker`
-/
@[simps]
def map_cone_whisker {E : K ⥤ J} {c : cone F} :
H.map_cone (c.whisker E) ≅ (H.map_cone c).whisker E :=
cones.ext (iso.refl _) (by tidy)
/--
`map_cocone` commutes with `whisker`
-/
@[simps]
def map_cocone_whisker {E : K ⥤ J} {c : cocone F} :
H.map_cocone (c.whisker E) ≅ (H.map_cocone c).whisker E :=
cocones.ext (iso.refl _) (by tidy)
end functor
end category_theory
namespace category_theory.limits
section
variables {F : J ⥤ C}
/-- Change a `cocone F` into a `cone F.op`. -/
@[simps] def cocone.op (c : cocone F) : cone F.op :=
{ X := op c.X,
π :=
{ app := λ j, (c.ι.app (unop j)).op,
naturality' := λ j j' f, has_hom.hom.unop_inj (by tidy) } }
/-- Change a `cone F` into a `cocone F.op`. -/
@[simps] def cone.op (c : cone F) : cocone F.op :=
{ X := op c.X,
ι :=
{ app := λ j, (c.π.app (unop j)).op,
naturality' := λ j j' f, has_hom.hom.unop_inj (by tidy) } }
/-- Change a `cocone F.op` into a `cone F`. -/
@[simps] def cocone.unop (c : cocone F.op) : cone F :=
{ X := unop c.X,
π :=
{ app := λ j, (c.ι.app (op j)).unop,
naturality' := λ j j' f, has_hom.hom.op_inj
begin dsimp, simp only [comp_id], exact (c.w f.op).symm, end } }
/-- Change a `cone F.op` into a `cocone F`. -/
@[simps] def cone.unop (c : cone F.op) : cocone F :=
{ X := unop c.X,
ι :=
{ app := λ j, (c.π.app (op j)).unop,
naturality' := λ j j' f, has_hom.hom.op_inj
begin dsimp, simp only [id_comp], exact (c.w f.op), end } }
variables (F)
/--
The category of cocones on `F`
is equivalent to the opposite category of
the category of cones on the opposite of `F`.
-/
@[simps]
def cocone_equivalence_op_cone_op : cocone F ≌ (cone F.op)ᵒᵖ :=
{ functor :=
{ obj := λ c, op (cocone.op c),
map := λ X Y f, has_hom.hom.op
{ hom := f.hom.op,
w' := λ j, by { apply has_hom.hom.unop_inj, dsimp, simp, }, } },
inverse :=
{ obj := λ c, cone.unop (unop c),
map := λ X Y f,
{ hom := f.unop.hom.unop,
w' := λ j, by { apply has_hom.hom.op_inj, dsimp, simp, }, } },
unit_iso := nat_iso.of_components (λ c, cocones.ext (iso.refl _) (by tidy)) (by tidy),
counit_iso := nat_iso.of_components (λ c,
by { op_induction c, dsimp, apply iso.op, exact cones.ext (iso.refl _) (by tidy), })
begin
intros,
have hX : X = op (unop X) := rfl,
revert hX,
generalize : unop X = X',
rintro rfl,
have hY : Y = op (unop Y) := rfl,
revert hY,
generalize : unop Y = Y',
rintro rfl,
apply has_hom.hom.unop_inj,
apply cone_morphism.ext,
dsimp, simp,
end,
functor_unit_iso_comp' := λ c, begin apply has_hom.hom.unop_inj, ext, dsimp, simp, end }
end
section
variables {F : J ⥤ Cᵒᵖ}
/-- Change a cocone on `F.left_op : Jᵒᵖ ⥤ C` to a cocone on `F : J ⥤ Cᵒᵖ`. -/
-- Here and below we only automatically generate the `@[simp]` lemma for the `X` field,
-- as we can write a simpler `rfl` lemma for the components of the natural transformation by hand.
@[simps {rhs_md := semireducible, simp_rhs := tt}]
def cone_of_cocone_left_op (c : cocone F.left_op) : cone F :=
{ X := op c.X,
π := nat_trans.remove_left_op (c.ι ≫ (const.op_obj_unop (op c.X)).hom) }
/-- Change a cone on `F : J ⥤ Cᵒᵖ` to a cocone on `F.left_op : Jᵒᵖ ⥤ C`. -/
@[simps {rhs_md := semireducible, simp_rhs := tt}]
def cocone_left_op_of_cone (c : cone F) : cocone (F.left_op) :=
{ X := unop c.X,
ι := nat_trans.left_op c.π }
/-- Change a cone on `F.left_op : Jᵒᵖ ⥤ C` to a cocone on `F : J ⥤ Cᵒᵖ`. -/
/- When trying use `@[simps]` to generate the `ι_app` field of this definition, `@[simps]` tries to
reduce the RHS using `expr.dsimp` and `expr.simp`, but for some reason the expression is not
being simplified properly. -/
@[simps X]
def cocone_of_cone_left_op (c : cone F.left_op) : cocone F :=
{ X := op c.X,
ι := nat_trans.remove_left_op ((const.op_obj_unop (op c.X)).hom ≫ c.π) }
@[simp] lemma cocone_of_cone_left_op_ι_app (c : cone F.left_op) (j) :
(cocone_of_cone_left_op c).ι.app j = (c.π.app (op j)).op :=
by { dsimp [cocone_of_cone_left_op], simp }
/-- Change a cocone on `F : J ⥤ Cᵒᵖ` to a cone on `F.left_op : Jᵒᵖ ⥤ C`. -/
@[simps {rhs_md := semireducible, simp_rhs := tt}]
def cone_left_op_of_cocone (c : cocone F) : cone (F.left_op) :=
{ X := unop c.X,
π := nat_trans.left_op c.ι }
end
end category_theory.limits
namespace category_theory.functor
open category_theory.limits
variables {F : J ⥤ C}
variables {D : Type u'} [category.{v} D]
section
variables (G : C ⥤ D)
/-- The opposite cocone of the image of a cone is the image of the opposite cocone. -/
def map_cone_op (t : cone F) : (G.map_cone t).op ≅ (G.op.map_cocone t.op) :=
cocones.ext (iso.refl _) (by tidy)
/-- The opposite cone of the image of a cocone is the image of the opposite cone. -/
def map_cocone_op {t : cocone F} : (G.map_cocone t).op ≅ (G.op.map_cone t.op) :=
cones.ext (iso.refl _) (by tidy)
end
end category_theory.functor
|
9766adcf0fc34fba605af2de091bc525735cd181 | 947b78d97130d56365ae2ec264df196ce769371a | /tests/lean/private.lean | f12a0f88dfb2f44fcdbb12bab6f1a28a12a33fcd | [
"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 | 990 | lean | new_frontend
-- Issue 1
def foo := 10
def f (x : Nat) := x + x
namespace Bla
private def foo := "hello"
#check foo == "world" -- `foo` resolves to private `Bla.foo`
private def foo : Float := 1.0 -- should produce error like in other programming languages
end Bla
#check foo == 0
#check Bla.foo
-- Issue 2
namespace Boo
def boo := 100
namespace Bla
private def boo := "hello"
#check boo == "world" -- resolving to `Boo.Bla.boo` as expected
#check boo ++ "world" -- should work
end Bla
#check Bla.boo == "world"
#check boo == 100
end Boo
#check Boo.Bla.boo == "world"
#check Boo.boo == 100
/-
Should the following work?
```
namespace N
private def b := 10
end N
open N
#check b
```
-/
-- Issue 3
private def Nat.mul10 (x : Nat) := x * 10
def x := 10
#check x.mul10 -- dot-notation should work with local private declarations
-- Issue 4
def y := 10
private def y := "hello" -- produce error
private def z := 10
def z := "hello" -- produce error
|
25aab0336098ecaa037db7dab24490106f438ecc | d9d511f37a523cd7659d6f573f990e2a0af93c6f | /src/analysis/analytic/basic.lean | 7b3523addd45799b8bda5bf085bdef4a38d9f9f1 | [
"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 | 50,569 | 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, Yury Kudryashov
-/
import analysis.calculus.formal_multilinear_series
import data.equiv.fin
/-!
# Analytic functions
A function is analytic in one dimension around `0` if it can be written as a converging power series
`Σ pₙ zⁿ`. This definition can be extended to any dimension (even in infinite dimension) by
requiring that `pₙ` is a continuous `n`-multilinear map. In general, `pₙ` is not unique (in two
dimensions, taking `p₂ (x, y) (x', y') = x y'` or `y x'` gives the same map when applied to a
vector `(x, y) (x, y)`). A way to guarantee uniqueness is to take a symmetric `pₙ`, but this is not
always possible in nonzero characteristic (in characteristic 2, the previous example has no
symmetric representative). Therefore, we do not insist on symmetry or uniqueness in the definition,
and we only require the existence of a converging series.
The general framework is important to say that the exponential map on bounded operators on a Banach
space is analytic, as well as the inverse on invertible operators.
## Main definitions
Let `p` be a formal multilinear series from `E` to `F`, i.e., `p n` is a multilinear map on `E^n`
for `n : ℕ`.
* `p.radius`: the largest `r : ℝ≥0∞` such that `∥p n∥ * r^n` grows subexponentially, defined as
a liminf.
* `p.le_radius_of_bound`, `p.le_radius_of_bound_nnreal`, `p.le_radius_of_is_O`: if `∥p n∥ * r ^ n`
is bounded above, then `r ≤ p.radius`;
* `p.is_o_of_lt_radius`, `p.norm_mul_pow_le_mul_pow_of_lt_radius`, `p.is_o_one_of_lt_radius`,
`p.norm_mul_pow_le_of_lt_radius`, `p.nnnorm_mul_pow_le_of_lt_radius`: if `r < p.radius`, then
`∥p n∥ * r ^ n` tends to zero exponentially;
* `p.lt_radius_of_is_O`: if `r ≠ 0` and `∥p n∥ * r ^ n = O(a ^ n)` for some `-1 < a < 1`, then
`r < p.radius`;
* `p.partial_sum n x`: the sum `∑_{i = 0}^{n-1} pᵢ xⁱ`.
* `p.sum x`: the sum `∑'_{i = 0}^{∞} pᵢ xⁱ`.
Additionally, let `f` be a function from `E` to `F`.
* `has_fpower_series_on_ball f p x r`: on the ball of center `x` with radius `r`,
`f (x + y) = ∑'_n pₙ yⁿ`.
* `has_fpower_series_at f p x`: on some ball of center `x` with positive radius, holds
`has_fpower_series_on_ball f p x r`.
* `analytic_at 𝕜 f x`: there exists a power series `p` such that holds
`has_fpower_series_at f p x`.
We develop the basic properties of these notions, notably:
* If a function admits a power series, it is continuous (see
`has_fpower_series_on_ball.continuous_on` and `has_fpower_series_at.continuous_at` and
`analytic_at.continuous_at`).
* In a complete space, the sum of a formal power series with positive radius is well defined on the
disk of convergence, see `formal_multilinear_series.has_fpower_series_on_ball`.
* If a function admits a power series in a ball, then it is analytic at any point `y` of this ball,
and the power series there can be expressed in terms of the initial power series `p` as
`p.change_origin y`. See `has_fpower_series_on_ball.change_origin`. It follows in particular that
the set of points at which a given function is analytic is open, see `is_open_analytic_at`.
## Implementation details
We only introduce the radius of convergence of a power series, as `p.radius`.
For a power series in finitely many dimensions, there is a finer (directional, coordinate-dependent)
notion, describing the polydisk of convergence. This notion is more specific, and not necessary to
build the general theory. We do not define it here.
-/
noncomputable theory
variables {𝕜 : Type*} [nondiscrete_normed_field 𝕜]
{E : Type*} [normed_group E] [normed_space 𝕜 E]
{F : Type*} [normed_group F] [normed_space 𝕜 F]
{G : Type*} [normed_group G] [normed_space 𝕜 G]
open_locale topological_space classical big_operators nnreal filter ennreal
open set filter asymptotics
/-! ### The radius of a formal multilinear series -/
namespace formal_multilinear_series
variables (p : formal_multilinear_series 𝕜 E F) {r : ℝ≥0}
/-- The radius of a formal multilinear series is the largest `r` such that the sum `Σ ∥pₙ∥ ∥y∥ⁿ`
converges for all `∥y∥ < r`. This implies that `Σ pₙ yⁿ` converges for all `∥y∥ < r`, but these
definitions are *not* equivalent in general. -/
def radius (p : formal_multilinear_series 𝕜 E F) : ℝ≥0∞ :=
⨆ (r : ℝ≥0) (C : ℝ) (hr : ∀ n, ∥p n∥ * r ^ n ≤ C), (r : ℝ≥0∞)
/-- If `∥pₙ∥ rⁿ` is bounded in `n`, then the radius of `p` is at least `r`. -/
lemma le_radius_of_bound (C : ℝ) {r : ℝ≥0} (h : ∀ (n : ℕ), ∥p n∥ * r^n ≤ C) :
(r : ℝ≥0∞) ≤ p.radius :=
le_supr_of_le r $ le_supr_of_le C $ (le_supr (λ _, (r : ℝ≥0∞)) h)
/-- If `∥pₙ∥ rⁿ` is bounded in `n`, then the radius of `p` is at least `r`. -/
lemma le_radius_of_bound_nnreal (C : ℝ≥0) {r : ℝ≥0} (h : ∀ (n : ℕ), ∥p n∥₊ * r^n ≤ C) :
(r : ℝ≥0∞) ≤ p.radius :=
p.le_radius_of_bound C $ λ n, by exact_mod_cast (h n)
/-- If `∥pₙ∥ rⁿ = O(1)`, as `n → ∞`, then the radius of `p` is at least `r`. -/
lemma le_radius_of_is_O (h : is_O (λ n, ∥p n∥ * r^n) (λ n, (1 : ℝ)) at_top) : ↑r ≤ p.radius :=
exists.elim (is_O_one_nat_at_top_iff.1 h) $ λ C hC, p.le_radius_of_bound C $
λ n, (le_abs_self _).trans (hC n)
lemma le_radius_of_eventually_le (C) (h : ∀ᶠ n in at_top, ∥p n∥ * r ^ n ≤ C) : ↑r ≤ p.radius :=
p.le_radius_of_is_O $ is_O.of_bound C $ h.mono $ λ n hn, by simpa
lemma le_radius_of_summable_nnnorm (h : summable (λ n, ∥p n∥₊ * r ^ n)) : ↑r ≤ p.radius :=
p.le_radius_of_bound_nnreal (∑' n, ∥p n∥₊ * r ^ n) $ λ n, le_tsum' h _
lemma le_radius_of_summable (h : summable (λ n, ∥p n∥ * r ^ n)) : ↑r ≤ p.radius :=
p.le_radius_of_summable_nnnorm $ by { simp only [← coe_nnnorm] at h, exact_mod_cast h }
lemma radius_eq_top_of_forall_nnreal_is_O
(h : ∀ r : ℝ≥0, is_O (λ n, ∥p n∥ * r^n) (λ n, (1 : ℝ)) at_top) : p.radius = ∞ :=
ennreal.eq_top_of_forall_nnreal_le $ λ r, p.le_radius_of_is_O (h r)
lemma radius_eq_top_of_eventually_eq_zero (h : ∀ᶠ n in at_top, p n = 0) : p.radius = ∞ :=
p.radius_eq_top_of_forall_nnreal_is_O $
λ r, (is_O_zero _ _).congr' (h.mono $ λ n hn, by simp [hn]) eventually_eq.rfl
lemma radius_eq_top_of_forall_image_add_eq_zero (n : ℕ) (hn : ∀ m, p (m + n) = 0) : p.radius = ∞ :=
p.radius_eq_top_of_eventually_eq_zero $ mem_at_top_sets.2 ⟨n, λ k hk, nat.sub_add_cancel hk ▸ hn _⟩
/-- For `r` strictly smaller than the radius of `p`, then `∥pₙ∥ rⁿ` tends to zero exponentially:
for some `0 < a < 1`, `∥p n∥ rⁿ = o(aⁿ)`. -/
lemma is_o_of_lt_radius (h : ↑r < p.radius) :
∃ a ∈ Ioo (0 : ℝ) 1, is_o (λ n, ∥p n∥ * r ^ n) (pow a) at_top :=
begin
rw (tfae_exists_lt_is_o_pow (λ n, ∥p n∥ * r ^ n) 1).out 1 4,
simp only [radius, lt_supr_iff] at h,
rcases h with ⟨t, C, hC, rt⟩,
rw [ennreal.coe_lt_coe, ← nnreal.coe_lt_coe] at rt,
have : 0 < (t : ℝ), from r.coe_nonneg.trans_lt rt,
rw [← div_lt_one this] at rt,
refine ⟨_, rt, C, or.inr zero_lt_one, λ n, _⟩,
calc abs (∥p n∥ * r ^ n) = (∥p n∥ * t ^ n) * (r / t) ^ n :
by field_simp [mul_right_comm, abs_mul, this.ne']
... ≤ C * (r / t) ^ n : mul_le_mul_of_nonneg_right (hC n) (pow_nonneg (div_nonneg r.2 t.2) _)
end
/-- For `r` strictly smaller than the radius of `p`, then `∥pₙ∥ rⁿ = o(1)`. -/
lemma is_o_one_of_lt_radius (h : ↑r < p.radius) :
is_o (λ n, ∥p n∥ * r ^ n) (λ _, 1 : ℕ → ℝ) at_top :=
let ⟨a, ha, hp⟩ := p.is_o_of_lt_radius h in
hp.trans $ (is_o_pow_pow_of_lt_left ha.1.le ha.2).congr (λ n, rfl) one_pow
/-- For `r` strictly smaller than the radius of `p`, then `∥pₙ∥ rⁿ` tends to zero exponentially:
for some `0 < a < 1` and `C > 0`, `∥p n∥ * r ^ n ≤ C * a ^ n`. -/
lemma norm_mul_pow_le_mul_pow_of_lt_radius (h : ↑r < p.radius) :
∃ (a ∈ Ioo (0 : ℝ) 1) (C > 0), ∀ n, ∥p n∥ * r^n ≤ C * a^n :=
begin
rcases ((tfae_exists_lt_is_o_pow (λ n, ∥p n∥ * r ^ n) 1).out 1 5).mp (p.is_o_of_lt_radius h)
with ⟨a, ha, C, hC, H⟩,
exact ⟨a, ha, C, hC, λ n, (le_abs_self _).trans (H n)⟩
end
/-- If `r ≠ 0` and `∥pₙ∥ rⁿ = O(aⁿ)` for some `-1 < a < 1`, then `r < p.radius`. -/
lemma lt_radius_of_is_O (h₀ : r ≠ 0) {a : ℝ} (ha : a ∈ Ioo (-1 : ℝ) 1)
(hp : is_O (λ n, ∥p n∥ * r ^ n) (pow a) at_top) :
↑r < p.radius :=
begin
rcases ((tfae_exists_lt_is_o_pow (λ n, ∥p n∥ * r ^ n) 1).out 2 5).mp ⟨a, ha, hp⟩
with ⟨a, ha, C, hC, hp⟩,
rw [← pos_iff_ne_zero, ← nnreal.coe_pos] at h₀,
lift a to ℝ≥0 using ha.1.le,
have : (r : ℝ) < r / a :=
by simpa only [div_one] using (div_lt_div_left h₀ zero_lt_one ha.1).2 ha.2,
norm_cast at this,
rw [← ennreal.coe_lt_coe] at this,
refine this.trans_le (p.le_radius_of_bound C $ λ n, _),
rw [nnreal.coe_div, div_pow, ← mul_div_assoc, div_le_iff (pow_pos ha.1 n)],
exact (le_abs_self _).trans (hp n)
end
/-- For `r` strictly smaller than the radius of `p`, then `∥pₙ∥ rⁿ` is bounded. -/
lemma norm_mul_pow_le_of_lt_radius (p : formal_multilinear_series 𝕜 E F) {r : ℝ≥0}
(h : (r : ℝ≥0∞) < p.radius) : ∃ C > 0, ∀ n, ∥p n∥ * r^n ≤ C :=
let ⟨a, ha, C, hC, h⟩ := p.norm_mul_pow_le_mul_pow_of_lt_radius h
in ⟨C, hC, λ n, (h n).trans $ mul_le_of_le_one_right hC.lt.le (pow_le_one _ ha.1.le ha.2.le)⟩
/-- For `r` strictly smaller than the radius of `p`, then `∥pₙ∥ rⁿ` is bounded. -/
lemma norm_le_div_pow_of_pos_of_lt_radius (p : formal_multilinear_series 𝕜 E F) {r : ℝ≥0}
(h0 : 0 < r) (h : (r : ℝ≥0∞) < p.radius) : ∃ C > 0, ∀ n, ∥p n∥ ≤ C / r ^ n :=
let ⟨C, hC, hp⟩ := p.norm_mul_pow_le_of_lt_radius h in
⟨C, hC, λ n, iff.mpr (le_div_iff (pow_pos h0 _)) (hp n)⟩
/-- For `r` strictly smaller than the radius of `p`, then `∥pₙ∥ rⁿ` is bounded. -/
lemma nnnorm_mul_pow_le_of_lt_radius (p : formal_multilinear_series 𝕜 E F) {r : ℝ≥0}
(h : (r : ℝ≥0∞) < p.radius) : ∃ C > 0, ∀ n, ∥p n∥₊ * r^n ≤ C :=
let ⟨C, hC, hp⟩ := p.norm_mul_pow_le_of_lt_radius h
in ⟨⟨C, hC.lt.le⟩, hC, by exact_mod_cast hp⟩
lemma le_radius_of_tendsto (p : formal_multilinear_series 𝕜 E F) {l : ℝ}
(h : tendsto (λ n, ∥p n∥ * r^n) at_top (𝓝 l)) : ↑r ≤ p.radius :=
p.le_radius_of_is_O (is_O_one_of_tendsto _ h)
lemma le_radius_of_summable_norm (p : formal_multilinear_series 𝕜 E F)
(hs : summable (λ n, ∥p n∥ * r^n)) : ↑r ≤ p.radius :=
p.le_radius_of_tendsto hs.tendsto_at_top_zero
lemma not_summable_norm_of_radius_lt_nnnorm (p : formal_multilinear_series 𝕜 E F) {x : E}
(h : p.radius < ∥x∥₊) : ¬ summable (λ n, ∥p n∥ * ∥x∥^n) :=
λ hs, not_le_of_lt h (p.le_radius_of_summable_norm hs)
lemma summable_norm_mul_pow (p : formal_multilinear_series 𝕜 E F)
{r : ℝ≥0} (h : ↑r < p.radius) :
summable (λ n : ℕ, ∥p n∥ * r ^ n) :=
begin
obtain ⟨a, ha : a ∈ Ioo (0 : ℝ) 1, C, hC : 0 < C, hp⟩ := p.norm_mul_pow_le_mul_pow_of_lt_radius h,
exact summable_of_nonneg_of_le (λ n, mul_nonneg (norm_nonneg _) (pow_nonneg r.coe_nonneg _)) hp
((summable_geometric_of_lt_1 ha.1.le ha.2).mul_left _),
end
lemma summable_norm_apply (p : formal_multilinear_series 𝕜 E F)
{x : E} (hx : x ∈ emetric.ball (0 : E) p.radius) :
summable (λ n : ℕ, ∥p n (λ _, x)∥) :=
begin
rw mem_emetric_ball_0_iff at hx,
refine summable_of_nonneg_of_le (λ _, norm_nonneg _) (λ n, ((p n).le_op_norm _).trans_eq _)
(p.summable_norm_mul_pow hx),
simp
end
lemma summable_nnnorm_mul_pow (p : formal_multilinear_series 𝕜 E F)
{r : ℝ≥0} (h : ↑r < p.radius) :
summable (λ n : ℕ, ∥p n∥₊ * r ^ n) :=
by { rw ← nnreal.summable_coe, push_cast, exact p.summable_norm_mul_pow h }
protected lemma summable [complete_space F]
(p : formal_multilinear_series 𝕜 E F) {x : E} (hx : x ∈ emetric.ball (0 : E) p.radius) :
summable (λ n : ℕ, p n (λ _, x)) :=
summable_of_summable_norm (p.summable_norm_apply hx)
lemma radius_eq_top_of_summable_norm (p : formal_multilinear_series 𝕜 E F)
(hs : ∀ r : ℝ≥0, summable (λ n, ∥p n∥ * r^n)) : p.radius = ∞ :=
ennreal.eq_top_of_forall_nnreal_le (λ r, p.le_radius_of_summable_norm (hs r))
lemma radius_eq_top_iff_summable_norm (p : formal_multilinear_series 𝕜 E F) :
p.radius = ∞ ↔ ∀ r : ℝ≥0, summable (λ n, ∥p n∥ * r^n) :=
begin
split,
{ intros h r,
obtain ⟨a, ha : a ∈ Ioo (0 : ℝ) 1, C, hC : 0 < C, hp⟩ :=
p.norm_mul_pow_le_mul_pow_of_lt_radius
(show (r:ℝ≥0∞) < p.radius, from h.symm ▸ ennreal.coe_lt_top),
refine (summable_of_norm_bounded (λ n, (C : ℝ) * a ^ n)
((summable_geometric_of_lt_1 ha.1.le ha.2).mul_left _) (λ n, _)),
specialize hp n,
rwa real.norm_of_nonneg (mul_nonneg (norm_nonneg _) (pow_nonneg r.coe_nonneg n)) },
{ exact p.radius_eq_top_of_summable_norm }
end
/-- If the radius of `p` is positive, then `∥pₙ∥` grows at most geometrically. -/
lemma le_mul_pow_of_radius_pos (p : formal_multilinear_series 𝕜 E F) (h : 0 < p.radius) :
∃ C r (hC : 0 < C) (hr : 0 < r), ∀ n, ∥p n∥ ≤ C * r ^ n :=
begin
rcases ennreal.lt_iff_exists_nnreal_btwn.1 h with ⟨r, r0, rlt⟩,
have rpos : 0 < (r : ℝ), by simp [ennreal.coe_pos.1 r0],
rcases norm_le_div_pow_of_pos_of_lt_radius p rpos rlt with ⟨C, Cpos, hCp⟩,
refine ⟨C, r ⁻¹, Cpos, by simp [rpos], λ n, _⟩,
convert hCp n,
exact inv_pow' _ _,
end
/-- The radius of the sum of two formal series is at least the minimum of their two radii. -/
lemma min_radius_le_radius_add (p q : formal_multilinear_series 𝕜 E F) :
min p.radius q.radius ≤ (p + q).radius :=
begin
refine ennreal.le_of_forall_nnreal_lt (λ r hr, _),
rw lt_min_iff at hr,
have := ((p.is_o_one_of_lt_radius hr.1).add (q.is_o_one_of_lt_radius hr.2)).is_O,
refine (p + q).le_radius_of_is_O ((is_O_of_le _ $ λ n, _).trans this),
rw [← add_mul, normed_field.norm_mul, normed_field.norm_mul, norm_norm],
exact mul_le_mul_of_nonneg_right ((norm_add_le _ _).trans (le_abs_self _)) (norm_nonneg _)
end
@[simp] lemma radius_neg (p : formal_multilinear_series 𝕜 E F) : (-p).radius = p.radius :=
by simp [radius]
/-- Given a formal multilinear series `p` and a vector `x`, then `p.sum x` is the sum `Σ pₙ xⁿ`. A
priori, it only behaves well when `∥x∥ < p.radius`. -/
protected def sum (p : formal_multilinear_series 𝕜 E F) (x : E) : F := ∑' n : ℕ , p n (λ i, x)
protected lemma has_sum [complete_space F]
(p : formal_multilinear_series 𝕜 E F) {x : E} (hx : x ∈ emetric.ball (0 : E) p.radius) :
has_sum (λ n : ℕ, p n (λ _, x)) (p.sum x) :=
(p.summable hx).has_sum
/-- Given a formal multilinear series `p` and a vector `x`, then `p.partial_sum n x` is the sum
`Σ pₖ xᵏ` for `k ∈ {0,..., n-1}`. -/
def partial_sum (p : formal_multilinear_series 𝕜 E F) (n : ℕ) (x : E) : F :=
∑ k in finset.range n, p k (λ(i : fin k), x)
/-- The partial sums of a formal multilinear series are continuous. -/
lemma partial_sum_continuous (p : formal_multilinear_series 𝕜 E F) (n : ℕ) :
continuous (p.partial_sum n) :=
by continuity
end formal_multilinear_series
/-! ### Expanding a function as a power series -/
section
variables {f g : E → F} {p pf pg : formal_multilinear_series 𝕜 E F} {x : E} {r r' : ℝ≥0∞}
/-- Given a function `f : E → F` and a formal multilinear series `p`, we say that `f` has `p` as
a power series on the ball of radius `r > 0` around `x` if `f (x + y) = ∑' pₙ yⁿ` for all `∥y∥ < r`.
-/
structure has_fpower_series_on_ball
(f : E → F) (p : formal_multilinear_series 𝕜 E F) (x : E) (r : ℝ≥0∞) : Prop :=
(r_le : r ≤ p.radius)
(r_pos : 0 < r)
(has_sum : ∀ {y}, y ∈ emetric.ball (0 : E) r → has_sum (λn:ℕ, p n (λ(i : fin n), y)) (f (x + y)))
/-- Given a function `f : E → F` and a formal multilinear series `p`, we say that `f` has `p` as
a power series around `x` if `f (x + y) = ∑' pₙ yⁿ` for all `y` in a neighborhood of `0`. -/
def has_fpower_series_at (f : E → F) (p : formal_multilinear_series 𝕜 E F) (x : E) :=
∃ r, has_fpower_series_on_ball f p x r
variable (𝕜)
/-- Given a function `f : E → F`, we say that `f` is analytic at `x` if it admits a convergent power
series expansion around `x`. -/
def analytic_at (f : E → F) (x : E) :=
∃ (p : formal_multilinear_series 𝕜 E F), has_fpower_series_at f p x
variable {𝕜}
lemma has_fpower_series_on_ball.has_fpower_series_at (hf : has_fpower_series_on_ball f p x r) :
has_fpower_series_at f p x := ⟨r, hf⟩
lemma has_fpower_series_at.analytic_at (hf : has_fpower_series_at f p x) : analytic_at 𝕜 f x :=
⟨p, hf⟩
lemma has_fpower_series_on_ball.analytic_at (hf : has_fpower_series_on_ball f p x r) :
analytic_at 𝕜 f x :=
hf.has_fpower_series_at.analytic_at
lemma has_fpower_series_on_ball.has_sum_sub (hf : has_fpower_series_on_ball f p x r) {y : E}
(hy : y ∈ emetric.ball x r) :
has_sum (λ n : ℕ, p n (λ i, y - x)) (f y) :=
have y - x ∈ emetric.ball (0 : E) r, by simpa [edist_eq_coe_nnnorm_sub] using hy,
by simpa only [add_sub_cancel'_right] using hf.has_sum this
lemma has_fpower_series_on_ball.radius_pos (hf : has_fpower_series_on_ball f p x r) :
0 < p.radius :=
lt_of_lt_of_le hf.r_pos hf.r_le
lemma has_fpower_series_at.radius_pos (hf : has_fpower_series_at f p x) :
0 < p.radius :=
let ⟨r, hr⟩ := hf in hr.radius_pos
lemma has_fpower_series_on_ball.mono
(hf : has_fpower_series_on_ball f p x r) (r'_pos : 0 < r') (hr : r' ≤ r) :
has_fpower_series_on_ball f p x r' :=
⟨le_trans hr hf.1, r'_pos, λ y hy, hf.has_sum (emetric.ball_subset_ball hr hy)⟩
protected lemma has_fpower_series_at.eventually (hf : has_fpower_series_at f p x) :
∀ᶠ r : ℝ≥0∞ in 𝓝[Ioi 0] 0, has_fpower_series_on_ball f p x r :=
let ⟨r, hr⟩ := hf in
mem_of_superset (Ioo_mem_nhds_within_Ioi (left_mem_Ico.2 hr.r_pos)) $
λ r' hr', hr.mono hr'.1 hr'.2.le
lemma has_fpower_series_on_ball.add
(hf : has_fpower_series_on_ball f pf x r) (hg : has_fpower_series_on_ball g pg x r) :
has_fpower_series_on_ball (f + g) (pf + pg) x r :=
{ r_le := le_trans (le_min_iff.2 ⟨hf.r_le, hg.r_le⟩) (pf.min_radius_le_radius_add pg),
r_pos := hf.r_pos,
has_sum := λ y hy, (hf.has_sum hy).add (hg.has_sum hy) }
lemma has_fpower_series_at.add
(hf : has_fpower_series_at f pf x) (hg : has_fpower_series_at g pg x) :
has_fpower_series_at (f + g) (pf + pg) x :=
begin
rcases (hf.eventually.and hg.eventually).exists with ⟨r, hr⟩,
exact ⟨r, hr.1.add hr.2⟩
end
lemma analytic_at.add (hf : analytic_at 𝕜 f x) (hg : analytic_at 𝕜 g x) :
analytic_at 𝕜 (f + g) x :=
let ⟨pf, hpf⟩ := hf, ⟨qf, hqf⟩ := hg in (hpf.add hqf).analytic_at
lemma has_fpower_series_on_ball.neg (hf : has_fpower_series_on_ball f pf x r) :
has_fpower_series_on_ball (-f) (-pf) x r :=
{ r_le := by { rw pf.radius_neg, exact hf.r_le },
r_pos := hf.r_pos,
has_sum := λ y hy, (hf.has_sum hy).neg }
lemma has_fpower_series_at.neg
(hf : has_fpower_series_at f pf x) : has_fpower_series_at (-f) (-pf) x :=
let ⟨rf, hrf⟩ := hf in hrf.neg.has_fpower_series_at
lemma analytic_at.neg (hf : analytic_at 𝕜 f x) : analytic_at 𝕜 (-f) x :=
let ⟨pf, hpf⟩ := hf in hpf.neg.analytic_at
lemma has_fpower_series_on_ball.sub
(hf : has_fpower_series_on_ball f pf x r) (hg : has_fpower_series_on_ball g pg x r) :
has_fpower_series_on_ball (f - g) (pf - pg) x r :=
by simpa only [sub_eq_add_neg] using hf.add hg.neg
lemma has_fpower_series_at.sub
(hf : has_fpower_series_at f pf x) (hg : has_fpower_series_at g pg x) :
has_fpower_series_at (f - g) (pf - pg) x :=
by simpa only [sub_eq_add_neg] using hf.add hg.neg
lemma analytic_at.sub (hf : analytic_at 𝕜 f x) (hg : analytic_at 𝕜 g x) :
analytic_at 𝕜 (f - g) x :=
by simpa only [sub_eq_add_neg] using hf.add hg.neg
lemma has_fpower_series_on_ball.coeff_zero (hf : has_fpower_series_on_ball f pf x r)
(v : fin 0 → E) : pf 0 v = f x :=
begin
have v_eq : v = (λ i, 0) := subsingleton.elim _ _,
have zero_mem : (0 : E) ∈ emetric.ball (0 : E) r, by simp [hf.r_pos],
have : ∀ i ≠ 0, pf i (λ j, 0) = 0,
{ assume i hi,
have : 0 < i := pos_iff_ne_zero.2 hi,
exact continuous_multilinear_map.map_coord_zero _ (⟨0, this⟩ : fin i) rfl },
have A := (hf.has_sum zero_mem).unique (has_sum_single _ this),
simpa [v_eq] using A.symm,
end
lemma has_fpower_series_at.coeff_zero (hf : has_fpower_series_at f pf x) (v : fin 0 → E) :
pf 0 v = f x :=
let ⟨rf, hrf⟩ := hf in hrf.coeff_zero v
/-- If a function admits a power series expansion, then it is exponentially close to the partial
sums of this power series on strict subdisks of the disk of convergence.
This version provides an upper estimate that decreases both in `∥y∥` and `n`. See also
`has_fpower_series_on_ball.uniform_geometric_approx` for a weaker version. -/
lemma has_fpower_series_on_ball.uniform_geometric_approx' {r' : ℝ≥0}
(hf : has_fpower_series_on_ball f p x r) (h : (r' : ℝ≥0∞) < r) :
∃ (a ∈ Ioo (0 : ℝ) 1) (C > 0), (∀ y ∈ metric.ball (0 : E) r', ∀ n,
∥f (x + y) - p.partial_sum n y∥ ≤ C * (a * (∥y∥ / r')) ^ n) :=
begin
obtain ⟨a, ha, C, hC, hp⟩ : ∃ (a ∈ Ioo (0 : ℝ) 1) (C > 0), ∀ n, ∥p n∥ * r' ^n ≤ C * a^n :=
p.norm_mul_pow_le_mul_pow_of_lt_radius (h.trans_le hf.r_le),
refine ⟨a, ha, C / (1 - a), div_pos hC (sub_pos.2 ha.2), λ y hy n, _⟩,
have yr' : ∥y∥ < r', by { rw ball_0_eq at hy, exact hy },
have hr'0 : 0 < (r' : ℝ), from (norm_nonneg _).trans_lt yr',
have : y ∈ emetric.ball (0 : E) r,
{ refine mem_emetric_ball_0_iff.2 (lt_trans _ h),
exact_mod_cast yr' },
rw [norm_sub_rev, ← mul_div_right_comm],
have ya : a * (∥y∥ / ↑r') ≤ a,
from mul_le_of_le_one_right ha.1.le (div_le_one_of_le yr'.le r'.coe_nonneg),
suffices : ∥p.partial_sum n y - f (x + y)∥ ≤ C * (a * (∥y∥ / r')) ^ n / (1 - a * (∥y∥ / r')),
{ refine this.trans _,
apply_rules [div_le_div_of_le_left, sub_pos.2, div_nonneg, mul_nonneg, pow_nonneg, hC.lt.le,
ha.1.le, norm_nonneg, nnreal.coe_nonneg, ha.2, (sub_le_sub_iff_left _).2]; apply_instance },
apply norm_sub_le_of_geometric_bound_of_has_sum (ya.trans_lt ha.2) _ (hf.has_sum this),
assume n,
calc ∥(p n) (λ (i : fin n), y)∥ ≤ ∥p n∥ * (∏ i : fin n, ∥y∥) :
continuous_multilinear_map.le_op_norm _ _
... = (∥p n∥ * r' ^ n) * (∥y∥ / r') ^ n : by field_simp [hr'0.ne', mul_right_comm]
... ≤ (C * a ^ n) * (∥y∥ / r') ^ n :
mul_le_mul_of_nonneg_right (hp n) (pow_nonneg (div_nonneg (norm_nonneg _) r'.coe_nonneg) _)
... ≤ C * (a * (∥y∥ / r')) ^ n : by rw [mul_pow, mul_assoc]
end
/-- If a function admits a power series expansion, then it is exponentially close to the partial
sums of this power series on strict subdisks of the disk of convergence. -/
lemma has_fpower_series_on_ball.uniform_geometric_approx {r' : ℝ≥0}
(hf : has_fpower_series_on_ball f p x r) (h : (r' : ℝ≥0∞) < r) :
∃ (a ∈ Ioo (0 : ℝ) 1) (C > 0), (∀ y ∈ metric.ball (0 : E) r', ∀ n,
∥f (x + y) - p.partial_sum n y∥ ≤ C * a ^ n) :=
begin
obtain ⟨a, ha, C, hC, hp⟩ : ∃ (a ∈ Ioo (0 : ℝ) 1) (C > 0),
(∀ y ∈ metric.ball (0 : E) r', ∀ n, ∥f (x + y) - p.partial_sum n y∥ ≤ C * (a * (∥y∥ / r')) ^ n),
from hf.uniform_geometric_approx' h,
refine ⟨a, ha, C, hC, λ y hy n, (hp y hy n).trans _⟩,
have yr' : ∥y∥ < r', by rwa ball_0_eq at hy,
refine mul_le_mul_of_nonneg_left (pow_le_pow_of_le_left _ _ _) hC.lt.le,
exacts [mul_nonneg ha.1.le (div_nonneg (norm_nonneg y) r'.coe_nonneg),
mul_le_of_le_one_right ha.1.le (div_le_one_of_le yr'.le r'.coe_nonneg)]
end
/-- Taylor formula for an analytic function, `is_O` version. -/
lemma has_fpower_series_at.is_O_sub_partial_sum_pow (hf : has_fpower_series_at f p x) (n : ℕ) :
is_O (λ y : E, f (x + y) - p.partial_sum n y) (λ y, ∥y∥ ^ n) (𝓝 0) :=
begin
rcases hf with ⟨r, hf⟩,
rcases ennreal.lt_iff_exists_nnreal_btwn.1 hf.r_pos with ⟨r', r'0, h⟩,
obtain ⟨a, ha, C, hC, hp⟩ : ∃ (a ∈ Ioo (0 : ℝ) 1) (C > 0),
(∀ y ∈ metric.ball (0 : E) r', ∀ n, ∥f (x + y) - p.partial_sum n y∥ ≤ C * (a * (∥y∥ / r')) ^ n),
from hf.uniform_geometric_approx' h,
refine is_O_iff.2 ⟨C * (a / r') ^ n, _⟩,
replace r'0 : 0 < (r' : ℝ), by exact_mod_cast r'0,
filter_upwards [metric.ball_mem_nhds (0 : E) r'0], intros y hy,
simpa [mul_pow, mul_div_assoc, mul_assoc, div_mul_eq_mul_div] using hp y hy n
end
-- hack to speed up simp when dealing with complicated types
local attribute [-instance] unique.subsingleton pi.subsingleton
/-- If `f` has formal power series `∑ n, pₙ` on a ball of radius `r`, then for `y, z` in any smaller
ball, the norm of the difference `f y - f z - p 1 (λ _, y - z)` is bounded above by
`C * (max ∥y - x∥ ∥z - x∥) * ∥y - z∥`. This lemma formulates this property using `is_O` and
`filter.principal` on `E × E`. -/
lemma has_fpower_series_on_ball.is_O_image_sub_image_sub_deriv_principal
(hf : has_fpower_series_on_ball f p x r) (hr : r' < r) :
is_O (λ y : E × E, f y.1 - f y.2 - (p 1 (λ _, y.1 - y.2)))
(λ y, ∥y - (x, x)∥ * ∥y.1 - y.2∥) (𝓟 $ emetric.ball (x, x) r') :=
begin
lift r' to ℝ≥0 using ne_top_of_lt hr,
rcases (zero_le r').eq_or_lt with rfl|hr'0,
{ simp only [is_O_bot, emetric.ball_zero, principal_empty, ennreal.coe_zero] },
obtain ⟨a, ha, C, hC : 0 < C, hp⟩ :
∃ (a ∈ Ioo (0 : ℝ) 1) (C > 0), ∀ (n : ℕ), ∥p n∥ * ↑r' ^ n ≤ C * a ^ n,
from p.norm_mul_pow_le_mul_pow_of_lt_radius (hr.trans_le hf.r_le),
simp only [← le_div_iff (pow_pos (nnreal.coe_pos.2 hr'0) _)] at hp,
set L : E × E → ℝ := λ y,
(C * (a / r') ^ 2) * (∥y - (x, x)∥ * ∥y.1 - y.2∥) * (a / (1 - a) ^ 2 + 2 / (1 - a)),
have hL : ∀ y ∈ emetric.ball (x, x) r',
∥f y.1 - f y.2 - (p 1 (λ _, y.1 - y.2))∥ ≤ L y,
{ intros y hy',
have hy : y ∈ (emetric.ball x r).prod (emetric.ball x r),
{ rw [emetric.ball_prod_same], exact emetric.ball_subset_ball hr.le hy' },
set A : ℕ → F := λ n, p n (λ _, y.1 - x) - p n (λ _, y.2 - x),
have hA : has_sum (λ n, A (n + 2)) (f y.1 - f y.2 - (p 1 (λ _, y.1 - y.2))),
{ convert (has_sum_nat_add_iff' 2).2 ((hf.has_sum_sub hy.1).sub (hf.has_sum_sub hy.2)) using 1,
rw [finset.sum_range_succ, finset.sum_range_one, hf.coeff_zero, hf.coeff_zero, sub_self,
zero_add, ← subsingleton.pi_single_eq (0 : fin 1) (y.1 - x), pi.single,
← subsingleton.pi_single_eq (0 : fin 1) (y.2 - x), pi.single, ← (p 1).map_sub, ← pi.single,
subsingleton.pi_single_eq, sub_sub_sub_cancel_right] },
rw [emetric.mem_ball, edist_eq_coe_nnnorm_sub, ennreal.coe_lt_coe] at hy',
set B : ℕ → ℝ := λ n,
(C * (a / r') ^ 2) * (∥y - (x, x)∥ * ∥y.1 - y.2∥) * ((n + 2) * a ^ n),
have hAB : ∀ n, ∥A (n + 2)∥ ≤ B n := λ n,
calc ∥A (n + 2)∥ ≤ ∥p (n + 2)∥ * ↑(n + 2) * ∥y - (x, x)∥ ^ (n + 1) * ∥y.1 - y.2∥ :
by simpa only [fintype.card_fin, pi_norm_const, prod.norm_def, pi.sub_def, prod.fst_sub,
prod.snd_sub, sub_sub_sub_cancel_right]
using (p $ n + 2).norm_image_sub_le (λ _, y.1 - x) (λ _, y.2 - x)
... = ∥p (n + 2)∥ * ∥y - (x, x)∥ ^ n * (↑(n + 2) * ∥y - (x, x)∥ * ∥y.1 - y.2∥) :
by { rw [pow_succ ∥y - (x, x)∥], ac_refl }
... ≤ (C * a ^ (n + 2) / r' ^ (n + 2)) * r' ^ n * (↑(n + 2) * ∥y - (x, x)∥ * ∥y.1 - y.2∥) :
by apply_rules [mul_le_mul_of_nonneg_right, mul_le_mul, hp, pow_le_pow_of_le_left,
hy'.le, norm_nonneg, pow_nonneg, div_nonneg, mul_nonneg, nat.cast_nonneg,
hC.le, r'.coe_nonneg, ha.1.le]
... = B n :
by { field_simp [B, pow_succ, hr'0.ne'], simp only [mul_assoc, mul_comm, mul_left_comm] },
have hBL : has_sum B (L y),
{ apply has_sum.mul_left,
simp only [add_mul],
have : ∥a∥ < 1, by simp only [real.norm_eq_abs, abs_of_pos ha.1, ha.2],
convert (has_sum_coe_mul_geometric_of_norm_lt_1 this).add
((has_sum_geometric_of_norm_lt_1 this).mul_left 2) },
exact hA.norm_le_of_bounded hBL hAB },
suffices : is_O L (λ y, ∥y - (x, x)∥ * ∥y.1 - y.2∥) (𝓟 (emetric.ball (x, x) r')),
{ refine (is_O.of_bound 1 (eventually_principal.2 $ λ y hy, _)).trans this,
rw one_mul,
exact (hL y hy).trans (le_abs_self _) },
simp_rw [L, mul_right_comm _ (_ * _)],
exact (is_O_refl _ _).const_mul_left _,
end
/-- If `f` has formal power series `∑ n, pₙ` on a ball of radius `r`, then for `y, z` in any smaller
ball, the norm of the difference `f y - f z - p 1 (λ _, y - z)` is bounded above by
`C * (max ∥y - x∥ ∥z - x∥) * ∥y - z∥`. -/
lemma has_fpower_series_on_ball.image_sub_sub_deriv_le
(hf : has_fpower_series_on_ball f p x r) (hr : r' < r) :
∃ C, ∀ (y z ∈ emetric.ball x r'),
∥f y - f z - (p 1 (λ _, y - z))∥ ≤ C * (max ∥y - x∥ ∥z - x∥) * ∥y - z∥ :=
by simpa only [is_O_principal, mul_assoc, normed_field.norm_mul, norm_norm, prod.forall,
emetric.mem_ball, prod.edist_eq, max_lt_iff, and_imp]
using hf.is_O_image_sub_image_sub_deriv_principal hr
/-- If `f` has formal power series `∑ n, pₙ` at `x`, then
`f y - f z - p 1 (λ _, y - z) = O(∥(y, z) - (x, x)∥ * ∥y - z∥)` as `(y, z) → (x, x)`.
In particular, `f` is strictly differentiable at `x`. -/
lemma has_fpower_series_at.is_O_image_sub_norm_mul_norm_sub (hf : has_fpower_series_at f p x) :
is_O (λ y : E × E, f y.1 - f y.2 - (p 1 (λ _, y.1 - y.2)))
(λ y, ∥y - (x, x)∥ * ∥y.1 - y.2∥) (𝓝 (x, x)) :=
begin
rcases hf with ⟨r, hf⟩,
rcases ennreal.lt_iff_exists_nnreal_btwn.1 hf.r_pos with ⟨r', r'0, h⟩,
refine (hf.is_O_image_sub_image_sub_deriv_principal h).mono _,
exact le_principal_iff.2 (emetric.ball_mem_nhds _ r'0)
end
/-- If a function admits a power series expansion at `x`, then it is the uniform limit of the
partial sums of this power series on strict subdisks of the disk of convergence, i.e., `f (x + y)`
is the uniform limit of `p.partial_sum n y` there. -/
lemma has_fpower_series_on_ball.tendsto_uniformly_on {r' : ℝ≥0}
(hf : has_fpower_series_on_ball f p x r) (h : (r' : ℝ≥0∞) < r) :
tendsto_uniformly_on (λ n y, p.partial_sum n y)
(λ y, f (x + y)) at_top (metric.ball (0 : E) r') :=
begin
obtain ⟨a, ha, C, hC, hp⟩ : ∃ (a ∈ Ioo (0 : ℝ) 1) (C > 0),
(∀ y ∈ metric.ball (0 : E) r', ∀ n, ∥f (x + y) - p.partial_sum n y∥ ≤ C * a ^ n),
from hf.uniform_geometric_approx h,
refine metric.tendsto_uniformly_on_iff.2 (λ ε εpos, _),
have L : tendsto (λ n, (C : ℝ) * a^n) at_top (𝓝 ((C : ℝ) * 0)) :=
tendsto_const_nhds.mul (tendsto_pow_at_top_nhds_0_of_lt_1 ha.1.le ha.2),
rw mul_zero at L,
refine (L.eventually (gt_mem_nhds εpos)).mono (λ n hn y hy, _),
rw dist_eq_norm,
exact (hp y hy n).trans_lt hn
end
/-- If a function admits a power series expansion at `x`, then it is the locally uniform limit of
the partial sums of this power series on the disk of convergence, i.e., `f (x + y)`
is the locally uniform limit of `p.partial_sum n y` there. -/
lemma has_fpower_series_on_ball.tendsto_locally_uniformly_on
(hf : has_fpower_series_on_ball f p x r) :
tendsto_locally_uniformly_on (λ n y, p.partial_sum n y) (λ y, f (x + y))
at_top (emetric.ball (0 : E) r) :=
begin
assume u hu x hx,
rcases ennreal.lt_iff_exists_nnreal_btwn.1 hx with ⟨r', xr', hr'⟩,
have : emetric.ball (0 : E) r' ∈ 𝓝 x :=
is_open.mem_nhds emetric.is_open_ball xr',
refine ⟨emetric.ball (0 : E) r', mem_nhds_within_of_mem_nhds this, _⟩,
simpa [metric.emetric_ball_nnreal] using hf.tendsto_uniformly_on hr' u hu
end
/-- If a function admits a power series expansion at `x`, then it is the uniform limit of the
partial sums of this power series on strict subdisks of the disk of convergence, i.e., `f y`
is the uniform limit of `p.partial_sum n (y - x)` there. -/
lemma has_fpower_series_on_ball.tendsto_uniformly_on' {r' : ℝ≥0}
(hf : has_fpower_series_on_ball f p x r) (h : (r' : ℝ≥0∞) < r) :
tendsto_uniformly_on (λ n y, p.partial_sum n (y - x)) f at_top (metric.ball (x : E) r') :=
begin
convert (hf.tendsto_uniformly_on h).comp (λ y, y - x),
{ simp [(∘)] },
{ ext z, simp [dist_eq_norm] }
end
/-- If a function admits a power series expansion at `x`, then it is the locally uniform limit of
the partial sums of this power series on the disk of convergence, i.e., `f y`
is the locally uniform limit of `p.partial_sum n (y - x)` there. -/
lemma has_fpower_series_on_ball.tendsto_locally_uniformly_on'
(hf : has_fpower_series_on_ball f p x r) :
tendsto_locally_uniformly_on (λ n y, p.partial_sum n (y - x)) f at_top (emetric.ball (x : E) r) :=
begin
have A : continuous_on (λ (y : E), y - x) (emetric.ball (x : E) r) :=
(continuous_id.sub continuous_const).continuous_on,
convert (hf.tendsto_locally_uniformly_on).comp (λ (y : E), y - x) _ A,
{ ext z, simp },
{ assume z, simp [edist_eq_coe_nnnorm, edist_eq_coe_nnnorm_sub] }
end
/-- If a function admits a power series expansion on a disk, then it is continuous there. -/
lemma has_fpower_series_on_ball.continuous_on
(hf : has_fpower_series_on_ball f p x r) : continuous_on f (emetric.ball x r) :=
hf.tendsto_locally_uniformly_on'.continuous_on $ λ n,
((p.partial_sum_continuous n).comp (continuous_id.sub continuous_const)).continuous_on
lemma has_fpower_series_at.continuous_at (hf : has_fpower_series_at f p x) : continuous_at f x :=
let ⟨r, hr⟩ := hf in hr.continuous_on.continuous_at (emetric.ball_mem_nhds x (hr.r_pos))
lemma analytic_at.continuous_at (hf : analytic_at 𝕜 f x) : continuous_at f x :=
let ⟨p, hp⟩ := hf in hp.continuous_at
/-- In a complete space, the sum of a converging power series `p` admits `p` as a power series.
This is not totally obvious as we need to check the convergence of the series. -/
protected lemma formal_multilinear_series.has_fpower_series_on_ball [complete_space F]
(p : formal_multilinear_series 𝕜 E F) (h : 0 < p.radius) :
has_fpower_series_on_ball p.sum p 0 p.radius :=
{ r_le := le_refl _,
r_pos := h,
has_sum := λ y hy, by { rw zero_add, exact p.has_sum hy } }
lemma has_fpower_series_on_ball.sum [complete_space F] (h : has_fpower_series_on_ball f p x r)
{y : E} (hy : y ∈ emetric.ball (0 : E) r) : f (x + y) = p.sum y :=
(h.has_sum hy).unique (p.has_sum (lt_of_lt_of_le hy h.r_le))
/-- The sum of a converging power series is continuous in its disk of convergence. -/
protected lemma formal_multilinear_series.continuous_on [complete_space F] :
continuous_on p.sum (emetric.ball 0 p.radius) :=
begin
cases (zero_le p.radius).eq_or_lt with h h,
{ simp [← h, continuous_on_empty] },
{ exact (p.has_fpower_series_on_ball h).continuous_on }
end
end
/-!
### Changing origin in a power series
If a function is analytic in a disk `D(x, R)`, then it is analytic in any disk contained in that
one. Indeed, one can write
$$
f (x + y + z) = \sum_{n} p_n (y + z)^n = \sum_{n, k} \binom{n}{k} p_n y^{n-k} z^k
= \sum_{k} \Bigl(\sum_{n} \binom{n}{k} p_n y^{n-k}\Bigr) z^k.
$$
The corresponding power series has thus a `k`-th coefficient equal to
$\sum_{n} \binom{n}{k} p_n y^{n-k}$. In the general case where `pₙ` is a multilinear map, this has
to be interpreted suitably: instead of having a binomial coefficient, one should sum over all
possible subsets `s` of `fin n` of cardinal `k`, and attribute `z` to the indices in `s` and
`y` to the indices outside of `s`.
In this paragraph, we implement this. The new power series is called `p.change_origin y`. Then, we
check its convergence and the fact that its sum coincides with the original sum. The outcome of this
discussion is that the set of points where a function is analytic is open.
-/
namespace formal_multilinear_series
section
variables (p : formal_multilinear_series 𝕜 E F) {x y : E} {r R : ℝ≥0}
/-- A term of `formal_multilinear_series.change_origin_series`.
Given a formal multilinear series `p` and a point `x` in its ball of convergence,
`p.change_origin x` is a formal multilinear series such that
`p.sum (x+y) = (p.change_origin x).sum y` when this makes sense. Each term of `p.change_origin x`
is itself an analytic function of `x` given by the series `p.change_origin_series`. Each term in
`change_origin_series` is the sum of `change_origin_series_term`'s over all `s` of cardinality `l`.
-/
def change_origin_series_term (k l : ℕ) (s : finset (fin (k + l))) (hs : s.card = l) :
E [×l]→L[𝕜] E [×k]→L[𝕜] F :=
continuous_multilinear_map.curry_fin_finset 𝕜 E F hs
(by erw [finset.card_compl, fintype.card_fin, hs, nat.add_sub_cancel]) (p $ k + l)
lemma change_origin_series_term_apply (k l : ℕ) (s : finset (fin (k + l))) (hs : s.card = l)
(x y : E) :
p.change_origin_series_term k l s hs (λ _, x) (λ _, y) =
p (k + l) (s.piecewise (λ _, x) (λ _, y)) :=
continuous_multilinear_map.curry_fin_finset_apply_const _ _ _ _ _
@[simp] lemma norm_change_origin_series_term (k l : ℕ) (s : finset (fin (k + l)))
(hs : s.card = l) :
∥p.change_origin_series_term k l s hs∥ = ∥p (k + l)∥ :=
by simp only [change_origin_series_term, linear_isometry_equiv.norm_map]
@[simp] lemma nnnorm_change_origin_series_term (k l : ℕ) (s : finset (fin (k + l)))
(hs : s.card = l) :
∥p.change_origin_series_term k l s hs∥₊ = ∥p (k + l)∥₊ :=
by simp only [change_origin_series_term, linear_isometry_equiv.nnnorm_map]
lemma nnnorm_change_origin_series_term_apply_le (k l : ℕ) (s : finset (fin (k + l)))
(hs : s.card = l) (x y : E) :
∥p.change_origin_series_term k l s hs (λ _, x) (λ _, y)∥₊ ≤ ∥p (k + l)∥₊ * ∥x∥₊ ^ l * ∥y∥₊ ^ k :=
begin
rw [← p.nnnorm_change_origin_series_term k l s hs, ← fin.prod_const, ← fin.prod_const],
apply continuous_multilinear_map.le_of_op_nnnorm_le,
apply continuous_multilinear_map.le_op_nnnorm
end
/-- The power series for `f.change_origin k`.
Given a formal multilinear series `p` and a point `x` in its ball of convergence,
`p.change_origin x` is a formal multilinear series such that
`p.sum (x+y) = (p.change_origin x).sum y` when this makes sense. -/
def change_origin_series (k : ℕ) : formal_multilinear_series 𝕜 E (E [×k]→L[𝕜] F) :=
λ l, ∑ s : {s : finset (fin (k + l)) // finset.card s = l}, p.change_origin_series_term k l s s.2
lemma nnnorm_change_origin_series_le_tsum (k l : ℕ) :
∥p.change_origin_series k l∥₊ ≤
∑' (x : {s : finset (fin (k + l)) // s.card = l}), ∥p (k + l)∥₊ :=
(nnnorm_sum_le _ _).trans_eq $ by simp only [tsum_fintype, nnnorm_change_origin_series_term]
lemma nnnorm_change_origin_series_apply_le_tsum (k l : ℕ) (x : E) :
∥p.change_origin_series k l (λ _, x)∥₊ ≤
∑' s : {s : finset (fin (k + l)) // s.card = l}, ∥p (k + l)∥₊ * ∥x∥₊ ^ l :=
begin
rw [nnreal.tsum_mul_right, ← fin.prod_const],
exact (p.change_origin_series k l).le_of_op_nnnorm_le _
(p.nnnorm_change_origin_series_le_tsum _ _)
end
/--
Changing the origin of a formal multilinear series `p`, so that
`p.sum (x+y) = (p.change_origin x).sum y` when this makes sense.
-/
def change_origin (x : E) : formal_multilinear_series 𝕜 E F :=
λ k, (p.change_origin_series k).sum x
/-- An auxiliary equivalence useful in the proofs about
`formal_multilinear_series.change_origin_series`: the set of triples `(k, l, s)`, where `s` is a
`finset (fin (k + l))` of cardinality `l` is equivalent to the set of pairs `(n, s)`, where `s` is a
`finset (fin n)`.
The forward map sends `(k, l, s)` to `(k + l, s)` and the inverse map sends `(n, s)` to
`(n - finset.card s, finset.card s, s)`. The actual definition is less readable because of problems
with non-definitional equalities. -/
@[simps] def change_origin_index_equiv :
(Σ k l : ℕ, {s : finset (fin (k + l)) // s.card = l}) ≃ Σ n : ℕ, finset (fin n) :=
{ to_fun := λ s, ⟨s.1 + s.2.1, s.2.2⟩,
inv_fun := λ s, ⟨s.1 - s.2.card, s.2.card, ⟨s.2.map
(fin.cast $ (nat.sub_add_cancel $ card_finset_fin_le s.2).symm).to_equiv.to_embedding,
finset.card_map _⟩⟩,
left_inv :=
begin
rintro ⟨k, l, ⟨s : finset (fin $ k + l), hs : s.card = l⟩⟩,
dsimp only [subtype.coe_mk],
-- Lean can't automatically generalize `k' = k + l - s.card`, `l' = s.card`, so we explicitly
-- formulate the generalized goal
suffices : ∀ k' l', k' = k → l' = l → ∀ (hkl : k + l = k' + l') hs',
(⟨k', l', ⟨finset.map (fin.cast hkl).to_equiv.to_embedding s, hs'⟩⟩ :
(Σ k l : ℕ, {s : finset (fin (k + l)) // s.card = l})) = ⟨k, l, ⟨s, hs⟩⟩,
{ apply this; simp only [hs, nat.add_sub_cancel] },
rintro _ _ rfl rfl hkl hs',
simp only [equiv.refl_to_embedding, fin.cast_refl, finset.map_refl, eq_self_iff_true,
order_iso.refl_to_equiv, and_self, heq_iff_eq]
end,
right_inv :=
begin
rintro ⟨n, s⟩,
simp [nat.sub_add_cancel (card_finset_fin_le s), fin.cast_to_equiv]
end }
lemma change_origin_series_summable_aux₁ {r r' : ℝ≥0} (hr : (r + r' : ℝ≥0∞) < p.radius) :
summable (λ s : Σ k l : ℕ, {s : finset (fin (k + l)) // s.card = l},
∥p (s.1 + s.2.1)∥₊ * r ^ s.2.1 * r' ^ s.1) :=
begin
rw ← change_origin_index_equiv.symm.summable_iff,
dsimp only [(∘), change_origin_index_equiv_symm_apply_fst,
change_origin_index_equiv_symm_apply_snd_fst],
have : ∀ n : ℕ, has_sum
(λ s : finset (fin n), ∥p (n - s.card + s.card)∥₊ * r ^ s.card * r' ^ (n - s.card))
(∥p n∥₊ * (r + r') ^ n),
{ intro n,
-- TODO: why `simp only [nat.sub_add_cancel (card_finset_fin_le _)]` fails?
convert_to has_sum (λ s : finset (fin n), ∥p n∥₊ * (r ^ s.card * r' ^ (n - s.card))) _,
{ ext1 s, rw [nat.sub_add_cancel (card_finset_fin_le _), mul_assoc] },
rw ← fin.sum_pow_mul_eq_add_pow,
exact (has_sum_fintype _).mul_left _ },
refine nnreal.summable_sigma.2 ⟨λ n, (this n).summable, _⟩,
simp only [(this _).tsum_eq],
exact p.summable_nnnorm_mul_pow hr
end
lemma change_origin_series_summable_aux₂ (hr : (r : ℝ≥0∞) < p.radius) (k : ℕ) :
summable (λ s : Σ l : ℕ, {s : finset (fin (k + l)) // s.card = l}, ∥p (k + s.1)∥₊ * r ^ s.1) :=
begin
rcases ennreal.lt_iff_exists_add_pos_lt.1 hr with ⟨r', h0, hr'⟩,
simpa only [mul_inv_cancel_right' (pow_pos h0 _).ne']
using ((nnreal.summable_sigma.1
(p.change_origin_series_summable_aux₁ hr')).1 k).mul_right (r' ^ k)⁻¹
end
lemma change_origin_series_summable_aux₃ {r : ℝ≥0} (hr : ↑r < p.radius) (k : ℕ) :
summable (λ l : ℕ, ∥p.change_origin_series k l∥₊ * r ^ l) :=
begin
refine nnreal.summable_of_le (λ n, _)
(nnreal.summable_sigma.1 $ p.change_origin_series_summable_aux₂ hr k).2,
simp only [nnreal.tsum_mul_right],
exact mul_le_mul' (p.nnnorm_change_origin_series_le_tsum _ _) le_rfl
end
lemma le_change_origin_series_radius (k : ℕ) :
p.radius ≤ (p.change_origin_series k).radius :=
ennreal.le_of_forall_nnreal_lt $ λ r hr,
le_radius_of_summable_nnnorm _ (p.change_origin_series_summable_aux₃ hr k)
lemma nnnorm_change_origin_le (k : ℕ) (h : (∥x∥₊ : ℝ≥0∞) < p.radius) :
∥p.change_origin x k∥₊ ≤
∑' s : Σ l : ℕ, {s : finset (fin (k + l)) // s.card = l}, ∥p (k + s.1)∥₊ * ∥x∥₊ ^ s.1 :=
begin
refine tsum_of_nnnorm_bounded _ (λ l, p.nnnorm_change_origin_series_apply_le_tsum k l x),
have := p.change_origin_series_summable_aux₂ h k,
refine has_sum.sigma this.has_sum (λ l, _),
exact ((nnreal.summable_sigma.1 this).1 l).has_sum
end
/-- The radius of convergence of `p.change_origin x` is at least `p.radius - ∥x∥`. In other words,
`p.change_origin x` is well defined on the largest ball contained in the original ball of
convergence.-/
lemma change_origin_radius : p.radius - ∥x∥₊ ≤ (p.change_origin x).radius :=
begin
refine ennreal.le_of_forall_pos_nnreal_lt (λ r h0 hr, _),
rw [ennreal.lt_sub_iff_add_lt, add_comm] at hr,
have hr' : (∥x∥₊ : ℝ≥0∞) < p.radius, from (le_add_right le_rfl).trans_lt hr,
apply le_radius_of_summable_nnnorm,
have : ∀ k : ℕ, ∥p.change_origin x k∥₊ * r ^ k ≤
(∑' s : Σ l : ℕ, {s : finset (fin (k + l)) // s.card = l}, ∥p (k + s.1)∥₊ * ∥x∥₊ ^ s.1) * r ^ k,
from λ k, mul_le_mul_right' (p.nnnorm_change_origin_le k hr') (r ^ k),
refine nnreal.summable_of_le this _,
simpa only [← nnreal.tsum_mul_right]
using (nnreal.summable_sigma.1 (p.change_origin_series_summable_aux₁ hr)).2
end
end
-- From this point on, assume that the space is complete, to make sure that series that converge
-- in norm also converge in `F`.
variables [complete_space F] (p : formal_multilinear_series 𝕜 E F) {x y : E} {r R : ℝ≥0}
lemma has_fpower_series_on_ball_change_origin (k : ℕ) (hr : 0 < p.radius) :
has_fpower_series_on_ball (λ x, p.change_origin x k) (p.change_origin_series k) 0 p.radius :=
have _ := p.le_change_origin_series_radius k,
((p.change_origin_series k).has_fpower_series_on_ball (hr.trans_le this)).mono hr this
/-- Summing the series `p.change_origin x` at a point `y` gives back `p (x + y)`-/
theorem change_origin_eval (h : (∥x∥₊ + ∥y∥₊ : ℝ≥0∞) < p.radius) :
(p.change_origin x).sum y = (p.sum (x + y)) :=
begin
have radius_pos : 0 < p.radius := lt_of_le_of_lt (zero_le _) h,
have x_mem_ball : x ∈ emetric.ball (0 : E) p.radius,
from mem_emetric_ball_0_iff.2 ((le_add_right le_rfl).trans_lt h),
have y_mem_ball : y ∈ emetric.ball (0 : E) (p.change_origin x).radius,
{ refine mem_emetric_ball_0_iff.2 (lt_of_lt_of_le _ p.change_origin_radius),
rwa [ennreal.lt_sub_iff_add_lt, add_comm] },
have x_add_y_mem_ball : x + y ∈ emetric.ball (0 : E) p.radius,
{ refine mem_emetric_ball_0_iff.2 (lt_of_le_of_lt _ h),
exact_mod_cast nnnorm_add_le x y },
set f : (Σ (k l : ℕ), {s : finset (fin (k + l)) // s.card = l}) → F :=
λ s, p.change_origin_series_term s.1 s.2.1 s.2.2 s.2.2.2 (λ _, x) (λ _, y),
have hsf : summable f,
{ refine summable_of_nnnorm_bounded _ (p.change_origin_series_summable_aux₁ h) _,
rintro ⟨k, l, s, hs⟩, dsimp only [subtype.coe_mk],
exact p.nnnorm_change_origin_series_term_apply_le _ _ _ _ _ _ },
have hf : has_sum f ((p.change_origin x).sum y),
{ refine has_sum.sigma_of_has_sum ((p.change_origin x).summable y_mem_ball).has_sum (λ k, _) hsf,
{ dsimp only [f],
refine continuous_multilinear_map.has_sum_eval _ _,
have := (p.has_fpower_series_on_ball_change_origin k radius_pos).has_sum x_mem_ball,
rw zero_add at this,
refine has_sum.sigma_of_has_sum this (λ l, _) _,
{ simp only [change_origin_series, continuous_multilinear_map.sum_apply],
apply has_sum_fintype },
{ refine summable_of_nnnorm_bounded _ (p.change_origin_series_summable_aux₂
(mem_emetric_ball_0_iff.1 x_mem_ball) k) (λ s, _),
refine (continuous_multilinear_map.le_op_nnnorm _ _).trans_eq _,
simp } } },
refine hf.unique (change_origin_index_equiv.symm.has_sum_iff.1 _),
refine has_sum.sigma_of_has_sum (p.has_sum x_add_y_mem_ball) (λ n, _)
(change_origin_index_equiv.symm.summable_iff.2 hsf),
erw [(p n).map_add_univ (λ _, x) (λ _, y)],
convert has_sum_fintype _,
ext1 s,
dsimp only [f, change_origin_series_term, (∘), change_origin_index_equiv_symm_apply_fst,
change_origin_index_equiv_symm_apply_snd_fst, change_origin_index_equiv_symm_apply_snd_snd_coe],
rw continuous_multilinear_map.curry_fin_finset_apply_const,
have : ∀ m (hm : n = m), p n (s.piecewise (λ _, x) (λ _, y)) =
p m ((s.map (fin.cast hm).to_equiv.to_embedding).piecewise (λ _, x) (λ _, y)),
{ rintro m rfl, simp, congr /- probably different `decidable_eq` instances -/ },
apply this
end
end formal_multilinear_series
section
variables [complete_space F] {f : E → F} {p : formal_multilinear_series 𝕜 E F} {x y : E}
{r : ℝ≥0∞}
/-- If a function admits a power series expansion `p` on a ball `B (x, r)`, then it also admits a
power series on any subball of this ball (even with a different center), given by `p.change_origin`.
-/
theorem has_fpower_series_on_ball.change_origin
(hf : has_fpower_series_on_ball f p x r) (h : (∥y∥₊ : ℝ≥0∞) < r) :
has_fpower_series_on_ball f (p.change_origin y) (x + y) (r - ∥y∥₊) :=
{ r_le := begin
apply le_trans _ p.change_origin_radius,
exact ennreal.sub_le_sub hf.r_le (le_refl _)
end,
r_pos := by simp [h],
has_sum := λ z hz, begin
convert (p.change_origin y).has_sum _,
{ rw [mem_emetric_ball_0_iff, ennreal.lt_sub_iff_add_lt, add_comm] at hz,
rw [p.change_origin_eval (hz.trans_le hf.r_le), add_assoc, hf.sum],
refine mem_emetric_ball_0_iff.2 (lt_of_le_of_lt _ hz),
exact_mod_cast nnnorm_add_le y z },
{ refine emetric.ball_subset_ball (le_trans _ p.change_origin_radius) hz,
exact ennreal.sub_le_sub hf.r_le le_rfl }
end }
/-- If a function admits a power series expansion `p` on an open ball `B (x, r)`, then
it is analytic at every point of this ball. -/
lemma has_fpower_series_on_ball.analytic_at_of_mem
(hf : has_fpower_series_on_ball f p x r) (h : y ∈ emetric.ball x r) :
analytic_at 𝕜 f y :=
begin
have : (∥y - x∥₊ : ℝ≥0∞) < r, by simpa [edist_eq_coe_nnnorm_sub] using h,
have := hf.change_origin this,
rw [add_sub_cancel'_right] at this,
exact this.analytic_at
end
variables (𝕜 f)
/-- For any function `f` from a normed vector space to a Banach space, the set of points `x` such
that `f` is analytic at `x` is open. -/
lemma is_open_analytic_at : is_open {x | analytic_at 𝕜 f x} :=
begin
rw is_open_iff_mem_nhds,
rintro x ⟨p, r, hr⟩,
exact mem_of_superset (emetric.ball_mem_nhds _ hr.r_pos) (λ y hy, hr.analytic_at_of_mem hy)
end
end
|
8f6ff49c8309a80492465f6921fb1568524ab98d | 624f6f2ae8b3b1adc5f8f67a365c51d5126be45a | /tests/lean/run/induction1.lean | a003814decd07338ae2b27d22c6b3a967e15afbd | [
"Apache-2.0"
] | permissive | mhuisi/lean4 | 28d35a4febc2e251c7f05492e13f3b05d6f9b7af | dda44bc47f3e5d024508060dac2bcb59fd12e4c0 | refs/heads/master | 1,621,225,489,283 | 1,585,142,689,000 | 1,585,142,689,000 | 250,590,438 | 0 | 2 | Apache-2.0 | 1,602,443,220,000 | 1,585,327,814,000 | C | UTF-8 | Lean | false | false | 1,848 | lean | @[recursor 4]
def Or.elim2 {p q r : Prop} (major : p ∨ q) (left : p → r) (right : q → r) : r :=
Or.elim major left right
new_frontend
theorem tst0 {p q : Prop } (h : p ∨ q) : q ∨ p :=
begin
induction h;
{ apply Or.inr; assumption };
{ apply Or.inl; assumption }
end
theorem tst1 {p q : Prop } (h : p ∨ q) : q ∨ p :=
begin
induction h with
| inr h2 => Or.inl h2
| inl h1 => Or.inr h1
end
theorem tst2 {p q : Prop } (h : p ∨ q) : q ∨ p :=
begin
induction h using elim2 with
| left _ => Or.inr $ by assumption
| right _ => Or.inl $ by assumption
end
theorem tst3 {p q : Prop } (h : p ∨ q) : q ∨ p :=
begin
induction h using elim2 with
| right h => Or.inl h
| left h => Or.inr h
end
theorem tst4 {p q : Prop } (h : p ∨ q) : q ∨ p :=
begin
induction h using elim2 with
| right h => ?myright
| left h => ?myleft;
case myleft { exact Or.inr h };
case myright { exact Or.inl h };
end
theorem tst5 {p q : Prop } (h : p ∨ q) : q ∨ p :=
begin
induction h using elim2 with
| right h => Or.inl ?myright
| left h => Or.inr ?myleft;
case myleft assumption;
case myright exact h;
end
theorem tst6 {p q : Prop } (h : p ∨ q) : q ∨ p :=
begin
cases h with
| inr h2 => Or.inl h2
| inl h1 => Or.inr h1
end
theorem tst7 {α : Type} (xs : List α) (h : (a : α) → (as : List α) → xs ≠ a :: as) : xs = [] :=
begin
induction xs with
| nil => rfl
| cons z zs ih => absurd rfl (h z zs)
end
theorem tst8 {α : Type} (xs : List α) (h : (a : α) → (as : List α) → xs ≠ a :: as) : xs = [] :=
begin
induction xs;
exact rfl;
exact absurd rfl $ h _ _
end
theorem tst9 {α : Type} (xs : List α) (h : (a : α) → (as : List α) → xs ≠ a :: as) : xs = [] :=
begin
cases xs with
| nil => rfl
| cons z zs => absurd rfl (h z zs)
end
|
fc9936bd3a0de262cbbe292a24ea79bb3c3dbb3d | 5e3548e65f2c037cb94cd5524c90c623fbd6d46a | /src_icannos_totilas/topologie-espaces-normés/cpge_ten_16.lean | 476dfd9c1d23996e64abc04afe9f266d28b7897d | [] | no_license | ahayat16/lean_exos | d4f08c30adb601a06511a71b5ffb4d22d12ef77f | 682f2552d5b04a8c8eb9e4ab15f875a91b03845c | refs/heads/main | 1,693,101,073,585 | 1,636,479,336,000 | 1,636,479,336,000 | 415,000,441 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 263 | lean | import topology.basic
import data.set.basic
import data.rat.basic
import data.real.basic
import analysis.normed_space.basic
-- Montrer que Z est une partie fermée de R
theorem exo:
is_closed (fun r, exists z: int, r = real.of_rat (rat.of_int z))
:= sorry
|
96b7ff30991d0cf3fac596fc97fbb2f003e24ef9 | 6432ea7a083ff6ba21ea17af9ee47b9c371760f7 | /tests/pkg/user_opt/UserOpt/Opts.lean | 9b656a13ebd437435d31c495103598acdd7515e4 | [
"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 | 194 | lean | import Lean
register_option myBoolOpt : Bool := {
defValue := false
descr := "my Boolean option"
}
register_option myNatOpt : Nat := {
defValue := 100
descr := "my Nat option"
}
|
eac888ec90b27e1e886a1126cc6238c997464056 | 36938939954e91f23dec66a02728db08a7acfcf9 | /lean/deps/decodex86/src/sexp.lean | 0fe5799b9b1a0961fe49e51f049b016d0e3a706c | [
"Apache-2.0"
] | permissive | pnwamk/reopt-vcg | f8b56dd0279392a5e1c6aee721be8138e6b558d3 | c9f9f185fbefc25c36c4b506bbc85fd1a03c3b6d | refs/heads/master | 1,631,145,017,772 | 1,593,549,019,000 | 1,593,549,143,000 | 254,191,418 | 0 | 0 | null | 1,586,377,077,000 | 1,586,377,077,000 | null | UTF-8 | Lean | false | false | 1,520 | lean |
import system.io -- debug
import data.buffer.parser
inductive sexp
| atom : string -> sexp
| list : list sexp -> sexp
mutual def sexp_to_string, sexp_to_string_list
with sexp_to_string : sexp -> string
| (sexp.atom s) := s
| (sexp.list ss) := "(" ++ sexp_to_string_list ss ++ ")"
with sexp_to_string_list : list sexp -> string
| [] := ""
| (s :: ss) :=
sexp_to_string s ++ (match ss with | [] := "" | _ := " " end) ++ sexp_to_string_list ss
instance sexp_has_repr: has_repr sexp := ⟨sexp_to_string⟩
namespace sexp
section
open parser
@[reducible] def is_whitespace (c : char) : Prop :=
c = ' ' ∨ c = '\t' ∨ c = '\n'
def whitespace : parser unit := many (sat is_whitespace) >> return ()
def whitespaced {a} (p : parser a) : parser a :=
whitespace *> p <* whitespace
def atom_parser : parser sexp :=
sexp.atom <$> list.as_string <$> many1 (sat (λc, ¬ is_whitespace c ∧ c ≠ '(' ∧ c ≠ ')'))
def list_parser : parser sexp -> parser sexp := λrec,
do ch '(',
vs <- many rec,
ch ')',
pure (sexp.list vs)
def sexp_parser : parser sexp :=
fix (λrec, whitespaced (atom_parser <|> list_parser rec))
def from_string := run_string sexp_parser
def from_buffer := run sexp_parser
end
end sexp
/-
def main : io unit := do
args ← io.cmdline_args,
stdin <- io.stdin,
buf <- io.fs.read_to_end stdin,
match sexp.from_buffer buf with
| (sum.inl e) := io.fail ("Decode error: " ++ e)
| (sum.inr r) := io.put_str_ln (repr r)
end
-/
|
70cb536fce5c99a941b88277549e9777030237f2 | a9d0fb7b0e4f802bd3857b803e6c5c23d87fef91 | /tests/lean/run/cute_binders.lean | 689ede441b41b51e6c6b026ae6b3c435ae748fdc | [
"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 | 650 | lean | definition set (A : Type) := A → Prop
definition mem {A : Type} (a : A) (s : set A) : Prop :=
s a
definition range (lower : nat) (upper : nat) : set nat :=
λ a, lower ≤ a ∧ a ≤ upper
infix ` ∈ ` := mem
local notation `[` L `, ` U `]` := range L U
variables s : set nat
variables p : nat → nat → Prop
-- check a ∈ s
set_option pp.binder_types true
check ∀ b c a ∈ s, a + b + c > 0
-- ∀ (b c a : ℕ), b ∈ s → c ∈ s → a ∈ s → a + b + c > 0 : Prop
check ∀ a < 5, p a (a+1)
-- ∀ (a : ℕ), a < 5 → p a (a + 1) : Prop
check ∀ a b ∈ [2, 3], p a b
-- ∀ (a b : ℕ), a ∈ [2, 3] → b ∈ [2, 3] → p a b
|
9779c4287943b63d53492480f7c75ab92ad8f0a8 | 7bc35d4fbdda0c01e9b22a949940ee5cbb9800d0 | /equiv.lean | f0e199f8e9d473eff75d529c5ee2cb852ce464fb | [] | no_license | truonghoangle/manifolds | e6c2534dd46579f56ba99a48e2eb7ce51640e7c0 | dcf4815b29ad363ec9712fd00b7756c36cfa7c1c | refs/heads/main | 1,638,501,090,139 | 1,636,918,550,000 | 1,636,918,550,000 | 185,779,631 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 2,277 | lean | import data.equiv.algebra algebra.module data.pfun
import analysis.normed_space.basic
universes u v w
variables {α : Type u} {β : Type v} {γ : Type w}
open equiv
namespace equiv
section instances
variables (e : α ≃ β)
protected def has_scalar [has_scalar γ β] : has_scalar γ α := ⟨λ (a:γ) x, e.symm ( a • e x)⟩
lemma smul_def [has_scalar γ β] (a: γ) (x : α) : @has_scalar.smul _ _ (equiv.has_scalar e) a x = e.symm ( a • e x) := rfl
protected def mul_action [monoid γ][mul_action γ β] : mul_action γ α :=
{ one_smul := by simp [smul_def],
mul_smul := by simp [smul_def, mul_action.mul_smul],
..equiv.has_scalar e }
end instances
end equiv
namespace pfun
protected def empty (α β : Type*) : α →. β := λx, roption.none
protected def id : α →. α := pfun.lift id
protected def comp (g : β →. γ) (f : α →. β) : α →. γ := λx, roption.bind (f x) g
infix ` ∘. `:90 := pfun.comp
def to_subtype (p : α → Prop) : α →. subtype p := λx, ⟨p x, λ h, ⟨x, h⟩⟩
def compatible (f g : α →. β) : Prop := ∀x, f x = g x
namespace compatible
variables {f g h : α →. β}
infix ` ~. `:50 := pfun.compatible
protected lemma symm (h : f ~. g) : g ~. f := λx, (h x).symm
end compatible
end pfun
structure pequiv (α : Type*) (β : Type*) :=
(to_fun : α →. β)
(inv_fun : β →. α)
(dom_inv_fun : ∀{{x}} (hx : x ∈ pfun.dom to_fun), to_fun.fn x hx ∈ pfun.dom inv_fun)
(dom_to_fun : ∀{{y}} (hy : y ∈ pfun.dom inv_fun), inv_fun.fn y hy ∈ pfun.dom to_fun)
(left_inv : inv_fun ∘. to_fun ~. pfun.id)
(right_inv : to_fun ∘. inv_fun ~. pfun.id)
infixr ` ≃. `:25 := pequiv
namespace roption
noncomputable theory
variable [normed_field α]
instance : has_add (roption α) := ⟨ λ x y, ⟨x.dom ∧ y.dom, λ h, x.get (h.1)+ y.get (h.2) ⟩ ⟩
instance : has_zero (roption (α )) :=⟨some (0:α)⟩
instance : has_one (roption (α )) :=⟨some (1:α)⟩
instance : has_mul (roption α) := ⟨ λ x y, ⟨x.dom ∧ y.dom, λ h, x.get (h.1) * y.get (h.2) ⟩ ⟩
instance : has_scalar α (roption α) := ⟨λ a f, ⟨f.dom, λ h, a* (f.get h) ⟩ ⟩
instance : has_neg (roption α) := ⟨ λ x, ⟨x.dom , λ h, -x.get h ⟩ ⟩
end roption
|
3e2d12e7e6782f0face77f13bcbc2a7b547f70a3 | d406927ab5617694ec9ea7001f101b7c9e3d9702 | /src/data/pi/interval.lean | 7388b3bbb69d29d81545993296e9cc9a21e36cc8 | [
"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,518 | lean | /-
Copyright (c) 2021 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import data.finset.locally_finite
import data.fintype.big_operators
/-!
# Intervals in a pi type
This file shows that (dependent) functions to locally finite orders equipped with the pointwise
order are locally finite and calculates the cardinality of their intervals.
-/
open finset fintype
open_locale big_operators
variables {ι : Type*} {α : ι → Type*}
namespace pi
section locally_finite
variables [decidable_eq ι] [fintype ι] [Π i, decidable_eq (α i)]
[Π i, partial_order (α i)] [Π i, locally_finite_order (α i)]
instance : locally_finite_order (Π i, α i) :=
locally_finite_order.of_Icc _
(λ a b, pi_finset $ λ i, Icc (a i) (b i))
(λ a b x, by simp_rw [mem_pi_finset, mem_Icc, le_def, forall_and_distrib])
variables (a b : Π i, α i)
lemma Icc_eq : Icc a b = pi_finset (λ i, Icc (a i) (b i)) := rfl
lemma card_Icc : (Icc a b).card = ∏ i, (Icc (a i) (b i)).card := card_pi_finset _
lemma card_Ico : (Ico a b).card = (∏ i, (Icc (a i) (b i)).card) - 1 :=
by rw [card_Ico_eq_card_Icc_sub_one, card_Icc]
lemma card_Ioc : (Ioc a b).card = (∏ i, (Icc (a i) (b i)).card) - 1 :=
by rw [card_Ioc_eq_card_Icc_sub_one, card_Icc]
lemma card_Ioo : (Ioo a b).card = (∏ i, (Icc (a i) (b i)).card) - 2 :=
by rw [card_Ioo_eq_card_Icc_sub_two, card_Icc]
end locally_finite
section bounded
variables [decidable_eq ι] [fintype ι] [Π i, decidable_eq (α i)] [Π i, partial_order (α i)]
section bot
variables [Π i, locally_finite_order_bot (α i)] (b : Π i, α i)
instance : locally_finite_order_bot (Π i, α i) :=
locally_finite_order_top.of_Iic _
(λ b, pi_finset $ λ i, Iic (b i))
(λ b x, by simp_rw [mem_pi_finset, mem_Iic, le_def])
lemma card_Iic : (Iic b).card = ∏ i, (Iic (b i)).card := card_pi_finset _
lemma card_Iio : (Iio b).card = (∏ i, (Iic (b i)).card) - 1 :=
by rw [card_Iio_eq_card_Iic_sub_one, card_Iic]
end bot
section top
variables [Π i, locally_finite_order_top (α i)] (a : Π i, α i)
instance : locally_finite_order_top (Π i, α i) :=
locally_finite_order_top.of_Ici _
(λ a, pi_finset $ λ i, Ici (a i))
(λ a x, by simp_rw [mem_pi_finset, mem_Ici, le_def])
lemma card_Ici : (Ici a).card = (∏ i, (Ici (a i)).card) := card_pi_finset _
lemma card_Ioi : (Ioi a).card = (∏ i, (Ici (a i)).card) - 1 :=
by rw [card_Ioi_eq_card_Ici_sub_one, card_Ici]
end top
end bounded
end pi
|
3b5e1747444a24f90ca2a1f8dcf0dcb94e5c74aa | ae1e94c332e17c7dc7051ce976d5a9eebe7ab8a5 | /stage0/src/Lean/Structure.lean | 3bae2f87d96289b9d2821985dd245f369654e3fc | [
"Apache-2.0"
] | permissive | dupuisf/lean4 | d082d13b01243e1de29ae680eefb476961221eef | 6a39c65bd28eb0e28c3870188f348c8914502718 | refs/heads/master | 1,676,948,755,391 | 1,610,665,114,000 | 1,610,665,114,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 6,791 | lean | /-
Copyright (c) 2019 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
Helper functions for retrieving structure information.
-/
import Lean.Environment
import Lean.ProjFns
/- TODO: We currently assume that the projection function for field `fieldName` at structure `structName` is
`structName ++ fieldName`. This is incorrect for private projections.
We will fix this by storing a mapping from `structure` + `fieldName` to projection function name in the environment.
This modification will impact functions such as `getStructureFields` and `getProjFnForField?` -/
namespace Lean
/--
Return true iff `constName` is the a non-recursive inductive
datatype that has only one constructor. -/
def isStructureLike (env : Environment) (constName : Name) : Bool :=
match env.find? constName with
| some (ConstantInfo.inductInfo { isRec := false, ctors := [ctor], .. }) => true
| _ => false
/-- We mark subobject fields by prefixing them with "_" in the structure's intro rule. -/
def mkInternalSubobjectFieldName (fieldName : Name) : Name :=
fieldName.appendBefore "_"
def isInternalSubobjectFieldName : Name → Bool
| Name.str _ s _ => s.length > 0 && s.get 0 == '_'
| _ => false
def deinternalizeFieldName : Name → Name
| n@(Name.str p s _) => if s.length > 0 && s.get 0 == '_' then Name.mkStr p (s.drop 1) else n
| n => n
def getStructureCtor (env : Environment) (constName : Name) : ConstructorVal :=
match env.find? constName with
| some (ConstantInfo.inductInfo { nparams := nparams, isRec := false, ctors := [ctorName], .. }) =>
match env.find? ctorName with
| some (ConstantInfo.ctorInfo val) => val
| _ => panic! "ill-formed environment"
| _ => panic! "structure expected"
private def getStructureFieldsAux (nparams : Nat) : Nat → Expr → Array Name → Array Name
| i, Expr.forallE n d b _, fieldNames =>
if i < nparams then
getStructureFieldsAux nparams (i+1) b fieldNames
else
getStructureFieldsAux nparams (i+1) b <| fieldNames.push <| deinternalizeFieldName n
| _, _, fieldNames => fieldNames
-- TODO: fix. See comment in the beginning of the file
def getStructureFields (env : Environment) (structName : Name) : Array Name :=
let ctor := getStructureCtor env structName;
getStructureFieldsAux ctor.nparams 0 ctor.type #[]
private def isSubobjectFieldAux (nparams : Nat) (target : Name) : Nat → Expr → Option Name
| i, Expr.forallE n d b _ =>
if i < nparams then
isSubobjectFieldAux nparams target (i+1) b
else if n == target then
match d.getAppFn with
| Expr.const parentStructName _ _ => some parentStructName
| _ => panic! "ill-formed structure"
else
isSubobjectFieldAux nparams target (i+1) b
| _, _ => none
-- TODO: fix. See comment in the beginning of the file
/-- If `fieldName` represents the relation to a parent structure `S`, return `S` -/
def isSubobjectField? (env : Environment) (structName : Name) (fieldName : Name) : Option Name :=
let ctor := getStructureCtor env structName;
isSubobjectFieldAux ctor.nparams (mkInternalSubobjectFieldName fieldName) 0 ctor.type
/-- Return immediate parent structures -/
def getParentStructures (env : Environment) (structName : Name) : Array Name :=
let fieldNames := getStructureFields env structName;
fieldNames.foldl (init := #[]) fun acc fieldName =>
match isSubobjectField? env structName fieldName with
| some parentStructName => acc.push parentStructName
| none => acc
/-- `findField? env S fname`. If `fname` is defined in a parent `S'` of `S`, return `S'` -/
partial def findField? (env : Environment) (structName : Name) (fieldName : Name) : Option Name :=
if (getStructureFields env structName).contains fieldName then
some structName
else
getParentStructures env structName |>.findSome? fun parentStructName => findField? env parentStructName fieldName
private partial def getStructureFieldsFlattenedAux (env : Environment) (structName : Name) (fullNames : Array Name) : Array Name :=
(getStructureFields env structName).foldl (init := fullNames) fun fullNames fieldName =>
let fullNames := fullNames.push fieldName;
match isSubobjectField? env structName fieldName with
| some parentStructName => getStructureFieldsFlattenedAux env parentStructName fullNames
| none => fullNames
def getStructureFieldsFlattened (env : Environment) (structName : Name) : Array Name :=
getStructureFieldsFlattenedAux env structName #[]
-- TODO: fix. See comment in the beginning of the file
private def hasProjFn (env : Environment) (structName : Name) (nparams : Nat) : Nat → Expr → Bool
| i, Expr.forallE n d b _ =>
if i < nparams then
hasProjFn env structName nparams (i+1) b
else
let fullFieldName := structName ++ deinternalizeFieldName n;
env.isProjectionFn fullFieldName
| _, _ => false
/--
Return true if `constName` is the name of an inductive datatype
created using the `structure` or `class` commands.
We perform the check by testing whether auxiliary projection functions
have been created. -/
def isStructure (env : Environment) (constName : Name) : Bool :=
if isStructureLike env constName then
let ctor := getStructureCtor env constName;
hasProjFn env constName ctor.nparams 0 ctor.type
else
false
-- TODO: fix. See comment in the beginning of the file
def getProjFnForField? (env : Environment) (structName : Name) (fieldName : Name) : Option Name :=
let fieldNames := getStructureFields env structName;
if fieldNames.any fun n => fieldName == n then
some (structName ++ fieldName)
else
none
partial def getPathToBaseStructureAux (env : Environment) (baseStructName : Name) (structName : Name) (path : List Name) : Option (List Name) :=
if baseStructName == structName then
some path.reverse
else
let fieldNames := getStructureFields env structName;
fieldNames.findSome? fun fieldName =>
match isSubobjectField? env structName fieldName with
| none => none
| some parentStructName =>
match getProjFnForField? env structName fieldName with
| none => none
| some projFn => getPathToBaseStructureAux env baseStructName parentStructName (projFn :: path)
/--
If `baseStructName` is an ancestor structure for `structName`, then return a sequence of projection functions
to go from `structName` to `baseStructName`. -/
def getPathToBaseStructure? (env : Environment) (baseStructName : Name) (structName : Name) : Option (List Name) :=
getPathToBaseStructureAux env baseStructName structName []
end Lean
|
44f396671b9e6d4b8ac5b8544ab9040c8070e59f | 302c785c90d40ad3d6be43d33bc6a558354cc2cf | /src/ring_theory/polynomial/dickson.lean | 4bdbca3edc8324ffb8fe87cd39214bdee382bc81 | [
"Apache-2.0"
] | permissive | ilitzroth/mathlib | ea647e67f1fdfd19a0f7bdc5504e8acec6180011 | 5254ef14e3465f6504306132fe3ba9cec9ffff16 | refs/heads/master | 1,680,086,661,182 | 1,617,715,647,000 | 1,617,715,647,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 10,508 | lean | /-
Copyright (c) 2021 Julian Kuelshammer. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Julian Kuelshammer
-/
import ring_theory.polynomial.chebyshev
import ring_theory.localization
import data.zmod.basic
import algebra.char_p.invertible
/-!
# Dickson polynomials
The (generalised) Dickson polynomials are a family of polynomials indexed by `ℕ × ℕ`,
with coefficients in a commutative ring `R` depending on an element `a∈R`. More precisely, the
they satisfy the recursion `dickson k a (n + 2) = X * (dickson k a n + 1) - a * (dickson k a n)`
with starting values `dickson k a 0 = 3 - k` and `dickson k a 1 = X`. In the literature,
`dickson k a n` is called the `n`-th Dickson polynomial of the `k`-th kind associated to the
parameter `a : R`. They are closely related to the Chebyshev polynomials in the case that `a=1`.
When `a=0` they are just the family of monomials `X ^ n`.
## Main definition
* `polynomial.dickson`: the generalised Dickson polynomials.
## Main statements
* `polynomial.dickson_one_one_mul`, the `(m * n)`-th Dickson polynomial of the first kind for
parameter `1 : R` is the composition of the `m`-th and `n`-th Dickson polynomials of the first
kind for `1 : R`.
* `polynomial.dickson_one_one_char_p`, for a prime number `p`, the `p`-th Dickson polynomial of the
first kind associated to parameter `1 : R` is congruent to `X ^ p` modulo `p`.
## References
* [R. Lidl, G. L. Mullen and G. Turnwald, _Dickson polynomials_][MR1237403]
## TODO
* Redefine `dickson` in terms of `linear_recurrence`.
* Show that `dickson 2 1` is equal to the characteristic polynomial of the adjacency matrix of a
type A Dynkin diagram.
* Prove that the adjacency matrices of simply laced Dynkin diagrams are precisely the adjacency
matrices of simple connected graphs which annihilate `dickson 2 1`.
-/
noncomputable theory
namespace polynomial
variables {R S : Type*} [comm_ring R] [comm_ring S] (k : ℕ) (a : R)
/-- `dickson` is the `n`the (generalised) Dickson polynomial of the `k`-th kind associated to the
element `a ∈ R`. -/
noncomputable def dickson : ℕ → polynomial R
| 0 := 3 - k
| 1 := X
| (n + 2) := X * dickson (n + 1) - (C a) * dickson n
@[simp] lemma dickson_zero : dickson k a 0 = 3 - k := rfl
@[simp] lemma dickson_one : dickson k a 1 = X := rfl
lemma dickson_two : dickson k a 2 = X ^ 2 - C a * (3 - k) :=
by simp only [dickson, pow_two]
@[simp] lemma dickson_add_two (n : ℕ) :
dickson k a (n + 2) = X * dickson k a (n + 1) - C a * dickson k a n :=
by rw dickson
lemma dickson_of_two_le {n : ℕ} (h : 2 ≤ n) :
dickson k a n = X * dickson k a (n - 1) - C a * dickson k a (n - 2) :=
begin
obtain ⟨n, rfl⟩ := nat.exists_eq_add_of_le h,
rw add_comm,
exact dickson_add_two k a n
end
variables {R S k a}
lemma map_dickson (f : R →+* S) :
∀ (n : ℕ), map f (dickson k a n) = dickson k (f a) n
| 0 := by simp only [dickson_zero, map_sub, map_nat_cast, bit1, bit0, map_add, map_one]
| 1 := by simp only [dickson_one, map_X]
| (n + 2) :=
begin
simp only [dickson_add_two, map_sub, map_mul, map_X, map_C],
rw [map_dickson, map_dickson]
end
variable {R}
@[simp] lemma dickson_two_zero :
∀ (n : ℕ), dickson 2 (0 : R) n = X ^ n
| 0 := by { simp only [dickson_zero, pow_zero], norm_num }
| 1 := by simp only [dickson_one, pow_one]
| (n + 2) :=
begin
simp only [dickson_add_two, C_0, zero_mul, sub_zero],
rw [dickson_two_zero, pow_add X (n + 1) 1, mul_comm, pow_one]
end
section dickson
/-!
### A Lambda structure on `polynomial ℤ`
Mathlib doesn't currently know what a Lambda ring is.
But once it does, we can endow `polynomial ℤ` with a Lambda structure
in terms of the `dickson 1 1` polynomials defined below.
There is exactly one other Lambda structure on `polynomial ℤ` in terms of binomial polynomials.
-/
variables {R}
lemma dickson_one_one_eval_add_inv (x y : R) (h : x * y = 1) :
∀ n, (dickson 1 (1 : R) n).eval (x + y) = x ^ n + y ^ n
| 0 := by { simp only [bit0, eval_one, eval_add, pow_zero, dickson_zero], norm_num }
| 1 := by simp only [eval_X, dickson_one, pow_one]
| (n + 2) :=
begin
simp only [eval_sub, eval_mul, dickson_one_one_eval_add_inv, eval_X, dickson_add_two, C_1,
eval_one],
conv_lhs { simp only [pow_succ, add_mul, mul_add, h, ← mul_assoc, mul_comm y x, one_mul] },
ring_exp
end
variables (R)
lemma dickson_one_one_eq_chebyshev_T [invertible (2 : R)] :
∀ n, dickson 1 (1 : R) n = 2 * (chebyshev.T R n).comp (C (⅟2) * X)
| 0 := by { simp only [chebyshev.T_zero, mul_one, one_comp, dickson_zero], norm_num }
| 1 := by rw [dickson_one, chebyshev.T_one, X_comp, ← mul_assoc, ← C_1, ← C_bit0, ← C_mul,
mul_inv_of_self, C_1, one_mul]
| (n + 2) :=
begin
simp only [dickson_add_two, chebyshev.T_add_two, dickson_one_one_eq_chebyshev_T (n + 1),
dickson_one_one_eq_chebyshev_T n, sub_comp, mul_comp, add_comp, X_comp, bit0_comp, one_comp],
simp only [← C_1, ← C_bit0, ← mul_assoc, ← C_mul, mul_inv_of_self],
rw [C_1, one_mul],
ring
end
lemma chebyshev_T_eq_dickson_one_one [invertible (2 : R)] (n : ℕ) :
chebyshev.T R n = C (⅟2) * (dickson 1 1 n).comp (2 * X) :=
begin
rw dickson_one_one_eq_chebyshev_T,
simp only [comp_assoc, mul_comp, C_comp, X_comp, ← mul_assoc, ← C_1, ← C_bit0, ← C_mul],
rw [inv_of_mul_self, C_1, one_mul, one_mul, comp_X]
end
/-- The `(m * n)`-th Dickson polynomial of the first kind is the composition of the `m`-th and
`n`-th. -/
lemma dickson_one_one_mul (m n : ℕ) :
dickson 1 (1 : R) (m * n) = (dickson 1 1 m).comp (dickson 1 1 n) :=
begin
have h : (1 : R) = int.cast_ring_hom R (1),
simp only [ring_hom.eq_int_cast, int.cast_one],
rw h,
simp only [← map_dickson (int.cast_ring_hom R), ← map_comp],
congr' 1,
apply map_injective (int.cast_ring_hom ℚ) int.cast_injective,
simp only [map_dickson, map_comp, ring_hom.eq_int_cast, int.cast_one,
dickson_one_one_eq_chebyshev_T, chebyshev.T_mul, two_mul, ← add_comp],
simp only [← two_mul, ← comp_assoc],
apply eval₂_congr rfl rfl,
rw [comp_assoc],
apply eval₂_congr rfl _ rfl,
rw [mul_comp, C_comp, X_comp, ← mul_assoc, ← C_1, ← C_bit0, ← C_mul,
inv_of_mul_self, C_1, one_mul]
end
lemma dickson_one_one_comp_comm (m n : ℕ) :
(dickson 1 (1 : R) m).comp (dickson 1 1 n) = (dickson 1 1 n).comp (dickson 1 1 m) :=
by rw [← dickson_one_one_mul, mul_comm, dickson_one_one_mul]
lemma dickson_one_one_zmod_p (p : ℕ) [fact p.prime] :
dickson 1 (1 : zmod p) p = X ^ p :=
begin
-- Recall that `dickson_eval_add_inv` characterises `dickson 1 1 p`
-- as a polynomial that maps `x + x⁻¹` to `x ^ p + (x⁻¹) ^ p`.
-- Since `X ^ p` also satisfies this property in characteristic `p`,
-- we can use a variant on `polynomial.funext` to conclude that these polynomials are equal.
-- For this argument, we need an arbitrary infinite field of characteristic `p`.
obtain ⟨K, _, _, H⟩ : ∃ (K : Type) [field K], by exactI ∃ [char_p K p], infinite K,
{ let K := fraction_ring (polynomial (zmod p)),
let f : zmod p →+* K := (fraction_ring.of _).to_map.comp C,
haveI : char_p K p := by { rw ← f.char_p_iff_char_p, apply_instance },
haveI : infinite K :=
by { apply infinite.of_injective _ (fraction_ring.of _).injective, apply_instance },
refine ⟨K, _, _, _⟩; apply_instance },
resetI,
apply map_injective (zmod.cast_hom (dvd_refl p) K) (ring_hom.injective _),
rw [map_dickson, map_pow, map_X],
apply eq_of_infinite_eval_eq,
-- The two polynomials agree on all `x` of the form `x = y + y⁻¹`.
apply @set.infinite_mono _ {x : K | ∃ y, x = y + y⁻¹ ∧ y ≠ 0},
{ rintro _ ⟨x, rfl, hx⟩,
simp only [eval_X, eval_pow, set.mem_set_of_eq, @add_pow_char K _ p,
dickson_one_one_eval_add_inv _ _ (mul_inv_cancel hx), inv_pow', zmod.cast_hom_apply,
zmod.cast_one'] },
-- Now we need to show that the set of such `x` is infinite.
-- If the set is finite, then we will show that `K` is also finite.
{ intro h,
rw ← set.infinite_univ_iff at H,
apply H,
-- To each `x` of the form `x = y + y⁻¹`
-- we `bind` the set of `y` that solve the equation `x = y + y⁻¹`.
-- For every `x`, that set is finite (since it is governed by a quadratic equation).
-- For the moment, we claim that all these sets together cover `K`.
suffices : (set.univ : set K) =
{x : K | ∃ (y : K), x = y + y⁻¹ ∧ y ≠ 0} >>= (λ x, {y | x = y + y⁻¹ ∨ y = 0}),
{ rw this, clear this,
apply set.finite_bUnion h,
rintro x hx,
-- The following quadratic polynomial has as solutions the `y` for which `x = y + y⁻¹`.
let φ : polynomial K := X ^ 2 - C x * X + 1,
have hφ : φ ≠ 0,
{ intro H,
have : φ.eval 0 = 0, by rw [H, eval_zero],
simpa [eval_X, eval_one, eval_pow, eval_sub, sub_zero, eval_add,
eval_mul, mul_zero, pow_two, zero_add, one_ne_zero] },
classical,
convert (φ.roots ∪ {0}).to_finset.finite_to_set using 1,
ext1 y,
simp only [multiset.mem_to_finset, set.mem_set_of_eq, finset.mem_coe, multiset.mem_union,
mem_roots hφ, is_root, eval_add, eval_sub, eval_pow, eval_mul, eval_X, eval_C, eval_one,
multiset.mem_singleton, multiset.singleton_eq_singleton],
by_cases hy : y = 0,
{ simp only [hy, eq_self_iff_true, or_true] },
apply or_congr _ iff.rfl,
rw [← mul_left_inj' hy, eq_comm, ← sub_eq_zero, add_mul, inv_mul_cancel hy],
apply eq_iff_eq_cancel_right.mpr,
ring },
-- Finally, we prove the claim that our finite union of finite sets covers all of `K`.
{ apply (set.eq_univ_of_forall _).symm,
intro x,
simp only [exists_prop, set.mem_Union, set.bind_def, ne.def, set.mem_set_of_eq],
by_cases hx : x = 0,
{ simp only [hx, and_true, eq_self_iff_true, inv_zero, or_true],
exact ⟨_, 1, rfl, one_ne_zero⟩ },
{ simp only [hx, or_false, exists_eq_right],
exact ⟨_, rfl, hx⟩ } } }
end
lemma dickson_one_one_char_p (p : ℕ) [fact p.prime] [char_p R p] :
dickson 1 (1 : R) p = X ^ p :=
begin
have h : (1 : R) = zmod.cast_hom (dvd_refl p) R (1),
simp only [zmod.cast_hom_apply, zmod.cast_one'],
rw [h, ← map_dickson (zmod.cast_hom (dvd_refl p) R), dickson_one_one_zmod_p, map_pow, map_X]
end
end dickson
end polynomial
|
27f3ff24cdba8e6804e72ebf7a37e3375e4c192d | aa3f8992ef7806974bc1ffd468baa0c79f4d6643 | /tests/lean/run/record4.lean | 7df0184f7f608b00181ddd048727ee433e53dd19 | [
"Apache-2.0"
] | permissive | codyroux/lean | 7f8dff750722c5382bdd0a9a9275dc4bb2c58dd3 | 0cca265db19f7296531e339192e9b9bae4a31f8b | refs/heads/master | 1,610,909,964,159 | 1,407,084,399,000 | 1,416,857,075,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 308 | lean | import logic data.unit
structure point (A : Type) (B : Type) :=
mk :: (x : A) (y : B)
check point.eta
example (p : point num num) : point.mk (point.x p) (point.y p) = p :=
point.eta p
inductive color :=
red, green, blue
structure color_point (A : Type) (B : Type) extends point A B :=
mk :: (c : color)
|
663e532aa9fe5329432500ef537ab3730fc130bd | cabd1ea95170493667c024ef2045eb86d981b133 | /src/super/defs.lean | 498ace4118cf11effa9923f05c3bf088314065cc | [] | no_license | semorrison/super | 31db4b5aa5ef4c2313dc5803b8c79a95f809815b | 0c6c03ba9c7470f801eb4d055294f424ff090308 | refs/heads/master | 1,630,272,140,541 | 1,511,054,739,000 | 1,511,054,756,000 | 114,317,807 | 0 | 0 | null | 1,513,304,776,000 | 1,513,304,775,000 | null | UTF-8 | Lean | false | false | 1,093 | lean | /-
Copyright (c) 2017 Gabriel Ebner. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Gabriel Ebner
-/
import .clause_ops .prover_state
open tactic expr monad
namespace super
meta def try_unfold_one_def (type : expr) : tactic expr :=
dunfold_head type transparency.all
meta def try_unfold_def_left (c : clause) (i : ℕ) : tactic (list clause) :=
on_left_at c i $ λt, do
t' ← try_unfold_one_def t,
ht' ← mk_local_def `h t',
return [([ht'], ht')]
meta def try_unfold_def_right (c : clause) (i : ℕ) : tactic (list clause) :=
on_right_at c i $ λh, do
t' ← try_unfold_one_def h.local_type,
hnt' ← mk_local_def `h (imp t' c.local_false),
return [([hnt'], app hnt' h)]
@[super.inf]
meta def unfold_def_inf : inf_decl := inf_decl.mk 40 $ assume given, sequence' $ do
r ← [try_unfold_def_right, try_unfold_def_left],
-- NOTE: we cannot restrict to selected literals here
-- as this might prevent factoring, e.g. _n>0_ ∨ is_pos(0)
i ← list.range given.c.num_lits,
[inf_if_successful 3 given (r given.c i)]
end super
|
695b1156ab8e410e4dc8cd0a25a75daeec5c2bd7 | ad0c7d243dc1bd563419e2767ed42fb323d7beea | /category/functor.lean | ebf597cd6507becb881adcc1c999567a9841d9a6 | [
"Apache-2.0"
] | permissive | sebzim4500/mathlib | e0b5a63b1655f910dee30badf09bd7e191d3cf30 | 6997cafbd3a7325af5cb318561768c316ceb7757 | refs/heads/master | 1,585,549,958,618 | 1,538,221,723,000 | 1,538,221,723,000 | 150,869,076 | 0 | 0 | Apache-2.0 | 1,538,229,323,000 | 1,538,229,323,000 | null | UTF-8 | Lean | false | false | 3,734 | lean | /-
Copyright (c) 2017 Simon Hudon. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Simon Hudon
Standard identity and composition functors
-/
import tactic.ext tactic.cache category.basic
universe variables u v w
section functor
variables {F : Type u → Type v}
variables {α β γ : Type u}
variables [functor F] [is_lawful_functor F]
lemma functor.map_id : (<$>) id = (id : F α → F α) :=
by apply funext; apply id_map
lemma functor.map_comp_map (f : α → β) (g : β → γ) :
((<$>) g ∘ (<$>) f : F α → F γ) = (<$>) (g ∘ f) :=
by apply funext; intro; rw comp_map
theorem functor.ext {F} : ∀ {F1 : functor F} {F2 : functor F}
[@is_lawful_functor F F1] [@is_lawful_functor F F2]
(H : ∀ α β (f : α → β) (x : F α),
@functor.map _ F1 _ _ f x = @functor.map _ F2 _ _ f x),
F1 = F2
| ⟨m, mc⟩ ⟨m', mc'⟩ H1 H2 H :=
begin
cases show @m = @m', by funext α β f x; apply H,
congr, funext α β,
have E1 := @map_const_eq _ ⟨@m, @mc⟩ H1,
have E2 := @map_const_eq _ ⟨@m, @mc'⟩ H2,
exact E1.trans E2.symm
end
end functor
def id.mk {α : Sort u} : α → id α := id
namespace functor
/-- `functor.comp` is a wrapper around `function.comp` for types.
It prevents Lean's type class resolution mechanism from trying
a `functor (comp F id)` when `functor F` would do. -/
def comp (F : Type u → Type w) (G : Type v → Type u) (α : Type v) : Type w :=
F $ G α
@[pattern] def comp.mk {F : Type u → Type w} {G : Type v → Type u} {α : Type v}
(x : F (G α)) : comp F G α := x
def comp.run {F : Type u → Type w} {G : Type v → Type u} {α : Type v}
(x : comp F G α) : F (G α) := x
namespace comp
variables {F : Type u → Type w} {G : Type v → Type u}
protected lemma ext
{α} {x y : comp F G α} : x.run = y.run → x = y := id
variables [functor F] [functor G]
protected def map {α β : Type v} (h : α → β) : comp F G α → comp F G β
| (comp.mk x) := comp.mk ((<$>) h <$> x)
instance : functor (comp F G) := { map := @comp.map F G _ _ }
@[functor_norm] lemma map_mk {α β} (h : α → β) (x : F (G α)) :
h <$> comp.mk x = comp.mk ((<$>) h <$> x) := rfl
variables [is_lawful_functor F] [is_lawful_functor G]
variables {α β γ : Type v}
protected lemma id_map : ∀ (x : comp F G α), comp.map id x = x
| (comp.mk x) := by simp [comp.map, functor.map_id]
protected lemma comp_map (g' : α → β) (h : β → γ) : ∀ (x : comp F G α),
comp.map (h ∘ g') x = comp.map h (comp.map g' x)
| (comp.mk x) := by simp [comp.map, functor.map_comp_map g' h] with functor_norm
@[simp] protected lemma run_map (h : α → β) (x : comp F G α) :
(h <$> x).run = (<$>) h <$> x.run := rfl
instance : is_lawful_functor (comp F G) :=
{ id_map := @comp.id_map F G _ _ _ _,
comp_map := @comp.comp_map F G _ _ _ _ }
theorem functor_comp_id {F} [AF : functor F] [is_lawful_functor F] :
@comp.functor F id _ _ = AF :=
@functor.ext F _ AF (@comp.is_lawful_functor F id _ _ _ _) _ (λ α β f x, rfl)
theorem functor_id_comp {F} [AF : functor F] [is_lawful_functor F] :
@comp.functor id F _ _ = AF :=
@functor.ext F _ AF (@comp.is_lawful_functor id F _ _ _ _) _ (λ α β f x, rfl)
end comp
end functor
namespace ulift
instance : functor ulift :=
{ map := λ α β f, up ∘ f ∘ down }
end ulift
namespace sum
variables {γ : Type u} {α β : Type v}
protected def mapr (f : α → β) : γ ⊕ α → γ ⊕ β
| (inl x) := inl x
| (inr x) := inr (f x)
instance : functor (sum.{u v} γ) :=
{ map := @sum.mapr γ }
instance : is_lawful_functor (sum γ) :=
{ id_map := by intros; casesm _ ⊕ _; refl,
comp_map := by intros; casesm _ ⊕ _; refl }
end sum
|
860bfd64dd3eadb9bebdfe9d14b08a40a8de1ef9 | e0f9ba56b7fedc16ef8697f6caeef5898b435143 | /src/ring_theory/euclidean_domain.lean | d098c655931081b3053d37608d2c69688c2bc6e5 | [
"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 | 1,861 | lean | /-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Chris Hughes
-/
import ring_theory.ideals
noncomputable theory
open_locale classical
open euclidean_domain set ideal
theorem span_gcd {α} [euclidean_domain α] (x y : α) :
span ({gcd x y} : set α) = span ({x, y} : set α) :=
begin
apply le_antisymm; refine span_le.1 _,
{ simp [submodule.span_span, mem_span_pair, submodule.le_def', mem_span_singleton'],
assume a b ha,
exact ⟨b * gcd_a x y, b * gcd_b x y, by rw [← ha, gcd_eq_gcd_ab x y];
simp [mul_add, mul_comm, mul_left_comm]⟩ },
{ assume z ,
simp [mem_span_singleton, euclidean_domain.gcd_dvd_left, mem_span_pair,
@eq_comm _ _ z] {contextual := tt},
assume a b h,
exact dvd_add (dvd_mul_of_dvd_right (gcd_dvd_left _ _) _)
(dvd_mul_of_dvd_right (gcd_dvd_right _ _) _) }
end
theorem gcd_is_unit_iff {α} [euclidean_domain α] {x y : α} :
is_unit (gcd x y) ↔ is_coprime x y :=
by rw [← span_singleton_eq_top, span_gcd, is_coprime]
theorem is_coprime_of_dvd {α} [euclidean_domain α] {x y : α}
(z : ¬ (x = 0 ∧ y = 0)) (H : ∀ z ∈ nonunits α, z ≠ 0 → z ∣ x → ¬ z ∣ y) :
is_coprime x y :=
begin
rw [← gcd_is_unit_iff],
by_contra h,
refine H _ h _ (gcd_dvd_left _ _) (gcd_dvd_right _ _),
rwa [ne, euclidean_domain.gcd_eq_zero_iff]
end
theorem dvd_or_coprime {α} [euclidean_domain α] (x y : α)
(h : irreducible x) : x ∣ y ∨ is_coprime x y :=
begin
refine or_iff_not_imp_left.2 (λ h', _),
unfreezeI, apply is_coprime_of_dvd,
{ rintro ⟨rfl, rfl⟩, simpa using h },
{ rintro z nu nz ⟨w, rfl⟩ dy,
refine h' (dvd.trans _ dy),
simpa using mul_dvd_mul_left z (is_unit_iff_dvd_one.1 $
(of_irreducible_mul h).resolve_left nu) }
end
|
707215ba19e83ab2a70f91c18bb684199f6fc819 | e00ea76a720126cf9f6d732ad6216b5b824d20a7 | /src/linear_algebra/determinant.lean | 06528aa0e7d4879214656f97d26419bc7d30ff46 | [
"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 | 9,321 | lean | /-
Copyright (c) 2018 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau, Chris Hughes, Tim Baanen
-/
import data.matrix.basic
import data.matrix.pequiv
import data.fintype.card
import group_theory.perm.sign
import tactic.ring
universes u v
open equiv equiv.perm finset function
namespace matrix
open_locale matrix
variables {n : Type u} [fintype n] [decidable_eq n] {R : Type v} [comm_ring R]
local notation `ε` σ:max := ((sign σ : ℤ ) : R)
/-- The determinant of a matrix given by the Leibniz formula. -/
definition det (M : matrix n n R) : R :=
univ.sum (λ (σ : perm n), ε σ * univ.prod (λ i, M (σ i) i))
@[simp] lemma det_diagonal {d : n → R} : det (diagonal d) = univ.prod d :=
begin
refine (finset.sum_eq_single 1 _ _).trans _,
{ intros σ h1 h2,
cases not_forall.1 (mt (equiv.ext _ _) h2) with x h3,
convert ring.mul_zero _,
apply finset.prod_eq_zero,
{ change x ∈ _, simp },
exact if_neg h3 },
{ simp },
{ simp }
end
@[simp] lemma det_zero (h : nonempty n) : det (0 : matrix n n R) = 0 :=
by rw [← diagonal_zero, det_diagonal, finset.prod_const, ← fintype.card,
zero_pow (fintype.card_pos_iff.2 h)]
@[simp] lemma det_one : det (1 : matrix n n R) = 1 :=
by rw [← diagonal_one]; simp [-diagonal_one]
lemma det_eq_one_of_card_eq_zero {A : matrix n n R} (h : fintype.card n = 0) : det A = 1 :=
begin
have perm_eq : (univ : finset (perm n)) = finset.singleton 1 :=
univ_eq_singleton_of_card_one (1 : perm n) (by simp [card_univ, fintype.card_perm, h]),
simp [det, card_eq_zero.mp h, perm_eq],
end
lemma det_mul_aux {M N : matrix n n R} {p : n → n} (H : ¬bijective p) :
univ.sum (λ σ : perm n, (ε σ) * (univ.prod (λ x, M (σ x) (p x) * N (p x) x))) = 0 :=
begin
obtain ⟨i, j, hpij, hij⟩ : ∃ i j, p i = p j ∧ i ≠ j,
{ rw [← fintype.injective_iff_bijective, injective] at H,
push_neg at H,
exact H },
exact sum_involution
(λ σ _, σ * swap i j)
(λ σ _,
have ∀ a, p (swap i j a) = p a := λ a, by simp only [swap_apply_def]; split_ifs; cc,
have univ.prod (λ x, M (σ x) (p x)) = univ.prod (λ x, M ((σ * swap i j) x) (p x)),
from prod_bij (λ a _, swap i j a) (λ _ _, mem_univ _) (by simp [this])
(λ _ _ _ _ h, (swap i j).injective h)
(λ b _, ⟨swap i j b, mem_univ _, by simp⟩),
by simp [sign_mul, this, sign_swap hij, prod_mul_distrib])
(λ σ _ _ h, hij (σ.injective $ by conv {to_lhs, rw ← h}; simp))
(λ _ _, mem_univ _)
(λ _ _, equiv.ext _ _ $ by simp)
end
@[simp] lemma det_mul (M N : matrix n n R) : det (M ⬝ N) = det M * det N :=
calc det (M ⬝ N) = univ.sum (λ σ : perm n, (univ.pi (λ a, univ)).sum
(λ (p : Π (a : n), a ∈ univ → n), ε σ *
univ.attach.prod (λ i, M (σ i.1) (p i.1 (mem_univ _)) * N (p i.1 (mem_univ _)) i.1))) :
by simp only [det, mul_val, prod_sum, mul_sum]
... = univ.sum (λ σ : perm n, univ.sum
(λ p : n → n, ε σ * univ.prod (λ i, M (σ i) (p i) * N (p i) i))) :
sum_congr rfl (λ σ _, sum_bij
(λ f h i, f i (mem_univ _)) (λ _ _, mem_univ _)
(by simp) (by simp [funext_iff]) (λ b _, ⟨λ i hi, b i, by simp⟩))
... = univ.sum (λ p : n → n, univ.sum
(λ σ : perm n, ε σ * univ.prod (λ i, M (σ i) (p i) * N (p i) i))) :
finset.sum_comm
... = ((@univ (n → n) _).filter bijective).sum (λ p : n → n, univ.sum
(λ σ : perm n, ε σ * univ.prod (λ i, M (σ i) (p i) * N (p i) i))) :
eq.symm $ sum_subset (filter_subset _)
(λ f _ hbij, det_mul_aux $ by simpa using hbij)
... = (@univ (perm n) _).sum (λ τ, univ.sum
(λ σ : perm n, ε σ * univ.prod (λ i, M (σ i) (τ i) * N (τ i) i))) :
sum_bij (λ p h, equiv.of_bijective (mem_filter.1 h).2) (λ _ _, mem_univ _)
(λ _ _, rfl) (λ _ _ _ _ h, by injection h)
(λ b _, ⟨b, mem_filter.2 ⟨mem_univ _, b.bijective⟩, eq_of_to_fun_eq rfl⟩)
... = univ.sum (λ σ : perm n, univ.sum (λ τ : perm n,
(univ.prod (λ i, N (σ i) i) * ε τ) * univ.prod (λ j, M (τ j) (σ j)))) :
by simp [mul_sum, det, mul_comm, mul_left_comm, prod_mul_distrib, mul_assoc]
... = univ.sum (λ σ : perm n, univ.sum (λ τ : perm n,
(univ.prod (λ i, N (σ i) i) * (ε σ * ε τ)) *
univ.prod (λ i, M (τ i) i))) :
sum_congr rfl (λ σ _, sum_bij (λ τ _, τ * σ⁻¹) (λ _ _, mem_univ _)
(λ τ _,
have univ.prod (λ j, M (τ j) (σ j)) = univ.prod (λ j, M ((τ * σ⁻¹) j) j),
by rw prod_univ_perm σ⁻¹; simp [mul_apply],
have h : ε σ * ε (τ * σ⁻¹) = ε τ :=
calc ε σ * ε (τ * σ⁻¹) = ε ((τ * σ⁻¹) * σ) :
by rw [mul_comm, sign_mul (τ * σ⁻¹)]; simp [sign_mul]
... = ε τ : by simp,
by rw h; simp [this, mul_comm, mul_assoc, mul_left_comm])
(λ _ _ _ _, (mul_right_inj _).1) (λ τ _, ⟨τ * σ, by simp⟩))
... = det M * det N : by simp [det, mul_assoc, mul_sum, mul_comm, mul_left_comm]
instance : is_monoid_hom (det : matrix n n R → R) :=
{ map_one := det_one,
map_mul := det_mul }
/-- Transposing a matrix preserves the determinant. -/
@[simp] lemma det_transpose (M : matrix n n R) : Mᵀ.det = M.det :=
begin
apply sum_bij (λ σ _, σ⁻¹),
{ intros σ _, apply mem_univ },
{ intros σ _,
rw [sign_inv],
congr' 1,
apply prod_bij (λ i _, σ i),
{ intros i _, apply mem_univ },
{ intros i _, simp },
{ intros i j _ _ h, simp at h, assumption },
{ intros i _, use σ⁻¹ i, finish } },
{ intros σ σ' _ _ h, simp at h, assumption },
{ intros σ _, use σ⁻¹, finish }
end
/-- The determinant of a permutation matrix equals its sign. -/
@[simp] lemma det_permutation (σ : perm n) :
matrix.det (σ.to_pequiv.to_matrix : matrix n n R) = σ.sign := begin
suffices : matrix.det (σ.to_pequiv.to_matrix) = ↑σ.sign * det (1 : matrix n n R), { simp [this] },
unfold det,
rw mul_sum,
apply sum_bij (λ τ _, σ * τ),
{ intros τ _, apply mem_univ },
{ intros τ _,
conv_lhs { rw [←one_mul (sign τ), ←int.units_pow_two (sign σ)] },
conv_rhs { rw [←mul_assoc, coe_coe, sign_mul, units.coe_mul, int.cast_mul, ←mul_assoc] },
congr,
{ simp [pow_two] },
{ ext i, apply pequiv.equiv_to_pequiv_to_matrix } },
{ intros τ τ' _ _, exact (mul_left_inj σ).mp },
{ intros τ _, use σ⁻¹ * τ, use (mem_univ _), exact (mul_inv_cancel_left _ _).symm }
end
/-- Permuting the columns changes the sign of the determinant. -/
lemma det_permute (σ : perm n) (M : matrix n n R) : matrix.det (λ i, M (σ i)) = σ.sign * M.det :=
by rw [←det_permutation, ←det_mul, pequiv.to_pequiv_mul_matrix]
@[simp] lemma det_smul {A : matrix n n R} {c : R} : det (c • A) = c ^ fintype.card n * det A :=
calc det (c • A) = det (matrix.mul (diagonal (λ _, c)) A) : by rw [smul_eq_diagonal_mul]
... = det (diagonal (λ _, c)) * det A : det_mul _ _
... = c ^ fintype.card n * det A : by simp [card_univ]
section det_zero
/-! ### `det_zero` section
Prove that a matrix with a repeated column has determinant equal to zero.
-/
lemma det_eq_zero_of_column_eq_zero {A : matrix n n R} (i : n) (h : ∀ j, A i j = 0) : det A = 0 :=
begin
rw [←det_transpose, det],
convert @sum_const_zero _ _ (univ : finset (perm n)) _,
ext σ,
convert mul_zero ↑(sign σ),
apply prod_eq_zero (mem_univ i),
rw [transpose_val],
apply h
end
/--
`mod_swap i j` contains permutations up to swapping `i` and `j`.
We use this to partition permutations in the expression for the determinant,
such that each partitions sums up to `0`.
-/
def mod_swap {n : Type u} [decidable_eq n] (i j : n) : setoid (perm n) :=
⟨ λ σ τ, σ = τ ∨ σ = swap i j * τ,
λ σ, or.inl (refl σ),
λ σ τ h, or.cases_on h (λ h, or.inl h.symm) (λ h, or.inr (by rw [h, swap_mul_self_mul])),
λ σ τ υ hστ hτυ, by cases hστ; cases hτυ; try {rw [hστ, hτυ, swap_mul_self_mul]}; finish⟩
instance (i j : n) : decidable_rel (mod_swap i j).r := λ σ τ, or.decidable
variables {M : matrix n n R} {i j : n}
/-- If a matrix has a repeated column, the determinant will be zero. -/
theorem det_zero_of_column_eq (i_ne_j : i ≠ j) (hij : M i = M j) : M.det = 0 :=
begin
have swap_invariant : ∀ k, M (swap i j k) = M k,
{ intros k,
rw [swap_apply_def],
by_cases k = i, { rw [if_pos h, h, ←hij] },
rw [if_neg h],
by_cases k = j, { rw [if_pos h, h, hij] },
rw [if_neg h] },
have : ∀ σ, _root_.disjoint (_root_.singleton σ) (_root_.singleton (swap i j * σ)),
{ intros σ,
rw [finset.singleton_eq_singleton, finset.singleton_eq_singleton, disjoint_singleton],
apply (not_congr mem_singleton).mpr,
exact (not_congr swap_mul_eq_iff).mpr i_ne_j },
apply finset.sum_cancels_of_partition_cancels (mod_swap i j),
intros σ _,
erw [filter_or, filter_eq', filter_eq', if_pos (mem_univ σ), if_pos (mem_univ (swap i j * σ)),
sum_union (this σ), sum_singleton, sum_singleton],
convert add_right_neg (↑↑(sign σ) * finset.prod univ (λ (i : n), M (σ i) i)),
rw [neg_mul_eq_neg_mul],
congr,
{ rw [sign_mul, sign_swap i_ne_j], norm_num },
ext j, rw [mul_apply, swap_invariant]
end
end det_zero
end matrix
|
5cc33d96c8f36fdda5233e25c8707e54bc8dc052 | 38ee9024fb5974f555fb578fcf5a5a7b71e669b5 | /Mathlib/Tactic/RunTac.lean | 550ca0f9dc3710976f91bc7551c60d493b6d00ce | [
"Apache-2.0"
] | permissive | denayd/mathlib4 | 750e0dcd106554640a1ac701e51517501a574715 | 7f40a5c514066801ab3c6d431e9f405baa9b9c58 | refs/heads/master | 1,693,743,991,894 | 1,636,618,048,000 | 1,636,618,048,000 | 373,926,241 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 986 | lean | /-
Copyright (c) 2018 Sebastian Ullrich. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Sebastian Ullrich
-/
import Lean.Elab.SyntheticMVars
open Lean Elab Tactic
unsafe def evalRunTacUnsafe (term : Syntax) : TacticM Unit := do
let n := `_runTac
let type := mkApp (mkConst ``TacticM) (mkConst ``Unit)
let e ← Term.elabTermEnsuringType term type
let e ← Meta.instantiateMVars e
Term.synthesizeSyntheticMVarsNoPostponing
let decl := Declaration.defnDecl {
name := n
levelParams := []
type := type
value := e
hints := ReducibilityHints.opaque
safety := DefinitionSafety.safe
}
Term.ensureNoUnassignedMVars decl
let env ← getEnv
let tac ← try
addAndCompile decl
evalConst (TacticM Unit) n
finally
setEnv env
tac
@[implementedBy evalRunTacUnsafe]
constant evalRunTac : Syntax → TacticM Unit
elab "runTac" e:term : tactic => evalRunTac e
|
2a2a72b893ac9f18c1ca1e5482ccbc5027b200df | ae1e94c332e17c7dc7051ce976d5a9eebe7ab8a5 | /tests/lean/run/coeIssue1.lean | 1e2c31b5775bf92da9a6d3a3aaa8aa30604b2ad4 | [
"Apache-2.0"
] | permissive | dupuisf/lean4 | d082d13b01243e1de29ae680eefb476961221eef | 6a39c65bd28eb0e28c3870188f348c8914502718 | refs/heads/master | 1,676,948,755,391 | 1,610,665,114,000 | 1,610,665,114,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 1,270 | lean | -- From @joehendrix
-- The imul doesn't type check as Lean won't try to coerce from a reg (bv 64) to a expr (bv ?u)
inductive MCType
| bv : Nat → MCType
open MCType
inductive Reg : MCType → Type
| rax (n : Nat) : Reg (bv n)
inductive Expr : MCType → Type
| r : ∀{tp:MCType}, Reg tp → Expr tp
| sextC {s:Nat} (x : Expr (bv s)) (t:Nat) : Expr (bv t)
instance reg_is_expr {tp:MCType} : Coe (Reg tp) (Expr tp) := ⟨Expr.r⟩
def bvmul {w:Nat} (x y : Expr (bv w)) : Expr (bv w) := x
/-
Remark: Joe's original example used the following definition.
```
def sext {s:Nat} (x : Expr (bv s)) (t:Nat) : Expr (bv t) := Expr.sextC x t
```
This definition is bad because the parameter `s` is unconstrained.
Type class resolution gets stuck at
```
CoeT (Reg (bv 64)) (Reg.rax 64) (Expr (bv ?m_1))
```
It would have to set `?m_1 := 64` which is not allowed since TC should
not change external TC metavariables.
I fixed the problem by changing the definition. Now,
type inference will enforce that `?m_1` must be 64, and TC will be able
to synthesize the instance.
-/
def sext {s:Nat} (x : Expr (bv s)) (n:Nat) : Expr (bv (s+n)) := Expr.sextC x (s+n)
open MCType
variables {u:Nat} (e : Expr (bv 64))
#check (bvmul (sext (Reg.rax 64) 64) (sext e 64) : Expr (bv 128))
|
014c9f45b750fd7b35eed0b50b32e002070adcc1 | 271e26e338b0c14544a889c31c30b39c989f2e0f | /src/Init/Data/BinomialHeap/Basic.lean | dd8b2305d88adfb58f5ff8411299ddb8165c90da | [
"Apache-2.0"
] | permissive | dgorokho/lean4 | 805f99b0b60c545b64ac34ab8237a8504f89d7d4 | e949a052bad59b1c7b54a82d24d516a656487d8a | refs/heads/master | 1,607,061,363,851 | 1,578,006,086,000 | 1,578,006,086,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 5,161 | lean | /-
Copyright (c) 2019 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
prelude
import Init.Data.List
import Init.Coe
universes u
namespace BinomialHeapImp
structure HeapNodeAux (α : Type u) (h : Type u) :=
(val : α) (rank : Nat) (children : List h)
inductive Heap (α : Type u) : Type u
| empty {} : Heap
| heap (ns : List (HeapNodeAux α Heap)) : Heap
abbrev HeapNode (α) := HeapNodeAux α (Heap α)
variables {α : Type u}
instance : Inhabited (Heap α) := ⟨Heap.empty⟩
def hRank : List (HeapNode α) → Nat
| [] => 0
| h::_ => h.rank
def isEmpty : Heap α → Bool
| Heap.empty => true
| _ => false
def singleton (a : α) : Heap α :=
Heap.heap [{ val := a, rank := 1, children := [] }]
@[specialize] def combine (lt : α → α → Bool) (n₁ n₂ : HeapNode α) : HeapNode α :=
if lt n₂.val n₁.val then
{ rank := n₂.rank + 1, children := n₂.children ++ [Heap.heap [n₁]], .. n₂ }
else
{ rank := n₁.rank + 1, children := n₁.children ++ [Heap.heap [n₂]], .. n₁ }
@[specialize] partial def mergeNodes (lt : α → α → Bool) : List (HeapNode α) → List (HeapNode α) → List (HeapNode α)
| [], h => h
| h, [] => h
| f@(h₁ :: t₁), s@(h₂ :: t₂) =>
if h₁.rank < h₂.rank then h₁ :: mergeNodes t₁ s
else if h₂.rank < h₁.rank then h₂ :: mergeNodes t₂ f
else
let merged := combine lt h₁ h₂;
let r := merged.rank;
if r != hRank t₁ then
if r != hRank t₂ then merged :: mergeNodes t₁ t₂ else mergeNodes (merged :: t₁) t₂
else
if r != hRank t₂ then mergeNodes t₁ (merged :: t₂) else merged :: mergeNodes t₁ t₂
@[specialize] def merge (lt : α → α → Bool) : Heap α → Heap α → Heap α
| Heap.empty, h => h
| h, Heap.empty => h
| Heap.heap h₁, Heap.heap h₂ => Heap.heap (mergeNodes lt h₁ h₂)
@[specialize] def head? (lt : α → α → Bool) : Heap α → Option α
| Heap.empty => none
| Heap.heap h => h.foldl
(fun r n => match r with
| none => n.val
| some v => if lt v n.val then v else n.val) none
/- O(log n) -/
@[specialize] def head [Inhabited α] (lt : α → α → Bool) : Heap α → α
| Heap.empty => arbitrary α
| Heap.heap [] => arbitrary α
| Heap.heap (h::hs) => hs.foldl (fun r n => if lt r n.val then r else n.val) h.val
@[specialize] def findMin (lt : α → α → Bool) : List (HeapNode α) → Nat → HeapNode α × Nat → HeapNode α × Nat
| [], _, r => r
| h::hs, idx, (h', idx') => if lt h.val h'.val then findMin hs (idx+1) (h, idx) else findMin hs (idx+1) (h', idx')
def tail (lt : α → α → Bool) : Heap α → Heap α
| Heap.empty => Heap.empty
| Heap.heap [] => Heap.empty
| Heap.heap [h] =>
match h.children with
| [] => Heap.empty
| (h::hs) => hs.foldl (merge lt) h
| Heap.heap hhs@(h::hs) =>
let (min, minIdx) := findMin lt hs 1 (h, 0);
let rest := hhs.eraseIdx minIdx;
min.children.foldl (merge lt) (Heap.heap rest)
partial def toList (lt : α → α → Bool) : Heap α → List α
| Heap.empty => []
| h => match head? lt h with
| none => []
| some a => a :: toList (tail lt h)
inductive WellFormed (lt : α → α → Bool) : Heap α → Prop
| emptyWff : WellFormed Heap.empty
| singletonWff (a : α) : WellFormed (singleton a)
| mergeWff (h₁ h₂ : Heap α) : WellFormed h₁ → WellFormed h₂ → WellFormed (merge lt h₁ h₂)
| tailWff (h : Heap α) : WellFormed h → WellFormed (tail lt h)
end BinomialHeapImp
open BinomialHeapImp
def BinomialHeap (α : Type u) (lt : α → α → Bool) := { h : Heap α // WellFormed lt h }
@[inline] def mkBinomialHeap (α : Type u) (lt : α → α → Bool) : BinomialHeap α lt :=
⟨Heap.empty, WellFormed.emptyWff lt⟩
namespace BinomialHeap
variables {α : Type u} {lt : α → α → Bool}
@[inline] def empty : BinomialHeap α lt :=
mkBinomialHeap α lt
@[inline] def isEmpty : BinomialHeap α lt → Bool
| ⟨b, _⟩ => BinomialHeapImp.isEmpty b
/- O(1) -/
@[inline] def singleton (a : α) : BinomialHeap α lt :=
⟨BinomialHeapImp.singleton a, WellFormed.singletonWff lt a⟩
/- O(log n) -/
@[inline] def merge : BinomialHeap α lt → BinomialHeap α lt → BinomialHeap α lt
| ⟨b₁, h₁⟩, ⟨b₂, h₂⟩ => ⟨BinomialHeapImp.merge lt b₁ b₂, WellFormed.mergeWff b₁ b₂ h₁ h₂⟩
/- O(log n) -/
@[inline] def head [Inhabited α] : BinomialHeap α lt → α
| ⟨b, _⟩ => BinomialHeapImp.head lt b
/- O(log n) -/
@[inline] def head? : BinomialHeap α lt → Option α
| ⟨b, _⟩ => BinomialHeapImp.head? lt b
/- O(log n) -/
@[inline] def tail : BinomialHeap α lt → BinomialHeap α lt
| ⟨b, h⟩ => ⟨BinomialHeapImp.tail lt b, WellFormed.tailWff b h⟩
/- O(log n) -/
@[inline] def insert (a : α) (h : BinomialHeap α lt) : BinomialHeap α lt :=
merge (singleton a) h
/- O(n log n) -/
@[inline] def toList : BinomialHeap α lt → List α
| ⟨b, _⟩ => BinomialHeapImp.toList lt b
end BinomialHeap
|
a695e0294e7f40a9e391147e455b3a00d96cc7a3 | c777c32c8e484e195053731103c5e52af26a25d1 | /src/algebra/module/localized_module.lean | 8941bab7c10a4bba6bfebda4d3895a7a4595f695 | [
"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 | 41,224 | lean | /-
Copyright (c) 2022 Jujian Zhang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Andrew Yang, Jujian Zhang
-/
import group_theory.monoid_localization
import ring_theory.localization.basic
import algebra.algebra.restrict_scalars
/-!
# Localized Module
Given a commutative ring `R`, a multiplicative subset `S ⊆ R` and an `R`-module `M`, we can localize
`M` by `S`. This gives us a `localization S`-module.
## Main definitions
* `localized_module.r` : the equivalence relation defining this localization, namely
`(m, s) ≈ (m', s')` if and only if if there is some `u : S` such that `u • s' • m = u • s • m'`.
* `localized_module M S` : the localized module by `S`.
* `localized_module.mk` : the canonical map sending `(m, s) : M × S ↦ m/s : localized_module M S`
* `localized_module.lift_on` : any well defined function `f : M × S → α` respecting `r` descents to
a function `localized_module M S → α`
* `localized_module.lift_on₂` : any well defined function `f : M × S → M × S → α` respecting `r`
descents to a function `localized_module M S → localized_module M S`
* `localized_module.mk_add_mk` : in the localized module
`mk m s + mk m' s' = mk (s' • m + s • m') (s * s')`
* `localized_module.mk_smul_mk` : in the localized module, for any `r : R`, `s t : S`, `m : M`,
we have `mk r s • mk m t = mk (r • m) (s * t)` where `mk r s : localization S` is localized ring
by `S`.
* `localized_module.is_module` : `localized_module M S` is a `localization S`-module.
## Future work
* Redefine `localization` for monoids and rings to coincide with `localized_module`.
-/
namespace localized_module
universes u v
variables {R : Type u} [comm_semiring R] (S : submonoid R)
variables (M : Type v) [add_comm_monoid M] [module R M]
/--The equivalence relation on `M × S` where `(m1, s1) ≈ (m2, s2)` if and only if
for some (u : S), u * (s2 • m1 - s1 • m2) = 0-/
def r (a b : M × S) : Prop :=
∃ (u : S), u • b.2 • a.1 = u • a.2 • b.1
lemma r.is_equiv : is_equiv _ (r S M) :=
{ refl := λ ⟨m, s⟩, ⟨1, by rw [one_smul]⟩,
trans := λ ⟨m1, s1⟩ ⟨m2, s2⟩ ⟨m3, s3⟩ ⟨u1, hu1⟩ ⟨u2, hu2⟩, begin
use u1 * u2 * s2,
-- Put everything in the same shape, sorting the terms using `simp`
have hu1' := congr_arg ((•) (u2 * s3)) hu1.symm,
have hu2' := congr_arg ((•) (u1 * s1)) hu2.symm,
simp only [← mul_smul, smul_assoc, mul_assoc, mul_comm, mul_left_comm] at ⊢ hu1' hu2',
rw [hu2', hu1']
end,
symm := λ ⟨m1, s1⟩ ⟨m2, s2⟩ ⟨u, hu⟩, ⟨u, hu.symm⟩ }
instance r.setoid : setoid (M × S) :=
{ r := r S M,
iseqv := ⟨(r.is_equiv S M).refl, (r.is_equiv S M).symm, (r.is_equiv S M).trans⟩ }
-- TODO: change `localization` to use `r'` instead of `r` so that the two types are also defeq,
-- `localization S = localized_module S R`.
example {R} [comm_semiring R] (S : submonoid R) : ⇑(localization.r' S) = localized_module.r S R :=
rfl
/--
If `S` is a multiplicative subset of a ring `R` and `M` an `R`-module, then
we can localize `M` by `S`.
-/
@[nolint has_nonempty_instance]
def _root_.localized_module : Type (max u v) := quotient (r.setoid S M)
section
variables {M S}
/--The canonical map sending `(m, s) ↦ m/s`-/
def mk (m : M) (s : S) : localized_module S M :=
quotient.mk ⟨m, s⟩
lemma mk_eq {m m' : M} {s s' : S} : mk m s = mk m' s' ↔ ∃ (u : S), u • s' • m = u • s • m' :=
quotient.eq
@[elab_as_eliminator]
lemma induction_on {β : localized_module S M → Prop} (h : ∀ (m : M) (s : S), β (mk m s)) :
∀ (x : localized_module S M), β x :=
by { rintro ⟨⟨m, s⟩⟩, exact h m s }
@[elab_as_eliminator]
lemma induction_on₂ {β : localized_module S M → localized_module S M → Prop}
(h : ∀ (m m' : M) (s s' : S), β (mk m s) (mk m' s')) : ∀ x y, β x y :=
by { rintro ⟨⟨m, s⟩⟩ ⟨⟨m', s'⟩⟩, exact h m m' s s' }
/--If `f : M × S → α` respects the equivalence relation `localized_module.r`, then
`f` descents to a map `localized_module M S → α`.
-/
def lift_on {α : Type*} (x : localized_module S M) (f : M × S → α)
(wd : ∀ (p p' : M × S) (h1 : p ≈ p'), f p = f p') : α :=
quotient.lift_on x f wd
lemma lift_on_mk {α : Type*} {f : M × S → α}
(wd : ∀ (p p' : M × S) (h1 : p ≈ p'), f p = f p')
(m : M) (s : S) :
lift_on (mk m s) f wd = f ⟨m, s⟩ :=
by convert quotient.lift_on_mk f wd ⟨m, s⟩
/--If `f : M × S → M × S → α` respects the equivalence relation `localized_module.r`, then
`f` descents to a map `localized_module M S → localized_module M S → α`.
-/
def lift_on₂ {α : Type*} (x y : localized_module S M) (f : (M × S) → (M × S) → α)
(wd : ∀ (p q p' q' : M × S) (h1 : p ≈ p') (h2 : q ≈ q'), f p q = f p' q') : α :=
quotient.lift_on₂ x y f wd
lemma lift_on₂_mk {α : Type*} (f : (M × S) → (M × S) → α)
(wd : ∀ (p q p' q' : M × S) (h1 : p ≈ p') (h2 : q ≈ q'), f p q = f p' q')
(m m' : M) (s s' : S) :
lift_on₂ (mk m s) (mk m' s') f wd = f ⟨m, s⟩ ⟨m', s'⟩ :=
by convert quotient.lift_on₂_mk f wd _ _
instance : has_zero (localized_module S M) := ⟨mk 0 1⟩
@[simp] lemma zero_mk (s : S) : mk (0 : M) s = 0 :=
mk_eq.mpr ⟨1, by rw [one_smul, smul_zero, smul_zero, one_smul]⟩
instance : has_add (localized_module S M) :=
{ add := λ p1 p2, lift_on₂ p1 p2 (λ x y, mk (y.2 • x.1 + x.2 • y.1) (x.2 * y.2)) $
λ ⟨m1, s1⟩ ⟨m2, s2⟩ ⟨m1', s1'⟩ ⟨m2', s2'⟩ ⟨u1, hu1⟩ ⟨u2, hu2⟩, mk_eq.mpr ⟨u1 * u2, begin
-- Put everything in the same shape, sorting the terms using `simp`
have hu1' := congr_arg ((•) (u2 * s2 * s2')) hu1,
have hu2' := congr_arg ((•) (u1 * s1 * s1')) hu2,
simp only [smul_add, ← mul_smul, smul_assoc, mul_assoc, mul_comm, mul_left_comm]
at ⊢ hu1' hu2',
rw [hu1', hu2']
end⟩ }
lemma mk_add_mk {m1 m2 : M} {s1 s2 : S} :
mk m1 s1 + mk m2 s2 = mk (s2 • m1 + s1 • m2) (s1 * s2) :=
mk_eq.mpr $ ⟨1, by dsimp only; rw [one_smul]⟩
private lemma add_assoc' (x y z : localized_module S M) :
x + y + z = x + (y + z) :=
begin
induction x using localized_module.induction_on with mx sx,
induction y using localized_module.induction_on with my sy,
induction z using localized_module.induction_on with mz sz,
simp only [mk_add_mk, smul_add],
refine mk_eq.mpr ⟨1, _⟩,
rw [one_smul, one_smul],
congr' 1,
{ rw [mul_assoc] },
{ rw [eq_comm, mul_comm, add_assoc, mul_smul, mul_smul, ←mul_smul sx sz, mul_comm, mul_smul], },
end
private lemma add_comm' (x y : localized_module S M) :
x + y = y + x :=
localized_module.induction_on₂ (λ m m' s s', by rw [mk_add_mk, mk_add_mk, add_comm, mul_comm]) x y
private lemma zero_add' (x : localized_module S M) : 0 + x = x :=
induction_on (λ m s, by rw [← zero_mk s, mk_add_mk, smul_zero, zero_add, mk_eq];
exact ⟨1, by rw [one_smul, mul_smul, one_smul]⟩) x
private lemma add_zero' (x : localized_module S M) : x + 0 = x :=
induction_on (λ m s, by rw [← zero_mk s, mk_add_mk, smul_zero, add_zero, mk_eq];
exact ⟨1, by rw [one_smul, mul_smul, one_smul]⟩) x
instance has_nat_smul : has_smul ℕ (localized_module S M) :=
{ smul := λ n, nsmul_rec n }
private lemma nsmul_zero' (x : localized_module S M) : (0 : ℕ) • x = 0 :=
localized_module.induction_on (λ _ _, rfl) x
private lemma nsmul_succ' (n : ℕ) (x : localized_module S M) :
n.succ • x = x + n • x :=
localized_module.induction_on (λ _ _, rfl) x
instance : add_comm_monoid (localized_module S M) :=
{ add := (+),
add_assoc := add_assoc',
zero := 0,
zero_add := zero_add',
add_zero := add_zero',
nsmul := (•),
nsmul_zero' := nsmul_zero',
nsmul_succ' := nsmul_succ',
add_comm := add_comm' }
instance {M : Type*} [add_comm_group M] [module R M] :
add_comm_group (localized_module S M) :=
{ neg := λ p, lift_on p (λ x, localized_module.mk (-x.1) x.2)
(λ ⟨m1, s1⟩ ⟨m2, s2⟩ ⟨u, hu⟩, by { rw mk_eq, exact ⟨u, by simpa⟩ }),
add_left_neg := λ p, begin
obtain ⟨⟨m, s⟩, rfl : mk m s = p⟩ := quotient.exists_rep p,
change (mk m s).lift_on (λ x, mk (-x.1) x.2)
(λ ⟨m1, s1⟩ ⟨m2, s2⟩ ⟨u, hu⟩, by { rw mk_eq, exact ⟨u, by simpa⟩ }) + mk m s = 0,
rw [lift_on_mk, mk_add_mk],
simp
end,
..(show add_comm_monoid (localized_module S M), by apply_instance) }
lemma mk_neg {M : Type*} [add_comm_group M] [module R M] {m : M} {s : S} :
mk (-m) s = - mk m s := rfl
instance {A : Type*} [semiring A] [algebra R A] {S : submonoid R} :
semiring (localized_module S A) :=
{ mul := λ m₁ m₂, lift_on₂ m₁ m₂ (λ x₁ x₂, localized_module.mk (x₁.1 * x₂.1) (x₁.2 * x₂.2))
(begin
rintros ⟨a₁, s₁⟩ ⟨a₂, s₂⟩ ⟨b₁, t₁⟩ ⟨b₂, t₂⟩ ⟨u₁, e₁⟩ ⟨u₂, e₂⟩,
rw mk_eq,
use u₁ * u₂,
dsimp only at ⊢ e₁ e₂,
rw eq_comm,
transitivity (u₁ • t₁ • a₁) • u₂ • t₂ • a₂,
rw [e₁, e₂], swap, rw eq_comm,
all_goals { rw [smul_smul, mul_mul_mul_comm, ← smul_eq_mul, ← smul_eq_mul A,
smul_smul_smul_comm, mul_smul, mul_smul] }
end),
left_distrib := begin
intros x₁ x₂ x₃,
obtain ⟨⟨a₁, s₁⟩, rfl : mk a₁ s₁ = x₁⟩ := quotient.exists_rep x₁,
obtain ⟨⟨a₂, s₂⟩, rfl : mk a₂ s₂ = x₂⟩ := quotient.exists_rep x₂,
obtain ⟨⟨a₃, s₃⟩, rfl : mk a₃ s₃ = x₃⟩ := quotient.exists_rep x₃,
apply mk_eq.mpr _,
use 1,
simp only [one_mul, smul_add, mul_add, mul_smul_comm, smul_smul, ← mul_assoc, mul_right_comm]
end,
right_distrib := begin
intros x₁ x₂ x₃,
obtain ⟨⟨a₁, s₁⟩, rfl : mk a₁ s₁ = x₁⟩ := quotient.exists_rep x₁,
obtain ⟨⟨a₂, s₂⟩, rfl : mk a₂ s₂ = x₂⟩ := quotient.exists_rep x₂,
obtain ⟨⟨a₃, s₃⟩, rfl : mk a₃ s₃ = x₃⟩ := quotient.exists_rep x₃,
apply mk_eq.mpr _,
use 1,
simp only [one_mul, smul_add, add_mul, smul_smul, ← mul_assoc, smul_mul_assoc, mul_right_comm],
end,
zero_mul := begin
intros x,
obtain ⟨⟨a, s⟩, rfl : mk a s = x⟩ := quotient.exists_rep x,
exact mk_eq.mpr ⟨1, by simp only [zero_mul, smul_zero]⟩,
end,
mul_zero := begin
intros x,
obtain ⟨⟨a, s⟩, rfl : mk a s = x⟩ := quotient.exists_rep x,
exact mk_eq.mpr ⟨1, by simp only [mul_zero, smul_zero]⟩,
end,
mul_assoc := begin
intros x₁ x₂ x₃,
obtain ⟨⟨a₁, s₁⟩, rfl : mk a₁ s₁ = x₁⟩ := quotient.exists_rep x₁,
obtain ⟨⟨a₂, s₂⟩, rfl : mk a₂ s₂ = x₂⟩ := quotient.exists_rep x₂,
obtain ⟨⟨a₃, s₃⟩, rfl : mk a₃ s₃ = x₃⟩ := quotient.exists_rep x₃,
apply mk_eq.mpr _,
use 1,
simp only [one_mul, smul_smul, ← mul_assoc, mul_right_comm],
end,
one := mk 1 (1 : S),
one_mul := begin
intros x,
obtain ⟨⟨a, s⟩, rfl : mk a s = x⟩ := quotient.exists_rep x,
exact mk_eq.mpr ⟨1, by simp only [one_mul, one_smul]⟩,
end,
mul_one := begin
intros x,
obtain ⟨⟨a, s⟩, rfl : mk a s = x⟩ := quotient.exists_rep x,
exact mk_eq.mpr ⟨1, by simp only [mul_one, one_smul]⟩,
end,
..(show add_comm_monoid (localized_module S A), by apply_instance) }
instance {A : Type*} [comm_semiring A] [algebra R A] {S : submonoid R} :
comm_semiring (localized_module S A) :=
{ mul_comm := begin
intros x₁ x₂,
obtain ⟨⟨a₁, s₁⟩, rfl : mk a₁ s₁ = x₁⟩ := quotient.exists_rep x₁,
obtain ⟨⟨a₂, s₂⟩, rfl : mk a₂ s₂ = x₂⟩ := quotient.exists_rep x₂,
exact mk_eq.mpr ⟨1, by simp only [one_smul, mul_comm]⟩
end,
..(show semiring (localized_module S A), by apply_instance) }
instance {A : Type*} [ring A] [algebra R A] {S : submonoid R} :
ring (localized_module S A) :=
{ ..(show add_comm_group (localized_module S A), by apply_instance),
..(show monoid (localized_module S A), by apply_instance),
..(show distrib (localized_module S A), by apply_instance) }
instance {A : Type*} [comm_ring A] [algebra R A] {S : submonoid R} :
comm_ring (localized_module S A) :=
{ mul_comm := begin
intros x₁ x₂,
obtain ⟨⟨a₁, s₁⟩, rfl : mk a₁ s₁ = x₁⟩ := quotient.exists_rep x₁,
obtain ⟨⟨a₂, s₂⟩, rfl : mk a₂ s₂ = x₂⟩ := quotient.exists_rep x₂,
exact mk_eq.mpr ⟨1, by simp only [one_smul, mul_comm]⟩
end,
..(show ring (localized_module S A), by apply_instance) }
lemma mk_mul_mk {A : Type*} [semiring A] [algebra R A] {a₁ a₂ : A} {s₁ s₂ : S} :
mk a₁ s₁ * mk a₂ s₂ = mk (a₁ * a₂) (s₁ * s₂) :=
rfl
instance : has_smul (localization S) (localized_module S M) :=
{ smul := λ f x, localization.lift_on f (λ r s, lift_on x (λ p, mk (r • p.1) (s * p.2))
begin
rintros ⟨m1, t1⟩ ⟨m2, t2⟩ ⟨u, h⟩,
refine mk_eq.mpr ⟨u, _⟩,
have h' := congr_arg ((•) (s • r)) h,
simp only [← mul_smul, smul_assoc, mul_comm, mul_left_comm, submonoid.smul_def,
submonoid.coe_mul] at ⊢ h',
rw h',
end) begin
induction x using localized_module.induction_on with m t,
rintros r r' s s' h,
simp only [lift_on_mk, lift_on_mk, mk_eq],
obtain ⟨u, eq1⟩ := localization.r_iff_exists.mp h,
use u,
have eq1' := congr_arg (• (t • m)) eq1,
simp only [← mul_smul, smul_assoc, submonoid.smul_def, submonoid.coe_mul] at ⊢ eq1',
ring_nf at ⊢ eq1',
rw eq1'
end }
lemma mk_smul_mk (r : R) (m : M) (s t : S) :
localization.mk r s • mk m t = mk (r • m) (s * t) :=
begin
unfold has_smul.smul,
rw [localization.lift_on_mk, lift_on_mk],
end
private lemma one_smul' (m : localized_module S M) :
(1 : localization S) • m = m :=
begin
induction m using localized_module.induction_on with m s,
rw [← localization.mk_one, mk_smul_mk, one_smul, one_mul],
end
private lemma mul_smul' (x y : localization S) (m : localized_module S M) :
(x * y) • m = x • y • m :=
begin
induction x using localization.induction_on with data,
induction y using localization.induction_on with data',
rcases ⟨data, data'⟩ with ⟨⟨r, s⟩, ⟨r', s'⟩⟩,
induction m using localized_module.induction_on with m t,
rw [localization.mk_mul, mk_smul_mk, mk_smul_mk, mk_smul_mk, mul_smul, mul_assoc],
end
private lemma smul_add' (x : localization S) (y z : localized_module S M) :
x • (y + z) = x • y + x • z :=
begin
induction x using localization.induction_on with data,
rcases data with ⟨r, u⟩,
induction y using localized_module.induction_on with m s,
induction z using localized_module.induction_on with n t,
rw [mk_smul_mk, mk_smul_mk, mk_add_mk, mk_smul_mk, mk_add_mk, mk_eq],
use 1,
simp only [one_smul, smul_add, ← mul_smul, submonoid.smul_def, submonoid.coe_mul],
ring_nf
end
private lemma smul_zero' (x : localization S) :
x • (0 : localized_module S M) = 0 :=
begin
induction x using localization.induction_on with data,
rcases data with ⟨r, s⟩,
rw [←zero_mk s, mk_smul_mk, smul_zero, zero_mk, zero_mk],
end
private lemma add_smul' (x y : localization S) (z : localized_module S M) :
(x + y) • z = x • z + y • z :=
begin
induction x using localization.induction_on with datax,
induction y using localization.induction_on with datay,
induction z using localized_module.induction_on with m t,
rcases ⟨datax, datay⟩ with ⟨⟨r, s⟩, ⟨r', s'⟩⟩,
rw [localization.add_mk, mk_smul_mk, mk_smul_mk, mk_smul_mk, mk_add_mk, mk_eq],
use 1,
simp only [one_smul, add_smul, smul_add, ← mul_smul, submonoid.smul_def, submonoid.coe_mul,
submonoid.coe_one],
rw add_comm, -- Commutativity of addition in the module is not applied by `ring`.
ring_nf,
end
private lemma zero_smul' (x : localized_module S M) :
(0 : localization S) • x = 0 :=
begin
induction x using localized_module.induction_on with m s,
rw [← localization.mk_zero s, mk_smul_mk, zero_smul, zero_mk],
end
instance is_module : module (localization S) (localized_module S M) :=
{ smul := (•),
one_smul := one_smul',
mul_smul := mul_smul',
smul_add := smul_add',
smul_zero := smul_zero',
add_smul := add_smul',
zero_smul := zero_smul' }
@[simp] lemma mk_cancel_common_left (s' s : S) (m : M) : mk (s' • m) (s' * s) = mk m s :=
mk_eq.mpr ⟨1, by { simp only [mul_smul, one_smul], rw smul_comm }⟩
@[simp] lemma mk_cancel (s : S) (m : M) : mk (s • m) s = mk m 1 :=
mk_eq.mpr ⟨1, by simp⟩
@[simp] lemma mk_cancel_common_right (s s' : S) (m : M) : mk (s' • m) (s * s') = mk m s :=
mk_eq.mpr ⟨1, by simp [mul_smul]⟩
instance is_module' : module R (localized_module S M) :=
{ ..module.comp_hom (localized_module S M) $ (algebra_map R (localization S)) }
lemma smul'_mk (r : R) (s : S) (m : M) : r • mk m s = mk (r • m) s :=
by erw [mk_smul_mk r m 1 s, one_mul]
instance {A : Type*} [semiring A] [algebra R A] :
algebra (localization S) (localized_module S A) :=
algebra.of_module
begin
intros r x₁ x₂,
obtain ⟨y, s, rfl : is_localization.mk' _ y s = r⟩ := is_localization.mk'_surjective S r,
obtain ⟨⟨a₁, s₁⟩, rfl : mk a₁ s₁ = x₁⟩ := quotient.exists_rep x₁,
obtain ⟨⟨a₂, s₂⟩, rfl : mk a₂ s₂ = x₂⟩ := quotient.exists_rep x₂,
rw [mk_mul_mk, ← localization.mk_eq_mk', mk_smul_mk, mk_smul_mk, mk_mul_mk,
mul_assoc, smul_mul_assoc],
end
begin
intros r x₁ x₂,
obtain ⟨y, s, rfl : is_localization.mk' _ y s = r⟩ := is_localization.mk'_surjective S r,
obtain ⟨⟨a₁, s₁⟩, rfl : mk a₁ s₁ = x₁⟩ := quotient.exists_rep x₁,
obtain ⟨⟨a₂, s₂⟩, rfl : mk a₂ s₂ = x₂⟩ := quotient.exists_rep x₂,
rw [mk_mul_mk, ← localization.mk_eq_mk', mk_smul_mk, mk_smul_mk, mk_mul_mk,
mul_left_comm, mul_smul_comm]
end
lemma algebra_map_mk {A : Type*} [semiring A] [algebra R A] (a : R) (s : S) :
algebra_map _ _ (localization.mk a s) = mk (algebra_map R A a) s :=
begin
rw [algebra.algebra_map_eq_smul_one],
change _ • mk _ _ = _,
rw [mk_smul_mk, algebra.algebra_map_eq_smul_one, mul_one]
end
instance : is_scalar_tower R (localization S) (localized_module S M) :=
restrict_scalars.is_scalar_tower R (localization S) (localized_module S M)
instance algebra' {A : Type*} [semiring A] [algebra R A] :
algebra R (localized_module S A) :=
{ commutes' := begin
intros r x,
obtain ⟨⟨a, s⟩, rfl : mk a s = x⟩ := quotient.exists_rep x,
dsimp,
rw [← localization.mk_one_eq_algebra_map, algebra_map_mk, mk_mul_mk, mk_mul_mk, mul_comm,
algebra.commutes],
end,
smul_def' := begin
intros r x,
obtain ⟨⟨a, s⟩, rfl : mk a s = x⟩ := quotient.exists_rep x,
dsimp,
rw [← localization.mk_one_eq_algebra_map, algebra_map_mk, mk_mul_mk, smul'_mk,
algebra.smul_def, one_mul],
end,
..(algebra_map (localization S) (localized_module S A)).comp (algebra_map R $ localization S),
..(show module R (localized_module S A), by apply_instance) }
section
variables (S M)
/-- The function `m ↦ m / 1` as an `R`-linear map.
-/
@[simps]
def mk_linear_map : M →ₗ[R] localized_module S M :=
{ to_fun := λ m, mk m 1,
map_add' := λ x y, by simp [mk_add_mk],
map_smul' := λ r x, (smul'_mk _ _ _).symm }
end
/--
For any `s : S`, there is an `R`-linear map given by `a/b ↦ a/(b*s)`.
-/
@[simps]
def div_by (s : S) : localized_module S M →ₗ[R] localized_module S M :=
{ to_fun := λ p, p.lift_on (λ p, mk p.1 (s * p.2)) $ λ ⟨a, b⟩ ⟨a', b'⟩ ⟨c, eq1⟩, mk_eq.mpr ⟨c,
begin
rw [mul_smul, mul_smul, smul_comm c, eq1, smul_comm s];
apply_instance,
end⟩,
map_add' := λ x y, x.induction_on₂
(begin
intros m₁ m₂ t₁ t₂,
simp only [mk_add_mk, localized_module.lift_on_mk, mul_smul, ←smul_add, mul_assoc,
mk_cancel_common_left s],
rw show s * (t₁ * t₂) = t₁ * (s * t₂), by { ext, simp only [submonoid.coe_mul], ring },
end) y,
map_smul' := λ r x, x.induction_on $ by { intros, simp [localized_module.lift_on_mk, smul'_mk] } }
lemma div_by_mul_by (s : S) (p : localized_module S M) :
div_by s (algebra_map R (module.End R (localized_module S M)) s p) = p :=
p.induction_on
begin
intros m t,
simp only [localized_module.lift_on_mk, module.algebra_map_End_apply, smul'_mk, div_by_apply],
erw mk_cancel_common_left s t,
end
lemma mul_by_div_by (s : S) (p : localized_module S M) :
algebra_map R (module.End R (localized_module S M)) s (div_by s p) = p :=
p.induction_on
begin
intros m t,
simp only [localized_module.lift_on_mk, div_by_apply, module.algebra_map_End_apply, smul'_mk],
erw mk_cancel_common_left s t,
end
end
end localized_module
section is_localized_module
universes u v
variables {R : Type*} [comm_ring R] (S : submonoid R)
variables {M M' M'' : Type*} [add_comm_monoid M] [add_comm_monoid M'] [add_comm_monoid M'']
variables [module R M] [module R M'] [module R M''] (f : M →ₗ[R] M') (g : M →ₗ[R] M'')
/--
The characteristic predicate for localized module.
`is_localized_module S f` describes that `f : M ⟶ M'` is the localization map identifying `M'` as
`localized_module S M`.
-/
class is_localized_module : Prop :=
(map_units [] : ∀ (x : S), is_unit (algebra_map R (module.End R M') x))
(surj [] : ∀ y : M', ∃ (x : M × S), x.2 • y = f x.1)
(eq_iff_exists [] : ∀ {x₁ x₂}, f x₁ = f x₂ ↔ ∃ c : S, c • x₂ = c • x₁)
namespace localized_module
/--
If `g` is a linear map `M → M''` such that all scalar multiplication by `s : S` is invertible, then
there is a linear map `localized_module S M → M''`.
-/
noncomputable def lift' (g : M →ₗ[R] M'')
(h : ∀ (x : S), is_unit ((algebra_map R (module.End R M'')) x)) :
(localized_module S M) → M'' :=
λ m, m.lift_on (λ p, (h $ p.2).unit⁻¹ $ g p.1) $ λ ⟨m, s⟩ ⟨m', s'⟩ ⟨c, eq1⟩,
begin
generalize_proofs h1 h2,
erw [module.End_algebra_map_is_unit_inv_apply_eq_iff, ←h2.unit⁻¹.1.map_smul], symmetry,
erw [module.End_algebra_map_is_unit_inv_apply_eq_iff], dsimp,
have : c • s • g m' = c • s' • g m,
{ erw [←g.map_smul, ←g.map_smul, ←g.map_smul, ←g.map_smul, eq1], refl, },
have : function.injective (h c).unit.inv,
{ rw function.injective_iff_has_left_inverse, refine ⟨(h c).unit, _⟩,
intros x,
change ((h c).unit.1 * (h c).unit.inv) x = x,
simp only [units.inv_eq_coe_inv, is_unit.mul_coe_inv, linear_map.one_apply], },
apply_fun (h c).unit.inv,
erw [units.inv_eq_coe_inv, module.End_algebra_map_is_unit_inv_apply_eq_iff,
←(h c).unit⁻¹.1.map_smul], symmetry,
erw [module.End_algebra_map_is_unit_inv_apply_eq_iff,
←g.map_smul, ←g.map_smul, ←g.map_smul, ←g.map_smul, eq1], refl,
end
lemma lift'_mk (g : M →ₗ[R] M'')
(h : ∀ (x : S), is_unit ((algebra_map R (module.End R M'')) x)) (m : M) (s : S) :
localized_module.lift' S g h (localized_module.mk m s) =
(h s).unit⁻¹.1 (g m) := rfl
lemma lift'_add (g : M →ₗ[R] M'')
(h : ∀ (x : S), is_unit ((algebra_map R (module.End R M'')) x)) (x y) :
localized_module.lift' S g h (x + y) =
localized_module.lift' S g h x + localized_module.lift' S g h y :=
localized_module.induction_on₂ begin
intros a a' b b',
erw [localized_module.lift'_mk, localized_module.lift'_mk, localized_module.lift'_mk],
dsimp, generalize_proofs h1 h2 h3,
erw [map_add, module.End_algebra_map_is_unit_inv_apply_eq_iff,
smul_add, ←h2.unit⁻¹.1.map_smul, ←h3.unit⁻¹.1.map_smul],
congr' 1; symmetry,
erw [module.End_algebra_map_is_unit_inv_apply_eq_iff, mul_smul, ←map_smul], refl,
erw [module.End_algebra_map_is_unit_inv_apply_eq_iff, mul_comm, mul_smul, ←map_smul], refl,
end x y
lemma lift'_smul (g : M →ₗ[R] M'')
(h : ∀ (x : S), is_unit ((algebra_map R (module.End R M'')) x))
(r : R) (m) :
r • localized_module.lift' S g h m = localized_module.lift' S g h (r • m) :=
m.induction_on begin
intros a b,
rw [localized_module.lift'_mk, localized_module.smul'_mk, localized_module.lift'_mk],
generalize_proofs h1 h2,
erw [←h1.unit⁻¹.1.map_smul, ←g.map_smul],
end
/--
If `g` is a linear map `M → M''` such that all scalar multiplication by `s : S` is invertible, then
there is a linear map `localized_module S M → M''`.
-/
noncomputable def lift (g : M →ₗ[R] M'')
(h : ∀ (x : S), is_unit ((algebra_map R (module.End R M'')) x)) :
(localized_module S M) →ₗ[R] M'' :=
{ to_fun := localized_module.lift' S g h,
map_add' := localized_module.lift'_add S g h,
map_smul' := λ r x, by rw [localized_module.lift'_smul, ring_hom.id_apply] }
/--
If `g` is a linear map `M → M''` such that all scalar multiplication by `s : S` is invertible, then
`lift g m s = s⁻¹ • g m`.
-/
lemma lift_mk (g : M →ₗ[R] M'')
(h : ∀ (x : S), is_unit ((algebra_map R (module.End R M'')) x))
(m : M) (s : S) :
localized_module.lift S g h (localized_module.mk m s) = (h s).unit⁻¹.1 (g m) := rfl
/--
If `g` is a linear map `M → M''` such that all scalar multiplication by `s : S` is invertible, then
there is a linear map `lift g ∘ mk_linear_map = g`.
-/
lemma lift_comp (g : M →ₗ[R] M'')
(h : ∀ (x : S), is_unit ((algebra_map R (module.End R M'')) x)) :
(lift S g h).comp (mk_linear_map S M) = g :=
begin
ext x, dsimp, rw localized_module.lift_mk,
erw [module.End_algebra_map_is_unit_inv_apply_eq_iff, one_smul],
end
/--
If `g` is a linear map `M → M''` such that all scalar multiplication by `s : S` is invertible and
`l` is another linear map `localized_module S M ⟶ M''` such that `l ∘ mk_linear_map = g` then
`l = lift g`
-/
lemma lift_unique (g : M →ₗ[R] M'')
(h : ∀ (x : S), is_unit ((algebra_map R (module.End R M'')) x))
(l : localized_module S M →ₗ[R] M'')
(hl : l.comp (localized_module.mk_linear_map S M) = g) :
localized_module.lift S g h = l :=
begin
ext x, induction x using localized_module.induction_on with m s,
rw [localized_module.lift_mk],
erw [module.End_algebra_map_is_unit_inv_apply_eq_iff, ←hl, linear_map.coe_comp, function.comp_app,
localized_module.mk_linear_map_apply, ←l.map_smul, localized_module.smul'_mk],
congr' 1, rw localized_module.mk_eq,
refine ⟨1, _⟩, simp only [one_smul], refl,
end
end localized_module
instance localized_module_is_localized_module :
is_localized_module S (localized_module.mk_linear_map S M) :=
{ map_units := λ s, ⟨⟨algebra_map R (module.End R (localized_module S M)) s,
localized_module.div_by s,
fun_like.ext _ _ $ localized_module.mul_by_div_by s,
fun_like.ext _ _ $ localized_module.div_by_mul_by s⟩,
fun_like.ext _ _ $ λ p, p.induction_on $ by { intros, refl }⟩,
surj := λ p, p.induction_on
begin
intros m t,
refine ⟨⟨m, t⟩, _⟩,
erw [localized_module.smul'_mk, localized_module.mk_linear_map_apply, submonoid.coe_subtype,
localized_module.mk_cancel t ],
end,
eq_iff_exists := λ m1 m2,
{ mp := λ eq1, by simpa only [eq_comm, one_smul] using localized_module.mk_eq.mp eq1,
mpr := λ ⟨c, eq1⟩,
localized_module.mk_eq.mpr ⟨c, by simpa only [eq_comm, one_smul] using eq1⟩ } }
namespace is_localized_module
variable [is_localized_module S f]
/--
If `(M', f : M ⟶ M')` satisfies universal property of localized module, there is a canonical map
`localized_module S M ⟶ M'`.
-/
noncomputable def from_localized_module' : localized_module S M → M' :=
λ p, p.lift_on (λ x, (is_localized_module.map_units f x.2).unit⁻¹ (f x.1))
begin
rintros ⟨a, b⟩ ⟨a', b'⟩ ⟨c, eq1⟩,
dsimp,
generalize_proofs h1 h2,
erw [module.End_algebra_map_is_unit_inv_apply_eq_iff, ←h2.unit⁻¹.1.map_smul,
module.End_algebra_map_is_unit_inv_apply_eq_iff', ←linear_map.map_smul, ←linear_map.map_smul],
exact (is_localized_module.eq_iff_exists S f).mpr ⟨c, eq1⟩,
end
@[simp] lemma from_localized_module'_mk (m : M) (s : S) :
from_localized_module' S f (localized_module.mk m s) =
(is_localized_module.map_units f s).unit⁻¹ (f m) :=
rfl
lemma from_localized_module'_add (x y : localized_module S M) :
from_localized_module' S f (x + y) =
from_localized_module' S f x + from_localized_module' S f y :=
localized_module.induction_on₂ begin
intros a a' b b',
simp only [localized_module.mk_add_mk, from_localized_module'_mk],
generalize_proofs h1 h2 h3,
erw [module.End_algebra_map_is_unit_inv_apply_eq_iff, smul_add, ←h2.unit⁻¹.1.map_smul,
←h3.unit⁻¹.1.map_smul, map_add],
congr' 1,
all_goals { erw [module.End_algebra_map_is_unit_inv_apply_eq_iff'] },
{ dsimp, erw [mul_smul, f.map_smul], refl, },
{ dsimp, erw [mul_comm, f.map_smul, mul_smul], refl, },
end x y
lemma from_localized_module'_smul (r : R) (x : localized_module S M) :
r • from_localized_module' S f x = from_localized_module' S f (r • x) :=
localized_module.induction_on begin
intros a b,
rw [from_localized_module'_mk, localized_module.smul'_mk, from_localized_module'_mk],
generalize_proofs h1, erw [f.map_smul, h1.unit⁻¹.1.map_smul], refl,
end x
/--
If `(M', f : M ⟶ M')` satisfies universal property of localized module, there is a canonical map
`localized_module S M ⟶ M'`.
-/
noncomputable def from_localized_module : localized_module S M →ₗ[R] M' :=
{ to_fun := from_localized_module' S f,
map_add' := from_localized_module'_add S f,
map_smul' := λ r x, by rw [from_localized_module'_smul, ring_hom.id_apply] }
lemma from_localized_module_mk (m : M) (s : S) :
from_localized_module S f (localized_module.mk m s) =
(is_localized_module.map_units f s).unit⁻¹ (f m) :=
rfl
lemma from_localized_module.inj : function.injective $ from_localized_module S f :=
λ x y eq1,
begin
induction x using localized_module.induction_on with a b,
induction y using localized_module.induction_on with a' b',
simp only [from_localized_module_mk] at eq1,
generalize_proofs h1 h2 at eq1,
erw [module.End_algebra_map_is_unit_inv_apply_eq_iff, ←linear_map.map_smul,
module.End_algebra_map_is_unit_inv_apply_eq_iff'] at eq1,
erw [localized_module.mk_eq, ←is_localized_module.eq_iff_exists S f, f.map_smul, f.map_smul, eq1],
refl,
end
lemma from_localized_module.surj : function.surjective $ from_localized_module S f :=
λ x, let ⟨⟨m, s⟩, eq1⟩ := is_localized_module.surj S f x in ⟨localized_module.mk m s,
by { rw [from_localized_module_mk, module.End_algebra_map_is_unit_inv_apply_eq_iff, ←eq1], refl }⟩
lemma from_localized_module.bij : function.bijective $ from_localized_module S f :=
⟨from_localized_module.inj _ _, from_localized_module.surj _ _⟩
/--
If `(M', f : M ⟶ M')` satisfies universal property of localized module, then `M'` is isomorphic to
`localized_module S M` as an `R`-module.
-/
@[simps] noncomputable def iso : localized_module S M ≃ₗ[R] M' :=
{ ..from_localized_module S f,
..equiv.of_bijective (from_localized_module S f) $ from_localized_module.bij _ _}
lemma iso_apply_mk (m : M) (s : S) :
iso S f (localized_module.mk m s) = (is_localized_module.map_units f s).unit⁻¹ (f m) :=
rfl
lemma iso_symm_apply_aux (m : M') :
(iso S f).symm m = localized_module.mk (is_localized_module.surj S f m).some.1
(is_localized_module.surj S f m).some.2 :=
begin
generalize_proofs _ h2,
apply_fun (iso S f) using linear_equiv.injective _,
rw [linear_equiv.apply_symm_apply],
simp only [iso_apply, linear_map.to_fun_eq_coe, from_localized_module_mk],
erw [module.End_algebra_map_is_unit_inv_apply_eq_iff', h2.some_spec],
end
lemma iso_symm_apply' (m : M') (a : M) (b : S) (eq1 : b • m = f a) :
(iso S f).symm m = localized_module.mk a b :=
(iso_symm_apply_aux S f m).trans $ localized_module.mk_eq.mpr $
begin
generalize_proofs h1,
erw [←is_localized_module.eq_iff_exists S f, f.map_smul, f.map_smul, ←h1.some_spec, ←mul_smul,
mul_comm, mul_smul, eq1],
end
lemma iso_symm_comp : (iso S f).symm.to_linear_map.comp f = localized_module.mk_linear_map S M :=
begin
ext m, rw [linear_map.comp_apply, localized_module.mk_linear_map_apply],
change (iso S f).symm _ = _, rw [iso_symm_apply'], exact one_smul _ _,
end
/--
If `M'` is a localized module and `g` is a linear map `M' → M''` such that all scalar multiplication
by `s : S` is invertible, then there is a linear map `M' → M''`.
-/
noncomputable def lift (g : M →ₗ[R] M'')
(h : ∀ (x : S), is_unit ((algebra_map R (module.End R M'')) x)) :
M' →ₗ[R] M'' :=
(localized_module.lift S g h).comp (iso S f).symm.to_linear_map
lemma lift_comp (g : M →ₗ[R] M'')
(h : ∀ (x : S), is_unit ((algebra_map R (module.End R M'')) x)) :
(lift S f g h).comp f = g :=
begin
dunfold is_localized_module.lift,
rw [linear_map.comp_assoc],
convert localized_module.lift_comp S g h,
exact iso_symm_comp _ _,
end
lemma lift_unique (g : M →ₗ[R] M'')
(h : ∀ (x : S), is_unit ((algebra_map R (module.End R M'')) x))
(l : M' →ₗ[R] M'') (hl : l.comp f = g) :
lift S f g h = l :=
begin
dunfold is_localized_module.lift,
rw [localized_module.lift_unique S g h (l.comp (iso S f).to_linear_map), linear_map.comp_assoc,
show (iso S f).to_linear_map.comp (iso S f).symm.to_linear_map = linear_map.id, from _,
linear_map.comp_id],
{ rw [linear_equiv.comp_to_linear_map_symm_eq, linear_map.id_comp], },
{ rw [linear_map.comp_assoc, ←hl], congr' 1, ext x,
erw [from_localized_module_mk, module.End_algebra_map_is_unit_inv_apply_eq_iff, one_smul], },
end
/--
Universal property from localized module:
If `(M', f : M ⟶ M')` is a localized module then it satisfies the following universal property:
For every `R`-module `M''` which every `s : S`-scalar multiplication is invertible and for every
`R`-linear map `g : M ⟶ M''`, there is a unique `R`-linear map `l : M' ⟶ M''` such that
`l ∘ f = g`.
```
M -----f----> M'
| /
|g /
| / l
v /
M''
```
-/
lemma is_universal :
∀ (g : M →ₗ[R] M'') (map_unit : ∀ (x : S), is_unit ((algebra_map R (module.End R M'')) x)),
∃! (l : M' →ₗ[R] M''), l.comp f = g :=
λ g h, ⟨lift S f g h, lift_comp S f g h, λ l hl, (lift_unique S f g h l hl).symm⟩
lemma ring_hom_ext (map_unit : ∀ (x : S), is_unit ((algebra_map R (module.End R M'')) x))
⦃j k : M' →ₗ[R] M''⦄ (h : j.comp f = k.comp f) : j = k :=
by { rw [←lift_unique S f (k.comp f) map_unit j h, lift_unique], refl }
/--
If `(M', f)` and `(M'', g)` both satisfy universal property of localized module, then `M', M''`
are isomorphic as `R`-module
-/
noncomputable def linear_equiv [is_localized_module S g] : M' ≃ₗ[R] M'' :=
(iso S f).symm.trans (iso S g)
variable {S}
lemma smul_injective (s : S) : function.injective (λ m : M', s • m) :=
((module.End_is_unit_iff _).mp (is_localized_module.map_units f s)).injective
lemma smul_inj (s : S) (m₁ m₂ : M') : s • m₁ = s • m₂ ↔ m₁ = m₂ :=
(smul_injective f s).eq_iff
/-- `mk' f m s` is the fraction `m/s` with respect to the localization map `f`. -/
noncomputable
def mk' (m : M) (s : S) : M' := from_localized_module S f (localized_module.mk m s)
lemma mk'_smul (r : R) (m : M) (s : S) : mk' f (r • m) s = r • mk' f m s :=
by { delta mk', rw [← localized_module.smul'_mk, linear_map.map_smul] }
lemma mk'_add_mk' (m₁ m₂ : M) (s₁ s₂ : S) :
mk' f m₁ s₁ + mk' f m₂ s₂ = mk' f (s₂ • m₁ + s₁ • m₂) (s₁ * s₂) :=
by { delta mk', rw [← map_add, localized_module.mk_add_mk] }
@[simp] lemma mk'_zero (s : S) :
mk' f 0 s = 0 :=
by rw [← zero_smul R (0 : M), mk'_smul, zero_smul]
variable (S)
@[simp] lemma mk'_one (m : M) :
mk' f m (1 : S) = f m :=
by { delta mk', rw [from_localized_module_mk, module.End_algebra_map_is_unit_inv_apply_eq_iff,
submonoid.coe_one, one_smul] }
variable {S}
@[simp] lemma mk'_cancel (m : M) (s : S) :
mk' f (s • m) s = f m :=
by { delta mk', rw [localized_module.mk_cancel, ← mk'_one S f], refl }
@[simp] lemma mk'_cancel' (m : M) (s : S) :
s • mk' f m s = f m :=
by rw [submonoid.smul_def, ← mk'_smul, ← submonoid.smul_def, mk'_cancel]
@[simp] lemma mk'_cancel_left (m : M) (s₁ s₂ : S) :
mk' f (s₁ • m) (s₁ * s₂) = mk' f m s₂ :=
by { delta mk', rw localized_module.mk_cancel_common_left }
@[simp] lemma mk'_cancel_right (m : M) (s₁ s₂ : S) :
mk' f (s₂ • m) (s₁ * s₂) = mk' f m s₁ :=
by { delta mk', rw localized_module.mk_cancel_common_right }
lemma mk'_add (m₁ m₂ : M) (s : S) : mk' f (m₁ + m₂) s = mk' f m₁ s + mk' f m₂ s :=
by { rw [mk'_add_mk', ← smul_add, mk'_cancel_left] }
lemma mk'_eq_mk'_iff (m₁ m₂ : M) (s₁ s₂ : S) :
mk' f m₁ s₁ = mk' f m₂ s₂ ↔ ∃ s : S, s • s₁ • m₂ = s • s₂ • m₁ :=
begin
delta mk',
rw [(from_localized_module.inj S f).eq_iff, localized_module.mk_eq],
simp_rw eq_comm
end
lemma mk'_neg {M M' : Type*} [add_comm_group M] [add_comm_group M'] [module R M]
[module R M'] (f : M →ₗ[R] M') [is_localized_module S f] (m : M) (s : S) :
mk' f (-m) s = - mk' f m s :=
by { delta mk', rw [localized_module.mk_neg, map_neg] }
lemma mk'_sub {M M' : Type*} [add_comm_group M] [add_comm_group M'] [module R M]
[module R M'] (f : M →ₗ[R] M') [is_localized_module S f] (m₁ m₂ : M) (s : S) :
mk' f (m₁ - m₂) s = mk' f m₁ s - mk' f m₂ s :=
by rw [sub_eq_add_neg, sub_eq_add_neg, mk'_add, mk'_neg]
lemma mk'_sub_mk' {M M' : Type*} [add_comm_group M] [add_comm_group M'] [module R M]
[module R M'] (f : M →ₗ[R] M') [is_localized_module S f] (m₁ m₂ : M) (s₁ s₂ : S) :
mk' f m₁ s₁ - mk' f m₂ s₂ = mk' f (s₂ • m₁ - s₁ • m₂) (s₁ * s₂) :=
by rw [sub_eq_add_neg, ← mk'_neg, mk'_add_mk', smul_neg, ← sub_eq_add_neg]
lemma mk'_mul_mk'_of_map_mul {M M' : Type*} [semiring M] [semiring M'] [module R M]
[algebra R M'] (f : M →ₗ[R] M') (hf : ∀ m₁ m₂, f (m₁ * m₂) = f m₁ * f m₂)
[is_localized_module S f] (m₁ m₂ : M) (s₁ s₂ : S) :
mk' f m₁ s₁ * mk' f m₂ s₂ = mk' f (m₁ * m₂) (s₁ * s₂) :=
begin
symmetry,
apply (module.End_algebra_map_is_unit_inv_apply_eq_iff _ _ _).mpr,
simp_rw [submonoid.coe_mul, ← smul_eq_mul],
rw [smul_smul_smul_comm, ← mk'_smul, ← mk'_smul],
simp_rw [← submonoid.smul_def, mk'_cancel, smul_eq_mul, hf],
end
lemma mk'_mul_mk' {M M' : Type*} [semiring M] [semiring M'] [algebra R M]
[algebra R M'] (f : M →ₐ[R] M')
[is_localized_module S f.to_linear_map] (m₁ m₂ : M) (s₁ s₂ : S) :
mk' f.to_linear_map m₁ s₁ * mk' f.to_linear_map m₂ s₂ =
mk' f.to_linear_map (m₁ * m₂) (s₁ * s₂) :=
mk'_mul_mk'_of_map_mul f.to_linear_map f.map_mul m₁ m₂ s₁ s₂
variables {f}
@[simp] lemma mk'_eq_iff {m : M} {s : S} {m' : M'} :
mk' f m s = m' ↔ f m = s • m' :=
by rw [← smul_inj f s, submonoid.smul_def, ← mk'_smul, ← submonoid.smul_def, mk'_cancel]
@[simp] lemma mk'_eq_zero {m : M} (s : S) :
mk' f m s = 0 ↔ f m = 0 :=
by rw [mk'_eq_iff, smul_zero]
variable (f)
lemma mk'_eq_zero' {m : M} (s : S) :
mk' f m s = 0 ↔ ∃ s' : S, s' • m = 0 :=
by simp_rw [← mk'_zero f (1 : S), mk'_eq_mk'_iff, smul_zero, one_smul, eq_comm]
lemma mk_eq_mk' (s : S) (m : M) :
localized_module.mk m s = mk' (localized_module.mk_linear_map S M) m s :=
by rw [eq_comm, mk'_eq_iff, submonoid.smul_def, localized_module.smul'_mk,
← submonoid.smul_def, localized_module.mk_cancel, localized_module.mk_linear_map_apply]
variable (S)
lemma eq_zero_iff {m : M} :
f m = 0 ↔ ∃ s' : S, s' • m = 0 :=
(mk'_eq_zero (1 : S)).symm.trans (mk'_eq_zero' f _)
lemma mk'_surjective : function.surjective (function.uncurry $ mk' f : M × S → M') :=
begin
intro x,
obtain ⟨⟨m, s⟩, e : s • x = f m⟩ := is_localized_module.surj S f x,
exact ⟨⟨m, s⟩, mk'_eq_iff.mpr e.symm⟩
end
section algebra
lemma mk_of_algebra {R S S' : Type*} [comm_ring R] [comm_ring S] [comm_ring S']
[algebra R S] [algebra R S'] (M : submonoid R) (f : S →ₐ[R] S')
(h₁ : ∀ x ∈ M, is_unit (algebra_map R S' x))
(h₂ : ∀ y, ∃ (x : S × M), x.2 • y = f x.1)
(h₃ : ∀ x, f x = 0 → ∃ m : M, m • x = 0) :
is_localized_module M f.to_linear_map :=
begin
replace h₃ := λ x, iff.intro (h₃ x) (λ ⟨⟨m, hm⟩, e⟩, (h₁ m hm).mul_left_cancel $
by { rw ← algebra.smul_def, simpa [submonoid.smul_def] using f.congr_arg e }),
constructor,
{ intro x,
rw module.End_is_unit_iff,
split,
{ rintros a b (e : x • a = x • b), simp_rw [submonoid.smul_def, algebra.smul_def] at e,
exact (h₁ x x.2).mul_left_cancel e },
{ intro a, refine ⟨((h₁ x x.2).unit⁻¹ : _) * a, _⟩, change (x : R) • (_ * a) = _,
rw [algebra.smul_def, ← mul_assoc, is_unit.mul_coe_inv, one_mul] } },
{ exact h₂ },
{ intros, dsimp, rw [eq_comm, ← sub_eq_zero, ← map_sub, h₃], simp_rw [smul_sub, sub_eq_zero] },
end
end algebra
end is_localized_module
end is_localized_module
|
cf11fe19908ed79fa5305ee601ecdeede9a6a583 | d1a52c3f208fa42c41df8278c3d280f075eb020c | /tests/elabissues/typeclasses_with_preconditions.lean | 4765af900120e23978b45063bfa7ccf3d5ba33c2 | [
"Apache-2.0",
"LLVM-exception",
"NCSA",
"LGPL-3.0-only",
"LicenseRef-scancode-inner-net-2.0",
"BSD-3-Clause",
"LGPL-2.0-or-later",
"Spencer-94",
"LGPL-2.1-or-later",
"HPND",
"LicenseRef-scancode-pcre",
"ISC",
"LGPL-2.1-only",
"LicenseRef-scancode-other-permissive",
"SunPro",
"CMU-Mach"... | permissive | cipher1024/lean4 | 6e1f98bb58e7a92b28f5364eb38a14c8d0aae393 | 69114d3b50806264ef35b57394391c3e738a9822 | refs/heads/master | 1,642,227,983,603 | 1,642,011,696,000 | 1,642,011,696,000 | 228,607,691 | 0 | 0 | Apache-2.0 | 1,576,584,269,000 | 1,576,584,268,000 | null | UTF-8 | Lean | false | false | 2,215 | lean | /-
The current plan is to allow instances to have preconditions with registered tactics.
Typeclass resolution will delay these proof obligations, effectively assuming that they will succeed.
If typeclass resolution succeeds, it will return a list of (mvar, lctx) pairs to the elaborator,
which will try to synthesize the proofs and throw a good error message if it fails.
-/
class Foo (b : Bool) : Type
class FooTrue (b : Bool) extends Foo b : Type :=
(H : b = true)
/- This requires the tactic framework and auto_param. -/
-- @[instance] axiom CoeFooFooTrue (b : Bool) (H : b = true . refl) : HasCoe (Foo b) (FooTrue b)
instance BoolToFoo (b : Bool) : Foo b := Foo.mk b
def forceFooTrue (b : Bool) (fooTrue : FooTrue b) : Bool := b
/- Should succeed (once CoeFooFooTrue can be written) -/
#check forceFooTrue true (Foo.mk true)
/- Should fail (even after CoeFooFooTrue can be written -/
#check forceFooTrue false (Foo.mk false)
/-
This plan has one limitation, that has so far been deemed acceptable:
it will not support classes with different instances depending on the provability of preconditions.
The classic example is multiplying two elements of `ℤ/nℤ` where `n` is not prime.
Here is a toy version of this problem:
<<
@[class] axiom Prime (p : Nat) : Prop
@[instance] axiom p2 : Prime 2
@[instance] axiom p3 : Prime 3
@[class] axiom Field : Type → Type
@[class] axiom Ring : Type → Type
@[instance] axiom FieldToDiv (α : Type) [Field α] : Div α
@[instance] axiom FieldToMul (α : Type) [Field α] : Mul α
@[instance] axiom RingToMul (α : Type) [Ring α] : Mul α
axiom mkType : Nat → Type
@[instance] axiom PrimeField (n : Nat) (Hp : Prime n . provePrimality) : Field (mkType n)
@[instance] axiom NonPrimeRing (n : Nat) : Ring (mkType n)
example (α β : mkType 4) : α * β = β * α
>>
The issue is that (depending on the order the instances are tried),
the instance involving `FieldToMul` will succeed in typeclass resolution,
but the proof will fail later on.
I (@dselsam) still thinks this plan is a good compromise.
For examples like this, the definition in question (i.e. `Prime`) can be made a class instead
and taken as an inst-implicit argument to `PrimeField`.
-/
|
181093b3f888caf0b5fe7c1628cbe547a8458a8d | e61a235b8468b03aee0120bf26ec615c045005d2 | /src/Init/Lean/Data/Json/FromToJson.lean | f17f0156fe5cc030e2b295b77c9dd6c7cf522df3 | [
"Apache-2.0"
] | permissive | SCKelemen/lean4 | 140dc63a80539f7c61c8e43e1c174d8500ec3230 | e10507e6615ddbef73d67b0b6c7f1e4cecdd82bc | refs/heads/master | 1,660,973,595,917 | 1,590,278,033,000 | 1,590,278,033,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 1,707 | lean | /-
Copyright (c) 2019 Gabriel Ebner. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Gabriel Ebner, Marc Huisinga
-/
prelude
import Init.Lean.Data.Json.Basic
import Init.Data.List.Control
namespace Lean
universes u
class HasFromJson (α : Type u) :=
(fromJson? : Json → Option α)
export HasFromJson (fromJson?)
class HasToJson (α : Type u) :=
(toJson : α → Json)
export HasToJson (toJson)
instance Json.hasFromJson : HasFromJson Json := ⟨some⟩
instance Json.HasToJson : HasToJson Json := ⟨id⟩
instance JsonNumber.hasFromJson : HasFromJson JsonNumber := ⟨Json.getNum?⟩
instance JsonNumber.hasToJson : HasToJson JsonNumber := ⟨Json.num⟩
-- looks like id, but there are coercions happening
instance Bool.hasFromJson : HasFromJson Bool := ⟨Json.getBool?⟩
instance Bool.hasToJson : HasToJson Bool := ⟨fun b => b⟩
instance Nat.hasFromJson : HasFromJson Nat := ⟨Json.getNat?⟩
instance Nat.hasToJson : HasToJson Nat := ⟨fun n => n⟩
instance Int.hasFromJson : HasFromJson Int := ⟨Json.getInt?⟩
instance Int.hasToJson : HasToJson Int := ⟨fun n => Json.num n⟩
instance String.hasFromJson : HasFromJson String := ⟨Json.getStr?⟩
instance String.hasToJson : HasToJson String := ⟨fun s => s⟩
instance Array.hasFromJson {α : Type u} [HasFromJson α] : HasFromJson (Array α) :=
⟨fun j => match j with
| Json.arr a => a.mapM fromJson?
| _ => none⟩
instance List.hasToJson {α : Type u} [HasToJson α] : HasToJson (Array α) :=
⟨fun a => Json.arr (a.map toJson)⟩
def Json.getObjValAs? (j : Json) (α : Type u) [HasFromJson α] (k : String) : Option α :=
(j.getObjVal? k).bind fromJson?
end Lean
|
5aa8318a0ef8c3364d9925a19b697c0a1eabd97c | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/number_theory/cyclotomic/discriminant.lean | 1875990e97556e53c835eff40cf51b841d1806b7 | [
"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 | 11,223 | lean | /-
Copyright (c) 2022 Riccardo Brasca. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Riccardo Brasca
-/
import number_theory.cyclotomic.primitive_roots
import ring_theory.discriminant
/-!
# Discriminant of cyclotomic fields
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
We compute the discriminant of a `p ^ n`-th cyclotomic extension.
## Main results
* `is_cyclotomic_extension.discr_odd_prime` : if `p` is an odd prime such that
`is_cyclotomic_extension {p} K L` and `irreducible (cyclotomic p K)`, then
`discr K (hζ.power_basis K).basis = (-1) ^ ((p - 1) / 2) * p ^ (p - 2)` for any
`hζ : is_primitive_root ζ p`.
-/
universes u v
open algebra polynomial nat is_primitive_root power_basis
open_locale polynomial cyclotomic
namespace is_primitive_root
variables {n : ℕ+} {K : Type u} [field K] [char_zero K] {ζ : K}
variables [is_cyclotomic_extension {n} ℚ K]
/-- The discriminant of the power basis given by a primitive root of unity `ζ` is the same as the
discriminant of the power basis given by `ζ - 1`. -/
lemma discr_zeta_eq_discr_zeta_sub_one (hζ : is_primitive_root ζ n) :
discr ℚ (hζ.power_basis ℚ).basis = discr ℚ (hζ.sub_one_power_basis ℚ).basis :=
begin
haveI : number_field K := number_field.mk,
have H₁ : (aeval (hζ.power_basis ℚ).gen) (X - 1 : ℤ[X]) = (hζ.sub_one_power_basis ℚ).gen :=
by simp,
have H₂ : (aeval (hζ.sub_one_power_basis ℚ).gen) (X + 1 : ℤ[X]) = (hζ.power_basis ℚ).gen :=
by simp,
refine discr_eq_discr_of_to_matrix_coeff_is_integral _
(λ i j, to_matrix_is_integral H₁ _ _ _ _)
(λ i j, to_matrix_is_integral H₂ _ _ _ _),
{ exact hζ.is_integral n.pos },
{ refine minpoly.is_integrally_closed_eq_field_fractions' _ (hζ.is_integral n.pos) },
{ exact is_integral_sub (hζ.is_integral n.pos) is_integral_one },
{ refine minpoly.is_integrally_closed_eq_field_fractions' _ _,
exact is_integral_sub (hζ.is_integral n.pos) is_integral_one }
end
end is_primitive_root
namespace is_cyclotomic_extension
variables {p : ℕ+} {k : ℕ} {K : Type u} {L : Type v} {ζ : L} [field K] [field L]
variables [algebra K L]
/-- If `p` is a prime and `is_cyclotomic_extension {p ^ (k + 1)} K L`, then the discriminant of
`hζ.power_basis K` is `(-1) ^ ((p ^ (k + 1).totient) / 2) * p ^ (p ^ k * ((p - 1) * (k + 1) - 1))`
if `irreducible (cyclotomic (p ^ (k + 1)) K))`, and `p ^ (k + 1) ≠ 2`. -/
lemma discr_prime_pow_ne_two [is_cyclotomic_extension {p ^ (k + 1)} K L] [hp : fact (p : ℕ).prime]
(hζ : is_primitive_root ζ ↑(p ^ (k + 1))) (hirr : irreducible (cyclotomic (↑(p ^ (k + 1)) : ℕ) K))
(hk : p ^ (k + 1) ≠ 2) :
discr K (hζ.power_basis K).basis =
(-1) ^ (((p ^ (k + 1) : ℕ).totient) / 2) * p ^ ((p : ℕ) ^ k * ((p - 1) * (k + 1) - 1)) :=
begin
haveI hne := is_cyclotomic_extension.ne_zero' (p ^ (k + 1)) K L,
rw [discr_power_basis_eq_norm, finrank L hirr, hζ.power_basis_gen _,
← hζ.minpoly_eq_cyclotomic_of_irreducible hirr, pnat.pow_coe,
totient_prime_pow hp.out (succ_pos k), succ_sub_one],
have hp2 : p = 2 → k ≠ 0,
{ unfreezingI { rintro rfl rfl },
exact absurd rfl hk },
congr' 1,
{ unfreezingI { rcases eq_or_ne p 2 with rfl | hp2 },
{ unfreezingI { rcases nat.exists_eq_succ_of_ne_zero (hp2 rfl) with ⟨k, rfl⟩ },
rw [pnat.coe_bit0, pnat.one_coe, succ_sub_succ_eq_sub, tsub_zero,
mul_one, pow_succ, mul_assoc, nat.mul_div_cancel_left _ zero_lt_two,
nat.mul_div_cancel_left _ zero_lt_two],
unfreezingI { cases k },
{ simp },
{ rw [pow_succ, (even_two.mul_right _).neg_one_pow,
((even_two.mul_right _).mul_right _).neg_one_pow] } },
{ replace hp2 : (p : ℕ) ≠ 2,
{ rwa [ne.def, ← pnat.one_coe, ← pnat.coe_bit0, pnat.coe_inj] },
have hpo : odd (p : ℕ) := hp.out.odd_of_ne_two hp2,
obtain ⟨a, ha⟩ := (hp.out.even_sub_one hp2).two_dvd,
rw [ha, mul_left_comm, mul_assoc, nat.mul_div_cancel_left _ two_pos,
nat.mul_div_cancel_left _ two_pos, mul_right_comm, pow_mul, (hpo.pow.mul _).neg_one_pow,
pow_mul, hpo.pow.neg_one_pow],
refine nat.even.sub_odd _ (even_two_mul _) odd_one,
rw [mul_left_comm, ← ha],
exact one_le_mul (one_le_pow _ _ hp.1.pos) (succ_le_iff.2 $ tsub_pos_of_lt hp.1.one_lt) } },
{ have H := congr_arg derivative (cyclotomic_prime_pow_mul_X_pow_sub_one K p k),
rw [derivative_mul, derivative_sub, derivative_one, sub_zero, derivative_X_pow, C_eq_nat_cast,
derivative_sub, derivative_one, sub_zero, derivative_X_pow, C_eq_nat_cast, ← pnat.pow_coe,
hζ.minpoly_eq_cyclotomic_of_irreducible hirr] at H,
replace H := congr_arg (λ P, aeval ζ P) H,
simp only [aeval_add, aeval_mul, minpoly.aeval, zero_mul, add_zero, aeval_nat_cast,
_root_.map_sub, aeval_one, aeval_X_pow] at H,
replace H := congr_arg (algebra.norm K) H,
have hnorm : (norm K) (ζ ^ (p : ℕ) ^ k - 1) = p ^ ((p : ℕ) ^ k),
{ by_cases hp : p = 2,
{ exact hζ.pow_sub_one_norm_prime_pow_of_ne_zero hirr le_rfl (hp2 hp) },
{ exact hζ.pow_sub_one_norm_prime_ne_two hirr le_rfl hp } },
rw [monoid_hom.map_mul, hnorm, monoid_hom.map_mul, ← map_nat_cast (algebra_map K L),
algebra.norm_algebra_map, finrank L hirr, pnat.pow_coe, totient_prime_pow hp.out (succ_pos k),
nat.sub_one, nat.pred_succ, ← hζ.minpoly_eq_cyclotomic_of_irreducible hirr, map_pow,
hζ.norm_eq_one hk hirr, one_pow, mul_one, cast_pow, ← coe_coe, ← pow_mul, ← mul_assoc,
mul_comm (k + 1), mul_assoc] at H,
{ have := mul_pos (succ_pos k) (tsub_pos_of_lt hp.out.one_lt),
rw [← succ_pred_eq_of_pos this, mul_succ, pow_add _ _ ((p : ℕ) ^ k)] at H,
replace H := (mul_left_inj' (λ h, _)).1 H,
{ simpa only [← pnat.pow_coe, H, mul_comm _ (k + 1)] },
{ replace h := pow_eq_zero h,
rw [coe_coe] at h,
simpa using hne.1 } } }
end
/-- If `p` is a prime and `is_cyclotomic_extension {p ^ (k + 1)} K L`, then the discriminant of
`hζ.power_basis K` is `(-1) ^ (p ^ k * (p - 1) / 2) * p ^ (p ^ k * ((p - 1) * (k + 1) - 1))`
if `irreducible (cyclotomic (p ^ (k + 1)) K))`, and `p ^ (k + 1) ≠ 2`. -/
lemma discr_prime_pow_ne_two' [is_cyclotomic_extension {p ^ (k + 1)} K L] [hp : fact (p : ℕ).prime]
(hζ : is_primitive_root ζ ↑(p ^ (k + 1))) (hirr : irreducible (cyclotomic (↑(p ^ (k + 1)) : ℕ) K))
(hk : p ^ (k + 1) ≠ 2) :
discr K (hζ.power_basis K).basis =
(-1) ^ (((p : ℕ) ^ k * (p - 1)) / 2) * p ^ ((p : ℕ) ^ k * ((p - 1) * (k + 1) - 1)) :=
by simpa [totient_prime_pow hp.out (succ_pos k)] using discr_prime_pow_ne_two hζ hirr hk
/-- If `p` is a prime and `is_cyclotomic_extension {p ^ k} K L`, then the discriminant of
`hζ.power_basis K` is `(-1) ^ ((p ^ k).totient / 2) * p ^ (p ^ (k - 1) * ((p - 1) * k - 1))`
if `irreducible (cyclotomic (p ^ k) K))`. Beware that in the cases `p ^ k = 1` and `p ^ k = 2`
the formula uses `1 / 2 = 0` and `0 - 1 = 0`. It is useful only to have a uniform result.
See also `is_cyclotomic_extension.discr_prime_pow_eq_unit_mul_pow`. -/
lemma discr_prime_pow [hcycl : is_cyclotomic_extension {p ^ k} K L] [hp : fact (p : ℕ).prime]
(hζ : is_primitive_root ζ ↑(p ^ k)) (hirr : irreducible (cyclotomic (↑(p ^ k) : ℕ) K)) :
discr K (hζ.power_basis K).basis =
(-1) ^ (((p ^ k : ℕ).totient) / 2) * p ^ ((p : ℕ) ^ (k - 1) * ((p - 1) * k - 1)) :=
begin
unfreezingI { cases k },
{ simp only [coe_basis, pow_zero, power_basis_gen, totient_one, mul_zero, mul_one, show 1 / 2 = 0,
by refl, discr, trace_matrix],
have hζone : ζ = 1 := by simpa using hζ,
rw [hζ.power_basis_dim _, hζone, ← (algebra_map K L).map_one,
minpoly.eq_X_sub_C_of_algebra_map_inj _ (algebra_map K L).injective, nat_degree_X_sub_C],
simp only [trace_matrix, map_one, one_pow, matrix.det_unique, trace_form_apply, mul_one],
rw [← (algebra_map K L).map_one, trace_algebra_map, finrank _ hirr],
{ simp },
{ apply_instance },
{ exact hcycl } },
{ by_cases hk : p ^ (k + 1) = 2,
{ have hp : p = 2,
{ rw [← pnat.coe_inj, pnat.coe_bit0, pnat.one_coe, pnat.pow_coe, ← pow_one 2] at hk,
replace hk := eq_of_prime_pow_eq (prime_iff.1 hp.out) (prime_iff.1 nat.prime_two)
(succ_pos _) hk,
rwa [show 2 = ((2 : ℕ+) : ℕ), by simp, pnat.coe_inj] at hk },
rw [hp, ← pnat.coe_inj, pnat.pow_coe, pnat.coe_bit0, pnat.one_coe] at hk,
nth_rewrite 1 [← pow_one 2] at hk,
replace hk := nat.pow_right_injective rfl.le hk,
rw [add_left_eq_self] at hk,
simp only [hp, hk, pow_one, pnat.coe_bit0, pnat.one_coe] at hζ,
simp only [hp, hk, show 1 / 2 = 0, by refl, coe_basis, pow_one, power_basis_gen,
pnat.coe_bit0, pnat.one_coe, totient_two, pow_zero, mul_one, mul_zero],
rw [power_basis_dim, hζ.eq_neg_one_of_two_right, show (-1 : L) = algebra_map K L (-1),
by simp, minpoly.eq_X_sub_C_of_algebra_map_inj _ (algebra_map K L).injective,
nat_degree_X_sub_C],
simp only [discr, trace_matrix_apply, matrix.det_unique, fin.default_eq_zero, fin.coe_zero,
pow_zero, trace_form_apply, mul_one],
rw [← (algebra_map K L).map_one, trace_algebra_map, finrank _ hirr, hp, hk],
{ simp },
{ apply_instance },
{ exact hcycl } },
{ exact discr_prime_pow_ne_two hζ hirr hk } }
end
/-- If `p` is a prime and `is_cyclotomic_extension {p ^ k} K L`, then there are `u : ℤˣ` and
`n : ℕ` such that the discriminant of `hζ.power_basis K` is `u * p ^ n`. Often this is enough and
less cumbersome to use than `is_cyclotomic_extension.discr_prime_pow`. -/
lemma discr_prime_pow_eq_unit_mul_pow [is_cyclotomic_extension {p ^ k} K L]
[hp : fact (p : ℕ).prime] (hζ : is_primitive_root ζ ↑(p ^ k))
(hirr : irreducible (cyclotomic (↑(p ^ k) : ℕ) K)) :
∃ (u : ℤˣ) (n : ℕ), discr K (hζ.power_basis K).basis = u * p ^ n :=
begin
rw [discr_prime_pow hζ hirr],
by_cases heven : even (((p ^ k : ℕ).totient) / 2),
{ refine ⟨1, (p : ℕ) ^ (k - 1) * ((p - 1) * k - 1), by simp [heven.neg_one_pow]⟩ },
{ exact ⟨-1, (p : ℕ) ^ (k - 1) * ((p - 1) * k - 1),
by simp [(odd_iff_not_even.2 heven).neg_one_pow]⟩ },
end
/-- If `p` is an odd prime and `is_cyclotomic_extension {p} K L`, then
`discr K (hζ.power_basis K).basis = (-1) ^ ((p - 1) / 2) * p ^ (p - 2)` if
`irreducible (cyclotomic p K)`. -/
lemma discr_odd_prime [is_cyclotomic_extension {p} K L] [hp : fact (p : ℕ).prime]
(hζ : is_primitive_root ζ p) (hirr : irreducible (cyclotomic p K)) (hodd : p ≠ 2) :
discr K (hζ.power_basis K).basis = (-1) ^ (((p : ℕ) - 1) / 2) * p ^ ((p : ℕ) - 2) :=
begin
haveI : is_cyclotomic_extension {p ^ (0 + 1)} K L,
{ rw [zero_add, pow_one],
apply_instance },
have hζ' : is_primitive_root ζ ↑(p ^ (0 + 1)) := by simpa using hζ,
convert discr_prime_pow_ne_two hζ' (by simpa [hirr]) (by simp [hodd]),
{ rw [zero_add, pow_one, totient_prime hp.out] },
{ rw [pow_zero, one_mul, zero_add, mul_one, nat.sub_sub] }
end
end is_cyclotomic_extension
|
e08306bde93cc661e6725681388022ec27f2db29 | bb31430994044506fa42fd667e2d556327e18dfe | /src/data/int/cast/defs.lean | bcb87ad797ead839541d96471cf2726dfbb583c6 | [
"Apache-2.0"
] | permissive | sgouezel/mathlib | 0cb4e5335a2ba189fa7af96d83a377f83270e503 | 00638177efd1b2534fc5269363ebf42a7871df9a | refs/heads/master | 1,674,527,483,042 | 1,673,665,568,000 | 1,673,665,568,000 | 119,598,202 | 0 | 0 | null | 1,517,348,647,000 | 1,517,348,646,000 | null | UTF-8 | Lean | false | false | 2,392 | lean | /-
Copyright (c) 2017 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Gabriel Ebner
-/
import data.nat.cast.defs
/-!
# Cast of integers
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
This file defines the *canonical* homomorphism from the integers into an
additive group with a one (typically a `ring`). In additive groups with a one
element, there exists a unique such homomorphism and we store it in the
`int_cast : ℤ → R` field.
Preferentially, the homomorphism is written as a coercion.
## Main declarations
* `int.cast`: Canonical homomorphism `ℤ → R`.
* `add_group_with_one`: Type class for `int.cast`.
-/
universes u
set_option old_structure_cmd true
attribute [simp] int.of_nat_eq_coe
/-- Default value for `add_group_with_one.int_cast`. -/
protected def int.cast_def {R : Type u} [has_nat_cast R] [has_neg R] : ℤ → R
| (n : ℕ) := n
| -[1+ n] := -(n+1 : ℕ)
/--
Type class for the canonical homomorphism `ℤ → R`.
-/
class has_int_cast (R : Type u) :=
(int_cast : ℤ → R)
/--
An `add_group_with_one` is an `add_group` with a `1`.
It also contains data for the unique homomorphisms `ℕ → R` and `ℤ → R`.
-/
@[protect_proj, ancestor has_int_cast add_group add_monoid_with_one]
class add_group_with_one (R : Type u)
extends has_int_cast R, add_group R, add_monoid_with_one R :=
(int_cast := int.cast_def)
(int_cast_of_nat : ∀ n : ℕ, int_cast n = (n : R) . control_laws_tac)
(int_cast_neg_succ_of_nat : ∀ n : ℕ, int_cast (-(n+1 : ℕ)) = -((n+1 : ℕ) : R) . control_laws_tac)
/-- An `add_comm_group_with_one` is an `add_group_with_one` satisfying `a + b = b + a`. -/
@[protect_proj, ancestor add_comm_group add_group_with_one]
class add_comm_group_with_one (R : Type u) extends add_comm_group R, add_group_with_one R
/-- Canonical homomorphism from the integers to any ring(-like) structure `R` -/
protected def int.cast {R : Type u} [has_int_cast R] (i : ℤ) : R := has_int_cast.int_cast i
open nat
namespace int
variables {R : Type u} [add_group_with_one R]
-- see Note [coercion into rings]
@[priority 900] instance cast_coe {R} [has_int_cast R] : has_coe_t ℤ R := ⟨int.cast⟩
theorem cast_of_nat (n : ℕ) : (of_nat n : R) = n := add_group_with_one.int_cast_of_nat n
end int
|
171ae2a05bf1677ffd46585aa18daaa86c552920 | fa02ed5a3c9c0adee3c26887a16855e7841c668b | /src/category_theory/fully_faithful.lean | 6be1dfb6141243ec0b4a56f49290969fcac82f7f | [
"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 | 8,417 | lean | /-
Copyright (c) 2018 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import category_theory.natural_isomorphism
import data.equiv.basic
-- declare the `v`'s first; see `category_theory.category` for an explanation
universes v₁ v₂ v₃ u₁ u₂ u₃
namespace category_theory
variables {C : Type u₁} [category.{v₁} C] {D : Type u₂} [category.{v₂} D]
/--
A functor `F : C ⥤ D` is full if for each `X Y : C`, `F.map` is surjective.
In fact, we use a constructive definition, so the `full F` typeclass contains data,
specifying a particular preimage of each `f : F.obj X ⟶ F.obj Y`.
See https://stacks.math.columbia.edu/tag/001C.
-/
class full (F : C ⥤ D) :=
(preimage : ∀ {X Y : C} (f : (F.obj X) ⟶ (F.obj Y)), X ⟶ Y)
(witness' : ∀ {X Y : C} (f : (F.obj X) ⟶ (F.obj Y)), F.map (preimage f) = f . obviously)
restate_axiom full.witness'
attribute [simp] full.witness
/--
A functor `F : C ⥤ D` is faithful if for each `X Y : C`, `F.map` is injective.
See https://stacks.math.columbia.edu/tag/001C.
-/
class faithful (F : C ⥤ D) : Prop :=
(map_injective' [] : ∀ {X Y : C}, function.injective (@functor.map _ _ _ _ F X Y) . obviously)
restate_axiom faithful.map_injective'
namespace functor
lemma map_injective (F : C ⥤ D) [faithful F] {X Y : C} :
function.injective $ @functor.map _ _ _ _ F X Y :=
faithful.map_injective F
/-- The specified preimage of a morphism under a full functor. -/
def preimage (F : C ⥤ D) [full F] {X Y : C} (f : F.obj X ⟶ F.obj Y) : X ⟶ Y :=
full.preimage.{v₁ v₂} f
@[simp] lemma image_preimage (F : C ⥤ D) [full F] {X Y : C} (f : F.obj X ⟶ F.obj Y) :
F.map (preimage F f) = f :=
by unfold preimage; obviously
end functor
variables {F : C ⥤ D} [full F] [faithful F] {X Y Z : C}
@[simp] lemma preimage_id : F.preimage (𝟙 (F.obj X)) = 𝟙 X :=
F.map_injective (by simp)
@[simp] lemma preimage_comp (f : F.obj X ⟶ F.obj Y) (g : F.obj Y ⟶ F.obj Z) :
F.preimage (f ≫ g) = F.preimage f ≫ F.preimage g :=
F.map_injective (by simp)
@[simp] lemma preimage_map (f : X ⟶ Y) :
F.preimage (F.map f) = f :=
F.map_injective (by simp)
/-- If `F : C ⥤ D` is fully faithful, every isomorphism `F.obj X ≅ F.obj Y` has a preimage. -/
def preimage_iso (f : (F.obj X) ≅ (F.obj Y)) : X ≅ Y :=
{ hom := F.preimage f.hom,
inv := F.preimage f.inv,
hom_inv_id' := F.map_injective (by simp),
inv_hom_id' := F.map_injective (by simp), }
@[simp] lemma preimage_iso_hom (f : (F.obj X) ≅ (F.obj Y)) :
(preimage_iso f).hom = F.preimage f.hom := rfl
@[simp] lemma preimage_iso_inv (f : (F.obj X) ≅ (F.obj Y)) :
(preimage_iso f).inv = F.preimage (f.inv) := rfl
@[simp] lemma preimage_iso_map_iso (f : X ≅ Y) : preimage_iso (F.map_iso f) = f :=
by tidy
variables (F)
/--
If the image of a morphism under a fully faithful functor in an isomorphism,
then the original morphisms is also an isomorphism.
-/
lemma is_iso_of_fully_faithful (f : X ⟶ Y) [is_iso (F.map f)] : is_iso f :=
⟨⟨F.preimage (inv (F.map f)),
⟨F.map_injective (by simp), F.map_injective (by simp)⟩⟩⟩
/-- If `F` is fully faithful, we have an equivalence of hom-sets `X ⟶ Y` and `F X ⟶ F Y`. -/
def equiv_of_fully_faithful {X Y} : (X ⟶ Y) ≃ (F.obj X ⟶ F.obj Y) :=
{ to_fun := λ f, F.map f,
inv_fun := λ f, F.preimage f,
left_inv := λ f, by simp,
right_inv := λ f, by simp }
@[simp]
lemma equiv_of_fully_faithful_apply {X Y : C} (f : X ⟶ Y) :
equiv_of_fully_faithful F f = F.map f := rfl
@[simp]
lemma equiv_of_fully_faithful_symm_apply {X Y} (f : F.obj X ⟶ F.obj Y) :
(equiv_of_fully_faithful F).symm f = F.preimage f := rfl
end category_theory
namespace category_theory
variables {C : Type u₁} [category.{v₁} C]
instance full.id : full (𝟭 C) :=
{ preimage := λ _ _ f, f }
instance faithful.id : faithful (𝟭 C) := by obviously
variables {D : Type u₂} [category.{v₂} D] {E : Type u₃} [category.{v₃} E]
variables (F F' : C ⥤ D) (G : D ⥤ E)
instance faithful.comp [faithful F] [faithful G] : faithful (F ⋙ G) :=
{ map_injective' := λ _ _ _ _ p, F.map_injective (G.map_injective p) }
lemma faithful.of_comp [faithful $ F ⋙ G] : faithful F :=
{ map_injective' := λ X Y, (F ⋙ G).map_injective.of_comp }
section
variables {F F'}
/-- If `F` is full, and naturally isomorphic to some `F'`, then `F'` is also full. -/
def full.of_iso [full F] (α : F ≅ F') : full F' :=
{ preimage := λ X Y f, F.preimage ((α.app X).hom ≫ f ≫ (α.app Y).inv),
witness' := λ X Y f, by simp [←nat_iso.naturality_1 α], }
lemma faithful.of_iso [faithful F] (α : F ≅ F') : faithful F' :=
{ map_injective' := λ X Y f f' h, F.map_injective
(by rw [←nat_iso.naturality_1 α.symm, h, nat_iso.naturality_1 α.symm]) }
end
variables {F G}
lemma faithful.of_comp_iso {H : C ⥤ E} [ℋ : faithful H] (h : F ⋙ G ≅ H) : faithful F :=
@faithful.of_comp _ _ _ _ _ _ F G (faithful.of_iso h.symm)
alias faithful.of_comp_iso ← category_theory.iso.faithful_of_comp
-- We could prove this from `faithful.of_comp_iso` using `eq_to_iso`,
-- but that would introduce a cyclic import.
lemma faithful.of_comp_eq {H : C ⥤ E} [ℋ : faithful H] (h : F ⋙ G = H) : faithful F :=
@faithful.of_comp _ _ _ _ _ _ F G (h.symm ▸ ℋ)
alias faithful.of_comp_eq ← eq.faithful_of_comp
variables (F G)
/-- “Divide” a functor by a faithful functor. -/
protected def faithful.div (F : C ⥤ E) (G : D ⥤ E) [faithful G]
(obj : C → D) (h_obj : ∀ X, G.obj (obj X) = F.obj X)
(map : Π {X Y}, (X ⟶ Y) → (obj X ⟶ obj Y))
(h_map : ∀ {X Y} {f : X ⟶ Y}, G.map (map f) == F.map f) :
C ⥤ D :=
{ obj := obj,
map := @map,
map_id' :=
begin
assume X,
apply G.map_injective,
apply eq_of_heq,
transitivity F.map (𝟙 X), from h_map,
rw [F.map_id, G.map_id, h_obj X]
end,
map_comp' :=
begin
assume X Y Z f g,
apply G.map_injective,
apply eq_of_heq,
transitivity F.map (f ≫ g), from h_map,
rw [F.map_comp, G.map_comp],
congr' 1;
try { exact (h_obj _).symm };
exact h_map.symm
end }
-- This follows immediately from `functor.hext` (`functor.hext h_obj @h_map`),
-- but importing `category_theory.eq_to_hom` causes an import loop:
-- category_theory.eq_to_hom → category_theory.opposites →
-- category_theory.equivalence → category_theory.fully_faithful
lemma faithful.div_comp (F : C ⥤ E) [faithful F] (G : D ⥤ E) [faithful G]
(obj : C → D) (h_obj : ∀ X, G.obj (obj X) = F.obj X)
(map : Π {X Y}, (X ⟶ Y) → (obj X ⟶ obj Y))
(h_map : ∀ {X Y} {f : X ⟶ Y}, G.map (map f) == F.map f) :
(faithful.div F G obj @h_obj @map @h_map) ⋙ G = F :=
begin
casesI F with F_obj _ _ _, casesI G with G_obj _ _ _,
unfold faithful.div functor.comp,
unfold_projs at h_obj,
have: F_obj = G_obj ∘ obj := (funext h_obj).symm,
substI this,
congr,
funext,
exact eq_of_heq h_map
end
lemma faithful.div_faithful (F : C ⥤ E) [faithful F] (G : D ⥤ E) [faithful G]
(obj : C → D) (h_obj : ∀ X, G.obj (obj X) = F.obj X)
(map : Π {X Y}, (X ⟶ Y) → (obj X ⟶ obj Y))
(h_map : ∀ {X Y} {f : X ⟶ Y}, G.map (map f) == F.map f) :
faithful (faithful.div F G obj @h_obj @map @h_map) :=
(faithful.div_comp F G _ h_obj _ @h_map).faithful_of_comp
instance full.comp [full F] [full G] : full (F ⋙ G) :=
{ preimage := λ _ _ f, F.preimage (G.preimage f) }
/--
Given a natural isomorphism between `F ⋙ H` and `G ⋙ H` for a fully faithful functor `H`, we
can 'cancel' it to give a natural iso between `F` and `G`.
-/
def fully_faithful_cancel_right {F G : C ⥤ D} (H : D ⥤ E)
[full H] [faithful H] (comp_iso: F ⋙ H ≅ G ⋙ H) : F ≅ G :=
nat_iso.of_components
(λ X, preimage_iso (comp_iso.app X))
(λ X Y f, H.map_injective (by simpa using comp_iso.hom.naturality f))
@[simp]
lemma fully_faithful_cancel_right_hom_app {F G : C ⥤ D} {H : D ⥤ E}
[full H] [faithful H] (comp_iso: F ⋙ H ≅ G ⋙ H) (X : C) :
(fully_faithful_cancel_right H comp_iso).hom.app X = H.preimage (comp_iso.hom.app X) :=
rfl
@[simp]
lemma fully_faithful_cancel_right_inv_app {F G : C ⥤ D} {H : D ⥤ E}
[full H] [faithful H] (comp_iso: F ⋙ H ≅ G ⋙ H) (X : C) :
(fully_faithful_cancel_right H comp_iso).inv.app X = H.preimage (comp_iso.inv.app X) :=
rfl
end category_theory
|
47b19654e5b5c9dd149a4dd6254d8c17358707e3 | 94e33a31faa76775069b071adea97e86e218a8ee | /src/order/complete_boolean_algebra.lean | 7f16480f758b945fb9dfa95628b5d019c02ccbd7 | [
"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 | 13,897 | 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, Yaël Dillies
-/
import order.complete_lattice
import order.directed
/-!
# Frames, completely distributive lattices and Boolean algebras
In this file we define and provide API for frames, completely distributive lattices and completely
distributive Boolean algebras.
## Typeclasses
* `order.frame`: Frame: A complete lattice whose `⊓` distributes over `⨆`.
* `order.coframe`: Coframe: A complete lattice whose `⊔` distributes over `⨅`.
* `complete_distrib_lattice`: Completely distributive lattices: A complete lattice whose `⊓` and `⊔`
distribute over `⨆` and `⨅` respectively.
* `complete_boolean_algebra`: Completely distributive Boolean algebra: A Boolean algebra whose `⊓`
and `⊔` distribute over `⨆` and `⨅` respectively.
A set of opens gives rise to a topological space precisely if it forms a frame. Such a frame is also
completely distributive, but not all frames are. `filter` is a coframe but not a completely
distributive lattice.
## TODO
Add instances for `prod`
## References
* [Wikipedia, *Complete Heyting algebra*](https://en.wikipedia.org/wiki/Complete_Heyting_algebra)
* [Francis Borceux, *Handbook of Categorical Algebra III*][borceux-vol3]
-/
set_option old_structure_cmd true
open function set
universes u v w
variables {α : Type u} {β : Type v} {ι : Sort w} {κ : ι → Sort*}
/-- A frame, aka complete Heyting algebra, is a complete lattice whose `⊓` distributes over `⨆`. -/
class order.frame (α : Type*) extends complete_lattice α :=
(inf_Sup_le_supr_inf (a : α) (s : set α) : a ⊓ Sup s ≤ ⨆ b ∈ s, a ⊓ b)
/-- A coframe, aka complete Brouwer algebra or complete co-Heyting algebra, is a complete lattice
whose `⊔` distributes over `⨅`. -/
class order.coframe (α : Type*) extends complete_lattice α :=
(infi_sup_le_sup_Inf (a : α) (s : set α) : (⨅ b ∈ s, a ⊔ b) ≤ a ⊔ Inf s)
open order
/-- A completely distributive lattice is a complete lattice whose `⊔` and `⊓` respectively
distribute over `⨅` and `⨆`. -/
class complete_distrib_lattice (α : Type*) extends frame α :=
(infi_sup_le_sup_Inf : ∀ a s, (⨅ b ∈ s, a ⊔ b) ≤ a ⊔ Inf s)
@[priority 100] -- See note [lower instance priority]
instance complete_distrib_lattice.to_coframe [complete_distrib_lattice α] : coframe α :=
{ .. ‹complete_distrib_lattice α› }
section frame
variables [frame α] {s t : set α} {a b : α}
instance order_dual.coframe : coframe αᵒᵈ :=
{ infi_sup_le_sup_Inf := frame.inf_Sup_le_supr_inf, ..order_dual.complete_lattice α }
lemma inf_Sup_eq : a ⊓ Sup s = ⨆ b ∈ s, a ⊓ b :=
(frame.inf_Sup_le_supr_inf _ _).antisymm supr_inf_le_inf_Sup
lemma Sup_inf_eq : Sup s ⊓ b = ⨆ a ∈ s, a ⊓ b :=
by simpa only [inf_comm] using @inf_Sup_eq α _ s b
lemma supr_inf_eq (f : ι → α) (a : α) : (⨆ i, f i) ⊓ a = ⨆ i, f i ⊓ a :=
by rw [supr, Sup_inf_eq, supr_range]
lemma inf_supr_eq (a : α) (f : ι → α) : a ⊓ (⨆ i, f i) = ⨆ i, a ⊓ f i :=
by simpa only [inf_comm] using supr_inf_eq f a
lemma bsupr_inf_eq {f : Π i, κ i → α} (a : α) : (⨆ i j, f i j) ⊓ a = ⨆ i j, f i j ⊓ a :=
by simp only [supr_inf_eq]
lemma inf_bsupr_eq {f : Π i, κ i → α} (a : α) : a ⊓ (⨆ i j, f i j) = ⨆ i j, a ⊓ f i j :=
by simp only [inf_supr_eq]
lemma supr_inf_supr {ι ι' : Type*} {f : ι → α} {g : ι' → α} :
(⨆ i, f i) ⊓ (⨆ j, g j) = ⨆ i : ι × ι', f i.1 ⊓ g i.2 :=
by simp only [inf_supr_eq, supr_inf_eq, supr_prod]
lemma bsupr_inf_bsupr {ι ι' : Type*} {f : ι → α} {g : ι' → α} {s : set ι} {t : set ι'} :
(⨆ i ∈ s, f i) ⊓ (⨆ j ∈ t, g j) = ⨆ p ∈ s ×ˢ t, f (p : ι × ι').1 ⊓ g p.2 :=
begin
simp only [supr_subtype', supr_inf_supr],
exact (equiv.surjective _).supr_congr (equiv.set.prod s t).symm (λ x, rfl)
end
lemma Sup_inf_Sup : Sup s ⊓ Sup t = ⨆ p ∈ s ×ˢ t, (p : α × α).1 ⊓ p.2 :=
by simp only [Sup_eq_supr, bsupr_inf_bsupr]
lemma supr_disjoint_iff {f : ι → α} : disjoint (⨆ i, f i) a ↔ ∀ i, disjoint (f i) a :=
by simp only [disjoint_iff, supr_inf_eq, supr_eq_bot]
lemma disjoint_supr_iff {f : ι → α} : disjoint a (⨆ i, f i) ↔ ∀ i, disjoint a (f i) :=
by simpa only [disjoint.comm] using supr_disjoint_iff
lemma supr₂_disjoint_iff {f : Π i, κ i → α} :
disjoint (⨆ i j, f i j) a ↔ ∀ i j, disjoint (f i j) a :=
by simp_rw supr_disjoint_iff
lemma disjoint_supr₂_iff {f : Π i, κ i → α} :
disjoint a (⨆ i j, f i j) ↔ ∀ i j, disjoint a (f i j) :=
by simp_rw disjoint_supr_iff
lemma Sup_disjoint_iff {s : set α} : disjoint (Sup s) a ↔ ∀ b ∈ s, disjoint b a :=
by simp only [disjoint_iff, Sup_inf_eq, supr_eq_bot]
lemma disjoint_Sup_iff {s : set α} : disjoint a (Sup s) ↔ ∀ b ∈ s, disjoint a b :=
by simpa only [disjoint.comm] using Sup_disjoint_iff
lemma supr_inf_of_monotone {ι : Type*} [preorder ι] [is_directed ι (≤)] {f g : ι → α}
(hf : monotone f) (hg : monotone g) :
(⨆ i, f i ⊓ g i) = (⨆ i, f i) ⊓ (⨆ i, g i) :=
begin
refine (le_supr_inf_supr f g).antisymm _,
rw [supr_inf_supr],
refine supr_mono' (λ i, _),
rcases directed_of (≤) i.1 i.2 with ⟨j, h₁, h₂⟩,
exact ⟨j, inf_le_inf (hf h₁) (hg h₂)⟩
end
lemma supr_inf_of_antitone {ι : Type*} [preorder ι] [is_directed ι (swap (≤))] {f g : ι → α}
(hf : antitone f) (hg : antitone g) :
(⨆ i, f i ⊓ g i) = (⨆ i, f i) ⊓ (⨆ i, g i) :=
@supr_inf_of_monotone α _ ιᵒᵈ _ _ f g hf.dual_left hg.dual_left
instance pi.frame {ι : Type*} {π : ι → Type*} [Π i, frame (π i)] : frame (Π i, π i) :=
{ inf_Sup_le_supr_inf := λ a s i,
by simp only [complete_lattice.Sup, Sup_apply, supr_apply, pi.inf_apply, inf_supr_eq,
← supr_subtype''],
..pi.complete_lattice }
@[priority 100] -- see Note [lower instance priority]
instance frame.to_distrib_lattice : distrib_lattice α :=
distrib_lattice.of_inf_sup_le $ λ a b c,
by rw [←Sup_pair, ←Sup_pair, inf_Sup_eq, ←Sup_image, image_pair]
end frame
section coframe
variables [coframe α] {s t : set α} {a b : α}
instance order_dual.frame : frame αᵒᵈ :=
{ inf_Sup_le_supr_inf := coframe.infi_sup_le_sup_Inf, ..order_dual.complete_lattice α }
lemma sup_Inf_eq : a ⊔ Inf s = ⨅ b ∈ s, a ⊔ b := @inf_Sup_eq αᵒᵈ _ _ _
lemma Inf_sup_eq : Inf s ⊔ b = ⨅ a ∈ s, a ⊔ b := @Sup_inf_eq αᵒᵈ _ _ _
lemma infi_sup_eq (f : ι → α) (a : α) : (⨅ i, f i) ⊔ a = ⨅ i, f i ⊔ a := @supr_inf_eq αᵒᵈ _ _ _ _
lemma sup_infi_eq (a : α) (f : ι → α) : a ⊔ (⨅ i, f i) = ⨅ i, a ⊔ f i := @inf_supr_eq αᵒᵈ _ _ _ _
lemma binfi_sup_eq {f : Π i, κ i → α} (a : α) : (⨅ i j, f i j) ⊔ a = ⨅ i j, f i j ⊔ a :=
@bsupr_inf_eq αᵒᵈ _ _ _ _ _
lemma sup_binfi_eq {f : Π i, κ i → α} (a : α) : a ⊔ (⨅ i j, f i j) = ⨅ i j, a ⊔ f i j :=
@inf_bsupr_eq αᵒᵈ _ _ _ _ _
lemma infi_sup_infi {ι ι' : Type*} {f : ι → α} {g : ι' → α} :
(⨅ i, f i) ⊔ (⨅ i, g i) = ⨅ i : ι × ι', f i.1 ⊔ g i.2 :=
@supr_inf_supr αᵒᵈ _ _ _ _ _
lemma binfi_sup_binfi {ι ι' : Type*} {f : ι → α} {g : ι' → α} {s : set ι} {t : set ι'} :
(⨅ i ∈ s, f i) ⊔ (⨅ j ∈ t, g j) = ⨅ p ∈ s ×ˢ t, f (p : ι × ι').1 ⊔ g p.2 :=
@bsupr_inf_bsupr αᵒᵈ _ _ _ _ _ _ _
theorem Inf_sup_Inf : Inf s ⊔ Inf t = (⨅ p ∈ s ×ˢ t, (p : α × α).1 ⊔ p.2) :=
@Sup_inf_Sup αᵒᵈ _ _ _
lemma infi_sup_of_monotone {ι : Type*} [preorder ι] [is_directed ι (swap (≤))] {f g : ι → α}
(hf : monotone f) (hg : monotone g) :
(⨅ i, f i ⊔ g i) = (⨅ i, f i) ⊔ (⨅ i, g i) :=
supr_inf_of_antitone hf.dual_right hg.dual_right
lemma infi_sup_of_antitone {ι : Type*} [preorder ι] [is_directed ι (≤)] {f g : ι → α}
(hf : antitone f) (hg : antitone g) :
(⨅ i, f i ⊔ g i) = (⨅ i, f i) ⊔ (⨅ i, g i) :=
supr_inf_of_monotone hf.dual_right hg.dual_right
instance pi.coframe {ι : Type*} {π : ι → Type*} [Π i, coframe (π i)] : coframe (Π i, π i) :=
{ Inf := Inf,
infi_sup_le_sup_Inf := λ a s i,
by simp only [←sup_infi_eq, Inf_apply, ←infi_subtype'', infi_apply, pi.sup_apply],
..pi.complete_lattice }
@[priority 100] -- see Note [lower instance priority]
instance coframe.to_distrib_lattice : distrib_lattice α :=
{ le_sup_inf := λ a b c, by rw [←Inf_pair, ←Inf_pair, sup_Inf_eq, ←Inf_image, image_pair],
..‹coframe α› }
end coframe
section complete_distrib_lattice
variables [complete_distrib_lattice α] {a b : α} {s t : set α}
instance : complete_distrib_lattice αᵒᵈ := { ..order_dual.frame, ..order_dual.coframe }
instance pi.complete_distrib_lattice {ι : Type*} {π : ι → Type*}
[Π i, complete_distrib_lattice (π i)] : complete_distrib_lattice (Π i, π i) :=
{ ..pi.frame, ..pi.coframe }
end complete_distrib_lattice
/-- A complete Boolean algebra is a completely distributive Boolean algebra. -/
class complete_boolean_algebra α extends boolean_algebra α, complete_distrib_lattice α
instance pi.complete_boolean_algebra {ι : Type*} {π : ι → Type*}
[∀ i, complete_boolean_algebra (π i)] : complete_boolean_algebra (Π i, π i) :=
{ .. pi.boolean_algebra, .. pi.complete_distrib_lattice }
instance Prop.complete_boolean_algebra : complete_boolean_algebra Prop :=
{ infi_sup_le_sup_Inf := λ p s, iff.mp $
by simp only [forall_or_distrib_left, complete_lattice.Inf, infi_Prop_eq, sup_Prop_eq],
inf_Sup_le_supr_inf := λ p s, iff.mp $
by simp only [complete_lattice.Sup, exists_and_distrib_left, inf_Prop_eq, supr_Prop_eq],
.. Prop.boolean_algebra, .. Prop.complete_lattice }
section complete_boolean_algebra
variables [complete_boolean_algebra α] {a b : α} {s : set α} {f : ι → α}
theorem compl_infi : (infi f)ᶜ = (⨆ i, (f i)ᶜ) :=
le_antisymm
(compl_le_of_compl_le $ le_infi $ λ i, compl_le_of_compl_le $ le_supr (compl ∘ f) i)
(supr_le $ λ i, compl_le_compl $ infi_le _ _)
theorem compl_supr : (supr f)ᶜ = (⨅ i, (f i)ᶜ) :=
compl_injective (by simp [compl_infi])
lemma compl_Inf : (Inf s)ᶜ = (⨆ i ∈ s, iᶜ) := by simp only [Inf_eq_infi, compl_infi]
lemma compl_Sup : (Sup s)ᶜ = (⨅ i ∈ s, iᶜ) := by simp only [Sup_eq_supr, compl_supr]
lemma compl_Inf' : (Inf s)ᶜ = Sup (compl '' s) := compl_Inf.trans Sup_image.symm
lemma compl_Sup' : (Sup s)ᶜ = Inf (compl '' s) := compl_Sup.trans Inf_image.symm
end complete_boolean_algebra
section lift
/-- Pullback an `order.frame` along an injection. -/
@[reducible] -- See note [reducible non-instances]
protected def function.injective.frame [has_sup α] [has_inf α] [has_Sup α] [has_Inf α] [has_top α]
[has_bot α] [frame β] (f : α → β) (hf : injective f) (map_sup : ∀ a b, f (a ⊔ b) = f a ⊔ f b)
(map_inf : ∀ a b, f (a ⊓ b) = f a ⊓ f b) (map_Sup : ∀ s, f (Sup s) = ⨆ a ∈ s, f a)
(map_Inf : ∀ s, f (Inf s) = ⨅ a ∈ s, f a) (map_top : f ⊤ = ⊤) (map_bot : f ⊥ = ⊥) :
frame α :=
{ inf_Sup_le_supr_inf := λ a s, begin
change f (a ⊓ Sup s) ≤ f _,
rw [←Sup_image, map_inf, map_Sup s, inf_bsupr_eq],
simp_rw ←map_inf,
exact ((map_Sup _).trans supr_image).ge,
end,
..hf.complete_lattice f map_sup map_inf map_Sup map_Inf map_top map_bot }
/-- Pullback an `order.coframe` along an injection. -/
@[reducible] -- See note [reducible non-instances]
protected def function.injective.coframe [has_sup α] [has_inf α] [has_Sup α] [has_Inf α] [has_top α]
[has_bot α] [coframe β] (f : α → β) (hf : injective f) (map_sup : ∀ a b, f (a ⊔ b) = f a ⊔ f b)
(map_inf : ∀ a b, f (a ⊓ b) = f a ⊓ f b) (map_Sup : ∀ s, f (Sup s) = ⨆ a ∈ s, f a)
(map_Inf : ∀ s, f (Inf s) = ⨅ a ∈ s, f a) (map_top : f ⊤ = ⊤) (map_bot : f ⊥ = ⊥) :
coframe α :=
{ infi_sup_le_sup_Inf := λ a s, begin
change f _ ≤ f (a ⊔ Inf s),
rw [←Inf_image, map_sup, map_Inf s, sup_binfi_eq],
simp_rw ←map_sup,
exact ((map_Inf _).trans infi_image).le,
end,
..hf.complete_lattice f map_sup map_inf map_Sup map_Inf map_top map_bot }
/-- Pullback a `complete_distrib_lattice` along an injection. -/
@[reducible] -- See note [reducible non-instances]
protected def function.injective.complete_distrib_lattice [has_sup α] [has_inf α] [has_Sup α]
[has_Inf α] [has_top α] [has_bot α] [complete_distrib_lattice β]
(f : α → β) (hf : function.injective f) (map_sup : ∀ a b, f (a ⊔ b) = f a ⊔ f b)
(map_inf : ∀ a b, f (a ⊓ b) = f a ⊓ f b) (map_Sup : ∀ s, f (Sup s) = ⨆ a ∈ s, f a)
(map_Inf : ∀ s, f (Inf s) = ⨅ a ∈ s, f a) (map_top : f ⊤ = ⊤) (map_bot : f ⊥ = ⊥) :
complete_distrib_lattice α :=
{ ..hf.frame f map_sup map_inf map_Sup map_Inf map_top map_bot,
..hf.coframe f map_sup map_inf map_Sup map_Inf map_top map_bot }
/-- Pullback a `complete_boolean_algebra` along an injection. -/
@[reducible] -- See note [reducible non-instances]
protected def function.injective.complete_boolean_algebra [has_sup α] [has_inf α] [has_Sup α]
[has_Inf α] [has_top α] [has_bot α] [has_compl α] [has_sdiff α] [complete_boolean_algebra β]
(f : α → β) (hf : function.injective f) (map_sup : ∀ a b, f (a ⊔ b) = f a ⊔ f b)
(map_inf : ∀ a b, f (a ⊓ b) = f a ⊓ f b) (map_Sup : ∀ s, f (Sup s) = ⨆ a ∈ s, f a)
(map_Inf : ∀ s, f (Inf s) = ⨅ a ∈ s, f a) (map_top : f ⊤ = ⊤) (map_bot : f ⊥ = ⊥)
(map_compl : ∀ a, f aᶜ = (f a)ᶜ) (map_sdiff : ∀ a b, f (a \ b) = f a \ f b) :
complete_boolean_algebra α :=
{ ..hf.complete_distrib_lattice f map_sup map_inf map_Sup map_Inf map_top map_bot,
..hf.boolean_algebra f map_sup map_inf map_top map_bot map_compl map_sdiff }
end lift
|
6edb0fbf3879762e746a6f5907d0955840be1fd7 | 968e2f50b755d3048175f176376eff7139e9df70 | /examples/prop_logic_lean_summary/unnamed_84.lean | 0df13adc0c7536dcf08f9d6e1a61fc1a098d4577 | [] | no_license | gihanmarasingha/mth1001_sphinx | 190a003269ba5e54717b448302a27ca26e31d491 | 05126586cbf5786e521be1ea2ef5b4ba3c44e74a | refs/heads/master | 1,672,913,933,677 | 1,604,516,583,000 | 1,604,516,583,000 | 309,245,750 | 1 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 77 | lean | variable p : Prop
-- BEGIN
example (h : p) : p :=
begin
exact h,
end
-- END |
a21a422af02d91c2130f6ecd119b77c89eaeb89c | d9d511f37a523cd7659d6f573f990e2a0af93c6f | /src/measure_theory/function/lp_space.lean | 33f5fa3f03c11fef1dc101d7cbdec28281559a67 | [
"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 | 102,132 | lean | /-
Copyright (c) 2020 Rémy Degenne. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Rémy Degenne, Sébastien Gouëzel
-/
import analysis.normed_space.indicator_function
import analysis.normed_space.normed_group_hom
import measure_theory.function.ess_sup
import measure_theory.function.ae_eq_fun
import measure_theory.integral.mean_inequalities
import topology.continuous_function.compact
/-!
# ℒp space and Lp space
This file describes properties of almost everywhere measurable functions with finite seminorm,
denoted by `snorm f p μ` and defined for `p:ℝ≥0∞` as `0` if `p=0`, `(∫ ∥f a∥^p ∂μ) ^ (1/p)` for
`0 < p < ∞` and `ess_sup ∥f∥ μ` for `p=∞`.
The Prop-valued `mem_ℒp f p μ` states that a function `f : α → E` has finite seminorm.
The space `Lp E p μ` is the subtype of elements of `α →ₘ[μ] E` (see ae_eq_fun) such that
`snorm f p μ` is finite. For `1 ≤ p`, `snorm` defines a norm and `Lp` is a complete metric space.
## Main definitions
* `snorm' f p μ` : `(∫ ∥f a∥^p ∂μ) ^ (1/p)` for `f : α → F` and `p : ℝ`, where `α` is a measurable
space and `F` is a normed group.
* `snorm_ess_sup f μ` : seminorm in `ℒ∞`, equal to the essential supremum `ess_sup ∥f∥ μ`.
* `snorm f p μ` : for `p : ℝ≥0∞`, seminorm in `ℒp`, equal to `0` for `p=0`, to `snorm' f p μ`
for `0 < p < ∞` and to `snorm_ess_sup f μ` for `p = ∞`.
* `mem_ℒp f p μ` : property that the function `f` is almost everywhere measurable and has finite
p-seminorm for measure `μ` (`snorm f p μ < ∞`)
* `Lp E p μ` : elements of `α →ₘ[μ] E` (see ae_eq_fun) such that `snorm f p μ` is finite. Defined
as an `add_subgroup` of `α →ₘ[μ] E`.
Lipschitz functions vanishing at zero act by composition on `Lp`. We define this action, and prove
that it is continuous. In particular,
* `continuous_linear_map.comp_Lp` defines the action on `Lp` of a continuous linear map.
* `Lp.pos_part` is the positive part of an `Lp` function.
* `Lp.neg_part` is the negative part of an `Lp` function.
When `α` is a topological space equipped with a finite Borel measure, there is a bounded linear map
from the normed space of bounded continuous functions (`α →ᵇ E`) to `Lp E p μ`. We construct this
as `bounded_continuous_function.to_Lp`.
## Notations
* `α →₁[μ] E` : the type `Lp E 1 μ`.
* `α →₂[μ] E` : the type `Lp E 2 μ`.
## Implementation
Since `Lp` is defined as an `add_subgroup`, dot notation does not work. Use `Lp.measurable f` to
say that the coercion of `f` to a genuine function is measurable, instead of the non-working
`f.measurable`.
To prove that two `Lp` elements are equal, it suffices to show that their coercions to functions
coincide almost everywhere (this is registered as an `ext` rule). This can often be done using
`filter_upwards`. For instance, a proof from first principles that `f + (g + h) = (f + g) + h`
could read (in the `Lp` namespace)
```
example (f g h : Lp E p μ) : (f + g) + h = f + (g + h) :=
begin
ext1,
filter_upwards [coe_fn_add (f + g) h, coe_fn_add f g, coe_fn_add f (g + h), coe_fn_add g h],
assume a ha1 ha2 ha3 ha4,
simp only [ha1, ha2, ha3, ha4, add_assoc],
end
```
The lemma `coe_fn_add` states that the coercion of `f + g` coincides almost everywhere with the sum
of the coercions of `f` and `g`. All such lemmas use `coe_fn` in their name, to distinguish the
function coercion from the coercion to almost everywhere defined functions.
-/
noncomputable theory
open topological_space measure_theory filter
open_locale nnreal ennreal big_operators topological_space
lemma fact_one_le_one_ennreal : fact ((1 : ℝ≥0∞) ≤ 1) := ⟨le_refl _⟩
lemma fact_one_le_two_ennreal : fact ((1 : ℝ≥0∞) ≤ 2) :=
⟨ennreal.coe_le_coe.2 (show (1 : ℝ≥0) ≤ 2, by norm_num)⟩
lemma fact_one_le_top_ennreal : fact ((1 : ℝ≥0∞) ≤ ∞) := ⟨le_top⟩
local attribute [instance] fact_one_le_one_ennreal fact_one_le_two_ennreal fact_one_le_top_ennreal
variables {α E F G : Type*} {m m0 : measurable_space α} {p : ℝ≥0∞} {q : ℝ} {μ ν : measure α}
[measurable_space E] [normed_group E]
[normed_group F] [normed_group G]
namespace measure_theory
section ℒp
/-!
### ℒp seminorm
We define the ℒp seminorm, denoted by `snorm f p μ`. For real `p`, it is given by an integral
formula (for which we use the notation `snorm' f p μ`), and for `p = ∞` it is the essential
supremum (for which we use the notation `snorm_ess_sup f μ`).
We also define a predicate `mem_ℒp f p μ`, requesting that a function is almost everywhere
measurable and has finite `snorm f p μ`.
This paragraph is devoted to the basic properties of these definitions. It is constructed as
follows: for a given property, we prove it for `snorm'` and `snorm_ess_sup` when it makes sense,
deduce it for `snorm`, and translate it in terms of `mem_ℒp`.
-/
section ℒp_space_definition
/-- `(∫ ∥f a∥^q ∂μ) ^ (1/q)`, which is a seminorm on the space of measurable functions for which
this quantity is finite -/
def snorm' {m : measurable_space α} (f : α → F) (q : ℝ) (μ : measure α) : ℝ≥0∞ :=
(∫⁻ a, (nnnorm (f a))^q ∂μ) ^ (1/q)
/-- seminorm for `ℒ∞`, equal to the essential supremum of `∥f∥`. -/
def snorm_ess_sup {m : measurable_space α} (f : α → F) (μ : measure α) :=
ess_sup (λ x, (nnnorm (f x) : ℝ≥0∞)) μ
/-- `ℒp` seminorm, equal to `0` for `p=0`, to `(∫ ∥f a∥^p ∂μ) ^ (1/p)` for `0 < p < ∞` and to
`ess_sup ∥f∥ μ` for `p = ∞`. -/
def snorm {m : measurable_space α} (f : α → F) (p : ℝ≥0∞) (μ : measure α) : ℝ≥0∞ :=
if p = 0 then 0 else (if p = ∞ then snorm_ess_sup f μ else snorm' f (ennreal.to_real p) μ)
lemma snorm_eq_snorm' (hp_ne_zero : p ≠ 0) (hp_ne_top : p ≠ ∞) {f : α → F} :
snorm f p μ = snorm' f (ennreal.to_real p) μ :=
by simp [snorm, hp_ne_zero, hp_ne_top]
lemma snorm_eq_lintegral_rpow_nnnorm (hp_ne_zero : p ≠ 0) (hp_ne_top : p ≠ ∞) {f : α → F} :
snorm f p μ = (∫⁻ x, (nnnorm (f x)) ^ p.to_real ∂μ) ^ (1 / p.to_real) :=
by rw [snorm_eq_snorm' hp_ne_zero hp_ne_top, snorm']
lemma snorm_one_eq_lintegral_nnnorm {f : α → F} : snorm f 1 μ = ∫⁻ x, nnnorm (f x) ∂μ :=
by simp_rw [snorm_eq_lintegral_rpow_nnnorm one_ne_zero ennreal.coe_ne_top, ennreal.one_to_real,
one_div_one, ennreal.rpow_one]
@[simp] lemma snorm_exponent_top {f : α → F} : snorm f ∞ μ = snorm_ess_sup f μ := by simp [snorm]
/-- The property that `f:α→E` is ae_measurable and `(∫ ∥f a∥^p ∂μ)^(1/p)` is finite if `p < ∞`, or
`ess_sup f < ∞` if `p = ∞`. -/
def mem_ℒp {α} {m : measurable_space α} (f : α → E) (p : ℝ≥0∞) (μ : measure α) : Prop :=
ae_measurable f μ ∧ snorm f p μ < ∞
lemma mem_ℒp.ae_measurable {f : α → E} {p : ℝ≥0∞} (h : mem_ℒp f p μ) : ae_measurable f μ := h.1
lemma lintegral_rpow_nnnorm_eq_rpow_snorm' {f : α → F} (hq0_lt : 0 < q) :
∫⁻ a, (nnnorm (f a)) ^ q ∂μ = (snorm' f q μ) ^ q :=
begin
rw [snorm', ←ennreal.rpow_mul, one_div, inv_mul_cancel, ennreal.rpow_one],
exact (ne_of_lt hq0_lt).symm,
end
end ℒp_space_definition
section top
lemma mem_ℒp.snorm_lt_top {f : α → E} (hfp : mem_ℒp f p μ) : snorm f p μ < ∞ := hfp.2
lemma mem_ℒp.snorm_ne_top {f : α → E} (hfp : mem_ℒp f p μ) : snorm f p μ ≠ ∞ := ne_of_lt (hfp.2)
lemma lintegral_rpow_nnnorm_lt_top_of_snorm'_lt_top {f : α → F} (hq0_lt : 0 < q)
(hfq : snorm' f q μ < ∞) :
∫⁻ a, (nnnorm (f a)) ^ q ∂μ < ∞ :=
begin
rw lintegral_rpow_nnnorm_eq_rpow_snorm' hq0_lt,
exact ennreal.rpow_lt_top_of_nonneg (le_of_lt hq0_lt) (ne_of_lt hfq),
end
lemma lintegral_rpow_nnnorm_lt_top_of_snorm_lt_top {f : α → F} (hp_ne_zero : p ≠ 0)
(hp_ne_top : p ≠ ∞) (hfp : snorm f p μ < ∞) :
∫⁻ a, (nnnorm (f a)) ^ p.to_real ∂μ < ∞ :=
begin
apply lintegral_rpow_nnnorm_lt_top_of_snorm'_lt_top,
{ exact ennreal.to_real_pos_iff.mpr ⟨bot_lt_iff_ne_bot.mpr hp_ne_zero, hp_ne_top⟩ },
{ simpa [snorm_eq_snorm' hp_ne_zero hp_ne_top] using hfp }
end
lemma snorm_lt_top_iff_lintegral_rpow_nnnorm_lt_top {f : α → F} (hp_ne_zero : p ≠ 0)
(hp_ne_top : p ≠ ∞) :
snorm f p μ < ∞ ↔ ∫⁻ a, (nnnorm (f a)) ^ p.to_real ∂μ < ∞ :=
⟨lintegral_rpow_nnnorm_lt_top_of_snorm_lt_top hp_ne_zero hp_ne_top,
begin
intros h,
have hp' := ennreal.to_real_pos_iff.mpr ⟨bot_lt_iff_ne_bot.mpr hp_ne_zero, hp_ne_top⟩,
have : 0 < 1 / p.to_real := div_pos zero_lt_one hp',
simpa [snorm_eq_lintegral_rpow_nnnorm hp_ne_zero hp_ne_top] using
ennreal.rpow_lt_top_of_nonneg (le_of_lt this) (ne_of_lt h)
end⟩
end top
section zero
@[simp] lemma snorm'_exponent_zero {f : α → F} : snorm' f 0 μ = 1 :=
by rw [snorm', div_zero, ennreal.rpow_zero]
@[simp] lemma snorm_exponent_zero {f : α → F} : snorm f 0 μ = 0 :=
by simp [snorm]
lemma mem_ℒp_zero_iff_ae_measurable {f : α → E} : mem_ℒp f 0 μ ↔ ae_measurable f μ :=
by simp [mem_ℒp, snorm_exponent_zero]
@[simp] lemma snorm'_zero (hp0_lt : 0 < q) : snorm' (0 : α → F) q μ = 0 :=
by simp [snorm', hp0_lt]
@[simp] lemma snorm'_zero' (hq0_ne : q ≠ 0) (hμ : μ ≠ 0) : snorm' (0 : α → F) q μ = 0 :=
begin
cases le_or_lt 0 q with hq0 hq_neg,
{ exact snorm'_zero (lt_of_le_of_ne hq0 hq0_ne.symm), },
{ simp [snorm', ennreal.rpow_eq_zero_iff, hμ, hq_neg], },
end
@[simp] lemma snorm_ess_sup_zero : snorm_ess_sup (0 : α → F) μ = 0 :=
begin
simp_rw [snorm_ess_sup, pi.zero_apply, nnnorm_zero, ennreal.coe_zero, ←ennreal.bot_eq_zero],
exact ess_sup_const_bot,
end
@[simp] lemma snorm_zero : snorm (0 : α → F) p μ = 0 :=
begin
by_cases h0 : p = 0,
{ simp [h0], },
by_cases h_top : p = ∞,
{ simp only [h_top, snorm_exponent_top, snorm_ess_sup_zero], },
rw ←ne.def at h0,
simp [snorm_eq_snorm' h0 h_top,
ennreal.to_real_pos_iff.mpr ⟨lt_of_le_of_ne (zero_le _) h0.symm, h_top⟩],
end
lemma zero_mem_ℒp : mem_ℒp (0 : α → E) p μ :=
⟨measurable_zero.ae_measurable, by { rw snorm_zero, exact ennreal.coe_lt_top, } ⟩
variables [measurable_space α]
lemma snorm'_measure_zero_of_pos {f : α → F} (hq_pos : 0 < q) :
snorm' f q (0 : measure α) = 0 :=
by simp [snorm', hq_pos]
lemma snorm'_measure_zero_of_exponent_zero {f : α → F} : snorm' f 0 (0 : measure α) = 1 :=
by simp [snorm']
lemma snorm'_measure_zero_of_neg {f : α → F} (hq_neg : q < 0) : snorm' f q (0 : measure α) = ∞ :=
by simp [snorm', hq_neg]
@[simp] lemma snorm_ess_sup_measure_zero {f : α → F} : snorm_ess_sup f (0 : measure α) = 0 :=
by simp [snorm_ess_sup]
@[simp] lemma snorm_measure_zero {f : α → F} : snorm f p (0 : measure α) = 0 :=
begin
by_cases h0 : p = 0,
{ simp [h0], },
by_cases h_top : p = ∞,
{ simp [h_top], },
rw ←ne.def at h0,
simp [snorm_eq_snorm' h0 h_top, snorm',
ennreal.to_real_pos_iff.mpr ⟨lt_of_le_of_ne (zero_le _) h0.symm, h_top⟩],
end
end zero
section const
lemma snorm'_const (c : F) (hq_pos : 0 < q) :
snorm' (λ x : α , c) q μ = (nnnorm c : ℝ≥0∞) * (μ set.univ) ^ (1/q) :=
begin
rw [snorm', lintegral_const, ennreal.mul_rpow_of_nonneg _ _ (by simp [hq_pos.le] : 0 ≤ 1 / q)],
congr,
rw ←ennreal.rpow_mul,
suffices hq_cancel : q * (1/q) = 1, by rw [hq_cancel, ennreal.rpow_one],
rw [one_div, mul_inv_cancel (ne_of_lt hq_pos).symm],
end
lemma snorm'_const' [is_finite_measure μ] (c : F) (hc_ne_zero : c ≠ 0) (hq_ne_zero : q ≠ 0) :
snorm' (λ x : α , c) q μ = (nnnorm c : ℝ≥0∞) * (μ set.univ) ^ (1/q) :=
begin
rw [snorm', lintegral_const, ennreal.mul_rpow_of_ne_top _ (measure_ne_top μ set.univ)],
{ congr,
rw ←ennreal.rpow_mul,
suffices hp_cancel : q * (1/q) = 1, by rw [hp_cancel, ennreal.rpow_one],
rw [one_div, mul_inv_cancel hq_ne_zero], },
{ rw [ne.def, ennreal.rpow_eq_top_iff, auto.not_or_eq, auto.not_and_eq, auto.not_and_eq],
split,
{ left,
rwa [ennreal.coe_eq_zero, nnnorm_eq_zero], },
{ exact or.inl ennreal.coe_ne_top, }, },
end
lemma snorm_ess_sup_const (c : F) (hμ : μ ≠ 0) :
snorm_ess_sup (λ x : α, c) μ = (nnnorm c : ℝ≥0∞) :=
by rw [snorm_ess_sup, ess_sup_const _ hμ]
lemma snorm'_const_of_is_probability_measure (c : F) (hq_pos : 0 < q) [is_probability_measure μ] :
snorm' (λ x : α , c) q μ = (nnnorm c : ℝ≥0∞) :=
by simp [snorm'_const c hq_pos, measure_univ]
lemma snorm_const (c : F) (h0 : p ≠ 0) (hμ : μ ≠ 0) :
snorm (λ x : α , c) p μ = (nnnorm c : ℝ≥0∞) * (μ set.univ) ^ (1/(ennreal.to_real p)) :=
begin
by_cases h_top : p = ∞,
{ simp [h_top, snorm_ess_sup_const c hμ], },
simp [snorm_eq_snorm' h0 h_top, snorm'_const,
ennreal.to_real_pos_iff.mpr ⟨lt_of_le_of_ne (zero_le _) h0.symm, h_top⟩],
end
lemma snorm_const' (c : F) (h0 : p ≠ 0) (h_top: p ≠ ∞) :
snorm (λ x : α , c) p μ = (nnnorm c : ℝ≥0∞) * (μ set.univ) ^ (1/(ennreal.to_real p)) :=
begin
simp [snorm_eq_snorm' h0 h_top, snorm'_const,
ennreal.to_real_pos_iff.mpr ⟨lt_of_le_of_ne (zero_le _) h0.symm, h_top⟩],
end
lemma mem_ℒp_const (c : E) [is_finite_measure μ] : mem_ℒp (λ a:α, c) p μ :=
begin
refine ⟨measurable_const.ae_measurable, _⟩,
by_cases h0 : p = 0,
{ simp [h0], },
by_cases hμ : μ = 0,
{ simp [hμ], },
rw snorm_const c h0 hμ,
refine ennreal.mul_lt_top ennreal.coe_lt_top _,
refine ennreal.rpow_lt_top_of_nonneg _ (measure_ne_top μ set.univ),
simp,
end
end const
lemma snorm'_mono_ae {f : α → F} {g : α → G} (hq : 0 ≤ q) (h : ∀ᵐ x ∂μ, ∥f x∥ ≤ ∥g x∥) :
snorm' f q μ ≤ snorm' g q μ :=
begin
rw [snorm'],
refine ennreal.rpow_le_rpow _ (one_div_nonneg.2 hq),
refine lintegral_mono_ae (h.mono $ λ x hx, _),
exact ennreal.rpow_le_rpow (ennreal.coe_le_coe.2 hx) hq
end
lemma snorm'_congr_norm_ae {f g : α → F} (hfg : ∀ᵐ x ∂μ, ∥f x∥ = ∥g x∥) :
snorm' f q μ = snorm' g q μ :=
begin
have : (λ x, (nnnorm (f x) ^ q : ℝ≥0∞)) =ᵐ[μ] (λ x, nnnorm (g x) ^ q),
from hfg.mono (λ x hx, by { simp only [← coe_nnnorm, nnreal.coe_eq] at hx, simp [hx] }),
simp only [snorm', lintegral_congr_ae this]
end
lemma snorm'_congr_ae {f g : α → F} (hfg : f =ᵐ[μ] g) : snorm' f q μ = snorm' g q μ :=
snorm'_congr_norm_ae (hfg.fun_comp _)
lemma snorm_ess_sup_congr_ae {f g : α → F} (hfg : f =ᵐ[μ] g) :
snorm_ess_sup f μ = snorm_ess_sup g μ :=
ess_sup_congr_ae (hfg.fun_comp (coe ∘ nnnorm))
lemma snorm_mono_ae {f : α → F} {g : α → G} (h : ∀ᵐ x ∂μ, ∥f x∥ ≤ ∥g x∥) :
snorm f p μ ≤ snorm g p μ :=
begin
simp only [snorm],
split_ifs,
{ exact le_rfl },
{ refine ess_sup_mono_ae (h.mono $ λ x hx, _),
exact_mod_cast hx },
{ exact snorm'_mono_ae ennreal.to_real_nonneg h }
end
lemma snorm_ess_sup_le_of_ae_bound {f : α → F} {C : ℝ} (hfC : ∀ᵐ x ∂μ, ∥f x∥ ≤ C) :
snorm_ess_sup f μ ≤ ennreal.of_real C:=
begin
simp_rw [snorm_ess_sup, ← of_real_norm_eq_coe_nnnorm],
refine ess_sup_le_of_ae_le (ennreal.of_real C) (hfC.mono (λ x hx, _)),
exact ennreal.of_real_le_of_real hx,
end
lemma snorm_ess_sup_lt_top_of_ae_bound {f : α → F} {C : ℝ} (hfC : ∀ᵐ x ∂μ, ∥f x∥ ≤ C) :
snorm_ess_sup f μ < ∞ :=
(snorm_ess_sup_le_of_ae_bound hfC).trans_lt ennreal.of_real_lt_top
lemma snorm_le_of_ae_bound {f : α → F} {C : ℝ} (hfC : ∀ᵐ x ∂μ, ∥f x∥ ≤ C) :
snorm f p μ ≤ ((μ set.univ) ^ p.to_real⁻¹) * (ennreal.of_real C) :=
begin
by_cases hμ : μ = 0,
{ simp [hμ] },
haveI : μ.ae.ne_bot := ae_ne_bot.mpr hμ,
by_cases hp : p = 0,
{ simp [hp] },
have hC : 0 ≤ C, from le_trans (norm_nonneg _) hfC.exists.some_spec,
have hC' : ∥C∥ = C := by rw [real.norm_eq_abs, abs_eq_self.mpr hC],
have : ∀ᵐ x ∂μ, ∥f x∥ ≤ ∥(λ _, C) x∥, from hfC.mono (λ x hx, hx.trans (le_of_eq hC'.symm)),
convert snorm_mono_ae this,
rw [snorm_const _ hp hμ, mul_comm, ← of_real_norm_eq_coe_nnnorm, hC', one_div]
end
lemma snorm_congr_norm_ae {f : α → F} {g : α → G} (hfg : ∀ᵐ x ∂μ, ∥f x∥ = ∥g x∥) :
snorm f p μ = snorm g p μ :=
le_antisymm (snorm_mono_ae $ eventually_eq.le hfg)
(snorm_mono_ae $ (eventually_eq.symm hfg).le)
@[simp] lemma snorm'_norm {f : α → F} : snorm' (λ a, ∥f a∥) q μ = snorm' f q μ :=
by simp [snorm']
@[simp] lemma snorm_norm (f : α → F) : snorm (λ x, ∥f x∥) p μ = snorm f p μ :=
snorm_congr_norm_ae $ eventually_of_forall $ λ x, norm_norm _
lemma snorm'_norm_rpow (f : α → F) (p q : ℝ) (hq_pos : 0 < q) :
snorm' (λ x, ∥f x∥ ^ q) p μ = (snorm' f (p * q) μ) ^ q :=
begin
simp_rw snorm',
rw [← ennreal.rpow_mul, ←one_div_mul_one_div],
simp_rw one_div,
rw [mul_assoc, inv_mul_cancel hq_pos.ne.symm, mul_one],
congr,
ext1 x,
simp_rw ← of_real_norm_eq_coe_nnnorm,
rw [real.norm_eq_abs, abs_eq_self.mpr (real.rpow_nonneg_of_nonneg (norm_nonneg _) _),
mul_comm, ← ennreal.of_real_rpow_of_nonneg (norm_nonneg _) hq_pos.le, ennreal.rpow_mul],
end
lemma snorm_norm_rpow (f : α → F) (hq_pos : 0 < q) :
snorm (λ x, ∥f x∥ ^ q) p μ = (snorm f (p * ennreal.of_real q) μ) ^ q :=
begin
by_cases h0 : p = 0,
{ simp [h0, ennreal.zero_rpow_of_pos hq_pos], },
by_cases hp_top : p = ∞,
{ simp only [hp_top, snorm_exponent_top, ennreal.top_mul, hq_pos.not_le, ennreal.of_real_eq_zero,
if_false, snorm_exponent_top, snorm_ess_sup],
have h_rpow : ess_sup (λ (x : α), (nnnorm (∥f x∥ ^ q) : ℝ≥0∞)) μ
= ess_sup (λ (x : α), (↑(nnnorm (f x))) ^ q) μ,
{ congr,
ext1 x,
nth_rewrite 1 ← nnnorm_norm,
rw [ennreal.coe_rpow_of_nonneg _ hq_pos.le, ennreal.coe_eq_coe],
ext,
push_cast,
rw real.norm_rpow_of_nonneg (norm_nonneg _), },
rw h_rpow,
have h_rpow_mono := ennreal.rpow_left_strict_mono_of_pos hq_pos,
have h_rpow_surj := (ennreal.rpow_left_bijective hq_pos.ne.symm).2,
let iso := h_rpow_mono.order_iso_of_surjective _ h_rpow_surj,
exact (iso.ess_sup_apply (λ x, ((nnnorm (f x)) : ℝ≥0∞)) μ).symm, },
rw [snorm_eq_snorm' h0 hp_top, snorm_eq_snorm' _ _],
swap, { refine mul_ne_zero h0 _, rwa [ne.def, ennreal.of_real_eq_zero, not_le], },
swap, { exact ennreal.mul_ne_top hp_top ennreal.of_real_ne_top, },
rw [ennreal.to_real_mul, ennreal.to_real_of_real hq_pos.le],
exact snorm'_norm_rpow f p.to_real q hq_pos,
end
lemma snorm_congr_ae {f g : α → F} (hfg : f =ᵐ[μ] g) : snorm f p μ = snorm g p μ :=
snorm_congr_norm_ae $ hfg.mono (λ x hx, hx ▸ rfl)
lemma mem_ℒp_congr_ae {f g : α → E} (hfg : f =ᵐ[μ] g) : mem_ℒp f p μ ↔ mem_ℒp g p μ :=
by simp only [mem_ℒp, snorm_congr_ae hfg, ae_measurable_congr hfg]
lemma mem_ℒp.ae_eq {f g : α → E} (hfg : f =ᵐ[μ] g) (hf_Lp : mem_ℒp f p μ) : mem_ℒp g p μ :=
(mem_ℒp_congr_ae hfg).1 hf_Lp
lemma mem_ℒp.of_le [measurable_space F] {f : α → E} {g : α → F}
(hg : mem_ℒp g p μ) (hf : ae_measurable f μ) (hfg : ∀ᵐ x ∂μ, ∥f x∥ ≤ ∥g x∥) : mem_ℒp f p μ :=
⟨hf, (snorm_mono_ae hfg).trans_lt hg.snorm_lt_top⟩
lemma mem_ℒp_top_of_bound {f : α → E} (hf : ae_measurable f μ) (C : ℝ)
(hfC : ∀ᵐ x ∂μ, ∥f x∥ ≤ C) :
mem_ℒp f ∞ μ :=
⟨hf, by { rw snorm_exponent_top, exact snorm_ess_sup_lt_top_of_ae_bound hfC, }⟩
lemma mem_ℒp.of_bound [is_finite_measure μ] {f : α → E} (hf : ae_measurable f μ)
(C : ℝ) (hfC : ∀ᵐ x ∂μ, ∥f x∥ ≤ C) :
mem_ℒp f p μ :=
(mem_ℒp_const C).of_le hf (hfC.mono (λ x hx, le_trans hx (le_abs_self _)))
@[mono] lemma snorm'_mono_measure (f : α → F) (hμν : ν ≤ μ) (hq : 0 ≤ q) :
snorm' f q ν ≤ snorm' f q μ :=
begin
simp_rw snorm',
suffices h_integral_mono : (∫⁻ a, (nnnorm (f a) : ℝ≥0∞) ^ q ∂ν) ≤ ∫⁻ a, (nnnorm (f a)) ^ q ∂μ,
from ennreal.rpow_le_rpow h_integral_mono (by simp [hq]),
exact lintegral_mono' hμν le_rfl,
end
@[mono] lemma snorm_ess_sup_mono_measure (f : α → F) (hμν : ν ≪ μ) :
snorm_ess_sup f ν ≤ snorm_ess_sup f μ :=
by { simp_rw snorm_ess_sup, exact ess_sup_mono_measure hμν, }
@[mono] lemma snorm_mono_measure (f : α → F) (hμν : ν ≤ μ) :
snorm f p ν ≤ snorm f p μ :=
begin
by_cases hp0 : p = 0,
{ simp [hp0], },
by_cases hp_top : p = ∞,
{ simp [hp_top, snorm_ess_sup_mono_measure f (measure.absolutely_continuous_of_le hμν)], },
simp_rw snorm_eq_snorm' hp0 hp_top,
exact snorm'_mono_measure f hμν ennreal.to_real_nonneg,
end
lemma mem_ℒp.mono_measure {f : α → E} (hμν : ν ≤ μ) (hf : mem_ℒp f p μ) :
mem_ℒp f p ν :=
⟨hf.1.mono_measure hμν, (snorm_mono_measure f hμν).trans_lt hf.2⟩
lemma mem_ℒp.restrict (s : set α) {f : α → E} (hf : mem_ℒp f p μ) :
mem_ℒp f p (μ.restrict s) :=
hf.mono_measure measure.restrict_le_self
section opens_measurable_space
variable [opens_measurable_space E]
lemma mem_ℒp.norm {f : α → E} (h : mem_ℒp f p μ) : mem_ℒp (λ x, ∥f x∥) p μ :=
h.of_le h.ae_measurable.norm (eventually_of_forall (λ x, by simp))
lemma snorm'_eq_zero_of_ae_zero {f : α → F} (hq0_lt : 0 < q) (hf_zero : f =ᵐ[μ] 0) :
snorm' f q μ = 0 :=
by rw [snorm'_congr_ae hf_zero, snorm'_zero hq0_lt]
lemma snorm'_eq_zero_of_ae_zero' (hq0_ne : q ≠ 0) (hμ : μ ≠ 0) {f : α → F} (hf_zero : f =ᵐ[μ] 0) :
snorm' f q μ = 0 :=
by rw [snorm'_congr_ae hf_zero, snorm'_zero' hq0_ne hμ]
lemma ae_eq_zero_of_snorm'_eq_zero {f : α → E} (hq0 : 0 ≤ q) (hf : ae_measurable f μ)
(h : snorm' f q μ = 0) : f =ᵐ[μ] 0 :=
begin
rw [snorm', ennreal.rpow_eq_zero_iff] at h,
cases h,
{ rw lintegral_eq_zero_iff' (hf.ennnorm.pow_const q) at h,
refine h.left.mono (λ x hx, _),
rw [pi.zero_apply, ennreal.rpow_eq_zero_iff] at hx,
cases hx,
{ cases hx with hx _,
rwa [←ennreal.coe_zero, ennreal.coe_eq_coe, nnnorm_eq_zero] at hx, },
{ exact absurd hx.left ennreal.coe_ne_top, }, },
{ exfalso,
rw [one_div, inv_lt_zero] at h,
exact hq0.not_lt h.right },
end
lemma snorm'_eq_zero_iff (hq0_lt : 0 < q) {f : α → E} (hf : ae_measurable f μ) :
snorm' f q μ = 0 ↔ f =ᵐ[μ] 0 :=
⟨ae_eq_zero_of_snorm'_eq_zero (le_of_lt hq0_lt) hf, snorm'_eq_zero_of_ae_zero hq0_lt⟩
lemma coe_nnnorm_ae_le_snorm_ess_sup {m : measurable_space α} (f : α → F) (μ : measure α) :
∀ᵐ x ∂μ, (nnnorm (f x) : ℝ≥0∞) ≤ snorm_ess_sup f μ :=
ennreal.ae_le_ess_sup (λ x, (nnnorm (f x) : ℝ≥0∞))
@[simp] lemma snorm_ess_sup_eq_zero_iff {f : α → F} : snorm_ess_sup f μ = 0 ↔ f =ᵐ[μ] 0 :=
by simp [eventually_eq, snorm_ess_sup]
lemma snorm_eq_zero_iff {f : α → E} (hf : ae_measurable f μ) (h0 : p ≠ 0) :
snorm f p μ = 0 ↔ f =ᵐ[μ] 0 :=
begin
by_cases h_top : p = ∞,
{ rw [h_top, snorm_exponent_top, snorm_ess_sup_eq_zero_iff], },
rw snorm_eq_snorm' h0 h_top,
exact snorm'_eq_zero_iff
(ennreal.to_real_pos_iff.mpr ⟨lt_of_le_of_ne (zero_le _) h0.symm, h_top⟩) hf,
end
section trim
lemma snorm'_trim (hm : m ≤ m0) {f : α → E} (hf : @measurable _ _ m _ f) :
snorm' f q (ν.trim hm) = snorm' f q ν :=
begin
simp_rw snorm',
congr' 1,
refine lintegral_trim hm _,
refine @measurable.pow_const _ _ _ _ _ _ _ m _ (@measurable.coe_nnreal_ennreal _ m _ _) _,
exact @measurable.nnnorm E _ _ _ _ m _ hf,
end
lemma limsup_trim (hm : m ≤ m0) {f : α → ℝ≥0∞} (hf : @measurable _ _ m _ f) :
(ν.trim hm).ae.limsup f = ν.ae.limsup f :=
begin
simp_rw limsup_eq,
suffices h_set_eq : {a : ℝ≥0∞ | ∀ᵐ n ∂(ν.trim hm), f n ≤ a} = {a : ℝ≥0∞ | ∀ᵐ n ∂ν, f n ≤ a},
by rw h_set_eq,
ext1 a,
suffices h_meas_eq : ν {x | ¬ f x ≤ a} = ν.trim hm {x | ¬ f x ≤ a},
by simp_rw [set.mem_set_of_eq, ae_iff, h_meas_eq],
refine (trim_measurable_set_eq hm _).symm,
refine @measurable_set.compl _ _ m (@measurable_set_le ℝ≥0∞ _ _ _ _ m _ _ _ _ _ hf _),
exact @measurable_const _ _ _ m _,
end
lemma ess_sup_trim (hm : m ≤ m0) {f : α → ℝ≥0∞} (hf : @measurable _ _ m _ f) :
ess_sup f (ν.trim hm) = ess_sup f ν :=
by { simp_rw ess_sup, exact limsup_trim hm hf, }
lemma snorm_ess_sup_trim (hm : m ≤ m0) {f : α → E} (hf : @measurable _ _ m _ f) :
snorm_ess_sup f (ν.trim hm) = snorm_ess_sup f ν :=
ess_sup_trim hm (@measurable.coe_nnreal_ennreal _ m _ (@measurable.nnnorm E _ _ _ _ m _ hf))
lemma snorm_trim (hm : m ≤ m0) {f : α → E} (hf : @measurable _ _ m _ f) :
snorm f p (ν.trim hm) = snorm f p ν :=
begin
by_cases h0 : p = 0,
{ simp [h0], },
by_cases h_top : p = ∞,
{ simpa only [h_top, snorm_exponent_top] using snorm_ess_sup_trim hm hf, },
simpa only [snorm_eq_snorm' h0 h_top] using snorm'_trim hm hf,
end
lemma snorm_trim_ae (hm : m ≤ m0) {f : α → E} (hf : ae_measurable f (ν.trim hm)) :
snorm f p (ν.trim hm) = snorm f p ν :=
begin
rw [snorm_congr_ae hf.ae_eq_mk, snorm_congr_ae (ae_eq_of_ae_eq_trim hf.ae_eq_mk)],
exact snorm_trim hm hf.measurable_mk,
end
lemma mem_ℒp_of_mem_ℒp_trim (hm : m ≤ m0) {f : α → E} (hf : mem_ℒp f p (ν.trim hm)) :
mem_ℒp f p ν :=
⟨ae_measurable_of_ae_measurable_trim hm hf.1, (le_of_eq (snorm_trim_ae hm hf.1).symm).trans_lt hf.2⟩
end trim
end opens_measurable_space
@[simp] lemma snorm'_neg {f : α → F} : snorm' (-f) q μ = snorm' f q μ := by simp [snorm']
@[simp] lemma snorm_neg {f : α → F} : snorm (-f) p μ = snorm f p μ :=
begin
by_cases h0 : p = 0,
{ simp [h0], },
by_cases h_top : p = ∞,
{ simp [h_top, snorm_ess_sup], },
simp [snorm_eq_snorm' h0 h_top],
end
section borel_space
variable [borel_space E]
lemma mem_ℒp.neg {f : α → E} (hf : mem_ℒp f p μ) : mem_ℒp (-f) p μ :=
⟨ae_measurable.neg hf.1, by simp [hf.right]⟩
lemma snorm'_le_snorm'_mul_rpow_measure_univ {p q : ℝ} (hp0_lt : 0 < p) (hpq : p ≤ q)
{f : α → E} (hf : ae_measurable f μ) :
snorm' f p μ ≤ snorm' f q μ * (μ set.univ) ^ (1/p - 1/q) :=
begin
have hq0_lt : 0 < q, from lt_of_lt_of_le hp0_lt hpq,
by_cases hpq_eq : p = q,
{ rw [hpq_eq, sub_self, ennreal.rpow_zero, mul_one],
exact le_refl _, },
have hpq : p < q, from lt_of_le_of_ne hpq hpq_eq,
let g := λ a : α, (1 : ℝ≥0∞),
have h_rw : ∫⁻ a, ↑(nnnorm (f a))^p ∂ μ = ∫⁻ a, (nnnorm (f a) * (g a))^p ∂ μ,
from lintegral_congr (λ a, by simp),
repeat {rw snorm'},
rw h_rw,
let r := p * q / (q - p),
have hpqr : 1/p = 1/q + 1/r,
{ field_simp [(ne_of_lt hp0_lt).symm,
(ne_of_lt hq0_lt).symm],
ring, },
calc (∫⁻ (a : α), (↑(nnnorm (f a)) * g a) ^ p ∂μ) ^ (1/p)
≤ (∫⁻ (a : α), ↑(nnnorm (f a)) ^ q ∂μ) ^ (1/q) * (∫⁻ (a : α), (g a) ^ r ∂μ) ^ (1/r) :
ennreal.lintegral_Lp_mul_le_Lq_mul_Lr hp0_lt hpq hpqr μ hf.ennnorm
ae_measurable_const
... = (∫⁻ (a : α), ↑(nnnorm (f a)) ^ q ∂μ) ^ (1/q) * μ set.univ ^ (1/p - 1/q) :
by simp [hpqr],
end
lemma snorm'_le_snorm_ess_sup_mul_rpow_measure_univ (hq_pos : 0 < q) {f : α → F} :
snorm' f q μ ≤ snorm_ess_sup f μ * (μ set.univ) ^ (1/q) :=
begin
have h_le : ∫⁻ (a : α), ↑(nnnorm (f a)) ^ q ∂μ ≤ ∫⁻ (a : α), (snorm_ess_sup f μ) ^ q ∂μ,
{ refine lintegral_mono_ae _,
have h_nnnorm_le_snorm_ess_sup := coe_nnnorm_ae_le_snorm_ess_sup f μ,
refine h_nnnorm_le_snorm_ess_sup.mono (λ x hx, ennreal.rpow_le_rpow hx (le_of_lt hq_pos)), },
rw [snorm', ←ennreal.rpow_one (snorm_ess_sup f μ)],
nth_rewrite 1 ←mul_inv_cancel (ne_of_lt hq_pos).symm,
rw [ennreal.rpow_mul, one_div,
←ennreal.mul_rpow_of_nonneg _ _ (by simp [hq_pos.le] : 0 ≤ q⁻¹)],
refine ennreal.rpow_le_rpow _ (by simp [hq_pos.le]),
rwa lintegral_const at h_le,
end
lemma snorm_le_snorm_mul_rpow_measure_univ {p q : ℝ≥0∞} (hpq : p ≤ q) {f : α → E}
(hf : ae_measurable f μ) :
snorm f p μ ≤ snorm f q μ * (μ set.univ) ^ (1/p.to_real - 1/q.to_real) :=
begin
by_cases hp0 : p = 0,
{ simp [hp0, zero_le], },
rw ← ne.def at hp0,
have hp0_lt : 0 < p, from lt_of_le_of_ne (zero_le _) hp0.symm,
have hq0_lt : 0 < q, from lt_of_lt_of_le hp0_lt hpq,
by_cases hq_top : q = ∞,
{ simp only [hq_top, div_zero, one_div, ennreal.top_to_real, sub_zero, snorm_exponent_top,
inv_zero],
by_cases hp_top : p = ∞,
{ simp only [hp_top, ennreal.rpow_zero, mul_one, ennreal.top_to_real, sub_zero, inv_zero,
snorm_exponent_top],
exact le_rfl, },
rw snorm_eq_snorm' hp0 hp_top,
have hp_pos : 0 < p.to_real, from ennreal.to_real_pos_iff.mpr ⟨hp0_lt, hp_top⟩,
refine (snorm'_le_snorm_ess_sup_mul_rpow_measure_univ hp_pos).trans (le_of_eq _),
congr,
exact one_div _, },
have hp_lt_top : p < ∞, from hpq.trans_lt (lt_top_iff_ne_top.mpr hq_top),
have hp_pos : 0 < p.to_real, from ennreal.to_real_pos_iff.mpr ⟨hp0_lt, hp_lt_top.ne⟩,
rw [snorm_eq_snorm' hp0_lt.ne.symm hp_lt_top.ne, snorm_eq_snorm' hq0_lt.ne.symm hq_top],
have hpq_real : p.to_real ≤ q.to_real, by rwa ennreal.to_real_le_to_real hp_lt_top.ne hq_top,
exact snorm'_le_snorm'_mul_rpow_measure_univ hp_pos hpq_real hf,
end
lemma snorm'_le_snorm'_of_exponent_le {m : measurable_space α} {p q : ℝ} (hp0_lt : 0 < p)
(hpq : p ≤ q) (μ : measure α) [is_probability_measure μ] {f : α → E} (hf : ae_measurable f μ) :
snorm' f p μ ≤ snorm' f q μ :=
begin
have h_le_μ := snorm'_le_snorm'_mul_rpow_measure_univ hp0_lt hpq hf,
rwa [measure_univ, ennreal.one_rpow, mul_one] at h_le_μ,
end
lemma snorm'_le_snorm_ess_sup (hq_pos : 0 < q) {f : α → F} [is_probability_measure μ] :
snorm' f q μ ≤ snorm_ess_sup f μ :=
le_trans (snorm'_le_snorm_ess_sup_mul_rpow_measure_univ hq_pos) (le_of_eq (by simp [measure_univ]))
lemma snorm_le_snorm_of_exponent_le {p q : ℝ≥0∞} (hpq : p ≤ q) [is_probability_measure μ]
{f : α → E} (hf : ae_measurable f μ) :
snorm f p μ ≤ snorm f q μ :=
(snorm_le_snorm_mul_rpow_measure_univ hpq hf).trans (le_of_eq (by simp [measure_univ]))
lemma snorm'_lt_top_of_snorm'_lt_top_of_exponent_le {p q : ℝ} [is_finite_measure μ] {f : α → E}
(hf : ae_measurable f μ) (hfq_lt_top : snorm' f q μ < ∞) (hp_nonneg : 0 ≤ p) (hpq : p ≤ q) :
snorm' f p μ < ∞ :=
begin
cases le_or_lt p 0 with hp_nonpos hp_pos,
{ rw le_antisymm hp_nonpos hp_nonneg,
simp, },
have hq_pos : 0 < q, from lt_of_lt_of_le hp_pos hpq,
calc snorm' f p μ
≤ snorm' f q μ * (μ set.univ) ^ (1/p - 1/q) :
snorm'_le_snorm'_mul_rpow_measure_univ hp_pos hpq hf
... < ∞ :
begin
rw ennreal.mul_lt_top_iff,
refine or.inl ⟨hfq_lt_top, ennreal.rpow_lt_top_of_nonneg _ (measure_ne_top μ set.univ)⟩,
rwa [le_sub, sub_zero, one_div, one_div, inv_le_inv hq_pos hp_pos],
end
end
lemma mem_ℒp.mem_ℒp_of_exponent_le {p q : ℝ≥0∞} [is_finite_measure μ] {f : α → E}
(hfq : mem_ℒp f q μ) (hpq : p ≤ q) :
mem_ℒp f p μ :=
begin
cases hfq with hfq_m hfq_lt_top,
by_cases hp0 : p = 0,
{ rwa [hp0, mem_ℒp_zero_iff_ae_measurable], },
rw ←ne.def at hp0,
refine ⟨hfq_m, _⟩,
by_cases hp_top : p = ∞,
{ have hq_top : q = ∞,
by rwa [hp_top, top_le_iff] at hpq,
rw [hp_top],
rwa hq_top at hfq_lt_top, },
have hp_pos : 0 < p.to_real,
from ennreal.to_real_pos_iff.mpr ⟨lt_of_le_of_ne (zero_le _) hp0.symm, hp_top⟩,
by_cases hq_top : q = ∞,
{ rw snorm_eq_snorm' hp0 hp_top,
rw [hq_top, snorm_exponent_top] at hfq_lt_top,
refine lt_of_le_of_lt (snorm'_le_snorm_ess_sup_mul_rpow_measure_univ hp_pos) _,
refine ennreal.mul_lt_top hfq_lt_top _,
exact ennreal.rpow_lt_top_of_nonneg (by simp [le_of_lt hp_pos]) (measure_ne_top μ set.univ), },
have hq0 : q ≠ 0,
{ by_contra hq_eq_zero,
push_neg at hq_eq_zero,
have hp_eq_zero : p = 0, from le_antisymm (by rwa hq_eq_zero at hpq) (zero_le _),
rw [hp_eq_zero, ennreal.zero_to_real] at hp_pos,
exact (lt_irrefl _) hp_pos, },
have hpq_real : p.to_real ≤ q.to_real, by rwa ennreal.to_real_le_to_real hp_top hq_top,
rw snorm_eq_snorm' hp0 hp_top,
rw snorm_eq_snorm' hq0 hq_top at hfq_lt_top,
exact snorm'_lt_top_of_snorm'_lt_top_of_exponent_le hfq_m hfq_lt_top (le_of_lt hp_pos) hpq_real,
end
lemma snorm'_add_le {f g : α → E} (hf : ae_measurable f μ) (hg : ae_measurable g μ) (hq1 : 1 ≤ q) :
snorm' (f + g) q μ ≤ snorm' f q μ + snorm' g q μ :=
calc (∫⁻ a, ↑(nnnorm ((f + g) a)) ^ q ∂μ) ^ (1 / q)
≤ (∫⁻ a, (((λ a, (nnnorm (f a) : ℝ≥0∞))
+ (λ a, (nnnorm (g a) : ℝ≥0∞))) a) ^ q ∂μ) ^ (1 / q) :
begin
refine ennreal.rpow_le_rpow _ (by simp [le_trans zero_le_one hq1] : 0 ≤ 1 / q),
refine lintegral_mono (λ a, ennreal.rpow_le_rpow _ (le_trans zero_le_one hq1)),
simp [←ennreal.coe_add, nnnorm_add_le],
end
... ≤ snorm' f q μ + snorm' g q μ :
ennreal.lintegral_Lp_add_le hf.ennnorm hg.ennnorm hq1
lemma snorm_ess_sup_add_le {f g : α → F} :
snorm_ess_sup (f + g) μ ≤ snorm_ess_sup f μ + snorm_ess_sup g μ :=
begin
refine le_trans (ess_sup_mono_ae (eventually_of_forall (λ x, _)))
(ennreal.ess_sup_add_le _ _),
simp_rw [pi.add_apply, ←ennreal.coe_add, ennreal.coe_le_coe],
exact nnnorm_add_le _ _,
end
lemma snorm_add_le {f g : α → E} (hf : ae_measurable f μ) (hg : ae_measurable g μ) (hp1 : 1 ≤ p) :
snorm (f + g) p μ ≤ snorm f p μ + snorm g p μ :=
begin
by_cases hp0 : p = 0,
{ simp [hp0], },
by_cases hp_top : p = ∞,
{ simp [hp_top, snorm_ess_sup_add_le], },
have hp1_real : 1 ≤ p.to_real,
by rwa [← ennreal.one_to_real, ennreal.to_real_le_to_real ennreal.one_ne_top hp_top],
repeat { rw snorm_eq_snorm' hp0 hp_top, },
exact snorm'_add_le hf hg hp1_real,
end
lemma snorm'_sum_le [second_countable_topology E] {ι} {f : ι → α → E} {s : finset ι}
(hfs : ∀ i, i ∈ s → ae_measurable (f i) μ) (hq1 : 1 ≤ q) :
snorm' (∑ i in s, f i) q μ ≤ ∑ i in s, snorm' (f i) q μ :=
finset.le_sum_of_subadditive_on_pred (λ (f : α → E), snorm' f q μ)
(λ f, ae_measurable f μ) (snorm'_zero (zero_lt_one.trans_le hq1))
(λ f g hf hg, snorm'_add_le hf hg hq1) (λ x y, ae_measurable.add) _ hfs
lemma snorm_sum_le [second_countable_topology E] {ι} {f : ι → α → E} {s : finset ι}
(hfs : ∀ i, i ∈ s → ae_measurable (f i) μ) (hp1 : 1 ≤ p) :
snorm (∑ i in s, f i) p μ ≤ ∑ i in s, snorm (f i) p μ :=
finset.le_sum_of_subadditive_on_pred (λ (f : α → E), snorm f p μ)
(λ f, ae_measurable f μ) snorm_zero (λ f g hf hg, snorm_add_le hf hg hp1)
(λ x y, ae_measurable.add) _ hfs
lemma snorm_add_lt_top_of_one_le {f g : α → E} (hf : mem_ℒp f p μ) (hg : mem_ℒp g p μ)
(hq1 : 1 ≤ p) : snorm (f + g) p μ < ∞ :=
lt_of_le_of_lt (snorm_add_le hf.1 hg.1 hq1) (ennreal.add_lt_top.mpr ⟨hf.2, hg.2⟩)
lemma snorm'_add_lt_top_of_le_one {f g : α → E} (hf : ae_measurable f μ) (hg : ae_measurable g μ)
(hf_snorm : snorm' f q μ < ∞) (hg_snorm : snorm' g q μ < ∞) (hq_pos : 0 < q) (hq1 : q ≤ 1) :
snorm' (f + g) q μ < ∞ :=
calc (∫⁻ a, ↑(nnnorm ((f + g) a)) ^ q ∂μ) ^ (1 / q)
≤ (∫⁻ a, (((λ a, (nnnorm (f a) : ℝ≥0∞))
+ (λ a, (nnnorm (g a) : ℝ≥0∞))) a) ^ q ∂μ) ^ (1 / q) :
begin
refine ennreal.rpow_le_rpow _ (by simp [hq_pos.le] : 0 ≤ 1 / q),
refine lintegral_mono (λ a, ennreal.rpow_le_rpow _ hq_pos.le),
simp [←ennreal.coe_add, nnnorm_add_le],
end
... ≤ (∫⁻ a, (nnnorm (f a) : ℝ≥0∞) ^ q + (nnnorm (g a) : ℝ≥0∞) ^ q ∂μ) ^ (1 / q) :
begin
refine ennreal.rpow_le_rpow (lintegral_mono (λ a, _)) (by simp [hq_pos.le] : 0 ≤ 1 / q),
exact ennreal.rpow_add_le_add_rpow _ _ hq_pos hq1,
end
... < ∞ :
begin
refine ennreal.rpow_lt_top_of_nonneg (by simp [hq_pos.le] : 0 ≤ 1 / q) _,
rw [lintegral_add' (hf.ennnorm.pow_const q)
(hg.ennnorm.pow_const q), ennreal.add_ne_top, ←lt_top_iff_ne_top,
←lt_top_iff_ne_top],
exact ⟨lintegral_rpow_nnnorm_lt_top_of_snorm'_lt_top hq_pos hf_snorm,
lintegral_rpow_nnnorm_lt_top_of_snorm'_lt_top hq_pos hg_snorm⟩,
end
lemma snorm_add_lt_top {f g : α → E} (hf : mem_ℒp f p μ) (hg : mem_ℒp g p μ) :
snorm (f + g) p μ < ∞ :=
begin
by_cases h0 : p = 0,
{ simp [h0], },
rw ←ne.def at h0,
cases le_total 1 p with hp1 hp1,
{ exact snorm_add_lt_top_of_one_le hf hg hp1, },
have hp_top : p ≠ ∞, from (lt_of_le_of_lt hp1 ennreal.coe_lt_top).ne,
have hp_pos : 0 < p.to_real,
{ rw [← ennreal.zero_to_real, @ennreal.to_real_lt_to_real 0 p ennreal.coe_ne_top hp_top],
exact ((zero_le p).lt_of_ne h0.symm), },
have hp1_real : p.to_real ≤ 1,
{ rwa [← ennreal.one_to_real, @ennreal.to_real_le_to_real p 1 hp_top ennreal.coe_ne_top], },
rw snorm_eq_snorm' h0 hp_top,
rw [mem_ℒp, snorm_eq_snorm' h0 hp_top] at hf hg,
exact snorm'_add_lt_top_of_le_one hf.1 hg.1 hf.2 hg.2 hp_pos hp1_real,
end
section second_countable_topology
variable [second_countable_topology E]
lemma mem_ℒp.add {f g : α → E} (hf : mem_ℒp f p μ) (hg : mem_ℒp g p μ) : mem_ℒp (f + g) p μ :=
⟨ae_measurable.add hf.1 hg.1, snorm_add_lt_top hf hg⟩
lemma mem_ℒp.sub {f g : α → E} (hf : mem_ℒp f p μ) (hg : mem_ℒp g p μ) : mem_ℒp (f - g) p μ :=
by { rw sub_eq_add_neg, exact hf.add hg.neg }
end second_countable_topology
end borel_space
section normed_space
variables {𝕜 : Type*} [normed_field 𝕜] [normed_space 𝕜 E] [normed_space 𝕜 F]
lemma snorm'_const_smul {f : α → F} (c : 𝕜) (hq_pos : 0 < q) :
snorm' (c • f) q μ = (nnnorm c : ℝ≥0∞) * snorm' f q μ :=
begin
rw snorm',
simp_rw [pi.smul_apply, nnnorm_smul, ennreal.coe_mul,
ennreal.mul_rpow_of_nonneg _ _ hq_pos.le],
suffices h_integral : ∫⁻ a, ↑(nnnorm c) ^ q * ↑(nnnorm (f a)) ^ q ∂μ
= (nnnorm c : ℝ≥0∞)^q * ∫⁻ a, (nnnorm (f a)) ^ q ∂μ,
{ apply_fun (λ x, x ^ (1/q)) at h_integral,
rw [h_integral, ennreal.mul_rpow_of_nonneg _ _ (by simp [hq_pos.le] : 0 ≤ 1 / q)],
congr,
simp_rw [←ennreal.rpow_mul, one_div, mul_inv_cancel hq_pos.ne.symm, ennreal.rpow_one], },
rw lintegral_const_mul',
rw ennreal.coe_rpow_of_nonneg _ hq_pos.le,
exact ennreal.coe_ne_top,
end
lemma snorm_ess_sup_const_smul {f : α → F} (c : 𝕜) :
snorm_ess_sup (c • f) μ = (nnnorm c : ℝ≥0∞) * snorm_ess_sup f μ :=
by simp_rw [snorm_ess_sup, pi.smul_apply, nnnorm_smul, ennreal.coe_mul, ennreal.ess_sup_const_mul]
lemma snorm_const_smul {f : α → F} (c : 𝕜) :
snorm (c • f) p μ = (nnnorm c : ℝ≥0∞) * snorm f p μ :=
begin
by_cases h0 : p = 0,
{ simp [h0], },
by_cases h_top : p = ∞,
{ simp [h_top, snorm_ess_sup_const_smul], },
repeat { rw snorm_eq_snorm' h0 h_top, },
rw ←ne.def at h0,
exact snorm'_const_smul c
(ennreal.to_real_pos_iff.mpr ⟨lt_of_le_of_ne (zero_le _) h0.symm, h_top⟩),
end
lemma mem_ℒp.const_smul [measurable_space 𝕜] [opens_measurable_space 𝕜] [borel_space E] {f : α → E}
(hf : mem_ℒp f p μ) (c : 𝕜) :
mem_ℒp (c • f) p μ :=
⟨ae_measurable.const_smul hf.1 c,
lt_of_le_of_lt (le_of_eq (snorm_const_smul c)) (ennreal.mul_lt_top ennreal.coe_lt_top hf.2)⟩
lemma mem_ℒp.const_mul [measurable_space 𝕜] [borel_space 𝕜]
{f : α → 𝕜} (hf : mem_ℒp f p μ) (c : 𝕜) : mem_ℒp (λ x, c * f x) p μ :=
hf.const_smul c
lemma snorm'_smul_le_mul_snorm' [opens_measurable_space E] [measurable_space 𝕜]
[opens_measurable_space 𝕜] {p q r : ℝ}
{f : α → E} (hf : ae_measurable f μ) {φ : α → 𝕜} (hφ : ae_measurable φ μ)
(hp0_lt : 0 < p) (hpq : p < q) (hpqr : 1/p = 1/q + 1/r) :
snorm' (φ • f) p μ ≤ snorm' φ q μ * snorm' f r μ :=
begin
simp_rw [snorm', pi.smul_apply', nnnorm_smul, ennreal.coe_mul],
exact ennreal.lintegral_Lp_mul_le_Lq_mul_Lr hp0_lt hpq hpqr μ hφ.ennnorm
hf.ennnorm,
end
end normed_space
section monotonicity
lemma snorm_le_mul_snorm_aux_of_nonneg {f : α → F} {g : α → G} {c : ℝ}
(h : ∀ᵐ x ∂μ, ∥f x∥ ≤ c * ∥g x∥) (hc : 0 ≤ c) (p : ℝ≥0∞) :
snorm f p μ ≤ (ennreal.of_real c) * snorm g p μ :=
begin
lift c to ℝ≥0 using hc,
rw [ennreal.of_real_coe_nnreal, ← c.nnnorm_eq, ← snorm_norm g, ← snorm_const_smul (c : ℝ)],
swap, apply_instance,
refine snorm_mono_ae _,
simpa
end
lemma snorm_le_mul_snorm_aux_of_neg {f : α → F} {g : α → G} {c : ℝ}
(h : ∀ᵐ x ∂μ, ∥f x∥ ≤ c * ∥g x∥) (hc : c < 0) (p : ℝ≥0∞) :
snorm f p μ = 0 ∧ snorm g p μ = 0 :=
begin
suffices : f =ᵐ[μ] 0 ∧ g =ᵐ[μ] 0,
by simp [snorm_congr_ae this.1, snorm_congr_ae this.2],
refine ⟨h.mono $ λ x hx, _, h.mono $ λ x hx, _⟩,
{ refine norm_le_zero_iff.1 (hx.trans _),
exact mul_nonpos_of_nonpos_of_nonneg hc.le (norm_nonneg _) },
{ refine norm_le_zero_iff.1 (nonpos_of_mul_nonneg_right _ hc),
exact (norm_nonneg _).trans hx }
end
lemma snorm_le_mul_snorm_of_ae_le_mul {f : α → F} {g : α → G} {c : ℝ}
(h : ∀ᵐ x ∂μ, ∥f x∥ ≤ c * ∥g x∥) (p : ℝ≥0∞) :
snorm f p μ ≤ (ennreal.of_real c) * snorm g p μ :=
begin
cases le_or_lt 0 c with hc hc,
{ exact snorm_le_mul_snorm_aux_of_nonneg h hc p },
{ simp [snorm_le_mul_snorm_aux_of_neg h hc p] }
end
lemma mem_ℒp.of_le_mul [measurable_space F] {f : α → E} {g : α → F} {c : ℝ}
(hg : mem_ℒp g p μ) (hf : ae_measurable f μ) (hfg : ∀ᵐ x ∂μ, ∥f x∥ ≤ c * ∥g x∥) :
mem_ℒp f p μ :=
begin
simp only [mem_ℒp, hf, true_and],
apply lt_of_le_of_lt (snorm_le_mul_snorm_of_ae_le_mul hfg p),
simp [lt_top_iff_ne_top, hg.snorm_ne_top],
end
end monotonicity
section is_R_or_C
variables {𝕜 : Type*} [is_R_or_C 𝕜] [measurable_space 𝕜] [opens_measurable_space 𝕜] {f : α → 𝕜}
lemma mem_ℒp.re (hf : mem_ℒp f p μ) : mem_ℒp (λ x, is_R_or_C.re (f x)) p μ :=
begin
have : ∀ x, ∥is_R_or_C.re (f x)∥ ≤ 1 * ∥f x∥,
by { intro x, rw one_mul, exact is_R_or_C.norm_re_le_norm (f x), },
exact hf.of_le_mul hf.1.re (eventually_of_forall this),
end
lemma mem_ℒp.im (hf : mem_ℒp f p μ) : mem_ℒp (λ x, is_R_or_C.im (f x)) p μ :=
begin
have : ∀ x, ∥is_R_or_C.im (f x)∥ ≤ 1 * ∥f x∥,
by { intro x, rw one_mul, exact is_R_or_C.norm_im_le_norm (f x), },
exact hf.of_le_mul hf.1.im (eventually_of_forall this),
end
end is_R_or_C
section inner_product
variables {E' 𝕜 : Type*} [is_R_or_C 𝕜] [measurable_space 𝕜] [borel_space 𝕜]
[inner_product_space 𝕜 E']
[measurable_space E'] [opens_measurable_space E'] [second_countable_topology E']
local notation `⟪`x`, `y`⟫` := @inner 𝕜 E' _ x y
lemma mem_ℒp.const_inner (c : E') {f : α → E'} (hf : mem_ℒp f p μ) :
mem_ℒp (λ a, ⟪c, f a⟫) p μ :=
hf.of_le_mul (ae_measurable.inner ae_measurable_const hf.1)
(eventually_of_forall (λ x, norm_inner_le_norm _ _))
lemma mem_ℒp.inner_const {f : α → E'} (hf : mem_ℒp f p μ) (c : E') :
mem_ℒp (λ a, ⟪f a, c⟫) p μ :=
hf.of_le_mul (ae_measurable.inner hf.1 ae_measurable_const)
(eventually_of_forall (λ x, by { rw mul_comm, exact norm_inner_le_norm _ _, }))
end inner_product
end ℒp
/-!
### Lp space
The space of equivalence classes of measurable functions for which `snorm f p μ < ∞`.
-/
@[simp] lemma snorm_ae_eq_fun {α E : Type*} [measurable_space α] {μ : measure α}
[measurable_space E] [normed_group E] {p : ℝ≥0∞} {f : α → E} (hf : ae_measurable f μ) :
snorm (ae_eq_fun.mk f hf) p μ = snorm f p μ :=
snorm_congr_ae (ae_eq_fun.coe_fn_mk _ _)
lemma mem_ℒp.snorm_mk_lt_top {α E : Type*} [measurable_space α] {μ : measure α}
[measurable_space E] [normed_group E] {p : ℝ≥0∞} {f : α → E} (hfp : mem_ℒp f p μ) :
snorm (ae_eq_fun.mk f hfp.1) p μ < ∞ :=
by simp [hfp.2]
/-- Lp space -/
def Lp {α} (E : Type*) {m : measurable_space α} [measurable_space E] [normed_group E]
[borel_space E] [second_countable_topology E]
(p : ℝ≥0∞) (μ : measure α) : add_subgroup (α →ₘ[μ] E) :=
{ carrier := {f | snorm f p μ < ∞},
zero_mem' := by simp [snorm_congr_ae ae_eq_fun.coe_fn_zero, snorm_zero],
add_mem' := λ f g hf hg, by simp [snorm_congr_ae (ae_eq_fun.coe_fn_add _ _),
snorm_add_lt_top ⟨f.ae_measurable, hf⟩ ⟨g.ae_measurable, hg⟩],
neg_mem' := λ f hf,
by rwa [set.mem_set_of_eq, snorm_congr_ae (ae_eq_fun.coe_fn_neg _), snorm_neg] }
localized "notation α ` →₁[`:25 μ `] ` E := measure_theory.Lp E 1 μ" in measure_theory
localized "notation α ` →₂[`:25 μ `] ` E := measure_theory.Lp E 2 μ" in measure_theory
namespace mem_ℒp
variables [borel_space E] [second_countable_topology E]
/-- make an element of Lp from a function verifying `mem_ℒp` -/
def to_Lp (f : α → E) (h_mem_ℒp : mem_ℒp f p μ) : Lp E p μ :=
⟨ae_eq_fun.mk f h_mem_ℒp.1, h_mem_ℒp.snorm_mk_lt_top⟩
lemma coe_fn_to_Lp {f : α → E} (hf : mem_ℒp f p μ) : hf.to_Lp f =ᵐ[μ] f :=
ae_eq_fun.coe_fn_mk _ _
@[simp] lemma to_Lp_eq_to_Lp_iff {f g : α → E} (hf : mem_ℒp f p μ) (hg : mem_ℒp g p μ) :
hf.to_Lp f = hg.to_Lp g ↔ f =ᵐ[μ] g :=
by simp [to_Lp]
@[simp] lemma to_Lp_zero (h : mem_ℒp (0 : α → E) p μ) : h.to_Lp 0 = 0 := rfl
lemma to_Lp_add {f g : α → E} (hf : mem_ℒp f p μ) (hg : mem_ℒp g p μ) :
(hf.add hg).to_Lp (f + g) = hf.to_Lp f + hg.to_Lp g := rfl
lemma to_Lp_neg {f : α → E} (hf : mem_ℒp f p μ) : hf.neg.to_Lp (-f) = - hf.to_Lp f := rfl
lemma to_Lp_sub {f g : α → E} (hf : mem_ℒp f p μ) (hg : mem_ℒp g p μ) :
(hf.sub hg).to_Lp (f - g) = hf.to_Lp f - hg.to_Lp g := rfl
end mem_ℒp
namespace Lp
variables [borel_space E] [second_countable_topology E]
instance : has_coe_to_fun (Lp E p μ) := ⟨λ _, α → E, λ f, ((f : α →ₘ[μ] E) : α → E)⟩
@[ext] lemma ext {f g : Lp E p μ} (h : f =ᵐ[μ] g) : f = g :=
begin
cases f,
cases g,
simp only [subtype.mk_eq_mk],
exact ae_eq_fun.ext h
end
lemma ext_iff {f g : Lp E p μ} : f = g ↔ f =ᵐ[μ] g :=
⟨λ h, by rw h, λ h, ext h⟩
lemma mem_Lp_iff_snorm_lt_top {f : α →ₘ[μ] E} : f ∈ Lp E p μ ↔ snorm f p μ < ∞ := iff.refl _
lemma mem_Lp_iff_mem_ℒp {f : α →ₘ[μ] E} : f ∈ Lp E p μ ↔ mem_ℒp f p μ :=
by simp [mem_Lp_iff_snorm_lt_top, mem_ℒp, f.measurable.ae_measurable]
lemma antimono [is_finite_measure μ] {p q : ℝ≥0∞} (hpq : p ≤ q) : Lp E q μ ≤ Lp E p μ :=
λ f hf, (mem_ℒp.mem_ℒp_of_exponent_le ⟨f.ae_measurable, hf⟩ hpq).2
@[simp] lemma coe_fn_mk {f : α →ₘ[μ] E} (hf : snorm f p μ < ∞) :
((⟨f, hf⟩ : Lp E p μ) : α → E) = f := rfl
@[simp] lemma coe_mk {f : α →ₘ[μ] E} (hf : snorm f p μ < ∞) :
((⟨f, hf⟩ : Lp E p μ) : α →ₘ[μ] E) = f := rfl
@[simp] lemma to_Lp_coe_fn (f : Lp E p μ) (hf : mem_ℒp f p μ) : hf.to_Lp f = f :=
by { cases f, simp [mem_ℒp.to_Lp] }
lemma snorm_lt_top (f : Lp E p μ) : snorm f p μ < ∞ := f.prop
lemma snorm_ne_top (f : Lp E p μ) : snorm f p μ ≠ ∞ := (snorm_lt_top f).ne
@[measurability]
protected lemma measurable (f : Lp E p μ) : measurable f := f.val.measurable
@[measurability]
protected lemma ae_measurable (f : Lp E p μ) : ae_measurable f μ := f.val.ae_measurable
protected lemma mem_ℒp (f : Lp E p μ) : mem_ℒp f p μ := ⟨Lp.ae_measurable f, f.prop⟩
variables (E p μ)
lemma coe_fn_zero : ⇑(0 : Lp E p μ) =ᵐ[μ] 0 := ae_eq_fun.coe_fn_zero
variables {E p μ}
lemma coe_fn_neg (f : Lp E p μ) : ⇑(-f) =ᵐ[μ] -f := ae_eq_fun.coe_fn_neg _
lemma coe_fn_add (f g : Lp E p μ) : ⇑(f + g) =ᵐ[μ] f + g := ae_eq_fun.coe_fn_add _ _
lemma coe_fn_sub (f g : Lp E p μ) : ⇑(f - g) =ᵐ[μ] f - g := ae_eq_fun.coe_fn_sub _ _
lemma mem_Lp_const (α) {m : measurable_space α} (μ : measure α) (c : E) [is_finite_measure μ] :
@ae_eq_fun.const α _ _ μ _ c ∈ Lp E p μ :=
(mem_ℒp_const c).snorm_mk_lt_top
instance : has_norm (Lp E p μ) := { norm := λ f, ennreal.to_real (snorm f p μ) }
instance : has_dist (Lp E p μ) := { dist := λ f g, ∥f - g∥}
instance : has_edist (Lp E p μ) := { edist := λ f g, ennreal.of_real (dist f g) }
lemma norm_def (f : Lp E p μ) : ∥f∥ = ennreal.to_real (snorm f p μ) := rfl
@[simp] lemma norm_to_Lp (f : α → E) (hf : mem_ℒp f p μ) :
∥hf.to_Lp f∥ = ennreal.to_real (snorm f p μ) :=
by rw [norm_def, snorm_congr_ae (mem_ℒp.coe_fn_to_Lp hf)]
lemma dist_def (f g : Lp E p μ) : dist f g = (snorm (f - g) p μ).to_real :=
begin
simp_rw [dist, norm_def],
congr' 1,
apply snorm_congr_ae (coe_fn_sub _ _),
end
lemma edist_def (f g : Lp E p μ) : edist f g = snorm (f - g) p μ :=
begin
simp_rw [edist, dist, norm_def, ennreal.of_real_to_real (snorm_ne_top _)],
exact snorm_congr_ae (coe_fn_sub _ _)
end
@[simp] lemma edist_to_Lp_to_Lp (f g : α → E) (hf : mem_ℒp f p μ) (hg : mem_ℒp g p μ) :
edist (hf.to_Lp f) (hg.to_Lp g) = snorm (f - g) p μ :=
by { rw edist_def, exact snorm_congr_ae (hf.coe_fn_to_Lp.sub hg.coe_fn_to_Lp) }
@[simp] lemma edist_to_Lp_zero (f : α → E) (hf : mem_ℒp f p μ) :
edist (hf.to_Lp f) 0 = snorm f p μ :=
by { convert edist_to_Lp_to_Lp f 0 hf zero_mem_ℒp, simp }
@[simp] lemma norm_zero : ∥(0 : Lp E p μ)∥ = 0 :=
begin
change (snorm ⇑(0 : α →ₘ[μ] E) p μ).to_real = 0,
simp [snorm_congr_ae ae_eq_fun.coe_fn_zero, snorm_zero]
end
lemma norm_eq_zero_iff {f : Lp E p μ} (hp : 0 < p) : ∥f∥ = 0 ↔ f = 0 :=
begin
refine ⟨λ hf, _, λ hf, by simp [hf]⟩,
rw [norm_def, ennreal.to_real_eq_zero_iff] at hf,
cases hf,
{ rw snorm_eq_zero_iff (Lp.ae_measurable f) hp.ne.symm at hf,
exact subtype.eq (ae_eq_fun.ext (hf.trans ae_eq_fun.coe_fn_zero.symm)), },
{ exact absurd hf (snorm_ne_top f), },
end
lemma eq_zero_iff_ae_eq_zero {f : Lp E p μ} : f = 0 ↔ f =ᵐ[μ] 0 :=
begin
split,
{ assume h,
rw h,
exact ae_eq_fun.coe_fn_const _ _ },
{ assume h,
ext1,
filter_upwards [h, ae_eq_fun.coe_fn_const α (0 : E)],
assume a ha h'a,
rw ha,
exact h'a.symm }
end
@[simp] lemma norm_neg {f : Lp E p μ} : ∥-f∥ = ∥f∥ :=
by rw [norm_def, norm_def, snorm_congr_ae (coe_fn_neg _), snorm_neg]
lemma norm_le_mul_norm_of_ae_le_mul
[second_countable_topology F] [measurable_space F] [borel_space F]
{c : ℝ} {f : Lp E p μ} {g : Lp F p μ} (h : ∀ᵐ x ∂μ, ∥f x∥ ≤ c * ∥g x∥) : ∥f∥ ≤ c * ∥g∥ :=
begin
by_cases pzero : p = 0,
{ simp [pzero, norm_def] },
cases le_or_lt 0 c with hc hc,
{ have := snorm_le_mul_snorm_aux_of_nonneg h hc p,
rw [← ennreal.to_real_le_to_real, ennreal.to_real_mul, ennreal.to_real_of_real hc] at this,
{ exact this },
{ exact (Lp.mem_ℒp _).snorm_ne_top },
{ simp [(Lp.mem_ℒp _).snorm_ne_top] } },
{ have := snorm_le_mul_snorm_aux_of_neg h hc p,
simp only [snorm_eq_zero_iff (Lp.ae_measurable _) pzero, ← eq_zero_iff_ae_eq_zero] at this,
simp [this] }
end
lemma norm_le_norm_of_ae_le [second_countable_topology F] [measurable_space F] [borel_space F]
{f : Lp E p μ} {g : Lp F p μ} (h : ∀ᵐ x ∂μ, ∥f x∥ ≤ ∥g x∥) : ∥f∥ ≤ ∥g∥ :=
begin
rw [norm_def, norm_def, ennreal.to_real_le_to_real (snorm_ne_top _) (snorm_ne_top _)],
exact snorm_mono_ae h
end
lemma mem_Lp_of_ae_le_mul [second_countable_topology F] [measurable_space F] [borel_space F]
{c : ℝ} {f : α →ₘ[μ] E} {g : Lp F p μ} (h : ∀ᵐ x ∂μ, ∥f x∥ ≤ c * ∥g x∥) : f ∈ Lp E p μ :=
mem_Lp_iff_mem_ℒp.2 $ mem_ℒp.of_le_mul (Lp.mem_ℒp g) f.ae_measurable h
lemma mem_Lp_of_ae_le [second_countable_topology F] [measurable_space F] [borel_space F]
{f : α →ₘ[μ] E} {g : Lp F p μ} (h : ∀ᵐ x ∂μ, ∥f x∥ ≤ ∥g x∥) : f ∈ Lp E p μ :=
mem_Lp_iff_mem_ℒp.2 $ mem_ℒp.of_le (Lp.mem_ℒp g) f.ae_measurable h
lemma mem_Lp_of_ae_bound [is_finite_measure μ] {f : α →ₘ[μ] E} (C : ℝ) (hfC : ∀ᵐ x ∂μ, ∥f x∥ ≤ C) :
f ∈ Lp E p μ :=
mem_Lp_iff_mem_ℒp.2 $ mem_ℒp.of_bound f.ae_measurable _ hfC
lemma norm_le_of_ae_bound [is_finite_measure μ] {f : Lp E p μ} {C : ℝ} (hC : 0 ≤ C)
(hfC : ∀ᵐ x ∂μ, ∥f x∥ ≤ C) :
∥f∥ ≤ (measure_univ_nnreal μ) ^ (p.to_real)⁻¹ * C :=
begin
by_cases hμ : μ = 0,
{ by_cases hp : p.to_real⁻¹ = 0,
{ simpa [hp, hμ, norm_def] using hC },
{ simp [hμ, norm_def, real.zero_rpow hp] } },
let A : ℝ≥0 := (measure_univ_nnreal μ) ^ (p.to_real)⁻¹ * ⟨C, hC⟩,
suffices : snorm f p μ ≤ A,
{ exact ennreal.to_real_le_coe_of_le_coe this },
convert snorm_le_of_ae_bound hfC,
rw [← coe_measure_univ_nnreal μ, ennreal.coe_rpow_of_ne_zero (measure_univ_nnreal_pos hμ).ne',
ennreal.coe_mul],
congr,
rw max_eq_left hC
end
instance [hp : fact (1 ≤ p)] : normed_group (Lp E p μ) :=
normed_group.of_core _
{ norm_eq_zero_iff := λ f, norm_eq_zero_iff (ennreal.zero_lt_one.trans_le hp.1),
triangle := begin
assume f g,
simp only [norm_def],
rw ← ennreal.to_real_add (snorm_ne_top f) (snorm_ne_top g),
suffices h_snorm : snorm ⇑(f + g) p μ ≤ snorm ⇑f p μ + snorm ⇑g p μ,
{ rwa ennreal.to_real_le_to_real (snorm_ne_top (f + g)),
exact ennreal.add_ne_top.mpr ⟨snorm_ne_top f, snorm_ne_top g⟩, },
rw [snorm_congr_ae (coe_fn_add _ _)],
exact snorm_add_le (Lp.ae_measurable f) (Lp.ae_measurable g) hp.1,
end,
norm_neg := by simp }
instance normed_group_L1 : normed_group (Lp E 1 μ) := by apply_instance
instance normed_group_L2 : normed_group (Lp E 2 μ) := by apply_instance
instance normed_group_Ltop : normed_group (Lp E ∞ μ) := by apply_instance
section normed_space
variables {𝕜 : Type*} [normed_field 𝕜] [normed_space 𝕜 E] [measurable_space 𝕜]
[opens_measurable_space 𝕜]
lemma mem_Lp_const_smul (c : 𝕜) (f : Lp E p μ) : c • ↑f ∈ Lp E p μ :=
begin
rw [mem_Lp_iff_snorm_lt_top, snorm_congr_ae (ae_eq_fun.coe_fn_smul _ _), snorm_const_smul,
ennreal.mul_lt_top_iff],
exact or.inl ⟨ennreal.coe_lt_top, f.prop⟩,
end
variables (E p μ 𝕜)
/-- The `𝕜`-submodule of elements of `α →ₘ[μ] E` whose `Lp` norm is finite. This is `Lp E p μ`,
with extra structure. -/
def Lp_submodule : submodule 𝕜 (α →ₘ[μ] E) :=
{ smul_mem' := λ c f hf, by simpa using mem_Lp_const_smul c ⟨f, hf⟩,
.. Lp E p μ }
variables {E p μ 𝕜}
lemma coe_Lp_submodule : (Lp_submodule E p μ 𝕜).to_add_subgroup = Lp E p μ := rfl
instance : module 𝕜 (Lp E p μ) :=
{ .. (Lp_submodule E p μ 𝕜).module }
lemma coe_fn_smul (c : 𝕜) (f : Lp E p μ) : ⇑(c • f) =ᵐ[μ] c • f := ae_eq_fun.coe_fn_smul _ _
lemma norm_const_smul (c : 𝕜) (f : Lp E p μ) : ∥c • f∥ = ∥c∥ * ∥f∥ :=
by rw [norm_def, snorm_congr_ae (coe_fn_smul _ _), snorm_const_smul c,
ennreal.to_real_mul, ennreal.coe_to_real, coe_nnnorm, norm_def]
instance [fact (1 ≤ p)] : normed_space 𝕜 (Lp E p μ) :=
{ norm_smul_le := λ _ _, by simp [norm_const_smul] }
instance normed_space_L1 : normed_space 𝕜 (Lp E 1 μ) := by apply_instance
instance normed_space_L2 : normed_space 𝕜 (Lp E 2 μ) := by apply_instance
instance normed_space_Ltop : normed_space 𝕜 (Lp E ∞ μ) := by apply_instance
instance [normed_space ℝ E] [has_scalar ℝ 𝕜] [is_scalar_tower ℝ 𝕜 E] :
is_scalar_tower ℝ 𝕜 (Lp E p μ) :=
begin
refine ⟨λ r c f, _⟩,
ext1,
refine (Lp.coe_fn_smul _ _).trans _,
rw smul_assoc,
refine eventually_eq.trans _ (Lp.coe_fn_smul _ _).symm,
refine (Lp.coe_fn_smul c f).mono (λ x hx, _),
rw [pi.smul_apply, pi.smul_apply, pi.smul_apply, hx, pi.smul_apply],
end
end normed_space
end Lp
namespace mem_ℒp
variables
[borel_space E] [second_countable_topology E]
{𝕜 : Type*} [normed_field 𝕜] [normed_space 𝕜 E] [measurable_space 𝕜] [opens_measurable_space 𝕜]
lemma to_Lp_const_smul {f : α → E} (c : 𝕜) (hf : mem_ℒp f p μ) :
(hf.const_smul c).to_Lp (c • f) = c • hf.to_Lp f := rfl
end mem_ℒp
/-! ### Indicator of a set as an element of Lᵖ
For a set `s` with `(hs : measurable_set s)` and `(hμs : μ s < ∞)`, we build
`indicator_const_Lp p hs hμs c`, the element of `Lp` corresponding to `s.indicator (λ x, c)`.
-/
section indicator
variables {s : set α} {hs : measurable_set s} {c : E} {f : α → E} {hf : ae_measurable f μ}
lemma snorm_ess_sup_indicator_le (s : set α) (f : α → G) :
snorm_ess_sup (s.indicator f) μ ≤ snorm_ess_sup f μ :=
begin
refine ess_sup_mono_ae (eventually_of_forall (λ x, _)),
rw [ennreal.coe_le_coe, nnnorm_indicator_eq_indicator_nnnorm],
exact set.indicator_le_self s _ x,
end
lemma snorm_ess_sup_indicator_const_le (s : set α) (c : G) :
snorm_ess_sup (s.indicator (λ x : α , c)) μ ≤ ∥c∥₊ :=
begin
by_cases hμ0 : μ = 0,
{ rw [hμ0, snorm_ess_sup_measure_zero, ennreal.coe_nonneg],
exact zero_le', },
{ exact (snorm_ess_sup_indicator_le s (λ x, c)).trans (snorm_ess_sup_const c hμ0).le, },
end
lemma snorm_ess_sup_indicator_const_eq (s : set α) (c : G) (hμs : μ s ≠ 0) :
snorm_ess_sup (s.indicator (λ x : α , c)) μ = ∥c∥₊ :=
begin
refine le_antisymm (snorm_ess_sup_indicator_const_le s c) _,
by_contra h,
push_neg at h,
have h' := ae_iff.mp (ae_lt_of_ess_sup_lt h),
push_neg at h',
refine hμs (measure_mono_null (λ x hx_mem, _) h'),
rw [set.mem_set_of_eq, set.indicator_of_mem hx_mem],
exact le_rfl,
end
variables (hs)
lemma snorm_indicator_le {E : Type*} [normed_group E] (f : α → E) :
snorm (s.indicator f) p μ ≤ snorm f p μ :=
begin
refine snorm_mono_ae (eventually_of_forall (λ x, _)),
suffices : ∥s.indicator f x∥₊ ≤ ∥f x∥₊,
{ exact nnreal.coe_mono this },
rw nnnorm_indicator_eq_indicator_nnnorm,
exact s.indicator_le_self _ x,
end
variables {hs}
lemma snorm_indicator_const {c : G} (hs : measurable_set s) (hp : p ≠ 0) (hp_top : p ≠ ∞) :
snorm (s.indicator (λ x, c)) p μ = ∥c∥₊ * (μ s) ^ (1 / p.to_real) :=
begin
have hp_pos : 0 < p.to_real,
from ennreal.to_real_pos_iff.mpr ⟨lt_of_le_of_ne (zero_le _) hp.symm, hp_top⟩,
rw snorm_eq_lintegral_rpow_nnnorm hp hp_top,
simp_rw [nnnorm_indicator_eq_indicator_nnnorm, ennreal.coe_indicator],
have h_indicator_pow : (λ a : α, s.indicator (λ (x : α), (∥c∥₊ : ℝ≥0∞)) a ^ p.to_real)
= s.indicator (λ (x : α), ↑∥c∥₊ ^ p.to_real),
{ rw set.comp_indicator_const (∥c∥₊ : ℝ≥0∞) (λ x, x ^ p.to_real) _,
simp [hp_pos], },
rw [h_indicator_pow, lintegral_indicator _ hs, set_lintegral_const, ennreal.mul_rpow_of_nonneg],
{ rw [← ennreal.rpow_mul, mul_one_div_cancel hp_pos.ne.symm, ennreal.rpow_one], },
{ simp [hp_pos.le], },
end
lemma snorm_indicator_const' {c : G} (hs : measurable_set s) (hμs : μ s ≠ 0) (hp : p ≠ 0) :
snorm (s.indicator (λ _, c)) p μ = ∥c∥₊ * (μ s) ^ (1 / p.to_real) :=
begin
by_cases hp_top : p = ∞,
{ simp [hp_top, snorm_ess_sup_indicator_const_eq s c hμs], },
{ exact snorm_indicator_const hs hp hp_top, },
end
lemma mem_ℒp.indicator (hs : measurable_set s) (hf : mem_ℒp f p μ) :
mem_ℒp (s.indicator f) p μ :=
⟨hf.ae_measurable.indicator hs, lt_of_le_of_lt (snorm_indicator_le f) hf.snorm_lt_top⟩
lemma mem_ℒp_indicator_const (p : ℝ≥0∞) (hs : measurable_set s) (c : E) (hμsc : c = 0 ∨ μ s ≠ ∞) :
mem_ℒp (s.indicator (λ _, c)) p μ :=
begin
cases hμsc with hc hμs,
{ simp only [hc, set.indicator_zero],
exact zero_mem_ℒp, },
refine ⟨(ae_measurable_indicator_iff hs).mpr ae_measurable_const, _⟩,
by_cases hp0 : p = 0,
{ simp only [hp0, snorm_exponent_zero, with_top.zero_lt_top], },
by_cases hp_top : p = ∞,
{ rw [hp_top, snorm_exponent_top],
exact (snorm_ess_sup_indicator_const_le s c).trans_lt ennreal.coe_lt_top, },
have hp_pos : 0 < p.to_real,
from ennreal.to_real_pos_iff.mpr ⟨lt_of_le_of_ne (zero_le _) (ne.symm hp0), hp_top⟩,
rw snorm_lt_top_iff_lintegral_rpow_nnnorm_lt_top hp0 hp_top,
simp_rw [nnnorm_indicator_eq_indicator_nnnorm, ennreal.coe_indicator],
have h_indicator_pow : (λ a : α, s.indicator (λ _, (∥c∥₊ : ℝ≥0∞)) a ^ p.to_real)
= s.indicator (λ _, ↑∥c∥₊ ^ p.to_real),
{ rw set.comp_indicator_const (∥c∥₊ : ℝ≥0∞) (λ x, x ^ p.to_real) _, simp [hp_pos], },
rw [h_indicator_pow, lintegral_indicator _ hs, set_lintegral_const],
refine ennreal.mul_lt_top _ (lt_top_iff_ne_top.mpr hμs),
exact ennreal.rpow_lt_top_of_nonneg hp_pos.le ennreal.coe_ne_top,
end
end indicator
section indicator_const_Lp
open set function
variables {s : set α} {hs : measurable_set s} {hμs : μ s ≠ ∞} {c : E}
[borel_space E] [second_countable_topology E]
/-- Indicator of a set as an element of `Lp`. -/
def indicator_const_Lp (p : ℝ≥0∞) (hs : measurable_set s) (hμs : μ s ≠ ∞) (c : E) : Lp E p μ :=
mem_ℒp.to_Lp (s.indicator (λ _, c)) (mem_ℒp_indicator_const p hs c (or.inr hμs))
lemma indicator_const_Lp_coe_fn : ⇑(indicator_const_Lp p hs hμs c) =ᵐ[μ] s.indicator (λ _, c) :=
mem_ℒp.coe_fn_to_Lp (mem_ℒp_indicator_const p hs c (or.inr hμs))
lemma indicator_const_Lp_coe_fn_mem :
∀ᵐ (x : α) ∂μ, x ∈ s → indicator_const_Lp p hs hμs c x = c :=
indicator_const_Lp_coe_fn.mono (λ x hx hxs, hx.trans (set.indicator_of_mem hxs _))
lemma indicator_const_Lp_coe_fn_nmem :
∀ᵐ (x : α) ∂μ, x ∉ s → indicator_const_Lp p hs hμs c x = 0 :=
indicator_const_Lp_coe_fn.mono (λ x hx hxs, hx.trans (set.indicator_of_not_mem hxs _))
lemma norm_indicator_const_Lp (hp_ne_zero : p ≠ 0) (hp_ne_top : p ≠ ∞) :
∥indicator_const_Lp p hs hμs c∥ = ∥c∥ * (μ s).to_real ^ (1 / p.to_real) :=
by rw [Lp.norm_def, snorm_congr_ae indicator_const_Lp_coe_fn,
snorm_indicator_const hs hp_ne_zero hp_ne_top, ennreal.to_real_mul, ennreal.to_real_rpow,
ennreal.coe_to_real, coe_nnnorm]
lemma norm_indicator_const_Lp_top (hμs_ne_zero : μ s ≠ 0) : ∥indicator_const_Lp ∞ hs hμs c∥ = ∥c∥ :=
by rw [Lp.norm_def, snorm_congr_ae indicator_const_Lp_coe_fn,
snorm_indicator_const' hs hμs_ne_zero ennreal.top_ne_zero, ennreal.top_to_real, div_zero,
ennreal.rpow_zero, mul_one, ennreal.coe_to_real, coe_nnnorm]
lemma norm_indicator_const_Lp' (hp_pos : p ≠ 0) (hμs_pos : μ s ≠ 0) :
∥indicator_const_Lp p hs hμs c∥ = ∥c∥ * (μ s).to_real ^ (1 / p.to_real) :=
begin
by_cases hp_top : p = ∞,
{ rw [hp_top, ennreal.top_to_real, div_zero, real.rpow_zero, mul_one],
exact norm_indicator_const_Lp_top hμs_pos, },
{ exact norm_indicator_const_Lp hp_pos hp_top, },
end
@[simp] lemma indicator_const_empty :
indicator_const_Lp p measurable_set.empty (by simp : μ ∅ ≠ ∞) c = 0 :=
begin
rw Lp.eq_zero_iff_ae_eq_zero,
convert indicator_const_Lp_coe_fn,
simp [set.indicator_empty'],
end
lemma mem_ℒp_add_of_disjoint {f g : α → E}
(h : disjoint (support f) (support g)) (hf : measurable f) (hg : measurable g) :
mem_ℒp (f + g) p μ ↔ mem_ℒp f p μ ∧ mem_ℒp g p μ :=
begin
refine ⟨λ hfg, ⟨_, _⟩, λ h, h.1.add h.2⟩,
{ rw ← indicator_add_eq_left h, exact hfg.indicator (measurable_set_support hf) },
{ rw ← indicator_add_eq_right h, exact hfg.indicator (measurable_set_support hg) }
end
/-- The indicator of a disjoint union of two sets is the sum of the indicators of the sets. -/
lemma indicator_const_Lp_disjoint_union {s t : set α} (hs : measurable_set s)
(ht : measurable_set t) (hμs : μ s ≠ ∞) (hμt : μ t ≠ ∞) (hst : s ∩ t = ∅) (c : E) :
(indicator_const_Lp p (hs.union ht) ((measure_union_le s t).trans_lt
(lt_top_iff_ne_top.mpr (ennreal.add_ne_top.mpr ⟨hμs, hμt⟩))).ne c)
= indicator_const_Lp p hs hμs c + indicator_const_Lp p ht hμt c :=
begin
ext1,
refine indicator_const_Lp_coe_fn.trans (eventually_eq.trans _ (Lp.coe_fn_add _ _).symm),
refine eventually_eq.trans _
(eventually_eq.add indicator_const_Lp_coe_fn.symm indicator_const_Lp_coe_fn.symm),
rw set.indicator_union_of_disjoint (set.disjoint_iff_inter_eq_empty.mpr hst) _,
end
end indicator_const_Lp
end measure_theory
open measure_theory
/-!
### Composition on `L^p`
We show that Lipschitz functions vanishing at zero act by composition on `L^p`, and specialize
this to the composition with continuous linear maps, and to the definition of the positive
part of an `L^p` function.
-/
section composition
variables [second_countable_topology E] [borel_space E]
[second_countable_topology F] [measurable_space F] [borel_space F]
{g : E → F} {c : ℝ≥0}
namespace lipschitz_with
lemma mem_ℒp_comp_iff_of_antilipschitz {α E F} {K K'} [measurable_space α] {μ : measure α}
[measurable_space E] [measurable_space F] [normed_group E] [normed_group F] [borel_space E]
[borel_space F] [complete_space E]
{f : α → E} {g : E → F} (hg : lipschitz_with K g) (hg' : antilipschitz_with K' g) (g0 : g 0 = 0) :
mem_ℒp (g ∘ f) p μ ↔ mem_ℒp f p μ :=
begin
have := ae_measurable_comp_iff_of_closed_embedding g (hg'.closed_embedding hg.uniform_continuous),
split,
{ assume H,
have A : ∀ᵐ x ∂μ, ∥f x∥ ≤ K' * ∥g (f x)∥,
{ apply filter.eventually_of_forall (λ x, _),
rw [← dist_zero_right, ← dist_zero_right, ← g0],
apply hg'.le_mul_dist },
exact H.of_le_mul (this.1 H.ae_measurable) A },
{ assume H,
have A : ∀ᵐ x ∂μ, ∥g (f x)∥ ≤ K * ∥f x∥,
{ apply filter.eventually_of_forall (λ x, _),
rw [← dist_zero_right, ← dist_zero_right, ← g0],
apply hg.dist_le_mul },
exact H.of_le_mul (this.2 H.ae_measurable) A }
end
/-- When `g` is a Lipschitz function sending `0` to `0` and `f` is in `Lp`, then `g ∘ f` is well
defined as an element of `Lp`. -/
def comp_Lp (hg : lipschitz_with c g) (g0 : g 0 = 0) (f : Lp E p μ) : Lp F p μ :=
⟨ae_eq_fun.comp g hg.continuous.measurable (f : α →ₘ[μ] E),
begin
suffices : ∀ᵐ x ∂μ, ∥ae_eq_fun.comp g hg.continuous.measurable (f : α →ₘ[μ] E) x∥ ≤ c * ∥f x∥,
{ exact Lp.mem_Lp_of_ae_le_mul this },
filter_upwards [ae_eq_fun.coe_fn_comp g hg.continuous.measurable (f : α →ₘ[μ] E)],
assume a ha,
simp only [ha],
rw [← dist_zero_right, ← dist_zero_right, ← g0],
exact hg.dist_le_mul (f a) 0,
end⟩
lemma coe_fn_comp_Lp (hg : lipschitz_with c g) (g0 : g 0 = 0) (f : Lp E p μ) :
hg.comp_Lp g0 f =ᵐ[μ] g ∘ f :=
ae_eq_fun.coe_fn_comp _ _ _
@[simp] lemma comp_Lp_zero (hg : lipschitz_with c g) (g0 : g 0 = 0) :
hg.comp_Lp g0 (0 : Lp E p μ) = 0 :=
begin
rw Lp.eq_zero_iff_ae_eq_zero,
apply (coe_fn_comp_Lp _ _ _).trans,
filter_upwards [Lp.coe_fn_zero E p μ],
assume a ha,
simp [ha, g0]
end
lemma norm_comp_Lp_sub_le (hg : lipschitz_with c g) (g0 : g 0 = 0) (f f' : Lp E p μ) :
∥hg.comp_Lp g0 f - hg.comp_Lp g0 f'∥ ≤ c * ∥f - f'∥ :=
begin
apply Lp.norm_le_mul_norm_of_ae_le_mul,
filter_upwards [hg.coe_fn_comp_Lp g0 f, hg.coe_fn_comp_Lp g0 f',
Lp.coe_fn_sub (hg.comp_Lp g0 f) (hg.comp_Lp g0 f'), Lp.coe_fn_sub f f'],
assume a ha1 ha2 ha3 ha4,
simp [ha1, ha2, ha3, ha4, ← dist_eq_norm],
exact hg.dist_le_mul (f a) (f' a)
end
lemma norm_comp_Lp_le (hg : lipschitz_with c g) (g0 : g 0 = 0) (f : Lp E p μ) :
∥hg.comp_Lp g0 f∥ ≤ c * ∥f∥ :=
by simpa using hg.norm_comp_Lp_sub_le g0 f 0
lemma lipschitz_with_comp_Lp [fact (1 ≤ p)] (hg : lipschitz_with c g) (g0 : g 0 = 0) :
lipschitz_with c (hg.comp_Lp g0 : Lp E p μ → Lp F p μ) :=
lipschitz_with.of_dist_le_mul $ λ f g, by simp [dist_eq_norm, norm_comp_Lp_sub_le]
lemma continuous_comp_Lp [fact (1 ≤ p)] (hg : lipschitz_with c g) (g0 : g 0 = 0) :
continuous (hg.comp_Lp g0 : Lp E p μ → Lp F p μ) :=
(lipschitz_with_comp_Lp hg g0).continuous
end lipschitz_with
namespace continuous_linear_map
variables {𝕜 : Type*} [nondiscrete_normed_field 𝕜] [normed_space 𝕜 E] [normed_space 𝕜 F]
/-- Composing `f : Lp ` with `L : E →L[𝕜] F`. -/
def comp_Lp (L : E →L[𝕜] F) (f : Lp E p μ) : Lp F p μ :=
L.lipschitz.comp_Lp (map_zero L) f
lemma coe_fn_comp_Lp (L : E →L[𝕜] F) (f : Lp E p μ) :
∀ᵐ a ∂μ, (L.comp_Lp f) a = L (f a) :=
lipschitz_with.coe_fn_comp_Lp _ _ _
lemma coe_fn_comp_Lp' (L : E →L[𝕜] F) (f : Lp E p μ) :
L.comp_Lp f =ᵐ[μ] λ a, L (f a) :=
L.coe_fn_comp_Lp f
lemma add_comp_Lp (L L' : E →L[𝕜] F) (f : Lp E p μ) :
(L + L').comp_Lp f = L.comp_Lp f + L'.comp_Lp f :=
begin
ext1,
refine (coe_fn_comp_Lp' (L + L') f).trans _,
refine eventually_eq.trans _ (Lp.coe_fn_add _ _).symm,
refine eventually_eq.trans _
(eventually_eq.add (L.coe_fn_comp_Lp' f).symm (L'.coe_fn_comp_Lp' f).symm),
refine eventually_of_forall (λ x, _),
refl,
end
lemma smul_comp_Lp {𝕜'} [normed_field 𝕜'] [measurable_space 𝕜'] [opens_measurable_space 𝕜']
[normed_space 𝕜' F] [smul_comm_class 𝕜 𝕜' F] (c : 𝕜') (L : E →L[𝕜] F) (f : Lp E p μ) :
(c • L).comp_Lp f = c • L.comp_Lp f :=
begin
ext1,
refine (coe_fn_comp_Lp' (c • L) f).trans _,
refine eventually_eq.trans _ (Lp.coe_fn_smul _ _).symm,
refine (L.coe_fn_comp_Lp' f).mono (λ x hx, _),
rw [pi.smul_apply, hx],
refl,
end
lemma norm_comp_Lp_le (L : E →L[𝕜] F) (f : Lp E p μ) : ∥L.comp_Lp f∥ ≤ ∥L∥ * ∥f∥ :=
lipschitz_with.norm_comp_Lp_le _ _ _
variables (μ p) [measurable_space 𝕜] [opens_measurable_space 𝕜]
/-- Composing `f : Lp E p μ` with `L : E →L[𝕜] F`, seen as a `𝕜`-linear map on `Lp E p μ`. -/
def comp_Lpₗ (L : E →L[𝕜] F) : (Lp E p μ) →ₗ[𝕜] (Lp F p μ) :=
{ to_fun := λ f, L.comp_Lp f,
map_add' := begin
intros f g,
ext1,
filter_upwards [Lp.coe_fn_add f g, coe_fn_comp_Lp L (f + g), coe_fn_comp_Lp L f,
coe_fn_comp_Lp L g, Lp.coe_fn_add (L.comp_Lp f) (L.comp_Lp g)],
assume a ha1 ha2 ha3 ha4 ha5,
simp only [ha1, ha2, ha3, ha4, ha5, map_add, pi.add_apply],
end,
map_smul' := begin
intros c f,
ext1,
filter_upwards [Lp.coe_fn_smul c f, coe_fn_comp_Lp L (c • f), Lp.coe_fn_smul c (L.comp_Lp f),
coe_fn_comp_Lp L f],
assume a ha1 ha2 ha3 ha4,
simp only [ha1, ha2, ha3, ha4, map_smul, pi.smul_apply],
end }
/-- Composing `f : Lp E p μ` with `L : E →L[𝕜] F`, seen as a continuous `𝕜`-linear map on
`Lp E p μ`. See also the similar
* `linear_map.comp_left` for functions,
* `continuous_linear_map.comp_left_continuous` for continuous functions,
* `continuous_linear_map.comp_left_continuous_bounded` for bounded continuous functions,
* `continuous_linear_map.comp_left_continuous_compact` for continuous functions on compact spaces.
-/
def comp_LpL [fact (1 ≤ p)] (L : E →L[𝕜] F) : (Lp E p μ) →L[𝕜] (Lp F p μ) :=
linear_map.mk_continuous (L.comp_Lpₗ p μ) ∥L∥ L.norm_comp_Lp_le
variables {μ p}
lemma coe_fn_comp_LpL [fact (1 ≤ p)] (L : E →L[𝕜] F) (f : Lp E p μ) :
L.comp_LpL p μ f =ᵐ[μ] λ a, L (f a) :=
L.coe_fn_comp_Lp f
lemma add_comp_LpL [fact (1 ≤ p)] (L L' : E →L[𝕜] F) :
(L + L').comp_LpL p μ = L.comp_LpL p μ + L'.comp_LpL p μ :=
by { ext1 f, exact add_comp_Lp L L' f }
lemma smul_comp_LpL [fact (1 ≤ p)] (c : 𝕜) (L : E →L[𝕜] F) :
(c • L).comp_LpL p μ = c • (L.comp_LpL p μ) :=
by { ext1 f, exact smul_comp_Lp c L f }
/-- TODO: written in an "apply" way because of a missing `has_scalar` instance. -/
lemma smul_comp_LpL_apply [fact (1 ≤ p)] {𝕜'} [normed_field 𝕜'] [measurable_space 𝕜']
[opens_measurable_space 𝕜'] [normed_space 𝕜' F] [smul_comm_class 𝕜 𝕜' F]
(c : 𝕜') (L : E →L[𝕜] F) (f : Lp E p μ) :
(c • L).comp_LpL p μ f = c • (L.comp_LpL p μ f) :=
smul_comp_Lp c L f
lemma norm_compLpL_le [fact (1 ≤ p)] (L : E →L[𝕜] F) :
∥L.comp_LpL p μ∥ ≤ ∥L∥ :=
linear_map.mk_continuous_norm_le _ (norm_nonneg _) _
end continuous_linear_map
namespace measure_theory
lemma indicator_const_Lp_eq_to_span_singleton_comp_Lp {s : set α} [normed_space ℝ F]
(hs : measurable_set s) (hμs : μ s ≠ ∞) (x : F) :
indicator_const_Lp 2 hs hμs x =
(continuous_linear_map.to_span_singleton ℝ x).comp_Lp (indicator_const_Lp 2 hs hμs (1 : ℝ)) :=
begin
ext1,
refine indicator_const_Lp_coe_fn.trans _,
have h_comp_Lp := (continuous_linear_map.to_span_singleton ℝ x).coe_fn_comp_Lp
(indicator_const_Lp 2 hs hμs (1 : ℝ)),
rw ← eventually_eq at h_comp_Lp,
refine eventually_eq.trans _ h_comp_Lp.symm,
refine (@indicator_const_Lp_coe_fn _ _ _ 2 μ _ _ s hs hμs (1 : ℝ) _ _).mono (λ y hy, _),
dsimp only,
rw hy,
simp_rw [continuous_linear_map.to_span_singleton_apply],
by_cases hy_mem : y ∈ s; simp [hy_mem, continuous_linear_map.lsmul_apply],
end
namespace Lp
section pos_part
lemma lipschitz_with_pos_part : lipschitz_with 1 (λ (x : ℝ), max x 0) :=
lipschitz_with.of_dist_le_mul $ λ x y, by simp [dist, abs_max_sub_max_le_abs]
/-- Positive part of a function in `L^p`. -/
def pos_part (f : Lp ℝ p μ) : Lp ℝ p μ :=
lipschitz_with_pos_part.comp_Lp (max_eq_right (le_refl _)) f
/-- Negative part of a function in `L^p`. -/
def neg_part (f : Lp ℝ p μ) : Lp ℝ p μ := pos_part (-f)
@[norm_cast]
lemma coe_pos_part (f : Lp ℝ p μ) : (pos_part f : α →ₘ[μ] ℝ) = (f : α →ₘ[μ] ℝ).pos_part := rfl
lemma coe_fn_pos_part (f : Lp ℝ p μ) : ⇑(pos_part f) =ᵐ[μ] λ a, max (f a) 0 :=
ae_eq_fun.coe_fn_pos_part _
lemma coe_fn_neg_part_eq_max (f : Lp ℝ p μ) : ∀ᵐ a ∂μ, neg_part f a = max (- f a) 0 :=
begin
rw neg_part,
filter_upwards [coe_fn_pos_part (-f), coe_fn_neg f],
assume a h₁ h₂,
rw [h₁, h₂, pi.neg_apply]
end
lemma coe_fn_neg_part (f : Lp ℝ p μ) : ∀ᵐ a ∂μ, neg_part f a = - min (f a) 0 :=
(coe_fn_neg_part_eq_max f).mono $ assume a h,
by rw [h, ← max_neg_neg, neg_zero]
lemma continuous_pos_part [fact (1 ≤ p)] : continuous (λf : Lp ℝ p μ, pos_part f) :=
lipschitz_with.continuous_comp_Lp _ _
lemma continuous_neg_part [fact (1 ≤ p)] : continuous (λf : Lp ℝ p μ, neg_part f) :=
have eq : (λf : Lp ℝ p μ, neg_part f) = (λf : Lp ℝ p μ, pos_part (-f)) := rfl,
by { rw eq, exact continuous_pos_part.comp continuous_neg }
end pos_part
end Lp
end measure_theory
end composition
/-!
## `L^p` is a complete space
We show that `L^p` is a complete space for `1 ≤ p`.
-/
section complete_space
variables [borel_space E] [second_countable_topology E]
namespace measure_theory
namespace Lp
lemma snorm'_lim_eq_lintegral_liminf {ι} [nonempty ι] [linear_order ι] {f : ι → α → G} {p : ℝ}
(hp_nonneg : 0 ≤ p) {f_lim : α → G}
(h_lim : ∀ᵐ (x : α) ∂μ, tendsto (λ n, f n x) at_top (𝓝 (f_lim x))) :
snorm' f_lim p μ = (∫⁻ a, at_top.liminf (λ m, (nnnorm (f m a) : ℝ≥0∞)^p) ∂μ) ^ (1/p) :=
begin
suffices h_no_pow : (∫⁻ a, (nnnorm (f_lim a)) ^ p ∂μ)
= (∫⁻ a, at_top.liminf (λ m, (nnnorm (f m a) : ℝ≥0∞)^p) ∂μ),
{ rw [snorm', h_no_pow], },
refine lintegral_congr_ae (h_lim.mono (λ a ha, _)),
rw tendsto.liminf_eq,
simp_rw [ennreal.coe_rpow_of_nonneg _ hp_nonneg, ennreal.tendsto_coe],
refine ((nnreal.continuous_rpow_const hp_nonneg).tendsto (nnnorm (f_lim a))).comp _,
exact (continuous_nnnorm.tendsto (f_lim a)).comp ha,
end
lemma snorm'_lim_le_liminf_snorm' {E} [measurable_space E]
[normed_group E] [borel_space E] {f : ℕ → α → E} {p : ℝ} (hp_pos : 0 < p)
(hf : ∀ n, ae_measurable (f n) μ) {f_lim : α → E}
(h_lim : ∀ᵐ (x : α) ∂μ, tendsto (λ n, f n x) at_top (𝓝 (f_lim x))) :
snorm' f_lim p μ ≤ at_top.liminf (λ n, snorm' (f n) p μ) :=
begin
rw snorm'_lim_eq_lintegral_liminf hp_pos.le h_lim,
rw [←ennreal.le_rpow_one_div_iff (by simp [hp_pos] : 0 < 1 / p), one_div_one_div],
refine (lintegral_liminf_le' (λ m, ((hf m).ennnorm.pow_const _))).trans_eq _,
have h_pow_liminf : at_top.liminf (λ n, snorm' (f n) p μ) ^ p
= at_top.liminf (λ n, (snorm' (f n) p μ) ^ p),
{ have h_rpow_mono := ennreal.rpow_left_strict_mono_of_pos hp_pos,
have h_rpow_surj := (ennreal.rpow_left_bijective hp_pos.ne.symm).2,
refine (h_rpow_mono.order_iso_of_surjective _ h_rpow_surj).liminf_apply _ _ _ _,
all_goals { is_bounded_default }, },
rw h_pow_liminf,
simp_rw [snorm', ← ennreal.rpow_mul, one_div, inv_mul_cancel hp_pos.ne.symm, ennreal.rpow_one],
end
lemma snorm_exponent_top_lim_eq_ess_sup_liminf {ι} [nonempty ι] [linear_order ι] {f : ι → α → G}
{f_lim : α → G}
(h_lim : ∀ᵐ (x : α) ∂μ, tendsto (λ n, f n x) at_top (𝓝 (f_lim x))) :
snorm f_lim ∞ μ = ess_sup (λ x, at_top.liminf (λ m, (nnnorm (f m x) : ℝ≥0∞))) μ :=
begin
rw [snorm_exponent_top, snorm_ess_sup],
refine ess_sup_congr_ae (h_lim.mono (λ x hx, _)),
rw tendsto.liminf_eq,
rw ennreal.tendsto_coe,
exact (continuous_nnnorm.tendsto (f_lim x)).comp hx,
end
lemma snorm_exponent_top_lim_le_liminf_snorm_exponent_top {ι} [nonempty ι] [encodable ι]
[linear_order ι] {f : ι → α → F} {f_lim : α → F}
(h_lim : ∀ᵐ (x : α) ∂μ, tendsto (λ n, f n x) at_top (𝓝 (f_lim x))) :
snorm f_lim ∞ μ ≤ at_top.liminf (λ n, snorm (f n) ∞ μ) :=
begin
rw snorm_exponent_top_lim_eq_ess_sup_liminf h_lim,
simp_rw [snorm_exponent_top, snorm_ess_sup],
exact ennreal.ess_sup_liminf_le (λ n, (λ x, (nnnorm (f n x) : ℝ≥0∞))),
end
lemma snorm_lim_le_liminf_snorm {E} [measurable_space E] [normed_group E] [borel_space E]
{f : ℕ → α → E} (hf : ∀ n, ae_measurable (f n) μ) (f_lim : α → E)
(h_lim : ∀ᵐ (x : α) ∂μ, tendsto (λ n, f n x) at_top (𝓝 (f_lim x))) :
snorm f_lim p μ ≤ at_top.liminf (λ n, snorm (f n) p μ) :=
begin
by_cases hp0 : p = 0,
{ simp [hp0], },
rw ← ne.def at hp0,
by_cases hp_top : p = ∞,
{ simp_rw [hp_top],
exact snorm_exponent_top_lim_le_liminf_snorm_exponent_top h_lim, },
simp_rw snorm_eq_snorm' hp0 hp_top,
have hp_pos : 0 < p.to_real,
from ennreal.to_real_pos_iff.mpr ⟨lt_of_le_of_ne (zero_le _) hp0.symm, hp_top⟩,
exact snorm'_lim_le_liminf_snorm' hp_pos hf h_lim,
end
/-! ### `Lp` is complete iff Cauchy sequences of `ℒp` have limits in `ℒp` -/
lemma tendsto_Lp_iff_tendsto_ℒp' {ι} {fi : filter ι} [fact (1 ≤ p)]
(f : ι → Lp E p μ) (f_lim : Lp E p μ) :
fi.tendsto f (𝓝 f_lim) ↔ fi.tendsto (λ n, snorm (f n - f_lim) p μ) (𝓝 0) :=
begin
rw tendsto_iff_dist_tendsto_zero,
simp_rw dist_def,
rw [← ennreal.zero_to_real, ennreal.tendsto_to_real_iff (λ n, _) ennreal.zero_ne_top],
rw snorm_congr_ae (Lp.coe_fn_sub _ _).symm,
exact Lp.snorm_ne_top _,
end
lemma tendsto_Lp_iff_tendsto_ℒp {ι} {fi : filter ι} [fact (1 ≤ p)]
(f : ι → Lp E p μ) (f_lim : α → E) (f_lim_ℒp : mem_ℒp f_lim p μ) :
fi.tendsto f (𝓝 (f_lim_ℒp.to_Lp f_lim)) ↔ fi.tendsto (λ n, snorm (f n - f_lim) p μ) (𝓝 0) :=
begin
rw tendsto_Lp_iff_tendsto_ℒp',
suffices h_eq : (λ n, snorm (f n - mem_ℒp.to_Lp f_lim f_lim_ℒp) p μ)
= (λ n, snorm (f n - f_lim) p μ),
by rw h_eq,
exact funext (λ n, snorm_congr_ae (eventually_eq.rfl.sub (mem_ℒp.coe_fn_to_Lp f_lim_ℒp))),
end
lemma tendsto_Lp_iff_tendsto_ℒp'' {ι} {fi : filter ι} [fact (1 ≤ p)]
(f : ι → α → E) (f_ℒp : ∀ n, mem_ℒp (f n) p μ) (f_lim : α → E) (f_lim_ℒp : mem_ℒp f_lim p μ) :
fi.tendsto (λ n, (f_ℒp n).to_Lp (f n)) (𝓝 (f_lim_ℒp.to_Lp f_lim))
↔ fi.tendsto (λ n, snorm (f n - f_lim) p μ) (𝓝 0) :=
begin
convert Lp.tendsto_Lp_iff_tendsto_ℒp' _ _,
ext1 n,
apply snorm_congr_ae,
filter_upwards [((f_ℒp n).sub f_lim_ℒp).coe_fn_to_Lp,
Lp.coe_fn_sub ((f_ℒp n).to_Lp (f n)) (f_lim_ℒp.to_Lp f_lim)],
intros x hx₁ hx₂,
rw ← hx₂,
exact hx₁.symm
end
lemma tendsto_Lp_of_tendsto_ℒp {ι} {fi : filter ι} [hp : fact (1 ≤ p)]
{f : ι → Lp E p μ} (f_lim : α → E) (f_lim_ℒp : mem_ℒp f_lim p μ)
(h_tendsto : fi.tendsto (λ n, snorm (f n - f_lim) p μ) (𝓝 0)) :
fi.tendsto f (𝓝 (f_lim_ℒp.to_Lp f_lim)) :=
(tendsto_Lp_iff_tendsto_ℒp f f_lim f_lim_ℒp).mpr h_tendsto
lemma cauchy_seq_Lp_iff_cauchy_seq_ℒp {ι} [nonempty ι] [semilattice_sup ι] [hp : fact (1 ≤ p)]
(f : ι → Lp E p μ) :
cauchy_seq f ↔ tendsto (λ (n : ι × ι), snorm (f n.fst - f n.snd) p μ) at_top (𝓝 0) :=
begin
simp_rw [cauchy_seq_iff_tendsto_dist_at_top_0, dist_def],
rw [← ennreal.zero_to_real, ennreal.tendsto_to_real_iff (λ n, _) ennreal.zero_ne_top],
rw snorm_congr_ae (Lp.coe_fn_sub _ _).symm,
exact snorm_ne_top _,
end
lemma complete_space_Lp_of_cauchy_complete_ℒp [hp : fact (1 ≤ p)]
(H : ∀ (f : ℕ → α → E) (hf : ∀ n, mem_ℒp (f n) p μ) (B : ℕ → ℝ≥0∞) (hB : ∑' i, B i < ∞)
(h_cau : ∀ (N n m : ℕ), N ≤ n → N ≤ m → snorm (f n - f m) p μ < B N),
∃ (f_lim : α → E) (hf_lim_meas : mem_ℒp f_lim p μ),
at_top.tendsto (λ n, snorm (f n - f_lim) p μ) (𝓝 0)) :
complete_space (Lp E p μ) :=
begin
let B := λ n : ℕ, ((1:ℝ) / 2) ^ n,
have hB_pos : ∀ n, 0 < B n, from λ n, pow_pos (div_pos zero_lt_one zero_lt_two) n,
refine metric.complete_of_convergent_controlled_sequences B hB_pos (λ f hf, _),
suffices h_limit : ∃ (f_lim : α → E) (hf_lim_meas : mem_ℒp f_lim p μ),
at_top.tendsto (λ n, snorm (f n - f_lim) p μ) (𝓝 0),
{ rcases h_limit with ⟨f_lim, hf_lim_meas, h_tendsto⟩,
exact ⟨hf_lim_meas.to_Lp f_lim, tendsto_Lp_of_tendsto_ℒp f_lim hf_lim_meas h_tendsto⟩, },
have hB : summable B, from summable_geometric_two,
cases hB with M hB,
let B1 := λ n, ennreal.of_real (B n),
have hB1_has : has_sum B1 (ennreal.of_real M),
{ have h_tsum_B1 : ∑' i, B1 i = (ennreal.of_real M),
{ change (∑' (n : ℕ), ennreal.of_real (B n)) = ennreal.of_real M,
rw ←hB.tsum_eq,
exact (ennreal.of_real_tsum_of_nonneg (λ n, le_of_lt (hB_pos n)) hB.summable).symm, },
have h_sum := (@ennreal.summable _ B1).has_sum,
rwa h_tsum_B1 at h_sum, },
have hB1 : ∑' i, B1 i < ∞, by {rw hB1_has.tsum_eq, exact ennreal.of_real_lt_top, },
let f1 : ℕ → α → E := λ n, f n,
refine H f1 (λ n, Lp.mem_ℒp (f n)) B1 hB1 (λ N n m hn hm, _),
specialize hf N n m hn hm,
rw dist_def at hf,
simp_rw [f1, B1],
rwa ennreal.lt_of_real_iff_to_real_lt,
rw snorm_congr_ae (Lp.coe_fn_sub _ _).symm,
exact Lp.snorm_ne_top _,
end
/-! ### Prove that controlled Cauchy sequences of `ℒp` have limits in `ℒp` -/
private lemma snorm'_sum_norm_sub_le_tsum_of_cauchy_snorm' {f : ℕ → α → E}
(hf : ∀ n, ae_measurable (f n) μ) {p : ℝ} (hp1 : 1 ≤ p)
{B : ℕ → ℝ≥0∞} (h_cau : ∀ (N n m : ℕ), N ≤ n → N ≤ m → snorm' (f n - f m) p μ < B N) (n : ℕ) :
snorm' (λ x, ∑ i in finset.range (n + 1), norm (f (i + 1) x - f i x)) p μ ≤ ∑' i, B i :=
begin
let f_norm_diff := λ i x, norm (f (i + 1) x - f i x),
have hgf_norm_diff : ∀ n, (λ x, ∑ i in finset.range (n + 1), norm (f (i + 1) x - f i x))
= ∑ i in finset.range (n + 1), f_norm_diff i,
from λ n, funext (λ x, by simp [f_norm_diff]),
rw hgf_norm_diff,
refine (snorm'_sum_le (λ i _, ((hf (i+1)).sub (hf i)).norm) hp1).trans _,
simp_rw [←pi.sub_apply, snorm'_norm],
refine (finset.sum_le_sum _).trans (sum_le_tsum _ (λ m _, zero_le _) ennreal.summable),
exact λ m _, (h_cau m (m + 1) m (nat.le_succ m) (le_refl m)).le,
end
private lemma lintegral_rpow_sum_coe_nnnorm_sub_le_rpow_tsum {f : ℕ → α → E}
(hf : ∀ n, ae_measurable (f n) μ) {p : ℝ} (hp1 : 1 ≤ p) {B : ℕ → ℝ≥0∞} (n : ℕ)
(hn : snorm' (λ x, ∑ i in finset.range (n + 1), norm (f (i + 1) x - f i x)) p μ ≤ ∑' i, B i) :
∫⁻ a, (∑ i in finset.range (n + 1), nnnorm (f (i + 1) a - f i a) : ℝ≥0∞)^p ∂μ
≤ (∑' i, B i) ^ p :=
begin
have hp_pos : 0 < p := zero_lt_one.trans_le hp1,
rw [←one_div_one_div p, @ennreal.le_rpow_one_div_iff _ _ (1/p) (by simp [hp_pos]),
one_div_one_div p],
simp_rw snorm' at hn,
have h_nnnorm_nonneg :
(λ a, (nnnorm (∑ i in finset.range (n + 1), ∥f (i + 1) a - f i a∥) : ℝ≥0∞) ^ p)
= λ a, (∑ i in finset.range (n + 1), (nnnorm(f (i + 1) a - f i a) : ℝ≥0∞)) ^ p,
{ ext1 a,
congr,
simp_rw ←of_real_norm_eq_coe_nnnorm,
rw ←ennreal.of_real_sum_of_nonneg,
{ rw real.norm_of_nonneg _,
exact finset.sum_nonneg (λ x hx, norm_nonneg _), },
{ exact λ x hx, norm_nonneg _, }, },
change (∫⁻ a, (λ x, ↑(nnnorm (∑ i in finset.range (n + 1), ∥f (i+1) x - f i x∥))^p) a ∂μ)^(1/p)
≤ ∑' i, B i at hn,
rwa h_nnnorm_nonneg at hn,
end
private lemma lintegral_rpow_tsum_coe_nnnorm_sub_le_tsum {f : ℕ → α → E}
(hf : ∀ n, ae_measurable (f n) μ) {p : ℝ} (hp1 : 1 ≤ p) {B : ℕ → ℝ≥0∞}
(h : ∀ n, ∫⁻ a, (∑ i in finset.range (n + 1), nnnorm (f (i + 1) a - f i a) : ℝ≥0∞)^p ∂μ
≤ (∑' i, B i) ^ p) :
(∫⁻ a, (∑' i, nnnorm (f (i + 1) a - f i a) : ℝ≥0∞)^p ∂μ) ^ (1/p) ≤ ∑' i, B i :=
begin
have hp_pos : 0 < p := zero_lt_one.trans_le hp1,
suffices h_pow : ∫⁻ a, (∑' i, nnnorm (f (i + 1) a - f i a) : ℝ≥0∞)^p ∂μ ≤ (∑' i, B i) ^ p,
by rwa [←ennreal.le_rpow_one_div_iff (by simp [hp_pos] : 0 < 1 / p), one_div_one_div],
have h_tsum_1 : ∀ g : ℕ → ℝ≥0∞,
∑' i, g i = at_top.liminf (λ n, ∑ i in finset.range (n + 1), g i),
by { intro g, rw [ennreal.tsum_eq_liminf_sum_nat, ← liminf_nat_add _ 1], },
simp_rw h_tsum_1 _,
rw ← h_tsum_1,
have h_liminf_pow : ∫⁻ a, at_top.liminf (λ n, ∑ i in finset.range (n + 1),
(nnnorm (f (i + 1) a - f i a)))^p ∂μ
= ∫⁻ a, at_top.liminf (λ n, (∑ i in finset.range (n + 1), (nnnorm (f (i + 1) a - f i a)))^p) ∂μ,
{ refine lintegral_congr (λ x, _),
have h_rpow_mono := ennreal.rpow_left_strict_mono_of_pos (zero_lt_one.trans_le hp1),
have h_rpow_surj := (ennreal.rpow_left_bijective hp_pos.ne.symm).2,
refine (h_rpow_mono.order_iso_of_surjective _ h_rpow_surj).liminf_apply _ _ _ _,
all_goals { is_bounded_default }, },
rw h_liminf_pow,
refine (lintegral_liminf_le' _).trans _,
{ exact λ n, (finset.ae_measurable_sum (finset.range (n+1))
(λ i _, ((hf (i+1)).sub (hf i)).ennnorm)).pow_const _, },
{ exact liminf_le_of_frequently_le' (frequently_of_forall h), },
end
private lemma tsum_nnnorm_sub_ae_lt_top
{f : ℕ → α → E} (hf : ∀ n, ae_measurable (f n) μ) {p : ℝ} (hp1 : 1 ≤ p) {B : ℕ → ℝ≥0∞}
(hB : ∑' i, B i < ∞)
(h : (∫⁻ a, (∑' i, nnnorm (f (i + 1) a - f i a) : ℝ≥0∞)^p ∂μ) ^ (1/p) ≤ ∑' i, B i) :
∀ᵐ x ∂μ, (∑' i, nnnorm (f (i + 1) x - f i x) : ℝ≥0∞) < ∞ :=
begin
have hp_pos : 0 < p := zero_lt_one.trans_le hp1,
have h_integral : ∫⁻ a, (∑' i, nnnorm (f (i + 1) a - f i a) : ℝ≥0∞)^p ∂μ < ∞,
{ have h_tsum_lt_top : (∑' i, B i) ^ p < ∞,
from ennreal.rpow_lt_top_of_nonneg hp_pos.le (lt_top_iff_ne_top.mp hB),
refine lt_of_le_of_lt _ h_tsum_lt_top,
rwa [←ennreal.le_rpow_one_div_iff (by simp [hp_pos] : 0 < 1 / p), one_div_one_div] at h, },
have rpow_ae_lt_top : ∀ᵐ x ∂μ, (∑' i, nnnorm (f (i + 1) x - f i x) : ℝ≥0∞)^p < ∞,
{ refine ae_lt_top' (ae_measurable.pow_const _ _) h_integral,
exact ae_measurable.ennreal_tsum (λ n, ((hf (n+1)).sub (hf n)).ennnorm), },
refine rpow_ae_lt_top.mono (λ x hx, _),
rwa [←ennreal.lt_rpow_one_div_iff hp_pos,
ennreal.top_rpow_of_pos (by simp [hp_pos] : 0 < 1 / p)] at hx,
end
lemma ae_tendsto_of_cauchy_snorm' [complete_space E] {f : ℕ → α → E} {p : ℝ}
(hf : ∀ n, ae_measurable (f n) μ) (hp1 : 1 ≤ p) {B : ℕ → ℝ≥0∞} (hB : ∑' i, B i < ∞)
(h_cau : ∀ (N n m : ℕ), N ≤ n → N ≤ m → snorm' (f n - f m) p μ < B N) :
∀ᵐ x ∂μ, ∃ l : E, at_top.tendsto (λ n, f n x) (𝓝 l) :=
begin
have h_summable : ∀ᵐ x ∂μ, summable (λ (i : ℕ), f (i + 1) x - f i x),
{ have h1 : ∀ n, snorm' (λ x, ∑ i in finset.range (n + 1), norm (f (i + 1) x - f i x)) p μ
≤ ∑' i, B i,
from snorm'_sum_norm_sub_le_tsum_of_cauchy_snorm' hf hp1 h_cau,
have h2 : ∀ n, ∫⁻ a, (∑ i in finset.range (n + 1), nnnorm (f (i + 1) a - f i a) : ℝ≥0∞)^p ∂μ
≤ (∑' i, B i) ^ p,
from λ n, lintegral_rpow_sum_coe_nnnorm_sub_le_rpow_tsum hf hp1 n (h1 n),
have h3 : (∫⁻ a, (∑' i, nnnorm (f (i + 1) a - f i a) : ℝ≥0∞)^p ∂μ) ^ (1/p) ≤ ∑' i, B i,
from lintegral_rpow_tsum_coe_nnnorm_sub_le_tsum hf hp1 h2,
have h4 : ∀ᵐ x ∂μ, (∑' i, nnnorm (f (i + 1) x - f i x) : ℝ≥0∞) < ∞,
from tsum_nnnorm_sub_ae_lt_top hf hp1 hB h3,
exact h4.mono (λ x hx, summable_of_summable_nnnorm
(ennreal.tsum_coe_ne_top_iff_summable.mp (lt_top_iff_ne_top.mp hx))), },
have h : ∀ᵐ x ∂μ, ∃ l : E,
at_top.tendsto (λ n, ∑ i in finset.range n, (f (i + 1) x - f i x)) (𝓝 l),
{ refine h_summable.mono (λ x hx, _),
let hx_sum := hx.has_sum.tendsto_sum_nat,
exact ⟨∑' i, (f (i + 1) x - f i x), hx_sum⟩, },
refine h.mono (λ x hx, _),
cases hx with l hx,
have h_rw_sum : (λ n, ∑ i in finset.range n, (f (i + 1) x - f i x)) = λ n, f n x - f 0 x,
{ ext1 n,
change ∑ (i : ℕ) in finset.range n, ((λ m, f m x) (i + 1) - (λ m, f m x) i) = f n x - f 0 x,
rw finset.sum_range_sub, },
rw h_rw_sum at hx,
have hf_rw : (λ n, f n x) = λ n, f n x - f 0 x + f 0 x, by { ext1 n, abel, },
rw hf_rw,
exact ⟨l + f 0 x, tendsto.add_const _ hx⟩,
end
lemma ae_tendsto_of_cauchy_snorm [complete_space E] {f : ℕ → α → E}
(hf : ∀ n, ae_measurable (f n) μ) (hp : 1 ≤ p) {B : ℕ → ℝ≥0∞} (hB : ∑' i, B i < ∞)
(h_cau : ∀ (N n m : ℕ), N ≤ n → N ≤ m → snorm (f n - f m) p μ < B N) :
∀ᵐ x ∂μ, ∃ l : E, at_top.tendsto (λ n, f n x) (𝓝 l) :=
begin
by_cases hp_top : p = ∞,
{ simp_rw [hp_top] at *,
have h_cau_ae : ∀ᵐ x ∂μ, ∀ N n m, N ≤ n → N ≤ m → (nnnorm ((f n - f m) x) : ℝ≥0∞) < B N,
{ simp_rw [ae_all_iff, ae_imp_iff],
exact λ N n m hnN hmN, ae_lt_of_ess_sup_lt (h_cau N n m hnN hmN), },
simp_rw [snorm_exponent_top, snorm_ess_sup] at h_cau,
refine h_cau_ae.mono (λ x hx, cauchy_seq_tendsto_of_complete _),
refine cauchy_seq_of_le_tendsto_0 (λ n, (B n).to_real) _ _,
{ intros n m N hnN hmN,
specialize hx N n m hnN hmN,
rw [dist_eq_norm, ←ennreal.to_real_of_real (norm_nonneg _),
ennreal.to_real_le_to_real ennreal.of_real_ne_top
((ennreal.ne_top_of_tsum_ne_top (lt_top_iff_ne_top.mp hB)) N)],
rw ←of_real_norm_eq_coe_nnnorm at hx,
exact hx.le, },
{ rw ← ennreal.zero_to_real,
exact tendsto.comp (ennreal.tendsto_to_real ennreal.zero_ne_top)
(ennreal.tendsto_at_top_zero_of_tsum_lt_top hB), }, },
have hp1 : 1 ≤ p.to_real,
{ rw [← ennreal.of_real_le_iff_le_to_real hp_top, ennreal.of_real_one],
exact hp, },
have h_cau' : ∀ (N n m : ℕ), N ≤ n → N ≤ m → snorm' (f n - f m) (p.to_real) μ < B N,
{ intros N n m hn hm,
specialize h_cau N n m hn hm,
rwa snorm_eq_snorm' (ennreal.zero_lt_one.trans_le hp).ne.symm hp_top at h_cau, },
exact ae_tendsto_of_cauchy_snorm' hf hp1 hB h_cau',
end
lemma cauchy_tendsto_of_tendsto {f : ℕ → α → E} (hf : ∀ n, ae_measurable (f n) μ)
(f_lim : α → E) {B : ℕ → ℝ≥0∞}
(hB : ∑' i, B i < ∞) (h_cau : ∀ (N n m : ℕ), N ≤ n → N ≤ m → snorm (f n - f m) p μ < B N)
(h_lim : ∀ᵐ (x : α) ∂μ, tendsto (λ n, f n x) at_top (𝓝 (f_lim x))) :
at_top.tendsto (λ n, snorm (f n - f_lim) p μ) (𝓝 0) :=
begin
rw ennreal.tendsto_at_top_zero,
intros ε hε,
have h_B : ∃ (N : ℕ), B N ≤ ε,
{ suffices h_tendsto_zero : ∃ (N : ℕ), ∀ n : ℕ, N ≤ n → B n ≤ ε,
from ⟨h_tendsto_zero.some, h_tendsto_zero.some_spec _ (le_refl _)⟩,
exact (ennreal.tendsto_at_top_zero.mp (ennreal.tendsto_at_top_zero_of_tsum_lt_top hB))
ε hε, },
cases h_B with N h_B,
refine ⟨N, λ n hn, _⟩,
have h_sub : snorm (f n - f_lim) p μ ≤ at_top.liminf (λ m, snorm (f n - f m) p μ),
{ refine snorm_lim_le_liminf_snorm (λ m, (hf n).sub (hf m)) (f n - f_lim) _,
refine h_lim.mono (λ x hx, _),
simp_rw sub_eq_add_neg,
exact tendsto.add tendsto_const_nhds (tendsto.neg hx), },
refine h_sub.trans _,
refine liminf_le_of_frequently_le' (frequently_at_top.mpr _),
refine λ N1, ⟨max N N1, le_max_right _ _, _⟩,
exact (h_cau N n (max N N1) hn (le_max_left _ _)).le.trans h_B,
end
lemma mem_ℒp_of_cauchy_tendsto (hp : 1 ≤ p) {f : ℕ → α → E} (hf : ∀ n, mem_ℒp (f n) p μ)
(f_lim : α → E) (h_lim_meas : ae_measurable f_lim μ)
(h_tendsto : at_top.tendsto (λ n, snorm (f n - f_lim) p μ) (𝓝 0)) :
mem_ℒp f_lim p μ :=
begin
refine ⟨h_lim_meas, _⟩,
rw ennreal.tendsto_at_top_zero at h_tendsto,
cases (h_tendsto 1 ennreal.zero_lt_one) with N h_tendsto_1,
specialize h_tendsto_1 N (le_refl N),
have h_add : f_lim = f_lim - f N + f N, by abel,
rw h_add,
refine lt_of_le_of_lt (snorm_add_le (h_lim_meas.sub (hf N).1) (hf N).1 hp) _,
rw ennreal.add_lt_top,
split,
{ refine lt_of_le_of_lt _ ennreal.one_lt_top,
have h_neg : f_lim - f N = -(f N - f_lim), by simp,
rwa [h_neg, snorm_neg], },
{ exact (hf N).2, },
end
lemma cauchy_complete_ℒp [complete_space E] (hp : 1 ≤ p)
{f : ℕ → α → E} (hf : ∀ n, mem_ℒp (f n) p μ) {B : ℕ → ℝ≥0∞} (hB : ∑' i, B i < ∞)
(h_cau : ∀ (N n m : ℕ), N ≤ n → N ≤ m → snorm (f n - f m) p μ < B N) :
∃ (f_lim : α → E) (hf_lim_meas : mem_ℒp f_lim p μ),
at_top.tendsto (λ n, snorm (f n - f_lim) p μ) (𝓝 0) :=
begin
obtain ⟨f_lim, h_f_lim_meas, h_lim⟩ : ∃ (f_lim : α → E) (hf_lim_meas : measurable f_lim),
∀ᵐ x ∂μ, tendsto (λ n, f n x) at_top (nhds (f_lim x)),
from measurable_limit_of_tendsto_metric_ae (λ n, (hf n).1)
(ae_tendsto_of_cauchy_snorm (λ n, (hf n).1) hp hB h_cau),
have h_tendsto' : at_top.tendsto (λ n, snorm (f n - f_lim) p μ) (𝓝 0),
from cauchy_tendsto_of_tendsto (λ m, (hf m).1) f_lim hB h_cau h_lim,
have h_ℒp_lim : mem_ℒp f_lim p μ,
from mem_ℒp_of_cauchy_tendsto hp hf f_lim h_f_lim_meas.ae_measurable h_tendsto',
exact ⟨f_lim, h_ℒp_lim, h_tendsto'⟩,
end
/-! ### `Lp` is complete for `1 ≤ p` -/
instance [complete_space E] [hp : fact (1 ≤ p)] : complete_space (Lp E p μ) :=
complete_space_Lp_of_cauchy_complete_ℒp (λ f hf B hB h_cau, cauchy_complete_ℒp hp.elim hf hB h_cau)
end Lp
end measure_theory
end complete_space
/-! ### Continuous functions in `Lp` -/
open_locale bounded_continuous_function
open bounded_continuous_function
variables [borel_space E] [second_countable_topology E] [topological_space α] [borel_space α]
variables (E p μ)
/-- An additive subgroup of `Lp E p μ`, consisting of the equivalence classes which contain a
bounded continuous representative. -/
def measure_theory.Lp.bounded_continuous_function : add_subgroup (Lp E p μ) :=
add_subgroup.add_subgroup_of
((continuous_map.to_ae_eq_fun_add_hom μ).comp (forget_boundedness_add_hom α E)).range
(Lp E p μ)
variables {E p μ}
/-- By definition, the elements of `Lp.bounded_continuous_function E p μ` are the elements of
`Lp E p μ` which contain a bounded continuous representative. -/
lemma measure_theory.Lp.mem_bounded_continuous_function_iff {f : (Lp E p μ)} :
f ∈ measure_theory.Lp.bounded_continuous_function E p μ
↔ ∃ f₀ : (α →ᵇ E), f₀.to_continuous_map.to_ae_eq_fun μ = (f : α →ₘ[μ] E) :=
add_subgroup.mem_add_subgroup_of
namespace bounded_continuous_function
variables [is_finite_measure μ]
/-- A bounded continuous function on a finite-measure space is in `Lp`. -/
lemma mem_Lp (f : α →ᵇ E) :
f.to_continuous_map.to_ae_eq_fun μ ∈ Lp E p μ :=
begin
refine Lp.mem_Lp_of_ae_bound (∥f∥) _,
filter_upwards [f.to_continuous_map.coe_fn_to_ae_eq_fun μ],
intros x hx,
convert f.norm_coe_le_norm x
end
/-- The `Lp`-norm of a bounded continuous function is at most a constant (depending on the measure
of the whole space) times its sup-norm. -/
lemma Lp_norm_le (f : α →ᵇ E) :
∥(⟨f.to_continuous_map.to_ae_eq_fun μ, mem_Lp f⟩ : Lp E p μ)∥
≤ (measure_univ_nnreal μ) ^ (p.to_real)⁻¹ * ∥f∥ :=
begin
apply Lp.norm_le_of_ae_bound (norm_nonneg f),
{ refine (f.to_continuous_map.coe_fn_to_ae_eq_fun μ).mono _,
intros x hx,
convert f.norm_coe_le_norm x },
{ apply_instance }
end
variables (p μ)
/-- The normed group homomorphism of considering a bounded continuous function on a finite-measure
space as an element of `Lp`. -/
def to_Lp_hom [fact (1 ≤ p)] : normed_group_hom (α →ᵇ E) (Lp E p μ) :=
{ bound' := ⟨_, Lp_norm_le⟩,
.. add_monoid_hom.cod_restrict
((continuous_map.to_ae_eq_fun_add_hom μ).comp (forget_boundedness_add_hom α E))
(Lp E p μ)
mem_Lp }
lemma range_to_Lp_hom [fact (1 ≤ p)] :
((to_Lp_hom p μ).range : add_subgroup (Lp E p μ))
= measure_theory.Lp.bounded_continuous_function E p μ :=
begin
symmetry,
convert add_monoid_hom.add_subgroup_of_range_eq_of_le
((continuous_map.to_ae_eq_fun_add_hom μ).comp (forget_boundedness_add_hom α E))
(by { rintros - ⟨f, rfl⟩, exact mem_Lp f } : _ ≤ Lp E p μ),
end
variables (𝕜 : Type*) [measurable_space 𝕜]
/-- The bounded linear map of considering a bounded continuous function on a finite-measure space
as an element of `Lp`. -/
def to_Lp [normed_field 𝕜] [opens_measurable_space 𝕜] [normed_space 𝕜 E] [fact (1 ≤ p)] :
(α →ᵇ E) →L[𝕜] (Lp E p μ) :=
linear_map.mk_continuous
(linear_map.cod_restrict
(Lp.Lp_submodule E p μ 𝕜)
((continuous_map.to_ae_eq_fun_linear_map μ).comp (forget_boundedness_linear_map α E 𝕜))
mem_Lp)
_
Lp_norm_le
variables {𝕜}
lemma range_to_Lp [normed_field 𝕜] [opens_measurable_space 𝕜] [normed_space 𝕜 E] [fact (1 ≤ p)] :
((to_Lp p μ 𝕜).range.to_add_subgroup : add_subgroup (Lp E p μ))
= measure_theory.Lp.bounded_continuous_function E p μ :=
range_to_Lp_hom p μ
variables {p}
lemma coe_fn_to_Lp [normed_field 𝕜] [opens_measurable_space 𝕜] [normed_space 𝕜 E] [fact (1 ≤ p)]
(f : α →ᵇ E) :
to_Lp p μ 𝕜 f =ᵐ[μ] f :=
ae_eq_fun.coe_fn_mk f _
lemma to_Lp_norm_le [nondiscrete_normed_field 𝕜] [opens_measurable_space 𝕜] [normed_space 𝕜 E]
[fact (1 ≤ p)] :
∥(to_Lp p μ 𝕜 : (α →ᵇ E) →L[𝕜] (Lp E p μ))∥ ≤ (measure_univ_nnreal μ) ^ (p.to_real)⁻¹ :=
linear_map.mk_continuous_norm_le _ ((measure_univ_nnreal μ) ^ (p.to_real)⁻¹).coe_nonneg _
end bounded_continuous_function
namespace continuous_map
variables [compact_space α] [is_finite_measure μ]
variables (𝕜 : Type*) [measurable_space 𝕜] (p μ) [fact (1 ≤ p)]
/-- The bounded linear map of considering a continuous function on a compact finite-measure
space `α` as an element of `Lp`. By definition, the norm on `C(α, E)` is the sup-norm, transferred
from the space `α →ᵇ E` of bounded continuous functions, so this construction is just a matter of
transferring the structure from `bounded_continuous_function.to_Lp` along the isometry. -/
def to_Lp [normed_field 𝕜] [opens_measurable_space 𝕜] [normed_space 𝕜 E] :
C(α, E) →L[𝕜] (Lp E p μ) :=
(bounded_continuous_function.to_Lp p μ 𝕜).comp
(linear_isometry_bounded_of_compact α E 𝕜).to_linear_isometry.to_continuous_linear_map
variables {𝕜}
lemma range_to_Lp [normed_field 𝕜] [opens_measurable_space 𝕜] [normed_space 𝕜 E] :
((to_Lp p μ 𝕜).range.to_add_subgroup : add_subgroup (Lp E p μ))
= measure_theory.Lp.bounded_continuous_function E p μ :=
begin
refine set_like.ext' _,
have := (linear_isometry_bounded_of_compact α E 𝕜).surjective,
convert function.surjective.range_comp this (bounded_continuous_function.to_Lp p μ 𝕜),
rw ← bounded_continuous_function.range_to_Lp p μ,
refl,
end
variables {p}
lemma coe_fn_to_Lp [normed_field 𝕜] [opens_measurable_space 𝕜] [normed_space 𝕜 E] (f : C(α, E)) :
to_Lp p μ 𝕜 f =ᵐ[μ] f :=
ae_eq_fun.coe_fn_mk f _
lemma to_Lp_def [normed_field 𝕜] [opens_measurable_space 𝕜] [normed_space 𝕜 E] (f : C(α, E)) :
to_Lp p μ 𝕜 f
= bounded_continuous_function.to_Lp p μ 𝕜 (linear_isometry_bounded_of_compact α E 𝕜 f) :=
rfl
@[simp] lemma to_Lp_comp_forget_boundedness [normed_field 𝕜] [opens_measurable_space 𝕜]
[normed_space 𝕜 E] (f : α →ᵇ E) :
to_Lp p μ 𝕜 (bounded_continuous_function.forget_boundedness α E f)
= bounded_continuous_function.to_Lp p μ 𝕜 f :=
rfl
@[simp] lemma coe_to_Lp [normed_field 𝕜] [opens_measurable_space 𝕜] [normed_space 𝕜 E]
(f : C(α, E)) :
(to_Lp p μ 𝕜 f : α →ₘ[μ] E) = f.to_ae_eq_fun μ :=
rfl
variables [nondiscrete_normed_field 𝕜] [opens_measurable_space 𝕜] [normed_space 𝕜 E]
lemma to_Lp_norm_eq_to_Lp_norm_coe :
∥(to_Lp p μ 𝕜 : C(α, E) →L[𝕜] (Lp E p μ))∥
= ∥(bounded_continuous_function.to_Lp p μ 𝕜 : (α →ᵇ E) →L[𝕜] (Lp E p μ))∥ :=
continuous_linear_map.op_norm_comp_linear_isometry_equiv _ _
/-- Bound for the operator norm of `continuous_map.to_Lp`. -/
lemma to_Lp_norm_le :
∥(to_Lp p μ 𝕜 : C(α, E) →L[𝕜] (Lp E p μ))∥ ≤ (measure_univ_nnreal μ) ^ (p.to_real)⁻¹ :=
by { rw to_Lp_norm_eq_to_Lp_norm_coe, exact bounded_continuous_function.to_Lp_norm_le μ }
end continuous_map
--(to_Lp p μ 𝕜 : (α →ᵇ E) →L[𝕜] (Lp E p μ))
|
1536cf72edf0faa5f28cb8f6bbee224a28fd3afe | d406927ab5617694ec9ea7001f101b7c9e3d9702 | /src/linear_algebra/clifford_algebra/basic.lean | f6828941f36584c129a2b1d02e998d7e0ddeff1c | [
"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 | 13,673 | lean | /-
Copyright (c) 2020 Eric Wieser. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Wieser, Utensil Song
-/
import algebra.ring_quot
import linear_algebra.tensor_algebra.basic
import linear_algebra.quadratic_form.isometry
/-!
# Clifford Algebras
We construct the Clifford algebra of a module `M` over a commutative ring `R`, equipped with
a quadratic_form `Q`.
## Notation
The Clifford algebra of the `R`-module `M` equipped with a quadratic_form `Q` is
an `R`-algebra denoted `clifford_algebra Q`.
Given a linear morphism `f : M → A` from a module `M` to another `R`-algebra `A`, such that
`cond : ∀ m, f m * f m = algebra_map _ _ (Q m)`, there is a (unique) lift of `f` to an `R`-algebra
morphism from `clifford_algebra Q` to `A`, which is denoted `clifford_algebra.lift Q f cond`.
The canonical linear map `M → clifford_algebra Q` is denoted `clifford_algebra.ι Q`.
## Theorems
The main theorems proved ensure that `clifford_algebra Q` satisfies the universal property
of the Clifford algebra.
1. `ι_comp_lift` is the fact that the composition of `ι Q` with `lift Q f cond` agrees with `f`.
2. `lift_unique` ensures the uniqueness of `lift Q f cond` with respect to 1.
Additionally, when `Q = 0` an `alg_equiv` to the `exterior_algebra` is provided as `as_exterior`.
## Implementation details
The Clifford algebra of `M` is constructed as a quotient of the tensor algebra, as follows.
1. We define a relation `clifford_algebra.rel Q` on `tensor_algebra R M`.
This is the smallest relation which identifies squares of elements of `M` with `Q m`.
2. The Clifford algebra is the quotient of the tensor algebra by this relation.
This file is almost identical to `linear_algebra/exterior_algebra.lean`.
-/
variables {R : Type*} [comm_ring R]
variables {M : Type*} [add_comm_group M] [module R M]
variables (Q : quadratic_form R M)
variable {n : ℕ}
namespace clifford_algebra
open tensor_algebra
/-- `rel` relates each `ι m * ι m`, for `m : M`, with `Q m`.
The Clifford algebra of `M` is defined as the quotient modulo this relation.
-/
inductive rel : tensor_algebra R M → tensor_algebra R M → Prop
| of (m : M) : rel (ι R m * ι R m) (algebra_map R _ (Q m))
end clifford_algebra
/--
The Clifford algebra of an `R`-module `M` equipped with a quadratic_form `Q`.
-/
@[derive [inhabited, ring, algebra R]]
def clifford_algebra := ring_quot (clifford_algebra.rel Q)
namespace clifford_algebra
/--
The canonical linear map `M →ₗ[R] clifford_algebra Q`.
-/
def ι : M →ₗ[R] clifford_algebra Q :=
(ring_quot.mk_alg_hom R _).to_linear_map.comp (tensor_algebra.ι R)
/-- As well as being linear, `ι Q` squares to the quadratic form -/
@[simp]
theorem ι_sq_scalar (m : M) : ι Q m * ι Q m = algebra_map R _ (Q m) :=
begin
erw [←alg_hom.map_mul, ring_quot.mk_alg_hom_rel R (rel.of m), alg_hom.commutes],
refl,
end
variables {Q} {A : Type*} [semiring A] [algebra R A]
@[simp]
theorem comp_ι_sq_scalar (g : clifford_algebra Q →ₐ[R] A) (m : M) :
g (ι Q m) * g (ι Q m) = algebra_map _ _ (Q m) :=
by rw [←alg_hom.map_mul, ι_sq_scalar, alg_hom.commutes]
variables (Q)
/--
Given a linear map `f : M →ₗ[R] A` into an `R`-algebra `A`, which satisfies the condition:
`cond : ∀ m : M, f m * f m = Q(m)`, this is the canonical lift of `f` to a morphism of `R`-algebras
from `clifford_algebra Q` to `A`.
-/
@[simps symm_apply]
def lift :
{f : M →ₗ[R] A // ∀ m, f m * f m = algebra_map _ _ (Q m)} ≃ (clifford_algebra Q →ₐ[R] A) :=
{ to_fun := λ f,
ring_quot.lift_alg_hom R ⟨tensor_algebra.lift R (f : M →ₗ[R] A),
(λ x y (h : rel Q x y), by
{ induction h,
rw [alg_hom.commutes, alg_hom.map_mul, tensor_algebra.lift_ι_apply, f.prop], })⟩,
inv_fun := λ F, ⟨F.to_linear_map.comp (ι Q), λ m, by rw [
linear_map.comp_apply, alg_hom.to_linear_map_apply, comp_ι_sq_scalar]⟩,
left_inv := λ f, by { ext,
simp only [ι, alg_hom.to_linear_map_apply, function.comp_app, linear_map.coe_comp,
subtype.coe_mk, ring_quot.lift_alg_hom_mk_alg_hom_apply,
tensor_algebra.lift_ι_apply] },
right_inv := λ F, by { ext,
simp only [ι, alg_hom.comp_to_linear_map, alg_hom.to_linear_map_apply, function.comp_app,
linear_map.coe_comp, subtype.coe_mk, ring_quot.lift_alg_hom_mk_alg_hom_apply,
tensor_algebra.lift_ι_apply] } }
variables {Q}
@[simp]
theorem ι_comp_lift (f : M →ₗ[R] A) (cond : ∀ m, f m * f m = algebra_map _ _ (Q m)) :
(lift Q ⟨f, cond⟩).to_linear_map.comp (ι Q) = f :=
(subtype.mk_eq_mk.mp $ (lift Q).symm_apply_apply ⟨f, cond⟩)
@[simp]
theorem lift_ι_apply (f : M →ₗ[R] A) (cond : ∀ m, f m * f m = algebra_map _ _ (Q m)) (x) :
lift Q ⟨f, cond⟩ (ι Q x) = f x :=
(linear_map.ext_iff.mp $ ι_comp_lift f cond) x
@[simp]
theorem lift_unique (f : M →ₗ[R] A) (cond : ∀ m : M, f m * f m = algebra_map _ _ (Q m))
(g : clifford_algebra Q →ₐ[R] A) :
g.to_linear_map.comp (ι Q) = f ↔ g = lift Q ⟨f, cond⟩ :=
begin
convert (lift Q).symm_apply_eq,
rw lift_symm_apply,
simp only,
end
attribute [irreducible] clifford_algebra ι lift
@[simp]
theorem lift_comp_ι (g : clifford_algebra Q →ₐ[R] A) :
lift Q ⟨g.to_linear_map.comp (ι Q), comp_ι_sq_scalar _⟩ = g :=
begin
convert (lift Q).apply_symm_apply g,
rw lift_symm_apply,
refl,
end
/-- See note [partially-applied ext lemmas]. -/
@[ext]
theorem hom_ext {A : Type*} [semiring A] [algebra R A] {f g : clifford_algebra Q →ₐ[R] A} :
f.to_linear_map.comp (ι Q) = g.to_linear_map.comp (ι Q) → f = g :=
begin
intro h,
apply (lift Q).symm.injective,
rw [lift_symm_apply, lift_symm_apply],
simp only [h],
end
/-- If `C` holds for the `algebra_map` of `r : R` into `clifford_algebra Q`, the `ι` of `x : M`,
and is preserved under addition and muliplication, then it holds for all of `clifford_algebra Q`.
See also the stronger `clifford_algebra.left_induction` and `clifford_algebra.right_induction`.
-/
-- This proof closely follows `tensor_algebra.induction`
@[elab_as_eliminator]
lemma induction {C : clifford_algebra Q → Prop}
(h_grade0 : ∀ r, C (algebra_map R (clifford_algebra Q) r))
(h_grade1 : ∀ x, C (ι Q x))
(h_mul : ∀ a b, C a → C b → C (a * b))
(h_add : ∀ a b, C a → C b → C (a + b))
(a : clifford_algebra Q) :
C a :=
begin
-- the arguments are enough to construct a subalgebra, and a mapping into it from M
let s : subalgebra R (clifford_algebra Q) :=
{ carrier := C,
mul_mem' := h_mul,
add_mem' := h_add,
algebra_map_mem' := h_grade0, },
let of : { f : M →ₗ[R] s // ∀ m, f m * f m = algebra_map _ _ (Q m) } :=
⟨(ι Q).cod_restrict s.to_submodule h_grade1,
λ m, subtype.eq $ ι_sq_scalar Q m ⟩,
-- the mapping through the subalgebra is the identity
have of_id : alg_hom.id R (clifford_algebra Q) = s.val.comp (lift Q of),
{ ext,
simp [of], },
-- finding a proof is finding an element of the subalgebra
convert subtype.prop (lift Q of a),
exact alg_hom.congr_fun of_id a,
end
/-- The symmetric product of vectors is a scalar -/
lemma ι_mul_ι_add_swap (a b : M) :
ι Q a * ι Q b + ι Q b * ι Q a = algebra_map R _ (quadratic_form.polar Q a b) :=
calc ι Q a * ι Q b + ι Q b * ι Q a
= ι Q (a + b) * ι Q (a + b) - ι Q a * ι Q a - ι Q b * ι Q b :
by { rw [(ι Q).map_add, mul_add, add_mul, add_mul], abel, }
... = algebra_map R _ (Q (a + b)) - algebra_map R _ (Q a) - algebra_map R _ (Q b) :
by rw [ι_sq_scalar, ι_sq_scalar, ι_sq_scalar]
... = algebra_map R _ (Q (a + b) - Q a - Q b) :
by rw [←ring_hom.map_sub, ←ring_hom.map_sub]
... = algebra_map R _ (quadratic_form.polar Q a b) : rfl
lemma ι_mul_comm (a b : M) :
ι Q a * ι Q b = algebra_map R _ (quadratic_form.polar Q a b) - ι Q b * ι Q a :=
eq_sub_of_add_eq (ι_mul_ι_add_swap a b)
/-- $aba$ is a vector. -/
lemma ι_mul_ι_mul_ι (a b : M) :
ι Q a * ι Q b * ι Q a = ι Q (quadratic_form.polar Q a b • a - Q a • b) :=
by rw [ι_mul_comm, sub_mul, mul_assoc, ι_sq_scalar, ←algebra.smul_def, ←algebra.commutes,
←algebra.smul_def, ←map_smul, ←map_smul, ←map_sub]
@[simp]
lemma ι_range_map_lift (f : M →ₗ[R] A) (cond : ∀ m, f m * f m = algebra_map _ _ (Q m)) :
(ι Q).range.map (lift Q ⟨f, cond⟩).to_linear_map = f.range :=
by rw [←linear_map.range_comp, ι_comp_lift]
section map
variables {M₁ M₂ M₃ : Type*}
variables [add_comm_group M₁] [add_comm_group M₂] [add_comm_group M₃]
variables [module R M₁] [module R M₂] [module R M₃]
variables (Q₁ : quadratic_form R M₁) (Q₂ : quadratic_form R M₂) (Q₃ : quadratic_form R M₃)
/-- Any linear map that preserves the quadratic form lifts to an `alg_hom` between algebras.
See `clifford_algebra.equiv_of_isometry` for the case when `f` is a `quadratic_form.isometry`. -/
def map (f : M₁ →ₗ[R] M₂) (hf : ∀ m, Q₂ (f m) = Q₁ m) :
clifford_algebra Q₁ →ₐ[R] clifford_algebra Q₂ :=
clifford_algebra.lift Q₁ ⟨(clifford_algebra.ι Q₂).comp f,
λ m, (ι_sq_scalar _ _).trans $ ring_hom.congr_arg _ $ hf m⟩
@[simp]
lemma map_comp_ι (f : M₁ →ₗ[R] M₂) (hf) :
(map Q₁ Q₂ f hf).to_linear_map.comp (ι Q₁) = (ι Q₂).comp f :=
ι_comp_lift _ _
@[simp]
lemma map_apply_ι (f : M₁ →ₗ[R] M₂) (hf) (m : M₁):
map Q₁ Q₂ f hf (ι Q₁ m) = ι Q₂ (f m) :=
lift_ι_apply _ _ m
@[simp]
lemma map_id :
map Q₁ Q₁ (linear_map.id : M₁ →ₗ[R] M₁) (λ m, rfl) = alg_hom.id R (clifford_algebra Q₁) :=
by { ext m, exact map_apply_ι _ _ _ _ m }
@[simp]
lemma map_comp_map (f : M₂ →ₗ[R] M₃) (hf) (g : M₁ →ₗ[R] M₂) (hg) :
(map Q₂ Q₃ f hf).comp (map Q₁ Q₂ g hg) = map Q₁ Q₃ (f.comp g) (λ m, (hf _).trans $ hg m) :=
begin
ext m,
dsimp only [linear_map.comp_apply, alg_hom.comp_apply, alg_hom.to_linear_map_apply,
alg_hom.id_apply],
rw [map_apply_ι, map_apply_ι, map_apply_ι, linear_map.comp_apply],
end
@[simp]
lemma ι_range_map_map (f : M₁ →ₗ[R] M₂) (hf : ∀ m, Q₂ (f m) = Q₁ m) :
(ι Q₁).range.map (map Q₁ Q₂ f hf).to_linear_map = f.range.map (ι Q₂) :=
(ι_range_map_lift _ _).trans (linear_map.range_comp _ _)
variables {Q₁ Q₂ Q₃}
/-- Two `clifford_algebra`s are equivalent as algebras if their quadratic forms are
equivalent. -/
@[simps apply]
def equiv_of_isometry (e : Q₁.isometry Q₂) :
clifford_algebra Q₁ ≃ₐ[R] clifford_algebra Q₂ :=
alg_equiv.of_alg_hom
(map Q₁ Q₂ e e.map_app)
(map Q₂ Q₁ e.symm e.symm.map_app)
((map_comp_map _ _ _ _ _ _ _).trans $ begin
convert map_id _ using 2,
ext m,
exact e.to_linear_equiv.apply_symm_apply m,
end)
((map_comp_map _ _ _ _ _ _ _).trans $ begin
convert map_id _ using 2,
ext m,
exact e.to_linear_equiv.symm_apply_apply m,
end)
@[simp]
lemma equiv_of_isometry_symm (e : Q₁.isometry Q₂) :
(equiv_of_isometry e).symm = equiv_of_isometry e.symm := rfl
@[simp]
lemma equiv_of_isometry_trans (e₁₂ : Q₁.isometry Q₂) (e₂₃ : Q₂.isometry Q₃) :
(equiv_of_isometry e₁₂).trans (equiv_of_isometry e₂₃) = equiv_of_isometry (e₁₂.trans e₂₃) :=
by { ext x, exact alg_hom.congr_fun (map_comp_map Q₁ Q₂ Q₃ _ _ _ _) x }
@[simp]
lemma equiv_of_isometry_refl :
(equiv_of_isometry $ quadratic_form.isometry.refl Q₁) = alg_equiv.refl :=
by { ext x, exact alg_hom.congr_fun (map_id Q₁) x }
end map
variables (Q)
/-- If the quadratic form of a vector is invertible, then so is that vector. -/
def invertible_ι_of_invertible (m : M) [invertible (Q m)] : invertible (ι Q m) :=
{ inv_of := ι Q (⅟(Q m) • m),
inv_of_mul_self := by rw [map_smul, smul_mul_assoc, ι_sq_scalar, algebra.smul_def, ←map_mul,
inv_of_mul_self, map_one],
mul_inv_of_self := by rw [map_smul, mul_smul_comm, ι_sq_scalar, algebra.smul_def, ←map_mul,
inv_of_mul_self, map_one] }
/-- For a vector with invertible quadratic form, $v^{-1} = \frac{v}{Q(v)}$ -/
lemma inv_of_ι (m : M) [invertible (Q m)] [invertible (ι Q m)] : ⅟(ι Q m) = ι Q (⅟(Q m) • m) :=
begin
letI := invertible_ι_of_invertible Q m,
convert (rfl : ⅟(ι Q m) = _),
end
lemma is_unit_ι_of_is_unit {m : M} (h : is_unit (Q m)) : is_unit (ι Q m) :=
begin
casesI h.nonempty_invertible,
letI := invertible_ι_of_invertible Q m,
exactI is_unit_of_invertible (ι Q m),
end
/-- $aba^{-1}$ is a vector. -/
lemma ι_mul_ι_mul_inv_of_ι (a b : M) [invertible (ι Q a)] [invertible (Q a)] :
ι Q a * ι Q b * ⅟(ι Q a) = ι Q ((⅟(Q a) * quadratic_form.polar Q a b) • a - b) :=
by rw [inv_of_ι, map_smul, mul_smul_comm, ι_mul_ι_mul_ι, ←map_smul, smul_sub, smul_smul, smul_smul,
inv_of_mul_self, one_smul]
/-- $a^{-1}ba$ is a vector. -/
lemma inv_of_ι_mul_ι_mul_ι (a b : M) [invertible (ι Q a)] [invertible (Q a)] :
⅟(ι Q a) * ι Q b * ι Q a = ι Q ((⅟(Q a) * quadratic_form.polar Q a b) • a - b) :=
by rw [inv_of_ι, map_smul, smul_mul_assoc, smul_mul_assoc, ι_mul_ι_mul_ι, ←map_smul, smul_sub,
smul_smul, smul_smul, inv_of_mul_self, one_smul]
end clifford_algebra
namespace tensor_algebra
variables {Q}
/-- The canonical image of the `tensor_algebra` in the `clifford_algebra`, which maps
`tensor_algebra.ι R x` to `clifford_algebra.ι Q x`. -/
def to_clifford : tensor_algebra R M →ₐ[R] clifford_algebra Q :=
tensor_algebra.lift R (clifford_algebra.ι Q)
@[simp] lemma to_clifford_ι (m : M) : (tensor_algebra.ι R m).to_clifford = clifford_algebra.ι Q m :=
by simp [to_clifford]
end tensor_algebra
|
74f8e39ee651d73fdc8b9fb4e06a0210c6640d6e | cf39355caa609c0f33405126beee2739aa3cb77e | /tests/lean/run/add_interactive.lean | 5c1cfbea1d4ce5500cf2ea180f8089df2d375ae7 | [
"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 | 887 | lean | namespace foo
namespace bla
open lean.parser interactive interactive.types
/-- test doc string -/
meta def my_exact (q : parse texpr) :=
tactic.interactive.exact q
/- Copy tactic my_exact to tactic.interactive. -/
run_cmd add_interactive [`my_exact]
/- Copy tactic my_exact to test_namespace. -/
run_cmd add_interactive [`my_exact] `test_namespace
end bla
example : true :=
begin
my_exact trivial
end
open tactic
run_cmd do
old_doc ← doc_string `foo.bla.my_exact,
new_doc ← doc_string `tactic.interactive.my_exact,
if old_doc = new_doc then skip else fail "doc strings of foo.bla.my_exact and tactic.interactive.my_exact do not match"
run_cmd do
old_doc ← doc_string `foo.bla.my_exact,
new_doc ← doc_string `test_namespace.my_exact,
if old_doc = new_doc then skip else fail "doc strings of foo.bla.my_exact and test_namespace.my_exact do not match"
end foo
|
7f2637af90f474e0a7e9ec32b88587f83f9bb982 | 74addaa0e41490cbaf2abd313a764c96df57b05d | /Mathlib/data/pfunctor/univariate/default.lean | 15b81217b73933a0a47b9c169fc7e0020a74a2f8 | [] | 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 | 192 | lean | import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.data.pfunctor.univariate.basic
import Mathlib.data.pfunctor.univariate.M
import Mathlib.PostPort
namespace Mathlib
|
fe0faffbd71d4fb08905d1b826c320e94ff13492 | cf39355caa609c0f33405126beee2739aa3cb77e | /tests/lean/run/compiler_bug3.lean | 9187b46c15c02abe679759646f52c186e7db7611 | [
"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 | 290 | lean | inductive {u} tree (A : Type u) : Type u
| leaf : A -> tree
| node : list tree -> tree
def foo {A : Type*} : nat → tree A → nat
| 0 _ := 0
| (n+1) (tree.leaf a) := 0
| (n+1) (tree.node []) := foo n (tree.node [])
| (n+1) (tree.node (x::xs)) := foo n x
|
63bf91aa0c70b983da881c6ec64892f5175f61b8 | 6432ea7a083ff6ba21ea17af9ee47b9c371760f7 | /tests/pkg/misc/Misc/Foo.lean | 918d229608ce34f4c998d3807ddcaf336ac4a110 | [
"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 | 289 | lean | import Lean
open Lean Meta
#eval id (α := MetaM Unit) do
modifyEnv fun env => env.addExtraName `auxDecl1
return ()
def foo := 42
local infix:50 " ≺ " => LE.le
#check 1 ≺ 2
local macro "my_refl" : tactic =>
`(tactic| rfl)
def f (x y : Nat) (_h : x = y := by my_refl) := x
|
59e6c19b1e7b17909e22fbeedb61839de0c90bbc | 947b78d97130d56365ae2ec264df196ce769371a | /stage0/src/Lean/Meta/FunInfo.lean | 3245426cd45a776cdcff8aebeea7034673e2e233 | [
"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 | 3,196 | lean | /-
Copyright (c) 2019 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
import Lean.Meta.Basic
import Lean.Meta.InferType
namespace Lean
namespace Meta
@[inline] private def checkFunInfoCache (fn : Expr) (maxArgs? : Option Nat) (k : MetaM FunInfo) : MetaM FunInfo := do
s ← get;
t ← getTransparency;
match s.cache.funInfo.find? ⟨t, fn, maxArgs?⟩ with
| some finfo => pure finfo
| none => do
finfo ← k;
modify $ fun s => { s with cache := { s.cache with funInfo := s.cache.funInfo.insert ⟨t, fn, maxArgs?⟩ finfo } };
pure finfo
@[inline] private def whenHasVar {α} (e : Expr) (deps : α) (k : α → α) : α :=
if e.hasFVar then k deps else deps
private def collectDepsAux (fvars : Array Expr) : Expr → Array Nat → Array Nat
| e@(Expr.app f a _), deps => whenHasVar e deps (collectDepsAux a ∘ collectDepsAux f)
| e@(Expr.forallE _ d b _), deps => whenHasVar e deps (collectDepsAux b ∘ collectDepsAux d)
| e@(Expr.lam _ d b _), deps => whenHasVar e deps (collectDepsAux b ∘ collectDepsAux d)
| e@(Expr.letE _ t v b _), deps => whenHasVar e deps (collectDepsAux b ∘ collectDepsAux v ∘ collectDepsAux t)
| Expr.proj _ _ e _, deps => collectDepsAux e deps
| Expr.mdata _ e _, deps => collectDepsAux e deps
| e@(Expr.fvar _ _), deps =>
match fvars.indexOf? e with
| none => deps
| some i => if deps.contains i.val then deps else deps.push i.val
| _, deps => deps
private def collectDeps (fvars : Array Expr) (e : Expr) : Array Nat :=
let deps := collectDepsAux fvars e #[];
deps.qsort (fun i j => i < j)
/-- Update `hasFwdDeps` fields using new `backDeps` -/
private def updateHasFwdDeps (pinfo : Array ParamInfo) (backDeps : Array Nat) : Array ParamInfo :=
if backDeps.size == 0 then
pinfo
else
-- update hasFwdDeps fields
pinfo.mapIdx $ fun i info =>
if info.hasFwdDeps then info
else if backDeps.contains i then
{ info with hasFwdDeps := true }
else
info
private def getFunInfoAux (fn : Expr) (maxArgs? : Option Nat) : MetaM FunInfo :=
checkFunInfoCache fn maxArgs? $ do
fnType ← inferType fn;
withTransparency TransparencyMode.default $
forallBoundedTelescope fnType maxArgs? $ fun fvars type => do
pinfo ← fvars.size.foldM
(fun (i : Nat) (pinfo : Array ParamInfo) => do
let fvar := fvars.get! i;
decl ← getFVarLocalDecl fvar;
let backDeps := collectDeps fvars decl.type;
let pinfo := updateHasFwdDeps pinfo backDeps;
pure $ pinfo.push {
backDeps := backDeps,
implicit := decl.binderInfo == BinderInfo.implicit,
instImplicit := decl.binderInfo == BinderInfo.instImplicit })
#[];
let resultDeps := collectDeps fvars type;
let pinfo := updateHasFwdDeps pinfo resultDeps;
pure { resultDeps := resultDeps, paramInfo := pinfo }
def getFunInfo (fn : Expr) : MetaM FunInfo :=
getFunInfoAux fn none
def getFunInfoNArgs (fn : Expr) (nargs : Nat) : MetaM FunInfo :=
getFunInfoAux fn (some nargs)
end Meta
end Lean
|
5ec3a9ab682dbaf0aaa5b52230c1674583328012 | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/set_theory/ordinal/exponential.lean | 0b1e2723c625a97c19dea6b637aa0f88a4be04db | [
"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 | 16,569 | lean | /-
Copyright (c) 2017 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Floris van Doorn, Violeta Hernández Palacios
-/
import set_theory.ordinal.arithmetic
/-! # Ordinal exponential
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
In this file we define the power function and the logarithm function on ordinals. The two are
related by the lemma `ordinal.opow_le_iff_le_log : (b^c) ≤ x ↔ c ≤ log b x` for nontrivial inputs
`b`, `c`.
-/
noncomputable theory
open function cardinal set equiv order
open_locale classical cardinal ordinal
universes u v w
namespace ordinal
/-- The ordinal exponential, defined by transfinite recursion. -/
instance : has_pow ordinal ordinal :=
⟨λ a b, if a = 0 then 1 - b else limit_rec_on b 1 (λ _ IH, IH * a) (λ b _, bsup.{u u} b)⟩
local infixr (name := ordinal.pow) ^ := @pow ordinal ordinal ordinal.has_pow
theorem opow_def (a b : ordinal) :
a ^ b = if a = 0 then 1 - b else limit_rec_on b 1 (λ _ IH, IH * a) (λ b _, bsup.{u u} b) :=
rfl
theorem zero_opow' (a : ordinal) : 0 ^ a = 1 - a :=
by simp only [opow_def, if_pos rfl]
@[simp] theorem zero_opow {a : ordinal} (a0 : a ≠ 0) : 0 ^ a = 0 :=
by rwa [zero_opow', ordinal.sub_eq_zero_iff_le, one_le_iff_ne_zero]
@[simp] theorem opow_zero (a : ordinal) : a ^ 0 = 1 :=
by by_cases a = 0; [simp only [opow_def, if_pos h, sub_zero],
simp only [opow_def, if_neg h, limit_rec_on_zero]]
@[simp] theorem opow_succ (a b : ordinal) : a ^ succ b = a ^ b * a :=
if h : a = 0 then by subst a; simp only [zero_opow (succ_ne_zero _), mul_zero]
else by simp only [opow_def, limit_rec_on_succ, if_neg h]
theorem opow_limit {a b : ordinal} (a0 : a ≠ 0) (h : is_limit b) :
a ^ b = bsup.{u u} b (λ c _, a ^ c) :=
by simp only [opow_def, if_neg a0]; rw limit_rec_on_limit _ _ _ _ h; refl
theorem opow_le_of_limit {a b c : ordinal} (a0 : a ≠ 0) (h : is_limit b) :
a ^ b ≤ c ↔ ∀ b' < b, a ^ b' ≤ c :=
by rw [opow_limit a0 h, bsup_le_iff]
theorem lt_opow_of_limit {a b c : ordinal} (b0 : b ≠ 0) (h : is_limit c) :
a < b ^ c ↔ ∃ c' < c, a < b ^ c' :=
by rw [← not_iff_not, not_exists]; simp only [not_lt, opow_le_of_limit b0 h, exists_prop, not_and]
@[simp] theorem opow_one (a : ordinal) : a ^ 1 = a :=
by rw [← succ_zero, opow_succ]; simp only [opow_zero, one_mul]
@[simp] theorem one_opow (a : ordinal) : 1 ^ a = 1 :=
begin
apply limit_rec_on a,
{ simp only [opow_zero] },
{ intros _ ih, simp only [opow_succ, ih, mul_one] },
refine λ b l IH, eq_of_forall_ge_iff (λ c, _),
rw [opow_le_of_limit ordinal.one_ne_zero l],
exact ⟨λ H, by simpa only [opow_zero] using H 0 l.pos,
λ H b' h, by rwa IH _ h⟩,
end
theorem opow_pos {a : ordinal} (b)
(a0 : 0 < a) : 0 < a ^ b :=
begin
have h0 : 0 < a ^ 0, {simp only [opow_zero, zero_lt_one]},
apply limit_rec_on b,
{ exact h0 },
{ intros b IH, rw [opow_succ],
exact mul_pos IH a0 },
{ exact λ b l _, (lt_opow_of_limit (ordinal.pos_iff_ne_zero.1 a0) l).2
⟨0, l.pos, h0⟩ },
end
theorem opow_ne_zero {a : ordinal} (b)
(a0 : a ≠ 0) : a ^ b ≠ 0 :=
ordinal.pos_iff_ne_zero.1 $ opow_pos b $ ordinal.pos_iff_ne_zero.2 a0
theorem opow_is_normal {a : ordinal} (h : 1 < a) : is_normal ((^) a) :=
have a0 : 0 < a, from zero_lt_one.trans h,
⟨λ b, by simpa only [mul_one, opow_succ] using
(mul_lt_mul_iff_left (opow_pos b a0)).2 h,
λ b l c, opow_le_of_limit (ne_of_gt a0) l⟩
theorem opow_lt_opow_iff_right {a b c : ordinal}
(a1 : 1 < a) : a ^ b < a ^ c ↔ b < c :=
(opow_is_normal a1).lt_iff
theorem opow_le_opow_iff_right {a b c : ordinal}
(a1 : 1 < a) : a ^ b ≤ a ^ c ↔ b ≤ c :=
(opow_is_normal a1).le_iff
theorem opow_right_inj {a b c : ordinal}
(a1 : 1 < a) : a ^ b = a ^ c ↔ b = c :=
(opow_is_normal a1).inj
theorem opow_is_limit {a b : ordinal}
(a1 : 1 < a) : is_limit b → is_limit (a ^ b) :=
(opow_is_normal a1).is_limit
theorem opow_is_limit_left {a b : ordinal}
(l : is_limit a) (hb : b ≠ 0) : is_limit (a ^ b) :=
begin
rcases zero_or_succ_or_limit b with e|⟨b,rfl⟩|l',
{ exact absurd e hb },
{ rw opow_succ,
exact mul_is_limit (opow_pos _ l.pos) l },
{ exact opow_is_limit l.one_lt l' }
end
theorem opow_le_opow_right {a b c : ordinal}
(h₁ : 0 < a) (h₂ : b ≤ c) : a ^ b ≤ a ^ c :=
begin
cases lt_or_eq_of_le (one_le_iff_pos.2 h₁) with h₁ h₁,
{ exact (opow_le_opow_iff_right h₁).2 h₂ },
{ subst a, simp only [one_opow] }
end
theorem opow_le_opow_left {a b : ordinal} (c)
(ab : a ≤ b) : a ^ c ≤ b ^ c :=
begin
by_cases a0 : a = 0,
{ subst a, by_cases c0 : c = 0,
{ subst c, simp only [opow_zero] },
{ simp only [zero_opow c0, ordinal.zero_le] } },
{ apply limit_rec_on c,
{ simp only [opow_zero] },
{ intros c IH, simpa only [opow_succ] using mul_le_mul' IH ab },
{ exact λ c l IH, (opow_le_of_limit a0 l).2
(λ b' h, (IH _ h).trans (opow_le_opow_right
((ordinal.pos_iff_ne_zero.2 a0).trans_le ab) h.le)) } }
end
theorem left_le_opow (a : ordinal) {b : ordinal} (b1 : 0 < b) : a ≤ a ^ b :=
begin
nth_rewrite 0 ←opow_one a,
cases le_or_gt a 1 with a1 a1,
{ cases lt_or_eq_of_le a1 with a0 a1,
{ rw lt_one_iff_zero at a0,
rw [a0, zero_opow ordinal.one_ne_zero],
exact ordinal.zero_le _ },
rw [a1, one_opow, one_opow] },
rwa [opow_le_opow_iff_right a1, one_le_iff_pos]
end
theorem right_le_opow {a : ordinal} (b) (a1 : 1 < a) : b ≤ a ^ b :=
(opow_is_normal a1).self_le _
theorem opow_lt_opow_left_of_succ {a b c : ordinal}
(ab : a < b) : a ^ succ c < b ^ succ c :=
by { rw [opow_succ, opow_succ], exact
(mul_le_mul_right' (opow_le_opow_left c ab.le) a).trans_lt
(mul_lt_mul_of_pos_left ab (opow_pos c ((ordinal.zero_le a).trans_lt ab))) }
theorem opow_add (a b c : ordinal) : a ^ (b + c) = a ^ b * a ^ c :=
begin
rcases eq_or_ne a 0 with rfl | a0,
{ rcases eq_or_ne c 0 with rfl | c0, { simp },
have : b + c ≠ 0 := ((ordinal.pos_iff_ne_zero.2 c0).trans_le (le_add_left _ _)).ne',
simp only [zero_opow c0, zero_opow this, mul_zero] },
rcases eq_or_lt_of_le (one_le_iff_ne_zero.2 a0) with rfl | a1,
{ simp only [one_opow, mul_one] },
apply limit_rec_on c,
{ simp },
{ intros c IH,
rw [add_succ, opow_succ, IH, opow_succ, mul_assoc] },
{ intros c l IH,
refine eq_of_forall_ge_iff (λ d, (((opow_is_normal a1).trans
(add_is_normal b)).limit_le l).trans _),
dsimp only [function.comp],
simp only [IH] {contextual := tt},
exact (((mul_is_normal $ opow_pos b (ordinal.pos_iff_ne_zero.2 a0)).trans
(opow_is_normal a1)).limit_le l).symm }
end
theorem opow_one_add (a b : ordinal) : a ^ (1 + b) = a * a ^ b :=
by rw [opow_add, opow_one]
theorem opow_dvd_opow (a) {b c : ordinal} (h : b ≤ c) : a ^ b ∣ a ^ c :=
⟨a ^ (c - b), by rw [←opow_add, ordinal.add_sub_cancel_of_le h] ⟩
theorem opow_dvd_opow_iff {a b c : ordinal} (a1 : 1 < a) : a ^ b ∣ a ^ c ↔ b ≤ c :=
⟨λ h, le_of_not_lt $ λ hn,
not_le_of_lt ((opow_lt_opow_iff_right a1).2 hn) $
le_of_dvd (opow_ne_zero _ $ one_le_iff_ne_zero.1 $ a1.le) h,
opow_dvd_opow _⟩
theorem opow_mul (a b c : ordinal) : a ^ (b * c) = (a ^ b) ^ c :=
begin
by_cases b0 : b = 0, {simp only [b0, zero_mul, opow_zero, one_opow]},
by_cases a0 : a = 0,
{ subst a,
by_cases c0 : c = 0, {simp only [c0, mul_zero, opow_zero]},
simp only [zero_opow b0, zero_opow c0, zero_opow (mul_ne_zero b0 c0)] },
cases eq_or_lt_of_le (one_le_iff_ne_zero.2 a0) with a1 a1,
{ subst a1, simp only [one_opow] },
apply limit_rec_on c,
{ simp only [mul_zero, opow_zero] },
{ intros c IH,
rw [mul_succ, opow_add, IH, opow_succ] },
{ intros c l IH,
refine eq_of_forall_ge_iff (λ d, (((opow_is_normal a1).trans
(mul_is_normal (ordinal.pos_iff_ne_zero.2 b0))).limit_le l).trans _),
dsimp only [function.comp],
simp only [IH] {contextual := tt},
exact (opow_le_of_limit (opow_ne_zero _ a0) l).symm }
end
/-! ### Ordinal logarithm -/
/-- The ordinal logarithm is the solution `u` to the equation `x = b ^ u * v + w` where `v < b` and
`w < b ^ u`. -/
@[pp_nodot] def log (b : ordinal) (x : ordinal) : ordinal :=
if h : 1 < b then pred (Inf {o | x < b ^ o}) else 0
/-- The set in the definition of `log` is nonempty. -/
theorem log_nonempty {b x : ordinal} (h : 1 < b) : {o | x < b ^ o}.nonempty :=
⟨_, succ_le_iff.1 (right_le_opow _ h)⟩
theorem log_def {b : ordinal} (h : 1 < b) (x : ordinal) : log b x = pred (Inf {o | x < b ^ o}) :=
by simp only [log, dif_pos h]
theorem log_of_not_one_lt_left {b : ordinal} (h : ¬ 1 < b) (x : ordinal) : log b x = 0 :=
by simp only [log, dif_neg h]
theorem log_of_left_le_one {b : ordinal} (h : b ≤ 1) : ∀ x, log b x = 0 :=
log_of_not_one_lt_left h.not_lt
@[simp] lemma log_zero_left : ∀ b, log 0 b = 0 :=
log_of_left_le_one zero_le_one
@[simp] theorem log_zero_right (b : ordinal) : log b 0 = 0 :=
if b1 : 1 < b then begin
rw [log_def b1, ← ordinal.le_zero, pred_le],
apply cInf_le',
dsimp,
rw [succ_zero, opow_one],
exact zero_lt_one.trans b1
end
else by simp only [log_of_not_one_lt_left b1]
@[simp] theorem log_one_left : ∀ b, log 1 b = 0 :=
log_of_left_le_one le_rfl
theorem succ_log_def {b x : ordinal} (hb : 1 < b) (hx : x ≠ 0) :
succ (log b x) = Inf {o | x < b ^ o} :=
begin
let t := Inf {o | x < b ^ o},
have : x < b ^ t := Inf_mem (log_nonempty hb),
rcases zero_or_succ_or_limit t with h|h|h,
{ refine ((one_le_iff_ne_zero.2 hx).not_lt _).elim,
simpa only [h, opow_zero] },
{ rw [show log b x = pred t, from log_def hb x,
succ_pred_iff_is_succ.2 h] },
{ rcases (lt_opow_of_limit (zero_lt_one.trans hb).ne' h).1 this with ⟨a, h₁, h₂⟩,
exact h₁.not_le.elim ((le_cInf_iff'' (log_nonempty hb)).1 le_rfl a h₂) }
end
theorem lt_opow_succ_log_self {b : ordinal} (hb : 1 < b) (x : ordinal) : x < b ^ succ (log b x) :=
begin
rcases eq_or_ne x 0 with rfl | hx,
{ apply opow_pos _ (zero_lt_one.trans hb) },
{ rw succ_log_def hb hx,
exact Inf_mem (log_nonempty hb) }
end
theorem opow_log_le_self (b) {x : ordinal} (hx : x ≠ 0) : b ^ log b x ≤ x :=
begin
rcases eq_or_ne b 0 with rfl | b0,
{ rw zero_opow',
refine (sub_le_self _ _).trans (one_le_iff_ne_zero.2 hx) },
rcases lt_or_eq_of_le (one_le_iff_ne_zero.2 b0) with hb | rfl,
{ refine le_of_not_lt (λ h, (lt_succ (log b x)).not_le _),
have := @cInf_le' _ _ {o | x < b ^ o} _ h,
rwa ←succ_log_def hb hx at this },
{ rwa [one_opow, one_le_iff_ne_zero] }
end
/-- `opow b` and `log b` (almost) form a Galois connection. -/
theorem opow_le_iff_le_log {b x c : ordinal} (hb : 1 < b) (hx : x ≠ 0) : b ^ c ≤ x ↔ c ≤ log b x :=
⟨λ h, le_of_not_lt $ λ hn,
(lt_opow_succ_log_self hb x).not_le $
((opow_le_opow_iff_right hb).2 (succ_le_of_lt hn)).trans h,
λ h, ((opow_le_opow_iff_right hb).2 h).trans (opow_log_le_self b hx)⟩
theorem lt_opow_iff_log_lt {b x c : ordinal} (hb : 1 < b) (hx : x ≠ 0) : x < b ^ c ↔ log b x < c :=
lt_iff_lt_of_le_iff_le (opow_le_iff_le_log hb hx)
theorem log_pos {b o : ordinal} (hb : 1 < b) (ho : o ≠ 0) (hbo : b ≤ o) : 0 < log b o :=
by rwa [←succ_le_iff, succ_zero, ←opow_le_iff_le_log hb ho, opow_one]
theorem log_eq_zero {b o : ordinal} (hbo : o < b) : log b o = 0 :=
begin
rcases eq_or_ne o 0 with rfl | ho,
{ exact log_zero_right b },
cases le_or_lt b 1 with hb hb,
{ rcases le_one_iff.1 hb with rfl | rfl,
{ exact log_zero_left o },
{ exact log_one_left o } },
{ rwa [←ordinal.le_zero, ←lt_succ_iff, succ_zero, ←lt_opow_iff_log_lt hb ho, opow_one] }
end
@[mono] theorem log_mono_right (b) {x y : ordinal} (xy : x ≤ y) : log b x ≤ log b y :=
if hx : x = 0 then by simp only [hx, log_zero_right, ordinal.zero_le] else
if hb : 1 < b then
(opow_le_iff_le_log hb (lt_of_lt_of_le (ordinal.pos_iff_ne_zero.2 hx) xy).ne').1 $
(opow_log_le_self _ hx).trans xy
else by simp only [log_of_not_one_lt_left hb, ordinal.zero_le]
theorem log_le_self (b x : ordinal) : log b x ≤ x :=
if hx : x = 0 then by simp only [hx, log_zero_right, ordinal.zero_le] else
if hb : 1 < b then (right_le_opow _ hb).trans (opow_log_le_self b hx)
else by simp only [log_of_not_one_lt_left hb, ordinal.zero_le]
@[simp] theorem log_one_right (b : ordinal) : log b 1 = 0 :=
if hb : 1 < b then log_eq_zero hb else log_of_not_one_lt_left hb 1
theorem mod_opow_log_lt_self (b : ordinal) {o : ordinal} (ho : o ≠ 0) : o % b ^ log b o < o :=
begin
rcases eq_or_ne b 0 with rfl | hb,
{ simpa using ordinal.pos_iff_ne_zero.2 ho },
{ exact (mod_lt _ $ opow_ne_zero _ hb).trans_le (opow_log_le_self _ ho) }
end
theorem log_mod_opow_log_lt_log_self {b o : ordinal} (hb : 1 < b) (ho : o ≠ 0) (hbo : b ≤ o) :
log b (o % b ^ log b o) < log b o :=
begin
cases eq_or_ne (o % b ^ log b o) 0,
{ rw [h, log_zero_right],
apply log_pos hb ho hbo },
{ rw [←succ_le_iff, succ_log_def hb h],
apply cInf_le',
apply mod_lt,
rw ←ordinal.pos_iff_ne_zero,
exact opow_pos _ (zero_lt_one.trans hb) }
end
lemma opow_mul_add_pos {b v : ordinal} (hb : b ≠ 0) (u) (hv : v ≠ 0) (w) : 0 < b ^ u * v + w :=
(opow_pos u $ ordinal.pos_iff_ne_zero.2 hb).trans_le $
(le_mul_left _ $ ordinal.pos_iff_ne_zero.2 hv).trans $ le_add_right _ _
lemma opow_mul_add_lt_opow_mul_succ {b u w : ordinal} (v : ordinal) (hw : w < b ^ u) :
b ^ u * v + w < b ^ u * (succ v) :=
by rwa [mul_succ, add_lt_add_iff_left]
lemma opow_mul_add_lt_opow_succ {b u v w : ordinal} (hvb : v < b) (hw : w < b ^ u) :
b ^ u * v + w < b ^ (succ u) :=
begin
convert (opow_mul_add_lt_opow_mul_succ v hw).trans_le (mul_le_mul_left' (succ_le_of_lt hvb) _),
exact opow_succ b u
end
theorem log_opow_mul_add {b u v w : ordinal} (hb : 1 < b) (hv : v ≠ 0) (hvb : v < b)
(hw : w < b ^ u) : log b (b ^ u * v + w) = u :=
begin
have hne' := (opow_mul_add_pos (zero_lt_one.trans hb).ne' u hv w).ne',
by_contra' hne,
cases lt_or_gt_of_ne hne with h h,
{ rw ←lt_opow_iff_log_lt hb hne' at h,
exact h.not_le ((le_mul_left _ (ordinal.pos_iff_ne_zero.2 hv)).trans (le_add_right _ _)) },
{ change _ < _ at h,
rw [←succ_le_iff, ←opow_le_iff_le_log hb hne'] at h,
exact (not_lt_of_le h) (opow_mul_add_lt_opow_succ hvb hw) }
end
theorem log_opow {b : ordinal} (hb : 1 < b) (x : ordinal) : log b (b ^ x) = x :=
begin
convert log_opow_mul_add hb zero_ne_one.symm hb (opow_pos x (zero_lt_one.trans hb)),
rw [add_zero, mul_one]
end
theorem div_opow_log_pos (b : ordinal) {o : ordinal} (ho : o ≠ 0) : 0 < o / b ^ log b o :=
begin
rcases eq_zero_or_pos b with (rfl | hb),
{ simpa using ordinal.pos_iff_ne_zero.2 ho },
{ rw div_pos (opow_ne_zero _ hb.ne'),
exact opow_log_le_self b ho }
end
theorem div_opow_log_lt {b : ordinal} (o : ordinal) (hb : 1 < b) : o / b ^ log b o < b :=
begin
rw [div_lt (opow_pos _ (zero_lt_one.trans hb)).ne', ←opow_succ],
exact lt_opow_succ_log_self hb o
end
theorem add_log_le_log_mul {x y : ordinal} (b : ordinal) (hx : x ≠ 0) (hy : y ≠ 0) :
log b x + log b y ≤ log b (x * y) :=
begin
by_cases hb : 1 < b,
{ rw [←opow_le_iff_le_log hb (mul_ne_zero hx hy), opow_add],
exact mul_le_mul' (opow_log_le_self b hx) (opow_log_le_self b hy) },
simp only [log_of_not_one_lt_left hb, zero_add]
end
/-! ### Interaction with `nat.cast` -/
@[simp, norm_cast] theorem nat_cast_opow (m : ℕ) : ∀ n : ℕ, ((pow m n : ℕ) : ordinal) = m ^ n
| 0 := by simp
| (n+1) := by rw [pow_succ', nat_cast_mul, nat_cast_opow, nat.cast_succ, add_one_eq_succ, opow_succ]
local infixr (name := ordinal.pow) ^ := @pow ordinal ordinal ordinal.has_pow
theorem sup_opow_nat {o : ordinal} (ho : 0 < o) : sup (λ n : ℕ, o ^ n) = o ^ ω :=
begin
rcases lt_or_eq_of_le (one_le_iff_pos.2 ho) with ho₁ | rfl,
{ exact (opow_is_normal ho₁).apply_omega },
{ rw one_opow,
refine le_antisymm (sup_le (λ n, by rw one_opow)) _,
convert le_sup _ 0,
rw [nat.cast_zero, opow_zero] }
end
end ordinal
namespace tactic
open ordinal positivity
/-- Extension for the `positivity` tactic: `ordinal.opow` takes positive values on positive inputs.
-/
@[positivity]
meta def positivity_opow : expr → tactic strictness
| `(@has_pow.pow _ _ %%inst %%a %%b) := do
strictness_a ← core a,
match strictness_a with
| positive p := positive <$> mk_app ``opow_pos [b, p]
| _ := failed -- We already know that `0 ≤ x` for all `x : ordinal`
end
| _ := failed
end tactic
|
4e487d25a33d9a4f4e3bfa923bfcf6596a09be23 | b147e1312077cdcfea8e6756207b3fa538982e12 | /tactic/ring.lean | c958d19af2c6f069f1ae18a39bc439a66fb03a49 | [
"Apache-2.0"
] | permissive | SzJS/mathlib | 07836ee708ca27cd18347e1e11ce7dd5afb3e926 | 23a5591fca0d43ee5d49d89f6f0ee07a24a6ca29 | refs/heads/master | 1,584,980,332,064 | 1,532,063,841,000 | 1,532,063,841,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 17,695 | lean | /-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
Evaluate expressions in the language of (semi-)rings.
Based on http://www.cs.ru.nl/~freek/courses/tt-2014/read/10.1.1.61.3041.pdf .
-/
import algebra.group_power tactic.norm_num
universes u v w
open tactic
def horner {α} [comm_semiring α] (a x : α) (n : ℕ) (b : α) := a * x ^ n + b
namespace tactic
namespace ring
meta structure cache :=
(α : expr)
(univ : level)
(comm_semiring_inst : expr)
meta def mk_cache (e : expr) : tactic cache :=
do α ← infer_type e,
c ← mk_app ``comm_semiring [α] >>= mk_instance,
u ← mk_meta_univ,
infer_type α >>= unify (expr.sort (level.succ u)),
u ← get_univ_assignment u,
return ⟨α, u, c⟩
meta def cache.cs_app (c : cache) (n : name) : list expr → expr :=
(@expr.const tt n [c.univ] c.α c.comm_semiring_inst).mk_app
meta inductive destruct_ty : Type
| const : ℚ → destruct_ty
| xadd : expr → expr → expr → ℕ → expr → destruct_ty
open destruct_ty
meta def destruct (e : expr) : option destruct_ty :=
match expr.to_rat e with
| some n := some $ const n
| none := match e with
| `(horner %%a %%x %%n %%b) :=
do n' ← expr.to_nat n,
some (xadd a x n n' b)
| _ := none
end
end
meta def normal_form_to_string : expr → string
| e := match destruct e with
| some (const n) := to_string n
| some (xadd a x _ n b) :=
"(" ++ normal_form_to_string a ++ ") * (" ++ to_string x ++ ")^"
++ to_string n ++ " + " ++ normal_form_to_string b
| none := to_string e
end
theorem zero_horner {α} [comm_semiring α] (x n b) :
@horner α _ 0 x n b = b :=
by simp [horner]
theorem horner_horner {α} [comm_semiring α] (a₁ x n₁ n₂ b n')
(h : n₁ + n₂ = n') :
@horner α _ (horner a₁ x n₁ 0) x n₂ b = horner a₁ x n' b :=
by simp [h.symm, horner, pow_add, mul_assoc]
meta def refl_conv (e : expr) : tactic (expr × expr) :=
do p ← mk_eq_refl e, return (e, p)
meta def trans_conv (t₁ t₂ : expr → tactic (expr × expr)) (e : expr) :
tactic (expr × expr) :=
(do (e₁, p₁) ← t₁ e,
(do (e₂, p₂) ← t₂ e₁,
p ← mk_eq_trans p₁ p₂, return (e₂, p)) <|>
return (e₁, p₁)) <|> t₂ e
meta def eval_horner (c : cache) (a x n b : expr) : tactic (expr × expr) :=
do d ← destruct a, match d with
| const q := if q = 0 then
return (b, c.cs_app ``zero_horner [x, n, b])
else refl_conv $ c.cs_app ``horner [a, x, n, b]
| xadd a₁ x₁ n₁ _ b₁ :=
if x₁ = x ∧ b₁.to_nat = some 0 then do
(n', h) ← mk_app ``has_add.add [n₁, n] >>= norm_num,
return (c.cs_app ``horner [a₁, x, n', b],
c.cs_app ``horner_horner [a₁, x, n₁, n, b, n', h])
else refl_conv $ c.cs_app ``horner [a, x, n, b]
end
theorem const_add_horner {α} [comm_semiring α] (k a x n b b') (h : k + b = b') :
k + @horner α _ a x n b = horner a x n b' :=
by simp [h.symm, horner]
theorem horner_add_const {α} [comm_semiring α] (a x n b k b') (h : b + k = b') :
@horner α _ a x n b + k = horner a x n b' :=
by simp [h.symm, horner]
theorem horner_add_horner_lt {α} [comm_semiring α] (a₁ x n₁ b₁ a₂ n₂ b₂ k a' b')
(h₁ : n₁ + k = n₂) (h₂ : (a₁ + horner a₂ x k 0 : α) = a') (h₃ : b₁ + b₂ = b') :
@horner α _ a₁ x n₁ b₁ + horner a₂ x n₂ b₂ = horner a' x n₁ b' :=
by simp [h₂.symm, h₃.symm, h₁.symm, horner, pow_add, mul_add, mul_comm, mul_left_comm]
theorem horner_add_horner_gt {α} [comm_semiring α] (a₁ x n₁ b₁ a₂ n₂ b₂ k a' b')
(h₁ : n₂ + k = n₁) (h₂ : (horner a₁ x k 0 + a₂ : α) = a') (h₃ : b₁ + b₂ = b') :
@horner α _ a₁ x n₁ b₁ + horner a₂ x n₂ b₂ = horner a' x n₂ b' :=
by simp [h₂.symm, h₃.symm, h₁.symm, horner, pow_add, mul_add, mul_comm, mul_left_comm]
theorem horner_add_horner_eq {α} [comm_semiring α] (a₁ x n b₁ a₂ b₂ a' b' t)
(h₁ : a₁ + a₂ = a') (h₂ : b₁ + b₂ = b') (h₃ : horner a' x n b' = t) :
@horner α _ a₁ x n b₁ + horner a₂ x n b₂ = t :=
by simp [h₃.symm, h₂.symm, h₁.symm, horner, add_mul, mul_comm]
meta def eval_add (c : cache) : expr → expr → tactic (expr × expr)
| e₁ e₂ := do d₁ ← destruct e₁, d₂ ← destruct e₂,
match d₁, d₂ with
| const n₁, const n₂ :=
mk_app ``has_add.add [e₁, e₂] >>= norm_num
| const k, xadd a x n _ b :=
if k = 0 then do
p ← mk_app ``zero_add [e₂],
return (e₂, p) else do
(b', h) ← eval_add e₁ b,
return (c.cs_app ``horner [a, x, n, b'],
c.cs_app ``const_add_horner [e₁, a, x, n, b, b', h])
| xadd a x n _ b, const k :=
if k = 0 then do
p ← mk_app ``add_zero [e₁],
return (e₁, p) else do
(b', h) ← eval_add b e₂,
return (c.cs_app ``horner [a, x, n, b'],
c.cs_app ``horner_add_const [a, x, n, b, e₂, b', h])
| xadd a₁ x₁ en₁ n₁ b₁, xadd a₂ x₂ en₂ n₂ b₂ :=
if expr.lex_lt x₁ x₂ then do
(b', h) ← eval_add b₁ e₂,
return (c.cs_app ``horner [a₁, x₁, en₁, b'],
c.cs_app ``horner_add_const [a₁, x₁, en₁, b₁, e₂, b', h])
else if x₁ ≠ x₂ then do
(b', h) ← eval_add e₁ b₂,
return (c.cs_app ``horner [a₂, x₂, en₂, b'],
c.cs_app ``const_add_horner [e₁, a₂, x₂, en₂, b₂, b', h])
else if n₁ < n₂ then do
k ← expr.of_nat (expr.const `nat []) (n₂ - n₁),
(_, h₁) ← mk_app ``has_add.add [en₁, k] >>= norm_num,
α0 ← expr.of_nat c.α 0,
(a', h₂) ← eval_add a₁ (c.cs_app ``horner [a₂, x₁, k, α0]),
(b', h₃) ← eval_add b₁ b₂,
return (c.cs_app ``horner [a', x₁, en₁, b'],
c.cs_app ``horner_add_horner_lt [a₁, x₁, en₁, b₁, a₂, en₂, b₂, k, a', b', h₁, h₂, h₃])
else if n₁ ≠ n₂ then do
k ← expr.of_nat (expr.const `nat []) (n₁ - n₂),
(_, h₁) ← mk_app ``has_add.add [en₂, k] >>= norm_num,
α0 ← expr.of_nat c.α 0,
(a', h₂) ← eval_add (c.cs_app ``horner [a₁, x₁, k, α0]) a₂,
(b', h₃) ← eval_add b₁ b₂,
return (c.cs_app ``horner [a', x₁, en₂, b'],
c.cs_app ``horner_add_horner_gt [a₁, x₁, en₁, b₁, a₂, en₂, b₂, k, a', b', h₁, h₂, h₃])
else do
(a', h₁) ← eval_add a₁ a₂,
(b', h₂) ← eval_add b₁ b₂,
(t, h₃) ← eval_horner c a' x₁ en₁ b',
return (t, c.cs_app ``horner_add_horner_eq
[a₁, x₁, en₁, b₁, a₂, b₂, a', b', t, h₁, h₂, h₃])
end
theorem horner_neg {α} [comm_ring α] (a x n b a' b')
(h₁ : -a = a') (h₂ : -b = b') :
-@horner α _ a x n b = horner a' x n b' :=
by simp [h₂.symm, h₁.symm, horner]
meta def eval_neg (c : cache) : expr → tactic (expr × expr) | e :=
do d ← destruct e, match d with
| const _ :=
mk_app ``has_neg.neg [e] >>= norm_num
| xadd a x n _ b := do
(a', h₁) ← eval_neg a,
(b', h₂) ← eval_neg b,
p ← mk_app ``horner_neg [a, x, n, b, a', b', h₁, h₂],
return (c.cs_app ``horner [a', x, n, b'], p)
end
theorem horner_const_mul {α} [comm_semiring α] (c a x n b a' b')
(h₁ : c * a = a') (h₂ : c * b = b') :
c * @horner α _ a x n b = horner a' x n b' :=
by simp [h₂.symm, h₁.symm, horner, mul_add, mul_assoc]
theorem horner_mul_const {α} [comm_semiring α] (a x n b c a' b')
(h₁ : a * c = a') (h₂ : b * c = b') :
@horner α _ a x n b * c = horner a' x n b' :=
by simp [h₂.symm, h₁.symm, horner, add_mul, mul_right_comm]
meta def eval_const_mul (c : cache) (k : expr) : expr → tactic (expr × expr) | e :=
do d ← destruct e, match d with
| const _ :=
mk_app ``has_mul.mul [k, e] >>= norm_num
| xadd a x n _ b := do
(a', h₁) ← eval_const_mul a,
(b', h₂) ← eval_const_mul b,
return (c.cs_app ``horner [a', x, n, b'],
c.cs_app ``horner_const_mul [k, a, x, n, b, a', b', h₁, h₂])
end
theorem horner_mul_horner_zero {α} [comm_semiring α] (a₁ x n₁ b₁ a₂ n₂ aa t)
(h₁ : @horner α _ a₁ x n₁ b₁ * a₂ = aa)
(h₂ : horner aa x n₂ 0 = t) :
horner a₁ x n₁ b₁ * horner a₂ x n₂ 0 = t :=
by rw [← h₂, ← h₁];
simp [horner, mul_add, mul_comm, mul_left_comm, mul_assoc]
theorem horner_mul_horner {α} [comm_semiring α]
(a₁ x n₁ b₁ a₂ n₂ b₂ aa haa ab bb t)
(h₁ : @horner α _ a₁ x n₁ b₁ * a₂ = aa)
(h₂ : horner aa x n₂ 0 = haa)
(h₃ : a₁ * b₂ = ab) (h₄ : b₁ * b₂ = bb)
(H : haa + horner ab x n₁ bb = t) :
horner a₁ x n₁ b₁ * horner a₂ x n₂ b₂ = t :=
by rw [← H, ← h₂, ← h₁, ← h₃, ← h₄];
simp [horner, mul_add, mul_comm, mul_left_comm, mul_assoc]
meta def eval_mul (c : cache) : expr → expr → tactic (expr × expr)
| e₁ e₂ := do d₁ ← destruct e₁, d₂ ← destruct e₂,
match d₁, d₂ with
| const n₁, const n₂ :=
mk_app ``has_mul.mul [e₁, e₂] >>= norm_num
| const n₁, _ :=
if n₁ = 0 then do
α0 ← expr.of_nat c.α 0,
p ← mk_app ``zero_mul [e₂],
return (α0, p) else
if n₁ = 1 then do
p ← mk_app ``one_mul [e₂],
return (e₂, p) else
eval_const_mul c e₁ e₂
| _, const _ := do
p₁ ← mk_app ``mul_comm [e₁, e₂],
(e', p₂) ← eval_mul e₂ e₁,
p ← mk_eq_trans p₁ p₂, return (e', p)
| xadd a₁ x₁ en₁ n₁ b₁, xadd a₂ x₂ en₂ n₂ b₂ :=
if expr.lex_lt x₁ x₂ then do
(a', h₁) ← eval_mul a₁ e₂,
(b', h₂) ← eval_mul b₁ e₂,
return (c.cs_app ``horner [a', x₁, en₁, b'],
c.cs_app ``horner_mul_const [a₁, x₁, en₁, b₁, e₂, a', b', h₁, h₂])
else if x₁ ≠ x₂ then do
(a', h₁) ← eval_mul e₁ a₂,
(b', h₂) ← eval_mul e₁ b₂,
return (c.cs_app ``horner [a', x₂, en₂, b'],
c.cs_app ``horner_const_mul [e₁, a₂, x₂, en₂, b₂, a', b', h₁, h₂])
else do
(aa, h₁) ← eval_mul e₁ a₂,
α0 ← expr.of_nat c.α 0,
(haa, h₂) ← eval_horner c aa x₁ en₂ α0,
if b₂.to_nat = some 0 then do
return (haa, c.cs_app ``horner_mul_horner_zero
[a₁, x₁, en₁, b₁, a₂, en₂, aa, haa, h₁, h₂])
else do
(ab, h₃) ← eval_mul a₁ b₂,
(bb, h₄) ← eval_mul b₁ b₂,
(t, H) ← eval_add c haa (c.cs_app ``horner [ab, x₁, en₁, bb]),
return (t, c.cs_app ``horner_mul_horner
[a₁, x₁, en₁, b₁, a₂, en₂, b₂, aa, haa, ab, bb, t, h₁, h₂, h₃, h₄, H])
end
theorem horner_pow {α} [comm_semiring α] (a x n m n' a')
(h₁ : n * m = n') (h₂ : a ^ m = a') :
@horner α _ a x n 0 ^ m = horner a' x n' 0 :=
by simp [h₁.symm, h₂.symm, horner, mul_pow, pow_mul]
meta def eval_pow (c : cache) : expr → nat → tactic (expr × expr)
| e 0 := do
α1 ← expr.of_nat c.α 1,
p ← mk_app ``pow_zero [e],
return (α1, p)
| e 1 := do
p ← mk_app ``pow_one [e],
return (e, p)
| e m := do d ← destruct e,
let N : expr := expr.const `nat [],
match d with
| const _ := do
e₂ ← expr.of_nat N m,
mk_app ``monoid.pow [e, e₂] >>= norm_num.derive
| xadd a x n _ b := match b.to_nat with
| some 0 := do
e₂ ← expr.of_nat N m,
(n', h₁) ← mk_app ``has_mul.mul [n, e₂] >>= norm_num,
(a', h₂) ← eval_pow a m,
α0 ← expr.of_nat c.α 0,
return (c.cs_app ``horner [a', x, n', α0],
c.cs_app ``horner_pow [a, x, n, e₂, n', a', h₁, h₂])
| _ := do
e₂ ← expr.of_nat N (m-1),
l ← mk_app ``monoid.pow [e, e₂],
(tl, hl) ← eval_pow e (m-1),
(t, p₂) ← eval_mul c tl e,
hr ← mk_eq_refl e,
p₂ ← mk_app ``norm_num.subst_into_prod [l, e, tl, e, t, hl, hr, p₂],
p₁ ← mk_app ``pow_succ' [e, e₂],
p ← mk_eq_trans p₁ p₂,
return (t, p)
end
end
theorem horner_atom {α} [comm_semiring α] (x : α) : x = horner 1 x 1 0 :=
by simp [horner]
lemma subst_into_neg {α} [has_neg α] (a ta t : α) (pra : a = ta) (prt : -ta = t) : -a = t :=
by simp [pra, prt]
meta def eval_atom (c : cache) (e : expr) : tactic (expr × expr) :=
do α0 ← expr.of_nat c.α 0,
α1 ← expr.of_nat c.α 1,
n1 ← expr.of_nat (expr.const `nat []) 1,
return (c.cs_app ``horner [α1, e, n1, α0], c.cs_app ``horner_atom [e])
lemma subst_into_pow {α} [monoid α] (l r tl tr t)
(prl : (l : α) = tl) (prr : (r : ℕ) = tr) (prt : tl ^ tr = t) : l ^ r = t :=
by simp [prl, prr, prt]
meta def eval (c : cache) : expr → tactic (expr × expr)
| `(%%e₁ + %%e₂) := do
(e₁', p₁) ← eval e₁,
(e₂', p₂) ← eval e₂,
(e', p') ← eval_add c e₁' e₂',
p ← mk_app ``norm_num.subst_into_sum [e₁, e₂, e₁', e₂', e', p₁, p₂, p'],
return (e', p)
| `(%%e₁ - %%e₂) := do
e₂' ← mk_app ``has_neg.neg [e₂],
mk_app ``has_add.add [e₁, e₂'] >>= eval
| `(- %%e) := do
(e₁, p₁) ← eval e,
(e₂, p₂) ← eval_neg c e₁,
p ← mk_app ``subst_into_neg [e, e₁, e₂, p₁, p₂],
return (e₂, p)
| `(%%e₁ * %%e₂) := do
(e₁', p₁) ← eval e₁,
(e₂', p₂) ← eval e₂,
(e', p') ← eval_mul c e₁' e₂',
p ← mk_app ``norm_num.subst_into_prod [e₁, e₂, e₁', e₂', e', p₁, p₂, p'],
return (e', p)
| e@`(has_inv.inv %%_) := (do
(e', p) ← norm_num.derive e,
e'.to_rat,
return (e', p)) <|> eval_atom c e
| e@`(%%e₁ / %%e₂) := do
e₂' ← mk_app ``has_inv.inv [e₂],
mk_app ``has_mul.mul [e₁, e₂'] >>= eval
| e@`(@has_pow.pow _ _ %%P %%e₁ %%e₂) := do
(e₂', p₂) ← eval e₂,
match e₂'.to_nat, P with
| some k, `(monoid.has_pow) := do
(e₁', p₁) ← eval e₁,
(e', p') ← eval_pow c e₁' k,
p ← mk_app ``subst_into_pow [e₁, e₂, e₁', e₂', e', p₁, p₂, p'],
return (e', p)
| some k, `(nat.has_pow) := do
(e₁', p₁) ← eval e₁,
(e', p') ← eval_pow c e₁' k,
p₃ ← mk_app ``subst_into_pow [e₁, e₂, e₁', e₂', e', p₁, p₂, p'],
p₄ ← mk_app ``nat.pow_eq_pow [e₁, e₂] >>= mk_eq_symm,
p ← mk_eq_trans p₄ p₃,
return (e', p)
| _, _ := eval_atom c e
end
| e := match e.to_nat with
| some _ := refl_conv e
| none := eval_atom c e
end
theorem horner_def' {α} [comm_semiring α] (a x n b) : @horner α _ a x n b = x ^ n * a + b :=
by simp [horner, mul_comm]
theorem mul_assoc_rev {α} [semigroup α] (a b c : α) : a * (b * c) = a * b * c :=
by simp [mul_assoc]
theorem pow_add_rev {α} [monoid α] (a b : α) (m n : ℕ) : a ^ m * a ^ n = a ^ (m + n) :=
by simp [pow_add]
theorem pow_add_rev_right {α} [monoid α] (a b : α) (m n : ℕ) : b * a ^ m * a ^ n = b * a ^ (m + n) :=
by simp [pow_add, mul_assoc]
theorem add_neg_eq_sub {α : Type u} [add_group α] (a b : α) : a + -b = a - b := rfl
@[derive has_reflect]
inductive normalize_mode | raw | SOP | horner
meta def normalize (mode := normalize_mode.horner) (e : expr) : tactic (expr × expr) := do
pow_lemma ← simp_lemmas.mk.add_simp ``pow_one,
let lemmas := match mode with
| normalize_mode.SOP :=
[``horner_def', ``add_zero, ``mul_one, ``mul_add, ``mul_sub,
``mul_assoc_rev, ``pow_add_rev, ``pow_add_rev_right,
``mul_neg_eq_neg_mul_symm, ``add_neg_eq_sub]
| normalize_mode.horner :=
[``horner.equations._eqn_1, ``add_zero, ``one_mul, ``pow_one,
``neg_mul_eq_neg_mul_symm, ``add_neg_eq_sub]
| _ := []
end,
lemmas ← lemmas.mfoldl simp_lemmas.add_simp simp_lemmas.mk,
(_, e', pr) ← ext_simplify_core () {}
simp_lemmas.mk (λ _, failed) (λ _ _ _ _ e, do
c ← mk_cache e,
(new_e, pr) ← match mode with
| normalize_mode.raw := eval c
| normalize_mode.horner := trans_conv (eval c) (simplify lemmas [])
| normalize_mode.SOP :=
trans_conv (eval c) $
trans_conv (simplify lemmas []) $
simp_bottom_up' (λ e, norm_num e <|> pow_lemma.rewrite e)
end e,
guard (¬ new_e =ₐ e),
return ((), new_e, some pr, ff))
(λ _ _ _ _ _, failed) `eq e,
return (e', pr)
end ring
namespace interactive
open interactive interactive.types lean.parser
open tactic.ring
local postfix `?`:9001 := optional
/-- Tactic for solving equations in the language of rings.
This version of `ring` fails if the target is not an equality
that is provable by the axioms of commutative (semi)rings. -/
meta def ring1 : tactic unit :=
do `(%%e₁ = %%e₂) ← target,
c ← mk_cache e₁,
(e₁', p₁) ← eval c e₁,
(e₂', p₂) ← eval c e₂,
is_def_eq e₁' e₂',
p ← mk_eq_symm p₂ >>= mk_eq_trans p₁,
tactic.exact p
meta def ring.mode : lean.parser ring.normalize_mode :=
with_desc "(SOP|raw|horner)?" $
do mode ← ident?, match mode with
| none := return ring.normalize_mode.horner
| some `horner := return ring.normalize_mode.horner
| some `SOP := return ring.normalize_mode.SOP
| some `raw := return ring.normalize_mode.raw
| _ := failed
end
/-- Tactic for solving equations in the language of rings.
Attempts to prove the goal outright if there is no `at`
specifier and the target is an equality, but if this
fails it falls back to rewriting all ring expressions
into a normal form. When writing a normal form,
`ring SOP` will use sum-of-products form instead of horner form. -/
meta def ring (SOP : parse ring.mode) (loc : parse location) : tactic unit :=
match loc with
| interactive.loc.ns [none] := ring1
| _ := failed
end <|>
do ns ← loc.get_locals,
tt ← tactic.replace_at (normalize SOP) ns loc.include_goal
| fail "ring failed to simplify",
when loc.include_goal $ try tactic.reflexivity
end interactive
end tactic
|
49b4388f94957a699f80a485c0e50db0d99e9961 | 77c5b91fae1b966ddd1db969ba37b6f0e4901e88 | /src/group_theory/order_of_element.lean | 136f2995d00b033898889262f579de915d108d85 | [
"Apache-2.0"
] | permissive | dexmagic/mathlib | ff48eefc56e2412429b31d4fddd41a976eb287ce | 7a5d15a955a92a90e1d398b2281916b9c41270b2 | refs/heads/master | 1,693,481,322,046 | 1,633,360,193,000 | 1,633,360,193,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 39,292 | 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, Julian Kuelshammer
-/
import algebra.pointwise
import group_theory.coset
import dynamics.periodic_pts
import algebra.iterate_hom
/-!
# Order of an element
This file defines the order of an element of a finite group. For a finite group `G` the order of
`x ∈ G` is the minimal `n ≥ 1` such that `x ^ n = 1`.
## Main definitions
* `is_of_fin_order` is a predicate on an element `x` of a monoid `G` saying that `x` is of finite
order.
* `is_of_fin_add_order` is the additive analogue of `is_of_find_order`.
* `order_of x` defines the order of an element `x` of a monoid `G`, by convention its value is `0`
if `x` has infinite order.
* `add_order_of` is the additive analogue of `order_of`.
## Tags
order of an element
-/
open function nat
open_locale pointwise
universes u v
variables {G : Type u} {A : Type v}
variables {x y : G} {a b : A} {n m : ℕ}
section monoid_add_monoid
variables [monoid G] [add_monoid A]
section is_of_fin_order
lemma is_periodic_pt_add_iff_nsmul_eq_zero (a : A) :
is_periodic_pt ((+) a) n 0 ↔ n • a = 0 :=
by rw [is_periodic_pt, is_fixed_pt, add_left_iterate, add_zero]
@[to_additive is_periodic_pt_add_iff_nsmul_eq_zero]
lemma is_periodic_pt_mul_iff_pow_eq_one (x : G) : is_periodic_pt ((*) x) n 1 ↔ x ^ n = 1 :=
by rw [is_periodic_pt, is_fixed_pt, mul_left_iterate, mul_one]
/-- `is_of_fin_add_order` is a predicate on an element `a` of an additive monoid to be of finite
order, i.e. there exists `n ≥ 1` such that `n • a = 0`.-/
def is_of_fin_add_order (a : A) : Prop :=
(0 : A) ∈ periodic_pts ((+) a)
/-- `is_of_fin_order` is a predicate on an element `x` of a monoid to be of finite order, i.e. there
exists `n ≥ 1` such that `x ^ n = 1`.-/
@[to_additive is_of_fin_add_order]
def is_of_fin_order (x : G) : Prop :=
(1 : G) ∈ periodic_pts ((*) x)
lemma is_of_fin_add_order_of_mul_iff :
is_of_fin_add_order (additive.of_mul x) ↔ is_of_fin_order x := iff.rfl
lemma is_of_fin_order_of_add_iff :
is_of_fin_order (multiplicative.of_add a) ↔ is_of_fin_add_order a := iff.rfl
lemma is_of_fin_add_order_iff_nsmul_eq_zero (a : A) :
is_of_fin_add_order a ↔ ∃ n, 0 < n ∧ n • a = 0 :=
by { convert iff.rfl, simp only [exists_prop, is_periodic_pt_add_iff_nsmul_eq_zero] }
@[to_additive is_of_fin_add_order_iff_nsmul_eq_zero]
lemma is_of_fin_order_iff_pow_eq_one (x : G) :
is_of_fin_order x ↔ ∃ n, 0 < n ∧ x ^ n = 1 :=
by { convert iff.rfl, simp [is_periodic_pt_mul_iff_pow_eq_one] }
end is_of_fin_order
/-- `add_order_of a` is the order of the element `a`, i.e. the `n ≥ 1`, s.t. `n • a = 0` if it
exists. Otherwise, i.e. if `a` is of infinite order, then `add_order_of a` is `0` by convention.-/
noncomputable def add_order_of (a : A) : ℕ :=
minimal_period ((+) a) 0
/-- `order_of x` is the order of the element `x`, i.e. the `n ≥ 1`, s.t. `x ^ n = 1` if it exists.
Otherwise, i.e. if `x` is of infinite order, then `order_of x` is `0` by convention.-/
@[to_additive add_order_of]
noncomputable def order_of (x : G) : ℕ :=
minimal_period ((*) x) 1
attribute [to_additive add_order_of] order_of
@[to_additive]
lemma commute.order_of_mul_dvd_lcm (h : commute x y) :
order_of (x * y) ∣ nat.lcm (order_of x) (order_of y) :=
begin
convert function.commute.minimal_period_of_comp_dvd_lcm h.function_commute_mul_left,
rw [order_of, comp_mul_left],
end
@[simp] lemma add_order_of_of_mul_eq_order_of (x : G) :
add_order_of (additive.of_mul x) = order_of x := rfl
@[simp] lemma order_of_of_add_eq_add_order_of (a : A) :
order_of (multiplicative.of_add a) = add_order_of a := rfl
@[to_additive add_order_of_pos']
lemma order_of_pos' (h : is_of_fin_order x) : 0 < order_of x :=
minimal_period_pos_of_mem_periodic_pts h
lemma pow_order_of_eq_one (x : G) : x ^ order_of x = 1 :=
begin
convert is_periodic_pt_minimal_period ((*) x) _,
rw [order_of, mul_left_iterate, mul_one],
end
lemma add_order_of_nsmul_eq_zero (a : A) : add_order_of a • a = 0 :=
begin
convert is_periodic_pt_minimal_period ((+) a) _,
rw [add_order_of, add_left_iterate, add_zero],
end
attribute [to_additive add_order_of_nsmul_eq_zero] pow_order_of_eq_one
@[to_additive add_order_of_eq_zero]
lemma order_of_eq_zero (h : ¬ is_of_fin_order x) : order_of x = 0 :=
by rwa [order_of, minimal_period, dif_neg]
@[to_additive add_order_of_eq_zero_iff] lemma order_of_eq_zero_iff :
order_of x = 0 ↔ ¬ is_of_fin_order x :=
⟨λ h H, (order_of_pos' H).ne' h, order_of_eq_zero⟩
lemma nsmul_ne_zero_of_lt_add_order_of' (n0 : n ≠ 0) (h : n < add_order_of a) :
n • a ≠ 0 :=
λ j, not_is_periodic_pt_of_pos_of_lt_minimal_period n0 h
((is_periodic_pt_add_iff_nsmul_eq_zero a).mpr j)
@[to_additive nsmul_ne_zero_of_lt_add_order_of']
lemma pow_eq_one_of_lt_order_of' (n0 : n ≠ 0) (h : n < order_of x) : x ^ n ≠ 1 :=
λ j, not_is_periodic_pt_of_pos_of_lt_minimal_period n0 h
((is_periodic_pt_mul_iff_pow_eq_one x).mpr j)
lemma add_order_of_le_of_nsmul_eq_zero (hn : 0 < n) (h : n • a = 0) : add_order_of a ≤ n :=
is_periodic_pt.minimal_period_le hn (by rwa is_periodic_pt_add_iff_nsmul_eq_zero)
@[to_additive add_order_of_le_of_nsmul_eq_zero]
lemma order_of_le_of_pow_eq_one (hn : 0 < n) (h : x ^ n = 1) : order_of x ≤ n :=
is_periodic_pt.minimal_period_le hn (by rwa is_periodic_pt_mul_iff_pow_eq_one)
@[simp] lemma order_of_one : order_of (1 : G) = 1 :=
by rw [order_of, one_mul_eq_id, minimal_period_id]
@[simp] lemma add_order_of_zero : add_order_of (0 : A) = 1 :=
by simp only [←order_of_of_add_eq_add_order_of, order_of_one, of_add_zero]
attribute [to_additive add_order_of_zero] order_of_one
@[simp] lemma order_of_eq_one_iff : order_of x = 1 ↔ x = 1 :=
by rw [order_of, is_fixed_point_iff_minimal_period_eq_one, is_fixed_pt, mul_one]
@[simp] lemma add_order_of_eq_one_iff : add_order_of a = 1 ↔ a = 0 :=
by simp [← order_of_of_add_eq_add_order_of]
attribute [to_additive add_order_of_eq_one_iff] order_of_eq_one_iff
lemma pow_eq_mod_order_of {n : ℕ} : x ^ n = x ^ (n % order_of x) :=
calc x ^ n = x ^ (n % order_of x + order_of x * (n / order_of x)) : by rw [nat.mod_add_div]
... = x ^ (n % order_of x) : by simp [pow_add, pow_mul, pow_order_of_eq_one]
lemma nsmul_eq_mod_add_order_of {n : ℕ} : n • a = (n % add_order_of a) • a :=
begin
apply multiplicative.of_add.injective,
rw [← order_of_of_add_eq_add_order_of, of_add_nsmul, of_add_nsmul, pow_eq_mod_order_of],
end
attribute [to_additive nsmul_eq_mod_add_order_of] pow_eq_mod_order_of
lemma order_of_dvd_of_pow_eq_one (h : x ^ n = 1) : order_of x ∣ n :=
is_periodic_pt.minimal_period_dvd ((is_periodic_pt_mul_iff_pow_eq_one _).mpr h)
lemma add_order_of_dvd_of_nsmul_eq_zero (h : n • a = 0) : add_order_of a ∣ n :=
is_periodic_pt.minimal_period_dvd ((is_periodic_pt_add_iff_nsmul_eq_zero _).mpr h)
attribute [to_additive add_order_of_dvd_of_nsmul_eq_zero] order_of_dvd_of_pow_eq_one
lemma add_order_of_dvd_iff_nsmul_eq_zero {n : ℕ} : add_order_of a ∣ n ↔ n • a = 0 :=
⟨λ h, by rw [nsmul_eq_mod_add_order_of, nat.mod_eq_zero_of_dvd h, zero_nsmul],
add_order_of_dvd_of_nsmul_eq_zero⟩
@[to_additive add_order_of_dvd_iff_nsmul_eq_zero]
lemma order_of_dvd_iff_pow_eq_one {n : ℕ} : order_of x ∣ n ↔ x ^ n = 1 :=
⟨λ h, by rw [pow_eq_mod_order_of, nat.mod_eq_zero_of_dvd h, pow_zero], order_of_dvd_of_pow_eq_one⟩
lemma exists_pow_eq_self_of_coprime (h : n.coprime (order_of x)) :
∃ m : ℕ, (x ^ n) ^ m = x :=
begin
by_cases h0 : order_of x = 0,
{ rw [h0, coprime_zero_right] at h,
exact ⟨1, by rw [h, pow_one, pow_one]⟩ },
by_cases h1 : order_of x = 1,
{ exact ⟨0, by rw [order_of_eq_one_iff.mp h1, one_pow, one_pow]⟩ },
obtain ⟨m, hm⟩ :=
exists_mul_mod_eq_one_of_coprime h (one_lt_iff_ne_zero_and_ne_one.mpr ⟨h0, h1⟩),
exact ⟨m, by rw [←pow_mul, pow_eq_mod_order_of, hm, pow_one]⟩,
end
lemma exists_nsmul_eq_self_of_coprime (a : A)
(h : coprime n (add_order_of a)) : ∃ m : ℕ, m • (n • a) = a :=
begin
change n.coprime (order_of (multiplicative.of_add a)) at h,
exact exists_pow_eq_self_of_coprime h,
end
attribute [to_additive exists_nsmul_eq_self_of_coprime] exists_pow_eq_self_of_coprime
lemma add_order_of_eq_add_order_of_iff {B : Type*} [add_monoid B] {b : B} :
add_order_of a = add_order_of b ↔ ∀ n : ℕ, n • a = 0 ↔ n • b = 0 :=
begin
simp_rw ← add_order_of_dvd_iff_nsmul_eq_zero,
exact ⟨λ h n, by rw h, λ h, nat.dvd_antisymm ((h _).mpr dvd_rfl) ((h _).mp dvd_rfl)⟩,
end
@[to_additive add_order_of_eq_add_order_of_iff]
lemma order_of_eq_order_of_iff {H : Type*} [monoid H] {y : H} :
order_of x = order_of y ↔ ∀ n : ℕ, x ^ n = 1 ↔ y ^ n = 1 :=
by simp_rw [← is_periodic_pt_mul_iff_pow_eq_one, ← minimal_period_eq_minimal_period_iff, order_of]
lemma add_order_of_injective {B : Type*} [add_monoid B] (f : A →+ B)
(hf : function.injective f) (a : A) : add_order_of (f a) = add_order_of a :=
by simp_rw [add_order_of_eq_add_order_of_iff, ←f.map_nsmul, ←f.map_zero, hf.eq_iff, iff_self,
forall_const]
@[to_additive add_order_of_injective]
lemma order_of_injective {H : Type*} [monoid H] (f : G →* H)
(hf : function.injective f) (x : G) : order_of (f x) = order_of x :=
by simp_rw [order_of_eq_order_of_iff, ←f.map_pow, ←f.map_one, hf.eq_iff, iff_self, forall_const]
@[simp, norm_cast, to_additive] lemma order_of_submonoid {H : submonoid G}
(y : H) : order_of (y : G) = order_of y :=
order_of_injective H.subtype subtype.coe_injective y
variables (x)
lemma order_of_pow' (h : n ≠ 0) :
order_of (x ^ n) = order_of x / gcd (order_of x) n :=
begin
convert minimal_period_iterate_eq_div_gcd h,
simp only [order_of, mul_left_iterate],
end
variables (a)
lemma add_order_of_nsmul' (h : n ≠ 0) :
add_order_of (n • a) = add_order_of a / gcd (add_order_of a) n :=
by simpa [← order_of_of_add_eq_add_order_of, of_add_nsmul] using order_of_pow' _ h
attribute [to_additive add_order_of_nsmul'] order_of_pow'
variable (n)
lemma order_of_pow'' (h : is_of_fin_order x) :
order_of (x ^ n) = order_of x / gcd (order_of x) n :=
begin
convert minimal_period_iterate_eq_div_gcd' h,
simp only [order_of, mul_left_iterate],
end
lemma add_order_of_nsmul'' (h : is_of_fin_add_order a) :
add_order_of (n • a) = add_order_of a / gcd (add_order_of a) n :=
by simp [← order_of_of_add_eq_add_order_of, of_add_nsmul,
order_of_pow'' _ n (is_of_fin_order_of_add_iff.mpr h)]
attribute [to_additive add_order_of_nsmul''] order_of_pow''
section p_prime
variables {a x n} {p : ℕ} [hp : fact p.prime]
include hp
lemma add_order_of_eq_prime (hg : p • a = 0) (hg1 : a ≠ 0) : add_order_of a = p :=
minimal_period_eq_prime ((is_periodic_pt_add_iff_nsmul_eq_zero _).mpr hg)
(by rwa [is_fixed_pt, add_zero])
@[to_additive add_order_of_eq_prime]
lemma order_of_eq_prime (hg : x ^ p = 1) (hg1 : x ≠ 1) : order_of x = p :=
minimal_period_eq_prime ((is_periodic_pt_mul_iff_pow_eq_one _).mpr hg)
(by rwa [is_fixed_pt, mul_one])
lemma add_order_of_eq_prime_pow (hnot : ¬ (p ^ n) • a = 0) (hfin : (p ^ (n + 1)) • a = 0) :
add_order_of a = p ^ (n + 1) :=
begin
apply minimal_period_eq_prime_pow;
rwa is_periodic_pt_add_iff_nsmul_eq_zero,
end
@[to_additive add_order_of_eq_prime_pow]
lemma order_of_eq_prime_pow (hnot : ¬ x ^ p ^ n = 1) (hfin : x ^ p ^ (n + 1) = 1) :
order_of x = p ^ (n + 1) :=
begin
apply minimal_period_eq_prime_pow;
rwa is_periodic_pt_mul_iff_pow_eq_one,
end
omit hp
-- An example on how to determine the order of an element of a finite group.
example : order_of (-1 : units ℤ) = 2 :=
begin
haveI : fact (prime 2) := ⟨prime_two⟩,
exact order_of_eq_prime (int.units_mul_self _) dec_trivial,
end
end p_prime
end monoid_add_monoid
section cancel_monoid
variables [left_cancel_monoid G] (x)
variables [add_left_cancel_monoid A] (a)
lemma pow_injective_aux (h : n ≤ m)
(hm : m < order_of x) (eq : x ^ n = x ^ m) : n = m :=
by_contradiction $ assume ne : n ≠ m,
have h₁ : m - n > 0, from nat.pos_of_ne_zero (by simp [nat.sub_eq_iff_eq_add h, ne.symm]),
have h₂ : m = n + (m - n) := (nat.add_sub_of_le h).symm,
have h₃ : x ^ (m - n) = 1,
by { rw [h₂, pow_add] at eq, apply mul_left_cancel, convert eq.symm, exact mul_one (x ^ n) },
have le : order_of x ≤ m - n, from order_of_le_of_pow_eq_one h₁ h₃,
have lt : m - n < order_of x,
from (nat.sub_lt_left_iff_lt_add h).mpr $ nat.lt_add_left _ _ _ hm,
lt_irrefl _ (le.trans_lt lt)
-- TODO: This lemma was originally private, but this doesn't seem to work with `to_additive`,
-- therefore the private got removed.
lemma nsmul_injective_aux {n m : ℕ} (h : n ≤ m)
(hm : m < add_order_of a) (eq : n • a = m • a) : n = m :=
begin
apply_fun multiplicative.of_add at eq,
rw [of_add_nsmul, of_add_nsmul] at eq,
rw ← order_of_of_add_eq_add_order_of at hm,
exact pow_injective_aux (multiplicative.of_add a) h hm eq,
end
attribute [to_additive nsmul_injective_aux] pow_injective_aux
lemma nsmul_injective_of_lt_add_order_of {n m : ℕ}
(hn : n < add_order_of a) (hm : m < add_order_of a) (eq : n • a = m • a) : n = m :=
(le_total n m).elim
(assume h, nsmul_injective_aux a h hm eq)
(assume h, (nsmul_injective_aux a h hn eq.symm).symm)
@[to_additive nsmul_injective_of_lt_add_order_of]
lemma pow_injective_of_lt_order_of
(hn : n < order_of x) (hm : m < order_of x) (eq : x ^ n = x ^ m) : n = m :=
(le_total n m).elim
(assume h, pow_injective_aux x h hm eq)
(assume h, (pow_injective_aux x h hn eq.symm).symm)
end cancel_monoid
section group
variables [group G] [add_group A] {x a} {i : ℤ}
@[to_additive add_order_of_dvd_iff_gsmul_eq_zero]
lemma order_of_dvd_iff_gpow_eq_one : (order_of x : ℤ) ∣ i ↔ x ^ i = 1 :=
begin
rcases int.eq_coe_or_neg i with ⟨i, rfl|rfl⟩,
{ rw [int.coe_nat_dvd, order_of_dvd_iff_pow_eq_one, gpow_coe_nat] },
{ rw [dvd_neg, int.coe_nat_dvd, gpow_neg, inv_eq_one, gpow_coe_nat,
order_of_dvd_iff_pow_eq_one] }
end
@[simp, norm_cast, to_additive] lemma order_of_subgroup {H : subgroup G}
(y: H) : order_of (y : G) = order_of y :=
order_of_injective H.subtype subtype.coe_injective y
lemma gpow_eq_mod_order_of : x ^ i = x ^ (i % order_of x) :=
calc x ^ i = x ^ (i % order_of x + order_of x * (i / order_of x)) :
by rw [int.mod_add_div]
... = x ^ (i % order_of x) :
by simp [gpow_add, gpow_mul, pow_order_of_eq_one]
lemma gsmul_eq_mod_add_order_of : i • a = (i % add_order_of a) • a :=
begin
apply multiplicative.of_add.injective,
simp [of_add_gsmul, gpow_eq_mod_order_of],
end
attribute [to_additive gsmul_eq_mod_add_order_of] gpow_eq_mod_order_of
@[to_additive nsmul_inj_iff_of_add_order_of_eq_zero]
lemma pow_inj_iff_of_order_of_eq_zero (h : order_of x = 0) {n m : ℕ} :
x ^ n = x ^ m ↔ n = m :=
begin
by_cases hx : x = 1,
{ rw [←order_of_eq_one_iff, h] at hx,
contradiction },
rw [order_of_eq_zero_iff, is_of_fin_order_iff_pow_eq_one] at h,
push_neg at h,
induction n with n IH generalizing m,
{ cases m,
{ simp },
{ simpa [eq_comm] using h m.succ m.zero_lt_succ } },
{ cases m,
{ simpa using h n.succ n.zero_lt_succ },
{ simp [pow_succ, IH] } }
end
lemma pow_inj_mod {n m : ℕ} :
x ^ n = x ^ m ↔ n % order_of x = m % order_of x :=
begin
cases (order_of x).zero_le.eq_or_lt with hx hx,
{ simp [pow_inj_iff_of_order_of_eq_zero, hx.symm] },
rw [pow_eq_mod_order_of, @pow_eq_mod_order_of _ _ _ m],
exact ⟨pow_injective_of_lt_order_of _ (nat.mod_lt _ hx) (nat.mod_lt _ hx), λ h, congr_arg _ h⟩
end
lemma nsmul_inj_mod {n m : ℕ} :
n • a = m • a ↔ n % add_order_of a = m % add_order_of a :=
begin
cases (add_order_of a).zero_le.eq_or_lt with hx hx,
{ simp [nsmul_inj_iff_of_add_order_of_eq_zero, hx.symm] },
rw [nsmul_eq_mod_add_order_of, @nsmul_eq_mod_add_order_of _ _ _ m],
refine ⟨nsmul_injective_of_lt_add_order_of a (nat.mod_lt n hx) (nat.mod_lt m hx), λ h, _⟩,
rw h
end
attribute [to_additive nsmul_inj_mod] pow_inj_mod
end group
section fintype
variables [fintype G] [fintype A]
section finite_monoid
variables [monoid G] [add_monoid A]
open_locale big_operators
lemma sum_card_add_order_of_eq_card_nsmul_eq_zero [decidable_eq A] (hn : 0 < n) :
∑ m in (finset.range n.succ).filter (∣ n), (finset.univ.filter (λ a : A, add_order_of a = m)).card
= (finset.univ.filter (λ a : A, n • a = 0)).card :=
calc ∑ m in (finset.range n.succ).filter (∣ n),
(finset.univ.filter (λ a : A, add_order_of a = m)).card
= _ : (finset.card_bUnion (by { intros, apply finset.disjoint_filter.2, cc })).symm
... = _ : congr_arg finset.card (finset.ext (begin
assume a,
suffices : add_order_of a ≤ n ∧ add_order_of a ∣ n ↔ n • a = 0,
{ simpa [nat.lt_succ_iff], },
exact ⟨λ h, let ⟨m, hm⟩ := h.2 in
by rw [hm, mul_comm, mul_nsmul, add_order_of_nsmul_eq_zero, nsmul_zero],
λ h, ⟨add_order_of_le_of_nsmul_eq_zero hn h, add_order_of_dvd_of_nsmul_eq_zero h⟩⟩
end))
@[to_additive sum_card_add_order_of_eq_card_nsmul_eq_zero]
lemma sum_card_order_of_eq_card_pow_eq_one [decidable_eq G] (hn : 0 < n) :
∑ m in (finset.range n.succ).filter (∣ n), (finset.univ.filter (λ x : G, order_of x = m)).card
= (finset.univ.filter (λ x : G, x ^ n = 1)).card :=
calc ∑ m in (finset.range n.succ).filter (∣ n), (finset.univ.filter (λ x : G, order_of x = m)).card
= _ : (finset.card_bUnion (by { intros, apply finset.disjoint_filter.2, cc })).symm
... = _ : congr_arg finset.card (finset.ext (begin
assume x,
suffices : order_of x ≤ n ∧ order_of x ∣ n ↔ x ^ n = 1,
{ simpa [nat.lt_succ_iff], },
exact ⟨λ h, let ⟨m, hm⟩ := h.2 in by rw [hm, pow_mul, pow_order_of_eq_one, one_pow],
λ h, ⟨order_of_le_of_pow_eq_one hn h, order_of_dvd_of_pow_eq_one h⟩⟩
end))
end finite_monoid
section finite_cancel_monoid
-- TODO: Of course everything also works for right_cancel_monoids.
variables [left_cancel_monoid G] [add_left_cancel_monoid A]
-- TODO: Use this to show that a finite left cancellative monoid is a group.
lemma exists_pow_eq_one (x : G) : is_of_fin_order x :=
begin
refine (is_of_fin_order_iff_pow_eq_one _).mpr _,
obtain ⟨i, j, a_eq, ne⟩ : ∃(i j : ℕ), x ^ i = x ^ j ∧ i ≠ j :=
by simpa only [not_forall, exists_prop, injective]
using (not_injective_infinite_fintype (λi:ℕ, x^i)),
wlog h'' : j ≤ i,
refine ⟨i - j, nat.sub_pos_of_lt (lt_of_le_of_ne h'' ne.symm), mul_right_injective (x^j) _⟩,
rw [mul_one, ← pow_add, ← a_eq, nat.add_sub_cancel' h''],
end
lemma exists_nsmul_eq_zero (a : A) : is_of_fin_add_order a :=
begin
rcases exists_pow_eq_one (multiplicative.of_add a) with ⟨i, hi1, hi2⟩,
refine ⟨i, hi1, multiplicative.of_add.injective _⟩,
rw [add_left_iterate, of_add_zero, of_add_eq_one, add_zero],
exact (is_periodic_pt_mul_iff_pow_eq_one (multiplicative.of_add a)).mp hi2,
end
attribute [to_additive exists_nsmul_eq_zero] exists_pow_eq_one
lemma add_order_of_le_card_univ : add_order_of a ≤ fintype.card A :=
finset.le_card_of_inj_on_range (• a)
(assume n _, finset.mem_univ _)
(assume i hi j hj, nsmul_injective_of_lt_add_order_of a hi hj)
@[to_additive add_order_of_le_card_univ]
lemma order_of_le_card_univ : order_of x ≤ fintype.card G :=
finset.le_card_of_inj_on_range ((^) x)
(assume n _, finset.mem_univ _)
(assume i hi j hj, pow_injective_of_lt_order_of x hi hj)
/-- This is the same as `add_order_of_pos' but with one fewer explicit assumption since this is
automatic in case of a finite cancellative additive monoid.-/
lemma add_order_of_pos (a : A) : 0 < add_order_of a := add_order_of_pos' (exists_nsmul_eq_zero _)
/-- This is the same as `order_of_pos' but with one fewer explicit assumption since this is
automatic in case of a finite cancellative monoid.-/
@[to_additive add_order_of_pos]
lemma order_of_pos (x : G) : 0 < order_of x := order_of_pos' (exists_pow_eq_one x)
open nat
/-- This is the same as `add_order_of_nsmul'` and `add_order_of_nsmul` but with one assumption less
which is automatic in the case of a finite cancellative additive monoid. -/
lemma add_order_of_nsmul (a : A) :
add_order_of (n • a) = add_order_of a / gcd (add_order_of a) n :=
add_order_of_nsmul'' _ _ (exists_nsmul_eq_zero _)
/-- This is the same as `order_of_pow'` and `order_of_pow''` but with one assumption less which is
automatic in the case of a finite cancellative monoid.-/
@[to_additive add_order_of_nsmul]
lemma order_of_pow (x : G) :
order_of (x ^ n) = order_of x / gcd (order_of x) n := order_of_pow'' _ _ (exists_pow_eq_one _)
lemma mem_multiples_iff_mem_range_add_order_of [decidable_eq A] :
b ∈ add_submonoid.multiples a ↔
b ∈ (finset.range (add_order_of a)).image ((• a) : ℕ → A) :=
finset.mem_range_iff_mem_finset_range_of_mod_eq' (add_order_of_pos a)
(assume i, nsmul_eq_mod_add_order_of.symm)
@[to_additive mem_multiples_iff_mem_range_add_order_of]
lemma mem_powers_iff_mem_range_order_of [decidable_eq G] :
y ∈ submonoid.powers x ↔ y ∈ (finset.range (order_of x)).image ((^) x : ℕ → G) :=
finset.mem_range_iff_mem_finset_range_of_mod_eq' (order_of_pos x)
(assume i, pow_eq_mod_order_of.symm)
noncomputable instance decidable_multiples [decidable_eq A] :
decidable_pred (∈ add_submonoid.multiples a) :=
begin
assume b,
apply decidable_of_iff' (b ∈ (finset.range (add_order_of a)).image (• a)),
exact mem_multiples_iff_mem_range_add_order_of,
end
@[to_additive decidable_multiples]
noncomputable instance decidable_powers [decidable_eq G] :
decidable_pred (∈ submonoid.powers x) :=
begin
assume y,
apply decidable_of_iff'
(y ∈ (finset.range (order_of x)).image ((^) x)),
exact mem_powers_iff_mem_range_order_of
end
/-- The equivalence between `fin (order_of x)` and `submonoid.powers x`, sending `i` to `x ^ i`. -/
noncomputable def fin_equiv_powers (x : G) :
fin (order_of x) ≃ (submonoid.powers x : set G) :=
equiv.of_bijective (λ n, ⟨x ^ ↑n, ⟨n, rfl⟩⟩) ⟨λ ⟨i, hi⟩ ⟨j, hj⟩ ij,
subtype.mk_eq_mk.2 (pow_injective_of_lt_order_of x hi hj (subtype.mk_eq_mk.1 ij)),
λ ⟨_, i, rfl⟩, ⟨⟨i % order_of x, mod_lt i (order_of_pos x)⟩, subtype.eq pow_eq_mod_order_of.symm⟩⟩
/-- The equivalence between `fin (add_order_of a)` and `add_submonoid.multiples a`,
sending `i` to `i • a`."-/
noncomputable def fin_equiv_multiples (a : A) :
fin (add_order_of a) ≃ (add_submonoid.multiples a : set A) :=
fin_equiv_powers (multiplicative.of_add a)
attribute [to_additive fin_equiv_multiples] fin_equiv_powers
@[simp] lemma fin_equiv_powers_apply {x : G} {n : fin (order_of x)} :
fin_equiv_powers x n = ⟨x ^ ↑n, n, rfl⟩ := rfl
@[simp] lemma fin_equiv_multiples_apply {a : A} {n : fin (add_order_of a)} :
fin_equiv_multiples a n = ⟨nsmul ↑n a, n, rfl⟩ := rfl
attribute [to_additive fin_equiv_multiples_apply] fin_equiv_powers_apply
@[simp] lemma fin_equiv_powers_symm_apply (x : G) (n : ℕ)
{hn : ∃ (m : ℕ), x ^ m = x ^ n} :
((fin_equiv_powers x).symm ⟨x ^ n, hn⟩) = ⟨n % order_of x, nat.mod_lt _ (order_of_pos x)⟩ :=
by rw [equiv.symm_apply_eq, fin_equiv_powers_apply, subtype.mk_eq_mk,
pow_eq_mod_order_of, fin.coe_mk]
@[simp] lemma fin_equiv_multiples_symm_apply (a : A) (n : ℕ)
{hn : ∃ (m : ℕ), m • a = n • a} :
((fin_equiv_multiples a).symm ⟨n • a, hn⟩) =
⟨n % add_order_of a, nat.mod_lt _ (add_order_of_pos a)⟩ :=
fin_equiv_powers_symm_apply (multiplicative.of_add a) n
attribute [to_additive fin_equiv_multiples_symm_apply] fin_equiv_powers_symm_apply
/-- The equivalence between `submonoid.powers` of two elements `x, y` of the same order, mapping
`x ^ i` to `y ^ i`. -/
noncomputable def powers_equiv_powers (h : order_of x = order_of y) :
(submonoid.powers x : set G) ≃ (submonoid.powers y : set G) :=
(fin_equiv_powers x).symm.trans ((fin.cast h).to_equiv.trans (fin_equiv_powers y))
/-- The equivalence between `submonoid.multiples` of two elements `a, b` of the same additive order,
mapping `i • a` to `i • b`. -/
noncomputable def multiples_equiv_multiples (h : add_order_of a = add_order_of b) :
(add_submonoid.multiples a : set A) ≃ (add_submonoid.multiples b : set A) :=
(fin_equiv_multiples a).symm.trans ((fin.cast h).to_equiv.trans (fin_equiv_multiples b))
attribute [to_additive multiples_equiv_multiples] powers_equiv_powers
@[simp]
lemma powers_equiv_powers_apply (h : order_of x = order_of y)
(n : ℕ) : powers_equiv_powers h ⟨x ^ n, n, rfl⟩ = ⟨y ^ n, n, rfl⟩ :=
begin
rw [powers_equiv_powers, equiv.trans_apply, equiv.trans_apply,
fin_equiv_powers_symm_apply, ← equiv.eq_symm_apply, fin_equiv_powers_symm_apply],
simp [h]
end
@[simp]
lemma multiples_equiv_multiples_apply (h : add_order_of a = add_order_of b)
(n : ℕ) : multiples_equiv_multiples h ⟨n • a, n, rfl⟩ = ⟨n • b, n, rfl⟩ :=
powers_equiv_powers_apply h n
attribute [to_additive multiples_equiv_multiples_apply] powers_equiv_powers_apply
lemma order_eq_card_powers [decidable_eq G] :
order_of x = fintype.card (submonoid.powers x : set G) :=
(fintype.card_fin (order_of x)).symm.trans (fintype.card_eq.2 ⟨fin_equiv_powers x⟩)
lemma add_order_of_eq_card_multiples [decidable_eq A] :
add_order_of a = fintype.card (add_submonoid.multiples a : set A) :=
(fintype.card_fin (add_order_of a)).symm.trans (fintype.card_eq.2 ⟨fin_equiv_multiples a⟩)
attribute [to_additive add_order_of_eq_card_multiples] order_eq_card_powers
end finite_cancel_monoid
section finite_group
variables [group G] [add_group A]
lemma exists_gpow_eq_one (x : G) : ∃ (i : ℤ) (H : i ≠ 0), x ^ (i : ℤ) = 1 :=
--lemma exists_gpow_eq_one (a : α) : ∃ (i : ℤ) (H : i ≠ 0), a ^ (i : ℤ) = 1 :=
begin
rcases exists_pow_eq_one x with ⟨w, hw1, hw2⟩,
refine ⟨w, int.coe_nat_ne_zero.mpr (ne_of_gt hw1), _⟩,
rw gpow_coe_nat,
exact (is_periodic_pt_mul_iff_pow_eq_one _).mp hw2,
end
lemma exists_gsmul_eq_zero (a : A) : ∃ (i : ℤ) (H : i ≠ 0), i • a = 0 :=
@exists_gpow_eq_one (multiplicative A) _ _ a
attribute [to_additive] exists_gpow_eq_one
lemma mem_multiples_iff_mem_gmultiples :
b ∈ add_submonoid.multiples a ↔ b ∈ add_subgroup.gmultiples a :=
⟨λ ⟨n, hn⟩, ⟨n, by simp * at *⟩, λ ⟨i, hi⟩, ⟨(i % add_order_of a).nat_abs,
by { simp only [nsmul_eq_smul] at hi ⊢,
rwa [← gsmul_coe_nat,
int.nat_abs_of_nonneg (int.mod_nonneg _ (int.coe_nat_ne_zero_iff_pos.2
(add_order_of_pos a))), ← gsmul_eq_mod_add_order_of] } ⟩⟩
open subgroup
@[to_additive mem_multiples_iff_mem_gmultiples]
lemma mem_powers_iff_mem_gpowers : y ∈ submonoid.powers x ↔ y ∈ gpowers x :=
⟨λ ⟨n, hn⟩, ⟨n, by simp * at *⟩,
λ ⟨i, hi⟩, ⟨(i % order_of x).nat_abs,
by rwa [← gpow_coe_nat, int.nat_abs_of_nonneg (int.mod_nonneg _
(int.coe_nat_ne_zero_iff_pos.2 (order_of_pos x))),
← gpow_eq_mod_order_of]⟩⟩
lemma multiples_eq_gmultiples (a : A) :
(add_submonoid.multiples a : set A) = add_subgroup.gmultiples a :=
set.ext $ λ y, mem_multiples_iff_mem_gmultiples
@[to_additive multiples_eq_gmultiples]
lemma powers_eq_gpowers (x : G) : (submonoid.powers x : set G) = gpowers x :=
set.ext $ λ x, mem_powers_iff_mem_gpowers
lemma mem_gmultiples_iff_mem_range_add_order_of [decidable_eq A] :
b ∈ add_subgroup.gmultiples a ↔ b ∈ (finset.range (add_order_of a)).image (• a) :=
by rw [← mem_multiples_iff_mem_gmultiples, mem_multiples_iff_mem_range_add_order_of]
@[to_additive mem_gmultiples_iff_mem_range_add_order_of]
lemma mem_gpowers_iff_mem_range_order_of [decidable_eq G] :
y ∈ subgroup.gpowers x ↔ y ∈ (finset.range (order_of x)).image ((^) x : ℕ → G) :=
by rw [← mem_powers_iff_mem_gpowers, mem_powers_iff_mem_range_order_of]
noncomputable instance decidable_gmultiples [decidable_eq A] :
decidable_pred (∈ add_subgroup.gmultiples a) :=
begin
simp_rw ←set_like.mem_coe,
rw ← multiples_eq_gmultiples,
exact decidable_multiples,
end
@[to_additive decidable_gmultiples]
noncomputable instance decidable_gpowers [decidable_eq G] :
decidable_pred (∈ subgroup.gpowers x) :=
begin
simp_rw ←set_like.mem_coe,
rw ← powers_eq_gpowers,
exact decidable_powers,
end
/-- The equivalence between `fin (order_of x)` and `subgroup.gpowers x`, sending `i` to `x ^ i`. -/
noncomputable def fin_equiv_gpowers (x : G) :
fin (order_of x) ≃ (subgroup.gpowers x : set G) :=
(fin_equiv_powers x).trans (equiv.set.of_eq (powers_eq_gpowers x))
/-- The equivalence between `fin (add_order_of a)` and `subgroup.gmultiples a`,
sending `i` to `i • a`. -/
noncomputable def fin_equiv_gmultiples (a : A) :
fin (add_order_of a) ≃ (add_subgroup.gmultiples a : set A) :=
fin_equiv_gpowers (multiplicative.of_add a)
attribute [to_additive fin_equiv_gmultiples] fin_equiv_gpowers
@[simp] lemma fin_equiv_gpowers_apply {n : fin (order_of x)} :
fin_equiv_gpowers x n = ⟨x ^ (n : ℕ), n, gpow_coe_nat x n⟩ := rfl
@[simp] lemma fin_equiv_gmultiples_apply {n : fin (add_order_of a)} :
fin_equiv_gmultiples a n = ⟨(n : ℕ) • a, n, gsmul_coe_nat a n⟩ :=
fin_equiv_gpowers_apply
attribute [to_additive fin_equiv_gmultiples_apply] fin_equiv_gpowers_apply
@[simp] lemma fin_equiv_gpowers_symm_apply (x : G) (n : ℕ)
{hn : ∃ (m : ℤ), x ^ m = x ^ n} :
((fin_equiv_gpowers x).symm ⟨x ^ n, hn⟩) = ⟨n % order_of x, nat.mod_lt _ (order_of_pos x)⟩ :=
by { rw [fin_equiv_gpowers, equiv.symm_trans_apply, equiv.set.of_eq_symm_apply],
exact fin_equiv_powers_symm_apply x n }
@[simp] lemma fin_equiv_gmultiples_symm_apply (a : A) (n : ℕ)
{hn : ∃ (m : ℤ), m • a = n • a} :
((fin_equiv_gmultiples a).symm ⟨n • a, hn⟩) =
⟨n % add_order_of a, nat.mod_lt _ (add_order_of_pos a)⟩ :=
fin_equiv_gpowers_symm_apply (multiplicative.of_add a) n
attribute [to_additive fin_equiv_gmultiples_symm_apply] fin_equiv_gpowers_symm_apply
/-- The equivalence between `subgroup.gpowers` of two elements `x, y` of the same order, mapping
`x ^ i` to `y ^ i`. -/
noncomputable def gpowers_equiv_gpowers (h : order_of x = order_of y) :
(subgroup.gpowers x : set G) ≃ (subgroup.gpowers y : set G) :=
(fin_equiv_gpowers x).symm.trans ((fin.cast h).to_equiv.trans (fin_equiv_gpowers y))
/-- The equivalence between `subgroup.gmultiples` of two elements `a, b` of the same additive order,
mapping `i • a` to `i • b`. -/
noncomputable def gmultiples_equiv_gmultiples (h : add_order_of a = add_order_of b) :
(add_subgroup.gmultiples a : set A) ≃ (add_subgroup.gmultiples b : set A) :=
(fin_equiv_gmultiples a).symm.trans ((fin.cast h).to_equiv.trans (fin_equiv_gmultiples b))
attribute [to_additive gmultiples_equiv_gmultiples] gpowers_equiv_gpowers
@[simp]
lemma gpowers_equiv_gpowers_apply (h : order_of x = order_of y)
(n : ℕ) : gpowers_equiv_gpowers h ⟨x ^ n, n, gpow_coe_nat x n⟩ = ⟨y ^ n, n, gpow_coe_nat y n⟩ :=
begin
rw [gpowers_equiv_gpowers, equiv.trans_apply, equiv.trans_apply,
fin_equiv_gpowers_symm_apply, ← equiv.eq_symm_apply, fin_equiv_gpowers_symm_apply],
simp [h]
end
@[simp]
lemma gmultiples_equiv_gmultiples_apply (h : add_order_of a = add_order_of b) (n : ℕ) :
gmultiples_equiv_gmultiples h ⟨n • a, n, gsmul_coe_nat a n⟩ = ⟨n • b, n, gsmul_coe_nat b n⟩ :=
gpowers_equiv_gpowers_apply h n
attribute [to_additive gmultiples_equiv_gmultiples_apply] gpowers_equiv_gpowers_apply
lemma order_eq_card_gpowers [decidable_eq G] :
order_of x = fintype.card (subgroup.gpowers x : set G) :=
(fintype.card_fin (order_of x)).symm.trans (fintype.card_eq.2 ⟨fin_equiv_gpowers x⟩)
lemma add_order_eq_card_gmultiples [decidable_eq A] :
add_order_of a = fintype.card (add_subgroup.gmultiples a : set A) :=
(fintype.card_fin (add_order_of a)).symm.trans (fintype.card_eq.2 ⟨fin_equiv_gmultiples a⟩)
attribute [to_additive add_order_eq_card_gmultiples] order_eq_card_gpowers
open quotient_group
/- TODO: use cardinal theory, introduce `card : set G → ℕ`, or setup decidability for cosets -/
lemma order_of_dvd_card_univ : order_of x ∣ fintype.card G :=
begin
classical,
have ft_prod : fintype (quotient (gpowers x) × (gpowers x)),
from fintype.of_equiv G group_equiv_quotient_times_subgroup,
have ft_s : fintype (gpowers x),
from @fintype.prod_right _ _ _ ft_prod _,
have ft_cosets : fintype (quotient (gpowers x)),
from @fintype.prod_left _ _ _ ft_prod ⟨⟨1, (gpowers x).one_mem⟩⟩,
have eq₁ : fintype.card G = @fintype.card _ ft_cosets * @fintype.card _ ft_s,
from calc fintype.card G = @fintype.card _ ft_prod :
@fintype.card_congr _ _ _ ft_prod group_equiv_quotient_times_subgroup
... = @fintype.card _ (@prod.fintype _ _ ft_cosets ft_s) :
congr_arg (@fintype.card _) $ subsingleton.elim _ _
... = @fintype.card _ ft_cosets * @fintype.card _ ft_s :
@fintype.card_prod _ _ ft_cosets ft_s,
have eq₂ : order_of x = @fintype.card _ ft_s,
from calc order_of x = _ : order_eq_card_gpowers
... = _ : congr_arg (@fintype.card _) $ subsingleton.elim _ _,
exact dvd.intro (@fintype.card (quotient (subgroup.gpowers x)) ft_cosets)
(by rw [eq₁, eq₂, mul_comm])
end
lemma add_order_of_dvd_card_univ : add_order_of a ∣ fintype.card A :=
begin
rw ← order_of_of_add_eq_add_order_of,
exact order_of_dvd_card_univ,
end
attribute [to_additive add_order_of_dvd_card_univ] order_of_dvd_card_univ
@[simp] lemma pow_card_eq_one : x ^ fintype.card G = 1 :=
let ⟨m, hm⟩ := @order_of_dvd_card_univ _ x _ _ in
by simp [hm, pow_mul, pow_order_of_eq_one]
@[simp] lemma card_nsmul_eq_zero {a : A} : fintype.card A • a = 0 :=
begin
apply multiplicative.of_add.injective,
rw [of_add_nsmul, of_add_zero],
exact pow_card_eq_one,
end
@[to_additive nsmul_eq_mod_card] lemma pow_eq_mod_card (n : ℕ) :
x ^ n = x ^ (n % fintype.card G) :=
by rw [pow_eq_mod_order_of, ←nat.mod_mod_of_dvd n order_of_dvd_card_univ,
← pow_eq_mod_order_of]
@[to_additive] lemma gpow_eq_mod_card (n : ℤ) :
x ^ n = x ^ (n % fintype.card G) :=
by by rw [gpow_eq_mod_order_of, ← int.mod_mod_of_dvd n (int.coe_nat_dvd.2 order_of_dvd_card_univ),
← gpow_eq_mod_order_of]
attribute [to_additive card_nsmul_eq_zero] pow_card_eq_one
/-- If `gcd(|G|,n)=1` then the `n`th power map is a bijection -/
@[simps] def pow_coprime (h : nat.coprime (fintype.card G) n) : G ≃ G :=
{ to_fun := λ g, g ^ n,
inv_fun := λ g, g ^ (nat.gcd_b (fintype.card G) n),
left_inv := λ g, by
{ have key : g ^ _ = g ^ _ := congr_arg (λ n : ℤ, g ^ n) (nat.gcd_eq_gcd_ab (fintype.card G) n),
rwa [gpow_add, gpow_mul, gpow_mul, gpow_coe_nat, gpow_coe_nat, gpow_coe_nat,
h.gcd_eq_one, pow_one, pow_card_eq_one, one_gpow, one_mul, eq_comm] at key },
right_inv := λ g, by
{ have key : g ^ _ = g ^ _ := congr_arg (λ n : ℤ, g ^ n) (nat.gcd_eq_gcd_ab (fintype.card G) n),
rwa [gpow_add, gpow_mul, gpow_mul', gpow_coe_nat, gpow_coe_nat, gpow_coe_nat,
h.gcd_eq_one, pow_one, pow_card_eq_one, one_gpow, one_mul, eq_comm] at key } }
@[simp] lemma pow_coprime_one (h : nat.coprime (fintype.card G) n) : pow_coprime h 1 = 1 :=
one_pow n
@[simp] lemma pow_coprime_inv (h : nat.coprime (fintype.card G) n) {g : G} :
pow_coprime h g⁻¹ = (pow_coprime h g)⁻¹ :=
inv_pow g n
lemma inf_eq_bot_of_coprime {G : Type*} [group G] {H K : subgroup G} [fintype H] [fintype K]
(h : nat.coprime (fintype.card H) (fintype.card K)) : H ⊓ K = ⊥ :=
begin
refine (H ⊓ K).eq_bot_iff_forall.mpr (λ x hx, _),
rw [←order_of_eq_one_iff, ←nat.dvd_one, ←h.gcd_eq_one, nat.dvd_gcd_iff],
exact ⟨(congr_arg (∣ fintype.card H) (order_of_subgroup ⟨x, hx.1⟩)).mpr order_of_dvd_card_univ,
(congr_arg (∣ fintype.card K) (order_of_subgroup ⟨x, hx.2⟩)).mpr order_of_dvd_card_univ⟩,
end
variable (a)
lemma image_range_add_order_of [decidable_eq A] :
finset.image (λ i, i • a) (finset.range (add_order_of a)) =
(add_subgroup.gmultiples a : set A).to_finset :=
by {ext x, rw [set.mem_to_finset, set_like.mem_coe, mem_gmultiples_iff_mem_range_add_order_of] }
/-- TODO: Generalise to `submonoid.powers`.-/
@[to_additive image_range_add_order_of]
lemma image_range_order_of [decidable_eq G] :
finset.image (λ i, x ^ i) (finset.range (order_of x)) = (gpowers x : set G).to_finset :=
by { ext x, rw [set.mem_to_finset, set_like.mem_coe, mem_gpowers_iff_mem_range_order_of] }
lemma gcd_nsmul_card_eq_zero_iff : n • a = 0 ↔ (gcd n (fintype.card A)) • a = 0 :=
⟨λ h, gcd_nsmul_eq_zero _ h $ card_nsmul_eq_zero,
λ h, let ⟨m, hm⟩ := gcd_dvd_left n (fintype.card A) in
by rw [hm, mul_comm, mul_nsmul, h, nsmul_zero]⟩
/-- TODO: Generalise to `finite_cancel_monoid`. -/
@[to_additive gcd_nsmul_card_eq_zero_iff]
lemma pow_gcd_card_eq_one_iff : x ^ n = 1 ↔ x ^ (gcd n (fintype.card G)) = 1 :=
⟨λ h, pow_gcd_eq_one _ h $ pow_card_eq_one,
λ h, let ⟨m, hm⟩ := gcd_dvd_left n (fintype.card G) in
by rw [hm, pow_mul, h, one_pow]⟩
end finite_group
end fintype
section pow_is_subgroup
/-- A nonempty idempotent subset of a finite cancellative monoid is a submonoid -/
def submonoid_of_idempotent {M : Type*} [left_cancel_monoid M] [fintype M] (S : set M)
(hS1 : S.nonempty) (hS2 : S * S = S) : submonoid M :=
have pow_mem : ∀ a : M, a ∈ S → ∀ n : ℕ, a ^ (n + 1) ∈ S :=
λ a ha, nat.rec (by rwa [zero_add, pow_one])
(λ n ih, (congr_arg2 (∈) (pow_succ a (n + 1)).symm hS2).mp (set.mul_mem_mul ha ih)),
{ carrier := S,
one_mem' := by {
obtain ⟨a, ha⟩ := hS1,
rw [←pow_order_of_eq_one a, ←nat.sub_add_cancel (order_of_pos a)],
exact pow_mem a ha (order_of a - 1) },
mul_mem' := λ a b ha hb, (congr_arg2 (∈) rfl hS2).mp (set.mul_mem_mul ha hb) }
/-- A nonempty idempotent subset of a finite group is a subgroup -/
def subgroup_of_idempotent {G : Type*} [group G] [fintype G] (S : set G)
(hS1 : S.nonempty) (hS2 : S * S = S) : subgroup G :=
{ carrier := S,
inv_mem' := λ a ha, by {
rw [←one_mul a⁻¹, ←pow_one a, ←pow_order_of_eq_one a, ←pow_sub a (order_of_pos a)],
exact (submonoid_of_idempotent S hS1 hS2).pow_mem ha (order_of a - 1) },
.. submonoid_of_idempotent S hS1 hS2 }
/-- If `S` is a nonempty subset of a finite group `G`, then `S ^ |G|` is a subgroup -/
def pow_card_subgroup {G : Type*} [group G] [fintype G] (S : set G) (hS : S.nonempty) :
subgroup G :=
have one_mem : (1 : G) ∈ (S ^ fintype.card G) := by
{ obtain ⟨a, ha⟩ := hS,
rw ← pow_card_eq_one,
exact set.pow_mem_pow ha (fintype.card G) },
subgroup_of_idempotent (S ^ (fintype.card G)) ⟨1, one_mem⟩ begin
classical,
refine (set.eq_of_subset_of_card_le
(λ b hb, (congr_arg (∈ _) (one_mul b)).mp (set.mul_mem_mul one_mem hb)) (ge_of_eq _)).symm,
change _ = fintype.card (_ * _ : set G),
rw [←pow_add, group.card_pow_eq_card_pow_card_univ S (fintype.card G) le_rfl,
group.card_pow_eq_card_pow_card_univ S (fintype.card G + fintype.card G) le_add_self],
end
end pow_is_subgroup
|
dd869bfd3b3566995c51b5d53c1f5d1b2a39703d | 2cf781335f4a6706b7452ab07ce323201e2e101f | /lean/deps/typed_smt2/src/galois/smt2/symbol.lean | f57b9fc12d2f999540b17837ac1d66da8e028c66 | [
"Apache-2.0"
] | permissive | simonjwinwood/reopt-vcg | 697cdd5e68366b5aa3298845eebc34fc97ccfbe2 | 6aca24e759bff4f2230bb58270bac6746c13665e | refs/heads/master | 1,586,353,878,347 | 1,549,667,148,000 | 1,549,667,148,000 | 159,409,828 | 0 | 0 | null | 1,543,358,444,000 | 1,543,358,444,000 | null | UTF-8 | Lean | false | false | 12,553 | lean | import galois.logic
import galois.category.except
import galois.data.fin
import galois.data.buffer
meta def exact_trivial_tac : tactic unit := `[exact trivial]
-- Defines the SMT symbol type
namespace smt2
------------------------------------------------------------------------
-- reserved_words
/--
This is the list of reserved words in SMTLIB.
TODO: Add all commands in Section 3.9
-/
def reserved_words : list string :=
[ "BINARY"
, "DECIMAL"
, "HEXADECIMAL"
, "NUMERAL"
, "STRING"
, "_"
, "!"
, "as"
, "let"
, "exists"
, "forall"
, "match"
, "par"
, "assert"
, "check-sat"
, "declare-const"
, "declare-fun"
, "define-fun"
]
--- Reserved words as a list of character buffers.
def reserved_words_buffer : list char_buffer := reserved_words.map string.to_char_buffer
structure reserved_word :=
(buffer : char_buffer)
(proof : buffer ∈ reserved_words_buffer)
--- Predicate that holds if buffer is a reserved word.
def is_reserved_word (b:char_buffer) : Prop :=
b ∈ reserved_words_buffer
namespace is_reserved_word
local attribute [reducible] is_reserved_word
instance decidable : decidable_pred is_reserved_word := by apply_instance
end is_reserved_word
namespace reserved_word
protected def of_buffer (b:char_buffer) (p:is_reserved_word b) : reserved_word := ⟨b, p⟩
protected def repr (w:reserved_word) : string := w.buffer.to_string
instance has_repr : has_repr reserved_word := ⟨reserved_word.repr⟩
/--
Construct a reserved word from a character buffer using the decidability of reserved word membership.
-/
def of_string (s:string) (p:as_true (s ∈ reserved_words) . exact_trivial_tac) : reserved_word :=
let q : s.to_char_buffer ∈ reserved_words_buffer :=
begin
simp [reserved_words_buffer],
apply (Exists.intro s),
simp [of_as_true p],
end in
⟨s.to_char_buffer, q⟩
end reserved_word
------------------------------------------------------------------------
-- is_printable
/-- Predicate that holds if character is considered an SMTLIB printable character. -/
def is_printable (c:char) : Prop := 0x20 ≤ c.val ∧ c.val ≠ 127
namespace is_printable
local attribute [reducible] is_printable
instance decidable_is_printable (c:char) : decidable (is_printable c) := by apply_instance
end is_printable
theorem alpha_is_printable {c:char} : c.is_alpha → is_printable c :=
begin
unfold char.is_alpha, unfold is_printable,
intro isa,
cases isa;
{
simp [char.is_upper, char.is_lower] at isa,
apply and.intro,
{ transitivity, tactic.swap, exact isa.left, exact dec_trivial, },
{ intro eq,
simp [eq] at isa,
exact of_as_false isa trivial,
}
},
end
theorem digit_is_printable {c:char} : c.is_digit → is_printable c :=
begin
unfold char.is_digit, unfold is_printable,
intro isd,
apply and.intro,
{ transitivity, tactic.swap, exact isd.left, exact dec_trivial, },
{ intro eq,
simp [eq] at isd,
exact of_as_false isd trivial,
},
end
------------------------------------------------------------------------
-- is_legal
/-- Legal characters are either printable characters or whitespace. -/
def is_legal (c:char) : Prop := is_printable c ∨ c ∈ ['\t', '\n', '\x0d']
namespace is_legal
local attribute [reducible] is_legal
instance is_legal_decidable (c:char) : decidable (is_legal c) := by apply_instance
end is_legal
------------------------------------------------------------------------
-- symbol
namespace symbol
/-- Check character is allowed in a symbol. -/
def is_symbol_char (c:char) : Prop := is_legal c ∧ c ∉ ['|', '\\']
namespace is_symbol_char
local attribute [reducible] is_symbol_char
instance decidable : decidable_pred is_symbol_char := by apply_instance
end is_symbol_char
/-- A simple symbol character is a quoted symbol. -/
theorem digit_is_symbol_char {c:char}
: char.is_digit c → is_symbol_char c :=
begin
intro h,
unfold is_symbol_char,
unfold is_legal,
apply and.intro,
exact or.inl (digit_is_printable h),
{ intro p, simp at p,
cases p; simp only [p] at h; exact (of_as_false h trivial),
},
end
/-- Check all characters in buffer can appear in quoted symbols. -/
def is_symbol (b:char_buffer) : Prop
:= ∀(i: fin b.size), is_symbol_char (b.read i)
namespace is_symbol
local attribute [reducible] is_symbol
instance decidable : decidable_pred is_symbol := by apply_instance
end is_symbol
end symbol
/-- A symbol is used to identify function or sort names. -/
structure symbol :=
(to_char_buffer : char_buffer)
(valid : symbol.is_symbol to_char_buffer)
namespace symbol
instance decidable_eq : decidable_eq symbol := by tactic.mk_dec_eq_instance
--- Reflexive lexicographic ordering of symbols.
protected def le (x y : symbol) : Prop := x.to_char_buffer ≤ y.to_char_buffer
instance : has_le symbol := ⟨symbol.le⟩
instance decidable_le
: Π(x y : symbol), decidable (x ≤ y)
| ⟨m,a⟩ ⟨n,b⟩ :=
begin
simp [has_le.le, symbol.le],
apply_instance,
end
--- Strict lexicographic ordering of symbols.
protected def lt (x y : symbol) : Prop := x.to_char_buffer < y.to_char_buffer
instance : has_lt symbol := ⟨symbol.lt⟩
instance decidable_lt
: Π(x y : symbol), decidable (x < y)
| ⟨m,a⟩ ⟨n,b⟩ :=
begin
simp [has_lt.lt, symbol.lt],
apply_instance,
end
/- Sizeof always returns a number greater than 0. -/
theorem sizeof_gt0 (s:symbol) : symbol.sizeof s > 0 :=
begin
cases s,
dsimp [symbol.sizeof],
exact dec_trivial,
end
section simple_symbols
/-- Symbol characters allowed in simple symbols -/
def simple_char_symbols : list char :=
['~', '!', '@', '$', '%', '^', '&', '*', '_', '-', '+', '=', '<', '>', '.', '?', '/' ]
/-- Predicate that checks if character is allowed in a simple symbol. -/
inductive is_simple_symbol_char (c:char) : Prop
| is_alpha : char.is_alpha c → is_simple_symbol_char
| is_digit : char.is_digit c → is_simple_symbol_char
| is_other : c ∈ simple_char_symbols → is_simple_symbol_char
-- Show is_simple_symbol_char is decidable.
open is_simple_symbol_char
open decidable
instance is_simple_symbol_char.decidable : decidable_pred is_simple_symbol_char
| c :=
if f : c.is_alpha then
is_true (is_alpha f)
else if g : c.is_digit then
is_true (is_digit g)
else if h : c ∈ simple_char_symbols then
is_true (is_other h)
else
is_false begin intro p, cases p; contradiction, end
/-- A simple symbol character is a quoted symbol. -/
theorem is_simple_symbol_char.is_symbol_char {c:char}
: is_simple_symbol_char c → is_symbol_char c :=
begin
intro h,
cases h,
case is_simple_symbol_char.is_alpha : h {
unfold is_symbol_char,
unfold is_legal,
apply and.intro,
exact or.inl (alpha_is_printable h),
{ intro p, simp at p,
cases p; simp only [p] at h; exact (of_as_false h trivial),
},
},
case is_simple_symbol_char.is_digit : h {
exact digit_is_symbol_char h,
},
case is_simple_symbol_char.is_other : h {
simp [simple_char_symbols] at h,
-- Try all characters and show they are allowed.
iterate { cases h, simp only [h], exact (of_as_true trivial), },
},
end
/-- Return true if this is a valid simple symbol. -/
def is_simple_symbol (b:char_buffer) : Prop
:= b ≠ buffer.nil
∧ ¬(is_reserved_word b)
∧ ∀(i: fin b.size),
let c := b.read i
in is_simple_symbol_char c ∧ (i.val = 0 → ¬(c.is_digit))
local attribute [reducible] is_simple_symbol
instance is_simple_symbol.decidable : decidable_pred is_simple_symbol := by apply_instance
end simple_symbols
------------------------------------------------------------------------
-- repr
section repr
/-- Render a symbol as a simple symbol is possible and quoted symbol otherwise. -/
protected
def repr (s:symbol) : string :=
if is_simple_symbol s.to_char_buffer then
s.to_char_buffer.to_string
else
"|" ++ s.to_char_buffer.to_string ++ "|"
instance : has_repr symbol := ⟨symbol.repr⟩
end repr
------------------------------------------------------------------------
-- Parsing
section parsing
theorem simple_symbol_is_symbol {b:char_buffer} : is_simple_symbol b → is_symbol b := do
begin
simp [is_simple_symbol, is_symbol],
intros is_not_nil is_not_reserved char_pred,
intro i,
let p : is_simple_symbol_char (buffer.read b i) := (char_pred i).left,
exact (is_simple_symbol_char.is_symbol_char p),
end
/--
A quoted symbol with the form "|???|" where '???' denotes
a list of legal characters '|' and '\\'.
-/
def is_quoted_symbol (b:char_buffer) : Prop
:= b.size ≥ 2
∧ ∀(i: fin b.size),
if i.val = 0 ∨ i.val = b.size - 1 then
b.read i = '|'
else
is_symbol_char (b.read i)
theorem is_quoted_symbol.size_ok {b:char_buffer} : is_quoted_symbol b → 1 ≤ b.size - 1 :=
begin
intro is_sym,
apply nat.le_sub_right_of_add_le,
dsimp [nat.add_succ],
dsimp [is_quoted_symbol] at is_sym,
exact is_sym.left,
end
theorem is_quoted_symbol.symbol_ok {b:char_buffer} (is_sym:is_quoted_symbol b)
: is_symbol (b.slice 1 (b.size - 1) (is_quoted_symbol.size_ok is_sym)) :=
begin
dsimp [is_symbol],
intro i,
cases i with i i_lt,
simp only [buffer.read_slice],
--simp [buffer.size_slice] at i_lt,
have i_p_1 : 1 + i < b.size := buffer.slice_index_bound ⟨i, i_lt⟩,
-- Introduce forall constraint
have q := is_sym.right ⟨1 + i, i_p_1⟩,
have pr : ¬(1 + i = 0) := by simp,
have min_le : buffer.size b - 1 ≤ buffer.size b := by apply nat.sub_le_self,
have sz_pos : b.size > 0 :=
calc b.size ≥ 2 : is_sym.left
... > 0 : of_as_true trivial,
have qr : ¬(1 + i= buffer.size b - 1),
{ intro q,
simp [buffer.size_slice, min_eq_left min_le] at i_lt,
simp only [nat.lt_sub_left_iff_add_lt, q] at i_lt,
simp [nat.succ_add, nat.sub_succ, nat.succ_pred_eq_of_pos sz_pos, lt_irrefl] at i_lt,
exact i_lt,
},
simp only [fin.val, pr, qr, false_or, if_false] at q,
exact q,
end
local attribute [reducible] is_quoted_symbol
instance is_quoted_symbol.decidable : decidable_pred is_quoted_symbol := by apply_instance
/- This parses the string as a symbol -/
protected
def parse (s:string) : except string symbol := do
let b := s.to_char_buffer,
if pr:is_quoted_symbol b then
pure ⟨ b.slice 1 (b.size - 1) (is_quoted_symbol.size_ok pr)
, is_quoted_symbol.symbol_ok pr
⟩
else if p:is_simple_symbol b then
pure ⟨b, simple_symbol_is_symbol p⟩
else
throw "Invalid symbol"
end parsing
-- meta constant eval_expr (α : Type u) [reflected α] : expr → tactic α
/- Return the value given a proof the result is ok -/
def is_ok_value : Π{e:except string symbol}, except.is_ok e → string
| (except.error l) p := false.elim p
| (except.ok r) p := r.to_char_buffer.to_string
/- Construct a symbol from a string literal. -/
def of_string (nm:string) (p : (symbol.parse nm).is_ok . exact_trivial_tac) : symbol := p.value
axiom by_reflection (α:Prop) : α
/- This generate a symbol from a string using a tactic that runs in the VM. -/
meta def vm_string_tac (s:string) : tactic unit := do
match symbol.parse s with
| (except.error e) :=
tactic.fail e
| (except.ok sym) :=
let r : expr := sym.to_char_buffer.to_string.reflect in
tactic.exact `(smt2.symbol.mk (string.to_char_buffer %%r) (by_reflection _))
end
theorem is_symbol_append {x y : char_buffer}
: is_symbol x → is_symbol y → is_symbol (x ++ y) :=
begin
unfold is_symbol,
intros p q i,
simp only [buffer.read_append],
apply (dite (i.val < buffer.size x)),
{ intro i_lt,
simp [i_lt],
exact (p _),
},
{ intro i_ge,
simp [i_ge],
exact (q _),
}
end
protected def append : symbol → symbol → symbol
| ⟨x,p⟩ ⟨y,q⟩ := ⟨x ++ y, is_symbol_append p q⟩
instance : has_append symbol := ⟨symbol.append⟩
theorem is_symbol_nat (v : ℕ) : is_symbol (string.to_char_buffer (repr v)) :=
begin
unfold is_symbol,
intro i_fin,
cases i_fin with i i_lt,
simp only [buffer.read_to_nth_le],
simp only [repr, has_repr.repr, nat.repr],
simp only [buffer.to_char_buffer_as_string],
simp only [buffer.to_list_to_buffer],
simp only [list.nth_le_reverse_simp],
simp only [list.nth_le_map'],
apply digit_is_symbol_char,
apply char.digit_char_is_digit,
exact (nat.nth_to_digits_is_lt (of_as_true trivial) _),
end
/- Construct a symbol from a string literal. -/
def of_nat (v : ℕ) : symbol := ⟨string.to_char_buffer (repr v), is_symbol_nat v⟩
end symbol
end smt2
|
49e949feee3ec4c7ce63046e61e817291d234bc0 | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/topology/continuous_function/stone_weierstrass.lean | 4d8ecabec58db9e7f718f682159067b38dd73418 | [
"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 | 20,952 | lean | /-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison, Heather Macbeth
-/
import topology.continuous_function.weierstrass
import data.is_R_or_C.basic
/-!
# The Stone-Weierstrass theorem
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
If a subalgebra `A` of `C(X, ℝ)`, where `X` is a compact topological space,
separates points, then it is dense.
We argue as follows.
* In any subalgebra `A` of `C(X, ℝ)`, if `f ∈ A`, then `abs f ∈ A.topological_closure`.
This follows from the Weierstrass approximation theorem on `[-‖f‖, ‖f‖]` by
approximating `abs` uniformly thereon by polynomials.
* This ensures that `A.topological_closure` is actually a sublattice:
if it contains `f` and `g`, then it contains the pointwise supremum `f ⊔ g`
and the pointwise infimum `f ⊓ g`.
* Any nonempty sublattice `L` of `C(X, ℝ)` which separates points is dense,
by a nice argument approximating a given `f` above and below using separating functions.
For each `x y : X`, we pick a function `g x y ∈ L` so `g x y x = f x` and `g x y y = f y`.
By continuity these functions remain close to `f` on small patches around `x` and `y`.
We use compactness to identify a certain finitely indexed infimum of finitely indexed supremums
which is then close to `f` everywhere, obtaining the desired approximation.
* Finally we put these pieces together. `L = A.topological_closure` is a nonempty sublattice
which separates points since `A` does, and so is dense (in fact equal to `⊤`).
We then prove the complex version for self-adjoint subalgebras `A`, by separately approximating
the real and imaginary parts using the real subalgebra of real-valued functions in `A`
(which still separates points, by taking the norm-square of a separating function).
## Future work
Extend to cover the case of subalgebras of the continuous functions vanishing at infinity,
on non-compact spaces.
-/
noncomputable theory
namespace continuous_map
variables {X : Type*} [topological_space X] [compact_space X]
open_locale polynomial
/--
Turn a function `f : C(X, ℝ)` into a continuous map into `set.Icc (-‖f‖) (‖f‖)`,
thereby explicitly attaching bounds.
-/
def attach_bound (f : C(X, ℝ)) : C(X, set.Icc (-‖f‖) (‖f‖)) :=
{ to_fun := λ x, ⟨f x, ⟨neg_norm_le_apply f x, apply_le_norm f x⟩⟩ }
@[simp] lemma attach_bound_apply_coe (f : C(X, ℝ)) (x : X) : ((attach_bound f) x : ℝ) = f x := rfl
lemma polynomial_comp_attach_bound (A : subalgebra ℝ C(X, ℝ)) (f : A) (g : ℝ[X]) :
(g.to_continuous_map_on (set.Icc (-‖f‖) ‖f‖)).comp (f : C(X, ℝ)).attach_bound =
polynomial.aeval f g :=
begin
ext,
simp only [continuous_map.coe_comp, function.comp_app,
continuous_map.attach_bound_apply_coe,
polynomial.to_continuous_map_on_apply,
polynomial.aeval_subalgebra_coe,
polynomial.aeval_continuous_map_apply,
polynomial.to_continuous_map_apply],
end
/--
Given a continuous function `f` in a subalgebra of `C(X, ℝ)`, postcomposing by a polynomial
gives another function in `A`.
This lemma proves something slightly more subtle than this:
we take `f`, and think of it as a function into the restricted target `set.Icc (-‖f‖) ‖f‖)`,
and then postcompose with a polynomial function on that interval.
This is in fact the same situation as above, and so also gives a function in `A`.
-/
lemma polynomial_comp_attach_bound_mem (A : subalgebra ℝ C(X, ℝ)) (f : A) (g : ℝ[X]) :
(g.to_continuous_map_on (set.Icc (-‖f‖) ‖f‖)).comp (f : C(X, ℝ)).attach_bound ∈ A :=
begin
rw polynomial_comp_attach_bound,
apply set_like.coe_mem,
end
theorem comp_attach_bound_mem_closure
(A : subalgebra ℝ C(X, ℝ)) (f : A) (p : C(set.Icc (-‖f‖) (‖f‖), ℝ)) :
p.comp (attach_bound f) ∈ A.topological_closure :=
begin
-- `p` itself is in the closure of polynomials, by the Weierstrass theorem,
have mem_closure : p ∈ (polynomial_functions (set.Icc (-‖f‖) (‖f‖))).topological_closure :=
continuous_map_mem_polynomial_functions_closure _ _ p,
-- and so there are polynomials arbitrarily close.
have frequently_mem_polynomials := mem_closure_iff_frequently.mp mem_closure,
-- To prove `p.comp (attached_bound f)` is in the closure of `A`,
-- we show there are elements of `A` arbitrarily close.
apply mem_closure_iff_frequently.mpr,
-- To show that, we pull back the polynomials close to `p`,
refine ((comp_right_continuous_map ℝ (attach_bound (f : C(X, ℝ)))).continuous_at p).tendsto
.frequently_map _ _ frequently_mem_polynomials,
-- but need to show that those pullbacks are actually in `A`.
rintros _ ⟨g, ⟨-,rfl⟩⟩,
simp only [set_like.mem_coe, alg_hom.coe_to_ring_hom, comp_right_continuous_map_apply,
polynomial.to_continuous_map_on_alg_hom_apply],
apply polynomial_comp_attach_bound_mem,
end
theorem abs_mem_subalgebra_closure (A : subalgebra ℝ C(X, ℝ)) (f : A) :
(f : C(X, ℝ)).abs ∈ A.topological_closure :=
begin
let M := ‖f‖,
let f' := attach_bound (f : C(X, ℝ)),
let abs : C(set.Icc (-‖f‖) (‖f‖), ℝ) :=
{ to_fun := λ x : set.Icc (-‖f‖) (‖f‖), |(x : ℝ)| },
change (abs.comp f') ∈ A.topological_closure,
apply comp_attach_bound_mem_closure,
end
theorem inf_mem_subalgebra_closure (A : subalgebra ℝ C(X, ℝ)) (f g : A) :
(f : C(X, ℝ)) ⊓ (g : C(X, ℝ)) ∈ A.topological_closure :=
begin
rw inf_eq,
refine A.topological_closure.smul_mem
(A.topological_closure.sub_mem
(A.topological_closure.add_mem (A.le_topological_closure f.property)
(A.le_topological_closure g.property)) _) _,
exact_mod_cast abs_mem_subalgebra_closure A _,
end
theorem inf_mem_closed_subalgebra (A : subalgebra ℝ C(X, ℝ)) (h : is_closed (A : set C(X, ℝ)))
(f g : A) : (f : C(X, ℝ)) ⊓ (g : C(X, ℝ)) ∈ A :=
begin
convert inf_mem_subalgebra_closure A f g,
apply set_like.ext',
symmetry,
erw closure_eq_iff_is_closed,
exact h,
end
theorem sup_mem_subalgebra_closure (A : subalgebra ℝ C(X, ℝ)) (f g : A) :
(f : C(X, ℝ)) ⊔ (g : C(X, ℝ)) ∈ A.topological_closure :=
begin
rw sup_eq,
refine A.topological_closure.smul_mem
(A.topological_closure.add_mem
(A.topological_closure.add_mem (A.le_topological_closure f.property)
(A.le_topological_closure g.property)) _) _,
exact_mod_cast abs_mem_subalgebra_closure A _,
end
theorem sup_mem_closed_subalgebra (A : subalgebra ℝ C(X, ℝ)) (h : is_closed (A : set C(X, ℝ)))
(f g : A) : (f : C(X, ℝ)) ⊔ (g : C(X, ℝ)) ∈ A :=
begin
convert sup_mem_subalgebra_closure A f g,
apply set_like.ext',
symmetry,
erw closure_eq_iff_is_closed,
exact h,
end
open_locale topology
-- Here's the fun part of Stone-Weierstrass!
theorem sublattice_closure_eq_top
(L : set C(X, ℝ)) (nA : L.nonempty)
(inf_mem : ∀ f g ∈ L, f ⊓ g ∈ L) (sup_mem : ∀ f g ∈ L, f ⊔ g ∈ L)
(sep : L.separates_points_strongly) :
closure L = ⊤ :=
begin
-- We start by boiling down to a statement about close approximation.
apply eq_top_iff.mpr,
rintros f -,
refine filter.frequently.mem_closure
((filter.has_basis.frequently_iff metric.nhds_basis_ball).mpr (λ ε pos, _)),
simp only [exists_prop, metric.mem_ball],
-- It will be helpful to assume `X` is nonempty later,
-- so we get that out of the way here.
by_cases nX : nonempty X,
swap,
exact ⟨nA.some, (dist_lt_iff pos).mpr (λ x, false.elim (nX ⟨x⟩)), nA.some_spec⟩,
/-
The strategy now is to pick a family of continuous functions `g x y` in `A`
with the property that `g x y x = f x` and `g x y y = f y`
(this is immediate from `h : separates_points_strongly`)
then use continuity to see that `g x y` is close to `f` near both `x` and `y`,
and finally using compactness to produce the desired function `h`
as a maximum over finitely many `x` of a minimum over finitely many `y` of the `g x y`.
-/
dsimp only [set.separates_points_strongly] at sep,
choose g hg w₁ w₂ using sep f,
-- For each `x y`, we define `U x y` to be `{z | f z - ε < g x y z}`,
-- and observe this is a neighbourhood of `y`.
let U : X → X → set X := λ x y, {z | f z - ε < g x y z},
have U_nhd_y : ∀ x y, U x y ∈ 𝓝 y,
{ intros x y,
refine is_open.mem_nhds _ _,
{ apply is_open_lt; continuity, },
{ rw [set.mem_set_of_eq, w₂],
exact sub_lt_self _ pos, }, },
-- Fixing `x` for a moment, we have a family of functions `λ y, g x y`
-- which on different patches (the `U x y`) are greater than `f z - ε`.
-- Taking the supremum of these functions
-- indexed by a finite collection of patches which cover `X`
-- will give us an element of `A` that is globally greater than `f z - ε`
-- and still equal to `f x` at `x`.
-- Since `X` is compact, for every `x` there is some finset `ys t`
-- so the union of the `U x y` for `y ∈ ys x` still covers everything.
let ys : Π x, finset X := λ x, (compact_space.elim_nhds_subcover (U x) (U_nhd_y x)).some,
let ys_w : ∀ x, (⋃ y ∈ ys x, U x y) = ⊤ :=
λ x, (compact_space.elim_nhds_subcover (U x) (U_nhd_y x)).some_spec,
have ys_nonempty : ∀ x, (ys x).nonempty :=
λ x, set.nonempty_of_union_eq_top_of_nonempty _ _ nX (ys_w x),
-- Thus for each `x` we have the desired `h x : A` so `f z - ε < h x z` everywhere
-- and `h x x = f x`.
let h : Π x, L := λ x,
⟨(ys x).sup' (ys_nonempty x) (λ y, (g x y : C(X, ℝ))),
finset.sup'_mem _ sup_mem _ _ _ (λ y _, hg x y)⟩,
have lt_h : ∀ x z, f z - ε < h x z,
{ intros x z,
obtain ⟨y, ym, zm⟩ := set.exists_set_mem_of_union_eq_top _ _ (ys_w x) z,
dsimp [h],
simp only [coe_fn_coe_base', subtype.coe_mk, sup'_coe, finset.sup'_apply, finset.lt_sup'_iff],
exact ⟨y, ym, zm⟩ },
have h_eq : ∀ x, h x x = f x,
{ intro x, simp [coe_fn_coe_base', w₁], },
-- For each `x`, we define `W x` to be `{z | h x z < f z + ε}`,
let W : Π x, set X := λ x, {z | h x z < f z + ε},
-- This is still a neighbourhood of `x`.
have W_nhd : ∀ x, W x ∈ 𝓝 x,
{ intros x,
refine is_open.mem_nhds _ _,
{ apply is_open_lt; continuity, },
{ dsimp only [W, set.mem_set_of_eq],
rw h_eq,
exact lt_add_of_pos_right _ pos}, },
-- Since `X` is compact, there is some finset `ys t`
-- so the union of the `W x` for `x ∈ xs` still covers everything.
let xs : finset X := (compact_space.elim_nhds_subcover W W_nhd).some,
let xs_w : (⋃ x ∈ xs, W x) = ⊤ :=
(compact_space.elim_nhds_subcover W W_nhd).some_spec,
have xs_nonempty : xs.nonempty := set.nonempty_of_union_eq_top_of_nonempty _ _ nX xs_w,
-- Finally our candidate function is the infimum over `x ∈ xs` of the `h x`.
-- This function is then globally less than `f z + ε`.
let k : (L : Type*) :=
⟨xs.inf' xs_nonempty (λ x, (h x : C(X, ℝ))),
finset.inf'_mem _ inf_mem _ _ _ (λ x _, (h x).2)⟩,
refine ⟨k.1, _, k.2⟩,
-- We just need to verify the bound, which we do pointwise.
rw dist_lt_iff pos,
intro z,
-- We rewrite into this particular form,
-- so that simp lemmas about inequalities involving `finset.inf'` can fire.
rw [(show ∀ a b ε : ℝ, dist a b < ε ↔ a < b + ε ∧ b - ε < a,
by { intros, simp only [← metric.mem_ball, real.ball_eq_Ioo, set.mem_Ioo, and_comm], })],
fsplit,
{ dsimp [k],
simp only [finset.inf'_lt_iff, continuous_map.inf'_apply],
exact set.exists_set_mem_of_union_eq_top _ _ xs_w z, },
{ dsimp [k],
simp only [finset.lt_inf'_iff, continuous_map.inf'_apply],
intros x xm,
apply lt_h, },
end
/--
The **Stone-Weierstrass Approximation Theorem**,
that a subalgebra `A` of `C(X, ℝ)`, where `X` is a compact topological space,
is dense if it separates points.
-/
theorem subalgebra_topological_closure_eq_top_of_separates_points
(A : subalgebra ℝ C(X, ℝ)) (w : A.separates_points) :
A.topological_closure = ⊤ :=
begin
-- The closure of `A` is closed under taking `sup` and `inf`,
-- and separates points strongly (since `A` does),
-- so we can apply `sublattice_closure_eq_top`.
apply set_like.ext',
let L := A.topological_closure,
have n : set.nonempty (L : set C(X, ℝ)) :=
⟨(1 : C(X, ℝ)), A.le_topological_closure A.one_mem⟩,
convert sublattice_closure_eq_top
(L : set C(X, ℝ)) n
(λ f fm g gm, inf_mem_closed_subalgebra L A.is_closed_topological_closure ⟨f, fm⟩ ⟨g, gm⟩)
(λ f fm g gm, sup_mem_closed_subalgebra L A.is_closed_topological_closure ⟨f, fm⟩ ⟨g, gm⟩)
(subalgebra.separates_points.strongly
(subalgebra.separates_points_monotone (A.le_topological_closure) w)),
{ simp, },
end
/--
An alternative statement of the Stone-Weierstrass theorem.
If `A` is a subalgebra of `C(X, ℝ)` which separates points (and `X` is compact),
every real-valued continuous function on `X` is a uniform limit of elements of `A`.
-/
theorem continuous_map_mem_subalgebra_closure_of_separates_points
(A : subalgebra ℝ C(X, ℝ)) (w : A.separates_points)
(f : C(X, ℝ)) :
f ∈ A.topological_closure :=
begin
rw subalgebra_topological_closure_eq_top_of_separates_points A w,
simp,
end
/--
An alternative statement of the Stone-Weierstrass theorem,
for those who like their epsilons.
If `A` is a subalgebra of `C(X, ℝ)` which separates points (and `X` is compact),
every real-valued continuous function on `X` is within any `ε > 0` of some element of `A`.
-/
theorem exists_mem_subalgebra_near_continuous_map_of_separates_points
(A : subalgebra ℝ C(X, ℝ)) (w : A.separates_points)
(f : C(X, ℝ)) (ε : ℝ) (pos : 0 < ε) :
∃ (g : A), ‖(g : C(X, ℝ)) - f‖ < ε :=
begin
have w := mem_closure_iff_frequently.mp
(continuous_map_mem_subalgebra_closure_of_separates_points A w f),
rw metric.nhds_basis_ball.frequently_iff at w,
obtain ⟨g, H, m⟩ := w ε pos,
rw [metric.mem_ball, dist_eq_norm] at H,
exact ⟨⟨g, m⟩, H⟩,
end
/--
An alternative statement of the Stone-Weierstrass theorem,
for those who like their epsilons and don't like bundled continuous functions.
If `A` is a subalgebra of `C(X, ℝ)` which separates points (and `X` is compact),
every real-valued continuous function on `X` is within any `ε > 0` of some element of `A`.
-/
theorem exists_mem_subalgebra_near_continuous_of_separates_points
(A : subalgebra ℝ C(X, ℝ)) (w : A.separates_points)
(f : X → ℝ) (c : continuous f) (ε : ℝ) (pos : 0 < ε) :
∃ (g : A), ∀ x, ‖g x - f x‖ < ε :=
begin
obtain ⟨g, b⟩ := exists_mem_subalgebra_near_continuous_map_of_separates_points A w ⟨f, c⟩ ε pos,
use g,
rwa norm_lt_iff _ pos at b,
end
end continuous_map
section is_R_or_C
open is_R_or_C
-- Redefine `X`, since for the next few lemmas it need not be compact
variables {𝕜 : Type*} {X : Type*} [is_R_or_C 𝕜] [topological_space X]
namespace continuous_map
/-- A real subalgebra of `C(X, 𝕜)` is `conj_invariant`, if it contains all its conjugates. -/
def conj_invariant_subalgebra (A : subalgebra ℝ C(X, 𝕜)) : Prop :=
A.map (conj_ae.to_alg_hom.comp_left_continuous ℝ conj_cle.continuous) ≤ A
lemma mem_conj_invariant_subalgebra {A : subalgebra ℝ C(X, 𝕜)} (hA : conj_invariant_subalgebra A)
{f : C(X, 𝕜)} (hf : f ∈ A) :
(conj_ae.to_alg_hom.comp_left_continuous ℝ conj_cle.continuous) f ∈ A :=
hA ⟨f, hf, rfl⟩
/-- If a set `S` is conjugation-invariant, then its `𝕜`-span is conjugation-invariant. -/
lemma subalgebra_conj_invariant {S : set C(X, 𝕜)}
(hS : ∀ f, f ∈ S → (conj_ae.to_alg_hom.comp_left_continuous ℝ conj_cle.continuous) f ∈ S) :
conj_invariant_subalgebra ((algebra.adjoin 𝕜 S).restrict_scalars ℝ) :=
begin
rintros _ ⟨f, hf, rfl⟩,
change _ ∈ ((algebra.adjoin 𝕜 S).restrict_scalars ℝ),
change _ ∈ ((algebra.adjoin 𝕜 S).restrict_scalars ℝ) at hf,
rw subalgebra.mem_restrict_scalars at hf ⊢,
apply algebra.adjoin_induction hf,
{ exact λ g hg, algebra.subset_adjoin (hS g hg), },
{ exact λ c, subalgebra.algebra_map_mem _ (star_ring_end 𝕜 c) },
{ intros f g hf hg,
convert subalgebra.add_mem _ hf hg,
exact alg_hom.map_add _ f g },
{ intros f g hf hg,
convert subalgebra.mul_mem _ hf hg,
exact alg_hom.map_mul _ f g, }
end
end continuous_map
open continuous_map
/-- If a conjugation-invariant subalgebra of `C(X, 𝕜)` separates points, then the real subalgebra
of its purely real-valued elements also separates points. -/
lemma subalgebra.separates_points.is_R_or_C_to_real {A : subalgebra 𝕜 C(X, 𝕜)}
(hA : A.separates_points) (hA' : conj_invariant_subalgebra (A.restrict_scalars ℝ)) :
((A.restrict_scalars ℝ).comap
(of_real_am.comp_left_continuous ℝ continuous_of_real)).separates_points :=
begin
intros x₁ x₂ hx,
-- Let `f` in the subalgebra `A` separate the points `x₁`, `x₂`
obtain ⟨_, ⟨f, hfA, rfl⟩, hf⟩ := hA hx,
let F : C(X, 𝕜) := f - const _ (f x₂),
-- Subtract the constant `f x₂` from `f`; this is still an element of the subalgebra
have hFA : F ∈ A,
{ refine A.sub_mem hfA (@eq.subst _ (∈ A) _ _ _ $ A.smul_mem A.one_mem $ f x₂),
ext1, simp only [coe_smul, coe_one, pi.smul_apply,
pi.one_apply, algebra.id.smul_eq_mul, mul_one, const_apply] },
-- Consider now the function `λ x, |f x - f x₂| ^ 2`
refine ⟨_, ⟨(⟨is_R_or_C.norm_sq, continuous_norm_sq⟩ : C(𝕜, ℝ)).comp F, _, rfl⟩, _⟩,
{ -- This is also an element of the subalgebra, and takes only real values
rw [set_like.mem_coe, subalgebra.mem_comap],
convert (A.restrict_scalars ℝ).mul_mem (mem_conj_invariant_subalgebra hA' hFA) hFA,
ext1,
rw [mul_comm],
exact (is_R_or_C.mul_conj _).symm },
{ -- And it also separates the points `x₁`, `x₂`
have : f x₁ - f x₂ ≠ 0 := sub_ne_zero.mpr hf,
simpa only [comp_apply, coe_sub, coe_const, pi.sub_apply,
coe_mk, sub_self, map_zero, ne.def, norm_sq_eq_zero] using this },
end
variables [compact_space X]
/--
The Stone-Weierstrass approximation theorem, `is_R_or_C` version,
that a subalgebra `A` of `C(X, 𝕜)`, where `X` is a compact topological space and `is_R_or_C 𝕜`,
is dense if it is conjugation-invariant and separates points.
-/
theorem continuous_map.subalgebra_is_R_or_C_topological_closure_eq_top_of_separates_points
(A : subalgebra 𝕜 C(X, 𝕜)) (hA : A.separates_points)
(hA' : conj_invariant_subalgebra (A.restrict_scalars ℝ)) :
A.topological_closure = ⊤ :=
begin
rw algebra.eq_top_iff,
-- Let `I` be the natural inclusion of `C(X, ℝ)` into `C(X, 𝕜)`
let I : C(X, ℝ) →ₗ[ℝ] C(X, 𝕜) := of_real_clm.comp_left_continuous ℝ X,
-- The main point of the proof is that its range (i.e., every real-valued function) is contained
-- in the closure of `A`
have key : I.range ≤ (A.to_submodule.restrict_scalars ℝ).topological_closure,
{ -- Let `A₀` be the subalgebra of `C(X, ℝ)` consisting of `A`'s purely real elements; it is the
-- preimage of `A` under `I`. In this argument we only need its submodule structure.
let A₀ : submodule ℝ C(X, ℝ) := (A.to_submodule.restrict_scalars ℝ).comap I,
-- By `subalgebra.separates_points.complex_to_real`, this subalgebra also separates points, so
-- we may apply the real Stone-Weierstrass result to it.
have SW : A₀.topological_closure = ⊤,
{ have := subalgebra_topological_closure_eq_top_of_separates_points _
(hA.is_R_or_C_to_real hA'),
exact congr_arg subalgebra.to_submodule this },
rw [← submodule.map_top, ← SW],
-- So it suffices to prove that the image under `I` of the closure of `A₀` is contained in the
-- closure of `A`, which follows by abstract nonsense
have h₁ := A₀.topological_closure_map ((@of_real_clm 𝕜 _).comp_left_continuous_compact X),
have h₂ := (A.to_submodule.restrict_scalars ℝ).map_comap_le I,
exact h₁.trans (submodule.topological_closure_mono h₂) },
-- In particular, for a function `f` in `C(X, 𝕜)`, the real and imaginary parts of `f` are in the
-- closure of `A`
intros f,
let f_re : C(X, ℝ) := (⟨is_R_or_C.re, is_R_or_C.re_clm.continuous⟩ : C(𝕜, ℝ)).comp f,
let f_im : C(X, ℝ) := (⟨is_R_or_C.im, is_R_or_C.im_clm.continuous⟩ : C(𝕜, ℝ)).comp f,
have h_f_re : I f_re ∈ A.topological_closure := key ⟨f_re, rfl⟩,
have h_f_im : I f_im ∈ A.topological_closure := key ⟨f_im, rfl⟩,
-- So `f_re + I • f_im` is in the closure of `A`
convert A.topological_closure.add_mem h_f_re (A.topological_closure.smul_mem h_f_im is_R_or_C.I),
-- And this, of course, is just `f`
ext,
apply eq.symm,
simp [I, mul_comm is_R_or_C.I _],
end
end is_R_or_C
|
c308d51b152c65f24ab51f9c8bc0db97341ecdd0 | 0845ae2ca02071debcfd4ac24be871236c01784f | /library/init/lean/level.lean | a46408df5ff6e1ffbda23c5d246797fe82bfafac | [
"Apache-2.0"
] | permissive | GaloisInc/lean4 | 74c267eb0e900bfaa23df8de86039483ecbd60b7 | 228ddd5fdcd98dd4e9c009f425284e86917938aa | refs/heads/master | 1,643,131,356,301 | 1,562,715,572,000 | 1,562,715,572,000 | 192,390,898 | 0 | 0 | null | 1,560,792,750,000 | 1,560,792,749,000 | null | UTF-8 | Lean | false | false | 4,645 | lean | /-
Copyright (c) 2018 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
prelude
import init.data.option.basic init.lean.name init.lean.format
namespace Lean
inductive Level
| zero : Level
| succ : Level → Level
| max : Level → Level → Level
| imax : Level → Level → Level
| Param : Name → Level
| mvar : Name → Level
attribute [extern "level_mk_succ"] Level.succ
attribute [extern "level_mk_max"] Level.max
attribute [extern "level_mk_imax"] Level.imax
attribute [extern "level_mk_param"] Level.Param
attribute [extern "level_mk_mvar"] Level.mvar
instance levelIsInhabited : Inhabited Level :=
⟨Level.zero⟩
def Level.one : Level := Level.succ Level.zero
def Level.hasParam : Level → Bool
| (Level.Param _) := true
| (Level.succ l) := Level.hasParam l
| (Level.max l₁ l₂) := Level.hasParam l₁ || Level.hasParam l₂
| (Level.imax l₁ l₂) := Level.hasParam l₁ || Level.hasParam l₂
| _ := false
def Level.hasMvar : Level → Bool
| (Level.mvar _) := true
| (Level.succ l) := Level.hasParam l
| (Level.max l₁ l₂) := Level.hasParam l₁ || Level.hasParam l₂
| (Level.imax l₁ l₂) := Level.hasParam l₁ || Level.hasParam l₂
| _ := false
def Level.ofNat : Nat → Level
| 0 := Level.zero
| (n+1) := Level.succ (Level.ofNat n)
def Nat.imax (n m : Nat) : Nat :=
if m = 0 then 0 else Nat.max n m
def Level.toNat : Level → Option Nat
| Level.zero := some 0
| (Level.succ l) := Nat.succ <$> Level.toNat l
| (Level.max l₁ l₂) := Nat.max <$> Level.toNat l₁ <*> Level.toNat l₂
| (Level.imax l₁ l₂) := Nat.imax <$> Level.toNat l₁ <*> Level.toNat l₂
| _ := none
def Level.toOffset : Level → Level × Nat
| Level.zero := (Level.zero, 0)
| (Level.succ l) := let (l', k) := Level.toOffset l; (l', k+1)
| l := (l, 0)
def Level.instantiate (s : Name → Option Level) : Level → Level
| Level.zero := Level.zero
| (Level.succ l) := Level.succ (Level.instantiate l)
| (Level.max l₁ l₂) := Level.max (Level.instantiate l₁) (Level.instantiate l₂)
| (Level.imax l₁ l₂) := Level.imax (Level.instantiate l₁) (Level.instantiate l₂)
| l@(Level.Param n) :=
match s n with
| some l' => l'
| none => l
| l := l
@[extern "lean_level_hash"]
constant Level.hash (n : @& Level) : USize := default USize
/- Level to Format -/
namespace LevelToFormat
inductive Result
| leaf : Format → Result
| num : Nat → Result
| offset : Result → Nat → Result
| maxNode : List Result → Result
| imaxNode : List Result → Result
def Result.succ : Result → Result
| (Result.offset f k) := Result.offset f (k+1)
| (Result.num k) := Result.num (k+1)
| f := Result.offset f 1
def Result.max : Result → Result → Result
| f (Result.maxNode Fs) := Result.maxNode (f::Fs)
| f₁ f₂ := Result.maxNode [f₁, f₂]
def Result.imax : Result → Result → Result
| f (Result.imaxNode Fs) := Result.imaxNode (f::Fs)
| f₁ f₂ := Result.imaxNode [f₁, f₂]
def parenIfFalse : Format → Bool → Format
| f true := f
| f false := f.paren
@[specialize] private def formatLst (fmt : Result → Format) : List Result → Format
| [] := Format.nil
| (r::rs) := Format.line ++ fmt r ++ formatLst rs
partial def Result.format : Result → Bool → Format
| (Result.leaf f) _ := f
| (Result.num k) _ := toString k
| (Result.offset f 0) r := Result.format f r
| (Result.offset f (k+1)) r :=
let f' := Result.format f false;
parenIfFalse (f' ++ "+" ++ fmt (k+1)) r
| (Result.maxNode fs) r := parenIfFalse (Format.group $ "max" ++ formatLst (fun r => Result.format r false) fs) r
| (Result.imaxNode fs) r := parenIfFalse (Format.group $ "imax" ++ formatLst (fun r => Result.format r false) fs) r
def Level.toResult : Level → Result
| Level.zero := Result.num 0
| (Level.succ l) := Result.succ (Level.toResult l)
| (Level.max l₁ l₂) := Result.max (Level.toResult l₁) (Level.toResult l₂)
| (Level.imax l₁ l₂) := Result.imax (Level.toResult l₁) (Level.toResult l₂)
| (Level.Param n) := Result.leaf (fmt n)
| (Level.mvar n) := Result.leaf (fmt n)
def Level.format (l : Level) : Format :=
(Level.toResult l).format true
instance levelHasFormat : HasFormat Level := ⟨Level.format⟩
instance levelHasToString : HasToString Level := ⟨Format.pretty ∘ Level.format⟩
end LevelToFormat
end Lean
|
41f3650390221e40d2230c7fc8b6f90b2ecdd4a7 | ad0c7d243dc1bd563419e2767ed42fb323d7beea | /analysis/normed_space.lean | 13ec6eb8d8ff61044f6853001f8afefc19414d0d | [
"Apache-2.0"
] | permissive | sebzim4500/mathlib | e0b5a63b1655f910dee30badf09bd7e191d3cf30 | 6997cafbd3a7325af5cb318561768c316ceb7757 | refs/heads/master | 1,585,549,958,618 | 1,538,221,723,000 | 1,538,221,723,000 | 150,869,076 | 0 | 0 | Apache-2.0 | 1,538,229,323,000 | 1,538,229,323,000 | null | UTF-8 | Lean | false | false | 11,974 | lean | /-
Copyright (c) 2018 Patrick Massot. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Normed spaces.
Authors: Patrick Massot, Johannes Hölzl
-/
import algebra.pi_instances
import linear_algebra.prod_module
import analysis.nnreal
variables {α : Type*} {β : Type*} {γ : Type*} {ι : Type*}
noncomputable theory
open filter
local notation f `→_{`:50 a `}`:0 b := tendsto f (nhds a) (nhds b)
lemma squeeze_zero {α} {f g : α → ℝ} {t₀ : filter α} (hf : ∀t, 0 ≤ f t) (hft : ∀t, f t ≤ g t)
(g0 : tendsto g t₀ (nhds 0)) : tendsto f t₀ (nhds 0) :=
begin
apply tendsto_of_tendsto_of_tendsto_of_le_of_le (tendsto_const_nhds) g0;
simp [*]; exact filter.univ_mem_sets
end
class has_norm (α : Type*) := (norm : α → ℝ)
export has_norm (norm)
notation `∥`:1024 e:1 `∥`:1 := norm e
class normed_group (α : Type*) extends has_norm α, add_comm_group α, metric_space α :=
(dist_eq : ∀ x y, dist x y = norm (x - y))
section normed_group
variables [normed_group α] [normed_group β]
lemma dist_eq_norm (g h : α) : dist g h = ∥g - h∥ :=
normed_group.dist_eq _ _
@[simp] lemma dist_zero_right (g : α) : dist g 0 = ∥g∥ :=
by { rw[dist_eq_norm], simp }
lemma norm_triangle (g h : α) : ∥g + h∥ ≤ ∥g∥ + ∥h∥ :=
calc ∥g + h∥ = ∥g - (-h)∥ : by simp
... = dist g (-h) : by simp[dist_eq_norm]
... ≤ dist g 0 + dist 0 (-h) : by apply dist_triangle
... = ∥g∥ + ∥h∥ : by simp[dist_eq_norm]
@[simp] lemma norm_nonneg (g : α) : 0 ≤ ∥g∥ :=
by { rw[←dist_zero_right], exact dist_nonneg }
lemma norm_eq_zero (g : α) : ∥g∥ = 0 ↔ g = 0 :=
by { rw[←dist_zero_right], exact dist_eq_zero }
@[simp] lemma norm_zero : ∥(0:α)∥ = 0 := (norm_eq_zero _).2 (by simp)
lemma norm_pos_iff (g : α) : ∥ g ∥ > 0 ↔ g ≠ 0 :=
begin
split ; intro h ; rw[←dist_zero_right] at *,
{ exact dist_pos.1 h },
{ exact dist_pos.2 h }
end
lemma norm_le_zero_iff (g : α) : ∥g∥ ≤ 0 ↔ g = 0 :=
by { rw[←dist_zero_right], exact dist_le_zero }
@[simp] lemma norm_neg (g : α) : ∥-g∥ = ∥g∥ :=
calc ∥-g∥ = ∥0 - g∥ : by simp
... = dist 0 g : (dist_eq_norm 0 g).symm
... = dist g 0 : dist_comm _ _
... = ∥g - 0∥ : (dist_eq_norm g 0)
... = ∥g∥ : by simp
lemma abs_norm_sub_norm_le (g h : α) : abs(∥g∥ - ∥h∥) ≤ ∥g - h∥ :=
abs_le.2 $ and.intro
(suffices -∥g - h∥ ≤ -(∥h∥ - ∥g∥), by simpa,
neg_le_neg $ sub_right_le_of_le_add $
calc ∥h∥ = ∥h - g + g∥ : by simp
... ≤ ∥h - g∥ + ∥g∥ : norm_triangle _ _
... = ∥-(g - h)∥ + ∥g∥ : by simp
... = ∥g - h∥ + ∥g∥ : by { rw [norm_neg (g-h)] })
(sub_right_le_of_le_add $ calc ∥g∥ = ∥g - h + h∥ : by simp ... ≤ ∥g-h∥ + ∥h∥ : norm_triangle _ _)
lemma dist_norm_norm_le (g h : α) : dist ∥g∥ ∥h∥ ≤ ∥g - h∥ :=
abs_norm_sub_norm_le g h
section nnnorm
def nnnorm (a : α) : nnreal := ⟨norm a, norm_nonneg a⟩
@[simp] lemma coe_nnnorm (a : α) : (nnnorm a : ℝ) = norm a := rfl
lemma nndist_eq_nnnorm (a b : α) : nndist a b = nnnorm (a - b) := nnreal.eq $ dist_eq_norm _ _
lemma nnnorm_eq_zero (a : α) : nnnorm a = 0 ↔ a = 0 :=
by simp only [nnreal.eq_iff.symm, nnreal.coe_zero, coe_nnnorm, norm_eq_zero]
@[simp] lemma nnnorm_zero : nnnorm (0 : α) = 0 :=
nnreal.eq norm_zero
lemma nnnorm_triangle (g h : α) : nnnorm (g + h) ≤ nnnorm g + nnnorm h :=
by simpa [nnreal.coe_le] using norm_triangle g h
@[simp] lemma nnnorm_neg (g : α) : nnnorm (-g) = nnnorm g :=
nnreal.eq $ norm_neg g
lemma nndist_nnnorm_nnnorm_le (g h : α) : nndist (nnnorm g) (nnnorm h) ≤ nnnorm (g - h) :=
(nnreal.coe_le _ _).2 $ dist_norm_norm_le g h
end nnnorm
instance prod.normed_group [normed_group β] : normed_group (α × β) :=
{ norm := λx, max ∥x.1∥ ∥x.2∥,
dist_eq := assume (x y : α × β),
show max (dist x.1 y.1) (dist x.2 y.2) = (max ∥(x - y).1∥ ∥(x - y).2∥), by simp [dist_eq_norm] }
lemma norm_fst_le (x : α × β) : ∥x.1∥ ≤ ∥x∥ :=
begin have : ∥x∥ = max (∥x.fst∥) (∥x.snd∥) := rfl, rw this, simp[le_max_left] end
lemma norm_snd_le (x : α × β) : ∥x.2∥ ≤ ∥x∥ :=
begin have : ∥x∥ = max (∥x.fst∥) (∥x.snd∥) := rfl, rw this, simp[le_max_right] end
instance fintype.normed_group {π : α → Type*} [fintype α] [∀i, normed_group (π i)] :
normed_group (Πb, π b) :=
{ norm := λf, ((finset.sup finset.univ (λ b, nnnorm (f b)) : nnreal) : ℝ),
dist_eq := assume x y,
congr_arg (coe : nnreal → ℝ) $ congr_arg (finset.sup finset.univ) $ funext $ assume a,
show nndist (x a) (y a) = nnnorm (x a - y a), from nndist_eq_nnnorm _ _ }
lemma tendsto_iff_norm_tendsto_zero {f : ι → β} {a : filter ι} {b : β} :
tendsto f a (nhds b) ↔ tendsto (λ e, ∥ f e - b ∥) a (nhds 0) :=
by rw tendsto_iff_dist_tendsto_zero ; simp only [(dist_eq_norm _ _).symm]
lemma lim_norm (x : α) : ((λ g, ∥g - x∥) : α → ℝ) →_{x} 0 :=
tendsto_iff_norm_tendsto_zero.1 (continuous_iff_tendsto.1 continuous_id x)
lemma lim_norm_zero : ((λ g, ∥g∥) : α → ℝ) →_{0} 0 :=
by simpa using lim_norm (0:α)
lemma continuous_norm : continuous ((λ g, ∥g∥) : α → ℝ) :=
begin
rw continuous_iff_tendsto,
intro x,
rw tendsto_iff_dist_tendsto_zero,
exact squeeze_zero (λ t, abs_nonneg _) (λ t, abs_norm_sub_norm_le _ _) (lim_norm x)
end
instance normed_top_monoid : topological_add_monoid α :=
⟨continuous_iff_tendsto.2 $ λ ⟨x₁, x₂⟩,
tendsto_iff_norm_tendsto_zero.2
begin
refine squeeze_zero (by simp) _
(by simpa using tendsto_add (lim_norm (x₁, x₂)) (lim_norm (x₁, x₂))),
exact λ ⟨e₁, e₂⟩, calc
∥(e₁ + e₂) - (x₁ + x₂)∥ = ∥(e₁ - x₁) + (e₂ - x₂)∥ : by simp
... ≤ ∥e₁ - x₁∥ + ∥e₂ - x₂∥ : norm_triangle _ _
... ≤ max (∥e₁ - x₁∥) (∥e₂ - x₂∥) + max (∥e₁ - x₁∥) (∥e₂ - x₂∥) :
add_le_add (le_max_left _ _) (le_max_right _ _)
end⟩
instance normed_top_group : topological_add_group α :=
⟨continuous_iff_tendsto.2 $ λ x,
tendsto_iff_norm_tendsto_zero.2 begin
have : ∀ (e : α), ∥-e - -x∥ = ∥e - x∥,
{ intro, simpa using norm_neg (e - x) },
rw funext this, exact lim_norm x,
end⟩
end normed_group
section normed_ring
class normed_ring (α : Type*) extends has_norm α, ring α, metric_space α :=
(dist_eq : ∀ x y, dist x y = norm (x - y))
(norm_mul : ∀ a b, norm (a * b) ≤ norm a * norm b)
instance normed_ring.to_normed_group [β : normed_ring α] : normed_group α := { ..β }
lemma norm_mul {α : Type*} [normed_ring α] (a b : α) : (∥a*b∥) ≤ (∥a∥) * (∥b∥) :=
normed_ring.norm_mul _ _
instance prod.normed_ring [normed_ring α] [normed_ring β] : normed_ring (α × β) :=
{ norm_mul := assume x y,
calc
∥x * y∥ = ∥(x.1*y.1, x.2*y.2)∥ : rfl
... = (max ∥x.1*y.1∥ ∥x.2*y.2∥) : rfl
... ≤ (max (∥x.1∥*∥y.1∥) (∥x.2∥*∥y.2∥)) : max_le_max (norm_mul (x.1) (y.1)) (norm_mul (x.2) (y.2))
... = (max (∥x.1∥*∥y.1∥) (∥y.2∥*∥x.2∥)) : by simp[mul_comm]
... ≤ (max (∥x.1∥) (∥x.2∥)) * (max (∥y.2∥) (∥y.1∥)) : by { apply max_mul_mul_le_max_mul_max; simp [norm_nonneg] }
... = (max (∥x.1∥) (∥x.2∥)) * (max (∥y.1∥) (∥y.2∥)) : by simp[max_comm]
... = (∥x∥*∥y∥) : rfl,
..prod.normed_group }
end normed_ring
section normed_field
class normed_field (α : Type*) extends has_norm α, discrete_field α, metric_space α :=
(dist_eq : ∀ x y, dist x y = norm (x - y))
(norm_mul : ∀ a b, norm (a * b) = norm a * norm b)
instance normed_field.to_normed_ring [i : normed_field α] : normed_ring α :=
{ norm_mul := by finish [i.norm_mul], ..i }
instance : normed_field ℝ :=
{ norm := λ x, abs x,
dist_eq := assume x y, rfl,
norm_mul := abs_mul }
lemma real.norm_eq_abs (r : ℝ): norm r = abs r := rfl
end normed_field
section normed_space
class normed_space (α : out_param $ Type*) (β : Type*) [out_param $ normed_field α]
extends has_norm β , vector_space α β, metric_space β :=
(dist_eq : ∀ x y, dist x y = norm (x - y))
(norm_smul : ∀ a b, norm (a • b) = has_norm.norm a * norm b)
variables [normed_field α]
instance normed_space.to_normed_group [i : normed_space α β] : normed_group β :=
by refine { add := (+),
dist_eq := normed_space.dist_eq,
zero := 0,
neg := λ x, -x,
..i, .. }; simp
instance normed_field.to_normed_space : normed_space α α :=
{ dist_eq := normed_field.dist_eq,
norm_smul := normed_field.norm_mul }
lemma norm_smul [normed_space α β] (s : α) (x : β) : ∥s • x∥ = ∥s∥ * ∥x∥ :=
normed_space.norm_smul _ _
lemma nnnorm_smul [normed_space α β] (s : α) (x : β) : nnnorm (s • x) = nnnorm s * nnnorm x :=
nnreal.eq $ norm_smul s x
variables {E : Type*} {F : Type*} [normed_space α E] [normed_space α F]
lemma tendsto_smul {f : γ → α} { g : γ → F} {e : filter γ} {s : α} {b : F} :
(tendsto f e (nhds s)) → (tendsto g e (nhds b)) → tendsto (λ x, (f x) • (g x)) e (nhds (s • b)) :=
begin
intros limf limg,
rw tendsto_iff_norm_tendsto_zero,
have ineq := λ x : γ, calc
∥f x • g x - s • b∥ = ∥(f x • g x - s • g x) + (s • g x - s • b)∥ : by simp[add_assoc]
... ≤ ∥f x • g x - s • g x∥ + ∥s • g x - s • b∥ : norm_triangle (f x • g x - s • g x) (s • g x - s • b)
... ≤ ∥f x - s∥*∥g x∥ + ∥s∥*∥g x - b∥ : by { rw [←smul_sub, ←sub_smul, norm_smul, norm_smul] },
apply squeeze_zero,
{ intro t, exact norm_nonneg _ },
{ exact ineq },
{ clear ineq,
have limf': tendsto (λ x, ∥f x - s∥) e (nhds 0) := tendsto_iff_norm_tendsto_zero.1 limf,
have limg' : tendsto (λ x, ∥g x∥) e (nhds ∥b∥) := filter.tendsto.comp limg (continuous_iff_tendsto.1 continuous_norm _),
have lim1 : tendsto (λ x, ∥f x - s∥ * ∥g x∥) e (nhds 0),
by simpa using tendsto_mul limf' limg',
have limg3 := tendsto_iff_norm_tendsto_zero.1 limg,
have lim2 : tendsto (λ x, ∥s∥ * ∥g x - b∥) e (nhds 0),
by simpa using tendsto_mul tendsto_const_nhds limg3,
rw [show (0:ℝ) = 0 + 0, by simp],
exact tendsto_add lim1 lim2 }
end
instance : normed_space α (E × F) :=
{ norm_smul :=
begin
intros s x,
cases x with x₁ x₂,
exact calc
∥s • (x₁, x₂)∥ = ∥ (s • x₁, s• x₂)∥ : rfl
... = max (∥s • x₁∥) (∥ s• x₂∥) : rfl
... = max (∥s∥ * ∥x₁∥) (∥s∥ * ∥x₂∥) : by simp [norm_smul s x₁, norm_smul s x₂]
... = ∥s∥ * max (∥x₁∥) (∥x₂∥) : by simp [mul_max_of_nonneg]
end,
add_smul := by simp[add_smul],
-- I have no idea why by simp[smul_add] is not enough for the next goal
smul_add := assume r x y, show (r•(x+y).fst, r•(x+y).snd) = (r•x.fst+r•y.fst, r•x.snd+r•y.snd),
by simp[smul_add],
..prod.normed_group,
..prod.vector_space }
instance fintype.normed_space {ι : Type*} {E : ι → Type*} [fintype ι] [∀i, normed_space α (E i)] :
normed_space α (Πi, E i) :=
{ norm := λf, ((finset.univ.sup (λb, nnnorm (f b)) : nnreal) : ℝ),
dist_eq :=
assume f g, congr_arg coe $ congr_arg (finset.sup finset.univ) $
by funext i; exact nndist_eq_nnnorm _ _,
norm_smul := λ a f,
show (↑(finset.sup finset.univ (λ (b : ι), nnnorm (a • f b))) : ℝ) =
nnnorm a * ↑(finset.sup finset.univ (λ (b : ι), nnnorm (f b))),
by simp only [(nnreal.coe_mul _ _).symm, nnreal.mul_finset_sup, nnnorm_smul],
..metric_space_pi,
..pi.vector_space α }
end normed_space
|
c45233f8dd5105ba26b83b6c87600d688aab549c | 2eab05920d6eeb06665e1a6df77b3157354316ad | /src/data/equiv/ring_aut.lean | 78fa57982e7e012aec65b69f720cc075cf30dfa9 | [
"Apache-2.0"
] | permissive | ayush1801/mathlib | 78949b9f789f488148142221606bf15c02b960d2 | ce164e28f262acbb3de6281b3b03660a9f744e3c | refs/heads/master | 1,692,886,907,941 | 1,635,270,866,000 | 1,635,270,866,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 2,178 | 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_aut
import data.equiv.ring
/-!
# Ring automorphisms
This file defines the automorphism group structure on `ring_aut R := ring_equiv R R`.
## Implementation notes
The definition of multiplication in the automorphism group agrees with function composition,
multiplication in `equiv.perm`, and multiplication in `category_theory.End`, but not with
`category_theory.comp`.
This file is kept separate from `data/equiv/ring` so that `group_theory.perm` is free to use
equivalences (and other files that use them) before the group structure is defined.
## Tags
ring_aut
-/
/-- The group of ring automorphisms. -/
@[reducible] def ring_aut (R : Type*) [has_mul R] [has_add R] := ring_equiv R R
namespace ring_aut
variables (R : Type*) [has_mul R] [has_add R]
/--
The group operation on automorphisms of a ring is defined by
`λ g h, ring_equiv.trans h g`.
This means that multiplication agrees with composition, `(g*h)(x) = g (h x)`.
-/
instance : group (ring_aut R) :=
by refine_struct
{ mul := λ g h, ring_equiv.trans h g,
one := ring_equiv.refl R,
inv := ring_equiv.symm,
div := _,
npow := @npow_rec _ ⟨ring_equiv.refl R⟩ ⟨λ g h, ring_equiv.trans h g⟩,
gpow := @gpow_rec _ ⟨ring_equiv.refl R⟩ ⟨λ g h, ring_equiv.trans h g⟩ ⟨ring_equiv.symm⟩ };
intros; ext; try { refl }; apply equiv.left_inv
instance : inhabited (ring_aut R) := ⟨1⟩
/-- Monoid homomorphism from ring automorphisms to additive automorphisms. -/
def to_add_aut : ring_aut R →* add_aut R :=
by refine_struct { to_fun := ring_equiv.to_add_equiv }; intros; refl
/-- Monoid homomorphism from ring automorphisms to multiplicative automorphisms. -/
def to_mul_aut : ring_aut R →* mul_aut R :=
by refine_struct { to_fun := ring_equiv.to_mul_equiv }; intros; refl
/-- Monoid homomorphism from ring automorphisms to permutations. -/
def to_perm : ring_aut R →* equiv.perm R :=
by refine_struct { to_fun := ring_equiv.to_equiv }; intros; refl
end ring_aut
|
6d71eaaa7cea4d39e0f3701bdcdf2364697bd8ab | fa02ed5a3c9c0adee3c26887a16855e7841c668b | /src/order/category/Preorder.lean | acb9e50172a6c7798ddbc4a9c49da019d17aed29 | [
"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 | 892 | lean | /-
Copyright (c) 2020 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin
-/
import order.preorder_hom
import category_theory.concrete_category
import algebra.punit_instances
/-! # Category of preorders -/
open category_theory
/-- The category of preorders. -/
def Preorder := bundled preorder
namespace Preorder
instance : bundled_hom @preorder_hom :=
{ to_fun := @preorder_hom.to_fun,
id := @preorder_hom.id,
comp := @preorder_hom.comp,
hom_ext := @preorder_hom.ext }
attribute [derive [has_coe_to_sort, large_category, concrete_category]] Preorder
/-- Construct a bundled Preorder from the underlying type and typeclass. -/
def of (α : Type*) [preorder α] : Preorder := bundled.of α
instance : inhabited Preorder := ⟨of punit⟩
instance (α : Preorder) : preorder α := α.str
end Preorder
|
d13c471c3fc1077791ccd70f145700e64263a7a8 | 7cef822f3b952965621309e88eadf618da0c8ae9 | /src/tactic/norm_cast.lean | 22d3d45d9958d885ec745bed44d0a68e361e6144 | [
"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 | 11,862 | 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
Normalizing casts inside expressions.
-/
import tactic.basic tactic.interactive tactic.converter.interactive
import data.buffer.parser
namespace tactic
/--
This is a work around to the fact that in some cases
mk_instance times out instead of failing
example: has_lift_t ℤ ℕ
mk_instance' is used when we assume the type class search
should end instantly
-/
meta def mk_instance' (e : expr) : tactic expr :=
try_for 1000 (mk_instance e)
end tactic
namespace expr
open tactic expr
meta def flip_eq (ty : expr) : tactic (expr × (expr → expr)) :=
do
(a, b) ← is_eq ty,
α ← infer_type a,
new_ty ← to_expr ``(%%b = %%a),
f ← to_expr ``(@eq.symm %%α %%a %%b),
return (new_ty, ⇑f)
meta def flip_iff (ty : expr) : tactic (expr × (expr → expr)) :=
do
(a, b) ← is_iff ty,
new_ty ← to_expr ``(%%b ↔ %%a),
f ← to_expr ``(@iff.symm %%a %%b),
return (new_ty, ⇑f)
end expr
namespace norm_cast
open tactic expr
private meta def new_name (n : name) : name := name.mk_string "reversed" n
private meta def aux_after_set (tac : expr → tactic (expr × (expr → expr))) :
expr → tactic (expr × (expr → expr))
| (pi n bi d b) := do
uniq_n ← mk_fresh_name,
let b' := b.instantiate_var (local_const uniq_n n bi d),
(b', f) ← aux_after_set b',
return $ (
pi n bi d $ b'.abstract_local uniq_n,
λ e, lam n bi d $ ( f $ e (local_const uniq_n n bi d) ).abstract_local uniq_n
)
| ty := tac ty
mk_simp_attribute push_cast "The `push_cast` simp attribute uses `move_cast` lemmas in the \"forward\" direction,
to move casts toward the leaf nodes of the expression."
/-- Called after the `move_cast` attribute is applied to a declaration. -/
private meta def after_set (decl : name) (prio : ℕ) (pers : bool) : tactic unit :=
do
(declaration.thm n l ty e) ← get_decl decl | failed,
let tac := λ ty, (flip_eq ty <|> flip_iff ty),
(ty', f) ← aux_after_set tac ty,
let e' := task.map f e,
let n' := new_name n,
add_decl (declaration.thm n' l ty' e'),
simp_attr.push_cast.set decl () tt
private meta def mk_cache : list name → tactic simp_lemmas :=
monad.foldl simp_lemmas.add_simp simp_lemmas.mk
/--
This is an attribute for simplification rules that are
used to normalize casts.
Let r be = or ↔, then elimination lemmas of the shape
Π ..., P ↑a1 ... ↑an r P a1 ... an should be given the
attribute elim_cast.
-/
@[user_attribute]
meta def elim_cast_attr : user_attribute simp_lemmas :=
{
name := `elim_cast,
descr := "attribute for lemmas of the shape Π ..., P ↑a1 ... ↑an = P a1 ... an",
cache_cfg :=
{ mk_cache := mk_cache,
dependencies := [], },
}
/--
This is an attribute for simplification rules that are
used to normalize casts.
Let r be = or ↔, then compositional lemmas of the shape
Π ..., ↑(P a1 ... an) r P ↑a1 ... ↑an should be given the
attribute move_cast.
-/
@[user_attribute]
meta def move_cast_attr : user_attribute simp_lemmas :=
{
name := `move_cast,
descr := "attribute for lemmas of the shape Π ..., ↑(P a1 ... an) = P ↑a1 ... ↑an",
after_set := some after_set,
cache_cfg :=
{ mk_cache := mk_cache ∘ (list.map new_name),
dependencies := [], },
}
private meta def get_cache : tactic simp_lemmas :=
do
a ← elim_cast_attr.get_cache,
b ← move_cast_attr.get_cache,
return $ simp_lemmas.join a b
/--
This is an attribute for simplification rules of the shape
Π ..., ↑↑a = ↑a or Π ..., ↑a = a.
They are used in a heuristic to infer intermediate casts.
-/
@[user_attribute]
meta def squash_cast_attr : user_attribute simp_lemmas :=
{
name := `squash_cast,
descr := "attribute for lemmas of the shape Π ..., ↑↑a = ↑a",
after_set := none,
cache_cfg := {
mk_cache := monad.foldl simp_lemmas.add_simp simp_lemmas.mk,
dependencies := [],
}
}
/-
This is an auxiliary function that proves e = new_e
using only squash_cast lemmas
-/
private meta def aux_simp (e new_e : expr) : tactic expr :=
do
s ← squash_cast_attr.get_cache,
(e', pr) ← s.rewrite new_e,
is_def_eq e e',
mk_eq_symm pr
/-
This is a supecial function for numerals:
- (1 : α) is rewritten as ((1 : ℕ) : α)
- (0 : α) is rewritten as ((0 : ℕ) : α)
-/
private meta def aux_num (_ : unit) (e : expr) : tactic (unit × expr × expr) :=
match e with
| `(0 : ℕ) := failed
| `(1 : ℕ) := failed
| `(@has_zero.zero %%α %%h) := do
coe_nat ← to_expr ``(has_lift_t ℕ %%α) >>= mk_instance',
new_e ← to_expr ``(@coe ℕ %%α %%coe_nat 0),
pr ← aux_simp e new_e,
return ((), new_e, pr)
| `(@has_one.one %%α %%h) := do
coe_nat ← to_expr ``(has_lift_t ℕ %%α) >>= mk_instance',
new_e ← to_expr ``(@coe ℕ %%α %%coe_nat 1),
pr ← aux_simp e new_e,
return ((), new_e, pr)
| _ := failed
end
/-
This is the main heuristic used alongside the elim_cast and move_cast lemmas.
An expression of the shape: op (↑(x : α) : γ) (↑(y : β) : γ)
is rewritten as: op (↑(↑(x : α) : β) : γ) (↑(y : β) : γ)
when the squash_cast lemmas can prove that (↑(x : α) : γ) = (↑(↑(x : α) : β) : γ)
-/
private meta def heur (_ : unit) (e : expr) : tactic (unit × expr × expr) :=
match e with
| (app (expr.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',
new_x ← to_expr ``(@coe %%β %%δ %%coe2 (@coe %%α %%β %%coe3 %%xx)),
let new_e := app (app op new_x) y,
eq_x ← aux_simp 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',
new_y ← to_expr ``(@coe %%α %%δ %%coe1 (@coe %%β %%α %%coe3 %%yy)),
let new_e := app (app op x) new_y,
eq_y ← aux_simp y new_y,
pr ← mk_congr_arg (app op x) eq_y,
return ((), new_e, pr)
)
| _ := failed
end
/-
simpa is used to discharge proofs
-/
private meta def prove : tactic unit :=
tactic.interactive.simpa none ff [] [] none
private meta def post (s : simp_lemmas) (_ : unit) (e : expr) : tactic (unit × 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)
/-
Core function
-/
meta def derive (e : expr) : tactic (expr × expr) :=
do
s ← get_cache,
e ← instantiate_mvars e,
let cfg : simp_config := {fail_if_unchanged := ff},
-- step 1: casts are moved upwards and eliminated
((), new_e, pr1) ← simplify_bottom_up ()
(λ a e, post s a e <|> heur a e <|> aux_num a e)
e cfg,
-- step 2: casts are squashed
s ← squash_cast_attr.get_cache,
(new_e, pr2) ← simplify s [] new_e cfg,
guard (¬ new_e =ₐ e),
pr ← mk_eq_trans pr1 pr2,
return (new_e, pr)
end norm_cast
namespace tactic
open tactic expr
open norm_cast
private 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
meta def exact_mod_cast (e : expr) : tactic unit :=
( do
new_e ← aux_mod_cast e,
exact new_e
) <|> fail "exact_mod_cast failed"
meta def apply_mod_cast (e : expr) : tactic (list (name × expr)) :=
( do
new_e ← aux_mod_cast e,
apply new_e
) <|> fail "apply_mod_cast failed"
meta def assumption_mod_cast : tactic unit :=
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)
} <|> fail "assumption_mod_cast failed"
end tactic
namespace tactic.interactive
open tactic interactive tactic.interactive interactive.types expr lean.parser
open norm_cast
local postfix `?`:9001 := optional
/--
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 rule and normalize casts between steps.
-/
meta def rw_mod_cast (rs : parse rw_rules) (loc : parse location) : tactic unit :=
( 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
) <|> fail "rw_mod_cast failed"
/--
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
/-- `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.
-/
meta def push_cast (l : parse location): tactic unit :=
tactic.interactive.simp none tt [] [`push_cast] l
end tactic.interactive
namespace conv.interactive
open conv tactic tactic.interactive interactive interactive.types
open norm_cast (derive)
meta def norm_cast : conv unit := replace_lhs derive
end conv.interactive
@[elim_cast] lemma ge_from_le {α} [has_le α] : ∀ (x y : α), x ≥ y ↔ y ≤ x := λ _ _, iff.rfl
@[elim_cast] lemma gt_from_lt {α} [has_lt α] : ∀ (x y : α), x > y ↔ y < x := λ _ _, iff.rfl
@[elim_cast] lemma ne_from_not_eq {α} : ∀ (x y : α), x ≠ y ↔ ¬(x = y) := λ _ _, iff.rfl
attribute [squash_cast] int.coe_nat_zero
attribute [squash_cast] int.coe_nat_one
attribute [elim_cast] int.nat_abs_of_nat
attribute [move_cast] int.coe_nat_succ
attribute [move_cast] int.coe_nat_add
attribute [move_cast] int.coe_nat_sub
attribute [move_cast] int.coe_nat_mul
@[move_cast] lemma ite_cast {α β : Type} [has_coe α β]
{c : Prop} [decidable c] {a b : α} :
↑(ite c a b) = ite c (↑a : β) (↑b : β) :=
by by_cases h : c; simp [h]
|
3f5b54deb4063141db00ccfa3e9712dc6e3b91c6 | 842b7df4a999c5c50bbd215b8617dd705e43c2e1 | /nat_num_game/src/Advanced_Multiplication_World/adv_mul_wrld4.lean | cf310275bb251b1f997fca4bade50e7930c5e87f | [] | no_license | Samyak-Surti/LeanCode | 1c245631f74b00057d20483c8ac75916e8643b14 | 944eac3e5f43e2614ed246083b97fbdf24181d83 | refs/heads/master | 1,669,023,730,828 | 1,595,534,784,000 | 1,595,534,784,000 | 282,037,186 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 164 | lean | theorem mul_left_cancel (a b c : ℕ) (ha : a ≠ 0) : a * b = a * c → b = c :=
begin
intro h,
induction c with d hd,
rw nat.mul_zero at h,
end |
a602b9bb0fbf408e62ecb2bde319a06e199ee7e6 | 82b86ba2ae0d5aed0f01f49c46db5afec0eb2bd7 | /stage0/src/Init/Data/Int/Basic.lean | edd7df195d56fdae83de3b93bcafc2033e7ced76 | [
"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,809 | lean | /-
Copyright (c) 2016 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
The integers, with addition, multiplication, and subtraction.
-/
prelude
import Init.Data.Nat.Basic
import Init.Data.List
import Init.Data.Repr
import Init.Data.ToString.Basic
open Nat
/- the Type, coercions, and notation -/
inductive Int : Type
| ofNat : Nat → Int
| negSucc : Nat → Int
attribute [extern "lean_nat_to_int"] Int.ofNat
attribute [extern "lean_int_neg_succ_of_nat"] Int.negSucc
instance : Coe Nat Int := ⟨Int.ofNat⟩
namespace Int
instance : Inhabited Int := ⟨ofNat 0⟩
def negOfNat : Nat → Int
| 0 => 0
| succ m => negSucc m
set_option bootstrap.gen_matcher_code false in
@[extern "lean_int_neg"]
protected def neg (n : @& Int) : Int :=
match n with
| ofNat n => negOfNat n
| negSucc n => succ n
def subNatNat (m n : Nat) : Int :=
match (n - m : Nat) with
| 0 => ofNat (m - n) -- m ≥ n
| (succ k) => negSucc k
set_option bootstrap.gen_matcher_code false in
@[extern "lean_int_add"]
protected def add (m n : @& Int) : Int :=
match m, n with
| ofNat m, ofNat n => ofNat (m + n)
| ofNat m, negSucc n => subNatNat m (succ n)
| negSucc m, ofNat n => subNatNat n (succ m)
| negSucc m, negSucc n => negSucc (succ (m + n))
set_option bootstrap.gen_matcher_code false in
@[extern "lean_int_mul"]
protected def mul (m n : @& Int) : Int :=
match m, n with
| ofNat m, ofNat n => ofNat (m * n)
| ofNat m, negSucc n => negOfNat (m * succ n)
| negSucc m, ofNat n => negOfNat (succ m * n)
| negSucc m, negSucc n => ofNat (succ m * succ n)
instance : Neg Int := ⟨Int.neg⟩
instance : Add Int := ⟨Int.add⟩
instance : Mul Int := ⟨Int.mul⟩
@[extern "lean_int_sub"]
protected def sub (m n : @& Int) : Int :=
m + (- n)
instance : Sub Int := ⟨Int.sub⟩
inductive NonNeg : Int → Prop
| mk (n : Nat) : NonNeg (ofNat n)
protected def LessEq (a b : Int) : Prop := NonNeg (b - a)
instance : HasLessEq Int := ⟨Int.LessEq⟩
protected def Less (a b : Int) : Prop := (a + 1) ≤ b
instance : HasLess Int := ⟨Int.Less⟩
set_option bootstrap.gen_matcher_code false in
@[extern "lean_int_dec_eq"]
protected def decEq (a b : @& Int) : Decidable (a = b) :=
match a, b with
| ofNat a, ofNat b => match decEq a b with
| isTrue h => isTrue $ h ▸ rfl
| isFalse h => isFalse $ fun h' => Int.noConfusion h' (fun h' => absurd h' h)
| negSucc a, negSucc b => match decEq a b with
| isTrue h => isTrue $ h ▸ rfl
| isFalse h => isFalse $ fun h' => Int.noConfusion h' (fun h' => absurd h' h)
| ofNat a, negSucc b => isFalse $ fun h => Int.noConfusion h
| negSucc a, ofNat b => isFalse $ fun h => Int.noConfusion h
instance : DecidableEq Int := Int.decEq
set_option bootstrap.gen_matcher_code false in
@[extern "lean_int_dec_nonneg"]
private def decNonneg (m : @& Int) : Decidable (NonNeg m) :=
match m with
| ofNat m => isTrue $ NonNeg.mk m
| negSucc m => isFalse $ fun h => nomatch h
@[extern "lean_int_dec_le"]
instance decLe (a b : @& Int) : Decidable (a ≤ b) :=
decNonneg _
@[extern "lean_int_dec_lt"]
instance decLt (a b : @& Int) : Decidable (a < b) :=
decNonneg _
set_option bootstrap.gen_matcher_code false in
@[extern "lean_nat_abs"]
def natAbs (m : @& Int) : Nat :=
match m with
| ofNat m => m
| negSucc m => m.succ
protected def repr : Int → String
| ofNat m => Nat.repr m
| negSucc m => "-" ++ Nat.repr (succ m)
instance : Repr Int := ⟨Int.repr⟩
instance : ToString Int := ⟨Int.repr⟩
instance : OfNat Int := ⟨Int.ofNat⟩
@[extern "lean_int_div"]
def div : (@& Int) → (@& Int) → Int
| ofNat m, ofNat n => ofNat (m / n)
| ofNat m, negSucc n => -ofNat (m / succ n)
| negSucc m, ofNat n => -ofNat (succ m / n)
| negSucc m, negSucc n => ofNat (succ m / succ n)
@[extern "lean_int_mod"]
def mod : (@& Int) → (@& Int) → Int
| ofNat m, ofNat n => ofNat (m % n)
| ofNat m, negSucc n => ofNat (m % succ n)
| negSucc m, ofNat n => -ofNat (succ m % n)
| negSucc m, negSucc n => -ofNat (succ m % succ n)
instance : Div Int := ⟨Int.div⟩
instance : Mod Int := ⟨Int.mod⟩
def toNat : Int → Nat
| ofNat n => n
| negSucc n => 0
def natMod (m n : Int) : Nat := (m % n).toNat
end Int
namespace String
def toInt? (s : String) : Option Int :=
if s.get 0 = '-' then do
let v ← (s.toSubstring.drop 1).toNat?;
pure $ - Int.ofNat v
else
Int.ofNat <$> s.toNat?
def isInt (s : String) : Bool :=
if s.get 0 = '-' then
(s.toSubstring.drop 1).isNat
else
s.isNat
def toInt! (s : String) : Int :=
match s.toInt? with
| some v => v
| none => panic! "Int expected"
end String
|
f3c18be8bea793dab12c30b8a82b16dc80ffb43b | 3c9dc4ea6cc92e02634ef557110bde9eae393338 | /stage0/src/Lean/Message.lean | 208b548dd7299486b7bc92be383adc2fdf87f06d | [
"Apache-2.0"
] | permissive | shingtaklam1324/lean4 | 3d7efe0c8743a4e33d3c6f4adbe1300df2e71492 | 351285a2e8ad0cef37af05851cfabf31edfb5970 | refs/heads/master | 1,676,827,679,740 | 1,610,462,623,000 | 1,610,552,340,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 13,481 | lean | /-
Copyright (c) 2018 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Sebastian Ullrich, Leonardo de Moura
Message Type used by the Lean frontend
-/
import Lean.Data.Position
import Lean.Data.OpenDecl
import Lean.Syntax
import Lean.MetavarContext
import Lean.Environment
import Lean.Util.PPExt
namespace Lean
def mkErrorStringWithPos (fileName : String) (line col : Nat) (msg : String) : String :=
fileName ++ ":" ++ toString line ++ ":" ++ toString col ++ ": " ++ toString msg
inductive MessageSeverity where
| information | warning | error
deriving Inhabited, BEq
structure MessageDataContext where
env : Environment
mctx : MetavarContext
lctx : LocalContext
opts : Options
structure NamingContext where
currNamespace : Name
openDecls : List OpenDecl
/- Structure message data. We use it for reporting errors, trace messages, etc. -/
inductive MessageData where
| ofFormat : Format → MessageData
| ofSyntax : Syntax → MessageData
| ofExpr : Expr → MessageData
| ofLevel : Level → MessageData
| ofName : Name → MessageData
| ofGoal : MVarId → MessageData
/- `withContext ctx d` specifies the pretty printing context `(env, mctx, lctx, opts)` for the nested expressions in `d`. -/
| withContext : MessageDataContext → MessageData → MessageData
| withNamingContext : NamingContext → MessageData → MessageData
/- Lifted `Format.nest` -/
| nest : Nat → MessageData → MessageData
/- Lifted `Format.group` -/
| group : MessageData → MessageData
/- Lifted `Format.compose` -/
| compose : MessageData → MessageData → MessageData
/- Tagged sections. `Name` should be viewed as a "kind", and is used by `MessageData` inspector functions.
Example: an inspector that tries to find "definitional equality failures" may look for the tag "DefEqFailure". -/
| tagged : Name → MessageData → MessageData
| node : Array MessageData → MessageData
deriving Inhabited
namespace MessageData
def nil : MessageData :=
ofFormat Format.nil
def isNil : MessageData → Bool
| ofFormat Format.nil => true
| _ => false
def isNest : MessageData → Bool
| nest _ _ => true
| _ => false
def mkPPContext (nCtx : NamingContext) (ctx : MessageDataContext) : PPContext := {
env := ctx.env, mctx := ctx.mctx, lctx := ctx.lctx, opts := ctx.opts,
currNamespace := nCtx.currNamespace, openDecls := nCtx.openDecls
}
partial def formatAux : NamingContext → Option MessageDataContext → MessageData → IO Format
| _, _, ofFormat fmt => pure fmt
| _, _, ofLevel u => pure $ fmt u
| _, _, ofName n => pure $ fmt n
| nCtx, some ctx, ofSyntax s => ppTerm (mkPPContext nCtx ctx) s -- HACK: might not be a term
| _, none, ofSyntax s => pure $ s.formatStx
| _, none, ofExpr e => pure $ format (toString e)
| nCtx, some ctx, ofExpr e => ppExpr (mkPPContext nCtx ctx) e
| _, none, ofGoal mvarId => pure $ "goal " ++ format (mkMVar mvarId)
| nCtx, some ctx, ofGoal mvarId => ppGoal (mkPPContext nCtx ctx) mvarId
| nCtx, _, withContext ctx d => formatAux nCtx ctx d
| _, ctx, withNamingContext nCtx d => formatAux nCtx ctx d
| nCtx, ctx, tagged cls d => do let d ← formatAux nCtx ctx d; pure $ Format.sbracket (format cls) ++ " " ++ d
| nCtx, ctx, nest n d => Format.nest n <$> formatAux nCtx ctx d
| nCtx, ctx, compose d₁ d₂ => do let d₁ ← formatAux nCtx ctx d₁; let d₂ ← formatAux nCtx ctx d₂; pure $ d₁ ++ d₂
| nCtx, ctx, group d => Format.group <$> formatAux nCtx ctx d
| nCtx, ctx, node ds => Format.nest 2 <$> ds.foldlM (fun r d => do let d ← formatAux nCtx ctx d; pure $ r ++ Format.line ++ d) Format.nil
protected def format (msgData : MessageData) : IO Format :=
formatAux { currNamespace := Name.anonymous, openDecls := [] } none msgData
protected def toString (msgData : MessageData) : IO String := do
let fmt ← msgData.format
pure $ toString fmt
instance : Append MessageData := ⟨compose⟩
instance : Coe String MessageData := ⟨ofFormat ∘ format⟩
instance : Coe Format MessageData := ⟨ofFormat⟩
instance : Coe Level MessageData := ⟨ofLevel⟩
instance : Coe Expr MessageData := ⟨ofExpr⟩
instance : Coe Name MessageData := ⟨ofName⟩
instance : Coe Syntax MessageData := ⟨ofSyntax⟩
instance : Coe (Option Expr) MessageData := ⟨fun o => match o with | none => "none" | some e => ofExpr e⟩
partial def arrayExpr.toMessageData (es : Array Expr) (i : Nat) (acc : MessageData) : MessageData :=
if h : i < es.size then
let e := es.get ⟨i, h⟩;
let acc := if i == 0 then acc ++ ofExpr e else acc ++ ", " ++ ofExpr e;
toMessageData es (i+1) acc
else
acc ++ "]"
instance : Coe (Array Expr) MessageData := ⟨fun es => arrayExpr.toMessageData es 0 "#["⟩
def bracket (l : String) (f : MessageData) (r : String) : MessageData := group (nest l.length $ l ++ f ++ r)
def paren (f : MessageData) : MessageData := bracket "(" f ")"
def sbracket (f : MessageData) : MessageData := bracket "[" f "]"
def joinSep : List MessageData → MessageData → MessageData
| [], sep => Format.nil
| [a], sep => a
| a::as, sep => a ++ sep ++ joinSep as sep
def ofList: List MessageData → MessageData
| [] => "[]"
| xs => sbracket $ joinSep xs (ofFormat "," ++ Format.line)
def ofArray (msgs : Array MessageData) : MessageData :=
ofList msgs.toList
instance : Coe (List MessageData) MessageData := ⟨ofList⟩
instance : Coe (List Expr) MessageData := ⟨fun es => ofList $ es.map ofExpr⟩
end MessageData
structure Message where
fileName : String
pos : Position
endPos : Option Position := none
severity : MessageSeverity := MessageSeverity.error
caption : String := ""
data : MessageData
deriving Inhabited
@[export lean_mk_message]
def mkMessageEx (fileName : String) (pos : Position) (endPos : Option Position) (severity : MessageSeverity) (caption : String) (text : String) : Message :=
{ fileName := fileName, pos := pos, endPos := endPos, severity := severity, caption := caption, data := text }
namespace Message
protected def toString (msg : Message) : IO String := do
let str ← msg.data.toString
pure $ mkErrorStringWithPos msg.fileName msg.pos.line msg.pos.column
((match msg.severity with
| MessageSeverity.information => ""
| MessageSeverity.warning => "warning: "
| MessageSeverity.error => "error: ") ++
(if msg.caption == "" then "" else msg.caption ++ ":\n") ++ str)
@[export lean_message_pos] def getPostEx (msg : Message) : Position := msg.pos
@[export lean_message_severity] def getSeverityEx (msg : Message) : MessageSeverity := msg.severity
@[export lean_message_string] unsafe def getMessageStringEx (msg : Message) : String :=
match unsafeIO (msg.data.toString) with -- hack: this is going to be deleted
| Except.ok msg => msg
| Except.error e => "error formatting message: " ++ toString e
end Message
structure MessageLog where
msgs : Std.PersistentArray Message := {}
deriving Inhabited
namespace MessageLog
def empty : MessageLog := ⟨{}⟩
def isEmpty (log : MessageLog) : Bool :=
log.msgs.isEmpty
def add (msg : Message) (log : MessageLog) : MessageLog :=
⟨log.msgs.push msg⟩
protected def append (l₁ l₂ : MessageLog) : MessageLog :=
⟨l₁.msgs ++ l₂.msgs⟩
instance : Append MessageLog :=
⟨MessageLog.append⟩
def hasErrors (log : MessageLog) : Bool :=
log.msgs.any fun m => match m.severity with
| MessageSeverity.error => true
| _ => false
def errorsToWarnings (log : MessageLog) : MessageLog :=
{ msgs := log.msgs.map (fun m => match m.severity with | MessageSeverity.error => { m with severity := MessageSeverity.warning } | _ => m) }
def getInfoMessages (log : MessageLog) : MessageLog :=
{ msgs := log.msgs.filter fun m => match m.severity with | MessageSeverity.information => true | _ => false }
def forM {m : Type → Type} [Monad m] (log : MessageLog) (f : Message → m Unit) : m Unit :=
log.msgs.forM f
def toList (log : MessageLog) : List Message :=
(log.msgs.foldl (fun acc msg => msg :: acc) []).reverse
end MessageLog
def MessageData.nestD (msg : MessageData) : MessageData :=
MessageData.nest 2 msg
def indentD (msg : MessageData) : MessageData :=
MessageData.nestD (Format.line ++ msg)
def indentExpr (e : Expr) : MessageData :=
indentD e
class AddMessageContext (m : Type → Type) where
addMessageContext : MessageData → m MessageData
export AddMessageContext (addMessageContext)
instance (m n) [AddMessageContext m] [MonadLift m n] : AddMessageContext n :=
{ addMessageContext := fun msg => liftM (addMessageContext msg : m _) }
def addMessageContextPartial {m} [Monad m] [MonadEnv m] [MonadOptions m] (msgData : MessageData) : m MessageData := do
let env ← getEnv
let opts ← getOptions
pure $ MessageData.withContext { env := env, mctx := {}, lctx := {}, opts := opts } msgData
def addMessageContextFull {m} [Monad m] [MonadEnv m] [MonadMCtx m] [MonadLCtx m] [MonadOptions m] (msgData : MessageData) : m MessageData := do
let env ← getEnv
let mctx ← getMCtx
let lctx ← getLCtx
let opts ← getOptions
pure $ MessageData.withContext { env := env, mctx := mctx, lctx := lctx, opts := opts } msgData
class ToMessageData (α : Type) where
toMessageData : α → MessageData
export ToMessageData (toMessageData)
def stringToMessageData (str : String) : MessageData :=
let lines := str.split (· == '\n')
let lines := lines.map (MessageData.ofFormat ∘ fmt)
MessageData.joinSep lines (MessageData.ofFormat Format.line)
instance {α} [ToFormat α] : ToMessageData α := ⟨MessageData.ofFormat ∘ fmt⟩
instance : ToMessageData Expr := ⟨MessageData.ofExpr⟩
instance : ToMessageData Level := ⟨MessageData.ofLevel⟩
instance : ToMessageData Name := ⟨MessageData.ofName⟩
instance : ToMessageData String := ⟨stringToMessageData⟩
instance : ToMessageData Syntax := ⟨MessageData.ofSyntax⟩
instance : ToMessageData Format := ⟨MessageData.ofFormat⟩
instance : ToMessageData MessageData := ⟨id⟩
instance {α} [ToMessageData α] : ToMessageData (List α) := ⟨fun as => MessageData.ofList $ as.map toMessageData⟩
instance {α} [ToMessageData α] : ToMessageData (Array α) := ⟨fun as => toMessageData as.toList⟩
instance {α} [ToMessageData α] : ToMessageData (Option α) := ⟨fun | none => "none" | some e => "some (" ++ toMessageData e ++ ")"⟩
instance : ToMessageData (Option Expr) := ⟨fun | none => "<not-available>" | some e => toMessageData e⟩
syntax:max "m!" interpolatedStr(term) : term
macro_rules
| `(m! $interpStr) => do interpStr.expandInterpolatedStr (← `(MessageData)) (← `(toMessageData))
namespace KernelException
private def mkCtx (env : Environment) (lctx : LocalContext) (opts : Options) (msg : MessageData) : MessageData :=
MessageData.withContext { env := env, mctx := {}, lctx := lctx, opts := opts } msg
def toMessageData (e : KernelException) (opts : Options) : MessageData :=
match e with
| unknownConstant env constName => mkCtx env {} opts m!"(kernel) unknown constant '{constName}'"
| alreadyDeclared env constName => mkCtx env {} opts m!"(kernel) constant has already been declared '{constName}'"
| declTypeMismatch env decl givenType =>
let process (n : Name) (expectedType : Expr) : MessageData :=
m!"(kernel) declaration type mismatch, '{n}' has type{indentExpr givenType}\nbut it is expected to have type{indentExpr expectedType}";
match decl with
| Declaration.defnDecl { name := n, type := type, .. } => process n type
| Declaration.thmDecl { name := n, type := type, .. } => process n type
| _ => "(kernel) declaration type mismatch" -- TODO fix type checker, type mismatch for mutual decls does not have enough information
| declHasMVars env constName _ => mkCtx env {} opts m!"(kernel) declaration has metavariables '{constName}'"
| declHasFVars env constName _ => mkCtx env {} opts m!"(kernel) declaration has free variables '{constName}'"
| funExpected env lctx e => mkCtx env lctx opts m!"(kernel) function expected{indentExpr e}"
| typeExpected env lctx e => mkCtx env lctx opts m!"(kernel) type expected{indentExpr e}"
| letTypeMismatch env lctx n _ _ => mkCtx env lctx opts m!"(kernel) let-declaration type mismatch '{n}'"
| exprTypeMismatch env lctx e _ => mkCtx env lctx opts m!"(kernel) type mismatch at{indentExpr e}"
| appTypeMismatch env lctx e fnType argType =>
mkCtx env lctx opts m!"application type mismatch{indentExpr e}\nargument has type{indentExpr argType}\nbut function has type{indentExpr fnType}"
| invalidProj env lctx e => mkCtx env lctx opts m!"(kernel) invalid projection{indentExpr e}"
| other msg => m!"(kernel) {msg}"
end KernelException
end Lean
|
50ff8c69e8b28f41db6c2bfbdb61696d89631b71 | 7920bb65c187f9e7065f47e49b3b60ebe8cfe2c1 | /src/utils.lean | 5dda575b0f578ab039a12a977781d80211bb3cb3 | [] | no_license | ADedecker/grifone-3-16 | 3357441687acd8e1d8aa0f3eaeab76d69bd46b62 | d7cb5a58695203dea6a27fb69067e08eb6a82bad | refs/heads/master | 1,679,431,665,551 | 1,616,077,475,000 | 1,616,077,475,000 | 348,148,279 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 2,052 | lean | import order.directed
import linear_algebra.basic
lemma antimono_of_antimono_nat {α : Type*} [preorder α] {f : ℕ → α}
(hf : ∀n, f (n + 1) ≤ f n) :
∀ ⦃x y⦄, x ≤ y → f y ≤ f x | n m h :=
begin
induction h,
{ refl },
{ transitivity, exact hf _, assumption }
end
lemma directed_le_of_monotone {α ι : Type*} [preorder α] [linear_order ι] {f : ι → α}
(hf : monotone f) : directed (≤) f :=
λ i j, ⟨max i j, hf (le_max_left i j), hf (le_max_right i j)⟩
namespace linear_map
variables {E K : Type*} [field K] [add_comm_group E] [vector_space K E] (f : E →ₗ[K] E)
lemma pow_succ_apply (n : ℕ) (x : E) : (f^(n+1)) x = f ((f^n) x) :=
by rw [pow_succ]; refl
lemma pow_succ_apply' (n : ℕ) (x : E) : (f^(n+1)) x = (f^n) (f x) :=
by rw [pow_succ']; refl
lemma pow_add_apply (n m : ℕ) (x : E) : (f^(n+m)) x = (f^n) ((f^m) x) :=
by rw [pow_add]; refl
lemma pow_add_apply' (n m : ℕ) (x : E) : (f^(n+m)) x = (f^m) ((f^n) x) :=
by rw [add_comm]; exact f.pow_add_apply m n x
lemma comp_stable (g : E →ₗ[K] E) {U : submodule K E} (hfU : ∀ x ∈ U, f x ∈ U)
(hgU : ∀ x ∈ U, g x ∈ U) : ∀ x ∈ U, (f.comp g) x ∈ U :=
λ x hx, hfU _ (hgU x hx)
lemma pow_stable {U : submodule K E} (hfU : ∀ x ∈ U, f x ∈ U) :
∀ (n : ℕ), ∀ x ∈ U, (f^n) x ∈ U
| 0 := λ x hx, hx
| (n+1) := λ x hx,
begin
rw pow_succ_apply,
exact hfU _ (pow_stable n _ hx)
end
lemma restrict_comp (g : E →ₗ[K] E) {U : submodule K E} (hfU : ∀ x ∈ U, f x ∈ U)
(hgU : ∀ x ∈ U, g x ∈ U) (hfgU : ∀ x ∈ U, (f.comp g) x ∈ U) :
(f.comp g).restrict hfgU = (f.restrict hfU).comp (g.restrict hgU) :=
rfl
lemma pow_restrict_comm {U : submodule K E} (hfU : ∀ x ∈ U, f x ∈ U) :
∀ n, (f.restrict hfU)^n = (f^n).restrict (f.pow_stable hfU n)
| 0 :=
begin
ext ⟨x, hx⟩,
refl
end
| (n+1) :=
begin
ext ⟨x, hx⟩,
simp only [pow_succ, mul_eq_comp, restrict_comp _ _ hfU (f.pow_stable hfU n) _],
rw pow_restrict_comm n
end
end linear_map |
e7ff1764ad0e60358800d53a5b40879c2c73722f | 94e33a31faa76775069b071adea97e86e218a8ee | /src/data/real/cau_seq.lean | 205e834413fa51a3b24de2c4acbce3aebb3ab275 | [
"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 | 24,244 | 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 algebra.order.absolute_value
import algebra.big_operators.order
/-!
# Cauchy sequences
A basic theory of Cauchy sequences, used in the construction of the reals and p-adic numbers. Where
applicable, lemmas that will be reused in other contexts have been stated in extra generality.
There are other "versions" of Cauchyness in the library, in particular Cauchy filters in topology.
This is a concrete implementation that is useful for simplicity and computability reasons.
## Important definitions
* `is_cau_seq`: a predicate that says `f : ℕ → β` is Cauchy.
* `cau_seq`: the type of Cauchy sequences valued in type `β` with respect to an absolute value
function `abv`.
## Tags
sequence, cauchy, abs val, absolute value
-/
open_locale big_operators
open is_absolute_value
theorem exists_forall_ge_and {α} [linear_order α] {P Q : α → Prop} :
(∃ i, ∀ j ≥ i, P j) → (∃ i, ∀ j ≥ i, Q j) →
∃ i, ∀ j ≥ i, P j ∧ Q j
| ⟨a, h₁⟩ ⟨b, h₂⟩ := let ⟨c, ac, bc⟩ := exists_ge_of_linear a b in
⟨c, λ j hj, ⟨h₁ _ (le_trans ac hj), h₂ _ (le_trans bc hj)⟩⟩
section
variables {α : Type*} [linear_ordered_field α]
{β : Type*} [ring β] (abv : β → α) [is_absolute_value abv]
theorem rat_add_continuous_lemma
{ε : α} (ε0 : 0 < ε) : ∃ δ > 0, ∀ {a₁ a₂ b₁ b₂ : β},
abv (a₁ - b₁) < δ → abv (a₂ - b₂) < δ → abv (a₁ + a₂ - (b₁ + b₂)) < ε :=
⟨ε / 2, half_pos ε0, λ a₁ a₂ b₁ b₂ h₁ h₂,
by simpa [add_halves, sub_eq_add_neg, add_comm, add_left_comm, add_assoc]
using lt_of_le_of_lt (abv_add abv _ _) (add_lt_add h₁ h₂)⟩
theorem rat_mul_continuous_lemma
{ε K₁ K₂ : α} (ε0 : 0 < ε) :
∃ δ > 0, ∀ {a₁ a₂ b₁ b₂ : β}, abv a₁ < K₁ → abv b₂ < K₂ →
abv (a₁ - b₁) < δ → abv (a₂ - b₂) < δ → abv (a₁ * a₂ - b₁ * b₂) < ε :=
begin
have K0 : (0 : α) < max 1 (max K₁ K₂) := lt_of_lt_of_le zero_lt_one (le_max_left _ _),
have εK := div_pos (half_pos ε0) K0,
refine ⟨_, εK, λ a₁ a₂ b₁ b₂ ha₁ hb₂ h₁ h₂, _⟩,
replace ha₁ := lt_of_lt_of_le ha₁ (le_trans (le_max_left _ K₂) (le_max_right 1 _)),
replace hb₂ := lt_of_lt_of_le hb₂ (le_trans (le_max_right K₁ _) (le_max_right 1 _)),
have := add_lt_add
(mul_lt_mul' (le_of_lt h₁) hb₂ (abv_nonneg abv _) εK)
(mul_lt_mul' (le_of_lt h₂) ha₁ (abv_nonneg abv _) εK),
rw [← abv_mul abv, mul_comm, div_mul_cancel _ (ne_of_gt K0), ← abv_mul abv, add_halves] at this,
simpa [mul_add, add_mul, sub_eq_add_neg, add_comm, add_left_comm]
using lt_of_le_of_lt (abv_add abv _ _) this
end
theorem rat_inv_continuous_lemma
{β : Type*} [field β] (abv : β → α) [is_absolute_value abv]
{ε K : α} (ε0 : 0 < ε) (K0 : 0 < K) :
∃ δ > 0, ∀ {a b : β}, K ≤ abv a → K ≤ abv b →
abv (a - b) < δ → abv (a⁻¹ - b⁻¹) < ε :=
begin
have KK := mul_pos K0 K0,
have εK := mul_pos ε0 KK,
refine ⟨_, εK, λ a b ha hb h, _⟩,
have a0 := lt_of_lt_of_le K0 ha,
have b0 := lt_of_lt_of_le K0 hb,
rw [inv_sub_inv ((abv_pos abv).1 a0) ((abv_pos abv).1 b0),
abv_div abv, abv_mul abv, mul_comm, abv_sub abv,
← mul_div_cancel ε (ne_of_gt KK)],
exact div_lt_div h
(mul_le_mul hb ha (le_of_lt K0) (abv_nonneg abv _))
(le_of_lt $ mul_pos ε0 KK) KK
end
end
/-- A sequence is Cauchy if the distance between its entries tends to zero. -/
def is_cau_seq {α : Type*} [linear_ordered_field α]
{β : Type*} [ring β] (abv : β → α) (f : ℕ → β) : Prop :=
∀ ε > 0, ∃ i, ∀ j ≥ i, abv (f j - f i) < ε
namespace is_cau_seq
variables {α : Type*} [linear_ordered_field α]
{β : Type*} [ring β] {abv : β → α} [is_absolute_value abv] {f : ℕ → β}
@[nolint ge_or_gt] -- see Note [nolint_ge]
theorem cauchy₂ (hf : is_cau_seq abv f) {ε : α} (ε0 : 0 < ε) :
∃ i, ∀ j k ≥ i, abv (f j - f k) < ε :=
begin
refine (hf _ (half_pos ε0)).imp (λ i hi j ij k ik, _),
rw ← add_halves ε,
refine lt_of_le_of_lt (abv_sub_le abv _ _ _) (add_lt_add (hi _ ij) _),
rw abv_sub abv, exact hi _ ik
end
theorem cauchy₃ (hf : is_cau_seq abv f) {ε : α} (ε0 : 0 < ε) :
∃ i, ∀ j ≥ i, ∀ k ≥ j, abv (f k - f j) < ε :=
let ⟨i, H⟩ := hf.cauchy₂ ε0 in ⟨i, λ j ij k jk, H _ (le_trans ij jk) _ ij⟩
end is_cau_seq
/-- `cau_seq β abv` is the type of `β`-valued Cauchy sequences, with respect to the absolute value
function `abv`. -/
def cau_seq {α : Type*} [linear_ordered_field α]
(β : Type*) [ring β] (abv : β → α) : Type* :=
{f : ℕ → β // is_cau_seq abv f}
namespace cau_seq
variables {α : Type*} [linear_ordered_field α]
section ring
variables {β : Type*} [ring β] {abv : β → α}
instance : has_coe_to_fun (cau_seq β abv) (λ _, ℕ → β) := ⟨subtype.val⟩
@[simp] theorem mk_to_fun (f) (hf : is_cau_seq abv f) :
@coe_fn (cau_seq β abv) _ _ ⟨f, hf⟩ = f := rfl
theorem ext {f g : cau_seq β abv} (h : ∀ i, f i = g i) : f = g :=
subtype.eq (funext h)
theorem is_cau (f : cau_seq β abv) : is_cau_seq abv f := f.2
theorem cauchy (f : cau_seq β abv) :
∀ {ε}, 0 < ε → ∃ i, ∀ j ≥ i, abv (f j - f i) < ε := f.2
/-- Given a Cauchy sequence `f`, create a Cauchy sequence from a sequence `g` with
the same values as `f`. -/
def of_eq (f : cau_seq β abv) (g : ℕ → β) (e : ∀ i, f i = g i) : cau_seq β abv :=
⟨g, λ ε, by rw [show g = f, from (funext e).symm]; exact f.cauchy⟩
variable [is_absolute_value abv]
@[nolint ge_or_gt] -- see Note [nolint_ge]
theorem cauchy₂ (f : cau_seq β abv) {ε} : 0 < ε →
∃ i, ∀ j k ≥ i, abv (f j - f k) < ε := f.2.cauchy₂
theorem cauchy₃ (f : cau_seq β abv) {ε} : 0 < ε →
∃ i, ∀ j ≥ i, ∀ k ≥ j, abv (f k - f j) < ε := f.2.cauchy₃
theorem bounded (f : cau_seq β abv) : ∃ r, ∀ i, abv (f i) < r :=
begin
cases f.cauchy zero_lt_one with i h,
let R := ∑ j in finset.range (i+1), abv (f j),
have : ∀ j ≤ i, abv (f j) ≤ R,
{ intros j ij, change (λ j, abv (f j)) j ≤ R,
apply finset.single_le_sum,
{ intros, apply abv_nonneg abv },
{ rwa [finset.mem_range, nat.lt_succ_iff] } },
refine ⟨R + 1, λ j, _⟩,
cases lt_or_le j i with ij ij,
{ exact lt_of_le_of_lt (this _ (le_of_lt ij)) (lt_add_one _) },
{ have := lt_of_le_of_lt (abv_add abv _ _)
(add_lt_add_of_le_of_lt (this _ le_rfl) (h _ ij)),
rw [add_sub, add_comm] at this, simpa }
end
theorem bounded' (f : cau_seq β abv) (x : α) : ∃ r > x, ∀ i, abv (f i) < r :=
let ⟨r, h⟩ := f.bounded in
⟨max r (x+1), lt_of_lt_of_le (lt_add_one _) (le_max_right _ _),
λ i, lt_of_lt_of_le (h i) (le_max_left _ _)⟩
instance : has_add (cau_seq β abv) :=
⟨λ f g, ⟨λ i, (f i + g i : β), λ ε ε0,
let ⟨δ, δ0, Hδ⟩ := rat_add_continuous_lemma abv ε0,
⟨i, H⟩ := exists_forall_ge_and (f.cauchy₃ δ0) (g.cauchy₃ δ0) in
⟨i, λ j ij, let ⟨H₁, H₂⟩ := H _ le_rfl in Hδ (H₁ _ ij) (H₂ _ ij)⟩⟩⟩
@[simp] theorem add_apply (f g : cau_seq β abv) (i : ℕ) : (f + g) i = f i + g i := rfl
variable (abv)
/-- The constant Cauchy sequence. -/
def const (x : β) : cau_seq β abv :=
⟨λ i, x, λ ε ε0, ⟨0, λ j ij, by simpa [abv_zero abv] using ε0⟩⟩
variable {abv}
local notation `const` := const abv
@[simp] theorem const_apply (x : β) (i : ℕ) : (const x : ℕ → β) i = x := rfl
theorem const_inj {x y : β} : (const x : cau_seq β abv) = const y ↔ x = y :=
⟨λ h, congr_arg (λ f:cau_seq β abv, (f:ℕ→β) 0) h, congr_arg _⟩
instance : has_zero (cau_seq β abv) := ⟨const 0⟩
instance : has_one (cau_seq β abv) := ⟨const 1⟩
instance : inhabited (cau_seq β abv) := ⟨0⟩
@[simp] theorem zero_apply (i) : (0 : cau_seq β abv) i = 0 := rfl
@[simp] theorem one_apply (i) : (1 : cau_seq β abv) i = 1 := rfl
@[simp] theorem const_zero : const 0 = 0 := rfl
theorem const_add (x y : β) : const (x + y) = const x + const y :=
rfl
instance : has_mul (cau_seq β abv) :=
⟨λ f g, ⟨λ i, (f i * g i : β), λ ε ε0,
let ⟨F, F0, hF⟩ := f.bounded' 0, ⟨G, G0, hG⟩ := g.bounded' 0,
⟨δ, δ0, Hδ⟩ := rat_mul_continuous_lemma abv ε0,
⟨i, H⟩ := exists_forall_ge_and (f.cauchy₃ δ0) (g.cauchy₃ δ0) in
⟨i, λ j ij, let ⟨H₁, H₂⟩ := H _ le_rfl in
Hδ (hF j) (hG i) (H₁ _ ij) (H₂ _ ij)⟩⟩⟩
@[simp] theorem mul_apply (f g : cau_seq β abv) (i : ℕ) : (f * g) i = f i * g i := rfl
theorem const_mul (x y : β) : const (x * y) = const x * const y :=
ext $ λ i, rfl
instance : has_neg (cau_seq β abv) :=
⟨λ f, of_eq (const (-1) * f) (λ x, -f x) (λ i, by simp)⟩
@[simp] theorem neg_apply (f : cau_seq β abv) (i) : (-f) i = -f i := rfl
theorem const_neg (x : β) : const (-x) = -const x :=
ext $ λ i, rfl
instance : has_sub (cau_seq β abv) :=
⟨λ f g, of_eq (f + -g) (λ x, f x - g x) (λ i, by simp [sub_eq_add_neg])⟩
@[simp] theorem sub_apply (f g : cau_seq β abv) (i : ℕ) : (f - g) i = f i - g i := rfl
theorem const_sub (x y : β) : const (x - y) = const x - const y :=
ext $ λ i, rfl
instance : add_group (cau_seq β abv) :=
by refine_struct
{ add := (+),
neg := has_neg.neg,
zero := (0 : cau_seq β abv),
sub := has_sub.sub,
zsmul := @zsmul_rec (cau_seq β abv) ⟨0⟩ ⟨(+)⟩ ⟨has_neg.neg⟩,
nsmul := @nsmul_rec (cau_seq β abv) ⟨0⟩ ⟨(+)⟩ };
intros; try { refl }; apply ext; simp [add_comm, add_left_comm, sub_eq_add_neg]
instance : add_group_with_one (cau_seq β abv) :=
{ one := 1,
nat_cast := λ n, const n,
nat_cast_zero := congr_arg const nat.cast_zero,
nat_cast_succ := λ n, congr_arg const (nat.cast_succ n),
int_cast := λ n, const n,
int_cast_of_nat := λ n, congr_arg const (int.cast_of_nat n),
int_cast_neg_succ_of_nat := λ n, congr_arg const (int.cast_neg_succ_of_nat n),
.. cau_seq.add_group }
instance : ring (cau_seq β abv) :=
by refine_struct
{ add := (+),
zero := (0 : cau_seq β abv),
mul := (*),
one := 1,
npow := @npow_rec (cau_seq β abv) ⟨1⟩ ⟨(*)⟩,
.. cau_seq.add_group_with_one };
intros; try { refl }; apply ext;
simp [mul_add, mul_assoc, add_mul, add_comm, add_left_comm, sub_eq_add_neg]
instance {β : Type*} [comm_ring β] {abv : β → α} [is_absolute_value abv] :
comm_ring (cau_seq β abv) :=
{ mul_comm := by intros; apply ext; simp [mul_left_comm, mul_comm],
..cau_seq.ring }
/-- `lim_zero f` holds when `f` approaches 0. -/
def lim_zero {abv : β → α} (f : cau_seq β abv) : Prop := ∀ ε > 0, ∃ i, ∀ j ≥ i, abv (f j) < ε
theorem add_lim_zero {f g : cau_seq β abv}
(hf : lim_zero f) (hg : lim_zero g) : lim_zero (f + g)
| ε ε0 := (exists_forall_ge_and
(hf _ $ half_pos ε0) (hg _ $ half_pos ε0)).imp $
λ i H j ij, let ⟨H₁, H₂⟩ := H _ ij in
by simpa [add_halves ε] using lt_of_le_of_lt (abv_add abv _ _) (add_lt_add H₁ H₂)
theorem mul_lim_zero_right (f : cau_seq β abv) {g}
(hg : lim_zero g) : lim_zero (f * g)
| ε ε0 := let ⟨F, F0, hF⟩ := f.bounded' 0 in
(hg _ $ div_pos ε0 F0).imp $ λ i H j ij,
by have := mul_lt_mul' (le_of_lt $ hF j) (H _ ij) (abv_nonneg abv _) F0;
rwa [mul_comm F, div_mul_cancel _ (ne_of_gt F0), ← abv_mul abv] at this
theorem mul_lim_zero_left {f} (g : cau_seq β abv)
(hg : lim_zero f) : lim_zero (f * g)
| ε ε0 := let ⟨G, G0, hG⟩ := g.bounded' 0 in
(hg _ $ div_pos ε0 G0).imp $ λ i H j ij,
by have := mul_lt_mul'' (H _ ij) (hG j) (abv_nonneg abv _) (abv_nonneg abv _);
rwa [div_mul_cancel _ (ne_of_gt G0), ← abv_mul abv] at this
theorem neg_lim_zero {f : cau_seq β abv} (hf : lim_zero f) : lim_zero (-f) :=
by rw ← neg_one_mul; exact mul_lim_zero_right _ hf
theorem sub_lim_zero {f g : cau_seq β abv}
(hf : lim_zero f) (hg : lim_zero g) : lim_zero (f - g) :=
by simpa only [sub_eq_add_neg] using add_lim_zero hf (neg_lim_zero hg)
theorem lim_zero_sub_rev {f g : cau_seq β abv} (hfg : lim_zero (f - g)) : lim_zero (g - f) :=
by simpa using neg_lim_zero hfg
theorem zero_lim_zero : lim_zero (0 : cau_seq β abv)
| ε ε0 := ⟨0, λ j ij, by simpa [abv_zero abv] using ε0⟩
theorem const_lim_zero {x : β} : lim_zero (const x) ↔ x = 0 :=
⟨λ H, (abv_eq_zero abv).1 $
eq_of_le_of_forall_le_of_dense (abv_nonneg abv _) $
λ ε ε0, let ⟨i, hi⟩ := H _ ε0 in le_of_lt $ hi _ le_rfl,
λ e, e.symm ▸ zero_lim_zero⟩
instance equiv : setoid (cau_seq β abv) :=
⟨λ f g, lim_zero (f - g),
⟨λ f, by simp [zero_lim_zero],
λ f g h, by simpa using neg_lim_zero h,
λ f g h fg gh, by simpa [sub_eq_add_neg, add_assoc] using add_lim_zero fg gh⟩⟩
lemma add_equiv_add {f1 f2 g1 g2 : cau_seq β abv} (hf : f1 ≈ f2) (hg : g1 ≈ g2) :
f1 + g1 ≈ f2 + g2 :=
begin
change lim_zero ((f1 + g1) - _),
convert add_lim_zero hf hg using 1,
simp only [sub_eq_add_neg, add_assoc],
rw add_comm (-f2), simp only [add_assoc],
congr' 2, simp
end
lemma neg_equiv_neg {f g : cau_seq β abv} (hf : f ≈ g) : -f ≈ -g :=
begin
show lim_zero (-f - -g),
rw ←neg_sub',
exact neg_lim_zero hf,
end
theorem equiv_def₃ {f g : cau_seq β abv} (h : f ≈ g) {ε : α} (ε0 : 0 < ε) :
∃ i, ∀ j ≥ i, ∀ k ≥ j, abv (f k - g j) < ε :=
(exists_forall_ge_and (h _ $ half_pos ε0) (f.cauchy₃ $ half_pos ε0)).imp $
λ i H j ij k jk, let ⟨h₁, h₂⟩ := H _ ij in
by have := lt_of_le_of_lt (abv_add abv (f j - g j) _) (add_lt_add h₁ (h₂ _ jk));
rwa [sub_add_sub_cancel', add_halves] at this
theorem lim_zero_congr {f g : cau_seq β abv} (h : f ≈ g) : lim_zero f ↔ lim_zero g :=
⟨λ l, by simpa using add_lim_zero (setoid.symm h) l,
λ l, by simpa using add_lim_zero h l⟩
theorem abv_pos_of_not_lim_zero {f : cau_seq β abv} (hf : ¬ lim_zero f) :
∃ K > 0, ∃ i, ∀ j ≥ i, K ≤ abv (f j) :=
begin
haveI := classical.prop_decidable,
by_contra nk,
refine hf (λ ε ε0, _),
simp [not_forall] at nk,
cases f.cauchy₃ (half_pos ε0) with i hi,
rcases nk _ (half_pos ε0) i with ⟨j, ij, hj⟩,
refine ⟨j, λ k jk, _⟩,
have := lt_of_le_of_lt (abv_add abv _ _) (add_lt_add (hi j ij k jk) hj),
rwa [sub_add_cancel, add_halves] at this
end
theorem of_near (f : ℕ → β) (g : cau_seq β abv)
(h : ∀ ε > 0, ∃ i, ∀ j ≥ i, abv (f j - g j) < ε) : is_cau_seq abv f
| ε ε0 :=
let ⟨i, hi⟩ := exists_forall_ge_and
(h _ (half_pos $ half_pos ε0)) (g.cauchy₃ $ half_pos ε0) in
⟨i, λ j ij, begin
cases hi _ le_rfl with h₁ h₂, rw abv_sub abv at h₁,
have := lt_of_le_of_lt (abv_add abv _ _) (add_lt_add (hi _ ij).1 h₁),
have := lt_of_le_of_lt (abv_add abv _ _) (add_lt_add this (h₂ _ ij)),
rwa [add_halves, add_halves, add_right_comm,
sub_add_sub_cancel, sub_add_sub_cancel] at this
end⟩
lemma not_lim_zero_of_not_congr_zero {f : cau_seq _ abv} (hf : ¬ f ≈ 0) : ¬ lim_zero f :=
assume : lim_zero f,
have lim_zero (f - 0), by simpa,
hf this
lemma mul_equiv_zero (g : cau_seq _ abv) {f : cau_seq _ abv} (hf : f ≈ 0) : g * f ≈ 0 :=
have lim_zero (f - 0), from hf,
have lim_zero (g*f), from mul_lim_zero_right _ $ by simpa,
show lim_zero (g*f - 0), by simpa
lemma mul_not_equiv_zero {f g : cau_seq _ abv} (hf : ¬ f ≈ 0) (hg : ¬ g ≈ 0) : ¬ (f * g) ≈ 0 :=
assume : lim_zero (f*g - 0),
have hlz : lim_zero (f*g), by simpa,
have hf' : ¬ lim_zero f, by simpa using (show ¬ lim_zero (f - 0), from hf),
have hg' : ¬ lim_zero g, by simpa using (show ¬ lim_zero (g - 0), from hg),
begin
rcases abv_pos_of_not_lim_zero hf' with ⟨a1, ha1, N1, hN1⟩,
rcases abv_pos_of_not_lim_zero hg' with ⟨a2, ha2, N2, hN2⟩,
have : 0 < a1 * a2, from mul_pos ha1 ha2,
cases hlz _ this with N hN,
let i := max N (max N1 N2),
have hN' := hN i (le_max_left _ _),
have hN1' := hN1 i (le_trans (le_max_left _ _) (le_max_right _ _)),
have hN1' := hN2 i (le_trans (le_max_right _ _) (le_max_right _ _)),
apply not_le_of_lt hN',
change _ ≤ abv (_ * _),
rw is_absolute_value.abv_mul abv,
apply mul_le_mul; try { assumption },
{ apply le_of_lt ha2 },
{ apply is_absolute_value.abv_nonneg abv }
end
theorem const_equiv {x y : β} : const x ≈ const y ↔ x = y :=
show lim_zero _ ↔ _, by rw [← const_sub, const_lim_zero, sub_eq_zero]
end ring
section comm_ring
variables {β : Type*} [comm_ring β] {abv : β → α} [is_absolute_value abv]
lemma mul_equiv_zero' (g : cau_seq _ abv) {f : cau_seq _ abv} (hf : f ≈ 0) : f * g ≈ 0 :=
by rw mul_comm; apply mul_equiv_zero _ hf
end comm_ring
section is_domain
variables {β : Type*} [ring β] [is_domain β] (abv : β → α) [is_absolute_value abv]
lemma one_not_equiv_zero : ¬ (const abv 1) ≈ (const abv 0) :=
assume h,
have ∀ ε > 0, ∃ i, ∀ k, i ≤ k → abv (1 - 0) < ε, from h,
have h1 : abv 1 ≤ 0, from le_of_not_gt $
assume h2 : 0 < abv 1,
exists.elim (this _ h2) $ λ i hi,
lt_irrefl (abv 1) $ by simpa using hi _ le_rfl,
have h2 : 0 ≤ abv 1, from is_absolute_value.abv_nonneg _ _,
have abv 1 = 0, from le_antisymm h1 h2,
have (1 : β) = 0, from (is_absolute_value.abv_eq_zero abv).1 this,
absurd this one_ne_zero
end is_domain
section field
variables {β : Type*} [field β] {abv : β → α} [is_absolute_value abv]
theorem inv_aux {f : cau_seq β abv} (hf : ¬ lim_zero f) :
∀ ε > 0, ∃ i, ∀ j ≥ i, abv ((f j)⁻¹ - (f i)⁻¹) < ε | ε ε0 :=
let ⟨K, K0, HK⟩ := abv_pos_of_not_lim_zero hf,
⟨δ, δ0, Hδ⟩ := rat_inv_continuous_lemma abv ε0 K0,
⟨i, H⟩ := exists_forall_ge_and HK (f.cauchy₃ δ0) in
⟨i, λ j ij, let ⟨iK, H'⟩ := H _ le_rfl in Hδ (H _ ij).1 iK (H' _ ij)⟩
/-- Given a Cauchy sequence `f` with nonzero limit, create a Cauchy sequence with values equal to
the inverses of the values of `f`. -/
def inv (f : cau_seq β abv) (hf : ¬ lim_zero f) : cau_seq β abv := ⟨_, inv_aux hf⟩
@[simp] theorem inv_apply {f : cau_seq β abv} (hf i) : inv f hf i = (f i)⁻¹ := rfl
theorem inv_mul_cancel {f : cau_seq β abv} (hf) : inv f hf * f ≈ 1 :=
λ ε ε0, let ⟨K, K0, i, H⟩ := abv_pos_of_not_lim_zero hf in
⟨i, λ j ij,
by simpa [(abv_pos abv).1 (lt_of_lt_of_le K0 (H _ ij)),
abv_zero abv] using ε0⟩
theorem const_inv {x : β} (hx : x ≠ 0) :
const abv (x⁻¹) = inv (const abv x) (by rwa const_lim_zero) :=
ext (assume n, by simp[inv_apply, const_apply])
end field
section abs
local notation `const` := const abs
/-- The entries of a positive Cauchy sequence eventually have a positive lower bound. -/
def pos (f : cau_seq α abs) : Prop := ∃ K > 0, ∃ i, ∀ j ≥ i, K ≤ f j
theorem not_lim_zero_of_pos {f : cau_seq α abs} : pos f → ¬ lim_zero f
| ⟨F, F0, hF⟩ H :=
let ⟨i, h⟩ := exists_forall_ge_and hF (H _ F0),
⟨h₁, h₂⟩ := h _ le_rfl in
not_lt_of_le h₁ (abs_lt.1 h₂).2
theorem const_pos {x : α} : pos (const x) ↔ 0 < x :=
⟨λ ⟨K, K0, i, h⟩, lt_of_lt_of_le K0 (h _ le_rfl),
λ h, ⟨x, h, 0, λ j _, le_rfl⟩⟩
theorem add_pos {f g : cau_seq α abs} : pos f → pos g → pos (f + g)
| ⟨F, F0, hF⟩ ⟨G, G0, hG⟩ :=
let ⟨i, h⟩ := exists_forall_ge_and hF hG in
⟨_, _root_.add_pos F0 G0, i,
λ j ij, let ⟨h₁, h₂⟩ := h _ ij in add_le_add h₁ h₂⟩
theorem pos_add_lim_zero {f g : cau_seq α abs} : pos f → lim_zero g → pos (f + g)
| ⟨F, F0, hF⟩ H :=
let ⟨i, h⟩ := exists_forall_ge_and hF (H _ (half_pos F0)) in
⟨_, half_pos F0, i, λ j ij, begin
cases h j ij with h₁ h₂,
have := add_le_add h₁ (le_of_lt (abs_lt.1 h₂).1),
rwa [← sub_eq_add_neg, sub_self_div_two] at this
end⟩
protected theorem mul_pos {f g : cau_seq α abs} : pos f → pos g → pos (f * g)
| ⟨F, F0, hF⟩ ⟨G, G0, hG⟩ :=
let ⟨i, h⟩ := exists_forall_ge_and hF hG in
⟨_, _root_.mul_pos F0 G0, i,
λ j ij, let ⟨h₁, h₂⟩ := h _ ij in
mul_le_mul h₁ h₂ (le_of_lt G0) (le_trans (le_of_lt F0) h₁)⟩
theorem trichotomy (f : cau_seq α abs) : pos f ∨ lim_zero f ∨ pos (-f) :=
begin
cases classical.em (lim_zero f); simp *,
rcases abv_pos_of_not_lim_zero h with ⟨K, K0, hK⟩,
rcases exists_forall_ge_and hK (f.cauchy₃ K0) with ⟨i, hi⟩,
refine (le_total 0 (f i)).imp _ _;
refine (λ h, ⟨K, K0, i, λ j ij, _⟩);
have := (hi _ ij).1;
cases hi _ le_rfl with h₁ h₂,
{ rwa abs_of_nonneg at this,
rw abs_of_nonneg h at h₁,
exact (le_add_iff_nonneg_right _).1
(le_trans h₁ $ neg_le_sub_iff_le_add'.1 $
le_of_lt (abs_lt.1 $ h₂ _ ij).1) },
{ rwa abs_of_nonpos at this,
rw abs_of_nonpos h at h₁,
rw [← sub_le_sub_iff_right, zero_sub],
exact le_trans (le_of_lt (abs_lt.1 $ h₂ _ ij).2) h₁ }
end
instance : has_lt (cau_seq α abs) := ⟨λ f g, pos (g - f)⟩
instance : has_le (cau_seq α abs) := ⟨λ f g, f < g ∨ f ≈ g⟩
theorem lt_of_lt_of_eq {f g h : cau_seq α abs}
(fg : f < g) (gh : g ≈ h) : f < h :=
show pos (h - f),
by simpa [sub_eq_add_neg, add_comm, add_left_comm] using pos_add_lim_zero fg (neg_lim_zero gh)
theorem lt_of_eq_of_lt {f g h : cau_seq α abs}
(fg : f ≈ g) (gh : g < h) : f < h :=
by have := pos_add_lim_zero gh (neg_lim_zero fg);
rwa [← sub_eq_add_neg, sub_sub_sub_cancel_right] at this
theorem lt_trans {f g h : cau_seq α abs} (fg : f < g) (gh : g < h) : f < h :=
show pos (h - f),
by simpa [sub_eq_add_neg, add_comm, add_left_comm] using add_pos fg gh
theorem lt_irrefl {f : cau_seq α abs} : ¬ f < f
| h := not_lim_zero_of_pos h (by simp [zero_lim_zero])
lemma le_of_eq_of_le {f g h : cau_seq α abs}
(hfg : f ≈ g) (hgh : g ≤ h) : f ≤ h :=
hgh.elim (or.inl ∘ cau_seq.lt_of_eq_of_lt hfg)
(or.inr ∘ setoid.trans hfg)
lemma le_of_le_of_eq {f g h : cau_seq α abs}
(hfg : f ≤ g) (hgh : g ≈ h) : f ≤ h :=
hfg.elim (λ h, or.inl (cau_seq.lt_of_lt_of_eq h hgh))
(λ h, or.inr (setoid.trans h hgh))
instance : preorder (cau_seq α abs) :=
{ lt := (<),
le := λ f g, f < g ∨ f ≈ g,
le_refl := λ f, or.inr (setoid.refl _),
le_trans := λ f g h fg, match fg with
| or.inl fg, or.inl gh := or.inl $ lt_trans fg gh
| or.inl fg, or.inr gh := or.inl $ lt_of_lt_of_eq fg gh
| or.inr fg, or.inl gh := or.inl $ lt_of_eq_of_lt fg gh
| or.inr fg, or.inr gh := or.inr $ setoid.trans fg gh
end,
lt_iff_le_not_le := λ f g,
⟨λ h, ⟨or.inl h,
not_or (mt (lt_trans h) lt_irrefl) (not_lim_zero_of_pos h)⟩,
λ ⟨h₁, h₂⟩, h₁.resolve_right
(mt (λ h, or.inr (setoid.symm h)) h₂)⟩ }
theorem le_antisymm {f g : cau_seq α abs} (fg : f ≤ g) (gf : g ≤ f) : f ≈ g :=
fg.resolve_left (not_lt_of_le gf)
theorem lt_total (f g : cau_seq α abs) : f < g ∨ f ≈ g ∨ g < f :=
(trichotomy (g - f)).imp_right
(λ h, h.imp (λ h, setoid.symm h) (λ h, by rwa neg_sub at h))
theorem le_total (f g : cau_seq α abs) : f ≤ g ∨ g ≤ f :=
(or.assoc.2 (lt_total f g)).imp_right or.inl
theorem const_lt {x y : α} : const x < const y ↔ x < y :=
show pos _ ↔ _, by rw [← const_sub, const_pos, sub_pos]
theorem const_le {x y : α} : const x ≤ const y ↔ x ≤ y :=
by rw le_iff_lt_or_eq; exact or_congr const_lt const_equiv
lemma le_of_exists {f g : cau_seq α abs}
(h : ∃ i, ∀ j ≥ i, f j ≤ g j) : f ≤ g :=
let ⟨i, hi⟩ := h in
(or.assoc.2 (cau_seq.lt_total f g)).elim
id
(λ hgf, false.elim (let ⟨K, hK0, j, hKj⟩ := hgf in
not_lt_of_ge (hi (max i j) (le_max_left _ _))
(sub_pos.1 (lt_of_lt_of_le hK0 (hKj _ (le_max_right _ _))))))
theorem exists_gt (f : cau_seq α abs) : ∃ a : α, f < const a :=
let ⟨K, H⟩ := f.bounded in
⟨K + 1, 1, zero_lt_one, 0, λ i _, begin
rw [sub_apply, const_apply, le_sub_iff_add_le', add_le_add_iff_right],
exact le_of_lt (abs_lt.1 (H _)).2
end⟩
theorem exists_lt (f : cau_seq α abs) : ∃ a : α, const a < f :=
let ⟨a, h⟩ := (-f).exists_gt in ⟨-a, show pos _,
by rwa [const_neg, sub_neg_eq_add, add_comm, ← sub_neg_eq_add]⟩
end abs
end cau_seq
|
f574f4202a4059a08c29da00d70b87edfac76e40 | 82e44445c70db0f03e30d7be725775f122d72f3e | /src/group_theory/quotient_group.lean | e715716318fa19baec5322fa0c21da5340b3c74a | [
"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 | 16,532 | lean | /-
Copyright (c) 2018 Kevin Buzzard, Patrick Massot. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kevin Buzzard, Patrick Massot
This file is to a certain extent based on `quotient_module.lean` by Johannes Hölzl.
-/
import group_theory.coset
/-!
# Quotients of groups by normal subgroups
This files develops the basic theory of quotients of groups by normal subgroups. In particular it
proves Noether's first and second isomorphism theorems.
## Main definitions
* `mk'`: the canonical group homomorphism `G →* G/N` given a normal subgroup `N` of `G`.
* `lift φ`: the group homomorphism `G/N →* H` given a group homomorphism `φ : G →* H` such that
`N ⊆ ker φ`.
* `map f`: the group homomorphism `G/N →* H/M` given a group homomorphism `f : G →* H` such that
`N ⊆ f⁻¹(M)`.
## Main statements
* `quotient_ker_equiv_range`: Noether's first isomorphism theorem, an explicit isomorphism
`G/ker φ → range φ` for every group homomorphism `φ : G →* H`.
* `quotient_inf_equiv_prod_normal_quotient`: Noether's second isomorphism theorem, an explicit
isomorphism between `H/(H ∩ N)` and `(HN)/N` given a subgroup `H` and a normal subgroup `N` of a
group `G`.
* `quotient_group.quotient_quotient_equiv_quotient`: Noether's third isomorphism theorem,
the canonical isomorphism between `(G / M) / (M / N)` and `G / N`, where `N ≤ M`.
## Tags
isomorphism theorems, quotient groups
-/
universes u v
namespace quotient_group
variables {G : Type u} [group G] (N : subgroup G) [nN : N.normal] {H : Type v} [group H]
include nN
-- Define the `div_inv_monoid` before the `group` structure,
-- to make sure we have `inv` fully defined before we show `mul_left_inv`.
-- TODO: is there a non-invasive way of defining this in one declaration?
@[to_additive quotient_add_group.div_inv_monoid]
instance : div_inv_monoid (quotient N) :=
{ one := (1 : G),
mul := quotient.map₂' (*)
(λ a₁ b₁ hab₁ a₂ b₂ hab₂,
((N.mul_mem_cancel_right (N.inv_mem hab₂)).1
(by rw [mul_inv_rev, mul_inv_rev, ← mul_assoc (a₂⁻¹ * a₁⁻¹),
mul_assoc _ b₂, ← mul_assoc b₂, mul_inv_self, one_mul, mul_assoc (a₂⁻¹)];
exact nN.conj_mem _ hab₁ _))),
mul_assoc := λ a b c, quotient.induction_on₃' a b c
(λ a b c, congr_arg mk (mul_assoc a b c)),
one_mul := λ a, quotient.induction_on' a
(λ a, congr_arg mk (one_mul a)),
mul_one := λ a, quotient.induction_on' a
(λ a, congr_arg mk (mul_one a)),
inv := λ a, quotient.lift_on' a (λ a, ((a⁻¹ : G) : quotient N))
(λ a b hab, quotient.sound' begin
show a⁻¹⁻¹ * b⁻¹ ∈ N,
rw ← mul_inv_rev,
exact N.inv_mem (nN.mem_comm hab)
end) }
@[to_additive quotient_add_group.add_group]
instance : group (quotient N) :=
{ mul_left_inv := λ a, quotient.induction_on' a
(λ a, congr_arg mk (mul_left_inv a)),
.. quotient.div_inv_monoid _ }
/-- The group homomorphism from `G` to `G/N`. -/
@[to_additive quotient_add_group.mk' "The additive group homomorphism from `G` to `G/N`."]
def mk' : G →* quotient N := monoid_hom.mk' (quotient_group.mk) (λ _ _, rfl)
@[to_additive, simp]
lemma coe_mk' : (mk' N : G → quotient N) = coe := rfl
@[to_additive, simp]
lemma mk'_apply (x : G) : mk' N x = x := rfl
@[simp, to_additive quotient_add_group.eq_zero_iff]
lemma eq_one_iff {N : subgroup G} [nN : N.normal] (x : G) : (x : quotient N) = 1 ↔ x ∈ N :=
begin
refine quotient_group.eq.trans _,
rw [mul_one, subgroup.inv_mem_iff],
end
@[simp, to_additive quotient_add_group.ker_mk]
lemma ker_mk :
monoid_hom.ker (quotient_group.mk' N : G →* quotient_group.quotient N) = N :=
subgroup.ext eq_one_iff
@[to_additive quotient_add_group.eq_iff_sub_mem]
lemma eq_iff_div_mem {N : subgroup G} [nN : N.normal] {x y : G} :
(x : quotient N) = y ↔ x / y ∈ N :=
begin
refine eq_comm.trans (quotient_group.eq.trans _),
rw [nN.mem_comm_iff, div_eq_mul_inv]
end
-- for commutative groups we don't need normality assumption
omit nN
@[to_additive quotient_add_group.add_comm_group]
instance {G : Type*} [comm_group G] (N : subgroup G) : comm_group (quotient N) :=
{ mul_comm := λ a b, quotient.induction_on₂' a b
(λ a b, congr_arg mk (mul_comm a b)),
.. @quotient_group.quotient.group _ _ N N.normal_of_comm }
include nN
local notation ` Q ` := quotient N
@[simp, to_additive quotient_add_group.coe_zero]
lemma coe_one : ((1 : G) : Q) = 1 := rfl
@[simp, to_additive quotient_add_group.coe_add]
lemma coe_mul (a b : G) : ((a * b : G) : Q) = a * b := rfl
@[simp, to_additive quotient_add_group.coe_neg]
lemma coe_inv (a : G) : ((a⁻¹ : G) : Q) = a⁻¹ := rfl
@[simp] lemma coe_pow (a : G) (n : ℕ) : ((a ^ n : G) : Q) = a ^ n :=
(mk' N).map_pow a n
@[simp] lemma coe_gpow (a : G) (n : ℤ) : ((a ^ n : G) : Q) = a ^ n :=
(mk' N).map_gpow a n
/-- A group homomorphism `φ : G →* H` with `N ⊆ ker(φ)` descends (i.e. `lift`s) to a
group homomorphism `G/N →* H`. -/
@[to_additive quotient_add_group.lift "An `add_group` homomorphism `φ : G →+ H` with `N ⊆ ker(φ)`
descends (i.e. `lift`s) to a group homomorphism `G/N →* H`."]
def lift (φ : G →* H) (HN : ∀x∈N, φ x = 1) : Q →* H :=
monoid_hom.mk'
(λ q : Q, q.lift_on' φ $ assume a b (hab : a⁻¹ * b ∈ N),
(calc φ a = φ a * 1 : (mul_one _).symm
... = φ a * φ (a⁻¹ * b) : HN (a⁻¹ * b) hab ▸ rfl
... = φ (a * (a⁻¹ * b)) : (φ.map_mul a (a⁻¹ * b)).symm
... = φ b : by rw mul_inv_cancel_left))
(λ q r, quotient.induction_on₂' q r $ φ.map_mul)
@[simp, to_additive quotient_add_group.lift_mk]
lemma lift_mk {φ : G →* H} (HN : ∀x∈N, φ x = 1) (g : G) :
lift N φ HN (g : Q) = φ g := rfl
@[simp, to_additive quotient_add_group.lift_mk']
lemma lift_mk' {φ : G →* H} (HN : ∀x∈N, φ x = 1) (g : G) :
lift N φ HN (mk g : Q) = φ g := rfl
@[simp, to_additive quotient_add_group.lift_quot_mk]
lemma lift_quot_mk {φ : G →* H} (HN : ∀x∈N, φ x = 1) (g : G) :
lift N φ HN (quot.mk _ g : Q) = φ g := rfl
/-- A group homomorphism `f : G →* H` induces a map `G/N →* H/M` if `N ⊆ f⁻¹(M)`. -/
@[to_additive quotient_add_group.map "An `add_group` homomorphism `f : G →+ H` induces a map
`G/N →+ H/M` if `N ⊆ f⁻¹(M)`."]
def map (M : subgroup H) [M.normal] (f : G →* H) (h : N ≤ M.comap f) :
quotient N →* quotient M :=
begin
refine quotient_group.lift N ((mk' M).comp f) _,
assume x hx,
refine quotient_group.eq.2 _,
rw [mul_one, subgroup.inv_mem_iff],
exact h hx,
end
@[simp, to_additive quotient_add_group.map_coe] lemma map_coe
(M : subgroup H) [M.normal] (f : G →* H) (h : N ≤ M.comap f) (x : G) :
map N M f h ↑x = ↑(f x) :=
lift_mk' _ _ x
@[to_additive quotient_add_group.map_mk'] lemma map_mk'
(M : subgroup H) [M.normal] (f : G →* H) (h : N ≤ M.comap f) (x : G) :
map N M f h (mk' _ x) = ↑(f x) :=
quotient_group.lift_mk' _ _ x
omit nN
variables (φ : G →* H)
open function monoid_hom
/-- The induced map from the quotient by the kernel to the codomain. -/
@[to_additive quotient_add_group.ker_lift "The induced map from the quotient by the kernel to the
codomain."]
def ker_lift : quotient (ker φ) →* H :=
lift _ φ $ λ g, φ.mem_ker.mp
@[simp, to_additive quotient_add_group.ker_lift_mk]
lemma ker_lift_mk (g : G) : (ker_lift φ) g = φ g :=
lift_mk _ _ _
@[simp, to_additive quotient_add_group.ker_lift_mk']
lemma ker_lift_mk' (g : G) : (ker_lift φ) (mk g) = φ g :=
lift_mk' _ _ _
@[to_additive quotient_add_group.injective_ker_lift]
lemma ker_lift_injective : injective (ker_lift φ) :=
assume a b, quotient.induction_on₂' a b $
assume a b (h : φ a = φ b), quotient.sound' $
show a⁻¹ * b ∈ ker φ, by rw [mem_ker,
φ.map_mul, ← h, φ.map_inv, inv_mul_self]
-- Note that `ker φ` isn't definitionally `ker (φ.range_restrict)`
-- so there is a bit of annoying code duplication here
/-- The induced map from the quotient by the kernel to the range. -/
@[to_additive quotient_add_group.range_ker_lift "The induced map from the quotient by the kernel to
the range."]
def range_ker_lift : quotient (ker φ) →* φ.range :=
lift _ φ.range_restrict $ λ g hg, (mem_ker _).mp $ by rwa range_restrict_ker
@[to_additive quotient_add_group.range_ker_lift_injective]
lemma range_ker_lift_injective : injective (range_ker_lift φ) :=
assume a b, quotient.induction_on₂' a b $
assume a b (h : φ.range_restrict a = φ.range_restrict b), quotient.sound' $
show a⁻¹ * b ∈ ker φ, by rw [←range_restrict_ker, mem_ker,
φ.range_restrict.map_mul, ← h, φ.range_restrict.map_inv, inv_mul_self]
@[to_additive quotient_add_group.range_ker_lift_surjective]
lemma range_ker_lift_surjective : surjective (range_ker_lift φ) :=
begin
rintro ⟨_, g, rfl⟩,
use mk g,
refl,
end
/-- **Noether's first isomorphism theorem** (a definition): the canonical isomorphism between
`G/(ker φ)` to `range φ`. -/
@[to_additive quotient_add_group.quotient_ker_equiv_range "The first isomorphism theorem
(a definition): the canonical isomorphism between `G/(ker φ)` to `range φ`."]
noncomputable def quotient_ker_equiv_range : (quotient (ker φ)) ≃* range φ :=
mul_equiv.of_bijective (range_ker_lift φ) ⟨range_ker_lift_injective φ, range_ker_lift_surjective φ⟩
/-- The canonical isomorphism `G/(ker φ) ≃* H` induced by a homomorphism `φ : G →* H`
with a right inverse `ψ : H → G`. -/
@[to_additive quotient_add_group.quotient_ker_equiv_of_right_inverse "The canonical isomorphism
`G/(ker φ) ≃+ H` induced by a homomorphism `φ : G →+ H` with a right inverse `ψ : H → G`.",
simps]
def quotient_ker_equiv_of_right_inverse (ψ : H → G) (hφ : function.right_inverse ψ φ) :
quotient (ker φ) ≃* H :=
{ to_fun := ker_lift φ,
inv_fun := mk ∘ ψ,
left_inv := λ x, ker_lift_injective φ (by rw [function.comp_app, ker_lift_mk', hφ]),
right_inv := hφ,
.. ker_lift φ }
/-- The canonical isomorphism `G/(ker φ) ≃* H` induced by a surjection `φ : G →* H`.
For a `computable` version, see `quotient_group.quotient_ker_equiv_of_right_inverse`.
-/
@[to_additive quotient_add_group.quotient_ker_equiv_of_surjective "The canonical isomorphism
`G/(ker φ) ≃+ H` induced by a surjection `φ : G →+ H`.
For a `computable` version, see `quotient_add_group.quotient_ker_equiv_of_right_inverse`."]
noncomputable def quotient_ker_equiv_of_surjective (hφ : function.surjective φ) :
quotient (ker φ) ≃* H :=
quotient_ker_equiv_of_right_inverse φ _ hφ.has_right_inverse.some_spec
/-- If two normal subgroups `M` and `N` of `G` are the same, their quotient groups are
isomorphic. -/
@[to_additive "If two normal subgroups `M` and `N` of `G` are the same, their quotient groups are
isomorphic."]
def equiv_quotient_of_eq {M N : subgroup G} [M.normal] [N.normal] (h : M = N) :
quotient M ≃* quotient N :=
{ to_fun := (lift M (mk' N) (λ m hm, quotient_group.eq.mpr (by simpa [← h] using M.inv_mem hm))),
inv_fun := (lift N (mk' M) (λ n hn, quotient_group.eq.mpr (by simpa [← h] using N.inv_mem hn))),
left_inv := λ x, x.induction_on' $ by { intro, refl },
right_inv := λ x, x.induction_on' $ by { intro, refl },
map_mul' := λ x y, by rw map_mul }
/-- Let `A', A, B', B` be subgroups of `G`. If `A' ≤ B'` and `A ≤ B`,
then there is a map `A / (A' ⊓ A) →* B / (B' ⊓ B)` induced by the inclusions. -/
@[to_additive "Let `A', A, B', B` be subgroups of `G`. If `A' ≤ B'` and `A ≤ B`,
then there is a map `A / (A' ⊓ A) →+ B / (B' ⊓ B)` induced by the inclusions."]
def quotient_map_subgroup_of_of_le {A' A B' B : subgroup G}
[hAN : (A'.subgroup_of A).normal] [hBN : (B'.subgroup_of B).normal]
(h' : A' ≤ B') (h : A ≤ B) :
quotient (A'.subgroup_of A) →* quotient (B'.subgroup_of B) :=
map _ _ (subgroup.inclusion h) $
by simp [subgroup.subgroup_of, subgroup.comap_comap]; exact subgroup.comap_mono h'
/-- Let `A', A, B', B` be subgroups of `G`.
If `A' = B'` and `A = B`, then the quotients `A / (A' ⊓ A)` and `B / (B' ⊓ B)` are isomorphic.
Applying this equiv is nicer than rewriting along the equalities, since the type of
`(A'.subgroup_of A : subgroup A)` depends on on `A`.
-/
@[to_additive "Let `A', A, B', B` be subgroups of `G`.
If `A' = B'` and `A = B`, then the quotients `A / (A' ⊓ A)` and `B / (B' ⊓ B)` are isomorphic.
Applying this equiv is nicer than rewriting along the equalities, since the type of
`(A'.add_subgroup_of A : add_subgroup A)` depends on on `A`.
"]
def equiv_quotient_subgroup_of_of_eq {A' A B' B : subgroup G}
[hAN : (A'.subgroup_of A).normal] [hBN : (B'.subgroup_of B).normal]
(h' : A' = B') (h : A = B) :
quotient (A'.subgroup_of A) ≃* quotient (B'.subgroup_of B) :=
by apply monoid_hom.to_mul_equiv
(quotient_map_subgroup_of_of_le h'.le h.le) (quotient_map_subgroup_of_of_le h'.ge h.ge);
{ ext ⟨x⟩, simp [quotient_map_subgroup_of_of_le, map, lift, mk', subgroup.inclusion], refl }
section snd_isomorphism_thm
open subgroup
/-- **Noether's second isomorphism theorem**: given two subgroups `H` and `N` of a group `G`, where
`N` is normal, defines an isomorphism between `H/(H ∩ N)` and `(HN)/N`. -/
@[to_additive "The second isomorphism theorem: given two subgroups `H` and `N` of a group `G`,
where `N` is normal, defines an isomorphism between `H/(H ∩ N)` and `(H + N)/N`"]
noncomputable def quotient_inf_equiv_prod_normal_quotient (H N : subgroup G) [N.normal] :
quotient ((H ⊓ N).comap H.subtype) ≃* quotient (N.comap (H ⊔ N).subtype) :=
/- φ is the natural homomorphism H →* (HN)/N. -/
let φ : H →* quotient (N.comap (H ⊔ N).subtype) :=
(mk' $ N.comap (H ⊔ N).subtype).comp (inclusion le_sup_left) in
have φ_surjective : function.surjective φ := λ x, x.induction_on' $
begin
rintro ⟨y, (hy : y ∈ ↑(H ⊔ N))⟩, rw mul_normal H N at hy,
rcases hy with ⟨h, n, hh, hn, rfl⟩,
use [h, hh], apply quotient.eq.mpr, change h⁻¹ * (h * n) ∈ N,
rwa [←mul_assoc, inv_mul_self, one_mul],
end,
(equiv_quotient_of_eq (by simp [comap_comap, ←comap_ker])).trans
(quotient_ker_equiv_of_surjective φ φ_surjective)
end snd_isomorphism_thm
section third_iso_thm
variables (M : subgroup G) [nM : M.normal]
include nM nN
@[to_additive quotient_add_group.map_normal]
instance map_normal : (M.map (quotient_group.mk' N)).normal :=
{ conj_mem := begin
rintro _ ⟨x, hx, rfl⟩ y,
refine induction_on' y (λ y, ⟨y * x * y⁻¹, subgroup.normal.conj_mem nM x hx y, _⟩),
simp only [mk'_apply, coe_mul, coe_inv]
end }
variables (h : N ≤ M)
/-- The map from the third isomorphism theorem for groups: `(G / N) / (M / N) → G / M`. -/
@[to_additive quotient_add_group.quotient_quotient_equiv_quotient_aux
"The map from the third isomorphism theorem for additive groups: `(A / N) / (M / N) → A / M`."]
def quotient_quotient_equiv_quotient_aux :
quotient (M.map (mk' N)) →* quotient M :=
lift (M.map (mk' N))
(map N M (monoid_hom.id G) h)
(by { rintro _ ⟨x, hx, rfl⟩, rw map_mk' N M _ _ x,
exact (quotient_group.eq_one_iff _).mpr hx })
@[simp, to_additive quotient_add_group.quotient_quotient_equiv_quotient_aux_coe]
lemma quotient_quotient_equiv_quotient_aux_coe (x : quotient_group.quotient N) :
quotient_quotient_equiv_quotient_aux N M h x = quotient_group.map N M (monoid_hom.id G) h x :=
quotient_group.lift_mk' _ _ x
@[to_additive quotient_add_group.quotient_quotient_equiv_quotient_aux_coe_coe]
lemma quotient_quotient_equiv_quotient_aux_coe_coe (x : G) :
quotient_quotient_equiv_quotient_aux N M h (x : quotient_group.quotient N) =
x :=
quotient_group.lift_mk' _ _ x
/-- **Noether's third isomorphism theorem** for groups: `(G / N) / (M / N) ≃ G / M`. -/
@[to_additive quotient_add_group.quotient_quotient_equiv_quotient
"**Noether's third isomorphism theorem** for additive groups: `(A / N) / (M / N) ≃ A / M`."]
def quotient_quotient_equiv_quotient :
quotient_group.quotient (M.map (quotient_group.mk' N)) ≃* quotient_group.quotient M :=
{ to_fun := quotient_quotient_equiv_quotient_aux N M h,
inv_fun := quotient_group.map _ _ (quotient_group.mk' N) (subgroup.le_comap_map _ _),
left_inv := λ x, quotient_group.induction_on' x $ λ x, quotient_group.induction_on' x $
λ x, by simp,
right_inv := λ x, quotient_group.induction_on' x $ λ x, by simp,
map_mul' := monoid_hom.map_mul _ }
end third_iso_thm
end quotient_group
|
18f072c16f814b62fc05b4c8b2e6d2f00d041a04 | 968e2f50b755d3048175f176376eff7139e9df70 | /examples/prop_logic_lean_summary/unnamed_295.lean | f20ddce2278964ee2f9d8429fcff5af4699bace0 | [] | no_license | gihanmarasingha/mth1001_sphinx | 190a003269ba5e54717b448302a27ca26e31d491 | 05126586cbf5786e521be1ea2ef5b4ba3c44e74a | refs/heads/master | 1,672,913,933,677 | 1,604,516,583,000 | 1,604,516,583,000 | 309,245,750 | 1 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 84 | lean | variables p q : Prop
-- BEGIN
example (k : q) : p → q :=
assume h : p,
k
-- END |
789a59d48b22a1563fc0b29d523f1a9f1776aad7 | e00ea76a720126cf9f6d732ad6216b5b824d20a7 | /src/data/list/min_max.lean | 48a3fe3964e2c762d2cde70e6f09f6da86ef9da9 | [
"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 | 11,232 | lean | /-
Copyright (c) 2019 Minchao Wu. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Minchao Wu, Chris Hughes
-/
import data.list.basic
/-
# Minimum and maximum of lists
## Main definitions
The main definitions are `argmax`, `argmin`, `minimum` and `maximum` for lists.
`argmax f l` returns `some a`, where `a` of `l` that maximises `f a`. If there are `a b` such that
`f a = f b`, it returns whichever of `a` or `b` comes first in the list.
`argmax f []` = none`
`minimum l` returns an `with_top α`, the smallest element of `l` for nonempty lists, and `⊤` for
`[]`
-/
namespace list
variables {α : Type*} {β : Type*} [decidable_linear_order β]
/-- Auxiliary definition to define `argmax` -/
def argmax₂ (f : α → β) (a : option α) (b : α) : option α :=
option.cases_on a (some b) (λ c, if f b ≤ f c then some c else some b)
/-- `argmax f l` returns `some a`, where `a` of `l` that maximises `f a`. If there are `a b` such that
`f a = f b`, it returns whichever of `a` or `b` comes first in the list.
`argmax f []` = none` -/
def argmax (f : α → β) (l : list α) : option α :=
l.foldl (argmax₂ f) none
/-- `argmin f l` returns `some a`, where `a` of `l` that minimises `f a`. If there are `a b` such that
`f a = f b`, it returns whichever of `a` or `b` comes first in the list.
`argmin f []` = none` -/
def argmin (f : α → β) (l : list α) :=
@argmax _ (order_dual β) _ f l
@[simp] lemma argmax_two_self (f : α → β) (a : α) : argmax₂ f (some a) a = a :=
if_pos (le_refl _)
@[simp] lemma argmax_nil (f : α → β) : argmax f [] = none := rfl
@[simp] lemma argmin_nil (f : α → β) : argmin f [] = none := rfl
@[simp] lemma argmax_singleton {f : α → β} {a : α} : argmax f [a] = some a := rfl
@[simp] lemma argmin_singleton {f : α → β} {a : α} : argmin f [a] = a := rfl
@[simp] lemma foldl_argmax₂_eq_none {f : α → β} {l : list α} {o : option α} :
l.foldl (argmax₂ f) o = none ↔ l = [] ∧ o = none :=
list.reverse_rec_on l (by simp) $
(assume tl hd, by simp [argmax₂];
cases foldl (argmax₂ f) o tl; simp; try {split_ifs}; simp)
private theorem le_of_foldl_argmax₂ {f : α → β} {l} : Π {a m : α} {o : option α}, a ∈ l →
m ∈ foldl (argmax₂ f) o l → f a ≤ f m :=
list.reverse_rec_on l
(λ _ _ _ h, absurd h $ not_mem_nil _)
begin
intros tl _ ih _ _ _ h ho,
rw [foldl_append, foldl_cons, foldl_nil, argmax₂] at ho,
cases hf : foldl (argmax₂ f) o tl,
{ rw [hf] at ho,
rw [foldl_argmax₂_eq_none] at hf,
simp [hf.1, hf.2, *] at * },
rw [hf, option.mem_def] at ho,
dsimp only at ho,
cases mem_append.1 h with h h,
{ refine le_trans (ih h hf) _,
have := @le_of_lt _ _ (f val) (f m),
split_ifs at ho;
simp * at * },
{ split_ifs at ho;
simp * at * }
end
private theorem foldl_argmax₂_mem (f : α → β) (l) : Π (a m : α),
m ∈ foldl (argmax₂ f) (some a) l → m ∈ a :: l :=
list.reverse_rec_on l (by simp [eq_comm])
begin
assume tl hd ih a m,
simp only [foldl_append, foldl_cons, foldl_nil, argmax₂],
cases hf : foldl (argmax₂ f) (some a) tl,
{ simp {contextual := tt} },
{ dsimp only, split_ifs,
{ finish [ih _ _ hf] },
{ simp {contextual := tt} } }
end
theorem argmax_mem {f : α → β} : Π {l : list α} {m : α}, m ∈ argmax f l → m ∈ l
| [] m := by simp
| (hd::tl) m := by simpa [argmax, argmax₂] using foldl_argmax₂_mem f tl hd m
theorem argmin_mem {f : α → β} : Π {l : list α} {m : α}, m ∈ argmin f l → m ∈ l :=
@argmax_mem _ (order_dual β) _ _
@[simp] theorem argmax_eq_none {f : α → β} {l : list α} : l.argmax f = none ↔ l = [] :=
by simp [argmax]
@[simp] theorem argmin_eq_none {f : α → β} {l : list α} : l.argmin f = none ↔ l = [] :=
@argmax_eq_none _ (order_dual β) _ _ _
theorem le_argmax_of_mem {f : α → β} {a m : α} {l : list α} : a ∈ l → m ∈ argmax f l → f a ≤ f m :=
le_of_foldl_argmax₂
theorem argmin_le_of_mem {f : α → β} {a m : α} {l : list α} : a ∈ l → m ∈ argmin f l → f m ≤ f a:=
@le_argmax_of_mem _ (order_dual β) _ _ _ _ _
theorem argmax_concat (f : α → β) (a : α) (l : list α) : argmax f (l ++ [a]) =
option.cases_on (argmax f l) (some a) (λ c, if f a ≤ f c then some c else some a) :=
by rw [argmax, argmax]; simp [argmax₂]
theorem argmin_concat (f : α → β) (a : α) (l : list α) : argmin f (l ++ [a]) =
option.cases_on (argmin f l) (some a) (λ c, if f c ≤ f a then some c else some a) :=
@argmax_concat _ (order_dual β) _ _ _ _
theorem argmax_cons (f : α → β) (a : α) (l : list α) : argmax f (a :: l) =
option.cases_on (argmax f l) (some a) (λ c, if f c ≤ f a then some a else some c) :=
list.reverse_rec_on l rfl $
assume hd tl ih, begin
rw [← cons_append, argmax_concat, ih, argmax_concat],
cases h : argmax f hd with m,
{ simp [h] },
{ simp [h], dsimp,
by_cases ham : f m ≤ f a,
{ rw if_pos ham, dsimp,
by_cases htlm : f tl ≤ f m,
{ rw if_pos htlm, dsimp,
rw [if_pos (le_trans htlm ham), if_pos ham] },
{ rw if_neg htlm } },
{ rw if_neg ham, dsimp,
by_cases htlm : f tl ≤ f m,
{ rw if_pos htlm, dsimp,
rw if_neg ham },
{ rw if_neg htlm, dsimp,
rw [if_neg (not_le_of_gt (lt_trans (lt_of_not_ge ham) (lt_of_not_ge htlm)))] } } }
end
theorem argmin_cons (f : α → β) (a : α) (l : list α) : argmin f (a :: l) =
option.cases_on (argmin f l) (some a) (λ c, if f a ≤ f c then some a else some c) :=
@argmax_cons _ (order_dual β) _ _ _ _
theorem index_of_argmax [decidable_eq α] {f : α → β} : Π {l : list α} {m : α}, m ∈ argmax f l →
∀ {a}, a ∈ l → f m ≤ f a → l.index_of m ≤ l.index_of a
| [] m _ _ _ _ := by simp
| (hd::tl) m hm a ha ham := begin
simp only [index_of_cons, argmax_cons, option.mem_def] at ⊢ hm,
cases h : argmax f tl,
{ rw h at hm,
simp * at * },
{ rw h at hm,
dsimp only at hm,
cases ha with hahd hatl,
{ clear index_of_argmax,
subst hahd,
split_ifs at hm,
{ subst hm },
{ subst hm, contradiction } },
{ have := index_of_argmax h hatl, clear index_of_argmax,
split_ifs at *;
refl <|> exact nat.zero_le _ <|> simp [*, nat.succ_le_succ_iff, -not_le] at * } }
end
theorem index_of_argmin [decidable_eq α] {f : α → β} : Π {l : list α} {m : α}, m ∈ argmin f l →
∀ {a}, a ∈ l → f a ≤ f m → l.index_of m ≤ l.index_of a :=
@index_of_argmax _ (order_dual β) _ _ _
theorem mem_argmax_iff [decidable_eq α] {f : α → β} {m : α} {l : list α} :
m ∈ argmax f l ↔ m ∈ l ∧ (∀ a ∈ l, f a ≤ f m) ∧
(∀ a ∈ l, f m ≤ f a → l.index_of m ≤ l.index_of a) :=
⟨λ hm, ⟨argmax_mem hm, λ a ha, le_argmax_of_mem ha hm, λ _, index_of_argmax hm⟩,
begin
rintros ⟨hml, ham, hma⟩,
cases harg : argmax f l with n,
{ simp * at * },
{ have := le_antisymm (hma n (argmax_mem harg) (le_argmax_of_mem hml harg))
(index_of_argmax harg hml (ham _ (argmax_mem harg))),
rw [(index_of_inj hml (argmax_mem harg)).1 this, option.mem_def] }
end⟩
theorem argmax_eq_some_iff [decidable_eq α] {f : α → β} {m : α} {l : list α} :
argmax f l = some m ↔ m ∈ l ∧ (∀ a ∈ l, f a ≤ f m) ∧
(∀ a ∈ l, f m ≤ f a → l.index_of m ≤ l.index_of a) := mem_argmax_iff
theorem mem_argmin_iff [decidable_eq α] {f : α → β} {m : α} {l : list α} :
m ∈ argmin f l ↔ m ∈ l ∧ (∀ a ∈ l, f m ≤ f a) ∧
(∀ a ∈ l, f a ≤ f m → l.index_of m ≤ l.index_of a) :=
@mem_argmax_iff _ (order_dual β) _ _ _ _ _
theorem argmin_eq_some_iff [decidable_eq α] {f : α → β} {m : α} {l : list α} :
argmin f l = some m ↔ m ∈ l ∧ (∀ a ∈ l, f m ≤ f a) ∧
(∀ a ∈ l, f a ≤ f m → l.index_of m ≤ l.index_of a) := mem_argmin_iff
variable [decidable_linear_order α]
/-- `maximum l` returns an `with_bot α`, the largest element of `l` for nonempty lists, and `⊥` for
`[]` -/
def maximum (l : list α) : with_bot α := argmax id l
/-- `minimum l` returns an `with_top α`, the smallest element of `l` for nonempty lists, and `⊤` for
`[]` -/
def minimum (l : list α) : with_top α := argmin id l
@[simp] lemma maximum_nil : maximum ([] : list α) = ⊥ := rfl
@[simp] lemma minimum_nil : minimum ([] : list α) = ⊤ := rfl
@[simp] lemma maximum_singleton (a : α) : maximum [a] = a := rfl
@[simp] lemma minimum_singleton (a : α) : minimum [a] = a := rfl
theorem maximum_mem {l : list α} {m : α} : (maximum l : with_top α) = m → m ∈ l := argmax_mem
theorem minimum_mem {l : list α} {m : α} : (minimum l : with_bot α) = m → m ∈ l := argmin_mem
@[simp] theorem maximum_eq_none {l : list α} : l.maximum = none ↔ l = [] := argmax_eq_none
@[simp] theorem minimum_eq_none {l : list α} : l.minimum = none ↔ l = [] := argmin_eq_none
theorem le_maximum_of_mem {a m : α} {l : list α} : a ∈ l → (maximum l : with_bot α) = m → a ≤ m :=
le_argmax_of_mem
theorem minimum_le_of_mem {a m : α} {l : list α} : a ∈ l → (minimum l : with_top α) = m → m ≤ a :=
argmin_le_of_mem
theorem le_maximum_of_mem' {a : α} {l : list α} (ha : a ∈ l) : (a : with_bot α) ≤ maximum l :=
option.cases_on (maximum l) (λ _ h, absurd ha ((h rfl).symm ▸ not_mem_nil _))
(λ m hm _, with_bot.coe_le_coe.2 $ hm _ rfl)
(λ m, @le_maximum_of_mem _ _ _ m _ ha)
(@maximum_eq_none _ _ l).1
theorem le_minimum_of_mem' {a : α} {l : list α} (ha : a ∈ l) : minimum l ≤ (a : with_top α) :=
@le_maximum_of_mem' (order_dual α) _ _ _ ha
theorem maximum_concat (a : α) (l : list α) : maximum (l ++ [a]) = max (maximum l) a :=
begin
rw max_comm,
simp only [maximum, argmax_concat, id, max],
cases h : argmax id l,
{ rw [if_neg], refl, exact not_le_of_gt (with_bot.bot_lt_some _) },
change (coe : α → with_bot α) with some,
simp, congr
end
theorem minimum_concat (a : α) (l : list α) : minimum (l ++ [a]) = min (minimum l) a :=
by simp only [min_comm _ (a : with_top α)]; exact @maximum_concat (order_dual α) _ _ _
theorem maximum_cons (a : α) (l : list α) : maximum (a :: l) = max a (maximum l) :=
list.reverse_rec_on l (by simp [@max_eq_left (with_bot α) _ _ _ bot_le])
(λ tl hd ih, by rw [← cons_append, maximum_concat, ih, maximum_concat, max_assoc])
theorem minimum_cons (a : α) (l : list α) : minimum (a :: l) = min a (minimum l) :=
min_comm (minimum l) a ▸ @maximum_cons (order_dual α) _ _ _
theorem maximum_eq_coe_iff {m : α} {l : list α} :
maximum l = m ↔ m ∈ l ∧ (∀ a ∈ l, a ≤ m) :=
begin
unfold_coes,
simp only [maximum, argmax_eq_some_iff, id],
split,
{ simp only [true_and, forall_true_iff] {contextual := tt} },
{ simp only [true_and, forall_true_iff] {contextual := tt},
intros h a hal hma,
rw [le_antisymm hma (h.2 a hal)] }
end
theorem minimum_eq_coe_iff {m : α} {l : list α} :
minimum l = m ↔ m ∈ l ∧ (∀ a ∈ l, m ≤ a) :=
@maximum_eq_coe_iff (order_dual α) _ _ _
end list
|
639ccc8faa4f8ffd023d2cc9d61dcc66c1bc6745 | e61a235b8468b03aee0120bf26ec615c045005d2 | /src/Init/Lean/Data/Json/Printer.lean | 62c92ef4331dcfdc9d1d3ba2bb8bf335e9db681d | [
"Apache-2.0"
] | permissive | SCKelemen/lean4 | 140dc63a80539f7c61c8e43e1c174d8500ec3230 | e10507e6615ddbef73d67b0b6c7f1e4cecdd82bc | refs/heads/master | 1,660,973,595,917 | 1,590,278,033,000 | 1,590,278,033,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 2,378 | lean | /-
Copyright (c) 2019 Gabriel Ebner. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Gabriel Ebner, Marc Huisinga
-/
prelude
import Init.Lean.Data.Format
import Init.Lean.Data.Json.Basic
namespace Lean
namespace Json
private def escapeAux (c : Char) (acc : String) : String :=
-- escape ", \, \n and \r, keep all other characters ≥ 0x20 and render characters < 0x20 with \u
if c = '"' then -- hack to prevent emacs from regarding the rest of the file as a string: "
"\\\"" ++ acc
else if c = '\\' then
"\\\\" ++ acc
else if c = '\n' then
"\\n" ++ acc
else if c = '\x0d' then
"\\r" ++ acc
-- the c.val ≤ 0x10ffff check is technically redundant,
-- since Lean chars are unicode scalar values ≤ 0x10ffff.
-- as to whether c.val > 0xffff should be split up and encoded with multiple \u,
-- the JSON standard is not definite: both directly printing the character
-- and encoding it with multiple \u is allowed, and it is up to parsers to make the
-- decision.
else if 0x0020 ≤ c.val ∧ c.val ≤ 0x10ffff then
String.singleton c ++ acc
else
let n := c.toNat;
-- since c.val < 0x20 in this case, this conversion is more involved than necessary
-- (but we keep it for completeness)
"\\u" ++
[ Nat.digitChar (n / 4096),
Nat.digitChar ((n % 4096) / 256),
Nat.digitChar ((n % 256) / 16),
Nat.digitChar (n % 16) ].asString ++
acc
def escape (s : String) : String :=
s.foldr escapeAux ""
def renderString (s : String) : String :=
"\"" ++ escape s ++ "\""
section
variables {α : Type}
@[specialize]
partial def render : Json → Format
| null => "null"
| bool true => "true"
| bool false => "false"
| num s => s.toString
| str s => renderString s
| arr elems =>
let elems := Format.joinSep (elems.map render).toList ("," ++ Format.line);
Format.bracket "[" elems "]"
| obj kvs =>
let renderKV : String → Json → Format := fun k v =>
Format.group (renderString k ++ ":" ++ Format.line ++ render v);
let kvs := Format.joinSep (kvs.fold (fun acc k j => renderKV k j :: acc) []) ("," ++ Format.line);
Format.bracket "{" kvs "}"
end
def pretty (j : Json) (lineWidth := 80) : String :=
Format.prettyAux (render j) lineWidth
instance jsonHasFormat : HasFormat Json := ⟨render⟩
instance jsonHasToString : HasToString Json := ⟨pretty⟩
end Json
end Lean
|
9cd8d8ef2b45cd98947a8629246c0488077b0343 | 6e9cd8d58e550c481a3b45806bd34a3514c6b3e0 | /src/topology/metric_space/basic.lean | b327cf8052818970a805d441f71bda939dd01b36 | [
"Apache-2.0"
] | permissive | sflicht/mathlib | 220fd16e463928110e7b0a50bbed7b731979407f | 1b2048d7195314a7e34e06770948ee00f0ac3545 | refs/heads/master | 1,665,934,056,043 | 1,591,373,803,000 | 1,591,373,803,000 | 269,815,267 | 0 | 0 | Apache-2.0 | 1,591,402,068,000 | 1,591,402,067,000 | null | UTF-8 | Lean | false | false | 73,430 | lean | /-
Copyright (c) 2015, 2017 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Metric spaces.
Authors: Jeremy Avigad, Robert Y. Lewis, Johannes Hölzl, Mario Carneiro, Sébastien Gouëzel
Many definitions and theorems expected on metric spaces are already introduced on uniform spaces and
topological spaces. For example:
open and closed sets, compactness, completeness, continuity and uniform continuity
-/
import topology.metric_space.emetric_space
import topology.algebra.ordered
open set filter classical topological_space
noncomputable theory
open_locale uniformity topological_space
universes u v w
variables {α : Type u} {β : Type v} {γ : Type w}
/-- Construct a uniform structure from a distance function and metric space axioms -/
def uniform_space_of_dist
(dist : α → α → ℝ)
(dist_self : ∀ x : α, dist x x = 0)
(dist_comm : ∀ x y : α, dist x y = dist y x)
(dist_triangle : ∀ x y z : α, dist x z ≤ dist x y + dist y z) : uniform_space α :=
uniform_space.of_core {
uniformity := (⨅ ε>0, principal {p:α×α | dist p.1 p.2 < ε}),
refl := le_infi $ assume ε, le_infi $
by simp [set.subset_def, id_rel, dist_self, (>)] {contextual := tt},
comp := le_infi $ assume ε, le_infi $ assume h, lift'_le
(mem_infi_sets (ε / 2) $ mem_infi_sets (div_pos_of_pos_of_pos h two_pos) (subset.refl _)) $
have ∀ (a b c : α), dist a c < ε / 2 → dist c b < ε / 2 → dist a b < ε,
from assume a b c hac hcb,
calc dist a b ≤ dist a c + dist c b : dist_triangle _ _ _
... < ε / 2 + ε / 2 : add_lt_add hac hcb
... = ε : by rw [div_add_div_same, add_self_div_two],
by simpa [comp_rel],
symm := tendsto_infi.2 $ assume ε, tendsto_infi.2 $ assume h,
tendsto_infi' ε $ tendsto_infi' h $ tendsto_principal_principal.2 $ by simp [dist_comm] }
/-- The distance function (given an ambient metric space on `α`), which returns
a nonnegative real number `dist x y` given `x y : α`. -/
class has_dist (α : Type*) := (dist : α → α → ℝ)
export has_dist (dist)
section prio
set_option default_priority 100 -- see Note [default priority]
/-- Metric space
Each metric space induces a canonical `uniform_space` and hence a canonical `topological_space`.
This is enforced in the type class definition, by extending the `uniform_space` structure. When
instantiating a `metric_space` structure, the uniformity fields are not necessary, they will be
filled in by default. In the same way, each metric space induces an emetric space structure.
It is included in the structure, but filled in by default.
When one instantiates a metric space structure, for instance a product structure,
this makes it possible to use a uniform structure and an edistance that are exactly
the ones for the uniform spaces product and the emetric spaces products, thereby
ensuring that everything in defeq in diamonds.-/
class metric_space (α : Type u) extends has_dist α : Type u :=
(dist_self : ∀ x : α, dist x x = 0)
(eq_of_dist_eq_zero : ∀ {x y : α}, dist x y = 0 → x = y)
(dist_comm : ∀ x y : α, dist x y = dist y x)
(dist_triangle : ∀ x y z : α, dist x z ≤ dist x y + dist y z)
(edist : α → α → ennreal := λx y, ennreal.of_real (dist x y))
(edist_dist : ∀ x y : α, edist x y = ennreal.of_real (dist x y) . control_laws_tac)
(to_uniform_space : uniform_space α := uniform_space_of_dist dist dist_self dist_comm dist_triangle)
(uniformity_dist : 𝓤 α = ⨅ ε>0, principal {p:α×α | dist p.1 p.2 < ε} . control_laws_tac)
end prio
variables [metric_space α]
@[priority 100] -- see Note [lower instance priority]
instance metric_space.to_uniform_space' : uniform_space α :=
metric_space.to_uniform_space
@[priority 200] -- see Note [lower instance priority]
instance metric_space.to_has_edist : has_edist α := ⟨metric_space.edist⟩
@[simp] theorem dist_self (x : α) : dist x x = 0 := metric_space.dist_self x
theorem eq_of_dist_eq_zero {x y : α} : dist x y = 0 → x = y :=
metric_space.eq_of_dist_eq_zero
theorem dist_comm (x y : α) : dist x y = dist y x := metric_space.dist_comm x y
theorem edist_dist (x y : α) : edist x y = ennreal.of_real (dist x y) :=
metric_space.edist_dist x y
@[simp] theorem dist_eq_zero {x y : α} : dist x y = 0 ↔ x = y :=
iff.intro eq_of_dist_eq_zero (assume : x = y, this ▸ dist_self _)
@[simp] theorem zero_eq_dist {x y : α} : 0 = dist x y ↔ x = y :=
by rw [eq_comm, dist_eq_zero]
theorem dist_triangle (x y z : α) : dist x z ≤ dist x y + dist y z :=
metric_space.dist_triangle x y z
theorem dist_triangle_left (x y z : α) : dist x y ≤ dist z x + dist z y :=
by rw dist_comm z; apply dist_triangle
theorem dist_triangle_right (x y z : α) : dist x y ≤ dist x z + dist y z :=
by rw dist_comm y; apply dist_triangle
lemma dist_triangle4 (x y z w : α) :
dist x w ≤ dist x y + dist y z + dist z w :=
calc
dist x w ≤ dist x z + dist z w : dist_triangle x z w
... ≤ (dist x y + dist y z) + dist z w : add_le_add_right (metric_space.dist_triangle x y z) _
lemma dist_triangle4_left (x₁ y₁ x₂ y₂ : α) :
dist x₂ y₂ ≤ dist x₁ y₁ + (dist x₁ x₂ + dist y₁ y₂) :=
by rw [add_left_comm, dist_comm x₁, ← add_assoc]; apply dist_triangle4
lemma dist_triangle4_right (x₁ y₁ x₂ y₂ : α) :
dist x₁ y₁ ≤ dist x₁ x₂ + dist y₁ y₂ + dist x₂ y₂ :=
by rw [add_right_comm, dist_comm y₁]; apply dist_triangle4
/-- The triangle (polygon) inequality for sequences of points; `finset.Ico` version. -/
lemma dist_le_Ico_sum_dist (f : ℕ → α) {m n} (h : m ≤ n) :
dist (f m) (f n) ≤ (finset.Ico m n).sum (λ i, dist (f i) (f (i + 1))) :=
begin
revert n,
apply nat.le_induction,
{ simp only [finset.sum_empty, finset.Ico.self_eq_empty, dist_self] },
{ assume n hn hrec,
calc dist (f m) (f (n+1)) ≤ dist (f m) (f n) + dist _ _ : dist_triangle _ _ _
... ≤ (finset.Ico m n).sum _ + _ : add_le_add hrec (le_refl _)
... = (finset.Ico m (n+1)).sum _ :
by rw [finset.Ico.succ_top hn, finset.sum_insert, add_comm]; simp }
end
/-- The triangle (polygon) inequality for sequences of points; `finset.range` version. -/
lemma dist_le_range_sum_dist (f : ℕ → α) (n : ℕ) :
dist (f 0) (f n) ≤ (finset.range n).sum (λ i, dist (f i) (f (i + 1))) :=
finset.Ico.zero_bot n ▸ dist_le_Ico_sum_dist f (nat.zero_le n)
/-- A version of `dist_le_Ico_sum_dist` with each intermediate distance replaced
with an upper estimate. -/
lemma dist_le_Ico_sum_of_dist_le {f : ℕ → α} {m n} (hmn : m ≤ n)
{d : ℕ → ℝ} (hd : ∀ {k}, m ≤ k → k < n → dist (f k) (f (k + 1)) ≤ d k) :
dist (f m) (f n) ≤ (finset.Ico m n).sum d :=
le_trans (dist_le_Ico_sum_dist f hmn) $
finset.sum_le_sum $ λ k hk, hd (finset.Ico.mem.1 hk).1 (finset.Ico.mem.1 hk).2
/-- A version of `dist_le_range_sum_dist` with each intermediate distance replaced
with an upper estimate. -/
lemma dist_le_range_sum_of_dist_le {f : ℕ → α} (n : ℕ)
{d : ℕ → ℝ} (hd : ∀ {k}, k < n → dist (f k) (f (k + 1)) ≤ d k) :
dist (f 0) (f n) ≤ (finset.range n).sum d :=
finset.Ico.zero_bot n ▸ dist_le_Ico_sum_of_dist_le (zero_le n) (λ _ _, hd)
theorem swap_dist : function.swap (@dist α _) = dist :=
by funext x y; exact dist_comm _ _
theorem abs_dist_sub_le (x y z : α) : abs (dist x z - dist y z) ≤ dist x y :=
abs_sub_le_iff.2
⟨sub_le_iff_le_add.2 (dist_triangle _ _ _),
sub_le_iff_le_add.2 (dist_triangle_left _ _ _)⟩
theorem dist_nonneg {x y : α} : 0 ≤ dist x y :=
have 2 * dist x y ≥ 0,
from calc 2 * dist x y = dist x y + dist y x : by rw [dist_comm x y, two_mul]
... ≥ 0 : by rw ← dist_self x; apply dist_triangle,
nonneg_of_mul_nonneg_left this two_pos
@[simp] theorem dist_le_zero {x y : α} : dist x y ≤ 0 ↔ x = y :=
by simpa [le_antisymm_iff, dist_nonneg] using @dist_eq_zero _ _ x y
@[simp] theorem dist_pos {x y : α} : 0 < dist x y ↔ x ≠ y :=
by simpa only [not_le] using not_congr dist_le_zero
@[simp] theorem abs_dist {a b : α} : abs (dist a b) = dist a b :=
abs_of_nonneg dist_nonneg
@[nolint ge_or_gt] -- see Note [nolint_ge]
theorem eq_of_forall_dist_le {x y : α} (h : ∀ ε > 0, dist x y ≤ ε) : x = y :=
eq_of_dist_eq_zero (eq_of_le_of_forall_le_of_dense dist_nonneg h)
/-- Distance as a nonnegative real number. -/
def nndist (a b : α) : nnreal := ⟨dist a b, dist_nonneg⟩
/--Express `nndist` in terms of `edist`-/
lemma nndist_edist (x y : α) : nndist x y = (edist x y).to_nnreal :=
by simp [nndist, edist_dist, nnreal.of_real, max_eq_left dist_nonneg, ennreal.of_real]
/--Express `edist` in terms of `nndist`-/
lemma edist_nndist (x y : α) : edist x y = ↑(nndist x y) :=
by { rw [edist_dist, nndist, ennreal.of_real_eq_coe_nnreal] }
/--In a metric space, the extended distance is always finite-/
lemma edist_ne_top (x y : α) : edist x y ≠ ⊤ :=
by rw [edist_dist x y]; apply ennreal.coe_ne_top
/--In a metric space, the extended distance is always finite-/
lemma edist_lt_top {α : Type*} [metric_space α] (x y : α) : edist x y < ⊤ :=
ennreal.lt_top_iff_ne_top.2 (edist_ne_top x y)
/--`nndist x x` vanishes-/
@[simp] lemma nndist_self (a : α) : nndist a a = 0 := (nnreal.coe_eq_zero _).1 (dist_self a)
/--Express `dist` in terms of `nndist`-/
lemma dist_nndist (x y : α) : dist x y = ↑(nndist x y) := rfl
/--Express `nndist` in terms of `dist`-/
lemma nndist_dist (x y : α) : nndist x y = nnreal.of_real (dist x y) :=
by rw [dist_nndist, nnreal.of_real_coe]
/--Deduce the equality of points with the vanishing of the nonnegative distance-/
theorem eq_of_nndist_eq_zero {x y : α} : nndist x y = 0 → x = y :=
by simp only [← nnreal.eq_iff, ← dist_nndist, imp_self, nnreal.coe_zero, dist_eq_zero]
theorem nndist_comm (x y : α) : nndist x y = nndist y x :=
by simpa only [dist_nndist, nnreal.coe_eq] using dist_comm x y
/--Characterize the equality of points with the vanishing of the nonnegative distance-/
@[simp] theorem nndist_eq_zero {x y : α} : nndist x y = 0 ↔ x = y :=
by simp only [← nnreal.eq_iff, ← dist_nndist, imp_self, nnreal.coe_zero, dist_eq_zero]
@[simp] theorem zero_eq_nndist {x y : α} : 0 = nndist x y ↔ x = y :=
by simp only [← nnreal.eq_iff, ← dist_nndist, imp_self, nnreal.coe_zero, zero_eq_dist]
/--Triangle inequality for the nonnegative distance-/
theorem nndist_triangle (x y z : α) : nndist x z ≤ nndist x y + nndist y z :=
by simpa [nnreal.coe_le_coe] using dist_triangle x y z
theorem nndist_triangle_left (x y z : α) : nndist x y ≤ nndist z x + nndist z y :=
by simpa [nnreal.coe_le_coe] using dist_triangle_left x y z
theorem nndist_triangle_right (x y z : α) : nndist x y ≤ nndist x z + nndist y z :=
by simpa [nnreal.coe_le_coe] using dist_triangle_right x y z
/--Express `dist` in terms of `edist`-/
lemma dist_edist (x y : α) : dist x y = (edist x y).to_real :=
by rw [edist_dist, ennreal.to_real_of_real (dist_nonneg)]
namespace metric
/- instantiate metric space as a topology -/
variables {x y z : α} {ε ε₁ ε₂ : ℝ} {s : set α}
/-- `ball x ε` is the set of all points `y` with `dist y x < ε` -/
def ball (x : α) (ε : ℝ) : set α := {y | dist y x < ε}
@[simp] theorem mem_ball : y ∈ ball x ε ↔ dist y x < ε := iff.rfl
theorem mem_ball' : y ∈ ball x ε ↔ dist x y < ε := by rw dist_comm; refl
/-- `closed_ball x ε` is the set of all points `y` with `dist y x ≤ ε` -/
def closed_ball (x : α) (ε : ℝ) := {y | dist y x ≤ ε}
/-- `sphere x ε` is the set of all points `y` with `dist y x = ε` -/
def sphere (x : α) (ε : ℝ) := {y | dist y x = ε}
@[simp] theorem mem_closed_ball : y ∈ closed_ball x ε ↔ dist y x ≤ ε := iff.rfl
theorem ball_subset_closed_ball : ball x ε ⊆ closed_ball x ε :=
assume y (hy : _ < _), le_of_lt hy
theorem sphere_subset_closed_ball : sphere x ε ⊆ closed_ball x ε :=
λ y, le_of_eq
theorem sphere_disjoint_ball : disjoint (sphere x ε) (ball x ε) :=
λ y ⟨hy₁, hy₂⟩, absurd hy₁ $ ne_of_lt hy₂
@[simp] theorem ball_union_sphere : ball x ε ∪ sphere x ε = closed_ball x ε :=
set.ext $ λ y, (@le_iff_lt_or_eq ℝ _ _ _).symm
@[simp] theorem sphere_union_ball : sphere x ε ∪ ball x ε = closed_ball x ε :=
by rw [union_comm, ball_union_sphere]
@[simp] theorem closed_ball_diff_sphere : closed_ball x ε \ sphere x ε = ball x ε :=
by rw [← ball_union_sphere, set.union_diff_cancel_right sphere_disjoint_ball.symm]
@[simp] theorem closed_ball_diff_ball : closed_ball x ε \ ball x ε = sphere x ε :=
by rw [← ball_union_sphere, set.union_diff_cancel_left sphere_disjoint_ball.symm]
theorem pos_of_mem_ball (hy : y ∈ ball x ε) : 0 < ε :=
lt_of_le_of_lt dist_nonneg hy
theorem mem_ball_self (h : 0 < ε) : x ∈ ball x ε :=
show dist x x < ε, by rw dist_self; assumption
theorem mem_closed_ball_self (h : 0 ≤ ε) : x ∈ closed_ball x ε :=
show dist x x ≤ ε, by rw dist_self; assumption
theorem mem_ball_comm : x ∈ ball y ε ↔ y ∈ ball x ε :=
by simp [dist_comm]
theorem ball_subset_ball (h : ε₁ ≤ ε₂) : ball x ε₁ ⊆ ball x ε₂ :=
λ y (yx : _ < ε₁), lt_of_lt_of_le yx h
theorem closed_ball_subset_closed_ball {α : Type u} [metric_space α] {ε₁ ε₂ : ℝ} {x : α} (h : ε₁ ≤ ε₂) :
closed_ball x ε₁ ⊆ closed_ball x ε₂ :=
λ y (yx : _ ≤ ε₁), le_trans yx h
theorem ball_disjoint (h : ε₁ + ε₂ ≤ dist x y) : ball x ε₁ ∩ ball y ε₂ = ∅ :=
eq_empty_iff_forall_not_mem.2 $ λ z ⟨h₁, h₂⟩,
not_lt_of_le (dist_triangle_left x y z)
(lt_of_lt_of_le (add_lt_add h₁ h₂) h)
theorem ball_disjoint_same (h : ε ≤ dist x y / 2) : ball x ε ∩ ball y ε = ∅ :=
ball_disjoint $ by rwa [← two_mul, ← le_div_iff' (@two_pos ℝ _)]
theorem ball_subset (h : dist x y ≤ ε₂ - ε₁) : ball x ε₁ ⊆ ball y ε₂ :=
λ z zx, by rw ← add_sub_cancel'_right ε₁ ε₂; exact
lt_of_le_of_lt (dist_triangle z x y) (add_lt_add_of_lt_of_le zx h)
theorem ball_half_subset (y) (h : y ∈ ball x (ε / 2)) : ball y (ε / 2) ⊆ ball x ε :=
ball_subset $ by rw sub_self_div_two; exact le_of_lt h
@[nolint ge_or_gt] -- see Note [nolint_ge]
theorem exists_ball_subset_ball (h : y ∈ ball x ε) : ∃ ε' > 0, ball y ε' ⊆ ball x ε :=
⟨_, sub_pos.2 h, ball_subset $ by rw sub_sub_self⟩
@[simp] theorem ball_eq_empty_iff_nonpos : ball x ε = ∅ ↔ ε ≤ 0 :=
eq_empty_iff_forall_not_mem.trans
⟨λ h, le_of_not_gt $ λ ε0, h _ $ mem_ball_self ε0,
λ ε0 y h, not_lt_of_le ε0 $ pos_of_mem_ball h⟩
@[simp] theorem closed_ball_eq_empty_iff_neg : closed_ball x ε = ∅ ↔ ε < 0 :=
eq_empty_iff_forall_not_mem.trans
⟨λ h, not_le.1 $ λ ε0, h x $ mem_closed_ball_self ε0,
λ ε0 y h, not_lt_of_le (mem_closed_ball.1 h) (lt_of_lt_of_le ε0 dist_nonneg)⟩
@[simp] lemma ball_zero : ball x 0 = ∅ :=
by rw [ball_eq_empty_iff_nonpos]
@[simp] lemma closed_ball_zero : closed_ball x 0 = {x} :=
set.ext $ λ y, dist_le_zero
theorem uniformity_basis_dist :
(𝓤 α).has_basis (λ ε : ℝ, 0 < ε) (λ ε, {p:α×α | dist p.1 p.2 < ε}) :=
begin
rw ← metric_space.uniformity_dist.symm,
refine has_basis_binfi_principal _ nonempty_Ioi,
exact λ r (hr : 0 < r) p (hp : 0 < p), ⟨min r p, lt_min hr hp,
λ x (hx : dist _ _ < _), lt_of_lt_of_le hx (min_le_left r p),
λ x (hx : dist _ _ < _), lt_of_lt_of_le hx (min_le_right r p)⟩
end
/-- Given `f : β → ℝ`, if `f` sends `{i | p i}` to a set of positive numbers
accumulating to zero, then `f i`-neighborhoods of the diagonal form a basis of `𝓤 α`.
For specific bases see `uniformity_basis_dist`, `uniformity_basis_dist_inv_nat_succ`,
and `uniformity_basis_dist_inv_nat_pos`. -/
protected theorem mk_uniformity_basis {β : Type*} {p : β → Prop} {f : β → ℝ}
(hf₀ : ∀ i, p i → 0 < f i) (hf : ∀ ⦃ε⦄, 0 < ε → ∃ i (hi : p i), f i ≤ ε) :
(𝓤 α).has_basis p (λ i, {p:α×α | dist p.1 p.2 < f i}) :=
begin
refine ⟨λ s, uniformity_basis_dist.mem_iff.trans _⟩,
split,
{ rintros ⟨ε, ε₀, hε⟩,
obtain ⟨i, hi, H⟩ : ∃ i (hi : p i), f i ≤ ε, from hf ε₀,
exact ⟨i, hi, λ x (hx : _ < _), hε $ lt_of_lt_of_le hx H⟩ },
{ exact λ ⟨i, hi, H⟩, ⟨f i, hf₀ i hi, H⟩ }
end
theorem uniformity_basis_dist_inv_nat_succ :
(𝓤 α).has_basis (λ _, true) (λ n:ℕ, {p:α×α | dist p.1 p.2 < 1 / (↑n+1) }) :=
metric.mk_uniformity_basis (λ n _, div_pos zero_lt_one $ nat.cast_add_one_pos n)
(λ ε ε0, (exists_nat_one_div_lt ε0).imp $ λ n hn, ⟨trivial, le_of_lt hn⟩)
theorem uniformity_basis_dist_inv_nat_pos :
(𝓤 α).has_basis (λ n:ℕ, 0<n) (λ n:ℕ, {p:α×α | dist p.1 p.2 < 1 / ↑n }) :=
metric.mk_uniformity_basis (λ n hn, div_pos zero_lt_one $ nat.cast_pos.2 hn)
(λ ε ε0, let ⟨n, hn⟩ := exists_nat_one_div_lt ε0 in ⟨n+1, nat.succ_pos n, le_of_lt hn⟩)
/-- Given `f : β → ℝ`, if `f` sends `{i | p i}` to a set of positive numbers
accumulating to zero, then closed neighborhoods of the diagonal of sizes `{f i | p i}`
form a basis of `𝓤 α`.
Currently we have only one specific basis `uniformity_basis_dist_le` based on this constructor.
More can be easily added if needed in the future. -/
protected theorem mk_uniformity_basis_le {β : Type*} {p : β → Prop} {f : β → ℝ}
(hf₀ : ∀ x, p x → 0 < f x) (hf : ∀ ε, 0 < ε → ∃ x (hx : p x), f x ≤ ε) :
(𝓤 α).has_basis p (λ x, {p:α×α | dist p.1 p.2 ≤ f x}) :=
begin
refine ⟨λ s, uniformity_basis_dist.mem_iff.trans _⟩,
split,
{ rintros ⟨ε, ε₀, hε⟩,
rcases dense ε₀ with ⟨ε', hε'⟩,
rcases hf ε' hε'.1 with ⟨i, hi, H⟩,
exact ⟨i, hi, λ x (hx : _ ≤ _), hε $ lt_of_le_of_lt (le_trans hx H) hε'.2⟩ },
{ exact λ ⟨i, hi, H⟩, ⟨f i, hf₀ i hi, λ x (hx : _ < _), H (le_of_lt hx)⟩ }
end
/-- Contant size closed neighborhoods of the diagonal form a basis
of the uniformity filter. -/
theorem uniformity_basis_dist_le :
(𝓤 α).has_basis (λ ε : ℝ, 0 < ε) (λ ε, {p:α×α | dist p.1 p.2 ≤ ε}) :=
metric.mk_uniformity_basis_le (λ _, id) (λ ε ε₀, ⟨ε, ε₀, le_refl ε⟩)
@[nolint ge_or_gt] -- see Note [nolint_ge]
theorem mem_uniformity_dist {s : set (α×α)} :
s ∈ 𝓤 α ↔ (∃ε>0, ∀{a b:α}, dist a b < ε → (a, b) ∈ s) :=
uniformity_basis_dist.mem_uniformity_iff
/-- A constant size neighborhood of the diagonal is an entourage. -/
theorem dist_mem_uniformity {ε:ℝ} (ε0 : 0 < ε) :
{p:α×α | dist p.1 p.2 < ε} ∈ 𝓤 α :=
mem_uniformity_dist.2 ⟨ε, ε0, λ a b, id⟩
@[nolint ge_or_gt] -- see Note [nolint_ge]
theorem uniform_continuous_iff [metric_space β] {f : α → β} :
uniform_continuous f ↔ ∀ ε > 0, ∃ δ > 0,
∀{a b:α}, dist a b < δ → dist (f a) (f b) < ε :=
uniformity_basis_dist.uniform_continuous_iff uniformity_basis_dist
@[nolint ge_or_gt] -- see Note [nolint_ge]
theorem uniform_embedding_iff [metric_space β] {f : α → β} :
uniform_embedding f ↔ function.injective f ∧ uniform_continuous f ∧
∀ δ > 0, ∃ ε > 0, ∀ {a b : α}, dist (f a) (f b) < ε → dist a b < δ :=
uniform_embedding_def'.trans $ and_congr iff.rfl $ and_congr iff.rfl
⟨λ H δ δ0, let ⟨t, tu, ht⟩ := H _ (dist_mem_uniformity δ0),
⟨ε, ε0, hε⟩ := mem_uniformity_dist.1 tu in
⟨ε, ε0, λ a b h, ht _ _ (hε h)⟩,
λ H s su, let ⟨δ, δ0, hδ⟩ := mem_uniformity_dist.1 su, ⟨ε, ε0, hε⟩ := H _ δ0 in
⟨_, dist_mem_uniformity ε0, λ a b h, hδ (hε h)⟩⟩
/-- A map between metric spaces is a uniform embedding if and only if the distance between `f x`
and `f y` is controlled in terms of the distance between `x` and `y` and conversely. -/
@[nolint ge_or_gt] -- see Note [nolint_ge]
theorem uniform_embedding_iff' [metric_space β] {f : α → β} :
uniform_embedding f ↔
(∀ ε > 0, ∃ δ > 0, ∀ {a b : α}, dist a b < δ → dist (f a) (f b) < ε) ∧
(∀ δ > 0, ∃ ε > 0, ∀ {a b : α}, dist (f a) (f b) < ε → dist a b < δ) :=
begin
split,
{ assume h,
exact ⟨uniform_continuous_iff.1 (uniform_embedding_iff.1 h).2.1,
(uniform_embedding_iff.1 h).2.2⟩ },
{ rintros ⟨h₁, h₂⟩,
refine uniform_embedding_iff.2 ⟨_, uniform_continuous_iff.2 h₁, h₂⟩,
assume x y hxy,
have : dist x y ≤ 0,
{ refine le_of_forall_lt' (λδ δpos, _),
rcases h₂ δ δpos with ⟨ε, εpos, hε⟩,
have : dist (f x) (f y) < ε, by simpa [hxy],
exact hε this },
simpa using this }
end
@[nolint ge_or_gt] -- see Note [nolint_ge]
theorem totally_bounded_iff {s : set α} :
totally_bounded s ↔ ∀ ε > 0, ∃t : set α, finite t ∧ s ⊆ ⋃y∈t, ball y ε :=
⟨λ H ε ε0, H _ (dist_mem_uniformity ε0),
λ H r ru, let ⟨ε, ε0, hε⟩ := mem_uniformity_dist.1 ru,
⟨t, ft, h⟩ := H ε ε0 in
⟨t, ft, subset.trans h $ Union_subset_Union $ λ y, Union_subset_Union $ λ yt z, hε⟩⟩
/-- A metric space space is totally bounded if one can reconstruct up to any ε>0 any element of the
space from finitely many data. -/
@[nolint ge_or_gt] -- see Note [nolint_ge]
lemma totally_bounded_of_finite_discretization {α : Type u} [metric_space α] {s : set α}
(H : ∀ε > (0 : ℝ), ∃ (β : Type u) [fintype β] (F : s → β),
∀x y, F x = F y → dist (x:α) y < ε) :
totally_bounded s :=
begin
cases s.eq_empty_or_nonempty with hs hs,
{ rw hs, exact totally_bounded_empty },
rcases hs with ⟨x0, hx0⟩,
haveI : inhabited s := ⟨⟨x0, hx0⟩⟩,
refine totally_bounded_iff.2 (λ ε ε0, _),
rcases H ε ε0 with ⟨β, fβ, F, hF⟩,
let Finv := function.inv_fun F,
refine ⟨range (subtype.val ∘ Finv), finite_range _, λ x xs, _⟩,
let x' := Finv (F ⟨x, xs⟩),
have : F x' = F ⟨x, xs⟩ := function.inv_fun_eq ⟨⟨x, xs⟩, rfl⟩,
simp only [set.mem_Union, set.mem_range],
exact ⟨_, ⟨F ⟨x, xs⟩, rfl⟩, hF _ _ this.symm⟩
end
/-- Expressing locally uniform convergence on a set using `dist`. -/
@[nolint ge_or_gt] -- see Note [nolint_ge]
lemma tendsto_locally_uniformly_on_iff {ι : Type*} [topological_space β]
{F : ι → β → α} {f : β → α} {p : filter ι} {s : set β} :
tendsto_locally_uniformly_on F f p s ↔
∀ ε > 0, ∀ x ∈ s, ∃ t ∈ nhds_within x s, ∀ᶠ n in p, ∀ y ∈ t, dist (f y) (F n y) < ε :=
begin
refine ⟨λ H ε hε, H _ (dist_mem_uniformity hε), λ H u hu x hx, _⟩,
rcases mem_uniformity_dist.1 hu with ⟨ε, εpos, hε⟩,
rcases H ε εpos x hx with ⟨t, ht, Ht⟩,
exact ⟨t, ht, Ht.mono (λ n hs x hx, hε (hs x hx))⟩
end
/-- Expressing uniform convergence on a set using `dist`. -/
@[nolint ge_or_gt] -- see Note [nolint_ge]
lemma tendsto_uniformly_on_iff {ι : Type*}
{F : ι → β → α} {f : β → α} {p : filter ι} {s : set β} :
tendsto_uniformly_on F f p s ↔ ∀ ε > 0, ∀ᶠ n in p, ∀ x ∈ s, dist (f x) (F n x) < ε :=
begin
refine ⟨λ H ε hε, H _ (dist_mem_uniformity hε), λ H u hu, _⟩,
rcases mem_uniformity_dist.1 hu with ⟨ε, εpos, hε⟩,
exact (H ε εpos).mono (λ n hs x hx, hε (hs x hx))
end
/-- Expressing locally uniform convergence using `dist`. -/
@[nolint ge_or_gt] -- see Note [nolint_ge]
lemma tendsto_locally_uniformly_iff {ι : Type*} [topological_space β]
{F : ι → β → α} {f : β → α} {p : filter ι} :
tendsto_locally_uniformly F f p ↔
∀ ε > 0, ∀ (x : β), ∃ t ∈ 𝓝 x, ∀ᶠ n in p, ∀ y ∈ t, dist (f y) (F n y) < ε :=
by simp [← nhds_within_univ, ← tendsto_locally_uniformly_on_univ, tendsto_locally_uniformly_on_iff]
/-- Expressing uniform convergence using `dist`. -/
@[nolint ge_or_gt] -- see Note [nolint_ge]
lemma tendsto_uniformly_iff {ι : Type*}
{F : ι → β → α} {f : β → α} {p : filter ι} :
tendsto_uniformly F f p ↔ ∀ ε > 0, ∀ᶠ n in p, ∀ x, dist (f x) (F n x) < ε :=
by { rw [← tendsto_uniformly_on_univ, tendsto_uniformly_on_iff], simp }
protected lemma cauchy_iff {f : filter α} :
cauchy f ↔ f ≠ ⊥ ∧ ∀ ε > 0, ∃ t ∈ f, ∀ x y ∈ t, dist x y < ε :=
uniformity_basis_dist.cauchy_iff
theorem nhds_basis_ball : (𝓝 x).has_basis (λ ε:ℝ, 0 < ε) (ball x) :=
nhds_basis_uniformity uniformity_basis_dist
theorem mem_nhds_iff : s ∈ 𝓝 x ↔ ∃ε>0, ball x ε ⊆ s :=
nhds_basis_ball.mem_iff
theorem nhds_basis_closed_ball : (𝓝 x).has_basis (λ ε:ℝ, 0 < ε) (closed_ball x) :=
nhds_basis_uniformity uniformity_basis_dist_le
theorem nhds_basis_ball_inv_nat_succ :
(𝓝 x).has_basis (λ _, true) (λ n:ℕ, ball x (1 / (↑n+1))) :=
nhds_basis_uniformity uniformity_basis_dist_inv_nat_succ
theorem nhds_basis_ball_inv_nat_pos :
(𝓝 x).has_basis (λ n, 0<n) (λ n:ℕ, ball x (1 / ↑n)) :=
nhds_basis_uniformity uniformity_basis_dist_inv_nat_pos
theorem is_open_iff : is_open s ↔ ∀x∈s, ∃ε>0, ball x ε ⊆ s :=
by simp only [is_open_iff_nhds, mem_nhds_iff, le_principal_iff]
theorem is_open_ball : is_open (ball x ε) :=
is_open_iff.2 $ λ y, exists_ball_subset_ball
theorem ball_mem_nhds (x : α) {ε : ℝ} (ε0 : 0 < ε) : ball x ε ∈ 𝓝 x :=
mem_nhds_sets is_open_ball (mem_ball_self ε0)
theorem nhds_within_basis_ball {s : set α} :
(nhds_within x s).has_basis (λ ε:ℝ, 0 < ε) (λ ε, ball x ε ∩ s) :=
nhds_within_has_basis nhds_basis_ball s
@[nolint ge_or_gt] -- see Note [nolint_ge]
theorem mem_nhds_within_iff {t : set α} : s ∈ nhds_within x t ↔ ∃ε>0, ball x ε ∩ t ⊆ s :=
nhds_within_basis_ball.mem_iff
@[nolint ge_or_gt] -- see Note [nolint_ge]
theorem tendsto_nhds_within_nhds_within [metric_space β] {t : set β} {f : α → β} {a b} :
tendsto f (nhds_within a s) (nhds_within b t) ↔
∀ ε > 0, ∃ δ > 0, ∀{x:α}, x ∈ s → dist x a < δ → f x ∈ t ∧ dist (f x) b < ε :=
(nhds_within_basis_ball.tendsto_iff nhds_within_basis_ball).trans $
by simp only [inter_comm, mem_inter_iff, and_imp, mem_ball]
@[nolint ge_or_gt] -- see Note [nolint_ge]
theorem tendsto_nhds_within_nhds [metric_space β] {f : α → β} {a b} :
tendsto f (nhds_within a s) (𝓝 b) ↔
∀ ε > 0, ∃ δ > 0, ∀{x:α}, x ∈ s → dist x a < δ → dist (f x) b < ε :=
by { rw [← nhds_within_univ, tendsto_nhds_within_nhds_within],
simp only [mem_univ, true_and] }
@[nolint ge_or_gt] -- see Note [nolint_ge]
theorem tendsto_nhds_nhds [metric_space β] {f : α → β} {a b} :
tendsto f (𝓝 a) (𝓝 b) ↔
∀ ε > 0, ∃ δ > 0, ∀{x:α}, dist x a < δ → dist (f x) b < ε :=
nhds_basis_ball.tendsto_iff nhds_basis_ball
@[nolint ge_or_gt] -- see Note [nolint_ge]
theorem continuous_at_iff [metric_space β] {f : α → β} {a : α} :
continuous_at f a ↔
∀ ε > 0, ∃ δ > 0, ∀{x:α}, dist x a < δ → dist (f x) (f a) < ε :=
by rw [continuous_at, tendsto_nhds_nhds]
@[nolint ge_or_gt] -- see Note [nolint_ge]
theorem continuous_within_at_iff [metric_space β] {f : α → β} {a : α} {s : set α} :
continuous_within_at f s a ↔
∀ ε > 0, ∃ δ > 0, ∀{x:α}, x ∈ s → dist x a < δ → dist (f x) (f a) < ε :=
by rw [continuous_within_at, tendsto_nhds_within_nhds]
@[nolint ge_or_gt] -- see Note [nolint_ge]
theorem continuous_on_iff [metric_space β] {f : α → β} {s : set α} :
continuous_on f s ↔
∀ (b ∈ s) (ε > 0), ∃ δ > 0, ∀a ∈ s, dist a b < δ → dist (f a) (f b) < ε :=
by simp [continuous_on, continuous_within_at_iff]
@[nolint ge_or_gt] -- see Note [nolint_ge]
theorem continuous_iff [metric_space β] {f : α → β} :
continuous f ↔
∀b (ε > 0), ∃ δ > 0, ∀a, dist a b < δ → dist (f a) (f b) < ε :=
continuous_iff_continuous_at.trans $ forall_congr $ λ b, tendsto_nhds_nhds
theorem tendsto_nhds {f : filter β} {u : β → α} {a : α} :
tendsto u f (𝓝 a) ↔ ∀ ε > 0, ∀ᶠ x in f, dist (u x) a < ε :=
nhds_basis_ball.tendsto_right_iff
@[nolint ge_or_gt] -- see Note [nolint_ge]
theorem continuous_at_iff' [topological_space β] {f : β → α} {b : β} :
continuous_at f b ↔
∀ ε > 0, ∀ᶠ x in 𝓝 b, dist (f x) (f b) < ε :=
by rw [continuous_at, tendsto_nhds]
@[nolint ge_or_gt] -- see Note [nolint_ge]
theorem continuous_within_at_iff' [topological_space β] {f : β → α} {b : β} {s : set β} :
continuous_within_at f s b ↔
∀ ε > 0, ∀ᶠ x in nhds_within b s, dist (f x) (f b) < ε :=
by rw [continuous_within_at, tendsto_nhds]
@[nolint ge_or_gt] -- see Note [nolint_ge]
theorem continuous_on_iff' [topological_space β] {f : β → α} {s : set β} :
continuous_on f s ↔
∀ (b ∈ s) (ε > 0), ∀ᶠ x in nhds_within b s, dist (f x) (f b) < ε :=
by simp [continuous_on, continuous_within_at_iff']
@[nolint ge_or_gt] -- see Note [nolint_ge]
theorem continuous_iff' [topological_space β] {f : β → α} :
continuous f ↔ ∀a (ε > 0), ∀ᶠ x in 𝓝 a, dist (f x) (f a) < ε :=
continuous_iff_continuous_at.trans $ forall_congr $ λ b, tendsto_nhds
@[nolint ge_or_gt] -- see Note [nolint_ge]
theorem tendsto_at_top [nonempty β] [semilattice_sup β] {u : β → α} {a : α} :
tendsto u at_top (𝓝 a) ↔ ∀ε>0, ∃N, ∀n≥N, dist (u n) a < ε :=
(at_top_basis.tendsto_iff nhds_basis_ball).trans $
by { simp only [exists_prop, true_and], refl }
end metric
open metric
@[priority 100] -- see Note [lower instance priority]
instance metric_space.to_separated : separated α :=
separated_def.2 $ λ x y h, eq_of_forall_dist_le $
λ ε ε0, le_of_lt (h _ (dist_mem_uniformity ε0))
/-Instantiate a metric space as an emetric space. Before we can state the instance,
we need to show that the uniform structure coming from the edistance and the
distance coincide. -/
/-- Expressing the uniformity in terms of `edist` -/
protected lemma metric.uniformity_basis_edist :
(𝓤 α).has_basis (λ ε:ennreal, 0 < ε) (λ ε, {p | edist p.1 p.2 < ε}) :=
⟨begin
intro t,
refine mem_uniformity_dist.trans ⟨_, _⟩; rintro ⟨ε, ε0, Hε⟩,
{ use [ennreal.of_real ε, ennreal.of_real_pos.2 ε0],
rintros ⟨a, b⟩,
simp only [edist_dist, ennreal.of_real_lt_of_real_iff ε0],
exact Hε },
{ rcases ennreal.lt_iff_exists_real_btwn.1 ε0 with ⟨ε', _, ε0', hε⟩,
rw [ennreal.of_real_pos] at ε0',
refine ⟨ε', ε0', λ a b h, Hε (lt_trans _ hε)⟩,
rwa [edist_dist, ennreal.of_real_lt_of_real_iff ε0'] }
end⟩
@[nolint ge_or_gt] -- see Note [nolint_ge]
theorem metric.uniformity_edist : 𝓤 α = (⨅ ε>0, principal {p:α×α | edist p.1 p.2 < ε}) :=
metric.uniformity_basis_edist.eq_binfi
/-- A metric space induces an emetric space -/
@[priority 100] -- see Note [lower instance priority]
instance metric_space.to_emetric_space : emetric_space α :=
{ edist := edist,
edist_self := by simp [edist_dist],
eq_of_edist_eq_zero := assume x y h, by simpa [edist_dist] using h,
edist_comm := by simp only [edist_dist, dist_comm]; simp,
edist_triangle := assume x y z, begin
simp only [edist_dist, ← ennreal.of_real_add, dist_nonneg],
rw ennreal.of_real_le_of_real_iff _,
{ exact dist_triangle _ _ _ },
{ simpa using add_le_add (dist_nonneg : 0 ≤ dist x y) dist_nonneg }
end,
uniformity_edist := metric.uniformity_edist,
..‹metric_space α› }
/-- Balls defined using the distance or the edistance coincide -/
lemma metric.emetric_ball {x : α} {ε : ℝ} : emetric.ball x (ennreal.of_real ε) = ball x ε :=
begin
ext y,
simp only [emetric.mem_ball, mem_ball, edist_dist],
exact ennreal.of_real_lt_of_real_iff_of_nonneg dist_nonneg
end
/-- Balls defined using the distance or the edistance coincide -/
lemma metric.emetric_ball_nnreal {x : α} {ε : nnreal} : emetric.ball x ε = ball x ε :=
by { convert metric.emetric_ball, simp }
/-- Closed balls defined using the distance or the edistance coincide -/
lemma metric.emetric_closed_ball {x : α} {ε : ℝ} (h : 0 ≤ ε) :
emetric.closed_ball x (ennreal.of_real ε) = closed_ball x ε :=
by ext y; simp [edist_dist]; rw ennreal.of_real_le_of_real_iff h
/-- Closed balls defined using the distance or the edistance coincide -/
lemma metric.emetric_closed_ball_nnreal {x : α} {ε : nnreal} :
emetric.closed_ball x ε = closed_ball x ε :=
by { convert metric.emetric_closed_ball ε.2, simp }
def metric_space.replace_uniformity {α} [U : uniform_space α] (m : metric_space α)
(H : @uniformity _ U = @uniformity _ emetric_space.to_uniform_space') :
metric_space α :=
{ dist := @dist _ m.to_has_dist,
dist_self := dist_self,
eq_of_dist_eq_zero := @eq_of_dist_eq_zero _ _,
dist_comm := dist_comm,
dist_triangle := dist_triangle,
edist := edist,
edist_dist := edist_dist,
to_uniform_space := U,
uniformity_dist := H.trans metric_space.uniformity_dist }
/-- One gets a metric space from an emetric space if the edistance
is everywhere finite, by pushing the edistance to reals. We set it up so that the edist and the
uniformity are defeq in the metric space and the emetric space. In this definition, the distance
is given separately, to be able to prescribe some expression which is not defeq to the push-forward
of the edistance to reals. -/
def emetric_space.to_metric_space_of_dist {α : Type u} [e : emetric_space α]
(dist : α → α → ℝ)
(edist_ne_top : ∀x y: α, edist x y ≠ ⊤)
(h : ∀x y, dist x y = ennreal.to_real (edist x y)) :
metric_space α :=
let m : metric_space α :=
{ dist := dist,
eq_of_dist_eq_zero := λx y hxy, by simpa [h, ennreal.to_real_eq_zero_iff, edist_ne_top x y] using hxy,
dist_self := λx, by simp [h],
dist_comm := λx y, by simp [h, emetric_space.edist_comm],
dist_triangle := λx y z, begin
simp only [h],
rw [← ennreal.to_real_add (edist_ne_top _ _) (edist_ne_top _ _),
ennreal.to_real_le_to_real (edist_ne_top _ _)],
{ exact edist_triangle _ _ _ },
{ simp [ennreal.add_eq_top, edist_ne_top] }
end,
edist := λx y, edist x y,
edist_dist := λx y, by simp [h, ennreal.of_real_to_real, edist_ne_top] } in
m.replace_uniformity $ by { rw [uniformity_edist, metric.uniformity_edist], refl }
/-- One gets a metric space from an emetric space if the edistance
is everywhere finite, by pushing the edistance to reals. We set it up so that the edist and the
uniformity are defeq in the metric space and the emetric space. -/
def emetric_space.to_metric_space {α : Type u} [e : emetric_space α] (h : ∀x y: α, edist x y ≠ ⊤) :
metric_space α :=
emetric_space.to_metric_space_of_dist (λx y, ennreal.to_real (edist x y)) h (λx y, rfl)
/-- A very useful criterion to show that a space is complete is to show that all sequences
which satisfy a bound of the form `dist (u n) (u m) < B N` for all `n m ≥ N` are
converging. This is often applied for `B N = 2^{-N}`, i.e., with a very fast convergence to
`0`, which makes it possible to use arguments of converging series, while this is impossible
to do in general for arbitrary Cauchy sequences. -/
theorem metric.complete_of_convergent_controlled_sequences (B : ℕ → real) (hB : ∀n, 0 < B n)
(H : ∀u : ℕ → α, (∀N n m : ℕ, N ≤ n → N ≤ m → dist (u n) (u m) < B N) → ∃x, tendsto u at_top (𝓝 x)) :
complete_space α :=
begin
-- this follows from the same criterion in emetric spaces. We just need to translate
-- the convergence assumption from `dist` to `edist`
apply emetric.complete_of_convergent_controlled_sequences (λn, ennreal.of_real (B n)),
{ simp [hB] },
{ assume u Hu,
apply H,
assume N n m hn hm,
rw [← ennreal.of_real_lt_of_real_iff (hB N), ← edist_dist],
exact Hu N n m hn hm }
end
theorem metric.complete_of_cauchy_seq_tendsto :
(∀ u : ℕ → α, cauchy_seq u → ∃a, tendsto u at_top (𝓝 a)) → complete_space α :=
emetric.complete_of_cauchy_seq_tendsto
section real
/-- Instantiate the reals as a metric space. -/
instance real.metric_space : metric_space ℝ :=
{ dist := λx y, abs (x - y),
dist_self := by simp [abs_zero],
eq_of_dist_eq_zero := by simp [sub_eq_zero],
dist_comm := assume x y, abs_sub _ _,
dist_triangle := assume x y z, abs_sub_le _ _ _ }
theorem real.dist_eq (x y : ℝ) : dist x y = abs (x - y) := rfl
theorem real.dist_0_eq_abs (x : ℝ) : dist x 0 = abs x :=
by simp [real.dist_eq]
instance : order_topology ℝ :=
order_topology_of_nhds_abs $ λ x, begin
simp only [show ∀ r, {b : ℝ | abs (x - b) < r} = ball x r,
by simp [abs_sub, ball, real.dist_eq]],
apply le_antisymm,
{ simp [le_infi_iff],
exact λ ε ε0, mem_nhds_sets (is_open_ball) (mem_ball_self ε0) },
{ intros s h,
rcases mem_nhds_iff.1 h with ⟨ε, ε0, ss⟩,
exact mem_infi_sets _ (mem_infi_sets ε0 (mem_principal_sets.2 ss)) },
end
lemma closed_ball_Icc {x r : ℝ} : closed_ball x r = Icc (x-r) (x+r) :=
by ext y; rw [mem_closed_ball, dist_comm, real.dist_eq,
abs_sub_le_iff, mem_Icc, ← sub_le_iff_le_add', sub_le]
/-- Special case of the sandwich theorem; see `tendsto_of_tendsto_of_tendsto_of_le_of_le`
and `tendsto_of_tendsto_of_tendsto_of_le_of_le'` for the general case. -/
lemma squeeze_zero {α} {f g : α → ℝ} {t₀ : filter α} (hf : ∀t, 0 ≤ f t) (hft : ∀t, f t ≤ g t)
(g0 : tendsto g t₀ (𝓝 0)) : tendsto f t₀ (𝓝 0) :=
tendsto_of_tendsto_of_tendsto_of_le_of_le tendsto_const_nhds g0 hf hft
theorem metric.uniformity_eq_comap_nhds_zero :
𝓤 α = comap (λp:α×α, dist p.1 p.2) (𝓝 (0 : ℝ)) :=
by { ext s,
simp [mem_uniformity_dist, (nhds_basis_ball.comap _).mem_iff, subset_def, real.dist_0_eq_abs] }
lemma cauchy_seq_iff_tendsto_dist_at_top_0 [nonempty β] [semilattice_sup β] {u : β → α} :
cauchy_seq u ↔ tendsto (λ (n : β × β), dist (u n.1) (u n.2)) at_top (𝓝 0) :=
by rw [cauchy_seq_iff_tendsto, metric.uniformity_eq_comap_nhds_zero, tendsto_comap_iff,
prod.map_def]
lemma tendsto_uniformity_iff_dist_tendsto_zero {ι : Type*} {f : ι → α × α} {p : filter ι} :
tendsto f p (𝓤 α) ↔ tendsto (λ x, dist (f x).1 (f x).2) p (𝓝 0) :=
by rw [metric.uniformity_eq_comap_nhds_zero, tendsto_comap_iff]
lemma filter.tendsto.congr_dist {ι : Type*} {f₁ f₂ : ι → α} {p : filter ι} {a : α}
(h₁ : tendsto f₁ p (𝓝 a)) (h : tendsto (λ x, dist (f₁ x) (f₂ x)) p (𝓝 0)) :
tendsto f₂ p (𝓝 a) :=
h₁.congr_uniformity $ tendsto_uniformity_iff_dist_tendsto_zero.2 h
alias filter.tendsto.congr_dist ← tendsto_of_tendsto_of_dist
lemma tendsto_iff_of_dist {ι : Type*} {f₁ f₂ : ι → α} {p : filter ι} {a : α}
(h : tendsto (λ x, dist (f₁ x) (f₂ x)) p (𝓝 0)) :
tendsto f₁ p (𝓝 a) ↔ tendsto f₂ p (𝓝 a) :=
uniform.tendsto_congr $ tendsto_uniformity_iff_dist_tendsto_zero.2 h
end real
section cauchy_seq
variables [nonempty β] [semilattice_sup β]
/-- In a metric space, Cauchy sequences are characterized by the fact that, eventually,
the distance between its elements is arbitrarily small -/
@[nolint ge_or_gt] -- see Note [nolint_ge]
theorem metric.cauchy_seq_iff {u : β → α} :
cauchy_seq u ↔ ∀ε>0, ∃N, ∀m n≥N, dist (u m) (u n) < ε :=
uniformity_basis_dist.cauchy_seq_iff
/-- A variation around the metric characterization of Cauchy sequences -/
@[nolint ge_or_gt] -- see Note [nolint_ge]
theorem metric.cauchy_seq_iff' {u : β → α} :
cauchy_seq u ↔ ∀ε>0, ∃N, ∀n≥N, dist (u n) (u N) < ε :=
uniformity_basis_dist.cauchy_seq_iff'
/-- If the distance between `s n` and `s m`, `n, m ≥ N` is bounded above by `b N`
and `b` converges to zero, then `s` is a Cauchy sequence. -/
lemma cauchy_seq_of_le_tendsto_0 {s : β → α} (b : β → ℝ)
(h : ∀ n m N : β, N ≤ n → N ≤ m → dist (s n) (s m) ≤ b N) (h₀ : tendsto b at_top (nhds 0)) :
cauchy_seq s :=
metric.cauchy_seq_iff.2 $ λ ε ε0,
(metric.tendsto_at_top.1 h₀ ε ε0).imp $ λ N hN m n hm hn,
calc dist (s m) (s n) ≤ b N : h m n N hm hn
... ≤ abs (b N) : le_abs_self _
... = dist (b N) 0 : by rw real.dist_0_eq_abs; refl
... < ε : (hN _ (le_refl N))
/-- A Cauchy sequence on the natural numbers is bounded. -/
theorem cauchy_seq_bdd {u : ℕ → α} (hu : cauchy_seq u) :
∃ R > 0, ∀ m n, dist (u m) (u n) < R :=
begin
rcases metric.cauchy_seq_iff'.1 hu 1 zero_lt_one with ⟨N, hN⟩,
suffices : ∃ R > 0, ∀ n, dist (u n) (u N) < R,
{ rcases this with ⟨R, R0, H⟩,
exact ⟨_, add_pos R0 R0, λ m n,
lt_of_le_of_lt (dist_triangle_right _ _ _) (add_lt_add (H m) (H n))⟩ },
let R := finset.sup (finset.range N) (λ n, nndist (u n) (u N)),
refine ⟨↑R + 1, add_pos_of_nonneg_of_pos R.2 zero_lt_one, λ n, _⟩,
cases le_or_lt N n,
{ exact lt_of_lt_of_le (hN _ h) (le_add_of_nonneg_left R.2) },
{ have : _ ≤ R := finset.le_sup (finset.mem_range.2 h),
exact lt_of_le_of_lt this (lt_add_of_pos_right _ zero_lt_one) }
end
/-- Yet another metric characterization of Cauchy sequences on integers. This one is often the
most efficient. -/
lemma cauchy_seq_iff_le_tendsto_0 {s : ℕ → α} : cauchy_seq s ↔ ∃ b : ℕ → ℝ,
(∀ n, 0 ≤ b n) ∧
(∀ n m N : ℕ, N ≤ n → N ≤ m → dist (s n) (s m) ≤ b N) ∧
tendsto b at_top (𝓝 0) :=
⟨λ hs, begin
/- `s` is a 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`.
First, we prove that all these distances are bounded, as otherwise the Sup
would not make sense. -/
let S := λ N, (λ(p : ℕ × ℕ), dist (s p.1) (s p.2)) '' {p | p.1 ≥ N ∧ p.2 ≥ N},
have hS : ∀ N, ∃ x, ∀ y ∈ S N, y ≤ x,
{ rcases cauchy_seq_bdd hs with ⟨R, R0, hR⟩,
refine λ N, ⟨R, _⟩, rintro _ ⟨⟨m, n⟩, _, rfl⟩,
exact le_of_lt (hR m n) },
have bdd : bdd_above (range (λ(p : ℕ × ℕ), dist (s p.1) (s p.2))),
{ rcases cauchy_seq_bdd hs with ⟨R, R0, hR⟩,
use R, rintro _ ⟨⟨m, n⟩, rfl⟩, exact le_of_lt (hR m n) },
-- Prove that it bounds the distances of points in the Cauchy sequence
have ub : ∀ m n N, N ≤ m → N ≤ n → dist (s m) (s n) ≤ Sup (S N) :=
λ m n N hm hn, real.le_Sup _ (hS N) ⟨⟨_, _⟩, ⟨hm, hn⟩, rfl⟩,
have S0m : ∀ n, (0:ℝ) ∈ S n := λ n, ⟨⟨n, n⟩, ⟨le_refl _, le_refl _⟩, dist_self _⟩,
have S0 := λ n, real.le_Sup _ (hS n) (S0m n),
-- Prove that it tends to `0`, by using the Cauchy property of `s`
refine ⟨λ N, Sup (S N), S0, ub, metric.tendsto_at_top.2 (λ ε ε0, _)⟩,
refine (metric.cauchy_seq_iff.1 hs (ε/2) (half_pos ε0)).imp (λ N hN n hn, _),
rw [real.dist_0_eq_abs, abs_of_nonneg (S0 n)],
refine lt_of_le_of_lt (real.Sup_le_ub _ ⟨_, S0m _⟩ _) (half_lt_self ε0),
rintro _ ⟨⟨m', n'⟩, ⟨hm', hn'⟩, rfl⟩,
exact le_of_lt (hN _ _ (le_trans hn hm') (le_trans hn hn'))
end,
λ ⟨b, _, b_bound, b_lim⟩, cauchy_seq_of_le_tendsto_0 b b_bound b_lim⟩
end cauchy_seq
def metric_space.induced {α β} (f : α → β) (hf : function.injective f)
(m : metric_space β) : metric_space α :=
{ dist := λ x y, dist (f x) (f y),
dist_self := λ x, dist_self _,
eq_of_dist_eq_zero := λ x y h, hf (dist_eq_zero.1 h),
dist_comm := λ x y, dist_comm _ _,
dist_triangle := λ x y z, dist_triangle _ _ _,
edist := λ x y, edist (f x) (f y),
edist_dist := λ x y, edist_dist _ _,
to_uniform_space := uniform_space.comap f m.to_uniform_space,
uniformity_dist := begin
apply @uniformity_dist_of_mem_uniformity _ _ _ _ _ (λ x y, dist (f x) (f y)),
refine λ s, mem_comap_sets.trans _,
split; intro H,
{ rcases H with ⟨r, ru, rs⟩,
rcases mem_uniformity_dist.1 ru with ⟨ε, ε0, hε⟩,
refine ⟨ε, ε0, λ a b h, rs (hε _)⟩, exact h },
{ rcases H with ⟨ε, ε0, hε⟩,
exact ⟨_, dist_mem_uniformity ε0, λ ⟨a, b⟩, hε⟩ }
end }
instance subtype.metric_space {α : Type*} {p : α → Prop} [t : metric_space α] :
metric_space (subtype p) :=
metric_space.induced coe (λ x y, subtype.coe_ext.2) t
theorem subtype.dist_eq {p : α → Prop} (x y : subtype p) : dist x y = dist (x : α) y := rfl
section nnreal
instance : metric_space nnreal := by unfold nnreal; apply_instance
lemma nnreal.dist_eq (a b : nnreal) : dist a b = abs ((a:ℝ) - b) := rfl
lemma nnreal.nndist_eq (a b : nnreal) :
nndist a b = max (a - b) (b - a) :=
begin
wlog h : a ≤ b,
{ apply nnreal.coe_eq.1,
rw [nnreal.sub_eq_zero h, max_eq_right (zero_le $ b - a), ← dist_nndist, nnreal.dist_eq,
nnreal.coe_sub h, abs, neg_sub],
apply max_eq_right,
linarith [nnreal.coe_le_coe.2 h] },
rwa [nndist_comm, max_comm]
end
end nnreal
section prod
instance prod.metric_space_max [metric_space β] : metric_space (α × β) :=
{ dist := λ x y, max (dist x.1 y.1) (dist x.2 y.2),
dist_self := λ x, by simp,
eq_of_dist_eq_zero := λ x y h, begin
cases max_le_iff.1 (le_of_eq h) with h₁ h₂,
exact prod.ext_iff.2 ⟨dist_le_zero.1 h₁, dist_le_zero.1 h₂⟩
end,
dist_comm := λ x y, by simp [dist_comm],
dist_triangle := λ x y z, max_le
(le_trans (dist_triangle _ _ _) (add_le_add (le_max_left _ _) (le_max_left _ _)))
(le_trans (dist_triangle _ _ _) (add_le_add (le_max_right _ _) (le_max_right _ _))),
edist := λ x y, max (edist x.1 y.1) (edist x.2 y.2),
edist_dist := assume x y, begin
have : monotone ennreal.of_real := assume x y h, ennreal.of_real_le_of_real h,
rw [edist_dist, edist_dist, ← this.map_max]
end,
uniformity_dist := begin
refine uniformity_prod.trans _,
simp only [uniformity_basis_dist.eq_binfi, comap_infi],
rw ← infi_inf_eq, congr, funext,
rw ← infi_inf_eq, congr, funext,
simp [inf_principal, ext_iff, max_lt_iff]
end,
to_uniform_space := prod.uniform_space }
lemma prod.dist_eq [metric_space β] {x y : α × β} :
dist x y = max (dist x.1 y.1) (dist x.2 y.2) := rfl
end prod
theorem uniform_continuous_dist' : uniform_continuous (λp:α×α, dist p.1 p.2) :=
metric.uniform_continuous_iff.2 (λ ε ε0, ⟨ε/2, half_pos ε0,
begin
suffices,
{ intros p q h, cases p with p₁ p₂, cases q with q₁ q₂,
cases max_lt_iff.1 h with h₁ h₂, clear h,
dsimp at h₁ h₂ ⊢,
rw real.dist_eq,
refine abs_sub_lt_iff.2 ⟨_, _⟩,
{ revert p₁ p₂ q₁ q₂ h₁ h₂, exact this },
{ apply this; rwa dist_comm } },
intros p₁ p₂ q₁ q₂ h₁ h₂,
have := add_lt_add
(abs_sub_lt_iff.1 (lt_of_le_of_lt (abs_dist_sub_le p₁ q₁ p₂) h₁)).1
(abs_sub_lt_iff.1 (lt_of_le_of_lt (abs_dist_sub_le p₂ q₂ q₁) h₂)).1,
rwa [add_halves, dist_comm p₂, sub_add_sub_cancel, dist_comm q₂] at this
end⟩)
theorem uniform_continuous_dist [uniform_space β] {f g : β → α}
(hf : uniform_continuous f) (hg : uniform_continuous g) :
uniform_continuous (λb, dist (f b) (g b)) :=
uniform_continuous_dist'.comp (hf.prod_mk hg)
theorem continuous_dist : continuous (λp:α×α, dist p.1 p.2) :=
uniform_continuous_dist'.continuous
theorem continuous.dist [topological_space β] {f g : β → α}
(hf : continuous f) (hg : continuous g) : continuous (λb, dist (f b) (g b)) :=
continuous_dist.comp (hf.prod_mk hg)
theorem filter.tendsto.dist {f g : β → α} {x : filter β} {a b : α}
(hf : tendsto f x (𝓝 a)) (hg : tendsto g x (𝓝 b)) :
tendsto (λx, dist (f x) (g x)) x (𝓝 (dist a b)) :=
(continuous_dist.tendsto (a, b)).comp (hf.prod_mk_nhds hg)
lemma nhds_comap_dist (a : α) : (𝓝 (0 : ℝ)).comap (λa', dist a' a) = 𝓝 a :=
by simp only [@nhds_eq_comap_uniformity α, metric.uniformity_eq_comap_nhds_zero,
comap_comap_comp, (∘), dist_comm]
lemma tendsto_iff_dist_tendsto_zero {f : β → α} {x : filter β} {a : α} :
(tendsto f x (𝓝 a)) ↔ (tendsto (λb, dist (f b) a) x (𝓝 0)) :=
by rw [← nhds_comap_dist a, tendsto_comap_iff]
lemma uniform_continuous_nndist : uniform_continuous (λp:α×α, nndist p.1 p.2) :=
uniform_continuous_subtype_mk uniform_continuous_dist' _
lemma continuous_nndist : continuous (λp:α×α, nndist p.1 p.2) :=
uniform_continuous_nndist.continuous
lemma continuous.nndist [topological_space β] {f g : β → α}
(hf : continuous f) (hg : continuous g) : continuous (λb, nndist (f b) (g b)) :=
continuous_nndist.comp (hf.prod_mk hg)
theorem filter.tendsto.nndist {f g : β → α} {x : filter β} {a b : α}
(hf : tendsto f x (𝓝 a)) (hg : tendsto g x (𝓝 b)) :
tendsto (λx, nndist (f x) (g x)) x (𝓝 (nndist a b)) :=
(continuous_nndist.tendsto (a, b)).comp (hf.prod_mk_nhds hg)
namespace metric
variables {x y z : α} {ε ε₁ ε₂ : ℝ} {s : set α}
theorem is_closed_ball : is_closed (closed_ball x ε) :=
is_closed_le (continuous_id.dist continuous_const) continuous_const
theorem closure_ball_subset_closed_ball : closure (ball x ε) ⊆ closed_ball x ε :=
closure_minimal ball_subset_closed_ball is_closed_ball
theorem frontier_ball_subset_sphere : frontier (ball x ε) ⊆ sphere x ε :=
frontier_lt_subset_eq (continuous_id.dist continuous_const) continuous_const
theorem frontier_closed_ball_subset_sphere : frontier (closed_ball x ε) ⊆ sphere x ε :=
frontier_le_subset_eq (continuous_id.dist continuous_const) continuous_const
theorem ball_subset_interior_closed_ball : ball x ε ⊆ interior (closed_ball x ε) :=
interior_maximal ball_subset_closed_ball is_open_ball
/-- ε-characterization of the closure in metric spaces-/
@[nolint ge_or_gt] -- see Note [nolint_ge]
theorem mem_closure_iff {α : Type u} [metric_space α] {s : set α} {a : α} :
a ∈ closure s ↔ ∀ε>0, ∃b ∈ s, dist a b < ε :=
(mem_closure_iff_nhds_basis nhds_basis_ball).trans $
by simp only [mem_ball, dist_comm]
lemma mem_closure_range_iff {α : Type u} [metric_space α] {e : β → α} {a : α} :
a ∈ closure (range e) ↔ ∀ε>0, ∃ k : β, dist a (e k) < ε :=
by simp only [mem_closure_iff, exists_range_iff]
lemma mem_closure_range_iff_nat {α : Type u} [metric_space α] {e : β → α} {a : α} :
a ∈ closure (range e) ↔ ∀n : ℕ, ∃ k : β, dist a (e k) < 1 / ((n : ℝ) + 1) :=
(mem_closure_iff_nhds_basis nhds_basis_ball_inv_nat_succ).trans $
by simp only [mem_ball, dist_comm, exists_range_iff, forall_const]
theorem mem_of_closed' {α : Type u} [metric_space α] {s : set α} (hs : is_closed s)
{a : α} : a ∈ s ↔ ∀ε>0, ∃b ∈ s, dist a b < ε :=
by simpa only [closure_eq_of_is_closed hs] using @mem_closure_iff _ _ s a
end metric
section pi
open finset
variables {π : β → Type*} [fintype β] [∀b, metric_space (π b)]
/-- A finite product of metric spaces is a metric space, with the sup distance. -/
instance metric_space_pi : metric_space (Πb, π b) :=
begin
/- we construct the instance from the emetric space instance to avoid checking again that the
uniformity is the same as the product uniformity, but we register nevertheless a nice formula
for the distance -/
refine emetric_space.to_metric_space_of_dist
(λf g, ((sup univ (λb, nndist (f b) (g b)) : nnreal) : ℝ)) _ _,
show ∀ (x y : Π (b : β), π b), edist x y ≠ ⊤,
{ assume x y,
rw ← lt_top_iff_ne_top,
have : (⊥ : ennreal) < ⊤ := ennreal.coe_lt_top,
simp [edist, this],
assume b,
rw lt_top_iff_ne_top,
exact edist_ne_top (x b) (y b) },
show ∀ (x y : Π (b : β), π b), ↑(sup univ (λ (b : β), nndist (x b) (y b))) =
ennreal.to_real (sup univ (λ (b : β), edist (x b) (y b))),
{ assume x y,
have : sup univ (λ (b : β), edist (x b) (y b)) = ↑(sup univ (λ (b : β), nndist (x b) (y b))),
{ simp [edist_nndist],
refine eq.symm (comp_sup_eq_sup_comp _ _ _),
exact (assume x y h, ennreal.coe_le_coe.2 h), refl },
rw this,
refl }
end
lemma dist_pi_def (f g : Πb, π b) :
dist f g = (sup univ (λb, nndist (f b) (g b)) : nnreal) := rfl
lemma dist_pi_lt_iff {f g : Πb, π b} {r : ℝ} (hr : 0 < r) :
dist f g < r ↔ ∀b, dist (f b) (g b) < r :=
begin
lift r to nnreal using le_of_lt hr,
rw_mod_cast [dist_pi_def, finset.sup_lt_iff],
{ simp [nndist], refl },
{ exact hr }
end
lemma dist_pi_le_iff {f g : Πb, π b} {r : ℝ} (hr : 0 ≤ r) :
dist f g ≤ r ↔ ∀b, dist (f b) (g b) ≤ r :=
begin
lift r to nnreal using hr,
rw_mod_cast [dist_pi_def, finset.sup_le_iff],
simp [nndist],
refl
end
/-- An open ball in a product space is a product of open balls. The assumption `0 < r`
is necessary for the case of the empty product. -/
lemma ball_pi (x : Πb, π b) {r : ℝ} (hr : 0 < r) :
ball x r = { y | ∀b, y b ∈ ball (x b) r } :=
by { ext p, simp [dist_pi_lt_iff hr] }
/-- A closed ball in a product space is a product of closed balls. The assumption `0 ≤ r`
is necessary for the case of the empty product. -/
lemma closed_ball_pi (x : Πb, π b) {r : ℝ} (hr : 0 ≤ r) :
closed_ball x r = { y | ∀b, y b ∈ closed_ball (x b) r } :=
by { ext p, simp [dist_pi_le_iff hr] }
end pi
section compact
/-- Any compact set in a metric space can be covered by finitely many balls of a given positive
radius -/
lemma finite_cover_balls_of_compact {α : Type u} [metric_space α] {s : set α}
(hs : compact s) {e : ℝ} (he : 0 < e) :
∃t ⊆ s, finite t ∧ s ⊆ ⋃x∈t, ball x e :=
begin
apply hs.elim_finite_subcover_image,
{ simp [is_open_ball] },
{ intros x xs,
simp,
exact ⟨x, ⟨xs, by simpa⟩⟩ }
end
alias finite_cover_balls_of_compact ← compact.finite_cover_balls
end compact
section proper_space
open metric
/-- A metric space is proper if all closed balls are compact. -/
class proper_space (α : Type u) [metric_space α] : Prop :=
(compact_ball : ∀x:α, ∀r, compact (closed_ball x r))
/-- If all closed balls of large enough radius are compact, then the space is proper. Especially
useful when the lower bound for the radius is 0. -/
lemma proper_space_of_compact_closed_ball_of_le
(R : ℝ) (h : ∀x:α, ∀r, R ≤ r → compact (closed_ball x r)) :
proper_space α :=
⟨begin
assume x r,
by_cases hr : R ≤ r,
{ exact h x r hr },
{ have : closed_ball x r = closed_ball x R ∩ closed_ball x r,
{ symmetry,
apply inter_eq_self_of_subset_right,
exact closed_ball_subset_closed_ball (le_of_lt (not_le.1 hr)) },
rw this,
exact (h x R (le_refl _)).inter_right is_closed_ball }
end⟩
/- A compact metric space is proper -/
@[priority 100] -- see Note [lower instance priority]
instance proper_of_compact [compact_space α] : proper_space α :=
⟨assume x r, compact_of_is_closed_subset compact_univ is_closed_ball (subset_univ _)⟩
/-- A proper space is locally compact -/
@[priority 100] -- see Note [lower instance priority]
instance locally_compact_of_proper [proper_space α] :
locally_compact_space α :=
begin
apply locally_compact_of_compact_nhds,
intros x,
existsi closed_ball x 1,
split,
{ apply mem_nhds_iff.2,
existsi (1 : ℝ),
simp,
exact ⟨zero_lt_one, ball_subset_closed_ball⟩ },
{ apply proper_space.compact_ball }
end
/-- A proper space is complete -/
@[priority 100] -- see Note [lower instance priority]
instance complete_of_proper [proper_space α] : complete_space α :=
⟨begin
intros f hf,
/- We want to show that the Cauchy filter `f` is converging. It suffices to find a closed
ball (therefore compact by properness) where it is nontrivial. -/
have A : ∃ t ∈ f, ∀ x y ∈ t, dist x y < 1 := (metric.cauchy_iff.1 hf).2 1 zero_lt_one,
rcases A with ⟨t, ⟨t_fset, ht⟩⟩,
rcases nonempty_of_mem_sets hf.1 t_fset with ⟨x, xt⟩,
have : t ⊆ closed_ball x 1 := by intros y yt; simp [dist_comm]; apply le_of_lt (ht x y xt yt),
have : closed_ball x 1 ∈ f := f.sets_of_superset t_fset this,
rcases (compact_iff_totally_bounded_complete.1 (proper_space.compact_ball x 1)).2 f hf (le_principal_iff.2 this)
with ⟨y, _, hy⟩,
exact ⟨y, hy⟩
end⟩
/-- A proper metric space is separable, and therefore second countable. Indeed, any ball is
compact, and therefore admits a countable dense subset. Taking a countable union over the balls
centered at a fixed point and with integer radius, one obtains a countable set which is
dense in the whole space. -/
@[priority 100] -- see Note [lower instance priority]
instance second_countable_of_proper [proper_space α] :
second_countable_topology α :=
begin
/- We show that the space admits a countable dense subset. The case where the space is empty
is special, and trivial. -/
have A : (univ : set α) = ∅ → ∃(s : set α), countable s ∧ closure s = (univ : set α) :=
assume H, ⟨∅, ⟨by simp, by simp; exact H.symm⟩⟩,
have B : (univ : set α).nonempty → ∃(s : set α), countable s ∧ closure s = (univ : set α) :=
begin
/- When the space is not empty, we take a point `x` in the space, and then a countable set
`T r` which is dense in the closed ball `closed_ball x r` for each `r`. Then the set
`t = ⋃ T n` (where the union is over all integers `n`) is countable, as a countable union
of countable sets, and dense in the space by construction. -/
rintros ⟨x, x_univ⟩,
choose T a using show ∀ (r:ℝ), ∃ t ⊆ closed_ball x r, (countable (t : set α) ∧ closed_ball x r = closure t),
from assume r, emetric.countable_closure_of_compact (proper_space.compact_ball _ _),
let t := (⋃n:ℕ, T (n : ℝ)),
have T₁ : countable t := by finish [countable_Union],
have T₂ : closure t ⊆ univ := by simp,
have T₃ : univ ⊆ closure t :=
begin
intros y y_univ,
rcases exists_nat_gt (dist y x) with ⟨n, n_large⟩,
have h : y ∈ closed_ball x (n : ℝ) := by simp; apply le_of_lt n_large,
have h' : closed_ball x (n : ℝ) = closure (T (n : ℝ)) := by finish,
have : y ∈ closure (T (n : ℝ)) := by rwa h' at h,
show y ∈ closure t, from mem_of_mem_of_subset this (by apply closure_mono; apply subset_Union (λ(n:ℕ), T (n:ℝ))),
end,
exact ⟨t, ⟨T₁, subset.antisymm T₂ T₃⟩⟩
end,
haveI : separable_space α := ⟨(eq_empty_or_nonempty univ).elim A B⟩,
apply emetric.second_countable_of_separable,
end
/-- A finite product of proper spaces is proper. -/
instance pi_proper_space {π : β → Type*} [fintype β] [∀b, metric_space (π b)]
[h : ∀b, proper_space (π b)] : proper_space (Πb, π b) :=
begin
refine proper_space_of_compact_closed_ball_of_le 0 (λx r hr, _),
rw closed_ball_pi _ hr,
apply compact_pi_infinite (λb, _),
apply (h b).compact_ball
end
end proper_space
namespace metric
section second_countable
open topological_space
/-- A metric space is second countable if, for every ε > 0, there is a countable set which is ε-dense. -/
lemma second_countable_of_almost_dense_set
(H : ∀ε > (0 : ℝ), ∃ s : set α, countable s ∧ (∀x, ∃y ∈ s, dist x y ≤ ε)) :
second_countable_topology α :=
begin
choose T T_dense using H,
have I1 : ∀n:ℕ, (n:ℝ) + 1 > 0 :=
λn, lt_of_lt_of_le zero_lt_one (le_add_of_nonneg_left (nat.cast_nonneg _)),
have I : ∀n:ℕ, (n+1 : ℝ)⁻¹ > 0 := λn, inv_pos.2 (I1 n),
let t := ⋃n:ℕ, T (n+1)⁻¹ (I n),
have count_t : countable t := by finish [countable_Union],
have clos_t : closure t = univ,
{ refine subset.antisymm (subset_univ _) (λx xuniv, mem_closure_iff.2 (λε εpos, _)),
rcases exists_nat_gt ε⁻¹ with ⟨n, hn⟩,
have : ε⁻¹ < n + 1 := lt_of_lt_of_le hn (le_add_of_nonneg_right zero_le_one),
have nε : ((n:ℝ)+1)⁻¹ < ε := (inv_lt (I1 n) εpos).2 this,
rcases (T_dense (n+1)⁻¹ (I n)).2 x with ⟨y, yT, Dxy⟩,
have : y ∈ t := mem_of_mem_of_subset yT (by apply subset_Union (λ (n:ℕ), T (n+1)⁻¹ (I n))),
exact ⟨y, this, lt_of_le_of_lt Dxy nε⟩ },
haveI : separable_space α := ⟨⟨t, ⟨count_t, clos_t⟩⟩⟩,
exact emetric.second_countable_of_separable α
end
/-- A metric space space is second countable if one can reconstruct up to any ε>0 any element of the
space from countably many data. -/
lemma second_countable_of_countable_discretization {α : Type u} [metric_space α]
(H : ∀ε > (0 : ℝ), ∃ (β : Type u) [encodable β] (F : α → β), ∀x y, F x = F y → dist x y ≤ ε) :
second_countable_topology α :=
begin
cases (univ : set α).eq_empty_or_nonempty with hs hs,
{ haveI : compact_space α := ⟨by rw hs; exact compact_empty⟩, by apply_instance },
rcases hs with ⟨x0, hx0⟩,
letI : inhabited α := ⟨x0⟩,
refine second_countable_of_almost_dense_set (λε ε0, _),
rcases H ε ε0 with ⟨β, fβ, F, hF⟩,
let Finv := function.inv_fun F,
refine ⟨range Finv, ⟨countable_range _, λx, _⟩⟩,
let x' := Finv (F x),
have : F x' = F x := function.inv_fun_eq ⟨x, rfl⟩,
exact ⟨x', mem_range_self _, hF _ _ this.symm⟩
end
end second_countable
end metric
lemma lebesgue_number_lemma_of_metric
{s : set α} {ι} {c : ι → set α} (hs : compact s)
(hc₁ : ∀ i, is_open (c i)) (hc₂ : s ⊆ ⋃ i, c i) :
∃ δ > 0, ∀ x ∈ s, ∃ i, ball x δ ⊆ c i :=
let ⟨n, en, hn⟩ := lebesgue_number_lemma hs hc₁ hc₂,
⟨δ, δ0, hδ⟩ := mem_uniformity_dist.1 en in
⟨δ, δ0, assume x hx, let ⟨i, hi⟩ := hn x hx in
⟨i, assume y hy, hi (hδ (mem_ball'.mp hy))⟩⟩
lemma lebesgue_number_lemma_of_metric_sUnion
{s : set α} {c : set (set α)} (hs : compact s)
(hc₁ : ∀ t ∈ c, is_open t) (hc₂ : s ⊆ ⋃₀ c) :
∃ δ > 0, ∀ x ∈ s, ∃ t ∈ c, ball x δ ⊆ t :=
by rw sUnion_eq_Union at hc₂;
simpa using lebesgue_number_lemma_of_metric hs (by simpa) hc₂
namespace metric
/-- Boundedness of a subset of a metric space. We formulate the definition to work
even in the empty space. -/
def bounded (s : set α) : Prop :=
∃C, ∀x y ∈ s, dist x y ≤ C
section bounded
variables {x : α} {s t : set α} {r : ℝ}
@[simp] lemma bounded_empty : bounded (∅ : set α) :=
⟨0, by simp⟩
lemma bounded_iff_mem_bounded : bounded s ↔ ∀ x ∈ s, bounded s :=
⟨λ h _ _, h, λ H,
s.eq_empty_or_nonempty.elim
(λ hs, hs.symm ▸ bounded_empty)
(λ ⟨x, hx⟩, H x hx)⟩
/-- Subsets of a bounded set are also bounded -/
lemma bounded.subset (incl : s ⊆ t) : bounded t → bounded s :=
Exists.imp $ λ C hC x y hx hy, hC x y (incl hx) (incl hy)
/-- Closed balls are bounded -/
lemma bounded_closed_ball : bounded (closed_ball x r) :=
⟨r + r, λ y z hy hz, begin
simp only [mem_closed_ball] at *,
calc dist y z ≤ dist y x + dist z x : dist_triangle_right _ _ _
... ≤ r + r : add_le_add hy hz
end⟩
/-- Open balls are bounded -/
lemma bounded_ball : bounded (ball x r) :=
bounded_closed_ball.subset ball_subset_closed_ball
/-- Given a point, a bounded subset is included in some ball around this point -/
lemma bounded_iff_subset_ball (c : α) : bounded s ↔ ∃r, s ⊆ closed_ball c r :=
begin
split; rintro ⟨C, hC⟩,
{ cases s.eq_empty_or_nonempty with h h,
{ subst s, exact ⟨0, by simp⟩ },
{ rcases h with ⟨x, hx⟩,
exact ⟨C + dist x c, λ y hy, calc
dist y c ≤ dist y x + dist x c : dist_triangle _ _ _
... ≤ C + dist x c : add_le_add_right (hC y x hy hx) _⟩ } },
{ exact bounded_closed_ball.subset hC }
end
/-- The union of two bounded sets is bounded iff each of the sets is bounded -/
@[simp] lemma bounded_union :
bounded (s ∪ t) ↔ bounded s ∧ bounded t :=
⟨λh, ⟨h.subset (by simp), h.subset (by simp)⟩,
begin
rintro ⟨hs, ht⟩,
refine bounded_iff_mem_bounded.2 (λ x _, _),
rw bounded_iff_subset_ball x at hs ht ⊢,
rcases hs with ⟨Cs, hCs⟩, rcases ht with ⟨Ct, hCt⟩,
exact ⟨max Cs Ct, union_subset
(subset.trans hCs $ closed_ball_subset_closed_ball $ le_max_left _ _)
(subset.trans hCt $ closed_ball_subset_closed_ball $ le_max_right _ _)⟩,
end⟩
/-- A finite union of bounded sets is bounded -/
lemma bounded_bUnion {I : set β} {s : β → set α} (H : finite I) :
bounded (⋃i∈I, s i) ↔ ∀i ∈ I, bounded (s i) :=
finite.induction_on H (by simp) $ λ x I _ _ IH,
by simp [or_imp_distrib, forall_and_distrib, IH]
/-- A compact set is bounded -/
lemma bounded_of_compact {s : set α} (h : compact s) : bounded s :=
-- We cover the compact set by finitely many balls of radius 1,
-- and then argue that a finite union of bounded sets is bounded
let ⟨t, ht, fint, subs⟩ := finite_cover_balls_of_compact h zero_lt_one in
bounded.subset subs $ (bounded_bUnion fint).2 $ λ i hi, bounded_ball
alias bounded_of_compact ← compact.bounded
/-- A finite set is bounded -/
lemma bounded_of_finite {s : set α} (h : finite s) : bounded s :=
h.compact.bounded
/-- A singleton is bounded -/
lemma bounded_singleton {x : α} : bounded ({x} : set α) :=
bounded_of_finite $ finite_singleton _
/-- Characterization of the boundedness of the range of a function -/
lemma bounded_range_iff {f : β → α} : bounded (range f) ↔ ∃C, ∀x y, dist (f x) (f y) ≤ C :=
exists_congr $ λ C, ⟨
λ H x y, H _ _ ⟨x, rfl⟩ ⟨y, rfl⟩,
by rintro H _ _ ⟨x, rfl⟩ ⟨y, rfl⟩; exact H x y⟩
/-- In a compact space, all sets are bounded -/
lemma bounded_of_compact_space [compact_space α] : bounded s :=
compact_univ.bounded.subset (subset_univ _)
/-- The Heine–Borel theorem:
In a proper space, a set is compact if and only if it is closed and bounded -/
lemma compact_iff_closed_bounded [proper_space α] :
compact s ↔ is_closed s ∧ bounded s :=
⟨λ h, ⟨closed_of_compact _ h, h.bounded⟩, begin
rintro ⟨hc, hb⟩,
cases s.eq_empty_or_nonempty with h h, {simp [h, compact_empty]},
rcases h with ⟨x, hx⟩,
rcases (bounded_iff_subset_ball x).1 hb with ⟨r, hr⟩,
exact compact_of_is_closed_subset (proper_space.compact_ball x r) hc hr
end⟩
/-- The image of a proper space under an expanding onto map is proper. -/
lemma proper_image_of_proper [proper_space α] [metric_space β] (f : α → β)
(f_cont : continuous f) (hf : range f = univ) (C : ℝ)
(hC : ∀x y, dist x y ≤ C * dist (f x) (f y)) : proper_space β :=
begin
apply proper_space_of_compact_closed_ball_of_le 0 (λx₀ r hr, _),
let K := f ⁻¹' (closed_ball x₀ r),
have A : is_closed K :=
continuous_iff_is_closed.1 f_cont (closed_ball x₀ r) (is_closed_ball),
have B : bounded K := ⟨max C 0 * (r + r), λx y hx hy, calc
dist x y ≤ C * dist (f x) (f y) : hC x y
... ≤ max C 0 * dist (f x) (f y) : mul_le_mul_of_nonneg_right (le_max_left _ _) (dist_nonneg)
... ≤ max C 0 * (dist (f x) x₀ + dist (f y) x₀) :
mul_le_mul_of_nonneg_left (dist_triangle_right (f x) (f y) x₀) (le_max_right _ _)
... ≤ max C 0 * (r + r) : begin
simp only [mem_closed_ball, mem_preimage] at hx hy,
exact mul_le_mul_of_nonneg_left (add_le_add hx hy) (le_max_right _ _)
end⟩,
have : compact K := compact_iff_closed_bounded.2 ⟨A, B⟩,
have C : compact (f '' K) := this.image f_cont,
have : f '' K = closed_ball x₀ r,
by { rw image_preimage_eq_of_subset, rw hf, exact subset_univ _ },
rwa this at C
end
end bounded
section diam
variables {s : set α} {x y z : α}
/-- The diameter of a set in a metric space. To get controllable behavior even when the diameter
should be infinite, we express it in terms of the emetric.diameter -/
def diam (s : set α) : ℝ := ennreal.to_real (emetric.diam s)
/-- The diameter of a set is always nonnegative -/
lemma diam_nonneg : 0 ≤ diam s := ennreal.to_real_nonneg
lemma diam_subsingleton (hs : s.subsingleton) : diam s = 0 :=
by simp only [diam, emetric.diam_subsingleton hs, ennreal.zero_to_real]
/-- The empty set has zero diameter -/
@[simp] lemma diam_empty : diam (∅ : set α) = 0 :=
diam_subsingleton subsingleton_empty
/-- A singleton has zero diameter -/
@[simp] lemma diam_singleton : diam ({x} : set α) = 0 :=
diam_subsingleton subsingleton_singleton
-- Does not work as a simp-lemma, since {x, y} reduces to (insert y {x})
lemma diam_pair : diam ({x, y} : set α) = dist x y :=
by simp only [diam, emetric.diam_pair, dist_edist]
-- Does not work as a simp-lemma, since {x, y, z} reduces to (insert z (insert y {x}))
lemma diam_triple :
metric.diam ({x, y, z} : set α) = max (max (dist x y) (dist x z)) (dist y z) :=
begin
simp only [metric.diam, emetric.diam_triple, dist_edist],
rw [ennreal.to_real_max, ennreal.to_real_max];
apply_rules [ne_of_lt, edist_lt_top, max_lt]
end
/-- If the distance between any two points in a set is bounded by some constant `C`,
then `ennreal.of_real C` bounds the emetric diameter of this set. -/
lemma ediam_le_of_forall_dist_le {C : ℝ} (h : ∀ (x ∈ s) (y ∈ s), dist x y ≤ C) :
emetric.diam s ≤ ennreal.of_real C :=
emetric.diam_le_of_forall_edist_le $
λ x hx y hy, (edist_dist x y).symm ▸ ennreal.of_real_le_of_real (h x hx y hy)
/-- If the distance between any two points in a set is bounded by some non-negative constant,
this constant bounds the diameter. -/
lemma diam_le_of_forall_dist_le {C : ℝ} (h₀ : 0 ≤ C) (h : ∀ (x ∈ s) (y ∈ s), dist x y ≤ C) :
diam s ≤ C :=
ennreal.to_real_le_of_le_of_real h₀ (ediam_le_of_forall_dist_le h)
/-- If the distance between any two points in a nonempty set is bounded by some constant,
this constant bounds the diameter. -/
lemma diam_le_of_forall_dist_le_of_nonempty (hs : s.nonempty) {C : ℝ}
(h : ∀ (x ∈ s) (y ∈ s), dist x y ≤ C) : diam s ≤ C :=
have h₀ : 0 ≤ C, from let ⟨x, hx⟩ := hs in le_trans dist_nonneg (h x hx x hx),
diam_le_of_forall_dist_le h₀ h
/-- The distance between two points in a set is controlled by the diameter of the set. -/
lemma dist_le_diam_of_mem' (h : emetric.diam s ≠ ⊤) (hx : x ∈ s) (hy : y ∈ s) :
dist x y ≤ diam s :=
begin
rw [diam, dist_edist],
rw ennreal.to_real_le_to_real (edist_ne_top _ _) h,
exact emetric.edist_le_diam_of_mem hx hy
end
/-- Characterize the boundedness of a set in terms of the finiteness of its emetric.diameter. -/
lemma bounded_iff_ediam_ne_top : bounded s ↔ emetric.diam s ≠ ⊤ :=
iff.intro
(λ ⟨C, hC⟩, ne_top_of_le_ne_top ennreal.of_real_ne_top
(ediam_le_of_forall_dist_le $ λ x hx y hy, hC x y hx hy))
(λ h, ⟨diam s, λ x y hx hy, dist_le_diam_of_mem' h hx hy⟩)
lemma bounded.ediam_ne_top (h : bounded s) : emetric.diam s ≠ ⊤ :=
bounded_iff_ediam_ne_top.1 h
/-- The distance between two points in a set is controlled by the diameter of the set. -/
lemma dist_le_diam_of_mem (h : bounded s) (hx : x ∈ s) (hy : y ∈ s) : dist x y ≤ diam s :=
dist_le_diam_of_mem' h.ediam_ne_top hx hy
/-- An unbounded set has zero diameter. If you would prefer to get the value ∞, use `emetric.diam`.
This lemma makes it possible to avoid side conditions in some situations -/
lemma diam_eq_zero_of_unbounded (h : ¬(bounded s)) : diam s = 0 :=
begin
simp only [bounded_iff_ediam_ne_top, not_not, ne.def] at h,
simp [diam, h]
end
/-- If `s ⊆ t`, then the diameter of `s` is bounded by that of `t`, provided `t` is bounded. -/
lemma diam_mono {s t : set α} (h : s ⊆ t) (ht : bounded t) : diam s ≤ diam t :=
begin
unfold diam,
rw ennreal.to_real_le_to_real (bounded.subset h ht).ediam_ne_top ht.ediam_ne_top,
exact emetric.diam_mono h
end
/-- The diameter of a union is controlled by the sum of the diameters, and the distance between
any two points in each of the sets. This lemma is true without any side condition, since it is
obviously true if `s ∪ t` is unbounded. -/
lemma diam_union {t : set α} (xs : x ∈ s) (yt : y ∈ t) : diam (s ∪ t) ≤ diam s + dist x y + diam t :=
begin
classical, by_cases H : bounded (s ∪ t),
{ have hs : bounded s, from H.subset (subset_union_left _ _),
have ht : bounded t, from H.subset (subset_union_right _ _),
rw [bounded_iff_ediam_ne_top] at H hs ht,
rw [dist_edist, diam, diam, diam, ← ennreal.to_real_add, ← ennreal.to_real_add,
ennreal.to_real_le_to_real];
repeat { apply ennreal.add_ne_top.2; split }; try { assumption };
try { apply edist_ne_top },
exact emetric.diam_union xs yt },
{ rw [diam_eq_zero_of_unbounded H],
apply_rules [add_nonneg, diam_nonneg, dist_nonneg] }
end
/-- If two sets intersect, the diameter of the union is bounded by the sum of the diameters. -/
lemma diam_union' {t : set α} (h : (s ∩ t).nonempty) : diam (s ∪ t) ≤ diam s + diam t :=
begin
rcases h with ⟨x, ⟨xs, xt⟩⟩,
simpa using diam_union xs xt
end
/-- The diameter of a closed ball of radius `r` is at most `2 r`. -/
lemma diam_closed_ball {r : ℝ} (h : 0 ≤ r) : diam (closed_ball x r) ≤ 2 * r :=
diam_le_of_forall_dist_le (mul_nonneg (le_of_lt two_pos) h) $ λa ha b hb, calc
dist a b ≤ dist a x + dist b x : dist_triangle_right _ _ _
... ≤ r + r : add_le_add ha hb
... = 2 * r : by simp [mul_two, mul_comm]
/-- The diameter of a ball of radius `r` is at most `2 r`. -/
lemma diam_ball {r : ℝ} (h : 0 ≤ r) : diam (ball x r) ≤ 2 * r :=
le_trans (diam_mono ball_subset_closed_ball bounded_closed_ball) (diam_closed_ball h)
end diam
end metric
|
2064fee87564a044c8c24cf942d00d2669ae94e8 | 8eeb99d0fdf8125f5d39a0ce8631653f588ee817 | /src/topology/topological_fiber_bundle.lean | 4ad853853edf9142e507da7204789944dd5d9e83 | [
"Apache-2.0"
] | permissive | jesse-michael-han/mathlib | a15c58378846011b003669354cbab7062b893cfe | fa6312e4dc971985e6b7708d99a5bc3062485c89 | refs/heads/master | 1,625,200,760,912 | 1,602,081,753,000 | 1,602,081,753,000 | 181,787,230 | 0 | 0 | null | 1,555,460,682,000 | 1,555,460,682,000 | null | UTF-8 | Lean | false | false | 25,557 | 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.local_homeomorph
/-!
# Fiber bundles
A topological fiber bundle with fiber `F` over a base `B` is a space projecting on `B` for which the
fibers are all homeomorphic to `F`, such that the local situation around each point is a direct
product. We define a predicate `is_topological_fiber_bundle F p` saying that `p : Z → B` is a
topological fiber bundle with fiber `F`.
It is in general nontrivial to construct a fiber bundle. A way is to start from the knowledge of
how changes of local trivializations act on the fiber. From this, one can construct the total space
of the bundle and its topology by a suitable gluing construction. The main content of this file is
an implementation of this construction: starting from an object of type
`topological_fiber_bundle_core` registering the trivialization changes, one gets the corresponding
fiber bundle and projection.
## Main definitions
* `bundle_trivialization F p` : structure extending local homeomorphisms, defining a local
trivialization of a topological space `Z` with projection `p` and fiber `F`.
* `is_topological_fiber_bundle F p` : Prop saying that the map `p` between topological spaces is a
fiber bundle with fiber `F`.
* `topological_fiber_bundle_core ι B F` : structure registering how changes of coordinates act
on the fiber `F` above open subsets of `B`, where local trivializations are indexed by `ι`.
Let `Z : topological_fiber_bundle_core ι B F`. Then we define
* `Z.total_space` : the total space of `Z`, defined as a `Type` as `Σ (b : B), F`, but with a
twisted topology coming from the fiber bundle structure
* `Z.proj` : projection from `Z.total_space` to `B`. It is continuous.
* `Z.fiber x` : the fiber above `x`, homeomorphic to `F` (and defeq to `F` as a type).
* `Z.local_triv i`: for `i : ι`, a local homeomorphism from `Z.total_space` to `B × F`, that
realizes a trivialization above the set `Z.base_set i`, which is an open set in `B`.
## Implementation notes
A topological fiber bundle with fiber `F` over a base `B` is a family of spaces isomorphic to `F`,
indexed by `B`, which is locally trivial in the following sense: there is a covering of `B` by open
sets such that, on each such open set `s`, the bundle is isomorphic to `s × F`.
To construct a fiber bundle formally, the main data is what happens when one changes trivializations
from `s × F` to `s' × F` on `s ∩ s'`: one should get a family of homeomorphisms of `F`, depending
continuously on the base point, satisfying basic compatibility conditions (cocycle property).
Useful classes of bundles can then be specified by requiring that these homeomorphisms of `F`
belong to some subgroup, preserving some structure (the "structure group of the bundle"): then
these structures are inherited by the fibers of the bundle.
Given such trivialization change data (encoded below in a structure called
`topological_fiber_bundle_core`), one can construct the fiber bundle. The intrinsic canonical
mathematical construction is the following.
The fiber above `x` is the disjoint union of `F` over all trivializations, modulo the gluing
identifications: one gets a fiber which is isomorphic to `F`, but non-canonically
(each choice of one of the trivializations around `x` gives such an isomorphism). Given a
trivialization over a set `s`, one gets an isomorphism between `s × F` and `proj^{-1} s`, by using
the identification corresponding to this trivialization. One chooses the topology on the bundle that
makes all of these into homeomorphisms.
For the practical implementation, it turns out to be more convenient to avoid completely the
gluing and quotienting construction above, and to declare above each `x` that the fiber is `F`,
but thinking that it corresponds to the `F` coming from the choice of one trivialization around `x`.
This has several practical advantages:
* without any work, one gets a topological space structure on the fiber. And if `F` has more
structure it is inherited for free by the fiber.
* In the case of the tangent bundle of manifolds, this implies that on vector spaces the derivative
(from `F` to `F`) and the manifold derivative (from `tangent_space I x` to `tangent_space I' (f x)`)
are equal.
A drawback is that some silly constructions will typecheck: in the case of the tangent bundle, one
can add two vectors in different tangent spaces (as they both are elements of `F` from the point of
view of Lean). To solve this, one could mark the tangent space as irreducible, but then one would
lose the identification of the tangent space to `F` with `F`. There is however a big advantage of
this situation: even if Lean can not check that two basepoints are defeq, it will accept the fact
that the tangent spaces are the same. For instance, if two maps `f` and `g` are locally inverse to
each other, one can express that the composition of their derivatives is the identity of
`tangent_space I x`. One could fear issues as this composition goes from `tangent_space I x` to
`tangent_space I (g (f x))` (which should be the same, but should not be obvious to Lean
as it does not know that `g (f x) = x`). As these types are the same to Lean (equal to `F`), there
are in fact no dependent type difficulties here!
For this construction of a fiber bundle from a `topological_fiber_bundle_core`, we should thus
choose for each `x` one specific trivialization around it. We include this choice in the definition
of the `topological_fiber_bundle_core`, as it makes some constructions more
functorial and it is a nice way to say that the trivializations cover the whole space `B`.
With this definition, the type of the fiber bundle space constructed from the core data is just
`Σ (b : B), F `, but the topology is not the product one, in general.
We also take the indexing type (indexing all the trivializations) as a parameter to the fiber bundle
core: it could always be taken as a subtype of all the maps from open subsets of `B` to continuous
maps of `F`, but in practice it will sometimes be something else. For instance, on a manifold, one
will use the set of charts as a good parameterization for the trivializations of the tangent bundle.
Or for the pullback of a `topological_fiber_bundle_core`, the indexing type will be the same as
for the initial bundle.
## Tags
Fiber bundle, topological bundle, vector bundle, local trivialization, structure group
-/
variables {ι : Type*} {B : Type*} {F : Type*}
open topological_space set
open_locale topological_space
section topological_fiber_bundle
variables {Z : Type*} [topological_space B] [topological_space Z]
[topological_space F] (proj : Z → B)
variable (F)
/--
A structure extending local homeomorphisms, defining a local trivialization of a projection
`proj : Z → B` with fiber `F`, as a local homeomorphism between `Z` and `B × F` defined between two
sets of the form `proj ⁻¹' base_set` and `base_set × F`, acting trivially on the first coordinate.
-/
structure bundle_trivialization extends local_homeomorph Z (B × F) :=
(base_set : set B)
(open_base_set : is_open base_set)
(source_eq : source = proj ⁻¹' base_set)
(target_eq : target = set.prod base_set univ)
(proj_to_fun : ∀ p ∈ source, (to_fun p).1 = proj p)
instance : has_coe_to_fun (bundle_trivialization F proj) := ⟨_, λ e, e.to_fun⟩
@[simp, mfld_simps] lemma bundle_trivialization.coe_coe (e : bundle_trivialization F proj) (x : Z) :
e.to_local_homeomorph x = e x := rfl
@[simp, mfld_simps] lemma bundle_trivialization.coe_mk (e : local_homeomorph Z (B × F)) (i j k l m) (x : Z) :
(bundle_trivialization.mk e i j k l m : bundle_trivialization F proj) x = e x := rfl
/-- A topological fiber bundle with fiber F over a base B is a space projecting on B for which the
fibers are all homeomorphic to F, such that the local situation around each point is a direct
product. -/
def is_topological_fiber_bundle : Prop :=
∀ x : Z, ∃e : bundle_trivialization F proj, x ∈ e.source
variables {F} {proj}
@[simp, mfld_simps] lemma bundle_trivialization.coe_fst (e : bundle_trivialization F proj) {x : Z}
(ex : x ∈ e.source) : (e x).1 = proj x :=
e.proj_to_fun x ex
/-- In the domain of a bundle trivialization, the projection is continuous-/
lemma bundle_trivialization.continuous_at_proj (e : bundle_trivialization F proj) {x : Z}
(ex : x ∈ e.source) : continuous_at proj x :=
begin
assume s hs,
obtain ⟨t, st, t_open, xt⟩ : ∃ t ⊆ s, is_open t ∧ proj x ∈ t,
from mem_nhds_sets_iff.1 hs,
rw e.source_eq at ex,
let u := e.base_set ∩ t,
have u_open : is_open u := is_open_inter e.open_base_set t_open,
have xu : proj x ∈ u := ⟨ex, xt⟩,
/- Take a small enough open neighborhood u of `proj x`, contained in a trivialization domain o.
One should show that its preimage is open. -/
suffices : is_open (proj ⁻¹' u),
{ have : proj ⁻¹' u ∈ 𝓝 x := mem_nhds_sets this xu,
apply filter.mem_sets_of_superset this,
exact preimage_mono (subset.trans (inter_subset_right _ _) st) },
-- to do this, rewrite `proj ⁻¹' u` in terms of the trivialization, and use its continuity.
have : proj ⁻¹' u = e ⁻¹' (set.prod u univ) ∩ e.source,
{ ext p,
split,
{ assume h,
have : p ∈ e.source,
{ rw e.source_eq,
have : u ⊆ e.base_set := inter_subset_left _ _,
exact preimage_mono this h },
simp [this, h.1, h.2], },
{ rintros ⟨h, h_source⟩,
simpa [h_source] using h } },
rw [this, inter_comm],
exact continuous_on.preimage_open_of_open e.continuous_to_fun e.open_source
(is_open_prod u_open is_open_univ)
end
/-- The projection from a topological fiber bundle to its base is continuous. -/
lemma is_topological_fiber_bundle.continuous_proj (h : is_topological_fiber_bundle F proj) :
continuous proj :=
begin
rw continuous_iff_continuous_at,
assume x,
rcases h x with ⟨e, ex⟩,
exact e.continuous_at_proj ex
end
/-- The projection from a topological fiber bundle to its base is an open map. -/
lemma is_topological_fiber_bundle.is_open_map_proj (h : is_topological_fiber_bundle F proj) :
is_open_map proj :=
begin
assume s hs,
rw is_open_iff_forall_mem_open,
assume x xs,
obtain ⟨y, ys, yx⟩ : ∃ y, y ∈ s ∧ proj y = x, from (mem_image _ _ _).1 xs,
obtain ⟨e, he⟩ : ∃ (e : bundle_trivialization F proj), y ∈ e.source, from h y,
refine ⟨proj '' (s ∩ e.source), image_subset _ (inter_subset_left _ _), _, ⟨y, ⟨ys, he⟩, yx⟩⟩,
have : ∀z ∈ s ∩ e.source, prod.fst (e z) = proj z := λz hz, e.proj_to_fun z hz.2,
rw [← image_congr this, image_comp],
have : is_open (e '' (s ∩ e.source)) :=
e.to_local_homeomorph.image_open_of_open (is_open_inter hs e.to_local_homeomorph.open_source)
(inter_subset_right _ _),
exact is_open_map_fst _ this
end
/-- The first projection in a product is a topological fiber bundle. -/
lemma is_topological_fiber_bundle_fst : is_topological_fiber_bundle F (prod.fst : B × F → B) :=
begin
let F : bundle_trivialization F (prod.fst : B × F → B) :=
{ base_set := univ,
open_base_set := is_open_univ,
source_eq := rfl,
target_eq := by simp,
proj_to_fun := by simp,
..local_homeomorph.refl _ },
exact λx, ⟨F, by simp⟩
end
/-- The second projection in a product is a topological fiber bundle. -/
lemma is_topological_fiber_bundle_snd : is_topological_fiber_bundle F (prod.snd : F × B → B) :=
begin
let F : bundle_trivialization F (prod.snd : F × B → B) :=
{ base_set := univ,
open_base_set := is_open_univ,
source_eq := rfl,
target_eq := by simp,
proj_to_fun := λp, by { simp, refl },
..(homeomorph.prod_comm F B).to_local_homeomorph },
exact λx, ⟨F, by simp⟩
end
end topological_fiber_bundle
/-- Core data defining a locally trivial topological bundle with fiber `F` over a topological
space `B`. Note that "bundle" is used in its mathematical sense. This is the (computer science)
bundled version, i.e., all the relevant data is contained in the following structure. A family of
local trivializations is indexed by a type ι, on open subsets `base_set i` for each `i : ι`.
Trivialization changes from `i` to `j` are given by continuous maps `coord_change i j` from
`base_set i ∩ base_set j` to the set of homeomorphisms of `F`, but we express them as maps
`B → F → F` and require continuity on `(base_set i ∩ base_set j) × F` to avoid the topology on the
space of continuous maps on `F`. -/
structure topological_fiber_bundle_core (ι : Type*) (B : Type*) [topological_space B]
(F : Type*) [topological_space F] :=
(base_set : ι → set B)
(is_open_base_set : ∀i, is_open (base_set i))
(index_at : B → ι)
(mem_base_set_at : ∀x, x ∈ base_set (index_at x))
(coord_change : ι → ι → B → F → F)
(coord_change_self : ∀i, ∀ x ∈ base_set i, ∀v, coord_change i i x v = v)
(coord_change_continuous : ∀i j, continuous_on (λp : B × F, coord_change i j p.1 p.2)
(set.prod ((base_set i) ∩ (base_set j)) univ))
(coord_change_comp : ∀i j k, ∀x ∈ (base_set i) ∩ (base_set j) ∩ (base_set k), ∀v,
(coord_change j k x) (coord_change i j x v) = coord_change i k x v)
attribute [simp, mfld_simps] topological_fiber_bundle_core.mem_base_set_at
namespace topological_fiber_bundle_core
variables [topological_space B] [topological_space F] (Z : topological_fiber_bundle_core ι B F)
include Z
/-- The index set of a topological fiber bundle core, as a convenience function for dot notation -/
@[nolint unused_arguments]
def index := ι
/-- The base space of a topological fiber bundle core, as a convenience function for dot notation -/
@[nolint unused_arguments]
def base := B
/-- The fiber of a topological fiber bundle core, as a convenience function for dot notation and
typeclass inference -/
@[nolint unused_arguments]
def fiber (x : B) := F
instance topological_space_fiber (x : B) : topological_space (Z.fiber x) :=
by { dsimp [fiber], apply_instance }
/-- Total space of a topological bundle created from core. It is equal to `Σ (x : B), F` as a type,
but the fiber above `x` is registered as `Z.fiber x` to make sure that it is possible to register
additional type classes on these fibers. -/
@[nolint unused_arguments]
def total_space := Σ (x : B), Z.fiber x
/-- The projection from the total space of a topological fiber bundle core, on its base. -/
@[simp, mfld_simps] def proj : Z.total_space → B := λp, p.1
/-- Local homeomorphism version of the trivialization change. -/
def triv_change (i j : ι) : local_homeomorph (B × F) (B × F) :=
{ source := set.prod (Z.base_set i ∩ Z.base_set j) univ,
target := set.prod (Z.base_set i ∩ Z.base_set j) univ,
to_fun := λp, ⟨p.1, Z.coord_change i j p.1 p.2⟩,
inv_fun := λp, ⟨p.1, Z.coord_change j i p.1 p.2⟩,
map_source' := λp hp, by simpa using hp,
map_target' := λp hp, by simpa using hp,
left_inv' := begin
rintros ⟨x, v⟩ hx,
simp only [prod_mk_mem_set_prod_eq, mem_inter_eq, and_true, mem_univ] at hx,
rw [Z.coord_change_comp, Z.coord_change_self],
{ exact hx.1 },
{ simp [hx] }
end,
right_inv' := begin
rintros ⟨x, v⟩ hx,
simp only [prod_mk_mem_set_prod_eq, mem_inter_eq, and_true, mem_univ] at hx,
rw [Z.coord_change_comp, Z.coord_change_self],
{ exact hx.2 },
{ simp [hx] },
end,
open_source :=
is_open_prod (is_open_inter (Z.is_open_base_set i) (Z.is_open_base_set j)) is_open_univ,
open_target :=
is_open_prod (is_open_inter (Z.is_open_base_set i) (Z.is_open_base_set j)) is_open_univ,
continuous_to_fun :=
continuous_on.prod continuous_fst.continuous_on (Z.coord_change_continuous i j),
continuous_inv_fun := by simpa [inter_comm]
using continuous_on.prod continuous_fst.continuous_on (Z.coord_change_continuous j i) }
@[simp, mfld_simps] lemma mem_triv_change_source (i j : ι) (p : B × F) :
p ∈ (Z.triv_change i j).source ↔ p.1 ∈ Z.base_set i ∩ Z.base_set j :=
by { erw [mem_prod], simp }
/-- Associate to a trivialization index `i : ι` the corresponding trivialization, i.e., a bijection
between `proj ⁻¹ (base_set i)` and `base_set i × F`. As the fiber above `x` is `F` but read in the
chart with index `index_at x`, the trivialization in the fiber above x is by definition the
coordinate change from i to `index_at x`, so it depends on `x`.
The local trivialization will ultimately be a local homeomorphism. For now, we only introduce the
local equiv version, denoted with a prime. In further developments, avoid this auxiliary version,
and use Z.local_triv instead.
-/
def local_triv' (i : ι) : local_equiv Z.total_space (B × F) :=
{ source := Z.proj ⁻¹' (Z.base_set i),
target := set.prod (Z.base_set i) univ,
inv_fun := λp, ⟨p.1, Z.coord_change i (Z.index_at p.1) p.1 p.2⟩,
to_fun := λp, ⟨p.1, Z.coord_change (Z.index_at p.1) i p.1 p.2⟩,
map_source' := λp hp,
by simpa only [set.mem_preimage, and_true, set.mem_univ, set.prod_mk_mem_set_prod_eq] using hp,
map_target' := λp hp,
by simpa only [set.mem_preimage, and_true, set.mem_univ, set.mem_prod] using hp,
left_inv' := begin
rintros ⟨x, v⟩ hx,
change x ∈ Z.base_set i at hx,
dsimp,
rw [Z.coord_change_comp, Z.coord_change_self],
{ exact Z.mem_base_set_at _ },
{ simp [hx] }
end,
right_inv' := begin
rintros ⟨x, v⟩ hx,
simp only [prod_mk_mem_set_prod_eq, and_true, mem_univ] at hx,
rw [Z.coord_change_comp, Z.coord_change_self],
{ exact hx },
{ simp [hx] }
end }
@[simp, mfld_simps] lemma mem_local_triv'_source (i : ι) (p : Z.total_space) :
p ∈ (Z.local_triv' i).source ↔ p.1 ∈ Z.base_set i :=
by refl
@[simp, mfld_simps] lemma mem_local_triv'_target (i : ι) (p : B × F) :
p ∈ (Z.local_triv' i).target ↔ p.1 ∈ Z.base_set i :=
by { erw [mem_prod], simp }
@[simp, mfld_simps] lemma local_triv'_apply (i : ι) (p : Z.total_space) :
(Z.local_triv' i) p = ⟨p.1, Z.coord_change (Z.index_at p.1) i p.1 p.2⟩ := rfl
@[simp, mfld_simps] lemma local_triv'_symm_apply (i : ι) (p : B × F) :
(Z.local_triv' i).symm p = ⟨p.1, Z.coord_change i (Z.index_at p.1) p.1 p.2⟩ := rfl
/-- The composition of two local trivializations is the trivialization change Z.triv_change i j. -/
lemma local_triv'_trans (i j : ι) :
(Z.local_triv' i).symm.trans (Z.local_triv' j) ≈ (Z.triv_change i j).to_local_equiv :=
begin
split,
{ ext x, erw [mem_prod], simp [local_equiv.trans_source] },
{ rintros ⟨x, v⟩ hx,
simp only [triv_change, local_triv', local_equiv.symm, true_and, prod_mk_mem_set_prod_eq,
local_equiv.trans_source, mem_inter_eq, and_true, mem_univ, prod.mk.inj_iff, mem_preimage,
proj, local_equiv.coe_mk, eq_self_iff_true, local_equiv.coe_trans] at hx ⊢,
simp [Z.coord_change_comp, hx] }
end
/-- Topological structure on the total space of a topological bundle created from core, designed so
that all the local trivialization are continuous. -/
instance to_topological_space : topological_space Z.total_space :=
topological_space.generate_from $ ⋃ (i : ι) (s : set (B × F)) (s_open : is_open s),
{(Z.local_triv' i).source ∩ (Z.local_triv' i) ⁻¹' s}
lemma open_source' (i : ι) : is_open (Z.local_triv' i).source :=
begin
apply topological_space.generate_open.basic,
simp only [exists_prop, mem_Union, mem_singleton_iff],
refine ⟨i, set.prod (Z.base_set i) univ, is_open_prod (Z.is_open_base_set i) (is_open_univ), _⟩,
ext p,
simp only with mfld_simps
end
lemma open_target' (i : ι) : is_open (Z.local_triv' i).target :=
is_open_prod (Z.is_open_base_set i) (is_open_univ)
/-- Local trivialization of a topological bundle created from core, as a local homeomorphism. -/
def local_triv (i : ι) : local_homeomorph Z.total_space (B × F) :=
{ open_source := Z.open_source' i,
open_target := Z.open_target' i,
continuous_to_fun := begin
rw continuous_on_open_iff (Z.open_source' i),
assume s s_open,
apply topological_space.generate_open.basic,
simp only [exists_prop, mem_Union, mem_singleton_iff],
exact ⟨i, s, s_open, rfl⟩
end,
continuous_inv_fun := begin
apply continuous_on_open_of_generate_from (Z.open_target' i),
assume t ht,
simp only [exists_prop, mem_Union, mem_singleton_iff] at ht,
obtain ⟨j, s, s_open, ts⟩ : ∃ j s,
is_open s ∧ t = (local_triv' Z j).source ∩ (local_triv' Z j) ⁻¹' s := ht,
rw ts,
simp only [local_equiv.right_inv, preimage_inter, local_equiv.left_inv],
let e := Z.local_triv' i,
let e' := Z.local_triv' j,
let f := e.symm.trans e',
have : is_open (f.source ∩ f ⁻¹' s),
{ rw [(Z.local_triv'_trans i j).source_inter_preimage_eq],
exact (continuous_on_open_iff (Z.triv_change i j).open_source).1
((Z.triv_change i j).continuous_on) _ s_open },
convert this using 1,
dsimp [local_equiv.trans_source],
rw [← preimage_comp, inter_assoc]
end,
..Z.local_triv' i }
/- We will now state again the basic properties of the local trivializations, but without primes,
i.e., for the local homeomorphism instead of the local equiv. -/
@[simp, mfld_simps] lemma mem_local_triv_source (i : ι) (p : Z.total_space) :
p ∈ (Z.local_triv i).source ↔ p.1 ∈ Z.base_set i :=
by refl
@[simp, mfld_simps] lemma mem_local_triv_target (i : ι) (p : B × F) :
p ∈ (Z.local_triv i).target ↔ p.1 ∈ Z.base_set i :=
by { erw [mem_prod], simp }
@[simp, mfld_simps] lemma local_triv_apply (i : ι) (p : Z.total_space) :
(Z.local_triv i) p = ⟨p.1, Z.coord_change (Z.index_at p.1) i p.1 p.2⟩ := rfl
@[simp, mfld_simps] lemma local_triv_symm_fst (i : ι) (p : B × F) :
(Z.local_triv i).symm p = ⟨p.1, Z.coord_change i (Z.index_at p.1) p.1 p.2⟩ := rfl
/-- The composition of two local trivializations is the trivialization change Z.triv_change i j. -/
lemma local_triv_trans (i j : ι) :
(Z.local_triv i).symm.trans (Z.local_triv j) ≈ Z.triv_change i j :=
Z.local_triv'_trans i j
/-- Extended version of the local trivialization of a fiber bundle constructed from core,
registering additionally in its type that it is a local bundle trivialization. -/
def local_triv_ext (i : ι) : bundle_trivialization F Z.proj :=
{ base_set := Z.base_set i,
open_base_set := Z.is_open_base_set i,
source_eq := rfl,
target_eq := rfl,
proj_to_fun := λp hp, by simp,
..Z.local_triv i }
/-- A topological fiber bundle constructed from core is indeed a topological fiber bundle. -/
theorem is_topological_fiber_bundle : is_topological_fiber_bundle F Z.proj :=
λx, ⟨Z.local_triv_ext (Z.index_at (Z.proj x)), by simp [local_triv_ext]⟩
/-- The projection on the base of a topological bundle created from core is continuous -/
lemma continuous_proj : continuous Z.proj :=
Z.is_topological_fiber_bundle.continuous_proj
/-- The projection on the base of a topological bundle created from core is an open map -/
lemma is_open_map_proj : is_open_map Z.proj :=
Z.is_topological_fiber_bundle.is_open_map_proj
/-- Preferred local trivialization of a fiber bundle constructed from core, at a given point, as
a local homeomorphism -/
def local_triv_at (p : Z.total_space) : local_homeomorph Z.total_space (B × F) :=
Z.local_triv (Z.index_at (Z.proj p))
@[simp, mfld_simps] lemma mem_local_triv_at_source (p : Z.total_space) :
p ∈ (Z.local_triv_at p).source :=
by simp [local_triv_at]
@[simp, mfld_simps] lemma local_triv_at_fst (p q : Z.total_space) :
((Z.local_triv_at p) q).1 = q.1 := rfl
@[simp, mfld_simps] lemma local_triv_at_symm_fst (p : Z.total_space) (q : B × F) :
((Z.local_triv_at p).symm q).1 = q.1 := rfl
/-- Preferred local trivialization of a fiber bundle constructed from core, at a given point, as
a bundle trivialization -/
def local_triv_at_ext (p : Z.total_space) : bundle_trivialization F Z.proj :=
Z.local_triv_ext (Z.index_at (Z.proj p))
@[simp, mfld_simps] lemma local_triv_at_ext_to_local_homeomorph (p : Z.total_space) :
(Z.local_triv_at_ext p).to_local_homeomorph = Z.local_triv_at p := rfl
/-- If an element of `F` is invariant under all coordinate changes, then one can define a
corresponding section of the fiber bundle, which is continuous. This applies in particular to the
zero section of a vector bundle. Another example (not yet defined) would be the identity
section of the endomorphism bundle of a vector bundle. -/
lemma continuous_const_section (v : F)
(h : ∀ i j, ∀ x ∈ (Z.base_set i) ∩ (Z.base_set j), Z.coord_change i j x v = v) :
continuous (show B → Z.total_space, from λ x, ⟨x, v⟩) :=
begin
apply continuous_iff_continuous_at.2 (λ x, _),
have A : Z.base_set (Z.index_at x) ∈ 𝓝 x :=
mem_nhds_sets (Z.is_open_base_set (Z.index_at x)) (Z.mem_base_set_at x),
apply ((Z.local_triv (Z.index_at x)).continuous_at_iff_continuous_at_comp_left _).2,
{ simp only [(∘)] with mfld_simps,
apply continuous_at_id.prod,
have : continuous_on (λ (y : B), v) (Z.base_set (Z.index_at x)) := continuous_on_const,
apply (this.congr _).continuous_at A,
assume y hy,
simp only [h, hy] with mfld_simps },
{ exact A }
end
end topological_fiber_bundle_core
|
f384eda292898d7815329b3098293963341b1619 | 57c233acf9386e610d99ed20ef139c5f97504ba3 | /src/algebra/homology/augment.lean | 3b4d1154223f81d435fec84c4d52e71734abff18 | [
"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 | 11,072 | lean | /-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import algebra.homology.single
import tactic.linarith
/-!
# Augmentation and truncation of `ℕ`-indexed (co)chain complexes.
-/
open category_theory
open category_theory.limits
open homological_complex
universes v u
variables {V : Type u} [category.{v} V]
namespace chain_complex
/--
The truncation of a `ℕ`-indexed chain complex,
deleting the object at `0` and shifting everything else down.
-/
@[simps]
def truncate [has_zero_morphisms V] : chain_complex V ℕ ⥤ chain_complex V ℕ :=
{ obj := λ C,
{ X := λ i, C.X (i+1),
d := λ i j, C.d (i+1) (j+1),
shape' := λ i j w, by { apply C.shape, simpa }, },
map := λ C D f,
{ f := λ i, f.f (i+1), }, }
/--
There is a canonical chain map from the truncation of a chain map `C` to
the "single object" chain complex consisting of the truncated object `C.X 0` in degree 0.
The components of this chain map are `C.d 1 0` in degree 0, and zero otherwise.
-/
def truncate_to [has_zero_object V] [has_zero_morphisms V] (C : chain_complex V ℕ) :
truncate.obj C ⟶ (single₀ V).obj (C.X 0) :=
(to_single₀_equiv (truncate.obj C) (C.X 0)).symm ⟨C.d 1 0, by tidy⟩
-- PROJECT when `V` is abelian (but not generally?)
-- `[∀ n, exact (C.d (n+2) (n+1)) (C.d (n+1) n)] [epi (C.d 1 0)]` iff `quasi_iso (C.truncate_to)`
variables [has_zero_morphisms V]
/--
We can "augment" a chain complex by inserting an arbitrary object in degree zero
(shifting everything else up), along with a suitable differential.
-/
def augment (C : chain_complex V ℕ) {X : V} (f : C.X 0 ⟶ X) (w : C.d 1 0 ≫ f = 0) :
chain_complex V ℕ :=
{ X := λ i, match i with
| 0 := X
| (i+1) := C.X i
end,
d := λ i j, match i, j with
| 1, 0 := f
| (i+1), (j+1) := C.d i j
| _, _ := 0
end,
shape' := λ i j s, begin
simp at s,
rcases i with _|_|i; cases j; unfold_aux; try { simp },
{ simpa using s, },
{ rw [C.shape], simpa [← ne.def, nat.succ_ne_succ] using s },
end,
d_comp_d' := λ i j k hij hjk, begin
rcases i with _|_|i; rcases j with _|_|j; cases k; unfold_aux; try { simp },
cases i,
{ exact w, },
{ rw [C.shape, zero_comp],
simpa using i.succ_succ_ne_one.symm },
end, }
@[simp] lemma augment_X_zero (C : chain_complex V ℕ) {X : V} (f : C.X 0 ⟶ X) (w : C.d 1 0 ≫ f = 0) :
(augment C f w).X 0 = X := rfl
@[simp] lemma augment_X_succ (C : chain_complex V ℕ) {X : V} (f : C.X 0 ⟶ X) (w : C.d 1 0 ≫ f = 0)
(i : ℕ) :
(augment C f w).X (i+1) = C.X i := rfl
@[simp] lemma augment_d_one_zero
(C : chain_complex V ℕ) {X : V} (f : C.X 0 ⟶ X) (w : C.d 1 0 ≫ f = 0) :
(augment C f w).d 1 0 = f := rfl
@[simp] lemma augment_d_succ_succ
(C : chain_complex V ℕ) {X : V} (f : C.X 0 ⟶ X) (w : C.d 1 0 ≫ f = 0) (i j : ℕ) :
(augment C f w).d (i+1) (j+1) = C.d i j :=
by { dsimp [augment], rcases i with _|i, refl, refl, }
/--
Truncating an augmented chain complex is isomorphic (with components the identity)
to the original complex.
-/
def truncate_augment (C : chain_complex V ℕ) {X : V} (f : C.X 0 ⟶ X) (w : C.d 1 0 ≫ f = 0) :
truncate.obj (augment C f w) ≅ C :=
{ hom :=
{ f := λ i, 𝟙 _, },
inv :=
{ f := λ i, by { cases i; exact 𝟙 _, },
comm' := λ i j, by { cases i; cases j; { dsimp, simp, }, }, },
hom_inv_id' := by { ext i, cases i; { dsimp, simp, }, },
inv_hom_id' := by { ext i, cases i; { dsimp, simp, }, }, }.
@[simp] lemma truncate_augment_hom_f
(C : chain_complex V ℕ) {X : V} (f : C.X 0 ⟶ X) (w : C.d 1 0 ≫ f = 0) (i : ℕ) :
(truncate_augment C f w).hom.f i = 𝟙 (C.X i) := rfl
@[simp] lemma truncate_augment_inv_f
(C : chain_complex V ℕ) {X : V} (f : C.X 0 ⟶ X) (w : C.d 1 0 ≫ f = 0) (i : ℕ) :
(truncate_augment C f w).inv.f i = 𝟙 ((truncate.obj (augment C f w)).X i) :=
by { cases i; refl, }
@[simp] lemma chain_complex_d_succ_succ_zero (C : chain_complex V ℕ) (i : ℕ) :
C.d (i+2) 0 = 0 :=
by { rw C.shape, simpa using i.succ_succ_ne_one.symm }
/--
Augmenting a truncated complex with the original object and morphism is isomorphic
(with components the identity) to the original complex.
-/
def augment_truncate (C : chain_complex V ℕ) :
augment (truncate.obj C) (C.d 1 0) (C.d_comp_d _ _ _) ≅ C :=
{ hom :=
{ f := λ i, by { cases i; exact 𝟙 _, },
comm' := λ i j, by { rcases i with _|_|i; cases j; { dsimp, simp, }, }, },
inv :=
{ f := λ i, by { cases i; exact 𝟙 _, },
comm' := λ i j, by { rcases i with _|_|i; cases j; { dsimp, simp, }, }, },
hom_inv_id' := by { ext i, cases i; { dsimp, simp, }, },
inv_hom_id' := by { ext i, cases i; { dsimp, simp, }, }, }.
@[simp] lemma augment_truncate_hom_f_zero (C : chain_complex V ℕ) :
(augment_truncate C).hom.f 0 = 𝟙 (C.X 0) :=
rfl
@[simp] lemma augment_truncate_hom_f_succ (C : chain_complex V ℕ) (i : ℕ) :
(augment_truncate C).hom.f (i+1) = 𝟙 (C.X (i+1)) :=
rfl
@[simp] lemma augment_truncate_inv_f_zero (C : chain_complex V ℕ) :
(augment_truncate C).inv.f 0 = 𝟙 (C.X 0) :=
rfl
@[simp] lemma augment_truncate_inv_f_succ (C : chain_complex V ℕ) (i : ℕ) :
(augment_truncate C).inv.f (i+1) = 𝟙 (C.X (i+1)) :=
rfl
/--
A chain map from a chain complex to a single object chain complex in degree zero
can be reinterpreted as a chain complex.
Ths is the inverse construction of `truncate_to`.
-/
def to_single₀_as_complex
[has_zero_object V] (C : chain_complex V ℕ) (X : V) (f : C ⟶ (single₀ V).obj X) :
chain_complex V ℕ :=
let ⟨f, w⟩ := to_single₀_equiv C X f in augment C f w
end chain_complex
namespace cochain_complex
/--
The truncation of a `ℕ`-indexed cochain complex,
deleting the object at `0` and shifting everything else down.
-/
@[simps]
def truncate [has_zero_morphisms V] : cochain_complex V ℕ ⥤ cochain_complex V ℕ :=
{ obj := λ C,
{ X := λ i, C.X (i+1),
d := λ i j, C.d (i+1) (j+1),
shape' := λ i j w, by { apply C.shape, simpa }, },
map := λ C D f,
{ f := λ i, f.f (i+1), }, }
/--
There is a canonical chain map from the truncation of a cochain complex `C` to
the "single object" cochain complex consisting of the truncated object `C.X 0` in degree 0.
The components of this chain map are `C.d 0 1` in degree 0, and zero otherwise.
-/
def to_truncate [has_zero_object V] [has_zero_morphisms V] (C : cochain_complex V ℕ) :
(single₀ V).obj (C.X 0) ⟶ truncate.obj C :=
(from_single₀_equiv (truncate.obj C) (C.X 0)).symm ⟨C.d 0 1, by tidy⟩
variables [has_zero_morphisms V]
/--
We can "augment" a cochain complex by inserting an arbitrary object in degree zero
(shifting everything else up), along with a suitable differential.
-/
def augment (C : cochain_complex V ℕ) {X : V} (f : X ⟶ C.X 0) (w : f ≫ C.d 0 1 = 0) :
cochain_complex V ℕ :=
{ X := λ i, match i with
| 0 := X
| (i+1) := C.X i
end,
d := λ i j, match i, j with
| 0, 1 := f
| (i+1), (j+1) := C.d i j
| _, _ := 0
end,
shape' := λ i j s, begin
simp at s,
rcases j with _|_|j; cases i; unfold_aux; try { simp },
{ simpa using s, },
{ rw [C.shape], simp only [complex_shape.up_rel], contrapose! s, rw ←s },
end,
d_comp_d' := λ i j k hij hjk, begin
rcases k with _|_|k; rcases j with _|_|j; cases i; unfold_aux; try { simp },
cases k,
{ exact w, },
{ rw [C.shape, comp_zero],
simp only [nat.nat_zero_eq_zero, complex_shape.up_rel, zero_add],
exact (nat.one_lt_succ_succ _).ne },
end, }
@[simp] lemma augment_X_zero
(C : cochain_complex V ℕ) {X : V} (f : X ⟶ C.X 0) (w : f ≫ C.d 0 1 = 0) :
(augment C f w).X 0 = X := rfl
@[simp] lemma augment_X_succ
(C : cochain_complex V ℕ) {X : V} (f : X ⟶ C.X 0) (w : f ≫ C.d 0 1 = 0) (i : ℕ) :
(augment C f w).X (i+1) = C.X i := rfl
@[simp] lemma augment_d_zero_one
(C : cochain_complex V ℕ) {X : V} (f : X ⟶ C.X 0) (w : f ≫ C.d 0 1 = 0) :
(augment C f w).d 0 1 = f := rfl
@[simp] lemma augment_d_succ_succ
(C : cochain_complex V ℕ) {X : V} (f : X ⟶ C.X 0) (w : f ≫ C.d 0 1 = 0) (i j : ℕ) :
(augment C f w).d (i+1) (j+1) = C.d i j :=
by { dsimp [augment], rcases i with _|i, refl, refl, }
/--
Truncating an augmented cochain complex is isomorphic (with components the identity)
to the original complex.
-/
def truncate_augment (C : cochain_complex V ℕ) {X : V} (f : X ⟶ C.X 0) (w : f ≫ C.d 0 1 = 0) :
truncate.obj (augment C f w) ≅ C :=
{ hom :=
{ f := λ i, 𝟙 _, },
inv :=
{ f := λ i, by { cases i; exact 𝟙 _, },
comm' := λ i j, by { cases i; cases j; { dsimp, simp, }, }, },
hom_inv_id' := by { ext i, cases i; { dsimp, simp, }, },
inv_hom_id' := by { ext i, cases i; { dsimp, simp, }, }, }.
@[simp] lemma truncate_augment_hom_f
(C : cochain_complex V ℕ) {X : V} (f : X ⟶ C.X 0) (w : f ≫ C.d 0 1 = 0) (i : ℕ) :
(truncate_augment C f w).hom.f i = 𝟙 (C.X i) := rfl
@[simp] lemma truncate_augment_inv_f
(C : cochain_complex V ℕ) {X : V} (f : X ⟶ C.X 0) (w : f ≫ C.d 0 1 = 0) (i : ℕ) :
(truncate_augment C f w).inv.f i = 𝟙 ((truncate.obj (augment C f w)).X i) :=
by { cases i; refl, }
@[simp] lemma cochain_complex_d_succ_succ_zero (C : cochain_complex V ℕ) (i : ℕ) :
C.d 0 (i+2) = 0 :=
by { rw C.shape, simp only [complex_shape.up_rel, zero_add], exact (nat.one_lt_succ_succ _).ne }
/--
Augmenting a truncated complex with the original object and morphism is isomorphic
(with components the identity) to the original complex.
-/
def augment_truncate (C : cochain_complex V ℕ) :
augment (truncate.obj C) (C.d 0 1) (C.d_comp_d _ _ _) ≅ C :=
{ hom :=
{ f := λ i, by { cases i; exact 𝟙 _, },
comm' := λ i j, by { rcases j with _|_|j; cases i; { dsimp, simp, }, }, },
inv :=
{ f := λ i, by { cases i; exact 𝟙 _, },
comm' := λ i j, by { rcases j with _|_|j; cases i; { dsimp, simp, }, }, },
hom_inv_id' := by { ext i, cases i; { dsimp, simp, }, },
inv_hom_id' := by { ext i, cases i; { dsimp, simp, }, }, }.
@[simp] lemma augment_truncate_hom_f_zero (C : cochain_complex V ℕ) :
(augment_truncate C).hom.f 0 = 𝟙 (C.X 0) :=
rfl
@[simp] lemma augment_truncate_hom_f_succ (C : cochain_complex V ℕ) (i : ℕ) :
(augment_truncate C).hom.f (i+1) = 𝟙 (C.X (i+1)) :=
rfl
@[simp] lemma augment_truncate_inv_f_zero (C : cochain_complex V ℕ) :
(augment_truncate C).inv.f 0 = 𝟙 (C.X 0) :=
rfl
@[simp] lemma augment_truncate_inv_f_succ (C : cochain_complex V ℕ) (i : ℕ) :
(augment_truncate C).inv.f (i+1) = 𝟙 (C.X (i+1)) :=
rfl
/--
A chain map from a single object cochain complex in degree zero to a cochain complex
can be reinterpreted as a cochain complex.
Ths is the inverse construction of `to_truncate`.
-/
def from_single₀_as_complex
[has_zero_object V] (C : cochain_complex V ℕ) (X : V) (f : (single₀ V).obj X ⟶ C) :
cochain_complex V ℕ :=
let ⟨f, w⟩ := from_single₀_equiv C X f in augment C f w
end cochain_complex
|
33442e8691b0e46956f75060e01d14eaa8b84c44 | 491068d2ad28831e7dade8d6dff871c3e49d9431 | /tests/lean/slow/path_groupoids.lean | a0ce90a0a6aa8b3e83948265b90c7f770dfced90 | [
"Apache-2.0"
] | permissive | davidmueller13/lean | 65a3ed141b4088cd0a268e4de80eb6778b21a0e9 | c626e2e3c6f3771e07c32e82ee5b9e030de5b050 | refs/heads/master | 1,611,278,313,401 | 1,444,021,177,000 | 1,444,021,177,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 24,823 | lean | -- Copyright (c) 2014 Microsoft Corporation. All rights reserved.
-- Released under Apache 2.0 license as described in the file LICENSE.
-- Author: Jeremy Avigad
-- Ported from Coq HoTT
definition id {A : Type} (a : A) := a
definition compose {A : Type} {B : Type} {C : Type} (g : B → C) (f : A → B) := λ x, g (f x)
infixr ∘ := compose
-- Path
-- ----
set_option unifier.max_steps 100000
inductive path {A : Type} (a : A) : A → Type :=
idpath : path a a
definition idpath := @path.idpath
infix `≈` := path
-- TODO: is this right?
notation x `≈`:50 y `:>`:0 A:0 := @path A x y
notation `idp`:max := idpath _ -- TODO: can we / should we use `1`?
namespace path
-- Concatenation and inverse
-- -------------------------
definition concat {A : Type} {x y z : A} (p : x ≈ y) (q : y ≈ z) : x ≈ z :=
path.rec (λu, u) q p
definition inverse {A : Type} {x y : A} (p : x ≈ y) : y ≈ x :=
path.rec (idpath x) p
infixl `⬝` := concat
postfix `**`:100 := inverse
-- In Coq, these are not needed, because concat and inv are kept transparent
definition inv_1 {A : Type} (x : A) : (idpath x)** ≈ idpath x := idp
definition concat_11 {A : Type} (x : A) : idpath x ⬝ idpath x ≈ idpath x := idp
-- The 1-dimensional groupoid structure
-- ------------------------------------
-- The identity path is a right unit.
definition concat_p1 {A : Type} {x y : A} (p : x ≈ y) : p ⬝ idp ≈ p :=
path.rec_on p idp
-- The identity path is a right unit.
definition concat_1p {A : Type} {x y : A} (p : x ≈ y) : idp ⬝ p ≈ p :=
path.rec_on p idp
-- Concatenation is associative.
definition concat_p_pp {A : Type} {x y z t : A} (p : x ≈ y) (q : y ≈ z) (r : z ≈ t) :
p ⬝ (q ⬝ r) ≈ (p ⬝ q) ⬝ r :=
path.rec_on r (path.rec_on q idp)
definition concat_pp_p {A : Type} {x y z t : A} (p : x ≈ y) (q : y ≈ z) (r : z ≈ t) :
(p ⬝ q) ⬝ r ≈ p ⬝ (q ⬝ r) :=
path.rec_on r (path.rec_on q idp)
-- The left inverse law.
definition concat_pV {A : Type} {x y : A} (p : x ≈ y) : p ⬝ p** ≈ idp :=
path.rec_on p idp
-- The right inverse law.
definition concat_Vp {A : Type} {x y : A} (p : x ≈ y) : p** ⬝ p ≈ idp :=
path.rec_on p idp
-- Several auxiliary theorems about canceling inverses across associativity. These are somewhat
-- redundant, following from earlier theorems.
definition concat_V_pp {A : Type} {x y z : A} (p : x ≈ y) (q : y ≈ z) : p** ⬝ (p ⬝ q) ≈ q :=
path.rec_on q (path.rec_on p idp)
definition concat_p_Vp {A : Type} {x y z : A} (p : x ≈ y) (q : x ≈ z) : p ⬝ (p** ⬝ q) ≈ q :=
path.rec_on q (path.rec_on p idp)
definition concat_pp_V {A : Type} {x y z : A} (p : x ≈ y) (q : y ≈ z) : (p ⬝ q) ⬝ q** ≈ p :=
path.rec_on q (path.rec_on p idp)
definition concat_pV_p {A : Type} {x y z : A} (p : x ≈ z) (q : y ≈ z) : (p ⬝ q**) ⬝ q ≈ p :=
path.rec_on q (take p, path.rec_on p idp) p
-- Inverse distributes over concatenation
definition inv_pp {A : Type} {x y z : A} (p : x ≈ y) (q : y ≈ z) : (p ⬝ q)** ≈ q** ⬝ p** :=
path.rec_on q (path.rec_on p idp)
definition inv_Vp {A : Type} {x y z : A} (p : y ≈ x) (q : y ≈ z) : (p** ⬝ q)** ≈ q** ⬝ p :=
path.rec_on q (path.rec_on p idp)
-- universe metavariables
definition inv_pV {A : Type} {x y z : A} (p : x ≈ y) (q : z ≈ y) : (p ⬝ q**)** ≈ q ⬝ p** :=
path.rec_on p (λq, path.rec_on q idp) q
definition inv_VV {A : Type} {x y z : A} (p : y ≈ x) (q : z ≈ y) : (p** ⬝ q**)** ≈ q ⬝ p :=
path.rec_on p (path.rec_on q idp)
-- Inverse is an involution.
definition inv_V {A : Type} {x y : A} (p : x ≈ y) : p**** ≈ p :=
path.rec_on p idp
-- Theorems for moving things around in equations
-- ----------------------------------------------
definition moveR_Mp {A : Type} {x y z : A} (p : x ≈ z) (q : y ≈ z) (r : y ≈ x) :
p ≈ (r** ⬝ q) → (r ⬝ p) ≈ q :=
have gen : Πp q, p ≈ (r** ⬝ q) → (r ⬝ p) ≈ q, from
path.rec_on r
(take p q,
assume h : p ≈ idp** ⬝ q,
show idp ⬝ p ≈ q, from concat_1p _ ⬝ h ⬝ concat_1p _),
gen p q
definition moveR_pM {A : Type} {x y z : A} (p : x ≈ z) (q : y ≈ z) (r : y ≈ x) :
r ≈ q ⬝ p** → r ⬝ p ≈ q :=
path.rec_on p (take q r h, (concat_p1 _ ⬝ h ⬝ concat_p1 _)) q r
definition moveR_Vp {A : Type} {x y z : A} (p : x ≈ z) (q : y ≈ z) (r : x ≈ y) :
p ≈ r ⬝ q → r** ⬝ p ≈ q :=
path.rec_on r (take p q h, concat_1p _ ⬝ h ⬝ concat_1p _) p q
definition moveR_pV {A : Type} {x y z : A} (p : z ≈ x) (q : y ≈ z) (r : y ≈ x) :
r ≈ q ⬝ p → r ⬝ p** ≈ q :=
path.rec_on p (take q r h, concat_p1 _ ⬝ h ⬝ concat_p1 _) q r
definition moveL_Mp {A : Type} {x y z : A} (p : x ≈ z) (q : y ≈ z) (r : y ≈ x) :
r** ⬝ q ≈ p → q ≈ r ⬝ p :=
path.rec_on r (take p q h, (concat_1p _)** ⬝ h ⬝ (concat_1p _)**) p q
definition moveL_pM {A : Type} {x y z : A} (p : x ≈ z) (q : y ≈ z) (r : y ≈ x) :
q ⬝ p** ≈ r → q ≈ r ⬝ p :=
path.rec_on p (take q r h, (concat_p1 _)** ⬝ h ⬝ (concat_p1 _)**) q r
definition moveL_Vp {A : Type} {x y z : A} (p : x ≈ z) (q : y ≈ z) (r : x ≈ y) :
r ⬝ q ≈ p → q ≈ r** ⬝ p :=
path.rec_on r (take p q h, (concat_1p _)** ⬝ h ⬝ (concat_1p _)**) p q
definition moveL_pV {A : Type} {x y z : A} (p : z ≈ x) (q : y ≈ z) (r : y ≈ x) :
q ⬝ p ≈ r → q ≈ r ⬝ p** :=
path.rec_on p (take q r h, (concat_p1 _)** ⬝ h ⬝ (concat_p1 _)**) q r
definition moveL_1M {A : Type} {x y : A} (p q : x ≈ y) :
p ⬝ q** ≈ idp → p ≈ q :=
path.rec_on q (take p h, (concat_p1 _)** ⬝ h) p
definition moveL_M1 {A : Type} {x y : A} (p q : x ≈ y) :
q** ⬝ p ≈ idp → p ≈ q :=
path.rec_on q (take p h, (concat_1p _)** ⬝ h) p
definition moveL_1V {A : Type} {x y : A} (p : x ≈ y) (q : y ≈ x) :
p ⬝ q ≈ idp → p ≈ q** :=
path.rec_on q (take p h, (concat_p1 _)** ⬝ h) p
definition moveL_V1 {A : Type} {x y : A} (p : x ≈ y) (q : y ≈ x) :
q ⬝ p ≈ idp → p ≈ q** :=
path.rec_on q (take p h, (concat_1p _)** ⬝ h) p
definition moveR_M1 {A : Type} {x y : A} (p q : x ≈ y) :
idp ≈ p** ⬝ q → p ≈ q :=
path.rec_on p (take q h, h ⬝ (concat_1p _)) q
definition moveR_1M {A : Type} {x y : A} (p q : x ≈ y) :
idp ≈ q ⬝ p** → p ≈ q :=
path.rec_on p (take q h, h ⬝ (concat_p1 _)) q
definition moveR_1V {A : Type} {x y : A} (p : x ≈ y) (q : y ≈ x) :
idp ≈ q ⬝ p → p** ≈ q :=
path.rec_on p (take q h, h ⬝ (concat_p1 _)) q
definition moveR_V1 {A : Type} {x y : A} (p : x ≈ y) (q : y ≈ x) :
idp ≈ p ⬝ q → p** ≈ q :=
path.rec_on p (take q h, h ⬝ (concat_1p _)) q
-- Transport
-- ---------
-- keep transparent, so transport _ idp p is definitionally equal to p
definition transport {A : Type} (P : A → Type) {x y : A} (p : x ≈ y) (u : P x) : P y :=
path.rec_on p u
definition transport_1 {A : Type} (P : A → Type) {x : A} (u : P x) : transport _ idp u ≈ u :=
idp
-- TODO: is the binding strength on x reasonable? (It is modeled on the notation for subst
-- in the standard library.)
-- This idiom makes the operation right associative.
notation p `#`:65 x:64 := transport _ p x
definition ap ⦃A B : Type⦄ (f : A → B) {x y:A} (p : x ≈ y) : f x ≈ f y :=
path.rec_on p idp
-- TODO: is this better than an alias? Note use of curly brackets
definition ap01 := ap
definition pointwise_paths {A : Type} {P : A → Type} (f g : Πx, P x) : Type :=
Πx : A, f x ≈ g x
infix `~` := pointwise_paths
definition apD10 {A} {B : A → Type} {f g : Πx, B x} (H : f ≈ g) : f ~ g :=
λx, path.rec_on H idp
definition ap10 {A B} {f g : A → B} (H : f ≈ g) : f ~ g := apD10 H
definition ap11 {A B} {f g : A → B} (H : f ≈ g) {x y : A} (p : x ≈ y) : f x ≈ g y :=
path.rec_on H (path.rec_on p idp)
-- TODO: Note that the next line breaks the proof!
-- opaque_hint (hiding path.rec_on)
-- set_option pp.implicit true
definition apD {A:Type} {B : A → Type} (f : Πa:A, B a) {x y : A} (p : x ≈ y) : p # (f x) ≈ f y :=
path.rec_on p idp
-- More theorems for moving things around in equations
-- ---------------------------------------------------
definition moveR_transport_p {A : Type} (P : A → Type) {x y : A} (p : x ≈ y) (u : P x) (v : P y) :
u ≈ p** # v → p # u ≈ v :=
path.rec_on p (take u v, id) u v
definition moveR_transport_V {A : Type} (P : A → Type) {x y : A} (p : y ≈ x) (u : P x) (v : P y) :
u ≈ p # v → p** # u ≈ v :=
path.rec_on p (take u v, id) u v
definition moveL_transport_V {A : Type} (P : A → Type) {x y : A} (p : x ≈ y) (u : P x) (v : P y) :
p # u ≈ v → u ≈ p** # v :=
path.rec_on p (take u v, id) u v
definition moveL_transport_p {A : Type} (P : A → Type) {x y : A} (p : y ≈ x) (u : P x) (v : P y) :
p** # u ≈ v → u ≈ p # v :=
path.rec_on p (take u v, id) u v
-- Functoriality of functions
-- --------------------------
-- Here we prove that functions behave like functors between groupoids, and that [ap] itself is
-- functorial.
-- Functions take identity paths to identity paths
definition ap_1 {A B : Type} (x : A) (f : A → B) : (ap f idp) ≈ idp :> (f x ≈ f x) := idp
definition apD_1 {A B} (x : A) (f : forall x : A, B x) : apD f idp ≈ idp :> (f x ≈ f x) := idp
-- Functions commute with concatenation.
definition ap_pp {A B : Type} (f : A → B) {x y z : A} (p : x ≈ y) (q : y ≈ z) :
ap f (p ⬝ q) ≈ (ap f p) ⬝ (ap f q) :=
path.rec_on q (path.rec_on p idp)
definition ap_p_pp {A B : Type} (f : A → B) {w x y z : A} (r : f w ≈ f x) (p : x ≈ y) (q : y ≈ z) :
r ⬝ (ap f (p ⬝ q)) ≈ (r ⬝ ap f p) ⬝ (ap f q) :=
path.rec_on p (take r q, path.rec_on q (concat_p_pp r idp idp)) r q
definition ap_pp_p {A B : Type} (f : A → B) {w x y z : A} (p : x ≈ y) (q : y ≈ z) (r : f z ≈ f w) :
(ap f (p ⬝ q)) ⬝ r ≈ (ap f p) ⬝ (ap f q ⬝ r) :=
path.rec_on p (take q, path.rec_on q (take r, concat_pp_p _ _ _)) q r
-- Functions commute with path inverses.
definition inverse_ap {A B : Type} (f : A → B) {x y : A} (p : x ≈ y) : (ap f p)** ≈ ap f (p**) :=
path.rec_on p idp
definition ap_V {A B : Type} (f : A → B) {x y : A} (p : x ≈ y) : ap f (p**) ≈ (ap f p)** :=
path.rec_on p idp
-- TODO: rename id to idmap?
definition ap_idmap {A : Type} {x y : A} (p : x ≈ y) : ap id p ≈ p :=
path.rec_on p idp
definition ap_compose {A B C : Type} (f : A → B) (g : B → C) {x y : A} (p : x ≈ y) :
ap (g ∘ f) p ≈ ap g (ap f p) :=
path.rec_on p idp
-- Sometimes we don't have the actual function [compose].
definition ap_compose' {A B C : Type} (f : A → B) (g : B → C) {x y : A} (p : x ≈ y) :
ap (λa, g (f a)) p ≈ ap g (ap f p) :=
path.rec_on p idp
-- The action of constant maps.
definition ap_const {A B : Type} {x y : A} (p : x ≈ y) (z : B) :
ap (λu, z) p ≈ idp :=
path.rec_on p idp
-- Naturality of [ap].
definition concat_Ap {A B : Type} {f g : A → B} (p : forall x, f x ≈ g x) {x y : A} (q : x ≈ y) :
(ap f q) ⬝ (p y) ≈ (p x) ⬝ (ap g q) :=
path.rec_on q (concat_1p _ ⬝ (concat_p1 _)**)
-- Naturality of [ap] at identity.
definition concat_A1p {A : Type} {f : A → A} (p : forall x, f x ≈ x) {x y : A} (q : x ≈ y) :
(ap f q) ⬝ (p y) ≈ (p x) ⬝ q :=
path.rec_on q (concat_1p _ ⬝ (concat_p1 _)**)
definition concat_pA1 {A : Type} {f : A → A} (p : forall x, x ≈ f x) {x y : A} (q : x ≈ y) :
(p x) ⬝ (ap f q) ≈ q ⬝ (p y) :=
path.rec_on q (concat_p1 _ ⬝ (concat_1p _)**)
--TODO: note that the Coq proof for the preceding is
--
-- match q as i in (_ ≈ y) return (p x ⬝ ap f i ≈ i ⬝ p y) with
-- | idpath => concat_p1 _ ⬝ (concat_1p _)**
-- end.
--
-- It is nice that we don't have to give the predicate.
-- Naturality with other paths hanging around.
definition concat_pA_pp {A B : Type} {f g : A → B} (p : forall x, f x ≈ g x)
{x y : A} (q : x ≈ y)
{w z : B} (r : w ≈ f x) (s : g y ≈ z) :
(r ⬝ ap f q) ⬝ (p y ⬝ s) ≈ (r ⬝ p x) ⬝ (ap g q ⬝ s) :=
path.rec_on q (take s, path.rec_on s (take r, idp)) s r
-- Action of [apD10] and [ap10] on paths
-- -------------------------------------
-- Application of paths between functions preserves the groupoid structure
definition apD10_1 {A} {B : A → Type} (f : Πx, B x) (x : A) : apD10 (idpath f) x ≈ idp := idp
definition apD10_pp {A} {B : A → Type} {f f' f'' : Πx, B x} (h : f ≈ f') (h' : f' ≈ f'') (x : A) :
apD10 (h ⬝ h') x ≈ apD10 h x ⬝ apD10 h' x :=
path.rec_on h (take h', path.rec_on h' idp) h'
definition apD10_V {A : Type} {B : A → Type} {f g : Πx : A, B x} (h : f ≈ g) (x : A) :
apD10 (h**) x ≈ (apD10 h x)** :=
path.rec_on h idp
definition ap10_1 {A B} {f : A → B} (x : A) : ap10 (idpath f) x ≈ idp := idp
definition ap10_pp {A B} {f f' f'' : A → B} (h : f ≈ f') (h' : f' ≈ f'') (x : A) :
ap10 (h ⬝ h') x ≈ ap10 h x ⬝ ap10 h' x := apD10_pp h h' x
definition ap10_V {A B} {f g : A→B} (h : f ≈ g) (x:A) : ap10 (h**) x ≈ (ap10 h x)** := apD10_V h x
-- [ap10] also behaves nicely on paths produced by [ap]
definition ap_ap10 {A B C} (f g : A → B) (h : B → C) (p : f ≈ g) (a : A) :
ap h (ap10 p a) ≈ ap10 (ap (λ f', h ∘ f') p) a:=
path.rec_on p idp
-- Transport and the groupoid structure of paths
-- ---------------------------------------------
-- TODO: move from above?
-- definition transport_1 {A : Type} (P : A → Type) {x : A} (u : P x)
-- : idp # u ≈ u := idp
definition transport_pp {A : Type} (P : A → Type) {x y z : A} (p : x ≈ y) (q : y ≈ z) (u : P x) :
p ⬝ q # u ≈ q # p # u :=
path.rec_on q (path.rec_on p idp)
definition transport_pV {A : Type} (P : A → Type) {x y : A} (p : x ≈ y) (z : P y) :
p # p** # z ≈ z :=
(transport_pp P (p**) p z)** ⬝ ap (λr, transport P r z) (concat_Vp p)
definition transport_Vp {A : Type} (P : A → Type) {x y : A} (p : x ≈ y) (z : P x) :
p** # p # z ≈ z :=
(transport_pp P p (p**) z)** ⬝ ap (λr, transport P r z) (concat_pV p)
-----------------------------------------------
-- *** Examples of difficult induction problems
-----------------------------------------------
theorem double_induction
{A : Type} {x y z : A} (p : x ≈ y) (q : y ≈ z)
{C : Π(x y z : A), Π(p : x ≈ y), Π(q : y ≈ z), Type}
(H : C x x x (idpath x) (idpath x)) :
C x y z p q :=
path.rec_on p (take z q, path.rec_on q H) z q
theorem double_induction2
{A : Type} {x y z : A} (p : x ≈ y) (q : z ≈ y)
{C : Π(x y z : A), Π(p : x ≈ y), Π(q : z ≈ y), Type}
(H : C z z z (idpath z) (idpath z)) :
C x y z p q :=
path.rec_on p (take y q, path.rec_on q H) y q
theorem double_induction2'
{A : Type} {x y z : A} (p : x ≈ y) (q : z ≈ y)
{C : Π(x y z : A), Π(p : x ≈ y), Π(q : z ≈ y), Type}
(H : C z z z (idpath z) (idpath z)) : C x y z p q :=
path.rec_on p (take y q, path.rec_on q H) y q
theorem triple_induction
{A : Type} {x y z w : A} (p : x ≈ y) (q : y ≈ z) (r : z ≈ w)
{C : Π(x y z w : A), Π(p : x ≈ y), Π(q : y ≈ z), Π(r: z ≈ w), Type}
(H : C x x x x (idpath x) (idpath x) (idpath x)) :
C x y z w p q r :=
path.rec_on p (take z q, path.rec_on q (take w r, path.rec_on r H)) z q w r
reveal path.double_induction2
-- try this again
definition concat_pV_p_new {A : Type} {x y z : A} (p : x ≈ z) (q : y ≈ z) : (p ⬝ q**) ⬝ q ≈ p :=
double_induction2 p q idp
reveal path.triple_induction
definition transport_p_pp {A : Type} (P : A → Type)
{x y z w : A} (p : x ≈ y) (q : y ≈ z) (r : z ≈ w) (u : P x) :
ap (λe, e # u) (concat_p_pp p q r) ⬝ (transport_pp P (p ⬝ q) r u) ⬝
ap (transport P r) (transport_pp P p q u)
≈ (transport_pp P p (q ⬝ r) u) ⬝ (transport_pp P q r (p # u))
:> ((p ⬝ (q ⬝ r)) # u ≈ r # q # p # u) :=
triple_induction p q r (take u, idp) u
-- Here is another coherence lemma for transport.
definition transport_pVp {A} (P : A → Type) {x y : A} (p : x ≈ y) (z : P x) :
transport_pV P p (transport P p z) ≈ ap (transport P p) (transport_Vp P p z)
:= path.rec_on p idp
-- Dependent transport in a doubly dependent type.
definition transportD {A : Type} (B : A → Type) (C : Π a : A, B a → Type)
{x1 x2 : A} (p : x1 ≈ x2) (y : B x1) (z : C x1 y) :
C x2 (p # y) :=
path.rec_on p z
-- Transporting along higher-dimensional paths
definition transport2 {A : Type} (P : A → Type) {x y : A} {p q : x ≈ y} (r : p ≈ q) (z : P x) :
p # z ≈ q # z := ap (λp', p' # z) r
-- An alternative definition.
definition transport2_is_ap10 {A : Type} (Q : A → Type) {x y : A} {p q : x ≈ y} (r : p ≈ q)
(z : Q x) :
transport2 Q r z ≈ ap10 (ap (transport Q) r) z :=
path.rec_on r idp
definition transport2_p2p {A : Type} (P : A → Type) {x y : A} {p1 p2 p3 : x ≈ y}
(r1 : p1 ≈ p2) (r2 : p2 ≈ p3) (z : P x) :
transport2 P (r1 ⬝ r2) z ≈ transport2 P r1 z ⬝ transport2 P r2 z :=
path.rec_on r1 (path.rec_on r2 idp)
-- TODO: another interesting case
definition transport2_V {A : Type} (Q : A → Type) {x y : A} {p q : x ≈ y} (r : p ≈ q) (z : Q x) :
transport2 Q (r**) z ≈ ((transport2 Q r z)**) :=
-- path.rec_on r idp -- doesn't work
path.rec_on r (idpath (inverse (transport2 Q (idpath p) z)))
definition concat_AT {A : Type} (P : A → Type) {x y : A} {p q : x ≈ y} {z w : P x} (r : p ≈ q)
(s : z ≈ w) :
ap (transport P p) s ⬝ transport2 P r w ≈ transport2 P r z ⬝ ap (transport P q) s :=
path.rec_on r (concat_p1 _ ⬝ (concat_1p _)**)
-- TODO (from Coq library): What should this be called?
definition ap_transport {A} {P Q : A → Type} {x y : A} (p : x ≈ y) (f : Πx, P x → Q x) (z : P x) :
f y (p # z) ≈ (p # (f x z)) :=
path.rec_on p idp
-- Transporting in particular fibrations
-- -------------------------------------
/-
From the Coq HoTT library:
One frequently needs lemmas showing that transport in a certain dependent type is equal to some
more explicitly defined operation, defined according to the structure of that dependent type.
For most dependent types, we prove these lemmas in the appropriate file in the types/
subdirectory. Here we consider only the most basic cases.
-/
-- Transporting in a constant fibration.
definition transport_const {A B : Type} {x1 x2 : A} (p : x1 ≈ x2) (y : B) :
transport (λx, B) p y ≈ y :=
path.rec_on p idp
definition transport2_const {A B : Type} {x1 x2 : A} {p q : x1 ≈ x2} (r : p ≈ q) (y : B) :
transport_const p y ≈ transport2 (λu, B) r y ⬝ transport_const q y :=
path.rec_on r (concat_1p _)**
-- Transporting in a pulled back fibration.
definition transport_compose {A B} {x y : A} (P : B → Type) (f : A → B) (p : x ≈ y) (z : P (f x)) :
transport (λx, P (f x)) p z ≈ transport P (ap f p) z :=
path.rec_on p idp
definition transport_precompose {A B C} (f : A → B) (g g' : B → C) (p : g ≈ g') :
transport (λh : B → C, g ∘ f ≈ h ∘ f) p idp ≈ ap (λh, h ∘ f) p :=
path.rec_on p idp
definition apD10_ap_precompose {A B C} (f : A → B) (g g' : B → C) (p : g ≈ g') (a : A) :
apD10 (ap (λh : B → C, h ∘ f) p) a ≈ apD10 p (f a) :=
path.rec_on p idp
definition apD10_ap_postcompose {A B C} (f : B → C) (g g' : A → B) (p : g ≈ g') (a : A) :
apD10 (ap (λh : A → B, f ∘ h) p) a ≈ ap f (apD10 p a) :=
path.rec_on p idp
-- TODO: another example where a term has to be given explicitly
-- A special case of [transport_compose] which seems to come up a lot.
definition transport_idmap_ap A (P : A → Type) x y (p : x ≈ y) (u : P x) :
transport P p u ≈ transport (λz, z) (ap P p) u :=
path.rec_on p (idpath (transport (λ (z : Type), z) (ap P (idpath x)) u))
-- The behavior of [ap] and [apD]
-- ------------------------------
-- In a constant fibration, [apD] reduces to [ap], modulo [transport_const].
definition apD_const {A B} {x y : A} (f : A → B) (p: x ≈ y) :
apD f p ≈ transport_const p (f x) ⬝ ap f p :=
path.rec_on p idp
-- The 2-dimensional groupoid structure
-- ------------------------------------
-- Horizontal composition of 2-dimensional paths.
definition concat2 {A} {x y z : A} {p p' : x ≈ y} {q q' : y ≈ z} (h : p ≈ p') (h' : q ≈ q') :
p ⬝ q ≈ p' ⬝ q' :=
path.rec_on h (path.rec_on h' idp)
infixl `⬝⬝`:75 := concat2
-- 2-dimensional path inversion
definition inverse2 {A : Type} {x y : A} {p q : x ≈ y} (h : p ≈ q) : p** ≈ q** :=
path.rec_on h idp
-- Whiskering
-- ----------
definition whiskerL {A : Type} {x y z : A} (p : x ≈ y) {q r : y ≈ z} (h : q ≈ r) : p ⬝ q ≈ p ⬝ r :=
idp ⬝⬝ h
definition whiskerR {A : Type} {x y z : A} {p q : x ≈ y} (h : p ≈ q) (r : y ≈ z) : p ⬝ r ≈ q ⬝ r :=
h ⬝⬝ idp
-- Unwhiskering, a.k.a. cancelling
-- -------------------------------
definition cancelL {A} {x y z : A} (p : x ≈ y) (q r : y ≈ z) : (p ⬝ q ≈ p ⬝ r) → (q ≈ r) :=
path.rec_on p (take r, path.rec_on r (take q a, (concat_1p q)** ⬝ a)) r q
definition cancelR {A} {x y z : A} (p q : x ≈ y) (r : y ≈ z) : (p ⬝ r ≈ q ⬝ r) → (p ≈ q) :=
path.rec_on r (take p, path.rec_on p (take q a, a ⬝ concat_p1 q)) p q
-- Whiskering and identity paths.
definition whiskerR_p1 {A : Type} {x y : A} {p q : x ≈ y} (h : p ≈ q) :
(concat_p1 p)** ⬝ whiskerR h idp ⬝ concat_p1 q ≈ h :=
path.rec_on h (path.rec_on p idp)
definition whiskerR_1p {A : Type} {x y z : A} (p : x ≈ y) (q : y ≈ z) :
whiskerR idp q ≈ idp :> (p ⬝ q ≈ p ⬝ q) :=
path.rec_on q idp
definition whiskerL_p1 {A : Type} {x y z : A} (p : x ≈ y) (q : y ≈ z) :
whiskerL p idp ≈ idp :> (p ⬝ q ≈ p ⬝ q) :=
path.rec_on q idp
definition whiskerL_1p {A : Type} {x y : A} {p q : x ≈ y} (h : p ≈ q) :
(concat_1p p) ** ⬝ whiskerL idp h ⬝ concat_1p q ≈ h :=
path.rec_on h (path.rec_on p idp)
definition concat2_p1 {A : Type} {x y : A} {p q : x ≈ y} (h : p ≈ q) :
h ⬝⬝ idp ≈ whiskerR h idp :> (p ⬝ idp ≈ q ⬝ idp) :=
path.rec_on h idp
definition concat2_1p {A : Type} {x y : A} {p q : x ≈ y} (h : p ≈ q) :
idp ⬝⬝ h ≈ whiskerL idp h :> (idp ⬝ p ≈ idp ⬝ q) :=
path.rec_on h idp
-- TODO: note, 4 inductions
-- The interchange law for concatenation.
definition concat_concat2 {A : Type} {x y z : A} {p p' p'' : x ≈ y} {q q' q'' : y ≈ z}
(a : p ≈ p') (b : p' ≈ p'') (c : q ≈ q') (d : q' ≈ q'') :
(a ⬝⬝ c) ⬝ (b ⬝⬝ d) ≈ (a ⬝ b) ⬝⬝ (c ⬝ d) :=
path.rec_on d (path.rec_on c (path.rec_on b (path.rec_on a idp)))
definition concat_whisker {A} {x y z : A} (p p' : x ≈ y) (q q' : y ≈ z) (a : p ≈ p') (b : q ≈ q') :
(whiskerR a q) ⬝ (whiskerL p' b) ≈ (whiskerL p b) ⬝ (whiskerR a q') :=
path.rec_on b (path.rec_on a (concat_1p _)**)
-- Structure corresponding to the coherence equations of a bicategory.
-- The "pentagonator": the 3-cell witnessing the associativity pentagon.
definition pentagon {A : Type₁} {v w x y z : A} (p : v ≈ w) (q : w ≈ x) (r : x ≈ y) (s : y ≈ z) :
whiskerL p (concat_p_pp q r s)
⬝ concat_p_pp p (q ⬝ r) s
⬝ whiskerR (concat_p_pp p q r) s
≈ concat_p_pp p q (r ⬝ s) ⬝ concat_p_pp (p ⬝ q) r s :=
path.rec_on p (take q, path.rec_on q (take r, path.rec_on r (take s, path.rec_on s idp))) q r s
-- The 3-cell witnessing the left unit triangle.
definition triangulator {A : Type} {x y z : A} (p : x ≈ y) (q : y ≈ z) :
concat_p_pp p idp q ⬝ whiskerR (concat_p1 p) q ≈ whiskerL p (concat_1p q) :=
path.rec_on p (take q, path.rec_on q idp) q
definition eckmann_hilton {A : Type} {x:A} (p q : idp ≈ idp :> (x ≈ x)) : p ⬝ q ≈ q ⬝ p :=
(whiskerR_p1 p ⬝⬝ whiskerL_1p q)**
⬝ (concat_p1 _ ⬝⬝ concat_p1 _)
⬝ (concat_1p _ ⬝⬝ concat_1p _)
⬝ (concat_whisker _ _ _ _ p q)
⬝ (concat_1p _ ⬝⬝ concat_1p _)**
⬝ (concat_p1 _ ⬝⬝ concat_p1 _)**
⬝ (whiskerL_1p q ⬝⬝ whiskerR_p1 p)
-- The action of functions on 2-dimensional paths
definition ap02 {A B : Type} (f:A → B) {x y : A} {p q : x ≈ y} (r : p ≈ q) : ap f p ≈ ap f q :=
path.rec_on r idp
definition ap02_pp {A B} (f : A → B) {x y : A} {p p' p'' : x ≈ y} (r : p ≈ p') (r' : p' ≈ p'') :
ap02 f (r ⬝ r') ≈ ap02 f r ⬝ ap02 f r' :=
path.rec_on r (path.rec_on r' idp)
definition ap02_p2p {A B} (f : A→B) {x y z : A} {p p' : x ≈ y} {q q' :y ≈ z} (r : p ≈ p')
(s : q ≈ q') :
ap02 f (r ⬝⬝ s) ≈ ap_pp f p q
⬝ (ap02 f r ⬝⬝ ap02 f s)
⬝ (ap_pp f p' q')** :=
path.rec_on r (path.rec_on s (path.rec_on q (path.rec_on p idp)))
definition apD02 {A : Type} {B : A → Type} {x y : A} {p q : x ≈ y} (f : Π x, B x) (r : p ≈ q) :
apD f p ≈ transport2 B r (f x) ⬝ apD f q :=
path.rec_on r (concat_1p _)**
end path
|
b11a9f03cdc65ccc3b192e5ee11ebddbc1b06595 | dd4e652c749fea9ac77e404005cb3470e5f75469 | /src/mat.lean | 3745d60bdefc1932b285127600c169e63513113e | [] | no_license | skbaek/cvx | e32822ad5943541539966a37dee162b0a5495f55 | c50c790c9116f9fac8dfe742903a62bdd7292c15 | refs/heads/master | 1,623,803,010,339 | 1,618,058,958,000 | 1,618,058,958,000 | 176,293,135 | 3 | 2 | null | null | null | null | UTF-8 | Lean | false | false | 3,405 | lean | import data.matrix.basic data.real.basic
universes u v
namespace matrix
variables {l m n o : Type u} [fintype l] [fintype m] [fintype n] [fintype o]
variables {α : Type v}
-- TODO: move / generalize in matrix.lean
lemma mul_zero' [ring α] (M : matrix m n α) : M.mul (0 : matrix n l α) = 0 :=
begin
ext i j,
unfold matrix.mul,
simp
end
lemma mul_add' [ring α] (L : matrix m n α) (M N : matrix n l α) : L.mul (M + N) = L.mul M + L.mul N :=
begin
ext i j,
unfold matrix.mul,
simp [left_distrib, finset.sum_add_distrib]
end
lemma add_mul' [ring α] (M N : matrix m n α) (L : matrix n l α) : (M + N).mul L = M.mul L + N.mul L :=
begin
ext i j,
unfold matrix.mul,
simp [right_distrib, finset.sum_add_distrib]
end
lemma mul_sub' [ring α] (L : matrix m n α) (M N : matrix n l α) : L.mul (M - N) = L.mul M - L.mul N :=
by simp [mul_add']
lemma sub_mul' [ring α] (M N : matrix m n α) (L : matrix n l α) : (M - N).mul L = M.mul L - N.mul L :=
by simp [add_mul']
local postfix `ᵀ` : 1500 := transpose
-- TODO: add to mathlib
lemma transpose_smul [semiring α] (a : α) (M : matrix m n α) :
(a • M)ᵀ = a • Mᵀ :=
by ext i j; refl
-- TODO: add to mathlib
lemma eq_iff_transpose_eq (M : matrix m n α) (N : matrix m n α) : M = N ↔ Mᵀ = Nᵀ :=
begin
split,
{ intro h, ext i j, rw h },
{ intro h, ext i j, rw [←transpose_transpose M,h,transpose_transpose] },
end
end matrix
variables {k m n : nat}
variables {α : Type} [ring α]
@[reducible] def mat (α : Type) [ring α] (m n : nat) : Type :=
matrix (fin m) (fin n) α
@[reducible] def vec (α : Type) [ring α] (n : nat) : Type := (fin n) → α
local notation v `⬝` w := matrix.vec_mul_vec v w --TODO: matrix.vec_mul_vec is not the dot product but the outer vector product
namespace mat
def mem (a : α) (A : mat α m n) : Prop :=
∃ i : fin m, ∃ j : fin n, a = A i j
instance has_mem : has_mem α (mat α m n) := ⟨mem⟩
def trace_aux (A : mat α n n) : ∀ m, m ≤ n → α
| 0 h := 0
| (m+1) h :=
have h' : m < n := nat.lt_of_succ_le h,
A ⟨m,h'⟩ ⟨m,h'⟩ + trace_aux m (le_trans (nat.le_succ _) h)
def trace (A : mat α n n) : α := trace_aux A n (le_refl _)
def pos_semidef {α : Type} [ordered_ring α] (A : mat α n n) : Prop :=
∀ x : vec α n, ∀ a ∈ (x ⬝ (matrix.mul_vec A x)), (0 : α) ≤ a
def pos_def {α : Type} [ordered_ring α] (A : mat α n n) : Prop :=
∀ x : vec α n, x ≠ 0 → ∀ a ∈ (x ⬝ (matrix.mul_vec A x)), (0 : α) < a
def loewner {α : Type} [ordered_ring α] (A B : mat α n n) : Prop :=
pos_semidef (A - B)
infix `≼` : 1200 := loewner
infix `≽` : 1200 := λ A B, loewner B A
def strict_loewner [ordered_ring α] (A B : mat α n n) : Prop :=
A ≼ B ∧ A ≠ B
infix `≺` : 1200 := loewner
infix `≻` : 1200 := λ A B, strict_loewner B A
postfix `ᵀ` : 1500 := matrix.transpose
def get_diagonal (A : mat α m m) : mat α m m | i j :=
if i = j
then A i j
else 0
def lower_triangle (A : mat α m m) : mat α m m | i j :=
if i = j
then 1
else if i > j
then A i j
else 0
end mat
def lists_to_mat_core {m n : nat} (ls : list (list α))
(i : fin m) (j : fin n) : option α :=
do l ← ls.nth i.val, l.nth j.val
def lists_to_mat (m n : nat)
(ls : list (list α)) : mat α m n | i j :=
match lists_to_mat_core ls i j with
| none := 0
| (some a) := a
end
|
28771e760404c07f7f27a977b333600e0929e7e9 | 54518a41e0f0c03b53f961e37a3ac2fed5cfeaa9 | /src/aleph_one.lean | 9a38bcd77ac326a7014c23e25bee850941688b62 | [
"Apache-2.0"
] | permissive | cipher1024/flypitch | 9110cbfc99aa2195fe0a903fffc7034cdb00e87c | 357cd9cc344d7b6ea0c1f5d7232956b9ddb39359 | refs/heads/master | 1,598,733,974,743 | 1,572,308,681,000 | 1,572,992,816,000 | 218,170,521 | 0 | 0 | Apache-2.0 | 1,572,308,724,000 | 1,572,308,723,000 | null | UTF-8 | Lean | false | false | 46,132 | lean | import .bvm_extras2
universes u v
namespace pSet
section
open cardinal
lemma regularity (x : pSet.{u}) (H_nonempty : ¬ equiv x (∅ : pSet.{u})) : ∃ (y : pSet) (Hy : y ∈ x), ∀ z ∈ x, ¬ (z ∈ y) :=
begin
have := is_epsilon_well_founded x,
cases exists_mem_of_nonempty H_nonempty with w Hw,
have := this x (subset_self) ‹_›,
{ rcases this with ⟨y, Hy₁, Hy₂⟩, exact ⟨y,‹_›,‹_›⟩ }
end
noncomputable def aleph_one : pSet := card_ex (aleph 1)
lemma aleph_one_Ord : Ord aleph_one := by apply Ord_mk
def aleph_one_weak_Ord_spec (x : pSet.{u}) : Prop :=
Ord x ∧ (∀ y : pSet.{u}, Ord y ∧ ¬ injects_into y pSet.omega → x ⊆ y)
def epsilon_trichotomy (x : pSet.{u}) : Prop := ∀ (y : pSet), y ∈ x → ∀ (z : pSet), z ∈ x → equiv y z ∨ y ∈ z ∨ z ∈ y
lemma epsilon_trichotomy_of_Ord {x : pSet.{u}} (H_ord : Ord x) : epsilon_trichotomy x :=
H_ord.left.left
lemma epsilon_trichotomy_of_Ord' {x : pSet.{u}} (H_ord : Ord x) : ∀ {y} (Hy : y ∈ x) {z} (Hz : z ∈ x), equiv y z ∨ y ∈ z ∨ z ∈ y :=
by { have := epsilon_trichotomy_of_Ord H_ord, intros, unfold epsilon_trichotomy at this, solve_by_elim }
lemma is_transitive_of_mem_Ord {x : pSet.{u}} (H_ord : Ord x) : is_transitive x := H_ord.right
lemma mem_of_mem_subset {x y z : pSet.{u}} (H_sub : y ⊆ z) (H_mem : x ∈ y) : x ∈ z :=
by {rw subset_iff_all_mem at H_sub, solve_by_elim}
lemma mem_of_mem_Ord {x y z : pSet.{u}} (H_ord : Ord z) (H_mem₁ : x ∈ y) (H_mem₂ : y ∈ z) : x ∈ z :=
begin
have := is_transitive_of_mem_Ord H_ord,
refine mem_of_mem_subset _ H_mem₁, solve_by_elim
end
lemma subset_of_mem_Ord {x z : pSet.{u}} (H_ord : Ord z) (H_mem₁ : x ∈ z) : x ⊆ z :=
by {cases H_ord with H_ewo H_trans, solve_by_elim}
lemma Ord_of_mem_Ord {x z : pSet.{u}} (H_mem : x ∈ z) (H : Ord z) : Ord x :=
begin
refine ⟨_,_⟩,
{ refine ⟨_, by apply is_epsilon_well_founded⟩,
intros y₁ Hy₁ y₂ Hy₂,
apply (epsilon_trichotomy_of_Ord H); apply mem_of_mem_Ord; from ‹_› },
{ apply transitive_of_mem_Ord, repeat { assumption } }
end
def compl (x y : pSet.{u}) : pSet.{u} := {z ∈ x | ¬ z ∈ y}
lemma mem_compl_iff {x y z : pSet.{u}} : z ∈ compl x y ↔ z ∈ x ∧ ¬ z ∈ y :=
by {erw mem_sep_iff, simp}
@[reducible]def non_empty (x : pSet.{u}) : Prop := ¬ (equiv x (∅ : pSet.{u}))
lemma equiv_unfold' {x y : pSet.{u}} : equiv x y ↔ (∀ z, z ∈ x → z ∈ y) ∧ (∀ z, z ∈ y → z ∈ x ) :=
by simp [equiv.ext, subset_iff_all_mem]
lemma nonempty_iff_exists_mem {x : pSet.{u}} : non_empty x ↔ ∃ y, y ∈ x :=
begin
refine ⟨_,_⟩,
{ exact exists_mem_of_nonempty },
{ intro H_ex_mem, intro H_eq, cases H_ex_mem with y Hy, apply pSet.mem_empty y, pSet_cc }
end
lemma nonempty_compl_of_ne {x y : pSet.{u}} (H_ne : ¬ equiv x y) : (non_empty $ compl x y) ∨ (non_empty $ compl y x) :=
begin
rw equiv_unfold' at H_ne, push_neg at H_ne, cases H_ne,
{ rcases H_ne with ⟨z,Hz₁,Hz₂⟩, left, rw nonempty_iff_exists_mem, use z, simp[mem_compl_iff, *] },
{ rcases H_ne with ⟨z,Hz₁,Hz₂⟩, right, rw nonempty_iff_exists_mem, use z, simp [mem_compl_iff, *] }
end
lemma compl_empty_of_subset {x y : pSet.{u}} (H_sub : x ⊆ y) : equiv (compl x y) (∅ : pSet.{u}) :=
begin
classical, by_contra H_contra, change non_empty _ at H_contra, rw nonempty_iff_exists_mem at H_contra,
cases H_contra with z Hz, rw mem_compl_iff at Hz, cases Hz,
suffices : z ∈ y,
by contradiction,
from mem_of_mem_subset H_sub ‹_›
end
def binary_inter (x y : pSet.{u}) : pSet.{u} := {z ∈ x | z ∈ y}
lemma mem_binary_inter_iff {x y z : pSet.{u}} : z ∈ binary_inter x y ↔ (z ∈ x ∧ z ∈ y) :=
by {erw mem_sep_iff, simp}
lemma binary_inter_subset {x y : pSet.{u}} : ((binary_inter x y ⊆ x) ∧ (binary_inter x y ⊆ y)) :=
by {refine ⟨_,_⟩; rw subset_iff_all_mem; intros z Hz; rw mem_binary_inter_iff at Hz; simp*}
lemma Ord_binary_inter {x y : pSet.{u}} (H₁ : Ord x) (H₂ : Ord y) : Ord (binary_inter x y) :=
begin
refine ⟨⟨_,_⟩,_⟩,
{ intros w Hw_mem z Hz_mem, rw mem_binary_inter_iff at Hw_mem Hz_mem,
have := epsilon_trichotomy_of_Ord H₁, tidy },
{ apply is_epsilon_well_founded },
{ intros z H_mem, rw mem_binary_inter_iff at H_mem, cases H_mem with H_mem₁ H_mem₂,
rw subset_iff_all_mem, intros w Hw, rw mem_binary_inter_iff, refine ⟨_,_⟩,
{ exact mem_of_mem_Ord H₁ ‹_› ‹_› },
{ exact mem_of_mem_Ord H₂ ‹_› ‹_› }}
end
lemma Ord.lt_of_ne_and_le {x y : pSet.{u}} (H₁ : Ord x) (H₂ : Ord y) (H_ne : ¬ (equiv x y)) (H_le : x ⊆ y) : x ∈ y :=
begin
have H_compl_nonempty : non_empty (compl y x),
by { have this₁ := nonempty_compl_of_ne ‹_›,
have this₂ := compl_empty_of_subset ‹_›,
cases this₁,
{ exfalso, contradiction },
{ from ‹_› } },
have H_ex_min := regularity _ H_compl_nonempty,
rcases H_ex_min with ⟨z,⟨Hz₁,Hz₂⟩⟩,
cases mem_compl_iff.mp Hz₁ with Hz₁ Hz₁',
suffices H_eq : equiv x z, by pSet_cc,
apply mem.ext, intro a, refine ⟨_,_⟩; intro H_mem,
{ have this' := epsilon_trichotomy_of_Ord' H₂ (mem_of_mem_subset H_le ‹_›) Hz₁,
cases this',
{ exfalso, pSet_cc },
{ cases this',
{ from ‹_› },
{ exfalso, suffices : z ∈ x, by pSet_cc,
refine mem_of_mem_Ord _ _ _, from a, repeat { assumption }}},},
{ classical, by_contra,
have H_mem_y : a ∈ y,
by {exact mem_of_mem_Ord ‹Ord y› H_mem ‹_› },
have : a ∈ y ∧ ¬(a ∈ x) := ⟨‹_›,‹_›⟩,
rw ←mem_compl_iff at this,
refine absurd H_mem _, solve_by_elim }
end
lemma Ord.le_or_le {x y : pSet.{u}} (H₁ : Ord x) (H₂ : Ord y) : x ⊆ y ∨ y ⊆ x :=
begin
let w := binary_inter x y,
have w_Ord : Ord w := Ord_binary_inter H₁ H₂,
have : equiv w x ∨ equiv w y,
by { classical, by_contra H_contra, push_neg at H_contra,
suffices : w ∈ x ∧ w ∈ y,
by { suffices : w ∈ w, from mem_self ‹_›,
rwa mem_binary_inter_iff },
cases H_contra with H_contra₁ H_contra₂,
refine ⟨_,_⟩,
{ exact Ord.lt_of_ne_and_le w_Ord ‹_› ‹_› binary_inter_subset.left },
{ exact Ord.lt_of_ne_and_le w_Ord H₂ ‹_› binary_inter_subset.right }},
cases @binary_inter_subset x y with H_sub₁ H_sub₂, cases this,
{ left, dsimp[w] at this, pSet_cc },
{ right, dsimp[w] at this, pSet_cc }
end
lemma equiv.comm {x y : pSet.{u}} : equiv x y ↔ equiv y x :=
by {have := @equiv.symm, tidy} -- why does {[smt] eblast_using [equiv.symm]} fail here?
lemma Ord.trichotomy {x y : pSet.{u}} (H₁ : Ord x) (H₂ : Ord y) : equiv x y ∨ x ∈ y ∨ y ∈ x :=
begin
classical, have := Ord.le_or_le H₁ H₂,
cases this,
{ by_cases (equiv x y),
{ from or.inl ‹_› },
{ refine or.inr (or.inl _), from Ord.lt_of_ne_and_le H₁ H₂ ‹_› ‹_› }},
{ by_cases (equiv x y),
{ from or.inl ‹_› },
{ refine or.inr (or.inr _), rw equiv.comm at h,
have := @Ord.lt_of_ne_and_le, tactic.back_chaining_using_hs },},
end
lemma Ord.lt_of_le_of_lt {x y z : pSet.{u}} (Hx : Ord x) (Hy : Ord y) (Hz : Ord z) (H_le : x ⊆ y) (H_lt : y ∈ z) : x ∈ z :=
begin
have := Ord.trichotomy Hx Hy,
have H_dichotomy : x ∈ y ∨ equiv x y,
by {cases this, right, from ‹_›, cases this, left, from ‹_›,
right, rw equiv.ext, refine ⟨‹_›,_⟩, apply Hx.right, from ‹_› },
cases H_dichotomy,
{ apply mem_trans_of_transitive, from ‹_›, from ‹_›, from Hz.right },
{ rwa mem.congr_left (equiv.symm H_dichotomy) at H_lt }
end
lemma Ord.le_iff_lt_or_eq {x z : pSet.{u}} (H₁ : Ord x) (H₂ : Ord z) : x ⊆ z ↔ x ∈ z ∨ equiv x z :=
begin
classical, refine ⟨_,_⟩; intro H,
{ by_cases H_eq : equiv x z,
{ right, from ‹_› },
{ left, refine Ord.lt_of_ne_and_le H₁ _ _ _, repeat { from ‹_› }}},
{ cases H,
{ from subset_of_mem_Ord H₂ ‹_› },
{ have : x ⊆ x := subset_self, pSet_cc }},
end
local prefix `#`:70 := cardinal.mk
lemma mk_injects_into_of_mk_le_omega {η : ordinal.{u}} (H_le : #(ordinal.mk η).type ≤ #(pSet.omega : pSet.{u}).type) : injects_into (ordinal.mk η) pSet.omega :=
begin
have H_ex_inj : ∃ f : (ordinal.mk η).type → (omega : pSet.{u}).type, function.injective f,
by exact cardinal.injection_of_mk_le ‹_›,
cases H_ex_inj with f Hf,
let ψ : (ordinal.mk η).type → pSet.{u} := λ i, omega.func (f i),
have H_congr : ∀ i j, pSet.equiv ((ordinal.mk η).func i) ((ordinal.mk η).func j) → pSet.equiv (ψ i) (ψ j),
by { intros i₁ i₂ H_eqv,
suffices : i₁ = i₂, by subst this, classical, by_contra,
have := ordinal.mk_inj η i₁ i₂ ‹_›, contradiction },
have H_inj : ∀ i₁ i₂, equiv (ψ i₁) (ψ i₂) → equiv ((ordinal.mk η).func i₁) ((ordinal.mk η).func i₂),
by {intros i₁ i₂ H_eqv,
suffices : i₁ = i₂,
by { subst this },
have := omega_inj H_eqv, finish },
use pSet.function.mk ψ H_congr,
refine ⟨_,_⟩,
{ apply pSet.function.mk_is_func, simp* },
{ apply pSet.function.mk_inj_of_inj, from ‹_› }
end
lemma injects_into_omega_of_mem_aleph_one {z : pSet} (H_mem : z ∈ aleph_one) : injects_into z omega :=
begin
rcases equiv_mk_of_mem_mk z H_mem with ⟨w, Hw_lt, Hz_eq⟩,
suffices : injects_into (ordinal.mk w) omega,
by { apply P_ext_injects_into_left, from equiv.symm ‹_›, from ‹_› },
refine mk_injects_into_of_mk_le_omega _,
rw [ordinal.mk_card, mk_omega_eq_mk_omega, ←cardinal.lt_succ],
rwa [lt_ord, aleph_one_eq_succ_aleph_zero] at Hw_lt
end
lemma aleph_one_satisfies_spec : aleph_one_weak_Ord_spec aleph_one :=
begin
refine ⟨aleph_one_Ord,_⟩,
rintros z ⟨Hz₁, Hz₂⟩,
rw Ord.le_iff_lt_or_eq (aleph_one_Ord) ‹_›,
have := Ord.trichotomy aleph_one_Ord ‹_›,
cases this with this₁ this,
{ from or.inr ‹_› },
{ cases this with this₂ this₃,
{ from or.inl ‹_› },
{ exfalso, from absurd (injects_into_omega_of_mem_aleph_one ‹_›) ‹_› }}
end
end
end pSet
open lattice bSet cardinal
namespace bSet
local notation `ℵ₁` := pSet.aleph_one
local infix ` ⟹ `:65 := lattice.imp
local infix ` ⇔ `:50 := lattice.biimp
local infix `≺`:75 := (λ x y, -(larger_than x y))
local infix `≼`:75 := (λ x y, injects_into x y)
section well_ordering
variables {𝔹 : Type u} [nontrivial_complete_boolean_algebra 𝔹]
@[reducible]def is_rel (r x : bSet 𝔹) : 𝔹 := r ⊆ᴮ prod x x
def is_wo (r x : bSet 𝔹) : 𝔹 :=
is_rel r x ⊓ ((⨅y, pair y x ∈ᴮ r ⟹ (⨅z, pair z x ∈ᴮ r ⟹ (y =ᴮ z ⊔ pair y z ∈ᴮ r ⊔ pair z y ∈ᴮ r))) ⊓
(⨅u, u ⊆ᴮ x ⟹ (- (u =ᴮ ∅) ⟹ ⨆y, pair y u ∈ᴮ r ⊓ (⨅z', pair z' u ∈ᴮ r ⟹ (- (pair z' y ∈ᴮ r))))))
def mem_rel (x : bSet 𝔹) : bSet 𝔹 := subset.mk (λ pr : (prod x x).type, x.func pr.1 ∈ᴮ x.func pr.2)
lemma mem_mem_rel_iff {x y z: bSet 𝔹} {Γ} : Γ ≤ pair y z ∈ᴮ mem_rel x ↔ (Γ ≤ y ∈ᴮ x ∧ Γ ≤ z ∈ᴮ x ∧ Γ ≤ y ∈ᴮ z) :=
begin
erw mem_subset.mk_iff, refine ⟨_,_⟩; intro H,
{ simp at H, simp only [le_inf_iff.symm], bv_cases_at H pr Hpr,
bv_split_at Hpr, rw pair_eq_pair_iff at Hpr_left, cases Hpr_left with H₁ H₂,
simp only [le_inf_iff] at ⊢ Hpr_right, rcases Hpr_right with ⟨H'₁,H'₂,H'₃⟩,
refine ⟨_,_,_⟩,
{ apply bv_rw' H₁, simp, simp* },
{ apply bv_rw' H₂, simp, simp* },
{ apply bv_rw' H₁, simp, apply bv_rw' H₂, simpa }},
{ rcases H with ⟨H₁, H₂, H₃⟩,
have H₄ := H₁, have H₅ := H₂, rw mem_unfold at H₄ H₅,
bv_cases_at H₄ i Hi, bv_cases_at H₅ j Hj, bv_split_at Hi, bv_split_at Hj,
apply bv_use (i,j), refine le_inf _ _,
{ dsimp, rw pair_eq_pair_iff, from ⟨‹_›, ‹_›⟩ },
{ tidy, bv_cc } }
end
@[simp]lemma B_congr_mem_rel : B_congr (mem_rel : bSet 𝔹 → bSet 𝔹) :=
begin
intros x y Γ H_eq, apply prod_ext, apply subset.mk_subset,
{ suffices : Γ ≤ prod x x =ᴮ prod y y, by {apply bv_rw' this, simp, apply subset.mk_subset },
exact prod_congr H_eq H_eq },
{ bv_intro v, bv_imp_intro Hv_mem, bv_intro w, bv_imp_intro Hw_mem,
refine le_inf _ _,
{ bv_imp_intro Hpr_mem, erw mem_mem_rel_iff at Hpr_mem ⊢, tidy; bv_cc },
{ bv_imp_intro Hpr_mem, erw mem_mem_rel_iff at Hpr_mem ⊢, tidy; bv_cc },}
end
def prod.map (x y v w : bSet 𝔹) (f g : bSet 𝔹) : bSet 𝔹 := subset.mk (λ (pr : (prod (prod x v) (prod y w)).type), pair (x.func pr.1.1) (y.func pr.2.1) ∈ᴮ f ⊓ pair (v.func pr.1.2) (w.func pr.2.2) ∈ᴮ g)
def prod.map_self (x y f : bSet 𝔹) : bSet 𝔹 :=
prod.map x y x y f f
lemma B_congr_prod.map_self_left_aux {y f x x' : bSet 𝔹} {Γ : 𝔹} {H_eq : Γ ≤ x =ᴮ x'}
: Γ ≤
⨅ (z : bSet 𝔹),
z ∈ᴮ (λ (x : bSet 𝔹), prod.map_self x y f) x ⟹ z ∈ᴮ (λ (x : bSet 𝔹), prod.map_self x y f) x' :=
begin
bv_intro z, bv_imp_intro H_mem, erw mem_subset.mk_iff₂ at H_mem ⊢,
bv_cases_at H_mem pr Hpr,
cases pr with pr₁ pr₂, cases pr₁ with a₁ a₂, cases pr₂ with b₁ b₂,
dsimp only at Hpr,
bv_split_at Hpr, bv_split_at Hpr_right, bv_split_at Hpr_right_right,
simp at Hpr_left, rcases Hpr_left with ⟨⟨Ha₁, Ha₂⟩, Hb₁, Hb₂⟩,
have Ha₁_mem : Γ_2 ≤ (x.func a₁) ∈ᴮ x' := bv_rw'' H_eq (mem.mk'' ‹_›),
have Ha₂_mem : Γ_2 ≤ (x.func a₂) ∈ᴮ x' := bv_rw'' H_eq (mem.mk'' ‹_›),
rw mem_unfold at Ha₁_mem Ha₂_mem, bv_cases_at Ha₁_mem a₁' Ha₁',
bv_cases_at Ha₂_mem a₂' Ha₂', apply bv_use ((a₁', a₂'), (b₁, b₂)),
bv_split_at Ha₁', bv_split_at Ha₂',
refine le_inf (le_inf (le_inf ‹_› ‹_›) (le_inf ‹_› ‹_›) ) (le_inf _ (le_inf _ _)),
{ apply bv_rw' Hpr_right_left, simp, erw pair_eq_pair_iff, refine ⟨_,_⟩,
{ erw pair_eq_pair_iff, from ⟨‹_›,‹_›⟩ },
{ erw pair_eq_pair_iff, from ⟨bv_refl, bv_refl⟩ } },
{ dsimp, change _ ≤ (λ w, pair w (func y b₁) ∈ᴮ f) _, apply bv_rw' (bv_symm Ha₁'_right),
from B_ext_pair_mem_left, from ‹_› },
{ dsimp, change _ ≤ (λ w, pair w (func y b₂) ∈ᴮ f) _, apply bv_rw' (bv_symm Ha₂'_right),
from B_ext_pair_mem_left, from ‹_› }
end
@[simp]lemma B_congr_prod.map_self_left { y f : bSet 𝔹 } : B_congr (λ x : bSet 𝔹, prod.map_self x y f ) :=
begin
intros x x' Γ H_eq, refine mem_ext _ _,
{ apply B_congr_prod.map_self_left_aux, from ‹_› },
{ apply B_congr_prod.map_self_left_aux, from bv_symm ‹_› }
end
lemma mem_prod.map_self_iff { x y f a₁ a₂ b₁ b₂ : bSet 𝔹 } { Γ : 𝔹 } (H_func : Γ ≤ is_function x y f) :
Γ ≤ pair (pair a₁ a₂) (pair b₁ b₂) ∈ᴮ prod.map_self x y f ↔ Γ ≤ a₁ ∈ᴮ x ∧ Γ ≤ a₂ ∈ᴮ x ∧ Γ ≤ b₁ ∈ᴮ y ∧ Γ ≤ b₂ ∈ᴮ y ∧ Γ ≤ pair a₁ b₁ ∈ᴮ f ∧ Γ ≤ pair a₂ b₂ ∈ᴮ f :=
begin
refine ⟨_,_⟩; intro H,
{ erw mem_subset.mk_iff₂ at H, simp only [le_inf_iff.symm],
bv_cases_at H pr Hpr, rcases pr with ⟨⟨i₁,i₂⟩, ⟨j₁,j₂⟩⟩,
simp only [le_inf_iff] at Hpr, rcases Hpr with ⟨Hpr, Hpr', Hpr'', Hpr'''⟩,
simp only [le_inf_iff], simp at Hpr, rcases Hpr with ⟨⟨Hi₁, Hi₂⟩, Hj₁, Hj₂⟩,
have Ha₁_mem : Γ_1 ≤ (x.func i₁) ∈ᴮ x := (mem.mk'' ‹_›),
have Ha₂_mem : Γ_1 ≤ (x.func i₂) ∈ᴮ x := (mem.mk'' ‹_›),
have Hb₁_mem : Γ_1 ≤ (y.func j₁) ∈ᴮ y := (mem.mk'' ‹_›),
have Hb₂_mem : Γ_1 ≤ (y.func j₂) ∈ᴮ y := (mem.mk'' ‹_›),
repeat {erw pair_eq_pair_iff at Hpr'},
dsimp at Hpr', rcases Hpr' with ⟨⟨Heq₁, Heq₂⟩, Heq₃, Heq₄⟩,
refine ⟨_,_,_,_,_,_⟩,
{ bv_cc },
{ bv_cc },
{ bv_cc },
{ bv_cc },
{ suffices : Γ_1 ≤ pair a₁ b₁ =ᴮ pair (func x i₁) (func y j₁),
by { change _ ≤ (λ w, w ∈ᴮ f) _, apply bv_rw' (this), simp, from ‹_› },
rw pair_eq_pair_iff, exact ⟨‹_›,‹_›⟩ },
{ suffices : Γ_1 ≤ pair a₂ b₂ =ᴮ pair (func x i₂) (func y j₂),
by { change _ ≤ (λ w, w ∈ᴮ f) _, apply bv_rw' (this), simp, from ‹_› },
rw pair_eq_pair_iff, exact ⟨‹_›,‹_›⟩ }},
{ rcases H with ⟨Ha₁_mem, Ha₂_mem, Hb₁_mem, Hb₂_mem, Hpr₁_mem, Hpr₂_mem⟩,
erw mem_subset.mk_iff₂,
rw mem_unfold at Ha₁_mem Ha₂_mem Hb₁_mem Hb₂_mem,
bv_cases_at Ha₁_mem i₁ Hi₁, bv_split_at Hi₁,
bv_cases_at Ha₂_mem i₂ Hi₂, bv_split_at Hi₂,
bv_cases_at Hb₁_mem j₁ Hj₁, bv_split_at Hj₁,
bv_cases_at Hb₂_mem j₂ Hj₂, bv_split_at Hj₂,
apply bv_use ((i₁,i₂), (j₁,j₂)),
refine le_inf (le_inf (le_inf ‹_› ‹_›) (le_inf ‹_› ‹_›)) (le_inf _ (le_inf _ _)),
{ repeat {erw pair_eq_pair_iff}, simp* },
{ dsimp, suffices : Γ_4 ≤ pair (func x i₁) (func y j₁) =ᴮ pair a₁ b₁,
by { change _ ≤ (λ w, w ∈ᴮ f) _, apply bv_rw' this, simp, from ‹_› },
rw pair_eq_pair_iff, refine ⟨bv_symm _, bv_symm _⟩; assumption },
{ dsimp, suffices : Γ_4 ≤ pair (func x i₂) (func y j₂) =ᴮ pair a₂ b₂,
by { change _ ≤ (λ w, w ∈ᴮ f) _, apply bv_rw' this, simp, from ‹_› },
rw pair_eq_pair_iff, refine ⟨bv_symm _, bv_symm _⟩; assumption } }
end
def induced_epsilon_rel (η : bSet 𝔹) (x : bSet 𝔹) (f : bSet 𝔹) : bSet 𝔹 :=
image (mem_rel η) (prod x x) (prod.map_self η x f)
lemma eq_pair_of_mem_induced_epsilon_rel {η x f pr : bSet 𝔹} {Γ} (H_mem : Γ ≤ pr ∈ᴮ induced_epsilon_rel η x f) : ∃ a b : bSet 𝔹, Γ ≤ a ∈ᴮ x ∧ Γ ≤ b ∈ᴮ x ∧ Γ ≤ pr =ᴮ pair a b ∧ Γ ≤ pair a b ∈ᴮ induced_epsilon_rel η x f :=
begin
have : Γ ≤ pr ∈ᴮ prod x x,
by {refine mem_of_mem_subset _ H_mem, apply subset.mk_subset},
rw mem_prod_iff₂ at this, rcases this with ⟨v,Hv,w,Hw,H_eq⟩,
use v, use w, refine ⟨‹_›,‹_›,‹_›, _⟩,
change _ ≤ (λ z, z ∈ᴮ induced_epsilon_rel η x f) _, apply bv_rw' (bv_symm H_eq), simpa
end
lemma mem_induced_epsilon_rel_iff { η x f a b : bSet 𝔹 } { Γ } (H_func : Γ ≤ is_function η x f) : Γ ≤ pair a b ∈ᴮ (induced_epsilon_rel η x f) ↔ (Γ ≤ a ∈ᴮ x) ∧ (Γ ≤ b ∈ᴮ x) ∧ (Γ ≤ ⨆ a', a' ∈ᴮ η ⊓ ⨆ b', b' ∈ᴮ η ⊓ (pair a' a ∈ᴮ f ⊓ pair b' b ∈ᴮ f ⊓ a' ∈ᴮ b')) :=
begin
refine ⟨_,_⟩; intro H,
{ erw mem_image_iff at H, cases H with H₁ H₂,
simp at H₁, cases H₁ with H₁ H₁',
refine ⟨‹_›,‹_›,_⟩,
bv_cases_at H₂ z Hz, bv_split_at Hz,
have : Γ_1 ≤ z ∈ᴮ prod η η,
by {refine mem_of_mem_subset _ Hz_left, apply subset.mk_subset },
rw mem_prod_iff₂ at this, rcases this with ⟨v,Hv,w,Hw,H_eq⟩,
apply bv_use v, refine le_inf ‹_› (bv_use w), refine le_inf ‹_› _,
have : Γ_1 ≤ pair (pair v w) (pair a b) ∈ᴮ prod.map_self η x f,
by { change _ ≤ (λ k, pair k (pair a b) ∈ᴮ prod.map_self η x f) _, apply bv_rw' (bv_symm H_eq),
simp, from ‹_› },
rw mem_prod.map_self_iff at this, rcases this with ⟨_,_,_,_,_,_⟩,
refine le_inf (le_inf ‹_› ‹_›) _,
suffices : Γ_1 ≤ (pair v w ∈ᴮ mem_rel η),
by { rw mem_mem_rel_iff at this, simp* },
change _ ≤ (λ s, s ∈ᴮ mem_rel η) _, apply bv_rw' (bv_symm H_eq), simp, from ‹_›, from ‹_› },
{ rcases H with ⟨H₁,H₂,H₃⟩, bv_cases_at H₃ a' Ha',
bv_split_at Ha', bv_cases_at Ha'_right b' Hb',
bv_split_at Hb',
erw mem_image_iff,
refine ⟨_,_⟩,
{ rw mem_prod_iff, bv_split_at Hb'_right, bv_split_at Hb'_right_left,
refine ⟨_,_⟩,
{ apply mem_codomain_of_is_function ‹_› ‹_› },
{ apply mem_codomain_of_is_function ‹Γ_2 ≤ pair b' b ∈ᴮ f› ‹_› }},
{ apply bv_use (pair a' b'), refine le_inf _ _,
{ rw mem_mem_rel_iff, exact ⟨‹_›,‹_›,bv_and.right ‹_›⟩ },
{ rw mem_prod.map_self_iff, refine ⟨‹_›,‹_›, ‹_›, ‹_›, _⟩, bv_split_at Hb'_right,
bv_split_at Hb'_right_left, from ⟨‹_›,‹_›⟩, from ‹_› }}}
end
lemma mem_induced_epsilon_rel_of_mem {η x f a b : bSet 𝔹} {Γ} (H_mem₁ : Γ ≤ a ∈ᴮ η) (H_mem₂ : Γ ≤ b ∈ᴮ η) (H_mem : Γ ≤ a ∈ᴮ b) (H_func : Γ ≤ is_function η x f) : Γ ≤ pair (function_eval H_func a H_mem₁) (function_eval H_func b H_mem₂) ∈ᴮ induced_epsilon_rel η x f :=
begin
rw mem_induced_epsilon_rel_iff ‹_›,
refine ⟨_,_,_⟩,
{ apply function_eval_mem_codomain },
{ apply function_eval_mem_codomain },
{ apply bv_use a, refine le_inf ‹_› (bv_use b),
refine le_inf ‹_› (le_inf (le_inf _ _) ‹_›),
{ apply function_eval_pair_mem },
{ apply function_eval_pair_mem }}
end
lemma mem_of_mem_induced_epsilon_rel {η x f a' b' a b : bSet 𝔹} {Γ} (H_inj : Γ ≤ is_injective_function η x f) (H_mem₁ : Γ ≤ pair a' a ∈ᴮ f) (H_mem₂ : Γ ≤ pair b' b ∈ᴮ f) (H_mem : Γ ≤ pair a b ∈ᴮ induced_epsilon_rel η x f) : Γ ≤ a' ∈ᴮ b' :=
begin
rw (mem_induced_epsilon_rel_iff $ bv_and.left ‹_›) at H_mem,
rcases H_mem with ⟨Ha_mem, Hb_mem, H⟩,
bv_cases_at H a'' Ha'', bv_split_at Ha'', bv_cases_at Ha''_right b'' Hb'', simp only [le_inf_iff] at Hb'',
rcases Hb'' with ⟨Hb''₁, ⟨Hb''₂, Hb''₃⟩, Hb''₄⟩,
suffices : Γ_2 ≤ a' =ᴮ a'' ∧ Γ_2 ≤ b' =ᴮ b'',
by {cases this, bv_cc},
have H_inj' := is_inj_of_is_injective_function H_inj,
refine ⟨_,_⟩,
{ refine H_inj' a' a'' a a _, exact le_inf (le_inf ‹_› ‹_›) bv_refl },
{ refine H_inj' b' b'' b b _, exact le_inf (le_inf ‹_› ‹_›) bv_refl }
end
lemma induced_epsilon_rel_sub_image_left { η x f a b : bSet 𝔹 } { Γ } (H_func : Γ ≤ is_function η x f) (H : Γ ≤ pair a b ∈ᴮ induced_epsilon_rel η x f ) : Γ ≤ a ∈ᴮ image η x f :=
begin
rw mem_image_iff, rw mem_induced_epsilon_rel_iff at H,
rcases H with ⟨H₁,H₂,H₃⟩, refine ⟨‹_›, _⟩,
bv_cases_at H₃ a' Ha', bv_split_at Ha', bv_cases_at Ha'_right b' Hb',
bv_split_at Hb', bv_split_at Hb'_right, bv_split_at Hb'_right_left,
apply bv_use a', from le_inf ‹_› ‹_›,
from ‹_›
end
lemma induced_epsilon_rel_sub_image_right { η x f a b : bSet 𝔹 } { Γ } (H_func : Γ ≤ is_function η x f) (H : Γ ≤ pair a b ∈ᴮ induced_epsilon_rel η x f ) : Γ ≤ b ∈ᴮ image η x f :=
begin
rw mem_image_iff, rw mem_induced_epsilon_rel_iff at H,
rcases H with ⟨H₁,H₂,H₃⟩, refine ⟨‹_›, _⟩,
bv_cases_at H₃ a' Ha', bv_split_at Ha', bv_cases_at Ha'_right b' Hb',
bv_split_at Hb', bv_split_at Hb'_right, bv_split_at Hb'_right_left,
apply bv_use b', from le_inf ‹_› ‹_›,
from ‹_›
end
lemma image_eq_of_eq_induced_epsilon_rel_aux
{ η ρ f g : bSet 𝔹 }
{ Γ }
(Hη_inj : Γ ≤ is_injective_function η omega f)
(Hρ_inj : Γ ≤ is_injective_function ρ omega g)
(H_eq : Γ ≤ induced_epsilon_rel η omega f =ᴮ induced_epsilon_rel ρ omega g)
(H_exists_two : Γ ≤ exists_two η) :
Γ ≤ ⨅ (z : bSet 𝔹), z ∈ᴮ image η omega f ⟹ z ∈ᴮ image ρ omega g :=
begin
bv_intro z, bv_imp_intro Hz_mem, rw mem_image_iff at Hz_mem,
cases Hz_mem with Hz_mem₁ Hz_mem₂,
bv_cases_at Hz_mem₂ z' Hz', bv_split_at Hz',
unfold exists_two at H_exists_two,
replace H_exists_two := H_exists_two z' ‹_›,
bv_cases_at H_exists_two w' Hw', bv_split_at Hw',
bv_or_elim_at' Hw'_right,
{ let w := function_eval (bv_and.left Hη_inj) w' ‹_›,
apply induced_epsilon_rel_sub_image_left, show bSet 𝔹, from w, from bv_and.left ‹_›,
apply bv_rw' (bv_symm H_eq), { simp },
rw mem_induced_epsilon_rel_iff,
refine ⟨‹_›, by { apply function_eval_mem_codomain }, _⟩, apply bv_use z',
refine le_inf ‹_› _, apply bv_use w', refine le_inf ‹_› _,
refine le_inf (le_inf ‹_› (by apply function_eval_pair_mem)) ‹_›, from bv_and.left ‹_› },
{ let w := function_eval (bv_and.left Hη_inj) w' ‹_›,
apply induced_epsilon_rel_sub_image_right, show bSet 𝔹, from w, from bv_and.left ‹_›,
apply bv_rw' (bv_symm H_eq), { simp },
rw mem_induced_epsilon_rel_iff,
refine ⟨ by { apply function_eval_mem_codomain }, ‹_›, _⟩, apply bv_use w',
refine le_inf ‹_› _, apply bv_use z', refine le_inf ‹_› _,
refine le_inf (le_inf (by apply function_eval_pair_mem) ‹_›) ‹_›, from bv_and.left ‹_› }
end
lemma image_eq_of_eq_induced_epsilon_rel
{ η ρ f g : bSet 𝔹 }
{ Γ }
(Hη_inj : Γ ≤ is_injective_function η omega f)
(Hρ_inj : Γ ≤ is_injective_function ρ omega g)
(H_eq : Γ ≤ induced_epsilon_rel η omega f =ᴮ induced_epsilon_rel ρ omega g)
(H_exists_two : Γ ≤ exists_two η)
(H_exists_two' : Γ ≤ exists_two ρ) :
Γ ≤ image η omega f =ᴮ image ρ omega g :=
by { refine mem_ext _ _;
apply image_eq_of_eq_induced_epsilon_rel_aux; repeat { assumption }, from bv_symm ‹_› }
lemma eq_of_eq_induced_epsilon_rel
{η ρ f g : bSet 𝔹}
{Γ}
(Hη_ord : Γ ≤ Ord η)
(Hρ_ord : Γ ≤ Ord ρ)
(Hη_inj : Γ ≤ is_injective_function η omega f)
(Hρ_inj : Γ ≤ is_injective_function ρ omega g)
(H_eq : Γ ≤ induced_epsilon_rel η omega f =ᴮ induced_epsilon_rel ρ omega g)
(H_exists_two : Γ ≤ exists_two η)
(H_exists_two' : Γ ≤ exists_two ρ)
: Γ ≤ η =ᴮ ρ :=
begin
suffices : Γ ≤ ⨆ h, eps_iso η ρ h,
by { exact eq_of_Ord_eps_iso Hη_ord Hρ_ord ‹_› },
refine bv_use (injective_function_comp (factor_image_is_injective_function Hη_inj) _),
from ρ, from injective_function_inverse Hρ_inj,
{ apply @bv_rw' _ _ _ _ _ (image_eq_of_eq_induced_epsilon_rel Hη_inj Hρ_inj ‹_› ‹_› ‹_›) (λ z, is_injective_function z ρ (injective_function_inverse Hρ_inj)), simp, from injective_function_inverse_is_injective_function },
refine le_inf (le_inf _ _) _,
{ apply injective_function_comp_is_function },
{ rw strong_eps_hom_iff, intros,
apply_all le_trans H_le, refine ⟨_,_⟩; intro H_mem,
{ erw mem_is_func'_comp_iff at Hpr₁_mem, rcases Hpr₁_mem with ⟨_,_,Hv₁_ex⟩,
erw mem_is_func'_comp_iff at Hpr₂_mem, rcases Hpr₂_mem with ⟨_,_,Hv₂_ex⟩,
bv_cases_at Hv₁_ex v₁ Hv₁, bv_cases_at Hv₂_ex v₂ Hv₂,
have v₁_mem_v₂ : Γ_2 ≤ pair v₁ v₂ ∈ᴮ induced_epsilon_rel η omega f,
by { rw mem_induced_epsilon_rel_iff, refine ⟨_,_,_⟩,
{ refine mem_of_mem_subset _ (bv_and.left Hv₁), apply image_subset },
{ refine mem_of_mem_subset _ (bv_and.left Hv₂), apply image_subset },
{ apply bv_use z₁, refine le_inf ‹_› (bv_use z₂),
refine le_inf ‹_› (le_inf (le_inf _ _) _),
{ bv_split, bv_split, from ‹_› },
{ bv_split, bv_split, from ‹_› },
{ from ‹_› } }, from bv_and.left ‹_› },
have Hpr₁_mem : Γ_2 ≤ pair w₁ v₁ ∈ᴮ g,
by { bv_split_at Hv₁, bv_split_at Hv₁_right, erw mem_inj_inverse_iff at Hv₁_right_right, simp* },
have Hpr₂_mem : Γ_2 ≤ pair w₂ v₂ ∈ᴮ g,
by { bv_split_at Hv₂, bv_split_at Hv₂_right, erw mem_inj_inverse_iff at Hv₂_right_right, simp* },
refine mem_of_mem_induced_epsilon_rel Hρ_inj_1 Hpr₁_mem Hpr₂_mem _,
apply bv_rw' (bv_symm H_eq_1), simp, from ‹_› },
{ erw mem_is_func'_comp_iff at Hpr₁_mem, rcases Hpr₁_mem with ⟨_,_,Hv₁_ex⟩,
erw mem_is_func'_comp_iff at Hpr₂_mem, rcases Hpr₂_mem with ⟨_,_,Hv₂_ex⟩,
bv_cases_at Hv₁_ex v₁ Hv₁, bv_cases_at Hv₂_ex v₂ Hv₂,
have v₁_mem_v₂ : Γ_2 ≤ pair v₁ v₂ ∈ᴮ induced_epsilon_rel ρ omega g,
by { rw mem_induced_epsilon_rel_iff, refine ⟨_,_,_⟩,
{ refine mem_of_mem_subset _ (bv_and.left Hv₁), apply image_subset },
{ refine mem_of_mem_subset _ (bv_and.left Hv₂), apply image_subset },
{ apply bv_use w₁, refine le_inf ‹_› (bv_use w₂),
refine le_inf ‹_› (le_inf (le_inf _ _) _),
{ bv_split_at Hv₁, bv_split_at Hv₁_right, erw mem_inj_inverse_iff at Hv₁_right_right, simp* },
{ bv_split_at Hv₂, bv_split_at Hv₂_right, erw mem_inj_inverse_iff at Hv₂_right_right, simp* },
{ from ‹_› } }, from bv_and.left ‹_› },
have Hpr₁_mem : Γ_2 ≤ pair z₁ v₁ ∈ᴮ f,
by bv_split; bv_split; from ‹_›,
have Hpr₂_mem : Γ_2 ≤ pair z₂ v₂ ∈ᴮ f,
by bv_split; bv_split; from ‹_›,
refine mem_of_mem_induced_epsilon_rel Hη_inj_1 Hpr₁_mem Hpr₂_mem _,
apply bv_rw' H_eq_1, simp, from ‹_› },
},
{apply is_func'_comp_surj,
{ from bv_and.right ‹_› },
{ apply injective_function_inverse_is_inj },
{ exact surj_image (is_func'_of_is_injective_function Hη_inj) },
{ change _ ≤ (λ z, is_surj z ρ (injective_function_inverse Hρ_inj)) _,
apply bv_rw' (image_eq_of_eq_induced_epsilon_rel Hη_inj Hρ_inj ‹_› ‹_› ‹_›), simp, apply inj_inverse.is_surj }}
end
end well_ordering
section a1
parameters {𝔹 : Type u} [nontrivial_complete_boolean_algebra 𝔹]
def a1.ϕ : bSet 𝔹 → 𝔹 := λ x, (⨆η, Ord η ⊓ ⨆ f, is_injective_function η omega f ⊓ (image (mem_rel η) (prod omega omega) (prod.map_self η omega f) =ᴮ x) ⊓ (- (x =ᴮ ∅)) )
@[simp]lemma B_ext_a1.ϕ : B_ext a1.ϕ :=
by simp [a1.ϕ]
def a1' : bSet 𝔹 := comprehend a1.ϕ (bv_powerset $ prod omega omega)
def a1.type := a1'.type
def a1.bval := a1'.bval
def a1.ψ (v : bSet 𝔹) : bSet 𝔹 → 𝔹 := λ x, (Ord x ⊓ ⨆ f, is_injective_function x omega f ⊓ image (mem_rel x) (prod omega omega) (prod.map_self x omega f) =ᴮ v ⊓ (- (v =ᴮ ∅)))
@[simp]lemma B_ext_a1.ψ {v : bSet 𝔹} : B_ext (a1.ψ v) :=
by { unfold a1.ψ, apply B_ext_inf, simp, apply B_ext_supr, intro i,
apply B_ext_inf, swap, simp, apply B_ext_inf, simp, intros x y, tidy_context,
refine bv_symm _, refine bv_trans (bv_symm a_right) _,
have : Γ ≤ mem_rel x =ᴮ mem_rel y,
by { exact B_congr_mem_rel ‹_› },
have := B_congr_image_left this, show bSet 𝔹, from prod omega omega, show bSet 𝔹, from (prod.map_self x omega i),
dsimp at this,
have : Γ ≤ (prod.map_self x omega i) =ᴮ (prod.map_self y omega i),
by { exact B_congr_prod.map_self_left ‹_› },
have := B_congr_image_right this, show bSet 𝔹, from (mem_rel y), show bSet 𝔹, from (prod omega omega),
dsimp at this, bv_cc }
lemma a1'.AE {Γ : 𝔹} : Γ ≤ ⨅ z, z ∈ᴮ a1' ⟹ ⨆ η, Ord η ⊓ ⨆ f, is_injective_function η omega f ⊓ image (mem_rel η) (prod omega omega) (prod.map_self η omega f) =ᴮ z ⊓ (- (z =ᴮ ∅)) :=
begin
bv_intro z, bv_imp_intro Hz_mem, erw mem_comprehend_iff at Hz_mem,
bv_cases_at Hz_mem χ Hχ,
bv_split_at Hχ, bv_split_at Hχ_right, apply bv_rw' Hχ_right_left, simp,
convert Hχ_right_right, from (bv_powerset $ prod omega omega), simp
end
noncomputable def a1.func : a1.type → bSet 𝔹 := λ χ, classical.some (AE_convert' (a1.ψ) (λ z, B_ext_a1.ψ) a1' (a1'.func χ))
lemma a1.func_spec_aux {χ : a1.type} : ∀ {Γ : 𝔹}, (Γ ≤ ⨅ z, z ∈ᴮ a1' ⟹ ⨆ w, a1.ψ z w) → Γ ≤ (a1'.func χ) ∈ᴮ a1' → Γ ≤ a1.ψ (a1'.func χ) (a1.func χ) :=
by {intro Γ, exact classical.some_spec (a1.func._proof_1 χ)}
lemma a1.func_spec {χ : a1.type} : ∀ {Γ : 𝔹}, Γ ≤ (a1'.func χ) ∈ᴮ a1' → Γ ≤ a1.ψ (a1'.func χ) (a1.func χ) :=
by { intros Γ H_mem, apply a1.func_spec_aux, exact a1'.AE, from ‹_› }
-- equality of pushforward epsilon relation is not enough to guarantee 0 or 1 are in a1,
-- since injectivity fails at 0 and 1 (both epsilon relations are empty)
noncomputable def a1_aux : bSet 𝔹 := ⟨a1.type, a1.func, a1.bval⟩
lemma Ord_of_mem_a1_aux {Γ : 𝔹} {η : bSet 𝔹} (H_mem : Γ ≤ η ∈ᴮ a1_aux) : Γ ≤ Ord η :=
begin
rw mem_unfold at H_mem, bv_cases_at H_mem χ Hχ, bv_split_at Hχ,
have : Γ_1 ≤ a1'.func χ ∈ᴮ a1',
by { convert mem.mk'' _, from ‹_› },
have := a1.func_spec this, bv_split_at this,
apply bv_rw' Hχ_right, simp, from ‹_›
end
noncomputable def a1 : bSet 𝔹 := insert 0 (insert 1 a1_aux)
lemma mem_a1_iff₀ { z : bSet 𝔹 } { Γ } : Γ ≤ z ∈ᴮ a1 ↔ Γ ≤ z =ᴮ 0 ⊔ z =ᴮ 1 ⊔ z ∈ᴮ a1_aux :=
by { simp [a1, sup_assoc] }
lemma Ord_of_mem_a1 { Γ : 𝔹 } { η : bSet 𝔹 } (H_mem : Γ ≤ η ∈ᴮ a1) : Γ ≤ Ord η :=
begin
rw mem_a1_iff₀ at H_mem, bv_or_elim_at H_mem,
{ bv_or_elim_at H_mem.left,
{ apply bv_rw' H_mem.left.left, simp, from Ord_zero },
{ apply bv_rw' H_mem.left.right, simp, from Ord_one }},
{ from Ord_of_mem_a1_aux ‹_› }
end
lemma eq_zero_iff_eq_empty {Γ : 𝔹} { u : bSet 𝔹 } : Γ ≤ u =ᴮ 0 ↔ Γ ≤ u =ᴮ ∅ :=
begin
refine ⟨_,_⟩; intro H,
{ apply bv_rw' (bv_symm zero_eq_empty), simp, from ‹_› },
{ apply bv_rw' zero_eq_empty, simp, from ‹_› }
end
lemma induced_rel_empty_of_eq_zero
{η f : bSet 𝔹}
{Γ : 𝔹}
(H_func : Γ ≤ is_function η omega f)
: Γ ≤ η =ᴮ 0 → Γ ≤ induced_epsilon_rel η omega f =ᴮ ∅ :=
begin
intro H_eq_zero, apply bv_by_contra, bv_imp_intro H_contra,
rw nonempty_iff_exists_mem at H_contra,
bv_cases_at H_contra pr Hpr,
rcases (eq_pair_of_mem_induced_epsilon_rel ‹_›) with ⟨a,b,Ha_mem,Hb_mem,H_eq,Hab⟩,
replace Hab := induced_epsilon_rel_sub_image_left ‹_› Hab,
rw mem_image_iff at Hab, cases Hab with _ H_im,
bv_cases_at H_im z Hz, bv_split_at Hz,
rw eq_zero_iff_eq_empty at H_eq_zero, rw empty_iff_forall_not_mem at H_eq_zero,
replace H_eq_zero := H_eq_zero z, exact bv_absurd _ Hz_left ‹_›
end
lemma nonempty_of_induced_rel_nonempty
{η f : bSet 𝔹}
{Γ : 𝔹}
(H_func : Γ ≤ is_function η omega f)
: Γ ≤ -(induced_epsilon_rel η omega f =ᴮ ∅) → Γ ≤ -(η =ᴮ ∅) :=
begin
intro H, rw ←imp_bot, bv_imp_intro H',
rw ← eq_zero_iff_eq_empty at H',
have := induced_rel_empty_of_eq_zero ‹_› ‹_›, bv_contradiction
end
lemma not_zero_of_induced_rel_nonempty
{η f : bSet 𝔹}
{Γ : 𝔹}
(H_func : Γ ≤ is_function η omega f)
: Γ ≤ -(induced_epsilon_rel η omega f =ᴮ ∅) → Γ ≤ -(η =ᴮ 0) :=
begin
intro H', apply @bv_rw' _ _ _ _ _ (zero_eq_empty) (λ w, - (η =ᴮ w)), {simp},
exact nonempty_of_induced_rel_nonempty ‹_› ‹_›
end
lemma not_one_of_induced_rel_nonempty
{η f : bSet 𝔹}
{Γ : 𝔹}
(H_func : Γ ≤ is_function η omega f)
: Γ ≤ -(induced_epsilon_rel η omega f =ᴮ ∅) → Γ ≤ -(η =ᴮ 1) :=
begin
intro H, rw nonempty_iff_exists_mem at H, bv_cases_at H pr Hpr,
rcases eq_pair_of_mem_induced_epsilon_rel Hpr with ⟨a,b,Ha,Hb,H_eq,Hab⟩,
rw mem_induced_epsilon_rel_iff at Hab, rcases Hab with ⟨Ha, Hb, Hab⟩,
bv_cases_at' Hab a' Ha', bv_split_at Ha',
bv_cases_at' Ha'_right b' Hb', bv_split_at Hb', bv_split_at Hb'_right, bv_split_at Hb'_right_left,
rw ←imp_bot, bv_imp_intro' H_eq_one,
suffices : Γ_4 ≤ 0 ∈ᴮ 0,
by { exact bot_of_mem_self' ‹_› },
suffices : Γ_4 ≤ a' =ᴮ 0 ∧ Γ_4 ≤ b' =ᴮ 0,
by { change _ ≤ (λ (w : bSet 𝔹), w ∈ᴮ 0) 0, apply bv_rw' (bv_symm this.left), simp,
change _ ≤ (λ w, a' ∈ᴮ w) _, apply bv_rw' (bv_symm this.right), simpa },
refine ⟨_,_⟩,
{ apply eq_zero_of_mem_one, have := mem_domain_of_is_function ‹Γ_4 ≤ pair a' a ∈ᴮ f› ‹_›, bv_cc },
{ apply eq_zero_of_mem_one, have := mem_domain_of_is_function ‹Γ_4 ≤ pair b' b ∈ᴮ f› ‹_›, bv_cc },
from ‹_›
end
lemma nonempty_induced_rel_iff_not_zero_and_not_one
{η f : bSet 𝔹}
{Γ : 𝔹}
(H_ord : Γ ≤ Ord η)
(H_inj : Γ ≤ is_function η omega f)
: Γ ≤ -((induced_epsilon_rel η omega f) =ᴮ ∅) ↔ (Γ ≤ -(η =ᴮ 0) ∧ Γ ≤ -(η =ᴮ 1)) :=
begin
refine ⟨_,_⟩; intro H,
{ refine ⟨_,_⟩,
{ exact not_zero_of_induced_rel_nonempty ‹_› ‹_› },
{ exact not_one_of_induced_rel_nonempty ‹_› ‹_› }},
{ cases H with H₁ H₂, rw nonempty_iff_exists_mem,
have := one_mem_of_not_zero_and_not_one ‹_› H₁ H₂,
have Hmem_one : Γ ≤ _ := zero_mem_one,
have H_zero_mem : Γ ≤ 0 ∈ᴮ η,
by { exact mem_of_mem_Ord ‹_› ‹_ ≤ 1 ∈ᴮ η› ‹_›},
refine bv_use _,
swap, apply mem_induced_epsilon_rel_of_mem H_zero_mem this ‹_›, from ‹_› }
end
/--
a1 contains every ordinal η which injects into ω
-/
lemma mem_a1_of_injects_into_omega_aux {Γ : 𝔹} {η : bSet 𝔹} (H_ord : Γ ≤ Ord η) (H_inj : Γ ≤ ⨆ f, is_injective_function η omega f) (H_not_zero : Γ ≤ - (η =ᴮ 0)) (H_not_one : Γ ≤ -(η =ᴮ 1)) : Γ ≤ η ∈ᴮ a1_aux :=
begin
bv_cases_at H_inj f Hf,
rw mem_unfold', let R := (induced_epsilon_rel η omega f),
have : Γ_1 ≤ R ∈ᴮ a1',
by { erw mem_comprehend_iff₂, apply bv_use R, refine le_inf _ (le_inf bv_refl _),
{ rw mem_powerset_iff, apply subset.mk_subset },
{ apply bv_use η, refine le_inf ‹_› _, apply bv_use f,
refine le_inf (le_inf ‹_› bv_refl) _,
erw nonempty_induced_rel_iff_not_zero_and_not_one, simp*, from ‹_›, from bv_and.left ‹_› },
simp },
rw mem_unfold at this, bv_cases_at this χ Hχ,
apply bv_use (a1.func χ), bv_split_at Hχ, refine le_inf _ _,
convert mem.mk'' _, refl, from ‹_›,
have H_mem : Γ_2 ≤ (a1'.func χ) ∈ᴮ a1', from mem.mk'' ‹_›,
have := a1.func_spec H_mem,
bv_split_at this,
bv_cases_at this_right g Hg, bv_split_at Hg,
bv_split_at Hg_left,
apply eq_of_eq_induced_epsilon_rel, from ‹_›,
{apply Ord_of_mem_a1_aux, convert mem.mk'' _, refl, from ‹_›},
from Hf, from Hg_left_left,
{ dsimp [R] at Hχ_right,change _ ≤ induced_epsilon_rel _ _ _ =ᴮ _ at Hg_left_right, bv_cc },
{ rw exists_two_iff; from ‹_› },
rw exists_two_iff,
suffices : Γ_3 ≤ -(image (mem_rel (a1.func χ)) (prod omega omega) (prod.map_self (a1.func χ) omega g) =ᴮ ∅),
by { erw nonempty_induced_rel_iff_not_zero_and_not_one at this, cases this with this₁ this₂,
from ‹_›, from ‹_›, from bv_and.left ‹_› },
apply @bv_rw' _ _ _ _ _ Hg_left_right (λ w, -(w =ᴮ ∅)), simp, from ‹_›, from ‹_›
end
lemma mem_a1_iff {Γ : 𝔹} {η : bSet 𝔹} (H_ord : Γ ≤ Ord η) : Γ ≤ η ∈ᴮ a1 ↔ Γ ≤ ⨆f, is_injective_function η omega f :=
begin
refine ⟨_,_⟩,
{ intro H_mem,
rw mem_a1_iff₀ at H_mem,
bv_or_elim_at H_mem, bv_or_elim_at H_mem.left,
{ apply injection_into_of_injects_into, apply injects_into_of_subset,
apply bv_rw' H_mem.left.left, simp, apply of_nat_subset_omega },
{ apply injection_into_of_injects_into, apply injects_into_of_subset,
apply bv_rw' H_mem.left.right, simp, apply of_nat_subset_omega },
{ rw mem_unfold at H_mem.right, bv_cases_at H_mem.right χ Hχ,
bv_split_at Hχ,
have : Γ_2 ≤ a1'.func χ ∈ᴮ a1',
by { from mem.mk'' ‹_› },
have := a1.func_spec this,
apply bv_rw' Hχ_right, simp,
bv_split_at this, bv_cases_at this_right f Hf, apply bv_use f,
exact bv_and.left (bv_and.left ‹_›) }},
{ intro H_ex, rw mem_a1_iff₀, bv_cases_on η =ᴮ 1,
{ exact bv_or_left (bv_or_right ‹_›) },
{ bv_cases_on η =ᴮ 0,
{ exact bv_or_left (bv_or_left ‹_›) },
{ refine bv_or_right _, apply mem_a1_of_injects_into_omega_aux, repeat { assumption }}}}
end
lemma a1_transitive {Γ} : Γ ≤ is_transitive a1 :=
begin
bv_intro z, bv_imp_intro Hz_mem,
rw subset_unfold', bv_intro w, bv_imp_intro Hw_mem,
rw mem_a1_iff _, swap,
{ refine Ord_of_mem_Ord Hw_mem _, from Ord_of_mem_a1 ‹_› },
{ have Hz_ord : Γ_2 ≤ Ord z := Ord_of_mem_a1 ‹_›,
rw (mem_a1_iff ‹_›) at Hz_mem,
cases (exists_convert Hz_mem) with f Hf,
have Hw_sub : Γ_2 ≤ w ⊆ᴮ z,
by {apply subset_of_mem_transitive, from bv_and.right ‹_›, from ‹_› },
have Hw_inj : Γ_2 ≤ injection_into w z := injection_into_of_subset Hw_sub,
cases (exists_convert Hw_inj) with g Hg,
apply bv_use (injective_function_comp Hg Hf), apply injective_function_comp_is_injective_function }
end
lemma a1_ewo {Γ} : Γ ≤ ewo a1 :=
begin
refine le_inf _ _,
{ apply epsilon_trichotomy_of_sub_Ord, bv_intro x, bv_imp_intro H_mem,
from Ord_of_mem_a1 ‹_› },
{ apply epsilon_wf_of_sub_Ord }
end
lemma a1_Ord {Γ : 𝔹} : Γ ≤ Ord a1 := le_inf a1_ewo a1_transitive
lemma a1_not_le_omega {Γ : 𝔹} : Γ ≤ -(a1 ≼ omega) :=
begin
rw ←imp_bot, bv_imp_intro H_contra, rw injects_into_iff_injection_into at H_contra,
erw ←mem_a1_iff (a1_Ord) at H_contra, from bot_of_mem_self' ‹_›
end
lemma a1_spec {Γ : 𝔹} : Γ ≤ aleph_one_Ord_spec a1 :=
begin
refine le_inf (a1_not_le_omega) _,
refine le_inf a1_Ord _,
bv_intro η, bv_imp_intro Ord_η, bv_imp_intro H,
classical,
by_cases ⊥ < Γ_2,
{ rw (Ord.le_iff_lt_or_eq a1_Ord ‹_›),
apply bv_by_contra, bv_imp_intro H_contra,
simp only [le_inf_iff] with bv_push_neg at H_contra,
cases H_contra with H_contra₁ H_contra₂,
suffices : Γ_3 ≤ injects_into η omega,
by exact bv_absurd _ this ‹_›,
suffices : Γ_3 ≤ η ∈ᴮ a1,
by {replace this := (mem_a1_iff ‹_›).mp this, bv_cases_at this f Hf,
apply bv_use f,
from le_inf (is_func'_of_is_injective_function ‹_›) (bv_and.right ‹_›) },
have : Γ_3 ≤ _ := Ord.trichotomy a1_Ord Ord_η,
apply bv_by_contra, bv_imp_intro H_contra₃,
bv_or_elim_at this,
{ bv_or_elim_at this.left,
{ bv_contradiction },
{ bv_contradiction }},
{ bv_contradiction } },
{ have : Γ_2 ≤ ⊥ := le_bot_iff_not_bot_lt.mp h,
from le_trans this bot_le }
end
lemma a1_le_of_omega_lt {Γ : 𝔹} : Γ ≤ le_of_omega_lt a1 :=
begin
bv_intro x, bv_imp_intro H_Ord, bv_imp_intro H_no_surj,
have H_no_inj : Γ_2 ≤ -(injects_into x omega),
by { rw ←imp_bot, bv_imp_intro H_contra,
refine bv_absurd _ _ H_no_surj,
bv_cases_on x =ᴮ ∅,
{ apply bv_use (∅ : bSet 𝔹), apply bv_use (∅ : bSet 𝔹),
refine le_inf _ _,
refine le_inf empty_subset _,
exact is_func'_empty,
apply bv_rw' H.left, simp, apply is_surj_empty },
{ apply larger_than_of_surjects_onto,
refine surjects_onto_of_injects_into ‹_› _, rwa ←nonempty_iff_exists_mem } },
have H_not_mem_a1 : Γ_2 ≤ -(x ∈ᴮ a1),
by { rw ←imp_bot, bv_imp_intro H_contra, rw mem_a1_iff ‹_›at H_contra,
have := injects_into_of_injection_into H_contra, bv_contradiction },
refine injects_into_of_subset _,
rw Ord.le_iff_lt_or_eq (a1_Ord) ‹_›,
have := Ord.trichotomy (a1_Ord) ‹_›,
bv_or_elim_at this, bv_or_elim_at this.left,
{ from bv_or_right ‹_› },
{ from bv_or_left ‹_› },
{ from bv_exfalso (by bv_contradiction) }
end
end a1
section
variables {𝔹 : Type u} [nontrivial_complete_boolean_algebra 𝔹]
lemma injects_into_omega_of_mem_aleph_one_check {Γ : 𝔹} {z : bSet 𝔹} (H_mem : Γ ≤ z ∈ᴮ (ℵ₁)̌ ): Γ ≤ injects_into z bSet.omega :=
begin
rw mem_unfold at H_mem, bv_cases_at H_mem η Hη, simp at Hη,
suffices : Γ_1 ≤ injects_into (ℵ₁̌.func η) bSet.omega,
apply bv_rw' Hη, simp, from ‹_›,
suffices : pSet.injects_into ((ℵ₁).func $ check_cast η) pSet.omega,
by {rw check_func, apply check_injects_into, from ‹_› },
refine pSet.injects_into_omega_of_mem_aleph_one _,
{ simp }
end
lemma mem_aleph_one_of_injects_into_omega {x : bSet 𝔹} {Γ : 𝔹} (H_aleph_one : Γ ≤ aleph_one_Ord_spec x) {z : bSet 𝔹} (H_x_Ord : Γ ≤ Ord x) (H_z_Ord : Γ ≤ Ord z) (H_inj : Γ ≤ injects_into z bSet.omega) : Γ ≤ z ∈ᴮ x :=
begin
apply bv_by_contra, bv_imp_intro H_contra,
have := Ord.resolve_lt H_z_Ord H_x_Ord H_contra,
rw ← Ord.le_iff_lt_or_eq H_x_Ord H_z_Ord at this,
suffices H_inj_omega : Γ_1 ≤ injects_into x omega,
by {refine bv_absurd _ H_inj_omega _, from bv_and.left ‹_› },
exact injects_into_trans (injects_into_of_subset this) (H_inj)
end
lemma aleph_one_check_sub_aleph_one_aux {x : bSet 𝔹} {Γ : 𝔹} (H_ord : Γ ≤ Ord x) (H_aleph_one : Γ ≤ aleph_one_Ord_spec x) : Γ ≤ ℵ₁̌ ⊆ᴮ x :=
begin
rw subset_unfold', bv_intro w, bv_imp_intro H_mem_w,
apply mem_aleph_one_of_injects_into_omega, from ‹_›, from ‹_›,
exact Ord_of_mem_Ord H_mem_w
(check_Ord (by {unfold pSet.aleph_one pSet.card_ex, simp })),
exact injects_into_omega_of_mem_aleph_one_check ‹_›
end
end
end bSet |
f999b73626287ddedb4172e17fd6e2148fb2b7ab | 761d983a78bc025071bac14a3facced881cf5e53 | /affine/affine.lean | afccc7d9b8adae548ad3f8ee7c70a63b3d247453 | [] | no_license | rohanrajnair/affine_lib | bcf22ff892cf74ccb36a95bc9b7fff8e0adb2d0d | 83076864245ac547b9d615bc6a23804b1b4a8f70 | refs/heads/master | 1,673,320,928,343 | 1,603,036,653,000 | 1,603,036,653,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 3,141 | lean | import .add_group_action
import .g_space tactic.ext
import algebra.module linear_algebra.basis
universes u v w
variables (X : Type u) (K : Type v) (V : Type w) (ι : Type*)
[field K] [add_comm_group V] [vector_space K V]
abbreviation affine_space
(X K V : Type*)
[field K] [add_comm_group V] [vector_space K V] := add_torsor V X
variables (s : finset ι) (g : ι → K) (v : ι → V) [is_basis K v] [affine_space X K V]
open_locale big_operators
def affine_combination (g_add : ∑ i in s, g i = 1) := ∑ i in s, g i • v i
def barycenter (g_add : ∑ i in s, g i = 1) := g -- TODO: want to coerce g to be a list?
structure affine_frame :=
(ref_pt : X)
(vec : ι → V)
(basis : is_basis K vec)
section affine_with_frame
@[ext]
structure vec_with_frame (frame : affine_frame X K V ι) :=
(vec : V)
structure pt_with_frame (frame : affine_frame X K V ι) :=
(pt : X)
variables (basis : affine_frame X K V ι) (pt : X)
def vecf_add : vec_with_frame X K V ι basis → vec_with_frame X K V ι basis → vec_with_frame X K V ι basis :=
λ x y, ⟨x.1 + y.1⟩
def vecf_neg : vec_with_frame X K V ι basis → vec_with_frame X K V ι basis :=
λ x, ⟨-x.1⟩
def vecf_scalar : K → vec_with_frame X K V ι basis → vec_with_frame X K V ι basis :=
λ c x, ⟨c • x.1⟩
instance : has_add (vec_with_frame X K V ι basis) := ⟨vecf_add X K V ι basis⟩
instance : has_neg (vec_with_frame X K V ι basis) := ⟨vecf_neg X K V ι basis⟩
instance vec_has_zero : has_zero V := by refine add_monoid.to_has_zero V
def vecf_zero : vec_with_frame X K V ι basis := ⟨(vec_has_zero V).zero⟩
instance : has_zero (vec_with_frame X K V ι basis) := ⟨vecf_zero X K V ι basis⟩
instance : has_scalar K (vec_with_frame X K V ι basis) := ⟨vecf_scalar X K V ι basis⟩
#print add_comm_group
lemma vadd_assoc : ∀ x y z : vec_with_frame X K V ι basis, x + y + z = x + (y + z) :=
begin
intros,
cases x, cases y, cases z,
ext,
exact add_assoc x y z,
end
lemma vzero_add : ∀ x : vec_with_frame X K V ι basis, 0 + x = x :=
begin
intros,
cases x,
ext,
exact zero_add x,
end
lemma vadd_zero : ∀ x : vec_with_frame X K V ι basis, x + 0 = x :=
begin
intros,
cases x,
ext,
exact add_zero x,
end
lemma vadd_left_neg : ∀ x : vec_with_frame X K V ι basis, -x + x = 0 :=
begin
intros,
cases x,
ext,
exact add_left_neg x,
end
lemma vadd_comm : ∀ x y : vec_with_frame X K V ι basis, x + y = y + x :=
begin
intros,
cases x, cases y,
ext,
exact add_comm x y,
end
instance : add_comm_group (vec_with_frame X K V ι basis) :=
⟨
vecf_add X K V ι basis,
vadd_assoc X K V ι basis,
vecf_zero X K V ι basis,
vzero_add X K V ι basis,
vadd_zero X K V ι basis,
vecf_neg X K V ι basis,
vadd_left_neg X K V ι basis,
vadd_comm X K V ι basis
⟩
#print vector_space
#print semimodule
instance : vector_space K (vec_with_frame X K V ι basis) := sorry
instance : affine_space (pt_with_frame X K V ι basis) K (vec_with_frame X K V ι basis) := sorry
end affine_with_frame |
b28fa8cf35cbff0c2074a4f7850122bfc2a1df77 | 57c233acf9386e610d99ed20ef139c5f97504ba3 | /src/analysis/special_functions/integrals.lean | ad17991a59d8296059500e3b3341129b2ff352c9 | [
"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 | 21,406 | lean | /-
Copyright (c) 2021 Benjamin Davidson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Benjamin Davidson
-/
import measure_theory.integral.interval_integral
import analysis.special_functions.trigonometric.arctan_deriv
/-!
# Integration of specific interval integrals
This file contains proofs of the integrals of various specific functions. This includes:
* Integrals of simple functions, such as `id`, `pow`, `inv`, `exp`, `log`
* Integrals of some trigonometric functions, such as `sin`, `cos`, `1 / (1 + x^2)`
* The integral of `cos x ^ 2 - sin x ^ 2`
* Reduction formulae for the integrals of `sin x ^ n` and `cos x ^ n` for `n ≥ 2`
* The computation of `∫ x in 0..π, sin x ^ n` as a product for even and odd `n` (used in proving the
Wallis product for pi)
* Integrals of the form `sin x ^ m * cos x ^ n`
With these lemmas, many simple integrals can be computed by `simp` or `norm_num`.
See `test/integration.lean` for specific examples.
This file also contains some facts about the interval integrability of specific functions.
This file is still being developed.
## Tags
integrate, integration, integrable, integrability
-/
open real nat set finset
open_locale real big_operators interval
variables {a b : ℝ} (n : ℕ)
namespace interval_integral
open measure_theory
variables {f : ℝ → ℝ} {μ ν : measure ℝ} [is_locally_finite_measure μ] (c d : ℝ)
/-! ### Interval integrability -/
@[simp]
lemma interval_integrable_pow : interval_integrable (λ x, x^n) μ a b :=
(continuous_pow n).interval_integrable a b
lemma interval_integrable_zpow {n : ℤ} (h : 0 ≤ n ∨ (0 : ℝ) ∉ [a, b]) :
interval_integrable (λ x, x ^ n) μ a b :=
(continuous_on_id.zpow n $ λ x hx, h.symm.imp (ne_of_mem_of_not_mem hx) id).interval_integrable
lemma interval_integrable_rpow {r : ℝ} (h : 0 ≤ r ∨ (0 : ℝ) ∉ [a, b]) :
interval_integrable (λ x, x ^ r) μ a b :=
(continuous_on_id.rpow_const $ λ x hx, h.symm.imp (ne_of_mem_of_not_mem hx) id).interval_integrable
@[simp]
lemma interval_integrable_id : interval_integrable (λ x, x) μ a b :=
continuous_id.interval_integrable a b
@[simp]
lemma interval_integrable_const : interval_integrable (λ x, c) μ a b :=
continuous_const.interval_integrable a b
@[simp]
lemma interval_integrable.const_mul (h : interval_integrable f ν a b) :
interval_integrable (λ x, c * f x) ν a b :=
by convert h.smul c
@[simp]
lemma interval_integrable.mul_const (h : interval_integrable f ν a b) :
interval_integrable (λ x, f x * c) ν a b :=
by simp only [mul_comm, interval_integrable.const_mul c h]
@[simp]
lemma interval_integrable.div (h : interval_integrable f ν a b) :
interval_integrable (λ x, f x / c) ν a b :=
interval_integrable.mul_const c⁻¹ h
lemma interval_integrable_one_div (h : ∀ x : ℝ, x ∈ [a, b] → f x ≠ 0)
(hf : continuous_on f [a, b]) :
interval_integrable (λ x, 1 / f x) μ a b :=
(continuous_on_const.div hf h).interval_integrable
@[simp]
lemma interval_integrable_inv (h : ∀ x : ℝ, x ∈ [a, b] → f x ≠ 0)
(hf : continuous_on f [a, b]) :
interval_integrable (λ x, (f x)⁻¹) μ a b :=
by simpa only [one_div] using interval_integrable_one_div h hf
@[simp]
lemma interval_integrable_exp : interval_integrable exp μ a b :=
continuous_exp.interval_integrable a b
@[simp]
lemma interval_integrable.log
(hf : continuous_on f [a, b]) (h : ∀ x : ℝ, x ∈ [a, b] → f x ≠ 0) :
interval_integrable (λ x, log (f x)) μ a b :=
(continuous_on.log hf h).interval_integrable
@[simp]
lemma interval_integrable_log (h : (0:ℝ) ∉ [a, b]) :
interval_integrable log μ a b :=
interval_integrable.log continuous_on_id $ λ x hx, ne_of_mem_of_not_mem hx h
@[simp]
lemma interval_integrable_sin : interval_integrable sin μ a b :=
continuous_sin.interval_integrable a b
@[simp]
lemma interval_integrable_cos : interval_integrable cos μ a b :=
continuous_cos.interval_integrable a b
lemma interval_integrable_one_div_one_add_sq : interval_integrable (λ x : ℝ, 1 / (1 + x^2)) μ a b :=
begin
refine (continuous_const.div _ (λ x, _)).interval_integrable a b,
{ continuity },
{ nlinarith },
end
@[simp]
lemma interval_integrable_inv_one_add_sq : interval_integrable (λ x : ℝ, (1 + x^2)⁻¹) μ a b :=
by simpa only [one_div] using interval_integrable_one_div_one_add_sq
/-! ### Integrals of the form `c * ∫ x in a..b, f (c * x + d)` -/
@[simp]
lemma mul_integral_comp_mul_right : c * ∫ x in a..b, f (x * c) = ∫ x in a*c..b*c, f x :=
smul_integral_comp_mul_right f c
@[simp]
lemma mul_integral_comp_mul_left : c * ∫ x in a..b, f (c * x) = ∫ x in c*a..c*b, f x :=
smul_integral_comp_mul_left f c
@[simp]
lemma inv_mul_integral_comp_div : c⁻¹ * ∫ x in a..b, f (x / c) = ∫ x in a/c..b/c, f x :=
inv_smul_integral_comp_div f c
@[simp]
lemma mul_integral_comp_mul_add : c * ∫ x in a..b, f (c * x + d) = ∫ x in c*a+d..c*b+d, f x :=
smul_integral_comp_mul_add f c d
@[simp]
lemma mul_integral_comp_add_mul : c * ∫ x in a..b, f (d + c * x) = ∫ x in d+c*a..d+c*b, f x :=
smul_integral_comp_add_mul f c d
@[simp]
lemma inv_mul_integral_comp_div_add : c⁻¹ * ∫ x in a..b, f (x / c + d) = ∫ x in a/c+d..b/c+d, f x :=
inv_smul_integral_comp_div_add f c d
@[simp]
lemma inv_mul_integral_comp_add_div : c⁻¹ * ∫ x in a..b, f (d + x / c) = ∫ x in d+a/c..d+b/c, f x :=
inv_smul_integral_comp_add_div f c d
@[simp]
lemma mul_integral_comp_mul_sub : c * ∫ x in a..b, f (c * x - d) = ∫ x in c*a-d..c*b-d, f x :=
smul_integral_comp_mul_sub f c d
@[simp]
lemma mul_integral_comp_sub_mul : c * ∫ x in a..b, f (d - c * x) = ∫ x in d-c*b..d-c*a, f x :=
smul_integral_comp_sub_mul f c d
@[simp]
lemma inv_mul_integral_comp_div_sub : c⁻¹ * ∫ x in a..b, f (x / c - d) = ∫ x in a/c-d..b/c-d, f x :=
inv_smul_integral_comp_div_sub f c d
@[simp]
lemma inv_mul_integral_comp_sub_div : c⁻¹ * ∫ x in a..b, f (d - x / c) = ∫ x in d-b/c..d-a/c, f x :=
inv_smul_integral_comp_sub_div f c d
end interval_integral
open interval_integral
/-! ### Integrals of simple functions -/
lemma integral_rpow {r : ℝ} (h : 0 ≤ r ∨ r ≠ -1 ∧ (0 : ℝ) ∉ [a, b]) :
∫ x in a..b, x ^ r = (b ^ (r + 1) - a ^ (r + 1)) / (r + 1) :=
begin
suffices : ∀ x ∈ [a, b], has_deriv_at (λ x : ℝ, x ^ (r + 1) / (r + 1)) (x ^ r) x,
{ rw sub_div,
exact integral_eq_sub_of_has_deriv_at this (interval_integrable_rpow (h.imp_right and.right)) },
intros x hx,
have hx' : x ≠ 0 ∨ 1 ≤ r + 1,
from h.symm.imp (λ h, ne_of_mem_of_not_mem hx h.2) (le_add_iff_nonneg_left _).2,
convert (real.has_deriv_at_rpow_const hx').div_const (r + 1),
rw [add_sub_cancel, mul_div_cancel_left],
rw [ne.def, ← eq_neg_iff_add_eq_zero],
rintro rfl,
apply (@zero_lt_one ℝ _ _).not_le,
simpa using h
end
lemma integral_zpow {n : ℤ} (h : 0 ≤ n ∨ n ≠ -1 ∧ (0 : ℝ) ∉ [a, b]) :
∫ x in a..b, x ^ n = (b ^ (n + 1) - a ^ (n + 1)) / (n + 1) :=
begin
replace h : 0 ≤ (n : ℝ) ∨ (n : ℝ) ≠ -1 ∧ (0 : ℝ) ∉ [a, b], by exact_mod_cast h,
exact_mod_cast integral_rpow h
end
@[simp] lemma integral_pow : ∫ x in a..b, x ^ n = (b ^ (n + 1) - a ^ (n + 1)) / (n + 1) :=
by simpa using integral_zpow (or.inl (int.coe_nat_nonneg n))
/-- Integral of `|x - a| ^ n` over `Ι a b`. This integral appears in the proof of the
Picard-Lindelöf/Cauchy-Lipschitz theorem. -/
lemma integral_pow_abs_sub_interval_oc :
∫ x in Ι a b, |x - a| ^ n = |b - a| ^ (n + 1) / (n + 1) :=
begin
cases le_or_lt a b with hab hab,
{ calc ∫ x in Ι a b, |x - a| ^ n = ∫ x in a..b, |x - a| ^ n :
by rw [interval_oc_of_le hab, ← integral_of_le hab]
... = ∫ x in 0..(b - a), x ^ n :
begin
simp only [integral_comp_sub_right (λ x, |x| ^ n), sub_self],
refine integral_congr (λ x hx, congr_arg2 has_pow.pow (abs_of_nonneg $ _) rfl),
rw interval_of_le (sub_nonneg.2 hab) at hx,
exact hx.1
end
... = |b - a| ^ (n + 1) / (n + 1) : by simp [abs_of_nonneg (sub_nonneg.2 hab)] },
{ calc ∫ x in Ι a b, |x - a| ^ n = ∫ x in b..a, |x - a| ^ n :
by rw [interval_oc_of_lt hab, ← integral_of_le hab.le]
... = ∫ x in b - a..0, (-x) ^ n :
begin
simp only [integral_comp_sub_right (λ x, |x| ^ n), sub_self],
refine integral_congr (λ x hx, congr_arg2 has_pow.pow (abs_of_nonpos $ _) rfl),
rw interval_of_le (sub_nonpos.2 hab.le) at hx,
exact hx.2
end
... = |b - a| ^ (n + 1) / (n + 1) :
by simp [integral_comp_neg (λ x, x ^ n), abs_of_neg (sub_neg.2 hab)] }
end
@[simp]
lemma integral_id : ∫ x in a..b, x = (b ^ 2 - a ^ 2) / 2 :=
by simpa using integral_pow 1
@[simp]
lemma integral_one : ∫ x in a..b, (1 : ℝ) = b - a :=
by simp only [mul_one, smul_eq_mul, integral_const]
@[simp]
lemma integral_inv (h : (0:ℝ) ∉ [a, b]) : ∫ x in a..b, x⁻¹ = log (b / a) :=
begin
have h' := λ x hx, ne_of_mem_of_not_mem hx h,
rw [integral_deriv_eq_sub' _ deriv_log' (λ x hx, differentiable_at_log (h' x hx))
(continuous_on_inv₀.mono $ subset_compl_singleton_iff.mpr h),
log_div (h' b right_mem_interval) (h' a left_mem_interval)],
end
@[simp]
lemma integral_inv_of_pos (ha : 0 < a) (hb : 0 < b) : ∫ x in a..b, x⁻¹ = log (b / a) :=
integral_inv $ not_mem_interval_of_lt ha hb
@[simp]
lemma integral_inv_of_neg (ha : a < 0) (hb : b < 0) : ∫ x in a..b, x⁻¹ = log (b / a) :=
integral_inv $ not_mem_interval_of_gt ha hb
lemma integral_one_div (h : (0:ℝ) ∉ [a, b]) : ∫ x : ℝ in a..b, 1/x = log (b / a) :=
by simp only [one_div, integral_inv h]
lemma integral_one_div_of_pos (ha : 0 < a) (hb : 0 < b) : ∫ x : ℝ in a..b, 1/x = log (b / a) :=
by simp only [one_div, integral_inv_of_pos ha hb]
lemma integral_one_div_of_neg (ha : a < 0) (hb : b < 0) : ∫ x : ℝ in a..b, 1/x = log (b / a) :=
by simp only [one_div, integral_inv_of_neg ha hb]
@[simp]
lemma integral_exp : ∫ x in a..b, exp x = exp b - exp a :=
by rw integral_deriv_eq_sub'; norm_num [continuous_on_exp]
@[simp]
lemma integral_log (h : (0:ℝ) ∉ [a, b]) :
∫ x in a..b, log x = b * log b - a * log a - b + a :=
begin
obtain ⟨h', heq⟩ := ⟨λ x hx, ne_of_mem_of_not_mem hx h, λ x hx, mul_inv_cancel (h' x hx)⟩,
convert integral_mul_deriv_eq_deriv_mul (λ x hx, has_deriv_at_log (h' x hx))
(λ x hx, has_deriv_at_id x)
(continuous_on_inv₀.mono $ subset_compl_singleton_iff.mpr h).interval_integrable
continuous_on_const.interval_integrable using 1;
simp [integral_congr heq, mul_comm, ← sub_add],
end
@[simp]
lemma integral_log_of_pos (ha : 0 < a) (hb : 0 < b) :
∫ x in a..b, log x = b * log b - a * log a - b + a :=
integral_log $ not_mem_interval_of_lt ha hb
@[simp]
lemma integral_log_of_neg (ha : a < 0) (hb : b < 0) :
∫ x in a..b, log x = b * log b - a * log a - b + a :=
integral_log $ not_mem_interval_of_gt ha hb
@[simp]
lemma integral_sin : ∫ x in a..b, sin x = cos a - cos b :=
by rw integral_deriv_eq_sub' (λ x, -cos x); norm_num [continuous_on_sin]
@[simp]
lemma integral_cos : ∫ x in a..b, cos x = sin b - sin a :=
by rw integral_deriv_eq_sub'; norm_num [continuous_on_cos]
lemma integral_cos_sq_sub_sin_sq :
∫ x in a..b, cos x ^ 2 - sin x ^ 2 = sin b * cos b - sin a * cos a :=
by simpa only [sq, sub_eq_add_neg, neg_mul_eq_mul_neg] using integral_deriv_mul_eq_sub
(λ x hx, has_deriv_at_sin x) (λ x hx, has_deriv_at_cos x) continuous_on_cos.interval_integrable
continuous_on_sin.neg.interval_integrable
@[simp]
lemma integral_inv_one_add_sq : ∫ x : ℝ in a..b, (1 + x^2)⁻¹ = arctan b - arctan a :=
begin
simp only [← one_div],
refine integral_deriv_eq_sub' _ _ _ (continuous_const.div _ (λ x, _)).continuous_on,
{ norm_num },
{ norm_num },
{ continuity },
{ nlinarith },
end
lemma integral_one_div_one_add_sq : ∫ x : ℝ in a..b, 1 / (1 + x^2) = arctan b - arctan a :=
by simp only [one_div, integral_inv_one_add_sq]
/-! ### Integral of `sin x ^ n` -/
lemma integral_sin_pow_aux :
∫ x in a..b, sin x ^ (n + 2) = sin a ^ (n + 1) * cos a - sin b ^ (n + 1) * cos b
+ (n + 1) * (∫ x in a..b, sin x ^ n) - (n + 1) * ∫ x in a..b, sin x ^ (n + 2) :=
begin
let C := sin a ^ (n + 1) * cos a - sin b ^ (n + 1) * cos b,
have h : ∀ α β γ : ℝ, α * (β * α * γ) = β * (α * α * γ) := λ α β γ, by ring,
have hu : ∀ x ∈ _, has_deriv_at (λ y, sin y ^ (n + 1)) ((n + 1) * cos x * sin x ^ n) x :=
λ x hx, by simpa only [mul_right_comm] using (has_deriv_at_sin x).pow,
have hv : ∀ x ∈ [a, b], has_deriv_at (-cos) (sin x) x :=
λ x hx, by simpa only [neg_neg] using (has_deriv_at_cos x).neg,
have H := integral_mul_deriv_eq_deriv_mul hu hv _ _,
calc ∫ x in a..b, sin x ^ (n + 2)
= ∫ x in a..b, sin x ^ (n + 1) * sin x : by simp only [pow_succ']
... = C + (n + 1) * ∫ x in a..b, cos x ^ 2 * sin x ^ n : by simp [H, h, sq]
... = C + (n + 1) * ∫ x in a..b, sin x ^ n - sin x ^ (n + 2) : by simp [cos_sq', sub_mul,
← pow_add, add_comm]
... = C + (n + 1) * (∫ x in a..b, sin x ^ n) - (n + 1) * ∫ x in a..b, sin x ^ (n + 2) :
by rw [integral_sub, mul_sub, add_sub_assoc]; apply continuous.interval_integrable; continuity,
all_goals { apply continuous.interval_integrable, continuity },
end
/-- The reduction formula for the integral of `sin x ^ n` for any natural `n ≥ 2`. -/
lemma integral_sin_pow :
∫ x in a..b, sin x ^ (n + 2) = (sin a ^ (n + 1) * cos a - sin b ^ (n + 1) * cos b) / (n + 2)
+ (n + 1) / (n + 2) * ∫ x in a..b, sin x ^ n :=
begin
have : (n : ℝ) + 2 ≠ 0 := by exact_mod_cast succ_ne_zero n.succ,
field_simp,
convert eq_sub_iff_add_eq.mp (integral_sin_pow_aux n),
ring,
end
@[simp]
lemma integral_sin_sq : ∫ x in a..b, sin x ^ 2 = (sin a * cos a - sin b * cos b + b - a) / 2 :=
by field_simp [integral_sin_pow, add_sub_assoc]
theorem integral_sin_pow_odd :
∫ x in 0..π, sin x ^ (2 * n + 1) = 2 * ∏ i in range n, (2 * i + 2) / (2 * i + 3) :=
begin
induction n with k ih, { norm_num },
rw [prod_range_succ_comm, mul_left_comm, ← ih, mul_succ, integral_sin_pow],
norm_cast,
simp [-cast_add] with field_simps,
end
theorem integral_sin_pow_even :
∫ x in 0..π, sin x ^ (2 * n) = π * ∏ i in range n, (2 * i + 1) / (2 * i + 2) :=
begin
induction n with k ih, { simp },
rw [prod_range_succ_comm, mul_left_comm, ← ih, mul_succ, integral_sin_pow],
norm_cast,
simp [-cast_add] with field_simps,
end
lemma integral_sin_pow_pos : 0 < ∫ x in 0..π, sin x ^ n :=
begin
rcases even_or_odd' n with ⟨k, (rfl | rfl)⟩;
simp only [integral_sin_pow_even, integral_sin_pow_odd];
refine mul_pos (by norm_num [pi_pos]) (prod_pos (λ n hn, div_pos _ _));
norm_cast;
linarith,
end
lemma integral_sin_pow_succ_le : ∫ x in 0..π, sin x ^ (n + 1) ≤ ∫ x in 0..π, sin x ^ n :=
let H := λ x h, pow_le_pow_of_le_one (sin_nonneg_of_mem_Icc h) (sin_le_one x) (n.le_add_right 1) in
by refine integral_mono_on pi_pos.le _ _ H; exact (continuous_sin.pow _).interval_integrable 0 π
lemma integral_sin_pow_antitone : antitone (λ n : ℕ, ∫ x in 0..π, sin x ^ n) :=
antitone_nat_of_succ_le integral_sin_pow_succ_le
/-! ### Integral of `cos x ^ n` -/
lemma integral_cos_pow_aux :
∫ x in a..b, cos x ^ (n + 2) = cos b ^ (n + 1) * sin b - cos a ^ (n + 1) * sin a
+ (n + 1) * (∫ x in a..b, cos x ^ n) - (n + 1) * ∫ x in a..b, cos x ^ (n + 2) :=
begin
let C := cos b ^ (n + 1) * sin b - cos a ^ (n + 1) * sin a,
have h : ∀ α β γ : ℝ, α * (β * α * γ) = β * (α * α * γ) := λ α β γ, by ring,
have hu : ∀ x ∈ _, has_deriv_at (λ y, cos y ^ (n + 1)) (-(n + 1) * sin x * cos x ^ n) x :=
λ x hx, by simpa only [mul_right_comm, neg_mul_eq_neg_mul_symm, mul_neg_eq_neg_mul_symm]
using (has_deriv_at_cos x).pow,
have hv : ∀ x ∈ [a, b], has_deriv_at sin (cos x) x := λ x hx, has_deriv_at_sin x,
have H := integral_mul_deriv_eq_deriv_mul hu hv _ _,
calc ∫ x in a..b, cos x ^ (n + 2)
= ∫ x in a..b, cos x ^ (n + 1) * cos x : by simp only [pow_succ']
... = C + (n + 1) * ∫ x in a..b, sin x ^ 2 * cos x ^ n : by simp [H, h, sq, -neg_add_rev]
... = C + (n + 1) * ∫ x in a..b, cos x ^ n - cos x ^ (n + 2) : by simp [sin_sq, sub_mul,
← pow_add, add_comm]
... = C + (n + 1) * (∫ x in a..b, cos x ^ n) - (n + 1) * ∫ x in a..b, cos x ^ (n + 2) :
by rw [integral_sub, mul_sub, add_sub_assoc]; apply continuous.interval_integrable; continuity,
all_goals { apply continuous.interval_integrable, continuity },
end
/-- The reduction formula for the integral of `cos x ^ n` for any natural `n ≥ 2`. -/
lemma integral_cos_pow :
∫ x in a..b, cos x ^ (n + 2) = (cos b ^ (n + 1) * sin b - cos a ^ (n + 1) * sin a) / (n + 2)
+ (n + 1) / (n + 2) * ∫ x in a..b, cos x ^ n :=
begin
have : (n : ℝ) + 2 ≠ 0 := by exact_mod_cast succ_ne_zero n.succ,
field_simp,
convert eq_sub_iff_add_eq.mp (integral_cos_pow_aux n),
ring,
end
@[simp]
lemma integral_cos_sq : ∫ x in a..b, cos x ^ 2 = (cos b * sin b - cos a * sin a + b - a) / 2 :=
by field_simp [integral_cos_pow, add_sub_assoc]
/-! ### Integral of `sin x ^ m * cos x ^ n` -/
/-- Simplification of the integral of `sin x ^ m * cos x ^ n`, case `n` is odd. -/
lemma integral_sin_pow_mul_cos_pow_odd (m n : ℕ) :
∫ x in a..b, sin x ^ m * cos x ^ (2 * n + 1) = ∫ u in sin a..sin b, u ^ m * (1 - u ^ 2) ^ n :=
have hc : continuous (λ u : ℝ, u ^ m * (1 - u ^ 2) ^ n), by continuity,
calc ∫ x in a..b, sin x ^ m * cos x ^ (2 * n + 1)
= ∫ x in a..b, sin x ^ m * (1 - sin x ^ 2) ^ n * cos x : by simp only [pow_succ', ← mul_assoc,
pow_mul, cos_sq']
... = ∫ u in sin a..sin b, u ^ m * (1 - u ^ 2) ^ n : integral_comp_mul_deriv
(λ x hx, has_deriv_at_sin x)
continuous_on_cos hc
/-- The integral of `sin x * cos x`, given in terms of sin².
See `integral_sin_mul_cos₂` below for the integral given in terms of cos². -/
@[simp]
lemma integral_sin_mul_cos₁ :
∫ x in a..b, sin x * cos x = (sin b ^ 2 - sin a ^ 2) / 2 :=
by simpa using integral_sin_pow_mul_cos_pow_odd 1 0
@[simp]
lemma integral_sin_sq_mul_cos :
∫ x in a..b, sin x ^ 2 * cos x = (sin b ^ 3 - sin a ^ 3) / 3 :=
by simpa using integral_sin_pow_mul_cos_pow_odd 2 0
@[simp]
lemma integral_cos_pow_three :
∫ x in a..b, cos x ^ 3 = sin b - sin a - (sin b ^ 3 - sin a ^ 3) / 3 :=
by simpa using integral_sin_pow_mul_cos_pow_odd 0 1
/-- Simplification of the integral of `sin x ^ m * cos x ^ n`, case `m` is odd. -/
lemma integral_sin_pow_odd_mul_cos_pow (m n : ℕ) :
∫ x in a..b, sin x ^ (2 * m + 1) * cos x ^ n = ∫ u in cos b..cos a, u ^ n * (1 - u ^ 2) ^ m :=
have hc : continuous (λ u : ℝ, u ^ n * (1 - u ^ 2) ^ m), by continuity,
calc ∫ x in a..b, sin x ^ (2 * m + 1) * cos x ^ n
= -∫ x in b..a, sin x ^ (2 * m + 1) * cos x ^ n : by rw integral_symm
... = ∫ x in b..a, (1 - cos x ^ 2) ^ m * -sin x * cos x ^ n : by simp [pow_succ', pow_mul, sin_sq]
... = ∫ x in b..a, cos x ^ n * (1 - cos x ^ 2) ^ m * -sin x : by { congr, ext, ring }
... = ∫ u in cos b..cos a, u ^ n * (1 - u ^ 2) ^ m : integral_comp_mul_deriv
(λ x hx, has_deriv_at_cos x)
continuous_on_sin.neg hc
/-- The integral of `sin x * cos x`, given in terms of cos².
See `integral_sin_mul_cos₁` above for the integral given in terms of sin². -/
lemma integral_sin_mul_cos₂ :
∫ x in a..b, sin x * cos x = (cos a ^ 2 - cos b ^ 2) / 2 :=
by simpa using integral_sin_pow_odd_mul_cos_pow 0 1
@[simp]
lemma integral_sin_mul_cos_sq :
∫ x in a..b, sin x * cos x ^ 2 = (cos a ^ 3 - cos b ^ 3) / 3 :=
by simpa using integral_sin_pow_odd_mul_cos_pow 0 2
@[simp]
lemma integral_sin_pow_three :
∫ x in a..b, sin x ^ 3 = cos a - cos b - (cos a ^ 3 - cos b ^ 3) / 3 :=
by simpa using integral_sin_pow_odd_mul_cos_pow 1 0
/-- Simplification of the integral of `sin x ^ m * cos x ^ n`, case `m` and `n` are both even. -/
lemma integral_sin_pow_even_mul_cos_pow_even (m n : ℕ) :
∫ x in a..b, sin x ^ (2 * m) * cos x ^ (2 * n)
= ∫ x in a..b, ((1 - cos (2 * x)) / 2) ^ m * ((1 + cos (2 * x)) / 2) ^ n :=
by field_simp [pow_mul, sin_sq, cos_sq, ← sub_sub, (by ring : (2:ℝ) - 1 = 1)]
@[simp]
lemma integral_sin_sq_mul_cos_sq :
∫ x in a..b, sin x ^ 2 * cos x ^ 2 = (b - a) / 8 - (sin (4 * b) - sin (4 * a)) / 32 :=
begin
convert integral_sin_pow_even_mul_cos_pow_even 1 1 using 1,
have h1 : ∀ c : ℝ, (1 - c) / 2 * ((1 + c) / 2) = (1 - c ^ 2) / 4 := λ c, by ring,
have h2 : continuous (λ x, cos (2 * x) ^ 2) := by continuity,
have h3 : ∀ x, cos x * sin x = sin (2 * x) / 2, { intro, rw sin_two_mul, ring },
have h4 : ∀ d : ℝ, 2 * (2 * d) = 4 * d := λ d, by ring,
simp [h1, h2.interval_integrable, integral_comp_mul_left (λ x, cos x ^ 2), h3, h4],
ring,
end
|
ad0cfbb8d4b16e87ab4b529f60c0e3a17cd08082 | a721fe7446524f18ba361625fc01033d9c8b7a78 | /elaborate/concat_empty_nat.stripped.lean | 1d0db47081b8737f5108e115675b85b46ae96c79 | [] | no_license | Sterrs/leaning | 8fd80d1f0a6117a220bb2e57ece639b9a63deadc | 3901cc953694b33adda86cb88ca30ba99594db31 | refs/heads/master | 1,627,023,822,744 | 1,616,515,221,000 | 1,616,515,221,000 | 245,512,190 | 2 | 0 | null | 1,616,429,050,000 | 1,583,527,118,000 | Lean | UTF-8 | Lean | false | false | 1,407 | lean | λ {lst : mylist mynat}, mylist.rec (eq.rec true.intro (eq.rec (eq.refl (empty = empty)) (eq.rec (eq.refl (empty = empty)) (propext {mp := λ (hl : empty = empty), true.intro, mpr := λ (hr : true), eq.refl empty})))) (λ (lst_head : mynat) (lst_tail : mylist mynat) (lst_ih : lst_tail ++ empty = lst_tail), eq.rec true.intro (eq.rec (eq.refl (lst_head :: (lst_tail ++ empty) = lst_head :: lst_tail)) (eq.rec (eq.rec (eq.rec (eq.rec (eq.refl (lst_head :: (lst_tail ++ empty) = lst_head :: lst_tail)) (eq.rec (eq.refl (eq (lst_head :: (lst_tail ++ empty)))) (eq.rec (eq.refl (lst_head :: (lst_tail ++ empty))) (eq.rec (eq.refl (lst_head :: (lst_tail ++ empty))) lst_ih)))) (propext {mp := λ (h : lst_head :: lst_tail = lst_head :: lst_tail), ⟨eq.refl lst_head, eq.refl lst_tail⟩, mpr := λ (a : lst_head = lst_head ∧ lst_tail = lst_tail), and.rec (λ (left : lst_head = lst_head) (right : lst_tail = lst_tail) («_» : lst_head = lst_head ∧ lst_tail = lst_tail), eq.refl (lst_head :: lst_tail)) a a})) (eq.rec (eq.rec (eq.refl (lst_head = lst_head ∧ lst_tail = lst_tail)) (propext {mp := λ (hl : lst_tail = lst_tail), true.intro, mpr := λ (hr : true), eq.refl lst_tail})) (eq.rec (eq.refl (and (lst_head = lst_head))) (propext {mp := λ (hl : lst_head = lst_head), true.intro, mpr := λ (hr : true), eq.refl lst_head})))) (propext {mp := and.left true, mpr := λ (h : true), ⟨h, h⟩})))) lst
|
0e76e44e5e4670bae87226d37e7c71eb85fe7619 | e38d5e91d30731bef617cc9b6de7f79c34cdce9a | /src/core/kan/basic.lean | b2e614f6d2963a9a967c079a5aa50083c6afc424 | [
"Apache-2.0"
] | permissive | bbentzen/cubicalean | 55e979c303fbf55a81ac46b1000c944b2498be7a | 3b94cd2aefdfc2163c263bd3fc6f2086fef814b5 | refs/heads/master | 1,588,314,875,258 | 1,554,412,699,000 | 1,554,412,699,000 | 177,333,390 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 1,039 | lean | /-
Copyright (c) 2019 Bruno Bentzen. All rights reserved.
Released under the Apache License 2.0 (see "License");
Author: Bruno Bentzen
-/
import ..interval
universe variable u
-- n-terms of a homogeneous type as iterated function types indexed by I
@[simp] def term (A : Type) : Π (n : ℕ), Type
| 0 := A
| (n+1) := I → term n
open interval
-- k-face map of a n-term
@[reducible] def term.face (dim : I) {A : Type} : Π (m n), m ≤ n → term A (n+1) → term A n
| 0 n h A := A dim
| 1 n h A := begin rw ←nat.sub_add_cancel h at A |-, exact λ i, A i dim end
| (m+2) n h A := begin rw ←nat.sub_add_cancel h at A |-,
exact (λ j i, term.face m (_ + m) (nat.le_add_left _ _) (A j i))
end
variables {A : Type} {a : term A 3}
#check a i0 -- face 0
#check λ i, a i i0 -- face 1
#check λ j i, a i j i0 -- face 2
-- examples
#reduce term.face i0 1 2 (nat.le_succ 1) a
#reduce term.face i0 2 2 (nat.less_than_or_equal.refl 2) a |
b8593858f1e038ba2863489a6172dca3815e03e3 | 9dc8cecdf3c4634764a18254e94d43da07142918 | /src/algebra/polynomial/group_ring_action.lean | cd41f9587ba6ef29d5012976b52f7f92bd659401 | [
"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,916 | 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.group_ring_action
import algebra.hom.group_action
import data.polynomial.algebra_map
import data.polynomial.monic
import group_theory.group_action.quotient
/-!
# Group action on rings applied to polynomials
This file contains instances and definitions relating `mul_semiring_action` to `polynomial`.
-/
variables (M : Type*) [monoid M]
open_locale polynomial
namespace polynomial
variables (R : Type*) [semiring R]
variables {M}
lemma smul_eq_map [mul_semiring_action M R] (m : M) :
((•) m) = map (mul_semiring_action.to_ring_hom M R m) :=
begin
suffices :
distrib_mul_action.to_add_monoid_hom R[X] m =
(map_ring_hom (mul_semiring_action.to_ring_hom M R m)).to_add_monoid_hom,
{ ext1 r, exact add_monoid_hom.congr_fun this r, },
ext n r : 2,
change m • monomial n r = map (mul_semiring_action.to_ring_hom M R m) (monomial n r),
simpa only [polynomial.map_monomial, polynomial.smul_monomial],
end
variables (M)
noncomputable instance [mul_semiring_action M R] : mul_semiring_action M R[X] :=
{ smul := (•),
smul_one := λ m,
(smul_eq_map R m).symm ▸ polynomial.map_one (mul_semiring_action.to_ring_hom M R m),
smul_mul := λ m p q,
(smul_eq_map R m).symm ▸ polynomial.map_mul (mul_semiring_action.to_ring_hom M R m),
..polynomial.distrib_mul_action }
variables {M R}
variables [mul_semiring_action M R]
@[simp] lemma smul_X (m : M) : (m • X : R[X]) = X :=
(smul_eq_map R m).symm ▸ map_X _
variables (S : Type*) [comm_semiring S] [mul_semiring_action M S]
theorem smul_eval_smul (m : M) (f : S[X]) (x : S) :
(m • f).eval (m • x) = m • f.eval x :=
polynomial.induction_on f
(λ r, by rw [smul_C, eval_C, eval_C])
(λ f g ihf ihg, by rw [smul_add, eval_add, ihf, ihg, eval_add, smul_add])
(λ n r ih, by rw [smul_mul', smul_pow', smul_C, smul_X, eval_mul, eval_C, eval_pow, eval_X,
eval_mul, eval_C, eval_pow, eval_X, smul_mul', smul_pow'])
variables (G : Type*) [group G]
theorem eval_smul' [mul_semiring_action G S] (g : G) (f : S[X]) (x : S) :
f.eval (g • x) = g • (g⁻¹ • f).eval x :=
by rw [← smul_eval_smul, smul_inv_smul]
theorem smul_eval [mul_semiring_action G S] (g : G) (f : S[X]) (x : S) :
(g • f).eval x = g • f.eval (g⁻¹ • x) :=
by rw [← smul_eval_smul, smul_inv_smul]
end polynomial
section comm_ring
variables (G : Type*) [group G] [fintype G]
variables (R : Type*) [comm_ring R] [mul_semiring_action G R]
open mul_action
open_locale classical
/-- the product of `(X - g • x)` over distinct `g • x`. -/
noncomputable def prod_X_sub_smul (x : R) : R[X] :=
(finset.univ : finset (G ⧸ mul_action.stabilizer G x)).prod $
λ g, polynomial.X - polynomial.C (of_quotient_stabilizer G x g)
theorem prod_X_sub_smul.monic (x : R) : (prod_X_sub_smul G R x).monic :=
polynomial.monic_prod_of_monic _ _ $ λ g _, polynomial.monic_X_sub_C _
theorem prod_X_sub_smul.eval (x : R) : (prod_X_sub_smul G R x).eval x = 0 :=
(monoid_hom.map_prod
((polynomial.aeval x).to_ring_hom.to_monoid_hom : R[X] →* R) _ _).trans $
finset.prod_eq_zero (finset.mem_univ $ quotient_group.mk 1) $
by simp
theorem prod_X_sub_smul.smul (x : R) (g : G) :
g • prod_X_sub_smul G R x = prod_X_sub_smul G R x :=
finset.smul_prod.trans $ fintype.prod_bijective _ (mul_action.bijective g) _ _
(λ g', by rw [of_quotient_stabilizer_smul, smul_sub, polynomial.smul_X, polynomial.smul_C])
theorem prod_X_sub_smul.coeff (x : R) (g : G) (n : ℕ) :
g • (prod_X_sub_smul G R x).coeff n =
(prod_X_sub_smul G R x).coeff n :=
by rw [← polynomial.coeff_smul, prod_X_sub_smul.smul]
end comm_ring
namespace mul_semiring_action_hom
variables {M}
variables {P : Type*} [comm_semiring P] [mul_semiring_action M P]
variables {Q : Type*} [comm_semiring Q] [mul_semiring_action M Q]
open polynomial
/-- An equivariant map induces an equivariant map on polynomials. -/
protected noncomputable def polynomial (g : P →+*[M] Q) : P[X] →+*[M] Q[X] :=
{ to_fun := map g,
map_smul' := λ m p, polynomial.induction_on p
(λ b, by rw [smul_C, map_C, coe_fn_coe, g.map_smul, map_C, coe_fn_coe, smul_C])
(λ p q ihp ihq, by rw [smul_add, polynomial.map_add, ihp, ihq, polynomial.map_add, smul_add])
(λ n b ih, by rw [smul_mul', smul_C, smul_pow', smul_X, polynomial.map_mul, map_C,
polynomial.map_pow, map_X, coe_fn_coe, g.map_smul, polynomial.map_mul, map_C,
polynomial.map_pow, map_X, smul_mul', smul_C, smul_pow', smul_X, coe_fn_coe]),
map_zero' := polynomial.map_zero g,
map_add' := λ p q, polynomial.map_add g,
map_one' := polynomial.map_one g,
map_mul' := λ p q, polynomial.map_mul g }
@[simp] theorem coe_polynomial (g : P →+*[M] Q) :
(g.polynomial : P[X] → Q[X]) = map g :=
rfl
end mul_semiring_action_hom
|
8aa21f1db636935acb348d9f31c6725c88927e70 | 6432ea7a083ff6ba21ea17af9ee47b9c371760f7 | /tests/lean/run/wfForIn.lean | 054d6630cffdaaf8f86a943f39474d4fc3930e08 | [
"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 | 298 | lean | inductive Term where
| app (f : String) (args : List Term)
def printFns : Term → IO Unit
| Term.app f args => do
IO.println f
for h : arg in args do
have : sizeOf arg < 1 + sizeOf f + sizeOf args := Nat.lt_trans (List.sizeOf_lt_of_mem h) (by simp_arith)
printFns arg
|
a050eff851723fddcfdfb673d0fd4d5cc2023c13 | 6432ea7a083ff6ba21ea17af9ee47b9c371760f7 | /src/lake/Lake/Build/Module.lean | a6eaa7ca049091de110cf8c26bd97f56577a3ba6 | [
"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 | 10,778 | lean | /-
Copyright (c) 2021 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sebastian Ullrich, Mac Malone
-/
import Lake.Util.OrdHashSet
import Lean.Elab.ParseImportsFast
import Lake.Build.Common
/-! # Module Facet Builds
Build function definitions for a module's builtin facets.
-/
open System
namespace Lake
def Module.buildUnlessUpToDate (mod : Module)
(dynlibPath : SearchPath) (dynlibs : Array FilePath)
(depTrace : BuildTrace) : BuildM PUnit := do
let isOldMode ← getIsOldMode
let argTrace : BuildTrace := pureHash mod.leanArgs
let srcTrace : BuildTrace ← computeTrace { path := mod.leanFile : TextFilePath }
let modTrace := (← getLeanTrace).mix <| argTrace.mix <| srcTrace.mix depTrace
let modUpToDate ← do
if isOldMode then
srcTrace.checkAgainstTime mod
else
modTrace.checkAgainstFile mod mod.traceFile
let name := mod.name.toString
unless modUpToDate do
compileLeanModule name mod.leanFile mod.oleanFile mod.ileanFile mod.cFile
(← getLeanPath) mod.rootDir dynlibs dynlibPath (mod.leanArgs ++ mod.weakLeanArgs) (← getLean)
unless isOldMode do
modTrace.writeToFile mod.traceFile
/-- Compute library directories and build external library Jobs of the given packages. -/
def recBuildExternDynlibs (pkgs : Array Package)
: IndexBuildM (Array (BuildJob Dynlib) × Array FilePath) := do
let mut libDirs := #[]
let mut jobs : Array (BuildJob Dynlib) := #[]
for pkg in pkgs do
libDirs := libDirs.push pkg.nativeLibDir
jobs := jobs.append <| ← pkg.externLibs.mapM (·.dynlib.fetch)
return (jobs, libDirs)
/--
Build the dynlibs of the transitive imports that want precompilation
and the dynlibs of *their* imports.
-/
partial def recBuildPrecompileDynlibs (imports : Array Module)
: IndexBuildM (Array (BuildJob Dynlib) × Array (BuildJob Dynlib) × Array FilePath) := do
let (pkgs, _, jobs) ←
go imports OrdPackageSet.empty ModuleSet.empty #[] false
return (jobs, ← recBuildExternDynlibs pkgs.toArray)
where
go imports pkgs modSet jobs shouldPrecompile := do
let mut pkgs := pkgs
let mut modSet := modSet
let mut jobs := jobs
for mod in imports do
if modSet.contains mod then
continue
modSet := modSet.insert mod
let shouldPrecompile := shouldPrecompile || mod.shouldPrecompile
if shouldPrecompile then
pkgs := pkgs.insert mod.pkg
jobs := jobs.push <| (← mod.dynlib.fetch)
let recImports ← mod.imports.fetch
(pkgs, modSet, jobs) ← go recImports pkgs modSet jobs shouldPrecompile
return (pkgs, modSet, jobs)
variable [MonadLiftT BuildM m]
/--
Recursively parse the Lean files of a module and its imports
building an `Array` product of its direct local imports.
-/
def Module.recParseImports (mod : Module) : IndexBuildM (Array Module) := do
let contents ← IO.FS.readFile mod.leanFile
let imports ← Lean.parseImports' contents mod.leanFile.toString
let mods ← imports.foldlM (init := OrdModuleSet.empty) fun set imp =>
findModule? imp.module <&> fun | some mod => set.insert mod | none => set
return mods.toArray
/-- The `ModuleFacetConfig` for the builtin `importsFacet`. -/
def Module.importsFacetConfig : ModuleFacetConfig importsFacet :=
mkFacetConfig (·.recParseImports)
/-- Recursively compute a module's transitive imports. -/
def Module.recComputeTransImports (mod : Module) : IndexBuildM (Array Module) := do
(·.toArray) <$> (← mod.imports.fetch).foldlM (init := OrdModuleSet.empty) fun set imp => do
return set.appendArray (← imp.transImports.fetch) |>.insert imp
/-- The `ModuleFacetConfig` for the builtin `transImportsFacet`. -/
def Module.transImportsFacetConfig : ModuleFacetConfig transImportsFacet :=
mkFacetConfig (·.recComputeTransImports)
/-- Recursively compute a module's precompiled imports. -/
def Module.recComputePrecompileImports (mod : Module) : IndexBuildM (Array Module) := do
(·.toArray) <$> (← mod.imports.fetch).foldlM (init := OrdModuleSet.empty) fun set imp => do
if imp.shouldPrecompile then
return set.appendArray (← imp.transImports.fetch) |>.insert imp
else
return set.appendArray (← imp.precompileImports.fetch)
/-- The `ModuleFacetConfig` for the builtin `precompileImportsFacet`. -/
def Module.precompileImportsFacetConfig : ModuleFacetConfig precompileImportsFacet :=
mkFacetConfig (·.recComputePrecompileImports)
/-- Recursively build a module's transitive local imports and shared library dependencies. -/
def Module.recBuildDeps (mod : Module) : IndexBuildM (BuildJob (SearchPath × Array FilePath)) := do
let imports ← mod.imports.fetch
let extraDepJob ← mod.lib.extraDep.fetch
let precompileImports ← mod.precompileImports.fetch
let modJobs ← precompileImports.mapM (·.dynlib.fetch)
let pkgs := precompileImports.foldl (·.insert ·.pkg)
OrdPackageSet.empty |>.insert mod.pkg |>.toArray
let (externJobs, libDirs) ← recBuildExternDynlibs pkgs
let importJob ← BuildJob.mixArray <| ← imports.mapM (·.importBin.fetch)
let externDynlibsJob ← BuildJob.collectArray externJobs
let modDynlibsJob ← BuildJob.collectArray modJobs
extraDepJob.bindAsync fun _ extraDepTrace => do
importJob.bindAsync fun _ importTrace => do
modDynlibsJob.bindAsync fun modDynlibs modTrace => do
return externDynlibsJob.mapWithTrace fun externDynlibs externTrace =>
let depTrace := extraDepTrace.mix <| importTrace.mix <| modTrace.mix externTrace
/-
Requirements:
* Lean wants the external library symbols before module symbols.
* Unix requires the file extension of the dynlib.
* For some reason, building from the Lean server requires full paths.
Everything else loads fine with just the augmented library path.
* Linux still needs the augmented path to resolve nested dependencies in dynlibs.
-/
let dynlibPath := libDirs ++ externDynlibs.filterMap (·.dir?) |>.toList
let dynlibs := externDynlibs.map (·.path) ++ modDynlibs.map (·.path)
((dynlibPath, dynlibs), depTrace)
/-- The `ModuleFacetConfig` for the builtin `depsFacet`. -/
def Module.depsFacetConfig : ModuleFacetConfig depsFacet :=
mkFacetJobConfigSmall (·.recBuildDeps)
/-- Recursively build a module and its dependencies. -/
def Module.recBuildLeanCore (mod : Module) : IndexBuildM (BuildJob Unit) := do
(← mod.deps.fetch).bindSync fun (dynlibPath, dynlibs) depTrace => do
mod.buildUnlessUpToDate dynlibPath dynlibs depTrace
return ((), depTrace)
/-- The `ModuleFacetConfig` for the builtin `leanBinFacet`. -/
def Module.leanBinFacetConfig : ModuleFacetConfig leanBinFacet :=
mkFacetJobConfig (·.recBuildLeanCore)
/-- The `ModuleFacetConfig` for the builtin `importBinFacet`. -/
def Module.importBinFacetConfig : ModuleFacetConfig importBinFacet :=
mkFacetJobConfigSmall fun mod => do
(← mod.leanBin.fetch).bindSync fun _ depTrace =>
return ((), mixTrace (← computeTrace mod) depTrace)
/-- The `ModuleFacetConfig` for the builtin `oleanFacet`. -/
def Module.oleanFacetConfig : ModuleFacetConfig oleanFacet :=
mkFacetJobConfigSmall fun mod => do
(← mod.leanBin.fetch).bindSync fun _ depTrace =>
return (mod.oleanFile, mixTrace (← computeTrace mod.oleanFile) depTrace)
/-- The `ModuleFacetConfig` for the builtin `ileanFacet`. -/
def Module.ileanFacetConfig : ModuleFacetConfig ileanFacet :=
mkFacetJobConfigSmall fun mod => do
(← mod.leanBin.fetch).bindSync fun _ depTrace =>
return (mod.ileanFile, mixTrace (← computeTrace mod.ileanFile) depTrace)
/-- The `ModuleFacetConfig` for the builtin `cFacet`. -/
def Module.cFacetConfig : ModuleFacetConfig cFacet :=
mkFacetJobConfigSmall fun mod => do
(← mod.leanBin.fetch).bindSync fun _ _ =>
-- do content-aware hashing so that we avoid recompiling unchanged C files
return (mod.cFile, ← computeTrace mod.cFile)
/-- Recursively build the module's object file from its C file produced by `lean`. -/
def Module.recBuildLeanO (self : Module) : IndexBuildM (BuildJob FilePath) := do
buildLeanO self.name.toString self.oFile (← self.c.fetch) self.leancArgs
/-- The `ModuleFacetConfig` for the builtin `oFacet`. -/
def Module.oFacetConfig : ModuleFacetConfig oFacet :=
mkFacetJobConfig Module.recBuildLeanO
-- TODO: Return `BuildJob OrdModuleSet × OrdPackageSet` or `OrdRBSet Dynlib`
/-- Recursively build the shared library of a module (e.g., for `--load-dynlib`). -/
def Module.recBuildDynlib (mod : Module) : IndexBuildM (BuildJob Dynlib) := do
-- Compute dependencies
let transImports ← mod.transImports.fetch
let modJobs ← transImports.mapM (·.dynlib.fetch)
let pkgs := transImports.foldl (·.insert ·.pkg)
OrdPackageSet.empty |>.insert mod.pkg |>.toArray
let (externJobs, pkgLibDirs) ← recBuildExternDynlibs pkgs
let linkJobs ← mod.nativeFacets.mapM (fetch <| mod.facet ·.name)
-- Collect Jobs
let linksJob ← BuildJob.collectArray linkJobs
let modDynlibsJob ← BuildJob.collectArray modJobs
let externDynlibsJob ← BuildJob.collectArray externJobs
-- Build dynlib
show SchedulerM _ from do
linksJob.bindAsync fun links oTrace => do
modDynlibsJob.bindAsync fun modDynlibs libTrace => do
externDynlibsJob.bindSync fun externDynlibs externTrace => do
let libNames := modDynlibs.map (·.name) ++ externDynlibs.map (·.name)
let libDirs := pkgLibDirs ++ externDynlibs.filterMap (·.dir?)
let depTrace := oTrace.mix <| libTrace.mix externTrace
let trace ← buildFileUnlessUpToDate mod.dynlibFile depTrace do
let args :=
links.map toString ++
libDirs.map (s!"-L{·}") ++ libNames.map (s!"-l{·}") ++
mod.linkArgs
compileSharedLib mod.name.toString mod.dynlibFile args (← getLeanc)
return (⟨mod.dynlibFile, mod.dynlibName⟩, trace)
/-- The `ModuleFacetConfig` for the builtin `dynlibFacet`. -/
def Module.dynlibFacetConfig : ModuleFacetConfig dynlibFacet :=
mkFacetJobConfig Module.recBuildDynlib
open Module in
/--
A name-configuration map for the initial set of
Lake module facets (e.g., `lean.{imports, c, o, dynlib]`).
-/
def initModuleFacetConfigs : DNameMap ModuleFacetConfig :=
DNameMap.empty
|>.insert importsFacet importsFacetConfig
|>.insert transImportsFacet transImportsFacetConfig
|>.insert precompileImportsFacet precompileImportsFacetConfig
|>.insert depsFacet depsFacetConfig
|>.insert leanBinFacet leanBinFacetConfig
|>.insert importBinFacet importBinFacetConfig
|>.insert oleanFacet oleanFacetConfig
|>.insert ileanFacet ileanFacetConfig
|>.insert cFacet cFacetConfig
|>.insert oFacet oFacetConfig
|>.insert dynlibFacet dynlibFacetConfig
|
47bc50511124dd535d1642a44a70941f367c6b4d | d406927ab5617694ec9ea7001f101b7c9e3d9702 | /src/category_theory/products/basic.lean | 65d15df5afe92d9437a4d5bdd53c2bec04cdf46b | [
"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 | 10,651 | lean | /-
Copyright (c) 2017 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Stephen Morgan, Scott Morrison
-/
import category_theory.eq_to_hom
import category_theory.functor.const
import data.prod.basic
/-!
# Cartesian products of categories
We define the category instance on `C × D` when `C` and `D` are categories.
We define:
* `sectl C Z` : the functor `C ⥤ C × D` given by `X ↦ ⟨X, Z⟩`
* `sectr Z D` : the functor `D ⥤ C × D` given by `Y ↦ ⟨Z, Y⟩`
* `fst` : the functor `⟨X, Y⟩ ↦ X`
* `snd` : the functor `⟨X, Y⟩ ↦ Y`
* `swap` : the functor `C × D ⥤ D × C` given by `⟨X, Y⟩ ↦ ⟨Y, X⟩`
(and the fact this is an equivalence)
We further define `evaluation : C ⥤ (C ⥤ D) ⥤ D` and `evaluation_uncurried : C × (C ⥤ D) ⥤ D`,
and products of functors and natural transformations, written `F.prod G` and `α.prod β`.
-/
namespace category_theory
-- declare the `v`'s first; see `category_theory.category` for an explanation
universes v₁ v₂ v₃ v₄ u₁ u₂ u₃ u₄
section
variables (C : Type u₁) [category.{v₁} C] (D : Type u₂) [category.{v₂} D]
/--
`prod C D` gives the cartesian product of two categories.
See <https://stacks.math.columbia.edu/tag/001K>.
-/
@[simps {not_recursive := []}] -- the generates simp lemmas like `id_fst` and `comp_snd`
instance prod : category.{max v₁ v₂} (C × D) :=
{ hom := λ X Y, ((X.1) ⟶ (Y.1)) × ((X.2) ⟶ (Y.2)),
id := λ X, ⟨ 𝟙 (X.1), 𝟙 (X.2) ⟩,
comp := λ _ _ _ f g, (f.1 ≫ g.1, f.2 ≫ g.2) }
/-- Two rfl lemmas that cannot be generated by `@[simps]`. -/
@[simp] lemma prod_id (X : C) (Y : D) : 𝟙 (X, Y) = (𝟙 X, 𝟙 Y) := rfl
@[simp] lemma prod_comp {P Q R : C} {S T U : D} (f : (P, S) ⟶ (Q, T)) (g : (Q, T) ⟶ (R, U)) :
f ≫ g = (f.1 ≫ g.1, f.2 ≫ g.2) := rfl
lemma is_iso_prod_iff {P Q : C} {S T : D} {f : (P, S) ⟶ (Q, T)} :
is_iso f ↔ is_iso f.1 ∧ is_iso f.2 :=
begin
split,
{ rintros ⟨g, hfg, hgf⟩,
simp at hfg hgf,
rcases hfg with ⟨hfg₁, hfg₂⟩,
rcases hgf with ⟨hgf₁, hgf₂⟩,
exact ⟨⟨⟨g.1, hfg₁, hgf₁⟩⟩, ⟨⟨g.2, hfg₂, hgf₂⟩⟩⟩ },
{ rintros ⟨⟨g₁, hfg₁, hgf₁⟩, ⟨g₂, hfg₂, hgf₂⟩⟩,
dsimp at hfg₁ hgf₁ hfg₂ hgf₂,
refine ⟨⟨(g₁, g₂), _, _⟩⟩; { simp; split; assumption } }
end
section
variables {C D}
/-- The isomorphism between `(X.1, X.2)` and `X`. -/
@[simps]
def prod.eta_iso (X : C × D) : (X.1, X.2) ≅ X := { hom := (𝟙 _, 𝟙 _), inv := (𝟙 _, 𝟙 _) }
/-- Construct an isomorphism in `C × D` out of two isomorphisms in `C` and `D`. -/
@[simps]
def iso.prod {P Q : C} {S T : D} (f : P ≅ Q) (g : S ≅ T) : (P, S) ≅ (Q, T) :=
{ hom := (f.hom, g.hom),
inv := (f.inv, g.inv), }
end
end
section
variables (C : Type u₁) [category.{v₁} C] (D : Type u₁) [category.{v₁} D]
/--
`prod.category.uniform C D` is an additional instance specialised so both factors have the same
universe levels. This helps typeclass resolution.
-/
instance uniform_prod : category (C × D) := category_theory.prod C D
end
-- Next we define the natural functors into and out of product categories. For now this doesn't
-- address the universal properties.
namespace prod
/-- `sectl C Z` is the functor `C ⥤ C × D` given by `X ↦ (X, Z)`. -/
@[simps] def sectl
(C : Type u₁) [category.{v₁} C] {D : Type u₂} [category.{v₂} D] (Z : D) : C ⥤ C × D :=
{ obj := λ X, (X, Z),
map := λ X Y f, (f, 𝟙 Z) }
/-- `sectr Z D` is the functor `D ⥤ C × D` given by `Y ↦ (Z, Y)` . -/
@[simps] def sectr
{C : Type u₁} [category.{v₁} C] (Z : C) (D : Type u₂) [category.{v₂} D] : D ⥤ C × D :=
{ obj := λ X, (Z, X),
map := λ X Y f, (𝟙 Z, f) }
variables (C : Type u₁) [category.{v₁} C] (D : Type u₂) [category.{v₂} D]
/-- `fst` is the functor `(X, Y) ↦ X`. -/
@[simps] def fst : C × D ⥤ C :=
{ obj := λ X, X.1,
map := λ X Y f, f.1 }
/-- `snd` is the functor `(X, Y) ↦ Y`. -/
@[simps] def snd : C × D ⥤ D :=
{ obj := λ X, X.2,
map := λ X Y f, f.2 }
/-- The functor swapping the factors of a cartesian product of categories, `C × D ⥤ D × C`. -/
@[simps] def swap : C × D ⥤ D × C :=
{ obj := λ X, (X.2, X.1),
map := λ _ _ f, (f.2, f.1) }
/--
Swapping the factors of a cartesion product of categories twice is naturally isomorphic
to the identity functor.
-/
@[simps] def symmetry : swap C D ⋙ swap D C ≅ 𝟭 (C × D) :=
{ hom := { app := λ X, 𝟙 X },
inv := { app := λ X, 𝟙 X } }
/--
The equivalence, given by swapping factors, between `C × D` and `D × C`.
-/
@[simps]
def braiding : C × D ≌ D × C :=
equivalence.mk (swap C D) (swap D C)
(nat_iso.of_components (λ X, eq_to_iso (by simp)) (by tidy))
(nat_iso.of_components (λ X, eq_to_iso (by simp)) (by tidy))
instance swap_is_equivalence : is_equivalence (swap C D) :=
(by apply_instance : is_equivalence (braiding C D).functor)
end prod
section
variables (C : Type u₁) [category.{v₁} C] (D : Type u₂) [category.{v₂} D]
/--
The "evaluation at `X`" functor, such that
`(evaluation.obj X).obj F = F.obj X`,
which is functorial in both `X` and `F`.
-/
@[simps] def evaluation : C ⥤ (C ⥤ D) ⥤ D :=
{ obj := λ X,
{ obj := λ F, F.obj X,
map := λ F G α, α.app X, },
map := λ X Y f,
{ app := λ F, F.map f,
naturality' := λ F G α, eq.symm (α.naturality f) } }
/--
The "evaluation of `F` at `X`" functor,
as a functor `C × (C ⥤ D) ⥤ D`.
-/
@[simps] def evaluation_uncurried : C × (C ⥤ D) ⥤ D :=
{ obj := λ p, p.2.obj p.1,
map := λ x y f, (x.2.map f.1) ≫ (f.2.app y.1),
map_comp' := λ X Y Z f g,
begin
cases g, cases f, cases Z, cases Y, cases X,
simp only [prod_comp, nat_trans.comp_app, functor.map_comp, category.assoc],
rw [←nat_trans.comp_app, nat_trans.naturality, nat_trans.comp_app,
category.assoc, nat_trans.naturality],
end }
variables {C}
/-- The constant functor followed by the evalutation functor is just the identity. -/
@[simps] def functor.const_comp_evaluation_obj (X : C) :
functor.const C ⋙ (evaluation C D).obj X ≅ 𝟭 D :=
nat_iso.of_components (λ Y, iso.refl _) (λ Y Z f, by simp)
end
variables {A : Type u₁} [category.{v₁} A]
{B : Type u₂} [category.{v₂} B]
{C : Type u₃} [category.{v₃} C]
{D : Type u₄} [category.{v₄} D]
namespace functor
/-- The cartesian product of two functors. -/
@[simps] def prod (F : A ⥤ B) (G : C ⥤ D) : A × C ⥤ B × D :=
{ obj := λ X, (F.obj X.1, G.obj X.2),
map := λ _ _ f, (F.map f.1, G.map f.2) }
/- Because of limitations in Lean 3's handling of notations, we do not setup a notation `F × G`.
You can use `F.prod G` as a "poor man's infix", or just write `functor.prod F G`. -/
/-- Similar to `prod`, but both functors start from the same category `A` -/
@[simps] def prod' (F : A ⥤ B) (G : A ⥤ C) : A ⥤ (B × C) :=
{ obj := λ a, (F.obj a, G.obj a),
map := λ x y f, (F.map f, G.map f), }
/-- The product `F.prod' G` followed by projection on the first component is isomorphic to `F` -/
@[simps]
def prod'_comp_fst (F : A ⥤ B) (G : A ⥤ C) : (F.prod' G) ⋙ (category_theory.prod.fst B C) ≅ F :=
nat_iso.of_components (λ X, iso.refl _) (λ X Y f, by simp)
/-- The product `F.prod' G` followed by projection on the second component is isomorphic to `G` -/
@[simps]
def prod'_comp_snd (F : A ⥤ B) (G : A ⥤ C) : (F.prod' G) ⋙ (category_theory.prod.snd B C) ≅ G :=
nat_iso.of_components (λ X, iso.refl _) (λ X Y f, by simp)
section
variable (C)
/-- The diagonal functor. -/
def diag : C ⥤ C × C := (𝟭 C).prod' (𝟭 C)
@[simp] lemma diag_obj (X : C) : (diag C).obj X = (X, X) := rfl
@[simp] lemma diag_map {X Y : C} (f : X ⟶ Y) : (diag C).map f = (f, f) := rfl
end
end functor
namespace nat_trans
/-- The cartesian product of two natural transformations. -/
@[simps] def prod {F G : A ⥤ B} {H I : C ⥤ D} (α : F ⟶ G) (β : H ⟶ I) :
F.prod H ⟶ G.prod I :=
{ app := λ X, (α.app X.1, β.app X.2),
naturality' := λ X Y f,
begin
cases X, cases Y,
simp only [functor.prod_map, prod.mk.inj_iff, prod_comp],
split; rw naturality
end }
/- Again, it is inadvisable in Lean 3 to setup a notation `α × β`;
use instead `α.prod β` or `nat_trans.prod α β`. -/
end nat_trans
/-- `F.flip` composed with evaluation is the same as evaluating `F`. -/
@[simps]
def flip_comp_evaluation (F : A ⥤ B ⥤ C) (a) :
F.flip ⋙ (evaluation _ _).obj a ≅ F.obj a :=
nat_iso.of_components (λ b, eq_to_iso rfl) $ by tidy
variables (A B C)
/-- The forward direction for `functor_prod_functor_equiv` -/
@[simps] def prod_functor_to_functor_prod : (A ⥤ B) × (A ⥤ C) ⥤ A ⥤ B × C :=
{ obj := λ F, F.1.prod' F.2,
map := λ F G f, { app := λ X, (f.1.app X, f.2.app X) } }
/-- The backward direction for `functor_prod_functor_equiv` -/
@[simps] def functor_prod_to_prod_functor : (A ⥤ B × C) ⥤ (A ⥤ B) × (A ⥤ C) :=
{ obj := λ F, ⟨F ⋙ (category_theory.prod.fst B C), F ⋙ (category_theory.prod.snd B C)⟩,
map := λ F G α,
⟨{ app := λ X, (α.app X).1,
naturality' := λ X Y f,
by simp only [functor.comp_map, prod.fst_map, ←prod_comp_fst, α.naturality] },
{ app := λ X, (α.app X).2,
naturality' := λ X Y f,
by simp only [functor.comp_map, prod.snd_map, ←prod_comp_snd, α.naturality] }⟩ }
/-- The unit isomorphism for `functor_prod_functor_equiv` -/
@[simps] def functor_prod_functor_equiv_unit_iso :
𝟭 _ ≅ prod_functor_to_functor_prod A B C ⋙ functor_prod_to_prod_functor A B C :=
nat_iso.of_components
(λ F, (((functor.prod'_comp_fst _ _).prod (functor.prod'_comp_snd _ _)).trans
(prod.eta_iso F)).symm) (λ F G α, by {tidy})
/-- The counit isomorphism for `functor_prod_functor_equiv` -/
@[simps] def functor_prod_functor_equiv_counit_iso :
functor_prod_to_prod_functor A B C ⋙ prod_functor_to_functor_prod A B C ≅ 𝟭 _ :=
nat_iso.of_components
(λ F, nat_iso.of_components (λ X, prod.eta_iso (F.obj X)) (by tidy)) (by tidy)
/-- The equivalence of categories between `(A ⥤ B) × (A ⥤ C)` and `A ⥤ (B × C)` -/
@[simps] def functor_prod_functor_equiv : ((A ⥤ B) × (A ⥤ C)) ≌ (A ⥤ (B × C)) :=
{ functor := prod_functor_to_functor_prod A B C,
inverse := functor_prod_to_prod_functor A B C,
unit_iso := functor_prod_functor_equiv_unit_iso A B C,
counit_iso := functor_prod_functor_equiv_counit_iso A B C }
end category_theory
|
3a0d2438127a7067256acd25299a2f6a20f6952a | 9dc8cecdf3c4634764a18254e94d43da07142918 | /src/ring_theory/witt_vector/frobenius_fraction_field.lean | 50c4fba3202de132fa0df8eca772abf6a958a50c | [
"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 | 11,776 | lean | /-
Copyright (c) 2022 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Heather Macbeth
-/
import field_theory.is_alg_closed.basic
import ring_theory.witt_vector.discrete_valuation_ring
/-!
# Solving equations about the Frobenius map on the field of fractions of `𝕎 k`
The goal of this file is to prove `witt_vector.exists_frobenius_solution_fraction_ring`,
which says that for an algebraically closed field `k` of characteristic `p` and `a, b` in the
field of fractions of Witt vectors over `k`,
there is a solution `b` to the equation `φ b * a = p ^ m * b`, where `φ` is the Frobenius map.
Most of this file builds up the equivalent theorem over `𝕎 k` directly,
moving to the field of fractions at the end.
See `witt_vector.frobenius_rotation` and its specification.
The construction proceeds by recursively defining a sequence of coefficients as solutions to a
polynomial equation in `k`. We must define these as generic polynomials using Witt vector API
(`witt_vector.witt_mul`, `witt_polynomial`) to show that they satisfy the desired equation.
Preliminary work is done in the dependency `ring_theory.witt_vector.mul_coeff`
to isolate the `n+1`st coefficients of `x` and `y` in the `n+1`st coefficient of `x*y`.
This construction is described in Dupuis, Lewis, and Macbeth,
[Formalized functional analysis via semilinear maps][dupuis-lewis-macbeth2022].
We approximately follow an approach sketched on MathOverflow:
<https://mathoverflow.net/questions/62468/about-frobenius-of-witt-vectors>
The result is a dependency for the proof of `witt_vector.isocrystal_classification`,
the classification of one-dimensional isocrystals over an algebraically closed field.
-/
noncomputable theory
namespace witt_vector
variables (p : ℕ) [hp : fact p.prime]
local notation `𝕎` := witt_vector p
namespace recursion_main
/-!
## The recursive case of the vector coefficients
The first coefficient of our solution vector is easy to define below.
In this section we focus on the recursive case.
The goal is to turn `witt_poly_prod n` into a univariate polynomial
whose variable represents the `n`th coefficient of `x` in `x * a`.
-/
section comm_ring
include hp
variables {k : Type*} [comm_ring k] [char_p k p]
open polynomial
/-- The root of this polynomial determines the `n+1`st coefficient of our solution. -/
def succ_nth_defining_poly (n : ℕ) (a₁ a₂ : 𝕎 k) (bs : fin (n+1) → k) : polynomial k :=
X^p * C (a₁.coeff 0 ^ (p^(n+1))) - X * C (a₂.coeff 0 ^ (p^(n+1)))
+ C (a₁.coeff (n+1) * ((bs 0)^p)^(p^(n+1)) +
nth_remainder p n (λ v, (bs v)^p) (truncate_fun (n+1) a₁) -
a₂.coeff (n+1) * (bs 0)^p^(n+1) - nth_remainder p n bs (truncate_fun (n+1) a₂))
lemma succ_nth_defining_poly_degree [is_domain k] (n : ℕ) (a₁ a₂ : 𝕎 k) (bs : fin (n+1) → k)
(ha₁ : a₁.coeff 0 ≠ 0) (ha₂ : a₂.coeff 0 ≠ 0) :
(succ_nth_defining_poly p n a₁ a₂ bs).degree = p :=
begin
have : (X ^ p * C (a₁.coeff 0 ^ p ^ (n+1))).degree = p,
{ rw [degree_mul, degree_C],
{ simp only [nat.cast_with_bot, add_zero, degree_X, degree_pow, nat.smul_one_eq_coe] },
{ exact pow_ne_zero _ ha₁ } },
have : (X ^ p * C (a₁.coeff 0 ^ p ^ (n+1)) - X * C (a₂.coeff 0 ^ p ^ (n+1))).degree = p,
{ rw [degree_sub_eq_left_of_degree_lt, this],
rw [this, degree_mul, degree_C, degree_X, add_zero],
{ exact_mod_cast hp.out.one_lt },
{ exact pow_ne_zero _ ha₂ } },
rw [succ_nth_defining_poly, degree_add_eq_left_of_degree_lt, this],
apply lt_of_le_of_lt (degree_C_le),
rw [this],
exact_mod_cast hp.out.pos
end
end comm_ring
section is_alg_closed
include hp
variables {k : Type*} [field k] [char_p k p] [is_alg_closed k]
lemma root_exists (n : ℕ) (a₁ a₂ : 𝕎 k) (bs : fin (n+1) → k)
(ha₁ : a₁.coeff 0 ≠ 0) (ha₂ : a₂.coeff 0 ≠ 0) :
∃ b : k, (succ_nth_defining_poly p n a₁ a₂ bs).is_root b :=
is_alg_closed.exists_root _ $
by simp [(succ_nth_defining_poly_degree p n a₁ a₂ bs ha₁ ha₂), hp.out.ne_zero]
/-- This is the `n+1`st coefficient of our solution, projected from `root_exists`. -/
def succ_nth_val (n : ℕ) (a₁ a₂ : 𝕎 k) (bs : fin (n+1) → k)
(ha₁ : a₁.coeff 0 ≠ 0) (ha₂ : a₂.coeff 0 ≠ 0) : k :=
classical.some (root_exists p n a₁ a₂ bs ha₁ ha₂)
lemma succ_nth_val_spec (n : ℕ) (a₁ a₂ : 𝕎 k) (bs : fin (n+1) → k)
(ha₁ : a₁.coeff 0 ≠ 0) (ha₂ : a₂.coeff 0 ≠ 0) :
(succ_nth_defining_poly p n a₁ a₂ bs).is_root (succ_nth_val p n a₁ a₂ bs ha₁ ha₂) :=
classical.some_spec (root_exists p n a₁ a₂ bs ha₁ ha₂)
lemma succ_nth_val_spec' (n : ℕ) (a₁ a₂ : 𝕎 k) (bs : fin (n+1) → k)
(ha₁ : a₁.coeff 0 ≠ 0) (ha₂ : a₂.coeff 0 ≠ 0) :
(succ_nth_val p n a₁ a₂ bs ha₁ ha₂)^p * a₁.coeff 0 ^ (p^(n+1)) +
a₁.coeff (n+1) * ((bs 0)^p)^(p^(n+1)) +
nth_remainder p n (λ v, (bs v)^p) (truncate_fun (n+1) a₁)
= (succ_nth_val p n a₁ a₂ bs ha₁ ha₂) * a₂.coeff 0 ^ (p^(n+1)) +
a₂.coeff (n+1) * (bs 0)^(p^(n+1)) + nth_remainder p n bs (truncate_fun (n+1) a₂) :=
begin
rw ← sub_eq_zero,
have := succ_nth_val_spec p n a₁ a₂ bs ha₁ ha₂,
simp only [polynomial.map_add, polynomial.eval_X, polynomial.map_pow, polynomial.eval_C,
polynomial.eval_pow, succ_nth_defining_poly, polynomial.eval_mul, polynomial.eval_add,
polynomial.eval_sub, polynomial.map_mul, polynomial.map_sub, polynomial.is_root.def] at this,
convert this using 1,
ring
end
end is_alg_closed
end recursion_main
namespace recursion_base
include hp
variables {k : Type*} [field k] [is_alg_closed k]
lemma solution_pow (a₁ a₂ : 𝕎 k) :
∃ x : k, x^(p-1) = a₂.coeff 0 / a₁.coeff 0 :=
is_alg_closed.exists_pow_nat_eq _ $ by linarith [hp.out.one_lt, le_of_lt hp.out.one_lt]
/-- The base case (0th coefficient) of our solution vector. -/
def solution (a₁ a₂ : 𝕎 k) : k :=
classical.some $ solution_pow p a₁ a₂
lemma solution_spec (a₁ a₂ : 𝕎 k) :
(solution p a₁ a₂)^(p-1) = a₂.coeff 0 / a₁.coeff 0 :=
classical.some_spec $ solution_pow p a₁ a₂
lemma solution_nonzero {a₁ a₂ : 𝕎 k} (ha₁ : a₁.coeff 0 ≠ 0) (ha₂ : a₂.coeff 0 ≠ 0) :
solution p a₁ a₂ ≠ 0 :=
begin
intro h,
have := solution_spec p a₁ a₂,
rw [h, zero_pow] at this,
{ simpa [ha₁, ha₂] using _root_.div_eq_zero_iff.mp this.symm },
{ linarith [hp.out.one_lt, le_of_lt hp.out.one_lt] }
end
lemma solution_spec' {a₁ : 𝕎 k} (ha₁ : a₁.coeff 0 ≠ 0) (a₂ : 𝕎 k) :
(solution p a₁ a₂)^p * a₁.coeff 0 = (solution p a₁ a₂) * a₂.coeff 0 :=
begin
have := solution_spec p a₁ a₂,
cases nat.exists_eq_succ_of_ne_zero hp.out.ne_zero with q hq,
have hq' : q = p - 1 := by simp only [hq, tsub_zero, nat.succ_sub_succ_eq_sub],
conv_lhs {congr, congr, skip, rw hq},
rw [pow_succ', hq', this],
field_simp [ha₁, mul_comm],
end
end recursion_base
open recursion_main recursion_base
section frobenius_rotation
section is_alg_closed
include hp
variables {k : Type*} [field k] [char_p k p] [is_alg_closed k]
/--
Recursively defines the sequence of coefficients for `witt_vector.frobenius_rotation`.
-/
noncomputable def frobenius_rotation_coeff {a₁ a₂ : 𝕎 k}
(ha₁ : a₁.coeff 0 ≠ 0) (ha₂ : a₂.coeff 0 ≠ 0) : ℕ → k
| 0 := solution p a₁ a₂
| (n + 1) := succ_nth_val p n a₁ a₂ (λ i, frobenius_rotation_coeff i.val) ha₁ ha₂
using_well_founded { dec_tac := `[apply fin.is_lt] }
/--
For nonzero `a₁` and `a₂`, `frobenius_rotation a₁ a₂` is a Witt vector that satisfies the
equation `frobenius (frobenius_rotation a₁ a₂) * a₁ = (frobenius_rotation a₁ a₂) * a₂`.
-/
def frobenius_rotation {a₁ a₂ : 𝕎 k} (ha₁ : a₁.coeff 0 ≠ 0) (ha₂ : a₂.coeff 0 ≠ 0) : 𝕎 k :=
witt_vector.mk p (frobenius_rotation_coeff p ha₁ ha₂)
lemma frobenius_rotation_nonzero {a₁ a₂ : 𝕎 k} (ha₁ : a₁.coeff 0 ≠ 0) (ha₂ : a₂.coeff 0 ≠ 0) :
frobenius_rotation p ha₁ ha₂ ≠ 0 :=
begin
intro h,
apply solution_nonzero p ha₁ ha₂,
simpa [← h, frobenius_rotation, frobenius_rotation_coeff] using witt_vector.zero_coeff p k 0
end
lemma frobenius_frobenius_rotation {a₁ a₂ : 𝕎 k} (ha₁ : a₁.coeff 0 ≠ 0) (ha₂ : a₂.coeff 0 ≠ 0) :
frobenius (frobenius_rotation p ha₁ ha₂) * a₁ = (frobenius_rotation p ha₁ ha₂) * a₂ :=
begin
ext n,
induction n with n ih,
{ simp only [witt_vector.mul_coeff_zero, witt_vector.coeff_frobenius_char_p,
frobenius_rotation, frobenius_rotation_coeff],
apply solution_spec' _ ha₁ },
{ simp only [nth_remainder_spec, witt_vector.coeff_frobenius_char_p, frobenius_rotation_coeff,
frobenius_rotation, fin.val_eq_coe],
have := succ_nth_val_spec' p n a₁ a₂
(λ (i : fin (n + 1)), frobenius_rotation_coeff p ha₁ ha₂ i.val) ha₁ ha₂,
simp only [frobenius_rotation_coeff, fin.val_eq_coe, fin.val_zero] at this,
convert this using 4,
apply truncated_witt_vector.ext,
intro i,
simp only [fin.val_eq_coe, witt_vector.coeff_truncate_fun, witt_vector.coeff_frobenius_char_p],
refl }
end
local notation `φ` := is_fraction_ring.field_equiv_of_ring_equiv (frobenius_equiv p k)
lemma exists_frobenius_solution_fraction_ring_aux
(m n : ℕ) (r' q' : 𝕎 k) (hr' : r'.coeff 0 ≠ 0) (hq' : q'.coeff 0 ≠ 0)
(hq : ↑p ^ n * q' ∈ non_zero_divisors (𝕎 k)) :
let b : 𝕎 k := frobenius_rotation p hr' hq' in
is_fraction_ring.field_equiv_of_ring_equiv
(frobenius_equiv p k)
(algebra_map (𝕎 k) (fraction_ring (𝕎 k)) b) *
localization.mk (↑p ^ m * r') ⟨↑p ^ n * q', hq⟩ =
↑p ^ (m - n : ℤ) * algebra_map (𝕎 k) (fraction_ring (𝕎 k)) b :=
begin
intros b,
have key : witt_vector.frobenius b * p ^ m * r' * p ^ n = p ^ m * b * (p ^ n * q'),
{ have H := congr_arg (λ x : 𝕎 k, x * p ^ m * p ^ n) (frobenius_frobenius_rotation p hr' hq'),
dsimp at H,
refine (eq.trans _ H).trans _; ring },
have hq'' : algebra_map (𝕎 k) (fraction_ring (𝕎 k)) q' ≠ 0,
{ have hq''' : q' ≠ 0 := λ h, hq' (by simp [h]),
simpa only [ne.def, map_zero] using
(is_fraction_ring.injective (𝕎 k) (fraction_ring (𝕎 k))).ne hq''' },
rw zpow_sub₀ (fraction_ring.p_nonzero p k),
field_simp [fraction_ring.p_nonzero p k],
simp only [is_fraction_ring.field_equiv_of_ring_equiv,
is_localization.ring_equiv_of_ring_equiv_eq, ring_equiv.coe_of_bijective],
convert congr_arg (λ x, algebra_map (𝕎 k) (fraction_ring (𝕎 k)) x) key using 1,
{ simp only [ring_hom.map_mul, ring_hom.map_pow, map_nat_cast, frobenius_equiv_apply],
ring },
{ simp only [ring_hom.map_mul, ring_hom.map_pow, map_nat_cast] }
end
lemma exists_frobenius_solution_fraction_ring {a : fraction_ring (𝕎 k)} (ha : a ≠ 0) :
∃ (b : fraction_ring (𝕎 k)) (hb : b ≠ 0) (m : ℤ), φ b * a = p ^ m * b :=
begin
revert ha,
refine localization.induction_on a _,
rintros ⟨r, q, hq⟩ hrq,
have hq0 : q ≠ 0 := mem_non_zero_divisors_iff_ne_zero.1 hq,
have hr0 : r ≠ 0 := λ h, hrq (by simp [h]),
obtain ⟨m, r', hr', rfl⟩ := exists_eq_pow_p_mul r hr0,
obtain ⟨n, q', hq', rfl⟩ := exists_eq_pow_p_mul q hq0,
let b := frobenius_rotation p hr' hq',
refine ⟨algebra_map (𝕎 k) _ b, _, m - n, _⟩,
{ simpa only [map_zero] using
(is_fraction_ring.injective (witt_vector p k) (fraction_ring (witt_vector p k))).ne
(frobenius_rotation_nonzero p hr' hq')},
exact exists_frobenius_solution_fraction_ring_aux p m n r' q' hr' hq' hq,
end
end is_alg_closed
end frobenius_rotation
end witt_vector
|
f415d0321d0435880e101037f3c796c00e0f5335 | d5bef83c55d40cb88f9a01b755c882a93348a847 | /tests/lean/run/u_eq_max_u_v.lean | b2e2af918d808ead2dfa44a2b012a4e6999d92df | [
"Apache-2.0"
] | permissive | urkud/lean | 587d78216e1f0c7f651566e9e92cf8ade285d58d | 3526539070ea6268df5dd373deeb3ac8b9621952 | refs/heads/master | 1,660,171,634,921 | 1,657,873,466,000 | 1,657,873,466,000 | 249,789,456 | 0 | 0 | Apache-2.0 | 1,585,075,263,000 | 1,585,075,263,000 | null | UTF-8 | Lean | false | false | 3,182 | lean | universe variables u v u1 u2 v1 v2
set_option pp.universes true
class semigroup (α : Type u) extends has_mul α :=
(mul_assoc : ∀ a b c : α, a * b * c = a * (b * c))
open smt_tactic
meta def blast : tactic unit := using_smt $ intros >> add_lemmas_from_facts >> iterate_at_most 3 ematch
notation `♮` := by blast
structure semigroup_morphism { α β : Type u } ( s : semigroup α ) ( t: semigroup β ) :=
(map: α → β)
(multiplicative : ∀ x y : α, map(x * y) = map(x) * map(y))
attribute [simp] semigroup_morphism.multiplicative
@[reducible] instance semigroup_morphism_to_map { α β : Type u } { s : semigroup α } { t: semigroup β } : has_coe_to_fun (semigroup_morphism s t) _ :=
{ coe := semigroup_morphism.map }
@[reducible] definition semigroup_identity { α : Type u } ( s: semigroup α ) : semigroup_morphism s s := ⟨ id, ♮ ⟩
@[reducible] definition semigroup_morphism_composition
{ α β γ : Type u } { s: semigroup α } { t: semigroup β } { u: semigroup γ}
( f: semigroup_morphism s t ) ( g: semigroup_morphism t u ) : semigroup_morphism s u :=
{
map := λ x, g (f x),
multiplicative := begin intros, simp [coe_fn] end
}
local attribute [simp] semigroup.mul_assoc
@[reducible] definition semigroup_product { α β : Type u } ( s : semigroup α ) ( t: semigroup β ) : semigroup (α × β) := {
mul := λ p q, (p^.fst * q^.fst, p^.snd * q^.snd),
mul_assoc := begin
intros,
simp [@has_mul.mul (α × β)]
end
}
definition semigroup_morphism_product
{ α β γ δ : Type u }
{ s_f : semigroup α } { s_g: semigroup β } { t_f : semigroup γ} { t_g: semigroup δ }
( f : semigroup_morphism s_f t_f ) ( g : semigroup_morphism s_g t_g )
: semigroup_morphism (semigroup_product s_f s_g) (semigroup_product t_f t_g) := {
map := λ p, (f p.1, g p.2),
multiplicative :=
begin
-- cf https://groups.google.com/d/msg/lean-user/bVs5FdjClp4/tfHiVjLIBAAJ
intros,
unfold has_mul.mul,
dsimp [coe_fn],
simp
end
}
structure Category :=
(Obj : Type u)
(Hom : Obj → Obj → Type v)
structure Functor (C : Category.{ u1 v1 }) (D : Category.{ u2 v2 }) :=
(onObjects : C^.Obj → D^.Obj)
(onMorphisms : Π { X Y : C^.Obj },
C^.Hom X Y → D^.Hom (onObjects X) (onObjects Y))
@[reducible] definition ProductCategory (C : Category) (D : Category) :
Category :=
{
Obj := C^.Obj × D^.Obj,
Hom := (λ X Y : C^.Obj × D^.Obj, C^.Hom (X^.fst) (Y^.fst) × D^.Hom (X^.snd) (Y^.snd))
}
namespace ProductCategory
notation C `×` D := ProductCategory C D
end ProductCategory
structure PreMonoidalCategory
extends carrier : Category :=
(tensor : Functor (carrier × carrier) carrier)
definition CategoryOfSemigroups : Category :=
{
Obj := Σ α : Type u, semigroup α,
Hom := λ s t, semigroup_morphism s.2 t.2
}
definition PreMonoidalCategoryOfSemigroups : PreMonoidalCategory := {
CategoryOfSemigroups with
tensor := {
onObjects := λ p, sigma.mk (p.1.1 × p.2.1) (semigroup_product p.1.2 p.2.2),
onMorphisms := λ s t f, semigroup_morphism_product f.1 f.2
}
}
|
13d93c3ac540b73ba8d5b66f7d3a3e3340f8738f | 4d2583807a5ac6caaffd3d7a5f646d61ca85d532 | /src/algebra/group/conj.lean | 39efac7b61797f86ce5b36e47d26c9aee6ea8a74 | [
"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 | 7,536 | lean | /-
Copyright (c) 2018 Patrick Massot. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Massot, Chris Hughes, Michael Howes
-/
import data.fintype.basic
import algebra.group.hom
import algebra.group.semiconj
import data.equiv.mul_add_aut
import algebra.group_with_zero.basic
/-!
# Conjugacy of group elements
See also `mul_aut.conj` and `quandle.conj`.
-/
universes u v
variables {α : Type u} {β : Type v}
section monoid
variables [monoid α] [monoid β]
/-- We say that `a` is conjugate to `b` if for some unit `c` we have `c * a * c⁻¹ = b`. -/
def is_conj (a b : α) := ∃ c : units α, semiconj_by ↑c a b
@[refl] lemma is_conj.refl (a : α) : is_conj a a :=
⟨1, semiconj_by.one_left a⟩
@[symm] lemma is_conj.symm {a b : α} : is_conj a b → is_conj b a
| ⟨c, hc⟩ := ⟨c⁻¹, hc.units_inv_symm_left⟩
@[trans] lemma is_conj.trans {a b c : α} : is_conj a b → is_conj b c → is_conj a c
| ⟨c₁, hc₁⟩ ⟨c₂, hc₂⟩ := ⟨c₂ * c₁, hc₂.mul_left hc₁⟩
@[simp] lemma is_conj_iff_eq {α : Type*} [comm_monoid α] {a b : α} : is_conj a b ↔ a = b :=
⟨λ ⟨c, hc⟩, begin
rw [semiconj_by, mul_comm, ← units.mul_inv_eq_iff_eq_mul, mul_assoc, c.mul_inv, mul_one] at hc,
exact hc,
end, λ h, by rw h⟩
protected lemma monoid_hom.map_is_conj (f : α →* β) {a b : α} : is_conj a b → is_conj (f a) (f b)
| ⟨c, hc⟩ := ⟨units.map f c, by rw [units.coe_map, semiconj_by, ← f.map_mul, hc.eq, f.map_mul]⟩
end monoid
section group
variables [group α]
@[simp] lemma is_conj_iff {a b : α} :
is_conj a b ↔ ∃ c : α, c * a * c⁻¹ = b :=
⟨λ ⟨c, hc⟩, ⟨c, mul_inv_eq_iff_eq_mul.2 hc⟩, λ ⟨c, hc⟩,
⟨⟨c, c⁻¹, mul_inv_self c, inv_mul_self c⟩, mul_inv_eq_iff_eq_mul.1 hc⟩⟩
@[simp] lemma is_conj_one_right {a : α} : is_conj 1 a ↔ a = 1 :=
⟨λ ⟨c, hc⟩, mul_right_cancel (hc.symm.trans ((mul_one _).trans (one_mul _).symm)), λ h, by rw [h]⟩
@[simp] lemma is_conj_one_left {a : α} : is_conj a 1 ↔ a = 1 :=
calc is_conj a 1 ↔ is_conj 1 a : ⟨is_conj.symm, is_conj.symm⟩
... ↔ a = 1 : is_conj_one_right
@[simp] lemma conj_inv {a b : α} : (b * a * b⁻¹)⁻¹ = b * a⁻¹ * b⁻¹ :=
((mul_aut.conj b).map_inv a).symm
@[simp] lemma conj_mul {a b c : α} : (b * a * b⁻¹) * (b * c * b⁻¹) = b * (a * c) * b⁻¹ :=
((mul_aut.conj b).map_mul a c).symm
@[simp] lemma conj_pow {i : ℕ} {a b : α} : (a * b * a⁻¹) ^ i = a * (b ^ i) * a⁻¹ :=
begin
induction i with i hi,
{ simp },
{ simp [pow_succ, hi] }
end
@[simp] lemma conj_zpow {i : ℤ} {a b : α} : (a * b * a⁻¹) ^ i = a * (b ^ i) * a⁻¹ :=
begin
induction i,
{ simp },
{ simp [zpow_neg_succ_of_nat, conj_pow] }
end
lemma conj_injective {x : α} : function.injective (λ (g : α), x * g * x⁻¹) :=
(mul_aut.conj x).injective
end group
@[simp] lemma is_conj_iff₀ [group_with_zero α] {a b : α} :
is_conj a b ↔ ∃ c : α, c ≠ 0 ∧ c * a * c⁻¹ = b :=
⟨λ ⟨c, hc⟩, ⟨c, begin
rw [← units.coe_inv', units.mul_inv_eq_iff_eq_mul],
exact ⟨c.ne_zero, hc⟩,
end⟩, λ ⟨c, c0, hc⟩,
⟨units.mk0 c c0, begin
rw [semiconj_by, ← units.mul_inv_eq_iff_eq_mul, units.coe_inv', units.coe_mk0],
exact hc
end⟩⟩
namespace is_conj
/- This small quotient API is largely copied from the API of `associates`;
where possible, try to keep them in sync -/
/-- The setoid of the relation `is_conj` iff there is a unit `u` such that `u * x = y * u` -/
protected def setoid (α : Type*) [monoid α] : setoid α :=
{ r := is_conj, iseqv := ⟨is_conj.refl, λa b, is_conj.symm, λa b c, is_conj.trans⟩ }
end is_conj
local attribute [instance, priority 100] is_conj.setoid
/-- The quotient type of conjugacy classes of a group. -/
def conj_classes (α : Type*) [monoid α] : Type* :=
quotient (is_conj.setoid α)
namespace conj_classes
section monoid
variables [monoid α] [monoid β]
/-- The canonical quotient map from a monoid `α` into the `conj_classes` of `α` -/
protected def mk {α : Type*} [monoid α] (a : α) : conj_classes α :=
⟦a⟧
instance : inhabited (conj_classes α) := ⟨⟦1⟧⟩
theorem mk_eq_mk_iff_is_conj {a b : α} :
conj_classes.mk a = conj_classes.mk b ↔ is_conj a b :=
iff.intro quotient.exact quot.sound
theorem quotient_mk_eq_mk (a : α) : ⟦ a ⟧ = conj_classes.mk a := rfl
theorem quot_mk_eq_mk (a : α) : quot.mk setoid.r a = conj_classes.mk a := rfl
theorem forall_is_conj {p : conj_classes α → Prop} :
(∀a, p a) ↔ (∀a, p (conj_classes.mk a)) :=
iff.intro
(assume h a, h _)
(assume h a, quotient.induction_on a h)
theorem mk_surjective : function.surjective (@conj_classes.mk α _) :=
forall_is_conj.2 (λ a, ⟨a, rfl⟩)
instance : has_one (conj_classes α) := ⟨⟦ 1 ⟧⟩
theorem one_eq_mk_one : (1 : conj_classes α) = conj_classes.mk 1 := rfl
lemma exists_rep (a : conj_classes α) : ∃ a0 : α, conj_classes.mk a0 = a :=
quot.exists_rep a
/-- A `monoid_hom` maps conjugacy classes of one group to conjugacy classes of another. -/
def map (f : α →* β) : conj_classes α → conj_classes β :=
quotient.lift (conj_classes.mk ∘ f) (λ a b ab, mk_eq_mk_iff_is_conj.2 (f.map_is_conj ab))
instance [fintype α] [decidable_rel (is_conj : α → α → Prop)] :
fintype (conj_classes α) :=
quotient.fintype (is_conj.setoid α)
end monoid
section comm_monoid
variable [comm_monoid α]
lemma mk_injective : function.injective (@conj_classes.mk α _) :=
λ _ _, (mk_eq_mk_iff_is_conj.trans is_conj_iff_eq).1
lemma mk_bijective : function.bijective (@conj_classes.mk α _) :=
⟨mk_injective, mk_surjective⟩
/-- The bijection between a `comm_group` and its `conj_classes`. -/
def mk_equiv : α ≃ conj_classes α :=
⟨conj_classes.mk, quotient.lift id (λ (a : α) b, is_conj_iff_eq.1), quotient.lift_mk _ _,
begin
rw [function.right_inverse, function.left_inverse, forall_is_conj],
intro x,
rw [← quotient_mk_eq_mk, ← quotient_mk_eq_mk, quotient.lift_mk, id.def],
end⟩
end comm_monoid
end conj_classes
section monoid
variables [monoid α]
/-- Given an element `a`, `conjugates a` is the set of conjugates. -/
def conjugates_of (a : α) : set α := {b | is_conj a b}
lemma mem_conjugates_of_self {a : α} : a ∈ conjugates_of a := is_conj.refl _
lemma is_conj.conjugates_of_eq {a b : α} (ab : is_conj a b) :
conjugates_of a = conjugates_of b :=
set.ext (λ g, ⟨λ ag, (ab.symm).trans ag, λ bg, ab.trans bg⟩)
lemma is_conj_iff_conjugates_of_eq {a b : α} :
is_conj a b ↔ conjugates_of a = conjugates_of b :=
⟨is_conj.conjugates_of_eq, λ h, begin
have ha := mem_conjugates_of_self,
rwa ← h at ha,
end⟩
end monoid
namespace conj_classes
variables [monoid α]
local attribute [instance] is_conj.setoid
/-- Given a conjugacy class `a`, `carrier a` is the set it represents. -/
def carrier : conj_classes α → set α :=
quotient.lift conjugates_of (λ (a : α) b ab, is_conj.conjugates_of_eq ab)
lemma mem_carrier_mk {a : α} : a ∈ carrier (conj_classes.mk a) := is_conj.refl _
lemma mem_carrier_iff_mk_eq {a : α} {b : conj_classes α} :
a ∈ carrier b ↔ conj_classes.mk a = b :=
begin
revert b,
rw forall_is_conj,
intro b,
rw [carrier, eq_comm, mk_eq_mk_iff_is_conj, ← quotient_mk_eq_mk, quotient.lift_mk],
refl,
end
lemma carrier_eq_preimage_mk {a : conj_classes α} :
a.carrier = conj_classes.mk ⁻¹' {a} :=
set.ext (λ x, mem_carrier_iff_mk_eq)
end conj_classes
|
b32fa6f32ef859fc796d114df09d9f19da5a740a | 4f065978c49388d188224610d9984673079f7d91 | /linear_algebra/vector_space.lean | 0aa65e6d0e4eaaca1bf99aac9f2c1cc85d4747a8 | [] | no_license | kckennylau/Lean | b323103f52706304907adcfaee6f5cb8095d4a33 | 907d0a4d2bd8f23785abd6142ad53d308c54fdcb | refs/heads/master | 1,624,623,720,653 | 1,563,901,820,000 | 1,563,901,820,000 | 109,506,702 | 3 | 1 | null | null | null | null | UTF-8 | Lean | false | false | 11,505 | lean | import algebra.module
instance field.to_vector_space {K : Type} [field K] :
vector_space K K := ⟨ring.to_module⟩
lemma eq_zero_of_add_self_eq {α : Type} [add_group α]
{a : α} (H : a + a = a) : a = 0 :=
add_left_cancel (by {rw add_zero, exact H})
class subspace (K : Type) (V : Type) [field K] [vector_space K V] (p : V → Prop) :=
(p_zero : p 0)
(p_add : ∀ u v, p u → p v → p (u + v))
(p_neg : ∀ v, p v → p (-v))
(p_smul : ∀ c v, p v → p (c • v))
namespace subspace
variables (K : Type) {V : Type} [field K] [vector_space K V]
{p : V → Prop} [subspace K V p]
variables {c d : K} (u v : {x // p x})
include K
def add (u v : {x // p x}) : {x // p x} :=
{
val := u.val + v.val,
property := p_add K u.val v.val u.property v.property
}
def zero : {x // p x} :=
{
val := 0,
property := p_zero K p
}
def neg (v : {x // p x}) : {x // p x} :=
{
val := -v.val,
property := p_neg K v.val v.property
}
def smul (c : K) (v : {x // p x}) : {x // p x} :=
{
val := c • v.val,
property := p_smul c v.val v.property
}
instance : has_add {x // p x} := ⟨add K⟩
instance : has_zero {x // p x} := ⟨zero K⟩
instance : has_neg {x // p x} := ⟨neg K⟩
instance : has_scalar K {x // p x} := ⟨smul K⟩
@[simp] lemma add_simp : (add K u v).val = u.val + v.val := rfl
@[simp] lemma zero_simp : (zero K : {x // p x}).val = 0 := rfl
@[simp] lemma neg_simp : (neg K v).val = -v.val := rfl
@[simp] lemma smul_simp : (smul K c v).val = c • v.val := rfl
@[simp] lemma add_simp' : (u + v).val = u.val + v.val := rfl
@[simp] lemma zero_simp' : (0 : {x // p x}).val = 0 := rfl
@[simp] lemma neg_simp' : (-v).val = -v.val := rfl
@[simp] lemma smul_simp' : (c • v).val = c • v.val := rfl
instance : vector_space K {x // p x} :=
{
add := add K,
add_assoc := (λ u v w, subtype.eq (by simp [add_assoc])),
zero := zero K,
zero_add := (λ v, subtype.eq (by simp [zero_add])),
add_zero := (λ v, subtype.eq (by simp [add_zero])),
neg := neg K,
add_left_neg := (λ v, subtype.eq (by simp [add_left_neg])),
add_comm := (λ u v, subtype.eq (by simp [add_comm])),
smul := smul K,
smul_left_distrib := (λ c u v, subtype.eq (by simp [smul_left_distrib])),
smul_right_distrib := (λ c u v, subtype.eq (by simp [smul_right_distrib])),
mul_smul := (λ c d v, subtype.eq (by simp [mul_smul])),
one_smul := (λ v, subtype.eq (by simp [one_smul]))
}
end subspace
structure linear_space (K V W : Type) [field K]
[vector_space K V] [vector_space K W] :=
(T : V → W)
(map_add : ∀ u v, T (u+v) = T u + T v)
(map_mul : ∀ (c:K) v, T (c • v) = c • (T v))
namespace linear_space
variables {K V W : Type} [field K] [vector_space K V] [vector_space K W]
variables {c d : K}
section basic
variables {u v : V} {A B C : linear_space K V W}
@[simp] lemma map_add_simp : A.T (u+v) = A.T u + A.T v := map_add A u v
@[simp] lemma map_mul_simp : A.T (c•v) = c • (A.T v) := map_mul A c v
theorem ext (HAB : ∀ v, A.T v = B.T v) : A = B :=
by {cases A, cases B, congr, exact funext HAB}
@[simp] lemma map_zero : A.T 0 = 0 :=
begin
have := eq.symm (map_add A 0 0),
rw [add_zero] at this,
exact eq_zero_of_add_self_eq this
end
@[simp] lemma map_neg : A.T (-v) = -(A.T v) :=
eq_neg_of_add_eq_zero (by {rw [←map_add], simp})
@[simp] lemma map_sub : A.T (u-v) = A.T u - A.T v := by simp
end basic
@[simp] def ker (A : linear_space K V W) : V → Prop := (λ v, A.T v = 0)
namespace ker
variables {A : linear_space K V W}
variables (u v : V)
theorem ker_of_map_eq_map (Huv : A.T u = A.T v) : A.ker (u-v) :=
by {rw [ker,map_sub], exact sub_eq_zero_of_eq Huv}
theorem inj_of_trivial_ker (H: ∀ v, A.ker v → v = 0) (Huv: A.T u = A.T v) : u = v :=
eq_of_sub_eq_zero (H _ (ker_of_map_eq_map _ _ Huv))
theorem ker_add (HU : A.ker u) (HV : A.ker v) : A.ker (u + v) :=
by {unfold ker at *, simp [HU,HV]}
theorem ker_zero : A.ker 0 := map_zero
theorem ker_neg (HV : A.ker v) : A.ker (-v) :=
by {unfold ker at *, simp [HV]}
theorem ker_sub (HU : A.ker u) (HV : A.ker v) : A.ker (u - v) :=
by {unfold ker at *, simp [HU,HV]}
theorem ker_smul (c : K) (v : V) (HV : A.ker v) : A.ker (c • v) :=
by {unfold ker at *, simp [HV]}
instance : subspace K V A.ker :=
{
p_add := ker_add,
p_zero := ker_zero,
p_neg := ker_neg,
p_smul := ker_smul
}
end ker
section Hom
variables {u v : V} {A B C : linear_space K V W}
def add (A B : linear_space K V W) : (linear_space K V W) :=
{
T := (λ v, (A.T v) + (B.T v)),
map_add := (λ u v, by simp),
map_mul := (λ c v, by simp [smul_left_distrib])
}
def zero : linear_space K V W :=
{
T := (λ v, 0),
map_add := (λ u v, by simp),
map_mul := (λ c v, by simp)
}
def neg (A : linear_space K V W) : linear_space K V W :=
{
T := (λ v, -A.T v),
map_add := (λ u v, by simp),
map_mul := (λ c v, by simp)
}
instance : has_add (linear_space K V W) := ⟨add⟩
instance : has_zero (linear_space K V W) := ⟨zero⟩
instance : has_neg (linear_space K V W) := ⟨neg⟩
@[simp] lemma add_simp : (A + B).T v = A.T v + B.T v := rfl
@[simp] lemma zero_simp : (0:linear_space K V W).T v = 0 := rfl
@[simp] lemma neg_simp : (-A).T v = -(A.T v) := rfl
def smul (c : K) (A : linear_space K V W) : linear_space K V W :=
{
T := (λ v, c•(A.T v)),
map_add := (λ u v, by simp [smul_left_distrib]),
map_mul := (λ k v, by simp [smul_smul])
}
local infix `⬝` := smul
@[simp] lemma smul_simp : (c⬝A).T v = c•(A.T v) := rfl
variables (c d u v A B C)
theorem add_zero : A + 0 = A := ext (λ v, by simp [add_zero])
theorem zero_add : 0 + A = A := ext (λ v, by simp [zero_add])
theorem add_right_neg : A + (-A) = 0 := ext (λ v, by simp [add_right_neg])
theorem add_left_neg : (-A) + A = 0 := ext (λ v, by simp [add_left_neg])
theorem add_assoc : A + B + C = A + (B + C) := ext (λ v, by simp [add_assoc])
theorem add_comm : A + B = B + A := ext (λ v, by simp [add_comm])
theorem smul_left_distrib : c⬝(A+B) = c⬝A + c⬝B := ext (λ v, by simp [smul_left_distrib])
theorem smul_right_distrib : (c+d)⬝A = c⬝A + d⬝A := ext (λ v, by simp [smul_right_distrib])
theorem mul_smul : (c*d)⬝A = c⬝(d⬝A) := ext (λ v, by simp [mul_smul])
theorem one_smul : 1⬝A = A := ext (λ v, by simp [one_smul])
instance : vector_space K (linear_space K V W) :=
{
add := add,
add_assoc := add_assoc,
zero := zero,
zero_add := zero_add,
add_zero := add_zero,
neg := neg,
add_left_neg := add_left_neg,
add_comm := add_comm,
smul := smul,
smul_left_distrib := smul_left_distrib,
smul_right_distrib := smul_right_distrib,
mul_smul := mul_smul,
one_smul := one_smul
}
end Hom
def Hom {K : Type} (V W : Type) [field K] [vector_space K V] [vector_space K W] :=
vector_space K (linear_space K V W)
def vector_space.dual {K: Type} (V: Type) [field K] [vector_space K V] :=
@Hom K V K _ _ field.to_vector_space
-- \ast
postfix `∗`:100 := vector_space.dual
section matrix_ring
variables {v : V} {A B C : linear_space K V V}
def id : linear_space K V V :=
{
T := id,
map_add := (λ u v, rfl),
map_mul := (λ u v, rfl),
}
def comp (A B : linear_space K V V) : linear_space K V V :=
{
T := (λ v, A.T $ B.T v),
map_add := (λ u v, by simp),
map_mul := (λ c v, by simp)
}
instance : has_mul (linear_space K V V) := ⟨comp⟩
@[simp] lemma id_simp : (id : linear_space K V V).T v = v := rfl
@[simp] lemma comp_simp : (A * B).T v = A.T (B.T v) := rfl
variables (v A B C)
@[simp] lemma comp_id : A * id = A := ext (λ v, rfl)
@[simp] lemma id_comp : id * A = A := ext (λ v, rfl)
theorem comp_assoc : (A * B) * C = A * (B * C) := ext (λ v, rfl)
theorem comp_add : A * (B + C) = A * B + A * C := ext (λ v, by simp)
theorem add_comp : (A + B) * C = A * C + B * C := ext (λ v, rfl)
instance : ring (linear_space K V V) :=
{
add := add,
add_assoc := add_assoc,
zero := zero,
zero_add := zero_add,
add_zero := add_zero,
neg := neg,
add_left_neg := add_left_neg,
add_comm := add_comm,
mul := comp,
mul_assoc := comp_assoc,
one := id,
one_mul := id_comp,
mul_one := comp_id,
left_distrib := comp_add,
right_distrib := add_comp
}
end matrix_ring
variables (K V)
namespace general_linear
structure invertible :=
(val : linear_space K V V)
(inv : linear_space K V V)
(property : val*inv = (id:linear_space K V V) ∧ inv*val = id)
variables {A B C : invertible K V}
variables {K V}
def ext (HAB : (∀ v:V, A.val.T v = B.val.T v)) : A = B :=
begin
cases A,
cases B,
congr,
apply ext HAB,
have HAB : val = val_1 := ext HAB,
exact calc
inv = inv * (val_1 * inv_1) : by rw [property_1.1,comp_id]
... = (inv * val_1) * inv_1 : by rw [mul_assoc]
... = (inv * val) * inv_1 : by rw [HAB]
... = inv_1 : by rw [property.2,id_comp]
end
lemma mul_four {α : Type} [monoid α]
{a b c d : α} : (a * b) * (c * d) = a * (b * c) * d := by simp
def comp (A B : invertible K V) : invertible K V :=
{
val := A.val * B.val,
inv := B.inv * A.inv,
property := ⟨by simp [mul_four,B.property.1,A.property.1],
by simp [mul_four,A.property.2,B.property.2]⟩
}
def id : invertible K V :=
{
val := id,
inv := id,
property := ⟨comp_id id, id_comp id⟩
}
def inv (A : invertible K V) : invertible K V :=
{
val := A.inv,
inv := A.val,
property := ⟨A.property.2, A.property.1⟩
}
instance : has_mul (invertible K V) := ⟨comp⟩
instance : has_one (invertible K V) := ⟨id⟩
instance : has_inv (invertible K V) := ⟨inv⟩
variables (A B C) (u v : V)
@[simp] lemma comp_simp : (comp A B).val.T v = A.val.T (B.val.T v) := rfl
@[simp] lemma id_simp : (id : invertible K V).val.T v = v := rfl
@[simp] lemma inv_simp : (inv A).val.T v = A.inv.T v := rfl
@[simp] lemma comp_simp' : (A * B).val.T v = A.val.T (B.val.T v) := rfl
@[simp] lemma id_simp' : (1 : invertible K V).val.T v = v := rfl
@[simp] lemma inv_simp' : (A⁻¹).val.T v = A.inv.T v := rfl
@[simp] lemma comp_inv_simp' : (A*A⁻¹).val.T v = v :=
begin
have := A.property.1,
have : (A.val * A.inv).T v = linear_space.id.T v := by rw [this],
simp at this,
simp [this]
end
@[simp] lemma inv_comp_simp' : (A⁻¹*A).val.T v = v :=
begin
have := A.property.2,
have : (A.inv * A.val).T v = linear_space.id.T v := by rw [this],
simp at this,
simp [this]
end
theorem comp_assoc : (A * B) * C = A * (B * C) := ext (λ v, by simp)
theorem comp_id : A * id = A := ext (λ v, by simp)
theorem id_comp : id * A = A := ext (λ v, by simp)
theorem comp_right_inv : A * A⁻¹ = 1 := ext (λ v, by simp)
theorem comp_left_inv : A⁻¹ * A = 1 := ext (λ v, by simp)
instance : group (invertible K V) :=
{
mul := comp,
mul_assoc := comp_assoc,
one := id,
mul_one := comp_id,
one_mul := id_comp,
inv := inv,
mul_left_inv := comp_left_inv
}
end general_linear
end linear_space
|
c055b9c83aeee4ab6aa9716f3133d53a07158bba | a9d0fb7b0e4f802bd3857b803e6c5c23d87fef91 | /tests/lean/run/section5.lean | dd5575a007aca7b70683f154787aed17597f5f19 | [
"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 | 264 | lean | section foo
parameter A : Type
variable a : A
definition foo := a
check foo
structure [class] point :=
(x : A) (y : A)
end foo
check foo
attribute [instance]
definition point_nat : point nat :=
point.mk nat.zero nat.zero
print classes
check point
|
9b3d735a98f63f54ec5f77df90e1944e99a11293 | 9e47285bdd500b89455fd905c20aabcd3af1a5cf | /fekete.lean | 8b2c844cf4b5e8c3f0ebd5d8e100cf2ca295c916 | [] | no_license | akreuzer/feteke-lean | d4ec120e3e7dab9d36681499b239f0e57eb18349 | d030101b3ab2aa4155c2aa1a84021e833da3a497 | refs/heads/master | 1,610,987,214,936 | 1,490,906,196,000 | 1,490,906,196,000 | 86,744,981 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 11,874 | lean | /- Copyright (c) Alexander Kreuzer 2016, 2017
LEAN Proof of Feteke's lemma
-/
import theories.analysis.real_limit
import standard
import ak_utils
import ak_compat
open real nat set rat pnat num classical int analysis
open eq.ops
open ak
set_option pp.coercions true
definition subadditive (X : ℕ → ℝ) : Prop :=
∀ {n1: ℕ}, ∀ {n2: ℕ}, X (n1 + n2) ≤ X n1 + X n2
noncomputable definition seq_quot (X : ℕ → ℝ) : ℕ → ℝ
| 0 := X 1
| n := (X n) / real.of_nat n
lemma seq_quod_nn (X : ℕ→ℝ) (n : ℕ) (Hn : n > 0) :
seq_quot X n = (X n) / real.of_nat n :=
begin
cases n,
have ¬ 0 > (0:ℕ), from not_lt_zero 0,
apply absurd Hn this,
unfold seq_quot
end
lemma seq_quod_eq_zero_one (X : ℕ → ℝ) :
seq_quot X 0 = seq_quot X 1 :=
begin
unfold seq_quot,
have of_nat (succ zero) = (1:ℝ), from rfl,
rewrite [this],
xrewrite [div_one (X (succ zero))]
end
definition seq_mulindex (X : ℕ → ℝ) (c: ℕ) : ℕ → ℝ := λ n , X ( c * n)
proposition subadditive_seq_mulindex (X : ℕ → ℝ) (Hsa : subadditive X) (c : ℕ) : subadditive (seq_mulindex X c) :=
take n1,
take n2,
have H1: X ( c * n1 + c * n2) ≤ X ( c * n1) + X ( c * n2), from Hsa,
show X ( c * (n1 + n2)) ≤ X ( c * n1) + X ( c * n2), from (left_distrib c n1 n2)⁻¹ ▸ H1
proposition t1 (X : ℕ → ℝ) (Hsa : subadditive(X)) (n: ℕ):
X (n + 1) ≤ of_nat (n+1) * X 1 :=
nat.induction_on n
(show X 1 ≤ 1 * X 1, from (one_mul (X 1))⁻¹ ▸ (real.le_refl (X 1)) )
(take n,
assume IH : X (n+1) ≤ of_nat (n+1) * (X 1),
have H1 : X (n+1+1) ≤ X (n+1) + (X 1) , from Hsa,
have H2 : X (n+1) + X 1 ≤ of_nat (n+1) * X 1 + X 1, from add_le_add_right IH (X 1),
have H2': 1 * X 1 = X 1, from one_mul (X 1),
have H2'': of_nat 1 = (1:ℝ), from rfl,
have H2''': of_nat (n+1+1) = of_nat (n+1) + of_nat 1, from of_nat_add (n+1) 1,
have H3 : of_nat (n+1) * X 1 + X 1 = of_nat (n+1+1) * X 1, from calc
of_nat (n+1) * (X 1) + (X 1) = of_nat (n+1) * X 1 + 1 * X 1 : H2'
... = (of_nat (n+1) + 1) * X 1 : right_distrib
... = (of_nat (n+1) + of_nat 1) * X 1 : H2''
... = (of_nat (n+1+1)) * X 1 : H2''',
have H4 : X (n+1) + X 1 ≤ of_nat (n+1+1) * X 1, from H3 ▸ H2,
show X (n+1+1) ≤ of_nat (n+1+1) * X 1, from real.le_trans Hsa H4)
attribute subadditive [irreducible]
corollary t1b (X : ℕ → ℝ) (Hsa : subadditive X) (c: ℕ) (n: ℕ):
X (c * (n + 1)) ≤ of_nat (n+1) * X c:=
let Y := seq_mulindex X c in
let HY := subadditive_seq_mulindex X Hsa c in
have H: Y (n+1) ≤ of_nat (n+1) * Y 1, from t1 Y HY n,
have H': Y (n+1) = X(c * (n +1)), from rfl,
have H'': Y 1 = X(c), from eq.subst (mul_one c) rfl,
show X(c * (n + 1)) ≤ of_nat (n+1) * X c , from eq.subst H'' (eq.subst H' H)
proposition t2 (X : ℕ → ℝ) (Hsa : subadditive X) (c : ℕ) (n : ℕ) :
X n ≤ of_nat (div n c) * X c + X (n % c) :=
assert H1: X n ≤ X (n / c * c) + X (n % c), from
begin
esimp [subadditive] at Hsa,
have X n = X ((n / c * c) + n % c), from eq.subst (eq_div_mul_add_mod n c) rfl,
rewrite [this],
apply Hsa
end,
begin
have div n c = 0 ∨ div n c ≠ 0, from !em,
cases this,
have n = n % c + (div n c) * c, from eq.subst !nat.add_comm (eq_div_mul_add_mod n c),
have n - (div n c) * c = n % c, from nat.sub_eq_of_eq_add this,
rewrite [-this,a],
have H: n - 0 = n, from rfl,
have of_nat 0 * X c = 0, from zero_mul (X c),
rewrite [zero_mul,H,this,zero_add],
apply le_of_eq,
apply rfl,
have Ha: div n c = succ (pred (div n c)), from
or.elim (eq_zero_or_eq_succ_pred (div n c)) (by contradiction) (assume Hp: _, Hp),
rewrite [Ha],
have X (c * succ (pred (div n c))) ≤ succ (pred (div n c)) * X c, from t1b X Hsa _ _,
have H2: X (c * succ (pred (div n c))) + X (n % c) ≤ succ (pred (div n c)) * X c + X (n % c), from add_le_add_right this _,
have H1': (div n c) * c = c * succ (pred (div n c)), from eq.subst Ha (nat.mul_comm (div n c) c),
show _, from real.le_trans (eq.subst H1' H1) H2,
end
corollary t2c (X : ℕ → ℝ) (Hsa : subadditive X) (c : ℕ) (n : ℕ) (Hc: c > (0 : ℕ)):
X n ≤ of_nat (div n c) * X c + (ak.seq_max_to X c) :=
have n % c ≤ c, from le_of_lt (mod_lt _ Hc),
have X(n % c) ≤ seq_max_to X c, from seq_max_to_le X this,
have of_nat (div n c) * X c + X (n % c) ≤ of_nat (div n c) * X c + seq_max_to X c, from add_le_add_left this _,
show _, from le.trans (t2 X Hsa c n) this
lemma seq_quot_inf_conv ( X : ℕ → ℝ) (Hsa : subadditive X):
∀ (x : ℝ), is_inf ((seq_quot X) ' univ) x → ak_compat.converges_to_seq (seq_quot X) x :=
let Xq := seq_quot X in
begin
intros [x, Hinfx],
have HinfxEx: ∀ (n : ℕ), Xq n ≥ x, from
begin
intro n,
unfold is_inf at Hinfx,
cases Hinfx with [Hinfx1,Hinfx2],
unfold lb at Hinfx1,
apply (Hinfx1 (Xq n)),
esimp [image,mem,set_of,univ],
existsi n,
split,
trivial,
apply rfl
end,
unfold ak_compat.converges_to_seq,
intro [ε, epspos],
have ε * of_rat 0.3 > 0, from mul_pos epspos (of_rat_lt_of_rat_of_lt dec_trivial),
have ∃ (y : ℝ), (y∈ Xq ' univ) ∧ (y - x < ε * of_rat 0.3), from inf_exists_point _ x Hinfx (ε * of_rat 0.3) this,
have ∃ (n : ℕ), (Xq n - x < ε * of_rat 0.3) ∧ n > 0, from exists.elim this
begin
intros [a, Ha],
cases Ha with [Ha1,Ha2],
esimp [image,mem,set_of] at Ha1,
show ∃ (n : ℕ), ((Xq n) - x < ε * of_rat 0.3) ∧ n > 0, from exists.elim Ha1
begin
intro [n, Hn],
cases Hn with [Hn1, Hn2],
cases n with [n0],
-- case n = 0
existsi 1,
rewrite [-seq_quod_eq_zero_one,Hn2],
split,
assumption,
exact zero_lt_one,
-- case n =/= 0
existsi (succ n0),
rewrite [Hn2],
split,
assumption,
exact !zero_lt_succ
end
end,
show ∃ (N:ℕ), ∀ {n:ℕ}, n≥ N → abs(seq_quot X n - x) < ε, from exists.elim this
begin
intros [c,Hc],
cases Hc with [Hc1, Hc2],
let lb1 := inv (ε * of_rat 0.3) * seq_max_to X c,
let lb2 := inv (ε * of_rat (-0.3)) * X c,
existsi succ (max (int.nat_abs (ceil lb1)) (int.nat_abs (ceil lb2))),
intros [n,Hn],
have Xq n - x ≥ 0, from sub_nonneg_of_le (HinfxEx n),
rewrite [abs_of_nonneg this],
apply sub_lt_left_of_lt_add,
have Hn': n > 0, from lt_of_lt_of_le (zero_lt_succ _) Hn,
rewrite [seq_quod_nn X n Hn'],
have X n ≤ of_nat (div n c) * X c + (seq_max_to X c), from t2c X Hsa c n Hc2,
have Ht2c1: X n / of_nat n ≤ (of_nat (div n c) * X c + (seq_max_to X c)) / of_nat n, from div_le_div_of_le_of_pos this (of_nat_lt_of_nat_of_lt (eq.subst rfl Hn')),
have (of_nat (div n c) * X c + (seq_max_to X c)) / of_nat n = of_nat (div n c) * X c / of_nat n + (seq_max_to X c) / of_nat n,
from eq.symm (div_add_div_same (of_nat (div n c) * X c) (seq_max_to X c) (of_nat n)),
have Ht2c1': X n / of_nat n ≤ of_nat (div n c) * X c / of_nat n + (seq_max_to X c) / of_nat n, from this ▸ Ht2c1,
have H1: (seq_max_to X c) / of_nat n < ε * of_rat 0.3, from
begin
apply div_lt_of_lt_mul_pos,
apply of_nat_lt_of_nat_of_lt,
apply Hn',
apply inv_mul_lt_of_lt_pos_mul,
assumption,
have lb1 ≤ nat_abs (ceil lb1), from le.trans (le_ceil lb1) (of_int_le_of_int_of_le (le_nat_abs (ceil lb1))),
apply (lt_of_le_of_lt this),
apply of_nat_lt_of_nat_of_lt,
apply lt_of_le_of_lt !le_max_left (lt_of_succ_le Hn),
end,
have H2: of_nat (div n c) * X c / of_nat n < x + ε * of_rat 0.6, from
begin
apply div_lt_of_lt_mul_pos,
apply of_nat_lt_of_nat_of_lt,
apply Hn',
have c= succ (pred c), from or.elim (eq_zero_or_eq_succ_pred c) (assume H: _, absurd H (ne_of_gt Hc2)) (assume H: _, H),
have Hseq_quot: X c / of_nat c = seq_quot X c, from calc
X c / of_nat c = X (succ (pred c)) / of_nat (succ (pred c)) : this
... = seq_quot X (succ (pred c)) : rfl
... = seq_quot X c : this,
have Hn'': 0< of_nat n, from
begin
cases n,
have false, from (iff.mp (lt_self_iff_false 0) Hn'),
exfalso,
trivial,
apply of_nat_lt_of_nat_of_lt,
apply dec_trivial,
end,
cases em (X c ≥ 0) with [HXc,HXcn],
have of_nat (n / c) ≤ of_nat n / of_nat c, from le_of_sub_nonneg (and.elim_right (nat_div_estimate n c Hc2)),
have of_nat (n / c) * X c ≤ (of_nat n / of_nat c) * X c, from mul_le_mul_of_nonneg_right this HXc,
apply lt_of_le_of_lt this,
xrewrite (division.def (of_nat n) (of_nat c)),
rewrite [mul.assoc,mul.comm],
apply mul_lt_mul_of_pos_right,
rewrite [mul.comm,-division.def],
xrewrite Hseq_quot,
apply lt_add_of_sub_lt_left,
apply lt.trans Hc1,
apply mul_lt_mul_of_pos_left,
apply of_rat_lt_of_rat_of_lt,
apply dec_trivial,
assumption,
assumption,
have of_nat n / of_nat c - 1 < of_nat (n / c), from sub_lt_right_of_lt_add (lt_add_of_sub_lt_left (and.elim_left (nat_div_estimate n c Hc2))),
have of_nat (n / c) * X c < (of_nat n / of_nat c - 1) * X c, from mul_lt_mul_of_neg_right this (lt_of_not_ge HXcn),
apply lt.trans this,
rewrite [mul_sub_right_distrib,-mul_inv_cancel (ne_of_gt (of_nat_lt_of_nat_of_lt Hn')) ],
xrewrite (division.def (of_nat n) (of_nat c)),
rewrite [*mul.assoc,-mul_sub_left_distrib,mul.comm],
apply mul_lt_mul_of_pos_right,
apply sub_lt_left_of_lt_add,
rewrite [mul.comm,-division.def],
xrewrite Hseq_quot,
rewrite [add.comm,add.assoc],
apply lt_add_of_sub_lt_left,
apply lt.trans Hc1,
apply lt_add_of_sub_lt_left,
rewrite [-mul_sub_left_distrib],
xrewrite [-of_rat_sub],
apply mul_lt_of_lt_pos_inv_mul,
assumption,
have (0.3:ℚ) - 0.6 = -0.3, from dec_trivial,
rewrite this,
apply mul_lt_of_gt_div_neg,
apply mul_neg_of_pos_of_neg,
assumption,
apply of_rat_lt_of_rat_of_lt,
apply dec_trivial,
have lb2 ≤ nat_abs (ceil lb2), from le.trans (le_ceil lb2) (of_int_le_of_int_of_le (le_nat_abs (ceil lb2))),
rewrite [division.def,mul.comm],
apply (lt_of_le_of_lt this),
apply of_nat_lt_of_nat_of_lt,
apply lt_of_le_of_lt !le_max_right (lt_of_succ_le Hn),
assumption
end,
apply lt_of_le_of_lt Ht2c1',
apply lt_of_lt_of_le (add_lt_add H2 H1),
rewrite add.assoc,
apply add_le_add_left,
rewrite [-left_distrib,-(mul_one ε),mul.assoc],
apply mul_le_mul_of_nonneg_left,
xrewrite one_mul,
xrewrite [-of_rat_one,-of_rat_add],
apply of_rat_le_of_rat_of_le,
apply dec_trivial,
apply real.le_of_lt,
exact epspos
end,
end
lemma seq_quot_conv_inf (X : ℕ → ℝ) (Hsa : subadditive X):
∀ (x : ℝ), ak_compat.converges_to_seq (seq_quot X) x → is_inf ((seq_quot X) ' univ) x :=
begin
intro,
intro HX,
let converges_seq_X := exists.intro x HX,
exact exists.elim (@ex_inf_of_seq_from_limit (seq_quot X) converges_seq_X)
begin
intros [y,Hy],
have ak_compat.converges_to_seq (seq_quot X) y, from seq_quot_inf_conv X Hsa y Hy,
have x=y, from ak_compat.converges_to_seq_unique HX this,
rewrite this,
assumption
end
end
-- Feteke's Lemma
-- This will be just a combination of seq_quot_inf_conv and seq_quot_conv_inf
theorem feteke (X : ℕ → ℝ) (Hsa: subadditive X):
∀ (x: ℝ), ak_compat.converges_to_seq (seq_quot X) x ↔ is_inf ((seq_quot X) ' univ) x
:=
take x, iff.intro (seq_quot_conv_inf X Hsa x) (seq_quot_inf_conv X Hsa x)
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.